@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.
Files changed (75) hide show
  1. package/CHANGELOG.json +18 -0
  2. package/CHANGELOG.md +13 -1
  3. package/LICENSE +1 -1
  4. package/esm/basic/definition.d.ts +43 -43
  5. package/esm/basic/definition.d.ts.map +1 -1
  6. package/esm/basic/definition.js +23 -23
  7. package/esm/basic/definition.js.map +1 -1
  8. package/esm/basic/field-value.d.ts +38 -38
  9. package/esm/basic/field-value.d.ts.map +1 -1
  10. package/esm/basic/field-value.js +45 -45
  11. package/esm/basic/field-value.js.map +1 -1
  12. package/esm/basic/index.d.ts +5 -5
  13. package/esm/basic/index.js +5 -5
  14. package/esm/basic/options.d.ts +9 -9
  15. package/esm/basic/options.js +3 -3
  16. package/esm/basic/stream.d.ts +19 -19
  17. package/esm/basic/stream.js +1 -1
  18. package/esm/basic/struct-value.d.ts +25 -25
  19. package/esm/basic/struct-value.d.ts.map +1 -1
  20. package/esm/basic/struct-value.js +56 -49
  21. package/esm/basic/struct-value.js.map +1 -1
  22. package/esm/index.d.ts +13 -13
  23. package/esm/index.js +5 -5
  24. package/esm/struct.d.ts +130 -129
  25. package/esm/struct.d.ts.map +1 -1
  26. package/esm/struct.js +210 -208
  27. package/esm/struct.js.map +1 -1
  28. package/esm/sync-promise.d.ts +12 -12
  29. package/esm/sync-promise.d.ts.map +1 -1
  30. package/esm/sync-promise.js +70 -70
  31. package/esm/sync-promise.js.map +1 -1
  32. package/esm/types/bigint.d.ts +25 -24
  33. package/esm/types/bigint.d.ts.map +1 -1
  34. package/esm/types/bigint.js +47 -46
  35. package/esm/types/bigint.js.map +1 -1
  36. package/esm/types/buffer/base.d.ts +64 -63
  37. package/esm/types/buffer/base.d.ts.map +1 -1
  38. package/esm/types/buffer/base.js +102 -101
  39. package/esm/types/buffer/base.js.map +1 -1
  40. package/esm/types/buffer/fixed-length.d.ts +8 -7
  41. package/esm/types/buffer/fixed-length.d.ts.map +1 -1
  42. package/esm/types/buffer/fixed-length.js +6 -7
  43. package/esm/types/buffer/fixed-length.js.map +1 -1
  44. package/esm/types/buffer/index.d.ts +3 -3
  45. package/esm/types/buffer/index.js +3 -3
  46. package/esm/types/buffer/variable-length.d.ts +44 -42
  47. package/esm/types/buffer/variable-length.d.ts.map +1 -1
  48. package/esm/types/buffer/variable-length.js +75 -75
  49. package/esm/types/buffer/variable-length.js.map +1 -1
  50. package/esm/types/index.d.ts +3 -3
  51. package/esm/types/index.js +3 -3
  52. package/esm/types/number.d.ts +27 -32
  53. package/esm/types/number.d.ts.map +1 -1
  54. package/esm/types/number.js +113 -64
  55. package/esm/types/number.js.map +1 -1
  56. package/esm/utils.d.ts +47 -47
  57. package/esm/utils.d.ts.map +1 -1
  58. package/esm/utils.js +15 -22
  59. package/esm/utils.js.map +1 -1
  60. package/package.json +13 -9
  61. package/src/basic/definition.ts +10 -7
  62. package/src/basic/field-value.ts +15 -12
  63. package/src/basic/index.ts +5 -5
  64. package/src/basic/struct-value.ts +16 -10
  65. package/src/index.ts +5 -5
  66. package/src/struct.ts +205 -200
  67. package/src/sync-promise.ts +32 -12
  68. package/src/types/bigint.ts +56 -30
  69. package/src/types/buffer/base.ts +54 -36
  70. package/src/types/buffer/fixed-length.ts +5 -9
  71. package/src/types/buffer/variable-length.ts +38 -24
  72. package/src/types/number.ts +128 -77
  73. package/src/utils.ts +30 -8
  74. package/tsconfig.build.json +1 -1
  75. 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 declare 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 declare 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 declare type Overwrite<TBase extends object, TNew extends object> = Evaluate<Omit<TBase, keyof TNew> & TNew>;
29
- /**
30
- * Remove fields with `never` type
31
- */
32
- export declare 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 declare type KeysOfType<T, TValue> = {
39
- [TKey in keyof T]: T[TKey] extends TValue ? TKey : never;
40
- }[keyof T];
41
- export declare 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;
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
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,oBAAY,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;AAE5B;;GAEG;AACH,oBAAY,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,oBAAY,SAAS,CAAC,KAAK,SAAS,MAAM,EAAE,IAAI,SAAS,MAAM,IAC3D,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;AAE7C;;GAEG;AACH,oBAAY,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE;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,CAAC,CAAC;AAEpG;;GAEG;AACH,oBAAY,UAAU,CAAC,CAAC,EAAE,MAAM,IAC5B;KAAG,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,KAAK;CAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAE1E,oBAAY,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAEnD;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,KAAK,CAAC,CAElC;AAeD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAEpD;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,GAAG,MAAM,CAExE"}
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
- // This library can't use `@types/node` or `lib: dom`
8
- // because they will pollute the global scope
9
- // So `TextEncoder` and `TextDecoder` are not available
10
- // Node.js 8.3 ships `TextEncoder` and `TextDecoder` in `util` module.
11
- // But using top level await to load them requires Node.js 14.1.
12
- // So there is no point to do that. Let's just assume they exist in global.
13
- // @ts-expect-error
14
- const Utf8Encoder = new TextEncoder();
15
- // @ts-expect-error
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":"AA2CA;;GAEG;AACH,MAAM,UAAU,WAAW;IACvB,OAAO,SAAyB,CAAC;AACrC,CAAC;AAED,qDAAqD;AACrD,6CAA6C;AAC7C,uDAAuD;AAEvD,sEAAsE;AACtE,gEAAgE;AAChE,2EAA2E;AAE3E,mBAAmB;AACnB,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,mBAAmB;AACnB,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"}
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.17",
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.17",
31
- "tslib": "^2.4.0"
30
+ "@yume-chan/dataview-bigint-polyfill": "^0.0.19",
31
+ "tslib": "^2.4.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@jest/globals": "^28.1.2",
35
- "@yume-chan/ts-package-builder": "^1.0.0",
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
- "jest": "^28.1.2",
38
- "ts-jest": "^28.0.5",
39
- "typescript": "^4.7.4"
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
  }
@@ -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
  }
@@ -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<any, any, any> = StructFieldDefinition<any, any, any>
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 this.get !== StructFieldValue.prototype.get ||
25
- this.set !== StructFieldValue.prototype.set;
28
+ return (
29
+ this.get !== StructFieldValue.prototype.get ||
30
+ this.set !== StructFieldValue.prototype.set
31
+ );
26
32
  }
27
33
 
28
- protected value: TDefinition['TValue'];
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['TValue'],
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['TValue'] {
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['TValue']): void {
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
  }
@@ -1,5 +1,5 @@
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';
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<PropertyKey, StructFieldValue> = {};
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: any) {
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
- this.value,
25
- STRUCT_VALUE_SYMBOL,
26
- { enumerable: false, value: this }
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() { return fieldValue.get(); },
46
- set(v) { fieldValue.set(v); },
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 './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';
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";