@startinblox/core 0.18.1 → 0.19.0-beta.10

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.
Files changed (163) hide show
  1. package/dist/{_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css → assets/MarkerCluster-614dea0a.css} +0 -0
  2. package/dist/{_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css → assets/MarkerCluster.Default-61258232.css} +0 -0
  3. package/dist/assets/en-e53105c5.js +14 -0
  4. package/dist/assets/en-e53105c5.js.map +1 -0
  5. package/dist/assets/fr-a7fcdb64.js +14 -0
  6. package/dist/assets/fr-a7fcdb64.js.map +1 -0
  7. package/dist/{_snowpack/pkg/fusejs.js → assets/helpers-bf15809c.js} +398 -454
  8. package/dist/assets/helpers-bf15809c.js.map +1 -0
  9. package/dist/{_snowpack/pkg/leaflet/dist/leaflet.css → assets/leaflet-3c081932.css} +3 -3
  10. package/dist/helpers.js +18 -0
  11. package/dist/helpers.js.map +1 -0
  12. package/dist/index.js +54600 -48
  13. package/dist/index.js.map +1 -0
  14. package/package.json +8 -22
  15. package/dist/_snowpack/pkg/autolinker.js +0 -4429
  16. package/dist/_snowpack/pkg/autolinker.js.map +0 -1
  17. package/dist/_snowpack/pkg/common/_baseUnary-c1edb653.js +0 -353
  18. package/dist/_snowpack/pkg/common/_baseUnary-c1edb653.js.map +0 -1
  19. package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js +0 -26
  20. package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js.map +0 -1
  21. package/dist/_snowpack/pkg/common/decode-26fbf385.js +0 -185
  22. package/dist/_snowpack/pkg/common/decode-26fbf385.js.map +0 -1
  23. package/dist/_snowpack/pkg/common/lit-html-3647afce.js +0 -1104
  24. package/dist/_snowpack/pkg/common/lit-html-3647afce.js.map +0 -1
  25. package/dist/_snowpack/pkg/delta-markdown-for-quill.js +0 -26198
  26. package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map +0 -1
  27. package/dist/_snowpack/pkg/dialog-polyfill.js +0 -827
  28. package/dist/_snowpack/pkg/dialog-polyfill.js.map +0 -1
  29. package/dist/_snowpack/pkg/fusejs.js.map +0 -1
  30. package/dist/_snowpack/pkg/import-map.json +0 -24
  31. package/dist/_snowpack/pkg/jsonld-context-parser.js +0 -836
  32. package/dist/_snowpack/pkg/jsonld-context-parser.js.map +0 -1
  33. package/dist/_snowpack/pkg/leaflet/dist/leaflet.css.proxy.js +0 -10
  34. package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css.proxy.js +0 -10
  35. package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css.proxy.js +0 -10
  36. package/dist/_snowpack/pkg/lit-html/directives/if-defined.js +0 -39
  37. package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map +0 -1
  38. package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js +0 -48
  39. package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map +0 -1
  40. package/dist/_snowpack/pkg/lit-html/directives/until.js +0 -87
  41. package/dist/_snowpack/pkg/lit-html/directives/until.js.map +0 -1
  42. package/dist/_snowpack/pkg/lit-html.js +0 -94
  43. package/dist/_snowpack/pkg/lit-html.js.map +0 -1
  44. package/dist/_snowpack/pkg/markdown-it-link-attributes.js +0 -68
  45. package/dist/_snowpack/pkg/markdown-it-link-attributes.js.map +0 -1
  46. package/dist/_snowpack/pkg/markdown-it.js +0 -11307
  47. package/dist/_snowpack/pkg/markdown-it.js.map +0 -1
  48. package/dist/_snowpack/pkg/quill/dist/quill.snow.css.proxy.js +0 -10
  49. package/dist/_snowpack/pkg/quill-delta-to-markdown.js +0 -971
  50. package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map +0 -1
  51. package/dist/_snowpack/pkg/quill.js +0 -14442
  52. package/dist/_snowpack/pkg/quill.js.map +0 -1
  53. package/dist/_snowpack/pkg/slim-select.js +0 -714
  54. package/dist/_snowpack/pkg/slim-select.js.map +0 -1
  55. package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css +0 -1149
  56. package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css.proxy.js +0 -10
  57. package/dist/_snowpack/pkg/tui-calendar.js +0 -46507
  58. package/dist/_snowpack/pkg/tui-calendar.js.map +0 -1
  59. package/dist/components/solid-ac-checker.js +0 -45
  60. package/dist/components/solid-calendar.js +0 -66
  61. package/dist/components/solid-delete.js +0 -96
  62. package/dist/components/solid-display.js +0 -150
  63. package/dist/components/solid-form-search.js +0 -174
  64. package/dist/components/solid-form.js +0 -259
  65. package/dist/components/solid-lang.js +0 -35
  66. package/dist/components/solid-map.js +0 -204
  67. package/dist/components/solid-table.js +0 -181
  68. package/dist/components/solid-widget.js +0 -72
  69. package/dist/import.css +0 -4
  70. package/dist/libs/Component.js +0 -13
  71. package/dist/libs/ComponentFactory.js +0 -168
  72. package/dist/libs/Compositor.js +0 -96
  73. package/dist/libs/Sib.js +0 -44
  74. package/dist/libs/filter.js +0 -184
  75. package/dist/libs/helpers.js +0 -191
  76. package/dist/libs/interfaces.js +0 -6
  77. package/dist/libs/lit-helpers.js +0 -142
  78. package/dist/libs/polyfills.js +0 -37
  79. package/dist/libs/store/server-pagination.js +0 -22
  80. package/dist/libs/store/server-search.js +0 -35
  81. package/dist/libs/store/store.js +0 -814
  82. package/dist/locales/en.json +0 -10
  83. package/dist/locales/en.json.proxy.js +0 -2
  84. package/dist/locales/fr.json +0 -10
  85. package/dist/locales/fr.json.proxy.js +0 -2
  86. package/dist/mixins/attributeBinderMixin.js +0 -116
  87. package/dist/mixins/contextMixin.js +0 -26
  88. package/dist/mixins/counterMixin.js +0 -54
  89. package/dist/mixins/federationMixin.js +0 -51
  90. package/dist/mixins/filterMixin.js +0 -155
  91. package/dist/mixins/grouperMixin.js +0 -73
  92. package/dist/mixins/highlighterMixin.js +0 -36
  93. package/dist/mixins/interfaces.js +0 -6
  94. package/dist/mixins/listMixin.js +0 -105
  95. package/dist/mixins/nextMixin.js +0 -23
  96. package/dist/mixins/paginateMixin.js +0 -97
  97. package/dist/mixins/requiredMixin.js +0 -26
  98. package/dist/mixins/serverPaginationMixin.js +0 -122
  99. package/dist/mixins/sorterMixin.js +0 -131
  100. package/dist/mixins/storeMixin.js +0 -109
  101. package/dist/mixins/translationMixin.js +0 -58
  102. package/dist/mixins/validationMixin.js +0 -95
  103. package/dist/mixins/widgetMixin.js +0 -351
  104. package/dist/new-widgets/attributeMixins/actionMixin.js +0 -13
  105. package/dist/new-widgets/attributeMixins/blankMixin.js +0 -7
  106. package/dist/new-widgets/attributeMixins/booleanMixin.js +0 -7
  107. package/dist/new-widgets/attributeMixins/index.js +0 -19
  108. package/dist/new-widgets/attributeMixins/mailtoMixin.js +0 -7
  109. package/dist/new-widgets/attributeMixins/multipleMixin.js +0 -27
  110. package/dist/new-widgets/attributeMixins/numberMixin.js +0 -7
  111. package/dist/new-widgets/attributeMixins/placeholderMixin.js +0 -16
  112. package/dist/new-widgets/attributeMixins/telMixin.js +0 -7
  113. package/dist/new-widgets/baseWidgetMixin.js +0 -109
  114. package/dist/new-widgets/callbackMixins/autocompletionMixin.js +0 -96
  115. package/dist/new-widgets/callbackMixins/index.js +0 -7
  116. package/dist/new-widgets/callbackMixins/richtextMixin.js +0 -37
  117. package/dist/new-widgets/callbackMixins/slimselect.css.proxy.js +0 -10
  118. package/dist/new-widgets/interfaces.js +0 -1
  119. package/dist/new-widgets/new-widget-factory.js +0 -91
  120. package/dist/new-widgets/templateAdditionMixins/addableMixin.js +0 -26
  121. package/dist/new-widgets/templateAdditionMixins/index.js +0 -13
  122. package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js +0 -16
  123. package/dist/new-widgets/templateAdditionMixins/labelMixin.js +0 -18
  124. package/dist/new-widgets/templates/defaultTemplatesDirectory.js +0 -29
  125. package/dist/new-widgets/templates/displayTemplatesDirectory.js +0 -54
  126. package/dist/new-widgets/templates/formTemplatesDirectory.js +0 -432
  127. package/dist/new-widgets/templates/groupTemplatesDirectory.js +0 -11
  128. package/dist/new-widgets/templates/index.js +0 -6
  129. package/dist/new-widgets/templates/setTemplatesDirectory.js +0 -16
  130. package/dist/new-widgets/templatesDependencies/altMixin.js +0 -12
  131. package/dist/new-widgets/templatesDependencies/editableMixin.js +0 -60
  132. package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js +0 -34
  133. package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js +0 -10
  134. package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js +0 -41
  135. package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +0 -56
  136. package/dist/new-widgets/templatesDependencies/formFileMixin.js +0 -82
  137. package/dist/new-widgets/templatesDependencies/formLengthMixin.js +0 -18
  138. package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js +0 -18
  139. package/dist/new-widgets/templatesDependencies/formMixin.js +0 -56
  140. package/dist/new-widgets/templatesDependencies/formNumberMixin.js +0 -10
  141. package/dist/new-widgets/templatesDependencies/formRadioMixin.js +0 -12
  142. package/dist/new-widgets/templatesDependencies/formStepMixin.js +0 -12
  143. package/dist/new-widgets/templatesDependencies/linkTextMixin.js +0 -13
  144. package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +0 -112
  145. package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +0 -65
  146. package/dist/new-widgets/templatesDependencies/patternMixin.js +0 -18
  147. package/dist/new-widgets/templatesDependencies/rangeMixin.js +0 -100
  148. package/dist/new-widgets/templatesDependencies/setMixin.js +0 -9
  149. package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js +0 -9
  150. package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js +0 -14
  151. package/dist/new-widgets/valueTransformationMixins/dateMixin.js +0 -29
  152. package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js +0 -12
  153. package/dist/new-widgets/valueTransformationMixins/index.js +0 -15
  154. package/dist/new-widgets/valueTransformationMixins/markdownMixin.js +0 -30
  155. package/dist/new-widgets/valueTransformationMixins/multilineMixin.js +0 -13
  156. package/dist/new-widgets/valueTransformationMixins/oembedMixin.js +0 -21
  157. package/dist/solid-template-element.js +0 -144
  158. package/dist/style/default-theme.css.proxy.js +0 -10
  159. package/dist/widgets/baseWidget.js +0 -268
  160. package/dist/widgets/widget-factory.js +0 -22
  161. /package/dist/{style/default-theme.css → assets/default-theme-d0f20a8a.css} +0 -0
  162. /package/dist/{_snowpack/pkg/quill/dist/quill.snow.css → assets/quill.snow-8f222e44.css} +0 -0
  163. /package/dist/{new-widgets/callbackMixins/slimselect.css → assets/slimselect-43e3ebc8.css} +0 -0
