ezship 0.1.16 → 0.1.18

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/connections.d.mts CHANGED
@@ -14,9 +14,9 @@ export const CONNECTION_VERSION: 1;
14
14
  export const DISCOVERY_PATH: "/.well-known/ezship";
15
15
  /** A bare Instance name means `https://<name>.<MANAGED_DOMAIN>`. */
16
16
  export const MANAGED_DOMAIN: "ezship.dev";
17
- /** ADR 0072: the contract's compatibility number, raised only by a change an older client cannot survive. */
17
+ /** ADR 0206: the contract's compatibility number, raised only by a change an older client cannot survive. */
18
18
  export const CONTRACT: number;
19
- /** ADR 0072: the oldest client contract this release serves; older clients are answered 426. */
19
+ /** ADR 0206: the oldest client contract this release serves; older clients are answered 426. */
20
20
  export const OLDEST_CONTRACT: number;
21
21
  export const CONTRACT_HEADER: "ez-contract";
22
22
  export function localOrigin(input: string): boolean;
@@ -51,7 +51,6 @@ export function connectionRequest(
51
51
  init?: RequestInit,
52
52
  send?: typeof fetch,
53
53
  ): Promise<Response>;
54
- export function contractNote(response: Pick<Response, "headers">, client?: number): string;
55
54
  export function usesWorkingCopy(words: string[]): boolean;
