@pod-os/core 0.34.0-rc.c7db9e6.0 → 0.34.0-rc.d2d66c6.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.
package/dist/index.js CHANGED
@@ -20100,7 +20100,7 @@ var Serializer = class _Serializer {
20100
20100
  return self2.atomicTermToN3(x);
20101
20101
  }
20102
20102
  var list = x.elements;
20103
- var rest3 = kb.sym(rdfns + "nill");
20103
+ var rest3 = kb.sym(rdfns + "nil");
20104
20104
  for (var i2 = list.length - 1; i2 >= 0; i2--) {
20105
20105
  var bnode = factory.blankNode();
20106
20106
  str += termToNT(bnode) + " " + termToNT(kb.sym(rdfns + "first")) + " " + termToNT(list[i2]) + ".\n";
@@ -20410,7 +20410,7 @@ var Serializer = class _Serializer {
20410
20410
  var canSplit = !namespaceIsBaseDir && !forbidDotLocal && namesp.length > minNamespaceLength && this.isValidPNLocal(localid);
20411
20411
  if (canSplit) {
20412
20412
  if (this.defaultNamespace && this.defaultNamespace === namesp && this.flags.indexOf("d") < 0) {
20413
- if (this.flags.indexOf("k") >= 0 && this.keyords.indexOf(localid) < 0) {
20413
+ if (this.flags.indexOf("k") >= 0 && this.keywords.indexOf(localid) < 0) {
20414
20414
  return localid;
20415
20415
  }
20416
20416
  return ":" + localid;
@@ -27433,7 +27433,7 @@ function parse2(str, kb, base2, contentType4 = "text/turtle", callback) {
27433
27433
  contentType4 = contentType4 || TurtleContentType;
27434
27434
  contentType4 = contentType4.split(";")[0];
27435
27435
  try {
27436
- if (contentType4 === N3ContentType || contentType4 === TurtleContentType) {
27436
+ if (contentType4 === N3ContentType || contentType4 === TurtleContentType || contentType4 === NTriplesContentType) {
27437
27437
  var p = n3parser_default(kb, kb, base2, base2, null, null, "", null);
27438
27438
  p.loadBuf(str);
27439
27439
  executeCallback();
@@ -27479,7 +27479,8 @@ function parse2(str, kb, base2, contentType4 = "text/turtle", callback) {
27479
27479
  "application/sparql-update-single-match": true,
27480
27480
  "application/ld+json": true,
27481
27481
  "application/nquads": true,
27482
- "application/n-quads": true
27482
+ "application/n-quads": true,
27483
+ "application/n-triples": true
27483
27484
  };
27484
27485
  function executeCallback() {
27485
27486
  if (callback) {
@@ -28013,15 +28014,24 @@ var Fetcher = class _Fetcher {
28013
28014
  options = this.initFetchOptions(docuri, options);
28014
28015
  const meta2 = this.appNode;
28015
28016
  const kb = this.store;
28016
- const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.sym(docuri), meta2).map((st2) => st2.subject);
28017
+ const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.rdfFactory.literal(docuri), meta2).map((st2) => st2.subject);
28018
+ let answered = false;
28019
+ let usableAnswer = false;
28017
28020
  for (const request2 of requests) {
28018
28021
  const response6 = kb.any(request2, this.ns.link("response"), null, meta2);
28019
- if (response6 != void 0) {
28020
- const quad3 = kb.statementsMatching(response6, this.ns.link("outOfDate"), true, meta2);
28021
- kb.remove(quad3);
28022
- options.force = true;
28023
- options.clearPreviousData = true;
28022
+ if (response6 == null) {
28023
+ continue;
28024
28024
  }
28025
+ answered = true;
28026
+ const outOfDate = kb.anyJS(response6, this.ns.link("outOfDate"), null, meta2);
28027
+ if (!outOfDate) {
28028
+ usableAnswer = true;
28029
+ break;
28030
+ }
28031
+ }
28032
+ if (answered && !usableAnswer) {
28033
+ options.force = true;
28034
+ options.clearPreviousData = true;
28025
28035
  }
28026
28036
  const initialisedOptions = this.initFetchOptions(docuri, options);
28027
28037
  return this.pendingFetchPromise(docuri, initialisedOptions.baseURI, initialisedOptions);
@@ -30574,16 +30584,20 @@ var SearchIndex = class {
30574
30584
  this.index = this.rebuild().index;
30575
30585
  }
30576
30586
  /**
30577
- * Recreates the search index with the current data from all label indexes
30587
+ * Recreates the search index with the current data from all label indexes.
30588
+ * Optionally replaces the captured label indexes before rebuilding.
30578
30589
  */
30579
- rebuild() {
30580
- const labelIndexes = this.labelIndexes;
30590
+ rebuild(labelIndexes) {
30591
+ if (labelIndexes) {
30592
+ this.labelIndexes = labelIndexes;
30593
+ }
30594
+ const captured = this.labelIndexes;
30581
30595
  this.index = (0, import_lunr.default)(function() {
30582
30596
  this.ref("uri");
30583
30597
  this.field("uri");
30584
30598
  this.field("label");
30585
30599
  this.metadataWhitelist = ["position"];
30586
- const items2 = labelIndexes.flatMap((it) => it.getIndexedItems());
30600
+ const items2 = captured.flatMap((it) => it.getIndexedItems());
30587
30601
  items2.forEach((item4) => {
30588
30602
  this.add({
30589
30603
  uri: item4.uri,
@@ -30786,26 +30800,48 @@ var SearchGateway = class {
30786
30800
  this.store = store;
30787
30801
  }
30788
30802
  /**
30789
- * Fetch the private label index for the given profile and build a search index from it
30803
+ * Fetch the private label index for the given profile and build a search index from it.
30804
+ * Repeated calls return the cached index instance.
30790
30805
  * @param profile
30791
30806
  */
30792
30807
  async buildSearchIndex(profile2) {
30793
- const labelIndexUris = profile2.getPrivateLabelIndexes();
30794
- if (labelIndexUris.length > 0) {
30795
- await this.store.fetchAll(labelIndexUris);
30796
- const labelIndex = labelIndexUris.map(
30797
- (uri6) => this.store.get(uri6).assume(LabelIndex)
30798
- );
30799
- return new SearchIndex(labelIndex);
30808
+ if (!this.cached) {
30809
+ const labelIndexUris = profile2.getPrivateLabelIndexes();
30810
+ this.cached = await this.buildIndex(labelIndexUris);
30800
30811
  }
30801
- return new SearchIndex([]);
30812
+ return this.cached;
30813
+ }
30814
+ /**
30815
+ * Clears the cached search index, so that the next call to {@link buildSearchIndex}
30816
+ * builds a new index.
30817
+ */
30818
+ clear() {
30819
+ this.cached = void 0;
30820
+ }
30821
+ async buildIndex(labelIndexUris) {
30822
+ const labelIndex = await this.resolveLabelIndexes(labelIndexUris);
30823
+ return new SearchIndex(labelIndex);
30824
+ }
30825
+ async resolveLabelIndexes(labelIndexUris) {
30826
+ await this.store.fetchAll(labelIndexUris);
30827
+ return labelIndexUris.map(
30828
+ (uri6) => this.store.get(uri6).assume(LabelIndex)
30829
+ );
30802
30830
  }
30803
30831
  async addToLabelIndex(thing, labelIndex) {
30804
30832
  await this.store.executeUpdate(addToLabelIndex(thing, labelIndex));
30833
+ if (this.cached) {
30834
+ this.cached.rebuild();
30835
+ }
30805
30836
  }
30806
30837
  async createDefaultLabelIndex(profile2) {
30807
30838
  const operation3 = createDefaultLabelIndex(profile2);
30808
30839
  await this.store.executeUpdate(operation3);
30840
+ if (this.cached) {
30841
+ this.cached.rebuild(
30842
+ await this.resolveLabelIndexes(profile2.getPrivateLabelIndexes())
30843
+ );
30844
+ }
30809
30845
  return this.store.get(operation3.uri).assume(LabelIndex);
30810
30846
  }
30811
30847
  };
@@ -53218,6 +53254,7 @@ var PodOS = class {
53218
53254
  this.session.observeSession().pipe(
53219
53255
  tap(() => {
53220
53256
  this.store.flagAuthorizationMetadata();
53257
+ this.searchGateway.clear();
53221
53258
  })
53222
53259
  ).subscribe();
53223
53260
  }
package/lib/index.js CHANGED
@@ -28542,7 +28542,7 @@ var PodOS = (() => {
28542
28542
  return self2.atomicTermToN3(x);
28543
28543
  }
28544
28544
  var list = x.elements;
28545
- var rest3 = kb.sym(rdfns + "nill");
28545
+ var rest3 = kb.sym(rdfns + "nil");
28546
28546
  for (var i2 = list.length - 1; i2 >= 0; i2--) {
28547
28547
  var bnode = factory.blankNode();
28548
28548
  str += termToNT(bnode) + " " + termToNT(kb.sym(rdfns + "first")) + " " + termToNT(list[i2]) + ".\n";
@@ -28852,7 +28852,7 @@ var PodOS = (() => {
28852
28852
  var canSplit = !namespaceIsBaseDir && !forbidDotLocal && namesp.length > minNamespaceLength && this.isValidPNLocal(localid);
28853
28853
  if (canSplit) {
28854
28854
  if (this.defaultNamespace && this.defaultNamespace === namesp && this.flags.indexOf("d") < 0) {
28855
- if (this.flags.indexOf("k") >= 0 && this.keyords.indexOf(localid) < 0) {
28855
+ if (this.flags.indexOf("k") >= 0 && this.keywords.indexOf(localid) < 0) {
28856
28856
  return localid;
28857
28857
  }
28858
28858
  return ":" + localid;
@@ -35875,7 +35875,7 @@ var PodOS = (() => {
35875
35875
  contentType4 = contentType4 || TurtleContentType;
35876
35876
  contentType4 = contentType4.split(";")[0];
35877
35877
  try {
35878
- if (contentType4 === N3ContentType || contentType4 === TurtleContentType) {
35878
+ if (contentType4 === N3ContentType || contentType4 === TurtleContentType || contentType4 === NTriplesContentType) {
35879
35879
  var p = n3parser_default(kb, kb, base2, base2, null, null, "", null);
35880
35880
  p.loadBuf(str);
35881
35881
  executeCallback();
@@ -35921,7 +35921,8 @@ var PodOS = (() => {
35921
35921
  "application/sparql-update-single-match": true,
35922
35922
  "application/ld+json": true,
35923
35923
  "application/nquads": true,
35924
- "application/n-quads": true
35924
+ "application/n-quads": true,
35925
+ "application/n-triples": true
35925
35926
  };
35926
35927
  function executeCallback() {
35927
35928
  if (callback) {
@@ -36455,15 +36456,24 @@ var PodOS = (() => {
36455
36456
  options = this.initFetchOptions(docuri, options);
36456
36457
  const meta2 = this.appNode;
36457
36458
  const kb = this.store;
36458
- const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.sym(docuri), meta2).map((st2) => st2.subject);
36459
+ const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.rdfFactory.literal(docuri), meta2).map((st2) => st2.subject);
36460
+ let answered = false;
36461
+ let usableAnswer = false;
36459
36462
  for (const request2 of requests) {
36460
36463
  const response6 = kb.any(request2, this.ns.link("response"), null, meta2);
36461
- if (response6 != void 0) {
36462
- const quad3 = kb.statementsMatching(response6, this.ns.link("outOfDate"), true, meta2);
36463
- kb.remove(quad3);
36464
- options.force = true;
36465
- options.clearPreviousData = true;
36464
+ if (response6 == null) {
36465
+ continue;
36466
36466
  }
36467
+ answered = true;
36468
+ const outOfDate = kb.anyJS(response6, this.ns.link("outOfDate"), null, meta2);
36469
+ if (!outOfDate) {
36470
+ usableAnswer = true;
36471
+ break;
36472
+ }
36473
+ }
36474
+ if (answered && !usableAnswer) {
36475
+ options.force = true;
36476
+ options.clearPreviousData = true;
36467
36477
  }
36468
36478
  const initialisedOptions = this.initFetchOptions(docuri, options);
36469
36479
  return this.pendingFetchPromise(docuri, initialisedOptions.baseURI, initialisedOptions);
@@ -39016,16 +39026,20 @@ _:patch
39016
39026
  this.index = this.rebuild().index;
39017
39027
  }
39018
39028
  /**
39019
- * Recreates the search index with the current data from all label indexes
39029
+ * Recreates the search index with the current data from all label indexes.
39030
+ * Optionally replaces the captured label indexes before rebuilding.
39020
39031
  */
39021
- rebuild() {
39022
- const labelIndexes = this.labelIndexes;
39032
+ rebuild(labelIndexes) {
39033
+ if (labelIndexes) {
39034
+ this.labelIndexes = labelIndexes;
39035
+ }
39036
+ const captured = this.labelIndexes;
39023
39037
  this.index = (0, import_lunr.default)(function() {
39024
39038
  this.ref("uri");
39025
39039
  this.field("uri");
39026
39040
  this.field("label");
39027
39041
  this.metadataWhitelist = ["position"];
39028
- const items2 = labelIndexes.flatMap((it) => it.getIndexedItems());
39042
+ const items2 = captured.flatMap((it) => it.getIndexedItems());
39029
39043
  items2.forEach((item4) => {
39030
39044
  this.add({
39031
39045
  uri: item4.uri,
@@ -39228,26 +39242,48 @@ _:patch
39228
39242
  this.store = store;
39229
39243
  }
39230
39244
  /**
39231
- * Fetch the private label index for the given profile and build a search index from it
39245
+ * Fetch the private label index for the given profile and build a search index from it.
39246
+ * Repeated calls return the cached index instance.
39232
39247
  * @param profile
39233
39248
  */
39234
39249
  async buildSearchIndex(profile2) {
39235
- const labelIndexUris = profile2.getPrivateLabelIndexes();
39236
- if (labelIndexUris.length > 0) {
39237
- await this.store.fetchAll(labelIndexUris);
39238
- const labelIndex = labelIndexUris.map(
39239
- (uri6) => this.store.get(uri6).assume(LabelIndex)
39240
- );
39241
- return new SearchIndex(labelIndex);
39250
+ if (!this.cached) {
39251
+ const labelIndexUris = profile2.getPrivateLabelIndexes();
39252
+ this.cached = await this.buildIndex(labelIndexUris);
39242
39253
  }
39243
- return new SearchIndex([]);
39254
+ return this.cached;
39255
+ }
39256
+ /**
39257
+ * Clears the cached search index, so that the next call to {@link buildSearchIndex}
39258
+ * builds a new index.
39259
+ */
39260
+ clear() {
39261
+ this.cached = void 0;
39262
+ }
39263
+ async buildIndex(labelIndexUris) {
39264
+ const labelIndex = await this.resolveLabelIndexes(labelIndexUris);
39265
+ return new SearchIndex(labelIndex);
39266
+ }
39267
+ async resolveLabelIndexes(labelIndexUris) {
39268
+ await this.store.fetchAll(labelIndexUris);
39269
+ return labelIndexUris.map(
39270
+ (uri6) => this.store.get(uri6).assume(LabelIndex)
39271
+ );
39244
39272
  }
39245
39273
  async addToLabelIndex(thing, labelIndex) {
39246
39274
  await this.store.executeUpdate(addToLabelIndex(thing, labelIndex));
39275
+ if (this.cached) {
39276
+ this.cached.rebuild();
39277
+ }
39247
39278
  }
39248
39279
  async createDefaultLabelIndex(profile2) {
39249
39280
  const operation3 = createDefaultLabelIndex(profile2);
39250
39281
  await this.store.executeUpdate(operation3);
39282
+ if (this.cached) {
39283
+ this.cached.rebuild(
39284
+ await this.resolveLabelIndexes(profile2.getPrivateLabelIndexes())
39285
+ );
39286
+ }
39251
39287
  return this.store.get(operation3.uri).assume(LabelIndex);
39252
39288
  }
39253
39289
  };
@@ -61660,6 +61696,7 @@ _:patch
61660
61696
  this.session.observeSession().pipe(
61661
61697
  tap(() => {
61662
61698
  this.store.flagAuthorizationMetadata();
61699
+ this.searchGateway.clear();
61663
61700
  })
61664
61701
  ).subscribe();
61665
61702
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pod-os/core",
3
3
  "description": "Core module of PodOS",
4
- "version": "0.34.0-rc.c7db9e6.0",
4
+ "version": "0.34.0-rc.d2d66c6.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./types/index.d.ts",
@@ -53,9 +53,9 @@
53
53
  "rimraf": "^6.1.3",
54
54
  "sparqljs": "^3.7.4",
55
55
  "typedoc": "^0.28.20",
56
- "typedoc-plugin-markdown": "^4.13.0",
56
+ "typedoc-plugin-markdown": "^4.13.1",
57
57
  "typescript": "^6.0.3",
58
- "typescript-eslint": "^8.67.0",
58
+ "typescript-eslint": "^8.71.0",
59
59
  "vitest": "^4.1.11",
60
60
  "vitest-when": "^0.10.0"
61
61
  },
@@ -67,7 +67,7 @@
67
67
  "mime": "^4.1.0",
68
68
  "neverthrow": "^8.2.0",
69
69
  "rdf-namespaces": "^1.17.0",
70
- "rdflib": "2.4.0",
70
+ "rdflib": "2.4.1",
71
71
  "rxjs": "^7.8.2",
72
72
  "slugify": "^1.6.9",
73
73
  "url": "^0.11.4",
@@ -5,12 +5,21 @@ import { Thing } from "../thing";
5
5
  import { SearchIndex } from "./SearchIndex";
6
6
  export declare class SearchGateway {
7
7
  private readonly store;
8
+ private cached?;
8
9
  constructor(store: Store);
9
10
  /**
10
- * Fetch the private label index for the given profile and build a search index from it
11
+ * Fetch the private label index for the given profile and build a search index from it.
12
+ * Repeated calls return the cached index instance.
11
13
  * @param profile
12
14
  */
13
15
  buildSearchIndex(profile: WebIdProfile): Promise<SearchIndex>;
16
+ /**
17
+ * Clears the cached search index, so that the next call to {@link buildSearchIndex}
18
+ * builds a new index.
19
+ */
20
+ clear(): void;
21
+ private buildIndex;
22
+ private resolveLabelIndexes;
14
23
  addToLabelIndex(thing: Thing, labelIndex: LabelIndex): Promise<void>;
15
24
  createDefaultLabelIndex(profile: WebIdProfile): Promise<LabelIndex>;
16
25
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -5,12 +5,13 @@ import { Index } from "lunr";
5
5
  */
6
6
  export declare class SearchIndex {
7
7
  private index;
8
- private readonly labelIndexes;
8
+ private labelIndexes;
9
9
  constructor(labelIndexes: LabelIndex[]);
10
10
  /**
11
- * Recreates the search index with the current data from all label indexes
11
+ * Recreates the search index with the current data from all label indexes.
12
+ * Optionally replaces the captured label indexes before rebuilding.
12
13
  */
13
- rebuild(): this;
14
+ rebuild(labelIndexes?: LabelIndex[]): this;
14
15
  /**
15
16
  * Search the index for a given term. It finds partial matches, but will rank exact matches higher.
16
17
  *