electrodb 1.9.0 → 1.10.2
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/index.d.ts +906 -776
- package/package.json +8 -8
- package/src/entity.js +9 -7
- package/src/util.js +6 -2
package/index.d.ts
CHANGED
|
@@ -1,11 +1,532 @@
|
|
|
1
|
-
type
|
|
2
|
-
? T
|
|
3
|
-
: T extends object
|
|
4
|
-
? {[Key in keyof T]: Flatten<T[Key]>}
|
|
5
|
-
: T;
|
|
1
|
+
export type DocumentClientMethod = (parameters: any) => {promise: () => Promise<any>};
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export type DocumentClient = {
|
|
4
|
+
get: DocumentClientMethod;
|
|
5
|
+
put: DocumentClientMethod;
|
|
6
|
+
delete: DocumentClientMethod;
|
|
7
|
+
update: DocumentClientMethod;
|
|
8
|
+
batchWrite: DocumentClientMethod;
|
|
9
|
+
batchGet: DocumentClientMethod;
|
|
10
|
+
scan: DocumentClientMethod;
|
|
11
|
+
transactGet: DocumentClientMethod;
|
|
12
|
+
transactWrite: DocumentClientMethod;
|
|
13
|
+
} | {
|
|
14
|
+
send: (command: any) => Promise<any>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type AllCollectionNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
18
|
+
[Name in keyof E]:
|
|
19
|
+
E[Name] extends Entity<infer A, infer F, infer C, infer S>
|
|
20
|
+
? {
|
|
21
|
+
[Collection in keyof EntityCollections<A,F,C,S>]: Collection
|
|
22
|
+
}[keyof EntityCollections<A,F,C,S>]
|
|
23
|
+
: never
|
|
24
|
+
}[keyof E];
|
|
25
|
+
|
|
26
|
+
export type AllEntityAttributeNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
27
|
+
[Name in keyof E]: {
|
|
28
|
+
[A in keyof E[Name]["schema"]["attributes"]]: A
|
|
29
|
+
}[keyof E[Name]["schema"]["attributes"]]
|
|
30
|
+
}[keyof E];
|
|
31
|
+
|
|
32
|
+
export type AllEntityAttributes<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
33
|
+
[Attr in AllEntityAttributeNames<E>]: {
|
|
34
|
+
[Name in keyof E]: Attr extends keyof E[Name]["schema"]["attributes"]
|
|
35
|
+
? ItemAttribute<E[Name]["schema"]["attributes"][Attr]>
|
|
36
|
+
: never
|
|
37
|
+
}[keyof E];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type CollectionAssociations<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
41
|
+
[Collection in AllCollectionNames<E>]: {
|
|
42
|
+
[Name in keyof E]: E[Name] extends Entity<infer A, infer F, infer C, infer S>
|
|
43
|
+
? Collection extends keyof EntityCollections<A,F,C,S>
|
|
44
|
+
? Name
|
|
45
|
+
: never
|
|
46
|
+
: never
|
|
47
|
+
}[keyof E];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type CollectionAttributes<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
|
|
51
|
+
[Collection in keyof Collections]: {
|
|
52
|
+
[EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
|
|
53
|
+
? EntityName extends Collections[Collection]
|
|
54
|
+
? keyof S["attributes"]
|
|
55
|
+
: never
|
|
56
|
+
: never
|
|
57
|
+
}[keyof E]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface CollectionWhereOperations {
|
|
61
|
+
eq: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
62
|
+
ne: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
63
|
+
gt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
64
|
+
lt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
65
|
+
gte: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
66
|
+
lte: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
67
|
+
between: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T, value2: T) => string;
|
|
68
|
+
begins: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
69
|
+
exists: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
|
|
70
|
+
notExists: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
|
|
71
|
+
contains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
72
|
+
notContains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
73
|
+
value: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
74
|
+
name: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type CollectionWhereCallback<E extends {[name: string]: Entity<any, any, any, any>}, I extends Partial<AllEntityAttributes<E>>> =
|
|
78
|
+
<W extends {[A in keyof I]: WhereAttributeSymbol<I[A]>}>(attributes: W, operations: CollectionWhereOperations) => string;
|
|
79
|
+
|
|
80
|
+
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;
|
|
81
|
+
|
|
82
|
+
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> {
|
|
83
|
+
go: GoRecord<Items>;
|
|
84
|
+
params: ParamRecord;
|
|
85
|
+
page: PageRecord<Items,IndexCompositeAttributes>;
|
|
86
|
+
where: CollectionWhereClause<E,A,F,C,S,I, WhereRecordsActionOptions<E,A,F,C,S,I,Items,IndexCompositeAttributes>>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type CollectionIndexKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
90
|
+
[Collection in keyof Collections]: {
|
|
91
|
+
[EntityResultName in Collections[Collection]]:
|
|
92
|
+
EntityResultName extends keyof Entities
|
|
93
|
+
? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
94
|
+
? keyof TableIndexCompositeAttributes<A, F, C, S>
|
|
95
|
+
: never
|
|
96
|
+
: never
|
|
97
|
+
}[Collections[Collection]]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type CollectionPageKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
101
|
+
[Collection in keyof Collections]: {
|
|
102
|
+
[EntityResultName in Collections[Collection]]:
|
|
103
|
+
EntityResultName extends keyof Entities
|
|
104
|
+
? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
105
|
+
? keyof Parameters<Entities[EntityResultName]["query"][
|
|
106
|
+
Collection extends keyof EntityCollections<A,F,C,S>
|
|
107
|
+
? EntityCollections<A,F,C,S>[Collection]
|
|
108
|
+
: never
|
|
109
|
+
]>[0]
|
|
110
|
+
: never
|
|
111
|
+
: never
|
|
112
|
+
}[Collections[Collection]]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type CollectionIndexAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
116
|
+
[Collection in keyof CollectionIndexKeys<Entities, Collections>]: {
|
|
117
|
+
[key in CollectionIndexKeys<Entities, Collections>[Collection]]:
|
|
118
|
+
key extends keyof AllEntityAttributes<Entities>
|
|
119
|
+
? AllEntityAttributes<Entities>[key]
|
|
120
|
+
: never
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type CollectionPageAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
125
|
+
[Collection in keyof CollectionPageKeys<Entities, Collections>]: {
|
|
126
|
+
[key in CollectionPageKeys<Entities, Collections>[Collection]]:
|
|
127
|
+
key extends keyof AllEntityAttributes<Entities>
|
|
128
|
+
? AllEntityAttributes<Entities>[key]
|
|
129
|
+
: never
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export type OptionalPropertyNames<T> =
|
|
134
|
+
{ [K in keyof T]: undefined extends T[K] ? K : never }[keyof T];
|
|
135
|
+
|
|
136
|
+
// Common properties from L and R with undefined in R[K] replaced by type in L[K]
|
|
137
|
+
export type SpreadProperties<L, R, K extends keyof L & keyof R> =
|
|
138
|
+
{ [P in K]: L[P] | Exclude<R[P], undefined> };
|
|
139
|
+
|
|
140
|
+
export type Id<T> = {[K in keyof T]: T[K]} // see note at bottom*
|
|
141
|
+
|
|
142
|
+
// Type of { ...L, ...R }
|
|
143
|
+
export type Spread<L, R> = Id<
|
|
144
|
+
// Properties in L that don't exist in R
|
|
145
|
+
& Pick<L, Exclude<keyof L, keyof R>>
|
|
146
|
+
// Properties in R with types that exclude undefined
|
|
147
|
+
& Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>>
|
|
148
|
+
// Properties in R, with types that include undefined, that don't exist in L
|
|
149
|
+
& Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>>
|
|
150
|
+
// Properties in R, with types that include undefined, that exist in L
|
|
151
|
+
& SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>
|
|
152
|
+
>;
|
|
153
|
+
|
|
154
|
+
export type RequiredProperties<T> = Pick<T, {[K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T]>
|
|
155
|
+
|
|
156
|
+
export type CollectionQueries<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
|
|
157
|
+
[Collection in keyof Collections]: {
|
|
158
|
+
[EntityName in keyof E]:
|
|
159
|
+
EntityName extends Collections[Collection]
|
|
160
|
+
? (params:
|
|
161
|
+
RequiredProperties<
|
|
162
|
+
Parameters<
|
|
163
|
+
E[EntityName]["query"][
|
|
164
|
+
E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
|
|
165
|
+
? Collection extends keyof EntityCollections<A,F,C,S>
|
|
166
|
+
? EntityCollections<A,F,C,S>[Collection]
|
|
167
|
+
: never
|
|
168
|
+
: never
|
|
169
|
+
]
|
|
170
|
+
>[0]
|
|
171
|
+
>) => {
|
|
172
|
+
go: GoRecord<{
|
|
173
|
+
[EntityResultName in Collections[Collection]]:
|
|
174
|
+
EntityResultName extends keyof E
|
|
175
|
+
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
176
|
+
? ResponseItem<A,F,C,S>[]
|
|
177
|
+
: never
|
|
178
|
+
: never
|
|
179
|
+
}>;
|
|
180
|
+
params: ParamRecord;
|
|
181
|
+
page: {
|
|
182
|
+
[EntityResultName in Collections[Collection]]: EntityResultName extends keyof E
|
|
183
|
+
? Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>> extends Partial<AllEntityAttributes<E>>
|
|
184
|
+
?
|
|
185
|
+
PageRecord<
|
|
186
|
+
{
|
|
187
|
+
[EntityResultName in Collections[Collection]]:
|
|
188
|
+
EntityResultName extends keyof E
|
|
189
|
+
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
190
|
+
? ResponseItem<A,F,C,S>[]
|
|
191
|
+
: never
|
|
192
|
+
: never
|
|
193
|
+
},
|
|
194
|
+
Partial<
|
|
195
|
+
Spread<
|
|
196
|
+
Collection extends keyof CollectionPageAttributes<E, Collections>
|
|
197
|
+
? CollectionPageAttributes<E, Collections>[Collection]
|
|
198
|
+
: {},
|
|
199
|
+
Collection extends keyof CollectionIndexAttributes<E, Collections>
|
|
200
|
+
? CollectionIndexAttributes<E, Collections>[Collection]
|
|
201
|
+
: {}
|
|
202
|
+
>
|
|
203
|
+
>
|
|
204
|
+
>
|
|
205
|
+
: never
|
|
206
|
+
: never
|
|
207
|
+
}[Collections[Collection]];
|
|
208
|
+
where: {
|
|
209
|
+
[EntityResultName in Collections[Collection]]: EntityResultName extends keyof E
|
|
210
|
+
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
211
|
+
? Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>> extends Partial<AllEntityAttributes<E>>
|
|
212
|
+
? CollectionWhereClause<E,A,F,C,S,
|
|
213
|
+
Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>>,
|
|
214
|
+
WhereRecordsActionOptions<E,A,F,C,S,
|
|
215
|
+
Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>>,
|
|
216
|
+
{
|
|
217
|
+
[EntityResultName in Collections[Collection]]:
|
|
218
|
+
EntityResultName extends keyof E
|
|
219
|
+
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
220
|
+
? ResponseItem<A,F,C,S>[]
|
|
221
|
+
: never
|
|
222
|
+
: never
|
|
223
|
+
},
|
|
224
|
+
Partial<
|
|
225
|
+
Spread<
|
|
226
|
+
Collection extends keyof CollectionPageAttributes<E, Collections>
|
|
227
|
+
? CollectionPageAttributes<E, Collections>[Collection]
|
|
228
|
+
: {},
|
|
229
|
+
Collection extends keyof CollectionIndexAttributes<E, Collections>
|
|
230
|
+
? CollectionIndexAttributes<E, Collections>[Collection]
|
|
231
|
+
: {}
|
|
232
|
+
>
|
|
233
|
+
>
|
|
234
|
+
>>
|
|
235
|
+
: never
|
|
236
|
+
: never
|
|
237
|
+
: never
|
|
238
|
+
}[Collections[Collection]];
|
|
239
|
+
}
|
|
240
|
+
: never
|
|
241
|
+
}[keyof E];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export type ElectroDBMethodTypes = "put" | "get" | "query" | "scan" | "update" | "delete" | "remove" | "patch" | "create" | "batchGet" | "batchWrite";
|
|
245
|
+
|
|
246
|
+
export interface ElectroQueryEvent<P extends any = any> {
|
|
247
|
+
type: 'query';
|
|
248
|
+
method: ElectroDBMethodTypes;
|
|
249
|
+
config: any;
|
|
250
|
+
params: P;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export interface ElectroResultsEvent<R extends any = any> {
|
|
254
|
+
type: 'results';
|
|
255
|
+
method: ElectroDBMethodTypes;
|
|
256
|
+
config: any;
|
|
257
|
+
results: R;
|
|
258
|
+
success: boolean;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export type ElectroEvent =
|
|
262
|
+
ElectroQueryEvent
|
|
263
|
+
| ElectroResultsEvent;
|
|
264
|
+
|
|
265
|
+
export type ElectroEventType = Pick<ElectroEvent, 'type'>;
|
|
266
|
+
|
|
267
|
+
export type ElectroEventListener = (event: ElectroEvent) => void;
|
|
268
|
+
|
|
269
|
+
// todo: coming soon, more events!
|
|
270
|
+
// | {
|
|
271
|
+
// name: "error";
|
|
272
|
+
// type: "configuration_error" | "invalid_query" | "dynamodb_client";
|
|
273
|
+
// message: string;
|
|
274
|
+
// details: ElectroError;
|
|
275
|
+
// } | {
|
|
276
|
+
// name: "error";
|
|
277
|
+
// type: "user_defined";
|
|
278
|
+
// message: string;
|
|
279
|
+
// details: ElectroValidationError;
|
|
280
|
+
// } | {
|
|
281
|
+
// name: "warn";
|
|
282
|
+
// type: "deprecation_warning" | "optimization_suggestion";
|
|
283
|
+
// message: string;
|
|
284
|
+
// details: any;
|
|
285
|
+
// } | {
|
|
286
|
+
// name: "info";
|
|
287
|
+
// type: "client_updated" | "table_overwritten";
|
|
288
|
+
// message: string;
|
|
289
|
+
// details: any;
|
|
290
|
+
// };
|
|
291
|
+
|
|
292
|
+
export type EntityItem<E extends Entity<any, any, any, any>> =
|
|
293
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
294
|
+
? ResponseItem<A, F, C, S>
|
|
295
|
+
: never;
|
|
296
|
+
|
|
297
|
+
export type CreateEntityItem<E extends Entity<any, any, any, any>> =
|
|
298
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
299
|
+
? PutItem<A, F, C, S>
|
|
300
|
+
: never;
|
|
301
|
+
|
|
302
|
+
export type UpdateEntityItem<E extends Entity<any, any, any, any>> =
|
|
303
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
304
|
+
? Partial<ResponseItem<A,F,C,S>>
|
|
305
|
+
: never;
|
|
306
|
+
|
|
307
|
+
export type UpdateAddEntityItem<E extends Entity<any, any, any, any>> =
|
|
308
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
309
|
+
? AddItem<A, F, C, S>
|
|
310
|
+
: never;
|
|
311
|
+
|
|
312
|
+
export type UpdateSubtractEntityItem<E extends Entity<any, any, any, any>> =
|
|
313
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
314
|
+
? SubtractItem<A, F, C, S>
|
|
315
|
+
: never;
|
|
316
|
+
|
|
317
|
+
export type UpdateAppendEntityItem<E extends Entity<any, any, any, any>> =
|
|
318
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
319
|
+
? AppendItem<A, F, C, S>
|
|
320
|
+
: never;
|
|
321
|
+
|
|
322
|
+
export type UpdateRemoveEntityItem<E extends Entity<any, any, any, any>> =
|
|
323
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
324
|
+
? RemoveItem<A, F, C, S>
|
|
325
|
+
: never;
|
|
326
|
+
|
|
327
|
+
export type UpdateDeleteEntityItem<E extends Entity<any, any, any, any>> =
|
|
328
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
329
|
+
? DeleteItem<A, F, C, S>
|
|
330
|
+
: never;
|
|
331
|
+
|
|
332
|
+
export type EntityRecord<E extends Entity<any, any, any, any>> =
|
|
333
|
+
E extends Entity<infer A, infer F, infer C, infer S>
|
|
334
|
+
? Item<A,F,C,S,S["attributes"]>
|
|
335
|
+
: never;
|
|
336
|
+
|
|
337
|
+
export type CollectionItem<SERVICE extends Service<any>, COLLECTION extends keyof SERVICE["collections"]> =
|
|
338
|
+
SERVICE extends Service<infer E>
|
|
339
|
+
? Pick<{
|
|
340
|
+
[EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
|
|
341
|
+
? COLLECTION extends keyof CollectionAssociations<E>
|
|
342
|
+
? EntityName extends CollectionAssociations<E>[COLLECTION]
|
|
343
|
+
? ResponseItem<A,F,C,S>[]
|
|
344
|
+
: never
|
|
345
|
+
: never
|
|
346
|
+
: never
|
|
347
|
+
}, COLLECTION extends keyof CollectionAssociations<E>
|
|
348
|
+
? CollectionAssociations<E>[COLLECTION]
|
|
349
|
+
: never>
|
|
350
|
+
: never
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
export interface RecordsActionOptions<A extends string,
|
|
354
|
+
F extends string, C extends string, S extends Schema<A,F,C>, Items, IndexCompositeAttributes> {
|
|
355
|
+
go: GoRecord<Items>;
|
|
356
|
+
params: ParamRecord;
|
|
357
|
+
page: PageRecord<Items,IndexCompositeAttributes>;
|
|
358
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,RecordsActionOptions<A,F,C,S,Items,IndexCompositeAttributes>>;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export interface SingleRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
|
|
362
|
+
go: GoRecord<ResponseType, QueryOptions>;
|
|
363
|
+
params: ParamRecord<QueryOptions>;
|
|
364
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,SingleRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export interface PutRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
|
|
368
|
+
go: GoRecord<ResponseType, PutQueryOptions>;
|
|
369
|
+
params: ParamRecord<PutQueryOptions>;
|
|
370
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,PutRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export interface UpdateRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
|
|
374
|
+
go: GoRecord<ResponseType, UpdateQueryOptions>;
|
|
375
|
+
params: ParamRecord<UpdateQueryParams>;
|
|
376
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,PutRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface DeleteRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
|
|
380
|
+
go: GoRecord<ResponseType, DeleteQueryOptions>;
|
|
381
|
+
params: ParamRecord<DeleteQueryOptions>;
|
|
382
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,DeleteRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export interface BulkRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType, AlternateResponseType> {
|
|
386
|
+
go: BatchGoRecord<ResponseType, AlternateResponseType>;
|
|
387
|
+
params: ParamRecord<BulkOptions>;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export interface SetRecordActionOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr,IndexCompositeAttributes,TableItem> {
|
|
391
|
+
go: GoRecord<Partial<TableItem>, UpdateQueryOptions>;
|
|
392
|
+
params: ParamRecord<UpdateQueryParams>;
|
|
393
|
+
set: SetRecord<A,F,C,S, SetItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
394
|
+
remove: SetRecord<A,F,C,S, Array<keyof SetItem<A,F,C,S>>,IndexCompositeAttributes,TableItem>;
|
|
395
|
+
add: SetRecord<A,F,C,S, AddItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
396
|
+
subtract: SetRecord<A,F,C,S, SubtractItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
397
|
+
append: SetRecord<A,F,C,S, AppendItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
398
|
+
delete: SetRecord<A,F,C,S, DeleteItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
399
|
+
data: DataUpdateMethodRecord<A,F,C,S, Item<A,F,C,S,S["attributes"]>,IndexCompositeAttributes,TableItem>;
|
|
400
|
+
where: WhereClause<A,F,C,S, Item<A,F,C,S,S["attributes"]>,SetRecordActionOptions<A,F,C,S,SetAttr,IndexCompositeAttributes,TableItem>>;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
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>;
|
|
404
|
+
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>;
|
|
405
|
+
|
|
406
|
+
export type DataUpdateMethodRecord<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr, IndexCompositeAttributes, TableItem> =
|
|
407
|
+
DataUpdateMethod<A,F,C,S, UpdateData<A,F,C,S>, SetRecordActionOptions<A,F,C,S, SetAttr, IndexCompositeAttributes, TableItem>>
|
|
408
|
+
|
|
409
|
+
interface QueryOperations<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, CompositeAttributes, TableItem, IndexCompositeAttributes> {
|
|
410
|
+
between: (skCompositeAttributesStart: CompositeAttributes, skCompositeAttributesEnd: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
411
|
+
gt: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
412
|
+
gte: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
413
|
+
lt: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
414
|
+
lte: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
415
|
+
begins: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
416
|
+
go: GoRecord<Array<TableItem>>;
|
|
417
|
+
params: ParamRecord;
|
|
418
|
+
page: PageRecord<Array<TableItem>,IndexCompositeAttributes>;
|
|
419
|
+
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,RecordsActionOptions<A,F,C,S,Array<TableItem>,IndexCompositeAttributes>>
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export type Queries<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
|
|
423
|
+
[I in keyof S["indexes"]]: <CompositeAttributes extends IndexCompositeAttributes<A,F,C,S,I>>(composite: CompositeAttributes) =>
|
|
424
|
+
IndexSKAttributes<A,F,C,S,I> extends infer SK
|
|
425
|
+
// If there is no SK, dont show query operations (when an empty array is provided)
|
|
426
|
+
? [keyof SK] extends [never]
|
|
427
|
+
? RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes>>
|
|
428
|
+
// If there is no SK, dont show query operations (When no PK is specified)
|
|
429
|
+
: S["indexes"][I] extends IndexWithSortKey
|
|
430
|
+
? QueryOperations<
|
|
431
|
+
A,F,C,S,
|
|
432
|
+
// Omit the composite attributes already provided
|
|
433
|
+
Omit<Partial<IndexSKAttributes<A,F,C,S,I>>, keyof CompositeAttributes>,
|
|
434
|
+
ResponseItem<A,F,C,S>,
|
|
435
|
+
AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes> & SK
|
|
436
|
+
>
|
|
437
|
+
: RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes> & SK>
|
|
438
|
+
: never
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export type ParseSingleInput = {
|
|
442
|
+
Item?: {[key: string]: any}
|
|
443
|
+
} | {
|
|
444
|
+
Attributes?: {[key: string]: any}
|
|
445
|
+
} | null;
|
|
446
|
+
|
|
447
|
+
export type ParseMultiInput = {
|
|
448
|
+
Items?: {[key: string]: any}[]
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export type ReturnValues = "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
452
|
+
|
|
453
|
+
export interface QueryOptions {
|
|
454
|
+
raw?: boolean;
|
|
455
|
+
table?: string;
|
|
456
|
+
limit?: number;
|
|
457
|
+
params?: object;
|
|
458
|
+
includeKeys?: boolean;
|
|
459
|
+
originalErr?: boolean;
|
|
460
|
+
ignoreOwnership?: boolean;
|
|
461
|
+
pages?: number;
|
|
462
|
+
listeners?: Array<ElectroEventListener>;
|
|
463
|
+
logger?: ElectroEventListener;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// subset of QueryOptions
|
|
467
|
+
export interface ParseOptions {
|
|
468
|
+
ignoreOwnership?: boolean;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export interface UpdateQueryOptions extends QueryOptions {
|
|
472
|
+
response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export interface UpdateQueryParams {
|
|
476
|
+
response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
477
|
+
table?: string;
|
|
478
|
+
params?: object;
|
|
479
|
+
originalErr?: boolean;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export interface DeleteQueryOptions extends QueryOptions {
|
|
483
|
+
response?: "default" | "none" | 'all_old';
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export interface PutQueryOptions extends QueryOptions {
|
|
487
|
+
response?: "default" | "none" | 'all_old';
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export interface ParamOptions {
|
|
491
|
+
params?: object;
|
|
492
|
+
table?: string;
|
|
493
|
+
limit?: number;
|
|
494
|
+
response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export interface PaginationOptions extends QueryOptions {
|
|
498
|
+
pager?: "raw" | "item" | "named";
|
|
499
|
+
limit?: number;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export interface BulkOptions extends QueryOptions {
|
|
503
|
+
unprocessed?: "raw" | "item";
|
|
504
|
+
concurrency?: number;
|
|
505
|
+
preserveBatchOrder?: boolean;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
export type OptionalDefaultEntityIdentifiers = {
|
|
509
|
+
__edb_e__?: string;
|
|
510
|
+
__edb_v__?: string;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export type GoRecord<ResponseType, Options = QueryOptions> = <T = ResponseType>(options?: Options) => Promise<T>;
|
|
514
|
+
|
|
515
|
+
export type BatchGoRecord<ResponseType, AlternateResponseType> = <O extends BulkOptions>(options?: O) =>
|
|
516
|
+
O extends infer Options
|
|
517
|
+
? 'preserveBatchOrder' extends keyof Options
|
|
518
|
+
? Options['preserveBatchOrder'] extends true
|
|
519
|
+
? Promise<AlternateResponseType>
|
|
520
|
+
: Promise<ResponseType>
|
|
521
|
+
: Promise<ResponseType>
|
|
522
|
+
: never
|
|
523
|
+
|
|
524
|
+
export type PageRecord<ResponseType, CompositeAttributes> = (page?: (CompositeAttributes & OptionalDefaultEntityIdentifiers) | null, options?: PaginationOptions) => Promise<[
|
|
525
|
+
(CompositeAttributes & OptionalDefaultEntityIdentifiers) | null,
|
|
526
|
+
ResponseType
|
|
527
|
+
]>;
|
|
528
|
+
|
|
529
|
+
export type ParamRecord<Options = ParamOptions> = <P>(options?: Options) => P;
|
|
9
530
|
|
|
10
531
|
export interface ElectroError extends Error {
|
|
11
532
|
readonly name: 'ElectroError';
|
|
@@ -20,7 +541,7 @@ export interface ElectroError extends Error {
|
|
|
20
541
|
}
|
|
21
542
|
}
|
|
22
543
|
|
|
23
|
-
interface ElectroValidationErrorFieldReference<T extends Error = Error> {
|
|
544
|
+
export interface ElectroValidationErrorFieldReference<T extends Error = Error> {
|
|
24
545
|
/**
|
|
25
546
|
* The json path to the attribute that had a validation error
|
|
26
547
|
*/
|
|
@@ -46,23 +567,27 @@ export interface ElectroValidationError<T extends Error = Error> extends Electro
|
|
|
46
567
|
readonly fields: ReadonlyArray<ElectroValidationErrorFieldReference<T>>;
|
|
47
568
|
}
|
|
48
569
|
|
|
49
|
-
interface ReadOnlyAttribute {
|
|
570
|
+
export interface ReadOnlyAttribute {
|
|
50
571
|
readonly readOnly: true;
|
|
51
572
|
}
|
|
52
573
|
|
|
53
|
-
interface RequiredAttribute {
|
|
54
|
-
|
|
574
|
+
export interface RequiredAttribute {
|
|
575
|
+
required: true;
|
|
55
576
|
}
|
|
56
577
|
|
|
57
|
-
interface HiddenAttribute {
|
|
578
|
+
export interface HiddenAttribute {
|
|
58
579
|
readonly hidden: true;
|
|
59
580
|
}
|
|
60
581
|
|
|
61
|
-
interface DefaultedAttribute {
|
|
582
|
+
export interface DefaultedAttribute {
|
|
62
583
|
readonly default: any;
|
|
63
584
|
}
|
|
64
585
|
|
|
65
|
-
|
|
586
|
+
export interface SecondaryIndex {
|
|
587
|
+
readonly index: string;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
export interface NestedBooleanAttribute {
|
|
66
591
|
readonly type: "boolean";
|
|
67
592
|
readonly required?: boolean;
|
|
68
593
|
readonly hidden?: boolean;
|
|
@@ -74,7 +599,7 @@ type NestedBooleanAttribute = {
|
|
|
74
599
|
readonly field?: string;
|
|
75
600
|
}
|
|
76
601
|
|
|
77
|
-
|
|
602
|
+
export interface BooleanAttribute {
|
|
78
603
|
readonly type: "boolean";
|
|
79
604
|
readonly required?: boolean;
|
|
80
605
|
readonly hidden?: boolean;
|
|
@@ -88,7 +613,7 @@ type BooleanAttribute = {
|
|
|
88
613
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
89
614
|
}
|
|
90
615
|
|
|
91
|
-
|
|
616
|
+
export interface NestedNumberAttribute {
|
|
92
617
|
readonly type: "number";
|
|
93
618
|
readonly required?: boolean;
|
|
94
619
|
readonly hidden?: boolean;
|
|
@@ -100,7 +625,7 @@ type NestedNumberAttribute = {
|
|
|
100
625
|
readonly field?: string;
|
|
101
626
|
}
|
|
102
627
|
|
|
103
|
-
|
|
628
|
+
export interface NumberAttribute {
|
|
104
629
|
readonly type: "number";
|
|
105
630
|
readonly required?: boolean;
|
|
106
631
|
readonly hidden?: boolean;
|
|
@@ -114,7 +639,7 @@ type NumberAttribute = {
|
|
|
114
639
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
115
640
|
}
|
|
116
641
|
|
|
117
|
-
|
|
642
|
+
export interface NestedStringAttribute {
|
|
118
643
|
readonly type: "string";
|
|
119
644
|
readonly required?: boolean;
|
|
120
645
|
readonly hidden?: boolean;
|
|
@@ -126,7 +651,7 @@ type NestedStringAttribute = {
|
|
|
126
651
|
readonly field?: string;
|
|
127
652
|
}
|
|
128
653
|
|
|
129
|
-
|
|
654
|
+
export interface StringAttribute {
|
|
130
655
|
readonly type: "string";
|
|
131
656
|
readonly required?: boolean;
|
|
132
657
|
readonly hidden?: boolean;
|
|
@@ -140,7 +665,7 @@ type StringAttribute = {
|
|
|
140
665
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
141
666
|
}
|
|
142
667
|
|
|
143
|
-
|
|
668
|
+
export interface NestedEnumAttribute {
|
|
144
669
|
readonly type: ReadonlyArray<string>;
|
|
145
670
|
readonly required?: boolean;
|
|
146
671
|
readonly hidden?: boolean;
|
|
@@ -154,7 +679,7 @@ type NestedEnumAttribute = {
|
|
|
154
679
|
}
|
|
155
680
|
|
|
156
681
|
|
|
157
|
-
|
|
682
|
+
export interface EnumAttribute {
|
|
158
683
|
readonly type: ReadonlyArray<string>;
|
|
159
684
|
readonly required?: boolean;
|
|
160
685
|
readonly hidden?: boolean;
|
|
@@ -168,7 +693,7 @@ type EnumAttribute = {
|
|
|
168
693
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
169
694
|
}
|
|
170
695
|
|
|
171
|
-
|
|
696
|
+
export interface NestedAnyAttribute {
|
|
172
697
|
readonly type: "any";
|
|
173
698
|
readonly required?: boolean;
|
|
174
699
|
readonly hidden?: boolean;
|
|
@@ -180,7 +705,7 @@ type NestedAnyAttribute = {
|
|
|
180
705
|
readonly field?: string;
|
|
181
706
|
}
|
|
182
707
|
|
|
183
|
-
|
|
708
|
+
export interface AnyAttribute {
|
|
184
709
|
readonly type: "any";
|
|
185
710
|
readonly required?: boolean;
|
|
186
711
|
readonly hidden?: boolean;
|
|
@@ -194,7 +719,7 @@ type AnyAttribute = {
|
|
|
194
719
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
195
720
|
}
|
|
196
721
|
|
|
197
|
-
|
|
722
|
+
export interface NestedMapAttribute {
|
|
198
723
|
readonly type: "map";
|
|
199
724
|
readonly properties: {
|
|
200
725
|
readonly [name: string]: NestedAttributes;
|
|
@@ -209,7 +734,7 @@ type NestedMapAttribute = {
|
|
|
209
734
|
readonly field?: string;
|
|
210
735
|
}
|
|
211
736
|
|
|
212
|
-
|
|
737
|
+
export interface MapAttribute {
|
|
213
738
|
readonly type: "map";
|
|
214
739
|
readonly properties: {
|
|
215
740
|
readonly [name: string]: NestedAttributes;
|
|
@@ -225,7 +750,7 @@ type MapAttribute = {
|
|
|
225
750
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
226
751
|
}
|
|
227
752
|
|
|
228
|
-
|
|
753
|
+
export interface NestedStringListAttribute {
|
|
229
754
|
readonly type: "list";
|
|
230
755
|
readonly items: {
|
|
231
756
|
readonly type: "string";
|
|
@@ -247,7 +772,7 @@ type NestedStringListAttribute = {
|
|
|
247
772
|
readonly validate?: ((val: Array<string>) => boolean) | ((val: Array<string>) => void) | ((val: Array<string>) => string | void);
|
|
248
773
|
}
|
|
249
774
|
|
|
250
|
-
|
|
775
|
+
export interface StringListAttribute {
|
|
251
776
|
readonly type: "list";
|
|
252
777
|
readonly items: {
|
|
253
778
|
readonly type: "string";
|
|
@@ -270,7 +795,7 @@ type StringListAttribute = {
|
|
|
270
795
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
271
796
|
}
|
|
272
797
|
|
|
273
|
-
|
|
798
|
+
export interface NestedNumberListAttribute {
|
|
274
799
|
readonly type: "list";
|
|
275
800
|
readonly items: NestedNumberAttribute;
|
|
276
801
|
readonly required?: boolean;
|
|
@@ -283,7 +808,7 @@ type NestedNumberListAttribute = {
|
|
|
283
808
|
readonly field?: string;
|
|
284
809
|
}
|
|
285
810
|
|
|
286
|
-
|
|
811
|
+
export interface NumberListAttribute {
|
|
287
812
|
readonly type: "list";
|
|
288
813
|
readonly items: NestedNumberAttribute;
|
|
289
814
|
readonly required?: boolean;
|
|
@@ -297,7 +822,7 @@ type NumberListAttribute = {
|
|
|
297
822
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
298
823
|
}
|
|
299
824
|
|
|
300
|
-
|
|
825
|
+
export interface NestedMapListAttribute {
|
|
301
826
|
readonly type: "list";
|
|
302
827
|
readonly items: NestedMapAttribute;
|
|
303
828
|
readonly required?: boolean;
|
|
@@ -310,7 +835,7 @@ type NestedMapListAttribute = {
|
|
|
310
835
|
readonly field?: string;
|
|
311
836
|
}
|
|
312
837
|
|
|
313
|
-
|
|
838
|
+
export interface MapListAttribute {
|
|
314
839
|
readonly type: "list";
|
|
315
840
|
readonly items: NestedMapAttribute;
|
|
316
841
|
readonly required?: boolean;
|
|
@@ -324,7 +849,7 @@ type MapListAttribute = {
|
|
|
324
849
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
325
850
|
}
|
|
326
851
|
|
|
327
|
-
|
|
852
|
+
export interface NestedStringSetAttribute {
|
|
328
853
|
readonly type: "set";
|
|
329
854
|
readonly items: "string";
|
|
330
855
|
readonly required?: boolean;
|
|
@@ -337,7 +862,7 @@ type NestedStringSetAttribute = {
|
|
|
337
862
|
readonly field?: string;
|
|
338
863
|
}
|
|
339
864
|
|
|
340
|
-
|
|
865
|
+
export interface StringSetAttribute {
|
|
341
866
|
readonly type: "set";
|
|
342
867
|
readonly items: "string";
|
|
343
868
|
readonly required?: boolean;
|
|
@@ -351,7 +876,7 @@ type StringSetAttribute = {
|
|
|
351
876
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
352
877
|
}
|
|
353
878
|
|
|
354
|
-
|
|
879
|
+
export interface NestedNumberSetAttribute {
|
|
355
880
|
readonly type: "set";
|
|
356
881
|
readonly items: "number";
|
|
357
882
|
readonly required?: boolean;
|
|
@@ -364,7 +889,7 @@ type NestedNumberSetAttribute = {
|
|
|
364
889
|
readonly field?: string;
|
|
365
890
|
}
|
|
366
891
|
|
|
367
|
-
|
|
892
|
+
export interface NumberSetAttribute {
|
|
368
893
|
readonly type: "set";
|
|
369
894
|
readonly items: "number";
|
|
370
895
|
readonly required?: boolean;
|
|
@@ -378,7 +903,7 @@ type NumberSetAttribute = {
|
|
|
378
903
|
readonly watch?: ReadonlyArray<string> | "*";
|
|
379
904
|
}
|
|
380
905
|
|
|
381
|
-
type Attribute =
|
|
906
|
+
export type Attribute =
|
|
382
907
|
BooleanAttribute
|
|
383
908
|
| NumberAttribute
|
|
384
909
|
| StringAttribute
|
|
@@ -391,7 +916,7 @@ type Attribute =
|
|
|
391
916
|
| NumberListAttribute
|
|
392
917
|
| MapListAttribute;
|
|
393
918
|
|
|
394
|
-
type NestedAttributes =
|
|
919
|
+
export type NestedAttributes =
|
|
395
920
|
NestedBooleanAttribute
|
|
396
921
|
| NestedNumberAttribute
|
|
397
922
|
| NestedStringAttribute
|
|
@@ -402,27 +927,9 @@ type NestedAttributes =
|
|
|
402
927
|
| NestedMapListAttribute
|
|
403
928
|
| NestedStringSetAttribute
|
|
404
929
|
| NestedNumberSetAttribute
|
|
405
|
-
| NestedEnumAttribute
|
|
406
|
-
|
|
407
|
-
type Attributes<A extends string> = {
|
|
408
|
-
readonly [a in A]: Attribute
|
|
409
|
-
}
|
|
930
|
+
| NestedEnumAttribute;
|
|
410
931
|
|
|
411
|
-
|
|
412
|
-
readonly index: string;
|
|
413
|
-
readonly pk: {
|
|
414
|
-
readonly field: string;
|
|
415
|
-
readonly composite: ReadonlyArray<string>;
|
|
416
|
-
readonly template?: string;
|
|
417
|
-
}
|
|
418
|
-
readonly sk?: {
|
|
419
|
-
readonly field: string;
|
|
420
|
-
readonly composite: ReadonlyArray<string>;
|
|
421
|
-
readonly template?: string;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
type IndexWithSortKey = {
|
|
932
|
+
export interface IndexWithSortKey {
|
|
426
933
|
readonly sk: {
|
|
427
934
|
readonly field: string;
|
|
428
935
|
readonly composite: ReadonlyArray<string>;
|
|
@@ -430,9 +937,9 @@ type IndexWithSortKey = {
|
|
|
430
937
|
}
|
|
431
938
|
}
|
|
432
939
|
|
|
433
|
-
type AccessPatternCollection<C extends string> = C | ReadonlyArray<C>;
|
|
940
|
+
export type AccessPatternCollection<C extends string> = C | ReadonlyArray<C>;
|
|
434
941
|
|
|
435
|
-
|
|
942
|
+
export interface Schema<A extends string, F extends string, C extends string> {
|
|
436
943
|
readonly model: {
|
|
437
944
|
readonly entity: string;
|
|
438
945
|
readonly service: string;
|
|
@@ -444,7 +951,7 @@ type Schema<A extends string, F extends A, C extends string> = {
|
|
|
444
951
|
readonly indexes: {
|
|
445
952
|
[accessPattern: string]: {
|
|
446
953
|
readonly index?: string;
|
|
447
|
-
readonly collection?:
|
|
954
|
+
readonly collection?: AccessPatternCollection<C>;
|
|
448
955
|
readonly pk: {
|
|
449
956
|
readonly casing?: "upper" | "lower" | "none" | "default";
|
|
450
957
|
readonly field: string;
|
|
@@ -459,16 +966,18 @@ type Schema<A extends string, F extends A, C extends string> = {
|
|
|
459
966
|
}
|
|
460
967
|
}
|
|
461
968
|
}
|
|
462
|
-
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
export type Attributes<A extends string> = Record<A, Attribute>
|
|
463
972
|
|
|
464
|
-
type IndexCollections<A extends string, F extends
|
|
973
|
+
export type IndexCollections<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
|
|
465
974
|
[i in keyof S["indexes"]]: S["indexes"][i]["collection"] extends
|
|
466
975
|
AccessPatternCollection<infer Name>
|
|
467
|
-
|
|
468
|
-
|
|
976
|
+
? Name
|
|
977
|
+
: never
|
|
469
978
|
}[keyof S["indexes"]];
|
|
470
979
|
|
|
471
|
-
type EntityCollections<A extends string, F extends
|
|
980
|
+
export type EntityCollections<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
|
|
472
981
|
[N in IndexCollections<A,F,C,S>]: {
|
|
473
982
|
[i in keyof S["indexes"]]: S["indexes"][i]["collection"] extends AccessPatternCollection<infer Name>
|
|
474
983
|
? Name extends N
|
|
@@ -478,7 +987,20 @@ type EntityCollections<A extends string, F extends A, C extends string, S extend
|
|
|
478
987
|
}[keyof S["indexes"]];
|
|
479
988
|
}
|
|
480
989
|
|
|
481
|
-
|
|
990
|
+
declare const SkipSymbol: unique symbol;
|
|
991
|
+
type SkipValue = typeof SkipSymbol;
|
|
992
|
+
|
|
993
|
+
type PartialDefinedKeys<T> = {
|
|
994
|
+
[P in keyof T as
|
|
995
|
+
[undefined] extends [T[P]]
|
|
996
|
+
? never
|
|
997
|
+
: SkipValue extends T[P]
|
|
998
|
+
? never
|
|
999
|
+
: P
|
|
1000
|
+
]?: T[P] | undefined;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
export type ItemAttribute<A extends Attribute> =
|
|
482
1004
|
A["type"] extends infer R
|
|
483
1005
|
? R extends "string" ? string
|
|
484
1006
|
: R extends "number" ? number
|
|
@@ -490,8 +1012,8 @@ type ItemAttribute<A extends Attribute> =
|
|
|
490
1012
|
[P in keyof A["properties"]]:
|
|
491
1013
|
A["properties"][P] extends infer M
|
|
492
1014
|
? M extends Attribute
|
|
493
|
-
|
|
494
|
-
|
|
1015
|
+
? ItemAttribute<M>
|
|
1016
|
+
: never
|
|
495
1017
|
: never
|
|
496
1018
|
}
|
|
497
1019
|
: never
|
|
@@ -515,9 +1037,20 @@ type ItemAttribute<A extends Attribute> =
|
|
|
515
1037
|
: never
|
|
516
1038
|
: never
|
|
517
1039
|
|
|
518
|
-
type
|
|
519
|
-
A extends
|
|
520
|
-
|
|
1040
|
+
type FormattedPutMapAttributes<A extends MapAttribute> = {
|
|
1041
|
+
[P in keyof A["properties"]]: A["properties"][P] extends infer M
|
|
1042
|
+
? M extends HiddenAttribute
|
|
1043
|
+
? false
|
|
1044
|
+
: M extends DefaultedAttribute
|
|
1045
|
+
? false
|
|
1046
|
+
: M extends RequiredAttribute
|
|
1047
|
+
? true
|
|
1048
|
+
: false
|
|
1049
|
+
: false
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
export type ReturnedAttribute<A extends Attribute> =
|
|
1053
|
+
A["type"] extends infer R
|
|
521
1054
|
? R extends "string" ? string
|
|
522
1055
|
: R extends "number" ? number
|
|
523
1056
|
: R extends "boolean" ? boolean
|
|
@@ -525,15 +1058,48 @@ type ReturnedAttribute<A extends Attribute> =
|
|
|
525
1058
|
: R extends "map"
|
|
526
1059
|
? "properties" extends keyof A
|
|
527
1060
|
?
|
|
528
|
-
|
|
529
|
-
[
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
1061
|
+
{
|
|
1062
|
+
[
|
|
1063
|
+
P in keyof A["properties"] as A["properties"][P] extends RequiredAttribute
|
|
1064
|
+
? P
|
|
1065
|
+
: never
|
|
1066
|
+
]: A["properties"][P] extends infer M
|
|
1067
|
+
? M extends Attribute
|
|
1068
|
+
? ReturnedAttribute<M>
|
|
1069
|
+
: never
|
|
1070
|
+
: never
|
|
1071
|
+
} & {
|
|
1072
|
+
[
|
|
1073
|
+
P in keyof A["properties"] as A["properties"][P] extends HiddenAttribute | RequiredAttribute
|
|
1074
|
+
? never
|
|
1075
|
+
: P
|
|
1076
|
+
]?: A["properties"][P] extends infer M
|
|
1077
|
+
? M extends Attribute
|
|
1078
|
+
? ReturnedAttribute<M> | undefined
|
|
535
1079
|
: never
|
|
536
|
-
|
|
1080
|
+
: never
|
|
1081
|
+
}
|
|
1082
|
+
// SkipKeys<{
|
|
1083
|
+
// [P in keyof A["properties"]]: A["properties"][P] extends infer M
|
|
1084
|
+
// ? M extends Attribute
|
|
1085
|
+
// ? M extends HiddenAttribute
|
|
1086
|
+
// ? SkipValue
|
|
1087
|
+
// : M extends RequiredAttribute
|
|
1088
|
+
// ? ReturnedAttribute<M>
|
|
1089
|
+
// : SkipValue
|
|
1090
|
+
// : never
|
|
1091
|
+
// : never
|
|
1092
|
+
// }> & SkipKeys<{
|
|
1093
|
+
// [P in keyof A["properties"]]?: A["properties"][P] extends infer M
|
|
1094
|
+
// ? M extends Attribute
|
|
1095
|
+
// ? M extends HiddenAttribute
|
|
1096
|
+
// ? SkipValue
|
|
1097
|
+
// : M extends RequiredAttribute
|
|
1098
|
+
// ? SkipValue
|
|
1099
|
+
// : ReturnedAttribute<M> | undefined
|
|
1100
|
+
// : never
|
|
1101
|
+
// : never
|
|
1102
|
+
// }>
|
|
537
1103
|
: never
|
|
538
1104
|
: R extends "list"
|
|
539
1105
|
? "items" extends keyof A
|
|
@@ -555,32 +1121,57 @@ type ReturnedAttribute<A extends Attribute> =
|
|
|
555
1121
|
: never
|
|
556
1122
|
: never
|
|
557
1123
|
|
|
558
|
-
type
|
|
559
|
-
[P in keyof T]: undefined extends T[P] ? P: never
|
|
560
|
-
}[keyof T]
|
|
561
|
-
|
|
562
|
-
type TrimmedAttributes<A extends Attributes<any>> =
|
|
563
|
-
Partial<Pick<A, UndefinedKeys<A>>> & Omit<A, UndefinedKeys<A>>
|
|
564
|
-
|
|
565
|
-
type CreatedAttribute<A extends Attribute> =
|
|
1124
|
+
export type CreatedAttribute<A extends Attribute> =
|
|
566
1125
|
A["type"] extends infer R
|
|
567
|
-
|
|
1126
|
+
? R extends "string" ? string
|
|
568
1127
|
: R extends "number" ? number
|
|
569
1128
|
: R extends "boolean" ? boolean
|
|
570
1129
|
: R extends ReadonlyArray<infer E> ? E
|
|
571
1130
|
: R extends "map"
|
|
572
1131
|
? "properties" extends keyof A
|
|
573
|
-
?
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
1132
|
+
? {
|
|
1133
|
+
[
|
|
1134
|
+
P in keyof A["properties"] as A["properties"][P] extends RequiredAttribute
|
|
1135
|
+
? A["properties"][P] extends DefaultedAttribute
|
|
1136
|
+
? never
|
|
1137
|
+
: P
|
|
1138
|
+
: never
|
|
1139
|
+
]: A["properties"][P] extends infer M
|
|
1140
|
+
? M extends Attribute
|
|
1141
|
+
? CreatedAttribute<M>
|
|
1142
|
+
: never
|
|
1143
|
+
: never
|
|
1144
|
+
} & {
|
|
1145
|
+
[P in keyof A["properties"] as A["properties"][P] extends HiddenAttribute
|
|
1146
|
+
? never
|
|
1147
|
+
: P
|
|
1148
|
+
]?: A["properties"][P] extends infer M
|
|
1149
|
+
? M extends Attribute
|
|
1150
|
+
? CreatedAttribute<M> | undefined
|
|
1151
|
+
: never
|
|
582
1152
|
: never
|
|
583
|
-
|
|
1153
|
+
}
|
|
1154
|
+
// ? SkipKeys<{
|
|
1155
|
+
// [P in keyof A["properties"]]: A["properties"][P] extends infer M
|
|
1156
|
+
// ? M extends Attribute
|
|
1157
|
+
// ? M extends HiddenAttribute
|
|
1158
|
+
// ? SkipValue
|
|
1159
|
+
// : M extends DefaultedAttribute
|
|
1160
|
+
// ? SkipValue
|
|
1161
|
+
// : M extends RequiredAttribute
|
|
1162
|
+
// ? CreatedAttribute<M>
|
|
1163
|
+
// : SkipValue
|
|
1164
|
+
// : never
|
|
1165
|
+
// : never
|
|
1166
|
+
// }> & SkipKeys<{
|
|
1167
|
+
// [P in keyof A["properties"]]?: A["properties"][P] extends infer M
|
|
1168
|
+
// ? M extends Attribute
|
|
1169
|
+
// ? M extends HiddenAttribute
|
|
1170
|
+
// ? SkipValue
|
|
1171
|
+
// : CreatedAttribute<M> | undefined
|
|
1172
|
+
// : never
|
|
1173
|
+
// : never
|
|
1174
|
+
// }>
|
|
584
1175
|
: never
|
|
585
1176
|
: R extends "list"
|
|
586
1177
|
? "items" extends keyof A
|
|
@@ -600,34 +1191,38 @@ type CreatedAttribute<A extends Attribute> =
|
|
|
600
1191
|
: never
|
|
601
1192
|
: R extends "any" ? any
|
|
602
1193
|
: never
|
|
603
|
-
|
|
1194
|
+
: never
|
|
604
1195
|
|
|
605
|
-
type ReturnedItem<A extends string, F extends
|
|
1196
|
+
export type ReturnedItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>,Attr extends S["attributes"]> = {
|
|
606
1197
|
[a in keyof Attr]: ReturnedAttribute<Attr[a]>
|
|
607
1198
|
}
|
|
608
1199
|
|
|
609
|
-
type CreatedItem<A extends string, F extends
|
|
1200
|
+
export type CreatedItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>,Attr extends S["attributes"]> = {
|
|
610
1201
|
[a in keyof Attr]: CreatedAttribute<Attr[a]>
|
|
611
1202
|
}
|
|
612
1203
|
|
|
613
|
-
type EditableItemAttribute<A extends Attribute> =
|
|
1204
|
+
export type EditableItemAttribute<A extends Attribute> =
|
|
614
1205
|
A extends ReadOnlyAttribute
|
|
615
1206
|
? never
|
|
616
1207
|
: A["type"] extends infer R
|
|
617
|
-
|
|
1208
|
+
? R extends "string" ? string
|
|
618
1209
|
: R extends "number" ? number
|
|
619
1210
|
: R extends "boolean" ? boolean
|
|
620
1211
|
: R extends ReadonlyArray<infer E> ? E
|
|
621
1212
|
: R extends "map"
|
|
622
1213
|
? "properties" extends keyof A
|
|
623
|
-
?
|
|
624
|
-
[
|
|
1214
|
+
? {
|
|
1215
|
+
[
|
|
1216
|
+
P in keyof A["properties"] as A["properties"][P] extends ReadOnlyAttribute
|
|
1217
|
+
? never
|
|
1218
|
+
: P
|
|
1219
|
+
]:
|
|
625
1220
|
A["properties"][P] extends infer M
|
|
626
1221
|
? M extends Attribute
|
|
627
|
-
|
|
628
|
-
|
|
1222
|
+
? EditableItemAttribute<M>
|
|
1223
|
+
: never
|
|
629
1224
|
: never
|
|
630
|
-
}
|
|
1225
|
+
}
|
|
631
1226
|
: never
|
|
632
1227
|
: R extends "list"
|
|
633
1228
|
? "items" extends keyof A
|
|
@@ -647,26 +1242,45 @@ type EditableItemAttribute<A extends Attribute> =
|
|
|
647
1242
|
: never
|
|
648
1243
|
: R extends "any" ? any
|
|
649
1244
|
: never
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
type UpdatableItemAttribute<A extends Attribute> =
|
|
1245
|
+
: never
|
|
1246
|
+
|
|
1247
|
+
export type UpdatableItemAttribute<A extends Attribute> =
|
|
653
1248
|
A extends ReadOnlyAttribute
|
|
654
1249
|
? never
|
|
655
1250
|
: A["type"] extends infer R
|
|
656
|
-
|
|
1251
|
+
? R extends "string" ? string
|
|
657
1252
|
: R extends "number" ? number
|
|
658
1253
|
: R extends "boolean" ? boolean
|
|
659
1254
|
: R extends ReadonlyArray<infer E> ? E
|
|
660
1255
|
: R extends "map"
|
|
661
1256
|
? "properties" extends keyof A
|
|
662
1257
|
? {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
1258
|
+
[
|
|
1259
|
+
P in keyof A["properties"] as A["properties"][P] extends ReadOnlyAttribute
|
|
1260
|
+
? never
|
|
1261
|
+
: A["properties"][P] extends RequiredAttribute
|
|
1262
|
+
? P
|
|
668
1263
|
: never
|
|
669
|
-
|
|
1264
|
+
]:
|
|
1265
|
+
A["properties"][P] extends infer M
|
|
1266
|
+
? M extends Attribute
|
|
1267
|
+
? UpdatableItemAttribute<M>
|
|
1268
|
+
: never
|
|
1269
|
+
: never
|
|
1270
|
+
} & {
|
|
1271
|
+
[
|
|
1272
|
+
P in keyof A["properties"] as A["properties"][P] extends ReadOnlyAttribute
|
|
1273
|
+
? never
|
|
1274
|
+
: A["properties"][P] extends RequiredAttribute
|
|
1275
|
+
? never
|
|
1276
|
+
: P
|
|
1277
|
+
]?:
|
|
1278
|
+
A["properties"][P] extends infer M
|
|
1279
|
+
? M extends Attribute
|
|
1280
|
+
? UpdatableItemAttribute<M>
|
|
1281
|
+
: never
|
|
1282
|
+
: never
|
|
1283
|
+
}
|
|
670
1284
|
: never
|
|
671
1285
|
: R extends "list"
|
|
672
1286
|
? "items" extends keyof A
|
|
@@ -686,9 +1300,9 @@ type UpdatableItemAttribute<A extends Attribute> =
|
|
|
686
1300
|
: never
|
|
687
1301
|
: R extends "any" ? any
|
|
688
1302
|
: never
|
|
689
|
-
|
|
1303
|
+
: never
|
|
690
1304
|
|
|
691
|
-
type RemovableItemAttribute<A extends Attribute> =
|
|
1305
|
+
export type RemovableItemAttribute<A extends Attribute> =
|
|
692
1306
|
A extends ReadOnlyAttribute | RequiredAttribute
|
|
693
1307
|
? never
|
|
694
1308
|
: A["type"] extends infer R
|
|
@@ -699,11 +1313,15 @@ type RemovableItemAttribute<A extends Attribute> =
|
|
|
699
1313
|
: R extends "map"
|
|
700
1314
|
? "properties" extends keyof A
|
|
701
1315
|
? {
|
|
702
|
-
[
|
|
1316
|
+
[
|
|
1317
|
+
P in keyof A["properties"] as A["properties"][P] extends ReadOnlyAttribute | RequiredAttribute
|
|
1318
|
+
? never
|
|
1319
|
+
: P
|
|
1320
|
+
]?:
|
|
703
1321
|
A["properties"][P] extends infer M
|
|
704
1322
|
? M extends Attribute
|
|
705
|
-
|
|
706
|
-
|
|
1323
|
+
? UpdatableItemAttribute<M>
|
|
1324
|
+
: never
|
|
707
1325
|
: never
|
|
708
1326
|
}
|
|
709
1327
|
: never
|
|
@@ -727,167 +1345,193 @@ type RemovableItemAttribute<A extends Attribute> =
|
|
|
727
1345
|
: never
|
|
728
1346
|
: never
|
|
729
1347
|
|
|
730
|
-
type Item<A extends string, F extends
|
|
1348
|
+
export type Item<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, Attr extends Attributes<A>> = {
|
|
731
1349
|
[a in keyof Attr]: ItemAttribute<Attr[a]>
|
|
732
1350
|
}
|
|
733
1351
|
|
|
734
|
-
type ItemTypeDescription<A extends string, F extends
|
|
1352
|
+
export type ItemTypeDescription<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
|
|
735
1353
|
[a in keyof S["attributes"]]: S["attributes"][a]["type"] extends infer R
|
|
736
1354
|
? R
|
|
737
1355
|
: never
|
|
738
1356
|
}
|
|
739
1357
|
|
|
740
|
-
type RequiredAttributes<A extends string, F extends
|
|
741
|
-
[a in keyof S["attributes"]]: S["attributes"][a]
|
|
742
|
-
?
|
|
743
|
-
|
|
744
|
-
: never;
|
|
1358
|
+
export type RequiredAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = ExtractKeysOfValueType<{
|
|
1359
|
+
[a in keyof S["attributes"]]: S["attributes"][a] extends RequiredAttribute
|
|
1360
|
+
? true
|
|
1361
|
+
: false
|
|
745
1362
|
}, true>
|
|
746
1363
|
|
|
747
|
-
type HiddenAttributes<A extends string, F extends
|
|
748
|
-
[a in keyof S["attributes"]]: S["attributes"][a]
|
|
749
|
-
?
|
|
750
|
-
|
|
751
|
-
: false
|
|
752
|
-
: never;
|
|
1364
|
+
export type HiddenAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = ExtractKeysOfValueType<{
|
|
1365
|
+
[a in keyof S["attributes"]]: S["attributes"][a] extends HiddenAttribute
|
|
1366
|
+
? true
|
|
1367
|
+
: false
|
|
753
1368
|
}, true>
|
|
754
1369
|
|
|
755
|
-
type ReadOnlyAttributes<A extends string, F extends
|
|
756
|
-
[a in keyof S["attributes"]]: S["attributes"][a]
|
|
757
|
-
?
|
|
758
|
-
|
|
759
|
-
: false
|
|
760
|
-
: never;
|
|
1370
|
+
export type ReadOnlyAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = ExtractKeysOfValueType<{
|
|
1371
|
+
[a in keyof S["attributes"]]: S["attributes"][a] extends ReadOnlyAttribute
|
|
1372
|
+
? true
|
|
1373
|
+
: false
|
|
761
1374
|
}, true>
|
|
762
1375
|
|
|
763
1376
|
type ExtractKeysOfValueType<T, K> = {
|
|
764
1377
|
[I in keyof T]: T[I] extends K ? I : never
|
|
765
1378
|
}[keyof T];
|
|
766
1379
|
|
|
767
|
-
type TableIndexes<A extends string, F extends
|
|
768
|
-
[i in keyof S["indexes"]]: S["indexes"][i] extends
|
|
769
|
-
?
|
|
770
|
-
|
|
771
|
-
: "table"
|
|
772
|
-
: never;
|
|
1380
|
+
export type TableIndexes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
|
|
1381
|
+
[i in keyof S["indexes"]]: S["indexes"][i] extends SecondaryIndex
|
|
1382
|
+
? "secondary"
|
|
1383
|
+
: "table"
|
|
773
1384
|
};
|
|
774
1385
|
|
|
775
|
-
type TableIndexName<A extends string, F extends
|
|
1386
|
+
export type TableIndexName<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = ExtractKeysOfValueType<TableIndexes<A,F,C,S>, "table">;
|
|
776
1387
|
|
|
777
|
-
type PKCompositeAttributes<A extends string, F extends
|
|
778
|
-
[i in keyof S["indexes"]]: S["indexes"][i]["pk"]["composite"]
|
|
1388
|
+
export type PKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
|
|
1389
|
+
[i in keyof S["indexes"]]: S["indexes"][i]["pk"]["composite"] extends ReadonlyArray<infer Composite>
|
|
1390
|
+
? Composite
|
|
1391
|
+
: never
|
|
779
1392
|
}
|
|
780
1393
|
|
|
781
|
-
type SKCompositeAttributes<A extends string, F extends
|
|
1394
|
+
export type SKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
|
|
782
1395
|
[i in keyof S["indexes"]]: S["indexes"][i] extends IndexWithSortKey
|
|
783
|
-
? S["indexes"][i]["sk"]["composite"]
|
|
1396
|
+
? S["indexes"][i]["sk"]["composite"] extends ReadonlyArray<infer Composite>
|
|
1397
|
+
? Composite
|
|
1398
|
+
: never
|
|
784
1399
|
: never;
|
|
785
1400
|
}
|
|
786
1401
|
|
|
787
|
-
type TableIndexPKCompositeAttributes<A extends string, F extends
|
|
1402
|
+
export type TableIndexPKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = Pick<PKCompositeAttributes<A,F,C,S>, TableIndexName<A,F,C,S>>;
|
|
788
1403
|
|
|
789
|
-
type TableIndexSKCompositeAttributes<A extends string, F extends
|
|
1404
|
+
export type TableIndexSKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = Pick<SKCompositeAttributes<A,F,C,S>, TableIndexName<A,F,C,S>>;
|
|
790
1405
|
|
|
791
|
-
type IndexPKCompositeAttributes<A extends string, F extends
|
|
1406
|
+
export type IndexPKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = Pick<PKCompositeAttributes<A,F,C,S>,I>;
|
|
792
1407
|
|
|
793
|
-
type IndexSKCompositeAttributes<A extends string, F extends
|
|
1408
|
+
export type IndexSKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = Pick<SKCompositeAttributes<A,F,C,S>,I>;
|
|
794
1409
|
|
|
795
|
-
type TableIndexPKAttributes<A extends string, F extends
|
|
1410
|
+
export type TableIndexPKAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
1411
|
+
TableIndexName<A,F,C,S> extends keyof TableIndexPKCompositeAttributes<A,F,C,S>
|
|
1412
|
+
? TableIndexPKCompositeAttributes<A,F,C,S>[TableIndexName<A,F,C,S>] extends keyof Item<A,F,C,S,S["attributes"]>
|
|
1413
|
+
? Pick<Item<A,F,C,S,S["attributes"]>, TableIndexPKCompositeAttributes<A,F,C,S>[TableIndexName<A,F,C,S>]>
|
|
1414
|
+
: never
|
|
1415
|
+
: never
|
|
796
1416
|
|
|
797
|
-
type TableIndexSKAttributes<A extends string, F extends
|
|
1417
|
+
export type TableIndexSKAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = TableIndexSKCompositeAttributes<A,F,C,S>[TableIndexName<A,F,C,S>] extends keyof S["attributes"]
|
|
798
1418
|
? Pick<Item<A,F,C,S,S["attributes"]>, TableIndexSKCompositeAttributes<A,F,C,S>[TableIndexName<A,F,C,S>]>
|
|
799
1419
|
: Item<A,F,C,S,S["attributes"]>;
|
|
800
1420
|
|
|
801
|
-
type IndexPKAttributes<A extends string, F extends
|
|
1421
|
+
export type IndexPKAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> =
|
|
1422
|
+
I extends keyof IndexPKCompositeAttributes<A,F,C,S,I>
|
|
1423
|
+
? IndexPKCompositeAttributes<A,F,C,S,I>[I] extends keyof Item<A,F,C,S,S["attributes"]>
|
|
1424
|
+
? Pick<Item<A,F,C,S,S["attributes"]>, IndexPKCompositeAttributes<A,F,C,S,I>[I]>
|
|
1425
|
+
: never
|
|
1426
|
+
: never;
|
|
802
1427
|
|
|
803
|
-
type IndexSKAttributes<A extends string, F extends
|
|
1428
|
+
export type IndexSKAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = IndexSKCompositeAttributes<A,F,C,S,I>[I] extends keyof S["attributes"]
|
|
804
1429
|
? Pick<Item<A,F,C,S,S["attributes"]>, IndexSKCompositeAttributes<A,F,C,S,I>[I]>
|
|
805
1430
|
: Item<A,F,C,S,S["attributes"]>;
|
|
806
1431
|
|
|
807
|
-
type TableIndexCompositeAttributes<A extends string, F extends
|
|
1432
|
+
export type TableIndexCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = TableIndexPKAttributes<A,F,C,S> & Partial<TableIndexSKAttributes<A,F,C,S>>;
|
|
808
1433
|
|
|
809
|
-
type AllTableIndexCompositeAttributes<A extends string, F extends
|
|
1434
|
+
export type AllTableIndexCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = TableIndexPKAttributes<A,F,C,S> & TableIndexSKAttributes<A,F,C,S>;
|
|
810
1435
|
|
|
811
|
-
type IndexCompositeAttributes<A extends string, F extends
|
|
1436
|
+
export type IndexCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = IndexPKAttributes<A,F,C,S,I> & Partial<IndexSKAttributes<A,F,C,S,I>>;
|
|
812
1437
|
|
|
813
|
-
type TableItem<A extends string, F extends
|
|
1438
|
+
export type TableItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
814
1439
|
AllTableIndexCompositeAttributes<A,F,C,S> &
|
|
815
1440
|
Pick<ReturnedItem<A,F,C,S,S["attributes"]>, RequiredAttributes<A,F,C,S>> &
|
|
816
1441
|
Partial<Omit<ReturnedItem<A,F,C,S,S["attributes"]>, RequiredAttributes<A,F,C,S>>>
|
|
817
1442
|
|
|
818
|
-
type ResponseItem<A extends string, F extends
|
|
1443
|
+
export type ResponseItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
819
1444
|
Omit<TableItem<A,F,C,S>, HiddenAttributes<A,F,C,S>>
|
|
820
1445
|
|
|
821
|
-
type RequiredPutItems<A extends string, F extends
|
|
1446
|
+
export type RequiredPutItems<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
|
|
822
1447
|
[Attribute in keyof S["attributes"]]:
|
|
823
1448
|
"default" extends keyof S["attributes"][Attribute]
|
|
824
1449
|
? false
|
|
825
1450
|
: "required" extends keyof S["attributes"][Attribute]
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
: Attribute extends keyof TableIndexCompositeAttributes<A,F,C,S>
|
|
829
|
-
? true
|
|
830
|
-
: false
|
|
1451
|
+
? true extends S["attributes"][Attribute]["required"]
|
|
1452
|
+
? true
|
|
831
1453
|
: Attribute extends keyof TableIndexCompositeAttributes<A,F,C,S>
|
|
832
1454
|
? true
|
|
833
1455
|
: false
|
|
1456
|
+
: Attribute extends keyof TableIndexCompositeAttributes<A,F,C,S>
|
|
1457
|
+
? true
|
|
1458
|
+
: false
|
|
834
1459
|
}
|
|
835
1460
|
|
|
836
|
-
type PutItem<A extends string, F extends
|
|
1461
|
+
export type PutItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
837
1462
|
Pick<CreatedItem<A,F,C,S,S["attributes"]>, ExtractKeysOfValueType<RequiredPutItems<A,F,C,S>,true>>
|
|
838
1463
|
& Partial<CreatedItem<A,F,C,S,S["attributes"]>>
|
|
839
1464
|
|
|
840
|
-
type UpdateData<A extends string, F extends
|
|
1465
|
+
export type UpdateData<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
841
1466
|
Omit<{
|
|
842
1467
|
[Attr in keyof S["attributes"]]: EditableItemAttribute<S["attributes"][Attr]>
|
|
843
1468
|
}, keyof AllTableIndexCompositeAttributes<A,F,C,S> | ReadOnlyAttributes<A,F,C,S>>
|
|
844
1469
|
|
|
845
|
-
type SetItem<A extends string, F extends
|
|
846
|
-
|
|
1470
|
+
export type SetItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
1471
|
+
// UpdatableItemAttribute
|
|
847
1472
|
Omit<{
|
|
848
1473
|
[Attr in keyof S["attributes"]]?: UpdatableItemAttribute<S["attributes"][Attr]>
|
|
849
1474
|
}, keyof AllTableIndexCompositeAttributes<A,F,C,S> | ReadOnlyAttributes<A,F,C,S>>
|
|
850
1475
|
|
|
851
|
-
// type RemoveItem<A extends string, F extends
|
|
1476
|
+
// type RemoveItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
852
1477
|
// Array<keyof SetItem<A,F,C,S>>
|
|
853
|
-
type RemoveItem<A extends string, F extends
|
|
1478
|
+
export type RemoveItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
854
1479
|
Array< keyof Omit<{
|
|
855
1480
|
[Attr in keyof S["attributes"]]?: RemovableItemAttribute<S["attributes"][Attr]>
|
|
856
1481
|
}, keyof AllTableIndexCompositeAttributes<A,F,C,S> | ReadOnlyAttributes<A,F,C,S> | RequiredAttributes<A,F,C,S>>>
|
|
857
1482
|
|
|
858
|
-
type AppendItem<A extends string, F extends
|
|
859
|
-
|
|
860
|
-
[
|
|
861
|
-
|
|
1483
|
+
export type AppendItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
1484
|
+
{
|
|
1485
|
+
[
|
|
1486
|
+
P in keyof ItemTypeDescription<A,F,C,S> as ItemTypeDescription<A,F,C,S>[P] extends 'list' | 'any'
|
|
1487
|
+
? P
|
|
862
1488
|
: never
|
|
863
|
-
|
|
1489
|
+
]?: P extends keyof SetItem<A,F,C,S>
|
|
1490
|
+
? SetItem<A,F,C,S>[P] | undefined
|
|
1491
|
+
: never
|
|
1492
|
+
}
|
|
864
1493
|
|
|
865
|
-
type AddItem<A extends string, F extends
|
|
866
|
-
|
|
867
|
-
[
|
|
868
|
-
|
|
1494
|
+
export type AddItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
1495
|
+
{
|
|
1496
|
+
[
|
|
1497
|
+
P in keyof ItemTypeDescription<A,F,C,S> as ItemTypeDescription<A,F,C,S>[P] extends "number" | "any" | "set"
|
|
1498
|
+
? P
|
|
869
1499
|
: never
|
|
870
|
-
|
|
1500
|
+
]?: P extends keyof SetItem<A,F,C,S>
|
|
1501
|
+
? SetItem<A,F,C,S>[P] | undefined
|
|
1502
|
+
: never
|
|
1503
|
+
}
|
|
871
1504
|
|
|
872
|
-
type SubtractItem<A extends string, F extends
|
|
873
|
-
|
|
874
|
-
[
|
|
875
|
-
|
|
1505
|
+
export type SubtractItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
1506
|
+
{
|
|
1507
|
+
[
|
|
1508
|
+
P in keyof ItemTypeDescription<A,F,C,S> as ItemTypeDescription<A,F,C,S>[P] extends "number" | "any"
|
|
1509
|
+
? P
|
|
876
1510
|
: never
|
|
877
|
-
|
|
1511
|
+
]?: P extends keyof SetItem<A,F,C,S>
|
|
1512
|
+
? SetItem<A,F,C,S>[P] | undefined
|
|
1513
|
+
: never
|
|
1514
|
+
}
|
|
878
1515
|
|
|
879
|
-
type DeleteItem<A extends string, F extends
|
|
880
|
-
|
|
881
|
-
[
|
|
882
|
-
|
|
1516
|
+
export type DeleteItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
|
|
1517
|
+
{
|
|
1518
|
+
[
|
|
1519
|
+
P in keyof ItemTypeDescription<A,F,C,S> as ItemTypeDescription<A,F,C,S>[P] extends "any" | "set"
|
|
1520
|
+
? P
|
|
883
1521
|
: never
|
|
884
|
-
|
|
1522
|
+
]?: P extends keyof SetItem<A,F,C,S>
|
|
1523
|
+
? SetItem<A,F,C,S>[P] | undefined
|
|
1524
|
+
: never
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
export declare const WhereSymbol: unique symbol;
|
|
1528
|
+
export declare const UpdateDataSymbol: unique symbol;
|
|
885
1529
|
|
|
886
1530
|
export type WhereAttributeSymbol<T extends any> =
|
|
887
|
-
|
|
1531
|
+
{ [WhereSymbol]: void }
|
|
888
1532
|
& T extends string ? T
|
|
889
|
-
|
|
890
|
-
|
|
1533
|
+
: T extends number ? T
|
|
1534
|
+
: T extends boolean ? T
|
|
891
1535
|
: T extends {[key: string]: any}
|
|
892
1536
|
? {[key in keyof T]: WhereAttributeSymbol<T[key]>}
|
|
893
1537
|
: T extends ReadonlyArray<infer A>
|
|
@@ -896,17 +1540,17 @@ export type WhereAttributeSymbol<T extends any> =
|
|
|
896
1540
|
? Array<WhereAttributeSymbol<I>>
|
|
897
1541
|
: T
|
|
898
1542
|
|
|
899
|
-
type WhereAttributes<A extends string, F extends
|
|
1543
|
+
export type WhereAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>> = {
|
|
900
1544
|
[Attr in keyof I]: WhereAttributeSymbol<I[Attr]>
|
|
901
1545
|
}
|
|
902
1546
|
|
|
903
|
-
export type DataUpdateAttributeSymbol<T extends any> =
|
|
904
|
-
|
|
1547
|
+
export type DataUpdateAttributeSymbol<T extends any> =
|
|
1548
|
+
{ [UpdateDataSymbol]: void }
|
|
905
1549
|
& T extends string ? T
|
|
906
1550
|
: T extends number ? T
|
|
907
1551
|
: T extends boolean ? T
|
|
908
|
-
|
|
909
|
-
|
|
1552
|
+
: T extends {[key: string]: any}
|
|
1553
|
+
? {[key in keyof T]: DataUpdateAttributeSymbol<T[key]>}
|
|
910
1554
|
: T extends ReadonlyArray<infer A>
|
|
911
1555
|
? ReadonlyArray<DataUpdateAttributeSymbol<A>>
|
|
912
1556
|
: T extends Array<infer I>
|
|
@@ -915,25 +1559,25 @@ export type DataUpdateAttributeSymbol<T extends any> =
|
|
|
915
1559
|
? never
|
|
916
1560
|
: T
|
|
917
1561
|
|
|
918
|
-
type DataUpdateAttributeValues<A extends DataUpdateAttributeSymbol<any>> =
|
|
1562
|
+
export type DataUpdateAttributeValues<A extends DataUpdateAttributeSymbol<any>> =
|
|
919
1563
|
A extends DataUpdateAttributeSymbol<infer T>
|
|
920
1564
|
? T extends string ? T
|
|
921
1565
|
: T extends number ? T
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1566
|
+
: T extends boolean ? T
|
|
1567
|
+
: T extends {[key: string]: any}
|
|
1568
|
+
? {[key in keyof T]?: DataUpdateAttributeValues<T[key]>}
|
|
1569
|
+
: T extends ReadonlyArray<infer A> ? ReadonlyArray<DataUpdateAttributeValues<A>>
|
|
1570
|
+
: T extends Array<infer I> ? Array<DataUpdateAttributeValues<I>>
|
|
1571
|
+
: [T] extends [never]
|
|
1572
|
+
? never
|
|
1573
|
+
: T
|
|
1574
|
+
: never
|
|
931
1575
|
|
|
932
|
-
type DataUpdateAttributes<A extends string, F extends
|
|
1576
|
+
export type DataUpdateAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends UpdateData<A,F,C,S>> = {
|
|
933
1577
|
[Attr in keyof I]: DataUpdateAttributeSymbol<I[Attr]>
|
|
934
1578
|
}
|
|
935
1579
|
|
|
936
|
-
|
|
1580
|
+
export interface WhereOperations<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>> {
|
|
937
1581
|
eq: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
938
1582
|
ne: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
939
1583
|
gt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
@@ -948,293 +1592,56 @@ type WhereOperations<A extends string, F extends A, C extends string, S extends
|
|
|
948
1592
|
notContains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
949
1593
|
value: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: A extends WhereAttributeSymbol<infer V> ? V : never) => A extends WhereAttributeSymbol<infer V> ? V : never;
|
|
950
1594
|
name: <A extends WhereAttributeSymbol<any>>(attr: A) => string;
|
|
951
|
-
}
|
|
1595
|
+
}
|
|
952
1596
|
|
|
953
|
-
|
|
1597
|
+
export interface DataUpdateOperations<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends UpdateData<A,F,C,S>> {
|
|
954
1598
|
set: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A>) => any;
|
|
955
1599
|
remove: <T, A extends DataUpdateAttributeSymbol<T>>(attr: [T] extends [never] ? never : A) => any;
|
|
956
1600
|
append: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A> extends Array<any> ? DataUpdateAttributeValues<A> : never) => any;
|
|
957
|
-
add: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends number | Array<any> ? V : [V] extends [any] ? V : never : never ) => any;
|
|
958
|
-
subtract: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends number ? V : [V] extends [any] ? V : never : never ) => any;
|
|
959
|
-
delete: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends Array<any> ? V : [V] extends [any] ? V : never : never ) => any;
|
|
960
|
-
del: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends Array<any> ? V : never : never ) => any;
|
|
961
|
-
value: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A>) => Required<DataUpdateAttributeValues<A>>;
|
|
962
|
-
name: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A) => any;
|
|
963
|
-
ifNotExists: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A>) => any;
|
|
964
|
-
};
|
|
965
|
-
|
|
966
|
-
type WhereCallback<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>> =
|
|
967
|
-
<W extends WhereAttributes<A,F,C,S,I>>(attributes: W, operations: WhereOperations<A,F,C,S,I>) => string;
|
|
968
|
-
|
|
969
|
-
type DataUpdateCallback<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, I extends UpdateData<A,F,C,S>> =
|
|
970
|
-
<W extends DataUpdateAttributes<A,F,C,S,I>>(attributes: W, operations: DataUpdateOperations<A,F,C,S,I>) => any;
|
|
971
|
-
|
|
972
|
-
type ReturnValues = "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
973
|
-
|
|
974
|
-
interface QueryOptions {
|
|
975
|
-
raw?: boolean;
|
|
976
|
-
table?: string;
|
|
977
|
-
limit?: number;
|
|
978
|
-
params?: object;
|
|
979
|
-
includeKeys?: boolean;
|
|
980
|
-
originalErr?: boolean;
|
|
981
|
-
ignoreOwnership?: boolean;
|
|
982
|
-
pages?: number;
|
|
983
|
-
listeners?: Array<EventListener>;
|
|
984
|
-
logger?: EventListener;
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
// subset of QueryOptions
|
|
988
|
-
interface ParseOptions {
|
|
989
|
-
ignoreOwnership?: boolean;
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
interface UpdateQueryOptions extends QueryOptions {
|
|
993
|
-
response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
interface UpdateQueryParams {
|
|
997
|
-
response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
998
|
-
table?: string;
|
|
999
|
-
params?: object;
|
|
1000
|
-
originalErr?: boolean;
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
interface DeleteQueryOptions extends QueryOptions {
|
|
1004
|
-
response?: "default" | "none" | 'all_old';
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
interface PutQueryOptions extends QueryOptions {
|
|
1008
|
-
response?: "default" | "none" | 'all_old';
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
interface ParamOptions {
|
|
1012
|
-
params?: object;
|
|
1013
|
-
table?: string;
|
|
1014
|
-
limit?: number;
|
|
1015
|
-
response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
interface PaginationOptions extends QueryOptions {
|
|
1019
|
-
pager?: "raw" | "item" | "named";
|
|
1020
|
-
limit?: number;
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
interface BulkOptions extends QueryOptions {
|
|
1024
|
-
unprocessed?: "raw" | "item";
|
|
1025
|
-
concurrency?: number;
|
|
1026
|
-
preserveBatchOrder?: boolean;
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
type OptionalDefaultEntityIdentifiers = {
|
|
1030
|
-
__edb_e__?: string;
|
|
1031
|
-
__edb_v__?: string;
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
type GoRecord<ResponseType, Options = QueryOptions> = <T = ResponseType>(options?: Options) => Promise<T>;
|
|
1035
|
-
|
|
1036
|
-
type BatchGoRecord<ResponseType, AlternateResponseType> = <O extends BulkOptions>(options?: O) =>
|
|
1037
|
-
O extends infer Options
|
|
1038
|
-
? 'preserveBatchOrder' extends keyof Options
|
|
1039
|
-
? Options['preserveBatchOrder'] extends true
|
|
1040
|
-
? Promise<AlternateResponseType>
|
|
1041
|
-
: Promise<ResponseType>
|
|
1042
|
-
: Promise<ResponseType>
|
|
1043
|
-
: never
|
|
1044
|
-
|
|
1045
|
-
type PageRecord<ResponseType, CompositeAttributes> = (page?: (CompositeAttributes & OptionalDefaultEntityIdentifiers) | null, options?: PaginationOptions) => Promise<[
|
|
1046
|
-
(CompositeAttributes & OptionalDefaultEntityIdentifiers) | null,
|
|
1047
|
-
ResponseType
|
|
1048
|
-
]>;
|
|
1049
|
-
|
|
1050
|
-
type ParamRecord<Options = ParamOptions> = <P>(options?: Options) => P;
|
|
1051
|
-
|
|
1052
|
-
type RecordsActionOptions<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, Items, IndexCompositeAttributes> = {
|
|
1053
|
-
go: GoRecord<Items>;
|
|
1054
|
-
params: ParamRecord;
|
|
1055
|
-
page: PageRecord<Items,IndexCompositeAttributes>;
|
|
1056
|
-
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,RecordsActionOptions<A,F,C,S,Items,IndexCompositeAttributes>>;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
type SingleRecordOperationOptions<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, ResponseType> = {
|
|
1060
|
-
go: GoRecord<ResponseType, QueryOptions>;
|
|
1061
|
-
params: ParamRecord<QueryOptions>;
|
|
1062
|
-
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,SingleRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
1063
|
-
};
|
|
1064
|
-
|
|
1065
|
-
type PutRecordOperationOptions<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, ResponseType> = {
|
|
1066
|
-
go: GoRecord<ResponseType, PutQueryOptions>;
|
|
1067
|
-
params: ParamRecord<PutQueryOptions>;
|
|
1068
|
-
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,PutRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
1069
|
-
};
|
|
1070
|
-
|
|
1071
|
-
type UpdateRecordOperationOptions<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, ResponseType> = {
|
|
1072
|
-
go: GoRecord<ResponseType, UpdateQueryOptions>;
|
|
1073
|
-
params: ParamRecord<UpdateQueryParams>;
|
|
1074
|
-
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,PutRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
1075
|
-
};
|
|
1076
|
-
|
|
1077
|
-
type DeleteRecordOperationOptions<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, ResponseType> = {
|
|
1078
|
-
go: GoRecord<ResponseType, DeleteQueryOptions>;
|
|
1079
|
-
params: ParamRecord<DeleteQueryOptions>;
|
|
1080
|
-
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,DeleteRecordOperationOptions<A,F,C,S,ResponseType>>;
|
|
1081
|
-
};
|
|
1082
|
-
|
|
1083
|
-
type BulkRecordOperationOptions<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, ResponseType, AlternateResponseType> = {
|
|
1084
|
-
go: BatchGoRecord<ResponseType, AlternateResponseType>;
|
|
1085
|
-
params: ParamRecord<BulkOptions>;
|
|
1086
|
-
};
|
|
1087
|
-
|
|
1088
|
-
type SetRecordActionOptions<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, SetAttr,IndexCompositeAttributes,TableItem> = {
|
|
1089
|
-
go: GoRecord<Partial<TableItem>, UpdateQueryOptions>;
|
|
1090
|
-
params: ParamRecord<UpdateQueryParams>;
|
|
1091
|
-
set: SetRecord<A,F,C,S, SetItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
1092
|
-
remove: SetRecord<A,F,C,S, Array<keyof SetItem<A,F,C,S>>,IndexCompositeAttributes,TableItem>;
|
|
1093
|
-
add: SetRecord<A,F,C,S, AddItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
1094
|
-
subtract: SetRecord<A,F,C,S, SubtractItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
1095
|
-
append: SetRecord<A,F,C,S, AppendItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
1096
|
-
delete: SetRecord<A,F,C,S, DeleteItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
1097
|
-
data: DataUpdateMethodRecord<A,F,C,S, Item<A,F,C,S,S["attributes"]>,IndexCompositeAttributes,TableItem>;
|
|
1098
|
-
where: WhereClause<A,F,C,S, Item<A,F,C,S,S["attributes"]>,SetRecordActionOptions<A,F,C,S,SetAttr,IndexCompositeAttributes,TableItem>>;
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
type SetRecord<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, SetAttr, IndexCompositeAttributes, TableItem> = (properties: SetAttr) => SetRecordActionOptions<A,F,C,S, SetAttr, IndexCompositeAttributes, TableItem>;
|
|
1102
|
-
type RemoveRecord<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, RemoveAttr, IndexCompositeAttributes, TableItem> = (properties: RemoveAttr) => SetRecordActionOptions<A,F,C,S, RemoveAttr, IndexCompositeAttributes, TableItem>;
|
|
1103
|
-
type DataUpdateMethodRecord<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, SetAttr, IndexCompositeAttributes, TableItem> =
|
|
1104
|
-
DataUpdateMethod<A,F,C,S, UpdateData<A,F,C,S>, SetRecordActionOptions<A,F,C,S, SetAttr, IndexCompositeAttributes, TableItem>>
|
|
1105
|
-
|
|
1106
|
-
type WhereClause<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>, T> = (where: WhereCallback<A,F,C,S,I>) => T;
|
|
1107
|
-
|
|
1108
|
-
type DataUpdateMethod<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, I extends UpdateData<A,F,C,S>, T> = (update: DataUpdateCallback<A,F,C,S,I>) => T;
|
|
1109
|
-
|
|
1110
|
-
type QueryOperations<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, CompositeAttributes, TableItem, IndexCompositeAttributes> = {
|
|
1111
|
-
between: (skCompositeAttributesStart: CompositeAttributes, skCompositeAttributesEnd: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
1112
|
-
gt: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
1113
|
-
gte: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
1114
|
-
lt: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
1115
|
-
lte: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
1116
|
-
begins: (skCompositeAttributes: CompositeAttributes) => RecordsActionOptions<A,F,C,S, Array<TableItem>,IndexCompositeAttributes>;
|
|
1117
|
-
go: GoRecord<Array<TableItem>>;
|
|
1118
|
-
params: ParamRecord;
|
|
1119
|
-
page: PageRecord<Array<TableItem>,IndexCompositeAttributes>;
|
|
1120
|
-
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,RecordsActionOptions<A,F,C,S,Array<TableItem>,IndexCompositeAttributes>>
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
type Queries<A extends string, F extends A, C extends string, S extends Schema<A,F,C>> = {
|
|
1124
|
-
[I in keyof S["indexes"]]: <CompositeAttributes extends IndexCompositeAttributes<A,F,C,S,I>>(composite: CompositeAttributes) =>
|
|
1125
|
-
IndexSKAttributes<A,F,C,S,I> extends infer SK
|
|
1126
|
-
// If there is no SK, dont show query operations (when an empty array is provided)
|
|
1127
|
-
? [keyof SK] extends [never]
|
|
1128
|
-
? RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes>>
|
|
1129
|
-
// If there is no SK, dont show query operations (When no PK is specified)
|
|
1130
|
-
: S["indexes"][I] extends IndexWithSortKey
|
|
1131
|
-
? QueryOperations<
|
|
1132
|
-
A,F,C,S,
|
|
1133
|
-
// Omit the composite attributes already provided
|
|
1134
|
-
Omit<Partial<IndexSKAttributes<A,F,C,S,I>>, keyof CompositeAttributes>,
|
|
1135
|
-
ResponseItem<A,F,C,S>,
|
|
1136
|
-
AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes> & SK
|
|
1137
|
-
>
|
|
1138
|
-
: RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes> & SK>
|
|
1139
|
-
: never
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
type DocumentClientMethod = (parameters: any) => {promise: () => Promise<any>};
|
|
1143
|
-
|
|
1144
|
-
type DocumentClient = {
|
|
1145
|
-
get: DocumentClientMethod;
|
|
1146
|
-
put: DocumentClientMethod;
|
|
1147
|
-
delete: DocumentClientMethod;
|
|
1148
|
-
update: DocumentClientMethod;
|
|
1149
|
-
batchWrite: DocumentClientMethod;
|
|
1150
|
-
batchGet: DocumentClientMethod;
|
|
1151
|
-
scan: DocumentClientMethod;
|
|
1152
|
-
transactGet: DocumentClientMethod;
|
|
1153
|
-
transactWrite: DocumentClientMethod;
|
|
1154
|
-
} | {
|
|
1155
|
-
send: (command: any) => Promise<any>;
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
type ElectroDBMethodTypes = "put" | "get" | "query" | "scan" | "update" | "delete" | "remove" | "patch" | "create" | "batchGet" | "batchWrite";
|
|
1159
|
-
|
|
1160
|
-
interface ElectroQueryEvent<P extends any = any> {
|
|
1161
|
-
type: 'query';
|
|
1162
|
-
method: ElectroDBMethodTypes;
|
|
1163
|
-
config: any;
|
|
1164
|
-
params: P;
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
interface ElectroResultsEvent<R extends any = any> {
|
|
1168
|
-
type: 'results';
|
|
1169
|
-
method: ElectroDBMethodTypes;
|
|
1170
|
-
config: any;
|
|
1171
|
-
results: R;
|
|
1172
|
-
success: boolean;
|
|
1601
|
+
add: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends number | Array<any> ? V : [V] extends [any] ? V : never : never ) => any;
|
|
1602
|
+
subtract: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends number ? V : [V] extends [any] ? V : never : never ) => any;
|
|
1603
|
+
delete: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends Array<any> ? V : [V] extends [any] ? V : never : never ) => any;
|
|
1604
|
+
del: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends Array<any> ? V : never : never ) => any;
|
|
1605
|
+
value: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A>) => Required<DataUpdateAttributeValues<A>>;
|
|
1606
|
+
name: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A) => any;
|
|
1607
|
+
ifNotExists: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A>) => any;
|
|
1173
1608
|
}
|
|
1174
1609
|
|
|
1175
|
-
type
|
|
1176
|
-
|
|
1177
|
-
| ElectroResultsEvent;
|
|
1610
|
+
export type WhereCallback<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>> =
|
|
1611
|
+
<W extends WhereAttributes<A,F,C,S,I>>(attributes: W, operations: WhereOperations<A,F,C,S,I>) => string;
|
|
1178
1612
|
|
|
1179
|
-
type
|
|
1613
|
+
export type DataUpdateCallback<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends UpdateData<A,F,C,S>> =
|
|
1614
|
+
<W extends DataUpdateAttributes<A,F,C,S,I>>(attributes: W, operations: DataUpdateOperations<A,F,C,S,I>) => any;
|
|
1180
1615
|
|
|
1181
|
-
type
|
|
1616
|
+
export type WhereClause<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>, T> = (where: WhereCallback<A,F,C,S,I>) => T;
|
|
1182
1617
|
|
|
1183
|
-
|
|
1184
|
-
// | {
|
|
1185
|
-
// name: "error";
|
|
1186
|
-
// type: "configuration_error" | "invalid_query" | "dynamodb_client";
|
|
1187
|
-
// message: string;
|
|
1188
|
-
// details: ElectroError;
|
|
1189
|
-
// } | {
|
|
1190
|
-
// name: "error";
|
|
1191
|
-
// type: "user_defined";
|
|
1192
|
-
// message: string;
|
|
1193
|
-
// details: ElectroValidationError;
|
|
1194
|
-
// } | {
|
|
1195
|
-
// name: "warn";
|
|
1196
|
-
// type: "deprecation_warning" | "optimization_suggestion";
|
|
1197
|
-
// message: string;
|
|
1198
|
-
// details: any;
|
|
1199
|
-
// } | {
|
|
1200
|
-
// name: "info";
|
|
1201
|
-
// type: "client_updated" | "table_overwritten";
|
|
1202
|
-
// message: string;
|
|
1203
|
-
// details: any;
|
|
1204
|
-
// };
|
|
1618
|
+
export type DataUpdateMethod<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends UpdateData<A,F,C,S>, T> = (update: DataUpdateCallback<A,F,C,S,I>) => T;
|
|
1205
1619
|
|
|
1206
|
-
type
|
|
1207
|
-
|
|
1208
|
-
client?: DocumentClient;
|
|
1209
|
-
listeners?: Array<EventListener>;
|
|
1210
|
-
logger?: EventListener;
|
|
1211
|
-
};
|
|
1620
|
+
type Resolve<T> = T extends Function | string | number | boolean
|
|
1621
|
+
? T : {[Key in keyof T]: Resolve<T[Key]>}
|
|
1212
1622
|
|
|
1213
|
-
type
|
|
1623
|
+
export type EntityConfiguration = {
|
|
1214
1624
|
table?: string;
|
|
1215
1625
|
client?: DocumentClient;
|
|
1216
|
-
listeners?: Array<
|
|
1217
|
-
logger?:
|
|
1626
|
+
listeners?: Array<ElectroEventListener>;
|
|
1627
|
+
logger?: ElectroEventListener;
|
|
1218
1628
|
};
|
|
1219
1629
|
|
|
1220
|
-
|
|
1221
|
-
Item?: {[key: string]: any}
|
|
1222
|
-
} | {
|
|
1223
|
-
Attributes?: {[key: string]: any}
|
|
1224
|
-
} | null;
|
|
1225
|
-
|
|
1226
|
-
type ParseMultiInput = {
|
|
1227
|
-
Items?: {[key: string]: any}[]
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
export class Entity<A extends string, F extends A, C extends string, S extends Schema<A,F,C>> {
|
|
1630
|
+
export class Entity<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> {
|
|
1231
1631
|
readonly schema: S;
|
|
1632
|
+
private config?: EntityConfiguration;
|
|
1232
1633
|
constructor(schema: S, config?: EntityConfiguration);
|
|
1634
|
+
|
|
1233
1635
|
get(key: AllTableIndexCompositeAttributes<A,F,C,S>): SingleRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S> | null>;
|
|
1234
|
-
get(key: AllTableIndexCompositeAttributes<A,F,C,S>[]): BulkRecordOperationOptions<A,F,C,S, [Array<
|
|
1636
|
+
get(key: AllTableIndexCompositeAttributes<A,F,C,S>[]): BulkRecordOperationOptions<A,F,C,S, [Array<Resolve<ResponseItem<A,F,C,S>>>, Array<Resolve<AllTableIndexCompositeAttributes<A,F,C,S>>>], [Array<Resolve<ResponseItem<A,F,C,S>> | null>, Array<Resolve<AllTableIndexCompositeAttributes<A,F,C,S>>>]>;
|
|
1637
|
+
|
|
1235
1638
|
delete(key: AllTableIndexCompositeAttributes<A,F,C,S>): DeleteRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S>>;
|
|
1236
1639
|
delete(key: AllTableIndexCompositeAttributes<A,F,C,S>[]): BulkRecordOperationOptions<A,F,C,S, AllTableIndexCompositeAttributes<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S>[]>;
|
|
1237
|
-
|
|
1640
|
+
|
|
1641
|
+
put(record: PutItem<A,F,C,S>): PutRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S>>;
|
|
1642
|
+
put(record: PutItem<A,F,C,S>[]): BulkRecordOperationOptions<A,F,C,S, AllTableIndexCompositeAttributes<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S>[]>;
|
|
1643
|
+
|
|
1644
|
+
remove(key: AllTableIndexCompositeAttributes<A,F,C,S>): DeleteRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S>>
|
|
1238
1645
|
update(key: AllTableIndexCompositeAttributes<A,F,C,S>): {
|
|
1239
1646
|
set: SetRecord<A,F,C,S, SetItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
|
|
1240
1647
|
remove: RemoveRecord<A,F,C,S, RemoveItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
|
|
@@ -1244,6 +1651,7 @@ export class Entity<A extends string, F extends A, C extends string, S extends S
|
|
|
1244
1651
|
delete: SetRecord<A,F,C,S, DeleteItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
|
|
1245
1652
|
data: DataUpdateMethodRecord<A,F,C,S, Item<A,F,C,S,S["attributes"]>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
|
|
1246
1653
|
};
|
|
1654
|
+
|
|
1247
1655
|
patch(key: AllTableIndexCompositeAttributes<A,F,C,S>): {
|
|
1248
1656
|
set: SetRecord<A,F,C,S, SetItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
|
|
1249
1657
|
remove: RemoveRecord<A,F,C,S, RemoveItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
|
|
@@ -1253,309 +1661,31 @@ export class Entity<A extends string, F extends A, C extends string, S extends S
|
|
|
1253
1661
|
delete: SetRecord<A,F,C,S, DeleteItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
|
|
1254
1662
|
data: DataUpdateMethodRecord<A,F,C,S, Item<A,F,C,S,S["attributes"]>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
|
|
1255
1663
|
};
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1664
|
+
|
|
1665
|
+
create(record: PutItem<A,F,C,S>): PutRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S>>
|
|
1666
|
+
|
|
1259
1667
|
find(record: Partial<Item<A,F,C,S,S["attributes"]>>): RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S>>;
|
|
1668
|
+
|
|
1260
1669
|
match(record: Partial<Item<A,F,C,S,S["attributes"]>>): RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S>>;
|
|
1261
|
-
|
|
1670
|
+
|
|
1671
|
+
scan: RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], TableIndexCompositeAttributes<A,F,C,S>>;
|
|
1262
1672
|
query: Queries<A,F,C,S>;
|
|
1673
|
+
|
|
1263
1674
|
parse(item: ParseSingleInput, options?: ParseOptions): ResponseItem<A,F,C,S> | null;
|
|
1264
1675
|
parse(item: ParseMultiInput, options?: ParseOptions): ResponseItem<A,F,C,S>[];
|
|
1265
1676
|
setIdentifier(type: "entity" | "version", value: string): void;
|
|
1266
1677
|
client: any;
|
|
1267
1678
|
}
|
|
1268
1679
|
|
|
1269
|
-
type
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
}[keyof EntityCollections<A,F,C,S>]
|
|
1275
|
-
: never
|
|
1276
|
-
}[keyof E];
|
|
1277
|
-
|
|
1278
|
-
type AllEntityAttributeNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
1279
|
-
[Name in keyof E]: {
|
|
1280
|
-
[A in keyof E[Name]["schema"]["attributes"]]: A
|
|
1281
|
-
}[keyof E[Name]["schema"]["attributes"]]
|
|
1282
|
-
}[keyof E];
|
|
1283
|
-
|
|
1284
|
-
type AllEntityAttributes<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
1285
|
-
[Attr in AllEntityAttributeNames<E>]: {
|
|
1286
|
-
[Name in keyof E]: Attr extends keyof E[Name]["schema"]["attributes"]
|
|
1287
|
-
? ItemAttribute<E[Name]["schema"]["attributes"][Attr]>
|
|
1288
|
-
: never
|
|
1289
|
-
}[keyof E];
|
|
1680
|
+
export type ServiceConfiguration = {
|
|
1681
|
+
table?: string;
|
|
1682
|
+
client?: DocumentClient;
|
|
1683
|
+
listeners?: Array<ElectroEventListener>;
|
|
1684
|
+
logger?: ElectroEventListener;
|
|
1290
1685
|
};
|
|
1291
1686
|
|
|
1292
|
-
type CollectionAssociations<E extends {[name: string]: Entity<any, any, any, any>}> = {
|
|
1293
|
-
[Collection in AllCollectionNames<E>]: {
|
|
1294
|
-
[Name in keyof E]: E[Name] extends Entity<infer A, infer F, infer C, infer S>
|
|
1295
|
-
? Collection extends keyof EntityCollections<A,F,C,S>
|
|
1296
|
-
? Name
|
|
1297
|
-
: never
|
|
1298
|
-
: never
|
|
1299
|
-
}[keyof E];
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
type CollectionAttributes<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
|
|
1303
|
-
[Collection in keyof Collections]: {
|
|
1304
|
-
[EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
|
|
1305
|
-
? EntityName extends Collections[Collection]
|
|
1306
|
-
? keyof S["attributes"]
|
|
1307
|
-
: never
|
|
1308
|
-
: never
|
|
1309
|
-
}[keyof E]
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
type CollectionWhereOperations = {
|
|
1313
|
-
eq: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
1314
|
-
ne: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
1315
|
-
gt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
1316
|
-
lt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
1317
|
-
gte: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
1318
|
-
lte: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
1319
|
-
between: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T, value2: T) => string;
|
|
1320
|
-
begins: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
1321
|
-
exists: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
|
|
1322
|
-
notExists: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
|
|
1323
|
-
contains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
1324
|
-
notContains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
1325
|
-
value: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
|
|
1326
|
-
name: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
type CollectionWhereCallback<E extends {[name: string]: Entity<any, any, any, any>}, I extends Partial<AllEntityAttributes<E>>> =
|
|
1330
|
-
<W extends {[A in keyof I]: WhereAttributeSymbol<I[A]>}>(attributes: W, operations: CollectionWhereOperations) => string;
|
|
1331
|
-
|
|
1332
|
-
type CollectionWhereClause<E extends {[name: string]: Entity<any, any, any, any>}, A extends string, F extends A, C extends string, S extends Schema<A,F,C>, I extends Partial<AllEntityAttributes<E>>, T> = (where: CollectionWhereCallback<E, I>) => T;
|
|
1333
|
-
|
|
1334
|
-
type WhereRecordsActionOptions<E extends {[name: string]: Entity<any, any, any, any>}, A extends string, F extends A, C extends string, S extends Schema<A,F,C>, I extends Partial<AllEntityAttributes<E>>, Items, IndexCompositeAttributes> = {
|
|
1335
|
-
go: GoRecord<Items>;
|
|
1336
|
-
params: ParamRecord;
|
|
1337
|
-
page: PageRecord<Items,IndexCompositeAttributes>;
|
|
1338
|
-
where: CollectionWhereClause<E,A,F,C,S,I, WhereRecordsActionOptions<E,A,F,C,S,I,Items,IndexCompositeAttributes>>;
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
type CollectionIndexKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
1342
|
-
[Collection in keyof Collections]: {
|
|
1343
|
-
[EntityResultName in Collections[Collection]]:
|
|
1344
|
-
EntityResultName extends keyof Entities
|
|
1345
|
-
? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
1346
|
-
? keyof TableIndexCompositeAttributes<A, F, C, S>
|
|
1347
|
-
: never
|
|
1348
|
-
: never
|
|
1349
|
-
}[Collections[Collection]]
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
type CollectionPageKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
1353
|
-
[Collection in keyof Collections]: {
|
|
1354
|
-
[EntityResultName in Collections[Collection]]:
|
|
1355
|
-
EntityResultName extends keyof Entities
|
|
1356
|
-
? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
1357
|
-
? keyof Parameters<Entities[EntityResultName]["query"][
|
|
1358
|
-
Collection extends keyof EntityCollections<A,F,C,S>
|
|
1359
|
-
? EntityCollections<A,F,C,S>[Collection]
|
|
1360
|
-
: never
|
|
1361
|
-
]>[0]
|
|
1362
|
-
: never
|
|
1363
|
-
: never
|
|
1364
|
-
}[Collections[Collection]]
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
type CollectionIndexAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
1368
|
-
[Collection in keyof CollectionIndexKeys<Entities, Collections>]: {
|
|
1369
|
-
[key in CollectionIndexKeys<Entities, Collections>[Collection]]:
|
|
1370
|
-
key extends keyof AllEntityAttributes<Entities>
|
|
1371
|
-
? AllEntityAttributes<Entities>[key]
|
|
1372
|
-
: never
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
type CollectionPageAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
|
|
1377
|
-
[Collection in keyof CollectionPageKeys<Entities, Collections>]: {
|
|
1378
|
-
[key in CollectionPageKeys<Entities, Collections>[Collection]]:
|
|
1379
|
-
key extends keyof AllEntityAttributes<Entities>
|
|
1380
|
-
? AllEntityAttributes<Entities>[key]
|
|
1381
|
-
: never
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
type OptionalPropertyNames<T> =
|
|
1386
|
-
{ [K in keyof T]: undefined extends T[K] ? K : never }[keyof T];
|
|
1387
|
-
|
|
1388
|
-
// Common properties from L and R with undefined in R[K] replaced by type in L[K]
|
|
1389
|
-
type SpreadProperties<L, R, K extends keyof L & keyof R> =
|
|
1390
|
-
{ [P in K]: L[P] | Exclude<R[P], undefined> };
|
|
1391
|
-
|
|
1392
|
-
type Id<T> = {[K in keyof T]: T[K]} // see note at bottom*
|
|
1393
|
-
|
|
1394
|
-
// Type of { ...L, ...R }
|
|
1395
|
-
type Spread<L, R> = Id<
|
|
1396
|
-
// Properties in L that don't exist in R
|
|
1397
|
-
& Pick<L, Exclude<keyof L, keyof R>>
|
|
1398
|
-
// Properties in R with types that exclude undefined
|
|
1399
|
-
& Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>>
|
|
1400
|
-
// Properties in R, with types that include undefined, that don't exist in L
|
|
1401
|
-
& Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>>
|
|
1402
|
-
// Properties in R, with types that include undefined, that exist in L
|
|
1403
|
-
& SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>
|
|
1404
|
-
>;
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
type CollectionQueries<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
|
|
1409
|
-
[Collection in keyof Collections]: {
|
|
1410
|
-
[EntityName in keyof E]:
|
|
1411
|
-
EntityName extends Collections[Collection]
|
|
1412
|
-
? (params:
|
|
1413
|
-
RequiredProperties<
|
|
1414
|
-
Parameters<
|
|
1415
|
-
E[EntityName]["query"][
|
|
1416
|
-
E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
|
|
1417
|
-
? Collection extends keyof EntityCollections<A,F,C,S>
|
|
1418
|
-
? EntityCollections<A,F,C,S>[Collection]
|
|
1419
|
-
: never
|
|
1420
|
-
: never
|
|
1421
|
-
]
|
|
1422
|
-
>[0]
|
|
1423
|
-
>) => {
|
|
1424
|
-
go: GoRecord<{
|
|
1425
|
-
[EntityResultName in Collections[Collection]]:
|
|
1426
|
-
EntityResultName extends keyof E
|
|
1427
|
-
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
1428
|
-
? ResponseItem<A,F,C,S>[]
|
|
1429
|
-
: never
|
|
1430
|
-
: never
|
|
1431
|
-
}>;
|
|
1432
|
-
params: ParamRecord;
|
|
1433
|
-
page: {
|
|
1434
|
-
[EntityResultName in Collections[Collection]]: EntityResultName extends keyof E
|
|
1435
|
-
? Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>> extends Partial<AllEntityAttributes<E>>
|
|
1436
|
-
?
|
|
1437
|
-
PageRecord<
|
|
1438
|
-
{
|
|
1439
|
-
[EntityResultName in Collections[Collection]]:
|
|
1440
|
-
EntityResultName extends keyof E
|
|
1441
|
-
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
1442
|
-
? ResponseItem<A,F,C,S>[]
|
|
1443
|
-
: never
|
|
1444
|
-
: never
|
|
1445
|
-
},
|
|
1446
|
-
Partial<
|
|
1447
|
-
Spread<
|
|
1448
|
-
Collection extends keyof CollectionPageAttributes<E, Collections>
|
|
1449
|
-
? CollectionPageAttributes<E, Collections>[Collection]
|
|
1450
|
-
: {},
|
|
1451
|
-
Collection extends keyof CollectionIndexAttributes<E, Collections>
|
|
1452
|
-
? CollectionIndexAttributes<E, Collections>[Collection]
|
|
1453
|
-
: {}
|
|
1454
|
-
>
|
|
1455
|
-
>
|
|
1456
|
-
>
|
|
1457
|
-
: never
|
|
1458
|
-
: never
|
|
1459
|
-
}[Collections[Collection]];
|
|
1460
|
-
where: {
|
|
1461
|
-
[EntityResultName in Collections[Collection]]: EntityResultName extends keyof E
|
|
1462
|
-
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
1463
|
-
? Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>> extends Partial<AllEntityAttributes<E>>
|
|
1464
|
-
? CollectionWhereClause<E,A,F,C,S,
|
|
1465
|
-
Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>>,
|
|
1466
|
-
WhereRecordsActionOptions<E,A,F,C,S,
|
|
1467
|
-
Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>>,
|
|
1468
|
-
{
|
|
1469
|
-
[EntityResultName in Collections[Collection]]:
|
|
1470
|
-
EntityResultName extends keyof E
|
|
1471
|
-
? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
|
|
1472
|
-
? ResponseItem<A,F,C,S>[]
|
|
1473
|
-
: never
|
|
1474
|
-
: never
|
|
1475
|
-
},
|
|
1476
|
-
Partial<
|
|
1477
|
-
Spread<
|
|
1478
|
-
Collection extends keyof CollectionPageAttributes<E, Collections>
|
|
1479
|
-
? CollectionPageAttributes<E, Collections>[Collection]
|
|
1480
|
-
: {},
|
|
1481
|
-
Collection extends keyof CollectionIndexAttributes<E, Collections>
|
|
1482
|
-
? CollectionIndexAttributes<E, Collections>[Collection]
|
|
1483
|
-
: {}
|
|
1484
|
-
>
|
|
1485
|
-
>
|
|
1486
|
-
>>
|
|
1487
|
-
: never
|
|
1488
|
-
: never
|
|
1489
|
-
: never
|
|
1490
|
-
}[Collections[Collection]];
|
|
1491
|
-
}
|
|
1492
|
-
: never
|
|
1493
|
-
}[keyof E];
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
|
-
type RequiredProperties<T> = Pick<T, {[K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T]>
|
|
1497
|
-
|
|
1498
1687
|
export class Service<E extends {[name: string]: Entity<any, any, any, any>}> {
|
|
1499
1688
|
entities: E;
|
|
1500
1689
|
collections: CollectionQueries<E, CollectionAssociations<E>>
|
|
1501
1690
|
constructor(entities: E, config?: ServiceConfiguration);
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
export type EntityItem<E extends Entity<any, any, any, any>> =
|
|
1505
|
-
E extends Entity<infer A, infer F, infer C, infer S>
|
|
1506
|
-
? ResponseItem<A, F, C, S>
|
|
1507
|
-
: never;
|
|
1508
|
-
|
|
1509
|
-
export type CreateEntityItem<E extends Entity<any, any, any, any>> =
|
|
1510
|
-
E extends Entity<infer A, infer F, infer C, infer S>
|
|
1511
|
-
? PutItem<A, F, C, S>
|
|
1512
|
-
: never;
|
|
1513
|
-
|
|
1514
|
-
export type UpdateEntityItem<E extends Entity<any, any, any, any>> =
|
|
1515
|
-
E extends Entity<infer A, infer F, infer C, infer S>
|
|
1516
|
-
? Partial<ResponseItem<A,F,C,S>>
|
|
1517
|
-
: never;
|
|
1518
|
-
|
|
1519
|
-
export type UpdateAddEntityItem<E extends Entity<any, any, any, any>> =
|
|
1520
|
-
E extends Entity<infer A, infer F, infer C, infer S>
|
|
1521
|
-
? AddItem<A, F, C, S>
|
|
1522
|
-
: never;
|
|
1523
|
-
|
|
1524
|
-
export type UpdateSubtractEntityItem<E extends Entity<any, any, any, any>> =
|
|
1525
|
-
E extends Entity<infer A, infer F, infer C, infer S>
|
|
1526
|
-
? SubtractItem<A, F, C, S>
|
|
1527
|
-
: never;
|
|
1528
|
-
|
|
1529
|
-
export type UpdateAppendEntityItem<E extends Entity<any, any, any, any>> =
|
|
1530
|
-
E extends Entity<infer A, infer F, infer C, infer S>
|
|
1531
|
-
? AppendItem<A, F, C, S>
|
|
1532
|
-
: never;
|
|
1533
|
-
|
|
1534
|
-
export type UpdateRemoveEntityItem<E extends Entity<any, any, any, any>> =
|
|
1535
|
-
E extends Entity<infer A, infer F, infer C, infer S>
|
|
1536
|
-
? RemoveItem<A, F, C, S>
|
|
1537
|
-
: never;
|
|
1538
|
-
|
|
1539
|
-
export type UpdateDeleteEntityItem<E extends Entity<any, any, any, any>> =
|
|
1540
|
-
E extends Entity<infer A, infer F, infer C, infer S>
|
|
1541
|
-
? DeleteItem<A, F, C, S>
|
|
1542
|
-
: never;
|
|
1543
|
-
|
|
1544
|
-
export type EntityRecord<E extends Entity<any, any, any, any>> =
|
|
1545
|
-
E extends Entity<infer A, infer F, infer C, infer S>
|
|
1546
|
-
? Item<A,F,C,S,S["attributes"]>
|
|
1547
|
-
: never;
|
|
1548
|
-
|
|
1549
|
-
export type CollectionItem<SERVICE extends Service<any>, COLLECTION extends keyof SERVICE["collections"]> =
|
|
1550
|
-
SERVICE extends Service<infer E> ? Pick<{
|
|
1551
|
-
[EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
|
|
1552
|
-
? COLLECTION extends keyof CollectionAssociations<E>
|
|
1553
|
-
? EntityName extends CollectionAssociations<E>[COLLECTION]
|
|
1554
|
-
? ResponseItem<A,F,C,S>[]
|
|
1555
|
-
: never
|
|
1556
|
-
: never
|
|
1557
|
-
: never
|
|
1558
|
-
}, COLLECTION extends keyof CollectionAssociations<E>
|
|
1559
|
-
? CollectionAssociations<E>[COLLECTION]
|
|
1560
|
-
: never>
|
|
1561
|
-
: never
|
|
1691
|
+
}
|