56
55
  export function extractTarget(words: string[]): {
57
56
  args: string[];
package/connections.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // Instance connections shared by the terminal and Studio (ADR 0026). Persistence stays in each client.
1
+ // Instance connections shared by the terminal and Studio (ADR 0202). Persistence stays in each client.
2
2
  /** @type {typeof import("./connections.d.mts").CONNECTION_VERSION} */
3
3
  export const CONNECTION_VERSION = 1;
4
4
  /** @type {typeof import("./connections.d.mts").DISCOVERY_PATH} */
@@ -6,15 +6,16 @@ export const DISCOVERY_PATH = "/.well-known/ezship";
6
6
  /** A bare Instance name means `https://<name>.<MANAGED_DOMAIN>`. */
7
7
  export const MANAGED_DOMAIN = "ezship.dev";
8
8
  /**
9
- * The contract's compatibility number (ADR 0072): raised only by a change an older client cannot survive.
9
+ * The contract's compatibility number (ADR 0206): raised only by a change an older client cannot survive.
10
10
  * @type {typeof import("./connections.d.mts").CONTRACT}
11
11
  */
12
- export const CONTRACT = 2;
12
+ export const CONTRACT = 3;
13
13
  /**
14
- * The oldest client contract this release still serves; a Host answers an older one 426.
14
+ * The oldest client contract this release serves; a Host answers an older one, and an API request that names
15
+ * none, 426.
15
16
  * @type {typeof import("./connections.d.mts").OLDEST_CONTRACT}
16
17
  */
17
- export const OLDEST_CONTRACT = 1;
18
+ export const OLDEST_CONTRACT = 3;
18
19
  /**
19
20
  * Sent by every client request and on every API response, each side's own `CONTRACT`.
20
21
  * @type {typeof import("./connections.d.mts").CONTRACT_HEADER}
@@ -49,8 +50,8 @@ export function instanceAddress(input) {
49
50
  }
50
51
 
51
52
  /**
52
- * The Studio's path for an Instance's app origin (ADR 0032): managed names stay short, other origins keep
53
- * their authority so links remain shareable. Invite emails (ADR 0055) and the Studio both use it.
53
+ * The Studio's path for an Instance's app origin (ADR 0201): managed names stay short, other origins keep
54
+ * their authority so links remain shareable. Invite emails (ADR 0202) and the Studio both use it.
54
55
  * @type {typeof import("./connections.d.mts").studioPath}
55
56
  */
56
57
  export function studioPath(app) {
@@ -144,7 +145,7 @@ export function readConnections(raw) {
144
145
  continue;
145
146
  logins[key] = c;
146
147
  } catch {
147
- /* Preserve invalid/legacy data at its old persistence key; never adopt its credentials. */
148
+ /* An entry that is not a valid connection is skipped; its credentials are never used. */
148
149
  }
149
150
  }
150
151
  return {
@@ -237,18 +238,6 @@ export async function connectionRequest(connection, path, init = {}, send = fetc
237
238
  return send(target.href, { ...init, headers, credentials: "omit", redirect: "error" });
238
239
  }
239
240
 
240
- /**
241
- * For a failed request: a note when the Host speaks an older contract than this client, whose command it
242
- * may not have yet; otherwise empty.
243
- * @type {typeof import("./connections.d.mts").contractNote}
244
- */
245
- export function contractNote(response, client = CONTRACT) {
246
- const host = Number(response.headers.get(CONTRACT_HEADER));
247
- return Number.isInteger(host) && host > 0 && host < client
248
- ? ` This Host speaks contract ${host} and this client ${client}; the Host may predate this command.`
249
- : "";
250
- }
251
-
252
241
  /**
253
242
  * Commands needing the target's own Working Copy; remote-only commands can select another Instance.
254
243
  * @type {typeof import("./connections.d.mts").usesWorkingCopy}
@@ -271,9 +260,8 @@ export function usesWorkingCopy(words) {
271
260
  "put",
272
261
  "edit",
273
262
  "delete",
274
- "rm",
275
263
  "mv",
276
- ].includes(command) && !(command === "preview" && ["ls", "delete", "rm"].includes(rest[0]))
264
+ ].includes(command) && !(command === "preview" && ["ls", "delete"].includes(rest[0]))
277
265
  );
278
266
  }
279
267
 
package/cron.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- /** A parsed five-field UTC cron (docs/adr/0076). Day of week 7 is folded into 0 (Sunday). */
1
+ /** A parsed five-field UTC cron (docs/adr/0230). Day of week 7 is folded into 0 (Sunday). */
2
2
  export type Cron = {
3
3
  minute: Set<number>;
4
4
  hour: Set<number>;
package/cron.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // Five-field UTC cron for the Global Workspace's schedules.json (docs/adr/0076, 0136). Zero dependencies: the
1
+ // Five-field UTC cron for the Global Workspace's schedules.json (docs/adr/0230). Zero dependencies: the
2
2
  // contract checks a file with it and the Host's scheduler computes due times with it, so both agree on every
3
3
  // minute.
4
4
 
package/documents.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- // The Document element tree (docs/adr/0105): what a template stage may return and the renderer may draw.
1
+ // The Document element tree (docs/adr/0233): what a template stage may return and the renderer may draw.
2
2
  import type { DocumentNode } from "./types.d.mts";
3
3
 
4
4
  /** The element types, the props each accepts, and the children it may hold. */
package/documents.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // The Document element tree (docs/adr/0105). A Document's template runs in QuickJS and returns this tree;
1
+ // The Document element tree (docs/adr/0233). A Document's template runs in QuickJS and returns this tree;
2
2
  // the Host checks it before reading any image, and the renderer checks it again before drawing. Nothing
3
3
  // outside these lists reaches react-pdf: no functions, no URLs to fetch, no fonts to load.
4
4
 
Binary file
package/editor.mjs CHANGED
@@ -1,19 +1,19 @@
1
- // Editor metadata only. The hosted Pipeline owns Rules, Check, Preview and Deploy (ADRs 0035/0038).
1
+ // Editor metadata only. The hosted Pipeline owns Rules, Check, Preview and Deploy (ADR 0205).
2
2
  import { mkdir, readdir, readFile, rm, rmdir, unlink, writeFile } from "node:fs/promises";
3
3
  import { dirname, join, relative, resolve, sep } from "node:path";
4
4
  import { gunzipSync } from "node:zlib";
5
5
  import { COMPILER_OPTIONS, GLOBAL_ID, SITES_FOLDER } from "./commands.mjs";
6
6
  import { instanceBinding, instanceFolderOf, readBinding, sameInstance } from "./bindings.mjs";
7
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.
8
+ // ADR 0214: 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/0214): global/session.ts's types as the Framework's.
10
10
  import type { Provided as Declared, Saved, SignedIn } from "global/session";
11
11
  declare module "@ezship/react" {
12
12
  interface Provided extends Declared {}
13
13
  interface Session extends Saved, SignedIn {}
14
14
  }
15
15
  `;
16
- const SESSION_NONE = `// The Instance declares no global/session.ts (docs/adr/0088).
16
+ const SESSION_NONE = `// The Instance declares no global/session.ts (docs/adr/0214).
17
17
  export type Provided = {};
18
18
  export type Saved = {};
19
19
  export type SignedIn = {};
@@ -48,40 +48,6 @@ async function editorDeclarations() {
48
48
  return declarations;
49
49
  }
50
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
51
  /** @param {string} path @param {string} content */
86
52
  async function writeChanged(path, content) {
87
53
  if ((await readFile(path, "utf8").catch(() => null)) === content) return;
@@ -90,7 +56,8 @@ async function writeChanged(path, content) {
90
56
  }
91
57
 
92
58
  /**
93
- * Use a matching parent Instance's project, or prepare a standalone Working Copy.
59
+ * A Working Copy in an Instance folder (`sites/<folder>/` or `global/`) uses the Instance's shared project; any
60
+ * other gets its own.
94
61
  * @param {string} dir @param {string} globalDir
95
62
  */
96
63
  export async function ensureEditor(dir, globalDir) {
@@ -98,7 +65,8 @@ export async function ensureEditor(dir, globalDir) {
98
65
  globalDir = resolve(globalDir);
99
66
  const root = instanceFolderOf(dir);
100
67
  const instance = await instanceBinding(root);
101
- if (!belongsTo(instance, await readBinding(dir))) {
68
+ const inInstance = dirname(dir) === join(root, SITES_FOLDER) || dir === join(root, GLOBAL_ID);
69
+ if (!inInstance || !belongsTo(instance, await readBinding(dir))) {
102
70
  await writeEditor(dir, globalDir, [dir]);
103
71
  return;
104
72
  }
@@ -107,28 +75,24 @@ export async function ensureEditor(dir, globalDir) {
107
75
  const existing = await readOptional(configPath);
108
76
  const shared =
109
77
  globalDir === join(root, GLOBAL_ID) && (existing === null || existing === CONFIG_STUB);
110
- // Custom configs and explicit --global-dir selections retain their own project.
78
+ // Custom configs and explicit --global-dir selections keep their own project.
111
79
  if (!shared) await writeEditor(dir, globalDir, [dir]);
112
80
  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.
81
+ const sites = join(root, SITES_FOLDER);
82
+ for (const entry of await readdir(sites, { withFileTypes: true }).catch(() => [])) {
83
+ if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
84
+ const folder = join(sites, entry.name);
85
+ if (!belongsTo(instance, await readBinding(folder))) continue;
86
+ // A folder with its own tsconfig.json keeps its own project until a Pull or Dev there rejoins it.
123
87
  if ((shared && folder === dir) || (await readOptional(join(folder, "tsconfig.json"))) === null)
124
88
  folders.push(folder);
125
89
  }
126
90
  await writeEditor(root, join(root, GLOBAL_ID), folders.sort());
127
91
  if (shared) {
128
- // Prepare the parent before removing the old project. Only our exact stub is replaceable.
92
+ // Rejoining the shared project (written first) drops the folder's own: only our exact stub goes, and the
93
+ // folder's `.ez/` once it is empty (its binding lives in the Instance folder, ADR 0205).
129
94
  if (existing === CONFIG_STUB) await unlink(configPath);
130
95
  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
96
  await rmdir(join(dir, ".ez")).catch(() => {});
133
97
  }
134
98
  }
@@ -144,11 +108,11 @@ async function writeEditor(dir, globalDir, folders) {
144
108
  }
145
109
  const config = {
146
110
  compilerOptions: {
147
- // The Pipeline's own options (docs/adr/0078), so local tsc and `ez check` agree.
111
+ // The Pipeline's own options (docs/adr/0236), so local tsc and `ez check` agree.
148
112
  ...COMPILER_OPTIONS,
149
113
  // Scripts in different Sites must not share top-level declarations in the editor.
150
114
  moduleDetection: "force",
151
- // Node's ambient `node:*` modules and globals, for local functions (ADR 0048); the bundle is the root.
115
+ // Node's ambient `node:*` modules and globals, for local functions (ADR 0235); the bundle is the root.
152
116
  types: ["node"],
153
117
  typeRoots: ["./types"],
154
118
  paths: {
@@ -160,7 +124,7 @@ async function writeEditor(dir, globalDir, folders) {
160
124
  "@ezship/react/local": ["./types/ezship/local.d.ts"],
161
125
  "@ezship/react/pdf": ["./types/ezship/pdf.d.ts"],
162
126
  zod: ["./types/zod/index.d.ts"],
163
- // ADR 0114: Site packages; what they import resolves inside types/node_modules.
127
+ // ADR 0209: Site packages; what they import resolves inside types/node_modules.
164
128
  recharts: ["./types/node_modules/recharts/types/index.d.ts"],
165
129
  "undici-types": ["./types/undici-types/index.d.ts"],
166
130
  "global/db/types": [`${global}/db/types.d.ts`],
@@ -169,6 +133,7 @@ async function writeEditor(dir, globalDir, folders) {
169
133
  "global/lib/*": [`${global}/lib/*`],
170
134
  "global/hooks/*": [`${global}/hooks/*`],
171
135
  "global/documents/*": [`${global}/documents/*`],
136
+ "global/components/*": [`${global}/components/*`],
172
137
  "global/*": [`${global}/components/*`],
173
138
  },
174
139
  },
@@ -182,6 +147,7 @@ async function writeEditor(dir, globalDir, folders) {
182
147
  `${prefix}/pages/*.tsx`,
183
148
  `${prefix}/components/*.tsx`,
184
149
  `${prefix}/hooks/*.ts`,
150
+ `${prefix}/lib/*.ts`,
185
151
  `${prefix}/functions/*.ts`,
186
152
  `${prefix}/local/*.ts`,
187
153
  `${prefix}/listeners/*.ts`,