@aws-amplify/data-schema 1.1.6 → 1.2.1
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/ModelSchema.js +19 -0
- package/dist/cjs/ModelSchema.js.map +1 -1
- package/dist/cjs/SchemaProcessor.js +1 -4
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/runtime/internals/APIClient.js +132 -22
- package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/list.js +4 -1
- package/dist/cjs/runtime/internals/operations/list.js.map +1 -1
- package/dist/cjs/runtime/utils/index.js +5 -1
- package/dist/cjs/runtime/utils/index.js.map +1 -1
- package/dist/cjs/runtime/utils/stringTransformation.js +13 -0
- package/dist/cjs/runtime/utils/stringTransformation.js.map +1 -0
- package/dist/esm/MappedTypes/MapIndexes.d.ts +13 -3
- package/dist/esm/ModelSchema.d.ts +13 -1
- package/dist/esm/ModelSchema.mjs +20 -1
- package/dist/esm/ModelSchema.mjs.map +1 -1
- package/dist/esm/ModelType.d.ts +1 -0
- package/dist/esm/SchemaProcessor.mjs +1 -4
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/runtime/client/index.d.ts +56 -7
- package/dist/esm/runtime/internals/APIClient.mjs +129 -18
- package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/list.mjs +4 -1
- package/dist/esm/runtime/internals/operations/list.mjs.map +1 -1
- package/dist/esm/runtime/utils/index.d.ts +2 -0
- package/dist/esm/runtime/utils/index.mjs +2 -0
- package/dist/esm/runtime/utils/index.mjs.map +1 -1
- package/dist/esm/runtime/utils/stringTransformation.d.ts +5 -0
- package/dist/esm/runtime/utils/stringTransformation.mjs +10 -0
- package/dist/esm/runtime/utils/stringTransformation.mjs.map +1 -0
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/MappedTypes/MapIndexes.ts +26 -3
- package/src/ModelSchema.ts +43 -1
- package/src/ModelType.ts +1 -1
- package/src/SchemaProcessor.ts +2 -7
- package/src/runtime/client/index.ts +68 -13
- package/src/runtime/internals/APIClient.ts +147 -27
- package/src/runtime/internals/operations/list.ts +6 -1
- package/src/runtime/utils/index.ts +2 -0
- package/src/runtime/utils/stringTransformation.ts +7 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/runtime/utils/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.findIndexByFields = exports.resolvePKFields = void 0;\nvar resolvePKFields_1 = require(\"./resolvePKFields\");\nObject.defineProperty(exports, \"resolvePKFields\", { enumerable: true, get: function () { return resolvePKFields_1.resolvePKFields; } });\nvar findIndexByFields_1 = require(\"./findIndexByFields\");\nObject.defineProperty(exports, \"findIndexByFields\", { enumerable: true, get: function () { return findIndexByFields_1.findIndexByFields; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,iBAAiB,GAAG,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/runtime/utils/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.capitalize = exports.resolveOwnerFields = exports.findIndexByFields = exports.resolvePKFields = void 0;\nvar resolvePKFields_1 = require(\"./resolvePKFields\");\nObject.defineProperty(exports, \"resolvePKFields\", { enumerable: true, get: function () { return resolvePKFields_1.resolvePKFields; } });\nvar findIndexByFields_1 = require(\"./findIndexByFields\");\nObject.defineProperty(exports, \"findIndexByFields\", { enumerable: true, get: function () { return findIndexByFields_1.findIndexByFields; } });\nvar resolveOwnerFields_1 = require(\"./resolveOwnerFields\");\nObject.defineProperty(exports, \"resolveOwnerFields\", { enumerable: true, get: function () { return resolveOwnerFields_1.resolveOwnerFields; } });\nvar stringTransformation_1 = require(\"./stringTransformation\");\nObject.defineProperty(exports, \"capitalize\", { enumerable: true, get: function () { return stringTransformation_1.capitalize; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,GAAG,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;AAC/G,IAAI,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AACrD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,iBAAiB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,iBAAiB,CAAC,eAAe,CAAC,EAAE,EAAE,CAAC,CAAC;AACxI,IAAI,mBAAmB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AACzD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,mBAAmB,CAAC,iBAAiB,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9I,IAAI,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAC3D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,oBAAoB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,oBAAoB,CAAC,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC;AACjJ,IAAI,sBAAsB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAC/D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,sBAAsB,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.capitalize = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* @param s string to capitalize
|
|
7
|
+
* @returns capitalized string
|
|
8
|
+
*/
|
|
9
|
+
function capitalize(s) {
|
|
10
|
+
return `${s[0].toUpperCase()}${s.slice(1)}`;
|
|
11
|
+
}
|
|
12
|
+
exports.capitalize = capitalize;
|
|
13
|
+
//# sourceMappingURL=stringTransformation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringTransformation.js","sources":["../../../../src/runtime/utils/stringTransformation.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.capitalize = void 0;\n/**\n * @param s string to capitalize\n * @returns capitalized string\n */\nfunction capitalize(s) {\n return `${s[0].toUpperCase()}${s.slice(1)}`;\n}\nexports.capitalize = capitalize;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;AAC5B;AACA;AACA;AACA;AACA,SAAS,UAAU,CAAC,CAAC,EAAE;AACvB,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AACD,OAAO,CAAC,UAAU,GAAG,UAAU;;"}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { ModelIndexType } from '../ModelIndex';
|
|
2
2
|
type ModelIndexTypeShape = ModelIndexType<any, any, any, any, any>;
|
|
3
|
-
export type PrimaryIndexFieldsToIR<IdxFields extends ReadonlyArray<string>, ResolvedFields> = IdxFields extends readonly [
|
|
3
|
+
export type PrimaryIndexFieldsToIR<IdxFields extends ReadonlyArray<string>, ResolvedFields> = IdxFields extends readonly [
|
|
4
|
+
infer PK,
|
|
5
|
+
...infer SK extends never | readonly string[]
|
|
6
|
+
] ? {
|
|
4
7
|
pk: PK extends keyof ResolvedFields ? {
|
|
5
8
|
[Key in PK]: Exclude<ResolvedFields[PK], null> & (string | number);
|
|
6
9
|
} : never;
|
|
7
10
|
sk: unknown extends SK ? never : ResolvedSortKeyFields<SK, ResolvedFields>;
|
|
11
|
+
compositeSk: SK['length'] extends 0 | 1 ? never : CompositeSkFieldName<ArrayShift<SK>, SK[0]>;
|
|
8
12
|
} : never;
|
|
13
|
+
type ArrayShift<Arr extends ReadonlyArray<any>> = Arr extends readonly [
|
|
14
|
+
infer _Shift,
|
|
15
|
+
...infer Rest
|
|
16
|
+
] ? Rest : never;
|
|
17
|
+
type CompositeSkFieldName<SK, Result extends string = ''> = SK extends readonly [infer A extends string, ...infer B extends string[]] ? CompositeSkFieldName<B, `${Result}${Capitalize<A>}`> : Result;
|
|
9
18
|
/**
|
|
10
19
|
* Maps array of ModelIndexType to SecondaryIndexIrShape (defined in in data-schema-types)
|
|
11
20
|
* */
|
|
@@ -29,13 +38,14 @@ export type SecondaryIndexToIR<Idxs extends ReadonlyArray<ModelIndexTypeShape>,
|
|
|
29
38
|
*
|
|
30
39
|
* @remarks - the IR type alias is defined as SecondaryIndexIrShape in data-schema-types
|
|
31
40
|
*/
|
|
32
|
-
type SingleIndexIrFromType<Idx extends ModelIndexTypeShape, ResolvedFields> = Idx extends ModelIndexType<any, infer PK extends string, infer SK, infer QueryField extends string | never, any> ? {
|
|
33
|
-
defaultQueryFieldSuffix:
|
|
41
|
+
type SingleIndexIrFromType<Idx extends ModelIndexTypeShape, ResolvedFields> = Idx extends ModelIndexType<any, infer PK extends string, infer SK extends readonly string[], infer QueryField extends string | never, any> ? {
|
|
42
|
+
defaultQueryFieldSuffix: QueryFieldLabelFromTuple<SK, Capitalize<PK>>;
|
|
34
43
|
queryField: QueryField;
|
|
35
44
|
pk: PK extends keyof ResolvedFields ? {
|
|
36
45
|
[Key in PK]: Exclude<ResolvedFields[PK], null>;
|
|
37
46
|
} : never;
|
|
38
47
|
sk: unknown extends SK ? never : ResolvedSortKeyFields<SK, ResolvedFields>;
|
|
48
|
+
compositeSk: SK['length'] extends 0 | 1 ? never : CompositeSkFieldName<ArrayShift<SK>, SK[0]>;
|
|
39
49
|
} : never;
|
|
40
50
|
/**
|
|
41
51
|
* @typeParam SK - tuple of SortKey field names, e.g. ['viewCount', 'createdAt']
|
|
@@ -12,6 +12,8 @@ export type RDSSchemaBrand = Brand<typeof rdsSchemaBrandName>;
|
|
|
12
12
|
export declare const ddbSchemaBrandName = "DDBSchema";
|
|
13
13
|
export type DDBSchemaBrand = Brand<typeof ddbSchemaBrandName>;
|
|
14
14
|
type SchemaContent = BaseModelType | CustomType<CustomTypeParamShape> | EnumType | CustomOperation<CustomOperationParamShape, any>;
|
|
15
|
+
type AddToSchemaContent = Exclude<SchemaContent, BaseModelType>;
|
|
16
|
+
type AddToSchemaContents = Record<string, AddToSchemaContent>;
|
|
15
17
|
type NonEmpty<T> = keyof T extends never ? never : T;
|
|
16
18
|
type ModelSchemaContents = Record<string, SchemaContent>;
|
|
17
19
|
type InternalSchemaModels = Record<string, InternalModel | EnumType<any> | CustomType<any> | InternalCustom>;
|
|
@@ -39,10 +41,20 @@ export type GenericModelSchema<T extends ModelSchemaParamShape> = BaseSchema<T>
|
|
|
39
41
|
export type ModelSchema<T extends ModelSchemaParamShape, UsedMethods extends 'authorization' | 'relationships' = never> = Omit<{
|
|
40
42
|
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(callback: (allow: AllowModifier) => AuthRules | AuthRules[]) => ModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
|
|
41
43
|
}, UsedMethods> & BaseSchema<T> & DDBSchemaBrand;
|
|
42
|
-
type RDSModelSchemaFunctions = 'addQueries' | 'addMutations' | 'addSubscriptions' | 'authorization' | 'setRelationships' | 'setAuthorization' | 'renameModelFields' | 'renameModels';
|
|
44
|
+
type RDSModelSchemaFunctions = 'addToSchema' | 'addQueries' | 'addMutations' | 'addSubscriptions' | 'authorization' | 'setRelationships' | 'setAuthorization' | 'renameModelFields' | 'renameModels';
|
|
43
45
|
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
|
+
addToSchema: <AddedTypes extends AddToSchemaContents>(types: AddedTypes) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & AddedTypes>, UsedMethods | 'addToSchema'>;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated use `addToSchema()` to add operations to a SQL schema
|
|
49
|
+
*/
|
|
44
50
|
addQueries: <Queries extends Record<string, QueryCustomOperation>>(types: Queries) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Queries>, UsedMethods | 'addQueries'>;
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated use `addToSchema()` to add operations to a SQL schema
|
|
53
|
+
*/
|
|
45
54
|
addMutations: <Mutations extends Record<string, MutationCustomOperation>>(types: Mutations) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Mutations>, UsedMethods | 'addMutations'>;
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated use `addToSchema()` to add operations to a SQL schema
|
|
57
|
+
*/
|
|
46
58
|
addSubscriptions: <Subscriptions extends Record<string, SubscriptionCustomOperation>>(types: Subscriptions) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Subscriptions>, UsedMethods | 'addSubscriptions'>;
|
|
47
59
|
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(callback: (allow: AllowModifier) => AuthRules | AuthRules[]) => RDSModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
|
|
48
60
|
setAuthorization: (callback: (models: BaseSchema<T, true>['models'], schema: RDSModelSchema<T, UsedMethods | 'setAuthorization'>) => void) => RDSModelSchema<T>;
|
package/dist/esm/ModelSchema.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isSchemaModelType } from './ModelType.mjs';
|
|
2
2
|
import { processSchema } from './SchemaProcessor.mjs';
|
|
3
3
|
import { allow } from './Authorization.mjs';
|
|
4
|
-
import { brand } from './util/Brand.mjs';
|
|
4
|
+
import { brand, getBrand } from './util/Brand.mjs';
|
|
5
5
|
|
|
6
6
|
const rdsSchemaBrandName = 'RDSSchema';
|
|
7
7
|
const rdsSchemaBrand = brand(rdsSchemaBrandName);
|
|
@@ -32,6 +32,19 @@ const filterSchemaModelTypes = (schemaContents) => {
|
|
|
32
32
|
const isModelSchema = (schema) => {
|
|
33
33
|
return typeof schema === 'object' && schema.data !== undefined;
|
|
34
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Ensures that only supported entities are being added to the SQL schema through `addToSchema`
|
|
37
|
+
* Models are not supported for brownfield SQL
|
|
38
|
+
*
|
|
39
|
+
* @param types - purposely widened to ModelSchemaContents, because we need to validate at runtime that a model is not being passed in here
|
|
40
|
+
*/
|
|
41
|
+
function validateAddToSchema(types) {
|
|
42
|
+
for (const [name, type] of Object.entries(types)) {
|
|
43
|
+
if (getBrand(type) === 'modelType') {
|
|
44
|
+
throw new Error(`Invalid value specified for ${name} in addToSchema(). Models cannot be manually added to a SQL schema.`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
35
48
|
function _rdsSchema(types, config) {
|
|
36
49
|
const data = {
|
|
37
50
|
types,
|
|
@@ -52,6 +65,12 @@ function _rdsSchema(types, config) {
|
|
|
52
65
|
const { authorization: _, ...rest } = this;
|
|
53
66
|
return rest;
|
|
54
67
|
},
|
|
68
|
+
addToSchema(types) {
|
|
69
|
+
validateAddToSchema(types);
|
|
70
|
+
this.data.types = { ...this.data.types, ...types };
|
|
71
|
+
const { addToSchema: _, ...rest } = this;
|
|
72
|
+
return rest;
|
|
73
|
+
},
|
|
55
74
|
addQueries(types) {
|
|
56
75
|
this.data.types = { ...this.data.types, ...types };
|
|
57
76
|
const { addQueries: _, ...rest } = this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelSchema.mjs","sources":["../../src/ModelSchema.ts"],"sourcesContent":["import { isSchemaModelType, } from './ModelType';\nimport { processSchema } from './SchemaProcessor';\nimport { allow } from './Authorization';\nimport { brand } from './util';\nexport const rdsSchemaBrandName = 'RDSSchema';\nexport const rdsSchemaBrand = brand(rdsSchemaBrandName);\nexport const ddbSchemaBrandName = 'DDBSchema';\nconst ddbSchemaBrand = brand(ddbSchemaBrandName);\n/**\n * Filter the schema types down to only include the ModelTypes as SchemaModelType\n *\n * @param schemaContents The object containing all SchemaContent for this schema\n * @returns Only the schemaContents that are ModelTypes, coerced to the SchemaModelType surface\n */\nconst filterSchemaModelTypes = (schemaContents) => {\n const modelTypes = {};\n if (schemaContents) {\n Object.entries(schemaContents).forEach(([key, content]) => {\n if (isSchemaModelType(content)) {\n modelTypes[key] = content;\n }\n });\n }\n return modelTypes;\n};\n/**\n * Model Schema type guard\n * @param schema - api-next ModelSchema or string\n * @returns true if the given value is a ModelSchema\n */\nexport const isModelSchema = (schema) => {\n return typeof schema === 'object' && schema.data !== undefined;\n};\nfunction _rdsSchema(types, config) {\n const data = {\n types,\n authorization: [],\n configuration: config,\n };\n const models = filterSchemaModelTypes(data.types);\n return {\n data,\n models,\n transform() {\n const internalSchema = { data };\n return processSchema({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(allow);\n this.data.authorization = Array.isArray(rules) ? rules : [rules];\n const { authorization: _, ...rest } = this;\n return rest;\n },\n addQueries(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addQueries: _, ...rest } = this;\n return rest;\n },\n addMutations(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addMutations: _, ...rest } = this;\n return rest;\n },\n addSubscriptions(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addSubscriptions: _, ...rest } = this;\n return rest;\n },\n setAuthorization(callback) {\n callback(models, this);\n const { setAuthorization: _, ...rest } = this;\n return rest;\n },\n setRelationships(callback) {\n const { setRelationships: _, ...rest } = this;\n // The relationships are added via `models.<Model>.relationships`\n // modifiers that's being called within the callback. They are modifying\n // by references on each model, so there is not anything else to be done\n // here.\n callback(models);\n return rest;\n },\n renameModels(callback) {\n const { renameModels: _, ...rest } = this;\n // returns an array of tuples [curName, newName]\n const changeLog = callback();\n changeLog.forEach(([curName, newName]) => {\n const currentType = data.types[curName];\n if (currentType === undefined) {\n throw new Error(`Invalid renameModels call. ${curName} is not defined in the schema`);\n }\n if (typeof newName !== 'string' || newName.length < 1) {\n throw new Error(`Invalid renameModels call. New name must be a non-empty string. Received: \"${newName}\"`);\n }\n models[newName] = currentType;\n data.types[newName] = currentType;\n models[newName].data.originalName = curName;\n delete models[curName];\n delete data.types[curName];\n });\n return rest;\n },\n ...rdsSchemaBrand,\n };\n}\nfunction _ddbSchema(types, config) {\n const data = {\n types,\n authorization: [],\n configuration: config,\n };\n return {\n data,\n transform() {\n const internalSchema = { data };\n return processSchema({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(allow);\n this.data.authorization = Array.isArray(rules) ? rules : [rules];\n const { authorization: _, ...rest } = this;\n return rest;\n },\n models: filterSchemaModelTypes(data.types),\n ...ddbSchemaBrand,\n };\n}\nfunction bindConfigToSchema(config) {\n return (types) => {\n return (config.database.engine === 'dynamodb'\n ? _ddbSchema(types, config)\n : _rdsSchema(types, config));\n };\n}\n/**\n * The API and data model definition for Amplify Data. Pass in `{ <NAME>: a.model(...) }` to create a database table\n * and exposes CRUDL operations via an API.\n * @param types The API and data model definition\n * @returns An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`)\n * or with the Amplify Data CDK construct (`@aws-amplify/data-construct`)\n */\nexport const schema = bindConfigToSchema({ database: { engine: 'dynamodb' } });\n/**\n * Configure wraps schema definition with non-default config to allow usecases other than\n * the default DynamoDB use-case.\n *\n * @param config The SchemaConfig augments the schema with content like the database type\n * @returns\n */\nexport function configure(config) {\n return {\n schema: bindConfigToSchema(config),\n };\n}\nexport function isCustomPathData(obj) {\n return ('stack' in obj &&\n (typeof obj.stack === 'undefined' || typeof obj.stack === 'string') &&\n 'entry' in obj &&\n typeof obj.entry === 'string');\n}\n"],"names":[],"mappings":";;;;;AAIY,MAAC,kBAAkB,GAAG,YAAY;AAClC,MAAC,cAAc,GAAG,KAAK,CAAC,kBAAkB,EAAE;AAC5C,MAAC,kBAAkB,GAAG,YAAY;AAC9C,MAAM,cAAc,GAAG,KAAK,CAAC,kBAAkB,CAAC,CAAC;AACjD;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,sBAAsB,GAAG,CAAC,cAAc,KAAK;AACnD,IAAI,MAAM,UAAU,GAAG,EAAE,CAAC;AAC1B,IAAI,IAAI,cAAc,EAAE;AACxB,QAAQ,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK;AACnE,YAAY,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;AAC5C,gBAAgB,UAAU,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;AAC1C,aAAa;AACb,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,UAAU,CAAC;AACtB,CAAC,CAAC;AACF;AACA;AACA;AACA;AACA;AACY,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KAAK,KAAK,WAAW,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC;AAC3E,QAAQ,OAAO,IAAI,GAAG;AACtB,QAAQ,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,EAAE;AACvC;;;;"}
|
|
1
|
+
{"version":3,"file":"ModelSchema.mjs","sources":["../../src/ModelSchema.ts"],"sourcesContent":["import { isSchemaModelType, } from './ModelType';\nimport { processSchema } from './SchemaProcessor';\nimport { allow } from './Authorization';\nimport { brand, getBrand } from './util';\nexport const rdsSchemaBrandName = 'RDSSchema';\nexport const rdsSchemaBrand = brand(rdsSchemaBrandName);\nexport const ddbSchemaBrandName = 'DDBSchema';\nconst ddbSchemaBrand = brand(ddbSchemaBrandName);\n/**\n * Filter the schema types down to only include the ModelTypes as SchemaModelType\n *\n * @param schemaContents The object containing all SchemaContent for this schema\n * @returns Only the schemaContents that are ModelTypes, coerced to the SchemaModelType surface\n */\nconst filterSchemaModelTypes = (schemaContents) => {\n const modelTypes = {};\n if (schemaContents) {\n Object.entries(schemaContents).forEach(([key, content]) => {\n if (isSchemaModelType(content)) {\n modelTypes[key] = content;\n }\n });\n }\n return modelTypes;\n};\n/**\n * Model Schema type guard\n * @param schema - api-next ModelSchema or string\n * @returns true if the given value is a ModelSchema\n */\nexport const isModelSchema = (schema) => {\n return typeof schema === 'object' && schema.data !== undefined;\n};\n/**\n * Ensures that only supported entities are being added to the SQL schema through `addToSchema`\n * Models are not supported for brownfield SQL\n *\n * @param types - purposely widened to ModelSchemaContents, because we need to validate at runtime that a model is not being passed in here\n */\nfunction validateAddToSchema(types) {\n for (const [name, type] of Object.entries(types)) {\n if (getBrand(type) === 'modelType') {\n throw new Error(`Invalid value specified for ${name} in addToSchema(). Models cannot be manually added to a SQL schema.`);\n }\n }\n}\nfunction _rdsSchema(types, config) {\n const data = {\n types,\n authorization: [],\n configuration: config,\n };\n const models = filterSchemaModelTypes(data.types);\n return {\n data,\n models,\n transform() {\n const internalSchema = { data };\n return processSchema({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(allow);\n this.data.authorization = Array.isArray(rules) ? rules : [rules];\n const { authorization: _, ...rest } = this;\n return rest;\n },\n addToSchema(types) {\n validateAddToSchema(types);\n this.data.types = { ...this.data.types, ...types };\n const { addToSchema: _, ...rest } = this;\n return rest;\n },\n addQueries(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addQueries: _, ...rest } = this;\n return rest;\n },\n addMutations(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addMutations: _, ...rest } = this;\n return rest;\n },\n addSubscriptions(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addSubscriptions: _, ...rest } = this;\n return rest;\n },\n setAuthorization(callback) {\n callback(models, this);\n const { setAuthorization: _, ...rest } = this;\n return rest;\n },\n setRelationships(callback) {\n const { setRelationships: _, ...rest } = this;\n // The relationships are added via `models.<Model>.relationships`\n // modifiers that's being called within the callback. They are modifying\n // by references on each model, so there is not anything else to be done\n // here.\n callback(models);\n return rest;\n },\n renameModels(callback) {\n const { renameModels: _, ...rest } = this;\n // returns an array of tuples [curName, newName]\n const changeLog = callback();\n changeLog.forEach(([curName, newName]) => {\n const currentType = data.types[curName];\n if (currentType === undefined) {\n throw new Error(`Invalid renameModels call. ${curName} is not defined in the schema`);\n }\n if (typeof newName !== 'string' || newName.length < 1) {\n throw new Error(`Invalid renameModels call. New name must be a non-empty string. Received: \"${newName}\"`);\n }\n models[newName] = currentType;\n data.types[newName] = currentType;\n models[newName].data.originalName = curName;\n delete models[curName];\n delete data.types[curName];\n });\n return rest;\n },\n ...rdsSchemaBrand,\n };\n}\nfunction _ddbSchema(types, config) {\n const data = {\n types,\n authorization: [],\n configuration: config,\n };\n return {\n data,\n transform() {\n const internalSchema = { data };\n return processSchema({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(allow);\n this.data.authorization = Array.isArray(rules) ? rules : [rules];\n const { authorization: _, ...rest } = this;\n return rest;\n },\n models: filterSchemaModelTypes(data.types),\n ...ddbSchemaBrand,\n };\n}\nfunction bindConfigToSchema(config) {\n return (types) => {\n return (config.database.engine === 'dynamodb'\n ? _ddbSchema(types, config)\n : _rdsSchema(types, config));\n };\n}\n/**\n * The API and data model definition for Amplify Data. Pass in `{ <NAME>: a.model(...) }` to create a database table\n * and exposes CRUDL operations via an API.\n * @param types The API and data model definition\n * @returns An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`)\n * or with the Amplify Data CDK construct (`@aws-amplify/data-construct`)\n */\nexport const schema = bindConfigToSchema({ database: { engine: 'dynamodb' } });\n/**\n * Configure wraps schema definition with non-default config to allow usecases other than\n * the default DynamoDB use-case.\n *\n * @param config The SchemaConfig augments the schema with content like the database type\n * @returns\n */\nexport function configure(config) {\n return {\n schema: bindConfigToSchema(config),\n };\n}\nexport function isCustomPathData(obj) {\n return ('stack' in obj &&\n (typeof obj.stack === 'undefined' || typeof obj.stack === 'string') &&\n 'entry' in obj &&\n typeof obj.entry === 'string');\n}\n"],"names":[],"mappings":";;;;;AAIY,MAAC,kBAAkB,GAAG,YAAY;AAClC,MAAC,cAAc,GAAG,KAAK,CAAC,kBAAkB,EAAE;AAC5C,MAAC,kBAAkB,GAAG,YAAY;AAC9C,MAAM,cAAc,GAAG,KAAK,CAAC,kBAAkB,CAAC,CAAC;AACjD;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,sBAAsB,GAAG,CAAC,cAAc,KAAK;AACnD,IAAI,MAAM,UAAU,GAAG,EAAE,CAAC;AAC1B,IAAI,IAAI,cAAc,EAAE;AACxB,QAAQ,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK;AACnE,YAAY,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;AAC5C,gBAAgB,UAAU,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;AAC1C,aAAa;AACb,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAA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AC,IAAI,CAAC,KAAK,CAAC;AAClD,QAAQ,GAAG,cAAc;AACzB,KAAK,CAAC;AACN,CAAC;AACD,SAAS,kBAAkB,CAAC,MAAM,EAAE;AACpC,IAAI,OAAO,CAAC,KAAK,KAAK;AACtB,QAAQ,QAAQ,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,UAAU;AACrD,cAAc,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC;AACvC,cAAc,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE;AACzC,KAAK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE;AAC/E;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,CAAC,MAAM,EAAE;AAClC,IAAI,OAAO;AACX,QAAQ,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC;AAC1C,KAAK,CAAC;AACN,CAAC;AACM,SAAS,gBAAgB,CAAC,GAAG,EAAE;AACtC,IAAI,QAAQ,OAAO,IAAI,GAAG;AAC1B,SAAS,OAAO,GAAG,CAAC,KAAK,KAAK,WAAW,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC;AAC3E,QAAQ,OAAO,IAAI,GAAG;AACtB,QAAQ,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,EAAE;AACvC;;;;"}
|
package/dist/esm/ModelType.d.ts
CHANGED
|
@@ -736,7 +736,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
736
736
|
const databaseType = schema.data.configuration.database.engine === 'dynamodb'
|
|
737
737
|
? 'dynamodb'
|
|
738
738
|
: 'sql';
|
|
739
|
-
const staticSchema =
|
|
739
|
+
const staticSchema = databaseType === 'sql';
|
|
740
740
|
const topLevelTypes = sortTopLevelTypes(Object.entries(schema.data.types));
|
|
741
741
|
const { schemaAuth, functionSchemaAccess } = extractFunctionSchemaAccess(schema.data.authorization);
|
|
742
742
|
const getRefType = getRefTypeForSchema(schema);
|
|
@@ -800,9 +800,6 @@ const schemaPreprocessor = (schema) => {
|
|
|
800
800
|
const identifier = typeDef.data.identifier;
|
|
801
801
|
const [partitionKey] = identifier;
|
|
802
802
|
const { authString, authFields } = calculateAuth(mostRelevantAuthRules);
|
|
803
|
-
if (authString == '') {
|
|
804
|
-
throw new Error(`Model \`${typeName}\` is missing authorization rules. Add global rules to the schema or ensure every model has its own rules.`);
|
|
805
|
-
}
|
|
806
803
|
const fieldLevelAuthRules = processFieldLevelAuthRules(fields, authFields);
|
|
807
804
|
validateStaticFields(fields, authFields);
|
|
808
805
|
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey);
|