@aws-amplify/data-schema 1.1.2 → 1.1.4

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 (32) hide show
  1. package/dist/cjs/MappedTypes/{MapSecondaryIndexes.js → MapIndexes.js} +1 -1
  2. package/dist/cjs/MappedTypes/MapIndexes.js.map +1 -0
  3. package/dist/cjs/ModelSchema.js +1 -0
  4. package/dist/cjs/ModelSchema.js.map +1 -1
  5. package/dist/cjs/SchemaProcessor.js +4 -1
  6. package/dist/cjs/SchemaProcessor.js.map +1 -1
  7. package/dist/esm/Authorization.d.ts +2 -2
  8. package/dist/esm/MappedTypes/ImplicitFieldInjector.d.ts +15 -5
  9. package/dist/esm/MappedTypes/{MapSecondaryIndexes.d.ts → MapIndexes.d.ts} +6 -0
  10. package/dist/esm/MappedTypes/MapIndexes.mjs +2 -0
  11. package/dist/esm/MappedTypes/MapIndexes.mjs.map +1 -0
  12. package/dist/esm/MappedTypes/ModelMetadata.d.ts +12 -5
  13. package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +3 -2
  14. package/dist/esm/ModelSchema.mjs +1 -0
  15. package/dist/esm/ModelSchema.mjs.map +1 -1
  16. package/dist/esm/ModelType.d.ts +23 -25
  17. package/dist/esm/SchemaProcessor.mjs +4 -1
  18. package/dist/esm/SchemaProcessor.mjs.map +1 -1
  19. package/dist/esm/runtime/client/index.d.ts +26 -15
  20. package/dist/meta/cjs.tsbuildinfo +1 -1
  21. package/package.json +1 -1
  22. package/src/MappedTypes/ImplicitFieldInjector.ts +22 -14
  23. package/src/MappedTypes/{MapSecondaryIndexes.ts → MapIndexes.ts} +16 -0
  24. package/src/MappedTypes/ModelMetadata.ts +17 -12
  25. package/src/MappedTypes/ResolveFieldProperties.ts +3 -2
  26. package/src/ModelSchema.ts +2 -1
  27. package/src/ModelType.ts +46 -46
  28. package/src/SchemaProcessor.ts +6 -3
  29. package/src/runtime/client/index.ts +52 -25
  30. package/dist/cjs/MappedTypes/MapSecondaryIndexes.js.map +0 -1
  31. package/dist/esm/MappedTypes/MapSecondaryIndexes.mjs +0 -2
  32. package/dist/esm/MappedTypes/MapSecondaryIndexes.mjs.map +0 -1
@@ -1,9 +1,10 @@
1
1
  import { type UnionToIntersection, type ExcludeEmpty } from '@aws-amplify/data-schema-types';
2
+ import { type PrimaryIndexIrShape } from '../runtime/';
2
3
  import type { ModelType } from '../ModelType';
3
4
  import type { ModelRelationalFieldParamShape } from '../ModelRelationalField';
