@idb-orm/core 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -20
- package/dist/builder.d.ts +6 -8
- package/dist/client/compiled-query.d.ts +3 -3
- package/dist/client/delete.d.ts +4 -5
- package/dist/client/helpers.d.ts +17 -9
- package/dist/client/index.d.ts +31 -5
- package/dist/client/types/find.d.ts +13 -11
- package/dist/client/types/index.d.ts +29 -28
- package/dist/client/types/mutation.d.ts +42 -39
- package/dist/core.d.ts +11 -0
- package/dist/dump/class.d.ts +22 -0
- package/dist/dump/json.d.ts +9 -0
- package/dist/error.d.ts +43 -14
- package/dist/field/field-types.d.ts +10 -9
- package/dist/field/index.d.ts +5 -4
- package/dist/field/primary-key.d.ts +10 -7
- package/dist/field/property.d.ts +37 -31
- package/dist/field/relation.d.ts +21 -2
- package/dist/field/type-wrapper.d.ts +108 -0
- package/dist/field/validators.d.ts +13 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +8 -9
- package/dist/index.es.js +2 -0
- package/dist/model/index.d.ts +2 -2
- package/dist/model/model-types.d.ts +9 -6
- package/dist/model/model.d.ts +23 -6
- package/dist/object-store.d.ts +12 -10
- package/dist/transaction.d.ts +23 -6
- package/dist/util-types.d.ts +18 -9
- package/dist/utils.d.ts +3 -14
- package/package.json +12 -13
- package/dist/dev-types.d.ts +0 -4
- package/dist/dev.d.ts +0 -5
- package/dist/field/constants.d.ts +0 -9
- package/dist/field/field.d.ts +0 -40
- package/dist/index.js +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/common.d.ts +0 -48
- package/dist/types.d.ts +0 -48
package/README.md
CHANGED
|
@@ -9,34 +9,31 @@
|
|
|
9
9
|
- [x] "Include" query field
|
|
10
10
|
- [x] Enforce that either "include" xor "select" is in the query object
|
|
11
11
|
- [x] modify the query object so that on relations it is recursive
|
|
12
|
-
- [
|
|
13
|
-
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
12
|
+
- [x] Make sure non-optional and non-array relations do not have the `SetNull` onDelete action on model compilation
|
|
13
|
+
- [x] Complete update action
|
|
14
|
+
- [x] Redo Mutation type. It should provide structurally no change:
|
|
15
|
+
- [x] Split `add` and `update` mutation until completely separate interfaces?
|
|
16
|
+
- [x] -Many or -All are only present on `ArrayRelation`'s,
|
|
17
|
+
- [x] Cannot use `delete` or `disconnect` on non-nullable (1-1) relations
|
|
18
|
+
- [x] Add additional functions to the storeInterface
|
|
19
|
+
- [x] get([primaryKey], [include/select])
|
|
20
|
+
- [x] update([primaryKey], [updateMutation without where])
|
|
21
|
+
- [x] Error Handling: Instead of needing to type `tx.abort(...)` just use the `throw new ...` syntax and catch the error and automatically abort the transaction. This will require actions to be wrapped in some kind of try-catch block.
|
|
17
22
|
- [ ] Dump database to different formats:
|
|
18
23
|
- [ ] JSON
|
|
19
24
|
- [ ] CSV
|
|
20
|
-
|
|
21
|
-
- [ ] Add extra object syntax to "where"
|
|
22
|
-
- [ ]
|
|
23
|
-
|
|
24
|
-
- [ ] deleteMany
|
|
25
|
-
- [ ] findMany
|
|
26
|
-
- [ ] updateMany
|
|
27
|
-
- [ ] Convert internal string unions to enums
|
|
28
|
-
- [x] Remove external dependencies
|
|
29
|
-
- [x] deep-equal
|
|
30
|
-
- [x] type-fest
|
|
31
|
-
- [x] uuid
|
|
32
|
-
- [x] zod
|
|
25
|
+
- [ ] Make package to wrap Tanstack query for react application
|
|
26
|
+
- [ ] Add extra object syntax to "where" clause (i.e. `in`/`ne`/`gt`/...)
|
|
27
|
+
- [ ] Allow object types in where clauses
|
|
28
|
+
- [x] Convert internal string unions to enums
|
|
33
29
|
- [ ] Make subpackages for adapters for different validation languages
|
|
34
|
-
- [
|
|
30
|
+
- [x] Zod
|
|
35
31
|
- [ ] Yup
|
|
36
32
|
- [ ] Joi
|
|
37
33
|
- [ ] schema.js
|
|
34
|
+
- [ ] Migrate to vite instead of rollup
|
|
38
35
|
|
|
39
36
|
### Roadmap - Maybe
|
|
40
37
|
|
|
38
|
+
- [ ] Optimize batch `add` editing with cursor functionality
|
|
41
39
|
- [ ] Discriminated union models: Be able to differentiate subtypes of a model by a discriminator key
|
|
42
|
-
- [ ] Error Handling: Instead of needing to type `tx.abort(...)` just use the `throw new ...` syntax and catch the error and automatically abort the transaction. This will require actions to be wrapped in some kind of try-catch block.
|
package/dist/builder.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { CollectionSchema, Model } from
|
|
2
|
-
import { DbClient } from
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
export type CollectionObject<Names extends string> = {
|
|
6
|
-
[K in Names]: Model<K, any>;
|
|
7
|
-
};
|
|
1
|
+
import { CollectionObject, CollectionSchema, FindPrimaryKey, Model } from './model';
|
|
2
|
+
import { DbClient } from './client';
|
|
3
|
+
import { ValidValue } from './field';
|
|
4
|
+
import { Dict } from './util-types';
|
|
8
5
|
export declare class Builder<Name extends string, Names extends string> {
|
|
9
6
|
readonly name: Name;
|
|
10
7
|
readonly names: Names[];
|
|
11
8
|
private models;
|
|
12
9
|
constructor(name: Name, names: Names[]);
|
|
13
|
-
defineModel<N extends Names, T extends Dict<ValidValue<Names>>>(
|
|
10
|
+
defineModel<N extends Names, T extends Dict<ValidValue<Names>>>(model: Model<N, T, FindPrimaryKey<T>>): Model<N, T, FindPrimaryKey<T>>;
|
|
11
|
+
defineModel<N extends Names, T extends Dict<ValidValue<Names>>>(name: N, values: T): Model<N, T, FindPrimaryKey<T>>;
|
|
14
12
|
compile<M extends CollectionObject<Names>>(models: M): CompiledDb<Name, Names, M>;
|
|
15
13
|
}
|
|
16
14
|
export declare class CompiledDb<Name extends string, Names extends string, C extends CollectionObject<Names>> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { CollectionObject } from '../model';
|
|
2
|
+
import { DbClient } from './index.ts';
|
|
3
|
+
import { FindInput, FindOutput } from './types/find.ts';
|
|
4
4
|
export declare class CompiledQuery<Stores extends string, Models extends CollectionObject<string>, Db extends DbClient<string, Stores, Models>, Input extends FindInput<Stores, Models[Stores], Models> = FindInput<Stores, Models[Stores], Models>, Output = FindOutput<Stores, Models[Stores], Models, Input>> {
|
|
5
5
|
private readonly client;
|
|
6
6
|
private readonly name;
|
package/dist/client/delete.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { CollectionObject } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { DbClient } from "./index.js";
|
|
1
|
+
import { CollectionObject, ExtractFields } from '../model';
|
|
2
|
+
import { WhereObject } from './types/find.js';
|
|
3
|
+
import { MutationState } from './types';
|
|
4
|
+
import { DbClient } from './index.js';
|
|
6
5
|
/**
|
|
7
6
|
* Deletes document(s) from a store
|
|
8
7
|
* @param name Name of the store
|
package/dist/client/helpers.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
1
|
+
import { Dict, Promisable } from '../util-types.js';
|
|
2
|
+
import { DbClient } from './index.ts';
|
|
3
|
+
import { QueryInput } from './types/find.ts';
|
|
4
|
+
import { Transaction } from '../transaction.js';
|
|
5
|
+
import { CollectionObject } from '../model';
|
|
6
|
+
type WhereClauseElement = [key: string, isFun: true, fn: (value: unknown) => boolean] | [key: string, isFun: false, value: unknown];
|
|
7
|
+
export declare function generateWhereClause(where?: Dict): WhereClauseElement[];
|
|
8
|
+
/**
|
|
9
|
+
* Parses a WhereClause array and returns if the item passes the checks or not
|
|
10
|
+
* @param whereArray Result of `generateWhereClause()`
|
|
11
|
+
* @param obj Object to check
|
|
12
|
+
* @returns If the object satisfies the where clause or not
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseWhere(whereArray: WhereClauseElement[], obj: unknown): boolean;
|
|
7
15
|
export declare function generateSelector<ModelNames extends string, Models extends CollectionObject<ModelNames>, Db extends DbClient<string, ModelNames, Models>, Q extends QueryInput<ModelNames, any, Models> = QueryInput<ModelNames, any, Models>>(name: ModelNames, client: Db, query?: Q, initTx?: Transaction<IDBTransactionMode, ModelNames>): (item: Dict, tx: Transaction<IDBTransactionMode, ModelNames>) => Promisable<Dict | undefined>;
|
|
8
|
-
export declare function getAccessedStores<ModelNames extends string, Models extends CollectionObject<ModelNames>>(name: ModelNames, query: Dict,
|
|
9
|
-
export declare function getSearchableQuery(q: QueryInput<any, any, any>): import(
|
|
10
|
-
export
|
|
16
|
+
export declare function getAccessedStores<ModelNames extends string, Models extends CollectionObject<ModelNames>>(name: ModelNames, query: Dict, isMutation: boolean, client: DbClient<string, ModelNames, Models>): Set<ModelNames>;
|
|
17
|
+
export declare function getSearchableQuery(q: QueryInput<any, any, any>): import('./types/find.ts').SelectObject<any, any, any>;
|
|
18
|
+
export {};
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { CompiledDb } from '../builder';
|
|
2
|
+
import { Arrayable } from '../util-types';
|
|
3
|
+
import { CollectionObject } from '../model';
|
|
4
|
+
import { Transaction, TransactionOptions } from '../transaction';
|
|
5
|
+
import { InterfaceMap } from './types';
|
|
6
|
+
import { CsvDump, JsonDump } from '../dump/class.js';
|
|
5
7
|
export declare class DbClient<Name extends string, ModelNames extends string, Models extends CollectionObject<ModelNames>> {
|
|
6
8
|
private readonly db;
|
|
7
9
|
private readonly models;
|
|
@@ -9,9 +11,12 @@ export declare class DbClient<Name extends string, ModelNames extends string, Mo
|
|
|
9
11
|
readonly version: number;
|
|
10
12
|
readonly stores: InterfaceMap<ModelNames, Models>;
|
|
11
13
|
constructor(db: IDBDatabase, models: CompiledDb<Name, ModelNames, Models>);
|
|
14
|
+
getDb(): IDBDatabase;
|
|
12
15
|
getStore<Name extends ModelNames>(name: Name): (typeof this.stores)[Name];
|
|
16
|
+
getStoreNames(): ModelNames[];
|
|
13
17
|
createTransaction<Mode extends IDBTransactionMode, Names extends ModelNames>(mode: Mode, stores: Arrayable<Names>, options?: TransactionOptions): Transaction<Mode, Names>;
|
|
14
18
|
deleteDb(): Promise<void>;
|
|
19
|
+
dump<Format extends "json" | "csv", Return = Format extends "json" ? JsonDump : CsvDump>(format: Format, stores?: ModelNames[]): Promise<Return>;
|
|
15
20
|
deleteAllStores(): void;
|
|
16
21
|
deleteStore(storeNames: Arrayable<ModelNames>): void;
|
|
17
22
|
getModel<N extends ModelNames>(name: N): Models[N];
|
|
@@ -29,5 +34,26 @@ export declare class DbClient<Name extends string, ModelNames extends string, Mo
|
|
|
29
34
|
*/
|
|
30
35
|
private find;
|
|
31
36
|
private update;
|
|
32
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Connects a document to another
|
|
39
|
+
*
|
|
40
|
+
* **This must be called within a wrapped environment**
|
|
41
|
+
* @param relation Relation object
|
|
42
|
+
* @param thisId Id of the source document
|
|
43
|
+
* @param documentId If of the target document
|
|
44
|
+
* @param tx Transaction this function is wrapped in
|
|
45
|
+
* @returns Id of the target document
|
|
46
|
+
*/
|
|
47
|
+
private connectDocument;
|
|
48
|
+
/**
|
|
49
|
+
* Disconnects a document from another
|
|
50
|
+
*
|
|
51
|
+
* **This must be called within a wrapped environment**
|
|
52
|
+
* @param relation Relation object
|
|
53
|
+
* @param thisId Id of the source document
|
|
54
|
+
* @param documentId If of the target document
|
|
55
|
+
* @param tx Transaction this function is wrapped in
|
|
56
|
+
* @returns Id of the target document
|
|
57
|
+
*/
|
|
58
|
+
private disconnectDocument;
|
|
33
59
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import type { CollectionObject } from "../../builder.ts";
|
|
1
|
+
import { Dict, If, Keyof, MakeRequired, NoUndefined, RemoveNeverValues, Simplify } from '../../util-types.js';
|
|
2
|
+
import { ExtractFields, ModelStructure, RelationlessModelStructure, RelationValue } from '../../model/model-types';
|
|
3
|
+
import { Model, CollectionObject } from '../../model';
|
|
4
|
+
import { BaseRelation, AbstractProperty, PrimaryKey, RelationOutputStructure, ValidValue, Relation } from '../../field';
|
|
6
5
|
export type FilterFn<Input> = (item: Input) => boolean;
|
|
7
6
|
/**
|
|
8
7
|
* If an property is an object type (dictionary, array, map, set, etc...) return never. If it's a union it strips out any object types
|
|
9
8
|
*/
|
|
10
|
-
export type ProhibitObjects<T> = T extends object ? never : T;
|
|
9
|
+
export type ProhibitObjects<T> = T extends Date ? Date : T extends object ? never : T;
|
|
11
10
|
export type WhereObject<Fields extends Dict<ValidValue>> = Partial<RemoveNeverValues<{
|
|
12
|
-
[K in keyof Fields]: Fields[K] extends AbstractProperty<infer Output, any> ? Output | FilterFn<Output> : Fields[K] extends PrimaryKey<any, infer Type> ? ProhibitObjects<Type> | FilterFn<Type> : never;
|
|
11
|
+
[K in keyof Fields]: Fields[K] extends AbstractProperty<infer Output, any> ? ProhibitObjects<Output> | FilterFn<Output> : Fields[K] extends PrimaryKey<any, infer Type> ? ProhibitObjects<Type> | FilterFn<Type> : never;
|
|
13
12
|
}>>;
|
|
14
13
|
export type SelectObject<All extends string, Fields extends Dict<ValidValue>, C extends CollectionObject<All>> = {
|
|
15
14
|
[K in keyof Fields]?: Fields[K] extends AbstractProperty<any, any> ? true : Fields[K] extends PrimaryKey<any, any> ? true : Fields[K] extends BaseRelation<infer To, any> ? true | (To extends Keyof<C> ? C[To] extends Model<any, infer SubFields, any> ? QueryInput<All, SubFields, C> : never : never) : never;
|
|
@@ -20,8 +19,11 @@ export interface QueryInput<All extends string, Fields extends Dict<ValidValue>,
|
|
|
20
19
|
include?: SelectObject<All, Fields, C>;
|
|
21
20
|
}
|
|
22
21
|
export type FindInput<All extends string, Struct extends object, C extends CollectionObject<All>> = Struct extends Model<any, infer Fields, any> ? QueryInput<All, Fields, C> : never;
|
|
23
|
-
type
|
|
24
|
-
[K in Keyof<Select>]: Fields[K] extends BaseRelation<infer To, any> ? To extends Keyof<C> ? C[To] extends Model<any,
|
|
25
|
-
}
|
|
26
|
-
|
|
22
|
+
type SelectOutput<All extends string, Select extends Dict<Dict | true>, Fields extends Dict<ValidValue>, C extends CollectionObject<All>> = {
|
|
23
|
+
[K in Keyof<Select>]: Fields[K] extends BaseRelation<infer To, any> ? To extends Keyof<C> ? C[To] extends Model<any, any, any> ? If<Select[K] extends true ? true : false, RelationOutputStructure<Fields[K], RelationlessModelStructure<C[To]>>, Select[K] extends FindInput<All, C[To], C> ? RelationOutputStructure<Fields[K], FindOutput<All, C[To], C, Select[K]>> : never> : never : never : Fields[K] extends PrimaryKey<any, infer Type> ? Type : Fields[K] extends AbstractProperty<infer Type, any> ? Type : never;
|
|
24
|
+
};
|
|
25
|
+
type IncludeOutput<All extends string, Include extends Dict<Dict | true>, Fields extends Dict<ValidValue>, C extends CollectionObject<All>> = Simplify<{
|
|
26
|
+
[K in Keyof<Fields>]: Fields[K] extends BaseRelation<infer To, any> ? To extends Keyof<C> ? C[To] extends Model<any, any, any> ? K extends Keyof<Include> ? Include[K] extends true ? RelationOutputStructure<Fields[K], RelationlessModelStructure<C[To]>> : Include[K] extends FindInput<All, C[To], C> ? MakeRequired<Fields[K] extends Relation<any, any> ? true : false, NoUndefined<RelationOutputStructure<Fields[K], NoUndefined<FindOutput<All, C[To], C, Include[K]>>>>> : unknown : RelationOutputStructure<Fields[K], RelationValue<To, C>> : never : never : Fields[K] extends PrimaryKey<any, infer Type> ? Type : Fields[K] extends AbstractProperty<infer Type, any> ? Type : never;
|
|
27
|
+
}>;
|
|
28
|
+
export type FindOutput<All extends string, Struct extends Model<any, any, any>, C extends CollectionObject<All>, F extends FindInput<All, Struct, C>> = Struct extends Model<any, infer Fields, any> ? Simplify<F["select"] extends Dict<true | Dict> ? SelectOutput<All, F["select"], Fields, C> : F["include"] extends Dict<true | Dict> ? IncludeOutput<All, F["include"], Fields, C> : ModelStructure<ExtractFields<Struct>, C>> | undefined : never;
|
|
27
29
|
export {};
|
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
export type
|
|
11
|
-
export
|
|
1
|
+
import { Dict, Simplify } from '../../util-types.js';
|
|
2
|
+
import { ExtractFields, Model, ModelStructure, PrimaryKeyType, CollectionObject } from '../../model';
|
|
3
|
+
import { AddMutation, MutationAction, UpdateMutation } from './mutation.ts';
|
|
4
|
+
import { FindInput, FindOutput, WhereObject } from './find.ts';
|
|
5
|
+
import { CompiledQuery } from '../compiled-query.ts';
|
|
6
|
+
import { DbClient } from '../index.ts';
|
|
7
|
+
import { Transaction } from '../../transaction.js';
|
|
8
|
+
import { BaseRelation, ValidKey } from '../../field';
|
|
9
|
+
import { CsvDump, JsonDump } from '../../dump/class.js';
|
|
10
|
+
export type GetStructure<N extends string, C extends Dict> = C[N] extends Model<N, infer F, any> ? Simplify<ModelStructure<F, C>> : never;
|
|
11
|
+
export type ExportFormat = "json";
|
|
12
|
+
export interface StoreInterface<Name extends Names, Names extends string, C extends CollectionObject<Names>, KeyType = PrimaryKeyType<C[Name]>, Add = AddMutation<Name, Names, C[Name], C>, Update extends UpdateMutation<Name, Names, C[Name], C> = UpdateMutation<Name, Names, C[Name], C>> {
|
|
12
13
|
add(mutation: Add, transaction?: Transaction<"readwrite", Names>): Promise<KeyType>;
|
|
13
14
|
addMany(mutations: Add[], transaction?: Transaction<"readwrite", Names>): Promise<KeyType[]>;
|
|
14
|
-
find<T extends FindInput<Names, C[Name], C>>(query: T, transaction?: Transaction<IDBTransactionMode, Names>): Promise<FindOutput<Names, C[Name], C, T
|
|
15
|
+
find<T extends FindInput<Names, C[Name], C>>(query: T, transaction?: Transaction<IDBTransactionMode, Names>): Promise<NonNullable<FindOutput<Names, C[Name], C, T>>[]>;
|
|
15
16
|
findFirst<T extends FindInput<Names, C[Name], C>>(query: T, transaction?: Transaction<IDBTransactionMode, Names>): Promise<FindOutput<Names, C[Name], C, T>>;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
updateMany(item: Update, transaction?: Transaction<"readwrite", Names>): Promise<KeyType[]>;
|
|
17
|
+
update(key: KeyType, data: Update["data"]): Promise<GetStructure<Name, C>>;
|
|
18
|
+
updateFirst(item: Update, transaction?: Transaction<"readwrite", Names>): Promise<GetStructure<Name, C> | undefined>;
|
|
19
|
+
updateMany(item: Update, transaction?: Transaction<"readwrite", Names>): Promise<GetStructure<Name, C>[]>;
|
|
20
20
|
delete(key: KeyType): Promise<boolean>;
|
|
21
21
|
deleteFirst(where?: WhereObject<ExtractFields<C[Name]>>): Promise<boolean>;
|
|
22
22
|
deleteMany(where: WhereObject<ExtractFields<C[Name]>>): Promise<number>;
|
|
23
|
-
/**
|
|
24
|
-
* Clears a store (does not update any relations)
|
|
25
|
-
*/
|
|
26
|
-
clear(transaction?: Transaction<"readwrite", Names>): Promise<void>;
|
|
27
23
|
compileQuery<T extends FindInput<Names, C[Name], C>>(query: T): CompiledQuery<Names, C, DbClient<string, Names, C>, T>;
|
|
28
|
-
get(key: KeyType): Promise<
|
|
24
|
+
get(key: KeyType): Promise<GetStructure<Name, C> | undefined>;
|
|
25
|
+
dump<Format extends ExportFormat>(format: Format, where?: WhereObject<C[Name] extends Model<any, infer Fields, any> ? Fields : never>): Promise<Format extends "json" ? JsonDump : CsvDump>;
|
|
29
26
|
}
|
|
30
27
|
export type InterfaceMap<Names extends string, C extends CollectionObject<Names>> = {
|
|
31
28
|
[K in Names]: StoreInterface<K, Names, C>;
|
|
@@ -33,10 +30,6 @@ export type InterfaceMap<Names extends string, C extends CollectionObject<Names>
|
|
|
33
30
|
export interface QueryState<Names extends string> {
|
|
34
31
|
tx?: Transaction<IDBTransactionMode, Names>;
|
|
35
32
|
}
|
|
36
|
-
export declare const enum MutationBreath {
|
|
37
|
-
Find = 0,
|
|
38
|
-
Singleton = 1
|
|
39
|
-
}
|
|
40
33
|
export interface MutationState<Names extends string> extends Partial<{
|
|
41
34
|
tx: Transaction<"readwrite", Names>;
|
|
42
35
|
relation: {
|
|
@@ -46,17 +39,25 @@ export interface MutationState<Names extends string> extends Partial<{
|
|
|
46
39
|
singleton: {
|
|
47
40
|
id: ValidKey;
|
|
48
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Flag indicating whether or not this is the final step of the query/mutation
|
|
44
|
+
* @default true
|
|
45
|
+
*/
|
|
49
46
|
finalStep: boolean;
|
|
50
47
|
}> {
|
|
51
48
|
}
|
|
52
|
-
export type
|
|
53
|
-
|
|
49
|
+
export type ActionItem = [action: MutationAction, value: unknown];
|
|
50
|
+
export type KeyObject<Index = string> = ({
|
|
54
51
|
key: Index;
|
|
55
52
|
} & ({
|
|
56
53
|
isRelation: true;
|
|
54
|
+
actions: ActionItem[];
|
|
57
55
|
relation: BaseRelation<any, any>;
|
|
56
|
+
updateFn?: undefined;
|
|
58
57
|
} | {
|
|
59
58
|
isRelation: false;
|
|
59
|
+
actions?: undefined;
|
|
60
60
|
relation?: undefined;
|
|
61
|
-
|
|
61
|
+
updateFn: <T>(value: T) => T;
|
|
62
|
+
}));
|
|
62
63
|
export type { AddMutation, UpdateMutation };
|
|
@@ -1,46 +1,49 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { MakeArrayable, MakeOptional, RemoveNeverValues, PartialOnUndefined, Extends, If, Or, Keyof } from '../../util-types.js';
|
|
2
|
+
import { BaseRelation, AbstractProperty, OptionalRelation, PrimaryKey, ArrayRelation } from '../../field';
|
|
3
|
+
import { WhereObject } from './find.js';
|
|
4
|
+
import { Model, FindRelationKey, RelationValue, CollectionObject } from '../../model';
|
|
5
|
+
export type MutationAction = "$connect" | "$connectMany" | "$create" | "$createMany" | "$update" | "$updateMany" | "$delete" | "$deleteMany" | "$deleteAll" | "$disconnect" | "$disconnectMany" | "$disconnectAll";
|
|
6
|
+
type WhereSelection<Struct extends object> = Struct extends Model<any, infer Fields, any> ? WhereObject<Fields> : never;
|
|
7
|
+
type _UpdateRelationMutation<This extends All, All extends string, C extends CollectionObject<All>, To extends All, Name extends string, Relation extends BaseRelation<To, Name>, ThisKey extends string, OmitKeys extends string, IsOptional extends boolean = Extends<Relation, OptionalRelation<any, any>>, IsArray extends boolean = Extends<Relation, ArrayRelation<any, any>>, IsNullable extends boolean = Or<IsOptional, IsArray>> = MakeOptional<IsNullable, MakeArrayable<IsArray, {
|
|
8
|
+
$connect: RelationValue<To, C>;
|
|
9
|
+
} | {
|
|
10
|
+
$create: Omit<AddMutation<To, All, C[To], C>, OmitKeys | FindRelationKey<This, Name, C[To]>>;
|
|
11
|
+
} | {
|
|
12
|
+
$update: If<IsArray, UpdateMutation<To, All, C[To], C, OmitKeys | ThisKey>, Omit<UpdateMutation<To, All, C[To], C>["data"], OmitKeys>>;
|
|
13
|
+
} | If<IsNullable, {
|
|
14
|
+
$delete: If<IsArray, RelationValue<To, C>, true>;
|
|
15
|
+
} | {
|
|
16
|
+
$disconnect: If<IsArray, RelationValue<To, C>, true>;
|
|
17
|
+
}, never>> | If<IsArray, {
|
|
18
|
+
$connectMany: RelationValue<To, C>[];
|
|
19
|
+
} | {
|
|
20
|
+
$createMany: Omit<AddMutation<To, All, C[To], C>, OmitKeys | FindRelationKey<This, Name, C[To]>>[];
|
|
21
|
+
} | {
|
|
22
|
+
$updateMany: UpdateMutation<To, All, C[To], C, OmitKeys | ThisKey>[];
|
|
23
|
+
} | {
|
|
24
|
+
$deleteMany: RelationValue<To, C>[];
|
|
25
|
+
} | {
|
|
26
|
+
$deleteAll: true;
|
|
27
|
+
} | {
|
|
28
|
+
$disconnectMany: RelationValue<To, C>[];
|
|
29
|
+
} | {
|
|
30
|
+
$disconnectAll: true;
|
|
31
|
+
}, never>>;
|
|
32
|
+
export type UpdateMutation<This extends All, All extends string, Struct extends object, C extends CollectionObject<All>, OmitKeys extends string = never> = {
|
|
33
|
+
where?: WhereSelection<Struct>;
|
|
34
|
+
data: PartialOnUndefined<RemoveNeverValues<Struct extends Model<any, infer Fields, any> ? {
|
|
35
|
+
[K in Exclude<Keyof<Fields>, OmitKeys>]: Fields[K] extends AbstractProperty<infer Type, any> ? Type | undefined | ((value: Type) => Type) : Fields[K] extends PrimaryKey<any, any> ? never : Fields[K] extends BaseRelation<infer To, infer Name> ? To extends All ? _UpdateRelationMutation<This, All, C, To, Name, Fields[K], K, OmitKeys> | undefined : never : never;
|
|
36
|
+
} : never>>;
|
|
37
|
+
};
|
|
38
|
+
export type AddMutation<This extends All, All extends string, Struct extends object, C extends CollectionObject<All>> = PartialOnUndefined<RemoveNeverValues<Struct extends Model<any, infer Fields, any> ? {
|
|
39
|
+
[K in keyof Fields]: Fields[K] extends AbstractProperty<infer Type, infer HasDefault> ? HasDefault extends true ? Type | undefined : Type : Fields[K] extends PrimaryKey<infer IsAuto, infer Type> ? IsAuto extends true ? never : Type : Fields[K] extends BaseRelation<infer To, infer Name> ? To extends All ? MakeOptional<Fields[K] extends OptionalRelation<any, any> ? true : Fields[K] extends ArrayRelation<any, any> ? true : false, MakeArrayable<Fields[K] extends ArrayRelation<any, any> ? true : false, {
|
|
9
40
|
$connect: RelationValue<To, C>;
|
|
10
41
|
} | {
|
|
11
|
-
$create: Omit<
|
|
12
|
-
} | (
|
|
13
|
-
$update: Fields[K] extends ArrayRelation<any, any> ? {
|
|
14
|
-
where?: WhereSelection<C[To]>;
|
|
15
|
-
data: Mutation<To, All, C[To], C, MutType>;
|
|
16
|
-
} : Mutation<To, All, C[To], C, MutType>;
|
|
17
|
-
} | {
|
|
18
|
-
$delete: Fields[K] extends ArrayRelation<any, any> ? RelationValue<To, C> : true;
|
|
19
|
-
} | {
|
|
20
|
-
$disconnect: Fields[K] extends ArrayRelation<any, any> ? RelationValue<To, C> : true;
|
|
21
|
-
} : never)> | (Fields[K] extends ArrayRelation<any, any> ? {
|
|
42
|
+
$create: Omit<AddMutation<To, All, C[To], C>, FindRelationKey<This, Name, C[To]>>;
|
|
43
|
+
}> | (Fields[K] extends ArrayRelation<any, any> ? {
|
|
22
44
|
$connectMany: RelationValue<To, C>[];
|
|
23
45
|
} | {
|
|
24
|
-
$createMany: Omit<
|
|
25
|
-
} | {
|
|
26
|
-
$updateMany: {
|
|
27
|
-
where?: WhereSelection<C[To]>;
|
|
28
|
-
data: Mutation<To, All, C[To], C, MutType>;
|
|
29
|
-
}[];
|
|
30
|
-
} | {
|
|
31
|
-
$deleteMany: RelationValue<To, C>[];
|
|
32
|
-
} | {
|
|
33
|
-
$deleteAll: true;
|
|
34
|
-
} | {
|
|
35
|
-
$disconnectMany: RelationValue<To, C>[];
|
|
36
|
-
} | {
|
|
37
|
-
$disconnectAll: true;
|
|
46
|
+
$createMany: Omit<AddMutation<To, All, C[To], C>, FindRelationKey<This, Name, C[To]>>[];
|
|
38
47
|
} : never)> : never : never;
|
|
39
48
|
} : never>>;
|
|
40
|
-
export type AddMutation<This extends All, All extends string, Struct extends object, C extends CollectionObject<All>> = Mutation<This, All, Struct, C, "add">;
|
|
41
|
-
export interface UpdateMutation<This extends All, All extends string, Struct extends object, C extends CollectionObject<All>> {
|
|
42
|
-
where?: WhereSelection<Struct>;
|
|
43
|
-
data: Mutation<This, All, Struct, C, "update">;
|
|
44
|
-
}
|
|
45
|
-
type WhereSelection<Struct extends object> = Struct extends Model<any, infer Fields, any> ? WhereObject<Fields> : never;
|
|
46
49
|
export {};
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { AbstractProperty } from './field/property';
|
|
2
|
+
export type { ParseFn, PropertyOptions, PropertyInputOptions, } from './field/property';
|
|
3
|
+
export type { PropertyUnion } from './field/field-types';
|
|
4
|
+
export * from './util-types';
|
|
5
|
+
export { Model } from './model';
|
|
6
|
+
export type { FindPrimaryKey } from './model';
|
|
7
|
+
export { VALIDATORS } from './field/validators.js';
|
|
8
|
+
export * from './field';
|
|
9
|
+
export * from './client';
|
|
10
|
+
export { Type } from './field/type-wrapper';
|
|
11
|
+
export type { TypeTag } from './field/type-wrapper';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Arrayable, Dict } from '../util-types';
|
|
2
|
+
declare abstract class Dump<T> {
|
|
3
|
+
protected readonly name: string;
|
|
4
|
+
protected readonly content: T;
|
|
5
|
+
protected readonly extension: string;
|
|
6
|
+
constructor(name: string, content: T, extension: string);
|
|
7
|
+
abstract getValue(): T;
|
|
8
|
+
abstract toFile(filename?: string, options?: FilePropertyBag): File;
|
|
9
|
+
download(filename?: string, options?: FilePropertyBag): void;
|
|
10
|
+
}
|
|
11
|
+
type JsonValue = Arrayable<Dict>;
|
|
12
|
+
export declare class JsonDump extends Dump<JsonValue> {
|
|
13
|
+
constructor(name: string, content: JsonValue);
|
|
14
|
+
getValue(): JsonValue;
|
|
15
|
+
toFile(filename?: string, options?: FilePropertyBag): File;
|
|
16
|
+
}
|
|
17
|
+
export declare class CsvDump extends Dump<string> {
|
|
18
|
+
constructor(name: string, content: string);
|
|
19
|
+
getValue(): string;
|
|
20
|
+
toFile(filename?: string, options?: FilePropertyBag): File;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WhereObject } from '../client/types/find.js';
|
|
2
|
+
import { Dict } from '../util-types';
|
|
3
|
+
import { DbClient } from '../client';
|
|
4
|
+
import { ValidValue } from '../field';
|
|
5
|
+
import { CollectionObject } from '../model';
|
|
6
|
+
import { Transaction } from '../transaction.js';
|
|
7
|
+
import { JsonDump } from './class.js';
|
|
8
|
+
export declare function dumpStoreToJson<Current extends Names, Names extends string, Models extends CollectionObject<Names>>(db: DbClient<string, Names, CollectionObject<Names>>, store: Current, where?: WhereObject<Models[Current] extends Dict<ValidValue> ? Models[Current] : never>, tx?: Transaction<"readonly", Names>): Promise<JsonDump>;
|
|
9
|
+
export declare function dumpDatabaseToJSON<Names extends string>(db: DbClient<string, Names, any>, stores?: Names[]): Promise<JsonDump>;
|
package/dist/error.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ErrorType = "ID_EXISTS" | "INVALID_ITEM" | "ADD_FAILED" | "UPDATE_FAILED" | "DELETE_FAILED" | "OVERWRITE_RELATION" | "NOT_FOUND" | "GET_FAILED"
|
|
1
|
+
export type ErrorType = "ID_EXISTS" | "INVALID_ITEM" | "ADD_FAILED" | "UPDATE_FAILED" | "DELETE_FAILED" | "OVERWRITE_RELATION" | "NOT_FOUND" | "GET_FAILED" | "EXPORT"
|
|
2
2
|
/**
|
|
3
3
|
* The given transaction is invalid for the store it is trying to access
|
|
4
4
|
*/
|
|
@@ -9,14 +9,13 @@ export type ErrorType = "ID_EXISTS" | "INVALID_ITEM" | "ADD_FAILED" | "UPDATE_FA
|
|
|
9
9
|
| "NO_DB" | "CUSTOM" | "INVALID_CONFIG" | "ASSERTION_FAILED" | "OPEN_CURSOR" | "UNKNOWN";
|
|
10
10
|
export declare class StoreError extends Error {
|
|
11
11
|
readonly code: ErrorType;
|
|
12
|
-
readonly message: string;
|
|
13
12
|
constructor(code: ErrorType, message: string);
|
|
14
13
|
}
|
|
15
14
|
export declare const InvalidConfigError: {
|
|
16
15
|
new (message?: string): {
|
|
17
16
|
readonly code: ErrorType;
|
|
18
|
-
readonly message: string;
|
|
19
17
|
name: string;
|
|
18
|
+
message: string;
|
|
20
19
|
stack?: string;
|
|
21
20
|
cause?: unknown;
|
|
22
21
|
};
|
|
@@ -30,8 +29,8 @@ export declare const InvalidConfigError: {
|
|
|
30
29
|
export declare const InvalidTransactionError: {
|
|
31
30
|
new (message?: string): {
|
|
32
31
|
readonly code: ErrorType;
|
|
33
|
-
readonly message: string;
|
|
34
32
|
name: string;
|
|
33
|
+
message: string;
|
|
35
34
|
stack?: string;
|
|
36
35
|
cause?: unknown;
|
|
37
36
|
};
|
|
@@ -45,8 +44,8 @@ export declare const InvalidTransactionError: {
|
|
|
45
44
|
export declare const InvalidItemError: {
|
|
46
45
|
new (message?: string): {
|
|
47
46
|
readonly code: ErrorType;
|
|
48
|
-
readonly message: string;
|
|
49
47
|
name: string;
|
|
48
|
+
message: string;
|
|
50
49
|
stack?: string;
|
|
51
50
|
cause?: unknown;
|
|
52
51
|
};
|
|
@@ -60,8 +59,8 @@ export declare const InvalidItemError: {
|
|
|
60
59
|
export declare const AssertionError: {
|
|
61
60
|
new (message?: string): {
|
|
62
61
|
readonly code: ErrorType;
|
|
63
|
-
readonly message: string;
|
|
64
62
|
name: string;
|
|
63
|
+
message: string;
|
|
65
64
|
stack?: string;
|
|
66
65
|
cause?: unknown;
|
|
67
66
|
};
|
|
@@ -75,8 +74,8 @@ export declare const AssertionError: {
|
|
|
75
74
|
export declare const UnknownError: {
|
|
76
75
|
new (message?: string): {
|
|
77
76
|
readonly code: ErrorType;
|
|
78
|
-
readonly message: string;
|
|
79
77
|
name: string;
|
|
78
|
+
message: string;
|
|
80
79
|
stack?: string;
|
|
81
80
|
cause?: unknown;
|
|
82
81
|
};
|
|
@@ -90,8 +89,8 @@ export declare const UnknownError: {
|
|
|
90
89
|
export declare const DeleteError: {
|
|
91
90
|
new (message?: string): {
|
|
92
91
|
readonly code: ErrorType;
|
|
93
|
-
readonly message: string;
|
|
94
92
|
name: string;
|
|
93
|
+
message: string;
|
|
95
94
|
stack?: string;
|
|
96
95
|
cause?: unknown;
|
|
97
96
|
};
|
|
@@ -105,8 +104,8 @@ export declare const DeleteError: {
|
|
|
105
104
|
export declare const ObjectStoreNotFoundError: {
|
|
106
105
|
new (message?: string): {
|
|
107
106
|
readonly code: ErrorType;
|
|
108
|
-
readonly message: string;
|
|
109
107
|
name: string;
|
|
108
|
+
message: string;
|
|
110
109
|
stack?: string;
|
|
111
110
|
cause?: unknown;
|
|
112
111
|
};
|
|
@@ -120,8 +119,8 @@ export declare const ObjectStoreNotFoundError: {
|
|
|
120
119
|
export declare const DocumentNotFoundError: {
|
|
121
120
|
new (message?: string): {
|
|
122
121
|
readonly code: ErrorType;
|
|
123
|
-
readonly message: string;
|
|
124
122
|
name: string;
|
|
123
|
+
message: string;
|
|
125
124
|
stack?: string;
|
|
126
125
|
cause?: unknown;
|
|
127
126
|
};
|
|
@@ -135,8 +134,8 @@ export declare const DocumentNotFoundError: {
|
|
|
135
134
|
export declare const UpdateError: {
|
|
136
135
|
new (message?: string): {
|
|
137
136
|
readonly code: ErrorType;
|
|
138
|
-
readonly message: string;
|
|
139
137
|
name: string;
|
|
138
|
+
message: string;
|
|
140
139
|
stack?: string;
|
|
141
140
|
cause?: unknown;
|
|
142
141
|
};
|
|
@@ -150,8 +149,8 @@ export declare const UpdateError: {
|
|
|
150
149
|
export declare const AddError: {
|
|
151
150
|
new (message?: string): {
|
|
152
151
|
readonly code: ErrorType;
|
|
153
|
-
readonly message: string;
|
|
154
152
|
name: string;
|
|
153
|
+
message: string;
|
|
155
154
|
stack?: string;
|
|
156
155
|
cause?: unknown;
|
|
157
156
|
};
|
|
@@ -165,8 +164,8 @@ export declare const AddError: {
|
|
|
165
164
|
export declare const OpenCursorError: {
|
|
166
165
|
new (message?: string): {
|
|
167
166
|
readonly code: ErrorType;
|
|
168
|
-
readonly message: string;
|
|
169
167
|
name: string;
|
|
168
|
+
message: string;
|
|
170
169
|
stack?: string;
|
|
171
170
|
cause?: unknown;
|
|
172
171
|
};
|
|
@@ -180,8 +179,8 @@ export declare const OpenCursorError: {
|
|
|
180
179
|
export declare const RetrievalError: {
|
|
181
180
|
new (message?: string): {
|
|
182
181
|
readonly code: ErrorType;
|
|
183
|
-
readonly message: string;
|
|
184
182
|
name: string;
|
|
183
|
+
message: string;
|
|
185
184
|
stack?: string;
|
|
186
185
|
cause?: unknown;
|
|
187
186
|
};
|
|
@@ -192,3 +191,33 @@ export declare const RetrievalError: {
|
|
|
192
191
|
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
193
192
|
stackTraceLimit: number;
|
|
194
193
|
};
|
|
194
|
+
export declare const OverwriteRelationError: {
|
|
195
|
+
new (message?: string): {
|
|
196
|
+
readonly code: ErrorType;
|
|
197
|
+
name: string;
|
|
198
|
+
message: string;
|
|
199
|
+
stack?: string;
|
|
200
|
+
cause?: unknown;
|
|
201
|
+
};
|
|
202
|
+
readonly code: "OVERWRITE_RELATION";
|
|
203
|
+
of(message: string): void;
|
|
204
|
+
isError(error: unknown): error is Error;
|
|
205
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
206
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
207
|
+
stackTraceLimit: number;
|
|
208
|
+
};
|
|
209
|
+
export declare const ExportError: {
|
|
210
|
+
new (message?: string): {
|
|
211
|
+
readonly code: ErrorType;
|
|
212
|
+
name: string;
|
|
213
|
+
message: string;
|
|
214
|
+
stack?: string;
|
|
215
|
+
cause?: unknown;
|
|
216
|
+
};
|
|
217
|
+
readonly code: "EXPORT";
|
|
218
|
+
of(message: string): void;
|
|
219
|
+
isError(error: unknown): error is Error;
|
|
220
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
221
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
222
|
+
stackTraceLimit: number;
|
|
223
|
+
};
|