@yume-chan/struct 0.0.17 → 0.0.19
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/CHANGELOG.json +18 -0
- package/CHANGELOG.md +13 -1
- package/LICENSE +1 -1
- package/esm/basic/definition.d.ts +43 -43
- package/esm/basic/definition.d.ts.map +1 -1
- package/esm/basic/definition.js +23 -23
- package/esm/basic/definition.js.map +1 -1
- package/esm/basic/field-value.d.ts +38 -38
- package/esm/basic/field-value.d.ts.map +1 -1
- package/esm/basic/field-value.js +45 -45
- package/esm/basic/field-value.js.map +1 -1
- package/esm/basic/index.d.ts +5 -5
- package/esm/basic/index.js +5 -5
- package/esm/basic/options.d.ts +9 -9
- package/esm/basic/options.js +3 -3
- package/esm/basic/stream.d.ts +19 -19
- package/esm/basic/stream.js +1 -1
- package/esm/basic/struct-value.d.ts +25 -25
- package/esm/basic/struct-value.d.ts.map +1 -1
- package/esm/basic/struct-value.js +56 -49
- package/esm/basic/struct-value.js.map +1 -1
- package/esm/index.d.ts +13 -13
- package/esm/index.js +5 -5
- package/esm/struct.d.ts +130 -129
- package/esm/struct.d.ts.map +1 -1
- package/esm/struct.js +210 -208
- package/esm/struct.js.map +1 -1
- package/esm/sync-promise.d.ts +12 -12
- package/esm/sync-promise.d.ts.map +1 -1
- package/esm/sync-promise.js +70 -70
- package/esm/sync-promise.js.map +1 -1
- package/esm/types/bigint.d.ts +25 -24
- package/esm/types/bigint.d.ts.map +1 -1
- package/esm/types/bigint.js +47 -46
- package/esm/types/bigint.js.map +1 -1
- package/esm/types/buffer/base.d.ts +64 -63
- package/esm/types/buffer/base.d.ts.map +1 -1
- package/esm/types/buffer/base.js +102 -101
- package/esm/types/buffer/base.js.map +1 -1
- package/esm/types/buffer/fixed-length.d.ts +8 -7
- package/esm/types/buffer/fixed-length.d.ts.map +1 -1
- package/esm/types/buffer/fixed-length.js +6 -7
- package/esm/types/buffer/fixed-length.js.map +1 -1
- package/esm/types/buffer/index.d.ts +3 -3
- package/esm/types/buffer/index.js +3 -3
- package/esm/types/buffer/variable-length.d.ts +44 -42
- package/esm/types/buffer/variable-length.d.ts.map +1 -1
- package/esm/types/buffer/variable-length.js +75 -75
- package/esm/types/buffer/variable-length.js.map +1 -1
- package/esm/types/index.d.ts +3 -3
- package/esm/types/index.js +3 -3
- package/esm/types/number.d.ts +27 -32
- package/esm/types/number.d.ts.map +1 -1
- package/esm/types/number.js +113 -64
- package/esm/types/number.js.map +1 -1
- package/esm/utils.d.ts +47 -47
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js +15 -22
- package/esm/utils.js.map +1 -1
- package/package.json +13 -9
- package/src/basic/definition.ts +10 -7
- package/src/basic/field-value.ts +15 -12
- package/src/basic/index.ts +5 -5
- package/src/basic/struct-value.ts +16 -10
- package/src/index.ts +5 -5
- package/src/struct.ts +205 -200
- package/src/sync-promise.ts +32 -12
- package/src/types/bigint.ts +56 -30
- package/src/types/buffer/base.ts +54 -36
- package/src/types/buffer/fixed-length.ts +5 -9
- package/src/types/buffer/variable-length.ts +38 -24
- package/src/types/number.ts +128 -77
- package/src/utils.ts +30 -8
- package/tsconfig.build.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
package/esm/utils.d.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* When evaluating a very complex generic type alias,
|
|
3
|
-
* tell TypeScript to use `T`, instead of current type alias' name, as the result type name
|
|
4
|
-
*
|
|
5
|
-
* Example:
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* type WithIdentity<T> = Identity<SomeType<T>>;
|
|
9
|
-
* type WithoutIdentity<T> = SomeType<T>;
|
|
10
|
-
*
|
|
11
|
-
* type WithIdentityResult = WithIdentity<number>;
|
|
12
|
-
* // Hover on this one shows `SomeType<number>`
|
|
13
|
-
*
|
|
14
|
-
* type WithoutIdentityResult = WithoutIdentity<number>;
|
|
15
|
-
* // Hover on this one shows `WithoutIdentity<number>`
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export
|
|
19
|
-
/**
|
|
20
|
-
* Collapse an intersection type (`{ foo: string } & { bar: number }`) to a simple type (`{ foo: string, bar: number }`)
|
|
21
|
-
*/
|
|
22
|
-
export
|
|
23
|
-
[K in keyof U]: U[K];
|
|
24
|
-
} : never;
|
|
25
|
-
/**
|
|
26
|
-
* Overwrite fields in `TBase` with fields in `TNew`
|
|
27
|
-
*/
|
|
28
|
-
export
|
|
29
|
-
/**
|
|
30
|
-
* Remove fields with `never` type
|
|
31
|
-
*/
|
|
32
|
-
export
|
|
33
|
-
[K in keyof T]: [T[K]] extends [never] ? never : K;
|
|
34
|
-
}[keyof T]>;
|
|
35
|
-
/**
|
|
36
|
-
* Extract keys of fields in `T` that has type `TValue`
|
|
37
|
-
*/
|
|
38
|
-
export
|
|
39
|
-
[TKey in keyof T]: T[TKey] extends TValue ? TKey : never;
|
|
40
|
-
}[keyof T];
|
|
41
|
-
export
|
|
42
|
-
/**
|
|
43
|
-
* Returns a (fake) value of the given type.
|
|
44
|
-
*/
|
|
45
|
-
export declare function placeholder<T>(): T;
|
|
46
|
-
export declare function encodeUtf8(input: string): Uint8Array;
|
|
47
|
-
export declare function decodeUtf8(buffer: ArrayBufferView | ArrayBuffer): string;
|
|
1
|
+
/**
|
|
2
|
+
* When evaluating a very complex generic type alias,
|
|
3
|
+
* tell TypeScript to use `T`, instead of current type alias' name, as the result type name
|
|
4
|
+
*
|
|
5
|
+
* Example:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* type WithIdentity<T> = Identity<SomeType<T>>;
|
|
9
|
+
* type WithoutIdentity<T> = SomeType<T>;
|
|
10
|
+
*
|
|
11
|
+
* type WithIdentityResult = WithIdentity<number>;
|
|
12
|
+
* // Hover on this one shows `SomeType<number>`
|
|
13
|
+
*
|
|
14
|
+
* type WithoutIdentityResult = WithoutIdentity<number>;
|
|
15
|
+
* // Hover on this one shows `WithoutIdentity<number>`
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export type Identity<T> = T;
|
|
19
|
+
/**
|
|
20
|
+
* Collapse an intersection type (`{ foo: string } & { bar: number }`) to a simple type (`{ foo: string, bar: number }`)
|
|
21
|
+
*/
|
|
22
|
+
export type Evaluate<T> = T extends infer U ? {
|
|
23
|
+
[K in keyof U]: U[K];
|
|
24
|
+
} : never;
|
|
25
|
+
/**
|
|
26
|
+
* Overwrite fields in `TBase` with fields in `TNew`
|
|
27
|
+
*/
|
|
28
|
+
export type Overwrite<TBase extends object, TNew extends object> = Evaluate<Omit<TBase, keyof TNew> & TNew>;
|
|
29
|
+
/**
|
|
30
|
+
* Remove fields with `never` type
|
|
31
|
+
*/
|
|
32
|
+
export type OmitNever<T> = Pick<T, {
|
|
33
|
+
[K in keyof T]: [T[K]] extends [never] ? never : K;
|
|
34
|
+
}[keyof T]>;
|
|
35
|
+
/**
|
|
36
|
+
* Extract keys of fields in `T` that has type `TValue`
|
|
37
|
+
*/
|
|
38
|
+
export type KeysOfType<T, TValue> = {
|
|
39
|
+
[TKey in keyof T]: T[TKey] extends TValue ? TKey : never;
|
|
40
|
+
}[keyof T];
|
|
41
|
+
export type ValueOrPromise<T> = T | PromiseLike<T>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a (fake) value of the given type.
|
|
44
|
+
*/
|
|
45
|
+
export declare function placeholder<T>(): T;
|
|
46
|
+
export declare function encodeUtf8(input: string): Uint8Array;
|
|
47
|
+
export declare function decodeUtf8(buffer: ArrayBufferView | ArrayBuffer): string;
|
|
48
48
|
//# sourceMappingURL=utils.d.ts.map
|
package/esm/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,KAAK,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,MAAM,EAAE,IAAI,SAAS,MAAM,IAAI,QAAQ,CACvE,IAAI,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,GAAG,IAAI,CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,IAAI,CAC3B,CAAC,EACD;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC;CAAE,CAAC,MAAM,CAAC,CAAC,CAClE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,MAAM,IAAI;KAC/B,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,KAAK;CAC3D,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAEnD;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,KAAK,CAAC,CAElC;AAgCD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAEpD;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,GAAG,MAAM,CAExE"}
|
package/esm/utils.js
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a (fake) value of the given type.
|
|
3
|
-
*/
|
|
4
|
-
export function placeholder() {
|
|
5
|
-
return undefined;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const Utf8Decoder = new TextDecoder();
|
|
17
|
-
export function encodeUtf8(input) {
|
|
18
|
-
return Utf8Encoder.encode(input);
|
|
19
|
-
}
|
|
20
|
-
export function decodeUtf8(buffer) {
|
|
21
|
-
return Utf8Decoder.decode(buffer);
|
|
22
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Returns a (fake) value of the given type.
|
|
3
|
+
*/
|
|
4
|
+
export function placeholder() {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const { TextEncoder, TextDecoder } = globalThis;
|
|
8
|
+
const Utf8Encoder = new TextEncoder();
|
|
9
|
+
const Utf8Decoder = new TextDecoder();
|
|
10
|
+
export function encodeUtf8(input) {
|
|
11
|
+
return Utf8Encoder.encode(input);
|
|
12
|
+
}
|
|
13
|
+
export function decodeUtf8(buffer) {
|
|
14
|
+
return Utf8Decoder.decode(buffer);
|
|
15
|
+
}
|
|
23
16
|
//# sourceMappingURL=utils.js.map
|
package/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAgDA;;GAEG;AACH,MAAM,UAAU,WAAW;IACvB,OAAO,SAAyB,CAAC;AACrC,CAAC;AA2BD,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,UAAwC,CAAC;AAE9E,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,MAAM,UAAU,UAAU,CAAC,KAAa;IACpC,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAqC;IAC5D,OAAO,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yume-chan/struct",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "C-style structure serializer and deserializer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"structure",
|
|
@@ -27,20 +27,24 @@
|
|
|
27
27
|
"main": "esm/index.js",
|
|
28
28
|
"types": "esm/index.d.ts",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@yume-chan/dataview-bigint-polyfill": "^0.0.
|
|
31
|
-
"tslib": "^2.4.
|
|
30
|
+
"@yume-chan/dataview-bigint-polyfill": "^0.0.19",
|
|
31
|
+
"tslib": "^2.4.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@jest/globals": "^
|
|
35
|
-
"@yume-chan/
|
|
34
|
+
"@jest/globals": "^29.5.0",
|
|
35
|
+
"@yume-chan/eslint-config": "^1.0.0",
|
|
36
|
+
"@yume-chan/tsconfig": "^1.0.0",
|
|
36
37
|
"cross-env": "^7.0.3",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
38
|
+
"eslint": "^8.36.0",
|
|
39
|
+
"jest": "^29.5.0",
|
|
40
|
+
"prettier": "^2.8.4",
|
|
41
|
+
"ts-jest": "^29.0.4",
|
|
42
|
+
"typescript": "^4.9.4"
|
|
40
43
|
},
|
|
41
44
|
"scripts": {
|
|
42
45
|
"build": "tsc -b tsconfig.build.json",
|
|
43
46
|
"build:watch": "tsc -b tsconfig.build.json",
|
|
44
|
-
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage"
|
|
47
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
|
|
48
|
+
"lint": "eslint src/**/*.ts --fix && prettier src/**/*.ts --write --tab-width 4"
|
|
45
49
|
}
|
|
46
50
|
}
|
package/src/basic/definition.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { StructAsyncDeserializeStream, StructDeserializeStream } from "./stream.js";
|
|
2
1
|
import type { StructFieldValue } from "./field-value.js";
|
|
3
|
-
import type { StructValue } from "./struct-value.js";
|
|
4
2
|
import type { StructOptions } from "./options.js";
|
|
3
|
+
import type {
|
|
4
|
+
StructAsyncDeserializeStream,
|
|
5
|
+
StructDeserializeStream,
|
|
6
|
+
} from "./stream.js";
|
|
7
|
+
import type { StructValue } from "./struct-value.js";
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* A field definition defines how to deserialize a field.
|
|
@@ -13,8 +16,8 @@ import type { StructOptions } from "./options.js";
|
|
|
13
16
|
export abstract class StructFieldDefinition<
|
|
14
17
|
TOptions = void,
|
|
15
18
|
TValue = unknown,
|
|
16
|
-
TOmitInitKey extends PropertyKey = never
|
|
17
|
-
|
|
19
|
+
TOmitInitKey extends PropertyKey = never
|
|
20
|
+
> {
|
|
18
21
|
/**
|
|
19
22
|
* When `T` is a type initiated `StructFieldDefinition`,
|
|
20
23
|
* use `T['TValue']` to retrieve its `TValue` type parameter.
|
|
@@ -46,7 +49,7 @@ export abstract class StructFieldDefinition<
|
|
|
46
49
|
public abstract create(
|
|
47
50
|
options: Readonly<StructOptions>,
|
|
48
51
|
structValue: StructValue,
|
|
49
|
-
value: TValue
|
|
52
|
+
value: TValue
|
|
50
53
|
): StructFieldValue<this>;
|
|
51
54
|
|
|
52
55
|
/**
|
|
@@ -58,11 +61,11 @@ export abstract class StructFieldDefinition<
|
|
|
58
61
|
public abstract deserialize(
|
|
59
62
|
options: Readonly<StructOptions>,
|
|
60
63
|
stream: StructDeserializeStream,
|
|
61
|
-
structValue: StructValue
|
|
64
|
+
structValue: StructValue
|
|
62
65
|
): StructFieldValue<this>;
|
|
63
66
|
public abstract deserialize(
|
|
64
67
|
options: Readonly<StructOptions>,
|
|
65
68
|
stream: StructAsyncDeserializeStream,
|
|
66
|
-
struct: StructValue
|
|
69
|
+
struct: StructValue
|
|
67
70
|
): Promise<StructFieldValue<this>>;
|
|
68
71
|
}
|
package/src/basic/field-value.ts
CHANGED
|
@@ -9,8 +9,12 @@ import type { StructValue } from "./struct-value.js";
|
|
|
9
9
|
* helpful for the serialization process.
|
|
10
10
|
*/
|
|
11
11
|
export abstract class StructFieldValue<
|
|
12
|
-
TDefinition extends StructFieldDefinition<
|
|
13
|
-
|
|
12
|
+
TDefinition extends StructFieldDefinition<
|
|
13
|
+
any,
|
|
14
|
+
any,
|
|
15
|
+
any
|
|
16
|
+
> = StructFieldDefinition<any, any, any>
|
|
17
|
+
> {
|
|
14
18
|
/** Gets the definition associated with this runtime value */
|
|
15
19
|
public readonly definition: TDefinition;
|
|
16
20
|
|
|
@@ -21,17 +25,19 @@ export abstract class StructFieldValue<
|
|
|
21
25
|
public readonly struct: StructValue;
|
|
22
26
|
|
|
23
27
|
public get hasCustomAccessors(): boolean {
|
|
24
|
-
return
|
|
25
|
-
this.
|
|
28
|
+
return (
|
|
29
|
+
this.get !== StructFieldValue.prototype.get ||
|
|
30
|
+
this.set !== StructFieldValue.prototype.set
|
|
31
|
+
);
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
protected value: TDefinition[
|
|
34
|
+
protected value: TDefinition["TValue"];
|
|
29
35
|
|
|
30
36
|
public constructor(
|
|
31
37
|
definition: TDefinition,
|
|
32
38
|
options: Readonly<StructOptions>,
|
|
33
39
|
struct: StructValue,
|
|
34
|
-
value: TDefinition[
|
|
40
|
+
value: TDefinition["TValue"]
|
|
35
41
|
) {
|
|
36
42
|
this.definition = definition;
|
|
37
43
|
this.options = options;
|
|
@@ -51,22 +57,19 @@ export abstract class StructFieldValue<
|
|
|
51
57
|
/**
|
|
52
58
|
* When implemented in derived classes, reads current field's value.
|
|
53
59
|
*/
|
|
54
|
-
public get(): TDefinition[
|
|
60
|
+
public get(): TDefinition["TValue"] {
|
|
55
61
|
return this.value;
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
/**
|
|
59
65
|
* When implemented in derived classes, updates current field's value.
|
|
60
66
|
*/
|
|
61
|
-
public set(value: TDefinition[
|
|
67
|
+
public set(value: TDefinition["TValue"]): void {
|
|
62
68
|
this.value = value;
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
/**
|
|
66
72
|
* When implemented in derived classes, serializes this field into `dataView` at `offset`
|
|
67
73
|
*/
|
|
68
|
-
public abstract serialize(
|
|
69
|
-
dataView: DataView,
|
|
70
|
-
offset: number,
|
|
71
|
-
): void;
|
|
74
|
+
public abstract serialize(dataView: DataView, offset: number): void;
|
|
72
75
|
}
|
package/src/basic/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./definition.js";
|
|
2
|
+
export * from "./field-value.js";
|
|
3
|
+
export * from "./options.js";
|
|
4
|
+
export * from "./stream.js";
|
|
5
|
+
export * from "./struct-value.js";
|
|
@@ -6,25 +6,27 @@ export const STRUCT_VALUE_SYMBOL = Symbol("struct-value");
|
|
|
6
6
|
* A struct value is a map between keys in a struct and their field values.
|
|
7
7
|
*/
|
|
8
8
|
export class StructValue {
|
|
9
|
-
/** @internal */ readonly fieldValues: Record<
|
|
9
|
+
/** @internal */ readonly fieldValues: Record<
|
|
10
|
+
PropertyKey,
|
|
11
|
+
StructFieldValue
|
|
12
|
+
> = {};
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Gets the result struct value object
|
|
13
16
|
*/
|
|
14
17
|
public readonly value: Record<PropertyKey, unknown>;
|
|
15
18
|
|
|
16
|
-
public constructor(prototype:
|
|
19
|
+
public constructor(prototype: object) {
|
|
17
20
|
// PERF: `Object.create(extra)` is 50% faster
|
|
18
21
|
// than `Object.defineProperties(this.value, extra)`
|
|
19
|
-
this.value = Object.create(prototype)
|
|
22
|
+
this.value = Object.create(prototype) as Record<PropertyKey, unknown>;
|
|
20
23
|
|
|
21
24
|
// PERF: `Object.defineProperty` is slow
|
|
22
25
|
// but we need it to be non-enumerable
|
|
23
|
-
Object.defineProperty(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
26
|
+
Object.defineProperty(this.value, STRUCT_VALUE_SYMBOL, {
|
|
27
|
+
enumerable: false,
|
|
28
|
+
value: this,
|
|
29
|
+
});
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -42,8 +44,12 @@ export class StructValue {
|
|
|
42
44
|
Object.defineProperty(this.value, name, {
|
|
43
45
|
configurable: true,
|
|
44
46
|
enumerable: true,
|
|
45
|
-
get() {
|
|
46
|
-
|
|
47
|
+
get() {
|
|
48
|
+
return fieldValue.get();
|
|
49
|
+
},
|
|
50
|
+
set(v) {
|
|
51
|
+
fieldValue.set(v);
|
|
52
|
+
},
|
|
47
53
|
});
|
|
48
54
|
} else {
|
|
49
55
|
this.value[name] = fieldValue.get();
|
package/src/index.ts
CHANGED
|
@@ -10,8 +10,8 @@ declare global {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export { Struct as default } from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
13
|
+
export * from "./basic/index.js";
|
|
14
|
+
export * from "./struct.js";
|
|
15
|
+
export { Struct as default } from "./struct.js";
|
|
16
|
+
export * from "./types/index.js";
|
|
17
|
+
export * from "./utils.js";
|