@aws-amplify/data-schema 1.1.2 → 1.1.4
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/MappedTypes/{MapSecondaryIndexes.js → MapIndexes.js} +1 -1
- package/dist/cjs/MappedTypes/MapIndexes.js.map +1 -0
- package/dist/cjs/ModelSchema.js +1 -0
- package/dist/cjs/ModelSchema.js.map +1 -1
- package/dist/cjs/SchemaProcessor.js +4 -1
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/esm/Authorization.d.ts +2 -2
- package/dist/esm/MappedTypes/ImplicitFieldInjector.d.ts +15 -5
- package/dist/esm/MappedTypes/{MapSecondaryIndexes.d.ts → MapIndexes.d.ts} +6 -0
- package/dist/esm/MappedTypes/MapIndexes.mjs +2 -0
- package/dist/esm/MappedTypes/MapIndexes.mjs.map +1 -0
- package/dist/esm/MappedTypes/ModelMetadata.d.ts +12 -5
- package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +3 -2
- package/dist/esm/ModelSchema.mjs +1 -0
- package/dist/esm/ModelSchema.mjs.map +1 -1
- package/dist/esm/ModelType.d.ts +23 -25
- package/dist/esm/SchemaProcessor.mjs +4 -1
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/runtime/client/index.d.ts +26 -15
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/MappedTypes/ImplicitFieldInjector.ts +22 -14
- package/src/MappedTypes/{MapSecondaryIndexes.ts → MapIndexes.ts} +16 -0
- package/src/MappedTypes/ModelMetadata.ts +17 -12
- package/src/MappedTypes/ResolveFieldProperties.ts +3 -2
- package/src/ModelSchema.ts +2 -1
- package/src/ModelType.ts +46 -46
- package/src/SchemaProcessor.ts +6 -3
- package/src/runtime/client/index.ts +52 -25
- package/dist/cjs/MappedTypes/MapSecondaryIndexes.js.map +0 -1
- package/dist/esm/MappedTypes/MapSecondaryIndexes.mjs +0 -2
- package/dist/esm/MappedTypes/MapSecondaryIndexes.mjs.map +0 -1
|
@@ -1,38 +1,40 @@
|
|
|
1
|
+
import type { PrimaryIndexIrShape } from '../runtime/';
|
|
2
|
+
|
|
1
3
|
type DefaultIdentifierFields = {
|
|
2
4
|
// implicit `id` is readonly because it's managed by the resolver; explicit `id` is writable
|
|
3
5
|
readonly id: string;
|
|
4
6
|
};
|
|
5
7
|
|
|
8
|
+
type DefaultIdentifierType = { pk: { id: string } };
|
|
9
|
+
|
|
6
10
|
type DefaultTimestampFields = {
|
|
7
11
|
readonly createdAt: string;
|
|
8
12
|
readonly updatedAt: string;
|
|
9
13
|
};
|
|
10
14
|
|
|
11
|
-
type InitialImplicitFields<Identifier> =
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
type InitialImplicitFields<Identifier> =
|
|
16
|
+
Identifier extends DefaultIdentifierType
|
|
17
|
+
? DefaultIdentifierFields & DefaultTimestampFields
|
|
18
|
+
: DefaultTimestampFields;
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
21
|
* @returns true if a string union `ExplicitFieldNames` contains a given string `FieldName`
|
|
17
22
|
*/
|
|
18
|
-
type FieldExists<
|
|
19
|
-
ExplicitFieldNames extends
|
|
20
|
-
FieldName extends string,
|
|
21
|
-
> = Extract<ExplicitFieldNames, FieldName> extends never ? false : true;
|
|
23
|
+
type FieldExists<ExplicitFieldNames extends string, FieldName extends string> =
|
|
24
|
+
Extract<ExplicitFieldNames, FieldName> extends never ? false : true;
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* @returns union of explicitly defined field names for a model
|
|
25
28
|
*/
|
|
26
|
-
type GetModelFieldNames<FlatModel> =
|
|
27
|
-
? R
|
|
28
|
-
: never;
|
|
29
|
+
type GetModelFieldNames<FlatModel> =
|
|
30
|
+
FlatModel extends Record<infer R, any> ? R : never;
|
|
29
31
|
|
|
30
32
|
/**
|
|
31
33
|
* Generate Record type containing all implicit fields for a given model
|
|
32
34
|
*/
|
|
33
35
|
type ImplicitFields<
|
|
34
36
|
FlatModel,
|
|
35
|
-
Identifier,
|
|
37
|
+
Identifier extends PrimaryIndexIrShape,
|
|
36
38
|
ModelFieldNames = GetModelFieldNames<FlatModel>,
|
|
37
39
|
> = {
|
|
38
40
|
[ImplicitField in keyof InitialImplicitFields<Identifier> as FieldExists<
|
|
@@ -46,7 +48,10 @@ type ImplicitFields<
|
|
|
46
48
|
/**
|
|
47
49
|
* @returns intersection of explicit and implicit model fields
|
|
48
50
|
*/
|
|
49
|
-
type InjectDefaultFieldsForModel<
|
|
51
|
+
type InjectDefaultFieldsForModel<
|
|
52
|
+
FlatModel,
|
|
53
|
+
ModelIdentifier extends { identifier: PrimaryIndexIrShape },
|
|
54
|
+
> = FlatModel &
|
|
50
55
|
ImplicitFields<
|
|
51
56
|
FlatModel,
|
|
52
57
|
'identifier' extends keyof ModelIdentifier
|
|
@@ -61,9 +66,12 @@ type InjectDefaultFieldsForModel<FlatModel, ModelIdentifier> = FlatModel &
|
|
|
61
66
|
*
|
|
62
67
|
* @typeParam FlattenedSchema - resolved schema type (TODO: add detail/example/link to type)
|
|
63
68
|
*/
|
|
64
|
-
export type InjectImplicitModelFields<
|
|
69
|
+
export type InjectImplicitModelFields<
|
|
70
|
+
FlattenedSchema,
|
|
71
|
+
IdentifierMeta extends Record<string, { identifier: PrimaryIndexIrShape }>,
|
|
72
|
+
> = {
|
|
65
73
|
[ModelName in keyof FlattenedSchema]: InjectDefaultFieldsForModel<
|
|
66
74
|
FlattenedSchema[ModelName],
|
|
67
|
-
ModelName extends keyof IdentifierMeta ? IdentifierMeta[ModelName] :
|
|
75
|
+
ModelName extends keyof IdentifierMeta ? IdentifierMeta[ModelName] : never
|
|
68
76
|
>;
|
|
69
77
|
};
|
|
@@ -2,6 +2,22 @@ import { ModelIndexType } from '../ModelIndex';
|
|
|
2
2
|
|
|
3
3
|
type ModelIndexTypeShape = ModelIndexType<any, any, any, any, any>;
|
|
4
4
|
|
|
5
|
+
export type PrimaryIndexFieldsToIR<
|
|
6
|
+
IdxFields extends ReadonlyArray<string>,
|
|
7
|
+
ResolvedFields,
|
|
8
|
+
> = IdxFields extends readonly [infer PK, ...infer SK]
|
|
9
|
+
? {
|
|
10
|
+
pk: PK extends keyof ResolvedFields
|
|
11
|
+
? {
|
|
12
|
+
[Key in PK]: Exclude<ResolvedFields[PK], null> & (string | number);
|
|
13
|
+
}
|
|
14
|
+
: never;
|
|
15
|
+
sk: unknown extends SK
|
|
16
|
+
? never
|
|
17
|
+
: ResolvedSortKeyFields<SK, ResolvedFields>;
|
|
18
|
+
}
|
|
19
|
+
: never;
|
|
20
|
+
|
|
5
21
|
/**
|
|
6
22
|
* Maps array of ModelIndexType to SecondaryIndexIrShape (defined in in data-schema-types)
|
|
7
23
|
* */
|
|
@@ -2,23 +2,21 @@ import {
|
|
|
2
2
|
type UnionToIntersection,
|
|
3
3
|
type ExcludeEmpty,
|
|
4
4
|
} from '@aws-amplify/data-schema-types';
|
|
5
|
-
import { __modelMeta__ } from '../runtime/
|
|
5
|
+
import { __modelMeta__, type PrimaryIndexIrShape } from '../runtime/';
|
|
6
6
|
import type { ModelType } from '../ModelType';
|
|
7
7
|
import type { ModelRelationalFieldParamShape } from '../ModelRelationalField';
|
|
8
8
|
|
|
9
9
|
export type ModelIdentifier<T> = {
|
|
10
10
|
[Property in keyof T]: T[Property] extends ModelType<infer R, any>
|
|
11
|
-
?
|
|
12
|
-
R['identifier']
|
|
13
|
-
? { identifier: R['identifier'][number] }
|
|
11
|
+
? R['identifier'] extends PrimaryIndexIrShape
|
|
12
|
+
? { identifier: R['identifier'] }
|
|
14
13
|
: never
|
|
15
14
|
: never;
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
export type ModelSecondaryIndexes<T> = {
|
|
19
18
|
[Property in keyof T]: T[Property] extends ModelType<infer R, any>
|
|
20
|
-
?
|
|
21
|
-
R['secondaryIndexes'] extends any[]
|
|
19
|
+
? R['secondaryIndexes'] extends any[]
|
|
22
20
|
? { secondaryIndexes: R['secondaryIndexes'] }
|
|
23
21
|
: never
|
|
24
22
|
: never;
|
|
@@ -27,7 +25,7 @@ export type ModelSecondaryIndexes<T> = {
|
|
|
27
25
|
export type RelationalMetadata<
|
|
28
26
|
ResolvedSchema,
|
|
29
27
|
ResolvedFields extends Record<string, unknown>,
|
|
30
|
-
IdentifierMeta extends Record<string,
|
|
28
|
+
IdentifierMeta extends Record<string, { identifier: PrimaryIndexIrShape }>,
|
|
31
29
|
> = UnionToIntersection<
|
|
32
30
|
ExcludeEmpty<
|
|
33
31
|
{
|
|
@@ -77,11 +75,18 @@ export type RelationalMetadata<
|
|
|
77
75
|
>
|
|
78
76
|
>;
|
|
79
77
|
|
|
80
|
-
type ExtractModelIdentifier<
|
|
81
|
-
ModelName
|
|
78
|
+
type ExtractModelIdentifier<
|
|
79
|
+
ModelName,
|
|
80
|
+
IdentifierMeta extends Record<string, { identifier: PrimaryIndexIrShape }>,
|
|
81
|
+
> = ModelName extends keyof IdentifierMeta ? IdentifierMeta[ModelName] : never;
|
|
82
82
|
|
|
83
83
|
type NormalizeInputFields<
|
|
84
84
|
ModelFields,
|
|
85
|
-
IdentifierMeta extends
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
IdentifierMeta extends { identifier: PrimaryIndexIrShape },
|
|
86
|
+
IdFields extends keyof ModelFields =
|
|
87
|
+
| (keyof IdentifierMeta['identifier']['pk'] & keyof ModelFields)
|
|
88
|
+
| (IdentifierMeta['identifier']['sk'] extends never
|
|
89
|
+
? never
|
|
90
|
+
: keyof IdentifierMeta['identifier']['sk'] & keyof ModelFields),
|
|
91
|
+
> = Partial<Omit<ModelFields, IdFields>> &
|
|
92
|
+
Required<Pick<ModelFields, IdFields>>;
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
ModelRelationalField,
|
|
11
11
|
ModelRelationalFieldParamShape,
|
|
12
12
|
} from '../ModelRelationalField';
|
|
13
|
+
import type { PrimaryIndexIrShape } from '../runtime/';
|
|
13
14
|
|
|
14
15
|
import type { ResolveSchema, SchemaTypes } from './ResolveSchema';
|
|
15
16
|
import type { InjectImplicitModelFields } from './ImplicitFieldInjector';
|
|
@@ -31,7 +32,7 @@ export type ResolveFieldProperties<
|
|
|
31
32
|
ResolvedSchema = ResolveSchema<Schema>,
|
|
32
33
|
IdentifierMeta extends Record<
|
|
33
34
|
string,
|
|
34
|
-
{ identifier:
|
|
35
|
+
{ identifier: PrimaryIndexIrShape }
|
|
35
36
|
> = ModelIdentifier<SchemaTypes<Schema>>,
|
|
36
37
|
FieldsWithInjectedImplicitFields = InjectImplicitModelFields<
|
|
37
38
|
ResolvedSchema,
|
|
@@ -56,7 +57,7 @@ export type ResolveStaticFieldProperties<
|
|
|
56
57
|
ResolvedSchema = ResolveSchema<Schema>,
|
|
57
58
|
FieldsWithInjectedImplicitFields = InjectImplicitModelFields<
|
|
58
59
|
ResolvedSchema & ImplicitModelsSchema,
|
|
59
|
-
|
|
60
|
+
never
|
|
60
61
|
>,
|
|
61
62
|
FieldsWithRelationships = ResolveModelsRelationalAndRefFields<
|
|
62
63
|
FieldsWithInjectedImplicitFields,
|
package/src/ModelSchema.ts
CHANGED
package/src/ModelType.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from '
|
|
5
|
-
import { Brand, brand } from './util';
|
|
6
|
-
import { ModelField, InternalField } from './ModelField';
|
|
1
|
+
import type { SetTypeSubArg } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import type { PrimaryIndexIrShape, SecondaryIndexIrShape } from './runtime';
|
|
3
|
+
import { type Brand, brand } from './util';
|
|
4
|
+
import type { ModelField, InternalField } from './ModelField';
|
|
7
5
|
import type {
|
|
8
6
|
ModelRelationalField,
|
|
9
7
|
InternalRelationalField,
|
|
10
8
|
ModelRelationalFieldParamShape,
|
|
11
9
|
} from './ModelRelationalField';
|
|
12
|
-
import { AllowModifier, Authorization, allow } from './Authorization';
|
|
13
|
-
import { RefType, RefTypeParamShape } from './RefType';
|
|
14
|
-
import { EnumType, EnumTypeParamShape } from './EnumType';
|
|
15
|
-
import { CustomType, CustomTypeParamShape } from './CustomType';
|
|
10
|
+
import { type AllowModifier, type Authorization, allow } from './Authorization';
|
|
11
|
+
import type { RefType, RefTypeParamShape } from './RefType';
|
|
12
|
+
import type { EnumType, EnumTypeParamShape } from './EnumType';
|
|
13
|
+
import type { CustomType, CustomTypeParamShape } from './CustomType';
|
|
16
14
|
import {
|
|
17
|
-
ModelIndexType,
|
|
18
|
-
InternalModelIndexType,
|
|
15
|
+
type ModelIndexType,
|
|
16
|
+
type InternalModelIndexType,
|
|
19
17
|
modelIndex,
|
|
20
18
|
} from './ModelIndex';
|
|
21
|
-
import {
|
|
19
|
+
import type {
|
|
20
|
+
PrimaryIndexFieldsToIR,
|
|
21
|
+
SecondaryIndexToIR,
|
|
22
|
+
} from './MappedTypes/MapIndexes';
|
|
22
23
|
|
|
23
24
|
const brandName = 'modelType';
|
|
24
25
|
export type deferredRefResolvingPrefix = 'deferredRefResolving:';
|
|
@@ -39,21 +40,22 @@ type InternalModelFields = Record<
|
|
|
39
40
|
|
|
40
41
|
type ModelData = {
|
|
41
42
|
fields: ModelFields;
|
|
42
|
-
identifier: string
|
|
43
|
+
identifier: ReadonlyArray<string>;
|
|
43
44
|
secondaryIndexes: ReadonlyArray<ModelIndexType<any, any, any, any, any>>;
|
|
44
45
|
authorization: Authorization<any, any, any>[];
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
type InternalModelData = ModelData & {
|
|
48
49
|
fields: InternalModelFields;
|
|
49
|
-
identifier: string
|
|
50
|
+
identifier: ReadonlyArray<string>;
|
|
50
51
|
secondaryIndexes: ReadonlyArray<InternalModelIndexType>;
|
|
51
52
|
authorization: Authorization<any, any, any>[];
|
|
53
|
+
originalName?: string;
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
export type ModelTypeParamShape = {
|
|
55
57
|
fields: ModelFields;
|
|
56
|
-
identifier:
|
|
58
|
+
identifier: PrimaryIndexIrShape;
|
|
57
59
|
secondaryIndexes: ReadonlyArray<SecondaryIndexIrShape>;
|
|
58
60
|
authorization: Authorization<any, any, any>[];
|
|
59
61
|
};
|
|
@@ -72,20 +74,27 @@ export type ModelTypeParamShape = {
|
|
|
72
74
|
* indicator string, and resolve its corresponding type later in
|
|
73
75
|
* packages/data-schema/src/runtime/client/index.ts
|
|
74
76
|
*/
|
|
75
|
-
type ExtractSecondaryIndexIRFields<
|
|
77
|
+
export type ExtractSecondaryIndexIRFields<
|
|
78
|
+
T extends ModelTypeParamShape,
|
|
79
|
+
RequiredOnly extends boolean = false,
|
|
80
|
+
> = {
|
|
76
81
|
[FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends ModelField<
|
|
77
82
|
infer R,
|
|
78
83
|
any,
|
|
79
84
|
any
|
|
80
85
|
>
|
|
81
86
|
? NonNullable<R> extends string | number
|
|
82
|
-
?
|
|
87
|
+
? RequiredOnly extends false
|
|
88
|
+
? FieldProp
|
|
89
|
+
: null extends R
|
|
90
|
+
? never
|
|
91
|
+
: FieldProp
|
|
83
92
|
: never
|
|
84
|
-
: T['fields'][FieldProp] extends
|
|
93
|
+
: T['fields'][FieldProp] extends
|
|
94
|
+
| EnumType<EnumTypeParamShape>
|
|
95
|
+
| RefType<RefTypeParamShape, any, any>
|
|
85
96
|
? FieldProp
|
|
86
|
-
: T['fields'][FieldProp] extends
|
|
87
|
-
? FieldProp
|
|
88
|
-
: never]: T['fields'][FieldProp] extends ModelField<infer R, any, any>
|
|
97
|
+
: never]: T['fields'][FieldProp] extends ModelField<infer R, any, any>
|
|
89
98
|
? R
|
|
90
99
|
: T['fields'][FieldProp] extends EnumType<infer R>
|
|
91
100
|
? R['values'][number]
|
|
@@ -106,26 +115,6 @@ type ExtractType<T extends ModelTypeParamShape> = {
|
|
|
106
115
|
: never;
|
|
107
116
|
};
|
|
108
117
|
|
|
109
|
-
type GetRequiredFields<T> = {
|
|
110
|
-
[FieldProp in keyof T as T[FieldProp] extends NonNullable<T[FieldProp]>
|
|
111
|
-
? FieldProp
|
|
112
|
-
: never]: T[FieldProp];
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
type IdentifierMap<T extends ModelTypeParamShape> = GetRequiredFields<
|
|
116
|
-
ExtractType<T>
|
|
117
|
-
>;
|
|
118
|
-
|
|
119
|
-
// extracts model fields that CAN BE used as identifiers (scalar, non-nullable fields)
|
|
120
|
-
// TODO: make this also filter out all non-scalars e.g., model fields and custom types
|
|
121
|
-
type IdentifierFields<T extends ModelTypeParamShape> = keyof IdentifierMap<T> &
|
|
122
|
-
string;
|
|
123
|
-
|
|
124
|
-
type IdentifierType<
|
|
125
|
-
T extends ModelTypeParamShape,
|
|
126
|
-
Fields extends string = IdentifierFields<T>,
|
|
127
|
-
> = Array<Fields>;
|
|
128
|
-
|
|
129
118
|
/**
|
|
130
119
|
* For a given ModelTypeParamShape, produces a map of Authorization rules
|
|
131
120
|
* that would *conflict* with the given type.
|
|
@@ -213,9 +202,20 @@ export type ModelType<
|
|
|
213
202
|
K extends keyof ModelType<T> = never,
|
|
214
203
|
> = Omit<
|
|
215
204
|
{
|
|
216
|
-
identifier<
|
|
205
|
+
identifier<
|
|
206
|
+
PrimaryIndexFields = ExtractSecondaryIndexIRFields<T, true>,
|
|
207
|
+
PrimaryIndexPool extends string = keyof PrimaryIndexFields & string,
|
|
208
|
+
const ID extends ReadonlyArray<PrimaryIndexPool> = readonly [],
|
|
209
|
+
const PrimaryIndexIR extends PrimaryIndexIrShape = PrimaryIndexFieldsToIR<
|
|
210
|
+
ID,
|
|
211
|
+
PrimaryIndexFields
|
|
212
|
+
>,
|
|
213
|
+
>(
|
|
217
214
|
identifier: ID,
|
|
218
|
-
): ModelType<
|
|
215
|
+
): ModelType<
|
|
216
|
+
SetTypeSubArg<T, 'identifier', PrimaryIndexIR>,
|
|
217
|
+
K | 'identifier'
|
|
218
|
+
>;
|
|
219
219
|
secondaryIndexes<
|
|
220
220
|
const SecondaryIndexFields = ExtractSecondaryIndexIRFields<T>,
|
|
221
221
|
const SecondaryIndexPKPool extends string = keyof SecondaryIndexFields &
|
|
@@ -271,7 +271,7 @@ export type SchemaModelType<
|
|
|
271
271
|
IsRDS extends boolean = false,
|
|
272
272
|
> = IsRDS extends true
|
|
273
273
|
? T & {
|
|
274
|
-
|
|
274
|
+
relationships<
|
|
275
275
|
Param extends Record<
|
|
276
276
|
string,
|
|
277
277
|
ModelRelationalField<any, string, any, any>
|
|
@@ -367,7 +367,7 @@ export function model<T extends ModelFields>(
|
|
|
367
367
|
fields: T,
|
|
368
368
|
): ModelType<{
|
|
369
369
|
fields: T;
|
|
370
|
-
identifier:
|
|
370
|
+
identifier: { pk: { id: string }; sk: never };
|
|
371
371
|
secondaryIndexes: [];
|
|
372
372
|
authorization: [];
|
|
373
373
|
}> {
|
package/src/SchemaProcessor.ts
CHANGED
|
@@ -133,7 +133,7 @@ function isRefField(
|
|
|
133
133
|
|
|
134
134
|
function scalarFieldToGql(
|
|
135
135
|
fieldDef: ScalarFieldDef,
|
|
136
|
-
identifier?: string[],
|
|
136
|
+
identifier?: readonly string[],
|
|
137
137
|
secondaryIndexes: string[] = [],
|
|
138
138
|
) {
|
|
139
139
|
const {
|
|
@@ -825,7 +825,7 @@ function processFields(
|
|
|
825
825
|
fields: Record<string, any>,
|
|
826
826
|
impliedFields: Record<string, any>,
|
|
827
827
|
fieldLevelAuthRules: Record<string, string | null>,
|
|
828
|
-
identifier?: string[],
|
|
828
|
+
identifier?: readonly string[],
|
|
829
829
|
partitionKey?: string,
|
|
830
830
|
secondaryIndexes: TransformedSecondaryIndexes = {},
|
|
831
831
|
) {
|
|
@@ -1329,13 +1329,16 @@ const schemaPreprocessor = (
|
|
|
1329
1329
|
topLevelTypes.push(...implicitTypes);
|
|
1330
1330
|
|
|
1331
1331
|
const joined = gqlFields.join('\n ');
|
|
1332
|
+
const refersToString = typeDef.data.originalName
|
|
1333
|
+
? ` @refersTo(name: "${typeDef.data.originalName}")`
|
|
1334
|
+
: '';
|
|
1332
1335
|
// TODO: update @model(timestamps: null) once a longer term solution gets
|
|
1333
1336
|
// determined.
|
|
1334
1337
|
//
|
|
1335
1338
|
// Context: SQL schema should not be automatically inserted with timestamp fields,
|
|
1336
1339
|
// passing (timestamps: null) to @model to suppress this behavior as a short
|
|
1337
1340
|
// term solution.
|
|
1338
|
-
const model = `type ${typeName} @model(timestamps: null) ${authString}\n{\n ${joined}\n}`;
|
|
1341
|
+
const model = `type ${typeName} @model(timestamps: null) ${authString}${refersToString}\n{\n ${joined}\n}`;
|
|
1339
1342
|
gqlModels.push(model);
|
|
1340
1343
|
} else {
|
|
1341
1344
|
const fields = typeDef.data.fields as Record<
|
|
@@ -271,9 +271,12 @@ export type SelectionSet<
|
|
|
271
271
|
// #endregion
|
|
272
272
|
|
|
273
273
|
// #region Input mapped types
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
|
|
275
|
+
export type ModelIdentifier<ModelMeta extends ModelMetaShape> =
|
|
276
|
+
ModelMeta['identifier']['pk'] &
|
|
277
|
+
(ModelMeta['identifier']['sk'] extends never
|
|
278
|
+
? unknown // unknown collapses in an intersection
|
|
279
|
+
: ModelMeta['identifier']['sk']);
|
|
277
280
|
|
|
278
281
|
type IfEquals<X, Y, A = X, B = never> =
|
|
279
282
|
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B;
|
|
@@ -306,7 +309,7 @@ type MutationInput<
|
|
|
306
309
|
*/
|
|
307
310
|
type CreateModelInput<
|
|
308
311
|
Model extends Record<string, unknown>,
|
|
309
|
-
ModelMeta extends
|
|
312
|
+
ModelMeta extends ModelMetaShape,
|
|
310
313
|
> =
|
|
311
314
|
Equal<ModelIdentifier<ModelMeta>, { id: string }> extends true
|
|
312
315
|
? Partial<ModelIdentifier<ModelMeta>> & Omit<MutationInput<Model>, 'id'>
|
|
@@ -492,7 +495,7 @@ export type ModelSortDirection = 'ASC' | 'DESC';
|
|
|
492
495
|
|
|
493
496
|
type ModelMetaShape = {
|
|
494
497
|
secondaryIndexes: SecondaryIndexIrShape[];
|
|
495
|
-
identifier:
|
|
498
|
+
identifier: PrimaryIndexIrShape;
|
|
496
499
|
};
|
|
497
500
|
|
|
498
501
|
// TODO: remove export. added for debugging.
|
|
@@ -542,9 +545,8 @@ export type ModelTypesClient<
|
|
|
542
545
|
},
|
|
543
546
|
): SingularReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
544
547
|
list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
|
|
545
|
-
options?:
|
|
548
|
+
options?: ListPkOptions<ModelMeta, Enums> & {
|
|
546
549
|
filter?: ModelFilter<Model>;
|
|
547
|
-
sortDirection?: ModelSortDirection;
|
|
548
550
|
limit?: number;
|
|
549
551
|
nextToken?: string | null;
|
|
550
552
|
selectionSet?: SelectionSet;
|
|
@@ -644,7 +646,7 @@ type ModelTypesSSRCookies<
|
|
|
644
646
|
},
|
|
645
647
|
): SingularReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
646
648
|
list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
|
|
647
|
-
options?:
|
|
649
|
+
options?: ListPkOptions<ModelMeta, Enums> & {
|
|
648
650
|
filter?: ModelFilter<Model>;
|
|
649
651
|
sortDirection?: ModelSortDirection;
|
|
650
652
|
limit?: number;
|
|
@@ -709,7 +711,7 @@ type ModelTypesSSRRequest<
|
|
|
709
711
|
): SingularReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
710
712
|
list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
|
|
711
713
|
contextSpec: any,
|
|
712
|
-
options?:
|
|
714
|
+
options?: ListPkOptions<ModelMeta, Enums> & {
|
|
713
715
|
filter?: ModelFilter<Model>;
|
|
714
716
|
sortDirection?: ModelSortDirection;
|
|
715
717
|
limit?: number;
|
|
@@ -883,14 +885,20 @@ export type CustomHeaders =
|
|
|
883
885
|
| ((requestOptions?: RequestOptions) => Promise<Record<string, string>>);
|
|
884
886
|
|
|
885
887
|
/**
|
|
886
|
-
*
|
|
888
|
+
* PrimaryIndex field types and query methods
|
|
889
|
+
*/
|
|
890
|
+
export interface PrimaryIndexIrShape {
|
|
891
|
+
pk: { [key: string]: string | number };
|
|
892
|
+
sk: { [key: string]: string | number } | never;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* SecondaryIndex field types and query methods
|
|
887
897
|
*/
|
|
888
|
-
export
|
|
898
|
+
export interface SecondaryIndexIrShape extends PrimaryIndexIrShape {
|
|
889
899
|
defaultQueryFieldSuffix: string;
|
|
890
900
|
queryField: string;
|
|
891
|
-
|
|
892
|
-
sk: { [key: string]: string | number };
|
|
893
|
-
};
|
|
901
|
+
}
|
|
894
902
|
|
|
895
903
|
type IndexQueryMethodsFromIR<
|
|
896
904
|
SecondaryIdxTuple extends SecondaryIndexIrShape[],
|
|
@@ -911,6 +919,35 @@ type IndexQueryMethodsFromIR<
|
|
|
911
919
|
>
|
|
912
920
|
: Res;
|
|
913
921
|
|
|
922
|
+
type ListPkOptions<
|
|
923
|
+
ModelMeta extends ModelMetaShape,
|
|
924
|
+
Enums extends Record<string, string>,
|
|
925
|
+
> = ModelMeta['identifier']['sk'] extends never
|
|
926
|
+
? unknown
|
|
927
|
+
: Prettify<
|
|
928
|
+
Partial<IndexQueryInput<ModelMeta['identifier'], Enums>> & {
|
|
929
|
+
sortDirection?: ModelSortDirection;
|
|
930
|
+
}
|
|
931
|
+
>;
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Accepts a PrimaryIndexIr or SecondaryIndexIr and returns resolved parameters
|
|
935
|
+
*/
|
|
936
|
+
type IndexQueryInput<
|
|
937
|
+
Idx extends PrimaryIndexIrShape,
|
|
938
|
+
Enums extends Record<string, string>,
|
|
939
|
+
> = {
|
|
940
|
+
[PKField in keyof Idx['pk']]: Idx['pk'][PKField] extends `${deferredRefResolvingPrefix}${infer R}`
|
|
941
|
+
? Enums[R]
|
|
942
|
+
: Idx['pk'][PKField];
|
|
943
|
+
} & {
|
|
944
|
+
[SKField in keyof Idx['sk']]+?: number extends Idx['sk'][SKField]
|
|
945
|
+
? NumericFilter
|
|
946
|
+
: Idx['sk'][SKField] extends `${deferredRefResolvingPrefix}${infer R}`
|
|
947
|
+
? StringFilter<Enums[R]>
|
|
948
|
+
: StringFilter<Idx['sk'][SKField] & string>;
|
|
949
|
+
};
|
|
950
|
+
|
|
914
951
|
type IndexQueryMethodSignature<
|
|
915
952
|
Idx extends SecondaryIndexIrShape,
|
|
916
953
|
ModelName extends string,
|
|
@@ -924,17 +961,7 @@ type IndexQueryMethodSignature<
|
|
|
924
961
|
FlatModel extends Record<string, unknown> = ResolvedModel<Model>,
|
|
925
962
|
SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
|
|
926
963
|
>(
|
|
927
|
-
input:
|
|
928
|
-
[PKField in keyof Idx['pk']]: Idx['pk'][PKField] extends `${deferredRefResolvingPrefix}${infer R}`
|
|
929
|
-
? Enums[R]
|
|
930
|
-
: Idx['pk'][PKField];
|
|
931
|
-
} & {
|
|
932
|
-
[SKField in keyof Idx['sk']]+?: number extends Idx['sk'][SKField]
|
|
933
|
-
? NumericFilter
|
|
934
|
-
: Idx['sk'][SKField] extends `${deferredRefResolvingPrefix}${infer R}`
|
|
935
|
-
? StringFilter<Enums[R]>
|
|
936
|
-
: StringFilter<Idx['sk'][SKField] & string>;
|
|
937
|
-
},
|
|
964
|
+
input: IndexQueryInput<Idx, Enums>,
|
|
938
965
|
options?: {
|
|
939
966
|
filter?: ModelFilter<Model>;
|
|
940
967
|
sortDirection?: ModelSortDirection;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MapSecondaryIndexes.js","sources":["../../../src/MappedTypes/MapSecondaryIndexes.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":"MapSecondaryIndexes.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|