@pod-os/core 0.33.0-rc.fae4f86.0 → 0.34.0-rc.2a1133e.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
@@ -17179,6 +17179,40 @@ function from(input2, scheduler) {
17179
17179
  return scheduler ? scheduled(input2, scheduler) : innerFrom(input2);
17180
17180
  }
17181
17181
 
17182
+ // ../node_modules/rxjs/dist/esm5/internal/util/EmptyError.js
17183
+ var EmptyError = createErrorClass(function(_super) {
17184
+ return function EmptyErrorImpl() {
17185
+ _super(this);
17186
+ this.name = "EmptyError";
17187
+ this.message = "no elements in sequence";
17188
+ };
17189
+ });
17190
+
17191
+ // ../node_modules/rxjs/dist/esm5/internal/lastValueFrom.js
17192
+ function lastValueFrom(source10, config2) {
17193
+ var hasConfig = typeof config2 === "object";
17194
+ return new Promise(function(resolve, reject) {
17195
+ var _hasValue = false;
17196
+ var _value2;
17197
+ source10.subscribe({
17198
+ next: function(value8) {
17199
+ _value2 = value8;
17200
+ _hasValue = true;
17201
+ },
17202
+ error: reject,
17203
+ complete: function() {
17204
+ if (_hasValue) {
17205
+ resolve(_value2);
17206
+ } else if (hasConfig) {
17207
+ resolve(config2.defaultValue);
17208
+ } else {
17209
+ reject(new EmptyError());
17210
+ }
17211
+ }
17212
+ });
17213
+ });
17214
+ }
17215
+
17182
17216
  // ../node_modules/rxjs/dist/esm5/internal/operators/map.js
