strictjs-runtime 2.0.7 → 2.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.
- package/index.js +205 -39
- package/package.json +1 -1
- package/pkg/README.md +0 -20
- package/pkg/package.json +0 -24
- package/pkg/strictjs_runtime.d.ts +0 -498
- package/pkg/strictjs_runtime.js +0 -2761
- package/pkg/strictjs_runtime_bg.wasm +0 -0
- package/pkg/strictjs_runtime_bg.wasm.d.ts +0 -207
package/index.js
CHANGED
|
@@ -1,37 +1,59 @@
|
|
|
1
1
|
import initWASM, {
|
|
2
|
-
StrictNumber,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Schema
|
|
2
|
+
StrictNumber, StrictString, get_memory, HeapType, StrictArray, StrictForLoop, StrictFunction, StrictObject, Schema,
|
|
3
|
+
// Additional exports from your wasm file
|
|
4
|
+
StrictBoolean, StrictBigInt, StrictPromise, StrictTimeout, StrictWhileLoop, StrictAsync,
|
|
5
|
+
ThreadManager, ThreadPool, ThreadTask, GPUMemoryManager, JsGPUType, JsSIMDType, JsHeapType,
|
|
6
|
+
JsTypeCapabilities, OptimizationMode, StringEncoding, TaskPriority, ThreadPriority, ThreadState,
|
|
7
|
+
getIterator, createTensor, createVector, createMatrix, createZeros, createOnes, createRange,
|
|
8
|
+
strict_fetch, init_thread_manager, create_simd_f32x4, create_simd_i32x4, create_simd_u8x16,
|
|
9
|
+
createGPUType, getAvailableGPUTypes, createSIMDType, getAvailableSIMDTypes, getSIMDTypeForUseCase
|
|
11
10
|
} from "./pkg/strictjs_runtime.js";
|
|
12
11
|
|
|
13
12
|
let nodeInitWASM = null;
|
|
13
|
+
let isInitialized = false;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* This function dynamically loads WASM in Node.js
|
|
17
17
|
*/
|
|
18
18
|
async function setupNodeLoader() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
try {
|
|
20
|
+
const fs = await import("fs");
|
|
21
|
+
const path = await import("path");
|
|
22
|
+
const { fileURLToPath } = await import("url");
|
|
23
|
+
|
|
24
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
const __dirname = path.dirname(__filename);
|
|
26
|
+
|
|
27
|
+
return async () => {
|
|
28
|
+
try {
|
|
29
|
+
const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
|
|
30
|
+
|
|
31
|
+
// Check if file exists before reading
|
|
32
|
+
if (!fs.existsSync(wasmPath)) {
|
|
33
|
+
// Try alternative path
|
|
34
|
+
const altWasmPath = path.resolve(__dirname, "strictjs_runtime_bg.wasm");
|
|
35
|
+
if (!fs.existsSync(altWasmPath)) {
|
|
36
|
+
throw new Error(`WASM file not found at ${wasmPath} or ${altWasmPath}`);
|
|
37
|
+
}
|
|
38
|
+
const wasmBuffer = fs.readFileSync(altWasmPath);
|
|
39
|
+
await initWASM(wasmBuffer);
|
|
40
|
+
} else {
|
|
41
|
+
const wasmBuffer = fs.readFileSync(wasmPath);
|
|
42
|
+
await initWASM(wasmBuffer);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
isInitialized = true;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error(`Failed to load WASM in Node.js: ${error.message}`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw new Error(`Failed to setup Node.js loader: ${error.message}`);
|
|
52
|
+
}
|
|
31
53
|
}
|
|
32
54
|
|
|
33
55
|
// Lazy initialize Node loader if in Node.js environment
|
|
34
|
-
if (typeof window === "undefined") {
|
|
56
|
+
if (typeof window === "undefined" && typeof process !== "undefined" && process.versions != null && process.versions.node != null) {
|
|
35
57
|
nodeInitWASM = await setupNodeLoader();
|
|
36
58
|
}
|
|
37
59
|
|
|
@@ -39,34 +61,178 @@ if (typeof window === "undefined") {
|
|
|
39
61
|
* Initializes StrictJS Runtime
|
|
40
62
|
* - Node: Loads WASM from filesystem
|
|
41
63
|
* - Browser: WASM auto-fetch
|
|
64
|
+
*
|
|
65
|
+
* @param {Object} options - Initialization options
|
|
66
|
+
* @param {string} [options.wasmPath] - Custom path to WASM file (browser only)
|
|
67
|
+
* @param {boolean} [options.sync=false] - Use synchronous initialization (Node.js only)
|
|
68
|
+
* @returns {Promise<Object>} Runtime exports
|
|
69
|
+
* @throws {Error} If initialization fails
|
|
42
70
|
*/
|
|
43
|
-
export default async function strictInit() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
71
|
+
export default async function strictInit(options = {}) {
|
|
72
|
+
// Prevent multiple initializations
|
|
73
|
+
if (isInitialized) {
|
|
74
|
+
return getExports();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
if (typeof window === "undefined") {
|
|
79
|
+
// Node.js environment
|
|
80
|
+
if (!nodeInitWASM) {
|
|
81
|
+
throw new Error("Node.js loader not initialized");
|
|
82
|
+
}
|
|
83
|
+
await nodeInitWASM();
|
|
84
|
+
} else {
|
|
85
|
+
// Browser environment
|
|
86
|
+
if (options.wasmPath) {
|
|
87
|
+
// Custom WASM path
|
|
88
|
+
const response = await fetch(options.wasmPath);
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
throw new Error(`Failed to fetch WASM: ${response.statusText}`);
|
|
91
|
+
}
|
|
92
|
+
const buffer = await response.arrayBuffer();
|
|
93
|
+
await initWASM(buffer);
|
|
94
|
+
} else {
|
|
95
|
+
// Default - let the wasm bindings fetch it
|
|
96
|
+
await initWASM();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
isInitialized = true;
|
|
101
|
+
return getExports();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
throw new Error(`StrictJS initialization failed: ${error.message}`);
|
|
48
104
|
}
|
|
105
|
+
}
|
|
49
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Get runtime exports
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
function getExports() {
|
|
50
112
|
return {
|
|
113
|
+
// Core types
|
|
51
114
|
StrictNumber,
|
|
52
115
|
StrictString,
|
|
53
|
-
get_memory,
|
|
54
|
-
HeapType,
|
|
55
116
|
StrictArray,
|
|
56
|
-
|
|
57
|
-
|
|
117
|
+
StrictBoolean,
|
|
118
|
+
StrictBigInt,
|
|
58
119
|
StrictObject,
|
|
59
|
-
|
|
120
|
+
StrictFunction,
|
|
121
|
+
StrictPromise,
|
|
122
|
+
|
|
123
|
+
// Loops and async
|
|
124
|
+
StrictForLoop,
|
|
125
|
+
StrictWhileLoop,
|
|
126
|
+
StrictTimeout,
|
|
127
|
+
StrictAsync,
|
|
128
|
+
|
|
129
|
+
// Threading
|
|
130
|
+
ThreadManager,
|
|
131
|
+
ThreadPool,
|
|
132
|
+
ThreadTask,
|
|
133
|
+
|
|
134
|
+
// GPU and SIMD
|
|
135
|
+
GPUMemoryManager,
|
|
136
|
+
JsGPUType,
|
|
137
|
+
JsSIMDType,
|
|
138
|
+
JsHeapType,
|
|
139
|
+
JsTypeCapabilities,
|
|
140
|
+
|
|
141
|
+
// Schema
|
|
142
|
+
Schema,
|
|
143
|
+
|
|
144
|
+
// Memory
|
|
145
|
+
get_memory,
|
|
146
|
+
|
|
147
|
+
// Enums
|
|
148
|
+
HeapType,
|
|
149
|
+
OptimizationMode,
|
|
150
|
+
StringEncoding,
|
|
151
|
+
TaskPriority,
|
|
152
|
+
ThreadPriority,
|
|
153
|
+
ThreadState,
|
|
154
|
+
|
|
155
|
+
// Factory functions
|
|
156
|
+
getIterator,
|
|
157
|
+
createTensor,
|
|
158
|
+
createVector,
|
|
159
|
+
createMatrix,
|
|
160
|
+
createZeros,
|
|
161
|
+
createOnes,
|
|
162
|
+
createRange,
|
|
163
|
+
strict_fetch,
|
|
164
|
+
init_thread_manager,
|
|
165
|
+
create_simd_f32x4,
|
|
166
|
+
create_simd_i32x4,
|
|
167
|
+
create_simd_u8x16,
|
|
168
|
+
createGPUType,
|
|
169
|
+
getAvailableGPUTypes,
|
|
170
|
+
createSIMDType,
|
|
171
|
+
getAvailableSIMDTypes,
|
|
172
|
+
getSIMDTypeForUseCase
|
|
60
173
|
};
|
|
61
174
|
}
|
|
62
175
|
|
|
63
|
-
// Named exports
|
|
176
|
+
// Named exports for core functionality
|
|
64
177
|
export {
|
|
65
|
-
|
|
66
|
-
|
|
178
|
+
// Core types
|
|
179
|
+
StrictNumber,
|
|
180
|
+
StrictString,
|
|
67
181
|
StrictArray,
|
|
68
|
-
|
|
69
|
-
|
|
182
|
+
StrictBoolean,
|
|
183
|
+
StrictBigInt,
|
|
70
184
|
StrictObject,
|
|
71
|
-
|
|
72
|
-
|
|
185
|
+
StrictFunction,
|
|
186
|
+
StrictPromise,
|
|
187
|
+
|
|
188
|
+
// Loops and async
|
|
189
|
+
StrictForLoop,
|
|
190
|
+
StrictWhileLoop,
|
|
191
|
+
StrictTimeout,
|
|
192
|
+
StrictAsync,
|
|
193
|
+
|
|
194
|
+
// Threading
|
|
195
|
+
ThreadManager,
|
|
196
|
+
ThreadPool,
|
|
197
|
+
ThreadTask,
|
|
198
|
+
|
|
199
|
+
// GPU and SIMD
|
|
200
|
+
GPUMemoryManager,
|
|
201
|
+
JsGPUType,
|
|
202
|
+
JsSIMDType,
|
|
203
|
+
JsHeapType,
|
|
204
|
+
JsTypeCapabilities,
|
|
205
|
+
|
|
206
|
+
// Schema
|
|
207
|
+
Schema,
|
|
208
|
+
|
|
209
|
+
// Memory
|
|
210
|
+
get_memory,
|
|
211
|
+
|
|
212
|
+
// Enums
|
|
213
|
+
HeapType,
|
|
214
|
+
OptimizationMode,
|
|
215
|
+
StringEncoding,
|
|
216
|
+
TaskPriority,
|
|
217
|
+
ThreadPriority,
|
|
218
|
+
ThreadState,
|
|
219
|
+
|
|
220
|
+
// Factory functions
|
|
221
|
+
getIterator,
|
|
222
|
+
createTensor,
|
|
223
|
+
createVector,
|
|
224
|
+
createMatrix,
|
|
225
|
+
createZeros,
|
|
226
|
+
createOnes,
|
|
227
|
+
createRange,
|
|
228
|
+
strict_fetch,
|
|
229
|
+
init_thread_manager,
|
|
230
|
+
create_simd_f32x4,
|
|
231
|
+
create_simd_i32x4,
|
|
232
|
+
create_simd_u8x16,
|
|
233
|
+
createGPUType,
|
|
234
|
+
getAvailableGPUTypes,
|
|
235
|
+
createSIMDType,
|
|
236
|
+
getAvailableSIMDTypes,
|
|
237
|
+
getSIMDTypeForUseCase
|
|
238
|
+
};
|
package/package.json
CHANGED
package/pkg/README.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# StrictJS Runtime
|
|
3
|
-
|
|
4
|
-
Type-safe JavaScript runtime with WebAssembly - Bringing Rust's safety guarantees to JavaScript.
|
|
5
|
-
|
|
6
|
-
## Features
|
|
7
|
-
|
|
8
|
-
- 🔒 **Type-safe numbers** with automatic clamping
|
|
9
|
-
- 📏 **Bounded strings** with character limits
|
|
10
|
-
- 🧮 **Safe arrays** with bounds checking
|
|
11
|
-
- 🏗️ **Schema-based objects** with type guarantees
|
|
12
|
-
- ⚡ **WebAssembly performance** with JavaScript convenience
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
### CDN (Browser)
|
|
17
|
-
```html
|
|
18
|
-
<script type="module">
|
|
19
|
-
import { StrictNumber, HeapType, StrictString, StrictArray, StrictObject } from 'https://cdn.jsdelivr.net/npm/strictjs-runtime@latest/pkg/strictjs_runtime.js';
|
|
20
|
-
</script>
|
package/pkg/package.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "strictjs-runtime",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"collaborators": [
|
|
5
|
-
"Your Name kennethmburu21@gmail.com"
|
|
6
|
-
],
|
|
7
|
-
"description": "Type-safe JavaScript runtime with WebAssembly - Bringing Rust's safety guarantees to JavaScript",
|
|
8
|
-
"version": "0.1.0",
|
|
9
|
-
"license": "MIT",
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "https://github.com/yourusername/strictjs-runtime"
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"strictjs_runtime_bg.wasm",
|
|
16
|
-
"strictjs_runtime.js",
|
|
17
|
-
"strictjs_runtime.d.ts"
|
|
18
|
-
],
|
|
19
|
-
"main": "strictjs_runtime.js",
|
|
20
|
-
"types": "strictjs_runtime.d.ts",
|
|
21
|
-
"sideEffects": [
|
|
22
|
-
"./snippets/*"
|
|
23
|
-
]
|
|
24
|
-
}
|