wasm-idle 1.0.8 → 1.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.
Files changed (79) hide show
  1. package/README.md +60 -26
  2. package/dist/playground/applicationAssets.js +18 -0
  3. package/dist/playground/assetBridge.d.ts +1 -1
  4. package/dist/playground/assetBridge.js +172 -117
  5. package/dist/playground/assets.d.ts +74 -4
  6. package/dist/playground/assets.js +127 -4
  7. package/dist/playground/cachedClang.js +44 -5
  8. package/dist/playground/clang.d.ts +5 -0
  9. package/dist/playground/clang.js +100 -0
  10. package/dist/playground/clangWorkerProtocol.d.ts +13 -1
  11. package/dist/playground/fennel.d.ts +9 -0
  12. package/dist/playground/fennel.js +30 -0
  13. package/dist/playground/fennelBootstrap.d.ts +31 -0
  14. package/dist/playground/fennelBootstrap.js +118 -0
  15. package/dist/playground/grain.d.ts +9 -0
  16. package/dist/playground/grain.js +127 -0
  17. package/dist/playground/hy.d.ts +21 -0
  18. package/dist/playground/hy.js +24 -0
  19. package/dist/playground/index.d.ts +1 -1
  20. package/dist/playground/index.js +49 -0
  21. package/dist/playground/lua.d.ts +19 -0
  22. package/dist/playground/lua.js +64 -39
  23. package/dist/playground/objectivec.d.ts +3 -1
  24. package/dist/playground/objectivec.js +6 -2
  25. package/dist/playground/options.js +1 -1
  26. package/dist/playground/postgresql.d.ts +36 -0
  27. package/dist/playground/postgresql.js +543 -0
  28. package/dist/playground/python.d.ts +5 -0
  29. package/dist/playground/python.js +13 -0
  30. package/dist/playground/rescript.d.ts +5 -0
  31. package/dist/playground/rescript.js +58 -0
  32. package/dist/playground/rescriptPreflight.d.ts +26 -0
  33. package/dist/playground/rescriptPreflight.js +381 -0
  34. package/dist/playground/runtimeAssetCache.d.ts +6 -0
  35. package/dist/playground/runtimeAssetCache.js +109 -0
  36. package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -1
  37. package/dist/playground/staticRuntimeModuleVersion.js +1 -1
  38. package/dist/playground/staticRuntimePreflightExecute.d.ts +2 -1
  39. package/dist/playground/staticRuntimePreflightExecute.js +9 -0
  40. package/dist/playground/staticRuntimePreflightProtocol.d.ts +1 -1
  41. package/dist/playground/v.d.ts +46 -0
  42. package/dist/playground/v.js +703 -0
  43. package/dist/playground/wasmBashVersion.d.ts +25 -25
  44. package/dist/playground/wasmBashVersion.js +12 -12
  45. package/dist/playground/wasmElixirVersion.d.ts +9 -9
  46. package/dist/playground/wasmElixirVersion.js +9 -9
  47. package/dist/playground/wasmFennelVersion.d.ts +23 -0
  48. package/dist/playground/wasmFennelVersion.js +16 -0
  49. package/dist/playground/wasmGrainVersion.d.ts +24 -0
  50. package/dist/playground/wasmGrainVersion.js +25 -0
  51. package/dist/playground/wasmHaskellVersion.d.ts +1 -1
  52. package/dist/playground/wasmHaskellVersion.js +1 -1
  53. package/dist/playground/wasmHyVersion.d.ts +7 -0
  54. package/dist/playground/wasmHyVersion.js +15 -0
  55. package/dist/playground/wasmLispVersion.d.ts +1 -1
  56. package/dist/playground/wasmLispVersion.js +1 -1
  57. package/dist/playground/wasmOcamlVersion.d.ts +4 -4
  58. package/dist/playground/wasmOcamlVersion.js +3 -3
  59. package/dist/playground/wasmPrologVersion.d.ts +19 -19
  60. package/dist/playground/wasmPrologVersion.js +18 -18
  61. package/dist/playground/wasmReScriptVersion.d.ts +20 -0
  62. package/dist/playground/wasmReScriptVersion.js +20 -0
  63. package/dist/playground/wasmTypeScriptVersion.d.ts +5 -5
  64. package/dist/playground/wasmTypeScriptVersion.js +5 -5
  65. package/dist/playground/worker/cachedClangCompile.js +44 -5
  66. package/dist/playground/worker/clang.js +44 -11
  67. package/dist/playground/worker/clangStreaming.js +6 -0
  68. package/dist/playground/worker/lua.js +48 -11
  69. package/dist/playground/worker/postgresql.d.ts +1 -0
  70. package/dist/playground/worker/postgresql.js +205 -0
  71. package/dist/playground/worker/python.js +113 -12
  72. package/dist/playground/worker/runtimeModule.d.ts +1 -1
  73. package/dist/playground/worker/runtimeModule.js +1 -1
  74. package/dist/playground/worker/staticRuntimePreflight.js +2 -1
  75. package/dist/playground/worker/v.d.ts +1 -0
  76. package/dist/playground/worker/v.js +106 -0
  77. package/dist/testPublicEnv.d.ts +2 -0
  78. package/dist/testPublicEnv.js +8 -0
  79. package/package.json +59 -48
