@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.
Files changed (122) hide show
  1. package/dist/cjs/ClientSchema/Core/ClientCustomOperations.js +4 -0
  2. package/dist/cjs/ClientSchema/Core/ClientCustomOperations.js.map +1 -0
  3. package/dist/cjs/{MappedTypes/CustomOperations.js → ClientSchema/Core/ClientCustomType.js} +1 -1
  4. package/dist/cjs/ClientSchema/Core/ClientCustomType.js.map +1 -0
  5. package/dist/cjs/{ClientSchema.js → ClientSchema/Core/ClientEnum.js} +1 -1
  6. package/dist/cjs/ClientSchema/Core/ClientEnum.js.map +1 -0
  7. package/dist/cjs/ClientSchema/Core/ClientModel.js +4 -0
  8. package/dist/cjs/ClientSchema/Core/ClientModel.js.map +1 -0
  9. package/dist/cjs/ClientSchema/Core/ClientSchemaProperty.js +4 -0
  10. package/dist/cjs/ClientSchema/Core/ClientSchemaProperty.js.map +1 -0
  11. package/dist/cjs/ClientSchema/Core/index.js +4 -0
  12. package/dist/cjs/ClientSchema/Core/index.js.map +1 -0
  13. package/dist/cjs/ClientSchema/index.js +4 -0
  14. package/dist/cjs/ClientSchema/index.js.map +1 -0
  15. package/dist/cjs/ClientSchema/utilities/ExtractNestedTypes.js +4 -0
  16. package/dist/cjs/ClientSchema/utilities/ExtractNestedTypes.js.map +1 -0
  17. package/dist/cjs/ClientSchema/utilities/ResolveField.js +4 -0
  18. package/dist/cjs/ClientSchema/utilities/ResolveField.js.map +1 -0
  19. package/dist/cjs/ClientSchema/utilities/ResolveRef.js +4 -0
  20. package/dist/cjs/ClientSchema/utilities/ResolveRef.js.map +1 -0
  21. package/dist/cjs/ClientSchema/utilities/SchemaMetadata.js +4 -0
  22. package/dist/cjs/ClientSchema/utilities/SchemaMetadata.js.map +1 -0
  23. package/dist/cjs/ClientSchema/utilities/index.js +9 -0
  24. package/dist/cjs/ClientSchema/utilities/index.js.map +1 -0
  25. package/dist/cjs/util/Filters.js +10 -0
  26. package/dist/cjs/util/Filters.js.map +1 -0
  27. package/dist/cjs/util/IndexShapes.js +4 -0
  28. package/dist/cjs/util/IndexShapes.js.map +1 -0
  29. package/dist/cjs/util/Select.js +4 -0
  30. package/dist/cjs/util/Select.js.map +1 -0
  31. package/dist/esm/Authorization.d.ts +3 -3
  32. package/dist/esm/ClientSchema/Core/ClientCustomOperations.d.ts +88 -0
  33. package/dist/esm/ClientSchema/Core/ClientCustomOperations.mjs +2 -0
  34. package/dist/esm/ClientSchema/Core/ClientCustomOperations.mjs.map +1 -0
  35. package/dist/esm/ClientSchema/Core/ClientCustomType.d.ts +7 -0
  36. package/dist/esm/ClientSchema/Core/ClientCustomType.mjs +2 -0
  37. package/dist/esm/ClientSchema/Core/ClientCustomType.mjs.map +1 -0
  38. package/dist/esm/ClientSchema/Core/ClientEnum.d.ts +5 -0
  39. package/dist/esm/ClientSchema/Core/ClientEnum.mjs +2 -0
  40. package/dist/esm/ClientSchema/Core/ClientEnum.mjs.map +1 -0
  41. package/dist/esm/ClientSchema/Core/ClientModel.d.ts +123 -0
  42. package/dist/esm/ClientSchema/Core/ClientModel.mjs +2 -0
  43. package/dist/esm/ClientSchema/Core/ClientModel.mjs.map +1 -0
  44. package/dist/esm/ClientSchema/Core/ClientSchemaProperty.d.ts +4 -0
  45. package/dist/esm/ClientSchema/Core/ClientSchemaProperty.mjs +2 -0
  46. package/dist/esm/ClientSchema/Core/ClientSchemaProperty.mjs.map +1 -0
  47. package/dist/esm/ClientSchema/Core/index.d.ts +5 -0
  48. package/dist/esm/ClientSchema/Core/index.mjs +2 -0
  49. package/dist/esm/ClientSchema/Core/index.mjs.map +1 -0
  50. package/dist/esm/ClientSchema/index.d.ts +59 -0
  51. package/dist/esm/ClientSchema/index.mjs +2 -0
  52. package/dist/esm/ClientSchema/index.mjs.map +1 -0
  53. package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.d.ts +7 -0
  54. package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.mjs +2 -0
  55. package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.mjs.map +1 -0
  56. package/dist/esm/ClientSchema/utilities/ResolveField.d.ts +29 -0
  57. package/dist/esm/ClientSchema/utilities/ResolveField.mjs +2 -0
  58. package/dist/esm/ClientSchema/utilities/ResolveField.mjs.map +1 -0
  59. package/dist/esm/ClientSchema/utilities/ResolveRef.d.ts +18 -0
  60. package/dist/esm/ClientSchema/utilities/ResolveRef.mjs +2 -0
  61. package/dist/esm/ClientSchema/utilities/ResolveRef.mjs.map +1 -0
  62. package/dist/esm/ClientSchema/utilities/SchemaMetadata.d.ts +7 -0
  63. package/dist/esm/ClientSchema/utilities/SchemaMetadata.mjs +2 -0
  64. package/dist/esm/ClientSchema/utilities/SchemaMetadata.mjs.map +1 -0
  65. package/dist/esm/ClientSchema/utilities/index.d.ts +4 -0
  66. package/dist/esm/ClientSchema/utilities/index.mjs +2 -0
  67. package/dist/esm/ClientSchema/utilities/index.mjs.map +1 -0
  68. package/dist/esm/MappedTypes/ImplicitFieldInjector.d.ts +1 -1
  69. package/dist/esm/MappedTypes/ModelMetadata.d.ts +1 -1
  70. package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +1 -1
  71. package/dist/esm/ModelSchema.d.ts +11 -5
  72. package/dist/esm/ModelType.d.ts +9 -8
  73. package/dist/esm/ModelType.mjs.map +1 -1
  74. package/dist/esm/runtime/client/index.d.ts +77 -223
  75. package/dist/esm/runtime/internals/generateCustomOperationsProperty.d.ts +12 -5
  76. package/dist/esm/util/Filters.d.ts +94 -0
  77. package/dist/esm/util/Filters.mjs +2 -0
  78. package/dist/esm/util/Filters.mjs.map +1 -0
  79. package/dist/esm/util/IndexShapes.d.ts +13 -0
  80. package/dist/esm/util/IndexShapes.mjs +2 -0
  81. package/dist/esm/util/IndexShapes.mjs.map +1 -0
  82. package/dist/esm/util/Select.d.ts +3 -0
  83. package/dist/esm/util/Select.mjs +2 -0
  84. package/dist/esm/util/Select.mjs.map +1 -0
  85. package/dist/esm/util/index.d.ts +3 -0
  86. package/dist/meta/cjs.tsbuildinfo +1 -1
  87. package/package.json +1 -1
  88. package/src/Authorization.ts +2 -2
  89. package/src/ClientSchema/Core/ClientCustomOperations.ts +152 -0
  90. package/src/ClientSchema/Core/ClientCustomType.ts +11 -0
  91. package/src/ClientSchema/Core/ClientEnum.ts +7 -0
  92. package/src/ClientSchema/Core/ClientModel.ts +299 -0
  93. package/src/ClientSchema/Core/ClientSchemaProperty.ts +10 -0
  94. package/src/ClientSchema/Core/index.ts +5 -0
  95. package/src/ClientSchema/index.ts +158 -0
  96. package/src/ClientSchema/utilities/ExtractNestedTypes.ts +15 -0
  97. package/src/ClientSchema/utilities/ResolveField.ts +79 -0
  98. package/src/ClientSchema/utilities/ResolveRef.ts +38 -0
  99. package/src/ClientSchema/utilities/SchemaMetadata.ts +11 -0
  100. package/src/ClientSchema/utilities/index.ts +4 -0
  101. package/src/MappedTypes/ImplicitFieldInjector.ts +1 -1
  102. package/src/MappedTypes/ModelMetadata.ts +2 -1
  103. package/src/MappedTypes/ResolveFieldProperties.ts +1 -1
  104. package/src/ModelSchema.ts +19 -4
  105. package/src/ModelType.ts +12 -3
  106. package/src/runtime/client/index.ts +175 -433
  107. package/src/runtime/internals/generateCustomOperationsProperty.ts +2 -2
  108. package/src/runtime/internals/utils/clientProperties/generateEnumsProperty.ts +1 -1
  109. package/src/util/Filters.ts +102 -0
  110. package/src/util/IndexShapes.ts +10 -0
  111. package/src/util/Select.ts +3 -0
  112. package/src/util/index.ts +3 -0
  113. package/dist/cjs/ClientSchema.js.map +0 -1
  114. package/dist/cjs/MappedTypes/CustomOperations.js.map +0 -1
  115. package/dist/esm/ClientSchema.d.ts +0 -51
  116. package/dist/esm/ClientSchema.mjs +0 -2
  117. package/dist/esm/ClientSchema.mjs.map +0 -1
  118. package/dist/esm/MappedTypes/CustomOperations.d.ts +0 -125
  119. package/dist/esm/MappedTypes/CustomOperations.mjs +0 -2
  120. package/dist/esm/MappedTypes/CustomOperations.mjs.map +0 -1
  121. package/src/ClientSchema.ts +0 -121
  122. 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,2 @@
1
+
2
+ //# sourceMappingURL=ResolveRef.mjs.map
@@ -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,2 @@
1
+
2
+ //# sourceMappingURL=SchemaMetadata.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaMetadata.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export * from './ExtractNestedTypes';
2
+ export * from './ResolveField';
3
+ export * from './ResolveRef';
4
+ export * from './SchemaMetadata';
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- import type { PrimaryIndexIrShape } from '../runtime/';
1
+ import type { PrimaryIndexIrShape } from '../util';
2
2
  type DefaultIdentifierFields = {
3
3
  readonly id: string;
4
4
  };
@@ -1,5 +1,5 @@
1
1
  import { type UnionToIntersection, type ExcludeEmpty } from '@aws-amplify/data-schema-types';
2
- import { type PrimaryIndexIrShape } from '../runtime/';
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 '../runtime/';
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<any> | CustomType<any> | InternalCustom>;
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 {};
@@ -1,5 +1,5 @@
1
1
  import type { SetTypeSubArg } from '@aws-amplify/data-schema-types';
2
- import type { PrimaryIndexIrShape, SecondaryIndexIrShape } from './runtime';
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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AY,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,WAA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