@_linked/core 2.36.1 → 2.36.3

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +19 -0
  3. package/lib/esm/collections/CoreSet.js +2 -0
  4. package/lib/esm/collections/CoreSet.js.map +1 -1
  5. package/lib/esm/collections/ShapeSet.js +2 -0
  6. package/lib/esm/collections/ShapeSet.js.map +1 -1
  7. package/lib/esm/expressions/Expr.js +3 -2
  8. package/lib/esm/expressions/Expr.js.map +1 -1
  9. package/lib/esm/expressions/ExpressionNode.js +10 -7
  10. package/lib/esm/expressions/ExpressionNode.js.map +1 -1
  11. package/lib/esm/index.d.ts +1 -1
  12. package/lib/esm/index.js +1 -1
  13. package/lib/esm/index.js.map +1 -1
  14. package/lib/esm/queries/AskBuilder.js +5 -3
  15. package/lib/esm/queries/AskBuilder.js.map +1 -1
  16. package/lib/esm/queries/CountBuilder.js +4 -2
  17. package/lib/esm/queries/CountBuilder.js.map +1 -1
  18. package/lib/esm/queries/CreateBuilder.js +2 -0
  19. package/lib/esm/queries/CreateBuilder.js.map +1 -1
  20. package/lib/esm/queries/DeleteBuilder.js +3 -1
  21. package/lib/esm/queries/DeleteBuilder.js.map +1 -1
  22. package/lib/esm/queries/DslJsonExpression.js +7 -6
  23. package/lib/esm/queries/DslJsonExpression.js.map +1 -1
  24. package/lib/esm/queries/FieldSet.js +10 -8
  25. package/lib/esm/queries/FieldSet.js.map +1 -1
  26. package/lib/esm/queries/IRLower.js +2 -1
  27. package/lib/esm/queries/IRLower.js.map +1 -1
  28. package/lib/esm/queries/MutationSerialization.js +2 -1
  29. package/lib/esm/queries/MutationSerialization.js.map +1 -1
  30. package/lib/esm/queries/PropertyPath.js +2 -0
  31. package/lib/esm/queries/PropertyPath.js.map +1 -1
  32. package/lib/esm/queries/ProxiedPathBuilder.js +2 -1
  33. package/lib/esm/queries/ProxiedPathBuilder.js.map +1 -1
  34. package/lib/esm/queries/QueryBuilder.js +5 -4
  35. package/lib/esm/queries/QueryBuilder.js.map +1 -1
  36. package/lib/esm/queries/QueryContext.js +17 -6
  37. package/lib/esm/queries/QueryContext.js.map +1 -1
  38. package/lib/esm/queries/SelectQuery.js +18 -12
  39. package/lib/esm/queries/SelectQuery.js.map +1 -1
  40. package/lib/esm/queries/UpdateBuilder.js +3 -1
  41. package/lib/esm/queries/UpdateBuilder.js.map +1 -1
  42. package/lib/esm/queries/lower.js +5 -4
  43. package/lib/esm/queries/lower.js.map +1 -1
  44. package/lib/esm/shapes/SHACL.js +6 -3
  45. package/lib/esm/shapes/SHACL.js.map +1 -1
  46. package/lib/esm/shapes/Shape.d.ts +3 -1
  47. package/lib/esm/shapes/Shape.js +20 -2
  48. package/lib/esm/shapes/Shape.js.map +1 -1
  49. package/lib/esm/utils/LinkedErrorLogging.d.ts +2 -1
  50. package/lib/esm/utils/LinkedErrorLogging.js +11 -0
  51. package/lib/esm/utils/LinkedErrorLogging.js.map +1 -1
  52. package/lib/esm/utils/LinkedFileStorage.d.ts +6 -4
  53. package/lib/esm/utils/LinkedFileStorage.js +34 -4
  54. package/lib/esm/utils/LinkedFileStorage.js.map +1 -1
  55. package/lib/esm/utils/Package.d.ts +6 -0
  56. package/lib/esm/utils/Package.js +35 -7
  57. package/lib/esm/utils/Package.js.map +1 -1
  58. package/lib/esm/utils/Prefix.d.ts +4 -2
  59. package/lib/esm/utils/Prefix.js +18 -2
  60. package/lib/esm/utils/Prefix.js.map +1 -1
  61. package/lib/esm/utils/ShapeClass.js +11 -6
  62. package/lib/esm/utils/ShapeClass.js.map +1 -1
  63. package/lib/esm/utils/cached.js +2 -1
  64. package/lib/esm/utils/cached.js.map +1 -1
  65. package/lib/esm/utils/linkedError.d.ts +32 -0
  66. package/lib/esm/utils/linkedError.js +63 -0
  67. package/lib/esm/utils/linkedError.js.map +1 -1
  68. package/lib/esm/utils/unresolvedShape.d.ts +3 -1
  69. package/lib/esm/utils/unresolvedShape.js +5 -1
  70. package/lib/esm/utils/unresolvedShape.js.map +1 -1
  71. package/package.json +1 -1
@@ -6,6 +6,8 @@ var _a, _b, _c;
6
6
  import * as ShapeModule from '../shapes/Shape.js';
7
7
  import { getPropertyShape, } from '../shapes/nodeShapeData.js';
8
8
  import { RegistryCache } from './registryCache.js';
9
+ import { sharedState } from './sharedState.js';
10
+ import { isLinkedInstance } from './linkedError.js';
9
11
  export { RegistryCache };
