windmill-cli 1.396.1 → 1.397.4

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.
Files changed (89) hide show
  1. package/esm/apps.js +6 -5
  2. package/esm/bootstrap/script_bootstrap.js +18 -0
  3. package/esm/context.js +4 -3
  4. package/esm/deps.js +19 -2
  5. package/esm/flow.js +9 -8
  6. package/esm/folder.js +6 -5
  7. package/esm/gen/core/ApiError.js +41 -0
  8. package/esm/gen/core/ApiRequestOptions.js +1 -0
  9. package/esm/gen/core/ApiResult.js +1 -0
  10. package/esm/gen/core/CancelablePromise.js +130 -0
  11. package/esm/gen/core/OpenAPI.js +41 -0
  12. package/esm/gen/core/request.js +305 -0
  13. package/esm/gen/index.js +6 -0
  14. package/esm/gen/services.gen.js +6782 -0
  15. package/esm/gen/types.gen.js +2 -0
  16. package/esm/hub.js +5 -4
  17. package/esm/instance.js +5 -4
  18. package/esm/main.js +5 -3
  19. package/esm/metadata.js +1 -1
  20. package/esm/resource-type.js +6 -5
  21. package/esm/resource.js +11 -5
  22. package/esm/schedule.js +6 -5
  23. package/esm/script.js +42 -10
  24. package/esm/script_common.js +6 -0
  25. package/esm/settings.js +28 -27
  26. package/esm/sync.js +101 -23
  27. package/esm/types.js +9 -3
  28. package/esm/user.js +27 -27
  29. package/esm/utils.js +7 -0
  30. package/esm/variable.js +7 -6
  31. package/esm/workspace.js +7 -6
  32. package/package.json +1 -2
  33. package/types/apps.d.ts +2 -1
  34. package/types/apps.d.ts.map +1 -1
  35. package/types/bootstrap/script_bootstrap.d.ts +2 -0
  36. package/types/bootstrap/script_bootstrap.d.ts.map +1 -1
  37. package/types/context.d.ts +1 -1
  38. package/types/context.d.ts.map +1 -1
  39. package/types/deps.d.ts +1 -1
  40. package/types/deps.d.ts.map +1 -1
  41. package/types/flow.d.ts +2 -1
  42. package/types/flow.d.ts.map +1 -1
  43. package/types/folder.d.ts +5 -2
  44. package/types/folder.d.ts.map +1 -1
  45. package/types/gen/core/ApiError.d.ts +11 -0
  46. package/types/gen/core/ApiError.d.ts.map +1 -0
  47. package/types/gen/core/ApiRequestOptions.d.ts +15 -0
  48. package/types/gen/core/ApiRequestOptions.d.ts.map +1 -0
  49. package/types/gen/core/ApiResult.d.ts +8 -0
  50. package/types/gen/core/ApiResult.d.ts.map +1 -0
  51. package/types/gen/core/CancelablePromise.d.ts +27 -0
  52. package/types/gen/core/CancelablePromise.d.ts.map +1 -0
  53. package/types/gen/core/OpenAPI.d.ts +28 -0
  54. package/types/gen/core/OpenAPI.d.ts.map +1 -0
  55. package/types/gen/core/request.d.ts +30 -0
  56. package/types/gen/core/request.d.ts.map +1 -0
  57. package/types/gen/index.d.ts +6 -0
  58. package/types/gen/index.d.ts.map +1 -0
  59. package/types/gen/services.gen.d.ts +3339 -0
  60. package/types/gen/services.gen.d.ts.map +1 -0
  61. package/types/gen/types.gen.d.ts +4831 -0
  62. package/types/gen/types.gen.d.ts.map +1 -0
  63. package/types/hub.d.ts.map +1 -1
  64. package/types/instance.d.ts.map +1 -1
  65. package/types/main.d.ts +1 -1
  66. package/types/main.d.ts.map +1 -1
  67. package/types/metadata.d.ts +1 -1
  68. package/types/metadata.d.ts.map +1 -1
  69. package/types/resource-type.d.ts +2 -1
  70. package/types/resource-type.d.ts.map +1 -1
  71. package/types/resource.d.ts +2 -1
  72. package/types/resource.d.ts.map +1 -1
  73. package/types/schedule.d.ts +2 -1
  74. package/types/schedule.d.ts.map +1 -1
  75. package/types/script.d.ts +1 -0
  76. package/types/script.d.ts.map +1 -1
  77. package/types/script_common.d.ts +1 -1
  78. package/types/script_common.d.ts.map +1 -1
  79. package/types/settings.d.ts.map +1 -1
  80. package/types/sync.d.ts +2 -1
  81. package/types/sync.d.ts.map +1 -1
  82. package/types/types.d.ts +1 -1
  83. package/types/types.d.ts.map +1 -1
  84. package/types/user.d.ts.map +1 -1
  85. package/types/utils.d.ts +1 -0
  86. package/types/utils.d.ts.map +1 -1
  87. package/types/variable.d.ts +2 -1
  88. package/types/variable.d.ts.map +1 -1
  89. package/types/workspace.d.ts.map +1 -1
