@rotu/structview 0.11.1 → 0.13.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/README.md CHANGED
@@ -11,8 +11,8 @@ data in a typesafe, declarative, object-oriented way.
11
11
  4. Clean object format. No risk of your struct field names colliding with
12
12
  implementation details. Type inference won't show excessive properties.
13
13
 
14
- ![JSR Version](https://img.shields.io/jsr/v/@rotu/structview)
15
- ![NPM Version](https://img.shields.io/npm/v/@rotu/structview)
14
+ [![JSR Version](https://img.shields.io/jsr/v/@rotu/structview)](https://jsr.io/@rotu/structview)
15
+ [![NPM Version](https://img.shields.io/npm/v/@rotu/structview)](https://www.npmjs.com/package/@rotu/structview)
16
16
 
17
17
  # example
18
18
 
@@ -75,7 +75,7 @@ class Menu extends defineArray({
75
75
  length: 3,
76
76
  }) {}
77
77
 
78
- const myMenu = new Menu({ byteLength: 48 })
78
+ const myMenu = Menu.alloc({ byteLength: 48 })
79
79
  Object.assign(myMenu.item(0), { name: "garden salad", price: 4 })
80
80
  Object.assign(myMenu.item(1), { name: "soup du jour", price: 2.5 })
81
81
  Object.assign(myMenu.item(2), { name: "fries", price: 2.25 })
package/esm/core.d.ts CHANGED
@@ -24,6 +24,19 @@ export declare function structBytes(struct: AnyStruct, start?: number, end?: num
24
24
  */
25
25
  export declare class Struct {
26
26
  [dataViewSymbol]: DataView;
27
+ /**
28
+ * Create a new instance of this Struct in a newly allocated buffer
29
+ * @param args options for allocation. Note that if the class does not have a static BYTE_LENGTH property, you *must* provide a byteLength here.
30
+ * @returns
31
+ */
32
+ static alloc<T extends Struct>(this: {
33
+ new ({ buffer }: {
34
+ readonly buffer: ArrayBufferLike;
35
+ }): T;
36
+ }, args?: {
37
+ byteLength?: number;
38
+ maxByteLength?: number;
39
+ }): T;
27
40
  get [Symbol.toStringTag](): string;
28
41
  static toDataView(o: Struct): DataView;
29
42
  static [Symbol.hasInstance](instance: unknown): boolean;
@@ -35,7 +48,8 @@ export declare class Struct {
35
48
  * @remarks
36
49
  * The reason we don't use a positional argument for `byteLength` is because it's confusing - TypedArray constructors take a `length` argument that is in elements, not bytes.
37
50
  * Another reason is because this allows you to pass in a `DataView` or a `TypedArray` directly to reinterpret its memory as a struct.
38
- */
51
+ *
52
+ * Instead of passing an undefined `buffer` property, consider using the `.alloc` static method. */
39
53
  constructor(arg: {
40
54
  readonly buffer: ArrayBufferLike;
41
55
  readonly byteOffset?: number;
package/esm/core.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,SAAS,EAET,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,cAAc,eAAgC,CAAA;AAE3D;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAM1D;AACD;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,EACjB,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,MAAM,GACX,UAAU,CAOZ;AAED;;;GAGG;AACH,qBAAa,MAAM;IACjB,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAA;IAE1B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAED,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ;IAItC,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO;IAQvD;;;;;;;;OAQG;gBAED,GAAG,EACC;QACA,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;QAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;QAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAC7B,GACC;QACA,QAAQ,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C,IAAI,CAAC,CAAA;IACxC,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,oIAAoI;IACpI,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB,GACA,iBAAiB,CAClB;IACE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB,GAAG,QAAQ,CAAC,IAAI,CAAC,CACnB,CAqDA"}
package/esm/core.js CHANGED
@@ -41,6 +41,21 @@ export function structBytes(struct, start, end) {
41
41
  * Note there are no predeclared string-keyed properties - all property names are reserved for user-defined fields
42
42
  */
43
43
  export class Struct {
44
+ /**
45
+ * Create a new instance of this Struct in a newly allocated buffer
46
+ * @param args options for allocation. Note that if the class does not have a static BYTE_LENGTH property, you *must* provide a byteLength here.
47
+ * @returns
48
+ */
49
+ static alloc(args) {
50
+ const byteLength = args?.byteLength ?? Reflect.get(this, "BYTE_LENGTH");
51
+ const maxByteLength = args?.maxByteLength ??
52
+ Reflect.get(this, "MAX_BYTE_LENGTH");
53
+ if (typeof byteLength !== "number") {
54
+ throw new TypeError("Cannot allocate struct - its class must have a static BYTE_LENGTH property");
55
+ }
56
+ const buffer = new ArrayBuffer(byteLength, { maxByteLength });
57
+ return new this({ buffer });
58
+ }
44
59
  get [(_a = dataViewSymbol, Symbol.toStringTag)]() {
45
60
  return Struct.name;
46
61
  }
@@ -60,7 +75,8 @@ export class Struct {
60
75
  * @remarks
61
76
  * The reason we don't use a positional argument for `byteLength` is because it's confusing - TypedArray constructors take a `length` argument that is in elements, not bytes.
62
77
  * Another reason is because this allows you to pass in a `DataView` or a `TypedArray` directly to reinterpret its memory as a struct.
63
- */
78
+ *
79
+ * Instead of passing an undefined `buffer` property, consider using the `.alloc` static method. */
64
80
  constructor(arg) {
65
81
  Object.defineProperty(this, _a, {
66
82
  enumerable: true,
package/esm/fields.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Factories for property descriptors representing fields in a binary struct
3
3
  * @module
4
4
  */
5
- import type { StructConstructor, StructPropertyDescriptor, TypedArraySpecies } from "./types.js";
5
+ import type { ReadOnlyAccessorDescriptor, StructConstructor, StructPropertyDescriptor, TypedArraySpecies } from "./types.js";
6
6
  /**
7
7
  * Field for a 8-bit unsigned integer
8
8
  */
@@ -73,7 +73,7 @@ export declare function bool(fieldOffset: number): StructPropertyDescriptor<bool
73
73
  * @param fieldGetter function which, given a dataview, returns
74
74
  * @returns
75
75
  */
76
- export declare function fromDataView<T>(fieldGetter: (dv: DataView) => T): StructPropertyDescriptor<T>;
76
+ export declare function fromDataView<T>(fieldGetter: (dv: DataView) => T): StructPropertyDescriptor<T> & ReadOnlyAccessorDescriptor<T>;
77
77
  /**
78
78
  * Field for an embedded struct
79
79
  * @param ctor constructor for the inner struct
@@ -81,7 +81,7 @@ export declare function fromDataView<T>(fieldGetter: (dv: DataView) => T): Struc
81
81
  * @param bytelength the length in bytes of the inner struct
82
82
  * @returns property descriptor for a struct
83
83
  */
84
- export declare function substruct<T extends object>(ctor: StructConstructor<T>, byteOffset?: number, bytelength?: number): StructPropertyDescriptor<T>;
84
+ export declare function substruct<T extends object>(ctor: StructConstructor<T>, byteOffset?: number, bytelength?: number): StructPropertyDescriptor<T> & ReadOnlyAccessorDescriptor<T>;
85
85
  /**
86
86
  * Field for a typed array
87
87
  *
@@ -98,7 +98,7 @@ export declare function typedArray<T>(fieldOffset: number, kwargs: {
98
98
  readonly length: number | string | undefined;
99
99
  /** TypedArray constructor */
100
100
  readonly species: TypedArraySpecies<T>;
101
- }): StructPropertyDescriptor<T>;
101
+ }): StructPropertyDescriptor<T> & ReadOnlyAccessorDescriptor<T>;
102
102
  /**
103
103
  * Field for a big-endian 16-bit unsigned integer
104
104
  */
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK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W,EAAE,MAAM,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAS3E;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAe3E;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAS3E;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAS3E"}
package/esm/types.d.ts CHANGED
@@ -25,15 +25,21 @@ export type TPropertyDescriptor<T> = {
25
25
  writable?: boolean;
26
26
  };
27
27
  /**
28
- * Object type that would result from Object.defineProperties(p:Props)
28
+ * Object type that would result from Object.defineProperties({}, p:Props)
29
29
  */
30
30
  export type MixinFromProps<Props extends object> = {
31
- -readonly [K in keyof Props]: Props[K] extends TPropertyDescriptor<infer V> ? V : unknown;
31
+ +readonly [K in keyof Props as (Props[K] extends ReadOnlyAccessorDescriptor<unknown> ? K : never)]: Props[K] extends TPropertyDescriptor<infer V> ? V : unknown;
32
+ } & {
33
+ -readonly [K in keyof Props as (Props[K] extends ReadOnlyAccessorDescriptor<unknown> ? never : K)]: Props[K] extends TPropertyDescriptor<infer V> ? V : unknown;
32
34
  };
33
35
  /**
34
36
  * Type of a property descriptor for a struct
35
37
  */
36
38
  export type StructPropertyDescriptor<T> = ThisType<AnyStruct> & TPropertyDescriptor<T>;
39
+ export type ReadOnlyAccessorDescriptor<T> = {
40
+ get(): T;
41
+ set?: undefined;
42
+ };
37
43
  export type StructConstructor<T extends object> = {
38
44
  new (arg: {
39
45
  readonly buffer: ArrayBufferLike;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE/C,MAAM,MAAM,SAAS,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MAAM,EAAE,eAAe,EACvB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,CAAC,CAAA;IACJ,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAA;CACnC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rotu/structview",
3
- "version": "0.11.1+dnt",
3
+ "version": "0.13.0+dnt",
4
4
  "description": "Read and write structured binary data with typesafe views",
5
5
  "repository": {
6
6
  "type": "git",