4
5
  export type ModelIdentifier<T> = {
5
- [Property in keyof T]: T[Property] extends ModelType<infer R, any> ? R['identifier'] extends any[] ? {
6
- identifier: R['identifier'][number];
6
+ [Property in keyof T]: T[Property] extends ModelType<infer R, any> ? R['identifier'] extends PrimaryIndexIrShape ? {
7
+ identifier: R['identifier'];
7
8
  } : never : never;
8
9
  };
9
10
  export type ModelSecondaryIndexes<T> = {
@@ -11,7 +12,9 @@ export type ModelSecondaryIndexes<T> = {
11
12
  secondaryIndexes: R['secondaryIndexes'];
12
13
  } : never : never;
13
14
  };
14
- export type RelationalMetadata<ResolvedSchema, ResolvedFields extends Record<string, unknown>, IdentifierMeta extends Record<string, any>> = UnionToIntersection<ExcludeEmpty<{
15
+ export type RelationalMetadata<ResolvedSchema, ResolvedFields extends Record<string, unknown>, IdentifierMeta extends Record<string, {
16
+ identifier: PrimaryIndexIrShape;
17
+ }>> = UnionToIntersection<ExcludeEmpty<{
15
18
  [ModelName in keyof ResolvedSchema]: {
16
19
  [Field in keyof ResolvedSchema[ModelName] as ResolvedSchema[ModelName][Field] extends ModelRelationalFieldParamShape ? ResolvedSchema[ModelName][Field]['relationshipType'] extends 'hasOne' | 'belongsTo' ? ModelName : never : never]: ResolvedSchema[ModelName][Field] extends ModelRelationalFieldParamShape ? ResolvedSchema[ModelName][Field] extends ModelRelationalFieldParamShape ? ResolvedSchema[ModelName][Field]['relationshipType'] extends 'hasMany' ? {
17
20
  relationalInputFields: Partial<Record<`${Uncapitalize<ModelName & string>}`, NormalizeInputFields<ResolvedFields[ModelName & string], ExtractModelIdentifier<ModelName, IdentifierMeta>>>>;
@@ -20,6 +23,10 @@ export type RelationalMetadata<ResolvedSchema, ResolvedFields extends Record<str
20
23
  } : never : never;
21
24
  };
22
25
  }[keyof ResolvedSchema]>>;
23
- type ExtractModelIdentifier<ModelName, IdentifierMeta> = ModelName extends keyof IdentifierMeta ? IdentifierMeta[ModelName] : never;
24
- type NormalizeInputFields<ModelFields, IdentifierMeta extends Record<string, any>> = Partial<Omit<ModelFields, IdentifierMeta['identifier']>> & Required<Pick<ModelFields, IdentifierMeta['identifier']>>;
26
+ type ExtractModelIdentifier<ModelName, IdentifierMeta extends Record<string, {
27
+ identifier: PrimaryIndexIrShape;
28
+ }>> = ModelName extends keyof IdentifierMeta ? IdentifierMeta[ModelName] : never;
29
+ type NormalizeInputFields<ModelFields, IdentifierMeta extends {
30
+ identifier: PrimaryIndexIrShape;
31
+ }, IdFields extends keyof ModelFields = (keyof IdentifierMeta['identifier']['pk'] & keyof ModelFields) | (IdentifierMeta['identifier']['sk'] extends never ? never : keyof IdentifierMeta['identifier']['sk'] & keyof ModelFields)> = Partial<Omit<ModelFields, IdFields>> & Required<Pick<ModelFields, IdFields>>;
25
32
  export {};
@@ -4,6 +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
8
  import type { ResolveSchema, SchemaTypes } from './ResolveSchema';
8
9
  import type { InjectImplicitModelFields } from './ImplicitFieldInjector';
9
10
  import type { ModelIdentifier } from './ModelMetadata';
@@ -13,9 +14,9 @@ import type { CustomType, CustomTypeParamShape } from '../CustomType';
13
14
  import type { EnumType, EnumTypeParamShape } from '../EnumType';
14
15
  import type { CustomOperation, CustomOperationParamShape } from '../CustomOperation';
15
16
  export type ResolveFieldProperties<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape, ResolvedSchema = ResolveSchema<Schema>, IdentifierMeta extends Record<string, {
16
- identifier: string;
17
+ identifier: PrimaryIndexIrShape;
17
18
  }> = ModelIdentifier<SchemaTypes<Schema>>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<ResolvedSchema, IdentifierMeta>, FieldsWithRelationships = ResolveModelsRelationalAndRefFields<FieldsWithInjectedImplicitFields, NonModelTypes>> = Intersection<FilterFieldTypes<MarkModelsNonNullableFieldsRequired<FieldsWithRelationships>>, FilterFieldTypes<MarkModelsNullableFieldsOptional<FieldsWithRelationships>>, FilterFieldTypes<ModelImpliedAuthFields<Schema>>>;
18
- export type ResolveStaticFieldProperties<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape, ImplicitModelsSchema, ResolvedSchema = ResolveSchema<Schema>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<ResolvedSchema & ImplicitModelsSchema, object>, FieldsWithRelationships = ResolveModelsRelationalAndRefFields<FieldsWithInjectedImplicitFields, NonModelTypes>> = Intersection<FilterFieldTypes<MarkModelsNonNullableFieldsRequired<FieldsWithRelationships>>, FilterFieldTypes<MarkModelsNullableFieldsOptional<FieldsWithRelationships>>>;
19
+ export type ResolveStaticFieldProperties<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape, ImplicitModelsSchema, ResolvedSchema = ResolveSchema<Schema>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<ResolvedSchema & ImplicitModelsSchema, never>, FieldsWithRelationships = ResolveModelsRelationalAndRefFields<FieldsWithInjectedImplicitFields, NonModelTypes>> = Intersection<FilterFieldTypes<MarkModelsNonNullableFieldsRequired<FieldsWithRelationships>>, FilterFieldTypes<MarkModelsNullableFieldsOptional<FieldsWithRelationships>>>;
19
20
  type GetRelationshipRef<T, RM extends keyof T, TypeArg extends ModelRelationalFieldParamShape, Flat extends boolean, ResolvedModel = ResolveRelationalFieldsForModel<T, RM, Flat>, Model = TypeArg['valueRequired'] extends true ? ResolvedModel : ResolvedModel | null | undefined> = LazyLoader<Model, TypeArg['array']>;
20
21
  type ResolveRelationalFieldsForModel<Schema, ModelName extends keyof Schema, Flat extends boolean> = {
21
22
  [FieldName in keyof Schema[ModelName]]: Schema[ModelName][FieldName] extends ModelRelationalFieldParamShape ? Schema[ModelName][FieldName]['relatedModel'] extends keyof Schema ? GetRelationshipRef<Schema, Schema[ModelName][FieldName]['relatedModel'], Schema[ModelName][FieldName], Flat> : never : Schema[ModelName][FieldName];
@@ -95,6 +95,7 @@ function _rdsSchema(types, config) {
95
95
  }
96
96
  models[newName] = currentType;
97
97
  data.types[newName] = currentType;
98
+ models[newName].data.originalName = curName;
98
99
  delete models[curName];
99
100
  delete data.types[curName];
100
101
  });
@@ -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 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;AAC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AAC,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 } 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,MAAC,aAAa,GAAG,CAAC,MAAM,KAAK;AACzC,IAAI,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC;AACnE,EAAE;AACF,SAAS,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE;AACnC,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,KAAK;AACb,QAAQ,aAAa,EAAE,EAAE;AACzB,QAAQ,aAAa,EAAE,MAAM;AAC7B,KAAK,CAAC;AACN,IAAI,MAAM,MAA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EAAE,aAAa,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;AACvD,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,MAAM,EAAE,sBAAsB,CAAC,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;;;;"}
@@ -1,32 +1,34 @@
1
- import type { SetTypeSubArg, SecondaryIndexIrShape } from '@aws-amplify/data-schema-types';
2
- import { Brand } from './util';
3
- import { ModelField, InternalField } from './ModelField';
1
+ import type { SetTypeSubArg } from '@aws-amplify/data-schema-types';
2
+ import type { PrimaryIndexIrShape, SecondaryIndexIrShape } from './runtime';
3
+ import { type Brand } from './util';
4
+ import type { ModelField, InternalField } from './ModelField';
4
5
  import type { ModelRelationalField, InternalRelationalField, ModelRelationalFieldParamShape } from './ModelRelationalField';
