@aws-amplify/data-schema 1.1.4 → 1.1.6

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 (57) hide show
  1. package/dist/cjs/CustomOperation.js +46 -0
  2. package/dist/cjs/CustomOperation.js.map +1 -1
  3. package/dist/cjs/CustomType.js +32 -0
  4. package/dist/cjs/CustomType.js.map +1 -1
  5. package/dist/cjs/Handler.js +62 -0
  6. package/dist/cjs/Handler.js.map +1 -1
  7. package/dist/cjs/ModelRelationalField.js +82 -3
  8. package/dist/cjs/ModelRelationalField.js.map +1 -1
  9. package/dist/cjs/util/Brand.js +4 -4
  10. package/dist/cjs/util/Brand.js.map +1 -1
  11. package/dist/cjs/util/usedMethods.js +4 -0
  12. package/dist/cjs/util/usedMethods.js.map +1 -0
  13. package/dist/esm/CustomOperation.d.ts +49 -3
  14. package/dist/esm/CustomOperation.mjs +46 -0
  15. package/dist/esm/CustomOperation.mjs.map +1 -1
  16. package/dist/esm/CustomType.d.ts +35 -3
  17. package/dist/esm/CustomType.mjs +32 -0
  18. package/dist/esm/CustomType.mjs.map +1 -1
  19. package/dist/esm/EnumType.d.ts +7 -9
  20. package/dist/esm/Handler.d.ts +62 -0
  21. package/dist/esm/Handler.mjs +62 -0
  22. package/dist/esm/Handler.mjs.map +1 -1
  23. package/dist/esm/MappedTypes/CustomOperations.d.ts +3 -3
  24. package/dist/esm/MappedTypes/ExtractNonModelTypes.d.ts +4 -4
  25. package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +2 -2
  26. package/dist/esm/MappedTypes/ResolveSchema.d.ts +6 -6
  27. package/dist/esm/ModelField.d.ts +16 -13
  28. package/dist/esm/ModelRelationalField.d.ts +83 -4
  29. package/dist/esm/ModelRelationalField.mjs +82 -3
  30. package/dist/esm/ModelRelationalField.mjs.map +1 -1
  31. package/dist/esm/ModelSchema.d.ts +4 -4
  32. package/dist/esm/ModelType.d.ts +16 -12
  33. package/dist/esm/RefType.d.ts +1 -1
  34. package/dist/esm/util/Brand.d.ts +1 -2
  35. package/dist/esm/util/Brand.mjs +1 -1
  36. package/dist/esm/util/Brand.mjs.map +1 -1
  37. package/dist/esm/util/usedMethods.d.ts +4 -0
  38. package/dist/esm/util/usedMethods.mjs +2 -0
  39. package/dist/esm/util/usedMethods.mjs.map +1 -0
  40. package/dist/meta/cjs.tsbuildinfo +1 -1
  41. package/package.json +1 -1
  42. package/src/CustomOperation.ts +49 -7
  43. package/src/CustomType.ts +36 -8
  44. package/src/EnumType.ts +16 -22
  45. package/src/Handler.ts +62 -0
  46. package/src/MappedTypes/CustomOperations.ts +4 -6
  47. package/src/MappedTypes/ExtractNonModelTypes.ts +39 -40
  48. package/src/MappedTypes/ResolveFieldProperties.ts +2 -2
  49. package/src/MappedTypes/ResolveSchema.ts +18 -21
  50. package/src/ModelField.ts +34 -19
  51. package/src/ModelRelationalField.ts +83 -4
  52. package/src/ModelSchema.ts +8 -12
  53. package/src/ModelType.ts +30 -34
  54. package/src/RefType.ts +1 -1
  55. package/src/SchemaProcessor.ts +21 -41
  56. package/src/util/Brand.ts +1 -1
  57. package/src/util/usedMethods.ts +5 -0
@@ -52,28 +52,107 @@ function _modelRelationalField(type, relatedModel, references) {
52
52
  };
53
53
  }
