@yume-chan/struct 0.0.9 → 0.0.10

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 (84) hide show
  1. package/CHANGELOG.json +23 -0
  2. package/CHANGELOG.md +16 -0
  3. package/LICENSE +21 -21
  4. package/README.md +720 -709
  5. package/dts/basic/context.d.ts +10 -18
  6. package/dts/basic/context.d.ts.map +1 -1
  7. package/dts/basic/definition.d.ts +4 -4
  8. package/dts/basic/definition.d.ts.map +1 -1
  9. package/dts/basic/field-value.d.ts +3 -5
  10. package/dts/basic/field-value.d.ts.map +1 -1
  11. package/dts/basic/struct-value.d.ts.map +1 -1
  12. package/dts/struct.d.ts +16 -17
  13. package/dts/struct.d.ts.map +1 -1
  14. package/dts/syncbird.d.ts +20 -0
  15. package/dts/syncbird.d.ts.map +1 -0
  16. package/dts/types/array-buffer.d.ts +13 -12
  17. package/dts/types/array-buffer.d.ts.map +1 -1
  18. package/dts/types/number.d.ts +4 -3
  19. package/dts/types/number.d.ts.map +1 -1
  20. package/dts/types/variable-length-array-buffer.d.ts +4 -4
  21. package/dts/types/variable-length-array-buffer.d.ts.map +1 -1
  22. package/dts/utils.d.ts +3 -2
  23. package/dts/utils.d.ts.map +1 -1
  24. package/esm/basic/context.js.map +1 -1
  25. package/esm/basic/definition.js.map +1 -1
  26. package/esm/basic/field-value.js +1 -2
  27. package/esm/basic/field-value.js.map +1 -1
  28. package/esm/basic/struct-value.js +0 -6
  29. package/esm/basic/struct-value.js.map +1 -1
  30. package/esm/struct.js +27 -17
  31. package/esm/struct.js.map +1 -1
  32. package/esm/syncbird.js +25 -0
  33. package/esm/syncbird.js.map +1 -0
  34. package/esm/types/array-buffer.js +21 -20
  35. package/esm/types/array-buffer.js.map +1 -1
  36. package/esm/types/number.js +9 -8
  37. package/esm/types/number.js.map +1 -1
  38. package/esm/types/variable-length-array-buffer.js +8 -8
  39. package/esm/types/variable-length-array-buffer.js.map +1 -1
  40. package/esm/utils.js +10 -0
  41. package/esm/utils.js.map +1 -1
  42. package/package.json +47 -50
  43. package/src/basic/context.ts +32 -42
  44. package/src/basic/definition.ts +72 -69
  45. package/src/basic/field-value.ts +67 -73
  46. package/src/basic/index.ts +4 -4
  47. package/src/basic/struct-value.ts +39 -45
  48. package/src/index.ts +5 -5
  49. package/src/struct.ts +595 -575
  50. package/src/syncbird.ts +53 -0
  51. package/src/types/array-buffer.ts +194 -184
  52. package/src/types/fixed-length-array-buffer.ts +17 -17
  53. package/src/types/index.ts +4 -4
  54. package/src/types/number.ts +114 -100
  55. package/src/types/variable-length-array-buffer.ts +142 -145
  56. package/src/utils.ts +62 -51
  57. package/cjs/basic/context.js +0 -7
  58. package/cjs/basic/context.js.map +0 -1
  59. package/cjs/basic/definition.js +0 -25
  60. package/cjs/basic/definition.js.map +0 -1
  61. package/cjs/basic/field-value.js +0 -40
  62. package/cjs/basic/field-value.js.map +0 -1
  63. package/cjs/basic/index.js +0 -8
  64. package/cjs/basic/index.js.map +0 -1
  65. package/cjs/basic/struct-value.js +0 -46
  66. package/cjs/basic/struct-value.js.map +0 -1
  67. package/cjs/index.js +0 -11
  68. package/cjs/index.js.map +0 -1
  69. package/cjs/struct.js +0 -177
  70. package/cjs/struct.js.map +0 -1
  71. package/cjs/types/array-buffer.js +0 -118
  72. package/cjs/types/array-buffer.js.map +0 -1
  73. package/cjs/types/fixed-length-array-buffer.js +0 -12
  74. package/cjs/types/fixed-length-array-buffer.js.map +0 -1
  75. package/cjs/types/index.js +0 -8
  76. package/cjs/types/index.js.map +0 -1
  77. package/cjs/types/number.js +0 -52
  78. package/cjs/types/number.js.map +0 -1
  79. package/cjs/types/variable-length-array-buffer.js +0 -77
  80. package/cjs/types/variable-length-array-buffer.js.map +0 -1
  81. package/cjs/utils.js +0 -11
  82. package/cjs/utils.js.map +0 -1
  83. package/tsconfig.cjs.json +0 -11
  84. package/tsconfig.esm.json +0 -15
