@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":"ModelIndex.js","sources":["../../src/ModelIndex.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.modelIndex = void 0;\nconst util_1 = require(\"./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 ...(0, util_1.brand)(brandName),\n };\n return { ...builder, data };\n}\nfunction modelIndex(partitionKeyFieldName) {\n return _modelIndex(partitionKeyFieldName);\n}\nexports.modelIndex = modelIndex;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;AAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,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,IAAI,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC;AACvC,KAAK,CAAC;AACN,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;AACD,SAAS,UAAU,CAAC,qBAAqB,EAAE;AAC3C,IAAI,OAAO,WAAW,CAAC,qBAAqB,CAAC,CAAC;AAC9C,CAAC;AACD,OAAO,CAAC,UAAU,GAAG,UAAU;;"}
1
+ {"version":3,"file":"ModelIndex.js","sources":["../../src/ModelIndex.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.modelIndex = modelIndex;\nconst util_1 = require(\"./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 ...(0, util_1.brand)(brandName),\n };\n return { ...builder, data };\n}\nfunction modelIndex(partitionKeyFieldName) {\n return _modelIndex(partitionKeyFieldName);\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,UAAU,GAAG,UAAU;AAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;AAChC,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,IAAI,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC;AACvC,KAAK;AACL,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE;AAC/B;AACA,SAAS,UAAU,CAAC,qBAAqB,EAAE;AAC3C,IAAI,OAAO,WAAW,CAAC,qBAAqB,CAAC;AAC7C;;"}
@@ -1,7 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.belongsTo = exports.hasMany = exports.hasOne = exports.ModelRelationshipTypes = exports.__auth = void 0;
4
+ exports.ModelRelationshipTypes = exports.__auth = void 0;
5
+ exports.hasOne = hasOne;
6
+ exports.hasMany = hasMany;
7
+ exports.belongsTo = belongsTo;
5
8
  const Authorization_1 = require("./Authorization");
6
9
  /**
7
10
  * Used to "attach" auth types to ModelField without exposing them on the builder.
@@ -85,7 +88,6 @@ function _modelRelationshipField(type, relatedModel, references) {
85
88
  function hasOne(relatedModel, references) {
86
89
  return _modelRelationshipField(ModelRelationshipTypes.hasOne, relatedModel, Array.isArray(references) ? references : [references]);
87
90
  }
88
- exports.hasOne = hasOne;
89
91
  /**
90
92
  * Create a one-directional one-to-many relationship between two models using the `hasMany("MODEL_NAME", "REFERENCE_FIELD(s)")` method.
91
93
  * @example
@@ -115,7 +117,6 @@ exports.hasOne = hasOne;
115
117
  function hasMany(relatedModel, references) {
116
118
  return _modelRelationshipField(ModelRelationshipTypes.hasMany, relatedModel, Array.isArray(references) ? references : [references]);
117
119
  }
118
- exports.hasMany = hasMany;
119
120
  /**
120
121
  * Use `belongsTo()` to create a field to query the related `hasOne()` or `hasMany()` relationship.
121
122
  * The belongsTo() method requires that a hasOne() or hasMany() relationship already exists from
@@ -166,5 +167,4 @@ exports.hasMany = hasMany;
166
167
  function belongsTo(relatedModel, references) {
167
168
  return _modelRelationshipField(ModelRelationshipTypes.belongsTo, relatedModel, Array.isArray(references) ? references : [references]);
168
169
  }
169
- exports.belongsTo = belongsTo;
170
170
  //# sourceMappingURL=ModelRelationshipField.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModelRelationshipField.js","sources":["../../src/ModelRelationshipField.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.belongsTo = exports.hasMany = exports.hasOne = exports.ModelRelationshipTypes = exports.__auth = void 0;\nconst Authorization_1 = require(\"./Authorization\");\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexports.__auth = Symbol('__auth');\nconst brandName = 'modelRelationshipField';\n/**\n * Model relationship types\n */\nvar ModelRelationshipTypes;\n(function (ModelRelationshipTypes) {\n ModelRelationshipTypes[\"hasOne\"] = \"hasOne\";\n ModelRelationshipTypes[\"hasMany\"] = \"hasMany\";\n ModelRelationshipTypes[\"belongsTo\"] = \"belongsTo\";\n})(ModelRelationshipTypes || (exports.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(Authorization_1.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 */\nfunction hasOne(relatedModel, references) {\n return _modelRelationshipField(ModelRelationshipTypes.hasOne, relatedModel, Array.isArray(references) ? references : [references]);\n}\nexports.hasOne = hasOne;\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 */\nfunction hasMany(relatedModel, references) {\n return _modelRelationshipField(ModelRelationshipTypes.hasMany, relatedModel, Array.isArray(references) ? references : [references]);\n}\nexports.hasMany = hasMany;\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 */\nfunction belongsTo(relatedModel, references) {\n return _modelRelationshipField(ModelRelationshipTypes.belongsTo, relatedModel, Array.isArray(references) ? references : [references]);\n}\nexports.belongsTo = belongsTo;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,sBAAsB,GAAG,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;AAChH,MAAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACnD;AACA;AACA;AACA,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAElC;AACA;AACA;AACA,IAAI,sBAAsB,CAAC;AAC3B,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,OAAO,CAAC,sBAAsB,GAAG,sBAAsB,GAAG,EAAE,CAAC,CAAC,CAAC;AAM7F,MAAM,mBAAmB,GAAG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AQ,GAAG;AACX,QAAQ,4BAA4B,CAAC,GAAG,CAAC;AACzC,KAAK,CAAC,CAAC,CAAC;AACR,IAAI,OAAO;AACX,QAAQ,GAAG,OAAO;AAClB,QAAQ,IAAI;AACZ,KAAK,CAAC;AACN,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,SAAS,MAAM,CAAC,YAAY,EAAE,UAAU,EAAE;AAC1C,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,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;AACxB;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,SAAS,OAAO,CAAC,YAAY,EAAE,UAAU,EAAE;AAC3C,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,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;AAC1B;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,SAAS,SAAS,CAAC,YAAY,EAAE,UAAU,EAAE;AAC7C,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,CAAC;AACD,OAAO,CAAC,SAAS,GAAG,SAAS;;"}
1
+ {"version":3,"file":"ModelRelationshipField.js","sources":["../../src/ModelRelationshipField.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ModelRelationshipTypes = exports.__auth = void 0;\nexports.hasOne = hasOne;\nexports.hasMany = hasMany;\nexports.belongsTo = belongsTo;\nconst Authorization_1 = require(\"./Authorization\");\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexports.__auth = Symbol('__auth');\nconst brandName = 'modelRelationshipField';\n/**\n * Model relationship types\n */\nvar ModelRelationshipTypes;\n(function (ModelRelationshipTypes) {\n ModelRelationshipTypes[\"hasOne\"] = \"hasOne\";\n ModelRelationshipTypes[\"hasMany\"] = \"hasMany\";\n ModelRelationshipTypes[\"belongsTo\"] = \"belongsTo\";\n})(ModelRelationshipTypes || (exports.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(Authorization_1.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 */\nfunction 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 */\nfunction 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 */\nfunction belongsTo(relatedModel, references) {\n return _modelRelationshipField(ModelRelationshipTypes.belongsTo, relatedModel, Array.isArray(references) ? references : [references]);\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,sBAAsB,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM;AACxD,OAAO,CAAC,MAAM,GAAG,MAAM;AACvB,OAAO,CAAC,OAAO,GAAG,OAAO;AACzB,OAAO,CAAC,SAAS,GAAG,SAAS;AAC7B,MAAM,eAAe,GAAG,OAAO,C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A;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,SAAS,SAAS,CAAC,YAAY,EAAE,UAAU,EAAE;AAC7C,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,7 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.isCustomPathData = exports.configure = exports.schema = exports.isModelSchema = exports.ddbSchemaBrandName = exports.rdsSchemaBrand = exports.rdsSchemaBrandName = void 0;
4
+ exports.schema = exports.isModelSchema = exports.ddbSchemaBrandName = exports.rdsSchemaBrand = exports.rdsSchemaBrandName = void 0;
5
+ exports.configure = configure;
6
+ exports.isCustomPathData = isCustomPathData;
5
7
  const ModelType_1 = require("./ModelType");
6
8
  const SchemaProcessor_1 = require("./SchemaProcessor");
7
9
  const Authorization_1 = require("./Authorization");
@@ -182,12 +184,10 @@ function configure(config) {
182
184
  schema: bindConfigToSchema(config),
183
185
  };
184
186
  }
185
- exports.configure = configure;
186
187
  function isCustomPathData(obj) {
187
188
  return ('stack' in obj &&
188
189
  (typeof obj.stack === 'undefined' || typeof obj.stack === 'string') &&
189
190
  'entry' in obj &&
190
191
  typeof obj.entry === 'string');
191
192
  }
192
- exports.isCustomPathData = isCustomPathData;
193
193
  //# sourceMappingURL=ModelSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModelSchema.js","sources":["../../src/ModelSchema.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isCustomPathData = exports.configure = exports.schema = exports.isModelSchema = exports.ddbSchemaBrandName = exports.rdsSchemaBrand = exports.rdsSchemaBrandName = void 0;\nconst ModelType_1 = require(\"./ModelType\");\nconst SchemaProcessor_1 = require(\"./SchemaProcessor\");\nconst Authorization_1 = require(\"./Authorization\");\nconst util_1 = require(\"./util\");\nexports.rdsSchemaBrandName = 'RDSSchema';\nexports.rdsSchemaBrand = (0, util_1.brand)(exports.rdsSchemaBrandName);\nexports.ddbSchemaBrandName = 'DDBSchema';\nconst ddbSchemaBrand = (0, util_1.brand)(exports.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 ((0, ModelType_1.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 */\nconst isModelSchema = (schema) => {\n return typeof schema === 'object' && schema.data !== undefined;\n};\nexports.isModelSchema = isModelSchema;\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 ((0, util_1.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 (0, SchemaProcessor_1.processSchema)({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(Authorization_1.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 ...exports.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 (0, SchemaProcessor_1.processSchema)({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(Authorization_1.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 */\nexports.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 */\nfunction configure(config) {\n return {\n schema: bindConfigToSchema(config),\n };\n}\nexports.configure = configure;\nfunction 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}\nexports.isCustomPathData = isCustomPathData;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,gBAAgB,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AAClL,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC3C,MAAM,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AACvD,MAAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACnD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,OAAO,CAAC,kBAAkB,GAAG,WAAW,CAAC;AACzC,OAAO,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AK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;AAC1E;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,SAAS,CAAC,MAAM,EAAE;AAC3B,IAAI,OAAO;AACX,QAAQ,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC;AAC1C,KAAK,CAAC;AACN,CAAC;AACD,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;AAC9B,SAAS,gBAAgB,CAAC,GAAG,EAAE;AAC/B,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,CAAC;AACD,OAAO,CAAC,gBAAgB,GAAG,gBAAgB;;"}
1
+ {"version":3,"file":"ModelSchema.js","sources":["../../src/ModelSchema.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.schema = exports.isModelSchema = exports.ddbSchemaBrandName = exports.rdsSchemaBrand = exports.rdsSchemaBrandName = void 0;\nexports.configure = configure;\nexports.isCustomPathData = isCustomPathData;\nconst ModelType_1 = require(\"./ModelType\");\nconst SchemaProcessor_1 = require(\"./SchemaProcessor\");\nconst Authorization_1 = require(\"./Authorization\");\nconst util_1 = require(\"./util\");\nexports.rdsSchemaBrandName = 'RDSSchema';\nexports.rdsSchemaBrand = (0, util_1.brand)(exports.rdsSchemaBrandName);\nexports.ddbSchemaBrandName = 'DDBSchema';\nconst ddbSchemaBrand = (0, util_1.brand)(exports.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 ((0, ModelType_1.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 */\nconst isModelSchema = (schema) => {\n return typeof schema === 'object' && schema.data !== undefined;\n};\nexports.isModelSchema = isModelSchema;\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 ((0, util_1.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 (0, SchemaProcessor_1.processSchema)({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(Authorization_1.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 ...exports.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 (0, SchemaProcessor_1.processSchema)({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(Authorization_1.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 */\nexports.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 */\nfunction configure(config) {\n return {\n schema: bindConfigToSchema(config),\n };\n}\nfunction 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":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,kBAAkB,GAAG,MAAM;AAClI,OAAO,CAAC,SAAS,GAAG,SAAS;AAC7B,OAAO,CAAC,gBAAgB,GAAG,gBAAgB;AAC3C,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;AAC1C,MAAM,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;AACtD,MAAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC;AAClD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;AAChC,OAAO,CAAC,kBAAkB,GAAG,WAAW;AACxC,OAAO,CAAC,cAAc,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,kBAAkB,CAAC;AACtE,OAAO,CAAC,kBAAkB,GAAG,WAAW;AACxC,MAAM,cAAc,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,kBAAkB,CAAC;AACpE;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,CAAC,CAAC,OAAO,CAAC,CAAC,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AAI;AACtD,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,MAAM,EAAE,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC;AAClD,QAAQ,GAAG,cAAc;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;AACA,OAAO,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC;AACzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,SAAS,CAAC,MAAM,EAAE;AAC3B,IAAI,OAAO;AACX,QAAQ,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC;AAC1C,KAAK;AACL;AACA,SAAS,gBAAgB,CAAC,GAAG,EAAE;AAC/B,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;;"}
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.model = exports.isSchemaModelType = void 0;
4
+ exports.isSchemaModelType = void 0;
5
+ exports.model = model;
5
6
  const util_1 = require("./util");
6
7
  const Authorization_1 = require("./Authorization");
7
8
  const ModelIndex_1 = require("./ModelIndex");
@@ -70,5 +71,4 @@ exports.isSchemaModelType = isSchemaModelType;
70
71
  function model(fields) {
71
72
  return _model(fields);
72
73
  }
73
- exports.model = model;
74
74
  //# sourceMappingURL=ModelType.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModelType.js","sources":["../../src/ModelType.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.model = exports.isSchemaModelType = void 0;\nconst util_1 = require(\"./util\");\nconst Authorization_1 = require(\"./Authorization\");\nconst ModelIndex_1 = require(\"./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_1.modelIndex);\n return this;\n },\n disableOperations(ops) {\n data.disabledOperations = ops;\n return this;\n },\n authorization(callback) {\n const { resource: _, ...rest } = Authorization_1.allow;\n const rules = callback(rest);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n ...(0, util_1.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 */\nconst 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};\nexports.isSchemaModelType = isSchemaModelType;\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 */\nfunction model(fields) {\n return _model(fields);\n}\nexports.model = model;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAA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K;;"}
1
+ {"version":3,"file":"ModelType.js","sources":["../../src/ModelType.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isSchemaModelType = void 0;\nexports.model = model;\nconst util_1 = require(\"./util\");\nconst Authorization_1 = require(\"./Authorization\");\nconst ModelIndex_1 = require(\"./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_1.modelIndex);\n return this;\n },\n disableOperations(ops) {\n data.disabledOperations = ops;\n return this;\n },\n authorization(callback) {\n const { resource: _, ...rest } = Authorization_1.allow;\n const rules = callback(rest);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n ...(0, util_1.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 */\nconst 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};\nexports.isSchemaModelType = isSchemaModelType;\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 */\nfunction model(fields) {\n return _model(fields);\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,iBAAiB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AG,IAAI,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC;AACvC,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;AACA,MAAM,iBAAiB,GAAG,CAAC,SAAS,KAAK;AACzC,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,CAAC;AACD,OAAO,CAAC,iBAAiB,GAAG,iBAAiB;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,KAAK,CAAC,MAAM,EAAE;AACvB,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC;AACzB;;"}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ref = void 0;
4
+ exports.ref = ref;
5
5
  const Authorization_1 = require("./Authorization");
6
6
  require("./ModelField");
7
7
  function brandedBuilder(builder) {
@@ -46,5 +46,4 @@ function _ref(link) {
46
46
  function ref(link) {
47
47
  return _ref(link);
48
48
  }
49
- exports.ref = ref;
50
49
  //# sourceMappingURL=RefType.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RefType.js","sources":["../../src/RefType.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ref = void 0;\nconst Authorization_1 = require(\"./Authorization\");\nconst ModelField_1 = require(\"./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(Authorization_1.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}\nfunction ref(link) {\n return _ref(link);\n}\nexports.ref = ref;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;AACrB,MAAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC9B,OAAO,CAAC,cAAc,EAAE;AAE7C,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,eAAe,CAAC,KAAK,CAAC,CAAC;AAC1D,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;AACD,SAAS,GAAG,CAAC,IAAI,EAAE;AACnB,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AACD,OAAO,CAAC,GAAG,GAAG,GAAG;;"}
1
+ {"version":3,"file":"RefType.js","sources":["../../src/RefType.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ref = ref;\nconst Authorization_1 = require(\"./Authorization\");\nconst ModelField_1 = require(\"./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(Authorization_1.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}\nfunction ref(link) {\n return _ref(link);\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,GAAG,GAAG,GAAG;AACjB,MAAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC;AAC7B,OAAO,CAAC,cAAc;AAE3C,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,eAAe,CAAC,KAAK,CAAC;AACzD,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;AACA,SAAS,GAAG,CAAC,IAAI,EAAE;AACnB,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC;AACrB;;"}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.processSchema = void 0;
4
+ exports.processSchema = processSchema;
5
5
  const tslib_1 = require("tslib");
6
6
  const ModelField_1 = require("./ModelField");
7
7
  const ModelRelationshipField_1 = require("./ModelRelationshipField");
@@ -75,7 +75,7 @@ function canGenerateFieldType(fieldType) {
75
75
  return fieldType === 'Int';
76
76
  }
77
77
  function scalarFieldToGql(fieldDef, identifier, secondaryIndexes = []) {
78
- const { fieldType, required, array, arrayRequired, default: _default, } = fieldDef;
78
+ const { fieldType, required, array, arrayRequired, default: _default, validation = [], } = fieldDef;
79
79
  let field = fieldType;
80
80
  if (identifier !== undefined) {
81
81
  field += '!';
@@ -114,6 +114,16 @@ function scalarFieldToGql(fieldDef, identifier, secondaryIndexes = []) {
114
114
  for (const index of secondaryIndexes) {
115
115
  field += ` ${index}`;
116
116
  }
117
+ // Add validation directives for each validation rule
118
+ for (const validationRule of validation) {
119
+ const valueStr = typeof validationRule.value === 'number' ? validationRule.value.toString() : validationRule.value;
120
+ if (validationRule.errorMessage) {
121
+ field += ` @validate(type: ${validationRule.type}, value: "${valueStr}", errorMessage: ${escapeGraphQlString(validationRule.errorMessage)})`;
122
+ }
123
+ else {
124
+ field += ` @validate(type: ${validationRule.type}, value: "${valueStr}")`;
125
+ }
126
+ }
117
127
  return field;
118
128
  }
119
129
  function modelFieldToGql(fieldDef) {
@@ -1708,5 +1718,4 @@ function processSchema(arg) {
1708
1718
  customSqlDataSourceStrategies,
1709
1719
  };
1710
1720
  }
1711
- exports.processSchema = processSchema;
1712
1721
  //# sourceMappingURL=SchemaProcessor.js.map