@dialecte/scl 0.1.19 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/{index-ChFpcq4k.js → dialecte.config-BkqCz0VE.js} +1011 -980
  2. package/dist/v2019C1/config/dialecte.config.d.ts +15 -0
  3. package/dist/v2019C1/config/dialecte.config.d.ts.map +1 -1
  4. package/dist/v2019C1/config/hydrated.types.d.ts +1 -0
  5. package/dist/v2019C1/config/hydrated.types.d.ts.map +1 -1
  6. package/dist/v2019C1/dialecte.d.ts +9 -50
  7. package/dist/v2019C1/dialecte.d.ts.map +1 -1
  8. package/dist/v2019C1/extensions/reference/constants/path-extraction.d.ts +4 -0
  9. package/dist/v2019C1/extensions/reference/constants/path-extraction.d.ts.map +1 -1
  10. package/dist/v2019C1/extensions/reference/query/build/path-segment.d.ts.map +1 -1
  11. package/dist/v2019C1/extensions/template/transaction/shared/clone-function.d.ts.map +1 -1
  12. package/dist/v2019C1/hooks/index.d.ts +2 -0
  13. package/dist/v2019C1/hooks/index.d.ts.map +1 -1
  14. package/dist/v2019C1/hooks/io/index.d.ts.map +1 -0
  15. package/dist/v2019C1/{io/hooks → hooks/io}/io-hooks.d.ts.map +1 -1
  16. package/dist/v2019C1/{io/hooks → hooks/io}/io-hooks.types.d.ts.map +1 -1
  17. package/dist/v2019C1/index.d.ts +0 -1
  18. package/dist/v2019C1/index.d.ts.map +1 -1
  19. package/dist/v2019C1/index.js +138 -164
  20. package/dist/v2019C1/test/hydrated-test.d.ts +4 -14
  21. package/dist/v2019C1/test/hydrated-test.d.ts.map +1 -1
  22. package/dist/v2019C1/test/hydrated-test.types.d.ts +3 -1
  23. package/dist/v2019C1/test/hydrated-test.types.d.ts.map +1 -1
  24. package/dist/v2019C1/test.js +20 -19
  25. package/package.json +2 -2
  26. package/dist/v2019C1/io/export.d.ts +0 -11
  27. package/dist/v2019C1/io/export.d.ts.map +0 -1
  28. package/dist/v2019C1/io/hooks/index.d.ts.map +0 -1
  29. package/dist/v2019C1/io/import.d.ts +0 -5
  30. package/dist/v2019C1/io/import.d.ts.map +0 -1
  31. package/dist/v2019C1/io/index.d.ts +0 -3
  32. package/dist/v2019C1/io/index.d.ts.map +0 -1
  33. /package/dist/v2019C1/{io/hooks → hooks/io}/index.d.ts +0 -0
  34. /package/dist/v2019C1/{io/hooks → hooks/io}/io-hooks.d.ts +0 -0
  35. /package/dist/v2019C1/{io/hooks → hooks/io}/io-hooks.types.d.ts +0 -0
@@ -21144,162 +21144,666 @@ const H = [
21144
21144
  }
21145
21145
  ]
21146
21146
  }
