@botpress/cli 0.11.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +9 -9
- package/dist/api/bot-body.js.map +2 -2
- package/dist/api/client.js +14 -28
- package/dist/api/client.js.map +3 -3
- package/dist/api/find-previous-version.js.map +1 -1
- package/dist/api/index.js +23 -0
- package/dist/api/index.js.map +7 -0
- package/dist/api/interface-body.js +25 -10
- package/dist/api/interface-body.js.map +2 -2
- package/dist/code-generation/bot-implementation/bot-implementation.js +92 -0
- package/dist/code-generation/bot-implementation/bot-implementation.js.map +7 -0
- package/dist/code-generation/{integration-schemas → bot-implementation/bot-typings}/events-module.js +15 -22
- package/dist/code-generation/bot-implementation/bot-typings/events-module.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-typings/index.js +96 -0
- package/dist/code-generation/bot-implementation/bot-typings/index.js.map +7 -0
- package/dist/code-generation/{integration-schemas → bot-implementation/bot-typings}/states-module.js +17 -22
- package/dist/code-generation/bot-implementation/bot-typings/states-module.js.map +7 -0
- package/dist/code-generation/bot-implementation/index.js +56 -0
- package/dist/code-generation/bot-implementation/index.js.map +7 -0
- package/dist/code-generation/{const.js → consts.js} +9 -4
- package/dist/code-generation/consts.js.map +7 -0
- package/dist/code-generation/generators.js +37 -7
- package/dist/code-generation/generators.js.map +2 -2
- package/dist/code-generation/index.js +15 -105
- package/dist/code-generation/index.js.map +3 -3
- package/dist/code-generation/integration-implementation/index.js +66 -0
- package/dist/code-generation/integration-implementation/index.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-implementation.js +110 -0
- package/dist/code-generation/integration-implementation/integration-implementation.js.map +7 -0
- package/dist/code-generation/{integration-secret.js → integration-implementation/integration-secret.js} +17 -7
- package/dist/code-generation/integration-implementation/integration-secret.js.map +7 -0
- package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/actions-module.js +28 -40
- package/dist/code-generation/integration-implementation/integration-typings/actions-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/channels-module.js +103 -0
- package/dist/code-generation/integration-implementation/integration-typings/channels-module.js.map +7 -0
- package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/configuration-module.js +18 -20
- package/dist/code-generation/integration-implementation/integration-typings/configuration-module.js.map +7 -0
- package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/configurations-module.js +21 -27
- package/dist/code-generation/integration-implementation/integration-typings/configurations-module.js.map +7 -0
- package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/entities-module.js +15 -22
- package/dist/code-generation/integration-implementation/integration-typings/entities-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/events-module.js +59 -0
- package/dist/code-generation/integration-implementation/integration-typings/events-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/index.js +128 -0
- package/dist/code-generation/integration-implementation/integration-typings/index.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/states-module.js +60 -0
- package/dist/code-generation/integration-implementation/integration-typings/states-module.js.map +7 -0
- package/dist/code-generation/integration-package/index.js +81 -0
- package/dist/code-generation/integration-package/index.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/actions-module.js +84 -0
- package/dist/code-generation/integration-package/integration-package-definition/actions-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/channels-module.js +103 -0
- package/dist/code-generation/integration-package/integration-package-definition/channels-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/configuration-module.js +58 -0
- package/dist/code-generation/integration-package/integration-package-definition/configuration-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/configurations-module.js +66 -0
- package/dist/code-generation/integration-package/integration-package-definition/configurations-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/entities-module.js +59 -0
- package/dist/code-generation/integration-package/integration-package-definition/entities-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/events-module.js +62 -0
- package/dist/code-generation/integration-package/integration-package-definition/events-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/index.js +136 -0
- package/dist/code-generation/integration-package/integration-package-definition/index.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/states-module.js +62 -0
- package/dist/code-generation/integration-package/integration-package-definition/states-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/typings.js +17 -0
- package/dist/code-generation/integration-package/integration-package-definition/typings.js.map +7 -0
- package/dist/code-generation/interface-package/index.js +81 -0
- package/dist/code-generation/interface-package/index.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/actions-module.js +84 -0
- package/dist/code-generation/interface-package/interface-package-definition/actions-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/channels-module.js +94 -0
- package/dist/code-generation/interface-package/interface-package-definition/channels-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/entities-module.js +59 -0
- package/dist/code-generation/interface-package/interface-package-definition/entities-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/events-module.js +62 -0
- package/dist/code-generation/interface-package/interface-package-definition/events-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/index.js +100 -0
- package/dist/code-generation/interface-package/interface-package-definition/index.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/typings.js +17 -0
- package/dist/code-generation/interface-package/interface-package-definition/typings.js.map +7 -0
- package/dist/code-generation/module.js +60 -16
- package/dist/code-generation/module.js.map +2 -2
- package/dist/code-generation/strings.js +5 -2
- package/dist/code-generation/strings.js.map +2 -2
- package/dist/code-generation/typings.js.map +1 -1
- package/dist/command-implementations/add-command.js +102 -91
- package/dist/command-implementations/add-command.js.map +3 -3
- package/dist/command-implementations/bundle-command.js +16 -9
- package/dist/command-implementations/bundle-command.js.map +2 -2
- package/dist/command-implementations/deploy-command.js +27 -19
- package/dist/command-implementations/deploy-command.js.map +2 -2
- package/dist/command-implementations/dev-command.js +15 -12
- package/dist/command-implementations/dev-command.js.map +2 -2
- package/dist/command-implementations/gen-command.js +31 -12
- package/dist/command-implementations/gen-command.js.map +3 -3
- package/dist/command-implementations/init-command.js +2 -2
- package/dist/command-implementations/init-command.js.map +2 -2
- package/dist/command-implementations/integration-commands.js +5 -5
- package/dist/command-implementations/integration-commands.js.map +2 -2
- package/dist/command-implementations/interface-commands.js +5 -5
- package/dist/command-implementations/interface-commands.js.map +2 -2
- package/dist/command-implementations/lint-command.js +3 -1
- package/dist/command-implementations/lint-command.js.map +3 -3
- package/dist/command-implementations/project-command.js +40 -23
- package/dist/command-implementations/project-command.js.map +3 -3
- package/dist/command-implementations/read-command.js +0 -5
- package/dist/command-implementations/read-command.js.map +2 -2
- package/dist/config.js +22 -7
- package/dist/config.js.map +2 -2
- package/dist/consts.js +15 -6
- package/dist/consts.js.map +2 -2
- package/dist/errors.js +19 -11
- package/dist/errors.js.map +2 -2
- package/dist/logger/index.js +4 -2
- package/dist/logger/index.js.map +2 -2
- package/dist/{integration-ref.js → package-ref.js} +11 -11
- package/dist/package-ref.js.map +7 -0
- package/dist/{integration-ref.test.js → package-ref.test.js} +18 -18
- package/dist/package-ref.test.js.map +7 -0
- package/dist/sdk/index.js +21 -0
- package/dist/sdk/index.js.map +7 -0
- package/dist/sdk/resolve-bot-interfaces.js +38 -0
- package/dist/sdk/resolve-bot-interfaces.js.map +7 -0
- package/dist/sdk/resolve-integration-interfaces.js +148 -0
- package/dist/sdk/resolve-integration-interfaces.js.map +7 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +2 -2
- package/dist/utils/path-utils.js +25 -8
- package/dist/utils/path-utils.js.map +3 -3
- package/dist/utils/path-utils.test.js +69 -0
- package/dist/utils/path-utils.test.js.map +7 -0
- package/dist/utils/record-utils.js +25 -0
- package/dist/utils/record-utils.js.map +3 -3
- package/dist/utils/schema-utils.js +11 -0
- package/dist/utils/schema-utils.js.map +2 -2
- package/dist/utils/schema-utils.test.js +51 -0
- package/dist/utils/schema-utils.test.js.map +7 -0
- package/dist/utils/template-utils.js +47 -0
- package/dist/utils/template-utils.js.map +7 -0
- package/dist/utils/type-utils.js.map +1 -1
- package/e2e/index.ts +2 -0
- package/e2e/tests/install-package.ts +163 -0
- package/e2e/utils.ts +25 -2
- package/package.json +5 -4
- package/templates/empty-bot/.botpress/implementation/index.ts +41 -0
- package/templates/empty-bot/.botpress/implementation/typings/index.ts +17 -0
- package/templates/empty-bot/.botpress/implementation/typings/integrations/index.ts +6 -0
- package/templates/empty-bot/.botpress/index.ts +1 -0
- package/templates/empty-bot/bot.definition.ts +2 -0
- package/templates/{echo-bot → empty-bot}/package.json +2 -2
- package/templates/empty-bot/src/index.ts +5 -0
- package/templates/empty-integration/.botpress/implementation/index.ts +7 -35
- package/templates/empty-integration/.botpress/implementation/typings/configuration/index.ts +2 -0
- package/templates/empty-integration/.botpress/implementation/typings/index.ts +31 -0
- package/templates/empty-integration/package.json +1 -1
- package/templates/hello-world/.botpress/implementation/index.ts +7 -35
- package/templates/hello-world/.botpress/implementation/typings/actions/helloWorld/input.ts +5 -0
- package/templates/hello-world/.botpress/implementation/typings/actions/helloWorld/output.ts +5 -0
- package/templates/hello-world/.botpress/implementation/typings/configuration/index.ts +2 -0
- package/templates/hello-world/.botpress/implementation/typings/index.ts +31 -0
- package/templates/hello-world/package.json +1 -1
- package/templates/webhook-message/.botpress/implementation/index.ts +7 -35
- package/templates/webhook-message/.botpress/implementation/typings/channels/webhook/messages/text.ts +5 -0
- package/templates/webhook-message/.botpress/implementation/typings/configuration/index.ts +8 -0
- package/templates/webhook-message/.botpress/implementation/typings/events/index.ts +6 -0
- package/templates/webhook-message/.botpress/implementation/typings/index.ts +31 -0
- package/templates/webhook-message/.botpress/implementation/typings/states/index.ts +6 -0
- package/templates/webhook-message/package.json +1 -1
- package/dist/code-generation/const.js.map +0 -7
- package/dist/code-generation/integration-implementation.js +0 -192
- package/dist/code-generation/integration-implementation.js.map +0 -7
- package/dist/code-generation/integration-instance.js +0 -185
- package/dist/code-generation/integration-instance.js.map +0 -7
- package/dist/code-generation/integration-schemas/actions-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/channels-module.js +0 -117
- package/dist/code-generation/integration-schemas/channels-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/configuration-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/configurations-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/entities-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/events-module.js.map +0 -7
- package/dist/code-generation/integration-schemas/states-module.js.map +0 -7
- package/dist/code-generation/integration-secret.js.map +0 -7
- package/dist/code-generation/map-integration.js +0 -76
- package/dist/code-generation/map-integration.js.map +0 -7
- package/dist/integration-ref.js.map +0 -7
- package/dist/integration-ref.test.js.map +0 -7
- package/templates/echo-bot/src/index.ts +0 -30
- package/templates/empty-integration/.botpress/implementation/configuration/index.ts +0 -10
- package/templates/hello-world/.botpress/implementation/actions/helloWorld/input.ts +0 -10
- package/templates/hello-world/.botpress/implementation/actions/helloWorld/output.ts +0 -10
- package/templates/hello-world/.botpress/implementation/configuration/index.ts +0 -10
- package/templates/webhook-message/.botpress/implementation/channels/webhook/messages/text.ts +0 -10
- package/templates/webhook-message/.botpress/implementation/configuration/index.ts +0 -13
- /package/templates/{empty-integration/.botpress/implementation → empty-bot/.botpress/implementation/typings}/events/index.ts +0 -0
- /package/templates/{empty-integration/.botpress/implementation → empty-bot/.botpress/implementation/typings}/states/index.ts +0 -0
- /package/templates/{echo-bot → empty-bot}/tsconfig.json +0 -0
- /package/templates/empty-integration/.botpress/implementation/{actions → typings/actions}/index.ts +0 -0
- /package/templates/empty-integration/.botpress/implementation/{channels → typings/channels}/index.ts +0 -0
- /package/templates/empty-integration/.botpress/implementation/{configurations → typings/configurations}/index.ts +0 -0
- /package/templates/empty-integration/.botpress/implementation/{entities → typings/entities}/index.ts +0 -0
- /package/templates/{hello-world/.botpress/implementation → empty-integration/.botpress/implementation/typings}/events/index.ts +0 -0
- /package/templates/{hello-world/.botpress/implementation → empty-integration/.botpress/implementation/typings}/states/index.ts +0 -0
- /package/templates/hello-world/.botpress/implementation/{actions → typings/actions}/helloWorld/index.ts +0 -0
- /package/templates/hello-world/.botpress/implementation/{actions → typings/actions}/index.ts +0 -0
- /package/templates/hello-world/.botpress/implementation/{channels → typings/channels}/index.ts +0 -0
- /package/templates/hello-world/.botpress/implementation/{configurations → typings/configurations}/index.ts +0 -0
- /package/templates/hello-world/.botpress/implementation/{entities → typings/entities}/index.ts +0 -0
- /package/templates/{webhook-message/.botpress/implementation → hello-world/.botpress/implementation/typings}/events/index.ts +0 -0
- /package/templates/{webhook-message/.botpress/implementation → hello-world/.botpress/implementation/typings}/states/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{actions → typings/actions}/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{channels → typings/channels}/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{channels → typings/channels}/webhook/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{channels → typings/channels}/webhook/messages/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{configurations → typings/configurations}/index.ts +0 -0
- /package/templates/webhook-message/.botpress/implementation/{entities → typings/entities}/index.ts +0 -0
package/dist/utils/path-utils.js
CHANGED
|
@@ -27,19 +27,34 @@ __export(path_utils_exports, {
|
|
|
27
27
|
PathStore: () => PathStore,
|
|
28
28
|
absoluteFrom: () => absoluteFrom,
|
|
29
29
|
cwd: () => cwd,
|
|
30
|
-
|
|
30
|
+
isAbsolutePath: () => isAbsolutePath,
|
|
31
31
|
isPath: () => isPath,
|
|
32
32
|
join: () => join,
|
|
33
|
+
posix: () => posix,
|
|
33
34
|
relativeFrom: () => relativeFrom,
|
|
34
35
|
rmExtension: () => rmExtension,
|
|
35
|
-
toUnix: () => toUnix
|
|
36
|
+
toUnix: () => toUnix,
|
|
37
|
+
win32: () => win32
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(path_utils_exports);
|
|
38
40
|
var import_lodash = __toESM(require("lodash"));
|
|
41
|
+
var import_os = __toESM(require("os"));
|
|
39
42
|
var import_path = __toESM(require("path"));
|
|
43
|
+
var posix;
|
|
44
|
+
((posix2) => {
|
|
45
|
+
posix2.isPath = (path) => posix2.isAbsolutePath(path) || posix2.isRelativePath(path);
|
|
46
|
+
posix2.isRelativePath = (path) => path.startsWith("./") || path.startsWith("../");
|
|
47
|
+
posix2.isAbsolutePath = (path) => import_path.default.posix.isAbsolute(path);
|
|
48
|
+
})(posix || (posix = {}));
|
|
49
|
+
var win32;
|
|
50
|
+
((win322) => {
|
|
51
|
+
win322.isPath = (path) => win322.isAbsolutePath(path) || win322.isRelativePath(path);
|
|
52
|
+
win322.isRelativePath = (path) => path.startsWith(".\\") || path.startsWith("..\\");
|
|
53
|
+
win322.isAbsolutePath = (path) => /^[a-zA-Z]:\\/.test(path);
|
|
54
|
+
})(win32 || (win32 = {}));
|
|
55
|
+
const isPath = (path) => import_os.default.platform() === "win32" ? win32.isPath(path) : posix.isPath(path);
|
|
56
|
+
const isAbsolutePath = (path) => import_os.default.platform() === "win32" ? win32.isAbsolutePath(path) : posix.isAbsolutePath(path);
|
|
40
57
|
const cwd = () => process.cwd();
|
|
41
|
-
const isAbsolute = (path) => import_path.default.isAbsolute(path);
|
|
42
|
-
const isPath = (path) => isAbsolute(path) || path.startsWith(".");
|
|
43
58
|
const join = (abs, ...paths) => {
|
|
44
59
|
const joined = import_path.default.join(abs, ...paths);
|
|
45
60
|
return import_path.default.normalize(joined);
|
|
@@ -47,14 +62,14 @@ const join = (abs, ...paths) => {
|
|
|
47
62
|
const rmExtension = (filename) => filename.replace(/\.[^/.]+$/, "");
|
|
48
63
|
const toUnix = (path) => path.split(import_path.default.sep).join(import_path.default.posix.sep);
|
|
49
64
|
const absoluteFrom = (rootdir, target) => {
|
|
50
|
-
if (
|
|
65
|
+
if (isAbsolutePath(target)) {
|
|
51
66
|
return target;
|
|
52
67
|
}
|
|
53
68
|
return import_path.default.join(rootdir, target);
|
|
54
69
|
};
|
|
55
70
|
const relativeFrom = (rootdir, target) => {
|
|
56
71
|
let absPath;
|
|
57
|
-
if (
|
|
72
|
+
if (isAbsolutePath(target)) {
|
|
58
73
|
absPath = target;
|
|
59
74
|
} else {
|
|
60
75
|
absPath = import_path.default.resolve(import_path.default.join(rootdir, target));
|
|
@@ -74,11 +89,13 @@ class PathStore {
|
|
|
74
89
|
PathStore,
|
|
75
90
|
absoluteFrom,
|
|
76
91
|
cwd,
|
|
77
|
-
|
|
92
|
+
isAbsolutePath,
|
|
78
93
|
isPath,
|
|
79
94
|
join,
|
|
95
|
+
posix,
|
|
80
96
|
relativeFrom,
|
|
81
97
|
rmExtension,
|
|
82
|
-
toUnix
|
|
98
|
+
toUnix,
|
|
99
|
+
win32
|
|
83
100
|
});
|
|
84
101
|
//# sourceMappingURL=path-utils.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/path-utils.ts"],
|
|
4
|
-
"sourcesContent": ["import _ from 'lodash'\nimport pathlib from 'path'\n\nexport type AbsolutePath = `/${string}
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAc;AACd,kBAAoB;
|
|
6
|
-
"names": ["pathlib", "_"]
|
|
4
|
+
"sourcesContent": ["import _ from 'lodash'\nimport oslib from 'os'\nimport pathlib from 'path'\n\nexport namespace posix {\n export type AbsolutePath = `/${string}`\n export const isPath = (path: string) => isAbsolutePath(path) || isRelativePath(path)\n export const isRelativePath = (path: string) => path.startsWith('./') || path.startsWith('../')\n export const isAbsolutePath = (path: string): path is AbsolutePath => pathlib.posix.isAbsolute(path)\n}\n\nexport namespace win32 {\n export type AbsolutePath = `${string}:\\\\${string}` // C:\\path\n export const isPath = (path: string) => isAbsolutePath(path) || isRelativePath(path)\n export const isRelativePath = (path: string) => path.startsWith('.\\\\') || path.startsWith('..\\\\')\n export const isAbsolutePath = (path: string): path is AbsolutePath => /^[a-zA-Z]:\\\\/.test(path) // bp cli does not allow omitting the drive letter\n}\n\nexport type AbsolutePath = posix.AbsolutePath | win32.AbsolutePath\nexport const isPath = (path: string) => (oslib.platform() === 'win32' ? win32.isPath(path) : posix.isPath(path))\nexport const isAbsolutePath = (path: string): path is AbsolutePath =>\n oslib.platform() === 'win32' ? win32.isAbsolutePath(path) : posix.isAbsolutePath(path)\n\nexport const cwd = (): AbsolutePath => process.cwd() as AbsolutePath\nexport const join = (abs: AbsolutePath, ...paths: string[]): AbsolutePath => {\n const joined = pathlib.join(abs, ...paths)\n return pathlib.normalize(joined) as AbsolutePath\n}\n\nexport const rmExtension = (filename: string) => filename.replace(/\\.[^/.]+$/, '')\n\nexport const toUnix = (path: string) => path.split(pathlib.sep).join(pathlib.posix.sep)\n\nexport const absoluteFrom = (rootdir: AbsolutePath, target: string): AbsolutePath => {\n if (isAbsolutePath(target)) {\n return target\n }\n return pathlib.join(rootdir, target) as AbsolutePath\n}\n\nexport const relativeFrom = (rootdir: AbsolutePath, target: string) => {\n let absPath: string\n\n if (isAbsolutePath(target)) {\n absPath = target\n } else {\n absPath = pathlib.resolve(pathlib.join(rootdir, target))\n }\n\n return pathlib.relative(rootdir, absPath)\n}\n\nexport class PathStore<P extends string> {\n public constructor(public readonly abs: Record<P, AbsolutePath>) {}\n public rel(from: Extract<P, `${string}Dir`>) {\n return _.mapValues(this.abs, (to) => relativeFrom(this.abs[from], to))\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAc;AACd,gBAAkB;AAClB,kBAAoB;AAEb,IAAU;AAAA,CAAV,CAAUA,WAAV;AAEE,EAAMA,OAAA,SAAS,CAAC,SAAiBA,OAAA,eAAe,IAAI,KAAKA,OAAA,eAAe,IAAI;AAC5E,EAAMA,OAAA,iBAAiB,CAAC,SAAiB,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK;AACvF,EAAMA,OAAA,iBAAiB,CAAC,SAAuC,YAAAC,QAAQ,MAAM,WAAW,IAAI;AAAA,GAJpF;AAOV,IAAU;AAAA,CAAV,CAAUC,WAAV;AAEE,EAAMA,OAAA,SAAS,CAAC,SAAiBA,OAAA,eAAe,IAAI,KAAKA,OAAA,eAAe,IAAI;AAC5E,EAAMA,OAAA,iBAAiB,CAAC,SAAiB,KAAK,WAAW,KAAK,KAAK,KAAK,WAAW,MAAM;AACzF,EAAMA,OAAA,iBAAiB,CAAC,SAAuC,eAAe,KAAK,IAAI;AAAA,GAJ/E;AAQV,MAAM,SAAS,CAAC,SAAkB,UAAAC,QAAM,SAAS,MAAM,UAAU,MAAM,OAAO,IAAI,IAAI,MAAM,OAAO,IAAI;AACvG,MAAM,iBAAiB,CAAC,SAC7B,UAAAA,QAAM,SAAS,MAAM,UAAU,MAAM,eAAe,IAAI,IAAI,MAAM,eAAe,IAAI;AAEhF,MAAM,MAAM,MAAoB,QAAQ,IAAI;AAC5C,MAAM,OAAO,CAAC,QAAsB,UAAkC;AAC3E,QAAM,SAAS,YAAAF,QAAQ,KAAK,KAAK,GAAG,KAAK;AACzC,SAAO,YAAAA,QAAQ,UAAU,MAAM;AACjC;AAEO,MAAM,cAAc,CAAC,aAAqB,SAAS,QAAQ,aAAa,EAAE;AAE1E,MAAM,SAAS,CAAC,SAAiB,KAAK,MAAM,YAAAA,QAAQ,GAAG,EAAE,KAAK,YAAAA,QAAQ,MAAM,GAAG;AAE/E,MAAM,eAAe,CAAC,SAAuB,WAAiC;AACnF,MAAI,eAAe,MAAM,GAAG;AAC1B,WAAO;AAAA,EACT;AACA,SAAO,YAAAA,QAAQ,KAAK,SAAS,MAAM;AACrC;AAEO,MAAM,eAAe,CAAC,SAAuB,WAAmB;AACrE,MAAI;AAEJ,MAAI,eAAe,MAAM,GAAG;AAC1B,cAAU;AAAA,EACZ,OAAO;AACL,cAAU,YAAAA,QAAQ,QAAQ,YAAAA,QAAQ,KAAK,SAAS,MAAM,CAAC;AAAA,EACzD;AAEA,SAAO,YAAAA,QAAQ,SAAS,SAAS,OAAO;AAC1C;AAEO,MAAM,UAA4B;AAAA,EAChC,YAA4B,KAA8B;AAA9B;AAAA,EAA+B;AAAA,EAC3D,IAAI,MAAkC;AAC3C,WAAO,cAAAG,QAAE,UAAU,KAAK,KAAK,CAAC,OAAO,aAAa,KAAK,IAAI,OAAO,EAAE,CAAC;AAAA,EACvE;AACF;",
|
|
6
|
+
"names": ["posix", "pathlib", "win32", "oslib", "_"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
|
+
mod
|
|
19
|
+
));
|
|
20
|
+
var import_node_test = require("node:test");
|
|
21
|
+
var import_vitest = require("vitest");
|
|
22
|
+
var pathUtils = __toESM(require("./path-utils"));
|
|
23
|
+
(0, import_node_test.describe)("posix", () => {
|
|
24
|
+
(0, import_vitest.test)("isPath with valid relative path should return true", () => {
|
|
25
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("./src")).toBe(true);
|
|
26
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("../src")).toBe(true);
|
|
27
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("./src/services")).toBe(true);
|
|
28
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("./src/services/index.ts")).toBe(true);
|
|
29
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("./.././.././../lol.json")).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
(0, import_vitest.test)("isPath with valid absolute path should return true", () => {
|
|
32
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("/src")).toBe(true);
|
|
33
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("/src")).toBe(true);
|
|
34
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("/src/services")).toBe(true);
|
|
35
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("/src/services/index.ts")).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
(0, import_vitest.test)("isPath with invalid path should return false", () => {
|
|
38
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("src")).toBe(false);
|
|
39
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath(".src")).toBe(false);
|
|
40
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("..src")).toBe(false);
|
|
41
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("src/services")).toBe(false);
|
|
42
|
+
(0, import_vitest.expect)(pathUtils.posix.isPath("src/services/index.ts")).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
(0, import_node_test.describe)("win32", () => {
|
|
46
|
+
(0, import_vitest.test)("isPath with valid relative path should return true", () => {
|
|
47
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath(".\\src")).toBe(true);
|
|
48
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("..\\src")).toBe(true);
|
|
49
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath(".\\src\\services")).toBe(true);
|
|
50
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath(".\\src\\services\\index.ts")).toBe(true);
|
|
51
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath(".\\..\\.\\..\\.\\..\\lol.json")).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
(0, import_vitest.test)("isPath with valid absolute path should return true", () => {
|
|
54
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("C:\\src")).toBe(true);
|
|
55
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("C:\\src")).toBe(true);
|
|
56
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("C:\\src\\services")).toBe(true);
|
|
57
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("C:\\src\\services\\index.ts")).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
(0, import_vitest.test)("isPath with invalid path should return false", () => {
|
|
60
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("src")).toBe(false);
|
|
61
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath(".src")).toBe(false);
|
|
62
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("..src")).toBe(false);
|
|
63
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("src\\services")).toBe(false);
|
|
64
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("src\\services\\index.ts")).toBe(false);
|
|
65
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("\\services")).toBe(false);
|
|
66
|
+
(0, import_vitest.expect)(pathUtils.win32.isPath("\\services\\index.ts")).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=path-utils.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/path-utils.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe } from 'node:test'\nimport { test, expect } from 'vitest'\nimport * as pathUtils from './path-utils'\n\ndescribe('posix', () => {\n test('isPath with valid relative path should return true', () => {\n expect(pathUtils.posix.isPath('./src')).toBe(true)\n expect(pathUtils.posix.isPath('../src')).toBe(true)\n expect(pathUtils.posix.isPath('./src/services')).toBe(true)\n expect(pathUtils.posix.isPath('./src/services/index.ts')).toBe(true)\n expect(pathUtils.posix.isPath('./.././.././../lol.json')).toBe(true)\n })\n\n test('isPath with valid absolute path should return true', () => {\n expect(pathUtils.posix.isPath('/src')).toBe(true)\n expect(pathUtils.posix.isPath('/src')).toBe(true)\n expect(pathUtils.posix.isPath('/src/services')).toBe(true)\n expect(pathUtils.posix.isPath('/src/services/index.ts')).toBe(true)\n })\n\n test('isPath with invalid path should return false', () => {\n // these are technically valid posix paths, but not for the bp cli\n expect(pathUtils.posix.isPath('src')).toBe(false)\n expect(pathUtils.posix.isPath('.src')).toBe(false)\n expect(pathUtils.posix.isPath('..src')).toBe(false)\n expect(pathUtils.posix.isPath('src/services')).toBe(false)\n expect(pathUtils.posix.isPath('src/services/index.ts')).toBe(false)\n })\n})\n\ndescribe('win32', () => {\n test('isPath with valid relative path should return true', () => {\n expect(pathUtils.win32.isPath('.\\\\src')).toBe(true)\n expect(pathUtils.win32.isPath('..\\\\src')).toBe(true)\n expect(pathUtils.win32.isPath('.\\\\src\\\\services')).toBe(true)\n expect(pathUtils.win32.isPath('.\\\\src\\\\services\\\\index.ts')).toBe(true)\n expect(pathUtils.win32.isPath('.\\\\..\\\\.\\\\..\\\\.\\\\..\\\\lol.json')).toBe(true)\n })\n\n test('isPath with valid absolute path should return true', () => {\n expect(pathUtils.win32.isPath('C:\\\\src')).toBe(true)\n expect(pathUtils.win32.isPath('C:\\\\src')).toBe(true)\n expect(pathUtils.win32.isPath('C:\\\\src\\\\services')).toBe(true)\n expect(pathUtils.win32.isPath('C:\\\\src\\\\services\\\\index.ts')).toBe(true)\n })\n\n test('isPath with invalid path should return false', () => {\n // these are technically valid win32 paths, but not for the bp cli\n expect(pathUtils.win32.isPath('src')).toBe(false)\n expect(pathUtils.win32.isPath('.src')).toBe(false)\n expect(pathUtils.win32.isPath('..src')).toBe(false)\n expect(pathUtils.win32.isPath('src\\\\services')).toBe(false)\n expect(pathUtils.win32.isPath('src\\\\services\\\\index.ts')).toBe(false)\n expect(pathUtils.win32.isPath('\\\\services')).toBe(false)\n expect(pathUtils.win32.isPath('\\\\services\\\\index.ts')).toBe(false)\n })\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA,uBAAyB;AACzB,oBAA6B;AAC7B,gBAA2B;AAAA,IAE3B,2BAAS,SAAS,MAAM;AACtB,0BAAK,sDAAsD,MAAM;AAC/D,8BAAO,UAAU,MAAM,OAAO,OAAO,CAAC,EAAE,KAAK,IAAI;AACjD,8BAAO,UAAU,MAAM,OAAO,QAAQ,CAAC,EAAE,KAAK,IAAI;AAClD,8BAAO,UAAU,MAAM,OAAO,gBAAgB,CAAC,EAAE,KAAK,IAAI;AAC1D,8BAAO,UAAU,MAAM,OAAO,yBAAyB,CAAC,EAAE,KAAK,IAAI;AACnE,8BAAO,UAAU,MAAM,OAAO,yBAAyB,CAAC,EAAE,KAAK,IAAI;AAAA,EACrE,CAAC;AAED,0BAAK,sDAAsD,MAAM;AAC/D,8BAAO,UAAU,MAAM,OAAO,MAAM,CAAC,EAAE,KAAK,IAAI;AAChD,8BAAO,UAAU,MAAM,OAAO,MAAM,CAAC,EAAE,KAAK,IAAI;AAChD,8BAAO,UAAU,MAAM,OAAO,eAAe,CAAC,EAAE,KAAK,IAAI;AACzD,8BAAO,UAAU,MAAM,OAAO,wBAAwB,CAAC,EAAE,KAAK,IAAI;AAAA,EACpE,CAAC;AAED,0BAAK,gDAAgD,MAAM;AAEzD,8BAAO,UAAU,MAAM,OAAO,KAAK,CAAC,EAAE,KAAK,KAAK;AAChD,8BAAO,UAAU,MAAM,OAAO,MAAM,CAAC,EAAE,KAAK,KAAK;AACjD,8BAAO,UAAU,MAAM,OAAO,OAAO,CAAC,EAAE,KAAK,KAAK;AAClD,8BAAO,UAAU,MAAM,OAAO,cAAc,CAAC,EAAE,KAAK,KAAK;AACzD,8BAAO,UAAU,MAAM,OAAO,uBAAuB,CAAC,EAAE,KAAK,KAAK;AAAA,EACpE,CAAC;AACH,CAAC;AAAA,IAED,2BAAS,SAAS,MAAM;AACtB,0BAAK,sDAAsD,MAAM;AAC/D,8BAAO,UAAU,MAAM,OAAO,QAAQ,CAAC,EAAE,KAAK,IAAI;AAClD,8BAAO,UAAU,MAAM,OAAO,SAAS,CAAC,EAAE,KAAK,IAAI;AACnD,8BAAO,UAAU,MAAM,OAAO,kBAAkB,CAAC,EAAE,KAAK,IAAI;AAC5D,8BAAO,UAAU,MAAM,OAAO,4BAA4B,CAAC,EAAE,KAAK,IAAI;AACtE,8BAAO,UAAU,MAAM,OAAO,+BAA+B,CAAC,EAAE,KAAK,IAAI;AAAA,EAC3E,CAAC;AAED,0BAAK,sDAAsD,MAAM;AAC/D,8BAAO,UAAU,MAAM,OAAO,SAAS,CAAC,EAAE,KAAK,IAAI;AACnD,8BAAO,UAAU,MAAM,OAAO,SAAS,CAAC,EAAE,KAAK,IAAI;AACnD,8BAAO,UAAU,MAAM,OAAO,mBAAmB,CAAC,EAAE,KAAK,IAAI;AAC7D,8BAAO,UAAU,MAAM,OAAO,6BAA6B,CAAC,EAAE,KAAK,IAAI;AAAA,EACzE,CAAC;AAED,0BAAK,gDAAgD,MAAM;AAEzD,8BAAO,UAAU,MAAM,OAAO,KAAK,CAAC,EAAE,KAAK,KAAK;AAChD,8BAAO,UAAU,MAAM,OAAO,MAAM,CAAC,EAAE,KAAK,KAAK;AACjD,8BAAO,UAAU,MAAM,OAAO,OAAO,CAAC,EAAE,KAAK,KAAK;AAClD,8BAAO,UAAU,MAAM,OAAO,eAAe,CAAC,EAAE,KAAK,KAAK;AAC1D,8BAAO,UAAU,MAAM,OAAO,yBAAyB,CAAC,EAAE,KAAK,KAAK;AACpE,8BAAO,UAAU,MAAM,OAAO,YAAY,CAAC,EAAE,KAAK,KAAK;AACvD,8BAAO,UAAU,MAAM,OAAO,sBAAsB,CAAC,EAAE,KAAK,KAAK;AAAA,EACnE,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
18
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
25
|
var record_utils_exports = {};
|
|
20
26
|
__export(record_utils_exports, {
|
|
@@ -22,10 +28,12 @@ __export(record_utils_exports, {
|
|
|
22
28
|
mapKeys: () => mapKeys,
|
|
23
29
|
mapValues: () => mapValues,
|
|
24
30
|
mapValuesAsync: () => mapValuesAsync,
|
|
31
|
+
mergeRecords: () => mergeRecords,
|
|
25
32
|
setNullOnMissingValues: () => setNullOnMissingValues,
|
|
26
33
|
zipObjects: () => zipObjects
|
|
27
34
|
});
|
|
28
35
|
module.exports = __toCommonJS(record_utils_exports);
|
|
36
|
+
var import_lodash = __toESM(require("lodash"));
|
|
29
37
|
const setNullOnMissingValues = (record = {}, oldRecord = {}) => {
|
|
30
38
|
const newRecord = {};
|
|
31
39
|
for (const [key, value] of Object.entries(record)) {
|
|
@@ -77,12 +85,29 @@ function filterValues(record, fn) {
|
|
|
77
85
|
}
|
|
78
86
|
return newRecord;
|
|
79
87
|
}
|
|
88
|
+
const mergeRecords = (a, b, merge) => {
|
|
89
|
+
const keys = import_lodash.default.uniq([...Object.keys(a), ...Object.keys(b)]);
|
|
90
|
+
const result = {};
|
|
91
|
+
for (const key of keys) {
|
|
92
|
+
const aValue = a[key];
|
|
93
|
+
const bValue = b[key];
|
|
94
|
+
if (aValue && bValue) {
|
|
95
|
+
result[key] = merge(aValue, bValue);
|
|
96
|
+
} else if (aValue) {
|
|
97
|
+
result[key] = aValue;
|
|
98
|
+
} else if (bValue) {
|
|
99
|
+
result[key] = bValue;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
};
|
|
80
104
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
105
|
0 && (module.exports = {
|
|
82
106
|
filterValues,
|
|
83
107
|
mapKeys,
|
|
84
108
|
mapValues,
|
|
85
109
|
mapValuesAsync,
|
|
110
|
+
mergeRecords,
|
|
86
111
|
setNullOnMissingValues,
|
|
87
112
|
zipObjects
|
|
88
113
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/record-utils.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import _ from 'lodash'\n\nexport const setNullOnMissingValues = <A, B>(\n record: Record<string, A> = {},\n oldRecord: Record<string, B> = {}\n): Record<string, A | null> => {\n const newRecord: Record<string, A | null> = {}\n\n for (const [key, value] of Object.entries(record)) {\n newRecord[key] = value\n }\n\n for (const value of Object.keys(oldRecord)) {\n if (!record[value]) {\n newRecord[value] = null\n }\n }\n\n return newRecord\n}\n\nexport const zipObjects = <A, B>(\n recordA: Record<string, A>,\n recordB: Record<string, B>\n): Record<string, [A | null, B | null]> => {\n const allKeys = new Set([...Object.keys(recordA), ...Object.keys(recordB)])\n const newRecord: Record<string, [A | null, B | null]> = {}\n\n for (const key of allKeys) {\n newRecord[key] = [recordA[key] ?? null, recordB[key] ?? null]\n }\n\n return newRecord\n}\n\nexport const mapValues = <A, B>(record: Record<string, A>, fn: (value: A, key: string) => B): Record<string, B> => {\n const newRecord: Record<string, B> = {}\n\n for (const [key, value] of Object.entries(record)) {\n newRecord[key] = fn(value, key)\n }\n\n return newRecord\n}\n\nexport const mapValuesAsync = async <A, B>(\n record: Record<string, A>,\n fn: (value: A, key: string) => Promise<B>\n): Promise<Record<string, B>> => {\n const newRecord: Record<string, B> = {}\n\n for (const [key, value] of Object.entries(record)) {\n newRecord[key] = await fn(value, key)\n }\n\n return newRecord\n}\n\nexport const mapKeys = <A>(record: Record<string, A>, fn: (value: A, key: string) => string): Record<string, A> => {\n const newRecord: Record<string, A> = {}\n\n for (const [key, value] of Object.entries(record)) {\n const newKey = fn(value, key) as string\n newRecord[newKey] = value\n }\n\n return newRecord\n}\n\nexport function filterValues<A, B extends A>(\n record: Record<string, A>,\n fn: (value: A, key: string) => value is B\n): Record<string, B>\nexport function filterValues<A, _B extends A>(\n record: Record<string, A>,\n fn: (value: A, key: string) => boolean\n): Record<string, A>\nexport function filterValues<A>(record: Record<string, A>, fn: (value: A, key: string) => boolean) {\n const newRecord: Record<string, A> = {}\n\n for (const [key, value] of Object.entries(record)) {\n if (fn(value, key)) {\n newRecord[key] = value\n }\n }\n\n return newRecord\n}\n\nexport const mergeRecords = <K extends string, V>(\n a: Record<K, V>,\n b: Record<K, V>,\n merge: (v1: V, v2: V) => V\n): Record<K, V> => {\n const keys = _.uniq([...Object.keys(a), ...Object.keys(b)]) as K[]\n const result: Record<K, V> = {} as Record<K, V>\n for (const key of keys) {\n const aValue = a[key]\n const bValue = b[key]\n if (aValue && bValue) {\n result[key] = merge(aValue, bValue)\n } else if (aValue) {\n result[key] = aValue\n } else if (bValue) {\n result[key] = bValue\n }\n }\n return result\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAc;AAEP,MAAM,yBAAyB,CACpC,SAA4B,CAAC,GAC7B,YAA+B,CAAC,MACH;AAC7B,QAAM,YAAsC,CAAC;AAE7C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,cAAU,OAAO;AAAA,EACnB;AAEA,aAAW,SAAS,OAAO,KAAK,SAAS,GAAG;AAC1C,QAAI,CAAC,OAAO,QAAQ;AAClB,gBAAU,SAAS;AAAA,IACrB;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,aAAa,CACxB,SACA,YACyC;AACzC,QAAM,UAAU,oBAAI,IAAI,CAAC,GAAG,OAAO,KAAK,OAAO,GAAG,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC;AAC1E,QAAM,YAAkD,CAAC;AAEzD,aAAW,OAAO,SAAS;AACzB,cAAU,OAAO,CAAC,QAAQ,QAAQ,MAAM,QAAQ,QAAQ,IAAI;AAAA,EAC9D;AAEA,SAAO;AACT;AAEO,MAAM,YAAY,CAAO,QAA2B,OAAwD;AACjH,QAAM,YAA+B,CAAC;AAEtC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,cAAU,OAAO,GAAG,OAAO,GAAG;AAAA,EAChC;AAEA,SAAO;AACT;AAEO,MAAM,iBAAiB,OAC5B,QACA,OAC+B;AAC/B,QAAM,YAA+B,CAAC;AAEtC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,cAAU,OAAO,MAAM,GAAG,OAAO,GAAG;AAAA,EACtC;AAEA,SAAO;AACT;AAEO,MAAM,UAAU,CAAI,QAA2B,OAA6D;AACjH,QAAM,YAA+B,CAAC;AAEtC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,UAAM,SAAS,GAAG,OAAO,GAAG;AAC5B,cAAU,UAAU;AAAA,EACtB;AAEA,SAAO;AACT;AAUO,SAAS,aAAgB,QAA2B,IAAwC;AACjG,QAAM,YAA+B,CAAC;AAEtC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,QAAI,GAAG,OAAO,GAAG,GAAG;AAClB,gBAAU,OAAO;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,eAAe,CAC1B,GACA,GACA,UACiB;AACjB,QAAM,OAAO,cAAAA,QAAE,KAAK,CAAC,GAAG,OAAO,KAAK,CAAC,GAAG,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC;AAC1D,QAAM,SAAuB,CAAC;AAC9B,aAAW,OAAO,MAAM;AACtB,UAAM,SAAS,EAAE;AACjB,UAAM,SAAS,EAAE;AACjB,QAAI,UAAU,QAAQ;AACpB,aAAO,OAAO,MAAM,QAAQ,MAAM;AAAA,IACpC,WAAW,QAAQ;AACjB,aAAO,OAAO;AAAA,IAChB,WAAW,QAAQ;AACjB,aAAO,OAAO;AAAA,IAChB;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
|
+
"names": ["_"]
|
|
7
7
|
}
|
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var schema_utils_exports = {};
|
|
20
20
|
__export(schema_utils_exports, {
|
|
21
|
+
dereferenceSchema: () => dereferenceSchema,
|
|
21
22
|
mapZodToJsonSchema: () => mapZodToJsonSchema
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(schema_utils_exports);
|
|
@@ -48,8 +49,18 @@ async function mapZodToJsonSchema(definition, options = {}) {
|
|
|
48
49
|
}
|
|
49
50
|
return schema;
|
|
50
51
|
}
|
|
52
|
+
const dereferenceSchema = async (schema) => {
|
|
53
|
+
return (0, import_json_schema_ref_parser.dereference)(schema, {
|
|
54
|
+
resolve: {
|
|
55
|
+
external: false,
|
|
56
|
+
file: false,
|
|
57
|
+
http: false
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
51
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
62
|
0 && (module.exports = {
|
|
63
|
+
dereferenceSchema,
|
|
53
64
|
mapZodToJsonSchema
|
|
54
65
|
});
|
|
55
66
|
//# sourceMappingURL=schema-utils.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/schema-utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { dereference } from '@apidevtools/json-schema-ref-parser'\nimport { z, transforms
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAA4B;AAC5B,
|
|
4
|
+
"sourcesContent": ["import { dereference } from '@apidevtools/json-schema-ref-parser'\nimport { z, transforms } from '@botpress/sdk'\nimport { JSONSchema7 } from 'json-schema'\n\ntype ZuiToJsonSchema = typeof transforms.zuiToJsonSchema\ntype JsonSchema = ReturnType<ZuiToJsonSchema>\ntype ObjectJsonSchema = Extract<JsonSchema, { type: 'object' }>\n\ntype SchemaOptions = {\n title?: string\n examples?: any[]\n}\n\ntype SchemaDefinition = {\n schema: z.ZodObject<any>\n ui?: Record<string, SchemaOptions | undefined>\n}\n\nexport type ZodToJsonOptions = {\n dereference?: boolean\n}\n\nconst isObjectSchema = (schema: JsonSchema): schema is ObjectJsonSchema => schema.type === 'object'\n\nexport async function mapZodToJsonSchema(\n definition: SchemaDefinition,\n options: ZodToJsonOptions = {}\n): Promise<ReturnType<typeof transforms.zuiToJsonSchema>> {\n let schema = transforms.zuiToJsonSchema(definition.schema, { target: 'jsonSchema7' })\n\n if (options.dereference) {\n schema = (await dereference(schema)) as typeof schema\n }\n\n if (!isObjectSchema(schema) || !definition.ui) {\n return schema\n }\n\n for (const [key, value] of Object.entries(definition.ui ?? {})) {\n const property = schema.properties?.[key]\n\n if (!property) {\n continue\n }\n\n if (!!value?.title) {\n ;(property as any).title = value.title\n }\n\n if (!!value?.examples) {\n ;(property as any).examples = value.examples\n }\n }\n\n return schema\n}\n\nexport const dereferenceSchema = async (schema: JSONSchema7): Promise<JSONSchema7> => {\n return dereference(schema, {\n resolve: {\n external: false,\n file: false,\n http: false,\n },\n })\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAA4B;AAC5B,iBAA8B;AAqB9B,MAAM,iBAAiB,CAAC,WAAmD,OAAO,SAAS;AAE3F,eAAsB,mBACpB,YACA,UAA4B,CAAC,GAC2B;AACxD,MAAI,SAAS,sBAAW,gBAAgB,WAAW,QAAQ,EAAE,QAAQ,cAAc,CAAC;AAEpF,MAAI,QAAQ,aAAa;AACvB,aAAU,UAAM,2CAAY,MAAM;AAAA,EACpC;AAEA,MAAI,CAAC,eAAe,MAAM,KAAK,CAAC,WAAW,IAAI;AAC7C,WAAO;AAAA,EACT;AAEA,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,MAAM,CAAC,CAAC,GAAG;AAC9D,UAAM,WAAW,OAAO,aAAa;AAErC,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,QAAI,CAAC,CAAC,OAAO,OAAO;AAClB;AAAC,MAAC,SAAiB,QAAQ,MAAM;AAAA,IACnC;AAEA,QAAI,CAAC,CAAC,OAAO,UAAU;AACrB;AAAC,MAAC,SAAiB,WAAW,MAAM;AAAA,IACtC;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,oBAAoB,OAAO,WAA8C;AACpF,aAAO,2CAAY,QAAQ;AAAA,IACzB,SAAS;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_node_test = require("node:test");
|
|
4
|
+
var import_schema_utils = require("./schema-utils");
|
|
5
|
+
(0, import_node_test.describe)("dereferenceSchema", () => {
|
|
6
|
+
(0, import_vitest.it)("should do nothing if no $ref", async () => {
|
|
7
|
+
const schema = { type: "object" };
|
|
8
|
+
const result = await (0, import_schema_utils.dereferenceSchema)(schema);
|
|
9
|
+
(0, import_vitest.expect)(result).toEqual(schema);
|
|
10
|
+
});
|
|
11
|
+
(0, import_vitest.it)("should dereference local $ref", async () => {
|
|
12
|
+
const schema = {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
foo: { $ref: "#/$defs/foo" },
|
|
16
|
+
bar: { $ref: "#/definitions/bar" }
|
|
17
|
+
},
|
|
18
|
+
$defs: {
|
|
19
|
+
foo: { type: "string" }
|
|
20
|
+
},
|
|
21
|
+
definitions: {
|
|
22
|
+
bar: { type: "number" }
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const result = await (0, import_schema_utils.dereferenceSchema)(schema);
|
|
26
|
+
(0, import_vitest.expect)(result).toEqual({
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
foo: { type: "string" },
|
|
30
|
+
bar: { type: "number" }
|
|
31
|
+
},
|
|
32
|
+
$defs: {
|
|
33
|
+
foo: { type: "string" }
|
|
34
|
+
},
|
|
35
|
+
definitions: {
|
|
36
|
+
bar: { type: "number" }
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
(0, import_vitest.it)("should ignore non-local $ref", async () => {
|
|
41
|
+
const schema = {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
foo: { $ref: "TItem" }
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const result = await (0, import_schema_utils.dereferenceSchema)(schema);
|
|
48
|
+
(0, import_vitest.expect)(result).toEqual(schema);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=schema-utils.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/schema-utils.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { it, expect } from 'vitest'\nimport { describe } from 'node:test'\nimport { dereferenceSchema } from './schema-utils'\nimport { JSONSchema7 } from 'json-schema'\n\ndescribe('dereferenceSchema', () => {\n it('should do nothing if no $ref', async () => {\n const schema: JSONSchema7 = { type: 'object' }\n const result = await dereferenceSchema(schema)\n expect(result).toEqual(schema)\n })\n\n it('should dereference local $ref', async () => {\n const schema: JSONSchema7 = {\n type: 'object',\n properties: {\n foo: { $ref: '#/$defs/foo' },\n bar: { $ref: '#/definitions/bar' },\n },\n $defs: {\n foo: { type: 'string' },\n },\n definitions: {\n bar: { type: 'number' },\n },\n }\n const result = await dereferenceSchema(schema)\n expect(result).toEqual({\n type: 'object',\n properties: {\n foo: { type: 'string' },\n bar: { type: 'number' },\n },\n $defs: {\n foo: { type: 'string' },\n },\n definitions: {\n bar: { type: 'number' },\n },\n })\n })\n\n it('should ignore non-local $ref', async () => {\n const schema: JSONSchema7 = {\n type: 'object',\n properties: {\n foo: { $ref: 'TItem' },\n },\n }\n const result = await dereferenceSchema(schema)\n expect(result).toEqual(schema)\n })\n})\n"],
|
|
5
|
+
"mappings": ";AAAA,oBAA2B;AAC3B,uBAAyB;AACzB,0BAAkC;AAAA,IAGlC,2BAAS,qBAAqB,MAAM;AAClC,wBAAG,gCAAgC,YAAY;AAC7C,UAAM,SAAsB,EAAE,MAAM,SAAS;AAC7C,UAAM,SAAS,UAAM,uCAAkB,MAAM;AAC7C,8BAAO,MAAM,EAAE,QAAQ,MAAM;AAAA,EAC/B,CAAC;AAED,wBAAG,iCAAiC,YAAY;AAC9C,UAAM,SAAsB;AAAA,MAC1B,MAAM;AAAA,MACN,YAAY;AAAA,QACV,KAAK,EAAE,MAAM,cAAc;AAAA,QAC3B,KAAK,EAAE,MAAM,oBAAoB;AAAA,MACnC;AAAA,MACA,OAAO;AAAA,QACL,KAAK,EAAE,MAAM,SAAS;AAAA,MACxB;AAAA,MACA,aAAa;AAAA,QACX,KAAK,EAAE,MAAM,SAAS;AAAA,MACxB;AAAA,IACF;AACA,UAAM,SAAS,UAAM,uCAAkB,MAAM;AAC7C,8BAAO,MAAM,EAAE,QAAQ;AAAA,MACrB,MAAM;AAAA,MACN,YAAY;AAAA,QACV,KAAK,EAAE,MAAM,SAAS;AAAA,QACtB,KAAK,EAAE,MAAM,SAAS;AAAA,MACxB;AAAA,MACA,OAAO;AAAA,QACL,KAAK,EAAE,MAAM,SAAS;AAAA,MACxB;AAAA,MACA,aAAa;AAAA,QACX,KAAK,EAAE,MAAM,SAAS;AAAA,MACxB;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,wBAAG,gCAAgC,YAAY;AAC7C,UAAM,SAAsB;AAAA,MAC1B,MAAM;AAAA,MACN,YAAY;AAAA,QACV,KAAK,EAAE,MAAM,QAAQ;AAAA,MACvB;AAAA,IACF;AACA,UAAM,SAAS,UAAM,uCAAkB,MAAM;AAC7C,8BAAO,MAAM,EAAE,QAAQ,MAAM;AAAA,EAC/B,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var template_utils_exports = {};
|
|
26
|
+
__export(template_utils_exports, {
|
|
27
|
+
formatHandleBars: () => formatHandleBars
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(template_utils_exports);
|
|
30
|
+
var import_handlebars = __toESM(require("handlebars"));
|
|
31
|
+
var casing = __toESM(require("./case-utils"));
|
|
32
|
+
import_handlebars.default.registerHelper("toUpperCase", (s) => s.toUpperCase());
|
|
33
|
+
import_handlebars.default.registerHelper("toLowerCase", (s) => s.toLowerCase());
|
|
34
|
+
import_handlebars.default.registerHelper("pascalCase", casing.to.pascalCase);
|
|
35
|
+
import_handlebars.default.registerHelper("kebabCase", casing.to.kebabCase);
|
|
36
|
+
import_handlebars.default.registerHelper("snakeCase", casing.to.snakeCase);
|
|
37
|
+
import_handlebars.default.registerHelper("screamingSnakeCase", casing.to.screamingSnakeCase);
|
|
38
|
+
import_handlebars.default.registerHelper("camelCase", casing.to.camelCase);
|
|
39
|
+
const formatHandleBars = (templateStr, data) => {
|
|
40
|
+
const template = import_handlebars.default.compile(templateStr);
|
|
41
|
+
return template(data);
|
|
42
|
+
};
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
formatHandleBars
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=template-utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/template-utils.ts"],
|
|
4
|
+
"sourcesContent": ["import hb from 'handlebars'\nimport * as casing from './case-utils'\n\nhb.registerHelper('toUpperCase', (s) => s.toUpperCase())\nhb.registerHelper('toLowerCase', (s) => s.toLowerCase())\nhb.registerHelper('pascalCase', casing.to.pascalCase)\nhb.registerHelper('kebabCase', casing.to.kebabCase)\nhb.registerHelper('snakeCase', casing.to.snakeCase)\nhb.registerHelper('screamingSnakeCase', casing.to.screamingSnakeCase)\nhb.registerHelper('camelCase', casing.to.camelCase)\n\nexport const formatHandleBars = (templateStr: string, data: Record<string, string>): string => {\n const template = hb.compile(templateStr)\n return template(data)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAe;AACf,aAAwB;AAExB,kBAAAA,QAAG,eAAe,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC;AACvD,kBAAAA,QAAG,eAAe,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC;AACvD,kBAAAA,QAAG,eAAe,cAAc,OAAO,GAAG,UAAU;AACpD,kBAAAA,QAAG,eAAe,aAAa,OAAO,GAAG,SAAS;AAClD,kBAAAA,QAAG,eAAe,aAAa,OAAO,GAAG,SAAS;AAClD,kBAAAA,QAAG,eAAe,sBAAsB,OAAO,GAAG,kBAAkB;AACpE,kBAAAA,QAAG,eAAe,aAAa,OAAO,GAAG,SAAS;AAE3C,MAAM,mBAAmB,CAAC,aAAqB,SAAyC;AAC7F,QAAM,WAAW,kBAAAA,QAAG,QAAQ,WAAW;AACvC,SAAO,SAAS,IAAI;AACtB;",
|
|
6
|
+
"names": ["hb"]
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/type-utils.ts"],
|
|
4
|
-
"sourcesContent": ["export type Merge<A extends object, B extends object> = Omit<A, keyof B> & B\n"],
|
|
4
|
+
"sourcesContent": ["export type Merge<A extends object, B extends object> = Omit<A, keyof B> & B\nexport type SafeOmit<T, K extends keyof T> = Omit<T, K>\nexport type Writable<T> = { -readonly [K in keyof T]: T[K] }\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/e2e/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import * as consts from '../src/consts'
|
|
|
4
4
|
import { createDeployBot } from './tests/create-deploy-bot'
|
|
5
5
|
import { createDeployIntegration } from './tests/create-deploy-integration'
|
|
6
6
|
import { devBot } from './tests/dev-bot'
|
|
7
|
+
import { addIntegration } from './tests/install-package'
|
|
7
8
|
import { requiredSecrets } from './tests/integration-secrets'
|
|
8
9
|
import { prependWorkspaceHandle, enforceWorkspaceHandle } from './tests/manage-workspace-handle'
|
|
9
10
|
import { Test } from './typings'
|
|
@@ -16,6 +17,7 @@ const tests: Test[] = [
|
|
|
16
17
|
requiredSecrets,
|
|
17
18
|
prependWorkspaceHandle,
|
|
18
19
|
enforceWorkspaceHandle,
|
|
20
|
+
addIntegration,
|
|
19
21
|
]
|
|
20
22
|
|
|
21
23
|
const timeout = (ms: number) =>
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import * as client from '@botpress/client'
|
|
2
|
+
import * as sdk from '@botpress/sdk'
|
|
3
|
+
import * as fslib from 'fs'
|
|
4
|
+
import * as pathlib from 'path'
|
|
5
|
+
import * as uuid from 'uuid'
|
|
6
|
+
import * as apiUtils from '../../src/api'
|
|
7
|
+
import impl from '../../src/command-implementations'
|
|
8
|
+
import defaults from '../defaults'
|
|
9
|
+
import { Test, TestProps } from '../typings'
|
|
10
|
+
import * as utils from '../utils'
|
|
11
|
+
|
|
12
|
+
const issueSchema = sdk.z.object({
|
|
13
|
+
id: sdk.z.string(),
|
|
14
|
+
priority: sdk.z.enum(['high', 'medium', 'low']),
|
|
15
|
+
title: sdk.z.string(),
|
|
16
|
+
body: sdk.z.string(),
|
|
17
|
+
})
|
|
18
|
+
const INTEGRATION = {
|
|
19
|
+
version: '0.0.1',
|
|
20
|
+
title: 'An Integration',
|
|
21
|
+
description: 'An integration',
|
|
22
|
+
user: { tags: { id: { title: 'ID', description: 'The user ID' } } },
|
|
23
|
+
configuration: { schema: sdk.z.object({}), identifier: { required: true, linkTemplateScript: '' } },
|
|
24
|
+
configurations: {
|
|
25
|
+
token: {
|
|
26
|
+
title: 'API Token',
|
|
27
|
+
description: 'The token to authenticate with',
|
|
28
|
+
schema: sdk.z.object({ token: sdk.z.string() }),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
actions: {
|
|
32
|
+
getIssue: {
|
|
33
|
+
input: { schema: sdk.z.object({ id: sdk.z.string() }) },
|
|
34
|
+
output: { schema: issueSchema },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
events: {
|
|
38
|
+
issueCreated: {
|
|
39
|
+
title: 'Issue Created',
|
|
40
|
+
description: 'An issue was created',
|
|
41
|
+
schema: issueSchema,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
channels: {
|
|
45
|
+
issueComment: {
|
|
46
|
+
title: 'Issue Comment',
|
|
47
|
+
description: 'Comment on an issue',
|
|
48
|
+
messages: { text: sdk.messages.defaults.text },
|
|
49
|
+
conversation: { tags: { id: { title: 'ID', description: 'The issue ID' } } },
|
|
50
|
+
message: { tags: { id: { title: 'ID', description: 'The issue comment ID' } } },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
entities: {
|
|
54
|
+
issue: {
|
|
55
|
+
title: 'Issue',
|
|
56
|
+
description: 'An issue',
|
|
57
|
+
schema: issueSchema,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
states: {
|
|
61
|
+
lastCreatedIssue: {
|
|
62
|
+
type: 'integration',
|
|
63
|
+
schema: issueSchema,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
identifier: {
|
|
67
|
+
extractScript: '',
|
|
68
|
+
},
|
|
69
|
+
} satisfies Omit<sdk.IntegrationDefinitionProps, 'name'>
|
|
70
|
+
|
|
71
|
+
const getHomeDir = (props: { tmpDir: string }) => pathlib.join(props.tmpDir, '.botpresshome')
|
|
72
|
+
const initBot = async (props: TestProps, definitionFile: string) => {
|
|
73
|
+
const { tmpDir, dependencies, ...creds } = props
|
|
74
|
+
const argv = {
|
|
75
|
+
...defaults,
|
|
76
|
+
botpressHome: getHomeDir(props),
|
|
77
|
+
confirm: true,
|
|
78
|
+
...creds,
|
|
79
|
+
}
|
|
80
|
+
const botName = uuid.v4().replace(/-/g, '')
|
|
81
|
+
const botDir = pathlib.join(tmpDir, botName)
|
|
82
|
+
await impl.init({ ...argv, workDir: tmpDir, name: botName, type: 'bot' }).then(utils.handleExitCode)
|
|
83
|
+
await utils.fixBotpressDependencies({ workDir: botDir, target: dependencies })
|
|
84
|
+
await utils.npmInstall({ workDir: botDir }).then(utils.handleExitCode)
|
|
85
|
+
await fslib.promises.writeFile(pathlib.join(botDir, 'bot.definition.ts'), definitionFile)
|
|
86
|
+
return { botDir }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// TODO: add an equivalent test with an interface once interfaces can be created by any workspace
|
|
90
|
+
|
|
91
|
+
export const addIntegration: Test = {
|
|
92
|
+
name: 'cli should allow installing an integration',
|
|
93
|
+
handler: async (props) => {
|
|
94
|
+
const { tmpDir, workspaceHandle, logger, ...creds } = props
|
|
95
|
+
const argv = {
|
|
96
|
+
...defaults,
|
|
97
|
+
botpressHome: getHomeDir({ tmpDir }),
|
|
98
|
+
confirm: true,
|
|
99
|
+
...creds,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const bpClient = new client.Client({ apiUrl: creds.apiUrl, token: creds.token, workspaceId: creds.workspaceId })
|
|
103
|
+
|
|
104
|
+
const integrationSuffix = uuid.v4().replace(/-/g, '')
|
|
105
|
+
const name = `myintegration${integrationSuffix}`
|
|
106
|
+
const integrationName = `${workspaceHandle}/${name}`
|
|
107
|
+
|
|
108
|
+
const createIntegrationBody = await apiUtils.prepareCreateIntegrationBody(
|
|
109
|
+
new sdk.IntegrationDefinition({
|
|
110
|
+
...INTEGRATION,
|
|
111
|
+
name: integrationName,
|
|
112
|
+
})
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
const { integration } = await bpClient.createIntegration({
|
|
116
|
+
...createIntegrationBody,
|
|
117
|
+
dev: true, // this way we ensure the integration will eventually be janitored if the test fails
|
|
118
|
+
url: creds.apiUrl,
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
logger.info('Initializing bot')
|
|
123
|
+
const { botDir } = await initBot(
|
|
124
|
+
props,
|
|
125
|
+
[
|
|
126
|
+
'import * as sdk from "@botpress/sdk"',
|
|
127
|
+
`import anIntegration from "./bp_modules/${workspaceHandle}-${name}"`,
|
|
128
|
+
'export default new sdk.BotDefinition({}).add(anIntegration, {',
|
|
129
|
+
' enabled: true,',
|
|
130
|
+
' configurationType: null,',
|
|
131
|
+
' configuration: {},',
|
|
132
|
+
'})',
|
|
133
|
+
].join('\n')
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
logger.info('Logging in')
|
|
137
|
+
await impl.login(argv).then(utils.handleExitCode)
|
|
138
|
+
|
|
139
|
+
logger.info('Installing integration')
|
|
140
|
+
await impl
|
|
141
|
+
.add({
|
|
142
|
+
...argv,
|
|
143
|
+
packageType: undefined,
|
|
144
|
+
installPath: botDir,
|
|
145
|
+
packageRef: integration.id,
|
|
146
|
+
})
|
|
147
|
+
.then(utils.handleExitCode)
|
|
148
|
+
|
|
149
|
+
logger.info('Building bot')
|
|
150
|
+
await impl.build({ ...argv, workDir: botDir }).then(utils.handleExitCode)
|
|
151
|
+
await utils.tscCheck({ workDir: botDir }).then(utils.handleExitCode)
|
|
152
|
+
} finally {
|
|
153
|
+
await impl.integrations.subcommands
|
|
154
|
+
.delete({
|
|
155
|
+
...argv,
|
|
156
|
+
integrationRef: integration.id,
|
|
157
|
+
})
|
|
158
|
+
.catch(() => {
|
|
159
|
+
logger.warn(`Failed to delete integration ${integration.id}`) // this is not the purpose of the test
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
}
|