@aws-amplify/data-schema 1.2.9 → 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 +6 -3
- 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 +8 -2
- 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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RefTypeParamShape } from '../../RefType';
|
|
2
|
+
/**
|
|
3
|
+
* Dereferences an `a.ref()` against a given "bag" of independently resolved types.
|
|
4
|
+
*
|
|
5
|
+
* This util will examine the ref for requiredness and array-ness and wrap/augment
|
|
6
|
+
* to referred-to type accordingly.
|
|
7
|
+
*/
|
|
8
|
+
export type ResolveRef<RefShape extends RefTypeParamShape, RefBag extends Record<string, {
|
|
9
|
+
__entityType: string;
|
|
10
|
+
type: unknown;
|
|
11
|
+
}>> = ResolveRefValueArrayTraits<RefShape, ApplyRequiredness<RefShape['link'] extends keyof RefBag ? RefBag[RefShape['link']]['type'] : never, RefShape['valueRequired']>>;
|
|
12
|
+
type ApplyRequiredness<Value, MakeRequired extends boolean> = MakeRequired extends true ? Exclude<Value, null> : Value | null | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Converts the resolved RefType Value type into Array<> according to the
|
|
15
|
+
* `array` and `arrayRequired` properties of the RefType
|
|
16
|
+
*/
|
|
17
|
+
type ResolveRefValueArrayTraits<Ref extends RefTypeParamShape, Value> = Ref['array'] extends false ? Value : Ref['arrayRequired'] extends true ? Array<Value> : Array<Value> | null | undefined;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResolveRef.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ImpliedAuthFields } from '../../Authorization';
|
|
2
|
+
import { BaseSchema } from '../../ModelSchema';
|
|
3
|
+
export interface SchemaMetadata<Schema extends BaseSchema<any, any>> {
|
|
4
|
+
authFields: AuthFields<Schema>;
|
|
5
|
+
}
|
|
6
|
+
type AuthFields<Schema extends Record<string, any>> = Schema['data']['authorization'][number] extends never ? object : ImpliedAuthFields<Schema['data']['authorization'][number]>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaMetadata.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type UnionToIntersection, type ExcludeEmpty } from '@aws-amplify/data-schema-types';
|
|
2
|
-
import {
|
|
2
|
+
import type { PrimaryIndexIrShape } from '../util';
|
|
3
3
|
import type { ModelType } from '../ModelType';
|
|
4
4
|
import type { ModelRelationalFieldParamShape } from '../ModelRelationalField';
|
|
5
5
|
export type ModelIdentifier<T> = {
|
|
@@ -4,7 +4,7 @@ import type { ModelField } from '../ModelField';
|
|
|
4
4
|
import type { ModelType, ModelTypeParamShape } from '../ModelType';
|
|
5
5
|
import type { GenericModelSchema } from '../ModelSchema';
|
|
6
6
|
import type { ModelRelationalField, ModelRelationalFieldParamShape } from '../ModelRelationalField';
|
|
7
|
-
import type { PrimaryIndexIrShape } from '../
|
|
7
|
+
import type { PrimaryIndexIrShape } from '../util/';
|
|
8
8
|
import type { ResolveSchema, SchemaTypes } from './ResolveSchema';
|
|
9
9
|
import type { InjectImplicitModelFields } from './ImplicitFieldInjector';
|
|
10
10
|
import type { ModelIdentifier } from './ModelMetadata';
|
|
@@ -6,6 +6,10 @@ import type { CustomOperation, CustomOperationParamShape, InternalCustom, Mutati
|
|
|
6
6
|
import { AllowModifier, SchemaAuthorization } from './Authorization';
|
|
7
7
|
import { Brand } from './util';
|
|
8
8
|
import { ModelRelationalField, ModelRelationalFieldParamShape } from './ModelRelationalField';
|
|
9
|
+
export { ModelType } from './ModelType';
|
|
10
|
+
export { EnumType } from './EnumType';
|
|
11
|
+
export { CustomType } from './CustomType';
|
|
12
|
+
export { CustomOperation } from './CustomOperation';
|
|
9
13
|
export declare const rdsSchemaBrandName = "RDSSchema";
|
|
10
14
|
export declare const rdsSchemaBrand: Brand<"RDSSchema">;
|
|
11
15
|
export type RDSSchemaBrand = Brand<typeof rdsSchemaBrandName>;
|
|
@@ -15,8 +19,8 @@ type SchemaContent = BaseModelType | CustomType<CustomTypeParamShape> | EnumType
|
|
|
15
19
|
type AddToSchemaContent = Exclude<SchemaContent, BaseModelType>;
|
|
16
20
|
type AddToSchemaContents = Record<string, AddToSchemaContent>;
|
|
17
21
|
type NonEmpty<T> = keyof T extends never ? never : T;
|
|
18
|
-
type ModelSchemaContents = Record<string, SchemaContent>;
|
|
19
|
-
type InternalSchemaModels = Record<string, InternalModel | EnumType
|
|
22
|
+
export type ModelSchemaContents = Record<string, SchemaContent>;
|
|
23
|
+
type InternalSchemaModels = Record<string, InternalModel | EnumType | CustomType<any> | InternalCustom>;
|
|
20
24
|
export type ModelSchemaParamShape = {
|
|
21
25
|
types: ModelSchemaContents;
|
|
22
26
|
authorization: SchemaAuthorization<any, any, any>[];
|
|
@@ -119,4 +123,3 @@ export type CustomPathData = {
|
|
|
119
123
|
stack: string | undefined;
|
|
120
124
|
entry: string;
|
|
121
125
|
};
|
|
122
|
-
export {};
|
package/dist/esm/ModelType.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SetTypeSubArg } from '@aws-amplify/data-schema-types';
|
|
2
|
-
import type
|
|
2
|
+
import { type PrimaryIndexIrShape, type SecondaryIndexIrShape } from './util';
|
|
3
3
|
import type { InternalField, BaseModelField } from './ModelField';
|
|
4
4
|
import type { ModelRelationalField, InternalRelationalField, ModelRelationalFieldParamShape } from './ModelRelationalField';
|
|
5
5
|
import { type AllowModifier, type Authorization } from './Authorization';
|
|
@@ -80,6 +80,13 @@ export type InternalModel = SchemaModelType<ModelType<ModelTypeParamShape>, stri
|
|
|
80
80
|
* @returns true if the given value is a ModelSchema
|
|
81
81
|
*/
|
|
82
82
|
export declare const isSchemaModelType: (modelType: any | SchemaModelType) => modelType is ModelType<ModelTypeParamShape, "identifier">;
|
|
83
|
+
export type ModelDefaultIdentifier = {
|
|
84
|
+
pk: {
|
|
85
|
+
readonly id: string;
|
|
86
|
+
};
|
|
87
|
+
sk: never;
|
|
88
|
+
compositeSk: never;
|
|
89
|
+
};
|
|
83
90
|
/**
|
|
84
91
|
* A data model that creates a matching Amazon DynamoDB table and provides create, read (list and get), update,
|
|
85
92
|
* delete, and subscription APIs.
|
|
@@ -89,13 +96,7 @@ export declare const isSchemaModelType: (modelType: any | SchemaModelType) => mo
|
|
|
89
96
|
*/
|
|
90
97
|
export declare function model<T extends ModelFields>(fields: T): ModelType<{
|
|
91
98
|
fields: T;
|
|
92
|
-
identifier:
|
|
93
|
-
pk: {
|
|
94
|
-
id: string;
|
|
95
|
-
};
|
|
96
|
-
sk: never;
|
|
97
|
-
compositeSk: never;
|
|
98
|
-
};
|
|
99
|
+
identifier: ModelDefaultIdentifier;
|
|
99
100
|
secondaryIndexes: [];
|
|
100
101
|
authorization: [];
|
|
101
102
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelType.mjs","sources":["../../src/ModelType.ts"],"sourcesContent":["import { brand } from './util';\nimport { allow } from './Authorization';\nimport { modelIndex, } from './ModelIndex';\nconst brandName = 'modelType';\nfunction _model(fields) {\n const data = {\n fields,\n identifier: ['id'],\n secondaryIndexes: [],\n authorization: [],\n };\n const builder = {\n identifier(identifier) {\n data.identifier = identifier;\n return this;\n },\n secondaryIndexes(callback) {\n data.secondaryIndexes = callback(modelIndex);\n return this;\n },\n authorization(callback) {\n const { resource: _, ...rest } = allow;\n const rules = callback(rest);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n ...brand(brandName),\n };\n return {\n ...builder,\n data,\n relationships(relationships) {\n data.fields = { ...data.fields, ...relationships };\n },\n fields: data.fields,\n };\n}\n/**\n * Model Type type guard\n * @param modelType - api-next ModelType\n * @returns true if the given value is a ModelSchema\n */\nexport const isSchemaModelType = (modelType) => {\n const internalType = modelType;\n return (typeof internalType === 'object' &&\n internalType.data !== undefined &&\n internalType.data.fields !== undefined &&\n internalType.data.authorization !== undefined &&\n internalType.data.identifier !== undefined &&\n internalType.data.secondaryIndexes !== undefined &&\n typeof internalType.relationships === 'function');\n};\n/**\n * A data model that creates a matching Amazon DynamoDB table and provides create, read (list and get), update,\n * delete, and subscription APIs.\n *\n * @param fields database table fields. Supports scalar types and relationship types.\n * @returns a data model definition\n */\nexport function model(fields) {\n return _model(fields);\n}\n"],"names":[],"mappings":";;;;AAGA,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,SAAS,MAAM,CAAC,MAAM,EAAE;AACxB,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM;AACd,QAAQ,UAAU,EAAE,CAAC,IAAI,CAAC;AAC1B,QAAQ,gBAAgB,EAAE,EAAE;AAC5B,QAAQ,aAAa,EAAE,EAAE;AACzB,KAAK,CAAC;AACN,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,UAAU,CAAC,UAAU,EAAE;AAC/B,YAAY,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;AACzC,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,gBAAgB,CAAC,QAAQ,EAAE;AACnC,YAAY,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;AACzD,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,aAAa,CAAC,QAAQ,EAAE;AAChC,YAAY,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;AACnD,YAAY,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;AACzC,YAAY,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC;AACxE,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC;AAC3B,KAAK,CAAC;AACN,IAAI,OAAO;AACX,QAAQ,GAAG,OAAO;AAClB,QAAQ,IAAI;AACZ,QAAQ,aAAa,CAAC,aAAa,EAAE;AACrC,YAAY,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;AAC/D,SAAS;AACT,QAAQ,MAAM,EAAE,IAAI,CAAC,MAAM;AAC3B,KAAK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACY,MAAC,iBAAiB,GAAG,CAAC,SAAS,KAAK;AAChD,IAAI,MAAM,YAAY,GAAG,SAAS,CAAC;AACnC,IAAI,QAAQ,OAAO,YAAY,KAAK,QAAQ;AAC5C,QAAQ,YAAY,CAAC,IAAI,KAAK,SAAS;AACvC,QAAQ,YAAY,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS;AAC9C,QAAQ,YAAY,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS;AACrD,QAAQ,YAAY,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS;AAClD,QAAQ,YAAY,CAAC,IAAI,CAAC,gBAAgB,KAAK,SAAS;AACxD,QAAQ,OAAO,YAAY,CAAC,aAAa,KAAK,UAAU,EAAE;AAC1D,EAAE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,CAAC,MAAM,EAAE;AAC9B,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AAC1B;;;;"}
|
|
1
|
+
{"version":3,"file":"ModelType.mjs","sources":["../../src/ModelType.ts"],"sourcesContent":["import { brand, } from './util';\nimport { allow } from './Authorization';\nimport { modelIndex, } from './ModelIndex';\nconst brandName = 'modelType';\nfunction _model(fields) {\n const data = {\n fields,\n identifier: ['id'],\n secondaryIndexes: [],\n authorization: [],\n };\n const builder = {\n identifier(identifier) {\n data.identifier = identifier;\n return this;\n },\n secondaryIndexes(callback) {\n data.secondaryIndexes = callback(modelIndex);\n return this;\n },\n authorization(callback) {\n const { resource: _, ...rest } = allow;\n const rules = callback(rest);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n ...brand(brandName),\n };\n return {\n ...builder,\n data,\n relationships(relationships) {\n data.fields = { ...data.fields, ...relationships };\n },\n fields: data.fields,\n };\n}\n/**\n * Model Type type guard\n * @param modelType - api-next ModelType\n * @returns true if the given value is a ModelSchema\n */\nexport const isSchemaModelType = (modelType) => {\n const internalType = modelType;\n return (typeof internalType === 'object' &&\n internalType.data !== undefined &&\n internalType.data.fields !== undefined &&\n internalType.data.authorization !== undefined &&\n internalType.data.identifier !== undefined &&\n internalType.data.secondaryIndexes !== undefined &&\n typeof internalType.relationships === 'function');\n};\n/**\n * A data model that creates a matching Amazon DynamoDB table and provides create, read (list and get), update,\n * delete, and subscription APIs.\n *\n * @param fields database table fields. Supports scalar types and relationship types.\n * @returns a data model definition\n */\nexport function model(fields) {\n return _model(fields);\n}\n"],"names":[],"mappings":";;;;AAGA,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,SAAS,MAAM,CAAC,MAAM,EAAE;AACxB,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM;AACd,QAAQ,UAAU,EAAE,CAAC,IAAI,CAAC;AAC1B,QAAQ,gBAAgB,EAAE,EAAE;AAC5B,QAAQ,aAAa,EAAE,EAAE;AACzB,KAAK,CAAC;AACN,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,UAAU,CAAC,UAAU,EAAE;AAC/B,YAAY,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;AACzC,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,gBAAgB,CAAC,QAAQ,EAAE;AACnC,YAAY,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;AACzD,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,aAAa,CAAC,QAAQ,EAAE;AAChC,YAAY,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;AACnD,YAAY,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;AACzC,YAAY,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC;AACxE,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC;AAC3B,KAAK,CAAC;AACN,IAAI,OAAO;AACX,QAAQ,GAAG,OAAO;AAClB,QAAQ,IAAI;AACZ,QAAQ,aAAa,CAAC,aAAa,EAAE;AACrC,YAAY,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;AAC/D,SAAS;AACT,QAAQ,MAAM,EAAE,IAAI,CAAC,MAAM;AAC3B,KAAK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACY,MAAC,iBAAiB,GAAG,CAAC,SAAS,KAAK;AAChD,IAAI,MAAM,YAAY,GAAG,SAAS,CAAC;AACnC,IAAI,QAAQ,OAAO,YAAY,KAAK,QAAQ;AAC5C,QAAQ,YAAY,CAAC,IAAI,KAAK,SAAS;AACvC,QAAQ,YAAY,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS;AAC9C,QAAQ,YAAY,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS;AACrD,QAAQ,YAAY,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS;AAClD,QAAQ,YAAY,CAAC,IAAI,CAAC,gBAAgB,KAAK,SAAS;AACxD,QAAQ,OAAO,YAAY,CAAC,aAAa,KAAK,UAAU,EAAE;AAC1D,EAAE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,CAAC,MAAM,EAAE;AAC9B,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AAC1B;;;;"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { DeepReadOnlyObject, UnwrapArray, UnionToIntersection, Prettify
|
|
1
|
+
import { type DeepReadOnlyObject, type UnwrapArray, type UnionToIntersection, type Prettify } from '@aws-amplify/data-schema-types';
|
|
2
2
|
import type { Observable } from 'rxjs';
|
|
3
|
-
import {
|
|
3
|
+
import type { ClientSchemaByEntityType, ClientSchemaByEntityTypeBaseShape } from '../../ClientSchema';
|
|
4
|
+
import type { ExtractNestedTypes } from '../../ClientSchema/utilities/';
|
|
5
|
+
import type { Select, StringFilter, NumericFilter, BooleanFilters } from '../../util';
|
|
4
6
|
export { __modelMeta__, ExtractModelMeta, } from '@aws-amplify/data-schema-types';
|
|
5
7
|
type Model = Record<string, any>;
|
|
6
8
|
/**
|
|
@@ -9,12 +11,15 @@ type Model = Record<string, any>;
|
|
|
9
11
|
type NonRelationalFields<M extends Model> = {
|
|
10
12
|
[Field in keyof M as UnwrapArray<M[Field]> extends Record<string, unknown> ? never : Field]: M[Field];
|
|
11
13
|
};
|
|
14
|
+
type WithOptionalsAsNullishOnly<T> = T extends Array<infer ArrayType> ? Array<WithOptionalsAsNullishOnly<ArrayType>> : T extends (...args: any) => any ? T : T extends object ? {
|
|
15
|
+
[K in keyof T]-?: WithOptionalsAsNullishOnly<T[K]>;
|
|
16
|
+
} : Exclude<T, undefined>;
|
|
12
17
|
/**
|
|
13
18
|
* Selection set-aware CRUDL operation return value type
|
|
14
19
|
*
|
|
15
|
-
* @returns model type
|
|
20
|
+
* @returns model type with default selection set; otherwise generates return type from custom sel. set. Optionality is removed from both return types.
|
|
16
21
|
*/
|
|
17
|
-
type ReturnValue<M extends
|
|
22
|
+
type ReturnValue<M extends ClientSchemaByEntityTypeBaseShape['models'][string], FlatModel extends Model, Paths extends ReadonlyArray<ModelPath<FlatModel>>> = Paths extends undefined | never[] ? WithOptionalsAsNullishOnly<M['type']> : WithOptionalsAsNullishOnly<CustomSelectionSetReturnValue<FlatModel, Paths[number]>>;
|
|
18
23
|
/**
|
|
19
24
|
* This mapped type traverses the SelectionSetReturnValue result and the original FlatModel, restoring array types
|
|
20
25
|
* that were flattened in DeepPickFromPath
|
|
@@ -154,34 +159,13 @@ RecursionLoop extends number[] = [-1, 0, 1, 2, 3, 4], Field = keyof FlatModel> =
|
|
|
154
159
|
*
|
|
155
160
|
* ```
|
|
156
161
|
*/
|
|
157
|
-
|
|
162
|
+
type ResolvedModel<Model extends Record<string, unknown>, Depth extends number = 7, RecursionLoop extends number[] = [-1, 0, 1, 2, 3, 4, 5, 6]> = {
|
|
158
163
|
done: NonRelationalFields<Model>;
|
|
159
164
|
recur: {
|
|
160
165
|
[Field in keyof Model]: Model[Field] extends (...args: any) => ListReturnValue<infer M> ? NonNullable<M> extends Record<string, any> ? ResolvedModel<NonNullable<M>, RecursionLoop[Depth]>[] : never : Model[Field] extends (...args: any) => SingularReturnValue<infer M> ? NonNullable<M> extends Record<string, any> ? ResolvedModel<NonNullable<M>, RecursionLoop[Depth]> : never : Model[Field];
|
|
161
166
|
};
|
|
162
167
|
}[Depth extends -1 ? 'done' : 'recur'];
|
|
163
|
-
export type SelectionSet<Model extends Record<string, unknown>, Path extends ReadonlyArray<ModelPath<FlatModel>>, FlatModel extends Record<string, unknown> = ResolvedModel<Model>> = CustomSelectionSetReturnValue<FlatModel, Path[number]
|
|
164
|
-
export type ModelIdentifier<ModelMeta extends ModelMetaShape> = ModelMeta['identifier']['pk'] & (ModelMeta['identifier']['sk'] extends never ? unknown : ModelMeta['identifier']['sk']);
|
|
165
|
-
type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B;
|
|
166
|
-
type WritableKeys<T> = {
|
|
167
|
-
[P in keyof T]-?: IfEquals<{
|
|
168
|
-
[Q in P]: T[P];
|
|
169
|
-
}, {
|
|
170
|
-
-readonly [Q in P]: T[P];
|
|
171
|
-
}, P>;
|
|
172
|
-
}[keyof T];
|
|
173
|
-
/**
|
|
174
|
-
* All required fields and relational fields, exclude readonly fields
|
|
175
|
-
*/
|
|
176
|
-
type MutationInput<Fields, WritableFields = Pick<Fields, WritableKeys<Fields>>> = {
|
|
177
|
-
[Prop in keyof WritableFields as WritableFields[Prop] extends (...args: any) => any ? never : Prop]: WritableFields[Prop];
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* All identifiers and fields used to create a model
|
|
181
|
-
*/
|
|
182
|
-
type CreateModelInput<Model extends Record<string, unknown>, ModelMeta extends ModelMetaShape> = Equal<ModelIdentifier<ModelMeta>, {
|
|
183
|
-
id: string;
|
|
184
|
-
}> extends true ? Partial<ModelIdentifier<ModelMeta>> & Omit<MutationInput<Model>, 'id'> : MutationInput<Model>;
|
|
168
|
+
export type SelectionSet<Model extends Record<string, unknown>, Path extends ReadonlyArray<ModelPath<FlatModel>>, FlatModel extends Record<string, unknown> = ResolvedModel<Model>> = WithOptionalsAsNullishOnly<CustomSelectionSetReturnValue<FlatModel, Path[number]>>;
|
|
185
169
|
/**
|
|
186
170
|
* See: https://spec.graphql.org/draft/#sec-Errors
|
|
187
171
|
*/
|
|
@@ -251,7 +235,7 @@ export type ObserveQueryReturnValue<T> = Observable<{
|
|
|
251
235
|
items: T[];
|
|
252
236
|
isSynced: boolean;
|
|
253
237
|
}>;
|
|
254
|
-
export type LazyLoader<
|
|
238
|
+
export type LazyLoader<T, IsArray extends boolean> = (options?: IsArray extends true ? {
|
|
255
239
|
authMode?: AuthMode;
|
|
256
240
|
authToken?: string;
|
|
257
241
|
limit?: number;
|
|
@@ -261,138 +245,59 @@ export type LazyLoader<Model, IsArray extends boolean> = (options?: IsArray exte
|
|
|
261
245
|
authMode?: AuthMode;
|
|
262
246
|
authToken?: string;
|
|
263
247
|
headers?: CustomHeaders;
|
|
264
|
-
}) => IsArray extends true ? ListReturnValue<Prettify<NonNullable<
|
|
248
|
+
}) => IsArray extends true ? ListReturnValue<Prettify<NonNullable<T>>> : SingularReturnValue<Prettify<T>>;
|
|
265
249
|
export type AuthMode = 'apiKey' | 'iam' | 'identityPool' | 'oidc' | 'userPool' | 'lambda' | 'none';
|
|
266
|
-
type LogicalFilters<Model extends
|
|
250
|
+
type LogicalFilters<Model extends ClientSchemaByEntityTypeBaseShape['models'][string]> = {
|
|
267
251
|
and?: ModelFilter<Model> | ModelFilter<Model>[];
|
|
268
252
|
or?: ModelFilter<Model> | ModelFilter<Model>[];
|
|
269
253
|
not?: ModelFilter<Model>;
|
|
270
254
|
};
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
*/
|
|
274
|
-
type SizeFilter = {
|
|
275
|
-
between?: [number, number];
|
|
276
|
-
eq?: number;
|
|
277
|
-
ge?: number;
|
|
278
|
-
gt?: number;
|
|
279
|
-
le?: number;
|
|
280
|
-
lt?: number;
|
|
281
|
-
ne?: number;
|
|
282
|
-
};
|
|
283
|
-
/**
|
|
284
|
-
* Not actually sure if/how customer can pass this through as variables yet.
|
|
285
|
-
* Leaving it out for now:
|
|
286
|
-
*
|
|
287
|
-
* attributeType: "binary" | "binarySet" | "bool" | "list" | "map" | "number" | "numberSet" | "string" | "stringSet" | "_null"
|
|
288
|
-
*/
|
|
289
|
-
/**
|
|
290
|
-
* Filters options that can be used on string-like fields.
|
|
291
|
-
*/
|
|
292
|
-
export type StringFilter<T extends string = string> = {
|
|
293
|
-
attributeExists?: boolean;
|
|
294
|
-
beginsWith?: string;
|
|
295
|
-
between?: [string, string];
|
|
296
|
-
contains?: string;
|
|
297
|
-
eq?: T;
|
|
298
|
-
ge?: string;
|
|
299
|
-
gt?: string;
|
|
300
|
-
le?: string;
|
|
301
|
-
lt?: string;
|
|
302
|
-
ne?: T;
|
|
303
|
-
notContains?: string;
|
|
304
|
-
size?: SizeFilter;
|
|
305
|
-
};
|
|
306
|
-
export type NumericFilter = {
|
|
307
|
-
attributeExists?: boolean;
|
|
308
|
-
between?: [number, number];
|
|
309
|
-
eq?: number;
|
|
310
|
-
ge?: number;
|
|
311
|
-
gt?: number;
|
|
312
|
-
le?: number;
|
|
313
|
-
lt?: number;
|
|
314
|
-
ne?: number;
|
|
315
|
-
};
|
|
316
|
-
type BooleanFilters = {
|
|
317
|
-
attributeExists?: boolean;
|
|
318
|
-
eq?: boolean;
|
|
319
|
-
ne?: boolean;
|
|
320
|
-
};
|
|
321
|
-
/**
|
|
322
|
-
* A composite SK (in an identifier or secondaryIndex) resolves to this type for
|
|
323
|
-
* list queries and index queries
|
|
324
|
-
*
|
|
325
|
-
* @example
|
|
326
|
-
* Given
|
|
327
|
-
* ```ts
|
|
328
|
-
* MyModel: a
|
|
329
|
-
.model({
|
|
330
|
-
pk: a.string().required(),
|
|
331
|
-
sk1: a.string().required(),
|
|
332
|
-
sk2: a.integer().required(),
|
|
333
|
-
})
|
|
334
|
-
.identifier(['pk', 'sk1', 'sk2']),
|
|
335
|
-
* ```
|
|
336
|
-
* Expected list options:
|
|
337
|
-
* ```ts
|
|
338
|
-
* {
|
|
339
|
-
* pk?: string
|
|
340
|
-
* sk1Sk2?: ModelPrimaryCompositeKeyConditionInput
|
|
341
|
-
* }
|
|
342
|
-
* ```
|
|
343
|
-
* Where ModelPrimaryCompositeKeyConditionInput resolves to:
|
|
344
|
-
* ```ts
|
|
345
|
-
* {
|
|
346
|
-
* eq: {sk1: string; sk2: number};
|
|
347
|
-
* le: {sk1: string; sk2: number};
|
|
348
|
-
* lt: {sk1: string; sk2: number};
|
|
349
|
-
* ge: {sk1: string; sk2: number};
|
|
350
|
-
* gt: {sk1: string; sk2: number};
|
|
351
|
-
* between: [ {sk1: string; sk2: number} ];
|
|
352
|
-
* beginsWith: {sk1: string; sk2: number};
|
|
353
|
-
* }
|
|
354
|
-
* ```
|
|
355
|
-
* */
|
|
356
|
-
export type ModelPrimaryCompositeKeyInput<SkIr extends Record<string, string | number>> = {
|
|
357
|
-
eq?: SkIr;
|
|
358
|
-
le?: SkIr;
|
|
359
|
-
lt?: SkIr;
|
|
360
|
-
ge?: SkIr;
|
|
361
|
-
gt?: SkIr;
|
|
362
|
-
between?: [SkIr];
|
|
363
|
-
beginsWith?: SkIr;
|
|
364
|
-
};
|
|
365
|
-
type ModelFilter<Model extends Record<any, any>> = LogicalFilters<Model> & {
|
|
366
|
-
[K in keyof Model as Model[K] extends LazyLoader<any, any> ? never : K]?: boolean extends Model[K] ? BooleanFilters : number extends Model[K] ? NumericFilter : StringFilter;
|
|
255
|
+
type ModelFilter<Model extends ClientSchemaByEntityTypeBaseShape['models'][string]> = LogicalFilters<Model> & {
|
|
256
|
+
[K in keyof Model['type'] as Model['type'][K] extends LazyLoader<any, any> ? never : K]?: boolean extends Model['type'][K] ? BooleanFilters : number extends Model['type'][K] ? NumericFilter : StringFilter;
|
|
367
257
|
};
|
|
368
258
|
export type ModelSortDirection = 'ASC' | 'DESC';
|
|
369
|
-
type
|
|
370
|
-
|
|
371
|
-
identifier: PrimaryIndexIrShape;
|
|
259
|
+
type ListCpkOptions<Model extends ClientSchemaByEntityTypeBaseShape['models'][string]> = unknown extends Model['__meta']['listOptionsPkParams'] ? unknown : Model['__meta']['listOptionsPkParams'] & {
|
|
260
|
+
sortDirection?: ModelSortDirection;
|
|
372
261
|
};
|
|
373
|
-
|
|
374
|
-
|
|
262
|
+
interface ClientSecondaryIndexField {
|
|
263
|
+
input: object;
|
|
264
|
+
}
|
|
265
|
+
type IndexQueryMethods<Model extends ClientSchemaByEntityTypeBaseShape['models'][string]> = {
|
|
266
|
+
[K in keyof Select<Model['secondaryIndexes'], ClientSecondaryIndexField>]: IndexQueryMethod<Model, Select<Model['secondaryIndexes'], ClientSecondaryIndexField>[K]>;
|
|
267
|
+
};
|
|
268
|
+
type IndexQueryMethod<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], Method extends ClientSecondaryIndexField, FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>> = <SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(input: Method['input'], options?: {
|
|
269
|
+
filter?: ModelFilter<Model>;
|
|
270
|
+
sortDirection?: ModelSortDirection;
|
|
271
|
+
limit?: number;
|
|
272
|
+
nextToken?: string | null;
|
|
273
|
+
selectionSet?: SelectionSet;
|
|
274
|
+
authMode?: AuthMode;
|
|
275
|
+
authToken?: string;
|
|
276
|
+
headers?: CustomHeaders;
|
|
277
|
+
}) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
278
|
+
type ModelTypesClient<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>> = IndexQueryMethods<Model> & {
|
|
279
|
+
create: (model: Model['createType'], options?: {
|
|
375
280
|
authMode?: AuthMode;
|
|
376
281
|
authToken?: string;
|
|
377
282
|
headers?: CustomHeaders;
|
|
378
|
-
}) => SingularReturnValue<Model>;
|
|
379
|
-
update: (model:
|
|
283
|
+
}) => SingularReturnValue<Model['type']>;
|
|
284
|
+
update: (model: Model['updateType'], options?: {
|
|
380
285
|
authMode?: AuthMode;
|
|
381
286
|
authToken?: string;
|
|
382
287
|
headers?: CustomHeaders;
|
|
383
|
-
}) => SingularReturnValue<Model>;
|
|
384
|
-
delete: (identifier:
|
|
288
|
+
}) => SingularReturnValue<Model['type']>;
|
|
289
|
+
delete: (identifier: Model['deleteType'], options?: {
|
|
385
290
|
authMode?: AuthMode;
|
|
386
291
|
authToken?: string;
|
|
387
292
|
headers?: CustomHeaders;
|
|
388
|
-
}) => SingularReturnValue<Model>;
|
|
389
|
-
get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(identifier:
|
|
293
|
+
}) => SingularReturnValue<Model['type']>;
|
|
294
|
+
get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(identifier: Model['identifier'], options?: {
|
|
390
295
|
selectionSet?: SelectionSet;
|
|
391
296
|
authMode?: AuthMode;
|
|
392
297
|
authToken?: string;
|
|
393
298
|
headers?: CustomHeaders;
|
|
394
299
|
}): SingularReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
395
|
-
list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(options?:
|
|
300
|
+
list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(options?: ListCpkOptions<Model> & {
|
|
396
301
|
filter?: ModelFilter<Model>;
|
|
397
302
|
limit?: number;
|
|
398
303
|
nextToken?: string | null;
|
|
@@ -429,29 +334,29 @@ export type ModelTypesClient<ModelName extends string, Model extends Record<stri
|
|
|
429
334
|
authToken?: string;
|
|
430
335
|
}): ObserveQueryReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
431
336
|
};
|
|
432
|
-
type ModelTypesSSRCookies<
|
|
433
|
-
create: (model:
|
|
337
|
+
type ModelTypesSSRCookies<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>> = IndexQueryMethods<Model> & {
|
|
338
|
+
create: (model: Model['createType'], options?: {
|
|
434
339
|
authMode?: AuthMode;
|
|
435
340
|
authToken?: string;
|
|
436
341
|
headers?: CustomHeaders;
|
|
437
342
|
}) => SingularReturnValue<Model>;
|
|
438
|
-
update: (model:
|
|
343
|
+
update: (model: Model['updateType'], options?: {
|
|
439
344
|
authMode?: AuthMode;
|
|
440
345
|
authToken?: string;
|
|
441
346
|
headers?: CustomHeaders;
|
|
442
347
|
}) => SingularReturnValue<Model>;
|
|
443
|
-
delete: (identifier:
|
|
348
|
+
delete: (identifier: Model['deleteType'], options?: {
|
|
444
349
|
authMode?: AuthMode;
|
|
445
350
|
authToken?: string;
|
|
446
351
|
headers?: CustomHeaders;
|
|
447
352
|
}) => SingularReturnValue<Model>;
|
|
448
|
-
get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(identifier:
|
|
353
|
+
get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(identifier: Model['identifier'], options?: {
|
|
449
354
|
selectionSet?: SelectionSet;
|
|
450
355
|
authMode?: AuthMode;
|
|
451
356
|
authToken?: string;
|
|
452
357
|
headers?: CustomHeaders;
|
|
453
358
|
}): SingularReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
454
|
-
list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(options?:
|
|
359
|
+
list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(options?: ListCpkOptions<Model> & {
|
|
455
360
|
filter?: ModelFilter<Model>;
|
|
456
361
|
sortDirection?: ModelSortDirection;
|
|
457
362
|
limit?: number;
|
|
@@ -462,29 +367,29 @@ type ModelTypesSSRCookies<ModelName extends string, Model extends Record<string,
|
|
|
462
367
|
headers?: CustomHeaders;
|
|
463
368
|
}): ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
464
369
|
};
|
|
465
|
-
type ModelTypesSSRRequest<
|
|
466
|
-
create: (contextSpec: any, model:
|
|
370
|
+
type ModelTypesSSRRequest<Model extends ClientSchemaByEntityTypeBaseShape['models'][string], FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>> = IndexQueryMethods<Model> & {
|
|
371
|
+
create: (contextSpec: any, model: Model['createType'], options?: {
|
|
467
372
|
authMode?: AuthMode;
|
|
468
373
|
authToken?: string;
|
|
469
374
|
headers?: CustomHeaders;
|
|
470
375
|
}) => SingularReturnValue<Model>;
|
|
471
|
-
update: (contextSpec: any, model:
|
|
376
|
+
update: (contextSpec: any, model: Model['updateType'], options?: {
|
|
472
377
|
authMode?: AuthMode;
|
|
473
378
|
authToken?: string;
|
|
474
379
|
headers?: CustomHeaders;
|
|
475
380
|
}) => SingularReturnValue<Model>;
|
|
476
|
-
delete: (contextSpec: any, identifier:
|
|
381
|
+
delete: (contextSpec: any, identifier: Model['deleteType'], options?: {
|
|
477
382
|
authMode?: AuthMode;
|
|
478
383
|
authToken?: string;
|
|
479
384
|
headers?: CustomHeaders;
|
|
480
385
|
}) => SingularReturnValue<Model>;
|
|
481
|
-
get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(contextSpec: any, identifier:
|
|
386
|
+
get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(contextSpec: any, identifier: Model['identifier'], options?: {
|
|
482
387
|
selectionSet?: SelectionSet;
|
|
483
388
|
authMode?: AuthMode;
|
|
484
389
|
authToken?: string;
|
|
485
390
|
headers?: CustomHeaders;
|
|
486
391
|
}): SingularReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
487
|
-
list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(contextSpec: any, options?:
|
|
392
|
+
list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(contextSpec: any, options?: ListCpkOptions<Model> & {
|
|
488
393
|
filter?: ModelFilter<Model>;
|
|
489
394
|
sortDirection?: ModelSortDirection;
|
|
490
395
|
limit?: number;
|
|
@@ -496,12 +401,12 @@ type ModelTypesSSRRequest<ModelName extends string, Model extends Record<string,
|
|
|
496
401
|
}): ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
|
|
497
402
|
};
|
|
498
403
|
type ContextType = 'CLIENT' | 'COOKIES' | 'REQUEST';
|
|
499
|
-
export type ModelTypes<
|
|
500
|
-
[ModelName in
|
|
404
|
+
export type ModelTypes<T extends Record<any, any>, Context extends ContextType = 'CLIENT', Schema extends ClientSchemaByEntityType<T> = ClientSchemaByEntityType<T>> = {
|
|
405
|
+
[ModelName in keyof Schema['models']]: Context extends 'CLIENT' ? ModelTypesClient<Schema['models'][ModelName]> : Context extends 'COOKIES' ? ModelTypesSSRCookies<Schema['models'][ModelName]> : Context extends 'REQUEST' ? ModelTypesSSRRequest<Schema['models'][ModelName]> : never;
|
|
501
406
|
};
|
|
502
|
-
export type CustomQueries<
|
|
503
|
-
export type CustomMutations<
|
|
504
|
-
export type CustomSubscriptions<
|
|
407
|
+
export type CustomQueries<T extends Record<any, any>, Context extends ContextType = 'CLIENT', Schema extends ClientSchemaByEntityType<T> = ClientSchemaByEntityType<T>> = CustomOperations<Schema['queries'], Context>;
|
|
408
|
+
export type CustomMutations<T extends Record<any, any>, Context extends ContextType = 'CLIENT', Schema extends ClientSchemaByEntityType<T> = ClientSchemaByEntityType<T>> = CustomOperations<Schema['mutations'], Context>;
|
|
409
|
+
export type CustomSubscriptions<T extends Record<any, any>, Context extends ContextType = 'CLIENT', Schema extends ClientSchemaByEntityType<T> = ClientSchemaByEntityType<T>> = CustomOperations<Schema['subscriptions'], Context>;
|
|
505
410
|
type CustomOperationMethodOptions = {
|
|
506
411
|
authMode?: AuthMode;
|
|
507
412
|
authToken?: string;
|
|
@@ -513,11 +418,11 @@ type CustomOperationMethodOptions = {
|
|
|
513
418
|
type CustomOperationFnParams<Args extends Record<string, unknown> | never> = [
|
|
514
419
|
Args
|
|
515
420
|
] extends [never] ? [CustomOperationMethodOptions?] : [Args, CustomOperationMethodOptions?];
|
|
516
|
-
export type CustomOperations<
|
|
517
|
-
[OpName in keyof
|
|
518
|
-
CLIENT: (...params: CustomOperationFnParams<
|
|
519
|
-
COOKIES: (...params: CustomOperationFnParams<
|
|
520
|
-
REQUEST: (contextSpec: any, ...params: CustomOperationFnParams<
|
|
421
|
+
export type CustomOperations<OperationDefs extends ClientSchemaByEntityTypeBaseShape['queries' | 'mutations' | 'subscriptions'], Context extends ContextType = 'CLIENT'> = {
|
|
422
|
+
[OpName in keyof OperationDefs]: {
|
|
423
|
+
CLIENT: (...params: CustomOperationFnParams<OperationDefs[OpName]['args']>) => OperationDefs[OpName]['operationType'] extends 'Subscription' ? ObservedReturnValue<OperationDefs[OpName]['type']> : SingularReturnValue<OperationDefs[OpName]['type']>;
|
|
424
|
+
COOKIES: (...params: CustomOperationFnParams<OperationDefs[OpName]['args']>) => SingularReturnValue<OperationDefs[OpName]['type']>;
|
|
425
|
+
REQUEST: (contextSpec: any, ...params: CustomOperationFnParams<OperationDefs[OpName]['args']>) => SingularReturnValue<OperationDefs[OpName]['type']>;
|
|
521
426
|
}[Context];
|
|
522
427
|
};
|
|
523
428
|
/**
|
|
@@ -537,11 +442,14 @@ export type CustomOperations<Schema extends Record<any, any>, OperationType exte
|
|
|
537
442
|
* }
|
|
538
443
|
* }
|
|
539
444
|
*/
|
|
540
|
-
export type EnumTypes<
|
|
541
|
-
[EnumName in keyof
|
|
542
|
-
values: () => Array<
|
|
445
|
+
export type EnumTypes<T extends Record<any, any>> = {
|
|
446
|
+
[EnumName in keyof AllEnumTypesRecursively<T>]: {
|
|
447
|
+
values: () => Array<AllEnumTypesRecursively<T>[EnumName]['type']>;
|
|
543
448
|
};
|
|
544
449
|
};
|
|
450
|
+
type AllEnumTypesRecursively<T extends Record<any, any>> = ClientSchemaByEntityType<T>['enums'] & Select<ExtractNestedTypes<ClientSchemaByEntityType<T>>, {
|
|
451
|
+
__entityType: 'enum';
|
|
452
|
+
}>;
|
|
545
453
|
/**
|
|
546
454
|
* Request options that are passed to custom header functions.
|
|
547
455
|
* `method` and `headers` are not included in custom header functions passed to
|
|
@@ -558,76 +466,22 @@ export type RequestOptions = {
|
|
|
558
466
|
* promise.
|
|
559
467
|
*/
|
|
560
468
|
export type CustomHeaders = Record<string, string> | ((requestOptions?: RequestOptions) => Promise<Record<string, string>>);
|
|
561
|
-
|
|
562
|
-
* PrimaryIndex field types and query methods
|
|
563
|
-
*/
|
|
564
|
-
export interface PrimaryIndexIrShape {
|
|
565
|
-
pk: {
|
|
566
|
-
[key: string]: string | number;
|
|
567
|
-
};
|
|
568
|
-
sk: {
|
|
569
|
-
[key: string]: string | number;
|
|
570
|
-
} | never;
|
|
571
|
-
compositeSk: never | string;
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* SecondaryIndex field types and query methods
|
|
575
|
-
*/
|
|
576
|
-
export interface SecondaryIndexIrShape extends PrimaryIndexIrShape {
|
|
577
|
-
defaultQueryFieldSuffix: string;
|
|
578
|
-
queryField: string;
|
|
579
|
-
}
|
|
580
|
-
export type IndexQueryMethodsFromIR<SecondaryIdxTuple extends SecondaryIndexIrShape[], ModelName extends string, Model extends Record<string, unknown>, Enums extends Record<string, string>, Res = unknown> = SecondaryIdxTuple extends [
|
|
581
|
-
infer A extends SecondaryIndexIrShape,
|
|
582
|
-
...infer B extends SecondaryIndexIrShape[]
|
|
583
|
-
] ? IndexQueryMethodsFromIR<B, ModelName, Model, Enums, IndexQueryMethodSignature<A, ModelName, Model, Enums> & Res> : Res;
|
|
584
|
-
export type ListPkOptions<ModelMeta extends ModelMetaShape, Enums extends Record<string, string>> = ModelMeta['identifier']['sk'] extends never ? unknown : Prettify<Partial<IndexQueryInput<ModelMeta['identifier'], Enums>> & {
|
|
585
|
-
sortDirection?: ModelSortDirection;
|
|
586
|
-
}>;
|
|
587
|
-
/**
|
|
588
|
-
* Accepts a PrimaryIndexIr or SecondaryIndexIr and returns resolved parameters
|
|
589
|
-
*/
|
|
590
|
-
export type IndexQueryInput<Idx extends PrimaryIndexIrShape, Enums extends Record<string, string>> = {
|
|
591
|
-
[PKField in keyof Idx['pk']]: Idx['pk'][PKField] extends `${deferredRefResolvingPrefix}${infer R}` ? Enums[R] : Idx['pk'][PKField];
|
|
592
|
-
} & (Idx['compositeSk'] extends never ? {
|
|
593
|
-
[SKField in keyof Idx['sk']]+?: number extends Idx['sk'][SKField] ? NumericFilter : Idx['sk'][SKField] extends `${deferredRefResolvingPrefix}${infer R}` ? StringFilter<Enums[R]> : StringFilter<Idx['sk'][SKField] & string>;
|
|
594
|
-
} : {
|
|
595
|
-
[CompositeSk in Idx['compositeSk']]+?: ModelPrimaryCompositeKeyInput<{
|
|
596
|
-
[SKField in keyof Idx['sk']]: Idx['sk'][SKField] extends `${deferredRefResolvingPrefix}${infer _R}` ? string : Idx['sk'][SKField];
|
|
597
|
-
}>;
|
|
598
|
-
});
|
|
599
|
-
type IndexQueryMethodSignature<Idx extends SecondaryIndexIrShape, ModelName extends string, Model extends Record<string, unknown>, Enums extends Record<string, string>> = Record<IsEmptyStringOrNever<Idx['queryField']> extends false ? Idx['queryField'] : `list${ModelName}By${Idx['defaultQueryFieldSuffix']}`, <FlatModel extends Record<string, unknown> = ResolvedModel<Model>, SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(input: IndexQueryInput<Idx, Enums>, options?: {
|
|
600
|
-
filter?: ModelFilter<Model>;
|
|
601
|
-
sortDirection?: ModelSortDirection;
|
|
602
|
-
limit?: number;
|
|
603
|
-
nextToken?: string | null;
|
|
604
|
-
selectionSet?: SelectionSet;
|
|
605
|
-
authMode?: AuthMode;
|
|
606
|
-
authToken?: string;
|
|
607
|
-
headers?: CustomHeaders;
|
|
608
|
-
}) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>>;
|
|
609
|
-
type FilteredKeys<T> = {
|
|
610
|
-
[P in keyof T]: T[P] extends never ? never : P;
|
|
611
|
-
}[keyof T];
|
|
612
|
-
type ExcludeNeverFields<O> = {
|
|
613
|
-
[K in FilteredKeys<O>]: O[K];
|
|
614
|
-
};
|
|
615
|
-
export type ClientExtensions<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
469
|
+
export type ClientExtensions<T extends Record<any, any> = never> = {
|
|
616
470
|
models: ModelTypes<T, 'CLIENT'>;
|
|
617
471
|
enums: EnumTypes<T>;
|
|
618
472
|
queries: CustomQueries<T, 'CLIENT'>;
|
|
619
473
|
mutations: CustomMutations<T, 'CLIENT'>;
|
|
620
474
|
subscriptions: CustomSubscriptions<T, 'CLIENT'>;
|
|
621
|
-
}
|
|
622
|
-
export type ClientExtensionsSSRRequest<T extends Record<any, any> = never> =
|
|
475
|
+
};
|
|
476
|
+
export type ClientExtensionsSSRRequest<T extends Record<any, any> = never> = {
|
|
623
477
|
models: ModelTypes<T, 'REQUEST'>;
|
|
624
478
|
enums: EnumTypes<T>;
|
|
625
479
|
queries: CustomQueries<T, 'REQUEST'>;
|
|
626
480
|
mutations: CustomMutations<T, 'REQUEST'>;
|
|
627
|
-
}
|
|
628
|
-
export type ClientExtensionsSSRCookies<T extends Record<any, any> = never> =
|
|
481
|
+
};
|
|
482
|
+
export type ClientExtensionsSSRCookies<T extends Record<any, any> = never> = {
|
|
629
483
|
models: ModelTypes<T, 'COOKIES'>;
|
|
630
484
|
enums: EnumTypes<T>;
|
|
631
485
|
queries: CustomQueries<T, 'COOKIES'>;
|
|
632
486
|
mutations: CustomMutations<T, 'COOKIES'>;
|
|
633
|
-
}
|
|
487
|
+
};
|