54
54
  /**
55
- * Create a one-directional one-to-one relationship between two models using the `hasOne("MODEL_NAME")` method.
55
+ * Create one-to-one relationship between two models using the `hasOne("MODEL_NAME", "REFERENCE_FIELD(s)")` method.
56
56
  * A hasOne relationship always uses a reference to the related model's identifier. Typically this is the `id` field
57
57
  * unless overwritten with the `identifier()` method.
58
+ * @example
59
+ * const schema = a.schema({
60
+ * Cart: a.model({
61
+ * items: a.string().required().array(),
62
+ * // 1. Create reference field
63
+ * customerId: a.id(),
64
+ * // 2. Create relationship field with the reference field
65
+ * customer: a.belongsTo('Customer', 'customerId'),
66
+ * }),
67
+ * Customer: a.model({
68
+ * name: a.string(),
69
+ * // 3. Create relationship field with the reference field
70
+ * // from the Cart model
71
+ * activeCart: a.hasOne('Cart', 'customerId')
72
+ * }),
73
+ * });
74
+ * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-a-one-to-one-relationship}
58
75
  * @param relatedModel the name of the related model
76
+ * @param references the field(s) that should be used to reference the related model
59
77
  * @returns a one-to-one relationship definition
60
78
  */
61
79
  function hasOne(relatedModel, references) {
62
80
  return _modelRelationalField(ModelRelationshipTypes.hasOne, relatedModel, Array.isArray(references) ? references : [references]);
63
81
  }
64
82
  /**
65
- * Create a one-directional one-to-many relationship between two models using the `hasMany()` method.
83
+ * Create a one-directional one-to-many relationship between two models using the `hasMany("MODEL_NAME", "REFERENCE_FIELD(s)")` method.
84
+ * @example
85
+ * const schema = a.schema({
86
+ * Member: a.model({
87
+ * name: a.string().required(),
88
+ * // 1. Create a reference field
89
+ * teamId: a.id(),
90
+ * // 2. Create a belongsTo relationship with the reference field
91
+ * team: a.belongsTo('Team', 'teamId'),
92
+ * })
93
+ * .authorization(allow => [allow.publicApiKey()]),
94
+ *
95
+ * Team: a.model({
96
+ * mantra: a.string().required(),
97
+ * // 3. Create a hasMany relationship with the reference field
98
+ * // from the `Member`s model.
99
+ * members: a.hasMany('Member', 'teamId'),
100
+ * })
101
+ * .authorization(allow => [allow.publicApiKey()]),
102
+ * });
103
+ * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-one-to-many-relationships}
66
104
  * @param relatedModel the name of the related model
105
+ * @param references the field(s) that should be used to reference the related model
67
106
  * @returns a one-to-many relationship definition
68
107
  */
69
108
  function hasMany(relatedModel, references) {
70
109
  return _modelRelationalField(ModelRelationshipTypes.hasMany, relatedModel, Array.isArray(references) ? references : [references]);
71
110
  }
72
111
  /**
73
- * Make a `hasOne()` or `hasMany()` relationship bi-directional using the `belongsTo()` method.
112
+ * Use `belongsTo()` to create a field to query the related `hasOne()` or `hasMany()` relationship.
74
113
  * The belongsTo() method requires that a hasOne() or hasMany() relationship already exists from
75
114
  * parent to the related model.
115
+ *
116
+ * @example
117
+ * // one-to-many relationship
118
+ * const schema = a.schema({
119
+ * Member: a.model({
120
+ * name: a.string().required(),
121
+ * // 1. Create a reference field
122
+ * teamId: a.id(),
123
+ * // 2. Create a belongsTo relationship with the reference field
124
+ * team: a.belongsTo('Team', 'teamId'),
125
+ * })
126
+ * .authorization(allow => [allow.publicApiKey()]),
127
+ *
128
+ * Team: a.model({
129
+ * mantra: a.string().required(),
130
+ * // 3. Create a hasMany relationship with the reference field
131
+ * // from the `Member`s model.
132
+ * members: a.hasMany('Member', 'teamId'),
133
+ * })
134
+ * .authorization(allow => [allow.publicApiKey()]),
135
+ * });
136
+ * @example
137
+ * // one-to-one relationship
138
+ * const schema = a.schema({
139
+ * Cart: a.model({
140
+ * items: a.string().required().array(),
141
+ * // 1. Create reference field
142
+ * customerId: a.id(),
143
+ * // 2. Create relationship field with the reference field
144
+ * customer: a.belongsTo('Customer', 'customerId'),
145
+ * }),
146
+ * Customer: a.model({
147
+ * name: a.string(),
148
+ * // 3. Create relationship field with the reference field
149
+ * // from the Cart model
150
+ * activeCart: a.hasOne('Cart', 'customerId')
151
+ * }),
152
+ * });
153
+ * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/}
76
154
  * @param relatedModel name of the related `.hasOne()` or `.hasMany()` model
155
+ * @param references the field(s) that should be used to reference the related model
77
156
  * @returns a belong-to relationship definition
78
157
  */