package/esm/sync.js CHANGED
@@ -1,15 +1,17 @@
1
1
  import * as dntShim from "./_dnt.shims.js";
2
2
  import { fetchVersion, requireLogin, resolveWorkspace } from "./context.js";
3
- import { colors, Command, Confirm, ensureDir, minimatch, path, ScriptService, FolderService, ResourceService, VariableService, AppService, FlowService, log, yamlStringify, yamlParse, ScheduleService, SEP, UserService, GroupService, } from "./deps.js";
3
+ import { colors, Command, Confirm, ensureDir, minimatch, path, log, yamlStringify, yamlParse, SEP, } from "./deps.js";
4
+ import * as wmill from "./gen/services.gen.js";
4
5
  import { getTypeStrFromPath, parseFromPath, pushObj, showConflict, showDiff, } from "./types.js";
5
6
  import { downloadZip } from "./pull.js";
6
- import { exts, findContentFile, findGlobalDeps, handleScriptMetadata, removeExtensionToPath, } from "./script.js";
7
+ import { exts, findContentFile, findGlobalDeps, findResourceFile, handleScriptMetadata, removeExtensionToPath, } from "./script.js";
7
8
  import { handleFile } from "./script.js";
8
- import { deepEqual } from "./utils.js";
9
+ import { deepEqual, isFileResource } from "./utils.js";
9
10
  import { mergeConfigWithConfigFile } from "./conf.js";
10
11
  import { removePathPrefix } from "./types.js";
11
12
  import { listSyncCodebases } from "./codebase.js";
12
13
  import { generateFlowLockInternal, generateScriptMetadataInternal, } from "./metadata.js";
