@aws-amplify/data-schema 1.2.8 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ClientSchema/Core/ClientCustomOperations.js +4 -0
- package/dist/cjs/ClientSchema/Core/ClientCustomOperations.js.map +1 -0
- package/dist/cjs/{MappedTypes/CustomOperations.js → ClientSchema/Core/ClientCustomType.js} +1 -1
- package/dist/cjs/ClientSchema/Core/ClientCustomType.js.map +1 -0
- package/dist/cjs/{ClientSchema.js → ClientSchema/Core/ClientEnum.js} +1 -1
- package/dist/cjs/ClientSchema/Core/ClientEnum.js.map +1 -0
- package/dist/cjs/ClientSchema/Core/ClientModel.js +4 -0
- package/dist/cjs/ClientSchema/Core/ClientModel.js.map +1 -0
- package/dist/cjs/ClientSchema/Core/ClientSchemaProperty.js +4 -0
- package/dist/cjs/ClientSchema/Core/ClientSchemaProperty.js.map +1 -0
- package/dist/cjs/ClientSchema/Core/index.js +4 -0
- package/dist/cjs/ClientSchema/Core/index.js.map +1 -0
- package/dist/cjs/ClientSchema/index.js +4 -0
- package/dist/cjs/ClientSchema/index.js.map +1 -0
- package/dist/cjs/ClientSchema/utilities/ExtractNestedTypes.js +4 -0
- package/dist/cjs/ClientSchema/utilities/ExtractNestedTypes.js.map +1 -0
- package/dist/cjs/ClientSchema/utilities/ResolveField.js +4 -0
- package/dist/cjs/ClientSchema/utilities/ResolveField.js.map +1 -0
- package/dist/cjs/ClientSchema/utilities/ResolveRef.js +4 -0
- package/dist/cjs/ClientSchema/utilities/ResolveRef.js.map +1 -0
- package/dist/cjs/ClientSchema/utilities/SchemaMetadata.js +4 -0
- package/dist/cjs/ClientSchema/utilities/SchemaMetadata.js.map +1 -0
- package/dist/cjs/ClientSchema/utilities/index.js +9 -0
- package/dist/cjs/ClientSchema/utilities/index.js.map +1 -0
- package/dist/cjs/util/Filters.js +10 -0
- package/dist/cjs/util/Filters.js.map +1 -0
- package/dist/cjs/util/IndexShapes.js +4 -0
- package/dist/cjs/util/IndexShapes.js.map +1 -0
- package/dist/cjs/util/Select.js +4 -0
- package/dist/cjs/util/Select.js.map +1 -0
- package/dist/esm/Authorization.d.ts +3 -3
- package/dist/esm/ClientSchema/Core/ClientCustomOperations.d.ts +88 -0
- package/dist/esm/ClientSchema/Core/ClientCustomOperations.mjs +2 -0
- package/dist/esm/ClientSchema/Core/ClientCustomOperations.mjs.map +1 -0
- package/dist/esm/ClientSchema/Core/ClientCustomType.d.ts +7 -0
- package/dist/esm/ClientSchema/Core/ClientCustomType.mjs +2 -0
- package/dist/esm/ClientSchema/Core/ClientCustomType.mjs.map +1 -0
- package/dist/esm/ClientSchema/Core/ClientEnum.d.ts +5 -0
- package/dist/esm/ClientSchema/Core/ClientEnum.mjs +2 -0
- package/dist/esm/ClientSchema/Core/ClientEnum.mjs.map +1 -0
- package/dist/esm/ClientSchema/Core/ClientModel.d.ts +123 -0
- package/dist/esm/ClientSchema/Core/ClientModel.mjs +2 -0
- package/dist/esm/ClientSchema/Core/ClientModel.mjs.map +1 -0
- package/dist/esm/ClientSchema/Core/ClientSchemaProperty.d.ts +4 -0
- package/dist/esm/ClientSchema/Core/ClientSchemaProperty.mjs +2 -0
- package/dist/esm/ClientSchema/Core/ClientSchemaProperty.mjs.map +1 -0
- package/dist/esm/ClientSchema/Core/index.d.ts +5 -0
- package/dist/esm/ClientSchema/Core/index.mjs +2 -0
- package/dist/esm/ClientSchema/Core/index.mjs.map +1 -0
- package/dist/esm/ClientSchema/index.d.ts +59 -0
- package/dist/esm/ClientSchema/index.mjs +2 -0
- package/dist/esm/ClientSchema/index.mjs.map +1 -0
- package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.d.ts +7 -0
- package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.mjs +2 -0
- package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.mjs.map +1 -0
- package/dist/esm/ClientSchema/utilities/ResolveField.d.ts +29 -0
- package/dist/esm/ClientSchema/utilities/ResolveField.mjs +2 -0
- package/dist/esm/ClientSchema/utilities/ResolveField.mjs.map +1 -0
- package/dist/esm/ClientSchema/utilities/ResolveRef.d.ts +18 -0
- package/dist/esm/ClientSchema/utilities/ResolveRef.mjs +2 -0
- package/dist/esm/ClientSchema/utilities/ResolveRef.mjs.map +1 -0
- package/dist/esm/ClientSchema/utilities/SchemaMetadata.d.ts +7 -0
- package/dist/esm/ClientSchema/utilities/SchemaMetadata.mjs +2 -0
- package/dist/esm/ClientSchema/utilities/SchemaMetadata.mjs.map +1 -0
- package/dist/esm/ClientSchema/utilities/index.d.ts +4 -0
- package/dist/esm/ClientSchema/utilities/index.mjs +2 -0
- package/dist/esm/ClientSchema/utilities/index.mjs.map +1 -0
- package/dist/esm/MappedTypes/ImplicitFieldInjector.d.ts +1 -1
- package/dist/esm/MappedTypes/ModelMetadata.d.ts +1 -1
- package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +1 -1
- package/dist/esm/ModelSchema.d.ts +11 -5
- package/dist/esm/ModelType.d.ts +9 -8
- package/dist/esm/ModelType.mjs.map +1 -1
- package/dist/esm/runtime/client/index.d.ts +77 -223
- package/dist/esm/runtime/internals/generateCustomOperationsProperty.d.ts +12 -5
- package/dist/esm/util/Filters.d.ts +94 -0
- package/dist/esm/util/Filters.mjs +2 -0
- package/dist/esm/util/Filters.mjs.map +1 -0
- package/dist/esm/util/IndexShapes.d.ts +13 -0
- package/dist/esm/util/IndexShapes.mjs +2 -0
- package/dist/esm/util/IndexShapes.mjs.map +1 -0
- package/dist/esm/util/Select.d.ts +3 -0
- package/dist/esm/util/Select.mjs +2 -0
- package/dist/esm/util/Select.mjs.map +1 -0
- package/dist/esm/util/index.d.ts +3 -0
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/Authorization.ts +2 -2
- package/src/ClientSchema/Core/ClientCustomOperations.ts +152 -0
- package/src/ClientSchema/Core/ClientCustomType.ts +11 -0
- package/src/ClientSchema/Core/ClientEnum.ts +7 -0
- package/src/ClientSchema/Core/ClientModel.ts +299 -0
- package/src/ClientSchema/Core/ClientSchemaProperty.ts +10 -0
- package/src/ClientSchema/Core/index.ts +5 -0
- package/src/ClientSchema/index.ts +158 -0
- package/src/ClientSchema/utilities/ExtractNestedTypes.ts +15 -0
- package/src/ClientSchema/utilities/ResolveField.ts +79 -0
- package/src/ClientSchema/utilities/ResolveRef.ts +38 -0
- package/src/ClientSchema/utilities/SchemaMetadata.ts +11 -0
- package/src/ClientSchema/utilities/index.ts +4 -0
- package/src/MappedTypes/ImplicitFieldInjector.ts +1 -1
- package/src/MappedTypes/ModelMetadata.ts +2 -1
- package/src/MappedTypes/ResolveFieldProperties.ts +1 -1
- package/src/ModelSchema.ts +19 -4
- package/src/ModelType.ts +12 -3
- package/src/runtime/client/index.ts +175 -433
- package/src/runtime/internals/generateCustomOperationsProperty.ts +2 -2
- package/src/runtime/internals/utils/clientProperties/generateEnumsProperty.ts +1 -1
- package/src/util/Filters.ts +102 -0
- package/src/util/IndexShapes.ts +10 -0
- package/src/util/Select.ts +3 -0
- package/src/util/index.ts +3 -0
- package/dist/cjs/ClientSchema.js.map +0 -1
- package/dist/cjs/MappedTypes/CustomOperations.js.map +0 -1
- package/dist/esm/ClientSchema.d.ts +0 -51
- package/dist/esm/ClientSchema.mjs +0 -2
- package/dist/esm/ClientSchema.mjs.map +0 -1
- package/dist/esm/MappedTypes/CustomOperations.d.ts +0 -125
- package/dist/esm/MappedTypes/CustomOperations.mjs +0 -2
- package/dist/esm/MappedTypes/CustomOperations.mjs.map +0 -1
- package/src/ClientSchema.ts +0 -121
- package/src/MappedTypes/CustomOperations.ts +0 -254
|
@@ -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>[];
|
|
@@ -42,6 +46,9 @@ export type ModelSchema<T extends ModelSchemaParamShape, UsedMethods extends 'au
|
|
|
42
46
|
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(callback: (allow: AllowModifier) => AuthRules | AuthRules[]) => ModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
|
|
43
47
|
}, UsedMethods> & BaseSchema<T> & DDBSchemaBrand;
|
|
44
48
|
type RDSModelSchemaFunctions = 'addToSchema' | 'addQueries' | 'addMutations' | 'addSubscriptions' | 'authorization' | 'setRelationships' | 'setAuthorization' | 'renameModelFields' | 'renameModels';
|
|
49
|
+
type OmitFromEach<Models, Modifier extends string> = {
|
|
50
|
+
[ModelName in keyof Models]: Omit<Models[ModelName], Modifier>;
|
|
51
|
+
};
|
|
45
52
|
export type RDSModelSchema<T extends RDSModelSchemaParamShape, UsedMethods extends RDSModelSchemaFunctions = never, RelationshipTemplate extends Record<string, ModelRelationalField<ModelRelationalFieldParamShape, string, any, any>> = Record<string, ModelRelationalField<ModelRelationalFieldParamShape, string, any, any>>> = Omit<{
|
|
46
53
|
addToSchema: <AddedTypes extends AddToSchemaContents>(types: AddedTypes) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & AddedTypes>, UsedMethods | 'addToSchema'>;
|
|
47
54
|
/**
|
|
@@ -57,8 +64,8 @@ export type RDSModelSchema<T extends RDSModelSchemaParamShape, UsedMethods exten
|
|
|
57
64
|
*/
|
|
58
65
|
addSubscriptions: <Subscriptions extends Record<string, SubscriptionCustomOperation>>(types: Subscriptions) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Subscriptions>, UsedMethods | 'addSubscriptions'>;
|
|
59
66
|
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(callback: (allow: AllowModifier) => AuthRules | AuthRules[]) => RDSModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
|
|
60
|
-
setAuthorization: (callback: (models: BaseSchema<T, true>['models'], schema: RDSModelSchema<T, UsedMethods | 'setAuthorization'>) => void) => RDSModelSchema<T>;
|
|
61
|
-
setRelationships: <Relationships extends ReadonlyArray<Partial<Record<keyof T['types'], RelationshipTemplate>>>>(callback: (models: BaseSchema<T, true>['models']) => Relationships) => RDSModelSchema<UnionToIntersection<Relationships[number]> extends infer RelationshipsDefs ? RelationshipsDefs extends Record<string, RelationshipTemplate> ? SetTypeSubArg<T, 'types', {
|
|
67
|
+
setAuthorization: (callback: (models: OmitFromEach<BaseSchema<T, true>['models'], 'secondaryIndexes'>, schema: RDSModelSchema<T, UsedMethods | 'setAuthorization'>) => void) => RDSModelSchema<T>;
|
|
68
|
+
setRelationships: <Relationships extends ReadonlyArray<Partial<Record<keyof T['types'], RelationshipTemplate>>>>(callback: (models: OmitFromEach<BaseSchema<T, true>['models'], 'authorization' | 'fields' | 'secondaryIndexes'>) => Relationships) => RDSModelSchema<UnionToIntersection<Relationships[number]> extends infer RelationshipsDefs ? RelationshipsDefs extends Record<string, RelationshipTemplate> ? SetTypeSubArg<T, 'types', {
|
|
62
69
|
[ModelName in keyof T['types']]: ModelName extends keyof RelationshipsDefs ? AddRelationshipFieldsToModelTypeFields<T['types'][ModelName], RelationshipsDefs[ModelName]> : T['types'][ModelName];
|
|
63
70
|
}> : T : T, UsedMethods | 'setRelationships'>;
|
|
64
71
|
renameModels: <NewName extends string, CurName extends string = keyof BaseSchema<T>['models'] & string, const ChangeLog extends readonly [CurName, NewName][] = []>(callback: () => ChangeLog) => RDSModelSchema<SetTypeSubArg<T, 'types', RenameModelArr<ChangeLog, T['types']>>, UsedMethods | 'renameModels'>;
|
|
@@ -116,4 +123,3 @@ export type CustomPathData = {
|
|
|
116
123
|
stack: string | undefined;
|
|
117
124
|
entry: string;
|
|
118
125
|
};
|
|
119
|
-
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,g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Y,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,EAA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