cajonzero 0.1.3 → 0.2.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 +36 -53
- package/dist/bin/cj0.js +2145 -1553
- package/dist/catalog-BRO-mQoP.d.ts +67 -0
- package/dist/{config-B32NDXlr.d.ts → config-glwUbUbx.d.ts} +1 -1
- package/dist/core.d.ts +10 -7
- package/dist/core.js +15035 -312
- package/dist/index.d.ts +7 -5
- package/dist/index.js +31958 -9898
- package/dist/maps.d.ts +182 -0
- package/dist/maps.js +14062 -0
- package/dist/{providers-BwJKzGkd.d.ts → providers-Bu0-iMVs.d.ts} +114 -58
- package/dist/quickjs.wasm +0 -0
- package/dist/scaffold.d.ts +18 -15
- package/dist/scaffold.js +67 -45
- package/dist/serve.d.ts +2 -1
- package/dist/serve.js +32749 -10689
- package/dist/ui/assets/index-Bf4Kjuyg.js +4404 -0
- package/dist/ui/assets/index-ZzhH55rc.css +2 -0
- package/dist/ui/assets/{main-DTcEV4JE.js → main-DB66UjcY.js} +4 -4
- package/dist/ui/assets/{voxel.worker-CvX1GY4o.js → voxel.worker-BFiKMi1W.js} +1 -1
- package/dist/ui/index.html +2 -2
- package/package.json +103 -95
- package/dist/ui/assets/index-Bhv7LV8L.css +0 -2
- package/dist/ui/assets/index-CNHWg0_t.js +0 -4404
package/dist/maps.d.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { MapEntry, MapCatalog } from './core.js';
|
|
2
|
+
|
|
3
|
+
interface BoxplayFile {
|
|
4
|
+
path: string;
|
|
5
|
+
data: Uint8Array;
|
|
6
|
+
size: number;
|
|
7
|
+
}
|
|
8
|
+
interface BoxplayBundleMember {
|
|
9
|
+
id: string;
|
|
10
|
+
permanentMapId?: string;
|
|
11
|
+
publicId?: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
mapRole?: string;
|
|
14
|
+
mainProjectId?: string;
|
|
15
|
+
}
|
|
16
|
+
interface BoxplayBundle {
|
|
17
|
+
formatVersion: number;
|
|
18
|
+
type: string;
|
|
19
|
+
mapGroupId: string;
|
|
20
|
+
permanentMapGroupId?: string;
|
|
21
|
+
mainProjectId?: string;
|
|
22
|
+
version: string;
|
|
23
|
+
createdAt?: string;
|
|
24
|
+
members: BoxplayBundleMember[];
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
interface BoxplayWorld {
|
|
28
|
+
worldId: string;
|
|
29
|
+
manifest: Record<string, unknown>;
|
|
30
|
+
dataFiles: string[];
|
|
31
|
+
}
|
|
32
|
+
interface BoxplayArchive {
|
|
33
|
+
bundle: BoxplayBundle;
|
|
34
|
+
worlds: BoxplayWorld[];
|
|
35
|
+
files: BoxplayFile[];
|
|
36
|
+
expandedBytes: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* cajonzero — precomputed world-seed packs.
|
|
41
|
+
*
|
|
42
|
+
* Resolving a map graph over HTTP takes one request per blob (a real map can be
|
|
43
|
+
* 100+ requests and a large amount of parsing). That is fine on a Node machine
|
|
44
|
+
* but expensive against Worker quotas, so `cj0 add` / `cj0 update` resolve the
|
|
45
|
+
* graph once on the operator's machine and write a single `seed.json[.gz]`
|
|
46
|
+
* next to the map root.
|
|
47
|
+
*
|
|
48
|
+
* The room then performs **one** fetch, `JSON.parse`s the seed, and decodes the
|
|
49
|
+
* embedded block palette — no graph traversal, no per-blob requests.
|
|
50
|
+
*
|
|
51
|
+
* Format (JSON):
|
|
52
|
+
*
|
|
53
|
+
* {
|
|
54
|
+
* "format": "cajonzero-seed",
|
|
55
|
+
* "version": 1,
|
|
56
|
+
* "mapId": "worlds/<id> directory name",
|
|
57
|
+
* "seed": { ...WorldSeed, "voxels": { ..., "chunkBlobs": ["<base64>"] } },
|
|
58
|
+
* "blockInfo": "<base64 raw BlockInfo blob>" // optional
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* `blockInfo` is the *raw* palette blob (not the decoded schema object, which
|
|
62
|
+
* is not JSON-safe); the loader decodes it with the same schema the graph path
|
|
63
|
+
* uses. Binary fields are base64 (`atob`/`btoa`, available in workerd and Node).
|
|
64
|
+
*
|
|
65
|
+
* Worker-safe: no Node globals.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/** Marker for the private (server-only) scripts pack. */
|
|
69
|
+
declare const SCRIPT_PACK_FORMAT = "cajonzero-scripts";
|
|
70
|
+
|
|
71
|
+
/** Default catalog path, relative to the project root. */
|
|
72
|
+
declare const DEFAULT_MAPS_FILE = "cajonzero/maps.json";
|
|
73
|
+
/** Default static-asset directory, relative to the project root. */
|
|
74
|
+
declare const DEFAULT_PUBLIC_DIR = "public";
|
|
75
|
+
/** Default private script-pack directory, relative to the project root. */
|
|
76
|
+
declare const DEFAULT_SCRIPTS_DIR: string;
|
|
77
|
+
/** Stable error codes so callers never string-match messages. */
|
|
78
|
+
type MapImportErrorCode = "ARCHIVE_NOT_FOUND" | "MAP_NOT_FOUND" | "SLUG_EXISTS" | "INVALID_SLUG" | "INVALID_ARCHIVE" | "INVALID_CATALOG" | "INVALID_ROOT";
|
|
79
|
+
/** Typed failure thrown by the map-import helpers. */
|
|
80
|
+
declare class MapImportError extends Error {
|
|
81
|
+
readonly code: MapImportErrorCode;
|
|
82
|
+
constructor(code: MapImportErrorCode, message: string);
|
|
83
|
+
}
|
|
84
|
+
/** Options shared by {@link addMap} and {@link updateMap}. */
|
|
85
|
+
interface MapImportOptions {
|
|
86
|
+
/** Project directory (default: `process.cwd()`). */
|
|
87
|
+
readonly cwd?: string;
|
|
88
|
+
/** Catalog path, relative to `cwd` (default `cajonzero/maps.json`). */
|
|
89
|
+
readonly maps?: string;
|
|
90
|
+
/** Static-asset directory, relative to `cwd` (default `public`). */
|
|
91
|
+
readonly publicDir?: string;
|
|
92
|
+
/** Private script-pack directory, relative to `cwd`. */
|
|
93
|
+
readonly scriptsDir?: string;
|
|
94
|
+
/** Override the derived slug (`add` only; `update` uses its argument). */
|
|
95
|
+
readonly slug?: string;
|
|
96
|
+
/** Write gzip packs (default `true`; `false` writes plain JSON). */
|
|
97
|
+
readonly gzip?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* `update` only: reset a manually changed `root`/`assetRoot` back to
|
|
100
|
+
* `/maps/<slug>/`. Ignored by `add`.
|
|
101
|
+
*/
|
|
102
|
+
readonly resetRoot?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/** One imported map, as returned to the CLI. */
|
|
105
|
+
interface MapImportResult {
|
|
106
|
+
readonly action: "add" | "update";
|
|
107
|
+
readonly slug: string;
|
|
108
|
+
readonly root: string;
|
|
109
|
+
readonly worldId: string;
|
|
110
|
+
readonly mapId: string;
|
|
111
|
+
readonly name?: string;
|
|
112
|
+
readonly version?: string;
|
|
113
|
+
/** Absolute path of the written map directory. */
|
|
114
|
+
readonly publicDir: string;
|
|
115
|
+
/** Absolute path of the public seed pack. */
|
|
116
|
+
readonly seedPack: string;
|
|
117
|
+
/** Absolute path of the private script pack (`undefined` when no scripts). */
|
|
118
|
+
readonly scriptsPack?: string;
|
|
119
|
+
/** Project-relative private script file recorded in `maps.json`. */
|
|
120
|
+
readonly scriptsFile?: string;
|
|
121
|
+
/** Public files written, including the seed pack. */
|
|
122
|
+
readonly files: number;
|
|
123
|
+
/** Public bytes written, including the seed pack. */
|
|
124
|
+
readonly bytes: number;
|
|
125
|
+
readonly seedPackBytes: number;
|
|
126
|
+
readonly scriptModules: number;
|
|
127
|
+
readonly warnings: readonly string[];
|
|
128
|
+
}
|
|
129
|
+
/** One catalog row for `cj0 list`. */
|
|
130
|
+
interface MapListEntry {
|
|
131
|
+
readonly slug: string;
|
|
132
|
+
readonly root: string;
|
|
133
|
+
readonly worldId?: string;
|
|
134
|
+
readonly name?: string;
|
|
135
|
+
readonly version?: string;
|
|
136
|
+
/** `true` when `public/maps/<slug>/` exists locally. */
|
|
137
|
+
readonly imported: boolean;
|
|
138
|
+
/** `true` when the public seed pack is present. */
|
|
139
|
+
readonly seeded: boolean;
|
|
140
|
+
/** `true` when a private script pack exists. */
|
|
141
|
+
readonly hasScripts: boolean;
|
|
142
|
+
}
|
|
143
|
+
/** Result of {@link removeMap}. */
|
|
144
|
+
interface MapRemoveResult {
|
|
145
|
+
readonly slug: string;
|
|
146
|
+
readonly removedDir?: string;
|
|
147
|
+
readonly removedScripts: readonly string[];
|
|
148
|
+
}
|
|
149
|
+
/** Read a catalog file (BOM-tolerant) or the empty catalog when absent. */
|
|
150
|
+
declare function readMapCatalogFile(mapsPath: string): MapCatalog;
|
|
151
|
+
/** Derive a catalog slug from the archive's own metadata. */
|
|
152
|
+
declare function deriveMapSlug(archive: BoxplayArchive, override?: string): string;
|
|
153
|
+
/** Lowercase + sanitize arbitrary archive metadata into the slug grammar. */
|
|
154
|
+
declare function toMapSlug(raw: string): string;
|
|
155
|
+
/** Public directory for a slug. */
|
|
156
|
+
declare function mapPublicDir(publicDir: string, slug: string): string;
|
|
157
|
+
/** Seed pack file name for the configured compression. */
|
|
158
|
+
declare function seedPackName(gzip: boolean): string;
|
|
159
|
+
/** Private script pack path (with extension) for the configured compression. */
|
|
160
|
+
declare function scriptsPackPath(scriptsDir: string, slug: string, gzip: boolean): string;
|
|
161
|
+
/** Resolve a catalog entry's private script pack file. */
|
|
162
|
+
declare function mapScriptsFile(entry: MapEntry, options?: MapImportOptions): string;
|
|
163
|
+
/** All catalog entries that have a local private script pack. */
|
|
164
|
+
declare function listScriptPackLocations(options?: MapImportOptions): {
|
|
165
|
+
slug: string;
|
|
166
|
+
file: string;
|
|
167
|
+
}[];
|
|
168
|
+
/** Import a new map (`cj0 add`). Fails when the slug already exists. */
|
|
169
|
+
declare function addMap(archivePath: string, options?: MapImportOptions): Promise<MapImportResult>;
|
|
170
|
+
/** Replace an existing map (`cj0 update`). */
|
|
171
|
+
declare function updateMap(slug: string, archivePath: string, options?: MapImportOptions): Promise<MapImportResult>;
|
|
172
|
+
/** List catalog entries and their local import state (`cj0 list`). */
|
|
173
|
+
declare function listMaps(options?: MapImportOptions): MapListEntry[];
|
|
174
|
+
/** Remove a map from `public/`, the private scripts dir and the catalog. */
|
|
175
|
+
declare function removeMap(slug: string, options?: MapImportOptions): MapRemoveResult;
|
|
176
|
+
/** Read a private script pack as JSON text (used by `cj0 deploy`). */
|
|
177
|
+
declare function readScriptsPackText(file: string): string | undefined;
|
|
178
|
+
/** All slugs with a local script pack. */
|
|
179
|
+
declare function listScriptPacks(scriptsDir: string): string[];
|
|
180
|
+
|
|
181
|
+
export { DEFAULT_MAPS_FILE, DEFAULT_PUBLIC_DIR, DEFAULT_SCRIPTS_DIR, MapImportError, SCRIPT_PACK_FORMAT, addMap, deriveMapSlug, listMaps, listScriptPackLocations, listScriptPacks, mapPublicDir, mapScriptsFile, readMapCatalogFile, readScriptsPackText, removeMap, scriptsPackPath, seedPackName, toMapSlug, updateMap };
|
|
182
|
+
export type { MapImportErrorCode, MapImportOptions, MapImportResult, MapListEntry, MapRemoveResult };
|