@ttsc/wasm 0.30.3 → 0.31.0
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/README.md +3 -3
- package/build/build-wasm.cjs +5 -4
- package/build/go-build-cache.cjs +347 -0
- package/build/pack-prepare.cjs +3 -2
- package/cmd/ttsc-wasm/main.go +22 -10
- package/cmd/ttsc-wasm/main_wasm.go +2 -2
- package/dist/.ttsc-wasm-build.json +138 -58
- package/dist/go.mod +7 -5
- package/dist/ttsc.wasm +2 -2
- package/go.mod +7 -5
- package/go.sum +10 -10
- package/host/api.go +34 -41
- package/host/doc.go +7 -6
- package/host/expose.go +42 -0
- package/host/fountain.go +192 -22
- package/host/host.go +10 -25
- package/host/host_native.go +3 -5
- package/host/invoke.go +133 -0
- package/host/plugin.go +37 -72
- package/host/result.go +108 -0
- package/lib/src/BootTtscWorkerTerminationError.d.ts +20 -0
- package/lib/src/BootTtscWorkerTerminationError.js +20 -0
- package/lib/src/BootTtscWorkerTerminationError.js.map +1 -1
- package/lib/src/MemFSError.d.ts +21 -2
- package/lib/src/MemFSError.js +25 -2
- package/lib/src/MemFSError.js.map +1 -1
- package/lib/src/bootTtsc.d.ts +49 -2
- package/lib/src/bootTtsc.js +89 -23
- package/lib/src/bootTtsc.js.map +1 -1
- package/lib/src/createMemFS.d.ts +45 -0
- package/lib/src/createMemFS.js +269 -66
- package/lib/src/createMemFS.js.map +1 -1
- package/lib/src/parseResult.d.ts +19 -0
- package/lib/src/parseResult.js +19 -0
- package/lib/src/parseResult.js.map +1 -1
- package/lib/src/structures/IBootResult.d.ts +20 -2
- package/lib/src/structures/IBootTtscOptions.d.ts +28 -6
- package/lib/src/structures/IFileStats.d.ts +51 -0
- package/lib/src/structures/IMemFSHost.d.ts +89 -0
- package/lib/src/structures/ITtscApi.d.ts +154 -9
- package/lib/src/structures/ITtscBuildOpts.d.ts +18 -1
- package/lib/src/structures/ITtscCompileResult.d.ts +20 -2
- package/lib/src/structures/ITtscDiagnostic.d.ts +25 -1
- package/lib/src/structures/ITtscFileQuery.d.ts +19 -1
- package/lib/src/structures/ITtscFountainDiagnosticsResult.d.ts +20 -1
- package/lib/src/structures/ITtscNodeAtPositionResult.d.ts +18 -1
- package/lib/src/structures/ITtscNodeInfo.d.ts +23 -2
- package/lib/src/structures/ITtscPluginOpts.d.ts +24 -3
- package/lib/src/structures/ITtscPositionQuery.d.ts +21 -4
- package/lib/src/structures/ITtscReleaseSnapshotResult.d.ts +22 -2
- package/lib/src/structures/ITtscResult.d.ts +31 -5
- package/lib/src/structures/ITtscSnapshotHandle.d.ts +19 -1
- package/lib/src/structures/ITtscSnapshotResult.d.ts +22 -1
- package/lib/src/structures/ITtscSnapshotsResult.d.ts +19 -1
- package/lib/src/structures/ITtscSourceFileTextResult.d.ts +19 -1
- package/lib/src/structures/ITtscSourceFilesResult.d.ts +23 -2
- package/lib/src/structures/ITtscSymbolAtPositionResult.d.ts +18 -1
- package/lib/src/structures/ITtscSymbolDeclaration.d.ts +25 -2
- package/lib/src/structures/ITtscSymbolInfo.d.ts +19 -1
- package/lib/src/structures/ITtscTransformResult.d.ts +21 -3
- package/lib/src/structures/ITtscTypeAtPositionResult.d.ts +18 -1
- package/lib/src/structures/ITtscTypeInfo.d.ts +19 -1
- package/lib/src/structures/ITtscVersion.d.ts +28 -1
- package/lib/src/structures/IWasmExecFS.d.ts +310 -0
- package/package.json +4 -2
- package/shim-vendor/shim/ast/enums_gen.go +4 -2
- package/shim-vendor/shim/ast/go.mod +5 -5
- package/shim-vendor/shim/ast/go.sum +10 -10
- package/shim-vendor/shim/ast/lint.go +1088 -20
- package/shim-vendor/shim/ast/parent.go +38 -22
- package/shim-vendor/shim/ast/safe_text.go +48 -26
- package/shim-vendor/shim/ast/shim.go +1307 -20
- package/shim-vendor/shim/ast/test/next_jsdoc_comment_location_reaches_variable_statement_test.go +51 -0
- package/shim-vendor/shim/ast/test/node_text_joins_multi_hop_qualified_name_test.go +24 -9
- package/shim-vendor/shim/ast/test/node_text_joins_one_hop_qualified_name_test.go +9 -5
- package/shim-vendor/shim/ast/test/node_text_returns_empty_for_nil_test.go +13 -5
- package/shim-vendor/shim/ast/test/node_text_returns_identifier_text_test.go +12 -5
- package/shim-vendor/shim/ast/test/node_text_skips_empty_qualified_left_test.go +35 -5
- package/shim-vendor/shim/astnav/go.mod +5 -5
- package/shim-vendor/shim/astnav/go.sum +12 -10
- package/shim-vendor/shim/astnav/shim.go +9 -0
- package/shim-vendor/shim/bundled/go.mod +7 -1
- package/shim-vendor/shim/bundled/go.sum +12 -0
- package/shim-vendor/shim/checker/enums_gen.go +4 -2
- package/shim-vendor/shim/checker/extra-shim.json +6 -0
- package/shim-vendor/shim/checker/go.mod +5 -5
- package/shim-vendor/shim/checker/go.sum +10 -10
- package/shim-vendor/shim/checker/node_builder_fields_gen.go +19 -0
- package/shim-vendor/shim/checker/shim.go +827 -114
- package/shim-vendor/shim/compiler/emit_sourcemap.go +68 -29
- package/shim-vendor/shim/compiler/emitassemble.go +36 -2
- package/shim-vendor/shim/compiler/emithook.go +13 -3
- package/shim-vendor/shim/compiler/go.mod +5 -5
- package/shim-vendor/shim/compiler/go.sum +10 -10
- package/shim-vendor/shim/compiler/incremental.go +56 -20
- package/shim-vendor/shim/compiler/resolution.go +92 -9
- package/shim-vendor/shim/core/enums_gen.go +2 -2
- package/shim-vendor/shim/core/go.mod +6 -1
- package/shim-vendor/shim/core/go.sum +10 -0
- package/shim-vendor/shim/core/modulekind.go +9 -0
- package/shim-vendor/shim/core/shim.go +157 -6
- package/shim-vendor/shim/diagnosticwriter/go.mod +10 -1
- package/shim-vendor/shim/diagnosticwriter/go.sum +20 -0
- package/shim-vendor/shim/diagnosticwriter/lint.go +188 -10
- package/shim-vendor/shim/diagnosticwriter/shim.go +14 -0
- package/shim-vendor/shim/lsp/go.mod +5 -5
- package/shim-vendor/shim/lsp/go.sum +10 -10
- package/shim-vendor/shim/lsp/shim.go +78 -2
- package/shim-vendor/shim/parser/go.mod +10 -1
- package/shim-vendor/shim/parser/go.sum +22 -0
- package/shim-vendor/shim/printer/emithost.go +46 -1
- package/shim-vendor/shim/printer/go.mod +5 -5
- package/shim-vendor/shim/printer/go.sum +10 -10
- package/shim-vendor/shim/printer/shim.go +114 -7
- package/shim-vendor/shim/printer/sourcemap.go +55 -0
- package/shim-vendor/shim/scanner/go.mod +10 -1
- package/shim-vendor/shim/scanner/go.sum +20 -0
- package/shim-vendor/shim/scanner/regexp.go +19 -4
- package/shim-vendor/shim/scanner/shim.go +3 -0
- package/shim-vendor/shim/stringutil/extra-shim.json +1 -0
- package/shim-vendor/shim/stringutil/go.mod +5 -0
- package/shim-vendor/shim/stringutil/go.sum +2 -0
- package/shim-vendor/shim/stringutil/shim.go +119 -0
- package/shim-vendor/shim/transformers/go.mod +5 -5
- package/shim-vendor/shim/transformers/go.sum +12 -10
- package/shim-vendor/shim/transformers/shim.go +12 -3
- package/shim-vendor/shim/tsoptions/command_line_raw.go +44 -0
- package/shim-vendor/shim/tsoptions/go.mod +10 -1
- package/shim-vendor/shim/tsoptions/go.sum +22 -0
- package/shim-vendor/shim/tsoptions/shim.go +1 -1
- package/shim-vendor/shim/tspath/go.mod +1 -1
- package/shim-vendor/shim/tspath/go.sum +6 -0
- package/shim-vendor/shim/vfs/cachedvfs/go.mod +3 -1
- package/shim-vendor/shim/vfs/cachedvfs/go.sum +12 -0
- package/shim-vendor/shim/vfs/decode.go +26 -0
- package/shim-vendor/shim/vfs/decode_test.go +42 -0
- package/shim-vendor/shim/vfs/go.mod +7 -1
- package/shim-vendor/shim/vfs/go.sum +12 -0
- package/shim-vendor/shim/vfs/osvfs/go.mod +7 -1
- package/shim-vendor/shim/vfs/osvfs/go.sum +12 -0
- package/src/BootTtscWorkerTerminationError.ts +22 -0
- package/src/MemFSError.ts +29 -2
- package/src/bootTtsc.ts +104 -28
- package/src/createMemFS.ts +291 -64
- package/src/parseResult.ts +19 -0
- package/src/structures/IBootResult.ts +21 -2
- package/src/structures/IBootTtscOptions.ts +32 -6
- package/src/structures/IFileStats.ts +65 -0
- package/src/structures/IMemFSHost.ts +97 -0
- package/src/structures/ITtscApi.ts +154 -9
- package/src/structures/ITtscBuildOpts.ts +19 -1
- package/src/structures/ITtscCompileResult.ts +21 -2
- package/src/structures/ITtscDiagnostic.ts +32 -1
- package/src/structures/ITtscFileQuery.ts +19 -1
- package/src/structures/ITtscFountainDiagnosticsResult.ts +20 -1
- package/src/structures/ITtscNodeAtPositionResult.ts +18 -1
- package/src/structures/ITtscNodeInfo.ts +27 -2
- package/src/structures/ITtscPluginOpts.ts +28 -3
- package/src/structures/ITtscPositionQuery.ts +21 -4
- package/src/structures/ITtscReleaseSnapshotResult.ts +22 -2
- package/src/structures/ITtscResult.ts +34 -5
- package/src/structures/ITtscSnapshotHandle.ts +19 -1
- package/src/structures/ITtscSnapshotResult.ts +22 -1
- package/src/structures/ITtscSnapshotsResult.ts +19 -1
- package/src/structures/ITtscSourceFileTextResult.ts +19 -1
- package/src/structures/ITtscSourceFilesResult.ts +23 -2
- package/src/structures/ITtscSymbolAtPositionResult.ts +18 -1
- package/src/structures/ITtscSymbolDeclaration.ts +27 -2
- package/src/structures/ITtscSymbolInfo.ts +23 -1
- package/src/structures/ITtscTransformResult.ts +22 -3
- package/src/structures/ITtscTypeAtPositionResult.ts +18 -1
- package/src/structures/ITtscTypeInfo.ts +20 -1
- package/src/structures/ITtscVersion.ts +33 -1
- package/src/structures/IWasmExecFS.ts +336 -0
package/host/invoke.go
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
package host
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"io"
|
|
6
|
+
"sync"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// PluginInvocation owns all mutable state for one plugin call.
|
|
10
|
+
//
|
|
11
|
+
// A plugin that needs asynchronous work must register it with Go before Run
|
|
12
|
+
// returns. InvokePlugin waits for every registered function. Registration
|
|
13
|
+
// after Run returns is rejected, and writes made after the invocation closes
|
|
14
|
+
// return io.ErrClosedPipe. This gives child goroutines an explicit ownership
|
|
15
|
+
// boundary without sharing process-global output state.
|
|
16
|
+
//
|
|
17
|
+
// @evidence contracts/common.md#principled-implementation Context, io.Writer and synchronization primitives make request and child ownership explicit.
|
|
18
|
+
// @evidence contracts/common.md#clear-and-simple-design Public command inputs and writers are distinct from private registration state; Go is the single boundary that couples task acceptance with the owner's completion wait.
|
|
19
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Mutable buffers belong to each request, without global-stream swapping for concurrent calls.
|
|
20
|
+
// @evidence contracts/common.md#meaningful-documentation Native paragraphs explain child registration and late-write rejection under the documentation skill.
|
|
21
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms This owning request type groups task state and inputs; its Go and InvokePlugin operations choose the processing strategy.
|
|
22
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work One effectful invocation is not a coordinator of equivalent request computations.
|
|
23
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources InvokePlugin acquires this request's context, copied arguments and writers. Go registers child tasks until Run exits; the owner waits for them and closes streams on normal and panic exits. Task count and captured bytes are unbounded, and children must cooperate with cancellation because the host cannot force goroutine termination.
|
|
24
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation PluginInvocation holds in-memory streams and a goroutine counter and carries no native path, process or platform capability.
|
|
25
|
+
type PluginInvocation struct {
|
|
26
|
+
// Context derives from the caller and is canceled when invocation ownership ends.
|
|
27
|
+
Context context.Context
|
|
28
|
+
|
|
29
|
+
// Command is the selected plugin subcommand.
|
|
30
|
+
Command string
|
|
31
|
+
|
|
32
|
+
// Args is the invocation-owned copy of forwarded CLI arguments.
|
|
33
|
+
Args []string
|
|
34
|
+
|
|
35
|
+
// Stdout accepts writes until all registered work completes.
|
|
36
|
+
Stdout io.Writer
|
|
37
|
+
|
|
38
|
+
// Stderr has the same ownership boundary as Stdout.
|
|
39
|
+
Stderr io.Writer
|
|
40
|
+
|
|
41
|
+
childrenMu sync.Mutex
|
|
42
|
+
children sync.WaitGroup
|
|
43
|
+
acceptingChild bool
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Go registers and starts invocation-owned asynchronous work. It returns false
|
|
47
|
+
// when Run has already returned and the ownership boundary is closed.
|
|
48
|
+
//
|
|
49
|
+
// The task receives the invocation context. It must honor cancellation itself;
|
|
50
|
+
// registration does not supply a timeout or recover a panic in the child.
|
|
51
|
+
//
|
|
52
|
+
// @evidence contracts/common.md#principled-implementation A mutex couples acceptance and WaitGroup.Add, making child registration precede the owner's Wait.
|
|
53
|
+
// @evidence contracts/common.md#clear-and-simple-design One registration method keeps the acceptance check and task-count transition together, with no separate caller-managed Add/Wait protocol.
|
|
54
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Late work is rejected instead of relying on a race-prone Add after Wait begins.
|
|
55
|
+
// @evidence contracts/common.md#meaningful-documentation Separate native paragraphs explain acceptance and task obligations under the documentation skill.
|
|
56
|
+
// @evidence contracts/performance.md#efficient-algorithms Registration checks acceptance and increments the WaitGroup count under one mutex in O(1), then schedules one goroutine. Task work is supplied by the plugin and is not rescanned by registration.
|
|
57
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work This operation registers an effectful child task; it does not determine equivalence of computations across requests.
|
|
58
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources Acceptance acquires one child count and goroutine; deferred Done releases the count when the task exits. Run's owner closes registration before waiting. Outstanding count is unbounded and completion depends on the task honoring its context and returning.
|
|
59
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation PluginInvocation.Go starts an in-process goroutine and touches no native path or operating-system process.
|
|
60
|
+
func (invocation *PluginInvocation) Go(task func(context.Context)) bool {
|
|
61
|
+
if task == nil {
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
invocation.childrenMu.Lock()
|
|
65
|
+
if !invocation.acceptingChild {
|
|
66
|
+
invocation.childrenMu.Unlock()
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
invocation.children.Add(1)
|
|
70
|
+
invocation.childrenMu.Unlock()
|
|
71
|
+
go func() {
|
|
72
|
+
defer invocation.children.Done()
|
|
73
|
+
task(invocation.Context)
|
|
74
|
+
}()
|
|
75
|
+
return true
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// InvokePlugin executes one plugin call and captures its request-owned output.
|
|
79
|
+
// Independent invocations may run concurrently without sharing buffers.
|
|
80
|
+
//
|
|
81
|
+
// The caller's arguments are copied before dispatch. Run must return and each
|
|
82
|
+
// registered task must finish before the result can be captured; the context is
|
|
83
|
+
// propagated through an invocation-owned child context, without a deadline or
|
|
84
|
+
// forced goroutine stop. A panic from Run cancels that context, closes child
|
|
85
|
+
// registration, waits for cooperative registered work and closes its streams
|
|
86
|
+
// before propagating to the caller's panic handler.
|
|
87
|
+
//
|
|
88
|
+
// @evidence contracts/common.md#principled-implementation Each call copies arguments and owns synchronized writers; closing task acceptance under the same mutex as registration makes Wait safe after Run exits. Deferred finalization closes streams only after registered work finishes, including cooperative cancellation on a Run panic.
|
|
89
|
+
// @evidence contracts/common.md#clear-and-simple-design One invocation owns context, child registration and output finalization. The private writer enforces the same closing boundary for both streams, without a global capture mechanism or separate plugin lifecycle framework.
|
|
90
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Owned streams replace process-global output mutation. Deferred finalization covers normal and panic exits without swallowing a panic; child tasks remain responsible for honoring context because Go cannot forcibly stop them.
|
|
91
|
+
// @evidence contracts/common.md#meaningful-documentation Native paragraphs explain isolation and completion obligations under the documentation skill's ownership guidance.
|
|
92
|
+
// @evidence contracts/performance.md#efficient-algorithms Copying A argument references costs O(A); the two bytes.Buffer writers grow amortized with B captured bytes and final string capture costs O(B). Waiting tracks G registered tasks without scanning a task list. The selected plugin owns its command's algorithm.
|
|
93
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Each command owns effects and output; this executor does not coordinate equivalent request computations, and equal argument strings do not make calls shareable.
|
|
94
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources The call owns context, argument copy, G child tasks and B captured bytes. Deferred finalization closes registration, waits for registered work, closes both writers and cancels the context on every return/panic path. G and B have no fixed bound, and a noncooperative task can keep finalization waiting; the returned strings transfer captured output to the caller.
|
|
95
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation InvokePlugin runs an in-process Plugin against in-memory buffers and starts no operating-system process and reads no native path.
|
|
96
|
+
func InvokePlugin(ctx context.Context, plugin Plugin, command string, args []string) (result APIResult) {
|
|
97
|
+
if ctx == nil {
|
|
98
|
+
ctx = context.Background()
|
|
99
|
+
}
|
|
100
|
+
ctx, cancel := context.WithCancel(ctx)
|
|
101
|
+
stdout := &invocationBuffer{}
|
|
102
|
+
stderr := &invocationBuffer{}
|
|
103
|
+
invocation := &PluginInvocation{
|
|
104
|
+
Context: ctx,
|
|
105
|
+
Command: command,
|
|
106
|
+
Args: append([]string(nil), args...),
|
|
107
|
+
Stdout: stdout,
|
|
108
|
+
Stderr: stderr,
|
|
109
|
+
acceptingChild: true,
|
|
110
|
+
}
|
|
111
|
+
code := 0
|
|
112
|
+
returned := false
|
|
113
|
+
defer func() {
|
|
114
|
+
defer cancel()
|
|
115
|
+
if !returned {
|
|
116
|
+
cancel()
|
|
117
|
+
}
|
|
118
|
+
invocation.childrenMu.Lock()
|
|
119
|
+
invocation.acceptingChild = false
|
|
120
|
+
invocation.childrenMu.Unlock()
|
|
121
|
+
invocation.children.Wait()
|
|
122
|
+
stdout.close()
|
|
123
|
+
stderr.close()
|
|
124
|
+
result = APIResult{
|
|
125
|
+
Code: code,
|
|
126
|
+
Stdout: stdout.String(),
|
|
127
|
+
Stderr: stderr.String(),
|
|
128
|
+
}
|
|
129
|
+
}()
|
|
130
|
+
code = plugin.Run(invocation)
|
|
131
|
+
returned = true
|
|
132
|
+
return
|
|
133
|
+
}
|
package/host/plugin.go
CHANGED
|
@@ -2,7 +2,6 @@ package host
|
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"bytes"
|
|
5
|
-
"context"
|
|
6
5
|
"io"
|
|
7
6
|
"sync"
|
|
8
7
|
)
|
|
@@ -13,88 +12,54 @@ import (
|
|
|
13
12
|
// adapters and registers them with Config. Every run receives invocation-owned
|
|
14
13
|
// streams; a plugin must write only to those streams, never os.Stdout or
|
|
15
14
|
// os.Stderr.
|
|
15
|
+
//
|
|
16
|
+
// @evidence contracts/common.md#principled-implementation A small Go interface supplies named command dispatch through invocation-owned streams.
|
|
17
|
+
// @evidence contracts/common.md#clear-and-simple-design Name identifies registration and Run owns command execution; invocation context and streams are supplied through one request rather than host-owned plugin-specific APIs.
|
|
18
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The supported plugin boundary avoids mutating process-global stdout/stderr to capture a call.
|
|
19
|
+
// @evidence contracts/common.md#meaningful-documentation Native paragraphs explain browser linkage and stream ownership under the documentation skill.
|
|
20
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources Plugin is an interface that acquires no handle, task or retained state.
|
|
21
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Plugin is an interface that chooses no algorithm or processing strategy.
|
|
22
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Plugin is an interface that coordinates no shared or repeated computation.
|
|
23
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Plugin declares command dispatch for in-process adapters and carries no native path, process or platform decision.
|
|
16
24
|
type Plugin interface {
|
|
17
25
|
// Name is the npm-style plugin id passed to api.plugin.
|
|
26
|
+
//
|
|
27
|
+
// @evidence contracts/common.md#principled-implementation Explicit registration identity decouples dispatch from the concrete plugin type.
|
|
28
|
+
// @evidence contracts/common.md#clear-and-simple-design One name query supplies the registry key without exposing command state or concrete plugin implementation.
|
|
29
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The implementation declares its id rather than being recognized by a consumer-specific type check.
|
|
30
|
+
// @evidence contracts/common.md#meaningful-documentation The Go member comment names the API consumer under the documentation skill's context rule.
|
|
31
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources Plugin.Name is an abstract method; the invocation and the concrete plugin own its resources.
|
|
32
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Plugin.Name is an abstract method; the concrete plugin chooses its algorithm.
|
|
33
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Plugin.Name is an abstract method; the concrete plugin owns any reuse of its work.
|
|
34
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Plugin.Name is an interface method with no native path, process or platform decision.
|
|
18
35
|
Name() string
|
|
19
36
|
|
|
20
37
|
// Run dispatches one subcommand and returns the native CLI exit code.
|
|
38
|
+
//
|
|
39
|
+
// @evidence contracts/common.md#principled-implementation A request object supplies context, arguments and owned writers through one Go extension boundary.
|
|
40
|
+
// @evidence contracts/common.md#clear-and-simple-design One invocation groups command inputs and owned effects; command-specific parsing stays with the implementation rather than the generic host.
|
|
41
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Commands run through the registered implementation rather than changing a foreign global launcher.
|
|
42
|
+
// @evidence contracts/common.md#meaningful-documentation The member comment states dispatch and exit-code roles under the documentation skill's clarity rule.
|
|
43
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources Plugin.Run is an abstract method; the invocation and the concrete plugin own its resources.
|
|
44
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Plugin.Run is an abstract method; the concrete plugin chooses its algorithm.
|
|
45
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Plugin.Run is an abstract method; the concrete plugin owns any reuse of its work.
|
|
46
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Plugin.Run is an interface method with no native path, process or platform decision.
|
|
21
47
|
Run(invocation *PluginInvocation) int
|
|
22
48
|
}
|
|
23
49
|
|
|
24
|
-
// PluginInvocation owns all mutable state for one plugin call.
|
|
25
|
-
//
|
|
26
|
-
// A plugin that needs asynchronous work must register it with Go before Run
|
|
27
|
-
// returns. InvokePlugin waits for every registered function. Registration
|
|
28
|
-
// after Run returns is rejected, and writes made after the invocation closes
|
|
29
|
-
// return io.ErrClosedPipe. This gives child goroutines an explicit ownership
|
|
30
|
-
// boundary without sharing process-global output state.
|
|
31
|
-
type PluginInvocation struct {
|
|
32
|
-
Context context.Context
|
|
33
|
-
Command string
|
|
34
|
-
Args []string
|
|
35
|
-
Stdout io.Writer
|
|
36
|
-
Stderr io.Writer
|
|
37
|
-
|
|
38
|
-
childrenMu sync.Mutex
|
|
39
|
-
children sync.WaitGroup
|
|
40
|
-
acceptingChild bool
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Go registers and starts invocation-owned asynchronous work. It returns false
|
|
44
|
-
// when Run has already returned and the ownership boundary is closed.
|
|
45
|
-
func (invocation *PluginInvocation) Go(task func(context.Context)) bool {
|
|
46
|
-
if task == nil {
|
|
47
|
-
return false
|
|
48
|
-
}
|
|
49
|
-
invocation.childrenMu.Lock()
|
|
50
|
-
if !invocation.acceptingChild {
|
|
51
|
-
invocation.childrenMu.Unlock()
|
|
52
|
-
return false
|
|
53
|
-
}
|
|
54
|
-
invocation.children.Add(1)
|
|
55
|
-
invocation.childrenMu.Unlock()
|
|
56
|
-
go func() {
|
|
57
|
-
defer invocation.children.Done()
|
|
58
|
-
task(invocation.Context)
|
|
59
|
-
}()
|
|
60
|
-
return true
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// InvokePlugin executes one plugin call and captures its request-owned output.
|
|
64
|
-
// Independent invocations may run concurrently without sharing buffers.
|
|
65
|
-
func InvokePlugin(ctx context.Context, plugin Plugin, command string, args []string) APIResult {
|
|
66
|
-
if ctx == nil {
|
|
67
|
-
ctx = context.Background()
|
|
68
|
-
}
|
|
69
|
-
stdout := &invocationBuffer{}
|
|
70
|
-
stderr := &invocationBuffer{}
|
|
71
|
-
invocation := &PluginInvocation{
|
|
72
|
-
Context: ctx,
|
|
73
|
-
Command: command,
|
|
74
|
-
Args: append([]string(nil), args...),
|
|
75
|
-
Stdout: stdout,
|
|
76
|
-
Stderr: stderr,
|
|
77
|
-
acceptingChild: true,
|
|
78
|
-
}
|
|
79
|
-
code := plugin.Run(invocation)
|
|
80
|
-
|
|
81
|
-
invocation.childrenMu.Lock()
|
|
82
|
-
invocation.acceptingChild = false
|
|
83
|
-
invocation.childrenMu.Unlock()
|
|
84
|
-
invocation.children.Wait()
|
|
85
|
-
|
|
86
|
-
stdout.close()
|
|
87
|
-
stderr.close()
|
|
88
|
-
return APIResult{
|
|
89
|
-
Code: code,
|
|
90
|
-
Stdout: stdout.String(),
|
|
91
|
-
Stderr: stderr.String(),
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
50
|
// Config carries the optional registrations the host applies before binding
|
|
96
51
|
// globalThis[name]. Pass Config{} for a vanilla ttsc + tsgo wasm.
|
|
52
|
+
//
|
|
53
|
+
// @evidence contracts/common.md#principled-implementation An explicit slice of the small Plugin interface keeps linkage and registration with the consumer host.
|
|
54
|
+
// @evidence contracts/common.md#clear-and-simple-design One registration list is sufficient for the host factory; command options and mutable invocation state remain owned by the selected plugin call.
|
|
55
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The host receives linked registrations rather than guessing installed packages from hardcoded ids.
|
|
56
|
+
// @evidence contracts/common.md#meaningful-documentation The native comment explains empty configuration and registration timing under the documentation skill's context rule.
|
|
57
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources Config is a data type and acquires no handle, task or retained state.
|
|
58
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Config is a data type and chooses no algorithm or processing strategy.
|
|
59
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Config is a data type and coordinates no shared or repeated computation.
|
|
60
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Config is a data type and performs no native filesystem, path or process operation.
|
|
97
61
|
type Config struct {
|
|
62
|
+
// Plugins are registered once; empty names and nil entries are skipped.
|
|
98
63
|
Plugins []Plugin
|
|
99
64
|
}
|
|
100
65
|
|
package/host/result.go
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// JSON payload shapes shared by the wasm and native entrypoints.
|
|
2
|
+
package host
|
|
3
|
+
|
|
4
|
+
// APIResult is the stdout/stderr capture returned by InvokePlugin. The
|
|
5
|
+
// js/wasm binding wraps it in the same JS result envelope that build/check/
|
|
6
|
+
// transform use, adding `result` when an endpoint has a JSON payload. `code`
|
|
7
|
+
// follows the native CLI exit-code contract (0 success, 2 compiler/config/
|
|
8
|
+
// usage error, 3 runtime error).
|
|
9
|
+
//
|
|
10
|
+
// @evidence contracts/common.md#principled-implementation Explicit stream fields mirror invocation capture and the JavaScript envelope.
|
|
11
|
+
// @evidence contracts/common.md#clear-and-simple-design One capture value separates exit status and the two streams, leaving project JSON to the JavaScript envelope.
|
|
12
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The exit code remains data rather than being replaced by a success-only output shape.
|
|
13
|
+
// @evidence contracts/common.md#meaningful-documentation Native comments explain channels and exit codes under the documentation skill's context guidance.
|
|
14
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources APIResult is a data type and acquires no handle, task or retained state.
|
|
15
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms APIResult is a data type and chooses no algorithm or processing strategy.
|
|
16
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work APIResult is a data type and coordinates no shared or repeated computation.
|
|
17
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation APIResult is a data type and performs no native filesystem, path or process operation.
|
|
18
|
+
type APIResult struct {
|
|
19
|
+
// Code is the plugin's CLI exit status.
|
|
20
|
+
Code int `json:"code"`
|
|
21
|
+
|
|
22
|
+
// Stdout contains this invocation's standard output.
|
|
23
|
+
Stdout string `json:"stdout"`
|
|
24
|
+
|
|
25
|
+
// Stderr contains this invocation's diagnostic output.
|
|
26
|
+
Stderr string `json:"stderr"`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// CompileResult mirrors `ttsc api-compile`. Field names are TypeScript-style
|
|
30
|
+
// so JS callers can use it directly without remapping.
|
|
31
|
+
//
|
|
32
|
+
// @evidence contracts/common.md#principled-implementation JSON field tags preserve the TypeScript-facing compiler payload and optional diagnostic list.
|
|
33
|
+
// @evidence contracts/common.md#clear-and-simple-design Diagnostics reuse one wire DTO while output text is keyed by destination; the transport envelope stays outside this payload.
|
|
34
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Emitted paths and contents remain compiler data rather than a consumer-shaped output schema.
|
|
35
|
+
// @evidence contracts/common.md#meaningful-documentation Comments identify the wire shape, omission and output path base under the documentation skill's context rule.
|
|
36
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources CompileResult is a data type and acquires no handle, task or retained state.
|
|
37
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms CompileResult is a data type and chooses no algorithm or processing strategy.
|
|
38
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work CompileResult is a data type and coordinates no shared or repeated computation.
|
|
39
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation CompileResult is a data type and performs no native filesystem, path or process operation.
|
|
40
|
+
type CompileResult struct {
|
|
41
|
+
// Diagnostics is omitted when the result has no messages.
|
|
42
|
+
Diagnostics []CompileDiagnostic `json:"diagnostics,omitempty"`
|
|
43
|
+
|
|
44
|
+
// Output maps emitted paths to JS / d.ts text. Paths inside cwd are relative;
|
|
45
|
+
// outside destinations stay absolute. Empty when no files were produced.
|
|
46
|
+
Output map[string]string `json:"output"`
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// TransformResult is the no-emit companion. The `typescript` map keys files
|
|
50
|
+
// the same way `output` does in compile mode.
|
|
51
|
+
//
|
|
52
|
+
// @evidence contracts/common.md#principled-implementation A distinct source-text map avoids conflating transformed TypeScript with emitted output.
|
|
53
|
+
// @evidence contracts/common.md#clear-and-simple-design The source-text map and shared diagnostics form one transform payload, separate from compile output and invocation streams.
|
|
54
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The payload represents actual program text instead of reconstructing it from JavaScript emit.
|
|
55
|
+
// @evidence contracts/common.md#meaningful-documentation Native comments distinguish the source stage and optional messages under the documentation skill's clarity rule.
|
|
56
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources TransformResult is a data type and acquires no handle, task or retained state.
|
|
57
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms TransformResult is a data type and chooses no algorithm or processing strategy.
|
|
58
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work TransformResult is a data type and coordinates no shared or repeated computation.
|
|
59
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation TransformResult is a data type and performs no native filesystem, path or process operation.
|
|
60
|
+
type TransformResult struct {
|
|
61
|
+
// Diagnostics is omitted when the result has no messages.
|
|
62
|
+
Diagnostics []CompileDiagnostic `json:"diagnostics,omitempty"`
|
|
63
|
+
|
|
64
|
+
// TypeScript holds post-plugin text under project-relative or outside absolute paths.
|
|
65
|
+
TypeScript map[string]string `json:"typescript"`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// CompileDiagnostic is the public TypeScript-side diagnostic DTO. Mirrors the
|
|
69
|
+
// shape `ttsc api-compile` writes so the JS host can render it without
|
|
70
|
+
// remapping fields.
|
|
71
|
+
//
|
|
72
|
+
// Start/Length are UTF-8 byte offsets and lengths. Line/Character are 1-based;
|
|
73
|
+
// Character counts UTF-8 bytes from the line start, as the native driver does.
|
|
74
|
+
// Zero display locations are omitted when no source context is available.
|
|
75
|
+
//
|
|
76
|
+
// @evidence contracts/common.md#principled-implementation Nullable file and optional location fields follow the driver's diagnostic projection through JSON.
|
|
77
|
+
// @evidence contracts/common.md#clear-and-simple-design File identity, severity, byte span and display location remain distinct fields, with pointers for absent spans rather than an alternate diagnostic model.
|
|
78
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Compiler coordinates are preserved rather than guessed from JavaScript text indices.
|
|
79
|
+
// @evidence contracts/common.md#meaningful-documentation Separate comments explain coordinate units and absence under the documentation skill's paragraph guidance.
|
|
80
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources CompileDiagnostic is a data type and acquires no handle, task or retained state.
|
|
81
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms CompileDiagnostic is a data type and chooses no algorithm or processing strategy.
|
|
82
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work CompileDiagnostic is a data type and coordinates no shared or repeated computation.
|
|
83
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation CompileDiagnostic is a data type and performs no native filesystem, path or process operation.
|
|
84
|
+
type CompileDiagnostic struct {
|
|
85
|
+
// File is an absolute slash path, or nil for a project-wide message.
|
|
86
|
+
File *string `json:"file"`
|
|
87
|
+
|
|
88
|
+
// Category is error or warning; errors affect the command exit code.
|
|
89
|
+
Category string `json:"category"`
|
|
90
|
+
|
|
91
|
+
// Code is the compiler or plugin diagnostic identifier.
|
|
92
|
+
Code int32 `json:"code"`
|
|
93
|
+
|
|
94
|
+
// Start is the optional inclusive UTF-8 byte offset.
|
|
95
|
+
Start *int `json:"start,omitempty"`
|
|
96
|
+
|
|
97
|
+
// Length is the optional span length in UTF-8 bytes.
|
|
98
|
+
Length *int `json:"length,omitempty"`
|
|
99
|
+
|
|
100
|
+
// Line is 1-based and omitted without a display location.
|
|
101
|
+
Line int `json:"line,omitempty"`
|
|
102
|
+
|
|
103
|
+
// Character is a 1-based UTF-8 byte column, omitted without a location.
|
|
104
|
+
Character int `json:"character,omitempty"`
|
|
105
|
+
|
|
106
|
+
// MessageText is the complete compiler or plugin message.
|
|
107
|
+
MessageText string `json:"messageText"`
|
|
108
|
+
}
|
|
@@ -5,11 +5,31 @@
|
|
|
5
5
|
* same API name in the same Worker would install a new readiness bridge that
|
|
6
6
|
* the stale runtime could invoke, so `bootTtsc` terminally rejects later boots
|
|
7
7
|
* until the caller terminates the Worker.
|
|
8
|
+
*
|
|
9
|
+
* @evidence contracts/common.md#principled-implementation
|
|
10
|
+
* An Error subclass carries a stable machine-readable code, API identity and
|
|
11
|
+
* original cause so the owner can replace the Worker rather than parse prose.
|
|
12
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
13
|
+
* One error identity groups the terminal discriminator, API slot and cause;
|
|
14
|
+
* Worker replacement remains the caller's responsibility, outside this value.
|
|
15
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
16
|
+
* The error exposes the runtime's terminal ownership limit rather than hiding
|
|
17
|
+
* it under retries that would reuse a stale global readiness bridge.
|
|
18
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
19
|
+
* Separate JSDoc paragraphs explain the failure and why replacement is required;
|
|
20
|
+
* members explain identity and cause, following the documentation skill.
|
|
21
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources BootTtscWorkerTerminationError retains only its own fields and cause and is released with the rejection.
|
|
22
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms BootTtscWorkerTerminationError builds one message string and chooses no processing strategy.
|
|
23
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work BootTtscWorkerTerminationError is an error value and coordinates no shared or repeated computation.
|
|
8
24
|
*/
|
|
9
25
|
export declare class BootTtscWorkerTerminationError extends Error {
|
|
26
|
+
/** Stable discriminator for Worker-replacement handling. */
|
|
10
27
|
static readonly CODE = "TTSC_WASM_WORKER_TERMINATION_REQUIRED";
|
|
28
|
+
/** Global API bridge whose Go runtime has already started. */
|
|
11
29
|
readonly apiName: string;
|
|
30
|
+
/** Instance discriminator shared with the class constant. */
|
|
12
31
|
readonly code = "TTSC_WASM_WORKER_TERMINATION_REQUIRED";
|
|
32
|
+
/** Original cancellation, startup or runtime failure. */
|
|
13
33
|
readonly cause: unknown;
|
|
14
34
|
constructor(apiName: string, cause: unknown);
|
|
15
35
|
}
|
|
@@ -8,11 +8,31 @@ exports.BootTtscWorkerTerminationError = void 0;
|
|
|
8
8
|
* same API name in the same Worker would install a new readiness bridge that
|
|
9
9
|
* the stale runtime could invoke, so `bootTtsc` terminally rejects later boots
|
|
10
10
|
* until the caller terminates the Worker.
|
|
11
|
+
*
|
|
12
|
+
* @evidence contracts/common.md#principled-implementation
|
|
13
|
+
* An Error subclass carries a stable machine-readable code, API identity and
|
|
14
|
+
* original cause so the owner can replace the Worker rather than parse prose.
|
|
15
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
16
|
+
* One error identity groups the terminal discriminator, API slot and cause;
|
|
17
|
+
* Worker replacement remains the caller's responsibility, outside this value.
|
|
18
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
19
|
+
* The error exposes the runtime's terminal ownership limit rather than hiding
|
|
20
|
+
* it under retries that would reuse a stale global readiness bridge.
|
|
21
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
22
|
+
* Separate JSDoc paragraphs explain the failure and why replacement is required;
|
|
23
|
+
* members explain identity and cause, following the documentation skill.
|
|
24
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources BootTtscWorkerTerminationError retains only its own fields and cause and is released with the rejection.
|
|
25
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms BootTtscWorkerTerminationError builds one message string and chooses no processing strategy.
|
|
26
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work BootTtscWorkerTerminationError is an error value and coordinates no shared or repeated computation.
|
|
11
27
|
*/
|
|
12
28
|
class BootTtscWorkerTerminationError extends Error {
|
|
29
|
+
/** Stable discriminator for Worker-replacement handling. */
|
|
13
30
|
static CODE = "TTSC_WASM_WORKER_TERMINATION_REQUIRED";
|
|
31
|
+
/** Global API bridge whose Go runtime has already started. */
|
|
14
32
|
apiName;
|
|
33
|
+
/** Instance discriminator shared with the class constant. */
|
|
15
34
|
code = BootTtscWorkerTerminationError.CODE;
|
|
35
|
+
/** Original cancellation, startup or runtime failure. */
|
|
16
36
|
cause;
|
|
17
37
|
constructor(apiName, cause) {
|
|
18
38
|
const causeMessage = cause instanceof Error ? cause.message : String(cause ?? "boot failed");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BootTtscWorkerTerminationError.js","sourceRoot":"","sources":["../../src/BootTtscWorkerTerminationError.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"BootTtscWorkerTerminationError.js","sourceRoot":"","sources":["../../src/BootTtscWorkerTerminationError.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,oCAA4C,SAAQ,KAAK;IACvD,4DAA4D;IACrD,MAAM,CAAU,IAAI,GAAG,uCAAuC,CAAC;IAEtE,8DAA8D;IAC9C,OAAO,CAAS;IAEhC,6DAA6D;IAC7C,IAAI,GAAG,8BAA8B,CAAC,IAAI,CAAC;IAE3D,yDAAyD;IAChC,KAAK,CAAU;IAExC,YAAmB,OAAe,EAAE,KAAc;QAChD,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,aAAa,CAAC,CAAC;QAC1E,KAAK,CACH,IAAI,8BAA8B,CAAC,IAAI,KAAK,YAAY,kBAAkB,OAAO,iFAAiF,CACnK,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
|
package/lib/src/MemFSError.d.ts
CHANGED
|
@@ -3,13 +3,32 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Matches the shape of `NodeJS.ErrnoException` so Go's `os` package interprets
|
|
5
5
|
* it as a proper `os.PathError` with a numeric error code. Thrown by the MemFS
|
|
6
|
-
* implementation
|
|
7
|
-
*
|
|
6
|
+
* implementation for rejected virtual filesystem operations.
|
|
7
|
+
*
|
|
8
|
+
* @evidence contracts/common.md#principled-implementation
|
|
9
|
+
* Error fields follow NodeJS.ErrnoException and Go's js/wasm filesystem bridge;
|
|
10
|
+
* numeric errno values describe that virtual ABI, not the browser host OS.
|
|
11
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
12
|
+
* The Error subclass groups the bridge's machine fields with its message;
|
|
13
|
+
* one private mapping owns errno translation for every virtual operation.
|
|
14
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
15
|
+
* POSIX error identifiers are protocol constants; failed operations remain
|
|
16
|
+
* errors instead of returning a fake successful callback value.
|
|
17
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
18
|
+
* Native JSDoc explains the bridge and members' machine-readable roles,
|
|
19
|
+
* following the documentation skill's concrete context guidance.
|
|
20
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources MemFSError retains only its own fields and is released with the thrown error.
|
|
21
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms MemFSError maps a code with one constant switch and chooses no processing strategy.
|
|
22
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work MemFSError is an error value and coordinates no shared or repeated computation.
|
|
8
23
|
*/
|
|
9
24
|
export declare class MemFSError extends Error {
|
|
25
|
+
/** POSIX symbolic error, consumed by the Go bridge. */
|
|
10
26
|
code: string;
|
|
27
|
+
/** Negative Linux-style errno for the virtual filesystem ABI. */
|
|
11
28
|
errno: number;
|
|
29
|
+
/** Normalized virtual path, when the failing operation identifies one. */
|
|
12
30
|
path?: string;
|
|
31
|
+
/** Filesystem operation that produced the error. */
|
|
13
32
|
syscall?: string;
|
|
14
33
|
constructor(code: string, syscall: string, path?: string);
|
|
15
34
|
}
|
package/lib/src/MemFSError.js
CHANGED
|
@@ -6,13 +6,32 @@ exports.MemFSError = void 0;
|
|
|
6
6
|
*
|
|
7
7
|
* Matches the shape of `NodeJS.ErrnoException` so Go's `os` package interprets
|
|
8
8
|
* it as a proper `os.PathError` with a numeric error code. Thrown by the MemFS
|
|
9
|
-
* implementation
|
|
10
|
-
*
|
|
9
|
+
* implementation for rejected virtual filesystem operations.
|
|
10
|
+
*
|
|
11
|
+
* @evidence contracts/common.md#principled-implementation
|
|
12
|
+
* Error fields follow NodeJS.ErrnoException and Go's js/wasm filesystem bridge;
|
|
13
|
+
* numeric errno values describe that virtual ABI, not the browser host OS.
|
|
14
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
15
|
+
* The Error subclass groups the bridge's machine fields with its message;
|
|
16
|
+
* one private mapping owns errno translation for every virtual operation.
|
|
17
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
18
|
+
* POSIX error identifiers are protocol constants; failed operations remain
|
|
19
|
+
* errors instead of returning a fake successful callback value.
|
|
20
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
21
|
+
* Native JSDoc explains the bridge and members' machine-readable roles,
|
|
22
|
+
* following the documentation skill's concrete context guidance.
|
|
23
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources MemFSError retains only its own fields and is released with the thrown error.
|
|
24
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms MemFSError maps a code with one constant switch and chooses no processing strategy.
|
|
25
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work MemFSError is an error value and coordinates no shared or repeated computation.
|
|
11
26
|
*/
|
|
12
27
|
class MemFSError extends Error {
|
|
28
|
+
/** POSIX symbolic error, consumed by the Go bridge. */
|
|
13
29
|
code;
|
|
30
|
+
/** Negative Linux-style errno for the virtual filesystem ABI. */
|
|
14
31
|
errno;
|
|
32
|
+
/** Normalized virtual path, when the failing operation identifies one. */
|
|
15
33
|
path;
|
|
34
|
+
/** Filesystem operation that produced the error. */
|
|
16
35
|
syscall;
|
|
17
36
|
constructor(code, syscall, path) {
|
|
18
37
|
super(`${code}: ${syscall} ${path ?? ""}`.trim());
|
|
@@ -40,8 +59,12 @@ function errnoForCode(code) {
|
|
|
40
59
|
return -21;
|
|
41
60
|
case "EINVAL":
|
|
42
61
|
return -22;
|
|
62
|
+
case "EFBIG":
|
|
63
|
+
return -27;
|
|
43
64
|
case "ESPIPE":
|
|
44
65
|
return -29;
|
|
66
|
+
case "EPIPE":
|
|
67
|
+
return -32;
|
|
45
68
|
case "ENOTEMPTY":
|
|
46
69
|
return -39;
|
|
47
70
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemFSError.js","sourceRoot":"","sources":["../../src/MemFSError.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"MemFSError.js","sourceRoot":"","sources":["../../src/MemFSError.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,gBAAwB,SAAQ,KAAK;IACnC,uDAAuD;IAChD,IAAI,CAAS;IAEpB,iEAAiE;IAC1D,KAAK,CAAS;IAErB,0EAA0E;IACnE,IAAI,CAAU;IAErB,oDAAoD;IAC7C,OAAO,CAAU;IAExB,YAAY,IAAY,EAAE,OAAe,EAAE,IAAa;QACtD,KAAK,CAAC,GAAG,IAAI,KAAK,OAAO,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;;AAED,kFAAkF;AAClF,SAAS,YAAY,CAAC,IAAY;IAChC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,CAAC,CAAC,CAAC;QACZ,KAAK,OAAO;YACV,OAAO,CAAC,CAAC,CAAC;QACZ,KAAK,OAAO;YACV,OAAO,CAAC,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,CAAC,EAAE,CAAC;QACb,KAAK,SAAS;YACZ,OAAO,CAAC,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,CAAC,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,CAAC,EAAE,CAAC;QACb,KAAK,OAAO;YACV,OAAO,CAAC,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,CAAC,EAAE,CAAC;QACb,KAAK,OAAO;YACV,OAAO,CAAC,EAAE,CAAC;QACb,KAAK,WAAW;YACd,OAAO,CAAC,EAAE,CAAC;QACb;YACE,OAAO,CAAC,CAAC,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/lib/src/bootTtsc.d.ts
CHANGED
|
@@ -12,12 +12,59 @@ import type { IBootTtscOptions } from "./structures/IBootTtscOptions";
|
|
|
12
12
|
* stop the old runtime; replace the Worker before retrying.
|
|
13
13
|
*
|
|
14
14
|
* **Single-Worker caveat.** Even with the chain, a second boot loaded into the
|
|
15
|
-
*
|
|
16
|
-
* of the first
|
|
15
|
+
* same Worker after a first boot completes will overlay its Go runtime on top
|
|
16
|
+
* of the first. `importScripts(wasmExecUrl)` rebinds `globalThis.Go`, and the
|
|
17
17
|
* first wasm's keepalive goroutine keeps running through the new runtime's
|
|
18
18
|
* js-bridge tables. The serialization is sufficient for the typical use case
|
|
19
19
|
* (one boot per Worker over the page's lifetime) but DOES NOT make a Worker
|
|
20
20
|
* safe to host two wasm instances at once. Create a fresh Worker per concurrent
|
|
21
21
|
* wasm.
|
|
22
|
+
*
|
|
23
|
+
* @evidence contracts/common.md#principled-implementation
|
|
24
|
+
* The documented Go wasm_exec bridge is installed before streaming
|
|
25
|
+
* instantiation, and Promise sharing coordinates calls that use its global
|
|
26
|
+
* readiness slot. This follows the host.Expose integration rather than
|
|
27
|
+
* inventing a second runtime protocol.
|
|
28
|
+
*
|
|
29
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
30
|
+
* The entry owns one attempt's host and cancellation, the per-API chain owns
|
|
31
|
+
* readiness-slot serialization, and bootTtscOnce owns setup and cleanup.
|
|
32
|
+
* These separate identities are needed because duplicate calls may join,
|
|
33
|
+
* distinct binary URLs may queue, and a started runtime cannot be retried.
|
|
34
|
+
*
|
|
35
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
36
|
+
* The ttsc default API name and Ready/Failed slots are the host protocol,
|
|
37
|
+
* not consumer or fixture matches. The attempt installs missing Go host
|
|
38
|
+
* shims and removes only its own failed installation; it does not replace an
|
|
39
|
+
* existing foreign filesystem. The documented one-runtime-per-Worker
|
|
40
|
+
* limitation is retained rather than hidden beneath retries after go.run.
|
|
41
|
+
*
|
|
42
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
43
|
+
* JSDoc explains why same-URL calls share a boot, why API-slot serialization
|
|
44
|
+
* is needed and why post-start failure requires Worker replacement. Separate
|
|
45
|
+
* paragraphs state purpose and the shared-runtime caveat under the
|
|
46
|
+
* documentation skill; option and result interfaces document cancellation
|
|
47
|
+
* and host ownership.
|
|
48
|
+
*
|
|
49
|
+
* @evidence contracts/performance.md#efficient-algorithms
|
|
50
|
+
* Cache lookup uses normalized URL length U and expected constant-time Map
|
|
51
|
+
* access; fetch/streaming compilation process the B binary bytes without a
|
|
52
|
+
* second JavaScript binary buffer. C joined callers add O(C) abort listeners,
|
|
53
|
+
* and cancellation uses events rather than a polling scan.
|
|
54
|
+
*
|
|
55
|
+
* @evidence contracts/performance.md#reuse-equivalent-work
|
|
56
|
+
* One API/normalized-URL pair shares fetch and instantiation only with the same
|
|
57
|
+
* runtime-script URL and an identical supplied host. Omitted hosts reuse the
|
|
58
|
+
* entry's actual host. Per-API Promise
|
|
59
|
+
* chains serialize access to the global readiness slot; distinct URLs are
|
|
60
|
+
* distinct boot identities. The URL must identify immutable binary content
|
|
61
|
+
* for successful-result reuse to remain valid within the Worker lifetime.
|
|
62
|
+
*
|
|
63
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
64
|
+
* Each entry owns its controller, host and result; settlement removes joined
|
|
65
|
+
* caller listeners and internal cancellation listeners. Successful boot keys,
|
|
66
|
+
* API chain heads and terminal failures remain until Worker termination, with
|
|
67
|
+
* no fixed key or retained-byte bound. Failed pre-start entries are removed;
|
|
68
|
+
* started runtimes cannot be stopped here and require Worker replacement.
|
|
22
69
|
*/
|
|
23
70
|
export declare function bootTtsc(options: IBootTtscOptions): Promise<IBootResult>;
|