@aws-amplify/data-schema 1.18.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/dist/cjs/Authorization.js.map +1 -1
  2. package/dist/cjs/ClientSchema/utilities/index.js.map +1 -1
  3. package/dist/cjs/CombineSchema.js +2 -2
  4. package/dist/cjs/CombineSchema.js.map +1 -1
  5. package/dist/cjs/CustomOperation.js +5 -5
  6. package/dist/cjs/CustomOperation.js.map +1 -1
  7. package/dist/cjs/CustomType.js +1 -2
  8. package/dist/cjs/CustomType.js.map +1 -1
  9. package/dist/cjs/EnumType.js +1 -2
  10. package/dist/cjs/EnumType.js.map +1 -1
  11. package/dist/cjs/Handler.js +2 -2
  12. package/dist/cjs/Handler.js.map +1 -1
  13. package/dist/cjs/ModelField.js +24 -17
  14. package/dist/cjs/ModelField.js.map +1 -1
  15. package/dist/cjs/ModelIndex.js +1 -2
  16. package/dist/cjs/ModelIndex.js.map +1 -1
  17. package/dist/cjs/ModelRelationshipField.js +4 -4
  18. package/dist/cjs/ModelRelationshipField.js.map +1 -1
  19. package/dist/cjs/ModelSchema.js +3 -3
  20. package/dist/cjs/ModelSchema.js.map +1 -1
  21. package/dist/cjs/ModelType.js +2 -2
  22. package/dist/cjs/ModelType.js.map +1 -1
  23. package/dist/cjs/RefType.js +1 -2
  24. package/dist/cjs/RefType.js.map +1 -1
  25. package/dist/cjs/SchemaProcessor.js +12 -3
  26. package/dist/cjs/SchemaProcessor.js.map +1 -1
  27. package/dist/cjs/Validate.js +145 -0
  28. package/dist/cjs/Validate.js.map +1 -0
  29. package/dist/cjs/a.js.map +1 -1
  30. package/dist/cjs/ai/ConversationSchemaGraphQLTypes.js.map +1 -1
  31. package/dist/cjs/ai/ConversationSchemaProcessor.js.map +1 -1
  32. package/dist/cjs/ai/ConversationType.js +3 -3
  33. package/dist/cjs/ai/ConversationType.js.map +1 -1
  34. package/dist/cjs/ai/ModelType.js +1 -2
  35. package/dist/cjs/ai/ModelType.js.map +1 -1
  36. package/dist/cjs/index.js.map +1 -1
  37. package/dist/cjs/internals/index.js.map +1 -1
  38. package/dist/cjs/runtime/addSchemaToClient.js +1 -2
  39. package/dist/cjs/runtime/addSchemaToClient.js.map +1 -1
  40. package/dist/cjs/runtime/addSchemaToClientWithInstance.js +1 -2
  41. package/dist/cjs/runtime/addSchemaToClientWithInstance.js.map +1 -1
  42. package/dist/cjs/runtime/bridge-types.js.map +1 -1
  43. package/dist/cjs/runtime/client/index.js.map +1 -1
  44. package/dist/cjs/runtime/client/index.v3.js.map +1 -1
  45. package/dist/cjs/runtime/index.js.map +1 -1
  46. package/dist/cjs/runtime/index.v3.js.map +1 -1
  47. package/dist/cjs/runtime/internals/APIClient.js +10 -10
  48. package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
  49. package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js +12 -0
  50. package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js.map +1 -1
  51. package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js +12 -0
  52. package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js.map +1 -1
  53. package/dist/cjs/runtime/internals/ai/conversationStreamEventDeserializers.js.map +1 -1
  54. package/dist/cjs/runtime/internals/ai/convertItemToConversation.js.map +1 -1
  55. package/dist/cjs/runtime/internals/ai/convertItemToConversationMessage.js.map +1 -1
  56. package/dist/cjs/runtime/internals/ai/createCreateConversationFunction.js.map +1 -1
  57. package/dist/cjs/runtime/internals/ai/createDeleteConversationFunction.js.map +1 -1
  58. package/dist/cjs/runtime/internals/ai/createGetConversationFunction.js.map +1 -1
  59. package/dist/cjs/runtime/internals/ai/createListConversationsFunction.js.map +1 -1
  60. package/dist/cjs/runtime/internals/ai/createListMessagesFunction.js.map +1 -1
  61. package/dist/cjs/runtime/internals/ai/createOnStreamEventFunction.js.map +1 -1
  62. package/dist/cjs/runtime/internals/ai/createSendMessageFunction.js.map +1 -1
  63. package/dist/cjs/runtime/internals/ai/createUpdateConversationFunction.js.map +1 -1
  64. package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js +2 -2
  65. package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js.map +1 -1
  66. package/dist/cjs/runtime/internals/cancellation.js +2 -3
  67. package/dist/cjs/runtime/internals/cancellation.js.map +1 -1
  68. package/dist/cjs/runtime/internals/clientUtils.js.map +1 -1
  69. package/dist/cjs/runtime/internals/generateCustomOperationsProperty.js +4 -5
  70. package/dist/cjs/runtime/internals/generateCustomOperationsProperty.js.map +1 -1
  71. package/dist/cjs/runtime/internals/index.js.map +1 -1
  72. package/dist/cjs/runtime/internals/operations/custom.js +1 -2
  73. package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
  74. package/dist/cjs/runtime/internals/operations/get.js +1 -2
  75. package/dist/cjs/runtime/internals/operations/get.js.map +1 -1
  76. package/dist/cjs/runtime/internals/operations/indexQuery.js +1 -2
  77. package/dist/cjs/runtime/internals/operations/indexQuery.js.map +1 -1
  78. package/dist/cjs/runtime/internals/operations/list.js +1 -2
  79. package/dist/cjs/runtime/internals/operations/list.js.map +1 -1
  80. package/dist/cjs/runtime/internals/operations/observeQuery.js +1 -2
  81. package/dist/cjs/runtime/internals/operations/observeQuery.js.map +1 -1
  82. package/dist/cjs/runtime/internals/operations/subscription.js +1 -2
  83. package/dist/cjs/runtime/internals/operations/subscription.js.map +1 -1
  84. package/dist/cjs/runtime/internals/operations/utils.js +2 -3
  85. package/dist/cjs/runtime/internals/operations/utils.js.map +1 -1
  86. package/dist/cjs/runtime/internals/server/generateModelsProperty.js +1 -2
  87. package/dist/cjs/runtime/internals/server/generateModelsProperty.js.map +1 -1
  88. package/dist/cjs/runtime/internals/server/index.js.map +1 -1
  89. package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js +1 -2
  90. package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js.map +1 -1
  91. package/dist/cjs/runtime/internals/utils/clientProperties/generateEnumsProperty.js.map +1 -1
  92. package/dist/cjs/runtime/internals/utils/clientProperties/generateGenerationsProperty.js +1 -2
  93. package/dist/cjs/runtime/internals/utils/clientProperties/generateGenerationsProperty.js.map +1 -1
  94. package/dist/cjs/runtime/internals/utils/clientProperties/generateModelsProperty.js +1 -2
  95. package/dist/cjs/runtime/internals/utils/clientProperties/generateModelsProperty.js.map +1 -1
  96. package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js +1 -2
  97. package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js.map +1 -1
  98. package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js +1 -2
  99. package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js.map +1 -1
  100. package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js +1 -2
  101. package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js.map +1 -1
  102. package/dist/cjs/runtime/utils/findIndexByFields.js +1 -2
  103. package/dist/cjs/runtime/utils/findIndexByFields.js.map +1 -1
  104. package/dist/cjs/runtime/utils/index.js.map +1 -1
  105. package/dist/cjs/runtime/utils/resolveOwnerFields.js +1 -2
  106. package/dist/cjs/runtime/utils/resolveOwnerFields.js.map +1 -1
  107. package/dist/cjs/runtime/utils/resolvePKFields.js +1 -2
  108. package/dist/cjs/runtime/utils/resolvePKFields.js.map +1 -1
  109. package/dist/cjs/runtime/utils/selfAwareAsync.js +1 -2
  110. package/dist/cjs/runtime/utils/selfAwareAsync.js.map +1 -1
  111. package/dist/cjs/runtime/utils/stringTransformation.js +1 -2
  112. package/dist/cjs/runtime/utils/stringTransformation.js.map +1 -1
  113. package/dist/cjs/util/Brand.js +3 -3
  114. package/dist/cjs/util/Brand.js.map +1 -1
  115. package/dist/cjs/util/index.js.map +1 -1
  116. package/dist/esm/Authorization.d.ts +8 -8
  117. package/dist/esm/Authorization.mjs.map +1 -1
  118. package/dist/esm/CombineSchema.mjs.map +1 -1
  119. package/dist/esm/CustomOperation.mjs.map +1 -1
  120. package/dist/esm/CustomType.mjs.map +1 -1
  121. package/dist/esm/EnumType.mjs.map +1 -1
  122. package/dist/esm/Handler.mjs.map +1 -1
  123. package/dist/esm/ModelField.d.ts +39 -24
  124. package/dist/esm/ModelField.mjs +9 -2
  125. package/dist/esm/ModelField.mjs.map +1 -1
  126. package/dist/esm/ModelIndex.mjs.map +1 -1
  127. package/dist/esm/ModelRelationshipField.mjs.map +1 -1
  128. package/dist/esm/ModelSchema.mjs.map +1 -1
  129. package/dist/esm/ModelType.d.ts +1 -1
  130. package/dist/esm/ModelType.mjs.map +1 -1
  131. package/dist/esm/RefType.mjs.map +1 -1
  132. package/dist/esm/SchemaProcessor.mjs +12 -2
  133. package/dist/esm/SchemaProcessor.mjs.map +1 -1
  134. package/dist/esm/Validate.d.ts +218 -0
  135. package/dist/esm/Validate.mjs +142 -0
  136. package/dist/esm/Validate.mjs.map +1 -0
  137. package/dist/esm/ai/ConversationSchemaGraphQLTypes.mjs.map +1 -1
  138. package/dist/esm/ai/ConversationSchemaProcessor.mjs.map +1 -1
  139. package/dist/esm/ai/ConversationType.mjs.map +1 -1
  140. package/dist/esm/ai/ModelType.mjs.map +1 -1
  141. package/dist/esm/ai/types/ConversationMessageContent.d.ts +14 -3
  142. package/dist/esm/ai/types/contentBlocks.d.ts +8 -0
  143. package/dist/esm/index.d.ts +1 -1
  144. package/dist/esm/runtime/addSchemaToClient.mjs.map +1 -1
  145. package/dist/esm/runtime/addSchemaToClientWithInstance.mjs.map +1 -1
  146. package/dist/esm/runtime/bridge-types.mjs.map +1 -1
  147. package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
  148. package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs +12 -0
  149. package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs.map +1 -1
  150. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.d.ts +8 -0
  151. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs +12 -0
  152. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs.map +1 -1
  153. package/dist/esm/runtime/internals/ai/conversationStreamEventDeserializers.mjs.map +1 -1
  154. package/dist/esm/runtime/internals/ai/convertItemToConversation.mjs.map +1 -1
  155. package/dist/esm/runtime/internals/ai/createCreateConversationFunction.d.ts +1 -1
  156. package/dist/esm/runtime/internals/ai/createCreateConversationFunction.mjs.map +1 -1
  157. package/dist/esm/runtime/internals/ai/createDeleteConversationFunction.d.ts +1 -1
  158. package/dist/esm/runtime/internals/ai/createDeleteConversationFunction.mjs.map +1 -1
  159. package/dist/esm/runtime/internals/ai/createGetConversationFunction.d.ts +1 -1
  160. package/dist/esm/runtime/internals/ai/createGetConversationFunction.mjs.map +1 -1
  161. package/dist/esm/runtime/internals/ai/createListConversationsFunction.d.ts +1 -1
  162. package/dist/esm/runtime/internals/ai/createListConversationsFunction.mjs.map +1 -1
  163. package/dist/esm/runtime/internals/ai/createListMessagesFunction.d.ts +1 -1
  164. package/dist/esm/runtime/internals/ai/createListMessagesFunction.mjs.map +1 -1
  165. package/dist/esm/runtime/internals/ai/createOnStreamEventFunction.d.ts +1 -1
  166. package/dist/esm/runtime/internals/ai/createOnStreamEventFunction.mjs.map +1 -1
  167. package/dist/esm/runtime/internals/ai/createSendMessageFunction.d.ts +1 -1
  168. package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs +1 -1
  169. package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs.map +1 -1
  170. package/dist/esm/runtime/internals/ai/createUpdateConversationFunction.d.ts +1 -1
  171. package/dist/esm/runtime/internals/ai/createUpdateConversationFunction.mjs.map +1 -1
  172. package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.mjs.map +1 -1
  173. package/dist/esm/runtime/internals/cancellation.mjs.map +1 -1
  174. package/dist/esm/runtime/internals/clientUtils.mjs.map +1 -1
  175. package/dist/esm/runtime/internals/generateCustomOperationsProperty.d.ts +3 -3
  176. package/dist/esm/runtime/internals/generateCustomOperationsProperty.mjs.map +1 -1
  177. package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
  178. package/dist/esm/runtime/internals/operations/get.mjs.map +1 -1
  179. package/dist/esm/runtime/internals/operations/indexQuery.mjs +1 -1
  180. package/dist/esm/runtime/internals/operations/indexQuery.mjs.map +1 -1
  181. package/dist/esm/runtime/internals/operations/list.mjs.map +1 -1
  182. package/dist/esm/runtime/internals/operations/observeQuery.mjs.map +1 -1
  183. package/dist/esm/runtime/internals/operations/subscription.mjs.map +1 -1
  184. package/dist/esm/runtime/internals/operations/utils.mjs.map +1 -1
  185. package/dist/esm/runtime/internals/server/generateModelsProperty.mjs.map +1 -1
  186. package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs.map +1 -1
  187. package/dist/esm/runtime/internals/utils/clientProperties/generateEnumsProperty.d.ts +1 -1
  188. package/dist/esm/runtime/internals/utils/clientProperties/generateEnumsProperty.mjs.map +1 -1
  189. package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.mjs.map +1 -1
  190. package/dist/esm/runtime/internals/utils/clientProperties/generateModelsProperty.mjs.map +1 -1
  191. package/dist/esm/runtime/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs.map +1 -1
  192. package/dist/esm/runtime/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs.map +1 -1
  193. package/dist/esm/runtime/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs.map +1 -1
  194. package/dist/esm/runtime/utils/findIndexByFields.mjs.map +1 -1
  195. package/dist/esm/runtime/utils/resolveOwnerFields.mjs.map +1 -1
  196. package/dist/esm/runtime/utils/resolvePKFields.mjs.map +1 -1
  197. package/dist/esm/runtime/utils/selfAwareAsync.mjs.map +1 -1
  198. package/dist/esm/runtime/utils/stringTransformation.mjs.map +1 -1
  199. package/dist/esm/util/Brand.mjs.map +1 -1
  200. package/dist/meta/cjs.tsbuildinfo +1 -1
  201. package/package.json +1 -1
  202. package/src/ModelField.ts +70 -29
  203. package/src/SchemaProcessor.ts +12 -0
  204. package/src/Validate.ts +418 -0
  205. package/src/ai/types/ConversationMessageContent.ts +20 -1
  206. package/src/ai/types/contentBlocks.ts +19 -0
  207. package/src/index.ts +1 -1
  208. package/src/runtime/internals/ai/conversationMessageDeserializers.ts +13 -0
  209. package/src/runtime/internals/ai/conversationMessageSerializers.ts +16 -0
