feat(domain): R4.3a FileBytes sink and the bytes entries of the wasm facade
FileBytes gathers a file chunk by chunk in linear memory (capacity reserved from the announced size, refused above the PDF cap); SheetHandle.import_pdf_bytes and restore_copy_bytes consume it, so the worker streams file.stream() and the file lives once, never as a JavaScript ArrayBuffer nor as a JSON-wrapped string. restore_copy: strict UTF-8, one BOM, the OD-3 budget, draft.restore's kinds. Node: same envelopes as import_pdf on the 51 O8 cases; rescue-copy parity with draft.restore.
This commit is contained in:
1 parent
f41dd59b2c
commit
52471dbbc0
5 files changed
+166
-12
No files matched your search
@@ -23,12 +23,24 @@ export interface GlueModule {
|
||||
core_version(): string
|
||||
call(op: string, input: string): string
|
||||
SheetHandle: new (bundle: string) => GlueSheetHandle
|
||||
FileBytes: new (expected: number) => GlueFileBytes
|
||||
}
|
||||
|
||||
export interface GlueSheetHandle {
|
||||
call(op: string, input: string): string
|
||||
/** R4: the PDF import, bytes in, the same envelope out (`PdfImportKind` on failure). */
|
||||
import_pdf(bytes: Uint8Array): string
|
||||
/** R4.3: the same import on bytes streamed into the module's memory (consumed). */
|
||||
import_pdf_bytes(bytes: GlueFileBytes): string
|
||||
/** R4.3: a rescue copy streamed into the module's memory (consumed): `draft.restore`'s kinds. */
|
||||
restore_copy_bytes(bytes: GlueFileBytes): string
|
||||
}
|
||||
|
||||
/** A file gathered chunk by chunk in the module's memory (crates/wasm `FileBytes`). */
|
||||
export interface GlueFileBytes {
|
||||
push(chunk: Uint8Array): boolean
|
||||
len(): number
|
||||
free(): void
|
||||
}
|
||||
|
||||
/** Where the module comes from: the browser (Vite asset URLs) or Node (files). */
|
||||
@@ -178,9 +190,7 @@ export class CoreRuntime {
|
||||
this.glue = glue
|
||||
this.generation += 1
|
||||
this.setState('ready')
|
||||
this.spare = this.source
|
||||
.importGlue(this.nextImport())
|
||||
.catch(() => null)
|
||||
this.spare = this.source.importGlue(this.nextImport()).catch(() => null)
|
||||
}
|
||||
|
||||
private setState(next: CoreStatus): void {
|
||||
@@ -240,7 +250,9 @@ function closedRefusal(error: unknown): string | null {
|
||||
if (!(error instanceof Error) || error.name !== 'Error') return null
|
||||
const match = /^([a-z_]+): /.exec(error.message)
|
||||
if (!match) return null
|
||||
return match[1] === 'invalid_sheet' ? error.message.slice(match[0].length) : error.message
|
||||
return match[1] === 'invalid_sheet'
|
||||
? error.message.slice(match[0].length)
|
||||
: error.message
|
||||
}
|
||||
|
||||
/** The calls that need the session's sheet (`SheetHandle` in the module's memory). */
|
||||
@@ -271,7 +283,8 @@ export class SheetSession {
|
||||
/** The handle of the live instance; a handle of a dropped instance is never called. */
|
||||
private current(): CoreOutcome<GlueSheetHandle> {
|
||||
if (this.handle && this.handleGeneration === this.runtime.generation) {
|
||||
if (this.runtime.status === 'ready') return { ok: true, value: this.handle }
|
||||
if (this.runtime.status === 'ready')
|
||||
return { ok: true, value: this.handle }
|
||||
this.runtime.kickRestart()
|
||||
return CORE_UNAVAILABLE
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user