10
12
  const resolveTargetClassId = (targetClass) => {
11
13
  var _a;
@@ -192,7 +194,7 @@ export function shapeCatalogKey(catalog) {
192
194
  return key;
193
195
  }
194
196
  /** The catalog of an adapter class a catalog built, keyed on the class. */
195
- const adapterCatalogs = new WeakMap();
197
+ const adapterCatalogs = sharedState('@_linked/core', 'ShapeClass.adapterCatalogs', () => new WeakMap());
196
198
  /**
197
199
  * The catalog a builder made from `shape` captures.
198
200
  *
@@ -351,8 +353,11 @@ const shapeAdapters = registryState.shapeAdapters;
351
353
  * you specifically need an authored class; use this when you need *something*
352
354
  * constructor-shaped to drive the query builders.
353
355
  */
354
- /** Adapters built inside a catalog: one map per catalog, keyed by IRI. */
355
- const catalogAdapters = new WeakMap();
356
+ /**
357
+ * Adapters built inside a catalog: one map per catalog, keyed by IRI. Shared with
358
+ * `adapterCatalogs` above, so an adapter one copy of core built keeps its catalog in another.
359
+ */
360
+ const catalogAdapters = sharedState('@_linked/core', 'ShapeClass.catalogAdapters', () => new WeakMap());
356
361
  export function getOrCreateShapeAdapter(nodeShape) {
357
362
  var _a;
358
363
  const catalog = registryState.activeCatalog;
@@ -783,7 +788,7 @@ export function hasSuperClass(a, b) {
783
788
  if (aData && bData)
784
789
  return isSubShapeOf(aData, bData);
785
790
  return typeof a === 'function' && typeof b === 'function'
786
- ? a.prototype instanceof b
791
+ ? isLinkedInstance(a.prototype, b)
787
792
  : false;
788
793
  }
789
794
  /** True when `b` extends `a` — the mirror of {@link hasSuperClass}. */
@@ -838,7 +843,7 @@ export function getMostSpecificSubShapes(shape) {
838
843
  function filterShapesToMostSpecific(subShapes) {
839
844
  return subShapes.filter((subShape) => {
840
845
  return !subShapes.some((otherSubShape) => {
841
- return otherSubShape.prototype instanceof subShape;
846
+ return isLinkedInstance(otherSubShape.prototype, subShape);
842
847
  });
843
848
  });
844
849
  }
@@ -850,7 +855,7 @@ function filterShapesToLeastSpecific(shapeClasses) {
850
855
  return shapeClasses.filter((shapeClass) => {
851
856
  return !shapeClasses.some((otherShapeClass) => {
852
857
  return (otherShapeClass !== shapeClass &&
853
- shapeClass.prototype instanceof otherShapeClass);
858
+ isLinkedInstance(shapeClass.prototype, otherShapeClass));
854
859
  });
855
860
  });
856
861
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ShapeClass.js","sourceRoot":"","sources":["../../../src/utils/ShapeClass.ts"],"names":[],"mappings":";AACA,sFAAsF;AACtF,6FAA6F;AAC7F,sFAAsF;AACtF,wFAAwF;AACxF,OAAO,KAAK,WAAW,MAAM,oBAAoB,CAAC;AAClD,OAAO,EACL,gBAAgB,GAGjB,MAAM,4BAA4B,CAAC;AAKpC,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAC,aAAa,EAAC,CAAC;AAEvB,MAAM,oBAAoB,GAAG,CAC3B,WAAuC,EACxB,EAAE;;IACjB,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAC9B,OAAO,MAAA,WAAW,CAAC,EAAE,mCAAI,IAAI,CAAC;AAChC,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,mBAAmB,GACvB,OAAO,UAAU,KAAK,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAE,EAAU,CAAC;AAE/D;;;;;;;;GAQG;AACH,MAAM,SAAS,GAAW,EAAE,CAAC;AAC7B,MAAM,MAAM,GAAgB,OAAC,mBAAmB,CAAC,2BAA2B,oCAA/C,mBAAmB,CAAC,2BAA2B,GAAK,IAAI,GAAG,E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SAAS;IAC3C,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE;QACnC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE;YACvC,OAAO,aAAa,CAAC,SAAS,YAAY,QAAQ,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,SAAS,2BAA2B,CAAC,YAAY;IAC/C,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;QACxC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,EAAE;YAC5C,OAAO,CACL,eAAe,KAAK,UAAU;gBAC9B,UAAU,CAAC,SAAS,YAAY,eAAe,CAChD,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,MAAM,CAAC,KAAsC;IACpD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC5C,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,WAAW,CAAC,KAAmB;IACtC,uCAAuC;IACvC,OAAO,CACL,oBAAoB,CAAC,KAAK,CAAC,WAAW,CAAC;QACvC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CACrE,CAAC;AACJ,CAAC","sourcesContent":["import {type Shape, type ShapeConstructor} from '../shapes/Shape.js';\n// Namespace import, read at CALL time rather than captured at module-evaluation time.\n// `getOrCreateShapeAdapter` subclasses `Shape` at runtime, and under some import orders this\n// module finishes evaluating before `Shape.js` does — a named import captured then is\n// permanently `undefined`, and the subclass fails with \"Class extends value undefined\".\nimport * as ShapeModule from '../shapes/Shape.js';\nimport {\n getPropertyShape,\n type NodeShapeData,\n type PropertyShapeData,\n} from '../shapes/nodeShapeData.js';\nimport type {NodeShapeWire} from '../shapes/nodeShapeWire.js';\nimport type {ICoreIterable} from '../interfaces/ICoreIterable.js';\nimport type {NodeReferenceValue} from './NodeReference.js';\nimport type {ShapeCatalog} from './ShapeCatalog.js';\nimport {RegistryCache} from './registryCache.js';\n\nexport {RegistryCache};\n\nconst resolveTargetClassId = (\n targetClass?: NodeReferenceValue | null,\n): string | null => {\n if (!targetClass) return null;\n return targetClass.id ?? null;\n};\n\n/**\n * The shape registries live on `globalThis`, not in module scope.\n *\n * A module can evaluate more than once in one process, and in a built app it does: an\n * app's backend is assembled from two graphs, one loaded by the bundler from `src/` and\n * one resolved by Node to `lib/esm/`. A module-scope `Map` then exists twice — shapes\n * register into one copy and every lookup reads the other, which finds nothing.\n *\n * The symptom never mentions module identity. It is `Invalid property key: projectSlug.\n * The shape Project does not have a registered property with this name` for a property\n * that is declared correctly two files away, because validation ran on the copy the\n * decorators never reached. See docs/reports/043-module-identity-in-the-backend.md.\n *\n * Sharing the state makes duplication harmless rather than merely absent: the graphs\n * still hold two copies of this module, but only one registry. `LinkedStorage` already\n * keeps its instance counter here; this keeps the data itself.\n */\nconst shapeRegistryGlobal: any =\n typeof globalThis !== 'undefined' ? globalThis : ({} as any);\n\n/**\n * Counts DISTINCT physical copies of this module, not evaluations of it.\n *\n * The difference matters. A bare `count++` here is incremented by Vite's HMR every time\n * the module is re-evaluated in the same process, against the same `globalThis` — so a\n * developer who edits a file a few times sees a count of 4 and goes hunting a\n * dual-resolution problem that does not exist. Recording a token per copy and counting\n * the tokens survives re-evaluation: HMR replaces the module, and its token with it.\n */\nconst copyToken: object = {};\nconst copies: Set<object> = (shapeRegistryGlobal.__linkedShapeRegistryCopies ??= new Set());\ncopies.add(copyToken);\n\n/**\n * More than one copy of this module means shapes register into one registry and are\n * looked up in another, and the resulting failures never mention module identity — they\n * say a declared property is not declared, or that a pinned shape has no pin.\n *\n * Reported rather than thrown. A throw from a library module at import time breaks\n * tooling that legitimately loads a module twice, and the shared state above means a\n * second copy is survivable: it is a correctness hazard for anything holding a class\n * reference, not an immediate failure. So this says so, once, as loudly as a log can.\n */\nif (copies.size > 1) {\n console.error(\n `[linked] ${copies.size} copies of @_linked/core's shape registry have loaded in ` +\n `this process. They share one registry, so lookups still resolve — but each copy ` +\n `has its own \\`Shape\\` base class, so \\`instanceof\\` comparisons across them are ` +\n `false and adapters built by one copy do not satisfy the other. This is a module ` +\n `resolution problem: part of the app is reaching this package by a path that ` +\n `resolves to its source and part by one that resolves to its build output.`,\n );\n}\n\n/**\n * One shared container, created by whichever copy evaluates first.\n *\n * `registryVersion` belongs here too: every derived cache in this module is keyed on it,\n * so a version that is not shared would let one copy's writes leave another copy's caches\n * looking valid. The caches themselves stay per-copy — they are rebuilt whenever the\n * shared version moves past them.\n */\nconst registryState: {\n nodeShapeToShapeClass: Map<string, typeof Shape>;\n nodeShapeRegistry: Map<string, NodeShapeData>;\n shapeAdapters: Map<string, typeof Shape>;\n registryVersion: number;\n /**\n * The catalog `withShapeCatalog` made current, or undefined for the global registry.\n * Shared like the rest, so a scope opened by one copy of this module is seen by another.\n */\n activeCatalog: ShapeCatalog | undefined;\n} = (shapeRegistryGlobal.__linkedShapeRegistry ??= {\n nodeShapeToShapeClass: new Map(),\n nodeShapeRegistry: new Map(),\n shapeAdapters: new Map(),\n registryVersion: 0,\n activeCatalog: undefined,\n});\n// A container created by an older copy has no slot yet; give it one so every read below\n// sees the same object layout.\nif (!('activeCatalog' in (registryState as object))) registryState.activeCatalog = undefined;\n\n/** How many distinct copies of this module are loaded. One is expected. */\nexport function getShapeRegistryInstanceCount(): number {\n return copies.size;\n}\n\n// ---------------------------------------------------------------------------\n// The active shape catalog\n// ---------------------------------------------------------------------------\n\n/**\n * Run `fn` with `catalog` as the shapes every registry accessor reads; `undefined` means\n * the global registry (explicitly — it does not inherit an outer catalog).\n *\n * Synchronous on purpose: it works the same in the browser and in Node, with no\n * AsyncLocalStorage. Scopes nest, the previous catalog is restored in `finally`, and fn's\n * value is returned unchanged. A promise returned by fn is not awaited, so its\n * continuation runs outside the scope. That is why builders and IRs capture their catalog\n * and every place that picks one up later re-enters it (see docs/architecture/runtime-instances.md).\n */\nexport function withShapeCatalog<T>(catalog: ShapeCatalog | undefined, fn: () => T): T {\n const previous = registryState.activeCatalog;\n if (previous === catalog) return fn();\n registryState.activeCatalog = catalog;\n try {\n const result = fn();\n if (result instanceof Promise) warnPromiseInScope();\n return result;\n } finally {\n registryState.activeCatalog = previous;\n }\n}\n\n/**\n * Run `fn` with no catalog active, without the promise warning: for core's own calls into a\n * dataset, whose asynchronous continuation is meant to run outside any catalog. @internal\n */\nexport function outsideShapeCatalog<T>(fn: () => T): T {\n const previous = registryState.activeCatalog;\n if (previous === undefined) return fn();\n registryState.activeCatalog = undefined;\n try {\n return fn();\n } finally {\n registryState.activeCatalog = previous;\n }\n}\n\nlet warnedPromiseInScope = false;\n\n/**\n * A scope ends when `fn` returns, so the continuation of a promise `fn` returns runs outside\n * it. Said once, outside production. A builder (a thenable, not a Promise) is the intended\n * return value: it captured the catalog and re-enters it.\n */\nfunction warnPromiseInScope(): void {\n if (warnedPromiseInScope) return;\n const env = (globalThis as {process?: {env?: Record<string, string | undefined>}}).process?.env;\n if (env?.NODE_ENV === 'production') return;\n warnedPromiseInScope = true;\n console.warn(\n '[linked] withShapeCatalog(catalog, fn): fn returned a promise. The scope ended when fn ' +\n 'returned, so code after its first await runs outside the catalog. Build the query inside ' +\n 'the scope and await it outside — a builder keeps its catalog.',\n );\n}\n\n/** The catalog of the current `withShapeCatalog` scope, or undefined for the global registry. */\nexport function getActiveShapeCatalog(): ShapeCatalog | undefined {\n return registryState.activeCatalog;\n}\n\n/**\n * The catalog a builder, a FieldSet or an IR captured — undefined means the global registry.\n * Reads the object's `catalog` field, which builders keep as a getter and IRs as a\n * non-enumerable property, so neither appears in `toJSON` or a JSON round trip.\n */\nexport function catalogOf(queryOrIr: object | null | undefined): ShapeCatalog | undefined {\n return (queryOrIr as {catalog?: ShapeCatalog} | null | undefined)?.catalog;\n}\n\n/**\n * Record `catalog` on an IR object as a non-enumerable `catalog` field, so the code that\n * compiles it later (often after an `await`) re-enters the catalog it was lowered in.\n * Nothing is written for the global registry: an IR without the field compiles globally.\n * @internal\n */\nexport function attachCatalog<T extends object>(\n ir: T,\n catalog: ShapeCatalog | undefined = registryState.activeCatalog,\n): T {\n if (catalog !== undefined) {\n Object.defineProperty(ir, 'catalog', {\n value: catalog,\n enumerable: false,\n configurable: true,\n writable: true,\n });\n }\n return ir;\n}\n\n/**\n * Process-unique ids for catalogs, for live-query template keys. On `globalThis`, like the\n * registry, so two copies of core give one catalog the same id.\n */\nconst keyState: {keys: WeakMap<object, number>; next: number} =\n (shapeRegistryGlobal.__linkedShapeCatalogKeys ??= {keys: new WeakMap(), next: 1});\n\n/** 0 for the global registry, else a process-unique id for the catalog. */\nexport function shapeCatalogKey(catalog: ShapeCatalog | undefined): number {\n if (catalog === undefined) return 0;\n let key = keyState.keys.get(catalog);\n if (key === undefined) {\n key = keyState.next++;\n keyState.keys.set(catalog, key);\n }\n return key;\n}\n\n/** The catalog of an adapter class a catalog built, keyed on the class. */\nconst adapterCatalogs = new WeakMap<Function, ShapeCatalog>();\n\n/**\n * The catalog a builder made from `shape` captures.\n *\n * Inside a scope: the active catalog when the root is an IRI (`shape` undefined) or a\n * shape the catalog holds; otherwise none. A class the active catalog does not hold is\n * authored code (CN's own shapes, built by CN code while a project scope is active) and\n * must lower against the global registry. Outside a scope: the catalog that built the\n * adapter class, if it is one, else none.\n * @internal\n */\nexport function captureCatalog(\n shape?: {shape?: {id?: string}} | Function | null,\n): ShapeCatalog | undefined {\n const active = registryState.activeCatalog;\n if (shape === undefined || shape === null) return active;\n if (active !== undefined) {\n const id = (shape as {shape?: {id?: string}}).shape?.id;\n if (id && active.has(id)) return active;\n }\n return typeof shape === 'function' ? adapterCatalogs.get(shape) : undefined;\n}\n\n/**\n * Throw when a registry write is attempted inside a catalog scope. A catalog is\n * immutable, and a write meant for it would land in the global registry instead.\n * @internal\n */\nexport function assertNoActiveCatalog(): void {\n if (registryState.activeCatalog !== undefined) {\n throw new Error(\n 'Cannot register shapes while a ShapeCatalog is active. Register outside ' +\n 'withShapeCatalog, or build a new catalog with ShapeCatalog.from().',\n );\n }\n}\n\n/** What a catalog holds, as the accessors below read it. Plain fields: any copy can read them. */\ntype CatalogContents = {\n readonly nodeShapes: ReadonlyMap<string, NodeShapeData>;\n readonly shapeClasses: ReadonlyMap<string, typeof Shape>;\n};\n\nfunction contentsOf(catalog: ShapeCatalog): CatalogContents {\n return catalog as unknown as CatalogContents;\n}\n\nconst subShapesCache = new RegistryCache<string, (typeof Shape)[]>();\nconst mostSpecificSubShapesCache = new RegistryCache<string, (typeof Shape)[]>();\nconst nodeShapeToShapeClass = registryState.nodeShapeToShapeClass;\nconst warnedDuplicateBases = new Set<string>();\n\n/**\n * The PRIMARY shape registry: node-shape IRI → its metadata.\n *\n * Every shape is here — those declared by a `@linkedShape` class and those known only\n * as data (a project-authored shape read from the graph). `nodeShapeToShapeClass` above\n * is the SECONDARY registry, holding only the shapes that have a TypeScript class, and\n * exists for the few callers that genuinely need a class (a `ShapeProvider` lookup, a\n * typed accessor). Query lowering, predicate resolution and containment all read\n * metadata, so they use this map and work identically for both kinds of shape.\n */\nconst nodeShapeRegistry = registryState.nodeShapeRegistry;\n\n/**\n * The shapes the accessors read: the active catalog's (its shapes plus core's built-ins),\n * else the global registry. One shared read and a null check on the global path.\n */\nfunction activeNodeShapes(): ReadonlyMap<string, NodeShapeData> {\n const catalog = registryState.activeCatalog;\n return catalog === undefined ? nodeShapeRegistry : contentsOf(catalog).nodeShapes;\n}\n\n/** The authored classes the accessors read: the catalog's built-ins, else every registered class. */\nfunction activeShapeClasses(): ReadonlyMap<string, typeof Shape> {\n const catalog = registryState.activeCatalog;\n return catalog === undefined ? nodeShapeToShapeClass : contentsOf(catalog).shapeClasses;\n}\n\n/**\n * The current registration version — a monotonic counter, bumped on every write.\n *\n * Every derived cache in this module, and in `irToAlgebra`, is keyed on it. It replaces\n * two earlier invalidation strategies that were both unsound: a `setTimeout(…, 0)` cache\n * clear (which missed anything registered later in the same session) and comparing the\n * registry SIZE (which silently reuses a stale cache when a registration and a removal\n * coincide, or when a shape is re-registered in place).\n *\n * It lives on the shared state, not in module scope: a cache keyed on a per-copy version\n * would look valid after another copy had written.\n */\nexport function getRegistryVersion(): number {\n return registryState.registryVersion;\n}\n\n/** Reverse index parentIri → direct child IRIs, rebuilt when the registry changes. */\nconst childIndex = new RegistryCache<string, string[]>((index) => {\n activeNodeShapes().forEach((shape, id) => {\n const parent = shape.extends?.id;\n if (!parent) return;\n const siblings = index.get(parent);\n if (siblings) siblings.push(id);\n else index.set(parent, [id]);\n });\n});\n\nfunction getChildIndex(): Map<string, string[]> {\n return childIndex.get();\n}\n\n// Every derived cache is a RegistryCache keyed on this version, so bumping it is the\n// whole invalidation.\nfunction invalidateRegistryCaches() {\n registryState.registryVersion++;\n}\n\n/** Drop the adapter for a shape whose metadata was replaced. */\nfunction invalidateShapeAdapter(id: string) {\n shapeAdapters.delete(id);\n}\n\n/**\n * Register a shape known only as data — no TypeScript class is created.\n *\n * This is the return leg of the round trip: `@linkedShape` is class → metadata,\n * `syncShapes` is metadata → RDF, and this is RDF → metadata. Idempotent: re-registering\n * the same IRI replaces the metadata (a shape edited in the builder), which is why cache\n * invalidation cannot be keyed on registry size.\n */\nexport function registerNodeShape(nodeShape: NodeShapeData): void {\n assertNoActiveCatalog();\n if (!nodeShape?.id) return;\n nodeShapeRegistry.set(nodeShape.id, nodeShape);\n invalidateShapeAdapter(nodeShape.id);\n invalidateRegistryCaches();\n}\n\n/** The metadata for a node-shape IRI, whether or not it has a TypeScript class. */\nexport function getNodeShape(\n nodeShape: NodeReferenceValue | {id: string} | string,\n): NodeShapeData | undefined {\n const id = typeof nodeShape === 'string' ? nodeShape : nodeShape?.id;\n if (!id) return undefined;\n return activeNodeShapes().get(id);\n}\n\n/**\n * Every registered shape's metadata, keyed by node-shape IRI. Inside a catalog scope:\n * exactly the catalog's shapes plus core's built-ins.\n */\nexport function getAllNodeShapes(): ReadonlyMap<string, NodeShapeData> {\n return activeNodeShapes();\n}\n\n/**\n * Lazily-built constructors for shapes that exist only as data.\n *\n * The builder entry points (`QueryBuilder`, `CreateBuilder`, `UpdateBuilder`,\n * `DeleteBuilder` via `resolveShape`) take a `ShapeConstructor` and instantiate result\n * proxies from it, so they need *a* class. Rather than have every caller hand-roll one —\n * which is what `create-now-js`'s `registerRuntimeShape` used to do, losing `extends` and\n * every value constraint on the way — core derives one on demand from the registered\n * metadata and caches it.\n *\n * These adapters are deliberately NOT in `nodeShapeToShapeClass`: `getShapeClass` keeps\n * telling the truth about which shapes have a real, authored class. An adapter carries\n * the metadata verbatim, so nothing is lost, and inheritance is read from\n * `nodeShape.extends` (not from the adapter's prototype, which is always `Shape`).\n */\nconst shapeAdapters = registryState.shapeAdapters;\n\n/**\n * A constructor for a shape known only as data, created on first use.\n *\n * Returns undefined when the IRI is not registered at all. Prefer `getShapeClass` when\n * you specifically need an authored class; use this when you need *something*\n * constructor-shaped to drive the query builders.\n */\n/** Adapters built inside a catalog: one map per catalog, keyed by IRI. */\nconst catalogAdapters = new WeakMap<object, Map<string, typeof Shape>>();\n\nexport function getOrCreateShapeAdapter(\n nodeShape: NodeShapeData | string,\n): typeof Shape | undefined {\n const catalog = registryState.activeCatalog;\n const shapes = catalog === undefined ? nodeShapeRegistry : contentsOf(catalog).nodeShapes;\n const data = typeof nodeShape === 'string' ? shapes.get(nodeShape) : nodeShape;\n if (!data?.id) return undefined;\n\n const authored = (\n catalog === undefined ? nodeShapeToShapeClass : contentsOf(catalog).shapeClasses\n ).get(data.id);\n if (authored) return authored;\n\n let adapters: Map<string, typeof Shape> | undefined = shapeAdapters;\n if (catalog !== undefined) {\n adapters = catalogAdapters.get(catalog);\n if (!adapters) catalogAdapters.set(catalog, (adapters = new Map()));\n }\n const cached = adapters.get(data.id);\n // Re-registering a shape replaces its metadata, so an adapter built from the old\n // object must not be reused.\n if (cached && cached.shape === data) return cached;\n\n class RuntimeShape extends ShapeModule.Shape {\n static shape = data as NodeShapeData;\n static targetClass = (data as NodeShapeData).targetClass ?? null;\n }\n Object.defineProperty(RuntimeShape, 'name', {\n value: (data as NodeShapeData).label || 'RuntimeShape',\n });\n adapters.set(data.id, RuntimeShape);\n if (catalog !== undefined) adapterCatalogs.set(RuntimeShape, catalog);\n return RuntimeShape;\n}\n\n/** Anything that can identify a shape: its metadata, its class, or its IRI. */\nexport type ShapeLike = NodeShapeData | typeof Shape | Function | string;\n\n/** Resolve a ShapeLike to node-shape metadata, or undefined if it isn't a shape. */\nfunction toNodeShapeData(shape: ShapeLike): NodeShapeData | undefined {\n if (!shape) return undefined;\n const shapes = activeNodeShapes();\n if (typeof shape === 'string') return shapes.get(shape);\n const asData = shape as NodeShapeData;\n // NodeShapeData is a plain object with an id; a Shape class is a function.\n if (typeof shape === 'object' && typeof asData.id === 'string') {\n return shapes.get(asData.id) ?? asData;\n }\n const asClass = shape as typeof Shape;\n const shapeData = asClass?.shape;\n if (shapeData?.id) return shapes.get(shapeData.id) ?? shapeData;\n return undefined;\n}\n\nconst warnedUnresolvedExtends = new Set<string>();\n\n/**\n * Every shape the given shape extends, most specific first.\n *\n * THE canonical inheritance walk — `getPropertyShapes(shape, true)` delegates to it, so\n * there is exactly one answer to \"what does this shape extend\". Two earlier walks\n * disagreed (one over the prototype chain, one over `extends`) and that divergence, not\n * either strategy, was the bug: `selectAll` listed labels from one and resolved them\n * through the other, so an inherited property became unresolvable and the query proxy\n * threw.\n *\n * Strategy is chosen by what is available:\n *\n * - **A class-backed shape walks its prototype chain.** This is authoritative and\n * includes the framework `Shape` root, whose own property shapes (`label`, `type`) are\n * genuinely inherited. `applyLinkedShape` deliberately does NOT record `extends` for\n * that root — it is not a domain shape and must not appear as an `extends` triple in\n * materialized SHACL — so the data alone cannot see it.\n * - **A shape known only as data walks `extends` through the registry.** This is what\n * makes inheritance work for a project-authored shape with no class, which the\n * prototype chain cannot express.\n *\n * `extends` is a REFERENCE, so a parent that was never registered ends the walk. The\n * prototype chain has no such failure mode, so it warns once per shape rather than\n * throwing — this runs on read paths.\n */\nexport function getSuperShapes(shape: ShapeLike): NodeShapeData[] {\n const start = toNodeShapeData(shape);\n const chain: NodeShapeData[] = [];\n if (!start) return chain;\n\n // Class-backed: the prototype chain is the authority.\n const shapes = activeNodeShapes();\n const startClass = activeShapeClasses().get(start.id);\n if (startClass) {\n let current: typeof Shape | undefined = startClass;\n while (current) {\n const parent = Object.getPrototypeOf(current) as typeof Shape | undefined;\n if (!parent?.shape) break;\n chain.push(parent.shape);\n if ((parent as unknown) === (ShapeModule.Shape as unknown)) break;\n current = parent;\n }\n return chain;\n }\n\n const seen = new Set<string>([start.id]);\n let current: NodeShapeData | undefined = start;\n while (current?.extends?.id) {\n const parentId = current.extends.id;\n if (seen.has(parentId)) break; // cycle guard — malformed data must not hang a read\n seen.add(parentId);\n const parent = shapes.get(parentId);\n if (!parent) {\n if (!warnedUnresolvedExtends.has(current.id)) {\n warnedUnresolvedExtends.add(current.id);\n console.warn(\n `[linked] Shape '${current.id}' extends '${parentId}', which is not registered. ` +\n `Inherited properties from it are unavailable. Register the parent shape first ` +\n `(import its module, or register its metadata before the child).`,\n );\n }\n break;\n }\n chain.push(parent);\n current = parent;\n }\n return chain;\n}\n\n/** Every shape that extends the given shape, transitively. Most specific last. */\nexport function getSubShapes(shape: ShapeLike): NodeShapeData[] {\n const start = toNodeShapeData(shape);\n if (!start) return [];\n const index = getChildIndex();\n const shapes = activeNodeShapes();\n const out: NodeShapeData[] = [];\n const seen = new Set<string>([start.id]);\n const queue = [start.id];\n while (queue.length) {\n const current = queue.shift()!;\n for (const childId of index.get(current) ?? []) {\n if (seen.has(childId)) continue;\n seen.add(childId);\n const child = shapes.get(childId);\n if (child) {\n out.push(child);\n queue.push(childId);\n }\n }\n }\n return out;\n}\n\n/** True when `a` extends `b` (strictly — a shape is not a sub-shape of itself). */\nexport function isSubShapeOf(a: ShapeLike, b: ShapeLike): boolean {\n const target = toNodeShapeData(b);\n if (!target) return false;\n return getSuperShapes(a).some((superShape) => superShape.id === target.id);\n}\n\n/**\n * The fields of a shape the targetClass lookups read. Both `NodeShapeData` and its wire\n * form satisfy it, so a caller holding a shape catalog never has to convert it first.\n */\ntype ShapeHeader = Pick<NodeShapeData, 'id' | 'targetClass' | 'extends'>;\n\n/**\n * Every shape `shape` extends, most specific first — resolving each parent in `local`\n * before the registry.\n *\n * `local` is a caller's own set of shapes (a project's catalog), which may hold shapes the\n * registry has never seen, or newer versions of ones it has. The catalog is the authority\n * for what it holds; once the chain leaves it, the registry knows the rest.\n */\nfunction superShapesWithin(\n shape: ShapeHeader,\n local?: ReadonlyMap<string, ShapeHeader>,\n): ShapeHeader[] {\n if (!local) return getSuperShapes(shape as NodeShapeData);\n const chain: ShapeHeader[] = [];\n const seen = new Set<string>([shape.id]);\n let current: ShapeHeader = shape;\n while (current.extends?.id) {\n const parentId = current.extends.id;\n if (seen.has(parentId)) break; // cycle guard — malformed data must not hang a read\n seen.add(parentId);\n const parent = local.get(parentId);\n if (!parent) {\n const registered = activeNodeShapes().get(parentId);\n if (registered) chain.push(registered, ...getSuperShapes(registered));\n break;\n }\n chain.push(parent);\n current = parent;\n }\n return chain;\n}\n\nfunction indexShapes<S extends ShapeHeader>(shapes: Iterable<S>): Map<string, S> {\n const index = new Map<string, S>();\n for (const shape of shapes) if (shape?.id) index.set(shape.id, shape);\n return index;\n}\n\nfunction targetClassIdWithin(\n shape: ShapeLike | NodeShapeWire | {id: string},\n local?: ReadonlyMap<string, ShapeHeader>,\n): string | undefined {\n if (!shape) return undefined;\n if (typeof shape === 'function') {\n // A class's static targetClass is inherited through the prototype chain for free.\n const asClass = shape as typeof Shape;\n if (asClass.targetClass?.id) return asClass.targetClass.id;\n if (!asClass.shape?.id) return undefined;\n shape = asClass.shape;\n }\n const id = typeof shape === 'string' ? shape : shape.id;\n if (!id) return undefined;\n const given = typeof shape === 'string' ? undefined : (shape as ShapeHeader);\n const shapes = activeNodeShapes();\n const own =\n given?.targetClass?.id ??\n local?.get(id)?.targetClass?.id ??\n getShapeClass(id)?.targetClass?.id ??\n shapes.get(id)?.targetClass?.id;\n if (own) return own;\n // A data-only shape's targetClass is not inherited for free, so walk `extends`.\n const start = local?.get(id) ?? (given?.extends ? given : shapes.get(id) ?? given);\n if (!start) return undefined;\n return superShapesWithin(start, local).find((s) => s.targetClass?.id)?.targetClass?.id;\n}\n\n/**\n * The class a shape's instances are typed with: its own `targetClass`, else the first one\n * found through what it extends. `undefined` when there is none anywhere in the chain.\n *\n * Accepts a shape IRI, a `{id}` reference, a shape's metadata (data or wire form) or a shape\n * class. Pass `shapes` to resolve the shape — and what it extends — in that set before the\n * registry; a project's catalog may hold shapes the registry does not.\n */\nexport function getTargetClassId(\n shape: ShapeLike | NodeShapeWire | {id: string},\n shapes?: Iterable<NodeShapeData | NodeShapeWire>,\n): string | undefined {\n return targetClassIdWithin(shape, shapes ? indexShapes(shapes) : undefined);\n}\n\n/**\n * The least specific candidates (the roots), by id. A candidate that extends another\n * candidate (directly or further up) is dropped: a relation to `Person` with `Person` and\n * `Employee extends Person` both targeting it means `Person` — a relation never upgrades\n * itself to a sub-shape; declare `sh:node` to ask for one. What remains are unrelated roots\n * the data does not choose between; they sort by id alone — never by depth or by\n * registration or catalog order — so the choice is stable and visibly arbitrary. If that\n * would drop every candidate (an `extends` cycle), all of them are kept, by id.\n */\nfunction leastSpecific<S extends ShapeHeader>(\n candidates: S[],\n local?: ReadonlyMap<string, ShapeHeader>,\n): S[] {\n const ids = new Set(candidates.map((c) => c.id));\n const byId = (a: S, b: S) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);\n const roots = candidates.filter(\n (candidate) => !superShapesWithin(candidate, local).some((parent) => ids.has(parent.id)),\n );\n // An `extends` cycle makes each member extend another, so the filter can leave nothing.\n // Malformed data must not turn a relation into \"no shape\" silently: keep every candidate\n // instead, by id, and let the caller's ambiguity handling (warn) apply.\n return (roots.length ? roots : [...candidates]).sort(byId);\n}\n\n/** targetClass IRI → registered shapes targeting it, ordered. Rebuilt when the registry changes. */\nconst targetClassIndex = new RegistryCache<string, NodeShapeData[]>((index) => {\n activeNodeShapes().forEach((shape) => {\n const classId = targetClassIdWithin(shape);\n if (!classId) return;\n const shapes = index.get(classId);\n if (shapes) shapes.push(shape);\n else index.set(classId, [shape]);\n });\n index.forEach((shapes, classId) => index.set(classId, leastSpecific(shapes)));\n});\n\nfunction getTargetClassIndex(): Map<string, NodeShapeData[]> {\n return targetClassIndex.get();\n}\n\n/**\n * The least specific shapes whose effective targetClass (own, or inherited through\n * `extends`) is exactly `classIri`, sorted by id. A matching shape that extends another\n * match is left out, so one entry means the class has one root shape and more than one\n * means unrelated roots compete for it. Sub-shapes are never chosen for a class alone.\n *\n * With no `shapes`, the candidates are the registered shapes. Pass `shapes` to choose among\n * that set only — the registry also holds compiled framework shapes, and a project's\n * `schema:Person` relation should resolve to the project's shape, not to one a framework\n * package happens to register for the same class. Inheritance is still resolved through\n * the registry when a candidate extends a shape outside the set.\n */\nexport function getShapesForTargetClass(classIri: string): NodeShapeData[];\nexport function getShapesForTargetClass<S extends NodeShapeData | NodeShapeWire>(\n classIri: string,\n shapes: Iterable<S>,\n): S[];\nexport function getShapesForTargetClass(\n classIri: string,\n shapes?: Iterable<NodeShapeData | NodeShapeWire>,\n): (NodeShapeData | NodeShapeWire)[] {\n if (!classIri) return [];\n if (!shapes) return [...(getTargetClassIndex().get(classIri) ?? [])];\n const local = indexShapes(shapes);\n const candidates = [...local.values()].filter(\n (shape) => targetClassIdWithin(shape, local) === classIri,\n );\n return leastSpecific(candidates, local);\n}\n\nexport function addNodeShapeToShapeClass(\n nodeShape: NodeShapeData,\n shapeClass: typeof Shape,\n) {\n assertNoActiveCatalog();\n if (!nodeShape?.id) {\n return;\n }\n // Dev guardrail for IDENTITY duplication. Shape URIs embed `constructor.name`\n // (getNodeShapeUri). If a bundler emits >1 copy of a framework package, the copies\n // are renamed `Person`→`Person2`/`3`, so a mangled URI registers alongside the clean\n // one — the exact failure that silently breaks cross-runtime shape lookup (`Person3`\n // on the FE ≠ `Person` on the backend). Warn ONCE per base so a build-config\n // regression (e.g. a dropped `optimizeDeps.exclude`) surfaces loudly instead of\n // no-op'ing a query at forward time.\n //\n // This used to be dev-only, on the reasoning that production is minified and\n // the check would false-fire. It does not: full minification renames a class\n // to something like `za`, so `base === id` and nothing fires. What DOES fire\n // is the case worth catching — a bundler appending a digit to disambiguate\n // `BackendAPIStore` from the ontology term of the same name, which is exactly\n // the collision that breaks shape lookup, and it only happens in a production\n // build. Suppressing the warning there hid it from the one place it occurs.\n {\n const id = nodeShape.id;\n const base = id.replace(/\\d+$/, '');\n const existing = nodeShapeToShapeClass.get(base);\n if (base !== id && existing && !warnedDuplicateBases.has(base)) {\n // A real duplicate is the SAME logical shape (same targetClass) registered under\n // a mangled name; a legit digit-suffixed sibling (e.g. `OAuth2` vs `OAuth`)\n // targets a different class. Warn only when they match (or targetClass is absent).\n const newTarget = (shapeClass as any).targetClass?.id;\n const existingTarget = (existing as any).targetClass?.id;\n if (!newTarget || !existingTarget || newTarget === existingTarget) {\n warnedDuplicateBases.add(base);\n console.warn(\n `[linked] Shape identity duplication: '${id}' registered alongside '${base}'. ` +\n `A bundler emitted >1 copy of this package — cross-runtime shape lookup will ` +\n `break. Check the cli vite-config single-instance levers (optimizeDeps.exclude ` +\n `/ ssr.noExternal).`,\n );\n }\n }\n }\n nodeShapeToShapeClass.set(nodeShape.id, shapeClass);\n // The class-backed shape goes into the primary registry too, so metadata consumers\n // see one map regardless of how a shape was declared. This also bumps the version,\n // which invalidates every derived cache immediately rather than on a next-tick timer.\n registerNodeShape(nodeShape);\n}\n\n/**\n * The constructor for a shape IRI — an authored class if there is one, otherwise one\n * derived from the registered metadata.\n *\n * This is what the query layer wants in every case, and `getShapeClass` alone is not:\n * it answers `undefined` for a shape that exists only as data, which is every shape\n * authored in a project. Five call sites used to spell this fallback out by hand, in\n * four different ways.\n *\n * `getShapeClass` is NOT consulted first. `getOrCreateShapeAdapter` already returns the\n * authored class when one exists, and a class-backed shape is always mirrored into the\n * primary registry, so the adapter path cannot miss a shape `getShapeClass` would find.\n */\nexport function resolveShapeConstructor(\n nodeShape: NodeReferenceValue | {id: string} | string,\n): ShapeConstructor | undefined {\n const id = typeof nodeShape === 'string' ? nodeShape : nodeShape?.id;\n if (!id) return undefined;\n // SAFETY: both paths yield a concrete subclass of Shape with a static .shape —\n // i.e. a ShapeConstructor. Same cast getShapeClass documents.\n return getOrCreateShapeAdapter(id) as unknown as ShapeConstructor | undefined;\n}\n\n/**\n * The constructor the query layer resolves an IRI to. In the global registry it is\n * `getShapeClass` (authored classes only, as always). Inside a catalog, where every shape\n * but core's built-ins is data, it is the catalog's constructor for any shape it holds.\n * @internal\n */\nexport function getQueryShapeClass(\n nodeShape: NodeReferenceValue | {id: string} | string,\n): ShapeConstructor | undefined {\n return registryState.activeCatalog === undefined\n ? getShapeClass(nodeShape)\n : resolveShapeConstructor(nodeShape);\n}\n\nexport function getShapeClass(\n nodeShape: NodeReferenceValue | {id: string} | string,\n): ShapeConstructor | undefined {\n const id = typeof nodeShape === 'string' ? nodeShape : nodeShape?.id;\n if (!id) {\n return undefined;\n }\n // SAFETY: The map stores `typeof Shape` (abstract), but registered shapes are always\n // concrete subclasses with a constructor and static .shape — i.e. ShapeConstructor.\n return activeShapeClasses().get(id) as unknown as ShapeConstructor | undefined;\n}\n\n/** The class registered globally for an IRI, whatever catalog is active. @internal */\nexport function getRegisteredShapeClass(id: string): typeof Shape | undefined {\n return nodeShapeToShapeClass.get(id);\n}\n\n/**\n * Returns all registered shape classes (keyed by NodeShape URI). Inside a catalog scope:\n * core's built-in classes only — a catalog holds no other class.\n */\nexport function getAllShapeClasses(): Map<string, typeof Shape> {\n return activeShapeClasses() as Map<string, typeof Shape>;\n}\n\n/**\n * Returns all the sub shapes of the given shape\n * That is all the shapes that extend this shape\n * @param shape\n */\n\nexport function getSubShapesClasses(\n shape: typeof Shape | (typeof Shape)[],\n _internalKey?: string,\n): (typeof Shape)[] {\n let key = _internalKey || getKey(shape);\n const cache = subShapesCache.get();\n if (!cache.has(key)) {\n //apply the hasSuperclass function to the shape\n let filterFunction = applyFnToShapeOrArray(shape, hasSubClass);\n //filter and then sort the results based on their inheritance (most specific classes first, so we use hasSuperClass for the sorting)\n cache.set(\n key,\n filterShapeClasses(filterFunction).sort((a, b) => {\n return hasSubClass(a, b) ? 1 : -1;\n }),\n );\n }\n //return a copy of the array to prevent it from being modified\n return [...cache.get(key)!];\n}\n\n/**\n * Returns all the superclasses of the given shape\n * That is all the shapes that it extends.\n * Results are sorted from most specific to least specific\n * @param shape\n */\nexport function getSuperShapesClasses(\n shape: typeof Shape | (typeof Shape)[],\n): (typeof Shape)[] {\n //apply the hasSuperclass function to the shape\n let filterFunction = applyFnToShapeOrArray(shape, hasSuperClass);\n //filter and then sort the results based on their inheritance\n return filterShapeClasses(filterFunction).sort((a, b) => {\n return hasSubClass(a, b) ? 1 : -1;\n });\n}\n\nexport function getPropertyShapeByLabel(\n shapeClass: typeof Shape,\n label: string,\n): PropertyShapeData | undefined {\n if (!shapeClass.shape) return undefined;\n return getPropertyShape(shapeClass.shape, label, true);\n}\n\n/**\n * True when `a` extends `b`.\n *\n * Inheritance is read from `nodeShape.extends` (data), not from the JS prototype chain.\n * `applyLinkedShape` derives `extends` FROM the prototype chain, so for a class-backed\n * shape the two agree — but only the data form also works for a shape that has no\n * class, which is the whole point. The prototype comparison is kept as a fallback for\n * classes that are not registered as shapes at all (an abstract intermediate class).\n */\nexport function hasSuperClass(a: ShapeLike, b: ShapeLike) {\n if (!a || !b) return false;\n const aData = toNodeShapeData(a);\n const bData = toNodeShapeData(b);\n if (aData && bData) return isSubShapeOf(aData, bData);\n return typeof a === 'function' && typeof b === 'function'\n ? (a as Function).prototype instanceof (b as Function)\n : false;\n}\n\n/** True when `b` extends `a` — the mirror of {@link hasSuperClass}. */\nexport function hasSubClass(a: ShapeLike, b: ShapeLike) {\n return hasSuperClass(b, a);\n}\n\nfunction applyFnToShapeOrArray(shape, filterFn) {\n if (Array.isArray(shape)) {\n return (shapeClass) => {\n //returns true if one of the given shapes extends the shapeClass passed as argument\n return (shape as Function[]).some((s) => filterFn(s, shapeClass));\n };\n } else {\n //first argument will be the given shape class, second argument will be each stored shape class in the map\n //will filter down where the given shape extends the stored shape\n return filterFn.bind(null, shape);\n }\n}\n\nfunction filterShapeClasses(filterFn) {\n let result = [];\n activeShapeClasses().forEach((shapeClass) => {\n if (filterFn(shapeClass)) {\n result.push(shapeClass);\n }\n });\n return result;\n}\n\nexport function getLeastSpecificShapeClasses(shapes: ICoreIterable<Shape>) {\n let shapeClasses = shapes.map((shape) =>\n getQueryShapeClass(shape.nodeShape.id),\n );\n return filterShapesToLeastSpecific(shapeClasses);\n}\n\nexport function getMostSpecificSubShapes(\n shape: typeof Shape | (typeof Shape)[],\n): (typeof Shape)[] {\n if (!Array.isArray(shape)) {\n shape = [shape];\n }\n //get the subshapes of the given shapes\n let key = shape.map((s) => s.name).join(',');\n const cache = mostSpecificSubShapesCache.get();\n if (!cache.has(key)) {\n //get the subshapes of the given shapes\n let subShapes: (typeof Shape)[] = getSubShapesClasses(shape, key);\n //filter them down to the most specific ones (that are not extended by any other shape)\n cache.set(key, filterShapesToMostSpecific(subShapes));\n }\n return cache.get(key)!;\n}\n\n/**\n * Filters out all shapes that are extended by any other shape in the given set/array\n * @param subShapes\n */\nfunction filterShapesToMostSpecific(subShapes) {\n return subShapes.filter((subShape) => {\n return !subShapes.some((otherSubShape) => {\n return otherSubShape.prototype instanceof subShape;\n });\n });\n}\n\n/**\n * Filters out all shapes that extend any other shape in the given set/array\n * @param shapeClasses\n */\nfunction filterShapesToLeastSpecific(shapeClasses) {\n return shapeClasses.filter((shapeClass) => {\n return !shapeClasses.some((otherShapeClass) => {\n return (\n otherShapeClass !== shapeClass &&\n shapeClass.prototype instanceof otherShapeClass\n );\n });\n });\n}\n\nfunction getKey(shape: typeof Shape | (typeof Shape)[]) {\n return Array.isArray(shape)\n ? shape.map((s) => getShapeKey(s)).join(',')\n : getShapeKey(shape);\n}\n\nfunction getShapeKey(shape: typeof Shape) {\n //return a unique string for each shape\n return (\n resolveTargetClassId(shape.targetClass) ||\n shape.name + shape.prototype.constructor.toString().substring(0, 80)\n );\n}\n"]}
1
+ {"version":3,"file":"ShapeClass.js","sourceRoot":"","sources":["../../../src/utils/ShapeClass.ts"],"names":[],"mappings":";AACA,sFAAsF;AACtF,6FAA6F;AAC7F,sFAAsF;AACtF,wFAAwF;AACxF,OAAO,KAAK,WAAW,MAAM,oBAAoB,CAAC;AAClD,OAAO,EACL,gBAAgB,GAGjB,MAAM,4BAA4B,CAAC;AAKpC,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAC,aAAa,EAAC,CAAC;AAEvB,MAAM,oBAAoB,GAAG,CAC3B,WAAuC,EACxB,EAAE;;IACjB,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAC9B,OAAO,MAAA,WAAW,CAAC,EAAE,mCAAI,IAAI,CAAC;AAChC,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,mBAAmB,GACvB,OAAO,UAAU,KAAK,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAE,EAAU,CAAC;AAE/D;;;;;;;;GAQG;AACH,MAAM,SAAS,GAAW,EAAE,CAAC;AAC7B,MAAM,MAAM,GAAgB,OAAC,mBAAmB,CA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WAAW,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CACrE,CAAC;AACJ,CAAC","sourcesContent":["import {type Shape, type ShapeConstructor} from '../shapes/Shape.js';\n// Namespace import, read at CALL time rather than captured at module-evaluation time.\n// `getOrCreateShapeAdapter` subclasses `Shape` at runtime, and under some import orders this\n// module finishes evaluating before `Shape.js` does — a named import captured then is\n// permanently `undefined`, and the subclass fails with \"Class extends value undefined\".\nimport * as ShapeModule from '../shapes/Shape.js';\nimport {\n getPropertyShape,\n type NodeShapeData,\n type PropertyShapeData,\n} from '../shapes/nodeShapeData.js';\nimport type {NodeShapeWire} from '../shapes/nodeShapeWire.js';\nimport type {ICoreIterable} from '../interfaces/ICoreIterable.js';\nimport type {NodeReferenceValue} from './NodeReference.js';\nimport type {ShapeCatalog} from './ShapeCatalog.js';\nimport {RegistryCache} from './registryCache.js';\nimport {sharedState} from './sharedState.js';\nimport {isLinkedInstance} from './linkedError.js';\n\nexport {RegistryCache};\n\nconst resolveTargetClassId = (\n targetClass?: NodeReferenceValue | null,\n): string | null => {\n if (!targetClass) return null;\n return targetClass.id ?? null;\n};\n\n/**\n * The shape registries live on `globalThis`, not in module scope.\n *\n * A module can evaluate more than once in one process, and in a built app it does: an\n * app's backend is assembled from two graphs, one loaded by the bundler from `src/` and\n * one resolved by Node to `lib/esm/`. A module-scope `Map` then exists twice — shapes\n * register into one copy and every lookup reads the other, which finds nothing.\n *\n * The symptom never mentions module identity. It is `Invalid property key: projectSlug.\n * The shape Project does not have a registered property with this name` for a property\n * that is declared correctly two files away, because validation ran on the copy the\n * decorators never reached. See docs/reports/043-module-identity-in-the-backend.md.\n *\n * Sharing the state makes duplication harmless rather than merely absent: the graphs\n * still hold two copies of this module, but only one registry. `LinkedStorage` already\n * keeps its instance counter here; this keeps the data itself.\n */\nconst shapeRegistryGlobal: any =\n typeof globalThis !== 'undefined' ? globalThis : ({} as any);\n\n/**\n * Counts DISTINCT physical copies of this module, not evaluations of it.\n *\n * The difference matters. A bare `count++` here is incremented by Vite's HMR every time\n * the module is re-evaluated in the same process, against the same `globalThis` — so a\n * developer who edits a file a few times sees a count of 4 and goes hunting a\n * dual-resolution problem that does not exist. Recording a token per copy and counting\n * the tokens survives re-evaluation: HMR replaces the module, and its token with it.\n */\nconst copyToken: object = {};\nconst copies: Set<object> = (shapeRegistryGlobal.__linkedShapeRegistryCopies ??= new Set());\ncopies.add(copyToken);\n\n/**\n * More than one copy of this module means shapes register into one registry and are\n * looked up in another, and the resulting failures never mention module identity — they\n * say a declared property is not declared, or that a pinned shape has no pin.\n *\n * Reported rather than thrown. A throw from a library module at import time breaks\n * tooling that legitimately loads a module twice, and the shared state above means a\n * second copy is survivable: it is a correctness hazard for anything holding a class\n * reference, not an immediate failure. So this says so, once, as loudly as a log can.\n */\nif (copies.size > 1) {\n console.error(\n `[linked] ${copies.size} copies of @_linked/core's shape registry have loaded in ` +\n `this process. They share one registry, so lookups still resolve — but each copy ` +\n `has its own \\`Shape\\` base class, so \\`instanceof\\` comparisons across them are ` +\n `false and adapters built by one copy do not satisfy the other. This is a module ` +\n `resolution problem: part of the app is reaching this package by a path that ` +\n `resolves to its source and part by one that resolves to its build output.`,\n );\n}\n\n/**\n * One shared container, created by whichever copy evaluates first.\n *\n * `registryVersion` belongs here too: every derived cache in this module is keyed on it,\n * so a version that is not shared would let one copy's writes leave another copy's caches\n * looking valid. The caches themselves stay per-copy — they are rebuilt whenever the\n * shared version moves past them.\n */\nconst registryState: {\n nodeShapeToShapeClass: Map<string, typeof Shape>;\n nodeShapeRegistry: Map<string, NodeShapeData>;\n shapeAdapters: Map<string, typeof Shape>;\n registryVersion: number;\n /**\n * The catalog `withShapeCatalog` made current, or undefined for the global registry.\n * Shared like the rest, so a scope opened by one copy of this module is seen by another.\n */\n activeCatalog: ShapeCatalog | undefined;\n} = (shapeRegistryGlobal.__linkedShapeRegistry ??= {\n nodeShapeToShapeClass: new Map(),\n nodeShapeRegistry: new Map(),\n shapeAdapters: new Map(),\n registryVersion: 0,\n activeCatalog: undefined,\n});\n// A container created by an older copy has no slot yet; give it one so every read below\n// sees the same object layout.\nif (!('activeCatalog' in (registryState as object))) registryState.activeCatalog = undefined;\n\n/** How many distinct copies of this module are loaded. One is expected. */\nexport function getShapeRegistryInstanceCount(): number {\n return copies.size;\n}\n\n// ---------------------------------------------------------------------------\n// The active shape catalog\n// ---------------------------------------------------------------------------\n\n/**\n * Run `fn` with `catalog` as the shapes every registry accessor reads; `undefined` means\n * the global registry (explicitly — it does not inherit an outer catalog).\n *\n * Synchronous on purpose: it works the same in the browser and in Node, with no\n * AsyncLocalStorage. Scopes nest, the previous catalog is restored in `finally`, and fn's\n * value is returned unchanged. A promise returned by fn is not awaited, so its\n * continuation runs outside the scope. That is why builders and IRs capture their catalog\n * and every place that picks one up later re-enters it (see docs/architecture/runtime-instances.md).\n */\nexport function withShapeCatalog<T>(catalog: ShapeCatalog | undefined, fn: () => T): T {\n const previous = registryState.activeCatalog;\n if (previous === catalog) return fn();\n registryState.activeCatalog = catalog;\n try {\n const result = fn();\n if (result instanceof Promise) warnPromiseInScope();\n return result;\n } finally {\n registryState.activeCatalog = previous;\n }\n}\n\n/**\n * Run `fn` with no catalog active, without the promise warning: for core's own calls into a\n * dataset, whose asynchronous continuation is meant to run outside any catalog. @internal\n */\nexport function outsideShapeCatalog<T>(fn: () => T): T {\n const previous = registryState.activeCatalog;\n if (previous === undefined) return fn();\n registryState.activeCatalog = undefined;\n try {\n return fn();\n } finally {\n registryState.activeCatalog = previous;\n }\n}\n\nlet warnedPromiseInScope = false;\n\n/**\n * A scope ends when `fn` returns, so the continuation of a promise `fn` returns runs outside\n * it. Said once, outside production. A builder (a thenable, not a Promise) is the intended\n * return value: it captured the catalog and re-enters it.\n */\nfunction warnPromiseInScope(): void {\n if (warnedPromiseInScope) return;\n const env = (globalThis as {process?: {env?: Record<string, string | undefined>}}).process?.env;\n if (env?.NODE_ENV === 'production') return;\n warnedPromiseInScope = true;\n console.warn(\n '[linked] withShapeCatalog(catalog, fn): fn returned a promise. The scope ended when fn ' +\n 'returned, so code after its first await runs outside the catalog. Build the query inside ' +\n 'the scope and await it outside — a builder keeps its catalog.',\n );\n}\n\n/** The catalog of the current `withShapeCatalog` scope, or undefined for the global registry. */\nexport function getActiveShapeCatalog(): ShapeCatalog | undefined {\n return registryState.activeCatalog;\n}\n\n/**\n * The catalog a builder, a FieldSet or an IR captured — undefined means the global registry.\n * Reads the object's `catalog` field, which builders keep as a getter and IRs as a\n * non-enumerable property, so neither appears in `toJSON` or a JSON round trip.\n */\nexport function catalogOf(queryOrIr: object | null | undefined): ShapeCatalog | undefined {\n return (queryOrIr as {catalog?: ShapeCatalog} | null | undefined)?.catalog;\n}\n\n/**\n * Record `catalog` on an IR object as a non-enumerable `catalog` field, so the code that\n * compiles it later (often after an `await`) re-enters the catalog it was lowered in.\n * Nothing is written for the global registry: an IR without the field compiles globally.\n * @internal\n */\nexport function attachCatalog<T extends object>(\n ir: T,\n catalog: ShapeCatalog | undefined = registryState.activeCatalog,\n): T {\n if (catalog !== undefined) {\n Object.defineProperty(ir, 'catalog', {\n value: catalog,\n enumerable: false,\n configurable: true,\n writable: true,\n });\n }\n return ir;\n}\n\n/**\n * Process-unique ids for catalogs, for live-query template keys. On `globalThis`, like the\n * registry, so two copies of core give one catalog the same id.\n */\nconst keyState: {keys: WeakMap<object, number>; next: number} =\n (shapeRegistryGlobal.__linkedShapeCatalogKeys ??= {keys: new WeakMap(), next: 1});\n\n/** 0 for the global registry, else a process-unique id for the catalog. */\nexport function shapeCatalogKey(catalog: ShapeCatalog | undefined): number {\n if (catalog === undefined) return 0;\n let key = keyState.keys.get(catalog);\n if (key === undefined) {\n key = keyState.next++;\n keyState.keys.set(catalog, key);\n }\n return key;\n}\n\n/** The catalog of an adapter class a catalog built, keyed on the class. */\nconst adapterCatalogs = sharedState(\n '@_linked/core',\n 'ShapeClass.adapterCatalogs',\n () => new WeakMap<Function, ShapeCatalog>(),\n);\n\n/**\n * The catalog a builder made from `shape` captures.\n *\n * Inside a scope: the active catalog when the root is an IRI (`shape` undefined) or a\n * shape the catalog holds; otherwise none. A class the active catalog does not hold is\n * authored code (CN's own shapes, built by CN code while a project scope is active) and\n * must lower against the global registry. Outside a scope: the catalog that built the\n * adapter class, if it is one, else none.\n * @internal\n */\nexport function captureCatalog(\n shape?: {shape?: {id?: string}} | Function | null,\n): ShapeCatalog | undefined {\n const active = registryState.activeCatalog;\n if (shape === undefined || shape === null) return active;\n if (active !== undefined) {\n const id = (shape as {shape?: {id?: string}}).shape?.id;\n if (id && active.has(id)) return active;\n }\n return typeof shape === 'function' ? adapterCatalogs.get(shape) : undefined;\n}\n\n/**\n * Throw when a registry write is attempted inside a catalog scope. A catalog is\n * immutable, and a write meant for it would land in the global registry instead.\n * @internal\n */\nexport function assertNoActiveCatalog(): void {\n if (registryState.activeCatalog !== undefined) {\n throw new Error(\n 'Cannot register shapes while a ShapeCatalog is active. Register outside ' +\n 'withShapeCatalog, or build a new catalog with ShapeCatalog.from().',\n );\n }\n}\n\n/** What a catalog holds, as the accessors below read it. Plain fields: any copy can read them. */\ntype CatalogContents = {\n readonly nodeShapes: ReadonlyMap<string, NodeShapeData>;\n readonly shapeClasses: ReadonlyMap<string, typeof Shape>;\n};\n\nfunction contentsOf(catalog: ShapeCatalog): CatalogContents {\n return catalog as unknown as CatalogContents;\n}\n\nconst subShapesCache = new RegistryCache<string, (typeof Shape)[]>();\nconst mostSpecificSubShapesCache = new RegistryCache<string, (typeof Shape)[]>();\nconst nodeShapeToShapeClass = registryState.nodeShapeToShapeClass;\nconst warnedDuplicateBases = new Set<string>();\n\n/**\n * The PRIMARY shape registry: node-shape IRI → its metadata.\n *\n * Every shape is here — those declared by a `@linkedShape` class and those known only\n * as data (a project-authored shape read from the graph). `nodeShapeToShapeClass` above\n * is the SECONDARY registry, holding only the shapes that have a TypeScript class, and\n * exists for the few callers that genuinely need a class (a `ShapeProvider` lookup, a\n * typed accessor). Query lowering, predicate resolution and containment all read\n * metadata, so they use this map and work identically for both kinds of shape.\n */\nconst nodeShapeRegistry = registryState.nodeShapeRegistry;\n\n/**\n * The shapes the accessors read: the active catalog's (its shapes plus core's built-ins),\n * else the global registry. One shared read and a null check on the global path.\n */\nfunction activeNodeShapes(): ReadonlyMap<string, NodeShapeData> {\n const catalog = registryState.activeCatalog;\n return catalog === undefined ? nodeShapeRegistry : contentsOf(catalog).nodeShapes;\n}\n\n/** The authored classes the accessors read: the catalog's built-ins, else every registered class. */\nfunction activeShapeClasses(): ReadonlyMap<string, typeof Shape> {\n const catalog = registryState.activeCatalog;\n return catalog === undefined ? nodeShapeToShapeClass : contentsOf(catalog).shapeClasses;\n}\n\n/**\n * The current registration version — a monotonic counter, bumped on every write.\n *\n * Every derived cache in this module, and in `irToAlgebra`, is keyed on it. It replaces\n * two earlier invalidation strategies that were both unsound: a `setTimeout(…, 0)` cache\n * clear (which missed anything registered later in the same session) and comparing the\n * registry SIZE (which silently reuses a stale cache when a registration and a removal\n * coincide, or when a shape is re-registered in place).\n *\n * It lives on the shared state, not in module scope: a cache keyed on a per-copy version\n * would look valid after another copy had written.\n */\nexport function getRegistryVersion(): number {\n return registryState.registryVersion;\n}\n\n/** Reverse index parentIri → direct child IRIs, rebuilt when the registry changes. */\nconst childIndex = new RegistryCache<string, string[]>((index) => {\n activeNodeShapes().forEach((shape, id) => {\n const parent = shape.extends?.id;\n if (!parent) return;\n const siblings = index.get(parent);\n if (siblings) siblings.push(id);\n else index.set(parent, [id]);\n });\n});\n\nfunction getChildIndex(): Map<string, string[]> {\n return childIndex.get();\n}\n\n// Every derived cache is a RegistryCache keyed on this version, so bumping it is the\n// whole invalidation.\nfunction invalidateRegistryCaches() {\n registryState.registryVersion++;\n}\n\n/** Drop the adapter for a shape whose metadata was replaced. */\nfunction invalidateShapeAdapter(id: string) {\n shapeAdapters.delete(id);\n}\n\n/**\n * Register a shape known only as data — no TypeScript class is created.\n *\n * This is the return leg of the round trip: `@linkedShape` is class → metadata,\n * `syncShapes` is metadata → RDF, and this is RDF → metadata. Idempotent: re-registering\n * the same IRI replaces the metadata (a shape edited in the builder), which is why cache\n * invalidation cannot be keyed on registry size.\n */\nexport function registerNodeShape(nodeShape: NodeShapeData): void {\n assertNoActiveCatalog();\n if (!nodeShape?.id) return;\n nodeShapeRegistry.set(nodeShape.id, nodeShape);\n invalidateShapeAdapter(nodeShape.id);\n invalidateRegistryCaches();\n}\n\n/** The metadata for a node-shape IRI, whether or not it has a TypeScript class. */\nexport function getNodeShape(\n nodeShape: NodeReferenceValue | {id: string} | string,\n): NodeShapeData | undefined {\n const id = typeof nodeShape === 'string' ? nodeShape : nodeShape?.id;\n if (!id) return undefined;\n return activeNodeShapes().get(id);\n}\n\n/**\n * Every registered shape's metadata, keyed by node-shape IRI. Inside a catalog scope:\n * exactly the catalog's shapes plus core's built-ins.\n */\nexport function getAllNodeShapes(): ReadonlyMap<string, NodeShapeData> {\n return activeNodeShapes();\n}\n\n/**\n * Lazily-built constructors for shapes that exist only as data.\n *\n * The builder entry points (`QueryBuilder`, `CreateBuilder`, `UpdateBuilder`,\n * `DeleteBuilder` via `resolveShape`) take a `ShapeConstructor` and instantiate result\n * proxies from it, so they need *a* class. Rather than have every caller hand-roll one —\n * which is what `create-now-js`'s `registerRuntimeShape` used to do, losing `extends` and\n * every value constraint on the way — core derives one on demand from the registered\n * metadata and caches it.\n *\n * These adapters are deliberately NOT in `nodeShapeToShapeClass`: `getShapeClass` keeps\n * telling the truth about which shapes have a real, authored class. An adapter carries\n * the metadata verbatim, so nothing is lost, and inheritance is read from\n * `nodeShape.extends` (not from the adapter's prototype, which is always `Shape`).\n */\nconst shapeAdapters = registryState.shapeAdapters;\n\n/**\n * A constructor for a shape known only as data, created on first use.\n *\n * Returns undefined when the IRI is not registered at all. Prefer `getShapeClass` when\n * you specifically need an authored class; use this when you need *something*\n * constructor-shaped to drive the query builders.\n */\n/**\n * Adapters built inside a catalog: one map per catalog, keyed by IRI. Shared with\n * `adapterCatalogs` above, so an adapter one copy of core built keeps its catalog in another.\n */\nconst catalogAdapters = sharedState(\n '@_linked/core',\n 'ShapeClass.catalogAdapters',\n () => new WeakMap<object, Map<string, typeof Shape>>(),\n);\n\nexport function getOrCreateShapeAdapter(\n nodeShape: NodeShapeData | string,\n): typeof Shape | undefined {\n const catalog = registryState.activeCatalog;\n const shapes = catalog === undefined ? nodeShapeRegistry : contentsOf(catalog).nodeShapes;\n const data = typeof nodeShape === 'string' ? shapes.get(nodeShape) : nodeShape;\n if (!data?.id) return undefined;\n\n const authored = (\n catalog === undefined ? nodeShapeToShapeClass : contentsOf(catalog).shapeClasses\n ).get(data.id);\n if (authored) return authored;\n\n let adapters: Map<string, typeof Shape> | undefined = shapeAdapters;\n if (catalog !== undefined) {\n adapters = catalogAdapters.get(catalog);\n if (!adapters) catalogAdapters.set(catalog, (adapters = new Map()));\n }\n const cached = adapters.get(data.id);\n // Re-registering a shape replaces its metadata, so an adapter built from the old\n // object must not be reused.\n if (cached && cached.shape === data) return cached;\n\n class RuntimeShape extends ShapeModule.Shape {\n static shape = data as NodeShapeData;\n static targetClass = (data as NodeShapeData).targetClass ?? null;\n }\n Object.defineProperty(RuntimeShape, 'name', {\n value: (data as NodeShapeData).label || 'RuntimeShape',\n });\n adapters.set(data.id, RuntimeShape);\n if (catalog !== undefined) adapterCatalogs.set(RuntimeShape, catalog);\n return RuntimeShape;\n}\n\n/** Anything that can identify a shape: its metadata, its class, or its IRI. */\nexport type ShapeLike = NodeShapeData | typeof Shape | Function | string;\n\n/** Resolve a ShapeLike to node-shape metadata, or undefined if it isn't a shape. */\nfunction toNodeShapeData(shape: ShapeLike): NodeShapeData | undefined {\n if (!shape) return undefined;\n const shapes = activeNodeShapes();\n if (typeof shape === 'string') return shapes.get(shape);\n const asData = shape as NodeShapeData;\n // NodeShapeData is a plain object with an id; a Shape class is a function.\n if (typeof shape === 'object' && typeof asData.id === 'string') {\n return shapes.get(asData.id) ?? asData;\n }\n const asClass = shape as typeof Shape;\n const shapeData = asClass?.shape;\n if (shapeData?.id) return shapes.get(shapeData.id) ?? shapeData;\n return undefined;\n}\n\nconst warnedUnresolvedExtends = new Set<string>();\n\n/**\n * Every shape the given shape extends, most specific first.\n *\n * THE canonical inheritance walk — `getPropertyShapes(shape, true)` delegates to it, so\n * there is exactly one answer to \"what does this shape extend\". Two earlier walks\n * disagreed (one over the prototype chain, one over `extends`) and that divergence, not\n * either strategy, was the bug: `selectAll` listed labels from one and resolved them\n * through the other, so an inherited property became unresolvable and the query proxy\n * threw.\n *\n * Strategy is chosen by what is available:\n *\n * - **A class-backed shape walks its prototype chain.** This is authoritative and\n * includes the framework `Shape` root, whose own property shapes (`label`, `type`) are\n * genuinely inherited. `applyLinkedShape` deliberately does NOT record `extends` for\n * that root — it is not a domain shape and must not appear as an `extends` triple in\n * materialized SHACL — so the data alone cannot see it.\n * - **A shape known only as data walks `extends` through the registry.** This is what\n * makes inheritance work for a project-authored shape with no class, which the\n * prototype chain cannot express.\n *\n * `extends` is a REFERENCE, so a parent that was never registered ends the walk. The\n * prototype chain has no such failure mode, so it warns once per shape rather than\n * throwing — this runs on read paths.\n */\nexport function getSuperShapes(shape: ShapeLike): NodeShapeData[] {\n const start = toNodeShapeData(shape);\n const chain: NodeShapeData[] = [];\n if (!start) return chain;\n\n // Class-backed: the prototype chain is the authority.\n const shapes = activeNodeShapes();\n const startClass = activeShapeClasses().get(start.id);\n if (startClass) {\n let current: typeof Shape | undefined = startClass;\n while (current) {\n const parent = Object.getPrototypeOf(current) as typeof Shape | undefined;\n if (!parent?.shape) break;\n chain.push(parent.shape);\n if ((parent as unknown) === (ShapeModule.Shape as unknown)) break;\n current = parent;\n }\n return chain;\n }\n\n const seen = new Set<string>([start.id]);\n let current: NodeShapeData | undefined = start;\n while (current?.extends?.id) {\n const parentId = current.extends.id;\n if (seen.has(parentId)) break; // cycle guard — malformed data must not hang a read\n seen.add(parentId);\n const parent = shapes.get(parentId);\n if (!parent) {\n if (!warnedUnresolvedExtends.has(current.id)) {\n warnedUnresolvedExtends.add(current.id);\n console.warn(\n `[linked] Shape '${current.id}' extends '${parentId}', which is not registered. ` +\n `Inherited properties from it are unavailable. Register the parent shape first ` +\n `(import its module, or register its metadata before the child).`,\n );\n }\n break;\n }\n chain.push(parent);\n current = parent;\n }\n return chain;\n}\n\n/** Every shape that extends the given shape, transitively. Most specific last. */\nexport function getSubShapes(shape: ShapeLike): NodeShapeData[] {\n const start = toNodeShapeData(shape);\n if (!start) return [];\n const index = getChildIndex();\n const shapes = activeNodeShapes();\n const out: NodeShapeData[] = [];\n const seen = new Set<string>([start.id]);\n const queue = [start.id];\n while (queue.length) {\n const current = queue.shift()!;\n for (const childId of index.get(current) ?? []) {\n if (seen.has(childId)) continue;\n seen.add(childId);\n const child = shapes.get(childId);\n if (child) {\n out.push(child);\n queue.push(childId);\n }\n }\n }\n return out;\n}\n\n/** True when `a` extends `b` (strictly — a shape is not a sub-shape of itself). */\nexport function isSubShapeOf(a: ShapeLike, b: ShapeLike): boolean {\n const target = toNodeShapeData(b);\n if (!target) return false;\n return getSuperShapes(a).some((superShape) => superShape.id === target.id);\n}\n\n/**\n * The fields of a shape the targetClass lookups read. Both `NodeShapeData` and its wire\n * form satisfy it, so a caller holding a shape catalog never has to convert it first.\n */\ntype ShapeHeader = Pick<NodeShapeData, 'id' | 'targetClass' | 'extends'>;\n\n/**\n * Every shape `shape` extends, most specific first — resolving each parent in `local`\n * before the registry.\n *\n * `local` is a caller's own set of shapes (a project's catalog), which may hold shapes the\n * registry has never seen, or newer versions of ones it has. The catalog is the authority\n * for what it holds; once the chain leaves it, the registry knows the rest.\n */\nfunction superShapesWithin(\n shape: ShapeHeader,\n local?: ReadonlyMap<string, ShapeHeader>,\n): ShapeHeader[] {\n if (!local) return getSuperShapes(shape as NodeShapeData);\n const chain: ShapeHeader[] = [];\n const seen = new Set<string>([shape.id]);\n let current: ShapeHeader = shape;\n while (current.extends?.id) {\n const parentId = current.extends.id;\n if (seen.has(parentId)) break; // cycle guard — malformed data must not hang a read\n seen.add(parentId);\n const parent = local.get(parentId);\n if (!parent) {\n const registered = activeNodeShapes().get(parentId);\n if (registered) chain.push(registered, ...getSuperShapes(registered));\n break;\n }\n chain.push(parent);\n current = parent;\n }\n return chain;\n}\n\nfunction indexShapes<S extends ShapeHeader>(shapes: Iterable<S>): Map<string, S> {\n const index = new Map<string, S>();\n for (const shape of shapes) if (shape?.id) index.set(shape.id, shape);\n return index;\n}\n\nfunction targetClassIdWithin(\n shape: ShapeLike | NodeShapeWire | {id: string},\n local?: ReadonlyMap<string, ShapeHeader>,\n): string | undefined {\n if (!shape) return undefined;\n if (typeof shape === 'function') {\n // A class's static targetClass is inherited through the prototype chain for free.\n const asClass = shape as typeof Shape;\n if (asClass.targetClass?.id) return asClass.targetClass.id;\n if (!asClass.shape?.id) return undefined;\n shape = asClass.shape;\n }\n const id = typeof shape === 'string' ? shape : shape.id;\n if (!id) return undefined;\n const given = typeof shape === 'string' ? undefined : (shape as ShapeHeader);\n const shapes = activeNodeShapes();\n const own =\n given?.targetClass?.id ??\n local?.get(id)?.targetClass?.id ??\n getShapeClass(id)?.targetClass?.id ??\n shapes.get(id)?.targetClass?.id;\n if (own) return own;\n // A data-only shape's targetClass is not inherited for free, so walk `extends`.\n const start = local?.get(id) ?? (given?.extends ? given : shapes.get(id) ?? given);\n if (!start) return undefined;\n return superShapesWithin(start, local).find((s) => s.targetClass?.id)?.targetClass?.id;\n}\n\n/**\n * The class a shape's instances are typed with: its own `targetClass`, else the first one\n * found through what it extends. `undefined` when there is none anywhere in the chain.\n *\n * Accepts a shape IRI, a `{id}` reference, a shape's metadata (data or wire form) or a shape\n * class. Pass `shapes` to resolve the shape — and what it extends — in that set before the\n * registry; a project's catalog may hold shapes the registry does not.\n */\nexport function getTargetClassId(\n shape: ShapeLike | NodeShapeWire | {id: string},\n shapes?: Iterable<NodeShapeData | NodeShapeWire>,\n): string | undefined {\n return targetClassIdWithin(shape, shapes ? indexShapes(shapes) : undefined);\n}\n\n/**\n * The least specific candidates (the roots), by id. A candidate that extends another\n * candidate (directly or further up) is dropped: a relation to `Person` with `Person` and\n * `Employee extends Person` both targeting it means `Person` — a relation never upgrades\n * itself to a sub-shape; declare `sh:node` to ask for one. What remains are unrelated roots\n * the data does not choose between; they sort by id alone — never by depth or by\n * registration or catalog order — so the choice is stable and visibly arbitrary. If that\n * would drop every candidate (an `extends` cycle), all of them are kept, by id.\n */\nfunction leastSpecific<S extends ShapeHeader>(\n candidates: S[],\n local?: ReadonlyMap<string, ShapeHeader>,\n): S[] {\n const ids = new Set(candidates.map((c) => c.id));\n const byId = (a: S, b: S) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);\n const roots = candidates.filter(\n (candidate) => !superShapesWithin(candidate, local).some((parent) => ids.has(parent.id)),\n );\n // An `extends` cycle makes each member extend another, so the filter can leave nothing.\n // Malformed data must not turn a relation into \"no shape\" silently: keep every candidate\n // instead, by id, and let the caller's ambiguity handling (warn) apply.\n return (roots.length ? roots : [...candidates]).sort(byId);\n}\n\n/** targetClass IRI → registered shapes targeting it, ordered. Rebuilt when the registry changes. */\nconst targetClassIndex = new RegistryCache<string, NodeShapeData[]>((index) => {\n activeNodeShapes().forEach((shape) => {\n const classId = targetClassIdWithin(shape);\n if (!classId) return;\n const shapes = index.get(classId);\n if (shapes) shapes.push(shape);\n else index.set(classId, [shape]);\n });\n index.forEach((shapes, classId) => index.set(classId, leastSpecific(shapes)));\n});\n\nfunction getTargetClassIndex(): Map<string, NodeShapeData[]> {\n return targetClassIndex.get();\n}\n\n/**\n * The least specific shapes whose effective targetClass (own, or inherited through\n * `extends`) is exactly `classIri`, sorted by id. A matching shape that extends another\n * match is left out, so one entry means the class has one root shape and more than one\n * means unrelated roots compete for it. Sub-shapes are never chosen for a class alone.\n *\n * With no `shapes`, the candidates are the registered shapes. Pass `shapes` to choose among\n * that set only — the registry also holds compiled framework shapes, and a project's\n * `schema:Person` relation should resolve to the project's shape, not to one a framework\n * package happens to register for the same class. Inheritance is still resolved through\n * the registry when a candidate extends a shape outside the set.\n */\nexport function getShapesForTargetClass(classIri: string): NodeShapeData[];\nexport function getShapesForTargetClass<S extends NodeShapeData | NodeShapeWire>(\n classIri: string,\n shapes: Iterable<S>,\n): S[];\nexport function getShapesForTargetClass(\n classIri: string,\n shapes?: Iterable<NodeShapeData | NodeShapeWire>,\n): (NodeShapeData | NodeShapeWire)[] {\n if (!classIri) return [];\n if (!shapes) return [...(getTargetClassIndex().get(classIri) ?? [])];\n const local = indexShapes(shapes);\n const candidates = [...local.values()].filter(\n (shape) => targetClassIdWithin(shape, local) === classIri,\n );\n return leastSpecific(candidates, local);\n}\n\nexport function addNodeShapeToShapeClass(\n nodeShape: NodeShapeData,\n shapeClass: typeof Shape,\n) {\n assertNoActiveCatalog();\n if (!nodeShape?.id) {\n return;\n }\n // Dev guardrail for IDENTITY duplication. Shape URIs embed `constructor.name`\n // (getNodeShapeUri). If a bundler emits >1 copy of a framework package, the copies\n // are renamed `Person`→`Person2`/`3`, so a mangled URI registers alongside the clean\n // one — the exact failure that silently breaks cross-runtime shape lookup (`Person3`\n // on the FE ≠ `Person` on the backend). Warn ONCE per base so a build-config\n // regression (e.g. a dropped `optimizeDeps.exclude`) surfaces loudly instead of\n // no-op'ing a query at forward time.\n //\n // This used to be dev-only, on the reasoning that production is minified and\n // the check would false-fire. It does not: full minification renames a class\n // to something like `za`, so `base === id` and nothing fires. What DOES fire\n // is the case worth catching — a bundler appending a digit to disambiguate\n // `BackendAPIStore` from the ontology term of the same name, which is exactly\n // the collision that breaks shape lookup, and it only happens in a production\n // build. Suppressing the warning there hid it from the one place it occurs.\n {\n const id = nodeShape.id;\n const base = id.replace(/\\d+$/, '');\n const existing = nodeShapeToShapeClass.get(base);\n if (base !== id && existing && !warnedDuplicateBases.has(base)) {\n // A real duplicate is the SAME logical shape (same targetClass) registered under\n // a mangled name; a legit digit-suffixed sibling (e.g. `OAuth2` vs `OAuth`)\n // targets a different class. Warn only when they match (or targetClass is absent).\n const newTarget = (shapeClass as any).targetClass?.id;\n const existingTarget = (existing as any).targetClass?.id;\n if (!newTarget || !existingTarget || newTarget === existingTarget) {\n warnedDuplicateBases.add(base);\n console.warn(\n `[linked] Shape identity duplication: '${id}' registered alongside '${base}'. ` +\n `A bundler emitted >1 copy of this package — cross-runtime shape lookup will ` +\n `break. Check the cli vite-config single-instance levers (optimizeDeps.exclude ` +\n `/ ssr.noExternal).`,\n );\n }\n }\n }\n nodeShapeToShapeClass.set(nodeShape.id, shapeClass);\n // The class-backed shape goes into the primary registry too, so metadata consumers\n // see one map regardless of how a shape was declared. This also bumps the version,\n // which invalidates every derived cache immediately rather than on a next-tick timer.\n registerNodeShape(nodeShape);\n}\n\n/**\n * The constructor for a shape IRI — an authored class if there is one, otherwise one\n * derived from the registered metadata.\n *\n * This is what the query layer wants in every case, and `getShapeClass` alone is not:\n * it answers `undefined` for a shape that exists only as data, which is every shape\n * authored in a project. Five call sites used to spell this fallback out by hand, in\n * four different ways.\n *\n * `getShapeClass` is NOT consulted first. `getOrCreateShapeAdapter` already returns the\n * authored class when one exists, and a class-backed shape is always mirrored into the\n * primary registry, so the adapter path cannot miss a shape `getShapeClass` would find.\n */\nexport function resolveShapeConstructor(\n nodeShape: NodeReferenceValue | {id: string} | string,\n): ShapeConstructor | undefined {\n const id = typeof nodeShape === 'string' ? nodeShape : nodeShape?.id;\n if (!id) return undefined;\n // SAFETY: both paths yield a concrete subclass of Shape with a static .shape —\n // i.e. a ShapeConstructor. Same cast getShapeClass documents.\n return getOrCreateShapeAdapter(id) as unknown as ShapeConstructor | undefined;\n}\n\n/**\n * The constructor the query layer resolves an IRI to. In the global registry it is\n * `getShapeClass` (authored classes only, as always). Inside a catalog, where every shape\n * but core's built-ins is data, it is the catalog's constructor for any shape it holds.\n * @internal\n */\nexport function getQueryShapeClass(\n nodeShape: NodeReferenceValue | {id: string} | string,\n): ShapeConstructor | undefined {\n return registryState.activeCatalog === undefined\n ? getShapeClass(nodeShape)\n : resolveShapeConstructor(nodeShape);\n}\n\nexport function getShapeClass(\n nodeShape: NodeReferenceValue | {id: string} | string,\n): ShapeConstructor | undefined {\n const id = typeof nodeShape === 'string' ? nodeShape : nodeShape?.id;\n if (!id) {\n return undefined;\n }\n // SAFETY: The map stores `typeof Shape` (abstract), but registered shapes are always\n // concrete subclasses with a constructor and static .shape — i.e. ShapeConstructor.\n return activeShapeClasses().get(id) as unknown as ShapeConstructor | undefined;\n}\n\n/** The class registered globally for an IRI, whatever catalog is active. @internal */\nexport function getRegisteredShapeClass(id: string): typeof Shape | undefined {\n return nodeShapeToShapeClass.get(id);\n}\n\n/**\n * Returns all registered shape classes (keyed by NodeShape URI). Inside a catalog scope:\n * core's built-in classes only — a catalog holds no other class.\n */\nexport function getAllShapeClasses(): Map<string, typeof Shape> {\n return activeShapeClasses() as Map<string, typeof Shape>;\n}\n\n/**\n * Returns all the sub shapes of the given shape\n * That is all the shapes that extend this shape\n * @param shape\n */\n\nexport function getSubShapesClasses(\n shape: typeof Shape | (typeof Shape)[],\n _internalKey?: string,\n): (typeof Shape)[] {\n let key = _internalKey || getKey(shape);\n const cache = subShapesCache.get();\n if (!cache.has(key)) {\n //apply the hasSuperclass function to the shape\n let filterFunction = applyFnToShapeOrArray(shape, hasSubClass);\n //filter and then sort the results based on their inheritance (most specific classes first, so we use hasSuperClass for the sorting)\n cache.set(\n key,\n filterShapeClasses(filterFunction).sort((a, b) => {\n return hasSubClass(a, b) ? 1 : -1;\n }),\n );\n }\n //return a copy of the array to prevent it from being modified\n return [...cache.get(key)!];\n}\n\n/**\n * Returns all the superclasses of the given shape\n * That is all the shapes that it extends.\n * Results are sorted from most specific to least specific\n * @param shape\n */\nexport function getSuperShapesClasses(\n shape: typeof Shape | (typeof Shape)[],\n): (typeof Shape)[] {\n //apply the hasSuperclass function to the shape\n let filterFunction = applyFnToShapeOrArray(shape, hasSuperClass);\n //filter and then sort the results based on their inheritance\n return filterShapeClasses(filterFunction).sort((a, b) => {\n return hasSubClass(a, b) ? 1 : -1;\n });\n}\n\nexport function getPropertyShapeByLabel(\n shapeClass: typeof Shape,\n label: string,\n): PropertyShapeData | undefined {\n if (!shapeClass.shape) return undefined;\n return getPropertyShape(shapeClass.shape, label, true);\n}\n\n/**\n * True when `a` extends `b`.\n *\n * Inheritance is read from `nodeShape.extends` (data), not from the JS prototype chain.\n * `applyLinkedShape` derives `extends` FROM the prototype chain, so for a class-backed\n * shape the two agree — but only the data form also works for a shape that has no\n * class, which is the whole point. The prototype comparison is kept as a fallback for\n * classes that are not registered as shapes at all (an abstract intermediate class).\n */\nexport function hasSuperClass(a: ShapeLike, b: ShapeLike) {\n if (!a || !b) return false;\n const aData = toNodeShapeData(a);\n const bData = toNodeShapeData(b);\n if (aData && bData) return isSubShapeOf(aData, bData);\n return typeof a === 'function' && typeof b === 'function'\n ? isLinkedInstance((a as Function).prototype, b as Function)\n : false;\n}\n\n/** True when `b` extends `a` — the mirror of {@link hasSuperClass}. */\nexport function hasSubClass(a: ShapeLike, b: ShapeLike) {\n return hasSuperClass(b, a);\n}\n\nfunction applyFnToShapeOrArray(shape, filterFn) {\n if (Array.isArray(shape)) {\n return (shapeClass) => {\n //returns true if one of the given shapes extends the shapeClass passed as argument\n return (shape as Function[]).some((s) => filterFn(s, shapeClass));\n };\n } else {\n //first argument will be the given shape class, second argument will be each stored shape class in the map\n //will filter down where the given shape extends the stored shape\n return filterFn.bind(null, shape);\n }\n}\n\nfunction filterShapeClasses(filterFn) {\n let result = [];\n activeShapeClasses().forEach((shapeClass) => {\n if (filterFn(shapeClass)) {\n result.push(shapeClass);\n }\n });\n return result;\n}\n\nexport function getLeastSpecificShapeClasses(shapes: ICoreIterable<Shape>) {\n let shapeClasses = shapes.map((shape) =>\n getQueryShapeClass(shape.nodeShape.id),\n );\n return filterShapesToLeastSpecific(shapeClasses);\n}\n\nexport function getMostSpecificSubShapes(\n shape: typeof Shape | (typeof Shape)[],\n): (typeof Shape)[] {\n if (!Array.isArray(shape)) {\n shape = [shape];\n }\n //get the subshapes of the given shapes\n let key = shape.map((s) => s.name).join(',');\n const cache = mostSpecificSubShapesCache.get();\n if (!cache.has(key)) {\n //get the subshapes of the given shapes\n let subShapes: (typeof Shape)[] = getSubShapesClasses(shape, key);\n //filter them down to the most specific ones (that are not extended by any other shape)\n cache.set(key, filterShapesToMostSpecific(subShapes));\n }\n return cache.get(key)!;\n}\n\n/**\n * Filters out all shapes that are extended by any other shape in the given set/array\n * @param subShapes\n */\nfunction filterShapesToMostSpecific(subShapes) {\n return subShapes.filter((subShape) => {\n return !subShapes.some((otherSubShape) => {\n return isLinkedInstance(otherSubShape.prototype, subShape);\n });\n });\n}\n\n/**\n * Filters out all shapes that extend any other shape in the given set/array\n * @param shapeClasses\n */\nfunction filterShapesToLeastSpecific(shapeClasses) {\n return shapeClasses.filter((shapeClass) => {\n return !shapeClasses.some((otherShapeClass) => {\n return (\n otherShapeClass !== shapeClass &&\n isLinkedInstance(shapeClass.prototype, otherShapeClass)\n );\n });\n });\n}\n\nfunction getKey(shape: typeof Shape | (typeof Shape)[]) {\n return Array.isArray(shape)\n ? shape.map((s) => getShapeKey(s)).join(',')\n : getShapeKey(shape);\n}\n\nfunction getShapeKey(shape: typeof Shape) {\n //return a unique string for each shape\n return (\n resolveTargetClassId(shape.targetClass) ||\n shape.name + shape.prototype.constructor.toString().substring(0, 80)\n );\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { Shape } from '../shapes/Shape.js';
2
+ import { isLinkedInstance } from './linkedError.js';
2
3
  // Per-function caches. Keying by the function identity (WeakMap) instead of a
3
4
  // single global string map means two different functions with identical args no
4
5
  // longer collide, and a function's cache is reclaimed once the function itself
@@ -22,7 +23,7 @@ export function cached(fn, args, cacheTimeMs, alsoCacheErrors) {
22
23
  const now = Date.now();
23
24
  const keyArgs = args.map((a) => {
24
25
  var _a;
25
- if (a instanceof Shape) {
26
+ if (isLinkedInstance(a, Shape)) {
26
27
  return (_a = a.id) !== null && _a !== void 0 ? _a : a.uri;
27
28
  }
28
29
  else if (a && typeof a === 'object' && 'id' in a) {
@@ -1 +1 @@
1
- {"version":3,"file":"cached.js","sourceRoot":"","sources":["../../../src/utils/cached.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAIzC,8EAA8E;AAC9E,gFAAgF;AAChF,+EAA+E;AAC/E,qCAAqC;AACrC,MAAM,MAAM,GAAG,IAAI,OAAO,EAAsC,CAAC;AAEjE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,MAAM,CAAC,EAAa,EAAE,IAAW,EAAE,WAAoB,EAAC,eAAyB;IAC/F,IAAI,WAAW,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;;YAC7B,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,OAAO,MAAA,CAAC,CAAC,EAAE,mCAAI,CAAC,CAAC,GAAG,CAAC;YACvB,CAAC;iBAAM,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;gBACnD,OAAQ,CAAkB,CAAC,EAAE,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,QAAQ,EAAE,CAAC;YACvB,CAAC;QACH,CAAC,CAAC,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACpC,IAAI,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;YACxC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC1B,CAAC;QACD,IAAI,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC;YACjC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpB,KAAK,GAAG,SAAS,CAAC;QACpB,CAAC;QACD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,IAAI,CAAC;gBACH,KAAK,GAAG,EAAC,OAAO,EAAE,GAAG,GAAG,WAAW,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC;YACpE,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,eAAe,EAAE,CAAC;oBACpB,KAAK,GAAG,EAAC,OAAO,EAAE,GAAG,GAAG,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;gBAChE,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,IAAI,KAAK,CAAC,OAAO;YAAE,MAAM,KAAK,CAAC,KAAK,CAAC;QACrC,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import {Shape} from '../shapes/Shape.js';\n\ntype CacheEntry = {timeout: number; value: any; isError: boolean};\n\n// Per-function caches. Keying by the function identity (WeakMap) instead of a\n// single global string map means two different functions with identical args no\n// longer collide, and a function's cache is reclaimed once the function itself\n// is unreferenced (bounding growth).\nconst _cache = new WeakMap<() => any, Map<string, CacheEntry>>();\n\n/**\n * Caches the result of a function call based on its arguments for a specified time.\n * Arguments are converted to strings for comparison.\n * Use cacheTimeMs = 0 to disable caching.\n * Use cacheTimeMs = Infinity to never expire the cache.\n * When `alsoCacheErrors` is set, a thrown error is remembered for the window so\n * the function is not re-invoked — but it is re-thrown to the caller, never\n * returned as if it were a value.\n * @param fn\n * @param args\n * @param cacheTimeMs\n * @param alsoCacheErrors\n */\nexport function cached(fn: () => any, args: any[], cacheTimeMs?: number,alsoCacheErrors?: boolean) {\n if (cacheTimeMs !== 0) {\n const now = Date.now();\n const keyArgs = args.map((a) => {\n if (a instanceof Shape) {\n return a.id ?? a.uri;\n } else if (a && typeof a === 'object' && 'id' in a) {\n return (a as {id: string}).id;\n } else {\n return a?.toString();\n }\n });\n const key = JSON.stringify(keyArgs);\n let fnCache = _cache.get(fn);\n if (!fnCache) {\n fnCache = new Map<string, CacheEntry>();\n _cache.set(fn, fnCache);\n }\n let entry = fnCache.get(key);\n if (entry && entry.timeout < now) {\n fnCache.delete(key);\n entry = undefined;\n }\n if (!entry) {\n try {\n entry = {timeout: now + cacheTimeMs, value: fn(), isError: false};\n } catch (e) {\n if (alsoCacheErrors) {\n entry = {timeout: now + cacheTimeMs, value: e, isError: true};\n } else {\n throw e;\n }\n }\n fnCache.set(key, entry);\n }\n if (entry.isError) throw entry.value;\n return entry.value;\n } else {\n return fn();\n }\n}\n"]}
1
+ {"version":3,"file":"cached.js","sourceRoot":"","sources":["../../../src/utils/cached.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAIlD,8EAA8E;AAC9E,gFAAgF;AAChF,+EAA+E;AAC/E,qCAAqC;AACrC,MAAM,MAAM,GAAG,IAAI,OAAO,EAAsC,CAAC;AAEjE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,MAAM,CAAC,EAAa,EAAE,IAAW,EAAE,WAAoB,EAAC,eAAyB;IAC/F,IAAI,WAAW,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,C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ACpB,KAAK,GAAG,EAAC,OAAO,EAAE,GAAG,GAAG,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;gBAChE,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,IAAI,KAAK,CAAC,OAAO;YAAE,MAAM,KAAK,CAAC,KAAK,CAAC;QACrC,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import {Shape} from '../shapes/Shape.js';\nimport {isLinkedInstance} from './linkedError.js';\n\ntype CacheEntry = {timeout: number; value: any; isError: boolean};\n\n// Per-function caches. Keying by the function identity (WeakMap) instead of a\n// single global string map means two different functions with identical args no\n// longer collide, and a function's cache is reclaimed once the function itself\n// is unreferenced (bounding growth).\nconst _cache = new WeakMap<() => any, Map<string, CacheEntry>>();\n\n/**\n * Caches the result of a function call based on its arguments for a specified time.\n * Arguments are converted to strings for comparison.\n * Use cacheTimeMs = 0 to disable caching.\n * Use cacheTimeMs = Infinity to never expire the cache.\n * When `alsoCacheErrors` is set, a thrown error is remembered for the window so\n * the function is not re-invoked — but it is re-thrown to the caller, never\n * returned as if it were a value.\n * @param fn\n * @param args\n * @param cacheTimeMs\n * @param alsoCacheErrors\n */\nexport function cached(fn: () => any, args: any[], cacheTimeMs?: number,alsoCacheErrors?: boolean) {\n if (cacheTimeMs !== 0) {\n const now = Date.now();\n const keyArgs = args.map((a) => {\n if (isLinkedInstance(a, Shape)) {\n return a.id ?? a.uri;\n } else if (a && typeof a === 'object' && 'id' in a) {\n return (a as {id: string}).id;\n } else {\n return a?.toString();\n }\n });\n const key = JSON.stringify(keyArgs);\n let fnCache = _cache.get(fn);\n if (!fnCache) {\n fnCache = new Map<string, CacheEntry>();\n _cache.set(fn, fnCache);\n }\n let entry = fnCache.get(key);\n if (entry && entry.timeout < now) {\n fnCache.delete(key);\n entry = undefined;\n }\n if (!entry) {\n try {\n entry = {timeout: now + cacheTimeMs, value: fn(), isError: false};\n } catch (e) {\n if (alsoCacheErrors) {\n entry = {timeout: now + cacheTimeMs, value: e, isError: true};\n } else {\n throw e;\n }\n }\n fnCache.set(key, entry);\n }\n if (entry.isError) throw entry.value;\n return entry.value;\n } else {\n return fn();\n }\n}\n"]}
@@ -12,6 +12,13 @@
12
12
  * the same keys. See https://github.com/linked-fw/cli/blob/main/docs/architecture/shared-state-and-error-brands.md.
13
13
  */
14
14
  type ErrorClass = abstract new (...args: never[]) => Error;
15
+ /**
16
+ * Any class whose instances are `T`: abstract or not, whatever its constructor takes, and
17
+ * also one whose constructor is `private` (which no `new (...) => T` type accepts).
18
+ */
19
+ type AnyClass<T = unknown> = Function & {
20
+ prototype: T;
21
+ };
15
22
  /**
16
23
  * Brand an error class so {@link isLinkedError} matches its instances from any copy of the
17
24
  * defining module. Call it once, right after the class declaration.
@@ -22,6 +29,18 @@ type ErrorClass = abstract new (...args: never[]) => Error;
22
29
  * @returns The class, for `export const X = brandLinkedError(class X ..., pkg, 'X')` use.
23
30
  */
24
31
  export declare function brandLinkedError<C extends ErrorClass>(Cls: C, pkg: string, name: string): C;
32
+ /**
33
+ * Brand any class so {@link isLinkedInstance} matches its instances from any copy of the
34
+ * defining module: `brandLinkedError` for classes that are not errors. Call it once, right
35
+ * after the class declaration. The brand is the same `Symbol.for('<pkg>:<name>')` an error
36
+ * class gets, so a branded error is also matched by `isLinkedInstance`.
37
+ *
38
+ * @param Cls The class.
39
+ * @param pkg The defining package's npm name, e.g. `'@_linked/core'`.
40
+ * @param name The class name. Passed explicitly because a minifier may rename the class.
41
+ * @returns The class.
42
+ */
43
+ export declare function brandLinkedClass<C extends AnyClass<object>>(Cls: C, pkg: string, name: string): C;
25
44
  /**
26
45
  * `err instanceof Cls`, extended to instances of `Cls` from another copy of its module.
27
46
  *
@@ -30,6 +49,19 @@ export declare function brandLinkedError<C extends ErrorClass>(Cls: C, pkg: stri
30
49
  * every instance of the base.
31
50
  */
32
51
  export declare function isLinkedError<C extends ErrorClass>(err: unknown, Cls: C): err is InstanceType<C>;
52
+ /**
53
+ * `value instanceof Cls`, extended to instances of `Cls` from another copy of its module.
54
+ *
55
+ * Use it for a value another package (or another copy of this one) may have made: a
56
+ * `Shape`, `ShapeSet`, `QueryBuilder`, `PendingQueryContext`, `FieldSet`. It also answers
57
+ * `Sub.prototype instanceof Cls` when passed `Sub.prototype`.
58
+ *
59
+ * The brand is looked up on the value's prototype chain, never read off the value itself,
60
+ * so a proxy whose `get` trap guards unknown keys is not touched. Falls back to plain
61
+ * `instanceof` for a class that is not branded; a subclass that is not branded itself does
62
+ * not inherit its base's brand for this check.
63
+ */
64
+ export declare function isLinkedInstance<T>(value: unknown, Cls: AnyClass<T>): value is T;
33
65
  /** The brand symbol for a class: `Symbol.for('<pkg>:<name>')`. */
34
66
  export declare function linkedErrorBrand(pkg: string, name: string): symbol;
35
67
  export {};
@@ -23,9 +23,24 @@ const LINKED_ERROR_BRAND = Symbol.for('@_linked/core:errorBrand');
23
23
  * @returns The class, for `export const X = brandLinkedError(class X ..., pkg, 'X')` use.
24
24
  */
25
25
  export function brandLinkedError(Cls, pkg, name) {
26
+ return brandLinkedClass(Cls, pkg, name);
27
+ }
28
+ /**
29
+ * Brand any class so {@link isLinkedInstance} matches its instances from any copy of the
30
+ * defining module: `brandLinkedError` for classes that are not errors. Call it once, right
31
+ * after the class declaration. The brand is the same `Symbol.for('<pkg>:<name>')` an error
32
+ * class gets, so a branded error is also matched by `isLinkedInstance`.
33
+ *
34
+ * @param Cls The class.
35
+ * @param pkg The defining package's npm name, e.g. `'@_linked/core'`.
36
+ * @param name The class name. Passed explicitly because a minifier may rename the class.
37
+ * @returns The class.
38
+ */
39
+ export function brandLinkedClass(Cls, pkg, name) {
26
40
  const brand = linkedErrorBrand(pkg, name);
27
41
  Object.defineProperty(Cls, LINKED_ERROR_BRAND, { value: brand, configurable: true });
28
42
  Object.defineProperty(Cls.prototype, brand, { value: true, configurable: true });
43
+ brandsByPrototype = new WeakMap();
29
44
  return Cls;
30
45
  }
31
46
  /**
@@ -45,6 +60,54 @@ export function isLinkedError(err, Cls) {
45
60
  const brand = Cls[LINKED_ERROR_BRAND];
46
61
  return err[brand] === true;
47
62
  }
63
+ /**
64
+ * `value instanceof Cls`, extended to instances of `Cls` from another copy of its module.
65
+ *
66
+ * Use it for a value another package (or another copy of this one) may have made: a
67
+ * `Shape`, `ShapeSet`, `QueryBuilder`, `PendingQueryContext`, `FieldSet`. It also answers
68
+ * `Sub.prototype instanceof Cls` when passed `Sub.prototype`.
69
+ *
70
+ * The brand is looked up on the value's prototype chain, never read off the value itself,
71
+ * so a proxy whose `get` trap guards unknown keys is not touched. Falls back to plain
72
+ * `instanceof` for a class that is not branded; a subclass that is not branded itself does
73
+ * not inherit its base's brand for this check.
74
+ */
75
+ export function isLinkedInstance(value, Cls) {
76
+ if (value instanceof Cls)
77
+ return true;
78
+ if (value === null || (typeof value !== 'object' && typeof value !== 'function'))
79
+ return false;
80
+ if (!Object.prototype.hasOwnProperty.call(Cls, LINKED_ERROR_BRAND))
81
+ return false;
82
+ const brand = Cls[LINKED_ERROR_BRAND];
83
+ const proto = Object.getPrototypeOf(value);
84
+ return proto !== null && prototypeChainHasBrand(proto, brand);
85
+ }
86
+ /**
87
+ * Per prototype, whether its chain carries each brand asked about. Most checks are misses
88
+ * (`isLinkedInstance(x, PendingQueryContext)` on every value a builder sees), and walking the
89
+ * chain each time made query building measurably slower; with this a repeat check is one
90
+ * WeakMap and one Map lookup. A memo, so per copy of this module. Cleared whenever this copy
91
+ * brands a class, so a brand added after a lookup is never hidden by it.
92
+ */
93
+ let brandsByPrototype = new WeakMap();
94
+ function prototypeChainHasBrand(proto, brand) {
95
+ let known = brandsByPrototype.get(proto);
96
+ if (!known)
97
+ brandsByPrototype.set(proto, (known = new Map()));
98
+ let has = known.get(brand);
99
+ if (has === undefined) {
100
+ has = false;
101
+ for (let p = proto; p; p = Object.getPrototypeOf(p)) {
102
+ if (Object.prototype.hasOwnProperty.call(p, brand)) {
103
+ has = true;
104
+ break;
105
+ }
106
+ }
107
+ known.set(brand, has);
108
+ }
109
+ return has;
110
+ }
48
111
  /** The brand symbol for a class: `Symbol.for('<pkg>:<name>')`. */
49
112
  export function linkedErrorBrand(pkg, name) {
50
113
  return Symbol.for(`${pkg}:${name}`);
@@ -1 +1 @@
1
- {"version":3,"file":"linkedError.js","sourceRoot":"","sources":["../../../src/utils/linkedError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,6EAA6E;AAC7E,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAIlE;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAuB,GAAM,EAAE,GAAW,EAAE,IAAY;IACtF,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC1C,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAC,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAC,CAAC,CAAC;IACnF,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,EAAC,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAC,CAAC,CAAC;IAC/E,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAuB,GAAY,EAAE,GAAM;IACtE,IAAI,GAAG,YAAY,GAAG;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,UAAU,CAAC;QAAE,OAAO,KAAK,CAAC;IACzF,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,kBAAkB,CAAC;QAAE,OAAO,KAAK,CAAC;IACjF,MAAM,KAAK,GAAI,GAAyC,CAAC,kBAAkB,CAAC,CAAC;IAC7E,OAAQ,GAA+B,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;AAC1D,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,IAAY;IACxD,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/**\n * Error identity that survives a second copy of the module that defines the error.\n *\n * `err instanceof RemoteDatasetError` is false when the error was thrown by one copy of\n * `@_linked/server` and the class was imported from another: each copy has its own class.\n * A branded class instead carries a brand, `Symbol.for('<pkg>:<ClassName>')`, on its\n * prototype. Every copy of the class carries the same symbol, so {@link isLinkedError} can\n * recognise an error from any copy. The brand is read along the error's prototype chain, so a\n * subclass instance matches its base class, as with `instanceof`.\n *\n * The convention is the symbol keys, not this module: two copies of core brand and check\n * the same keys. See https://github.com/linked-fw/cli/blob/main/docs/architecture/shared-state-and-error-brands.md.\n */\n\n/** Static key on a branded class whose value is the class's brand symbol. */\nconst LINKED_ERROR_BRAND = Symbol.for('@_linked/core:errorBrand');\n\ntype ErrorClass = abstract new (...args: never[]) => Error;\n\n/**\n * Brand an error class so {@link isLinkedError} matches its instances from any copy of the\n * defining module. Call it once, right after the class declaration.\n *\n * @param Cls The error class.\n * @param pkg The defining package's npm name, e.g. `'@_linked/server'`.\n * @param name The class name. Passed explicitly because a minifier may rename the class.\n * @returns The class, for `export const X = brandLinkedError(class X ..., pkg, 'X')` use.\n */\nexport function brandLinkedError<C extends ErrorClass>(Cls: C, pkg: string, name: string): C {\n const brand = linkedErrorBrand(pkg, name);\n Object.defineProperty(Cls, LINKED_ERROR_BRAND, {value: brand, configurable: true});\n Object.defineProperty(Cls.prototype, brand, {value: true, configurable: true});\n return Cls;\n}\n\n/**\n * `err instanceof Cls`, extended to instances of `Cls` from another copy of its module.\n *\n * Falls back to plain `instanceof` for a class that is not branded. A subclass that is not\n * branded itself does not inherit its base's brand for this check: it would otherwise match\n * every instance of the base.\n */\nexport function isLinkedError<C extends ErrorClass>(err: unknown, Cls: C): err is InstanceType<C> {\n if (err instanceof Cls) return true;\n if (err === null || (typeof err !== 'object' && typeof err !== 'function')) return false;\n if (!Object.prototype.hasOwnProperty.call(Cls, LINKED_ERROR_BRAND)) return false;\n const brand = (Cls as unknown as Record<symbol, symbol>)[LINKED_ERROR_BRAND];\n return (err as Record<symbol, unknown>)[brand] === true;\n}\n\n/** The brand symbol for a class: `Symbol.for('<pkg>:<name>')`. */\nexport function linkedErrorBrand(pkg: string, name: string): symbol {\n return Symbol.for(`${pkg}:${name}`);\n}\n"]}
1
+ {"version":3,"file":"linkedError.js","sourceRoot":"","sources":["../../../src/utils/linkedError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,6EAA6E;AAC7E,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AASlE;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAuB,GAAM,EAAE,GAAW,EAAE,IAAY;IACtF,OAAO,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAA6B,GAAM,EAAE,GAAW,EAAE,IAAY;IAC5F,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC1C,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAC,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAC,CAAC,CAAC;IACnF,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK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CAAC;AAED;;;;;;GAMG;AACH,IAAI,iBAAiB,GAAG,IAAI,OAAO,EAAgC,CAAC;AAEpE,SAAS,sBAAsB,CAAC,KAAa,EAAE,KAAa;IAC1D,IAAI,KAAK,GAAG,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACzC,IAAI,CAAC,KAAK;QAAE,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;IAC9D,IAAI,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3B,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,GAAG,GAAG,KAAK,CAAC;QACZ,KAAK,IAAI,CAAC,GAAkB,KAAK,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;YACnE,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;gBACnD,GAAG,GAAG,IAAI,CAAC;gBACX,MAAM;YACR,CAAC;QACH,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,IAAY;IACxD,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/**\n * Error identity that survives a second copy of the module that defines the error.\n *\n * `err instanceof RemoteDatasetError` is false when the error was thrown by one copy of\n * `@_linked/server` and the class was imported from another: each copy has its own class.\n * A branded class instead carries a brand, `Symbol.for('<pkg>:<ClassName>')`, on its\n * prototype. Every copy of the class carries the same symbol, so {@link isLinkedError} can\n * recognise an error from any copy. The brand is read along the error's prototype chain, so a\n * subclass instance matches its base class, as with `instanceof`.\n *\n * The convention is the symbol keys, not this module: two copies of core brand and check\n * the same keys. See https://github.com/linked-fw/cli/blob/main/docs/architecture/shared-state-and-error-brands.md.\n */\n\n/** Static key on a branded class whose value is the class's brand symbol. */\nconst LINKED_ERROR_BRAND = Symbol.for('@_linked/core:errorBrand');\n\ntype ErrorClass = abstract new (...args: never[]) => Error;\n/**\n * Any class whose instances are `T`: abstract or not, whatever its constructor takes, and\n * also one whose constructor is `private` (which no `new (...) => T` type accepts).\n */\ntype AnyClass<T = unknown> = Function & {prototype: T};\n\n/**\n * Brand an error class so {@link isLinkedError} matches its instances from any copy of the\n * defining module. Call it once, right after the class declaration.\n *\n * @param Cls The error class.\n * @param pkg The defining package's npm name, e.g. `'@_linked/server'`.\n * @param name The class name. Passed explicitly because a minifier may rename the class.\n * @returns The class, for `export const X = brandLinkedError(class X ..., pkg, 'X')` use.\n */\nexport function brandLinkedError<C extends ErrorClass>(Cls: C, pkg: string, name: string): C {\n return brandLinkedClass(Cls, pkg, name);\n}\n\n/**\n * Brand any class so {@link isLinkedInstance} matches its instances from any copy of the\n * defining module: `brandLinkedError` for classes that are not errors. Call it once, right\n * after the class declaration. The brand is the same `Symbol.for('<pkg>:<name>')` an error\n * class gets, so a branded error is also matched by `isLinkedInstance`.\n *\n * @param Cls The class.\n * @param pkg The defining package's npm name, e.g. `'@_linked/core'`.\n * @param name The class name. Passed explicitly because a minifier may rename the class.\n * @returns The class.\n */\nexport function brandLinkedClass<C extends AnyClass<object>>(Cls: C, pkg: string, name: string): C {\n const brand = linkedErrorBrand(pkg, name);\n Object.defineProperty(Cls, LINKED_ERROR_BRAND, {value: brand, configurable: true});\n Object.defineProperty(Cls.prototype, brand, {value: true, configurable: true});\n brandsByPrototype = new WeakMap();\n return Cls;\n}\n\n/**\n * `err instanceof Cls`, extended to instances of `Cls` from another copy of its module.\n *\n * Falls back to plain `instanceof` for a class that is not branded. A subclass that is not\n * branded itself does not inherit its base's brand for this check: it would otherwise match\n * every instance of the base.\n */\nexport function isLinkedError<C extends ErrorClass>(err: unknown, Cls: C): err is InstanceType<C> {\n if (err instanceof Cls) return true;\n if (err === null || (typeof err !== 'object' && typeof err !== 'function')) return false;\n if (!Object.prototype.hasOwnProperty.call(Cls, LINKED_ERROR_BRAND)) return false;\n const brand = (Cls as unknown as Record<symbol, symbol>)[LINKED_ERROR_BRAND];\n return (err as Record<symbol, unknown>)[brand] === true;\n}\n\n/**\n * `value instanceof Cls`, extended to instances of `Cls` from another copy of its module.\n *\n * Use it for a value another package (or another copy of this one) may have made: a\n * `Shape`, `ShapeSet`, `QueryBuilder`, `PendingQueryContext`, `FieldSet`. It also answers\n * `Sub.prototype instanceof Cls` when passed `Sub.prototype`.\n *\n * The brand is looked up on the value's prototype chain, never read off the value itself,\n * so a proxy whose `get` trap guards unknown keys is not touched. Falls back to plain\n * `instanceof` for a class that is not branded; a subclass that is not branded itself does\n * not inherit its base's brand for this check.\n */\nexport function isLinkedInstance<T>(value: unknown, Cls: AnyClass<T>): value is T {\n if (value instanceof Cls) return true;\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) return false;\n if (!Object.prototype.hasOwnProperty.call(Cls, LINKED_ERROR_BRAND)) return false;\n const brand = (Cls as unknown as Record<symbol, symbol>)[LINKED_ERROR_BRAND];\n const proto = Object.getPrototypeOf(value);\n return proto !== null && prototypeChainHasBrand(proto, brand);\n}\n\n/**\n * Per prototype, whether its chain carries each brand asked about. Most checks are misses\n * (`isLinkedInstance(x, PendingQueryContext)` on every value a builder sees), and walking the\n * chain each time made query building measurably slower; with this a repeat check is one\n * WeakMap and one Map lookup. A memo, so per copy of this module. Cleared whenever this copy\n * brands a class, so a brand added after a lookup is never hidden by it.\n */\nlet brandsByPrototype = new WeakMap<object, Map<symbol, boolean>>();\n\nfunction prototypeChainHasBrand(proto: object, brand: symbol): boolean {\n let known = brandsByPrototype.get(proto);\n if (!known) brandsByPrototype.set(proto, (known = new Map()));\n let has = known.get(brand);\n if (has === undefined) {\n has = false;\n for (let p: object | null = proto; p; p = Object.getPrototypeOf(p)) {\n if (Object.prototype.hasOwnProperty.call(p, brand)) {\n has = true;\n break;\n }\n }\n known.set(brand, has);\n }\n return has;\n}\n\n/** The brand symbol for a class: `Symbol.for('<pkg>:<name>')`. */\nexport function linkedErrorBrand(pkg: string, name: string): symbol {\n return Symbol.for(`${pkg}:${name}`);\n}\n"]}
@@ -14,7 +14,9 @@ export interface UnresolvedShapeDetails {
14
14
  /**
15
15
  * The error core throws when a shape IRI does not resolve, carrying the IRIs as fields so a
16
16
  * host can map it without parsing the message. It stays a plain `Error` (`name` is
17
- * `'Error'`): only the message and the fields are added.
17
+ * `'Error'`): only the message and the fields are added. Match it with
18
+ * `isLinkedError(err, UnresolvedShapeError)`, which also recognises one thrown by another copy
19
+ * of core.
18
20
  */
19
21
  export declare class UnresolvedShapeError extends Error implements UnresolvedShapeDetails {
20
22
  readonly shapeIri: string;
@@ -1,8 +1,11 @@
1
1
  import { getActiveShapeCatalog } from './ShapeClass.js';
2
+ import { brandLinkedError } from './linkedError.js';
2
3
  /**
3
4
  * The error core throws when a shape IRI does not resolve, carrying the IRIs as fields so a
4
5
  * host can map it without parsing the message. It stays a plain `Error` (`name` is
5
- * `'Error'`): only the message and the fields are added.
6
+ * `'Error'`): only the message and the fields are added. Match it with
7
+ * `isLinkedError(err, UnresolvedShapeError)`, which also recognises one thrown by another copy
8
+ * of core.
6
9
  */
7
10
  export class UnresolvedShapeError extends Error {
8
11
  constructor(message, details) {
@@ -18,6 +21,7 @@ export class UnresolvedShapeError extends Error {
18
21
  this.catalog = details.catalog;
19
22
  }
20
23
  }
24
+ brandLinkedError(UnresolvedShapeError, '@_linked/core', 'UnresolvedShapeError');
21
25
  /**
22
26
  * The details for a property whose value shape does not resolve. The owner is the property's
23
27
  * `parentNodeShape`, or `owner` when the caller knows it better (a path walk).