@@ -1,814 +0,0 @@
1
- let _Symbol$toPrimitive;
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
- import PubSub from 'https://cdn.skypack.dev/pubsub-js';
8
- import { appendServerSearchToIri } from './server-search.js';
9
- import { appendServerPaginationToIri } from './server-pagination.js';
10
- const ContextParser = JSONLDContextParser.ContextParser;
11
- const myParser = new ContextParser();
12
- export const base_context = {
13
- '@vocab': 'http://happy-dev.fr/owl/#',
14
- rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
15
- rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
16
- ldp: 'http://www.w3.org/ns/ldp#',
17
- foaf: 'http://xmlns.com/foaf/0.1/',
18
- name: 'rdfs:label',
19
- acl: 'http://www.w3.org/ns/auth/acl#',
20
- permissions: 'acl:accessControl',
21
- mode: 'acl:mode',
22
- geo: "http://www.w3.org/2003/01/geo/wgs84_pos#",
23
- lat: "geo:lat",
24
- lng: "geo:long"
25
- };
26
- class Store {
27
- constructor(storeOptions) {
28
- this.storeOptions = storeOptions;
29
- _defineProperty(this, "cache", void 0);
30
- _defineProperty(this, "subscriptionIndex", void 0);
31
- // index of all the containers per resource
32
- _defineProperty(this, "subscriptionVirtualContainersIndex", void 0);
33
- // index of all the containers per resource
34
- _defineProperty(this, "loadingList", void 0);
35
- _defineProperty(this, "headers", void 0);
36
- _defineProperty(this, "fetch", void 0);
37
- _defineProperty(this, "session", void 0);
38
- _defineProperty(this, "resolveResource", function (id, resolve) {
39
- const handler = function (event) {
40
- if (event.detail.id === id) {
41
- resolve(event.detail.resource);
42
- // TODO : callback
43
- document.removeEventListener('resourceReady', handler);
44
- }
45
- };
46
- return handler;
47
- });
48
- this.cache = new Map();
49
- this.subscriptionIndex = new Map();
50
- this.subscriptionVirtualContainersIndex = new Map();
51
- this.loadingList = new Set();
52
- this.headers = {
53
- 'Accept': 'application/ld+json',
54
- 'Content-Type': 'application/ld+json',
55
- 'Cache-Control': 'must-revalidate'
56
- };
57
- this.fetch = this.storeOptions.fetchMethod;
58
- this.session = this.storeOptions.session;
59
- }
60
-
61
- /**
62
- * Fetch data and cache it
63
- * @param id - uri of the resource to fetch
64
- * @param context - context used to expand id and predicates when accessing the resource
65
- * @param parentId - uri of the parent caller used to expand uri for local files
66
- * @param localData - data to put in cache
67
- * @param forceFetch - force the fetch of data
68
- * @param serverPagination - Server pagination options
69
- * @param serverSearch - Server search options
70
- *
71
- * @returns The fetched resource
72
- *
73
- * @async
74
- */
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;
82
- let key = id;
83
- if (serverPagination) {
84
- key = id + "#p" + serverPagination.limit + "?o" + serverPagination.offset;
85
- }
86
- if (serverSearch) {
87
- key = appendServerSearchToIri(key, serverSearch);
88
- }
89
- if (localData == null && this.cache.has(key) && !this.loadingList.has(key)) {
90
- const resource = this.get(key);
91
- if (resource && resource.isFullResource?.() && !forceFetch) return resource; // if resource is not complete, re-fetch it
92
- }
93
-
94
- return new Promise(async resolve => {
95
- document.addEventListener('resourceReady', this.resolveResource(key, resolve));
96
- if (this.loadingList.has(key)) return;
97
- this.loadingList.add(key);
98
-
99
- // Generate proxy
100
- const clientContext = await myParser.parse(context);
101
- let resource = null;
102
- if (this._isLocalId(id)) {
103
- if (localData == null) localData = {};
104
- localData["@id"] = id;
105
- resource = localData;
106
- } else try {
107
- resource = localData || (await this.fetchData(id, clientContext, parentId, serverPagination, serverSearch));
108
- } catch (error) {
109
- console.error(error);
110
- }
111
- if (!resource) {
112
- this.loadingList.delete(key);
113
- resolve(null);
114
- return;
115
- }
116
- const serverContext = await myParser.parse([resource['@context'] || {}]);
117
- const resourceProxy = new CustomGetter(key, resource, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch).getProxy();
118
- // Cache proxy
119
- await this.cacheGraph(key, resourceProxy, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch);
120
- this.loadingList.delete(key);
121
- document.dispatchEvent(new CustomEvent('resourceReady', {
122
- detail: {
123
- id: key,
124
- resource: this.get(key)
125
- }
126
- }));
127
- });
128
- }
129
- async fetchAuthn(iri, options) {
130
- let authenticated = false;
131
- if (this.session) authenticated = await this.session;
132
- if (this.fetch && authenticated) {
133
- // authenticated
134
- return this.fetch.then(fn => fn(iri, options));
135
- } else {
136
- // anonymous
137
- if (options.headers) options.headers = this._convertHeaders(options.headers);
138
- return fetch(iri, options).then(function (response) {
139
- if (options.method === "PURGE" && !response.ok && response.status === 404) {
140
- const err = new Error("PURGE call is returning 404");
141
- throw err;
142
- }
143
- return response;
144
- });
145
- }
146
- }
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;
152
- let iri = this._getAbsoluteIri(id, context, parentId);
153
- if (serverPagination) iri = appendServerPaginationToIri(iri, serverPagination);
154
- if (serverSearch) iri = appendServerSearchToIri(iri, serverSearch);
155
- const headers = {
156
- ...this.headers,
157
- 'accept-language': this._getLanguage()
158
- // 'Prefer' : 'return=representation; max-triple-count="100"' // Commenting out for now as it raises CORS errors
159
- };
160
-
161
- return this.fetchAuthn(iri, {
162
- method: 'GET',
163
- headers: headers,
164
- credentials: 'include'
165
- }).then(response => {
166
- if (!response.ok) return;
167
- return response.json();
168
- });
169
- }
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) {
174
- // if already cached, merge data
175
- this.cache.get(key).merge(resource);
176
- ;
177
- } else {
178
- // else, put in cache
179
- this.cache.set(key, resource);
180
- }
181
- }
182
-
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
- }
224
-
225
- /**
226
- * Update fetch
227
- * @param method - 'POST', 'PATCH', 'PUT', '_LOCAL'
228
- * @param resource - resource to send
229
- * @param id - uri to update
230
- * @returns - object
231
- */
232
- async _fetch(method, resource, id) {
233
- if (method !== '_LOCAL') return this.fetchAuthn(id, {
234
- method: method,
235
- headers: this.headers,
236
- body: JSON.stringify(resource),
237
- credentials: 'include'
238
- });
239
- const resourceProxy = store.get(id);
240
- const clientContext = resourceProxy ? {
241
- ...resourceProxy.clientContext,
242
- ...resource['@context']
243
- } : resource['@context'];
244
- this.clearCache(id);
245
- await this.getData(id, clientContext, '', resource);
246
- return {
247
- ok: true
248
- };
249
- }
250
- async _updateResource(method, resource, id) {
251
- if (!['POST', 'PUT', 'PATCH', '_LOCAL'].includes(method)) throw new Error('Error: method not allowed');
252
- const context = await myParser.parse([resource['@context'] || {}]); // parse context before expandTerm
253
- const expandedId = this._getExpandedId(id, context);
254
- return this._fetch(method, resource, id).then(async response => {
255
- if (response.ok) {
256
- if (method !== '_LOCAL') {
257
- // await this.purge(id);
258
- this.clearCache(expandedId);
259
- } // clear cache
260
- this.getData(expandedId, resource['@context']).then(async () => {
261
- // re-fetch data
262
- const nestedResources = await this.getNestedResources(resource, id);
263
- const resourcesToRefresh = this.subscriptionVirtualContainersIndex.get(expandedId) || [];
264
- const resourcesToNotify = this.subscriptionIndex.get(expandedId) || [];
265
- return this.refreshResources([...nestedResources, ...resourcesToRefresh]) // refresh related resources
266
- .then(resourceIds => this.notifyResources([expandedId, ...resourceIds, ...resourcesToNotify])); // notify components
267
- });
268
-
269
- return response.headers?.get('Location') || null;
270
- } else {
271
- throw response;
272
- }
273
- });
274
- }
275
-
276
- /**
277
- * Clear cache and refetch data for a list of ids
278
- * @param resourceIds -
279
- * @returns - all the resource ids
280
- */
281
- async refreshResources(resourceIds) {
282
- resourceIds = [...new Set(resourceIds.filter(id => this.cache.has(id)))]; // remove duplicates and not cached resources
283
- const resourceWithContexts = resourceIds.map(resourceId => ({
284
- "id": resourceId,
285
- "context": store.get(resourceId)?.clientContext
286
- }));
287
- for (const resource of resourceWithContexts) {
288
- if (!this._isLocalId(resource.id)) this.clearCache(resource.id);
289
- }
290
- await Promise.all(resourceWithContexts.map(_ref => {
291
- let {
292
- id,
293
- context
294
- } = _ref;
295
- return this.getData(id, context || base_context);
296
- }));
297
- return resourceIds;
298
- }
299
- /**
300
- * Notifies all components for a list of ids
301
- * @param resourceIds -
302
- */
303
- async notifyResources(resourceIds) {
304
- resourceIds = [...new Set(resourceIds)]; // remove duplicates
305
- for (const id of resourceIds) PubSub.publish(id);
306
- }
307
-
308
- /**
309
- * Return id of nested properties of a resource
310
- * @param resource - object
311
- * @param id - string
312
- */
313
- async getNestedResources(resource, id) {
314
- const cachedResource = store.get(id);
315
- if (!cachedResource || cachedResource.isContainer?.()) return [];
316
- let nestedProperties = [];
317
- const excludeKeys = ['@context'];
318
- for (let p of Object.keys(resource)) {
319
- if (resource[p] && typeof resource[p] === 'object' && !excludeKeys.includes(p) && resource[p]['@id']) {
320
- nestedProperties.push(resource[p]['@id']);
321
- }
322
- }
323
- return nestedProperties;
324
- }
325
-
326
- /**
327
- * Returns the resource with id from the cache
328
- * @param id - id of the resource to retrieve
329
- *
330
- * @returns Resource (Proxy) if in the cache, null otherwise
331
- */
332
- get(id, serverSearch) {
333
- if (serverSearch) {
334
- id = appendServerSearchToIri(id, serverSearch);
335
- }
336
- return this.cache.get(id) || null;
337
- }
338
-
339
- /**
340
- * Removes a resource from the cache
341
- * @param id - id of the resource to remove from the cache
342
- */
343
- clearCache(id) {
344
- if (this.cache.has(id)) {
345
- // For federation, clear each source
346
- const resource = this.cache.get(id);
347
- if (resource['@type'] === 'ldp:Container') {
348
- resource['ldp:contains'].forEach(child => {
349
- if (child && child['@type'] === 'ldp:Container') this.cache.delete(child['@id']);
350
- });
351
- }
352
- this.cache.delete(id);
353
- }
354
- }
355
-
356
- /**
357
- * Send data to create a local resource in a container
358
- * @param resource - resource to create
359
- * @param id - uri of the container to add resource. should start with ``
360
- *
361
- * @returns id of the posted resource
362
- */
363
- async setLocalData(resource, id) {
364
- return this._updateResource('_LOCAL', resource, id);
365
- }
366
-
367
- /**
368
- * Send a POST request to create a resource in a container
369
- * @param resource - resource to create
370
- * @param id - uri of the container to add resource
371
- *
372
- * @returns id of the posted resource
373
- */
374
- async post(resource, id) {
375
- return this._updateResource('POST', resource, id);
376
- }
377
-
378
- /**
379
- * Send a PUT request to edit a resource
380
- * @param resource - resource data to send
381
- * @param id - uri of the resource to edit
382
- *
383
- * @returns id of the edited resource
384
- */
385
- async put(resource, id) {
386
- return this._updateResource('PUT', resource, id);
387
- }
388
-
389
- /**
390
- * Send a PATCH request to edit a resource
391
- * @param resource - resource data to send
392
- * @param id - uri of the resource to patch
393
- *
394
- * @returns id of the edited resource
395
- */
396
- async patch(resource, id) {
397
- return this._updateResource('PATCH', resource, id);
398
- }
399
-
400
- /**
401
- * Send a PURGE request to remove a resource from REDIS AD cache
402
- * @param id - uri of the resource to patch
403
- *
404
- * @returns id of the edited resource
405
- */
406
- async purge(id) {
407
- await this.fetchAuthn(id, {
408
- method: "PURGE",
409
- headers: this.headers
410
- }).catch(function (error) {
411
- console.warn('No purge method allowed: ' + error);
412
- });
413
- try {
414
- const fullURL = new URL(id);
415
- var pathArray = fullURL.pathname.split('/');
416
- var containerUrl = fullURL.origin + '/' + pathArray[1] + '/';
417
- const headers = {
418
- ...this.headers,
419
- 'X-Cache-Purge-Match': 'startswith'
420
- };
421
- await this.fetchAuthn(containerUrl, {
422
- method: "PURGE",
423
- headers: headers
424
- }).catch(function (error) {
425
- console.warn('No purge method allowed: ' + error);
426
- });
427
- } catch (error) {
428
- console.warn('The resource ID is not a complete URL: ' + error);
429
- return;
430
- }
431
- }
432
-
433
- /**
434
- * Send a DELETE request to delete a resource
435
- * @param id - uri of the resource to delete
436
- * @param context - can be used to expand id
437
- *
438
- * @returns id of the deleted resource
439
- */
440
- async delete(id) {
441
- let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
442
- const expandedId = this._getExpandedId(id, context);
443
- const deleted = await this.fetchAuthn(expandedId, {
444
- method: 'DELETE',
445
- headers: this.headers,
446
- credentials: 'include'
447
- });
448
- // await this.purge(id);
449
-
450
- const resourcesToNotify = this.subscriptionIndex.get(expandedId) || [];
451
- const resourcesToRefresh = this.subscriptionVirtualContainersIndex.get(expandedId) || [];
452
- this.refreshResources([...resourcesToNotify, ...resourcesToRefresh]).then(resourceIds => this.notifyResources(resourceIds));
453
- return deleted;
454
- }
455
-
456
- /**
457
- * Convert headers object to Headers
458
- * @param headersObject - object
459
- * @returns {Headers}
460
- */
461
- _convertHeaders(headersObject) {
462
- const headers = new Headers();
463
- for (const [key, value] of Object.entries(headersObject)) {
464
- headers.set(key, value);
465
- }
466
- return headers;
467
- }
468
- _getExpandedId(id, context) {
469
- return context && Object.keys(context) ? ContextParser.expandTerm(id, context) : id;
470
- }
471
- _isLocalId(id) {
472
- return id.startsWith('store://local.');
473
- }
474
-
475
- /**
476
- * Make a resource listen changes of another one
477
- * @param resourceId - id of the resource which needs to be updated
478
- * @param nestedResourceId - id of the resource which will change
479
- */
480
- subscribeResourceTo(resourceId, nestedResourceId) {
481
- const existingSubscriptions = this.subscriptionIndex.get(nestedResourceId) || [];
482
- this.subscriptionIndex.set(nestedResourceId, [...new Set([...existingSubscriptions, resourceId])]);
483
- }
484
-
485
- /**
486
- * Make a virtual container listen for changes of a resource
487
- * @param virtualContainerId - id of the container which needs to be updated
488
- * @param nestedResourceId - id of the resource which will change
489
- */
490
- subscribeVirtualContainerTo(virtualContainerId, nestedResourceId) {
491
- const existingSubscriptions = this.subscriptionVirtualContainersIndex.get(nestedResourceId) || [];
492
- this.subscriptionVirtualContainersIndex.set(nestedResourceId, [...new Set([...existingSubscriptions, virtualContainerId])]);
493
- }
494
-
495
- /**
496
- * Return absolute IRI of the resource
497
- * @param id
498
- * @param context
499
- * @param parentId
500
- */
501
- _getAbsoluteIri(id, context, parentId) {
502
- let iri = ContextParser.expandTerm(id, context); // expand if reduced ids
503
- if (parentId) {
504
- // and get full URL from parent caller for local files
505
- let parentIri = new URL(parentId, document.location.href).href;
506
- iri = new URL(iri, parentIri).href;
507
- } else {
508
- iri = new URL(iri, document.location.href).href;
509
- }
510
- return iri;
511
- }
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
-
521
- /**
522
- * Return language of the users
523
- */
524
- _getLanguage() {
525
- return localStorage.getItem('language') || window.navigator.language.slice(0, 2);
526
- }
527
-
528
- /**
529
- * Save the preferred language of the user
530
- * @param selectedLanguageCode
531
- */
532
- selectLanguage(selectedLanguageCode) {
533
- localStorage.setItem('language', selectedLanguageCode);
534
- }
535
- }
536
- let store;
537
- if (window.sibStore) {
538
- store = window.sibStore;
539
- } else {
540
- const sibAuth = document.querySelector('sib-auth');
541
- const storeOptions = {};
542
- if (sibAuth) {
543
- const sibAuthDefined = customElements.whenDefined(sibAuth.localName);
544
- storeOptions.session = sibAuthDefined.then(() => sibAuth.session);
545
- storeOptions.fetchMethod = sibAuthDefined.then(() => sibAuth.getFetch());
546
- }
547
- store = new Store(storeOptions);
548
- window.sibStore = store;
549
- }
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
- }