ezship 0.1.10 → 0.1.12
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 +56 -8
- package/access.d.mts +120 -0
- package/access.mjs +987 -0
- package/account.d.mts +19 -0
- package/account.mjs +91 -0
- package/bindings.mjs +136 -0
- package/commands.d.mts +644 -0
- package/commands.mjs +7130 -0
- package/connections.d.mts +61 -0
- package/connections.mjs +312 -0
- package/cron.d.mts +17 -0
- package/cron.mjs +124 -0
- package/documents.d.mts +26 -0
- package/documents.mjs +242 -0
- package/editor-types.json.gz +0 -0
- package/editor.mjs +212 -0
- package/ez.mjs +1300 -2
- package/local-fetch.mjs +57 -0
- package/package.json +83 -7
- package/schema.d.mts +369 -0
- package/schema.mjs +3099 -0
- package/session.d.mts +20 -0
- package/session.mjs +142 -0
- package/shape.d.mts +14 -0
- package/shape.mjs +312 -0
- package/signup.d.mts +11 -0
- package/signup.mjs +42 -0
- package/types.d.mts +838 -0
- package/update-check.mjs +105 -0
- package/workflow.d.mts +63 -0
- package/workflow.mjs +450 -0
package/documents.mjs
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// The Document element tree (docs/adr/0105). A Document's template runs in QuickJS and returns this tree;
|
|
2
|
+
// the Host checks it before reading any image, and the renderer checks it again before drawing. Nothing
|
|
3
|
+
// outside these lists reaches react-pdf: no functions, no URLs to fetch, no fonts to load.
|
|
4
|
+
|
|
5
|
+
const BOX = ["style", "wrap", "fixed", "break", "minPresenceAhead"];
|
|
6
|
+
const BLOCK = ["View", "Text", "Image", "Link", "PageNumber"];
|
|
7
|
+
|
|
8
|
+
/** @type {typeof import("./documents.d.mts").DOCUMENT_ELEMENTS} */
|
|
9
|
+
export const DOCUMENT_ELEMENTS = Object.freeze({
|
|
10
|
+
Document: {
|
|
11
|
+
props: ["title", "author", "subject", "keywords", "language"],
|
|
12
|
+
children: ["Page"],
|
|
13
|
+
text: false,
|
|
14
|
+
},
|
|
15
|
+
Page: { props: ["size", "orientation", "style", "wrap"], children: BLOCK, text: false },
|
|
16
|
+
View: { props: BOX, children: BLOCK, text: false },
|
|
17
|
+
Text: { props: BOX, children: ["Text", "Link", "PageNumber"], text: true },
|
|
18
|
+
Link: { props: ["src", ...BOX], children: ["Text", "View", "Image"], text: true },
|
|
19
|
+
Image: { props: ["src", "style", "fixed", "break"], children: [], text: false },
|
|
20
|
+
PageNumber: { props: ["format", "style", "fixed"], children: [], text: false },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const SIDES = ["Top", "Right", "Bottom", "Left"];
|
|
24
|
+
/** @type {typeof import("./documents.d.mts").DOCUMENT_STYLES} */
|
|
25
|
+
export const DOCUMENT_STYLES = new Set([
|
|
26
|
+
// layout and size
|
|
27
|
+
"alignContent",
|
|
28
|
+
"alignItems",
|
|
29
|
+
"alignSelf",
|
|
30
|
+
"flex",
|
|
31
|
+
"flexDirection",
|
|
32
|
+
"flexWrap",
|
|
33
|
+
"flexGrow",
|
|
34
|
+
"flexShrink",
|
|
35
|
+
"flexBasis",
|
|
36
|
+
"justifyContent",
|
|
37
|
+
"gap",
|
|
38
|
+
"rowGap",
|
|
39
|
+
"columnGap",
|
|
40
|
+
"aspectRatio",
|
|
41
|
+
"display",
|
|
42
|
+
"position",
|
|
43
|
+
"top",
|
|
44
|
+
"right",
|
|
45
|
+
"bottom",
|
|
46
|
+
"left",
|
|
47
|
+
"overflow",
|
|
48
|
+
"zIndex",
|
|
49
|
+
"width",
|
|
50
|
+
"height",
|
|
51
|
+
"minWidth",
|
|
52
|
+
"minHeight",
|
|
53
|
+
"maxWidth",
|
|
54
|
+
"maxHeight",
|
|
55
|
+
// color and text
|
|
56
|
+
"color",
|
|
57
|
+
"backgroundColor",
|
|
58
|
+
"opacity",
|
|
59
|
+
"fontSize",
|
|
60
|
+
"fontFamily",
|
|
61
|
+
"fontStyle",
|
|
62
|
+
"fontWeight",
|
|
63
|
+
"letterSpacing",
|
|
64
|
+
"lineHeight",
|
|
65
|
+
"maxLines",
|
|
66
|
+
"textAlign",
|
|
67
|
+
"textDecoration",
|
|
68
|
+
"textDecorationColor",
|
|
69
|
+
"textDecorationStyle",
|
|
70
|
+
"textIndent",
|
|
71
|
+
"textOverflow",
|
|
72
|
+
"textTransform",
|
|
73
|
+
"verticalAlign",
|
|
74
|
+
"objectFit",
|
|
75
|
+
"objectPosition",
|
|
76
|
+
"objectPositionX",
|
|
77
|
+
"objectPositionY",
|
|
78
|
+
// box
|
|
79
|
+
"margin",
|
|
80
|
+
"marginHorizontal",
|
|
81
|
+
"marginVertical",
|
|
82
|
+
...SIDES.map((s) => `margin${s}`),
|
|
83
|
+
"padding",
|
|
84
|
+
"paddingHorizontal",
|
|
85
|
+
"paddingVertical",
|
|
86
|
+
...SIDES.map((s) => `padding${s}`),
|
|
87
|
+
"transform",
|
|
88
|
+
"transformOrigin",
|
|
89
|
+
"border",
|
|
90
|
+
"borderWidth",
|
|
91
|
+
"borderColor",
|
|
92
|
+
"borderStyle",
|
|
93
|
+
"borderRadius",
|
|
94
|
+
...SIDES.flatMap((s) => [`border${s}`, `border${s}Color`, `border${s}Style`, `border${s}Width`]),
|
|
95
|
+
...["TopLeft", "TopRight", "BottomRight", "BottomLeft"].map((c) => `border${c}Radius`),
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
/** @type {typeof import("./documents.d.mts").DOCUMENT_FONTS} */
|
|
99
|
+
export const DOCUMENT_FONTS = Object.freeze(
|
|
100
|
+
/** @type {const} */ (["Helvetica", "Times-Roman", "Courier"]),
|
|
101
|
+
);
|
|
102
|
+
/** @type {typeof import("./documents.d.mts").MAX_DOCUMENT_TREE_BYTES} */
|
|
103
|
+
export const MAX_DOCUMENT_TREE_BYTES = 4_000_000;
|
|
104
|
+
/** @type {typeof import("./documents.d.mts").MAX_DOCUMENT_NODES} */
|
|
105
|
+
export const MAX_DOCUMENT_NODES = 100_000;
|
|
106
|
+
/** @type {typeof import("./documents.d.mts").MAX_DOCUMENT_PAGES} */
|
|
107
|
+
export const MAX_DOCUMENT_PAGES = 200;
|
|
108
|
+
/** @type {typeof import("./documents.d.mts").MAX_DOCUMENT_BYTES} */
|
|
109
|
+
export const MAX_DOCUMENT_BYTES = 20_000_000;
|
|
110
|
+
|
|
111
|
+
/** @type {typeof import("./documents.d.mts").imageKey} */
|
|
112
|
+
export const imageKey = (ref) =>
|
|
113
|
+
"asset" in ref ? `asset:${ref.asset}` : `attachment:${ref.attachment}`;
|
|
114
|
+
|
|
115
|
+
const ASSET_NAME = /^[a-z][a-z0-9-]{0,63}$/;
|
|
116
|
+
const FILE_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
117
|
+
const LINK = /^(https?:\/\/|mailto:|#)/i;
|
|
118
|
+
const isObject = (/** @type {unknown} */ v) =>
|
|
119
|
+
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
120
|
+
const short = (/** @type {unknown} */ v, max = 500) => typeof v === "string" && v.length <= max;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Why one prop's value is refused, or null.
|
|
124
|
+
* @param {string} type @param {string} name @param {unknown} value @param {import("./documents.d.mts").ImageRef[]} images
|
|
125
|
+
* @returns {string | null}
|
|
126
|
+
*/
|
|
127
|
+
function propError(type, name, value, images) {
|
|
128
|
+
switch (name) {
|
|
129
|
+
case "style": {
|
|
130
|
+
if (!isObject(value)) return "style must be an object";
|
|
131
|
+
for (const [key, v] of Object.entries(/** @type {Record<string, unknown>} */ (value))) {
|
|
132
|
+
if (!DOCUMENT_STYLES.has(key)) return `style.${key} is not supported`;
|
|
133
|
+
if (typeof v === "number" ? !Number.isFinite(v) : !short(v, 200))
|
|
134
|
+
return `style.${key} must be a number or a short string`;
|
|
135
|
+
if (typeof v === "string" && /url\s*\(/i.test(v)) return `style.${key} may not name a URL`;
|
|
136
|
+
if (key === "fontFamily" && !DOCUMENT_FONTS.includes(/** @type {never} */ (v)))
|
|
137
|
+
return `fontFamily must be one of ${DOCUMENT_FONTS.join(", ")}`;
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
case "wrap":
|
|
142
|
+
case "fixed":
|
|
143
|
+
case "break":
|
|
144
|
+
return typeof value === "boolean" ? null : `${name} must be true or false`;
|
|
145
|
+
case "minPresenceAhead":
|
|
146
|
+
return typeof value === "number" && Number.isFinite(value)
|
|
147
|
+
? null
|
|
148
|
+
: `${name} must be a number`;
|
|
149
|
+
case "orientation":
|
|
150
|
+
return value === "portrait" || value === "landscape"
|
|
151
|
+
? null
|
|
152
|
+
: "orientation is portrait or landscape";
|
|
153
|
+
case "size":
|
|
154
|
+
if (typeof value === "string")
|
|
155
|
+
return /^[A-Za-z0-9]{2,12}$/.test(value) ? null : "size names a page size (A4, LETTER)";
|
|
156
|
+
return Array.isArray(value) &&
|
|
157
|
+
value.length === 2 &&
|
|
158
|
+
value.every((n) => typeof n === "number" && n > 0 && n <= 14_400)
|
|
159
|
+
? null
|
|
160
|
+
: "size is a page size name or [width, height] in points";
|
|
161
|
+
case "format":
|
|
162
|
+
return short(value, 200) ? null : "format must be a short string";
|
|
163
|
+
case "src":
|
|
164
|
+
if (type === "Link")
|
|
165
|
+
return short(value, 2000) && LINK.test(String(value))
|
|
166
|
+
? null
|
|
167
|
+
: "Link src must be an http(s), mailto or # URL";
|
|
168
|
+
if (isObject(value)) {
|
|
169
|
+
const ref = /** @type {Record<string, unknown>} */ (value);
|
|
170
|
+
const keys = Object.keys(ref);
|
|
171
|
+
if (keys.length === 1 && typeof ref.asset === "string" && ASSET_NAME.test(ref.asset)) {
|
|
172
|
+
images.push({ asset: ref.asset });
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
if (
|
|
176
|
+
keys.length === 1 &&
|
|
177
|
+
typeof ref.attachment === "string" &&
|
|
178
|
+
FILE_ID.test(ref.attachment)
|
|
179
|
+
) {
|
|
180
|
+
images.push({ attachment: ref.attachment });
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return "Image src must be asset(name) or attachment(id)";
|
|
185
|
+
default:
|
|
186
|
+
return short(value) ? null : `${name} must be a short string`;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** @type {typeof import("./documents.d.mts").checkDocumentTree} */
|
|
191
|
+
export function checkDocumentTree(tree) {
|
|
192
|
+
let json;
|
|
193
|
+
try {
|
|
194
|
+
json = JSON.stringify(tree);
|
|
195
|
+
} catch {
|
|
196
|
+
return { ok: false, error: "The Document did not render to plain data." };
|
|
197
|
+
}
|
|
198
|
+
if (json === undefined || json.length > MAX_DOCUMENT_TREE_BYTES)
|
|
199
|
+
return { ok: false, error: `The Document's elements exceed ${MAX_DOCUMENT_TREE_BYTES} bytes.` };
|
|
200
|
+
/** @type {import("./documents.d.mts").ImageRef[]} */
|
|
201
|
+
const images = [];
|
|
202
|
+
let nodes = 0;
|
|
203
|
+
/** @param {unknown} node @param {string} path @returns {string | null} */
|
|
204
|
+
const visit = (node, path) => {
|
|
205
|
+
if (++nodes > MAX_DOCUMENT_NODES) return `more than ${MAX_DOCUMENT_NODES} elements`;
|
|
206
|
+
if (!isObject(node)) return `${path}: not an element`;
|
|
207
|
+
const { t, p, c, ...rest } = /** @type {Record<string, unknown>} */ (node);
|
|
208
|
+
if (Object.keys(rest).length) return `${path}: not an element`;
|
|
209
|
+
if (typeof t !== "string" || !Object.hasOwn(DOCUMENT_ELEMENTS, t))
|
|
210
|
+
return `${path}: ${String(t)} is not a Document element`;
|
|
211
|
+
const spec = DOCUMENT_ELEMENTS[t];
|
|
212
|
+
if (!isObject(p) || !Array.isArray(c)) return `${path} ${t}: not an element`;
|
|
213
|
+
for (const [name, value] of Object.entries(/** @type {Record<string, unknown>} */ (p))) {
|
|
214
|
+
if (!spec.props.includes(name)) return `${path} ${t}: ${name} is not a ${t} prop`;
|
|
215
|
+
const why = propError(t, name, value, images);
|
|
216
|
+
if (why) return `${path} ${t}: ${why}`;
|
|
217
|
+
}
|
|
218
|
+
for (const [i, child] of c.entries()) {
|
|
219
|
+
if (typeof child === "string") {
|
|
220
|
+
if (!spec.text) return `${path} ${t}: text belongs in a <Text>`;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const type = isObject(child) ? /** @type {Record<string, unknown>} */ (child).t : undefined;
|
|
224
|
+
if (
|
|
225
|
+
typeof type === "string" &&
|
|
226
|
+
Object.hasOwn(DOCUMENT_ELEMENTS, type) &&
|
|
227
|
+
!spec.children.includes(type)
|
|
228
|
+
)
|
|
229
|
+
return `${path} ${t}: a <${type}> cannot be inside a <${t}>`;
|
|
230
|
+
const why = visit(child, `${path}.${i}`);
|
|
231
|
+
if (why) return why;
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
};
|
|
235
|
+
if (!isObject(tree) || /** @type {Record<string, unknown>} */ (tree).t !== "Document")
|
|
236
|
+
return { ok: false, error: "A Document renders a <Document> at the top." };
|
|
237
|
+
const why = visit(tree, "Document");
|
|
238
|
+
if (why) return { ok: false, error: why };
|
|
239
|
+
if (!/** @type {{ c: unknown[] }} */ (tree).c.length)
|
|
240
|
+
return { ok: false, error: "A Document needs at least one <Page>." };
|
|
241
|
+
return { ok: true, tree: /** @type {import("./types.d.mts").DocumentNode} */ (tree), images };
|
|
242
|
+
}
|
|
Binary file
|
package/editor.mjs
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// Editor metadata only. The hosted Pipeline owns Rules, Check, Preview and Deploy (ADRs 0035/0038).
|
|
2
|
+
import { mkdir, readdir, readFile, rm, rmdir, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { gunzipSync } from "node:zlib";
|
|
5
|
+
import { COMPILER_OPTIONS, GLOBAL_ID, SITES_FOLDER } from "./commands.mjs";
|
|
6
|
+
import { instanceBinding, instanceFolderOf, readBinding, sameInstance } from "./bindings.mjs";
|
|
7
|
+
|
|
8
|
+
// ADR 0088: global/session.ts's types become the Framework's, or nothing when the Instance declares none.
|
|
9
|
+
const SESSION_TYPES = `// Generated by ez (docs/adr/0088): global/session.ts's types as the Framework's.
|
|
10
|
+
import type { Provided as Declared, Saved, SignedIn } from "global/session";
|
|
11
|
+
declare module "@ezship/react" {
|
|
12
|
+
interface Provided extends Declared {}
|
|
13
|
+
interface Session extends Saved, SignedIn {}
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
const SESSION_NONE = `// The Instance declares no global/session.ts (docs/adr/0088).
|
|
17
|
+
export type Provided = {};
|
|
18
|
+
export type Saved = {};
|
|
19
|
+
export type SignedIn = {};
|
|
20
|
+
export declare const defaults: {};
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
const CONFIG_STUB = JSON.stringify({ extends: "./.ez/editor/tsconfig.json" }, null, 2) + "\n";
|
|
24
|
+
|
|
25
|
+
/** @param {string} path */
|
|
26
|
+
async function readOptional(path) {
|
|
27
|
+
try {
|
|
28
|
+
return await readFile(path, "utf8");
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") return null;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {Partial<import("./connections.d.mts").Connection> | null} instance
|
|
37
|
+
* @param {Partial<import("./connections.d.mts").Connection> | null} workingCopy
|
|
38
|
+
*/
|
|
39
|
+
const belongsTo = (instance, workingCopy) =>
|
|
40
|
+
Boolean(workingCopy?.site) && sameInstance(instance, workingCopy);
|
|
41
|
+
|
|
42
|
+
/** @type {Promise<Record<string, string>> | undefined} */
|
|
43
|
+
let declarations;
|
|
44
|
+
async function editorDeclarations() {
|
|
45
|
+
declarations ??= readFile(new URL("./editor-types.json.gz", import.meta.url)).then(
|
|
46
|
+
(bytes) => JSON.parse(gunzipSync(bytes).toString("utf8")).files,
|
|
47
|
+
);
|
|
48
|
+
return declarations;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const DECLARED_RE =
|
|
52
|
+
/^export declare (?:function|const|let|var|type|interface|class|enum) ([A-Za-z_$][\w$]*)/gm;
|
|
53
|
+
const EXPORT_LIST_RE = /^export (?:type )?\{([^}]*)\}/gm;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The names the shipped declarations export per Framework module (docs/adr/0078), to tell a Builder whose
|
|
57
|
+
* editor accepts a name the Host's older Builder lacks what is going on.
|
|
58
|
+
* @returns {Promise<Record<string, string[]>>}
|
|
59
|
+
*/
|
|
60
|
+
export async function editorExports() {
|
|
61
|
+
const files = await editorDeclarations();
|
|
62
|
+
/** @type {Record<string, string[]>} */
|
|
63
|
+
const out = {};
|
|
64
|
+
for (const [module, file] of [
|
|
65
|
+
["@ezship/react", "ezship/index.d.ts"],
|
|
66
|
+
["@ezship/react/server", "ezship/server.d.ts"],
|
|
67
|
+
["@ezship/react/local", "ezship/local.d.ts"],
|
|
68
|
+
]) {
|
|
69
|
+
const source = files[file] ?? "";
|
|
70
|
+
const names = [...source.matchAll(DECLARED_RE)].map((m) => m[1]);
|
|
71
|
+
for (const m of source.matchAll(EXPORT_LIST_RE))
|
|
72
|
+
for (const part of m[1].split(",")) {
|
|
73
|
+
const name = part
|
|
74
|
+
.trim()
|
|
75
|
+
.split(/\s+as\s+/)
|
|
76
|
+
.pop()
|
|
77
|
+
?.replace(/^type\s+/, "");
|
|
78
|
+
if (name) names.push(name);
|
|
79
|
+
}
|
|
80
|
+
out[module] = [...new Set(names)].sort();
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @param {string} path @param {string} content */
|
|
86
|
+
async function writeChanged(path, content) {
|
|
87
|
+
if ((await readFile(path, "utf8").catch(() => null)) === content) return;
|
|
88
|
+
await mkdir(dirname(path), { recursive: true });
|
|
89
|
+
await writeFile(path, content);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Use a matching parent Instance's project, or prepare a standalone Working Copy.
|
|
94
|
+
* @param {string} dir @param {string} globalDir
|
|
95
|
+
*/
|
|
96
|
+
export async function ensureEditor(dir, globalDir) {
|
|
97
|
+
dir = resolve(dir);
|
|
98
|
+
globalDir = resolve(globalDir);
|
|
99
|
+
const root = instanceFolderOf(dir);
|
|
100
|
+
const instance = await instanceBinding(root);
|
|
101
|
+
if (!belongsTo(instance, await readBinding(dir))) {
|
|
102
|
+
await writeEditor(dir, globalDir, [dir]);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const configPath = join(dir, "tsconfig.json");
|
|
107
|
+
const existing = await readOptional(configPath);
|
|
108
|
+
const shared =
|
|
109
|
+
globalDir === join(root, GLOBAL_ID) && (existing === null || existing === CONFIG_STUB);
|
|
110
|
+
// Custom configs and explicit --global-dir selections retain their own project.
|
|
111
|
+
if (!shared) await writeEditor(dir, globalDir, [dir]);
|
|
112
|
+
const folders = [];
|
|
113
|
+
const candidates = [];
|
|
114
|
+
for (const parent of [join(root, SITES_FOLDER), root])
|
|
115
|
+
for (const entry of await readdir(parent, { withFileTypes: true }).catch(() => [])) {
|
|
116
|
+
if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
|
|
117
|
+
candidates.push(join(parent, entry.name));
|
|
118
|
+
}
|
|
119
|
+
for (const folder of candidates) {
|
|
120
|
+
const pulled = await readBinding(folder);
|
|
121
|
+
if (!belongsTo(instance, pulled) || pulled.site === GLOBAL_ID) continue;
|
|
122
|
+
// Existing per-folder projects stay independent until their own Pull/Dev migrates them.
|
|
123
|
+
if ((shared && folder === dir) || (await readOptional(join(folder, "tsconfig.json"))) === null)
|
|
124
|
+
folders.push(folder);
|
|
125
|
+
}
|
|
126
|
+
await writeEditor(root, join(root, GLOBAL_ID), folders.sort());
|
|
127
|
+
if (shared) {
|
|
128
|
+
// Prepare the parent before removing the old project. Only our exact stub is replaceable.
|
|
129
|
+
if (existing === CONFIG_STUB) await unlink(configPath);
|
|
130
|
+
await rm(join(dir, ".ez", "editor"), { recursive: true, force: true });
|
|
131
|
+
// Its binding lives in the Instance folder (ADR 0085); an emptied `.ez/` goes too.
|
|
132
|
+
await rmdir(join(dir, ".ez")).catch(() => {});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** @param {string} dir @param {string} globalDir @param {string[]} folders */
|
|
137
|
+
async function writeEditor(dir, globalDir, folders) {
|
|
138
|
+
const editor = join(dir, ".ez", "editor");
|
|
139
|
+
/** @param {string} folder */
|
|
140
|
+
const fromEditor = (folder) => relative(editor, folder).split(sep).join("/") || ".";
|
|
141
|
+
const global = fromEditor(globalDir);
|
|
142
|
+
for (const [file, content] of Object.entries(await editorDeclarations())) {
|
|
143
|
+
await writeChanged(join(editor, "types", file), content);
|
|
144
|
+
}
|
|
145
|
+
const config = {
|
|
146
|
+
compilerOptions: {
|
|
147
|
+
// The Pipeline's own options (docs/adr/0078), so local tsc and `ez check` agree.
|
|
148
|
+
...COMPILER_OPTIONS,
|
|
149
|
+
// Scripts in different Sites must not share top-level declarations in the editor.
|
|
150
|
+
moduleDetection: "force",
|
|
151
|
+
// Node's ambient `node:*` modules and globals, for local functions (ADR 0048); the bundle is the root.
|
|
152
|
+
types: ["node"],
|
|
153
|
+
typeRoots: ["./types"],
|
|
154
|
+
paths: {
|
|
155
|
+
react: ["./types/react/index.d.ts"],
|
|
156
|
+
"react/*": ["./types/react/*"],
|
|
157
|
+
csstype: ["./types/csstype/index.d.ts"],
|
|
158
|
+
"@ezship/react": ["./types/ezship/index.d.ts"],
|
|
159
|
+
"@ezship/react/server": ["./types/ezship/server.d.ts"],
|
|
160
|
+
"@ezship/react/local": ["./types/ezship/local.d.ts"],
|
|
161
|
+
"@ezship/react/pdf": ["./types/ezship/pdf.d.ts"],
|
|
162
|
+
zod: ["./types/zod/index.d.ts"],
|
|
163
|
+
// ADR 0114: Site packages; what they import resolves inside types/node_modules.
|
|
164
|
+
recharts: ["./types/node_modules/recharts/types/index.d.ts"],
|
|
165
|
+
"undici-types": ["./types/undici-types/index.d.ts"],
|
|
166
|
+
"global/db/types": [`${global}/db/types.d.ts`],
|
|
167
|
+
"global/constants": [`${global}/constants.ts`],
|
|
168
|
+
"global/session": [`${global}/session.ts`, "./session-none.d.ts"],
|
|
169
|
+
"global/lib/*": [`${global}/lib/*`],
|
|
170
|
+
"global/hooks/*": [`${global}/hooks/*`],
|
|
171
|
+
"global/documents/*": [`${global}/documents/*`],
|
|
172
|
+
"global/*": [`${global}/components/*`],
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
include: [
|
|
176
|
+
...new Set([
|
|
177
|
+
...folders.flatMap((folder) => {
|
|
178
|
+
const prefix = fromEditor(folder);
|
|
179
|
+
return [
|
|
180
|
+
`${prefix}/*.ts`,
|
|
181
|
+
`${prefix}/*.tsx`,
|
|
182
|
+
`${prefix}/pages/*.tsx`,
|
|
183
|
+
`${prefix}/components/*.tsx`,
|
|
184
|
+
`${prefix}/hooks/*.ts`,
|
|
185
|
+
`${prefix}/functions/*.ts`,
|
|
186
|
+
`${prefix}/local/*.ts`,
|
|
187
|
+
`${prefix}/listeners/*.ts`,
|
|
188
|
+
];
|
|
189
|
+
}),
|
|
190
|
+
`${global}/*.ts`,
|
|
191
|
+
`${global}/*.tsx`,
|
|
192
|
+
`${global}/components/*.tsx`,
|
|
193
|
+
`${global}/lib/*.ts`,
|
|
194
|
+
`${global}/hooks/*.ts`,
|
|
195
|
+
`${global}/rules/*.ts`,
|
|
196
|
+
`${global}/workflows/*.ts`,
|
|
197
|
+
`${global}/jobs/*.ts`,
|
|
198
|
+
`${global}/db/types.d.ts`,
|
|
199
|
+
"session.d.ts",
|
|
200
|
+
]),
|
|
201
|
+
],
|
|
202
|
+
};
|
|
203
|
+
await writeChanged(join(editor, "session.d.ts"), SESSION_TYPES);
|
|
204
|
+
await writeChanged(join(editor, "session-none.d.ts"), SESSION_NONE);
|
|
205
|
+
await writeChanged(join(editor, "tsconfig.json"), JSON.stringify(config, null, 2) + "\n");
|
|
206
|
+
// Keep custom settings, including JSONC, byte-for-byte. Never parse/rewrite someone else's config.
|
|
207
|
+
try {
|
|
208
|
+
await writeFile(join(dir, "tsconfig.json"), CONFIG_STUB, { flag: "wx" });
|
|
209
|
+
} catch (error) {
|
|
210
|
+
if (!(error instanceof Error && "code" in error && error.code === "EEXIST")) throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|