castle-web-cli 0.4.237 → 0.4.238
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +24 -0
- package/dist/bundle.js +447 -4
- package/dist/bundleLatin1.d.ts +6 -0
- package/dist/bundleLatin1.js +333 -0
- package/dist/castle-host/host.d.ts +10 -1
- package/dist/castle-host/host.js +78 -9
- package/dist/castleJson.d.ts +2 -0
- package/dist/castleJson.js +1 -0
- package/dist/deckExports.d.ts +35 -0
- package/dist/deckExports.js +365 -0
- package/dist/importCheckHook.d.ts +1 -0
- package/dist/importCheckHook.js +1 -1
- package/dist/index.js +5 -0
- package/dist/init.js +2 -1
- package/dist/save-deck.js +4 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +47 -0
- package/kits/base/sdk/castle.d.ts +3 -1
- package/kits/base/sdk/castle.js +1 -0
- package/kits/base/sdk/commands.d.ts +25 -1
- package/kits/base/sdk/commands.js +29 -1
- package/kits/base/sdk/hub.d.ts +17 -0
- package/kits/base/sdk/hub.js +33 -9
- package/kits/base/sdk/localCache.d.ts +27 -0
- package/kits/base/sdk/localCache.js +115 -0
- package/kits/base/sdk/localCacheStore.d.ts +15 -0
- package/kits/base/sdk/localCacheStore.js +358 -0
- package/kits/base/sdk/transport.d.ts +1 -0
- package/kits/base/sdk/transport.js +4 -5
- package/kits/hub-game/CLAUDE.md +22 -2
- package/kits/hub-game/castle.json +4 -1
- package/kits/hub-game/code/client/act.js +66 -91
- package/kits/hub-game/code/client/actCore.js +134 -0
- package/kits/hub-game/code/client/car.js +35 -0
- package/kits/hub-game/code/client/chrome.js +207 -381
- package/kits/hub-game/code/client/crowdNames.js +2 -2
- package/kits/hub-game/code/client/emoteWheel.js +109 -0
- package/kits/hub-game/code/client/hats.js +2 -0
- package/kits/hub-game/code/client/hookLayer.js +99 -48
- package/kits/hub-game/code/client/hostGo.js +77 -0
- package/kits/hub-game/code/client/hubControls.js +125 -0
- package/kits/hub-game/code/client/hubEntry.js +187 -0
- package/kits/hub-game/code/client/hudSurface.js +148 -0
- package/kits/hub-game/code/client/hudTree.js +96 -0
- package/kits/hub-game/code/client/idle.js +59 -13
- package/kits/hub-game/code/client/invites.js +13 -4
- package/kits/hub-game/code/client/menuIcons.js +8 -0
- package/kits/hub-game/code/client/noTrips.js +38 -0
- package/kits/hub-game/code/client/qualityEntry.js +6 -1
- package/kits/hub-game/code/client/rehello.js +3 -1
- package/kits/hub-game/code/client/riders.js +26 -0
- package/kits/hub-game/code/client/role.js +79 -0
- package/kits/hub-game/code/client/safeLayout.js +32 -3
- package/kits/hub-game/code/client/sound.js +10 -3
- package/kits/hub-game/code/client/soundscape.js +2 -2
- package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
- package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
- package/kits/hub-game/code/client/soundscapeCues.js +2 -1
- package/kits/hub-game/code/client/state.js +19 -0
- package/kits/hub-game/code/client/stuck.js +2 -1
- package/kits/hub-game/code/client/talkSurface.js +178 -0
- package/kits/hub-game/code/client/talkTree.js +238 -0
- package/kits/hub-game/code/client/tiers.js +8 -5
- package/kits/hub-game/code/client/uiDom.js +600 -0
- package/kits/hub-game/code/client/uiTree.js +359 -0
- package/kits/hub-game/code/client/vehicle.js +154 -0
- package/kits/hub-game/code/client/wear.js +27 -5
- package/kits/hub-game/code/client/worldLabels.js +3 -2
- package/kits/hub-game/code/client/yours.js +10 -3
- package/kits/hub-game/code/server/actors.js +4 -3
- package/kits/hub-game/code/server/analytics.js +56 -6
- package/kits/hub-game/code/server/decor.js +56 -16
- package/kits/hub-game/code/server/hub.js +258 -46
- package/kits/hub-game/code/server/idle.js +118 -5
- package/kits/hub-game/code/server/manifest.js +46 -4
- package/kits/hub-game/code/server/npcs.js +4 -2
- package/kits/hub-game/code/server/players.js +3 -0
- package/kits/hub-game/code/server/role.js +142 -0
- package/kits/hub-game/code/server/standing.js +6 -4
- package/kits/hub-game/code/server/vehicle.js +126 -0
- package/kits/hub-game/code/shared/car.js +52 -0
- package/kits/hub-game/code/shared/deckFlags.js +34 -0
- package/kits/hub-game/code/shared/deviceClass.js +39 -0
- package/kits/hub-game/code/shared/expression.js +9 -0
- package/kits/hub-game/code/systems/hub.js +272 -84
- package/kits/hub-game/docs/analytics.md +11 -2
- package/kits/hub-game/docs/contract.md +352 -14
- package/kits/hub-game/docs/vehicle-preset.md +132 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
- package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
- package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
- package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
- package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
- package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
- package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
- package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
- package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
- package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
- package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
- package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
- package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
- package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
- package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
- package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
- package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
- package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
- package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
- package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
- package/kits/hub-game/package-lock.json +1 -1
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/check.mjs +7 -4
- package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
- package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
- package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
- package/kits/hub-game/scripts/gen-hats.mjs +46 -2
- package/kits/hub-game/scripts/gen-role.mjs +80 -0
- package/kits/hub-game/scripts/test-act-core.mjs +167 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
- package/kits/hub-game/scripts/test-actors.mjs +48 -0
- package/kits/hub-game/scripts/test-analytics.mjs +99 -5
- package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
- package/kits/hub-game/scripts/test-ballot.mjs +2 -0
- package/kits/hub-game/scripts/test-car.mjs +43 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
- package/kits/hub-game/scripts/test-decor.mjs +77 -0
- package/kits/hub-game/scripts/test-device-class.mjs +83 -0
- package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
- package/kits/hub-game/scripts/test-hats.mjs +5 -4
- package/kits/hub-game/scripts/test-host-go.mjs +265 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
- package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
- package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
- package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
- package/kits/hub-game/scripts/test-idle.mjs +347 -1
- package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
- package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
- package/kits/hub-game/scripts/test-manifest.mjs +30 -0
- package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-quality.mjs +13 -0
- package/kits/hub-game/scripts/test-rehello.mjs +258 -3
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
- package/kits/hub-game/scripts/test-resync.mjs +183 -0
- package/kits/hub-game/scripts/test-role-client.mjs +421 -0
- package/kits/hub-game/scripts/test-role.mjs +350 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
- package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
- package/kits/hub-game/scripts/test-standing.mjs +15 -1
- package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
- package/kits/hub-game/scripts/test-tiers.mjs +13 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
- package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
- package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
- package/kits/hub-game/scripts/test-yours.mjs +33 -0
- package/kits/hub-game/tools/hubScene/export.mjs +613 -0
- package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
- package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
- package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
- package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
- package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
- package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
- package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
- package/kits/multiplayer-3d/castle.json +4 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
- package/kits/multiplayer-3d/code/client/steer.js +3 -1
- package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
- package/kits/physics-3d/CLAUDE.md +1 -1
- package/kits/physics-3d/behaviors/Player.jsx +37 -27
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
- package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
- package/kits/physics-3d/engine3d/playerRun.js +6 -1
- package/kits/physics-3d/engine3d/pxmodel.js +6 -1
- package/kits/physics-3d/engine3d/world3d.js +6 -3
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/play/behaviors/Player.js +40 -28
- package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/messages.js +5 -0
- package/kits/real-time/code/server/session.js +28 -1
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +5 -4
- package/vendor/three/LICENSE +21 -0
- package/vendor/three/build/three.core.js +58773 -0
- package/vendor/three/build/three.module.js +18251 -0
- package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
- package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
- package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
- package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
- package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
- package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
- package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
- package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
- package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
- package/vendor/three/package.json +134 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
// Running every import's save-time exporters (castle.json `exports`, see
|
|
2
|
+
// castleJson.ts for the contract): derived artifacts a kit writes for the decks
|
|
3
|
+
// built on it, beside the save rather than inside it.
|
|
4
|
+
//
|
|
5
|
+
// The CLI knows nothing about what an exporter makes. An import names scripts
|
|
6
|
+
// of its own by export name; the CLI runs each in a child `node`, hands it the
|
|
7
|
+
// deck, an output folder of its own and a cache folder shared across decks, and
|
|
8
|
+
// reports the JSON summary it prints. Nothing it writes is published. The
|
|
9
|
+
// exporter writes into a fresh stage under the cache root; the CLI alone moves
|
|
10
|
+
// it into `<deck>/.castle/exports/<name>/`, through folders it proved are the
|
|
11
|
+
// deck's own. Cache garbage collection is out of scope.
|
|
12
|
+
//
|
|
13
|
+
// `castle-web export` runs them on demand. `save-deck` runs them after a
|
|
14
|
+
// successful save only when CASTLE_SAVE_EXPORTS=1: off by default, and a
|
|
15
|
+
// failure there is a warning -- an exporter can never cost a save.
|
|
16
|
+
//
|
|
17
|
+
// An exporter runs only from the kits this CLI ships (a builtin pin, or a
|
|
18
|
+
// shipped kit checked as itself), its entry point proven by real path to be one
|
|
19
|
+
// of their files. A fetched import's exporters never run.
|
|
20
|
+
import { spawn } from 'child_process';
|
|
21
|
+
import * as fs from 'fs';
|
|
22
|
+
import * as os from 'os';
|
|
23
|
+
import * as path from 'path';
|
|
24
|
+
import { IMPORTS_DIR, readCastleJson } from './castleJson.js';
|
|
25
|
+
import { isShippedKitDir } from './importCheckHook.js';
|
|
26
|
+
import { outputLines, resolveFileInside } from './importUpdateHook.js';
|
|
27
|
+
import { getKitsDir, getPackageRoot } from './localPaths.js';
|
|
28
|
+
/** The env var that turns exporters on for `save-deck`. */
|
|
29
|
+
export const SAVE_EXPORTS_ENV = 'CASTLE_SAVE_EXPORTS';
|
|
30
|
+
// An export name is a folder name under .castle/exports/ and the cache.
|
|
31
|
+
const EXPORT_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
32
|
+
const MAX_EXPORT_OUTPUT = 16 * 1024 * 1024;
|
|
33
|
+
// How long an exporter that ignores SIGTERM gets before its whole process group
|
|
34
|
+
// is killed outright.
|
|
35
|
+
function killGraceMs() {
|
|
36
|
+
const raw = Number(process.env.CASTLE_EXPORT_KILL_GRACE_MS);
|
|
37
|
+
return Number.isFinite(raw) && raw >= 0 ? raw : 5_000;
|
|
38
|
+
}
|
|
39
|
+
// Exporters build whole worlds; a wall clock still keeps one from hanging a
|
|
40
|
+
// save forever. The env override is for tests and unusually large decks.
|
|
41
|
+
function exportTimeoutMs() {
|
|
42
|
+
const raw = Number(process.env.CASTLE_EXPORT_TIMEOUT_MS);
|
|
43
|
+
return Number.isFinite(raw) && raw > 0 ? raw : 600_000;
|
|
44
|
+
}
|
|
45
|
+
/** `~/.castle/export-cache/<name>/`, shared by every deck on this machine. */
|
|
46
|
+
export function exportCacheRoot() {
|
|
47
|
+
return path.resolve(process.env.CASTLE_EXPORT_CACHE_ROOT ?? path.join(os.homedir(), '.castle', 'export-cache'));
|
|
48
|
+
}
|
|
49
|
+
export function exportCacheDir(name) {
|
|
50
|
+
return path.join(exportCacheRoot(), name);
|
|
51
|
+
}
|
|
52
|
+
// A real folder (made if missing) whose canonical path is `realParent/name`:
|
|
53
|
+
// never a symlink, never one that resolves elsewhere. Returns that canonical path.
|
|
54
|
+
function provenDir(parent, realParent, name) {
|
|
55
|
+
const dir = path.join(parent, name);
|
|
56
|
+
const real = path.join(realParent, name);
|
|
57
|
+
if (!lexists(dir))
|
|
58
|
+
fs.mkdirSync(dir);
|
|
59
|
+
const st = fs.lstatSync(dir);
|
|
60
|
+
if (st.isSymbolicLink() || !st.isDirectory())
|
|
61
|
+
throw new Error(`${dir} is a symlink or not a folder`);
|
|
62
|
+
if (fs.realpathSync(dir) !== real)
|
|
63
|
+
throw new Error(`${dir} resolves outside ${realParent}`);
|
|
64
|
+
return real;
|
|
65
|
+
}
|
|
66
|
+
function lexists(p) {
|
|
67
|
+
try {
|
|
68
|
+
fs.lstatSync(p);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** `<deck>/.castle/exports`, proven a real folder of the canonical deck. */
|
|
76
|
+
function deckExportsDir(deckDir) {
|
|
77
|
+
const realDeck = fs.realpathSync(deckDir);
|
|
78
|
+
const castle = provenDir(deckDir, realDeck, '.castle');
|
|
79
|
+
return provenDir(castle, castle, 'exports');
|
|
80
|
+
}
|
|
81
|
+
// Moves the exporter's finished stage into `<exports>/<name>`: the old output is
|
|
82
|
+
// renamed aside first, the stage renamed in (across filesystems, copied into
|
|
83
|
+
// the exports folder and renamed from there), and the old one removed only once
|
|
84
|
+
// it is proven a real folder inside the exports folder.
|
|
85
|
+
function installStage(stage, exportsDir, name) {
|
|
86
|
+
const final = path.join(exportsDir, name);
|
|
87
|
+
const tag = `${process.pid}-${Date.now()}`;
|
|
88
|
+
let old = null;
|
|
89
|
+
if (lexists(final)) {
|
|
90
|
+
const st = fs.lstatSync(final);
|
|
91
|
+
if (st.isSymbolicLink() || !st.isDirectory())
|
|
92
|
+
throw new Error(`${final} is a symlink or not a folder`);
|
|
93
|
+
old = path.join(exportsDir, `.old-${name}-${tag}`);
|
|
94
|
+
fs.renameSync(final, old);
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
try {
|
|
98
|
+
fs.renameSync(stage, final);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
if (e.code !== 'EXDEV')
|
|
102
|
+
throw e;
|
|
103
|
+
const incoming = path.join(exportsDir, `.incoming-${name}-${tag}`);
|
|
104
|
+
fs.cpSync(stage, incoming, { recursive: true });
|
|
105
|
+
fs.renameSync(incoming, final);
|
|
106
|
+
fs.rmSync(stage, { recursive: true, force: true });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
if (old)
|
|
111
|
+
fs.renameSync(old, final);
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
if (old && !fs.lstatSync(old).isSymbolicLink() && path.dirname(fs.realpathSync(old)) === exportsDir) {
|
|
115
|
+
fs.rmSync(old, { recursive: true, force: true });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function declaredExports(dir) {
|
|
119
|
+
const declared = readCastleJson(dir)?.exports;
|
|
120
|
+
if (!declared || typeof declared !== 'object' || Array.isArray(declared))
|
|
121
|
+
return {};
|
|
122
|
+
return Object.fromEntries(Object.entries(declared).filter(([, v]) => typeof v === 'string' && v.trim()));
|
|
123
|
+
}
|
|
124
|
+
// The CLI's own copy of a builtin pin's kit, or null: exporters run only from
|
|
125
|
+
// the kits this CLI ships, never from an imports/ copy of anything.
|
|
126
|
+
function shippedKitOf(pin) {
|
|
127
|
+
if (pin.source !== 'builtin')
|
|
128
|
+
return null;
|
|
129
|
+
const kit = typeof pin.kit === 'string' ? pin.kit : '';
|
|
130
|
+
const kits = path.resolve(getKitsDir());
|
|
131
|
+
const kitDir = path.join(kits, kit);
|
|
132
|
+
if (!kit || path.dirname(kitDir) !== kits || !fs.existsSync(path.join(kitDir, 'castle.json')))
|
|
133
|
+
return null;
|
|
134
|
+
return kitDir;
|
|
135
|
+
}
|
|
136
|
+
// The entry point's real path, when it lies under the real shipped kits folder:
|
|
137
|
+
// a symlink leading anywhere else is not one of the CLI's files.
|
|
138
|
+
function shippedModule(dir, declared) {
|
|
139
|
+
const lexical = resolveFileInside(dir, declared);
|
|
140
|
+
if (!lexical)
|
|
141
|
+
return null;
|
|
142
|
+
const real = fs.realpathSync(lexical);
|
|
143
|
+
const kits = fs.realpathSync(getKitsDir());
|
|
144
|
+
return real.startsWith(kits + path.sep) ? real : null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Every exporter that applies to this deck and may run here: each import's, in
|
|
148
|
+
* pin order, then the deck's own (only for a kit this CLI ships, as with
|
|
149
|
+
* `onCheck`). The first to claim a name keeps it.
|
|
150
|
+
*/
|
|
151
|
+
export function exportTargets(deckDir, log) {
|
|
152
|
+
const config = readCastleJson(deckDir);
|
|
153
|
+
const sources = [];
|
|
154
|
+
for (const [alias, pin] of Object.entries(config?.imports ?? {})) {
|
|
155
|
+
if (!pin)
|
|
156
|
+
continue;
|
|
157
|
+
const dir = shippedKitOf(pin);
|
|
158
|
+
if (dir)
|
|
159
|
+
sources.push({ alias, dir });
|
|
160
|
+
else if (Object.keys(declaredExports(path.join(deckDir, IMPORTS_DIR, alias))).length > 0) {
|
|
161
|
+
log(`Warning: ${alias} declares exporters, which run only from a kit this CLI ships -- skipped.`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (isShippedKitDir(deckDir))
|
|
165
|
+
sources.push({ alias: 'self', dir: deckDir });
|
|
166
|
+
const targets = [];
|
|
167
|
+
const taken = new Set();
|
|
168
|
+
for (const { alias, dir } of sources) {
|
|
169
|
+
const declared = declaredExports(dir);
|
|
170
|
+
if (Object.keys(declared).length === 0)
|
|
171
|
+
continue;
|
|
172
|
+
for (const [name, declaredPath] of Object.entries(declared)) {
|
|
173
|
+
if (!EXPORT_NAME.test(name)) {
|
|
174
|
+
log(`Warning: ${alias} declares an export named ${JSON.stringify(name)}, which is not a usable name -- skipped.`);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (taken.has(name)) {
|
|
178
|
+
log(`Warning: ${alias} declares export "${name}", which another import already declares -- skipped.`);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const modulePath = shippedModule(dir, declaredPath);
|
|
182
|
+
if (!modulePath) {
|
|
183
|
+
log(`Warning: ${alias} declares export "${name}" at "${declaredPath}", which is not a file of the kits this CLI ships -- skipped.`);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
taken.add(name);
|
|
187
|
+
targets.push({ alias, name, modulePath, outDir: path.join(deckDir, '.castle', 'exports', name), cacheDir: exportCacheDir(name) });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return targets;
|
|
191
|
+
}
|
|
192
|
+
// The last stdout line that parses as JSON: an exporter's summary.
|
|
193
|
+
function lastJson(stdout) {
|
|
194
|
+
for (const line of outputLines(stdout).reverse()) {
|
|
195
|
+
if (!line.startsWith('{') && !line.startsWith('['))
|
|
196
|
+
continue;
|
|
197
|
+
try {
|
|
198
|
+
return JSON.parse(line);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// not the summary
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
// The exporter in a process group of its own, so a timeout reaches whatever it
|
|
207
|
+
// started too: SIGTERM to the group, then SIGKILL once the grace period is up.
|
|
208
|
+
// Settles when the group's leader exits (or on the SIGKILL), never later.
|
|
209
|
+
// Out of process: cancels nothing in the save that ran before it.
|
|
210
|
+
function runChild(args, cwd, env) {
|
|
211
|
+
return new Promise((resolve) => {
|
|
212
|
+
const child = spawn(process.execPath, args, { cwd, env, detached: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
213
|
+
let stdout = '';
|
|
214
|
+
let stderr = '';
|
|
215
|
+
let timedOut = false;
|
|
216
|
+
let settled = false;
|
|
217
|
+
const take = (prev, chunk) => (prev.length >= MAX_EXPORT_OUTPUT ? prev : prev + chunk.toString('utf8'));
|
|
218
|
+
child.stdout.on('data', (c) => { stdout = take(stdout, c); });
|
|
219
|
+
child.stderr.on('data', (c) => { stderr = take(stderr, c); });
|
|
220
|
+
const signalGroup = (signal) => {
|
|
221
|
+
try {
|
|
222
|
+
if (child.pid)
|
|
223
|
+
process.kill(-child.pid, signal);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
// the group is already gone
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
let killTimer;
|
|
230
|
+
const finish = (code) => {
|
|
231
|
+
if (settled)
|
|
232
|
+
return;
|
|
233
|
+
settled = true;
|
|
234
|
+
clearTimeout(termTimer);
|
|
235
|
+
clearTimeout(killTimer);
|
|
236
|
+
// Anything the exporter left running in its group goes with it.
|
|
237
|
+
signalGroup('SIGKILL');
|
|
238
|
+
resolve({ code, stdout, stderr, timedOut });
|
|
239
|
+
};
|
|
240
|
+
const termTimer = setTimeout(() => {
|
|
241
|
+
timedOut = true;
|
|
242
|
+
signalGroup('SIGTERM');
|
|
243
|
+
killTimer = setTimeout(() => {
|
|
244
|
+
signalGroup('SIGKILL');
|
|
245
|
+
finish(null);
|
|
246
|
+
}, killGraceMs());
|
|
247
|
+
}, exportTimeoutMs());
|
|
248
|
+
child.on('error', (e) => {
|
|
249
|
+
stderr += String(e);
|
|
250
|
+
finish(null);
|
|
251
|
+
});
|
|
252
|
+
// Output can still be in the pipes when the leader exits: wait for them to
|
|
253
|
+
// close, but not on a grandchild that kept them open.
|
|
254
|
+
child.on('exit', (code) => {
|
|
255
|
+
child.on('close', () => finish(code));
|
|
256
|
+
setTimeout(() => finish(code), 1_000).unref();
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
async function runOne(deckDir, target, log) {
|
|
261
|
+
const refuse = (error) => {
|
|
262
|
+
log(`${target.alias} export ${target.name} ${error}`);
|
|
263
|
+
return { alias: target.alias, name: target.name, ok: false, summary: null, error };
|
|
264
|
+
};
|
|
265
|
+
// The deck side is proven before anything runs; the exporter itself writes
|
|
266
|
+
// only into a fresh stage under the cache root and into the cache.
|
|
267
|
+
let exportsDir;
|
|
268
|
+
let cacheDir;
|
|
269
|
+
let stage;
|
|
270
|
+
try {
|
|
271
|
+
exportsDir = deckExportsDir(deckDir);
|
|
272
|
+
const prev = path.join(exportsDir, target.name);
|
|
273
|
+
if (lexists(prev) && (fs.lstatSync(prev).isSymbolicLink() || !fs.lstatSync(prev).isDirectory())) {
|
|
274
|
+
throw new Error(`${prev} is a symlink or not a folder`);
|
|
275
|
+
}
|
|
276
|
+
const root = exportCacheRoot();
|
|
277
|
+
fs.mkdirSync(root, { recursive: true });
|
|
278
|
+
cacheDir = provenDir(root, fs.realpathSync(root), target.name);
|
|
279
|
+
stage = fs.mkdtempSync(path.join(fs.realpathSync(root), `.stage-${target.name}-`));
|
|
280
|
+
}
|
|
281
|
+
catch (e) {
|
|
282
|
+
return refuse(`refused its output folders: ${e instanceof Error ? e.message : String(e)}`);
|
|
283
|
+
}
|
|
284
|
+
const prevDir = path.join(exportsDir, target.name);
|
|
285
|
+
const { getCliVersion } = await import('./init.js');
|
|
286
|
+
const args = [target.modulePath, '--deck', deckDir, '--stage', stage, '--cache', cacheDir];
|
|
287
|
+
const env = {
|
|
288
|
+
...process.env,
|
|
289
|
+
CASTLE_EXPORT_NAME: target.name,
|
|
290
|
+
CASTLE_EXPORT_DECK_DIR: deckDir,
|
|
291
|
+
CASTLE_EXPORT_STAGE_DIR: stage,
|
|
292
|
+
CASTLE_EXPORT_CACHE_DIR: cacheDir,
|
|
293
|
+
CASTLE_EXPORT_PREV_DIR: lexists(prevDir) ? prevDir : '',
|
|
294
|
+
// The only kit code an exporter may load: this CLI's own kits.
|
|
295
|
+
CASTLE_EXPORT_SHIPPED_KITS: path.resolve(getKitsDir()),
|
|
296
|
+
// The kits' `three`, as this CLI ships it (../scripts/vendor-three.mjs), so an exporter never
|
|
297
|
+
// loads a deck's node_modules. Absent in a checkout that has not built the CLI.
|
|
298
|
+
CASTLE_EXPORT_THREE_DIR: fs.existsSync(path.join(getPackageRoot(), 'vendor/three/build/three.module.js')) ? path.join(getPackageRoot(), 'vendor/three') : '',
|
|
299
|
+
CASTLE_EXPORT_CLI_VERSION: getCliVersion(),
|
|
300
|
+
};
|
|
301
|
+
const result = await runChild(args, deckDir, env);
|
|
302
|
+
const summary = lastJson(result.stdout);
|
|
303
|
+
if (!result.timedOut && result.code === 0) {
|
|
304
|
+
try {
|
|
305
|
+
installStage(stage, deckExportsDir(deckDir), target.name);
|
|
306
|
+
return { alias: target.alias, name: target.name, ok: true, summary };
|
|
307
|
+
}
|
|
308
|
+
catch (e) {
|
|
309
|
+
fs.rmSync(stage, { recursive: true, force: true });
|
|
310
|
+
return refuse(`could not be put in place: ${e instanceof Error ? e.message : String(e)}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
fs.rmSync(stage, { recursive: true, force: true });
|
|
314
|
+
const error = result.timedOut
|
|
315
|
+
? `it did not finish in ${exportTimeoutMs()}ms and was stopped`
|
|
316
|
+
: outputLines(result.stderr).slice(-8).join('\n') || `it exited with code ${result.code}`;
|
|
317
|
+
log(`${target.alias} export ${target.name} failed: ${error}`);
|
|
318
|
+
return { alias: target.alias, name: target.name, ok: false, summary, error };
|
|
319
|
+
}
|
|
320
|
+
/** Run every applicable exporter, one at a time. */
|
|
321
|
+
export async function runDeckExports(deckDir, log = (message) => console.log(message)) {
|
|
322
|
+
const outcomes = [];
|
|
323
|
+
for (const target of exportTargets(deckDir, log)) {
|
|
324
|
+
outcomes.push(await runOne(deckDir, target, log));
|
|
325
|
+
}
|
|
326
|
+
return outcomes;
|
|
327
|
+
}
|
|
328
|
+
/** `castle-web export [dir]`: prints each summary; exits 1 when one failed. */
|
|
329
|
+
export async function exportCommand(dir) {
|
|
330
|
+
const deckDir = path.resolve(dir);
|
|
331
|
+
if (!fs.existsSync(path.join(deckDir, 'castle.json'))) {
|
|
332
|
+
console.error(`No castle.json in ${deckDir} -- is this a deck?`);
|
|
333
|
+
process.exit(1);
|
|
334
|
+
}
|
|
335
|
+
const outcomes = await runDeckExports(deckDir);
|
|
336
|
+
if (outcomes.length === 0) {
|
|
337
|
+
console.log('Nothing to export: no import of this deck declares an exporter.');
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
for (const o of outcomes) {
|
|
341
|
+
console.log(`${o.ok ? 'Exported' : 'FAILED'} ${o.name} (${o.alias}): ${JSON.stringify(o.summary)}`);
|
|
342
|
+
}
|
|
343
|
+
if (outcomes.some((o) => !o.ok))
|
|
344
|
+
process.exit(1);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* After a successful save, under CASTLE_SAVE_EXPORTS=1 only. Never throws:
|
|
348
|
+
* whatever an exporter does, the save already happened and stands.
|
|
349
|
+
*/
|
|
350
|
+
export async function runSaveExports(deckDir) {
|
|
351
|
+
if (process.env[SAVE_EXPORTS_ENV] !== '1')
|
|
352
|
+
return;
|
|
353
|
+
try {
|
|
354
|
+
const outcomes = await runDeckExports(deckDir, (message) => console.warn(message));
|
|
355
|
+
for (const o of outcomes) {
|
|
356
|
+
if (o.ok)
|
|
357
|
+
console.log(`Exported ${o.name} (${o.alias}).`);
|
|
358
|
+
else
|
|
359
|
+
console.warn(`Warning: export ${o.name} (${o.alias}) failed; the save is unaffected.`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
catch (e) {
|
|
363
|
+
console.warn(`Warning: exporters did not run (${e instanceof Error ? e.message : String(e)}); the save is unaffected.`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
@@ -18,6 +18,7 @@ export interface CheckTarget {
|
|
|
18
18
|
/** The import's pin, or null for the deck's own check. */
|
|
19
19
|
pin: DeckImport | null;
|
|
20
20
|
}
|
|
21
|
+
export declare function isShippedKitDir(dir: string): boolean;
|
|
21
22
|
/**
|
|
22
23
|
* Run every applicable `onCheck`, one at a time, and collect what they found.
|
|
23
24
|
* Warnings are logged here; errors are returned for the caller to refuse on --
|
package/dist/importCheckHook.js
CHANGED
|
@@ -20,7 +20,7 @@ import { importIsOnTrustedAccount, TRUSTED_IMPORT_ACCOUNT } from './importTrust.
|
|
|
20
20
|
/** The alias a deck's OWN `onCheck` is reported under. */
|
|
21
21
|
export const SELF_CHECK_ALIAS = 'self';
|
|
22
22
|
// Whether `dir` is one of the kits this CLI ships, checked as itself.
|
|
23
|
-
function isShippedKitDir(dir) {
|
|
23
|
+
export function isShippedKitDir(dir) {
|
|
24
24
|
const kits = path.resolve(getKitsDir());
|
|
25
25
|
const rel = path.relative(kits, path.resolve(dir));
|
|
26
26
|
return !!rel && !rel.startsWith('..') && !path.isAbsolute(rel) && !rel.includes(path.sep);
|
package/dist/index.js
CHANGED
|
@@ -197,6 +197,7 @@ function usage() {
|
|
|
197
197
|
castle-web update-import [alias] [dir] [--check] [--revert] (re-fetches imports; no alias means all)
|
|
198
198
|
castle-web install [dir]
|
|
199
199
|
castle-web check [dir] [--pin-installed-imports] (bundles the deck and its server, then runs each import's onCheck -- the same gates save-deck runs)
|
|
200
|
+
castle-web export [dir] (runs each import's save-time exporters (castle.json "exports") into .castle/exports/<name>/; save-deck runs them only with CASTLE_SAVE_EXPORTS=1)
|
|
200
201
|
castle-web bundle-chunks [dir] --out DIR [--base-url URL] (writes the classic chunked bundle: index.html plus <sha256>.js chunks named at URL, default ./)
|
|
201
202
|
castle-web save-version [-m MESSAGE] [paths...] [--dir DIR] (no paths saves the whole deck)
|
|
202
203
|
castle-web list-versions [version] [--dir DIR] (defaults to the latest version)
|
|
@@ -640,6 +641,10 @@ async function main() {
|
|
|
640
641
|
await check(findPositionalDir(), { pinInstalledImports: hasFlag('--pin-installed-imports') });
|
|
641
642
|
break;
|
|
642
643
|
}
|
|
644
|
+
case 'export': {
|
|
645
|
+
await (await import('./deckExports.js')).exportCommand(findPositionalDir());
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
643
648
|
case 'bundle-chunks':
|
|
644
649
|
await (await import('./bundle.js')).bundleChunksCommand(findPositionalDir(), getFlagValue('--out'), getFlagValue('--base-url'));
|
|
645
650
|
break;
|
package/dist/init.js
CHANGED
|
@@ -64,7 +64,7 @@ const BARE_SCAFFOLDS = [
|
|
|
64
64
|
// Registry version of castle-web-sdk to inject when scaffolding from a
|
|
65
65
|
// globally-installed castle-web (not from inside the workspace). Bumped
|
|
66
66
|
// alongside cli/sdk version bumps.
|
|
67
|
-
const PUBLISHED_SDK_VERSION = '0.4.
|
|
67
|
+
const PUBLISHED_SDK_VERSION = '0.4.51';
|
|
68
68
|
// Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
|
|
69
69
|
// face can ship without a cli release, and a caret range means an existing
|
|
70
70
|
// deck's next install picks it up. Nothing here has to move when it does.
|
|
@@ -398,6 +398,7 @@ const STARTER_CONFIG_RESERVED = new Set([
|
|
|
398
398
|
'importWhenRemixed',
|
|
399
399
|
'onUpdate',
|
|
400
400
|
'onCheck',
|
|
401
|
+
'exports',
|
|
401
402
|
'main',
|
|
402
403
|
'starterScene',
|
|
403
404
|
'starterFiles',
|
package/dist/save-deck.js
CHANGED
|
@@ -11,6 +11,7 @@ import { importChecksFailedMessage, runImportChecks } from './importCheckHook.js
|
|
|
11
11
|
import { selectSaveCover } from './saveCover.js';
|
|
12
12
|
import { COVER_FILE } from './localPaths.js';
|
|
13
13
|
import { buildServerBundle } from './serverBundle.js';
|
|
14
|
+
import { runSaveExports } from './deckExports.js';
|
|
14
15
|
import { buildContentPack } from './contentPack.js';
|
|
15
16
|
import { importRegressionMessage, importRegressions, savedDeckImportPins } from './importRegression.js';
|
|
16
17
|
import { isSandboxEnv } from './cloudGit.js';
|
|
@@ -824,6 +825,9 @@ async function saveDeckAfterValidation(dir, opts, projectDir, visibility) {
|
|
|
824
825
|
console.error(`Could not record the saved version: ${e instanceof Error ? e.message : String(e)}`);
|
|
825
826
|
}
|
|
826
827
|
await clearingExperiments?.settle();
|
|
828
|
+
// Save-time exporters (deckExports.ts): off unless CASTLE_SAVE_EXPORTS=1,
|
|
829
|
+
// and never able to fail the save that just happened.
|
|
830
|
+
await runSaveExports(projectDir);
|
|
827
831
|
}
|
|
828
832
|
catch (e) {
|
|
829
833
|
const code = e?.extensions?.code ?? '';
|
package/kits/base/castle.json
CHANGED
package/kits/base/sdk/README.md
CHANGED
|
@@ -18,6 +18,7 @@ import { setup, initCard, Store, Leaderboard } from "castle-web-sdk";
|
|
|
18
18
|
- [Store](#store)
|
|
19
19
|
- [Storage](#storage)
|
|
20
20
|
- [SharedStorage](#sharedstorage)
|
|
21
|
+
- [LocalCache](#localcache)
|
|
21
22
|
- [Leaderboard](#leaderboard)
|
|
22
23
|
- [Time](#time)
|
|
23
24
|
- [User](#user)
|
|
@@ -853,6 +854,44 @@ const { color } = await Store.user(otherUserId).get(["color"]);
|
|
|
853
854
|
await Store.me.set({ color: "red" });
|
|
854
855
|
```
|
|
855
856
|
|
|
857
|
+
## LocalCache
|
|
858
|
+
|
|
859
|
+
`LocalCache` keeps bytes and text on the player's device, for things the
|
|
860
|
+
deck can rebuild: downloaded or unpacked assets, compiled data. Entries
|
|
861
|
+
belong to the deck whose code is running. A hub town's doors change the
|
|
862
|
+
place but not the code, so the games played through them use the town's
|
|
863
|
+
entries. In the app, decks loaded from the same web address share entries.
|
|
864
|
+
|
|
865
|
+
Any entry can be gone at any time. Each deck has 20 MB; past that, its own
|
|
866
|
+
least recently used entries are evicted. On the web all decks
|
|
867
|
+
together have 300 MB; past that, the least recently used entries of any
|
|
868
|
+
deck are evicted. Both are less when the device is short of space. The
|
|
869
|
+
browser or app may also clear the whole cache. Never keep anything here
|
|
870
|
+
that the deck cannot make again; use [`Store`](#store) for that.
|
|
871
|
+
|
|
872
|
+
- **`LocalCache.getBinary(key): Promise<ArrayBuffer | null>`** — the bytes
|
|
873
|
+
at `key`, or `null` if there are none. A text entry comes back as UTF-8.
|
|
874
|
+
- **`LocalCache.getText(key): Promise<string | null>`** — the text at
|
|
875
|
+
`key`. A bytes entry is decoded as UTF-8.
|
|
876
|
+
- **`LocalCache.set(key, value): Promise<void>`** — stores an
|
|
877
|
+
`ArrayBuffer`, a `Uint8Array` or a string. An `ArrayBuffer` is moved, not
|
|
878
|
+
copied, and is empty (detached) once `set` returns; pass `buffer.slice(0)`
|
|
879
|
+
to keep one. A `Uint8Array` that covers its whole buffer moves that buffer
|
|
880
|
+
the same way; one over part of a buffer is copied.
|
|
881
|
+
- **`LocalCache.remove(key): Promise<void>`** — removes `key`.
|
|
882
|
+
|
|
883
|
+
Keys are 1 to 1024 characters, without NUL; a bad key or value throws.
|
|
884
|
+
Nothing else does: a get that cannot read returns `null`, and a set that
|
|
885
|
+
cannot write stores nothing.
|
|
886
|
+
|
|
887
|
+
```js
|
|
888
|
+
let bytes = await LocalCache.getBinary("town-v3");
|
|
889
|
+
if (!bytes) {
|
|
890
|
+
bytes = await unpackTown();
|
|
891
|
+
LocalCache.set("town-v3", bytes.slice(0));
|
|
892
|
+
}
|
|
893
|
+
```
|
|
894
|
+
|
|
856
895
|
## Leaderboard
|
|
857
896
|
|
|
858
897
|
`Leaderboard` ranks players by a numeric score, per deck and per
|
|
@@ -1361,6 +1400,14 @@ the signed-in account id. A new host without native sign-in support returns
|
|
|
1361
1400
|
- `Hub.onBack(listener)` hears the host's Back control, which a game cannot hide.
|
|
1362
1401
|
Answer it with `Hub.back()` behind the door animation; a host that hears
|
|
1363
1402
|
nothing takes the player home itself. Returns an unsubscribe function.
|
|
1403
|
+
- `Hub.onGo(listener)` hears the host ask to take the player through a door,
|
|
1404
|
+
e.g. a trip begun outside this page. The listener gets
|
|
1405
|
+
`{ doorId, owner, title, party }`: `owner` is whose House a House door leads
|
|
1406
|
+
to (or null), `title` the host's name for the door (or null), `party` how many
|
|
1407
|
+
travel (1 when the host does not say). A hub kit answers it like a fired pad:
|
|
1408
|
+
`Hub.go(doorId)` (with `{ ownerUserId: owner }` when set) behind its door
|
|
1409
|
+
animation. Hosts that never send it are the norm. Returns an unsubscribe
|
|
1410
|
+
function.
|
|
1364
1411
|
|
|
1365
1412
|
A player Castle has barred from the hub is refused at every hub door and at the
|
|
1366
1413
|
town itself with `CastleError` code `CAULDRON_HUB_BANNED` (from `Hub.go`,
|
|
@@ -13,7 +13,7 @@ export { deckPrefixOf, IMPORTS_DIR, IMPORTS_PREFIX, isImportedFile, resolveDeckF
|
|
|
13
13
|
export { Haptics } from "./haptics";
|
|
14
14
|
export type { CastleHapticsApi, HapticsResult, HapticsStatus, HapticStyle } from "./haptics";
|
|
15
15
|
export { Hub } from "./hub";
|
|
16
|
-
export type { CastleHubApi, HubBackResult, HubCancelResult, HubCancelStatus, HubChatMessage, HubChatResult, HubDoor, HubDoorsResult, HubFriend, HubFriendsResult, HubInviteResult, HubCanInviteResult, HubInviteArrivalResult, HubHeartsResult, HubGoParams, HubSignInParams, HubSignInResult, HubGoResult, HubHandoffResult, HubHandoffStatus, HubJumpResult, HubPlacementKind, HubReportResult, HubSayResult, } from "./hub";
|
|
16
|
+
export type { CastleHubApi, HubBackResult, HubCancelResult, HubCancelStatus, HubChatMessage, HubChatResult, HubDoor, HubDoorsResult, HubFriend, HubFriendsResult, HubInviteResult, HubCanInviteResult, HubInviteArrivalResult, HubHeartsResult, HubGoParams, HubGoRequest, HubSignInParams, HubSignInResult, HubGoResult, HubHandoffResult, HubHandoffStatus, HubJumpResult, HubPlacementKind, HubReportResult, HubSayResult, } from "./hub";
|
|
17
17
|
export { Social } from "./social";
|
|
18
18
|
export type { CastleSocialApi, SocialFriend, SocialPresence } from "./social";
|
|
19
19
|
export { Party } from "./party";
|
|
@@ -42,6 +42,8 @@ export { cardUnit, fitStage, fovForAspect, getDisplay } from "./display";
|
|
|
42
42
|
export type { DeckDisplay, DeckLayout, DeckOrientation } from "./display";
|
|
43
43
|
export { flushSaves, hasPendingSave, onSaveState, writeFile, } from "./saveQueue";
|
|
44
44
|
export type { SaveState } from "./saveQueue";
|
|
45
|
+
export { LocalCache } from "./localCache";
|
|
46
|
+
export type { LocalCacheApi } from "./localCache";
|
|
45
47
|
export { SharedStorage, Storage } from "./storage";
|
|
46
48
|
export { Store } from "./store";
|
|
47
49
|
export type { CastleStoreApi, StoreBoardApi, StoreBoardScore, StoreListEntry, StoreListOptions, StoreListPage, StoreAllowance, StoreScopeApi, StoreUsage, } from "./store";
|
package/kits/base/sdk/castle.js
CHANGED
|
@@ -22,6 +22,7 @@ export { Portal } from "./portal";
|
|
|
22
22
|
export { CARD_RATIO, deleteFile, fileUrl, initCard, onBeforeRestart, onFilesChanged, onSaveReloadState, openFile, renameFile, requestReload, setup, takeReloadState, writeFileOnce, } from "./runtime";
|
|
23
23
|
export { cardUnit, fitStage, fovForAspect, getDisplay } from "./display";
|
|
24
24
|
export { flushSaves, hasPendingSave, onSaveState, writeFile, } from "./saveQueue";
|
|
25
|
+
export { LocalCache } from "./localCache";
|
|
25
26
|
export { SharedStorage, Storage } from "./storage";
|
|
26
27
|
export { Store } from "./store";
|
|
27
28
|
export { Time } from "./time";
|
|
@@ -348,9 +348,18 @@ export type HubCancelStatus = "cancelled" | "expired" | "none" | "unavailable";
|
|
|
348
348
|
export interface HubCancelResult {
|
|
349
349
|
status: HubCancelStatus;
|
|
350
350
|
}
|
|
351
|
-
export type
|
|
351
|
+
export type HubBackEvent = {
|
|
352
352
|
type: "back";
|
|
353
353
|
};
|
|
354
|
+
export type HubGoEvent = {
|
|
355
|
+
type: "go";
|
|
356
|
+
doorId: string;
|
|
357
|
+
owner?: string;
|
|
358
|
+
title?: string;
|
|
359
|
+
party?: number;
|
|
360
|
+
};
|
|
361
|
+
export type HubEvent = HubBackEvent | HubGoEvent;
|
|
362
|
+
export declare const HUB_GO_DOOR_ID_MAX = 128;
|
|
354
363
|
export interface HubEventEnvelope {
|
|
355
364
|
castleSdk: typeof CASTLE_SDK_PROTOCOL;
|
|
356
365
|
hub: HubEvent;
|
|
@@ -791,6 +800,16 @@ export interface CommandParams {
|
|
|
791
800
|
};
|
|
792
801
|
"cauldronStorage.usage": Record<string, never>;
|
|
793
802
|
"lifecycle.restoreState": Record<string, never>;
|
|
803
|
+
"localCache.get": {
|
|
804
|
+
key: string;
|
|
805
|
+
};
|
|
806
|
+
"localCache.set": {
|
|
807
|
+
key: string;
|
|
808
|
+
value: ArrayBuffer | string;
|
|
809
|
+
};
|
|
810
|
+
"localCache.remove": {
|
|
811
|
+
key: string;
|
|
812
|
+
};
|
|
794
813
|
}
|
|
795
814
|
export interface CommandResult {
|
|
796
815
|
"agent.chat": AgentChatResult;
|
|
@@ -938,6 +957,11 @@ export interface CommandResult {
|
|
|
938
957
|
usage: StoreAllowances;
|
|
939
958
|
};
|
|
940
959
|
"lifecycle.restoreState": LifecycleRestoreStateResult;
|
|
960
|
+
"localCache.get": {
|
|
961
|
+
value: ArrayBuffer | string | null;
|
|
962
|
+
};
|
|
963
|
+
"localCache.set": Record<string, never>;
|
|
964
|
+
"localCache.remove": Record<string, never>;
|
|
941
965
|
}
|
|
942
966
|
export interface UserPayload {
|
|
943
967
|
userId: string;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// Marker + protocol version. Doubles as a discriminator so host messages can't
|
|
7
7
|
// be confused with embed.js `castlexyz:` strings or RN console messages.
|
|
8
8
|
export const CASTLE_SDK_PROTOCOL = 1;
|
|
9
|
+
export const HUB_GO_DOOR_ID_MAX = 128;
|
|
9
10
|
export function hubEventFrom(value) {
|
|
10
11
|
if (typeof value !== "object" || value === null)
|
|
11
12
|
return null;
|
|
@@ -15,7 +16,29 @@ export function hubEventFrom(value) {
|
|
|
15
16
|
const event = record.hub;
|
|
16
17
|
if (typeof event !== "object" || event === null)
|
|
17
18
|
return null;
|
|
18
|
-
|
|
19
|
+
if (event.type === "back")
|
|
20
|
+
return { type: "back" };
|
|
21
|
+
if (event.type === "go")
|
|
22
|
+
return hubGoEventFrom(event);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
function hubGoEventFrom(event) {
|
|
26
|
+
const { doorId, owner, title, party } = event;
|
|
27
|
+
if (typeof doorId !== "string" || doorId.length === 0 || doorId.length > HUB_GO_DOOR_ID_MAX)
|
|
28
|
+
return null;
|
|
29
|
+
const go = { type: "go", doorId };
|
|
30
|
+
// A bad owner refuses the whole event: a trip to the wrong House is worse
|
|
31
|
+
// than none.
|
|
32
|
+
if (owner !== undefined && owner !== null) {
|
|
33
|
+
if (typeof owner !== "string" || !/^[1-9]\d{0,9}$/.test(owner))
|
|
34
|
+
return null;
|
|
35
|
+
go.owner = owner;
|
|
36
|
+
}
|
|
37
|
+
if (typeof title === "string")
|
|
38
|
+
go.title = title;
|
|
39
|
+
if (typeof party === "number" && Number.isInteger(party) && party > 0)
|
|
40
|
+
go.party = party;
|
|
41
|
+
return go;
|
|
19
42
|
}
|
|
20
43
|
// How long the deck waits for a reply to these commands, in place of the
|
|
21
44
|
// data-command timeout. A deck list fetches every cover on the list. A host
|
|
@@ -32,6 +55,11 @@ export const COMMAND_TIMEOUTS_MS = {
|
|
|
32
55
|
// Native auth may include a provider handoff, but it must not leave a deck
|
|
33
56
|
// waiting forever if the host loses the completion callback.
|
|
34
57
|
"hub.signIn": 120_000,
|
|
58
|
+
// A large entry is an IndexedDB read or write plus a copy into the other
|
|
59
|
+
// frame, and can wait behind other tabs' writes to the same store.
|
|
60
|
+
"localCache.get": 60_000,
|
|
61
|
+
"localCache.set": 60_000,
|
|
62
|
+
"localCache.remove": 60_000,
|
|
35
63
|
};
|
|
36
64
|
// Once a host streams a command, each stream envelope restarts the wait at this
|
|
37
65
|
// length instead. The deck-agent service sends a heartbeat every 15 seconds, and the host
|
package/kits/base/sdk/hub.d.ts
CHANGED
|
@@ -112,5 +112,22 @@ export interface CastleHubApi {
|
|
|
112
112
|
* takes the player home itself. Returns an unsubscribe function.
|
|
113
113
|
*/
|
|
114
114
|
onBack(listener: () => void): () => void;
|
|
115
|
+
/**
|
|
116
|
+
* The host asked to take the player through a door, e.g. a trip begun
|
|
117
|
+
* outside this page. A hub kit answers it like a fired pad: `go(doorId)`
|
|
118
|
+
* behind its door animation, passing `owner` as `ownerUserId` when set.
|
|
119
|
+
* `owner` names whose House a House door leads to, or null; `title` is the
|
|
120
|
+
* host's name for the door, or null; `party` is how many travel (1 when
|
|
121
|
+
* the host does not say). Hosts
|
|
122
|
+
* that never send it are the norm. Returns an unsubscribe function.
|
|
123
|
+
*/
|
|
124
|
+
onGo(listener: (go: HubGoRequest) => void): () => void;
|
|
125
|
+
}
|
|
126
|
+
/** A host's request to go through a door (see `Hub.onGo`). */
|
|
127
|
+
export interface HubGoRequest {
|
|
128
|
+
doorId: string;
|
|
129
|
+
owner: string | null;
|
|
130
|
+
title: string | null;
|
|
131
|
+
party: number;
|
|
115
132
|
}
|
|
116
133
|
export declare const Hub: CastleHubApi;
|