@aws-amplify/data-schema 1.17.5 → 1.19.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 (28) hide show
  1. package/dist/cjs/SchemaProcessor.js +154 -6
  2. package/dist/cjs/SchemaProcessor.js.map +1 -1
  3. package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js +12 -0
  4. package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js.map +1 -1
  5. package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js +12 -0
  6. package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js.map +1 -1
  7. package/dist/esm/ClientSchema/Core/ClientCustomOperations.d.ts +9 -6
  8. package/dist/esm/CustomOperation.d.ts +1 -1
  9. package/dist/esm/SchemaProcessor.mjs +154 -6
  10. package/dist/esm/SchemaProcessor.mjs.map +1 -1
  11. package/dist/esm/ai/types/ConversationMessageContent.d.ts +14 -3
  12. package/dist/esm/ai/types/contentBlocks.d.ts +8 -0
  13. package/dist/esm/runtime/bridge-types.d.ts +3 -1
  14. package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs +12 -0
  15. package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs.map +1 -1
  16. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.d.ts +8 -0
  17. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs +12 -0
  18. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs.map +1 -1
  19. package/dist/meta/cjs.tsbuildinfo +1 -1
  20. package/package.json +1 -1
  21. package/src/ClientSchema/Core/ClientCustomOperations.ts +14 -15
  22. package/src/CustomOperation.ts +1 -1
  23. package/src/SchemaProcessor.ts +212 -12
  24. package/src/ai/types/ConversationMessageContent.ts +20 -1
  25. package/src/ai/types/contentBlocks.ts +19 -0
  26. package/src/runtime/bridge-types.ts +8 -1
  27. package/src/runtime/internals/ai/conversationMessageDeserializers.ts +13 -0
  28. package/src/runtime/internals/ai/conversationMessageSerializers.ts +16 -0
@@ -9,6 +9,9 @@ const deserializeContent = (content) => content.map((block) => {
9
9
  if (block.image) {
10
10
  return deserializeImageBlock(block);
11
11
  }
12
+ if (block.document) {
13
+ return deserializeDocumentBlock(block);
14
+ }
12
15
  if (block.toolUse) {
13
16
  return deserializeToolUseBlock(block);
14
17
  }
@@ -27,6 +30,15 @@ const deserializeImageBlock = ({ image }) => ({
27
30
  },
28
31
  },
29
32
  });
33
+ const deserializeDocumentBlock = ({ document }) => ({
34
+ document: {
35
+ ...document,
36
+ source: {
37
+ ...document.source,
38
+ bytes: (0, util_base64_1.fromBase64)(document.source.bytes),
39
+ },
40
+ },
41
+ });
30
42
  const deserializeJsonBlock = ({ json }) => ({
31
43
  json: JSON.parse(json),
32
44
  });
