windmill-utils-internal 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/dist/constants.d.ts +16 -0
- package/dist/constants.js +44 -0
- package/dist/gen/core/ApiError.d.ts +10 -0
- package/dist/gen/core/ApiError.js +20 -0
- package/dist/gen/core/ApiRequestOptions.d.ts +14 -0
- package/dist/gen/core/ApiRequestOptions.js +2 -0
- package/dist/gen/core/ApiResult.d.ts +7 -0
- package/dist/gen/core/ApiResult.js +2 -0
- package/dist/gen/core/CancelablePromise.d.ts +26 -0
- package/dist/gen/core/CancelablePromise.js +100 -0
- package/dist/gen/core/OpenAPI.d.ts +27 -0
- package/dist/gen/core/OpenAPI.js +39 -0
- package/dist/gen/core/request.d.ts +29 -0
- package/dist/gen/core/request.js +323 -0
- package/dist/gen/index.d.ts +5 -0
- package/dist/gen/index.js +27 -0
- package/dist/gen/services.gen.d.ts +4894 -0
- package/dist/gen/services.gen.js +10485 -0
- package/dist/gen/types.gen.d.ts +7319 -0
- package/dist/gen/types.gen.js +3 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +32 -0
- package/dist/inline-scripts/extractor.d.ts +30 -0
- package/dist/inline-scripts/extractor.js +85 -0
- package/dist/inline-scripts/index.d.ts +2 -0
- package/dist/inline-scripts/index.js +18 -0
- package/dist/inline-scripts/replacer.d.ts +16 -0
- package/dist/inline-scripts/replacer.js +97 -0
- package/dist/parse/index.d.ts +1 -0
- package/dist/parse/index.js +17 -0
- package/dist/parse/parse-schema.d.ts +93 -0
- package/dist/parse/parse-schema.js +205 -0
- package/dist/path-utils/index.d.ts +1 -0
- package/dist/path-utils/index.js +17 -0
- package/dist/path-utils/path-assigner.d.ts +28 -0
- package/dist/path-utils/path-assigner.js +60 -0
- package/package.json +24 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Main entry point for windmill-utils-internal package
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for handling Windmill flows, scripts, and schemas:
|
|
5
|
+
* - Inline script extraction and replacement
|
|
6
|
+
* - Path utilities for different programming languages
|
|
7
|
+
* - Schema parsing and conversion utilities
|
|
8
|
+
* - Cross-platform path constants
|
|
9
|
+
*/
|
|
10
|
+
export * from "./inline-scripts";
|
|
11
|
+
export * from "./path-utils";
|
|
12
|
+
export * from "./parse";
|
|
13
|
+
export { SEP, DELIMITER } from "./constants";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Main entry point for windmill-utils-internal package
|
|
4
|
+
*
|
|
5
|
+
* This module provides utilities for handling Windmill flows, scripts, and schemas:
|
|
6
|
+
* - Inline script extraction and replacement
|
|
7
|
+
* - Path utilities for different programming languages
|
|
8
|
+
* - Schema parsing and conversion utilities
|
|
9
|
+
* - Cross-platform path constants
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
23
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.DELIMITER = exports.SEP = void 0;
|
|
27
|
+
__exportStar(require("./inline-scripts"), exports);
|
|
28
|
+
__exportStar(require("./path-utils"), exports);
|
|
29
|
+
__exportStar(require("./parse"), exports);
|
|
30
|
+
var constants_1 = require("./constants");
|
|
31
|
+
Object.defineProperty(exports, "SEP", { enumerable: true, get: function () { return constants_1.SEP; } });
|
|
32
|
+
Object.defineProperty(exports, "DELIMITER", { enumerable: true, get: function () { return constants_1.DELIMITER; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FlowModule } from "../gen/types.gen";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an inline script extracted from a flow module
|
|
4
|
+
*/
|
|
5
|
+
interface InlineScript {
|
|
6
|
+
/** File path where the script content should be written */
|
|
7
|
+
path: string;
|
|
8
|
+
/** The actual script content */
|
|
9
|
+
content: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Extracts inline scripts from flow modules, converting them to separate files
|
|
13
|
+
* and replacing the original content with file references.
|
|
14
|
+
*
|
|
15
|
+
* @param modules - Array of flow modules to process
|
|
16
|
+
* @param mapping - Optional mapping of module IDs to custom file paths
|
|
17
|
+
* @param defaultTs - Default TypeScript runtime to use ("bun" or "deno")
|
|
18
|
+
* @returns Array of inline scripts with their paths and content
|
|
19
|
+
*/
|
|
20
|
+
export declare function extractInlineScripts(modules: FlowModule[], mapping?: Record<string, string>, separator?: string, defaultTs?: "bun" | "deno"): InlineScript[];
|
|
21
|
+
/**
|
|
22
|
+
* Extracts the current mapping of module IDs to file paths from flow modules
|
|
23
|
+
* by analyzing existing inline script references.
|
|
24
|
+
*
|
|
25
|
+
* @param modules - Array of flow modules to analyze (can be undefined)
|
|
26
|
+
* @param mapping - Existing mapping to extend (defaults to empty object)
|
|
27
|
+
* @returns Record mapping module IDs to their corresponding file paths
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractCurrentMapping(modules: FlowModule[] | undefined, mapping?: Record<string, string>): Record<string, string>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractInlineScripts = extractInlineScripts;
|
|
4
|
+
exports.extractCurrentMapping = extractCurrentMapping;
|
|
5
|
+
const path_assigner_1 = require("../path-utils/path-assigner");
|
|
6
|
+
/**
|
|
7
|
+
* Extracts inline scripts from flow modules, converting them to separate files
|
|
8
|
+
* and replacing the original content with file references.
|
|
9
|
+
*
|
|
10
|
+
* @param modules - Array of flow modules to process
|
|
11
|
+
* @param mapping - Optional mapping of module IDs to custom file paths
|
|
12
|
+
* @param defaultTs - Default TypeScript runtime to use ("bun" or "deno")
|
|
13
|
+
* @returns Array of inline scripts with their paths and content
|
|
14
|
+
*/
|
|
15
|
+
function extractInlineScripts(modules, mapping = {}, separator = "/", defaultTs) {
|
|
16
|
+
return modules.flatMap((m) => {
|
|
17
|
+
if (m.value.type == "rawscript") {
|
|
18
|
+
const [basePath, ext] = (0, path_assigner_1.assignPath)(m.id, m.value.language, defaultTs);
|
|
19
|
+
const path = mapping[m.id] ?? basePath + ext;
|
|
20
|
+
const content = m.value.content;
|
|
21
|
+
const r = [{ path: path, content: content }];
|
|
22
|
+
m.value.content = "!inline " + path.replaceAll(separator, "/");
|
|
23
|
+
const lock = m.value.lock;
|
|
24
|
+
if (lock && lock != "") {
|
|
25
|
+
const lockPath = basePath + "lock";
|
|
26
|
+
m.value.lock = "!inline " + lockPath.replaceAll(separator, "/");
|
|
27
|
+
r.push({ path: lockPath, content: lock });
|
|
28
|
+
}
|
|
29
|
+
return r;
|
|
30
|
+
}
|
|
31
|
+
else if (m.value.type == "forloopflow") {
|
|
32
|
+
return extractInlineScripts(m.value.modules, mapping, separator, defaultTs);
|
|
33
|
+
}
|
|
34
|
+
else if (m.value.type == "branchall") {
|
|
35
|
+
return m.value.branches.flatMap((b) => extractInlineScripts(b.modules, mapping, separator, defaultTs));
|
|
36
|
+
}
|
|
37
|
+
else if (m.value.type == "whileloopflow") {
|
|
38
|
+
return extractInlineScripts(m.value.modules, mapping, separator, defaultTs);
|
|
39
|
+
}
|
|
40
|
+
else if (m.value.type == "branchone") {
|
|
41
|
+
return [
|
|
42
|
+
...m.value.branches.flatMap((b) => extractInlineScripts(b.modules, mapping, separator, defaultTs)),
|
|
43
|
+
...extractInlineScripts(m.value.default, mapping, separator, defaultTs),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Extracts the current mapping of module IDs to file paths from flow modules
|
|
53
|
+
* by analyzing existing inline script references.
|
|
54
|
+
*
|
|
55
|
+
* @param modules - Array of flow modules to analyze (can be undefined)
|
|
56
|
+
* @param mapping - Existing mapping to extend (defaults to empty object)
|
|
57
|
+
* @returns Record mapping module IDs to their corresponding file paths
|
|
58
|
+
*/
|
|
59
|
+
function extractCurrentMapping(modules, mapping = {}) {
|
|
60
|
+
if (!modules || !Array.isArray(modules)) {
|
|
61
|
+
return mapping;
|
|
62
|
+
}
|
|
63
|
+
modules.forEach((m) => {
|
|
64
|
+
if (!m?.value?.type) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (m.value.type === "rawscript") {
|
|
68
|
+
if (m.value.content && m.value.content.startsWith("!inline ")) {
|
|
69
|
+
mapping[m.id] = m.value.content.trim().split(" ")[1];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (m.value.type === "forloopflow" ||
|
|
73
|
+
m.value.type === "whileloopflow") {
|
|
74
|
+
extractCurrentMapping(m.value.modules, mapping);
|
|
75
|
+
}
|
|
76
|
+
else if (m.value.type === "branchall") {
|
|
77
|
+
m.value.branches.forEach((b) => extractCurrentMapping(b.modules, mapping));
|
|
78
|
+
}
|
|
79
|
+
else if (m.value.type === "branchone") {
|
|
80
|
+
m.value.branches.forEach((b) => extractCurrentMapping(b.modules, mapping));
|
|
81
|
+
extractCurrentMapping(m.value.default, mapping);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return mapping;
|
|
85
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./replacer"), exports);
|
|
18
|
+
__exportStar(require("./extractor"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FlowModule } from "../gen/types.gen";
|
|
2
|
+
/**
|
|
3
|
+
* Replaces inline script references with actual file content from the filesystem.
|
|
4
|
+
* This function recursively processes all flow modules and their nested structures.
|
|
5
|
+
*
|
|
6
|
+
* @param modules - Array of flow modules to process
|
|
7
|
+
* @param fileReader - Function to read file content (typically fs.readFile or similar)
|
|
8
|
+
* @param logger - Optional logger object with info and error methods
|
|
9
|
+
* @param localPath - Base path for resolving relative file paths
|
|
10
|
+
* @param removeLocks - Optional array of paths for which to remove lock files
|
|
11
|
+
* @returns Promise that resolves when all inline scripts have been replaced
|
|
12
|
+
*/
|
|
13
|
+
export declare function replaceInlineScripts(modules: FlowModule[], fileReader: (path: string) => Promise<string>, logger: {
|
|
14
|
+
info: (message: string) => void;
|
|
15
|
+
error: (message: string) => void;
|
|
16
|
+
} | undefined, localPath: string, separator?: string, removeLocks?: string[], renamer?: (path: string, newPath: string) => void, deleter?: (path: string) => void): Promise<void>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceInlineScripts = replaceInlineScripts;
|
|
4
|
+
/**
|
|
5
|
+
* Replaces inline script references with actual file content from the filesystem.
|
|
6
|
+
* This function recursively processes all flow modules and their nested structures.
|
|
7
|
+
*
|
|
8
|
+
* @param modules - Array of flow modules to process
|
|
9
|
+
* @param fileReader - Function to read file content (typically fs.readFile or similar)
|
|
10
|
+
* @param logger - Optional logger object with info and error methods
|
|
11
|
+
* @param localPath - Base path for resolving relative file paths
|
|
12
|
+
* @param removeLocks - Optional array of paths for which to remove lock files
|
|
13
|
+
* @returns Promise that resolves when all inline scripts have been replaced
|
|
14
|
+
*/
|
|
15
|
+
async function replaceInlineScripts(modules, fileReader, logger = {
|
|
16
|
+
info: () => { },
|
|
17
|
+
error: () => { },
|
|
18
|
+
}, localPath, separator = "/", removeLocks, renamer, deleter) {
|
|
19
|
+
await Promise.all(modules.map(async (module) => {
|
|
20
|
+
if (!module.value) {
|
|
21
|
+
throw new Error(`Module value is undefined for module ${module.id}`);
|
|
22
|
+
}
|
|
23
|
+
if (module.value.type === "rawscript" && module.value.content && module.value.content.startsWith("!inline")) {
|
|
24
|
+
const path = module.value.content.split(" ")[1];
|
|
25
|
+
const pathPrefix = path.split(".")[0];
|
|
26
|
+
const pathSuffix = path.split(".").slice(1).join(".");
|
|
27
|
+
// new path is the module id with the same suffix
|
|
28
|
+
const newPath = module.id + "." + pathSuffix;
|
|
29
|
+
try {
|
|
30
|
+
module.value.content = await fileReader(path);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
logger.error(`Script file ${path} not found`);
|
|
34
|
+
// try new path
|
|
35
|
+
try {
|
|
36
|
+
module.value.content = await fileReader(newPath);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
logger.error(`Script file ${newPath} not found`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// rename the file if the prefix is different from the module id (fix old naming)
|
|
43
|
+
if (pathPrefix != module.id && renamer) {
|
|
44
|
+
logger.info(`Renaming ${path} to ${module.id}.${pathSuffix}`);
|
|
45
|
+
try {
|
|
46
|
+
renamer(localPath + path, localPath + module.id + "." + pathSuffix);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
logger.info(`Failed to rename ${path} to ${module.id}.${pathSuffix}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const lock = module.value.lock;
|
|
53
|
+
if (removeLocks && removeLocks.includes(path)) {
|
|
54
|
+
module.value.lock = undefined;
|
|
55
|
+
// delete the file if the prefix is different from the module id (fix old naming)
|
|
56
|
+
if (lock && lock != "") {
|
|
57
|
+
const path = lock.split(" ")[1];
|
|
58
|
+
const pathPrefix = path.split(".")[0];
|
|
59
|
+
if (pathPrefix != module.id && deleter) {
|
|
60
|
+
logger.info(`Deleting ${path}`);
|
|
61
|
+
try {
|
|
62
|
+
deleter(localPath + path);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
logger.error(`Failed to delete ${path}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (lock &&
|
|
71
|
+
typeof lock == "string" &&
|
|
72
|
+
lock.trimStart().startsWith("!inline ")) {
|
|
73
|
+
const path = lock.split(" ")[1];
|
|
74
|
+
try {
|
|
75
|
+
module.value.lock = await fileReader(path.replaceAll("/", separator));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
logger.error(`Lock file ${path} not found`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (module.value.type === "forloopflow" || module.value.type === "whileloopflow") {
|
|
83
|
+
await replaceInlineScripts(module.value.modules, fileReader, logger, localPath, separator, removeLocks);
|
|
84
|
+
}
|
|
85
|
+
else if (module.value.type === "branchall") {
|
|
86
|
+
await Promise.all(module.value.branches.map(async (branch) => {
|
|
87
|
+
await replaceInlineScripts(branch.modules, fileReader, logger, localPath, separator, removeLocks);
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
else if (module.value.type === "branchone") {
|
|
91
|
+
await Promise.all(module.value.branches.map(async (branch) => {
|
|
92
|
+
await replaceInlineScripts(branch.modules, fileReader, logger, localPath, separator, removeLocks);
|
|
93
|
+
}));
|
|
94
|
+
await replaceInlineScripts(module.value.default, fileReader, logger, localPath, separator, removeLocks);
|
|
95
|
+
}
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./parse-schema";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./parse-schema"), exports);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type alias for enum values - can be an array of strings or undefined
|
|
3
|
+
*/
|
|
4
|
+
export type EnumType = string[] | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Represents a property in a JSON schema with various validation and display options
|
|
7
|
+
*/
|
|
8
|
+
export interface SchemaProperty {
|
|
9
|
+
type: string | undefined;
|
|
10
|
+
description?: string;
|
|
11
|
+
pattern?: string;
|
|
12
|
+
default?: any;
|
|
13
|
+
enum?: EnumType;
|
|
14
|
+
contentEncoding?: 'base64' | 'binary';
|
|
15
|
+
format?: string;
|
|
16
|
+
items?: {
|
|
17
|
+
type?: 'string' | 'number' | 'bytes' | 'object' | 'resource';
|
|
18
|
+
contentEncoding?: 'base64';
|
|
19
|
+
enum?: string[];
|
|
20
|
+
resourceType?: string;
|
|
21
|
+
properties?: {
|
|
22
|
+
[name: string]: SchemaProperty;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
min?: number;
|
|
26
|
+
max?: number;
|
|
27
|
+
currency?: string;
|
|
28
|
+
currencyLocale?: string;
|
|
29
|
+
multiselect?: boolean;
|
|
30
|
+
customErrorMessage?: string;
|
|
31
|
+
properties?: {
|
|
32
|
+
[name: string]: SchemaProperty;
|
|
33
|
+
};
|
|
34
|
+
required?: string[];
|
|
35
|
+
showExpr?: string;
|
|
36
|
+
password?: boolean;
|
|
37
|
+
order?: string[];
|
|
38
|
+
nullable?: boolean;
|
|
39
|
+
dateFormat?: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
placeholder?: string;
|
|
42
|
+
oneOf?: SchemaProperty[];
|
|
43
|
+
originalType?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Converts argument signature types to JSON schema properties.
|
|
47
|
+
* This function handles various Windmill-specific types and converts them
|
|
48
|
+
* to standard JSON schema format while preserving existing property metadata.
|
|
49
|
+
*
|
|
50
|
+
* @param t - The argument signature type definition (can be string or complex object types)
|
|
51
|
+
* @param oldS - Existing schema property to update with new type information
|
|
52
|
+
*/
|
|
53
|
+
export declare function argSigToJsonSchemaType(t: string | {
|
|
54
|
+
resource: string | null;
|
|
55
|
+
} | {
|
|
56
|
+
list: (string | {
|
|
57
|
+
name?: string;
|
|
58
|
+
props?: {
|
|
59
|
+
key: string;
|
|
60
|
+
typ: any;
|
|
61
|
+
}[];
|
|
62
|
+
}) | {
|
|
63
|
+
str: any;
|
|
64
|
+
} | {
|
|
65
|
+
object: {
|
|
66
|
+
name?: string;
|
|
67
|
+
props?: {
|
|
68
|
+
key: string;
|
|
69
|
+
typ: any;
|
|
70
|
+
}[];
|
|
71
|
+
};
|
|
72
|
+
} | null;
|
|
73
|
+
} | {
|
|
74
|
+
dynselect: string;
|
|
75
|
+
} | {
|
|
76
|
+
str: string[] | null;
|
|
77
|
+
} | {
|
|
78
|
+
object: {
|
|
79
|
+
name?: string;
|
|
80
|
+
props?: {
|
|
81
|
+
key: string;
|
|
82
|
+
typ: any;
|
|
83
|
+
}[];
|
|
84
|
+
};
|
|
85
|
+
} | {
|
|
86
|
+
oneof: {
|
|
87
|
+
label: string;
|
|
88
|
+
properties: {
|
|
89
|
+
key: string;
|
|
90
|
+
typ: any;
|
|
91
|
+
}[];
|
|
92
|
+
}[];
|
|
93
|
+
}, oldS: SchemaProperty): void;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.argSigToJsonSchemaType = argSigToJsonSchemaType;
|
|
4
|
+
/**
|
|
5
|
+
* Converts argument signature types to JSON schema properties.
|
|
6
|
+
* This function handles various Windmill-specific types and converts them
|
|
7
|
+
* to standard JSON schema format while preserving existing property metadata.
|
|
8
|
+
*
|
|
9
|
+
* @param t - The argument signature type definition (can be string or complex object types)
|
|
10
|
+
* @param oldS - Existing schema property to update with new type information
|
|
11
|
+
*/
|
|
12
|
+
function argSigToJsonSchemaType(t, oldS) {
|
|
13
|
+
const newS = { type: '' };
|
|
14
|
+
if (t === 'int') {
|
|
15
|
+
newS.type = 'integer';
|
|
16
|
+
}
|
|
17
|
+
else if (t === 'float') {
|
|
18
|
+
newS.type = 'number';
|
|
19
|
+
}
|
|
20
|
+
else if (t === 'bool') {
|
|
21
|
+
newS.type = 'boolean';
|
|
22
|
+
}
|
|
23
|
+
else if (t === 'email') {
|
|
24
|
+
newS.type = 'string';
|
|
25
|
+
newS.format = 'email';
|
|
26
|
+
}
|
|
27
|
+
else if (t === 'sql') {
|
|
28
|
+
newS.type = 'string';
|
|
29
|
+
newS.format = 'sql';
|
|
30
|
+
}
|
|
31
|
+
else if (t === 'yaml') {
|
|
32
|
+
newS.type = 'string';
|
|
33
|
+
newS.format = 'yaml';
|
|
34
|
+
}
|
|
35
|
+
else if (t === 'bytes') {
|
|
36
|
+
newS.type = 'string';
|
|
37
|
+
newS.contentEncoding = 'base64';
|
|
38
|
+
newS.originalType = 'bytes';
|
|
39
|
+
}
|
|
40
|
+
else if (t === 'datetime') {
|
|
41
|
+
newS.type = 'string';
|
|
42
|
+
newS.format = 'date-time';
|
|
43
|
+
}
|
|
44
|
+
else if (typeof t !== 'string' && 'oneof' in t) {
|
|
45
|
+
newS.type = 'object';
|
|
46
|
+
if (t.oneof) {
|
|
47
|
+
newS.oneOf = t.oneof.map((obj) => {
|
|
48
|
+
const oldObjS = oldS.oneOf?.find((o) => o?.title === obj.label) ?? undefined;
|
|
49
|
+
const properties = {};
|
|
50
|
+
for (const prop of obj.properties) {
|
|
51
|
+
if (oldObjS?.properties && prop.key in oldObjS?.properties) {
|
|
52
|
+
properties[prop.key] = oldObjS?.properties[prop.key];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
properties[prop.key] = { description: '', type: '' };
|
|
56
|
+
}
|
|
57
|
+
argSigToJsonSchemaType(prop.typ, properties[prop.key]);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
type: 'object',
|
|
61
|
+
title: obj.label,
|
|
62
|
+
properties,
|
|
63
|
+
order: oldObjS?.order ?? undefined
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (typeof t !== 'string' && `object` in t) {
|
|
69
|
+
newS.type = 'object';
|
|
70
|
+
if (t.object.name) {
|
|
71
|
+
newS.format = `resource-${t.object.name}`;
|
|
72
|
+
}
|
|
73
|
+
if (t.object.props) {
|
|
74
|
+
const properties = {};
|
|
75
|
+
for (const prop of t.object.props) {
|
|
76
|
+
if (oldS.properties && prop.key in oldS.properties) {
|
|
77
|
+
properties[prop.key] = oldS.properties[prop.key];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
properties[prop.key] = { description: '', type: '' };
|
|
81
|
+
}
|
|
82
|
+
argSigToJsonSchemaType(prop.typ, properties[prop.key]);
|
|
83
|
+
}
|
|
84
|
+
newS.properties = properties;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (typeof t !== 'string' && `str` in t) {
|
|
88
|
+
newS.type = 'string';
|
|
89
|
+
if (t.str) {
|
|
90
|
+
newS.originalType = 'enum';
|
|
91
|
+
newS.enum = t.str;
|
|
92
|
+
}
|
|
93
|
+
else if (oldS.originalType == 'string' && oldS.enum) {
|
|
94
|
+
newS.originalType = 'string';
|
|
95
|
+
newS.enum = oldS.enum;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
newS.originalType = 'string';
|
|
99
|
+
newS.enum = undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (typeof t !== 'string' && `resource` in t) {
|
|
103
|
+
newS.type = 'object';
|
|
104
|
+
newS.format = `resource-${t.resource}`;
|
|
105
|
+
}
|
|
106
|
+
else if (typeof t !== 'string' && `dynselect` in t) {
|
|
107
|
+
newS.type = 'object';
|
|
108
|
+
newS.format = `dynselect-${t.dynselect}`;
|
|
109
|
+
}
|
|
110
|
+
else if (typeof t !== 'string' && `list` in t) {
|
|
111
|
+
newS.type = 'array';
|
|
112
|
+
if (t.list === 'int' || t.list === 'float') {
|
|
113
|
+
newS.items = { type: 'number' };
|
|
114
|
+
newS.originalType = 'number[]';
|
|
115
|
+
}
|
|
116
|
+
else if (t.list === 'bytes') {
|
|
117
|
+
newS.items = { type: 'string', contentEncoding: 'base64' };
|
|
118
|
+
newS.originalType = 'bytes[]';
|
|
119
|
+
}
|
|
120
|
+
else if (t.list && typeof t.list == 'object' && 'str' in t.list && t.list.str) {
|
|
121
|
+
newS.items = { type: 'string', enum: t.list.str };
|
|
122
|
+
newS.originalType = 'enum[]';
|
|
123
|
+
}
|
|
124
|
+
else if (t.list == 'string' || (t.list && typeof t.list == 'object' && 'str' in t.list)) {
|
|
125
|
+
newS.items = { type: 'string', enum: oldS.items?.enum };
|
|
126
|
+
newS.originalType = 'string[]';
|
|
127
|
+
}
|
|
128
|
+
else if (t.list && typeof t.list == 'object' && 'resource' in t.list && t.list.resource) {
|
|
129
|
+
newS.items = {
|
|
130
|
+
type: 'resource',
|
|
131
|
+
resourceType: t.list.resource
|
|
132
|
+
};
|
|
133
|
+
newS.originalType = 'resource[]';
|
|
134
|
+
}
|
|
135
|
+
else if (t.list && typeof t.list == 'object' && 'object' in t.list && t.list.object) {
|
|
136
|
+
if (t.list.object.name) {
|
|
137
|
+
newS.format = `resource-${t.list.object.name}`;
|
|
138
|
+
}
|
|
139
|
+
if (t.list.object.props && t.list.object.props.length > 0) {
|
|
140
|
+
const properties = {};
|
|
141
|
+
for (const prop of t.list.object.props) {
|
|
142
|
+
properties[prop.key] = { description: '', type: '' };
|
|
143
|
+
argSigToJsonSchemaType(prop.typ, properties[prop.key]);
|
|
144
|
+
}
|
|
145
|
+
newS.items = { type: 'object', properties: properties };
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
newS.items = { type: 'object' };
|
|
149
|
+
}
|
|
150
|
+
newS.originalType = 'record[]';
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
newS.items = { type: 'object' };
|
|
154
|
+
newS.originalType = 'object[]';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
newS.type = 'object';
|
|
159
|
+
}
|
|
160
|
+
const preservedFields = [
|
|
161
|
+
'description',
|
|
162
|
+
'pattern',
|
|
163
|
+
'min',
|
|
164
|
+
'max',
|
|
165
|
+
'currency',
|
|
166
|
+
'currencyLocale',
|
|
167
|
+
'multiselect',
|
|
168
|
+
'customErrorMessage',
|
|
169
|
+
'required',
|
|
170
|
+
'showExpr',
|
|
171
|
+
'password',
|
|
172
|
+
'order',
|
|
173
|
+
'dateFormat',
|
|
174
|
+
'title',
|
|
175
|
+
'placeholder'
|
|
176
|
+
];
|
|
177
|
+
preservedFields.forEach((field) => {
|
|
178
|
+
// @ts-ignore
|
|
179
|
+
if (oldS[field] !== undefined) {
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
newS[field] = oldS[field];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
if (oldS.type != newS.type) {
|
|
185
|
+
for (const prop of Object.getOwnPropertyNames(newS)) {
|
|
186
|
+
if (prop != 'description') {
|
|
187
|
+
// @ts-ignore
|
|
188
|
+
delete oldS[prop];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else if ((oldS.format == 'date' || oldS.format === 'date-time') && newS.format == 'string') {
|
|
193
|
+
newS.format = oldS.format;
|
|
194
|
+
}
|
|
195
|
+
else if (newS.format == 'date-time' && oldS.format == 'date') {
|
|
196
|
+
newS.format = 'date';
|
|
197
|
+
}
|
|
198
|
+
else if (oldS.items?.type != newS.items?.type) {
|
|
199
|
+
delete oldS.items;
|
|
200
|
+
}
|
|
201
|
+
if (oldS.format && !newS.format) {
|
|
202
|
+
oldS.format = undefined;
|
|
203
|
+
}
|
|
204
|
+
Object.assign(oldS, newS);
|
|
205
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./path-assigner";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./path-assigner"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RawScript } from "../gen/types.gen";
|
|
2
|
+
/**
|
|
3
|
+
* Union type of all supported programming languages in Windmill
|
|
4
|
+
*/
|
|
5
|
+
export type SupportedLanguage = RawScript["language"] | "frontend" | "bunnative" | "oracledb" | "rust" | "csharp" | "nu" | "ansible" | "java" | "duckdb";
|
|
6
|
+
/**
|
|
7
|
+
* Mapping of supported languages to their file extensions
|
|
8
|
+
*/
|
|
9
|
+
export declare const LANGUAGE_EXTENSIONS: Record<SupportedLanguage, string>;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the appropriate file extension for a given programming language.
|
|
12
|
+
* Handles special cases for TypeScript variants based on the default runtime.
|
|
13
|
+
*
|
|
14
|
+
* @param language - The programming language to get extension for
|
|
15
|
+
* @param defaultTs - Default TypeScript runtime ("bun" or "deno")
|
|
16
|
+
* @returns File extension string (without the dot)
|
|
17
|
+
*/
|
|
18
|
+
export declare function getLanguageExtension(language: SupportedLanguage, defaultTs?: "bun" | "deno"): string;
|
|
19
|
+
/**
|
|
20
|
+
* Assigns a file path for an inline script based on its ID and language.
|
|
21
|
+
* Returns both the base path and extension as separate components.
|
|
22
|
+
*
|
|
23
|
+
* @param id - Unique identifier for the script
|
|
24
|
+
* @param language - Programming language of the script
|
|
25
|
+
* @param defaultTs - Default TypeScript runtime ("bun" or "deno")
|
|
26
|
+
* @returns Tuple containing [basePath, extension]
|
|
27
|
+
*/
|
|
28
|
+
export declare function assignPath(id: string, language: SupportedLanguage, defaultTs?: "bun" | "deno"): [string, string];
|