@ricsam/quickjs-core 0.2.0 → 0.2.2

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 (63) hide show
  1. package/dist/cjs/blob.cjs +197 -0
  2. package/dist/cjs/blob.cjs.map +10 -0
  3. package/dist/cjs/class-builder.cjs +244 -0
  4. package/dist/cjs/class-builder.cjs.map +10 -0
  5. package/dist/cjs/dom-exception.cjs +95 -0
  6. package/dist/cjs/dom-exception.cjs.map +10 -0
  7. package/dist/cjs/file.cjs +234 -0
  8. package/dist/cjs/file.cjs.map +10 -0
  9. package/dist/cjs/function-builder.cjs +70 -0
  10. package/dist/cjs/function-builder.cjs.map +10 -0
  11. package/dist/cjs/index.cjs +22 -22
  12. package/dist/cjs/index.cjs.map +2 -2
  13. package/dist/cjs/marshal.cjs +191 -0
  14. package/dist/cjs/marshal.cjs.map +10 -0
  15. package/dist/cjs/package.json +1 -1
  16. package/dist/cjs/readable-stream.cjs +588 -0
  17. package/dist/cjs/readable-stream.cjs.map +10 -0
  18. package/dist/cjs/scope.cjs +76 -0
  19. package/dist/cjs/scope.cjs.map +10 -0
  20. package/dist/cjs/transform-stream.cjs +152 -0
  21. package/dist/cjs/transform-stream.cjs.map +10 -0
  22. package/dist/cjs/types.cjs +39 -0
  23. package/dist/cjs/types.cjs.map +10 -0
  24. package/dist/cjs/unmarshal.cjs +254 -0
  25. package/dist/cjs/unmarshal.cjs.map +10 -0
  26. package/dist/cjs/url-search-params.cjs +165 -0
  27. package/dist/cjs/url-search-params.cjs.map +10 -0
  28. package/dist/cjs/url.cjs +183 -0
  29. package/dist/cjs/url.cjs.map +10 -0
  30. package/dist/cjs/writable-stream.cjs +513 -0
  31. package/dist/cjs/writable-stream.cjs.map +10 -0
  32. package/dist/mjs/blob.mjs +166 -0
  33. package/dist/mjs/blob.mjs.map +10 -0
  34. package/dist/mjs/class-builder.mjs +213 -0
  35. package/dist/mjs/class-builder.mjs.map +10 -0
  36. package/dist/mjs/dom-exception.mjs +64 -0
  37. package/dist/mjs/dom-exception.mjs.map +10 -0
  38. package/dist/mjs/file.mjs +203 -0
  39. package/dist/mjs/file.mjs.map +10 -0
  40. package/dist/mjs/function-builder.mjs +39 -0
  41. package/dist/mjs/function-builder.mjs.map +10 -0
  42. package/dist/mjs/index.mjs +22 -22
  43. package/dist/mjs/index.mjs.map +2 -2
  44. package/dist/mjs/marshal.mjs +160 -0
  45. package/dist/mjs/marshal.mjs.map +10 -0
  46. package/dist/mjs/package.json +1 -1
  47. package/dist/mjs/readable-stream.mjs +557 -0
  48. package/dist/mjs/readable-stream.mjs.map +10 -0
  49. package/dist/mjs/scope.mjs +45 -0
  50. package/dist/mjs/scope.mjs.map +10 -0
  51. package/dist/mjs/transform-stream.mjs +121 -0
  52. package/dist/mjs/transform-stream.mjs.map +10 -0
  53. package/dist/mjs/types.mjs +8 -0
  54. package/dist/mjs/types.mjs.map +10 -0
  55. package/dist/mjs/unmarshal.mjs +223 -0
  56. package/dist/mjs/unmarshal.mjs.map +10 -0
  57. package/dist/mjs/url-search-params.mjs +134 -0
  58. package/dist/mjs/url-search-params.mjs.map +10 -0
  59. package/dist/mjs/url.mjs +152 -0
  60. package/dist/mjs/url.mjs.map +10 -0
  61. package/dist/mjs/writable-stream.mjs +482 -0
  62. package/dist/mjs/writable-stream.mjs.map +10 -0
  63. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/streams/readable-stream.ts"],
