@ttsc/playground 0.23.0 → 0.25.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/LICENSE +21 -21
- package/README.md +2 -2
- package/lib/src/compiler/loadTypiaSourcePack.d.ts +4 -4
- package/lib/src/compiler/loadTypiaSourcePack.js +7 -28
- package/lib/src/compiler/loadTypiaSourcePack.js.map +1 -1
- package/lib/src/index.d.ts +2 -2
- package/lib/src/index.js +1 -3
- package/lib/src/index.js.map +1 -1
- package/lib/src/sandbox/loadTypiaRuntimePack.d.ts +4 -4
- package/lib/src/sandbox/loadTypiaRuntimePack.js +7 -25
- package/lib/src/sandbox/loadTypiaRuntimePack.js.map +1 -1
- package/lib/src/structures/IInstallTypiaSourcePackOptions.d.ts +0 -2
- package/lib/src/structures/ILoadTypiaRuntimePackOptions.d.ts +1 -3
- package/package.json +3 -3
- package/src/compiler/loadTypiaSourcePack.ts +7 -36
- package/src/index.ts +2 -8
- package/src/react/ConsoleViewer.tsx +121 -121
- package/src/react/DependencyProgressModal.tsx +73 -73
- package/src/react/DiagnosticsPanel.tsx +74 -74
- package/src/react/ExamplePicker.tsx +93 -93
- package/src/react/LintPane.tsx +58 -58
- package/src/react/OptionsPanel.tsx +132 -132
- package/src/react/ResultViewer.tsx +75 -75
- package/src/react/SourceEditor.tsx +95 -95
- package/src/sandbox/loadTypiaRuntimePack.ts +7 -33
- package/src/structures/IInstallTypiaSourcePackOptions.ts +0 -2
- package/src/structures/ILoadTypiaRuntimePackOptions.ts +1 -3
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Jeongho Nam
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jeongho Nam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ export default function SitePlayground() {
|
|
|
101
101
|
}
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
`sandbox.signal` aborts when source or compiler options change, another Execute starts, or the shell unmounts. Pass it to setup work such as `loadTypiaRuntimePack(url, { signal: sandbox.signal })`. Runtime-pack loads
|
|
104
|
+
`sandbox.signal` aborts when source or compiler options change, another Execute starts, or the shell unmounts. Pass it to setup work such as `loadTypiaRuntimePack(url, { signal: sandbox.signal })`. Runtime-pack loads share one request per URL and evict a rejected request so the next Execute retries. Nothing else ends the load: how long a fetch takes belongs to the network, not to a number chosen here. A signal cannot preempt synchronous evaluated user code; use an isolated executor with its own termination mechanism when that boundary matters.
|
|
105
105
|
|
|
106
106
|
## Typia integration (optional)
|
|
107
107
|
|
|
@@ -128,7 +128,7 @@ const service = createWorkerCompiler({
|
|
|
128
128
|
|
|
129
129
|
The typia pack itself is built by the site (typically with a `pack-typia-sources.cjs`-style script that bundles `typia/`, `@typia/utils`, and `@typia/interface` into a flat JSON map). See the ttsc website's [`build/pack-typia-sources.cjs`](https://github.com/samchon/ttsc/blob/master/website/build/pack-typia-sources.cjs) for the reference implementation.
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
Calls for one URL share a single in-flight request; any caller's `signal` cancels that shared attempt, and a rejected attempt is evicted so the next compiler request retries the mount without starting another WASM runtime. There is no deadline over the fetch or the JSON body read — the network decides how long it takes. Pass the policy with `createTypiaSourcePackMount({ url, signal })`.
|
|
132
132
|
|
|
133
133
|
## Runtime npm dependency installer
|
|
134
134
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { IInstallTypiaSourcePackOptions } from "../structures/IInstallTypiaSourcePackOptions";
|
|
2
|
-
export declare const DEFAULT_SOURCE_PACK_TIMEOUT_MS = 30000;
|
|
3
2
|
/**
|
|
4
3
|
* Fetch the typia source pack JSON once per URL.
|
|
5
4
|
*
|
|
6
|
-
* Concurrent callers share one load. A caller abort
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Concurrent callers share one load. A caller abort cancels that shared
|
|
6
|
+
* attempt; rejection removes it from the cache so the next call retries from
|
|
7
|
+
* scratch. Nothing else ends the load: how long a fetch takes belongs to the
|
|
8
|
+
* network, not to a number chosen here.
|
|
9
9
|
*/
|
|
10
10
|
export declare function loadTypiaSourcePack(options: IInstallTypiaSourcePackOptions): Promise<Record<string, string>>;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_SOURCE_PACK_TIMEOUT_MS = void 0;
|
|
4
3
|
exports.loadTypiaSourcePack = loadTypiaSourcePack;
|
|
5
|
-
exports.DEFAULT_SOURCE_PACK_TIMEOUT_MS = 30_000;
|
|
6
4
|
const packCache = new Map();
|
|
7
5
|
/**
|
|
8
6
|
* Fetch the typia source pack JSON once per URL.
|
|
9
7
|
*
|
|
10
|
-
* Concurrent callers share one load. A caller abort
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* Concurrent callers share one load. A caller abort cancels that shared
|
|
9
|
+
* attempt; rejection removes it from the cache so the next call retries from
|
|
10
|
+
* scratch. Nothing else ends the load: how long a fetch takes belongs to the
|
|
11
|
+
* network, not to a number chosen here.
|
|
13
12
|
*/
|
|
14
13
|
function loadTypiaSourcePack(options) {
|
|
15
|
-
const timeoutMs = resolveSourcePackTimeout(options.timeoutMs);
|
|
16
14
|
const cached = packCache.get(options.url);
|
|
17
15
|
if (cached) {
|
|
18
|
-
attachSourcePackCancellation(cached, options.signal
|
|
16
|
+
attachSourcePackCancellation(cached, options.signal);
|
|
19
17
|
return cached.promise;
|
|
20
18
|
}
|
|
21
19
|
const fetchImpl = options.fetch ?? globalThis.fetch?.bind(globalThis);
|
|
@@ -43,17 +41,10 @@ function loadTypiaSourcePack(options) {
|
|
|
43
41
|
.finally(cancellation.dispose);
|
|
44
42
|
entry = { controller, promise };
|
|
45
43
|
packCache.set(url, entry);
|
|
46
|
-
attachSourcePackCancellation(entry, options.signal
|
|
44
|
+
attachSourcePackCancellation(entry, options.signal);
|
|
47
45
|
return promise;
|
|
48
46
|
}
|
|
49
|
-
function
|
|
50
|
-
const value = timeoutMs ?? exports.DEFAULT_SOURCE_PACK_TIMEOUT_MS;
|
|
51
|
-
if (!Number.isSafeInteger(value) || value <= 0 || value > 2_147_483_647) {
|
|
52
|
-
throw new RangeError("loadTypiaSourcePack: timeoutMs must be a positive integer no greater than 2147483647.");
|
|
53
|
-
}
|
|
54
|
-
return value;
|
|
55
|
-
}
|
|
56
|
-
function attachSourcePackCancellation(entry, callerSignal, timeoutMs) {
|
|
47
|
+
function attachSourcePackCancellation(entry, callerSignal) {
|
|
57
48
|
const abortFromCaller = () => {
|
|
58
49
|
if (!entry.controller.signal.aborted) {
|
|
59
50
|
entry.controller.abort({
|
|
@@ -66,16 +57,7 @@ function attachSourcePackCancellation(entry, callerSignal, timeoutMs) {
|
|
|
66
57
|
abortFromCaller();
|
|
67
58
|
else
|
|
68
59
|
callerSignal?.addEventListener("abort", abortFromCaller, { once: true });
|
|
69
|
-
const timer = setTimeout(() => {
|
|
70
|
-
if (!entry.controller.signal.aborted) {
|
|
71
|
-
entry.controller.abort({
|
|
72
|
-
kind: "timeout",
|
|
73
|
-
timeoutMs,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}, timeoutMs);
|
|
77
60
|
const cleanup = () => {
|
|
78
|
-
clearTimeout(timer);
|
|
79
61
|
callerSignal?.removeEventListener("abort", abortFromCaller);
|
|
80
62
|
};
|
|
81
63
|
void entry.promise.then(cleanup, cleanup);
|
|
@@ -109,9 +91,6 @@ async function raceSourcePackCancellation(work, cancellation, signal, getPhase)
|
|
|
109
91
|
}
|
|
110
92
|
function sourcePackCancellationError(signal, phase) {
|
|
111
93
|
const reason = signal.reason;
|
|
112
|
-
if (reason?.kind === "timeout") {
|
|
113
|
-
return new Error(`loadTypiaSourcePack: timed out after ${reason.timeoutMs}ms while ${phase}.`);
|
|
114
|
-
}
|
|
115
94
|
const error = new Error(`loadTypiaSourcePack: aborted while ${phase}.`);
|
|
116
95
|
const cause = reason?.kind === "abort" ? reason.reason : signal.reason;
|
|
117
96
|
if (cause !== undefined)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadTypiaSourcePack.js","sourceRoot":"","sources":["../../../src/compiler/loadTypiaSourcePack.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadTypiaSourcePack.js","sourceRoot":"","sources":["../../../src/compiler/loadTypiaSourcePack.ts"],"names":[],"mappings":";;;AAiBA,MAAM,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;AAErD;;;;;;;GAOG;AACH,6BACE,OAAuC;IAEvC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1C,IAAI,MAAM,EAAE,CAAC;QACX,4BAA4B,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACtE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACxB,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;IAC9B,OAAO;QACL,OAAO;QACP,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC;KAC5D,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,0BAA0B,CACvC,IAAgB,EAChB,YAA4B,EAC5B,MAAmB,EACnB,QAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,2BAA2B,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,2BAA2B,CAClC,MAAmB,EACnB,KAAa;IAEb,MAAM,MAAM,GAAG,MAAM,CAAC,MAAkD,CAAC;IACzE,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,sCAAsC,KAAK,GAAG,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,MAAM,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IACvE,IAAI,KAAK,KAAK,SAAS;QAAG,KAAqC,CAAC,KAAK,GAAG,KAAK,CAAC;IAC9E,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/lib/src/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export { DEFAULT_WORK_DIR } from "./compiler/DEFAULT_WORK_DIR";
|
|
|
22
22
|
export { installDependenciesIntoMemFS } from "./compiler/installDependenciesIntoMemFS";
|
|
23
23
|
export { installTypiaSourcePack } from "./compiler/installTypiaSourcePack";
|
|
24
24
|
export { lineColumnOf } from "./compiler/lineColumnOf";
|
|
25
|
-
export {
|
|
25
|
+
export { loadTypiaSourcePack } from "./compiler/loadTypiaSourcePack";
|
|
26
26
|
export { mapDiagnostic } from "./compiler/mapDiagnostic";
|
|
27
27
|
export { normalizeError } from "./compiler/normalizeError";
|
|
28
28
|
export { normalizeNodeModulePath } from "./compiler/normalizeNodeModulePath";
|
|
@@ -32,7 +32,7 @@ export { collectExternalPackageNames } from "./npm/collectExternalPackageNames";
|
|
|
32
32
|
export { installPlaygroundDependencies } from "./npm/installPlaygroundDependencies";
|
|
33
33
|
export { packageNameFromSpecifier } from "./npm/packageNameFromSpecifier";
|
|
34
34
|
export { createSandboxRequire } from "./sandbox/createSandboxRequire";
|
|
35
|
-
export {
|
|
35
|
+
export { loadTypiaRuntimePack } from "./sandbox/loadTypiaRuntimePack";
|
|
36
36
|
export { ConsoleViewer } from "./react/ConsoleViewer";
|
|
37
37
|
export { createCompilerClient } from "./react/createCompilerClient";
|
|
38
38
|
export { DEFAULT_OPTION_TOGGLES } from "./react/DEFAULT_OPTION_TOGGLES";
|
package/lib/src/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.SourceEditor = exports.ResultViewer = exports.PlaygroundShell = exports.OptionsPanel = exports.LintPane = exports.ExamplePicker = exports.DiagnosticsPanel = exports.DependencyProgressModal = exports.DEFAULT_OPTION_TOGGLES = exports.createCompilerClient = exports.ConsoleViewer = exports.loadTypiaRuntimePack = exports.
|
|
29
|
+
exports.SourceEditor = exports.ResultViewer = exports.PlaygroundShell = exports.OptionsPanel = exports.LintPane = exports.ExamplePicker = exports.DiagnosticsPanel = exports.DependencyProgressModal = exports.DEFAULT_OPTION_TOGGLES = exports.createCompilerClient = exports.ConsoleViewer = exports.loadTypiaRuntimePack = exports.createSandboxRequire = exports.packageNameFromSpecifier = exports.installPlaygroundDependencies = exports.collectExternalPackageNames = exports.BUILT_IN_PLAYGROUND_PACKAGES = exports.pickEmittedJS = exports.normalizeNodeModulePath = exports.normalizeError = exports.mapDiagnostic = exports.loadTypiaSourcePack = exports.lineColumnOf = exports.installTypiaSourcePack = exports.installDependenciesIntoMemFS = exports.DEFAULT_WORK_DIR = exports.DEFAULT_TYPIA_PLUGIN_NAME = exports.DEFAULT_TSCONFIG_PATH = exports.DEFAULT_PLAYGROUND_COMPILER_OPTIONS = exports.DEFAULT_LINT_PLUGIN_NAME = exports.DEFAULT_ENTRY_FILE = exports.createWorkerCompiler = exports.createTypiaSourcePackMount = exports.buildTsconfigJSON = void 0;
|
|
30
30
|
// ── compiler / worker core ────────────────────────────────────────────────
|
|
31
31
|
var buildTsconfigJSON_1 = require("./compiler/buildTsconfigJSON");
|
|
32
32
|
Object.defineProperty(exports, "buildTsconfigJSON", { enumerable: true, get: function () { return buildTsconfigJSON_1.buildTsconfigJSON; } });
|
|
@@ -53,7 +53,6 @@ Object.defineProperty(exports, "installTypiaSourcePack", { enumerable: true, get
|
|
|
53
53
|
var lineColumnOf_1 = require("./compiler/lineColumnOf");
|
|
54
54
|
Object.defineProperty(exports, "lineColumnOf", { enumerable: true, get: function () { return lineColumnOf_1.lineColumnOf; } });
|
|
55
55
|
var loadTypiaSourcePack_1 = require("./compiler/loadTypiaSourcePack");
|
|
56
|
-
Object.defineProperty(exports, "DEFAULT_SOURCE_PACK_TIMEOUT_MS", { enumerable: true, get: function () { return loadTypiaSourcePack_1.DEFAULT_SOURCE_PACK_TIMEOUT_MS; } });
|
|
57
56
|
Object.defineProperty(exports, "loadTypiaSourcePack", { enumerable: true, get: function () { return loadTypiaSourcePack_1.loadTypiaSourcePack; } });
|
|
58
57
|
var mapDiagnostic_1 = require("./compiler/mapDiagnostic");
|
|
59
58
|
Object.defineProperty(exports, "mapDiagnostic", { enumerable: true, get: function () { return mapDiagnostic_1.mapDiagnostic; } });
|
|
@@ -76,7 +75,6 @@ Object.defineProperty(exports, "packageNameFromSpecifier", { enumerable: true, g
|
|
|
76
75
|
var createSandboxRequire_1 = require("./sandbox/createSandboxRequire");
|
|
77
76
|
Object.defineProperty(exports, "createSandboxRequire", { enumerable: true, get: function () { return createSandboxRequire_1.createSandboxRequire; } });
|
|
78
77
|
var loadTypiaRuntimePack_1 = require("./sandbox/loadTypiaRuntimePack");
|
|
79
|
-
Object.defineProperty(exports, "DEFAULT_RUNTIME_PACK_TIMEOUT_MS", { enumerable: true, get: function () { return loadTypiaRuntimePack_1.DEFAULT_RUNTIME_PACK_TIMEOUT_MS; } });
|
|
80
78
|
Object.defineProperty(exports, "loadTypiaRuntimePack", { enumerable: true, get: function () { return loadTypiaRuntimePack_1.loadTypiaRuntimePack; } });
|
|
81
79
|
// ── React UI surface ──────────────────────────────────────────────────────
|
|
82
80
|
var ConsoleViewer_1 = require("./react/ConsoleViewer");
|
package/lib/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;;AAEH,6EAA6E;AAC7E,kEAAiE;AAAxD,sHAAA,iBAAiB,OAAA;AAC1B,oFAAmF;AAA1E,wIAAA,0BAA0B,OAAA;AACnC,wEAAuE;AAA9D,4HAAA,oBAAoB,OAAA;AAC7B,oEAAmE;AAA1D,wHAAA,kBAAkB,OAAA;AAC3B,gFAA+E;AAAtE,oIAAA,wBAAwB,OAAA;AACjC,sGAAqG;AAA5F,0JAAA,mCAAmC,OAAA;AAC5C,0EAAyE;AAAhE,8HAAA,qBAAqB,OAAA;AAC9B,kFAAiF;AAAxE,sIAAA,yBAAyB,OAAA;AAClC,gEAA+D;AAAtD,oHAAA,gBAAgB,OAAA;AACzB,wFAAuF;AAA9E,4IAAA,4BAA4B,OAAA;AACrC,4EAA2E;AAAlE,gIAAA,sBAAsB,OAAA;AAC/B,wDAAuD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GAAA,aAAa,OAAA;AACtB,qEAAoE;AAA3D,4HAAA,oBAAoB,OAAA;AAC7B,yEAAwE;AAA/D,gIAAA,sBAAsB,OAAA;AAC/B,2EAA0E;AAAjE,kIAAA,uBAAuB,OAAA;AAChC,6DAA4D;AAAnD,oHAAA,gBAAgB,OAAA;AACzB,uDAAsD;AAA7C,8GAAA,aAAa,OAAA;AACtB,6CAA4C;AAAnC,oGAAA,QAAQ,OAAA;AACjB,qDAAoD;AAA3C,4GAAA,YAAY,OAAA;AACrB,2DAA0D;AAAjD,kHAAA,eAAe,OAAA;AACxB,qDAAoD;AAA3C,4GAAA,YAAY,OAAA;AACrB,qDAAoD;AAA3C,4GAAA,YAAY,OAAA;AAErB,6EAA6E;AAC7E,qDAAmC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ILoadTypiaRuntimePackOptions } from "../structures/ILoadTypiaRuntimePackOptions";
|
|
2
|
-
export declare const DEFAULT_RUNTIME_PACK_TIMEOUT_MS = 30000;
|
|
3
2
|
/**
|
|
4
3
|
* Fetches the prebuilt runtime pack once per URL.
|
|
5
4
|
*
|
|
6
|
-
* Concurrent callers share one load. A caller abort
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Concurrent callers share one load. A caller abort cancels that shared
|
|
6
|
+
* attempt; rejection removes it from the cache so the next call retries from
|
|
7
|
+
* scratch. Successful packs remain cached. Nothing else ends the load: how long
|
|
8
|
+
* a fetch takes belongs to the network, not to a number chosen here.
|
|
9
9
|
*/
|
|
10
10
|
export declare function loadTypiaRuntimePack(url: string, options?: ILoadTypiaRuntimePackOptions): Promise<Record<string, string>>;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_RUNTIME_PACK_TIMEOUT_MS = void 0;
|
|
4
3
|
exports.loadTypiaRuntimePack = loadTypiaRuntimePack;
|
|
5
|
-
exports.DEFAULT_RUNTIME_PACK_TIMEOUT_MS = 30_000;
|
|
6
4
|
const packCache = new Map();
|
|
7
5
|
/**
|
|
8
6
|
* Fetches the prebuilt runtime pack once per URL.
|
|
9
7
|
*
|
|
10
|
-
* Concurrent callers share one load. A caller abort
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* Concurrent callers share one load. A caller abort cancels that shared
|
|
9
|
+
* attempt; rejection removes it from the cache so the next call retries from
|
|
10
|
+
* scratch. Successful packs remain cached. Nothing else ends the load: how long
|
|
11
|
+
* a fetch takes belongs to the network, not to a number chosen here.
|
|
13
12
|
*/
|
|
14
13
|
function loadTypiaRuntimePack(url, options = {}) {
|
|
15
|
-
const timeoutMs = resolveRuntimePackTimeout(options.timeoutMs);
|
|
16
14
|
const cached = packCache.get(url);
|
|
17
15
|
if (cached) {
|
|
18
|
-
attachRuntimePackCancellation(cached, options.signal
|
|
16
|
+
attachRuntimePackCancellation(cached, options.signal);
|
|
19
17
|
return cached.promise;
|
|
20
18
|
}
|
|
21
19
|
const controller = new AbortController();
|
|
@@ -37,16 +35,10 @@ function loadTypiaRuntimePack(url, options = {}) {
|
|
|
37
35
|
.finally(cancellation.dispose);
|
|
38
36
|
entry = { controller, promise };
|
|
39
37
|
packCache.set(url, entry);
|
|
40
|
-
attachRuntimePackCancellation(entry, options.signal
|
|
38
|
+
attachRuntimePackCancellation(entry, options.signal);
|
|
41
39
|
return promise;
|
|
42
40
|
}
|
|
43
|
-
function
|
|
44
|
-
const value = timeoutMs ?? exports.DEFAULT_RUNTIME_PACK_TIMEOUT_MS;
|
|
45
|
-
if (!Number.isSafeInteger(value) || value <= 0 || value > 2_147_483_647)
|
|
46
|
-
throw new RangeError("loadTypiaRuntimePack: timeoutMs must be a positive integer no greater than 2147483647.");
|
|
47
|
-
return value;
|
|
48
|
-
}
|
|
49
|
-
function attachRuntimePackCancellation(entry, callerSignal, timeoutMs) {
|
|
41
|
+
function attachRuntimePackCancellation(entry, callerSignal) {
|
|
50
42
|
const abortFromCaller = () => {
|
|
51
43
|
if (!entry.controller.signal.aborted)
|
|
52
44
|
entry.controller.abort({
|
|
@@ -58,15 +50,7 @@ function attachRuntimePackCancellation(entry, callerSignal, timeoutMs) {
|
|
|
58
50
|
abortFromCaller();
|
|
59
51
|
else
|
|
60
52
|
callerSignal?.addEventListener("abort", abortFromCaller, { once: true });
|
|
61
|
-
const timer = setTimeout(() => {
|
|
62
|
-
if (!entry.controller.signal.aborted)
|
|
63
|
-
entry.controller.abort({
|
|
64
|
-
kind: "timeout",
|
|
65
|
-
timeoutMs,
|
|
66
|
-
});
|
|
67
|
-
}, timeoutMs);
|
|
68
53
|
const cleanup = () => {
|
|
69
|
-
clearTimeout(timer);
|
|
70
54
|
callerSignal?.removeEventListener("abort", abortFromCaller);
|
|
71
55
|
};
|
|
72
56
|
void entry.promise.then(cleanup, cleanup);
|
|
@@ -99,8 +83,6 @@ async function raceRuntimePackCancellation(work, cancellation, signal, getPhase)
|
|
|
99
83
|
}
|
|
100
84
|
function runtimePackCancellationError(signal, phase) {
|
|
101
85
|
const reason = signal.reason;
|
|
102
|
-
if (reason?.kind === "timeout")
|
|
103
|
-
return new Error(`loadTypiaRuntimePack: timed out after ${reason.timeoutMs}ms while ${phase}.`);
|
|
104
86
|
const error = new Error(`loadTypiaRuntimePack: aborted while ${phase}.`);
|
|
105
87
|
const cause = reason?.kind === "abort" ? reason.reason : signal.reason;
|
|
106
88
|
if (cause !== undefined)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadTypiaRuntimePack.js","sourceRoot":"","sources":["../../../src/sandbox/loadTypiaRuntimePack.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadTypiaRuntimePack.js","sourceRoot":"","sources":["../../../src/sandbox/loadTypiaRuntimePack.ts"],"names":[],"mappings":";;;AAwBA,MAAM,SAAS,GAAG,IAAI,GAAG,EAA4B,CAAC;AAEtD;;;;;;;GAOG;AACH,8BACE,GAAW,EACX,OAAO,GAA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/** Maximum fetch and JSON-read time. Defaults to 30 seconds. */
|
|
16
|
-
timeoutMs?: number;
|
|
17
15
|
/**
|
|
18
16
|
* Optional fetcher. Defaults to `globalThis.fetch`. Override for tests or for
|
|
19
17
|
* sites that want their own caching strategy.
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
/** Cancellation
|
|
1
|
+
/** Cancellation policy for `loadTypiaRuntimePack`. */
|
|
2
2
|
export interface ILoadTypiaRuntimePackOptions {
|
|
3
3
|
/** Cancel the shared in-flight load. */
|
|
4
4
|
signal?: AbortSignal;
|
|
5
|
-
/** Maximum fetch and JSON-read time. Defaults to 30 seconds. */
|
|
6
|
-
timeoutMs?: number;
|
|
7
5
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttsc/playground",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Reusable React + Web Worker scaffolding for in-browser ttsc playgrounds built on @ttsc/wasm.",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"react": "^18.0.0",
|
|
40
40
|
"react-dom": "^18.0.0",
|
|
41
41
|
"tgrid": "^1.0.3",
|
|
42
|
-
"@ttsc/wasm": "^0.
|
|
42
|
+
"@ttsc/wasm": "^0.25.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@monaco-editor/react": "^4.6.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"rimraf": "^6.1.2",
|
|
53
53
|
"tgrid": "^1.0.3",
|
|
54
54
|
"typescript": "^7.0.2",
|
|
55
|
-
"@ttsc/wasm": "^0.
|
|
55
|
+
"@ttsc/wasm": "^0.25.0"
|
|
56
56
|
},
|
|
57
57
|
"keywords": [
|
|
58
58
|
"ttsc",
|
|
@@ -6,9 +6,8 @@ interface SourcePackEntry {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
interface SourcePackCancellationReason {
|
|
9
|
-
kind: "abort"
|
|
9
|
+
kind: "abort";
|
|
10
10
|
reason?: unknown;
|
|
11
|
-
timeoutMs?: number;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
interface SourcePackCancellation {
|
|
@@ -16,24 +15,22 @@ interface SourcePackCancellation {
|
|
|
16
15
|
dispose: () => void;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
export const DEFAULT_SOURCE_PACK_TIMEOUT_MS = 30_000;
|
|
20
|
-
|
|
21
18
|
const packCache = new Map<string, SourcePackEntry>();
|
|
22
19
|
|
|
23
20
|
/**
|
|
24
21
|
* Fetch the typia source pack JSON once per URL.
|
|
25
22
|
*
|
|
26
|
-
* Concurrent callers share one load. A caller abort
|
|
27
|
-
*
|
|
28
|
-
*
|
|
23
|
+
* Concurrent callers share one load. A caller abort cancels that shared
|
|
24
|
+
* attempt; rejection removes it from the cache so the next call retries from
|
|
25
|
+
* scratch. Nothing else ends the load: how long a fetch takes belongs to the
|
|
26
|
+
* network, not to a number chosen here.
|
|
29
27
|
*/
|
|
30
28
|
export function loadTypiaSourcePack(
|
|
31
29
|
options: IInstallTypiaSourcePackOptions,
|
|
32
30
|
): Promise<Record<string, string>> {
|
|
33
|
-
const timeoutMs = resolveSourcePackTimeout(options.timeoutMs);
|
|
34
31
|
const cached = packCache.get(options.url);
|
|
35
32
|
if (cached) {
|
|
36
|
-
attachSourcePackCancellation(cached, options.signal
|
|
33
|
+
attachSourcePackCancellation(cached, options.signal);
|
|
37
34
|
return cached.promise;
|
|
38
35
|
}
|
|
39
36
|
|
|
@@ -81,24 +78,13 @@ export function loadTypiaSourcePack(
|
|
|
81
78
|
|
|
82
79
|
entry = { controller, promise };
|
|
83
80
|
packCache.set(url, entry);
|
|
84
|
-
attachSourcePackCancellation(entry, options.signal
|
|
81
|
+
attachSourcePackCancellation(entry, options.signal);
|
|
85
82
|
return promise;
|
|
86
83
|
}
|
|
87
84
|
|
|
88
|
-
function resolveSourcePackTimeout(timeoutMs: number | undefined): number {
|
|
89
|
-
const value = timeoutMs ?? DEFAULT_SOURCE_PACK_TIMEOUT_MS;
|
|
90
|
-
if (!Number.isSafeInteger(value) || value <= 0 || value > 2_147_483_647) {
|
|
91
|
-
throw new RangeError(
|
|
92
|
-
"loadTypiaSourcePack: timeoutMs must be a positive integer no greater than 2147483647.",
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return value;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
85
|
function attachSourcePackCancellation(
|
|
99
86
|
entry: SourcePackEntry,
|
|
100
87
|
callerSignal: AbortSignal | undefined,
|
|
101
|
-
timeoutMs: number,
|
|
102
88
|
): void {
|
|
103
89
|
const abortFromCaller = (): void => {
|
|
104
90
|
if (!entry.controller.signal.aborted) {
|
|
@@ -111,16 +97,7 @@ function attachSourcePackCancellation(
|
|
|
111
97
|
if (callerSignal?.aborted) abortFromCaller();
|
|
112
98
|
else callerSignal?.addEventListener("abort", abortFromCaller, { once: true });
|
|
113
99
|
|
|
114
|
-
const timer = setTimeout(() => {
|
|
115
|
-
if (!entry.controller.signal.aborted) {
|
|
116
|
-
entry.controller.abort({
|
|
117
|
-
kind: "timeout",
|
|
118
|
-
timeoutMs,
|
|
119
|
-
} satisfies SourcePackCancellationReason);
|
|
120
|
-
}
|
|
121
|
-
}, timeoutMs);
|
|
122
100
|
const cleanup = (): void => {
|
|
123
|
-
clearTimeout(timer);
|
|
124
101
|
callerSignal?.removeEventListener("abort", abortFromCaller);
|
|
125
102
|
};
|
|
126
103
|
void entry.promise.then(cleanup, cleanup);
|
|
@@ -166,12 +143,6 @@ function sourcePackCancellationError(
|
|
|
166
143
|
phase: string,
|
|
167
144
|
): Error {
|
|
168
145
|
const reason = signal.reason as SourcePackCancellationReason | undefined;
|
|
169
|
-
if (reason?.kind === "timeout") {
|
|
170
|
-
return new Error(
|
|
171
|
-
`loadTypiaSourcePack: timed out after ${reason.timeoutMs}ms while ${phase}.`,
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
146
|
const error = new Error(`loadTypiaSourcePack: aborted while ${phase}.`);
|
|
176
147
|
const cause = reason?.kind === "abort" ? reason.reason : signal.reason;
|
|
177
148
|
if (cause !== undefined) (error as Error & { cause?: unknown }).cause = cause;
|
package/src/index.ts
CHANGED
|
@@ -24,10 +24,7 @@ export { DEFAULT_WORK_DIR } from "./compiler/DEFAULT_WORK_DIR";
|
|
|
24
24
|
export { installDependenciesIntoMemFS } from "./compiler/installDependenciesIntoMemFS";
|
|
25
25
|
export { installTypiaSourcePack } from "./compiler/installTypiaSourcePack";
|
|
26
26
|
export { lineColumnOf } from "./compiler/lineColumnOf";
|
|
27
|
-
export {
|
|
28
|
-
DEFAULT_SOURCE_PACK_TIMEOUT_MS,
|
|
29
|
-
loadTypiaSourcePack,
|
|
30
|
-
} from "./compiler/loadTypiaSourcePack";
|
|
27
|
+
export { loadTypiaSourcePack } from "./compiler/loadTypiaSourcePack";
|
|
31
28
|
export { mapDiagnostic } from "./compiler/mapDiagnostic";
|
|
32
29
|
export { normalizeError } from "./compiler/normalizeError";
|
|
33
30
|
export { normalizeNodeModulePath } from "./compiler/normalizeNodeModulePath";
|
|
@@ -41,10 +38,7 @@ export { packageNameFromSpecifier } from "./npm/packageNameFromSpecifier";
|
|
|
41
38
|
|
|
42
39
|
// ── typia runtime sandbox (CJS-flavoured require over a pack JSON) ────────
|
|
43
40
|
export { createSandboxRequire } from "./sandbox/createSandboxRequire";
|
|
44
|
-
export {
|
|
45
|
-
DEFAULT_RUNTIME_PACK_TIMEOUT_MS,
|
|
46
|
-
loadTypiaRuntimePack,
|
|
47
|
-
} from "./sandbox/loadTypiaRuntimePack";
|
|
41
|
+
export { loadTypiaRuntimePack } from "./sandbox/loadTypiaRuntimePack";
|
|
48
42
|
|
|
49
43
|
// ── React UI surface ──────────────────────────────────────────────────────
|
|
50
44
|
export { ConsoleViewer } from "./react/ConsoleViewer";
|