@botpress/cli 1.2.0 ā 1.2.2
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/.turbo/turbo-build.log +10 -10
- package/dist/command-implementations/lint-command.js +4 -0
- package/dist/command-implementations/lint-command.js.map +2 -2
- package/dist/linter/integration-linter.js +3 -0
- package/dist/linter/integration-linter.js.map +2 -2
- package/dist/utils/schema-utils.js +1 -1
- package/dist/utils/schema-utils.js.map +2 -2
- package/package.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/cli@1.2.
|
|
2
|
+
> @botpress/cli@1.2.2 build /home/runner/work/botpress/botpress/packages/cli
|
|
3
3
|
> pnpm run bundle && pnpm run template:gen
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @botpress/cli@1.2.
|
|
6
|
+
> @botpress/cli@1.2.2 bundle /home/runner/work/botpress/botpress/packages/cli
|
|
7
7
|
> ts-node -T build.ts
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
> @botpress/cli@1.2.
|
|
10
|
+
> @botpress/cli@1.2.2 template:gen /home/runner/work/botpress/botpress/packages/cli
|
|
11
11
|
> pnpm -r --stream -F @bp-templates/* exec bp gen
|
|
12
12
|
|
|
13
|
-
š¤ Botpress CLI v1.2.
|
|
14
|
-
š¤ Botpress CLI v1.2.
|
|
15
|
-
š¤ Botpress CLI v1.2.
|
|
16
|
-
š¤ Botpress CLI v1.2.
|
|
17
|
-
[2K[1Gā Generating typings for bot...[2K[1Gā Typings available at .botpress
|
|
18
|
-
[2K[1Gā Generating typings for integration empty-integration...[2K[1G
|
|
19
|
-
[2K[1Gā Generating typings for integration
|
|
13
|
+
š¤ Botpress CLI v1.2.2
|
|
14
|
+
š¤ Botpress CLI v1.2.2
|
|
15
|
+
š¤ Botpress CLI v1.2.2
|
|
16
|
+
š¤ Botpress CLI v1.2.2
|
|
17
|
+
[2K[1Gā Generating typings for bot...[2K[1Gā Generating typings for integration hello-world...[2K[1Gā Typings available at .botpress
|
|
18
|
+
[2K[1Gā Generating typings for integration empty-integration...[2K[1Gā Typings available at .botpress
|
|
19
|
+
[2K[1Gā Generating typings for integration webhook-message...[2K[1Gā Typings available at .botpress
|
|
20
20
|
[2K[1Gā Typings available at .botpress
|
|
@@ -52,6 +52,10 @@ class LintCommand extends import_project_command.ProjectCommand {
|
|
|
52
52
|
const linter = new import_integration_linter.IntegrationLinter({ ...parsedIntegrationDefinition, secrets: strippedDefinition.secrets });
|
|
53
53
|
await linter.lint();
|
|
54
54
|
linter.logResults(this.logger);
|
|
55
|
+
if (linter.hasErrors()) {
|
|
56
|
+
throw new errors.BotpressCLIError("Integration definition contains linting errors");
|
|
57
|
+
}
|
|
58
|
+
this.logger.success("Integration definition is valid");
|
|
55
59
|
}
|
|
56
60
|
_stripAutoGeneratedContentFromIntegration(definition) {
|
|
57
61
|
const { actionNames, eventNames } = this._getAutoGeneratedContentOfIntegration(definition);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/lint-command.ts"],
|
|
4
|
-
"sourcesContent": ["import { IntegrationDefinition } from '@botpress/sdk'\nimport { prepareCreateIntegrationBody } from '../api/integration-body'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { IntegrationLinter } from '../linter/integration-linter'\nimport { getImplementationStatements } from '../sdk'\nimport { ProjectCommand } from './project-command'\n\nexport type LintCommandDefinition = typeof commandDefinitions.lint\nexport class LintCommand extends ProjectCommand<LintCommandDefinition> {\n public async run(): Promise<void> {\n const projectDef = await this.readProjectDefinitionFromFS()\n\n switch (projectDef.type) {\n case 'integration':\n return this._runLintForIntegration(projectDef.definition)\n case 'bot':\n throw new errors.BotpressCLIError('Bot linting is not yet implemented')\n case 'interface':\n throw new errors.BotpressCLIError('Interface linting is not yet implemented')\n default:\n throw new errors.BotpressCLIError('Unsupported project type')\n }\n }\n\n private async _runLintForIntegration(definition: IntegrationDefinition): Promise<void> {\n const strippedDefinition = this._stripAutoGeneratedContentFromIntegration(definition)\n const parsedIntegrationDefinition = await prepareCreateIntegrationBody(strippedDefinition)\n const linter = new IntegrationLinter({ ...parsedIntegrationDefinition, secrets: strippedDefinition.secrets })\n\n await linter.lint()\n linter.logResults(this.logger)\n }\n\n private _stripAutoGeneratedContentFromIntegration(definition: IntegrationDefinition) {\n const { actionNames, eventNames } = this._getAutoGeneratedContentOfIntegration(definition)\n\n return {\n ...definition,\n actions: Object.fromEntries(Object.entries(definition.actions ?? {}).filter(([key]) => !actionNames.has(key))),\n events: Object.fromEntries(Object.entries(definition.events ?? {}).filter(([key]) => !eventNames.has(key))),\n } as IntegrationDefinition\n }\n\n private _getAutoGeneratedContentOfIntegration(definition: IntegrationDefinition) {\n const actionNames = new Set<string>()\n const eventNames = new Set<string>()\n\n const interfacesStatements = getImplementationStatements(definition)\n for (const iface of Object.values(interfacesStatements)) {\n for (const actionDefinition of Object.values(iface.actions)) {\n actionNames.add(actionDefinition.name)\n }\n for (const eventDefinition of Object.values(iface.events)) {\n eventNames.add(eventDefinition.name)\n }\n }\n\n return { actionNames, eventNames } as const\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAA6C;AAE7C,aAAwB;AACxB,gCAAkC;AAClC,IAAAA,cAA4C;AAC5C,6BAA+B;AAGxB,MAAM,oBAAoB,sCAAsC;AAAA,EACrE,MAAa,MAAqB;AAChC,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAE1D,YAAQ,WAAW,MAAM;AAAA,MACvB,KAAK;AACH,eAAO,KAAK,uBAAuB,WAAW,UAAU;AAAA,MAC1D,KAAK;AACH,cAAM,IAAI,OAAO,iBAAiB,oCAAoC;AAAA,MACxE,KAAK;AACH,cAAM,IAAI,OAAO,iBAAiB,0CAA0C;AAAA,MAC9E;AACE,cAAM,IAAI,OAAO,iBAAiB,0BAA0B;AAAA,IAChE;AAAA,EACF;AAAA,EAEA,MAAc,uBAAuB,YAAkD;AACrF,UAAM,qBAAqB,KAAK,0CAA0C,UAAU;AACpF,UAAM,8BAA8B,UAAM,sDAA6B,kBAAkB;AACzF,UAAM,SAAS,IAAI,4CAAkB,EAAE,GAAG,6BAA6B,SAAS,mBAAmB,QAAQ,CAAC;AAE5G,UAAM,OAAO,KAAK;AAClB,WAAO,WAAW,KAAK,MAAM;AAAA,
|
|
4
|
+
"sourcesContent": ["import { IntegrationDefinition } from '@botpress/sdk'\nimport { prepareCreateIntegrationBody } from '../api/integration-body'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { IntegrationLinter } from '../linter/integration-linter'\nimport { getImplementationStatements } from '../sdk'\nimport { ProjectCommand } from './project-command'\n\nexport type LintCommandDefinition = typeof commandDefinitions.lint\nexport class LintCommand extends ProjectCommand<LintCommandDefinition> {\n public async run(): Promise<void> {\n const projectDef = await this.readProjectDefinitionFromFS()\n\n switch (projectDef.type) {\n case 'integration':\n return this._runLintForIntegration(projectDef.definition)\n case 'bot':\n throw new errors.BotpressCLIError('Bot linting is not yet implemented')\n case 'interface':\n throw new errors.BotpressCLIError('Interface linting is not yet implemented')\n default:\n throw new errors.BotpressCLIError('Unsupported project type')\n }\n }\n\n private async _runLintForIntegration(definition: IntegrationDefinition): Promise<void> {\n const strippedDefinition = this._stripAutoGeneratedContentFromIntegration(definition)\n const parsedIntegrationDefinition = await prepareCreateIntegrationBody(strippedDefinition)\n const linter = new IntegrationLinter({ ...parsedIntegrationDefinition, secrets: strippedDefinition.secrets })\n\n await linter.lint()\n linter.logResults(this.logger)\n\n if (linter.hasErrors()) {\n throw new errors.BotpressCLIError('Integration definition contains linting errors')\n }\n\n this.logger.success('Integration definition is valid')\n }\n\n private _stripAutoGeneratedContentFromIntegration(definition: IntegrationDefinition) {\n const { actionNames, eventNames } = this._getAutoGeneratedContentOfIntegration(definition)\n\n return {\n ...definition,\n actions: Object.fromEntries(Object.entries(definition.actions ?? {}).filter(([key]) => !actionNames.has(key))),\n events: Object.fromEntries(Object.entries(definition.events ?? {}).filter(([key]) => !eventNames.has(key))),\n } as IntegrationDefinition\n }\n\n private _getAutoGeneratedContentOfIntegration(definition: IntegrationDefinition) {\n const actionNames = new Set<string>()\n const eventNames = new Set<string>()\n\n const interfacesStatements = getImplementationStatements(definition)\n for (const iface of Object.values(interfacesStatements)) {\n for (const actionDefinition of Object.values(iface.actions)) {\n actionNames.add(actionDefinition.name)\n }\n for (const eventDefinition of Object.values(iface.events)) {\n eventNames.add(eventDefinition.name)\n }\n }\n\n return { actionNames, eventNames } as const\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAA6C;AAE7C,aAAwB;AACxB,gCAAkC;AAClC,IAAAA,cAA4C;AAC5C,6BAA+B;AAGxB,MAAM,oBAAoB,sCAAsC;AAAA,EACrE,MAAa,MAAqB;AAChC,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAE1D,YAAQ,WAAW,MAAM;AAAA,MACvB,KAAK;AACH,eAAO,KAAK,uBAAuB,WAAW,UAAU;AAAA,MAC1D,KAAK;AACH,cAAM,IAAI,OAAO,iBAAiB,oCAAoC;AAAA,MACxE,KAAK;AACH,cAAM,IAAI,OAAO,iBAAiB,0CAA0C;AAAA,MAC9E;AACE,cAAM,IAAI,OAAO,iBAAiB,0BAA0B;AAAA,IAChE;AAAA,EACF;AAAA,EAEA,MAAc,uBAAuB,YAAkD;AACrF,UAAM,qBAAqB,KAAK,0CAA0C,UAAU;AACpF,UAAM,8BAA8B,UAAM,sDAA6B,kBAAkB;AACzF,UAAM,SAAS,IAAI,4CAAkB,EAAE,GAAG,6BAA6B,SAAS,mBAAmB,QAAQ,CAAC;AAE5G,UAAM,OAAO,KAAK;AAClB,WAAO,WAAW,KAAK,MAAM;AAE7B,QAAI,OAAO,UAAU,GAAG;AACtB,YAAM,IAAI,OAAO,iBAAiB,gDAAgD;AAAA,IACpF;AAEA,SAAK,OAAO,QAAQ,iCAAiC;AAAA,EACvD;AAAA,EAEQ,0CAA0C,YAAmC;AACnF,UAAM,EAAE,aAAa,WAAW,IAAI,KAAK,sCAAsC,UAAU;AAEzF,WAAO;AAAA,MACL,GAAG;AAAA,MACH,SAAS,OAAO,YAAY,OAAO,QAAQ,WAAW,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,YAAY,IAAI,GAAG,CAAC,CAAC;AAAA,MAC7G,QAAQ,OAAO,YAAY,OAAO,QAAQ,WAAW,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,IAAI,GAAG,CAAC,CAAC;AAAA,IAC5G;AAAA,EACF;AAAA,EAEQ,sCAAsC,YAAmC;AAC/E,UAAM,cAAc,oBAAI,IAAY;AACpC,UAAM,aAAa,oBAAI,IAAY;AAEnC,UAAM,2BAAuB,yCAA4B,UAAU;AACnE,eAAW,SAAS,OAAO,OAAO,oBAAoB,GAAG;AACvD,iBAAW,oBAAoB,OAAO,OAAO,MAAM,OAAO,GAAG;AAC3D,oBAAY,IAAI,iBAAiB,IAAI;AAAA,MACvC;AACA,iBAAW,mBAAmB,OAAO,OAAO,MAAM,MAAM,GAAG;AACzD,mBAAW,IAAI,gBAAgB,IAAI;AAAA,MACrC;AAAA,IACF;AAEA,WAAO,EAAE,aAAa,WAAW;AAAA,EACnC;AACF;",
|
|
6
6
|
"names": ["import_sdk"]
|
|
7
7
|
}
|
|
@@ -46,6 +46,9 @@ class IntegrationLinter {
|
|
|
46
46
|
getSortedResults() {
|
|
47
47
|
return this._getResults().sort((a, b) => a.path > b.path ? 1 : a.path < b.path ? -1 : 0);
|
|
48
48
|
}
|
|
49
|
+
hasErrors() {
|
|
50
|
+
return this._results.some((result) => result.severity === 0);
|
|
51
|
+
}
|
|
49
52
|
_getResults() {
|
|
50
53
|
return this._results.map((result) => ({
|
|
51
54
|
message: result.message,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/linter/integration-linter.ts"],
|
|
4
|
-
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport { Spectral, Document, ISpectralDiagnostic } from '@stoplight/spectral-core'\nimport { Json as JsonParser, JsonParserResult } from '@stoplight/spectral-parsers'\nimport { CreateIntegrationBody } from '../api/integration-body'\nimport { Logger } from '../logger'\nimport { INTEGRATION_RULESET } from './rulesets/integration.ruleset'\n\n// The CreateIntegrationBody type does not contain the descriptions for the secrets\nexport type AggregateIntegrationBody = Omit<CreateIntegrationBody, 'secrets'> &\n Pick<sdk.IntegrationDefinitionProps, 'secrets'>\n\ntype ProblemSeverity = 0 | 1 | 2 | 3\n\nexport class IntegrationLinter {\n private readonly _spectral: Spectral\n private readonly _spectralDocument: Document<unknown, JsonParserResult<unknown>>\n private _results: ISpectralDiagnostic[] = []\n\n public constructor(definition: AggregateIntegrationBody) {\n const json = JSON.stringify(definition).replaceAll('\"$ref\":', '\"_$ref\":')\n this._spectralDocument = new Document(json, JsonParser)\n this._spectral = new Spectral()\n\n this._spectral.setRuleset(INTEGRATION_RULESET)\n }\n\n public async lint(): Promise<void> {\n this._results = await this._spectral.run(this._spectralDocument)\n }\n\n public logResults(logger: Logger) {\n for (const result of this.getSortedResults()) {\n const message = `${result.path}: ${result.message}`\n\n this._logResultMessage(logger, message, result.severity)\n }\n }\n\n public getSortedResults() {\n return this._getResults().sort((a, b) => (a.path > b.path ? 1 : a.path < b.path ? -1 : 0))\n }\n\n private _getResults() {\n return this._results.map((result) => ({\n message: result.message,\n path: this._simplifyPath(result.path),\n severity: result.severity as ProblemSeverity,\n }))\n }\n\n private _simplifyPath(path: (string | number)[]) {\n return path.join('.').replaceAll('.properties.', '.').replaceAll('.x-zui', '')\n }\n\n private _logResultMessage(logger: Logger, message: string, severity: ProblemSeverity) {\n const logLevelMapping = {\n 0: logger.error,\n 1: logger.warn,\n 2: logger.log,\n 3: logger.debug,\n } as const\n\n logLevelMapping[severity].call(logger, message)\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAwD;AACxD,8BAAqD;AAGrD,yBAAoC;AAQ7B,MAAM,kBAAkB;AAAA,EACZ;AAAA,EACA;AAAA,EACT,WAAkC,CAAC;AAAA,EAEpC,YAAY,YAAsC;AACvD,UAAM,OAAO,KAAK,UAAU,UAAU,EAAE,WAAW,WAAW,UAAU;AACxE,SAAK,oBAAoB,IAAI,8BAAS,MAAM,wBAAAA,IAAU;AACtD,SAAK,YAAY,IAAI,8BAAS;AAE9B,SAAK,UAAU,WAAW,sCAAmB;AAAA,EAC/C;AAAA,EAEA,MAAa,OAAsB;AACjC,SAAK,WAAW,MAAM,KAAK,UAAU,IAAI,KAAK,iBAAiB;AAAA,EACjE;AAAA,EAEO,WAAW,QAAgB;AAChC,eAAW,UAAU,KAAK,iBAAiB,GAAG;AAC5C,YAAM,UAAU,GAAG,OAAO,SAAS,OAAO;AAE1C,WAAK,kBAAkB,QAAQ,SAAS,OAAO,QAAQ;AAAA,IACzD;AAAA,EACF;AAAA,EAEO,mBAAmB;AACxB,WAAO,KAAK,YAAY,EAAE,KAAK,CAAC,GAAG,MAAO,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,OAAO,EAAE,OAAO,KAAK,CAAE;AAAA,EAC3F;AAAA,EAEQ,cAAc;AACpB,WAAO,KAAK,SAAS,IAAI,CAAC,YAAY;AAAA,MACpC,SAAS,OAAO;AAAA,MAChB,MAAM,KAAK,cAAc,OAAO,IAAI;AAAA,MACpC,UAAU,OAAO;AAAA,IACnB,EAAE;AAAA,EACJ;AAAA,EAEQ,cAAc,MAA2B;AAC/C,WAAO,KAAK,KAAK,GAAG,EAAE,WAAW,gBAAgB,GAAG,EAAE,WAAW,UAAU,EAAE;AAAA,EAC/E;AAAA,EAEQ,kBAAkB,QAAgB,SAAiB,UAA2B;AACpF,UAAM,kBAAkB;AAAA,MACtB,GAAG,OAAO;AAAA,MACV,GAAG,OAAO;AAAA,MACV,GAAG,OAAO;AAAA,MACV,GAAG,OAAO;AAAA,IACZ;AAEA,oBAAgB,UAAU,KAAK,QAAQ,OAAO;AAAA,EAChD;AACF;",
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport { Spectral, Document, ISpectralDiagnostic } from '@stoplight/spectral-core'\nimport { Json as JsonParser, JsonParserResult } from '@stoplight/spectral-parsers'\nimport { CreateIntegrationBody } from '../api/integration-body'\nimport { Logger } from '../logger'\nimport { INTEGRATION_RULESET } from './rulesets/integration.ruleset'\n\n// The CreateIntegrationBody type does not contain the descriptions for the secrets\nexport type AggregateIntegrationBody = Omit<CreateIntegrationBody, 'secrets'> &\n Pick<sdk.IntegrationDefinitionProps, 'secrets'>\n\ntype ProblemSeverity = 0 | 1 | 2 | 3\n\nexport class IntegrationLinter {\n private readonly _spectral: Spectral\n private readonly _spectralDocument: Document<unknown, JsonParserResult<unknown>>\n private _results: ISpectralDiagnostic[] = []\n\n public constructor(definition: AggregateIntegrationBody) {\n const json = JSON.stringify(definition).replaceAll('\"$ref\":', '\"_$ref\":')\n this._spectralDocument = new Document(json, JsonParser)\n this._spectral = new Spectral()\n\n this._spectral.setRuleset(INTEGRATION_RULESET)\n }\n\n public async lint(): Promise<void> {\n this._results = await this._spectral.run(this._spectralDocument)\n }\n\n public logResults(logger: Logger) {\n for (const result of this.getSortedResults()) {\n const message = `${result.path}: ${result.message}`\n\n this._logResultMessage(logger, message, result.severity)\n }\n }\n\n public getSortedResults() {\n return this._getResults().sort((a, b) => (a.path > b.path ? 1 : a.path < b.path ? -1 : 0))\n }\n\n public hasErrors() {\n return this._results.some((result) => result.severity === 0)\n }\n\n private _getResults() {\n return this._results.map((result) => ({\n message: result.message,\n path: this._simplifyPath(result.path),\n severity: result.severity as ProblemSeverity,\n }))\n }\n\n private _simplifyPath(path: (string | number)[]) {\n return path.join('.').replaceAll('.properties.', '.').replaceAll('.x-zui', '')\n }\n\n private _logResultMessage(logger: Logger, message: string, severity: ProblemSeverity) {\n const logLevelMapping = {\n 0: logger.error,\n 1: logger.warn,\n 2: logger.log,\n 3: logger.debug,\n } as const\n\n logLevelMapping[severity].call(logger, message)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAwD;AACxD,8BAAqD;AAGrD,yBAAoC;AAQ7B,MAAM,kBAAkB;AAAA,EACZ;AAAA,EACA;AAAA,EACT,WAAkC,CAAC;AAAA,EAEpC,YAAY,YAAsC;AACvD,UAAM,OAAO,KAAK,UAAU,UAAU,EAAE,WAAW,WAAW,UAAU;AACxE,SAAK,oBAAoB,IAAI,8BAAS,MAAM,wBAAAA,IAAU;AACtD,SAAK,YAAY,IAAI,8BAAS;AAE9B,SAAK,UAAU,WAAW,sCAAmB;AAAA,EAC/C;AAAA,EAEA,MAAa,OAAsB;AACjC,SAAK,WAAW,MAAM,KAAK,UAAU,IAAI,KAAK,iBAAiB;AAAA,EACjE;AAAA,EAEO,WAAW,QAAgB;AAChC,eAAW,UAAU,KAAK,iBAAiB,GAAG;AAC5C,YAAM,UAAU,GAAG,OAAO,SAAS,OAAO;AAE1C,WAAK,kBAAkB,QAAQ,SAAS,OAAO,QAAQ;AAAA,IACzD;AAAA,EACF;AAAA,EAEO,mBAAmB;AACxB,WAAO,KAAK,YAAY,EAAE,KAAK,CAAC,GAAG,MAAO,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,OAAO,EAAE,OAAO,KAAK,CAAE;AAAA,EAC3F;AAAA,EAEO,YAAY;AACjB,WAAO,KAAK,SAAS,KAAK,CAAC,WAAW,OAAO,aAAa,CAAC;AAAA,EAC7D;AAAA,EAEQ,cAAc;AACpB,WAAO,KAAK,SAAS,IAAI,CAAC,YAAY;AAAA,MACpC,SAAS,OAAO;AAAA,MAChB,MAAM,KAAK,cAAc,OAAO,IAAI;AAAA,MACpC,UAAU,OAAO;AAAA,IACnB,EAAE;AAAA,EACJ;AAAA,EAEQ,cAAc,MAA2B;AAC/C,WAAO,KAAK,KAAK,GAAG,EAAE,WAAW,gBAAgB,GAAG,EAAE,WAAW,UAAU,EAAE;AAAA,EAC/E;AAAA,EAEQ,kBAAkB,QAAgB,SAAiB,UAA2B;AACpF,UAAM,kBAAkB;AAAA,MACtB,GAAG,OAAO;AAAA,MACV,GAAG,OAAO;AAAA,MACV,GAAG,OAAO;AAAA,MACV,GAAG,OAAO;AAAA,IACZ;AAEA,oBAAgB,UAAU,KAAK,QAAQ,OAAO;AAAA,EAChD;AACF;",
|
|
6
6
|
"names": ["JsonParser"]
|
|
7
7
|
}
|
|
@@ -27,7 +27,7 @@ var import_sdk = require("@botpress/sdk");
|
|
|
27
27
|
const isObjectSchema = (schema) => schema.type === "object";
|
|
28
28
|
async function mapZodToJsonSchema(definition) {
|
|
29
29
|
let schema = import_sdk.transforms.zuiToJsonSchema(definition.schema, { target: "jsonSchema7" });
|
|
30
|
-
schema = await (
|
|
30
|
+
schema = await dereferenceSchema(schema);
|
|
31
31
|
if (!isObjectSchema(schema) || !definition.ui) {
|
|
32
32
|
return schema;
|
|
33
33
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/schema-utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { dereference } from '@apidevtools/json-schema-ref-parser'\nimport { z, transforms } from '@botpress/sdk'\nimport { JSONSchema7 } from 'json-schema'\n\ntype ZuiToJsonSchema = typeof transforms.zuiToJsonSchema\ntype JsonSchema = ReturnType<ZuiToJsonSchema>\ntype ObjectJsonSchema = Extract<JsonSchema, { type: 'object' }>\n\ntype SchemaOptions = {\n title?: string\n examples?: any[]\n}\n\ntype SchemaDefinition = {\n schema: z.ZodObject<any>\n ui?: Record<string, SchemaOptions | undefined>\n}\n\nconst isObjectSchema = (schema: JsonSchema): schema is ObjectJsonSchema => schema.type === 'object'\n\nexport async function mapZodToJsonSchema(\n definition: SchemaDefinition\n): Promise<ReturnType<typeof transforms.zuiToJsonSchema>> {\n let schema = transforms.zuiToJsonSchema(definition.schema, { target: 'jsonSchema7' })\n schema = (await
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAA4B;AAC5B,iBAA8B;AAiB9B,MAAM,iBAAiB,CAAC,WAAmD,OAAO,SAAS;AAE3F,eAAsB,mBACpB,YACwD;AACxD,MAAI,SAAS,sBAAW,gBAAgB,WAAW,QAAQ,EAAE,QAAQ,cAAc,CAAC;AACpF,WAAU,
|
|
4
|
+
"sourcesContent": ["import { dereference } from '@apidevtools/json-schema-ref-parser'\nimport { z, transforms } from '@botpress/sdk'\nimport { JSONSchema7 } from 'json-schema'\n\ntype ZuiToJsonSchema = typeof transforms.zuiToJsonSchema\ntype JsonSchema = ReturnType<ZuiToJsonSchema>\ntype ObjectJsonSchema = Extract<JsonSchema, { type: 'object' }>\n\ntype SchemaOptions = {\n title?: string\n examples?: any[]\n}\n\ntype SchemaDefinition = {\n schema: z.ZodObject<any>\n ui?: Record<string, SchemaOptions | undefined>\n}\n\nconst isObjectSchema = (schema: JsonSchema): schema is ObjectJsonSchema => schema.type === 'object'\n\nexport async function mapZodToJsonSchema(\n definition: SchemaDefinition\n): Promise<ReturnType<typeof transforms.zuiToJsonSchema>> {\n let schema = transforms.zuiToJsonSchema(definition.schema, { target: 'jsonSchema7' })\n schema = (await dereferenceSchema(schema)) as typeof schema\n\n if (!isObjectSchema(schema) || !definition.ui) {\n return schema\n }\n\n for (const [key, value] of Object.entries(definition.ui ?? {})) {\n const property = schema.properties?.[key]\n\n if (!property) {\n continue\n }\n\n if (!!value?.title) {\n ;(property as any).title = value.title\n }\n\n if (!!value?.examples) {\n ;(property as any).examples = value.examples\n }\n }\n\n return schema\n}\n\nexport const dereferenceSchema = async (schema: JSONSchema7): Promise<JSONSchema7> => {\n return dereference(schema, {\n resolve: {\n external: false,\n file: false,\n http: false,\n },\n })\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAA4B;AAC5B,iBAA8B;AAiB9B,MAAM,iBAAiB,CAAC,WAAmD,OAAO,SAAS;AAE3F,eAAsB,mBACpB,YACwD;AACxD,MAAI,SAAS,sBAAW,gBAAgB,WAAW,QAAQ,EAAE,QAAQ,cAAc,CAAC;AACpF,WAAU,MAAM,kBAAkB,MAAM;AAExC,MAAI,CAAC,eAAe,MAAM,KAAK,CAAC,WAAW,IAAI;AAC7C,WAAO;AAAA,EACT;AAEA,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,MAAM,CAAC,CAAC,GAAG;AAC9D,UAAM,WAAW,OAAO,aAAa;AAErC,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,QAAI,CAAC,CAAC,OAAO,OAAO;AAClB;AAAC,MAAC,SAAiB,QAAQ,MAAM;AAAA,IACnC;AAEA,QAAI,CAAC,CAAC,OAAO,UAAU;AACrB;AAAC,MAAC,SAAiB,WAAW,MAAM;AAAA,IACtC;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,oBAAoB,OAAO,WAA8C;AACpF,aAAO,2CAAY,QAAQ;AAAA,IACzB,SAAS;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|