Skip to content
This repository was archived by the owner on Sep 18, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
env: {
browser: true,
es2021: true
},
extends: ['airbnb-base'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
rules: {}
};
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and publish crudodb

on:
push:
branches: [master]
branches: [main, next]
jobs:
release:
runs-on: ubuntu-latest
Expand Down
14 changes: 0 additions & 14 deletions .releaserc.json

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ For example:
const instance = await CrudoDb.setup();

// key will generated by CrudoDb
const key = await instance.registerDatabase({
const key = await instance.registerSchema({
schema: mySchema
});
const item: T = { key: 'value', id: '1' };
Expand Down
49 changes: 35 additions & 14 deletions docs/angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,61 @@ recommendation for angular is to use shared root service, which setup the instan

all consuming services need a schemaKey. To work smooth with it, cache it in a property and optional combine it with the instance from root service.

In all following usages, you have to pipe `handle$` to the matching method
In all following usages, you have to pipe `handle$` to the matching method

```typescript
import {Injectable} from '@angular/core';
import {combineLatest, Observable} from "rxjs";
import {map, shareReplay, switchMap, tap} from "rxjs/operators";
import {fromPromise} from "rxjs/internal-compatibility";
import {CrudoDb} from "crudodb";
import {StoreSchema} from "./store-schema";

@Injectable({providedIn: 'root'})
export class StoreAccessService {

public instance$ = fromPromise(CrudoDb.setup)
.pipe(shareReplay(1));
public instance$ = fromPromise(CrudoDb.setup())
.pipe(shareReplay(1));

}

interface Dao {
key: string;
id: number;
}

const schema: StoreSchema = {
dbName: 'my-database',
dbVersion: 1,
store: 'dao',
indices: [
{ name: 'id', unique: true },
{ name: 'key' }
]
};

@Injectable({providedIn: 'root'})
export class DaoService {

private key$ = this.storeAccess.instance$.pipe(
switchMap((instance) => instance.registerSchema({schema})),
shareReplay(1)
);
private key$ = this.storeAccess.instance$.pipe(
switchMap((instance) => instance.registerSchema({schema})),
shareReplay(1)
);

private handle$ = combineLatest([this.key$, this.storeAccess.instance$]).pipe(shareReplay(1));
private handle$ = combineLatest([
this.key$,
this.storeAccess.instance$
]).pipe(shareReplay(1));

constructor(private storeAccess: StoreAccessService) {}
constructor(
private storeAccess: StoreAccessService
) {}

public create(item: Dao): Observable<Dao> {
return this.handle$.pipe(
switchMap(([key, instance]) => instance.create(key, item))
);
}
public create(item: Dao): Observable<Dao> {
return this.handle$.pipe(
switchMap(([key, instance]) => instance.create(key, item))
);
}
}

```
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
"devDependencies": {
"@types/jest": "^26.0.14",
"@types/node": "^14.11.5",
"@typescript-eslint/eslint-plugin": "^4.6.0",
"@typescript-eslint/parser": "^4.4.0",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"babel-jest": "^26.5.2",
"eslint": "^7.10.0",
"eslint": "^7.25.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-ban": "^1.5.1",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.0",
"eslint-plugin-typescript": "^0.14.0",
"eslint-plugin-unused-imports": "^1.0.0",
Expand All @@ -58,6 +59,7 @@
"lint-staged": {
"*.+(js|ts)": [
"yarn format:prettier",
"yarn lint:es:fix",
"git add"
]
},
Expand Down
14 changes: 14 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
branches: ['main', { name: 'next', prerelease: true }],
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
[
'@semantic-release/npm',
{
pkgRoot: 'dist/src'
}
],
'@semantic-release/github'
]
};
Loading