windmill-client 1.285.4 → 1.286.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +6 -0
- package/dist/client.js +135 -1
- package/dist/core/OpenAPI.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ export declare function getResource(path?: string, undefinedIfEmpty?: boolean):
|
|
|
24
24
|
* @returns root job id
|
|
25
25
|
*/
|
|
26
26
|
export declare function getRootJobId(jobId?: string): Promise<string>;
|
|
27
|
+
export declare function runScript(path?: string | null, hash_?: string | null, args?: Record<string, any> | null, verbose?: boolean): Promise<any>;
|
|
28
|
+
export declare function waitJob(jobId: string, verbose?: boolean, assertResultIsNotNull?: boolean): Promise<any>;
|
|
29
|
+
export declare function getResult(jobId: string): Promise<any>;
|
|
30
|
+
export declare function getResultMaybe(jobId: string): Promise<any>;
|
|
31
|
+
export declare function task<P, T>(f: (_: P) => T): (_: P) => Promise<T>;
|
|
32
|
+
export declare function runScriptAsync(path: string | null, hash_: string | null, args: Record<string, any> | null, scheduledInSeconds?: number | null): Promise<string>;
|
|
27
33
|
/**
|
|
28
34
|
* Resolve a resource value in case the default value was picked because the input payload was undefined
|
|
29
35
|
* @param obj resource value or path of the resource under the format `$res:path`
|
package/dist/client.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.uint8ArrayToBase64 = exports.base64ToUint8Array = exports.getIdToken = exports.getResumeEndpoints = exports.getResumeUrls = exports.writeS3File = exports.loadS3FileStream = exports.loadS3File = exports.denoS3LightClientSettings = exports.databaseUrlFromResource = exports.setVariable = exports.getVariable = exports.getState = exports.getInternalState = exports.setState = exports.setInternalState = exports.setResource = exports.getStatePath = exports.resolveDefaultResource = exports.getRootJobId = exports.getResource = exports.getWorkspace = exports.setClient = exports.SHARED_FOLDER = exports.WorkspaceService = exports.UserService = exports.SettingsService = exports.ScheduleService = exports.ScriptService = exports.VariableService = exports.ResourceService = exports.JobService = exports.GroupService = exports.GranularAclService = exports.FlowService = exports.AuditService = exports.AdminService = void 0;
|
|
12
|
+
exports.uint8ArrayToBase64 = exports.base64ToUint8Array = exports.getIdToken = exports.getResumeEndpoints = exports.getResumeUrls = exports.writeS3File = exports.loadS3FileStream = exports.loadS3File = exports.denoS3LightClientSettings = exports.databaseUrlFromResource = exports.setVariable = exports.getVariable = exports.getState = exports.getInternalState = exports.setState = exports.setInternalState = exports.setResource = exports.getStatePath = exports.resolveDefaultResource = exports.runScriptAsync = exports.task = exports.getResultMaybe = exports.getResult = exports.waitJob = exports.runScript = exports.getRootJobId = exports.getResource = exports.getWorkspace = exports.setClient = exports.SHARED_FOLDER = exports.WorkspaceService = exports.UserService = exports.SettingsService = exports.ScheduleService = exports.ScriptService = exports.VariableService = exports.ResourceService = exports.JobService = exports.GroupService = exports.GranularAclService = exports.FlowService = exports.AuditService = exports.AdminService = void 0;
|
|
13
13
|
const index_1 = require("./index");
|
|
14
14
|
const index_2 = require("./index");
|
|
15
15
|
var index_3 = require("./index");
|
|
@@ -105,6 +105,140 @@ function getRootJobId(jobId) {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
exports.getRootJobId = getRootJobId;
|
|
108
|
+
function runScript(path = null, hash_ = null, args = null, verbose = false) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
args = args || {};
|
|
111
|
+
if (verbose) {
|
|
112
|
+
console.info(`running \`${path}\` synchronously with args:`, args);
|
|
113
|
+
}
|
|
114
|
+
const jobId = yield runScriptAsync(path, hash_, args);
|
|
115
|
+
return yield waitJob(jobId, verbose);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.runScript = runScript;
|
|
119
|
+
function waitJob(jobId, verbose = false, assertResultIsNotNull = false) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
while (true) {
|
|
122
|
+
// Implement your HTTP request logic here to get job result
|
|
123
|
+
const resultRes = yield getResult(jobId);
|
|
124
|
+
const started = resultRes.started;
|
|
125
|
+
const completed = resultRes.completed;
|
|
126
|
+
const success = resultRes.success;
|
|
127
|
+
if (!started && verbose) {
|
|
128
|
+
console.info(`job ${jobId} has not started yet`);
|
|
129
|
+
}
|
|
130
|
+
if (completed) {
|
|
131
|
+
const result = resultRes.result;
|
|
132
|
+
if (success) {
|
|
133
|
+
if (result === null && assertResultIsNotNull) {
|
|
134
|
+
throw new Error("Result was null");
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const error = result.error;
|
|
140
|
+
throw new Error(`Job ${jobId} was not successful: ${error}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (verbose) {
|
|
144
|
+
console.info(`sleeping 0.5 seconds for jobId: ${jobId}`);
|
|
145
|
+
}
|
|
146
|
+
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
exports.waitJob = waitJob;
|
|
151
|
+
function getResult(jobId) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
!clientSet && setClient();
|
|
154
|
+
const workspace = getWorkspace();
|
|
155
|
+
return yield index_1.JobService.getCompletedJobResult({ workspace, id: jobId });
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
exports.getResult = getResult;
|
|
159
|
+
function getResultMaybe(jobId) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
!clientSet && setClient();
|
|
162
|
+
const workspace = getWorkspace();
|
|
163
|
+
return yield index_1.JobService.getCompletedJobResultMaybe({ workspace, id: jobId });
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
exports.getResultMaybe = getResultMaybe;
|
|
167
|
+
const STRIP_COMMENTS = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/gm;
|
|
168
|
+
const ARGUMENT_NAMES = /([^\s,]+)/g;
|
|
169
|
+
function getParamNames(func) {
|
|
170
|
+
const fnStr = func.toString().replace(STRIP_COMMENTS, "");
|
|
171
|
+
let result = fnStr
|
|
172
|
+
.slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")"))
|
|
173
|
+
.match(ARGUMENT_NAMES);
|
|
174
|
+
if (result === null)
|
|
175
|
+
result = [];
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
function task(f) {
|
|
179
|
+
!clientSet && setClient();
|
|
180
|
+
return (...y) => __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const args = {};
|
|
182
|
+
const paramNames = getParamNames(f);
|
|
183
|
+
y.forEach((x, i) => (args[paramNames[i]] = x));
|
|
184
|
+
let req = yield fetch(`${index_2.OpenAPI.BASE}/w/${getWorkspace()}/jobs/run/workflow_as_code/${getEnv("WM_JOB_ID")}/${f.name}`, {
|
|
185
|
+
method: "POST",
|
|
186
|
+
headers: {
|
|
187
|
+
"Content-Type": "application/json",
|
|
188
|
+
Authorization: `Bearer ${getEnv("WM_TOKEN")}`,
|
|
189
|
+
},
|
|
190
|
+
body: JSON.stringify({ args }),
|
|
191
|
+
});
|
|
192
|
+
let jobId = yield req.text();
|
|
193
|
+
return yield waitJob(jobId);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
exports.task = task;
|
|
197
|
+
function runScriptAsync(path, hash_, args, scheduledInSeconds = null) {
|
|
198
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
!clientSet && setClient();
|
|
200
|
+
// Create a script job and return its job id.
|
|
201
|
+
if (path && hash_) {
|
|
202
|
+
throw new Error("path and hash_ are mutually exclusive");
|
|
203
|
+
}
|
|
204
|
+
args = args || {};
|
|
205
|
+
const params = {};
|
|
206
|
+
if (scheduledInSeconds) {
|
|
207
|
+
params["scheduled_in_secs"] = scheduledInSeconds;
|
|
208
|
+
}
|
|
209
|
+
let parentJobId = getEnv("WM_JOB_ID");
|
|
210
|
+
if (parentJobId !== undefined) {
|
|
211
|
+
params["parent_job"] = parentJobId;
|
|
212
|
+
}
|
|
213
|
+
let rootJobId = getEnv("WM_ROOT_FLOW_JOB_ID");
|
|
214
|
+
if (rootJobId != undefined) {
|
|
215
|
+
params["root_job"] = rootJobId;
|
|
216
|
+
}
|
|
217
|
+
let endpoint;
|
|
218
|
+
if (path) {
|
|
219
|
+
endpoint = `/w/${getWorkspace()}/jobs/run/p/${path}`;
|
|
220
|
+
}
|
|
221
|
+
else if (hash_) {
|
|
222
|
+
endpoint = `/w/${getWorkspace()}/jobs/run/h/${hash_}`;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
throw new Error("path or hash_ must be provided");
|
|
226
|
+
}
|
|
227
|
+
let url = new URL(index_2.OpenAPI.BASE + endpoint);
|
|
228
|
+
url.search = new URLSearchParams(params).toString();
|
|
229
|
+
return fetch(url, {
|
|
230
|
+
method: "POST",
|
|
231
|
+
headers: {
|
|
232
|
+
"Content-Type": "application/json",
|
|
233
|
+
Authorization: `Bearer ${index_2.OpenAPI.TOKEN}`,
|
|
234
|
+
},
|
|
235
|
+
body: JSON.stringify(args),
|
|
236
|
+
})
|
|
237
|
+
.then((res) => res.json())
|
|
238
|
+
.then((data) => data.id);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
exports.runScriptAsync = runScriptAsync;
|
|
108
242
|
/**
|
|
109
243
|
* Resolve a resource value in case the default value was picked because the input payload was undefined
|
|
110
244
|
* @param obj resource value or path of the resource under the format `$res:path`
|
package/dist/core/OpenAPI.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -176,4 +176,4 @@ export { VariableService } from './services/VariableService';
|
|
|
176
176
|
export { WorkerService } from './services/WorkerService';
|
|
177
177
|
export { WorkspaceService } from './services/WorkspaceService';
|
|
178
178
|
export type { S3Object, DenoS3LightClientSettings } from "./s3Types";
|
|
179
|
-
export { type Base64, setClient, getVariable, setVariable, getResource, setResource, getResumeUrls, setState, getState, getIdToken, denoS3LightClientSettings, loadS3FileStream, loadS3File, writeS3File } from "./client";
|
|
179
|
+
export { type Base64, setClient, getVariable, setVariable, getResource, setResource, getResumeUrls, setState, getState, getIdToken, denoS3LightClientSettings, loadS3FileStream, loadS3File, writeS3File, task, runScript, runScriptAsync, waitJob, getRootJobId } from "./client";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VariableService = exports.UserService = exports.SettingsService = exports.SettingService = exports.ScriptService = exports.ScheduleService = exports.ResourceService = exports.RawAppService = exports.OidcService = exports.OauthService = exports.MetricsService = exports.JobService = exports.IntegrationService = exports.InputService = exports.HelpersService = exports.GroupService = exports.GranularAclService = exports.FolderService = exports.FlowService = exports.FavoriteService = exports.DraftService = exports.ConfigService = exports.ConcurrencyGroupsService = exports.CaptureService = exports.AuditService = exports.AppService = exports.AdminService = exports.WindmillFilePreview = exports.Script = exports.RunnableType = exports.RawScriptForDependencies = exports.RawScript = exports.QueuedJob = exports.Preview = exports.Policy = exports.NewScript = exports.MainArgSignature = exports.ListableApp = exports.LargeFileStorage = exports.Job = exports.GlobalUserInfo = exports.FlowStatusModule = exports.CompletedJob = exports.AuditLog = exports.AppWithLastVersion = exports.ActionKind = exports.OpenAPI = exports.CancelError = exports.CancelablePromise = exports.ApiError = void 0;
|
|
4
|
-
exports.writeS3File = exports.loadS3File = exports.loadS3FileStream = exports.denoS3LightClientSettings = exports.getIdToken = exports.getState = exports.setState = exports.getResumeUrls = exports.setResource = exports.getResource = exports.setVariable = exports.getVariable = exports.setClient = exports.WorkspaceService = exports.WorkerService = void 0;
|
|
4
|
+
exports.getRootJobId = exports.waitJob = exports.runScriptAsync = exports.runScript = exports.task = exports.writeS3File = exports.loadS3File = exports.loadS3FileStream = exports.denoS3LightClientSettings = exports.getIdToken = exports.getState = exports.setState = exports.getResumeUrls = exports.setResource = exports.getResource = exports.setVariable = exports.getVariable = exports.setClient = exports.WorkspaceService = exports.WorkerService = void 0;
|
|
5
5
|
/* generated using openapi-typescript-codegen -- do no edit */
|
|
6
6
|
/* istanbul ignore file */
|
|
7
7
|
/* tslint:disable */
|
|
@@ -123,3 +123,8 @@ Object.defineProperty(exports, "denoS3LightClientSettings", { enumerable: true,
|
|
|
123
123
|
Object.defineProperty(exports, "loadS3FileStream", { enumerable: true, get: function () { return client_1.loadS3FileStream; } });
|
|
124
124
|
Object.defineProperty(exports, "loadS3File", { enumerable: true, get: function () { return client_1.loadS3File; } });
|
|
125
125
|
Object.defineProperty(exports, "writeS3File", { enumerable: true, get: function () { return client_1.writeS3File; } });
|
|
126
|
+
Object.defineProperty(exports, "task", { enumerable: true, get: function () { return client_1.task; } });
|
|
127
|
+
Object.defineProperty(exports, "runScript", { enumerable: true, get: function () { return client_1.runScript; } });
|
|
128
|
+
Object.defineProperty(exports, "runScriptAsync", { enumerable: true, get: function () { return client_1.runScriptAsync; } });
|
|
129
|
+
Object.defineProperty(exports, "waitJob", { enumerable: true, get: function () { return client_1.waitJob; } });
|
|
130
|
+
Object.defineProperty(exports, "getRootJobId", { enumerable: true, get: function () { return client_1.getRootJobId; } });
|