@startinblox/core 0.18.0-beta.4 → 0.18.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/common/{_baseUnary-d2677655.js → _baseUnary-c1edb653.js} +2 -2
- package/dist/_snowpack/pkg/common/{_baseUnary-d2677655.js.map → _baseUnary-c1edb653.js.map} +1 -1
- package/dist/_snowpack/pkg/common/{_commonjsHelpers-0597c316.js → _commonjsHelpers-37fa8da4.js} +2 -2
- package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js.map +1 -0
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js +2 -2
- package/dist/_snowpack/pkg/dialog-polyfill.js +2 -1
- package/dist/_snowpack/pkg/dialog-polyfill.js.map +1 -1
- package/dist/_snowpack/pkg/import-map.json +0 -1
- package/dist/_snowpack/pkg/jsonld-context-parser.js +1 -1
- package/dist/_snowpack/pkg/markdown-it.js +1 -1
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js +2 -2
- package/dist/_snowpack/pkg/quill.js +11644 -11643
- package/dist/_snowpack/pkg/quill.js.map +1 -1
- package/dist/_snowpack/pkg/tui-calendar.js +43199 -43195
- package/dist/_snowpack/pkg/tui-calendar.js.map +1 -1
- package/dist/components/solid-form-search.js +2 -1
- package/dist/components/solid-form.js +4 -2
- package/dist/libs/ComponentFactory.js +4 -1
- package/dist/libs/filter.js +1 -1
- package/dist/libs/helpers.js +10 -4
- package/dist/libs/lit-helpers.js +4 -1
- package/dist/libs/polyfills.js +4 -2
- package/dist/libs/store/server-pagination.js +7 -4
- package/dist/libs/store/server-search.js +7 -4
- package/dist/libs/store/store.js +346 -92
- package/dist/mixins/attributeBinderMixin.js +6 -3
- package/dist/mixins/federationMixin.js +0 -6
- package/dist/mixins/filterMixin.js +16 -13
- package/dist/mixins/listMixin.js +9 -20
- package/dist/mixins/requiredMixin.js +3 -15
- package/dist/mixins/storeMixin.js +0 -30
- package/dist/mixins/widgetMixin.js +5 -12
- package/dist/new-widgets/templates/formTemplatesDirectory.js +15 -6
- package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +0 -3
- package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +3 -7
- package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +2 -11
- package/dist/widgets/baseWidget.js +5 -4
- package/dist/widgets/widget-factory.js +3 -1
- package/package.json +4 -5
- package/dist/_snowpack/pkg/common/_commonjsHelpers-0597c316.js.map +0 -1
- package/dist/_snowpack/pkg/jsonld.js +0 -11760
- package/dist/_snowpack/pkg/jsonld.js.map +0 -1
- package/dist/libs/store/custom-getter.js +0 -344
package/dist/libs/store/store.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
let _Symbol$toPrimitive;
|
|
1
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; }
|
|
2
3
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
3
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); }
|
|
4
5
|
import JSONLDContextParser from '../../_snowpack/pkg/jsonld-context-parser.js';
|
|
5
6
|
//@ts-ignore
|
|
6
7
|
import PubSub from 'https://cdn.skypack.dev/pubsub-js';
|
|
7
|
-
import jsonld from '../../_snowpack/pkg/jsonld.js';
|
|
8
|
-
import { CustomGetter } from './custom-getter.js';
|
|
9
8
|
import { appendServerSearchToIri } from './server-search.js';
|
|
10
9
|
import { appendServerPaginationToIri } from './server-pagination.js';
|
|
11
10
|
const ContextParser = JSONLDContextParser.ContextParser;
|
|
@@ -68,13 +67,18 @@ class Store {
|
|
|
68
67
|
* @param forceFetch - force the fetch of data
|
|
69
68
|
* @param serverPagination - Server pagination options
|
|
70
69
|
* @param serverSearch - Server search options
|
|
71
|
-
*
|
|
72
|
-
*
|
|
70
|
+
*
|
|
73
71
|
* @returns The fetched resource
|
|
74
72
|
*
|
|
75
73
|
* @async
|
|
76
74
|
*/
|
|
77
|
-
async getData(id
|
|
75
|
+
async getData(id) {
|
|
76
|
+
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
77
|
+
let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
|
|
78
|
+
let localData = arguments.length > 3 ? arguments[3] : undefined;
|
|
79
|
+
let forceFetch = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
80
|
+
let serverPagination = arguments.length > 5 ? arguments[5] : undefined;
|
|
81
|
+
let serverSearch = arguments.length > 6 ? arguments[6] : undefined;
|
|
78
82
|
let key = id;
|
|
79
83
|
if (serverPagination) {
|
|
80
84
|
key = id + "#p" + serverPagination.limit + "?o" + serverPagination.offset;
|
|
@@ -110,9 +114,9 @@ class Store {
|
|
|
110
114
|
return;
|
|
111
115
|
}
|
|
112
116
|
const serverContext = await myParser.parse([resource['@context'] || {}]);
|
|
113
|
-
|
|
117
|
+
const resourceProxy = new CustomGetter(key, resource, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch).getProxy();
|
|
114
118
|
// Cache proxy
|
|
115
|
-
await this.cacheGraph(
|
|
119
|
+
await this.cacheGraph(key, resourceProxy, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch);
|
|
116
120
|
this.loadingList.delete(key);
|
|
117
121
|
document.dispatchEvent(new CustomEvent('resourceReady', {
|
|
118
122
|
detail: {
|
|
@@ -140,17 +144,11 @@ class Store {
|
|
|
140
144
|
});
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
* @param idParent - id of the caller resource. Needed to expand id
|
|
149
|
-
* @param serverPagination - Server pagination query params
|
|
150
|
-
* @param serverSearch - Server search query params
|
|
151
|
-
* @returns data in json
|
|
152
|
-
*/
|
|
153
|
-
async fetchData(id, context = {}, parentId = "", serverPagination, serverSearch) {
|
|
147
|
+
async fetchData(id) {
|
|
148
|
+
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
149
|
+
let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
|
|
150
|
+
let serverPagination = arguments.length > 3 ? arguments[3] : undefined;
|
|
151
|
+
let serverSearch = arguments.length > 4 ? arguments[4] : undefined;
|
|
154
152
|
let iri = this._getAbsoluteIri(id, context, parentId);
|
|
155
153
|
if (serverPagination) iri = appendServerPaginationToIri(iri, serverPagination);
|
|
156
154
|
if (serverSearch) iri = appendServerSearchToIri(iri, serverSearch);
|
|
@@ -160,12 +158,6 @@ class Store {
|
|
|
160
158
|
// 'Prefer' : 'return=representation; max-triple-count="100"' // Commenting out for now as it raises CORS errors
|
|
161
159
|
};
|
|
162
160
|
|
|
163
|
-
/**
|
|
164
|
-
* Fetch data with authentication if available (sib-auth)
|
|
165
|
-
* @param iri - iri to call
|
|
166
|
-
* @param options - options of the request
|
|
167
|
-
* @returns - response
|
|
168
|
-
*/
|
|
169
161
|
return this.fetchAuthn(iri, {
|
|
170
162
|
method: 'GET',
|
|
171
163
|
headers: headers,
|
|
@@ -175,51 +167,59 @@ class Store {
|
|
|
175
167
|
return response.json();
|
|
176
168
|
});
|
|
177
169
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
* @param clientContext - context of the client app
|
|
183
|
-
* @param parentContext - context of the server
|
|
184
|
-
* @param parentId - id of the parent caller
|
|
185
|
-
* @param serverPagination - Server pagination query params
|
|
186
|
-
* @param serverSearch - Server search query params
|
|
187
|
-
*/
|
|
188
|
-
async cacheGraph(resource, clientContext, parentContext, parentId, serverPagination, serverSearch) {
|
|
189
|
-
const flattenedResources = await jsonld.flatten(resource);
|
|
190
|
-
const compactedResources = await Promise.all(flattenedResources.map(r => jsonld.compact(r, {})));
|
|
191
|
-
for (let resource of compactedResources) {
|
|
192
|
-
let id = resource['@id'] || resource['id'];
|
|
193
|
-
let key = resource['@id'] || resource['id'];
|
|
194
|
-
if (!key) console.log('No key or id for resource:', resource);
|
|
195
|
-
if (key === '/') key = parentId;
|
|
196
|
-
if (key.startsWith('_:b')) key = key + parentId; // anonymous node -> change key before saving in cache
|
|
197
|
-
|
|
198
|
-
// We have to add the server search and pagination attributes again here to the resource cache key
|
|
199
|
-
if (key === id && resource['@type'] == this.getExpandedPredicate("ldp:Container", clientContext)) {
|
|
200
|
-
// Add only pagination and search params to the original resource
|
|
201
|
-
if (serverPagination) key = key + "#p" + serverPagination.limit + "?o" + serverPagination.offset;
|
|
202
|
-
if (serverSearch) key = appendServerSearchToIri(key, serverSearch);
|
|
203
|
-
}
|
|
204
|
-
const resourceProxy = new CustomGetter(key, resource, clientContext, parentContext, parentId, serverPagination, serverSearch).getProxy();
|
|
205
|
-
if (resourceProxy.isContainer()) this.subscribeChildren(resourceProxy, id);
|
|
206
|
-
if (this.get(key)) {
|
|
170
|
+
async cacheGraph(key, resource, clientContext, parentContext, parentId, serverPagination, serverSearch) {
|
|
171
|
+
if (resource.properties) {
|
|
172
|
+
// if proxy, cache it
|
|
173
|
+
if (this.get(key) && this.cache.get(key).merge) {
|
|
207
174
|
// if already cached, merge data
|
|
208
|
-
this.cache.get(key).merge(
|
|
175
|
+
this.cache.get(key).merge(resource);
|
|
176
|
+
;
|
|
209
177
|
} else {
|
|
210
178
|
// else, put in cache
|
|
211
|
-
this.
|
|
179
|
+
this.cache.set(key, resource);
|
|
212
180
|
}
|
|
213
181
|
}
|
|
214
|
-
}
|
|
215
182
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
183
|
+
// Cache nested resources
|
|
184
|
+
if (resource.getSubObjects) {
|
|
185
|
+
for (let res of resource.getSubObjects()) {
|
|
186
|
+
let newParentContext = parentContext;
|
|
187
|
+
// If additional context in resource, use it to expand properties
|
|
188
|
+
if (res['@context']) newParentContext = await myParser.parse({
|
|
189
|
+
...parentContext,
|
|
190
|
+
...res['@context']
|
|
191
|
+
});
|
|
192
|
+
const resourceProxy = new CustomGetter(res['@id'], res, clientContext, newParentContext, parentId).getProxy();
|
|
193
|
+
// this.subscribeResourceTo(resource['@id'], res['@id']); // removed to prevent useless updates
|
|
194
|
+
await this.cacheGraph(res['@id'], resourceProxy, clientContext, parentContext, parentId, serverPagination, serverSearch);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Cache children of container
|
|
199
|
+
if (resource['@type'] == "ldp:Container" && resource.getChildren) {
|
|
200
|
+
const cacheChildrenPromises = [];
|
|
201
|
+
|
|
202
|
+
//TODO: return complete object without the need for the fetch data from the cacheGraph
|
|
203
|
+
for (let res of await resource.getChildren()) {
|
|
204
|
+
this.subscribeResourceTo(resource['@id'], res['@id']);
|
|
205
|
+
cacheChildrenPromises.push(this.cacheGraph(res['@id'], res, clientContext, parentContext, parentId, serverPagination, serverSearch));
|
|
206
|
+
}
|
|
207
|
+
await Promise.all(cacheChildrenPromises);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Create proxy, (fetch data) and cache resource
|
|
212
|
+
if (resource['@id'] && !resource.properties) {
|
|
213
|
+
if (resource['@id'].match(/^b\d+$/)) return; // not anonymous node
|
|
214
|
+
// Fetch data if
|
|
215
|
+
if (resource['@type'] === "sib:federatedContainer" && resource['@cache'] !== 'false') {
|
|
216
|
+
// if object is federated container
|
|
217
|
+
await this.getData(resource['@id'], clientContext, parentId); // then init graph
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const resourceProxy = new CustomGetter(key, resource, clientContext, parentContext, parentId).getProxy();
|
|
221
|
+
await this.cacheGraph(key, resourceProxy, clientContext, parentContext, parentId);
|
|
222
|
+
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
/**
|
|
@@ -247,25 +247,6 @@ class Store {
|
|
|
247
247
|
ok: true
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Subscribe all the children of a container to its parent
|
|
253
|
-
* @param container
|
|
254
|
-
*/
|
|
255
|
-
subscribeChildren(container, containerId) {
|
|
256
|
-
if (!container['ldp:contains']) return;
|
|
257
|
-
for (let res of container['ldp:contains']) {
|
|
258
|
-
this.subscribeResourceTo(containerId, res['@id'] || res['id']);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Update a resource
|
|
264
|
-
* @param method - can be POST, PUT or PATCH
|
|
265
|
-
* @param resource - content of the updated resource
|
|
266
|
-
* @param id - id of the resource to update
|
|
267
|
-
* @returns void
|
|
268
|
-
*/
|
|
269
250
|
async _updateResource(method, resource, id) {
|
|
270
251
|
if (!['POST', 'PUT', 'PATCH', '_LOCAL'].includes(method)) throw new Error('Error: method not allowed');
|
|
271
252
|
const context = await myParser.parse([resource['@context'] || {}]); // parse context before expandTerm
|
|
@@ -306,10 +287,13 @@ class Store {
|
|
|
306
287
|
for (const resource of resourceWithContexts) {
|
|
307
288
|
if (!this._isLocalId(resource.id)) this.clearCache(resource.id);
|
|
308
289
|
}
|
|
309
|
-
await Promise.all(resourceWithContexts.map(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
290
|
+
await Promise.all(resourceWithContexts.map(_ref => {
|
|
291
|
+
let {
|
|
292
|
+
id,
|
|
293
|
+
context
|
|
294
|
+
} = _ref;
|
|
295
|
+
return this.getData(id, context || base_context);
|
|
296
|
+
}));
|
|
313
297
|
return resourceIds;
|
|
314
298
|
}
|
|
315
299
|
/**
|
|
@@ -453,7 +437,8 @@ class Store {
|
|
|
453
437
|
*
|
|
454
438
|
* @returns id of the deleted resource
|
|
455
439
|
*/
|
|
456
|
-
async delete(id
|
|
440
|
+
async delete(id) {
|
|
441
|
+
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
457
442
|
const expandedId = this._getExpandedId(id, context);
|
|
458
443
|
const deleted = await this.fetchAuthn(expandedId, {
|
|
459
444
|
method: 'DELETE',
|
|
@@ -483,9 +468,6 @@ class Store {
|
|
|
483
468
|
_getExpandedId(id, context) {
|
|
484
469
|
return context && Object.keys(context) ? ContextParser.expandTerm(id, context) : id;
|
|
485
470
|
}
|
|
486
|
-
getExpandedPredicate(property, context) {
|
|
487
|
-
return ContextParser.expandTerm(property, context, true);
|
|
488
|
-
}
|
|
489
471
|
_isLocalId(id) {
|
|
490
472
|
return id.startsWith('store://local.');
|
|
491
473
|
}
|
|
@@ -518,7 +500,7 @@ class Store {
|
|
|
518
500
|
*/
|
|
519
501
|
_getAbsoluteIri(id, context, parentId) {
|
|
520
502
|
let iri = ContextParser.expandTerm(id, context); // expand if reduced ids
|
|
521
|
-
if (parentId
|
|
503
|
+
if (parentId) {
|
|
522
504
|
// and get full URL from parent caller for local files
|
|
523
505
|
let parentIri = new URL(parentId, document.location.href).href;
|
|
524
506
|
iri = new URL(iri, parentIri).href;
|
|
@@ -528,6 +510,14 @@ class Store {
|
|
|
528
510
|
return iri;
|
|
529
511
|
}
|
|
530
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Check if object is a full resource
|
|
515
|
+
* @param resource
|
|
516
|
+
*/
|
|
517
|
+
_resourceIsComplete(resource) {
|
|
518
|
+
return !!(Object.keys(resource).filter(p => !p.startsWith('@')).length > 0 && resource['@id']);
|
|
519
|
+
}
|
|
520
|
+
|
|
531
521
|
/**
|
|
532
522
|
* Return language of the users
|
|
533
523
|
*/
|
|
@@ -557,4 +547,268 @@ if (window.sibStore) {
|
|
|
557
547
|
store = new Store(storeOptions);
|
|
558
548
|
window.sibStore = store;
|
|
559
549
|
}
|
|
560
|
-
export { store };
|
|
550
|
+
export { store };
|
|
551
|
+
_Symbol$toPrimitive = Symbol.toPrimitive;
|
|
552
|
+
class CustomGetter {
|
|
553
|
+
// search attributes to give to server
|
|
554
|
+
|
|
555
|
+
constructor(resourceId, resource, clientContext, serverContext) {
|
|
556
|
+
let parentId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
|
|
557
|
+
let serverPagination = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
558
|
+
let serverSearch = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
|
|
559
|
+
_defineProperty(this, "resource", void 0);
|
|
560
|
+
// content of the requested resource
|
|
561
|
+
_defineProperty(this, "resourceId", void 0);
|
|
562
|
+
_defineProperty(this, "clientContext", void 0);
|
|
563
|
+
// context given by the app
|
|
564
|
+
_defineProperty(this, "serverContext", void 0);
|
|
565
|
+
// context given by the server
|
|
566
|
+
_defineProperty(this, "parentId", void 0);
|
|
567
|
+
// id of the parent resource, used to get the absolute url of the current resource
|
|
568
|
+
_defineProperty(this, "serverPagination", void 0);
|
|
569
|
+
// pagination attributes to give to server
|
|
570
|
+
_defineProperty(this, "serverSearch", void 0);
|
|
571
|
+
this.clientContext = clientContext;
|
|
572
|
+
this.serverContext = serverContext;
|
|
573
|
+
this.parentId = parentId;
|
|
574
|
+
this.resource = this.expandProperties({
|
|
575
|
+
...resource
|
|
576
|
+
}, {
|
|
577
|
+
...serverContext,
|
|
578
|
+
...clientContext
|
|
579
|
+
});
|
|
580
|
+
this.resourceId = resourceId;
|
|
581
|
+
this.serverPagination = serverPagination;
|
|
582
|
+
this.serverSearch = serverSearch;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Expand all predicates of a resource with a given context
|
|
587
|
+
* @param resource: object
|
|
588
|
+
* @param context: object
|
|
589
|
+
*/
|
|
590
|
+
expandProperties(resource, context) {
|
|
591
|
+
for (let prop of Object.keys(resource)) {
|
|
592
|
+
if (!prop) continue;
|
|
593
|
+
this.objectReplaceProperty(resource, prop, ContextParser.expandTerm(prop, context, true));
|
|
594
|
+
}
|
|
595
|
+
return resource;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Change the key of an object
|
|
600
|
+
* @param object: object
|
|
601
|
+
* @param oldProp: string - current key
|
|
602
|
+
* @param newProp: string - new key to set
|
|
603
|
+
*/
|
|
604
|
+
objectReplaceProperty(object, oldProp, newProp) {
|
|
605
|
+
if (newProp !== oldProp) {
|
|
606
|
+
Object.defineProperty(object, newProp, Object.getOwnPropertyDescriptor(object, oldProp) || '');
|
|
607
|
+
delete object[oldProp];
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Get the property of a resource for a given path
|
|
613
|
+
* @param path: string
|
|
614
|
+
*/
|
|
615
|
+
async get(path) {
|
|
616
|
+
if (!path) return;
|
|
617
|
+
const path1 = path.split('.');
|
|
618
|
+
const path2 = [];
|
|
619
|
+
let value;
|
|
620
|
+
if (!this.isFullResource()) {
|
|
621
|
+
// if resource is not complete, fetch it first
|
|
622
|
+
await this.getResource(this.resourceId, {
|
|
623
|
+
...this.serverContext,
|
|
624
|
+
...this.clientContext
|
|
625
|
+
}, this.parentId);
|
|
626
|
+
}
|
|
627
|
+
while (true) {
|
|
628
|
+
try {
|
|
629
|
+
value = this.resource[this.getExpandedPredicate(path1[0])];
|
|
630
|
+
} catch (e) {
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
if (path1.length <= 1) break; // no dot path
|
|
634
|
+
const lastPath1El = path1.pop();
|
|
635
|
+
if (lastPath1El) path2.unshift(lastPath1El);
|
|
636
|
+
}
|
|
637
|
+
if (path2.length === 0) {
|
|
638
|
+
// end of the path
|
|
639
|
+
if (!value || !value['@id']) return value; // no value or not a resource
|
|
640
|
+
return await this.getResource(value['@id'], {
|
|
641
|
+
...this.serverContext,
|
|
642
|
+
...this.clientContext
|
|
643
|
+
}, this.parentId || this.resourceId); // return complete resource
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (!value) return undefined;
|
|
647
|
+
let resource = await this.getResource(value['@id'], {
|
|
648
|
+
...this.serverContext,
|
|
649
|
+
...this.clientContext
|
|
650
|
+
}, this.parentId || this.resourceId);
|
|
651
|
+
store.subscribeResourceTo(this.resourceId, value['@id']);
|
|
652
|
+
return resource ? await resource[path2.join('.')] : undefined; // return value
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Cache resource in the store, and return the created proxy
|
|
657
|
+
* @param id
|
|
658
|
+
* @param context
|
|
659
|
+
* @param iriParent
|
|
660
|
+
* @param forceFetch
|
|
661
|
+
*/
|
|
662
|
+
async getResource(id, context, iriParent) {
|
|
663
|
+
let forceFetch = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
664
|
+
return store.getData(id, context, iriParent, undefined, forceFetch);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Return true if the resource is a container
|
|
669
|
+
*/
|
|
670
|
+
isContainer() {
|
|
671
|
+
return this.resource["@type"] == "ldp:Container" || this.resource["@type"] == "sib:federatedContainer";
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Get all properties of a resource
|
|
676
|
+
*/
|
|
677
|
+
getProperties() {
|
|
678
|
+
return Object.keys(this.resource).map(prop => this.getCompactedPredicate(prop));
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Get children of container as objects
|
|
683
|
+
*/
|
|
684
|
+
getChildren() {
|
|
685
|
+
return this.resource[this.getExpandedPredicate("ldp:contains")] || [];
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Get children of container as Proxys
|
|
690
|
+
*/
|
|
691
|
+
getLdpContains() {
|
|
692
|
+
const children = this.resource[this.getExpandedPredicate("ldp:contains")];
|
|
693
|
+
return children ? children.map(res => store.get(res['@id'])) : [];
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Get all nested resource or containers which contains datas
|
|
698
|
+
*/
|
|
699
|
+
getSubObjects() {
|
|
700
|
+
let subObjects = [];
|
|
701
|
+
for (let p of Object.keys(this.resource)) {
|
|
702
|
+
let property = this.resource[p];
|
|
703
|
+
if (!this.isFullNestedResource(property)) continue; // if not a resource, stop
|
|
704
|
+
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
|
|
705
|
+
subObjects.push(property);
|
|
706
|
+
}
|
|
707
|
+
return subObjects;
|
|
708
|
+
}
|
|
709
|
+
merge(resource) {
|
|
710
|
+
this.resource = {
|
|
711
|
+
...this.getResourceData(),
|
|
712
|
+
...resource.getResourceData()
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
getResourceData() {
|
|
716
|
+
return this.resource;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* return true if prop is a resource with an @id and some properties
|
|
721
|
+
* @param prop
|
|
722
|
+
*/
|
|
723
|
+
isFullNestedResource(prop) {
|
|
724
|
+
return prop && typeof prop == "object" && prop['@id'] != undefined && Object.keys(prop).filter(p => !p.startsWith('@')).length > 0;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* return true resource seems complete
|
|
728
|
+
* @param prop
|
|
729
|
+
*/
|
|
730
|
+
isFullResource() {
|
|
731
|
+
return Object.keys(this.resource).filter(p => !p.startsWith('@')).length > 0;
|
|
732
|
+
}
|
|
733
|
+
async getPermissions() {
|
|
734
|
+
const permissionPredicate = this.getExpandedPredicate("permissions");
|
|
735
|
+
let permissions = this.resource[permissionPredicate];
|
|
736
|
+
if (!permissions) {
|
|
737
|
+
// if no permission, re-fetch data
|
|
738
|
+
await this.getResource(this.resourceId, {
|
|
739
|
+
...this.serverContext,
|
|
740
|
+
...this.clientContext
|
|
741
|
+
}, this.parentId, true);
|
|
742
|
+
permissions = this.resource[permissionPredicate];
|
|
743
|
+
}
|
|
744
|
+
return permissions ? permissions.map(perm => ContextParser.expandTerm(perm.mode['@type'], this.serverContext, true)) : [];
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Remove the resource from the cache
|
|
749
|
+
*/
|
|
750
|
+
clearCache() {
|
|
751
|
+
store.clearCache(this.resourceId);
|
|
752
|
+
}
|
|
753
|
+
getExpandedPredicate(property) {
|
|
754
|
+
return ContextParser.expandTerm(property, {
|
|
755
|
+
...this.serverContext,
|
|
756
|
+
...this.clientContext
|
|
757
|
+
}, true);
|
|
758
|
+
}
|
|
759
|
+
getCompactedPredicate(property) {
|
|
760
|
+
return ContextParser.compactIri(property, {
|
|
761
|
+
...this.serverContext,
|
|
762
|
+
...this.clientContext
|
|
763
|
+
}, true);
|
|
764
|
+
}
|
|
765
|
+
getCompactedIri(id) {
|
|
766
|
+
return ContextParser.compactIri(id, {
|
|
767
|
+
...this.serverContext,
|
|
768
|
+
...this.clientContext
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
toString() {
|
|
772
|
+
return this.getCompactedIri(this.resource['@id']);
|
|
773
|
+
}
|
|
774
|
+
[_Symbol$toPrimitive]() {
|
|
775
|
+
return this.getCompactedIri(this.resource['@id']);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Returns a Proxy which handles the different get requests
|
|
780
|
+
*/
|
|
781
|
+
getProxy() {
|
|
782
|
+
return new Proxy(this, {
|
|
783
|
+
get: (resource, property) => {
|
|
784
|
+
if (!this.resource) return undefined;
|
|
785
|
+
if (typeof resource[property] === 'function') return resource[property].bind(resource);
|
|
786
|
+
switch (property) {
|
|
787
|
+
case '@id':
|
|
788
|
+
if (this.resource['@id']) return this.getCompactedIri(this.resource['@id']); // Compact @id if possible
|
|
789
|
+
else console.log(this.resource, this.resource['@id']);
|
|
790
|
+
return;
|
|
791
|
+
case '@type':
|
|
792
|
+
return this.resource['@type'];
|
|
793
|
+
// return synchronously
|
|
794
|
+
case 'properties':
|
|
795
|
+
return this.getProperties();
|
|
796
|
+
case 'ldp:contains':
|
|
797
|
+
return this.getLdpContains();
|
|
798
|
+
// returns standard arrays synchronously
|
|
799
|
+
case 'permissions':
|
|
800
|
+
return this.getPermissions();
|
|
801
|
+
// get expanded permissions
|
|
802
|
+
case 'clientContext':
|
|
803
|
+
return this.clientContext;
|
|
804
|
+
// get saved client context to re-fetch easily a resource
|
|
805
|
+
case 'then':
|
|
806
|
+
return;
|
|
807
|
+
default:
|
|
808
|
+
// FIXME: missing 'await'
|
|
809
|
+
return resource.get(property);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
}
|
|
@@ -20,7 +20,8 @@ const AttributeBinderMixin = {
|
|
|
20
20
|
* Replace store://XXX attributes by corresponding data
|
|
21
21
|
* @param reset - set to false if no need to reset data
|
|
22
22
|
*/
|
|
23
|
-
async replaceAttributesData(
|
|
23
|
+
async replaceAttributesData() {
|
|
24
|
+
let reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
24
25
|
if (reset) this.resetAttributesData();
|
|
25
26
|
const oldAttributes = Array.from(this.element.attributes) // transform NamedNodeMap in object
|
|
26
27
|
.reduce((obj, attr) => {
|
|
@@ -58,7 +59,7 @@ const AttributeBinderMixin = {
|
|
|
58
59
|
const value = attributes[attr];
|
|
59
60
|
// Avoid error if value is a number
|
|
60
61
|
if (typeof value === 'string') {
|
|
61
|
-
// Replace attribute value
|
|
62
|
+
// Replace attribute value
|
|
62
63
|
if (!isContainer && resource && value.startsWith('store://resource')) {
|
|
63
64
|
// RESOURCE
|
|
64
65
|
let path = value.replace('store://resource.', '');
|
|
@@ -97,7 +98,9 @@ const AttributeBinderMixin = {
|
|
|
97
98
|
* @param maxRetries
|
|
98
99
|
* @returns
|
|
99
100
|
*/
|
|
100
|
-
async retry(fn
|
|
101
|
+
async retry(fn) {
|
|
102
|
+
let ms = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
|
|
103
|
+
let maxRetries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 5;
|
|
101
104
|
return new Promise((resolve, reject) => {
|
|
102
105
|
let retries = 0;
|
|
103
106
|
fn().then(resolve).catch(() => {
|
|
@@ -17,7 +17,6 @@ const FederationMixin = {
|
|
|
17
17
|
if (nextProcessor) await nextProcessor(newResources, listPostProcessors, div, context);
|
|
18
18
|
},
|
|
19
19
|
async getResources(resources) {
|
|
20
|
-
if (!resources) return [];
|
|
21
20
|
const newResources = [];
|
|
22
21
|
const getChildResources = async res => {
|
|
23
22
|
if (!res) return;
|
|
@@ -30,16 +29,11 @@ const FederationMixin = {
|
|
|
30
29
|
const resourcesFetched = await this.fetchSource(containerId); // fetch the resources of this container
|
|
31
30
|
if (resourcesFetched) newResources.push(...(await this.getResources(resourcesFetched))); // Add content of source to array...
|
|
32
31
|
}
|
|
33
|
-
} else if (!res.isArray?.()) {
|
|
34
|
-
const resource = await store.getData(res['@id'], this.context);
|
|
35
|
-
if (resource) newResources.push(resource);
|
|
36
32
|
} else {
|
|
37
33
|
newResources.push(res); // Or resource directly if not a container
|
|
38
34
|
}
|
|
39
35
|
};
|
|
40
36
|
|
|
41
|
-
// Special case for list support, if there is only one item it is serialized as an object, not an array
|
|
42
|
-
if (!Array.isArray(resources)) resources = [resources];
|
|
43
37
|
await Promise.all(resources.map(res => getChildResources(res)));
|
|
44
38
|
return newResources;
|
|
45
39
|
},
|
|
@@ -67,9 +67,12 @@ const FilterMixin = {
|
|
|
67
67
|
const filters = this.filters;
|
|
68
68
|
if (this.isFilteredOnServer() && filters) {
|
|
69
69
|
const fields = Object.keys(filters);
|
|
70
|
-
const value = Object.values(filters).map(
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const value = Object.values(filters).map(_ref => {
|
|
71
|
+
let {
|
|
72
|
+
value
|
|
73
|
+
} = _ref;
|
|
74
|
+
return value;
|
|
75
|
+
}).filter(value => !!value).join(' ').trim();
|
|
73
76
|
if (fields.length > 0 && value) {
|
|
74
77
|
return {
|
|
75
78
|
fields,
|
|
@@ -106,15 +109,14 @@ const FilterMixin = {
|
|
|
106
109
|
console.warn(`The format value of ${field} is not suitable with auto-range-[field] attribute`);
|
|
107
110
|
continue;
|
|
108
111
|
}
|
|
112
|
+
const nextArrayOfIds = nextArrayOfObjects['ldp:contains'];
|
|
113
|
+
for (const obj of nextArrayOfIds) {
|
|
114
|
+
// catch each element id
|
|
115
|
+
arrayOfDataIds.push(obj['@id']);
|
|
116
|
+
}
|
|
109
117
|
if (nextArrayOfObjects['@type'] !== 'ldp:Container') {
|
|
110
118
|
// if no element in 'ldp:contains', catch object id
|
|
111
119
|
arrayOfDataIds.push(nextArrayOfObjects['@id']);
|
|
112
|
-
} else {
|
|
113
|
-
if (!nextArrayOfObjects['ldp:contains']) continue;
|
|
114
|
-
for (const obj of nextArrayOfObjects['ldp:contains']) {
|
|
115
|
-
// catch each element id
|
|
116
|
-
arrayOfDataIds.push(obj['@id']);
|
|
117
|
-
}
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
return arrayOfDataIds;
|
|
@@ -139,10 +141,11 @@ const FilterMixin = {
|
|
|
139
141
|
name: attr['name'].replace('search-', ''),
|
|
140
142
|
value: attr['value']
|
|
141
143
|
}));
|
|
142
|
-
searchAttributes.forEach(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
searchAttributes.forEach(_ref2 => {
|
|
145
|
+
let {
|
|
146
|
+
name,
|
|
147
|
+
value
|
|
148
|
+
} = _ref2;
|
|
146
149
|
this.searchForm.setAttribute(name, value);
|
|
147
150
|
});
|
|
148
151
|
this.element.insertBefore(this.searchForm, this.element.firstChild);
|
package/dist/mixins/listMixin.js
CHANGED
|
@@ -43,32 +43,21 @@ const ListMixin = {
|
|
|
43
43
|
if (!this.resource) return;
|
|
44
44
|
|
|
45
45
|
// Not a container but a single resource
|
|
46
|
-
if (!this.resource.isContainer?.()
|
|
46
|
+
if (!this.resource.isContainer?.()) {
|
|
47
47
|
this.setElementAttribute("resource");
|
|
48
48
|
this.appendSingleElt(div);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
listPostProcessors.push(this.handleEmptyWidget.bind(this));
|
|
51
|
+
this.setElementAttribute("container");
|
|
52
|
+
const listPostProcessors = [...this.listPostProcessors];
|
|
53
|
+
this.renderCallbacks = [];
|
|
54
|
+
listPostProcessors.push(this.renderDOM.bind(this));
|
|
55
|
+
listPostProcessors.push(this.handleEmptyWidget.bind(this));
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
} else if (this.arrayField && this.predicateName && this.resource[this.predicateName]) {
|
|
62
|
-
this.setElementAttribute("container");
|
|
63
|
-
const listPostProcessors = [...this.listPostProcessors];
|
|
64
|
-
this.renderCallbacks = [];
|
|
65
|
-
listPostProcessors.push(this.renderDOM.bind(this));
|
|
66
|
-
listPostProcessors.push(this.handleEmptyWidget.bind(this));
|
|
57
|
+
// Execute the first post-processor of the list
|
|
58
|
+
const nextProcessor = listPostProcessors.shift();
|
|
59
|
+
await nextProcessor(this.resource['ldp:contains'], listPostProcessors, div, this.dataSrc);
|
|
67
60
|
|
|
68
|
-
// Execute the first post-processor of the list
|
|
69
|
-
const nextProcessor = listPostProcessors.shift();
|
|
70
|
-
await nextProcessor(await this.resource[this.predicateName], listPostProcessors, div, this.dataSrc);
|
|
71
|
-
}
|
|
72
61
|
// Execute the render callbacks
|
|
73
62
|
for (const renderCallback of this.renderCallbacks) {
|
|
74
63
|
// Render the template in the given parent element
|