relaxnative 0.1.0-beta.1

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 (130) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +592 -0
  3. package/dist/chunk-22W76CYR.js +607 -0
  4. package/dist/chunk-24NXCU65.js +254 -0
  5. package/dist/chunk-2APMRURB.js +65 -0
  6. package/dist/chunk-2CHBHJPT.js +607 -0
  7. package/dist/chunk-2I4JHZI7.js +287 -0
  8. package/dist/chunk-2JOHYYQO.js +607 -0
  9. package/dist/chunk-3GW77EWF.js +505 -0
  10. package/dist/chunk-5J5CAKCD.js +266 -0
  11. package/dist/chunk-5NTDZ7YZ.js +377 -0
  12. package/dist/chunk-5TA6MROS.js +529 -0
  13. package/dist/chunk-5WVEBKMJ.js +1019 -0
  14. package/dist/chunk-6O5TIEEI.js +545 -0
  15. package/dist/chunk-6XU5DETO.js +896 -0
  16. package/dist/chunk-7BIZ6P3B.js +176 -0
  17. package/dist/chunk-7DKO777J.js +285 -0
  18. package/dist/chunk-7JYWUH4Y.js +268 -0
  19. package/dist/chunk-7NMCEP2V.js +756 -0
  20. package/dist/chunk-A7N4YBP2.js +379 -0
  21. package/dist/chunk-AZTCDV6R.js +572 -0
  22. package/dist/chunk-B34XEGM6.js +559 -0
  23. package/dist/chunk-BFHBLVXW.js +607 -0
  24. package/dist/chunk-BLOJ33LO.js +65 -0
  25. package/dist/chunk-BYPXCWTI.js +375 -0
  26. package/dist/chunk-C4KJD2AN.js +1044 -0
  27. package/dist/chunk-CJALJTRQ.js +814 -0
  28. package/dist/chunk-D4PK367Z.js +627 -0
  29. package/dist/chunk-DCWBZPEV.js +287 -0
  30. package/dist/chunk-DI7KSUEC.js +676 -0
  31. package/dist/chunk-DQ2KXIOO.js +665 -0
  32. package/dist/chunk-DV5STE3W.js +986 -0
  33. package/dist/chunk-EG5KNEKP.js +1027 -0
  34. package/dist/chunk-EOA2OWFA.js +1020 -0
  35. package/dist/chunk-ES3B6EZJ.js +56 -0
  36. package/dist/chunk-ETIXNPU5.js +741 -0
  37. package/dist/chunk-EUZBU2H7.js +824 -0
  38. package/dist/chunk-F6V7XDEB.js +150 -0
  39. package/dist/chunk-FNJKUFNF.js +1019 -0
  40. package/dist/chunk-FZB37DWL.js +453 -0
  41. package/dist/chunk-G3NDHZNZ.js +453 -0
  42. package/dist/chunk-G4YR34LE.js +410 -0
  43. package/dist/chunk-GU4XXISM.js +264 -0
  44. package/dist/chunk-GVPSQXGJ.js +1027 -0
  45. package/dist/chunk-HD5C4RNU.js +676 -0
  46. package/dist/chunk-HDIVY47T.js +287 -0
  47. package/dist/chunk-HFLRTDNK.js +985 -0
  48. package/dist/chunk-HGWRCVQ5.js +287 -0
  49. package/dist/chunk-HRG3SVKK.js +995 -0
  50. package/dist/chunk-HUGFULJ3.js +1027 -0
  51. package/dist/chunk-IDYSBXYS.js +344 -0
  52. package/dist/chunk-ISDDUQVI.js +1019 -0
  53. package/dist/chunk-IZ632ZCJ.js +286 -0
  54. package/dist/chunk-J5XI4L52.js +218 -0
  55. package/dist/chunk-JTIO7BUH.js +582 -0
  56. package/dist/chunk-JTWSFMF2.js +1020 -0
  57. package/dist/chunk-K5TV62T4.js +736 -0
  58. package/dist/chunk-K7MTG53V.js +985 -0
  59. package/dist/chunk-KGLZB3H2.js +676 -0
  60. package/dist/chunk-KYAB35P5.js +741 -0
  61. package/dist/chunk-KYDW3YVX.js +453 -0
  62. package/dist/chunk-L3MEMPRH.js +361 -0
  63. package/dist/chunk-LFTO3Z7N.js +757 -0
  64. package/dist/chunk-LLZ4I4OR.js +405 -0
  65. package/dist/chunk-LMRUM4U4.js +207 -0
  66. package/dist/chunk-LT5OGU6T.js +559 -0
  67. package/dist/chunk-LZQQOC3M.js +741 -0
  68. package/dist/chunk-LZYUNF6Q.js +1017 -0
  69. package/dist/chunk-MCTPVW4G.js +453 -0
  70. package/dist/chunk-MGLWXBIB.js +65 -0
  71. package/dist/chunk-MLKGABMK.js +9 -0
  72. package/dist/chunk-MTE6XDGC.js +541 -0
  73. package/dist/chunk-NDJUNDAE.js +676 -0
  74. package/dist/chunk-NG7SNFUD.js +1027 -0
  75. package/dist/chunk-ONVWKYK7.js +739 -0
  76. package/dist/chunk-OVMTFGE7.js +1042 -0
  77. package/dist/chunk-P5RQPRJ4.js +741 -0
  78. package/dist/chunk-PFABSW6Y.js +401 -0
  79. package/dist/chunk-PVVUJA2M.js +65 -0
  80. package/dist/chunk-Q3CDTGTX.js +676 -0
  81. package/dist/chunk-QKAKWDOQ.js +967 -0
  82. package/dist/chunk-QMPRDU6I.js +598 -0
  83. package/dist/chunk-R5U7XKVJ.js +16 -0
  84. package/dist/chunk-RB6RHB6C.js +254 -0
  85. package/dist/chunk-RD2K7ODW.js +175 -0
  86. package/dist/chunk-RHBHJND2.js +582 -0
  87. package/dist/chunk-RUP6POSE.js +453 -0
  88. package/dist/chunk-RYNSM23L.js +582 -0
  89. package/dist/chunk-S72S7XXS.js +255 -0
  90. package/dist/chunk-SDV5AAPW.js +213 -0
  91. package/dist/chunk-STXQPXUY.js +242 -0
  92. package/dist/chunk-TUSF5AEG.js +140 -0
  93. package/dist/chunk-V74SNTE6.js +736 -0
  94. package/dist/chunk-VHM5XETC.js +453 -0
  95. package/dist/chunk-VKQIXLNL.js +273 -0
  96. package/dist/chunk-VPG23Z7Y.js +545 -0
  97. package/dist/chunk-VSP234PR.js +627 -0
  98. package/dist/chunk-WH4JPUWF.js +598 -0
  99. package/dist/chunk-WLAUJL3K.js +409 -0
  100. package/dist/chunk-WXCN2QJ7.js +350 -0
  101. package/dist/chunk-X3JZKLJC.js +896 -0
  102. package/dist/chunk-X7SAP7FC.js +582 -0
  103. package/dist/chunk-XEH6PRYE.js +968 -0
  104. package/dist/chunk-XI65CAQV.js +211 -0
  105. package/dist/chunk-Y7OSHR6W.js +235 -0
  106. package/dist/chunk-YN4WUMVD.js +1020 -0
  107. package/dist/chunk-YUWJ2C4Y.js +1020 -0
  108. package/dist/chunk-YXLBPWNU.js +263 -0
  109. package/dist/chunk-YYJJHO7R.js +407 -0
  110. package/dist/chunk-Z2RBHUIH.js +757 -0
  111. package/dist/chunk-Z6G3KIOM.js +1027 -0
  112. package/dist/chunk-ZPPXCDSH.js +361 -0
  113. package/dist/chunk-ZRTY24SZ.js +582 -0
  114. package/dist/chunk-ZSDFBCQG.js +741 -0
  115. package/dist/cli.d.ts +1 -0
  116. package/dist/cli.js +339 -0
  117. package/dist/esmLoader.d.ts +10 -0
  118. package/dist/esmLoader.js +112 -0
  119. package/dist/index.d.ts +407 -0
  120. package/dist/index.js +126 -0
  121. package/dist/memory/memory.selftest.d.ts +2 -0
  122. package/dist/memory/memory.selftest.js +25 -0
  123. package/dist/worker/processEntry.d.ts +2 -0
  124. package/dist/worker/processEntry.js +160 -0
  125. package/dist/worker/workerEntry.d.ts +2 -0
  126. package/dist/worker/workerEntry.js +27 -0
  127. package/native/examples/add.c +6 -0
  128. package/native/examples/add_test.c +23 -0
  129. package/native/relaxnative_test.h +36 -0
  130. package/package.json +81 -0