4
+ "sourcesContent": [
5
+ "import type { QuickJSContext, QuickJSHandle } from \"quickjs-emscripten\";\nimport type { StateMap } from \"../types.cjs\";\nimport { defineClass, getState, getInstanceStateById } from \"../class-builder.cjs\";\nimport { marshal } from \"../marshal.cjs\";\nimport { unmarshal } from \"../unmarshal.cjs\";\n\ninterface ReadableStreamController {\n enqueue(chunk: unknown): void;\n close(): void;\n error(e: unknown): void;\n desiredSize: number | null;\n}\n\ninterface ReadableStreamInternalState {\n locked: boolean;\n controller: ReadableStreamController;\n reader: ReadableStreamReaderState | null;\n queue: unknown[];\n closeRequested: boolean;\n closed: boolean;\n errored: boolean;\n errorValue: unknown;\n pullPromise: { resolve: () => void; reject: (e: unknown) => void } | null;\n started: boolean;\n source?: {\n start?: (controller: ReadableStreamController) => void | Promise<void>;\n pull?: (controller: ReadableStreamController) => void | Promise<void>;\n cancel?: (reason?: unknown) => void | Promise<void>;\n };\n}\n\ninterface ReadableStreamReaderState {\n stream: ReadableStreamInternalState;\n closed: boolean;\n closedPromiseResolvers: {\n resolve: () => void;\n reject: (e: unknown) => void;\n };\n _closedPromise?: Promise<void>; // Lazy-created to avoid marshalling issues\n readRequests: Array<{\n resolve: (result: { value: unknown; done: boolean }) => void;\n reject: (e: unknown) => void;\n }>;\n}\n\n/**\n * Create the ReadableStreamDefaultReader class\n */\nexport function createReadableStreamDefaultReaderClass(\n context: QuickJSContext,\n stateMap: StateMap\n): QuickJSHandle {\n return defineClass<ReadableStreamReaderState>(context, stateMap, {\n name: \"ReadableStreamDefaultReader\",\n construct: () => {\n // Note: Actual construction happens when getReader() is called\n // Promise is created lazily to avoid marshalling issues with handle cleanup\n let resolveClosedPromise: (() => void) | undefined;\n let rejectClosedPromise: ((e: unknown) => void) | undefined;\n\n const state: ReadableStreamReaderState = {\n stream: null as unknown as ReadableStreamInternalState,\n closed: false,\n closedPromiseResolvers: {\n resolve: () => resolveClosedPromise?.(),\n reject: (e) => rejectClosedPromise?.(e),\n },\n readRequests: [],\n };\n\n // Define _closedPromise as a lazy getter (won't be marshalled until accessed)\n Object.defineProperty(state, \"_closedPromise\", {\n value: undefined,\n writable: true,\n enumerable: false, // Don't include in marshalling\n });\n\n // Create promise accessor\n Object.defineProperty(state, \"getClosedPromise\", {\n value: function (this: ReadableStreamReaderState): Promise<void> {\n if (!this._closedPromise) {\n this._closedPromise = new Promise<void>((resolve, reject) => {\n resolveClosedPromise = resolve;\n rejectClosedPromise = reject;\n });\n }\n return this._closedPromise;\n },\n enumerable: false,\n });\n\n return state;\n },\n properties: {\n closed: {\n get(this: ReadableStreamReaderState) {\n // Use the lazy promise accessor\n return (this as unknown as { getClosedPromise: () => Promise<void> }).getClosedPromise();\n },\n },\n },\n methods: {\n read(this: ReadableStreamReaderState): Promise<{ value: unknown; done: boolean }> {\n if (!this.stream) {\n return Promise.reject(new TypeError(\"Reader has no stream\"));\n }\n if (this.stream.locked === false) {\n return Promise.reject(new TypeError(\"Stream is not locked\"));\n }\n\n return new Promise((resolve, reject) => {\n // If there's something in the queue, return it\n if (this.stream.queue.length > 0) {\n const chunk = this.stream.queue.shift();\n resolve({ value: chunk, done: false });\n return;\n }\n\n // If stream is closed, return done\n if (this.stream.closed || this.stream.closeRequested) {\n resolve({ value: undefined, done: true });\n this.closedPromiseResolvers.resolve();\n return;\n }\n\n // If stream errored, reject\n if (this.stream.errored) {\n reject(this.stream.errorValue);\n return;\n }\n\n // Otherwise, queue the read request\n this.readRequests.push({ resolve, reject });\n\n // Try to pull more data\n if (this.stream.source?.pull && this.stream.started) {\n try {\n const pullResult = this.stream.source.pull(this.stream.controller);\n if (pullResult instanceof Promise) {\n pullResult.catch((e) => {\n this.stream.errored = true;\n this.stream.errorValue = e;\n this.readRequests.forEach((req) => req.reject(e));\n this.readRequests = [];\n });\n }\n } catch (e) {\n this.stream.errored = true;\n this.stream.errorValue = e;\n reject(e);\n }\n }\n });\n },\n cancel(this: ReadableStreamReaderState, reason?: unknown): Promise<void> {\n if (!this.stream) {\n return Promise.reject(new TypeError(\"Reader has no stream\"));\n }\n\n return new Promise((resolve, reject) => {\n try {\n if (this.stream.source?.cancel) {\n const result = this.stream.source.cancel(reason);\n if (result instanceof Promise) {\n result.then(resolve).catch(reject);\n return;\n }\n }\n this.stream.closed = true;\n this.closedPromiseResolvers.resolve();\n resolve();\n } catch (e) {\n reject(e);\n }\n });\n },\n releaseLock(this: ReadableStreamReaderState): void {\n if (!this.stream) {\n return;\n }\n this.stream.locked = false;\n this.stream.reader = null;\n },\n },\n });\n}\n\n/**\n * Create the ReadableStream class\n */\nexport function createReadableStreamClass(\n context: QuickJSContext,\n stateMap: StateMap,\n readerClass: QuickJSHandle\n): QuickJSHandle {\n const classHandle = defineClass<ReadableStreamInternalState>(context, stateMap, {\n name: \"ReadableStream\",\n construct: (args) => {\n const underlyingSource = args[0] as {\n start?: (controller: ReadableStreamController) => void | Promise<void>;\n pull?: (controller: ReadableStreamController) => void | Promise<void>;\n cancel?: (reason?: unknown) => void | Promise<void>;\n } | undefined;\n\n const state: ReadableStreamInternalState = {\n locked: false,\n controller: null as unknown as ReadableStreamController,\n reader: null,\n queue: [],\n closeRequested: false,\n closed: false,\n errored: false,\n errorValue: undefined,\n pullPromise: null,\n started: false,\n source: underlyingSource,\n };\n\n // Create controller\n state.controller = {\n enqueue(chunk: unknown) {\n if (state.closeRequested || state.closed) {\n throw new TypeError(\"Stream is closed\");\n }\n state.queue.push(chunk);\n\n // If there are pending read requests, fulfill them\n if (state.reader && state.reader.readRequests.length > 0) {\n const request = state.reader.readRequests.shift()!;\n const value = state.queue.shift();\n request.resolve({ value, done: false });\n }\n },\n close() {\n if (state.closeRequested || state.closed) {\n return;\n }\n state.closeRequested = true;\n\n if (state.queue.length === 0) {\n state.closed = true;\n if (state.reader) {\n state.reader.closedPromiseResolvers.resolve();\n // Resolve any pending reads with done: true\n state.reader.readRequests.forEach((req) => {\n req.resolve({ value: undefined, done: true });\n });\n state.reader.readRequests = [];\n }\n }\n },\n error(e: unknown) {\n if (state.errored || state.closed) {\n return;\n }\n state.errored = true;\n state.errorValue = e;\n\n if (state.reader) {\n state.reader.closedPromiseResolvers.reject(e);\n state.reader.readRequests.forEach((req) => req.reject(e));\n state.reader.readRequests = [];\n }\n },\n get desiredSize() {\n if (state.errored) return null;\n if (state.closeRequested) return 0;\n return 1 - state.queue.length;\n },\n };\n\n // Call start if provided\n if (underlyingSource?.start) {\n try {\n const startResult = underlyingSource.start(state.controller);\n if (startResult instanceof Promise) {\n startResult\n .then(() => {\n state.started = true;\n })\n .catch((e) => {\n state.errored = true;\n state.errorValue = e;\n });\n } else {\n state.started = true;\n }\n } catch (e) {\n state.errored = true;\n state.errorValue = e;\n }\n } else {\n state.started = true;\n }\n\n return state;\n },\n properties: {\n locked: {\n get(this: ReadableStreamInternalState) {\n return this.locked;\n },\n },\n },\n methods: {\n // __linkReader__ is called from JavaScript getReader() to link stream and reader states\n __linkReader__(this: ReadableStreamInternalState, readerObj: unknown): void {\n if (this.locked) {\n throw new TypeError(\"ReadableStream is locked\");\n }\n this.locked = true;\n\n // Get the reader's internal state from instanceStateMap\n const readerId = (readerObj as { __instanceId__: number }).__instanceId__;\n const readerState = getInstanceStateById<ReadableStreamReaderState>(readerId);\n if (!readerState) {\n throw new Error(\"Reader instance state not found\");\n }\n\n // Link bidirectionally\n readerState.stream = this;\n this.reader = readerState;\n },\n cancel(this: ReadableStreamInternalState, reason?: unknown): Promise<void> {\n if (this.locked) {\n return Promise.reject(new TypeError(\"Cannot cancel a locked stream\"));\n }\n\n return new Promise((resolve, reject) => {\n try {\n if (this.source?.cancel) {\n const result = this.source.cancel(reason);\n if (result instanceof Promise) {\n result.then(resolve).catch(reject);\n return;\n }\n }\n this.closed = true;\n resolve();\n } catch (e) {\n reject(e);\n }\n });\n },\n // Note: pipeTo, pipeThrough, and tee are implemented as JavaScript code below\n },\n });\n\n // Add methods to the prototype that need to be JavaScript code\n // (because they need to create instances of other classes or call methods on them)\n const prototypeHandle = context.getProp(classHandle, \"prototype\");\n\n // Define getReader - must be JavaScript to return a ReadableStreamDefaultReader instance\n const getReaderCode = `(function() {\n // Create a reader instance\n const reader = new ReadableStreamDefaultReader();\n // Link it to this stream's internal state\n this.__linkReader__(reader);\n return reader;\n })`;\n const getReaderResult = context.evalCode(getReaderCode);\n if (!getReaderResult.error) {\n context.setProp(prototypeHandle, \"getReader\", getReaderResult.value);\n getReaderResult.value.dispose();\n } else {\n getReaderResult.error.dispose();\n }\n\n // Define pipeTo\n const pipeToCode = `(async function(destination, options = {}) {\n if (this.locked) throw new TypeError(\"ReadableStream is locked\");\n if (destination.locked) throw new TypeError(\"WritableStream is locked\");\n\n const reader = this.getReader();\n const writer = destination.getWriter();\n\n try {\n while (true) {\n const { value, done } = await reader.read();\n if (done) break;\n await writer.write(value);\n }\n if (!options.preventClose) await writer.close();\n } catch (error) {\n if (!options.preventAbort) await writer.abort(error);\n if (!options.preventCancel) await reader.cancel(error);\n throw error;\n } finally {\n reader.releaseLock();\n writer.releaseLock();\n }\n })`;\n const pipeToResult = context.evalCode(pipeToCode);\n if (!pipeToResult.error) {\n context.setProp(prototypeHandle, \"pipeTo\", pipeToResult.value);\n pipeToResult.value.dispose();\n } else {\n pipeToResult.error.dispose();\n }\n\n // Define pipeThrough\n const pipeThroughCode = `(function(transform, options = {}) {\n if (this.locked) throw new TypeError(\"ReadableStream is locked\");\n if (transform.writable.locked) throw new TypeError(\"WritableStream is locked\");\n\n // Start piping in background\n this.pipeTo(transform.writable, {\n preventClose: options.preventClose,\n preventAbort: options.preventAbort,\n preventCancel: options.preventCancel,\n signal: options.signal\n }).catch(() => {}); // Errors handled internally\n\n return transform.readable;\n })`;\n const pipeThroughResult = context.evalCode(pipeThroughCode);\n if (!pipeThroughResult.error) {\n context.setProp(prototypeHandle, \"pipeThrough\", pipeThroughResult.value);\n pipeThroughResult.value.dispose();\n } else {\n pipeThroughResult.error.dispose();\n }\n\n // Define tee - uses a closure that references ReadableStream, so we need to set it after global registration\n // For now, we'll set it on the prototype but the inner ReadableStream references will need to be resolved at runtime\n const teeCode = `(function() {\n if (this.locked) throw new TypeError(\"ReadableStream is locked\");\n\n const reader = this.getReader();\n let reading = false;\n let readAgain = false;\n let canceled1 = false, canceled2 = false;\n let reason1, reason2;\n let branch1Controller, branch2Controller;\n\n function pullAlgorithm() {\n if (reading) {\n readAgain = true;\n return Promise.resolve();\n }\n reading = true;\n\n return reader.read().then(({ value, done }) => {\n reading = false;\n if (done) {\n if (!canceled1 && branch1Controller) branch1Controller.close();\n if (!canceled2 && branch2Controller) branch2Controller.close();\n return;\n }\n if (!canceled1 && branch1Controller) branch1Controller.enqueue(value);\n if (!canceled2 && branch2Controller) branch2Controller.enqueue(value);\n if (readAgain) {\n readAgain = false;\n return pullAlgorithm();\n }\n });\n }\n\n const branch1 = new ReadableStream({\n start(controller) { branch1Controller = controller; },\n pull: pullAlgorithm,\n cancel(reason) {\n canceled1 = true;\n reason1 = reason;\n if (canceled2) reader.cancel(reason1);\n }\n });\n\n const branch2 = new ReadableStream({\n start(controller) { branch2Controller = controller; },\n pull: pullAlgorithm,\n cancel(reason) {\n canceled2 = true;\n reason2 = reason;\n if (canceled1) reader.cancel(reason2);\n }\n });\n\n return [branch1, branch2];\n })`;\n const teeResult = context.evalCode(teeCode);\n if (!teeResult.error) {\n context.setProp(prototypeHandle, \"tee\", teeResult.value);\n teeResult.value.dispose();\n } else {\n teeResult.error.dispose();\n }\n\n prototypeHandle.dispose();\n\n return classHandle;\n}\n\n/**\n * Create a ReadableStream in QuickJS from a host-side source\n */\nexport function createReadableStream(\n context: QuickJSContext,\n stateMap: StateMap,\n source: UnderlyingSource\n): QuickJSHandle {\n // Create the source object with callbacks that will work in QuickJS\n const sourceObj = context.newObject();\n\n if (source.start) {\n const startFn = context.newFunction(\"start\", (controllerHandle) => {\n const controller = {\n enqueue: (chunk: unknown) => {\n const enqueueFn = context.getProp(controllerHandle, \"enqueue\");\n const chunkHandle = marshal(context, chunk);\n context.callFunction(enqueueFn, controllerHandle, chunkHandle);\n chunkHandle.dispose();\n enqueueFn.dispose();\n },\n close: () => {\n const closeFn = context.getProp(controllerHandle, \"close\");\n context.callFunction(closeFn, controllerHandle);\n closeFn.dispose();\n },\n error: (e: unknown) => {\n const errorFn = context.getProp(controllerHandle, \"error\");\n const errorHandle = marshal(context, e);\n context.callFunction(errorFn, controllerHandle, errorHandle);\n errorHandle.dispose();\n errorFn.dispose();\n },\n };\n\n const result = source.start!(controller as unknown as ReadableStreamController);\n if (result instanceof Promise) {\n const deferred = context.newPromise();\n result.then(() => {\n deferred.resolve(context.undefined);\n context.runtime.executePendingJobs();\n }).catch((e) => {\n deferred.reject(marshal(context, e));\n context.runtime.executePendingJobs();\n });\n return deferred.handle;\n }\n return context.undefined;\n });\n context.setProp(sourceObj, \"start\", startFn);\n startFn.dispose();\n }\n\n if (source.pull) {\n const pullFn = context.newFunction(\"pull\", (controllerHandle) => {\n const controller = {\n enqueue: (chunk: unknown) => {\n const enqueueFn = context.getProp(controllerHandle, \"enqueue\");\n const chunkHandle = marshal(context, chunk);\n context.callFunction(enqueueFn, controllerHandle, chunkHandle);\n chunkHandle.dispose();\n enqueueFn.dispose();\n },\n close: () => {\n const closeFn = context.getProp(controllerHandle, \"close\");\n context.callFunction(closeFn, controllerHandle);\n closeFn.dispose();\n },\n error: (e: unknown) => {\n const errorFn = context.getProp(controllerHandle, \"error\");\n const errorHandle = marshal(context, e);\n context.callFunction(errorFn, controllerHandle, errorHandle);\n errorHandle.dispose();\n errorFn.dispose();\n },\n };\n\n const result = source.pull!(controller as unknown as ReadableStreamController);\n if (result instanceof Promise) {\n const deferred = context.newPromise();\n result.then(() => {\n deferred.resolve(context.undefined);\n context.runtime.executePendingJobs();\n }).catch((e) => {\n deferred.reject(marshal(context, e));\n context.runtime.executePendingJobs();\n });\n return deferred.handle;\n }\n return context.undefined;\n });\n context.setProp(sourceObj, \"pull\", pullFn);\n pullFn.dispose();\n }\n\n if (source.cancel) {\n const cancelFn = context.newFunction(\"cancel\", (reasonHandle) => {\n const reason = unmarshal(context, reasonHandle);\n const result = source.cancel!(reason);\n if (result instanceof Promise) {\n const deferred = context.newPromise();\n result.then(() => {\n deferred.resolve(context.undefined);\n context.runtime.executePendingJobs();\n }).catch((e) => {\n deferred.reject(marshal(context, e));\n context.runtime.executePendingJobs();\n });\n return deferred.handle;\n }\n return context.undefined;\n });\n context.setProp(sourceObj, \"cancel\", cancelFn);\n cancelFn.dispose();\n }\n\n // Create ReadableStream instance using evalCode to ensure 'new' is used\n // Store source on global temporarily\n context.setProp(context.global, \"__tempReadableStreamSource__\", sourceObj);\n sourceObj.dispose();\n\n // Create the stream and store source reference on it to prevent GC\n // The source object needs to stay alive because the host-side unmarshaled\n // functions hold references to QuickJS handles that would be GCed otherwise\n const result = context.evalCode(`\n (function() {\n const stream = new ReadableStream(__tempReadableStreamSource__);\n stream.__source__ = __tempReadableStreamSource__;\n return stream;\n })()\n `);\n\n // Clean up temp property\n const cleanupResult = context.evalCode(\"delete __tempReadableStreamSource__\");\n if (cleanupResult.error) cleanupResult.error.dispose();\n else cleanupResult.value.dispose();\n\n if (result.error) {\n const msgHandle = context.getProp(result.error, \"message\");\n const errorMsg = context.dump(msgHandle);\n msgHandle.dispose();\n result.error.dispose();\n throw new Error(`Failed to create ReadableStream: ${errorMsg}`);\n }\n\n return result.value;\n}\n\n/**\n * Consume a ReadableStream from QuickJS in the host\n */\nexport async function* consumeReadableStream(\n context: QuickJSContext,\n stateMap: StateMap,\n streamHandle: QuickJSHandle\n): AsyncIterable<unknown> {\n // Get reader\n const getReaderFn = context.getProp(streamHandle, \"getReader\");\n const readerResult = context.callFunction(getReaderFn, streamHandle);\n getReaderFn.dispose();\n\n if (readerResult.error) {\n const error = context.dump(readerResult.error);\n readerResult.error.dispose();\n throw new Error(`Failed to get reader: ${error}`);\n }\n\n const reader = readerResult.value;\n\n try {\n while (true) {\n const readFn = context.getProp(reader, \"read\");\n const readResult = context.callFunction(readFn, reader);\n readFn.dispose();\n\n if (readResult.error) {\n const error = context.dump(readResult.error);\n readResult.error.dispose();\n throw new Error(`Read failed: ${error}`);\n }\n\n // Handle promise\n const resolved = await context.resolvePromise(readResult.value);\n readResult.value.dispose();\n context.runtime.executePendingJobs();\n\n if (resolved.error) {\n const error = context.dump(resolved.error);\n resolved.error.dispose();\n throw new Error(`Read failed: ${error}`);\n }\n\n const result = unmarshal(context, resolved.value) as { value: unknown; done: boolean };\n resolved.value.dispose();\n\n if (result.done) {\n break;\n }\n\n yield result.value;\n }\n } finally {\n const releaseLockFn = context.getProp(reader, \"releaseLock\");\n context.callFunction(releaseLockFn, reader);\n releaseLockFn.dispose();\n reader.dispose();\n }\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE4D,IAA5D;AACwB,IAAxB;AAC0B,IAA1B;AA4CO,SAAS,sCAAsC,CACpD,SACA,UACe;AAAA,EACf,OAAO,iCAAuC,SAAS,UAAU;AAAA,IAC/D,MAAM;AAAA,IACN,WAAW,MAAM;AAAA,MAGf,IAAI;AAAA,MACJ,IAAI;AAAA,MAEJ,MAAM,QAAmC;AAAA,QACvC,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,wBAAwB;AAAA,UACtB,SAAS,MAAM,uBAAuB;AAAA,UACtC,QAAQ,CAAC,MAAM,sBAAsB,CAAC;AAAA,QACxC;AAAA,QACA,cAAc,CAAC;AAAA,MACjB;AAAA,MAGA,OAAO,eAAe,OAAO,kBAAkB;AAAA,QAC7C,OAAO;AAAA,QACP,UAAU;AAAA,QACV,YAAY;AAAA,MACd,CAAC;AAAA,MAGD,OAAO,eAAe,OAAO,oBAAoB;AAAA,QAC/C,OAAO,QAAS,GAAiD;AAAA,UAC/D,IAAI,CAAC,KAAK,gBAAgB;AAAA,YACxB,KAAK,iBAAiB,IAAI,QAAc,CAAC,SAAS,WAAW;AAAA,cAC3D,uBAAuB;AAAA,cACvB,sBAAsB;AAAA,aACvB;AAAA,UACH;AAAA,UACA,OAAO,KAAK;AAAA;AAAA,QAEd,YAAY;AAAA,MACd,CAAC;AAAA,MAED,OAAO;AAAA;AAAA,IAET,YAAY;AAAA,MACV,QAAQ;AAAA,QACN,GAAG,GAAkC;AAAA,UAEnC,OAAQ,KAA8D,iBAAiB;AAAA;AAAA,MAE3F;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,IAAI,GAA8E;AAAA,QAChF,IAAI,CAAC,KAAK,QAAQ;AAAA,UAChB,OAAO,QAAQ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M,IAAI,MAAM,yBAAyB,OAAO;AAAA,EAClD;AAAA,EAEA,MAAM,SAAS,aAAa;AAAA,EAE5B,IAAI;AAAA,IACF,OAAO,MAAM;AAAA,MACX,MAAM,SAAS,QAAQ,QAAQ,QAAQ,MAAM;AAAA,MAC7C,MAAM,aAAa,QAAQ,aAAa,QAAQ,MAAM;AAAA,MACtD,OAAO,QAAQ;AAAA,MAEf,IAAI,WAAW,OAAO;AAAA,QACpB,MAAM,QAAQ,QAAQ,KAAK,WAAW,KAAK;AAAA,QAC3C,WAAW,MAAM,QAAQ;AAAA,QACzB,MAAM,IAAI,MAAM,gBAAgB,OAAO;AAAA,MACzC;AAAA,MAGA,MAAM,WAAW,MAAM,QAAQ,eAAe,WAAW,KAAK;AAAA,MAC9D,WAAW,MAAM,QAAQ;AAAA,MACzB,QAAQ,QAAQ,mBAAmB;AAAA,MAEnC,IAAI,SAAS,OAAO;AAAA,QAClB,MAAM,QAAQ,QAAQ,KAAK,SAAS,KAAK;AAAA,QACzC,SAAS,MAAM,QAAQ;AAAA,QACvB,MAAM,IAAI,MAAM,gBAAgB,OAAO;AAAA,MACzC;AAAA,MAEA,MAAM,SAAS,2BAAU,SAAS,SAAS,KAAK;AAAA,MAChD,SAAS,MAAM,QAAQ;AAAA,MAEvB,IAAI,OAAO,MAAM;AAAA,QACf;AAAA,MACF;AAAA,MAEA,MAAM,OAAO;AAAA,IACf;AAAA,YACA;AAAA,IACA,MAAM,gBAAgB,QAAQ,QAAQ,QAAQ,aAAa;AAAA,IAC3D,QAAQ,aAAa,eAAe,MAAM;AAAA,IAC1C,cAAc,QAAQ;AAAA,IACtB,OAAO,QAAQ;AAAA;AAAA;",
8
+ "debugId": "824583274BA2456864756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,76 @@
1
+ // @bun @bun-cjs
2
+ (function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
7
+ var __toCommonJS = (from) => {
8
+ var entry = __moduleCache.get(from), desc;
9
+ if (entry)
10
+ return entry;
11
+ entry = __defProp({}, "__esModule", { value: true });
12
+ if (from && typeof from === "object" || typeof from === "function")
13
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ }));
17
+ __moduleCache.set(from, entry);
18
+ return entry;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true,
25
+ configurable: true,
26
+ set: (newValue) => all[name] = () => newValue
27
+ });
28
+ };
29
+
30
+ // packages/core/src/scope.ts
31
+ var exports_scope = {};
32
+ __export(exports_scope, {
33
+ withScopeAsync: () => withScopeAsync,
34
+ withScope: () => withScope
35
+ });
36
+ module.exports = __toCommonJS(exports_scope);
37
+ function createScope() {
38
+ const handles = [];
39
+ return {
40
+ manage(handle) {
41
+ handles.push(handle);
42
+ return handle;
43
+ },
44
+ get handles() {
45
+ return handles;
46
+ }
47
+ };
48
+ }
49
+ function disposeScope(scope) {
50
+ const handles = scope.handles;
51
+ for (let i = handles.length - 1;i >= 0; i--) {
52
+ const handle = handles[i];
53
+ if (handle && handle.alive) {
54
+ handle.dispose();
55
+ }
56
+ }
57
+ }
58
+ function withScope(_context, fn) {
59
+ const scope = createScope();
60
+ try {
61
+ return fn(scope);
62
+ } finally {
63
+ disposeScope(scope);
64
+ }
65
+ }
66
+ async function withScopeAsync(_context, fn) {
67
+ const scope = createScope();
68
+ try {
69
+ return await fn(scope);
70
+ } finally {
71
+ disposeScope(scope);
72
+ }
73
+ }
74
+ })
75
+
76
+ //# debugId=C97AB5B520552F3B64756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/scope.ts"],
4
+ "sourcesContent": [
5
+ "import type { QuickJSContext, QuickJSHandle } from \"quickjs-emscripten\";\nimport type { Scope } from \"./types.cjs\";\n\n/**\n * Create a new scope for tracking handles\n */\nfunction createScope(): Scope {\n const handles: QuickJSHandle[] = [];\n\n return {\n manage<T extends QuickJSHandle>(handle: T): T {\n handles.push(handle);\n return handle;\n },\n get handles() {\n return handles as readonly QuickJSHandle[];\n },\n };\n}\n\n/**\n * Dispose all handles in a scope (in reverse order)\n */\nfunction disposeScope(scope: Scope): void {\n const handles = scope.handles;\n for (let i = handles.length - 1; i >= 0; i--) {\n const handle = handles[i];\n if (handle && handle.alive) {\n handle.dispose();\n }\n }\n}\n\n/**\n * Execute a function with automatic handle cleanup\n *\n * @example\n * const result = withScope(context, (scope) => {\n * const obj = scope.manage(context.newObject());\n * const str = scope.manage(context.newString(\"hello\"));\n * context.setProp(obj, \"message\", str);\n * return context.dump(obj);\n * });\n */\nexport function withScope<T>(\n _context: QuickJSContext,\n fn: (scope: Scope) => T\n): T {\n const scope = createScope();\n try {\n return fn(scope);\n } finally {\n disposeScope(scope);\n }\n}\n\n/**\n * Async version of withScope for promise-based operations\n */\nexport async function withScopeAsync<T>(\n _context: QuickJSContext,\n fn: (scope: Scope) => Promise<T>\n): Promise<T> {\n const scope = createScope();\n try {\n return await fn(scope);\n } finally {\n disposeScope(scope);\n }\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,SAAS,WAAW,GAAU;AAAA,EAC5B,MAAM,UAA2B,CAAC;AAAA,EAElC,OAAO;AAAA,IACL,MAA+B,CAAC,QAAc;AAAA,MAC5C,QAAQ,KAAK,MAAM;AAAA,MACnB,OAAO;AAAA;AAAA,QAEL,OAAO,GAAG;AAAA,MACZ,OAAO;AAAA;AAAA,EAEX;AAAA;AAMF,SAAS,YAAY,CAAC,OAAoB;AAAA,EACxC,MAAM,UAAU,MAAM;AAAA,EACtB,SAAS,IAAI,QAAQ,SAAS,EAAG,KAAK,GAAG,KAAK;AAAA,IAC5C,MAAM,SAAS,QAAQ;AAAA,IACvB,IAAI,UAAU,OAAO,OAAO;AAAA,MAC1B,OAAO,QAAQ;AAAA,IACjB;AAAA,EACF;AAAA;AAcK,SAAS,SAAY,CAC1B,UACA,IACG;AAAA,EACH,MAAM,QAAQ,YAAY;AAAA,EAC1B,IAAI;AAAA,IACF,OAAO,GAAG,KAAK;AAAA,YACf;AAAA,IACA,aAAa,KAAK;AAAA;AAAA;AAOtB,eAAsB,cAAiB,CACrC,UACA,IACY;AAAA,EACZ,MAAM,QAAQ,YAAY;AAAA,EAC1B,IAAI;AAAA,IACF,OAAO,MAAM,GAAG,KAAK;AAAA,YACrB;AAAA,IACA,aAAa,KAAK;AAAA;AAAA;",
8
+ "debugId": "C97AB5B520552F3B64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,152 @@
1
+ // @bun @bun-cjs
2
+ (function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
7
+ var __toCommonJS = (from) => {
8
+ var entry = __moduleCache.get(from), desc;
9
+ if (entry)
10
+ return entry;
11
+ entry = __defProp({}, "__esModule", { value: true });
12
+ if (from && typeof from === "object" || typeof from === "function")
13
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ }));
17
+ __moduleCache.set(from, entry);
18
+ return entry;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true,
25
+ configurable: true,
26
+ set: (newValue) => all[name] = () => newValue
27
+ });
28
+ };
29
+
30
+ // packages/core/src/streams/transform-stream.ts
31
+ var exports_transform_stream = {};
32
+ __export(exports_transform_stream, {
33
+ createTransformStreamClass: () => createTransformStreamClass
34
+ });
35
+ module.exports = __toCommonJS(exports_transform_stream);
36
+ var import_class_builder = require("../class-builder.cjs");
37
+ function createTransformStreamClass(context, stateMap) {
38
+ return import_class_builder.defineClass(context, stateMap, {
39
+ name: "TransformStream",
40
+ construct: (args) => {
41
+ const transformer = args[0];
42
+ const readableQueue = [];
43
+ let readableCloseRequested = false;
44
+ let readableClosed = false;
45
+ let readableErrored = false;
46
+ let readableErrorValue = undefined;
47
+ const controller = {
48
+ enqueue(chunk) {
49
+ if (readableCloseRequested || readableClosed) {
50
+ throw new TypeError("Readable side is closed");
51
+ }
52
+ readableQueue.push(chunk);
53
+ },
54
+ error(e) {
55
+ readableErrored = true;
56
+ readableErrorValue = e;
57
+ },
58
+ terminate() {
59
+ readableCloseRequested = true;
60
+ },
61
+ get desiredSize() {
62
+ if (readableErrored)
63
+ return null;
64
+ if (readableCloseRequested)
65
+ return 0;
66
+ return 1 - readableQueue.length;
67
+ }
68
+ };
69
+ const readableState = {
70
+ locked: false,
71
+ reader: null,
72
+ queue: readableQueue,
73
+ closeRequested: readableCloseRequested,
74
+ closed: readableClosed,
75
+ errored: readableErrored,
76
+ errorValue: readableErrorValue,
77
+ started: true,
78
+ controller: {
79
+ enqueue: controller.enqueue,
80
+ close: controller.terminate,
81
+ error: controller.error,
82
+ desiredSize: 1
83
+ }
84
+ };
85
+ const writableState = {
86
+ locked: false,
87
+ writer: null,
88
+ closed: false,
89
+ errored: false,
90
+ errorValue: undefined,
91
+ closeRequested: false,
92
+ writeRequests: [],
93
+ inFlightWriteRequest: null,
94
+ started: true,
95
+ controller: {
96
+ error: controller.error
97
+ },
98
+ sink: {
99
+ write: async (chunk) => {
100
+ if (transformer?.transform) {
101
+ await transformer.transform(chunk, controller);
102
+ } else {
103
+ controller.enqueue(chunk);
104
+ }
105
+ },
106
+ close: async () => {
107
+ if (transformer?.flush) {
108
+ await transformer.flush(controller);
109
+ }
110
+ controller.terminate();
111
+ }
112
+ }
113
+ };
114
+ const state = {
115
+ readable: readableState,
116
+ writable: writableState,
117
+ transformer,
118
+ controller,
119
+ backpressure: false,
120
+ backpressureChangePromise: null
121
+ };
122
+ if (transformer?.start) {
123
+ try {
124
+ const startResult = transformer.start(controller);
125
+ if (startResult instanceof Promise) {
126
+ startResult.catch((e) => {
127
+ controller.error(e);
128
+ });
129
+ }
130
+ } catch (e) {
131
+ controller.error(e);
132
+ }
133
+ }
134
+ return state;
135
+ },
136
+ properties: {
137
+ readable: {
138
+ get() {
139
+ return this.readable;
140
+ }
141
+ },
142
+ writable: {
143
+ get() {
144
+ return this.writable;
145
+ }
146
+ }
147
+ }
148
+ });
149
+ }
150
+ })
151
+
152
+ //# debugId=32391A1A87ABB81C64756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/streams/transform-stream.ts"],
4
+ "sourcesContent": [
5
+ "import type { QuickJSContext, QuickJSHandle } from \"quickjs-emscripten\";\nimport type { StateMap } from \"../types.cjs\";\nimport { defineClass } from \"../class-builder.cjs\";\nimport { marshal } from \"../marshal.cjs\";\nimport { unmarshal } from \"../unmarshal.cjs\";\n\ninterface TransformStreamController {\n enqueue(chunk: unknown): void;\n error(e: unknown): void;\n terminate(): void;\n desiredSize: number | null;\n}\n\ninterface TransformStreamInternalState {\n readable: object; // ReadableStream internal state\n writable: object; // WritableStream internal state\n transformer?: {\n start?: (controller: TransformStreamController) => void | Promise<void>;\n transform?: (chunk: unknown, controller: TransformStreamController) => void | Promise<void>;\n flush?: (controller: TransformStreamController) => void | Promise<void>;\n };\n controller: TransformStreamController;\n backpressure: boolean;\n backpressureChangePromise: {\n resolve: () => void;\n promise: Promise<void>;\n } | null;\n}\n\n/**\n * Create the TransformStream class\n */\nexport function createTransformStreamClass(\n context: QuickJSContext,\n stateMap: StateMap\n): QuickJSHandle {\n return defineClass<TransformStreamInternalState>(context, stateMap, {\n name: \"TransformStream\",\n construct: (args) => {\n const transformer = args[0] as {\n start?: (controller: TransformStreamController) => void | Promise<void>;\n transform?: (chunk: unknown, controller: TransformStreamController) => void | Promise<void>;\n flush?: (controller: TransformStreamController) => void | Promise<void>;\n } | undefined;\n\n // Queue for the readable side\n const readableQueue: unknown[] = [];\n let readableCloseRequested = false;\n let readableClosed = false;\n let readableErrored = false;\n let readableErrorValue: unknown = undefined;\n\n // Create controller\n const controller: TransformStreamController = {\n enqueue(chunk: unknown) {\n if (readableCloseRequested || readableClosed) {\n throw new TypeError(\"Readable side is closed\");\n }\n readableQueue.push(chunk);\n },\n error(e: unknown) {\n readableErrored = true;\n readableErrorValue = e;\n },\n terminate() {\n readableCloseRequested = true;\n },\n get desiredSize() {\n if (readableErrored) return null;\n if (readableCloseRequested) return 0;\n return 1 - readableQueue.length;\n },\n };\n\n // Create readable side state\n const readableState = {\n locked: false,\n reader: null,\n queue: readableQueue,\n closeRequested: readableCloseRequested,\n closed: readableClosed,\n errored: readableErrored,\n errorValue: readableErrorValue,\n started: true,\n controller: {\n enqueue: controller.enqueue,\n close: controller.terminate,\n error: controller.error,\n desiredSize: 1,\n },\n };\n\n // Create writable side state\n const writableState = {\n locked: false,\n writer: null,\n closed: false,\n errored: false,\n errorValue: undefined,\n closeRequested: false,\n writeRequests: [],\n inFlightWriteRequest: null,\n started: true,\n controller: {\n error: controller.error,\n },\n sink: {\n write: async (chunk: unknown) => {\n if (transformer?.transform) {\n await transformer.transform(chunk, controller);\n } else {\n // Default identity transform\n controller.enqueue(chunk);\n }\n },\n close: async () => {\n if (transformer?.flush) {\n await transformer.flush(controller);\n }\n controller.terminate();\n },\n },\n };\n\n const state: TransformStreamInternalState = {\n readable: readableState,\n writable: writableState,\n transformer,\n controller,\n backpressure: false,\n backpressureChangePromise: null,\n };\n\n // Call start if provided\n if (transformer?.start) {\n try {\n const startResult = transformer.start(controller);\n if (startResult instanceof Promise) {\n startResult.catch((e) => {\n controller.error(e);\n });\n }\n } catch (e) {\n controller.error(e);\n }\n }\n\n return state;\n },\n properties: {\n readable: {\n get(this: TransformStreamInternalState) {\n // Return the readable state - will be wrapped by the stream class\n return this.readable;\n },\n },\n writable: {\n get(this: TransformStreamInternalState) {\n // Return the writable state - will be wrapped by the stream class\n return this.writable;\n },\n },\n },\n });\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE4B,IAA5B;AA8BO,SAAS,0BAA0B,CACxC,SACA,UACe;AAAA,EACf,OAAO,iCAA0C,SAAS,UAAU;AAAA,IAClE,MAAM;AAAA,IACN,WAAW,CAAC,SAAS;AAAA,MACnB,MAAM,cAAc,KAAK;AAAA,MAOzB,MAAM,gBAA2B,CAAC;AAAA,MAClC,IAAI,yBAAyB;AAAA,MAC7B,IAAI,iBAAiB;AAAA,MACrB,IAAI,kBAAkB;AAAA,MACtB,IAAI,qBAA8B;AAAA,MAGlC,MAAM,aAAwC;AAAA,QAC5C,OAAO,CAAC,OAAgB;AAAA,UACtB,IAAI,0BAA0B,gBAAgB;AAAA,YAC5C,MAAM,IAAI,UAAU,yBAAyB;AAAA,UAC/C;AAAA,UACA,cAAc,KAAK,KAAK;AAAA;AAAA,QAE1B,KAAK,CAAC,GAAY;AAAA,UAChB,kBAAkB;AAAA,UAClB,qBAAqB;AAAA;AAAA,QAEvB,SAAS,GAAG;AAAA,UACV,yBAAyB;AAAA;AAAA,YAEvB,WAAW,GAAG;AAAA,UAChB,IAAI;AAAA,YAAiB,OAAO;AAAA,UAC5B,IAAI;AAAA,YAAwB,OAAO;AAAA,UACnC,OAAO,IAAI,cAAc;AAAA;AAAA,MAE7B;AAAA,MAGA,MAAM,gBAAgB;AAAA,QACpB,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,gBAAgB;AAAA,QAChB,QAAQ;AAAA,QACR,SA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AA,QACR,GAAG,GAAqC;AAAA,UAEtC,OAAO,KAAK;AAAA;AAAA,MAEhB;AAAA,MACA,UAAU;AAAA,QACR,GAAG,GAAqC;AAAA,UAEtC,OAAO,KAAK;AAAA;AAAA,MAEhB;AAAA,IACF;AAAA,EACF,CAAC;AAAA;",
8
+ "debugId": "32391A1A87ABB81C64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,39 @@
1
+ // @bun @bun-cjs
2
+ (function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
7
+ var __toCommonJS = (from) => {
8
+ var entry = __moduleCache.get(from), desc;
9
+ if (entry)
10
+ return entry;
11
+ entry = __defProp({}, "__esModule", { value: true });
12
+ if (from && typeof from === "object" || typeof from === "function")
13
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ }));
17
+ __moduleCache.set(from, entry);
18
+ return entry;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true,
25
+ configurable: true,
26
+ set: (newValue) => all[name] = () => newValue
27
+ });
28
+ };
29
+
30
+ // packages/core/src/types.ts
31
+ var exports_types = {};
32
+ __export(exports_types, {
33
+ INTERNAL_STATE: () => INTERNAL_STATE
34
+ });
35
+ module.exports = __toCommonJS(exports_types);
36
+ var INTERNAL_STATE = Symbol("INTERNAL_STATE");
37
+ })
38
+
39
+ //# debugId=1449C2F7927C25D664756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/types.ts"],
4
+ "sourcesContent": [
5
+ "import type {\n QuickJSContext,\n QuickJSHandle,\n QuickJSRuntime,\n} from \"quickjs-emscripten\";\n\nexport type { QuickJSContext, QuickJSHandle, QuickJSRuntime };\n\n/**\n * A scope for automatic handle cleanup\n */\nexport interface Scope {\n /** Track a handle for cleanup when scope ends */\n manage<T extends QuickJSHandle>(handle: T): T;\n\n /** Get all managed handles */\n readonly handles: readonly QuickJSHandle[];\n}\n\n/**\n * Options for marshalling values\n */\nexport interface MarshalOptions {\n /** Maximum depth for nested objects (default: 10) */\n maxDepth?: number;\n\n /** Custom marshaller for specific types */\n custom?: (value: unknown, context: QuickJSContext) => QuickJSHandle | undefined;\n}\n\n/**\n * Options for unmarshalling values\n */\nexport interface UnmarshalOptions {\n /** Maximum depth for nested objects (default: 10) */\n maxDepth?: number;\n\n /** Custom unmarshaller for specific handles */\n custom?: (handle: QuickJSHandle, context: QuickJSContext) => unknown | undefined;\n}\n\n/**\n * Property descriptor for class builder\n */\nexport interface PropertyDescriptor<TState = unknown> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n get?: (this: TState) => any;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n set?: (this: TState, value: any) => void;\n value?: unknown;\n writable?: boolean;\n enumerable?: boolean;\n configurable?: boolean;\n}\n\n/**\n * Options for defining a class\n */\nexport interface ClassDefinition<TState extends object = object> {\n /** Class name */\n name: string;\n\n /** Constructor function - receives unmarshalled args, returns internal state */\n construct?: (args: unknown[]) => TState;\n\n /** Prototype methods */\n methods?: Record<string, (this: TState, ...args: unknown[]) => unknown>;\n\n /** Prototype getters/setters */\n properties?: Record<string, PropertyDescriptor<TState>>;\n\n /** Static methods */\n staticMethods?: Record<string, (...args: unknown[]) => unknown>;\n\n /** Static properties */\n staticProperties?: Record<string, unknown>;\n\n /** Parent class handle (for inheritance) */\n extends?: QuickJSHandle;\n}\n\n/**\n * Symbol used to store internal state on QuickJS class instances\n */\nexport const INTERNAL_STATE: unique symbol = Symbol(\"INTERNAL_STATE\");\n\n/**\n * Map to store internal state for QuickJS object handles\n */\nexport type StateMap = WeakMap<QuickJSHandle, object>;\n\n/**\n * Options for setting up core APIs\n */\nexport interface SetupCoreOptions {\n /** Existing state map to use (creates new one if not provided) */\n stateMap?: StateMap;\n}\n\n/**\n * Handle returned from setupCore\n */\nexport interface CoreHandle {\n /** State map containing internal states */\n readonly stateMap: StateMap;\n\n /** Dispose all handles */\n dispose(): void;\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFO,IAAM,iBAAgC,OAAO,gBAAgB;",
8
+ "debugId": "1449C2F7927C25D664756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,254 @@
1
+ // @bun @bun-cjs
2
+ (function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
7
+ var __toCommonJS = (from) => {
8
+ var entry = __moduleCache.get(from), desc;
9
+ if (entry)
10
+ return entry;
11
+ entry = __defProp({}, "__esModule", { value: true });
12
+ if (from && typeof from === "object" || typeof from === "function")
13
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ }));
17
+ __moduleCache.set(from, entry);
18
+ return entry;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true,
25
+ configurable: true,
26
+ set: (newValue) => all[name] = () => newValue
27
+ });
28
+ };
29
+
30
+ // packages/core/src/unmarshal.ts
31
+ var exports_unmarshal = {};
32
+ __export(exports_unmarshal, {
33
+ unmarshal: () => unmarshal,
34
+ cleanupUnmarshaledHandles: () => cleanupUnmarshaledHandles
35
+ });
36
+ module.exports = __toCommonJS(exports_unmarshal);
37
+ var import_marshal = require("./marshal.cjs");
38
+ var contextDupedHandles = new WeakMap;
39
+ function getDupedHandles(context) {
40
+ let handles = contextDupedHandles.get(context);
41
+ if (!handles) {
42
+ handles = new Set;
43
+ contextDupedHandles.set(context, handles);
44
+ }
45
+ return handles;
46
+ }
47
+ function cleanupUnmarshaledHandles(context) {
48
+ const handles = contextDupedHandles.get(context);
49
+ if (handles) {
50
+ for (const handle of handles) {
51
+ try {
52
+ handle.dispose();
53
+ } catch {}
54
+ }
55
+ handles.clear();
56
+ contextDupedHandles.delete(context);
57
+ }
58
+ }
59
+ function unmarshal(context, handle, options = {}) {
60
+ const maxDepth = options.maxDepth ?? 10;
61
+ const seen = new WeakMap;
62
+ function unmarshalValue(h, depth) {
63
+ if (depth > maxDepth) {
64
+ throw new Error(`Maximum unmarshalling depth of ${maxDepth} exceeded`);
65
+ }
66
+ if (options.custom) {
67
+ const customResult = options.custom(h, context);
68
+ if (customResult !== undefined) {
69
+ return customResult;
70
+ }
71
+ }
72
+ const type = context.typeof(h);
73
+ if (type === "undefined") {
74
+ return;
75
+ }
76
+ const dumpedValue = context.dump(h);
77
+ if (dumpedValue === null) {
78
+ return null;
79
+ }
80
+ if (type === "boolean") {
81
+ return dumpedValue;
82
+ }
83
+ if (type === "number") {
84
+ return dumpedValue;
85
+ }
86
+ if (type === "string") {
87
+ return dumpedValue;
88
+ }
89
+ if (typeof dumpedValue === "bigint") {
90
+ return dumpedValue;
91
+ }
92
+ if (type === "function") {
93
+ const fnHandle = h.dup();
94
+ getDupedHandles(context).add(fnHandle);
95
+ const wrapper = (...args) => {
96
+ const argHandles = args.map((arg) => import_marshal.marshal(context, arg));
97
+ try {
98
+ const result = context.callFunction(fnHandle, context.undefined, ...argHandles);
99
+ if (result.error) {
100
+ const errorValue = context.dump(result.error);
101
+ result.error.dispose();
102
+ throw new Error(typeof errorValue === "object" && errorValue !== null ? errorValue.message || String(errorValue) : String(errorValue));
103
+ }
104
+ const value = unmarshalValue(result.value, depth + 1);
105
+ result.value.dispose();
106
+ return value;
107
+ } finally {
108
+ for (const argHandle of argHandles) {
109
+ argHandle.dispose();
110
+ }
111
+ }
112
+ };
113
+ wrapper.__dispose__ = () => {
114
+ fnHandle.dispose();
115
+ };
116
+ return wrapper;
117
+ }
118
+ if (type === "object") {
119
+ if (seen.has(h)) {
120
+ return seen.get(h);
121
+ }
122
+ const lengthHandle = context.getProp(h, "length");
123
+ const lengthType = context.typeof(lengthHandle);
124
+ lengthHandle.dispose();
125
+ if (lengthType === "number") {
126
+ const arrayIsArray = context.getProp(context.global, "Array");
127
+ const isArrayFn = context.getProp(arrayIsArray, "isArray");
128
+ const isArrayResult = context.callFunction(isArrayFn, context.undefined, h);
129
+ arrayIsArray.dispose();
130
+ isArrayFn.dispose();
131
+ let isArray = false;
132
+ if (!isArrayResult.error) {
133
+ isArray = context.dump(isArrayResult.value) === true;
134
+ isArrayResult.value.dispose();
135
+ } else {
136
+ isArrayResult.error.dispose();
137
+ }
138
+ if (isArray) {
139
+ const arr = [];
140
+ seen.set(h, arr);
141
+ const len = context.getNumber(context.getProp(h, "length"));
142
+ const lenHandle = context.getProp(h, "length");
143
+ const length = context.getNumber(lenHandle);
144
+ lenHandle.dispose();
145
+ for (let i = 0;i < length; i++) {
146
+ const elementHandle = context.getProp(h, i);
147
+ arr[i] = unmarshalValue(elementHandle, depth + 1);
148
+ elementHandle.dispose();
149
+ }
150
+ return arr;
151
+ }
152
+ }
153
+ const dateConstructor = context.getProp(context.global, "Date");
154
+ const isDateResult = context.evalCode(`(function(obj, Date) { return obj instanceof Date; })`);
155
+ if (!isDateResult.error) {
156
+ const checkResult = context.callFunction(isDateResult.value, context.undefined, h, dateConstructor);
157
+ isDateResult.value.dispose();
158
+ if (!checkResult.error && context.dump(checkResult.value) === true) {
159
+ checkResult.value.dispose();
160
+ dateConstructor.dispose();
161
+ const getTimeHandle = context.getProp(h, "getTime");
162
+ const timeResult = context.callFunction(getTimeHandle, h);
163
+ getTimeHandle.dispose();
164
+ if (!timeResult.error) {
165
+ const timestamp = context.getNumber(timeResult.value);
166
+ timeResult.value.dispose();
167
+ return new Date(timestamp);
168
+ }
169
+ if (timeResult.error)
170
+ timeResult.error.dispose();
171
+ }
172
+ if (checkResult.error)
173
+ checkResult.error.dispose();
174
+ else if (checkResult.value)
175
+ checkResult.value.dispose();
176
+ } else {
177
+ isDateResult.error.dispose();
178
+ }
179
+ dateConstructor.dispose();
180
+ const uint8ArrayConstructor = context.getProp(context.global, "Uint8Array");
181
+ const isUint8ArrayResult = context.evalCode(`(function(obj, U8) { return obj instanceof U8; })`);
182
+ if (!isUint8ArrayResult.error) {
183
+ const checkResult = context.callFunction(isUint8ArrayResult.value, context.undefined, h, uint8ArrayConstructor);
184
+ isUint8ArrayResult.value.dispose();
185
+ if (!checkResult.error && context.dump(checkResult.value) === true) {
186
+ checkResult.value.dispose();
187
+ uint8ArrayConstructor.dispose();
188
+ const arrayBuffer = context.getArrayBuffer(h);
189
+ if (arrayBuffer) {
190
+ return new Uint8Array(arrayBuffer.value);
191
+ }
192
+ } else {
193
+ if (checkResult.error)
194
+ checkResult.error.dispose();
195
+ else
196
+ checkResult.value.dispose();
197
+ uint8ArrayConstructor.dispose();
198
+ }
199
+ } else {
200
+ isUint8ArrayResult.error.dispose();
201
+ uint8ArrayConstructor.dispose();
202
+ }
203
+ const arrayBufferConstructor = context.getProp(context.global, "ArrayBuffer");
204
+ const isArrayBufferResult = context.evalCode(`(function(obj, AB) { return obj instanceof AB; })`);
205
+ if (!isArrayBufferResult.error) {
206
+ const checkResult = context.callFunction(isArrayBufferResult.value, context.undefined, h, arrayBufferConstructor);
207
+ isArrayBufferResult.value.dispose();
208
+ if (!checkResult.error && context.dump(checkResult.value) === true) {
209
+ checkResult.value.dispose();
210
+ arrayBufferConstructor.dispose();
211
+ const arrayBuffer = context.getArrayBuffer(h);
212
+ if (arrayBuffer) {
213
+ return arrayBuffer.value.slice(0);
214
+ }
215
+ } else {
216
+ if (checkResult.error)
217
+ checkResult.error.dispose();
218
+ else
219
+ checkResult.value.dispose();
220
+ arrayBufferConstructor.dispose();
221
+ }
222
+ } else {
223
+ isArrayBufferResult.error.dispose();
224
+ arrayBufferConstructor.dispose();
225
+ }
226
+ const obj = {};
227
+ seen.set(h, obj);
228
+ const keysResult = context.evalCode(`(function(obj) { return Object.keys(obj); })`);
229
+ if (!keysResult.error) {
230
+ const keysArrayHandle = context.callFunction(keysResult.value, context.undefined, h);
231
+ keysResult.value.dispose();
232
+ if (!keysArrayHandle.error) {
233
+ const keysArray = unmarshalValue(keysArrayHandle.value, depth + 1);
234
+ keysArrayHandle.value.dispose();
235
+ for (const key of keysArray) {
236
+ const propHandle = context.getProp(h, key);
237
+ obj[key] = unmarshalValue(propHandle, depth + 1);
238
+ propHandle.dispose();
239
+ }
240
+ } else {
241
+ keysArrayHandle.error.dispose();
242
+ }
243
+ } else {
244
+ keysResult.error.dispose();
245
+ }
246
+ return obj;
247
+ }
248
+ return dumpedValue;
249
+ }
250
+ return unmarshalValue(handle, 0);
251
+ }
252
+ })
253
+
254
+ //# debugId=DBC78D31C4F4935E64756E2164756E21