@@ -6,9 +6,16 @@ import { createWasmIdleSharedBuffer } from './sharedBuffer';
6
6
  import { WorkerSession } from './workerSession';
7
7
  import { reportWorkerInputReady, reportWorkerProgress } from './workerProgress';
8
8
  const OUTPUT_ENCODER = new TextEncoder();
9
- const abortReason = (signal, phase) => signal.reason !== undefined
9
+ const abortReason = (signal, phase, label) => signal.reason !== undefined
10
10
  ? signal.reason
11
- : new DOMException(phase === 'startup' ? 'Lua runtime startup aborted' : 'Lua execution aborted', 'AbortError');
11
+ : new DOMException(phase === 'startup'
12
+ ? `${label} runtime startup aborted`
13
+ : `${label} execution aborted`, 'AbortError');
14
+ const LUA_DIALECT = {
15
+ label: 'Lua',
16
+ runtimeId: 'LUA',
17
+ defaultActivePath: 'main.lua'
18
+ };
12
19
  class Lua {
13
20
  output = null;
14
21
  worker = null;
@@ -25,34 +32,45 @@ class Lua {
25
32
  activeOperation = null;
26
33
  disposed = false;
27
34
  disposePromise = null;
28
- disposeCancellation = new CancelledError('Lua sandbox disposed', {
29
- phase: 'dispose',
30
- runtimeId: 'LUA',
31
- recoverable: false
32
- });
33
- workerSession = new WorkerSession({
34
- label: 'Lua',
35
- onDispose: (worker) => {
36
- if (this.worker === worker)
37
- delete this.worker;
38
- this.exit = true;
39
- this.waitingForInput = false;
40
- this.pendingEof = false;
41
- }
42
- });
35
+ dialect;
36
+ label;
37
+ runtimeId;
38
+ workerIdentity = '';
39
+ disposeCancellation;
40
+ workerSession;
41
+ constructor(dialect = LUA_DIALECT) {
42
+ this.dialect = dialect;
43
+ this.label = dialect.label;
44
+ this.runtimeId = dialect.runtimeId;
45
+ this.disposeCancellation = new CancelledError(`${this.label} sandbox disposed`, {
46
+ phase: 'dispose',
47
+ runtimeId: this.runtimeId,
48
+ recoverable: false
49
+ });
50
+ this.workerSession = new WorkerSession({
51
+ label: this.label,
52
+ onDispose: (worker) => {
53
+ if (this.worker === worker)
54
+ delete this.worker;
55
+ this.exit = true;
56
+ this.waitingForInput = false;
57
+ this.pendingEof = false;
58
+ }
59
+ });
60
+ }
43
61
  requireOperationIdle() {
44
62
  if (!this.activeOperation)
45
63
  return;
46
- throw new BusyError('Lua runtime already has an active operation', {
47
- runtimeId: 'LUA',
64
+ throw new BusyError(`${this.label} runtime already has an active operation`, {
65
+ runtimeId: this.runtimeId,
48
66
  phase: this.activeOperation.phase
49
67
  });
50
68
  }
51
69
  beginOperation(phase) {
52
70
  if (this.disposed) {
53
- throw new RuntimeConfigurationError('Lua sandbox is disposed', {
71
+ throw new RuntimeConfigurationError(`${this.label} sandbox is disposed`, {
54
72
  phase: 'dispose',
55
- runtimeId: 'LUA'
73
+ runtimeId: this.runtimeId
56
74
  });
57
75
  }
58
76
  this.requireOperationIdle();
@@ -113,7 +131,7 @@ class Lua {
113
131
  return;
114
132
  let reason;
115
133
  try {
116
- reason = abortReason(signal, operation.phase);
134
+ reason = abortReason(signal, operation.phase, this.label);
117
135
  }
118
136
  catch (error) {
119
137
  reason = error;
@@ -149,7 +167,7 @@ class Lua {
149
167
  return;
150
168
  let reason;
151
169
  try {
152
- reason = abortReason(signal, operation.phase);
170
+ reason = abortReason(signal, operation.phase, this.label);
153
171
  }
154
172
  catch (error) {
155
173
  reason = error;
@@ -189,9 +207,9 @@ class Lua {
189
207
  if (!this.isOperationActive(operation))
190
208
  return;
191
209
  const label = operation.phase === 'startup' ? 'startup' : 'execution';
192
- this.cancelOperation(operation, new TimeoutError(`Lua ${label} timed out after ${timeoutMs} ms`, {
210
+ this.cancelOperation(operation, new TimeoutError(`${this.label} ${label} timed out after ${timeoutMs} ms`, {
193
211
  phase: operation.phase,
194
- runtimeId: 'LUA',
212
+ runtimeId: this.runtimeId,
195
213
  timeoutMs
196
214
  }));
197
215
  }, timeoutMs);
@@ -234,11 +252,11 @@ class Lua {
234
252
  signal = options.signal;
235
253
  unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
236
254
  if (!this.isOperationActive(activeOperation) || signal?.aborted) {
237
- return Promise.reject(this.releaseBeforeSession(activeOperation, 'Lua runtime startup cancelled'));
255
+ return Promise.reject(this.releaseBeforeSession(activeOperation, `${this.label} runtime startup cancelled`));
238
256
  }
239
257
  limits = resolveExecutionLimits(options.limits);
240
258
  if (!this.isOperationActive(activeOperation) || signal?.aborted) {
241
- return Promise.reject(this.releaseBeforeSession(activeOperation, 'Lua runtime startup cancelled'));
259
+ return Promise.reject(this.releaseBeforeSession(activeOperation, `${this.label} runtime startup cancelled`));
242
260
  }
243
261
  unbindPreSessionAbort();
244
262
  }
@@ -246,7 +264,7 @@ class Lua {
246
264
  return Promise.reject(this.releaseBeforeSession(activeOperation, error));
247
265
  }
248
266
  if (!this.isOperationActive(activeOperation)) {
249
- return Promise.reject(this.releaseBeforeSession(activeOperation, 'Lua runtime startup cancelled'));
267
+ return Promise.reject(this.releaseBeforeSession(activeOperation, `${this.label} runtime startup cancelled`));
250
268
  }
251
269
  const loadPromise = this.workerSession.load(async (resolve, reject) => {
252
270
  const resolveLoad = () => {
@@ -274,8 +292,13 @@ class Lua {
274
292
  if (!nextModuleUrl) {
275
293
  return rejectLoad('Lua runtime is not configured. Set PUBLIC_WASM_LUA_MODULE_URL or runtimeAssets.lua.moduleUrl.');
276
294
  }
277
- const needsWorkerReset = !this.worker || this.moduleUrl !== nextModuleUrl;
295
+ const loadExtras = this.dialect.resolveWorkerLoadExtras?.(runtimeAssets, currentUrl) ?? {};
296
+ if (!this.isOperationActive(activeOperation))
297
+ return;
298
+ const nextWorkerIdentity = JSON.stringify([nextModuleUrl, loadExtras]);
299
+ const needsWorkerReset = !this.worker || this.workerIdentity !== nextWorkerIdentity;
278
300
  this.moduleUrl = nextModuleUrl;
301
+ this.workerIdentity = nextWorkerIdentity;
279
302
  if (needsWorkerReset && this.worker) {
280
303
  this.workerSession.reset();
281
304
  }
@@ -320,6 +343,7 @@ class Lua {
320
343
  };
321
344
  worker.onmessage = handler;
322
345
  worker.postMessage({
346
+ ...loadExtras,
323
347
  load: true,
324
348
  moduleUrl: this.moduleUrl
325
349
  });
@@ -392,12 +416,12 @@ class Lua {
392
416
  signal = options.signal;
393
417
  unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
394
418
  if (!this.isOperationActive(activeOperation)) {
395
- return Promise.reject(this.releaseBeforeSession(activeOperation, 'Lua execution cancelled'));
419
+ return Promise.reject(this.releaseBeforeSession(activeOperation, `${this.label} execution cancelled`));
396
420
  }
397
- executionArgs = resolveSandboxExecutionArgs('LUA', args, options);
421
+ executionArgs = resolveSandboxExecutionArgs(this.runtimeId, args, options);
398
422
  limits = resolveExecutionLimits(options.limits);
399
423
  const workspaceFiles = options.workspaceFiles ?? [];
400
- const activePath = options.activePath ?? 'main.lua';
424
+ const activePath = options.activePath ?? this.dialect.defaultActivePath;
401
425
  const workspaceLimits = options.workspaceLimits;
402
426
  workspace = validateExecutionWorkspace(code, workspaceFiles, activePath, {
403
427
  ...workspaceLimits,
@@ -406,7 +430,7 @@ class Lua {
406
430
  });
407
431
  stdin = options.stdin;
408
432
  if (!this.isOperationActive(activeOperation) || signal?.aborted) {
409
- return Promise.reject(this.releaseBeforeSession(activeOperation, 'Lua execution cancelled'));
433
+ return Promise.reject(this.releaseBeforeSession(activeOperation, `${this.label} execution cancelled`));
410
434
  }
411
435
  unbindPreSessionAbort();
412
436
  }
@@ -414,7 +438,7 @@ class Lua {
414
438
  return Promise.reject(this.releaseBeforeSession(activeOperation, error));
415
439
  }
416
440
  if (!this.isOperationActive(activeOperation)) {
417
- return Promise.reject(this.releaseBeforeSession(activeOperation, 'Lua execution cancelled'));
441
+ return Promise.reject(this.releaseBeforeSession(activeOperation, `${this.label} execution cancelled`));
418
442
  }
419
443
  const hasExplicitStdin = stdin !== undefined;
420
444
  if (hasExplicitStdin) {
@@ -476,7 +500,7 @@ class Lua {
476
500
  if (buffer && !hasExplicitStdin) {
477
501
  this.waitingForInput = true;
478
502
  if (!prepare) {
479
- reportWorkerInputReady(_prog, 'Lua runtime ready for input');
503
+ reportWorkerInputReady(_prog, `${this.label} runtime ready for input`);
480
504
  if (!ownsRun())
481
505
  return;
482
506
  }
@@ -490,11 +514,11 @@ class Lua {
490
514
  if (output) {
491
515
  const actual = outputBytes + OUTPUT_ENCODER.encode(String(output)).byteLength;
492
516
  if (actual > limits.maxOutputBytes) {
493
- failRun(new OutputLimitError(`Lua output exceeded ${limits.maxOutputBytes} bytes`, {
517
+ failRun(new OutputLimitError(`${this.label} output exceeded ${limits.maxOutputBytes} bytes`, {
494
518
  actual,
495
519
  limit: limits.maxOutputBytes,
496
520
  phase: 'execute',
497
- runtimeId: 'LUA'
521
+ runtimeId: this.runtimeId
498
522
  }), true);
499
523
  return;
500
524
  }
@@ -506,11 +530,11 @@ class Lua {
506
530
  if (diagnostic) {
507
531
  const actual = diagnosticCount + 1;
508
532
  if (actual > limits.maxDiagnostics) {
509
- failRun(new DiagnosticLimitError(`Lua diagnostics exceeded ${limits.maxDiagnostics} messages`, {
533
+ failRun(new DiagnosticLimitError(`${this.label} diagnostics exceeded ${limits.maxDiagnostics} messages`, {
510
534
  actual,
511
535
  limit: limits.maxDiagnostics,
512
536
  phase: 'execute',
513
- runtimeId: 'LUA'
537
+ runtimeId: this.runtimeId
514
538
  }), true);
515
539
  return;
516
540
  }
@@ -613,6 +637,7 @@ class Lua {
613
637
  const activeOperation = this.activeOperation;
614
638
  delete this.worker;
615
639
  this.moduleUrl = '';
640
+ this.workerIdentity = '';
616
641
  this.output = null;
617
642
  this.oncompilerdiagnostic = undefined;
618
643
  this.resetExplicitStdinState();
@@ -3,8 +3,9 @@ import type { DebugCommand, DebugSessionEvent } from './options';
3
3
  import { type PlaygroundRuntimeAssets } from './assets';
4
4
  import type { SandboxExecutionOptions } from './options';
5
5
  import type { Sandbox, SandboxProgress } from './sandbox';
6
+ export type ObjectiveCSandboxLanguage = 'OBJC' | 'OBJECTIVECXX';
6
7
  declare class ObjectiveC implements Sandbox {
7
- language: string;
8
+ language: ObjectiveCSandboxLanguage;
8
9
  output?: (data: string) => void;
9
10
  ondebug?: (event: DebugSessionEvent) => void;
10
11
  worker?: Worker;
@@ -24,6 +25,7 @@ declare class ObjectiveC implements Sandbox {
24
25
  assetBridge: WorkerAssetBridge | null;
25
26
  activeObjectiveCAssetsKey: string;
26
27
  private readonly workerSession;
28
+ constructor(language?: ObjectiveCSandboxLanguage);
27
29
  load(runtimeAssets?: string | PlaygroundRuntimeAssets, code?: string, log?: boolean, args?: string[], options?: SandboxExecutionOptions, progress?: SandboxProgress): Promise<void>;
28
30
  write(input: string): void;
29
31
  eof(): void;
@@ -9,7 +9,7 @@ import { AssetTooLargeError, createRuntimeAssetsKey, resolveExecutionLimits } fr
9
9
  const debugBreakpointBufferInts = 1028;
10
10
  const objectiveCAssetsKey = (assets) => createRuntimeAssetsKey({ objectivec: assets }) || '';
11
11
  class ObjectiveC {
12
- language = 'OBJC';
12
+ language;
13
13
  output;
14
14
  ondebug;
15
15
  worker = null;
@@ -49,6 +49,9 @@ class ObjectiveC {
49
49
  this.ondebug?.({ type: 'stop' });
50
50
  }
51
51
  });
52
+ constructor(language = 'OBJC') {
53
+ this.language = language;
54
+ }
52
55
  load(runtimeAssets = '', code = '', log = true, args = [], options = {}, progress) {
53
56
  let limits;
54
57
  try {
@@ -220,7 +223,8 @@ class ObjectiveC {
220
223
  log,
221
224
  compileArgs,
222
225
  programArgs,
223
- activePath: options.activePath,
226
+ activePath: options.activePath ||
227
+ (this.language === 'OBJECTIVECXX' ? 'main.mm' : undefined),
224
228
  workspaceFiles: options.workspaceFiles,
225
229
  debug: !!options.debug,
226
230
  breakpoints: [...(options.breakpoints || [])],
@@ -1,7 +1,7 @@
1
1
  function cloneArgs(value) {
2
2
  return Array.isArray(value) ? [...value] : [];
3
3
  }
4
- const compileArgLanguages = new Set(['C', 'CPP', 'OBJC']);
4
+ const compileArgLanguages = new Set(['C', 'CPP', 'OBJC', 'OBJECTIVECXX']);
5
5
  export function resolveSandboxExecutionArgs(language, args = [], options = {}) {
6
6
  if (compileArgLanguages.has(language)) {
7
7
  return {
@@ -0,0 +1,36 @@
1
+ import type { CompilerDiagnostic, SandboxExecutionOptions } from './options';
2
+ import { type PlaygroundRuntimeAssets } from './assets';
3
+ import type { Sandbox, SandboxProgress } from './sandbox';
4
+ declare class Postgresql implements Sandbox {
5
+ output: any;
6
+ worker?: Worker;
7
+ begin: number;
8
+ elapse: number;
9
+ uid: number;
10
+ exit: boolean;
11
+ moduleUrl: string;
12
+ oncompilerdiagnostic?: (diagnostic: CompilerDiagnostic) => void;
13
+ private activeOperation;
14
+ private disposed;
15
+ private disposePromise;
16
+ private readonly disposeCancellation;
17
+ private readonly workerSession;
18
+ private beginOperation;
19
+ private isOperationActive;
20
+ private releaseOperation;
21
+ private cleanupOperation;
22
+ private releaseBeforeSession;
23
+ private bindPreSessionAbort;
24
+ private bindAbortSignal;
25
+ private bindOperationTimeout;
26
+ private cancelOperation;
27
+ load(runtimeAssets?: string | PlaygroundRuntimeAssets, _code?: string, _log?: boolean, _args?: string[], options?: SandboxExecutionOptions, progress?: SandboxProgress): Promise<void>;
28
+ write(): void;
29
+ eof(): void;
30
+ run(code: string, prepare: boolean, _log?: boolean, _prog?: SandboxProgress, _args?: string[], options?: SandboxExecutionOptions): Promise<boolean | string>;
31
+ kill(): void;
32
+ terminate(reason?: unknown): void;
33
+ clear(): Promise<void>;
34
+ dispose(): Promise<void>;
35
+ }
36
+ export default Postgresql;