@dotbep/core 0.2.16 → 0.2.18

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 (3) hide show
  1. package/dist/index.d.ts +19 -24
  2. package/dist/index.js +1037 -1030
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ const Ge = r.enum([
4
4
  "appointing-party",
5
5
  "lead-appointed-party",
6
6
  "appointed-party"
7
- ]), Xe = r.enum(["video", "document"]), Ve = r.enum(["zone", "location"]), He = r.enum(["LR", "TB"]), Ps = r.enum(["start", "end", "process", "decision", "automation"]), Ye = r.enum(["info", "warning", "blocking"]), Qe = r.enum([
7
+ ]), Xe = r.enum(["video", "document"]), Ve = r.enum(["zone", "location"]), He = r.enum(["LR", "TB"]), Ms = r.enum(["start", "end", "process", "decision", "automation"]), Ye = r.enum(["info", "warning", "blocking"]), Qe = r.enum([
8
8
  "roles",
9
9
  "members",
10
10
  "teams",
@@ -128,7 +128,7 @@ const Ge = r.enum([
128
128
  description: r.string().optional(),
129
129
  softwareIds: r.array(r.string()).optional().describe("ref Software.id[]"),
130
130
  guideIds: r.array(r.string()).optional().describe("ref Guide.id[]")
131
- }).describe("A human-performed activity referenced by workflow process nodes. Actions represent what a person in a given role does at a specific step."), C = r.object({
131
+ }).describe("A human-performed activity referenced by workflow process nodes. Actions represent what a person in a given role does at a specific step."), L = r.object({
132
132
  key: r.string().min(1),
133
133
  type: r.enum(["string", "number", "boolean"]),
134
134
  required: r.boolean(),
@@ -137,21 +137,21 @@ const Ge = r.enum([
137
137
  validation: r.object({ pattern: r.string().min(1), flags: r.string().optional() }).optional(),
138
138
  validationMessage: r.string().optional(),
139
139
  options: r.array(r.string().min(1)).optional()
140
- }), Se = r.object({
140
+ }), ke = r.object({
141
141
  id: r.string().min(1).describe('Human-readable slug, e.g. "status-changed".'),
142
142
  name: r.string().min(1),
143
- payload: r.array(C).optional()
144
- }).describe("A signal that advances a workflow instance from one node to the next. Carries a typed payload that moves the workflow instance forward and can be evaluated by decision guards."), Ne = r.object({
143
+ payload: r.array(L).optional()
144
+ }).describe("A signal that advances a workflow instance from one node to the next. Carries a typed payload that moves the workflow instance forward and can be evaluated by decision guards."), Se = r.object({
145
145
  id: r.string().min(1).describe('Human-readable slug, e.g. "notify".'),
146
146
  name: r.string().min(1),
147
147
  description: r.string().min(1).describe("Describe exactly what this effect must do so the runtime developer knows what to implement: what action it performs and what external system or service it calls."),
148
- payload: r.array(C).optional()
149
- }).describe("A fire-and-forget side effect triggered on a workflow edge. Executed by the runtime when the edge is traversed, using fields from the instance context as payload."), ke = r.object({
148
+ payload: r.array(L).optional()
149
+ }).describe("A fire-and-forget side effect triggered on a workflow edge. Executed by the runtime when the edge is traversed, using fields from the instance context as payload."), Ne = r.object({
150
150
  id: r.string().min(1).describe('Human-readable slug, e.g. "verify-tolerances".'),
151
151
  name: r.string().min(1),
152
152
  description: r.string().min(1).describe("Describe what this handler checks and what decision it produces: what condition or business rule it evaluates and where that data comes from."),
153
- payload: r.array(C).optional().describe("Fields consumed from instance context and passed to the handler."),
154
- output: r.array(C).describe("Fields the handler must return. Guards on outgoing edges reference these.")
153
+ payload: r.array(L).optional().describe("Fields consumed from instance context and passed to the handler."),
154
+ output: r.array(L).describe("Fields the handler must return. Guards on outgoing edges reference these.")
155
155
  }).describe("A system-executed node in a workflow. Runs a handler automatically, produces a typed output, and must be followed by a decision node that branches on that output."), it = r.object({
156
156
  hours: r.number().positive(),
157
157
  effectId: r.string().min(1).describe("ref FlowEffect.id")
@@ -227,10 +227,10 @@ const Ge = r.enum([
227
227
  nodes: r.record(r.string(), ft),
228
228
  edges: r.record(r.string(), gt)
229
229
  }).superRefine((n, e) => {
230
- const s = Object.entries(n.nodes), t = s.filter(([, a]) => a.type === "start").length, i = s.filter(([, a]) => a.type === "end").length;
231
- t !== 1 && e.addIssue({
230
+ const t = Object.entries(n.nodes), s = t.filter(([, a]) => a.type === "start").length, i = t.filter(([, a]) => a.type === "end").length;
231
+ s !== 1 && e.addIssue({
232
232
  code: "custom",
233
- message: `Diagram must have exactly one start node (found ${t}).`,
233
+ message: `Diagram must have exactly one start node (found ${s}).`,
234
234
  path: ["nodes"]
235
235
  }), i !== 1 && e.addIssue({
236
236
  code: "custom",
@@ -240,7 +240,7 @@ const Ge = r.enum([
240
240
  const o = {};
241
241
  for (const [a, d] of Object.entries(n.edges))
242
242
  o[d.from] ??= [], o[d.from].push({ edgeId: a, toKey: d.to });
243
- for (const [a, d] of s) {
243
+ for (const [a, d] of t) {
244
244
  const l = o[a] ?? [];
245
245
  d.type === "automation" && (l.length !== 1 ? e.addIssue({
246
246
  code: "custom",
@@ -259,12 +259,12 @@ const Ge = r.enum([
259
259
  for (const [a, d] of Object.entries(n.edges)) {
260
260
  const l = n.nodes[d.from];
261
261
  if (!l) continue;
262
- const c = "triggerEventId" in d, u = "guard" in d;
263
- l.type === "start" && (c || u) && e.addIssue({
262
+ const c = "triggerEventId" in d, f = "guard" in d;
263
+ l.type === "start" && (c || f) && e.addIssue({
264
264
  code: "custom",
265
265
  message: "Edges from start nodes cannot have a trigger or guard — instance creation is the implicit trigger.",
266
266
  path: ["edges", a]
267
- }), l.type === "decision" && !u && e.addIssue({
267
+ }), l.type === "decision" && !f && e.addIssue({
268
268
  code: "custom",
269
269
  message: "Edges from decision nodes must have a guard — all paths must be explicit.",
270
270
  path: ["edges", a, "guard"]
@@ -276,26 +276,26 @@ const Ge = r.enum([
276
276
  code: "custom",
277
277
  message: `Edges from ${l.type} nodes must have a trigger.`,
278
278
  path: ["edges", a, "triggerEventId"]
279
- }), (l.type === "process" || l.type === "automation") && u && e.addIssue({
279
+ }), (l.type === "process" || l.type === "automation") && f && e.addIssue({
280
280
  code: "custom",
281
281
  message: `Edges from ${l.type} nodes cannot have a guard — use a decision node to branch.`,
282
282
  path: ["edges", a, "guard"]
283
283
  });
284
284
  }
285
- }).describe("The visual and structural definition of a workflow."), Re = r.object({
285
+ }).describe("The visual and structural definition of a workflow."), $e = r.object({
286
286
  id: r.uuid(),
287
287
  name: r.string().min(1),
288
288
  description: r.string().optional(),
289
289
  example: r.string().optional().describe("Narrative example showcasing one cycle of this workflow."),
290
290
  trackedAssetTypeId: r.string().optional().describe("ref AssetType.id"),
291
291
  diagram: wt
292
- }).describe("A reusable process definition associated with one or more BIM uses. Describes the ordered steps, responsibilities, and transitions that govern how work is carried out."), Te = r.object({
292
+ }).describe("A reusable process definition associated with one or more BIM uses. Describes the ordered steps, responsibilities, and transitions that govern how work is carried out."), Re = r.object({
293
293
  id: r.uuid(),
294
294
  name: r.string().min(1),
295
295
  type: Xe,
296
296
  url: r.string().min(1),
297
297
  description: r.string().optional()
298
- }).describe("Supporting material attached to the BEP, such as a reference document or instructional video."), $e = r.object({
298
+ }).describe("Supporting material attached to the BEP, such as a reference document or instructional video."), Te = r.object({
299
299
  id: r.uuid(),
300
300
  name: r.string().min(1),
301
301
  description: r.string().optional().describe("Short guide description, not it's content"),
@@ -323,7 +323,7 @@ const Ge = r.enum([
323
323
  element: r.string().min(1),
324
324
  disciplineId: r.string(),
325
325
  milestones: r.array(yt).optional()
326
- }).describe("An information requirement for a model element. Declares what geometric detail and information properties are required for a specific model element and discipline across project milestones."), Me = r.object({
326
+ }).describe("An information requirement for a model element. Declares what geometric detail and information properties are required for a specific model element and discipline across project milestones."), xe = r.object({
327
327
  id: r.uuid(),
328
328
  message: r.string().min(1),
329
329
  memberEmail: r.email(),
@@ -335,7 +335,7 @@ const Ge = r.enum([
335
335
  severity: Ye,
336
336
  message: r.string().min(1),
337
337
  generatedAt: r.iso.datetime()
338
- }).describe("A diagnostic message attached to the BEP or one of its entities. Indicates an issue or observation with a severity level that guides the author."), Pe = vt.refine((n) => n.entity === null == (n.entityId === null), {
338
+ }).describe("A diagnostic message attached to the BEP or one of its entities. Indicates an issue or observation with a severity level that guides the author."), Me = vt.refine((n) => n.entity === null == (n.entityId === null), {
339
339
  message: "entity and entityId must both be null (BEP-level) or both be non-null (entity-level)."
340
340
  }), bt = r.object({
341
341
  id: r.uuid(),
@@ -350,25 +350,25 @@ const Ge = r.enum([
350
350
  predecessorId: r.string().optional(),
351
351
  url: r.url().optional(),
352
352
  resolverId: r.string().min(1).optional()
353
- }).describe("A formal output committed by a team at a milestone. Defines what must be delivered, in what format, by whom, and by when."), xe = bt.refine((n) => !n.predecessorId || n.predecessorId !== n.id, {
353
+ }).describe("A formal output committed by a team at a milestone. Defines what must be delivered, in what format, by whom, and by when."), Pe = bt.refine((n) => !n.predecessorId || n.predecessorId !== n.id, {
354
354
  message: "predecessorId cannot reference the deliverable itself.",
355
355
  path: ["predecessorId"]
356
356
  }), Fe = r.object({
357
357
  key: r.string().min(1),
358
358
  description: r.string().min(1).describe("Describe what this variable holds and which service it belongs to."),
359
359
  sensitive: r.boolean().optional()
360
- }).describe("A runtime configuration entry for handlers. Used to store credentials, endpoints, or other runtime settings without hardcoding them."), Ce = r.object({
360
+ }).describe("A runtime configuration entry for handlers. Used to store credentials, endpoints, or other runtime settings without hardcoding them."), Le = r.object({
361
361
  id: r.string().min(1).describe('Human-readable slug, e.g. "google-sheet"'),
362
362
  name: r.string().min(1),
363
363
  description: r.string().min(1).describe("Describe what external data this fetches, from where, and what format it returns: which service or API it calls, what credentials it needs, and the shape of the raw payload it returns."),
364
364
  envKeys: r.array(r.string().min(1)).describe("ref EnvVar.key[] — env vars required by this resolver handler.")
365
- }).describe("A server-side handler declared in the BEP bundle that authenticates against an external service, fetches data, and returns a raw payload for a live resource."), Le = r.object({
365
+ }).describe("A server-side handler declared in the BEP bundle that authenticates against an external service, fetches data, and returns a raw payload for a live resource."), Ce = r.object({
366
366
  id: r.uuid(),
367
367
  name: r.string().min(1),
368
368
  description: r.string().min(1).describe("Describe what this data source represents in the project context: what information it holds, how it is used in the BEP, and who or what system produces it."),
369
369
  url: r.url(),
370
370
  resolverId: r.string().min(1).optional().describe("ref Resolver.id")
371
- }).describe("A reference to an external data source that is fetched at runtime. The BEP does not store the data — it only declares where it lives and how to access it using a resolver."), xs = r.object({
371
+ }).describe("A reference to an external data source that is fetched at runtime. The BEP does not store the data — it only declares where it lives and how to access it using a resolver."), Ps = r.object({
372
372
  project: de,
373
373
  deliverableNamingConvention: ue.optional(),
374
374
  roles: r.array(le),
@@ -384,22 +384,22 @@ const Ge = r.enum([
384
384
  objectives: r.array(be),
385
385
  bimUses: r.array(Ie),
386
386
  actions: r.array(Ee),
387
- events: r.array(Se),
388
- effects: r.array(Ne),
389
- automations: r.array(ke),
387
+ events: r.array(ke),
388
+ effects: r.array(Se),
389
+ automations: r.array(Ne),
390
390
  env: r.array(Fe),
391
- resolvers: r.array(Ce),
392
- remoteData: r.array(Le),
393
- workflows: r.array(Re),
394
- guides: r.array($e),
395
- annexes: r.array(Te),
391
+ resolvers: r.array(Le),
392
+ remoteData: r.array(Ce),
393
+ workflows: r.array($e),
394
+ guides: r.array(Te),
395
+ annexes: r.array(Re),
396
396
  standards: r.array(Ae),
397
397
  lods: r.array(je),
398
398
  lois: r.array(Oe),
399
399
  loin: r.array(Be),
400
- deliverables: r.array(xe),
401
- notes: r.array(Me),
402
- flags: r.array(Pe)
400
+ deliverables: r.array(Pe),
401
+ notes: r.array(xe),
402
+ flags: r.array(Me)
403
403
  }), ne = r.object({
404
404
  version: r.string().regex(/^\d+\.\d+$/).describe('Format: "{major}.{minor}" (e.g. "1.0", "2.3").'),
405
405
  date: r.iso.datetime(),
@@ -416,36 +416,36 @@ const Ge = r.enum([
416
416
  current: r.string().regex(/^\d+\.\d+$/).describe('Current version in "{major}.{minor}" format.'),
417
417
  versions: r.array(It)
418
418
  });
419
- function $(n) {
419
+ function A(n) {
420
420
  return n.roles ??= [], n.members ??= [], n.teams ??= [], n.phases ??= [], n.milestones ??= [], n.lbs ??= [], n.disciplines ??= [], n.extensions ??= [], n.assetTypes ??= [], n.softwares ??= [], n.objectives ??= [], n.bimUses ??= [], n.actions ??= [], n.events ??= [], n.effects ??= [], n.workflows ??= [], n.guides ??= [], n.annexes ??= [], n.standards ??= [], n.lods ??= [], n.lois ??= [], n.loin ??= [], n.deliverables ??= [], n.notes ??= [], n.flags ??= [], n.env ??= [], n.automations ??= [], n.resolvers ??= [], n.remoteData ??= [], n;
421
421
  }
422
- const Et = "-", St = "^[A-Z0-9]{3}$";
423
- function Nt(n, e) {
422
+ const Et = "-", kt = "^[A-Z0-9]{3}$";
423
+ function St(n, e) {
424
424
  if (e) {
425
- const s = e.segments.find((t) => t.type === "field" && t.token === n);
426
- if (s?.type === "field" && s.pattern) return s.pattern;
425
+ const t = e.segments.find((s) => s.type === "field" && s.token === n);
426
+ if (t?.type === "field" && t.pattern) return t.pattern;
427
427
  }
428
- return St;
428
+ return kt;
429
429
  }
430
- function j(n, e, s) {
431
- const t = s?.delimiter ?? Et, i = Nt(n, s);
432
- return new RegExp(i).test(e) ? e.includes(t) ? `"${e}" contains the naming delimiter "${t}"` : null : `"${e}" does not match naming pattern ${i} for token "${n}"`;
430
+ function O(n, e, t) {
431
+ const s = t?.delimiter ?? Et, i = St(n, t);
432
+ return new RegExp(i).test(e) ? e.includes(s) ? `"${e}" contains the naming delimiter "${s}"` : null : `"${e}" does not match naming pattern ${i} for token "${n}"`;
433
433
  }
434
- function kt(n, e) {
435
- const s = [], t = (i, o) => {
436
- const a = j(i, o, e);
437
- a && s.push(a);
434
+ function Nt(n, e) {
435
+ const t = [], s = (i, o) => {
436
+ const a = O(i, o, e);
437
+ a && t.push(a);
438
438
  };
439
- t("project", n.project.code);
440
- for (const i of n.teams) t("team", i.id);
441
- for (const i of n.disciplines) t("discipline", i.id);
442
- for (const i of n.assetTypes) t("assetType", i.id);
443
- for (const i of n.lbs) t(i.type === "zone" ? "lbsZone" : "lbsLocation", i.id);
444
- return s;
439
+ s("project", n.project.code);
440
+ for (const i of n.teams) s("team", i.id);
441
+ for (const i of n.disciplines) s("discipline", i.id);
442
+ for (const i of n.assetTypes) s("assetType", i.id);
443
+ for (const i of n.lbs) s(i.type === "zone" ? "lbsZone" : "lbsLocation", i.id);
444
+ return t;
445
445
  }
446
446
  class _t {
447
- constructor(e, s, t, i, o) {
448
- this.getItem = e, this.setItem = s, this.schema = t, this.validate = i, this.getBep = o;
447
+ constructor(e, t, s, i, o) {
448
+ this.getItem = e, this.setItem = t, this.schema = s, this.validate = i, this.getBep = o;
449
449
  }
450
450
  getItem;
451
451
  setItem;
@@ -456,12 +456,12 @@ class _t {
456
456
  return this.getItem();
457
457
  }
458
458
  update(e) {
459
- const s = this.schema.parse({ ...this.getItem(), ...e });
459
+ const t = this.schema.parse({ ...this.getItem(), ...e });
460
460
  if (this.validate && this.getBep) {
461
- const t = this.validate(s, this.getBep());
462
- if (t.length) throw new Error(t.join("; "));
461
+ const s = this.validate(t, this.getBep());
462
+ if (s.length) throw new Error(s.join("; "));
463
463
  }
464
- return this.setItem(s), s;
464
+ return this.setItem(t), t;
465
465
  }
466
466
  }
467
467
  const De = [
@@ -504,29 +504,29 @@ const De = [
504
504
  // lbs (self-referential)
505
505
  { entity: "lbs", references: "lbs", inField: "lbsNodeIds", array: !0 }
506
506
  ];
507
- function Rt(n, e, s) {
508
- return De.filter((t) => t.references === e).flatMap((t) => s[t.entity].filter((o) => {
509
- const a = o[t.inField];
510
- return t.array ? Array.isArray(a) && a.includes(n) : a === n;
507
+ function $t(n, e, t) {
508
+ return De.filter((s) => s.references === e).flatMap((s) => t[s.entity].filter((o) => {
509
+ const a = o[s.inField];
510
+ return s.array ? Array.isArray(a) && a.includes(n) : a === n;
511
511
  }).map((o) => {
512
512
  const a = o.id ?? o.email ?? "?";
513
- return `${String(t.entity)}["${a}"].${String(t.inField)}`;
513
+ return `${String(s.entity)}["${a}"].${String(s.inField)}`;
514
514
  }));
515
515
  }
516
- function ie(n, e, s) {
517
- return De.filter((t) => t.entity === e).flatMap((t) => {
518
- const i = n[t.inField];
516
+ function ie(n, e, t) {
517
+ return De.filter((s) => s.entity === e).flatMap((s) => {
518
+ const i = n[s.inField];
519
519
  if (i == null || i === "") return [];
520
- const o = t.array ? i : [i], a = s[t.references];
521
- return o.filter((d) => !a.some((l) => (l.id ?? l.email) === d)).map((d) => `${String(t.references)}["${d}"] not found`);
520
+ const o = s.array ? i : [i], a = t[s.references];
521
+ return o.filter((d) => !a.some((l) => (l.id ?? l.email) === d)).map((d) => `${String(s.references)}["${d}"] not found`);
522
522
  });
523
523
  }
524
524
  function z(n) {
525
525
  return n instanceof We ? n.issues.map((e) => (e.path.length ? e.path.join(".") + ": " : "") + e.message).join("; ") : n.message;
526
526
  }
527
- class w {
528
- constructor(e, s, t) {
529
- this.getItems = e, this.getBep = s, this.config = t, this.idField = t.idField ?? "id";
527
+ class y {
528
+ constructor(e, t, s) {
529
+ this.getItems = e, this.getBep = t, this.config = s, this.idField = s.idField ?? "id";
530
530
  }
531
531
  getItems;
532
532
  getBep;
@@ -539,77 +539,77 @@ class w {
539
539
  return this.getItems();
540
540
  }
541
541
  get(e) {
542
- const s = [], t = [];
542
+ const t = [], s = [];
543
543
  for (const i of e) {
544
544
  const o = this.getItems().find((a) => this.getId(a) === i);
545
- o ? s.push(o) : t.push({ id: i, error: `Not found: ${i}` });
545
+ o ? t.push(o) : s.push({ id: i, error: `Not found: ${i}` });
546
546
  }
547
- return { succeeded: s, failed: t };
547
+ return { succeeded: t, failed: s };
548
548
  }
549
549
  add(e) {
550
- const s = [], t = [];
550
+ const t = [], s = [];
551
551
  for (const i of e) {
552
552
  const o = { ...i };
553
553
  this.config.autoId && !o[this.idField] && (o[this.idField] = globalThis.crypto.randomUUID());
554
554
  const a = String(o[this.idField] ?? "(unknown)");
555
555
  try {
556
556
  const d = this.config.schema.parse(o);
557
- if (this.getItems().some((u) => this.getId(u) === this.getId(d)))
557
+ if (this.getItems().some((f) => this.getId(f) === this.getId(d)))
558
558
  throw new Error(`Already exists: ${this.getId(d)}`);
559
559
  const l = ie(d, this.config.key, this.getBep());
560
560
  if (l.length) throw new Error(l.join("; "));
561
561
  const c = this.config.validate?.(d, this.getBep()) ?? [];
562
562
  if (c.length) throw new Error(c.join("; "));
563
- this.getItems().push(d), s.push(d);
563
+ this.getItems().push(d), t.push(d);
564
564
  } catch (d) {
565
- t.push({ id: a, error: z(d) });
565
+ s.push({ id: a, error: z(d) });
566
566
  }
567
567
  }
568
- return { succeeded: s, failed: t };
568
+ return { succeeded: t, failed: s };
569
569
  }
570
570
  update(e) {
571
- const s = [], t = [];
571
+ const t = [], s = [];
572
572
  for (const i of e) {
573
573
  const o = String(i[this.idField]), a = this.getItems(), d = a.findIndex((c) => this.getId(c) === o);
574
574
  if (d === -1) {
575
- t.push({ id: o, error: `Not found: ${o}` });
575
+ s.push({ id: o, error: `Not found: ${o}` });
576
576
  continue;
577
577
  }
578
578
  const l = ie(i, this.config.key, this.getBep());
579
579
  if (l.length) {
580
- t.push({ id: o, error: l.join("; ") });
580
+ s.push({ id: o, error: l.join("; ") });
581
581
  continue;
582
582
  }
583
583
  try {
584
- const c = this.config.schema.parse({ ...a[d], ...i }), u = this.config.validate?.(c, this.getBep()) ?? [];
585
- if (u.length) throw new Error(u.join("; "));
586
- a[d] = c, s.push(a[d]);
584
+ const c = this.config.schema.parse({ ...a[d], ...i }), f = this.config.validate?.(c, this.getBep()) ?? [];
585
+ if (f.length) throw new Error(f.join("; "));
586
+ a[d] = c, t.push(a[d]);
587
587
  } catch (c) {
588
- t.push({ id: o, error: z(c) });
588
+ s.push({ id: o, error: z(c) });
589
589
  }
590
590
  }
591
- return { succeeded: s, failed: t };
591
+ return { succeeded: t, failed: s };
592
592
  }
593
593
  remove(e) {
594
- const s = [], t = [];
594
+ const t = [], s = [];
595
595
  for (const i of e) {
596
596
  const o = this.getItems(), a = o.findIndex((d) => this.getId(d) === i);
597
597
  if (a === -1) {
598
- t.push({ id: i, error: `Not found: ${i}` });
598
+ s.push({ id: i, error: `Not found: ${i}` });
599
599
  continue;
600
600
  }
601
601
  try {
602
- const d = Rt(i, this.config.key, this.getBep());
602
+ const d = $t(i, this.config.key, this.getBep());
603
603
  if (d.length) throw new Error(`Referenced by: ${d.join(", ")}`);
604
- this.config.beforeRemove?.(i, this.getBep()), o.splice(a, 1), s.push(i);
604
+ this.config.beforeRemove?.(i, this.getBep()), o.splice(a, 1), t.push(i);
605
605
  } catch (d) {
606
- t.push({ id: i, error: z(d) });
606
+ s.push({ id: i, error: z(d) });
607
607
  }
608
608
  }
609
- return { succeeded: s, failed: t };
609
+ return { succeeded: t, failed: s };
610
610
  }
611
611
  }
612
- class Tt extends w {
612
+ class Rt extends y {
613
613
  constructor(e) {
614
614
  super(
615
615
  () => e().actions,
@@ -618,44 +618,44 @@ class Tt extends w {
618
618
  key: "actions",
619
619
  schema: Ee,
620
620
  autoId: !0,
621
- beforeRemove: (s, t) => {
622
- for (const i of t.workflows)
621
+ beforeRemove: (t, s) => {
622
+ for (const i of s.workflows)
623
623
  for (const [o, a] of Object.entries(i.diagram.nodes))
624
- if (a.type === "process" && a.actionId === s)
624
+ if (a.type === "process" && a.actionId === t)
625
625
  throw new Error(`Referenced by: workflows["${i.id}"].diagram.nodes["${o}"].actionId`);
626
626
  }
627
627
  }
628
628
  );
629
629
  }
630
630
  }
631
- class $t extends w {
631
+ class Tt extends y {
632
632
  constructor(e) {
633
633
  super(
634
634
  () => e().annexes,
635
635
  e,
636
636
  {
637
637
  key: "annexes",
638
- schema: Te,
638
+ schema: Re,
639
639
  autoId: !0
640
640
  }
641
641
  );
642
642
  }
643
643
  }
644
- class At extends w {
644
+ class At extends y {
645
645
  constructor(e) {
646
646
  super(
647
647
  () => e().effects,
648
648
  e,
649
649
  {
650
650
  key: "effects",
651
- schema: Ne,
652
- beforeRemove: (s, t) => {
653
- for (const i of t.workflows) {
651
+ schema: Se,
652
+ beforeRemove: (t, s) => {
653
+ for (const i of s.workflows) {
654
654
  for (const [o, a] of Object.entries(i.diagram.nodes))
655
- if ((a.type === "process" || a.type === "automation") && a.timeouts?.some((d) => d.effectId === s))
655
+ if ((a.type === "process" || a.type === "automation") && a.timeouts?.some((d) => d.effectId === t))
656
656
  throw new Error(`Referenced by: workflows["${i.id}"].diagram.nodes["${o}"].timeouts[].effectId`);
657
657
  for (const [o, a] of Object.entries(i.diagram.edges))
658
- if (a.effectIds?.includes(s))
658
+ if (a.effectIds?.includes(t))
659
659
  throw new Error(`Referenced by: workflows["${i.id}"].diagram.edges["${o}"].effectIds`);
660
660
  }
661
661
  }
@@ -663,25 +663,25 @@ class At extends w {
663
663
  );
664
664
  }
665
665
  }
666
- class jt extends w {
666
+ class jt extends y {
667
667
  constructor(e) {
668
668
  super(
669
669
  () => e().automations,
670
670
  e,
671
671
  {
672
672
  key: "automations",
673
- schema: ke,
674
- beforeRemove: (s, t) => {
675
- for (const i of t.workflows)
673
+ schema: Ne,
674
+ beforeRemove: (t, s) => {
675
+ for (const i of s.workflows)
676
676
  for (const [o, a] of Object.entries(i.diagram.nodes))
677
- if (a.type === "automation" && a.automationId === s)
677
+ if (a.type === "automation" && a.automationId === t)
678
678
  throw new Error(`Referenced by: workflows["${i.id}"].diagram.nodes["${o}"].automationId`);
679
679
  }
680
680
  }
681
681
  );
682
682
  }
683
683
  }
684
- class Ot extends w {
684
+ class Ot extends y {
685
685
  constructor(e) {
686
686
  super(
687
687
  () => e().env,
@@ -694,69 +694,69 @@ class Ot extends w {
694
694
  );
695
695
  }
696
696
  }
697
- class Bt extends w {
697
+ class Bt extends y {
698
698
  constructor(e) {
699
699
  super(
700
700
  () => e().events,
701
701
  e,
702
702
  {
703
703
  key: "events",
704
- schema: Se,
705
- beforeRemove: (s, t) => {
706
- for (const i of t.workflows)
704
+ schema: ke,
705
+ beforeRemove: (t, s) => {
706
+ for (const i of s.workflows)
707
707
  for (const [o, a] of Object.entries(i.diagram.edges))
708
- if ("triggerEventId" in a && a.triggerEventId === s)
708
+ if ("triggerEventId" in a && a.triggerEventId === t)
709
709
  throw new Error(`Referenced by: workflows["${i.id}"].diagram.edges["${o}"].trigger`);
710
710
  }
711
711
  }
712
712
  );
713
713
  }
714
714
  }
715
- function x(n) {
715
+ function P(n) {
716
716
  const e = /* @__PURE__ */ new Map();
717
- for (const s of n)
718
- for (const t of s.lbsNodeIds ?? [])
719
- e.set(t, s.id);
717
+ for (const t of n)
718
+ for (const s of t.lbsNodeIds ?? [])
719
+ e.set(s, t.id);
720
720
  return e;
721
721
  }
722
722
  function Q(n) {
723
723
  const e = /* @__PURE__ */ new Set();
724
- for (const s of n)
725
- for (const t of s.lbsNodeIds ?? []) e.add(t);
726
- return new Set(n.map((s) => s.id).filter((s) => !e.has(s)));
724
+ for (const t of n)
725
+ for (const s of t.lbsNodeIds ?? []) e.add(s);
726
+ return new Set(n.map((t) => t.id).filter((t) => !e.has(t)));
727
727
  }
728
728
  function Ue(n, e) {
729
729
  if (!n) return { zoneCode: "XXX", locationCode: "XXX" };
730
- const s = new Map(e.map((d) => [d.id, d])), t = x(e), i = Q(e), o = s.get(n);
730
+ const t = new Map(e.map((d) => [d.id, d])), s = P(e), i = Q(e), o = t.get(n);
731
731
  if (!o) return { zoneCode: "XXX", locationCode: "XXX" };
732
732
  if (i.has(o.id)) return { zoneCode: "ZZZ", locationCode: "ZZZ" };
733
733
  if (o.type === "zone") return { zoneCode: o.id, locationCode: "ZZZ" };
734
- let a = t.get(o.id);
734
+ let a = s.get(o.id);
735
735
  for (; a; ) {
736
- const d = s.get(a);
736
+ const d = t.get(a);
737
737
  if (!d) break;
738
738
  if (d.type === "zone" && !i.has(d.id))
739
739
  return { zoneCode: d.id, locationCode: o.id };
740
- a = t.get(a);
740
+ a = s.get(a);
741
741
  }
742
742
  return { zoneCode: "ZZZ", locationCode: o.id };
743
743
  }
744
- function Mt(n) {
745
- const e = [], s = new Map(n.map((d) => [d.id, d])), t = Q(n);
746
- for (const d of t) {
747
- const l = s.get(d);
744
+ function xt(n) {
745
+ const e = [], t = new Map(n.map((d) => [d.id, d])), s = Q(n);
746
+ for (const d of s) {
747
+ const l = t.get(d);
748
748
  l && l.type !== "zone" && e.push(`Root node "${d}" must be of type "zone".`);
749
749
  }
750
750
  for (const d of n)
751
751
  if (d.type === "location")
752
752
  for (const l of d.lbsNodeIds ?? [])
753
- s.get(l)?.type === "zone" && e.push(`Node "${d.id}" (location) cannot have a zone child ("${l}").`);
753
+ t.get(l)?.type === "zone" && e.push(`Node "${d.id}" (location) cannot have a zone child ("${l}").`);
754
754
  const i = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
755
755
  function a(d) {
756
756
  if (o.has(d)) return !0;
757
757
  if (i.has(d)) return !1;
758
758
  i.add(d), o.add(d);
759
- for (const l of s.get(d)?.lbsNodeIds ?? [])
759
+ for (const l of t.get(d)?.lbsNodeIds ?? [])
760
760
  if (a(l))
761
761
  return e.push(`Cycle detected in LBS tree at node "${d}".`), !0;
762
762
  return o.delete(d), !1;
@@ -766,34 +766,34 @@ function Mt(n) {
766
766
  return e;
767
767
  }
768
768
  function K(n) {
769
- const e = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
770
- for (const t of n) {
771
- const i = (s.get(t.responsibleId) ?? 0) + 1;
772
- s.set(t.responsibleId, i), e.set(t.id, i);
769
+ const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
770
+ for (const s of n) {
771
+ const i = (t.get(s.responsibleId) ?? 0) + 1;
772
+ t.set(s.responsibleId, i), e.set(s.id, i);
773
773
  }
774
774
  return e;
775
775
  }
776
- const P = "XXX";
777
- function ze(n, e, s, t, i) {
778
- const { zoneCode: o, locationCode: a } = Ue(n.lbsNodeId, t);
776
+ const M = "XXX";
777
+ function ze(n, e, t, s, i) {
778
+ const { zoneCode: o, locationCode: a } = Ue(n.lbsNodeId, s);
779
779
  if (!i) {
780
- const l = String(s.get(n.id) ?? 0).padStart(3, "0");
780
+ const l = String(t.get(n.id) ?? 0).padStart(3, "0");
781
781
  return [e, n.responsibleId, o, a, n.assetTypeId, n.disciplineId, l].join("-");
782
782
  }
783
783
  return i.segments.map((l) => {
784
784
  if (l.type === "sequence") {
785
785
  const c = l.padding ?? 3;
786
- return String(s.get(n.id) ?? 0).padStart(c, "0");
786
+ return String(t.get(n.id) ?? 0).padStart(c, "0");
787
787
  }
788
788
  switch (l.token) {
789
789
  case "project":
790
- return e || P;
790
+ return e || M;
791
791
  case "team":
792
- return n.responsibleId || P;
792
+ return n.responsibleId || M;
793
793
  case "discipline":
794
- return n.disciplineId || P;
794
+ return n.disciplineId || M;
795
795
  case "assetType":
796
- return n.assetTypeId || P;
796
+ return n.assetTypeId || M;
797
797
  case "lbsZone":
798
798
  return o;
799
799
  case "lbsLocation":
@@ -801,14 +801,14 @@ function ze(n, e, s, t, i) {
801
801
  }
802
802
  }).join(i.delimiter);
803
803
  }
804
- function Ze(n, e, s, t) {
804
+ function Ze(n, e, t, s) {
805
805
  const i = K(n);
806
806
  return new Map(n.map((o) => [
807
807
  o.id,
808
- ze(o, e, i, s, t)
808
+ ze(o, e, i, t, s)
809
809
  ]));
810
810
  }
811
- class Pt {
811
+ class Mt {
812
812
  constructor(e) {
813
813
  this.getBep = e;
814
814
  }
@@ -822,10 +822,10 @@ class Pt {
822
822
  * Returns null if the deliverable id is not found.
823
823
  */
824
824
  getCode(e) {
825
- const s = this.getBep(), t = s.deliverables.find((o) => o.id === e);
826
- if (!t) return null;
827
- const i = K(s.deliverables);
828
- return ze(t, s.project.code, i, s.lbs, s.deliverableNamingConvention);
825
+ const t = this.getBep(), s = t.deliverables.find((o) => o.id === e);
826
+ if (!s) return null;
827
+ const i = K(t.deliverables);
828
+ return ze(s, t.project.code, i, t.lbs, t.deliverableNamingConvention);
829
829
  }
830
830
  /** Builds the complete map of deliverable.id → nomenclature code. */
831
831
  buildCodeMap() {
@@ -833,35 +833,35 @@ class Pt {
833
833
  return Ze(e.deliverables, e.project.code, e.lbs, e.deliverableNamingConvention);
834
834
  }
835
835
  }
836
- class xt extends w {
837
- constructor(e, s, t, i, o) {
836
+ class Pt extends y {
837
+ constructor(e, t, s, i, o) {
838
838
  super(
839
839
  () => e().deliverables,
840
840
  e,
841
841
  {
842
842
  key: "deliverables",
843
- schema: xe,
843
+ schema: Pe,
844
844
  autoId: !0
845
845
  }
846
- ), this.getTeams = s, this.getAssetTypes = t, this.getLBSNodes = i, this.getMilestones = o;
846
+ ), this.getTeams = t, this.getAssetTypes = s, this.getLBSNodes = i, this.getMilestones = o;
847
847
  }
848
848
  getTeams;
849
849
  getAssetTypes;
850
850
  getLBSNodes;
851
851
  getMilestones;
852
852
  listResolved() {
853
- const e = this.getBep(), s = Ze(e.deliverables, e.project.code, e.lbs), t = new Map(this.getTeams().listResolved().map((l) => [l.id, l])), i = new Map(this.getAssetTypes().listResolved().map((l) => [l.id, l])), o = new Map(this.getLBSNodes().listResolved().map((l) => [l.id, l])), a = new Map(this.getMilestones().listResolved().map((l) => [l.id, l])), d = /* @__PURE__ */ new Map();
853
+ const e = this.getBep(), t = Ze(e.deliverables, e.project.code, e.lbs), s = new Map(this.getTeams().listResolved().map((l) => [l.id, l])), i = new Map(this.getAssetTypes().listResolved().map((l) => [l.id, l])), o = new Map(this.getLBSNodes().listResolved().map((l) => [l.id, l])), a = new Map(this.getMilestones().listResolved().map((l) => [l.id, l])), d = /* @__PURE__ */ new Map();
854
854
  for (const l of e.deliverables) {
855
855
  const c = a.get(l.milestoneId) ?? null;
856
856
  d.set(l.id, {
857
857
  ...l,
858
- nomenclatureCode: s.get(l.id) ?? "",
858
+ nomenclatureCode: t.get(l.id) ?? "",
859
859
  effectiveDate: l.dueDate ?? c?.date ?? "",
860
860
  lbsNode: l.lbsNodeId ? o.get(l.lbsNodeId) ?? null : null,
861
- discipline: e.disciplines.find((u) => u.id === l.disciplineId) ?? null,
861
+ discipline: e.disciplines.find((f) => f.id === l.disciplineId) ?? null,
862
862
  assetType: i.get(l.assetTypeId) ?? null,
863
- extensions: (l.extensionIds ?? []).map((u) => e.extensions.find((f) => f.id === u)).filter(Boolean),
864
- responsible: t.get(l.responsibleId) ?? null,
863
+ extensions: (l.extensionIds ?? []).map((f) => e.extensions.find((u) => u.id === f)).filter(Boolean),
864
+ responsible: s.get(l.responsibleId) ?? null,
865
865
  milestone: c,
866
866
  predecessor: null
867
867
  });
@@ -874,42 +874,42 @@ class xt extends w {
874
874
  return [...d.values()];
875
875
  }
876
876
  }
877
- class Ft extends w {
877
+ class Ft extends y {
878
878
  constructor(e) {
879
879
  super(
880
880
  () => e().flags,
881
881
  e,
882
882
  {
883
883
  key: "flags",
884
- schema: Pe,
884
+ schema: Me,
885
885
  autoId: !0
886
886
  }
887
887
  );
888
888
  }
889
889
  }
890
- class Ct extends w {
891
- constructor(e, s) {
890
+ class Lt extends y {
891
+ constructor(e, t) {
892
892
  super(
893
893
  () => e().notes,
894
894
  e,
895
895
  {
896
896
  key: "notes",
897
- schema: Me,
897
+ schema: xe,
898
898
  autoId: !0
899
899
  }
900
- ), this.getMembers = s;
900
+ ), this.getMembers = t;
901
901
  }
902
902
  getMembers;
903
903
  listResolved() {
904
- const e = new Map(this.getMembers().listResolved().map((s) => [s.email, s]));
905
- return this.getBep().notes.map((s) => ({
906
- ...s,
907
- member: e.get(s.memberEmail) ?? null
904
+ const e = new Map(this.getMembers().listResolved().map((t) => [t.email, t]));
905
+ return this.getBep().notes.map((t) => ({
906
+ ...t,
907
+ member: e.get(t.memberEmail) ?? null
908
908
  }));
909
909
  }
910
910
  }
911
- class Lt extends w {
912
- constructor(e, s) {
911
+ class Ct extends y {
912
+ constructor(e, t) {
913
913
  super(
914
914
  () => e().bimUses,
915
915
  e,
@@ -917,34 +917,34 @@ class Lt extends w {
917
917
  key: "bimUses",
918
918
  schema: Ie,
919
919
  autoId: !0,
920
- validate: (t, i) => {
920
+ validate: (s, i) => {
921
921
  const o = [];
922
- for (const a of t.objectiveIds ?? [])
922
+ for (const a of s.objectiveIds ?? [])
923
923
  i.objectives.some((d) => d.id === a) || o.push(`objectives["${a}"] not found`);
924
- for (const a of t.milestoneIds ?? [])
924
+ for (const a of s.milestoneIds ?? [])
925
925
  i.milestones.some((d) => d.id === a) || o.push(`milestones["${a}"] not found`);
926
- for (const a of t.workflowIds ?? [])
926
+ for (const a of s.workflowIds ?? [])
927
927
  i.workflows.some((d) => d.id === a) || o.push(`workflows["${a}"] not found`);
928
928
  return o;
929
929
  }
930
930
  }
931
- ), this.getWorkflows = s;
931
+ ), this.getWorkflows = t;
932
932
  }
933
933
  getWorkflows;
934
934
  listResolved() {
935
- const e = this.getBep(), s = new Map(this.getWorkflows().listResolved().map((t) => [t.id, t]));
936
- return e.bimUses.map((t) => ({
937
- ...t,
938
- objectives: (t.objectiveIds ?? []).map((i) => e.objectives.find((o) => o.id === i)).filter(Boolean),
939
- milestones: (t.milestoneIds ?? []).map((i) => {
935
+ const e = this.getBep(), t = new Map(this.getWorkflows().listResolved().map((s) => [s.id, s]));
936
+ return e.bimUses.map((s) => ({
937
+ ...s,
938
+ objectives: (s.objectiveIds ?? []).map((i) => e.objectives.find((o) => o.id === i)).filter(Boolean),
939
+ milestones: (s.milestoneIds ?? []).map((i) => {
940
940
  const o = e.milestones.find((a) => a.id === i);
941
941
  return o ? { ...o, phase: e.phases.find((a) => a.id === o.phaseId) ?? null } : null;
942
942
  }).filter(Boolean),
943
- workflows: (t.workflowIds ?? []).map((i) => s.get(i)).filter(Boolean)
943
+ workflows: (s.workflowIds ?? []).map((i) => t.get(i)).filter(Boolean)
944
944
  }));
945
945
  }
946
946
  }
947
- class Dt extends w {
947
+ class Dt extends y {
948
948
  constructor(e) {
949
949
  super(
950
950
  () => e().disciplines,
@@ -952,35 +952,35 @@ class Dt extends w {
952
952
  {
953
953
  key: "disciplines",
954
954
  schema: ge,
955
- validate: (s, t) => {
956
- const i = j("discipline", s.id, t.deliverableNamingConvention);
955
+ validate: (t, s) => {
956
+ const i = O("discipline", t.id, s.deliverableNamingConvention);
957
957
  return i ? [i] : [];
958
958
  }
959
959
  }
960
960
  );
961
961
  }
962
962
  }
963
- class Ut extends w {
963
+ class Ut extends y {
964
964
  constructor(e) {
965
965
  super(
966
966
  () => e().guides,
967
967
  e,
968
968
  {
969
969
  key: "guides",
970
- schema: $e,
970
+ schema: Te,
971
971
  autoId: !0
972
972
  }
973
973
  );
974
974
  }
975
975
  listResolved() {
976
976
  const e = this.getBep();
977
- return e.guides.map((s) => ({
978
- ...s,
979
- annexes: (s.annexIds ?? []).map((t) => e.annexes.find((i) => i.id === t)).filter(Boolean)
977
+ return e.guides.map((t) => ({
978
+ ...t,
979
+ annexes: (t.annexIds ?? []).map((s) => e.annexes.find((i) => i.id === s)).filter(Boolean)
980
980
  }));
981
981
  }
982
982
  }
983
- class zt extends w {
983
+ class zt extends y {
984
984
  constructor(e) {
985
985
  super(
986
986
  () => e().lods,
@@ -988,15 +988,15 @@ class zt extends w {
988
988
  {
989
989
  key: "lods",
990
990
  schema: je,
991
- beforeRemove: (s, t) => {
992
- for (const i of t.loin)
993
- if (i.milestones?.find((a) => a.lodId === s)) throw new Error(`Referenced by: loin["${i.id}"].milestones[lodId=${s}]`);
991
+ beforeRemove: (t, s) => {
992
+ for (const i of s.loin)
993
+ if (i.milestones?.find((a) => a.lodId === t)) throw new Error(`Referenced by: loin["${i.id}"].milestones[lodId=${t}]`);
994
994
  }
995
995
  }
996
996
  );
997
997
  }
998
998
  }
999
- class Zt extends w {
999
+ class Zt extends y {
1000
1000
  constructor(e) {
1001
1001
  super(
1002
1002
  () => e().lois,
@@ -1004,15 +1004,15 @@ class Zt extends w {
1004
1004
  {
1005
1005
  key: "lois",
1006
1006
  schema: Oe,
1007
- beforeRemove: (s, t) => {
1008
- for (const i of t.loin)
1009
- if (i.milestones?.find((a) => a.loiId === s)) throw new Error(`Referenced by: loin["${i.id}"].milestones[loiId=${s}]`);
1007
+ beforeRemove: (t, s) => {
1008
+ for (const i of s.loin)
1009
+ if (i.milestones?.find((a) => a.loiId === t)) throw new Error(`Referenced by: loin["${i.id}"].milestones[loiId=${t}]`);
1010
1010
  }
1011
1011
  }
1012
1012
  );
1013
1013
  }
1014
1014
  }
1015
- class Jt extends w {
1015
+ class Jt extends y {
1016
1016
  constructor(e) {
1017
1017
  super(
1018
1018
  () => e().loin,
@@ -1021,102 +1021,102 @@ class Jt extends w {
1021
1021
  key: "loin",
1022
1022
  schema: Be,
1023
1023
  autoId: !0,
1024
- validate: (s, t) => {
1024
+ validate: (t, s) => {
1025
1025
  const i = [];
1026
- for (const o of s.milestones ?? [])
1027
- t.milestones.some((a) => a.id === o.milestoneId) || i.push(`milestones["${o.milestoneId}"] not found`), t.lods.some((a) => a.id === o.lodId) || i.push(`lods[${o.lodId}] not found`), t.lois.some((a) => a.id === o.loiId) || i.push(`lois[${o.loiId}] not found`);
1026
+ for (const o of t.milestones ?? [])
1027
+ s.milestones.some((a) => a.id === o.milestoneId) || i.push(`milestones["${o.milestoneId}"] not found`), s.lods.some((a) => a.id === o.lodId) || i.push(`lods[${o.lodId}] not found`), s.lois.some((a) => a.id === o.loiId) || i.push(`lois[${o.loiId}] not found`);
1028
1028
  return i;
1029
1029
  }
1030
1030
  }
1031
1031
  );
1032
1032
  }
1033
1033
  addMilestones(e) {
1034
- const s = [], t = [];
1034
+ const t = [], s = [];
1035
1035
  for (const i of e) {
1036
1036
  const o = this.getBep().loin.find((c) => c.id === i.loinId);
1037
1037
  if (!o) {
1038
- t.push({ loinId: i.loinId, error: `Not found: ${i.loinId}` });
1038
+ s.push({ loinId: i.loinId, error: `Not found: ${i.loinId}` });
1039
1039
  continue;
1040
1040
  }
1041
- const a = i.milestones.find((c) => (o.milestones ?? []).some((u) => u.milestoneId === c.milestoneId));
1041
+ const a = i.milestones.find((c) => (o.milestones ?? []).some((f) => f.milestoneId === c.milestoneId));
1042
1042
  if (a) {
1043
- t.push({ loinId: i.loinId, error: `Milestone "${a.milestoneId}" already exists. Use updateMilestones to modify it.` });
1043
+ s.push({ loinId: i.loinId, error: `Milestone "${a.milestoneId}" already exists. Use updateMilestones to modify it.` });
1044
1044
  continue;
1045
1045
  }
1046
1046
  const d = [...o.milestones ?? [], ...i.milestones], l = this.update([{ id: i.loinId, milestones: d }]);
1047
1047
  if (l.failed.length > 0) {
1048
- t.push({ loinId: i.loinId, error: l.failed[0].error });
1048
+ s.push({ loinId: i.loinId, error: l.failed[0].error });
1049
1049
  continue;
1050
1050
  }
1051
- s.push({ loinId: i.loinId, element: o.element, addedMilestones: i.milestones.map((c) => c.milestoneId) });
1051
+ t.push({ loinId: i.loinId, element: o.element, addedMilestones: i.milestones.map((c) => c.milestoneId) });
1052
1052
  }
1053
- return { succeeded: s, failed: t };
1053
+ return { succeeded: t, failed: s };
1054
1054
  }
1055
1055
  updateMilestones(e) {
1056
- const s = [], t = [];
1056
+ const t = [], s = [];
1057
1057
  for (const i of e) {
1058
- const o = this.getBep().loin.find((f) => f.id === i.loinId);
1058
+ const o = this.getBep().loin.find((u) => u.id === i.loinId);
1059
1059
  if (!o) {
1060
- t.push({ loinId: i.loinId, error: `Not found: ${i.loinId}` });
1060
+ s.push({ loinId: i.loinId, error: `Not found: ${i.loinId}` });
1061
1061
  continue;
1062
1062
  }
1063
- const a = i.milestones.find((f) => !(o.milestones ?? []).some((m) => m.milestoneId === f.milestoneId));
1063
+ const a = i.milestones.find((u) => !(o.milestones ?? []).some((m) => m.milestoneId === u.milestoneId));
1064
1064
  if (a) {
1065
- t.push({ loinId: i.loinId, error: `Milestone "${a.milestoneId}" not found. Use addMilestones to create it.` });
1065
+ s.push({ loinId: i.loinId, error: `Milestone "${a.milestoneId}" not found. Use addMilestones to create it.` });
1066
1066
  continue;
1067
1067
  }
1068
- const d = new Map(o.milestones.map((f) => [f.milestoneId, { lodId: f.lodId, loiId: f.loiId, idsPath: f.idsPath }])), l = (o.milestones ?? []).map((f) => {
1069
- const m = i.milestones.find((p) => p.milestoneId === f.milestoneId);
1070
- return m ? { ...f, ...m } : f;
1068
+ const d = new Map(o.milestones.map((u) => [u.milestoneId, { lodId: u.lodId, loiId: u.loiId, idsPath: u.idsPath }])), l = (o.milestones ?? []).map((u) => {
1069
+ const m = i.milestones.find((p) => p.milestoneId === u.milestoneId);
1070
+ return m ? { ...u, ...m } : u;
1071
1071
  }), c = this.update([{ id: i.loinId, milestones: l }]);
1072
1072
  if (c.failed.length > 0) {
1073
- t.push({ loinId: i.loinId, error: c.failed[0].error });
1073
+ s.push({ loinId: i.loinId, error: c.failed[0].error });
1074
1074
  continue;
1075
1075
  }
1076
- const u = this.getBep().loin.find((f) => f.id === i.loinId);
1077
- s.push({
1076
+ const f = this.getBep().loin.find((u) => u.id === i.loinId);
1077
+ t.push({
1078
1078
  loinId: i.loinId,
1079
1079
  element: o.element,
1080
- milestones: i.milestones.map((f) => {
1081
- const m = u.milestones.find((g) => g.milestoneId === f.milestoneId), p = d.get(f.milestoneId);
1082
- return { milestoneId: f.milestoneId, before: p, after: { lodId: m.lodId, loiId: m.loiId, idsPath: m.idsPath } };
1080
+ milestones: i.milestones.map((u) => {
1081
+ const m = f.milestones.find((w) => w.milestoneId === u.milestoneId), p = d.get(u.milestoneId);
1082
+ return { milestoneId: u.milestoneId, before: p, after: { lodId: m.lodId, loiId: m.loiId, idsPath: m.idsPath } };
1083
1083
  })
1084
1084
  });
1085
1085
  }
1086
- return { succeeded: s, failed: t };
1086
+ return { succeeded: t, failed: s };
1087
1087
  }
1088
1088
  removeMilestones(e) {
1089
- const s = [], t = [];
1089
+ const t = [], s = [];
1090
1090
  for (const i of e) {
1091
1091
  const o = this.getBep().loin.find((d) => d.id === i.loinId);
1092
1092
  if (!o) {
1093
- t.push({ loinId: i.loinId, error: `Not found: ${i.loinId}` });
1093
+ s.push({ loinId: i.loinId, error: `Not found: ${i.loinId}` });
1094
1094
  continue;
1095
1095
  }
1096
1096
  const a = i.milestoneIds.filter((d) => !(o.milestones ?? []).some((l) => l.milestoneId === d));
1097
1097
  if (a.length > 0) {
1098
- t.push({ loinId: i.loinId, error: `Milestones not found in this LOIN: ${a.join(", ")}` });
1098
+ s.push({ loinId: i.loinId, error: `Milestones not found in this LOIN: ${a.join(", ")}` });
1099
1099
  continue;
1100
1100
  }
1101
- o.milestones = (o.milestones ?? []).filter((d) => !i.milestoneIds.includes(d.milestoneId)), s.push({ loinId: i.loinId, element: o.element, removedMilestones: i.milestoneIds });
1101
+ o.milestones = (o.milestones ?? []).filter((d) => !i.milestoneIds.includes(d.milestoneId)), t.push({ loinId: i.loinId, element: o.element, removedMilestones: i.milestoneIds });
1102
1102
  }
1103
- return { succeeded: s, failed: t };
1103
+ return { succeeded: t, failed: s };
1104
1104
  }
1105
1105
  listResolved() {
1106
1106
  const e = this.getBep();
1107
- return e.loin.map((s) => ({
1108
- ...s,
1109
- discipline: e.disciplines.find((t) => t.id === s.disciplineId) ?? null,
1110
- milestones: (s.milestones ?? []).map((t) => ({
1111
- ...t,
1112
- milestone: e.milestones.find((i) => i.id === t.milestoneId) ?? null,
1113
- lod: e.lods.find((i) => i.id === t.lodId) ?? null,
1114
- loi: e.lois.find((i) => i.id === t.loiId) ?? null
1107
+ return e.loin.map((t) => ({
1108
+ ...t,
1109
+ discipline: e.disciplines.find((s) => s.id === t.disciplineId) ?? null,
1110
+ milestones: (t.milestones ?? []).map((s) => ({
1111
+ ...s,
1112
+ milestone: e.milestones.find((i) => i.id === s.milestoneId) ?? null,
1113
+ lod: e.lods.find((i) => i.id === s.lodId) ?? null,
1114
+ loi: e.lois.find((i) => i.id === s.loiId) ?? null
1115
1115
  }))
1116
1116
  }));
1117
1117
  }
1118
1118
  }
1119
- class Kt extends w {
1119
+ class Kt extends y {
1120
1120
  constructor(e) {
1121
1121
  super(
1122
1122
  () => e().assetTypes,
@@ -1124,8 +1124,8 @@ class Kt extends w {
1124
1124
  {
1125
1125
  key: "assetTypes",
1126
1126
  schema: ye,
1127
- validate: (s, t) => {
1128
- const i = j("assetType", s.id, t.deliverableNamingConvention);
1127
+ validate: (t, s) => {
1128
+ const i = O("assetType", t.id, s.deliverableNamingConvention);
1129
1129
  return i ? [i] : [];
1130
1130
  }
1131
1131
  }
@@ -1133,13 +1133,13 @@ class Kt extends w {
1133
1133
  }
1134
1134
  listResolved() {
1135
1135
  const e = this.getBep();
1136
- return e.assetTypes.map((s) => ({
1137
- ...s,
1138
- extensions: (s.extensionIds ?? []).map((t) => e.extensions.find((i) => i.id === t)).filter(Boolean)
1136
+ return e.assetTypes.map((t) => ({
1137
+ ...t,
1138
+ extensions: (t.extensionIds ?? []).map((s) => e.extensions.find((i) => i.id === s)).filter(Boolean)
1139
1139
  }));
1140
1140
  }
1141
1141
  }
1142
- class qt extends w {
1142
+ class qt extends y {
1143
1143
  constructor(e) {
1144
1144
  super(
1145
1145
  () => e().extensions,
@@ -1151,7 +1151,7 @@ class qt extends w {
1151
1151
  );
1152
1152
  }
1153
1153
  }
1154
- class Wt extends w {
1154
+ class Wt extends y {
1155
1155
  constructor(e) {
1156
1156
  super(
1157
1157
  () => e().roles,
@@ -1160,13 +1160,13 @@ class Wt extends w {
1160
1160
  key: "roles",
1161
1161
  schema: le,
1162
1162
  autoId: !0,
1163
- beforeRemove: (s, t) => {
1163
+ beforeRemove: (t, s) => {
1164
1164
  const i = ["responsibleRoleIds", "accountableRoleIds", "consultedRoleIds", "informedRoleIds"];
1165
- for (const o of t.workflows)
1165
+ for (const o of s.workflows)
1166
1166
  for (const [a, d] of Object.entries(o.diagram.nodes))
1167
1167
  if (d.type === "process") {
1168
1168
  for (const l of i)
1169
- if (d[l]?.includes(s))
1169
+ if (d[l]?.includes(t))
1170
1170
  throw new Error(`Referenced by: workflows["${o.id}"].diagram.nodes["${a}"].${l}`);
1171
1171
  }
1172
1172
  }
@@ -1174,7 +1174,7 @@ class Wt extends w {
1174
1174
  );
1175
1175
  }
1176
1176
  }
1177
- class Gt extends w {
1177
+ class Gt extends y {
1178
1178
  constructor(e) {
1179
1179
  super(
1180
1180
  () => e().lbs,
@@ -1182,12 +1182,12 @@ class Gt extends w {
1182
1182
  {
1183
1183
  key: "lbs",
1184
1184
  schema: he,
1185
- validate: (s, t) => {
1186
- const i = [], o = s.type === "zone" ? "lbsZone" : "lbsLocation", a = j(o, s.id, t.deliverableNamingConvention);
1187
- if (a && i.push(a), s.type === "location" && s.lbsNodeIds?.length) {
1188
- const d = new Map(t.lbs.map((l) => [l.id, l]));
1189
- for (const l of s.lbsNodeIds ?? [])
1190
- d.get(l)?.type === "zone" && i.push(`Node "${s.id}" (location) cannot have a zone child ("${l}").`);
1185
+ validate: (t, s) => {
1186
+ const i = [], o = t.type === "zone" ? "lbsZone" : "lbsLocation", a = O(o, t.id, s.deliverableNamingConvention);
1187
+ if (a && i.push(a), t.type === "location" && t.lbsNodeIds?.length) {
1188
+ const d = new Map(s.lbs.map((l) => [l.id, l]));
1189
+ for (const l of t.lbsNodeIds ?? [])
1190
+ d.get(l)?.type === "zone" && i.push(`Node "${t.id}" (location) cannot have a zone child ("${l}").`);
1191
1191
  }
1192
1192
  return i;
1193
1193
  }
@@ -1195,25 +1195,25 @@ class Gt extends w {
1195
1195
  );
1196
1196
  }
1197
1197
  listResolved() {
1198
- const e = this.getBep(), s = x(e.lbs), t = Q(e.lbs), i = new Map(e.lbs.map((o) => [o.id, o]));
1198
+ const e = this.getBep(), t = P(e.lbs), s = Q(e.lbs), i = new Map(e.lbs.map((o) => [o.id, o]));
1199
1199
  return e.lbs.map((o) => {
1200
- const a = s.get(o.id), d = a ? i.get(a) : void 0;
1200
+ const a = t.get(o.id), d = a ? i.get(a) : void 0;
1201
1201
  return {
1202
1202
  ...o,
1203
- isRoot: t.has(o.id),
1203
+ isRoot: s.has(o.id),
1204
1204
  parent: d ? { id: d.id, name: d.name, type: d.type } : null,
1205
1205
  children: (o.lbsNodeIds ?? []).map((l) => i.get(l)).filter(Boolean)
1206
1206
  };
1207
1207
  });
1208
1208
  }
1209
1209
  addNodes(e) {
1210
- const s = this.getBep(), t = [], i = [];
1210
+ const t = this.getBep(), s = [], i = [];
1211
1211
  for (const o of e) {
1212
1212
  if (!o.parentId && o.type !== "zone") {
1213
1213
  i.push({ input: o, error: 'Root nodes (no parentId) must be type "zone".' });
1214
1214
  continue;
1215
1215
  }
1216
- if (o.parentId && !s.lbs.find((f) => f.id === o.parentId)) {
1216
+ if (o.parentId && !t.lbs.find((u) => u.id === o.parentId)) {
1217
1217
  i.push({ input: o, error: `No LBS node found with ID "${o.parentId}".` });
1218
1218
  continue;
1219
1219
  }
@@ -1223,20 +1223,20 @@ class Gt extends w {
1223
1223
  continue;
1224
1224
  }
1225
1225
  let c;
1226
- a && (c = s.lbs.find((f) => f.id === a), c && (c.lbsNodeIds ??= [], c.lbsNodeIds.push(o.id)));
1227
- const u = this.validateTree();
1228
- if (u.length > 0) {
1229
- s.lbs.splice(s.lbs.findIndex((f) => f.id === o.id), 1), c?.lbsNodeIds && (c.lbsNodeIds = c.lbsNodeIds.filter((f) => f !== o.id)), i.push({ input: o, error: u.join("; ") });
1226
+ a && (c = t.lbs.find((u) => u.id === a), c && (c.lbsNodeIds ??= [], c.lbsNodeIds.push(o.id)));
1227
+ const f = this.validateTree();
1228
+ if (f.length > 0) {
1229
+ t.lbs.splice(t.lbs.findIndex((u) => u.id === o.id), 1), c?.lbsNodeIds && (c.lbsNodeIds = c.lbsNodeIds.filter((u) => u !== o.id)), i.push({ input: o, error: f.join("; ") });
1230
1230
  continue;
1231
1231
  }
1232
- t.push({ ...s.lbs.find((f) => f.id === o.id), parentId: a ?? null });
1232
+ s.push({ ...t.lbs.find((u) => u.id === o.id), parentId: a ?? null });
1233
1233
  }
1234
- return { succeeded: t, failed: i };
1234
+ return { succeeded: s, failed: i };
1235
1235
  }
1236
1236
  updateNodes(e) {
1237
- const s = this.getBep(), t = [], i = [];
1237
+ const t = this.getBep(), s = [], i = [];
1238
1238
  for (const o of e) {
1239
- if (o.parentId && !s.lbs.find((h) => h.id === o.parentId)) {
1239
+ if (o.parentId && !t.lbs.find((h) => h.id === o.parentId)) {
1240
1240
  i.push({ id: o.id, error: `No LBS node found with ID "${o.parentId}".` });
1241
1241
  continue;
1242
1242
  }
@@ -1244,37 +1244,37 @@ class Gt extends w {
1244
1244
  i.push({ id: o.id, error: "A node cannot be its own parent." });
1245
1245
  continue;
1246
1246
  }
1247
- const a = s.lbs.find((h) => h.id === o.id), d = x(s.lbs).get(o.id) ?? null, { parentId: l, ...c } = o, u = this.update([c]);
1248
- if (u.failed.length > 0) {
1249
- i.push({ id: o.id, error: u.failed[0].error });
1247
+ const a = t.lbs.find((h) => h.id === o.id), d = P(t.lbs).get(o.id) ?? null, { parentId: l, ...c } = o, f = this.update([c]);
1248
+ if (f.failed.length > 0) {
1249
+ i.push({ id: o.id, error: f.failed[0].error });
1250
1250
  continue;
1251
1251
  }
1252
- const f = { name: a.name, type: a.type, description: a.description, parentId: d }, m = s.lbs.find((h) => h.id === o.id);
1252
+ const u = { name: a.name, type: a.type, description: a.description, parentId: d }, m = t.lbs.find((h) => h.id === o.id);
1253
1253
  if (l !== void 0) {
1254
- for (const h of s.lbs)
1255
- h.lbsNodeIds?.includes(o.id) && (h.lbsNodeIds = h.lbsNodeIds.filter((y) => y !== o.id));
1254
+ for (const h of t.lbs)
1255
+ h.lbsNodeIds?.includes(o.id) && (h.lbsNodeIds = h.lbsNodeIds.filter((v) => v !== o.id));
1256
1256
  if (l) {
1257
- const h = s.lbs.find((y) => y.id === l);
1257
+ const h = t.lbs.find((v) => v.id === l);
1258
1258
  h.lbsNodeIds ??= [], h.lbsNodeIds.push(o.id);
1259
1259
  }
1260
1260
  }
1261
1261
  const p = this.validateTree();
1262
1262
  if (p.length > 0) {
1263
- if (m.name = f.name, m.type = f.type, f.description !== void 0 ? m.description = f.description : delete m.description, l !== void 0) {
1264
- for (const h of s.lbs)
1265
- h.lbsNodeIds?.includes(o.id) && (h.lbsNodeIds = h.lbsNodeIds.filter((y) => y !== o.id));
1266
- if (f.parentId) {
1267
- const h = s.lbs.find((y) => y.id === f.parentId);
1263
+ if (m.name = u.name, m.type = u.type, u.description !== void 0 ? m.description = u.description : delete m.description, l !== void 0) {
1264
+ for (const h of t.lbs)
1265
+ h.lbsNodeIds?.includes(o.id) && (h.lbsNodeIds = h.lbsNodeIds.filter((v) => v !== o.id));
1266
+ if (u.parentId) {
1267
+ const h = t.lbs.find((v) => v.id === u.parentId);
1268
1268
  h && (h.lbsNodeIds ??= [], h.lbsNodeIds.push(o.id));
1269
1269
  }
1270
1270
  }
1271
1271
  i.push({ id: o.id, error: p.join("; ") });
1272
1272
  continue;
1273
1273
  }
1274
- const g = x(s.lbs).get(m.id) ?? null;
1275
- t.push({ id: o.id, before: f, after: { name: m.name, type: m.type, description: m.description, parentId: g } });
1274
+ const w = P(t.lbs).get(m.id) ?? null;
1275
+ s.push({ id: o.id, before: u, after: { name: m.name, type: m.type, description: m.description, parentId: w } });
1276
1276
  }
1277
- return { succeeded: t, failed: i };
1277
+ return { succeeded: s, failed: i };
1278
1278
  }
1279
1279
  /** Resolves zone and location codes for nomenclature given a node id. */
1280
1280
  resolveCodes(e) {
@@ -1282,10 +1282,10 @@ class Gt extends w {
1282
1282
  }
1283
1283
  /** Validates the full LBS tree and returns a list of structural errors. */
1284
1284
  validateTree() {
1285
- return Mt(this.list());
1285
+ return xt(this.list());
1286
1286
  }
1287
1287
  }
1288
- class Xt extends w {
1288
+ class Xt extends y {
1289
1289
  constructor(e) {
1290
1290
  super(
1291
1291
  () => e().members,
@@ -1299,67 +1299,67 @@ class Xt extends w {
1299
1299
  }
1300
1300
  listResolved() {
1301
1301
  const e = this.getBep();
1302
- return e.members.map((s) => {
1303
- const t = e.teams.find((i) => (i.memberEmails ?? []).includes(s.email));
1302
+ return e.members.map((t) => {
1303
+ const s = e.teams.find((i) => (i.memberEmails ?? []).includes(t.email));
1304
1304
  return {
1305
- ...s,
1306
- role: e.roles.find((i) => i.id === s.roleId) ?? null,
1307
- team: t ? { id: t.id, name: t.name } : null,
1308
- isRepresentative: t?.representativeEmail === s.email
1305
+ ...t,
1306
+ role: e.roles.find((i) => i.id === t.roleId) ?? null,
1307
+ team: s ? { id: s.id, name: s.name } : null,
1308
+ isRepresentative: s?.representativeEmail === t.email
1309
1309
  };
1310
1310
  });
1311
1311
  }
1312
1312
  addToTeam(e) {
1313
- const s = [], t = [];
1313
+ const t = [], s = [];
1314
1314
  for (const i of e) {
1315
1315
  const a = this.getBep().teams.find((m) => m.id === i.teamId);
1316
1316
  if (!a) {
1317
- t.push({ input: i, error: `Team not found: ${i.teamId}` });
1317
+ s.push({ input: i, error: `Team not found: ${i.teamId}` });
1318
1318
  continue;
1319
1319
  }
1320
- const { teamId: d, isRepresentative: l, ...c } = i, u = this.add([c]);
1321
- if (u.failed.length > 0) {
1322
- t.push({ input: i, error: u.failed[0].error });
1320
+ const { teamId: d, isRepresentative: l, ...c } = i, f = this.add([c]);
1321
+ if (f.failed.length > 0) {
1322
+ s.push({ input: i, error: f.failed[0].error });
1323
1323
  continue;
1324
1324
  }
1325
1325
  a.memberEmails ??= [], a.memberEmails.includes(i.email) || a.memberEmails.push(i.email), l && (a.representativeEmail = i.email);
1326
- const f = this.listResolved().find((m) => m.email === i.email);
1327
- s.push(f);
1326
+ const u = this.listResolved().find((m) => m.email === i.email);
1327
+ t.push(u);
1328
1328
  }
1329
- return { succeeded: s, failed: t };
1329
+ return { succeeded: t, failed: s };
1330
1330
  }
1331
1331
  updateInTeam(e) {
1332
- const s = [], t = [];
1332
+ const t = [], s = [];
1333
1333
  for (const i of e) {
1334
1334
  const o = this.getBep(), { teamId: a, isRepresentative: d, ...l } = i;
1335
- if (a !== void 0 && !o.teams.find((f) => f.id === a)) {
1336
- t.push({ email: i.email, error: `Team not found: ${a}` });
1335
+ if (a !== void 0 && !o.teams.find((u) => u.id === a)) {
1336
+ s.push({ email: i.email, error: `Team not found: ${a}` });
1337
1337
  continue;
1338
1338
  }
1339
1339
  const c = this.update([l]);
1340
1340
  if (c.failed.length > 0) {
1341
- t.push({ email: i.email, error: c.failed[0].error });
1341
+ s.push({ email: i.email, error: c.failed[0].error });
1342
1342
  continue;
1343
1343
  }
1344
1344
  if (a !== void 0) {
1345
- const f = o.teams.find((p) => p.id === a), m = o.teams.find((p) => (p.memberEmails ?? []).includes(i.email));
1346
- m && m.id !== a && (m.memberEmails = (m.memberEmails ?? []).filter((p) => p !== i.email), m.representativeEmail === i.email && (m.representativeEmail = void 0)), f.memberEmails ??= [], f.memberEmails.includes(i.email) || f.memberEmails.push(i.email);
1345
+ const u = o.teams.find((p) => p.id === a), m = o.teams.find((p) => (p.memberEmails ?? []).includes(i.email));
1346
+ m && m.id !== a && (m.memberEmails = (m.memberEmails ?? []).filter((p) => p !== i.email), m.representativeEmail === i.email && (m.representativeEmail = void 0)), u.memberEmails ??= [], u.memberEmails.includes(i.email) || u.memberEmails.push(i.email);
1347
1347
  }
1348
1348
  if (d !== void 0) {
1349
- const f = o.teams.find((m) => (m.memberEmails ?? []).includes(i.email));
1350
- f && (f.representativeEmail = d ? i.email : f.representativeEmail === i.email ? void 0 : f.representativeEmail);
1349
+ const u = o.teams.find((m) => (m.memberEmails ?? []).includes(i.email));
1350
+ u && (u.representativeEmail = d ? i.email : u.representativeEmail === i.email ? void 0 : u.representativeEmail);
1351
1351
  }
1352
- const u = this.listResolved().find((f) => f.email === i.email);
1353
- s.push({ email: i.email, after: u });
1352
+ const f = this.listResolved().find((u) => u.email === i.email);
1353
+ t.push({ email: i.email, after: f });
1354
1354
  }
1355
- return { succeeded: s, failed: t };
1355
+ return { succeeded: t, failed: s };
1356
1356
  }
1357
1357
  removeFromBep(e) {
1358
- const s = [], t = [];
1358
+ const t = [], s = [];
1359
1359
  for (const i of e) {
1360
1360
  const o = this.getBep(), a = this.listResolved().find((l) => l.email === i);
1361
1361
  if (!a) {
1362
- t.push({ email: i, error: `Not found: ${i}` });
1362
+ s.push({ email: i, error: `Not found: ${i}` });
1363
1363
  continue;
1364
1364
  }
1365
1365
  for (const l of o.teams)
@@ -1370,15 +1370,15 @@ class Xt extends w {
1370
1370
  const l = o.teams.find((c) => c.id === a.team.id);
1371
1371
  l && (l.memberEmails ??= [], l.memberEmails.includes(i) || l.memberEmails.push(i), a.isRepresentative && (l.representativeEmail = i));
1372
1372
  }
1373
- t.push({ email: i, error: d.failed[0].error });
1373
+ s.push({ email: i, error: d.failed[0].error });
1374
1374
  continue;
1375
1375
  }
1376
- s.push(a);
1376
+ t.push(a);
1377
1377
  }
1378
- return { succeeded: s, failed: t };
1378
+ return { succeeded: t, failed: s };
1379
1379
  }
1380
1380
  }
1381
- class Vt extends w {
1381
+ class Vt extends y {
1382
1382
  constructor(e) {
1383
1383
  super(
1384
1384
  () => e().milestones,
@@ -1387,22 +1387,22 @@ class Vt extends w {
1387
1387
  key: "milestones",
1388
1388
  schema: pe,
1389
1389
  autoId: !0,
1390
- beforeRemove: (s, t) => {
1391
- for (const i of t.loin)
1392
- if (i.milestones?.find((a) => a.milestoneId === s)) throw new Error(`Referenced by: loin["${i.id}"].milestones[milestoneId="${s}"]`);
1390
+ beforeRemove: (t, s) => {
1391
+ for (const i of s.loin)
1392
+ if (i.milestones?.find((a) => a.milestoneId === t)) throw new Error(`Referenced by: loin["${i.id}"].milestones[milestoneId="${t}"]`);
1393
1393
  }
1394
1394
  }
1395
1395
  );
1396
1396
  }
1397
1397
  listResolved() {
1398
1398
  const e = this.getBep();
1399
- return e.milestones.map((s) => ({
1400
- ...s,
1401
- phase: e.phases.find((t) => t.id === s.phaseId) ?? null
1399
+ return e.milestones.map((t) => ({
1400
+ ...t,
1401
+ phase: e.phases.find((s) => s.id === t.phaseId) ?? null
1402
1402
  }));
1403
1403
  }
1404
1404
  }
1405
- class Ht extends w {
1405
+ class Ht extends y {
1406
1406
  constructor(e) {
1407
1407
  super(
1408
1408
  () => e().objectives,
@@ -1415,7 +1415,7 @@ class Ht extends w {
1415
1415
  );
1416
1416
  }
1417
1417
  }
1418
- class Yt extends w {
1418
+ class Yt extends y {
1419
1419
  constructor(e) {
1420
1420
  super(
1421
1421
  () => e().phases,
@@ -1428,37 +1428,37 @@ class Yt extends w {
1428
1428
  );
1429
1429
  }
1430
1430
  }
1431
- class Qt extends w {
1431
+ class Qt extends y {
1432
1432
  constructor(e) {
1433
1433
  super(
1434
1434
  () => e().remoteData,
1435
1435
  e,
1436
1436
  {
1437
1437
  key: "remoteData",
1438
- schema: Le,
1438
+ schema: Ce,
1439
1439
  autoId: !0
1440
1440
  }
1441
1441
  );
1442
1442
  }
1443
1443
  }
1444
- class es extends w {
1444
+ class es extends y {
1445
1445
  constructor(e) {
1446
1446
  super(
1447
1447
  () => e().resolvers,
1448
1448
  e,
1449
1449
  {
1450
1450
  key: "resolvers",
1451
- schema: Ce,
1452
- beforeRemove: (s, t) => {
1453
- const i = t.remoteData.find((o) => o.resolverId === s);
1451
+ schema: Le,
1452
+ beforeRemove: (t, s) => {
1453
+ const i = s.remoteData.find((o) => o.resolverId === t);
1454
1454
  if (i) throw new Error(`Referenced by: remoteData["${i.id}"].resolverId`);
1455
1455
  }
1456
1456
  }
1457
1457
  );
1458
1458
  }
1459
1459
  }
1460
- class ts extends w {
1461
- constructor(e, s) {
1460
+ class ts extends y {
1461
+ constructor(e, t) {
1462
1462
  super(
1463
1463
  () => e().softwares,
1464
1464
  e,
@@ -1466,24 +1466,24 @@ class ts extends w {
1466
1466
  key: "softwares",
1467
1467
  schema: ve
1468
1468
  }
1469
- ), this.getAssetTypes = s;
1469
+ ), this.getAssetTypes = t;
1470
1470
  }
1471
1471
  getAssetTypes;
1472
1472
  listResolved() {
1473
- const e = new Map(this.getAssetTypes().listResolved().map((s) => [s.id, s]));
1474
- return this.getBep().softwares.map((s) => ({
1475
- ...s,
1476
- assetTypes: (s.assetTypeIds ?? []).map((t) => e.get(t)).filter(Boolean)
1473
+ const e = new Map(this.getAssetTypes().listResolved().map((t) => [t.id, t]));
1474
+ return this.getBep().softwares.map((t) => ({
1475
+ ...t,
1476
+ assetTypes: (t.assetTypeIds ?? []).map((s) => e.get(s)).filter(Boolean)
1477
1477
  }));
1478
1478
  }
1479
1479
  }
1480
- class ss extends w {
1481
- constructor(e, s) {
1480
+ class ss extends y {
1481
+ constructor(e, t) {
1482
1482
  super(
1483
1483
  () => e().standards,
1484
1484
  e,
1485
1485
  { key: "standards", schema: Ae, autoId: !0 }
1486
- ), this.getZip = s;
1486
+ ), this.getZip = t;
1487
1487
  }
1488
1488
  getZip;
1489
1489
  /**
@@ -1493,95 +1493,95 @@ class ss extends w {
1493
1493
  * Union with AddInput<Standard> satisfies the base class contract.
1494
1494
  */
1495
1495
  add(e) {
1496
- const s = e.map((t) => {
1496
+ const t = e.map((s) => {
1497
1497
  const i = `standards/${globalThis.crypto.randomUUID()}.md`;
1498
- if ("content" in t) {
1499
- const { content: o, ...a } = t;
1498
+ if ("content" in s) {
1499
+ const { content: o, ...a } = s;
1500
1500
  return this.getZip().file(i, o), { ...a, contentPath: i };
1501
1501
  }
1502
- return this.getZip().file(i, ""), { ...t, contentPath: i };
1502
+ return this.getZip().file(i, ""), { ...s, contentPath: i };
1503
1503
  });
1504
- return super.add(s);
1504
+ return super.add(t);
1505
1505
  }
1506
1506
  /** Removes standards and deletes their .md files from the zip. */
1507
1507
  remove(e) {
1508
- const s = new Map(
1508
+ const t = new Map(
1509
1509
  e.map((i) => [i, this.list().find((o) => o.id === i)?.contentPath]).filter((i) => i[1] !== void 0)
1510
- ), t = super.remove(e);
1511
- for (const i of t.succeeded) {
1512
- const o = s.get(i);
1510
+ ), s = super.remove(e);
1511
+ for (const i of s.succeeded) {
1512
+ const o = t.get(i);
1513
1513
  o && this.getZip().remove(o);
1514
1514
  }
1515
- return t;
1515
+ return s;
1516
1516
  }
1517
1517
  /** Returns the markdown text content of the given standard. */
1518
1518
  async getContent(e) {
1519
- const s = this.list().find((i) => i.id === e);
1520
- if (!s) throw new Error(`Standard not found: ${e}`);
1521
- const t = this.getZip().file(s.contentPath);
1522
- if (!t) throw new Error(`Content file not found: ${s.contentPath}`);
1523
- return t.async("string");
1524
- }
1525
- /** Writes new markdown text content for the given standard. */
1526
- setContent(e, s) {
1527
1519
  const t = this.list().find((i) => i.id === e);
1528
1520
  if (!t) throw new Error(`Standard not found: ${e}`);
1529
- this.getZip().file(t.contentPath, s);
1521
+ const s = this.getZip().file(t.contentPath);
1522
+ if (!s) throw new Error(`Content file not found: ${t.contentPath}`);
1523
+ return s.async("string");
1524
+ }
1525
+ /** Writes new markdown text content for the given standard. */
1526
+ setContent(e, t) {
1527
+ const s = this.list().find((i) => i.id === e);
1528
+ if (!s) throw new Error(`Standard not found: ${e}`);
1529
+ this.getZip().file(s.contentPath, t);
1530
1530
  }
1531
1531
  }
1532
- class ns extends w {
1533
- constructor(e, s) {
1532
+ class ns extends y {
1533
+ constructor(e, t) {
1534
1534
  super(
1535
1535
  () => e().teams,
1536
1536
  e,
1537
1537
  {
1538
1538
  key: "teams",
1539
1539
  schema: fe,
1540
- validate: (t, i) => {
1541
- const o = [], a = j("team", t.id, i.deliverableNamingConvention);
1542
- return a && o.push(a), t.representativeEmail && !(t.memberEmails ?? []).includes(t.representativeEmail) && o.push(`representativeEmail "${t.representativeEmail}" is not a member of this team`), o;
1540
+ validate: (s, i) => {
1541
+ const o = [], a = O("team", s.id, i.deliverableNamingConvention);
1542
+ return a && o.push(a), s.representativeEmail && !(s.memberEmails ?? []).includes(s.representativeEmail) && o.push(`representativeEmail "${s.representativeEmail}" is not a member of this team`), o;
1543
1543
  },
1544
- beforeRemove: (t, i) => {
1545
- if (i.project.clientId === t)
1544
+ beforeRemove: (s, i) => {
1545
+ if (i.project.clientId === s)
1546
1546
  throw new Error("Referenced by: project.clientId");
1547
1547
  }
1548
1548
  }
1549
- ), this.getMembers = s;
1549
+ ), this.getMembers = t;
1550
1550
  }
1551
1551
  getMembers;
1552
1552
  listResolved() {
1553
- const e = this.getBep(), s = new Map(this.getMembers().listResolved().map((t) => [t.email, t]));
1554
- return e.teams.map((t) => ({
1555
- ...t,
1556
- representative: s.get(t.representativeEmail ?? "") ?? null,
1557
- members: (t.memberEmails ?? []).map((i) => s.get(i)).filter(Boolean),
1558
- disciplines: (t.disciplineIds ?? []).map((i) => e.disciplines.find((o) => o.id === i)).filter(Boolean)
1553
+ const e = this.getBep(), t = new Map(this.getMembers().listResolved().map((s) => [s.email, s]));
1554
+ return e.teams.map((s) => ({
1555
+ ...s,
1556
+ representative: t.get(s.representativeEmail ?? "") ?? null,
1557
+ members: (s.memberEmails ?? []).map((i) => t.get(i)).filter(Boolean),
1558
+ disciplines: (s.disciplineIds ?? []).map((i) => e.disciplines.find((o) => o.id === i)).filter(Boolean)
1559
1559
  }));
1560
1560
  }
1561
1561
  }
1562
- function is(n, e, s) {
1563
- const t = [];
1562
+ function is(n, e, t) {
1563
+ const s = [];
1564
1564
  for (const [l, c] of Object.entries(n.nodes))
1565
1565
  if (c.type === "process") {
1566
- c.actionId && !e.actions.some((u) => u.id === c.actionId) && t.push(`actions["${c.actionId}"] not found (node: ${l})`);
1567
- for (const u of ["responsibleRoleIds", "accountableRoleIds", "consultedRoleIds", "informedRoleIds"])
1568
- for (const f of c[u] ?? [])
1569
- e.roles.some((m) => m.id === f) || t.push(`roles["${f}"] not found (node: ${l}.${u})`);
1566
+ c.actionId && !e.actions.some((f) => f.id === c.actionId) && s.push(`actions["${c.actionId}"] not found (node: ${l})`);
1567
+ for (const f of ["responsibleRoleIds", "accountableRoleIds", "consultedRoleIds", "informedRoleIds"])
1568
+ for (const u of c[f] ?? [])
1569
+ e.roles.some((m) => m.id === u) || s.push(`roles["${u}"] not found (node: ${l}.${f})`);
1570
1570
  }
1571
1571
  for (const [l, c] of Object.entries(n.edges)) {
1572
- n.nodes[c.from] || t.push(`edge "${l}": from node "${c.from}" not found`), n.nodes[c.to] || t.push(`edge "${l}": to node "${c.to}" not found`), "triggerEventId" in c && !e.events.some((u) => u.id === c.triggerEventId) && t.push(`events["${c.triggerEventId}"] not found (edge: ${l})`);
1573
- for (const u of c.effectIds ?? [])
1574
- e.effects.some((f) => f.id === u) || t.push(`effects["${u}"] not found (edge: ${l})`);
1572
+ n.nodes[c.from] || s.push(`edge "${l}": from node "${c.from}" not found`), n.nodes[c.to] || s.push(`edge "${l}": to node "${c.to}" not found`), "triggerEventId" in c && !e.events.some((f) => f.id === c.triggerEventId) && s.push(`events["${c.triggerEventId}"] not found (edge: ${l})`);
1573
+ for (const f of c.effectIds ?? [])
1574
+ e.effects.some((u) => u.id === f) || s.push(`effects["${f}"] not found (edge: ${l})`);
1575
1575
  }
1576
1576
  for (const [l, c] of Object.entries(n.nodes))
1577
- if (c.type === "automation" && !e.automations.some((u) => u.id === c.automationId) && t.push(`automations["${c.automationId}"] not found (node: ${l})`), c.type === "process" && c.workflowId && (c.workflowId === s ? t.push(`node "${l}" references its own workflow — would cause infinite recursion`) : e.workflows.some((u) => u.id === c.workflowId) || t.push(`workflows["${c.workflowId}"] not found (node: ${l})`)), (c.type === "process" || c.type === "automation") && c.timeouts)
1578
- for (const u of c.timeouts)
1579
- e.effects.some((f) => f.id === u.effectId) || t.push(`effects["${u.effectId}"] not found (node: ${l}.timeouts)`);
1577
+ if (c.type === "automation" && !e.automations.some((f) => f.id === c.automationId) && s.push(`automations["${c.automationId}"] not found (node: ${l})`), c.type === "process" && c.workflowId && (c.workflowId === t ? s.push(`node "${l}" references its own workflow — would cause infinite recursion`) : e.workflows.some((f) => f.id === c.workflowId) || s.push(`workflows["${c.workflowId}"] not found (node: ${l})`)), (c.type === "process" || c.type === "automation") && c.timeouts)
1578
+ for (const f of c.timeouts)
1579
+ e.effects.some((u) => u.id === f.effectId) || s.push(`effects["${f.effectId}"] not found (node: ${l}.timeouts)`);
1580
1580
  const i = Object.keys(n.nodes), o = new Set(Object.values(n.edges).map((l) => l.to)), a = new Set(Object.values(n.edges).map((l) => l.from));
1581
1581
  for (const l of i)
1582
- n.nodes[l].type !== "start" && (o.has(l) || t.push(`node "${l}" is unreachable — no edges point to it`));
1582
+ n.nodes[l].type !== "start" && (o.has(l) || s.push(`node "${l}" is unreachable — no edges point to it`));
1583
1583
  for (const l of i)
1584
- n.nodes[l].type !== "end" && (a.has(l) || t.push(`node "${l}" has no outgoing edges — workflow would get stuck here`));
1584
+ n.nodes[l].type !== "end" && (a.has(l) || s.push(`node "${l}" has no outgoing edges — workflow would get stuck here`));
1585
1585
  const d = {};
1586
1586
  for (const l of Object.keys(n.edges)) {
1587
1587
  const c = n.edges[l];
@@ -1589,110 +1589,110 @@ function is(n, e, s) {
1589
1589
  }
1590
1590
  for (const [l, c] of Object.entries(n.nodes)) {
1591
1591
  if (c.type !== "decision") continue;
1592
- const u = /* @__PURE__ */ new Set();
1593
- for (const f of d[l] ?? []) {
1594
- const m = n.edges[f], p = n.nodes[m.from];
1592
+ const f = /* @__PURE__ */ new Set();
1593
+ for (const u of d[l] ?? []) {
1594
+ const m = n.edges[u], p = n.nodes[m.from];
1595
1595
  if (p) {
1596
1596
  if (p.type === "automation") {
1597
- const g = e.automations.find((h) => h.id === p.automationId);
1598
- for (const h of g?.output ?? []) u.add(h.key);
1597
+ const w = e.automations.find((h) => h.id === p.automationId);
1598
+ for (const h of w?.output ?? []) f.add(h.key);
1599
1599
  }
1600
1600
  if (p.type === "process" && "triggerEventId" in m) {
1601
- const g = e.events.find((h) => h.id === m.triggerEventId);
1602
- for (const h of g?.payload ?? []) u.add(h.key);
1601
+ const w = e.events.find((h) => h.id === m.triggerEventId);
1602
+ for (const h of w?.payload ?? []) f.add(h.key);
1603
1603
  }
1604
1604
  }
1605
1605
  }
1606
- if (u.size !== 0)
1607
- for (const [f, m] of Object.entries(n.edges))
1608
- m.from === l && "guard" in m && (u.has(m.guard.field) || t.push(`guard field "${m.guard.field}" on edge "${f}" is not declared in any direct predecessor's output or payload (node: ${l})`));
1606
+ if (f.size !== 0)
1607
+ for (const [u, m] of Object.entries(n.edges))
1608
+ m.from === l && "guard" in m && (f.has(m.guard.field) || s.push(`guard field "${m.guard.field}" on edge "${u}" is not declared in any direct predecessor's output or payload (node: ${l})`));
1609
1609
  }
1610
- return t;
1610
+ return s;
1611
1611
  }
1612
- class os extends w {
1613
- constructor(e, s, t) {
1612
+ class os extends y {
1613
+ constructor(e, t, s) {
1614
1614
  super(
1615
1615
  () => e().workflows,
1616
1616
  e,
1617
1617
  {
1618
1618
  key: "workflows",
1619
- schema: Re,
1619
+ schema: $e,
1620
1620
  autoId: !0,
1621
1621
  validate: (i, o) => is(i.diagram, o, i.id)
1622
1622
  }
1623
- ), this.getMembers = s, this.getTeams = t;
1623
+ ), this.getMembers = t, this.getTeams = s;
1624
1624
  }
1625
1625
  getMembers;
1626
1626
  getTeams;
1627
1627
  getRaciMatrix() {
1628
- const e = this.getBep(), s = [], t = /* @__PURE__ */ new Set(), i = this.getMembers().listResolved(), o = this.getTeams().listResolved(), a = (l) => (l ?? []).flatMap((c) => {
1629
- const u = e.roles.find((p) => p.id === c);
1630
- if (!u) return [];
1631
- t.add(c);
1632
- const f = i.filter((p) => p.role?.id === c), m = o.find((p) => p.members.some((g) => g.role?.id === c)) ?? null;
1633
- return [{ role: u, members: f, team: m }];
1628
+ const e = this.getBep(), t = [], s = /* @__PURE__ */ new Set(), i = this.getMembers().listResolved(), o = this.getTeams().listResolved(), a = (l) => (l ?? []).flatMap((c) => {
1629
+ const f = e.roles.find((p) => p.id === c);
1630
+ if (!f) return [];
1631
+ s.add(c);
1632
+ const u = i.filter((p) => p.role?.id === c), m = o.find((p) => p.members.some((w) => w.role?.id === c)) ?? null;
1633
+ return [{ role: f, members: u, team: m }];
1634
1634
  });
1635
1635
  for (const l of e.workflows)
1636
- for (const [c, u] of Object.entries(l.diagram.nodes)) {
1637
- if (u.type !== "process") continue;
1638
- const f = u.actionId ? e.actions.find((m) => m.id === u.actionId) : void 0;
1639
- s.push({
1636
+ for (const [c, f] of Object.entries(l.diagram.nodes)) {
1637
+ if (f.type !== "process") continue;
1638
+ const u = f.actionId ? e.actions.find((m) => m.id === f.actionId) : void 0;
1639
+ t.push({
1640
1640
  workflow: { id: l.id, name: l.name },
1641
1641
  nodeId: c,
1642
- label: f?.name ?? c,
1643
- ...f?.description ? { description: f.description } : {},
1644
- ...u.actionId ? { actionId: u.actionId } : {},
1645
- responsible: a(u.responsibleRoleIds),
1646
- accountable: a(u.accountableRoleIds),
1647
- consulted: a(u.consultedRoleIds),
1648
- informed: a(u.informedRoleIds)
1642
+ label: u?.name ?? c,
1643
+ ...u?.description ? { description: u.description } : {},
1644
+ ...f.actionId ? { actionId: f.actionId } : {},
1645
+ responsible: a(f.responsibleRoleIds),
1646
+ accountable: a(f.accountableRoleIds),
1647
+ consulted: a(f.consultedRoleIds),
1648
+ informed: a(f.informedRoleIds)
1649
1649
  });
1650
1650
  }
1651
- return { roles: [...t].map((l) => e.roles.find((c) => c.id === l)).filter(Boolean), rows: s };
1651
+ return { roles: [...s].map((l) => e.roles.find((c) => c.id === l)).filter(Boolean), rows: t };
1652
1652
  }
1653
1653
  getRaciMatrixForWorkflow(e) {
1654
- const s = this.getRaciMatrix(), t = s.rows.filter((o) => o.workflow.id === e), i = new Set(
1655
- t.flatMap((o) => [...o.responsible, ...o.accountable, ...o.consulted, ...o.informed].map((a) => a.role.id))
1654
+ const t = this.getRaciMatrix(), s = t.rows.filter((o) => o.workflow.id === e), i = new Set(
1655
+ s.flatMap((o) => [...o.responsible, ...o.accountable, ...o.consulted, ...o.informed].map((a) => a.role.id))
1656
1656
  );
1657
- return { roles: s.roles.filter((o) => i.has(o.id)), rows: t };
1657
+ return { roles: t.roles.filter((o) => i.has(o.id)), rows: s };
1658
1658
  }
1659
1659
  getConsolidatedRaciMatrix() {
1660
- const e = this.getRaciMatrix(), s = /* @__PURE__ */ new Map(), t = (a, d) => {
1660
+ const e = this.getRaciMatrix(), t = /* @__PURE__ */ new Map(), s = (a, d) => {
1661
1661
  const l = new Map(a.map((c) => [c.role.id, { ...c, members: [...c.members] }]));
1662
1662
  for (const c of d)
1663
1663
  if (!l.has(c.role.id))
1664
1664
  l.set(c.role.id, { ...c, members: [...c.members] });
1665
1665
  else {
1666
- const u = l.get(c.role.id), f = new Set(u.members.map((m) => m.email));
1667
- for (const m of c.members) f.has(m.email) || u.members.push(m);
1666
+ const f = l.get(c.role.id), u = new Set(f.members.map((m) => m.email));
1667
+ for (const m of c.members) u.has(m.email) || f.members.push(m);
1668
1668
  }
1669
1669
  return [...l.values()];
1670
1670
  };
1671
1671
  for (const a of e.rows) {
1672
1672
  const d = a.actionId ?? `node:${a.workflow.id}:${a.nodeId}`;
1673
- if (!s.has(d))
1674
- s.set(d, { ...a, workflow: { id: "", name: "" } });
1673
+ if (!t.has(d))
1674
+ t.set(d, { ...a, workflow: { id: "", name: "" } });
1675
1675
  else {
1676
- const l = s.get(d);
1677
- l.responsible = t(l.responsible, a.responsible), l.accountable = t(l.accountable, a.accountable), l.consulted = t(l.consulted, a.consulted), l.informed = t(l.informed, a.informed);
1676
+ const l = t.get(d);
1677
+ l.responsible = s(l.responsible, a.responsible), l.accountable = s(l.accountable, a.accountable), l.consulted = s(l.consulted, a.consulted), l.informed = s(l.informed, a.informed);
1678
1678
  }
1679
1679
  }
1680
- const i = [...s.values()], o = new Set(
1680
+ const i = [...t.values()], o = new Set(
1681
1681
  i.flatMap((a) => [...a.responsible, ...a.accountable, ...a.consulted, ...a.informed].map((d) => d.role.id))
1682
1682
  );
1683
1683
  return { roles: e.roles.filter((a) => o.has(a.id)), rows: i };
1684
1684
  }
1685
1685
  listResolved() {
1686
1686
  const e = this.getBep();
1687
- return e.workflows.map((s) => {
1688
- const t = {};
1689
- for (const [i, o] of Object.entries(s.diagram.nodes)) {
1687
+ return e.workflows.map((t) => {
1688
+ const s = {};
1689
+ for (const [i, o] of Object.entries(t.diagram.nodes)) {
1690
1690
  const a = (d) => ({
1691
1691
  roles: (d ?? []).map((l) => e.roles.find((c) => c.id === l)).filter(Boolean),
1692
1692
  teams: [],
1693
1693
  members: []
1694
1694
  });
1695
- t[i] = {
1695
+ s[i] = {
1696
1696
  type: o.type,
1697
1697
  label: o.type === "decision" ? o.label : void 0,
1698
1698
  timeouts: o.type === "process" || o.type === "automation" ? o.timeouts : void 0,
@@ -1707,26 +1707,26 @@ class os extends w {
1707
1707
  };
1708
1708
  }
1709
1709
  return {
1710
- ...s,
1711
- diagram: { ...s.diagram, nodes: t }
1710
+ ...t,
1711
+ diagram: { ...t.diagram, nodes: s }
1712
1712
  };
1713
1713
  });
1714
1714
  }
1715
1715
  }
1716
1716
  var rs = /* @__PURE__ */ (function() {
1717
- var n = function(e, s) {
1718
- return n = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, i) {
1719
- t.__proto__ = i;
1720
- } || function(t, i) {
1721
- for (var o in i) i.hasOwnProperty(o) && (t[o] = i[o]);
1722
- }, n(e, s);
1717
+ var n = function(e, t) {
1718
+ return n = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(s, i) {
1719
+ s.__proto__ = i;
1720
+ } || function(s, i) {
1721
+ for (var o in i) i.hasOwnProperty(o) && (s[o] = i[o]);
1722
+ }, n(e, t);
1723
1723
  };
1724
- return function(e, s) {
1725
- n(e, s);
1726
- function t() {
1724
+ return function(e, t) {
1725
+ n(e, t);
1726
+ function s() {
1727
1727
  this.constructor = e;
1728
1728
  }
1729
- e.prototype = s === null ? Object.create(s) : (t.prototype = s.prototype, new t());
1729
+ e.prototype = t === null ? Object.create(t) : (s.prototype = t.prototype, new s());
1730
1730
  };
1731
1731
  })(), as = Object.prototype.hasOwnProperty;
1732
1732
  function q(n, e) {
@@ -1734,18 +1734,18 @@ function q(n, e) {
1734
1734
  }
1735
1735
  function W(n) {
1736
1736
  if (Array.isArray(n)) {
1737
- for (var e = new Array(n.length), s = 0; s < e.length; s++)
1738
- e[s] = "" + s;
1737
+ for (var e = new Array(n.length), t = 0; t < e.length; t++)
1738
+ e[t] = "" + t;
1739
1739
  return e;
1740
1740
  }
1741
1741
  if (Object.keys)
1742
1742
  return Object.keys(n);
1743
- var t = [];
1743
+ var s = [];
1744
1744
  for (var i in n)
1745
- q(n, i) && t.push(i);
1746
- return t;
1745
+ q(n, i) && s.push(i);
1746
+ return s;
1747
1747
  }
1748
- function S(n) {
1748
+ function N(n) {
1749
1749
  switch (typeof n) {
1750
1750
  case "object":
1751
1751
  return JSON.parse(JSON.stringify(n));
@@ -1758,8 +1758,8 @@ function S(n) {
1758
1758
  }
1759
1759
  }
1760
1760
  function G(n) {
1761
- for (var e = 0, s = n.length, t; e < s; ) {
1762
- if (t = n.charCodeAt(e), t >= 48 && t <= 57) {
1761
+ for (var e = 0, t = n.length, s; e < t; ) {
1762
+ if (s = n.charCodeAt(e), s >= 48 && s <= 57) {
1763
1763
  e++;
1764
1764
  continue;
1765
1765
  }
@@ -1767,7 +1767,7 @@ function G(n) {
1767
1767
  }
1768
1768
  return !0;
1769
1769
  }
1770
- function _(n) {
1770
+ function R(n) {
1771
1771
  return n.indexOf("/") === -1 && n.indexOf("~") === -1 ? n : n.replace(/~/g, "~0").replace(/\//g, "~1");
1772
1772
  }
1773
1773
  function Je(n) {
@@ -1778,217 +1778,217 @@ function X(n) {
1778
1778
  return !0;
1779
1779
  if (n) {
1780
1780
  if (Array.isArray(n)) {
1781
- for (var e = 0, s = n.length; e < s; e++)
1781
+ for (var e = 0, t = n.length; e < t; e++)
1782
1782
  if (X(n[e]))
1783
1783
  return !0;
1784
1784
  } else if (typeof n == "object") {
1785
- for (var t = W(n), i = t.length, o = 0; o < i; o++)
1786
- if (X(n[t[o]]))
1785
+ for (var s = W(n), i = s.length, o = 0; o < i; o++)
1786
+ if (X(n[s[o]]))
1787
1787
  return !0;
1788
1788
  }
1789
1789
  }
1790
1790
  return !1;
1791
1791
  }
1792
1792
  function oe(n, e) {
1793
- var s = [n];
1794
- for (var t in e) {
1795
- var i = typeof e[t] == "object" ? JSON.stringify(e[t], null, 2) : e[t];
1796
- typeof i < "u" && s.push(t + ": " + i);
1793
+ var t = [n];
1794
+ for (var s in e) {
1795
+ var i = typeof e[s] == "object" ? JSON.stringify(e[s], null, 2) : e[s];
1796
+ typeof i < "u" && t.push(s + ": " + i);
1797
1797
  }
1798
- return s.join(`
1798
+ return t.join(`
1799
1799
  `);
1800
1800
  }
1801
1801
  var Ke = (
1802
1802
  /** @class */
1803
1803
  (function(n) {
1804
1804
  rs(e, n);
1805
- function e(s, t, i, o, a) {
1806
- var d = this.constructor, l = n.call(this, oe(s, { name: t, index: i, operation: o, tree: a })) || this;
1807
- return l.name = t, l.index = i, l.operation = o, l.tree = a, Object.setPrototypeOf(l, d.prototype), l.message = oe(s, { name: t, index: i, operation: o, tree: a }), l;
1805
+ function e(t, s, i, o, a) {
1806
+ var d = this.constructor, l = n.call(this, oe(t, { name: s, index: i, operation: o, tree: a })) || this;
1807
+ return l.name = s, l.index = i, l.operation = o, l.tree = a, Object.setPrototypeOf(l, d.prototype), l.message = oe(t, { name: s, index: i, operation: o, tree: a }), l;
1808
1808
  }
1809
1809
  return e;
1810
1810
  })(Error)
1811
- ), b = Ke, ds = S, A = {
1812
- add: function(n, e, s) {
1813
- return n[e] = this.value, { newDocument: s };
1811
+ ), E = Ke, ds = N, j = {
1812
+ add: function(n, e, t) {
1813
+ return n[e] = this.value, { newDocument: t };
1814
1814
  },
1815
- remove: function(n, e, s) {
1816
- var t = n[e];
1817
- return delete n[e], { newDocument: s, removed: t };
1815
+ remove: function(n, e, t) {
1816
+ var s = n[e];
1817
+ return delete n[e], { newDocument: t, removed: s };
1818
1818
  },
1819
- replace: function(n, e, s) {
1820
- var t = n[e];
1821
- return n[e] = this.value, { newDocument: s, removed: t };
1819
+ replace: function(n, e, t) {
1820
+ var s = n[e];
1821
+ return n[e] = this.value, { newDocument: t, removed: s };
1822
1822
  },
1823
- move: function(n, e, s) {
1824
- var t = L(s, this.path);
1825
- t && (t = S(t));
1826
- var i = R(s, { op: "remove", path: this.from }).removed;
1827
- return R(s, { op: "add", path: this.path, value: i }), { newDocument: s, removed: t };
1823
+ move: function(n, e, t) {
1824
+ var s = C(t, this.path);
1825
+ s && (s = N(s));
1826
+ var i = T(t, { op: "remove", path: this.from }).removed;
1827
+ return T(t, { op: "add", path: this.path, value: i }), { newDocument: t, removed: s };
1828
1828
  },
1829
- copy: function(n, e, s) {
1830
- var t = L(s, this.from);
1831
- return R(s, { op: "add", path: this.path, value: S(t) }), { newDocument: s };
1829
+ copy: function(n, e, t) {
1830
+ var s = C(t, this.from);
1831
+ return T(t, { op: "add", path: this.path, value: N(s) }), { newDocument: t };
1832
1832
  },
1833
- test: function(n, e, s) {
1834
- return { newDocument: s, test: B(n[e], this.value) };
1833
+ test: function(n, e, t) {
1834
+ return { newDocument: t, test: x(n[e], this.value) };
1835
1835
  },
1836
- _get: function(n, e, s) {
1837
- return this.value = n[e], { newDocument: s };
1836
+ _get: function(n, e, t) {
1837
+ return this.value = n[e], { newDocument: t };
1838
1838
  }
1839
1839
  }, ls = {
1840
- add: function(n, e, s) {
1841
- return G(e) ? n.splice(e, 0, this.value) : n[e] = this.value, { newDocument: s, index: e };
1840
+ add: function(n, e, t) {
1841
+ return G(e) ? n.splice(e, 0, this.value) : n[e] = this.value, { newDocument: t, index: e };
1842
1842
  },
1843
- remove: function(n, e, s) {
1844
- var t = n.splice(e, 1);
1845
- return { newDocument: s, removed: t[0] };
1843
+ remove: function(n, e, t) {
1844
+ var s = n.splice(e, 1);
1845
+ return { newDocument: t, removed: s[0] };
1846
1846
  },
1847
- replace: function(n, e, s) {
1848
- var t = n[e];
1849
- return n[e] = this.value, { newDocument: s, removed: t };
1847
+ replace: function(n, e, t) {
1848
+ var s = n[e];
1849
+ return n[e] = this.value, { newDocument: t, removed: s };
1850
1850
  },
1851
- move: A.move,
1852
- copy: A.copy,
1853
- test: A.test,
1854
- _get: A._get
1851
+ move: j.move,
1852
+ copy: j.copy,
1853
+ test: j.test,
1854
+ _get: j._get
1855
1855
  };
1856
- function L(n, e) {
1856
+ function C(n, e) {
1857
1857
  if (e == "")
1858
1858
  return n;
1859
- var s = { op: "_get", path: e };
1860
- return R(n, s), s.value;
1859
+ var t = { op: "_get", path: e };
1860
+ return T(n, t), t.value;
1861
1861
  }
1862
- function R(n, e, s, t, i, o) {
1863
- if (s === void 0 && (s = !1), t === void 0 && (t = !0), i === void 0 && (i = !0), o === void 0 && (o = 0), s && (typeof s == "function" ? s(e, 0, n, e.path) : D(e, 0)), e.path === "") {
1862
+ function T(n, e, t, s, i, o) {
1863
+ if (t === void 0 && (t = !1), s === void 0 && (s = !0), i === void 0 && (i = !0), o === void 0 && (o = 0), t && (typeof t == "function" ? t(e, 0, n, e.path) : D(e, 0)), e.path === "") {
1864
1864
  var a = { newDocument: n };
1865
1865
  if (e.op === "add")
1866
1866
  return a.newDocument = e.value, a;
1867
1867
  if (e.op === "replace")
1868
1868
  return a.newDocument = e.value, a.removed = n, a;
1869
1869
  if (e.op === "move" || e.op === "copy")
1870
- return a.newDocument = L(n, e.from), e.op === "move" && (a.removed = n), a;
1870
+ return a.newDocument = C(n, e.from), e.op === "move" && (a.removed = n), a;
1871
1871
  if (e.op === "test") {
1872
- if (a.test = B(n, e.value), a.test === !1)
1873
- throw new b("Test operation failed", "TEST_OPERATION_FAILED", o, e, n);
1872
+ if (a.test = x(n, e.value), a.test === !1)
1873
+ throw new E("Test operation failed", "TEST_OPERATION_FAILED", o, e, n);
1874
1874
  return a.newDocument = n, a;
1875
1875
  } else {
1876
1876
  if (e.op === "remove")
1877
1877
  return a.removed = n, a.newDocument = null, a;
1878
1878
  if (e.op === "_get")
1879
1879
  return e.value = n, a;
1880
- if (s)
1881
- throw new b("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", o, e, n);
1880
+ if (t)
1881
+ throw new E("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", o, e, n);
1882
1882
  return a;
1883
1883
  }
1884
1884
  } else {
1885
- t || (n = S(n));
1886
- var d = e.path || "", l = d.split("/"), c = n, u = 1, f = l.length, m = void 0, p = void 0, g = void 0;
1887
- for (typeof s == "function" ? g = s : g = D; ; ) {
1888
- if (p = l[u], p && p.indexOf("~") != -1 && (p = Je(p)), i && (p == "__proto__" || p == "prototype" && u > 0 && l[u - 1] == "constructor"))
1885
+ s || (n = N(n));
1886
+ var d = e.path || "", l = d.split("/"), c = n, f = 1, u = l.length, m = void 0, p = void 0, w = void 0;
1887
+ for (typeof t == "function" ? w = t : w = D; ; ) {
1888
+ if (p = l[f], p && p.indexOf("~") != -1 && (p = Je(p)), i && (p == "__proto__" || p == "prototype" && f > 0 && l[f - 1] == "constructor"))
1889
1889
  throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");
1890
- if (s && m === void 0 && (c[p] === void 0 ? m = l.slice(0, u).join("/") : u == f - 1 && (m = e.path), m !== void 0 && g(e, 0, n, m)), u++, Array.isArray(c)) {
1890
+ if (t && m === void 0 && (c[p] === void 0 ? m = l.slice(0, f).join("/") : f == u - 1 && (m = e.path), m !== void 0 && w(e, 0, n, m)), f++, Array.isArray(c)) {
1891
1891
  if (p === "-")
1892
1892
  p = c.length;
1893
1893
  else {
1894
- if (s && !G(p))
1895
- throw new b("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", o, e, n);
1894
+ if (t && !G(p))
1895
+ throw new E("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", o, e, n);
1896
1896
  G(p) && (p = ~~p);
1897
1897
  }
1898
- if (u >= f) {
1899
- if (s && e.op === "add" && p > c.length)
1900
- throw new b("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", o, e, n);
1898
+ if (f >= u) {
1899
+ if (t && e.op === "add" && p > c.length)
1900
+ throw new E("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", o, e, n);
1901
1901
  var a = ls[e.op].call(e, c, p, n);
1902
1902
  if (a.test === !1)
1903
- throw new b("Test operation failed", "TEST_OPERATION_FAILED", o, e, n);
1903
+ throw new E("Test operation failed", "TEST_OPERATION_FAILED", o, e, n);
1904
1904
  return a;
1905
1905
  }
1906
- } else if (u >= f) {
1907
- var a = A[e.op].call(e, c, p, n);
1906
+ } else if (f >= u) {
1907
+ var a = j[e.op].call(e, c, p, n);
1908
1908
  if (a.test === !1)
1909
- throw new b("Test operation failed", "TEST_OPERATION_FAILED", o, e, n);
1909
+ throw new E("Test operation failed", "TEST_OPERATION_FAILED", o, e, n);
1910
1910
  return a;
1911
1911
  }
1912
- if (c = c[p], s && u < f && (!c || typeof c != "object"))
1913
- throw new b("Cannot perform operation at the desired path", "OPERATION_PATH_UNRESOLVABLE", o, e, n);
1912
+ if (c = c[p], t && f < u && (!c || typeof c != "object"))
1913
+ throw new E("Cannot perform operation at the desired path", "OPERATION_PATH_UNRESOLVABLE", o, e, n);
1914
1914
  }
1915
1915
  }
1916
1916
  }
1917
- function U(n, e, s, t, i) {
1918
- if (t === void 0 && (t = !0), i === void 0 && (i = !0), s && !Array.isArray(e))
1919
- throw new b("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
1920
- t || (n = S(n));
1917
+ function U(n, e, t, s, i) {
1918
+ if (s === void 0 && (s = !0), i === void 0 && (i = !0), t && !Array.isArray(e))
1919
+ throw new E("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
1920
+ s || (n = N(n));
1921
1921
  for (var o = new Array(e.length), a = 0, d = e.length; a < d; a++)
1922
- o[a] = R(n, e[a], s, !0, i, a), n = o[a].newDocument;
1922
+ o[a] = T(n, e[a], t, !0, i, a), n = o[a].newDocument;
1923
1923
  return o.newDocument = n, o;
1924
1924
  }
1925
- function cs(n, e, s) {
1926
- var t = R(n, e);
1927
- if (t.test === !1)
1928
- throw new b("Test operation failed", "TEST_OPERATION_FAILED", s, e, n);
1929
- return t.newDocument;
1925
+ function cs(n, e, t) {
1926
+ var s = T(n, e);
1927
+ if (s.test === !1)
1928
+ throw new E("Test operation failed", "TEST_OPERATION_FAILED", t, e, n);
1929
+ return s.newDocument;
1930
1930
  }
1931
- function D(n, e, s, t) {
1931
+ function D(n, e, t, s) {
1932
1932
  if (typeof n != "object" || n === null || Array.isArray(n))
1933
- throw new b("Operation is not an object", "OPERATION_NOT_AN_OBJECT", e, n, s);
1934
- if (A[n.op]) {
1933
+ throw new E("Operation is not an object", "OPERATION_NOT_AN_OBJECT", e, n, t);
1934
+ if (j[n.op]) {
1935
1935
  if (typeof n.path != "string")
1936
- throw new b("Operation `path` property is not a string", "OPERATION_PATH_INVALID", e, n, s);
1936
+ throw new E("Operation `path` property is not a string", "OPERATION_PATH_INVALID", e, n, t);
1937
1937
  if (n.path.indexOf("/") !== 0 && n.path.length > 0)
1938
- throw new b('Operation `path` property must start with "/"', "OPERATION_PATH_INVALID", e, n, s);
1938
+ throw new E('Operation `path` property must start with "/"', "OPERATION_PATH_INVALID", e, n, t);
1939
1939
  if ((n.op === "move" || n.op === "copy") && typeof n.from != "string")
1940
- throw new b("Operation `from` property is not present (applicable in `move` and `copy` operations)", "OPERATION_FROM_REQUIRED", e, n, s);
1940
+ throw new E("Operation `from` property is not present (applicable in `move` and `copy` operations)", "OPERATION_FROM_REQUIRED", e, n, t);
1941
1941
  if ((n.op === "add" || n.op === "replace" || n.op === "test") && n.value === void 0)
1942
- throw new b("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_REQUIRED", e, n, s);
1942
+ throw new E("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_REQUIRED", e, n, t);
1943
1943
  if ((n.op === "add" || n.op === "replace" || n.op === "test") && X(n.value))
1944
- throw new b("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED", e, n, s);
1945
- if (s) {
1944
+ throw new E("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED", e, n, t);
1945
+ if (t) {
1946
1946
  if (n.op == "add") {
1947
- var i = n.path.split("/").length, o = t.split("/").length;
1947
+ var i = n.path.split("/").length, o = s.split("/").length;
1948
1948
  if (i !== o + 1 && i !== o)
1949
- throw new b("Cannot perform an `add` operation at the desired path", "OPERATION_PATH_CANNOT_ADD", e, n, s);
1949
+ throw new E("Cannot perform an `add` operation at the desired path", "OPERATION_PATH_CANNOT_ADD", e, n, t);
1950
1950
  } else if (n.op === "replace" || n.op === "remove" || n.op === "_get") {
1951
- if (n.path !== t)
1952
- throw new b("Cannot perform the operation at a path that does not exist", "OPERATION_PATH_UNRESOLVABLE", e, n, s);
1951
+ if (n.path !== s)
1952
+ throw new E("Cannot perform the operation at a path that does not exist", "OPERATION_PATH_UNRESOLVABLE", e, n, t);
1953
1953
  } else if (n.op === "move" || n.op === "copy") {
1954
- var a = { op: "_get", path: n.from, value: void 0 }, d = qe([a], s);
1954
+ var a = { op: "_get", path: n.from, value: void 0 }, d = qe([a], t);
1955
1955
  if (d && d.name === "OPERATION_PATH_UNRESOLVABLE")
1956
- throw new b("Cannot perform the operation from a path that does not exist", "OPERATION_FROM_UNRESOLVABLE", e, n, s);
1956
+ throw new E("Cannot perform the operation from a path that does not exist", "OPERATION_FROM_UNRESOLVABLE", e, n, t);
1957
1957
  }
1958
1958
  }
1959
- } else throw new b("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", e, n, s);
1959
+ } else throw new E("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", e, n, t);
1960
1960
  }
1961
- function qe(n, e, s) {
1961
+ function qe(n, e, t) {
1962
1962
  try {
1963
1963
  if (!Array.isArray(n))
1964
- throw new b("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
1964
+ throw new E("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
1965
1965
  if (e)
1966
- U(S(e), S(n), s || !0);
1966
+ U(N(e), N(n), t || !0);
1967
1967
  else {
1968
- s = s || D;
1969
- for (var t = 0; t < n.length; t++)
1970
- s(n[t], t, e, void 0);
1968
+ t = t || D;
1969
+ for (var s = 0; s < n.length; s++)
1970
+ t(n[s], s, e, void 0);
1971
1971
  }
1972
1972
  } catch (i) {
1973
- if (i instanceof b)
1973
+ if (i instanceof E)
1974
1974
  return i;
1975
1975
  throw i;
1976
1976
  }
1977
1977
  }
1978
- function B(n, e) {
1978
+ function x(n, e) {
1979
1979
  if (n === e)
1980
1980
  return !0;
1981
1981
  if (n && e && typeof n == "object" && typeof e == "object") {
1982
- var s = Array.isArray(n), t = Array.isArray(e), i, o, a;
1983
- if (s && t) {
1982
+ var t = Array.isArray(n), s = Array.isArray(e), i, o, a;
1983
+ if (t && s) {
1984
1984
  if (o = n.length, o != e.length)
1985
1985
  return !1;
1986
1986
  for (i = o; i-- !== 0; )
1987
- if (!B(n[i], e[i]))
1987
+ if (!x(n[i], e[i]))
1988
1988
  return !1;
1989
1989
  return !0;
1990
1990
  }
1991
- if (s != t)
1991
+ if (t != s)
1992
1992
  return !1;
1993
1993
  var d = Object.keys(n);
1994
1994
  if (o = d.length, o !== Object.keys(e).length)
@@ -1997,7 +1997,7 @@ function B(n, e) {
1997
1997
  if (!e.hasOwnProperty(d[i]))
1998
1998
  return !1;
1999
1999
  for (i = o; i-- !== 0; )
2000
- if (a = d[i], !B(n[a], e[a]))
2000
+ if (a = d[i], !x(n[a], e[a]))
2001
2001
  return !1;
2002
2002
  return !0;
2003
2003
  }
@@ -2005,13 +2005,13 @@ function B(n, e) {
2005
2005
  }
2006
2006
  const fs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2007
2007
  __proto__: null,
2008
- JsonPatchError: b,
2009
- _areEquals: B,
2010
- applyOperation: R,
2008
+ JsonPatchError: E,
2009
+ _areEquals: x,
2010
+ applyOperation: T,
2011
2011
  applyPatch: U,
2012
2012
  applyReducer: cs,
2013
2013
  deepClone: ds,
2014
- getValueByPointer: L,
2014
+ getValueByPointer: C,
2015
2015
  validate: qe,
2016
2016
  validator: D
2017
2017
  }, Symbol.toStringTag, { value: "Module" }));
@@ -2026,8 +2026,8 @@ var ee = /* @__PURE__ */ new WeakMap(), us = (
2026
2026
  ), ms = (
2027
2027
  /** @class */
2028
2028
  /* @__PURE__ */ (function() {
2029
- function n(e, s) {
2030
- this.callback = e, this.observer = s;
2029
+ function n(e, t) {
2030
+ this.callback = e, this.observer = t;
2031
2031
  }
2032
2032
  return n;
2033
2033
  })()
@@ -2045,56 +2045,56 @@ function ws(n, e) {
2045
2045
  e.unobserve();
2046
2046
  }
2047
2047
  function ys(n, e) {
2048
- var s = [], t, i = ps(n);
2048
+ var t = [], s, i = ps(n);
2049
2049
  if (!i)
2050
2050
  i = new us(n), ee.set(n, i);
2051
2051
  else {
2052
2052
  var o = hs(i, e);
2053
- t = o && o.observer;
2053
+ s = o && o.observer;
2054
2054
  }
2055
- if (t)
2056
- return t;
2057
- if (t = {}, i.value = S(n), e) {
2058
- t.callback = e, t.next = null;
2055
+ if (s)
2056
+ return s;
2057
+ if (s = {}, i.value = N(n), e) {
2058
+ s.callback = e, s.next = null;
2059
2059
  var a = function() {
2060
- V(t);
2060
+ V(s);
2061
2061
  }, d = function() {
2062
- clearTimeout(t.next), t.next = setTimeout(a);
2062
+ clearTimeout(s.next), s.next = setTimeout(a);
2063
2063
  };
2064
2064
  typeof window < "u" && (window.addEventListener("mouseup", d), window.addEventListener("keyup", d), window.addEventListener("mousedown", d), window.addEventListener("keydown", d), window.addEventListener("change", d));
2065
2065
  }
2066
- return t.patches = s, t.object = n, t.unobserve = function() {
2067
- V(t), clearTimeout(t.next), gs(i, t), typeof window < "u" && (window.removeEventListener("mouseup", d), window.removeEventListener("keyup", d), window.removeEventListener("mousedown", d), window.removeEventListener("keydown", d), window.removeEventListener("change", d));
2068
- }, i.observers.set(e, new ms(e, t)), t;
2066
+ return s.patches = t, s.object = n, s.unobserve = function() {
2067
+ V(s), clearTimeout(s.next), gs(i, s), typeof window < "u" && (window.removeEventListener("mouseup", d), window.removeEventListener("keyup", d), window.removeEventListener("mousedown", d), window.removeEventListener("keydown", d), window.removeEventListener("change", d));
2068
+ }, i.observers.set(e, new ms(e, s)), s;
2069
2069
  }
2070
2070
  function V(n, e) {
2071
2071
  e === void 0 && (e = !1);
2072
- var s = ee.get(n.object);
2073
- te(s.value, n.object, n.patches, "", e), n.patches.length && U(s.value, n.patches);
2074
- var t = n.patches;
2075
- return t.length > 0 && (n.patches = [], n.callback && n.callback(t)), t;
2072
+ var t = ee.get(n.object);
2073
+ te(t.value, n.object, n.patches, "", e), n.patches.length && U(t.value, n.patches);
2074
+ var s = n.patches;
2075
+ return s.length > 0 && (n.patches = [], n.callback && n.callback(s)), s;
2076
2076
  }
2077
- function te(n, e, s, t, i) {
2077
+ function te(n, e, t, s, i) {
2078
2078
  if (e !== n) {
2079
2079
  typeof e.toJSON == "function" && (e = e.toJSON());
2080
2080
  for (var o = W(e), a = W(n), d = !1, l = a.length - 1; l >= 0; l--) {
2081
- var c = a[l], u = n[c];
2082
- if (q(e, c) && !(e[c] === void 0 && u !== void 0 && Array.isArray(e) === !1)) {
2083
- var f = e[c];
2084
- typeof u == "object" && u != null && typeof f == "object" && f != null && Array.isArray(u) === Array.isArray(f) ? te(u, f, s, t + "/" + _(c), i) : u !== f && (i && s.push({ op: "test", path: t + "/" + _(c), value: S(u) }), s.push({ op: "replace", path: t + "/" + _(c), value: S(f) }));
2085
- } else Array.isArray(n) === Array.isArray(e) ? (i && s.push({ op: "test", path: t + "/" + _(c), value: S(u) }), s.push({ op: "remove", path: t + "/" + _(c) }), d = !0) : (i && s.push({ op: "test", path: t, value: n }), s.push({ op: "replace", path: t, value: e }));
2081
+ var c = a[l], f = n[c];
2082
+ if (q(e, c) && !(e[c] === void 0 && f !== void 0 && Array.isArray(e) === !1)) {
2083
+ var u = e[c];
2084
+ typeof f == "object" && f != null && typeof u == "object" && u != null && Array.isArray(f) === Array.isArray(u) ? te(f, u, t, s + "/" + R(c), i) : f !== u && (i && t.push({ op: "test", path: s + "/" + R(c), value: N(f) }), t.push({ op: "replace", path: s + "/" + R(c), value: N(u) }));
2085
+ } else Array.isArray(n) === Array.isArray(e) ? (i && t.push({ op: "test", path: s + "/" + R(c), value: N(f) }), t.push({ op: "remove", path: s + "/" + R(c) }), d = !0) : (i && t.push({ op: "test", path: s, value: n }), t.push({ op: "replace", path: s, value: e }));
2086
2086
  }
2087
2087
  if (!(!d && o.length == a.length))
2088
2088
  for (var l = 0; l < o.length; l++) {
2089
2089
  var c = o[l];
2090
- !q(n, c) && e[c] !== void 0 && s.push({ op: "add", path: t + "/" + _(c), value: S(e[c]) });
2090
+ !q(n, c) && e[c] !== void 0 && t.push({ op: "add", path: s + "/" + R(c), value: N(e[c]) });
2091
2091
  }
2092
2092
  }
2093
2093
  }
2094
- function H(n, e, s) {
2095
- s === void 0 && (s = !1);
2096
- var t = [];
2097
- return te(n, e, t, "", s), t;
2094
+ function H(n, e, t) {
2095
+ t === void 0 && (t = !1);
2096
+ var s = [];
2097
+ return te(n, e, s, "", t), s;
2098
2098
  }
2099
2099
  const vs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2100
2100
  __proto__: null,
@@ -2105,85 +2105,85 @@ const vs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2105
2105
  }, Symbol.toStringTag, { value: "Module" }));
2106
2106
  Object.assign({}, fs, vs, {
2107
2107
  JsonPatchError: Ke,
2108
- deepClone: S,
2109
- escapePathComponent: _,
2108
+ deepClone: N,
2109
+ escapePathComponent: R,
2110
2110
  unescapePathComponent: Je
2111
2111
  });
2112
- function v(n, e, s) {
2113
- return { key: n, getId: (t) => e(t), getLabel: (t) => s(t) };
2112
+ function b(n, e, t) {
2113
+ return { key: n, getId: (s) => e(s), getLabel: (s) => t(s) };
2114
2114
  }
2115
2115
  const bs = [
2116
- v("roles", (n) => n.id, (n) => n.name),
2117
- v("members", (n) => n.email, (n) => `${n.name} (${n.email})`),
2118
- v("teams", (n) => n.id, (n) => `${n.id} — ${n.name}`),
2119
- v("phases", (n) => n.id, (n) => n.name),
2120
- v("milestones", (n) => n.id, (n) => n.name),
2121
- v("lbs", (n) => n.id, (n) => `${n.id} — ${n.name} (${n.type})`),
2122
- v("disciplines", (n) => n.id, (n) => `${n.id} — ${n.name}`),
2123
- v("extensions", (n) => n.id, (n) => n.id),
2124
- v("assetTypes", (n) => n.id, (n) => `${n.id} — ${n.name}`),
2125
- v("softwares", (n) => n.id, (n) => n.name),
2126
- v("objectives", (n) => n.id, (n) => n.description),
2127
- v("bimUses", (n) => n.id, (n) => n.name),
2128
- v("actions", (n) => n.id, (n) => n.name),
2129
- v("events", (n) => n.id, (n) => n.name),
2130
- v("effects", (n) => n.id, (n) => n.name),
2131
- v("automations", (n) => n.id, (n) => n.name),
2132
- v("workflows", (n) => n.id, (n) => n.name),
2133
- v("guides", (n) => n.id, (n) => n.name),
2134
- v("annexes", (n) => n.id, (n) => n.name),
2135
- v("standards", (n) => n.id, (n) => n.name),
2136
- v("lods", (n) => String(n.id), (n) => `${n.id} — ${n.name}`),
2137
- v("lois", (n) => String(n.id), (n) => `${n.id} — ${n.name}`),
2138
- v("loin", (n) => n.id, (n) => n.element),
2139
- v("deliverables", (n) => n.id, (n) => n.description ?? n.id),
2140
- v("notes", (n) => n.id, (n) => n.message),
2141
- v("env", (n) => n.key, (n) => n.key)
2116
+ b("roles", (n) => n.id, (n) => n.name),
2117
+ b("members", (n) => n.email, (n) => `${n.name} (${n.email})`),
2118
+ b("teams", (n) => n.id, (n) => `${n.id} — ${n.name}`),
2119
+ b("phases", (n) => n.id, (n) => n.name),
2120
+ b("milestones", (n) => n.id, (n) => n.name),
2121
+ b("lbs", (n) => n.id, (n) => `${n.id} — ${n.name} (${n.type})`),
2122
+ b("disciplines", (n) => n.id, (n) => `${n.id} — ${n.name}`),
2123
+ b("extensions", (n) => n.id, (n) => n.id),
2124
+ b("assetTypes", (n) => n.id, (n) => `${n.id} — ${n.name}`),
2125
+ b("softwares", (n) => n.id, (n) => n.name),
2126
+ b("objectives", (n) => n.id, (n) => n.description),
2127
+ b("bimUses", (n) => n.id, (n) => n.name),
2128
+ b("actions", (n) => n.id, (n) => n.name),
2129
+ b("events", (n) => n.id, (n) => n.name),
2130
+ b("effects", (n) => n.id, (n) => n.name),
2131
+ b("automations", (n) => n.id, (n) => n.name),
2132
+ b("workflows", (n) => n.id, (n) => n.name),
2133
+ b("guides", (n) => n.id, (n) => n.name),
2134
+ b("annexes", (n) => n.id, (n) => n.name),
2135
+ b("standards", (n) => n.id, (n) => n.name),
2136
+ b("lods", (n) => String(n.id), (n) => `${n.id} — ${n.name}`),
2137
+ b("lois", (n) => String(n.id), (n) => `${n.id} — ${n.name}`),
2138
+ b("loin", (n) => n.id, (n) => n.element),
2139
+ b("deliverables", (n) => n.id, (n) => n.description ?? n.id),
2140
+ b("notes", (n) => n.id, (n) => n.message),
2141
+ b("env", (n) => n.key, (n) => n.key)
2142
2142
  ];
2143
- function Is(n, e, s, t) {
2144
- const i = new Map(n.map((a) => [s(a), a])), o = new Map(e.map((a) => [s(a), a]));
2143
+ function Is(n, e, t, s) {
2144
+ const i = new Map(n.map((a) => [t(a), a])), o = new Map(e.map((a) => [t(a), a]));
2145
2145
  return {
2146
- added: e.filter((a) => !i.has(s(a))).map(t),
2147
- removed: n.filter((a) => !o.has(s(a))).map(t),
2146
+ added: e.filter((a) => !i.has(t(a))).map(s),
2147
+ removed: n.filter((a) => !o.has(t(a))).map(s),
2148
2148
  modified: e.filter((a) => {
2149
- const d = i.get(s(a));
2149
+ const d = i.get(t(a));
2150
2150
  return d !== void 0 && JSON.stringify(d) !== JSON.stringify(a);
2151
- }).map(t)
2151
+ }).map(s)
2152
2152
  };
2153
2153
  }
2154
2154
  function Es(n, e) {
2155
- let s = null;
2156
- JSON.stringify(n.project) !== JSON.stringify(e.project) && (s = { changed: !0, fields: Object.keys({ ...n.project, ...e.project }).filter((a) => {
2155
+ let t = null;
2156
+ JSON.stringify(n.project) !== JSON.stringify(e.project) && (t = { changed: !0, fields: Object.keys({ ...n.project, ...e.project }).filter((a) => {
2157
2157
  const d = n.project[a], l = e.project[a];
2158
2158
  return JSON.stringify(d) !== JSON.stringify(l);
2159
2159
  }) });
2160
- const t = {};
2160
+ const s = {};
2161
2161
  for (const { key: o, getId: a, getLabel: d } of bs) {
2162
- const l = e[o] ?? [], c = n[o] ?? [], u = Is(l, c, a, d);
2163
- (u.added.length || u.removed.length || u.modified.length) && (t[o] = u);
2162
+ const l = e[o] ?? [], c = n[o] ?? [], f = Is(l, c, a, d);
2163
+ (f.added.length || f.removed.length || f.modified.length) && (s[o] = f);
2164
2164
  }
2165
- const i = [...s ? ["project"] : [], ...Object.keys(t)];
2166
- return { project: s, sections: t, changedKeys: i };
2165
+ const i = [...t ? ["project"] : [], ...Object.keys(s)];
2166
+ return { project: t, sections: s, changedKeys: i };
2167
2167
  }
2168
- class I {
2169
- constructor(e, s, t) {
2170
- this.getBep = e, this.setBep = s, this.getZip = t;
2168
+ class S {
2169
+ constructor(e, t, s) {
2170
+ this.getBep = e, this.setBep = t, this.getZip = s;
2171
2171
  }
2172
2172
  getBep;
2173
2173
  setBep;
2174
2174
  getZip;
2175
2175
  // ─── Version helpers ──────────────────────────────────────────────────────
2176
2176
  static parseVersion(e) {
2177
- const [s, t] = e.split(".").map(Number);
2178
- return { major: s, minor: t };
2177
+ const [t, s] = e.split(".").map(Number);
2178
+ return { major: t, minor: s };
2179
2179
  }
2180
- static compareVersions(e, s) {
2181
- const t = I.parseVersion(e), i = I.parseVersion(s);
2182
- return t.major !== i.major ? t.major - i.major : t.minor - i.minor;
2180
+ static compareVersions(e, t) {
2181
+ const s = S.parseVersion(e), i = S.parseVersion(t);
2182
+ return s.major !== i.major ? s.major - i.major : s.minor - i.minor;
2183
2183
  }
2184
- static bumpVersion(e, s) {
2185
- const [t, i] = e.split(".").map(Number);
2186
- return s === "version" ? `${t + 1}.0` : `${t}.${i + 1}`;
2184
+ static bumpVersion(e, t) {
2185
+ const [s, i] = e.split(".").map(Number);
2186
+ return t === "version" ? `${s + 1}.0` : `${s}.${i + 1}`;
2187
2187
  }
2188
2188
  // ─── Zip helpers ──────────────────────────────────────────────────────────
2189
2189
  async readChangelog() {
@@ -2192,25 +2192,25 @@ class I {
2192
2192
  }
2193
2193
  async readBaseline() {
2194
2194
  const e = this.getZip().file("baseline/bep.json");
2195
- return e ? $(JSON.parse(await e.async("string"))) : null;
2195
+ return e ? A(JSON.parse(await e.async("string"))) : null;
2196
2196
  }
2197
2197
  // ─── Standards versioning helpers ─────────────────────────────────────────
2198
2198
  /**
2199
2199
  * At commit time: for each standard whose .md content changed since the last
2200
2200
  * snapshot, saves changelog/standards/{id}/v{version}.md.
2201
2201
  */
2202
- async snapshotChangedStandards(e, s) {
2203
- const t = this.getZip();
2202
+ async snapshotChangedStandards(e, t) {
2203
+ const s = this.getZip();
2204
2204
  for (const i of e.standards) {
2205
- const o = t.file(i.contentPath);
2205
+ const o = s.file(i.contentPath);
2206
2206
  if (!o) continue;
2207
- const a = await o.async("string"), d = `changelog/standards/${i.id}/`, l = Object.keys(t.files).filter((u) => u.startsWith(d) && u.endsWith(".md") && u.slice(d.length).startsWith("v")).map((u) => u.slice(d.length + 1, -3));
2207
+ const a = await o.async("string"), d = `changelog/standards/${i.id}/`, l = Object.keys(s.files).filter((f) => f.startsWith(d) && f.endsWith(".md") && f.slice(d.length).startsWith("v")).map((f) => f.slice(d.length + 1, -3));
2208
2208
  let c = null;
2209
2209
  if (l.length > 0) {
2210
- const u = l.sort((m, p) => I.compareVersions(p, m))[0], f = t.file(`${d}v${u}.md`);
2211
- f && (c = await f.async("string"));
2210
+ const f = l.sort((m, p) => S.compareVersions(p, m))[0], u = s.file(`${d}v${f}.md`);
2211
+ u && (c = await u.async("string"));
2212
2212
  }
2213
- c !== a && t.file(`${d}v${s}.md`, a);
2213
+ c !== a && s.file(`${d}v${t}.md`, a);
2214
2214
  }
2215
2215
  }
2216
2216
  /**
@@ -2218,12 +2218,12 @@ class I {
2218
2218
  * discard() can restore the .md files to their last committed state.
2219
2219
  */
2220
2220
  async snapshotBaseStandards(e) {
2221
- const s = this.getZip();
2222
- for (const t of e.standards) {
2223
- const i = s.file(t.contentPath);
2221
+ const t = this.getZip();
2222
+ for (const s of e.standards) {
2223
+ const i = t.file(s.contentPath);
2224
2224
  if (!i) continue;
2225
2225
  const o = await i.async("string");
2226
- s.file(`baseline/standards/${t.id}.md`, o);
2226
+ t.file(`baseline/standards/${s.id}.md`, o);
2227
2227
  }
2228
2228
  }
2229
2229
  /**
@@ -2231,13 +2231,13 @@ class I {
2231
2231
  * Finds the latest snapshot in changelog/standards/{id}/ with version ≤ target.
2232
2232
  * Falls back to the current file if no snapshot exists (content never changed).
2233
2233
  */
2234
- async resolveStandardContent(e, s) {
2235
- const t = this.getZip(), i = `changelog/standards/${e.id}/`, o = Object.keys(t.files).filter((d) => d.startsWith(i) && d.endsWith(".md") && d.slice(i.length).startsWith("v")).map((d) => d.slice(i.length + 1, -3)).filter((d) => I.compareVersions(d, s) <= 0).sort((d, l) => I.compareVersions(l, d));
2234
+ async resolveStandardContent(e, t) {
2235
+ const s = this.getZip(), i = `changelog/standards/${e.id}/`, o = Object.keys(s.files).filter((d) => d.startsWith(i) && d.endsWith(".md") && d.slice(i.length).startsWith("v")).map((d) => d.slice(i.length + 1, -3)).filter((d) => S.compareVersions(d, t) <= 0).sort((d, l) => S.compareVersions(l, d));
2236
2236
  if (o.length === 0) {
2237
- const d = t.file(e.contentPath);
2237
+ const d = s.file(e.contentPath);
2238
2238
  return d ? d.async("string") : null;
2239
2239
  }
2240
- const a = t.file(`${i}v${o[0]}.md`);
2240
+ const a = s.file(`${i}v${o[0]}.md`);
2241
2241
  return a ? a.async("string") : null;
2242
2242
  }
2243
2243
  // ─── Public API ───────────────────────────────────────────────────────────
@@ -2247,42 +2247,42 @@ class I {
2247
2247
  async list() {
2248
2248
  return (await this.readChangelog())?.versions ?? [];
2249
2249
  }
2250
- async commit(e, s = !1) {
2251
- const t = this.getZip(), i = this.getBep(), o = await this.readChangelog(), a = await this.readBaseline(), d = (/* @__PURE__ */ new Date()).toISOString();
2250
+ async commit(e, t = !1) {
2251
+ const s = this.getZip(), i = this.getBep(), o = await this.readChangelog(), a = await this.readBaseline(), d = (/* @__PURE__ */ new Date()).toISOString();
2252
2252
  if (!a) throw new Error("No baseline found — create a BEP with Bep.create() or open one with Bep.open()");
2253
2253
  if (e.type === "version") {
2254
- const g = e.approvedBy.filter((h) => !i.members.some((y) => y.email === h));
2255
- if (g.length) throw new Error(`Members not found: ${g.join(", ")}`);
2254
+ const w = e.approvedBy.filter((h) => !i.members.some((v) => v.email === h));
2255
+ if (w.length) throw new Error(`Members not found: ${w.join(", ")}`);
2256
2256
  }
2257
- if (!s && !await this.hasPendingChanges())
2257
+ if (!t && !await this.hasPendingChanges())
2258
2258
  throw new Error("No pending changes since last commit");
2259
- const l = o?.current ?? "0.0", c = I.bumpVersion(l, e.type), u = `changelog/v${c}.diff.json`, f = H(i, a), m = e.type === "patch" ? { version: c, type: "patch", date: d, author: e.author, description: e.description, diff: u } : { version: c, type: "version", date: d, author: e.author, description: e.description, approvedBy: e.approvedBy, diff: u }, p = {
2259
+ const l = o?.current ?? "0.0", c = S.bumpVersion(l, e.type), f = `changelog/v${c}.diff.json`, u = H(i, a), m = e.type === "patch" ? { version: c, type: "patch", date: d, author: e.author, description: e.description, diff: f } : { version: c, type: "version", date: d, author: e.author, description: e.description, approvedBy: e.approvedBy, diff: f }, p = {
2260
2260
  current: c,
2261
2261
  versions: [...o?.versions ?? [], m]
2262
2262
  };
2263
- return t.file(u, JSON.stringify(f, null, 2)), await this.snapshotChangedStandards(i, c), t.file("baseline/bep.json", JSON.stringify(i, null, 2)), await this.snapshotBaseStandards(i), t.file("changelog.json", JSON.stringify(p, null, 2)), m;
2263
+ return s.file(f, JSON.stringify(u, null, 2)), await this.snapshotChangedStandards(i, c), s.file("baseline/bep.json", JSON.stringify(i, null, 2)), await this.snapshotBaseStandards(i), s.file("changelog.json", JSON.stringify(p, null, 2)), m;
2264
2264
  }
2265
2265
  /**
2266
2266
  * Reconstructs the BEP state at the given version (read-only).
2267
2267
  * Applies inverse diffs backward from the current state.
2268
2268
  */
2269
2269
  async get(e) {
2270
- const s = await this.readChangelog();
2271
- if (!s) throw new Error("No changelog found — call commit() first");
2272
- if (e === s.current)
2270
+ const t = await this.readChangelog();
2271
+ if (!t) throw new Error("No changelog found — call commit() first");
2272
+ if (e === t.current)
2273
2273
  return JSON.parse(JSON.stringify(this.getBep()));
2274
- const t = s.versions.findIndex((a) => a.version === e);
2275
- if (t === -1) {
2274
+ const s = t.versions.findIndex((a) => a.version === e);
2275
+ if (s === -1) {
2276
2276
  const a = this.getZip().file(`changelog/v${e}.json`);
2277
2277
  if (!a) throw new Error(`Version not found: ${e}`);
2278
- return $(JSON.parse(await a.async("string")));
2278
+ return A(JSON.parse(await a.async("string")));
2279
2279
  }
2280
- if (s.versions[t].diff === null) {
2280
+ if (t.versions[s].diff === null) {
2281
2281
  const a = this.getZip().file(`changelog/v${e}.json`);
2282
2282
  if (!a) throw new Error(`Missing terminus: changelog/v${e}.json`);
2283
- return $(JSON.parse(await a.async("string")));
2283
+ return A(JSON.parse(await a.async("string")));
2284
2284
  }
2285
- const i = s.versions.filter((a) => I.compareVersions(a.version, e) > 0).sort((a, d) => I.compareVersions(d.version, a.version)), o = JSON.parse(JSON.stringify(this.getBep()));
2285
+ const i = t.versions.filter((a) => S.compareVersions(a.version, e) > 0).sort((a, d) => S.compareVersions(d.version, a.version)), o = JSON.parse(JSON.stringify(this.getBep()));
2286
2286
  for (const a of i) {
2287
2287
  if (!a.diff) break;
2288
2288
  const d = this.getZip().file(a.diff);
@@ -2290,70 +2290,70 @@ class I {
2290
2290
  const l = JSON.parse(await d.async("string"));
2291
2291
  U(o, l);
2292
2292
  }
2293
- return $(o);
2293
+ return A(o);
2294
2294
  }
2295
2295
  /** Returns the RFC 6902 diff and standards summary between two versions. */
2296
- async compare(e, s) {
2297
- const [t, i, o] = await Promise.all([
2296
+ async compare(e, t) {
2297
+ const [s, i, o] = await Promise.all([
2298
2298
  this.get(e),
2299
- this.get(s),
2299
+ this.get(t),
2300
2300
  this.readChangelog()
2301
- ]), a = H(t, i), d = new Set(t.standards.map((h) => h.id)), l = new Set(i.standards.map((h) => h.id)), c = i.standards.filter((h) => !d.has(h.id)).map((h) => ({ id: h.id, name: h.name })), u = t.standards.filter((h) => !l.has(h.id)).map((h) => ({ id: h.id, name: h.name })), m = (o?.versions ?? []).filter((h) => I.compareVersions(h.version, e) > 0 && I.compareVersions(h.version, s) <= 0).map((h) => h.version), p = this.getZip(), g = (await Promise.all(
2301
+ ]), a = H(s, i), d = new Set(s.standards.map((h) => h.id)), l = new Set(i.standards.map((h) => h.id)), c = i.standards.filter((h) => !d.has(h.id)).map((h) => ({ id: h.id, name: h.name })), f = s.standards.filter((h) => !l.has(h.id)).map((h) => ({ id: h.id, name: h.name })), m = (o?.versions ?? []).filter((h) => S.compareVersions(h.version, e) > 0 && S.compareVersions(h.version, t) <= 0).map((h) => h.version), p = this.getZip(), w = (await Promise.all(
2302
2302
  i.standards.filter((h) => d.has(h.id)).map(async (h) => {
2303
- const y = (await Promise.all(
2304
- m.map(async (N) => p.file(`changelog/standards/${h.id}/v${N}.md`) !== null ? N : null)
2305
- )).filter((N) => N !== null);
2306
- return y.length > 0 ? { id: h.id, name: h.name, changedIn: y } : null;
2303
+ const v = (await Promise.all(
2304
+ m.map(async (k) => p.file(`changelog/standards/${h.id}/v${k}.md`) !== null ? k : null)
2305
+ )).filter((k) => k !== null);
2306
+ return v.length > 0 ? { id: h.id, name: h.name, changedIn: v } : null;
2307
2307
  })
2308
2308
  )).filter((h) => h !== null);
2309
- return { diff: a, standards: { added: c, removed: u, contentModified: g } };
2309
+ return { diff: a, standards: { added: c, removed: f, contentModified: w } };
2310
2310
  }
2311
2311
  /**
2312
2312
  * Resets in-memory BEP and restores .md files to the last committed baseline.
2313
2313
  * Standards added since the baseline have their .md deleted.
2314
2314
  */
2315
2315
  async discard() {
2316
- const e = this.getZip(), s = await this.readBaseline();
2317
- if (!s) throw new Error("No baseline found — call commit() first");
2318
- const t = new Set(s.standards.map((i) => i.id));
2316
+ const e = this.getZip(), t = await this.readBaseline();
2317
+ if (!t) throw new Error("No baseline found — call commit() first");
2318
+ const s = new Set(t.standards.map((i) => i.id));
2319
2319
  for (const i of this.getBep().standards)
2320
- t.has(i.id) || e.remove(i.contentPath);
2321
- for (const i of s.standards) {
2320
+ s.has(i.id) || e.remove(i.contentPath);
2321
+ for (const i of t.standards) {
2322
2322
  const o = e.file(`baseline/standards/${i.id}.md`);
2323
2323
  if (!o) continue;
2324
2324
  const a = await o.async("string");
2325
2325
  e.file(i.contentPath, a);
2326
2326
  }
2327
- this.setBep(s);
2327
+ this.setBep(t);
2328
2328
  }
2329
2329
  /**
2330
2330
  * Non-destructive revert: restores BEP state and .md files to a historical
2331
2331
  * version and immediately commits it as a new version.
2332
2332
  */
2333
- async revert(e, s) {
2334
- const t = this.getZip(), i = await this.get(e);
2333
+ async revert(e, t) {
2334
+ const s = this.getZip(), i = await this.get(e);
2335
2335
  for (const o of i.standards) {
2336
2336
  const a = await this.resolveStandardContent(o, e);
2337
- a !== null && t.file(o.contentPath, a);
2337
+ a !== null && s.file(o.contentPath, a);
2338
2338
  }
2339
- return this.setBep(i), this.commit(s);
2339
+ return this.setBep(i), this.commit(t);
2340
2340
  }
2341
2341
  /**
2342
2342
  * Returns a structured diff of the current BEP state vs the last committed baseline.
2343
2343
  * Includes .md content changes for standards (added, removed, modified, content-modified).
2344
2344
  */
2345
2345
  async status() {
2346
- const e = this.getZip(), s = await this.readBaseline();
2347
- if (!s) return { hasPendingChanges: !1, project: null, sections: {}, changedKeys: [], standards: [] };
2348
- const t = this.getBep(), i = Es(t, s), o = [], a = new Map(s.standards.map((c) => [c.id, c])), d = new Set(t.standards.map((c) => c.id));
2349
- for (const c of t.standards)
2346
+ const e = this.getZip(), t = await this.readBaseline();
2347
+ if (!t) return { hasPendingChanges: !1, project: null, sections: {}, changedKeys: [], standards: [] };
2348
+ const s = this.getBep(), i = Es(s, t), o = [], a = new Map(t.standards.map((c) => [c.id, c])), d = new Set(s.standards.map((c) => c.id));
2349
+ for (const c of s.standards)
2350
2350
  if (!a.has(c.id))
2351
2351
  o.push({ id: c.id, name: c.name, status: "added" });
2352
2352
  else {
2353
- const u = JSON.stringify(a.get(c.id)) !== JSON.stringify(c), f = e.file(`baseline/standards/${c.id}.md`), m = e.file(c.contentPath), p = f ? await f.async("string") : "", g = m ? await m.async("string") : "";
2354
- u ? o.push({ id: c.id, name: c.name, status: "modified" }) : p !== g && o.push({ id: c.id, name: c.name, status: "content-modified" });
2353
+ const f = JSON.stringify(a.get(c.id)) !== JSON.stringify(c), u = e.file(`baseline/standards/${c.id}.md`), m = e.file(c.contentPath), p = u ? await u.async("string") : "", w = m ? await m.async("string") : "";
2354
+ f ? o.push({ id: c.id, name: c.name, status: "modified" }) : p !== w && o.push({ id: c.id, name: c.name, status: "content-modified" });
2355
2355
  }
2356
- for (const c of s.standards)
2356
+ for (const c of t.standards)
2357
2357
  d.has(c.id) || o.push({ id: c.id, name: c.name, status: "removed" });
2358
2358
  return { hasPendingChanges: i.changedKeys.length > 0 || o.length > 0, standards: o, ...i };
2359
2359
  }
@@ -2363,19 +2363,19 @@ class I {
2363
2363
  }
2364
2364
  /** Returns all versions sorted ascending, with author/approvedBy resolved to { email, name } objects. */
2365
2365
  async listResolved() {
2366
- const [e, s] = await Promise.all([this.list(), this.current()]), t = this.getBep().members;
2367
- return e.sort((i, o) => I.compareVersions(i.version, o.version)).map((i) => ({
2366
+ const [e, t] = await Promise.all([this.list(), this.current()]), s = this.getBep().members;
2367
+ return e.sort((i, o) => S.compareVersions(i.version, o.version)).map((i) => ({
2368
2368
  version: i.version,
2369
2369
  type: i.type,
2370
2370
  date: i.date,
2371
2371
  description: i.description,
2372
2372
  diff: i.diff,
2373
- isCurrent: i.version === s,
2374
- author: i.author ? { email: i.author, name: t.find((o) => o.email === i.author)?.name ?? null } : null,
2373
+ isCurrent: i.version === t,
2374
+ author: i.author ? { email: i.author, name: s.find((o) => o.email === i.author)?.name ?? null } : null,
2375
2375
  ...i.type === "version" ? {
2376
2376
  approvedBy: i.approvedBy.map((o) => ({
2377
2377
  email: o,
2378
- name: t.find((a) => a.email === o)?.name ?? null
2378
+ name: s.find((a) => a.email === o)?.name ?? null
2379
2379
  }))
2380
2380
  } : {}
2381
2381
  }));
@@ -2384,35 +2384,35 @@ class I {
2384
2384
  * Resolves the markdown content of a standard at a specific historical version.
2385
2385
  * Returns null if the standard did not exist at that version.
2386
2386
  */
2387
- async getStandardContent(e, s) {
2388
- const i = (await this.get(s)).standards.find((o) => o.id === e);
2389
- return i ? this.resolveStandardContent(i, s) : null;
2387
+ async getStandardContent(e, t) {
2388
+ const i = (await this.get(t)).standards.find((o) => o.id === e);
2389
+ return i ? this.resolveStandardContent(i, t) : null;
2390
2390
  }
2391
2391
  /**
2392
2392
  * ⚠️ Destructive: resets the BEP to a historical version and permanently
2393
2393
  * deletes all subsequent diffs, standard snapshots, and changelog entries.
2394
2394
  */
2395
2395
  async reset(e) {
2396
- const s = this.getZip(), t = await this.readChangelog();
2397
- if (!t) throw new Error("No changelog found");
2398
- const i = t.versions.find((c) => c.version === e), o = !!this.getZip().file(`changelog/v${e}.json`);
2396
+ const t = this.getZip(), s = await this.readChangelog();
2397
+ if (!s) throw new Error("No changelog found");
2398
+ const i = s.versions.find((c) => c.version === e), o = !!this.getZip().file(`changelog/v${e}.json`);
2399
2399
  if (!i && !o)
2400
2400
  throw new Error(`Version not found: ${e}`);
2401
- if (e === t.current)
2401
+ if (e === s.current)
2402
2402
  throw new Error(`Already at version ${e}`);
2403
- const a = t.versions.filter((c) => I.compareVersions(c.version, e) > 0), d = await this.get(e);
2403
+ const a = s.versions.filter((c) => S.compareVersions(c.version, e) > 0), d = await this.get(e);
2404
2404
  for (const c of d.standards) {
2405
- const u = await this.resolveStandardContent(c, e);
2406
- u !== null && s.file(c.contentPath, u);
2405
+ const f = await this.resolveStandardContent(c, e);
2406
+ f !== null && t.file(c.contentPath, f);
2407
2407
  }
2408
2408
  await this.snapshotBaseStandards(d);
2409
2409
  for (const c of a)
2410
- c.diff && s.remove(c.diff), Object.keys(s.files).filter((u) => u.startsWith("changelog/standards/") && u.includes(`/v${c.version}.md`)).forEach((u) => s.remove(u));
2410
+ c.diff && t.remove(c.diff), Object.keys(t.files).filter((f) => f.startsWith("changelog/standards/") && f.includes(`/v${c.version}.md`)).forEach((f) => t.remove(f));
2411
2411
  const l = JSON.stringify(d, null, 2);
2412
- s.file("changelog.json", JSON.stringify({
2412
+ t.file("changelog.json", JSON.stringify({
2413
2413
  current: e,
2414
- versions: t.versions.filter((c) => I.compareVersions(c.version, e) <= 0)
2415
- }, null, 2)), s.file("bep.json", l), s.file("baseline/bep.json", l), this.setBep(d);
2414
+ versions: s.versions.filter((c) => S.compareVersions(c.version, e) <= 0)
2415
+ }, null, 2)), t.file("bep.json", l), t.file("baseline/bep.json", l), this.setBep(d);
2416
2416
  }
2417
2417
  /**
2418
2418
  * ⚠️ Destructive: collapses all history into a single new terminus version.
@@ -2420,24 +2420,24 @@ class I {
2420
2420
  * newBase must be in X.0 format and greater than the current version.
2421
2421
  */
2422
2422
  async squash(e) {
2423
- const s = this.getZip(), t = await this.readChangelog();
2424
- if (!t) throw new Error("No changelog found");
2423
+ const t = this.getZip(), s = await this.readChangelog();
2424
+ if (!s) throw new Error("No changelog found");
2425
2425
  if (!/^\d+\.0$/.test(e.newBase))
2426
2426
  throw new Error(`newBase must be in X.0 format (e.g. "2.0"), got "${e.newBase}"`);
2427
- if (I.compareVersions(e.newBase, t.current) <= 0)
2428
- throw new Error(`newBase "${e.newBase}" must be greater than current version "${t.current}"`);
2427
+ if (S.compareVersions(e.newBase, s.current) <= 0)
2428
+ throw new Error(`newBase "${e.newBase}" must be greater than current version "${s.current}"`);
2429
2429
  const i = this.getBep(), o = e.approvedBy.filter((d) => !i.members.some((l) => l.email === d));
2430
2430
  if (o.length) throw new Error(`Members not found: ${o.join(", ")}`);
2431
- for (const d of t.versions)
2432
- d.diff && s.remove(d.diff);
2433
- Object.keys(s.files).filter((d) => /^changelog\/v[\d.]+\.json$/.test(d)).forEach((d) => s.remove(d)), Object.keys(s.files).filter((d) => d.startsWith("changelog/standards/") && d.endsWith(".md")).forEach((d) => s.remove(d)), s.file(`changelog/v${e.newBase}.json`, JSON.stringify(i, null, 2));
2431
+ for (const d of s.versions)
2432
+ d.diff && t.remove(d.diff);
2433
+ Object.keys(t.files).filter((d) => /^changelog\/v[\d.]+\.json$/.test(d)).forEach((d) => t.remove(d)), Object.keys(t.files).filter((d) => d.startsWith("changelog/standards/") && d.endsWith(".md")).forEach((d) => t.remove(d)), t.file(`changelog/v${e.newBase}.json`, JSON.stringify(i, null, 2));
2434
2434
  for (const d of i.standards) {
2435
- const l = s.file(d.contentPath);
2435
+ const l = t.file(d.contentPath);
2436
2436
  if (!l) continue;
2437
2437
  const c = await l.async("string");
2438
- s.file(`changelog/standards/${d.id}/v${e.newBase}.md`, c);
2438
+ t.file(`changelog/standards/${d.id}/v${e.newBase}.md`, c);
2439
2439
  }
2440
- s.file("baseline/bep.json", JSON.stringify(i, null, 2)), await this.snapshotBaseStandards(i);
2440
+ t.file("baseline/bep.json", JSON.stringify(i, null, 2)), await this.snapshotBaseStandards(i);
2441
2441
  const a = {
2442
2442
  version: e.newBase,
2443
2443
  type: "version",
@@ -2447,12 +2447,12 @@ class I {
2447
2447
  approvedBy: e.approvedBy,
2448
2448
  diff: null
2449
2449
  };
2450
- return s.file("changelog.json", JSON.stringify({ current: e.newBase, versions: [a] }, null, 2)), a;
2450
+ return t.file("changelog.json", JSON.stringify({ current: e.newBase, versions: [a] }, null, 2)), a;
2451
2451
  }
2452
2452
  }
2453
2453
  class Z {
2454
- constructor(e, s) {
2455
- this.path = e, this.getZip = s;
2454
+ constructor(e, t) {
2455
+ this.path = e, this.getZip = t;
2456
2456
  }
2457
2457
  path;
2458
2458
  getZip;
@@ -2466,44 +2466,44 @@ class Z {
2466
2466
  this.getZip().file(this.path, e);
2467
2467
  }
2468
2468
  }
2469
- const Ss = 10;
2470
- function Ns(n, e) {
2471
- const s = e[n.field];
2469
+ const ks = 10;
2470
+ function Ss(n, e) {
2471
+ const t = e[n.field];
2472
2472
  switch (n.operator) {
2473
2473
  case "exists":
2474
- return s != null;
2474
+ return t != null;
2475
2475
  case "eq":
2476
- return s === n.value;
2476
+ return t === n.value;
2477
2477
  case "neq":
2478
- return s !== n.value;
2478
+ return t !== n.value;
2479
2479
  case "gt":
2480
- return typeof s == "number" && typeof n.value == "number" && s > n.value;
2480
+ return typeof t == "number" && typeof n.value == "number" && t > n.value;
2481
2481
  case "lt":
2482
- return typeof s == "number" && typeof n.value == "number" && s < n.value;
2482
+ return typeof t == "number" && typeof n.value == "number" && t < n.value;
2483
2483
  case "contains":
2484
- return typeof s == "string" && typeof n.value == "string" || Array.isArray(s) ? s.includes(n.value) : !1;
2484
+ return typeof t == "string" && typeof n.value == "string" || Array.isArray(t) ? t.includes(n.value) : !1;
2485
2485
  default:
2486
2486
  return !1;
2487
2487
  }
2488
2488
  }
2489
- function ks(n, e, s, t) {
2490
- const o = n.workflows.find((m) => m.id === s)?.diagram.nodes[e];
2489
+ function Ns(n, e, t, s) {
2490
+ const o = n.workflows.find((m) => m.id === t)?.diagram.nodes[e];
2491
2491
  if (!o || o.type !== "process") return !0;
2492
2492
  const a = !!(o.responsibleRoleIds?.length || o.responsibleTeamIds?.length || o.responsibleEmails?.length), d = !!(o.accountableRoleIds?.length || o.accountableTeamIds?.length || o.accountableEmails?.length);
2493
2493
  if (!a && !d) return !0;
2494
- const c = n.members.find((m) => m.email === t)?.roleId, u = new Set(n.teams.filter((m) => (m.memberEmails ?? []).includes(t)).map((m) => m.id)), f = (m, p, g) => {
2495
- if (g?.includes(t)) return !0;
2496
- const h = !!m?.length, y = !!p?.length;
2497
- return y && h ? !!c && m.includes(c) && p.some((N) => u.has(N)) : y ? p.some((N) => u.has(N)) : h ? !!c && m.includes(c) : !1;
2494
+ const c = n.members.find((m) => m.email === s)?.roleId, f = new Set(n.teams.filter((m) => (m.memberEmails ?? []).includes(s)).map((m) => m.id)), u = (m, p, w) => {
2495
+ if (w?.includes(s)) return !0;
2496
+ const h = !!m?.length, v = !!p?.length;
2497
+ return v && h ? !!c && m.includes(c) && p.some((k) => f.has(k)) : v ? p.some((k) => f.has(k)) : h ? !!c && m.includes(c) : !1;
2498
2498
  };
2499
- return a && f(o.responsibleRoleIds, o.responsibleTeamIds, o.responsibleEmails) || d && f(o.accountableRoleIds, o.accountableTeamIds, o.accountableEmails);
2499
+ return a && u(o.responsibleRoleIds, o.responsibleTeamIds, o.responsibleEmails) || d && u(o.accountableRoleIds, o.accountableTeamIds, o.accountableEmails);
2500
2500
  }
2501
2501
  const _s = { string: "string", number: "number", boolean: "boolean" };
2502
- function Rs(n, e, s) {
2503
- const t = n.events.find((d) => d.id === e);
2504
- if (!t?.payload?.length) return [];
2505
- const i = [], o = s ?? {};
2506
- for (const d of t.payload) {
2502
+ function $s(n, e, t) {
2503
+ const s = n.events.find((d) => d.id === e);
2504
+ if (!s?.payload?.length) return [];
2505
+ const i = [], o = t ?? {};
2506
+ for (const d of s.payload) {
2507
2507
  const l = o[d.key];
2508
2508
  if (l == null)
2509
2509
  d.required && i.push({ field: d.key, reason: "missing" });
@@ -2518,100 +2518,99 @@ function Rs(n, e, s) {
2518
2518
  }
2519
2519
  }
2520
2520
  }
2521
- const a = new Set(t.payload.map((d) => d.key));
2521
+ const a = new Set(s.payload.map((d) => d.key));
2522
2522
  for (const d of Object.keys(o))
2523
2523
  a.has(d) || i.push({ field: d, reason: "unknown_field" });
2524
2524
  return i;
2525
2525
  }
2526
- function Ts(n, e) {
2526
+ function Rs(n, e) {
2527
2527
  return !(!("triggerEventId" in n) || n.triggerEventId !== e.eventId);
2528
2528
  }
2529
- function $s(n, e, s, t, i) {
2530
- const o = n.workflows.find((f) => f.id === e);
2531
- if (!o) return null;
2532
- const a = Object.keys(o.diagram.nodes).find(
2533
- (f) => o.diagram.nodes[f].type === "start"
2529
+ function Ts(n, e, t, s) {
2530
+ const i = n.workflows.find((f) => f.id === e);
2531
+ if (!i) return null;
2532
+ const o = Object.keys(i.diagram.nodes).find(
2533
+ (f) => i.diagram.nodes[f].type === "start"
2534
2534
  );
2535
- if (!a) return null;
2536
- const d = Object.entries(o.diagram.edges).find(([, f]) => f.from === a), l = d?.[1].to ?? a, c = d ? (d[1].effectIds ?? []).map((f) => ({ effectId: f, fromEdgeId: d[0], triggerPayload: {} })) : [], u = (/* @__PURE__ */ new Date()).toISOString();
2535
+ if (!o) return null;
2536
+ const a = Object.entries(i.diagram.edges).find(([, f]) => f.from === o), d = a?.[1].to ?? o, l = a ? (a[1].effectIds ?? []).map((f) => ({ effectId: f, fromEdgeId: a[0], triggerPayload: {} })) : [], c = (/* @__PURE__ */ new Date()).toISOString();
2537
2537
  return {
2538
2538
  instance: {
2539
2539
  id: globalThis.crypto.randomUUID(),
2540
2540
  workflowId: e,
2541
- bepVersion: i,
2542
- trackedAsset: s,
2543
- currentNodeId: l,
2541
+ trackedAsset: t,
2542
+ currentNodeId: d,
2544
2543
  status: "active",
2545
2544
  history: [],
2546
- createdAt: u,
2547
- updatedAt: u,
2548
- initiatedBy: t
2545
+ createdAt: c,
2546
+ updatedAt: c,
2547
+ initiatedBy: s
2549
2548
  },
2550
- startEffects: c
2549
+ startEffects: l
2551
2550
  };
2552
2551
  }
2553
- function J(n, e, s, t) {
2552
+ function J(n, e, t, s) {
2554
2553
  if (e.status !== "active")
2555
2554
  return { ok: !1, error: "INSTANCE_NOT_ACTIVE" };
2556
- if (!t?.skipRaci && !ks(n, e.currentNodeId, e.workflowId, s.actor))
2555
+ if (!s?.skipRaci && !Ns(n, e.currentNodeId, e.workflowId, t.actor))
2557
2556
  return { ok: !1, error: "UNAUTHORIZED" };
2558
- const i = n.workflows.find((E) => E.id === e.workflowId);
2557
+ const i = n.workflows.find((I) => I.id === e.workflowId);
2559
2558
  if (!i) return { ok: !1, error: "NO_MATCHING_EDGE" };
2560
2559
  const { nodes: o, edges: a } = i.diagram;
2561
2560
  let d = e.currentNodeId;
2562
- const l = [], c = [], u = [], f = Object.entries(a).filter(
2563
- ([, E]) => E.from === d && Ts(E, s)
2561
+ const l = [], c = [], f = [], u = Object.entries(a).filter(
2562
+ ([, I]) => I.from === d && Rs(I, t)
2564
2563
  );
2565
- if (f.length === 0) return { ok: !1, error: "NO_MATCHING_EDGE" };
2566
- if (f.length > 1) return { ok: !1, error: "AMBIGUOUS_TRANSITION" };
2567
- const [m, p] = f[0];
2564
+ if (u.length === 0) return { ok: !1, error: "NO_MATCHING_EDGE" };
2565
+ if (u.length > 1) return { ok: !1, error: "AMBIGUOUS_TRANSITION" };
2566
+ const [m, p] = u[0];
2568
2567
  if ("triggerEventId" in p) {
2569
- const E = Rs(n, p.triggerEventId, s.payload);
2570
- if (E.length > 0) return { ok: !1, error: "INVALID_PAYLOAD", payloadErrors: E };
2568
+ const I = $s(n, p.triggerEventId, t.payload);
2569
+ if (I.length > 0) return { ok: !1, error: "INVALID_PAYLOAD", payloadErrors: I };
2571
2570
  }
2572
- l.push(re(m, d, p.to, s)), c.push(...(p.effectIds ?? []).map((E) => ({ effectId: E, fromEdgeId: m, triggerPayload: s.payload ?? {} }))), u.push({ edgeId: m, fromNodeId: d, toNodeId: p.to }), d = p.to;
2573
- let g = 0;
2571
+ l.push(re(m, d, p.to, t)), c.push(...(p.effectIds ?? []).map((I) => ({ effectId: I, fromEdgeId: m, triggerPayload: t.payload ?? {} }))), f.push({ edgeId: m, fromNodeId: d, toNodeId: p.to }), d = p.to;
2572
+ let w = 0;
2574
2573
  for (; o[d]?.type === "decision"; ) {
2575
- if (++g > Ss) return { ok: !1, error: "DECISION_LOOP" };
2576
- const E = Object.entries(a).filter(([, O]) => O.from !== d || !("guard" in O) ? !1 : Ns(O.guard, s.payload ?? {}));
2577
- if (E.length === 0) break;
2578
- const [k, T] = E[0];
2579
- l.push(re(k, d, T.to, s, !0)), c.push(...(T.effectIds ?? []).map((O) => ({ effectId: O, fromEdgeId: k, triggerPayload: s.payload ?? {} }))), u.push({ edgeId: k, fromNodeId: d, toNodeId: T.to }), d = T.to;
2574
+ if (++w > ks) return { ok: !1, error: "DECISION_LOOP" };
2575
+ const I = Object.entries(a).filter(([, B]) => B.from !== d || !("guard" in B) ? !1 : Ss(B.guard, t.payload ?? {}));
2576
+ if (I.length === 0) break;
2577
+ const [_, $] = I[0];
2578
+ l.push(re(_, d, $.to, t, !0)), c.push(...($.effectIds ?? []).map((B) => ({ effectId: B, fromEdgeId: _, triggerPayload: t.payload ?? {} }))), f.push({ edgeId: _, fromNodeId: d, toNodeId: $.to }), d = $.to;
2580
2579
  }
2581
- const h = o[d], y = h?.type === "end" ? "completed" : "active", N = {
2580
+ const h = o[d], v = h?.type === "end" ? "completed" : "active", k = {
2582
2581
  ...e,
2583
2582
  currentNodeId: d,
2584
- status: y,
2583
+ status: v,
2585
2584
  history: [...e.history, ...l],
2586
2585
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
2587
- }, M = h?.type === "automation" && h.automationId ? { nodeId: d, automationId: h.automationId, triggerPayload: s.payload ?? {} } : void 0;
2588
- return { ok: !0, instance: N, transitionsApplied: u, effectsToFire: c, automationNodePending: M };
2586
+ }, g = h?.type === "automation" && h.automationId ? { nodeId: d, automationId: h.automationId, triggerPayload: t.payload ?? {} } : void 0;
2587
+ return { ok: !0, instance: k, transitionsApplied: f, effectsToFire: c, automationNodePending: g };
2589
2588
  }
2590
2589
  function As(n, e) {
2591
- const s = n.workflows.find((m) => m.id === e.workflowId), { nodes: t, edges: i } = s.diagram, o = t[e.currentNodeId], a = (m) => (m ?? []).flatMap((p) => {
2592
- const g = n.roles.find((h) => h.id === p);
2593
- return g ? [{ id: g.id, name: g.name }] : [];
2590
+ const t = n.workflows.find((m) => m.id === e.workflowId), { nodes: s, edges: i } = t.diagram, o = s[e.currentNodeId], a = (m) => (m ?? []).flatMap((p) => {
2591
+ const w = n.roles.find((h) => h.id === p);
2592
+ return w ? [{ id: w.id, name: w.name }] : [];
2594
2593
  }), d = (m) => (m ?? []).flatMap((p) => {
2595
- const g = n.teams.find((h) => h.id === p);
2596
- return g ? [{ id: g.id, name: g.name }] : [];
2597
- }), l = (m, p, g) => ({
2594
+ const w = n.teams.find((h) => h.id === p);
2595
+ return w ? [{ id: w.id, name: w.name }] : [];
2596
+ }), l = (m, p, w) => ({
2598
2597
  roles: a(m),
2599
2598
  teams: d(p),
2600
- emails: g ?? []
2599
+ emails: w ?? []
2601
2600
  }), c = (m) => (n.events.find((p) => p.id === m)?.payload ?? []).map((p) => ({
2602
2601
  key: p.key,
2603
2602
  type: p.type,
2604
2603
  required: p.required,
2605
2604
  label: p.label
2606
- })), u = o.type === "process" ? o : null, f = [];
2605
+ })), f = o.type === "process" ? o : null, u = [];
2607
2606
  for (const [m, p] of Object.entries(i)) {
2608
2607
  if (p.from !== e.currentNodeId || !("triggerEventId" in p)) continue;
2609
- const g = p.triggerEventId;
2610
- f.push({
2608
+ const w = p.triggerEventId;
2609
+ u.push({
2611
2610
  edgeId: m,
2612
- label: p.label ?? g,
2613
- emits: g,
2614
- requiredPayload: c(g)
2611
+ label: p.label ?? w,
2612
+ emits: w,
2613
+ requiredPayload: c(w)
2615
2614
  });
2616
2615
  }
2617
2616
  return {
@@ -2621,24 +2620,24 @@ function As(n, e) {
2621
2620
  label: e.currentNodeId
2622
2621
  },
2623
2622
  status: e.status,
2624
- transitions: f,
2623
+ transitions: u,
2625
2624
  raci: {
2626
- responsible: l(u?.responsibleRoleIds, u?.responsibleTeamIds, u?.responsibleEmails),
2627
- accountable: l(u?.accountableRoleIds, u?.accountableTeamIds, u?.accountableEmails),
2628
- consulted: l(u?.consultedRoleIds, u?.consultedTeamIds, u?.consultedEmails),
2629
- informed: l(u?.informedRoleIds, u?.informedTeamIds, u?.informedEmails)
2625
+ responsible: l(f?.responsibleRoleIds, f?.responsibleTeamIds, f?.responsibleEmails),
2626
+ accountable: l(f?.accountableRoleIds, f?.accountableTeamIds, f?.accountableEmails),
2627
+ consulted: l(f?.consultedRoleIds, f?.consultedTeamIds, f?.consultedEmails),
2628
+ informed: l(f?.informedRoleIds, f?.informedTeamIds, f?.informedEmails)
2630
2629
  },
2631
2630
  isTerminal: o.type === "end"
2632
2631
  };
2633
2632
  }
2634
- function re(n, e, s, t, i) {
2633
+ function re(n, e, t, s, i) {
2635
2634
  return {
2636
2635
  id: globalThis.crypto.randomUUID(),
2637
2636
  edgeId: n,
2638
2637
  fromNodeId: e,
2639
- toNodeId: s,
2640
- trigger: t,
2641
- actor: t.actor,
2638
+ toNodeId: t,
2639
+ trigger: s,
2640
+ actor: s.actor,
2642
2641
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2643
2642
  ...i ? { auto: !0 } : {}
2644
2643
  };
@@ -2646,8 +2645,8 @@ function re(n, e, s, t, i) {
2646
2645
  class js {
2647
2646
  instances = /* @__PURE__ */ new Map();
2648
2647
  async listInstances(e) {
2649
- let s = [...this.instances.values()];
2650
- return e?.workflowId && (s = s.filter((t) => t.workflowId === e.workflowId)), e?.status && (s = s.filter((t) => t.status === e.status)), e?.trackedAssetTypeId && (s = s.filter((t) => t.trackedAsset.assetTypeId === e.trackedAssetTypeId)), e?.trackedAssetId && (s = s.filter((t) => t.trackedAsset.id === e.trackedAssetId)), s;
2648
+ let t = [...this.instances.values()];
2649
+ return e?.workflowId && (t = t.filter((s) => s.workflowId === e.workflowId)), e?.status && (t = t.filter((s) => s.status === e.status)), e?.trackedAssetId && (t = t.filter((s) => s.trackedAsset.source === "internal" && s.trackedAsset.id === e.trackedAssetId)), t;
2651
2650
  }
2652
2651
  async getInstance(e) {
2653
2652
  return this.instances.get(e) ?? null;
@@ -2662,8 +2661,8 @@ class js {
2662
2661
  function ae(n) {
2663
2662
  if (n == null) return "Unknown error";
2664
2663
  if (typeof n == "string") return n;
2665
- const e = n, s = typeof e.name == "string" ? e.name : "Error", t = typeof e.message == "string" ? e.message : void 0;
2666
- if (t !== void 0) return t ? `${s}: ${t}` : s;
2664
+ const e = n, t = typeof e.name == "string" ? e.name : "Error", s = typeof e.message == "string" ? e.message : void 0;
2665
+ if (s !== void 0) return s ? `${t}: ${s}` : t;
2667
2666
  try {
2668
2667
  return String(n);
2669
2668
  } catch {
@@ -2672,7 +2671,6 @@ function ae(n) {
2672
2671
  }
2673
2672
  class Os {
2674
2673
  getBep;
2675
- getHistoricalBep;
2676
2674
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2677
2675
  _runtime;
2678
2676
  storage;
@@ -2690,10 +2688,10 @@ class Os {
2690
2688
  }
2691
2689
  /** Namespaced workflow instance operations. */
2692
2690
  workflows;
2693
- constructor(e, s) {
2694
- this.getBep = e, this.getHistoricalBep = s, this.workflows = {
2695
- create: (t, i, o) => this._create(t, i, o),
2696
- emit: (t, i) => this._emit(t, i),
2691
+ constructor(e) {
2692
+ this.getBep = e, this.workflows = {
2693
+ create: (t, s, i) => this._create(t, s, i),
2694
+ emit: (t, s) => this._emit(t, s),
2697
2695
  get: (t) => this._get(t),
2698
2696
  list: (t) => this._list(t),
2699
2697
  delete: (t) => this._delete(t),
@@ -2719,65 +2717,66 @@ class Os {
2719
2717
  // ─── Remote data ──────────────────────────────────────────────────────────
2720
2718
  async getRemoteData(e) {
2721
2719
  this._assertInit();
2722
- const t = this.getBep().remoteData.find((i) => i.id === e);
2723
- if (!t) throw new Error(`Remote data "${e}" not found in BEP`);
2724
- if (!t.resolverId) throw new Error(`Remote data "${e}" has no resolver assigned`);
2725
- return this._runtime._runResolver(t.resolverId, t.url);
2720
+ const s = this.getBep().remoteData.find((i) => i.id === e);
2721
+ if (!s) throw new Error(`Remote data "${e}" not found in BEP`);
2722
+ if (!s.resolverId) throw new Error(`Remote data "${e}" has no resolver assigned`);
2723
+ return this._runtime._runResolver(s.resolverId, s.url);
2726
2724
  }
2727
2725
  // ─── Private workflow instance operations ─────────────────────────────────
2728
- async _create(e, s, t) {
2726
+ async _create(e, t, s) {
2729
2727
  this._assertInit();
2730
- let i;
2731
- if ("rawPayload" in s) {
2732
- const y = this._runtime.triggers[e];
2733
- if (!y) throw new Error(`No trigger handler declared for workflow "${e}"`);
2734
- i = await y(s.rawPayload), t = "dotBEP";
2728
+ let i, o;
2729
+ if ("rawPayload" in t) {
2730
+ const v = this._runtime.triggers[e];
2731
+ if (!v) throw new Error(`No trigger handler declared for software "${e}"`);
2732
+ const k = await v(t.rawPayload);
2733
+ i = k.trackedAsset, o = k.workflowId, s = "dotBEP";
2735
2734
  } else
2736
- i = s;
2737
- const o = this.getBep(), d = $s(o, e, i, t, "unversioned");
2735
+ i = t, o = e;
2736
+ const a = this.getBep(), d = Ts(a, o, i, s);
2738
2737
  if (!d) return null;
2739
2738
  const { instance: l, startEffects: c } = d;
2740
- for (const y of c)
2741
- await this._executeEffect(l, y);
2742
- const f = o.workflows.find((y) => y.id === e)?.diagram.nodes[l.currentNodeId];
2743
- let m = f?.type === "automation" && f.automationId ? { automationId: f.automationId, triggerPayload: {} } : void 0, p = l;
2744
- const g = 10;
2739
+ for (const v of c)
2740
+ await this._executeEffect(l, v);
2741
+ const u = a.workflows.find((v) => v.id === o)?.diagram.nodes[l.currentNodeId];
2742
+ let m = u?.type === "automation" && u.automationId ? { automationId: u.automationId, triggerPayload: {} } : void 0, p = l;
2743
+ const w = 10;
2745
2744
  let h = 0;
2746
- for (; m && h++ < g; ) {
2747
- const { automationId: y, triggerPayload: N } = m, { eventId: M, ...E } = await this._executeAutomationNode(p, y, N), k = J(o, p, {
2748
- eventId: M,
2745
+ for (; m && h++ < w; ) {
2746
+ const { automationId: v, triggerPayload: k } = m, { eventId: g, ...I } = await this._executeAutomationNode(p, v, k), _ = J(a, p, {
2747
+ eventId: g,
2749
2748
  actor: "dotBEP",
2750
2749
  softwareId: "dotBEP",
2751
- payload: E
2750
+ payload: I
2752
2751
  });
2753
- if (!k.ok) break;
2754
- p = k.instance;
2755
- for (const T of k.effectsToFire ?? [])
2756
- await this._executeEffect(p, T);
2757
- m = k.automationNodePending;
2752
+ if (!_.ok) break;
2753
+ p = _.instance;
2754
+ for (const $ of _.effectsToFire ?? [])
2755
+ await this._executeEffect(p, $);
2756
+ m = _.automationNodePending;
2758
2757
  }
2759
2758
  return await this.storage.saveInstance(p), await this._fire(this._createdListeners, p), p;
2760
2759
  }
2761
- async _emit(e, s) {
2760
+ async _emit(e, t) {
2762
2761
  this._assertInit();
2763
- const t = await this.storage.getInstance(e);
2764
- if (!t) return { ok: !1, error: "NO_MATCHING_EDGE" };
2765
- const i = await this._resolveBep(t.bepVersion);
2766
- let o = J(i, t, s, { skipRaci: this.skipRaci });
2762
+ const s = await this.storage.getInstance(e);
2763
+ if (!s) return { ok: !1, error: "NO_MATCHING_EDGE" };
2764
+ const i = this.getBep();
2765
+ let o = J(i, s, t, { skipRaci: this.skipRaci });
2767
2766
  if (!o.ok) return { ok: !1, error: o.error, payloadErrors: o.payloadErrors };
2768
2767
  const a = [...o.transitionsApplied ?? []], d = [];
2769
2768
  let l = o.instance;
2770
- for (const f of o.effectsToFire ?? [])
2771
- d.push(await this._executeEffect(l, f));
2769
+ for (const u of o.effectsToFire ?? [])
2770
+ d.push(await this._executeEffect(l, u));
2772
2771
  const c = 10;
2773
- let u = 0;
2774
- for (; o.automationNodePending && u++ < c; ) {
2775
- const { automationId: f, triggerPayload: m } = o.automationNodePending, { eventId: p, ...g } = await this._executeAutomationNode(l, f, m);
2772
+ let f = 0;
2773
+ for (; o.automationNodePending && f++ < c; ) {
2774
+ const { automationId: u, triggerPayload: m } = o.automationNodePending, { eventId: p, ...w } = await this._executeAutomationNode(l, u, m);
2776
2775
  if (o = J(i, l, {
2777
2776
  eventId: p,
2778
2777
  actor: "dotBEP",
2779
2778
  softwareId: "dotBEP",
2780
- payload: g
2779
+ payload: w
2781
2780
  }), !o.ok) break;
2782
2781
  l = o.instance, a.push(...o.transitionsApplied ?? []);
2783
2782
  for (const h of o.effectsToFire ?? [])
@@ -2795,19 +2794,19 @@ class Os {
2795
2794
  }
2796
2795
  async _list(e) {
2797
2796
  this._assertInit();
2798
- const { pendingActionFor: s, ...t } = e ?? {}, i = await this.storage.listInstances(t);
2799
- if (!s) return i;
2800
- const o = this.getBep(), a = o.members.find((d) => d.email === s);
2797
+ const { pendingActionFor: t, ...s } = e ?? {}, i = await this.storage.listInstances(s);
2798
+ if (!t) return i;
2799
+ const o = this.getBep(), a = o.members.find((d) => d.email === t);
2801
2800
  return a ? i.filter((d) => {
2802
2801
  const l = o.workflows.find((m) => m.id === d.workflowId);
2803
2802
  if (!l) return !1;
2804
2803
  const c = l.diagram.nodes[d.currentNodeId];
2805
2804
  if (!c) return !1;
2806
- const u = c.type === "process" ? c : null, f = [
2807
- ...u?.responsibleRoleIds ?? [],
2808
- ...u?.accountableRoleIds ?? []
2805
+ const f = c.type === "process" ? c : null, u = [
2806
+ ...f?.responsibleRoleIds ?? [],
2807
+ ...f?.accountableRoleIds ?? []
2809
2808
  ];
2810
- return f.length === 0 || f.includes(a.roleId);
2809
+ return u.length === 0 || u.includes(a.roleId);
2811
2810
  }) : [];
2812
2811
  }
2813
2812
  async _delete(e) {
@@ -2815,61 +2814,58 @@ class Os {
2815
2814
  }
2816
2815
  async _cancel(e) {
2817
2816
  this._assertInit();
2818
- const s = await this.storage.getInstance(e);
2819
- if (!s || s.status !== "active") return;
2820
- const t = {
2821
- ...s,
2817
+ const t = await this.storage.getInstance(e);
2818
+ if (!t || t.status !== "active") return;
2819
+ const s = {
2820
+ ...t,
2822
2821
  status: "cancelled",
2823
2822
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
2824
2823
  };
2825
- await this.storage.saveInstance(t), await this._fire(this._cancelledListeners, t);
2824
+ await this.storage.saveInstance(s), await this._fire(this._cancelledListeners, s);
2826
2825
  }
2827
2826
  async _getStatus(e) {
2828
2827
  this._assertInit();
2829
- const s = await this.storage.getInstance(e);
2830
- if (!s) return null;
2831
- const t = await this._resolveBep(s.bepVersion);
2832
- return As(t, s);
2828
+ const t = await this.storage.getInstance(e);
2829
+ if (!t) return null;
2830
+ const s = this.getBep();
2831
+ return As(s, t);
2833
2832
  }
2834
2833
  async _resolveContext(e) {
2835
2834
  this._assertInit();
2836
- const s = await this.storage.getInstance(e);
2837
- if (!s) return {};
2838
- const t = {};
2839
- for (const i of s.history)
2840
- Object.assign(t, i.trigger.payload ?? {});
2841
- return t;
2835
+ const t = await this.storage.getInstance(e);
2836
+ if (!t) return {};
2837
+ const s = {};
2838
+ for (const i of t.history)
2839
+ Object.assign(s, i.trigger.payload ?? {});
2840
+ return s;
2842
2841
  }
2843
2842
  // ─── Internal helpers ─────────────────────────────────────────────────────
2844
2843
  _assertInit() {
2845
2844
  if (!this._runtime || !this.storage)
2846
2845
  throw new Error("Engine not initialized — call bep.engine.init({ runtime, storage }) first.");
2847
2846
  }
2848
- async _resolveBep(e) {
2849
- return this.getHistoricalBep && e !== "unversioned" ? this.getHistoricalBep(e) : this.getBep();
2850
- }
2851
- async _fire(e, ...s) {
2852
- await Promise.allSettled(e.map((t) => t(...s)));
2847
+ async _fire(e, ...t) {
2848
+ await Promise.allSettled(e.map((s) => s(...t)));
2853
2849
  }
2854
- async _executeAutomationNode(e, s, t) {
2855
- const i = this._runtime.automations[s];
2856
- if (!i) throw new Error(`No handler declared for automation "${s}"`);
2850
+ async _executeAutomationNode(e, t, s) {
2851
+ const i = this._runtime.automations[t];
2852
+ if (!i) throw new Error(`No handler declared for automation "${t}"`);
2857
2853
  try {
2858
- return await i(e, t);
2854
+ return await i(e, s);
2859
2855
  } catch (o) {
2860
- throw await this._fire(this._automationFailedListeners, e, s, ae(o)), o;
2856
+ throw await this._fire(this._automationFailedListeners, e, t, ae(o)), o;
2861
2857
  }
2862
2858
  }
2863
- async _executeEffect(e, s) {
2864
- const t = this._runtime.effects[s.effectId];
2865
- if (!t)
2866
- return { effectId: s.effectId, fromEdgeId: s.fromEdgeId, status: "skipped" };
2859
+ async _executeEffect(e, t) {
2860
+ const s = this._runtime.effects[t.effectId];
2861
+ if (!s)
2862
+ return { effectId: t.effectId, fromEdgeId: t.fromEdgeId, status: "skipped" };
2867
2863
  try {
2868
- return await t(e, s.triggerPayload), { effectId: s.effectId, fromEdgeId: s.fromEdgeId, status: "executed" };
2864
+ return await s(e, t.triggerPayload), { effectId: t.effectId, fromEdgeId: t.fromEdgeId, status: "executed" };
2869
2865
  } catch (i) {
2870
2866
  const o = {
2871
- effectId: s.effectId,
2872
- fromEdgeId: s.fromEdgeId,
2867
+ effectId: t.effectId,
2868
+ fromEdgeId: t.fromEdgeId,
2873
2869
  status: "failed",
2874
2870
  error: ae(i)
2875
2871
  };
@@ -2877,16 +2873,16 @@ class Os {
2877
2873
  }
2878
2874
  }
2879
2875
  }
2880
- function Cs(n, e) {
2881
- const s = /* @__PURE__ */ new Map();
2882
- for (const t of n) {
2883
- const i = [e(t)].flat();
2876
+ function Ls(n, e) {
2877
+ const t = /* @__PURE__ */ new Map();
2878
+ for (const s of n) {
2879
+ const i = [e(s)].flat();
2884
2880
  for (const o of i)
2885
- s.has(o) || s.set(o, []), s.get(o).push(t);
2881
+ t.has(o) || t.set(o, []), t.get(o).push(s);
2886
2882
  }
2887
- return Array.from(s.entries()).map(([t, i]) => ({ key: t, rows: i }));
2883
+ return Array.from(t.entries()).map(([s, i]) => ({ key: s, rows: i }));
2888
2884
  }
2889
- class Ls {
2885
+ class Cs {
2890
2886
  env;
2891
2887
  effects = {};
2892
2888
  automations = {};
@@ -2901,29 +2897,29 @@ class Ls {
2901
2897
  constructor({ env: e = {} } = {}) {
2902
2898
  this.env = e;
2903
2899
  }
2904
- effect(e, s) {
2905
- return this.effects[e] = s, this;
2900
+ effect(e, t) {
2901
+ return this.effects[e] = t, this;
2906
2902
  }
2907
- automation(e, s) {
2908
- return this.automations[e] = s, this;
2903
+ automation(e, t) {
2904
+ return this.automations[e] = t, this;
2909
2905
  }
2910
- resolver(e, s) {
2911
- return this.resolvers[e] = s, this;
2906
+ resolver(e, t) {
2907
+ return this.resolvers[e] = t, this;
2912
2908
  }
2913
- trigger(e, s) {
2914
- return this.triggers[e] = s, this;
2909
+ trigger(e, t) {
2910
+ return this.triggers[e] = t, this;
2915
2911
  }
2916
2912
  /** @internal Called by Engine.getRemoteData — keeps env encapsulated inside the Runtime. */
2917
- _runResolver(e, s) {
2918
- const t = this.resolvers[e];
2919
- if (!t) throw new Error(`No handler declared for resolver "${e}"`);
2920
- return t(s, this.env);
2913
+ _runResolver(e, t) {
2914
+ const s = this.resolvers[e];
2915
+ if (!s) throw new Error(`No handler declared for resolver "${e}"`);
2916
+ return s(t, this.env);
2921
2917
  }
2922
2918
  }
2923
2919
  class F {
2924
- constructor(e, s) {
2925
- this._data = e, this._zip = s;
2926
- const t = () => this._data;
2920
+ constructor(e, t) {
2921
+ this._data = e, this._zip = t;
2922
+ const s = () => this._data;
2927
2923
  this.project = new _t(
2928
2924
  () => this._data.project,
2929
2925
  (i) => {
@@ -2931,20 +2927,17 @@ class F {
2931
2927
  },
2932
2928
  de,
2933
2929
  (i, o) => {
2934
- const a = [], d = j("project", i.code, o.deliverableNamingConvention);
2930
+ const a = [], d = O("project", i.code, o.deliverableNamingConvention);
2935
2931
  return d && a.push(d), i.clientId && !o.teams.some((l) => l.id === i.clientId) && a.push(`teams["${i.clientId}"] not found`), a;
2936
2932
  },
2937
- t
2938
- ), this.actions = new Tt(t), this.annexes = new $t(t), this.env = new Ot(t), this.events = new Bt(t), this.effects = new At(t), this.automations = new jt(t), this.bimUses = new Lt(t, () => this.workflows), this.disciplines = new Dt(t), this.guides = new Ut(t), this.lods = new zt(t), this.lois = new Zt(t), this.loin = new Jt(t), this.lbsNodes = new Gt(t), this.assetTypes = new Kt(t), this.extensions = new qt(t), this.roles = new Wt(t), this.members = new Xt(t), this.milestones = new Vt(t), this.objectives = new Ht(t), this.phases = new Yt(t), this.remoteData = new Qt(t), this.resolvers = new es(t), this.softwares = new ts(t, () => this.assetTypes), this.standards = new ss(t, () => this._zip), this.teams = new ns(t, () => this.members), this.workflows = new os(t, () => this.members, () => this.teams), this.deliverables = new xt(t, () => this.teams, () => this.assetTypes, () => this.lbsNodes, () => this.milestones), this.notes = new Ct(t, () => this.members), this.flags = new Ft(t), this.engine = new Os(
2939
- () => this._data,
2940
- (i) => this.history.get(i)
2941
- ), this.history = new I(
2942
- t,
2933
+ s
2934
+ ), this.actions = new Rt(s), this.annexes = new Tt(s), this.env = new Ot(s), this.events = new Bt(s), this.effects = new At(s), this.automations = new jt(s), this.bimUses = new Ct(s, () => this.workflows), this.disciplines = new Dt(s), this.guides = new Ut(s), this.lods = new zt(s), this.lois = new Zt(s), this.loin = new Jt(s), this.lbsNodes = new Gt(s), this.assetTypes = new Kt(s), this.extensions = new qt(s), this.roles = new Wt(s), this.members = new Xt(s), this.milestones = new Vt(s), this.objectives = new Ht(s), this.phases = new Yt(s), this.remoteData = new Qt(s), this.resolvers = new es(s), this.softwares = new ts(s, () => this.assetTypes), this.standards = new ss(s, () => this._zip), this.teams = new ns(s, () => this.members), this.workflows = new os(s, () => this.members, () => this.teams), this.deliverables = new Pt(s, () => this.teams, () => this.assetTypes, () => this.lbsNodes, () => this.milestones), this.notes = new Lt(s, () => this.members), this.flags = new Ft(s), this.engine = new Os(() => this._data), this.history = new S(
2935
+ s,
2943
2936
  (i) => {
2944
2937
  this._data = i;
2945
2938
  },
2946
2939
  () => this._zip
2947
- ), this.nomenclature = new Pt(t), this.memory = new Z("memory.md", () => this._zip), this.skill = new Z("skills/bep-authoring/SKILL.md", () => this._zip), this.icon = new Z("icon.svg", () => this._zip);
2940
+ ), this.nomenclature = new Mt(s), this.memory = new Z("memory.md", () => this._zip), this.skill = new Z("skills/bep-authoring/SKILL.md", () => this._zip), this.icon = new Z("icon.svg", () => this._zip);
2948
2941
  }
2949
2942
  _data;
2950
2943
  _zip;
@@ -3001,10 +2994,10 @@ class F {
3001
2994
  * fully operational after open(). Idempotent — existing files are untouched.
3002
2995
  */
3003
2996
  static async open(e) {
3004
- const s = await se.loadAsync(e), t = s.file("bep.json");
3005
- if (!t) throw new Error("Invalid .bep file: missing bep.json");
3006
- const i = await t.async("string"), o = $(JSON.parse(i));
3007
- return await F._initialize(o, s), new F(o, s);
2997
+ const t = await se.loadAsync(e), s = t.file("bep.json");
2998
+ if (!s) throw new Error("Invalid .bep file: missing bep.json");
2999
+ const i = await s.async("string"), o = A(JSON.parse(i));
3000
+ return await F._initialize(o, t), new F(o, t);
3008
3001
  }
3009
3002
  /**
3010
3003
  * Ensures all expected files exist in the zip.
@@ -3017,21 +3010,21 @@ class F {
3017
3010
  * diff against this terminus. The baseline is written so history.status()
3018
3011
  * and history.discard() work before the first commit.
3019
3012
  */
3020
- static async _initialize(e, s) {
3021
- s.file("memory.md") || s.file("memory.md", ""), s.file("skills/bep-authoring/SKILL.md") || s.file("skills/bep-authoring/SKILL.md", "");
3022
- for (const t of e.standards)
3023
- s.file(t.contentPath) || s.file(t.contentPath, "");
3024
- if (!s.file("baseline/bep.json")) {
3025
- const t = JSON.stringify(e, null, 2);
3026
- s.file("baseline/bep.json", t), s.file("changelog/v0.0.json", t);
3013
+ static async _initialize(e, t) {
3014
+ t.file("memory.md") || t.file("memory.md", ""), t.file("skills/bep-authoring/SKILL.md") || t.file("skills/bep-authoring/SKILL.md", "");
3015
+ for (const s of e.standards)
3016
+ t.file(s.contentPath) || t.file(s.contentPath, "");
3017
+ if (!t.file("baseline/bep.json")) {
3018
+ const s = JSON.stringify(e, null, 2);
3019
+ t.file("baseline/bep.json", s), t.file("changelog/v0.0.json", s);
3027
3020
  for (const i of e.standards) {
3028
- const o = await s.file(i.contentPath).async("string");
3029
- s.file(`baseline/standards/${i.id}.md`, o), s.file(`changelog/standards/${i.id}/v0.0.md`, o);
3021
+ const o = await t.file(i.contentPath).async("string");
3022
+ t.file(`baseline/standards/${i.id}.md`, o), t.file(`changelog/standards/${i.id}/v0.0.md`, o);
3030
3023
  }
3031
3024
  }
3032
3025
  }
3033
3026
  static create(e) {
3034
- const s = $({
3027
+ const t = A({
3035
3028
  project: { name: e.name, code: e.code, clientId: e.clientId, description: e.description },
3036
3029
  roles: [],
3037
3030
  members: [],
@@ -3060,8 +3053,8 @@ class F {
3060
3053
  flags: [],
3061
3054
  env: [],
3062
3055
  automations: []
3063
- }), t = new se(), i = JSON.stringify(s, null, 2);
3064
- return t.file("memory.md", ""), t.file("skills/bep-authoring/SKILL.md", ""), t.file("baseline/bep.json", i), t.file("changelog/v0.0.json", i), new F(s, t);
3056
+ }), s = new se(), i = JSON.stringify(t, null, 2);
3057
+ return s.file("memory.md", ""), s.file("skills/bep-authoring/SKILL.md", ""), s.file("baseline/bep.json", i), s.file("changelog/v0.0.json", i), new F(t, s);
3065
3058
  }
3066
3059
  // ─── Accessors ────────────────────────────────────────────────────────────
3067
3060
  get data() {
@@ -3077,62 +3070,62 @@ class F {
3077
3070
  delete this._data.deliverableNamingConvention;
3078
3071
  return;
3079
3072
  }
3080
- const s = ue.parse(e), t = kt(this._data, s);
3081
- if (t.length) throw new Error(`Naming convention incompatible with existing data:
3082
- ${t.join(`
3073
+ const t = ue.parse(e), s = Nt(this._data, t);
3074
+ if (s.length) throw new Error(`Naming convention incompatible with existing data:
3075
+ ${s.join(`
3083
3076
  `)}`);
3084
- this._data.deliverableNamingConvention = s;
3077
+ this._data.deliverableNamingConvention = t;
3085
3078
  }
3086
3079
  // ─── File access ──────────────────────────────────────────────────────────
3087
3080
  /** Reads any text file stored inside the .bep archive by its zip path. */
3088
3081
  async readFile(e) {
3089
- const s = this._zip.file(e);
3090
- return s ? s.async("string") : null;
3082
+ const t = this._zip.file(e);
3083
+ return t ? t.async("string") : null;
3091
3084
  }
3092
3085
  // ─── Skills ───────────────────────────────────────────────────────────────
3093
3086
  /** Returns the names of all skills present in the archive. */
3094
3087
  listSkills() {
3095
3088
  const e = /* @__PURE__ */ new Set();
3096
- return this._zip.forEach((s) => {
3097
- const t = s.match(/^skills\/([^/]+)\/SKILL\.md$/);
3098
- t && e.add(t[1]);
3089
+ return this._zip.forEach((t) => {
3090
+ const s = t.match(/^skills\/([^/]+)\/SKILL\.md$/);
3091
+ s && e.add(s[1]);
3099
3092
  }), [...e];
3100
3093
  }
3101
3094
  /** Returns the SKILL.md content for the given skill, or null if it does not exist. */
3102
3095
  async getSkill(e) {
3103
- const s = this._zip.file(`skills/${e}/SKILL.md`);
3104
- return s ? s.async("string") : null;
3096
+ const t = this._zip.file(`skills/${e}/SKILL.md`);
3097
+ return t ? t.async("string") : null;
3105
3098
  }
3106
3099
  /** Writes the SKILL.md content for the given skill, creating it if needed. */
3107
- async setSkill(e, s) {
3108
- this._zip.file(`skills/${e}/SKILL.md`, s);
3100
+ async setSkill(e, t) {
3101
+ this._zip.file(`skills/${e}/SKILL.md`, t);
3109
3102
  }
3110
3103
  /** Returns the names of all resource files for the given skill. */
3111
3104
  listSkillResources(e) {
3112
- const s = `skills/${e}/resources/`, t = [];
3105
+ const t = `skills/${e}/resources/`, s = [];
3113
3106
  return this._zip.forEach((i) => {
3114
- i.startsWith(s) && i !== s && t.push(i.slice(s.length));
3115
- }), t;
3107
+ i.startsWith(t) && i !== t && s.push(i.slice(t.length));
3108
+ }), s;
3116
3109
  }
3117
3110
  /** Returns the content of a resource file for the given skill, or null if it does not exist. */
3118
- async getSkillResource(e, s) {
3119
- const t = this._zip.file(`skills/${e}/resources/${s}`);
3120
- return t ? t.async("string") : null;
3111
+ async getSkillResource(e, t) {
3112
+ const s = this._zip.file(`skills/${e}/resources/${t}`);
3113
+ return s ? s.async("string") : null;
3121
3114
  }
3122
3115
  /** Writes a resource file for the given skill, creating it if needed. */
3123
- async setSkillResource(e, s, t) {
3124
- this._zip.file(`skills/${e}/resources/${s}`, t);
3116
+ async setSkillResource(e, t, s) {
3117
+ this._zip.file(`skills/${e}/resources/${t}`, s);
3125
3118
  }
3126
3119
  /** Removes a skill's SKILL.md and all its resources from the archive. No-op if not found. */
3127
3120
  removeSkill(e) {
3128
- const s = `skills/${e}/`, t = [];
3121
+ const t = `skills/${e}/`, s = [];
3129
3122
  this._zip.forEach((i) => {
3130
- i.startsWith(s) && t.push(i);
3131
- }), t.forEach((i) => this._zip.remove(i));
3123
+ i.startsWith(t) && s.push(i);
3124
+ }), s.forEach((i) => this._zip.remove(i));
3132
3125
  }
3133
3126
  /** Removes a single resource file from a skill. No-op if not found. */
3134
- removeSkillResource(e, s) {
3135
- this._zip.remove(`skills/${e}/resources/${s}`);
3127
+ removeSkillResource(e, t) {
3128
+ this._zip.remove(`skills/${e}/resources/${t}`);
3136
3129
  }
3137
3130
  // ─── Type generation ──────────────────────────────────────────────────────
3138
3131
  /**
@@ -3145,18 +3138,32 @@ ${t.join(`
3145
3138
  * writeFileSync('bep.d.ts', bep.generateRuntimeTypes())
3146
3139
  */
3147
3140
  generateRuntimeTypes() {
3148
- const e = (f) => f, s = (f) => ` /** ${f} */
3149
- `, t = (f) => `{ ${f.map((m) => `${m.key}${m.required ? "" : "?"}: ${e(m.type)}`).join("; ")} }`, i = (f) => !f.payload || f.payload.length === 0 ? "() => void" : `(payload: ${t(f.payload)}) => void`, o = (f) => {
3150
- const m = f.payload && f.payload.length > 0 ? `payload: ${t(f.payload)}` : "", p = f.output.length === 0 ? "{ eventId: string }" : `{ eventId: string; ${f.output.map((g) => `${g.key}${g.required ? "" : "?"}: ${e(g.type)}`).join("; ")} }`;
3151
- return `(${m}) => ${p}`;
3152
- }, a = (f) => f.envKeys.length === 0 ? "(url: string) => unknown" : `(url: string, env: ${`{ ${f.envKeys.map((p) => `${p}: string`).join("; ")} }`}) => unknown`, d = this._data.effects.length ? this._data.effects.map((f) => `${s(f.description)} '${f.id}': ${i(f)}`).join(`
3153
- `) : " [key: string]: () => void", l = this._data.automations.length ? this._data.automations.map((f) => `${s(f.description)} '${f.id}': ${o(f)}`).join(`
3154
- `) : " [key: string]: () => { eventId: string }", c = this._data.resolvers.length ? this._data.resolvers.map((f) => `${s(f.description)} '${f.id}': ${a(f)}`).join(`
3155
- `) : " [key: string]: (url: string) => unknown", u = this._data.env.length ? this._data.env.map((f) => `${s(f.description)} ${f.key}: string`).join(`
3156
- `) : " [key: string]: string";
3157
- return [
3141
+ const e = (g) => g, t = (g) => ` /** ${g} */
3142
+ `, s = (g) => `{ ${g.map((I) => `${I.key}${I.required ? "" : "?"}: ${e(I.type)}`).join("; ")} }`, i = (g) => !g.payload || g.payload.length === 0 ? "() => void" : `(payload: ${s(g.payload)}) => void`, o = (g) => {
3143
+ const I = g.payload && g.payload.length > 0 ? `payload: ${s(g.payload)}` : "", _ = g.output.length === 0 ? "{ eventId: string }" : `{ eventId: string; ${g.output.map(($) => `${$.key}${$.required ? "" : "?"}: ${e($.type)}`).join("; ")} }`;
3144
+ return `(${I}) => ${_}`;
3145
+ }, a = (g) => g.envKeys.length === 0 ? "(url: string) => unknown" : `(url: string, env: ${`{ ${g.envKeys.map((_) => `${_}: string`).join("; ")} }`}) => unknown`, d = this._data.effects.length ? this._data.effects.map((g) => `${t(g.description)} '${g.id}': ${i(g)}`).join(`
3146
+ `) : " [key: string]: () => void", l = this._data.automations.length ? this._data.automations.map((g) => `${t(g.description)} '${g.id}': ${o(g)}`).join(`
3147
+ `) : " [key: string]: () => { eventId: string }", c = this._data.resolvers.length ? this._data.resolvers.map((g) => `${t(g.description)} '${g.id}': ${a(g)}`).join(`
3148
+ `) : " [key: string]: (url: string) => unknown", f = this._data.env.length ? this._data.env.map((g) => `${t(g.description)} ${g.key}: string`).join(`
3149
+ `) : " [key: string]: string", u = this._data.workflows.length > 0, m = u ? this._data.workflows.map((g) => {
3150
+ const I = g.description ? `${g.name} — ${g.description}` : g.name;
3151
+ return `${t(I)} '${g.id}': never`;
3152
+ }).join(`
3153
+ `) : null, h = `(rawPayload: unknown) => ${`Promise<{ trackedAsset: import('@dotbep/core').WorkflowInstance['trackedAsset']; workflowId: ${u ? "WorkflowId" : "string"} }>`}`, v = this._data.softwares.length ? this._data.softwares.map((g) => `${t(g.name)} '${g.id}': ${h}`).join(`
3154
+ `) : ` [key: string]: ${h}`, k = [
3158
3155
  "// Generated by bep.generateRuntimeTypes() — do not edit manually",
3156
+ ""
3157
+ ];
3158
+ return m && k.push(
3159
+ "// ─── Workflows ───────────────────────────────────────────────────────────────",
3159
3160
  "",
3161
+ "export interface BepWorkflows {",
3162
+ m,
3163
+ "}",
3164
+ "export type WorkflowId = keyof BepWorkflows | (string & {})",
3165
+ ""
3166
+ ), k.push(
3160
3167
  "// ─── Effects ──────────────────────────────────────────────────────────────────",
3161
3168
  "",
3162
3169
  "export interface BepEffects {",
@@ -3178,13 +3185,13 @@ ${t.join(`
3178
3185
  "// ─── Triggers ─────────────────────────────────────────────────────────────────",
3179
3186
  "",
3180
3187
  "export interface BepTriggers {",
3181
- " [key: string]: (rawPayload: unknown) => Promise<{ assetTypeId: string; source: string; id: string; label: string }>",
3188
+ v,
3182
3189
  "}",
3183
3190
  "",
3184
3191
  "// ─── Env ──────────────────────────────────────────────────────────────────────",
3185
3192
  "",
3186
3193
  "export interface BepEnv {",
3187
- u,
3194
+ f,
3188
3195
  "}",
3189
3196
  "",
3190
3197
  "// ─── Combined ─────────────────────────────────────────────────────────────────",
@@ -3197,7 +3204,7 @@ ${t.join(`
3197
3204
  " env: BepEnv",
3198
3205
  "}",
3199
3206
  ""
3200
- ].join(`
3207
+ ), k.join(`
3201
3208
  `);
3202
3209
  }
3203
3210
  // ─── Serialization ────────────────────────────────────────────────────────
@@ -3212,31 +3219,31 @@ ${t.join(`
3212
3219
  }
3213
3220
  export {
3214
3221
  Ee as ActionSchema,
3215
- Tt as Actions,
3216
- Te as AnnexSchema,
3222
+ Rt as Actions,
3223
+ Re as AnnexSchema,
3217
3224
  Xe as AnnexType,
3218
- $t as Annexes,
3225
+ Tt as Annexes,
3219
3226
  ye as AssetTypeSchema,
3220
3227
  Kt as AssetTypes,
3221
3228
  jt as Automations,
3222
- xs as BEPSchema,
3229
+ Ps as BEPSchema,
3223
3230
  ne as BEPVersionBase,
3224
3231
  It as BEPVersionSchema,
3225
3232
  Ie as BIMUseSchema,
3226
- Lt as BIMUses,
3233
+ Ct as BIMUses,
3227
3234
  F as Bep,
3228
3235
  Fs as ChangelogSchema,
3229
3236
  Et as DEFAULT_DELIMITER,
3230
- St as DEFAULT_TOKEN_PATTERN,
3237
+ kt as DEFAULT_TOKEN_PATTERN,
3231
3238
  bt as DeliverableBaseSchema,
3232
- xe as DeliverableSchema,
3233
- xt as Deliverables,
3239
+ Pe as DeliverableSchema,
3240
+ Pt as Deliverables,
3234
3241
  ge as DisciplineSchema,
3235
3242
  Dt as Disciplines,
3236
3243
  ut as EdgeGuardSchema,
3237
3244
  At as Effects,
3238
3245
  Os as Engine,
3239
- w as Entity,
3246
+ y as Entity,
3240
3247
  Ot as Env,
3241
3248
  Fe as EnvVarSchema,
3242
3249
  Bt as Events,
@@ -3244,28 +3251,28 @@ export {
3244
3251
  qt as Extensions,
3245
3252
  vt as FlagBaseSchema,
3246
3253
  Qe as FlagEntityType,
3247
- Pe as FlagSchema,
3254
+ Me as FlagSchema,
3248
3255
  Ye as FlagSeverity,
3249
3256
  Ft as Flags,
3250
3257
  lt as FlowAutomationNodeSchema,
3251
- ke as FlowAutomationSchema,
3258
+ Ne as FlowAutomationSchema,
3252
3259
  pt as FlowDecisionEdgeSchema,
3253
3260
  dt as FlowDecisionNodeSchema,
3254
3261
  wt as FlowDiagramSchema,
3255
3262
  ht as FlowDirectEdgeSchema,
3256
3263
  He as FlowDirection,
3257
3264
  gt as FlowEdgeSchema,
3258
- Ne as FlowEffectSchema,
3265
+ Se as FlowEffectSchema,
3259
3266
  at as FlowEndNodeSchema,
3260
- Se as FlowEventSchema,
3267
+ ke as FlowEventSchema,
3261
3268
  ft as FlowNodeSchema,
3262
- C as FlowPayloadFieldSchema,
3269
+ L as FlowPayloadFieldSchema,
3263
3270
  ct as FlowProcessNodeSchema,
3264
3271
  rt as FlowStartNodeSchema,
3265
3272
  mt as FlowTransitionEdgeSchema,
3266
- $e as GuideSchema,
3273
+ Te as GuideSchema,
3267
3274
  Ut as Guides,
3268
- I as History,
3275
+ S as History,
3269
3276
  Ge as ISORole,
3270
3277
  nt as LBSNodeBaseSchema,
3271
3278
  he as LBSNodeSchema,
@@ -3287,22 +3294,22 @@ export {
3287
3294
  st as NamingSegmentSchema,
3288
3295
  tt as NamingTokenSchema,
3289
3296
  it as NodeTimeoutSchema,
3290
- Ps as NodeType,
3291
- Pt as Nomenclature,
3292
- Me as NoteSchema,
3293
- Ct as Notes,
3297
+ Ms as NodeType,
3298
+ Mt as Nomenclature,
3299
+ xe as NoteSchema,
3300
+ Lt as Notes,
3294
3301
  be as ObjectiveSchema,
3295
3302
  Ht as Objectives,
3296
3303
  me as PhaseSchema,
3297
3304
  Yt as Phases,
3298
3305
  de as ProjectSchema,
3299
3306
  Qt as RemoteDataEntity,
3300
- Le as RemoteDataSchema,
3301
- Ce as ResolverSchema,
3307
+ Ce as RemoteDataSchema,
3308
+ Le as ResolverSchema,
3302
3309
  es as Resolvers,
3303
3310
  le as RoleSchema,
3304
3311
  Wt as Roles,
3305
- Ls as Runtime,
3312
+ Cs as Runtime,
3306
3313
  _t as Singleton,
3307
3314
  ve as SoftwareSchema,
3308
3315
  ts as Softwares,
@@ -3312,21 +3319,21 @@ export {
3312
3319
  fe as TeamSchema,
3313
3320
  ns as Teams,
3314
3321
  Z as TextFile,
3315
- Re as WorkflowSchema,
3322
+ $e as WorkflowSchema,
3316
3323
  os as Workflows,
3317
3324
  bs as arrayDefs,
3318
3325
  Ze as buildCodeMap,
3319
3326
  K as buildConsecutivoMap,
3320
- x as buildParentMap,
3327
+ P as buildParentMap,
3321
3328
  Es as diffBep,
3322
3329
  Is as diffEntities,
3323
3330
  ze as getNomenCode,
3324
3331
  Q as getRootIds,
3325
- Nt as getTokenPattern,
3326
- Cs as groupRaciRows,
3327
- $ as normalizeBep,
3332
+ St as getTokenPattern,
3333
+ Ls as groupRaciRows,
3334
+ A as normalizeBep,
3328
3335
  Ue as resolveLBSCodes,
3329
- kt as validateAllTokens,
3330
- Mt as validateLBS,
3331
- j as validateTokenValue
3336
+ Nt as validateAllTokens,
3337
+ xt as validateLBS,
3338
+ O as validateTokenValue
3332
3339
  };