21147
- }, f = {
21148
- direct: "direct",
21149
- lnode: "lnode",
21150
- iedAddress: "ied-address",
21151
- behaviorDescription: "behavior-description",
21152
- unsupported: "unsupported"
21153
- }, m = {
21154
- AllocationRoleRef: [
21155
- {
21156
- attribute: { path: "allocationRole", uuid: "allocationRoleUuid" },
21157
- resolution: "direct",
21158
- target: ["AllocationRole"],
21159
- companions: []
21160
- }
21161
- ],
21162
- BehaviorDescriptionRef: [
21163
- {
21164
- attribute: { path: "behaviorDescription", uuid: "behaviorDescriptionUuid" },
21165
- resolution: "direct",
21166
- target: ["BehaviorDescription"],
21167
- companions: []
21168
- }
21169
- ],
21170
- BehaviorReference: [
21147
+ };
21148
+ async function $(a) {
21149
+ const { childRecord: e, parentRecord: t, query: i } = a;
21150
+ if (e.namespace.prefix === P.namespaces.default.prefix)
21151
+ return [];
21152
+ const n = t.tagName === "Private", u = t.namespace.prefix === P.namespaces.default.prefix;
21153
+ if (!n && !u)
21154
+ return [];
21155
+ const r = t.children.find((o) => o.tagName === "Private"), s = {
21156
+ ...t,
21157
+ children: t.children.filter((o) => o.id !== e.id)
21158
+ };
21159
+ return n ? J({ parentRecord: t, childRecord: e, query: i }) : r ? ee({
21160
+ existingPrivateRef: r,
21161
+ parentRecord: t,
21162
+ updatedParentRecord: s,
21163
+ childRecord: e,
21164
+ query: i
21165
+ }) : (await i.findAncestors(t)).some(
21166
+ (o) => o.tagName === "Private" && o.attributes.some(
21167
+ (p) => p.name === "type" && p.value === e.namespace.prefix
21168
+ )
21169
+ ) ? [] : te({ parentRecord: t, updatedParentRecord: s, childRecord: e });
21170
+ }
21171
+ async function J(a) {
21172
+ const { parentRecord: e, childRecord: t, query: i } = a, n = e;
21173
+ if (t.parent?.id === n.id && t.parent?.tagName === "Private")
21174
+ return [];
21175
+ const u = await F({ privateId: n.id, query: i });
21176
+ I(u, {
21177
+ detail: "Latest private record not found",
21178
+ key: "ELEMENT_NOT_FOUND"
21179
+ });
21180
+ const { childRecord: r, privateRecord: s } = q({
21181
+ privateRecord: u,
21182
+ childRecord: t
21183
+ });
21184
+ return [
21171
21185
  {
21172
- attribute: { path: "behaviorReference", uuid: "behaviorUuid" },
21173
- resolution: "direct",
21174
- target: ["BehaviorDescription"],
21175
- companions: []
21176
- }
21177
- ],
21178
- ControllingLNode: [
21186
+ status: "updated",
21187
+ oldRecord: d(t),
21188
+ newRecord: d(r)
21189
+ },
21179
21190
  {
21180
- attribute: { path: "resourceName", uuid: "resourceUuid" },
21181
- resolution: "direct",
21182
- target: ["ProcessResource"],
21183
- companions: []
21191
+ status: "updated",
21192
+ oldRecord: d(u),
21193
+ newRecord: d(s)
21184
21194
  }
21185
- ],
21186
- ControlRef: [
21195
+ ];
21196
+ }
21197
+ async function ee(a) {
21198
+ const { existingPrivateRef: e, parentRecord: t, updatedParentRecord: i, childRecord: n, query: u } = a, r = await F({
21199
+ privateId: e.id,
21200
+ query: u
21201
+ });
21202
+ if (I(r, {
21203
+ detail: "Latest private record not found",
21204
+ key: "ELEMENT_NOT_FOUND"
21205
+ }), !r.attributes.some(
21206
+ (o) => o.name === "type" && o.value === n.namespace.prefix
21207
+ )) return [];
21208
+ const { childRecord: c, privateRecord: l } = q({
21209
+ privateRecord: r,
21210
+ childRecord: n
21211
+ });
21212
+ return [
21187
21213
  {
21188
- attribute: { path: "controlled", uuid: "controlledLNodeUuid" },
21189
- resolution: "lnode",
21190
- target: ["LNode"],
21191
- companions: [{ name: "controlledDoName", required: !0 }]
21214
+ status: "updated",
21215
+ oldRecord: d(n),
21216
+ newRecord: d(c)
21192
21217
  },
21193
21218
  {
21194
- attribute: { path: "extCtrlAddr", uuid: "extCtrlUuid" },
21195
- resolution: "ied-address",
21196
- target: ["ExtCtrl"],
21197
- companions: []
21219
+ status: "updated",
21220
+ oldRecord: d(r),
21221
+ newRecord: d(l)
21198
21222
  },
21199
21223
  {
21200
- attribute: { path: "resourceName", uuid: "resourceUuid" },
21201
- resolution: "direct",
21202
- target: ["ProcessResource"],
21203
- companions: []
21204
- }
21205
- ],
21206
- DAS: [
21207
- {
21208
- attribute: { path: "mappedDaName", uuid: "mappedLnUuid" },
21209
- resolution: "lnode",
21210
- target: ["LN", "LN0"],
21211
- companions: []
21224
+ status: "updated",
21225
+ oldRecord: d(t),
21226
+ newRecord: d(i)
21212
21227
  }
21213
- ],
21214
- DOS: [
21228
+ ];
21229
+ }
21230
+ function te(a) {
21231
+ const { parentRecord: e, updatedParentRecord: t, childRecord: i } = a, n = {
21232
+ id: crypto.randomUUID(),
21233
+ tagName: "Private",
21234
+ namespace: P.namespaces.default,
21235
+ attributes: [{ name: "type", value: i.namespace.prefix }],
21236
+ value: "",
21237
+ parent: { id: e.id, tagName: e.tagName },
21238
+ children: [{ id: i.id, tagName: i.tagName }]
21239
+ }, u = {
21240
+ ...i,
21241
+ parent: { id: n.id, tagName: "Private" }
21242
+ }, r = {
21243
+ ...t,
21244
+ children: [...t.children, { id: n.id, tagName: "Private" }]
21245
+ };
21246
+ return [
21247
+ { status: "created", oldRecord: void 0, newRecord: d(n) },
21215
21248
  {
21216
- attribute: { path: "mappedDoName", uuid: "mappedLnUuid" },
21217
- resolution: "lnode",
21218
- target: ["LN", "LN0"],
21219
- companions: []
21220
- }
21221
- ],
21222
- FunctionCategoryRef: [
21249
+ status: "updated",
21250
+ oldRecord: d(i),
21251
+ newRecord: d(u)
21252
+ },
21223
21253
  {
21224
- attribute: { path: "functionCategory", uuid: "functionCategoryUuid" },
21225
- resolution: "direct",
21226
- target: ["FunctionCategory", "SubCategory"],
21227
- companions: []
21254
+ status: "updated",
21255
+ oldRecord: d(e),
21256
+ newRecord: d(r)
21228
21257
  }
21229
- ],
21230
- FunctionCatRef: [
21231
- {
21232
- attribute: { path: "function", uuid: "functionUuid" },
21233
- resolution: "direct",
21234
- target: ["Function", "SubFunction"],
21235
- companions: []
21258
+ ];
21259
+ }
21260
+ async function F(a) {
21261
+ const { privateId: e, query: t } = a;
21262
+ return await t.getRecord({ id: e, tagName: "Private" });
21263
+ }
21264
+ function q(a) {
21265
+ const { privateRecord: e, childRecord: t } = a, i = {
21266
+ ...t,
21267
+ parent: { id: e.id, tagName: "Private" }
21268
+ }, n = {
21269
+ ...e,
21270
+ children: [...e.children, { id: t.id, tagName: t.tagName }]
21271
+ };
21272
+ return { childRecord: i, privateRecord: n };
21273
+ }
21274
+ const y = {
21275
+ // Transparent - do not contribute a path segment
21276
+ AccessPoint: { type: "transparent" },
21277
+ Server: { type: "transparent" },
21278
+ Private: { type: "transparent" },
21279
+ LNodeInputs: { type: "transparent" },
21280
+ LNodeOutputs: { type: "transparent" },
21281
+ // IED section - structural containers
21282
+ LDevice: { type: "attribute", attr: "inst", separator: "/" },
21283
+ IED: { type: "name" },
21284
+ // IED section - logical nodes (targets of lnode resolution)
21285
+ LN: { type: "lnClass" },
21286
+ LN0: { type: "lnClass" },
21287
+ // IED section - data instances (dot-separated)
21288
+ DOI: { type: "name", separator: "." },
21289
+ SDI: { type: "name", separator: "." },
21290
+ DAI: { type: "name", separator: "." },
21291
+ // IED section - data references
21292
+ ExtRef: { type: "attribute", attr: "intAddr", separator: "." },
21293
+ ExtCtrl: { type: "attribute", attr: "intAddr", separator: "." },
21294
+ // Process section - named path contributors (targets of lnode / ied-address resolution)
21295
+ SourceRef: { type: "sourceRef" },
21296
+ ControlRef: { type: "controlRef" },
21297
+ // Process section - data specifications (6-100, dot-separated)
21298
+ DOS: { type: "name", separator: "." },
21299
+ DAS: { type: "name", separator: "." },
21300
+ SDS: { type: "name", separator: "." },
21301
+ // Process section - targets of direct UUID resolution
21302
+ Substation: { type: "name" },
21303
+ VoltageLevel: { type: "name" },
21304
+ Bay: { type: "name" },
21305
+ Line: { type: "name" },
21306
+ ConductingEquipment: { type: "name" },
21307
+ ConnectivityNode: { type: "name" },
21308
+ PowerTransformer: { type: "name" },
21309
+ TransformerWinding: { type: "name" },
21310
+ TapChanger: { type: "name" },
21311
+ GeneralEquipment: { type: "name" },
21312
+ SubEquipment: { type: "name" },
21313
+ LNode: { type: "lnClass" },
21314
+ Function: { type: "name" },
21315
+ SubFunction: { type: "name" },
21316
+ FunctionTemplate: { type: "name" },
21317
+ SubFunctionTemplate: { type: "name" },
21318
+ EqFunction: { type: "name" },
21319
+ EqSubFunction: { type: "name" },
21320
+ Application: { type: "name" },
21321
+ AllocationRole: { type: "name" },
21322
+ BehaviorDescription: { type: "name" },
21323
+ FunctionCategory: { type: "name" },
21324
+ SubCategory: { type: "name" },
21325
+ FunctionalVariant: { type: "name" },
21326
+ FunctionalSubVariant: { type: "name" },
21327
+ FunctionalVariantGroup: { type: "name" },
21328
+ ProcessResource: { type: "name" },
21329
+ PowerSystemRelation: { type: "name" },
21330
+ Variable: { type: "name" },
21331
+ Process: { type: "name" }
21332
+ }, ae = ["lnClass", "prefix", "inst", "lnInst"], ie = new Set(
21333
+ Object.values(y).flatMap((a) => {
21334
+ switch (a.type) {
21335
+ case "transparent":
21336
+ return [];
21337
+ case "name":
21338
+ return ["name"];
21339
+ case "lnClass":
21340
+ return [...ae];
21341
+ case "attribute":
21342
+ return [a.attr];
21343
+ case "sourceRef":
21344
+ return ["input", "inputInst", "pDA"];
21345
+ case "controlRef":
21346
+ return ["output", "outputInst"];
21236
21347
  }
21237
- ],
21238
- FunctionRef: [
21239
- {
21240
- attribute: { path: "function", uuid: "functionUuid" },
21241
- resolution: "direct",
21242
- target: ["Function", "SubFunction", "EqFunction", "EqSubFunction"],
21243
- companions: []
21348
+ })
21349
+ );
21350
+ function ne(a) {
21351
+ switch (a.type) {
21352
+ case "transparent":
21353
+ return () => null;
21354
+ case "name": {
21355
+ const e = a.separator ?? "/";
21356
+ return (t) => {
21357
+ const i = b(t, "name");
21358
+ return i ? { segment: i, separator: e } : null;
21359
+ };
21244
21360
  }
21245
- ],
21246
- FunctionalVariantRef: [
21247
- {
21248
- attribute: { path: "functionalVariant", uuid: "functionalVariantUuid" },
21249
- resolution: "direct",
21250
- target: ["FunctionalVariant", "FunctionalSubVariant"],
21251
- companions: []
21361
+ case "lnClass":
21362
+ return (e) => {
21363
+ const t = b(e, "lnClass");
21364
+ if (!t) return null;
21365
+ const i = b(e, "prefix") ?? "", n = b(e, "inst") ?? b(e, "lnInst") ?? "";
21366
+ return { segment: `${i}${t}${n}`, separator: "/" };
21367
+ };
21368
+ case "attribute":
21369
+ return (e) => {
21370
+ const t = b(e, a.attr);
21371
+ return t ? { segment: t, separator: a.separator } : null;
21372
+ };
21373
+ case "sourceRef":
21374
+ return (e) => {
21375
+ const t = b(e, "input");
21376
+ if (!t) return null;
21377
+ let i = t;
21378
+ const n = b(e, "inputInst");
21379
+ n && n !== "1" && (i += `(${n})`);
21380
+ const u = b(e, "pDA");
21381
+ return u && (i += `.${u}`), { segment: i, separator: "." };
21382
+ };
21383
+ case "controlRef":
21384
+ return (e) => {
21385
+ const t = b(e, "output");
21386
+ if (!t) return null;
21387
+ let i = t;
21388
+ const n = b(e, "outputInst");
21389
+ return n && n !== "1" && (i += `(${n})`), { segment: i, separator: "." };
21390
+ };
21391
+ }
21392
+ }
21393
+ const re = Object.fromEntries(
21394
+ Object.entries(y).map(([a, e]) => [a, ne(e)])
21395
+ );
21396
+ function L(a) {
21397
+ const e = re[a.tagName];
21398
+ return e ? e(a) : null;
21399
+ }
21400
+ function x(a) {
21401
+ const { record: e, ancestry: t } = a, i = [];
21402
+ for (const u of t) {
21403
+ const r = L(u);
21404
+ r && i.push({ ...r, ref: { tagName: u.tagName, id: u.id } });
21405
+ }
21406
+ const n = L(e);
21407
+ return n && i.push({ ...n, ref: { tagName: e.tagName, id: e.id } }), i.length === 0 ? null : { path: O(i), segments: i };
21408
+ }
21409
+ function b(a, e) {
21410
+ return a.attributes.find((t) => t.name === e)?.value;
21411
+ }
21412
+ function O(a) {
21413
+ let e = a[0].segment;
21414
+ for (let t = 1; t < a.length; t++)
21415
+ e += a[t].separator + a[t].segment;
21416
+ return e;
21417
+ }
21418
+ async function E(a, e) {
21419
+ const t = await a.getRecord(e);
21420
+ if (!t) return null;
21421
+ const i = await a.findAncestors(e, { order: "top-down" });
21422
+ return x({
21423
+ record: d(t),
21424
+ ancestry: i.map(d)
21425
+ });
21426
+ }
21427
+ function k(a) {
21428
+ if (!a) return [];
21429
+ const e = [];
21430
+ let t = "", i = "/";
21431
+ for (const n of a)
21432
+ n === "/" || n === "." ? (t && e.push({ segment: t, separator: i }), i = n, t = "") : t += n;
21433
+ return t && e.push({ segment: t, separator: i }), e;
21434
+ }
21435
+ function V(a) {
21436
+ const e = a.split("/"), t = e[e.length - 1], i = t.indexOf(".");
21437
+ if (i === -1) return { path: a };
21438
+ const n = t.substring(0, i), u = t.substring(i + 1);
21439
+ return { path: [...e.slice(0, -1), n].join("/"), qualifier: u || void 0 };
21440
+ }
21441
+ function Z(a, e, t, i) {
21442
+ return !a || a === f.unsupported ? null : a === f.direct ? { lookupKey: t } : a === f.iedAddress ? se(t, i) : a === f.lnode ? ue(t) : a === f.behaviorDescription ? ce(e, t, i) : null;
21443
+ }
21444
+ function ue(a) {
21445
+ const { path: e, qualifier: t } = V(a);
21446
+ return { lookupKey: e, qualifier: t };
21447
+ }
21448
+ function se(a, e) {
21449
+ if (e) {
21450
+ const t = de(e);
21451
+ if (t)
21452
+ return { lookupKey: a, fallbackLookupKey: `${t}/${a}` };
21453
+ }
21454
+ return { lookupKey: a };
21455
+ }
21456
+ function ce(a, e, t) {
21457
+ if (!t) return null;
21458
+ const i = oe(t);
21459
+ if (!i) return null;
21460
+ if (a === "dataName")
21461
+ return { lookupKey: i, qualifier: e };
21462
+ if (a === "inputName" || a === "outputName") {
21463
+ const n = le(e);
21464
+ return { lookupKey: `${i}.${n}` };
21465
+ }
21466
+ return null;
21467
+ }
21468
+ function oe(a) {
21469
+ let e = -1;
21470
+ for (let i = a.length - 1; i >= 0; i--)
21471
+ if (a[i].tagName === "BehaviorDescription") {
21472
+ e = i;
21473
+ break;
21252
21474
  }
21253
- ],
21254
- InputVar: [
21255
- {
21256
- attribute: { path: "dataName", uuid: "lnodeUuid" },
21257
- resolution: "behavior-description",
21258
- target: ["LNode"],
21259
- companions: [
21260
- { name: "doName", required: !0 },
21261
- { name: "daName", required: !1 }
21262
- ]
21263
- },
21475
+ if (e === -1) return null;
21476
+ const t = [];
21477
+ for (let i = 0; i < e; i++) {
21478
+ const n = L(a[i]);
21479
+ n && t.push(n);
21480
+ }
21481
+ return t.length === 0 ? null : O(t);
21482
+ }
21483
+ function le(a) {
21484
+ const e = a.indexOf("("), t = a.indexOf(".");
21485
+ return e !== -1 ? a.substring(0, e) : t !== -1 ? a.substring(0, t) : a;
21486
+ }
21487
+ function de(a) {
21488
+ for (let e = a.length - 1; e >= 0; e--)
21489
+ if (a[e].tagName === "LNode")
21490
+ return a[e].attributes.find((t) => t.name === "iedName")?.value ?? null;
21491
+ return null;
21492
+ }
21493
+ async function M(a, e) {
21494
+ const { reference: t, target: i } = e, n = pe(t.tagName, i.tagName);
21495
+ if (!n) return null;
21496
+ const u = n.resolution;
21497
+ if (u === f.unsupported) return null;
21498
+ if (u === f.behaviorDescription) {
21499
+ const c = await a.getRecord(i);
21500
+ return c ? L(d(c))?.segment ?? null : null;
21501
+ }
21502
+ const r = await E(a, i);
21503
+ if (!r) return null;
21504
+ const s = r.path;
21505
+ if (u === f.lnode) {
21506
+ const c = await a.getRecord(t);
21507
+ if (!c) return s;
21508
+ const l = c.attributes.find((p) => p.name === n.attribute.path)?.value;
21509
+ if (!l) return s;
21510
+ const { qualifier: o } = V(l);
21511
+ return o ? `${s}.${o}` : s;
21512
+ }
21513
+ return s;
21514
+ }
21515
+ function pe(a, e) {
21516
+ const t = m[a];
21517
+ return t ? t.find((i) => i.target.includes(e)) ?? null : null;
21518
+ }
21519
+ async function Se(a, e, t) {
21520
+ const i = fe(e.tagName, t);
21521
+ if (!i) return;
21522
+ const n = e.attributes.find((p) => p.name === t)?.value;
21523
+ if (!n) return;
21524
+ let u;
21525
+ (i.resolution === f.behaviorDescription || i.resolution === f.iedAddress) && (u = (await a.findAncestors(e, { order: "top-down" })).map((R) => d(R)));
21526
+ const r = Z(
21527
+ i.resolution,
21528
+ t,
21529
+ n,
21530
+ u
21531
+ );
21532
+ if (!r) return;
21533
+ const s = k(r.lookupKey);
21534
+ if (s.length === 0) return;
21535
+ const c = s[s.length - 1], l = s.slice(0, -1), o = await Le({
21536
+ query: a,
21537
+ targets: i.target,
21538
+ segment: c,
21539
+ expectedAncestry: l
21540
+ });
21541
+ if (o)
21542
+ return { record: o, qualifier: r.qualifier };
21543
+ }
21544
+ function fe(a, e) {
21545
+ const t = m[a];
21546
+ if (t)
21547
+ return t.find((i) => i.attribute.path === e);
21548
+ }
21549
+ const me = new Set(
21550
+ D.LNode.attributes.details.lnClass.facets.enumeration
21551
+ ), be = {
21552
+ LNode: "lnInst",
21553
+ LN: "inst",
21554
+ LN0: "inst"
21555
+ };
21556
+ function Re(a) {
21557
+ for (let e = 0; e <= a.length - 4; e++) {
21558
+ const t = a.substring(e, e + 4);
21559
+ if (me.has(t))
21560
+ return {
21561
+ prefix: a.substring(0, e),
21562
+ lnClass: t,
21563
+ inst: a.substring(e + 4)
21564
+ };
21565
+ }
21566
+ return null;
21567
+ }
21568
+ async function Le(a) {
21569
+ const { query: e, targets: t, segment: i, expectedAncestry: n } = a;
21570
+ for (const u of t) {
21571
+ const r = be[u];
21572
+ if (r) {
21573
+ const s = await Pe({
21574
+ query: e,
21575
+ tagName: u,
21576
+ segment: i,
21577
+ instAttr: r,
21578
+ expectedAncestry: n
21579
+ });
21580
+ if (s) return s;
21581
+ } else {
21582
+ const s = await Ce({
21583
+ query: e,
21584
+ tagName: u,
21585
+ segment: i,
21586
+ expectedAncestry: n
21587
+ });
21588
+ if (s) return s;
21589
+ }
21590
+ }
21591
+ }
21592
+ async function Pe(a) {
21593
+ const { query: e, tagName: t, segment: i, instAttr: n, expectedAncestry: u } = a, r = Re(i.segment);
21594
+ if (!r) return;
21595
+ const s = await e.findByAttributes({
21596
+ tagName: t,
21597
+ attributes: { lnClass: r.lnClass }
21598
+ });
21599
+ for (const c of s) {
21600
+ const l = c.attributes.find((p) => p.name === "prefix")?.value ?? "", o = c.attributes.find((p) => p.name === n)?.value ?? "";
21601
+ if (!(l !== r.prefix || o !== r.inst) && await G(e, c, u))
21602
+ return c;
21603
+ }
21604
+ }
21605
+ async function Ce(a) {
21606
+ const { query: e, tagName: t, segment: i, expectedAncestry: n } = a, u = await e.getRecordsByTagName(t);
21607
+ for (const r of u) {
21608
+ const s = L(d(r));
21609
+ if (!(!s || s.segment !== i.segment) && await G(e, r, n))
21610
+ return r;
21611
+ }
21612
+ }
21613
+ async function G(a, e, t) {
21614
+ if (t.length === 0) return !0;
21615
+ const i = await a.findAncestors(e), n = [];
21616
+ for (let u = i.length - 1; u >= 0; u--) {
21617
+ const r = L(d(i[u]));
21618
+ r && n.push(r);
21619
+ }
21620
+ return n.length !== t.length ? !1 : n.every((u, r) => u.segment === t[r].segment);
21621
+ }
21622
+ async function Ae(a, e) {
21623
+ const t = k(e);
21624
+ if (t.length === 0) return;
21625
+ const i = await a.getRoot();
21626
+ return v({
21627
+ query: a,
21628
+ current: i,
21629
+ segments: t,
21630
+ index: 0
21631
+ });
21632
+ }
21633
+ async function v(a) {
21634
+ const { query: e, current: t, segments: i, index: n } = a;
21635
+ if (n >= i.length) return t;
21636
+ const u = t.children ?? [];
21637
+ if (u.length === 0) return;
21638
+ const r = await e.getRecords(u), s = i[n];
21639
+ for (const c of r) {
21640
+ if (!c) continue;
21641
+ const l = L(d(c));
21642
+ if (!l) {
21643
+ const o = await v({ query: e, current: c, segments: i, index: n });
21644
+ if (o) return o;
21645
+ continue;
21646
+ }
21647
+ if (l.segment === s.segment && l.separator === s.separator)
21648
+ return v({ query: e, current: c, segments: i, index: n + 1 });
21649
+ }
21650
+ }
21651
+ const f = {
21652
+ direct: "direct",
21653
+ lnode: "lnode",
21654
+ iedAddress: "ied-address",
21655
+ behaviorDescription: "behavior-description",
21656
+ unsupported: "unsupported"
21657
+ }, m = {
21658
+ AllocationRoleRef: [
21264
21659
  {
21265
- attribute: { path: "inputName", uuid: "inputUuid" },
21266
- resolution: "behavior-description",
21267
- target: ["SourceRef"],
21660
+ attribute: { path: "allocationRole", uuid: "allocationRoleUuid" },
21661
+ resolution: "direct",
21662
+ target: ["AllocationRole"],
21268
21663
  companions: []
21269
21664
  }
21270
21665
  ],
21271
- LNodeDataRef: [
21666
+ BehaviorDescriptionRef: [
21272
21667
  {
21273
- attribute: { path: "data", uuid: "lnodeUuid" },
21274
- resolution: "lnode",
21275
- target: ["LNode"],
21276
- companions: [
21277
- { name: "doName", required: !0 },
21278
- { name: "daName", required: !1 }
21279
- ]
21668
+ attribute: { path: "behaviorDescription", uuid: "behaviorDescriptionUuid" },
21669
+ resolution: "direct",
21670
+ target: ["BehaviorDescription"],
21671
+ companions: []
21280
21672
  }
21281
21673
  ],
21282
- LNodeInputRef: [
21674
+ BehaviorReference: [
21283
21675
  {
21284
- attribute: { path: "sourceRef", uuid: "sourceRefUuid" },
21676
+ attribute: { path: "behaviorReference", uuid: "behaviorUuid" },
21285
21677
  resolution: "direct",
21286
- target: ["SourceRef"],
21678
+ target: ["BehaviorDescription"],
21287
21679
  companions: []
21288
21680
  }
21289
21681
  ],
21290
- LNodeOutputRef: [
21682
+ ControllingLNode: [
21291
21683
  {
21292
- attribute: { path: "controlRef", uuid: "controlRefUuid" },
21684
+ attribute: { path: "resourceName", uuid: "resourceUuid" },
21293
21685
  resolution: "direct",
21294
- target: ["ControlRef"],
21686
+ target: ["ProcessResource"],
21295
21687
  companions: []
21296
21688
  }
21297
21689
  ],
21298
- OutputVar: [
21690
+ ControlRef: [
21299
21691
  {
21300
- attribute: { path: "dataName", uuid: "lnodeUuid" },
21301
- resolution: "behavior-description",
21302
- target: ["LNode"],
21692
+ attribute: { path: "controlled", uuid: "controlledLNodeUuid" },
21693
+ resolution: "lnode",
21694
+ target: ["LNode"],
21695
+ companions: [{ name: "controlledDoName", required: !0 }]
21696
+ },
21697
+ {
21698
+ attribute: { path: "extCtrlAddr", uuid: "extCtrlUuid" },
21699
+ resolution: "ied-address",
21700
+ target: ["ExtCtrl"],
21701
+ companions: []
21702
+ },
21703
+ {
21704
+ attribute: { path: "resourceName", uuid: "resourceUuid" },
21705
+ resolution: "direct",
21706
+ target: ["ProcessResource"],
21707
+ companions: []
21708
+ }
21709
+ ],
21710
+ DAS: [
21711
+ {
21712
+ attribute: { path: "mappedDaName", uuid: "mappedLnUuid" },
21713
+ resolution: "lnode",
21714
+ target: ["LN", "LN0"],
21715
+ companions: []
21716
+ }
21717
+ ],
21718
+ DOS: [
21719
+ {
21720
+ attribute: { path: "mappedDoName", uuid: "mappedLnUuid" },
21721
+ resolution: "lnode",
21722
+ target: ["LN", "LN0"],
21723
+ companions: []
21724
+ }
21725
+ ],
21726
+ FunctionCategoryRef: [
21727
+ {
21728
+ attribute: { path: "functionCategory", uuid: "functionCategoryUuid" },
21729
+ resolution: "direct",
21730
+ target: ["FunctionCategory", "SubCategory"],
21731
+ companions: []
21732
+ }
21733
+ ],
21734
+ FunctionCatRef: [
21735
+ {
21736
+ attribute: { path: "function", uuid: "functionUuid" },
21737
+ resolution: "direct",
21738
+ target: ["Function", "SubFunction"],
21739
+ companions: []
21740
+ }
21741
+ ],
21742
+ FunctionRef: [
21743
+ {
21744
+ attribute: { path: "function", uuid: "functionUuid" },
21745
+ resolution: "direct",
21746
+ target: ["Function", "SubFunction", "EqFunction", "EqSubFunction"],
21747
+ companions: []
21748
+ }
21749
+ ],
21750
+ FunctionalVariantRef: [
21751
+ {
21752
+ attribute: { path: "functionalVariant", uuid: "functionalVariantUuid" },
21753
+ resolution: "direct",
21754
+ target: ["FunctionalVariant", "FunctionalSubVariant"],
21755
+ companions: []
21756
+ }
21757
+ ],
21758
+ InputVar: [
21759
+ {
21760
+ attribute: { path: "dataName", uuid: "lnodeUuid" },
21761
+ resolution: "behavior-description",
21762
+ target: ["LNode"],
21763
+ companions: [
21764
+ { name: "doName", required: !0 },
21765
+ { name: "daName", required: !1 }
21766
+ ]
21767
+ },
21768
+ {
21769
+ attribute: { path: "inputName", uuid: "inputUuid" },
21770
+ resolution: "behavior-description",
21771
+ target: ["SourceRef"],
21772
+ companions: []
21773
+ }
21774
+ ],
21775
+ LNodeDataRef: [
21776
+ {
21777
+ attribute: { path: "data", uuid: "lnodeUuid" },
21778
+ resolution: "lnode",
21779
+ target: ["LNode"],
21780
+ companions: [
21781
+ { name: "doName", required: !0 },
21782
+ { name: "daName", required: !1 }
21783
+ ]
21784
+ }
21785
+ ],
21786
+ LNodeInputRef: [
21787
+ {
21788
+ attribute: { path: "sourceRef", uuid: "sourceRefUuid" },
21789
+ resolution: "direct",
21790
+ target: ["SourceRef"],
21791
+ companions: []
21792
+ }
21793
+ ],
21794
+ LNodeOutputRef: [
21795
+ {
21796
+ attribute: { path: "controlRef", uuid: "controlRefUuid" },
21797
+ resolution: "direct",
21798
+ target: ["ControlRef"],
21799
+ companions: []
21800
+ }
21801
+ ],
21802
+ OutputVar: [
21803
+ {
21804
+ attribute: { path: "dataName", uuid: "lnodeUuid" },
21805
+ resolution: "behavior-description",
21806
+ target: ["LNode"],
21303
21807
  companions: [
21304
21808
  { name: "doName", required: !0 },
21305
21809
  { name: "daName", required: !1 }
@@ -21403,788 +21907,190 @@ const H = [
21403
21907
  {
21404
21908
  attribute: { path: "extRefAddr", uuid: "extRefUuid" },
21405
21909
  resolution: "ied-address",
21406
- target: ["ExtRef"],
21407
- companions: []
21408
- },
21409
- {
21410
- attribute: { path: "resourceName", uuid: "resourceUuid" },
21411
- resolution: "direct",
21412
- target: ["ProcessResource"],
21413
- companions: []
21414
- }
21415
- ],
21416
- SubscriberLNode: [
21417
- {
21418
- attribute: { path: "resourceName", uuid: "resourceUuid" },
21419
- resolution: "direct",
21420
- target: ["ProcessResource"],
21421
- companions: []
21422
- }
21423
- ],
21424
- VariableApplyTo: [
21425
- {
21426
- attribute: { path: "element", uuid: "elementUuid" },
21427
- resolution: "unsupported",
21428
- target: ["LNode", "Function", "SubFunction", "EqFunction", "EqSubFunction"],
21429
- companions: [
21430
- { name: "doName", required: !1 },
21431
- { name: "daName", required: !1 }
21432
- ]
21433
- }
21434
- ],
21435
- VariableRef: [
21436
- {
21437
- attribute: { path: "variable", uuid: "variableUuid" },
21438
- resolution: "direct",
21439
- target: ["Variable"],
21440
- companions: []
21441
- }
21442
- ]
21443
- };
21444
- function $(a) {
21445
- const e = {};
21446
- for (const [t, i] of Object.entries(a))
21447
- for (const n of i) {
21448
- const s = e[n.resolution] ??= /* @__PURE__ */ new Map();
21449
- for (const r of n.target) {
21450
- const u = s.get(r) ?? [];
21451
- u.push({
21452
- refTagName: t,
21453
- uuidAttr: n.attribute.uuid,
21454
- pathAttr: n.attribute.path
21455
- }), s.set(r, u);
21456
- }
21457
- }
21458
- return e;
21459
- }
21460
- function J(a) {
21461
- const e = /* @__PURE__ */ new Map();
21462
- for (const [t, i] of Object.entries(a))
21463
- e.set(
21464
- t,
21465
- i.map((n) => ({
21466
- uuidAttr: n.attribute.uuid,
21467
- pathAttr: n.attribute.path,
21468
- resolution: n.resolution,
21469
- targetTagNames: n.target
21470
- }))
21471
- );
21472
- return e;
21473
- }
21474
- const F = $(m), q = [
21475
- f.direct,
21476
- f.lnode,
21477
- f.iedAddress,
21478
- f.behaviorDescription
21479
- ], ee = J(m);
21480
- [
21481
- ...new Set(
21482
- Object.values(m).flatMap(
21483
- (a) => a.map((e) => e.attribute.uuid)
21484
- )
21485
- )
21486
- ];
21487
- const te = /* @__PURE__ */ new Set(["SourceRef", "ControlRef", "DOS", "SDS", "DAS", "InputVar", "OutputVar", "ProcessEcho"]), mt = {
21488
- FunctionCatRef: ["SubCategory", "FunctionCategory"],
21489
- PowerSystemRelation: ["PowerSystemRelations"],
21490
- Resource: ["ProcessResource", "ProcessResources"],
21491
- VariableApplyTo: ["Variable"]
21492
- }, y = {
21493
- // Transparent - do not contribute a path segment
21494
- AccessPoint: { type: "transparent" },
21495
- Server: { type: "transparent" },
21496
- Private: { type: "transparent" },
21497
- LNodeInputs: { type: "transparent" },
21498
- LNodeOutputs: { type: "transparent" },
21499
- // IED section - structural containers
21500
- LDevice: { type: "attribute", attr: "inst", separator: "/" },
21501
- IED: { type: "name" },
21502
- // IED section - logical nodes (targets of lnode resolution)
21503
- LN: { type: "lnClass" },
21504
- LN0: { type: "lnClass" },
21505
- // IED section - data instances (dot-separated)
21506
- DOI: { type: "name", separator: "." },
21507
- SDI: { type: "name", separator: "." },
21508
- DAI: { type: "name", separator: "." },
21509
- // IED section - data references
21510
- ExtRef: { type: "attribute", attr: "intAddr", separator: "." },
21511
- ExtCtrl: { type: "attribute", attr: "intAddr", separator: "." },
21512
- // Process section - named path contributors (targets of lnode / ied-address resolution)
21513
- SourceRef: { type: "attribute", attr: "input", separator: "." },
21514
- ControlRef: { type: "attribute", attr: "output", separator: "." },
21515
- // Process section - data specifications (6-100, dot-separated)
21516
- DOS: { type: "name", separator: "." },
21517
- DAS: { type: "name", separator: "." },
21518
- SDS: { type: "name", separator: "." },
21519
- // Process section - targets of direct UUID resolution
21520
- Substation: { type: "name" },
21521
- VoltageLevel: { type: "name" },
21522
- Bay: { type: "name" },
21523
- Line: { type: "name" },
21524
- ConductingEquipment: { type: "name" },
21525
- ConnectivityNode: { type: "name" },
21526
- PowerTransformer: { type: "name" },
21527
- TransformerWinding: { type: "name" },
21528
- TapChanger: { type: "name" },
21529
- GeneralEquipment: { type: "name" },
21530
- SubEquipment: { type: "name" },
21531
- LNode: { type: "lnClass" },
21532
- Function: { type: "name" },
21533
- SubFunction: { type: "name" },
21534
- FunctionTemplate: { type: "name" },
21535
- SubFunctionTemplate: { type: "name" },
21536
- EqFunction: { type: "name" },
21537
- EqSubFunction: { type: "name" },
21538
- Application: { type: "name" },
21539
- AllocationRole: { type: "name" },
21540
- BehaviorDescription: { type: "name" },
21541
- FunctionCategory: { type: "name" },
21542
- SubCategory: { type: "name" },
21543
- FunctionalVariant: { type: "name" },
21544
- FunctionalSubVariant: { type: "name" },
21545
- FunctionalVariantGroup: { type: "name" },
21546
- ProcessResource: { type: "name" },
21547
- PowerSystemRelation: { type: "name" },
21548
- Variable: { type: "name" },
21549
- Process: { type: "name" }
21550
- }, ae = ["lnClass", "prefix", "inst", "lnInst"], ie = new Set(
21551
- Object.values(y).flatMap((a) => {
21552
- switch (a.type) {
21553
- case "transparent":
21554
- return [];
21555
- case "name":
21556
- return ["name"];
21557
- case "lnClass":
21558
- return [...ae];
21559
- case "attribute":
21560
- return [a.attr];
21561
- }
21562
- })
21563
- );
21564
- function ne(a) {
21565
- switch (a.type) {
21566
- case "transparent":
21567
- return () => null;
21568
- case "name": {
21569
- const e = a.separator ?? "/";
21570
- return (t) => {
21571
- const i = P(t, "name");
21572
- return i ? { segment: i, separator: e } : null;
21573
- };
21574
- }
21575
- case "lnClass":
21576
- return (e) => {
21577
- const t = P(e, "lnClass");
21578
- if (!t) return null;
21579
- const i = P(e, "prefix") ?? "", n = P(e, "inst") ?? P(e, "lnInst") ?? "";
21580
- return { segment: `${i}${t}${n}`, separator: "/" };
21581
- };
21582
- case "attribute":
21583
- return (e) => {
21584
- const t = P(e, a.attr);
21585
- return t ? { segment: t, separator: a.separator } : null;
21586
- };
21587
- }
21588
- }
21589
- const re = Object.fromEntries(
21590
- Object.entries(y).map(([a, e]) => [a, ne(e)])
21591
- );
21592
- function R(a) {
21593
- const e = re[a.tagName];
21594
- return e ? e(a) : null;
21595
- }
21596
- function x(a) {
21597
- const { record: e, ancestry: t } = a, i = [];
21598
- for (const s of t) {
21599
- const r = R(s);
21600
- r && i.push({ ...r, ref: { tagName: s.tagName, id: s.id } });
21601
- }
21602
- const n = R(e);
21603
- return n && i.push({ ...n, ref: { tagName: e.tagName, id: e.id } }), i.length === 0 ? null : { path: O(i), segments: i };
21604
- }
21605
- function P(a, e) {
21606
- return a.attributes.find((t) => t.name === e)?.value;
21607
- }
21608
- function O(a) {
21609
- let e = a[0].segment;
21610
- for (let t = 1; t < a.length; t++)
21611
- e += a[t].separator + a[t].segment;
21612
- return e;
21613
- }
21614
- async function E(a, e) {
21615
- const t = await a.getRecord(e);
21616
- if (!t) return null;
21617
- const i = await a.findAncestors(e, { order: "top-down" });
21618
- return x({
21619
- record: d(t),
21620
- ancestry: i.map(d)
21621
- });
21622
- }
21623
- async function k(a, e) {
21624
- const { reference: t, target: i } = e, n = ue(t.tagName, i.tagName);
21625
- if (!n) return null;
21626
- const s = n.resolution;
21627
- if (s === f.unsupported) return null;
21628
- if (s === f.behaviorDescription) {
21629
- const c = await a.getRecord(i);
21630
- return c ? R(d(c))?.segment ?? null : null;
21631
- }
21632
- const r = await E(a, i);
21633
- if (!r) return null;
21634
- const u = r.path;
21635
- if (s === f.lnode) {
21636
- const c = await a.getRecord(t);
21637
- if (!c) return u;
21638
- const l = c.attributes.find((p) => p.name === n.attribute.path)?.value;
21639
- if (!l) return u;
21640
- const { qualifier: o } = G(l);
21641
- return o ? `${u}.${o}` : u;
21642
- }
21643
- return u;
21644
- }
21645
- function ue(a, e) {
21646
- const t = m[a];
21647
- return t ? t.find((i) => i.target.includes(e)) ?? null : null;
21648
- }
21649
- async function se(a, e, t) {
21650
- const i = ce(e.tagName, t);
21651
- if (!i) return;
21652
- const n = e.attributes.find((p) => p.name === t)?.value;
21653
- if (!n) return;
21654
- let s;
21655
- (i.resolution === f.behaviorDescription || i.resolution === f.iedAddress) && (s = (await a.findAncestors(e, { order: "top-down" })).map((b) => d(b)));
21656
- const r = B(
21657
- i.resolution,
21658
- t,
21659
- n,
21660
- s
21661
- );
21662
- if (!r) return;
21663
- const u = M(r.lookupKey);
21664
- if (u.length === 0) return;
21665
- const c = u[u.length - 1], l = u.slice(0, -1), o = await pe({
21666
- query: a,
21667
- targets: i.target,
21668
- segment: c,
21669
- expectedAncestry: l
21670
- });
21671
- if (o)
21672
- return { record: o, qualifier: r.qualifier };
21673
- }
21674
- function ce(a, e) {
21675
- const t = m[a];
21676
- if (t)
21677
- return t.find((i) => i.attribute.path === e);
21678
- }
21679
- const oe = new Set(
21680
- D.LNode.attributes.details.lnClass.facets.enumeration
21681
- ), le = {
21682
- LNode: "lnInst",
21683
- LN: "inst",
21684
- LN0: "inst"
21685
- };
21686
- function de(a) {
21687
- for (let e = 0; e <= a.length - 4; e++) {
21688
- const t = a.substring(e, e + 4);
21689
- if (oe.has(t))
21690
- return {
21691
- prefix: a.substring(0, e),
21692
- lnClass: t,
21693
- inst: a.substring(e + 4)
21694
- };
21695
- }
21696
- return null;
21697
- }
21698
- async function pe(a) {
21699
- const { query: e, targets: t, segment: i, expectedAncestry: n } = a;
21700
- for (const s of t) {
21701
- const r = le[s];
21702
- if (r) {
21703
- const u = await Se({
21704
- query: e,
21705
- tagName: s,
21706
- segment: i,
21707
- instAttr: r,
21708
- expectedAncestry: n
21709
- });
21710
- if (u) return u;
21711
- } else {
21712
- const u = await fe({
21713
- query: e,
21714
- tagName: s,
21715
- segment: i,
21716
- expectedAncestry: n
21717
- });
21718
- if (u) return u;
21719
- }
21720
- }
21721
- }
21722
- async function Se(a) {
21723
- const { query: e, tagName: t, segment: i, instAttr: n, expectedAncestry: s } = a, r = de(i.segment);
21724
- if (!r) return;
21725
- const u = await e.findByAttributes({
21726
- tagName: t,
21727
- attributes: { lnClass: r.lnClass }
21728
- });
21729
- for (const c of u) {
21730
- const l = c.attributes.find((p) => p.name === "prefix")?.value ?? "", o = c.attributes.find((p) => p.name === n)?.value ?? "";
21731
- if (!(l !== r.prefix || o !== r.inst) && await V(e, c, s))
21732
- return c;
21733
- }
21734
- }
21735
- async function fe(a) {
21736
- const { query: e, tagName: t, segment: i, expectedAncestry: n } = a, s = await e.getRecordsByTagName(t);
21737
- for (const r of s) {
21738
- const u = R(d(r));
21739
- if (!(!u || u.segment !== i.segment) && await V(e, r, n))
21740
- return r;
21741
- }
21742
- }
21743
- async function V(a, e, t) {
21744
- if (t.length === 0) return !0;
21745
- const i = await a.findAncestors(e), n = [];
21746
- for (let s = i.length - 1; s >= 0; s--) {
21747
- const r = R(d(i[s]));
21748
- r && n.push(r);
21749
- }
21750
- return n.length !== t.length ? !1 : n.every((s, r) => s.segment === t[r].segment);
21751
- }
21752
- async function me(a, e) {
21753
- const t = M(e);
21754
- if (t.length === 0) return;
21755
- const i = await a.getRoot();
21756
- return v({
21757
- query: a,
21758
- current: i,
21759
- segments: t,
21760
- index: 0
21761
- });
21762
- }
21763
- async function v(a) {
21764
- const { query: e, current: t, segments: i, index: n } = a;
21765
- if (n >= i.length) return t;
21766
- const s = t.children ?? [];
21767
- if (s.length === 0) return;
21768
- const r = await e.getRecords(s), u = i[n];
21769
- for (const c of r) {
21770
- if (!c) continue;
21771
- const l = R(d(c));
21772
- if (!l) {
21773
- const o = await v({ query: e, current: c, segments: i, index: n });
21774
- if (o) return o;
21775
- continue;
21776
- }
21777
- if (l.segment === u.segment && l.separator === u.separator)
21778
- return v({ query: e, current: c, segments: i, index: n + 1 });
21779
- }
21780
- }
21781
- async function be(a, e) {
21782
- const { target: t, containerTagName: i } = e, n = await a.getRecord(t);
21783
- if (!n) return [];
21784
- const s = n.attributes.find((c) => c.name === "uuid")?.value;
21785
- if (!s) return [];
21786
- const r = Re(n.tagName);
21787
- if (r.length === 0) return [];
21788
- const u = [];
21789
- for (const c of r) {
21790
- if (!T(c.refTagName, L)) continue;
21791
- const l = await a.findByAttributes({
21792
- tagName: c.refTagName,
21793
- attributes: { [c.uuidAttr]: s }
21794
- });
21795
- for (const o of l) {
21796
- const p = i ? await Le(a, o, i) : void 0;
21797
- u.push({ ref: o, container: p });
21798
- }
21799
- }
21800
- return u;
21801
- }
21802
- function Re(a) {
21803
- const e = [];
21804
- for (const t of q) {
21805
- const i = F[t].get(a);
21806
- i && e.push(...i);
21807
- }
21808
- return e;
21809
- }
21810
- async function Le(a, e, t) {
21811
- return (await a.findAncestors(e, { stopAtTagName: t })).find((n) => n.tagName === t);
21812
- }
21813
- const Pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
21814
- __proto__: null,
21815
- buildElementPath: E,
21816
- buildReferencePath: k,
21817
- findRefsPointingTo: be,
21818
- resolveElementPath: me,
21819
- resolveReferencePath: se
21820
- }, Symbol.toStringTag, { value: "Module" })), Z = {
21821
- query: Pe
21822
- };
21823
- function M(a) {
21824
- if (!a) return [];
21825
- const e = [];
21826
- let t = "", i = "/";
21827
- for (const n of a)
21828
- n === "/" || n === "." ? (t && e.push({ segment: t, separator: i }), i = n, t = "") : t += n;
21829
- return t && e.push({ segment: t, separator: i }), e;
21830
- }
21831
- function G(a) {
21832
- const e = a.split("/"), t = e[e.length - 1], i = t.indexOf(".");
21833
- if (i === -1) return { path: a };
21834
- const n = t.substring(0, i), s = t.substring(i + 1);
21835
- return { path: [...e.slice(0, -1), n].join("/"), qualifier: s || void 0 };
21836
- }
21837
- function B(a, e, t, i) {
21838
- return !a || a === f.unsupported ? null : a === f.direct ? { lookupKey: t } : a === f.iedAddress ? Ae(t, i) : a === f.lnode ? Ce(t) : a === f.behaviorDescription ? ge(e, t, i) : null;
21839
- }
21840
- function Ce(a) {
21841
- const { path: e, qualifier: t } = G(a);
21842
- return { lookupKey: e, qualifier: t };
21843
- }
21844
- function Ae(a, e) {
21845
- if (e) {
21846
- const t = he(e);
21847
- if (t)
21848
- return { lookupKey: a, fallbackLookupKey: `${t}/${a}` };
21849
- }
21850
- return { lookupKey: a };
21851
- }
21852
- function ge(a, e, t) {
21853
- if (!t) return null;
21854
- const i = ve(t);
21855
- if (!i) return null;
21856
- if (a === "dataName")
21857
- return { lookupKey: i, qualifier: e };
21858
- if (a === "inputName" || a === "outputName") {
21859
- const n = Te(e);
21860
- return { lookupKey: `${i}.${n}` };
21861
- }
21862
- return null;
21863
- }
21864
- function ve(a) {
21865
- let e = -1;
21866
- for (let i = a.length - 1; i >= 0; i--)
21867
- if (a[i].tagName === "BehaviorDescription") {
21868
- e = i;
21869
- break;
21870
- }
21871
- if (e === -1) return null;
21872
- const t = [];
21873
- for (let i = 0; i < e; i++) {
21874
- const n = R(a[i]);
21875
- n && t.push(n);
21876
- }
21877
- return t.length === 0 ? null : O(t);
21878
- }
21879
- function Te(a) {
21880
- const e = a.indexOf("("), t = a.indexOf(".");
21881
- return e !== -1 ? a.substring(0, e) : t !== -1 ? a.substring(0, t) : a;
21882
- }
21883
- function he(a) {
21884
- for (let e = a.length - 1; e >= 0; e--)
21885
- if (a[e].tagName === "LNode")
21886
- return a[e].attributes.find((t) => t.name === "iedName")?.value ?? null;
21887
- return null;
21888
- }
21889
- function Ne() {
21890
- const a = /* @__PURE__ */ new Map(), e = [], t = [];
21891
- return {
21892
- beforeImportRecord: (s) => {
21893
- const { record: r, ancestry: u } = s, { tagName: c } = r, l = Fe(r);
21894
- if (l && De.has(c)) {
21895
- const S = x({ record: r, ancestry: u });
21896
- S && a.set(S.path, l);
21897
- }
21898
- if (!we.has(c)) return;
21899
- const b = m[c];
21900
- for (const S of b) {
21901
- const C = r.attributes.find(
21902
- (g) => g.name === S.attribute.path
21903
- )?.value;
21904
- if (!C || r.attributes.find(
21905
- (g) => g.name === S.attribute.uuid
21906
- )?.value) continue;
21907
- const A = B(S.resolution, S.attribute.path, C, u);
21908
- if (!A) {
21909
- S.resolution === f.unsupported && t.push({
21910
- type: "unsupported-xpath-reference",
21911
- recordId: r.id,
21912
- details: {
21913
- elementTag: c,
21914
- pathAttribute: S.attribute.path,
21915
- uuidAttribute: S.attribute.uuid,
21916
- pathValue: C
21917
- }
21918
- });
21919
- continue;
21920
- }
21921
- e.push({
21922
- recordId: r.id,
21923
- elementTag: c,
21924
- uuidAttributeName: S.attribute.uuid,
21925
- pathValue: C,
21926
- lookupKey: A.lookupKey,
21927
- fallbackLookupKey: A.fallbackLookupKey
21928
- });
21929
- }
21930
- },
21931
- afterImport: async () => {
21932
- const s = [], r = [...t];
21933
- for (const u of e) {
21934
- const c = a.get(u.lookupKey) ?? (u.fallbackLookupKey ? a.get(u.fallbackLookupKey) : void 0);
21935
- if (!c) {
21936
- r.push({
21937
- type: "unresolved-reference",
21938
- recordId: u.recordId,
21939
- details: {
21940
- elementTag: u.elementTag,
21941
- uuidAttribute: u.uuidAttributeName,
21942
- pathValue: u.pathValue,
21943
- triedKeys: u.fallbackLookupKey ? [u.lookupKey, u.fallbackLookupKey] : [u.lookupKey]
21944
- }
21945
- });
21946
- continue;
21947
- }
21948
- s.push({
21949
- recordId: u.recordId,
21950
- attributes: [{ name: u.uuidAttributeName, value: c }]
21951
- });
21952
- }
21953
- return a.clear(), e.length = 0, t.length = 0, {
21954
- updates: s,
21955
- warnings: r.length > 0 ? r : void 0
21956
- };
21957
- }
21958
- };
21959
- }
21960
- const Ie = new Set(
21961
- Object.entries(w).filter(([, a]) => "uuid" in a).map(([a]) => a)
21962
- ), we = new Set(Object.keys(m)), De = new Set(
21963
- Object.values(m).flatMap((a) => a.flatMap((e) => e.target))
21964
- );
21965
- function Fe(a) {
21966
- if (!Ie.has(a.tagName)) return;
21967
- const e = a.attributes.find((i) => i.name === "uuid");
21968
- if (e) return e.value;
21969
- const t = crypto.randomUUID();
21970
- return a.attributes.push({ name: "uuid", value: t }), t;
21971
- }
21972
- const qe = {
21973
- supportedFileExtensions: [".fsd", ".asd", ".ssd", ".scd", ".isd", ".xml"],
21974
- hooks: Ne()
21975
- }, ye = {
21976
- tables: {
21977
- xmlElements: {
21978
- name: "sclElements",
21979
- schema: "id, tagName, [id+tagName], parent.id, parent.tagName, *children.id, *children.tagName"
21980
- },
21981
- additionalTables: {
21982
- attachedFiles: {
21983
- schema: "id, filename, file"
21984
- }
21985
- }
21986
- }
21987
- }, xe = {
21988
- default: { uri: "http://www.iec.ch/61850/2003/SCL", prefix: "" },
21989
- v2019C1: {
21990
- uri: "http://www.iec.ch/61850/2019/SCL/6-100",
21991
- prefix: "eIEC61850-6-100"
21992
- }
21993
- }, L = {
21994
- rootElementName: Y,
21995
- singletonElements: j,
21996
- elements: H,
21997
- namespaces: xe,
21998
- attributes: w,
21999
- children: W,
22000
- parents: K,
22001
- descendants: X,
22002
- ancestors: Q,
22003
- database: ye,
22004
- io: qe,
22005
- definition: D
22006
- };
22007
- async function Oe(a) {
22008
- const { childRecord: e, parentRecord: t, query: i } = a;
22009
- if (e.namespace.prefix === L.namespaces.default.prefix)
22010
- return [];
22011
- const n = t.tagName === "Private", s = t.namespace.prefix === L.namespaces.default.prefix;
22012
- if (!n && !s)
22013
- return [];
22014
- const r = t.children.find((o) => o.tagName === "Private"), u = {
22015
- ...t,
22016
- children: t.children.filter((o) => o.id !== e.id)
22017
- };
22018
- return n ? Ee({ parentRecord: t, childRecord: e, query: i }) : r ? ke({
22019
- existingPrivateRef: r,
22020
- parentRecord: t,
22021
- updatedParentRecord: u,
22022
- childRecord: e,
22023
- query: i
22024
- }) : (await i.findAncestors(t)).some(
22025
- (o) => o.tagName === "Private" && o.attributes.some(
22026
- (p) => p.name === "type" && p.value === e.namespace.prefix
22027
- )
22028
- ) ? [] : Ve({ parentRecord: t, updatedParentRecord: u, childRecord: e });
22029
- }
22030
- async function Ee(a) {
22031
- const { parentRecord: e, childRecord: t, query: i } = a, n = e;
22032
- if (t.parent?.id === n.id && t.parent?.tagName === "Private")
22033
- return [];
22034
- const s = await U({ privateId: n.id, query: i });
22035
- I(s, {
22036
- detail: "Latest private record not found",
22037
- key: "ELEMENT_NOT_FOUND"
22038
- });
22039
- const { childRecord: r, privateRecord: u } = z({
22040
- privateRecord: s,
22041
- childRecord: t
22042
- });
22043
- return [
22044
- {
22045
- status: "updated",
22046
- oldRecord: d(t),
22047
- newRecord: d(r)
22048
- },
22049
- {
22050
- status: "updated",
22051
- oldRecord: d(s),
22052
- newRecord: d(u)
22053
- }
22054
- ];
22055
- }
22056
- async function ke(a) {
22057
- const { existingPrivateRef: e, parentRecord: t, updatedParentRecord: i, childRecord: n, query: s } = a, r = await U({
22058
- privateId: e.id,
22059
- query: s
22060
- });
22061
- if (I(r, {
22062
- detail: "Latest private record not found",
22063
- key: "ELEMENT_NOT_FOUND"
22064
- }), !r.attributes.some(
22065
- (o) => o.name === "type" && o.value === n.namespace.prefix
22066
- )) return [];
22067
- const { childRecord: c, privateRecord: l } = z({
22068
- privateRecord: r,
22069
- childRecord: n
22070
- });
22071
- return [
22072
- {
22073
- status: "updated",
22074
- oldRecord: d(n),
22075
- newRecord: d(c)
22076
- },
22077
- {
22078
- status: "updated",
22079
- oldRecord: d(r),
22080
- newRecord: d(l)
21910
+ target: ["ExtRef"],
21911
+ companions: []
22081
21912
  },
22082
21913
  {
22083
- status: "updated",
22084
- oldRecord: d(t),
22085
- newRecord: d(i)
21914
+ attribute: { path: "resourceName", uuid: "resourceUuid" },
21915
+ resolution: "direct",
21916
+ target: ["ProcessResource"],
21917
+ companions: []
22086
21918
  }
22087
- ];
22088
- }
22089
- function Ve(a) {
22090
- const { parentRecord: e, updatedParentRecord: t, childRecord: i } = a, n = {
22091
- id: crypto.randomUUID(),
22092
- tagName: "Private",
22093
- namespace: L.namespaces.default,
22094
- attributes: [{ name: "type", value: i.namespace.prefix }],
22095
- value: "",
22096
- parent: { id: e.id, tagName: e.tagName },
22097
- children: [{ id: i.id, tagName: i.tagName }]
22098
- }, s = {
22099
- ...i,
22100
- parent: { id: n.id, tagName: "Private" }
22101
- }, r = {
22102
- ...t,
22103
- children: [...t.children, { id: n.id, tagName: "Private" }]
22104
- };
22105
- return [
22106
- { status: "created", oldRecord: void 0, newRecord: d(n) },
21919
+ ],
21920
+ SubscriberLNode: [
22107
21921
  {
22108
- status: "updated",
22109
- oldRecord: d(i),
22110
- newRecord: d(s)
22111
- },
21922
+ attribute: { path: "resourceName", uuid: "resourceUuid" },
21923
+ resolution: "direct",
21924
+ target: ["ProcessResource"],
21925
+ companions: []
21926
+ }
21927
+ ],
21928
+ VariableApplyTo: [
22112
21929
  {
22113
- status: "updated",
22114
- oldRecord: d(e),
22115
- newRecord: d(r)
21930
+ attribute: { path: "element", uuid: "elementUuid" },
21931
+ resolution: "unsupported",
21932
+ target: ["LNode", "Function", "SubFunction", "EqFunction", "EqSubFunction"],
21933
+ companions: [
21934
+ { name: "doName", required: !1 },
21935
+ { name: "daName", required: !1 }
21936
+ ]
22116
21937
  }
22117
- ];
21938
+ ],
21939
+ VariableRef: [
21940
+ {
21941
+ attribute: { path: "variable", uuid: "variableUuid" },
21942
+ resolution: "direct",
21943
+ target: ["Variable"],
21944
+ companions: []
21945
+ }
21946
+ ]
21947
+ };
21948
+ function ge(a) {
21949
+ const e = {};
21950
+ for (const [t, i] of Object.entries(a))
21951
+ for (const n of i) {
21952
+ const u = e[n.resolution] ??= /* @__PURE__ */ new Map();
21953
+ for (const r of n.target) {
21954
+ const s = u.get(r) ?? [];
21955
+ s.push({
21956
+ refTagName: t,
21957
+ uuidAttr: n.attribute.uuid,
21958
+ pathAttr: n.attribute.path
21959
+ }), u.set(r, s);
21960
+ }
21961
+ }
21962
+ return e;
22118
21963
  }
22119
- async function U(a) {
22120
- const { privateId: e, query: t } = a;
22121
- return await t.getRecord({ id: e, tagName: "Private" });
21964
+ function ve(a) {
21965
+ const e = /* @__PURE__ */ new Map();
21966
+ for (const [t, i] of Object.entries(a))
21967
+ e.set(
21968
+ t,
21969
+ i.map((n) => ({
21970
+ uuidAttr: n.attribute.uuid,
21971
+ pathAttr: n.attribute.path,
21972
+ resolution: n.resolution,
21973
+ targetTagNames: n.target
21974
+ }))
21975
+ );
21976
+ return e;
22122
21977
  }
22123
- function z(a) {
22124
- const { privateRecord: e, childRecord: t } = a, i = {
22125
- ...t,
22126
- parent: { id: e.id, tagName: "Private" }
22127
- }, n = {
22128
- ...e,
22129
- children: [...e.children, { id: t.id, tagName: t.tagName }]
22130
- };
22131
- return { childRecord: i, privateRecord: n };
21978
+ const B = ge(m), U = [
21979
+ f.direct,
21980
+ f.lnode,
21981
+ f.iedAddress,
21982
+ f.behaviorDescription
21983
+ ], Te = ve(m);
21984
+ [
21985
+ ...new Set(
21986
+ Object.values(m).flatMap(
21987
+ (a) => a.map((e) => e.attribute.uuid)
21988
+ )
21989
+ )
21990
+ ];
21991
+ const he = /* @__PURE__ */ new Set(["SourceRef", "ControlRef", "DOS", "SDS", "DAS", "InputVar", "OutputVar", "ProcessEcho"]), bt = {
21992
+ FunctionCatRef: ["SubCategory", "FunctionCategory"],
21993
+ PowerSystemRelation: ["PowerSystemRelations"],
21994
+ Resource: ["ProcessResource", "ProcessResources"],
21995
+ VariableApplyTo: ["Variable"]
21996
+ };
21997
+ async function Ne(a, e) {
21998
+ const { target: t, containerTagName: i } = e, n = await a.getRecord(t);
21999
+ if (!n) return [];
22000
+ const u = n.attributes.find((c) => c.name === "uuid")?.value;
22001
+ if (!u) return [];
22002
+ const r = Ie(n.tagName);
22003
+ if (r.length === 0) return [];
22004
+ const s = [];
22005
+ for (const c of r) {
22006
+ if (!T(c.refTagName, P)) continue;
22007
+ const l = await a.findByAttributes({
22008
+ tagName: c.refTagName,
22009
+ attributes: { [c.uuidAttr]: u }
22010
+ });
22011
+ for (const o of l) {
22012
+ const p = i ? await we(a, o, i) : void 0;
22013
+ s.push({ ref: o, container: p });
22014
+ }
22015
+ }
22016
+ return s;
22017
+ }
22018
+ function Ie(a) {
22019
+ const e = [];
22020
+ for (const t of U) {
22021
+ const i = B[t].get(a);
22022
+ i && e.push(...i);
22023
+ }
22024
+ return e;
22025
+ }
22026
+ async function we(a, e, t) {
22027
+ return (await a.findAncestors(e, { stopAtTagName: t })).find((n) => n.tagName === t);
22132
22028
  }
22029
+ const De = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
22030
+ __proto__: null,
22031
+ buildElementPath: E,
22032
+ buildReferencePath: M,
22033
+ findRefsPointingTo: Ne,
22034
+ resolveElementPath: Ae,
22035
+ resolveReferencePath: Se
22036
+ }, Symbol.toStringTag, { value: "Module" })), z = {
22037
+ query: De
22038
+ };
22133
22039
  async function h(a) {
22134
22040
  const { uuid: e, entry: t, target: i, query: n } = a;
22135
- if (!T(t.refTagName, L)) return [];
22136
- const s = await n.getRecordsByTagName(t.refTagName), r = [];
22137
- for (const u of s) {
22138
- if (u.attributes.find(
22041
+ if (!T(t.refTagName, P)) return [];
22042
+ const u = await n.getRecordsByTagName(t.refTagName), r = [];
22043
+ for (const s of u) {
22044
+ if (s.attributes.find(
22139
22045
  (S) => S.name === t.uuidAttr
22140
22046
  )?.value !== e) continue;
22141
- const l = { tagName: u.tagName, id: u.id }, o = await Z.query.buildReferencePath(n, { reference: l, target: i });
22142
- if (!o || u.attributes.find(
22047
+ const l = { tagName: s.tagName, id: s.id }, o = await z.query.buildReferencePath(n, { reference: l, target: i });
22048
+ if (!o || s.attributes.find(
22143
22049
  (S) => S.name === t.pathAttr
22144
22050
  )?.value === o) continue;
22145
- const b = u.attributes.map(
22051
+ const R = s.attributes.map(
22146
22052
  (S) => S.name === t.pathAttr ? { ...S, value: o } : S
22147
22053
  );
22148
22054
  r.push({
22149
22055
  status: "updated",
22150
- oldRecord: d(u),
22151
- newRecord: d({ ...u, attributes: b })
22056
+ oldRecord: d(s),
22057
+ newRecord: d({ ...s, attributes: R })
22152
22058
  });
22153
22059
  }
22154
22060
  return r;
22155
22061
  }
22156
22062
  function N(a) {
22157
22063
  const e = [];
22158
- for (const t of q) {
22159
- const i = F[t].get(a);
22064
+ for (const t of U) {
22065
+ const i = B[t].get(a);
22160
22066
  i && e.push(...i);
22161
22067
  }
22162
22068
  return e;
22163
22069
  }
22164
- async function Ze(a) {
22165
- const { childRecord: e, query: t } = a, i = await Me({ childRecord: e, query: t }), n = await Ue({ childRecord: e, query: t });
22070
+ async function Fe(a) {
22071
+ const { childRecord: e, query: t } = a, i = await qe({ childRecord: e, query: t }), n = await Oe({ childRecord: e, query: t });
22166
22072
  return [...i, ...n];
22167
22073
  }
22168
- async function Me(a) {
22169
- const { childRecord: e, query: t } = a, i = ee.get(e.tagName);
22074
+ async function qe(a) {
22075
+ const { childRecord: e, query: t } = a, i = Te.get(e.tagName);
22170
22076
  if (!i?.length) return [];
22171
22077
  const n = [];
22172
- for (const s of i) {
22173
- const r = await Ge({ childRecord: e, pair: s, query: t });
22078
+ for (const u of i) {
22079
+ const r = await ye({ childRecord: e, pair: u, query: t });
22174
22080
  r && n.push(r);
22175
22081
  }
22176
22082
  return n;
22177
22083
  }
22178
- async function Ge(a) {
22084
+ async function ye(a) {
22179
22085
  const { childRecord: e, pair: t, query: i } = a, n = e.attributes.find((o) => o.name === t.uuidAttr)?.value;
22180
22086
  if (!n) return null;
22181
- const s = await Be({
22087
+ const u = await xe({
22182
22088
  uuidValue: n,
22183
22089
  targetTagNames: t.targetTagNames,
22184
22090
  query: i
22185
22091
  });
22186
- if (!s) return null;
22187
- const r = { tagName: e.tagName, id: e.id }, u = { tagName: s.tagName, id: s.id }, c = await k(i, { reference: r, target: u });
22092
+ if (!u) return null;
22093
+ const r = { tagName: e.tagName, id: e.id }, s = { tagName: u.tagName, id: u.id }, c = await M(i, { reference: r, target: s });
22188
22094
  if (!c) return null;
22189
22095
  const l = e.attributes.map(
22190
22096
  (o) => o.name === t.pathAttr ? { ...o, value: c } : o
@@ -22198,66 +22104,66 @@ async function Ge(a) {
22198
22104
  }
22199
22105
  };
22200
22106
  }
22201
- async function Be(a) {
22107
+ async function xe(a) {
22202
22108
  const { uuidValue: e, targetTagNames: t, query: i } = a;
22203
22109
  for (const n of t) {
22204
- if (!T(n, L)) continue;
22110
+ if (!T(n, P)) continue;
22205
22111
  const r = (await i.getRecordsByTagName(n)).find(
22206
- (u) => u.attributes.find((c) => c.name === "uuid")?.value === e
22112
+ (s) => s.attributes.find((c) => c.name === "uuid")?.value === e
22207
22113
  );
22208
22114
  if (r) return { tagName: r.tagName, id: r.id };
22209
22115
  }
22210
22116
  return null;
22211
22117
  }
22212
- async function Ue(a) {
22213
- const { childRecord: e, query: t } = a, i = e.attributes.find((u) => u.name === "uuid")?.value;
22118
+ async function Oe(a) {
22119
+ const { childRecord: e, query: t } = a, i = e.attributes.find((s) => s.name === "uuid")?.value;
22214
22120
  if (!i) return [];
22215
22121
  const n = N(e.tagName);
22216
22122
  if (n.length === 0) return [];
22217
- const s = { tagName: e.tagName, id: e.id }, r = [];
22218
- for (const u of n) {
22219
- const c = await h({ uuid: i, entry: u, target: s, query: t });
22123
+ const u = { tagName: e.tagName, id: e.id }, r = [];
22124
+ for (const s of n) {
22125
+ const c = await h({ uuid: i, entry: s, target: u, query: t });
22220
22126
  r.push(...c);
22221
22127
  }
22222
22128
  return r;
22223
22129
  }
22224
- async function ze(a) {
22225
- const { childRecord: e, parentRecord: t, query: i } = a, n = await Oe({ childRecord: e, parentRecord: t, query: i }), s = await Ze({ childRecord: e, query: i });
22226
- return [...n, ...s];
22130
+ async function Ee(a) {
22131
+ const { childRecord: e, parentRecord: t, query: i } = a, n = await $({ childRecord: e, parentRecord: t, query: i }), u = await Fe({ childRecord: e, query: i });
22132
+ return [...n, ...u];
22227
22133
  }
22228
- async function _e(a) {
22229
- const { cumulativeCloneMappings: e, query: t } = a, { uuidMap: i, uuidToRef: n } = await He(e, t);
22134
+ async function ke(a) {
22135
+ const { cumulativeCloneMappings: e, query: t } = a, { uuidMap: i, uuidToRef: n } = await Ve(e, t);
22230
22136
  if (i.size === 0) return [];
22231
- const s = [];
22137
+ const u = [];
22232
22138
  for (const { target: r } of e) {
22233
- const u = await Ke({ target: r, uuidMap: i, uuidToRef: n, query: t });
22234
- u && s.push(u);
22139
+ const s = await Me({ target: r, uuidMap: i, uuidToRef: n, query: t });
22140
+ s && u.push(s);
22235
22141
  }
22236
- return s;
22142
+ return u;
22237
22143
  }
22238
- async function He(a, e) {
22144
+ async function Ve(a, e) {
22239
22145
  const t = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
22240
- for (const { source: n, target: s } of a)
22241
- await We({ source: n, target: s, query: e, uuidMap: t, uuidToRef: i });
22146
+ for (const { source: n, target: u } of a)
22147
+ await Ze({ source: n, target: u, query: e, uuidMap: t, uuidToRef: i });
22242
22148
  return { uuidMap: t, uuidToRef: i };
22243
22149
  }
22244
- async function We(a) {
22245
- const { source: e, target: t, query: i, uuidMap: n, uuidToRef: s } = a, r = await i.getRecord(t);
22150
+ async function Ze(a) {
22151
+ const { source: e, target: t, query: i, uuidMap: n, uuidToRef: u } = a, r = await i.getRecord(t);
22246
22152
  if (!r) return;
22247
- const u = e.attributes.find((l) => l.name === "uuid")?.value, c = r.attributes.find((l) => l.name === "uuid")?.value;
22248
- !u || !c || (n.set(u, c), s.set(c, { tagName: r.tagName, id: r.id }));
22153
+ const s = e.attributes.find((l) => l.name === "uuid")?.value, c = r.attributes.find((l) => l.name === "uuid")?.value;
22154
+ !s || !c || (n.set(s, c), u.set(c, { tagName: r.tagName, id: r.id }));
22249
22155
  }
22250
- async function Ke(a) {
22251
- const { target: e, uuidMap: t, uuidToRef: i, query: n } = a, s = e.tagName;
22252
- if (!(s in m)) return null;
22156
+ async function Me(a) {
22157
+ const { target: e, uuidMap: t, uuidToRef: i, query: n } = a, u = e.tagName;
22158
+ if (!(u in m)) return null;
22253
22159
  const r = await n.getRecord(e);
22254
22160
  if (!r) return null;
22255
- const u = m[s];
22161
+ const s = m[u];
22256
22162
  let c = [...r.attributes], l = !1;
22257
- for (const o of u) {
22258
- const p = await Xe({
22163
+ for (const o of s) {
22164
+ const p = await Ge({
22259
22165
  pair: o,
22260
- tagName: s,
22166
+ tagName: u,
22261
22167
  refId: r.id,
22262
22168
  updatedAttributes: c,
22263
22169
  uuidMap: t,
@@ -22272,44 +22178,44 @@ async function Ke(a) {
22272
22178
  newRecord: d({ ...r, attributes: c })
22273
22179
  } : null;
22274
22180
  }
22275
- async function Xe(a) {
22276
- const { pair: e, tagName: t, refId: i, uuidMap: n, uuidToRef: s, query: r } = a;
22277
- let u = [...a.updatedAttributes];
22278
- const c = u.find((S) => S.name === e.attribute.uuid)?.value;
22181
+ async function Ge(a) {
22182
+ const { pair: e, tagName: t, refId: i, uuidMap: n, uuidToRef: u, query: r } = a;
22183
+ let s = [...a.updatedAttributes];
22184
+ const c = s.find((S) => S.name === e.attribute.uuid)?.value;
22279
22185
  if (!c) return null;
22280
22186
  const l = n.get(c);
22281
22187
  if (!l) return null;
22282
22188
  let o = !1;
22283
- const p = Qe(u, e.attribute.uuid, c, l);
22284
- p && (u = p, o = !0);
22285
- const b = await Ye({
22286
- attributes: u,
22189
+ const p = Be(s, e.attribute.uuid, c, l);
22190
+ p && (s = p, o = !0);
22191
+ const R = await Ue({
22192
+ attributes: s,
22287
22193
  pathAttrName: e.attribute.path,
22288
22194
  newUuid: l,
22289
- uuidToRef: s,
22195
+ uuidToRef: u,
22290
22196
  tagName: t,
22291
22197
  refId: i,
22292
22198
  query: r
22293
22199
  });
22294
- return b && (u = b, o = !0), o ? u : null;
22200
+ return R && (s = R, o = !0), o ? s : null;
22295
22201
  }
22296
- function Qe(a, e, t, i) {
22202
+ function Be(a, e, t, i) {
22297
22203
  return i === t ? null : a.map((n) => n.name === e ? { ...n, value: i } : n);
22298
22204
  }
22299
- async function Ye(a) {
22300
- const { attributes: e, pathAttrName: t, newUuid: i, uuidToRef: n, tagName: s, refId: r, query: u } = a, c = n.get(i);
22205
+ async function Ue(a) {
22206
+ const { attributes: e, pathAttrName: t, newUuid: i, uuidToRef: n, tagName: u, refId: r, query: s } = a, c = n.get(i);
22301
22207
  if (!c) return null;
22302
- const l = await Z.query.buildReferencePath(u, {
22303
- reference: { tagName: s, id: r },
22208
+ const l = await z.query.buildReferencePath(s, {
22209
+ reference: { tagName: u, id: r },
22304
22210
  target: { tagName: c.tagName, id: c.id }
22305
22211
  });
22306
22212
  return !l || e.find((p) => p.name === t)?.value === l ? null : e.map((p) => p.name === t ? { ...p, value: l } : p);
22307
22213
  }
22308
- async function je(a) {
22309
- return _e(a);
22214
+ async function ze(a) {
22215
+ return ke(a);
22310
22216
  }
22311
- function $e(a) {
22312
- const { record: e } = a, { tagName: t, attributes: i } = e, n = L.definition[t];
22217
+ function _e(a) {
22218
+ const { record: e } = a, { tagName: t, attributes: i } = e, n = P.definition[t];
22313
22219
  if (!("uuid" in n.attributes.details) || i.find((o) => o.name === "uuid")?.value) return e;
22314
22220
  const c = n.attributes.details.uuid?.namespace, l = i.filter((o) => o.name !== "uuid");
22315
22221
  return {
@@ -22324,52 +22230,52 @@ function $e(a) {
22324
22230
  ]
22325
22231
  };
22326
22232
  }
22327
- function Je(a) {
22328
- return $e(a);
22233
+ function He(a) {
22234
+ return _e(a);
22329
22235
  }
22330
- async function et(a) {
22331
- const { oldRecord: e, newRecord: t, query: i } = a, n = [], s = t.attributes.find((r) => r.name === "uuid")?.value;
22332
- if (s) {
22333
- const r = N(t.tagName), u = { tagName: t.tagName, id: t.id };
22236
+ async function We(a) {
22237
+ const { oldRecord: e, newRecord: t, query: i } = a, n = [], u = t.attributes.find((r) => r.name === "uuid")?.value;
22238
+ if (u) {
22239
+ const r = N(t.tagName), s = { tagName: t.tagName, id: t.id };
22334
22240
  for (const c of r) {
22335
- const l = await h({ uuid: s, entry: c, target: u, query: i });
22241
+ const l = await h({ uuid: u, entry: c, target: s, query: i });
22336
22242
  n.push(...l);
22337
22243
  }
22338
22244
  }
22339
- if (tt(e, t)) {
22340
- const r = await at({ newRecord: t, query: i });
22245
+ if (Ke(e, t)) {
22246
+ const r = await Xe({ newRecord: t, query: i });
22341
22247
  n.push(...r);
22342
22248
  }
22343
22249
  return n;
22344
22250
  }
22345
- function tt(a, e) {
22251
+ function Ke(a, e) {
22346
22252
  for (const t of ie) {
22347
- const i = a.attributes.find((s) => s.name === t)?.value, n = e.attributes.find((s) => s.name === t)?.value;
22253
+ const i = a.attributes.find((u) => u.name === t)?.value, n = e.attributes.find((u) => u.name === t)?.value;
22348
22254
  if (i !== n) return !0;
22349
22255
  }
22350
22256
  return !1;
22351
22257
  }
22352
- async function at(a) {
22353
- const { newRecord: e, query: t } = a, i = { tagName: e.tagName, id: e.id }, n = await t.findDescendants(i), s = [];
22258
+ async function Xe(a) {
22259
+ const { newRecord: e, query: t } = a, i = { tagName: e.tagName, id: e.id }, n = await t.findDescendants(i), u = [];
22354
22260
  for (const r of Object.values(n))
22355
- for (const u of r) {
22356
- if (u.id === e.id) continue;
22357
- const c = await t.any.getAttribute(u, { name: "uuid" });
22261
+ for (const s of r) {
22262
+ if (s.id === e.id) continue;
22263
+ const c = await t.any.getAttribute(s, { name: "uuid" });
22358
22264
  if (!c) continue;
22359
- const l = N(u.tagName);
22265
+ const l = N(s.tagName);
22360
22266
  if (l.length === 0) continue;
22361
- const o = { tagName: u.tagName, id: u.id };
22267
+ const o = { tagName: s.tagName, id: s.id };
22362
22268
  for (const p of l) {
22363
- const b = await h({ uuid: c, entry: p, target: o, query: t });
22364
- s.push(...b);
22269
+ const R = await h({ uuid: c, entry: p, target: o, query: t });
22270
+ u.push(...R);
22365
22271
  }
22366
22272
  }
22367
- return s;
22273
+ return u;
22368
22274
  }
22369
- async function it(a) {
22370
- return et(a);
22275
+ async function Qe(a) {
22276
+ return We(a);
22371
22277
  }
22372
- function nt(a) {
22278
+ function Ye(a) {
22373
22279
  const { record: e } = a;
22374
22280
  let t = !0;
22375
22281
  e.tagName === "Private" && !e.tree.length && (t = !1);
@@ -22384,44 +22290,44 @@ function nt(a) {
22384
22290
  }
22385
22291
  };
22386
22292
  }
22387
- async function rt(a) {
22293
+ async function je(a) {
22388
22294
  const { record: e, query: t } = a, i = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
22389
22295
  if (await _({ record: e, query: t, ids: i, uuids: n }), n.size === 0) return [];
22390
- const s = [], r = Object.keys(m);
22391
- for (const u of r) {
22392
- const c = await ut({ refTagName: u, subtreeIds: i, subtreeUuids: n, query: t });
22393
- s.push(...c);
22296
+ const u = [], r = Object.keys(m);
22297
+ for (const s of r) {
22298
+ const c = await $e({ refTagName: s, subtreeIds: i, subtreeUuids: n, query: t });
22299
+ u.push(...c);
22394
22300
  }
22395
- return s;
22301
+ return u;
22396
22302
  }
22397
- async function ut(a) {
22398
- const { refTagName: e, subtreeIds: t, subtreeUuids: i, query: n } = a, s = m[e], r = await n.getRecordsByTagName(e), u = [];
22303
+ async function $e(a) {
22304
+ const { refTagName: e, subtreeIds: t, subtreeUuids: i, query: n } = a, u = m[e], r = await n.getRecordsByTagName(e), s = [];
22399
22305
  for (const c of r) {
22400
22306
  if (t.has(c.id)) continue;
22401
- const l = await st({ refTagName: e, refRecord: c, refPairs: s, subtreeUuids: i, query: n });
22402
- u.push(...l);
22307
+ const l = await Je({ refTagName: e, refRecord: c, refPairs: u, subtreeUuids: i, query: n });
22308
+ s.push(...l);
22403
22309
  }
22404
- return u;
22310
+ return s;
22405
22311
  }
22406
- async function st(a) {
22407
- const { refTagName: e, refRecord: t, refPairs: i, subtreeUuids: n, query: s } = a, r = ct({ refPairs: i, refRecord: t, subtreeUuids: n });
22408
- return r.size === 0 ? [] : te.has(e) ? [ot(t, r)] : lt(t, s);
22312
+ async function Je(a) {
22313
+ const { refTagName: e, refRecord: t, refPairs: i, subtreeUuids: n, query: u } = a, r = et({ refPairs: i, refRecord: t, subtreeUuids: n });
22314
+ return r.size === 0 ? [] : he.has(e) ? [tt(t, r)] : at(t, u);
22409
22315
  }
22410
- function ct(a) {
22316
+ function et(a) {
22411
22317
  const { refPairs: e, refRecord: t, subtreeUuids: i } = a, n = /* @__PURE__ */ new Set();
22412
- for (const s of e) {
22318
+ for (const u of e) {
22413
22319
  const r = t.attributes.find(
22414
- (u) => u.name === s.attribute.uuid
22320
+ (s) => s.name === u.attribute.uuid
22415
22321
  )?.value;
22416
22322
  if (!(!r || !i.has(r))) {
22417
- n.add(s.attribute.uuid), n.add(s.attribute.path);
22418
- for (const u of s.companions)
22419
- n.add(u.name);
22323
+ n.add(u.attribute.uuid), n.add(u.attribute.path);
22324
+ for (const s of u.companions)
22325
+ n.add(s.name);
22420
22326
  }
22421
22327
  }
22422
22328
  return n;
22423
22329
  }
22424
- function ot(a, e) {
22330
+ function tt(a, e) {
22425
22331
  const t = a.attributes.filter(
22426
22332
  (i) => !e.has(i.name)
22427
22333
  );
@@ -22431,7 +22337,7 @@ function ot(a, e) {
22431
22337
  newRecord: d({ ...a, attributes: t })
22432
22338
  };
22433
22339
  }
22434
- async function lt(a, e) {
22340
+ async function at(a, e) {
22435
22341
  const t = [
22436
22342
  { status: "deleted", oldRecord: d(a), newRecord: void 0 }
22437
22343
  ];
@@ -22440,7 +22346,7 @@ async function lt(a, e) {
22440
22346
  if (i) {
22441
22347
  const n = {
22442
22348
  ...i,
22443
- children: i.children.filter((s) => s.id !== a.id)
22349
+ children: i.children.filter((u) => u.id !== a.id)
22444
22350
  };
22445
22351
  t.push({
22446
22352
  status: "updated",
@@ -22454,34 +22360,159 @@ async function lt(a, e) {
22454
22360
  async function _(a) {
22455
22361
  const { record: e, query: t, ids: i, uuids: n } = a;
22456
22362
  i.add(e.id);
22457
- const s = e.attributes.find((r) => r.name === "uuid")?.value;
22458
- s && n.add(s);
22363
+ const u = e.attributes.find((r) => r.name === "uuid")?.value;
22364
+ u && n.add(u);
22459
22365
  for (const r of e.children) {
22460
- const u = await t.getRecord(r);
22461
- u && await _({ record: u, query: t, ids: i, uuids: n });
22366
+ const s = await t.getRecord(r);
22367
+ s && await _({ record: s, query: t, ids: i, uuids: n });
22462
22368
  }
22463
22369
  }
22464
- async function dt(a) {
22465
- return rt(a);
22370
+ async function it(a) {
22371
+ return je(a);
22372
+ }
22373
+ function nt() {
22374
+ const a = /* @__PURE__ */ new Map(), e = [], t = [];
22375
+ return {
22376
+ beforeImportRecord: (u) => {
22377
+ const { record: r, ancestry: s } = u, { tagName: c } = r, l = ct(r);
22378
+ if (l && st.has(c)) {
22379
+ const S = x({ record: r, ancestry: s });
22380
+ S && a.set(S.path, l);
22381
+ }
22382
+ if (!ut.has(c)) return;
22383
+ const R = m[c];
22384
+ for (const S of R) {
22385
+ const C = r.attributes.find(
22386
+ (g) => g.name === S.attribute.path
22387
+ )?.value;
22388
+ if (!C || r.attributes.find(
22389
+ (g) => g.name === S.attribute.uuid
22390
+ )?.value) continue;
22391
+ const A = Z(S.resolution, S.attribute.path, C, s);
22392
+ if (!A) {
22393
+ S.resolution === f.unsupported && t.push({
22394
+ type: "unsupported-xpath-reference",
22395
+ recordId: r.id,
22396
+ details: {
22397
+ elementTag: c,
22398
+ pathAttribute: S.attribute.path,
22399
+ uuidAttribute: S.attribute.uuid,
22400
+ pathValue: C
22401
+ }
22402
+ });
22403
+ continue;
22404
+ }
22405
+ e.push({
22406
+ recordId: r.id,
22407
+ elementTag: c,
22408
+ uuidAttributeName: S.attribute.uuid,
22409
+ pathValue: C,
22410
+ lookupKey: A.lookupKey,
22411
+ fallbackLookupKey: A.fallbackLookupKey
22412
+ });
22413
+ }
22414
+ },
22415
+ afterImport: async () => {
22416
+ const u = [], r = [...t];
22417
+ for (const s of e) {
22418
+ const c = a.get(s.lookupKey) ?? (s.fallbackLookupKey ? a.get(s.fallbackLookupKey) : void 0);
22419
+ if (!c) {
22420
+ r.push({
22421
+ type: "unresolved-reference",
22422
+ recordId: s.recordId,
22423
+ details: {
22424
+ elementTag: s.elementTag,
22425
+ uuidAttribute: s.uuidAttributeName,
22426
+ pathValue: s.pathValue,
22427
+ triedKeys: s.fallbackLookupKey ? [s.lookupKey, s.fallbackLookupKey] : [s.lookupKey]
22428
+ }
22429
+ });
22430
+ continue;
22431
+ }
22432
+ u.push({
22433
+ recordId: s.recordId,
22434
+ attributes: [{ name: s.uuidAttributeName, value: c }]
22435
+ });
22436
+ }
22437
+ return a.clear(), e.length = 0, t.length = 0, {
22438
+ updates: u,
22439
+ warnings: r.length > 0 ? r : void 0
22440
+ };
22441
+ }
22442
+ };
22443
+ }
22444
+ const rt = new Set(
22445
+ Object.entries(w).filter(([, a]) => "uuid" in a).map(([a]) => a)
22446
+ ), ut = new Set(Object.keys(m)), st = new Set(
22447
+ Object.values(m).flatMap((a) => a.flatMap((e) => e.target))
22448
+ );
22449
+ function ct(a) {
22450
+ if (!rt.has(a.tagName)) return;
22451
+ const e = a.attributes.find((i) => i.name === "uuid");
22452
+ if (e) return e.value;
22453
+ const t = crypto.randomUUID();
22454
+ return a.attributes.push({ name: "uuid", value: t }), t;
22466
22455
  }
22467
- const bt = {
22468
- beforeClone: nt,
22469
- afterStandardizedRecord: Je,
22470
- afterCreated: ze,
22471
- afterDeepClone: je,
22472
- afterUpdated: it,
22473
- beforeDelete: dt
22456
+ const Rt = {
22457
+ beforeClone: Ye,
22458
+ afterStandardizedRecord: He,
22459
+ afterCreated: Ee,
22460
+ afterDeepClone: ze,
22461
+ afterUpdated: Qe,
22462
+ beforeDelete: it
22463
+ }, ot = nt(), lt = {
22464
+ supportedFileExtensions: [".fsd", ".asd", ".ssd", ".scd", ".isd", ".xml"],
22465
+ hooks: ot
22466
+ }, dt = {
22467
+ recordSchema: {
22468
+ primaryKey: "id",
22469
+ indexes: ["tagName", "parent.id", "parent.tagName"],
22470
+ compoundIndexes: [["id", "tagName"]],
22471
+ arrayIndexes: ["children.id", "children.tagName"]
22472
+ },
22473
+ /** @deprecated - kept for old io/ pipeline until Phase 5 removes it */
22474
+ tables: {
22475
+ xmlElements: {
22476
+ name: "sclElements",
22477
+ schema: "id, tagName, [id+tagName], parent.id, parent.tagName, *children.id, *children.tagName"
22478
+ },
22479
+ additionalTables: {
22480
+ attachedFiles: {
22481
+ schema: "id, filename, file"
22482
+ }
22483
+ }
22484
+ }
22485
+ }, pt = {
22486
+ default: { uri: "http://www.iec.ch/61850/2003/SCL", prefix: "" },
22487
+ v2019C1: {
22488
+ uri: "http://www.iec.ch/61850/2019/SCL/6-100",
22489
+ prefix: "eIEC61850-6-100"
22490
+ }
22491
+ }, P = {
22492
+ rootElementName: Y,
22493
+ singletonElements: j,
22494
+ transparentElements: ["Private"],
22495
+ elements: H,
22496
+ namespaces: pt,
22497
+ attributes: w,
22498
+ children: W,
22499
+ parents: K,
22500
+ descendants: X,
22501
+ ancestors: Q,
22502
+ database: dt,
22503
+ io: lt,
22504
+ definition: D
22474
22505
  };
22475
22506
  export {
22476
22507
  D,
22477
- bt as H,
22478
- te as K,
22479
- mt as R,
22480
- L as S,
22508
+ Rt as H,
22509
+ he as K,
22510
+ bt as R,
22511
+ P as S,
22481
22512
  m as U,
22482
22513
  X as a,
22483
- ye as b,
22484
- qe as c,
22485
- xe as d,
22486
- Z as r
22514
+ dt as b,
22515
+ lt as c,
22516
+ pt as d,
22517
+ z as r
22487
22518
  };