@nextera.one/axis-server-sdk 2.3.23 → 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
@@ -3732,7 +3732,8 @@ var init_intent_router = __esm({
3732
3732
  required: f.required,
3733
3733
  maxLen: f.maxLen,
3734
3734
  max: f.max,
3735
- scope: f.scope
3735
+ scope: f.scope,
3736
+ ...f.encode !== void 0 ? { encode: f.encode } : {}
3736
3737
  }))
3737
3738
  };
3738
3739
  this.intentSchemas.set(meta.intent, schema2);
@@ -3756,7 +3757,8 @@ var init_intent_router = __esm({
3756
3757
  required: f.required,
3757
3758
  maxLen: f.maxLen,
3758
3759
  max: f.max,
3759
- scope: f.scope
3760
+ scope: f.scope,
3761
+ ...f.encode !== void 0 ? { encode: f.encode } : {}
3760
3762
  }))
3761
3763
  };
3762
3764
  this.intentSchemas.set(meta.intent, schema);
@@ -9430,9 +9432,10 @@ var init_timeline_store = __esm({
9430
9432
  // src/utils/axis-tlv-codec.ts
9431
9433
  function encodeAxisTlvDto(dtoClass, data, context = {}) {
9432
9434
  const schema = (0, import_dto_schema2.extractDtoSchema)(dtoClass);
9435
+ const effectiveContext = withDtoName(dtoClass, context);
9433
9436
  const items = schema.fields.flatMap((field) => {
9434
9437
  const value = data[field.name];
9435
- if (!shouldEncodeField(field, value, data, context)) return [];
9438
+ if (!shouldEncodeField(field, value, data, effectiveContext)) return [];
9436
9439
  if (value === void 0 || value === null) {
9437
9440
  if (field.required) {
9438
9441
  throw new Error(`Missing required TLV response field: ${field.name}`);
@@ -9445,17 +9448,18 @@ function encodeAxisTlvDto(dtoClass, data, context = {}) {
9445
9448
  }
9446
9449
  function projectAxisTlvDto(dtoClass, data, context = {}) {
9447
9450
  const schema = (0, import_dto_schema2.extractDtoSchema)(dtoClass);
9451
+ const effectiveContext = withDtoName(dtoClass, context);
9448
9452
  const result = {};
9449
9453
  for (const field of schema.fields) {
9450
9454
  const value = data[field.name];
9451
- if (!shouldEncodeField(field, value, data, context)) continue;
9455
+ if (!shouldEncodeField(field, value, data, effectiveContext)) continue;
9452
9456
  if (value === void 0 || value === null) continue;
9453
9457
  result[field.name] = value;
9454
9458
  }
9455
9459
  return result;
9456
9460
  }
9457
9461
  function shouldEncodeField(field, value, data, context) {
9458
- const rule = field.encode;
9462
+ const rule = resolveEncodeRule(field, value, data, context);
9459
9463
  if (rule === void 0) return true;
9460
9464
  if (rule === false) return false;
9461
9465
  if (rule.onlyRoles?.length && !hasAnyRole(context, rule.onlyRoles)) {
@@ -9475,6 +9479,22 @@ function shouldEncodeField(field, value, data, context) {
9475
9479
  }
9476
9480
  return true;
9477
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
+ }
9478
9498
  function hasAnyRole(context, expectedRoles) {
9479
9499
  const actualRoles = context.roles ?? [];
9480
9500
  return expectedRoles.some((role) => actualRoles.includes(role));
@@ -9522,6 +9542,82 @@ var init_axis_tlv_codec = __esm({
9522
9542
  }
9523
9543
  });
9524
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
+
9525
9621
  // src/loom/loom.types.ts
9526
9622
  function deriveAnchorReflection(softid, context = "openlogs", scope = "loom") {
9527
9623
  return `ar:${context}:${scope}:${softid}`;
@@ -13257,6 +13353,7 @@ __export(index_exports, {
13257
13353
  AxisSensorChainService: () => AxisSensorChainService,
13258
13354
  AxisStream: () => AxisStream,
13259
13355
  AxisTlvDto: () => AxisTlvDto,
13356
+ AxisTlvVisibilityRegistry: () => AxisTlvVisibilityRegistry,
13260
13357
  BAND: () => BAND,
13261
13358
  BodyProfile: () => BodyProfile2,
13262
13359
  BodyProfileValidator: () => BodyProfileValidator,
@@ -13602,6 +13699,7 @@ var init_index = __esm({
13602
13699
  init_cce_pipeline();
13603
13700
  init_cce_types();
13604
13701
  init_axis_tlv_codec();
13702
+ init_axis_tlv_visibility_registry();
13605
13703
  init_loom_types();
13606
13704
  init_loom_engine();
13607
13705
  init_idel_compiler();
@@ -13664,6 +13762,7 @@ export {
13664
13762
  AxisSensorChainService,
13665
13763
  AxisStream,
13666
13764
  AxisTlvDto,
13765
+ AxisTlvVisibilityRegistry,
13667
13766
  BAND,
13668
13767
  BodyProfile2 as BodyProfile,
13669
13768
  BodyProfileValidator,