@_linked/server 2.23.1 → 2.24.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.
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3
3
  "changelog": [
4
4
  "@changesets/changelog-github",
5
- { "repo": "linked-cm/server" }
5
+ { "repo": "linked-fw/server" }
6
6
  ],
7
7
  "commit": false,
8
8
  "fixed": [],
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @\_linked/server
2
2
 
3
+ ## 2.24.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#148](https://github.com/linked-fw/server/pull/148) [`f435d22`](https://github.com/linked-fw/server/commit/f435d2242e32f3e41df82fcecb8972f092ac768f) Thanks [@flyon](https://github.com/flyon)! - Remove the in-memory shape index and the endpoints that served it.
8
+
9
+ This release removes public API but is published as a minor version on purpose, because no linked package uses it any more. If you still do, see the migration notes below.
10
+
11
+ Removed:
12
+
13
+ - `indexShapesIntoMemory()` and the `@_linked/server/utils/Shapes` module. The module's re-exports of `ShapeDetails`, `PropertyDetails`, `getShapeIndex` and `getShapeFromIndex` go with it, and `@_linked/server-utils` 1.12.0 removes those too. The server no longer builds the index when it starts.
14
+ - `LincdServerBackendProvider.getShapes()`.
15
+ - `LincdAPI.get_all_shapes` (`GET /api/all-shapes`), `LincdAPI.get_shape_details` (`GET /api/shape-details`) and the `ShapeSummary` type.
16
+ - The `GET /api/:method` route, which served only those two endpoints. `LincdAPI` keeps its `POST /api/...` query routes.
17
+
18
+ **Behaviour change:** `LincdAPI` no longer answers unmatched `GET /api/*` requests. They now go to the app's own routes and, if none matches, to the SPA shell.
19
+
20
+ Why: shape metadata is stored as SHACL, and nothing reads the in-memory index any more. The index was also lossy: it stored complex property paths (sequences, alternatives, inverses) as an empty id.
21
+
22
+ Migration:
23
+
24
+ - Instead of calling `GET /api/all-shapes`, `GET /api/shape-details` or `getShapes()`, read shapes from your store, or from core's registry for compiled shapes (for example `getNodeShape(id)` from `@_linked/core/utils/ShapeClass`).
25
+ - Type shape metadata as `NodeShapeWire` / `PropertyShapeWire` from `@_linked/core/shapes/nodeShapeWire`.
26
+
27
+ Requires `@_linked/server-utils` ^1.12.0.
28
+
3
29
  ## 2.23.1
4
30
 
5
31
  ### Patch Changes
@@ -1,7 +1,6 @@
1
1
  import { BackendProvider } from '@_linked/server-utils/utils/BackendProvider';
2
2
  export default class LincdServerBackendProvider extends BackendProvider {
3
3
  setupBeforeControllers(): Promise<void>;
4
- getShapes(): Record<string, import("@_linked/server-utils/types/ShapeDetails.js").ShapeDetails>;
5
4
  selectQuery(json: any): Promise<unknown>;
6
5
  askQuery(json: any): Promise<boolean>;
7
6
  updateQuery(json: any): Promise<unknown>;
@@ -12,7 +12,6 @@ import { callable } from '@_linked/server-utils/utils/callable';
12
12
  import { LinkedFileStorage } from '@_linked/core/utils/LinkedFileStorage';
13
13
  import { LinkedStorage } from '@_linked/core/utils/LinkedStorage';
14
14
  import { LocalFileStore } from './shapes/filestores/LocalFileStore.js';
15
- import { getShapeIndex } from './utils/Shapes.js';
16
15
  import { authorizeGenericQuery, toQueryBuilder } from './utils/queryPlane.js';
17
16
  import path from 'path';
18
17
  import fs from 'fs/promises';
@@ -31,12 +30,6 @@ export default class LincdServerBackendProvider extends BackendProvider {
31
30
  });
32
31
  }
33
32
  }
34
- // Not callable over RPC: no client calls it. Clients read the same index
35
- // through LincdAPI's `/api/all-shapes` and `/api/shape-details`; backend code
36
- // can still reach it with a local `Server.call`.
37
- getShapes() {
38
- return getShapeIndex();
39
- }
40
33
  // ── BackendAPIStore query execution ──────────────────────────────────────
41
34
  //
42
35
  // These answer the frontend `BackendAPIStore`, which calls
