@idb-orm/core 1.0.3 → 1.0.4
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 +4 -0
- package/dist/client/compiled-query.d.ts +4 -14
- package/dist/client/delete.d.ts +14 -0
- package/dist/client/helpers.d.ts +1 -2
- package/dist/client/index.d.ts +4 -32
- package/dist/client/types/find.d.ts +15 -99
- package/dist/client/types/index.d.ts +41 -77
- package/dist/client/types/mutation.d.ts +41 -220
- package/dist/field/property.d.ts +70 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/model-types.d.ts +24 -111
- package/dist/model/model.d.ts +5 -23
- package/dist/object-store.d.ts +1 -2
- package/dist/transaction.d.ts +11 -22
- package/dist/types/common.d.ts +4 -1
- package/dist/utils.d.ts +1 -2
- package/package.json +1 -1
- package/eslint.config.js +0 -55
- package/playwright.config.ts +0 -79
- package/tests/helpers.ts +0 -72
- package/tests/test.spec.ts +0 -101
package/README.md
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import type { CollectionObject } from "../builder";
|
|
2
|
-
import type { DbClient } from "./index";
|
|
3
|
-
import type { FindInput, FindOutput } from "./types/find";
|
|
4
|
-
export declare class CompiledQuery<
|
|
5
|
-
Stores extends string,
|
|
6
|
-
Models extends CollectionObject<string>,
|
|
7
|
-
Db extends DbClient<string, Stores, Models>,
|
|
8
|
-
Input extends FindInput<Stores, Models[Stores], Models> = FindInput<
|
|
9
|
-
Stores,
|
|
10
|
-
Models[Stores],
|
|
11
|
-
Models
|
|
12
|
-
>,
|
|
13
|
-
Output = FindOutput<Stores, Models[Stores], Models, Input>
|
|
14
|
-
> {
|
|
1
|
+
import type { CollectionObject } from "../builder.ts";
|
|
2
|
+
import type { DbClient } from "./index.ts";
|
|
3
|
+
import type { FindInput, FindOutput } from "./types/find.ts";
|
|
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>> {
|
|
15
5
|
private readonly client;
|
|
16
6
|
private readonly name;
|
|
17
7
|
private readonly accessedStores;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CollectionObject } from "../builder.js";
|
|
2
|
+
import { ExtractFields } from "../model/model-types.js";
|
|
3
|
+
import { WhereObject } from "./types/find.js";
|
|
4
|
+
import { MutationState } from "./types";
|
|
5
|
+
import { DbClient } from "./index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Deletes document(s) from a store
|
|
8
|
+
* @param name Name of the store
|
|
9
|
+
* @param client DbClient object
|
|
10
|
+
* @param stopOnFirst Stop after the first deletion
|
|
11
|
+
* @param _state Optional state for multi-stage actions
|
|
12
|
+
* @returns Number of items removed
|
|
13
|
+
*/
|
|
14
|
+
export declare function deleteItems<ModelNames extends string, Name extends ModelNames, Models extends CollectionObject<ModelNames>>(name: Name, client: DbClient<string, ModelNames, Models>, where?: WhereObject<ExtractFields<Models[Name]>>, stopOnFirst?: boolean, _state?: MutationState<ModelNames>): Promise<number>;
|
package/dist/client/helpers.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { Dict } from "../types/common.js";
|
|
1
|
+
import type { Dict, Promisable } from "../types/common.js";
|
|
2
2
|
import type { DbClient } from "./index.ts";
|
|
3
3
|
import type { CollectionObject } from "../builder.ts";
|
|
4
4
|
import type { QueryInput } from "./types/find.ts";
|
|
5
5
|
import type { Transaction } from "../transaction.js";
|
|
6
|
-
import type { Promisable } from "type-fest";
|
|
7
6
|
export declare function generateWhereClause(where?: Dict): (obj: unknown) => boolean;
|
|
8
7
|
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>;
|
|
9
8
|
export declare function getAccessedStores<ModelNames extends string, Models extends CollectionObject<ModelNames>>(name: ModelNames, query: Dict, type: "mutation" | "query", client: DbClient<string, ModelNames, Models>): Set<ModelNames>;
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type { Arrayable } from "type-fest";
|
|
2
1
|
import type { CollectionObject, CompiledDb } from "../builder";
|
|
2
|
+
import type { Arrayable } from "../types/common";
|
|
3
3
|
import { Transaction, type TransactionOptions } from "../transaction";
|
|
4
|
-
import type
|
|
5
|
-
export declare class DbClient<
|
|
6
|
-
Name extends string,
|
|
7
|
-
ModelNames extends string,
|
|
8
|
-
Models extends CollectionObject<ModelNames>
|
|
9
|
-
> {
|
|
4
|
+
import { type InterfaceMap } from "./types";
|
|
5
|
+
export declare class DbClient<Name extends string, ModelNames extends string, Models extends CollectionObject<ModelNames>> {
|
|
10
6
|
private readonly db;
|
|
11
7
|
private readonly models;
|
|
12
8
|
readonly name: Name;
|
|
@@ -14,14 +10,7 @@ export declare class DbClient<
|
|
|
14
10
|
readonly stores: InterfaceMap<ModelNames, Models>;
|
|
15
11
|
constructor(db: IDBDatabase, models: CompiledDb<Name, ModelNames, Models>);
|
|
16
12
|
getStore<Name extends ModelNames>(name: Name): (typeof this.stores)[Name];
|
|
17
|
-
createTransaction<
|
|
18
|
-
Mode extends IDBTransactionMode,
|
|
19
|
-
Names extends ModelNames
|
|
20
|
-
>(
|
|
21
|
-
mode: Mode,
|
|
22
|
-
stores: Arrayable<Names>,
|
|
23
|
-
options?: TransactionOptions
|
|
24
|
-
): Transaction<Mode, Names>;
|
|
13
|
+
createTransaction<Mode extends IDBTransactionMode, Names extends ModelNames>(mode: Mode, stores: Arrayable<Names>, options?: TransactionOptions): Transaction<Mode, Names>;
|
|
25
14
|
deleteDb(): Promise<void>;
|
|
26
15
|
deleteAllStores(): void;
|
|
27
16
|
deleteStore(storeNames: Arrayable<ModelNames>): void;
|
|
@@ -30,23 +19,6 @@ export declare class DbClient<
|
|
|
30
19
|
private createInterface;
|
|
31
20
|
private add;
|
|
32
21
|
private clear;
|
|
33
|
-
/**
|
|
34
|
-
* Deletes a single document from a store given its Primary key value
|
|
35
|
-
* @param name Name of the store
|
|
36
|
-
* @param key Primary key value
|
|
37
|
-
* @param _state Optional state for multi-stage actions
|
|
38
|
-
* @returns Boolean indicating whether or not an item was removed
|
|
39
|
-
*/
|
|
40
|
-
private deleteSingleton;
|
|
41
|
-
/**
|
|
42
|
-
* Deletes documents from the store that match the given filter.
|
|
43
|
-
* @param name Name of the store
|
|
44
|
-
* @param where Optional filter
|
|
45
|
-
* @param stopOnFirst Flag to stop after one successful deletion
|
|
46
|
-
* @param _state Optional state for multi-stage actions
|
|
47
|
-
* @returns The number of documents deleted
|
|
48
|
-
*/
|
|
49
|
-
private delete;
|
|
50
22
|
/**
|
|
51
23
|
* Finds documents from the store that match the filter
|
|
52
24
|
* @param name Name of the store
|
|
@@ -1,107 +1,23 @@
|
|
|
1
1
|
import type { Dict, If, Keyof, RemoveNeverValues } from "../../types/common.js";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "../../model/model-types.js";
|
|
7
|
-
import type { Model } from "../../model/index";
|
|
8
|
-
import type {
|
|
9
|
-
BaseRelation,
|
|
10
|
-
Field,
|
|
11
|
-
PrimaryKey,
|
|
12
|
-
RelationOutputStructure,
|
|
13
|
-
ValidValue,
|
|
14
|
-
} from "../../field/index";
|
|
15
|
-
import type { CollectionObject } from "../../builder";
|
|
2
|
+
import type { ExtractFields, ModelStructure, RelationlessModelStructure } from "../../model/model-types.js";
|
|
3
|
+
import type { Model } from "../../model";
|
|
4
|
+
import type { BaseRelation, Field, PrimaryKey, RelationOutputStructure, ValidValue } from "../../field";
|
|
5
|
+
import type { CollectionObject } from "../../builder.ts";
|
|
16
6
|
export type FilterFn<Input> = (item: Input) => boolean;
|
|
17
|
-
export type WhereObject<Fields extends Dict<ValidValue>> = Partial<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
? Type | FilterFn<Type>
|
|
23
|
-
: never;
|
|
24
|
-
}>
|
|
25
|
-
>;
|
|
26
|
-
export type SelectObject<
|
|
27
|
-
All extends string,
|
|
28
|
-
Fields extends Dict<ValidValue>,
|
|
29
|
-
C extends CollectionObject<All>
|
|
30
|
-
> = {
|
|
31
|
-
[K in keyof Fields]?: Fields[K] extends Field<any, any>
|
|
32
|
-
? true
|
|
33
|
-
: Fields[K] extends PrimaryKey<any, any>
|
|
34
|
-
? true
|
|
35
|
-
: Fields[K] extends BaseRelation<infer To, any>
|
|
36
|
-
?
|
|
37
|
-
| true
|
|
38
|
-
| (To extends Keyof<C>
|
|
39
|
-
? C[To] extends Model<any, infer SubFields, any>
|
|
40
|
-
? QueryInput<All, SubFields, C>
|
|
41
|
-
: never
|
|
42
|
-
: never)
|
|
43
|
-
: never;
|
|
7
|
+
export type WhereObject<Fields extends Dict<ValidValue>> = Partial<RemoveNeverValues<{
|
|
8
|
+
[K in keyof Fields]: Fields[K] extends Field<infer Output, any> ? Output | FilterFn<Output> : Fields[K] extends PrimaryKey<any, infer Type> ? Type | FilterFn<Type> : never;
|
|
9
|
+
}>>;
|
|
10
|
+
export type SelectObject<All extends string, Fields extends Dict<ValidValue>, C extends CollectionObject<All>> = {
|
|
11
|
+
[K in keyof Fields]?: Fields[K] extends Field<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;
|
|
44
12
|
};
|
|
45
|
-
export interface QueryInput<
|
|
46
|
-
All extends string,
|
|
47
|
-
Fields extends Dict<ValidValue>,
|
|
48
|
-
C extends CollectionObject<All>
|
|
49
|
-
> {
|
|
13
|
+
export interface QueryInput<All extends string, Fields extends Dict<ValidValue>, C extends CollectionObject<All>> {
|
|
50
14
|
where?: WhereObject<Fields>;
|
|
51
15
|
select?: SelectObject<All, Fields, C>;
|
|
52
16
|
include?: SelectObject<All, Fields, C>;
|
|
53
17
|
}
|
|
54
|
-
export type FindInput<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
? QueryInput<All, Fields, C>
|
|
60
|
-
: never;
|
|
61
|
-
type _FindOutput<
|
|
62
|
-
All extends string,
|
|
63
|
-
Select extends Dict<Dict | true>,
|
|
64
|
-
Fields extends Dict<ValidValue>,
|
|
65
|
-
C extends CollectionObject<All>
|
|
66
|
-
> =
|
|
67
|
-
| {
|
|
68
|
-
[K in Keyof<Select>]: Fields[K] extends BaseRelation<infer To, any>
|
|
69
|
-
? To extends Keyof<C>
|
|
70
|
-
? C[To] extends Model<any, infer Sub, any>
|
|
71
|
-
? If<
|
|
72
|
-
Select[K] extends true ? true : false,
|
|
73
|
-
RelationOutputStructure<
|
|
74
|
-
Fields[K],
|
|
75
|
-
RelationlessModelStructure<C[To]>
|
|
76
|
-
>,
|
|
77
|
-
Select[K] extends Dict<Dict | true>
|
|
78
|
-
? RelationOutputStructure<
|
|
79
|
-
Fields[K],
|
|
80
|
-
_FindOutput<All, Select[K], Sub, C>
|
|
81
|
-
>
|
|
82
|
-
: never
|
|
83
|
-
>
|
|
84
|
-
: never
|
|
85
|
-
: never
|
|
86
|
-
: Fields[K] extends PrimaryKey<any, infer Type>
|
|
87
|
-
? Type
|
|
88
|
-
: Fields[K] extends Field<infer Type, any>
|
|
89
|
-
? Type
|
|
90
|
-
: never;
|
|
91
|
-
}
|
|
92
|
-
| undefined;
|
|
93
|
-
export type FindOutput<
|
|
94
|
-
All extends string,
|
|
95
|
-
Struct extends Model<any, any, any>,
|
|
96
|
-
C extends CollectionObject<All>,
|
|
97
|
-
F extends FindInput<All, Struct, C>
|
|
98
|
-
> = Struct extends Model<any, infer Fields, any>
|
|
99
|
-
? F extends object
|
|
100
|
-
?
|
|
101
|
-
| (F["select"] extends Dict<true | Dict>
|
|
102
|
-
? _FindOutput<All, F["select"], Fields, C>
|
|
103
|
-
: ModelStructure<ExtractFields<Struct>, C>)
|
|
104
|
-
| undefined
|
|
105
|
-
: never
|
|
106
|
-
: never;
|
|
18
|
+
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;
|
|
19
|
+
type _FindOutput<All extends string, Select extends Dict<Dict | true>, Fields extends Dict<ValidValue>, C extends CollectionObject<All>> = {
|
|
20
|
+
[K in Keyof<Select>]: Fields[K] extends BaseRelation<infer To, any> ? To extends Keyof<C> ? C[To] extends Model<any, infer Sub, any> ? If<Select[K] extends true ? true : false, RelationOutputStructure<Fields[K], RelationlessModelStructure<C[To]>>, Select[K] extends Dict<Dict | true> ? RelationOutputStructure<Fields[K], _FindOutput<All, Select[K], Sub, C>> : never> : never : never : Fields[K] extends PrimaryKey<any, infer Type> ? Type : Fields[K] extends Field<infer Type, any> ? Type : never;
|
|
21
|
+
} | undefined;
|
|
22
|
+
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> ? F extends object ? (F["select"] extends Dict<true | Dict> ? _FindOutput<All, F["select"], Fields, C> : ModelStructure<ExtractFields<Struct>, C>) | undefined : never : never;
|
|
107
23
|
export {};
|
|
@@ -1,58 +1,22 @@
|
|
|
1
|
-
import type { CollectionObject } from "../../builder";
|
|
1
|
+
import type { CollectionObject } from "../../builder.ts";
|
|
2
2
|
import type { Dict, ValidKey } from "../../types/common.js";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "../../model/index";
|
|
9
|
-
import type { AddMutation, UpdateMutation } from "./mutation";
|
|
10
|
-
import type { FindInput, FindOutput, WhereObject } from "./find";
|
|
11
|
-
import type { CompiledQuery } from "../compiled-query";
|
|
12
|
-
import type { DbClient } from "../index";
|
|
3
|
+
import type { ExtractFields, Model, ModelStructure, PrimaryKeyType } from "../../model";
|
|
4
|
+
import type { AddMutation, UpdateMutation } from "./mutation.ts";
|
|
5
|
+
import type { FindInput, FindOutput, WhereObject } from "./find.ts";
|
|
6
|
+
import type { CompiledQuery } from "../compiled-query.ts";
|
|
7
|
+
import type { DbClient } from "../index.ts";
|
|
13
8
|
import { Transaction } from "../../transaction.js";
|
|
14
|
-
import { BaseRelation } from "../../field
|
|
15
|
-
export type InsertMutation<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Names extends string,
|
|
22
|
-
C extends CollectionObject<Names>,
|
|
23
|
-
KeyType = PrimaryKeyType<C[Name]>,
|
|
24
|
-
Add = AddMutation<Name, Names, C[Name], C>,
|
|
25
|
-
Update = UpdateMutation<Name, Names, C[Name], C>
|
|
26
|
-
> {
|
|
27
|
-
add(
|
|
28
|
-
mutation: Add,
|
|
29
|
-
transaction?: Transaction<"readwrite", Names>
|
|
30
|
-
): Promise<KeyType>;
|
|
31
|
-
addMany(
|
|
32
|
-
mutations: Add[],
|
|
33
|
-
transaction?: Transaction<"readwrite", Names>
|
|
34
|
-
): Promise<KeyType[]>;
|
|
35
|
-
find<T extends FindInput<Names, C[Name], C>>(
|
|
36
|
-
query: T,
|
|
37
|
-
transaction?: Transaction<IDBTransactionMode, Names>
|
|
38
|
-
): Promise<FindOutput<Names, C[Name], C, T>[]>;
|
|
39
|
-
findFirst<T extends FindInput<Names, C[Name], C>>(
|
|
40
|
-
query: T,
|
|
41
|
-
transaction?: Transaction<IDBTransactionMode, Names>
|
|
42
|
-
): Promise<FindOutput<Names, C[Name], C, T>>;
|
|
9
|
+
import { BaseRelation } from "../../field";
|
|
10
|
+
export type InsertMutation<N extends string, C extends Dict> = C[N] extends Model<N, infer F, any> ? ModelStructure<F, C> : never;
|
|
11
|
+
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 = UpdateMutation<Name, Names, C[Name], C>> {
|
|
12
|
+
add(mutation: Add, transaction?: Transaction<"readwrite", Names>): Promise<KeyType>;
|
|
13
|
+
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
|
+
findFirst<T extends FindInput<Names, C[Name], C>>(query: T, transaction?: Transaction<IDBTransactionMode, Names>): Promise<FindOutput<Names, C[Name], C, T>>;
|
|
43
16
|
put(): Promise<void>;
|
|
44
|
-
insert(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
): Promise<KeyType>;
|
|
48
|
-
updateFirst(
|
|
49
|
-
item: Update,
|
|
50
|
-
transaction?: Transaction<"readwrite", Names>
|
|
51
|
-
): Promise<KeyType | undefined>;
|
|
52
|
-
updateMany(
|
|
53
|
-
item: Update,
|
|
54
|
-
transaction?: Transaction<"readwrite", Names>
|
|
55
|
-
): Promise<KeyType[]>;
|
|
17
|
+
insert(item: InsertMutation<Name, C>, transaction?: Transaction<"readwrite", Names>): Promise<KeyType>;
|
|
18
|
+
updateFirst(item: Update, transaction?: Transaction<"readwrite", Names>): Promise<KeyType | undefined>;
|
|
19
|
+
updateMany(item: Update, transaction?: Transaction<"readwrite", Names>): Promise<KeyType[]>;
|
|
56
20
|
delete(key: KeyType): Promise<boolean>;
|
|
57
21
|
deleteFirst(where?: WhereObject<ExtractFields<C[Name]>>): Promise<boolean>;
|
|
58
22
|
deleteMany(where: WhereObject<ExtractFields<C[Name]>>): Promise<number>;
|
|
@@ -60,39 +24,39 @@ export interface StoreInterface<
|
|
|
60
24
|
* Clears a store (does not update any relations)
|
|
61
25
|
*/
|
|
62
26
|
clear(transaction?: Transaction<"readwrite", Names>): Promise<void>;
|
|
63
|
-
compileQuery<T extends FindInput<Names, C[Name], C>>(
|
|
64
|
-
query: T
|
|
65
|
-
): CompiledQuery<Names, C, DbClient<string, Names, C>, T>;
|
|
27
|
+
compileQuery<T extends FindInput<Names, C[Name], C>>(query: T): CompiledQuery<Names, C, DbClient<string, Names, C>, T>;
|
|
66
28
|
get(key: KeyType): Promise<any>;
|
|
67
29
|
}
|
|
68
|
-
export type InterfaceMap<
|
|
69
|
-
Names extends string,
|
|
70
|
-
C extends CollectionObject<Names>
|
|
71
|
-
> = {
|
|
30
|
+
export type InterfaceMap<Names extends string, C extends CollectionObject<Names>> = {
|
|
72
31
|
[K in Names]: StoreInterface<K, Names, C>;
|
|
73
32
|
};
|
|
74
33
|
export interface QueryState<Names extends string> {
|
|
75
34
|
tx?: Transaction<IDBTransactionMode, Names>;
|
|
76
35
|
}
|
|
77
|
-
export
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
36
|
+
export declare const enum MutationBreath {
|
|
37
|
+
Find = 0,
|
|
38
|
+
Singleton = 1
|
|
39
|
+
}
|
|
40
|
+
export interface MutationState<Names extends string> extends Partial<{
|
|
41
|
+
tx: Transaction<"readwrite", Names>;
|
|
42
|
+
relation: {
|
|
43
|
+
id: ValidKey;
|
|
44
|
+
key: string;
|
|
45
|
+
};
|
|
46
|
+
singleton: {
|
|
47
|
+
id: ValidKey;
|
|
48
|
+
};
|
|
49
|
+
finalStep: boolean;
|
|
50
|
+
}> {
|
|
51
|
+
}
|
|
85
52
|
export type KeyObject<Index = string> = {
|
|
86
53
|
isFun: boolean;
|
|
87
54
|
key: Index;
|
|
88
|
-
} & (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
relation?: undefined;
|
|
96
|
-
}
|
|
97
|
-
);
|
|
55
|
+
} & ({
|
|
56
|
+
isRelation: true;
|
|
57
|
+
relation: BaseRelation<any, any>;
|
|
58
|
+
} | {
|
|
59
|
+
isRelation: false;
|
|
60
|
+
relation?: undefined;
|
|
61
|
+
});
|
|
98
62
|
export type { AddMutation, UpdateMutation };
|
|
@@ -1,225 +1,46 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
RemoveNeverValues,
|
|
5
|
-
PartialOnUndefined,
|
|
6
|
-
} from "../../types/common.js";
|
|
7
|
-
import type {
|
|
8
|
-
BaseRelation,
|
|
9
|
-
Field,
|
|
10
|
-
OptionalRelation,
|
|
11
|
-
PrimaryKey,
|
|
12
|
-
RelationArray,
|
|
13
|
-
} from "../../field/index";
|
|
14
|
-
import type { CollectionObject } from "../../builder";
|
|
1
|
+
import type { MakeArrayable, MakeOptional, RemoveNeverValues, PartialOnUndefined } from "../../types/common.js";
|
|
2
|
+
import type { BaseRelation, Field, OptionalRelation, PrimaryKey, RelationArray } from "../../field";
|
|
3
|
+
import type { CollectionObject } from "../../builder.ts";
|
|
15
4
|
import { WhereObject } from "./find.js";
|
|
16
|
-
import { Model, FindRelationKey, RelationValue } from "../../model
|
|
17
|
-
export type MutationActions =
|
|
18
|
-
|
|
19
|
-
| "
|
|
20
|
-
|
|
21
|
-
|
|
|
22
|
-
|
|
23
|
-
| "
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
? never
|
|
54
|
-
: Type
|
|
55
|
-
: Fields[K] extends BaseRelation<infer To, infer Name>
|
|
56
|
-
? To extends All
|
|
57
|
-
? MakeOptional<
|
|
58
|
-
Fields[K] extends OptionalRelation<any, any>
|
|
59
|
-
? true
|
|
60
|
-
: Fields[K] extends RelationArray<any, any>
|
|
61
|
-
? true
|
|
62
|
-
: MutType extends "update"
|
|
63
|
-
? true
|
|
64
|
-
: false,
|
|
65
|
-
| MakeArrayable<
|
|
66
|
-
Fields[K] extends RelationArray<any, any>
|
|
67
|
-
? true
|
|
68
|
-
: false,
|
|
69
|
-
| {
|
|
70
|
-
$connect: RelationValue<To, C>;
|
|
71
|
-
}
|
|
72
|
-
| {
|
|
73
|
-
$create: Omit<
|
|
74
|
-
Mutation<
|
|
75
|
-
To,
|
|
76
|
-
All,
|
|
77
|
-
C[To],
|
|
78
|
-
C,
|
|
79
|
-
"add"
|
|
80
|
-
>,
|
|
81
|
-
FindRelationKey<
|
|
82
|
-
This,
|
|
83
|
-
Name,
|
|
84
|
-
C[To]
|
|
85
|
-
>
|
|
86
|
-
>;
|
|
87
|
-
}
|
|
88
|
-
| (MutType extends "update"
|
|
89
|
-
?
|
|
90
|
-
| {
|
|
91
|
-
$update: Fields[K] extends RelationArray<
|
|
92
|
-
any,
|
|
93
|
-
any
|
|
94
|
-
>
|
|
95
|
-
? {
|
|
96
|
-
where?: WhereSelection<
|
|
97
|
-
C[To]
|
|
98
|
-
>;
|
|
99
|
-
data: Mutation<
|
|
100
|
-
To,
|
|
101
|
-
All,
|
|
102
|
-
C[To],
|
|
103
|
-
C,
|
|
104
|
-
MutType
|
|
105
|
-
>;
|
|
106
|
-
}
|
|
107
|
-
: Mutation<
|
|
108
|
-
To,
|
|
109
|
-
All,
|
|
110
|
-
C[To],
|
|
111
|
-
C,
|
|
112
|
-
MutType
|
|
113
|
-
>;
|
|
114
|
-
}
|
|
115
|
-
| {
|
|
116
|
-
$delete: Fields[K] extends RelationArray<
|
|
117
|
-
any,
|
|
118
|
-
any
|
|
119
|
-
>
|
|
120
|
-
? RelationValue<
|
|
121
|
-
To,
|
|
122
|
-
C
|
|
123
|
-
>
|
|
124
|
-
: true;
|
|
125
|
-
}
|
|
126
|
-
| {
|
|
127
|
-
$disconnect: Fields[K] extends RelationArray<
|
|
128
|
-
any,
|
|
129
|
-
any
|
|
130
|
-
>
|
|
131
|
-
? RelationValue<
|
|
132
|
-
To,
|
|
133
|
-
C
|
|
134
|
-
>
|
|
135
|
-
: true;
|
|
136
|
-
}
|
|
137
|
-
: never)
|
|
138
|
-
>
|
|
139
|
-
| (Fields[K] extends RelationArray<any, any>
|
|
140
|
-
?
|
|
141
|
-
| {
|
|
142
|
-
$connectMany: RelationValue<
|
|
143
|
-
To,
|
|
144
|
-
C
|
|
145
|
-
>[];
|
|
146
|
-
}
|
|
147
|
-
| {
|
|
148
|
-
$createMany: Omit<
|
|
149
|
-
Mutation<
|
|
150
|
-
To,
|
|
151
|
-
All,
|
|
152
|
-
C[To],
|
|
153
|
-
C,
|
|
154
|
-
"add"
|
|
155
|
-
>,
|
|
156
|
-
FindRelationKey<
|
|
157
|
-
This,
|
|
158
|
-
Name,
|
|
159
|
-
C[To]
|
|
160
|
-
>
|
|
161
|
-
>[];
|
|
162
|
-
}
|
|
163
|
-
| {
|
|
164
|
-
$updateMany: {
|
|
165
|
-
where?: WhereSelection<
|
|
166
|
-
C[To]
|
|
167
|
-
>;
|
|
168
|
-
data: Mutation<
|
|
169
|
-
To,
|
|
170
|
-
All,
|
|
171
|
-
C[To],
|
|
172
|
-
C,
|
|
173
|
-
MutType
|
|
174
|
-
>;
|
|
175
|
-
}[];
|
|
176
|
-
}
|
|
177
|
-
| {
|
|
178
|
-
$deleteMany: RelationValue<
|
|
179
|
-
To,
|
|
180
|
-
C
|
|
181
|
-
>[];
|
|
182
|
-
}
|
|
183
|
-
| {
|
|
184
|
-
$deleteAll: true;
|
|
185
|
-
}
|
|
186
|
-
| {
|
|
187
|
-
$disconnectMany: RelationValue<
|
|
188
|
-
To,
|
|
189
|
-
C
|
|
190
|
-
>[];
|
|
191
|
-
}
|
|
192
|
-
| {
|
|
193
|
-
$disconnectAll: true;
|
|
194
|
-
}
|
|
195
|
-
: never)
|
|
196
|
-
>
|
|
197
|
-
: never
|
|
198
|
-
: never;
|
|
199
|
-
}
|
|
200
|
-
: never
|
|
201
|
-
>
|
|
202
|
-
>;
|
|
203
|
-
export type AddMutation<
|
|
204
|
-
This extends All,
|
|
205
|
-
All extends string,
|
|
206
|
-
Struct extends object,
|
|
207
|
-
C extends CollectionObject<All>
|
|
208
|
-
> = Mutation<This, All, Struct, C, "add">;
|
|
209
|
-
export interface UpdateMutation<
|
|
210
|
-
This extends All,
|
|
211
|
-
All extends string,
|
|
212
|
-
Struct extends object,
|
|
213
|
-
C extends CollectionObject<All>
|
|
214
|
-
> {
|
|
5
|
+
import { Model, FindRelationKey, RelationValue } from "../../model";
|
|
6
|
+
export type MutationActions = "$connect" | "$connectMany" | "$create" | "$createMany" | "$update" | "$updateMany" | "$delete" | "$deleteMany" | "$deleteAll" | "$disconnect" | "$disconnectMany" | "$disconnectAll";
|
|
7
|
+
export type Mutation<This extends All, All extends string, Struct extends object, C extends CollectionObject<All>, MutType extends string = "add"> = PartialOnUndefined<RemoveNeverValues<Struct extends Model<any, infer Fields, any> ? {
|
|
8
|
+
[K in keyof Fields]: Fields[K] extends Field<infer Type, infer HasDefault> ? MutType extends "update" ? Type | undefined | ((value: Type) => Type) : HasDefault extends true ? Type | undefined : Type : Fields[K] extends PrimaryKey<infer IsAuto, infer Type> ? MutType extends "update" ? never : 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 RelationArray<any, any> ? true : MutType extends "update" ? true : false, MakeArrayable<Fields[K] extends RelationArray<any, any> ? true : false, {
|
|
9
|
+
$connect: RelationValue<To, C>;
|
|
10
|
+
} | {
|
|
11
|
+
$create: Omit<Mutation<To, All, C[To], C, "add">, FindRelationKey<This, Name, C[To]>>;
|
|
12
|
+
} | (MutType extends "update" ? {
|
|
13
|
+
$update: Fields[K] extends RelationArray<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 RelationArray<any, any> ? RelationValue<To, C> : true;
|
|
19
|
+
} | {
|
|
20
|
+
$disconnect: Fields[K] extends RelationArray<any, any> ? RelationValue<To, C> : true;
|
|
21
|
+
} : never)> | (Fields[K] extends RelationArray<any, any> ? {
|
|
22
|
+
$connectMany: RelationValue<To, C>[];
|
|
23
|
+
} | {
|
|
24
|
+
$createMany: Omit<Mutation<To, All, C[To], C, "add">, FindRelationKey<This, Name, C[To]>>[];
|
|
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;
|
|
38
|
+
} : never)> : never : never;
|
|
39
|
+
} : 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>> {
|
|
215
42
|
where?: WhereSelection<Struct>;
|
|
216
43
|
data: Mutation<This, All, Struct, C, "update">;
|
|
217
44
|
}
|
|
218
|
-
type WhereSelection<Struct extends object> = Struct extends Model<
|
|
219
|
-
any,
|
|
220
|
-
infer Fields,
|
|
221
|
-
any
|
|
222
|
-
>
|
|
223
|
-
? WhereObject<Fields>
|
|
224
|
-
: never;
|
|
45
|
+
type WhereSelection<Struct extends object> = Struct extends Model<any, infer Fields, any> ? WhereObject<Fields> : never;
|
|
225
46
|
export {};
|