@platforma-sdk/block-tools 2.10.13 → 2.10.15

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 (169) hide show
  1. package/dist/cli.js +23 -2
  2. package/dist/cli.js.map +1 -1
  3. package/dist/cli.mjs +1944 -100
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/cmd/index.d.ts +10 -4
  6. package/dist/cmd/structure/check.d.ts +10 -0
  7. package/dist/cmd/structure/init.d.ts +18 -0
  8. package/dist/cmd/structure/refresh.d.ts +11 -0
  9. package/dist/cmd/update-deps.d.ts +7 -0
  10. package/dist/structure/cli/run-structure.d.ts +19 -0
  11. package/dist/structure/engine/api.d.ts +55 -0
  12. package/dist/structure/engine/builders.d.ts +95 -0
  13. package/dist/structure/engine/content-rules.d.ts +148 -0
  14. package/dist/structure/engine/ctx.d.ts +34 -0
  15. package/dist/structure/engine/discovery-fs.d.ts +22 -0
  16. package/dist/structure/engine/discovery.d.ts +39 -0
  17. package/dist/structure/engine/flatten.d.ts +3 -0
  18. package/dist/structure/engine/fs/api.d.ts +27 -0
  19. package/dist/structure/engine/fs/memory.d.ts +16 -0
  20. package/dist/structure/engine/fs/node.d.ts +14 -0
  21. package/dist/structure/engine/glob.d.ts +4 -0
  22. package/dist/structure/engine/ir.d.ts +124 -0
  23. package/dist/structure/engine/parsers/json.d.ts +37 -0
  24. package/dist/structure/engine/parsers/lines.d.ts +9 -0
  25. package/dist/structure/engine/parsers/yaml.d.ts +18 -0
  26. package/dist/structure/engine/registry-client.d.ts +34 -0
  27. package/dist/structure/engine/runner.d.ts +45 -0
  28. package/dist/structure/engine/templates.d.ts +30 -0
  29. package/dist/structure/engine/testing.d.ts +34 -0
  30. package/dist/structure/engine/version.d.ts +18 -0
  31. package/dist/structure/init-block-constructor.d.ts +32 -0
  32. package/dist/structure/rules/block-package-json.d.ts +9 -0
  33. package/dist/structure/rules/block.d.ts +1 -0
  34. package/dist/structure/rules/migrations.d.ts +2 -0
  35. package/dist/structure/rules/model-package-json.d.ts +3 -0
  36. package/dist/structure/rules/model.d.ts +1 -0
  37. package/dist/structure/rules/root-catalog-bump.d.ts +1 -0
  38. package/dist/structure/rules/root-gitignore.d.ts +2 -0
  39. package/dist/structure/rules/root-package-json.d.ts +3 -0
  40. package/dist/structure/rules/root-pnpm-workspace.d.ts +15 -0
  41. package/dist/structure/rules/root.d.ts +1 -0
  42. package/dist/structure/rules/shared/colocated-tests.d.ts +2 -0
  43. package/dist/structure/rules/shared/key-order.d.ts +1 -0
  44. package/dist/structure/rules/software-package-json.d.ts +3 -0
  45. package/dist/structure/rules/software.d.ts +1 -0
  46. package/dist/structure/rules/test-package-json.d.ts +3 -0
  47. package/dist/structure/rules/test.d.ts +1 -0
  48. package/dist/structure/rules/ui-package-json.d.ts +3 -0
  49. package/dist/structure/rules/ui.d.ts +1 -0
  50. package/dist/structure/rules/workflow-package-json.d.ts +3 -0
  51. package/dist/structure/rules/workflow.d.ts +1 -0
  52. package/dist/structure/structure-definition.d.ts +1 -0
  53. package/package.json +8 -6
  54. package/src/cmd/index.ts +10 -4
  55. package/src/cmd/structure/check.ts +51 -0
  56. package/src/cmd/structure/init.ts +65 -0
  57. package/src/cmd/structure/refresh.ts +44 -0
  58. package/src/cmd/update-deps.ts +15 -3
  59. package/src/structure/__tests__/colocated-test-wiring.test.ts +107 -0
  60. package/src/structure/__tests__/floor-version.test.ts +52 -0
  61. package/src/structure/__tests__/init-catalog-resolution.test.ts +82 -0
  62. package/src/structure/__tests__/init-check-parity.test.ts +59 -0
  63. package/src/structure/__tests__/model-package-json.snapshot.test.ts +60 -0
  64. package/src/structure/__tests__/oxfmt-clean-init.test.ts +64 -0
  65. package/src/structure/__tests__/root-catalog-bump.test.ts +110 -0
  66. package/src/structure/__tests__/seed-disjointness.test.ts +79 -0
  67. package/src/structure/cli/run-structure.ts +89 -0
  68. package/src/structure/engine/__tests__/content-rules/active-state-guards.test.ts +61 -0
  69. package/src/structure/engine/__tests__/content-rules/catalog-pin.test.ts +46 -0
  70. package/src/structure/engine/__tests__/content-rules/enforce-alphabetical-order.test.ts +55 -0
  71. package/src/structure/engine/__tests__/content-rules/enforce-field-order.test.ts +73 -0
  72. package/src/structure/engine/__tests__/content-rules/ensure-catalog-absent.test.ts +29 -0
  73. package/src/structure/engine/__tests__/content-rules/ensure-catalog-latest.test.ts +70 -0
  74. package/src/structure/engine/__tests__/content-rules/ensure-dep.test.ts +63 -0
  75. package/src/structure/engine/__tests__/content-rules/ensure-deps-bulk.test.ts +46 -0
  76. package/src/structure/engine/__tests__/content-rules/ensure-field-entries.test.ts +35 -0
  77. package/src/structure/engine/__tests__/content-rules/ensure-field.test.ts +56 -0
  78. package/src/structure/engine/__tests__/content-rules/ensure-script.test.ts +39 -0
  79. package/src/structure/engine/__tests__/content-rules/ensure-workspace-scope-deps.test.ts +92 -0
  80. package/src/structure/engine/__tests__/content-rules/gitignore.test.ts +50 -0
  81. package/src/structure/engine/__tests__/content-rules/pin-catalog-to.test.ts +64 -0
  82. package/src/structure/engine/__tests__/content-rules/prune-keys.test.ts +59 -0
  83. package/src/structure/engine/__tests__/content-rules/registry-client.test.ts +116 -0
  84. package/src/structure/engine/__tests__/content-rules/remove-field.test.ts +49 -0
  85. package/src/structure/engine/__tests__/content-rules/require-field.test.ts +40 -0
  86. package/src/structure/engine/__tests__/content-rules/transform-at.test.ts +33 -0
  87. package/src/structure/engine/__tests__/content-rules/when-inner.test.ts +244 -0
  88. package/src/structure/engine/__tests__/content-rules/workspace-module-paths.test.ts +53 -0
  89. package/src/structure/engine/__tests__/discovery.test.ts +160 -0
  90. package/src/structure/engine/__tests__/fs-memory.test.ts +59 -0
  91. package/src/structure/engine/__tests__/glob.test.ts +43 -0
  92. package/src/structure/engine/__tests__/parsers-json.test.ts +189 -0
  93. package/src/structure/engine/__tests__/parsers-lines.test.ts +44 -0
  94. package/src/structure/engine/__tests__/parsers-yaml.test.ts +90 -0
  95. package/src/structure/engine/__tests__/recheck.test.ts +99 -0
  96. package/src/structure/engine/__tests__/registry-lookup.test.ts +49 -0
  97. package/src/structure/engine/__tests__/runner-when-inside-managed.test.ts +136 -0
  98. package/src/structure/engine/__tests__/runner.test.ts +136 -0
  99. package/src/structure/engine/__tests__/synthetic.test.ts +153 -0
  100. package/src/structure/engine/__tests__/version.test.ts +44 -0
  101. package/src/structure/engine/__tests__/when-files-exist.test.ts +89 -0
  102. package/src/structure/engine/api.ts +131 -0
  103. package/src/structure/engine/builders.ts +341 -0
  104. package/src/structure/engine/content-rules.ts +616 -0
  105. package/src/structure/engine/ctx.ts +94 -0
  106. package/src/structure/engine/discovery-fs.ts +209 -0
  107. package/src/structure/engine/discovery.ts +168 -0
  108. package/src/structure/engine/flatten.ts +117 -0
  109. package/src/structure/engine/fs/api.ts +40 -0
  110. package/src/structure/engine/fs/memory.ts +132 -0
  111. package/src/structure/engine/fs/node.ts +89 -0
  112. package/src/structure/engine/glob.ts +42 -0
  113. package/src/structure/engine/ir.ts +149 -0
  114. package/src/structure/engine/parsers/json.ts +212 -0
  115. package/src/structure/engine/parsers/lines.ts +42 -0
  116. package/src/structure/engine/parsers/yaml.ts +72 -0
  117. package/src/structure/engine/registry-client.ts +140 -0
  118. package/src/structure/engine/runner.ts +519 -0
  119. package/src/structure/engine/templates.ts +74 -0
  120. package/src/structure/engine/testing.ts +93 -0
  121. package/src/structure/engine/version.ts +60 -0
  122. package/src/structure/init-block-constructor.ts +164 -0
  123. package/src/structure/rules/block-package-json.ts +156 -0
  124. package/src/structure/rules/block.ts +29 -0
  125. package/src/structure/rules/migrations.ts +63 -0
  126. package/src/structure/rules/model-package-json.ts +123 -0
  127. package/src/structure/rules/model.ts +65 -0
  128. package/src/structure/rules/root-catalog-bump.ts +77 -0
  129. package/src/structure/rules/root-gitignore.ts +27 -0
  130. package/src/structure/rules/root-package-json.ts +119 -0
  131. package/src/structure/rules/root-pnpm-workspace.ts +103 -0
  132. package/src/structure/rules/root.ts +43 -0
  133. package/src/structure/rules/shared/colocated-tests.ts +11 -0
  134. package/src/structure/rules/shared/key-order.ts +34 -0
  135. package/src/structure/rules/software-package-json.ts +86 -0
  136. package/src/structure/rules/software.ts +33 -0
  137. package/src/structure/rules/test-package-json.ts +70 -0
  138. package/src/structure/rules/test.ts +40 -0
  139. package/src/structure/rules/ui-package-json.ts +108 -0
  140. package/src/structure/rules/ui.ts +75 -0
  141. package/src/structure/rules/workflow-package-json.ts +92 -0
  142. package/src/structure/rules/workflow.ts +51 -0
  143. package/src/structure/structure-definition.ts +28 -0
  144. package/src/structure/templates/static/block/index.d.ts +6 -0
  145. package/src/structure/templates/static/block/index.js +8 -0
  146. package/src/structure/templates/static/block/logos/block-logo.png +0 -0
  147. package/src/structure/templates/static/block/logos/organization-logo.png +0 -0
  148. package/src/structure/templates/static/model/.oxfmtrc.json +4 -0
  149. package/src/structure/templates/static/model/.oxlintrc.json +3 -0
  150. package/src/structure/templates/static/model/src/index.ts +13 -0
  151. package/src/structure/templates/static/model/tsconfig.json +4 -0
  152. package/src/structure/templates/static/root/.gitignore +13 -0
  153. package/src/structure/templates/static/root/.vscode/settings.json +3 -0
  154. package/src/structure/templates/static/root/turbo.json +35 -0
  155. package/src/structure/templates/static/test/tsconfig.json +5 -0
  156. package/src/structure/templates/static/test/vitest.config.mts +8 -0
  157. package/src/structure/templates/static/ui/.oxfmtrc.json +3 -0
  158. package/src/structure/templates/static/ui/.oxlintrc.json +3 -0
  159. package/src/structure/templates/static/ui/index.html +12 -0
  160. package/src/structure/templates/static/ui/src/main.ts +5 -0
  161. package/src/structure/templates/static/ui/tsconfig.json +4 -0
  162. package/src/structure/templates/static/workflow/format.el +42 -0
  163. package/src/structure/templates/static/workflow/tsconfig.json +16 -0
  164. package/src/structure/templates/static/workflow/vitest.config.mts +9 -0
  165. package/src/structure/templates/text/README.md +5 -0
  166. package/src/structure/templates/text/docs/description.md +3 -0
  167. package/src/structure/templates/text/ui/src/MainPage.tpl.vue +9 -0
  168. package/src/structure/templates/text/ui/src/app.tpl.ts +11 -0
  169. package/src/structure/templates/text/workflow/src/main.tpl.tengo +10 -0
package/dist/cli.mjs CHANGED
@@ -1,13 +1,14 @@
1
- import { H as e, K as t, O as n, U as r, _ as i, _t as a, b as o, et as s, n as c, p as l, rt as u } from "./config-DpfTzcgG.mjs";
2
- import { Command as d, Flags as f } from "@oclif/core";
1
+ import { H as e, K as t, O as n, U as r, _ as i, _t as a, b as o, et as s, n as c, p as ee, rt as l } from "./config-DpfTzcgG.mjs";
2
+ import { Args as u, Command as d, Flags as f } from "@oclif/core";
3
3
  import p from "node:path";
4
4
  import m from "node:fs";
5
- import { BlockPackManifest as h, StableChannel as g, overrideDescriptionVersion as _, overrideManifestVersion as v } from "@milaboratories/pl-model-middle-layer";
6
- import { OclifLoggerAdapter as y } from "@milaboratories/ts-helpers-oclif";
7
- import b from "yaml";
8
- import { updatePackages as x } from "@platforma-sdk/blocks-deps-updater";
5
+ import { BlockPackManifest as te, StableChannel as ne, overrideDescriptionVersion as re, overrideManifestVersion as ie } from "@milaboratories/pl-model-middle-layer";
6
+ import { OclifLoggerAdapter as h } from "@milaboratories/ts-helpers-oclif";
7
+ import ae, { parse as oe, parseDocument as se, stringify as ce } from "yaml";
8
+ import { setTimeout as le } from "node:timers/promises";
9
+ import { confirm as ue, input as de, select as fe } from "@inquirer/prompts";
9
10
  //#region src/cmd/build-meta.ts
