windmill-cli 1.458.3 → 1.460.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/esm/gen/core/OpenAPI.js +1 -1
- package/esm/gen/services.gen.js +19 -0
- package/esm/instance.js +2 -0
- package/esm/main.js +5 -2
- package/esm/pull.js +2 -2
- package/esm/settings.js +33 -5
- package/esm/sync.js +75 -14
- package/esm/trigger.js +149 -0
- package/esm/types.js +22 -1
- package/package.json +1 -1
- package/types/conf.d.ts +1 -0
- package/types/conf.d.ts.map +1 -1
- package/types/gen/services.gen.d.ts +10 -1
- package/types/gen/services.gen.d.ts.map +1 -1
- package/types/gen/types.gen.d.ts +11 -1
- package/types/gen/types.gen.d.ts.map +1 -1
- package/types/instance.d.ts.map +1 -1
- package/types/main.d.ts +3 -2
- package/types/main.d.ts.map +1 -1
- package/types/pull.d.ts +1 -1
- package/types/pull.d.ts.map +1 -1
- package/types/settings.d.ts +3 -0
- package/types/settings.d.ts.map +1 -1
- package/types/sync.d.ts +3 -0
- package/types/sync.d.ts.map +1 -1
- package/types/trigger.d.ts +21 -0
- package/types/trigger.d.ts.map +1 -0
- package/types/types.d.ts +1 -1
- package/types/types.d.ts.map +1 -1
package/esm/gen/core/OpenAPI.js
CHANGED
package/esm/gen/services.gen.js
CHANGED
|
@@ -6772,6 +6772,25 @@ export const setPostgresTriggerEnabled = (data) => {
|
|
|
6772
6772
|
mediaType: 'application/json'
|
|
6773
6773
|
});
|
|
6774
6774
|
};
|
|
6775
|
+
/**
|
|
6776
|
+
* test postgres connection
|
|
6777
|
+
* @param data The data for the request.
|
|
6778
|
+
* @param data.workspace
|
|
6779
|
+
* @param data.requestBody test postgres connection
|
|
6780
|
+
* @returns string successfuly connected to postgres
|
|
6781
|
+
* @throws ApiError
|
|
6782
|
+
*/
|
|
6783
|
+
export const testPostgresConnection = (data) => {
|
|
6784
|
+
return __request(OpenAPI, {
|
|
6785
|
+
method: 'POST',
|
|
6786
|
+
url: '/w/{workspace}/postgres_triggers/test',
|
|
6787
|
+
path: {
|
|
6788
|
+
workspace: data.workspace
|
|
6789
|
+
},
|
|
6790
|
+
body: data.requestBody,
|
|
6791
|
+
mediaType: 'application/json'
|
|
6792
|
+
});
|
|
6793
|
+
};
|
|
6775
6794
|
/**
|
|
6776
6795
|
* list instance groups
|
|
6777
6796
|
* @returns InstanceGroup instance group list
|
package/esm/instance.js
CHANGED
|
@@ -250,6 +250,7 @@ async function instancePull(opts) {
|
|
|
250
250
|
baseUrl: undefined,
|
|
251
251
|
includeGroups: true,
|
|
252
252
|
includeSchedules: true,
|
|
253
|
+
includeTriggers: true,
|
|
253
254
|
includeSettings: true,
|
|
254
255
|
includeUsers: true,
|
|
255
256
|
includeKey: true,
|
|
@@ -382,6 +383,7 @@ async function instancePush(opts) {
|
|
|
382
383
|
baseUrl: undefined,
|
|
383
384
|
includeGroups: true,
|
|
384
385
|
includeSchedules: true,
|
|
386
|
+
includeTriggers: true,
|
|
385
387
|
includeSettings: true,
|
|
386
388
|
includeUsers: true,
|
|
387
389
|
includeKey: true,
|
package/esm/main.js
CHANGED
|
@@ -13,6 +13,7 @@ import variable from "./variable.js";
|
|
|
13
13
|
import hub from "./hub.js";
|
|
14
14
|
import folder from "./folder.js";
|
|
15
15
|
import schedule from "./schedule.js";
|
|
16
|
+
import trigger from "./trigger.js";
|
|
16
17
|
import sync from "./sync.js";
|
|
17
18
|
import instance from "./instance.js";
|
|
18
19
|
import workerGroups from "./worker_groups.js";
|
|
@@ -26,14 +27,14 @@ import { pull, push } from "./sync.js";
|
|
|
26
27
|
import { add as workspaceAdd } from "./workspace.js";
|
|
27
28
|
import workers from "./workers.js";
|
|
28
29
|
import queues from "./queues.js";
|
|
29
|
-
export { flow, app, script, workspace, resource, user, variable, hub, folder, schedule, sync, instance, dev, hubPull, pull, push, workspaceAdd, };
|
|
30
|
+
export { flow, app, script, workspace, resource, user, variable, hub, folder, schedule, trigger, sync, instance, dev, hubPull, pull, push, workspaceAdd, };
|
|
30
31
|
// addEventListener("error", (event) => {
|
|
31
32
|
// if (event.error) {
|
|
32
33
|
// console.error("Error details of: " + event.error.message);
|
|
33
34
|
// console.error(JSON.stringify(event.error, null, 4));
|
|
34
35
|
// }
|
|
35
36
|
// });
|
|
36
|
-
export const VERSION = "1.
|
|
37
|
+
export const VERSION = "1.460.0";
|
|
37
38
|
const command = new Command()
|
|
38
39
|
.name("wmill")
|
|
39
40
|
.action(() => log.info(`Welcome to Windmill CLI ${VERSION}. Use -h for help.`))
|
|
@@ -60,6 +61,7 @@ const command = new Command()
|
|
|
60
61
|
skipResources: true,
|
|
61
62
|
skipSecrets: true,
|
|
62
63
|
includeSchedules: false,
|
|
64
|
+
includeTriggers: false,
|
|
63
65
|
}));
|
|
64
66
|
log.info(colors.green("wmill.yaml created"));
|
|
65
67
|
})
|
|
@@ -73,6 +75,7 @@ const command = new Command()
|
|
|
73
75
|
.command("hub", hub)
|
|
74
76
|
.command("folder", folder)
|
|
75
77
|
.command("schedule", schedule)
|
|
78
|
+
.command("trigger", trigger)
|
|
76
79
|
.command("dev", dev)
|
|
77
80
|
.command("sync", sync)
|
|
78
81
|
.command("instance", instance)
|
package/esm/pull.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { colors, Command, JSZip, log } from "./deps.js";
|
|
2
2
|
import { getHeaders } from "./utils.js";
|
|
3
|
-
export async function downloadZip(workspace, plainSecrets, skipVariables, skipResources, skipSecrets, includeSchedules, includeUsers, includeGroups, includeSettings, includeKey, defaultTs) {
|
|
3
|
+
export async function downloadZip(workspace, plainSecrets, skipVariables, skipResources, skipSecrets, includeSchedules, includeTriggers, includeUsers, includeGroups, includeSettings, includeKey, defaultTs) {
|
|
4
4
|
const requestHeaders = new Headers();
|
|
5
5
|
requestHeaders.set("Authorization", "Bearer " + workspace.token);
|
|
6
6
|
requestHeaders.set("Content-Type", "application/octet-stream");
|
|
@@ -13,7 +13,7 @@ export async function downloadZip(workspace, plainSecrets, skipVariables, skipRe
|
|
|
13
13
|
const zipResponse = await fetch(workspace.remote +
|
|
14
14
|
"api/w/" +
|
|
15
15
|
workspace.workspaceId +
|
|
16
|
-
`/workspaces/tarball?archive_type=zip&plain_secret=${plainSecrets ?? false}&skip_variables=${skipVariables ?? false}&skip_resources=${skipResources ?? false}&skip_secrets=${skipSecrets ?? false}&include_schedules=${includeSchedules ?? false}&include_users=${includeUsers ?? false}&include_groups=${includeGroups ?? false}&include_settings=${includeSettings ?? false}&include_key=${includeKey ?? false}&default_ts=${defaultTs ?? "bun"}`, {
|
|
16
|
+
`/workspaces/tarball?archive_type=zip&plain_secret=${plainSecrets ?? false}&skip_variables=${skipVariables ?? false}&skip_resources=${skipResources ?? false}&skip_secrets=${skipSecrets ?? false}&include_schedules=${includeSchedules ?? false}&include_triggers=${includeTriggers ?? false}&include_users=${includeUsers ?? false}&include_groups=${includeGroups ?? false}&include_settings=${includeSettings ?? false}&include_key=${includeKey ?? false}&default_ts=${defaultTs ?? "bun"}`, {
|
|
17
17
|
headers: requestHeaders,
|
|
18
18
|
method: "GET",
|
|
19
19
|
});
|
package/esm/settings.js
CHANGED
|
@@ -51,6 +51,9 @@ export async function pushWorkspaceSettings(workspace, _path, settings, localSet
|
|
|
51
51
|
default_app: remoteSettings.default_app,
|
|
52
52
|
default_scripts: remoteSettings.default_scripts,
|
|
53
53
|
name: workspaceName,
|
|
54
|
+
mute_critical_alerts: remoteSettings.mute_critical_alerts,
|
|
55
|
+
color: remoteSettings.color,
|
|
56
|
+
operator_settings: remoteSettings.operator_settings,
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
catch (err) {
|
|
@@ -120,9 +123,9 @@ export async function pushWorkspaceSettings(workspace, _path, settings, localSet
|
|
|
120
123
|
},
|
|
121
124
|
});
|
|
122
125
|
}
|
|
123
|
-
if (localSettings.error_handler
|
|
126
|
+
if (localSettings.error_handler != settings.error_handler ||
|
|
124
127
|
!deepEqual(localSettings.error_handler_extra_args, settings.error_handler_extra_args) ||
|
|
125
|
-
localSettings.error_handler_muted_on_cancel
|
|
128
|
+
localSettings.error_handler_muted_on_cancel !=
|
|
126
129
|
settings.error_handler_muted_on_cancel) {
|
|
127
130
|
log.debug(`Updating error handler...`);
|
|
128
131
|
await wmill.editErrorHandler({
|
|
@@ -134,7 +137,7 @@ export async function pushWorkspaceSettings(workspace, _path, settings, localSet
|
|
|
134
137
|
},
|
|
135
138
|
});
|
|
136
139
|
}
|
|
137
|
-
if (localSettings.deploy_to
|
|
140
|
+
if (localSettings.deploy_to != settings.deploy_to) {
|
|
138
141
|
log.debug(`Updating deploy to...`);
|
|
139
142
|
await wmill.editDeployTo({
|
|
140
143
|
workspace,
|
|
@@ -168,7 +171,7 @@ export async function pushWorkspaceSettings(workspace, _path, settings, localSet
|
|
|
168
171
|
requestBody: localSettings.default_scripts,
|
|
169
172
|
});
|
|
170
173
|
}
|
|
171
|
-
if (localSettings.default_app
|
|
174
|
+
if (localSettings.default_app != settings.default_app) {
|
|
172
175
|
log.debug(`Updating default app...`);
|
|
173
176
|
await wmill.editWorkspaceDefaultApp({
|
|
174
177
|
workspace,
|
|
@@ -177,7 +180,7 @@ export async function pushWorkspaceSettings(workspace, _path, settings, localSet
|
|
|
177
180
|
},
|
|
178
181
|
});
|
|
179
182
|
}
|
|
180
|
-
if (localSettings.name
|
|
183
|
+
if (localSettings.name != settings.name) {
|
|
181
184
|
log.debug(`Updating workspace name...`);
|
|
182
185
|
await wmill.changeWorkspaceName({
|
|
183
186
|
workspace,
|
|
@@ -186,6 +189,31 @@ export async function pushWorkspaceSettings(workspace, _path, settings, localSet
|
|
|
186
189
|
},
|
|
187
190
|
});
|
|
188
191
|
}
|
|
192
|
+
if (localSettings.mute_critical_alerts != settings.mute_critical_alerts) {
|
|
193
|
+
log.debug(`Updating mute critical alerts...`);
|
|
194
|
+
await wmill.workspaceMuteCriticalAlertsUi({
|
|
195
|
+
workspace,
|
|
196
|
+
requestBody: {
|
|
197
|
+
mute_critical_alerts: localSettings.mute_critical_alerts,
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
if (localSettings.color != settings.color) {
|
|
202
|
+
log.debug(`Updating workspace color...`);
|
|
203
|
+
await wmill.changeWorkspaceColor({
|
|
204
|
+
workspace,
|
|
205
|
+
requestBody: {
|
|
206
|
+
color: localSettings.color,
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (localSettings.operator_settings != settings.operator_settings) {
|
|
211
|
+
log.debug(`Updating operator settings...`);
|
|
212
|
+
await wmill.updateOperatorSettings({
|
|
213
|
+
workspace,
|
|
214
|
+
requestBody: localSettings.operator_settings,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
189
217
|
}
|
|
190
218
|
export async function pushWorkspaceKey(workspace, _path, key, localKey) {
|
|
191
219
|
try {
|
package/esm/sync.js
CHANGED
|
@@ -68,7 +68,7 @@ async function addCodebaseDigestIfRelevant(path, content, codebases) {
|
|
|
68
68
|
const parsed = yamlParseContent(path, content);
|
|
69
69
|
if (parsed && typeof parsed == "object") {
|
|
70
70
|
parsed["codebase"] = c.digest;
|
|
71
|
-
parsed["lock"] =
|
|
71
|
+
parsed["lock"] = "";
|
|
72
72
|
return yamlStringify(parsed, yamlOptions);
|
|
73
73
|
}
|
|
74
74
|
else {
|
|
@@ -514,6 +514,13 @@ export async function elementsToMap(els, ignore, json, skips) {
|
|
|
514
514
|
const ext = json ? ".json" : ".yaml";
|
|
515
515
|
if (!skips.includeSchedules && path.endsWith(".schedule" + ext))
|
|
516
516
|
continue;
|
|
517
|
+
if (!skips.includeTriggers &&
|
|
518
|
+
(path.endsWith(".http_trigger" + ext) ||
|
|
519
|
+
path.endsWith(".websocket_trigger" + ext) ||
|
|
520
|
+
path.endsWith(".kafka_trigger" + ext) ||
|
|
521
|
+
path.endsWith(".nats_trigger" + ext) ||
|
|
522
|
+
path.endsWith(".postgres_trigger" + ext)))
|
|
523
|
+
continue;
|
|
517
524
|
if (!skips.includeUsers && path.endsWith(".user" + ext))
|
|
518
525
|
continue;
|
|
519
526
|
if (!skips.includeGroups && path.endsWith(".group" + ext))
|
|
@@ -649,13 +656,20 @@ async function compareDynFSElement(els1, els2, ignore, json, skips, ignoreMetada
|
|
|
649
656
|
continue;
|
|
650
657
|
}
|
|
651
658
|
}
|
|
652
|
-
changes.push({
|
|
659
|
+
changes.push({
|
|
660
|
+
name: "edited",
|
|
661
|
+
path: k,
|
|
662
|
+
after: v,
|
|
663
|
+
before: m2[k],
|
|
664
|
+
codebase: codebaseChanges[k],
|
|
665
|
+
});
|
|
653
666
|
}
|
|
654
667
|
}
|
|
655
668
|
const remoteCodebase = {};
|
|
656
669
|
for (const [k] of Object.entries(m2)) {
|
|
657
670
|
if (m1[k] === undefined) {
|
|
658
|
-
if (!ignoreMetadataDeletion ||
|
|
671
|
+
if (!ignoreMetadataDeletion ||
|
|
672
|
+
(!k?.endsWith(".script.yaml") && !k?.endsWith(".script.json"))) {
|
|
659
673
|
changes.push({ name: "deleted", path: k });
|
|
660
674
|
}
|
|
661
675
|
else if (k?.endsWith(".script.yaml")) {
|
|
@@ -668,12 +682,18 @@ async function compareDynFSElement(els1, els2, ignore, json, skips, ignoreMetada
|
|
|
668
682
|
}
|
|
669
683
|
for (const [k, v] of Object.entries(remoteCodebase)) {
|
|
670
684
|
const tsFile = k.replace(".script.yaml", ".ts");
|
|
671
|
-
if (changes.find(c => c.path == tsFile && (c.name == "edited" || c.name == "deleted"))) {
|
|
685
|
+
if (changes.find((c) => c.path == tsFile && (c.name == "edited" || c.name == "deleted"))) {
|
|
672
686
|
continue;
|
|
673
687
|
}
|
|
674
688
|
let c = findCodebase(tsFile, codebases);
|
|
675
689
|
if (c?.digest != v) {
|
|
676
|
-
changes.push({
|
|
690
|
+
changes.push({
|
|
691
|
+
name: "edited",
|
|
692
|
+
path: tsFile,
|
|
693
|
+
codebase: v,
|
|
694
|
+
before: m1[tsFile],
|
|
695
|
+
after: m2[tsFile],
|
|
696
|
+
});
|
|
677
697
|
}
|
|
678
698
|
}
|
|
679
699
|
for (const change of changes) {
|
|
@@ -716,21 +736,28 @@ function getOrderFromPath(p) {
|
|
|
716
736
|
else if (typ == "schedule") {
|
|
717
737
|
return 7;
|
|
718
738
|
}
|
|
719
|
-
else if (typ == "
|
|
739
|
+
else if (typ == "http_trigger" ||
|
|
740
|
+
typ == "websocket_trigger" ||
|
|
741
|
+
typ == "kafka_trigger" ||
|
|
742
|
+
typ == "nats_trigger" ||
|
|
743
|
+
typ == "postgres_trigger") {
|
|
720
744
|
return 8;
|
|
721
745
|
}
|
|
722
|
-
else if (typ == "
|
|
746
|
+
else if (typ == "variable") {
|
|
723
747
|
return 9;
|
|
724
748
|
}
|
|
725
|
-
else if (typ == "
|
|
749
|
+
else if (typ == "user") {
|
|
726
750
|
return 10;
|
|
727
751
|
}
|
|
728
|
-
else if (typ == "
|
|
752
|
+
else if (typ == "group") {
|
|
729
753
|
return 11;
|
|
730
754
|
}
|
|
731
|
-
else {
|
|
755
|
+
else if (typ == "encryption_key") {
|
|
732
756
|
return 12;
|
|
733
757
|
}
|
|
758
|
+
else {
|
|
759
|
+
return 13;
|
|
760
|
+
}
|
|
734
761
|
}
|
|
735
762
|
const isNotWmillFile = (p, isDirectory) => {
|
|
736
763
|
if (p.endsWith(SEP)) {
|
|
@@ -867,7 +894,7 @@ export async function pull(opts) {
|
|
|
867
894
|
catch {
|
|
868
895
|
// ignore
|
|
869
896
|
}
|
|
870
|
-
const remote = ZipFSElement((await downloadZip(workspace, opts.plainSecrets, opts.skipVariables, opts.skipResources, opts.skipSecrets, opts.includeSchedules, opts.includeUsers, opts.includeGroups, opts.includeSettings, opts.includeKey, opts.defaultTs)), !opts.json, opts.defaultTs ?? "bun", resourceTypeToFormatExtension);
|
|
897
|
+
const remote = ZipFSElement((await downloadZip(workspace, opts.plainSecrets, opts.skipVariables, opts.skipResources, opts.skipSecrets, opts.includeSchedules, opts.includeTriggers, opts.includeUsers, opts.includeGroups, opts.includeSettings, opts.includeKey, opts.defaultTs)), !opts.json, opts.defaultTs ?? "bun", resourceTypeToFormatExtension);
|
|
871
898
|
const local = !opts.stateful
|
|
872
899
|
? await FSFSElement(dntShim.Deno.cwd(), codebases)
|
|
873
900
|
: await FSFSElement(path.join(dntShim.Deno.cwd(), ".wmill"), []);
|
|
@@ -996,7 +1023,9 @@ function prettyChanges(changes) {
|
|
|
996
1023
|
log.info(colors.red(`- ${getTypeStrFromPath(change.path)} ` + change.path));
|
|
997
1024
|
}
|
|
998
1025
|
else if (change.name === "edited") {
|
|
999
|
-
log.info(colors.yellow(`~ ${getTypeStrFromPath(change.path)} ` +
|
|
1026
|
+
log.info(colors.yellow(`~ ${getTypeStrFromPath(change.path)} ` +
|
|
1027
|
+
change.path +
|
|
1028
|
+
(change.codebase ? ` (codebase changed)` : "")));
|
|
1000
1029
|
if (change.before != change.after) {
|
|
1001
1030
|
showDiff(change.before, change.after);
|
|
1002
1031
|
}
|
|
@@ -1053,7 +1082,7 @@ export async function push(opts) {
|
|
|
1053
1082
|
catch {
|
|
1054
1083
|
// ignore
|
|
1055
1084
|
}
|
|
1056
|
-
const remote = ZipFSElement((await downloadZip(workspace, opts.plainSecrets, opts.skipVariables, opts.skipResources, opts.skipSecrets, opts.includeSchedules, opts.includeUsers, opts.includeGroups, opts.includeSettings, opts.includeKey, opts.defaultTs)), !opts.json, opts.defaultTs ?? "bun", resourceTypeToFormatExtension);
|
|
1085
|
+
const remote = ZipFSElement((await downloadZip(workspace, opts.plainSecrets, opts.skipVariables, opts.skipResources, opts.skipSecrets, opts.includeSchedules, opts.includeTriggers, opts.includeUsers, opts.includeGroups, opts.includeSettings, opts.includeKey, opts.defaultTs)), !opts.json, opts.defaultTs ?? "bun", resourceTypeToFormatExtension);
|
|
1057
1086
|
const local = await FSFSElement(path.join(dntShim.Deno.cwd(), ""), codebases);
|
|
1058
1087
|
const changes = await compareDynFSElement(local, remote, await ignoreF(opts), opts.json ?? false, opts, true, codebases);
|
|
1059
1088
|
const globalDeps = await findGlobalDeps();
|
|
@@ -1113,7 +1142,7 @@ export async function push(opts) {
|
|
|
1113
1142
|
// Group changes by base path (before first dot)
|
|
1114
1143
|
const groupedChanges = new Map();
|
|
1115
1144
|
for (const change of changes) {
|
|
1116
|
-
const basePath = change.path.split(
|
|
1145
|
+
const basePath = change.path.split(".")[0];
|
|
1117
1146
|
if (!groupedChanges.has(basePath)) {
|
|
1118
1147
|
groupedChanges.set(basePath, []);
|
|
1119
1148
|
}
|
|
@@ -1265,6 +1294,36 @@ export async function push(opts) {
|
|
|
1265
1294
|
path: removeSuffix(target, ".schedule.json"),
|
|
1266
1295
|
});
|
|
1267
1296
|
break;
|
|
1297
|
+
case "http_trigger":
|
|
1298
|
+
await wmill.deleteHttpTrigger({
|
|
1299
|
+
workspace: workspaceId,
|
|
1300
|
+
path: removeSuffix(target, ".http_trigger.json"),
|
|
1301
|
+
});
|
|
1302
|
+
break;
|
|
1303
|
+
case "websocket_trigger":
|
|
1304
|
+
await wmill.deleteWebsocketTrigger({
|
|
1305
|
+
workspace: workspaceId,
|
|
1306
|
+
path: removeSuffix(target, ".websocket_trigger.json"),
|
|
1307
|
+
});
|
|
1308
|
+
break;
|
|
1309
|
+
case "kafka_trigger":
|
|
1310
|
+
await wmill.deleteKafkaTrigger({
|
|
1311
|
+
workspace: workspaceId,
|
|
1312
|
+
path: removeSuffix(target, ".kafka_trigger.json"),
|
|
1313
|
+
});
|
|
1314
|
+
break;
|
|
1315
|
+
case "nats_trigger":
|
|
1316
|
+
await wmill.deleteNatsTrigger({
|
|
1317
|
+
workspace: workspaceId,
|
|
1318
|
+
path: removeSuffix(target, ".nats_trigger.json"),
|
|
1319
|
+
});
|
|
1320
|
+
break;
|
|
1321
|
+
case "postgres_trigger":
|
|
1322
|
+
await wmill.deletePostgresTrigger({
|
|
1323
|
+
workspace: workspaceId,
|
|
1324
|
+
path: removeSuffix(target, ".postgres_trigger.json"),
|
|
1325
|
+
});
|
|
1326
|
+
break;
|
|
1268
1327
|
case "variable":
|
|
1269
1328
|
await wmill.deleteVariable({
|
|
1270
1329
|
workspace: workspaceId,
|
|
@@ -1331,6 +1390,7 @@ const command = new Command()
|
|
|
1331
1390
|
.option("--skip-resources", "Skip syncing resources")
|
|
1332
1391
|
// .option("--skip-scripts-metadata", "Skip syncing scripts metadata, focus solely on logic")
|
|
1333
1392
|
.option("--include-schedules", "Include syncing schedules")
|
|
1393
|
+
.option("--include-triggers", "Include syncing triggers")
|
|
1334
1394
|
.option("--include-users", "Include syncing users")
|
|
1335
1395
|
.option("--include-groups", "Include syncing groups")
|
|
1336
1396
|
.option("--include-settings", "Include syncing workspace settings")
|
|
@@ -1350,6 +1410,7 @@ const command = new Command()
|
|
|
1350
1410
|
.option("--skip-resources", "Skip syncing resources")
|
|
1351
1411
|
// .option("--skip-scripts-metadata", "Skip syncing scripts metadata, focus solely on logic")
|
|
1352
1412
|
.option("--include-schedules", "Include syncing schedules")
|
|
1413
|
+
.option("--include-triggers", "Include syncing triggers")
|
|
1353
1414
|
.option("--include-users", "Include syncing users")
|
|
1354
1415
|
.option("--include-groups", "Include syncing groups")
|
|
1355
1416
|
.option("--include-settings", "Include syncing workspace settings")
|
package/esm/trigger.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import * as dntShim from "./_dnt.shims.js";
|
|
2
|
+
import * as wmill from "./gen/services.gen.js";
|
|
3
|
+
import { colors, Command, log, SEP, Table } from "./deps.js";
|
|
4
|
+
import { isSuperset, parseFromFile, removeType, } from "./types.js";
|
|
5
|
+
import { requireLogin } from "./context.js";
|
|
6
|
+
import { validatePath } from "./context.js";
|
|
7
|
+
import { resolveWorkspace } from "./context.js";
|
|
8
|
+
async function getTrigger(triggerType, workspace, path) {
|
|
9
|
+
const triggerFunctions = {
|
|
10
|
+
http: wmill.getHttpTrigger,
|
|
11
|
+
websocket: wmill.getWebsocketTrigger,
|
|
12
|
+
kafka: wmill.getKafkaTrigger,
|
|
13
|
+
nats: wmill.getNatsTrigger,
|
|
14
|
+
postgres: wmill.getPostgresTrigger,
|
|
15
|
+
};
|
|
16
|
+
const triggerFunction = triggerFunctions[triggerType];
|
|
17
|
+
const trigger = await triggerFunction({ workspace, path });
|
|
18
|
+
return trigger;
|
|
19
|
+
}
|
|
20
|
+
async function updateTrigger(triggerType, workspace, path, trigger) {
|
|
21
|
+
const triggerFunctions = {
|
|
22
|
+
http: wmill.updateHttpTrigger,
|
|
23
|
+
websocket: wmill.updateWebsocketTrigger,
|
|
24
|
+
kafka: wmill.updateKafkaTrigger,
|
|
25
|
+
nats: wmill.updateNatsTrigger,
|
|
26
|
+
postgres: wmill.updatePostgresTrigger,
|
|
27
|
+
};
|
|
28
|
+
const triggerFunction = triggerFunctions[triggerType];
|
|
29
|
+
await triggerFunction({ workspace, path, requestBody: trigger });
|
|
30
|
+
}
|
|
31
|
+
async function createTrigger(triggerType, workspace, path, trigger) {
|
|
32
|
+
const triggerFunctions = {
|
|
33
|
+
http: wmill.createHttpTrigger,
|
|
34
|
+
websocket: wmill.createWebsocketTrigger,
|
|
35
|
+
kafka: wmill.createKafkaTrigger,
|
|
36
|
+
nats: wmill.createNatsTrigger,
|
|
37
|
+
postgres: wmill.createPostgresTrigger,
|
|
38
|
+
};
|
|
39
|
+
const triggerFunction = triggerFunctions[triggerType];
|
|
40
|
+
await triggerFunction({ workspace, path, requestBody: trigger });
|
|
41
|
+
}
|
|
42
|
+
export async function pushTrigger(triggerType, workspace, path, trigger, localTrigger) {
|
|
43
|
+
path = removeType(path, triggerType + "_trigger").replaceAll(SEP, "/");
|
|
44
|
+
log.debug(`Processing local ${triggerType} trigger ${path}`);
|
|
45
|
+
try {
|
|
46
|
+
trigger = await getTrigger(triggerType, workspace, path);
|
|
47
|
+
log.debug(`${triggerType} trigger ${path} exists on remote`);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
log.debug(`${triggerType} trigger ${path} does not exist on remote`);
|
|
51
|
+
//ignore
|
|
52
|
+
}
|
|
53
|
+
if (trigger) {
|
|
54
|
+
if (isSuperset(localTrigger, trigger)) {
|
|
55
|
+
log.debug(`${triggerType} trigger ${path} is up to date`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
log.debug(`${triggerType} trigger ${path} is not up-to-date, updating...`);
|
|
59
|
+
try {
|
|
60
|
+
await updateTrigger(triggerType, workspace, path, {
|
|
61
|
+
...localTrigger,
|
|
62
|
+
path,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
console.error(e.body);
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
console.log(colors.bold.yellow(`Creating new ${triggerType} trigger: ${path}`));
|
|
72
|
+
try {
|
|
73
|
+
await createTrigger(triggerType, workspace, path, {
|
|
74
|
+
...localTrigger,
|
|
75
|
+
path,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
console.error(e.body);
|
|
80
|
+
throw e;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function list(opts) {
|
|
85
|
+
const workspace = await resolveWorkspace(opts);
|
|
86
|
+
await requireLogin(opts);
|
|
87
|
+
const httpTriggers = await wmill.listHttpTriggers({
|
|
88
|
+
workspace: workspace.workspaceId,
|
|
89
|
+
});
|
|
90
|
+
const websocketTriggers = await wmill.listWebsocketTriggers({
|
|
91
|
+
workspace: workspace.workspaceId,
|
|
92
|
+
});
|
|
93
|
+
const kafkaTriggers = await wmill.listKafkaTriggers({
|
|
94
|
+
workspace: workspace.workspaceId,
|
|
95
|
+
});
|
|
96
|
+
const natsTriggers = await wmill.listNatsTriggers({
|
|
97
|
+
workspace: workspace.workspaceId,
|
|
98
|
+
});
|
|
99
|
+
const postgresTriggers = await wmill.listPostgresTriggers({
|
|
100
|
+
workspace: workspace.workspaceId,
|
|
101
|
+
});
|
|
102
|
+
const triggers = [
|
|
103
|
+
...httpTriggers.map((x) => ({ path: x.path, kind: "http" })),
|
|
104
|
+
...websocketTriggers.map((x) => ({ path: x.path, kind: "websocket" })),
|
|
105
|
+
...kafkaTriggers.map((x) => ({ path: x.path, kind: "kafka" })),
|
|
106
|
+
...natsTriggers.map((x) => ({ path: x.path, kind: "nats" })),
|
|
107
|
+
...postgresTriggers.map((x) => ({ path: x.path, kind: "postgres" })),
|
|
108
|
+
];
|
|
109
|
+
new Table()
|
|
110
|
+
.header(["Path", "Kind"])
|
|
111
|
+
.padding(2)
|
|
112
|
+
.border(true)
|
|
113
|
+
.body(triggers.map((x) => [x.path, x.kind]))
|
|
114
|
+
.render();
|
|
115
|
+
}
|
|
116
|
+
function checkIfValidTrigger(kind) {
|
|
117
|
+
if (kind &&
|
|
118
|
+
["http", "websocket", "kafka", "nats", "postgres"].includes(kind)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function push(opts, filePath, remotePath) {
|
|
126
|
+
const workspace = await resolveWorkspace(opts);
|
|
127
|
+
await requireLogin(opts);
|
|
128
|
+
if (!validatePath(remotePath)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const fstat = await dntShim.Deno.stat(filePath);
|
|
132
|
+
if (!fstat.isFile) {
|
|
133
|
+
throw new Error("file path must refer to a file.");
|
|
134
|
+
}
|
|
135
|
+
console.log(colors.bold.yellow("Pushing trigger..."));
|
|
136
|
+
const triggerKind = filePath.split(".")[1].split("_")[0];
|
|
137
|
+
if (!checkIfValidTrigger(triggerKind)) {
|
|
138
|
+
throw new Error("Invalid trigger kind: " + triggerKind);
|
|
139
|
+
}
|
|
140
|
+
await pushTrigger(triggerKind, workspace.workspaceId, remotePath, undefined, parseFromFile(filePath));
|
|
141
|
+
console.log(colors.bold.underline.green("Trigger pushed"));
|
|
142
|
+
}
|
|
143
|
+
const command = new Command()
|
|
144
|
+
.description("trigger related commands")
|
|
145
|
+
.action(list)
|
|
146
|
+
.command("push", "push a local trigger spec. This overrides any remote versions.")
|
|
147
|
+
.arguments("<file_path:string> <remote_path:string>")
|
|
148
|
+
.action(push);
|
|
149
|
+
export default command;
|
package/esm/types.js
CHANGED
|
@@ -14,6 +14,7 @@ import { pushSchedule } from "./schedule.js";
|
|
|
14
14
|
import { pushWorkspaceUser } from "./user.js";
|
|
15
15
|
import { pushGroup } from "./user.js";
|
|
16
16
|
import { pushWorkspaceSettings, pushWorkspaceKey } from "./settings.js";
|
|
17
|
+
import { pushTrigger } from "./trigger.js";
|
|
17
18
|
export function isSuperset(subset, superset) {
|
|
18
19
|
return Object.keys(subset).every((key) => {
|
|
19
20
|
const eq = deepEqual(subset[key], superset[key]);
|
|
@@ -37,7 +38,7 @@ export function showDiff(local, remote) {
|
|
|
37
38
|
log.info("Diff too large to display");
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
40
|
-
for (const part of Diff.diffLines(local ??
|
|
41
|
+
for (const part of Diff.diffLines(local ?? "", remote ?? "")) {
|
|
41
42
|
if (part.removed) {
|
|
42
43
|
// print red if removed without newline
|
|
43
44
|
finalString += `\x1b[31m${part.value}\x1b[0m`;
|
|
@@ -93,6 +94,21 @@ export async function pushObj(workspace, p, befObj, newObj, plainSecrets, alread
|
|
|
93
94
|
else if (typeEnding === "schedule") {
|
|
94
95
|
await pushSchedule(workspace, p, befObj, newObj);
|
|
95
96
|
}
|
|
97
|
+
else if (typeEnding === "http_trigger") {
|
|
98
|
+
await pushTrigger("http", workspace, p, befObj, newObj);
|
|
99
|
+
}
|
|
100
|
+
else if (typeEnding === "websocket_trigger") {
|
|
101
|
+
await pushTrigger("websocket", workspace, p, befObj, newObj);
|
|
102
|
+
}
|
|
103
|
+
else if (typeEnding === "kafka_trigger") {
|
|
104
|
+
await pushTrigger("kafka", workspace, p, befObj, newObj);
|
|
105
|
+
}
|
|
106
|
+
else if (typeEnding === "nats_trigger") {
|
|
107
|
+
await pushTrigger("nats", workspace, p, befObj, newObj);
|
|
108
|
+
}
|
|
109
|
+
else if (typeEnding === "postgres_trigger") {
|
|
110
|
+
await pushTrigger("postgres", workspace, p, befObj, newObj);
|
|
111
|
+
}
|
|
96
112
|
else if (typeEnding === "user") {
|
|
97
113
|
await pushWorkspaceUser(workspace, p, befObj, newObj);
|
|
98
114
|
}
|
|
@@ -159,6 +175,11 @@ export function getTypeStrFromPath(p) {
|
|
|
159
175
|
typeEnding === "resource-type" ||
|
|
160
176
|
typeEnding === "app" ||
|
|
161
177
|
typeEnding === "schedule" ||
|
|
178
|
+
typeEnding === "http_trigger" ||
|
|
179
|
+
typeEnding === "websocket_trigger" ||
|
|
180
|
+
typeEnding === "kafka_trigger" ||
|
|
181
|
+
typeEnding === "nats_trigger" ||
|
|
182
|
+
typeEnding === "postgres_trigger" ||
|
|
162
183
|
typeEnding === "user" ||
|
|
163
184
|
typeEnding === "group" ||
|
|
164
185
|
typeEnding === "settings" ||
|
package/package.json
CHANGED
package/types/conf.d.ts
CHANGED
package/types/conf.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conf.d.ts","sourceRoot":"","sources":["../src/conf.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,C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