@@ -1 +1 @@
1
- {"version":3,"file":"backend.js","sourceRoot":"","sources":["../../src/backend.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,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GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,qBAAqB,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;QAClE,OAAO,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;CACF;AAjCO;IADL,QAAQ,CAAC,QAAQ,CAAC;;;;6DAKlB;AAGK;IADL,QAAQ,CAAC,QAAQ,CAAC;;;;0DAKlB;AAGK;IADL,QAAQ,CAAC,QAAQ,CAAC;;;;6DAKlB;AAGK;IADL,QAAQ,CAAC,QAAQ,CAAC;;;;6DAKlB;AAGK;IADL,QAAQ,CAAC,QAAQ,CAAC;;;;6DAKlB","sourcesContent":["import { BackendProvider } from '@_linked/server-utils/utils/BackendProvider';\nimport { callable } from '@_linked/server-utils/utils/callable';\nimport { LinkedFileStorage } from '@_linked/core/utils/LinkedFileStorage';\nimport { LinkedStorage } from '@_linked/core/utils/LinkedStorage';\nimport { LocalFileStore } from './shapes/filestores/LocalFileStore.js';\nimport { getShapeIndex } from './utils/Shapes.js';\nimport { authorizeGenericQuery, toQueryBuilder } from './utils/queryPlane.js';\nimport path from 'path';\nimport fs from 'fs/promises';\n\nexport default class LincdServerBackendProvider extends BackendProvider {\n async setupBeforeControllers() {\n if (!LinkedFileStorage.getDefaultStore()) {\n LinkedFileStorage.setDefaultStore(\n new LocalFileStore(process.env.NODE_ENV + '-filestore')\n );\n }\n let fileSystemUploadPath = path.join('data', 'filestores');\n try {\n await fs.access(fileSystemUploadPath);\n } catch (err) {\n await fs.mkdir(path.join(fileSystemUploadPath, 'filestores'), {\n recursive: true,\n });\n }\n }\n\n // Not callable over RPC: no client calls it. Clients read the same index\n // through LincdAPI's `/api/all-shapes` and `/api/shape-details`; backend code\n // can still reach it with a local `Server.call`.\n getShapes() {\n return getShapeIndex();\n }\n\n // ── BackendAPIStore query execution ──────────────────────────────────────\n //\n // These answer the frontend `BackendAPIStore`, which calls\n // `Server.call(packageName, {method}, json)` — the PACKAGE form, so the request\n // arrives here on the generic provider rather than through Shape resolution.\n //\n // They used to live on `BackendAPIStoreProvider`, a `ShapeProvider`, whose methods\n // took the store as a first argument and never read it. Reaching that provider meant\n // the transport had to carry a `shapeURI` and an `instanceNode`, and the server had to\n // rebuild the store with `new (providerShapeClass)({id})` — instantiating a Shape only\n // to discard it. Addressing by package removes all of that.\n //\n // A query cannot cross the wire live (core 2.10.0 contract flip), so the client ships\n // `toJSON()` and `fromJSON()` rehydrates it here into a live, closed query.\n // `LinkedStorage` then routes it by the QUERY's shape — which is, and always was, what\n // decides the target dataset. The store instance never participated.\n\n //\n // Every query is checked first against the access rules of the stores it\n // maps to, declared in the app's storage config (`withAccess`; a store with\n // no rule requires a session): see utils/queryPlane. INTERIM model, to be\n // rethought. The store runs the builder that was checked. They are declared\n // 'public' because that check, not the RPC layer, decides whether a session\n // is required.\n\n @callable('public')\n async selectQuery(json: any) {\n const query = toQueryBuilder(json);\n await authorizeGenericQuery('select', json, query, 'selectQuery');\n return LinkedStorage.selectQuery(query);\n }\n\n @callable('public')\n async askQuery(json: any) {\n const query = toQueryBuilder(json);\n await authorizeGenericQuery('ask', json, query, 'askQuery');\n return LinkedStorage.askQuery(query);\n }\n\n @callable('public')\n async updateQuery(json: any) {\n const query = toQueryBuilder(json);\n await authorizeGenericQuery('update', json, query, 'updateQuery');\n return LinkedStorage.updateQuery(query);\n }\n\n @callable('public')\n async createQuery(json: any) {\n const query = toQueryBuilder(json);\n await authorizeGenericQuery('create', json, query, 'createQuery');\n return LinkedStorage.createQuery(query);\n }\n\n @callable('public')\n async deleteQuery(json: any) {\n const query = toQueryBuilder(json);\n await authorizeGenericQuery('delete', json, query, 'deleteQuery');\n return LinkedStorage.deleteQuery(query);\n }\n}\n"]}
1
+ {"version":3,"file":"backend.js","sourceRoot":"","sources":["../../src/backend.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,O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WAAW,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;CACF;AAjCO;IADL,QAAQ,CAAC,QAAQ,CAAC;;;;6DAKlB;AAGK;IADL,QAAQ,CAAC,QAAQ,CAAC;;;;0DAKlB;AAGK;IADL,QAAQ,CAAC,QAAQ,CAAC;;;;6DAKlB;AAGK;IADL,QAAQ,CAAC,QAAQ,CAAC;;;;6DAKlB;AAGK;IADL,QAAQ,CAAC,QAAQ,CAAC;;;;6DAKlB","sourcesContent":["import { BackendProvider } from '@_linked/server-utils/utils/BackendProvider';\nimport { callable } from '@_linked/server-utils/utils/callable';\nimport { LinkedFileStorage } from '@_linked/core/utils/LinkedFileStorage';\nimport { LinkedStorage } from '@_linked/core/utils/LinkedStorage';\nimport { LocalFileStore } from './shapes/filestores/LocalFileStore.js';\nimport { authorizeGenericQuery, toQueryBuilder } from './utils/queryPlane.js';\nimport path from 'path';\nimport fs from 'fs/promises';\n\nexport default class LincdServerBackendProvider extends BackendProvider {\n async setupBeforeControllers() {\n if (!LinkedFileStorage.getDefaultStore()) {\n LinkedFileStorage.setDefaultStore(\n new LocalFileStore(process.env.NODE_ENV + '-filestore')\n );\n }\n let fileSystemUploadPath = path.join('data', 'filestores');\n try {\n await fs.access(fileSystemUploadPath);\n } catch (err) {\n await fs.mkdir(path.join(fileSystemUploadPath, 'filestores'), {\n recursive: true,\n });\n }\n }\n\n // ── BackendAPIStore query execution ──────────────────────────────────────\n //\n // These answer the frontend `BackendAPIStore`, which calls\n // `Server.call(packageName, {method}, json)` — the PACKAGE form, so the request\n // arrives here on the generic provider rather than through Shape resolution.\n //\n // They used to live on `BackendAPIStoreProvider`, a `ShapeProvider`, whose methods\n // took the store as a first argument and never read it. Reaching that provider meant\n // the transport had to carry a `shapeURI` and an `instanceNode`, and the server had to\n // rebuild the store with `new (providerShapeClass)({id})` — instantiating a Shape only\n // to discard it. Addressing by package removes all of that.\n //\n // A query cannot cross the wire live (core 2.10.0 contract flip), so the client ships\n // `toJSON()` and `fromJSON()` rehydrates it here into a live, closed query.\n // `LinkedStorage` then routes it by the QUERY's shape — which is, and always was, what\n // decides the target dataset. The store instance never participated.\n\n //\n // Every query is checked first against the access rules of the stores it\n // maps to, declared in the app's storage config (`withAccess`; a store with\n // no rule requires a session): see utils/queryPlane. INTERIM model, to be\n // rethought. The store runs the builder that was checked. They are declared\n // 'public' because that check, not the RPC layer, decides whether a session\n // is required.\n\n @callable('public')\n async selectQuery(json: any) {\n const query = toQueryBuilder(json);\n await authorizeGenericQuery('select', json, query, 'selectQuery');\n return LinkedStorage.selectQuery(query);\n }\n\n @callable('public')\n async askQuery(json: any) {\n const query = toQueryBuilder(json);\n await authorizeGenericQuery('ask', json, query, 'askQuery');\n return LinkedStorage.askQuery(query);\n }\n\n @callable('public')\n async updateQuery(json: any) {\n const query = toQueryBuilder(json);\n await authorizeGenericQuery('update', json, query, 'updateQuery');\n return LinkedStorage.updateQuery(query);\n }\n\n @callable('public')\n async createQuery(json: any) {\n const query = toQueryBuilder(json);\n await authorizeGenericQuery('create', json, query, 'createQuery');\n return LinkedStorage.createQuery(query);\n }\n\n @callable('public')\n async deleteQuery(json: any) {\n const query = toQueryBuilder(json);\n await authorizeGenericQuery('delete', json, query, 'deleteQuery');\n return LinkedStorage.deleteQuery(query);\n }\n}\n"]}
@@ -1,27 +1,7 @@
1
1
  import { Shape } from '@_linked/core/shapes/Shape';
2
- import { ShapeDetails } from '../utils/Shapes.js';
3
- export type ShapeSummary = {
4
- id: string;
5
- label: string;
6
- description: string;
7
- target: {
8
- id: string;
9
- };
10
- extends?: {
11
- id: string;
12
- };
13
- numInstances: number;
14
- };
15
2
  export declare class LincdAPI extends Shape {
16
3
  static targetClass: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
17
4
  process(request: any, response: any, httpMethod: 'get' | 'post' | 'put' | 'delete'): Promise<void>;
18
- get_shape_details({ shapes, }: {
19
- shapes: string[];
20
- }): Record<string, ShapeDetails>;
21
- get_all_shapes(): Promise<{
22
- shapes: Record<string, ShapeDetails>;
23
- defaultGraph: string;
24
- }>;
25
5
  post_select({ query }: {
26
6
  query: any;
27
7
  }): Promise<unknown>;
@@ -10,8 +10,6 @@ import { server } from '../ontologies/server.js';
10
10
  import { JSONParser } from '@_linked/server-utils/utils/JSONParser';
11
11
  import { LinkedStorage } from '@_linked/core/utils/LinkedStorage';
12
12
  import { JSONWriter } from '@_linked/server-utils/utils/JSONWriter';
13
- import { cached } from '@_linked/core/utils/cached';
14
- import { getShapeIndex } from '../utils/Shapes.js';
15
13
  import { authorizeGenericQuery, authorizeRawQuery, toQueryBuilder, } from '../utils/queryPlane.js';
16
14
  import { getRpcExposureMode } from '../utils/rpcExposure.js';
17
15
  /** An error carrying an HTTP status, such as a `ServerCallError` (401/403). */
@@ -22,7 +20,6 @@ function isStatusError(error) {
22
20
  error.status < 600 &&
23
21
  error.name === 'ServerCallError');
24
22
  }
25
- const cacheTime = process.env.NODE_ENV === 'development' ? 0 : Infinity;
26
23
  // Named explicitly: tsc emits `let X = class X`, and any later esbuild pass over that JS (Vite's
27
24
  // SSR `define` replacement runs one on every file mentioning a defined `process.env.*`) renames
28
25
  // the inner binding to `X2`, which would otherwise become this shape's IRI.
@@ -38,8 +35,7 @@ let LincdAPI = class LincdAPI extends Shape {
38
35
  throw new Error('Unknown method: ' + localMethod);
39
36
  }
40
37
  // The query routes (`post_*`) check access themselves, through
41
- // utils/queryPlane. The `get_*` routes describe shapes and stay reachable:
42
- // apps read each other's `/api/all-shapes` server to server.
38
+ // utils/queryPlane.
43
39
  try {
44
40
  const result = await this[localMethod](body, request, response);
45
41
  if (typeof result !== 'undefined' || !response.headersSent) {
@@ -59,51 +55,6 @@ let LincdAPI = class LincdAPI extends Shape {
59
55
  }
60
56
  }
61
57
  }
62
- get_shape_details({ shapes, }) {
63
- return cached(() => {
64
- const shapeIndex = getShapeIndex();
65
- const filteredShapeIndex = {};
66
- for (const shapeId of shapes) {
67
- if (shapeIndex[shapeId]) {
68
- filteredShapeIndex[shapeId] = shapeIndex[shapeId];
69
- }
70
- }
71
- return filteredShapeIndex;
72
- }, [shapes], cacheTime);
73
- }
74
- get_all_shapes() {
75
- return cached(async () => {
76
- var _a;
77
- const shapeIndex = getShapeIndex();
78
- const typesWithInstances = new Map();
79
- this.checkRawQuerySupport();
80
- await LinkedStorage.getDefaultDataset()
81
- .rawQuery(`SELECT (COUNT(?s) AS ?count) ?type WHERE { ?s a ?type } GROUP BY ?type`)
82
- .then((results) => {
83
- // rawQuery also types ASK results (a boolean envelope); this is a SELECT.
84
- if (!results || !('results' in results))
85
- return;
86
- results.results.bindings.forEach((binding) => {
87
- if (binding.type && binding.type.value) {
88
- typesWithInstances.set(binding.type.value, parseInt(binding.count.value));
89
- }
90
- });
91
- })
92
- .catch(console.error);
93
- const shapesWithInstances = {};
94
- for (const shapeId in shapeIndex) {
95
- const shape = shapeIndex[shapeId];
96
- shapesWithInstances[shapeId] = {
97
- ...shape,
98
- numInstances: typesWithInstances.get((_a = shape.targetClass) === null || _a === void 0 ? void 0 : _a.id) || 0,
99
- };
100
- }
101
- return {
102
- shapes: shapesWithInstances,
103
- defaultGraph: process.env.DATA_ROOT,
104
- };
105
- }, [], cacheTime);
106
- }
107
58
  async post_select({ query }) {
108
59
  const builder = toQueryBuilder(query);
109
60
  await authorizeGenericQuery('select', query, builder, 'api/select');
@@ -1 +1 @@
1
- {"version":3,"file":"LincdAPI.js","sourceRoot":"","sources":["../../../src/shapes/LincdAPI.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;A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,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QACpE,OAAO,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE;QAC7B,wEAAwE;QACxE,+DAA+D;QAC/D,MAAM,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;QACjD,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,OAAQ,aAAa,CAAC,iBAAiB,EAA6B,CAAC,QAAQ,CAC3E,KAAK,CACN,CAAC;IACJ,CAAC;IAEO,oBAAoB;QAC1B,IAAI,CAAE,aAAa,CAAC,iBAAiB,EAA6B,CAAC,QAAQ,EAAE,CAAC;YAC5E,MAAM,IAAI,KAAK,CACb,kBACE,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAC,WAAW;iBACjE,IACL,uCAAuC,CACxC,CAAC;QACJ,CAAC;IACH,CAAC;;AApJM,oBAAW,GAAG,MAAM,CAAC,QAAQ,AAAlB,CAAmB;AAD1B,QAAQ;IADpB,WAAW,CAAC,EAAC,IAAI,EAAE,UAAU,EAAC,CAAC;GACnB,QAAQ,CAsJpB","sourcesContent":["import { Shape } from '@_linked/core/shapes/Shape';\nimport { linkedShape } from '../package.js';\nimport { server } from '../ontologies/server.js';\nimport { JSONParser } from '@_linked/server-utils/utils/JSONParser';\nimport { LinkedStorage } from '@_linked/core/utils/LinkedStorage';\nimport { JSONWriter } from '@_linked/server-utils/utils/JSONWriter';\nimport { cached } from '@_linked/core/utils/cached';\nimport { getShapeIndex, ShapeDetails } from '../utils/Shapes.js';\nimport { SparqlDataset as SPARQLStore } from '@_linked/core/sparql/SparqlDataset';\nimport {\n authorizeGenericQuery,\n authorizeRawQuery,\n toQueryBuilder,\n} from '../utils/queryPlane.js';\nimport { getRpcExposureMode } from '../utils/rpcExposure.js';\n\n/** An error carrying an HTTP status, such as a `ServerCallError` (401/403). */\nfunction isStatusError(error: any): error is { status: number; message: string } {\n return (\n !!error &&\n typeof error.status === 'number' &&\n error.status >= 400 &&\n error.status < 600 &&\n error.name === 'ServerCallError'\n );\n}\n\nconst cacheTime = process.env.NODE_ENV === 'development' ? 0 : Infinity;\nexport type ShapeSummary = {\n id: string;\n label: string;\n description: string;\n target: { id: string };\n extends?: { id: string };\n numInstances: number;\n};\n// Named explicitly: tsc emits `let X = class X`, and any later esbuild pass over that JS (Vite's\n// SSR `define` replacement runs one on every file mentioning a defined `process.env.*`) renames\n// the inner binding to `X2`, which would otherwise become this shape's IRI.\n@linkedShape({name: 'LincdAPI'})\nexport class LincdAPI extends Shape {\n static targetClass = server.LincdAPI;\n\n async process(\n request,\n response,\n httpMethod: 'get' | 'post' | 'put' | 'delete'\n ) {\n let { method, action } = request.params;\n const body = JSONParser.parseObject<any>(request.body, {\n shapeClasses: getRpcExposureMode() === 'enforce' ? 'reject' : 'warn',\n });\n\n //replace - with _ in action names\n let localMethod = httpMethod + '_' + method.replace(/-/g, '_');\n if (typeof this[localMethod] !== 'function') {\n throw new Error('Unknown method: ' + localMethod);\n }\n\n // The query routes (`post_*`) check access themselves, through\n // utils/queryPlane. The `get_*` routes describe shapes and stay reachable:\n // apps read each other's `/api/all-shapes` server to server.\n try {\n const result = await this[localMethod](body, request, response);\n if (typeof result !== 'undefined' || !response.headersSent) {\n const jsonObject = JSONWriter.toJsObject(result);\n response.json(jsonObject);\n }\n } catch (error) {\n if (!response.headersSent && isStatusError(error)) {\n response.status(error.status).json({ error: error.message });\n return;\n }\n console.error(`Error while processing ${localMethod}:`, error);\n if (!response.headersSent) {\n const message =\n error instanceof Error ? error.message : 'Unknown server error';\n response.status(500).json({ error: message });\n }\n }\n }\n\n get_shape_details({\n shapes,\n }: {\n shapes: string[];\n }): Record<string, ShapeDetails> {\n return cached(\n () => {\n const shapeIndex = getShapeIndex();\n const filteredShapeIndex = {};\n for (const shapeId of shapes) {\n if (shapeIndex[shapeId]) {\n filteredShapeIndex[shapeId] = shapeIndex[shapeId];\n }\n }\n return filteredShapeIndex;\n },\n [shapes],\n cacheTime\n );\n }\n\n get_all_shapes(): Promise<{\n shapes: Record<string, ShapeDetails>;\n defaultGraph: string;\n }> {\n return cached(\n async () => {\n const shapeIndex = getShapeIndex();\n\n const typesWithInstances = new Map<string, number>();\n this.checkRawQuerySupport();\n await (LinkedStorage.getDefaultDataset() as unknown as SPARQLStore)\n .rawQuery(\n `SELECT (COUNT(?s) AS ?count) ?type WHERE { ?s a ?type } GROUP BY ?type`\n )\n .then((results) => {\n // rawQuery also types ASK results (a boolean envelope); this is a SELECT.\n if (!results || !('results' in results)) return;\n results.results.bindings.forEach((binding) => {\n if (binding.type && binding.type.value) {\n typesWithInstances.set(\n binding.type.value,\n parseInt(binding.count.value)\n );\n }\n });\n })\n .catch(console.error);\n\n const shapesWithInstances: Record<string, ShapeDetails> = {};\n for (const shapeId in shapeIndex) {\n const shape = shapeIndex[shapeId];\n shapesWithInstances[shapeId] = {\n ...shape,\n numInstances: typesWithInstances.get(shape.targetClass?.id) || 0,\n };\n }\n return {\n shapes: shapesWithInstances,\n defaultGraph: process.env.DATA_ROOT,\n };\n },\n [],\n cacheTime\n );\n }\n\n async post_select({ query }) {\n const builder = toQueryBuilder(query);\n await authorizeGenericQuery('select', query, builder, 'api/select');\n return LinkedStorage.selectQuery(builder);\n }\n async post_create({ query }) {\n const builder = toQueryBuilder(query);\n await authorizeGenericQuery('create', query, builder, 'api/create');\n return LinkedStorage.createQuery(builder);\n }\n async post_update({ query }) {\n const builder = toQueryBuilder(query);\n await authorizeGenericQuery('update', query, builder, 'api/update');\n return LinkedStorage.updateQuery(builder);\n }\n async post_delete({ query }) {\n const builder = toQueryBuilder(query);\n await authorizeGenericQuery('delete', query, builder, 'api/delete');\n return LinkedStorage.deleteQuery(builder);\n }\n\n async post_select_raw({ query }) {\n // A raw SPARQL string cannot be analysed for the shapes it touches: the\n // `rawQueries` setting decides (a session by default, or off).\n await authorizeRawQuery(query, 'api/select-raw');\n this.checkRawQuerySupport();\n return (LinkedStorage.getDefaultDataset() as unknown as SPARQLStore).rawQuery(\n query\n );\n }\n\n private checkRawQuerySupport() {\n if (!(LinkedStorage.getDefaultDataset() as unknown as SPARQLStore).rawQuery) {\n throw new Error(\n `Default store (${\n Object.getPrototypeOf(LinkedStorage.getDefaultDataset()).constructor\n .name\n }) does not support raw SPARQL queries`\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"LincdAPI.js","sourceRoot":"","sources":["../../../src/shapes/LincdAPI.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAEpE,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,+EAA+E;AAC/E,SAAS,aAAa,CAAC,KAAU;IAC/B,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;QAChC,KAAK,CAAC,MAAM,IAAI,GAAG;QACnB,KAAK,CAAC,MAAM,GAAG,GAAG;QAClB,KAAK,CAAC,IAAI,KAAK,iBAAiB,CACjC,CAAC;AACJ,CAAC;AAED,iGAAiG;AACjG,gGAAgG;AAChG,4EAA4E;AAErE,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,KAAK;IAGjC,KAAK,CAAC,OAAO,CACX,OAAO,EACP,QAAQ,EACR,UAA6C;QAE7C,IAAI,EAAE,MAAM,EA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AC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE;QAC7B,wEAAwE;QACxE,+DAA+D;QAC/D,MAAM,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;QACjD,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,OAAQ,aAAa,CAAC,iBAAiB,EAA6B,CAAC,QAAQ,CAC3E,KAAK,CACN,CAAC;IACJ,CAAC;IAEO,oBAAoB;QAC1B,IAAI,CAAE,aAAa,CAAC,iBAAiB,EAA6B,CAAC,QAAQ,EAAE,CAAC;YAC5E,MAAM,IAAI,KAAK,CACb,kBACE,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAC,WAAW;iBACjE,IACL,uCAAuC,CACxC,CAAC;QACJ,CAAC;IACH,CAAC;;AAhFM,oBAAW,GAAG,MAAM,CAAC,QAAQ,AAAlB,CAAmB;AAD1B,QAAQ;IADpB,WAAW,CAAC,EAAC,IAAI,EAAE,UAAU,EAAC,CAAC;GACnB,QAAQ,CAkFpB","sourcesContent":["import { Shape } from '@_linked/core/shapes/Shape';\nimport { linkedShape } from '../package.js';\nimport { server } from '../ontologies/server.js';\nimport { JSONParser } from '@_linked/server-utils/utils/JSONParser';\nimport { LinkedStorage } from '@_linked/core/utils/LinkedStorage';\nimport { JSONWriter } from '@_linked/server-utils/utils/JSONWriter';\nimport { SparqlDataset as SPARQLStore } from '@_linked/core/sparql/SparqlDataset';\nimport {\n authorizeGenericQuery,\n authorizeRawQuery,\n toQueryBuilder,\n} from '../utils/queryPlane.js';\nimport { getRpcExposureMode } from '../utils/rpcExposure.js';\n\n/** An error carrying an HTTP status, such as a `ServerCallError` (401/403). */\nfunction isStatusError(error: any): error is { status: number; message: string } {\n return (\n !!error &&\n typeof error.status === 'number' &&\n error.status >= 400 &&\n error.status < 600 &&\n error.name === 'ServerCallError'\n );\n}\n\n// Named explicitly: tsc emits `let X = class X`, and any later esbuild pass over that JS (Vite's\n// SSR `define` replacement runs one on every file mentioning a defined `process.env.*`) renames\n// the inner binding to `X2`, which would otherwise become this shape's IRI.\n@linkedShape({name: 'LincdAPI'})\nexport class LincdAPI extends Shape {\n static targetClass = server.LincdAPI;\n\n async process(\n request,\n response,\n httpMethod: 'get' | 'post' | 'put' | 'delete'\n ) {\n let { method, action } = request.params;\n const body = JSONParser.parseObject<any>(request.body, {\n shapeClasses: getRpcExposureMode() === 'enforce' ? 'reject' : 'warn',\n });\n\n //replace - with _ in action names\n let localMethod = httpMethod + '_' + method.replace(/-/g, '_');\n if (typeof this[localMethod] !== 'function') {\n throw new Error('Unknown method: ' + localMethod);\n }\n\n // The query routes (`post_*`) check access themselves, through\n // utils/queryPlane.\n try {\n const result = await this[localMethod](body, request, response);\n if (typeof result !== 'undefined' || !response.headersSent) {\n const jsonObject = JSONWriter.toJsObject(result);\n response.json(jsonObject);\n }\n } catch (error) {\n if (!response.headersSent && isStatusError(error)) {\n response.status(error.status).json({ error: error.message });\n return;\n }\n console.error(`Error while processing ${localMethod}:`, error);\n if (!response.headersSent) {\n const message =\n error instanceof Error ? error.message : 'Unknown server error';\n response.status(500).json({ error: message });\n }\n }\n }\n\n async post_select({ query }) {\n const builder = toQueryBuilder(query);\n await authorizeGenericQuery('select', query, builder, 'api/select');\n return LinkedStorage.selectQuery(builder);\n }\n async post_create({ query }) {\n const builder = toQueryBuilder(query);\n await authorizeGenericQuery('create', query, builder, 'api/create');\n return LinkedStorage.createQuery(builder);\n }\n async post_update({ query }) {\n const builder = toQueryBuilder(query);\n await authorizeGenericQuery('update', query, builder, 'api/update');\n return LinkedStorage.updateQuery(builder);\n }\n async post_delete({ query }) {\n const builder = toQueryBuilder(query);\n await authorizeGenericQuery('delete', query, builder, 'api/delete');\n return LinkedStorage.deleteQuery(builder);\n }\n\n async post_select_raw({ query }) {\n // A raw SPARQL string cannot be analysed for the shapes it touches: the\n // `rawQueries` setting decides (a session by default, or off).\n await authorizeRawQuery(query, 'api/select-raw');\n this.checkRawQuerySupport();\n return (LinkedStorage.getDefaultDataset() as unknown as SPARQLStore).rawQuery(\n query\n );\n }\n\n private checkRawQuerySupport() {\n if (!(LinkedStorage.getDefaultDataset() as unknown as SPARQLStore).rawQuery) {\n throw new Error(\n `Default store (${\n Object.getPrototypeOf(LinkedStorage.getDefaultDataset()).constructor\n .name\n }) does not support raw SPARQL queries`\n );\n }\n }\n}\n"]}
@@ -266,8 +266,11 @@ export declare class LinkedServer extends Shape {
266
266
  callBackendMethod(pkg: string, method: string, args: any[], request?: any, response?: any): any;
267
267
  }
268
268
  /**
269
- * Register the RPC routes (`/call/...`) and the `LincdAPI` routes (`/api/...`)
270
- * of `linkedServer` on an express app.
269
+ * Register the RPC routes (`/call/...`) and the `LincdAPI` routes (`POST /api/...`)
270
+ * of `linkedServer` on an express app. `LincdAPI` answers POST only: its GET
271
+ * routes (`/api/all-shapes`, `/api/shape-details`) served the in-memory shape
272
+ * index, which is gone, so no `GET /api/...` is mounted and those paths are left
273
+ * to the app's own routes.
271
274
  *
272
275
  * `LinkedServer.start()` calls this; tests call it on a bare express app so they
273
276
  * drive exactly the routes a running server has.
@@ -111,7 +111,6 @@ import { resolveStaticAccessURL, staticAssetURL, } from '../utils/releaseManifes
111
111
  import { resolveBootstrapEntry, resolveViteMainEntry, resolveViteServingMode, } from '../utils/bootstrapEntry.js';
112
112
  import { resolveRouteAssets } from '../utils/routeAssets.js';
113
113
  import { resolveRouteComponent, ssrCssInlineUrls, ssrCssScope, } from '../utils/ssrCss.js';
114
- import { indexShapesIntoMemory } from '../utils/Shapes.js';
115
114
  import { materializeShapes } from '../utils/syncShapes.js';
116
115
  import { installSpaFallback, repinSpaFallback, } from '../utils/spaFallback.js';
117
116
  import { LincdAPI } from './LincdAPI.js';
@@ -314,7 +313,6 @@ let LinkedServer = class LinkedServer extends Shape {
314
313
  this.initPackage();
315
314
  this.server = express();
316
315
  await this.initBackendProviders();
317
- await indexShapesIntoMemory();
318
316
  await this.materializeShapesIntoStore();
319
317
  return this;
320
318
  }
@@ -502,7 +500,6 @@ let LinkedServer = class LinkedServer extends Shape {
502
500
  // });
503
501
  // before controllers
504
502
  await this.initBackendProviders();
505
- await indexShapesIntoMemory();
506
503
  await this.materializeShapesIntoStore();
507
504
  //START OF EXPRESS ROUTES AND MIDDLEWARE
508
505
  //use cors
@@ -2095,8 +2092,11 @@ LinkedServer = __decorate([
2095
2092
  ], LinkedServer);
2096
2093
  export { LinkedServer };
2097
2094
  /**
2098
- * Register the RPC routes (`/call/...`) and the `LincdAPI` routes (`/api/...`)
2099
- * of `linkedServer` on an express app.
2095
+ * Register the RPC routes (`/call/...`) and the `LincdAPI` routes (`POST /api/...`)
2096
+ * of `linkedServer` on an express app. `LincdAPI` answers POST only: its GET
2097
+ * routes (`/api/all-shapes`, `/api/shape-details`) served the in-memory shape
2098
+ * index, which is gone, so no `GET /api/...` is mounted and those paths are left
2099
+ * to the app's own routes.
2100
2100
  *
2101
2101
  * `LinkedServer.start()` calls this; tests call it on a bare express app so they
2102
2102
  * drive exactly the routes a running server has.
@@ -2121,6 +2121,5 @@ export function registerCallRoutes(app, linkedServer) {
2121
2121
  app.post('/call/:pkg/:method', server.handleErrorsJson(async (req, res) => server.processBackendMethodCall(req, res)));
2122
2122
  app.post('/call/:pkg/:shape/:method', server.handleErrorsJson(async (req, res) => server.processShapeMethodCall(req, res)));
2123
2123
  app.post('/api/:method/:action?', server.handleErrorsJson(async (req, res) => server.processAPICall(req, res, 'post')));
2124
- app.get('/api/:method/:action?', server.handleErrorsJson(async (req, res) => server.processAPICall(req, res, 'get')));
2125
2124
  }
2126
2125
  //# sourceMappingURL=LinkedServer.js.map