@pod-os/core 0.34.0-rc.52a2c43.0 → 0.34.0-rc.8dbc7e9.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 +130 -39
- package/lib/index.js +130 -39
- package/package.json +6 -6
- 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) {
|
|
@@ -18428,7 +18462,8 @@ var Mime = class {
|
|
|
18428
18462
|
getAllExtensions(type5) {
|
|
18429
18463
|
if (typeof type5 !== "string")
|
|
18430
18464
|
return null;
|
|
18431
|
-
|
|
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 + "
|
|
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.
|
|
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.
|
|
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
|
|
28020
|
-
|
|
28021
|
-
|
|
28022
|
-
|
|
28023
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
*
|
|
30790
|
-
*
|
|
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(
|
|
30793
|
-
const
|
|
30794
|
-
|
|
30795
|
-
|
|
30796
|
-
|
|
30797
|
-
|
|
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
|
-
|
|
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 {
|
|
@@ -53198,14 +53280,18 @@ var PodOS = class {
|
|
|
53198
53280
|
onlineStatus,
|
|
53199
53281
|
internalStore
|
|
53200
53282
|
);
|
|
53201
|
-
this.
|
|
53283
|
+
this.profileGateway = new ProfileGateway(this.store);
|
|
53284
|
+
this.searchGateway = new SearchGateway(
|
|
53285
|
+
this.store,
|
|
53286
|
+
this.session,
|
|
53287
|
+
this.profileGateway
|
|
53288
|
+
);
|
|
53202
53289
|
this.fileFetcher = new FileFetcher(this.session);
|
|
53203
53290
|
this.fileGateway = new FileGateway(this.store, this.fileFetcher);
|
|
53204
53291
|
this.attachmentGateway = new AttachmentGateway(this.fileGateway);
|
|
53205
53292
|
this.pictureGateway = new PictureGateway(this.fileGateway);
|
|
53206
53293
|
this.flagAuthorizationMetaDataOnSessionChange();
|
|
53207
53294
|
this.uriService = new UriService(this.store);
|
|
53208
|
-
this.profileGateway = new ProfileGateway(this.store);
|
|
53209
53295
|
}
|
|
53210
53296
|
/*
|
|
53211
53297
|
Flagging authorization metadata is necessary every time the user
|
|
@@ -53218,6 +53304,7 @@ var PodOS = class {
|
|
|
53218
53304
|
this.session.observeSession().pipe(
|
|
53219
53305
|
tap(() => {
|
|
53220
53306
|
this.store.flagAuthorizationMetadata();
|
|
53307
|
+
this.searchGateway.clear();
|
|
53221
53308
|
})
|
|
53222
53309
|
).subscribe();
|
|
53223
53310
|
}
|
|
@@ -53293,11 +53380,15 @@ var PodOS = class {
|
|
|
53293
53380
|
return this.profileGateway.fetchProfile(webId);
|
|
53294
53381
|
}
|
|
53295
53382
|
/**
|
|
53296
|
-
*
|
|
53297
|
-
*
|
|
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.
|
|
53298
53389
|
*/
|
|
53299
|
-
async buildSearchIndex(
|
|
53300
|
-
return this.searchGateway.buildSearchIndex(
|
|
53390
|
+
async buildSearchIndex() {
|
|
53391
|
+
return this.searchGateway.buildSearchIndex();
|
|
53301
53392
|
}
|
|
53302
53393
|
logout() {
|
|
53303
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
|
-
|
|
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 + "
|
|
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.
|
|
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.
|
|
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
|
|
36462
|
-
|
|
36463
|
-
|
|
36464
|
-
|
|
36465
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
*
|
|
39232
|
-
*
|
|
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(
|
|
39235
|
-
const
|
|
39236
|
-
|
|
39237
|
-
|
|
39238
|
-
|
|
39239
|
-
|
|
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
|
-
|
|
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 {
|
|
@@ -61640,14 +61722,18 @@ _:patch
|
|
|
61640
61722
|
onlineStatus,
|
|
61641
61723
|
internalStore
|
|
61642
61724
|
);
|
|
61643
|
-
this.
|
|
61725
|
+
this.profileGateway = new ProfileGateway(this.store);
|
|
61726
|
+
this.searchGateway = new SearchGateway(
|
|
61727
|
+
this.store,
|
|
61728
|
+
this.session,
|
|
61729
|
+
this.profileGateway
|
|
61730
|
+
);
|
|
61644
61731
|
this.fileFetcher = new FileFetcher(this.session);
|
|
61645
61732
|
this.fileGateway = new FileGateway(this.store, this.fileFetcher);
|
|
61646
61733
|
this.attachmentGateway = new AttachmentGateway(this.fileGateway);
|
|
61647
61734
|
this.pictureGateway = new PictureGateway(this.fileGateway);
|
|
61648
61735
|
this.flagAuthorizationMetaDataOnSessionChange();
|
|
61649
61736
|
this.uriService = new UriService(this.store);
|
|
61650
|
-
this.profileGateway = new ProfileGateway(this.store);
|
|
61651
61737
|
}
|
|
61652
61738
|
/*
|
|
61653
61739
|
Flagging authorization metadata is necessary every time the user
|
|
@@ -61660,6 +61746,7 @@ _:patch
|
|
|
61660
61746
|
this.session.observeSession().pipe(
|
|
61661
61747
|
tap(() => {
|
|
61662
61748
|
this.store.flagAuthorizationMetadata();
|
|
61749
|
+
this.searchGateway.clear();
|
|
61663
61750
|
})
|
|
61664
61751
|
).subscribe();
|
|
61665
61752
|
}
|
|
@@ -61735,11 +61822,15 @@ _:patch
|
|
|
61735
61822
|
return this.profileGateway.fetchProfile(webId);
|
|
61736
61823
|
}
|
|
61737
61824
|
/**
|
|
61738
|
-
*
|
|
61739
|
-
*
|
|
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.
|
|
61740
61831
|
*/
|
|
61741
|
-
async buildSearchIndex(
|
|
61742
|
-
return this.searchGateway.buildSearchIndex(
|
|
61832
|
+
async buildSearchIndex() {
|
|
61833
|
+
return this.searchGateway.buildSearchIndex();
|
|
61743
61834
|
}
|
|
61744
61835
|
logout() {
|
|
61745
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.34.0-rc.
|
|
4
|
+
"version": "0.34.0-rc.8dbc7e9.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./types/index.d.ts",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"esbuild": "^0.28.2",
|
|
50
50
|
"eslint": "^9.39.5",
|
|
51
51
|
"npm-run-all": "^4.1.5",
|
|
52
|
-
"prettier": "^3.9.
|
|
52
|
+
"prettier": "^3.9.9",
|
|
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
|
-
"typescript-eslint": "^8.
|
|
58
|
+
"typescript-eslint": "^8.71.0",
|
|
59
59
|
"vitest": "^4.1.11",
|
|
60
60
|
"vitest-when": "^0.10.0"
|
|
61
61
|
},
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
"@types/lunr": "^2.3.7",
|
|
65
65
|
"buffer": "^6.0.3",
|
|
66
66
|
"lunr": "^2.3.9",
|
|
67
|
-
"mime": "^4.1.
|
|
67
|
+
"mime": "^4.1.1",
|
|
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
|
*
|