@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
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import type { GenericModelSchema } from '../ModelSchema';
|
|
2
|
-
import type { NonModelTypesShape } from './ExtractNonModelTypes';
|
|
3
|
-
import type {
|
|
4
|
-
CustomOperation,
|
|
5
|
-
CustomOperationParamShape,
|
|
6
|
-
} from '../CustomOperation';
|
|
7
|
-
import type { BaseModelField } from '../ModelField';
|
|
8
|
-
import type { RefType, RefTypeParamShape } from '../RefType';
|
|
9
|
-
import type {
|
|
10
|
-
ResolveFieldRequirements,
|
|
11
|
-
ResolveRefsOfCustomType,
|
|
12
|
-
ResolveRefValueArrayTraits,
|
|
13
|
-
} from './ResolveFieldProperties';
|
|
14
|
-
import type { AppSyncResolverHandler } from 'aws-lambda';
|
|
15
|
-
import type { CustomType } from '../CustomType';
|
|
16
|
-
import type { FieldTypesOfCustomType } from './ResolveSchema';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Creates meta types for custom operations from a schema.
|
|
20
|
-
*/
|
|
21
|
-
export type ResolveCustomOperations<
|
|
22
|
-
Schema extends GenericModelSchema<any>,
|
|
23
|
-
FullyResolvedSchema extends Record<string, unknown>,
|
|
24
|
-
NonModelTypes extends NonModelTypesShape,
|
|
25
|
-
CustomOperations extends Record<
|
|
26
|
-
string,
|
|
27
|
-
CustomOperationParamShape
|
|
28
|
-
> = CustomOpShapes<Schema>,
|
|
29
|
-
> = {
|
|
30
|
-
customOperations: {
|
|
31
|
-
[OpName in keyof CustomOperations]: {
|
|
32
|
-
arguments: CustomOpArguments<CustomOperations[OpName]>;
|
|
33
|
-
returnType: CustomOpReturnType<
|
|
34
|
-
CustomOperations[OpName],
|
|
35
|
-
FullyResolvedSchema,
|
|
36
|
-
NonModelTypes,
|
|
37
|
-
CustomOperations
|
|
38
|
-
>;
|
|
39
|
-
typeName: CustomOperations[OpName]['typeName'];
|
|
40
|
-
authorization: CustomOperations[OpName]['authorization'];
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Filtered, mapped list of custom operations shapes from a schema.
|
|
47
|
-
*/
|
|
48
|
-
export type CustomOpShapes<Schema extends GenericModelSchema<any>> = {
|
|
49
|
-
[K in keyof Schema['data']['types'] as Schema['data']['types'][K] extends CustomOperation<
|
|
50
|
-
any,
|
|
51
|
-
any
|
|
52
|
-
>
|
|
53
|
-
? K
|
|
54
|
-
: never]: Schema['data']['types'][K] extends CustomOperation<
|
|
55
|
-
infer Shape,
|
|
56
|
-
any
|
|
57
|
-
>
|
|
58
|
-
? Shape
|
|
59
|
-
: never;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Digs out custom operation arguments, mapped to the intended graphql types.
|
|
64
|
-
*/
|
|
65
|
-
export type CustomOpArguments<Shape extends CustomOperationParamShape> =
|
|
66
|
-
Shape['arguments'] extends null
|
|
67
|
-
? never
|
|
68
|
-
: ResolveFieldRequirements<{
|
|
69
|
-
[FieldName in keyof Shape['arguments']]: Shape['arguments'][FieldName] extends BaseModelField<
|
|
70
|
-
infer R
|
|
71
|
-
>
|
|
72
|
-
? R
|
|
73
|
-
: never;
|
|
74
|
-
}>;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Computes the return type from the `returnType` of a custom operation shape.
|
|
78
|
-
*
|
|
79
|
-
* This entails dereferencing refs and inferring graphql types from field-type defs.
|
|
80
|
-
*/
|
|
81
|
-
export type CustomOpReturnType<
|
|
82
|
-
Shape extends CustomOperationParamShape,
|
|
83
|
-
FullyResolvedSchema extends Record<string, unknown>,
|
|
84
|
-
NonModelTypes extends NonModelTypesShape,
|
|
85
|
-
CustomOperations extends Record<string, CustomOperationParamShape>,
|
|
86
|
-
> =
|
|
87
|
-
Shape['returnType'] extends RefType<infer RefShape, any, any>
|
|
88
|
-
? RefShape['link'] extends keyof CustomOperations
|
|
89
|
-
? // The case that a custom subscription's return type is set from its resource
|
|
90
|
-
CustomOpReturnType<
|
|
91
|
-
CustomOperations[RefShape['link']],
|
|
92
|
-
FullyResolvedSchema,
|
|
93
|
-
NonModelTypes,
|
|
94
|
-
CustomOperations
|
|
95
|
-
>
|
|
96
|
-
: ResolveRef<
|
|
97
|
-
RefShape,
|
|
98
|
-
FullyResolvedSchema,
|
|
99
|
-
NonModelTypes,
|
|
100
|
-
CustomOperations
|
|
101
|
-
>
|
|
102
|
-
: Shape['returnType'] extends BaseModelField<infer R>
|
|
103
|
-
? R
|
|
104
|
-
: Shape['returnType'] extends CustomType<infer R>
|
|
105
|
-
?
|
|
106
|
-
| ResolveFieldRequirements<
|
|
107
|
-
FieldTypesOfCustomType<{
|
|
108
|
-
thisCustomType: R['fields'];
|
|
109
|
-
}>['thisCustomType']
|
|
110
|
-
> // The inline `.customType()` with a custom operation doesn't have
|
|
111
|
-
// `.required()` modifier, hence it's nullable
|
|
112
|
-
| null
|
|
113
|
-
: never;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* `a.ref()` resolution specific to custom operations, for which `a.ref()`
|
|
117
|
-
* can refer to a model, custom type, or enum.
|
|
118
|
-
*
|
|
119
|
-
* This utility is a duplication of ResolveRef (src/MappedTypes/ResolveFieldProperties.ts)
|
|
120
|
-
* with the addition that allows .ref() a model with custom operations.
|
|
121
|
-
*/
|
|
122
|
-
export type ResolveRef<
|
|
123
|
-
Shape extends RefTypeParamShape,
|
|
124
|
-
FullyResolvedSchema extends Record<string, unknown>,
|
|
125
|
-
NonModelTypes extends NonModelTypesShape,
|
|
126
|
-
CustomOperations extends Record<string, CustomOperationParamShape>,
|
|
127
|
-
Link = Shape['link'],
|
|
128
|
-
RefValue = Link extends keyof FullyResolvedSchema
|
|
129
|
-
? FullyResolvedSchema[Link]
|
|
130
|
-
: Link extends keyof NonModelTypes['enums']
|
|
131
|
-
? NonModelTypes['enums'][Link]
|
|
132
|
-
: Link extends keyof NonModelTypes['customTypes']
|
|
133
|
-
? ResolveRefsOfCustomType<
|
|
134
|
-
NonModelTypes,
|
|
135
|
-
NonModelTypes['customTypes'][Link]
|
|
136
|
-
>
|
|
137
|
-
: Link extends keyof CustomOperations
|
|
138
|
-
? // e.g. .subscription().for(a.ref('aCustomMutation'))
|
|
139
|
-
CustomOpReturnType<
|
|
140
|
-
CustomOperations[Link],
|
|
141
|
-
FullyResolvedSchema,
|
|
142
|
-
NonModelTypes,
|
|
143
|
-
CustomOperations
|
|
144
|
-
>
|
|
145
|
-
: never,
|
|
146
|
-
Value = Shape['valueRequired'] extends true ? RefValue : RefValue | null,
|
|
147
|
-
> = ResolveRefValueArrayTraits<Shape, Value>;
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
// To support exposing custom handler types.
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* The kind of shape we need to map to custom handler (e.g., lambda) function
|
|
155
|
-
* signatures.
|
|
156
|
-
*/
|
|
157
|
-
type CustomOperationsMap = Record<string, CustomOperationMinimalDef>;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* The minimal amount of structure needed to extract types for a custom handler.
|
|
161
|
-
*/
|
|
162
|
-
type CustomOperationMinimalDef = {
|
|
163
|
-
arguments: any;
|
|
164
|
-
returnType: any;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Derives the signature and types for a lambda handler for a particular
|
|
169
|
-
* custom Query or Mutation from a Schema.
|
|
170
|
-
*/
|
|
171
|
-
type IndividualCustomHandlerTypes<Op extends CustomOperationMinimalDef> = {
|
|
172
|
-
/**
|
|
173
|
-
* Handler type for lambda function implementations. E.g.,
|
|
174
|
-
*
|
|
175
|
-
* ```typescript
|
|
176
|
-
* import type { Schema } from './resource';
|
|
177
|
-
*
|
|
178
|
-
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => {
|
|
179
|
-
* // event and context will be fully typed inside here.
|
|
180
|
-
* }
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
functionHandler: AppSyncResolverHandler<
|
|
184
|
-
Op['arguments'],
|
|
185
|
-
LambdaReturnType<Op['returnType']>
|
|
186
|
-
>;
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* The `context.arguments` type for lambda function implementations.
|
|
190
|
-
*
|
|
191
|
-
* ```typescript
|
|
192
|
-
* import type { Schema } from './resource';
|
|
193
|
-
*
|
|
194
|
-
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => {
|
|
195
|
-
* // Provides this type, if needed:
|
|
196
|
-
* const args: Schema['echo']['functionHandlerArguments'] = event.arguments;
|
|
197
|
-
* }
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
args: Op['arguments'];
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* The return type expected by a lambda function handler.
|
|
204
|
-
*
|
|
205
|
-
* ```typescript
|
|
206
|
-
* import type { Schema } from './resource';
|
|
207
|
-
*
|
|
208
|
-
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => {
|
|
209
|
-
* // Result type enforced here:
|
|
210
|
-
* const result: Schema['echo']['functionHandlerResult'] = buildResult(...);
|
|
211
|
-
*
|
|
212
|
-
* // `Result` type matches expected function return type here:
|
|
213
|
-
* return result;
|
|
214
|
-
* }
|
|
215
|
-
* ```
|
|
216
|
-
*/
|
|
217
|
-
returnType: LambdaReturnType<Op['returnType']>;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Derives the function signatures for a lambda handlers for all the provided
|
|
222
|
-
* custom queries and mutations.
|
|
223
|
-
*/
|
|
224
|
-
export type CustomOperationHandlerTypes<
|
|
225
|
-
CustomOperations extends CustomOperationsMap,
|
|
226
|
-
> = {
|
|
227
|
-
[K in keyof CustomOperations]: IndividualCustomHandlerTypes<
|
|
228
|
-
CustomOperations[K]
|
|
229
|
-
>;
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Returns a return type with lazy loaders removed.
|
|
234
|
-
*
|
|
235
|
-
* (Custom handlers should not return lazy loaded fields -- they're *lazy loaded*.)
|
|
236
|
-
*/
|
|
237
|
-
type LambdaReturnType<T> =
|
|
238
|
-
T extends Record<string, any>
|
|
239
|
-
? {
|
|
240
|
-
// Return type can include `null | undefined`, which we can't meaningfully
|
|
241
|
-
// map over.
|
|
242
|
-
[K in keyof Exclude<T, null | undefined> as Exclude<
|
|
243
|
-
T,
|
|
244
|
-
null | undefined
|
|
245
|
-
>[K] extends (...args: any) => any
|
|
246
|
-
? never
|
|
247
|
-
: K]: Exclude<T, null | undefined>[K];
|
|
248
|
-
}
|
|
249
|
-
:
|
|
250
|
-
| T
|
|
251
|
-
// If the original return type allowed null | undefined, mix them back into
|
|
252
|
-
// the final return type
|
|
253
|
-
| (null extends T ? null : never)
|
|
254
|
-
| (undefined extends T ? undefined : never);
|