@aws-amplify/data-schema 1.23.0 → 1.25.0
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/dist/cjs/ModelIndex.js +9 -0
- package/dist/cjs/ModelIndex.js.map +1 -1
- package/dist/cjs/SchemaProcessor.js +14 -4
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/esm/ClientSchema/Core/ClientModel.d.ts +4 -1
- package/dist/esm/ClientSchema/utilities/ResolveField.d.ts +33 -3
- package/dist/esm/ModelIndex.d.ts +15 -0
- package/dist/esm/ModelIndex.mjs +9 -0
- package/dist/esm/ModelIndex.mjs.map +1 -1
- package/dist/esm/SchemaProcessor.mjs +14 -4
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/runtime/client/index.d.ts +8 -54
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/ClientSchema/Core/ClientModel.ts +21 -1
- package/src/ClientSchema/utilities/ResolveField.ts +85 -11
- package/src/ModelIndex.ts +32 -0
- package/src/SchemaProcessor.ts +16 -2
- package/src/runtime/client/index.ts +33 -102
|
@@ -139,59 +139,13 @@ type FlattenArrays<T> = {
|
|
|
139
139
|
* and especially for bi-directional relationships which are infinitely recursable by their nature
|
|
140
140
|
*
|
|
141
141
|
*/
|
|
142
|
-
|
|
142
|
+
type ModelPathInner<FlatModel extends Record<string, unknown>, Depth extends number = 5, // think of this as the initialization expr. in a for loop (e.g. `let depth = 5`)
|
|
143
143
|
RecursionLoop extends number[] = [-1, 0, 1, 2, 3, 4], Field = keyof FlatModel> = {
|
|
144
144
|
done: Field extends string ? `${Field}.*` : never;
|
|
145
|
-
recur: Field extends string ? NonNullable<UnwrapArray<FlatModel[Field]>> extends Record<string, unknown> ? `${Field}.${
|
|
145
|
+
recur: Field extends string ? NonNullable<UnwrapArray<FlatModel[Field]>> extends Record<string, unknown> ? `${Field}.${ModelPathInner<NonNullable<UnwrapArray<FlatModel[Field]>>, RecursionLoop[Depth]>}` | `${Field}.*` : `${Field}` : never;
|
|
146
146
|
}[Depth extends -1 ? 'done' : 'recur'];
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
*
|
|
150
|
-
* This type is used for generating the base shape for custom selection set input and its return value
|
|
151
|
-
* Uses same pattern as above to limit recursion depth to maximum usable for selection set.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ### Given
|
|
155
|
-
* ```ts
|
|
156
|
-
* Model = {
|
|
157
|
-
title: string;
|
|
158
|
-
comments: () => ListReturnValue<({
|
|
159
|
-
content: string;
|
|
160
|
-
readonly id: string;
|
|
161
|
-
readonly createdAt: string;
|
|
162
|
-
readonly updatedAt: string;
|
|
163
|
-
} | null | undefined)[]>;
|
|
164
|
-
readonly id: string;
|
|
165
|
-
readonly createdAt: string;
|
|
166
|
-
readonly updatedAt: string;
|
|
167
|
-
description?: string | ... 1 more ... | undefined;
|
|
168
|
-
}
|
|
169
|
-
* ```
|
|
170
|
-
* ### Returns
|
|
171
|
-
* ```ts
|
|
172
|
-
* {
|
|
173
|
-
title: string;
|
|
174
|
-
comments: {
|
|
175
|
-
content: string;
|
|
176
|
-
readonly id: string;
|
|
177
|
-
readonly createdAt: string;
|
|
178
|
-
readonly updatedAt: string;
|
|
179
|
-
}[];
|
|
180
|
-
readonly id: string;
|
|
181
|
-
readonly createdAt: string;
|
|
182
|
-
readonly updatedAt: string;
|
|
183
|
-
description: string | null | undefined;
|
|
184
|
-
}
|
|
185
|
-
*
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
type ResolvedModel<Model extends Record<string, unknown>, Depth extends number = 7, RecursionLoop extends number[] = [-1, 0, 1, 2, 3, 4, 5, 6]> = {
|
|
189
|
-
done: NonRelationshipFields<Model>;
|
|
190
|
-
recur: {
|
|
191
|
-
[Field in keyof Model]: Model[Field] extends (...args: any) => ListReturnValue<infer M> ? NonNullable<M> extends Record<string, any> ? ResolvedModel<NonNullable<M>, RecursionLoop[Depth]>[] : never : Model[Field] extends (...args: any) => SingularReturnValue<infer M> ? NonNullable<M> extends Record<string, any> ? ResolvedModel<NonNullable<M>, RecursionLoop[Depth]> : never : Model[Field];
|
|
192
|
-
};
|
|
193
|
-
}[Depth extends -1 ? 'done' : 'recur'];
|
|
194
|
-
export type SelectionSet<Model extends Record<string, unknown>, Path extends ReadonlyArray<ModelPath<FlatModel>>, FlatModel extends Record<string, unknown> = ResolvedModel<Model>> = WithOptionalsAsNullishOnly<CustomSelectionSetReturnValue<FlatModel, Path[number]>>;
|
|
147
|
+
export type ModelPath<FlatModel extends Record<string, unknown>> = ModelPathInner<FlatModel>;
|
|
148
|
+
export type SelectionSet<Model, Path extends ReadonlyArray<ModelPath<FlatModel>>, FlatModel extends Record<string, unknown> = Model extends ClientSchemaByEntityTypeBaseShape['models'][string] ? Model['__meta']['flatModel'] : Record<string, any>> = Model extends ClientSchemaByEntityTypeBaseShape['models'][string] ? WithOptionalsAsNullishOnly<CustomSelectionSetReturnValue<FlatModel, Path[number]>> : any;
|
|
195
149
|
/**
|
|
196
150
|
* See: https://spec.graphql.org/draft/#sec-Errors
|
|
197
151
|
*/
|
|
@@ -299,7 +253,7 @@ interface ClientSecondaryIndexField {
|
|
|
299
253
|
type IndexQueryMethods<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], Context extends ContextType = 'CLIENT'> = {
|
|
300
254
|
[K in keyof Select<Model['secondaryIndexes'], ClientSecondaryIndexField>]: IndexQueryMethod<Model, Select<Model['secondaryIndexes'], ClientSecondaryIndexField>[K], Context>;
|
|
301
255
|
};
|
|
302
|
-
type IndexQueryMethod<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], Method extends ClientSecondaryIndexField, Context extends ContextType = 'CLIENT', FlatModel extends Record<string, unknown> =
|
|
256
|
+
type IndexQueryMethod<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], Method extends ClientSecondaryIndexField, Context extends ContextType = 'CLIENT', FlatModel extends Record<string, unknown> = Model['__meta']['flatModel']> = Context extends 'CLIENT' | 'COOKIES' ? <SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(input: Method['input'], options?: {
|
|
303
257
|
filter?: ModelFilter<Model>;
|
|
304
258
|
sortDirection?: ModelSortDirection;
|
|
305
259
|
limit?: number;
|
|
@@ -318,7 +272,7 @@ type IndexQueryMethod<Model extends ClientSchemaByEntityTypeBaseShape['models'][
|
|
|
318
272
|
authToken?: string;
|
|
319
273
|
headers?: CustomHeaders;
|
|
320
274
|
}) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
321
|
-
type ModelTypesClient<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], FlatModel extends Record<string, unknown> =
|
|
275
|
+
type ModelTypesClient<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], FlatModel extends Record<string, unknown> = Model['__meta']['flatModel']> = IndexQueryMethods<Model> & Omit<{
|
|
322
276
|
create<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(model: Model['createType'], options?: {
|
|
323
277
|
selectionSet?: SelectionSet;
|
|
324
278
|
authMode?: AuthMode;
|
|
@@ -380,7 +334,7 @@ type ModelTypesClient<Model extends ClientSchemaByEntityTypeBaseShape['models'][
|
|
|
380
334
|
authToken?: string;
|
|
381
335
|
}): ObserveQueryReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
382
336
|
}, keyof Model['__meta']['disabledOperations']>;
|
|
383
|
-
type ModelTypesSSRCookies<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], FlatModel extends Record<string, unknown> =
|
|
337
|
+
type ModelTypesSSRCookies<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], FlatModel extends Record<string, unknown> = Model['__meta']['flatModel']> = IndexQueryMethods<Model> & Omit<{
|
|
384
338
|
create<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(model: Model['createType'], options?: {
|
|
385
339
|
selectionSet?: SelectionSet;
|
|
386
340
|
authMode?: AuthMode;
|
|
@@ -416,7 +370,7 @@ type ModelTypesSSRCookies<Model extends ClientSchemaByEntityTypeBaseShape['model
|
|
|
416
370
|
headers?: CustomHeaders;
|
|
417
371
|
}): ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
418
372
|
}, keyof Model['__meta']['disabledOperations']>;
|
|
419
|
-
type ModelTypesSSRRequest<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], FlatModel extends Record<string, unknown> =
|
|
373
|
+
type ModelTypesSSRRequest<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], FlatModel extends Record<string, unknown> = Model['__meta']['flatModel']> = IndexQueryMethods<Model, 'REQUEST'> & Omit<{
|
|
420
374
|
create<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(contextSpec: AmplifyServer.ContextSpec, model: Model['createType'], options?: {
|
|
421
375
|
selectionSet?: SelectionSet;
|
|
422
376
|
authMode?: AuthMode;
|