@startinblox/core 0.18.1 → 0.19.0-beta.2
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-c1edb653.js → _baseUnary-d2677655.js} +2 -2
- package/dist/_snowpack/pkg/common/{_baseUnary-c1edb653.js.map → _baseUnary-d2677655.js.map} +1 -1
- package/dist/_snowpack/pkg/common/{_commonjsHelpers-37fa8da4.js → _commonjsHelpers-0597c316.js} +2 -2
- package/dist/_snowpack/pkg/common/_commonjsHelpers-0597c316.js.map +1 -0
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js +2 -2
- package/dist/_snowpack/pkg/dialog-polyfill.js +1 -2
- package/dist/_snowpack/pkg/dialog-polyfill.js.map +1 -1
- package/dist/_snowpack/pkg/import-map.json +1 -0
- package/dist/_snowpack/pkg/jsonld-context-parser.js +1 -1
- package/dist/_snowpack/pkg/jsonld.js +11760 -0
- package/dist/_snowpack/pkg/jsonld.js.map +1 -0
- 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 +11626 -11627
- package/dist/_snowpack/pkg/quill.js.map +1 -1
- package/dist/_snowpack/pkg/tui-calendar.js +43101 -43105
- package/dist/_snowpack/pkg/tui-calendar.js.map +1 -1
- package/dist/components/solid-form-search.js +1 -2
- package/dist/components/solid-form.js +2 -4
- package/dist/libs/ComponentFactory.js +1 -4
- package/dist/libs/filter.js +1 -1
- package/dist/libs/helpers.js +4 -10
- package/dist/libs/lit-helpers.js +1 -4
- package/dist/libs/polyfills.js +2 -4
- package/dist/libs/store/custom-getter.js +313 -0
- package/dist/libs/store/server-pagination.js +4 -7
- package/dist/libs/store/server-search.js +4 -7
- package/dist/libs/store/store.js +92 -346
- package/dist/mixins/attributeBinderMixin.js +3 -6
- package/dist/mixins/federationMixin.js +6 -0
- package/dist/mixins/filterMixin.js +13 -16
- package/dist/mixins/listMixin.js +20 -9
- package/dist/mixins/requiredMixin.js +15 -3
- package/dist/mixins/storeMixin.js +30 -0
- package/dist/mixins/widgetMixin.js +18 -5
- package/dist/new-widgets/templates/formTemplatesDirectory.js +6 -15
- package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +3 -0
- package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +17 -4
- package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +11 -2
- package/dist/widgets/baseWidget.js +4 -5
- package/dist/widgets/widget-factory.js +1 -3
- package/package.json +5 -4
- package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js.map +0 -1
package/dist/libs/store/store.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
let _Symbol$toPrimitive;
|
|
2
1
|
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
2
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
4
3
|
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
4
|
import JSONLDContextParser from '../../_snowpack/pkg/jsonld-context-parser.js';
|
|
6
5
|
//@ts-ignore
|
|
7
6
|
import PubSub from 'https://cdn.skypack.dev/pubsub-js';
|
|
7
|
+
import jsonld from '../../_snowpack/pkg/jsonld.js';
|
|
8
|
+
import { CustomGetter } from './custom-getter.js';
|
|
8
9
|
import { appendServerSearchToIri } from './server-search.js';
|
|
9
10
|
import { appendServerPaginationToIri } from './server-pagination.js';
|
|
10
11
|
const ContextParser = JSONLDContextParser.ContextParser;
|
|
@@ -67,18 +68,13 @@ class Store {
|
|
|
67
68
|
* @param forceFetch - force the fetch of data
|
|
68
69
|
* @param serverPagination - Server pagination options
|
|
69
70
|
* @param serverSearch - Server search options
|
|
70
|
-
*
|
|
71
|
+
* @param predicateName - predicate name if we target a specific predicate from the resource, useful for arrays
|
|
72
|
+
*
|
|
71
73
|
* @returns The fetched resource
|
|
72
74
|
*
|
|
73
75
|
* @async
|
|
74
76
|
*/
|
|
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;
|
|
77
|
+
async getData(id, context = {}, parentId = "", localData, forceFetch = false, serverPagination, serverSearch) {
|
|
82
78
|
let key = id;
|
|
83
79
|
if (serverPagination) {
|
|
84
80
|
key = id + "#p" + serverPagination.limit + "?o" + serverPagination.offset;
|
|
@@ -114,9 +110,9 @@ class Store {
|
|
|
114
110
|
return;
|
|
115
111
|
}
|
|
116
112
|
const serverContext = await myParser.parse([resource['@context'] || {}]);
|
|
117
|
-
const resourceProxy = new CustomGetter(key, resource, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch).getProxy();
|
|
113
|
+
// const resourceProxy = new CustomGetter(key, resource, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch).getProxy();
|
|
118
114
|
// Cache proxy
|
|
119
|
-
await this.cacheGraph(
|
|
115
|
+
await this.cacheGraph(resource, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch);
|
|
120
116
|
this.loadingList.delete(key);
|
|
121
117
|
document.dispatchEvent(new CustomEvent('resourceReady', {
|
|
122
118
|
detail: {
|
|
@@ -144,11 +140,17 @@ class Store {
|
|
|
144
140
|
});
|
|
145
141
|
}
|
|
146
142
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Fetch resource
|
|
146
|
+
* @param id - id of the resource
|
|
147
|
+
* @param context - context used to expand id
|
|
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) {
|
|
152
154
|
let iri = this._getAbsoluteIri(id, context, parentId);
|
|
153
155
|
if (serverPagination) iri = appendServerPaginationToIri(iri, serverPagination);
|
|
154
156
|
if (serverSearch) iri = appendServerSearchToIri(iri, serverSearch);
|
|
@@ -158,6 +160,12 @@ class Store {
|
|
|
158
160
|
// 'Prefer' : 'return=representation; max-triple-count="100"' // Commenting out for now as it raises CORS errors
|
|
159
161
|
};
|
|
160
162
|
|
|
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
|
+
*/
|
|
161
169
|
return this.fetchAuthn(iri, {
|
|
162
170
|
method: 'GET',
|
|
163
171
|
headers: headers,
|
|
@@ -167,59 +175,51 @@ class Store {
|
|
|
167
175
|
return response.json();
|
|
168
176
|
});
|
|
169
177
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Cache the whole graph
|
|
181
|
+
* @param resource - graph fetched
|
|
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)) {
|
|
174
207
|
// if already cached, merge data
|
|
175
|
-
this.cache.get(key).merge(
|
|
176
|
-
;
|
|
208
|
+
this.cache.get(key).merge(resourceProxy);
|
|
177
209
|
} else {
|
|
178
210
|
// else, put in cache
|
|
179
|
-
this.
|
|
211
|
+
this.cacheResource(key, resourceProxy);
|
|
180
212
|
}
|
|
181
213
|
}
|
|
214
|
+
}
|
|
182
215
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
}
|
|
216
|
+
/**
|
|
217
|
+
* Put proxy in cache
|
|
218
|
+
* @param key
|
|
219
|
+
* @param resourceProxy
|
|
220
|
+
*/
|
|
221
|
+
cacheResource(key, resourceProxy) {
|
|
222
|
+
this.cache.set(key, resourceProxy);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
/**
|
|
@@ -247,6 +247,25 @@ 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
|
+
*/
|
|
250
269
|
async _updateResource(method, resource, id) {
|
|
251
270
|
if (!['POST', 'PUT', 'PATCH', '_LOCAL'].includes(method)) throw new Error('Error: method not allowed');
|
|
252
271
|
const context = await myParser.parse([resource['@context'] || {}]); // parse context before expandTerm
|
|
@@ -287,13 +306,10 @@ class Store {
|
|
|
287
306
|
for (const resource of resourceWithContexts) {
|
|
288
307
|
if (!this._isLocalId(resource.id)) this.clearCache(resource.id);
|
|
289
308
|
}
|
|
290
|
-
await Promise.all(resourceWithContexts.map(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
} = _ref;
|
|
295
|
-
return this.getData(id, context || base_context);
|
|
296
|
-
}));
|
|
309
|
+
await Promise.all(resourceWithContexts.map(({
|
|
310
|
+
id,
|
|
311
|
+
context
|
|
312
|
+
}) => this.getData(id, context || base_context)));
|
|
297
313
|
return resourceIds;
|
|
298
314
|
}
|
|
299
315
|
/**
|
|
@@ -437,8 +453,7 @@ class Store {
|
|
|
437
453
|
*
|
|
438
454
|
* @returns id of the deleted resource
|
|
439
455
|
*/
|
|
440
|
-
async delete(id) {
|
|
441
|
-
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
456
|
+
async delete(id, context = {}) {
|
|
442
457
|
const expandedId = this._getExpandedId(id, context);
|
|
443
458
|
const deleted = await this.fetchAuthn(expandedId, {
|
|
444
459
|
method: 'DELETE',
|
|
@@ -468,6 +483,9 @@ class Store {
|
|
|
468
483
|
_getExpandedId(id, context) {
|
|
469
484
|
return context && Object.keys(context) ? ContextParser.expandTerm(id, context) : id;
|
|
470
485
|
}
|
|
486
|
+
getExpandedPredicate(property, context) {
|
|
487
|
+
return ContextParser.expandTerm(property, context, true);
|
|
488
|
+
}
|
|
471
489
|
_isLocalId(id) {
|
|
472
490
|
return id.startsWith('store://local.');
|
|
473
491
|
}
|
|
@@ -500,7 +518,7 @@ class Store {
|
|
|
500
518
|
*/
|
|
501
519
|
_getAbsoluteIri(id, context, parentId) {
|
|
502
520
|
let iri = ContextParser.expandTerm(id, context); // expand if reduced ids
|
|
503
|
-
if (parentId) {
|
|
521
|
+
if (parentId && !parentId.startsWith('store://local')) {
|
|
504
522
|
// and get full URL from parent caller for local files
|
|
505
523
|
let parentIri = new URL(parentId, document.location.href).href;
|
|
506
524
|
iri = new URL(iri, parentIri).href;
|
|
@@ -510,14 +528,6 @@ class Store {
|
|
|
510
528
|
return iri;
|
|
511
529
|
}
|
|
512
530
|
|
|
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
|
-
|
|
521
531
|
/**
|
|
522
532
|
* Return language of the users
|
|
523
533
|
*/
|
|
@@ -547,268 +557,4 @@ if (window.sibStore) {
|
|
|
547
557
|
store = new Store(storeOptions);
|
|
548
558
|
window.sibStore = store;
|
|
549
559
|
}
|
|
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
|
-
}
|
|
560
|
+
export { store };
|
|
@@ -20,8 +20,7 @@ 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() {
|
|
24
|
-
let reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
23
|
+
async replaceAttributesData(reset = true) {
|
|
25
24
|
if (reset) this.resetAttributesData();
|
|
26
25
|
const oldAttributes = Array.from(this.element.attributes) // transform NamedNodeMap in object
|
|
27
26
|
.reduce((obj, attr) => {
|
|
@@ -59,7 +58,7 @@ const AttributeBinderMixin = {
|
|
|
59
58
|
const value = attributes[attr];
|
|
60
59
|
// Avoid error if value is a number
|
|
61
60
|
if (typeof value === 'string') {
|
|
62
|
-
// Replace attribute value
|
|
61
|
+
// Replace attribute value
|
|
63
62
|
if (!isContainer && resource && value.startsWith('store://resource')) {
|
|
64
63
|
// RESOURCE
|
|
65
64
|
let path = value.replace('store://resource.', '');
|
|
@@ -98,9 +97,7 @@ const AttributeBinderMixin = {
|
|
|
98
97
|
* @param maxRetries
|
|
99
98
|
* @returns
|
|
100
99
|
*/
|
|
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;
|
|
100
|
+
async retry(fn, ms = 200, maxRetries = 5) {
|
|
104
101
|
return new Promise((resolve, reject) => {
|
|
105
102
|
let retries = 0;
|
|
106
103
|
fn().then(resolve).catch(() => {
|
|
@@ -17,6 +17,7 @@ const FederationMixin = {
|
|
|
17
17
|
if (nextProcessor) await nextProcessor(newResources, listPostProcessors, div, context);
|
|
18
18
|
},
|
|
19
19
|
async getResources(resources) {
|
|
20
|
+
if (!resources) return [];
|
|
20
21
|
const newResources = [];
|
|
21
22
|
const getChildResources = async res => {
|
|
22
23
|
if (!res) return;
|
|
@@ -29,11 +30,16 @@ const FederationMixin = {
|
|
|
29
30
|
const resourcesFetched = await this.fetchSource(containerId); // fetch the resources of this container
|
|
30
31
|
if (resourcesFetched) newResources.push(...(await this.getResources(resourcesFetched))); // Add content of source to array...
|
|
31
32
|
}
|
|
33
|
+
} else if (!res.isArray?.()) {
|
|
34
|
+
const resource = await store.getData(res['@id'], this.context);
|
|
35
|
+
if (resource) newResources.push(resource);
|
|
32
36
|
} else {
|
|
33
37
|
newResources.push(res); // Or resource directly if not a container
|
|
34
38
|
}
|
|
35
39
|
};
|
|
36
40
|
|
|
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];
|
|
37
43
|
await Promise.all(resources.map(res => getChildResources(res)));
|
|
38
44
|
return newResources;
|
|
39
45
|
},
|
|
@@ -67,12 +67,9 @@ 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
|
-
|
|
73
|
-
} = _ref;
|
|
74
|
-
return value;
|
|
75
|
-
}).filter(value => !!value).join(' ').trim();
|
|
70
|
+
const value = Object.values(filters).map(({
|
|
71
|
+
value
|
|
72
|
+
}) => value).filter(value => !!value).join(' ').trim();
|
|
76
73
|
if (fields.length > 0 && value) {
|
|
77
74
|
return {
|
|
78
75
|
fields,
|
|
@@ -109,14 +106,15 @@ const FilterMixin = {
|
|
|
109
106
|
console.warn(`The format value of ${field} is not suitable with auto-range-[field] attribute`);
|
|
110
107
|
continue;
|
|
111
108
|
}
|
|
112
|
-
const nextArrayOfIds = nextArrayOfObjects['ldp:contains'];
|
|
113
|
-
for (const obj of nextArrayOfIds) {
|
|
114
|
-
// catch each element id
|
|
115
|
-
arrayOfDataIds.push(obj['@id']);
|
|
116
|
-
}
|
|
117
109
|
if (nextArrayOfObjects['@type'] !== 'ldp:Container') {
|
|
118
110
|
// if no element in 'ldp:contains', catch object id
|
|
119
111
|
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
|
+
}
|
|
120
118
|
}
|
|
121
119
|
}
|
|
122
120
|
return arrayOfDataIds;
|
|
@@ -141,11 +139,10 @@ const FilterMixin = {
|
|
|
141
139
|
name: attr['name'].replace('search-', ''),
|
|
142
140
|
value: attr['value']
|
|
143
141
|
}));
|
|
144
|
-
searchAttributes.forEach(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
} = _ref2;
|
|
142
|
+
searchAttributes.forEach(({
|
|
143
|
+
name,
|
|
144
|
+
value
|
|
145
|
+
}) => {
|
|
149
146
|
this.searchForm.setAttribute(name, value);
|
|
150
147
|
});
|
|
151
148
|
this.element.insertBefore(this.searchForm, this.element.firstChild);
|
package/dist/mixins/listMixin.js
CHANGED
|
@@ -43,21 +43,32 @@ 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?.() && !this.arrayField && !this.predicateName) {
|
|
47
47
|
this.setElementAttribute("resource");
|
|
48
48
|
this.appendSingleElt(div);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
if (this.resource.isContainer?.()) {
|
|
52
|
+
this.setElementAttribute("container");
|
|
53
|
+
const listPostProcessors = [...this.listPostProcessors];
|
|
54
|
+
this.renderCallbacks = [];
|
|
55
|
+
listPostProcessors.push(this.renderDOM.bind(this));
|
|
56
|
+
listPostProcessors.push(this.handleEmptyWidget.bind(this));
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
// Execute the first post-processor of the list
|
|
59
|
+
const nextProcessor = listPostProcessors.shift();
|
|
60
|
+
await nextProcessor(this.resource['ldp:contains'], listPostProcessors, div, this.dataSrc);
|
|
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));
|
|
60
67
|
|
|
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
|
+
}
|
|
61
72
|
// Execute the render callbacks
|
|
62
73
|
for (const renderCallback of this.renderCallbacks) {
|
|
63
74
|
// Render the template in the given parent element
|