79
158
  function belongsTo(relatedModel, references) {
@@ -1 +1 @@
1
- {"version":3,"file":"ModelRelationalField.mjs","sources":["../../src/ModelRelationalField.ts"],"sourcesContent":["import { allow } from './Authorization';\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexport const __auth = Symbol('__auth');\nconst brandName = 'modelRelationalField';\nexport var ModelRelationshipTypes;\n(function (ModelRelationshipTypes) {\n ModelRelationshipTypes[\"hasOne\"] = \"hasOne\";\n ModelRelationshipTypes[\"hasMany\"] = \"hasMany\";\n ModelRelationshipTypes[\"belongsTo\"] = \"belongsTo\";\n})(ModelRelationshipTypes || (ModelRelationshipTypes = {}));\nconst relationalModifiers = [\n 'required',\n 'valueRequired',\n 'authorization',\n];\nconst relationModifierMap = {\n belongsTo: ['authorization'],\n hasMany: ['valueRequired', 'authorization'],\n hasOne: ['required', 'authorization'],\n};\nfunction _modelRelationalField(type, relatedModel, references) {\n const data = {\n relatedModel,\n type,\n fieldType: 'model',\n array: false,\n valueRequired: false,\n arrayRequired: false,\n references,\n authorization: [],\n };\n data.array = type === 'hasMany';\n const relationshipBuilderFunctions = {\n required() {\n data.arrayRequired = true;\n return this;\n },\n valueRequired() {\n data.valueRequired = true;\n return this;\n },\n authorization(callback) {\n const rules = callback(allow);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n };\n const builder = Object.fromEntries(relationModifierMap[type].map((key) => [\n key,\n relationshipBuilderFunctions[key],\n ]));\n return {\n ...builder,\n data,\n };\n}\n/**\n * Create a one-directional one-to-one relationship between two models using the `hasOne(\"MODEL_NAME\")` method.\n * A hasOne relationship always uses a reference to the related model's identifier. Typically this is the `id` field\n * unless overwritten with the `identifier()` method.\n * @param relatedModel the name of the related model\n * @returns a one-to-one relationship definition\n */\nexport function hasOne(relatedModel, references) {\n return _modelRelationalField(ModelRelationshipTypes.hasOne, relatedModel, Array.isArray(references) ? references : [references]);\n}\n/**\n * Create a one-directional one-to-many relationship between two models using the `hasMany()` method.\n * @param relatedModel the name of the related model\n * @returns a one-to-many relationship definition\n */\nexport function hasMany(relatedModel, references) {\n return _modelRelationalField(ModelRelationshipTypes.hasMany, relatedModel, Array.isArray(references) ? references : [references]);\n}\n/**\n * Make a `hasOne()` or `hasMany()` relationship bi-directional using the `belongsTo()` method.\n * The belongsTo() method requires that a hasOne() or hasMany() relationship already exists from\n * parent to the related model.\n * @param relatedModel name of the related `.hasOne()` or `.hasMany()` model\n * @returns a belong-to relationship definition\n */\nexport function belongsTo(relatedModel, references) {\n return _modelRelationalField(ModelRelationshipTypes.belongsTo,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KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACxI;;;;"}
1
+ {"version":3,"file":"ModelRelationalField.mjs","sources":["../../src/ModelRelationalField.ts"],"sourcesContent":["import { allow } from './Authorization';\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexport const __auth = Symbol('__auth');\nconst brandName = 'modelRelationalField';\nexport var ModelRelationshipTypes;\n(function (ModelRelationshipTypes) {\n ModelRelationshipTypes[\"hasOne\"] = \"hasOne\";\n ModelRelationshipTypes[\"hasMany\"] = \"hasMany\";\n ModelRelationshipTypes[\"belongsTo\"] = \"belongsTo\";\n})(ModelRelationshipTypes || (ModelRelationshipTypes = {}));\nconst relationalModifiers = [\n 'required',\n 'valueRequired',\n 'authorization',\n];\nconst relationModifierMap = {\n belongsTo: ['authorization'],\n hasMany: ['valueRequired', 'authorization'],\n hasOne: ['required', 'authorization'],\n};\nfunction _modelRelationalField(type, relatedModel, references) {\n const data = {\n relatedModel,\n type,\n fieldType: 'model',\n array: false,\n valueRequired: false,\n arrayRequired: false,\n references,\n authorization: [],\n };\n data.array = type === 'hasMany';\n const relationshipBuilderFunctions = {\n required() {\n data.arrayRequired = true;\n return this;\n },\n valueRequired() {\n data.valueRequired = true;\n return this;\n },\n authorization(callback) {\n const rules = callback(allow);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n };\n const builder = Object.fromEntries(relationModifierMap[type].map((key) => [\n key,\n relationshipBuilderFunctions[key],\n ]));\n return {\n ...builder,\n data,\n };\n}\n/**\n * Create one-to-one relationship between two models using the `hasOne(\"MODEL_NAME\", \"REFERENCE_FIELD(s)\")` method.\n * A hasOne relationship always uses a reference to the related model's identifier. Typically this is the `id` field\n * unless overwritten with the `identifier()` method.\n * @example\n * const schema = a.schema({\n * Cart: a.model({\n * items: a.string().required().array(),\n * // 1. Create reference field\n * customerId: a.id(),\n * // 2. Create relationship field with the reference field\n * customer: a.belongsTo('Customer', 'customerId'),\n * }),\n * Customer: a.model({\n * name: a.string(),\n * // 3. Create relationship field with the reference field\n * // from the Cart model\n * activeCart: a.hasOne('Cart', 'customerId')\n * }),\n * });\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-a-one-to-one-relationship}\n * @param relatedModel the name of the related model\n * @param references the field(s) that should be used to reference the related model\n * @returns a one-to-one relationship definition\n */\nexport function hasOne(relatedModel, references) {\n return _modelRelationalField(ModelRelationshipTypes.hasOne, relatedModel, Array.isArray(references) ? references : [references]);\n}\n/**\n * Create a one-directional one-to-many relationship between two models using the `hasMany(\"MODEL_NAME\", \"REFERENCE_FIELD(s)\")` method.\n * @example\n * const schema = a.schema({\n * Member: a.model({\n * name: a.string().required(),\n * // 1. Create a reference field\n * teamId: a.id(),\n * // 2. Create a belongsTo relationship with the reference field\n * team: a.belongsTo('Team', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n *\n * Team: a.model({\n * mantra: a.string().required(),\n * // 3. Create a hasMany relationship with the reference field\n * // from the `Member`s model.\n * members: a.hasMany('Member', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n * });\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-one-to-many-relationships}\n * @param relatedModel the name of the related model\n * @param references the field(s) that should be used to reference the related model\n * @returns a one-to-many relationship definition\n */\nexport function hasMany(relatedModel, references) {\n return _modelRelationalField(ModelRelationshipTypes.hasMany, relatedModel, Array.isArray(references) ? references : [references]);\n}\n/**\n * Use `belongsTo()` to create a field to query the related `hasOne()` or `hasMany()` relationship.\n * The belongsTo() method requires that a hasOne() or hasMany() relationship already exists from\n * parent to the related model.\n *\n * @example\n * // one-to-many relationship\n * const schema = a.schema({\n * Member: a.model({\n * name: a.string().required(),\n * // 1. Create a reference field\n * teamId: a.id(),\n * // 2. Create a belongsTo relationship with the reference field\n * team: a.belongsTo('Team', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n *\n * Team: a.model({\n * mantra: a.string().required(),\n * // 3. Create a hasMany relationship with the reference field\n * // from the `Member`s model.\n * members: a.hasMany('Member', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n * });\n * @example\n * // one-to-one relationship\n * const schema = a.schema({\n * Cart: a.model({\n * items: a.string().required().array(),\n * // 1. Create reference field\n * customerId: a.id(),\n * // 2. Create relationship field with the reference field\n * customer: a.belongsTo('Customer', 'customerId'),\n * }),\n * Customer: a.model({\n * name: a.string(),\n * // 3. Create relationship field with the reference field\n * // from the Cart model\n * activeCart: a.hasOne('Cart', 'customerId')\n * }),\n * });\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/}\n * @param relatedModel name of the related `.hasOne()` or `.hasMany()` model\n * @param references the field(s) that should be used to reference the related model\n * @returns a belong-to relationship definition\n */\nexport function belongsTo(relatedModel, references) {\n return _modelRelationalField(ModelRelationshipTypes.belongsTo, relatedModel, Array.isArray(references) ? references : [references]);\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE;AAE7B,IAAC,uBAAuB;AAClC,CAAC,UAAU,sBAAsB,EAAE;AACnC,IAAI,sBAAsB,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AAChD,IAAI,sBAAsB,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AAClD,IAAI,sBAAsB,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;AACtD,CAAC,EAAE,sBAAsB,KAAK,sBAAsB,GAAG,EAAE,CAAC,CAAC,CAAC;AAM5D,MAAM,mBAAmB,GAAG;AAC5B,IAAI,SAAS,EAAE,CAAC,eAAe,CAAC;AAChC,IAAI,OAAO,EAAE,CAAC,eAAe,EAAE,eAAe,CAAC;AAC/C,IAAI,MAAM,EAAE,CAAC,UAAU,EAAE,eAAe,CAAC;AACzC,CAAC,CAAC;AACF,SAAS,qBA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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,MAAM,CAAC,YAAY,EAAE,UAAU,EAAE;AACjD,IAAI,OAAO,qBAAqB,CAAC,sBAAsB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACrI,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,OAAO,CAAC,YAAY,EAAE,UAAU,EAAE;AAClD,IAAI,OAAO,qBAAqB,CAAC,sBAAsB,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACtI,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,CAAC,YAAY,EAAE,UAAU,EAAE;AACpD,IAAI,OAAO,qBAAqB,CAAC,sBAAsB,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACxI;;;;"}
@@ -1,6 +1,6 @@
1
1
  import type { DerivedApiDefinition, SetTypeSubArg, SchemaConfiguration, DataSourceConfiguration, DatasourceEngine, UnionToIntersection } from '@aws-amplify/data-schema-types';
2
- import { type ModelType, type ModelTypeParamShape, type InternalModel, SchemaModelType, AddRelationshipFieldsToModelTypeFields } from './ModelType';
3
- import type { EnumType, EnumTypeParamShape } from './EnumType';
2
+ import { type InternalModel, SchemaModelType, AddRelationshipFieldsToModelTypeFields, type BaseModelType } from './ModelType';
3
+ import type { EnumType } from './EnumType';
4
4
  import type { CustomType, CustomTypeParamShape } from './CustomType';
5
5
  import type { CustomOperation, CustomOperationParamShape, InternalCustom, MutationCustomOperation, QueryCustomOperation, SubscriptionCustomOperation } from './CustomOperation';
6
6
  import { AllowModifier, SchemaAuthorization } from './Authorization';
@@ -11,7 +11,7 @@ export declare const rdsSchemaBrand: Brand<"RDSSchema">;
11
11
  export type RDSSchemaBrand = Brand<typeof rdsSchemaBrandName>;
12
12
  export declare const ddbSchemaBrandName = "DDBSchema";
13
13
  export type DDBSchemaBrand = Brand<typeof ddbSchemaBrandName>;
14
- type SchemaContent = ModelType<ModelTypeParamShape, any> | CustomType<CustomTypeParamShape> | EnumType<EnumTypeParamShape> | CustomOperation<CustomOperationParamShape, any>;
14
+ type SchemaContent = BaseModelType | CustomType<CustomTypeParamShape> | EnumType | CustomOperation<CustomOperationParamShape, any>;
15
15
  type NonEmpty<T> = keyof T extends never ? never : T;
16
16
  type ModelSchemaContents = Record<string, SchemaContent>;
17
17
  type InternalSchemaModels = Record<string, InternalModel | EnumType<any> | CustomType<any> | InternalCustom>;
@@ -31,7 +31,7 @@ export type InternalSchema = {
31
31
  export type BaseSchema<T extends ModelSchemaParamShape, IsRDS extends boolean = false> = {
32
32
  data: T;
33
33
  models: {
34
- [TypeKey in keyof T['types']]: T['types'][TypeKey] extends ModelType<ModelTypeParamShape, never | 'identifier'> ? SchemaModelType<T['types'][TypeKey], TypeKey & string, IsRDS> : never;
34
+ [TypeKey in keyof T['types']]: T['types'][TypeKey] extends BaseModelType ? SchemaModelType<T['types'][TypeKey], TypeKey & string, IsRDS> : never;
35
35
  };
36
36
  transform: () => DerivedApiDefinition;
37
37
  };
@@ -1,17 +1,18 @@
1
1
  import type { SetTypeSubArg } from '@aws-amplify/data-schema-types';
2
2
  import type { PrimaryIndexIrShape, SecondaryIndexIrShape } from './runtime';
3
- import { type Brand } from './util';
4
- import type { ModelField, InternalField } from './ModelField';
3
+ import type { InternalField, BaseModelField } from './ModelField';
5
4
  import type { ModelRelationalField, InternalRelationalField, ModelRelationalFieldParamShape } from './ModelRelationalField';
6
5
  import { type AllowModifier, type Authorization } from './Authorization';
7
6
  import type { RefType, RefTypeParamShape } from './RefType';
8
- import type { EnumType, EnumTypeParamShape } from './EnumType';
7
+ import type { EnumType } from './EnumType';
9
8
  import type { CustomType, CustomTypeParamShape } from './CustomType';
10
9
  import { type ModelIndexType, type InternalModelIndexType } from './ModelIndex';
11
10
  import type { PrimaryIndexFieldsToIR, SecondaryIndexToIR } from './MappedTypes/MapIndexes';
11
+ import type { brandSymbol } from './util/Brand.js';
12
+ import type { methodKeyOf } from './util/usedMethods.js';
12
13
  declare const brandName = "modelType";
13
14
  export type deferredRefResolvingPrefix = 'deferredRefResolving:';
14
- type ModelFields = Record<string, ModelField<any, any, any> | ModelRelationalField<any, string, any, any> | RefType<any, any, any> | EnumType<EnumTypeParamShape> | CustomType<CustomTypeParamShape>>;
15
+ type ModelFields = Record<string, BaseModelField | ModelRelationalField<any, string, any, any> | RefType<any, any, any> | EnumType | CustomType<CustomTypeParamShape>>;
15
16
  type InternalModelFields = Record<string, InternalField | InternalRelationalField>;
16
17
  type ModelData = {
17
18
  fields: ModelFields;
@@ -47,21 +48,24 @@ export type ModelTypeParamShape = {
47
48
  * packages/data-schema/src/runtime/client/index.ts
48
49
  */
49
50
  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;
51
+ [FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends BaseModelField<infer R> ? NonNullable<R> extends string | number ? RequiredOnly extends false ? FieldProp : null extends R ? never : FieldProp : never : T['fields'][FieldProp] extends EnumType | RefType<RefTypeParamShape, any, any> ? FieldProp : never]: T['fields'][FieldProp] extends BaseModelField<infer R> ? R : T['fields'][FieldProp] extends EnumType<infer values> ? values[number] : T['fields'][FieldProp] extends RefType<infer R, any, any> ? `${deferredRefResolvingPrefix}${R['link']}` : never;
51
52
  };
52
53
  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;
53
- export type ModelType<T extends ModelTypeParamShape, K extends keyof ModelType<T> = never> = Omit<{
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'>;
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'>;
56
- authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: Omit<AllowModifier, 'resource'>) => AuthRuleType | AuthRuleType[]): ModelType<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, K | 'authorization'>;
57
- }, K> & Brand<typeof brandName>;
54
+ export type BaseModelType<T extends ModelTypeParamShape = ModelTypeParamShape> = ModelType<T, UsableModelTypeKey>;
55
+ export type UsableModelTypeKey = methodKeyOf<ModelType>;
56
+ export type ModelType<T extends ModelTypeParamShape = ModelTypeParamShape, UsedMethod extends UsableModelTypeKey = never> = Omit<{
57
+ [brandSymbol]: typeof brandName;
58
+ 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>, UsedMethod | 'identifier'>;
59
+ 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>, UsedMethod | 'secondaryIndexes'>;
60
+ authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: Omit<AllowModifier, 'resource'>) => AuthRuleType | AuthRuleType[]): ModelType<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, UsedMethod | 'authorization'>;
61
+ }, UsedMethod>;
58
62
  /**
59
63
  * External representation of Model Type that exposes the `relationships` modifier.
60
64
  * Used on the complete schema object.
61
65
  */
62
- 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 & {
66
+ export type SchemaModelType<T extends BaseModelType = ModelType<ModelTypeParamShape, 'identifier'>, ModelName extends string = string, IsRDS extends boolean = false> = IsRDS extends true ? T & {
63
67
  relationships<Param extends Record<string, ModelRelationalField<any, string, any, any>> = Record<never, never>>(relationships: Param): Record<ModelName, Param>;
64
- fields: T extends ModelType<infer R extends ModelTypeParamShape, any> ? R['fields'] : never;
68
+ fields: T extends ModelType<infer R, any> ? R['fields'] : never;
65
69
  } : T;
66
70
  /**
67
71
  * Internal representation of Model Type that exposes the `data` property.
@@ -31,7 +31,7 @@ export type RefType<T extends RefTypeParamShape, K extends keyof RefType<T> = ne
31
31
  */
32
32
  array(): RefType<SetTypeSubArg<T, 'array', true>, Exclude<K, 'required'> | 'array'>;
33
33
  /**
34
- * Configures field-level authorization rules. Pass in an array of authorizations `(a.allow.____)` to mix and match
34
+ * Configures field-level authorization rules. Pass in an array of authorizations `(allow => allow.____)` to mix and match
35
35
  * multiple authorization rules for this field.
36
36
  */
37
37
  authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: AllowModifier) => AuthRuleType | AuthRuleType[]): RefType<T, K | 'authorization', AuthRuleType>;
