@componentor/quickjs-emscripten 0.31.26 → 0.31.28

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/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to},__reExport=(target,mod,secondTarget)=>(__copyProps(target,mod,"default"),secondTarget&&__copyProps(secondTarget,mod,"default")),__toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var index_exports={};__export(index_exports,{DEBUG_ASYNC:()=>import_quickjs_wasmfile_debug_asyncify.default,DEBUG_SYNC:()=>import_quickjs_wasmfile_debug_sync.default,RELEASE_ASYNC:()=>import_quickjs_wasmfile_release_asyncify.default,RELEASE_SYNC:()=>import_quickjs_wasmfile_release_sync.default,getQuickJS:()=>getQuickJS,getQuickJSSync:()=>getQuickJSSync,newAsyncContext:()=>newAsyncContext,newAsyncRuntime:()=>newAsyncRuntime,newQuickJSAsyncWASMModule:()=>newQuickJSAsyncWASMModule,newQuickJSWASMModule:()=>newQuickJSWASMModule});module.exports=__toCommonJS(index_exports);__reExport(index_exports,require("@componentor/quickjs-emscripten-core"),module.exports);var import_quickjs_emscripten_core=require("@componentor/quickjs-emscripten-core"),import_quickjs_wasmfile_debug_sync=__toESM(require("@componentor/quickjs-wasmfile-debug-sync")),import_quickjs_wasmfile_release_sync=__toESM(require("@componentor/quickjs-wasmfile-release-sync")),import_quickjs_wasmfile_debug_asyncify=__toESM(require("@componentor/quickjs-wasmfile-debug-asyncify")),import_quickjs_wasmfile_release_asyncify=__toESM(require("@componentor/quickjs-wasmfile-release-asyncify"));async function newQuickJSWASMModule(variantOrPromise=import_quickjs_wasmfile_release_sync.default){return(0,import_quickjs_emscripten_core.newQuickJSWASMModuleFromVariant)(variantOrPromise)}async function newQuickJSAsyncWASMModule(variantOrPromise=import_quickjs_wasmfile_release_asyncify.default){return(0,import_quickjs_emscripten_core.newQuickJSAsyncWASMModuleFromVariant)(variantOrPromise)}var singleton,singletonPromise;async function getQuickJS(){return singletonPromise??(singletonPromise=newQuickJSWASMModule().then(instance=>(singleton=instance,instance))),await singletonPromise}function getQuickJSSync(){if(!singleton)throw new Error("QuickJS not initialized. Await getQuickJS() at least once.");return singleton}async function newAsyncRuntime(options){return(await newQuickJSAsyncWASMModule()).newRuntime(options)}async function newAsyncContext(options){return(await newQuickJSAsyncWASMModule()).newContext(options)}0&&(module.exports={DEBUG_ASYNC,DEBUG_SYNC,RELEASE_ASYNC,RELEASE_SYNC,getQuickJS,getQuickJSSync,newAsyncContext,newAsyncRuntime,newQuickJSAsyncWASMModule,newQuickJSWASMModule,...require("@componentor/quickjs-emscripten-core")});
1
+ "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to},__reExport=(target,mod,secondTarget)=>(__copyProps(target,mod,"default"),secondTarget&&__copyProps(secondTarget,mod,"default")),__toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var index_exports={};__export(index_exports,{DEBUG_ASYNC:()=>import_quickjs_wasmfile_debug_asyncify.default,DEBUG_SYNC:()=>import_quickjs_wasmfile_debug_sync.default,MultiThreadingNotSupportedError:()=>import_quickjs_emscripten_worker_pool2.MultiThreadingNotSupportedError,PoolDisposedError:()=>import_quickjs_emscripten_worker_pool2.PoolDisposedError,QueueFullError:()=>import_quickjs_emscripten_worker_pool2.QueueFullError,QuickJSWorkerPool:()=>import_quickjs_emscripten_worker_pool2.QuickJSWorkerPool,RELEASE_ASYNC:()=>import_quickjs_wasmfile_release_asyncify.default,RELEASE_SYNC:()=>import_quickjs_wasmfile_release_sync.default,WorkerCrashError:()=>import_quickjs_emscripten_worker_pool2.WorkerCrashError,WorkerEnabledContext:()=>import_quickjs_emscripten_worker_pool2.WorkerEnabledContext,WorkerPoolContext:()=>import_quickjs_emscripten_worker_pool2.WorkerPoolContext,WorkerTaskCancelledError:()=>import_quickjs_emscripten_worker_pool2.WorkerTaskCancelledError,WorkerTaskTimeoutError:()=>import_quickjs_emscripten_worker_pool2.WorkerTaskTimeoutError,canUseWorkers:()=>canUseWorkers,configureWorkerPool:()=>configureWorkerPool,detectPlatform:()=>import_quickjs_emscripten_worker_pool2.detectPlatform,getDefaultPoolSize:()=>import_quickjs_emscripten_worker_pool2.getDefaultPoolSize,getQuickJS:()=>getQuickJS,getQuickJSSync:()=>getQuickJSSync,getWorkerPool:()=>import_quickjs_emscripten_worker_pool2.getWorkerPool,getWorkerPoolConfig:()=>getWorkerPoolConfig,getWorkerPoolSync:()=>import_quickjs_emscripten_worker_pool2.getWorkerPoolSync,isMultiThreadingSupported:()=>import_quickjs_emscripten_worker_pool2.isMultiThreadingSupported,newAsyncContext:()=>newAsyncContext,newAsyncRuntime:()=>newAsyncRuntime,newQuickJSAsyncWASMModule:()=>newQuickJSAsyncWASMModule,newQuickJSWASMModule:()=>newQuickJSWASMModule,newWorkerAsyncContext:()=>newWorkerAsyncContext,newWorkerEnabledContext:()=>import_quickjs_emscripten_worker_pool2.newWorkerEnabledContext,newWorkerPool:()=>import_quickjs_emscripten_worker_pool2.newWorkerPool,newWorkerPoolContext:()=>import_quickjs_emscripten_worker_pool2.newWorkerPoolContext,resetWorkerPoolConfig:()=>resetWorkerPoolConfig});module.exports=__toCommonJS(index_exports);__reExport(index_exports,require("@componentor/quickjs-emscripten-core"),module.exports);var import_quickjs_emscripten_core=require("@componentor/quickjs-emscripten-core"),import_quickjs_wasmfile_debug_sync=__toESM(require("@componentor/quickjs-wasmfile-debug-sync")),import_quickjs_wasmfile_release_sync=__toESM(require("@componentor/quickjs-wasmfile-release-sync")),import_quickjs_wasmfile_debug_asyncify=__toESM(require("@componentor/quickjs-wasmfile-debug-asyncify")),import_quickjs_wasmfile_release_asyncify=__toESM(require("@componentor/quickjs-wasmfile-release-asyncify"));async function newQuickJSWASMModule(variantOrPromise=import_quickjs_wasmfile_release_sync.default){return(0,import_quickjs_emscripten_core.newQuickJSWASMModuleFromVariant)(variantOrPromise)}async function newQuickJSAsyncWASMModule(variantOrPromise=import_quickjs_wasmfile_release_asyncify.default){return(0,import_quickjs_emscripten_core.newQuickJSAsyncWASMModuleFromVariant)(variantOrPromise)}var import_quickjs_emscripten_worker_pool=require("@componentor/quickjs-emscripten-worker-pool");var singleton,singletonPromise,globalWorkerConfig={enabled:!0};function configureWorkerPool(config){globalWorkerConfig={...globalWorkerConfig,...config}}function getWorkerPoolConfig(){return{...globalWorkerConfig}}function resetWorkerPoolConfig(){globalWorkerConfig={enabled:!0}}async function getQuickJS(){return singletonPromise??(singletonPromise=newQuickJSWASMModule().then(instance=>(singleton=instance,instance))),await singletonPromise}function getQuickJSSync(){if(!singleton)throw new Error("QuickJS not initialized. Await getQuickJS() at least once.");return singleton}async function newAsyncRuntime(options){return(await newQuickJSAsyncWASMModule()).newRuntime(options)}async function newAsyncContext(options){return(await newQuickJSAsyncWASMModule()).newContext(options)}async function newWorkerAsyncContext(options){let mergedOptions={poolSize:options?.poolSize??globalWorkerConfig.poolSize,bootstrapCode:options?.bootstrapCode??globalWorkerConfig.bootstrapCode,useSession:options?.useSession??globalWorkerConfig.useSession,verbose:options?.verbose??globalWorkerConfig.verbose,defaultTimeout:options?.defaultTimeout??globalWorkerConfig.defaultTimeout,...options};return(0,import_quickjs_emscripten_worker_pool.newWorkerEnabledContext)(mergedOptions)}function canUseWorkers(){return(0,import_quickjs_emscripten_worker_pool.isMultiThreadingSupported)()}var import_quickjs_emscripten_worker_pool2=require("@componentor/quickjs-emscripten-worker-pool");0&&(module.exports={DEBUG_ASYNC,DEBUG_SYNC,MultiThreadingNotSupportedError,PoolDisposedError,QueueFullError,QuickJSWorkerPool,RELEASE_ASYNC,RELEASE_SYNC,WorkerCrashError,WorkerEnabledContext,WorkerPoolContext,WorkerTaskCancelledError,WorkerTaskTimeoutError,canUseWorkers,configureWorkerPool,detectPlatform,getDefaultPoolSize,getQuickJS,getQuickJSSync,getWorkerPool,getWorkerPoolConfig,getWorkerPoolSync,isMultiThreadingSupported,newAsyncContext,newAsyncRuntime,newQuickJSAsyncWASMModule,newQuickJSWASMModule,newWorkerAsyncContext,newWorkerEnabledContext,newWorkerPool,newWorkerPoolContext,resetWorkerPoolConfig,...require("@componentor/quickjs-emscripten-core")});
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/variants.ts","../src/mod.ts"],"sourcesContent":["export * from \"@componentor/quickjs-emscripten-core\"\nexport * from \"#variants\"\nexport * from \"./mod.js\"\n","import type {\n QuickJSSyncVariant,\n QuickJSAsyncVariant,\n QuickJSWASMModule,\n QuickJSAsyncWASMModule,\n PromisedDefault,\n} from \"@componentor/quickjs-emscripten-core\"\nimport {\n newQuickJSWASMModuleFromVariant,\n newQuickJSAsyncWASMModuleFromVariant,\n} from \"@componentor/quickjs-emscripten-core\"\nimport DEBUG_SYNC from \"@componentor/quickjs-wasmfile-debug-sync\"\nimport RELEASE_SYNC from \"@componentor/quickjs-wasmfile-release-sync\"\nimport DEBUG_ASYNC from \"@componentor/quickjs-wasmfile-debug-asyncify\"\nimport RELEASE_ASYNC from \"@componentor/quickjs-wasmfile-release-asyncify\"\n\n/**\n * Create a new, completely isolated WebAssembly module containing the QuickJS library.\n * See the documentation on {@link QuickJSWASMModule}.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n */\nexport async function newQuickJSWASMModule(\n /**\n * Optionally, pass a {@link QuickJSSyncVariant} to construct a different WebAssembly module.\n */\n variantOrPromise: PromisedDefault<QuickJSSyncVariant> = RELEASE_SYNC,\n): Promise<QuickJSWASMModule> {\n return newQuickJSWASMModuleFromVariant(variantOrPromise)\n}\n\n/**\n * Create a new, completely isolated WebAssembly module containing a version of the QuickJS library\n * compiled with Emscripten's [ASYNCIFY](https://emscripten.org/docs/porting/asyncify.html) transform.\n *\n * This version of the library offers features that enable synchronous code\n * inside the VM to interact with asynchronous code in the host environment.\n * See the documentation on {@link QuickJSAsyncWASMModule}, {@link QuickJSAsyncRuntime},\n * and {@link QuickJSAsyncContext}.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n */\nexport async function newQuickJSAsyncWASMModule(\n /**\n * Optionally, pass a {@link QuickJSAsyncVariant} to construct a different WebAssembly module.\n */\n variantOrPromise: PromisedDefault<QuickJSAsyncVariant> = RELEASE_ASYNC,\n): Promise<QuickJSAsyncWASMModule> {\n return newQuickJSAsyncWASMModuleFromVariant(variantOrPromise)\n}\n\nexport { DEBUG_SYNC, RELEASE_SYNC, DEBUG_ASYNC, RELEASE_ASYNC }\n","import type {\n AsyncRuntimeOptions,\n ContextOptions,\n QuickJSAsyncContext,\n QuickJSAsyncRuntime,\n QuickJSWASMModule,\n} from \"@componentor/quickjs-emscripten-core\"\nimport { newQuickJSAsyncWASMModule, newQuickJSWASMModule } from \"#variants\"\n\nlet singleton: QuickJSWASMModule | undefined = undefined\nlet singletonPromise: Promise<QuickJSWASMModule> | undefined = undefined\n\n/**\n * Get a shared singleton {@link QuickJSWASMModule}. Use this to evaluate code\n * or create Javascript environments.\n *\n * This is the top-level entrypoint for the quickjs-emscripten library.\n *\n * If you need strictest possible isolation guarantees, you may create a\n * separate {@link QuickJSWASMModule} via {@link newQuickJSWASMModule}.\n *\n * To work with the asyncified version of this library, see these functions:\n *\n * - {@link newAsyncRuntime}.\n * - {@link newAsyncContext}.\n * - {@link newQuickJSAsyncWASMModule}.\n */\nexport async function getQuickJS(): Promise<QuickJSWASMModule> {\n singletonPromise ??= newQuickJSWASMModule().then((instance) => {\n singleton = instance\n return instance\n })\n return await singletonPromise\n}\n\n/**\n * Provides synchronous access to the shared {@link QuickJSWASMModule} instance returned by {@link getQuickJS}, as long as\n * least once.\n * @throws If called before `getQuickJS` resolves.\n */\nexport function getQuickJSSync(): QuickJSWASMModule {\n if (!singleton) {\n throw new Error(\"QuickJS not initialized. Await getQuickJS() at least once.\")\n }\n return singleton\n}\n\n/**\n * Create a new {@link QuickJSAsyncRuntime} in a separate WebAssembly module.\n *\n * Each runtime is isolated in a separate WebAssembly module, so that errors in\n * one runtime cannot contaminate another runtime, and each runtime can execute\n * an asynchronous action without conflicts.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n */\nexport async function newAsyncRuntime(options?: AsyncRuntimeOptions): Promise<QuickJSAsyncRuntime> {\n const module = await newQuickJSAsyncWASMModule()\n return module.newRuntime(options)\n}\n\n/**\n * Create a new {@link QuickJSAsyncContext} (with an associated runtime) in an\n * separate WebAssembly module.\n *\n * Each context is isolated in a separate WebAssembly module, so that errors in\n * one runtime cannot contaminate another runtime, and each runtime can execute\n * an asynchronous action without conflicts.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n */\nexport async function newAsyncContext(options?: ContextOptions): Promise<QuickJSAsyncContext> {\n const module = await newQuickJSAsyncWASMModule()\n return module.newContext(options)\n}\n"],"mappings":"qhCAAA,oGAAAA,QAAA,kDAAAC,QAAA,2DAAAC,QAAA,sDAAAC,QAAA,gTAAc,gDAAd,gBCOA,mCAGO,gDACP,mCAAuB,6DACvB,qCAAyB,+DACzB,uCAAwB,iEACxB,yCAA0B,mEAU1B,eAAsB,qBAIpB,iBAAwD,qCAAAC,QAC5B,CAC5B,SAAO,gEAAgC,gBAAgB,CACzD,CAeA,eAAsB,0BAIpB,iBAAyD,yCAAAC,QACxB,CACjC,SAAO,qEAAqC,gBAAgB,CAC9D,CC5CA,IAAI,UACA,iBAiBJ,eAAsB,YAAyC,CAC7D,2CAAqB,qBAAqB,EAAE,KAAM,WAChD,UAAY,SACL,SACR,GACM,MAAM,gBACf,CAOO,SAAS,gBAAoC,CAClD,GAAI,CAAC,UACH,MAAM,IAAI,MAAM,4DAA4D,EAE9E,OAAO,SACT,CAaA,eAAsB,gBAAgB,QAA6D,CAEjG,OADe,MAAM,0BAA0B,GACjC,WAAW,OAAO,CAClC,CAcA,eAAsB,gBAAgB,QAAwD,CAE5F,OADe,MAAM,0BAA0B,GACjC,WAAW,OAAO,CAClC","names":["DEBUG_ASYNC","DEBUG_SYNC","RELEASE_ASYNC","RELEASE_SYNC","RELEASE_SYNC","RELEASE_ASYNC"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/variants.ts","../src/mod.ts"],"sourcesContent":["export * from \"@componentor/quickjs-emscripten-core\"\nexport * from \"#variants\"\nexport * from \"./mod.js\"\n\n// Worker pool exports - for parallel execution across workers\nexport {\n // Main pool classes and factories\n QuickJSWorkerPool,\n newWorkerPool,\n getWorkerPool,\n getWorkerPoolSync,\n // Context wrappers\n WorkerPoolContext,\n newWorkerPoolContext,\n WorkerEnabledContext,\n newWorkerEnabledContext,\n // Capability detection\n isMultiThreadingSupported,\n getDefaultPoolSize,\n detectPlatform,\n // Errors\n WorkerTaskTimeoutError,\n WorkerTaskCancelledError,\n WorkerCrashError,\n PoolDisposedError,\n QueueFullError,\n MultiThreadingNotSupportedError,\n // Types\n type WorkerPoolOptions,\n type WorkerPoolVariant,\n type WorkerTask,\n type WorkerTaskResult,\n type WorkerTaskError,\n type TaskHandle,\n type PoolStats,\n type WorkerSession,\n type SessionEvalOptions,\n type WorkerPoolContextResult,\n type WorkerPoolEvalOptions,\n type WorkerEnabledContextOptions,\n type WorkerEnabledContextResult,\n} from \"@componentor/quickjs-emscripten-worker-pool\"\n","import type {\n QuickJSSyncVariant,\n QuickJSAsyncVariant,\n QuickJSWASMModule,\n QuickJSAsyncWASMModule,\n PromisedDefault,\n} from \"@componentor/quickjs-emscripten-core\"\nimport {\n newQuickJSWASMModuleFromVariant,\n newQuickJSAsyncWASMModuleFromVariant,\n} from \"@componentor/quickjs-emscripten-core\"\nimport DEBUG_SYNC from \"@componentor/quickjs-wasmfile-debug-sync\"\nimport RELEASE_SYNC from \"@componentor/quickjs-wasmfile-release-sync\"\nimport DEBUG_ASYNC from \"@componentor/quickjs-wasmfile-debug-asyncify\"\nimport RELEASE_ASYNC from \"@componentor/quickjs-wasmfile-release-asyncify\"\n\n/**\n * Create a new, completely isolated WebAssembly module containing the QuickJS library.\n * See the documentation on {@link QuickJSWASMModule}.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n */\nexport async function newQuickJSWASMModule(\n /**\n * Optionally, pass a {@link QuickJSSyncVariant} to construct a different WebAssembly module.\n */\n variantOrPromise: PromisedDefault<QuickJSSyncVariant> = RELEASE_SYNC,\n): Promise<QuickJSWASMModule> {\n return newQuickJSWASMModuleFromVariant(variantOrPromise)\n}\n\n/**\n * Create a new, completely isolated WebAssembly module containing a version of the QuickJS library\n * compiled with Emscripten's [ASYNCIFY](https://emscripten.org/docs/porting/asyncify.html) transform.\n *\n * This version of the library offers features that enable synchronous code\n * inside the VM to interact with asynchronous code in the host environment.\n * See the documentation on {@link QuickJSAsyncWASMModule}, {@link QuickJSAsyncRuntime},\n * and {@link QuickJSAsyncContext}.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n */\nexport async function newQuickJSAsyncWASMModule(\n /**\n * Optionally, pass a {@link QuickJSAsyncVariant} to construct a different WebAssembly module.\n */\n variantOrPromise: PromisedDefault<QuickJSAsyncVariant> = RELEASE_ASYNC,\n): Promise<QuickJSAsyncWASMModule> {\n return newQuickJSAsyncWASMModuleFromVariant(variantOrPromise)\n}\n\nexport { DEBUG_SYNC, RELEASE_SYNC, DEBUG_ASYNC, RELEASE_ASYNC }\n","import type {\n AsyncRuntimeOptions,\n ContextOptions,\n QuickJSAsyncContext,\n QuickJSAsyncRuntime,\n QuickJSWASMModule,\n} from \"@componentor/quickjs-emscripten-core\"\nimport {\n newWorkerEnabledContext as createWorkerEnabledContext,\n isMultiThreadingSupported,\n type WorkerEnabledContext,\n type WorkerEnabledContextOptions,\n} from \"@componentor/quickjs-emscripten-worker-pool\"\nimport { newQuickJSAsyncWASMModule, newQuickJSWASMModule } from \"#variants\"\n\nlet singleton: QuickJSWASMModule | undefined = undefined\nlet singletonPromise: Promise<QuickJSWASMModule> | undefined = undefined\n\n// ============================================\n// Global Worker Pool Configuration\n// ============================================\n\n/**\n * Global configuration for worker pool contexts.\n * These settings are used as defaults when calling {@link newWorkerAsyncContext}.\n */\nexport interface WorkerPoolConfig {\n /**\n * Whether worker pool is enabled.\n * @default true\n */\n enabled?: boolean\n\n /**\n * Number of workers in the pool.\n * @default navigator.hardwareConcurrency or 4\n */\n poolSize?: number\n\n /**\n * Bootstrap code that runs on each worker during initialization.\n * Use this to set up shared state like mocks, utilities, etc.\n *\n * @example\n * ```typescript\n * configureWorkerPool({\n * bootstrapCode: `\n * globalThis.mockFetch = (url) => ({ status: 200, url })\n * `\n * })\n * ```\n */\n bootstrapCode?: string\n\n /**\n * Whether to use a session for state persistence.\n * - false (default): Parallel execution, each eval may hit different worker\n * - true: Sequential execution, all evals go to same worker (state persists)\n * @default false\n */\n useSession?: boolean\n\n /**\n * Enable verbose logging for debugging.\n * @default false\n */\n verbose?: boolean\n\n /**\n * Default timeout for code execution in milliseconds.\n * @default 0 (no timeout)\n */\n defaultTimeout?: number\n}\n\n// Global worker pool configuration\nlet globalWorkerConfig: WorkerPoolConfig = {\n enabled: true, // Auto-use workers by default\n}\n\n/**\n * Configure the global worker pool settings.\n *\n * Call this before creating worker contexts to set up default worker pool options.\n * These settings are used as defaults when calling {@link newWorkerAsyncContext}.\n *\n * @example\n * ```typescript\n * import { configureWorkerPool, newWorkerAsyncContext } from \"@componentor/quickjs-emscripten\"\n *\n * // Configure once at startup\n * configureWorkerPool({\n * poolSize: 4,\n * bootstrapCode: `\n * globalThis.mockFetch = (url) => ({ status: 200, url })\n * `\n * })\n *\n * // Create worker context - uses global config!\n * const ctx = await newWorkerAsyncContext()\n *\n * // Parallel execution across workers\n * const results = await Promise.all([\n * ctx.evalCodeAsync('mockFetch(\"/api/1\")'),\n * ctx.evalCodeAsync('mockFetch(\"/api/2\")'),\n * ctx.evalCodeAsync('mockFetch(\"/api/3\")'),\n * ])\n * ```\n */\nexport function configureWorkerPool(config: WorkerPoolConfig): void {\n globalWorkerConfig = { ...globalWorkerConfig, ...config }\n}\n\n/**\n * Get the current global worker pool configuration.\n */\nexport function getWorkerPoolConfig(): WorkerPoolConfig {\n return { ...globalWorkerConfig }\n}\n\n/**\n * Reset the global worker pool configuration to defaults.\n */\nexport function resetWorkerPoolConfig(): void {\n globalWorkerConfig = { enabled: true }\n}\n\n// ============================================\n// Core QuickJS Functions\n// ============================================\n\n/**\n * Get a shared singleton {@link QuickJSWASMModule}. Use this to evaluate code\n * or create Javascript environments.\n *\n * This is the top-level entrypoint for the quickjs-emscripten library.\n *\n * If you need strictest possible isolation guarantees, you may create a\n * separate {@link QuickJSWASMModule} via {@link newQuickJSWASMModule}.\n *\n * To work with the asyncified version of this library, see these functions:\n *\n * - {@link newAsyncRuntime}.\n * - {@link newAsyncContext}.\n * - {@link newQuickJSAsyncWASMModule}.\n */\nexport async function getQuickJS(): Promise<QuickJSWASMModule> {\n singletonPromise ??= newQuickJSWASMModule().then((instance) => {\n singleton = instance\n return instance\n })\n return await singletonPromise\n}\n\n/**\n * Provides synchronous access to the shared {@link QuickJSWASMModule} instance returned by {@link getQuickJS}, as long as\n * least once.\n * @throws If called before `getQuickJS` resolves.\n */\nexport function getQuickJSSync(): QuickJSWASMModule {\n if (!singleton) {\n throw new Error(\"QuickJS not initialized. Await getQuickJS() at least once.\")\n }\n return singleton\n}\n\n/**\n * Create a new {@link QuickJSAsyncRuntime} in a separate WebAssembly module.\n *\n * Each runtime is isolated in a separate WebAssembly module, so that errors in\n * one runtime cannot contaminate another runtime, and each runtime can execute\n * an asynchronous action without conflicts.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n */\nexport async function newAsyncRuntime(options?: AsyncRuntimeOptions): Promise<QuickJSAsyncRuntime> {\n const module = await newQuickJSAsyncWASMModule()\n return module.newRuntime(options)\n}\n\n/**\n * Create a new {@link QuickJSAsyncContext} in a separate WebAssembly module.\n *\n * Each context is isolated in a separate WebAssembly module, so that errors in\n * one runtime cannot contaminate another runtime, and each runtime can execute\n * an asynchronous action without conflicts.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n *\n * For parallel execution across workers, use {@link newWorkerAsyncContext} instead.\n */\nexport async function newAsyncContext(options?: ContextOptions): Promise<QuickJSAsyncContext> {\n const module = await newQuickJSAsyncWASMModule()\n return module.newContext(options)\n}\n\n// ============================================\n// Worker Pool Helpers\n// ============================================\n\n/**\n * Options for creating a worker-enabled async context.\n */\nexport interface WorkerAsyncContextOptions extends WorkerEnabledContextOptions {\n /**\n * Context options for the local QuickJS context.\n */\n contextOptions?: ContextOptions\n}\n\n/**\n * Create a new {@link WorkerEnabledContext} for parallel execution across workers.\n *\n * This is the recommended way to use QuickJS with parallel execution. Each\n * `evalCodeAsync` call can be distributed to different workers for parallelism.\n *\n * Uses global config from {@link configureWorkerPool} as defaults, which can\n * be overridden by passing options.\n *\n * @example\n * ```typescript\n * // Simple usage with defaults\n * const ctx = await newWorkerAsyncContext()\n *\n * // Parallel execution\n * const results = await Promise.all([\n * ctx.evalCodeAsync('1 + 1'),\n * ctx.evalCodeAsync('2 + 2'),\n * ctx.evalCodeAsync('3 + 3'),\n * ])\n * ```\n *\n * @example\n * ```typescript\n * // With bootstrap code for mocks\n * const ctx = await newWorkerAsyncContext({\n * poolSize: 8,\n * bootstrapCode: `\n * globalThis.mockFetch = (url) => ({ status: 200, url })\n * `,\n * })\n * ```\n *\n * @param options Worker pool and context options (overrides global config)\n * @returns A new WorkerEnabledContext instance\n */\nexport async function newWorkerAsyncContext(\n options?: WorkerAsyncContextOptions,\n): Promise<WorkerEnabledContext> {\n // Merge global config with provided options\n const mergedOptions: WorkerAsyncContextOptions = {\n poolSize: options?.poolSize ?? globalWorkerConfig.poolSize,\n bootstrapCode: options?.bootstrapCode ?? globalWorkerConfig.bootstrapCode,\n useSession: options?.useSession ?? globalWorkerConfig.useSession,\n verbose: options?.verbose ?? globalWorkerConfig.verbose,\n defaultTimeout: options?.defaultTimeout ?? globalWorkerConfig.defaultTimeout,\n ...options,\n }\n return createWorkerEnabledContext(mergedOptions)\n}\n\n/**\n * Check if multi-threading is supported in the current environment.\n *\n * Returns true if SharedArrayBuffer is available (required for Web Workers\n * to share memory). In browsers, this requires COOP/COEP headers to be set.\n * In Node.js, this is typically always available.\n *\n * @example\n * ```typescript\n * if (canUseWorkers()) {\n * console.log('Parallel execution available!')\n * } else {\n * console.log('Falling back to single-threaded execution')\n * }\n * ```\n */\nexport function canUseWorkers(): boolean {\n return isMultiThreadingSupported()\n}\n"],"mappings":"qhCAAA,oGAAAA,QAAA,kDAAAC,QAAA,6YAAAC,QAAA,sDAAAC,QAAA,qjDAAc,gDAAd,gBCOA,mCAGO,gDACP,mCAAuB,6DACvB,qCAAyB,+DACzB,uCAAwB,iEACxB,yCAA0B,mEAU1B,eAAsB,qBAIpB,iBAAwD,qCAAAC,QAC5B,CAC5B,SAAO,gEAAgC,gBAAgB,CACzD,CAeA,eAAsB,0BAIpB,iBAAyD,yCAAAC,QACxB,CACjC,SAAO,qEAAqC,gBAAgB,CAC9D,CC9CA,0CAKO,uDAGP,IAAI,UACA,iBA4DA,mBAAuC,CACzC,QAAS,EACX,EA+BO,SAAS,oBAAoB,OAAgC,CAClE,mBAAqB,CAAE,GAAG,mBAAoB,GAAG,MAAO,CAC1D,CAKO,SAAS,qBAAwC,CACtD,MAAO,CAAE,GAAG,kBAAmB,CACjC,CAKO,SAAS,uBAA8B,CAC5C,mBAAqB,CAAE,QAAS,EAAK,CACvC,CAqBA,eAAsB,YAAyC,CAC7D,2CAAqB,qBAAqB,EAAE,KAAM,WAChD,UAAY,SACL,SACR,GACM,MAAM,gBACf,CAOO,SAAS,gBAAoC,CAClD,GAAI,CAAC,UACH,MAAM,IAAI,MAAM,4DAA4D,EAE9E,OAAO,SACT,CAaA,eAAsB,gBAAgB,QAA6D,CAEjG,OADe,MAAM,0BAA0B,GACjC,WAAW,OAAO,CAClC,CAeA,eAAsB,gBAAgB,QAAwD,CAE5F,OADe,MAAM,0BAA0B,GACjC,WAAW,OAAO,CAClC,CAoDA,eAAsB,sBACpB,QAC+B,CAE/B,IAAM,cAA2C,CAC/C,SAAU,SAAS,UAAY,mBAAmB,SAClD,cAAe,SAAS,eAAiB,mBAAmB,cAC5D,WAAY,SAAS,YAAc,mBAAmB,WACtD,QAAS,SAAS,SAAW,mBAAmB,QAChD,eAAgB,SAAS,gBAAkB,mBAAmB,eAC9D,GAAG,OACL,EACA,SAAO,sCAAAC,yBAA2B,aAAa,CACjD,CAkBO,SAAS,eAAyB,CACvC,SAAO,iEAA0B,CACnC,CFtRA,IAAAC,uCAoCO","names":["DEBUG_ASYNC","DEBUG_SYNC","RELEASE_ASYNC","RELEASE_SYNC","RELEASE_SYNC","RELEASE_ASYNC","createWorkerEnabledContext","import_quickjs_emscripten_worker_pool"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{DEBUG_ASYNC,DEBUG_SYNC,RELEASE_ASYNC,RELEASE_SYNC,newQuickJSAsyncWASMModule,newQuickJSWASMModule}from"./chunk-IBGVJUFE.mjs";export*from"@componentor/quickjs-emscripten-core";var singleton,singletonPromise;async function getQuickJS(){return singletonPromise??(singletonPromise=newQuickJSWASMModule().then(instance=>(singleton=instance,instance))),await singletonPromise}function getQuickJSSync(){if(!singleton)throw new Error("QuickJS not initialized. Await getQuickJS() at least once.");return singleton}async function newAsyncRuntime(options){return(await newQuickJSAsyncWASMModule()).newRuntime(options)}async function newAsyncContext(options){return(await newQuickJSAsyncWASMModule()).newContext(options)}export{DEBUG_ASYNC,DEBUG_SYNC,RELEASE_ASYNC,RELEASE_SYNC,getQuickJS,getQuickJSSync,newAsyncContext,newAsyncRuntime,newQuickJSAsyncWASMModule,newQuickJSWASMModule};
1
+ import{DEBUG_ASYNC,DEBUG_SYNC,RELEASE_ASYNC,RELEASE_SYNC,newQuickJSAsyncWASMModule,newQuickJSWASMModule}from"./chunk-IBGVJUFE.mjs";export*from"@componentor/quickjs-emscripten-core";import{newWorkerEnabledContext as createWorkerEnabledContext,isMultiThreadingSupported}from"@componentor/quickjs-emscripten-worker-pool";var singleton,singletonPromise,globalWorkerConfig={enabled:!0};function configureWorkerPool(config){globalWorkerConfig={...globalWorkerConfig,...config}}function getWorkerPoolConfig(){return{...globalWorkerConfig}}function resetWorkerPoolConfig(){globalWorkerConfig={enabled:!0}}async function getQuickJS(){return singletonPromise??(singletonPromise=newQuickJSWASMModule().then(instance=>(singleton=instance,instance))),await singletonPromise}function getQuickJSSync(){if(!singleton)throw new Error("QuickJS not initialized. Await getQuickJS() at least once.");return singleton}async function newAsyncRuntime(options){return(await newQuickJSAsyncWASMModule()).newRuntime(options)}async function newAsyncContext(options){return(await newQuickJSAsyncWASMModule()).newContext(options)}async function newWorkerAsyncContext(options){let mergedOptions={poolSize:(options==null?void 0:options.poolSize)??globalWorkerConfig.poolSize,bootstrapCode:(options==null?void 0:options.bootstrapCode)??globalWorkerConfig.bootstrapCode,useSession:(options==null?void 0:options.useSession)??globalWorkerConfig.useSession,verbose:(options==null?void 0:options.verbose)??globalWorkerConfig.verbose,defaultTimeout:(options==null?void 0:options.defaultTimeout)??globalWorkerConfig.defaultTimeout,...options};return createWorkerEnabledContext(mergedOptions)}function canUseWorkers(){return isMultiThreadingSupported()}import{QuickJSWorkerPool,newWorkerPool,getWorkerPool,getWorkerPoolSync,WorkerPoolContext,newWorkerPoolContext,WorkerEnabledContext,newWorkerEnabledContext,isMultiThreadingSupported as isMultiThreadingSupported2,getDefaultPoolSize,detectPlatform,WorkerTaskTimeoutError,WorkerTaskCancelledError,WorkerCrashError,PoolDisposedError,QueueFullError,MultiThreadingNotSupportedError}from"@componentor/quickjs-emscripten-worker-pool";export{DEBUG_ASYNC,DEBUG_SYNC,MultiThreadingNotSupportedError,PoolDisposedError,QueueFullError,QuickJSWorkerPool,RELEASE_ASYNC,RELEASE_SYNC,WorkerCrashError,WorkerEnabledContext,WorkerPoolContext,WorkerTaskCancelledError,WorkerTaskTimeoutError,canUseWorkers,configureWorkerPool,detectPlatform,getDefaultPoolSize,getQuickJS,getQuickJSSync,getWorkerPool,getWorkerPoolConfig,getWorkerPoolSync,isMultiThreadingSupported2 as isMultiThreadingSupported,newAsyncContext,newAsyncRuntime,newQuickJSAsyncWASMModule,newQuickJSWASMModule,newWorkerAsyncContext,newWorkerEnabledContext,newWorkerPool,newWorkerPoolContext,resetWorkerPoolConfig};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/mod.ts"],"sourcesContent":["export * from \"@componentor/quickjs-emscripten-core\"\nexport * from \"#variants\"\nexport * from \"./mod.js\"\n","import type {\n AsyncRuntimeOptions,\n ContextOptions,\n QuickJSAsyncContext,\n QuickJSAsyncRuntime,\n QuickJSWASMModule,\n} from \"@componentor/quickjs-emscripten-core\"\nimport { newQuickJSAsyncWASMModule, newQuickJSWASMModule } from \"#variants\"\n\nlet singleton: QuickJSWASMModule | undefined = undefined\nlet singletonPromise: Promise<QuickJSWASMModule> | undefined = undefined\n\n/**\n * Get a shared singleton {@link QuickJSWASMModule}. Use this to evaluate code\n * or create Javascript environments.\n *\n * This is the top-level entrypoint for the quickjs-emscripten library.\n *\n * If you need strictest possible isolation guarantees, you may create a\n * separate {@link QuickJSWASMModule} via {@link newQuickJSWASMModule}.\n *\n * To work with the asyncified version of this library, see these functions:\n *\n * - {@link newAsyncRuntime}.\n * - {@link newAsyncContext}.\n * - {@link newQuickJSAsyncWASMModule}.\n */\nexport async function getQuickJS(): Promise<QuickJSWASMModule> {\n singletonPromise ??= newQuickJSWASMModule().then((instance) => {\n singleton = instance\n return instance\n })\n return await singletonPromise\n}\n\n/**\n * Provides synchronous access to the shared {@link QuickJSWASMModule} instance returned by {@link getQuickJS}, as long as\n * least once.\n * @throws If called before `getQuickJS` resolves.\n */\nexport function getQuickJSSync(): QuickJSWASMModule {\n if (!singleton) {\n throw new Error(\"QuickJS not initialized. Await getQuickJS() at least once.\")\n }\n return singleton\n}\n\n/**\n * Create a new {@link QuickJSAsyncRuntime} in a separate WebAssembly module.\n *\n * Each runtime is isolated in a separate WebAssembly module, so that errors in\n * one runtime cannot contaminate another runtime, and each runtime can execute\n * an asynchronous action without conflicts.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n */\nexport async function newAsyncRuntime(options?: AsyncRuntimeOptions): Promise<QuickJSAsyncRuntime> {\n const module = await newQuickJSAsyncWASMModule()\n return module.newRuntime(options)\n}\n\n/**\n * Create a new {@link QuickJSAsyncContext} (with an associated runtime) in an\n * separate WebAssembly module.\n *\n * Each context is isolated in a separate WebAssembly module, so that errors in\n * one runtime cannot contaminate another runtime, and each runtime can execute\n * an asynchronous action without conflicts.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n */\nexport async function newAsyncContext(options?: ContextOptions): Promise<QuickJSAsyncContext> {\n const module = await newQuickJSAsyncWASMModule()\n return module.newContext(options)\n}\n"],"mappings":"mIAAA,WAAc,uCCSd,IAAI,UACA,iBAiBJ,eAAsB,YAAyC,CAC7D,2CAAqB,qBAAqB,EAAE,KAAM,WAChD,UAAY,SACL,SACR,GACM,MAAM,gBACf,CAOO,SAAS,gBAAoC,CAClD,GAAI,CAAC,UACH,MAAM,IAAI,MAAM,4DAA4D,EAE9E,OAAO,SACT,CAaA,eAAsB,gBAAgB,QAA6D,CAEjG,OADe,MAAM,0BAA0B,GACjC,WAAW,OAAO,CAClC,CAcA,eAAsB,gBAAgB,QAAwD,CAE5F,OADe,MAAM,0BAA0B,GACjC,WAAW,OAAO,CAClC","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/mod.ts"],"sourcesContent":["export * from \"@componentor/quickjs-emscripten-core\"\nexport * from \"#variants\"\nexport * from \"./mod.js\"\n\n// Worker pool exports - for parallel execution across workers\nexport {\n // Main pool classes and factories\n QuickJSWorkerPool,\n newWorkerPool,\n getWorkerPool,\n getWorkerPoolSync,\n // Context wrappers\n WorkerPoolContext,\n newWorkerPoolContext,\n WorkerEnabledContext,\n newWorkerEnabledContext,\n // Capability detection\n isMultiThreadingSupported,\n getDefaultPoolSize,\n detectPlatform,\n // Errors\n WorkerTaskTimeoutError,\n WorkerTaskCancelledError,\n WorkerCrashError,\n PoolDisposedError,\n QueueFullError,\n MultiThreadingNotSupportedError,\n // Types\n type WorkerPoolOptions,\n type WorkerPoolVariant,\n type WorkerTask,\n type WorkerTaskResult,\n type WorkerTaskError,\n type TaskHandle,\n type PoolStats,\n type WorkerSession,\n type SessionEvalOptions,\n type WorkerPoolContextResult,\n type WorkerPoolEvalOptions,\n type WorkerEnabledContextOptions,\n type WorkerEnabledContextResult,\n} from \"@componentor/quickjs-emscripten-worker-pool\"\n","import type {\n AsyncRuntimeOptions,\n ContextOptions,\n QuickJSAsyncContext,\n QuickJSAsyncRuntime,\n QuickJSWASMModule,\n} from \"@componentor/quickjs-emscripten-core\"\nimport {\n newWorkerEnabledContext as createWorkerEnabledContext,\n isMultiThreadingSupported,\n type WorkerEnabledContext,\n type WorkerEnabledContextOptions,\n} from \"@componentor/quickjs-emscripten-worker-pool\"\nimport { newQuickJSAsyncWASMModule, newQuickJSWASMModule } from \"#variants\"\n\nlet singleton: QuickJSWASMModule | undefined = undefined\nlet singletonPromise: Promise<QuickJSWASMModule> | undefined = undefined\n\n// ============================================\n// Global Worker Pool Configuration\n// ============================================\n\n/**\n * Global configuration for worker pool contexts.\n * These settings are used as defaults when calling {@link newWorkerAsyncContext}.\n */\nexport interface WorkerPoolConfig {\n /**\n * Whether worker pool is enabled.\n * @default true\n */\n enabled?: boolean\n\n /**\n * Number of workers in the pool.\n * @default navigator.hardwareConcurrency or 4\n */\n poolSize?: number\n\n /**\n * Bootstrap code that runs on each worker during initialization.\n * Use this to set up shared state like mocks, utilities, etc.\n *\n * @example\n * ```typescript\n * configureWorkerPool({\n * bootstrapCode: `\n * globalThis.mockFetch = (url) => ({ status: 200, url })\n * `\n * })\n * ```\n */\n bootstrapCode?: string\n\n /**\n * Whether to use a session for state persistence.\n * - false (default): Parallel execution, each eval may hit different worker\n * - true: Sequential execution, all evals go to same worker (state persists)\n * @default false\n */\n useSession?: boolean\n\n /**\n * Enable verbose logging for debugging.\n * @default false\n */\n verbose?: boolean\n\n /**\n * Default timeout for code execution in milliseconds.\n * @default 0 (no timeout)\n */\n defaultTimeout?: number\n}\n\n// Global worker pool configuration\nlet globalWorkerConfig: WorkerPoolConfig = {\n enabled: true, // Auto-use workers by default\n}\n\n/**\n * Configure the global worker pool settings.\n *\n * Call this before creating worker contexts to set up default worker pool options.\n * These settings are used as defaults when calling {@link newWorkerAsyncContext}.\n *\n * @example\n * ```typescript\n * import { configureWorkerPool, newWorkerAsyncContext } from \"@componentor/quickjs-emscripten\"\n *\n * // Configure once at startup\n * configureWorkerPool({\n * poolSize: 4,\n * bootstrapCode: `\n * globalThis.mockFetch = (url) => ({ status: 200, url })\n * `\n * })\n *\n * // Create worker context - uses global config!\n * const ctx = await newWorkerAsyncContext()\n *\n * // Parallel execution across workers\n * const results = await Promise.all([\n * ctx.evalCodeAsync('mockFetch(\"/api/1\")'),\n * ctx.evalCodeAsync('mockFetch(\"/api/2\")'),\n * ctx.evalCodeAsync('mockFetch(\"/api/3\")'),\n * ])\n * ```\n */\nexport function configureWorkerPool(config: WorkerPoolConfig): void {\n globalWorkerConfig = { ...globalWorkerConfig, ...config }\n}\n\n/**\n * Get the current global worker pool configuration.\n */\nexport function getWorkerPoolConfig(): WorkerPoolConfig {\n return { ...globalWorkerConfig }\n}\n\n/**\n * Reset the global worker pool configuration to defaults.\n */\nexport function resetWorkerPoolConfig(): void {\n globalWorkerConfig = { enabled: true }\n}\n\n// ============================================\n// Core QuickJS Functions\n// ============================================\n\n/**\n * Get a shared singleton {@link QuickJSWASMModule}. Use this to evaluate code\n * or create Javascript environments.\n *\n * This is the top-level entrypoint for the quickjs-emscripten library.\n *\n * If you need strictest possible isolation guarantees, you may create a\n * separate {@link QuickJSWASMModule} via {@link newQuickJSWASMModule}.\n *\n * To work with the asyncified version of this library, see these functions:\n *\n * - {@link newAsyncRuntime}.\n * - {@link newAsyncContext}.\n * - {@link newQuickJSAsyncWASMModule}.\n */\nexport async function getQuickJS(): Promise<QuickJSWASMModule> {\n singletonPromise ??= newQuickJSWASMModule().then((instance) => {\n singleton = instance\n return instance\n })\n return await singletonPromise\n}\n\n/**\n * Provides synchronous access to the shared {@link QuickJSWASMModule} instance returned by {@link getQuickJS}, as long as\n * least once.\n * @throws If called before `getQuickJS` resolves.\n */\nexport function getQuickJSSync(): QuickJSWASMModule {\n if (!singleton) {\n throw new Error(\"QuickJS not initialized. Await getQuickJS() at least once.\")\n }\n return singleton\n}\n\n/**\n * Create a new {@link QuickJSAsyncRuntime} in a separate WebAssembly module.\n *\n * Each runtime is isolated in a separate WebAssembly module, so that errors in\n * one runtime cannot contaminate another runtime, and each runtime can execute\n * an asynchronous action without conflicts.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n */\nexport async function newAsyncRuntime(options?: AsyncRuntimeOptions): Promise<QuickJSAsyncRuntime> {\n const module = await newQuickJSAsyncWASMModule()\n return module.newRuntime(options)\n}\n\n/**\n * Create a new {@link QuickJSAsyncContext} in a separate WebAssembly module.\n *\n * Each context is isolated in a separate WebAssembly module, so that errors in\n * one runtime cannot contaminate another runtime, and each runtime can execute\n * an asynchronous action without conflicts.\n *\n * Note that there is a hard limit on the number of WebAssembly modules in older\n * versions of v8:\n * https://bugs.chromium.org/p/v8/issues/detail?id=12076\n *\n * For parallel execution across workers, use {@link newWorkerAsyncContext} instead.\n */\nexport async function newAsyncContext(options?: ContextOptions): Promise<QuickJSAsyncContext> {\n const module = await newQuickJSAsyncWASMModule()\n return module.newContext(options)\n}\n\n// ============================================\n// Worker Pool Helpers\n// ============================================\n\n/**\n * Options for creating a worker-enabled async context.\n */\nexport interface WorkerAsyncContextOptions extends WorkerEnabledContextOptions {\n /**\n * Context options for the local QuickJS context.\n */\n contextOptions?: ContextOptions\n}\n\n/**\n * Create a new {@link WorkerEnabledContext} for parallel execution across workers.\n *\n * This is the recommended way to use QuickJS with parallel execution. Each\n * `evalCodeAsync` call can be distributed to different workers for parallelism.\n *\n * Uses global config from {@link configureWorkerPool} as defaults, which can\n * be overridden by passing options.\n *\n * @example\n * ```typescript\n * // Simple usage with defaults\n * const ctx = await newWorkerAsyncContext()\n *\n * // Parallel execution\n * const results = await Promise.all([\n * ctx.evalCodeAsync('1 + 1'),\n * ctx.evalCodeAsync('2 + 2'),\n * ctx.evalCodeAsync('3 + 3'),\n * ])\n * ```\n *\n * @example\n * ```typescript\n * // With bootstrap code for mocks\n * const ctx = await newWorkerAsyncContext({\n * poolSize: 8,\n * bootstrapCode: `\n * globalThis.mockFetch = (url) => ({ status: 200, url })\n * `,\n * })\n * ```\n *\n * @param options Worker pool and context options (overrides global config)\n * @returns A new WorkerEnabledContext instance\n */\nexport async function newWorkerAsyncContext(\n options?: WorkerAsyncContextOptions,\n): Promise<WorkerEnabledContext> {\n // Merge global config with provided options\n const mergedOptions: WorkerAsyncContextOptions = {\n poolSize: options?.poolSize ?? globalWorkerConfig.poolSize,\n bootstrapCode: options?.bootstrapCode ?? globalWorkerConfig.bootstrapCode,\n useSession: options?.useSession ?? globalWorkerConfig.useSession,\n verbose: options?.verbose ?? globalWorkerConfig.verbose,\n defaultTimeout: options?.defaultTimeout ?? globalWorkerConfig.defaultTimeout,\n ...options,\n }\n return createWorkerEnabledContext(mergedOptions)\n}\n\n/**\n * Check if multi-threading is supported in the current environment.\n *\n * Returns true if SharedArrayBuffer is available (required for Web Workers\n * to share memory). In browsers, this requires COOP/COEP headers to be set.\n * In Node.js, this is typically always available.\n *\n * @example\n * ```typescript\n * if (canUseWorkers()) {\n * console.log('Parallel execution available!')\n * } else {\n * console.log('Falling back to single-threaded execution')\n * }\n * ```\n */\nexport function canUseWorkers(): boolean {\n return isMultiThreadingSupported()\n}\n"],"mappings":"mIAAA,WAAc,uCCOd,OACE,2BAA2B,2BAC3B,8BAGK,8CAGP,IAAI,UACA,iBA4DA,mBAAuC,CACzC,QAAS,EACX,EA+BO,SAAS,oBAAoB,OAAgC,CAClE,mBAAqB,CAAE,GAAG,mBAAoB,GAAG,MAAO,CAC1D,CAKO,SAAS,qBAAwC,CACtD,MAAO,CAAE,GAAG,kBAAmB,CACjC,CAKO,SAAS,uBAA8B,CAC5C,mBAAqB,CAAE,QAAS,EAAK,CACvC,CAqBA,eAAsB,YAAyC,CAC7D,2CAAqB,qBAAqB,EAAE,KAAM,WAChD,UAAY,SACL,SACR,GACM,MAAM,gBACf,CAOO,SAAS,gBAAoC,CAClD,GAAI,CAAC,UACH,MAAM,IAAI,MAAM,4DAA4D,EAE9E,OAAO,SACT,CAaA,eAAsB,gBAAgB,QAA6D,CAEjG,OADe,MAAM,0BAA0B,GACjC,WAAW,OAAO,CAClC,CAeA,eAAsB,gBAAgB,QAAwD,CAE5F,OADe,MAAM,0BAA0B,GACjC,WAAW,OAAO,CAClC,CAoDA,eAAsB,sBACpB,QAC+B,CAE/B,IAAM,cAA2C,CAC/C,UAAU,6BAAS,WAAY,mBAAmB,SAClD,eAAe,6BAAS,gBAAiB,mBAAmB,cAC5D,YAAY,6BAAS,aAAc,mBAAmB,WACtD,SAAS,6BAAS,UAAW,mBAAmB,QAChD,gBAAgB,6BAAS,iBAAkB,mBAAmB,eAC9D,GAAG,OACL,EACA,OAAO,2BAA2B,aAAa,CACjD,CAkBO,SAAS,eAAyB,CACvC,OAAO,0BAA0B,CACnC,CDtRA,OAEE,kBACA,cACA,cACA,kBAEA,kBACA,qBACA,qBACA,wBAEA,6BAAAA,2BACA,mBACA,eAEA,uBACA,yBACA,iBACA,kBACA,eACA,oCAeK","names":["isMultiThreadingSupported"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@componentor/quickjs-emscripten",
3
- "version": "0.31.26",
3
+ "version": "0.31.28",
4
4
  "sideEffects": false,
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -44,29 +44,30 @@
44
44
  "./package.json": "./package.json"
45
45
  },
