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