@@ -1,4 +1,4 @@
1
- declare const brandSymbol: unique symbol;
1
+ export declare const brandSymbol: unique symbol;
2
2
  /**
3
3
  * @typeParam BrandStr - String type to brand this object with
4
4
  * @returns A branded empty object type
@@ -32,4 +32,3 @@ export declare function brand<BrandStr extends string>(brand: BrandStr): Brand<B
32
32
  * @returns The string brand value
33
33
  */
34
34
  export declare function getBrand(branded: Brand<string>): string;
35
- export {};
@@ -26,5 +26,5 @@ function getBrand(branded) {
26
26
  return branded[brandSymbol];
27
27
  }
28
28
 
29
- export { brand, getBrand };
29
+ export { brand, brandSymbol, getBrand };
30
30
  //# sourceMappingURL=Brand.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Brand.mjs","sources":["../../../src/util/Brand.ts"],"sourcesContent":["const brandSymbol = Symbol('brand');\n/**\n * Create an object of a specific type Brand\n * string branded type.\n *\n * @param brand: The string to Brand onto a simple object\n * @returns A branded empty object\n *\n * @example\n * brand('example') => {[brandSymbol]: 'example'}\n *\n * Which I might use like this:\n * const myType = {content: \"default content\", ...brand<'example'>}\n */\nexport function brand(brand) {\n return {\n [brandSymbol]: brand,\n };\n}\n/**\n *\n * @param branded: Branded object\n * @returns The string brand value\n */\nexport function getBrand(branded) {\n return branded[brandSymbol];\n}\n"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,CAAC,KAAK,EAAE;AAC7B,IAAI,OAAO;AACX,QAAQ,CAAC,WAAW,GAAG,KAAK;AAC5B,KAAK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,QAAQ,CAAC,OAAO,EAAE;AAClC,IAAI,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC;AAChC;;;;"}
