electrodb 1.8.4 → 1.10.1
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 +20 -16
- package/index.d.ts +3 -1551
- package/package.json +8 -8
- package/src/entity.d.ts +94 -0
- package/src/entity.js +69 -25
- package/src/entity.test-d.ts +110 -0
- package/src/service.d.ts +17 -0
- package/src/types/client.ts +15 -0
- package/src/types/collections.ts +243 -0
- package/src/types/events.ts +47 -0
- package/src/types/index.ts +72 -0
- package/src/types/model.ts +132 -0
- package/src/types/options.ts +81 -0
- package/src/types/schema.test-d.ts +2507 -0
- package/src/types/schema.ts +1016 -0
- package/src/types/tests.test-d.ts +3 -0
- package/src/types/types.test-d.ts +142 -0
- package/src/types/where.test-d.ts +1939 -0
- package/src/types/where.ts +94 -0
- package/src/util.js +38 -1
- package/CHANGELOG.md +0 -185
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { Entity } from '../entity';
|
|
2
|
+
import {
|
|
3
|
+
GoRecord,
|
|
4
|
+
ParamRecord,
|
|
5
|
+
PageRecord,
|
|
6
|
+
} from './options';
|
|
7
|
+
import {
|
|
8
|
+
EntityCollections,
|
|
9
|
+
ItemAttribute,
|
|
10
|
+
ResponseItem,
|
|
11
|
+
Schema,
|
|
12
|
+
TableIndexCompositeAttributes,
|
|
13
|
+
} from './schema';
|
|
14
|
+
import {
|
|
15
|
+
WhereAttributeSymbol
|
|
16
|
+
} from './where';
|
|
17
|
+
|
|
18
|
+
export type AllCollectionNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
19
|
+
[Name in keyof E]:
|
|
20
|
+
E[Name] extends Entity<infer A, infer F, infer C, infer S>
|
|
21
|
+
? {
|
|
22
|
+
[Collection in keyof EntityCollections<A,F,C,S>]: Collection
|
|
23
|
+
}[keyof EntityCollections<A,F,C,S>]
|
|
24
|
+
: never
|
|
25
|
+
}[keyof E];
|
|
26
|
+
|
|
27
|
+
export type AllEntityAttributeNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
28
|
+
[Name in keyof E]: {
|
|
29
|
+
[A in keyof E[Name]["schema"]["attributes"]]: A
|
|
30
|
+
}[keyof E[Name]["schema"]["attributes"]]
|
|
31
|
+
}[keyof E];
|
|
32
|
+
|
|
33
|
+
export type AllEntityAttributes<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
34
|
+
[Attr in AllEntityAttributeNames<E>]: {
|
|
35
|
+
[Name in keyof E]: Attr extends keyof E[Name]["schema"]["attributes"]
|
|
36
|
+
? ItemAttribute<E[Name]["schema"]["attributes"][Attr]>
|
|
37
|
+
: never
|
|
38
|
+
}[keyof E];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type CollectionAssociations<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
42
|
+
[Collection in AllCollectionNames<E>]: {
|
|
43
|
+
[Name in keyof E]: E[Name] extends Entity<infer A, infer F, infer C, infer S>
|
|
44
|
+
? Collection extends keyof EntityCollections<A,F,C,S>
|
|
45
|
+
? Name
|
|
46
|
+
: never
|
|
47
|
+
: never
|
|
48
|
+
}[keyof E];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type CollectionAttributes<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
|
|
52
|
+
[Collection in keyof Collections]: {
|
|
53
|
+
[EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
|
|
54
|
+
? EntityName extends Collections[Collection]
|
|
55
|
+
? keyof S["attributes"]
|
|
56
|
+
: never
|
|
57
|
+
: never
|
|
58
|
+
}[keyof E]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface CollectionWhereOperations {
|
|
62
|
+
eq: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
63
|
+
ne: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
64
|
+
gt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
65
|
+
lt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
66
|
+
gte: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
67
|
+
lte: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
68
|
+
between: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T, value2: T) => string;
|
|
69
|
+
begins: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
70
|
+
exists: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
|
|
71
|
+
notExists: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
|
|
72
|
+
contains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
73
|
+
notContains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
74
|
+
value: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
75
|
+
name: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type CollectionWhereCallback<E extends {[name: string]: Entity<any, any, any, any>}, I extends Partial<AllEntityAttributes<E>>> =
|
|
79
|
+
<W extends {[A in keyof I]: WhereAttributeSymbol<I[A]>}>(attributes: W, operations: CollectionWhereOperations) => string;
|
|
80
|
+
|
|
81
|
+
export type CollectionWhereClause<E extends {[name: string]: Entity<any, any, any, any>}, A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Partial<AllEntityAttributes<E>>, T> = (where: CollectionWhereCallback<E, I>) => T;
|
|
82
|
+
|
|
83
|
+
export interface WhereRecordsActionOptions<E extends {[name: string]: Entity<any, any, any, any>}, A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Partial<AllEntityAttributes<E>>, Items, IndexCompositeAttributes> {
|
|
84
|
+
go: GoRecord<Items>;
|
|
85
|
+
params: ParamRecord;
|
|
86
|
+
page: PageRecord<Items,IndexCompositeAttributes>;
|
|
87
|
+
where: CollectionWhereClause<E,A,F,C,S,I, WhereRecordsActionOptions<E,A,F,C,S,I,Items,IndexCompositeAttributes>>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type CollectionIndexKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
91
|
+
[Collection in keyof Collections]: {
|
|
92
|
+
[EntityResultName in Collections[Collection]]:
|
|
93
|
+
EntityResultName extends keyof Entities
|
|
94
|
+
? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
95
|
+
? keyof TableIndexCompositeAttributes<A, F, C, S>
|
|
96
|
+
: never
|
|
97
|
+
: never
|
|
98
|
+
}[Collections[Collection]]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type CollectionPageKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
102
|
+
[Collection in keyof Collections]: {
|
|
103
|
+
[EntityResultName in Collections[Collection]]:
|
|
104
|
+
EntityResultName extends keyof Entities
|
|
105
|
+
? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
106
|
+
? keyof Parameters<Entities[EntityResultName]["query"][
|
|
107
|
+
Collection extends keyof EntityCollections<A,F,C,S>
|
|
108
|
+
? EntityCollections<A,F,C,S>[Collection]
|
|
109
|
+
: never
|
|
110
|
+
]>[0]
|
|
111
|
+
: never
|
|
112
|
+
: never
|
|
113
|
+
}[Collections[Collection]]
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type CollectionIndexAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
117
|
+
[Collection in keyof CollectionIndexKeys<Entities, Collections>]: {
|
|
118
|
+
[key in CollectionIndexKeys<Entities, Collections>[Collection]]:
|
|
119
|
+
key extends keyof AllEntityAttributes<Entities>
|
|
120
|
+
? AllEntityAttributes<Entities>[key]
|
|
121
|
+
: never
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type CollectionPageAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
126
|
+
[Collection in keyof CollectionPageKeys<Entities, Collections>]: {
|
|
127
|
+
[key in CollectionPageKeys<Entities, Collections>[Collection]]:
|
|
128
|
+
key extends keyof AllEntityAttributes<Entities>
|
|
129
|
+
? AllEntityAttributes<Entities>[key]
|
|
130
|
+
: never
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type OptionalPropertyNames<T> =
|
|
135
|
+
{ [K in keyof T]: undefined extends T[K] ? K : never }[keyof T];
|
|
136
|
+
|
|
137
|
+
// Common properties from L and R with undefined in R[K] replaced by type in L[K]
|
|
138
|
+
export type SpreadProperties<L, R, K extends keyof L & keyof R> =
|
|
139
|
+
{ [P in K]: L[P] | Exclude<R[P], undefined> };
|
|
140
|
+
|
|
141
|
+
export type Id<T> = {[K in keyof T]: T[K]} // see note at bottom*
|
|
142
|
+
|
|
143
|
+
// Type of { ...L, ...R }
|
|
144
|
+
export type Spread<L, R> = Id<
|
|
145
|
+
// Properties in L that don't exist in R
|
|
146
|
+
& Pick<L, Exclude<keyof L, keyof R>>
|
|
147
|
+
// Properties in R with types that exclude undefined
|
|
148
|
+
& Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>>
|
|
149
|
+
// Properties in R, with types that include undefined, that don't exist in L
|
|
150
|
+
& Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>>
|
|
151
|
+
// Properties in R, with types that include undefined, that exist in L
|
|
152
|
+
& SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>
|
|
153
|
+
>;
|
|
154
|
+
|
|
155
|
+
export type RequiredProperties<T> = Pick<T, {[K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T]>
|
|
156
|
+
|
|
157
|
+
export type CollectionQueries<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
|
|
158
|
+
[Collection in keyof Collections]: {
|
|
159
|
+
[EntityName in keyof E]:
|
|
160
|
+
EntityName extends Collections[Collection]
|
|
161
|
+
? (params:
|
|
162
|
+
RequiredProperties<
|
|
163
|
+
Parameters<
|
|
164
|
+
E[EntityName]["query"][
|
|
165
|
+
E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
|
|
166
|
+
? Collection extends keyof EntityCollections<A,F,C,S>
|
|
167
|
+
? EntityCollections<A,F,C,S>[Collection]
|
|
168
|
+
: never
|
|
169
|
+
: never
|
|
170
|
+
]
|
|
171
|
+
>[0]
|
|
172
|
+
>) => {
|
|
173
|
+
go: GoRecord<{
|
|
174
|
+
[EntityResultName in Collections[Collection]]:
|
|
175
|
+
EntityResultName extends keyof E
|
|
176
|
+
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
177
|
+
? ResponseItem<A,F,C,S>[]
|
|
178
|
+
: never
|
|
179
|
+
: never
|
|
180
|
+
}>;
|
|
181
|
+
params: ParamRecord;
|
|
182
|
+
page: {
|
|
183
|
+
[EntityResultName in Collections[Collection]]: EntityResultName extends keyof E
|
|
184
|
+
? Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>> extends Partial<AllEntityAttributes<E>>
|
|
185
|
+
?
|
|
186
|
+
PageRecord<
|
|
187
|
+
{
|
|
188
|
+
[EntityResultName in Collections[Collection]]:
|
|
189
|
+
EntityResultName extends keyof E
|
|
190
|
+
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
191
|
+
? ResponseItem<A,F,C,S>[]
|
|
192
|
+
: never
|
|
193
|
+
: never
|
|
194
|
+
},
|
|
195
|
+
Partial<
|
|
196
|
+
Spread<
|
|
197
|
+
Collection extends keyof CollectionPageAttributes<E, Collections>
|
|
198
|
+
? CollectionPageAttributes<E, Collections>[Collection]
|
|
199
|
+
: {},
|
|
200
|
+
Collection extends keyof CollectionIndexAttributes<E, Collections>
|
|
201
|
+
? CollectionIndexAttributes<E, Collections>[Collection]
|
|
202
|
+
: {}
|
|
203
|
+
>
|
|
204
|
+
>
|
|
205
|
+
>
|
|
206
|
+
: never
|
|
207
|
+
: never
|
|
208
|
+
}[Collections[Collection]];
|
|
209
|
+
where: {
|
|
210
|
+
[EntityResultName in Collections[Collection]]: EntityResultName extends keyof E
|
|
211
|
+
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
212
|
+
? Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>> extends Partial<AllEntityAttributes<E>>
|
|
213
|
+
? CollectionWhereClause<E,A,F,C,S,
|
|
214
|
+
Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>>,
|
|
215
|
+
WhereRecordsActionOptions<E,A,F,C,S,
|
|
216
|
+
Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>>,
|
|
217
|
+
{
|
|
218
|
+
[EntityResultName in Collections[Collection]]:
|
|
219
|
+
EntityResultName extends keyof E
|
|
220
|
+
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
221
|
+
? ResponseItem<A,F,C,S>[]
|
|
222
|
+
: never
|
|
223
|
+
: never
|
|
224
|
+
},
|
|
225
|
+
Partial<
|
|
226
|
+
Spread<
|
|
227
|
+
Collection extends keyof CollectionPageAttributes<E, Collections>
|
|
228
|
+
? CollectionPageAttributes<E, Collections>[Collection]
|
|
229
|
+
: {},
|
|
230
|
+
Collection extends keyof CollectionIndexAttributes<E, Collections>
|
|
231
|
+
? CollectionIndexAttributes<E, Collections>[Collection]
|
|
232
|
+
: {}
|
|
233
|
+
>
|
|
234
|
+
>
|
|
235
|
+
>>
|
|
236
|
+
: never
|
|
237
|
+
: never
|
|
238
|
+
: never
|
|
239
|
+
}[Collections[Collection]];
|
|
240
|
+
}
|
|
241
|
+
: never
|
|
242
|
+
}[keyof E];
|
|
243
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export type ElectroDBMethodTypes = "put" | "get" | "query" | "scan" | "update" | "delete" | "remove" | "patch" | "create" | "batchGet" | "batchWrite";
|
|
2
|
+
|
|
3
|
+
export interface ElectroQueryEvent<P extends any = any> {
|
|
4
|
+
type: 'query';
|
|
5
|
+
method: ElectroDBMethodTypes;
|
|
6
|
+
config: any;
|
|
7
|
+
params: P;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ElectroResultsEvent<R extends any = any> {
|
|
11
|
+
type: 'results';
|
|
12
|
+
method: ElectroDBMethodTypes;
|
|
13
|
+
config: any;
|
|
14
|
+
results: R;
|
|
15
|
+
success: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type ElectroEvent =
|
|
19
|
+
ElectroQueryEvent
|
|
20
|
+
| ElectroResultsEvent;
|
|
21
|
+
|
|
22
|
+
export type ElectroEventType = Pick<ElectroEvent, 'type'>;
|
|
23
|
+
|
|
24
|
+
export type ElectroEventListener = (event: ElectroEvent) => void;
|
|
25
|
+
|
|
26
|
+
// todo: coming soon, more events!
|
|
27
|
+
// | {
|
|
28
|
+
// name: "error";
|
|
29
|
+
// type: "configuration_error" | "invalid_query" | "dynamodb_client";
|
|
30
|
+
// message: string;
|
|
31
|
+
// details: ElectroError;
|
|
32
|
+
// } | {
|
|
33
|
+
// name: "error";
|
|
34
|
+
// type: "user_defined";
|
|
35
|
+
// message: string;
|
|
36
|
+
// details: ElectroValidationError;
|
|
37
|
+
// } | {
|
|
38
|
+
// name: "warn";
|
|
39
|
+
// type: "deprecation_warning" | "optimization_suggestion";
|
|
40
|
+
// message: string;
|
|
41
|
+
// details: any;
|
|
42
|
+
// } | {
|
|
43
|
+
// name: "info";
|
|
44
|
+
// type: "client_updated" | "table_overwritten";
|
|
45
|
+
// message: string;
|
|
46
|
+
// details: any;
|
|
47
|
+
// };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Entity } from '../entity';
|
|
2
|
+
import { ResponseItem, PutItem, AddItem, SubtractItem, AppendItem, RemoveItem, DeleteItem, Item } from './schema';
|
|
3
|
+
import { Service } from '../service';
|
|
4
|
+
import { CollectionAssociations } from './collections';
|
|
5
|
+
|
|
6
|
+
export * from './where';
|
|
7
|
+
export * from './schema';
|
|
8
|
+
export * from './options';
|
|
9
|
+
export * from './client';
|
|
10
|
+
export * from './collections';
|
|
11
|
+
export * from './model';
|
|
12
|
+
export * from './events';
|
|
13
|
+
|
|
14
|
+
export type EntityItem<E extends Entity<any, any, any, any>> =
|
|
15
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
16
|
+
? ResponseItem<A, F, C, S>
|
|
17
|
+
: never;
|
|
18
|
+
|
|
19
|
+
export type CreateEntityItem<E extends Entity<any, any, any, any>> =
|
|
20
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
21
|
+
? PutItem<A, F, C, S>
|
|
22
|
+
: never;
|
|
23
|
+
|
|
24
|
+
export type UpdateEntityItem<E extends Entity<any, any, any, any>> =
|
|
25
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
26
|
+
? Partial<ResponseItem<A,F,C,S>>
|
|
27
|
+
: never;
|
|
28
|
+
|
|
29
|
+
export type UpdateAddEntityItem<E extends Entity<any, any, any, any>> =
|
|
30
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
31
|
+
? AddItem<A, F, C, S>
|
|
32
|
+
: never;
|
|
33
|
+
|
|
34
|
+
export type UpdateSubtractEntityItem<E extends Entity<any, any, any, any>> =
|
|
35
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
36
|
+
? SubtractItem<A, F, C, S>
|
|
37
|
+
: never;
|
|
38
|
+
|
|
39
|
+
export type UpdateAppendEntityItem<E extends Entity<any, any, any, any>> =
|
|
40
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
41
|
+
? AppendItem<A, F, C, S>
|
|
42
|
+
: never;
|
|
43
|
+
|
|
44
|
+
export type UpdateRemoveEntityItem<E extends Entity<any, any, any, any>> =
|
|
45
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
46
|
+
? RemoveItem<A, F, C, S>
|
|
47
|
+
: never;
|
|
48
|
+
|
|
49
|
+
export type UpdateDeleteEntityItem<E extends Entity<any, any, any, any>> =
|
|
50
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
51
|
+
? DeleteItem<A, F, C, S>
|
|
52
|
+
: never;
|
|
53
|
+
|
|
54
|
+
export type EntityRecord<E extends Entity<any, any, any, any>> =
|
|
55
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
56
|
+
? Item<A,F,C,S,S["attributes"]>
|
|
57
|
+
: never;
|
|
58
|
+
|
|
59
|
+
export type CollectionItem<SERVICE extends Service<any>, COLLECTION extends keyof SERVICE["collections"]> =
|
|
60
|
+
SERVICE extends Service<infer E>
|
|
61
|
+
? Pick<{
|
|
62
|
+
[EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
|
|
63
|
+
? COLLECTION extends keyof CollectionAssociations<E>
|
|
64
|
+
? EntityName extends CollectionAssociations<E>[COLLECTION]
|
|
65
|
+
? ResponseItem<A,F,C,S>[]
|
|
66
|
+
: never
|
|
67
|
+
: never
|
|
68
|
+
: never
|
|
69
|
+
}, COLLECTION extends keyof CollectionAssociations<E>
|
|
70
|
+
? CollectionAssociations<E>[COLLECTION]
|
|
71
|
+
: never>
|
|
72
|
+
: never
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GoRecord,
|
|
3
|
+
ParamRecord,
|
|
4
|
+
QueryOptions,
|
|
5
|
+
PageRecord,
|
|
6
|
+
PutQueryOptions,
|
|
7
|
+
UpdateQueryOptions,
|
|
8
|
+
UpdateQueryParams,
|
|
9
|
+
DeleteQueryOptions,
|
|
10
|
+
BulkOptions,
|
|
11
|
+
BatchGoRecord
|
|
12
|
+
} from './options';
|
|
13
|
+
import {
|
|
14
|
+
WhereClause,
|
|
15
|
+
DataUpdateMethod,
|
|
16
|
+
} from './where';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
AllTableIndexCompositeAttributes,
|
|
20
|
+
IndexCompositeAttributes,
|
|
21
|
+
ResponseItem,
|
|
22
|
+
IndexWithSortKey,
|
|
23
|
+
IndexSKAttributes,
|
|
24
|
+
Item,
|
|
25
|
+
Schema,
|
|
26
|
+
SetItem,
|
|
27
|
+
UpdateData,
|
|
28
|
+
AddItem,
|
|
29
|
+
SubtractItem,
|
|
30
|
+
AppendItem,
|
|
31
|
+
DeleteItem,
|
|
32
|
+
} from './schema';
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export interface RecordsActionOptions<A extends string,
|
|
36
|
+
F extends string, C extends string, S extends Schema<A,F,C>, Items, IndexCompositeAttributes> {
|
|
37
|
+
go: GoRecord<Items>;
|
|
38
|
+
params: ParamRecord;
|
|
39
|
+
page: PageRecord<Items,IndexCompositeAttributes>;
|
|
40
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,RecordsActionOptions<A,F,C,S,Items,IndexCompositeAttributes>>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SingleRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
|
|
44
|
+
go: GoRecord<ResponseType, QueryOptions>;
|
|
45
|
+
params: ParamRecord<QueryOptions>;
|
|
46
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,SingleRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface PutRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
|
|
50
|
+
go: GoRecord<ResponseType, PutQueryOptions>;
|
|
51
|
+
params: ParamRecord<PutQueryOptions>;
|
|
52
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,PutRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface UpdateRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
|
|
56
|
+
go: GoRecord<ResponseType, UpdateQueryOptions>;
|
|
57
|
+
params: ParamRecord<UpdateQueryParams>;
|
|
58
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,PutRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface DeleteRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
|
|
62
|
+
go: GoRecord<ResponseType, DeleteQueryOptions>;
|
|
63
|
+
params: ParamRecord<DeleteQueryOptions>;
|
|
64
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,DeleteRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface BulkRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType, AlternateResponseType> {
|
|
68
|
+
go: BatchGoRecord<ResponseType, AlternateResponseType>;
|
|
69
|
+
params: ParamRecord<BulkOptions>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface SetRecordActionOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr,IndexCompositeAttributes,TableItem> {
|
|
73
|
+
go: GoRecord<Partial<TableItem>, UpdateQueryOptions>;
|
|
74
|
+
params: ParamRecord<UpdateQueryParams>;
|
|
75
|
+
set: SetRecord<A,F,C,S, SetItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
76
|
+
remove: SetRecord<A,F,C,S, Array<keyof SetItem<A,F,C,S>>,IndexCompositeAttributes,TableItem>;
|
|
77
|
+
add: SetRecord<A,F,C,S, AddItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
78
|
+
subtract: SetRecord<A,F,C,S, SubtractItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
79
|
+
append: SetRecord<A,F,C,S, AppendItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
80
|
+
delete: SetRecord<A,F,C,S, DeleteItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
81
|
+
data: DataUpdateMethodRecord<A,F,C,S, Item<A,F,C,S,S["attributes"]>,IndexCompositeAttributes,TableItem>;
|
|
82
|
+
where: WhereClause<A,F,C,S, Item<A,F,C,S,S["attributes"]>,SetRecordActionOptions<A,F,C,S,SetAttr,IndexCompositeAttributes,TableItem>>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type SetRecord<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr, IndexCompositeAttributes, TableItem> = (properties: SetAttr) => SetRecordActionOptions<A,F,C,S, SetAttr, IndexCompositeAttributes, TableItem>;
|
|
86
|
+
export type RemoveRecord<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, RemoveAttr, IndexCompositeAttributes, TableItem> = (properties: RemoveAttr) => SetRecordActionOptions<A,F,C,S, RemoveAttr, IndexCompositeAttributes, TableItem>;
|
|
87
|
+
|
|
88
|
+
export type DataUpdateMethodRecord<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr, IndexCompositeAttributes, TableItem> =
|
|
89
|
+
DataUpdateMethod<A,F,C,S, UpdateData<A,F,C,S>, SetRecordActionOptions<A,F,C,S, SetAttr, IndexCompositeAttributes, TableItem>>
|
|
90
|
+
|
|
91
|
+
interface QueryOperations<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, CompositeAttributes, TableItem, IndexCompositeAttributes> {
|
|
92
|
+
between: (skCompositeAttributesStart: CompositeAttributes, skCompositeAttributesEnd: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
93
|
+
gt: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
94
|
+
gte: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
95
|
+
lt: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
96
|
+
lte: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
97
|
+
begins: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
98
|
+
go: GoRecord<Array<TableItem>>;
|
|
99
|
+
params: ParamRecord;
|
|
100
|
+
page: PageRecord<Array<TableItem>,IndexCompositeAttributes>;
|
|
101
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,RecordsActionOptions<A,F,C,S,Array<TableItem>,IndexCompositeAttributes>>
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type Queries<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
|
|
105
|
+
[I in keyof S["indexes"]]: <CompositeAttributes extends IndexCompositeAttributes<A,F,C,S,I>>(composite: CompositeAttributes) =>
|
|
106
|
+
IndexSKAttributes<A,F,C,S,I> extends infer SK
|
|
107
|
+
// If there is no SK, dont show query operations (when an empty array is provided)
|
|
108
|
+
? [keyof SK] extends [never]
|
|
109
|
+
? RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes>>
|
|
110
|
+
// If there is no SK, dont show query operations (When no PK is specified)
|
|
111
|
+
: S["indexes"][I] extends IndexWithSortKey
|
|
112
|
+
? QueryOperations<
|
|
113
|
+
A,F,C,S,
|
|
114
|
+
// Omit the composite attributes already provided
|
|
115
|
+
Omit<Partial<IndexSKAttributes<A,F,C,S,I>>, keyof CompositeAttributes>,
|
|
116
|
+
ResponseItem<A,F,C,S>,
|
|
117
|
+
AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes> & SK
|
|
118
|
+
>
|
|
119
|
+
: RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes> & SK>
|
|
120
|
+
: never
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type ParseSingleInput = {
|
|
124
|
+
Item?: {[key: string]: any}
|
|
125
|
+
} | {
|
|
126
|
+
Attributes?: {[key: string]: any}
|
|
127
|
+
} | null;
|
|
128
|
+
|
|
129
|
+
export type ParseMultiInput = {
|
|
130
|
+
Items?: {[key: string]: any}[]
|
|
131
|
+
}
|
|
132
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ElectroEventListener } from './events';
|
|
2
|
+
|
|
3
|
+
export type ReturnValues = "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
4
|
+
|
|
5
|
+
export interface QueryOptions {
|
|
6
|
+
raw?: boolean;
|
|
7
|
+
table?: string;
|
|
8
|
+
limit?: number;
|
|
9
|
+
params?: object;
|
|
10
|
+
includeKeys?: boolean;
|
|
11
|
+
originalErr?: boolean;
|
|
12
|
+
ignoreOwnership?: boolean;
|
|
13
|
+
pages?: number;
|
|
14
|
+
listeners?: Array<ElectroEventListener>;
|
|
15
|
+
logger?: ElectroEventListener;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// subset of QueryOptions
|
|
19
|
+
export interface ParseOptions {
|
|
20
|
+
ignoreOwnership?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface UpdateQueryOptions extends QueryOptions {
|
|
24
|
+
response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface UpdateQueryParams {
|
|
28
|
+
response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
29
|
+
table?: string;
|
|
30
|
+
params?: object;
|
|
31
|
+
originalErr?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface DeleteQueryOptions extends QueryOptions {
|
|
35
|
+
response?: "default" | "none" | 'all_old';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface PutQueryOptions extends QueryOptions {
|
|
39
|
+
response?: "default" | "none" | 'all_old';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ParamOptions {
|
|
43
|
+
params?: object;
|
|
44
|
+
table?: string;
|
|
45
|
+
limit?: number;
|
|
46
|
+
response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface PaginationOptions extends QueryOptions {
|
|
50
|
+
pager?: "raw" | "item" | "named";
|
|
51
|
+
limit?: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface BulkOptions extends QueryOptions {
|
|
55
|
+
unprocessed?: "raw" | "item";
|
|
56
|
+
concurrency?: number;
|
|
57
|
+
preserveBatchOrder?: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type OptionalDefaultEntityIdentifiers = {
|
|
61
|
+
__edb_e__?: string;
|
|
62
|
+
__edb_v__?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type GoRecord<ResponseType, Options = QueryOptions> = <T = ResponseType>(options?: Options) => Promise<T>;
|
|
66
|
+
|
|
67
|
+
export type BatchGoRecord<ResponseType, AlternateResponseType> = <O extends BulkOptions>(options?: O) =>
|
|
68
|
+
O extends infer Options
|
|
69
|
+
? 'preserveBatchOrder' extends keyof Options
|
|
70
|
+
? Options['preserveBatchOrder'] extends true
|
|
71
|
+
? Promise<AlternateResponseType>
|
|
72
|
+
: Promise<ResponseType>
|
|
73
|
+
: Promise<ResponseType>
|
|
74
|
+
: never
|
|
75
|
+
|
|
76
|
+
export type PageRecord<ResponseType, CompositeAttributes> = (page?: (CompositeAttributes & OptionalDefaultEntityIdentifiers) | null, options?: PaginationOptions) => Promise<[
|
|
77
|
+
(CompositeAttributes & OptionalDefaultEntityIdentifiers) | null,
|
|
78
|
+
ResponseType
|
|
79
|
+
]>;
|
|
80
|
+
|
|
81
|
+
export type ParamRecord<Options = ParamOptions> = <P>(options?: Options) => P;
|