5
- import { AllowModifier, Authorization } from './Authorization';
6
- import { RefType, RefTypeParamShape } 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';
6
+ import { type AllowModifier, type Authorization } from './Authorization';
7
+ import type { RefType, RefTypeParamShape } from './RefType';
8
+ import type { EnumType, EnumTypeParamShape } from './EnumType';
9
+ import type { CustomType, CustomTypeParamShape } from './CustomType';
10
+ import { type ModelIndexType, type InternalModelIndexType } from './ModelIndex';
11
+ import type { PrimaryIndexFieldsToIR, SecondaryIndexToIR } from './MappedTypes/MapIndexes';
11
12
  declare const brandName = "modelType";
12
13
  export type deferredRefResolvingPrefix = 'deferredRefResolving:';
13
14
  type ModelFields = Record<string, ModelField<any, any, any> | ModelRelationalField<any, string, any, any> | RefType<any, any, any> | EnumType<EnumTypeParamShape> | CustomType<CustomTypeParamShape>>;
14
15
  type InternalModelFields = Record<string, InternalField | InternalRelationalField>;
15
16
  type ModelData = {
16
17
  fields: ModelFields;
17
- identifier: string[];
18
+ identifier: ReadonlyArray<string>;
18
19
  secondaryIndexes: ReadonlyArray<ModelIndexType<any, any, any, any, any>>;
19
20
  authorization: Authorization<any, any, any>[];
20
21
  };
