devtape-dtp-wasm 0.0.0-stage → 0.4.5

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
@@ -1,3 +1,22 @@
1
- # Temporary Holding Version
1
+ # devtape-dtp-wasm
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Decode DTP v0.1 tapes with incremental ANSI replay sanitization. Initialize once before decoding. Archives must still be treated as untrusted input.
4
+
5
+ Node.js ESM:
6
+
7
+ ```js
8
+ import { readFile } from 'node:fs/promises';
9
+ import { initDtpWasm, decodeTape } from 'devtape-dtp-wasm';
10
+ await initDtpWasm();
11
+ const archive = decodeTape(await readFile('session.tape'));
12
+ ```
13
+
14
+ Browser (using an ESM-aware bundler or import map):
15
+
16
+ ```js
17
+ import { initDtpWasm, decodeTape } from 'devtape-dtp-wasm';
18
+ await initDtpWasm();
19
+ const archive = decodeTape(new Uint8Array(await file.arrayBuffer()));
20
+ ```
21
+
22
+ Pass a URL, bytes, or compiled module to `initDtpWasm` to customize loading. The JSON-string decoder is also exported as `decode_and_sanitize_tape_json` and `decodeAndSanitizeTapeJson`.
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export type DtpWasmInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
2
+ export function initDtpWasm(input?: DtpWasmInput | Promise<DtpWasmInput>): Promise<WebAssembly.Exports>;
3
+ export function decode_and_sanitize_tape_json(bytes: Uint8Array): string;
4
+ export const decodeAndSanitizeTapeJson: typeof decode_and_sanitize_tape_json;
5
+ export function decodeTape(bytes: Uint8Array): { manifest: { session_id: string; [key: string]: unknown }; [key: string]: unknown };
package/index.mjs ADDED
@@ -0,0 +1,13 @@
1
+ import init, { decode_and_sanitize_tape_json as decode } from './pkg/dtp_wasm.js';
2
+
3
+ export async function initDtpWasm(input) {
4
+ if (input === undefined && typeof process !== 'undefined' && process.versions?.node) {
5
+ const { readFile } = await import('node:fs/promises');
6
+ const { fileURLToPath } = await import('node:url');
7
+ input = await readFile(fileURLToPath(new URL('./pkg/dtp_wasm_bg.wasm', import.meta.url)));
8
+ }
9
+ return input === undefined ? init() : init({ module_or_path: input });
10
+ }
11
+ export const decode_and_sanitize_tape_json = decode;
12
+ export const decodeAndSanitizeTapeJson = decode;
13
+ export function decodeTape(bytes) { return JSON.parse(decode(bytes)); }
package/package.json CHANGED
@@ -1,6 +1,14 @@
1
1
  {
2
- "name": "devtape-dtp-wasm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "devtape-dtp-wasm", "version": "0.4.5",
3
+ "description": "WebAssembly DTP v0.1 .tape decoder and incremental ANSI replay sanitizer",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/sayyidsh/devtape.git",
7
+ "directory": "packages/dtp-wasm"
8
+ },
9
+ "license": "Apache-2.0", "type": "module", "main": "./index.mjs", "types": "./index.d.ts",
10
+ "exports": { ".": { "types": "./index.d.ts", "default": "./index.mjs" } },
11
+ "publishConfig": { "access": "public" },
12
+ "files": ["index.mjs", "index.d.ts", "pkg/dtp_wasm.js", "pkg/dtp_wasm_bg.wasm", "pkg/dtp_wasm.d.ts", "pkg/dtp_wasm_bg.wasm.d.ts", "README.md"],
13
+ "scripts": { "build": "bash ./build.sh", "test": "node ./test.mjs" }
14
+ }
@@ -0,0 +1,51 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Browser entry point. The macro's generated ABI glue compiles under the crate's
6
+ * `forbid(unsafe_code)` policy; all validation uses the same codec as the CLI.
7
+ */
8
+ export function decode_and_sanitize_tape_json(bytes: Uint8Array | number[]): string;
9
+
10
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
11
+
12
+ export interface InitOutput {
13
+ readonly memory: WebAssembly.Memory;
14
+ readonly decode_and_sanitize_tape_json: (a: number, b: number, c: number) => void;
15
+ readonly rust_zstd_wasm_shim_calloc: (a: number, b: number) => number;
16
+ readonly rust_zstd_wasm_shim_free: (a: number) => void;
17
+ readonly rust_zstd_wasm_shim_malloc: (a: number) => number;
18
+ readonly rust_zstd_wasm_shim_memcmp: (a: number, b: number, c: number) => number;
19
+ readonly rust_zstd_wasm_shim_memcpy: (a: number, b: number, c: number) => number;
20
+ readonly rust_zstd_wasm_shim_memmove: (a: number, b: number, c: number) => number;
21
+ readonly rust_zstd_wasm_shim_memset: (a: number, b: number, c: number) => number;
22
+ readonly rust_zstd_wasm_shim_qsort: (a: number, b: number, c: number, d: number) => void;
23
+ readonly __wbindgen_externrefs: WebAssembly.Table;
24
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
25
+ readonly __wbindgen_export: (a: number, b: number) => number;
26
+ readonly __wbindgen_export2: (a: number, b: number, c: number) => void;
27
+ readonly __wbindgen_export3: (a: number) => void;
28
+ readonly __wbindgen_start: () => void;
29
+ }
30
+
31
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
32
+
33
+ /**
34
+ * Instantiates the given `module`, which can either be bytes or
35
+ * a precompiled `WebAssembly.Module`.
36
+ *
37
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
38
+ *
39
+ * @returns {InitOutput}
40
+ */
41
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
42
+
43
+ /**
44
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
45
+ * for everything else, calls `WebAssembly.instantiate` directly.
46
+ *
47
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
48
+ *
49
+ * @returns {Promise<InitOutput>}
50
+ */
51
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,212 @@
1
+ /* @ts-self-types="./dtp_wasm.d.ts" */
2
+
3
+ /**
4
+ * Browser entry point. The macro's generated ABI glue compiles under the crate's
5
+ * `forbid(unsafe_code)` policy; all validation uses the same codec as the CLI.
6
+ * @param {Uint8Array | number[]} bytes
7
+ * @returns {string}
8
+ */
9
+ export function decode_and_sanitize_tape_json(bytes) {
10
+ let deferred3_0;
11
+ let deferred3_1;
12
+ try {
13
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
14
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
15
+ const len0 = WASM_VECTOR_LEN;
16
+ wasm.decode_and_sanitize_tape_json(retptr, ptr0, len0);
17
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
18
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
19
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
20
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
21
+ var ptr2 = r0;
22
+ var len2 = r1;
23
+ if (r3) {
24
+ ptr2 = 0; len2 = 0;
25
+ throw takeFromExternrefTable0(r2);
26
+ }
27
+ deferred3_0 = ptr2;
28
+ deferred3_1 = len2;
29
+ return getStringFromWasm0(ptr2, len2);
30
+ } finally {
31
+ wasm.__wbindgen_add_to_stack_pointer(16);
32
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
33
+ }
34
+ }
35
+ function __wbg_get_imports() {
36
+ const import0 = {
37
+ __proto__: null,
38
+ __wbindgen_generic_0000000000000001: function(arg0, arg1) {
39
+ // Cast intrinsic for `Ref(String) -> Externref`.
40
+ const ret = getStringFromWasm0(arg0, arg1);
41
+ return ret;
42
+ },
43
+ __wbindgen_init_externref_table: function() {
44
+ const table = wasm.__wbindgen_externrefs;
45
+ table.set(0, undefined);
46
+ table.set(1024, undefined);
47
+ table.set(1025, null);
48
+ table.set(1026, true);
49
+ table.set(1027, false);
50
+ },
51
+ };
52
+ return {
53
+ __proto__: null,
54
+ "./dtp_wasm_bg.js": import0,
55
+ };
56
+ }
57
+
58
+ let cachedDataViewMemory0 = null;
59
+ function getDataViewMemory0() {
60
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
61
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
62
+ }
63
+ return cachedDataViewMemory0;
64
+ }
65
+
66
+ function getStringFromWasm0(ptr, len) {
67
+ ptr = ptr >>> 0;
68
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
69
+ }
70
+
71
+ let cachedUint8ArrayMemory0 = null;
72
+ function getUint8ArrayMemory0() {
73
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
74
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
75
+ }
76
+ return cachedUint8ArrayMemory0;
77
+ }
78
+
79
+ function passArray8ToWasm0(arg, malloc) {
80
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
81
+ getUint8ArrayMemory0().set(arg, ptr / 1);
82
+ WASM_VECTOR_LEN = arg.length;
83
+ return ptr;
84
+ }
85
+
86
+ function takeFromExternrefTable0(idx) {
87
+ const value = wasm.__wbindgen_externrefs.get(idx);
88
+ wasm.__wbindgen_export3(idx);
89
+ return value;
90
+ }
91
+
92
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
93
+ cachedTextDecoder.decode();
94
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
95
+ let numBytesDecoded = 0;
96
+ function decodeText(bytes) {
97
+ numBytesDecoded += bytes.length;
98
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
99
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
100
+ cachedTextDecoder.decode();
101
+ numBytesDecoded = bytes.length;
102
+ }
103
+ return cachedTextDecoder.decode(bytes);
104
+ }
105
+
106
+ let WASM_VECTOR_LEN = 0;
107
+
108
+ let wasmModule, wasmInstance, wasm;
109
+ function __wbg_finalize_init(instance, module) {
110
+ wasmInstance = instance;
111
+ wasm = instance.exports;
112
+ wasmModule = module;
113
+ cachedDataViewMemory0 = null;
114
+ cachedUint8ArrayMemory0 = null;
115
+ wasm.__wbindgen_start();
116
+ return wasm;
117
+ }
118
+
119
+ async function __wbg_load(module, imports) {
120
+ if (typeof Response === 'function' && module instanceof Response) {
121
+ if (!module.ok) {
122
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
123
+ }
124
+
125
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
126
+ try {
127
+ return await WebAssembly.instantiateStreaming(module, imports);
128
+ } catch (e) {
129
+ const validResponse = expectedResponseType(module.type);
130
+
131
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
132
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
133
+
134
+ } else { throw e; }
135
+ }
136
+ }
137
+
138
+ const bytes = await module.arrayBuffer();
139
+ return await WebAssembly.instantiate(bytes, imports);
140
+ } else {
141
+ const instance = await WebAssembly.instantiate(module, imports);
142
+
143
+ if (instance instanceof WebAssembly.Instance) {
144
+ return { instance, module };
145
+ } else {
146
+ return instance;
147
+ }
148
+ }
149
+
150
+ function expectedResponseType(type) {
151
+ switch (type) {
152
+ case 'basic': case 'cors': case 'default': return true;
153
+ }
154
+ return false;
155
+ }
156
+ }
157
+
158
+ function initSync(module) {
159
+ if (wasm !== undefined) return wasm;
160
+
161
+
162
+ if (module !== undefined) {
163
+ if (Object.getPrototypeOf(module) === Object.prototype) {
164
+ ({module} = module)
165
+ } else {
166
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
167
+ }
168
+ }
169
+
170
+ const imports = __wbg_get_imports();
171
+ if (!(module instanceof WebAssembly.Module)) {
172
+ module = new WebAssembly.Module(module);
173
+ }
174
+ const instance = new WebAssembly.Instance(module, imports);
175
+ return __wbg_finalize_init(instance, module);
176
+ }
177
+
178
+ let __wbg_init_promise;
179
+ async function __wbg_init(module_or_path) {
180
+ if (wasm !== undefined) return wasm;
181
+ if (__wbg_init_promise === undefined) {
182
+ __wbg_init_promise = __wbg_init_once(module_or_path);
183
+ __wbg_init_promise.catch(() => { __wbg_init_promise = undefined; });
184
+ }
185
+ return __wbg_init_promise;
186
+ }
187
+
188
+ async function __wbg_init_once(module_or_path) {
189
+
190
+ if (module_or_path !== undefined) {
191
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
192
+ ({module_or_path} = module_or_path)
193
+ } else {
194
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
195
+ }
196
+ }
197
+
198
+ if (module_or_path === undefined) {
199
+ module_or_path = new URL('dtp_wasm_bg.wasm', import.meta.url);
200
+ }
201
+ const imports = __wbg_get_imports();
202
+
203
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
204
+ module_or_path = fetch(module_or_path);
205
+ }
206
+
207
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
208
+
209
+ return __wbg_finalize_init(instance, module);
210
+ }
211
+
212
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,18 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const decode_and_sanitize_tape_json: (a: number, b: number, c: number) => void;
5
+ export const rust_zstd_wasm_shim_calloc: (a: number, b: number) => number;
6
+ export const rust_zstd_wasm_shim_free: (a: number) => void;
7
+ export const rust_zstd_wasm_shim_malloc: (a: number) => number;
8
+ export const rust_zstd_wasm_shim_memcmp: (a: number, b: number, c: number) => number;
9
+ export const rust_zstd_wasm_shim_memcpy: (a: number, b: number, c: number) => number;
10
+ export const rust_zstd_wasm_shim_memmove: (a: number, b: number, c: number) => number;
11
+ export const rust_zstd_wasm_shim_memset: (a: number, b: number, c: number) => number;
12
+ export const rust_zstd_wasm_shim_qsort: (a: number, b: number, c: number, d: number) => void;
13
+ export const __wbindgen_externrefs: WebAssembly.Table;
14
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
15
+ export const __wbindgen_export: (a: number, b: number) => number;
16
+ export const __wbindgen_export2: (a: number, b: number, c: number) => void;
17
+ export const __wbindgen_export3: (a: number) => void;
18
+ export const __wbindgen_start: () => void;