@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
package/src/Authorization.ts
CHANGED
|
@@ -639,8 +639,8 @@ export type ImpliedAuthField<T extends Authorization<any, any, any>> =
|
|
|
639
639
|
? never
|
|
640
640
|
: Field extends string
|
|
641
641
|
? isMulti extends true
|
|
642
|
-
? { [K in Field]?: string[] }
|
|
643
|
-
: { [K in Field]?: string }
|
|
642
|
+
? { [K in Field]?: string[] | null | undefined }
|
|
643
|
+
: { [K in Field]?: string | null | undefined }
|
|
644
644
|
: never
|
|
645
645
|
: never;
|
|
646
646
|
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { CustomOperationParamShape } from '../../CustomOperation';
|
|
2
|
+
import type { BaseModelField } from '../../ModelField';
|
|
3
|
+
import type { RefType } from '../../RefType';
|
|
4
|
+
import type { ResolveFieldRequirements } from '../../MappedTypes/ResolveFieldProperties';
|
|
5
|
+
import type { AppSyncResolverHandler } from 'aws-lambda';
|
|
6
|
+
import type { CustomType } from '../../CustomType';
|
|
7
|
+
import type { FieldTypesOfCustomType } from '../../MappedTypes/ResolveSchema';
|
|
8
|
+
import type { ResolveRef } from '../utilities/ResolveRef';
|
|
9
|
+
import { ClientSchemaProperty } from './ClientSchemaProperty';
|
|
10
|
+
|
|
11
|
+
type CustomOperationSubType<Op extends CustomOperationParamShape> =
|
|
12
|
+
`custom${Op['typeName']}`;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Derives the signature and types for a lambda handler for a particular
|
|
16
|
+
* custom Query or Mutation from a Schema.
|
|
17
|
+
*/
|
|
18
|
+
export interface ClientCustomOperation<
|
|
19
|
+
RefBag extends Record<any, any>,
|
|
20
|
+
Op extends CustomOperationParamShape,
|
|
21
|
+
> extends ClientSchemaProperty {
|
|
22
|
+
__entityType: CustomOperationSubType<Op>;
|
|
23
|
+
operationType: Op['typeName'];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Handler type for lambda function implementations. E.g.,
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import type { Schema } from './resource';
|
|
30
|
+
*
|
|
31
|
+
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => {
|
|
32
|
+
* // event and context will be fully typed inside here.
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
functionHandler: AppSyncResolverHandler<
|
|
37
|
+
CustomOpArguments<Op>,
|
|
38
|
+
LambdaReturnType<CustomOpReturnType<Op, RefBag>>
|
|
39
|
+
>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The `context.arguments` type for lambda function implementations.
|
|
43
|
+
*
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import type { Schema } from './resource';
|
|
46
|
+
*
|
|
47
|
+
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => {
|
|
48
|
+
* // Provides this type, if needed:
|
|
49
|
+
* const args: Schema['echo']['functionHandlerArguments'] = event.arguments;
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
args: CustomOpArguments<Op>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The return type expected by a lambda function handler.
|
|
57
|
+
*
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import type { Schema } from './resource';
|
|
60
|
+
*
|
|
61
|
+
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => {
|
|
62
|
+
* // Result type enforced here:
|
|
63
|
+
* const result: Schema['echo']['functionHandlerResult'] = buildResult(...);
|
|
64
|
+
*
|
|
65
|
+
* // `Result` type matches expected function return type here:
|
|
66
|
+
* return result;
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
returnType: LambdaReturnType<CustomOpReturnType<Op, RefBag>>;
|
|
71
|
+
|
|
72
|
+
type: CustomOpReturnType<Op, RefBag>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Digs out custom operation arguments, mapped to the intended graphql types.
|
|
77
|
+
*/
|
|
78
|
+
type CustomOpArguments<Shape extends CustomOperationParamShape> =
|
|
79
|
+
Shape['arguments'] extends null
|
|
80
|
+
? never
|
|
81
|
+
: ResolveFieldRequirements<{
|
|
82
|
+
[FieldName in keyof Shape['arguments']]: Shape['arguments'][FieldName] extends BaseModelField<
|
|
83
|
+
infer R
|
|
84
|
+
>
|
|
85
|
+
? R
|
|
86
|
+
: never;
|
|
87
|
+
}>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Removes `null | undefined` from the return type if the operation is a subscription,
|
|
91
|
+
* since subs don't fire on empty/non-existent values.
|
|
92
|
+
*/
|
|
93
|
+
type Normalize<
|
|
94
|
+
Shape extends CustomOperationParamShape,
|
|
95
|
+
RT,
|
|
96
|
+
> = Shape['typeName'] extends 'Subscription'
|
|
97
|
+
? Exclude<RT, null | undefined>
|
|
98
|
+
: RT;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Computes the return type from the `returnType` of a custom operation shape.
|
|
102
|
+
*
|
|
103
|
+
* This entails dereferencing refs and inferring graphql types from field-type defs.
|
|
104
|
+
*/
|
|
105
|
+
type CustomOpReturnType<
|
|
106
|
+
Shape extends CustomOperationParamShape,
|
|
107
|
+
RefBag extends Record<string, any>,
|
|
108
|
+
> = Normalize<
|
|
109
|
+
Shape,
|
|
110
|
+
Shape['returnType'] extends RefType<infer RefShape, any, any>
|
|
111
|
+
? RefShape['link'] extends keyof RefBag
|
|
112
|
+
? ResolveRef<RefShape, RefBag>
|
|
113
|
+
: never
|
|
114
|
+
: Shape['returnType'] extends BaseModelField<infer R>
|
|
115
|
+
? R
|
|
116
|
+
: Shape['returnType'] extends CustomType<infer R>
|
|
117
|
+
?
|
|
118
|
+
| ResolveFieldRequirements<
|
|
119
|
+
FieldTypesOfCustomType<{
|
|
120
|
+
thisCustomType: R['fields'];
|
|
121
|
+
}>['thisCustomType']
|
|
122
|
+
> // The inline `.customType()` with a custom operation doesn't have
|
|
123
|
+
// `.required()` modifier, hence it's nullable
|
|
124
|
+
| null
|
|
125
|
+
: never
|
|
126
|
+
>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Returns a return type with lazy loaders removed.
|
|
130
|
+
*
|
|
131
|
+
* (Custom handlers should not return lazy loaded fields -- they're *lazy loaded*.)
|
|
132
|
+
*/
|
|
133
|
+
type LambdaReturnType<T> =
|
|
134
|
+
T extends Array<infer RT>
|
|
135
|
+
? Array<LambdaReturnType<RT>>
|
|
136
|
+
: T extends Record<string, any>
|
|
137
|
+
? {
|
|
138
|
+
// Return type can include `null | undefined`, which we can't meaningfully
|
|
139
|
+
// map over.
|
|
140
|
+
[K in keyof Exclude<T, null | undefined> as Exclude<
|
|
141
|
+
T,
|
|
142
|
+
null | undefined
|
|
143
|
+
>[K] extends (...args: any) => any
|
|
144
|
+
? never
|
|
145
|
+
: K]: Exclude<T, null | undefined>[K];
|
|
146
|
+
}
|
|
147
|
+
:
|
|
148
|
+
| T
|
|
149
|
+
// If the original return type allowed null | undefined, mix them back into
|
|
150
|
+
// the final return type
|
|
151
|
+
| (null extends T ? null : never)
|
|
152
|
+
| (undefined extends T ? undefined : never);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CustomTypeParamShape } from '../../CustomType';
|
|
2
|
+
import { ClientSchemaProperty } from './ClientSchemaProperty';
|
|
3
|
+
import { ResolveFields } from '../utilities/ResolveField';
|
|
4
|
+
|
|
5
|
+
export interface ClientCustomType<
|
|
6
|
+
Bag extends Record<string, unknown>,
|
|
7
|
+
T extends CustomTypeParamShape,
|
|
8
|
+
> extends ClientSchemaProperty {
|
|
9
|
+
__entityType: 'customType';
|
|
10
|
+
type: ResolveFields<Bag, T['fields']>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
deferredRefResolvingPrefix,
|
|
3
|
+
ModelTypeParamShape,
|
|
4
|
+
ModelDefaultIdentifier,
|
|
5
|
+
} from '../../ModelType';
|
|
6
|
+
import type { ClientSchemaProperty } from './ClientSchemaProperty';
|
|
7
|
+
import type { Authorization, ImpliedAuthFields } from '../../Authorization';
|
|
8
|
+
import type { SchemaMetadata, ResolveFields } from '../utilities';
|
|
9
|
+
import type {
|
|
10
|
+
IsEmptyStringOrNever,
|
|
11
|
+
UnionToIntersection,
|
|
12
|
+
Equal,
|
|
13
|
+
Prettify,
|
|
14
|
+
} from '@aws-amplify/data-schema-types';
|
|
15
|
+
import type { ModelField } from '../../ModelField';
|
|
16
|
+
import type { ModelRelationalField } from '../../ModelRelationalField';
|
|
17
|
+
import type { EnumType } from '../../EnumType';
|
|
18
|
+
import type { CustomType, CustomTypeParamShape } from '../../CustomType';
|
|
19
|
+
import type { RefType } from '../../RefType';
|
|
20
|
+
import type {
|
|
21
|
+
StringFilter,
|
|
22
|
+
NumericFilter,
|
|
23
|
+
ModelPrimaryCompositeKeyInput,
|
|
24
|
+
PrimaryIndexIrShape,
|
|
25
|
+
SecondaryIndexIrShape,
|
|
26
|
+
} from '../../util';
|
|
27
|
+
|
|
28
|
+
export interface ClientModel<
|
|
29
|
+
Bag extends Record<string, unknown>,
|
|
30
|
+
Metadata extends SchemaMetadata<any>,
|
|
31
|
+
IsRDS extends boolean,
|
|
32
|
+
T extends ModelTypeParamShape,
|
|
33
|
+
K extends keyof Bag & string,
|
|
34
|
+
> extends ClientSchemaProperty {
|
|
35
|
+
__entityType: 'model';
|
|
36
|
+
// Adding prettify here breaks a bunch of things. Need to revisit Prettify impl.
|
|
37
|
+
// Probably work investigating a sprinkling of shallow prettification around instead.
|
|
38
|
+
type: ShallowPretty<ClientFields<Bag, Metadata, IsRDS, T>>;
|
|
39
|
+
createType: Prettify<
|
|
40
|
+
CreateModelInput<ClientModel<Bag, Metadata, IsRDS, T, K>>
|
|
41
|
+
>;
|
|
42
|
+
updateType: Prettify<
|
|
43
|
+
UpdateModelInput<ClientModel<Bag, Metadata, IsRDS, T, K>>
|
|
44
|
+
>;
|
|
45
|
+
deleteType: Prettify<ModelIdentifier<Bag, T>>;
|
|
46
|
+
identifier: ShallowPretty<ModelIdentifier<Bag, T>>;
|
|
47
|
+
nestedTypes: NestedTypes<ClientFields<Bag, Metadata, IsRDS, T>, T>;
|
|
48
|
+
secondaryIndexes: IndexQueryMethodsFromIR<Bag, T['secondaryIndexes'], K>;
|
|
49
|
+
__meta: {
|
|
50
|
+
listOptionsPkParams: ListOptionsPkParams<Bag, T>;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type ShallowPretty<T> = {
|
|
55
|
+
[K in keyof T]: T[K];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type ClientFields<
|
|
59
|
+
Bag extends Record<string, unknown>,
|
|
60
|
+
Metadata extends SchemaMetadata<any>,
|
|
61
|
+
IsRDS extends boolean,
|
|
62
|
+
T extends ModelTypeParamShape,
|
|
63
|
+
> = ResolveFields<Bag, T['fields']> &
|
|
64
|
+
If<Not<IsRDS>, ImplicitIdentifier<T>> &
|
|
65
|
+
AuthFields<Metadata, T> &
|
|
66
|
+
Omit<SystemFields<IsRDS>, keyof ResolveFields<Bag, T['fields']>>;
|
|
67
|
+
|
|
68
|
+
type SystemFields<IsRDS extends boolean> = IsRDS extends false
|
|
69
|
+
? {
|
|
70
|
+
readonly createdAt: string;
|
|
71
|
+
readonly updatedAt: string;
|
|
72
|
+
}
|
|
73
|
+
: object;
|
|
74
|
+
|
|
75
|
+
// refs are not being resolved here ... yet.
|
|
76
|
+
type ModelIdentifier<
|
|
77
|
+
Bag extends Record<string, unknown>,
|
|
78
|
+
T extends ModelTypeParamShape,
|
|
79
|
+
> = ResolveIdentifierFields<
|
|
80
|
+
ResolveFields<Bag, T['fields']>,
|
|
81
|
+
T['identifier']['pk'] &
|
|
82
|
+
(T['identifier']['sk'] extends never ? unknown : T['identifier']['sk'])
|
|
83
|
+
>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Separate util for *injecting* the default implicit identifier for performance
|
|
87
|
+
* reasons. The full ModelIdentifer util needs to extract types from the fields
|
|
88
|
+
* matching the explicitly defined field types. Contrast that to **injecting** PK
|
|
89
|
+
* fields into the model, which is only done specifically when the default of
|
|
90
|
+
* `readonly id: string` is being injected IF AND ONLY IF another `id` field is
|
|
91
|
+
* not already present on the model.
|
|
92
|
+
*/
|
|
93
|
+
type ImplicitIdentifier<T extends ModelTypeParamShape> =
|
|
94
|
+
T['identifier']['pk'] extends ModelDefaultIdentifier['pk']
|
|
95
|
+
? 'id' extends keyof T['fields']
|
|
96
|
+
? unknown
|
|
97
|
+
: ModelDefaultIdentifier['pk']
|
|
98
|
+
: unknown;
|
|
99
|
+
|
|
100
|
+
type ResolveIdentifierFields<Model, IdentifierFields> = {
|
|
101
|
+
[K in keyof IdentifierFields]: K extends keyof Model ? Model[K] : string;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
type If<
|
|
105
|
+
ConditionResult extends boolean,
|
|
106
|
+
IfTrueValue,
|
|
107
|
+
IfFalseValue = unknown,
|
|
108
|
+
> = ConditionResult extends true ? IfTrueValue : IfFalseValue;
|
|
109
|
+
|
|
110
|
+
type Not<T extends boolean> = T extends true ? false : true;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Models with composite PKs defined are expected to contain the model's pk, sk, and sortDirection properties in the `options` param
|
|
114
|
+
*
|
|
115
|
+
* @returns an object containing additional `options` properties for models with a composite primary index
|
|
116
|
+
*
|
|
117
|
+
*/
|
|
118
|
+
export type ListOptionsPkParams<
|
|
119
|
+
Bag extends Record<string, unknown>,
|
|
120
|
+
T extends ModelTypeParamShape,
|
|
121
|
+
> = T['identifier']['sk'] extends never
|
|
122
|
+
? unknown
|
|
123
|
+
: Prettify<Partial<IndexQueryInput<Bag, T['identifier']>>>;
|
|
124
|
+
|
|
125
|
+
type AuthFields<
|
|
126
|
+
SchemaMeta extends SchemaMetadata<any>,
|
|
127
|
+
Model extends ModelTypeParamShape,
|
|
128
|
+
> = (Model['authorization'][number] extends never
|
|
129
|
+
? SchemaMeta['authFields'] extends never
|
|
130
|
+
? object
|
|
131
|
+
: SchemaMeta['authFields']
|
|
132
|
+
: ImpliedAuthFields<Model['authorization'][number]> extends never
|
|
133
|
+
? object
|
|
134
|
+
: ImpliedAuthFields<Model['authorization'][number]>) &
|
|
135
|
+
ImpliedAuthFieldsFromFields<Model>;
|
|
136
|
+
|
|
137
|
+
type ImpliedAuthFieldsFromFields<T> = UnionToIntersection<
|
|
138
|
+
T extends ModelTypeParamShape
|
|
139
|
+
? T['fields'][keyof T['fields']] extends
|
|
140
|
+
| ModelField<any, any, infer Auth>
|
|
141
|
+
| ModelRelationalField<any, any, any, infer Auth>
|
|
142
|
+
| RefType<any, any, infer Auth>
|
|
143
|
+
? Auth extends Authorization<any, any, any>
|
|
144
|
+
? ImpliedAuthFields<Auth>
|
|
145
|
+
: object
|
|
146
|
+
: object
|
|
147
|
+
: object
|
|
148
|
+
>;
|
|
149
|
+
|
|
150
|
+
type NestedTypes<
|
|
151
|
+
Bag extends Record<string, unknown>,
|
|
152
|
+
T extends ModelTypeParamShape,
|
|
153
|
+
> = {
|
|
154
|
+
[K in keyof T['fields'] as T['fields'][K] extends
|
|
155
|
+
| EnumType
|
|
156
|
+
| CustomType<CustomTypeParamShape>
|
|
157
|
+
? K
|
|
158
|
+
: never]: K extends keyof Bag
|
|
159
|
+
? {
|
|
160
|
+
// A little hackier than I'd like here.
|
|
161
|
+
// Ideally, adapt ClientEnum and ClientCustomType to work with us here instead.
|
|
162
|
+
__entityType: T['fields'][K] extends EnumType ? 'enum' : 'customType';
|
|
163
|
+
type: Exclude<Bag[K], null | undefined>;
|
|
164
|
+
}
|
|
165
|
+
: never;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
type IndexQueryMethodsFromIR<
|
|
169
|
+
Bag extends Record<string, unknown>,
|
|
170
|
+
Indexes,
|
|
171
|
+
ModelName extends string,
|
|
172
|
+
Res = unknown, // defaulting `unknown` because it gets absorbed in an intersection, e.g. `{a: 1} & unknown` => `{a: 1}`
|
|
173
|
+
> = Indexes extends [
|
|
174
|
+
infer A extends SecondaryIndexIrShape,
|
|
175
|
+
...infer B extends SecondaryIndexIrShape[],
|
|
176
|
+
]
|
|
177
|
+
? IndexQueryMethodsFromIR<
|
|
178
|
+
Bag,
|
|
179
|
+
B,
|
|
180
|
+
ModelName,
|
|
181
|
+
IndexQueryMethodSignature<Bag, A, ModelName> & Res
|
|
182
|
+
>
|
|
183
|
+
: Res;
|
|
184
|
+
|
|
185
|
+
type IndexQueryMethodSignature<
|
|
186
|
+
Bag extends Record<string, unknown>,
|
|
187
|
+
Idx extends SecondaryIndexIrShape,
|
|
188
|
+
ModelName extends string,
|
|
189
|
+
> = Record<
|
|
190
|
+
IsEmptyStringOrNever<Idx['queryField']> extends false
|
|
191
|
+
? Idx['queryField']
|
|
192
|
+
: `list${ModelName}By${Idx['defaultQueryFieldSuffix']}`,
|
|
193
|
+
{
|
|
194
|
+
input: IndexQueryInput<Bag, Idx>;
|
|
195
|
+
}
|
|
196
|
+
>;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Accepts a PrimaryIndexIr or SecondaryIndexIr and returns resolved parameters
|
|
200
|
+
*
|
|
201
|
+
* TODO: Get rid of the `deferredRefResolvingPrefix` reference hack.
|
|
202
|
+
* Instead, just dereference refs as usual?
|
|
203
|
+
*/
|
|
204
|
+
export type IndexQueryInput<
|
|
205
|
+
Bag extends Record<string, unknown>,
|
|
206
|
+
Idx extends PrimaryIndexIrShape,
|
|
207
|
+
> = {
|
|
208
|
+
[PKField in keyof Idx['pk']]: Idx['pk'][PKField] extends `${deferredRefResolvingPrefix}${infer R}`
|
|
209
|
+
? 'type' extends keyof Bag[R]
|
|
210
|
+
? Bag[R]['type']
|
|
211
|
+
: never
|
|
212
|
+
: Idx['pk'][PKField];
|
|
213
|
+
} & (Idx['compositeSk'] extends never
|
|
214
|
+
? {
|
|
215
|
+
[SKField in keyof Idx['sk']]+?: number extends Idx['sk'][SKField]
|
|
216
|
+
? NumericFilter
|
|
217
|
+
: Idx['sk'][SKField] extends `${deferredRefResolvingPrefix}${infer R}`
|
|
218
|
+
? 'type' extends keyof Bag[R]
|
|
219
|
+
? Bag[R]['type'] extends string
|
|
220
|
+
? StringFilter<Bag[R]['type']>
|
|
221
|
+
: never
|
|
222
|
+
: never
|
|
223
|
+
: StringFilter<Idx['sk'][SKField] & string>;
|
|
224
|
+
}
|
|
225
|
+
: {
|
|
226
|
+
[CompositeSk in Idx['compositeSk']]+?: ModelPrimaryCompositeKeyInput<{
|
|
227
|
+
[SKField in keyof Idx['sk']]: Idx['sk'][SKField] extends `${deferredRefResolvingPrefix}${infer _R}`
|
|
228
|
+
? string
|
|
229
|
+
: Idx['sk'][SKField];
|
|
230
|
+
}>;
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
*
|
|
235
|
+
* TEMP
|
|
236
|
+
* ---++---
|
|
237
|
+
* ||
|
|
238
|
+
* ||
|
|
239
|
+
* \^^/
|
|
240
|
+
* \/
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* All required fields and relational fields, exclude readonly fields
|
|
245
|
+
*/
|
|
246
|
+
type MutationInput<
|
|
247
|
+
Model extends ClientModel<any, any, any, any, any>,
|
|
248
|
+
WritableFields = Pick<Model['type'], WritableKeys<Model['type']>>,
|
|
249
|
+
> = WithNullablesAsOptionalRecursively<{
|
|
250
|
+
[Prop in keyof WritableFields as WritableFields[Prop] extends (
|
|
251
|
+
...args: any
|
|
252
|
+
) => any
|
|
253
|
+
? never
|
|
254
|
+
: Prop]: WritableFields[Prop];
|
|
255
|
+
}>;
|
|
256
|
+
|
|
257
|
+
type IfEquals<X, Y, A = X, B = never> =
|
|
258
|
+
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B;
|
|
259
|
+
|
|
260
|
+
// Excludes readonly fields from Record type
|
|
261
|
+
type WritableKeys<T> = {
|
|
262
|
+
[P in keyof T]-?: IfEquals<
|
|
263
|
+
{ [Q in P]: T[P] },
|
|
264
|
+
{ -readonly [Q in P]: T[P] },
|
|
265
|
+
P
|
|
266
|
+
>;
|
|
267
|
+
}[keyof T];
|
|
268
|
+
|
|
269
|
+
type MinusReadonly<T> = {
|
|
270
|
+
-readonly [K in keyof T]: T[K];
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
type WithNullablesAsOptionalRecursively<T> = T extends
|
|
274
|
+
| Array<any>
|
|
275
|
+
| ((...args: any) => any)
|
|
276
|
+
? T
|
|
277
|
+
: T extends object
|
|
278
|
+
? {
|
|
279
|
+
[K in keyof T as null extends T[K]
|
|
280
|
+
? K
|
|
281
|
+
: never]+?: WithNullablesAsOptionalRecursively<T[K]>;
|
|
282
|
+
} & {
|
|
283
|
+
[K in keyof T as null extends T[K]
|
|
284
|
+
? never
|
|
285
|
+
: K]: WithNullablesAsOptionalRecursively<T[K]>;
|
|
286
|
+
}
|
|
287
|
+
: T;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* All identifiers and fields used to create a model
|
|
291
|
+
*/
|
|
292
|
+
type CreateModelInput<Model extends ClientModel<any, any, any, any, any>> =
|
|
293
|
+
Equal<MinusReadonly<Model['identifier']>, { id: string }> extends true
|
|
294
|
+
? Partial<MinusReadonly<Model['identifier']>> &
|
|
295
|
+
Omit<MutationInput<Model>, 'id'>
|
|
296
|
+
: MutationInput<Model>;
|
|
297
|
+
|
|
298
|
+
type UpdateModelInput<Model extends ClientModel<any, any, any, any, any>> =
|
|
299
|
+
MinusReadonly<Model['identifier']> & Partial<MutationInput<Model>>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ClientCustomOperation } from './ClientCustomOperations';
|
|
2
|
+
export { ClientEnum } from './ClientEnum';
|
|
3
|
+
export { ClientCustomType } from './ClientCustomType';
|
|
4
|
+
export { ClientModel } from './ClientModel';
|
|
5
|
+
export { ClientSchemaProperty } from './ClientSchemaProperty';
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { __modelMeta__ } from '../runtime/client';
|
|
2
|
+
import type {
|
|
3
|
+
BaseSchema,
|
|
4
|
+
CustomOperation,
|
|
5
|
+
CustomType,
|
|
6
|
+
EnumType,
|
|
7
|
+
GenericModelSchema,
|
|
8
|
+
ModelSchemaContents,
|
|
9
|
+
ModelType,
|
|
10
|
+
} from '../ModelSchema';
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
ClientCustomOperation,
|
|
14
|
+
ClientCustomType,
|
|
15
|
+
ClientEnum,
|
|
16
|
+
ClientModel,
|
|
17
|
+
} from './Core';
|
|
18
|
+
import type {
|
|
19
|
+
CombinedModelSchema,
|
|
20
|
+
CombinedSchemaIndexesUnion,
|
|
21
|
+
} from '../CombineSchema';
|
|
22
|
+
import type { SchemaMetadata } from './utilities/SchemaMetadata';
|
|
23
|
+
import type { Brand, Select, SpreadTuple } from '../util';
|
|
24
|
+
|
|
25
|
+
export type ClientSchema<
|
|
26
|
+
Schema extends GenericModelSchema<any> | CombinedModelSchema<any>,
|
|
27
|
+
> =
|
|
28
|
+
Schema extends GenericModelSchema<any>
|
|
29
|
+
? InternalClientSchema<Schema>
|
|
30
|
+
: Schema extends CombinedModelSchema<any>
|
|
31
|
+
? InternalCombinedSchema<Schema>
|
|
32
|
+
: never;
|
|
33
|
+
|
|
34
|
+
type InternalClientSchema<
|
|
35
|
+
CustomerSchema extends ModelSchemaContents | BaseSchema<any, any>,
|
|
36
|
+
Metadata extends SchemaMetadata<any> = never,
|
|
37
|
+
IsRDS extends boolean = never,
|
|
38
|
+
> = CustomerSchema extends ModelSchemaContents
|
|
39
|
+
? {
|
|
40
|
+
[K in keyof CustomerSchema as K extends string
|
|
41
|
+
? K
|
|
42
|
+
: never]: K extends string
|
|
43
|
+
? ClientSchemaProperty<CustomerSchema, Metadata, IsRDS, K>
|
|
44
|
+
: never;
|
|
45
|
+
}
|
|
46
|
+
: CustomerSchema extends BaseSchema<any, any>
|
|
47
|
+
? InternalClientSchema<
|
|
48
|
+
CustomerSchema['data']['types'],
|
|
49
|
+
SchemaMetadata<CustomerSchema>,
|
|
50
|
+
CustomerSchema extends Brand<'RDSSchema'> ? true : false
|
|
51
|
+
>
|
|
52
|
+
: never;
|
|
53
|
+
|
|
54
|
+
type ClientSchemaProperty<
|
|
55
|
+
T extends ModelSchemaContents,
|
|
56
|
+
Metadata extends SchemaMetadata<any>,
|
|
57
|
+
IsRDS extends boolean,
|
|
58
|
+
K extends keyof T & string,
|
|
59
|
+
> =
|
|
60
|
+
T[K] extends Brand<'enum'>
|
|
61
|
+
? RemapEnum<T, T[K]>
|
|
62
|
+
: T[K] extends Brand<'customType'>
|
|
63
|
+
? RemapCustomType<T, Metadata, IsRDS, T[K]>
|
|
64
|
+
: T[K] extends Brand<
|
|
65
|
+
| 'queryCustomOperation'
|
|
66
|
+
| 'mutationCustomOperation'
|
|
67
|
+
| 'subscriptionCustomOperation'
|
|
68
|
+
>
|
|
69
|
+
? RemapCustomOperation<T, Metadata, IsRDS, T[K]>
|
|
70
|
+
: T[K] extends Brand<'modelType'>
|
|
71
|
+
? RemapModel<T, Metadata, IsRDS, T[K], K>
|
|
72
|
+
: never;
|
|
73
|
+
|
|
74
|
+
type RemapEnum<_T extends ModelSchemaContents, E> =
|
|
75
|
+
E extends EnumType<infer values> ? ClientEnum<values> : never;
|
|
76
|
+
|
|
77
|
+
type RemapCustomType<
|
|
78
|
+
T extends ModelSchemaContents,
|
|
79
|
+
Metadata extends SchemaMetadata<any>,
|
|
80
|
+
IsRDS extends boolean,
|
|
81
|
+
E,
|
|
82
|
+
> =
|
|
83
|
+
E extends CustomType<infer CT>
|
|
84
|
+
? ClientCustomType<InternalClientSchema<T, Metadata, IsRDS>, CT>
|
|
85
|
+
: never;
|
|
86
|
+
|
|
87
|
+
type RemapCustomOperation<
|
|
88
|
+
T extends ModelSchemaContents,
|
|
89
|
+
Metadata extends SchemaMetadata<any>,
|
|
90
|
+
IsRDS extends boolean,
|
|
91
|
+
E,
|
|
92
|
+
> =
|
|
93
|
+
E extends CustomOperation<infer CO, any>
|
|
94
|
+
? ClientCustomOperation<InternalClientSchema<T, Metadata, IsRDS>, CO>
|
|
95
|
+
: never;
|
|
96
|
+
|
|
97
|
+
type RemapModel<
|
|
98
|
+
T extends ModelSchemaContents,
|
|
99
|
+
Metadata extends SchemaMetadata<any>,
|
|
100
|
+
IsRDS extends boolean,
|
|
101
|
+
E,
|
|
102
|
+
K extends keyof T & string,
|
|
103
|
+
> =
|
|
104
|
+
E extends ModelType<infer MT, any>
|
|
105
|
+
? ClientModel<
|
|
106
|
+
InternalClientSchema<T, Metadata, IsRDS>,
|
|
107
|
+
Metadata,
|
|
108
|
+
IsRDS,
|
|
109
|
+
MT,
|
|
110
|
+
K
|
|
111
|
+
>
|
|
112
|
+
: never;
|
|
113
|
+
|
|
114
|
+
type GetInternalClientSchema<Schema> =
|
|
115
|
+
Schema extends GenericModelSchema<any> ? InternalClientSchema<Schema> : never;
|
|
116
|
+
|
|
117
|
+
type CombinedClientSchemas<
|
|
118
|
+
Schemas extends CombinedModelSchema<any>['schemas'],
|
|
119
|
+
> = {
|
|
120
|
+
[Index in keyof Schemas]: Index extends CombinedSchemaIndexesUnion
|
|
121
|
+
? GetInternalClientSchema<Schemas[Index]>
|
|
122
|
+
: never;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Types for unwrapping and combining generic type args into client-consumable types
|
|
127
|
+
* for multiple schemas
|
|
128
|
+
*
|
|
129
|
+
* @typeParam Combined - A container of multiple schemas
|
|
130
|
+
*
|
|
131
|
+
* @internal @typeParam ClientSchemas - The tuple of client schemas to combine
|
|
132
|
+
*/
|
|
133
|
+
type InternalCombinedSchema<
|
|
134
|
+
Combined extends CombinedModelSchema<any>,
|
|
135
|
+
ClientSchemas extends [...any] = CombinedClientSchemas<Combined['schemas']>,
|
|
136
|
+
> = SpreadTuple<{
|
|
137
|
+
[I in keyof ClientSchemas]: I extends CombinedSchemaIndexesUnion
|
|
138
|
+
? Omit<ClientSchemas[I], typeof __modelMeta__>
|
|
139
|
+
: never;
|
|
140
|
+
}>;
|
|
141
|
+
|
|
142
|
+
export type ClientSchemaByEntityTypeBaseShape = {
|
|
143
|
+
enums: Record<string, ClientEnum<any>>;
|
|
144
|
+
customTypes: Record<string, ClientCustomType<any, any>>;
|
|
145
|
+
models: Record<string, ClientModel<any, any, any, any, any>>;
|
|
146
|
+
queries: Record<string, ClientCustomOperation<any, any>>;
|
|
147
|
+
mutations: Record<string, ClientCustomOperation<any, any>>;
|
|
148
|
+
subscriptions: Record<string, ClientCustomOperation<any, any>>;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export type ClientSchemaByEntityType<T> = {
|
|
152
|
+
enums: Select<T, { __entityType: 'enum' }>;
|
|
153
|
+
customTypes: Select<T, { __entityType: 'customType' }>;
|
|
154
|
+
models: Select<T, { __entityType: 'model' }>;
|
|
155
|
+
queries: Select<T, { __entityType: 'customQuery' }>;
|
|
156
|
+
mutations: Select<T, { __entityType: 'customMutation' }>;
|
|
157
|
+
subscriptions: Select<T, { __entityType: 'customSubscription' }>;
|
|
158
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ClientSchemaByEntityTypeBaseShape } from '..';
|
|
2
|
+
import { UnionToIntersection } from '@aws-amplify/data-schema-types';
|
|
3
|
+
|
|
4
|
+
export type ExtractNestedTypes<T extends ClientSchemaByEntityTypeBaseShape> =
|
|
5
|
+
UnionToIntersection<
|
|
6
|
+
{
|
|
7
|
+
[ModelName in keyof T['models']]: ModelName extends string
|
|
8
|
+
? {
|
|
9
|
+
[TypeName in keyof T['models'][ModelName]['nestedTypes'] as TypeName extends string
|
|
10
|
+
? `${ModelName}${Capitalize<TypeName>}`
|
|
11
|
+
: never]: T['models'][ModelName]['nestedTypes'][TypeName];
|
|
12
|
+
}
|
|
13
|
+
: never;
|
|
14
|
+
}[keyof T['models']]
|
|
15
|
+
>;
|