@aws-amplify/data-schema 1.3.6 → 1.3.8
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/SchemaProcessor.js +2 -2
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/custom.js +15 -2
- package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
- package/dist/cjs/runtime/internals/server/generateModelsProperty.js +1 -1
- package/dist/cjs/runtime/internals/server/generateModelsProperty.js.map +1 -1
- package/dist/esm/ClientSchema/Core/ClientCustomOperations.d.ts +2 -1
- package/dist/esm/SchemaProcessor.mjs +2 -2
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/runtime/client/index.d.ts +20 -10
- package/dist/esm/runtime/internals/operations/custom.mjs +15 -2
- package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
- package/dist/esm/runtime/internals/server/generateModelsProperty.mjs +1 -1
- package/dist/esm/runtime/internals/server/generateModelsProperty.mjs.map +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/ClientSchema/Core/ClientCustomOperations.ts +4 -1
- package/src/SchemaProcessor.ts +2 -2
- package/src/runtime/client/index.ts +40 -22
- package/src/runtime/internals/operations/custom.ts +17 -2
- package/src/runtime/internals/server/generateModelsProperty.ts +1 -0
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import type { AppSyncResolverHandler } from 'aws-lambda';
|
|
|
6
6
|
import type { CustomType } from '../../CustomType';
|
|
7
7
|
import type { FieldTypesOfCustomType } from '../../MappedTypes/ResolveSchema';
|
|
8
8
|
import type { ResolveRef } from '../utilities/ResolveRef';
|
|
9
|
+
import type { EnumType } from '../../EnumType';
|
|
9
10
|
import { ClientSchemaProperty } from './ClientSchemaProperty';
|
|
10
11
|
|
|
11
12
|
type CustomOperationSubType<Op extends CustomOperationParamShape> =
|
|
@@ -83,7 +84,9 @@ type CustomOpArguments<Shape extends CustomOperationParamShape> =
|
|
|
83
84
|
infer R
|
|
84
85
|
>
|
|
85
86
|
? R
|
|
86
|
-
:
|
|
87
|
+
: Shape['arguments'][FieldName] extends EnumType<infer Values>
|
|
88
|
+
? Values[number] | null
|
|
89
|
+
: never;
|
|
87
90
|
}>;
|
|
88
91
|
|
|
89
92
|
/**
|
package/src/SchemaProcessor.ts
CHANGED
|
@@ -398,14 +398,14 @@ function customOperationToGql(
|
|
|
398
398
|
}
|
|
399
399
|
|
|
400
400
|
if (Object.keys(fieldArgs).length > 0) {
|
|
401
|
-
const { gqlFields, implicitTypes } = processFields(
|
|
401
|
+
const { gqlFields, implicitTypes: implied } = processFields(
|
|
402
402
|
typeName,
|
|
403
403
|
fieldArgs,
|
|
404
404
|
{},
|
|
405
405
|
{},
|
|
406
406
|
);
|
|
407
407
|
callSignature += `(${gqlFields.join(', ')})`;
|
|
408
|
-
implicitTypes.push(...
|
|
408
|
+
implicitTypes.push(...implied);
|
|
409
409
|
}
|
|
410
410
|
|
|
411
411
|
const handler = handlers && handlers[0];
|
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
NumericFilter,
|
|
20
20
|
BooleanFilters,
|
|
21
21
|
} from '../../util';
|
|
22
|
+
import { AmplifyServer } from '../bridge-types';
|
|
22
23
|
|
|
23
24
|
// temporarily export symbols from `data-schema-types` because in case part of the
|
|
24
25
|
// problem with the runtime -> data-schema migration comes down to a mismatch
|
|
@@ -434,33 +435,51 @@ interface ClientSecondaryIndexField {
|
|
|
434
435
|
|
|
435
436
|
type IndexQueryMethods<
|
|
436
437
|
Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
|
|
438
|
+
Context extends ContextType = 'CLIENT',
|
|
437
439
|
> = {
|
|
438
440
|
[K in keyof Select<
|
|
439
441
|
Model['secondaryIndexes'],
|
|
440
442
|
ClientSecondaryIndexField
|
|
441
443
|
>]: IndexQueryMethod<
|
|
442
444
|
Model,
|
|
443
|
-
Select<Model['secondaryIndexes'], ClientSecondaryIndexField>[K]
|
|
445
|
+
Select<Model['secondaryIndexes'], ClientSecondaryIndexField>[K],
|
|
446
|
+
Context
|
|
444
447
|
>;
|
|
445
448
|
};
|
|
446
449
|
|
|
447
450
|
type IndexQueryMethod<
|
|
448
451
|
Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
|
|
449
452
|
Method extends ClientSecondaryIndexField,
|
|
453
|
+
Context extends ContextType = 'CLIENT',
|
|
450
454
|
FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>,
|
|
451
|
-
> =
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
455
|
+
> = Context extends 'CLIENT' | 'COOKIES'
|
|
456
|
+
? <SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
|
|
457
|
+
input: Method['input'],
|
|
458
|
+
options?: {
|
|
459
|
+
filter?: ModelFilter<Model>;
|
|
460
|
+
sortDirection?: ModelSortDirection;
|
|
461
|
+
limit?: number;
|
|
462
|
+
nextToken?: string | null;
|
|
463
|
+
selectionSet?: SelectionSet;
|
|
464
|
+
authMode?: AuthMode;
|
|
465
|
+
authToken?: string;
|
|
466
|
+
headers?: CustomHeaders;
|
|
467
|
+
},
|
|
468
|
+
) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>
|
|
469
|
+
: <SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
|
|
470
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
471
|
+
input: Method['input'],
|
|
472
|
+
options?: {
|
|
473
|
+
filter?: ModelFilter<Model>;
|
|
474
|
+
sortDirection?: ModelSortDirection;
|
|
475
|
+
limit?: number;
|
|
476
|
+
nextToken?: string | null;
|
|
477
|
+
selectionSet?: SelectionSet;
|
|
478
|
+
authMode?: AuthMode;
|
|
479
|
+
authToken?: string;
|
|
480
|
+
headers?: CustomHeaders;
|
|
481
|
+
},
|
|
482
|
+
) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
464
483
|
|
|
465
484
|
type ModelTypesClient<
|
|
466
485
|
Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
|
|
@@ -609,10 +628,9 @@ type ModelTypesSSRCookies<
|
|
|
609
628
|
type ModelTypesSSRRequest<
|
|
610
629
|
Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
|
|
611
630
|
FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>,
|
|
612
|
-
> = IndexQueryMethods<Model> & {
|
|
631
|
+
> = IndexQueryMethods<Model, 'REQUEST'> & {
|
|
613
632
|
create: (
|
|
614
|
-
|
|
615
|
-
contextSpec: any,
|
|
633
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
616
634
|
model: Model['createType'],
|
|
617
635
|
options?: {
|
|
618
636
|
authMode?: AuthMode;
|
|
@@ -621,7 +639,7 @@ type ModelTypesSSRRequest<
|
|
|
621
639
|
},
|
|
622
640
|
) => SingularReturnValue<Model['type']>;
|
|
623
641
|
update: (
|
|
624
|
-
contextSpec:
|
|
642
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
625
643
|
model: Model['updateType'],
|
|
626
644
|
options?: {
|
|
627
645
|
authMode?: AuthMode;
|
|
@@ -630,7 +648,7 @@ type ModelTypesSSRRequest<
|
|
|
630
648
|
},
|
|
631
649
|
) => SingularReturnValue<Model['type']>;
|
|
632
650
|
delete: (
|
|
633
|
-
contextSpec:
|
|
651
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
634
652
|
identifier: Model['deleteType'],
|
|
635
653
|
options?: {
|
|
636
654
|
authMode?: AuthMode;
|
|
@@ -639,7 +657,7 @@ type ModelTypesSSRRequest<
|
|
|
639
657
|
},
|
|
640
658
|
) => SingularReturnValue<Model['type']>;
|
|
641
659
|
get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
|
|
642
|
-
contextSpec:
|
|
660
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
643
661
|
identifier: Model['identifier'],
|
|
644
662
|
options?: {
|
|
645
663
|
selectionSet?: SelectionSet;
|
|
@@ -649,7 +667,7 @@ type ModelTypesSSRRequest<
|
|
|
649
667
|
},
|
|
650
668
|
): SingularReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
651
669
|
list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
|
|
652
|
-
contextSpec:
|
|
670
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
653
671
|
options?: ListCpkOptions<Model> & {
|
|
654
672
|
filter?: ModelFilter<Model>;
|
|
655
673
|
sortDirection?: ModelSortDirection;
|
|
@@ -731,7 +749,7 @@ export type CustomOperations<
|
|
|
731
749
|
...params: CustomOperationFnParams<OperationDefs[OpName]['args']>
|
|
732
750
|
) => SingularReturnValue<OperationDefs[OpName]['type']>;
|
|
733
751
|
REQUEST: (
|
|
734
|
-
contextSpec:
|
|
752
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
735
753
|
...params: CustomOperationFnParams<OperationDefs[OpName]['args']>
|
|
736
754
|
) => SingularReturnValue<OperationDefs[OpName]['type']>;
|
|
737
755
|
}[Context];
|
|
@@ -191,6 +191,21 @@ function hasStringField<Field extends string>(
|
|
|
191
191
|
return typeof o[field] === 'string';
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
/**
|
|
195
|
+
* @param argDef A single argument definition from a custom operation
|
|
196
|
+
* @returns A string naming the base type including the `!` if the arg is required.
|
|
197
|
+
*/
|
|
198
|
+
function argumentBaseTypeString(
|
|
199
|
+
argDef: Exclude<CustomOperation['arguments'], undefined>[number],
|
|
200
|
+
) {
|
|
201
|
+
const requiredFlag = argDef.isRequired ? '!' : '';
|
|
202
|
+
if (argDef.type instanceof Object && 'enum' in argDef.type) {
|
|
203
|
+
return argDef.type.enum + requiredFlag;
|
|
204
|
+
} else {
|
|
205
|
+
return argDef.type + requiredFlag;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
194
209
|
/**
|
|
195
210
|
* Generates "outer" arguments string for a custom operation. For example,
|
|
196
211
|
* in this operation:
|
|
@@ -216,7 +231,7 @@ function outerArguments(operation: CustomOperation): string {
|
|
|
216
231
|
}
|
|
217
232
|
const args = Object.entries(operation.arguments)
|
|
218
233
|
.map(([k, v]) => {
|
|
219
|
-
const baseType =
|
|
234
|
+
const baseType = argumentBaseTypeString(v);
|
|
220
235
|
const finalType = v.isArray
|
|
221
236
|
? `[${baseType}]${v.isArrayNullable ? '' : '!'}`
|
|
222
237
|
: baseType;
|
|
@@ -261,7 +276,7 @@ function innerArguments(operation: CustomOperation): string {
|
|
|
261
276
|
/**
|
|
262
277
|
* Generates the selection set string for a custom operation. This is slightly
|
|
263
278
|
* different than the selection set generation for models. If the custom op returns
|
|
264
|
-
* a primitive or enum types, it
|
|
279
|
+
* a primitive or enum types, it doesn't require a selection set at all.
|
|
265
280
|
*
|
|
266
281
|
* E.g., the graphql might look like this:
|
|
267
282
|
*
|