14
+ import { pushResource } from "./resource.js";
13
15
  export function findCodebase(path, codebases) {
14
16
  if (!path.endsWith(".ts")) {
15
17
  return;
@@ -262,13 +264,17 @@ export function newPathAssigner(defaultTs) {
262
264
  ext = "frontend.js";
263
265
  else if (language == "php")
264
266
  ext = "php";
267
+ else if (language == "rust")
268
+ ext = "rs";
269
+ else if (language == "ansible")
270
+ ext = "playbook.yml";
265
271
  else
266
272
  ext = "no_ext";
267
273
  return [`${name}.inline_script.`, ext];
268
274
  }
269
275
  return { assignPath };
270
276
  }
271
- function ZipFSElement(zip, useYaml, defaultTs) {
277
+ function ZipFSElement(zip, useYaml, defaultTs, resourceTypeToFormatExtension) {
272
278
  async function _internal_file(p, f) {
273
279
  const kind = p.endsWith("flow.json")
274
280
  ? "flow"
@@ -276,7 +282,9 @@ function ZipFSElement(zip, useYaml, defaultTs) {
276
282
  ? "app"
277
283
  : p.endsWith("script.json")
278
284
  ? "script"
279
- : "other";
285
+ : p.endsWith("resource.json")
286
+ ? "resource"
287
+ : "other";
280
288
  const isJson = p.endsWith(".json");
281
289
  function transformPath() {
282
290
  if (kind == "flow") {
@@ -366,6 +374,21 @@ function ZipFSElement(zip, useYaml, defaultTs) {
366
374
  ? yamlStringify(parsed, yamlOptions)
367
375
  : JSON.stringify(parsed, null, 2);
368
376
  }
377
+ if (kind == "resource") {
378
+ const content = await f.async("text");
379
+ const parsed = JSON.parse(content);
380
+ const formatExtension = resourceTypeToFormatExtension[parsed["resource_type"]];
381
+ if (formatExtension) {
382
+ parsed["value"]["content"] =
383
+ "!inline " +
384
+ removeSuffix(p.replaceAll(SEP, "/"), ".resource.json") +
385
+ ".resource.file." +
386
+ formatExtension;
387
+ }
388
+ return useYaml
389
+ ? yamlStringify(parsed, yamlOptions)
390
+ : JSON.stringify(parsed, null, 2);
391
+ }
369
392
  return useYaml && isJson
370
393
  ? yamlStringify(JSON.parse(content), yamlOptions)
371
394
  : content;
@@ -388,6 +411,25 @@ function ZipFSElement(zip, useYaml, defaultTs) {
388
411
  });
389
412
  }
390
413
  }
414
+ if (kind == "resource") {
415
+ const content = await f.async("text");
416
+ const parsed = JSON.parse(content);
417
+ const formatExtension = resourceTypeToFormatExtension[parsed["resource_type"]];
418
+ if (formatExtension) {
419
+ const fileContent = parsed["value"]["content"];
420
+ r.push({
421
+ isDirectory: false,
422
+ path: removeSuffix(finalPath, ".resource.json") +
423
+ ".resource.file." +
424
+ formatExtension,
425
+ async *getChildren() { },
426
+ // deno-lint-ignore require-await
427
+ async getContentText() {
428
+ return fileContent;
429
+ },
430
+ });
431
+ }
432
+ }
391
433
  return r;
392
434
  }
393
435
  function _internal_folder(p, zip) {
@@ -479,6 +521,8 @@ export async function elementsToMap(els, ignore, json, skips) {
479
521
  continue;
480
522
  if (skips.skipResources && path.endsWith(".resource" + ext))
481
523
  continue;
524
+ if (skips.skipResources && isFileResource(path))
525
+ continue;
482
526
  if (![
483
527
  "json",
484
528
  "yaml",
@@ -492,7 +536,10 @@ export async function elementsToMap(els, ignore, json, skips) {
492
536
  "php",
493
537
  "js",
494
538
  "lock",
495
- ].includes(path.split(".").pop() ?? ""))
539
+ "rs",
540
+ "yml",
541
+ ].includes(path.split(".").pop() ?? "") &&
542
+ !isFileResource(path))
496
543
  continue;
497
544
  const content = await entry.getContentText();
498
545
  if (skips.skipSecrets && path.endsWith(".variable" + ext)) {
@@ -695,7 +742,16 @@ export async function pull(opts) {
695
742
  await requireLogin(opts);
696
743
  const codebases = await listSyncCodebases(opts);
697
744
  log.info(colors.gray("Computing the files to update locally to match remote (taking wmill.yaml into account)"));
698
- 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");
745
+ let resourceTypeToFormatExtension = {};
746
+ try {
747
+ resourceTypeToFormatExtension = (await wmill.fileResourceTypeToFileExtMap({
748
+ workspace: workspace.workspaceId,
749
+ }));
750
+ }
751
+ catch {
752
+ // ignore
753
+ }
754
+ 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);
699
755
  const local = !opts.stateful
700
756
  ? await FSFSElement(dntShim.Deno.cwd(), codebases)
701
757
  : await FSFSElement(path.join(dntShim.Deno.cwd(), ".wmill"), []);
@@ -910,7 +966,16 @@ export async function push(opts) {
910
966
  const workspace = await resolveWorkspace(opts);
911
967
  await requireLogin(opts);
912
968
  log.info(colors.gray("Computing the files to update on the remote to match local (taking wmill.yaml includes/excludes into account)"));
913
- 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");
969
+ let resourceTypeToFormatExtension = {};
970
+ try {
971
+ resourceTypeToFormatExtension = (await wmill.fileResourceTypeToFileExtMap({
972
+ workspace: workspace.workspaceId,
973
+ }));
974
+ }
975
+ catch {
976
+ // ignore
977
+ }
978
+ 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);
914
979
  const local = await FSFSElement(path.join(dntShim.Deno.cwd(), ""), codebases);
915
980
  const changes = await compareDynFSElement(local, remote, await ignoreF(opts), opts.json ?? false, opts, true);
916
981
  const version = await fetchVersion(workspace.remote);
@@ -954,9 +1019,21 @@ export async function push(opts) {
954
1019
  await ensureDir(path.dirname(stateTarget));
955
1020
  log.info(`Editing ${getTypeStrFromPath(change.path)} ${change.path}`);
956
1021
  }
1022
+ if (isFileResource(change.path)) {
1023
+ const resourceFilePath = await findResourceFile(change.path);
1024
+ if (!alreadySynced.includes(resourceFilePath)) {
1025
+ alreadySynced.push(resourceFilePath);
1026
+ const newObj = parseFromPath(resourceFilePath, await dntShim.Deno.readTextFile(resourceFilePath));
1027
+ await pushResource(workspace.workspaceId, resourceFilePath, undefined, newObj);
1028
+ if (opts.stateful && stateExists) {
1029
+ await dntShim.Deno.writeTextFile(stateTarget, change.after);
1030
+ }
1031
+ continue;
1032
+ }
1033
+ }
957
1034
  const oldObj = parseFromPath(change.path, change.before);
958
1035
  const newObj = parseFromPath(change.path, change.after);
959
- await pushObj(workspace.workspaceId, change.path, oldObj, newObj, opts.plainSecrets ?? false, opts.message);
1036
+ await pushObj(workspace.workspaceId, change.path, oldObj, newObj, opts.plainSecrets ?? false, alreadySynced, opts.message);
960
1037
  if (opts.stateful && stateExists) {
961
1038
  await dntShim.Deno.writeTextFile(stateTarget, change.after);
962
1039
  }
@@ -964,7 +1041,8 @@ export async function push(opts) {
964
1041
  else if (change.name === "added") {
965
1042
  if (change.path.endsWith(".script.json") ||
966
1043
  change.path.endsWith(".script.yaml") ||
967
- change.path.endsWith(".lock")) {
1044
+ change.path.endsWith(".lock") ||
1045
+ isFileResource(change.path)) {
968
1046
  continue;
969
1047
  }
970
1048
  else if (await handleFile(change.path, workspace, alreadySynced, opts.message, opts, globalDeps, codebases)) {
@@ -975,7 +1053,7 @@ export async function push(opts) {
975
1053
  log.info(`Adding ${getTypeStrFromPath(change.path)} ${change.path}`);
976
1054
  }
977
1055
  const obj = parseFromPath(change.path, change.content);
978
- await pushObj(workspace.workspaceId, change.path, undefined, obj, opts.plainSecrets ?? false, opts.message);
1056
+ await pushObj(workspace.workspaceId, change.path, undefined, obj, opts.plainSecrets ?? false, [], opts.message);
979
1057
  if (opts.stateful && stateExists) {
980
1058
  await dntShim.Deno.writeTextFile(stateTarget, change.content);
981
1059
  }
@@ -994,60 +1072,60 @@ export async function push(opts) {
994
1072
  const workspaceId = workspace.workspaceId;
995
1073
  switch (typ) {
996
1074
  case "script": {
997
- const script = await ScriptService.getScriptByPath({
1075
+ const script = await wmill.getScriptByPath({
998
1076
  workspace: workspaceId,
999
1077
  path: removeExtensionToPath(change.path),
1000
1078
  });
1001
- await ScriptService.archiveScriptByHash({
1079
+ await wmill.archiveScriptByHash({
1002
1080
  workspace: workspaceId,
1003
1081
  hash: script.hash,
1004
1082
  });
1005
1083
  break;
1006
1084
  }
1007
1085
  case "folder":
1008
- await FolderService.deleteFolder({
1086
+ await wmill.deleteFolder({
1009
1087
  workspace: workspaceId,
1010
1088
  name: change.path.split(SEP)[1],
1011
1089
  });
1012
1090
  break;
1013
1091
  case "resource":
1014
- await ResourceService.deleteResource({
1092
+ await wmill.deleteResource({
1015
1093
  workspace: workspaceId,
1016
1094
  path: removeSuffix(change.path, ".resource.json"),
1017
1095
  });
1018
1096
  break;
1019
1097
  case "resource-type":
1020
- await ResourceService.deleteResourceType({
1098
+ await wmill.deleteResourceType({
1021
1099
  workspace: workspaceId,
1022
1100
  path: removeSuffix(change.path, ".resource-type.json"),
1023
1101
  });
1024
1102
  break;
1025
1103
  case "flow":
1026
- await FlowService.deleteFlowByPath({
1104
+ await wmill.deleteFlowByPath({
1027
1105
  workspace: workspaceId,
1028
1106
  path: removeSuffix(change.path, ".flow/flow.json"),
1029
1107
  });
1030
1108
  break;
1031
1109
  case "app":
1032
- await AppService.deleteApp({
1110
+ await wmill.deleteApp({
1033
1111
  workspace: workspaceId,
1034
1112
  path: removeSuffix(change.path, ".app/app.json"),
1035
1113
  });
1036
1114
  break;
1037
1115
  case "schedule":
1038
- await ScheduleService.deleteSchedule({
1116
+ await wmill.deleteSchedule({
1039
1117
  workspace: workspaceId,
1040
1118
  path: removeSuffix(change.path, ".schedule.json"),
1041
1119
  });
1042
1120
  break;
1043
1121
  case "variable":
1044
- await VariableService.deleteVariable({
1122
+ await wmill.deleteVariable({
1045
1123
  workspace: workspaceId,
1046
1124
  path: removeSuffix(change.path, ".variable.json"),
1047
1125
  });
1048
1126
  break;
1049
1127
  case "user": {
1050
- const users = await UserService.listUsers({
1128
+ const users = await wmill.listUsers({
1051
1129
  workspace: workspaceId,
1052
1130
  });
1053
1131
  const email = removeSuffix(removePathPrefix(change.path, "users"), ".user.json");
@@ -1055,14 +1133,14 @@ export async function push(opts) {
1055
1133
  if (!user) {
1056
1134
  throw new Error(`User ${email} not found`);
1057
1135
  }
1058
- await UserService.deleteUser({
1136
+ await wmill.deleteUser({
1059
1137
  workspace: workspaceId,
1060
1138
  username: user.username,
1061
1139
  });
1062
1140
  break;
1063
1141
  }
1064
1142
  case "group":
1065
- await GroupService.deleteGroup({
1143
+ await wmill.deleteGroup({
1066
1144
  workspace: workspaceId,
1067
1145
  name: removeSuffix(removePathPrefix(change.path, "groups"), ".group.json"),
1068
1146
  });
package/esm/types.js CHANGED
@@ -9,7 +9,7 @@ import { pushResourceType } from "./resource-type.js";
9
9
  import { pushVariable } from "./variable.js";
10
10
  import { yamlOptions } from "./sync.js";
11
11
  import { showDiffs } from "./main.js";
12
- import { deepEqual } from "./utils.js";
12
+ import { deepEqual, isFileResource } from "./utils.js";
13
13
  import { pushSchedule } from "./schedule.js";
14
14
  import { pushWorkspaceUser } from "./user.js";
15
15
  import { pushGroup } from "./user.js";
@@ -65,7 +65,7 @@ export function showConflict(path, local, remote) {
65
65
  log.info("\x1b[31mlocal\x1b[31m - \x1b[32mremote\x1b[32m");
66
66
  log.info("\n");
67
67
  }
68
- export async function pushObj(workspace, p, befObj, newObj, plainSecrets, message) {
68
+ export async function pushObj(workspace, p, befObj, newObj, plainSecrets, alreadySynced, message) {
69
69
  const typeEnding = getTypeStrFromPath(p);
70
70
  if (typeEnding === "app") {
71
71
  const appName = p.split(".app" + SEP)[0];
@@ -82,7 +82,10 @@ export async function pushObj(workspace, p, befObj, newObj, plainSecrets, messag
82
82
  await pushFlow(workspace, flowName, flowName + ".flow", message);
83
83
  }
84
84
  else if (typeEnding === "resource") {
85
- await pushResource(workspace, p, befObj, newObj);
85
+ if (!alreadySynced.includes(p)) {
86
+ alreadySynced.push(p);
87
+ await pushResource(workspace, p, befObj, newObj);
88
+ }
86
89
  }
87
90
  else if (typeEnding === "resource-type") {
88
91
  await pushResourceType(workspace, p, befObj, newObj);
@@ -160,6 +163,9 @@ export function getTypeStrFromPath(p) {
160
163
  return typeEnding;
161
164
  }
162
165
  else {
166
+ if (isFileResource(p)) {
167
+ return "resource";
168
+ }
163
169
  throw new Error("Could not infer type of path " + JSON.stringify(parsed));
164
170
  }
165
171
  }
package/esm/user.js CHANGED
@@ -3,15 +3,15 @@ import * as dntShim from "./_dnt.shims.js";
3
3
  import { requireLogin } from "./context.js";
4
4
  import { isSuperset, removeType, removePathPrefix, } from "./types.js";
5
5
  import { compareInstanceObjects } from "./instance.js";
6
- import { colors, Command, log, Table, UserService, GroupService, WorkspaceService, GranularAclService, yamlStringify, yamlParse, } from "./deps.js";
7
- import { SettingService } from "./deps.js";
6
+ import { colors, Command, log, Table, yamlStringify, yamlParse, } from "./deps.js";
7
+ import * as wmill from "./gen/services.gen.js";
8
8
  async function list(opts) {
9
9
  await requireLogin(opts);
10
10
  const perPage = 10;
11
11
  let page = 0;
12
12
  const total = [];
13
13
  while (true) {
14
- const res = await UserService.listUsersAsSuperAdmin({ page, perPage });
14
+ const res = await wmill.listUsersAsSuperAdmin({ page, perPage });
15
15
  total.push(...res);
16
16
  page += 1;
17
17
  if (res.length < perPage) {
@@ -37,7 +37,7 @@ function rdString() {
37
37
  async function add(opts, email, password) {
38
38
  await requireLogin(opts);
39
39
  const password_final = password ?? rdString();
40
- await UserService.createUserGlobally({
40
+ await wmill.createUserGlobally({
41
41
  requestBody: {
42
42
  email,
43
43
  password: password_final,
@@ -53,13 +53,13 @@ async function add(opts, email, password) {
53
53
  }
54
54
  async function remove(opts, email) {
55
55
  await requireLogin(opts);
56
- await UserService.globalUserDelete({ email });
56
+ await wmill.globalUserDelete({ email });
57
57
  log.info(colors.green("Deleted User " + email));
58
58
  }
59
59
  async function createToken(opts) {
60
60
  if (opts.email && opts.password) {
61
61
  log.info("Token: " +
62
- (await UserService.login({
62
+ (await wmill.login({
63
63
  requestBody: {
64
64
  email: opts.email,
65
65
  password: opts.password,
@@ -67,7 +67,7 @@ async function createToken(opts) {
67
67
  })));
68
68
  }
69
69
  await requireLogin(opts);
70
- log.info("Token: " + (await UserService.createToken({ requestBody: {} })));
70
+ log.info("Token: " + (await wmill.createToken({ requestBody: {} })));
71
71
  }
72
72
  export async function pushWorkspaceUser(workspace, path, user, localUser) {
73
73
  const email = removePathPrefix(removeType(path, "user"), "users");
@@ -76,7 +76,7 @@ export async function pushWorkspaceUser(workspace, path, user, localUser) {
76
76
  throw new Error(`Invalid role for user ${email}: ${localUser.role}`);
77
77
  }
78
78
  try {
79
- const remoteUser = await UserService.getUser({
79
+ const remoteUser = await wmill.getUser({
80
80
  workspace,
81
81
  username: localUser.username,
82
82
  });
@@ -105,7 +105,7 @@ export async function pushWorkspaceUser(workspace, path, user, localUser) {
105
105
  }
106
106
  log.debug(`User ${email} is not up-to-date, updating...`);
107
107
  try {
108
- await UserService.updateUser({
108
+ await wmill.updateUser({
109
109
  workspace: workspace,
110
110
  username: localUser.username,
111
111
  requestBody: {
@@ -123,10 +123,10 @@ export async function pushWorkspaceUser(workspace, path, user, localUser) {
123
123
  else {
124
124
  console.log(colors.bold.yellow("Creating new user: " + email));
125
125
  try {
126
- const automatedUsernameCreation = (await SettingService.getGlobal({
126
+ const automatedUsernameCreation = (await wmill.getGlobal({
127
127
  key: "automate_username_creation",
128
128
  }));
129
- await WorkspaceService.addUser({
129
+ await wmill.addUser({
130
130
  workspace: workspace,
131
131
  requestBody: {
132
132
  email: email,
@@ -146,7 +146,7 @@ export async function pushGroup(workspace, path, group, localGroup) {
146
146
  const name = removePathPrefix(removeType(path, "group"), "groups");
147
147
  log.debug(`Processing local group ${name}`);
148
148
  try {
149
- const remoteGroup = await GroupService.getGroup({
149
+ const remoteGroup = await wmill.getGroup({
150
150
  workspace,
151
151
  name,
152
152
  });
@@ -176,7 +176,7 @@ export async function pushGroup(workspace, path, group, localGroup) {
176
176
  }
177
177
  log.debug(`Group ${name} is not up-to-date, updating...`);
178
178
  try {
179
- await GroupService.updateGroup({
179
+ await wmill.updateGroup({
180
180
  workspace: workspace,
181
181
  name,
182
182
  requestBody: {
@@ -195,7 +195,7 @@ export async function pushGroup(workspace, path, group, localGroup) {
195
195
  }
196
196
  else {
197
197
  log.debug(`Adding ${member} to group ${name}`);
198
- await GroupService.addUserToGroup({
198
+ await wmill.addUserToGroup({
199
199
  workspace: workspace,
200
200
  name,
201
201
  requestBody: {
@@ -206,7 +206,7 @@ export async function pushGroup(workspace, path, group, localGroup) {
206
206
  if (localGroup.admins.includes(member) &&
207
207
  !group.admins.includes(member)) {
208
208
  log.debug(`Setting role of ${member} as admin in group ${name}`);
209
- await GranularAclService.addGranularAcls({
209
+ await wmill.addGranularAcls({
210
210
  workspace: workspace,
211
211
  kind: "group_",
212
212
  path: name,
@@ -219,7 +219,7 @@ export async function pushGroup(workspace, path, group, localGroup) {
219
219
  if (localGroup.members.includes(member) &&
220
220
  !group.members.includes(member)) {
221
221
  log.debug(`Setting role of ${member} as member in group ${name}`);
222
- await GranularAclService.addGranularAcls({
222
+ await wmill.addGranularAcls({
223
223
  workspace: workspace,
224
224
  kind: "group_",
225
225
  path: name,
@@ -239,14 +239,14 @@ export async function pushGroup(workspace, path, group, localGroup) {
239
239
  if (![...localGroup.members, ...localGroup.admins].includes(member)) {
240
240
  log.debug(`Removing ${member} and any associated role from group ${name}`);
241
241
  try {
242
- await GroupService.removeUserToGroup({
242
+ await wmill.removeUserToGroup({
243
243
  workspace: workspace,
244
244
  name,
245
245
  requestBody: {
246
246
  username: member.slice(2),
247
247
  },
248
248
  });
249
- await GranularAclService.removeGranularAcls({
249
+ await wmill.removeGranularAcls({
250
250
  workspace: workspace,
251
251
  kind: "group_",
252
252
  path: name,
@@ -265,7 +265,7 @@ export async function pushGroup(workspace, path, group, localGroup) {
265
265
  else {
266
266
  console.log(colors.bold.yellow("Creating new user: " + name));
267
267
  try {
268
- await GroupService.createGroup({
268
+ await wmill.createGroup({
269
269
  workspace: workspace,
270
270
  requestBody: {
271
271
  name,
@@ -275,7 +275,7 @@ export async function pushGroup(workspace, path, group, localGroup) {
275
275
  for (const member of [...localGroup.members, ...localGroup.admins]) {
276
276
  log.debug(`Adding user ${member} to group ${name}`);
277
277
  try {
278
- await GroupService.addUserToGroup({
278
+ await wmill.addUserToGroup({
279
279
  workspace: workspace,
280
280
  name,
281
281
  requestBody: {
@@ -284,7 +284,7 @@ export async function pushGroup(workspace, path, group, localGroup) {
284
284
  });
285
285
  if (localGroup.admins.includes(member)) {
286
286
  log.debug(`Setting role of ${member} as admin in group ${name}`);
287
- await GranularAclService.addGranularAcls({
287
+ await wmill.addGranularAcls({
288
288
  workspace: workspace,
289
289
  kind: "group_",
290
290
  path: name,
@@ -308,7 +308,7 @@ export async function pushGroup(workspace, path, group, localGroup) {
308
308
  }
309
309
  }
310
310
  export async function pullInstanceUsers(preview = false) {
311
- const remoteUsers = await UserService.globalUsersExport();
311
+ const remoteUsers = await wmill.globalUsersExport();
312
312
  if (preview) {
313
313
  let localUsers = [];
314
314
  try {
@@ -325,7 +325,7 @@ export async function pullInstanceUsers(preview = false) {
325
325
  }
326
326
  }
327
327
  export async function pushInstanceUsers(preview = false) {
328
- const remoteUsers = await UserService.globalUsersExport();
328
+ const remoteUsers = await wmill.globalUsersExport();
329
329
  const localUsers = (await dntShim.Deno.readTextFile("instance_users.yaml")
330
330
  .then((raw) => yamlParse(raw))
331
331
  .catch(() => []));
@@ -334,14 +334,14 @@ export async function pushInstanceUsers(preview = false) {
334
334
  }
335
335
  else {
336
336
  log.info("Pushing users to instance...");
337
- await UserService.globalUsersOverwrite({
337
+ await wmill.globalUsersOverwrite({
338
338
  requestBody: localUsers,
339
339
  });
340
340
  log.info(colors.green("Users pushed to the instance"));
341
341
  }
342
342
  }
343
343
  export async function pullInstanceGroups(preview = false) {
344
- const remoteGroups = await GroupService.exportInstanceGroups();
344
+ const remoteGroups = await wmill.exportInstanceGroups();
345
345
  if (preview) {
346
346
  let localGroups = [];
347
347
  try {
@@ -358,7 +358,7 @@ export async function pullInstanceGroups(preview = false) {
358
358
  }
359
359
  }
360
360
  export async function pushInstanceGroups(preview = false) {
361
- const remoteGroups = await GroupService.exportInstanceGroups();
361
+ const remoteGroups = await wmill.exportInstanceGroups();
362
362
  const localGroups = (await dntShim.Deno.readTextFile("instance_groups.yaml")
363
363
  .then((raw) => yamlParse(raw))
364
364
  .catch(() => []));
@@ -367,7 +367,7 @@ export async function pushInstanceGroups(preview = false) {
367
367
  }
368
368
  else {
369
369
  log.info("Pushing groups to instance...");
370
- await GroupService.overwriteInstanceGroups({
370
+ await wmill.overwriteInstanceGroups({
371
371
  requestBody: localGroups,
372
372
  });
373
373
  log.info(colors.green("Groups pushed to the instance"));
package/esm/utils.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import * as dntShim from "./_dnt.shims.js";
4
4
  // @ts-nocheck This file is copied from a JS project, so it's not type-safe.
5
5
  import { log, encodeHex, SEP } from "./deps.js";
6
+ import crypto from "node:crypto";
6
7
  export function deepEqual(a, b) {
7
8
  if (a === b)
8
9
  return true;
@@ -120,3 +121,9 @@ export function readInlinePathSync(path) {
120
121
  export function sleep(ms) {
121
122
  return new Promise((resolve) => setTimeout(resolve, ms));
122
123
  }
124
+ export function isFileResource(path) {
125
+ const splitPath = path.split(".");
126
+ return (splitPath.length >= 4 &&
127
+ splitPath[1] == "resource" &&
128
+ splitPath[2] == "file");
129
+ }
package/esm/variable.js CHANGED
@@ -2,11 +2,12 @@
2
2
  import * as dntShim from "./_dnt.shims.js";
3
3
  import { requireLogin, resolveWorkspace, validatePath } from "./context.js";
4
4
  import { isSuperset, parseFromFile, removeType, } from "./types.js";
5
- import { colors, Command, Confirm, log, SEP, Table, VariableService, } from "./deps.js";
5
+ import { colors, Command, Confirm, log, SEP, Table } from "./deps.js";
6
+ import * as wmill from "./gen/services.gen.js";
6
7
  async function list(opts) {
7
8
  const workspace = await resolveWorkspace(opts);
8
9
  await requireLogin(opts);
9
- const variables = await VariableService.listVariable({
10
+ const variables = await wmill.listVariable({
10
11
  workspace: workspace.workspaceId,
11
12
  });
12
13
  new Table()
@@ -25,7 +26,7 @@ export async function pushVariable(workspace, remotePath, variable, localVariabl
25
26
  remotePath = removeType(remotePath, "variable");
26
27
  log.debug(`Processing local variable ${remotePath}`);
27
28
  try {
28
- variable = await VariableService.getVariable({
29
+ variable = await wmill.getVariable({
29
30
  workspace: workspace,
30
31
  path: remotePath.replaceAll(SEP, "/"),
31
32
  decryptSecret: plainSecrets,
@@ -42,7 +43,7 @@ export async function pushVariable(workspace, remotePath, variable, localVariabl
42
43
  return;
43
44
  }
44
45
  log.debug(`Variable ${remotePath} is not up-to-date, updating`);
45
- await VariableService.updateVariable({
46
+ await wmill.updateVariable({
46
47
  workspace,
47
48
  path: remotePath.replaceAll(SEP, "/"),
48
49
  alreadyEncrypted: !plainSecrets,
@@ -54,7 +55,7 @@ export async function pushVariable(workspace, remotePath, variable, localVariabl
54
55
  }
55
56
  else {
56
57
  log.info(colors.yellow.bold(`Creating new variable ${remotePath}...`));
57
- await VariableService.createVariable({
58
+ await wmill.createVariable({
58
59
  workspace,
59
60
  alreadyEncrypted: !plainSecrets,
60
61
  requestBody: {
@@ -84,7 +85,7 @@ async function add(opts, value, remotePath) {
84
85
  if (!validatePath(remotePath)) {
85
86
  return;
86
87
  }
87
- if (await VariableService.existsVariable({
88
+ if (await wmill.existsVariable({
88
89
  workspace: workspace.workspaceId,
89
90
  path: remotePath,
90
91
  })) {
package/esm/workspace.js CHANGED
@@ -2,7 +2,8 @@
2
2
  import * as dntShim from "./_dnt.shims.js";
3
3
  import { getRootStore } from "./store.js";
4
4
  import { loginInteractive, tryGetLoginInfo } from "./login.js";
5
- import { colors, Command, Input, log, setClient, Table, UserService, WorkspaceService, SettingService, } from "./deps.js";
5
+ import { colors, Command, Input, log, setClient, Table } from "./deps.js";
6
+ import * as wmill from "./gen/services.gen.js";
6
7
  import { requireLogin } from "./context.js";
7
8
  export async function allWorkspaces() {
8
9
  try {
@@ -130,7 +131,7 @@ export async function add(opts, workspaceName, workspaceId, remote) {
130
131
  setClient(token, remote.endsWith("/") ? remote.substring(0, remote.length - 1) : remote);
131
132
  let alreadyExists = false;
132
133
  try {
133
- alreadyExists = await WorkspaceService.existsWorkspace({
134
+ alreadyExists = await wmill.existsWorkspace({
134
135
  requestBody: { id: workspaceId },
135
136
  });
136
137
  }
@@ -141,10 +142,10 @@ export async function add(opts, workspaceName, workspaceId, remote) {
141
142
  if (opts.create) {
142
143
  if (!alreadyExists) {
143
144
  log.info(colors.yellow(`Workspace at id ${workspaceId} on ${remote} does not exist. Creating...`));
144
- const automateUsernameCreation = (await SettingService.getGlobal({
145
+ const automateUsernameCreation = (await wmill.getGlobal({
145
146
  key: "automate_username_creation",
146
147
  })) ?? false;
147
- await WorkspaceService.createWorkspace({
148
+ await wmill.createWorkspace({
148
149
  requestBody: {
149
150
  id: workspaceId,
150
151
  name: opts.createWorkspaceName ?? workspaceName,
@@ -156,7 +157,7 @@ export async function add(opts, workspaceName, workspaceId, remote) {
156
157
  else if (!alreadyExists) {
157
158
  log.info(colors.red.bold(`! Workspace at id ${workspaceId} on ${remote} does not exist. Re-run with --create to create it. Aborting.`));
158
159
  log.info("On that instance and with those credentials, the workspaces that you can access are:");
159
- const workspaces = await WorkspaceService.listWorkspaces();
160
+ const workspaces = await wmill.listWorkspaces();
160
161
  for (const workspace of workspaces) {
161
162
  log.info(`- ${workspace.id} (name: ${workspace.name})`);
162
163
  }
@@ -209,7 +210,7 @@ async function remove(_opts, name) {
209
210
  }
210
211
  async function whoami(_opts) {
211
212
  await requireLogin(_opts);
212
- log.info(await UserService.globalWhoami());
213
+ log.info(await wmill.globalWhoami());
213
214
  const activeName = await getActiveWorkspaceName(_opts);
214
215
  log.info("Active: " + colors.green.bold(activeName || "none"));
215
216
  }