@aws-amplify/data-schema 0.0.0-20240412222732

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 (92) hide show
  1. package/LICENSE +175 -0
  2. package/NOTICE +1 -0
  3. package/internals/package.json +6 -0
  4. package/lib-esm/index.d.ts +5 -0
  5. package/lib-esm/index.d.ts.map +1 -0
  6. package/lib-esm/index.js +28 -0
  7. package/lib-esm/src/Authorization.d.ts +287 -0
  8. package/lib-esm/src/Authorization.d.ts.map +1 -0
  9. package/lib-esm/src/Authorization.js +332 -0
  10. package/lib-esm/src/ClientSchema.d.ts +54 -0
  11. package/lib-esm/src/ClientSchema.d.ts.map +1 -0
  12. package/lib-esm/src/ClientSchema.js +2 -0
  13. package/lib-esm/src/CombineSchema.d.ts +19 -0
  14. package/lib-esm/src/CombineSchema.d.ts.map +1 -0
  15. package/lib-esm/src/CombineSchema.js +40 -0
  16. package/lib-esm/src/CustomOperation.d.ts +98 -0
  17. package/lib-esm/src/CustomOperation.d.ts.map +1 -0
  18. package/lib-esm/src/CustomOperation.js +67 -0
  19. package/lib-esm/src/CustomType.d.ts +36 -0
  20. package/lib-esm/src/CustomType.d.ts.map +1 -0
  21. package/lib-esm/src/CustomType.js +14 -0
  22. package/lib-esm/src/EnumType.d.ts +16 -0
  23. package/lib-esm/src/EnumType.d.ts.map +1 -0
  24. package/lib-esm/src/EnumType.js +17 -0
  25. package/lib-esm/src/Handler.d.ts +58 -0
  26. package/lib-esm/src/Handler.d.ts.map +1 -0
  27. package/lib-esm/src/Handler.js +48 -0
  28. package/lib-esm/src/MappedTypes/CustomOperations.d.ts +127 -0
  29. package/lib-esm/src/MappedTypes/CustomOperations.d.ts.map +1 -0
  30. package/lib-esm/src/MappedTypes/CustomOperations.js +2 -0
  31. package/lib-esm/src/MappedTypes/ExtractNonModelTypes.d.ts +74 -0
  32. package/lib-esm/src/MappedTypes/ExtractNonModelTypes.d.ts.map +1 -0
  33. package/lib-esm/src/MappedTypes/ExtractNonModelTypes.js +2 -0
  34. package/lib-esm/src/MappedTypes/ForeignKeys.d.ts +84 -0
  35. package/lib-esm/src/MappedTypes/ForeignKeys.d.ts.map +1 -0
  36. package/lib-esm/src/MappedTypes/ForeignKeys.js +2 -0
  37. package/lib-esm/src/MappedTypes/ImplicitFieldInjector.d.ts +38 -0
  38. package/lib-esm/src/MappedTypes/ImplicitFieldInjector.d.ts.map +1 -0
  39. package/lib-esm/src/MappedTypes/ImplicitFieldInjector.js +2 -0
  40. package/lib-esm/src/MappedTypes/MapSecondaryIndexes.d.ts +61 -0
  41. package/lib-esm/src/MappedTypes/MapSecondaryIndexes.d.ts.map +1 -0
  42. package/lib-esm/src/MappedTypes/MapSecondaryIndexes.js +2 -0
  43. package/lib-esm/src/MappedTypes/ModelMetadata.d.ts +26 -0
  44. package/lib-esm/src/MappedTypes/ModelMetadata.d.ts.map +1 -0
  45. package/lib-esm/src/MappedTypes/ModelMetadata.js +2 -0
  46. package/lib-esm/src/MappedTypes/ResolveFieldProperties.d.ts +70 -0
  47. package/lib-esm/src/MappedTypes/ResolveFieldProperties.d.ts.map +1 -0
  48. package/lib-esm/src/MappedTypes/ResolveFieldProperties.js +2 -0
  49. package/lib-esm/src/MappedTypes/ResolveSchema.d.ts +65 -0
  50. package/lib-esm/src/MappedTypes/ResolveSchema.d.ts.map +1 -0
  51. package/lib-esm/src/MappedTypes/ResolveSchema.js +2 -0
  52. package/lib-esm/src/ModelField.d.ts +162 -0
  53. package/lib-esm/src/ModelField.d.ts.map +1 -0
  54. package/lib-esm/src/ModelField.js +209 -0
  55. package/lib-esm/src/ModelIndex.d.ts +19 -0
  56. package/lib-esm/src/ModelIndex.d.ts.map +1 -0
  57. package/lib-esm/src/ModelIndex.js +33 -0
  58. package/lib-esm/src/ModelRelationalField.d.ts +119 -0
  59. package/lib-esm/src/ModelRelationalField.d.ts.map +1 -0
  60. package/lib-esm/src/ModelRelationalField.js +120 -0
  61. package/lib-esm/src/ModelSchema.d.ts +107 -0
  62. package/lib-esm/src/ModelSchema.d.ts.map +1 -0
  63. package/lib-esm/src/ModelSchema.js +162 -0
  64. package/lib-esm/src/ModelType.d.ts +85 -0
  65. package/lib-esm/src/ModelType.d.ts.map +1 -0
  66. package/lib-esm/src/ModelType.js +64 -0
  67. package/lib-esm/src/RefType.d.ts +59 -0
  68. package/lib-esm/src/RefType.d.ts.map +1 -0
  69. package/lib-esm/src/RefType.js +47 -0
  70. package/lib-esm/src/SchemaProcessor.d.ts +11 -0
  71. package/lib-esm/src/SchemaProcessor.d.ts.map +1 -0
  72. package/lib-esm/src/SchemaProcessor.js +1106 -0
  73. package/lib-esm/src/index.d.ts +13 -0
  74. package/lib-esm/src/index.d.ts.map +1 -0
  75. package/lib-esm/src/index.js +43 -0
  76. package/lib-esm/src/internals/index.d.ts +2 -0
  77. package/lib-esm/src/internals/index.d.ts.map +1 -0
  78. package/lib-esm/src/internals/index.js +5 -0
  79. package/lib-esm/src/util/Brand.d.ts +36 -0
  80. package/lib-esm/src/util/Brand.d.ts.map +1 -0
  81. package/lib-esm/src/util/Brand.js +32 -0
  82. package/lib-esm/src/util/IndexLimit.d.ts +8 -0
  83. package/lib-esm/src/util/IndexLimit.d.ts.map +1 -0
  84. package/lib-esm/src/util/IndexLimit.js +2 -0
  85. package/lib-esm/src/util/SpreadTuple.d.ts +7 -0
  86. package/lib-esm/src/util/SpreadTuple.d.ts.map +1 -0
  87. package/lib-esm/src/util/SpreadTuple.js +2 -0
  88. package/lib-esm/src/util/index.d.ts +4 -0
  89. package/lib-esm/src/util/index.d.ts.map +1 -0
  90. package/lib-esm/src/util/index.js +6 -0
  91. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  92. package/package.json +62 -0
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCustomPathData = exports.configure = exports.schema = exports.isModelSchema = exports.ddbSchemaBrandName = exports.rdsSchemaBrand = exports.rdsSchemaBrandName = void 0;
4
+ const ModelType_1 = require("./ModelType");
5
+ const SchemaProcessor_1 = require("./SchemaProcessor");
6
+ const util_1 = require("./util");
7
+ exports.rdsSchemaBrandName = 'RDSSchema';
8
+ exports.rdsSchemaBrand = (0, util_1.brand)(exports.rdsSchemaBrandName);
9
+ exports.ddbSchemaBrandName = 'DDBSchema';
10
+ const ddbSchemaBrand = (0, util_1.brand)(exports.ddbSchemaBrandName);
11
+ /**
12
+ * Filter the schema types down to only include the ModelTypes as SchemaModelType
13
+ *
14
+ * @param schemaContents The object containing all SchemaContent for this schema
15
+ * @returns Only the schemaContents that are ModelTypes, coerced to the SchemaModelType surface
16
+ */
17
+ const filterSchemaModelTypes = (schemaContents) => {
18
+ const modelTypes = {};
19
+ if (schemaContents) {
20
+ Object.entries(schemaContents).forEach(([key, content]) => {
21
+ if ((0, ModelType_1.isSchemaModelType)(content)) {
22
+ modelTypes[key] = content;
23
+ }
24
+ });
25
+ }
26
+ return modelTypes;
27
+ };
28
+ /**
29
+ * Model Schema type guard
30
+ * @param schema - api-next ModelSchema or string
31
+ * @returns true if the given value is a ModelSchema
32
+ */
33
+ const isModelSchema = (schema) => {
34
+ return typeof schema === 'object' && schema.data !== undefined;
35
+ };
36
+ exports.isModelSchema = isModelSchema;
37
+ function _rdsSchema(types, config) {
38
+ const data = {
39
+ types,
40
+ authorization: [],
41
+ configuration: config,
42
+ };
43
+ const models = filterSchemaModelTypes(data.types);
44
+ return {
45
+ data,
46
+ models,
47
+ transform() {
48
+ const internalSchema = { data };
49
+ return (0, SchemaProcessor_1.processSchema)({ schema: internalSchema });
50
+ },
51
+ authorization(rules) {
52
+ this.data.authorization = rules;
53
+ const { authorization: _, ...rest } = this;
54
+ return rest;
55
+ },
56
+ addQueries(types) {
57
+ this.data.types = { ...this.data.types, ...types };
58
+ const { addQueries: _, ...rest } = this;
59
+ return rest;
60
+ },
61
+ addMutations(types) {
62
+ this.data.types = { ...this.data.types, ...types };
63
+ const { addMutations: _, ...rest } = this;
64
+ return rest;
65
+ },
66
+ addSubscriptions(types) {
67
+ this.data.types = { ...this.data.types, ...types };
68
+ const { addSubscriptions: _, ...rest } = this;
69
+ return rest;
70
+ },
71
+ setAuthorization(callback) {
72
+ callback(models, this);
73
+ const { setAuthorization: _, ...rest } = this;
74
+ return rest;
75
+ },
76
+ relationships(callback) {
77
+ const { relationships: _, ...rest } = this;
78
+ // The relationships are added via `models.<Model>.addRelationships`
79
+ // modifiers that's being called within the callback. They are modifying
80
+ // by references on each model, so there is not anything else to be done
81
+ // here.
82
+ callback(models);
83
+ return rest;
84
+ },
85
+ renameModels(callback) {
86
+ const { renameModels: _, ...rest } = this;
87
+ // returns an array of tuples [curName, newName]
88
+ const changeLog = callback();
89
+ changeLog.forEach(([curName, newName]) => {
90
+ const currentType = data.types[curName];
91
+ if (currentType === undefined) {
92
+ throw new Error(`Invalid renameModels call. ${curName} is not defined in the schema`);
93
+ }
94
+ if (typeof newName !== 'string' || newName.length < 1) {
95
+ throw new Error(`Invalid renameModels call. New name must be a non-empty string. Received: "${newName}"`);
96
+ }
97
+ models[newName] = currentType;
98
+ data.types[newName] = currentType;
99
+ delete models[curName];
100
+ delete data.types[curName];
101
+ });
102
+ return rest;
103
+ },
104
+ ...exports.rdsSchemaBrand,
105
+ };
106
+ }
107
+ function _ddbSchema(types, config) {
108
+ const data = {
109
+ types,
110
+ authorization: [],
111
+ configuration: config,
112
+ };
113
+ return {
114
+ data,
115
+ transform() {
116
+ const internalSchema = { data };
117
+ return (0, SchemaProcessor_1.processSchema)({ schema: internalSchema });
118
+ },
119
+ authorization(rules) {
120
+ this.data.authorization = rules;
121
+ const { authorization: _, ...rest } = this;
122
+ return rest;
123
+ },
124
+ models: filterSchemaModelTypes(data.types),
125
+ ...ddbSchemaBrand,
126
+ };
127
+ }
128
+ function bindConfigToSchema(config) {
129
+ return (types) => {
130
+ return (config.database.engine === 'dynamodb'
131
+ ? _ddbSchema(types, config)
132
+ : _rdsSchema(types, config));
133
+ };
134
+ }
135
+ /**
136
+ * The API and data model definition for Amplify Data. Pass in `{ <NAME>: a.model(...) }` to create a database table
137
+ * and exposes CRUDL operations via an API.
138
+ * @param types The API and data model definition
139
+ * @returns An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`)
140
+ * or with the Amplify Data CDK construct (`@aws-amplify/data-construct`)
141
+ */
142
+ exports.schema = bindConfigToSchema({ database: { engine: 'dynamodb' } });
143
+ /**
144
+ * Configure wraps schema definition with non-default config to allow usecases other than
145
+ * the default DynamoDB use-case.
146
+ *
147
+ * @param config The SchemaConfig augments the schema with content like the database type
148
+ * @returns
149
+ */
150
+ function configure(config) {
151
+ return {
152
+ schema: bindConfigToSchema(config),
153
+ };
154
+ }
155
+ exports.configure = configure;
156
+ function isCustomPathData(obj) {
157
+ return ('stack' in obj &&
158
+ (typeof obj.stack === 'undefined' || typeof obj.stack === 'string') &&
159
+ 'entry' in obj &&
160
+ typeof obj.entry === 'string');
161
+ }
162
+ exports.isCustomPathData = isCustomPathData;
@@ -0,0 +1,85 @@
1
+ import type { SetTypeSubArg, SecondaryIndexIrShape } from '@aws-amplify/data-schema-types';
2
+ import { Brand } from './util';
3
+ import { ModelField, InternalField } from './ModelField';
4
+ import type { ModelRelationalField, InternalRelationalField, ModelRelationalFieldParamShape } from './ModelRelationalField';
5
+ import { Authorization } from './Authorization';
6
+ import { RefType } from './RefType';
7
+ import { EnumType, EnumTypeParamShape } from './EnumType';
8
+ import { CustomType, CustomTypeParamShape } from './CustomType';
9
+ import { ModelIndexType, InternalModelIndexType } from './ModelIndex';
10
+ import { SecondaryIndexToIR } from './MappedTypes/MapSecondaryIndexes';
11
+ declare const brandName = "modelType";
12
+ type ModelFields = Record<string, ModelField<any, any, any> | ModelRelationalField<any, string, any, any> | RefType<any, any, any> | EnumType<EnumTypeParamShape> | CustomType<CustomTypeParamShape>>;
13
+ type InternalModelFields = Record<string, InternalField | InternalRelationalField>;
14
+ type ModelData = {
15
+ fields: ModelFields;
16
+ identifier: string[];
17
+ secondaryIndexes: ReadonlyArray<ModelIndexType<any, any, any, any, any>>;
18
+ authorization: Authorization<any, any, any>[];
19
+ };
20
+ type InternalModelData = ModelData & {
21
+ fields: InternalModelFields;
22
+ identifier: string[];
23
+ secondaryIndexes: ReadonlyArray<InternalModelIndexType>;
24
+ authorization: Authorization<any, any, any>[];
25
+ };
26
+ export type ModelTypeParamShape = {
27
+ fields: ModelFields;
28
+ identifier: string[];
29
+ secondaryIndexes: ReadonlyArray<SecondaryIndexIrShape>;
30
+ authorization: Authorization<any, any, any>[];
31
+ };
32
+ type SecondaryIndexFields<T extends Record<string, unknown>> = keyof {
33
+ [Field in keyof T as NonNullable<T[Field]> extends string | number ? Field : never]: T[Field];
34
+ } & string;
35
+ type ExtractType<T extends ModelTypeParamShape> = {
36
+ [FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends ModelField<any, any, any> ? FieldProp : never]: T['fields'][FieldProp] extends ModelField<infer R, any, any> ? R : never;
37
+ };
38
+ type GetRequiredFields<T> = {
39
+ [FieldProp in keyof T as T[FieldProp] extends NonNullable<T[FieldProp]> ? FieldProp : never]: T[FieldProp];
40
+ };
41
+ type IdentifierMap<T extends ModelTypeParamShape> = GetRequiredFields<ExtractType<T>>;
42
+ type IdentifierFields<T extends ModelTypeParamShape> = keyof IdentifierMap<T> & string;
43
+ type IdentifierType<T extends ModelTypeParamShape, Fields extends string = IdentifierFields<T>> = Array<Fields>;
44
+ export type AddRelationshipFieldsToModelTypeFields<Model, RelationshipFields extends Record<string, ModelRelationalField<ModelRelationalFieldParamShape, string, any, any>>> = Model extends ModelType<infer ModelParam extends ModelTypeParamShape, infer HiddenKeys> ? ModelType<SetTypeSubArg<ModelParam, 'fields', ModelParam['fields'] & RelationshipFields>, HiddenKeys> : never;
45
+ export type ModelType<T extends ModelTypeParamShape, K extends keyof ModelType<T> = never> = Omit<{
46
+ identifier<ID extends IdentifierType<T> = []>(identifier: ID): ModelType<SetTypeSubArg<T, 'identifier', ID>, K | 'identifier'>;
47
+ secondaryIndexes<const SecondaryIndexPKPool extends string = SecondaryIndexFields<ExtractType<T>>, const Indexes extends readonly ModelIndexType<string, string, unknown, readonly [], any>[] = readonly [], const IndexesIR extends readonly any[] = SecondaryIndexToIR<Indexes, ExtractType<T>>>(callback: (index: <PK extends SecondaryIndexPKPool>(pk: PK) => ModelIndexType<SecondaryIndexPKPool, PK, ReadonlyArray<Exclude<SecondaryIndexPKPool, PK>>>) => Indexes): ModelType<SetTypeSubArg<T, 'secondaryIndexes', IndexesIR>, K | 'secondaryIndexes'>;
48
+ authorization<AuthRuleType extends Authorization<any, any, any>>(rules: AuthRuleType[]): ModelType<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, K | 'authorization'>;
49
+ }, K> & Brand<typeof brandName>;
50
+ /**
51
+ * External representation of Model Type that exposes the `addRelationships` modifier.
52
+ * Used on the complete schema object.
53
+ */
54
+ export type SchemaModelType<T extends ModelType<ModelTypeParamShape, never | 'identifier'> = ModelType<ModelTypeParamShape, never | 'identifier'>, ModelName extends string = string, IsRDS extends boolean = false> = IsRDS extends true ? T & {
55
+ addRelationships<Param extends Record<string, ModelRelationalField<any, string, any, any>> = Record<never, never>>(relationships: Param): Record<ModelName, Param>;
56
+ fields: T extends ModelType<infer R extends ModelTypeParamShape, any> ? R['fields'] : never;
57
+ } : T;
58
+ /**
59
+ * Internal representation of Model Type that exposes the `data` property.
60
+ * Used at buildtime.
61
+ */
62
+ export type InternalModel = SchemaModelType<ModelType<ModelTypeParamShape>, string, true> & {
63
+ data: InternalModelData;
64
+ };
65
+ /**
66
+ * Model Type type guard
67
+ * @param modelType - api-next ModelType
68
+ * @returns true if the given value is a ModelSchema
69
+ */
70
+ export declare const isSchemaModelType: (modelType: any | SchemaModelType) => modelType is ModelType<ModelTypeParamShape, "identifier">;
71
+ /**
72
+ * A data model that creates a matching Amazon DynamoDB table and provides create, read (list and get), update,
73
+ * delete, and subscription APIs.
74
+ *
75
+ * @param fields database table fields. Supports scalar types and relationship types.
76
+ * @returns a data model definition
77
+ */
78
+ export declare function model<T extends ModelFields>(fields: T): ModelType<{
79
+ fields: T;
80
+ identifier: Array<'id'>;
81
+ secondaryIndexes: [];
82
+ authorization: [];
83
+ }>;
84
+ export {};
85
+ //# sourceMappingURL=ModelType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelType.d.ts","sourceRoot":"","sources":["../../src/ModelType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACtB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,KAAK,EAAS,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EACV,oBAAoB,EACpB,uBAAuB,EACvB,8BAA8B,EAC/B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EACL,cAAc,EACd,sBAAsB,EAEvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,QAAA,MAAM,SAAS,cAAc,CAAC;AAE9B,KAAK,WAAW,GAAG,MAAM,CACvB,MAAM,EACJ,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GACzB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,GAC3C,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GACtB,QAAQ,CAAC,kBAAkB,CAAC,GAC5B,UAAU,CAAC,oBAAoB,CAAC,CACnC,CAAC;AAEF,KAAK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AAe,CACzB,CAAC,SAAS,SAAS,CAAC,mBAAmB,EAAE,KAAK,GAAG,YAAY,CAAC,GAAG,SAAS,CACxE,mBAAmB,EACnB,KAAK,GAAG,YAAY,CACrB,EACD,SAAS,SAAS,MAAM,GAAG,MAAM,EACjC,KAAK,SAAS,OAAO,GAAG,KAAK,IAC3B,KAAK,SAAS,IAAI,GAClB,CAAC,GAAG;IACF,gBAAgB,CACd,KAAK,SAAS,MAAM,CAClB,MAAM,EACN,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAC5C,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAExB,aAAa,EAAE,KAAK,GACnB,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5B,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,SAAS,mBAAmB,EAAE,GAAG,CAAC,GACjE,CAAC,CAAC,QAAQ,CAAC,GACX,KAAK,CAAC;CACX,GACD,CAAC,CAAC;AAEN;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,eAAe,CACzC,SAAS,CAAC,mBAAmB,CAAC,EAC9B,MAAM,EACN,IAAI,CACL,GAAG;IACF,IAAI,EAAE,iBAAiB,CAAC;CACzB,CAAC;AAuCF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,cACjB,GAAG,GAAG,eAAe,8DAYjC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,WAAW,EACzC,MAAM,EAAE,CAAC,GACR,SAAS,CAAC;IACX,MAAM,EAAE,CAAC,CAAC;IACV,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACxB,gBAAgB,EAAE,EAAE,CAAC;IACrB,aAAa,EAAE,EAAE,CAAC;CACnB,CAAC,CAED"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.model = exports.isSchemaModelType = void 0;
4
+ const util_1 = require("./util");
5
+ const ModelIndex_1 = require("./ModelIndex");
6
+ const brandName = 'modelType';
7
+ function _model(fields) {
8
+ const data = {
9
+ fields,
10
+ identifier: ['id'],
11
+ secondaryIndexes: [],
12
+ authorization: [],
13
+ };
14
+ const builder = {
15
+ identifier(identifier) {
16
+ data.identifier = identifier;
17
+ return this;
18
+ },
19
+ secondaryIndexes(callback) {
20
+ data.secondaryIndexes = callback(ModelIndex_1.modelIndex);
21
+ return this;
22
+ },
23
+ authorization(rules) {
24
+ data.authorization = rules;
25
+ return this;
26
+ },
27
+ ...(0, util_1.brand)(brandName),
28
+ };
29
+ return {
30
+ ...builder,
31
+ data,
32
+ addRelationships(relationships) {
33
+ data.fields = { ...data.fields, ...relationships };
34
+ },
35
+ fields: data.fields,
36
+ };
37
+ }
38
+ /**
39
+ * Model Type type guard
40
+ * @param modelType - api-next ModelType
41
+ * @returns true if the given value is a ModelSchema
42
+ */
43
+ const isSchemaModelType = (modelType) => {
44
+ const internalType = modelType;
45
+ return (typeof internalType === 'object' &&
46
+ internalType.data !== undefined &&
47
+ internalType.data.fields !== undefined &&
48
+ internalType.data.authorization !== undefined &&
49
+ internalType.data.identifier !== undefined &&
50
+ internalType.data.secondaryIndexes !== undefined &&
51
+ typeof internalType.addRelationships === 'function');
52
+ };
53
+ exports.isSchemaModelType = isSchemaModelType;
54
+ /**
55
+ * A data model that creates a matching Amazon DynamoDB table and provides create, read (list and get), update,
56
+ * delete, and subscription APIs.
57
+ *
58
+ * @param fields database table fields. Supports scalar types and relationship types.
59
+ * @returns a data model definition
60
+ */
61
+ function model(fields) {
62
+ return _model(fields);
63
+ }
64
+ exports.model = model;
@@ -0,0 +1,59 @@
1
+ import { SetTypeSubArg } from '@aws-amplify/data-schema-types';
2
+ import { Brand } from './util';
3
+ import { Authorization } from './Authorization';
4
+ import { __auth } from './ModelField';
5
+ declare const brandName = "ref";
6
+ type RefTypeData = {
7
+ type: 'ref';
8
+ link: string;
9
+ valueRequired: boolean;
10
+ array: boolean;
11
+ arrayRequired: boolean;
12
+ mutationOperations: MutationOperations[];
13
+ authorization: Authorization<any, any, any>[];
14
+ };
15
+ export type RefTypeParamShape = {
16
+ type: 'ref';
17
+ link: string;
18
+ valueRequired: boolean;
19
+ array: boolean;
20
+ arrayRequired: boolean;
21
+ authorization: Authorization<any, any, any>[];
22
+ };
23
+ type MutationOperations = 'create' | 'update' | 'delete';
24
+ export type RefType<T extends RefTypeParamShape, K extends keyof RefType<T> = never, Auth = undefined> = Omit<{
25
+ /**
26
+ * Marks a field as required.
27
+ */
28
+ required(): RefType<SetTypeSubArg<T, T['array'] extends true ? 'arrayRequired' : 'valueRequired', true>, K | 'required'>;
29
+ /**
30
+ * Marks a field as an array of the specified ref type.
31
+ */
32
+ array(): RefType<SetTypeSubArg<T, 'array', true>, Exclude<K, 'required'> | 'array'>;
33
+ /**
34
+ * Configures field-level authorization rules. Pass in an array of authorizations `(a.allow.____)` to mix and match
35
+ * multiple authorization rules for this field.
36
+ */
37
+ authorization<AuthRuleType extends Authorization<any, any, any>>(rules: AuthRuleType[]): RefType<T, K | 'authorization', AuthRuleType>;
38
+ mutations(operations: MutationOperations[]): RefType<T, K | 'mutations'>;
39
+ }, K> & {
40
+ [__auth]?: Auth;
41
+ } & Brand<typeof brandName>;
42
+ /**
43
+ * Internal representation of Ref that exposes the `data` property.
44
+ * Used at buildtime.
45
+ */
46
+ export type InternalRef = RefType<RefTypeParamShape> & {
47
+ data: RefTypeData;
48
+ };
49
+ type RefTypeArgFactory<Link extends string> = {
50
+ type: 'ref';
51
+ link: Link;
52
+ valueRequired: false;
53
+ array: false;
54
+ arrayRequired: false;
55
+ authorization: [];
56
+ };
57
+ export declare function ref<Value extends string, T extends Value>(link: T): RefType<RefTypeArgFactory<T>, never, undefined>;
58
+ export {};
59
+ //# sourceMappingURL=RefType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RefType.d.ts","sourceRoot":"","sources":["../../src/RefType.ts"],"names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EG;IACH,KAAK,IAAI,OAAO,CACd,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAC/B,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,OAAO,CACjC,CAAC;IACF;;;OAGG;IACH,aAAa,CAAC,YAAY,SAAS,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC7D,KAAK,EAAE,YAAY,EAAE,GACpB,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,eAAe,EAAE,YAAY,CAAC,CAAC;IAEjD,SAAS,CAAC,UAAU,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC;CAC1E,EACD,CAAC,CACF,GAAG;IAEF,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC;CACjB,GAAG,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAQ5B;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAAG;IACrD,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AA0CF,KAAK,iBAAiB,CAAC,IAAI,SAAS,MAAM,IAAI;IAC5C,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,IAAI,CAAC;IACX,aAAa,EAAE,KAAK,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,KAAK,CAAC;IACrB,aAAa,EAAE,EAAE,CAAC;CACnB,CAAC;AAEF,wBAAgB,GAAG,CAAC,KAAK,SAAS,MAAM,EAAE,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,CAAC,mDAEjE"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ref = void 0;
4
+ const ModelField_1 = require("./ModelField");
5
+ const brandName = 'ref';
6
+ function brandedBuilder(builder) {
7
+ return builder;
8
+ }
9
+ function _ref(link) {
10
+ const data = {
11
+ type: 'ref',
12
+ link,
13
+ valueRequired: false,
14
+ array: false,
15
+ arrayRequired: false,
16
+ mutationOperations: [],
17
+ authorization: [],
18
+ };
19
+ const builder = brandedBuilder({
20
+ required() {
21
+ if (data.array) {
22
+ data.arrayRequired = true;
23
+ }
24
+ else {
25
+ data.valueRequired = true;
26
+ }
27
+ return this;
28
+ },
29
+ array() {
30
+ data.array = true;
31
+ return this;
32
+ },
33
+ authorization(rules) {
34
+ data.authorization = rules;
35
+ return this;
36
+ },
37
+ mutations(operations) {
38
+ data.mutationOperations = operations;
39
+ return this;
40
+ },
41
+ });
42
+ return { ...builder, data };
43
+ }
44
+ function ref(link) {
45
+ return _ref(link);
46
+ }
47
+ exports.ref = ref;
@@ -0,0 +1,11 @@
1
+ import { type InternalSchema } from './ModelSchema';
2
+ import { DerivedApiDefinition } from '@aws-amplify/data-schema-types';
3
+ /**
4
+ * Returns API definition from ModelSchema or string schema
5
+ * @param arg - { schema }
6
+ * @returns DerivedApiDefinition that conforms to IAmplifyGraphqlDefinition
7
+ */
8
+ export declare function processSchema(arg: {
9
+ schema: InternalSchema;
10
+ }): DerivedApiDefinition;
11
+ //# sourceMappingURL=SchemaProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaProcessor.d.ts","sourceRoot":"","sources":["../../src/SchemaProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAsBzE,OAAO,EACL,oBAAoB,EAMrB,MAAM,gCAAgC,CAAC;AA4nDxC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE;IACjC,MAAM,EAAE,cAAc,CAAC;CACxB,GAAG,oBAAoB,CAiBvB"}