@@ -1 +1 @@
1
- {"version":3,"file":"conversationMessageDeserializers.js","sources":["../../../../../src/runtime/internals/ai/conversationMessageDeserializers.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.deserializeContent = void 0;\nconst util_base64_1 = require(\"@smithy/util-base64\");\nconst deserializeContent = (content) => content.map((block) => {\n if (block.image) {\n return deserializeImageBlock(block);\n }\n if (block.toolUse) {\n return deserializeToolUseBlock(block);\n }\n if (block.toolResult) {\n return deserializeToolResultBlock(block);\n }\n return removeNullsFromBlock(block);\n});\nexports.deserializeContent = deserializeContent;\nconst deserializeImageBlock = ({ image }) => ({\n image: {\n ...image,\n source: {\n ...image.source,\n bytes: (0, util_base64_1.fromBase64)(image.source.bytes),\n },\n },\n});\nconst deserializeJsonBlock = ({ json }) => ({\n json: JSON.parse(json),\n});\nconst deserializeToolUseBlock = ({ toolUse }) => ({\n toolUse: {\n ...toolUse,\n input: JSON.parse(toolUse.input),\n },\n});\nconst deserializeToolResultBlock = ({ toolResult, }) => ({\n toolResult: {\n toolUseId: toolResult.toolUseId,\n content: toolResult.content.map((toolResultBlock) => {\n if (toolResultBlock.image) {\n return deserializeImageBlock(toolResultBlock);\n }\n if (toolResultBlock.json) {\n return deserializeJsonBlock(toolResultBlock);\n }\n return removeNullsFromBlock(toolResultBlock);\n }),\n },\n});\nconst removeNullsFromBlock = (block) => Object.fromEntries(Object.entries(block).filter(([_, v]) => v !== null));\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACpC,MAAM,aAAa,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AACrD,MAAM,kBAAkB,GAAG,CAAC,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,KAAK;AAC/D,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE;AACrB,QAAQ,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;AAC5C,KAAK;AACL,IAAI,IAAI,KAAK,CAAC,OAAO,EAAE;AACvB,QAAQ,OAAO,uBAAuB,CAAC,KAAK,CAAC,CAAC;AAC9C,KAAK;AACL,IAAI,IAAI,KAAK,CAAC,UAAU,EAAE;AAC1B,QAAQ,OAAO,0BAA0B,CAAC,KAAK,CAAC,CAAC;AACjD,KAAK;AACL,IAAI,OAAO,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;AAChD,MAAM,qBAAqB,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM;AAC9C,IAAI,KAAK,EAAE;AACX,QAAQ,GAAG,KAAK;AAChB,QAAQ,MAAM,EAAE;AAChB,YAAY,GAAG,KAAK,CAAC,MAAM;AAC3B,YAAY,KAAK,EAAE,IAAI,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;AACpE,SAAS;AACT,KAAK;AACL,CAAC,CAAC,CAAC;AACH,MAAM,oBAAoB,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM;AAC5C,IAAI,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;AAC1B,CAAC,CAAC,CAAC;AACH,MAAM,uBAAuB,GAAG,CAAC,EAAE,OAAO,EAAE,MAAM;AAClD,IAAI,OAAO,EAAE;AACb,QAAQ,GAAG,OAAO;AAClB,QAAQ,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;AACxC,KAAK;AACL,CAAC,CAAC,CAAC;AACH,MAAM,0BAA0B,GAAG,CAAC,EAAE,UAAU,GAAG,MAAM;AACzD,IAAI,UAAU,EAAE;AAChB,QAAQ,SAAS,EAAE,UAAU,CAAC,SAAS;AACvC,QAAQ,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,eAAe,KAAK;AAC7D,YAAY,IAAI,eAAe,CAAC,KAAK,EAAE;AACvC,gBAAgB,OAAO,qBAAqB,CAAC,eAAe,CAAC,CAAC;AAC9D,aAAa;AACb,YAAY,IAAI,eAAe,CAAC,IAAI,EAAE;AACtC,gBAAgB,OAAO,oBAAoB,CAAC,eAAe,CAAC,CAAC;AAC7D,aAAa;AACb,YAAY,OAAO,oBAAoB,CAAC,eAAe,CAAC,CAAC;AACzD,SAAS,CAAC;AACV,KAAK;AACL,CAAC,CAAC,CAAC;AACH,MAAM,oBAAoB,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;;"}
1
+ {"version":3,"file":"conversationMessageDeserializers.js","sources":["../../../../../src/runtime/internals/ai/conversationMessageDeserializers.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.deserializeContent = void 0;\nconst util_base64_1 = require(\"@smithy/util-base64\");\nconst deserializeContent = (content) => content.map((block) => {\n if (block.image) {\n return deserializeImageBlock(block);\n }\n if (block.document) {\n return deserializeDocumentBlock(block);\n }\n if (block.toolUse) {\n return deserializeToolUseBlock(block);\n }\n if (block.toolResult) {\n return deserializeToolResultBlock(block);\n }\n return removeNullsFromBlock(block);\n});\nexports.deserializeContent = deserializeContent;\nconst deserializeImageBlock = ({ image }) => ({\n image: {\n ...image,\n source: {\n ...image.source,\n bytes: (0, util_base64_1.fromBase64)(image.source.bytes),\n },\n },\n});\nconst deserializeDocumentBlock = ({ document }) => ({\n document: {\n ...document,\n source: {\n ...document.source,\n bytes: (0, util_base64_1.fromBase64)(document.source.bytes),\n },\n },\n});\nconst deserializeJsonBlock = ({ json }) => ({\n json: JSON.parse(json),\n});\nconst deserializeToolUseBlock = ({ toolUse }) => ({\n toolUse: {\n ...toolUse,\n input: JSON.parse(toolUse.input),\n },\n});\nconst deserializeToolResultBlock = ({ toolResult, }) => ({\n toolResult: {\n toolUseId: toolResult.toolUseId,\n content: toolResult.content.map((toolResultBlock) => {\n if (toolResultBlock.image) {\n return deserializeImageBlock(toolResultBlock);\n }\n if (toolResultBlock.json) {\n return deserializeJsonBlock(toolResultBlock);\n }\n return removeNullsFromBlock(toolResultBlock);\n }),\n },\n});\nconst removeNullsFromBlock = (block) => Object.fromEntries(Object.entries(block).filter(([_, v]) => v !== null));\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACpC,MAAM,aAAa,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC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C,CAAC,CAAC;AACH,MAAM,oBAAoB,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM;AAC5C,IAAI,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;AAC1B,CAAC,CAAC,CAAC;AACH,MAAM,uBAAuB,GAAG,CAAC,EAAE,OAAO,EAAE,MAAM;AAClD,IAAI,OAAO,EAAE;AACb,QAAQ,GAAG,OAAO;AAClB,QAAQ,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;AACxC,KAAK;AACL,CAAC,CAAC,CAAC;AACH,MAAM,0BAA0B,GAAG,CAAC,EAAE,UAAU,GAAG,MAAM;AACzD,IAAI,UAAU,EAAE;AAChB,QAAQ,SAAS,EAAE,UAAU,CAAC,SAAS;AACvC,QAAQ,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,eAAe,KAAK;AAC7D,YAAY,IAAI,eAAe,CAAC,KAAK,EAAE;AACvC,gBAAgB,OAAO,qBAAqB,CAAC,eAAe,CAAC,CAAC;AAC9D,aAAa;AACb,YAAY,IAAI,eAAe,CAAC,IAAI,EAAE;AACtC,gBAAgB,OAAO,oBAAoB,CAAC,eAAe,CAAC,CAAC;AAC7D,aAAa;AACb,YAAY,OAAO,oBAAoB,CAAC,eAAe,CAAC,CAAC;AACzD,SAAS,CAAC;AACV,KAAK;AACL,CAAC,CAAC,CAAC;AACH,MAAM,oBAAoB,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;;"}
@@ -11,6 +11,9 @@ const serializeContent = (content) => content.map((block) => {
11
11
  if (block.image) {
12
12
  return serializeImageBlock(block);
13
13
  }
14
+ if (block.document) {
15
+ return serializeDocumentBlock(block);
16
+ }
14
17
  if (block.toolResult) {
15
18
  return serializeToolResultBlock(block);
16
19
  }
@@ -38,6 +41,15 @@ const serializeImageBlock = ({ image }) => ({
38
41
  },
39
42
  },
40
43
  });
44
+ const serializeDocumentBlock = ({ document, }) => ({
45
+ document: {
46
+ ...document,
47
+ source: {
48
+ ...document.source,
49
+ bytes: (0, util_base64_1.toBase64)(document.source.bytes),
50
+ },
51
+ },
52
+ });
41
53
  const serializeJsonBlock = ({ json }) => ({
42
54
  json: JSON.stringify(json),
43
55
  });
@@ -1 +1 @@
1
- {"version":3,"file":"conversationMessageSerializers.js","sources":["../../../../../src/runtime/internals/ai/conversationMessageSerializers.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.serializeToolConfiguration = exports.serializeContent = exports.serializeAiContext = void 0;\nconst util_base64_1 = require(\"@smithy/util-base64\");\nconst serializeAiContext = (aiContext) => JSON.stringify(aiContext);\nexports.serializeAiContext = serializeAiContext;\nconst serializeContent = (content) => content.map((block) => {\n if (block.image) {\n return serializeImageBlock(block);\n }\n if (block.toolResult) {\n return serializeToolResultBlock(block);\n }\n return block;\n});\nexports.serializeContent = serializeContent;\nconst serializeToolConfiguration = ({ tools }) => ({\n tools: Object.entries(tools).map(([name, tool]) => ({\n toolSpec: {\n name,\n description: tool.description,\n inputSchema: {\n json: JSON.stringify(tool.inputSchema.json),\n },\n },\n })),\n});\nexports.serializeToolConfiguration = serializeToolConfiguration;\nconst serializeImageBlock = ({ image }) => ({\n image: {\n ...image,\n source: {\n ...image.source,\n bytes: (0, util_base64_1.toBase64)(image.source.bytes),\n },\n },\n});\nconst serializeJsonBlock = ({ json }) => ({\n json: JSON.stringify(json),\n});\nconst serializeToolResultBlock = ({ toolResult, }) => ({\n toolResult: {\n ...toolResult,\n content: toolResult.content.map((toolResultBlock) => {\n if (toolResultBlock.image) {\n return serializeImageBlock(toolResultBlock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AC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;AAC3D,aAAa;AACb,SAAS;AACT,KAAK,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,0BAA0B,GAAG,0BAA0B,CAAC;AAChE,MAAM,mBAAmB,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM;AAC5C,IAAI,KAAK,EAAE;AACX,QAAQ,GAAG,KAAK;AAChB,QAAQ,MAAM,EAAE;AAChB,YAAY,GAAG,KAAK,CAAC,MAAM;AAC3B,YAAY,KAAK,EAAE,IAAI,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;AAClE,SAAS;AACT,KAAK;AACL,CAAC,CAAC,CAAC;AACH,MAAM,kBAAkB,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM;AAC1C,IAAI,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;AAC9B,CAAC,CAAC,CAAC;AACH,MAAM,wBAAwB,GAAG,CAAC,EAAE,UAAU,GAAG,MAAM;AACvD,IAAI,UAAU,EAAE;AAChB,QAAQ,GAAG,UAAU;AACrB,QAAQ,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,eAAe,KAAK;AAC7D,YAAY,IAAI,eAAe,CAAC,KAAK,EAAE;AACvC,gBAAgB,OAAO,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAC5D,aAAa;AACb,YAAY,IAAI,eAAe,CAAC,IAAI,EAAE;AACtC,gBAAgB,OAAO,kBAAkB,CAAC,eAAe,CAAC,CAAC;AAC3D,aAAa;AACb,YAAY,OAAO,eAAe,CAAC;AACnC,SAAS,CAAC;AACV,KAAK;AACL,CAAC,CAAC;;"}
1
+ {"version":3,"file":"conversationMessageSerializers.js","sources":["../../../../../src/runtime/internals/ai/conversationMessageSerializers.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.serializeToolConfiguration = exports.serializeContent = exports.serializeAiContext = void 0;\nconst util_base64_1 = require(\"@smithy/util-base64\");\nconst serializeAiContext = (aiContext) => JSON.stringify(aiContext);\nexports.serializeAiContext = serializeAiContext;\nconst serializeContent = (content) => content.map((block) => {\n if (block.image) {\n return serializeImageBlock(block);\n }\n if (block.document) {\n return serializeDocumentBlock(block);\n }\n if (block.toolResult) {\n return serializeToolResultBlock(block);\n }\n return block;\n});\nexports.serializeContent = serializeContent;\nconst serializeToolConfiguration = ({ tools }) => ({\n tools: Object.entries(tools).map(([name, tool]) => ({\n toolSpec: {\n name,\n description: tool.description,\n inputSchema: {\n json: JSON.stringify(tool.inputSchema.json),\n },\n },\n })),\n});\nexports.serializeToolConfiguration = serializeToolConfiguration;\nconst serializeImageBlock = ({ image }) => ({\n image: {\n ...image,\n source: {\n ...image.source,\n bytes: (0, util_base64_1.toBase64)(image.source.bytes),\n },\n },\n});\nconst serializeDocumentBlock = ({ document, }) => ({\n document: {\n ...document,\n source: {\n ...document.source,\n bytes: (0, util_base64_1.toBase64)(document.source.bytes),\n },\n },\n});\nconst serializeJsonBlock = ({ json }) => ({\n json: JSON.stringify(json),\n});\nconst serializeToolResultBlock = ({ toolResult, }) => ({\n toolResult: {\n ...toolResult,\n content: toolResult.content.map((toolResultBlock) => {\n if (toolResultBlock.image) {\n return serializeImageBlock(toolResultBlock);\n }\n if (toolResultBlock.json) {\n return serializeJsonBlock(toolResultBlock);\n }\n return toolResultBlock;\n }),\n },\n});\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACpG,MAAM,aAAa,GAAG,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omType } from '../../CustomType';
7
7
  import type { FieldTypesOfCustomType } from '../../MappedTypes/ResolveSchema';
8
8
  import type { ResolveRef } from '../utilities/ResolveRef';
9
- import type { EnumType } from '../../EnumType';
10
9
  import { ClientSchemaProperty } from './ClientSchemaProperty';
10
+ import type { ResolveFields } from '../utilities';
11
11
  type CustomOperationSubType<Op extends CustomOperationParamShape> = `custom${Op['typeName']}`;
12
12
  /**
13
13
  * Derives the signature and types for a lambda handler for a particular
@@ -27,7 +27,7 @@ export interface ClientCustomOperation<RefBag extends Record<any, any>, Op exten
27
27
  * }
28
28
  * ```
29
29
  */
30
- functionHandler: AppSyncResolverHandler<CustomOpArguments<Op>, Op['handlers'] extends UltimateFunctionHandlerAsyncType ? void : LambdaReturnType<CustomOpReturnType<Op, RefBag>>>;
30
+ functionHandler: AppSyncResolverHandler<CustomOpArguments<Op, RefBag>, Op['handlers'] extends UltimateFunctionHandlerAsyncType ? void : LambdaReturnType<CustomOpReturnType<Op, RefBag>>>;
31
31
  /**
32
32
  * The `context.arguments` type for lambda function implementations.
33
33
  *
@@ -40,7 +40,7 @@ export interface ClientCustomOperation<RefBag extends Record<any, any>, Op exten
40
40
  * }
41
41
  * ```
42
42
  */
43
- args: CustomOpArguments<Op>;
43
+ args: CustomOpArguments<Op, RefBag>;
44
44
  /**
45
45
  * The return type expected by a lambda function handler.
46
46
  *
@@ -61,10 +61,13 @@ export interface ClientCustomOperation<RefBag extends Record<any, any>, Op exten
61
61
  }
62
62
  /**
63
63
  * Digs out custom operation arguments, mapped to the intended graphql types.
64
+ * using the existing ResolveFields utility type. This handles:
65
+ * - Basic scalar fields
66
+ * - Enum types
67
+ * - Custom types (including nested structures)
68
+ * - Reference types
64
69
  */
65
- type CustomOpArguments<Shape extends CustomOperationParamShape> = Shape['arguments'] extends null ? never : ResolveFieldRequirements<{
66
- [FieldName in keyof Shape['arguments']]: Shape['arguments'][FieldName] extends BaseModelField<infer R> ? R : Shape['arguments'][FieldName] extends EnumType<infer Values> ? Values[number] | null : never;
67
- }>;
70
+ type CustomOpArguments<Shape extends CustomOperationParamShape, RefBag extends Record<string, any> = any> = Shape['arguments'] extends null ? never : ResolveFields<RefBag, Shape['arguments']>;
68
71
  /**
69
72
  * Removes `null | undefined` from the return type if the operation is a subscription,
70
73
  * since subs don't fire on empty/non-existent values.
@@ -12,7 +12,7 @@ declare const mutationBrand = "mutationCustomOperation";
12
12
  declare const subscriptionBrand = "subscriptionCustomOperation";
13
13
  declare const generationBrand = "generationCustomOperation";
14
14
  type CustomOperationBrand = typeof queryBrand | typeof mutationBrand | typeof subscriptionBrand | typeof generationBrand;
15
- type CustomArguments = Record<string, BaseModelField | EnumType>;
15
+ type CustomArguments = Record<string, BaseModelField | EnumType | CustomType<any> | RefType<any, any>>;
16
16
  type SubscriptionSource = RefType<any, any>;
17
17
  type InternalSubscriptionSource = InternalRef;
18
18
  type CustomReturnType = RefType<any> | CustomType<any>;
@@ -252,10 +252,15 @@ function customOperationToGql(typeName, typeDef, authorization, isCustom = false
252
252
  refererTypeName: typeName,
253
253
  });
254
254
  }
255
- if (Object.keys(fieldArgs).length > 0) {
256
- const { gqlFields, implicitTypes: implied } = processFields(typeName, fieldArgs, {}, {});
257
- callSignature += `(${gqlFields.join(', ')})`;
258
- implicitTypes.push(...implied);
255
+ const { inputTypes, argDefinitions, collectedEnums } = generateInputTypes(typeName, fieldArgs, getRefType);
256
+ // Handle collected enums
257
+ for (const [enumName, enumDef] of collectedEnums) {
258
+ if (!implicitTypes.some(([name]) => name === enumName)) {
259
+ implicitTypes.push([enumName, enumDef]);
260
+ }
261
+ }
262
+ if (argDefinitions.length > 0) {
263
+ callSignature += `(${argDefinitions.join(', ')})`;
259
264
  }
260
265
  const handler = handlers && handlers[0];
261
266
  const brand = handler && getBrand(handler);
@@ -330,6 +335,7 @@ function customOperationToGql(typeName, typeDef, authorization, isCustom = false
330
335
  customTypeAuthRules,
331
336
  lambdaFunctionDefinition,
332
337
  customSqlDataSourceStrategy,
338
+ inputTypes,
333
339
  };
334
340
  }
335
341
  /**
@@ -853,6 +859,134 @@ const mergeCustomTypeAuthRules = (existing, added) => {
853
859
  existing[typeName] = authRules;
854
860
  }
855
861
  };
862
+ /**
863
+ * Generates input types for custom operations in the schema.
864
+ *
865
+ * Processes operation arguments to create corresponding input types,
866
+ * handling referenced and inline custom types, enums, and nested structures.
867
+ * Manages circular references and prevents duplicate processing.
868
+ *
869
+ **/
870
+ function generateInputTypes(operationName, args, getRefType) {
871
+ const inputTypes = [];
872
+ const argDefinitions = [];
873
+ const collectedEnums = new Map();
874
+ const processedTypes = new Set(); // Track processed types to avoid duplicates
875
+ const processNonScalarFields = (fields, originalTypeName, isParentRef = false, parentChain = []) => {
876
+ const processedFields = {};
877
+ for (const [fieldName, fieldDef] of Object.entries(fields)) {
878
+ if (isRefField(fieldDef)) {
879
+ const refType = getRefType(fieldDef.data.link, originalTypeName);
880
+ if (refType.type === 'CustomType') {
881
+ const nestedInputTypeName = `${fieldDef.data.link}Input`;
882
+ processedFields[fieldName] = {
883
+ data: { type: 'ref', link: nestedInputTypeName },
884
+ };
885
+ // Process the nested type if it hasn't been processed and isn't a circular reference
886
+ if (!parentChain.includes(nestedInputTypeName) &&
887
+ !processedTypes.has(nestedInputTypeName)) {
888
+ processedTypes.add(nestedInputTypeName);
889
+ const nestedFields = processNonScalarFields(refType.def.data.fields, fieldDef.data.link, true, [...parentChain, nestedInputTypeName]);
890
+ inputTypes.push({
891
+ name: nestedInputTypeName,
892
+ fields: nestedFields,
893
+ });
894
+ }
895
+ }
896
+ else if (refType.type === 'Enum') {
897
+ processedFields[fieldName] = {
898
+ data: { type: 'ref', link: fieldDef.data.link },
899
+ };
900
+ }
901
+ else {
902
+ throw new Error(`Unsupported reference type '${refType.type}' for field '${fieldName}'. ` +
903
+ `Only references to CustomType and Enum are supported.`);
904
+ }
905
+ }
906
+ else if (isCustomType(fieldDef)) {
907
+ // Handle inline custom types
908
+ const nestedInputTypeName = `${capitalize(originalTypeName)}${capitalize(fieldName)}Input`;
909
+ processedFields[fieldName] = {
910
+ data: { type: 'ref', link: nestedInputTypeName },
911
+ };
912
+ if (!processedTypes.has(nestedInputTypeName)) {
913
+ processedTypes.add(nestedInputTypeName);
914
+ const nestedFields = processNonScalarFields(fieldDef.data.fields, `${capitalize(originalTypeName)}${capitalize(fieldName)}`, isParentRef, [...parentChain, nestedInputTypeName]);
915
+ inputTypes.push({
916
+ name: nestedInputTypeName,
917
+ fields: nestedFields,
918
+ });
919
+ }
920
+ }
921
+ else if (isEnumType(fieldDef)) {
922
+ // Handle enum types
923
+ const enumName = `${capitalize(originalTypeName)}${capitalize(fieldName)}`;
924
+ if (!collectedEnums.has(enumName) && !isParentRef) {
925
+ collectedEnums.set(enumName, fieldDef);
926
+ }
927
+ processedFields[fieldName] = { data: { type: 'ref', link: enumName } };
928
+ }
929
+ else {
930
+ processedFields[fieldName] = fieldDef;
931
+ }
932
+ }
933
+ return processedFields;
934
+ };
935
+ // Process top-level arguments
936
+ for (const [argName, argDef] of Object.entries(args)) {
937
+ if (isRefField(argDef)) {
938
+ const refType = getRefType(argDef.data.link, operationName);
939
+ if (refType.type === 'CustomType') {
940
+ const inputTypeName = `${argDef.data.link}Input`;
941
+ argDefinitions.push(`${argName}: ${inputTypeName}`);
942
+ // Process the input type if it hasn't been processed yet
943
+ if (!processedTypes.has(inputTypeName)) {
944
+ processedTypes.add(inputTypeName);
945
+ const fields = processNonScalarFields(refType.def.data.fields, argDef.data.link, true, [inputTypeName]);
946
+ inputTypes.push({
947
+ name: inputTypeName,
948
+ fields,
949
+ });
950
+ }
951
+ }
952
+ else if (refType.type === 'Enum') {
953
+ argDefinitions.push(`${argName}: ${argDef.data.link}`);
954
+ }
955
+ else {
956
+ throw new Error(`Unsupported reference type '${refType.type}' for argument '${argName}' in '${operationName}'. ` +
957
+ `Only references to CustomType and Enum are supported.`);
958
+ }
959
+ }
960
+ else if (isEnumType(argDef)) {
961
+ // Handle top-level enum arguments
962
+ const enumName = `${capitalize(operationName)}${capitalize(argName)}`;
963
+ if (!collectedEnums.has(enumName)) {
964
+ collectedEnums.set(enumName, argDef);
965
+ }
966
+ argDefinitions.push(`${argName}: ${enumName}`);
967
+ }
968
+ else if (isCustomType(argDef)) {
969
+ // Handle top-level custom type arguments
970
+ const inputTypeName = `${capitalize(operationName)}${capitalize(argName)}Input`;
971
+ argDefinitions.push(`${argName}: ${inputTypeName}`);
972
+ if (!processedTypes.has(inputTypeName)) {
973
+ processedTypes.add(inputTypeName);
974
+ const fields = processNonScalarFields(argDef.data.fields, `${capitalize(operationName)}${capitalize(argName)}`, false, [inputTypeName]);
975
+ inputTypes.push({
976
+ name: inputTypeName,
977
+ fields,
978
+ });
979
+ }
980
+ }
981
+ else if (isScalarField(argDef)) {
982
+ argDefinitions.push(`${argName}: ${scalarFieldToGql(argDef.data)}`);
983
+ }
984
+ else {
985
+ throw new Error(`Unsupported argument type for ${argName}`);
986
+ }
987
+ }
988
+ return { inputTypes, argDefinitions, collectedEnums };
989
+ }
856
990
  const schemaPreprocessor = (schema) => {
857
991
  const gqlModels = [];
858
992
  const customQueries = [];
@@ -884,6 +1018,7 @@ const schemaPreprocessor = (schema) => {
884
1018
  const topLevelTypes = sortTopLevelTypes(Object.entries(schema.data.types));
885
1019
  const { schemaAuth, functionSchemaAccess } = extractFunctionSchemaAccess(schema.data.authorization);
886
1020
  const getRefType = getRefTypeForSchema(schema);
1021
+ const uniqueInputTypes = new Map();
887
1022
  for (const [typeName, typeDef] of topLevelTypes) {
888
1023
  const mostRelevantAuthRules = typeDef.data?.authorization?.length > 0
889
1024
  ? typeDef.data.authorization
@@ -916,7 +1051,13 @@ const schemaPreprocessor = (schema) => {
916
1051
  else if (isCustomOperation(typeDef)) {
917
1052
  // TODO: add generation route logic.
918
1053
  const { typeName: opType } = typeDef.data;
919
- const { gqlField, implicitTypes, customTypeAuthRules, jsFunctionForField, lambdaFunctionDefinition, customSqlDataSourceStrategy, } = transformCustomOperations(typeDef, typeName, mostRelevantAuthRules, databaseType, getRefType);
1054
+ const { gqlField, implicitTypes, customTypeAuthRules, jsFunctionForField, lambdaFunctionDefinition, customSqlDataSourceStrategy, inputTypes, } = transformCustomOperations(typeDef, typeName, mostRelevantAuthRules, databaseType, getRefType);
1055
+ // Process input types without duplicates
1056
+ for (const { name, fields } of inputTypes) {
1057
+ if (!uniqueInputTypes.has(name)) {
1058
+ uniqueInputTypes.set(name, fields);
1059
+ }
1060
+ }
920
1061
  topLevelTypes.push(...implicitTypes);
921
1062
  mergeCustomTypeAuthRules(customTypeInheritedAuthRules, customTypeAuthRules);
922
1063
  if (customTypeAuthRules) {
@@ -1006,6 +1147,12 @@ const schemaPreprocessor = (schema) => {
1006
1147
  gqlModels.push(model);
1007
1148
  }
1008
1149
  }
1150
+ // Generate input types after processing all custom operations
1151
+ for (const [name, fields] of uniqueInputTypes) {
1152
+ const { gqlFields } = processFields(name, fields, {}, {}, undefined, undefined, undefined, databaseEngine);
1153
+ const inputTypeDefinition = `input ${name} {\n ${gqlFields.join('\n ')}\n}`;
1154
+ gqlModels.push(inputTypeDefinition);
1155
+ }
1009
1156
  const customOperations = {
1010
1157
  queries: customQueries,
1011
1158
  mutations: customMutations,
@@ -1200,7 +1347,7 @@ function transformCustomOperations(typeDef, typeName, authRules, databaseType, g
1200
1347
  opType, typeName);
1201
1348
  }
1202
1349
  const isCustom = Boolean(jsFunctionForField);
1203
- const { gqlField, implicitTypes, customTypeAuthRules, lambdaFunctionDefinition, customSqlDataSourceStrategy, } = customOperationToGql(typeName, typeDef, authRules, isCustom, databaseType, getRefType);
1350
+ const { gqlField, implicitTypes, customTypeAuthRules, lambdaFunctionDefinition, customSqlDataSourceStrategy, inputTypes, } = customOperationToGql(typeName, typeDef, authRules, isCustom, databaseType, getRefType);
1204
1351
  return {
1205
1352
  gqlField,
1206
1353
  implicitTypes,
@@ -1208,6 +1355,7 @@ function transformCustomOperations(typeDef, typeName, authRules, databaseType, g
1208
1355
  jsFunctionForField,
1209
1356
  lambdaFunctionDefinition,
1210
1357
  customSqlDataSourceStrategy,
1358
+ inputTypes,
1211
1359
  };
1212
1360
  }
1213
1361
  function generateCustomOperationTypes({ queries, mutations, subscriptions, }) {