utilium 0.3.3 → 0.3.4
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/struct.d.ts +43 -43
- package/dist/struct.js +5 -7
- package/package.json +1 -1
- package/src/struct.ts +7 -10
package/dist/struct.d.ts
CHANGED
@@ -23,7 +23,7 @@ export declare function struct(options?: Partial<StructOptions>): (target: Class
|
|
23
23
|
/**
|
24
24
|
* Decorates a class member to be serialized
|
25
25
|
*/
|
26
|
-
export declare function member(type: ValidPrimitiveType | ClassLike, length?: number): (target: object,
|
26
|
+
export declare function member(type: ValidPrimitiveType | ClassLike, length?: number): (target: object, context?: ClassMemberDecoratorContext | string | symbol) => void;
|
27
27
|
/**
|
28
28
|
* Serializes a struct into a Uint8Array
|
29
29
|
*/
|
@@ -39,87 +39,87 @@ export declare function deserialize(instance: unknown, _buffer: ArrayBuffer | Ar
|
|
39
39
|
*/
|
40
40
|
export declare const types: {
|
41
41
|
int8: {
|
42
|
-
(length?: number): (target: object, context
|
43
|
-
(target: object, context
|
42
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
43
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
44
44
|
};
|
45
45
|
int16: {
|
46
|
-
(length?: number): (target: object, context
|
47
|
-
(target: object, context
|
46
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
47
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
48
48
|
};
|
49
49
|
int32: {
|
50
|
-
(length?: number): (target: object, context
|
51
|
-
(target: object, context
|
50
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
51
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
52
52
|
};
|
53
53
|
int64: {
|
54
|
-
(length?: number): (target: object, context
|
55
|
-
(target: object, context
|
54
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
55
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
56
56
|
};
|
57
57
|
uint8: {
|
58
|
-
(length?: number): (target: object, context
|
59
|
-
(target: object, context
|
58
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
59
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
60
60
|
};
|
61
61
|
uint16: {
|
62
|
-
(length?: number): (target: object, context
|
63
|
-
(target: object, context
|
62
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
63
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
64
64
|
};
|
65
65
|
uint32: {
|
66
|
-
(length?: number): (target: object, context
|
67
|
-
(target: object, context
|
66
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
67
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
68
68
|
};
|
69
69
|
uint64: {
|
70
|
-
(length?: number): (target: object, context
|
71
|
-
(target: object, context
|
70
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
71
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
72
72
|
};
|
73
73
|
float32: {
|
74
|
-
(length?: number): (target: object, context
|
75
|
-
(target: object, context
|
74
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
75
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
76
76
|
};
|
77
77
|
float64: {
|
78
|
-
(length?: number): (target: object, context
|
79
|
-
(target: object, context
|
78
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
79
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
80
80
|
};
|
81
81
|
Int8: {
|
82
|
-
(length?: number): (target: object, context
|
83
|
-
(target: object, context
|
82
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
83
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
84
84
|
};
|
85
85
|
Int16: {
|
86
|
-
(length?: number): (target: object, context
|
87
|
-
(target: object, context
|
86
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
87
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
88
88
|
};
|
89
89
|
Int32: {
|
90
|
-
(length?: number): (target: object, context
|
91
|
-
(target: object, context
|
90
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
91
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
92
92
|
};
|
93
93
|
Int64: {
|
94
|
-
(length?: number): (target: object, context
|
95
|
-
(target: object, context
|
94
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
95
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
96
96
|
};
|
97
97
|
Uint8: {
|
98
|
-
(length?: number): (target: object, context
|
99
|
-
(target: object, context
|
98
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
99
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
100
100
|
};
|
101
101
|
Uint16: {
|
102
|
-
(length?: number): (target: object, context
|
103
|
-
(target: object, context
|
102
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
103
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
104
104
|
};
|
105
105
|
Uint32: {
|
106
|
-
(length?: number): (target: object, context
|
107
|
-
(target: object, context
|
106
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
107
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
108
108
|
};
|
109
109
|
Uint64: {
|
110
|
-
(length?: number): (target: object, context
|
111
|
-
(target: object, context
|
110
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
111
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
112
112
|
};
|
113
113
|
Float32: {
|
114
|
-
(length?: number): (target: object, context
|
115
|
-
(target: object, context
|
114
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
115
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
116
116
|
};
|
117
117
|
Float64: {
|
118
|
-
(length?: number): (target: object, context
|
119
|
-
(target: object, context
|
118
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
119
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
120
120
|
};
|
121
121
|
char: {
|
122
|
-
(length?: number): (target: object, context
|
123
|
-
(target: object, context
|
122
|
+
(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
123
|
+
(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
124
124
|
};
|
125
125
|
};
|
package/dist/struct.js
CHANGED
@@ -74,15 +74,13 @@ export function struct(options = {}) {
|
|
74
74
|
* Decorates a class member to be serialized
|
75
75
|
*/
|
76
76
|
export function member(type, length) {
|
77
|
-
return function (target,
|
77
|
+
return function (target, context) {
|
78
|
+
let name = typeof context == 'object' ? context.name : context;
|
78
79
|
if (typeof name == 'symbol') {
|
79
80
|
console.warn('Symbol used for struct member name will be coerced to string: ' + name.toString());
|
80
81
|
name = name.toString();
|
81
82
|
}
|
82
|
-
if (typeof target != 'object' || typeof target != 'function') {
|
83
|
-
throw new TypeError('Invalid member for struct field');
|
84
|
-
}
|
85
|
-
if (!('constructor' in target)) {
|
83
|
+
if ((typeof target != 'object' || typeof target != 'function') && !('constructor' in target)) {
|
86
84
|
throw new TypeError('Invalid member for struct field');
|
87
85
|
}
|
88
86
|
target.constructor[init] ||= [];
|
@@ -168,13 +166,13 @@ export function deserialize(instance, _buffer) {
|
|
168
166
|
}
|
169
167
|
}
|
170
168
|
function _member(type) {
|
171
|
-
function
|
169
|
+
function _(targetOrLength, context) {
|
172
170
|
if (typeof targetOrLength == 'number') {
|
173
171
|
return member(type, targetOrLength);
|
174
172
|
}
|
175
173
|
return member(type)(targetOrLength, context);
|
176
174
|
}
|
177
|
-
return
|
175
|
+
return _;
|
178
176
|
}
|
179
177
|
/**
|
180
178
|
* Shortcut types
|
package/package.json
CHANGED
package/src/struct.ts
CHANGED
@@ -133,17 +133,14 @@ export function struct(options: Partial<StructOptions> = {}) {
|
|
133
133
|
* Decorates a class member to be serialized
|
134
134
|
*/
|
135
135
|
export function member(type: ValidPrimitiveType | ClassLike, length?: number) {
|
136
|
-
return function (target: object,
|
136
|
+
return function (target: object, context?: ClassMemberDecoratorContext | string | symbol) {
|
137
|
+
let name = typeof context == 'object' ? context.name : context;
|
137
138
|
if (typeof name == 'symbol') {
|
138
139
|
console.warn('Symbol used for struct member name will be coerced to string: ' + name.toString());
|
139
140
|
name = name.toString();
|
140
141
|
}
|
141
142
|
|
142
|
-
if (typeof target != 'object' || typeof target != 'function') {
|
143
|
-
throw new TypeError('Invalid member for struct field');
|
144
|
-
}
|
145
|
-
|
146
|
-
if (!('constructor' in target)) {
|
143
|
+
if ((typeof target != 'object' || typeof target != 'function') && !('constructor' in target)) {
|
147
144
|
throw new TypeError('Invalid member for struct field');
|
148
145
|
}
|
149
146
|
|
@@ -251,16 +248,16 @@ export function deserialize(instance: unknown, _buffer: ArrayBuffer | ArrayBuffe
|
|
251
248
|
}
|
252
249
|
|
253
250
|
function _member<T extends ValidPrimitiveType>(type: T) {
|
254
|
-
function
|
255
|
-
function
|
256
|
-
function
|
251
|
+
function _(length?: number): (target: object, context?: string | symbol | ClassMemberDecoratorContext) => void;
|
252
|
+
function _(target: object, context?: string | symbol | ClassMemberDecoratorContext): void;
|
253
|
+
function _(targetOrLength: object | number, context?: string | symbol | ClassMemberDecoratorContext) {
|
257
254
|
if (typeof targetOrLength == 'number') {
|
258
255
|
return member(type, targetOrLength);
|
259
256
|
}
|
260
257
|
|
261
258
|
return member(type)(targetOrLength, context);
|
262
259
|
}
|
263
|
-
return
|
260
|
+
return _;
|
264
261
|
}
|
265
262
|
|
266
263
|
/**
|