@@ -0,0 +1,407 @@
1
+ type ExecutionMode = 'sync' | 'async';
2
+ type RelaxConfig = {
3
+ /**
4
+ * Force execution mode by function name (exact match).
5
+ * Example: { heavy: 'async', add: 'sync' }
6
+ */
7
+ functionMode?: Record<string, ExecutionMode>;
8
+ /**
9
+ * Default mode when no annotation/config provided.
10
+ * Keeping default as 'sync' for low-latency trivial calls.
11
+ */
12
+ defaultMode?: ExecutionMode;
13
+ };
14
+ type IsolationMode = 'in-process' | 'worker' | 'process';
15
+ declare function loadNative(sourcePath: string, options?: {
16
+ config?: RelaxConfig;
17
+ isolation?: IsolationMode;
18
+ }): Promise<any>;
19
+ /**
20
+ * Advanced API: returns both the wrapped module and the computed bindings.
21
+ * Useful for registry loaders to attach safety metadata.
22
+ */
23
+ declare function loadNativeWithBindings(sourcePath: string, options?: {
24
+ config?: RelaxConfig;
25
+ isolation?: IsolationMode;
26
+ mutateBindings?: (bindings: any) => void;
27
+ }): Promise<{
28
+ mod: any;
29
+ bindings: any;
30
+ }>;
31
+
32
+ type Ownership = 'js' | 'native' | 'borrowed';
33
+ declare class MemoryError extends Error {
34
+ name: string;
35
+ }
36
+ declare class UseAfterFreeError extends MemoryError {
37
+ name: string;
38
+ }
39
+ declare class InvalidFreeError extends MemoryError {
40
+ name: string;
41
+ }
42
+ declare class NullPointerError extends MemoryError {
43
+ name: string;
44
+ }
45
+
46
+ declare const kBrand$1: unique symbol;
47
+ declare class NativeBuffer {
48
+ readonly [kBrand$1] = true;
49
+ private _handle;
50
+ private _view;
51
+ private _freed;
52
+ readonly ownership: Ownership;
53
+ constructor(allocation: {
54
+ handle: any;
55
+ view: Uint8Array;
56
+ }, opts?: {
57
+ ownership?: Ownership;
58
+ autoFree?: boolean;
59
+ });
60
+ get address(): number;
61
+ get size(): number;
62
+ get freed(): boolean;
63
+ assertAlive(): void;
64
+ toUint8Array(): Uint8Array;
65
+ /**
66
+ * Create a bounds-checked DataView into this buffer.
67
+ *
68
+ * Tip: prefer the typed view helpers (u32(), f64(), etc.) when possible.
69
+ */
70
+ dataView(offset?: number, length?: number): DataView;
71
+ private _typed;
72
+ u8(offset?: number, length?: number): Uint8Array<ArrayBuffer>;
73
+ i8(offset?: number, length?: number): Int8Array<ArrayBuffer>;
74
+ u16(offset?: number, length?: number): Uint16Array<ArrayBuffer>;
75
+ i16(offset?: number, length?: number): Int16Array<ArrayBuffer>;
76
+ u32(offset?: number, length?: number): Uint32Array<ArrayBuffer>;
77
+ i32(offset?: number, length?: number): Int32Array<ArrayBuffer>;
78
+ f32(offset?: number, length?: number): Float32Array<ArrayBuffer>;
79
+ f64(offset?: number, length?: number): Float64Array<ArrayBuffer>;
80
+ write(src: Uint8Array, offset?: number): void;
81
+ free(): void;
82
+ toJSON(): {
83
+ address: number;
84
+ size: number;
85
+ ownership: Ownership;
86
+ };
87
+ static isNativeBuffer(v: any): v is NativeBuffer;
88
+ /**
89
+ * Return the koffi allocation handle.
90
+ *
91
+ * Important: passing raw numeric addresses to koffi is not reliably supported
92
+ * across platforms/Node versions and can segfault. The handle returned by
93
+ * `koffi.alloc()` is the safe thing to pass back into FFI calls.
94
+ */
95
+ toKoffiPointer(): any;
96
+ }
97
+
98
+ declare const kBrand: unique symbol;
99
+ declare class NativePointer {
100
+ readonly [kBrand] = true;
101
+ /** Opaque native address (number). */
102
+ readonly address: number;
103
+ /** Size in bytes when known (0 means unknown). */
104
+ readonly size: number;
105
+ /** Ownership of the pointee memory. */
106
+ readonly ownership: Ownership;
107
+ private _freed;
108
+ constructor(opts: {
109
+ address: number;
110
+ size?: number;
111
+ ownership?: Ownership;
112
+ });
113
+ get freed(): boolean;
114
+ /**
115
+ * Marks this pointer as freed (used internally by NativeBuffer).
116
+ * This does *not* free underlying memory.
117
+ */
118
+ _markFreed(): void;
119
+ assertAlive(): void;
120
+ /**
121
+ * Convert to the koffi pointer value.
122
+ *
123
+ * Note: numeric-address pointers are inherently less safe than passing a
124
+ * koffi External handle (like NativeBuffer does). Use NativePointer for
125
+ * borrowed/opaque pointers returned by native code.
126
+ */
127
+ toKoffiPointer(): number;
128
+ static isNativePointer(v: any): v is NativePointer;
129
+ /**
130
+ * Convenience for koffi type declarations.
131
+ * Example: lib.func('foo', 'int', [NativePointer.koffiType()])
132
+ */
133
+ static koffiType(): any;
134
+ }
135
+
136
+ /**
137
+ * Low-level process memory primitives.
138
+ *
139
+ * Notes:
140
+ * - This uses koffi's built-in allocator so we don't need a bespoke native shim.
141
+ * - Returned pointers are *opaque* JS numbers (addresses). Wrap them in
142
+ * NativePointer/NativeBuffer for safety checks + ownership tracking.
143
+ */
144
+ type NativeAddress = number;
145
+ type RawAllocation = {
146
+ handle: any;
147
+ view: Uint8Array;
148
+ };
149
+ declare function allocRaw(size: number): RawAllocation;
150
+ declare function freeRaw(ptr: unknown): void;
151
+
152
+ /**
153
+ * High-level user-facing API.
154
+ */
155
+ declare function alloc(size: number, opts?: {
156
+ autoFree?: boolean;
157
+ }): NativeBuffer;
158
+ declare function free(ptr: NativeBuffer | NativePointer): void;
159
+
160
+ type index_InvalidFreeError = InvalidFreeError;
161
+ declare const index_InvalidFreeError: typeof InvalidFreeError;
162
+ type index_MemoryError = MemoryError;
163
+ declare const index_MemoryError: typeof MemoryError;
164
+ type index_NativeAddress = NativeAddress;
165
+ type index_NativeBuffer = NativeBuffer;
166
+ declare const index_NativeBuffer: typeof NativeBuffer;
167
+ type index_NativePointer = NativePointer;
168
+ declare const index_NativePointer: typeof NativePointer;
169
+ type index_NullPointerError = NullPointerError;
170
+ declare const index_NullPointerError: typeof NullPointerError;
171
+ type index_Ownership = Ownership;
172
+ type index_RawAllocation = RawAllocation;
173
+ type index_UseAfterFreeError = UseAfterFreeError;
174
+ declare const index_UseAfterFreeError: typeof UseAfterFreeError;
175
+ declare const index_alloc: typeof alloc;
176
+ declare const index_allocRaw: typeof allocRaw;
177
+ declare const index_free: typeof free;
178
+ declare const index_freeRaw: typeof freeRaw;
179
+ declare namespace index {
180
+ export { index_InvalidFreeError as InvalidFreeError, index_MemoryError as MemoryError, type index_NativeAddress as NativeAddress, index_NativeBuffer as NativeBuffer, index_NativePointer as NativePointer, index_NullPointerError as NullPointerError, type index_Ownership as Ownership, type index_RawAllocation as RawAllocation, index_UseAfterFreeError as UseAfterFreeError, index_alloc as alloc, index_allocRaw as allocRaw, index_free as free, index_freeRaw as freeRaw };
181
+ }
182
+
183
+ declare function getProjectRoot(cwd?: string): string;
184
+ declare function getRegistryRoot(projectRoot?: string): string;
185
+ declare function getInstalledPackageDir(pkg: string, projectRoot?: string): string;
186
+ declare function resolveRegistryImport(specifier: string, projectRoot?: string): string | null;
187
+
188
+ type RelaxPermissions = {
189
+ fs?: {
190
+ read?: string[];
191
+ write?: string[];
192
+ };
193
+ network?: {
194
+ outbound?: boolean;
195
+ };
196
+ process?: {
197
+ spawn?: boolean;
198
+ };
199
+ };
200
+ type RelaxExport = {
201
+ /** source file relative to the package root */
202
+ source: string;
203
+ /** optional name for JS default export (defaults to package name) */
204
+ name?: string;
205
+ };
206
+ type RelaxJson = {
207
+ name: string;
208
+ version: string;
209
+ /** Trust level of the package (affects UX + defaults). */
210
+ trust?: 'local' | 'community' | 'verified';
211
+ /** Required for verified packages (provided by registry, validated at install). */
212
+ registrySignature?: {
213
+ alg: 'sha256';
214
+ digest: string;
215
+ };
216
+ language?: 'c' | 'cpp' | 'rust';
217
+ exports: RelaxExport[];
218
+ /** compiler flags applied during compilation */
219
+ flags?: string[];
220
+ /** security permissions requested by this package */
221
+ permissions?: RelaxPermissions;
222
+ /** runtime limits (best-effort) */
223
+ limits?: {
224
+ /** max wall clock time per call in ms (process isolation enforces by killing helper) */
225
+ timeoutMs?: number;
226
+ /** best-effort soft cap for native heap in bytes (enforced only in process isolation) */
227
+ memoryBytes?: number;
228
+ };
229
+ /** execution hints by function name */
230
+ functionMode?: Record<string, 'sync' | 'async'>;
231
+ /** Default isolation preference for this package (installer may enforce stricter). */
232
+ defaultIsolation?: 'in-process' | 'worker' | 'process';
233
+ /** Default execution mode for functions when not specified; most useful for async-only APIs. */
234
+ defaultExecutionMode?: 'sync' | 'async';
235
+ };
236
+
237
+ declare function readRelaxJson(pkgDir: string): RelaxJson;
238
+
239
+ type TrustLevel = 'local' | 'community' | 'verified';
240
+
241
+ type InstallResult = {
242
+ pkg: string;
243
+ dir: string;
244
+ warnings: string[];
245
+ trust: TrustLevel;
246
+ };
247
+ declare function installPackage(pkgSpecifier: string, projectRoot?: string): InstallResult;
248
+ type InstallOptions = {
249
+ /** If true, skip interactive prompt (still refuses community unless previously trusted). */
250
+ yes?: boolean;
251
+ };
252
+ declare function installPackageEnforcingTrust(pkgSpecifier: string, projectRoot?: string, options?: InstallOptions): Promise<InstallResult>;
253
+ declare function removePackage(pkg: string, projectRoot?: string): void;
254
+ declare function listPackages(projectRoot?: string): string[];
255
+ declare function updateIndex(projectRoot?: string): void;
256
+
257
+ declare function loadRegistry(pkg: string, projectRoot?: string): Promise<any>;
258
+
259
+ type NativeTestKind = 'int' | 'cstring';
260
+ type NativeTestCase = {
261
+ name: string;
262
+ sourcePath: string;
263
+ line?: number;
264
+ kind: NativeTestKind;
265
+ };
266
+ type NativeTestResult = {
267
+ name: string;
268
+ ok: boolean;
269
+ message?: string;
270
+ sourcePath: string;
271
+ line?: number;
272
+ durationMs: number;
273
+ };
274
+ declare function discoverNativeTestFiles(rootDir: string): string[];
275
+ declare function discoverNativeTestsFromFile(sourcePath: string): NativeTestCase[];
276
+ declare function discoverNativeTests(rootDir: string): NativeTestCase[];
277
+ declare function formatNativeTestResults(results: NativeTestResult[]): string;
278
+ declare function runNativeTests(rootDir: string, opts?: {
279
+ isolation?: 'in-process' | 'worker' | 'process';
280
+ }): Promise<{
281
+ results: NativeTestResult[];
282
+ exitCode: number;
283
+ }>;
284
+ declare function getSourceLine(sourcePath: string, line?: number): string | null;
285
+
286
+ type BenchmarkOptions = {
287
+ iterations?: number;
288
+ warmup?: number;
289
+ mode?: 'sync' | 'worker';
290
+ /**
291
+ * Arguments to pass to the benchmarked function.
292
+ * If omitted, we try a small default based on arity (0 args => [], else => [1,2]).
293
+ */
294
+ args?: any[];
295
+ json?: boolean;
296
+ confirmExpensive?: boolean;
297
+ };
298
+ type BenchmarkResult = {
299
+ fnName: string;
300
+ mode: 'sync' | 'worker';
301
+ iterations: number;
302
+ warmup: number;
303
+ callsPerSec: number;
304
+ avgLatencyMs: number;
305
+ minLatencyMs: number;
306
+ maxLatencyMs: number;
307
+ };
308
+ type TraditionalBenchmarkResult = {
309
+ name: string;
310
+ iterations: number;
311
+ warmup: number;
312
+ callsPerSec: number;
313
+ avgLatencyMs: number;
314
+ minLatencyMs: number;
315
+ maxLatencyMs: number;
316
+ };
317
+ declare function benchmarkJsFunction(name: string, fn: (...args: any[]) => any, opts?: {
318
+ iterations?: number;
319
+ warmup?: number;
320
+ args?: any[];
321
+ }): Promise<TraditionalBenchmarkResult>;
322
+ declare function benchmarkNativeFunction(nativePath: string, fnName: string, opts?: BenchmarkOptions): Promise<BenchmarkResult>;
323
+ declare function benchmarkCompareSyncVsWorker(nativePath: string, fnName: string, opts?: Omit<BenchmarkOptions, 'mode'>): Promise<{
324
+ sync: BenchmarkResult;
325
+ worker: BenchmarkResult;
326
+ }>;
327
+ declare function benchmarkCompareTraditionalVsRelaxnative(nativePath: string, fnName: string, opts?: Omit<BenchmarkOptions, 'mode'> & {
328
+ /**
329
+ * JS baseline implementation to compare against.
330
+ * If omitted, we provide a tiny baseline only for a couple of known demo functions.
331
+ */
332
+ baseline?: (...args: any[]) => any;
333
+ baselineName?: string;
334
+ }): Promise<{
335
+ traditional: TraditionalBenchmarkResult;
336
+ relaxnative: {
337
+ sync: BenchmarkResult;
338
+ worker: BenchmarkResult;
339
+ };
340
+ }>;
341
+ declare function formatBenchmarkResult(r: BenchmarkResult): string;
342
+ declare function formatBenchmarkCompare(res: {
343
+ sync: BenchmarkResult;
344
+ worker: BenchmarkResult;
345
+ }): string;
346
+ declare function formatBenchmarkTraditionalCompare(res: {
347
+ traditional: TraditionalBenchmarkResult;
348
+ relaxnative: {
349
+ sync: BenchmarkResult;
350
+ worker: BenchmarkResult;
351
+ };
352
+ }): string;
353
+
354
+ type HotReloadOptions = {
355
+ isolation?: 'in-process' | 'worker' | 'process';
356
+ onReload?: (info: {
357
+ sourcePath: string;
358
+ durationMs: number;
359
+ }) => void;
360
+ };
361
+ type HotReloadHandle = {
362
+ /** current module; stable identity, updated on reload */
363
+ mod: any;
364
+ close(): void;
365
+ };
366
+ declare function loadNativeDevHot(sourcePath: string, opts?: HotReloadOptions): Promise<HotReloadHandle>;
367
+
368
+ type PlatformInfo = {
369
+ platform: NodeJS.Platform;
370
+ arch: string;
371
+ isWindows: boolean;
372
+ isMac: boolean;
373
+ isLinux: boolean;
374
+ };
375
+
376
+ declare function detectCompilers(): {
377
+ platform: PlatformInfo;
378
+ c: CompilerInfo;
379
+ rust: any;
380
+ };
381
+
382
+ type CompilerKind = 'c' | 'cpp' | 'rust';
383
+ type CompilerInfo$1 = {
384
+ kind: CompilerKind;
385
+ path: string;
386
+ version: string;
387
+ vendor?: string;
388
+ };
389
+
390
+ type NativeLanguage = 'c' | 'cpp' | 'rust';
391
+
392
+ type CompileRequest = {
393
+ sourcePath: string;
394
+ outDir: string;
395
+ flags?: string[];
396
+ };
397
+ type CompileResult = {
398
+ language: NativeLanguage;
399
+ outputPath: string;
400
+ command: string[];
401
+ };
402
+
403
+ declare function compileNative(compiler: CompilerInfo$1, platform: PlatformInfo, request: CompileRequest): CompileResult;
404
+
405
+ declare function compileWithCache(compiler: CompilerInfo$1, platform: PlatformInfo, request: CompileRequest): CompileResult;
406
+
407
+ export { type BenchmarkOptions, type BenchmarkResult, type ExecutionMode, type HotReloadHandle, type HotReloadOptions, type InstallOptions, type InstallResult, InvalidFreeError, type IsolationMode, MemoryError, type NativeAddress, NativeBuffer, NativePointer, type NativeTestCase, type NativeTestKind, type NativeTestResult, NullPointerError, type Ownership, type RawAllocation, type RelaxConfig, type TraditionalBenchmarkResult, UseAfterFreeError, alloc, allocRaw, benchmarkCompareSyncVsWorker, benchmarkCompareTraditionalVsRelaxnative, benchmarkJsFunction, benchmarkNativeFunction, compileNative, compileWithCache, detectCompilers, discoverNativeTestFiles, discoverNativeTests, discoverNativeTestsFromFile, formatBenchmarkCompare, formatBenchmarkResult, formatBenchmarkTraditionalCompare, formatNativeTestResults, free, freeRaw, getInstalledPackageDir, getProjectRoot, getRegistryRoot, getSourceLine, installPackage, installPackageEnforcingTrust, listPackages, loadNative, loadNativeDevHot, loadNativeWithBindings, loadRegistry, index as native, readRelaxJson, removePackage, resolveRegistryImport, runNativeTests, updateIndex };
package/dist/index.js ADDED
@@ -0,0 +1,126 @@
1
+ import {
2
+ benchmarkCompareSyncVsWorker,
3
+ benchmarkCompareTraditionalVsRelaxnative,
4
+ benchmarkJsFunction,
5
+ benchmarkNativeFunction,
6
+ discoverNativeTestFiles,
7
+ discoverNativeTests,
8
+ discoverNativeTestsFromFile,
9
+ formatBenchmarkCompare,
10
+ formatBenchmarkResult,
11
+ formatBenchmarkTraditionalCompare,
12
+ formatNativeTestResults,
13
+ getInstalledPackageDir,
14
+ getProjectRoot,
15
+ getRegistryRoot,
16
+ getSourceLine,
17
+ installPackage,
18
+ installPackageEnforcingTrust,
19
+ listPackages,
20
+ normalizeTrustLevel,
21
+ readRelaxJson,
22
+ removePackage,
23
+ resolveRegistryImport,
24
+ runNativeTests,
25
+ trustPolicy,
26
+ updateIndex
27
+ } from "./chunk-OVMTFGE7.js";
28
+ import {
29
+ alloc,
30
+ allocRaw,
31
+ compileNative,
32
+ compileWithCache,
33
+ detectCompilers,
34
+ free,
35
+ freeRaw,
36
+ loadNative,
37
+ loadNativeDevHot,
38
+ loadNativeWithBindings,
39
+ memory_exports
40
+ } from "./chunk-LFTO3Z7N.js";
41
+ import "./chunk-HDIVY47T.js";
42
+ import {
43
+ InvalidFreeError,
44
+ MemoryError,
45
+ NativeBuffer,
46
+ NativePointer,
47
+ NullPointerError,
48
+ UseAfterFreeError
49
+ } from "./chunk-LLZ4I4OR.js";
50
+ import "./chunk-MLKGABMK.js";
51
+
52
+ // src/registry/loadRegistry.ts
53
+ import { join } from "path";
54
+ async function loadRegistry(pkg, projectRoot = process.cwd()) {
55
+ const pkgDir = getInstalledPackageDir(pkg, projectRoot);
56
+ const manifest = readRelaxJson(pkgDir);
57
+ const entry = manifest.exports[0];
58
+ if (!entry?.source) throw new Error(`No exports[0].source for ${pkg}`);
59
+ const trust = normalizeTrustLevel(manifest.trust);
60
+ const policy = trustPolicy(trust);
61
+ const safety = {
62
+ trust,
63
+ permissions: manifest.permissions,
64
+ limits: manifest.limits
65
+ };
66
+ const sourcePath = join(pkgDir, entry.source);
67
+ const { mod } = await loadNativeWithBindings(sourcePath, {
68
+ isolation: manifest.defaultIsolation ?? policy.defaultIsolation,
69
+ config: {
70
+ functionMode: manifest.functionMode,
71
+ defaultMode: manifest.defaultExecutionMode ?? policy.defaultExecutionMode
72
+ },
73
+ mutateBindings(bindings) {
74
+ bindings.__safety = safety;
75
+ }
76
+ });
77
+ if (process.env.VITEST) {
78
+ mod.__test_forbidden_fs = () => mod.__call("__test_forbidden_fs");
79
+ mod.__test_forbidden_net = () => mod.__call("__test_forbidden_net");
80
+ mod.__test_forbidden_spawn = () => mod.__call("__test_forbidden_spawn");
81
+ }
82
+ return mod;
83
+ }
84
+ export {
85
+ InvalidFreeError,
86
+ MemoryError,
87
+ NativeBuffer,
88
+ NativePointer,
89
+ NullPointerError,
90
+ UseAfterFreeError,
91
+ alloc,
92
+ allocRaw,
93
+ benchmarkCompareSyncVsWorker,
94
+ benchmarkCompareTraditionalVsRelaxnative,
95
+ benchmarkJsFunction,
96
+ benchmarkNativeFunction,
97
+ compileNative,
98
+ compileWithCache,
99
+ detectCompilers,
100
+ discoverNativeTestFiles,
101
+ discoverNativeTests,
102
+ discoverNativeTestsFromFile,
103
+ formatBenchmarkCompare,
104
+ formatBenchmarkResult,
105
+ formatBenchmarkTraditionalCompare,
106
+ formatNativeTestResults,
107
+ free,
108
+ freeRaw,
109
+ getInstalledPackageDir,
110
+ getProjectRoot,
111
+ getRegistryRoot,
112
+ getSourceLine,
113
+ installPackage,
114
+ installPackageEnforcingTrust,
115
+ listPackages,
116
+ loadNative,
117
+ loadNativeDevHot,
118
+ loadNativeWithBindings,
119
+ loadRegistry,
120
+ memory_exports as native,
121
+ readRelaxJson,
122
+ removePackage,
123
+ resolveRegistryImport,
124
+ runNativeTests,
125
+ updateIndex
126
+ };
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,25 @@
1
+ import {
2
+ alloc,
3
+ loadNative
4
+ } from "../chunk-LFTO3Z7N.js";
5
+ import "../chunk-HDIVY47T.js";
6
+ import "../chunk-LLZ4I4OR.js";
7
+ import "../chunk-MLKGABMK.js";
8
+
9
+ // src/memory/memory.selftest.ts
10
+ import { strict as assert } from "assert";
11
+ async function main() {
12
+ const buf = alloc(16);
13
+ assert.equal(buf.size, 16);
14
+ buf.write(new Uint8Array([1, 2, 3, 4]));
15
+ assert.equal(buf.toUint8Array()[0], 1);
16
+ const mod = await loadNative("examples/buffer.c");
17
+ assert.equal(typeof mod.fill_u8, "function");
18
+ assert.equal(typeof mod.sum_u8, "function");
19
+ mod.fill_u8(buf, buf.size, 7);
20
+ const sum = mod.sum_u8(buf, buf.size);
21
+ assert.equal(sum, 112);
22
+ buf.free();
23
+ console.log("memory selftest: ok");
24
+ }
25
+ main();
@@ -0,0 +1,2 @@
1
+
2
+ export { }