@nextera.one/axis-server-sdk 2.1.8 → 2.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.
- package/dist/index.d.mts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +43 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -681,7 +681,7 @@ declare function Handler(intent?: string): ClassDecorator;
|
|
|
681
681
|
|
|
682
682
|
declare const INTENT_METADATA_KEY = "axis:intent";
|
|
683
683
|
declare const INTENT_ROUTES_KEY = "axis:intent_routes";
|
|
684
|
-
type IntentKind =
|
|
684
|
+
type IntentKind = "create" | "read" | "update" | "delete" | "action";
|
|
685
685
|
type AxisIntentSensorRef = string | Function;
|
|
686
686
|
interface AxisIntentSensorOptions {
|
|
687
687
|
is?: AxisIntentSensorRef[];
|
|
@@ -689,11 +689,11 @@ interface AxisIntentSensorOptions {
|
|
|
689
689
|
interface IntentTlvField {
|
|
690
690
|
name: string;
|
|
691
691
|
tag: number;
|
|
692
|
-
kind:
|
|
692
|
+
kind: "utf8" | "u64" | "bytes" | "bytes16" | "bool" | "obj" | "arr";
|
|
693
693
|
required?: boolean;
|
|
694
694
|
maxLen?: number;
|
|
695
695
|
max?: string;
|
|
696
|
-
scope?:
|
|
696
|
+
scope?: "header" | "body";
|
|
697
697
|
}
|
|
698
698
|
interface IntentRoute extends AxisIntentSensorOptions {
|
|
699
699
|
action: string;
|
|
@@ -703,7 +703,7 @@ interface IntentRoute extends AxisIntentSensorOptions {
|
|
|
703
703
|
kind?: IntentKind;
|
|
704
704
|
sensitivity?: SensitivityLevel;
|
|
705
705
|
chain?: boolean | ChainOptions;
|
|
706
|
-
bodyProfile?:
|
|
706
|
+
bodyProfile?: "TLV_MAP" | "RAW" | "TLV_OBJ" | "TLV_ARR";
|
|
707
707
|
tlv?: IntentTlvField[];
|
|
708
708
|
dto?: Function;
|
|
709
709
|
}
|
|
@@ -713,9 +713,10 @@ interface IntentOptions extends AxisIntentSensorOptions {
|
|
|
713
713
|
absolute?: boolean;
|
|
714
714
|
frame?: boolean;
|
|
715
715
|
chain?: boolean | ChainOptions;
|
|
716
|
-
bodyProfile?:
|
|
716
|
+
bodyProfile?: "TLV_MAP" | "RAW" | "TLV_OBJ" | "TLV_ARR";
|
|
717
717
|
tlv?: IntentTlvField[];
|
|
718
718
|
dto?: Function;
|
|
719
|
+
decoder?: (buf: Buffer) => any;
|
|
719
720
|
}
|
|
720
721
|
declare function Intent(action: string, options?: IntentOptions): MethodDecorator;
|
|
721
722
|
|
|
@@ -793,6 +794,7 @@ declare function extractDtoSchema(dto: Function): DtoSchema;
|
|
|
793
794
|
declare function buildDtoDecoder(dto: Function): (bodyBytes: Buffer) => Record<string, any>;
|
|
794
795
|
|
|
795
796
|
declare abstract class AxisTlvDto {
|
|
797
|
+
static afterDecode(_dto: Record<string, any>): void;
|
|
796
798
|
}
|
|
797
799
|
|
|
798
800
|
declare class AxisIdDto extends AxisTlvDto {
|
package/dist/index.d.ts
CHANGED
|
@@ -681,7 +681,7 @@ declare function Handler(intent?: string): ClassDecorator;
|
|
|
681
681
|
|
|
682
682
|
declare const INTENT_METADATA_KEY = "axis:intent";
|
|
683
683
|
declare const INTENT_ROUTES_KEY = "axis:intent_routes";
|
|
684
|
-
type IntentKind =
|
|
684
|
+
type IntentKind = "create" | "read" | "update" | "delete" | "action";
|
|
685
685
|
type AxisIntentSensorRef = string | Function;
|
|
686
686
|
interface AxisIntentSensorOptions {
|
|
687
687
|
is?: AxisIntentSensorRef[];
|
|
@@ -689,11 +689,11 @@ interface AxisIntentSensorOptions {
|
|
|
689
689
|
interface IntentTlvField {
|
|
690
690
|
name: string;
|
|
691
691
|
tag: number;
|
|
692
|
-
kind:
|
|
692
|
+
kind: "utf8" | "u64" | "bytes" | "bytes16" | "bool" | "obj" | "arr";
|
|
693
693
|
required?: boolean;
|
|
694
694
|
maxLen?: number;
|
|
695
695
|
max?: string;
|
|
696
|
-
scope?:
|
|
696
|
+
scope?: "header" | "body";
|
|
697
697
|
}
|
|
698
698
|
interface IntentRoute extends AxisIntentSensorOptions {
|
|
699
699
|
action: string;
|
|
@@ -703,7 +703,7 @@ interface IntentRoute extends AxisIntentSensorOptions {
|
|
|
703
703
|
kind?: IntentKind;
|
|
704
704
|
sensitivity?: SensitivityLevel;
|
|
705
705
|
chain?: boolean | ChainOptions;
|
|
706
|
-
bodyProfile?:
|
|
706
|
+
bodyProfile?: "TLV_MAP" | "RAW" | "TLV_OBJ" | "TLV_ARR";
|
|
707
707
|
tlv?: IntentTlvField[];
|
|
708
708
|
dto?: Function;
|
|
709
709
|
}
|
|
@@ -713,9 +713,10 @@ interface IntentOptions extends AxisIntentSensorOptions {
|
|
|
713
713
|
absolute?: boolean;
|
|
714
714
|
frame?: boolean;
|
|
715
715
|
chain?: boolean | ChainOptions;
|
|
716
|
-
bodyProfile?:
|
|
716
|
+
bodyProfile?: "TLV_MAP" | "RAW" | "TLV_OBJ" | "TLV_ARR";
|
|
717
717
|
tlv?: IntentTlvField[];
|
|
718
718
|
dto?: Function;
|
|
719
|
+
decoder?: (buf: Buffer) => any;
|
|
719
720
|
}
|
|
720
721
|
declare function Intent(action: string, options?: IntentOptions): MethodDecorator;
|
|
721
722
|
|
|
@@ -793,6 +794,7 @@ declare function extractDtoSchema(dto: Function): DtoSchema;
|
|
|
793
794
|
declare function buildDtoDecoder(dto: Function): (bodyBytes: Buffer) => Record<string, any>;
|
|
794
795
|
|
|
795
796
|
declare abstract class AxisTlvDto {
|
|
797
|
+
static afterDecode(_dto: Record<string, any>): void;
|
|
796
798
|
}
|
|
797
799
|
|
|
798
800
|
declare class AxisIdDto extends AxisTlvDto {
|
package/dist/index.js
CHANGED
|
@@ -318,6 +318,25 @@ var init_handler_decorator = __esm({
|
|
|
318
318
|
}
|
|
319
319
|
});
|
|
320
320
|
|
|
321
|
+
// src/decorators/intent-body.decorator.ts
|
|
322
|
+
var intent_body_decorator_exports = {};
|
|
323
|
+
__export(intent_body_decorator_exports, {
|
|
324
|
+
INTENT_BODY_KEY: () => INTENT_BODY_KEY,
|
|
325
|
+
IntentBody: () => IntentBody
|
|
326
|
+
});
|
|
327
|
+
function IntentBody(decoder) {
|
|
328
|
+
return (target, propertyKey) => {
|
|
329
|
+
Reflect.defineMetadata(INTENT_BODY_KEY, decoder, target, propertyKey);
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
var import_reflect_metadata4, INTENT_BODY_KEY;
|
|
333
|
+
var init_intent_body_decorator = __esm({
|
|
334
|
+
"src/decorators/intent-body.decorator.ts"() {
|
|
335
|
+
import_reflect_metadata4 = require("reflect-metadata");
|
|
336
|
+
INTENT_BODY_KEY = "axis:intent:body";
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
321
340
|
// src/decorators/intent.decorator.ts
|
|
322
341
|
var intent_decorator_exports = {};
|
|
323
342
|
__export(intent_decorator_exports, {
|
|
@@ -329,6 +348,14 @@ function Intent(action, options) {
|
|
|
329
348
|
return (target, propertyKey) => {
|
|
330
349
|
const metadata = { intent: action, ...options };
|
|
331
350
|
Reflect.defineMetadata(INTENT_METADATA_KEY, metadata, target, propertyKey);
|
|
351
|
+
if (options?.decoder) {
|
|
352
|
+
Reflect.defineMetadata(
|
|
353
|
+
INTENT_BODY_KEY,
|
|
354
|
+
options.decoder,
|
|
355
|
+
target,
|
|
356
|
+
propertyKey
|
|
357
|
+
);
|
|
358
|
+
}
|
|
332
359
|
if (options?.sensitivity) {
|
|
333
360
|
Reflect.defineMetadata(
|
|
334
361
|
SENSITIVITY_METADATA_KEY,
|
|
@@ -354,35 +381,17 @@ function Intent(action, options) {
|
|
|
354
381
|
Reflect.defineMetadata(INTENT_ROUTES_KEY, routes, target.constructor);
|
|
355
382
|
};
|
|
356
383
|
}
|
|
357
|
-
var
|
|
384
|
+
var import_reflect_metadata5, INTENT_METADATA_KEY, INTENT_ROUTES_KEY;
|
|
358
385
|
var init_intent_decorator = __esm({
|
|
359
386
|
"src/decorators/intent.decorator.ts"() {
|
|
360
|
-
|
|
387
|
+
import_reflect_metadata5 = require("reflect-metadata");
|
|
388
|
+
init_intent_body_decorator();
|
|
361
389
|
init_intent_policy_decorator();
|
|
362
390
|
INTENT_METADATA_KEY = "axis:intent";
|
|
363
391
|
INTENT_ROUTES_KEY = "axis:intent_routes";
|
|
364
392
|
}
|
|
365
393
|
});
|
|
366
394
|
|
|
367
|
-
// src/decorators/intent-body.decorator.ts
|
|
368
|
-
var intent_body_decorator_exports = {};
|
|
369
|
-
__export(intent_body_decorator_exports, {
|
|
370
|
-
INTENT_BODY_KEY: () => INTENT_BODY_KEY,
|
|
371
|
-
IntentBody: () => IntentBody
|
|
372
|
-
});
|
|
373
|
-
function IntentBody(decoder) {
|
|
374
|
-
return (target, propertyKey) => {
|
|
375
|
-
Reflect.defineMetadata(INTENT_BODY_KEY, decoder, target, propertyKey);
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
var import_reflect_metadata5, INTENT_BODY_KEY;
|
|
379
|
-
var init_intent_body_decorator = __esm({
|
|
380
|
-
"src/decorators/intent-body.decorator.ts"() {
|
|
381
|
-
import_reflect_metadata5 = require("reflect-metadata");
|
|
382
|
-
INTENT_BODY_KEY = "axis:intent:body";
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
|
|
386
395
|
// src/decorators/intent-sensors.decorator.ts
|
|
387
396
|
var intent_sensors_decorator_exports = {};
|
|
388
397
|
__export(intent_sensors_decorator_exports, {
|
|
@@ -621,9 +630,12 @@ var require_dto_schema_util = __commonJS({
|
|
|
621
630
|
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
622
631
|
var tlv_1 = (init_tlv(), __toCommonJS(tlv_exports));
|
|
623
632
|
function extractDtoSchema2(dto) {
|
|
633
|
+
if (typeof dto !== "function") {
|
|
634
|
+
throw new Error(`extractDtoSchema expected a class constructor but received ${typeof dto} (${String(dto)}) \u2014 did you pass a plain object or instance to @Intent({ dto }) instead of a class?`);
|
|
635
|
+
}
|
|
624
636
|
const fieldMetas = Reflect.getMetadata(tlv_field_decorator_1.TLV_FIELDS_KEY, dto) || [];
|
|
625
637
|
if (fieldMetas.length === 0) {
|
|
626
|
-
throw new Error(`DTO class ${dto.name} has no @TlvField decorators \u2014 nothing to validate
|
|
638
|
+
throw new Error(`DTO class ${dto.name || "<anonymous>"} has no @TlvField decorators \u2014 nothing to validate. Make sure the class extends AxisTlvDto and its fields are annotated with @TlvField(tag, { kind }).`);
|
|
627
639
|
}
|
|
628
640
|
const tagByProp = /* @__PURE__ */ new Map();
|
|
629
641
|
const fields = fieldMetas.map((m) => {
|
|
@@ -651,14 +663,19 @@ var require_dto_schema_util = __commonJS({
|
|
|
651
663
|
return { fields, validators };
|
|
652
664
|
}
|
|
653
665
|
function buildDtoDecoder2(dto) {
|
|
666
|
+
if (typeof dto !== "function") {
|
|
667
|
+
throw new Error(`buildDtoDecoder expected a class constructor but received ${typeof dto} (${String(dto)}) \u2014 did you pass a plain object or instance to @Intent({ dto }) instead of a class?`);
|
|
668
|
+
}
|
|
654
669
|
const fieldMetas = Reflect.getMetadata(tlv_field_decorator_1.TLV_FIELDS_KEY, dto) || [];
|
|
655
670
|
if (fieldMetas.length === 0) {
|
|
656
|
-
throw new Error(`DTO class ${dto.name} has no @TlvField decorators \u2014 cannot build decoder
|
|
671
|
+
throw new Error(`DTO class ${dto.name || "<anonymous>"} has no @TlvField decorators \u2014 cannot build decoder. Make sure the class extends AxisTlvDto and its fields are annotated with @TlvField(tag, { kind }).`);
|
|
657
672
|
}
|
|
658
673
|
const tagMap = /* @__PURE__ */ new Map();
|
|
659
674
|
for (const m of fieldMetas) {
|
|
660
675
|
tagMap.set(m.tag, { property: m.property, kind: m.options.kind });
|
|
661
676
|
}
|
|
677
|
+
const dtoClass = dto;
|
|
678
|
+
const afterDecode = typeof dtoClass.afterDecode === "function" ? dtoClass.afterDecode.bind(dtoClass) : void 0;
|
|
662
679
|
return (bodyBytes) => {
|
|
663
680
|
const tlvMap2 = (0, tlv_1.decodeTLVs)(new Uint8Array(bodyBytes));
|
|
664
681
|
const result = {};
|
|
@@ -693,6 +710,7 @@ var require_dto_schema_util = __commonJS({
|
|
|
693
710
|
result[meta.property] = raw;
|
|
694
711
|
}
|
|
695
712
|
}
|
|
713
|
+
afterDecode?.(result);
|
|
696
714
|
return result;
|
|
697
715
|
};
|
|
698
716
|
}
|
|
@@ -708,6 +726,8 @@ var AxisTlvDto;
|
|
|
708
726
|
var init_axis_tlv_dto = __esm({
|
|
709
727
|
"src/base/axis-tlv.dto.ts"() {
|
|
710
728
|
AxisTlvDto = class {
|
|
729
|
+
static afterDecode(_dto) {
|
|
730
|
+
}
|
|
711
731
|
};
|
|
712
732
|
}
|
|
713
733
|
});
|