@nextera.one/axis-server-sdk 2.3.24 → 2.3.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -9432,9 +9432,10 @@ var init_timeline_store = __esm({
9432
9432
  // src/utils/axis-tlv-codec.ts
9433
9433
  function encodeAxisTlvDto(dtoClass, data, context = {}) {
9434
9434
  const schema = (0, import_dto_schema2.extractDtoSchema)(dtoClass);
9435
+ const effectiveContext = withDtoName(dtoClass, context);
9435
9436
  const items = schema.fields.flatMap((field) => {
9436
9437
  const value = data[field.name];
9437
- if (!shouldEncodeField(field, value, data, context)) return [];
9438
+ if (!shouldEncodeField(field, value, data, effectiveContext)) return [];
9438
9439
  if (value === void 0 || value === null) {
9439
9440
  if (field.required) {
9440
9441
  throw new Error(`Missing required TLV response field: ${field.name}`);
@@ -9447,17 +9448,18 @@ function encodeAxisTlvDto(dtoClass, data, context = {}) {
9447
9448
  }
9448
9449
  function projectAxisTlvDto(dtoClass, data, context = {}) {
9449
9450
  const schema = (0, import_dto_schema2.extractDtoSchema)(dtoClass);
9451
+ const effectiveContext = withDtoName(dtoClass, context);
9450
9452
  const result = {};
9451
9453
  for (const field of schema.fields) {
9452
9454
  const value = data[field.name];
9453
- if (!shouldEncodeField(field, value, data, context)) continue;
9455
+ if (!shouldEncodeField(field, value, data, effectiveContext)) continue;
9454
9456
  if (value === void 0 || value === null) continue;
9455
9457
  result[field.name] = value;
9456
9458
  }
9457
9459
  return result;
9458
9460
  }
9459
9461
  function shouldEncodeField(field, value, data, context) {
9460
- const rule = field.encode;
9462
+ const rule = resolveEncodeRule(field, value, data, context);
9461
9463
  if (rule === void 0) return true;
9462
9464
  if (rule === false) return false;
9463
9465
  if (rule.onlyRoles?.length && !hasAnyRole(context, rule.onlyRoles)) {
@@ -9477,6 +9479,22 @@ function shouldEncodeField(field, value, data, context) {
9477
9479
  }
9478
9480
  return true;
9479
9481
  }
9482
+ function withDtoName(dtoClass, context) {
9483
+ return {
9484
+ ...context,
9485
+ dtoName: context.dtoName ?? dtoClass.name
9486
+ };
9487
+ }
9488
+ function resolveEncodeRule(field, value, data, context) {
9489
+ return context.visibilityRegistry?.resolve({
9490
+ intent: context.intent,
9491
+ dtoName: context.dtoName,
9492
+ field,
9493
+ value,
9494
+ data,
9495
+ context
9496
+ }) ?? field.encode;
9497
+ }
9480
9498
  function hasAnyRole(context, expectedRoles) {
9481
9499
  const actualRoles = context.roles ?? [];
9482
9500
  return expectedRoles.some((role) => actualRoles.includes(role));
@@ -9524,6 +9542,82 @@ var init_axis_tlv_codec = __esm({
9524
9542
  }
9525
9543
  });
9526
9544
 
9545
+ // src/utils/axis-tlv-visibility-registry.ts
9546
+ function overrideKey(override) {
9547
+ return [
9548
+ normalizeKey(override.intent),
9549
+ normalizeKey(override.dtoName),
9550
+ normalizeKey(override.field),
9551
+ override.tag ?? ""
9552
+ ].join("|");
9553
+ }
9554
+ function normalizeKey(value) {
9555
+ return typeof value === "string" ? value.trim() : "";
9556
+ }
9557
+ function matchScore(override, input) {
9558
+ if (override.enabled === false) return -1;
9559
+ const intent = normalizeKey(input.intent);
9560
+ const dtoName = normalizeKey(input.dtoName);
9561
+ const overrideIntent = normalizeKey(override.intent);
9562
+ const overrideDtoName = normalizeKey(override.dtoName);
9563
+ const overrideField = normalizeKey(override.field);
9564
+ const fieldName = normalizeKey(input.field.name);
9565
+ if (overrideIntent && overrideIntent !== intent) return -1;
9566
+ if (overrideDtoName && overrideDtoName !== dtoName) return -1;
9567
+ const fieldMatches = Boolean(overrideField && overrideField === fieldName);
9568
+ const tagMatches = typeof override.tag === "number" && override.tag === input.field.tag;
9569
+ if (!fieldMatches && !tagMatches) return -1;
9570
+ return (overrideIntent ? 100 : 0) + (overrideDtoName ? 50 : 0) + (fieldMatches ? 10 : 0) + (tagMatches ? 8 : 0);
9571
+ }
9572
+ var AxisTlvVisibilityRegistry;
9573
+ var init_axis_tlv_visibility_registry = __esm({
9574
+ "src/utils/axis-tlv-visibility-registry.ts"() {
9575
+ AxisTlvVisibilityRegistry = class {
9576
+ constructor(overrides = []) {
9577
+ this.overrides = [];
9578
+ this.setOverrides(overrides);
9579
+ }
9580
+ setOverrides(overrides) {
9581
+ this.overrides = overrides.map((override) => ({ ...override }));
9582
+ }
9583
+ listOverrides() {
9584
+ return this.overrides.map((override) => ({ ...override }));
9585
+ }
9586
+ upsert(override) {
9587
+ const key = overrideKey(override);
9588
+ const index = this.overrides.findIndex((item) => overrideKey(item) === key);
9589
+ if (index >= 0) {
9590
+ this.overrides[index] = { ...override };
9591
+ return;
9592
+ }
9593
+ this.overrides.push({ ...override });
9594
+ }
9595
+ remove(match) {
9596
+ const before = this.overrides.length;
9597
+ this.overrides = this.overrides.filter(
9598
+ (item) => overrideKey(item) !== overrideKey(match)
9599
+ );
9600
+ return before - this.overrides.length;
9601
+ }
9602
+ resolve(input) {
9603
+ let bestScore = -1;
9604
+ let bestIndex = -1;
9605
+ let best;
9606
+ this.overrides.forEach((override, index) => {
9607
+ const score = matchScore(override, input);
9608
+ if (score < 0) return;
9609
+ if (score > bestScore || score === bestScore && index > bestIndex) {
9610
+ bestScore = score;
9611
+ bestIndex = index;
9612
+ best = override;
9613
+ }
9614
+ });
9615
+ return best?.encode;
9616
+ }
9617
+ };
9618
+ }
9619
+ });
9620
+
9527
9621
  // src/loom/loom.types.ts
9528
9622
  function deriveAnchorReflection(softid, context = "openlogs", scope = "loom") {
9529
9623
  return `ar:${context}:${scope}:${softid}`;
@@ -13259,6 +13353,7 @@ __export(index_exports, {
13259
13353
  AxisSensorChainService: () => AxisSensorChainService,
13260
13354
  AxisStream: () => AxisStream,
13261
13355
  AxisTlvDto: () => AxisTlvDto,
13356
+ AxisTlvVisibilityRegistry: () => AxisTlvVisibilityRegistry,
13262
13357
  BAND: () => BAND,
13263
13358
  BodyProfile: () => BodyProfile2,
13264
13359
  BodyProfileValidator: () => BodyProfileValidator,
@@ -13604,6 +13699,7 @@ var init_index = __esm({
13604
13699
  init_cce_pipeline();
13605
13700
  init_cce_types();
13606
13701
  init_axis_tlv_codec();
13702
+ init_axis_tlv_visibility_registry();
13607
13703
  init_loom_types();
13608
13704
  init_loom_engine();
13609
13705
  init_idel_compiler();
@@ -13666,6 +13762,7 @@ export {
13666
13762
  AxisSensorChainService,
13667
13763
  AxisStream,
13668
13764
  AxisTlvDto,
13765
+ AxisTlvVisibilityRegistry,
13669
13766
  BAND,
13670
13767
  BodyProfile2 as BodyProfile,
13671
13768
  BodyProfileValidator,