@aws-amplify/data-schema 1.10.2 → 1.12.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.
- package/dist/cjs/SchemaProcessor.js +40 -5
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/createUpdateConversationFunction.js +21 -0
- package/dist/cjs/runtime/internals/ai/createUpdateConversationFunction.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js +1 -0
- package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js +2 -0
- package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js.map +1 -1
- package/dist/esm/ModelType.d.ts +3 -3
- package/dist/esm/SchemaProcessor.mjs +40 -5
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/ai/ConversationType.d.ts +16 -1
- package/dist/esm/runtime/internals/ai/createUpdateConversationFunction.d.ts +3 -0
- package/dist/esm/runtime/internals/ai/createUpdateConversationFunction.mjs +19 -0
- package/dist/esm/runtime/internals/ai/createUpdateConversationFunction.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.d.ts +2 -1
- package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.mjs +1 -0
- package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs +2 -0
- package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs.map +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/ModelType.ts +2 -7
- package/src/SchemaProcessor.ts +55 -1
- package/src/ai/ConversationType.ts +25 -2
- package/src/runtime/internals/ai/createUpdateConversationFunction.ts +58 -0
- package/src/runtime/internals/ai/getCustomUserAgentDetails.ts +1 -0
- package/src/runtime/internals/utils/clientProperties/generateConversationsProperty.ts +9 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createUpdateConversationFunction = void 0;
|
|
7
|
+
const get_1 = require("../operations/get");
|
|
8
|
+
const convertItemToConversation_1 = require("./convertItemToConversation");
|
|
9
|
+
const getCustomUserAgentDetails_1 = require("./getCustomUserAgentDetails");
|
|
10
|
+
const createUpdateConversationFunction = (client, modelIntrospection, conversationRouteName, conversationModel, conversationMessageModel, getInternals) => async ({ id, metadata, name }) => {
|
|
11
|
+
const updateOperation = (0, get_1.getFactory)(client, modelIntrospection, conversationModel, 'UPDATE', getInternals, false, (0, getCustomUserAgentDetails_1.getCustomUserAgentDetails)(getCustomUserAgentDetails_1.AiAction.UpdateConversation));
|
|
12
|
+
const { data, errors } = await updateOperation({ id, metadata, name });
|
|
13
|
+
return {
|
|
14
|
+
data: data
|
|
15
|
+
? (0, convertItemToConversation_1.convertItemToConversation)(client, modelIntrospection, data?.id, data?.createdAt, data?.updatedAt, conversationRouteName, conversationMessageModel, getInternals, data?.metadata, data?.name)
|
|
16
|
+
: data,
|
|
17
|
+
errors,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.createUpdateConversationFunction = createUpdateConversationFunction;
|
|
21
|
+
//# sourceMappingURL=createUpdateConversationFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createUpdateConversationFunction.js","sources":["../../../../../src/runtime/internals/ai/createUpdateConversationFunction.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.createUpdateConversationFunction = void 0;\nconst get_1 = require(\"../operations/get\");\nconst convertItemToConversation_1 = require(\"./convertItemToConversation\");\nconst getCustomUserAgentDetails_1 = require(\"./getCustomUserAgentDetails\");\nconst createUpdateConversationFunction = (client, modelIntrospection, conversationRouteName, conversationModel, conversationMessageModel, getInternals) => async ({ id, metadata, name }) => {\n const updateOperation = (0, get_1.getFactory)(client, modelIntrospection, conversationModel, 'UPDATE', getInternals, false, (0, getCustomUserAgentDetails_1.getCustomUserAgentDetails)(getCustomUserAgentDetails_1.AiAction.UpdateConversation));\n const { data, errors } = await updateOperation({ id, metadata, name });\n return {\n data: data\n ? (0, convertItemToConversation_1.convertItemToConversation)(client, modelIntrospection, data?.id, data?.createdAt, data?.updatedAt, conversationRouteName, conversationMessageModel, getInternals, data?.metadata, data?.name)\n : data,\n errors,\n };\n};\nexports.createUpdateConversationFunction = createUpdateConversationFunction;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,gCAAgC,GAAG,KAAK,CAAC,CAAC;AAClD,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC3C,MAAM,2BAA2B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAC3E,MAAM,2BAA2B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAC3E,MAAM,gCAAgC,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,YAAY,KAAK,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK;AAC7L,IAAI,MAAM,eAAe,GAAG,IAAI,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,2BAA2B,CAAC,yBAAyB,EAAE,2BAA2B,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC;AACrP,IAAI,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,eAAe,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3E,IAAI,OAAO;AACX,QAAQ,IAAI,EAAE,IAAI;AAClB,cAAc,IAAI,2BAA2B,CAAC,yBAAyB,EAAE,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC;AAC3O,cAAc,IAAI;AAClB,QAAQ,MAAM;AACd,KAAK,CAAC;AACN,CAAC,CAAC;AACF,OAAO,CAAC,gCAAgC,GAAG,gCAAgC;;"}
|
|
@@ -23,6 +23,7 @@ var AiAction;
|
|
|
23
23
|
AiAction["ListMessages"] = "6";
|
|
24
24
|
AiAction["OnMessage"] = "7";
|
|
25
25
|
AiAction["Generation"] = "8";
|
|
26
|
+
AiAction["UpdateConversation"] = "9";
|
|
26
27
|
})(AiAction || (exports.AiAction = AiAction = {}));
|
|
27
28
|
const getCustomUserAgentDetails = (action) => ({
|
|
28
29
|
category: 'ai',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCustomUserAgentDetails.js","sources":["../../../../../src/runtime/internals/ai/getCustomUserAgentDetails.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.createUserAgentOverride = exports.getCustomUserAgentDetails = exports.AiAction = exports.INTERNAL_USER_AGENT_OVERRIDE = void 0;\n/**\n * Symbol used for internal user agent overrides.\n *\n * @internal\n * This symbol is intended for internal use within the Amplify library.\n * It may change or be removed in future versions without notice.\n * External usage of this symbol is discouraged and may lead to unexpected behavior.\n */\nexports.INTERNAL_USER_AGENT_OVERRIDE = Symbol('INTERNAL_USER_AGENT_OVERRIDE');\nvar AiAction;\n(function (AiAction) {\n AiAction[\"CreateConversation\"] = \"1\";\n AiAction[\"GetConversation\"] = \"2\";\n AiAction[\"ListConversations\"] = \"3\";\n AiAction[\"DeleteConversation\"] = \"4\";\n AiAction[\"SendMessage\"] = \"5\";\n AiAction[\"ListMessages\"] = \"6\";\n AiAction[\"OnMessage\"] = \"7\";\n AiAction[\"Generation\"] = \"8\";\n})(AiAction || (exports.AiAction = AiAction = {}));\nconst getCustomUserAgentDetails = (action) => ({\n category: 'ai',\n action,\n});\nexports.getCustomUserAgentDetails = getCustomUserAgentDetails;\n/**\n * Creates a user agent override object based on custom details.\n *\n * @internal\n * This function is intended for internal use within the Amplify library.\n * It may change or be removed in future versions without notice.\n *\n * @param customUserAgentDetails - Optional custom user agent details\n * @returns An object with INTERNAL_USER_AGENT_OVERRIDE symbol as key and customUserAgentDetails as value, or undefined if no details provided\n */\nfunction createUserAgentOverride(customUserAgentDetails) {\n return customUserAgentDetails\n ? { [exports.INTERNAL_USER_AGENT_OVERRIDE]: customUserAgentDetails }\n : undefined;\n}\nexports.createUserAgentOverride = createUserAgentOverride;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,uBAAuB,GAAG,OAAO,CAAC,yBAAyB,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,4BAA4B,GAAG,KAAK,CAAC,CAAC;AACvI;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC,4BAA4B,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAC9E,IAAI,QAAQ,CAAC;AACb,CAAC,UAAU,QAAQ,EAAE;AACrB,IAAI,QAAQ,CAAC,oBAAoB,CAAC,GAAG,GAAG,CAAC;AACzC,IAAI,QAAQ,CAAC,iBAAiB,CAAC,GAAG,GAAG,CAAC;AACtC,IAAI,QAAQ,CAAC,mBAAmB,CAAC,GAAG,GAAG,CAAC;AACxC,IAAI,QAAQ,CAAC,oBAAoB,CAAC,GAAG,GAAG,CAAC;AACzC,IAAI,QAAQ,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC;AAClC,IAAI,QAAQ,CAAC,cAAc,CAAC,GAAG,GAAG,CAAC;AACnC,IAAI,QAAQ,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC;AAChC,IAAI,QAAQ,CAAC,YAAY,CAAC,GAAG,GAAG,CAAC;AACjC,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,QAAQ,GAAG,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;AACnD,MAAM,yBAAyB,GAAG,CAAC,MAAM,MAAM;AAC/C,IAAI,QAAQ,EAAE,IAAI;AAClB,IAAI,MAAM;AACV,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,yBAAyB,GAAG,yBAAyB,CAAC;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,uBAAuB,CAAC,sBAAsB,EAAE;AACzD,IAAI,OAAO,sBAAsB;AACjC,UAAU,EAAE,CAAC,OAAO,CAAC,4BAA4B,GAAG,sBAAsB,EAAE;AAC5E,UAAU,SAAS,CAAC;AACpB,CAAC;AACD,OAAO,CAAC,uBAAuB,GAAG,uBAAuB;;"}
|
|
1
|
+
{"version":3,"file":"getCustomUserAgentDetails.js","sources":["../../../../../src/runtime/internals/ai/getCustomUserAgentDetails.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.createUserAgentOverride = exports.getCustomUserAgentDetails = exports.AiAction = exports.INTERNAL_USER_AGENT_OVERRIDE = void 0;\n/**\n * Symbol used for internal user agent overrides.\n *\n * @internal\n * This symbol is intended for internal use within the Amplify library.\n * It may change or be removed in future versions without notice.\n * External usage of this symbol is discouraged and may lead to unexpected behavior.\n */\nexports.INTERNAL_USER_AGENT_OVERRIDE = Symbol('INTERNAL_USER_AGENT_OVERRIDE');\nvar AiAction;\n(function (AiAction) {\n AiAction[\"CreateConversation\"] = \"1\";\n AiAction[\"GetConversation\"] = \"2\";\n AiAction[\"ListConversations\"] = \"3\";\n AiAction[\"DeleteConversation\"] = \"4\";\n AiAction[\"SendMessage\"] = \"5\";\n AiAction[\"ListMessages\"] = \"6\";\n AiAction[\"OnMessage\"] = \"7\";\n AiAction[\"Generation\"] = \"8\";\n AiAction[\"UpdateConversation\"] = \"9\";\n})(AiAction || (exports.AiAction = AiAction = {}));\nconst getCustomUserAgentDetails = (action) => ({\n category: 'ai',\n action,\n});\nexports.getCustomUserAgentDetails = getCustomUserAgentDetails;\n/**\n * Creates a user agent override object based on custom details.\n *\n * @internal\n * This function is intended for internal use within the Amplify library.\n * It may change or be removed in future versions without notice.\n *\n * @param customUserAgentDetails - Optional custom user agent details\n * @returns An object with INTERNAL_USER_AGENT_OVERRIDE symbol as key and customUserAgentDetails as value, or undefined if no details provided\n */\nfunction createUserAgentOverride(customUserAgentDetails) {\n return customUserAgentDetails\n ? { [exports.INTERNAL_USER_AGENT_OVERRIDE]: customUserAgentDetails }\n : undefined;\n}\nexports.createUserAgentOverride = createUserAgentOverride;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,uBAAuB,GAAG,OAAO,CAAC,yBAAyB,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,4BAA4B,GAAG,KAAK,CAAC,CAAC;AACvI;AACA;AACA;AACA;AACA;AACA;AACA;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createGetConversationFunction_1 = require("../../ai/createGetConversationFunction");
|
|
9
9
|
const createListConversationsFunction_1 = require("../../ai/createListConversationsFunction");
|
|
10
10
|
const createDeleteConversationFunction_1 = require("../../ai/createDeleteConversationFunction");
|
|
11
|
+
const createUpdateConversationFunction_1 = require("../../ai/createUpdateConversationFunction");
|
|
11
12
|
function generateConversationsProperty(client, apiGraphQLConfig, getInternals) {
|
|
12
13
|
const modelIntrospection = apiGraphQLConfig?.modelIntrospection;
|
|
13
14
|
// conversations will be absent from model intro schema if no conversation routes
|
|
@@ -38,6 +39,7 @@ function generateConversationsProperty(client, apiGraphQLConfig, getInternals) {
|
|
|
38
39
|
},
|
|
39
40
|
};
|
|
40
41
|
conversations[name] = {
|
|
42
|
+
update: (0, createUpdateConversationFunction_1.createUpdateConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),
|
|
41
43
|
create: (0, createCreateConversationFunction_1.createCreateConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),
|
|
42
44
|
get: (0, createGetConversationFunction_1.createGetConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),
|
|
43
45
|
delete: (0, createDeleteConversationFunction_1.createDeleteConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),
|
package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateConversationsProperty.js","sources":["../../../../../../src/runtime/internals/utils/clientProperties/generateConversationsProperty.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.generateConversationsProperty = void 0;\nconst createCreateConversationFunction_1 = require(\"../../ai/createCreateConversationFunction\");\nconst createGetConversationFunction_1 = require(\"../../ai/createGetConversationFunction\");\nconst createListConversationsFunction_1 = require(\"../../ai/createListConversationsFunction\");\nconst createDeleteConversationFunction_1 = require(\"../../ai/createDeleteConversationFunction\");\nfunction generateConversationsProperty(client, apiGraphQLConfig, getInternals) {\n const modelIntrospection = apiGraphQLConfig?.modelIntrospection;\n // conversations will be absent from model intro schema if no conversation routes\n // are present on the source schema.\n if (!modelIntrospection?.conversations) {\n return {};\n }\n const conversations = {};\n for (const { name, conversation, message, models, nonModels, enums, } of Object.values(modelIntrospection.conversations)) {\n const conversationModel = models[conversation.modelName];\n const conversationMessageModel = models[message.modelName];\n if (!conversationModel || !conversationMessageModel) {\n return {};\n }\n const conversationModelIntrospection = {\n ...modelIntrospection,\n models: {\n ...modelIntrospection.models,\n ...models,\n },\n nonModels: {\n ...modelIntrospection.nonModels,\n ...nonModels,\n },\n enums: {\n ...modelIntrospection.enums,\n ...enums,\n },\n };\n conversations[name] = {\n create: (0, createCreateConversationFunction_1.createCreateConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),\n get: (0, createGetConversationFunction_1.createGetConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),\n delete: (0, createDeleteConversationFunction_1.createDeleteConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),\n list: (0, createListConversationsFunction_1.createListConversationsFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),\n };\n }\n return conversations;\n}\nexports.generateConversationsProperty = generateConversationsProperty;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,6BAA6B,GAAG,KAAK,CAAC,CAAC;AAC/C,MAAM,kCAAkC,GAAG,OAAO,CAAC,2CAA2C,CAAC,CAAC;AAChG,MAAM,+BAA+B,GAAG,OAAO,CAAC,wCAAwC,CAAC,CAAC;AAC1F,MAAM,iCAAiC,GA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AAY,MAAM,EAAE,IAAI,kCAAkC,CAAC,gCAAgC,EAAE,MAAM,EAAE,8BAA8B,EAAE,IAAI,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACrM,YAAY,GAAG,EAAE,IAAI,+BAA+B,CAAC,6BAA6B,EAAE,MAAM,EAAE,8BAA8B,EAAE,IAAI,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,YAAY,CAAC;AAC5L,YAAY,MAAM,EAAE,IAAI,kCAAkC,CAAC,gCAAgC,EAAE,MAAM,EAAE,8BAA8B,EAAE,IAAI,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACrM,YAAY,IAAI,EAAE,IAAI,iCAAiC,CAAC,+BAA+B,EAAE,MAAM,EAAE,8BAA8B,EAAE,IAAI,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACjM,SAAS,CAAC;AACV,KAAK;AACL,IAAI,OAAO,aAAa,CAAC;AACzB,CAAC;AACD,OAAO,CAAC,6BAA6B,GAAG,6BAA6B;;"}
|
|
1
|
+
{"version":3,"file":"generateConversationsProperty.js","sources":["../../../../../../src/runtime/internals/utils/clientProperties/generateConversationsProperty.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.generateConversationsProperty = void 0;\nconst createCreateConversationFunction_1 = require(\"../../ai/createCreateConversationFunction\");\nconst createGetConversationFunction_1 = require(\"../../ai/createGetConversationFunction\");\nconst createListConversationsFunction_1 = require(\"../../ai/createListConversationsFunction\");\nconst createDeleteConversationFunction_1 = require(\"../../ai/createDeleteConversationFunction\");\nconst createUpdateConversationFunction_1 = require(\"../../ai/createUpdateConversationFunction\");\nfunction generateConversationsProperty(client, apiGraphQLConfig, getInternals) {\n const modelIntrospection = apiGraphQLConfig?.modelIntrospection;\n // conversations will be absent from model intro schema if no conversation routes\n // are present on the source schema.\n if (!modelIntrospection?.conversations) {\n return {};\n }\n const conversations = {};\n for (const { name, conversation, message, models, nonModels, enums, } of Object.values(modelIntrospection.conversations)) {\n const conversationModel = models[conversation.modelName];\n const conversationMessageModel = models[message.modelName];\n if (!conversationModel || !conversationMessageModel) {\n return {};\n }\n const conversationModelIntrospection = {\n ...modelIntrospection,\n models: {\n ...modelIntrospection.models,\n ...models,\n },\n nonModels: {\n ...modelIntrospection.nonModels,\n ...nonModels,\n },\n enums: {\n ...modelIntrospection.enums,\n ...enums,\n },\n };\n conversations[name] = {\n update: (0, createUpdateConversationFunction_1.createUpdateConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),\n create: (0, createCreateConversationFunction_1.createCreateConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),\n get: (0, createGetConversationFunction_1.createGetConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),\n delete: (0, createDeleteConversationFunction_1.createDeleteConversationFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),\n list: (0, createListConversationsFunction_1.createListConversationsFunction)(client, conversationModelIntrospection, name, conversationModel, conversationMessageModel, getInternals),\n };\n }\n return conversations;\n}\nexports.generateConversationsProperty = generateConversationsProperty;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,6BAA6B,GAAG,KAAK,CAAC,CAAC;AAC/C,MAAM,kCAAkC,GAAG,OAAO,CAAC,2CAA2C,CAAC,CAAC;AAChG,MAAM,+BAA+B,GAAG,OAAO,CAAC,wCAAwC,CAAC,CAAC;AAC1F,MAAM,iCAAiC,GAAG,OAAO,CAAC,0CAA0C,CAAC,CAAC;AAC9F,MAAM,kCAAkC,GAAG,OAAO,CAAC,2CAA2C,CAAC,CAAC;AAChG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gC,EAAE,MAAM,EAAE,8BAA8B,EAAE,IAAI,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACrM,YAAY,MAAM,EAAE,IAAI,kCAAkC,CAAC,gCAAgC,EAAE,MAAM,EAAE,8BAA8B,EAAE,IAAI,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACrM,YAAY,GAAG,EAAE,IAAI,+BAA+B,CAAC,6BAA6B,EAAE,MAAM,EAAE,8BAA8B,EAAE,IAAI,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,YAAY,CAAC;AAC5L,YAAY,MAAM,EAAE,IAAI,kCAAkC,CAAC,gCAAgC,EAAE,MAAM,EAAE,8BAA8B,EAAE,IAAI,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACrM,YAAY,IAAI,EAAE,IAAI,iCAAiC,CAAC,+BAA+B,EAAE,MAAM,EAAE,8BAA8B,EAAE,IAAI,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACjM,SAAS,CAAC;AACV,KAAK;AACL,IAAI,OAAO,aAAa,CAAC;AACzB,CAAC;AACD,OAAO,CAAC,6BAA6B,GAAG,6BAA6B;;"}
|
package/dist/esm/ModelType.d.ts
CHANGED
|
@@ -51,8 +51,8 @@ export type ModelTypeParamShape = {
|
|
|
51
51
|
* indicator string, and resolve its corresponding type later in
|
|
52
52
|
* packages/data-schema/src/runtime/client/index.ts
|
|
53
53
|
*/
|
|
54
|
-
export type ExtractSecondaryIndexIRFields<T extends ModelTypeParamShape
|
|
55
|
-
[FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends BaseModelField<infer R> ? NonNullable<R> extends string | number ?
|
|
54
|
+
export type ExtractSecondaryIndexIRFields<T extends ModelTypeParamShape> = {
|
|
55
|
+
[FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends BaseModelField<infer R> ? NonNullable<R> extends string | number ? FieldProp : never : T['fields'][FieldProp] extends EnumType | RefType<RefTypeParamShape, any, any> ? FieldProp : never]: T['fields'][FieldProp] extends BaseModelField<infer R> ? R : T['fields'][FieldProp] extends EnumType<infer values> ? values[number] : T['fields'][FieldProp] extends RefType<infer R, any, any> ? `${deferredRefResolvingPrefix}${R['link']}` : never;
|
|
56
56
|
};
|
|
57
57
|
export type AddRelationshipFieldsToModelTypeFields<Model, RelationshipFields extends Record<string, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>> = Model extends ModelType<infer ModelParam extends ModelTypeParamShape, infer HiddenKeys> ? ModelType<SetTypeSubArg<ModelParam, 'fields', ModelParam['fields'] & RelationshipFields>, HiddenKeys> : never;
|
|
58
58
|
export type BaseModelType<T extends ModelTypeParamShape = ModelTypeParamShape> = ModelType<T, UsableModelTypeKey>;
|
|
@@ -65,7 +65,7 @@ export type UsableModelTypeKey = methodKeyOf<ModelType>;
|
|
|
65
65
|
*/
|
|
66
66
|
export type ModelType<T extends ModelTypeParamShape = ModelTypeParamShape, UsedMethod extends UsableModelTypeKey = never> = Omit<{
|
|
67
67
|
[brandSymbol]: typeof brandName;
|
|
68
|
-
identifier<PrimaryIndexFields = ExtractSecondaryIndexIRFields<T
|
|
68
|
+
identifier<PrimaryIndexFields = ExtractSecondaryIndexIRFields<T>, PrimaryIndexPool extends string = keyof PrimaryIndexFields & string, const ID extends ReadonlyArray<PrimaryIndexPool> = readonly [], const PrimaryIndexIR extends PrimaryIndexIrShape = PrimaryIndexFieldsToIR<ID, PrimaryIndexFields>>(identifier: ID): ModelType<SetTypeSubArg<T, 'identifier', PrimaryIndexIR>, UsedMethod | 'identifier'>;
|
|
69
69
|
secondaryIndexes<const SecondaryIndexFields = ExtractSecondaryIndexIRFields<T>, const SecondaryIndexPKPool extends string = keyof SecondaryIndexFields & string, const Indexes extends readonly ModelIndexType<string, string, unknown, readonly [], any>[] = readonly [], const IndexesIR extends readonly any[] = SecondaryIndexToIR<Indexes, SecondaryIndexFields>>(callback: (index: <PK extends SecondaryIndexPKPool>(pk: PK) => ModelIndexType<SecondaryIndexPKPool, PK, ReadonlyArray<Exclude<SecondaryIndexPKPool, PK>>>) => Indexes): ModelType<SetTypeSubArg<T, 'secondaryIndexes', IndexesIR>, UsedMethod | 'secondaryIndexes'>;
|
|
70
70
|
disableOperations<const Ops extends ReadonlyArray<DisableOperationsOptions>>(ops: Ops): ModelType<SetTypeSubArg<T, 'disabledOperations', Ops>, UsedMethod | 'disableOperations'>;
|
|
71
71
|
authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: Omit<AllowModifier, 'resource'>) => AuthRuleType | AuthRuleType[]): ModelType<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, UsedMethod | 'authorization'>;
|
|
@@ -64,6 +64,9 @@ function isScalarField(field) {
|
|
|
64
64
|
function isRefField(field) {
|
|
65
65
|
return isRefFieldDef(field?.data);
|
|
66
66
|
}
|
|
67
|
+
function canGenerateFieldType(fieldType) {
|
|
68
|
+
return fieldType === 'Int';
|
|
69
|
+
}
|
|
67
70
|
function scalarFieldToGql(fieldDef, identifier, secondaryIndexes = []) {
|
|
68
71
|
const { fieldType, required, array, arrayRequired, default: _default, } = fieldDef;
|
|
69
72
|
let field = fieldType;
|
|
@@ -81,6 +84,9 @@ function scalarFieldToGql(fieldDef, identifier, secondaryIndexes = []) {
|
|
|
81
84
|
for (const index of secondaryIndexes) {
|
|
82
85
|
field += ` ${index}`;
|
|
83
86
|
}
|
|
87
|
+
if (_default === __generated) {
|
|
88
|
+
field += ` @default`;
|
|
89
|
+
}
|
|
84
90
|
return field;
|
|
85
91
|
}
|
|
86
92
|
if (required === true) {
|
|
@@ -609,12 +615,40 @@ function processFieldLevelAuthRules(fields, authFields) {
|
|
|
609
615
|
}
|
|
610
616
|
return fieldLevelAuthRules;
|
|
611
617
|
}
|
|
612
|
-
function
|
|
618
|
+
function validateDBGeneration(fields, databaseEngine) {
|
|
619
|
+
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
620
|
+
const _default = fieldDef.data?.default;
|
|
621
|
+
const fieldType = fieldDef.data?.fieldType;
|
|
622
|
+
const isGenerated = _default === __generated;
|
|
623
|
+
if (isGenerated && databaseEngine !== 'postgresql') {
|
|
624
|
+
throw new Error(`Invalid field definition for ${fieldName}. DB-generated fields are only supported with PostgreSQL data sources.`);
|
|
625
|
+
}
|
|
626
|
+
if (isGenerated && !canGenerateFieldType(fieldType)) {
|
|
627
|
+
throw new Error(`Incompatible field type. Field type ${fieldType} in field ${fieldName} cannot be configured as a DB-generated field.`);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
function validateNullableIdentifiers(fields, identifier) {
|
|
632
|
+
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
633
|
+
const fieldType = fieldDef.data?.fieldType;
|
|
634
|
+
const required = fieldDef.data?.required;
|
|
635
|
+
const _default = fieldDef.data?.default;
|
|
636
|
+
const isGenerated = _default === __generated;
|
|
637
|
+
if (identifier !== undefined && identifier.includes(fieldName)) {
|
|
638
|
+
if (!required && fieldType !== 'ID' && !isGenerated) {
|
|
639
|
+
throw new Error(`Invalid identifier definition. Field ${fieldName} cannot be used in the identifier. Identifiers must reference required or DB-generated fields)`);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
function processFields(typeName, fields, impliedFields, fieldLevelAuthRules, identifier, partitionKey, secondaryIndexes = {}, databaseEngine = 'dynamodb') {
|
|
613
645
|
const gqlFields = [];
|
|
614
646
|
// stores nested, field-level type definitions (custom types and enums)
|
|
615
647
|
// the need to be hoisted to top-level schema types and processed accordingly
|
|
616
648
|
const implicitTypes = [];
|
|
617
649
|
validateImpliedFields(fields, impliedFields);
|
|
650
|
+
validateDBGeneration(fields, databaseEngine);
|
|
651
|
+
validateNullableIdentifiers(fields, identifier);
|
|
618
652
|
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
619
653
|
const fieldAuth = fieldLevelAuthRules[fieldName]
|
|
620
654
|
? ` ${fieldLevelAuthRules[fieldName]}`
|
|
@@ -829,7 +863,8 @@ const schemaPreprocessor = (schema) => {
|
|
|
829
863
|
const jsFunctions = [];
|
|
830
864
|
const lambdaFunctions = {};
|
|
831
865
|
const customSqlDataSourceStrategies = [];
|
|
832
|
-
const
|
|
866
|
+
const databaseEngine = schema.data.configuration.database.engine;
|
|
867
|
+
const databaseType = databaseEngine === 'dynamodb'
|
|
833
868
|
? 'dynamodb'
|
|
834
869
|
: 'sql';
|
|
835
870
|
const staticSchema = databaseType === 'sql';
|
|
@@ -872,7 +907,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
872
907
|
}
|
|
873
908
|
const authFields = {};
|
|
874
909
|
const fieldLevelAuthRules = processFieldLevelAuthRules(fieldAuthApplicableFields, authFields);
|
|
875
|
-
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules);
|
|
910
|
+
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, undefined, undefined, undefined, databaseEngine);
|
|
876
911
|
topLevelTypes.push(...implicitTypes);
|
|
877
912
|
const joined = gqlFields.join('\n ');
|
|
878
913
|
const model = `type ${typeName} ${customAuth}\n{\n ${joined}\n}`;
|
|
@@ -929,7 +964,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
929
964
|
const { authString, authFields } = calculateAuth(mostRelevantAuthRules);
|
|
930
965
|
const fieldLevelAuthRules = processFieldLevelAuthRules(fields, authFields);
|
|
931
966
|
validateStaticFields(fields, authFields);
|
|
932
|
-
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey);
|
|
967
|
+
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey, undefined, databaseEngine);
|
|
933
968
|
topLevelTypes.push(...implicitTypes);
|
|
934
969
|
const joined = gqlFields.join('\n ');
|
|
935
970
|
const refersToString = typeDef.data.originalName
|
|
@@ -963,7 +998,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
963
998
|
};
|
|
964
999
|
validateRelationships(typeName, fields, getInternalModel);
|
|
965
1000
|
const fieldLevelAuthRules = processFieldLevelAuthRules(fields, authFields);
|
|
966
|
-
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey, transformedSecondaryIndexes);
|
|
1001
|
+
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey, transformedSecondaryIndexes, databaseEngine);
|
|
967
1002
|
topLevelTypes.push(...implicitTypes);
|
|
968
1003
|
const joined = gqlFields.join('\n ');
|
|
969
1004
|
const modelAttrs = modelAttributesFromDisabledOps(typeDef.data.disabledOperations);
|