17183
17217
  function map(project, thisArg) {
17184
17218
  return operate(function(source10, subscriber3) {
@@ -18428,7 +18462,8 @@ var Mime = class {
18428
18462
  getAllExtensions(type5) {
18429
18463
  if (typeof type5 !== "string")
18430
18464
  return null;
18431
- return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type5.toLowerCase()) ?? null;
18465
+ type5 = type5.split(";")[0].trim().toLowerCase();
18466
+ return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type5) ?? null;
18432
18467
  }
18433
18468
  _freeze() {
18434
18469
  this.define = () => {
@@ -20100,7 +20135,7 @@ var Serializer = class _Serializer {
20100
20135
  return self2.atomicTermToN3(x);
20101
20136
  }
20102
20137
  var list = x.elements;
20103
- var rest3 = kb.sym(rdfns + "nill");
20138
+ var rest3 = kb.sym(rdfns + "nil");
20104
20139
  for (var i2 = list.length - 1; i2 >= 0; i2--) {
20105
20140
  var bnode = factory.blankNode();
20106
20141
  str += termToNT(bnode) + " " + termToNT(kb.sym(rdfns + "first")) + " " + termToNT(list[i2]) + ".\n";
@@ -20410,7 +20445,7 @@ var Serializer = class _Serializer {
20410
20445
  var canSplit = !namespaceIsBaseDir && !forbidDotLocal && namesp.length > minNamespaceLength && this.isValidPNLocal(localid);
20411
20446
  if (canSplit) {
20412
20447
  if (this.defaultNamespace && this.defaultNamespace === namesp && this.flags.indexOf("d") < 0) {
20413
- if (this.flags.indexOf("k") >= 0 && this.keyords.indexOf(localid) < 0) {
20448
+ if (this.flags.indexOf("k") >= 0 && this.keywords.indexOf(localid) < 0) {
20414
20449
  return localid;
20415
20450
  }
20416
20451
  return ":" + localid;
@@ -27433,7 +27468,7 @@ function parse2(str, kb, base2, contentType4 = "text/turtle", callback) {
27433
27468
  contentType4 = contentType4 || TurtleContentType;
27434
27469
  contentType4 = contentType4.split(";")[0];
27435
27470
  try {
27436
- if (contentType4 === N3ContentType || contentType4 === TurtleContentType) {
27471
+ if (contentType4 === N3ContentType || contentType4 === TurtleContentType || contentType4 === NTriplesContentType) {
27437
27472
  var p = n3parser_default(kb, kb, base2, base2, null, null, "", null);
27438
27473
  p.loadBuf(str);
27439
27474
  executeCallback();
@@ -27479,7 +27514,8 @@ function parse2(str, kb, base2, contentType4 = "text/turtle", callback) {
27479
27514
  "application/sparql-update-single-match": true,
27480
27515
  "application/ld+json": true,
27481
27516
  "application/nquads": true,
27482
- "application/n-quads": true
27517
+ "application/n-quads": true,
27518
+ "application/n-triples": true
27483
27519
  };
27484
27520
  function executeCallback() {
27485
27521
  if (callback) {
@@ -28013,16 +28049,25 @@ var Fetcher = class _Fetcher {
28013
28049
  options = this.initFetchOptions(docuri, options);
28014
28050
  const meta2 = this.appNode;
28015
28051
  const kb = this.store;
28016
- const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.sym(docuri), meta2).map((st2) => st2.subject);
28052
+ const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.rdfFactory.literal(docuri), meta2).map((st2) => st2.subject);
28053
+ let answered = false;
28054
+ let usableAnswer = false;
28017
28055
  for (const request2 of requests) {
28018
28056
  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;
28057
+ if (response6 == null) {
28058
+ continue;
28059
+ }
28060
+ answered = true;
28061
+ const outOfDate = kb.anyJS(response6, this.ns.link("outOfDate"), null, meta2);
28062
+ if (!outOfDate) {
28063
+ usableAnswer = true;
28064
+ break;
28024
28065
  }
28025
28066
  }
28067
+ if (answered && !usableAnswer) {
28068
+ options.force = true;
28069
+ options.clearPreviousData = true;
28070
+ }
28026
28071
  const initialisedOptions = this.initFetchOptions(docuri, options);
28027
28072
  return this.pendingFetchPromise(docuri, initialisedOptions.baseURI, initialisedOptions);
28028
28073
  }
@@ -30574,16 +30619,20 @@ var SearchIndex = class {
30574
30619
  this.index = this.rebuild().index;
30575
30620
  }
30576
30621
  /**
30577
- * Recreates the search index with the current data from all label indexes
30622
+ * Recreates the search index with the current data from all label indexes.
30623
+ * Optionally replaces the captured label indexes before rebuilding.
30578
30624
  */
30579
- rebuild() {
30580
- const labelIndexes = this.labelIndexes;
30625
+ rebuild(labelIndexes) {
30626
+ if (labelIndexes) {
30627
+ this.labelIndexes = labelIndexes;
30628
+ }
30629
+ const captured = this.labelIndexes;
30581
30630
  this.index = (0, import_lunr.default)(function() {
30582
30631
  this.ref("uri");
30583
30632
  this.field("uri");
30584
30633
  this.field("label");
30585
30634
  this.metadataWhitelist = ["position"];
30586
- const items2 = labelIndexes.flatMap((it) => it.getIndexedItems());
30635
+ const items2 = captured.flatMap((it) => it.getIndexedItems());
30587
30636
  items2.forEach((item4) => {
30588
30637
  this.add({
30589
30638
  uri: item4.uri,
@@ -30782,30 +30831,69 @@ var addToLabelIndex = (thing, labelIndex) => {
30782
30831
 
30783
30832
  // src/search/SearchGateway.ts
30784
30833
  var SearchGateway = class {
30785
- constructor(store) {
30834
+ constructor(store, session4, profileGateway) {
30786
30835
  this.store = store;
30836
+ this.session = session4;
30837
+ this.profileGateway = profileGateway;
30787
30838
  }
30788
30839
  /**
30789
- * Fetch the private label index for the given profile and build a search index from it
30790
- * @param profile
30840
+ * Build a search index on demand.
30841
+ *
30842
+ * While logged in, the profile is resolved from the current session's webId
30843
+ * and the index is built from the profile's label indexes and cached, so that
30844
+ * repeated calls return the same instance.
30845
+ *
30846
+ * While logged out, a fresh empty index is returned that is NOT cached —
30847
+ * the next call after login is a cache miss and builds.
30791
30848
  */
30792
- 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);
30849
+ async buildSearchIndex() {
30850
+ const session4 = await lastValueFrom(
30851
+ this.session.observeSession().pipe(take(1))
30852
+ );
30853
+ if (!session4.isLoggedIn) {
30854
+ return new SearchIndex([]);
30800
30855
  }
30801
- return new SearchIndex([]);
30856
+ const webId = session4.webId;
30857
+ const profile2 = await this.profileGateway.fetchProfile(webId);
30858
+ if (!this.cached) {
30859
+ const labelIndexUris = profile2.getPrivateLabelIndexes();
30860
+ this.cached = await this.buildIndex(labelIndexUris);
30861
+ }
30862
+ return this.cached;
30863
+ }
30864
+ /**
30865
+ * Empties the cached search index in place and drops the cache reference, so
30866
+ * that consumers already holding the instance see an empty index immediately
30867
+ * and the next call to {@link buildSearchIndex} builds a new index.
30868
+ */
30869
+ clear() {
30870
+ this.cached?.clear();
30871
+ this.cached = void 0;
30872
+ }
30873
+ async buildIndex(labelIndexUris) {
30874
+ const labelIndex = await this.resolveLabelIndexes(labelIndexUris);
30875
+ return new SearchIndex(labelIndex);
30876
+ }
30877
+ async resolveLabelIndexes(labelIndexUris) {
30878
+ await this.store.fetchAll(labelIndexUris);
30879
+ return labelIndexUris.map(
30880
+ (uri6) => this.store.get(uri6).assume(LabelIndex)
30881
+ );
30802
30882
  }
30803
30883
  async addToLabelIndex(thing, labelIndex) {
30804
30884
  await this.store.executeUpdate(addToLabelIndex(thing, labelIndex));
30885
+ if (this.cached) {
30886
+ this.cached.rebuild();
30887
+ }
30805
30888
  }
30806
30889
  async createDefaultLabelIndex(profile2) {
30807
30890
  const operation3 = createDefaultLabelIndex(profile2);
30808
30891
  await this.store.executeUpdate(operation3);
30892
+ if (this.cached) {
30893
+ this.cached.rebuild(
30894
+ await this.resolveLabelIndexes(profile2.getPrivateLabelIndexes())
30895
+ );
30896
+ }
30809
30897
  return this.store.get(operation3.uri).assume(LabelIndex);
30810
30898
  }
30811
30899
  };
@@ -30920,11 +31008,6 @@ var Store = class {
30920
31008
  */
30921
31009
  async fetch(uri6) {
30922
31010
  const response6 = await this.fetcher.load(namedNode2(uri6), {
30923
- // force fetching due to
30924
- // https://github.com/linkeddata/rdflib.js/issues/247
30925
- // and
30926
- // https://github.com/linkeddata/rdflib.js/issues/441
30927
- force: true,
30928
31011
  // explicitly omit credentials due to
30929
31012
  // https://github.com/pod-os/PodOS/issues/17
30930
31013
  credentials: "omit"
@@ -30938,7 +31021,6 @@ var Store = class {
30938
31021
  if (descriptionResourceUri) {
30939
31022
  try {
30940
31023
  await this.fetcher.load(namedNode2(descriptionResourceUri.value), {
30941
- force: true,
30942
31024
  credentials: "omit"
30943
31025
  });
30944
31026
  } catch {
@@ -30980,6 +31062,33 @@ var Store = class {
30980
31062
  st(namedNode2(thing.uri), namedNode2(property4), lit(value8), namedNode2(docUrl))
30981
31063
  );
30982
31064
  }
31065
+ /**
31066
+ * Updates the value of the given property of the given thing to the new value
31067
+ * @param thing
31068
+ * @param property
31069
+ * @param oldValue
31070
+ * @param newValue
31071
+ */
31072
+ async editPropertyValue(thing, property4, oldValue, newValue) {
31073
+ const docUrl = this.determineDocumentToUpdate(thing);
31074
+ const remove = st(
31075
+ namedNode2(thing.uri),
31076
+ namedNode2(property4),
31077
+ lit(oldValue),
31078
+ namedNode2(docUrl)
31079
+ );
31080
+ const insert = st(
31081
+ namedNode2(thing.uri),
31082
+ namedNode2(property4),
31083
+ lit(newValue),
31084
+ namedNode2(docUrl)
31085
+ );
31086
+ return this.updater.update([remove], [insert], void 0, false, {
31087
+ // explicitly omit credentials due to
31088
+ // https://github.com/pod-os/PodOS/issues/17
31089
+ credentials: "omit"
31090
+ });
31091
+ }
30983
31092
  insert(statement2) {
30984
31093
  return this.updater.update([], [statement2], void 0, false, {
30985
31094
  // explicitly omit credentials due to
@@ -53171,14 +53280,18 @@ var PodOS = class {
53171
53280
  onlineStatus,
53172
53281
  internalStore
53173
53282
  );
53174
- this.searchGateway = new SearchGateway(this.store);
53283
+ this.profileGateway = new ProfileGateway(this.store);
53284
+ this.searchGateway = new SearchGateway(
53285
+ this.store,
53286
+ this.session,
53287
+ this.profileGateway
53288
+ );
53175
53289
  this.fileFetcher = new FileFetcher(this.session);
53176
53290
  this.fileGateway = new FileGateway(this.store, this.fileFetcher);
53177
53291
  this.attachmentGateway = new AttachmentGateway(this.fileGateway);
53178
53292
  this.pictureGateway = new PictureGateway(this.fileGateway);
53179
53293
  this.flagAuthorizationMetaDataOnSessionChange();
53180
53294
  this.uriService = new UriService(this.store);
53181
- this.profileGateway = new ProfileGateway(this.store);
53182
53295
  }
53183
53296
  /*
53184
53297
  Flagging authorization metadata is necessary every time the user
@@ -53191,6 +53304,7 @@ var PodOS = class {
53191
53304
  this.session.observeSession().pipe(
53192
53305
  tap(() => {
53193
53306
  this.store.flagAuthorizationMetadata();
53307
+ this.searchGateway.clear();
53194
53308
  })
53195
53309
  ).subscribe();
53196
53310
  }
@@ -53224,6 +53338,16 @@ var PodOS = class {
53224
53338
  addPropertyValue(thing, property4, value8) {
53225
53339
  return this.store.addPropertyValue(thing, property4, value8);
53226
53340
  }
53341
+ /**
53342
+ * Updates the value of the given property of the given thing to the new value
53343
+ * @param thing
53344
+ * @param property
53345
+ * @param oldValue
53346
+ * @param newValue
53347
+ */
53348
+ editPropertyValue(thing, property4, oldValue, newValue) {
53349
+ return this.store.editPropertyValue(thing, property4, oldValue, newValue);
53350
+ }
53227
53351
  /**
53228
53352
  * Adds a new relation (link) from the thing to the given uri using the property
53229
53353
  * @param thing
@@ -53256,11 +53380,15 @@ var PodOS = class {
53256
53380
  return this.profileGateway.fetchProfile(webId);
53257
53381
  }
53258
53382
  /**
53259
- * Fetch the private label index for the given profile and build a search index from it
53260
- * @param profile
53383
+ * Build the search index on demand.
53384
+ *
53385
+ * While logged in, the index is built from the logged-in user's label indexes
53386
+ * and cached, so repeated calls return the same instance.
53387
+ *
53388
+ * While logged out, a fresh empty index is returned that is not cached.
53261
53389
  */
53262
- async buildSearchIndex(profile2) {
53263
- return this.searchGateway.buildSearchIndex(profile2);
53390
+ async buildSearchIndex() {
53391
+ return this.searchGateway.buildSearchIndex();
53264
53392
  }
53265
53393
  logout() {
53266
53394
  this.offlineCache.clear();
package/lib/index.js CHANGED
@@ -25621,6 +25621,40 @@ var PodOS = (() => {
25621
25621
  return scheduler ? scheduled(input2, scheduler) : innerFrom(input2);
25622
25622
  }
25623
25623
 
25624
+ // ../node_modules/rxjs/dist/esm5/internal/util/EmptyError.js
25625
+ var EmptyError = createErrorClass(function(_super) {
25626
+ return function EmptyErrorImpl() {
25627
+ _super(this);
25628
+ this.name = "EmptyError";
25629
+ this.message = "no elements in sequence";
25630
+ };
25631
+ });
25632
+
25633
+ // ../node_modules/rxjs/dist/esm5/internal/lastValueFrom.js
25634
+ function lastValueFrom(source10, config2) {
25635
+ var hasConfig = typeof config2 === "object";
25636
+ return new Promise(function(resolve, reject) {
25637
+ var _hasValue = false;
25638
+ var _value2;
25639
+ source10.subscribe({
25640
+ next: function(value8) {
25641
+ _value2 = value8;
25642
+ _hasValue = true;
25643
+ },
25644
+ error: reject,
25645
+ complete: function() {
25646
+ if (_hasValue) {
25647
+ resolve(_value2);
25648
+ } else if (hasConfig) {
25649
+ resolve(config2.defaultValue);
25650
+ } else {
25651
+ reject(new EmptyError());
25652
+ }
25653
+ }
25654
+ });
25655
+ });
25656
+ }
25657
+
25624
25658
  // ../node_modules/rxjs/dist/esm5/internal/operators/map.js
25625
25659
  function map(project, thisArg) {
25626
25660
  return operate(function(source10, subscriber3) {
@@ -26870,7 +26904,8 @@ var PodOS = (() => {
26870
26904
  getAllExtensions(type5) {
26871
26905
  if (typeof type5 !== "string")
26872
26906
  return null;
26873
- return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type5.toLowerCase()) ?? null;
26907
+ type5 = type5.split(";")[0].trim().toLowerCase();
26908
+ return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type5) ?? null;
26874
26909
  }
26875
26910
  _freeze() {
26876
26911
  this.define = () => {
@@ -28542,7 +28577,7 @@ var PodOS = (() => {
28542
28577
  return self2.atomicTermToN3(x);
28543
28578
  }
28544
28579
  var list = x.elements;
28545
- var rest3 = kb.sym(rdfns + "nill");
28580
+ var rest3 = kb.sym(rdfns + "nil");
28546
28581
  for (var i2 = list.length - 1; i2 >= 0; i2--) {
28547
28582
  var bnode = factory.blankNode();
28548
28583
  str += termToNT(bnode) + " " + termToNT(kb.sym(rdfns + "first")) + " " + termToNT(list[i2]) + ".\n";
@@ -28852,7 +28887,7 @@ var PodOS = (() => {
28852
28887
  var canSplit = !namespaceIsBaseDir && !forbidDotLocal && namesp.length > minNamespaceLength && this.isValidPNLocal(localid);
28853
28888
  if (canSplit) {
28854
28889
  if (this.defaultNamespace && this.defaultNamespace === namesp && this.flags.indexOf("d") < 0) {
28855
- if (this.flags.indexOf("k") >= 0 && this.keyords.indexOf(localid) < 0) {
28890
+ if (this.flags.indexOf("k") >= 0 && this.keywords.indexOf(localid) < 0) {
28856
28891
  return localid;
28857
28892
  }
28858
28893
  return ":" + localid;
@@ -35875,7 +35910,7 @@ var PodOS = (() => {
35875
35910
  contentType4 = contentType4 || TurtleContentType;
35876
35911
  contentType4 = contentType4.split(";")[0];
35877
35912
  try {
35878
- if (contentType4 === N3ContentType || contentType4 === TurtleContentType) {
35913
+ if (contentType4 === N3ContentType || contentType4 === TurtleContentType || contentType4 === NTriplesContentType) {
35879
35914
  var p = n3parser_default(kb, kb, base2, base2, null, null, "", null);
35880
35915
  p.loadBuf(str);
35881
35916
  executeCallback();
@@ -35921,7 +35956,8 @@ var PodOS = (() => {
35921
35956
  "application/sparql-update-single-match": true,
35922
35957
  "application/ld+json": true,
35923
35958
  "application/nquads": true,
35924
- "application/n-quads": true
35959
+ "application/n-quads": true,
35960
+ "application/n-triples": true
35925
35961
  };
35926
35962
  function executeCallback() {
35927
35963
  if (callback) {
@@ -36455,16 +36491,25 @@ var PodOS = (() => {
36455
36491
  options = this.initFetchOptions(docuri, options);
36456
36492
  const meta2 = this.appNode;
36457
36493
  const kb = this.store;
36458
- const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.sym(docuri), meta2).map((st2) => st2.subject);
36494
+ const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.rdfFactory.literal(docuri), meta2).map((st2) => st2.subject);
36495
+ let answered = false;
36496
+ let usableAnswer = false;
36459
36497
  for (const request2 of requests) {
36460
36498
  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;
36499
+ if (response6 == null) {
36500
+ continue;
36501
+ }
36502
+ answered = true;
36503
+ const outOfDate = kb.anyJS(response6, this.ns.link("outOfDate"), null, meta2);
36504
+ if (!outOfDate) {
36505
+ usableAnswer = true;
36506
+ break;
36466
36507
  }
36467
36508
  }
36509
+ if (answered && !usableAnswer) {
36510
+ options.force = true;
36511
+ options.clearPreviousData = true;
36512
+ }
36468
36513
  const initialisedOptions = this.initFetchOptions(docuri, options);
36469
36514
  return this.pendingFetchPromise(docuri, initialisedOptions.baseURI, initialisedOptions);
36470
36515
  }
@@ -39016,16 +39061,20 @@ _:patch
39016
39061
  this.index = this.rebuild().index;
39017
39062
  }
39018
39063
  /**
39019
- * Recreates the search index with the current data from all label indexes
39064
+ * Recreates the search index with the current data from all label indexes.
39065
+ * Optionally replaces the captured label indexes before rebuilding.
39020
39066
  */
39021
- rebuild() {
39022
- const labelIndexes = this.labelIndexes;
39067
+ rebuild(labelIndexes) {
39068
+ if (labelIndexes) {
39069
+ this.labelIndexes = labelIndexes;
39070
+ }
39071
+ const captured = this.labelIndexes;
39023
39072
  this.index = (0, import_lunr.default)(function() {
39024
39073
  this.ref("uri");
39025
39074
  this.field("uri");
39026
39075
  this.field("label");
39027
39076
  this.metadataWhitelist = ["position"];
39028
- const items2 = labelIndexes.flatMap((it) => it.getIndexedItems());
39077
+ const items2 = captured.flatMap((it) => it.getIndexedItems());
39029
39078
  items2.forEach((item4) => {
39030
39079
  this.add({
39031
39080
  uri: item4.uri,
@@ -39224,30 +39273,69 @@ _:patch
39224
39273
 
39225
39274
  // src/search/SearchGateway.ts
39226
39275
  var SearchGateway = class {
39227
- constructor(store) {
39276
+ constructor(store, session4, profileGateway) {
39228
39277
  this.store = store;
39278
+ this.session = session4;
39279
+ this.profileGateway = profileGateway;
39229
39280
  }
39230
39281
  /**
39231
- * Fetch the private label index for the given profile and build a search index from it
39232
- * @param profile
39282
+ * Build a search index on demand.
39283
+ *
39284
+ * While logged in, the profile is resolved from the current session's webId
39285
+ * and the index is built from the profile's label indexes and cached, so that
39286
+ * repeated calls return the same instance.
39287
+ *
39288
+ * While logged out, a fresh empty index is returned that is NOT cached —
39289
+ * the next call after login is a cache miss and builds.
39233
39290
  */
39234
- 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);
39291
+ async buildSearchIndex() {
39292
+ const session4 = await lastValueFrom(
39293
+ this.session.observeSession().pipe(take(1))
39294
+ );
39295
+ if (!session4.isLoggedIn) {
39296
+ return new SearchIndex([]);
39242
39297
  }
39243
- return new SearchIndex([]);
39298
+ const webId = session4.webId;
39299
+ const profile2 = await this.profileGateway.fetchProfile(webId);
39300
+ if (!this.cached) {
39301
+ const labelIndexUris = profile2.getPrivateLabelIndexes();
39302
+ this.cached = await this.buildIndex(labelIndexUris);
39303
+ }
39304
+ return this.cached;
39305
+ }
39306
+ /**
39307
+ * Empties the cached search index in place and drops the cache reference, so
39308
+ * that consumers already holding the instance see an empty index immediately
39309
+ * and the next call to {@link buildSearchIndex} builds a new index.
39310
+ */
39311
+ clear() {
39312
+ this.cached?.clear();
39313
+ this.cached = void 0;
39314
+ }
39315
+ async buildIndex(labelIndexUris) {
39316
+ const labelIndex = await this.resolveLabelIndexes(labelIndexUris);
39317
+ return new SearchIndex(labelIndex);
39318
+ }
39319
+ async resolveLabelIndexes(labelIndexUris) {
39320
+ await this.store.fetchAll(labelIndexUris);
39321
+ return labelIndexUris.map(
39322
+ (uri6) => this.store.get(uri6).assume(LabelIndex)
39323
+ );
39244
39324
  }
39245
39325
  async addToLabelIndex(thing, labelIndex) {
39246
39326
  await this.store.executeUpdate(addToLabelIndex(thing, labelIndex));
39327
+ if (this.cached) {
39328
+ this.cached.rebuild();
39329
+ }
39247
39330
  }
39248
39331
  async createDefaultLabelIndex(profile2) {
39249
39332
  const operation3 = createDefaultLabelIndex(profile2);
39250
39333
  await this.store.executeUpdate(operation3);
39334
+ if (this.cached) {
39335
+ this.cached.rebuild(
39336
+ await this.resolveLabelIndexes(profile2.getPrivateLabelIndexes())
39337
+ );
39338
+ }
39251
39339
  return this.store.get(operation3.uri).assume(LabelIndex);
39252
39340
  }
39253
39341
  };
@@ -39362,11 +39450,6 @@ _:patch
39362
39450
  */
39363
39451
  async fetch(uri6) {
39364
39452
  const response6 = await this.fetcher.load(namedNode2(uri6), {
39365
- // force fetching due to
39366
- // https://github.com/linkeddata/rdflib.js/issues/247
39367
- // and
39368
- // https://github.com/linkeddata/rdflib.js/issues/441
39369
- force: true,
39370
39453
  // explicitly omit credentials due to
39371
39454
  // https://github.com/pod-os/PodOS/issues/17
39372
39455
  credentials: "omit"
@@ -39380,7 +39463,6 @@ _:patch
39380
39463
  if (descriptionResourceUri) {
39381
39464
  try {
39382
39465
  await this.fetcher.load(namedNode2(descriptionResourceUri.value), {
39383
- force: true,
39384
39466
  credentials: "omit"
39385
39467
  });
39386
39468
  } catch {
@@ -39422,6 +39504,33 @@ _:patch
39422
39504
  st(namedNode2(thing.uri), namedNode2(property4), lit(value8), namedNode2(docUrl))
39423
39505
  );
39424
39506
  }
39507
+ /**
39508
+ * Updates the value of the given property of the given thing to the new value
39509
+ * @param thing
39510
+ * @param property
39511
+ * @param oldValue
39512
+ * @param newValue
39513
+ */
39514
+ async editPropertyValue(thing, property4, oldValue, newValue) {
39515
+ const docUrl = this.determineDocumentToUpdate(thing);
39516
+ const remove = st(
39517
+ namedNode2(thing.uri),
39518
+ namedNode2(property4),
39519
+ lit(oldValue),
39520
+ namedNode2(docUrl)
39521
+ );
39522
+ const insert = st(
39523
+ namedNode2(thing.uri),
39524
+ namedNode2(property4),
39525
+ lit(newValue),
39526
+ namedNode2(docUrl)
39527
+ );
39528
+ return this.updater.update([remove], [insert], void 0, false, {
39529
+ // explicitly omit credentials due to
39530
+ // https://github.com/pod-os/PodOS/issues/17
39531
+ credentials: "omit"
39532
+ });
39533
+ }
39425
39534
  insert(statement2) {
39426
39535
  return this.updater.update([], [statement2], void 0, false, {
39427
39536
  // explicitly omit credentials due to
@@ -61613,14 +61722,18 @@ _:patch
61613
61722
  onlineStatus,
61614
61723
  internalStore
61615
61724
  );
61616
- this.searchGateway = new SearchGateway(this.store);
61725
+ this.profileGateway = new ProfileGateway(this.store);
61726
+ this.searchGateway = new SearchGateway(
61727
+ this.store,
61728
+ this.session,
61729
+ this.profileGateway
61730
+ );
61617
61731
  this.fileFetcher = new FileFetcher(this.session);
61618
61732
  this.fileGateway = new FileGateway(this.store, this.fileFetcher);
61619
61733
  this.attachmentGateway = new AttachmentGateway(this.fileGateway);
61620
61734
  this.pictureGateway = new PictureGateway(this.fileGateway);
61621
61735
  this.flagAuthorizationMetaDataOnSessionChange();
61622
61736
  this.uriService = new UriService(this.store);
61623
- this.profileGateway = new ProfileGateway(this.store);
61624
61737
  }
61625
61738
  /*
61626
61739
  Flagging authorization metadata is necessary every time the user
@@ -61633,6 +61746,7 @@ _:patch
61633
61746
  this.session.observeSession().pipe(
61634
61747
  tap(() => {
61635
61748
  this.store.flagAuthorizationMetadata();
61749
+ this.searchGateway.clear();
61636
61750
  })
61637
61751
  ).subscribe();
61638
61752
  }
@@ -61666,6 +61780,16 @@ _:patch
61666
61780
  addPropertyValue(thing, property4, value8) {
61667
61781
  return this.store.addPropertyValue(thing, property4, value8);
61668
61782
  }
61783
+ /**
61784
+ * Updates the value of the given property of the given thing to the new value
61785
+ * @param thing
61786
+ * @param property
61787
+ * @param oldValue
61788
+ * @param newValue
61789
+ */
61790
+ editPropertyValue(thing, property4, oldValue, newValue) {
61791
+ return this.store.editPropertyValue(thing, property4, oldValue, newValue);
61792
+ }
61669
61793
  /**
61670
61794
  * Adds a new relation (link) from the thing to the given uri using the property
61671
61795
  * @param thing
@@ -61698,11 +61822,15 @@ _:patch
61698
61822
  return this.profileGateway.fetchProfile(webId);
61699
61823
  }
61700
61824
  /**
61701
- * Fetch the private label index for the given profile and build a search index from it
61702
- * @param profile
61825
+ * Build the search index on demand.
61826
+ *
61827
+ * While logged in, the index is built from the logged-in user's label indexes
61828
+ * and cached, so repeated calls return the same instance.
61829
+ *
61830
+ * While logged out, a fresh empty index is returned that is not cached.
61703
61831
  */
61704
- async buildSearchIndex(profile2) {
61705
- return this.searchGateway.buildSearchIndex(profile2);
61832
+ async buildSearchIndex() {
61833
+ return this.searchGateway.buildSearchIndex();
61706
61834
  }
61707
61835
  logout() {
61708
61836
  this.offlineCache.clear();
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.33.0-rc.fae4f86.0",
4
+ "version": "0.34.0-rc.2a1133e.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./types/index.d.ts",
@@ -30,8 +30,7 @@
30
30
  "build:types": "rimraf types && tsc --emitDeclarationOnly --outDir types",
31
31
  "build:types:watch": "rimraf types && tsc --emitDeclarationOnly --outDir types --watch",
32
32
  "build:watch": "node esbuild/watch-esm.mjs",
33
- "build:doc": "typedoc --gitRevision main",
34
- "postbuild:doc": "./scripts/postprocess-typedoc.sh",
33
+ "build:doc": "typedoc --gitRevision main && ./scripts/postprocess-typedoc.sh",
35
34
  "dev": "run-p build:types:watch build:watch",
36
35
  "build": " npm run build:bundle && npm run build:types && npm run build:esm"
37
36
  },
@@ -50,14 +49,14 @@
50
49
  "esbuild": "^0.28.2",
51
50
  "eslint": "^9.39.5",
52
51
  "npm-run-all": "^4.1.5",
53
- "prettier": "^3.9.6",
52
+ "prettier": "^3.9.9",
54
53
  "rimraf": "^6.1.3",
55
54
  "sparqljs": "^3.7.4",
56
55
  "typedoc": "^0.28.20",
57
- "typedoc-plugin-markdown": "^4.12.0",
56
+ "typedoc-plugin-markdown": "^4.14.0",
58
57
  "typescript": "^6.0.3",
59
- "typescript-eslint": "^8.67.0",
60
- "vitest": "^4.1.10",
58
+ "typescript-eslint": "^8.71.0",
59
+ "vitest": "^4.1.11",
61
60
  "vitest-when": "^0.10.0"
62
61
  },
63
62
  "dependencies": {
@@ -65,10 +64,10 @@
65
64
  "@types/lunr": "^2.3.7",
66
65
  "buffer": "^6.0.3",
67
66
  "lunr": "^2.3.9",
68
- "mime": "^4.1.0",
67
+ "mime": "^4.1.1",
69
68
  "neverthrow": "^8.2.0",
70
69
  "rdf-namespaces": "^1.17.0",
71
- "rdflib": "2.4.0",
70
+ "rdflib": "2.4.1",
72
71
  "rxjs": "^7.8.2",
73
72
  "slugify": "^1.6.9",
74
73
  "url": "^0.11.4",
package/types/Store.d.ts CHANGED
@@ -42,6 +42,14 @@ export declare class Store {
42
42
  * @param value
43
43
  */
44
44
  addPropertyValue(thing: Thing, property: string, value: string): Promise<void>;
45
+ /**
46
+ * Updates the value of the given property of the given thing to the new value
47
+ * @param thing
48
+ * @param property
49
+ * @param oldValue
50
+ * @param newValue
51
+ */
52
+ editPropertyValue(thing: Thing, property: string, oldValue: string, newValue: string): Promise<void>;
45
53
  private insert;
46
54
  /**
47
55
  * Adds a new relation (link) from the thing to the given uri using the property
package/types/index.d.ts CHANGED
@@ -68,6 +68,14 @@ export declare class PodOS {
68
68
  * @param value
69
69
  */
70
70
  addPropertyValue(thing: Thing, property: string, value: string): Promise<void>;
71
+ /**
72
+ * Updates the value of the given property of the given thing to the new value
73
+ * @param thing
74
+ * @param property
75
+ * @param oldValue
76
+ * @param newValue
77
+ */
78
+ editPropertyValue(thing: Thing, property: string, oldValue: string, newValue: string): Promise<void>;
71
79
  /**
72
80
  * Adds a new relation (link) from the thing to the given uri using the property
73
81
  * @param thing
@@ -88,10 +96,14 @@ export declare class PodOS {
88
96
  */
89
97
  fetchProfile(webId: string): Promise<WebIdProfile>;
90
98
  /**
91
- * Fetch the private label index for the given profile and build a search index from it
92
- * @param profile
99
+ * Build the search index on demand.
100
+ *
101
+ * While logged in, the index is built from the logged-in user's label indexes
102
+ * and cached, so repeated calls return the same instance.
103
+ *
104
+ * While logged out, a fresh empty index is returned that is not cached.
93
105
  */
94
- buildSearchIndex(profile: WebIdProfile): Promise<import("./search").SearchIndex>;
106
+ buildSearchIndex(): Promise<import("./search").SearchIndex>;
95
107
  logout(): Promise<void>;
96
108
  login(oidcIssuer?: string): Promise<void>;
97
109
  /**
@@ -1,16 +1,35 @@
1
1
  import { WebIdProfile } from "../profile";
2
+ import { ProfileGateway } from "../profile";
2
3
  import { Store } from "../Store";
3
4
  import { LabelIndex } from "./LabelIndex";
5
+ import { PodOsSession } from "../authentication";
4
6
  import { Thing } from "../thing";
5
7
  import { SearchIndex } from "./SearchIndex";
6
8
  export declare class SearchGateway {
7
9
  private readonly store;
8
- constructor(store: Store);
10
+ private readonly profileGateway;
11
+ private readonly session;
12
+ private cached?;
13
+ constructor(store: Store, session: PodOsSession, profileGateway: ProfileGateway);
9
14
  /**
10
- * Fetch the private label index for the given profile and build a search index from it
11
- * @param profile
15
+ * Build a search index on demand.
16
+ *
17
+ * While logged in, the profile is resolved from the current session's webId
18
+ * and the index is built from the profile's label indexes and cached, so that
19
+ * repeated calls return the same instance.
20
+ *
21
+ * While logged out, a fresh empty index is returned that is NOT cached —
22
+ * the next call after login is a cache miss and builds.
12
23
  */
13
- buildSearchIndex(profile: WebIdProfile): Promise<SearchIndex>;
24
+ buildSearchIndex(): Promise<SearchIndex>;
25
+ /**
26
+ * Empties the cached search index in place and drops the cache reference, so
27
+ * that consumers already holding the instance see an empty index immediately
28
+ * and the next call to {@link buildSearchIndex} builds a new index.
29
+ */
30
+ clear(): void;
31
+ private buildIndex;
32
+ private resolveLabelIndexes;
14
33
  addToLabelIndex(thing: Thing, labelIndex: LabelIndex): Promise<void>;
15
34
  createDefaultLabelIndex(profile: WebIdProfile): Promise<LabelIndex>;
16
35
  }
@@ -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
  *