@pod-os/core 0.34.0-rc.913c85c.0 → 0.34.0-rc.aff4dc6.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) {
@@ -30796,15 +30830,30 @@ var addToLabelIndex = (thing, labelIndex) => {
30796
30830
 
30797
30831
  // src/search/SearchGateway.ts
30798
30832
  var SearchGateway = class {
30799
- constructor(store) {
30833
+ constructor(store, session4, profileGateway) {
30800
30834
  this.store = store;
30835
+ this.session = session4;
30836
+ this.profileGateway = profileGateway;
30801
30837
  }
30802
30838
  /**
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.
30805
- * @param profile
30839
+ * Build a search index on demand.
30840
+ *
30841
+ * While logged in, the profile is resolved from the current session's webId
30842
+ * and the index is built from the profile's label indexes and cached, so that
30843
+ * repeated calls return the same instance.
30844
+ *
30845
+ * While logged out, a fresh empty index is returned that is NOT cached —
30846
+ * the next call after login is a cache miss and builds.
30806
30847
  */
30807
- async buildSearchIndex(profile2) {
30848
+ async buildSearchIndex() {
30849
+ const session4 = await lastValueFrom(
30850
+ this.session.observeSession().pipe(take(1))
30851
+ );
30852
+ if (!session4.isLoggedIn) {
30853
+ return new SearchIndex([]);
30854
+ }
30855
+ const webId = session4.webId;
30856
+ const profile2 = await this.profileGateway.fetchProfile(webId);
30808
30857
  if (!this.cached) {
30809
30858
  const labelIndexUris = profile2.getPrivateLabelIndexes();
30810
30859
  this.cached = await this.buildIndex(labelIndexUris);
@@ -30812,10 +30861,12 @@ var SearchGateway = class {
30812
30861
  return this.cached;
30813
30862
  }
30814
30863
  /**
30815
- * Clears the cached search index, so that the next call to {@link buildSearchIndex}
30816
- * builds a new index.
30864
+ * Empties the cached search index in place and drops the cache reference, so
30865
+ * that consumers already holding the instance see an empty index immediately
30866
+ * and the next call to {@link buildSearchIndex} builds a new index.
30817
30867
  */
30818
30868
  clear() {
30869
+ this.cached?.clear();
30819
30870
  this.cached = void 0;
30820
30871
  }
30821
30872
  async buildIndex(labelIndexUris) {
@@ -30956,11 +31007,6 @@ var Store = class {
30956
31007
  */
30957
31008
  async fetch(uri6) {
30958
31009
  const response6 = await this.fetcher.load(namedNode2(uri6), {
30959
- // force fetching due to
30960
- // https://github.com/linkeddata/rdflib.js/issues/247
30961
- // and
30962
- // https://github.com/linkeddata/rdflib.js/issues/441
30963
- force: true,
30964
31010
  // explicitly omit credentials due to
30965
31011
  // https://github.com/pod-os/PodOS/issues/17
30966
31012
  credentials: "omit"
@@ -30974,7 +31020,6 @@ var Store = class {
30974
31020
  if (descriptionResourceUri) {
30975
31021
  try {
30976
31022
  await this.fetcher.load(namedNode2(descriptionResourceUri.value), {
30977
- force: true,
30978
31023
  credentials: "omit"
30979
31024
  });
30980
31025
  } catch {
@@ -53234,14 +53279,18 @@ var PodOS = class {
53234
53279
  onlineStatus,
53235
53280
  internalStore
53236
53281
  );
53237
- this.searchGateway = new SearchGateway(this.store);
53282
+ this.profileGateway = new ProfileGateway(this.store);
53283
+ this.searchGateway = new SearchGateway(
53284
+ this.store,
53285
+ this.session,
53286
+ this.profileGateway
53287
+ );
53238
53288
  this.fileFetcher = new FileFetcher(this.session);
53239
53289
  this.fileGateway = new FileGateway(this.store, this.fileFetcher);
53240
53290
  this.attachmentGateway = new AttachmentGateway(this.fileGateway);
53241
53291
  this.pictureGateway = new PictureGateway(this.fileGateway);
53242
53292
  this.flagAuthorizationMetaDataOnSessionChange();
53243
53293
  this.uriService = new UriService(this.store);
53244
- this.profileGateway = new ProfileGateway(this.store);
53245
53294
  }
53246
53295
  /*
53247
53296
  Flagging authorization metadata is necessary every time the user
@@ -53330,11 +53379,15 @@ var PodOS = class {
53330
53379
  return this.profileGateway.fetchProfile(webId);
53331
53380
  }
53332
53381
  /**
53333
- * Fetch the private label index for the given profile and build a search index from it
53334
- * @param profile
53382
+ * Build the search index on demand.
53383
+ *
53384
+ * While logged in, the index is built from the logged-in user's label indexes
53385
+ * and cached, so repeated calls return the same instance.
53386
+ *
53387
+ * While logged out, a fresh empty index is returned that is not cached.
53335
53388
  */
53336
- async buildSearchIndex(profile2) {
53337
- return this.searchGateway.buildSearchIndex(profile2);
53389
+ async buildSearchIndex() {
53390
+ return this.searchGateway.buildSearchIndex();
53338
53391
  }
53339
53392
  logout() {
53340
53393
  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) {
@@ -39238,15 +39272,30 @@ _:patch
39238
39272
 
39239
39273
  // src/search/SearchGateway.ts
39240
39274
  var SearchGateway = class {
39241
- constructor(store) {
39275
+ constructor(store, session4, profileGateway) {
39242
39276
  this.store = store;
39277
+ this.session = session4;
39278
+ this.profileGateway = profileGateway;
39243
39279
  }
39244
39280
  /**
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.
39247
- * @param profile
39281
+ * Build a search index on demand.
39282
+ *
39283
+ * While logged in, the profile is resolved from the current session's webId
39284
+ * and the index is built from the profile's label indexes and cached, so that
39285
+ * repeated calls return the same instance.
39286
+ *
39287
+ * While logged out, a fresh empty index is returned that is NOT cached —
39288
+ * the next call after login is a cache miss and builds.
39248
39289
  */
39249
- async buildSearchIndex(profile2) {
39290
+ async buildSearchIndex() {
39291
+ const session4 = await lastValueFrom(
39292
+ this.session.observeSession().pipe(take(1))
39293
+ );
39294
+ if (!session4.isLoggedIn) {
39295
+ return new SearchIndex([]);
39296
+ }
39297
+ const webId = session4.webId;
39298
+ const profile2 = await this.profileGateway.fetchProfile(webId);
39250
39299
  if (!this.cached) {
39251
39300
  const labelIndexUris = profile2.getPrivateLabelIndexes();
39252
39301
  this.cached = await this.buildIndex(labelIndexUris);
@@ -39254,10 +39303,12 @@ _:patch
39254
39303
  return this.cached;
39255
39304
  }
39256
39305
  /**
39257
- * Clears the cached search index, so that the next call to {@link buildSearchIndex}
39258
- * builds a new index.
39306
+ * Empties the cached search index in place and drops the cache reference, so
39307
+ * that consumers already holding the instance see an empty index immediately
39308
+ * and the next call to {@link buildSearchIndex} builds a new index.
39259
39309
  */
39260
39310
  clear() {
39311
+ this.cached?.clear();
39261
39312
  this.cached = void 0;
39262
39313
  }
39263
39314
  async buildIndex(labelIndexUris) {
@@ -39398,11 +39449,6 @@ _:patch
39398
39449
  */
39399
39450
  async fetch(uri6) {
39400
39451
  const response6 = await this.fetcher.load(namedNode2(uri6), {
39401
- // force fetching due to
39402
- // https://github.com/linkeddata/rdflib.js/issues/247
39403
- // and
39404
- // https://github.com/linkeddata/rdflib.js/issues/441
39405
- force: true,
39406
39452
  // explicitly omit credentials due to
39407
39453
  // https://github.com/pod-os/PodOS/issues/17
39408
39454
  credentials: "omit"
@@ -39416,7 +39462,6 @@ _:patch
39416
39462
  if (descriptionResourceUri) {
39417
39463
  try {
39418
39464
  await this.fetcher.load(namedNode2(descriptionResourceUri.value), {
39419
- force: true,
39420
39465
  credentials: "omit"
39421
39466
  });
39422
39467
  } catch {
@@ -61676,14 +61721,18 @@ _:patch
61676
61721
  onlineStatus,
61677
61722
  internalStore
61678
61723
  );
61679
- this.searchGateway = new SearchGateway(this.store);
61724
+ this.profileGateway = new ProfileGateway(this.store);
61725
+ this.searchGateway = new SearchGateway(
61726
+ this.store,
61727
+ this.session,
61728
+ this.profileGateway
61729
+ );
61680
61730
  this.fileFetcher = new FileFetcher(this.session);
61681
61731
  this.fileGateway = new FileGateway(this.store, this.fileFetcher);
61682
61732
  this.attachmentGateway = new AttachmentGateway(this.fileGateway);
61683
61733
  this.pictureGateway = new PictureGateway(this.fileGateway);
61684
61734
  this.flagAuthorizationMetaDataOnSessionChange();
61685
61735
  this.uriService = new UriService(this.store);
61686
- this.profileGateway = new ProfileGateway(this.store);
61687
61736
  }
61688
61737
  /*
61689
61738
  Flagging authorization metadata is necessary every time the user
@@ -61772,11 +61821,15 @@ _:patch
61772
61821
  return this.profileGateway.fetchProfile(webId);
61773
61822
  }
61774
61823
  /**
61775
- * Fetch the private label index for the given profile and build a search index from it
61776
- * @param profile
61824
+ * Build the search index on demand.
61825
+ *
61826
+ * While logged in, the index is built from the logged-in user's label indexes
61827
+ * and cached, so repeated calls return the same instance.
61828
+ *
61829
+ * While logged out, a fresh empty index is returned that is not cached.
61777
61830
  */
61778
- async buildSearchIndex(profile2) {
61779
- return this.searchGateway.buildSearchIndex(profile2);
61831
+ async buildSearchIndex() {
61832
+ return this.searchGateway.buildSearchIndex();
61780
61833
  }
61781
61834
  logout() {
61782
61835
  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.34.0-rc.913c85c.0",
4
+ "version": "0.34.0-rc.aff4dc6.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -96,10 +96,14 @@ export declare class PodOS {
96
96
  */
97
97
  fetchProfile(webId: string): Promise<WebIdProfile>;
98
98
  /**
99
- * Fetch the private label index for the given profile and build a search index from it
100
- * @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.
101
105
  */
102
- buildSearchIndex(profile: WebIdProfile): Promise<import("./search").SearchIndex>;
106
+ buildSearchIndex(): Promise<import("./search").SearchIndex>;
103
107
  logout(): Promise<void>;
104
108
  login(oidcIssuer?: string): Promise<void>;
105
109
  /**
@@ -1,21 +1,31 @@
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;
10
+ private readonly profileGateway;
11
+ private readonly session;
8
12
  private cached?;
9
- constructor(store: Store);
13
+ constructor(store: Store, session: PodOsSession, profileGateway: ProfileGateway);
10
14
  /**
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.
13
- * @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.
14
23
  */
15
- buildSearchIndex(profile: WebIdProfile): Promise<SearchIndex>;
24
+ buildSearchIndex(): Promise<SearchIndex>;
16
25
  /**
17
- * Clears the cached search index, so that the next call to {@link buildSearchIndex}
18
- * builds a new index.
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.
19
29
  */
20
30
  clear(): void;
21
31
  private buildIndex;