10
- var S = class e extends d {
11
+ var pe = class e extends d {
11
12
  static description = "Extracts meta information from blocks package.json and outputs meta.json with embedded binary and textual information linked from the meta section.";
12
13
  static flags = {
13
14
  modulePath: f.string({
@@ -24,13 +25,13 @@ var S = class e extends d {
24
25
  })
25
26
  };
26
27
  async run() {
27
- let { flags: t } = await this.parse(e), n = p.resolve(t.modulePath), i = await s(await u((await r(n)).meta, n));
28
+ let { flags: t } = await this.parse(e), n = p.resolve(t.modulePath), i = await s(await l((await r(n)).meta, n));
28
29
  await m.promises.writeFile(p.resolve(t.destination), JSON.stringify(i));
29
30
  }
30
31
  };
31
32
  //#endregion
32
33
  //#region src/cmd/build-model.ts
33
- async function C(e) {
34
+ async function me(e) {
34
35
  try {
35
36
  return await m.promises.readFile(e, "utf8");
36
37
  } catch (e) {
@@ -38,7 +39,7 @@ async function C(e) {
38
39
  throw e;
39
40
  }
40
41
  }
41
- var w = class e extends d {
42
+ var he = class e extends d {
42
43
  static description = "Extracts and outputs block model JSON from pre-built block model module";
43
44
  static flags = {
44
45
  modulePath: f.string({
@@ -66,13 +67,13 @@ var w = class e extends d {
66
67
  let { config: i } = n;
67
68
  if (!i) throw Error("Malformed \"model\" object, check it is created with \"BlockModel\" and \".done()\" is executed as the call in the chain.");
68
69
  if (!("outputs" in i) || !("sections" in i)) throw Error("\"config\" has unexpected structure");
69
- let o = await C(t.sourceBundle);
70
+ let o = await me(t.sourceBundle);
70
71
  o !== void 0 && (i.code = {
71
72
  type: "plain",
72
73
  content: o
73
74
  }), await m.promises.writeFile(p.resolve(t.destination), JSON.stringify(i));
74
75
  }
75
- }, T = class e extends d {
76
+ }, ge = class e extends d {
76
77
  static description = "List all available global overview snapshots in the registry";
77
78
  static flags = {
78
79
  registry: f.string({
@@ -88,7 +89,7 @@ var w = class e extends d {
88
89
  })
89
90
  };
90
91
  async run() {
91
- let { flags: t } = await this.parse(e), n = await new o(i(t.registry), new y(this)).listGlobalOverviewSnapshots();
92
+ let { flags: t } = await this.parse(e), n = await new o(i(t.registry), new h(this)).listGlobalOverviewSnapshots();
92
93
  if (t.json) this.log(JSON.stringify(n, null, 2));
93
94
  else if (n.length === 0) this.log("No snapshots found.");
94
95
  else {
@@ -96,7 +97,7 @@ var w = class e extends d {
96
97
  for (let e of n) this.log(` ${e.timestamp}`), this.log(` Path: ${e.path}`), this.log("");
97
98
  }
98
99
  }
99
- }, E = class e extends d {
100
+ }, _e = class e extends d {
100
101
  static description = "Mark target block stable";
101
102
  static flags = {
102
103
  modulePath: f.string({
@@ -110,7 +111,7 @@ var w = class e extends d {
110
111
  hidden: !0,
111
112
  summary: "custom channel",
112
113
  helpValue: "<channel name>",
113
- default: g
114
+ default: ne
114
115
  }),
115
116
  "version-override": f.file({
116
117
  char: "v",
@@ -136,11 +137,11 @@ var w = class e extends d {
136
137
  };
137
138
  async run() {
138
139
  let { flags: t } = await this.parse(e), n = await r(p.resolve(t.modulePath));
139
- t["version-override"] && (n = _(n, t["version-override"]));
140
- let a = new o(i(t.registry), new y(this));
140
+ t["version-override"] && (n = re(n, t["version-override"]));
141
+ let a = new o(i(t.registry), new h(this));
141
142
  t.unmark ? await a.removePackageFromChannel(n.id, t.channel) : await a.addPackageToChannel(n.id, t.channel), t.refresh && await a.updateIfNeeded();
142
143
  }
143
- }, D = class n extends d {
144
+ }, ve = class n extends d {
144
145
  static description = "Builds block pack and outputs a block pack manifest consolidating all references assets into a single folder";
145
146
  static flags = {
146
147
  modulePath: f.string({
@@ -163,12 +164,12 @@ var w = class e extends d {
163
164
  };
164
165
  //#endregion
165
166
  //#region src/cmd/publish.ts
166
- function O(e, t) {
167
+ function ye(e, t) {
167
168
  let n = { ...e };
168
- for (let e in t) t[e] && typeof t[e] == "object" && !Array.isArray(t[e]) && n[e] && typeof n[e] == "object" && !Array.isArray(n[e]) ? n[e] = O(n[e], t[e]) : n[e] = t[e];
169
+ for (let e in t) t[e] && typeof t[e] == "object" && !Array.isArray(t[e]) && n[e] && typeof n[e] == "object" && !Array.isArray(n[e]) ? n[e] = ye(n[e], t[e]) : n[e] = t[e];
169
170
  return n;
170
171
  }
171
- var k = class e extends d {
172
+ var be = class e extends d {
172
173
  static description = "Publishes the block package and refreshes the registry (for v2 block-pack schema)";
173
174
  static flags = {
174
175
  registry: f.string({
@@ -201,14 +202,14 @@ var k = class e extends d {
201
202
  })
202
203
  };
203
204
  async run() {
204
- let { flags: t } = await this.parse(e), n = p.resolve(t.manifest), r = JSON.parse(await m.promises.readFile(n, { encoding: "utf-8" })), a = h.parse(r);
205
- a = O(r, a);
205
+ let { flags: t } = await this.parse(e), n = p.resolve(t.manifest), r = JSON.parse(await m.promises.readFile(n, { encoding: "utf-8" })), a = te.parse(r);
206
+ a = ye(r, a);
206
207
  let s = p.dirname(n);
207
- this.log(`Manifest root = ${s}`), t["version-override"] && (a = v(a, t["version-override"]));
208
- let c = new o(i(t.registry), new y(this));
209
- await c.publishPackage(a, async (e) => Buffer.from(await m.promises.readFile(p.resolve(s, e)))), t.unstable || (this.log(`Adding package to ${g} channel...`), await c.addPackageToChannel(a.description.id, g)), t.refresh && await c.updateIfNeeded();
208
+ this.log(`Manifest root = ${s}`), t["version-override"] && (a = ie(a, t["version-override"]));
209
+ let c = new o(i(t.registry), new h(this));
210
+ await c.publishPackage(a, async (e) => Buffer.from(await m.promises.readFile(p.resolve(s, e)))), t.unstable || (this.log(`Adding package to ${ne} channel...`), await c.addPackageToChannel(a.description.id, ne)), t.refresh && await c.updateIfNeeded();
210
211
  }
211
- }, A = class e extends d {
212
+ }, xe = class e extends d {
212
213
  static description = "Refresh overview files based on published but not proecessed artefacts";
213
214
  static flags = {
214
215
  registry: f.string({
@@ -233,9 +234,9 @@ var k = class e extends d {
233
234
  };
234
235
  async run() {
235
236
  let { flags: t } = await this.parse(e);
236
- await new o(i(t.registry), new y(this)).updateIfNeeded(t.mode);
237
+ await new o(i(t.registry), new h(this)).updateIfNeeded(t.mode);
237
238
  }
238
- }, j = class e extends d {
239
+ }, Se = class e extends d {
239
240
  static description = "Restore global overview from a snapshot";
240
241
  static flags = {
241
242
  registry: f.string({
@@ -257,7 +258,7 @@ var k = class e extends d {
257
258
  })
258
259
  };
259
260
  async run() {
260
- let { flags: t } = await this.parse(e), n = new o(i(t.registry), new y(this)), r = await n.listGlobalOverviewSnapshots();
261
+ let { flags: t } = await this.parse(e), n = new o(i(t.registry), new h(this)), r = await n.listGlobalOverviewSnapshots();
261
262
  if (r.find((e) => e.timestamp === t.snapshot) || this.error(`Snapshot '${t.snapshot}' not found. Available snapshots:\n${r.map((e) => ` - ${e.timestamp}`).join("\n") || " (none)"}`), !t["skip-confirmation"]) {
262
263
  let e = (await import("node:readline")).createInterface({
263
264
  input: process.stdin,
@@ -276,10 +277,16 @@ var k = class e extends d {
276
277
  this.error(`Failed to restore from snapshot: ${String(e)}`);
277
278
  }
278
279
  }
280
+ }, Ce = class extends d {
281
+ static description = "[DEPRECATED] Use `block-tools structure refresh --update-deps-only`. This alias delegates to it.";
282
+ static examples = ["<%= config.bin %> <%= command.id %>"];
283
+ async run() {
284
+ this.warn("`block-tools update-deps` is deprecated and will be removed in a future release. Use `block-tools structure refresh --update-deps-only` instead. Delegating now."), await this.config.runCommand("structure:refresh", ["--update-deps-only"]);
285
+ }
279
286
  };
280
287
  //#endregion
281
288
  //#region src/registry_v1/flags.ts
282
- function M(e) {
289
+ function we(e) {
283
290
  let t = e.match(/(?<destName>[^/\\]+)=(?<src>.*)/);
284
291
  if (t) {
285
292
  let { src: e, destName: n } = t.groups;
@@ -292,91 +299,1928 @@ function M(e) {
292
299
  destName: p.basename(e)
293
300
  };
294
301
  }
295
- var N = f.custom({
302
+ var Te = f.custom({
296
303
  summary: "target files to upload",
297
304
  helpValue: "file_path | package_name=file_path",
298
- parse: async (e) => M(e)
299
- }), P = [
305
+ parse: async (e) => we(e)
306
+ }), Ee = [
300
307
  "registry",
301
308
  "organization",
302
309
  "package",
303
310
  "version"
304
- ], F = {
305
- "build-meta": S,
306
- "build-model": w,
307
- "list-overview-snapshots": T,
308
- "mark-stable": E,
309
- pack: D,
310
- publish: k,
311
- "refresh-registry": A,
312
- "restore-overview-from-snapshot": j,
313
- "upload-package-v1": class e extends d {
314
- static description = "Uploads V1 package and refreshes the registry";
311
+ ], De = class e extends d {
312
+ static description = "Uploads V1 package and refreshes the registry";
313
+ static flags = {
314
+ registry: f.string({
315
+ char: "r",
316
+ summary: "full address of the registry or alias from .pl.reg",
317
+ helpValue: "<address|alias>",
318
+ env: "PL_REGISTRY"
319
+ }),
320
+ organization: f.string({
321
+ char: "o",
322
+ summary: "target organisation",
323
+ env: "PL_PACKAGE_ORGANIZATION"
324
+ }),
325
+ package: f.string({
326
+ char: "p",
327
+ summary: "target package",
328
+ env: "PL_PACKAGE_NAME"
329
+ }),
330
+ version: f.string({
331
+ char: "v",
332
+ summary: "target version",
333
+ env: "PL_PACKAGE_VERSION"
334
+ }),
335
+ meta: f.file({
336
+ char: "m",
337
+ summary: "json file containing meta information to associate with tha package",
338
+ exists: !0
339
+ }),
340
+ file: Te({
341
+ char: "f",
342
+ summary: "package files",
343
+ multiple: !0,
344
+ default: []
345
+ }),
346
+ refresh: f.boolean({
347
+ summary: "refresh repository after adding the package",
348
+ default: !0,
349
+ allowNo: !0,
350
+ env: "PL_REGISTRY_REFRESH"
351
+ })
352
+ };
353
+ async run() {
354
+ let { flags: t } = await this.parse(e), n = ee.parse({});
355
+ for (let e of Ee) t[e] && (n[e] = t[e]);
356
+ t.meta && (t.meta.endsWith(".json") ? n.meta = JSON.parse(await m.promises.readFile(t.meta, { encoding: "utf-8" })) : t.meta.endsWith(".yaml") && (n.meta = ae.parse(await m.promises.readFile(t.meta, { encoding: "utf-8" }))));
357
+ for (let e of t.file) n.files[e.destName] = e.src;
358
+ let r = await c(n);
359
+ this.log(ae.stringify(r.conf));
360
+ let i = r.createRegistry(new h(this)), a = r.fullPackageName, o = i.constructNewPackage(a);
361
+ for (let [e, t] of Object.entries(r.conf.files)) {
362
+ this.log(`Uploading ${t} -> ${e} ...`);
363
+ let n = await m.promises.readFile(t);
364
+ await o.addFile(e, n);
365
+ }
366
+ this.log("Uploading meta information..."), await o.writeMeta(r.conf.meta), await o.finish(), t.refresh && await i.updateIfNeeded();
367
+ }
368
+ }, Oe = class {
369
+ constructor(e) {
370
+ this.root = e;
371
+ }
372
+ abs(e) {
373
+ return p.resolve(this.root, e);
374
+ }
375
+ read(e) {
376
+ return m.readFileSync(this.abs(e), "utf-8");
377
+ }
378
+ write(e, t) {
379
+ let n = this.abs(e);
380
+ m.mkdirSync(p.dirname(n), { recursive: !0 }), m.writeFileSync(n, t, "utf-8");
381
+ }
382
+ writeBinary(e, t) {
383
+ let n = this.abs(e);
384
+ m.mkdirSync(p.dirname(n), { recursive: !0 }), m.writeFileSync(n, t);
385
+ }
386
+ exists(e) {
387
+ try {
388
+ return m.statSync(this.abs(e)), !0;
389
+ } catch {
390
+ return !1;
391
+ }
392
+ }
393
+ list(e) {
394
+ let t = this.abs(e);
395
+ try {
396
+ if (!m.statSync(t).isDirectory()) return [];
397
+ } catch {
398
+ return [];
399
+ }
400
+ let n = [];
401
+ function r(e, t) {
402
+ let i = m.readdirSync(t, { withFileTypes: !0 });
403
+ for (let a of i) {
404
+ let i = e ? `${e}/${a.name}` : a.name, o = p.join(t, a.name);
405
+ a.isDirectory() ? r(i, o) : a.isFile() && n.push(i);
406
+ }
407
+ }
408
+ return r(e === "" || e === "." ? "" : e, t), n.sort();
409
+ }
410
+ listDir(e) {
411
+ let t = this.abs(e), n;
412
+ try {
413
+ n = m.readdirSync(t, { withFileTypes: !0 });
414
+ } catch {
415
+ return [];
416
+ }
417
+ return n.map((e) => ({
418
+ name: e.name,
419
+ isDirectory: e.isDirectory()
420
+ })).sort((e, t) => e.name.localeCompare(t.name));
421
+ }
422
+ move(e, t) {
423
+ let n = this.abs(e), r = this.abs(t);
424
+ m.mkdirSync(p.dirname(r), { recursive: !0 }), m.renameSync(n, r);
425
+ }
426
+ delete(e) {
427
+ m.rmSync(this.abs(e), {
428
+ recursive: !0,
429
+ force: !0
430
+ });
431
+ }
432
+ }, ke = class {
433
+ constructor(e) {
434
+ this.root = e;
435
+ }
436
+ staticRead(e) {
437
+ return m.readFileSync(p.resolve(this.root, "static", e), "utf-8");
438
+ }
439
+ staticReadBinary(e) {
440
+ return m.readFileSync(p.resolve(this.root, "static", e));
441
+ }
442
+ textRead(e) {
443
+ return m.readFileSync(p.resolve(this.root, "text", e), "utf-8");
444
+ }
445
+ };
446
+ function Ae(e, t) {
447
+ return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (e, n) => t[n] ?? `\${${n}}`);
448
+ }
449
+ //#endregion
450
+ //#region src/structure/engine/flatten.ts
451
+ var je = ["default", "init"];
452
+ function Me(e, t) {
453
+ if (!e) return t;
454
+ if (!t) return e;
455
+ let n = e.endsWith("/") ? e.slice(0, -1) : e, r = t.startsWith("/") ? t.slice(1) : t;
456
+ return r ? `${n}/${r}` : n;
457
+ }
458
+ function Ne(e, t) {
459
+ return e.filter((e) => e.scope === t).slice().sort((e, t) => e.path.localeCompare(t.path));
460
+ }
461
+ function Pe(e, t) {
462
+ let n = [];
463
+ function r(e, i, a, o, s) {
464
+ if (e.kind === "scope") {
465
+ let n = Ne(t.modules, e.scope);
466
+ for (let t of n) for (let n of e.children) r(n, e.scope, t.path, o, s);
467
+ return;
468
+ }
469
+ if (e.kind === "when") {
470
+ let t = o.concat(e.trigger);
471
+ for (let n of e.children) r(n, i, a, t, s);
472
+ return;
473
+ }
474
+ if (e.kind === "mode") {
475
+ for (let t of e.children) r(t, i, a, o, e.modes);
476
+ return;
477
+ }
478
+ if (i === void 0 || a === void 0) throw Error(`flatten: leaf '${Ie(e)}' is not inside a scope() frame`);
479
+ if (e.kind === "rename") {
480
+ n.push({
481
+ leaf: e,
482
+ scope: i,
483
+ modulePath: a,
484
+ resolvedPath: Me(a, e.from),
485
+ resolvedTo: Me(a, e.to),
486
+ triggers: o,
487
+ modes: s
488
+ });
489
+ return;
490
+ }
491
+ n.push({
492
+ leaf: e,
493
+ scope: i,
494
+ modulePath: a,
495
+ resolvedPath: Me(a, Fe(e)),
496
+ triggers: o,
497
+ modes: s
498
+ });
499
+ }
500
+ for (let t of e.children) r(t, void 0, void 0, [], je);
501
+ return n;
502
+ }
503
+ function Fe(e) {
504
+ switch (e.kind) {
505
+ case "fixed":
506
+ case "managed":
507
+ case "scaffold":
508
+ case "seed":
509
+ case "remove": return e.path;
510
+ case "rename": return e.from;
511
+ }
512
+ }
513
+ function Ie(e) {
514
+ return e.kind === "rename" ? `rename ${e.from} -> ${e.to}` : `${e.kind} ${e.path}`;
515
+ }
516
+ //#endregion
517
+ //#region src/structure/engine/glob.ts
518
+ var Le = /[.+^${}()|[\]\\]/g;
519
+ function Re(e) {
520
+ let t = "";
521
+ for (let n = 0; n < e.length; n++) {
522
+ let r = e[n];
523
+ r === "*" ? e[n + 1] === "*" ? (n++, e[n + 1] === "/" ? (n++, t += "(?:.*/)?") : t += ".*") : t += "[^/]*" : r === "?" ? t += "[^/]" : t += r.replace(Le, "\\$&");
524
+ }
525
+ return RegExp(`^${t}$`);
526
+ }
527
+ function ze(e, t) {
528
+ return Re(e).test(t);
529
+ }
530
+ //#endregion
531
+ //#region src/structure/engine/builders.ts
532
+ var g, _;
533
+ function Be(e) {
534
+ if (!g) throw Error(`${e}() called outside defineStructure(). Builders must run inside the lambda passed to defineStructure(...).`);
535
+ return g;
536
+ }
537
+ function v(e, t) {
538
+ let n = Be(e);
539
+ n.stack[n.stack.length - 1].push(t);
540
+ }
541
+ function Ve(e, t) {
542
+ let n = _;
543
+ _ = e;
544
+ try {
545
+ return t();
546
+ } finally {
547
+ _ = n;
548
+ }
549
+ }
550
+ function He() {
551
+ return _;
552
+ }
553
+ function y() {
554
+ if (!_) throw Error("getActiveRunContext() called outside engine.run(). Generators only see the run context during a run.");
555
+ return _;
556
+ }
557
+ function Ue(e) {
558
+ if (g) throw Error("defineStructure() cannot be called from inside another defineStructure().");
559
+ let t = [], n = {
560
+ root: t,
561
+ stack: [t],
562
+ inScope: !1
563
+ };
564
+ g = n;
565
+ try {
566
+ if (e(), n.stack.length !== 1) throw Error(`defineStructure: builder body left ${n.stack.length - 1} unclosed group frame(s)`);
567
+ let r = { children: t };
568
+ return We(r), r;
569
+ } finally {
570
+ g = void 0;
571
+ }
572
+ }
573
+ function We(e) {
574
+ let t = /* @__PURE__ */ new Map();
575
+ function n(e, r) {
576
+ if (e.kind === "scope") {
577
+ for (let t of e.children) n(t, e.scope);
578
+ return;
579
+ }
580
+ if (e.kind === "when" || e.kind === "mode") {
581
+ for (let t of e.children) n(t, r);
582
+ return;
583
+ }
584
+ if (e.kind === "rename") return;
585
+ let i = t.get(r);
586
+ i || (i = /* @__PURE__ */ new Map(), t.set(r, i));
587
+ let a = i.get(e.path);
588
+ a || (a = /* @__PURE__ */ new Set(), i.set(e.path, a)), a.add(e.kind);
589
+ }
590
+ for (let t of e.children) n(t, "(top-level)");
591
+ for (let [e, n] of t) for (let [t, r] of n) if (r.has("seed") && (r.has("managed") || r.has("fixed") || r.has("scaffold"))) {
592
+ let n = [...r].filter((e) => e !== "seed").sort().join(", ");
593
+ throw Error(`defineStructure validation: path '${t}' under scope '${e}' is declared as both seed and ${n}. Seeds are block-author territory (written once at init, untouched thereafter); engine-managed primitives (fixed/managed/scaffold) rewrite on every refresh. The two contracts cannot coexist on the same path.`);
594
+ }
595
+ }
596
+ function b(e, t) {
597
+ let n = Be("scope");
598
+ if (n.inScope) throw Error("scope() cannot nest. Already inside a scope.");
599
+ let r = {
600
+ kind: "scope",
601
+ scope: e,
602
+ children: []
603
+ };
604
+ n.stack[n.stack.length - 1].push(r), n.stack.push(r.children), n.inScope = !0;
605
+ try {
606
+ t();
607
+ } finally {
608
+ n.stack.pop(), n.inScope = !1;
609
+ }
610
+ }
611
+ var Ge;
612
+ function Ke(e) {
613
+ Ge = e;
614
+ }
615
+ function x(e, t) {
616
+ if (g) {
617
+ let n = g, r = {
618
+ kind: "when",
619
+ trigger: e,
620
+ children: []
621
+ };
622
+ n.stack[n.stack.length - 1].push(r), n.stack.push(r.children);
623
+ try {
624
+ t();
625
+ } finally {
626
+ n.stack.pop();
627
+ }
628
+ return;
629
+ }
630
+ if (!(Ge && Ge(e, t))) throw Error("when() called outside defineStructure() and outside any managed(...) body. Place this call inside one of the two.");
631
+ }
632
+ function S(e) {
633
+ return (t) => t.filesMatch(e);
634
+ }
635
+ function qe(e, t, n) {
636
+ let r = Be(e), i = {
637
+ kind: "mode",
638
+ modes: t,
639
+ children: []
640
+ };
641
+ r.stack[r.stack.length - 1].push(i), r.stack.push(i.children);
642
+ try {
643
+ n();
644
+ } finally {
645
+ r.stack.pop();
646
+ }
647
+ }
648
+ function Je(e) {
649
+ qe("onInitOrUpdate", ["init", "updateDeps"], e);
650
+ }
651
+ function C(e, t) {
652
+ v("fixed", {
653
+ kind: "fixed",
654
+ path: e,
655
+ content: t
656
+ });
657
+ }
658
+ function w(e, t, n) {
659
+ v("managed", {
660
+ kind: "managed",
661
+ path: e,
662
+ initial: t,
663
+ body: n
664
+ });
665
+ }
666
+ function Ye(e, t) {
667
+ v("scaffold", {
668
+ kind: "scaffold",
669
+ path: e,
670
+ initial: t
671
+ });
672
+ }
673
+ function T(e, t) {
674
+ v("seed", {
675
+ kind: "seed",
676
+ path: e,
677
+ initial: t
678
+ });
679
+ }
680
+ function E(e) {
681
+ v("remove", {
682
+ kind: "remove",
683
+ path: e
684
+ });
685
+ }
686
+ function D(e) {
687
+ return {
688
+ kind: "file",
689
+ path: e
690
+ };
691
+ }
692
+ function Xe(e) {
693
+ return {
694
+ kind: "binary",
695
+ path: e
696
+ };
697
+ }
698
+ function Ze(e) {
699
+ return {
700
+ kind: "text",
701
+ value: e
702
+ };
703
+ }
704
+ function Qe(e, t) {
705
+ return {
706
+ kind: "tpl",
707
+ path: e,
708
+ vars: t
709
+ };
710
+ }
711
+ function O(e) {
712
+ return {
713
+ kind: "generate",
714
+ fn: e
715
+ };
716
+ }
717
+ function $e() {
718
+ if (!_) throw Error("blockVars() called outside engine.run(). Generators and managed bodies only see BlockVars during a run.");
719
+ return _.blockVars;
720
+ }
721
+ //#endregion
722
+ //#region src/structure/engine/parsers/json.ts
723
+ function et(e) {
724
+ return JSON.parse(e);
725
+ }
726
+ var tt = 100, nt = 2;
727
+ function rt(e) {
728
+ return e.length === 0 ? "[]" : "[" + e.map(it).join(", ") + "]";
729
+ }
730
+ function it(e) {
731
+ if (Array.isArray(e)) return rt(e);
732
+ if (A(e)) {
733
+ let t = Object.entries(e);
734
+ return t.length === 0 ? "{}" : "{ " + t.map(([e, t]) => `${JSON.stringify(e)}: ${it(t)}`).join(", ") + " }";
735
+ }
736
+ return JSON.stringify(e);
737
+ }
738
+ function at(e, t, n, r) {
739
+ let i = t + nt, a = " ".repeat(i);
740
+ if (Array.isArray(e)) {
741
+ let o = rt(e);
742
+ if (n + o.length + r <= tt) return o;
743
+ let s = e.length - 1;
744
+ return "[\n" + e.map((e, t) => a + at(e, i, i, t === s ? 0 : 1)).join(",\n") + "\n" + " ".repeat(t) + "]";
745
+ }
746
+ if (A(e)) {
747
+ let n = Object.entries(e);
748
+ if (n.length === 0) return "{}";
749
+ let r = n.length - 1;
750
+ return "{\n" + n.map(([e, t], n) => {
751
+ let o = `${a}${JSON.stringify(e)}: `;
752
+ return o + at(t, i, o.length, n === r ? 0 : 1);
753
+ }).join(",\n") + "\n" + " ".repeat(t) + "}";
754
+ }
755
+ return JSON.stringify(e);
756
+ }
757
+ function ot(e, t) {
758
+ return t?.collapse ? at(JSON.parse(JSON.stringify(e ?? null)), 0, 0, 0) + "\n" : JSON.stringify(e, null, 2) + "\n";
759
+ }
760
+ function k(e) {
761
+ return e === "" || e === void 0 ? [] : e.split(".");
762
+ }
763
+ function A(e) {
764
+ return typeof e == "object" && !!e && !Array.isArray(e);
765
+ }
766
+ function st(e, t) {
767
+ let n = k(t), r = e;
768
+ for (let e of n) {
769
+ if (!A(r)) return;
770
+ r = r[e];
771
+ }
772
+ return r;
773
+ }
774
+ function ct(e, t) {
775
+ let n = k(t);
776
+ if (n.length === 0) return !0;
777
+ let r = e;
778
+ for (let e = 0; e < n.length - 1; e++) {
779
+ if (!A(r)) return !1;
780
+ r = r[n[e]];
781
+ }
782
+ return A(r) ? n[n.length - 1] in r : !1;
783
+ }
784
+ function lt(e, t, n) {
785
+ let r = k(t);
786
+ if (r.length === 0) throw Error("setAtPath: jsonPath must be non-empty");
787
+ let i = e;
788
+ for (let e = 0; e < r.length - 1; e++) {
789
+ let t = r[e], n = i[t];
790
+ if (n === void 0) {
791
+ let e = {};
792
+ i[t] = e, i = e;
793
+ } else if (A(n)) i = n;
794
+ else throw Error(`setAtPath: cannot descend into non-object at '${r.slice(0, e + 1).join(".")}'`);
795
+ }
796
+ i[r[r.length - 1]] = n;
797
+ }
798
+ function ut(e, t) {
799
+ let n = k(t);
800
+ if (n.length === 0) throw Error("deleteAtPath: jsonPath must be non-empty");
801
+ let r = e;
802
+ for (let e = 0; e < n.length - 1; e++) {
803
+ if (!A(r)) return;
804
+ r = r[n[e]];
805
+ }
806
+ A(r) && delete r[n[n.length - 1]];
807
+ }
808
+ function dt(e, t) {
809
+ let n = new Set(t), r = Object.keys(e), i = /* @__PURE__ */ new Map();
810
+ i.set("", []);
811
+ let a = "";
812
+ for (let e of r) n.has(e) ? (a = e, i.set(a, [])) : i.get(a).push(e);
813
+ let o = {};
814
+ for (let t of i.get("")) o[t] = e[t];
815
+ for (let n of t) if (n in e) {
816
+ o[n] = e[n];
817
+ for (let t of i.get(n) ?? []) o[t] = e[t];
818
+ }
819
+ return o;
820
+ }
821
+ //#endregion
822
+ //#region src/structure/engine/parsers/lines.ts
823
+ function ft(e) {
824
+ let t = e.split("\n");
825
+ return t.length > 0 && t[t.length - 1] === "" && t.pop(), t;
826
+ }
827
+ function pt(e) {
828
+ return e.join("\n") + "\n";
829
+ }
830
+ function mt(e) {
831
+ return e.replace(/(^|\s)#.*$/, "$1").trim();
832
+ }
833
+ function ht(e, t) {
834
+ let n = mt(e);
835
+ return n === "" ? !1 : n === t.trim();
836
+ }
837
+ function gt(e, t) {
838
+ for (let n of e) if (ht(n, t)) return !0;
839
+ return !1;
840
+ }
841
+ //#endregion
842
+ //#region src/structure/engine/content-rules.ts
843
+ function _t(e, t) {
844
+ return e === "sdk:" ? t ? "workspace:*" : "catalog:" : e;
845
+ }
846
+ var vt = [
847
+ "dependencies",
848
+ "devDependencies",
849
+ "peerDependencies",
850
+ "optionalDependencies"
851
+ ];
852
+ function yt(e, t) {
853
+ if (N(e)) for (let n of vt) {
854
+ let r = e[n];
855
+ if (N(r)) for (let e of Object.keys(r)) r[e] === "sdk:" && (r[e] = t ? "workspace:*" : "catalog:");
856
+ }
857
+ }
858
+ var j;
859
+ function bt(e) {
860
+ if (!j) throw Error(`${e}() only valid inside a managed(...) body. Move this call inside managed(path, initial, () => {...}).`);
861
+ return j;
862
+ }
863
+ function M(e) {
864
+ let t = bt(e);
865
+ if (t.kind !== "json") throw Error(`${e}() requires a JSON-managed body; got '${t.kind}'.`);
866
+ return t;
867
+ }
868
+ function xt(e) {
869
+ let t = bt(e);
870
+ if (t.kind !== "yaml") throw Error(`${e}() requires a YAML-managed body; got '${t.kind}'.`);
871
+ return t;
872
+ }
873
+ function St(e) {
874
+ let t = bt(e);
875
+ if (t.kind !== "lines") throw Error(`${e}() requires a lines-managed body; got '${t.kind}'.`);
876
+ return t;
877
+ }
878
+ function Ct(e, t) {
879
+ let n = e.ctx ?? He();
880
+ if (!n) throw Error(`${t}() needs a RunContext but none is active. Pass { ctx } via the with-managed-* helper or run inside engine.run(...).`);
881
+ return n;
882
+ }
883
+ function N(e) {
884
+ return typeof e == "object" && !!e && !Array.isArray(e);
885
+ }
886
+ function wt(e, t, n = {}) {
887
+ if (j) throw Error("Nested managed(...) body — engine bug.");
888
+ j = {
889
+ kind: "json",
890
+ obj: e,
891
+ ctx: n.ctx,
892
+ triggerContext: n.triggerContext
893
+ };
894
+ try {
895
+ return t(), e;
896
+ } finally {
897
+ j = void 0;
898
+ }
899
+ }
900
+ function Tt(e, t, n = {}) {
901
+ if (j) throw Error("Nested managed(...) body — engine bug.");
902
+ j = {
903
+ kind: "yaml",
904
+ doc: e,
905
+ ctx: n.ctx,
906
+ triggerContext: n.triggerContext,
907
+ getLatestVersion: n.getLatestVersion
908
+ };
909
+ try {
910
+ return t(), e;
911
+ } finally {
912
+ j = void 0;
913
+ }
914
+ }
915
+ function Et(e, t, n = {}) {
916
+ if (j) throw Error("Nested managed(...) body — engine bug.");
917
+ j = {
918
+ kind: "lines",
919
+ lines: e,
920
+ ctx: n.ctx,
921
+ triggerContext: n.triggerContext
922
+ };
923
+ try {
924
+ return t(), e;
925
+ } finally {
926
+ j = void 0;
927
+ }
928
+ }
929
+ Ke((e, t) => {
930
+ if (!j) return !1;
931
+ let n = j.triggerContext;
932
+ if (!n) throw Error("when() inside a managed(...) body requires a triggerContext. The runner supplies it via the `triggerContext` opt to with-managed-*; ensure your test/test helper passes one.");
933
+ return e(n) && t(), !0;
934
+ });
935
+ function P(e, t) {
936
+ lt(M("ensureField").obj, e, t);
937
+ }
938
+ function F(e, t) {
939
+ let n = M("removeField").obj;
940
+ ct(n, e) && (t && !t(st(n, e)) || ut(n, e));
941
+ }
942
+ function I(e, t) {
943
+ P(`scripts.${e}`, t);
944
+ }
945
+ function Dt(e) {
946
+ F(`scripts.${e}`);
947
+ }
948
+ var Ot = [
949
+ "dependencies",
950
+ "devDependencies",
951
+ "peerDependencies",
952
+ "optionalDependencies"
953
+ ];
954
+ function L(e, t, n, r) {
955
+ let i = M(e), a = i.obj, o = n === "sdk:" ? _t(n, Ct(i, e).isSdkInternal) : n;
956
+ for (let e of Ot) {
957
+ if (e === r) continue;
958
+ let n = a[e];
959
+ N(n) && t in n && delete n[t];
960
+ }
961
+ let s = a[r], c = N(s) ? s : {};
962
+ c[t] = o, N(s) || (a[r] = c);
963
+ }
964
+ function R(e, t) {
965
+ L("ensureDep", e, t, "dependencies");
966
+ }
967
+ function z(e, t) {
968
+ L("ensureDevDep", e, t, "devDependencies");
969
+ }
970
+ function kt(e, t) {
971
+ L("ensurePeerDep", e, t, "peerDependencies");
972
+ }
973
+ function At(e) {
974
+ let t = M("removeDep").obj;
975
+ for (let n of Ot) {
976
+ let r = t[n];
977
+ N(r) && e in r && delete r[e];
978
+ }
979
+ }
980
+ function B(e) {
981
+ for (let [t, n] of Object.entries(e)) z(t, n);
982
+ }
983
+ function V(e) {
984
+ for (let [t, n] of Object.entries(e)) kt(t, n);
985
+ }
986
+ function jt(e, t, n) {
987
+ let r = Ct(M(e), e);
988
+ for (let i of r.modules) i.scope === t && L(e, i.name, "workspace:*", n);
989
+ }
990
+ function H(e) {
991
+ jt("ensureWorkspaceScopeDeps", e, "dependencies");
992
+ }
993
+ function Mt(e) {
994
+ let t = M("pruneKeysMatching").obj;
995
+ for (let n of Object.keys(t)) e(n, t[n]) && delete t[n];
996
+ }
997
+ function Nt(e, t) {
998
+ let n = dt(e, t);
999
+ for (let t of Object.keys(e)) delete e[t];
1000
+ for (let t of Object.keys(n)) e[t] = n[t];
1001
+ }
1002
+ function U(e) {
1003
+ Nt(M("enforceFieldOrder").obj, e);
1004
+ }
1005
+ function Pt(e, t) {
1006
+ let n = Object.keys(e).sort(), r = {};
1007
+ for (let t of n) r[t] = e[t];
1008
+ for (let t of Object.keys(e)) delete e[t];
1009
+ for (let i of n) e[i] = r[i], t && N(e[i]) && Pt(e[i], !0);
1010
+ }
1011
+ function W(e = "", t = {}) {
1012
+ let n = t.recursive ?? !1;
1013
+ if (e === "" && !n) return;
1014
+ let r = M("enforceAlphabeticalOrder").obj;
1015
+ if (e === "") {
1016
+ Pt(r, !0);
1017
+ return;
1018
+ }
1019
+ let i = st(r, e);
1020
+ N(i) && Pt(i, n);
1021
+ }
1022
+ function Ft() {
1023
+ let e = xt("ensureWorkspaceModulePaths"), t = Ct(e, "ensureWorkspaceModulePaths").modules.filter((e) => e.path !== "").map((e) => e.path).sort(), n = e.doc.toJSON()?.packages;
1024
+ Array.isArray(n) && n.length === t.length && n.every((e, n) => e === t[n]) || e.doc.setIn(["packages"], t);
1025
+ }
1026
+ function It(e, t) {
1027
+ let n = e.doc.getIn(["catalog", t]);
1028
+ return typeof n == "string" ? n : void 0;
1029
+ }
1030
+ function Lt(e, t) {
1031
+ let n = xt("ensureCatalogVersion");
1032
+ It(n, e) === void 0 && n.doc.setIn(["catalog", e], t);
1033
+ }
1034
+ function Rt(e) {
1035
+ let t = xt("ensureCatalogLatest");
1036
+ if (!t.getLatestVersion) return;
1037
+ let n = t.getLatestVersion(e);
1038
+ n !== void 0 && It(t, e) !== n && t.doc.setIn(["catalog", e], n);
1039
+ }
1040
+ function zt(e) {
1041
+ let t = St("ensureGitignoreEntries");
1042
+ for (let n of e) gt(t.lines, n) || t.lines.push(n);
1043
+ }
1044
+ //#endregion
1045
+ //#region src/structure/engine/parsers/yaml.ts
1046
+ function Bt(e) {
1047
+ return se(e);
1048
+ }
1049
+ function Vt(e) {
1050
+ return e.toString();
1051
+ }
1052
+ var G = ".structure";
1053
+ function Ht(e, t = 0) {
1054
+ if (e < t) throw new Ut(e, t);
1055
+ }
1056
+ var Ut = class extends Error {
1057
+ constructor(e, t) {
1058
+ super(`Block .structure version is ${e}, below floor ${t}. Bootstrap via the legacy-migration skill, then re-run.`), this.version = e, this.floor = t, this.name = "StructureVersionFloorError";
1059
+ }
1060
+ };
1061
+ function Wt(e, t = 1) {
1062
+ let n = { version: t };
1063
+ e.write(G, JSON.stringify(n));
1064
+ }
1065
+ //#endregion
1066
+ //#region src/structure/engine/runner.ts
1067
+ var Gt = class extends Error {
1068
+ constructor(e) {
1069
+ super(`Post-run recheck: rule set not idempotent. Failing item: ${e.primitive} '${e.path}' (scope=${e.scope}, action=${e.action}). Engine bug.`), this.failing = e, this.name = "RecheckError";
1070
+ }
1071
+ };
1072
+ function Kt(e, t, n, r) {
1073
+ switch (e.kind) {
1074
+ case "text": return e.value;
1075
+ case "file":
1076
+ if (!n) throw Error(`file('${e.path}'): no TemplateProvider configured. Pass opts.templates to engine.run(...).`);
1077
+ return n.staticRead(e.path);
1078
+ case "tpl":
1079
+ if (!n) throw Error(`tpl('${e.path}'): no TemplateProvider configured. Pass opts.templates to engine.run(...).`);
1080
+ return Ae(n.textRead(e.path), typeof e.vars == "function" ? e.vars() : e.vars);
1081
+ case "generate": {
1082
+ let n = e.fn();
1083
+ if (t.endsWith(".json")) return yt(n, r), ot(n, { collapse: !t.endsWith("package.json") });
1084
+ if (t.endsWith(".yaml") || t.endsWith(".yml")) return ce(n);
1085
+ if (typeof n != "string") throw Error(`generate() for '${t}' must return a string for non-JSON/YAML files; got ${typeof n}`);
1086
+ return n;
1087
+ }
1088
+ case "binary": throw Error(`binary('${e.path}') cannot be resolved to a string; it is only valid inside seed()/scaffold(), which copy it verbatim via fs.writeBinary.`);
1089
+ }
1090
+ }
1091
+ function qt(e, t, n, r, i) {
1092
+ if (n.kind === "binary") {
1093
+ if (!r) throw Error(`binary('${n.path}'): no TemplateProvider configured. Pass opts.templates to engine.run(...).`);
1094
+ e.writeBinary(t, r.staticReadBinary(n.path));
1095
+ return;
1096
+ }
1097
+ e.write(t, Kt(n, t, r, i));
1098
+ }
1099
+ function Jt(e, t, n, r, i) {
1100
+ let a = e.split("/").pop() ?? e;
1101
+ if (e.endsWith(".json")) {
1102
+ let i = et(t);
1103
+ if (typeof i != "object" || !i || Array.isArray(i)) throw Error(`managed: parsed value at '${e}' is not a JSON object`);
1104
+ return wt(i, n, { triggerContext: r }), ot(i, { collapse: a !== "package.json" });
1105
+ }
1106
+ if (e.endsWith(".yaml") || e.endsWith(".yml")) {
1107
+ let e = Bt(t);
1108
+ return Tt(e, n, {
1109
+ triggerContext: r,
1110
+ getLatestVersion: i
1111
+ }), Vt(e);
1112
+ }
1113
+ if (a === ".gitignore" || a.endsWith(".gitignore")) {
1114
+ let e = ft(t);
1115
+ return Et(e, n, { triggerContext: r }), pt(e);
1116
+ }
1117
+ throw Error(`managed('${e}'): unsupported file kind. Only .json, .yaml, .yml, .gitignore are dispatched.`);
1118
+ }
1119
+ function Yt(e) {
1120
+ let t = e.list(""), n = /* @__PURE__ */ new Set();
1121
+ for (let e of t) {
1122
+ n.add(e);
1123
+ let t = e.split("/");
1124
+ for (let e = 1; e < t.length; e++) n.add(t.slice(0, e).join("/"));
1125
+ }
1126
+ return n;
1127
+ }
1128
+ function Xt(e, t) {
1129
+ let n = t === "" ? t : t.endsWith("/") ? t.slice(0, -1) : t;
1130
+ return e.has(n);
1131
+ }
1132
+ function Zt(e, t, n) {
1133
+ return {
1134
+ ctx: t,
1135
+ version: t.version,
1136
+ pathExists: (t) => Xt(e, t),
1137
+ pathMissing: (t) => !Xt(e, t),
1138
+ filesMatch: (t) => {
1139
+ let r = n ? `${n}/${t}` : t;
1140
+ for (let t of e) if (ze(r, t)) return !0;
1141
+ return !1;
1142
+ }
1143
+ };
1144
+ }
1145
+ function Qt(e, t) {
1146
+ for (let n of e.triggers) if (!n(t)) return !1;
1147
+ return !0;
1148
+ }
1149
+ function $t(e, t) {
1150
+ return t ? "init" : e.updateDepsOnly ? "updateDeps" : "default";
1151
+ }
1152
+ function en(e, t) {
1153
+ return e.filter((e) => e.modes.includes(t));
1154
+ }
1155
+ function tn(e, t, n, r, i, a) {
1156
+ let o = e.leaf;
1157
+ if (o.kind === "fixed") {
1158
+ let i = Kt(o.content, e.resolvedPath, r, a);
1159
+ return t.exists(e.resolvedPath) ? t.read(e.resolvedPath) === i ? void 0 : (n || t.write(e.resolvedPath, i), {
1160
+ scope: e.scope,
1161
+ path: e.resolvedPath,
1162
+ primitive: "fixed",
1163
+ action: "update"
1164
+ }) : (n || t.write(e.resolvedPath, i), {
1165
+ scope: e.scope,
1166
+ path: e.resolvedPath,
1167
+ primitive: "fixed",
1168
+ action: "create"
1169
+ });
1170
+ }
1171
+ if (o.kind === "scaffold") return t.exists(e.resolvedPath) ? void 0 : (n || qt(t, e.resolvedPath, o.initial, r, a), {
1172
+ scope: e.scope,
1173
+ path: e.resolvedPath,
1174
+ primitive: "scaffold",
1175
+ action: "create"
1176
+ });
1177
+ if (o.kind === "seed") return !i || t.exists(e.resolvedPath) ? void 0 : (n || qt(t, e.resolvedPath, o.initial, r, a), {
1178
+ scope: e.scope,
1179
+ path: e.resolvedPath,
1180
+ primitive: "seed",
1181
+ action: "create"
1182
+ });
1183
+ if (o.kind === "remove") return t.exists(e.resolvedPath) ? (n || t.delete(e.resolvedPath), {
1184
+ scope: e.scope,
1185
+ path: e.resolvedPath,
1186
+ primitive: "remove",
1187
+ action: "delete"
1188
+ }) : void 0;
1189
+ if (o.kind === "rename") {
1190
+ if (!t.exists(e.resolvedPath)) return;
1191
+ let r = e.resolvedTo;
1192
+ return t.exists(r) ? void 0 : (n || t.move(e.resolvedPath, r), {
1193
+ scope: e.scope,
1194
+ path: e.resolvedPath,
1195
+ primitive: "rename",
1196
+ action: "rename"
1197
+ });
1198
+ }
1199
+ }
1200
+ function nn(e, t, n, r, i, a, o) {
1201
+ if (e.leaf.kind !== "managed") return;
1202
+ let s = e.leaf, c = e.resolvedPath, ee = t.exists(c), l, u = !1;
1203
+ ee ? l = t.read(c) : (l = Kt(s.initial, c, i, o), u = !0);
1204
+ let d = Jt(c, l, s.body, r, a);
1205
+ if (u) return n || t.write(c, d), {
1206
+ scope: e.scope,
1207
+ path: c,
1208
+ primitive: "managed",
1209
+ action: "create"
1210
+ };
1211
+ if (d !== l) return n || t.write(c, d), {
1212
+ scope: e.scope,
1213
+ path: c,
1214
+ primitive: "managed",
1215
+ action: "update"
1216
+ };
1217
+ }
1218
+ function rn(e, t, n, r, i, a, o) {
1219
+ let s = en(e, $t(n, a)), c = [], ee = Yt(t);
1220
+ for (let e of s) {
1221
+ if (e.leaf.kind === "managed" || !Qt(e, Zt(ee, n, e.modulePath))) continue;
1222
+ let o = tn(e, t, r, i, a, n.isSdkInternal);
1223
+ o && c.push(o);
1224
+ }
1225
+ let l = Yt(t);
1226
+ for (let e of s) {
1227
+ if (e.leaf.kind !== "managed") continue;
1228
+ let a = Zt(l, n, e.modulePath);
1229
+ if (!Qt(e, a)) continue;
1230
+ let s = nn(e, t, r, a, i, o, n.isSdkInternal);
1231
+ s && c.push(s);
1232
+ }
1233
+ return c;
1234
+ }
1235
+ function an(e, t, n, r = {}) {
1236
+ return Ve(n, () => {
1237
+ let i = Pe(e, n), a = !!r.initMode, o = rn(i, t, n, n.dryRun, r.templates, a, r.registryLookup);
1238
+ if (!n.dryRun && !n.updateDepsOnly && !a) {
1239
+ Wt(t);
1240
+ let i = {
1241
+ ...r.rediscover ? r.rediscover(t) : n,
1242
+ dryRun: !0
1243
+ }, a = rn(Pe(e, i), t, i, !0, r.templates, !1, r.registryLookup).filter((e) => e.path !== G);
1244
+ if (a.length > 0) throw new Gt(a[0]);
1245
+ }
1246
+ return a && !n.dryRun && Wt(t), { changes: o };
1247
+ });
1248
+ }
1249
+ //#endregion
1250
+ //#region src/structure/engine/discovery.ts
1251
+ var on = [
1252
+ "root",
1253
+ "block",
1254
+ "model",
1255
+ "ui",
1256
+ "workflow",
1257
+ "test",
1258
+ "software"
1259
+ ], sn = class extends Error {
1260
+ constructor(e, t) {
1261
+ super(e), this.path = t, this.name = "DiscoveryError";
1262
+ }
1263
+ };
1264
+ function cn(e) {
1265
+ let t = /* @__PURE__ */ new Set();
1266
+ for (let n of [
1267
+ e.dependencies,
1268
+ e.devDependencies,
1269
+ e.peerDependencies,
1270
+ e.optionalDependencies
1271
+ ]) if (n) for (let e of Object.keys(n)) t.add(e);
1272
+ return t;
1273
+ }
1274
+ function ln(e) {
1275
+ return e === "" || e === ".";
1276
+ }
1277
+ function un(e, t) {
1278
+ let n = e.pkg["block-scope"];
1279
+ if (typeof n == "string") {
1280
+ if (!on.includes(n)) throw new sn(`package.json "block-scope" must be one of ${on.join(", ")}, got '${n}'`, e.path);
1281
+ return n;
1282
+ }
1283
+ if (ln(e.path)) return "root";
1284
+ let r = cn(e.pkg);
1285
+ if (e.pkg["block-software"] !== void 0) return "software";
1286
+ if (r.has("@platforma-sdk/package-builder")) {
1287
+ for (let e of r) if (/^@platforma-open\/.*runenv/.test(e)) return "software";
1288
+ }
1289
+ if (r.has("@platforma-sdk/workflow-tengo")) return "workflow";
1290
+ if ((r.has("@platforma-sdk/ui-vue") || r.has("vue")) && !e.pkg.main) return "ui";
1291
+ if (r.has("@platforma-sdk/block-tools")) {
1292
+ if ([...r].filter((e) => t.has(e) && (e.endsWith(".model") || e.endsWith(".ui") || e.endsWith(".workflow"))).length >= 2) return "block";
1293
+ let n = e.pkg.files;
1294
+ if (Array.isArray(n) && n.length === 2 && n.includes("index.d.ts") && n.includes("index.js")) return "block";
1295
+ }
1296
+ if (r.has("@platforma-sdk/model") && e.pkg.main) return "model";
1297
+ if (r.has("@platforma-sdk/test")) return "test";
1298
+ }
1299
+ function dn(e) {
1300
+ let t = /* @__PURE__ */ new Set();
1301
+ for (let n of e) typeof n.pkg.name == "string" && t.add(n.pkg.name);
1302
+ let n = [];
1303
+ for (let r of e) {
1304
+ let e = un(r, t);
1305
+ if (!e) throw new sn(`Unclassified workspace package at '${r.path}'. Add a top-level "block-scope" string to its package.json.`, r.path);
1306
+ n.push({
1307
+ scope: e,
1308
+ name: r.pkg.name ?? r.path,
1309
+ path: ln(r.path) ? "" : r.path
1310
+ });
1311
+ }
1312
+ return n;
1313
+ }
1314
+ //#endregion
1315
+ //#region src/structure/engine/ctx.ts
1316
+ function K(e, t) {
1317
+ return e.modules.filter((e) => e.scope === t);
1318
+ }
1319
+ function fn(e, t) {
1320
+ let n = K(e, t);
1321
+ if (n.length === 0) throw Error(`findModule: expected one '${t}' module, found none`);
1322
+ if (n.length > 1) throw Error(`findModule: expected exactly one '${t}' module, found ${n.length}`);
1323
+ return n[0];
1324
+ }
1325
+ function q(e, t) {
1326
+ return { [fn(e, t).name]: "workspace:*" };
1327
+ }
1328
+ function pn(e, t) {
1329
+ let n = {};
1330
+ for (let r of K(e, t)) n[r.name] = "workspace:*";
1331
+ return n;
1332
+ }
1333
+ function mn(e) {
1334
+ let t = e.facadeName, n = [
1335
+ {
1336
+ scope: "root",
1337
+ name: t,
1338
+ path: ""
1339
+ },
1340
+ {
1341
+ scope: "block",
1342
+ name: `${t}.block`,
1343
+ path: "block"
1344
+ },
1345
+ {
1346
+ scope: "model",
1347
+ name: `${t}.model`,
1348
+ path: "model"
1349
+ },
1350
+ {
1351
+ scope: "ui",
1352
+ name: `${t}.ui`,
1353
+ path: "ui"
1354
+ },
1355
+ {
1356
+ scope: "workflow",
1357
+ name: `${t}.workflow`,
1358
+ path: "workflow"
1359
+ },
1360
+ {
1361
+ scope: "test",
1362
+ name: `${t}.test`,
1363
+ path: "test"
1364
+ }
1365
+ ];
1366
+ return e.softwarePlatform && n.push({
1367
+ scope: "software",
1368
+ name: `${t}.software`,
1369
+ path: "software"
1370
+ }), n;
1371
+ }
1372
+ function hn(e) {
1373
+ return {
1374
+ isSdkInternal: e.isSdkInternal ?? !1,
1375
+ updateDepsOnly: e.updateDepsOnly ?? !1,
1376
+ modules: e.modules,
1377
+ blockVars: e.blockVars,
1378
+ version: e.version ?? 0,
1379
+ dryRun: e.dryRun ?? !1
1380
+ };
1381
+ }
1382
+ //#endregion
1383
+ //#region src/structure/engine/discovery-fs.ts
1384
+ var J = class extends Error {
1385
+ constructor(e) {
1386
+ super(e), this.name = "StructureCliError";
1387
+ }
1388
+ };
1389
+ function gn(e, t) {
1390
+ return e === "" ? t : `${e}/${t}`;
1391
+ }
1392
+ function _n(e, t) {
1393
+ try {
1394
+ return JSON.parse(e.read(t));
1395
+ } catch {
1396
+ return;
1397
+ }
1398
+ }
1399
+ function vn(e) {
1400
+ if (e.includes("*")) throw new J(`pnpm-workspace.yaml 'packages:' entry '${e}' contains a glob. The structurer requires literal package paths — replace the glob with one entry per package directory.`);
1401
+ let t = e.replace(/^\.\//, "").replace(/\/$/, "");
1402
+ return t === "." ? "" : t;
1403
+ }
1404
+ function yn(e) {
1405
+ let t;
1406
+ try {
1407
+ t = e.read("pnpm-workspace.yaml");
1408
+ } catch {
1409
+ throw new J("No pnpm-workspace.yaml found. This directory is empty or unrecognisable as a block — run 'block-tools structure init' instead, or pass --sdk-internal for an in-monorepo block.");
1410
+ }
1411
+ let n = oe(t) ?? {}, r = Array.isArray(n.packages) ? n.packages : [], i = new Set([""]);
1412
+ for (let t of r) {
1413
+ let n = vn(t);
1414
+ (n === "" || e.exists(n)) && i.add(n);
1415
+ }
1416
+ let a = [];
1417
+ for (let t of i) {
1418
+ let n = _n(e, gn(t, "package.json"));
1419
+ n && a.push({
1420
+ path: t,
1421
+ pkg: n
1422
+ });
1423
+ }
1424
+ return a;
1425
+ }
1426
+ function bn(e) {
1427
+ let t = [], n = new Set([
1428
+ "node_modules",
1429
+ ".turbo",
1430
+ "dist",
1431
+ ".git",
1432
+ "block-pack"
1433
+ ]);
1434
+ function r(i, a) {
1435
+ let o = e.listDir(i);
1436
+ for (let s of o) {
1437
+ if (!s.isDirectory || n.has(s.name)) continue;
1438
+ let o = gn(i, s.name), c = _n(e, gn(o, "package.json"));
1439
+ c && t.push({
1440
+ path: o,
1441
+ pkg: c
1442
+ }), a < 2 && r(o, a + 1);
1443
+ }
1444
+ }
1445
+ return r("", 1), t;
1446
+ }
1447
+ function xn(e) {
1448
+ let t = e.indexOf("/");
1449
+ if (!e.startsWith("@") || t < 0) throw new J(`Cannot parse block name '${e}': expected '@npm-org/org-scope.short-name'.`);
1450
+ let n = e.slice(0, t), r = e.slice(t + 1), i = r.indexOf(".");
1451
+ if (i < 0) throw new J(`Cannot parse block name '${e}': base name '${r}' has no '.' separating org-scope from short-name.`);
1452
+ return {
1453
+ facadeName: e,
1454
+ baseName: r,
1455
+ npmOrg: n,
1456
+ orgScope: r.slice(0, i),
1457
+ shortName: r.slice(i + 1)
1458
+ };
1459
+ }
1460
+ function Sn(e) {
1461
+ try {
1462
+ let t = JSON.parse(e.read(G));
1463
+ return typeof t.version == "number" ? t.version : 0;
1464
+ } catch {
1465
+ return 0;
1466
+ }
1467
+ }
1468
+ function Cn(e) {
1469
+ let { fs: t, isSdkInternal: n } = e, r = n ? bn(t) : yn(t);
1470
+ if (r.length === 0) throw new J("No workspace packages found. Run 'block-tools structure init' to scaffold a block.");
1471
+ let i = dn(r), a = Sn(t);
1472
+ Ht(a, 0);
1473
+ let o = i.find((e) => e.scope === "block") ?? i.find((e) => e.scope === "root");
1474
+ if (!o) throw new J("Could not find a 'block' (or root-as-block) package to derive BlockVars from.");
1475
+ let s = xn(o.name);
1476
+ return hn({
1477
+ isSdkInternal: n,
1478
+ updateDepsOnly: e.updateDepsOnly ?? !1,
1479
+ modules: i,
1480
+ blockVars: s,
1481
+ version: a,
1482
+ dryRun: e.dryRun ?? !1
1483
+ });
1484
+ }
1485
+ //#endregion
1486
+ //#region src/structure/rules/shared/key-order.ts
1487
+ var Y = [
1488
+ "name",
1489
+ "version",
1490
+ "private",
1491
+ "description",
1492
+ "keywords",
1493
+ "files",
1494
+ "type",
1495
+ "main",
1496
+ "module",
1497
+ "types",
1498
+ "exports",
1499
+ "scripts",
1500
+ "dependencies",
1501
+ "devDependencies",
1502
+ "peerDependencies",
1503
+ "optionalDependencies",
1504
+ "packageManager",
1505
+ "pnpm",
1506
+ "block",
1507
+ "block-software"
1508
+ ];
1509
+ //#endregion
1510
+ //#region src/structure/rules/root-package-json.ts
1511
+ function wn(e) {
1512
+ return {
1513
+ version: "1.0.0",
1514
+ private: !0,
1515
+ scripts: {
1516
+ fmt: "turbo run fmt",
1517
+ check: "turbo run check",
1518
+ build: "turbo run build",
1519
+ "build:dev": "env PL_PKG_DEV=local turbo run build",
1520
+ test: "env PL_PKG_DEV=local turbo run test --concurrency 1",
1521
+ "test:dry-run": "env PL_PKG_DEV=local turbo run test --dry-run=json",
1522
+ "mark-stable": "turbo run mark-stable",
1523
+ "do-pack": "turbo run do-pack",
1524
+ watch: "turbo watch build",
1525
+ changeset: "changeset",
1526
+ "version-packages": "changeset version",
1527
+ "update-sdk": "block-tools structure refresh --update-deps-only",
1528
+ update: "block-tools structure refresh --update-deps-only && pnpm i && block-tools structure refresh && pnpm fmt"
1529
+ },
1530
+ peerDependencies: {
1531
+ oxlint: "*",
1532
+ oxfmt: "*"
1533
+ },
1534
+ devDependencies: {
1535
+ "@changesets/cli": "catalog:",
1536
+ "@milaboratories/ts-builder": "sdk:",
1537
+ "@platforma-sdk/block-tools": "sdk:",
1538
+ shx: "catalog:",
1539
+ turbo: "catalog:"
1540
+ },
1541
+ packageManager: "pnpm@9.12.0"
1542
+ };
1543
+ }
1544
+ function Tn() {
1545
+ P("packageManager", "pnpm@9.12.0"), F("name"), I("fmt", "turbo run fmt"), I("check", "turbo run check"), I("build", "turbo run build"), I("build:dev", "env PL_PKG_DEV=local turbo run build"), I("test", "env PL_PKG_DEV=local turbo run test --concurrency 1"), I("test:dry-run", "env PL_PKG_DEV=local turbo run test --dry-run=json"), I("mark-stable", "turbo run mark-stable"), I("do-pack", "turbo run do-pack"), I("watch", "turbo watch build"), I("changeset", "changeset"), I("version-packages", "changeset version"), I("update-sdk", "block-tools structure refresh --update-deps-only"), I("update", "block-tools structure refresh --update-deps-only && pnpm i && block-tools structure refresh && pnpm fmt"), B({
1546
+ "@changesets/cli": "catalog:",
1547
+ "@milaboratories/ts-builder": "sdk:",
1548
+ "@platforma-sdk/block-tools": "sdk:",
1549
+ shx: "catalog:",
1550
+ turbo: "catalog:"
1551
+ }), V({
1552
+ oxlint: "*",
1553
+ oxfmt: "*"
1554
+ }), Mt((e, t) => {
1555
+ if (!/^(\/\/|--)/.test(e) || typeof t != "object" || !t) return !1;
1556
+ let n = t;
1557
+ return n.pnpm !== void 0 || n.overrides !== void 0;
1558
+ }), W("dependencies"), W("devDependencies"), W("peerDependencies"), W("optionalDependencies"), U([...Y]);
1559
+ }
1560
+ //#endregion
1561
+ //#region src/structure/engine/registry-client.ts
1562
+ var En = 2, Dn = 500, On = 3e4;
1563
+ function kn(e) {
1564
+ if (!e) return null;
1565
+ let t = Number(e);
1566
+ if (Number.isFinite(t) && t > 0) return t * 1e3;
1567
+ let n = Date.parse(e);
1568
+ return Number.isNaN(n) ? null : Math.max(0, n - Date.now());
1569
+ }
1570
+ async function An(e) {
1571
+ for (let t = 1;; t++) {
1572
+ let n;
1573
+ try {
1574
+ n = await fetch(e, { signal: AbortSignal.timeout(On) });
1575
+ } catch (e) {
1576
+ if (t > En) throw e;
1577
+ await le(Dn * 2 ** (t - 1) * (.8 + .4 * Math.random()));
1578
+ continue;
1579
+ }
1580
+ if (n.ok) return n;
1581
+ if (!(n.status === 429 || n.status >= 500) || t > En) throw Error(`registry returned HTTP ${n.status}`);
1582
+ let r = kn(n.headers.get("retry-after"));
1583
+ if (r != null) {
1584
+ await le(r);
1585
+ continue;
1586
+ }
1587
+ await le(Dn * 2 ** (t - 1) * (.8 + .4 * Math.random()));
1588
+ }
1589
+ }
1590
+ function jn() {
1591
+ return { async getLatestVersion(e) {
1592
+ let t = (await (await An(`https://registry.npmjs.org/-/package/${e}/dist-tags`)).json()).latest;
1593
+ if (!t) throw Error("no 'latest' dist-tag in registry response");
1594
+ return t;
1595
+ } };
1596
+ }
1597
+ async function Mn(e, t) {
1598
+ let n = await Promise.all(t.map(async (t) => [t, await e.getLatestVersion(t)]));
1599
+ return new Map(n);
1600
+ }
1601
+ function Nn(e) {
1602
+ return (t) => e.get(t);
1603
+ }
1604
+ var Pn = [/^@platforma-sdk\//, /^@milaboratories\//];
1605
+ function Fn(e) {
1606
+ return Pn.some((t) => t.test(e));
1607
+ }
1608
+ async function In(e, t = jn()) {
1609
+ return e.length === 0 ? () => void 0 : Nn(await Mn(t, e));
1610
+ }
1611
+ //#endregion
1612
+ //#region src/structure/rules/root-pnpm-workspace.ts
1613
+ var X = [
1614
+ "@platforma-sdk/model",
1615
+ "@platforma-sdk/ui-vue",
1616
+ "@platforma-sdk/workflow-tengo",
1617
+ "@platforma-sdk/test",
1618
+ "@platforma-sdk/block-tools",
1619
+ "@platforma-sdk/tengo-builder",
1620
+ "@platforma-sdk/package-builder",
1621
+ "@milaboratories/ts-builder",
1622
+ "@milaboratories/ts-configs"
1623
+ ], Ln = "0.0.0-init-must-fetch";
1624
+ for (let e of X) if (!Fn(e)) throw Error(`SDK_CATALOG_PACKAGES entry '${e}' matches no catalog bump pattern; its placeholder would never be resolved to npm latest on init. Add it to CATALOG_BUMP_PATTERNS or move it to the infra floor.`);
1625
+ var Rn = {
1626
+ turbo: "~2.8.11",
1627
+ shx: "~0.4.0",
1628
+ "@changesets/cli": "~2.29.8",
1629
+ vitest: "~4.0.18",
1630
+ vue: "3.5.24"
1631
+ }, zn = "@platforma-open/milaboratories.runenv-python-3", Bn = "1.8.2";
1632
+ function Vn(e) {
1633
+ let t = e.modules.filter((e) => e.path !== "").map((e) => e.path).sort(), n = {};
1634
+ for (let e of X) n[e] = Ln;
1635
+ return Object.assign(n, Rn), e.modules.some((e) => e.scope === "software") && (n[zn] = Bn), {
1636
+ packages: t,
1637
+ catalog: n
1638
+ };
1639
+ }
1640
+ function Hn() {
1641
+ Ft();
1642
+ }
1643
+ //#endregion
1644
+ //#region src/structure/rules/root-gitignore.ts
1645
+ var Un = [
1646
+ ".test_auth.json",
1647
+ "node_modules/",
1648
+ "dist/",
1649
+ "block-pack/",
1650
+ "dev/",
1651
+ "work/",
1652
+ "log/",
1653
+ ".turbo",
1654
+ "vite.config.*.timestamp-*",
1655
+ "software/**/*.tgz",
1656
+ ".DS_Store",
1657
+ ".vscode/sftp.json",
1658
+ "test-dry-run.json"
1659
+ ];
1660
+ function Wn() {
1661
+ zt(Un);
1662
+ }
1663
+ //#endregion
1664
+ //#region src/structure/rules/root.ts
1665
+ function Gn() {
1666
+ b("root", () => {
1667
+ x(({ ctx: e }) => !e.isSdkInternal, () => {
1668
+ C("turbo.json", D("root/turbo.json")), C(".vscode/settings.json", D("root/.vscode/settings.json")), w("package.json", O(() => wn(y())), () => {
1669
+ Tn();
1670
+ }), w("pnpm-workspace.yaml", O(() => Vn(y())), () => {
1671
+ Hn();
1672
+ }), w(".gitignore", D("root/.gitignore"), () => {
1673
+ Wn();
1674
+ });
1675
+ });
1676
+ });
1677
+ }
1678
+ //#endregion
1679
+ //#region src/structure/rules/block-package-json.ts
1680
+ function Kn(e) {
1681
+ let t = {};
1682
+ for (let n of K(e, "workflow")) t.workflow = `${n.name}/dist/tengo/tpl/main.plj.gz`;
1683
+ for (let n of K(e, "model")) t.model = `${n.name}/dist/model.json`;
1684
+ for (let n of K(e, "ui")) t.ui = `${n.name}/dist`;
1685
+ return t;
1686
+ }
1687
+ function qn(e) {
1688
+ if (Object.keys(e.components).length === 0) throw Error("block.components is empty — no workflow/model/ui module was discovered");
1689
+ let t = e.meta, n = [
1690
+ ["block.meta.title", t.title],
1691
+ ["block.meta.description", t.description],
1692
+ ["block.meta.logo", t.logo],
1693
+ ["block.meta.organization.name", t.organization?.name],
1694
+ ["block.meta.organization.url", t.organization?.url],
1695
+ ["block.meta.organization.logo", t.organization?.logo]
1696
+ ];
1697
+ for (let [e, t] of n) if (typeof t != "string" || t === "") throw Error(`required block field '${e}' is empty`);
1698
+ }
1699
+ function Jn(e) {
1700
+ let t = e.blockVars, n = {
1701
+ ...q(e, "model"),
1702
+ ...q(e, "ui"),
1703
+ ...q(e, "workflow")
1704
+ }, r = {
1705
+ components: Kn(e),
1706
+ meta: {
1707
+ title: t.shortName,
1708
+ description: `${t.shortName} block`,
1709
+ logo: "file:logos/block-logo.png",
1710
+ organization: {
1711
+ name: t.orgScope,
1712
+ url: "https://example.com",
1713
+ logo: "file:logos/organization-logo.png"
1714
+ }
1715
+ }
1716
+ };
1717
+ return qn(r), {
1718
+ name: `${t.facadeName}.block`,
1719
+ version: "1.0.0",
1720
+ files: ["index.d.ts", "index.js"],
1721
+ scripts: {
1722
+ build: "shx rm -rf ./block-pack && block-tools pack",
1723
+ "mark-stable": "block-tools mark-stable -r 's3://milab-euce1-prod-pkgs-s3-block-registry/pub/releases/?region=eu-central-1'",
1724
+ prepublishOnly: "block-tools pack && block-tools publish -r 's3://milab-euce1-prod-pkgs-s3-block-registry/pub/releases/?region=eu-central-1'",
1725
+ "do-pack": "shx rm -f *.tgz && block-tools pack && pnpm pack && shx mv *.tgz package.tgz"
1726
+ },
1727
+ dependencies: n,
1728
+ devDependencies: {
1729
+ "@platforma-sdk/block-tools": "sdk:",
1730
+ shx: "catalog:"
1731
+ },
1732
+ block: r
1733
+ };
1734
+ }
1735
+ function Yn() {
1736
+ P("files", ["index.d.ts", "index.js"]), I("build", "shx rm -rf ./block-pack && block-tools pack"), I("mark-stable", "block-tools mark-stable -r 's3://milab-euce1-prod-pkgs-s3-block-registry/pub/releases/?region=eu-central-1'"), I("prepublishOnly", "block-tools pack && block-tools publish -r 's3://milab-euce1-prod-pkgs-s3-block-registry/pub/releases/?region=eu-central-1'"), I("do-pack", "shx rm -f *.tgz && block-tools pack && pnpm pack && shx mv *.tgz package.tgz"), H("model"), H("ui"), H("workflow"), z("@platforma-sdk/block-tools", "sdk:"), z("shx", "catalog:"), P("block.components", Kn(y())), W("dependencies"), W("devDependencies"), W("peerDependencies"), W("optionalDependencies"), U([...Y]);
1737
+ }
1738
+ //#endregion
1739
+ //#region src/structure/rules/block.ts
1740
+ function Xn() {
1741
+ b("block", () => {
1742
+ C("index.js", D("block/index.js")), C("index.d.ts", D("block/index.d.ts")), T("logos/block-logo.png", Xe("block/logos/block-logo.png")), T("logos/organization-logo.png", Xe("block/logos/organization-logo.png")), w("package.json", O(() => Jn(y())), () => {
1743
+ Yn();
1744
+ });
1745
+ });
1746
+ }
1747
+ //#endregion
1748
+ //#region src/structure/rules/shared/colocated-tests.ts
1749
+ var Z = "src/**/*.test.ts";
1750
+ //#endregion
1751
+ //#region src/structure/rules/model-package-json.ts
1752
+ function Zn(e) {
1753
+ return {
1754
+ name: `${e.blockVars.facadeName}.model`,
1755
+ version: "1.0.0",
1756
+ type: "module",
1757
+ main: "dist/index.cjs",
1758
+ module: "dist/index.js",
1759
+ types: "dist/index.d.ts",
1760
+ exports: {
1761
+ ".": {
1762
+ types: "./dist/index.d.ts",
1763
+ sources: "./src/index.ts",
1764
+ import: "./dist/index.js"
1765
+ },
1766
+ "./dist/*": "./dist/*"
1767
+ },
1768
+ scripts: {
1769
+ fmt: "ts-builder format",
1770
+ watch: "ts-builder build --target block-model --watch",
1771
+ build: "ts-builder build --target block-model && block-tools build-model",
1772
+ check: "ts-builder check --target block-model"
1773
+ },
1774
+ dependencies: { "@platforma-sdk/model": "sdk:" },
1775
+ devDependencies: {
1776
+ "@milaboratories/ts-builder": "sdk:",
1777
+ "@milaboratories/ts-configs": "sdk:",
1778
+ "@platforma-sdk/block-tools": "sdk:",
1779
+ vitest: "catalog:"
1780
+ },
1781
+ peerDependencies: {
1782
+ "@types/node": "*",
1783
+ typescript: "*"
1784
+ }
1785
+ };
1786
+ }
1787
+ function Qn() {
1788
+ P("type", "module"), P("main", "dist/index.cjs"), P("module", "dist/index.js"), P("types", "dist/index.d.ts"), P("exports", {
1789
+ ".": {
1790
+ types: "./dist/index.d.ts",
1791
+ sources: "./src/index.ts",
1792
+ import: "./dist/index.js"
1793
+ },
1794
+ "./dist/*": "./dist/*"
1795
+ }), I("fmt", "ts-builder format"), I("watch", "ts-builder build --target block-model --watch"), I("build", "ts-builder build --target block-model && block-tools build-model"), I("check", "ts-builder check --target block-model"), R("@platforma-sdk/model", "sdk:"), B({
1796
+ "@milaboratories/ts-builder": "sdk:",
1797
+ "@milaboratories/ts-configs": "sdk:",
1798
+ "@platforma-sdk/block-tools": "sdk:",
1799
+ vitest: "catalog:"
1800
+ }), V({
1801
+ "@types/node": "*",
1802
+ typescript: "*"
1803
+ }), x(S(Z), () => {
1804
+ I("test", "vitest run --passWithNoTests"), z("@types/node", "*");
1805
+ }), W("dependencies"), W("devDependencies"), W("peerDependencies"), W("optionalDependencies"), U([...Y]);
1806
+ }
1807
+ //#endregion
1808
+ //#region src/structure/rules/model.ts
1809
+ function $n() {
1810
+ b("model", () => {
1811
+ w("tsconfig.json", D("model/tsconfig.json"), () => {
1812
+ P("extends", "@milaboratories/ts-configs/block/model"), F("compilerOptions"), x(S(Z), () => {
1813
+ P("compilerOptions.types", ["node"]);
1814
+ }), P("include", ["src/**/*"]), Mt((e) => e !== "extends" && e !== "include" && e !== "compilerOptions");
1815
+ }), C(".oxlintrc.json", D("model/.oxlintrc.json")), C(".oxfmtrc.json", D("model/.oxfmtrc.json")), T("src/index.ts", D("model/src/index.ts")), w("package.json", O(() => Zn(y())), () => {
1816
+ Qn();
1817
+ });
1818
+ });
1819
+ }
1820
+ //#endregion
1821
+ //#region src/structure/rules/ui-package-json.ts
1822
+ function er(e) {
1823
+ return {
1824
+ name: `${e.blockVars.facadeName}.ui`,
1825
+ version: "1.0.0",
1826
+ type: "module",
1827
+ scripts: {
1828
+ fmt: "ts-builder format",
1829
+ dev: "ts-builder serve --target block-ui",
1830
+ watch: "ts-builder build --target block-ui --watch",
1831
+ build: "ts-builder build --target block-ui",
1832
+ check: "ts-builder check --target block-ui"
1833
+ },
1834
+ dependencies: {
1835
+ "@platforma-sdk/ui-vue": "sdk:",
1836
+ vue: "catalog:",
1837
+ ...q(e, "model")
1838
+ },
1839
+ devDependencies: {
1840
+ "@milaboratories/ts-builder": "sdk:",
1841
+ "@milaboratories/ts-configs": "sdk:",
1842
+ vitest: "catalog:"
1843
+ },
1844
+ peerDependencies: { typescript: "*" }
1845
+ };
1846
+ }
1847
+ function tr() {
1848
+ P("type", "module"), I("fmt", "ts-builder format"), I("dev", "ts-builder serve --target block-ui"), I("watch", "ts-builder build --target block-ui --watch"), I("build", "ts-builder build --target block-ui"), I("check", "ts-builder check --target block-ui"), R("@platforma-sdk/ui-vue", "sdk:"), R("vue", "catalog:"), H("model"), B({
1849
+ "@milaboratories/ts-builder": "sdk:",
1850
+ "@milaboratories/ts-configs": "sdk:",
1851
+ vitest: "catalog:"
1852
+ }), V({ typescript: "*" }), At("@types/node"), x(S(Z), () => {
1853
+ I("test", "vitest run --passWithNoTests"), z("@types/node", "*");
1854
+ }), W("dependencies"), W("devDependencies"), W("peerDependencies"), W("optionalDependencies"), U([...Y]);
1855
+ }
1856
+ //#endregion
1857
+ //#region src/structure/rules/ui.ts
1858
+ function nr() {
1859
+ b("ui", () => {
1860
+ w("tsconfig.json", D("ui/tsconfig.json"), () => {
1861
+ P("extends", "@milaboratories/ts-configs/block/ui"), F("compilerOptions"), x(S(Z), () => {
1862
+ P("compilerOptions.types", ["node"]);
1863
+ }), P("include", ["src/**/*"]), Mt((e) => e !== "extends" && e !== "include" && e !== "compilerOptions");
1864
+ }), C(".oxlintrc.json", D("ui/.oxlintrc.json")), C(".oxfmtrc.json", D("ui/.oxfmtrc.json")), Ye("index.html", D("ui/index.html")), T("src/main.ts", D("ui/src/main.ts")), T("src/app.ts", Qe("ui/src/app.tpl.ts", () => ({ modelPkg: `${$e().facadeName}.model` }))), T("src/MainPage.vue", Qe("ui/src/MainPage.tpl.vue", () => ({ shortName: $e().shortName }))), w("package.json", O(() => er(y())), () => {
1865
+ tr();
1866
+ });
1867
+ });
1868
+ }
1869
+ //#endregion
1870
+ //#region src/structure/rules/workflow-package-json.ts
1871
+ function rr(e) {
1872
+ return {
1873
+ name: `${e.blockVars.facadeName}.workflow`,
1874
+ version: "1.0.0",
1875
+ type: "module",
1876
+ scripts: {
1877
+ build: "shx rm -rf dist && pl-tengo build",
1878
+ check: "pl-tengo check",
1879
+ format: "/usr/bin/env emacs --script ./format.el || echo 'No emacs.'"
1880
+ },
1881
+ dependencies: {
1882
+ "@platforma-sdk/workflow-tengo": "sdk:",
1883
+ ...pn(e, "software")
1884
+ },
1885
+ devDependencies: {
1886
+ "@platforma-sdk/tengo-builder": "sdk:",
1887
+ "@platforma-sdk/test": "sdk:",
1888
+ vitest: "catalog:",
1889
+ shx: "catalog:"
1890
+ }
1891
+ };
1892
+ }
1893
+ function ir() {
1894
+ P("type", "module"), I("build", "shx rm -rf dist && pl-tengo build"), I("check", "pl-tengo check"), I("format", "/usr/bin/env emacs --script ./format.el || echo 'No emacs.'"), x(S(Z), () => {
1895
+ I("test", "vitest run --passWithNoTests");
1896
+ }), R("@platforma-sdk/workflow-tengo", "sdk:"), H("software"), B({
1897
+ "@platforma-sdk/tengo-builder": "sdk:",
1898
+ "@platforma-sdk/test": "sdk:",
1899
+ vitest: "catalog:",
1900
+ shx: "catalog:"
1901
+ }), W("dependencies"), W("devDependencies"), W("peerDependencies"), W("optionalDependencies"), U([...Y]);
1902
+ }
1903
+ //#endregion
1904
+ //#region src/structure/rules/workflow.ts
1905
+ function ar() {
1906
+ b("workflow", () => {
1907
+ C("tsconfig.json", D("workflow/tsconfig.json")), C("format.el", D("workflow/format.el")), Ye("vitest.config.mts", D("workflow/vitest.config.mts")), E("index.js"), E("index.d.ts"), T("src/main.tpl.tengo", Qe("workflow/src/main.tpl.tengo", () => ({ shortName: $e().shortName }))), w("package.json", O(() => rr(y())), () => {
1908
+ ir();
1909
+ });
1910
+ });
1911
+ }
1912
+ //#endregion
1913
+ //#region src/structure/rules/test-package-json.ts
1914
+ function or(e) {
1915
+ return {
1916
+ name: `${e.blockVars.facadeName}.test`,
1917
+ version: "1.0.0",
1918
+ private: !0,
1919
+ type: "module",
1920
+ scripts: {
1921
+ check: "ts-builder type-check --target block-test",
1922
+ test: "vitest run --passWithNoTests"
1923
+ },
1924
+ peerDependencies: { typescript: "*" },
1925
+ devDependencies: {
1926
+ "@platforma-sdk/test": "sdk:",
1927
+ "@milaboratories/ts-builder": "sdk:",
1928
+ "@milaboratories/ts-configs": "sdk:",
1929
+ vitest: "catalog:"
1930
+ }
1931
+ };
1932
+ }
1933
+ function sr() {
1934
+ P("type", "module"), I("check", "ts-builder type-check --target block-test"), I("test", "vitest run --passWithNoTests"), B({
1935
+ "@platforma-sdk/test": "sdk:",
1936
+ "@milaboratories/ts-builder": "sdk:",
1937
+ "@milaboratories/ts-configs": "sdk:",
1938
+ vitest: "catalog:"
1939
+ }), V({ typescript: "*" }), At("@types/node"), W("dependencies"), W("devDependencies"), W("peerDependencies"), W("optionalDependencies"), U([...Y]);
1940
+ }
1941
+ //#endregion
1942
+ //#region src/structure/rules/test.ts
1943
+ function cr() {
1944
+ b("test", () => {
1945
+ C("tsconfig.json", D("test/tsconfig.json")), Ye("vitest.config.mts", D("test/vitest.config.mts")), T("src/demo.test.ts", Ze("import { expect, test } from \"vitest\";\n\ntest(\"scaffolded block sanity check\", () => {\n expect(true).toBe(true);\n});\n")), w("package.json", O(() => or(y())), () => {
1946
+ sr();
1947
+ });
1948
+ });
1949
+ }
1950
+ //#endregion
1951
+ //#region src/structure/rules/software-package-json.ts
1952
+ function lr() {
1953
+ return { entrypoints: { main: { binary: {
1954
+ artifact: {
1955
+ type: "python",
1956
+ registry: "platforma-open",
1957
+ environment: "@platforma-open/milaboratories.runenv-python-3:3.12.10",
1958
+ dependencies: {
1959
+ toolset: "pip",
1960
+ requirements: "requirements.txt"
1961
+ },
1962
+ root: "./src"
1963
+ },
1964
+ cmd: ["python", "{pkg}/main.py"]
1965
+ } } } };
1966
+ }
1967
+ function ur(e) {
1968
+ return {
1969
+ name: `${e.blockVars.facadeName}.software`,
1970
+ version: "1.0.0",
1971
+ type: "module",
1972
+ description: "Block Software",
1973
+ files: ["./dist/**/*"],
1974
+ scripts: {
1975
+ build: "pl-pkg build",
1976
+ prepublishOnly: "pl-pkg prepublish",
1977
+ changeset: "changeset",
1978
+ "version-packages": "changeset version"
1979
+ },
1980
+ "block-software": lr(),
1981
+ devDependencies: {
1982
+ "@platforma-open/milaboratories.runenv-python-3": "catalog:",
1983
+ "@platforma-sdk/package-builder": "sdk:"
1984
+ }
1985
+ };
1986
+ }
1987
+ function dr() {
1988
+ P("type", "module"), P("files", ["./dist/**/*"]), I("build", "pl-pkg build"), I("prepublishOnly", "pl-pkg prepublish"), I("changeset", "changeset"), I("version-packages", "changeset version"), B({
1989
+ "@platforma-open/milaboratories.runenv-python-3": "catalog:",
1990
+ "@platforma-sdk/package-builder": "sdk:"
1991
+ }), W("dependencies"), W("devDependencies"), W("peerDependencies"), W("optionalDependencies"), U([...Y]);
1992
+ }
1993
+ //#endregion
1994
+ //#region src/structure/rules/software.ts
1995
+ var fr = "import sys\n\nprint(\"Hello from Python, \" + sys.argv[1] + \"!\")\n", pr = "# No dependencies specified for this script\n";
1996
+ function mr() {
1997
+ b("software", () => {
1998
+ T("src/main.py", Ze(fr)), T("src/requirements.txt", Ze(pr)), w("package.json", O(() => ur(y())), () => {
1999
+ dr();
2000
+ });
2001
+ });
2002
+ }
2003
+ function hr() {
2004
+ b("model", () => {
2005
+ E("eslint.config.mjs"), E("vite.config.mts");
2006
+ }), b("ui", () => {
2007
+ E("eslint.config.mjs"), E("vite.config.ts"), E("tsconfig.app.json"), E("tsconfig.node.json");
2008
+ }), b("test", () => {
2009
+ E("eslint.config.mjs");
2010
+ }), b("root", () => {
2011
+ E(".prettierrc"), w("package.json", O(() => wn(y())), () => {
2012
+ Dt("pretty"), At("@platforma-sdk/blocks-deps-updater");
2013
+ });
2014
+ });
2015
+ }
2016
+ //#endregion
2017
+ //#region src/structure/rules/root-catalog-bump.ts
2018
+ function gr() {
2019
+ Je(() => {
2020
+ b("root", () => {
2021
+ x(({ ctx: e }) => !e.isSdkInternal, () => {
2022
+ w("pnpm-workspace.yaml", O(() => Vn(y())), () => {
2023
+ for (let e of X) Rt(e);
2024
+ for (let [e, t] of Object.entries(Rn)) Lt(e, t);
2025
+ y().modules.some((e) => e.scope === "software") && Lt(zn, Bn);
2026
+ });
2027
+ });
2028
+ });
2029
+ });
2030
+ }
2031
+ //#endregion
2032
+ //#region src/structure/structure-definition.ts
2033
+ var _r = Ue(() => {
2034
+ Gn(), Xn(), $n(), nr(), ar(), cr(), mr(), hr(), gr();
2035
+ });
2036
+ //#endregion
2037
+ //#region src/structure/cli/run-structure.ts
2038
+ async function vr() {
2039
+ return In(X.filter(Fn));
2040
+ }
2041
+ async function yr(e) {
2042
+ let t = p.resolve(e.blockPath), n = e.mode === "check", r = new Oe(t), i = new ke(e.templatesRoot), a = an(_r, r, Cn({
2043
+ fs: r,
2044
+ isSdkInternal: e.isSdkInternal,
2045
+ updateDepsOnly: e.updateDepsOnly,
2046
+ dryRun: n
2047
+ }), {
2048
+ templates: i,
2049
+ registryLookup: e.updateDepsOnly ? await vr() : void 0,
2050
+ rediscover: () => Cn({
2051
+ fs: r,
2052
+ isSdkInternal: e.isSdkInternal,
2053
+ updateDepsOnly: !1,
2054
+ dryRun: !0
2055
+ })
2056
+ });
2057
+ return {
2058
+ blockPath: e.blockPath,
2059
+ changes: a.changes
2060
+ };
2061
+ }
2062
+ function br(e, t) {
2063
+ if (t.length === 0) return ` ${e}: up to date (0 changes)`;
2064
+ let n = t.map((e) => ` ${e.action.padEnd(6)} ${e.primitive.padEnd(8)} ${e.path} [${e.scope}]`);
2065
+ return ` ${e}: ${t.length} change(s)\n${n.join("\n")}`;
2066
+ }
2067
+ //#endregion
2068
+ //#region src/cmd/structure/check.ts
2069
+ var xr = class e extends d {
2070
+ static description = "Check block(s) against the canonical structure (read-only). Exits non-zero if any diff would land — used as the CI gate.";
2071
+ static examples = ["<%= config.bin %> <%= command.id %> ./my-block", "<%= config.bin %> <%= command.id %> --sdk-internal etc/blocks/*"];
2072
+ static strict = !1;
2073
+ static flags = { "sdk-internal": f.boolean({ description: "block(s) live inside the SDK monorepo; skip root-scope rules" }) };
2074
+ async run() {
2075
+ let { argv: t, flags: n } = await this.parse(e), r = t.length > 0 ? t : ["."], i = p.join(this.config.root, "src", "structure", "templates"), a = !1;
2076
+ for (let e of r) {
2077
+ let t = await yr({
2078
+ blockPath: e,
2079
+ isSdkInternal: n["sdk-internal"],
2080
+ updateDepsOnly: !1,
2081
+ mode: "check",
2082
+ templatesRoot: i,
2083
+ log: (e) => this.log(e)
2084
+ });
2085
+ this.log(br(e, t.changes)), t.changes.length > 0 && (a = !0);
2086
+ }
2087
+ a && this.error("Structure check failed: one or more blocks are out of date. Run `structure refresh`.", { exit: 1 });
2088
+ }
2089
+ }, Q = ["python"], Sr = class extends Error {
2090
+ constructor(e) {
2091
+ super(`Missing required flag --${e} in --non-interactive mode. Supply every BlockVars flag, or drop --non-interactive to be prompted.`), this.name = "InitFlagError";
2092
+ }
2093
+ };
2094
+ async function $(e, t, n, r) {
2095
+ if (e !== void 0 && e !== "") return e;
2096
+ if (n) throw new Sr(t);
2097
+ return r();
2098
+ }
2099
+ async function Cr(e) {
2100
+ let t = await $(e.npmOrg, "npm-org", e.nonInteractive, () => de({
2101
+ message: "npm org (e.g. @platforma-open):",
2102
+ default: "@platforma-open"
2103
+ })), n = await $(e.orgScope, "org-scope", e.nonInteractive, () => de({ message: "org scope (e.g. my-org):" })), r = await $(e.shortName, "short-name", e.nonInteractive, () => de({ message: "block short name (e.g. mixcr-clonotyping):" })), i;
2104
+ i = e.withSoftware === void 0 ? e.nonInteractive ? !1 : await ue({
2105
+ message: "Include a software module?",
2106
+ default: !1
2107
+ }) : e.withSoftware;
2108
+ let a;
2109
+ if (i) {
2110
+ if (a = await $(e.platform, "platform", e.nonInteractive, () => fe({
2111
+ message: "Software platform:",
2112
+ choices: Q.map((e) => ({
2113
+ name: e,
2114
+ value: e
2115
+ }))
2116
+ })), !Q.includes(a)) throw Error(`Unsupported --platform '${a}'. Only ${Q.join(", ")} ${Q.length === 1 ? "is" : "are"} supported at v1.`);
2117
+ } else if (e.platform) throw Error("--platform was given but software is disabled (--no-software).");
2118
+ return {
2119
+ facadeName: `${t}/${n}.${r}`,
2120
+ baseName: `${n}.${r}`,
2121
+ npmOrg: t,
2122
+ orgScope: n,
2123
+ shortName: r,
2124
+ softwarePlatform: a
2125
+ };
2126
+ }
2127
+ async function wr(e) {
2128
+ let t = e.vars, n = mn(t), r = new Oe(e.blockPath), i = new ke(e.templatesRoot), a = hn({
2129
+ blockVars: t,
2130
+ modules: n,
2131
+ isSdkInternal: !1,
2132
+ version: 1,
2133
+ dryRun: !1
2134
+ }), o = X.filter(Fn), s;
2135
+ try {
2136
+ s = await In(o);
2137
+ } catch (e) {
2138
+ throw Error(`init requires network access to resolve SDK catalog versions from npm, but the registry lookup failed: ${e instanceof Error ? e.message : String(e)}`);
2139
+ }
2140
+ return an(_r, r, a, {
2141
+ templates: i,
2142
+ initMode: !0,
2143
+ registryLookup: s
2144
+ }), e.log(`Initialised block '${t.facadeName}'${t.softwarePlatform ? ` (software: ${t.softwarePlatform})` : " (no software)"} at ${e.blockPath}`), t;
2145
+ }
2146
+ //#endregion
2147
+ //#region src/cmd/index.ts
2148
+ var Tr = {
2149
+ "build-meta": pe,
2150
+ "build-model": he,
2151
+ "list-overview-snapshots": ge,
2152
+ "mark-stable": _e,
2153
+ pack: ve,
2154
+ publish: be,
2155
+ "refresh-registry": xe,
2156
+ "restore-overview-from-snapshot": Se,
2157
+ "update-deps": Ce,
2158
+ "upload-package-v1": De,
2159
+ "structure:check": xr,
2160
+ "structure:init": class e extends d {
2161
+ static description = "Scaffold a fresh Platforma block from the canonical structure. Missing flags are prompted unless --non-interactive.";
2162
+ static examples = ["<%= config.bin %> <%= command.id %> --npm-org @platforma-open --org-scope my-org --short-name demo --no-software --non-interactive", "<%= config.bin %> <%= command.id %> ./demo --npm-org @platforma-open --org-scope my-org --short-name demo --with-software --platform python --non-interactive"];
2163
+ static args = { path: u.string({ description: "target directory (default: <short-name> under the current directory)" }) };
315
2164
  static flags = {
316
- registry: f.string({
317
- char: "r",
318
- summary: "full address of the registry or alias from .pl.reg",
319
- helpValue: "<address|alias>",
320
- env: "PL_REGISTRY"
321
- }),
322
- organization: f.string({
323
- char: "o",
324
- summary: "target organisation",
325
- env: "PL_PACKAGE_ORGANIZATION"
326
- }),
327
- package: f.string({
328
- char: "p",
329
- summary: "target package",
330
- env: "PL_PACKAGE_NAME"
331
- }),
332
- version: f.string({
333
- char: "v",
334
- summary: "target version",
335
- env: "PL_PACKAGE_VERSION"
336
- }),
337
- meta: f.file({
338
- char: "m",
339
- summary: "json file containing meta information to associate with tha package",
340
- exists: !0
341
- }),
342
- file: N({
343
- char: "f",
344
- summary: "package files",
345
- multiple: !0,
346
- default: []
2165
+ "npm-org": f.string({ description: "npm org, e.g. @platforma-open" }),
2166
+ "org-scope": f.string({ description: "org scope, e.g. my-org" }),
2167
+ "short-name": f.string({ description: "block short name, e.g. mixcr-clonotyping" }),
2168
+ "with-software": f.boolean({ description: "include a software module" }),
2169
+ "no-software": f.boolean({ description: "omit the software module" }),
2170
+ platform: f.string({
2171
+ description: "software platform (single-valued)",
2172
+ options: [...Q]
347
2173
  }),
348
- refresh: f.boolean({
349
- summary: "refresh repository after adding the package",
350
- default: !0,
351
- allowNo: !0,
352
- env: "PL_REGISTRY_REFRESH"
353
- })
2174
+ "non-interactive": f.boolean({ description: "error on any missing flag instead of prompting" })
354
2175
  };
355
2176
  async run() {
356
- let { flags: t } = await this.parse(e), n = l.parse({});
357
- for (let e of P) t[e] && (n[e] = t[e]);
358
- t.meta && (t.meta.endsWith(".json") ? n.meta = JSON.parse(await m.promises.readFile(t.meta, { encoding: "utf-8" })) : t.meta.endsWith(".yaml") && (n.meta = b.parse(await m.promises.readFile(t.meta, { encoding: "utf-8" }))));
359
- for (let e of t.file) n.files[e.destName] = e.src;
360
- let r = await c(n);
361
- this.log(b.stringify(r.conf));
362
- let i = r.createRegistry(new y(this)), a = r.fullPackageName, o = i.constructNewPackage(a);
363
- for (let [e, t] of Object.entries(r.conf.files)) {
364
- this.log(`Uploading ${t} -> ${e} ...`);
365
- let n = await m.promises.readFile(t);
366
- await o.addFile(e, n);
367
- }
368
- this.log("Uploading meta information..."), await o.writeMeta(r.conf.meta), await o.finish(), t.refresh && await i.updateIfNeeded();
2177
+ let { args: t, flags: n } = await this.parse(e);
2178
+ n["with-software"] && n["no-software"] && this.error("--with-software and --no-software are mutually exclusive.");
2179
+ let r = n["with-software"] ? !0 : n["no-software"] ? !1 : void 0, i = await Cr({
2180
+ npmOrg: n["npm-org"],
2181
+ orgScope: n["org-scope"],
2182
+ shortName: n["short-name"],
2183
+ withSoftware: r,
2184
+ platform: n.platform,
2185
+ nonInteractive: n["non-interactive"]
2186
+ });
2187
+ await wr({
2188
+ vars: i,
2189
+ blockPath: t.path ? p.resolve(t.path) : p.resolve(process.cwd(), i.shortName),
2190
+ templatesRoot: p.join(this.config.root, "src", "structure", "templates"),
2191
+ log: (e) => this.log(e)
2192
+ });
369
2193
  }
370
2194
  },
371
- "update-deps": class extends d {
372
- static description = "Updates @platforma-sdk and @milaboratories packages in pnpm-workspace.yaml catalog to their latest versions from npm registry.";
373
- static examples = ["<%= config.bin %> <%= command.id %>"];
2195
+ "structure:refresh": class e extends d {
2196
+ static description = "Bring block(s) up to date with the canonical structure. Applies rules, writes files, bumps .structure version. Default mode is offline; --update-deps-only fires only catalog-bump rules (network).";
2197
+ static examples = [
2198
+ "<%= config.bin %> <%= command.id %> ./my-block",
2199
+ "<%= config.bin %> <%= command.id %> --sdk-internal etc/blocks/*",
2200
+ "<%= config.bin %> <%= command.id %> --update-deps-only"
2201
+ ];
2202
+ static strict = !1;
2203
+ static flags = {
2204
+ "sdk-internal": f.boolean({ description: "block(s) live inside the SDK monorepo; skip root-scope rules" }),
2205
+ "update-deps-only": f.boolean({ description: "fire ONLY catalog-bump rules (npm network). Follow with `pnpm install` then a plain refresh." })
2206
+ };
374
2207
  async run() {
375
- await x();
2208
+ let { argv: t, flags: n } = await this.parse(e), r = t.length > 0 ? t : ["."], i = p.join(this.config.root, "src", "structure", "templates");
2209
+ for (let e of r) {
2210
+ let t = await yr({
2211
+ blockPath: e,
2212
+ isSdkInternal: n["sdk-internal"],
2213
+ updateDepsOnly: n["update-deps-only"],
2214
+ mode: "refresh",
2215
+ templatesRoot: i,
2216
+ log: (e) => this.log(e)
2217
+ });
2218
+ this.log(br(e, t.changes));
2219
+ }
376
2220
  }
377
2221
  }
378
2222
  };
379
2223
  //#endregion
380
- export { F as COMMANDS };
2224
+ export { Tr as COMMANDS };
381
2225
 
382
2226
  //# sourceMappingURL=cli.mjs.map