@crossworks/client-types 0.300.64 → 0.300.66

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossworks/client-types",
3
- "version": "0.300.64",
3
+ "version": "0.300.66",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/app-viewer.ts CHANGED
@@ -9,9 +9,14 @@
9
9
  * every app), so an app cannot join a person across apps.
10
10
  */
11
11
 
12
- /** The kind of viewer: the owner or an admin login, a member login, a client
13
- * login, a Contact share's contact, or an open /s link (no person). */
14
- export type AppViewerKind = 'admin' | 'member' | 'client' | 'contact' | 'public';
12
+ import type { LoginRole } from './role-names';
13
+
14
+ /** The kind of viewer: a login (its role: the owner or an admin login, a
15
+ * member login), a Contact share's contact, or an open /s link (no person).
16
+ * `client` stays for the wire contract (additive only): a client login was
17
+ * a viewer kind until workspaces W8a removed the role, and an app may still
18
+ * test `:host_me_kind` for it. No brain answers it now. */
19
+ export type AppViewerKind = LoginRole | 'client' | 'contact' | 'public';
15
20
 
16
21
  export type AppViewer = {
17
22
  /** Stable for this person inside this app only; null on an open link. */
package/src/dto/access.ts CHANGED
@@ -42,6 +42,8 @@ export type AccessLinkView = {
42
42
  export type MemberItemAuthor = {
43
43
  name: string;
44
44
  acceptedAt: string | null;
45
+ /** `client` stays for the wire contract (additive only): the client role
46
+ * is gone since workspaces W8a and no brain answers it now. */
45
47
  role?: 'member' | 'client' | null;
46
48
  };
47
49
 
package/src/dto/rows.ts CHANGED
@@ -55,7 +55,9 @@ export type TaskTodo = {
55
55
  done: boolean;
56
56
  };
57
57
 
58
- /** Mirrors @mantle/db `NodeCommentAuthorKind`. */
58
+ /** Mirrors @mantle/db `NodeCommentAuthorKind`. `client` stays for the wire
59
+ * contract (additive only) and for the comments a client login wrote
60
+ * before workspaces W8a removed the role; no new comment gets it. */
59
61
  export type NodeCommentAuthorKind = 'owner' | 'member' | 'agent' | 'client';
60
62
 
61
63
  /**
@@ -4,11 +4,15 @@
4
4
  *
5
5
  * Record, move, compare: the first commit of A10 #12 proved RECORDED
6
6
  * against the literals in the source (git show 12b4564ec); now each list is
7
- * a filter over a registry field (./kind-lists), and this proves the derived
8
- * list equals RECORDED with CHANGES applied, CHANGES naming every cell that
9
- * moved. A list the code only asks membership of is compared as a set; a
10
- * list whose order means something (TYPE_RANK) is compared in order.
7
+ * a filter over a registry field (./kind-lists), and this proves two things:
8
+ * each consumer named in RECORDED reads the derived list (CONSUMERS: its
9
+ * file binds the list's name, so the value it uses is the derived one), and
10
+ * the derived list equals RECORDED with CHANGES applied, CHANGES naming
11
+ * every cell that moved. A list the code only asks membership of is
12
+ * compared as a set; a list whose order means something (TYPE_RANK) or that
13
+ * CHANGES says moved in order is compared in order.
11
14
  */
15
+ import { readFileSync } from 'node:fs';
12
16
  import { describe, expect, it } from 'vitest';
13
17
  import {
14
18
  ACCEPTED_KINDS,
@@ -190,7 +194,91 @@ export const CHANGES = {
190
194
  Record<keyof typeof RECORDED, { add?: readonly string[]; order?: true; why: string }>
191
195
  >;
192
196
 
197
+ /**
198
+ * Where each recorded list is read now: the consumer file and the line that
199
+ * binds it to the derived list (whitespace collapsed). The lists themselves
200
+ * are not exported by most consumers (and importing server code here would
201
+ * turn the package graph around), so the test reads the binding: a consumer
202
+ * that went back to a literal, or to another list, fails here as well as in
203
+ * the lint (no-hand-kind-lists).
204
+ */
205
+ export const CONSUMERS: Record<keyof typeof RECORDED, readonly [string, string]> = {
206
+ DEFAULT_EXTRACT_TYPES: [
207
+ 'server/api/src/agent/extract/gates.ts',
208
+ 'const DEFAULT_EXTRACT_TYPES: readonly string[] = EXTRACT_KINDS;',
209
+ ],
210
+ LANDED_TYPES: [
211
+ 'server/web/lib/integrity/landed.ts',
212
+ 'export const LANDED_TYPES: readonly string[] = EXTRACT_KINDS;',
213
+ ],
214
+ CORPUS_MAP_TYPES: [
215
+ 'packages/runtime/src/agent/conversation.ts',
216
+ 'const CORPUS_MAP_TYPES: readonly string[] = CORPUS_MAP_KINDS;',
217
+ ],
218
+ CONTEXT_KINDS: [
219
+ 'packages/db/src/context-ref-resolve.ts',
220
+ 'export const CONTEXT_KINDS = CONTEXT_REF_KINDS;',
221
+ ],
222
+ NODE_TYPE_BY_KIND: [
223
+ 'packages/db/src/context-ref-resolve.ts',
224
+ "Object.entries(NODE_TYPE_BY_CONTEXT_REF).filter(([kind]) => kind !== 'email'),",
225
+ ],
226
+ EMBEDDING_KINDS: [
227
+ 'packages/content/src/embed-closure.ts',
228
+ 'export const EMBEDDING_KINDS: readonly string[] = REGISTRY_EMBEDDING_KINDS;',
229
+ ],
230
+ REFOLD_KINDS: [
231
+ 'server/web/lib/maintenance/refold-embeds.ts',
232
+ 'const KINDS: readonly Kind[] = EMBEDDING_KINDS;',
233
+ ],
234
+ MENTION_TARGETS: [
235
+ 'server/web/app/api/mentions/search/route.ts',
236
+ 'inArray(nodes.type, [...MENTION_TARGET_KINDS]),',
237
+ ],
238
+ LINK_SERVE_KINDS: [
239
+ 'packages/content/src/link-serve.ts',
240
+ 'if (!(LINK_SERVE_KINDS as readonly string[]).includes(item.type)) return new Set();',
241
+ ],
242
+ EXPORTABLE_TYPES: [
243
+ 'packages/content/src/export-node.ts',
244
+ 'export const EXPORTABLE_TYPES: Readonly<Record<ExportKind, ExportFormat>> = EXPORT_FORMAT_BY_KIND;',
245
+ ],
246
+ TYPE_RANK: ['packages/content/src/login-notices.ts', 'const rank = acceptedRank;'],
247
+ SWITCH_MEMBER_ACCEPTED: ['packages/content/src/member-accepted.ts', 'forAcceptedKind<'],
248
+ SWITCH_MEMBER_LIBRARY: ['packages/content/src/member-library.ts', 'forAcceptedKind<'],
249
+ SWITCH_MEMBER_SNAPSHOTS: ['packages/content/src/member-snapshots.ts', 'forAcceptedKind<'],
250
+ SWITCH_SNAPSHOT_COPIES: ['server/web/lib/snapshot-copies.ts', 'forAcceptedKind<'],
251
+ SEARCH_NODES_TYPE_ENUM: [
252
+ 'packages/tools/src/builtins-search.ts',
253
+ 'enum: [...SEARCH_TOOL_KINDS],',
254
+ ],
255
+ MCP_SEARCH_TYPE_ENUM: [
256
+ 'packages/mcp-core/src/mcp-defs.ts',
257
+ 'type: z.enum(SEARCH_TOOL_KINDS).optional(),',
258
+ ],
259
+ PEER_PICKER_EXCLUDED: [
260
+ 'server/web/app/api/peers/nodes/route.ts',
261
+ 'const EXCLUDED = PEER_PICK_EXCLUDED_KINDS;',
262
+ ],
263
+ DOCUMENT_NODE_TYPES: [
264
+ 'packages/content/src/entity-names.ts',
265
+ 'const DOCUMENT_NODE_TYPES: ReadonlySet<string> = new Set(DOCUMENT_TITLE_KINDS);',
266
+ ],
267
+ };
268
+
269
+ const REPO = new URL('../../../', import.meta.url);
270
+ const flat = (t: string) => t.replace(/\s+/g, ' ');
271
+
193
272
  const set = (xs: readonly string[]) => [...xs].sort();
273
+ /** `xs` in registry order (the order kindsWhere gives). */
274
+ const inRegistryOrder = (xs: readonly string[]) =>
275
+ ITEM_KIND_NAMES.filter((t) => (xs as readonly string[]).includes(t));
276
+ /** The lists CHANGES says moved in order: compared in order. */
277
+ const ORDER_MOVED = new Set(
278
+ Object.entries(CHANGES)
279
+ .filter(([, c]) => 'order' in c)
280
+ .map(([name]) => name),
281
+ );
194
282
  const omit = <T extends Record<string, unknown>>(o: T, k: string) =>
195
283
  Object.fromEntries(Object.entries(o).filter(([key]) => key !== k));
196
284
 
@@ -213,8 +301,9 @@ function derived(): Record<keyof typeof RECORDED, unknown> {
213
301
  SWITCH_MEMBER_LIBRARY: accepted,
214
302
  SWITCH_MEMBER_SNAPSHOTS: accepted,
215
303
  SWITCH_SNAPSHOT_COPIES: accepted,
216
- SEARCH_NODES_TYPE_ENUM: set(SEARCH_TOOL_KINDS),
217
- MCP_SEARCH_TYPE_ENUM: set(SEARCH_TOOL_KINDS),
304
+ // In order: CHANGES says these moved to registry order.
305
+ SEARCH_NODES_TYPE_ENUM: [...SEARCH_TOOL_KINDS],
306
+ MCP_SEARCH_TYPE_ENUM: [...SEARCH_TOOL_KINDS],
218
307
  PEER_PICKER_EXCLUDED: set(PEER_PICK_EXCLUDED_KINDS),
219
308
  DOCUMENT_NODE_TYPES: set(DOCUMENT_TITLE_KINDS),
220
309
  };
@@ -227,7 +316,8 @@ function expected(): Record<keyof typeof RECORDED, unknown> {
227
316
  const change = (CHANGES as Partial<Record<string, { add?: readonly string[] }>>)[name];
228
317
  if (Array.isArray(value)) {
229
318
  const list = [...(value as string[]), ...(change?.add ?? [])];
230
- out[name] = name === 'TYPE_RANK' ? list : set(list);
319
+ out[name] =
320
+ name === 'TYPE_RANK' ? list : ORDER_MOVED.has(name) ? inRegistryOrder(list) : set(list);
231
321
  } else out[name] = value;
232
322
  }
233
323
  return out;
@@ -238,12 +328,33 @@ describe('the hand kind lists, derived from the registry', () => {
238
328
  expect(derived()).toEqual(expected());
239
329
  });
240
330
 
241
- it('CHANGES names only lists that moved', () => {
331
+ it('each recorded list is read from the derived list by its consumer', () => {
332
+ for (const [name, [file, binding]] of Object.entries(CONSUMERS)) {
333
+ const text = flat(readFileSync(new URL(file, REPO), 'utf8'));
334
+ expect(text.includes("from '@mantle/client-types/kind-lists'"), `${name}: ${file}`).toBe(
335
+ true,
336
+ );
337
+ expect(text.includes(flat(binding)), `${name}: ${file} binds ${binding}`).toBe(true);
338
+ }
339
+ });
340
+
341
+ it('CHANGES names only lists that moved: an order entry moved its order and kept its set', () => {
242
342
  for (const name of Object.keys(CHANGES) as (keyof typeof CHANGES)[]) {
243
343
  const was = RECORDED[name] as readonly string[];
244
344
  const now = derived()[name] as readonly string[];
245
- const moved = 'order' in CHANGES[name] ? true : set(was).join() !== set(now).join();
246
- expect(moved, name).toBe(true);
345
+ if ('order' in CHANGES[name]) {
346
+ expect(now.join(), `${name}: the order moved`).not.toBe(was.join());
347
+ expect(set(now), `${name}: the same set`).toEqual(set(was));
348
+ } else {
349
+ expect(set(now).join(), `${name}: the set moved`).not.toBe(set(was).join());
350
+ }
351
+ }
352
+ });
353
+
354
+ it('the derived lists are frozen: one shared list cannot be changed through a name (F4)', () => {
355
+ for (const list of [EXTRACT_KINDS, SEARCH_TOOL_KINDS, ACCEPTED_KINDS, EMBEDDING_KINDS]) {
356
+ expect(Object.isFrozen(list)).toBe(true);
357
+ expect(() => (list as unknown as string[]).push('x')).toThrow(TypeError);
247
358
  }
248
359
  });
249
360
 
package/src/kinds.ts CHANGED
@@ -801,11 +801,16 @@ export const ITEM_KIND_NAMES = Object.keys(ITEM_KINDS) as ItemKind[];
801
801
  export type KindsWhere<P> = { [K in ItemKind]: Kinds[K] extends P ? K : never }[ItemKind];
802
802
 
803
803
  /** The node types whose spec passes `pick`, in registry order. Never empty for
804
- * the lists derived here (their snapshot tests say so). */
804
+ * the lists derived here (their snapshot tests say so). Frozen: several
805
+ * names share one list (DEFAULT_EXTRACT_TYPES and LANDED_TYPES are both
806
+ * EXTRACT_KINDS), so a caller that sorted or pushed onto its own would
807
+ * change every other's (low round, F4). */
805
808
  export function kindsWhere<K extends ItemKind = ItemKind>(
806
809
  pick: (spec: KindSpec, type: ItemKind) => boolean,
807
810
  ): readonly [K, ...K[]] {
808
- return ITEM_KIND_NAMES.filter((t) => pick(ITEM_KINDS[t], t)) as unknown as readonly [K, ...K[]];
811
+ return Object.freeze(
812
+ ITEM_KIND_NAMES.filter((t) => pick(ITEM_KINDS[t], t)),
813
+ ) as unknown as readonly [K, ...K[]];
809
814
  }
810
815
 
811
816
  /** The spec of `type`, or null for a value the registry does not know. */
@@ -7,8 +7,11 @@
7
7
  * every copy of a concept already held its source's values (no difference
8
8
  * on main). Now each copy reads its source (./role-names and the dto lists),
9
9
  * and this proves each source holds exactly the values main recorded, in
10
- * main's order. A list the code only asks membership of is compared as a
11
- * set; a list whose order means something is compared in order (ORDERED).
10
+ * main's order, and that each recorded copy's file now names its source.
11
+ * A list the code only asks membership of is compared as a set; a list
12
+ * whose order means something is compared in order (ORDERED). That no hand
13
+ * copy is left anywhere is the lint's (no-hand-role-lists, pinned at 0 in
14
+ * eslint-rules/arch-lints.test.ts).
12
15
  *
13
16
  * These are also the contract's VALUES (jackdaw holds hand copies of some):
14
17
  * a change here is a contract change, made on purpose.
@@ -189,6 +192,19 @@ const SOURCES = {
189
192
  keyArea: ACCESS_KEY_AREAS,
190
193
  } as const satisfies Record<keyof typeof RECORDED, readonly string[]>;
191
194
 
195
+ /** The names a copy reads its concept's source by: the list, its type, its
196
+ * guard or its zod schema (LoginRoleSchema in server/web/lib/login-update.ts,
197
+ * z.enum(LOGIN_ROLES)). */
198
+ const SOURCE_NAMES = {
199
+ loginRole: ['LOGIN_ROLES', 'LoginRole', 'isLoginRole', 'LoginRoleSchema'],
200
+ workspaceArea: ['WORKSPACE_AREAS', 'WorkspaceArea', 'isWorkspaceArea'],
201
+ historyActor: ['HISTORY_ACTORS', 'HistoryActor'],
202
+ recallActor: ['RECALL_ACTOR_KINDS', 'RecallActorKind'],
203
+ accessLevel: ['ACCESS_LEVELS', 'AccessLevel'],
204
+ keyArea: ['ACCESS_KEY_AREAS', 'AccessKeyArea'],
205
+ } as const satisfies Record<keyof typeof RECORDED, readonly string[]>;
206
+
207
+ const REPO = new URL('../../../', import.meta.url);
192
208
  const MIGRATIONS = new URL('../../db/migrations/', import.meta.url);
193
209
 
194
210
  /** The text of the newest migration that adds `constraint`. */
@@ -210,8 +226,9 @@ function newestCheck(constraint: string): string {
210
226
 
211
227
  const quoted = (values: readonly string[]) => values.map((v) => `'${v}'`).join(', ');
212
228
 
213
- /** Each copy that differs from its source (as a set, or in order for
214
- * ORDERED): none on main. */
229
+ /** Each RECORDED copy that differs from its source (as a set, or in order
230
+ * for ORDERED): none. A check of the record (literals against literals),
231
+ * not of the code: see the copies' own test below. */
215
232
  function differences(): string[] {
216
233
  const out: string[] = [];
217
234
  for (const [concept, { source: src, copies }] of Object.entries(RECORDED)) {
@@ -234,10 +251,25 @@ describe('the role, area and actor names, recorded on main v0.300.47', () => {
234
251
  }
235
252
  });
236
253
 
237
- it('every copy on main already held its source values', () => {
254
+ it('the record: every copy main held had its source values', () => {
238
255
  expect(differences()).toEqual([]);
239
256
  });
240
257
 
258
+ it('every recorded copy reads its source now: its file names the list, its type or its guard', () => {
259
+ const missing: string[] = [];
260
+ for (const [concept, { copies }] of Object.entries(RECORDED)) {
261
+ const names: readonly string[] = SOURCE_NAMES[concept as keyof typeof RECORDED];
262
+ for (const site of Object.keys(copies)) {
263
+ const file = site.split(' ')[0]!;
264
+ const text = readFileSync(new URL(file, REPO), 'utf8');
265
+ if (!names.some((n) => new RegExp(`\\b${n}\\b`).test(text))) {
266
+ missing.push(`${concept}: ${site}`);
267
+ }
268
+ }
269
+ }
270
+ expect(missing).toEqual([]);
271
+ });
272
+
241
273
  it('the guards accept exactly the source values', () => {
242
274
  for (const r of LOGIN_ROLES) expect(isLoginRole(r)).toBe(true);
243
275
  for (const v of ['client', 'owner', 'Admin', '', null, undefined, 1]) {