@botpress/cli 3.5.0 ā 3.6.1
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 +23 -13
- package/dist/code-generation/bot-implementation/bot-implementation.js +9 -0
- package/dist/code-generation/bot-implementation/bot-implementation.js.map +2 -2
- package/dist/code-generation/generators.js +7 -3
- package/dist/code-generation/generators.js.map +2 -2
- package/dist/code-generation/plugin-implementation/plugin-implementation.js +9 -0
- package/dist/code-generation/plugin-implementation/plugin-implementation.js.map +2 -2
- package/dist/code-generation/plugin-package/plugin-package-definition/index.js +10 -2
- package/dist/code-generation/plugin-package/plugin-package-definition/index.js.map +2 -2
- package/dist/code-generation/plugin-package/plugin-package-definition/recurring-events-module.js +71 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/recurring-events-module.js.map +7 -0
- package/dist/code-generation/typings.js.map +1 -1
- package/dist/command-implementations/add-command.js +2 -1
- package/dist/command-implementations/add-command.js.map +2 -2
- package/dist/logger/base-logger.js +8 -2
- package/dist/logger/base-logger.js.map +2 -2
- package/dist/logger/index.js +15 -18
- package/dist/logger/index.js.map +2 -2
- package/dist/logger/logger.test.js +96 -0
- package/dist/logger/logger.test.js.map +7 -0
- package/package.json +2 -2
- package/templates/empty-bot/.botpress/implementation/index.ts +9 -0
- package/templates/empty-bot/package.json +1 -1
- package/templates/empty-integration/package.json +1 -1
- package/templates/empty-plugin/.botpress/implementation/index.ts +9 -0
- package/templates/empty-plugin/package.json +1 -1
- package/templates/hello-world/package.json +1 -1
- package/templates/webhook-message/package.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/cli@3.
|
|
2
|
+
> @botpress/cli@3.6.1 build /home/runner/work/botpress/botpress/packages/cli
|
|
3
3
|
> pnpm run bundle && pnpm run template:gen
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @botpress/cli@3.
|
|
6
|
+
> @botpress/cli@3.6.1 bundle /home/runner/work/botpress/botpress/packages/cli
|
|
7
7
|
> ts-node -T build.ts
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
> @botpress/cli@3.
|
|
10
|
+
> @botpress/cli@3.6.1 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 v3.
|
|
14
|
-
š¤ Botpress CLI v3.
|
|
15
|
-
š¤ Botpress CLI v3.
|
|
16
|
-
š¤ Botpress CLI v3.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
š¤ Botpress CLI v3.6.1
|
|
14
|
+
š¤ Botpress CLI v3.6.1
|
|
15
|
+
š¤ Botpress CLI v3.6.1
|
|
16
|
+
š¤ Botpress CLI v3.6.1
|
|
17
|
+
ā Generating typings for bot...
|
|
18
|
+
ā Typings available at .botpress
|
|
19
|
+
|
|
20
|
+
ā Generating typings for integration hello-world...
|
|
21
|
+
ā Generating typings for plugin empty-plugin...
|
|
22
|
+
ā Typings available at .botpress
|
|
23
|
+
|
|
24
|
+
ā Typings available at .botpress
|
|
25
|
+
|
|
26
|
+
ā Generating typings for integration empty-integration...
|
|
27
|
+
ā Typings available at .botpress
|
|
28
|
+
|
|
29
|
+
š¤ Botpress CLI v3.6.1
|
|
30
|
+
ā Generating typings for integration webhook-message...
|
|
31
|
+
ā Typings available at .botpress
|
|
32
|
+
|
|
@@ -95,9 +95,18 @@ class BotImplementationModule extends import_module.Module {
|
|
|
95
95
|
"export type MessageHandlers = Required<{",
|
|
96
96
|
" [K in keyof BotHandlers['messageHandlers']]: NonNullable<BotHandlers['messageHandlers'][K]>[number]",
|
|
97
97
|
"}>",
|
|
98
|
+
"export type WorkflowHandlers = {",
|
|
99
|
+
" [TWorkflowName in keyof Required<BotHandlers['workflowHandlers'][keyof BotHandlers['workflowHandlers']]>]:",
|
|
100
|
+
" Required<BotHandlers['workflowHandlers'][keyof BotHandlers['workflowHandlers']]>[TWorkflowName] extends",
|
|
101
|
+
" ({ handler: infer U })[] ? U : never",
|
|
102
|
+
"}",
|
|
98
103
|
"",
|
|
99
104
|
"export type MessageHandlerProps = Parameters<MessageHandlers['*']>[0]",
|
|
100
105
|
"export type EventHandlerProps = Parameters<EventHandlers['*']>[0]",
|
|
106
|
+
"export type WorkflowHandlerProps = {",
|
|
107
|
+
" [TWorkflowName in keyof WorkflowHandlers]: WorkflowHandlers[TWorkflowName] extends",
|
|
108
|
+
" (..._: infer U) => any ? U[0] : never",
|
|
109
|
+
"}",
|
|
101
110
|
"",
|
|
102
111
|
"export type Client = (MessageHandlerProps | EventHandlerProps)['client']",
|
|
103
112
|
"export type ClientOperation = keyof {",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/code-generation/bot-implementation/bot-implementation.ts"],
|
|
4
|
-
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as consts from '../consts'\nimport { Module } from '../module'\nimport { BotPluginsIndexModule } from './bot-plugins'\nimport { BotTypingsModule } from './bot-typings'\n\nexport class BotImplementationModule extends Module {\n private _typingsModule: BotTypingsModule\n private _pluginsModule: BotPluginsIndexModule\n\n public constructor(bot: sdk.BotDefinition) {\n super({\n exportName: 'Bot',\n path: consts.INDEX_FILE,\n })\n\n this._typingsModule = new BotTypingsModule(bot)\n this._typingsModule.unshift('typings')\n this.pushDep(this._typingsModule)\n\n this._pluginsModule = new BotPluginsIndexModule(bot)\n this._pluginsModule.unshift(consts.fromOutDir.pluginsDir)\n this.pushDep(this._pluginsModule)\n }\n\n public async getContent() {\n const {\n //\n _typingsModule: typingsModule,\n _pluginsModule: pluginsModule,\n } = this\n\n const typingsImport = typingsModule.import(this)\n const pluginsImport = pluginsModule.import(this)\n\n return [\n consts.GENERATED_HEADER,\n 'import * as sdk from \"@botpress/sdk\"',\n `import * as ${typingsModule.name} from \"./${typingsImport}\"`,\n `import * as ${pluginsModule.name} from \"./${pluginsImport}\"`,\n '',\n `export * from \"./${typingsImport}\"`,\n `export * from \"./${pluginsImport}\"`,\n '',\n `type TPlugins = ${pluginsModule.name}.TPlugins`,\n `type TBot = sdk.DefaultBot<${typingsModule.name}.${typingsModule.exportName}>`,\n '',\n 'export type BotProps = {',\n ' actions: sdk.BotProps<TBot, TPlugins>[\"actions\"]',\n '}',\n '',\n 'export class Bot extends sdk.Bot<TBot, TPlugins> {',\n ' public constructor(props: BotProps) {',\n ' super({',\n ' actions: props.actions,',\n ` plugins: ${pluginsModule.name}.${pluginsModule.exportName}`,\n ' })',\n ' }',\n '}',\n '',\n '// extra types',\n '',\n 'type AsyncFunction = (...args: any[]) => Promise<any>',\n '',\n 'export type BotHandlers = sdk.BotHandlers<TBot>',\n '',\n 'export type EventHandlers = Required<{',\n \" [K in keyof BotHandlers['eventHandlers']]: NonNullable<BotHandlers['eventHandlers'][K]>[number]\",\n '}>',\n 'export type MessageHandlers = Required<{',\n \" [K in keyof BotHandlers['messageHandlers']]: NonNullable<BotHandlers['messageHandlers'][K]>[number]\",\n '}>',\n '',\n \"export type MessageHandlerProps = Parameters<MessageHandlers['*']>[0]\",\n \"export type EventHandlerProps = Parameters<EventHandlers['*']>[0]\",\n '',\n \"export type Client = (MessageHandlerProps | EventHandlerProps)['client']\",\n 'export type ClientOperation = keyof {',\n ' [K in keyof Client as Client[K] extends AsyncFunction ? K : never]: null',\n '}',\n 'export type ClientInputs = {',\n ' [K in ClientOperation]: Parameters<Client[K]>[0]',\n '}',\n 'export type ClientOutputs = {',\n ' [K in ClientOperation]: Awaited<ReturnType<Client[K]>>',\n '}',\n ].join('\\n')\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AACxB,oBAAuB;AACvB,yBAAsC;AAC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AA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,EAAE,KAAK,IAAI;AAAA,EACb;AACF;",
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as consts from '../consts'\nimport { Module } from '../module'\nimport { BotPluginsIndexModule } from './bot-plugins'\nimport { BotTypingsModule } from './bot-typings'\n\nexport class BotImplementationModule extends Module {\n private _typingsModule: BotTypingsModule\n private _pluginsModule: BotPluginsIndexModule\n\n public constructor(bot: sdk.BotDefinition) {\n super({\n exportName: 'Bot',\n path: consts.INDEX_FILE,\n })\n\n this._typingsModule = new BotTypingsModule(bot)\n this._typingsModule.unshift('typings')\n this.pushDep(this._typingsModule)\n\n this._pluginsModule = new BotPluginsIndexModule(bot)\n this._pluginsModule.unshift(consts.fromOutDir.pluginsDir)\n this.pushDep(this._pluginsModule)\n }\n\n public async getContent() {\n const {\n //\n _typingsModule: typingsModule,\n _pluginsModule: pluginsModule,\n } = this\n\n const typingsImport = typingsModule.import(this)\n const pluginsImport = pluginsModule.import(this)\n\n return [\n consts.GENERATED_HEADER,\n 'import * as sdk from \"@botpress/sdk\"',\n `import * as ${typingsModule.name} from \"./${typingsImport}\"`,\n `import * as ${pluginsModule.name} from \"./${pluginsImport}\"`,\n '',\n `export * from \"./${typingsImport}\"`,\n `export * from \"./${pluginsImport}\"`,\n '',\n `type TPlugins = ${pluginsModule.name}.TPlugins`,\n `type TBot = sdk.DefaultBot<${typingsModule.name}.${typingsModule.exportName}>`,\n '',\n 'export type BotProps = {',\n ' actions: sdk.BotProps<TBot, TPlugins>[\"actions\"]',\n '}',\n '',\n 'export class Bot extends sdk.Bot<TBot, TPlugins> {',\n ' public constructor(props: BotProps) {',\n ' super({',\n ' actions: props.actions,',\n ` plugins: ${pluginsModule.name}.${pluginsModule.exportName}`,\n ' })',\n ' }',\n '}',\n '',\n '// extra types',\n '',\n 'type AsyncFunction = (...args: any[]) => Promise<any>',\n '',\n 'export type BotHandlers = sdk.BotHandlers<TBot>',\n '',\n 'export type EventHandlers = Required<{',\n \" [K in keyof BotHandlers['eventHandlers']]: NonNullable<BotHandlers['eventHandlers'][K]>[number]\",\n '}>',\n 'export type MessageHandlers = Required<{',\n \" [K in keyof BotHandlers['messageHandlers']]: NonNullable<BotHandlers['messageHandlers'][K]>[number]\",\n '}>',\n 'export type WorkflowHandlers = {',\n \" [TWorkflowName in keyof Required<BotHandlers['workflowHandlers'][keyof BotHandlers['workflowHandlers']]>]:\",\n \" Required<BotHandlers['workflowHandlers'][keyof BotHandlers['workflowHandlers']]>[TWorkflowName] extends\",\n ' ({ handler: infer U })[] ? U : never',\n '}',\n '',\n \"export type MessageHandlerProps = Parameters<MessageHandlers['*']>[0]\",\n \"export type EventHandlerProps = Parameters<EventHandlers['*']>[0]\",\n 'export type WorkflowHandlerProps = {',\n ' [TWorkflowName in keyof WorkflowHandlers]: WorkflowHandlers[TWorkflowName] extends',\n ' (..._: infer U) => any ? U[0] : never',\n '}',\n '',\n \"export type Client = (MessageHandlerProps | EventHandlerProps)['client']\",\n 'export type ClientOperation = keyof {',\n ' [K in keyof Client as Client[K] extends AsyncFunction ? K : never]: null',\n '}',\n 'export type ClientInputs = {',\n ' [K in ClientOperation]: Parameters<Client[K]>[0]',\n '}',\n 'export type ClientOutputs = {',\n ' [K in ClientOperation]: Awaited<ReturnType<Client[K]>>',\n '}',\n ].join('\\n')\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AACxB,oBAAuB;AACvB,yBAAsC;AACtC,yBAAiC;AAE1B,MAAM,gCAAgC,qBAAO;AAAA,EAC1C;AAAA,EACA;AAAA,EAED,YAAY,KAAwB;AACzC,UAAM;AAAA,MACJ,YAAY;AAAA,MACZ,MAAM,OAAO;AAAA,IACf,CAAC;AAED,SAAK,iBAAiB,IAAI,oCAAiB,GAAG;AAC9C,SAAK,eAAe,QAAQ,SAAS;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+29,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var generators_exports = {};
|
|
30
30
|
__export(generators_exports, {
|
|
31
31
|
jsonSchemaToTypescriptZuiSchema: () => jsonSchemaToTypescriptZuiSchema,
|
|
32
|
+
primitiveRecordToRecordString: () => primitiveRecordToRecordString,
|
|
32
33
|
primitiveRecordToTypescriptValues: () => primitiveRecordToTypescriptValues,
|
|
33
34
|
primitiveToTypescriptValue: () => primitiveToTypescriptValue,
|
|
34
35
|
stringifySingleLine: () => stringifySingleLine,
|
|
36
|
+
typescriptValuesToRecordString: () => typescriptValuesToRecordString,
|
|
35
37
|
zuiSchemaToTypeScriptType: () => zuiSchemaToTypeScriptType
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(generators_exports);
|
|
@@ -60,9 +62,7 @@ const jsonSchemaToTypescriptZuiSchema = async (schema, name, extraProps = {}) =>
|
|
|
60
62
|
let code = [
|
|
61
63
|
consts.GENERATED_HEADER,
|
|
62
64
|
'import { z } from "@botpress/sdk"',
|
|
63
|
-
`export const ${name} = {
|
|
64
|
-
...Object.entries(allProps).map(([key, value]) => ` ${key}: ${value},`),
|
|
65
|
-
"}"
|
|
65
|
+
`export const ${name} = ${typescriptValuesToRecordString(allProps)}`
|
|
66
66
|
].join("\n");
|
|
67
67
|
code = await prettier.format(code, { parser: "typescript" });
|
|
68
68
|
return code;
|
|
@@ -79,12 +79,16 @@ function primitiveToTypescriptValue(x) {
|
|
|
79
79
|
function primitiveRecordToTypescriptValues(x) {
|
|
80
80
|
return (0, import_lodash.default)(x).toPairs().filter(([_key, value]) => value !== void 0).map(([key, value]) => [key, primitiveToTypescriptValue(value)]).fromPairs().value();
|
|
81
81
|
}
|
|
82
|
+
const primitiveRecordToRecordString = (record) => typescriptValuesToRecordString(primitiveRecordToTypescriptValues(record));
|
|
83
|
+
const typescriptValuesToRecordString = (record) => ["{", ...Object.entries(record).map(([key, value]) => ` ${key}: ${value},`), "}"].join("\n");
|
|
82
84
|
// Annotate the CommonJS export names for ESM import in node:
|
|
83
85
|
0 && (module.exports = {
|
|
84
86
|
jsonSchemaToTypescriptZuiSchema,
|
|
87
|
+
primitiveRecordToRecordString,
|
|
85
88
|
primitiveRecordToTypescriptValues,
|
|
86
89
|
primitiveToTypescriptValue,
|
|
87
90
|
stringifySingleLine,
|
|
91
|
+
typescriptValuesToRecordString,
|
|
88
92
|
zuiSchemaToTypeScriptType
|
|
89
93
|
});
|
|
90
94
|
//# sourceMappingURL=generators.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/code-generation/generators.ts"],
|
|
4
|
-
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport { JSONSchema7 } from 'json-schema'\nimport _ from 'lodash'\nimport * as prettier from 'prettier'\nimport * as utils from '../utils'\nimport * as consts from './consts'\n\nexport type Primitive = string | number | boolean | null | undefined\n\nexport const zuiSchemaToTypeScriptType = async (zuiSchema: sdk.z.Schema, name: string): Promise<string> => {\n let code = zuiSchema.toTypescript()\n code = `export type ${name} = ${code}`\n code = await prettier.format(code, { parser: 'typescript' })\n return [\n //\n consts.GENERATED_HEADER,\n code,\n ].join('\\n')\n}\n\nexport const jsonSchemaToTypescriptZuiSchema = async (\n schema: JSONSchema7,\n name: string,\n extraProps: Record<string, string> = {}\n): Promise<string> => {\n schema = await utils.schema.dereferenceSchema(schema)\n const zuiSchema = sdk.z.fromJsonSchema(schema)\n\n const allProps = {\n ...extraProps,\n schema: zuiSchema.toTypescriptSchema(),\n }\n\n let code = [\n consts.GENERATED_HEADER,\n 'import { z } from \"@botpress/sdk\"',\n `export const ${name} = {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAAqB;AAErB,oBAAc;AACd,eAA0B;AAC1B,YAAuB;AACvB,aAAwB;AAIjB,MAAM,4BAA4B,OAAO,WAAyB,SAAkC;AACzG,MAAI,OAAO,UAAU,aAAa;AAClC,SAAO,eAAe,UAAU;AAChC,SAAO,MAAM,SAAS,OAAO,MAAM,EAAE,QAAQ,aAAa,CAAC;AAC3D,SAAO;AAAA;AAAA,IAEL,OAAO;AAAA,IACP;AAAA,EACF,EAAE,KAAK,IAAI;AACb;AAEO,MAAM,kCAAkC,OAC7C,QACA,MACA,aAAqC,CAAC,MAClB;AACpB,WAAS,MAAM,MAAM,OAAO,kBAAkB,MAAM;AACpD,QAAM,YAAY,IAAI,EAAE,eAAe,MAAM;AAE7C,QAAM,WAAW;AAAA,IACf,GAAG;AAAA,IACH,QAAQ,UAAU,mBAAmB;AAAA,EACvC;AAEA,MAAI,OAAO;AAAA,IACT,OAAO;AAAA,IACP;AAAA,IACA,gBAAgB
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport { JSONSchema7 } from 'json-schema'\nimport _ from 'lodash'\nimport * as prettier from 'prettier'\nimport * as utils from '../utils'\nimport * as consts from './consts'\n\nexport type Primitive = string | number | boolean | null | undefined\n\nexport const zuiSchemaToTypeScriptType = async (zuiSchema: sdk.z.Schema, name: string): Promise<string> => {\n let code = zuiSchema.toTypescript()\n code = `export type ${name} = ${code}`\n code = await prettier.format(code, { parser: 'typescript' })\n return [\n //\n consts.GENERATED_HEADER,\n code,\n ].join('\\n')\n}\n\nexport const jsonSchemaToTypescriptZuiSchema = async (\n schema: JSONSchema7,\n name: string,\n extraProps: Record<string, string> = {}\n): Promise<string> => {\n schema = await utils.schema.dereferenceSchema(schema)\n const zuiSchema = sdk.z.fromJsonSchema(schema)\n\n const allProps = {\n ...extraProps,\n schema: zuiSchema.toTypescriptSchema(),\n }\n\n let code = [\n consts.GENERATED_HEADER,\n 'import { z } from \"@botpress/sdk\"',\n `export const ${name} = ${typescriptValuesToRecordString(allProps)}`,\n ].join('\\n')\n code = await prettier.format(code, { parser: 'typescript' })\n return code\n}\n\nexport const stringifySingleLine = (x: object): string => {\n return JSON.stringify(x, null, 1).replace(/\\n */g, ' ')\n}\n\nexport function primitiveToTypescriptValue(x: Primitive): string {\n if (typeof x === 'undefined') {\n return 'undefined'\n }\n return JSON.stringify(x)\n}\n\nexport function primitiveRecordToTypescriptValues(x: Record<string, Primitive>): Record<string, string> {\n return _(x)\n .toPairs()\n .filter(([_key, value]) => value !== undefined)\n .map(([key, value]) => [key, primitiveToTypescriptValue(value)])\n .fromPairs()\n .value()\n}\n\nexport const primitiveRecordToRecordString = (record: Record<string, Primitive>): string =>\n typescriptValuesToRecordString(primitiveRecordToTypescriptValues(record))\n\nexport const typescriptValuesToRecordString = (record: Record<string, string>): string =>\n ['{', ...Object.entries(record).map(([key, value]) => ` ${key}: ${value},`), '}'].join('\\n')\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAAqB;AAErB,oBAAc;AACd,eAA0B;AAC1B,YAAuB;AACvB,aAAwB;AAIjB,MAAM,4BAA4B,OAAO,WAAyB,SAAkC;AACzG,MAAI,OAAO,UAAU,aAAa;AAClC,SAAO,eAAe,UAAU;AAChC,SAAO,MAAM,SAAS,OAAO,MAAM,EAAE,QAAQ,aAAa,CAAC;AAC3D,SAAO;AAAA;AAAA,IAEL,OAAO;AAAA,IACP;AAAA,EACF,EAAE,KAAK,IAAI;AACb;AAEO,MAAM,kCAAkC,OAC7C,QACA,MACA,aAAqC,CAAC,MAClB;AACpB,WAAS,MAAM,MAAM,OAAO,kBAAkB,MAAM;AACpD,QAAM,YAAY,IAAI,EAAE,eAAe,MAAM;AAE7C,QAAM,WAAW;AAAA,IACf,GAAG;AAAA,IACH,QAAQ,UAAU,mBAAmB;AAAA,EACvC;AAEA,MAAI,OAAO;AAAA,IACT,OAAO;AAAA,IACP;AAAA,IACA,gBAAgB,UAAU,+BAA+B,QAAQ;AAAA,EACnE,EAAE,KAAK,IAAI;AACX,SAAO,MAAM,SAAS,OAAO,MAAM,EAAE,QAAQ,aAAa,CAAC;AAC3D,SAAO;AACT;AAEO,MAAM,sBAAsB,CAAC,MAAsB;AACxD,SAAO,KAAK,UAAU,GAAG,MAAM,CAAC,EAAE,QAAQ,SAAS,GAAG;AACxD;AAEO,SAAS,2BAA2B,GAAsB;AAC/D,MAAI,OAAO,MAAM,aAAa;AAC5B,WAAO;AAAA,EACT;AACA,SAAO,KAAK,UAAU,CAAC;AACzB;AAEO,SAAS,kCAAkC,GAAsD;AACtG,aAAO,cAAAA,SAAE,CAAC,EACP,QAAQ,EACR,OAAO,CAAC,CAAC,MAAM,KAAK,MAAM,UAAU,MAAS,EAC7C,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,2BAA2B,KAAK,CAAC,CAAC,EAC9D,UAAU,EACV,MAAM;AACX;AAEO,MAAM,gCAAgC,CAAC,WAC5C,+BAA+B,kCAAkC,MAAM,CAAC;AAEnE,MAAM,iCAAiC,CAAC,WAC7C,CAAC,KAAK,GAAG,OAAO,QAAQ,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,KAAK,QAAQ,QAAQ,GAAG,GAAG,EAAE,KAAK,IAAI;",
|
|
6
6
|
"names": ["_"]
|
|
7
7
|
}
|
|
@@ -78,6 +78,11 @@ class PluginImplementationModule extends import_module.Module {
|
|
|
78
78
|
" [K in keyof PluginHandlers['hookHandlers'][H]]: NonNullable<PluginHandlers['hookHandlers'][H][K]>[number]",
|
|
79
79
|
" }>",
|
|
80
80
|
"}>",
|
|
81
|
+
"export type WorkflowHandlers = {",
|
|
82
|
+
" [TWorkflowName in keyof Required<PluginHandlers['workflowHandlers'][keyof PluginHandlers['workflowHandlers']]>]:",
|
|
83
|
+
" Required<PluginHandlers['workflowHandlers'][keyof PluginHandlers['workflowHandlers']]>[TWorkflowName] extends",
|
|
84
|
+
" ({ handler: infer U })[] ? U : never",
|
|
85
|
+
"}",
|
|
81
86
|
"",
|
|
82
87
|
"export type AnyMessageHandler = MessageHandlers['*']",
|
|
83
88
|
"export type AnyEventHandler = EventHandlers['*']",
|
|
@@ -92,6 +97,10 @@ class PluginImplementationModule extends import_module.Module {
|
|
|
92
97
|
"export type HookHandlerProps = {",
|
|
93
98
|
" [H in keyof AnyHookHanders]: Parameters<NonNullable<AnyHookHanders[H]>>[0]",
|
|
94
99
|
"}",
|
|
100
|
+
"export type WorkflowHandlerProps = {",
|
|
101
|
+
" [TWorkflowName in keyof WorkflowHandlers]: WorkflowHandlers[TWorkflowName] extends",
|
|
102
|
+
" (..._: infer U) => any ? U[0] : never",
|
|
103
|
+
"}",
|
|
95
104
|
"",
|
|
96
105
|
"export type Client = (MessageHandlerProps | EventHandlerProps)['client']",
|
|
97
106
|
"export type ClientOperation = keyof {",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/code-generation/plugin-implementation/plugin-implementation.ts"],
|
|
4
|
-
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as consts from '../consts'\nimport { Module } from '../module'\nimport { PluginTypingsModule } from './plugin-typings'\n\nexport class PluginImplementationModule extends Module {\n private _typingsModule: PluginTypingsModule\n\n public constructor(plugin: sdk.PluginDefinition) {\n super({\n exportName: 'Plugin',\n path: consts.INDEX_FILE,\n })\n\n this._typingsModule = new PluginTypingsModule(plugin)\n this._typingsModule.unshift('typings')\n this.pushDep(this._typingsModule)\n }\n\n public async getContent() {\n const typingsImport = this._typingsModule.import(this)\n\n return [\n consts.GENERATED_HEADER,\n 'import * as sdk from \"@botpress/sdk\"',\n `import * as ${this._typingsModule.name} from \"./${typingsImport}\"`,\n `export * from \"./${typingsImport}\"`,\n '',\n `type TPlugin = sdk.DefaultPlugin<${this._typingsModule.name}.${this._typingsModule.exportName}>`,\n '',\n 'export class Plugin extends sdk.Plugin<TPlugin> {}',\n '',\n 'export type PluginProps = sdk.PluginProps<TPlugin>',\n 'export type PluginRuntimeProps = sdk.PluginRuntimeProps<TPlugin>',\n '',\n '// extra types',\n '',\n 'type ValueOf<T> = T[keyof T]',\n 'type AsyncFunction = (...args: any[]) => Promise<any>',\n '',\n 'export type PluginHandlers = sdk.PluginHandlers<TPlugin>',\n '',\n 'export type EventHandlers = Required<{',\n \" [K in keyof PluginHandlers['eventHandlers']]: NonNullable<PluginHandlers['eventHandlers'][K]>[number]\",\n '}>',\n 'export type MessageHandlers = Required<{',\n \" [K in keyof PluginHandlers['messageHandlers']]: NonNullable<PluginHandlers['messageHandlers'][K]>[number]\",\n '}>',\n 'export type HookHandlers = Required<{',\n \" [H in keyof PluginHandlers['hookHandlers']]: Required<{\",\n \" [K in keyof PluginHandlers['hookHandlers'][H]]: NonNullable<PluginHandlers['hookHandlers'][H][K]>[number]\",\n ' }>',\n '}>',\n '',\n \"export type AnyMessageHandler = MessageHandlers['*']\",\n \"export type AnyEventHandler = EventHandlers['*']\",\n \"export type AnyActionHandler = ValueOf<PluginHandlers['actionHandlers']>\",\n 'export type AnyHookHanders = {',\n \" [H in keyof HookHandlers]: NonNullable<HookHandlers[H]['*']>\",\n '}',\n '',\n 'export type MessageHandlerProps = Parameters<AnyMessageHandler>[0]',\n 'export type EventHandlerProps = Parameters<AnyEventHandler>[0]',\n 'export type ActionHandlerProps = Parameters<AnyActionHandler>[0]',\n 'export type HookHandlerProps = {',\n ' [H in keyof AnyHookHanders]: Parameters<NonNullable<AnyHookHanders[H]>>[0]',\n '}',\n '',\n \"export type Client = (MessageHandlerProps | EventHandlerProps)['client']\",\n 'export type ClientOperation = keyof {',\n ' [K in keyof Client as Client[K] extends AsyncFunction ? K : never]: null',\n '}',\n 'export type ClientInputs = {',\n ' [K in ClientOperation]: Parameters<Client[K]>[0]',\n '}',\n 'export type ClientOutputs = {',\n ' [K in ClientOperation]: Awaited<ReturnType<Client[K]>>',\n '}',\n ].join('\\n')\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AACxB,oBAAuB;AACvB,4BAAoC;AAE7B,MAAM,mCAAmC,qBAAO;AAAA,EAC7C;AAAA,EAED,YAAY,QAA8B;AAC/C,UAAM;AAAA,MACJ,YAAY;AAAA,MACZ,MAAM,OAAO;AAAA,IACf,CAAC;AAED,SAAK,iBAAiB,IAAI,0CAAoB,MAAM;AACpD,SAAK,eAAe,QAAQ,SAAS;AACrC,SAAK,QAAQ,KAAK,cAAc;AAAA,EAClC;AAAA,EAEA,MAAa,aAAa;AACxB,UAAM,gBAAgB,KAAK,eAAe,OAAO,IAAI;AAErD,WAAO;AAAA,MACL,OAAO;AAAA,MACP;AAAA,MACA,eAAe,KAAK,eAAe,gBAAgB;AAAA,MACnD,oBAAoB;AAAA,MACpB;AAAA,MACA,oCAAoC,KAAK,eAAe,QAAQ,KAAK,eAAe;AAAA,MACpF;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,EAAE,KAAK,IAAI;AAAA,EACb;AACF;",
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as consts from '../consts'\nimport { Module } from '../module'\nimport { PluginTypingsModule } from './plugin-typings'\n\nexport class PluginImplementationModule extends Module {\n private _typingsModule: PluginTypingsModule\n\n public constructor(plugin: sdk.PluginDefinition) {\n super({\n exportName: 'Plugin',\n path: consts.INDEX_FILE,\n })\n\n this._typingsModule = new PluginTypingsModule(plugin)\n this._typingsModule.unshift('typings')\n this.pushDep(this._typingsModule)\n }\n\n public async getContent() {\n const typingsImport = this._typingsModule.import(this)\n\n return [\n consts.GENERATED_HEADER,\n 'import * as sdk from \"@botpress/sdk\"',\n `import * as ${this._typingsModule.name} from \"./${typingsImport}\"`,\n `export * from \"./${typingsImport}\"`,\n '',\n `type TPlugin = sdk.DefaultPlugin<${this._typingsModule.name}.${this._typingsModule.exportName}>`,\n '',\n 'export class Plugin extends sdk.Plugin<TPlugin> {}',\n '',\n 'export type PluginProps = sdk.PluginProps<TPlugin>',\n 'export type PluginRuntimeProps = sdk.PluginRuntimeProps<TPlugin>',\n '',\n '// extra types',\n '',\n 'type ValueOf<T> = T[keyof T]',\n 'type AsyncFunction = (...args: any[]) => Promise<any>',\n '',\n 'export type PluginHandlers = sdk.PluginHandlers<TPlugin>',\n '',\n 'export type EventHandlers = Required<{',\n \" [K in keyof PluginHandlers['eventHandlers']]: NonNullable<PluginHandlers['eventHandlers'][K]>[number]\",\n '}>',\n 'export type MessageHandlers = Required<{',\n \" [K in keyof PluginHandlers['messageHandlers']]: NonNullable<PluginHandlers['messageHandlers'][K]>[number]\",\n '}>',\n 'export type HookHandlers = Required<{',\n \" [H in keyof PluginHandlers['hookHandlers']]: Required<{\",\n \" [K in keyof PluginHandlers['hookHandlers'][H]]: NonNullable<PluginHandlers['hookHandlers'][H][K]>[number]\",\n ' }>',\n '}>',\n 'export type WorkflowHandlers = {',\n \" [TWorkflowName in keyof Required<PluginHandlers['workflowHandlers'][keyof PluginHandlers['workflowHandlers']]>]:\",\n \" Required<PluginHandlers['workflowHandlers'][keyof PluginHandlers['workflowHandlers']]>[TWorkflowName] extends\",\n ' ({ handler: infer U })[] ? U : never',\n '}',\n '',\n \"export type AnyMessageHandler = MessageHandlers['*']\",\n \"export type AnyEventHandler = EventHandlers['*']\",\n \"export type AnyActionHandler = ValueOf<PluginHandlers['actionHandlers']>\",\n 'export type AnyHookHanders = {',\n \" [H in keyof HookHandlers]: NonNullable<HookHandlers[H]['*']>\",\n '}',\n '',\n 'export type MessageHandlerProps = Parameters<AnyMessageHandler>[0]',\n 'export type EventHandlerProps = Parameters<AnyEventHandler>[0]',\n 'export type ActionHandlerProps = Parameters<AnyActionHandler>[0]',\n 'export type HookHandlerProps = {',\n ' [H in keyof AnyHookHanders]: Parameters<NonNullable<AnyHookHanders[H]>>[0]',\n '}',\n 'export type WorkflowHandlerProps = {',\n ' [TWorkflowName in keyof WorkflowHandlers]: WorkflowHandlers[TWorkflowName] extends',\n ' (..._: infer U) => any ? U[0] : never',\n '}',\n '',\n \"export type Client = (MessageHandlerProps | EventHandlerProps)['client']\",\n 'export type ClientOperation = keyof {',\n ' [K in keyof Client as Client[K] extends AsyncFunction ? K : never]: null',\n '}',\n 'export type ClientInputs = {',\n ' [K in ClientOperation]: Parameters<Client[K]>[0]',\n '}',\n 'export type ClientOutputs = {',\n ' [K in ClientOperation]: Awaited<ReturnType<Client[K]>>',\n '}',\n ].join('\\n')\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AACxB,oBAAuB;AACvB,4BAAoC;AAE7B,MAAM,mCAAmC,qBAAO;AAAA,EAC7C;AAAA,EAED,YAAY,QAA8B;AAC/C,UAAM;AAAA,MACJ,YAAY;AAAA,MACZ,MAAM,OAAO;AAAA,IACf,CAAC;AAED,SAAK,iBAAiB,IAAI,0CAAoB,MAAM;AACpD,SAAK,eAAe,QAAQ,SAAS;AACrC,SAAK,QAAQ,KAAK,cAAc;AAAA,EAClC;AAAA,EAEA,MAAa,aAAa;AACxB,UAAM,gBAAgB,KAAK,eAAe,OAAO,IAAI;AAErD,WAAO;AAAA,MACL,OAAO;AAAA,MACP;AAAA,MACA,eAAe,KAAK,eAAe,gBAAgB;AAAA,MACnD,oBAAoB;AAAA,MACpB;AAAA,MACA,oCAAoC,KAAK,eAAe,QAAQ,KAAK,eAAe;AAAA,MACpF;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,EAAE,KAAK,IAAI;AAAA,EACb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -38,6 +38,7 @@ var import_actions_module = require("./actions-module");
|
|
|
38
38
|
var import_configuration_module = require("./configuration-module");
|
|
39
39
|
var import_events_module = require("./events-module");
|
|
40
40
|
var import_interfaces_module = require("./interfaces-module");
|
|
41
|
+
var import_recurring_events_module = require("./recurring-events-module");
|
|
41
42
|
var import_states_module = require("./states-module");
|
|
42
43
|
class PluginPackageDefinitionModule extends import_module.Module {
|
|
43
44
|
constructor(_plugin) {
|
|
@@ -56,12 +57,15 @@ class PluginPackageDefinitionModule extends import_module.Module {
|
|
|
56
57
|
statesModule.unshift("states");
|
|
57
58
|
const interfacesModule = new import_interfaces_module.InterfacesModule(_plugin.dependencies?.interfaces ?? {});
|
|
58
59
|
interfacesModule.unshift("interfaces");
|
|
60
|
+
const recurringEventsModule = new import_recurring_events_module.RecurringEventsModule(_plugin.recurringEvents ?? {});
|
|
61
|
+
recurringEventsModule.unshift("recurringEvents");
|
|
59
62
|
this._dependencies = {
|
|
60
63
|
defaultConfigModule,
|
|
61
64
|
actionsModule,
|
|
62
65
|
eventsModule,
|
|
63
66
|
statesModule,
|
|
64
|
-
interfacesModule
|
|
67
|
+
interfacesModule,
|
|
68
|
+
recurringEventsModule
|
|
65
69
|
};
|
|
66
70
|
for (const dep of Object.values(this._dependencies)) {
|
|
67
71
|
this.pushDep(dep);
|
|
@@ -70,12 +74,13 @@ class PluginPackageDefinitionModule extends import_module.Module {
|
|
|
70
74
|
_dependencies;
|
|
71
75
|
async getContent() {
|
|
72
76
|
let content = "";
|
|
73
|
-
const { defaultConfigModule, actionsModule, eventsModule, statesModule, interfacesModule } = this._dependencies;
|
|
77
|
+
const { defaultConfigModule, actionsModule, eventsModule, statesModule, interfacesModule, recurringEventsModule } = this._dependencies;
|
|
74
78
|
const defaultConfigImport = defaultConfigModule.import(this);
|
|
75
79
|
const actionsImport = actionsModule.import(this);
|
|
76
80
|
const eventsImport = eventsModule.import(this);
|
|
77
81
|
const statesImport = statesModule.import(this);
|
|
78
82
|
const interfacesImport = interfacesModule.import(this);
|
|
83
|
+
const recurringEventsImport = recurringEventsModule.import(this);
|
|
79
84
|
const user = {
|
|
80
85
|
tags: this._plugin.user?.tags ?? {}
|
|
81
86
|
};
|
|
@@ -91,11 +96,13 @@ class PluginPackageDefinitionModule extends import_module.Module {
|
|
|
91
96
|
`import * as ${eventsModule.name} from "./${eventsImport}"`,
|
|
92
97
|
`import * as ${statesModule.name} from "./${statesImport}"`,
|
|
93
98
|
`import * as ${interfacesModule.name} from "./${interfacesImport}"`,
|
|
99
|
+
`import * as ${recurringEventsModule.name} from "./${recurringEventsImport}"`,
|
|
94
100
|
`export * as ${defaultConfigModule.name} from "./${defaultConfigImport}"`,
|
|
95
101
|
`export * as ${actionsModule.name} from "./${actionsImport}"`,
|
|
96
102
|
`export * as ${eventsModule.name} from "./${eventsImport}"`,
|
|
97
103
|
`export * as ${statesModule.name} from "./${statesImport}"`,
|
|
98
104
|
`export * as ${interfacesModule.name} from "./${interfacesImport}"`,
|
|
105
|
+
`export * as ${recurringEventsModule.name} from "./${recurringEventsImport}"`,
|
|
99
106
|
"",
|
|
100
107
|
"export default {",
|
|
101
108
|
` name: "${this._plugin.name}",`,
|
|
@@ -107,6 +114,7 @@ class PluginPackageDefinitionModule extends import_module.Module {
|
|
|
107
114
|
` events: ${eventsModule.name}.${eventsModule.exportName},`,
|
|
108
115
|
` states: ${statesModule.name}.${statesModule.exportName},`,
|
|
109
116
|
` interfaces: ${interfacesModule.name}.${interfacesModule.exportName},`,
|
|
117
|
+
` recurringEvents: ${recurringEventsModule.name}.${recurringEventsModule.exportName},`,
|
|
110
118
|
'} satisfies sdk.PluginPackage["definition"]'
|
|
111
119
|
].join("\n");
|
|
112
120
|
return content;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/code-generation/plugin-package/plugin-package-definition/index.ts"],
|
|
4
|
-
"sourcesContent": ["import * as consts from '../../consts'\nimport { stringifySingleLine } from '../../generators'\nimport { Module } from '../../module'\nimport { ActionsModule } from './actions-module'\nimport { DefaultConfigurationModule } from './configuration-module'\nimport { EventsModule } from './events-module'\nimport { InterfacesModule } from './interfaces-module'\nimport { StatesModule } from './states-module'\nimport * as types from './typings'\n\ntype PluginPackageModuleDependencies = {\n defaultConfigModule: DefaultConfigurationModule\n actionsModule: ActionsModule\n eventsModule: EventsModule\n statesModule: StatesModule\n interfacesModule: InterfacesModule\n}\n\nexport class PluginPackageDefinitionModule extends Module {\n private _dependencies: PluginPackageModuleDependencies\n\n public constructor(private _plugin: types.PluginDefinition) {\n super({\n path: consts.INDEX_FILE,\n exportName: consts.DEFAULT_EXPORT_NAME,\n })\n\n const defaultConfigModule = new DefaultConfigurationModule(_plugin.configuration ?? {})\n defaultConfigModule.unshift('configuration')\n\n const actionsModule = new ActionsModule(_plugin.actions ?? {})\n actionsModule.unshift('actions')\n\n const eventsModule = new EventsModule(_plugin.events ?? {})\n eventsModule.unshift('events')\n\n const statesModule = new StatesModule(_plugin.states ?? {})\n statesModule.unshift('states')\n\n const interfacesModule = new InterfacesModule(_plugin.dependencies?.interfaces ?? {})\n interfacesModule.unshift('interfaces')\n\n this._dependencies = {\n defaultConfigModule,\n actionsModule,\n eventsModule,\n statesModule,\n interfacesModule,\n }\n\n for (const dep of Object.values(this._dependencies)) {\n this.pushDep(dep)\n }\n }\n\n public async getContent() {\n let content = ''\n\n const { defaultConfigModule, actionsModule, eventsModule, statesModule, interfacesModule }
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AACxB,wBAAoC;AACpC,oBAAuB;AACvB,4BAA8B;AAC9B,kCAA2C;AAC3C,2BAA6B;AAC7B,+BAAiC;AACjC,2BAA6B;
|
|
4
|
+
"sourcesContent": ["import * as consts from '../../consts'\nimport { stringifySingleLine } from '../../generators'\nimport { Module } from '../../module'\nimport { ActionsModule } from './actions-module'\nimport { DefaultConfigurationModule } from './configuration-module'\nimport { EventsModule } from './events-module'\nimport { InterfacesModule } from './interfaces-module'\nimport { RecurringEventsModule } from './recurring-events-module'\nimport { StatesModule } from './states-module'\nimport * as types from './typings'\n\ntype PluginPackageModuleDependencies = {\n defaultConfigModule: DefaultConfigurationModule\n actionsModule: ActionsModule\n eventsModule: EventsModule\n statesModule: StatesModule\n interfacesModule: InterfacesModule\n recurringEventsModule: RecurringEventsModule\n}\n\nexport class PluginPackageDefinitionModule extends Module {\n private _dependencies: PluginPackageModuleDependencies\n\n public constructor(private _plugin: types.PluginDefinition) {\n super({\n path: consts.INDEX_FILE,\n exportName: consts.DEFAULT_EXPORT_NAME,\n })\n\n const defaultConfigModule = new DefaultConfigurationModule(_plugin.configuration ?? {})\n defaultConfigModule.unshift('configuration')\n\n const actionsModule = new ActionsModule(_plugin.actions ?? {})\n actionsModule.unshift('actions')\n\n const eventsModule = new EventsModule(_plugin.events ?? {})\n eventsModule.unshift('events')\n\n const statesModule = new StatesModule(_plugin.states ?? {})\n statesModule.unshift('states')\n\n const interfacesModule = new InterfacesModule(_plugin.dependencies?.interfaces ?? {})\n interfacesModule.unshift('interfaces')\n\n const recurringEventsModule = new RecurringEventsModule(_plugin.recurringEvents ?? {})\n recurringEventsModule.unshift('recurringEvents')\n\n this._dependencies = {\n defaultConfigModule,\n actionsModule,\n eventsModule,\n statesModule,\n interfacesModule,\n recurringEventsModule,\n }\n\n for (const dep of Object.values(this._dependencies)) {\n this.pushDep(dep)\n }\n }\n\n public async getContent() {\n let content = ''\n\n const { defaultConfigModule, actionsModule, eventsModule, statesModule, interfacesModule, recurringEventsModule } =\n this._dependencies\n\n const defaultConfigImport = defaultConfigModule.import(this)\n const actionsImport = actionsModule.import(this)\n const eventsImport = eventsModule.import(this)\n const statesImport = statesModule.import(this)\n const interfacesImport = interfacesModule.import(this)\n const recurringEventsImport = recurringEventsModule.import(this)\n\n const user = {\n tags: this._plugin.user?.tags ?? {},\n }\n\n const conversation = {\n tags: this._plugin.conversation?.tags ?? {},\n }\n\n content += [\n consts.GENERATED_HEADER,\n 'import * as sdk from \"@botpress/sdk\"',\n '',\n `import * as ${defaultConfigModule.name} from \"./${defaultConfigImport}\"`,\n `import * as ${actionsModule.name} from \"./${actionsImport}\"`,\n `import * as ${eventsModule.name} from \"./${eventsImport}\"`,\n `import * as ${statesModule.name} from \"./${statesImport}\"`,\n `import * as ${interfacesModule.name} from \"./${interfacesImport}\"`,\n `import * as ${recurringEventsModule.name} from \"./${recurringEventsImport}\"`,\n `export * as ${defaultConfigModule.name} from \"./${defaultConfigImport}\"`,\n `export * as ${actionsModule.name} from \"./${actionsImport}\"`,\n `export * as ${eventsModule.name} from \"./${eventsImport}\"`,\n `export * as ${statesModule.name} from \"./${statesImport}\"`,\n `export * as ${interfacesModule.name} from \"./${interfacesImport}\"`,\n `export * as ${recurringEventsModule.name} from \"./${recurringEventsImport}\"`,\n '',\n 'export default {',\n ` name: \"${this._plugin.name}\",`,\n ` version: \"${this._plugin.version}\",`,\n ` user: ${stringifySingleLine(user)},`,\n ` conversation: ${stringifySingleLine(conversation)},`,\n ` configuration: ${defaultConfigModule.name}.${defaultConfigModule.exportName},`,\n ` actions: ${actionsModule.name}.${actionsModule.exportName},`,\n ` events: ${eventsModule.name}.${eventsModule.exportName},`,\n ` states: ${statesModule.name}.${statesModule.exportName},`,\n ` interfaces: ${interfacesModule.name}.${interfacesModule.exportName},`,\n ` recurringEvents: ${recurringEventsModule.name}.${recurringEventsModule.exportName},`,\n '} satisfies sdk.PluginPackage[\"definition\"]',\n ].join('\\n')\n\n return content\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AACxB,wBAAoC;AACpC,oBAAuB;AACvB,4BAA8B;AAC9B,kCAA2C;AAC3C,2BAA6B;AAC7B,+BAAiC;AACjC,qCAAsC;AACtC,2BAA6B;AAYtB,MAAM,sCAAsC,qBAAO;AAAA,EAGjD,YAAoB,SAAiC;AAC1D,UAAM;AAAA,MACJ,MAAM,OAAO;AAAA,MACb,YAAY,OAAO;AAAA,IACrB,CAAC;AAJwB;AAMzB,UAAM,sBAAsB,IAAI,uDAA2B,QAAQ,iBAAiB,CAAC,CAAC;AACtF,wBAAoB,QAAQ,eAAe;AAE3C,UAAM,gBAAgB,IAAI,oCAAc,QAAQ,WAAW,CAAC,CAAC;AAC7D,kBAAc,QAAQ,SAA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,gBAAgB;AAAA,MAC5C,eAAe,aAAa,gBAAgB;AAAA,MAC5C,eAAe,iBAAiB,gBAAgB;AAAA,MAChD,eAAe,sBAAsB,gBAAgB;AAAA,MACrD,eAAe,oBAAoB,gBAAgB;AAAA,MACnD,eAAe,cAAc,gBAAgB;AAAA,MAC7C,eAAe,aAAa,gBAAgB;AAAA,MAC5C,eAAe,aAAa,gBAAgB;AAAA,MAC5C,eAAe,iBAAiB,gBAAgB;AAAA,MAChD,eAAe,sBAAsB,gBAAgB;AAAA,MACrD;AAAA,MACA;AAAA,MACA,YAAY,KAAK,QAAQ;AAAA,MACzB,eAAe,KAAK,QAAQ;AAAA,MAC5B,eAAW,uCAAoB,IAAI;AAAA,MACnC,uBAAmB,uCAAoB,YAAY;AAAA,MACnD,oBAAoB,oBAAoB,QAAQ,oBAAoB;AAAA,MACpE,cAAc,cAAc,QAAQ,cAAc;AAAA,MAClD,aAAa,aAAa,QAAQ,aAAa;AAAA,MAC/C,aAAa,aAAa,QAAQ,aAAa;AAAA,MAC/C,iBAAiB,iBAAiB,QAAQ,iBAAiB;AAAA,MAC3D,sBAAsB,sBAAsB,QAAQ,sBAAsB;AAAA,MAC1E;AAAA,IACF,EAAE,KAAK,IAAI;AAEX,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/code-generation/plugin-package/plugin-package-definition/recurring-events-module.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var recurring_events_module_exports = {};
|
|
30
|
+
__export(recurring_events_module_exports, {
|
|
31
|
+
RecurringEventsModule: () => RecurringEventsModule
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(recurring_events_module_exports);
|
|
34
|
+
var prettier = __toESM(require("prettier"));
|
|
35
|
+
var consts = __toESM(require("../../consts"));
|
|
36
|
+
var gen = __toESM(require("../../generators"));
|
|
37
|
+
var import_module = require("../../module");
|
|
38
|
+
var strings = __toESM(require("../../strings"));
|
|
39
|
+
class RecurringEventModule extends import_module.Module {
|
|
40
|
+
constructor(name, _event) {
|
|
41
|
+
const eventName = name;
|
|
42
|
+
const exportName = strings.varName(eventName);
|
|
43
|
+
super({ path: `${name}.ts`, exportName });
|
|
44
|
+
this._event = _event;
|
|
45
|
+
}
|
|
46
|
+
async getContent() {
|
|
47
|
+
const code = [
|
|
48
|
+
consts.GENERATED_HEADER,
|
|
49
|
+
`export const ${this.exportName} = {`,
|
|
50
|
+
` type: ${gen.primitiveToTypescriptValue(this._event.type)},`,
|
|
51
|
+
` schedule: ${gen.stringifySingleLine(this._event.schedule)},`,
|
|
52
|
+
` payload: ${gen.primitiveRecordToRecordString(this._event.payload)}`,
|
|
53
|
+
"}"
|
|
54
|
+
].join("\n");
|
|
55
|
+
return await prettier.format(code, { parser: "typescript" });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
class RecurringEventsModule extends import_module.ReExportVariableModule {
|
|
59
|
+
constructor(recurringEvents) {
|
|
60
|
+
super({ exportName: strings.varName("recurringEvents") });
|
|
61
|
+
for (const [eventName, event] of Object.entries(recurringEvents)) {
|
|
62
|
+
const module2 = new RecurringEventModule(eventName, event);
|
|
63
|
+
this.pushDep(module2);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
RecurringEventsModule
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=recurring-events-module.js.map
|
package/dist/code-generation/plugin-package/plugin-package-definition/recurring-events-module.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/code-generation/plugin-package/plugin-package-definition/recurring-events-module.ts"],
|
|
4
|
+
"sourcesContent": ["import * as prettier from 'prettier'\nimport * as consts from '../../consts'\nimport * as gen from '../../generators'\nimport { Module, ReExportVariableModule } from '../../module'\nimport * as strings from '../../strings'\nimport * as commonTypes from '../../typings'\n\nclass RecurringEventModule extends Module {\n public constructor(\n name: string,\n private _event: commonTypes.RecurringEventDefinition\n ) {\n const eventName = name\n const exportName = strings.varName(eventName)\n super({ path: `${name}.ts`, exportName })\n }\n\n public async getContent(): Promise<string> {\n const code = [\n consts.GENERATED_HEADER,\n `export const ${this.exportName} = {`,\n ` type: ${gen.primitiveToTypescriptValue(this._event.type)},`,\n ` schedule: ${gen.stringifySingleLine(this._event.schedule)},`,\n ` payload: ${gen.primitiveRecordToRecordString(this._event.payload)}`,\n '}',\n ].join('\\n')\n return await prettier.format(code, { parser: 'typescript' })\n }\n}\n\nexport class RecurringEventsModule extends ReExportVariableModule {\n public constructor(recurringEvents: Exclude<commonTypes.PluginDefinition['recurringEvents'], undefined>) {\n super({ exportName: strings.varName('recurringEvents') })\n for (const [eventName, event] of Object.entries(recurringEvents)) {\n const module = new RecurringEventModule(eventName, event)\n this.pushDep(module)\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAA0B;AAC1B,aAAwB;AACxB,UAAqB;AACrB,oBAA+C;AAC/C,cAAyB;AAGzB,MAAM,6BAA6B,qBAAO;AAAA,EACjC,YACL,MACQ,QACR;AACA,UAAM,YAAY;AAClB,UAAM,aAAa,QAAQ,QAAQ,SAAS;AAC5C,UAAM,EAAE,MAAM,GAAG,WAAW,WAAW,CAAC;AAJhC;AAAA,EAKV;AAAA,EAEA,MAAa,aAA8B;AACzC,UAAM,OAAO;AAAA,MACX,OAAO;AAAA,MACP,gBAAgB,KAAK;AAAA,MACrB,WAAW,IAAI,2BAA2B,KAAK,OAAO,IAAI;AAAA,MAC1D,eAAe,IAAI,oBAAoB,KAAK,OAAO,QAAQ;AAAA,MAC3D,cAAc,IAAI,8BAA8B,KAAK,OAAO,OAAO;AAAA,MACnE;AAAA,IACF,EAAE,KAAK,IAAI;AACX,WAAO,MAAM,SAAS,OAAO,MAAM,EAAE,QAAQ,aAAa,CAAC;AAAA,EAC7D;AACF;AAEO,MAAM,8BAA8B,qCAAuB;AAAA,EACzD,YAAY,iBAAsF;AACvG,UAAM,EAAE,YAAY,QAAQ,QAAQ,iBAAiB,EAAE,CAAC;AACxD,eAAW,CAAC,WAAW,KAAK,KAAK,OAAO,QAAQ,eAAe,GAAG;AAChE,YAAMA,UAAS,IAAI,qBAAqB,WAAW,KAAK;AACxD,WAAK,QAAQA,OAAM;AAAA,IACrB;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["module"]
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/code-generation/typings.ts"],
|
|
4
|
-
"sourcesContent": ["import * as client from '@botpress/client'\nimport * as utils from '../utils'\n\ntype NameVersion = { name: string; version: string }\ntype PackageRef = { id?: string; name: string; version: string }\ntype Schema = Record<string, any>\ntype Aliases = Record<string, { name: string }>\n\ntype TitleDescription = { title?: string; description?: string }\ntype Tags = { tags: Record<string, {}> }\ntype InputOutput = { input: { schema: Schema }; output: { schema: Schema } }\n\nexport type File = { path: string; content: string }\n\nexport type IntegrationDefinition = PackageRef & {\n interfaces?: Record<\n string,\n {\n id?: string\n entities?: Aliases\n actions?: Aliases\n events?: Aliases\n channels?: Aliases\n }\n >\n configuration?: TitleDescription & {\n schema?: Schema\n }\n configurations?: Record<\n string,\n TitleDescription & {\n schema?: Schema\n }\n >\n channels?: Record<\n string,\n TitleDescription & {\n messages: Record<string, TitleDescription & { schema: Schema }>\n conversation?: {\n tags?: Record<string, {}>\n creation?: {\n enabled: boolean\n requiredTags: string[]\n }\n }\n message?: {\n tags?: Record<string, {}>\n }\n }\n >\n states?: Record<\n string,\n TitleDescription & {\n type: client.State['type']\n schema: Schema\n }\n >\n events?: Record<string, TitleDescription & { schema: Schema }>\n actions?: Record<\n string,\n TitleDescription & {\n billable?: boolean\n cacheable?: boolean\n input: {\n schema: Schema\n }\n output: {\n schema: Schema\n }\n }\n >\n entities?: Record<string, TitleDescription & { schema: Schema }>\n user?: {\n tags?: Record<string, {}>\n creation?: {\n enabled: boolean\n requiredTags: string[]\n }\n }\n}\n\nexport type InterfaceDefinition = PackageRef & {\n entities?: Record<string, TitleDescription & { schema: Schema }>\n events?: Record<string, TitleDescription & { schema: Schema }>\n actions?: Record<\n string,\n TitleDescription & {\n billable?: boolean\n cacheable?: boolean\n input: { schema: Schema }\n output: { schema: Schema }\n }\n >\n channels?: Record<string, TitleDescription & { messages: Record<string, TitleDescription & { schema: Schema }> }>\n}\n\nexport type PluginDefinition = PackageRef & {\n configuration?: TitleDescription & { schema?: Schema }\n user?: { tags: Record<string, {}> }\n conversation?: Tags\n states?: Record<string, TitleDescription & { type: client.State['type']; schema: Schema }>\n events?: Record<string, TitleDescription & { schema: Schema }>\n actions?: Record<string, TitleDescription & InputOutput>\n workflows?: Record<string, TitleDescription & Tags & InputOutput>\n dependencies?: {\n interfaces?: Record<string, PackageRef>\n integrations?: Record<string, PackageRef>\n }\n}\n\nexport type IntegrationInstallablePackage = NameVersion & {\n integration: IntegrationDefinition\n devId?: string\n path?: utils.path.AbsolutePath\n}\n\nexport type InterfaceInstallablePackage = NameVersion & {\n interface: InterfaceDefinition\n path?: utils.path.AbsolutePath\n}\n\nexport type PluginInstallablePackage = NameVersion & {\n plugin: PluginDefinition\n path?: utils.path.AbsolutePath\n code: string\n}\n"],
|
|
4
|
+
"sourcesContent": ["import * as client from '@botpress/client'\nimport * as utils from '../utils'\n\ntype NameVersion = { name: string; version: string }\ntype PackageRef = { id?: string; name: string; version: string }\ntype Schema = Record<string, any>\ntype Aliases = Record<string, { name: string }>\n\ntype TitleDescription = { title?: string; description?: string }\ntype Tags = { tags: Record<string, {}> }\ntype InputOutput = { input: { schema: Schema }; output: { schema: Schema } }\n\nexport type File = { path: string; content: string }\n\nexport type IntegrationDefinition = PackageRef & {\n interfaces?: Record<\n string,\n {\n id?: string\n entities?: Aliases\n actions?: Aliases\n events?: Aliases\n channels?: Aliases\n }\n >\n configuration?: TitleDescription & {\n schema?: Schema\n }\n configurations?: Record<\n string,\n TitleDescription & {\n schema?: Schema\n }\n >\n channels?: Record<\n string,\n TitleDescription & {\n messages: Record<string, TitleDescription & { schema: Schema }>\n conversation?: {\n tags?: Record<string, {}>\n creation?: {\n enabled: boolean\n requiredTags: string[]\n }\n }\n message?: {\n tags?: Record<string, {}>\n }\n }\n >\n states?: Record<\n string,\n TitleDescription & {\n type: client.State['type']\n schema: Schema\n }\n >\n events?: Record<string, TitleDescription & { schema: Schema }>\n actions?: Record<\n string,\n TitleDescription & {\n billable?: boolean\n cacheable?: boolean\n input: {\n schema: Schema\n }\n output: {\n schema: Schema\n }\n }\n >\n entities?: Record<string, TitleDescription & { schema: Schema }>\n user?: {\n tags?: Record<string, {}>\n creation?: {\n enabled: boolean\n requiredTags: string[]\n }\n }\n}\n\nexport type InterfaceDefinition = PackageRef & {\n entities?: Record<string, TitleDescription & { schema: Schema }>\n events?: Record<string, TitleDescription & { schema: Schema }>\n actions?: Record<\n string,\n TitleDescription & {\n billable?: boolean\n cacheable?: boolean\n input: { schema: Schema }\n output: { schema: Schema }\n }\n >\n channels?: Record<string, TitleDescription & { messages: Record<string, TitleDescription & { schema: Schema }> }>\n}\n\nexport type RecurringEventDefinition = {\n type: string\n payload: Record<string, any>\n schedule: { cron: string }\n}\n\nexport type PluginDefinition = PackageRef & {\n configuration?: TitleDescription & { schema?: Schema }\n user?: { tags: Record<string, {}> }\n conversation?: Tags\n states?: Record<string, TitleDescription & { type: client.State['type']; schema: Schema }>\n events?: Record<string, TitleDescription & { schema: Schema }>\n actions?: Record<string, TitleDescription & InputOutput>\n workflows?: Record<string, TitleDescription & Tags & InputOutput>\n dependencies?: {\n interfaces?: Record<string, PackageRef>\n integrations?: Record<string, PackageRef>\n }\n recurringEvents?: Record<string, RecurringEventDefinition>\n}\n\nexport type IntegrationInstallablePackage = NameVersion & {\n integration: IntegrationDefinition\n devId?: string\n path?: utils.path.AbsolutePath\n}\n\nexport type InterfaceInstallablePackage = NameVersion & {\n interface: InterfaceDefinition\n path?: utils.path.AbsolutePath\n}\n\nexport type PluginInstallablePackage = NameVersion & {\n plugin: PluginDefinition\n path?: utils.path.AbsolutePath\n code: string\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/add-command.ts"],
|
|
4
|
-
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as fslib from 'fs'\nimport * as pathlib from 'path'\nimport * as apiUtils from '../api'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as pkgRef from '../package-ref'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\nimport { ProjectCache, ProjectCommand, ProjectCommandDefinition, ProjectDefinition } from './project-command'\n\ntype InstallablePackage =\n | {\n type: 'integration'\n pkg: codegen.IntegrationInstallablePackage\n }\n | {\n type: 'interface'\n pkg: codegen.InterfaceInstallablePackage\n }\n | {\n type: 'plugin'\n pkg: codegen.PluginInstallablePackage\n }\n\nexport type AddCommandDefinition = typeof commandDefinitions.add\nexport class AddCommand extends GlobalCommand<AddCommandDefinition> {\n public async run(): Promise<void> {\n const ref = this._parseArgvRef()\n if (ref) {\n return await this._addSinglePackage(ref)\n }\n\n const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath)\n if (!pkgJson) {\n this.logger.warn('No package.json found in the install path')\n return\n }\n\n const { bpDependencies } = pkgJson\n if (!bpDependencies) {\n this.logger.log('No bp dependencies found in package.json')\n return\n }\n\n const bpDependenciesSchema = sdk.z.record(sdk.z.string())\n const parseResults = bpDependenciesSchema.safeParse(bpDependencies)\n if (!parseResults.success) {\n throw new errors.BotpressCLIError('Invalid bpDependencies found in package.json')\n }\n\n for (const [pkgAlias, pkgRefStr] of Object.entries(parseResults.data)) {\n const parsed = pkgRef.parsePackageRef(pkgRefStr)\n if (!parsed) {\n throw new errors.InvalidPackageReferenceError(pkgRefStr)\n }\n\n await this._addSinglePackage({ ...parsed, alias: pkgAlias })\n }\n }\n\n private _parseArgvRef = (): pkgRef.PackageRef | undefined => {\n if (!this.argv.packageRef) {\n return\n }\n\n const parsed = pkgRef.parsePackageRef(this.argv.packageRef)\n if (!parsed) {\n throw new errors.InvalidPackageReferenceError(this.argv.packageRef)\n }\n\n if (parsed.type !== 'name') {\n return parsed\n }\n\n const argvPkgType = this.argv.packageType\n if (!argvPkgType) {\n return parsed\n }\n\n const ref = { ...parsed, pkg: argvPkgType }\n\n const strRef = pkgRef.formatPackageRef(ref)\n this.logger.warn(`argument --packageType is deprecated; please use the package reference format \"${strRef}\"`)\n\n return ref\n }\n\n private async _addSinglePackage(ref: pkgRef.PackageRef & { alias?: string }): Promise<void> {\n const targetPackage = ref.type === 'path' ? await this._findLocalPackage(ref) : await this._findRemotePackage(ref)\n\n if (!targetPackage) {\n const strRef = pkgRef.formatPackageRef(ref)\n throw new errors.BotpressCLIError(`Could not find package \"${strRef}\"`)\n }\n\n const packageName = ref.alias ?? targetPackage.pkg.name\n const baseInstallPath = utils.path.absoluteFrom(utils.path.cwd(), this.argv.installPath)\n const packageDirName = utils.casing.to.kebabCase(packageName)\n const installPath = utils.path.join(baseInstallPath, consts.installDirName, packageDirName)\n\n const alreadyInstalled = fslib.existsSync(installPath)\n if (alreadyInstalled) {\n this.logger.warn(`Package with name \"${packageName}\" already installed.`)\n const res = await this.prompt.confirm('Do you want to overwrite the existing package?')\n if (!res) {\n this.logger.log('Aborted')\n return\n }\n\n await this._uninstall(installPath)\n }\n\n let files: codegen.File[]\n if (targetPackage.type === 'integration') {\n files = await codegen.generateIntegrationPackage(targetPackage.pkg)\n } else if (targetPackage.type === 'interface') {\n files = await codegen.generateInterfacePackage(targetPackage.pkg)\n } else if (targetPackage.type === 'plugin') {\n files = await codegen.generatePluginPackage(targetPackage.pkg)\n } else {\n type _assertion = utils.types.AssertNever<typeof targetPackage>\n throw new errors.BotpressCLIError('Invalid package type')\n }\n\n await this._install(installPath, files)\n }\n\n private async _findRemotePackage(ref: pkgRef.ApiPackageRef): Promise<InstallablePackage | undefined> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (this._pkgCouldBe(ref, 'integration')) {\n const integration = await api.findIntegration(ref)\n if (integration) {\n const { name, version } = integration\n return { type: 'integration', pkg: { integration, name, version } }\n }\n }\n if (this._pkgCouldBe(ref, 'interface')) {\n const intrface = await api.findPublicInterface(ref)\n if (intrface) {\n const { name, version } = intrface\n return { type: 'interface', pkg: { interface: intrface, name, version } }\n }\n }\n if (this._pkgCouldBe(ref, 'plugin')) {\n const plugin = await api.findPublicPlugin(ref)\n if (plugin) {\n const { code } = await api.client.getPluginCode({ id: plugin.id, platform: 'node' })\n const { name, version } = plugin\n return {\n type: 'plugin',\n pkg: {\n name,\n version,\n plugin,\n code,\n },\n }\n }\n }\n return\n }\n\n private async _findLocalPackage(ref: pkgRef.LocalPackageRef): Promise<InstallablePackage | undefined> {\n const absPath = utils.path.absoluteFrom(utils.path.cwd(), ref.path)\n const {\n definition: projectDefinition,\n implementation: projectImplementation,\n devId: projectDevId,\n } = await this._readProject(absPath)\n\n if (projectDefinition?.type === 'integration') {\n const { name, version } = projectDefinition.definition\n let devId: string | undefined\n if (this.argv.useDev && projectDevId) {\n this.logger.warn(`Installing integration \"${name}\" with dev version \"${projectDevId}\"`)\n devId = projectDevId\n }\n\n let createIntegrationReqBody = await this._getProjectCmd(ref.path).prepareCreateIntegrationBody(\n projectDefinition.definition\n )\n createIntegrationReqBody = {\n ...createIntegrationReqBody,\n interfaces: utils.records.mapValues(projectDefinition.definition.interfaces ?? {}, (i) => ({\n id: '', // TODO: do this better\n ...i,\n })),\n }\n return {\n type: 'integration',\n pkg: { path: absPath, devId, name, version, integration: createIntegrationReqBody },\n }\n }\n\n if (projectDefinition?.type === 'interface') {\n const { name, version } = projectDefinition.definition\n const createInterfaceReqBody = await apiUtils.prepareCreateInterfaceBody(projectDefinition.definition)\n return {\n type: 'interface',\n pkg: { path: absPath, name, version, interface: createInterfaceReqBody },\n }\n }\n\n if (projectDefinition?.type === 'plugin') {\n if (!projectImplementation) {\n throw new errors.BotpressCLIError(\n 'Plugin implementation not found; Please build the plugin project before installing'\n )\n }\n\n const { name, version } = projectDefinition.definition\n const code = projectImplementation\n\n const createPluginReqBody = await apiUtils.prepareCreatePluginBody(projectDefinition.definition)\n return {\n type: 'plugin',\n pkg: {\n path: absPath,\n name,\n version,\n code,\n plugin: {\n ...createPluginReqBody,\n dependencies: {\n interfaces: await utils.promises.awaitRecord(\n utils.records.mapValues(\n projectDefinition.definition.interfaces ?? {},\n apiUtils.prepareCreateInterfaceBody\n )\n ),\n integrations: await utils.promises.awaitRecord(\n utils.records.mapValues(\n projectDefinition.definition.integrations ?? {},\n apiUtils.prepareCreateIntegrationBody\n )\n ),\n },\n },\n },\n }\n }\n\n if (projectDefinition?.type === 'bot') {\n throw new errors.BotpressCLIError('Cannot install a bot as a package')\n }\n return\n }\n\n private async _install(installPath: utils.path.AbsolutePath, files: codegen.File[]): Promise<void> {\n const line = this.logger.line()\n line.started(`Installing ${files.length} files to \"${installPath}\"`)\n try {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(installPath, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fslib.promises.mkdir(dirPath, { recursive: true })\n await fslib.promises.writeFile(filePath, file.content)\n }\n line.success(`Installed ${files.length} files to \"${installPath}\"`)\n } finally {\n line.commit()\n }\n }\n\n private async _uninstall(installPath: utils.path.AbsolutePath): Promise<void> {\n await fslib.promises.rm(installPath, { recursive: true })\n }\n\n private async _readProject(workDir: utils.path.AbsolutePath): Promise<{\n definition?: ProjectDefinition\n implementation?: string\n devId?: string\n }> {\n const cmd = this._getProjectCmd(workDir)\n\n const definition = await cmd.readProjectDefinitionFromFS().catch((thrown) => {\n if (thrown instanceof errors.ProjectDefinitionNotFoundError) {\n return undefined\n }\n throw thrown\n })\n\n const devId = await cmd.projectCache.get('devId')\n\n const implementationAbsPath = utils.path.join(workDir, consts.fromWorkDir.outFileCJS)\n if (!fslib.existsSync(implementationAbsPath)) {\n return { definition, devId }\n }\n\n const implementation = await fslib.promises.readFile(implementationAbsPath, 'utf8')\n return { definition, implementation, devId }\n }\n\n private _pkgCouldBe = (ref: pkgRef.ApiPackageRef, pkgType: InstallablePackage['type']) => {\n if (ref.type === 'id') {\n // TODO: use ULID prefixes to determine the type of the package\n return true\n }\n if (!ref.pkg) {\n return true // ref does not specify the package type\n }\n return ref.pkg === pkgType\n }\n\n private _getProjectCmd(workDir: string): _AnyProjectCommand {\n return new _AnyProjectCommand(apiUtils.ApiClient, this.prompt, this.logger, {\n ...this.argv,\n workDir,\n })\n }\n}\n\n// this is a hack to avoid refactoring the project command class\nclass _AnyProjectCommand extends ProjectCommand<ProjectCommandDefinition> {\n public async run(): Promise<void> {\n throw new errors.BotpressCLIError('Not implemented')\n }\n\n public async readProjectDefinitionFromFS(): Promise<ProjectDefinition> {\n return super.readProjectDefinitionFromFS()\n }\n\n public async prepareCreateIntegrationBody(\n integrationDef: sdk.IntegrationDefinition\n ): Promise<apiUtils.CreateIntegrationRequestBody> {\n return super.prepareCreateIntegrationBody(integrationDef)\n }\n\n public get projectCache(): utils.cache.FSKeyValueCache<ProjectCache> {\n return super.projectCache\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAAqB;AACrB,YAAuB;AACvB,cAAyB;AACzB,eAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,4BAA8B;AAC9B,6BAA0F;AAiBnF,MAAM,mBAAmB,oCAAoC;AAAA,EAClE,MAAa,MAAqB;AAChC,UAAM,MAAM,KAAK,cAAc;AAC/B,QAAI,KAAK;AACP,aAAO,MAAM,KAAK,kBAAkB,GAAG;AAAA,IACzC;AAEA,UAAM,UAAU,MAAM,MAAM,QAAQ,gBAAgB,KAAK,KAAK,WAAW;AACzE,Q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SAAS;AAAA,gBACX;AAAA,cACF;AAAA,YACF;AAAA,
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as fslib from 'fs'\nimport * as pathlib from 'path'\nimport * as apiUtils from '../api'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as pkgRef from '../package-ref'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\nimport { ProjectCache, ProjectCommand, ProjectCommandDefinition, ProjectDefinition } from './project-command'\n\ntype InstallablePackage =\n | {\n type: 'integration'\n pkg: codegen.IntegrationInstallablePackage\n }\n | {\n type: 'interface'\n pkg: codegen.InterfaceInstallablePackage\n }\n | {\n type: 'plugin'\n pkg: codegen.PluginInstallablePackage\n }\n\nexport type AddCommandDefinition = typeof commandDefinitions.add\nexport class AddCommand extends GlobalCommand<AddCommandDefinition> {\n public async run(): Promise<void> {\n const ref = this._parseArgvRef()\n if (ref) {\n return await this._addSinglePackage(ref)\n }\n\n const pkgJson = await utils.pkgJson.readPackageJson(this.argv.installPath)\n if (!pkgJson) {\n this.logger.warn('No package.json found in the install path')\n return\n }\n\n const { bpDependencies } = pkgJson\n if (!bpDependencies) {\n this.logger.log('No bp dependencies found in package.json')\n return\n }\n\n const bpDependenciesSchema = sdk.z.record(sdk.z.string())\n const parseResults = bpDependenciesSchema.safeParse(bpDependencies)\n if (!parseResults.success) {\n throw new errors.BotpressCLIError('Invalid bpDependencies found in package.json')\n }\n\n for (const [pkgAlias, pkgRefStr] of Object.entries(parseResults.data)) {\n const parsed = pkgRef.parsePackageRef(pkgRefStr)\n if (!parsed) {\n throw new errors.InvalidPackageReferenceError(pkgRefStr)\n }\n\n await this._addSinglePackage({ ...parsed, alias: pkgAlias })\n }\n }\n\n private _parseArgvRef = (): pkgRef.PackageRef | undefined => {\n if (!this.argv.packageRef) {\n return\n }\n\n const parsed = pkgRef.parsePackageRef(this.argv.packageRef)\n if (!parsed) {\n throw new errors.InvalidPackageReferenceError(this.argv.packageRef)\n }\n\n if (parsed.type !== 'name') {\n return parsed\n }\n\n const argvPkgType = this.argv.packageType\n if (!argvPkgType) {\n return parsed\n }\n\n const ref = { ...parsed, pkg: argvPkgType }\n\n const strRef = pkgRef.formatPackageRef(ref)\n this.logger.warn(`argument --packageType is deprecated; please use the package reference format \"${strRef}\"`)\n\n return ref\n }\n\n private async _addSinglePackage(ref: pkgRef.PackageRef & { alias?: string }): Promise<void> {\n const targetPackage = ref.type === 'path' ? await this._findLocalPackage(ref) : await this._findRemotePackage(ref)\n\n if (!targetPackage) {\n const strRef = pkgRef.formatPackageRef(ref)\n throw new errors.BotpressCLIError(`Could not find package \"${strRef}\"`)\n }\n\n const packageName = ref.alias ?? targetPackage.pkg.name\n const baseInstallPath = utils.path.absoluteFrom(utils.path.cwd(), this.argv.installPath)\n const packageDirName = utils.casing.to.kebabCase(packageName)\n const installPath = utils.path.join(baseInstallPath, consts.installDirName, packageDirName)\n\n const alreadyInstalled = fslib.existsSync(installPath)\n if (alreadyInstalled) {\n this.logger.warn(`Package with name \"${packageName}\" already installed.`)\n const res = await this.prompt.confirm('Do you want to overwrite the existing package?')\n if (!res) {\n this.logger.log('Aborted')\n return\n }\n\n await this._uninstall(installPath)\n }\n\n let files: codegen.File[]\n if (targetPackage.type === 'integration') {\n files = await codegen.generateIntegrationPackage(targetPackage.pkg)\n } else if (targetPackage.type === 'interface') {\n files = await codegen.generateInterfacePackage(targetPackage.pkg)\n } else if (targetPackage.type === 'plugin') {\n files = await codegen.generatePluginPackage(targetPackage.pkg)\n } else {\n type _assertion = utils.types.AssertNever<typeof targetPackage>\n throw new errors.BotpressCLIError('Invalid package type')\n }\n\n await this._install(installPath, files)\n }\n\n private async _findRemotePackage(ref: pkgRef.ApiPackageRef): Promise<InstallablePackage | undefined> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (this._pkgCouldBe(ref, 'integration')) {\n const integration = await api.findIntegration(ref)\n if (integration) {\n const { name, version } = integration\n return { type: 'integration', pkg: { integration, name, version } }\n }\n }\n if (this._pkgCouldBe(ref, 'interface')) {\n const intrface = await api.findPublicInterface(ref)\n if (intrface) {\n const { name, version } = intrface\n return { type: 'interface', pkg: { interface: intrface, name, version } }\n }\n }\n if (this._pkgCouldBe(ref, 'plugin')) {\n const plugin = await api.findPublicPlugin(ref)\n if (plugin) {\n const { code } = await api.client.getPluginCode({ id: plugin.id, platform: 'node' })\n const { name, version } = plugin\n return {\n type: 'plugin',\n pkg: {\n name,\n version,\n plugin,\n code,\n },\n }\n }\n }\n return\n }\n\n private async _findLocalPackage(ref: pkgRef.LocalPackageRef): Promise<InstallablePackage | undefined> {\n const absPath = utils.path.absoluteFrom(utils.path.cwd(), ref.path)\n const {\n definition: projectDefinition,\n implementation: projectImplementation,\n devId: projectDevId,\n } = await this._readProject(absPath)\n\n if (projectDefinition?.type === 'integration') {\n const { name, version } = projectDefinition.definition\n let devId: string | undefined\n if (this.argv.useDev && projectDevId) {\n this.logger.warn(`Installing integration \"${name}\" with dev version \"${projectDevId}\"`)\n devId = projectDevId\n }\n\n let createIntegrationReqBody = await this._getProjectCmd(ref.path).prepareCreateIntegrationBody(\n projectDefinition.definition\n )\n createIntegrationReqBody = {\n ...createIntegrationReqBody,\n interfaces: utils.records.mapValues(projectDefinition.definition.interfaces ?? {}, (i) => ({\n id: '', // TODO: do this better\n ...i,\n })),\n }\n return {\n type: 'integration',\n pkg: { path: absPath, devId, name, version, integration: createIntegrationReqBody },\n }\n }\n\n if (projectDefinition?.type === 'interface') {\n const { name, version } = projectDefinition.definition\n const createInterfaceReqBody = await apiUtils.prepareCreateInterfaceBody(projectDefinition.definition)\n return {\n type: 'interface',\n pkg: { path: absPath, name, version, interface: createInterfaceReqBody },\n }\n }\n\n if (projectDefinition?.type === 'plugin') {\n if (!projectImplementation) {\n throw new errors.BotpressCLIError(\n 'Plugin implementation not found; Please build the plugin project before installing'\n )\n }\n\n const { name, version } = projectDefinition.definition\n const code = projectImplementation\n\n const createPluginReqBody = await apiUtils.prepareCreatePluginBody(projectDefinition.definition)\n return {\n type: 'plugin',\n pkg: {\n path: absPath,\n name,\n version,\n code,\n plugin: {\n ...createPluginReqBody,\n dependencies: {\n interfaces: await utils.promises.awaitRecord(\n utils.records.mapValues(\n projectDefinition.definition.interfaces ?? {},\n apiUtils.prepareCreateInterfaceBody\n )\n ),\n integrations: await utils.promises.awaitRecord(\n utils.records.mapValues(\n projectDefinition.definition.integrations ?? {},\n apiUtils.prepareCreateIntegrationBody\n )\n ),\n },\n recurringEvents: projectDefinition.definition.recurringEvents,\n },\n },\n }\n }\n\n if (projectDefinition?.type === 'bot') {\n throw new errors.BotpressCLIError('Cannot install a bot as a package')\n }\n return\n }\n\n private async _install(installPath: utils.path.AbsolutePath, files: codegen.File[]): Promise<void> {\n const line = this.logger.line()\n line.started(`Installing ${files.length} files to \"${installPath}\"`)\n try {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(installPath, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fslib.promises.mkdir(dirPath, { recursive: true })\n await fslib.promises.writeFile(filePath, file.content)\n }\n line.success(`Installed ${files.length} files to \"${installPath}\"`)\n } finally {\n line.commit()\n }\n }\n\n private async _uninstall(installPath: utils.path.AbsolutePath): Promise<void> {\n await fslib.promises.rm(installPath, { recursive: true })\n }\n\n private async _readProject(workDir: utils.path.AbsolutePath): Promise<{\n definition?: ProjectDefinition\n implementation?: string\n devId?: string\n }> {\n const cmd = this._getProjectCmd(workDir)\n\n const definition = await cmd.readProjectDefinitionFromFS().catch((thrown) => {\n if (thrown instanceof errors.ProjectDefinitionNotFoundError) {\n return undefined\n }\n throw thrown\n })\n\n const devId = await cmd.projectCache.get('devId')\n\n const implementationAbsPath = utils.path.join(workDir, consts.fromWorkDir.outFileCJS)\n if (!fslib.existsSync(implementationAbsPath)) {\n return { definition, devId }\n }\n\n const implementation = await fslib.promises.readFile(implementationAbsPath, 'utf8')\n return { definition, implementation, devId }\n }\n\n private _pkgCouldBe = (ref: pkgRef.ApiPackageRef, pkgType: InstallablePackage['type']) => {\n if (ref.type === 'id') {\n // TODO: use ULID prefixes to determine the type of the package\n return true\n }\n if (!ref.pkg) {\n return true // ref does not specify the package type\n }\n return ref.pkg === pkgType\n }\n\n private _getProjectCmd(workDir: string): _AnyProjectCommand {\n return new _AnyProjectCommand(apiUtils.ApiClient, this.prompt, this.logger, {\n ...this.argv,\n workDir,\n })\n }\n}\n\n// this is a hack to avoid refactoring the project command class\nclass _AnyProjectCommand extends ProjectCommand<ProjectCommandDefinition> {\n public async run(): Promise<void> {\n throw new errors.BotpressCLIError('Not implemented')\n }\n\n public async readProjectDefinitionFromFS(): Promise<ProjectDefinition> {\n return super.readProjectDefinitionFromFS()\n }\n\n public async prepareCreateIntegrationBody(\n integrationDef: sdk.IntegrationDefinition\n ): Promise<apiUtils.CreateIntegrationRequestBody> {\n return super.prepareCreateIntegrationBody(integrationDef)\n }\n\n public get projectCache(): utils.cache.FSKeyValueCache<ProjectCache> {\n return super.projectCache\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAAqB;AACrB,YAAuB;AACvB,cAAyB;AACzB,eAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,4BAA8B;AAC9B,6BAA0F;AAiBnF,MAAM,mBAAmB,oCAAoC;AAAA,EAClE,MAAa,MAAqB;AAChC,UAAM,MAAM,KAAK,cAAc;AAC/B,QAAI,KAAK;AACP,aAAO,MAAM,KAAK,kBAAkB,GAAG;AAAA,IACzC;AAEA,UAAM,UAAU,MAAM,MAAM,QAAQ,gBAAgB,KAAK,KAAK,WAAW;AACzE,QAAI,CAAC,SAAS;AACZ,WAAK,OAAO,KAAK,2CAA2C;AAC5D;AAAA,IACF;AAEA,UAAM,EAAE,eAAe,IAAI;AAC3B,QAAI,C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AAc,CAAC,KAA2B,YAAwC;AACxF,QAAI,IAAI,SAAS,MAAM;AAErB,aAAO;AAAA,IACT;AACA,QAAI,CAAC,IAAI,KAAK;AACZ,aAAO;AAAA,IACT;AACA,WAAO,IAAI,QAAQ;AAAA,EACrB;AAAA,EAEQ,eAAe,SAAqC;AAC1D,WAAO,IAAI,mBAAmB,SAAS,WAAW,KAAK,QAAQ,KAAK,QAAQ;AAAA,MAC1E,GAAG,KAAK;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAGA,MAAM,2BAA2B,sCAAyC;AAAA,EACxE,MAAa,MAAqB;AAChC,UAAM,IAAI,OAAO,iBAAiB,iBAAiB;AAAA,EACrD;AAAA,EAEA,MAAa,8BAA0D;AACrE,WAAO,MAAM,4BAA4B;AAAA,EAC3C;AAAA,EAEA,MAAa,6BACX,gBACgD;AAChD,WAAO,MAAM,6BAA6B,cAAc;AAAA,EAC1D;AAAA,EAEA,IAAW,eAA0D;AACnE,WAAO,MAAM;AAAA,EACf;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -37,7 +37,12 @@ var import_lodash = __toESM(require("lodash"));
|
|
|
37
37
|
var import_util = __toESM(require("util"));
|
|
38
38
|
var utils = __toESM(require("../utils"));
|
|
39
39
|
const STDOUT_CHUNK_SIZE = 100;
|
|
40
|
-
const DEFAULT_OPTIONS = {
|
|
40
|
+
const DEFAULT_OPTIONS = {
|
|
41
|
+
verbose: false,
|
|
42
|
+
json: false,
|
|
43
|
+
outStream: process.stdout,
|
|
44
|
+
errStream: process.stderr
|
|
45
|
+
};
|
|
41
46
|
const NO_COLOR = (str) => str;
|
|
42
47
|
const PINK = [255, 100, 255];
|
|
43
48
|
const ORANGE = [255, 165, 0];
|
|
@@ -157,7 +162,8 @@ class BaseLogger {
|
|
|
157
162
|
return renderer.default;
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
|
-
render(message,
|
|
165
|
+
render(message, streamType = "out") {
|
|
166
|
+
const stream = streamType === "err" ? this.opts.errStream : this.opts.outStream;
|
|
161
167
|
for (const chunk of utils.string.chunkString(message, STDOUT_CHUNK_SIZE)) {
|
|
162
168
|
stream.write(chunk);
|
|
163
169
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/logger/base-logger.ts"],
|
|
4
|
-
"sourcesContent": ["import boxen from 'boxen'\nimport chalk from 'chalk'\nimport _ from 'lodash'\nimport util from 'util'\nimport * as utils from '../utils'\n\nexport type LoggerOptions = {\n verbose: boolean\n json
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,mBAAkB;AAClB,oBAAc;AACd,kBAAiB;AACjB,YAAuB;
|
|
4
|
+
"sourcesContent": ["import boxen from 'boxen'\nimport chalk from 'chalk'\nimport _ from 'lodash'\nimport util from 'util'\nimport * as utils from '../utils'\n\nexport type LoggerOptions = {\n verbose: boolean\n json: boolean // prevents loggin anything else than json\n outStream: NodeJS.WriteStream\n errStream: NodeJS.WriteStream\n}\n\nconst STDOUT_CHUNK_SIZE = 100\nconst DEFAULT_OPTIONS: LoggerOptions = {\n verbose: false,\n json: false,\n outStream: process.stdout,\n errStream: process.stderr,\n}\n\ntype ChalkColor = (str: string) => string\nconst NO_COLOR: ChalkColor = (str: string) => str\n\nconst PINK = [255, 100, 255] as const\nconst ORANGE = [255, 165, 0] as const\nconst PURPLE = [128, 0, 128] as const\n\nconst BG_COLORS: Record<Color, ChalkColor> = {\n blue: chalk.bgBlueBright,\n green: chalk.bgGreenBright,\n yellow: chalk.bgYellowBright,\n red: chalk.bgRedBright,\n white: chalk.bgWhite,\n pink: (str: string) => chalk.bgRgb(...PINK)(str),\n orange: (str: string) => chalk.bgRgb(...ORANGE)(str),\n purple: (str: string) => chalk.bgRgb(...PURPLE)(str),\n}\n\nconst FG_COLORS: Record<Color, ChalkColor> = {\n blue: chalk.blueBright,\n green: chalk.green,\n yellow: chalk.yellowBright,\n red: chalk.red,\n white: chalk.white,\n pink: (str: string) => chalk.rgb(...PINK)(str),\n orange: (str: string) => chalk.rgb(...ORANGE)(str),\n purple: (str: string) => chalk.rgb(...PURPLE)(str),\n}\n\ntype Symbol = '\u2713' | '\u26A0' | '\u00D7' | '\u25CF' | ' ' | '\u25CB'\ntype Color = 'blue' | 'green' | 'yellow' | 'red' | 'pink' | 'white' | 'orange' | 'purple'\ntype LogPrefix = { symbol: Symbol; fg?: Color; bg?: Color; indent?: number } | string\ntype SymbolRenderer<T extends Symbol> = { default: T; windows?: string; mac?: string }\n\ntype LogProps = {\n prefix: LogPrefix\n stderr?: boolean\n}\n\ntype PrintProps = {\n metadata: any\n prefix: string\n stderr?: boolean\n}\n\nconst checkmark: SymbolRenderer<'\u2713'> = {\n default: '\u2713',\n windows: '\u221A',\n mac: '\u2714',\n}\n\nconst cross: SymbolRenderer<'\u00D7'> = {\n default: '\u00D7',\n mac: '\u2716',\n}\n\nconst danger: SymbolRenderer<'\u26A0'> = { default: '\u26A0' }\nconst circle: SymbolRenderer<'\u25CB'> = { default: '\u25CB' }\nconst disc: SymbolRenderer<'\u25CF'> = { default: '\u25CF' }\nconst space: SymbolRenderer<' '> = { default: ' ' }\n\nconst renderers: Record<Symbol, SymbolRenderer<Symbol>> = {\n '\u2713': checkmark,\n '\u00D7': cross,\n '\u26A0': danger,\n '\u25CB': circle,\n '\u25CF': disc,\n ' ': space,\n}\n\nconst BOX_OPTIONS: boxen.Options = {\n padding: 1,\n margin: 1,\n borderStyle: 'round',\n borderColor: 'yellow',\n}\n\nexport type StreamType = 'out' | 'err'\n\nexport abstract class BaseLogger {\n protected opts: LoggerOptions\n\n public constructor(opts: Partial<LoggerOptions> = {}) {\n this.opts = { ...DEFAULT_OPTIONS, ...opts }\n }\n\n public log(message: string, props: Partial<LogProps> = {}): void {\n if (this.opts.json && !props.stderr) {\n return\n }\n\n const prefix = this._resolvePrefix(props.prefix)\n this.print(message, { ...props, prefix })\n }\n\n public json(data: any, opts: Partial<{ depth: number }> = { depth: Infinity }): void {\n if (this.opts.json) {\n this.print(JSON.stringify(data, undefined, 2))\n return\n }\n\n const { depth } = opts\n const msg = util.inspect(data, { colors: true, depth })\n this.log(msg)\n }\n\n public debug(message: string): void {\n if (!this.opts.verbose) {\n return\n }\n this.log(chalk.grey(message), { prefix: { symbol: '\u25CF', fg: 'blue' } })\n }\n\n public started(message: string): void {\n this.log(message, { prefix: { symbol: '\u25CB', fg: 'purple' } })\n }\n\n public success(message: string): void {\n this.log(message, { prefix: { symbol: '\u2713', fg: 'green' } })\n }\n\n public warn(message: string): void {\n this.log(message, { prefix: { symbol: '\u26A0', fg: 'yellow' } })\n }\n\n public error(message: string): void {\n this.log(message, { prefix: { symbol: '\u00D7', fg: 'red' }, stderr: true })\n }\n\n public box(message: string): void {\n const box = boxen(message, BOX_OPTIONS)\n this.log(box)\n }\n\n protected abstract print(message: string, props?: Partial<PrintProps>): void\n\n private _resolvePrefix(prefix: LogPrefix | undefined): string | undefined {\n if (!prefix) {\n return\n }\n\n if (_.isString(prefix)) {\n return prefix\n }\n\n const { symbol, fg, bg, indent } = prefix\n const renderedSymbol = this._renderSymbol(symbol)\n const fgcolor = fg ? FG_COLORS[fg] : NO_COLOR\n const bgcolor = bg ? BG_COLORS[bg] : NO_COLOR\n const indentStr = indent ? ' '.repeat(indent) : ''\n const symbolStr = fgcolor(bgcolor(renderedSymbol))\n return `${indentStr}${symbolStr}`\n }\n\n private _renderSymbol(symbol: Symbol): string {\n const renderer = renderers[symbol]\n if (process.platform === 'win32') {\n return renderer.windows || renderer.default\n } else if (process.platform === 'darwin') {\n return renderer.mac || renderer.default\n } else {\n return renderer.default\n }\n }\n\n protected render(message: string, streamType: StreamType = 'out'): void {\n // chunking the message ensures that the process won't exit before the message is fully written\n const stream = streamType === 'err' ? this.opts.errStream : this.opts.outStream\n for (const chunk of utils.string.chunkString(message, STDO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AA,EAEQ,cAAc,QAAwB;AAC5C,UAAM,WAAW,UAAU,MAAM;AACjC,QAAI,QAAQ,aAAa,SAAS;AAChC,aAAO,SAAS,WAAW,SAAS;AAAA,IACtC,WAAW,QAAQ,aAAa,UAAU;AACxC,aAAO,SAAS,OAAO,SAAS;AAAA,IAClC,OAAO;AACL,aAAO,SAAS;AAAA,IAClB;AAAA,EACF;AAAA,EAEU,OAAO,SAAiB,aAAyB,OAAa;AAEtE,UAAM,SAAS,eAAe,QAAQ,KAAK,KAAK,YAAY,KAAK,KAAK;AACtE,eAAW,SAAS,MAAM,OAAO,YAAY,SAAS,iBAAiB,GAAG;AACxE,aAAO,MAAM,KAAK;AAAA,IACpB;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["chalk", "util", "boxen", "_"]
|
|
7
7
|
}
|
package/dist/logger/index.js
CHANGED
|
@@ -18,18 +18,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var logger_exports = {};
|
|
20
20
|
__export(logger_exports, {
|
|
21
|
-
Logger: () => Logger
|
|
22
|
-
SingleLineLogger: () => SingleLineLogger
|
|
21
|
+
Logger: () => Logger
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(logger_exports);
|
|
25
|
-
var import_readline = require("readline");
|
|
26
24
|
var import_base_logger = require("./base-logger");
|
|
27
25
|
class Logger extends import_base_logger.BaseLogger {
|
|
28
26
|
static _previousLine;
|
|
29
27
|
// this is global to the whole process
|
|
30
28
|
print(message, props = {}) {
|
|
31
29
|
this.cleanup();
|
|
32
|
-
const stream = props.stderr ?
|
|
30
|
+
const stream = props.stderr ? "err" : "out";
|
|
33
31
|
const { prefix } = props;
|
|
34
32
|
if (prefix) {
|
|
35
33
|
this.render(`${prefix} ${message}
|
|
@@ -41,7 +39,7 @@ class Logger extends import_base_logger.BaseLogger {
|
|
|
41
39
|
}
|
|
42
40
|
line() {
|
|
43
41
|
this.cleanup();
|
|
44
|
-
const currentLine = new
|
|
42
|
+
const currentLine = new _SingleLineLogger({ ...this.opts });
|
|
45
43
|
Logger._previousLine = currentLine;
|
|
46
44
|
return currentLine;
|
|
47
45
|
}
|
|
@@ -52,35 +50,34 @@ class Logger extends import_base_logger.BaseLogger {
|
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
class
|
|
53
|
+
class _SingleLineLogger extends import_base_logger.BaseLogger {
|
|
56
54
|
_commited = false;
|
|
57
|
-
constructor(opts) {
|
|
58
|
-
super(opts);
|
|
59
|
-
}
|
|
60
55
|
commit() {
|
|
61
56
|
if (this._commited) {
|
|
62
57
|
return;
|
|
63
58
|
}
|
|
64
59
|
this._commited = true;
|
|
65
|
-
|
|
60
|
+
this.print("");
|
|
66
61
|
}
|
|
67
62
|
print(message, props = {}) {
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
let suffix;
|
|
64
|
+
if (!this._commited && this.opts.outStream.isTTY) {
|
|
65
|
+
this.opts.outStream.clearLine(0);
|
|
66
|
+
this.opts.outStream.cursorTo(0);
|
|
67
|
+
suffix = "";
|
|
68
|
+
} else {
|
|
69
|
+
suffix = "\n";
|
|
70
70
|
}
|
|
71
|
-
(0, import_readline.clearLine)(process.stdout, 0);
|
|
72
71
|
const { prefix } = props;
|
|
73
|
-
(0, import_readline.cursorTo)(process.stdout, 0);
|
|
74
72
|
if (prefix) {
|
|
75
|
-
this.render(`${prefix} ${message}`);
|
|
73
|
+
this.render(`${prefix} ${message}${suffix}`);
|
|
76
74
|
return;
|
|
77
75
|
}
|
|
78
|
-
this.render(message);
|
|
76
|
+
this.render(message + suffix);
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
79
|
// Annotate the CommonJS export names for ESM import in node:
|
|
82
80
|
0 && (module.exports = {
|
|
83
|
-
Logger
|
|
84
|
-
SingleLineLogger
|
|
81
|
+
Logger
|
|
85
82
|
});
|
|
86
83
|
//# sourceMappingURL=index.js.map
|
package/dist/logger/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/logger/index.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["import { BaseLogger, StreamType } from './base-logger'\n\nexport class Logger extends BaseLogger {\n private static _previousLine: _SingleLineLogger | undefined // this is global to the whole process\n\n protected print(message: string, props: Partial<{ prefix: string; stderr?: boolean }> = {}): void {\n this.cleanup()\n const stream: StreamType = props.stderr ? 'err' : 'out'\n const { prefix } = props\n if (prefix) {\n this.render(`${prefix} ${message}\\n`, stream)\n return\n }\n this.render(`${message}\\n`, stream)\n }\n\n public line(): _SingleLineLogger {\n this.cleanup()\n const currentLine = new _SingleLineLogger({ ...this.opts })\n Logger._previousLine = currentLine\n return currentLine\n }\n\n public cleanup(): void {\n if (Logger._previousLine) {\n Logger._previousLine.commit()\n Logger._previousLine = undefined\n }\n }\n}\n\n/**\n * Prints to a single line unless it is committed.\n * When committed or if the stream is not TTY, it prints normally using new lines.\n */\nclass _SingleLineLogger extends BaseLogger {\n private _commited = false\n\n public commit(): void {\n if (this._commited) {\n return\n }\n this._commited = true\n this.print('')\n }\n\n protected print(message: string, props: Partial<{ prefix: string }> = {}): void {\n let suffix: string\n if (!this._commited && this.opts.outStream.isTTY) {\n this.opts.outStream.clearLine(0)\n this.opts.outStream.cursorTo(0)\n suffix = ''\n } else {\n suffix = '\\n'\n }\n\n const { prefix } = props\n if (prefix) {\n this.render(`${prefix} ${message}${suffix}`)\n return\n }\n this.render(message + suffix)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAuC;AAEhC,MAAM,eAAe,8BAAW;AAAA,EACrC,OAAe;AA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FakeStream {
|
|
5
|
+
_lines = [];
|
|
6
|
+
_y = 0;
|
|
7
|
+
_x = 0;
|
|
8
|
+
static create() {
|
|
9
|
+
return new _FakeStream();
|
|
10
|
+
}
|
|
11
|
+
get _currentLine() {
|
|
12
|
+
return this._lines[this._y] || "";
|
|
13
|
+
}
|
|
14
|
+
set _currentLine(line) {
|
|
15
|
+
this._lines[this._y] = line;
|
|
16
|
+
}
|
|
17
|
+
get isTTY() {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
write(str) {
|
|
21
|
+
const tokens = str.toString().split(/(\n)/).filter(Boolean);
|
|
22
|
+
for (const token of tokens) {
|
|
23
|
+
if (token === "\n") {
|
|
24
|
+
this._y++;
|
|
25
|
+
this._currentLine = "";
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
this._currentLine = this._currentLine + token;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
clearLine(dir) {
|
|
33
|
+
if (dir === 0) {
|
|
34
|
+
this._currentLine = "";
|
|
35
|
+
} else if (dir === -1) {
|
|
36
|
+
const right = this._currentLine.slice(this._x);
|
|
37
|
+
this._currentLine = right;
|
|
38
|
+
} else {
|
|
39
|
+
const left = this._currentLine.slice(0, this._x);
|
|
40
|
+
this._currentLine = left;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
cursorTo(x, y) {
|
|
45
|
+
this._x = x;
|
|
46
|
+
this._y = typeof y === "number" ? y : this._y;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
get data() {
|
|
50
|
+
return this._lines.join("\n");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
(0, import_vitest.test)("logging with a prefix should write the prefix", () => {
|
|
54
|
+
const stream = _FakeStream.create();
|
|
55
|
+
const logger = new import__.Logger({ outStream: stream, errStream: stream });
|
|
56
|
+
logger.log("lol1", { prefix: "###" });
|
|
57
|
+
(0, import_vitest.expect)(stream.data).toEqual("### lol1\n");
|
|
58
|
+
});
|
|
59
|
+
(0, import_vitest.test)("logging a certain sequence of messages should write message in order", () => {
|
|
60
|
+
const stream = _FakeStream.create();
|
|
61
|
+
const logger = new import__.Logger({ outStream: stream, errStream: stream });
|
|
62
|
+
logger.log("lol1");
|
|
63
|
+
logger.log("lol2");
|
|
64
|
+
logger.log("lol3");
|
|
65
|
+
logger.log("lol4");
|
|
66
|
+
(0, import_vitest.expect)(stream.data).toEqual(`lol1
|
|
67
|
+
lol2
|
|
68
|
+
lol3
|
|
69
|
+
lol4
|
|
70
|
+
`);
|
|
71
|
+
});
|
|
72
|
+
(0, import_vitest.test)("logging on a single line should write message on a single line", () => {
|
|
73
|
+
const stream = _FakeStream.create();
|
|
74
|
+
const logger = new import__.Logger({ outStream: stream, errStream: stream }).line();
|
|
75
|
+
logger.log("lol1");
|
|
76
|
+
logger.log("lol2");
|
|
77
|
+
logger.log("lol3");
|
|
78
|
+
logger.log("lol4");
|
|
79
|
+
(0, import_vitest.expect)(stream.data).toEqual("lol4");
|
|
80
|
+
});
|
|
81
|
+
(0, import_vitest.test)("logging on a single line, then logging on multiple line should keep logging on next line", () => {
|
|
82
|
+
const stream = _FakeStream.create();
|
|
83
|
+
const logger = new import__.Logger({ outStream: stream, errStream: stream });
|
|
84
|
+
logger.log("lol1");
|
|
85
|
+
const line = logger.line();
|
|
86
|
+
line.log("lol2");
|
|
87
|
+
line.log("lol3");
|
|
88
|
+
logger.log("lol4");
|
|
89
|
+
line.log("lol5");
|
|
90
|
+
(0, import_vitest.expect)(stream.data).toEqual(`lol1
|
|
91
|
+
lol3
|
|
92
|
+
lol4
|
|
93
|
+
lol5
|
|
94
|
+
`);
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=logger.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/logger/logger.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { Logger } from '.'\nimport { test, expect } from 'vitest'\n\ntype _IFakeStream = Partial<NodeJS.WriteStream> & {\n data: string\n}\nclass _FakeStream implements _IFakeStream {\n private _lines: string[] = []\n private _y = 0\n private _x = 0\n\n public static create(): _IFakeStream {\n return new _FakeStream()\n }\n\n private get _currentLine(): string {\n return this._lines[this._y] || ''\n }\n\n private set _currentLine(line: string) {\n this._lines[this._y] = line\n }\n\n public get isTTY() {\n return true\n }\n\n public write(str: Uint8Array | string): boolean {\n const tokens: string[] = str.toString().split(/(\\n)/).filter(Boolean)\n\n for (const token of tokens) {\n if (token === '\\n') {\n this._y++\n this._currentLine = ''\n continue\n }\n this._currentLine = this._currentLine + token\n }\n\n return true\n }\n\n public clearLine(dir: -1 | 0 | 1) {\n if (dir === 0) {\n this._currentLine = ''\n } else if (dir === -1) {\n const right = this._currentLine.slice(this._x)\n this._currentLine = right\n } else {\n const left = this._currentLine.slice(0, this._x)\n this._currentLine = left\n }\n return true\n }\n\n public cursorTo(x: number, y?: number | Function): boolean {\n this._x = x\n this._y = typeof y === 'number' ? y : this._y\n return true\n }\n\n public get data(): string {\n return this._lines.join('\\n')\n }\n}\n\ntest('logging with a prefix should write the prefix', () => {\n const stream = _FakeStream.create()\n const logger = new Logger({ outStream: stream as NodeJS.WriteStream, errStream: stream as NodeJS.WriteStream })\n\n logger.log('lol1', { prefix: '###' })\n expect(stream.data).toEqual('### lol1\\n')\n})\n\ntest('logging a certain sequence of messages should write message in order', () => {\n const stream = _FakeStream.create()\n const logger = new Logger({ outStream: stream as NodeJS.WriteStream, errStream: stream as NodeJS.WriteStream })\n\n logger.log('lol1')\n logger.log('lol2')\n logger.log('lol3')\n logger.log('lol4')\n\n expect(stream.data).toEqual(`lol1\nlol2\nlol3\nlol4\n`)\n})\n\ntest('logging on a single line should write message on a single line', () => {\n const stream = _FakeStream.create()\n const logger = new Logger({ outStream: stream as NodeJS.WriteStream, errStream: stream as NodeJS.WriteStream }).line()\n logger.log('lol1')\n logger.log('lol2')\n logger.log('lol3')\n logger.log('lol4')\n\n expect(stream.data).toEqual('lol4')\n})\n\ntest('logging on a single line, then logging on multiple line should keep logging on next line', () => {\n const stream = _FakeStream.create()\n\n const logger = new Logger({ outStream: stream as NodeJS.WriteStream, errStream: stream as NodeJS.WriteStream })\n logger.log('lol1')\n\n const line = logger.line()\n line.log('lol2')\n line.log('lol3')\n logger.log('lol4')\n line.log('lol5')\n\n expect(stream.data).toEqual(`lol1\nlol3\nlol4\nlol5\n`)\n})\n"],
|
|
5
|
+
"mappings": ";AAAA,eAAuB;AACvB,oBAA6B;AAK7B,MAAM,YAAoC;AAAA,EAChC,SAAmB,CAAC;AAAA,EACpB,KAAK;AAAA,EACL,KAAK;AAAA,EAEb,OAAc,SAAuB;AACnC,WAAO,IAAI,YAAY;AAAA,EACzB;AAAA,EAEA,IAAY,eAAuB;AACjC,WAAO,KAAK,OAAO,KAAK,EAAE,KAAK;AAAA,EACjC;AAAA,EAEA,IAAY,aAAa,MAAc;AACrC,SAAK,OAAO,KAAK,EAAE,IAAI;AAAA,EACzB;AAAA,EAEA,IAAW,QAAQ;AACjB,WAAO;AAAA,EACT;AAAA,EAEO,MAAM,KAAmC;AAC9C,UAAM,SAAmB,IAAI,SAAS,EAAE,MAAM,MAAM,EAAE,OAAO,OAAO;AAEpE,eAAW,SAAS,QAAQ;AAC1B,UAAI,UAAU,MAAM;AAClB,aAAK;AACL,aAAK,eAAe;AACpB;AAAA,MACF;AACA,WAAK,eAAe,KAAK,eAAe;AAAA,IAC1C;AAEA,WAAO;AAAA,EACT;AAAA,EAEO,UAAU,KAAiB;AAChC,QAAI,QAAQ,GAAG;AACb,WAAK,eAAe;AAAA,IACtB,WAAW,QAAQ,IAAI;AACrB,YAAM,QAAQ,KAAK,aAAa,MAAM,KAAK,EAAE;AAC7C,WAAK,eAAe;AAAA,IACtB,OAAO;AACL,YAAM,OAAO,KAAK,aAAa,MAAM,GAAG,KAAK,EAAE;AAC/C,WAAK,eAAe;AAAA,IAC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AAM;AAEjB,QAAM,OAAO,OAAO,KAAK;AACzB,OAAK,IAAI,MAAM;AACf,OAAK,IAAI,MAAM;AACf,SAAO,IAAI,MAAM;AACjB,OAAK,IAAI,MAAM;AAEf,4BAAO,OAAO,IAAI,EAAE,QAAQ;AAAA;AAAA;AAAA;AAAA,CAI7B;AACD,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"description": "Botpress CLI",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "pnpm run bundle && pnpm run template:gen",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@apidevtools/json-schema-ref-parser": "^11.7.0",
|
|
23
23
|
"@botpress/chat": "0.5.1",
|
|
24
24
|
"@botpress/client": "0.48.0",
|
|
25
|
-
"@botpress/sdk": "3.
|
|
25
|
+
"@botpress/sdk": "3.6.0",
|
|
26
26
|
"@bpinternal/const": "^0.1.0",
|
|
27
27
|
"@bpinternal/tunnel": "^0.1.1",
|
|
28
28
|
"@bpinternal/yargs-extra": "^0.0.3",
|
|
@@ -37,9 +37,18 @@ export type EventHandlers = Required<{
|
|
|
37
37
|
export type MessageHandlers = Required<{
|
|
38
38
|
[K in keyof BotHandlers['messageHandlers']]: NonNullable<BotHandlers['messageHandlers'][K]>[number]
|
|
39
39
|
}>
|
|
40
|
+
export type WorkflowHandlers = {
|
|
41
|
+
[TWorkflowName in keyof Required<BotHandlers['workflowHandlers'][keyof BotHandlers['workflowHandlers']]>]:
|
|
42
|
+
Required<BotHandlers['workflowHandlers'][keyof BotHandlers['workflowHandlers']]>[TWorkflowName] extends
|
|
43
|
+
({ handler: infer U })[] ? U : never
|
|
44
|
+
}
|
|
40
45
|
|
|
41
46
|
export type MessageHandlerProps = Parameters<MessageHandlers['*']>[0]
|
|
42
47
|
export type EventHandlerProps = Parameters<EventHandlers['*']>[0]
|
|
48
|
+
export type WorkflowHandlerProps = {
|
|
49
|
+
[TWorkflowName in keyof WorkflowHandlers]: WorkflowHandlers[TWorkflowName] extends
|
|
50
|
+
(..._: infer U) => any ? U[0] : never
|
|
51
|
+
}
|
|
43
52
|
|
|
44
53
|
export type Client = (MessageHandlerProps | EventHandlerProps)['client']
|
|
45
54
|
export type ClientOperation = keyof {
|
|
@@ -31,6 +31,11 @@ export type HookHandlers = Required<{
|
|
|
31
31
|
[K in keyof PluginHandlers['hookHandlers'][H]]: NonNullable<PluginHandlers['hookHandlers'][H][K]>[number]
|
|
32
32
|
}>
|
|
33
33
|
}>
|
|
34
|
+
export type WorkflowHandlers = {
|
|
35
|
+
[TWorkflowName in keyof Required<PluginHandlers['workflowHandlers'][keyof PluginHandlers['workflowHandlers']]>]:
|
|
36
|
+
Required<PluginHandlers['workflowHandlers'][keyof PluginHandlers['workflowHandlers']]>[TWorkflowName] extends
|
|
37
|
+
({ handler: infer U })[] ? U : never
|
|
38
|
+
}
|
|
34
39
|
|
|
35
40
|
export type AnyMessageHandler = MessageHandlers['*']
|
|
36
41
|
export type AnyEventHandler = EventHandlers['*']
|
|
@@ -45,6 +50,10 @@ export type ActionHandlerProps = Parameters<AnyActionHandler>[0]
|
|
|
45
50
|
export type HookHandlerProps = {
|
|
46
51
|
[H in keyof AnyHookHanders]: Parameters<NonNullable<AnyHookHanders[H]>>[0]
|
|
47
52
|
}
|
|
53
|
+
export type WorkflowHandlerProps = {
|
|
54
|
+
[TWorkflowName in keyof WorkflowHandlers]: WorkflowHandlers[TWorkflowName] extends
|
|
55
|
+
(..._: infer U) => any ? U[0] : never
|
|
56
|
+
}
|
|
48
57
|
|
|
49
58
|
export type Client = (MessageHandlerProps | EventHandlerProps)['client']
|
|
50
59
|
export type ClientOperation = keyof {
|