@aws-amplify/data-schema 1.2.8 → 1.3.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/ClientSchema/Core/ClientCustomOperations.js +4 -0
- package/dist/cjs/ClientSchema/Core/ClientCustomOperations.js.map +1 -0
- package/dist/cjs/{MappedTypes/CustomOperations.js → ClientSchema/Core/ClientCustomType.js} +1 -1
- package/dist/cjs/ClientSchema/Core/ClientCustomType.js.map +1 -0
- package/dist/cjs/{ClientSchema.js → ClientSchema/Core/ClientEnum.js} +1 -1
- package/dist/cjs/ClientSchema/Core/ClientEnum.js.map +1 -0
- package/dist/cjs/ClientSchema/Core/ClientModel.js +4 -0
- package/dist/cjs/ClientSchema/Core/ClientModel.js.map +1 -0
- package/dist/cjs/ClientSchema/Core/ClientSchemaProperty.js +4 -0
- package/dist/cjs/ClientSchema/Core/ClientSchemaProperty.js.map +1 -0
- package/dist/cjs/ClientSchema/Core/index.js +4 -0
- package/dist/cjs/ClientSchema/Core/index.js.map +1 -0
- package/dist/cjs/ClientSchema/index.js +4 -0
- package/dist/cjs/ClientSchema/index.js.map +1 -0
- package/dist/cjs/ClientSchema/utilities/ExtractNestedTypes.js +4 -0
- package/dist/cjs/ClientSchema/utilities/ExtractNestedTypes.js.map +1 -0
- package/dist/cjs/ClientSchema/utilities/ResolveField.js +4 -0
- package/dist/cjs/ClientSchema/utilities/ResolveField.js.map +1 -0
- package/dist/cjs/ClientSchema/utilities/ResolveRef.js +4 -0
- package/dist/cjs/ClientSchema/utilities/ResolveRef.js.map +1 -0
- package/dist/cjs/ClientSchema/utilities/SchemaMetadata.js +4 -0
- package/dist/cjs/ClientSchema/utilities/SchemaMetadata.js.map +1 -0
- package/dist/cjs/ClientSchema/utilities/index.js +9 -0
- package/dist/cjs/ClientSchema/utilities/index.js.map +1 -0
- package/dist/cjs/util/Filters.js +10 -0
- package/dist/cjs/util/Filters.js.map +1 -0
- package/dist/cjs/util/IndexShapes.js +4 -0
- package/dist/cjs/util/IndexShapes.js.map +1 -0
- package/dist/cjs/util/Select.js +4 -0
- package/dist/cjs/util/Select.js.map +1 -0
- package/dist/esm/Authorization.d.ts +3 -3
- package/dist/esm/ClientSchema/Core/ClientCustomOperations.d.ts +88 -0
- package/dist/esm/ClientSchema/Core/ClientCustomOperations.mjs +2 -0
- package/dist/esm/ClientSchema/Core/ClientCustomOperations.mjs.map +1 -0
- package/dist/esm/ClientSchema/Core/ClientCustomType.d.ts +7 -0
- package/dist/esm/ClientSchema/Core/ClientCustomType.mjs +2 -0
- package/dist/esm/ClientSchema/Core/ClientCustomType.mjs.map +1 -0
- package/dist/esm/ClientSchema/Core/ClientEnum.d.ts +5 -0
- package/dist/esm/ClientSchema/Core/ClientEnum.mjs +2 -0
- package/dist/esm/ClientSchema/Core/ClientEnum.mjs.map +1 -0
- package/dist/esm/ClientSchema/Core/ClientModel.d.ts +123 -0
- package/dist/esm/ClientSchema/Core/ClientModel.mjs +2 -0
- package/dist/esm/ClientSchema/Core/ClientModel.mjs.map +1 -0
- package/dist/esm/ClientSchema/Core/ClientSchemaProperty.d.ts +4 -0
- package/dist/esm/ClientSchema/Core/ClientSchemaProperty.mjs +2 -0
- package/dist/esm/ClientSchema/Core/ClientSchemaProperty.mjs.map +1 -0
- package/dist/esm/ClientSchema/Core/index.d.ts +5 -0
- package/dist/esm/ClientSchema/Core/index.mjs +2 -0
- package/dist/esm/ClientSchema/Core/index.mjs.map +1 -0
- package/dist/esm/ClientSchema/index.d.ts +59 -0
- package/dist/esm/ClientSchema/index.mjs +2 -0
- package/dist/esm/ClientSchema/index.mjs.map +1 -0
- package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.d.ts +7 -0
- package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.mjs +2 -0
- package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.mjs.map +1 -0
- package/dist/esm/ClientSchema/utilities/ResolveField.d.ts +29 -0
- package/dist/esm/ClientSchema/utilities/ResolveField.mjs +2 -0
- package/dist/esm/ClientSchema/utilities/ResolveField.mjs.map +1 -0
- package/dist/esm/ClientSchema/utilities/ResolveRef.d.ts +18 -0
- package/dist/esm/ClientSchema/utilities/ResolveRef.mjs +2 -0
- package/dist/esm/ClientSchema/utilities/ResolveRef.mjs.map +1 -0
- package/dist/esm/ClientSchema/utilities/SchemaMetadata.d.ts +7 -0
- package/dist/esm/ClientSchema/utilities/SchemaMetadata.mjs +2 -0
- package/dist/esm/ClientSchema/utilities/SchemaMetadata.mjs.map +1 -0
- package/dist/esm/ClientSchema/utilities/index.d.ts +4 -0
- package/dist/esm/ClientSchema/utilities/index.mjs +2 -0
- package/dist/esm/ClientSchema/utilities/index.mjs.map +1 -0
- package/dist/esm/MappedTypes/ImplicitFieldInjector.d.ts +1 -1
- package/dist/esm/MappedTypes/ModelMetadata.d.ts +1 -1
- package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +1 -1
- package/dist/esm/ModelSchema.d.ts +11 -5
- package/dist/esm/ModelType.d.ts +9 -8
- package/dist/esm/ModelType.mjs.map +1 -1
- package/dist/esm/runtime/client/index.d.ts +77 -223
- package/dist/esm/runtime/internals/generateCustomOperationsProperty.d.ts +12 -5
- package/dist/esm/util/Filters.d.ts +94 -0
- package/dist/esm/util/Filters.mjs +2 -0
- package/dist/esm/util/Filters.mjs.map +1 -0
- package/dist/esm/util/IndexShapes.d.ts +13 -0
- package/dist/esm/util/IndexShapes.mjs +2 -0
- package/dist/esm/util/IndexShapes.mjs.map +1 -0
- package/dist/esm/util/Select.d.ts +3 -0
- package/dist/esm/util/Select.mjs +2 -0
- package/dist/esm/util/Select.mjs.map +1 -0
- package/dist/esm/util/index.d.ts +3 -0
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/Authorization.ts +2 -2
- package/src/ClientSchema/Core/ClientCustomOperations.ts +152 -0
- package/src/ClientSchema/Core/ClientCustomType.ts +11 -0
- package/src/ClientSchema/Core/ClientEnum.ts +7 -0
- package/src/ClientSchema/Core/ClientModel.ts +299 -0
- package/src/ClientSchema/Core/ClientSchemaProperty.ts +10 -0
- package/src/ClientSchema/Core/index.ts +5 -0
- package/src/ClientSchema/index.ts +158 -0
- package/src/ClientSchema/utilities/ExtractNestedTypes.ts +15 -0
- package/src/ClientSchema/utilities/ResolveField.ts +79 -0
- package/src/ClientSchema/utilities/ResolveRef.ts +38 -0
- package/src/ClientSchema/utilities/SchemaMetadata.ts +11 -0
- package/src/ClientSchema/utilities/index.ts +4 -0
- package/src/MappedTypes/ImplicitFieldInjector.ts +1 -1
- package/src/MappedTypes/ModelMetadata.ts +2 -1
- package/src/MappedTypes/ResolveFieldProperties.ts +1 -1
- package/src/ModelSchema.ts +19 -4
- package/src/ModelType.ts +12 -3
- package/src/runtime/client/index.ts +175 -433
- package/src/runtime/internals/generateCustomOperationsProperty.ts +2 -2
- package/src/runtime/internals/utils/clientProperties/generateEnumsProperty.ts +1 -1
- package/src/util/Filters.ts +102 -0
- package/src/util/IndexShapes.ts +10 -0
- package/src/util/Select.ts +3 -0
- package/src/util/index.ts +3 -0
- package/dist/cjs/ClientSchema.js.map +0 -1
- package/dist/cjs/MappedTypes/CustomOperations.js.map +0 -1
- package/dist/esm/ClientSchema.d.ts +0 -51
- package/dist/esm/ClientSchema.mjs +0 -2
- package/dist/esm/ClientSchema.mjs.map +0 -1
- package/dist/esm/MappedTypes/CustomOperations.d.ts +0 -125
- package/dist/esm/MappedTypes/CustomOperations.mjs +0 -2
- package/dist/esm/MappedTypes/CustomOperations.mjs.map +0 -1
- package/src/ClientSchema.ts +0 -121
- package/src/MappedTypes/CustomOperations.ts +0 -254
|
@@ -37,7 +37,7 @@ export function generateCustomOperationsProperty<
|
|
|
37
37
|
config: GraphQLProviderConfig['GraphQL'],
|
|
38
38
|
operationsType: OpType,
|
|
39
39
|
getInternals: ClientInternalsGetter,
|
|
40
|
-
):
|
|
40
|
+
): CustomOpsProperty<T, OpType> {
|
|
41
41
|
// some bundlers end up with `Amplify.configure` being called *after* generate client.
|
|
42
42
|
// if that occurs, we need to *not error* while we wait. handling for late configuration
|
|
43
43
|
// occurs in `generateClient()`. we do not need to subscribe to Hub events here.
|
|
@@ -73,7 +73,7 @@ export function generateCustomOperationsProperty<
|
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
return ops
|
|
76
|
+
return ops as CustomOpsProperty<T, OpType>;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export function generateCustomMutationsProperty<T extends Record<any, any>>(
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Not actually sure if/how customer can pass this through as variables yet.
|
|
3
|
+
* Leaving it out for now:
|
|
4
|
+
*
|
|
5
|
+
* attributeType: "binary" | "binarySet" | "bool" | "list" | "map" | "number" | "numberSet" | "string" | "stringSet" | "_null"
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Filters options that can be used on string-like fields.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export type StringFilter<T extends string = string> = {
|
|
13
|
+
attributeExists?: boolean;
|
|
14
|
+
beginsWith?: string;
|
|
15
|
+
between?: [string, string];
|
|
16
|
+
contains?: string;
|
|
17
|
+
eq?: T;
|
|
18
|
+
ge?: string;
|
|
19
|
+
gt?: string;
|
|
20
|
+
le?: string;
|
|
21
|
+
lt?: string;
|
|
22
|
+
ne?: T;
|
|
23
|
+
notContains?: string;
|
|
24
|
+
size?: SizeFilter;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type NumericFilter = {
|
|
28
|
+
attributeExists?: boolean;
|
|
29
|
+
between?: [number, number];
|
|
30
|
+
eq?: number;
|
|
31
|
+
ge?: number;
|
|
32
|
+
gt?: number;
|
|
33
|
+
le?: number;
|
|
34
|
+
lt?: number;
|
|
35
|
+
ne?: number;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Filter options that can be used on fields where size checks are supported.
|
|
40
|
+
*/
|
|
41
|
+
export type SizeFilter = {
|
|
42
|
+
between?: [number, number];
|
|
43
|
+
eq?: number;
|
|
44
|
+
ge?: number;
|
|
45
|
+
gt?: number;
|
|
46
|
+
le?: number;
|
|
47
|
+
lt?: number;
|
|
48
|
+
ne?: number;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type BooleanFilters = {
|
|
52
|
+
attributeExists?: boolean;
|
|
53
|
+
eq?: boolean;
|
|
54
|
+
ne?: boolean;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A composite SK (in an identifier or secondaryIndex) resolves to this type for
|
|
59
|
+
* list queries and index queries
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* Given
|
|
63
|
+
* ```ts
|
|
64
|
+
* MyModel: a
|
|
65
|
+
.model({
|
|
66
|
+
pk: a.string().required(),
|
|
67
|
+
sk1: a.string().required(),
|
|
68
|
+
sk2: a.integer().required(),
|
|
69
|
+
})
|
|
70
|
+
.identifier(['pk', 'sk1', 'sk2']),
|
|
71
|
+
* ```
|
|
72
|
+
* Expected list options:
|
|
73
|
+
* ```ts
|
|
74
|
+
* {
|
|
75
|
+
* pk?: string
|
|
76
|
+
* sk1Sk2?: ModelPrimaryCompositeKeyConditionInput
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
* Where ModelPrimaryCompositeKeyConditionInput resolves to:
|
|
80
|
+
* ```ts
|
|
81
|
+
* {
|
|
82
|
+
* eq: {sk1: string; sk2: number};
|
|
83
|
+
* le: {sk1: string; sk2: number};
|
|
84
|
+
* lt: {sk1: string; sk2: number};
|
|
85
|
+
* ge: {sk1: string; sk2: number};
|
|
86
|
+
* gt: {sk1: string; sk2: number};
|
|
87
|
+
* between: [ {sk1: string; sk2: number} ];
|
|
88
|
+
* beginsWith: {sk1: string; sk2: number};
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
* */
|
|
92
|
+
export type ModelPrimaryCompositeKeyInput<
|
|
93
|
+
SkIr extends Record<string, string | number>,
|
|
94
|
+
> = {
|
|
95
|
+
eq?: SkIr;
|
|
96
|
+
le?: SkIr;
|
|
97
|
+
lt?: SkIr;
|
|
98
|
+
ge?: SkIr;
|
|
99
|
+
gt?: SkIr;
|
|
100
|
+
between?: [SkIr];
|
|
101
|
+
beginsWith?: SkIr;
|
|
102
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface PrimaryIndexIrShape {
|
|
2
|
+
pk: { [key: string]: string | number };
|
|
3
|
+
sk: { [key: string]: string | number } | never;
|
|
4
|
+
compositeSk: never | string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface SecondaryIndexIrShape extends PrimaryIndexIrShape {
|
|
8
|
+
defaultQueryFieldSuffix: string;
|
|
9
|
+
queryField: string;
|
|
10
|
+
}
|
package/src/util/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClientSchema.js","sources":["../../src/ClientSchema.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CustomOperations.js","sources":["../../../src/MappedTypes/CustomOperations.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;;"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { __modelMeta__ } from './runtime/client';
|
|
2
|
-
import type { GenericModelSchema, RDSModelSchema } from './ModelSchema';
|
|
3
|
-
import type { ResolveSchema, SchemaTypes } from './MappedTypes/ResolveSchema';
|
|
4
|
-
import type { ResolveFieldProperties, ResolveStaticFieldProperties } from './MappedTypes/ResolveFieldProperties';
|
|
5
|
-
import type { ModelIdentifier, ModelSecondaryIndexes, RelationalMetadata } from './MappedTypes/ModelMetadata';
|
|
6
|
-
import type { ExtractNonModelTypes, NonModelTypesShape } from './MappedTypes/ExtractNonModelTypes';
|
|
7
|
-
import type { ResolveCustomOperations, CustomOperationHandlerTypes } from './MappedTypes/CustomOperations';
|
|
8
|
-
import type { CombinedModelSchema, CombinedSchemaIndexesUnion } from './CombineSchema';
|
|
9
|
-
import type { SpreadTuple } from './util';
|
|
10
|
-
export type ClientSchema<Schema extends GenericModelSchema<any> | CombinedModelSchema<any>> = Schema extends GenericModelSchema<any> ? InternalClientSchema<Schema> : Schema extends CombinedModelSchema<any> ? InternalCombinedSchema<Schema> : never;
|
|
11
|
-
/**
|
|
12
|
-
* Types for unwrapping generic type args into client-consumable types
|
|
13
|
-
*
|
|
14
|
-
* @typeParam Schema - Data schema builder model type
|
|
15
|
-
*
|
|
16
|
-
* The following params are used solely as variables in order to simplify mapped type usage.
|
|
17
|
-
* They should not receive external type args.
|
|
18
|
-
*
|
|
19
|
-
* @internal @typeParam NonModelTypes - Custom Types, Enums, and Custom Operations
|
|
20
|
-
* @internal @typeParam ResolvedSchema - Resolve the schema types used by other generics
|
|
21
|
-
* @internal @typeParam ResolvedFields - Resolved client-facing types used for CRUDL response shapes
|
|
22
|
-
* @internal @typeParam IdentifierMeta - Resolve the identifier fields for all models
|
|
23
|
-
* @internal @typeParam SecondaryIndexes - Map of model secondary index metadata
|
|
24
|
-
*/
|
|
25
|
-
type InternalClientSchema<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape = ExtractNonModelTypes<Schema>, ResolvedSchema = ResolveSchema<Schema>, ResolvedFields extends Record<string, unknown> = Schema extends RDSModelSchema<any, any> ? ResolveStaticFieldProperties<Schema, NonModelTypes, object> : ResolveFieldProperties<Schema, NonModelTypes>, IdentifierMeta extends Record<string, any> = ModelIdentifier<SchemaTypes<Schema>>, SecondaryIndexes extends Record<string, any> = Schema extends RDSModelSchema<any, any> ? object : ModelSecondaryIndexes<SchemaTypes<Schema>>> = CustomOperationHandlerTypes<ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>['customOperations']> & {
|
|
26
|
-
[K in keyof ResolvedFields]: {
|
|
27
|
-
type: ResolvedFields[K];
|
|
28
|
-
};
|
|
29
|
-
} & {
|
|
30
|
-
[__modelMeta__]: IdentifierMeta & SecondaryIndexes & RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta> & NonModelTypes & ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>;
|
|
31
|
-
};
|
|
32
|
-
type GetInternalClientSchema<Schema> = Schema extends GenericModelSchema<any> ? InternalClientSchema<Schema> : never;
|
|
33
|
-
type CombinedClientSchemas<Schemas extends CombinedModelSchema<any>['schemas']> = {
|
|
34
|
-
[Index in keyof Schemas]: Index extends CombinedSchemaIndexesUnion ? GetInternalClientSchema<Schemas[Index]> : never;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Types for unwrapping and combining generic type args into client-consumable types
|
|
38
|
-
* for multiple schemas
|
|
39
|
-
*
|
|
40
|
-
* @typeParam Combined - A container of multiple schemas
|
|
41
|
-
*
|
|
42
|
-
* @internal @typeParam ClientSchemas - The tuple of client schemas to combine
|
|
43
|
-
*/
|
|
44
|
-
type InternalCombinedSchema<Combined extends CombinedModelSchema<any>, ClientSchemas extends [...any] = CombinedClientSchemas<Combined['schemas']>> = SpreadTuple<{
|
|
45
|
-
[I in keyof ClientSchemas]: I extends CombinedSchemaIndexesUnion ? Omit<ClientSchemas[I], typeof __modelMeta__> : never;
|
|
46
|
-
}> & {
|
|
47
|
-
[__modelMeta__]: SpreadTuple<{
|
|
48
|
-
[I in keyof ClientSchemas]: I extends CombinedSchemaIndexesUnion ? ClientSchemas[I][typeof __modelMeta__] : never;
|
|
49
|
-
}>;
|
|
50
|
-
};
|
|
51
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClientSchema.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { GenericModelSchema } from '../ModelSchema';
|
|
2
|
-
import type { NonModelTypesShape } from './ExtractNonModelTypes';
|
|
3
|
-
import type { CustomOperation, CustomOperationParamShape } from '../CustomOperation';
|
|
4
|
-
import type { BaseModelField } from '../ModelField';
|
|
5
|
-
import type { RefType, RefTypeParamShape } from '../RefType';
|
|
6
|
-
import type { ResolveFieldRequirements, ResolveRefsOfCustomType, ResolveRefValueArrayTraits } from './ResolveFieldProperties';
|
|
7
|
-
import type { AppSyncResolverHandler } from 'aws-lambda';
|
|
8
|
-
import type { CustomType } from '../CustomType';
|
|
9
|
-
import type { FieldTypesOfCustomType } from './ResolveSchema';
|
|
10
|
-
/**
|
|
11
|
-
* Creates meta types for custom operations from a schema.
|
|
12
|
-
*/
|
|
13
|
-
export type ResolveCustomOperations<Schema extends GenericModelSchema<any>, FullyResolvedSchema extends Record<string, unknown>, NonModelTypes extends NonModelTypesShape, CustomOperations extends Record<string, CustomOperationParamShape> = CustomOpShapes<Schema>> = {
|
|
14
|
-
customOperations: {
|
|
15
|
-
[OpName in keyof CustomOperations]: {
|
|
16
|
-
arguments: CustomOpArguments<CustomOperations[OpName]>;
|
|
17
|
-
returnType: CustomOpReturnType<CustomOperations[OpName], FullyResolvedSchema, NonModelTypes, CustomOperations>;
|
|
18
|
-
typeName: CustomOperations[OpName]['typeName'];
|
|
19
|
-
authorization: CustomOperations[OpName]['authorization'];
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Filtered, mapped list of custom operations shapes from a schema.
|
|
25
|
-
*/
|
|
26
|
-
export type CustomOpShapes<Schema extends GenericModelSchema<any>> = {
|
|
27
|
-
[K in keyof Schema['data']['types'] as Schema['data']['types'][K] extends CustomOperation<any, any> ? K : never]: Schema['data']['types'][K] extends CustomOperation<infer Shape, any> ? Shape : never;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Digs out custom operation arguments, mapped to the intended graphql types.
|
|
31
|
-
*/
|
|
32
|
-
export type CustomOpArguments<Shape extends CustomOperationParamShape> = Shape['arguments'] extends null ? never : ResolveFieldRequirements<{
|
|
33
|
-
[FieldName in keyof Shape['arguments']]: Shape['arguments'][FieldName] extends BaseModelField<infer R> ? R : never;
|
|
34
|
-
}>;
|
|
35
|
-
/**
|
|
36
|
-
* Computes the return type from the `returnType` of a custom operation shape.
|
|
37
|
-
*
|
|
38
|
-
* This entails dereferencing refs and inferring graphql types from field-type defs.
|
|
39
|
-
*/
|
|
40
|
-
export type CustomOpReturnType<Shape extends CustomOperationParamShape, FullyResolvedSchema extends Record<string, unknown>, NonModelTypes extends NonModelTypesShape, CustomOperations extends Record<string, CustomOperationParamShape>> = Shape['returnType'] extends RefType<infer RefShape, any, any> ? RefShape['link'] extends keyof CustomOperations ? CustomOpReturnType<CustomOperations[RefShape['link']], FullyResolvedSchema, NonModelTypes, CustomOperations> : ResolveRef<RefShape, FullyResolvedSchema, NonModelTypes, CustomOperations> : Shape['returnType'] extends BaseModelField<infer R> ? R : Shape['returnType'] extends CustomType<infer R> ? ResolveFieldRequirements<FieldTypesOfCustomType<{
|
|
41
|
-
thisCustomType: R['fields'];
|
|
42
|
-
}>['thisCustomType']> | null : never;
|
|
43
|
-
/**
|
|
44
|
-
* `a.ref()` resolution specific to custom operations, for which `a.ref()`
|
|
45
|
-
* can refer to a model, custom type, or enum.
|
|
46
|
-
*
|
|
47
|
-
* This utility is a duplication of ResolveRef (src/MappedTypes/ResolveFieldProperties.ts)
|
|
48
|
-
* with the addition that allows .ref() a model with custom operations.
|
|
49
|
-
*/
|
|
50
|
-
export type ResolveRef<Shape extends RefTypeParamShape, FullyResolvedSchema extends Record<string, unknown>, NonModelTypes extends NonModelTypesShape, CustomOperations extends Record<string, CustomOperationParamShape>, Link = Shape['link'], RefValue = Link extends keyof FullyResolvedSchema ? FullyResolvedSchema[Link] : Link extends keyof NonModelTypes['enums'] ? NonModelTypes['enums'][Link] : Link extends keyof NonModelTypes['customTypes'] ? ResolveRefsOfCustomType<NonModelTypes, NonModelTypes['customTypes'][Link]> : Link extends keyof CustomOperations ? CustomOpReturnType<CustomOperations[Link], FullyResolvedSchema, NonModelTypes, CustomOperations> : never, Value = Shape['valueRequired'] extends true ? RefValue : RefValue | null> = ResolveRefValueArrayTraits<Shape, Value>;
|
|
51
|
-
/**
|
|
52
|
-
* The kind of shape we need to map to custom handler (e.g., lambda) function
|
|
53
|
-
* signatures.
|
|
54
|
-
*/
|
|
55
|
-
type CustomOperationsMap = Record<string, CustomOperationMinimalDef>;
|
|
56
|
-
/**
|
|
57
|
-
* The minimal amount of structure needed to extract types for a custom handler.
|
|
58
|
-
*/
|
|
59
|
-
type CustomOperationMinimalDef = {
|
|
60
|
-
arguments: any;
|
|
61
|
-
returnType: any;
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Derives the signature and types for a lambda handler for a particular
|
|
65
|
-
* custom Query or Mutation from a Schema.
|
|
66
|
-
*/
|
|
67
|
-
type IndividualCustomHandlerTypes<Op extends CustomOperationMinimalDef> = {
|
|
68
|
-
/**
|
|
69
|
-
* Handler type for lambda function implementations. E.g.,
|
|
70
|
-
*
|
|
71
|
-
* ```typescript
|
|
72
|
-
* import type { Schema } from './resource';
|
|
73
|
-
*
|
|
74
|
-
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => {
|
|
75
|
-
* // event and context will be fully typed inside here.
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
functionHandler: AppSyncResolverHandler<Op['arguments'], LambdaReturnType<Op['returnType']>>;
|
|
80
|
-
/**
|
|
81
|
-
* The `context.arguments` type for lambda function implementations.
|
|
82
|
-
*
|
|
83
|
-
* ```typescript
|
|
84
|
-
* import type { Schema } from './resource';
|
|
85
|
-
*
|
|
86
|
-
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => {
|
|
87
|
-
* // Provides this type, if needed:
|
|
88
|
-
* const args: Schema['echo']['functionHandlerArguments'] = event.arguments;
|
|
89
|
-
* }
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
args: Op['arguments'];
|
|
93
|
-
/**
|
|
94
|
-
* The return type expected by a lambda function handler.
|
|
95
|
-
*
|
|
96
|
-
* ```typescript
|
|
97
|
-
* import type { Schema } from './resource';
|
|
98
|
-
*
|
|
99
|
-
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => {
|
|
100
|
-
* // Result type enforced here:
|
|
101
|
-
* const result: Schema['echo']['functionHandlerResult'] = buildResult(...);
|
|
102
|
-
*
|
|
103
|
-
* // `Result` type matches expected function return type here:
|
|
104
|
-
* return result;
|
|
105
|
-
* }
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
returnType: LambdaReturnType<Op['returnType']>;
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Derives the function signatures for a lambda handlers for all the provided
|
|
112
|
-
* custom queries and mutations.
|
|
113
|
-
*/
|
|
114
|
-
export type CustomOperationHandlerTypes<CustomOperations extends CustomOperationsMap> = {
|
|
115
|
-
[K in keyof CustomOperations]: IndividualCustomHandlerTypes<CustomOperations[K]>;
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Returns a return type with lazy loaders removed.
|
|
119
|
-
*
|
|
120
|
-
* (Custom handlers should not return lazy loaded fields -- they're *lazy loaded*.)
|
|
121
|
-
*/
|
|
122
|
-
type LambdaReturnType<T> = T extends Record<string, any> ? {
|
|
123
|
-
[K in keyof Exclude<T, null | undefined> as Exclude<T, null | undefined>[K] extends (...args: any) => any ? never : K]: Exclude<T, null | undefined>[K];
|
|
124
|
-
} : T | (null extends T ? null : never) | (undefined extends T ? undefined : never);
|
|
125
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CustomOperations.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/src/ClientSchema.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type { __modelMeta__ } from './runtime/client';
|
|
2
|
-
import type { GenericModelSchema, RDSModelSchema } from './ModelSchema';
|
|
3
|
-
|
|
4
|
-
// MappedTypes
|
|
5
|
-
import type { ResolveSchema, SchemaTypes } from './MappedTypes/ResolveSchema';
|
|
6
|
-
import type {
|
|
7
|
-
ResolveFieldProperties,
|
|
8
|
-
ResolveStaticFieldProperties,
|
|
9
|
-
} from './MappedTypes/ResolveFieldProperties';
|
|
10
|
-
import type {
|
|
11
|
-
ModelIdentifier,
|
|
12
|
-
ModelSecondaryIndexes,
|
|
13
|
-
RelationalMetadata,
|
|
14
|
-
} from './MappedTypes/ModelMetadata';
|
|
15
|
-
import type {
|
|
16
|
-
ExtractNonModelTypes,
|
|
17
|
-
NonModelTypesShape,
|
|
18
|
-
} from './MappedTypes/ExtractNonModelTypes';
|
|
19
|
-
import type {
|
|
20
|
-
ResolveCustomOperations,
|
|
21
|
-
CustomOperationHandlerTypes,
|
|
22
|
-
} from './MappedTypes/CustomOperations';
|
|
23
|
-
import type {
|
|
24
|
-
CombinedModelSchema,
|
|
25
|
-
CombinedSchemaIndexesUnion,
|
|
26
|
-
} from './CombineSchema';
|
|
27
|
-
import type { SpreadTuple } from './util';
|
|
28
|
-
|
|
29
|
-
export type ClientSchema<
|
|
30
|
-
Schema extends GenericModelSchema<any> | CombinedModelSchema<any>,
|
|
31
|
-
> =
|
|
32
|
-
Schema extends GenericModelSchema<any>
|
|
33
|
-
? InternalClientSchema<Schema>
|
|
34
|
-
: Schema extends CombinedModelSchema<any>
|
|
35
|
-
? InternalCombinedSchema<Schema>
|
|
36
|
-
: never;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Types for unwrapping generic type args into client-consumable types
|
|
40
|
-
*
|
|
41
|
-
* @typeParam Schema - Data schema builder model type
|
|
42
|
-
*
|
|
43
|
-
* The following params are used solely as variables in order to simplify mapped type usage.
|
|
44
|
-
* They should not receive external type args.
|
|
45
|
-
*
|
|
46
|
-
* @internal @typeParam NonModelTypes - Custom Types, Enums, and Custom Operations
|
|
47
|
-
* @internal @typeParam ResolvedSchema - Resolve the schema types used by other generics
|
|
48
|
-
* @internal @typeParam ResolvedFields - Resolved client-facing types used for CRUDL response shapes
|
|
49
|
-
* @internal @typeParam IdentifierMeta - Resolve the identifier fields for all models
|
|
50
|
-
* @internal @typeParam SecondaryIndexes - Map of model secondary index metadata
|
|
51
|
-
*/
|
|
52
|
-
type InternalClientSchema<
|
|
53
|
-
Schema extends GenericModelSchema<any>,
|
|
54
|
-
NonModelTypes extends NonModelTypesShape = ExtractNonModelTypes<Schema>,
|
|
55
|
-
ResolvedSchema = ResolveSchema<Schema>,
|
|
56
|
-
ResolvedFields extends Record<
|
|
57
|
-
string,
|
|
58
|
-
unknown
|
|
59
|
-
> = Schema extends RDSModelSchema<any, any>
|
|
60
|
-
? ResolveStaticFieldProperties<Schema, NonModelTypes, object>
|
|
61
|
-
: ResolveFieldProperties<Schema, NonModelTypes>,
|
|
62
|
-
IdentifierMeta extends Record<string, any> = ModelIdentifier<
|
|
63
|
-
SchemaTypes<Schema>
|
|
64
|
-
>,
|
|
65
|
-
SecondaryIndexes extends Record<string, any> = Schema extends RDSModelSchema<
|
|
66
|
-
any,
|
|
67
|
-
any
|
|
68
|
-
>
|
|
69
|
-
? object
|
|
70
|
-
: ModelSecondaryIndexes<SchemaTypes<Schema>>,
|
|
71
|
-
> = CustomOperationHandlerTypes<
|
|
72
|
-
ResolveCustomOperations<
|
|
73
|
-
Schema,
|
|
74
|
-
ResolvedFields,
|
|
75
|
-
NonModelTypes
|
|
76
|
-
>['customOperations']
|
|
77
|
-
> & {
|
|
78
|
-
[K in keyof ResolvedFields]: {
|
|
79
|
-
type: ResolvedFields[K];
|
|
80
|
-
};
|
|
81
|
-
} & {
|
|
82
|
-
[__modelMeta__]: IdentifierMeta &
|
|
83
|
-
SecondaryIndexes &
|
|
84
|
-
RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta> &
|
|
85
|
-
NonModelTypes &
|
|
86
|
-
ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
type GetInternalClientSchema<Schema> =
|
|
90
|
-
Schema extends GenericModelSchema<any> ? InternalClientSchema<Schema> : never;
|
|
91
|
-
|
|
92
|
-
type CombinedClientSchemas<
|
|
93
|
-
Schemas extends CombinedModelSchema<any>['schemas'],
|
|
94
|
-
> = {
|
|
95
|
-
[Index in keyof Schemas]: Index extends CombinedSchemaIndexesUnion
|
|
96
|
-
? GetInternalClientSchema<Schemas[Index]>
|
|
97
|
-
: never;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Types for unwrapping and combining generic type args into client-consumable types
|
|
102
|
-
* for multiple schemas
|
|
103
|
-
*
|
|
104
|
-
* @typeParam Combined - A container of multiple schemas
|
|
105
|
-
*
|
|
106
|
-
* @internal @typeParam ClientSchemas - The tuple of client schemas to combine
|
|
107
|
-
*/
|
|
108
|
-
type InternalCombinedSchema<
|
|
109
|
-
Combined extends CombinedModelSchema<any>,
|
|
110
|
-
ClientSchemas extends [...any] = CombinedClientSchemas<Combined['schemas']>,
|
|
111
|
-
> = SpreadTuple<{
|
|
112
|
-
[I in keyof ClientSchemas]: I extends CombinedSchemaIndexesUnion
|
|
113
|
-
? Omit<ClientSchemas[I], typeof __modelMeta__>
|
|
114
|
-
: never;
|
|
115
|
-
}> & {
|
|
116
|
-
[__modelMeta__]: SpreadTuple<{
|
|
117
|
-
[I in keyof ClientSchemas]: I extends CombinedSchemaIndexesUnion
|
|
118
|
-
? ClientSchemas[I][typeof __modelMeta__]
|
|
119
|
-
: never;
|
|
120
|
-
}>;
|
|
121
|
-
};
|