21
22
  type InternalModelData = ModelData & {
22
23
  fields: InternalModelFields;
23
- identifier: string[];
24
+ identifier: ReadonlyArray<string>;
24
25
  secondaryIndexes: ReadonlyArray<InternalModelIndexType>;
25
26
  authorization: Authorization<any, any, any>[];
27
+ originalName?: string;
26
28
  };
27
29
  export type ModelTypeParamShape = {
28
30
  fields: ModelFields;
29
- identifier: string[];
31
+ identifier: PrimaryIndexIrShape;
30
32
  secondaryIndexes: ReadonlyArray<SecondaryIndexIrShape>;
31
33
  authorization: Authorization<any, any, any>[];
32
34
  };
@@ -44,21 +46,12 @@ export type ModelTypeParamShape = {
44
46
  * indicator string, and resolve its corresponding type later in
45
47
  * packages/data-schema/src/runtime/client/index.ts
46
48
  */
47
- type ExtractSecondaryIndexIRFields<T extends ModelTypeParamShape> = {
48
- [FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends ModelField<infer R, any, any> ? NonNullable<R> extends string | number ? FieldProp : never : T['fields'][FieldProp] extends EnumType<EnumTypeParamShape> ? FieldProp : T['fields'][FieldProp] extends RefType<RefTypeParamShape, any, any> ? FieldProp : never]: T['fields'][FieldProp] extends ModelField<infer R, any, any> ? R : T['fields'][FieldProp] extends EnumType<infer R> ? R['values'][number] : T['fields'][FieldProp] extends RefType<infer R, any, any> ? `${deferredRefResolvingPrefix}${R['link']}` : never;
49
+ export type ExtractSecondaryIndexIRFields<T extends ModelTypeParamShape, RequiredOnly extends boolean = false> = {
50
+ [FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends ModelField<infer R, any, any> ? NonNullable<R> extends string | number ? RequiredOnly extends false ? FieldProp : null extends R ? never : FieldProp : never : T['fields'][FieldProp] extends EnumType<EnumTypeParamShape> | RefType<RefTypeParamShape, any, any> ? FieldProp : never]: T['fields'][FieldProp] extends ModelField<infer R, any, any> ? R : T['fields'][FieldProp] extends EnumType<infer R> ? R['values'][number] : T['fields'][FieldProp] extends RefType<infer R, any, any> ? `${deferredRefResolvingPrefix}${R['link']}` : never;
49
51
  };
50
- type ExtractType<T extends ModelTypeParamShape> = {
51
- [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;
52
- };
53
- type GetRequiredFields<T> = {
54
- [FieldProp in keyof T as T[FieldProp] extends NonNullable<T[FieldProp]> ? FieldProp : never]: T[FieldProp];
55
- };
56
- type IdentifierMap<T extends ModelTypeParamShape> = GetRequiredFields<ExtractType<T>>;
57
- type IdentifierFields<T extends ModelTypeParamShape> = keyof IdentifierMap<T> & string;
58
- type IdentifierType<T extends ModelTypeParamShape, Fields extends string = IdentifierFields<T>> = Array<Fields>;
59
52
  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;
60
53
  export type ModelType<T extends ModelTypeParamShape, K extends keyof ModelType<T> = never> = Omit<{
61
- identifier<ID extends IdentifierType<T> = []>(identifier: ID): ModelType<SetTypeSubArg<T, 'identifier', ID>, K | 'identifier'>;
54
+ identifier<PrimaryIndexFields = ExtractSecondaryIndexIRFields<T, true>, PrimaryIndexPool extends string = keyof PrimaryIndexFields & string, const ID extends ReadonlyArray<PrimaryIndexPool> = readonly [], const PrimaryIndexIR extends PrimaryIndexIrShape = PrimaryIndexFieldsToIR<ID, PrimaryIndexFields>>(identifier: ID): ModelType<SetTypeSubArg<T, 'identifier', PrimaryIndexIR>, K | 'identifier'>;
62
55
  secondaryIndexes<const SecondaryIndexFields = ExtractSecondaryIndexIRFields<T>, const SecondaryIndexPKPool extends string = keyof SecondaryIndexFields & string, const Indexes extends readonly ModelIndexType<string, string, unknown, readonly [], any>[] = readonly [], const IndexesIR extends readonly any[] = SecondaryIndexToIR<Indexes, SecondaryIndexFields>>(callback: (index: <PK extends SecondaryIndexPKPool>(pk: PK) => ModelIndexType<SecondaryIndexPKPool, PK, ReadonlyArray<Exclude<SecondaryIndexPKPool, PK>>>) => Indexes): ModelType<SetTypeSubArg<T, 'secondaryIndexes', IndexesIR>, K | 'secondaryIndexes'>;
63
56
  authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: Omit<AllowModifier, 'resource'>) => AuthRuleType | AuthRuleType[]): ModelType<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, K | 'authorization'>;
64
57
  }, K> & Brand<typeof brandName>;
@@ -92,7 +85,12 @@ export declare const isSchemaModelType: (modelType: any | SchemaModelType) => mo
92
85
  */
93
86
  export declare function model<T extends ModelFields>(fields: T): ModelType<{
94
87
  fields: T;
95
- identifier: Array<'id'>;
88
+ identifier: {
89
+ pk: {
90
+ id: string;
91
+ };
92
+ sk: never;
93
+ };
96
94
  secondaryIndexes: [];
97
95
  authorization: [];
98
96
  }>;
@@ -808,13 +808,16 @@ const schemaPreprocessor = (schema) => {
808
808
  const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey);
809
809
  topLevelTypes.push(...implicitTypes);
810
810
  const joined = gqlFields.join('\n ');
811
+ const refersToString = typeDef.data.originalName
812
+ ? ` @refersTo(name: "${typeDef.data.originalName}")`
813
+ : '';
811
814
  // TODO: update @model(timestamps: null) once a longer term solution gets
812
815
  // determined.
813
816
  //
814
817
  // Context: SQL schema should not be automatically inserted with timestamp fields,
815
818
  // passing (timestamps: null) to @model to suppress this behavior as a short
816
819
  // term solution.
817
- const model = `type ${typeName} @model(timestamps: null) ${authString}\n{\n ${joined}\n}`;
820
+ const model = `type ${typeName} @model(timestamps: null) ${authString}${refersToString}\n{\n ${joined}\n}`;
818
821
  gqlModels.push(model);
819
822
  }
820
823
  else {