@pod-os/core 0.34.0-rc.a31f2a2.0 → 0.34.0-rc.b7663ff.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 +128 -38
- package/lib/index.js +128 -38
- package/package.json +3 -3
- package/types/index.d.ts +7 -3
- package/types/search/SearchGateway.d.ts +23 -4
- package/types/search/SearchGateway.spec.d.ts +1 -0
- package/types/search/SearchIndex.d.ts +4 -3
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) {
|
|
@@ -20100,7 +20134,7 @@ var Serializer = class _Serializer {
|
|
|
20100
20134
|
return self2.atomicTermToN3(x);
|
|
20101
20135
|
}
|
|
20102
20136
|
var list = x.elements;
|
|
20103
|
-
var rest3 = kb.sym(rdfns + "
|
|
20137
|
+
var rest3 = kb.sym(rdfns + "nil");
|
|
20104
20138
|
for (var i2 = list.length - 1; i2 >= 0; i2--) {
|
|
20105
20139
|
var bnode = factory.blankNode();
|
|
20106
20140
|
str += termToNT(bnode) + " " + termToNT(kb.sym(rdfns + "first")) + " " + termToNT(list[i2]) + ".\n";
|
|
@@ -20410,7 +20444,7 @@ var Serializer = class _Serializer {
|
|
|
20410
20444
|
var canSplit = !namespaceIsBaseDir && !forbidDotLocal && namesp.length > minNamespaceLength && this.isValidPNLocal(localid);
|
|
20411
20445
|
if (canSplit) {
|
|
20412
20446
|
if (this.defaultNamespace && this.defaultNamespace === namesp && this.flags.indexOf("d") < 0) {
|
|
20413
|
-
if (this.flags.indexOf("k") >= 0 && this.
|
|
20447
|
+
if (this.flags.indexOf("k") >= 0 && this.keywords.indexOf(localid) < 0) {
|
|
20414
20448
|
return localid;
|
|
20415
20449
|
}
|
|
20416
20450
|
return ":" + localid;
|
|
@@ -27433,7 +27467,7 @@ function parse2(str, kb, base2, contentType4 = "text/turtle", callback) {
|
|
|
27433
27467
|
contentType4 = contentType4 || TurtleContentType;
|
|
27434
27468
|
contentType4 = contentType4.split(";")[0];
|
|
27435
27469
|
try {
|
|
27436
|
-
if (contentType4 === N3ContentType || contentType4 === TurtleContentType) {
|
|
27470
|
+
if (contentType4 === N3ContentType || contentType4 === TurtleContentType || contentType4 === NTriplesContentType) {
|
|
27437
27471
|
var p = n3parser_default(kb, kb, base2, base2, null, null, "", null);
|
|
27438
27472
|
p.loadBuf(str);
|
|
27439
27473
|
executeCallback();
|
|
@@ -27479,7 +27513,8 @@ function parse2(str, kb, base2, contentType4 = "text/turtle", callback) {
|
|
|
27479
27513
|
"application/sparql-update-single-match": true,
|
|
27480
27514
|
"application/ld+json": true,
|
|
27481
27515
|
"application/nquads": true,
|
|
27482
|
-
"application/n-quads": true
|
|
27516
|
+
"application/n-quads": true,
|
|
27517
|
+
"application/n-triples": true
|
|
27483
27518
|
};
|
|
27484
27519
|
function executeCallback() {
|
|
27485
27520
|
if (callback) {
|
|
@@ -28013,16 +28048,25 @@ var Fetcher = class _Fetcher {
|
|
|
28013
28048
|
options = this.initFetchOptions(docuri, options);
|
|
28014
28049
|
const meta2 = this.appNode;
|
|
28015
28050
|
const kb = this.store;
|
|
28016
|
-
const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.
|
|
28051
|
+
const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.rdfFactory.literal(docuri), meta2).map((st2) => st2.subject);
|
|
28052
|
+
let answered = false;
|
|
28053
|
+
let usableAnswer = false;
|
|
28017
28054
|
for (const request2 of requests) {
|
|
28018
28055
|
const response6 = kb.any(request2, this.ns.link("response"), null, meta2);
|
|
28019
|
-
if (response6
|
|
28020
|
-
|
|
28021
|
-
|
|
28022
|
-
|
|
28023
|
-
|
|
28056
|
+
if (response6 == null) {
|
|
28057
|
+
continue;
|
|
28058
|
+
}
|
|
28059
|
+
answered = true;
|
|
28060
|
+
const outOfDate = kb.anyJS(response6, this.ns.link("outOfDate"), null, meta2);
|
|
28061
|
+
if (!outOfDate) {
|
|
28062
|
+
usableAnswer = true;
|
|
28063
|
+
break;
|
|
28024
28064
|
}
|
|
28025
28065
|
}
|
|
28066
|
+
if (answered && !usableAnswer) {
|
|
28067
|
+
options.force = true;
|
|
28068
|
+
options.clearPreviousData = true;
|
|
28069
|
+
}
|
|
28026
28070
|
const initialisedOptions = this.initFetchOptions(docuri, options);
|
|
28027
28071
|
return this.pendingFetchPromise(docuri, initialisedOptions.baseURI, initialisedOptions);
|
|
28028
28072
|
}
|
|
@@ -30574,16 +30618,20 @@ var SearchIndex = class {
|
|
|
30574
30618
|
this.index = this.rebuild().index;
|
|
30575
30619
|
}
|
|
30576
30620
|
/**
|
|
30577
|
-
* Recreates the search index with the current data from all label indexes
|
|
30621
|
+
* Recreates the search index with the current data from all label indexes.
|
|
30622
|
+
* Optionally replaces the captured label indexes before rebuilding.
|
|
30578
30623
|
*/
|
|
30579
|
-
rebuild() {
|
|
30580
|
-
|
|
30624
|
+
rebuild(labelIndexes) {
|
|
30625
|
+
if (labelIndexes) {
|
|
30626
|
+
this.labelIndexes = labelIndexes;
|
|
30627
|
+
}
|
|
30628
|
+
const captured = this.labelIndexes;
|
|
30581
30629
|
this.index = (0, import_lunr.default)(function() {
|
|
30582
30630
|
this.ref("uri");
|
|
30583
30631
|
this.field("uri");
|
|
30584
30632
|
this.field("label");
|
|
30585
30633
|
this.metadataWhitelist = ["position"];
|
|
30586
|
-
const items2 =
|
|
30634
|
+
const items2 = captured.flatMap((it) => it.getIndexedItems());
|
|
30587
30635
|
items2.forEach((item4) => {
|
|
30588
30636
|
this.add({
|
|
30589
30637
|
uri: item4.uri,
|
|
@@ -30782,30 +30830,69 @@ var addToLabelIndex = (thing, labelIndex) => {
|
|
|
30782
30830
|
|
|
30783
30831
|
// src/search/SearchGateway.ts
|
|
30784
30832
|
var SearchGateway = class {
|
|
30785
|
-
constructor(store) {
|
|
30833
|
+
constructor(store, session4, profileGateway) {
|
|
30786
30834
|
this.store = store;
|
|
30835
|
+
this.session = session4;
|
|
30836
|
+
this.profileGateway = profileGateway;
|
|
30787
30837
|
}
|
|
30788
30838
|
/**
|
|
30789
|
-
*
|
|
30790
|
-
*
|
|
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.
|
|
30791
30847
|
*/
|
|
30792
|
-
async buildSearchIndex(
|
|
30793
|
-
const
|
|
30794
|
-
|
|
30795
|
-
|
|
30796
|
-
|
|
30797
|
-
|
|
30798
|
-
);
|
|
30799
|
-
return new SearchIndex(labelIndex);
|
|
30848
|
+
async buildSearchIndex() {
|
|
30849
|
+
const session4 = await lastValueFrom(
|
|
30850
|
+
this.session.observeSession().pipe(take(1))
|
|
30851
|
+
);
|
|
30852
|
+
if (!session4.isLoggedIn) {
|
|
30853
|
+
return new SearchIndex([]);
|
|
30800
30854
|
}
|
|
30801
|
-
|
|
30855
|
+
const webId = session4.webId;
|
|
30856
|
+
const profile2 = await this.profileGateway.fetchProfile(webId);
|
|
30857
|
+
if (!this.cached) {
|
|
30858
|
+
const labelIndexUris = profile2.getPrivateLabelIndexes();
|
|
30859
|
+
this.cached = await this.buildIndex(labelIndexUris);
|
|
30860
|
+
}
|
|
30861
|
+
return this.cached;
|
|
30862
|
+
}
|
|
30863
|
+
/**
|
|
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.
|
|
30867
|
+
*/
|
|
30868
|
+
clear() {
|
|
30869
|
+
this.cached?.clear();
|
|
30870
|
+
this.cached = void 0;
|
|
30871
|
+
}
|
|
30872
|
+
async buildIndex(labelIndexUris) {
|
|
30873
|
+
const labelIndex = await this.resolveLabelIndexes(labelIndexUris);
|
|
30874
|
+
return new SearchIndex(labelIndex);
|
|
30875
|
+
}
|
|
30876
|
+
async resolveLabelIndexes(labelIndexUris) {
|
|
30877
|
+
await this.store.fetchAll(labelIndexUris);
|
|
30878
|
+
return labelIndexUris.map(
|
|
30879
|
+
(uri6) => this.store.get(uri6).assume(LabelIndex)
|
|
30880
|
+
);
|
|
30802
30881
|
}
|
|
30803
30882
|
async addToLabelIndex(thing, labelIndex) {
|
|
30804
30883
|
await this.store.executeUpdate(addToLabelIndex(thing, labelIndex));
|
|
30884
|
+
if (this.cached) {
|
|
30885
|
+
this.cached.rebuild();
|
|
30886
|
+
}
|
|
30805
30887
|
}
|
|
30806
30888
|
async createDefaultLabelIndex(profile2) {
|
|
30807
30889
|
const operation3 = createDefaultLabelIndex(profile2);
|
|
30808
30890
|
await this.store.executeUpdate(operation3);
|
|
30891
|
+
if (this.cached) {
|
|
30892
|
+
this.cached.rebuild(
|
|
30893
|
+
await this.resolveLabelIndexes(profile2.getPrivateLabelIndexes())
|
|
30894
|
+
);
|
|
30895
|
+
}
|
|
30809
30896
|
return this.store.get(operation3.uri).assume(LabelIndex);
|
|
30810
30897
|
}
|
|
30811
30898
|
};
|
|
@@ -30920,11 +31007,6 @@ var Store = class {
|
|
|
30920
31007
|
*/
|
|
30921
31008
|
async fetch(uri6) {
|
|
30922
31009
|
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
31010
|
// explicitly omit credentials due to
|
|
30929
31011
|
// https://github.com/pod-os/PodOS/issues/17
|
|
30930
31012
|
credentials: "omit"
|
|
@@ -30938,7 +31020,6 @@ var Store = class {
|
|
|
30938
31020
|
if (descriptionResourceUri) {
|
|
30939
31021
|
try {
|
|
30940
31022
|
await this.fetcher.load(namedNode2(descriptionResourceUri.value), {
|
|
30941
|
-
force: true,
|
|
30942
31023
|
credentials: "omit"
|
|
30943
31024
|
});
|
|
30944
31025
|
} catch {
|
|
@@ -53198,14 +53279,18 @@ var PodOS = class {
|
|
|
53198
53279
|
onlineStatus,
|
|
53199
53280
|
internalStore
|
|
53200
53281
|
);
|
|
53201
|
-
this.
|
|
53282
|
+
this.profileGateway = new ProfileGateway(this.store);
|
|
53283
|
+
this.searchGateway = new SearchGateway(
|
|
53284
|
+
this.store,
|
|
53285
|
+
this.session,
|
|
53286
|
+
this.profileGateway
|
|
53287
|
+
);
|
|
53202
53288
|
this.fileFetcher = new FileFetcher(this.session);
|
|
53203
53289
|
this.fileGateway = new FileGateway(this.store, this.fileFetcher);
|
|
53204
53290
|
this.attachmentGateway = new AttachmentGateway(this.fileGateway);
|
|
53205
53291
|
this.pictureGateway = new PictureGateway(this.fileGateway);
|
|
53206
53292
|
this.flagAuthorizationMetaDataOnSessionChange();
|
|
53207
53293
|
this.uriService = new UriService(this.store);
|
|
53208
|
-
this.profileGateway = new ProfileGateway(this.store);
|
|
53209
53294
|
}
|
|
53210
53295
|
/*
|
|
53211
53296
|
Flagging authorization metadata is necessary every time the user
|
|
@@ -53218,6 +53303,7 @@ var PodOS = class {
|
|
|
53218
53303
|
this.session.observeSession().pipe(
|
|
53219
53304
|
tap(() => {
|
|
53220
53305
|
this.store.flagAuthorizationMetadata();
|
|
53306
|
+
this.searchGateway.clear();
|
|
53221
53307
|
})
|
|
53222
53308
|
).subscribe();
|
|
53223
53309
|
}
|
|
@@ -53293,11 +53379,15 @@ var PodOS = class {
|
|
|
53293
53379
|
return this.profileGateway.fetchProfile(webId);
|
|
53294
53380
|
}
|
|
53295
53381
|
/**
|
|
53296
|
-
*
|
|
53297
|
-
*
|
|
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.
|
|
53298
53388
|
*/
|
|
53299
|
-
async buildSearchIndex(
|
|
53300
|
-
return this.searchGateway.buildSearchIndex(
|
|
53389
|
+
async buildSearchIndex() {
|
|
53390
|
+
return this.searchGateway.buildSearchIndex();
|
|
53301
53391
|
}
|
|
53302
53392
|
logout() {
|
|
53303
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) {
|
|
@@ -28542,7 +28576,7 @@ var PodOS = (() => {
|
|
|
28542
28576
|
return self2.atomicTermToN3(x);
|
|
28543
28577
|
}
|
|
28544
28578
|
var list = x.elements;
|
|
28545
|
-
var rest3 = kb.sym(rdfns + "
|
|
28579
|
+
var rest3 = kb.sym(rdfns + "nil");
|
|
28546
28580
|
for (var i2 = list.length - 1; i2 >= 0; i2--) {
|
|
28547
28581
|
var bnode = factory.blankNode();
|
|
28548
28582
|
str += termToNT(bnode) + " " + termToNT(kb.sym(rdfns + "first")) + " " + termToNT(list[i2]) + ".\n";
|
|
@@ -28852,7 +28886,7 @@ var PodOS = (() => {
|
|
|
28852
28886
|
var canSplit = !namespaceIsBaseDir && !forbidDotLocal && namesp.length > minNamespaceLength && this.isValidPNLocal(localid);
|
|
28853
28887
|
if (canSplit) {
|
|
28854
28888
|
if (this.defaultNamespace && this.defaultNamespace === namesp && this.flags.indexOf("d") < 0) {
|
|
28855
|
-
if (this.flags.indexOf("k") >= 0 && this.
|
|
28889
|
+
if (this.flags.indexOf("k") >= 0 && this.keywords.indexOf(localid) < 0) {
|
|
28856
28890
|
return localid;
|
|
28857
28891
|
}
|
|
28858
28892
|
return ":" + localid;
|
|
@@ -35875,7 +35909,7 @@ var PodOS = (() => {
|
|
|
35875
35909
|
contentType4 = contentType4 || TurtleContentType;
|
|
35876
35910
|
contentType4 = contentType4.split(";")[0];
|
|
35877
35911
|
try {
|
|
35878
|
-
if (contentType4 === N3ContentType || contentType4 === TurtleContentType) {
|
|
35912
|
+
if (contentType4 === N3ContentType || contentType4 === TurtleContentType || contentType4 === NTriplesContentType) {
|
|
35879
35913
|
var p = n3parser_default(kb, kb, base2, base2, null, null, "", null);
|
|
35880
35914
|
p.loadBuf(str);
|
|
35881
35915
|
executeCallback();
|
|
@@ -35921,7 +35955,8 @@ var PodOS = (() => {
|
|
|
35921
35955
|
"application/sparql-update-single-match": true,
|
|
35922
35956
|
"application/ld+json": true,
|
|
35923
35957
|
"application/nquads": true,
|
|
35924
|
-
"application/n-quads": true
|
|
35958
|
+
"application/n-quads": true,
|
|
35959
|
+
"application/n-triples": true
|
|
35925
35960
|
};
|
|
35926
35961
|
function executeCallback() {
|
|
35927
35962
|
if (callback) {
|
|
@@ -36455,16 +36490,25 @@ var PodOS = (() => {
|
|
|
36455
36490
|
options = this.initFetchOptions(docuri, options);
|
|
36456
36491
|
const meta2 = this.appNode;
|
|
36457
36492
|
const kb = this.store;
|
|
36458
|
-
const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.
|
|
36493
|
+
const requests = kb.statementsMatching(void 0, this.ns.link("requestedURI"), kb.rdfFactory.literal(docuri), meta2).map((st2) => st2.subject);
|
|
36494
|
+
let answered = false;
|
|
36495
|
+
let usableAnswer = false;
|
|
36459
36496
|
for (const request2 of requests) {
|
|
36460
36497
|
const response6 = kb.any(request2, this.ns.link("response"), null, meta2);
|
|
36461
|
-
if (response6
|
|
36462
|
-
|
|
36463
|
-
|
|
36464
|
-
|
|
36465
|
-
|
|
36498
|
+
if (response6 == null) {
|
|
36499
|
+
continue;
|
|
36500
|
+
}
|
|
36501
|
+
answered = true;
|
|
36502
|
+
const outOfDate = kb.anyJS(response6, this.ns.link("outOfDate"), null, meta2);
|
|
36503
|
+
if (!outOfDate) {
|
|
36504
|
+
usableAnswer = true;
|
|
36505
|
+
break;
|
|
36466
36506
|
}
|
|
36467
36507
|
}
|
|
36508
|
+
if (answered && !usableAnswer) {
|
|
36509
|
+
options.force = true;
|
|
36510
|
+
options.clearPreviousData = true;
|
|
36511
|
+
}
|
|
36468
36512
|
const initialisedOptions = this.initFetchOptions(docuri, options);
|
|
36469
36513
|
return this.pendingFetchPromise(docuri, initialisedOptions.baseURI, initialisedOptions);
|
|
36470
36514
|
}
|
|
@@ -39016,16 +39060,20 @@ _:patch
|
|
|
39016
39060
|
this.index = this.rebuild().index;
|
|
39017
39061
|
}
|
|
39018
39062
|
/**
|
|
39019
|
-
* Recreates the search index with the current data from all label indexes
|
|
39063
|
+
* Recreates the search index with the current data from all label indexes.
|
|
39064
|
+
* Optionally replaces the captured label indexes before rebuilding.
|
|
39020
39065
|
*/
|
|
39021
|
-
rebuild() {
|
|
39022
|
-
|
|
39066
|
+
rebuild(labelIndexes) {
|
|
39067
|
+
if (labelIndexes) {
|
|
39068
|
+
this.labelIndexes = labelIndexes;
|
|
39069
|
+
}
|
|
39070
|
+
const captured = this.labelIndexes;
|
|
39023
39071
|
this.index = (0, import_lunr.default)(function() {
|
|
39024
39072
|
this.ref("uri");
|
|
39025
39073
|
this.field("uri");
|
|
39026
39074
|
this.field("label");
|
|
39027
39075
|
this.metadataWhitelist = ["position"];
|
|
39028
|
-
const items2 =
|
|
39076
|
+
const items2 = captured.flatMap((it) => it.getIndexedItems());
|
|
39029
39077
|
items2.forEach((item4) => {
|
|
39030
39078
|
this.add({
|
|
39031
39079
|
uri: item4.uri,
|
|
@@ -39224,30 +39272,69 @@ _:patch
|
|
|
39224
39272
|
|
|
39225
39273
|
// src/search/SearchGateway.ts
|
|
39226
39274
|
var SearchGateway = class {
|
|
39227
|
-
constructor(store) {
|
|
39275
|
+
constructor(store, session4, profileGateway) {
|
|
39228
39276
|
this.store = store;
|
|
39277
|
+
this.session = session4;
|
|
39278
|
+
this.profileGateway = profileGateway;
|
|
39229
39279
|
}
|
|
39230
39280
|
/**
|
|
39231
|
-
*
|
|
39232
|
-
*
|
|
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.
|
|
39233
39289
|
*/
|
|
39234
|
-
async buildSearchIndex(
|
|
39235
|
-
const
|
|
39236
|
-
|
|
39237
|
-
|
|
39238
|
-
|
|
39239
|
-
|
|
39240
|
-
);
|
|
39241
|
-
return new SearchIndex(labelIndex);
|
|
39290
|
+
async buildSearchIndex() {
|
|
39291
|
+
const session4 = await lastValueFrom(
|
|
39292
|
+
this.session.observeSession().pipe(take(1))
|
|
39293
|
+
);
|
|
39294
|
+
if (!session4.isLoggedIn) {
|
|
39295
|
+
return new SearchIndex([]);
|
|
39242
39296
|
}
|
|
39243
|
-
|
|
39297
|
+
const webId = session4.webId;
|
|
39298
|
+
const profile2 = await this.profileGateway.fetchProfile(webId);
|
|
39299
|
+
if (!this.cached) {
|
|
39300
|
+
const labelIndexUris = profile2.getPrivateLabelIndexes();
|
|
39301
|
+
this.cached = await this.buildIndex(labelIndexUris);
|
|
39302
|
+
}
|
|
39303
|
+
return this.cached;
|
|
39304
|
+
}
|
|
39305
|
+
/**
|
|
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.
|
|
39309
|
+
*/
|
|
39310
|
+
clear() {
|
|
39311
|
+
this.cached?.clear();
|
|
39312
|
+
this.cached = void 0;
|
|
39313
|
+
}
|
|
39314
|
+
async buildIndex(labelIndexUris) {
|
|
39315
|
+
const labelIndex = await this.resolveLabelIndexes(labelIndexUris);
|
|
39316
|
+
return new SearchIndex(labelIndex);
|
|
39317
|
+
}
|
|
39318
|
+
async resolveLabelIndexes(labelIndexUris) {
|
|
39319
|
+
await this.store.fetchAll(labelIndexUris);
|
|
39320
|
+
return labelIndexUris.map(
|
|
39321
|
+
(uri6) => this.store.get(uri6).assume(LabelIndex)
|
|
39322
|
+
);
|
|
39244
39323
|
}
|
|
39245
39324
|
async addToLabelIndex(thing, labelIndex) {
|
|
39246
39325
|
await this.store.executeUpdate(addToLabelIndex(thing, labelIndex));
|
|
39326
|
+
if (this.cached) {
|
|
39327
|
+
this.cached.rebuild();
|
|
39328
|
+
}
|
|
39247
39329
|
}
|
|
39248
39330
|
async createDefaultLabelIndex(profile2) {
|
|
39249
39331
|
const operation3 = createDefaultLabelIndex(profile2);
|
|
39250
39332
|
await this.store.executeUpdate(operation3);
|
|
39333
|
+
if (this.cached) {
|
|
39334
|
+
this.cached.rebuild(
|
|
39335
|
+
await this.resolveLabelIndexes(profile2.getPrivateLabelIndexes())
|
|
39336
|
+
);
|
|
39337
|
+
}
|
|
39251
39338
|
return this.store.get(operation3.uri).assume(LabelIndex);
|
|
39252
39339
|
}
|
|
39253
39340
|
};
|
|
@@ -39362,11 +39449,6 @@ _:patch
|
|
|
39362
39449
|
*/
|
|
39363
39450
|
async fetch(uri6) {
|
|
39364
39451
|
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
39452
|
// explicitly omit credentials due to
|
|
39371
39453
|
// https://github.com/pod-os/PodOS/issues/17
|
|
39372
39454
|
credentials: "omit"
|
|
@@ -39380,7 +39462,6 @@ _:patch
|
|
|
39380
39462
|
if (descriptionResourceUri) {
|
|
39381
39463
|
try {
|
|
39382
39464
|
await this.fetcher.load(namedNode2(descriptionResourceUri.value), {
|
|
39383
|
-
force: true,
|
|
39384
39465
|
credentials: "omit"
|
|
39385
39466
|
});
|
|
39386
39467
|
} catch {
|
|
@@ -61640,14 +61721,18 @@ _:patch
|
|
|
61640
61721
|
onlineStatus,
|
|
61641
61722
|
internalStore
|
|
61642
61723
|
);
|
|
61643
|
-
this.
|
|
61724
|
+
this.profileGateway = new ProfileGateway(this.store);
|
|
61725
|
+
this.searchGateway = new SearchGateway(
|
|
61726
|
+
this.store,
|
|
61727
|
+
this.session,
|
|
61728
|
+
this.profileGateway
|
|
61729
|
+
);
|
|
61644
61730
|
this.fileFetcher = new FileFetcher(this.session);
|
|
61645
61731
|
this.fileGateway = new FileGateway(this.store, this.fileFetcher);
|
|
61646
61732
|
this.attachmentGateway = new AttachmentGateway(this.fileGateway);
|
|
61647
61733
|
this.pictureGateway = new PictureGateway(this.fileGateway);
|
|
61648
61734
|
this.flagAuthorizationMetaDataOnSessionChange();
|
|
61649
61735
|
this.uriService = new UriService(this.store);
|
|
61650
|
-
this.profileGateway = new ProfileGateway(this.store);
|
|
61651
61736
|
}
|
|
61652
61737
|
/*
|
|
61653
61738
|
Flagging authorization metadata is necessary every time the user
|
|
@@ -61660,6 +61745,7 @@ _:patch
|
|
|
61660
61745
|
this.session.observeSession().pipe(
|
|
61661
61746
|
tap(() => {
|
|
61662
61747
|
this.store.flagAuthorizationMetadata();
|
|
61748
|
+
this.searchGateway.clear();
|
|
61663
61749
|
})
|
|
61664
61750
|
).subscribe();
|
|
61665
61751
|
}
|
|
@@ -61735,11 +61821,15 @@ _:patch
|
|
|
61735
61821
|
return this.profileGateway.fetchProfile(webId);
|
|
61736
61822
|
}
|
|
61737
61823
|
/**
|
|
61738
|
-
*
|
|
61739
|
-
*
|
|
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.
|
|
61740
61830
|
*/
|
|
61741
|
-
async buildSearchIndex(
|
|
61742
|
-
return this.searchGateway.buildSearchIndex(
|
|
61831
|
+
async buildSearchIndex() {
|
|
61832
|
+
return this.searchGateway.buildSearchIndex();
|
|
61743
61833
|
}
|
|
61744
61834
|
logout() {
|
|
61745
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.
|
|
4
|
+
"version": "0.34.0-rc.b7663ff.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./types/index.d.ts",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"rimraf": "^6.1.3",
|
|
54
54
|
"sparqljs": "^3.7.4",
|
|
55
55
|
"typedoc": "^0.28.20",
|
|
56
|
-
"typedoc-plugin-markdown": "^4.
|
|
56
|
+
"typedoc-plugin-markdown": "^4.14.0",
|
|
57
57
|
"typescript": "^6.0.3",
|
|
58
58
|
"typescript-eslint": "^8.71.0",
|
|
59
59
|
"vitest": "^4.1.11",
|
|
@@ -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.
|
|
70
|
+
"rdflib": "2.4.1",
|
|
71
71
|
"rxjs": "^7.8.2",
|
|
72
72
|
"slugify": "^1.6.9",
|
|
73
73
|
"url": "^0.11.4",
|
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
|
-
*
|
|
100
|
-
*
|
|
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(
|
|
106
|
+
buildSearchIndex(): Promise<import("./search").SearchIndex>;
|
|
103
107
|
logout(): Promise<void>;
|
|
104
108
|
login(oidcIssuer?: string): Promise<void>;
|
|
105
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
|
-
|
|
10
|
+
private readonly profileGateway;
|
|
11
|
+
private readonly session;
|
|
12
|
+
private cached?;
|
|
13
|
+
constructor(store: Store, session: PodOsSession, profileGateway: ProfileGateway);
|
|
9
14
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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(
|
|
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
|
|
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
|
*
|