46
46
  "dependencies": {
47
- "@componentor/quickjs-wasmfs-release-sync": "0.31.26",
48
- "@componentor/quickjs-wasmfile-debug-asyncify": "0.31.26",
49
- "@componentor/quickjs-wasmfile-debug-sync": "0.31.26",
50
- "@componentor/quickjs-emscripten-core": "0.31.26",
51
- "@componentor/quickjs-wasmfile-release-sync": "0.31.26",
52
- "@componentor/quickjs-wasmfile-release-asyncify": "0.31.26"
47
+ "@componentor/quickjs-wasmfile-release-asyncify": "0.31.28",
48
+ "@componentor/quickjs-wasmfile-debug-asyncify": "0.31.28",
49
+ "@componentor/quickjs-emscripten-worker-pool": "0.31.28",
50
+ "@componentor/quickjs-wasmfile-debug-sync": "0.31.28",
51
+ "@componentor/quickjs-wasmfs-release-sync": "0.31.28",
52
+ "@componentor/quickjs-emscripten-core": "0.31.28",
53
+ "@componentor/quickjs-wasmfile-release-sync": "0.31.28"
53
54
  },
54
55
  "devDependencies": {
55
- "@componentor/quickjs-ffi-types": "0.31.26",
56
- "@componentor/quickjs-asmjs-mjs-release-sync": "0.31.26",
57
- "@componentor/quickjs-ng-wasmfile-debug-sync": "0.31.26",
58
- "@componentor/quickjs-ng-wasmfile-debug-asyncify": "0.31.26",
59
- "@componentor/quickjs-ng-wasmfile-release-sync": "0.31.26",
60
- "@componentor/quickjs-ng-wasmfile-release-asyncify": "0.31.26",
61
- "@componentor/quickjs-singlefile-cjs-debug-asyncify": "0.31.26",
62
- "@componentor/quickjs-singlefile-cjs-debug-sync": "0.31.26",
63
- "@componentor/quickjs-singlefile-cjs-release-asyncify": "0.31.26",
64
- "@componentor/quickjs-singlefile-cjs-release-sync": "0.31.26",
65
- "@jitl/tsconfig": "0.31.26",
66
- "@componentor/quickjs-singlefile-mjs-debug-sync": "0.31.26",
67
- "@componentor/quickjs-singlefile-mjs-debug-asyncify": "0.31.26",
68
- "@componentor/quickjs-singlefile-mjs-release-asyncify": "0.31.26",
69
- "@componentor/quickjs-singlefile-mjs-release-sync": "0.31.26"
56
+ "@componentor/quickjs-ffi-types": "0.31.28",
57
+ "@componentor/quickjs-asmjs-mjs-release-sync": "0.31.28",
58
+ "@componentor/quickjs-ng-wasmfile-debug-sync": "0.31.28",
59
+ "@componentor/quickjs-ng-wasmfile-debug-asyncify": "0.31.28",
60
+ "@componentor/quickjs-ng-wasmfile-release-asyncify": "0.31.28",
61
+ "@componentor/quickjs-singlefile-cjs-debug-sync": "0.31.28",
62
+ "@componentor/quickjs-singlefile-cjs-debug-asyncify": "0.31.28",
63
+ "@componentor/quickjs-singlefile-cjs-release-asyncify": "0.31.28",
64
+ "@componentor/quickjs-singlefile-cjs-release-sync": "0.31.28",
65
+ "@componentor/quickjs-ng-wasmfile-release-sync": "0.31.28",
66
+ "@componentor/quickjs-singlefile-mjs-debug-sync": "0.31.28",
67
+ "@jitl/tsconfig": "0.31.28",
68
+ "@componentor/quickjs-singlefile-mjs-debug-asyncify": "0.31.28",
69
+ "@componentor/quickjs-singlefile-mjs-release-asyncify": "0.31.28",
70
+ "@componentor/quickjs-singlefile-mjs-release-sync": "0.31.28"
70
71
  },
71
72
  "engines": {
72
73
  "node": ">=16.0.0"