@startinblox/core 0.17.31 → 0.18.0-beta.1
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/_snowpack/pkg/autolinker.js +3515 -3367
- package/dist/_snowpack/pkg/autolinker.js.map +1 -1
- package/dist/_snowpack/pkg/common/{_baseUnary-217dffb2.js → _baseUnary-c1edb653.js} +16 -40
- package/dist/_snowpack/pkg/common/{_baseUnary-217dffb2.js.map → _baseUnary-c1edb653.js.map} +1 -1
- package/dist/_snowpack/pkg/common/{_commonjsHelpers-8c19dec8.js → _commonjsHelpers-37fa8da4.js} +6 -2
- package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js.map +1 -0
- package/dist/_snowpack/pkg/common/{decode-a4c334cf.js → decode-26fbf385.js} +38 -69
- package/dist/_snowpack/pkg/common/decode-26fbf385.js.map +1 -0
- package/dist/_snowpack/pkg/common/lit-html-3647afce.js +1104 -0
- package/dist/_snowpack/pkg/common/lit-html-3647afce.js.map +1 -0
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js +4767 -4246
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map +1 -1
- package/dist/_snowpack/pkg/dialog-polyfill.js +107 -139
- package/dist/_snowpack/pkg/dialog-polyfill.js.map +1 -1
- package/dist/_snowpack/pkg/fusejs.js +411 -601
- package/dist/_snowpack/pkg/fusejs.js.map +1 -1
- package/dist/_snowpack/pkg/jsonld-context-parser.js +718 -686
- package/dist/_snowpack/pkg/jsonld-context-parser.js.map +1 -1
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css +59 -59
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css.proxy.js +1 -1
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css +14 -14
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css.proxy.js +1 -1
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js +13 -14
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map +1 -1
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js +17 -15
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map +1 -1
- package/dist/_snowpack/pkg/lit-html/directives/until.js +45 -46
- package/dist/_snowpack/pkg/lit-html/directives/until.js.map +1 -1
- package/dist/_snowpack/pkg/lit-html.js +37 -35
- package/dist/_snowpack/pkg/lit-html.js.map +1 -1
- package/dist/_snowpack/pkg/markdown-it-link-attributes.js +1 -20
- package/dist/_snowpack/pkg/markdown-it-link-attributes.js.map +1 -1
- package/dist/_snowpack/pkg/markdown-it.js +1731 -2284
- package/dist/_snowpack/pkg/markdown-it.js.map +1 -1
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js +236 -294
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map +1 -1
- package/dist/_snowpack/pkg/quill.js +12077 -11017
- package/dist/_snowpack/pkg/quill.js.map +1 -1
- package/dist/_snowpack/pkg/slim-select.js +711 -1
- package/dist/_snowpack/pkg/slim-select.js.map +1 -1
- package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css +1 -16
- package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css.proxy.js +1 -1
- package/dist/_snowpack/pkg/tui-calendar.js +44297 -40075
- package/dist/_snowpack/pkg/tui-calendar.js.map +1 -1
- package/dist/components/solid-ac-checker.js +4 -17
- package/dist/components/solid-calendar.js +5 -26
- package/dist/components/solid-delete.js +9 -24
- package/dist/components/solid-display.js +15 -59
- package/dist/components/solid-form-search.js +27 -79
- package/dist/components/solid-form.js +48 -143
- package/dist/components/solid-lang.js +8 -19
- package/dist/components/solid-map.js +26 -64
- package/dist/components/solid-table.js +51 -133
- package/dist/components/solid-widget.js +2 -24
- package/dist/index.js +17 -11
- package/dist/libs/Component.js +4 -10
- package/dist/libs/ComponentFactory.js +6 -34
- package/dist/libs/Compositor.js +8 -15
- package/dist/libs/Sib.js +7 -21
- package/dist/libs/filter.js +184 -0
- package/dist/libs/helpers.js +19 -47
- package/dist/libs/interfaces.js +1 -1
- package/dist/libs/lit-helpers.js +7 -34
- package/dist/libs/polyfills.js +7 -10
- package/dist/libs/store/server-pagination.js +22 -0
- package/dist/libs/store/server-search.js +35 -0
- package/dist/libs/store/store.js +212 -227
- package/dist/mixins/attributeBinderMixin.js +17 -25
- package/dist/mixins/contextMixin.js +5 -7
- package/dist/mixins/counterMixin.js +2 -23
- package/dist/mixins/federationMixin.js +2 -14
- package/dist/mixins/filterMixin.js +60 -100
- package/dist/mixins/grouperMixin.js +11 -18
- package/dist/mixins/highlighterMixin.js +2 -8
- package/dist/mixins/interfaces.js +3 -5
- package/dist/mixins/listMixin.js +12 -43
- package/dist/mixins/nextMixin.js +1 -4
- package/dist/mixins/paginateMixin.js +17 -30
- package/dist/mixins/requiredMixin.js +1 -9
- package/dist/mixins/serverPaginationMixin.js +122 -0
- package/dist/mixins/sorterMixin.js +26 -44
- package/dist/mixins/storeMixin.js +28 -21
- package/dist/mixins/translationMixin.js +2 -12
- package/dist/mixins/validationMixin.js +28 -46
- package/dist/mixins/widgetMixin.js +58 -154
- package/dist/new-widgets/attributeMixins/actionMixin.js +1 -2
- package/dist/new-widgets/attributeMixins/blankMixin.js +1 -4
- package/dist/new-widgets/attributeMixins/booleanMixin.js +1 -4
- package/dist/new-widgets/attributeMixins/index.js +1 -2
- package/dist/new-widgets/attributeMixins/mailtoMixin.js +1 -4
- package/dist/new-widgets/attributeMixins/multipleMixin.js +1 -2
- package/dist/new-widgets/attributeMixins/numberMixin.js +1 -4
- package/dist/new-widgets/attributeMixins/placeholderMixin.js +1 -4
- package/dist/new-widgets/attributeMixins/telMixin.js +1 -4
- package/dist/new-widgets/baseWidgetMixin.js +5 -18
- package/dist/new-widgets/callbackMixins/autocompletionMixin.js +3 -11
- package/dist/new-widgets/callbackMixins/index.js +1 -2
- package/dist/new-widgets/callbackMixins/richtextMixin.js +1 -6
- package/dist/new-widgets/interfaces.js +1 -0
- package/dist/new-widgets/new-widget-factory.js +14 -19
- package/dist/new-widgets/templateAdditionMixins/addableMixin.js +6 -21
- package/dist/new-widgets/templateAdditionMixins/index.js +2 -3
- package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js +5 -18
- package/dist/new-widgets/templateAdditionMixins/labelMixin.js +5 -18
- package/dist/new-widgets/templates/defaultTemplatesDirectory.js +21 -27
- package/dist/new-widgets/templates/displayTemplatesDirectory.js +35 -70
- package/dist/new-widgets/templates/formTemplatesDirectory.js +350 -315
- package/dist/new-widgets/templates/groupTemplatesDirectory.js +5 -15
- package/dist/new-widgets/templates/index.js +1 -2
- package/dist/new-widgets/templates/setTemplatesDirectory.js +4 -37
- package/dist/new-widgets/templatesDependencies/altMixin.js +1 -2
- package/dist/new-widgets/templatesDependencies/editableMixin.js +9 -26
- package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js +3 -7
- package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js +1 -5
- package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js +1 -11
- package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +3 -13
- package/dist/new-widgets/templatesDependencies/formFileMixin.js +1 -13
- package/dist/new-widgets/templatesDependencies/formLengthMixin.js +1 -2
- package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js +1 -2
- package/dist/new-widgets/templatesDependencies/formMixin.js +4 -14
- package/dist/new-widgets/templatesDependencies/formNumberMixin.js +1 -5
- package/dist/new-widgets/templatesDependencies/formRadioMixin.js +1 -5
- package/dist/new-widgets/templatesDependencies/formStepMixin.js +1 -2
- package/dist/new-widgets/templatesDependencies/linkTextMixin.js +13 -0
- package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +23 -18
- package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +1 -10
- package/dist/new-widgets/templatesDependencies/patternMixin.js +1 -2
- package/dist/new-widgets/templatesDependencies/rangeMixin.js +5 -15
- package/dist/new-widgets/templatesDependencies/setMixin.js +1 -4
- package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js +1 -4
- package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js +1 -5
- package/dist/new-widgets/valueTransformationMixins/dateMixin.js +5 -11
- package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js +1 -5
- package/dist/new-widgets/valueTransformationMixins/index.js +1 -2
- package/dist/new-widgets/valueTransformationMixins/markdownMixin.js +1 -7
- package/dist/new-widgets/valueTransformationMixins/multilineMixin.js +1 -5
- package/dist/new-widgets/valueTransformationMixins/oembedMixin.js +1 -7
- package/dist/solid-template-element.js +24 -44
- package/dist/widgets/baseWidget.js +21 -85
- package/dist/widgets/widget-factory.js +4 -6
- package/package.json +8 -6
- package/dist/_snowpack/env.js +0 -3
- package/dist/_snowpack/pkg/autolinker.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/common/_baseUnary-217dffb2.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/common/_commonjsHelpers-8c19dec8.js.map +0 -1
- package/dist/_snowpack/pkg/common/_commonjsHelpers-8c19dec8.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/common/decode-a4c334cf.js.map +0 -1
- package/dist/_snowpack/pkg/common/decode-a4c334cf.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/common/lit-html-babd44cd.js +0 -1119
- package/dist/_snowpack/pkg/common/lit-html-babd44cd.js.map +0 -1
- package/dist/_snowpack/pkg/common/lit-html-babd44cd.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/dialog-polyfill.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/fusejs.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/jsonld-context-parser.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/lit-html/directives/until.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/lit-html.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/markdown-it-link-attributes.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/markdown-it.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/quill.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/slim-select.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/tui-calendar.js.map.proxy.js +0 -1
- package/dist/components/solid-ac-checker.js.map +0 -1
- package/dist/components/solid-calendar.js.map +0 -1
- package/dist/components/solid-delete.js.map +0 -1
- package/dist/components/solid-display.js.map +0 -1
- package/dist/components/solid-form-search.js.map +0 -1
- package/dist/components/solid-form.js.map +0 -1
- package/dist/components/solid-lang.js.map +0 -1
- package/dist/components/solid-map.js.map +0 -1
- package/dist/components/solid-table.js.map +0 -1
- package/dist/components/solid-widget.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/libs/Component.js.map +0 -1
- package/dist/libs/ComponentFactory.js.map +0 -1
- package/dist/libs/Compositor.js.map +0 -1
- package/dist/libs/Sib.js.map +0 -1
- package/dist/libs/helpers.js.map +0 -1
- package/dist/libs/interfaces.js.map +0 -1
- package/dist/libs/lit-helpers.js.map +0 -1
- package/dist/libs/polyfills.js.map +0 -1
- package/dist/libs/store/store.js.map +0 -1
- package/dist/mixins/attributeBinderMixin.js.map +0 -1
- package/dist/mixins/contextMixin.js.map +0 -1
- package/dist/mixins/counterMixin.js.map +0 -1
- package/dist/mixins/federationMixin.js.map +0 -1
- package/dist/mixins/filterMixin.js.map +0 -1
- package/dist/mixins/grouperMixin.js.map +0 -1
- package/dist/mixins/highlighterMixin.js.map +0 -1
- package/dist/mixins/interfaces.js.map +0 -1
- package/dist/mixins/listMixin.js.map +0 -1
- package/dist/mixins/nextMixin.js.map +0 -1
- package/dist/mixins/paginateMixin.js.map +0 -1
- package/dist/mixins/requiredMixin.js.map +0 -1
- package/dist/mixins/sorterMixin.js.map +0 -1
- package/dist/mixins/storeMixin.js.map +0 -1
- package/dist/mixins/translationMixin.js.map +0 -1
- package/dist/mixins/validationMixin.js.map +0 -1
- package/dist/mixins/widgetMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/actionMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/blankMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/booleanMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/index.js.map +0 -1
- package/dist/new-widgets/attributeMixins/mailtoMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/multipleMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/numberMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/placeholderMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/telMixin.js.map +0 -1
- package/dist/new-widgets/baseWidgetMixin.js.map +0 -1
- package/dist/new-widgets/callbackMixins/autocompletionMixin.js.map +0 -1
- package/dist/new-widgets/callbackMixins/index.js.map +0 -1
- package/dist/new-widgets/callbackMixins/richtextMixin.js.map +0 -1
- package/dist/new-widgets/new-widget-factory.js.map +0 -1
- package/dist/new-widgets/templateAdditionMixins/addableMixin.js.map +0 -1
- package/dist/new-widgets/templateAdditionMixins/index.js.map +0 -1
- package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js.map +0 -1
- package/dist/new-widgets/templateAdditionMixins/labelMixin.js.map +0 -1
- package/dist/new-widgets/templates/defaultTemplatesDirectory.js.map +0 -1
- package/dist/new-widgets/templates/displayTemplatesDirectory.js.map +0 -1
- package/dist/new-widgets/templates/formTemplatesDirectory.js.map +0 -1
- package/dist/new-widgets/templates/groupTemplatesDirectory.js.map +0 -1
- package/dist/new-widgets/templates/index.js.map +0 -1
- package/dist/new-widgets/templates/setTemplatesDirectory.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/altMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/editableMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formDropdownMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formFileMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formLengthMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formNumberMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formRadioMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formStepMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/multipleFormMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/patternMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/rangeMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/setMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/dateMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/index.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/markdownMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/multilineMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/oembedMixin.js.map +0 -1
- package/dist/solid-template-element.js.map +0 -1
- package/dist/widgets/baseWidget.js.map +0 -1
- package/dist/widgets/widget-factory.js.map +0 -1
package/dist/libs/store/store.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
let _Symbol$toPrimitive;
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
import JSONLDContextParser from '../../_snowpack/pkg/jsonld-context-parser.js';
|
|
6
|
-
|
|
2
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
3
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
4
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
5
|
+
import JSONLDContextParser from '../../_snowpack/pkg/jsonld-context-parser.js';
|
|
6
|
+
//@ts-ignore
|
|
7
7
|
import PubSub from 'https://cdn.skypack.dev/pubsub-js';
|
|
8
|
+
import { appendServerSearchToIri } from './server-search.js';
|
|
9
|
+
import { appendServerPaginationToIri } from './server-pagination.js';
|
|
8
10
|
const ContextParser = JSONLDContextParser.ContextParser;
|
|
9
11
|
const myParser = new ContextParser();
|
|
10
12
|
export const base_context = {
|
|
@@ -21,125 +23,140 @@ export const base_context = {
|
|
|
21
23
|
lat: "geo:lat",
|
|
22
24
|
lng: "geo:long"
|
|
23
25
|
};
|
|
24
|
-
|
|
25
26
|
class Store {
|
|
26
|
-
// index of all the containers per resource
|
|
27
|
-
// index of all the containers per resource
|
|
28
27
|
constructor(storeOptions) {
|
|
29
28
|
this.storeOptions = storeOptions;
|
|
30
|
-
|
|
31
29
|
_defineProperty(this, "cache", void 0);
|
|
32
|
-
|
|
33
30
|
_defineProperty(this, "subscriptionIndex", void 0);
|
|
34
|
-
|
|
31
|
+
// index of all the containers per resource
|
|
35
32
|
_defineProperty(this, "subscriptionVirtualContainersIndex", void 0);
|
|
36
|
-
|
|
33
|
+
// index of all the containers per resource
|
|
37
34
|
_defineProperty(this, "loadingList", void 0);
|
|
38
|
-
|
|
39
35
|
_defineProperty(this, "headers", void 0);
|
|
40
|
-
|
|
41
36
|
_defineProperty(this, "fetch", void 0);
|
|
42
|
-
|
|
43
37
|
_defineProperty(this, "session", void 0);
|
|
44
|
-
|
|
45
38
|
_defineProperty(this, "resolveResource", function (id, resolve) {
|
|
46
39
|
const handler = function (event) {
|
|
47
40
|
if (event.detail.id === id) {
|
|
48
|
-
resolve(event.detail.resource);
|
|
49
|
-
|
|
41
|
+
resolve(event.detail.resource);
|
|
42
|
+
// TODO : callback
|
|
50
43
|
document.removeEventListener('resourceReady', handler);
|
|
51
44
|
}
|
|
52
45
|
};
|
|
53
|
-
|
|
54
46
|
return handler;
|
|
55
47
|
});
|
|
56
|
-
|
|
57
48
|
this.cache = new Map();
|
|
58
49
|
this.subscriptionIndex = new Map();
|
|
59
50
|
this.subscriptionVirtualContainersIndex = new Map();
|
|
60
51
|
this.loadingList = new Set();
|
|
61
52
|
this.headers = {
|
|
62
|
-
'Content-Type': 'application/ld+json'
|
|
53
|
+
'Content-Type': 'application/ld+json',
|
|
54
|
+
'Cache-Control': 'must-revalidate'
|
|
63
55
|
};
|
|
64
56
|
this.fetch = this.storeOptions.fetchMethod;
|
|
65
57
|
this.session = this.storeOptions.session;
|
|
66
58
|
}
|
|
59
|
+
|
|
67
60
|
/**
|
|
68
61
|
* Fetch data and cache it
|
|
69
62
|
* @param id - uri of the resource to fetch
|
|
70
63
|
* @param context - context used to expand id and predicates when accessing the resource
|
|
71
|
-
* @param
|
|
64
|
+
* @param parentId - uri of the parent caller used to expand uri for local files
|
|
65
|
+
* @param localData - data to put in cache
|
|
66
|
+
* @param forceFetch - force the fetch of data
|
|
67
|
+
* @param serverPagination - Server pagination options
|
|
68
|
+
* @param serverSearch - Server search options
|
|
72
69
|
*
|
|
73
70
|
* @returns The fetched resource
|
|
74
71
|
*
|
|
75
72
|
* @async
|
|
76
73
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
async getData(id) {
|
|
75
|
+
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
76
|
+
let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
|
|
77
|
+
let localData = arguments.length > 3 ? arguments[3] : undefined;
|
|
78
|
+
let forceFetch = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
79
|
+
let serverPagination = arguments.length > 5 ? arguments[5] : undefined;
|
|
80
|
+
let serverSearch = arguments.length > 6 ? arguments[6] : undefined;
|
|
81
|
+
let key = id;
|
|
82
|
+
if (serverPagination) {
|
|
83
|
+
key = id + "#p" + serverPagination.limit + "?o" + serverPagination.offset;
|
|
84
|
+
}
|
|
85
|
+
if (serverSearch) {
|
|
86
|
+
key = appendServerSearchToIri(key, serverSearch);
|
|
87
|
+
}
|
|
88
|
+
if (localData == null && this.cache.has(key) && !this.loadingList.has(key)) {
|
|
89
|
+
const resource = this.get(key);
|
|
90
|
+
if (resource && resource.isFullResource?.() && !forceFetch) return resource; // if resource is not complete, re-fetch it
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
return new Promise(async resolve => {
|
|
86
|
-
document.addEventListener('resourceReady', this.resolveResource(
|
|
87
|
-
if (this.loadingList.has(
|
|
88
|
-
this.loadingList.add(
|
|
94
|
+
document.addEventListener('resourceReady', this.resolveResource(key, resolve));
|
|
95
|
+
if (this.loadingList.has(key)) return;
|
|
96
|
+
this.loadingList.add(key);
|
|
89
97
|
|
|
98
|
+
// Generate proxy
|
|
90
99
|
const clientContext = await myParser.parse(context);
|
|
91
100
|
let resource = null;
|
|
92
|
-
|
|
93
101
|
if (this._isLocalId(id)) {
|
|
94
102
|
if (localData == null) localData = {};
|
|
95
103
|
localData["@id"] = id;
|
|
96
104
|
resource = localData;
|
|
97
105
|
} else try {
|
|
98
|
-
resource = localData || (await this.fetchData(id, clientContext,
|
|
106
|
+
resource = localData || (await this.fetchData(id, clientContext, parentId, serverPagination, serverSearch));
|
|
99
107
|
} catch (error) {
|
|
100
108
|
console.error(error);
|
|
101
109
|
}
|
|
102
|
-
|
|
103
110
|
if (!resource) {
|
|
104
|
-
this.loadingList.delete(
|
|
111
|
+
this.loadingList.delete(key);
|
|
105
112
|
resolve(null);
|
|
106
113
|
return;
|
|
107
114
|
}
|
|
108
|
-
|
|
109
115
|
const serverContext = await myParser.parse([resource['@context'] || {}]);
|
|
110
|
-
const resourceProxy = new CustomGetter(
|
|
111
|
-
|
|
112
|
-
await this.cacheGraph(
|
|
113
|
-
this.loadingList.delete(
|
|
116
|
+
const resourceProxy = new CustomGetter(key, resource, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch).getProxy();
|
|
117
|
+
// Cache proxy
|
|
118
|
+
await this.cacheGraph(key, resourceProxy, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch);
|
|
119
|
+
this.loadingList.delete(key);
|
|
114
120
|
document.dispatchEvent(new CustomEvent('resourceReady', {
|
|
115
121
|
detail: {
|
|
116
|
-
id:
|
|
117
|
-
resource: this.get(
|
|
122
|
+
id: key,
|
|
123
|
+
resource: this.get(key)
|
|
118
124
|
}
|
|
119
125
|
}));
|
|
120
126
|
});
|
|
121
127
|
}
|
|
122
|
-
|
|
123
128
|
async fetchAuthn(iri, options) {
|
|
124
129
|
let authenticated = false;
|
|
125
130
|
if (this.session) authenticated = await this.session;
|
|
126
|
-
|
|
127
131
|
if (this.fetch && authenticated) {
|
|
128
132
|
// authenticated
|
|
129
133
|
return this.fetch.then(fn => fn(iri, options));
|
|
130
134
|
} else {
|
|
131
135
|
// anonymous
|
|
132
136
|
if (options.headers) options.headers = this._convertHeaders(options.headers);
|
|
133
|
-
return fetch(iri, options)
|
|
137
|
+
return fetch(iri, options).then(function (response) {
|
|
138
|
+
if (options.method === "PURGE" && !response.ok && response.status === 404) {
|
|
139
|
+
const err = new Error("PURGE call is returning 404");
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
return response;
|
|
143
|
+
});
|
|
134
144
|
}
|
|
135
145
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
async fetchData(id) {
|
|
147
|
+
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
148
|
+
let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
|
|
149
|
+
let serverPagination = arguments.length > 3 ? arguments[3] : undefined;
|
|
150
|
+
let serverSearch = arguments.length > 4 ? arguments[4] : undefined;
|
|
151
|
+
let iri = this._getAbsoluteIri(id, context, parentId);
|
|
152
|
+
if (serverPagination) iri = appendServerPaginationToIri(iri, serverPagination);
|
|
153
|
+
if (serverSearch) iri = appendServerSearchToIri(iri, serverSearch);
|
|
154
|
+
const headers = {
|
|
155
|
+
...this.headers,
|
|
141
156
|
'accept-language': this._getLanguage()
|
|
157
|
+
// 'Prefer' : 'return=representation; max-triple-count="100"' // Commenting out for now as it raises CORS errors
|
|
142
158
|
};
|
|
159
|
+
|
|
143
160
|
return this.fetchAuthn(iri, {
|
|
144
161
|
method: 'GET',
|
|
145
162
|
headers: headers,
|
|
@@ -149,62 +166,61 @@ class Store {
|
|
|
149
166
|
return response.json();
|
|
150
167
|
});
|
|
151
168
|
}
|
|
152
|
-
|
|
153
|
-
async cacheGraph(key, resource, clientContext, parentContext, parentId) {
|
|
169
|
+
async cacheGraph(key, resource, clientContext, parentContext, parentId, serverPagination, serverSearch) {
|
|
154
170
|
if (resource.properties) {
|
|
155
171
|
// if proxy, cache it
|
|
156
|
-
if (this.get(key)) {
|
|
172
|
+
if (this.get(key) && this.cache.get(key).merge) {
|
|
157
173
|
// if already cached, merge data
|
|
158
174
|
this.cache.get(key).merge(resource);
|
|
175
|
+
;
|
|
159
176
|
} else {
|
|
160
177
|
// else, put in cache
|
|
161
178
|
this.cache.set(key, resource);
|
|
162
179
|
}
|
|
163
|
-
}
|
|
164
|
-
|
|
180
|
+
}
|
|
165
181
|
|
|
182
|
+
// Cache nested resources
|
|
166
183
|
if (resource.getSubObjects) {
|
|
167
184
|
for (let res of resource.getSubObjects()) {
|
|
168
|
-
let newParentContext = parentContext;
|
|
169
|
-
|
|
170
|
-
if (res['@context']) newParentContext = await myParser.parse({
|
|
185
|
+
let newParentContext = parentContext;
|
|
186
|
+
// If additional context in resource, use it to expand properties
|
|
187
|
+
if (res['@context']) newParentContext = await myParser.parse({
|
|
188
|
+
...parentContext,
|
|
171
189
|
...res['@context']
|
|
172
190
|
});
|
|
173
|
-
const resourceProxy = new CustomGetter(res['@id'], res, clientContext, newParentContext, parentId).getProxy();
|
|
174
|
-
|
|
175
|
-
await this.cacheGraph(res['@id'], resourceProxy, clientContext, parentContext, parentId);
|
|
191
|
+
const resourceProxy = new CustomGetter(res['@id'], res, clientContext, newParentContext, parentId).getProxy();
|
|
192
|
+
// this.subscribeResourceTo(resource['@id'], res['@id']); // removed to prevent useless updates
|
|
193
|
+
await this.cacheGraph(res['@id'], resourceProxy, clientContext, parentContext, parentId, serverPagination, serverSearch);
|
|
176
194
|
}
|
|
177
|
-
}
|
|
178
|
-
|
|
195
|
+
}
|
|
179
196
|
|
|
197
|
+
// Cache children of container
|
|
180
198
|
if (resource['@type'] == "ldp:Container" && resource.getChildren) {
|
|
181
199
|
const cacheChildrenPromises = [];
|
|
182
200
|
|
|
183
|
-
for
|
|
201
|
+
//TODO: return complete object without the need for the fetch data from the cacheGraph
|
|
202
|
+
for (let res of await resource.getChildren()) {
|
|
184
203
|
this.subscribeResourceTo(resource['@id'], res['@id']);
|
|
185
|
-
cacheChildrenPromises.push(this.cacheGraph(res['@id'], res, clientContext, parentContext, parentId));
|
|
204
|
+
cacheChildrenPromises.push(this.cacheGraph(res['@id'], res, clientContext, parentContext, parentId, serverPagination, serverSearch));
|
|
186
205
|
}
|
|
187
|
-
|
|
188
206
|
await Promise.all(cacheChildrenPromises);
|
|
189
207
|
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
208
|
+
}
|
|
192
209
|
|
|
210
|
+
// Create proxy, (fetch data) and cache resource
|
|
193
211
|
if (resource['@id'] && !resource.properties) {
|
|
194
212
|
if (resource['@id'].match(/^b\d+$/)) return; // not anonymous node
|
|
195
213
|
// Fetch data if
|
|
196
|
-
|
|
197
214
|
if (resource['@type'] === "sib:federatedContainer" && resource['@cache'] !== 'false') {
|
|
198
215
|
// if object is federated container
|
|
199
216
|
await this.getData(resource['@id'], clientContext, parentId); // then init graph
|
|
200
|
-
|
|
201
217
|
return;
|
|
202
218
|
}
|
|
203
|
-
|
|
204
|
-
const resourceProxy = new CustomGetter(resource['@id'], resource, clientContext, parentContext, parentId).getProxy();
|
|
219
|
+
const resourceProxy = new CustomGetter(key, resource, clientContext, parentContext, parentId).getProxy();
|
|
205
220
|
await this.cacheGraph(key, resourceProxy, clientContext, parentContext, parentId);
|
|
206
221
|
}
|
|
207
222
|
}
|
|
223
|
+
|
|
208
224
|
/**
|
|
209
225
|
* Update fetch
|
|
210
226
|
* @param method - 'POST', 'PATCH', 'PUT', '_LOCAL'
|
|
@@ -212,8 +228,6 @@ class Store {
|
|
|
212
228
|
* @param id - uri to update
|
|
213
229
|
* @returns - object
|
|
214
230
|
*/
|
|
215
|
-
|
|
216
|
-
|
|
217
231
|
async _fetch(method, resource, id) {
|
|
218
232
|
if (method !== '_LOCAL') return this.fetchAuthn(id, {
|
|
219
233
|
method: method,
|
|
@@ -229,19 +243,16 @@ class Store {
|
|
|
229
243
|
ok: true
|
|
230
244
|
};
|
|
231
245
|
}
|
|
232
|
-
|
|
233
246
|
async _updateResource(method, resource, id) {
|
|
234
247
|
if (!['POST', 'PUT', 'PATCH', '_LOCAL'].includes(method)) throw new Error('Error: method not allowed');
|
|
235
248
|
const context = await myParser.parse([resource['@context'] || {}]); // parse context before expandTerm
|
|
236
|
-
|
|
237
249
|
const expandedId = this._getExpandedId(id, context);
|
|
238
|
-
|
|
239
|
-
return this._fetch(method, resource, id).then(response => {
|
|
250
|
+
return this._fetch(method, resource, id).then(async response => {
|
|
240
251
|
if (response.ok) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
252
|
+
if (method !== '_LOCAL') {
|
|
253
|
+
// await this.purge(id);
|
|
254
|
+
this.clearCache(expandedId);
|
|
255
|
+
} // clear cache
|
|
245
256
|
this.getData(expandedId, resource['@context']).then(async () => {
|
|
246
257
|
// re-fetch data
|
|
247
258
|
const nestedResources = await this.getNestedResources(resource, id);
|
|
@@ -250,104 +261,94 @@ class Store {
|
|
|
250
261
|
return this.refreshResources([...nestedResources, ...resourcesToRefresh]) // refresh related resources
|
|
251
262
|
.then(resourceIds => this.notifyResources([expandedId, ...resourceIds, ...resourcesToNotify])); // notify components
|
|
252
263
|
});
|
|
253
|
-
|
|
264
|
+
|
|
265
|
+
return response.headers?.get('Location') || null;
|
|
254
266
|
} else {
|
|
255
267
|
throw response;
|
|
256
268
|
}
|
|
257
269
|
});
|
|
258
270
|
}
|
|
271
|
+
|
|
259
272
|
/**
|
|
260
273
|
* Clear cache and refetch data for a list of ids
|
|
261
274
|
* @param resourceIds -
|
|
262
275
|
* @returns - all the resource ids
|
|
263
276
|
*/
|
|
264
|
-
|
|
265
|
-
|
|
266
277
|
async refreshResources(resourceIds) {
|
|
267
278
|
resourceIds = [...new Set(resourceIds.filter(id => this.cache.has(id)))]; // remove duplicates and not cached resources
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return {
|
|
273
|
-
"id": resourceId,
|
|
274
|
-
"context": (_store$get = store.get(resourceId)) === null || _store$get === void 0 ? void 0 : _store$get.clientContext
|
|
275
|
-
};
|
|
276
|
-
});
|
|
277
|
-
|
|
279
|
+
const resourceWithContexts = resourceIds.map(resourceId => ({
|
|
280
|
+
"id": resourceId,
|
|
281
|
+
"context": store.get(resourceId)?.clientContext
|
|
282
|
+
}));
|
|
278
283
|
for (const resource of resourceWithContexts) {
|
|
279
284
|
if (!this._isLocalId(resource.id)) this.clearCache(resource.id);
|
|
280
285
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
+
await Promise.all(resourceWithContexts.map(_ref => {
|
|
287
|
+
let {
|
|
288
|
+
id,
|
|
289
|
+
context
|
|
290
|
+
} = _ref;
|
|
291
|
+
return this.getData(id, context || base_context);
|
|
292
|
+
}));
|
|
286
293
|
return resourceIds;
|
|
287
294
|
}
|
|
288
295
|
/**
|
|
289
296
|
* Notifies all components for a list of ids
|
|
290
297
|
* @param resourceIds -
|
|
291
298
|
*/
|
|
292
|
-
|
|
293
|
-
|
|
294
299
|
async notifyResources(resourceIds) {
|
|
295
300
|
resourceIds = [...new Set(resourceIds)]; // remove duplicates
|
|
296
|
-
|
|
297
301
|
for (const id of resourceIds) PubSub.publish(id);
|
|
298
302
|
}
|
|
303
|
+
|
|
299
304
|
/**
|
|
300
305
|
* Return id of nested properties of a resource
|
|
301
306
|
* @param resource - object
|
|
302
307
|
* @param id - string
|
|
303
308
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
306
309
|
async getNestedResources(resource, id) {
|
|
307
310
|
const cachedResource = store.get(id);
|
|
308
|
-
if (!cachedResource || cachedResource.isContainer()) return [];
|
|
311
|
+
if (!cachedResource || cachedResource.isContainer?.()) return [];
|
|
309
312
|
let nestedProperties = [];
|
|
310
313
|
const excludeKeys = ['@context'];
|
|
311
|
-
|
|
312
314
|
for (let p of Object.keys(resource)) {
|
|
313
315
|
if (resource[p] && typeof resource[p] === 'object' && !excludeKeys.includes(p) && resource[p]['@id']) {
|
|
314
316
|
nestedProperties.push(resource[p]['@id']);
|
|
315
317
|
}
|
|
316
318
|
}
|
|
317
|
-
|
|
318
319
|
return nestedProperties;
|
|
319
320
|
}
|
|
321
|
+
|
|
320
322
|
/**
|
|
321
323
|
* Returns the resource with id from the cache
|
|
322
324
|
* @param id - id of the resource to retrieve
|
|
323
325
|
*
|
|
324
326
|
* @returns Resource (Proxy) if in the cache, null otherwise
|
|
325
327
|
*/
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
328
|
+
get(id, serverSearch) {
|
|
329
|
+
if (serverSearch) {
|
|
330
|
+
id = appendServerSearchToIri(id, serverSearch);
|
|
331
|
+
}
|
|
329
332
|
return this.cache.get(id) || null;
|
|
330
333
|
}
|
|
334
|
+
|
|
331
335
|
/**
|
|
332
336
|
* Removes a resource from the cache
|
|
333
337
|
* @param id - id of the resource to remove from the cache
|
|
334
338
|
*/
|
|
335
|
-
|
|
336
|
-
|
|
337
339
|
clearCache(id) {
|
|
338
340
|
if (this.cache.has(id)) {
|
|
339
341
|
// For federation, clear each source
|
|
340
342
|
const resource = this.cache.get(id);
|
|
341
|
-
|
|
342
343
|
if (resource['@type'] === 'ldp:Container') {
|
|
343
344
|
resource['ldp:contains'].forEach(child => {
|
|
344
345
|
if (child && child['@type'] === 'ldp:Container') this.cache.delete(child['@id']);
|
|
345
346
|
});
|
|
346
347
|
}
|
|
347
|
-
|
|
348
348
|
this.cache.delete(id);
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
+
|
|
351
352
|
/**
|
|
352
353
|
* Send data to create a local resource in a container
|
|
353
354
|
* @param resource - resource to create
|
|
@@ -355,11 +356,10 @@ class Store {
|
|
|
355
356
|
*
|
|
356
357
|
* @returns id of the posted resource
|
|
357
358
|
*/
|
|
358
|
-
|
|
359
|
-
|
|
360
359
|
async setLocalData(resource, id) {
|
|
361
360
|
return this._updateResource('_LOCAL', resource, id);
|
|
362
361
|
}
|
|
362
|
+
|
|
363
363
|
/**
|
|
364
364
|
* Send a POST request to create a resource in a container
|
|
365
365
|
* @param resource - resource to create
|
|
@@ -367,11 +367,10 @@ class Store {
|
|
|
367
367
|
*
|
|
368
368
|
* @returns id of the posted resource
|
|
369
369
|
*/
|
|
370
|
-
|
|
371
|
-
|
|
372
370
|
async post(resource, id) {
|
|
373
371
|
return this._updateResource('POST', resource, id);
|
|
374
372
|
}
|
|
373
|
+
|
|
375
374
|
/**
|
|
376
375
|
* Send a PUT request to edit a resource
|
|
377
376
|
* @param resource - resource data to send
|
|
@@ -379,11 +378,10 @@ class Store {
|
|
|
379
378
|
*
|
|
380
379
|
* @returns id of the edited resource
|
|
381
380
|
*/
|
|
382
|
-
|
|
383
|
-
|
|
384
381
|
async put(resource, id) {
|
|
385
382
|
return this._updateResource('PUT', resource, id);
|
|
386
383
|
}
|
|
384
|
+
|
|
387
385
|
/**
|
|
388
386
|
* Send a PATCH request to edit a resource
|
|
389
387
|
* @param resource - resource data to send
|
|
@@ -391,11 +389,43 @@ class Store {
|
|
|
391
389
|
*
|
|
392
390
|
* @returns id of the edited resource
|
|
393
391
|
*/
|
|
394
|
-
|
|
395
|
-
|
|
396
392
|
async patch(resource, id) {
|
|
397
393
|
return this._updateResource('PATCH', resource, id);
|
|
398
394
|
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Send a PURGE request to remove a resource from REDIS AD cache
|
|
398
|
+
* @param id - uri of the resource to patch
|
|
399
|
+
*
|
|
400
|
+
* @returns id of the edited resource
|
|
401
|
+
*/
|
|
402
|
+
async purge(id) {
|
|
403
|
+
await this.fetchAuthn(id, {
|
|
404
|
+
method: "PURGE",
|
|
405
|
+
headers: this.headers
|
|
406
|
+
}).catch(function (error) {
|
|
407
|
+
console.warn('No purge method allowed: ' + error);
|
|
408
|
+
});
|
|
409
|
+
try {
|
|
410
|
+
const fullURL = new URL(id);
|
|
411
|
+
var pathArray = fullURL.pathname.split('/');
|
|
412
|
+
var containerUrl = fullURL.origin + '/' + pathArray[1] + '/';
|
|
413
|
+
const headers = {
|
|
414
|
+
...this.headers,
|
|
415
|
+
'X-Cache-Purge-Match': 'startswith'
|
|
416
|
+
};
|
|
417
|
+
await this.fetchAuthn(containerUrl, {
|
|
418
|
+
method: "PURGE",
|
|
419
|
+
headers: headers
|
|
420
|
+
}).catch(function (error) {
|
|
421
|
+
console.warn('No purge method allowed: ' + error);
|
|
422
|
+
});
|
|
423
|
+
} catch (error) {
|
|
424
|
+
console.warn('The resource ID is not a complete URL: ' + error);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
399
429
|
/**
|
|
400
430
|
* Send a DELETE request to delete a resource
|
|
401
431
|
* @param id - uri of the resource to delete
|
|
@@ -403,78 +433,69 @@ class Store {
|
|
|
403
433
|
*
|
|
404
434
|
* @returns id of the deleted resource
|
|
405
435
|
*/
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
async delete(id, context = {}) {
|
|
436
|
+
async delete(id) {
|
|
437
|
+
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
409
438
|
const expandedId = this._getExpandedId(id, context);
|
|
410
|
-
|
|
411
439
|
const deleted = await this.fetchAuthn(expandedId, {
|
|
412
440
|
method: 'DELETE',
|
|
413
441
|
headers: this.headers,
|
|
414
442
|
credentials: 'include'
|
|
415
443
|
});
|
|
444
|
+
// await this.purge(id);
|
|
445
|
+
|
|
416
446
|
const resourcesToNotify = this.subscriptionIndex.get(expandedId) || [];
|
|
417
447
|
const resourcesToRefresh = this.subscriptionVirtualContainersIndex.get(expandedId) || [];
|
|
418
448
|
this.refreshResources([...resourcesToNotify, ...resourcesToRefresh]).then(resourceIds => this.notifyResources(resourceIds));
|
|
419
449
|
return deleted;
|
|
420
450
|
}
|
|
451
|
+
|
|
421
452
|
/**
|
|
422
453
|
* Convert headers object to Headers
|
|
423
454
|
* @param headersObject - object
|
|
424
455
|
* @returns {Headers}
|
|
425
456
|
*/
|
|
426
|
-
|
|
427
|
-
|
|
428
457
|
_convertHeaders(headersObject) {
|
|
429
458
|
const headers = new Headers();
|
|
430
|
-
|
|
431
459
|
for (const [key, value] of Object.entries(headersObject)) {
|
|
432
460
|
headers.set(key, value);
|
|
433
461
|
}
|
|
434
|
-
|
|
435
462
|
return headers;
|
|
436
463
|
}
|
|
437
|
-
|
|
438
464
|
_getExpandedId(id, context) {
|
|
439
465
|
return context && Object.keys(context) ? ContextParser.expandTerm(id, context) : id;
|
|
440
466
|
}
|
|
441
|
-
|
|
442
467
|
_isLocalId(id) {
|
|
443
468
|
return id.startsWith('store://local.');
|
|
444
469
|
}
|
|
470
|
+
|
|
445
471
|
/**
|
|
446
472
|
* Make a resource listen changes of another one
|
|
447
473
|
* @param resourceId - id of the resource which needs to be updated
|
|
448
474
|
* @param nestedResourceId - id of the resource which will change
|
|
449
475
|
*/
|
|
450
|
-
|
|
451
|
-
|
|
452
476
|
subscribeResourceTo(resourceId, nestedResourceId) {
|
|
453
477
|
const existingSubscriptions = this.subscriptionIndex.get(nestedResourceId) || [];
|
|
454
478
|
this.subscriptionIndex.set(nestedResourceId, [...new Set([...existingSubscriptions, resourceId])]);
|
|
455
479
|
}
|
|
480
|
+
|
|
456
481
|
/**
|
|
457
482
|
* Make a virtual container listen for changes of a resource
|
|
458
483
|
* @param virtualContainerId - id of the container which needs to be updated
|
|
459
484
|
* @param nestedResourceId - id of the resource which will change
|
|
460
485
|
*/
|
|
461
|
-
|
|
462
|
-
|
|
463
486
|
subscribeVirtualContainerTo(virtualContainerId, nestedResourceId) {
|
|
464
487
|
const existingSubscriptions = this.subscriptionVirtualContainersIndex.get(nestedResourceId) || [];
|
|
465
488
|
this.subscriptionVirtualContainersIndex.set(nestedResourceId, [...new Set([...existingSubscriptions, virtualContainerId])]);
|
|
466
489
|
}
|
|
490
|
+
|
|
467
491
|
/**
|
|
468
492
|
* Return absolute IRI of the resource
|
|
469
493
|
* @param id
|
|
470
494
|
* @param context
|
|
471
495
|
* @param parentId
|
|
472
496
|
*/
|
|
473
|
-
|
|
474
|
-
|
|
475
497
|
_getAbsoluteIri(id, context, parentId) {
|
|
476
498
|
let iri = ContextParser.expandTerm(id, context); // expand if reduced ids
|
|
477
|
-
|
|
478
499
|
if (parentId) {
|
|
479
500
|
// and get full URL from parent caller for local files
|
|
480
501
|
let parentIri = new URL(parentId, document.location.href).href;
|
|
@@ -482,145 +503,131 @@ class Store {
|
|
|
482
503
|
} else {
|
|
483
504
|
iri = new URL(iri, document.location.href).href;
|
|
484
505
|
}
|
|
485
|
-
|
|
486
506
|
return iri;
|
|
487
507
|
}
|
|
508
|
+
|
|
488
509
|
/**
|
|
489
510
|
* Check if object is a full resource
|
|
490
511
|
* @param resource
|
|
491
512
|
*/
|
|
492
|
-
|
|
493
|
-
|
|
494
513
|
_resourceIsComplete(resource) {
|
|
495
514
|
return !!(Object.keys(resource).filter(p => !p.startsWith('@')).length > 0 && resource['@id']);
|
|
496
515
|
}
|
|
516
|
+
|
|
497
517
|
/**
|
|
498
518
|
* Return language of the users
|
|
499
519
|
*/
|
|
500
|
-
|
|
501
|
-
|
|
502
520
|
_getLanguage() {
|
|
503
521
|
return localStorage.getItem('language') || window.navigator.language.slice(0, 2);
|
|
504
522
|
}
|
|
523
|
+
|
|
505
524
|
/**
|
|
506
525
|
* Save the preferred language of the user
|
|
507
526
|
* @param selectedLanguageCode
|
|
508
527
|
*/
|
|
509
|
-
|
|
510
|
-
|
|
511
528
|
selectLanguage(selectedLanguageCode) {
|
|
512
529
|
localStorage.setItem('language', selectedLanguageCode);
|
|
513
530
|
}
|
|
514
|
-
|
|
515
531
|
}
|
|
516
|
-
|
|
517
532
|
let store;
|
|
518
|
-
|
|
519
533
|
if (window.sibStore) {
|
|
520
534
|
store = window.sibStore;
|
|
521
535
|
} else {
|
|
522
536
|
const sibAuth = document.querySelector('sib-auth');
|
|
523
537
|
const storeOptions = {};
|
|
524
|
-
|
|
525
538
|
if (sibAuth) {
|
|
526
539
|
const sibAuthDefined = customElements.whenDefined(sibAuth.localName);
|
|
527
540
|
storeOptions.session = sibAuthDefined.then(() => sibAuth.session);
|
|
528
541
|
storeOptions.fetchMethod = sibAuthDefined.then(() => sibAuth.getFetch());
|
|
529
542
|
}
|
|
530
|
-
|
|
531
543
|
store = new Store(storeOptions);
|
|
532
544
|
window.sibStore = store;
|
|
533
545
|
}
|
|
534
|
-
|
|
535
546
|
export { store };
|
|
536
547
|
_Symbol$toPrimitive = Symbol.toPrimitive;
|
|
537
|
-
|
|
538
548
|
class CustomGetter {
|
|
539
|
-
//
|
|
540
|
-
// context given by the app
|
|
541
|
-
// context given by the server
|
|
542
|
-
// id of the parent resource, used to get the absolute url of the current resource
|
|
543
|
-
constructor(resourceId, resource, clientContext, serverContext = {}, parentId = "") {
|
|
544
|
-
_defineProperty(this, "resource", void 0);
|
|
549
|
+
// search attributes to give to server
|
|
545
550
|
|
|
551
|
+
constructor(resourceId, resource, clientContext) {
|
|
552
|
+
let serverContext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
553
|
+
let parentId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
|
|
554
|
+
let serverPagination = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
555
|
+
let serverSearch = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
|
|
556
|
+
_defineProperty(this, "resource", void 0);
|
|
557
|
+
// content of the requested resource
|
|
546
558
|
_defineProperty(this, "resourceId", void 0);
|
|
547
|
-
|
|
548
559
|
_defineProperty(this, "clientContext", void 0);
|
|
549
|
-
|
|
560
|
+
// context given by the app
|
|
550
561
|
_defineProperty(this, "serverContext", void 0);
|
|
551
|
-
|
|
562
|
+
// context given by the server
|
|
552
563
|
_defineProperty(this, "parentId", void 0);
|
|
553
|
-
|
|
564
|
+
// id of the parent resource, used to get the absolute url of the current resource
|
|
565
|
+
_defineProperty(this, "serverPagination", void 0);
|
|
566
|
+
// pagination attributes to give to server
|
|
567
|
+
_defineProperty(this, "serverSearch", void 0);
|
|
554
568
|
this.clientContext = clientContext;
|
|
555
569
|
this.serverContext = serverContext;
|
|
556
570
|
this.parentId = parentId;
|
|
557
|
-
this.resource = this.expandProperties({
|
|
571
|
+
this.resource = this.expandProperties({
|
|
572
|
+
...resource
|
|
558
573
|
}, serverContext);
|
|
559
574
|
this.resourceId = resourceId;
|
|
575
|
+
this.serverPagination = serverPagination;
|
|
576
|
+
this.serverSearch = serverSearch;
|
|
560
577
|
}
|
|
578
|
+
|
|
561
579
|
/**
|
|
562
580
|
* Expand all predicates of a resource with a given context
|
|
563
581
|
* @param resource: object
|
|
564
582
|
* @param context: object
|
|
565
583
|
*/
|
|
566
|
-
|
|
567
|
-
|
|
568
584
|
expandProperties(resource, context) {
|
|
569
585
|
for (let prop of Object.keys(resource)) {
|
|
570
586
|
if (!prop) continue;
|
|
571
587
|
this.objectReplaceProperty(resource, prop, ContextParser.expandTerm(prop, context, true));
|
|
572
588
|
}
|
|
573
|
-
|
|
574
589
|
return resource;
|
|
575
590
|
}
|
|
591
|
+
|
|
576
592
|
/**
|
|
577
593
|
* Change the key of an object
|
|
578
594
|
* @param object: object
|
|
579
595
|
* @param oldProp: string - current key
|
|
580
596
|
* @param newProp: string - new key to set
|
|
581
597
|
*/
|
|
582
|
-
|
|
583
|
-
|
|
584
598
|
objectReplaceProperty(object, oldProp, newProp) {
|
|
585
599
|
if (newProp !== oldProp) {
|
|
586
600
|
Object.defineProperty(object, newProp, Object.getOwnPropertyDescriptor(object, oldProp) || '');
|
|
587
601
|
delete object[oldProp];
|
|
588
602
|
}
|
|
589
603
|
}
|
|
604
|
+
|
|
590
605
|
/**
|
|
591
606
|
* Get the property of a resource for a given path
|
|
592
607
|
* @param path: string
|
|
593
608
|
*/
|
|
594
|
-
|
|
595
|
-
|
|
596
609
|
async get(path) {
|
|
597
610
|
if (!path) return;
|
|
598
611
|
const path1 = path.split('.');
|
|
599
612
|
const path2 = [];
|
|
600
613
|
let value;
|
|
601
|
-
|
|
602
614
|
if (!this.isFullResource()) {
|
|
603
615
|
// if resource is not complete, fetch it first
|
|
604
616
|
await this.getResource(this.resourceId, this.clientContext, this.parentId);
|
|
605
617
|
}
|
|
606
|
-
|
|
607
618
|
while (true) {
|
|
608
619
|
try {
|
|
609
620
|
value = this.resource[this.getExpandedPredicate(path1[0])];
|
|
610
621
|
} catch (e) {
|
|
611
622
|
break;
|
|
612
623
|
}
|
|
613
|
-
|
|
614
624
|
if (path1.length <= 1) break; // no dot path
|
|
615
|
-
|
|
616
625
|
const lastPath1El = path1.pop();
|
|
617
626
|
if (lastPath1El) path2.unshift(lastPath1El);
|
|
618
627
|
}
|
|
619
|
-
|
|
620
628
|
if (path2.length === 0) {
|
|
621
629
|
// end of the path
|
|
622
630
|
if (!value || !value['@id']) return value; // no value or not a resource
|
|
623
|
-
|
|
624
631
|
return await this.getResource(value['@id'], this.clientContext, this.parentId || this.resourceId); // return complete resource
|
|
625
632
|
}
|
|
626
633
|
|
|
@@ -629,85 +636,75 @@ class CustomGetter {
|
|
|
629
636
|
store.subscribeResourceTo(this.resourceId, value['@id']);
|
|
630
637
|
return resource ? await resource[path2.join('.')] : undefined; // return value
|
|
631
638
|
}
|
|
639
|
+
|
|
632
640
|
/**
|
|
633
641
|
* Cache resource in the store, and return the created proxy
|
|
634
642
|
* @param id
|
|
635
643
|
* @param context
|
|
636
644
|
* @param iriParent
|
|
645
|
+
* @param forceFetch
|
|
637
646
|
*/
|
|
638
|
-
|
|
639
|
-
|
|
640
647
|
async getResource(id, context, iriParent) {
|
|
641
|
-
|
|
648
|
+
let forceFetch = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
649
|
+
return store.getData(id, context, iriParent, undefined, forceFetch);
|
|
642
650
|
}
|
|
651
|
+
|
|
643
652
|
/**
|
|
644
653
|
* Return true if the resource is a container
|
|
645
654
|
*/
|
|
646
|
-
|
|
647
|
-
|
|
648
655
|
isContainer() {
|
|
649
656
|
return this.resource["@type"] == "ldp:Container" || this.resource["@type"] == "sib:federatedContainer";
|
|
650
657
|
}
|
|
658
|
+
|
|
651
659
|
/**
|
|
652
660
|
* Get all properties of a resource
|
|
653
661
|
*/
|
|
654
|
-
|
|
655
|
-
|
|
656
662
|
getProperties() {
|
|
657
663
|
return Object.keys(this.resource).map(prop => this.getCompactedPredicate(prop));
|
|
658
664
|
}
|
|
665
|
+
|
|
659
666
|
/**
|
|
660
667
|
* Get children of container as objects
|
|
661
668
|
*/
|
|
662
|
-
|
|
663
|
-
|
|
664
669
|
getChildren() {
|
|
665
670
|
return this.resource[this.getExpandedPredicate("ldp:contains")] || [];
|
|
666
671
|
}
|
|
672
|
+
|
|
667
673
|
/**
|
|
668
674
|
* Get children of container as Proxys
|
|
669
675
|
*/
|
|
670
|
-
|
|
671
|
-
|
|
672
676
|
getLdpContains() {
|
|
673
677
|
const children = this.resource[this.getExpandedPredicate("ldp:contains")];
|
|
674
678
|
return children ? children.map(res => store.get(res['@id'])) : [];
|
|
675
679
|
}
|
|
680
|
+
|
|
676
681
|
/**
|
|
677
682
|
* Get all nested resource or containers which contains datas
|
|
678
683
|
*/
|
|
679
|
-
|
|
680
|
-
|
|
681
684
|
getSubObjects() {
|
|
682
685
|
let subObjects = [];
|
|
683
|
-
|
|
684
686
|
for (let p of Object.keys(this.resource)) {
|
|
685
687
|
let property = this.resource[p];
|
|
686
688
|
if (!this.isFullNestedResource(property)) continue; // if not a resource, stop
|
|
687
|
-
|
|
688
689
|
if (property['@type'] == "ldp:Container" && (property['ldp:contains'] == undefined || property['ldp:contains'].length >= 1 && !this.isFullNestedResource(property['ldp:contains'][0]))) continue; // if not a full container
|
|
689
|
-
|
|
690
690
|
subObjects.push(property);
|
|
691
691
|
}
|
|
692
|
-
|
|
693
692
|
return subObjects;
|
|
694
693
|
}
|
|
695
|
-
|
|
696
694
|
merge(resource) {
|
|
697
|
-
this.resource = {
|
|
695
|
+
this.resource = {
|
|
696
|
+
...this.getResourceData(),
|
|
698
697
|
...resource.getResourceData()
|
|
699
698
|
};
|
|
700
699
|
}
|
|
701
|
-
|
|
702
700
|
getResourceData() {
|
|
703
701
|
return this.resource;
|
|
704
702
|
}
|
|
703
|
+
|
|
705
704
|
/**
|
|
706
705
|
* return true if prop is a resource with an @id and some properties
|
|
707
706
|
* @param prop
|
|
708
707
|
*/
|
|
709
|
-
|
|
710
|
-
|
|
711
708
|
isFullNestedResource(prop) {
|
|
712
709
|
return prop && typeof prop == "object" && prop['@id'] != undefined && Object.keys(prop).filter(p => !p.startsWith('@')).length > 0;
|
|
713
710
|
}
|
|
@@ -715,88 +712,76 @@ class CustomGetter {
|
|
|
715
712
|
* return true resource seems complete
|
|
716
713
|
* @param prop
|
|
717
714
|
*/
|
|
718
|
-
|
|
719
|
-
|
|
720
715
|
isFullResource() {
|
|
721
716
|
return Object.keys(this.resource).filter(p => !p.startsWith('@')).length > 0;
|
|
722
717
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
718
|
+
async getPermissions() {
|
|
719
|
+
const permissionPredicate = this.getExpandedPredicate("permissions");
|
|
720
|
+
let permissions = this.resource[permissionPredicate];
|
|
721
|
+
if (!permissions) {
|
|
722
|
+
// if no permission, re-fetch data
|
|
723
|
+
await this.getResource(this.resourceId, this.clientContext, this.parentId, true);
|
|
724
|
+
permissions = this.resource[permissionPredicate];
|
|
725
|
+
}
|
|
726
726
|
return permissions ? permissions.map(perm => ContextParser.expandTerm(perm.mode['@type'], this.serverContext, true)) : [];
|
|
727
727
|
}
|
|
728
|
+
|
|
728
729
|
/**
|
|
729
730
|
* Remove the resource from the cache
|
|
730
731
|
*/
|
|
731
|
-
|
|
732
|
-
|
|
733
732
|
clearCache() {
|
|
734
733
|
store.clearCache(this.resourceId);
|
|
735
734
|
}
|
|
736
|
-
|
|
737
735
|
getExpandedPredicate(property) {
|
|
738
736
|
return ContextParser.expandTerm(property, this.clientContext, true);
|
|
739
737
|
}
|
|
740
|
-
|
|
741
738
|
getCompactedPredicate(property) {
|
|
742
739
|
return ContextParser.compactIri(property, this.clientContext, true);
|
|
743
740
|
}
|
|
744
|
-
|
|
745
741
|
getCompactedIri(id) {
|
|
746
742
|
return ContextParser.compactIri(id, this.clientContext);
|
|
747
743
|
}
|
|
748
|
-
|
|
749
744
|
toString() {
|
|
750
745
|
return this.getCompactedIri(this.resource['@id']);
|
|
751
746
|
}
|
|
752
|
-
|
|
753
747
|
[_Symbol$toPrimitive]() {
|
|
754
748
|
return this.getCompactedIri(this.resource['@id']);
|
|
755
749
|
}
|
|
750
|
+
|
|
756
751
|
/**
|
|
757
752
|
* Returns a Proxy which handles the different get requests
|
|
758
753
|
*/
|
|
759
|
-
|
|
760
|
-
|
|
761
754
|
getProxy() {
|
|
762
755
|
return new Proxy(this, {
|
|
763
756
|
get: (resource, property) => {
|
|
764
757
|
if (!this.resource) return undefined;
|
|
765
758
|
if (typeof resource[property] === 'function') return resource[property].bind(resource);
|
|
766
|
-
|
|
767
759
|
switch (property) {
|
|
768
760
|
case '@id':
|
|
769
|
-
return this.getCompactedIri(this.resource['@id']);
|
|
770
|
-
|
|
771
|
-
|
|
761
|
+
if (this.resource['@id']) return this.getCompactedIri(this.resource['@id']); // Compact @id if possible
|
|
762
|
+
else console.log(this.resource, this.resource['@id']);
|
|
763
|
+
return;
|
|
772
764
|
case '@type':
|
|
773
765
|
return this.resource['@type'];
|
|
774
766
|
// return synchronously
|
|
775
|
-
|
|
776
767
|
case 'properties':
|
|
777
768
|
return this.getProperties();
|
|
778
|
-
|
|
779
769
|
case 'ldp:contains':
|
|
780
770
|
return this.getLdpContains();
|
|
781
771
|
// returns standard arrays synchronously
|
|
782
|
-
|
|
783
772
|
case 'permissions':
|
|
784
773
|
return this.getPermissions();
|
|
785
774
|
// get expanded permissions
|
|
786
|
-
|
|
787
775
|
case 'clientContext':
|
|
788
776
|
return this.clientContext;
|
|
789
777
|
// get saved client context to re-fetch easily a resource
|
|
790
|
-
|
|
791
778
|
case 'then':
|
|
792
779
|
return;
|
|
793
|
-
|
|
794
780
|
default:
|
|
781
|
+
// FIXME: missing 'await'
|
|
795
782
|
return resource.get(property);
|
|
796
783
|
}
|
|
797
784
|
}
|
|
798
785
|
});
|
|
799
786
|
}
|
|
800
|
-
|
|
801
|
-
}
|
|
802
|
-
//# sourceMappingURL=store.js.map
|
|
787
|
+
}
|