@aws-amplify/data-schema 1.1.3 → 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/SchemaProcessor.js +3 -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/ModelType.d.ts +22 -25
- package/dist/esm/SchemaProcessor.mjs +3 -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/ModelType.ts +45 -46
- package/src/SchemaProcessor.ts +5 -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/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,14 +40,14 @@ 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>[];
|
|
52
53
|
originalName?: string;
|
|
@@ -54,7 +55,7 @@ type InternalModelData = ModelData & {
|
|
|
54
55
|
|
|
55
56
|
export type ModelTypeParamShape = {
|
|
56
57
|
fields: ModelFields;
|
|
57
|
-
identifier:
|
|
58
|
+
identifier: PrimaryIndexIrShape;
|
|
58
59
|
secondaryIndexes: ReadonlyArray<SecondaryIndexIrShape>;
|
|
59
60
|
authorization: Authorization<any, any, any>[];
|
|
60
61
|
};
|
|
@@ -73,20 +74,27 @@ export type ModelTypeParamShape = {
|
|
|
73
74
|
* indicator string, and resolve its corresponding type later in
|
|
74
75
|
* packages/data-schema/src/runtime/client/index.ts
|
|
75
76
|
*/
|
|
76
|
-
type ExtractSecondaryIndexIRFields<
|
|
77
|
+
export type ExtractSecondaryIndexIRFields<
|
|
78
|
+
T extends ModelTypeParamShape,
|
|
79
|
+
RequiredOnly extends boolean = false,
|
|
80
|
+
> = {
|
|
77
81
|
[FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends ModelField<
|
|
78
82
|
infer R,
|
|
79
83
|
any,
|
|
80
84
|
any
|
|
81
85
|
>
|
|
82
86
|
? NonNullable<R> extends string | number
|
|
83
|
-
?
|
|
87
|
+
? RequiredOnly extends false
|
|
88
|
+
? FieldProp
|
|
89
|
+
: null extends R
|
|
90
|
+
? never
|
|
91
|
+
: FieldProp
|
|
84
92
|
: never
|
|
85
|
-
: T['fields'][FieldProp] extends
|
|
93
|
+
: T['fields'][FieldProp] extends
|
|
94
|
+
| EnumType<EnumTypeParamShape>
|
|
95
|
+
| RefType<RefTypeParamShape, any, any>
|
|
86
96
|
? FieldProp
|
|
87
|
-
: T['fields'][FieldProp] extends
|
|
88
|
-
? FieldProp
|
|
89
|
-
: never]: T['fields'][FieldProp] extends ModelField<infer R, any, any>
|
|
97
|
+
: never]: T['fields'][FieldProp] extends ModelField<infer R, any, any>
|
|
90
98
|
? R
|
|
91
99
|
: T['fields'][FieldProp] extends EnumType<infer R>
|
|
92
100
|
? R['values'][number]
|
|
@@ -107,26 +115,6 @@ type ExtractType<T extends ModelTypeParamShape> = {
|
|
|
107
115
|
: never;
|
|
108
116
|
};
|
|
109
117
|
|
|
110
|
-
type GetRequiredFields<T> = {
|
|
111
|
-
[FieldProp in keyof T as T[FieldProp] extends NonNullable<T[FieldProp]>
|
|
112
|
-
? FieldProp
|
|
113
|
-
: never]: T[FieldProp];
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
type IdentifierMap<T extends ModelTypeParamShape> = GetRequiredFields<
|
|
117
|
-
ExtractType<T>
|
|
118
|
-
>;
|
|
119
|
-
|
|
120
|
-
// extracts model fields that CAN BE used as identifiers (scalar, non-nullable fields)
|
|
121
|
-
// TODO: make this also filter out all non-scalars e.g., model fields and custom types
|
|
122
|
-
type IdentifierFields<T extends ModelTypeParamShape> = keyof IdentifierMap<T> &
|
|
123
|
-
string;
|
|
124
|
-
|
|
125
|
-
type IdentifierType<
|
|
126
|
-
T extends ModelTypeParamShape,
|
|
127
|
-
Fields extends string = IdentifierFields<T>,
|
|
128
|
-
> = Array<Fields>;
|
|
129
|
-
|
|
130
118
|
/**
|
|
131
119
|
* For a given ModelTypeParamShape, produces a map of Authorization rules
|
|
132
120
|
* that would *conflict* with the given type.
|
|
@@ -214,9 +202,20 @@ export type ModelType<
|
|
|
214
202
|
K extends keyof ModelType<T> = never,
|
|
215
203
|
> = Omit<
|
|
216
204
|
{
|
|
217
|
-
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
|
+
>(
|
|
218
214
|
identifier: ID,
|
|
219
|
-
): ModelType<
|
|
215
|
+
): ModelType<
|
|
216
|
+
SetTypeSubArg<T, 'identifier', PrimaryIndexIR>,
|
|
217
|
+
K | 'identifier'
|
|
218
|
+
>;
|
|
220
219
|
secondaryIndexes<
|
|
221
220
|
const SecondaryIndexFields = ExtractSecondaryIndexIRFields<T>,
|
|
222
221
|
const SecondaryIndexPKPool extends string = keyof SecondaryIndexFields &
|
|
@@ -272,7 +271,7 @@ export type SchemaModelType<
|
|
|
272
271
|
IsRDS extends boolean = false,
|
|
273
272
|
> = IsRDS extends true
|
|
274
273
|
? T & {
|
|
275
|
-
|
|
274
|
+
relationships<
|
|
276
275
|
Param extends Record<
|
|
277
276
|
string,
|
|
278
277
|
ModelRelationalField<any, string, any, any>
|
|
@@ -368,7 +367,7 @@ export function model<T extends ModelFields>(
|
|
|
368
367
|
fields: T,
|
|
369
368
|
): ModelType<{
|
|
370
369
|
fields: T;
|
|
371
|
-
identifier:
|
|
370
|
+
identifier: { pk: { id: string }; sk: never };
|
|
372
371
|
secondaryIndexes: [];
|
|
373
372
|
authorization: [];
|
|
374
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,7 +1329,9 @@ const schemaPreprocessor = (
|
|
|
1329
1329
|
topLevelTypes.push(...implicitTypes);
|
|
1330
1330
|
|
|
1331
1331
|
const joined = gqlFields.join('\n ');
|
|
1332
|
-
const refersToString = typeDef.data.originalName
|
|
1332
|
+
const refersToString = typeDef.data.originalName
|
|
1333
|
+
? ` @refersTo(name: "${typeDef.data.originalName}")`
|
|
1334
|
+
: '';
|
|
1333
1335
|
// TODO: update @model(timestamps: null) once a longer term solution gets
|
|
1334
1336
|
// determined.
|
|
1335
1337
|
//
|
|
@@ -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":""}
|