@@ -1,73 +1,67 @@
1
- import type { StructOptions, StructSerializationContext } from './context';
2
- import type { StructFieldDefinition } from './definition';
3
- import type { StructValue } from './struct-value';
4
-
5
- /**
6
- * Field runtime value manages one field of one `Struct` instance.
7
- *
8
- * If one `StructFieldDefinition` needs to change other field's semantics
9
- * It can override other fields' `StructFieldValue` in its own `StructFieldValue`'s constructor
10
- */
11
- export abstract class StructFieldValue<
12
- TDefinition extends StructFieldDefinition<any, any, any> = StructFieldDefinition<any, any, any>
13
- > {
14
- /** Gets the definition associated with this runtime value */
15
- public readonly definition: TDefinition;
16
-
17
- /** Gets the options of the associated `Struct` */
18
- public readonly options: Readonly<StructOptions>;
19
-
20
- /** Gets the serialization context of the associated `Struct` instance */
21
- public readonly context: StructSerializationContext;
22
-
23
- /** Gets the associated `Struct` instance */
24
- public readonly struct: StructValue;
25
-
26
- protected value: TDefinition['TValue'];
27
-
28
- public constructor(
29
- definition: TDefinition,
30
- options: Readonly<StructOptions>,
31
- context: StructSerializationContext,
32
- struct: StructValue,
33
- value: TDefinition['TValue'],
34
- ) {
35
- this.definition = definition;
36
- this.options = options;
37
- this.context = context;
38
- this.struct = struct;
39
- this.value = value;
40
- }
41
-
42
- /**
43
- * Gets size of this field. By default, it returns its `definition`'s size.
44
- *
45
- * When overridden in derived classes, can have custom logic to calculate the actual size.
46
- */
47
- public getSize(): number {
48
- return this.definition.getSize();
49
- }
50
-
51
- /**
52
- * When implemented in derived classes, returns the current value of this field
53
- */
54
- public get(): TDefinition['TValue'] {
55
- return this.value;
56
- }
57
-
58
- /**
59
- * When implemented in derived classes, update the current value of this field
60
- */
61
- public set(value: TDefinition['TValue']): void {
62
- this.value = value;
63
- }
64
-
65
- /**
66
- * When implemented in derived classes, serializes this field into `dataView` at `offset`
67
- */
68
- public abstract serialize(
69
- dataView: DataView,
70
- offset: number,
71
- context: StructSerializationContext
72
- ): void;
73
- }
1
+ import type { StructOptions } from './context';
2
+ import type { StructFieldDefinition } from './definition';
3
+ import type { StructValue } from './struct-value';
4
+
5
+ /**
6
+ * Field runtime value manages one field of one `Struct` instance.
7
+ *
8
+ * If one `StructFieldDefinition` needs to change other field's semantics
9
+ * It can override other fields' `StructFieldValue` in its own `StructFieldValue`'s constructor
10
+ */
11
+ export abstract class StructFieldValue<
12
+ TDefinition extends StructFieldDefinition<any, any, any> = StructFieldDefinition<any, any, any>
13
+ > {
14
+ /** Gets the definition associated with this runtime value */
15
+ public readonly definition: TDefinition;
16
+
17
+ /** Gets the options of the associated `Struct` */
18
+ public readonly options: Readonly<StructOptions>;
19
+
20
+ /** Gets the associated `Struct` instance */
21
+ public readonly struct: StructValue;
22
+
23
+ protected value: TDefinition['TValue'];
24
+
25
+ public constructor(
26
+ definition: TDefinition,
27
+ options: Readonly<StructOptions>,
28
+ struct: StructValue,
29
+ value: TDefinition['TValue'],
30
+ ) {
31
+ this.definition = definition;
32
+ this.options = options;
33
+ this.struct = struct;
34
+ this.value = value;
35
+ }
36
+
37
+ /**
38
+ * Gets size of this field. By default, it returns its `definition`'s size.
39
+ *
40
+ * When overridden in derived classes, can have custom logic to calculate the actual size.
41
+ */
42
+ public getSize(): number {
43
+ return this.definition.getSize();
44
+ }
45
+
46
+ /**
47
+ * When implemented in derived classes, returns the current value of this field
48
+ */
49
+ public get(): TDefinition['TValue'] {
50
+ return this.value;
51
+ }
52
+
53
+ /**
54
+ * When implemented in derived classes, update the current value of this field
55
+ */
56
+ public set(value: TDefinition['TValue']): void {
57
+ this.value = value;
58
+ }
59
+
60
+ /**
61
+ * When implemented in derived classes, serializes this field into `dataView` at `offset`
62
+ */
63
+ public abstract serialize(
64
+ dataView: DataView,
65
+ offset: number,
66
+ ): void;
67
+ }
@@ -1,4 +1,4 @@
1
- export * from './context';
2
- export * from './definition';
3
- export * from './field-value';
4
- export * from './struct-value';
1
+ export * from './context';
2
+ export * from './definition';
3
+ export * from './field-value';
4
+ export * from './struct-value';
@@ -1,45 +1,39 @@
1
- import type { StructFieldValue } from './field-value';
2
-
3
- /**
4
- * Manages the initialization process of a struct value
5
- */
6
- export class StructValue {
7
- /** @internal */ readonly fieldValues: Record<PropertyKey, StructFieldValue> = {};
8
-
9
- /**
10
- * Gets the result struct value object
11
- */
12
- public readonly value: Record<PropertyKey, unknown> = {};
13
-
14
- /**
15
- * Sets a `StructFieldValue` for `key`
16
- *
17
- * @param key The field name
18
- * @param value The associated `StructFieldValue`
19
- */
20
- public set(key: PropertyKey, value: StructFieldValue): void {
21
- // TODO: TypeScript 4.2 will allow this behavior
22
- // https://github.com/microsoft/TypeScript/pull/26797
23
- // @ts-expect-error Type 'symbol' cannot be used as an index type. ts(2538)
24
- this.fieldValues[key] = value;
25
-
26
- Object.defineProperty(this.value, key, {
27
- configurable: true,
28
- enumerable: true,
29
- get() { return value.get(); },
30
- set(v) { value.set(v); },
31
- });
32
- }
33
-
34
- /**
35
- * Gets a previously `StructFieldValue` for `key`
36
- *
37
- * @param key The field name
38
- */
39
- public get(key: PropertyKey): StructFieldValue {
40
- // TODO: TypeScript 4.2 will allow this behavior
41
- // https://github.com/microsoft/TypeScript/pull/26797
42
- // @ts-expect-error Type 'symbol' cannot be used as an index type. ts(2538)
43
- return this.fieldValues[key];
44
- }
45
- }
1
+ import type { StructFieldValue } from './field-value';
2
+
3
+ /**
4
+ * Manages the initialization process of a struct value
5
+ */
6
+ export class StructValue {
7
+ /** @internal */ readonly fieldValues: Record<PropertyKey, StructFieldValue> = {};
8
+
9
+ /**
10
+ * Gets the result struct value object
11
+ */
12
+ public readonly value: Record<PropertyKey, unknown> = {};
13
+
14
+ /**
15
+ * Sets a `StructFieldValue` for `key`
16
+ *
17
+ * @param key The field name
18
+ * @param value The associated `StructFieldValue`
19
+ */
20
+ public set(key: PropertyKey, value: StructFieldValue): void {
21
+ this.fieldValues[key] = value;
22
+
23
+ Object.defineProperty(this.value, key, {
24
+ configurable: true,
25
+ enumerable: true,
26
+ get() { return value.get(); },
27
+ set(v) { value.set(v); },
28
+ });
29
+ }
30
+
31
+ /**
32
+ * Gets a previously `StructFieldValue` for `key`
33
+ *
34
+ * @param key The field name
35
+ */
36
+ public get(key: PropertyKey): StructFieldValue {
37
+ return this.fieldValues[key];
38
+ }
39
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './basic';
2
- export * from './struct';
3
- export { Struct as default } from './struct';
4
- export * from './types';
5
- export * from './utils';
1
+ export * from './basic';
2
+ export * from './struct';
3
+ export { Struct as default } from './struct';
4
+ export * from './types';
5
+ export * from './utils';