1
+ {"version":3,"file":"Brand.mjs","sources":["../../../src/util/Brand.ts"],"sourcesContent":["export const brandSymbol = Symbol('brand');\n/**\n * Create an object of a specific type Brand\n * string branded type.\n *\n * @param brand: The string to Brand onto a simple object\n * @returns A branded empty object\n *\n * @example\n * brand('example') => {[brandSymbol]: 'example'}\n *\n * Which I might use like this:\n * const myType = {content: \"default content\", ...brand<'example'>}\n */\nexport function brand(brand) {\n return {\n [brandSymbol]: brand,\n };\n}\n/**\n *\n * @param branded: Branded object\n * @returns The string brand value\n */\nexport function getBrand(branded) {\n return branded[brandSymbol];\n}\n"],"names":[],"mappings":"AAAY,MAAC,WAAW,GAAG,MAAM,CAAC,OAAO,EAAE;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,CAAC,KAAK,EAAE;AAC7B,IAAI,OAAO;AACX,QAAQ,CAAC,WAAW,GAAG,KAAK;AAC5B,KAAK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,QAAQ,CAAC,OAAO,EAAE;AAClC,IAAI,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC;AAChC;;;;"}
@@ -0,0 +1,4 @@
1
+ export type methodKeyOf<o> = {
2
+ [k in keyof o]-?: o[k] extends (...args: never) => unknown ? k : never;
3
+ }[keyof o];
4
+ export type satisfy<base, t extends base> = t;
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=usedMethods.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usedMethods.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}