@_linked/core 2.25.0 → 2.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { type Shape, type ShapeConstructor } from '../shapes/Shape.js';
2
2
  import { type NodeShapeData, type PropertyShapeData } from '../shapes/nodeShapeData.js';
3
+ import type { NodeShapeWire } from '../shapes/nodeShapeWire.js';
3
4
  import type { ICoreIterable } from '../interfaces/ICoreIterable.js';
4
5
  import type { NodeReferenceValue } from './NodeReference.js';
5
6
  /** How many distinct copies of this module are loaded. One is expected. */
@@ -72,6 +73,31 @@ export declare function getSuperShapes(shape: ShapeLike): NodeShapeData[];
72
73
  export declare function getSubShapes(shape: ShapeLike): NodeShapeData[];
73
74
  /** True when `a` extends `b` (strictly — a shape is not a sub-shape of itself). */
74
75
  export declare function isSubShapeOf(a: ShapeLike, b: ShapeLike): boolean;
76
+ /**
77
+ * The class a shape's instances are typed with: its own `targetClass`, else the first one
78
+ * found through what it extends. `undefined` when there is none anywhere in the chain.
79
+ *
80
+ * Accepts a shape IRI, a `{id}` reference, a shape's metadata (data or wire form) or a shape
81
+ * class. Pass `shapes` to resolve the shape — and what it extends — in that set before the
82
+ * registry; a project's catalog may hold shapes the registry does not.
83
+ */
84
+ export declare function getTargetClassId(shape: ShapeLike | NodeShapeWire | {
85
+ id: string;
86
+ }, shapes?: Iterable<NodeShapeData | NodeShapeWire>): string | undefined;
87
+ /**
88
+ * The least specific shapes whose effective targetClass (own, or inherited through
89
+ * `extends`) is exactly `classIri`, sorted by id. A matching shape that extends another
90
+ * match is left out, so one entry means the class has one root shape and more than one
91
+ * means unrelated roots compete for it. Sub-shapes are never chosen for a class alone.
92
+ *
93
+ * With no `shapes`, the candidates are the registered shapes. Pass `shapes` to choose among
94
+ * that set only — the registry also holds compiled framework shapes, and a project's
95
+ * `schema:Person` relation should resolve to the project's shape, not to one a framework
96
+ * package happens to register for the same class. Inheritance is still resolved through
97
+ * the registry when a candidate extends a shape outside the set.
98
+ */
99
+ export declare function getShapesForTargetClass(classIri: string): NodeShapeData[];
100
+ export declare function getShapesForTargetClass<S extends NodeShapeData | NodeShapeWire>(classIri: string, shapes: Iterable<S>): S[];
75
101
  export declare function addNodeShapeToShapeClass(nodeShape: NodeShapeData, shapeClass: typeof Shape): void;
76
102
  /**
77
103
  * The constructor for a shape IRI — an authored class if there is one, otherwise one
@@ -136,6 +136,7 @@ function invalidateRegistryCaches() {
136
136
  subShapesCache.clear();
137
137
  mostSpecificSubShapesCache.clear();
138
138
  childIndex = null;
139
+ targetClassIndex = null;
139
140
  }
140
141
  /** Drop the adapter for a shape whose metadata was replaced. */