@@ -1 +1 @@
1
- {"version":3,"file":"ModelField.mjs","sources":["../../src/ModelField.ts"],"sourcesContent":["import { brand } from './util';\nimport { allow } from './Authorization';\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexport const __auth = Symbol('__auth');\n/**\n * Used by `.default()` to represent a generated field (SQL).\n */\nexport const __generated = Symbol('__generated');\nconst brandName = 'modelField';\nconst internal = Symbol('internal');\nexport var ModelFieldType;\n(function (ModelFieldType) {\n ModelFieldType[\"Id\"] = \"ID\";\n ModelFieldType[\"String\"] = \"String\";\n ModelFieldType[\"Integer\"] = \"Int\";\n ModelFieldType[\"Float\"] = \"Float\";\n ModelFieldType[\"Boolean\"] = \"Boolean\";\n ModelFieldType[\"Date\"] = \"AWSDate\";\n ModelFieldType[\"Time\"] = \"AWSTime\";\n ModelFieldType[\"DateTime\"] = \"AWSDateTime\";\n ModelFieldType[\"Timestamp\"] = \"AWSTimestamp\";\n ModelFieldType[\"Email\"] = \"AWSEmail\";\n ModelFieldType[\"JSON\"] = \"AWSJSON\";\n ModelFieldType[\"Phone\"] = \"AWSPhone\";\n ModelFieldType[\"Url\"] = \"AWSURL\";\n ModelFieldType[\"IPAddress\"] = \"AWSIPAddress\";\n})(ModelFieldType || (ModelFieldType = {}));\nexport var ModelFieldDataType;\n(function (ModelFieldDataType) {\n ModelFieldDataType[\"String\"] = \"string\";\n ModelFieldDataType[\"Number\"] = \"number\";\n ModelFieldDataType[\"Boolean\"] = \"boolean\";\n ModelFieldDataType[\"Date\"] = \"Date\";\n ModelFieldDataType[\"JSON\"] = \"any\";\n})(ModelFieldDataType || (ModelFieldDataType = {}));\n/**\n * Model Field Implementation\n *\n * @typeParam T - holds the JS data type of the field; invoking the public methods changes this type accordingly\n * @example\n * string() => T = string | null\n * string().array() => T = Array<string | null> | null\n * string().array().required() => T = Array<string | null>\n * string().required().array().required() => T = Array<string>\n *\n * @param fieldType - stores the GraphQL data type of the field\n */\nfunction _field(fieldType) {\n const _meta = {\n lastInvokedMethod: null,\n };\n const data = {\n fieldType,\n required: false,\n array: false,\n arrayRequired: false,\n default: undefined,\n authorization: [],\n };\n const builder = {\n required() {\n if (_meta.lastInvokedMethod === 'array') {\n data.arrayRequired = true;\n }\n else {\n data.required = true;\n }\n _meta.lastInvokedMethod = 'required';\n return this;\n },\n array() {\n data.array = true;\n _meta.lastInvokedMethod = 'array';\n return this;\n },\n default(val) {\n data.default = typeof val === 'undefined' ? __generated : val;\n _meta.lastInvokedMethod = 'default';\n return this;\n },\n authorization(callback) {\n const { resource: _, ...rest } = allow;\n const rules = callback(rest);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n _meta.lastInvokedMethod = 'authorization';\n return this;\n },\n ...brand(brandName),\n [internal]() {\n return this;\n },\n };\n // this double cast gives us a Subtyping Constraint i.e., hides `data` from the public API,\n // but makes it available internally when needed\n return { ...builder, data };\n}\n/**\n * A unique identifier scalar type. This scalar is serialized like a String but isn't meant to be human-readable.\n * If not specified on create operations, a ULID will be auto-generated service-side.\n * @returns ID field definition\n */\nexport function id() {\n return _field(ModelFieldType.Id);\n}\n/**\n * A string scalar type that is represented server-side as a UTF-8 character sequence.\n * @returns string field definition\n */\nexport function string() {\n return _field(ModelFieldType.String);\n}\n/**\n * An integer scalar type with a supported value range between -(2^31) and 2^31-1.\n * @returns integer field definition\n */\nexport function integer() {\n return _field(ModelFieldType.Integer);\n}\n/**\n * A float scalar type following represented server-side as an IEEE 754 floating point value.\n * @returns float field definition\n */\nexport function float() {\n return _field(ModelFieldType.Float);\n}\n/**\n * A boolean scalar type that can be either true or false.\n * @returns boolean field definition\n */\nexport function boolean() {\n return _field(ModelFieldType.Boolean);\n}\n/**\n * A date scalar type that is represented server-side as an extended ISO 8601 date string in the format `YYYY-MM-DD`.\n * @returns date field definition\n */\nexport function date() {\n return _field(ModelFieldType.Date);\n}\n/**\n * A time scalar type that is represented server-side as an extended ISO 8601 time string in the format `hh:mm:ss.sss`.\n * @returns time field definition\n */\nexport function time() {\n return _field(ModelFieldType.Time);\n}\n/**\n * A date time scalar type that is represented server-side as an extended ISO 8601 date and time string in the format `YYYY-MM-DDThh:mm:ss.sssZ`.\n * @returns datetime field definition\n */\nexport function datetime() {\n return _field(ModelFieldType.DateTime);\n}\n/**\n * A timestamp scalar type that is represented by an integer value of the number of seconds before or after `1970-01-01-T00:00Z`.\n * @returns timestamp field definition\n */\nexport function timestamp() {\n return _field(ModelFieldType.Timestamp);\n}\n/**\n * An email scalar type that is represented server-side in the format `local-part@domain-part` as defined by RFC 822.\n * @returns email field definition\n */\nexport function email() {\n return _field(ModelFieldType.Email);\n}\n/**\n * A JSON scalar type that is automatically parsed and loaded server-side as maps, lists, or scalar values\n * rather than as the literal input strings.\n * @returns JSON field definition\n */\nexport function json() {\n return _field(ModelFieldType.JSON);\n}\n/**\n * A phone number scalar type thas is stored as a string server-side. Phone numbers can contain either spaces\n * or hyphens to separate digit groups. Phone numbers without a country code are assumed to be US/North American numbers adhering\n * to the North American Numbering Plan.\n * @returns phone number field definition\n */\nexport function phone() {\n return _field(ModelFieldType.Phone);\n}\n/**\n * A URL scalar type as defined by RFC 1738. For example, https://www.amazon.com/dp/B000NZW3KC/ or mailto:example@example.com.\n * URLs must contain a schema (http, mailto) and can't contain two forward slashes (//) in the path part.\n * @returns URL field definition\n */\nexport function url() {\n return _field(ModelFieldType.Url);\n}\n/**\n * A valid IPv4 or IPv6 address scalar type. IPv4 addresses are expected in quad-dotted notation (123.12.34.56). IPv6 addresses\n * are expected in non-bracketed, colon-separated format (1a2b:3c4b:🔢4567). You can include an optional CIDR suffix (123.45.67.89/16)\n * to indicate subnet mask.\n * @returns IP address field definition\n */\nexport function ipAddress() {\n return _field(ModelFieldType.IPAddress);\n}\n"],"names":[],"mappings":";;;AAEA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE;AACvC;AACA;AACA;AACY,MAAC,WAAW,GAAG,MAAM,CAAC,aAAa,EAAE;AACjD,MAAM,SAAS,GAAG,YAAY,CAAC;AAC/B,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC1B,IAAC,eAAe;AAC1B,CAAC,UAAU,cAAc,EAAE;AAC3B,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAChC,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AACxC,IAAI,cAAc,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;AACtC,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AACtC,IAAI,cAAc,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AAC1C,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AACvC,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AACvC,IAAI,cAAc,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC;AAC/C,IAAI,cAAc,CAAC,WAAW,CAAC,GAAG,cAAc,CAAC;AACjD,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC;AACzC,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AACvC,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC;AACzC,IAAI,cAAc,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;AACrC,IAAI,cAAc,CAAC,WAAW,CAAC,GAAG,cAAc,C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I,OAAO,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,GAAG;AAC5B,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;AAC5C;;;;"}
1
+ {"version":3,"file":"ModelField.mjs","sources":["../../src/ModelField.ts"],"sourcesContent":["import { brand } from './util';\nimport { allow } from './Authorization';\nimport { createValidationBuilder, } from './Validate';\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexport const __auth = Symbol('__auth');\n/**\n * Used by `.default()` to represent a generated field (SQL).\n */\nexport const __generated = Symbol('__generated');\nconst brandName = 'modelField';\nconst internal = Symbol('internal');\nexport var ModelFieldType;\n(function (ModelFieldType) {\n ModelFieldType[\"Id\"] = \"ID\";\n ModelFieldType[\"String\"] = \"String\";\n ModelFieldType[\"Integer\"] = \"Int\";\n ModelFieldType[\"Float\"] = \"Float\";\n ModelFieldType[\"Boolean\"] = \"Boolean\";\n ModelFieldType[\"Date\"] = \"AWSDate\";\n ModelFieldType[\"Time\"] = \"AWSTime\";\n ModelFieldType[\"DateTime\"] = \"AWSDateTime\";\n ModelFieldType[\"Timestamp\"] = \"AWSTimestamp\";\n ModelFieldType[\"Email\"] = \"AWSEmail\";\n ModelFieldType[\"JSON\"] = \"AWSJSON\";\n ModelFieldType[\"Phone\"] = \"AWSPhone\";\n ModelFieldType[\"Url\"] = \"AWSURL\";\n ModelFieldType[\"IPAddress\"] = \"AWSIPAddress\";\n})(ModelFieldType || (ModelFieldType = {}));\nexport var ModelFieldDataType;\n(function (ModelFieldDataType) {\n ModelFieldDataType[\"String\"] = \"string\";\n ModelFieldDataType[\"Number\"] = \"number\";\n ModelFieldDataType[\"Boolean\"] = \"boolean\";\n ModelFieldDataType[\"Date\"] = \"Date\";\n ModelFieldDataType[\"JSON\"] = \"any\";\n})(ModelFieldDataType || (ModelFieldDataType = {}));\n/**\n * Model Field Implementation\n *\n * @typeParam T - holds the JS data type of the field; invoking the public methods changes this type accordingly\n * @example\n * string() => T = string | null\n * string().array() => T = Array<string | null> | null\n * string().array().required() => T = Array<string | null>\n * string().required().array().required() => T = Array<string>\n *\n * @param fieldType - stores the GraphQL data type of the field\n */\nfunction _field(fieldType) {\n const _meta = {\n lastInvokedMethod: null,\n };\n const data = {\n fieldType,\n required: false,\n array: false,\n arrayRequired: false,\n default: undefined,\n authorization: [],\n validation: [],\n };\n const builder = {\n required() {\n if (_meta.lastInvokedMethod === 'array') {\n data.arrayRequired = true;\n }\n else {\n data.required = true;\n }\n _meta.lastInvokedMethod = 'required';\n return this;\n },\n array() {\n data.array = true;\n _meta.lastInvokedMethod = 'array';\n return this;\n },\n default(val) {\n data.default = typeof val === 'undefined' ? __generated : val;\n _meta.lastInvokedMethod = 'default';\n return this;\n },\n authorization(callback) {\n const { resource: _, ...rest } = allow;\n const rules = callback(rest);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n _meta.lastInvokedMethod = 'authorization';\n return this;\n },\n validate(callback) {\n const { builder, getRules } = createValidationBuilder();\n callback(builder);\n data.validation = getRules();\n _meta.lastInvokedMethod = 'validate';\n return this;\n },\n ...brand(brandName),\n [internal]() {\n return this;\n },\n };\n return { ...builder, data };\n}\n/**\n * A unique identifier scalar type. This scalar is serialized like a String but isn't meant to be human-readable.\n * If not specified on create operations, a ULID will be auto-generated service-side.\n * @returns ID field definition\n */\nexport function id() {\n return _field(ModelFieldType.Id);\n}\n/**\n * A string scalar type that is represented server-side as a UTF-8 character sequence.\n * @returns string field definition\n */\nexport function string() {\n return _field(ModelFieldType.String);\n}\n/**\n * An integer scalar type with a supported value range between -(2^31) and 2^31-1.\n * @returns integer field definition\n */\nexport function integer() {\n return _field(ModelFieldType.Integer);\n}\n/**\n * A float scalar type following represented server-side as an IEEE 754 floating point value.\n * @returns float field definition\n */\nexport function float() {\n return _field(ModelFieldType.Float);\n}\n/**\n * A boolean scalar type that can be either true or false.\n * @returns boolean field definition\n */\nexport function boolean() {\n return _field(ModelFieldType.Boolean);\n}\n/**\n * A date scalar type that is represented server-side as an extended ISO 8601 date string in the format `YYYY-MM-DD`.\n * @returns date field definition\n */\nexport function date() {\n return _field(ModelFieldType.Date);\n}\n/**\n * A time scalar type that is represented server-side as an extended ISO 8601 time string in the format `hh:mm:ss.sss`.\n * @returns time field definition\n */\nexport function time() {\n return _field(ModelFieldType.Time);\n}\n/**\n * A date time scalar type that is represented server-side as an extended ISO 8601 date and time string in the format `YYYY-MM-DDThh:mm:ss.sssZ`.\n * @returns datetime field definition\n */\nexport function datetime() {\n return _field(ModelFieldType.DateTime);\n}\n/**\n * A timestamp scalar type that is represented by an integer value of the number of seconds before or after `1970-01-01-T00:00Z`.\n * @returns timestamp field definition\n */\nexport function timestamp() {\n return _field(ModelFieldType.Timestamp);\n}\n/**\n * An email scalar type that is represented server-side in the format `local-part@domain-part` as defined by RFC 822.\n * @returns email field definition\n */\nexport function email() {\n return _field(ModelFieldType.Email);\n}\n/**\n * A JSON scalar type that is automatically parsed and loaded server-side as maps, lists, or scalar values\n * rather than as the literal input strings.\n * @returns JSON field definition\n */\nexport function json() {\n return _field(ModelFieldType.JSON);\n}\n/**\n * A phone number scalar type thas is stored as a string server-side. Phone numbers can contain either spaces\n * or hyphens to separate digit groups. Phone numbers without a country code are assumed to be US/North American numbers adhering\n * to the North American Numbering Plan.\n * @returns phone number field definition\n */\nexport function phone() {\n return _field(ModelFieldType.Phone);\n}\n/**\n * A URL scalar type as defined by RFC 1738. For example, https://www.amazon.com/dp/B000NZW3KC/ or mailto:example@example.com.\n * URLs must contain a schema (http, mailto) and can't contain two forward slashes (//) in the path part.\n * @returns URL field definition\n */\nexport function url() {\n return _field(ModelFieldType.Url);\n}\n/**\n * A valid IPv4 or IPv6 address scalar type. IPv4 addresses are expected in quad-dotted notation (123.12.34.56). IPv6 addresses\n * are expected in non-bracketed, colon-separated format (1a2b:3c4b:🔢4567). You can include an optional CIDR suffix (123.45.67.89/16)\n * to indicate subnet mask.\n * @returns IP address field definition\n */\nexport function ipAddress() {\n return _field(ModelFieldType.IPAddress);\n}\n"],"names":[],"mappings":";;;;AAGA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,CAAC,QAAQ;AACrC;AACA;AACA;AACY,MAAC,WAAW,GAAG,MAAM,CAAC,aAAa;AAC/C,MAAM,SAAS,GAAG,YAAY;AAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC;AACzB,IAAC;AACX,CAAC,UAAU,cAAc,EAAE;AAC3B,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI;AAC/B,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACvC,IAAI,cAAc,CAAC,SAAS,CAAC,GAAG,KAAK;AACrC,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO;AACrC,IAAI,cAAc,CAAC,SAAS,CAAC,GAAG,SAAS;AACzC,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS;AACtC,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS;AACtC,IAAI,cAAc,CAAC,UAAU,CAAC,GAAG,aAAa;AAC9C,IAAI,cAAc,CAAC,WAAW,CAAC,GAAG,cAAc;AAChD,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,UAAU;AACxC,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS;AACtC,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,UAAU;AACxC,IAAI,cAAc,CAAC,KAAK,CAAC,GAAG,QAAQ;AACpC,IAAI,cAAc,CAAC,WAAW,CAAC,GAAG,cAAc;AAChD,CAAC,EAAE,cAAc,KAAK,cAAc,GAAG,EAAE,CAAC,CAAC;AACjC,IAAC;AACX,CAAC,UAAU,kBAAkB,EAAE;AAC/B,IAAI,kBAAkB,CAAC,QAAQ,CAAC,GAAG,QAAQ;AAC3C,IAAI,kBAAkB,CAAC,QAAQ,CAAC,GAAG,QAAQ;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,SAAS,KAAK,GAAG;AACxB,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC;AACvC;AACA;AACA;AACA;AACA;AACO,SAAS,OAAO,GAAG;AAC1B,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC;AACzC;AACA;AACA;AACA;AACA;AACO,SAAS,IAAI,GAAG;AACvB,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;AACtC;AACA;AACA;AACA;AACA;AACO,SAAS,IAAI,GAAG;AACvB,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;AACtC;AACA;AACA;AACA;AACA;AACO,SAAS,QAAQ,GAAG;AAC3B,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC;AAC1C;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,GAAG;AAC5B,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC;AAC3C;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,GAAG;AACxB,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC;AACvC;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,IAAI,GAAG;AACvB,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,GAAG;AACxB,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC;AACvC;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,GAAG,GAAG;AACtB,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,GAAG;AAC5B,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC;AAC3C;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ModelIndex.mjs","sources":["../../src/ModelIndex.ts"],"sourcesContent":["import { brand } from './util';\nconst brandName = 'modelIndexType';\nfunction _modelIndex(partitionKeyFieldName) {\n const data = {\n partitionKey: partitionKeyFieldName,\n sortKeys: [],\n indexName: '',\n queryField: '',\n };\n const builder = {\n sortKeys(sortKeys) {\n data.sortKeys = sortKeys;\n return this;\n },\n name(name) {\n data.indexName = name;\n return this;\n },\n queryField(field) {\n data.queryField = field;\n return this;\n },\n ...brand(brandName),\n };\n return { ...builder, data };\n}\nexport function modelIndex(partitionKeyFieldName) {\n return _modelIndex(partitionKeyFieldName);\n}\n"],"names":[],"mappings":";;AACA,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,SAAS,WAAW,CAAC,qBAAqB,EAAE;AAC5C,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,YAAY,EAAE,qBAAqB;AAC3C,QAAQ,QAAQ,EAAE,EAAE;AACpB,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,EAAE;AACtB,KAAK,CAAC;AACN,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,QAAQ,CAAC,QAAQ,EAAE;AAC3B,YAAY,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACrC,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,IAAI,CAAC,IAAI,EAAE;AACnB,YAAY,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;AAClC,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,UAAU,CAAC,KAAK,EAAE;AAC1B,YAAY,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;AACpC,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC;AAC3B,KAAK,CAAC;AACN,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;AACM,SAAS,UAAU,CAAC,qBAAqB,EAAE;AAClD,IAAI,OAAO,WAAW,CAAC,qBAAqB,CAAC,CAAC;AAC9C;;;;"}
1
+ {"version":3,"file":"ModelIndex.mjs","sources":["../../src/ModelIndex.ts"],"sourcesContent":["import { brand } from './util';\nconst brandName = 'modelIndexType';\nfunction _modelIndex(partitionKeyFieldName) {\n const data = {\n partitionKey: partitionKeyFieldName,\n sortKeys: [],\n indexName: '',\n queryField: '',\n };\n const builder = {\n sortKeys(sortKeys) {\n data.sortKeys = sortKeys;\n return this;\n },\n name(name) {\n data.indexName = name;\n return this;\n },\n queryField(field) {\n data.queryField = field;\n return this;\n },\n ...brand(brandName),\n };\n return { ...builder, data };\n}\nexport function modelIndex(partitionKeyFieldName) {\n return _modelIndex(partitionKeyFieldName);\n}\n"],"names":[],"mappings":";;AACA,MAAM,SAAS,GAAG,gBAAgB;AAClC,SAAS,WAAW,CAAC,qBAAqB,EAAE;AAC5C,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,YAAY,EAAE,qBAAqB;AAC3C,QAAQ,QAAQ,EAAE,EAAE;AACpB,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,EAAE;AACtB,KAAK;AACL,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,QAAQ,CAAC,QAAQ,EAAE;AAC3B,YAAY,IAAI,CAAC,QAAQ,GAAG,QAAQ;AACpC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,IAAI,CAAC,IAAI,EAAE;AACnB,YAAY,IAAI,CAAC,SAAS,GAAG,IAAI;AACjC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,UAAU,CAAC,KAAK,EAAE;AAC1B,YAAY,IAAI,CAAC,UAAU,GAAG,KAAK;AACnC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC;AAC3B,KAAK;AACL,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE;AAC/B;AACO,SAAS,UAAU,CAAC,qBAAqB,EAAE;AAClD,IAAI,OAAO,WAAW,CAAC,qBAAqB,CAAC;AAC7C;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ModelRelationshipField.mjs","sources":["../../src/ModelRelationshipField.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 = 'modelRelationshipField';\n/**\n * Model relationship types\n */\nexport var ModelRelationshipTypes;\n(function (ModelRelationshipTypes) {\n ModelRelationshipTypes[\"hasOne\"] = \"hasOne\";\n ModelRelationshipTypes[\"hasMany\"] = \"hasMany\";\n ModelRelationshipTypes[\"belongsTo\"] = \"belongsTo\";\n})(ModelRelationshipTypes || (ModelRelationshipTypes = {}));\nconst relationshipModifiers = [\n 'required',\n 'valueRequired',\n 'authorization',\n];\nconst relationModifierMap = {\n belongsTo: ['authorization'],\n hasMany: ['valueRequired', 'authorization'],\n hasOne: ['required', 'authorization'],\n};\nfunction _modelRelationshipField(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 _modelRelationshipField(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 _modelRelationshipField(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 _modelRelationshipField(ModelRelationshipTypes.belongsTo, relatedModel, Array.isArray(references) ? references : [references]);\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE;AAEvC;AACA;AACA;AACU,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,uBAA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A;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,uBAAuB,CAAC,sBAAsB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACvI,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,uBAAuB,CAAC,sBAAsB,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACxI,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,uBAAuB,CAAC,sBAAsB,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AAC1I;;;;"}
1
+ {"version":3,"file":"ModelRelationshipField.mjs","sources":["../../src/ModelRelationshipField.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 = 'modelRelationshipField';\n/**\n * Model relationship types\n */\nexport var ModelRelationshipTypes;\n(function (ModelRelationshipTypes) {\n ModelRelationshipTypes[\"hasOne\"] = \"hasOne\";\n ModelRelationshipTypes[\"hasMany\"] = \"hasMany\";\n ModelRelationshipTypes[\"belongsTo\"] = \"belongsTo\";\n})(ModelRelationshipTypes || (ModelRelationshipTypes = {}));\nconst relationshipModifiers = [\n 'required',\n 'valueRequired',\n 'authorization',\n];\nconst relationModifierMap = {\n belongsTo: ['authorization'],\n hasMany: ['valueRequired', 'authorization'],\n hasOne: ['required', 'authorization'],\n};\nfunction _modelRelationshipField(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 _modelRelationshipField(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 _modelRelationshipField(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 _modelRelationshipField(ModelRelationshipTypes.belongsTo, relatedModel, Array.isArray(references) ? references : [references]);\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,CAAC,QAAQ;AAErC;AACA;AACA;AACU,IAAC;AACX,CAAC,UAAU,sBAAsB,EAAE;AACnC,IAAI,sBAAsB,CAAC,QAAQ,CAAC,GAAG,QAAQ;AAC/C,IAAI,sBAAsB,CAAC,SAAS,CAAC,GAAG,SAAS;AACjD,IAAI,sBAAsB,CAAC,WAAW,CAAC,GAAG,WAAW;AACrD,CAAC,EAAE,sBAAsB,KAAK,sBAAsB,GAAG,EAAE,CAAC,CAAC;AAM3D,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;AACD,SAAS,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE;AACjE,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,YAAY;AACpB,QAAQ,IAAI;AACZ,QAAQ,SAAS,EAAE,OAAO;AAC1B,QAAQ,KAAK,EAAE,KAAK;AACpB,QAAQ,aAAa,EAAE,KAAK;AAC5B,QAAQ,aAAa,EAAE,KAAK;AAC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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,OAAO,CAAC,YAAY,EAAE,UAAU,EAAE;AAClD,IAAI,OAAO,uBAAuB,CAAC,sBAAsB,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC;AACvI;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;AACA;AACO,SAAS,SAAS,CAAC,YAAY,EAAE,UAAU,EAAE;AACpD,IAAI,OAAO,uBAAuB,CAAC,sBAAsB,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC;AACzI;;;;"}
@@ -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, 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 = {\n data,\n context: this.context,\n };\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 = {\n data,\n context: this.context,\n };\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":";;;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,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
+ {"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 = {\n data,\n context: this.context,\n };\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 = {\n data,\n context: this.context,\n };\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;AACtB,MAAC,cAAc,GAAG,KAAK,CAAC,kBAAkB;AAC1C,MAAC,kBAAkB,GAAG;AAClC,MAAM,cAAc,GAAG,KAAK,CAAC,kBAAkB,CAAC;AAChD;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,sBAAsB,GAAG,CAAC,cAAc,KAAK;AACnD,IAAI,MAAM,UAAU,GAAG,EAAE;AACzB,IAAI,IAAI,cAAc,EAAE;AACxB,QAAQ,MAAM,CAAC,OAAO,CAAC,cAAc,CA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AAc;AACzB,KAAK;AACL;AACA,SAAS,kBAAkB,CAAC,MAAM,EAAE;AACpC,IAAI,OAAO,CAAC,KAAK,KAAK;AACtB,QAAQ,QAAQ,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK;AAC3C,cAAc,UAAU,CAAC,KAAK,EAAE,MAAM;AACtC,cAAc,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC;AACvC,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE;AAC7E;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;AACL;AACO,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;AACrC;;;;"}
@@ -139,7 +139,7 @@ export type InternalModel = SchemaModelType<ModelType<ModelTypeParamShape>, stri
139
139
  * @param modelType - api-next ModelType
140
140
  * @returns true if the given value is a ModelSchema
141
141
  */
142
- export declare const isSchemaModelType: (modelType: any | SchemaModelType) => modelType is ModelType<ModelTypeParamShape, "identifier">;
142
+ export declare const isSchemaModelType: (modelType: any | SchemaModelType) => modelType is SchemaModelType;
143
143
  /**
144
144
  * Model default identifier
145
145
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ModelType.mjs","sources":["../../src/ModelType.ts"],"sourcesContent":["import { brand, } from './util';\nimport { allow, } from './Authorization';\nimport { modelIndex, } from './ModelIndex';\nconst brandName = 'modelType';\nfunction _model(fields) {\n const data = {\n fields,\n identifier: ['id'],\n secondaryIndexes: [],\n authorization: [],\n disabledOperations: [],\n };\n const builder = {\n identifier(identifier) {\n data.identifier = identifier;\n return this;\n },\n secondaryIndexes(callback) {\n data.secondaryIndexes = callback(modelIndex);\n return this;\n },\n disableOperations(ops) {\n data.disabledOperations = ops;\n return this;\n },\n authorization(callback) {\n const { resource: _, ...rest } = allow;\n const rules = callback(rest);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n ...brand(brandName),\n };\n return {\n ...builder,\n data,\n relationships(relationships) {\n data.fields = { ...data.fields, ...relationships };\n },\n fields: data.fields,\n };\n}\n/**\n * Model Type type guard\n * @param modelType - api-next ModelType\n * @returns true if the given value is a ModelSchema\n */\nexport const isSchemaModelType = (modelType) => {\n const internalType = modelType;\n return (typeof internalType === 'object' &&\n internalType.data !== undefined &&\n internalType.data.fields !== undefined &&\n internalType.data.authorization !== undefined &&\n internalType.data.identifier !== undefined &&\n internalType.data.secondaryIndexes !== undefined &&\n typeof internalType.relationships === 'function');\n};\n/**\n * A data model that creates a matching Amazon DynamoDB table and provides create, read (list and get), update,\n * delete, and subscription APIs.\n *\n * @param fields database table fields. Supports scalar types and relationship types.\n * @returns a data model definition\n */\nexport function model(fields) {\n return _model(fields);\n}\n"],"names":[],"mappings":";;;;AAGA,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,SAAS,MAAM,CAAC,MAAM,EAAE;AACxB,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM;AACd,QAAQ,UAAU,EAAE,CAAC,IAAI,CAAC;AAC1B,QAAQ,gBAAgB,EAAE,EAAE;AAC5B,QAAQ,aAAa,EAAE,EAAE;AACzB,QAAQ,kBAAkB,EAAE,EAAE;AAC9B,KAAK,CAAC;AACN,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,UAAU,CAAC,UAAU,EAAE;AAC/B,YAAY,IAAI,CAAC,UAAU,GAAG,UAA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Y,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS;AAC9C,QAAQ,YAAY,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS;AACrD,QAAQ,YAAY,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS;AAClD,QAAQ,YAAY,CAAC,IAAI,CAAC,gBAAgB,KAAK,SAAS;AACxD,QAAQ,OAAO,YAAY,CAAC,aAAa,KAAK,UAAU,EAAE;AAC1D,EAAE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,CAAC,MAAM,EAAE;AAC9B,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AAC1B;;;;"}
1
+ {"version":3,"file":"ModelType.mjs","sources":["../../src/ModelType.ts"],"sourcesContent":["import { brand, } from './util';\nimport { allow, } from './Authorization';\nimport { modelIndex, } from './ModelIndex';\nconst brandName = 'modelType';\nfunction _model(fields) {\n const data = {\n fields,\n identifier: ['id'],\n secondaryIndexes: [],\n authorization: [],\n disabledOperations: [],\n };\n const builder = {\n identifier(identifier) {\n data.identifier = identifier;\n return this;\n },\n secondaryIndexes(callback) {\n data.secondaryIndexes = callback(modelIndex);\n return this;\n },\n disableOperations(ops) {\n data.disabledOperations = ops;\n return this;\n },\n authorization(callback) {\n const { resource: _, ...rest } = allow;\n const rules = callback(rest);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n ...brand(brandName),\n };\n return {\n ...builder,\n data,\n relationships(relationships) {\n data.fields = { ...data.fields, ...relationships };\n },\n fields: data.fields,\n };\n}\n/**\n * Model Type type guard\n * @param modelType - api-next ModelType\n * @returns true if the given value is a ModelSchema\n */\nexport const isSchemaModelType = (modelType) => {\n const internalType = modelType;\n return (typeof internalType === 'object' &&\n internalType.data !== undefined &&\n internalType.data.fields !== undefined &&\n internalType.data.authorization !== undefined &&\n internalType.data.identifier !== undefined &&\n internalType.data.secondaryIndexes !== undefined &&\n typeof internalType.relationships === 'function');\n};\n/**\n * A data model that creates a matching Amazon DynamoDB table and provides create, read (list and get), update,\n * delete, and subscription APIs.\n *\n * @param fields database table fields. Supports scalar types and relationship types.\n * @returns a data model definition\n */\nexport function model(fields) {\n return _model(fields);\n}\n"],"names":[],"mappings":";;;;AAGA,MAAM,SAAS,GAAG,WAAW;AAC7B,SAAS,MAAM,CAAC,MAAM,EAAE;AACxB,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM;AACd,QAAQ,UAAU,EAAE,CAAC,IAAI,CAAC;AAC1B,QAAQ,gBAAgB,EAAE,EAAE;AAC5B,QAAQ,aAAa,EAAE,EAAE;AACzB,QAAQ,kBAAkB,EAAE,EAAE;AAC9B,KAAK;AACL,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,UAAU,CAAC,UAAU,EAAE;AAC/B,YAAY,IAAI,CAAC,UAAU,GAAG,UAAU;AACxC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,gBAAgB,CAAC,QAAQ,EAAE;AACnC,YAAY,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC,UAAU,CAAC;AACxD,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,iBAAiB,CAAC,GAAG,EAAE;AAC/B,YAAY,IAAI,CAAC,kBAAkB,GAAG,GAAG;AACzC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,aAAa,CAAC,QAAQ,EAAE;AAChC,YAAY,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK;AAClD,YAAY,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC;AACxC,YAAY,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC;AACvE,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC;AAC3B,KAAK;AACL,IAAI,OAAO;AACX,QAAQ,GAAG,OAAO;AAClB,QAAQ,IAAI;AACZ,QAAQ,aAAa,CAAC,aAAa,EAAE;AACrC,YAAY,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,aAAa,EAAE;AAC9D,SAAS;AACT,QAAQ,MAAM,EAAE,IAAI,CAAC,MAAM;AAC3B,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,iBAAiB,GAAG,CAAC,SAAS,KAAK;AAChD,IAAI,MAAM,YAAY,GAAG,SAAS;AAClC,IAAI,QAAQ,OAAO,YAAY,KAAK,QAAQ;AAC5C,QAAQ,YAAY,CAAC,IAAI,KAAK,SAAS;AACvC,QAAQ,YAAY,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS;AAC9C,QAAQ,YAAY,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS;AACrD,QAAQ,YAAY,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS;AAClD,QAAQ,YAAY,CAAC,IAAI,CAAC,gBAAgB,KAAK,SAAS;AACxD,QAAQ,OAAO,YAAY,CAAC,aAAa,KAAK,UAAU;AACxD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,CAAC,MAAM,EAAE;AAC9B,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC;AACzB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"RefType.mjs","sources":["../../src/RefType.ts"],"sourcesContent":["import { allow } from './Authorization';\nimport { __auth } from './ModelField';\nconst brandName = 'ref';\nfunction brandedBuilder(builder) {\n return builder;\n}\nfunction _ref(link) {\n const data = {\n type: 'ref',\n link,\n valueRequired: false,\n array: false,\n arrayRequired: false,\n mutationOperations: [],\n authorization: [],\n };\n const builder = brandedBuilder({\n required() {\n if (data.array) {\n data.arrayRequired = true;\n }\n else {\n data.valueRequired = true;\n }\n return this;\n },\n array() {\n data.array = 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 mutations(operations) {\n data.mutationOperations = operations;\n return this;\n },\n });\n return { ...builder, data };\n}\nexport function ref(link) {\n return _ref(link);\n}\n"],"names":[],"mappings":";;;AAGA,SAAS,cAAc,CAAC,OAAO,EAAE;AACjC,IAAI,OAAO,OAAO,CAAC;AACnB,CAAC;AACD,SAAS,IAAI,CAAC,IAAI,EAAE;AACpB,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,IAAI,EAAE,KAAK;AACnB,QAAQ,IAAI;AACZ,QAAQ,aAAa,EAAE,KAAK;AAC5B,QAAQ,KAAK,EAAE,KAAK;AACpB,QAAQ,aAAa,EAAE,KAAK;AAC5B,QAAQ,kBAAkB,EAAE,EAAE;AAC9B,QAAQ,aAAa,EAAE,EAAE;AACzB,KAAK,CAAC;AACN,IAAI,MAAM,OAAO,GAAG,cAAc,CAAC;AACnC,QAAQ,QAAQ,GAAG;AACnB,YAAY,IAAI,IAAI,CAAC,KAAK,EAAE;AAC5B,gBAAgB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;AAC1C,aAAa;AACb,iBAAiB;AACjB,gBAAgB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;AAC1C,aAAa;AACb,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,KAAK,GAAG;AAChB,YAAY,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;AAC9B,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,aAAa,CAAC,QAAQ,EAAE;AAChC,YAAY,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC1C,YAAY,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC;AACxE,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,SAAS,CAAC,UAAU,EAAE;AAC9B,YAAY,IAAI,CAAC,kBAAkB,GAAG,UAAU,CAAC;AACjD,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;AACM,SAAS,GAAG,CAAC,IAAI,EAAE;AAC1B,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AACtB;;;;"}
1
+ {"version":3,"file":"RefType.mjs","sources":["../../src/RefType.ts"],"sourcesContent":["import { allow } from './Authorization';\nimport { __auth } from './ModelField';\nconst brandName = 'ref';\nfunction brandedBuilder(builder) {\n return builder;\n}\nfunction _ref(link) {\n const data = {\n type: 'ref',\n link,\n valueRequired: false,\n array: false,\n arrayRequired: false,\n mutationOperations: [],\n authorization: [],\n };\n const builder = brandedBuilder({\n required() {\n if (data.array) {\n data.arrayRequired = true;\n }\n else {\n data.valueRequired = true;\n }\n return this;\n },\n array() {\n data.array = 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 mutations(operations) {\n data.mutationOperations = operations;\n return this;\n },\n });\n return { ...builder, data };\n}\nexport function ref(link) {\n return _ref(link);\n}\n"],"names":[],"mappings":";;;AAGA,SAAS,cAAc,CAAC,OAAO,EAAE;AACjC,IAAI,OAAO,OAAO;AAClB;AACA,SAAS,IAAI,CAAC,IAAI,EAAE;AACpB,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,IAAI,EAAE,KAAK;AACnB,QAAQ,IAAI;AACZ,QAAQ,aAAa,EAAE,KAAK;AAC5B,QAAQ,KAAK,EAAE,KAAK;AACpB,QAAQ,aAAa,EAAE,KAAK;AAC5B,QAAQ,kBAAkB,EAAE,EAAE;AAC9B,QAAQ,aAAa,EAAE,EAAE;AACzB,KAAK;AACL,IAAI,MAAM,OAAO,GAAG,cAAc,CAAC;AACnC,QAAQ,QAAQ,GAAG;AACnB,YAAY,IAAI,IAAI,CAAC,KAAK,EAAE;AAC5B,gBAAgB,IAAI,CAAC,aAAa,GAAG,IAAI;AACzC;AACA,iBAAiB;AACjB,gBAAgB,IAAI,CAAC,aAAa,GAAG,IAAI;AACzC;AACA,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,KAAK,GAAG;AAChB,YAAY,IAAI,CAAC,KAAK,GAAG,IAAI;AAC7B,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,aAAa,CAAC,QAAQ,EAAE;AAChC,YAAY,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;AACzC,YAAY,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC;AACvE,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,SAAS,CAAC,UAAU,EAAE;AAC9B,YAAY,IAAI,CAAC,kBAAkB,GAAG,UAAU;AAChD,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,KAAK,CAAC;AACN,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE;AAC/B;AACO,SAAS,GAAG,CAAC,IAAI,EAAE;AAC1B,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC;AACrB;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { ModelFieldType, string, __generated } from './ModelField.mjs';
2
2
  import { ModelRelationshipTypes } from './ModelRelationshipField.mjs';
3
- import { accessData, accessSchemaData } from './Authorization.mjs';
3
+ import { accessSchemaData, accessData } from './Authorization.mjs';
4
4
  import { CustomOperationNames } from './CustomOperation.mjs';
5
5
  import { getBrand, brandSymbol } from './util/Brand.mjs';
6
6
  import { getHandlerData } from './Handler.mjs';
@@ -70,7 +70,7 @@ function canGenerateFieldType(fieldType) {
70
70
  return fieldType === 'Int';
71
71
  }
72
72
  function scalarFieldToGql(fieldDef, identifier, secondaryIndexes = []) {
73
- const { fieldType, required, array, arrayRequired, default: _default, } = fieldDef;
73
+ const { fieldType, required, array, arrayRequired, default: _default, validation = [], } = fieldDef;
74
74
  let field = fieldType;
75
75
  if (identifier !== undefined) {
76
76
  field += '!';
@@ -109,6 +109,16 @@ function scalarFieldToGql(fieldDef, identifier, secondaryIndexes = []) {
109
109
  for (const index of secondaryIndexes) {
110
110
  field += ` ${index}`;
111
111
  }
112
+ // Add validation directives for each validation rule
113
+ for (const validationRule of validation) {
114
+ const valueStr = typeof validationRule.value === 'number' ? validationRule.value.toString() : validationRule.value;
115
+ if (validationRule.errorMessage) {
116
+ field += ` @validate(type: ${validationRule.type}, value: "${valueStr}", errorMessage: ${escapeGraphQlString(validationRule.errorMessage)})`;
117
+ }
118
+ else {
119
+ field += ` @validate(type: ${validationRule.type}, value: "${valueStr}")`;
120
+ }
121
+ }
112
122
  return field;
113
123
  }
114
124
  function modelFieldToGql(fieldDef) {