@thi.ng/wasm-api 1.2.7 → 1.3.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-01-10T15:20:19Z
3
+ - **Last updated**: 2023-02-05T14:42:22Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [1.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@1.3.0) (2023-02-05)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add ManagedIndex.initCapacity() ([788dfa2](https://github.com/thi-ng/umbrella/commit/788dfa2))
17
+ - add WasmType.instanceArray(), add docs ([2adf65f](https://github.com/thi-ng/umbrella/commit/2adf65f))
18
+
12
19
  ## [1.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@1.2.0) (2022-12-01)
13
20
 
14
21
  #### 🚀 Features
package/api.d.ts CHANGED
@@ -17,9 +17,29 @@ export interface WasmTypeBase {
17
17
  readonly __bytes: Uint8Array;
18
18
  }
19
19
  export interface WasmType<T> {
20
+ /**
21
+ * Type alignment (in bytes)
22
+ */
20
23
  readonly align: number;
24
+ /**
25
+ * Type size (in bytes)
26
+ */
21
27
  readonly size: number;
22
- instance: Fn<number, T>;
28
+ /**
29
+ * Takes a start address and number of items. Returns an array of memory
30
+ * mapped type instances (see {@link WasmType.instance}).
31
+ *
32
+ * @param base
33
+ * @param num
34
+ * @returns
35
+ */
36
+ instanceArray: (base: number, num: number) => T[];
37
+ /**
38
+ * Returns a memory-mapped type instance for given start address.
39
+ *
40
+ * @param base
41
+ */
42
+ instance: (base: number) => T;
23
43
  }
24
44
  export type WasmTypeConstructor<T> = Fn<IWasmMemoryAccess, WasmType<T>>;
25
45
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/wasm-api",
3
- "version": "1.2.7",
3
+ "version": "1.3.0",
4
4
  "description": "Generic, modular, extensible API bridge and infrastructure for hybrid JS & WebAssembly projects",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,21 +35,21 @@
35
35
  "test:build-zig": "zig build-lib -O ReleaseSmall -target wasm32-freestanding -dynamic --strip --pkg-begin wasmapi zig/lib.zig --pkg-end test/custom.zig && wasm-dis -o custom.wast custom.wasm && cp custom.wasm test"
36
36
  },
37
37
  "dependencies": {
38
- "@thi.ng/api": "^8.6.3",
39
- "@thi.ng/arrays": "^2.5.1",
40
- "@thi.ng/checks": "^3.3.7",
41
- "@thi.ng/errors": "^2.2.8",
42
- "@thi.ng/hex": "^2.3.4",
43
- "@thi.ng/idgen": "^2.1.24",
44
- "@thi.ng/logger": "^1.4.7"
38
+ "@thi.ng/api": "^8.7.0",
39
+ "@thi.ng/arrays": "^2.5.2",
40
+ "@thi.ng/checks": "^3.3.8",
41
+ "@thi.ng/errors": "^2.2.9",
42
+ "@thi.ng/hex": "^2.3.5",
43
+ "@thi.ng/idgen": "^2.1.25",
44
+ "@thi.ng/logger": "^1.4.8"
45
45
  },
46
46
  "devDependencies": {
47
- "@microsoft/api-extractor": "^7.33.7",
48
- "@thi.ng/testament": "^0.3.9",
49
- "rimraf": "^3.0.2",
47
+ "@microsoft/api-extractor": "^7.34.2",
48
+ "@thi.ng/testament": "^0.3.10",
49
+ "rimraf": "^4.1.2",
50
50
  "tools": "^0.0.1",
51
- "typedoc": "^0.23.22",
52
- "typescript": "^4.9.4"
51
+ "typedoc": "^0.23.24",
52
+ "typescript": "^4.9.5"
53
53
  },
54
54
  "keywords": [
55
55
  "allocator",
@@ -115,5 +115,5 @@
115
115
  "status": "alpha",
116
116
  "year": 2022
117
117
  },
118
- "gitHead": "3f0b3e2a7c82aefc7e46fb4338369836b5e1b8cf\n"
118
+ "gitHead": "50ba9c87676fac60c46d2bc0e4d2c7711a374a68\n"
119
119
  }
@@ -42,6 +42,13 @@ pub fn ManagedIndex(comptime T: type, comptime I: type) type {
42
42
  };
43
43
  }
44
44
 
45
+ /// Initializes the underlying array list with given initial capacity
46
+ pub fn initCapacity(allocator: Allocator, num: usize) !Self {
47
+ return .{
48
+ .list = try std.ArrayList(Item).initCapacity(allocator, num),
49
+ };
50
+ }
51
+
45
52
  /// De-initializes the underlying array list
46
53
  pub fn deinit(self: *Self) void {
47
54
  self.list.deinit();
@@ -89,7 +96,7 @@ pub fn ManagedIndex(comptime T: type, comptime I: type) type {
89
96
  }
90
97
 
91
98
  /// Returns true if given `id` is valid, i.e. is referring to a
92
- /// currently used item (and isn't part of the list of free slots).
99
+ /// currently used item and isn't part of the list of free slots.
93
100
  pub fn has(self: *const Self, id: I) bool {
94
101
  if (id >= self.list.items.len) return false;
95
102
  var freeID = self.freeID;
@@ -112,7 +119,7 @@ pub fn ManagedIndex(comptime T: type, comptime I: type) type {
112
119
  return .{ .parent = parent };
113
120
  }
114
121
 
115
- pub fn next(self: *@This()) ?T {
122
+ pub inline fn next(self: *@This()) ?T {
116
123
  const items = self.parent.list.items;
117
124
  if (self.i >= items.len) return null;
118
125
  while (self.i < items.len) {
@@ -155,8 +162,8 @@ pub fn ManagedIndex(comptime T: type, comptime I: type) type {
155
162
  while (i < slice.len) {
156
163
  if (freeID) |fid| {
157
164
  slice[i] = fid;
158
- i += 1;
159
165
  freeID = self.list.items[fid].id;
166
+ i += 1;
160
167
  } else {
161
168
  break;
162
169
  }