141
142
  function invalidateShapeAdapter(id) {
@@ -332,6 +333,133 @@ export function isSubShapeOf(a, b) {
332
333
  return false;
333
334
  return getSuperShapes(a).some((superShape) => superShape.id === target.id);
334
335
  }
336
+ /**
337
+ * Every shape `shape` extends, most specific first — resolving each parent in `local`
338
+ * before the registry.
339
+ *
340
+ * `local` is a caller's own set of shapes (a project's catalog), which may hold shapes the
341
+ * registry has never seen, or newer versions of ones it has. The catalog is the authority
342
+ * for what it holds; once the chain leaves it, the registry knows the rest.
343
+ */
344
+ function superShapesWithin(shape, local) {
345
+ var _a;
346
+ if (!local)
347
+ return getSuperShapes(shape);
348
+ const chain = [];
349
+ const seen = new Set([shape.id]);
350
+ let current = shape;
351
+ while ((_a = current.extends) === null || _a === void 0 ? void 0 : _a.id) {
352
+ const parentId = current.extends.id;
353
+ if (seen.has(parentId))
354
+ break; // cycle guard — malformed data must not hang a read
355
+ seen.add(parentId);
356
+ const parent = local.get(parentId);
357
+ if (!parent) {
358
+ const registered = nodeShapeRegistry.get(parentId);
359
+ if (registered)
360
+ chain.push(registered, ...getSuperShapes(registered));
361
+ break;
362
+ }
363
+ chain.push(parent);
364
+ current = parent;
365
+ }
366
+ return chain;
367
+ }
368
+ function indexShapes(shapes) {
369
+ const index = new Map();
370
+ for (const shape of shapes)
371
+ if (shape === null || shape === void 0 ? void 0 : shape.id)
372
+ index.set(shape.id, shape);
373
+ return index;
374
+ }
375
+ function targetClassIdWithin(shape, local) {
376
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
377
+ if (!shape)
378
+ return undefined;
379
+ if (typeof shape === 'function') {
380
+ // A class's static targetClass is inherited through the prototype chain for free.
381
+ const asClass = shape;
382
+ if ((_a = asClass.targetClass) === null || _a === void 0 ? void 0 : _a.id)
383
+ return asClass.targetClass.id;
384
+ if (!((_b = asClass.shape) === null || _b === void 0 ? void 0 : _b.id))
385
+ return undefined;
386
+ shape = asClass.shape;
387
+ }
388
+ const id = typeof shape === 'string' ? shape : shape.id;
389
+ if (!id)
390
+ return undefined;
391
+ const given = typeof shape === 'string' ? undefined : shape;
392
+ const own = (_k = (_g = (_d = (_c = given === null || given === void 0 ? void 0 : given.targetClass) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : (_f = (_e = local === null || local === void 0 ? void 0 : local.get(id)) === null || _e === void 0 ? void 0 : _e.targetClass) === null || _f === void 0 ? void 0 : _f.id) !== null && _g !== void 0 ? _g : (_j = (_h = getShapeClass(id)) === null || _h === void 0 ? void 0 : _h.targetClass) === null || _j === void 0 ? void 0 : _j.id) !== null && _k !== void 0 ? _k : (_m = (_l = nodeShapeRegistry.get(id)) === null || _l === void 0 ? void 0 : _l.targetClass) === null || _m === void 0 ? void 0 : _m.id;
393
+ if (own)
394
+ return own;
395
+ // A data-only shape's targetClass is not inherited for free, so walk `extends`.
396
+ const start = (_o = local === null || local === void 0 ? void 0 : local.get(id)) !== null && _o !== void 0 ? _o : ((given === null || given === void 0 ? void 0 : given.extends) ? given : (_p = nodeShapeRegistry.get(id)) !== null && _p !== void 0 ? _p : given);
397
+ if (!start)
398
+ return undefined;
399
+ return (_r = (_q = superShapesWithin(start, local).find((s) => { var _a; return (_a = s.targetClass) === null || _a === void 0 ? void 0 : _a.id; })) === null || _q === void 0 ? void 0 : _q.targetClass) === null || _r === void 0 ? void 0 : _r.id;
400
+ }
401
+ /**
402
+ * The class a shape's instances are typed with: its own `targetClass`, else the first one
403
+ * found through what it extends. `undefined` when there is none anywhere in the chain.
404
+ *
405
+ * Accepts a shape IRI, a `{id}` reference, a shape's metadata (data or wire form) or a shape
406
+ * class. Pass `shapes` to resolve the shape — and what it extends — in that set before the
407
+ * registry; a project's catalog may hold shapes the registry does not.
408
+ */
409
+ export function getTargetClassId(shape, shapes) {
410
+ return targetClassIdWithin(shape, shapes ? indexShapes(shapes) : undefined);
411
+ }
412
+ /**
413
+ * The least specific candidates (the roots), by id. A candidate that extends another
414
+ * candidate (directly or further up) is dropped: a relation to `Person` with `Person` and
415
+ * `Employee extends Person` both targeting it means `Person` — a relation never upgrades
416
+ * itself to a sub-shape; declare `sh:node` to ask for one. What remains are unrelated roots
417
+ * the data does not choose between; they sort by id alone — never by depth or by
418
+ * registration or catalog order — so the choice is stable and visibly arbitrary. If that
419
+ * would drop every candidate (an `extends` cycle), all of them are kept, by id.
420
+ */
421
+ function leastSpecific(candidates, local) {
422
+ const ids = new Set(candidates.map((c) => c.id));
423
+ const byId = (a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
424
+ const roots = candidates.filter((candidate) => !superShapesWithin(candidate, local).some((parent) => ids.has(parent.id)));
425
+ // An `extends` cycle makes each member extend another, so the filter can leave nothing.
426
+ // Malformed data must not turn a relation into "no shape" silently: keep every candidate
427
+ // instead, by id, and let the caller's ambiguity handling (warn) apply.
428
+ return (roots.length ? roots : [...candidates]).sort(byId);
429
+ }
430
+ /** targetClass IRI → registered shapes targeting it, ordered. Rebuilt when the registry changes. */
431
+ let targetClassIndex = null;
432
+ let targetClassIndexVersion = -1;
433
+ function getTargetClassIndex() {
434
+ if (targetClassIndex && targetClassIndexVersion === registryState.registryVersion) {
435
+ return targetClassIndex;
436
+ }
437
+ const index = new Map();
438
+ nodeShapeRegistry.forEach((shape) => {
439
+ const classId = targetClassIdWithin(shape);
440
+ if (!classId)
441
+ return;
442
+ const shapes = index.get(classId);
443
+ if (shapes)
444
+ shapes.push(shape);
445
+ else
446
+ index.set(classId, [shape]);
447
+ });
448
+ index.forEach((shapes, classId) => index.set(classId, leastSpecific(shapes)));
449
+ targetClassIndex = index;
450
+ targetClassIndexVersion = registryState.registryVersion;
451
+ return index;
452
+ }
453
+ export function getShapesForTargetClass(classIri, shapes) {
454
+ var _a;
455
+ if (!classIri)
456
+ return [];
457
+ if (!shapes)
458
+ return [...((_a = getTargetClassIndex().get(classIri)) !== null && _a !== void 0 ? _a : [])];
459
+ const local = indexShapes(shapes);
460
+ const candidates = [...local.values()].filter((shape) => targetClassIdWithin(shape, local) === classIri);
461
+ return leastSpecific(candidates, local);
462
+ }
335
463
  export function addNodeShapeToShapeClass(nodeShape, shapeClass) {
336
464
  var _a, _b;
337
465
  if (!(nodeShape === null || nodeShape === void 0 ? void 0 : nodeShape.id)) {
@@ -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;AAIpC,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,O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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 {ICoreIterable} from '../interfaces/ICoreIterable.js';\nimport type {NodeReferenceValue} from './NodeReference.js';\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} = (shapeRegistryGlobal.__linkedShapeRegistry ??= {\n nodeShapeToShapeClass: new Map(),\n nodeShapeRegistry: new Map(),\n shapeAdapters: new Map(),\n registryVersion: 0,\n});\n\n/** How many distinct copies of this module are loaded. One is expected. */\nexport function getShapeRegistryInstanceCount(): number {\n return copies.size;\n}\n\nlet subShapesCache: Map<string, (typeof Shape)[]> = new Map();\nlet mostSpecificSubShapesCache: Map<string, (typeof Shape)[]> = new Map();\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/** Version the sub-shape caches above were filled at. */\nlet subShapesCacheVersion = -1;\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. */\nlet childIndex: Map<string, string[]> | null = null;\nlet childIndexVersion = -1;\n\nfunction getChildIndex(): Map<string, string[]> {\n if (childIndex && childIndexVersion === registryState.registryVersion) return childIndex;\n const index = new Map<string, string[]>();\n nodeShapeRegistry.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 childIndex = index;\n childIndexVersion = registryState.registryVersion;\n return index;\n}\n\nfunction invalidateRegistryCaches() {\n registryState.registryVersion++;\n subShapesCache.clear();\n mostSpecificSubShapesCache.clear();\n childIndex = null;\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 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 nodeShapeRegistry.get(id);\n}\n\n/** Every registered shape's metadata, keyed by node-shape IRI. */\nexport function getAllNodeShapes(): ReadonlyMap<string, NodeShapeData> {\n return nodeShapeRegistry;\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 */\nexport function getOrCreateShapeAdapter(\n nodeShape: NodeShapeData | string,\n): typeof Shape | undefined {\n const data =\n typeof nodeShape === 'string' ? nodeShapeRegistry.get(nodeShape) : nodeShape;\n if (!data?.id) return undefined;\n\n const authored = nodeShapeToShapeClass.get(data.id);\n if (authored) return authored;\n\n const cached = shapeAdapters.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 shapeAdapters.set(data.id, RuntimeShape);\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 if (typeof shape === 'string') return nodeShapeRegistry.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 nodeShapeRegistry.get(asData.id) ?? asData;\n }\n const asClass = shape as typeof Shape;\n const shapeData = asClass?.shape;\n if (shapeData?.id) return nodeShapeRegistry.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 startClass = nodeShapeToShapeClass.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 = nodeShapeRegistry.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 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 = nodeShapeRegistry.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\nexport function addNodeShapeToShapeClass(\n nodeShape: NodeShapeData,\n shapeClass: typeof Shape,\n) {\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\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 nodeShapeToShapeClass.get(id) as unknown as ShapeConstructor | undefined;\n}\n\n/**\n * Returns all registered shape classes (keyed by NodeShape URI).\n */\nexport function getAllShapeClasses(): Map<string, typeof Shape> {\n return nodeShapeToShapeClass;\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 if (subShapesCacheVersion !== registryState.registryVersion) {\n subShapesCache.clear();\n mostSpecificSubShapesCache.clear();\n subShapesCacheVersion = registryState.registryVersion;\n }\n if (!subShapesCache.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 subShapesCache.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 [...subShapesCache.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 nodeShapeToShapeClass.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 getShapeClass(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 if (subShapesCacheVersion !== registryState.registryVersion) {\n subShapesCache.clear();\n mostSpecificSubShapesCache.clear();\n subShapesCacheVersion = registryState.registryVersion;\n }\n if (!mostSpecificSubShapesCache.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 mostSpecificSubShapesCache.set(key, filterShapesToMostSpecific(subShapes));\n }\n return mostSpecificSubShapesCache.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,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,EAAE,EAAC,CAAC;AAC5F,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAEtB;;;;;;;;;GASG;AACH,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;IACpB,OAAO,CAAC,KAAK,CACX,YAAY,MAAM,CAAC,IAAI,2DAA2D;QAChF,kFAAk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5C,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';\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} = (shapeRegistryGlobal.__linkedShapeRegistry ??= {\n nodeShapeToShapeClass: new Map(),\n nodeShapeRegistry: new Map(),\n shapeAdapters: new Map(),\n registryVersion: 0,\n});\n\n/** How many distinct copies of this module are loaded. One is expected. */\nexport function getShapeRegistryInstanceCount(): number {\n return copies.size;\n}\n\nlet subShapesCache: Map<string, (typeof Shape)[]> = new Map();\nlet mostSpecificSubShapesCache: Map<string, (typeof Shape)[]> = new Map();\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/** Version the sub-shape caches above were filled at. */\nlet subShapesCacheVersion = -1;\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. */\nlet childIndex: Map<string, string[]> | null = null;\nlet childIndexVersion = -1;\n\nfunction getChildIndex(): Map<string, string[]> {\n if (childIndex && childIndexVersion === registryState.registryVersion) return childIndex;\n const index = new Map<string, string[]>();\n nodeShapeRegistry.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 childIndex = index;\n childIndexVersion = registryState.registryVersion;\n return index;\n}\n\nfunction invalidateRegistryCaches() {\n registryState.registryVersion++;\n subShapesCache.clear();\n mostSpecificSubShapesCache.clear();\n childIndex = null;\n targetClassIndex = null;\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 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 nodeShapeRegistry.get(id);\n}\n\n/** Every registered shape's metadata, keyed by node-shape IRI. */\nexport function getAllNodeShapes(): ReadonlyMap<string, NodeShapeData> {\n return nodeShapeRegistry;\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 */\nexport function getOrCreateShapeAdapter(\n nodeShape: NodeShapeData | string,\n): typeof Shape | undefined {\n const data =\n typeof nodeShape === 'string' ? nodeShapeRegistry.get(nodeShape) : nodeShape;\n if (!data?.id) return undefined;\n\n const authored = nodeShapeToShapeClass.get(data.id);\n if (authored) return authored;\n\n const cached = shapeAdapters.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 shapeAdapters.set(data.id, RuntimeShape);\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 if (typeof shape === 'string') return nodeShapeRegistry.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 nodeShapeRegistry.get(asData.id) ?? asData;\n }\n const asClass = shape as typeof Shape;\n const shapeData = asClass?.shape;\n if (shapeData?.id) return nodeShapeRegistry.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 startClass = nodeShapeToShapeClass.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 = nodeShapeRegistry.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 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 = nodeShapeRegistry.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 = nodeShapeRegistry.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 own =\n given?.targetClass?.id ??\n local?.get(id)?.targetClass?.id ??\n getShapeClass(id)?.targetClass?.id ??\n nodeShapeRegistry.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 : nodeShapeRegistry.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. */\nlet targetClassIndex: Map<string, NodeShapeData[]> | null = null;\nlet targetClassIndexVersion = -1;\n\nfunction getTargetClassIndex(): Map<string, NodeShapeData[]> {\n if (targetClassIndex && targetClassIndexVersion === registryState.registryVersion) {\n return targetClassIndex;\n }\n const index = new Map<string, NodeShapeData[]>();\n nodeShapeRegistry.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 targetClassIndex = index;\n targetClassIndexVersion = registryState.registryVersion;\n return index;\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 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\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 nodeShapeToShapeClass.get(id) as unknown as ShapeConstructor | undefined;\n}\n\n/**\n * Returns all registered shape classes (keyed by NodeShape URI).\n */\nexport function getAllShapeClasses(): Map<string, typeof Shape> {\n return nodeShapeToShapeClass;\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 if (subShapesCacheVersion !== registryState.registryVersion) {\n subShapesCache.clear();\n mostSpecificSubShapesCache.clear();\n subShapesCacheVersion = registryState.registryVersion;\n }\n if (!subShapesCache.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 subShapesCache.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 [...subShapesCache.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 nodeShapeToShapeClass.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 getShapeClass(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 if (subShapesCacheVersion !== registryState.registryVersion) {\n subShapesCache.clear();\n mostSpecificSubShapesCache.clear();\n subShapesCacheVersion = registryState.registryVersion;\n }\n if (!mostSpecificSubShapesCache.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 mostSpecificSubShapesCache.set(key, filterShapesToMostSpecific(subShapes));\n }\n return mostSpecificSubShapesCache.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"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@_linked/core",
3
- "version": "2.25.0",
4
- "packageManager": "npm@11.20.0",
3
+ "version": "2.26.0",
4
+ "packageManager": "npm@12.1.0",
5
5
  "license": "MIT",
6
6
  "linkedPackage": true,
7
7
  "type": "module",