@startinblox/core 2.0.1-beta.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  var _a2;
5
- import { g as getDefaultExportFromCjs, s as store, b as base_context, f as formatAttributesToServerPaginationOptions, m as mergeServerSearchOptions, a as formatAttributesToServerSearchOptions, c as commonjsGlobal } from "./store-Clion-HD.js";
5
+ import { g as getDefaultExportFromCjs, s as store, b as base_context, f as formatAttributesToServerPaginationOptions, m as mergeServerSearchOptions, a as formatAttributesToServerSearchOptions, c as commonjsGlobal } from "./store-1t_BHzwg.js";
6
6
  import { d as defineComponent, n as normalizeContext, u as uniqID, e as evalTemplateString, a as doesResourceContainList, c as compare, p as parseFieldsString, f as findClosingBracketMatchIndex, g as generalComparator, b as fuzzyCompare, h as asyncQuerySelector, i as importInlineCSS, j as importCSS, t as transformArrayToContainer, s as setDeepProperty } from "./helpers-4GFJ8HI8.js";
7
7
  import { k } from "./helpers-4GFJ8HI8.js";
8
8
  if (!("flat" in Array.prototype)) {
@@ -1593,15 +1593,11 @@ const StoreMixin = {
1593
1593
  },
1594
1594
  created() {
1595
1595
  if (this.element.closest("[no-render]")) this.noRender = "";
1596
- this.loadResource();
1597
1596
  },
1598
1597
  detached() {
1599
1598
  if (this.subscription) PubSub.unsubscribe(this.subscription);
1600
1599
  },
1601
1600
  get resource() {
1602
- return this._resource;
1603
- },
1604
- async loadResource() {
1605
1601
  var _a3;
1606
1602
  const id = this.resourceId;
1607
1603
  const serverPagination = formatAttributesToServerPaginationOptions(
@@ -1612,16 +1608,7 @@ const StoreMixin = {
1612
1608
  (_a3 = this.getDynamicServerSearch) == null ? void 0 : _a3.call(this)
1613
1609
  // from `filterMixin`
1614
1610
  );
1615
- if (id) {
1616
- const fetched = await store.get(
1617
- id,
1618
- serverPagination,
1619
- serverSearch
1620
- );
1621
- this._resource = fetched;
1622
- return this._resource;
1623
- }
1624
- return null;
1611
+ return id ? store.get(id, serverPagination, serverSearch) : null;
1625
1612
  },
1626
1613
  get loader() {
1627
1614
  return this.loaderId ? document.getElementById(this.loaderId) : null;
@@ -1629,8 +1616,7 @@ const StoreMixin = {
1629
1616
  async fetchData(value) {
1630
1617
  var _a3;
1631
1618
  this.empty();
1632
- if (this.sub1) PubSub.unsubscribe(this.sub1);
1633
- if (this.sub2) PubSub.unsubscribe(this.sub2);
1619
+ if (this.subscription) PubSub.unsubscribe(this.subscription);
1634
1620
  if (!value || value === "undefined") return;
1635
1621
  this.resourceId = value;
1636
1622
  if (this.nestedField) {
@@ -1641,14 +1627,13 @@ const StoreMixin = {
1641
1627
  for (const property in await resource) {
1642
1628
  console.log(`${property}: ${await resource[property]}`);
1643
1629
  }
1644
- throw `Error: the key "${this.nestedField}" does not exist on the resource at id "${resource["@id"]}"`;
1630
+ throw `Error: the key "${this.nestedField}" does not exist on the resource at id "${await resource["@id"]}"`;
1645
1631
  }
1646
1632
  }
1647
1633
  this.updateNavigateSubscription();
1648
- this.sub1 = PubSub.subscribe(this.resourceId, this.updateDOM.bind(this));
1649
- this.sub2 = PubSub.subscribe(
1634
+ this.subscription = PubSub.subscribe(
1650
1635
  this.resourceId,
1651
- this.syncResourceWithCache.bind(this)
1636
+ this.updateDOM.bind(this)
1652
1637
  );
1653
1638
  const serverPagination = formatAttributesToServerPaginationOptions(
1654
1639
  this.element.attributes
@@ -1668,19 +1653,14 @@ const StoreMixin = {
1668
1653
  serverPagination,
1669
1654
  serverSearch
1670
1655
  );
1671
- this._resource = await store.get(this.resourceId);
1672
1656
  this.updateDOM();
1673
1657
  },
1674
- async syncResourceWithCache() {
1675
- this._resource = await store.get(this.resourceId);
1676
- },
1677
1658
  toggleLoaderHidden(toggle) {
1678
1659
  if (this.loader) this.loader.toggleAttribute("hidden", toggle);
1679
1660
  },
1680
1661
  updateNavigateSubscription() {
1681
1662
  },
1682
1663
  async updateDOM() {
1683
- this._resource = await store.get(this.resourceId);
1684
1664
  this.toggleLoaderHidden(false);
1685
1665
  this.empty();
1686
1666
  await this.replaceAttributesData();
@@ -2873,34 +2853,24 @@ const FederationMixin = {
2873
2853
  if (!this.containerFetched.includes(containerId)) {
2874
2854
  this.containerFetched.push(containerId);
2875
2855
  const resourcesFetched = await this.fetchSource(containerId);
2876
- if (resourcesFetched) {
2877
- const t2 = await this.getResources(resourcesFetched);
2878
- newResources.push(...t2);
2879
- }
2856
+ if (resourcesFetched)
2857
+ newResources.push(...await this.getResources(resourcesFetched));
2880
2858
  }
2881
2859
  } else {
2882
2860
  newResources.push(res);
2883
2861
  }
2884
2862
  };
2885
2863
  if (!Array.isArray(resources)) resources = [resources];
2886
- await Promise.all(resources.map(async (res) => await getChildResources(res)));
2864
+ await Promise.all(resources.map((res) => getChildResources(res)));
2887
2865
  return newResources;
2888
2866
  },
2889
2867
  async fetchSource(containerId) {
2890
- let container = await store.get(containerId);
2891
- const isMissingOrEmpty = !container || await container.getContainerList() === null;
2892
- if (isMissingOrEmpty) {
2893
- container = await store.getData(
2894
- containerId,
2895
- this.context,
2896
- void 0,
2897
- void 0,
2898
- true
2899
- );
2900
- } else {
2901
- container = await store.getData(containerId, this.context);
2868
+ const cachedContainer = store.get(containerId);
2869
+ if (!cachedContainer || cachedContainer.getContainerList() === null) {
2870
+ store.clearCache(containerId);
2902
2871
  }
2903
- return await (container == null ? void 0 : container["listPredicate"]);
2872
+ const container = await store.getData(containerId, this.context);
2873
+ return container == null ? void 0 : container["listPredicate"];
2904
2874
  }
2905
2875
  };
2906
2876
  const isSet$1 = (field, fields) => {
@@ -2946,8 +2916,7 @@ const matchValue = async (val, query, throwOn) => {
2946
2916
  }
2947
2917
  if ((_a3 = subject.isContainer) == null ? void 0 : _a3.call(subject)) {
2948
2918
  let ret = Promise.resolve(query.value === "");
2949
- const subjectList = await subject["listPredicate"];
2950
- for (const value of subjectList) {
2919
+ for (const value of subject["listPredicate"]) {
2951
2920
  ret = await ret || await matchValue(value, query);
2952
2921
  if (ret) return orThrow(throwOn, true);
2953
2922
  }
@@ -2995,7 +2964,7 @@ const traversePath = async (resource, path, targetedType) => {
2995
2964
  let targetsRes = await res[remainingPath[0]];
2996
2965
  if (!targetsRes) return [];
2997
2966
  if ((_a3 = targetsRes.isContainer) == null ? void 0 : _a3.call(targetsRes)) {
2998
- targetsRes = await targetsRes["listPredicate"];
2967
+ targetsRes = targetsRes["listPredicate"];
2999
2968
  }
3000
2969
  if (!Array.isArray(targetsRes)) targetsRes = [targetsRes];
3001
2970
  for (const targetRes of targetsRes) {
@@ -3107,11 +3076,11 @@ const FilterMixin = {
3107
3076
  filteredBy: {
3108
3077
  type: String,
3109
3078
  default: null,
3110
- async callback(newValue) {
3079
+ callback(newValue) {
3111
3080
  if (newValue && this.searchForm && newValue !== this.searchForm.getAttribute("id")) {
3112
3081
  this.searchForm.component.detach(this);
3113
3082
  this.searchForm = null;
3114
- await this.populate();
3083
+ this.populate();
3115
3084
  }
3116
3085
  }
3117
3086
  },
@@ -3204,7 +3173,7 @@ const FilterMixin = {
3204
3173
  await this.populate();
3205
3174
  },
3206
3175
  async getValuesOfField(field) {
3207
- const arrayOfDataObjects = await this.resource["listPredicate"];
3176
+ const arrayOfDataObjects = this.resource["listPredicate"];
3208
3177
  const arrayOfDataIds = [];
3209
3178
  for (const obj of arrayOfDataObjects) {
3210
3179
  const nextArrayOfObjects = await obj[field];
@@ -3219,7 +3188,7 @@ const FilterMixin = {
3219
3188
  arrayOfDataIds.push(nextArrayOfObjects["@id"]);
3220
3189
  continue;
3221
3190
  }
3222
- const children = await nextArrayOfObjects["listPredicate"];
3191
+ const children = nextArrayOfObjects["listPredicate"];
3223
3192
  if (!children) continue;
3224
3193
  arrayOfDataIds.push(...children.map((child) => child["@id"]));
3225
3194
  }
@@ -3478,10 +3447,7 @@ const ListMixin = {
3478
3447
  var _a3, _b, _c, _d;
3479
3448
  const listPostProcessorsCopy = this.listPostProcessors.deepCopy();
3480
3449
  const div = this.div;
3481
- if (!await this.resource) {
3482
- console.warn("[ListMixin] No resource to populate");
3483
- return;
3484
- }
3450
+ if (!this.resource) return;
3485
3451
  if (!((_b = (_a3 = this.resource).isContainer) == null ? void 0 : _b.call(_a3)) && !this.arrayField && !this.predicateName) {
3486
3452
  this.setElementAttribute("resource");
3487
3453
  this.appendSingleElt(div);
@@ -3499,14 +3465,13 @@ const ListMixin = {
3499
3465
  "ListMixin:handleEmptyWidget"
3500
3466
  );
3501
3467
  const nextProcessor = listPostProcessorsCopy.shift();
3502
- const listPredicate = await this.resource["listPredicate"];
3503
3468
  await nextProcessor(
3504
- listPredicate,
3469
+ this.resource["listPredicate"],
3505
3470
  listPostProcessorsCopy,
3506
3471
  div,
3507
3472
  this.dataSrc
3508
3473
  );
3509
- } else if (this.arrayField && this.predicateName && await this.resource[this.predicateName]) {
3474
+ } else if (this.arrayField && this.predicateName && this.resource[this.predicateName]) {
3510
3475
  this.setElementAttribute("container");
3511
3476
  this.renderCallbacks = [];
3512
3477
  listPostProcessorsCopy.attach(
@@ -3740,10 +3705,10 @@ const SorterMixin = {
3740
3705
  sortedBy: {
3741
3706
  type: String,
3742
3707
  default: null,
3743
- async callback(newValue) {
3708
+ callback(newValue) {
3744
3709
  if (newValue && this.sortForm && newValue !== this.sortForm.getAttribute("id")) {
3745
3710
  this.sortForm = null;
3746
- await this.populate();
3711
+ this.populate();
3747
3712
  }
3748
3713
  }
3749
3714
  }
@@ -91414,9 +91379,9 @@ const MultipleFormMixin = {
91414
91379
  const nextProcessor = listValueTransformations.shift();
91415
91380
  if (nextProcessor) nextProcessor(value, listValueTransformations);
91416
91381
  },
91417
- async populate() {
91382
+ populate() {
91418
91383
  var _a3;
91419
- const resources = await ((_a3 = this.resource) == null ? void 0 : _a3["listPredicate"]);
91384
+ const resources = (_a3 = this.resource) == null ? void 0 : _a3["listPredicate"];
91420
91385
  if (!resources) return;
91421
91386
  this.listAttributes.children = [];
91422
91387
  for (const resource of resources) {
@@ -91519,9 +91484,9 @@ const MultipleselectFormMixin = {
91519
91484
  const nextProcessor = listValueTransformations.shift();
91520
91485
  if (nextProcessor) nextProcessor(value, listValueTransformations);
91521
91486
  },
91522
- async populate() {
91487
+ populate() {
91523
91488
  var _a3;
91524
- const resources = await ((_a3 = this.resource) == null ? void 0 : _a3["listPredicate"]);
91489
+ const resources = (_a3 = this.resource) == null ? void 0 : _a3["listPredicate"];
91525
91490
  if (!this.resource || !resources && !Array.isArray(this.resource)) return;
91526
91491
  this.setValue(resources);
91527
91492
  this.planRender();
@@ -91614,7 +91579,7 @@ const RangeMixin = {
91614
91579
  this.listAttributes.optionValue = this.optionValue;
91615
91580
  },
91616
91581
  async populate() {
91617
- const resources = this.resource ? await this.resource["listPredicate"] : [];
91582
+ const resources = this.resource ? this.resource["listPredicate"] : [];
91618
91583
  const listPostProcessorsCopy = this.listPostProcessors.deepCopy();
91619
91584
  listPostProcessorsCopy.attach(
91620
91585
  this.setRangeAttribute.bind(this),
@@ -91643,7 +91608,7 @@ const RangeMixin = {
91643
91608
  return { value, label, selectedValue };
91644
91609
  };
91645
91610
  this.listAttributes.range = await Promise.all(
91646
- resources.filter((el) => el !== null).map(async (r3) => await getRangeValue(r3))
91611
+ resources.filter((el) => el !== null).map((r3) => getRangeValue(r3))
91647
91612
  );
91648
91613
  }
91649
91614
  this.planRender();
@@ -96471,7 +96436,7 @@ const WidgetMixin = {
96471
96436
  if (attr) return parseFieldsString(attr);
96472
96437
  let resource = this.resource;
96473
96438
  if ((_a3 = resource == null ? void 0 : resource.isContainer) == null ? void 0 : _a3.call(resource)) {
96474
- const resources = await resource["listPredicate"];
96439
+ const resources = resource["listPredicate"];
96475
96440
  for (const res of resources) {
96476
96441
  resource = res;
96477
96442
  break;
@@ -97118,7 +97083,7 @@ const SolidFormSearch = {
97118
97083
  "@context": this.context,
97119
97084
  "ldp:contains": ldpContains
97120
97085
  };
97121
- await sibStore.setLocalData(data, id);
97086
+ sibStore.setLocalData(data, id);
97122
97087
  }
97123
97088
  },
97124
97089
  change(resource, eventOptions) {
@@ -98625,7 +98590,7 @@ class BaseWidget extends HTMLElement {
98625
98590
  }
98626
98591
  async fetchSources(resource) {
98627
98592
  var _a3;
98628
- const data = await resource["listPredicate"];
98593
+ const data = resource["listPredicate"];
98629
98594
  if (!data) return null;
98630
98595
  const resources = [];
98631
98596
  let index2 = 0;
@@ -98645,7 +98610,7 @@ class BaseWidget extends HTMLElement {
98645
98610
  );
98646
98611
  this._listen(res["@id"]);
98647
98612
  if (resourcesFromContainer) {
98648
- resources.push(...await resourcesFromContainer["listPredicate"]);
98613
+ resources.push(...resourcesFromContainer["listPredicate"]);
98649
98614
  }
98650
98615
  } else {
98651
98616
  resources.push(res);
@@ -98665,8 +98630,7 @@ class BaseWidget extends HTMLElement {
98665
98630
  let selected;
98666
98631
  if ((_b = (_a3 = this._value) == null ? void 0 : _a3.isContainer) == null ? void 0 : _b.call(_a3)) {
98667
98632
  selected = false;
98668
- const listPredicate = await this._value["listPredicate"];
98669
- for await (const value of listPredicate) {
98633
+ for await (const value of this._value["listPredicate"]) {
98670
98634
  if (value["@id"] === element["@id"]) {
98671
98635
  selected = true;
98672
98636
  break;
@@ -8851,25 +8851,23 @@ class CustomGetter {
8851
8851
  if (!isUrl.protocol.startsWith("http"))
8852
8852
  throw new Error("Not a valid HTTP url");
8853
8853
  if (isUrl) {
8854
- let resources = await this.getList(path);
8854
+ let resources = this.getList(path);
8855
8855
  if (!resources || Array.isArray(resources) && resources.length === 0)
8856
8856
  return void 0;
8857
8857
  if (!Array.isArray(resources)) resources = [resources];
8858
- const result = resources ? Promise.all(
8859
- resources.map(async (res) => {
8860
- let resource = await store.get(res["@id"]);
8861
- if (resource) return resource;
8862
- resource = new CustomGetter(
8863
- res["@id"],
8864
- { "@id": res["@id"] },
8865
- this.clientContext,
8866
- this.serverContext,
8867
- this.parentId
8868
- ).getProxy();
8869
- await store.cacheResource(res["@id"], resource);
8870
- return resource;
8871
- })
8872
- ) : [];
8858
+ const result = resources ? resources.map((res) => {
8859
+ let resource = store.get(res["@id"]);
8860
+ if (resource) return resource;
8861
+ resource = new CustomGetter(
8862
+ res["@id"],
8863
+ { "@id": res["@id"] },
8864
+ this.clientContext,
8865
+ this.serverContext,
8866
+ this.parentId
8867
+ ).getProxy();
8868
+ store.cacheResource(res["@id"], resource);
8869
+ return resource;
8870
+ }) : [];
8873
8871
  return result;
8874
8872
  }
8875
8873
  } catch {
@@ -8945,7 +8943,7 @@ class CustomGetter {
8945
8943
  */
8946
8944
  async getResource(id, context2, iriParent, forceFetch = false) {
8947
8945
  if (id.startsWith("_:b")) return await store.get(id + iriParent);
8948
- return await store.getData(id, context2, iriParent, void 0, forceFetch);
8946
+ return store.getData(id, context2, iriParent, void 0, forceFetch);
8949
8947
  }
8950
8948
  /**
8951
8949
  * Return true if the resource is a container
@@ -8981,12 +8979,12 @@ class CustomGetter {
8981
8979
  /**
8982
8980
  * Get children of container as objects
8983
8981
  */
8984
- async getList(predicateName) {
8985
- let value = await this.resource[predicateName];
8982
+ getList(predicateName) {
8983
+ let value = this.resource[predicateName];
8986
8984
  if (!value) {
8987
8985
  const index = this.getExpandedPredicate(predicateName);
8988
8986
  if (index) {
8989
- value = await this.resource[index];
8987
+ value = this.resource[index];
8990
8988
  }
8991
8989
  }
8992
8990
  if (value === void 0 || value === null) {
@@ -8994,35 +8992,33 @@ class CustomGetter {
8994
8992
  }
8995
8993
  return value;
8996
8994
  }
8997
- async getListAndCacheIt(predicate) {
8998
- let children = await this.getList(predicate);
8995
+ getListAndCacheIt(predicate) {
8996
+ let children = this.getList(predicate);
8999
8997
  if (!children) return null;
9000
8998
  if (!Array.isArray(children)) children = [children];
9001
- const result = children ? await Promise.all(
9002
- children.map(async (res) => {
9003
- let resource = await store.get(res["@id"]);
9004
- if (resource) return resource;
9005
- resource = new CustomGetter(
9006
- res["@id"],
9007
- { "@id": res["@id"] },
9008
- this.clientContext,
9009
- this.serverContext,
9010
- this.parentId
9011
- ).getProxy();
9012
- await store.cacheResource(res["@id"], resource);
9013
- return resource;
9014
- })
9015
- ) : [];
8999
+ const result = children ? children.map((res) => {
9000
+ let resource = store.get(res["@id"]);
9001
+ if (resource) return resource;
9002
+ resource = new CustomGetter(
9003
+ res["@id"],
9004
+ { "@id": res["@id"] },
9005
+ this.clientContext,
9006
+ this.serverContext,
9007
+ this.parentId
9008
+ ).getProxy();
9009
+ store.cacheResource(res["@id"], resource);
9010
+ return resource;
9011
+ }) : [];
9016
9012
  return result;
9017
9013
  }
9018
- async getDcatDataset() {
9019
- return await this.getListAndCacheIt("dcat:dataset");
9014
+ getDcatDataset() {
9015
+ return this.getListAndCacheIt("dcat:dataset");
9020
9016
  }
9021
9017
  /**
9022
9018
  * Get children of container as Proxys
9023
9019
  */
9024
- async getLdpContains() {
9025
- return await this.getListAndCacheIt("ldp:contains");
9020
+ getLdpContains() {
9021
+ return this.getListAndCacheIt("ldp:contains");
9026
9022
  }
9027
9023
  merge(resource) {
9028
9024
  this.resource = {
@@ -9040,12 +9036,12 @@ class CustomGetter {
9040
9036
  * If the resource is not a container or a catalog, it will return null
9041
9037
  * @returns object[] | null
9042
9038
  */
9043
- async getContainerList() {
9039
+ getContainerList() {
9044
9040
  if (this.hasType("ldp:Container")) {
9045
- return await this.getLdpContains();
9041
+ return this.getLdpContains();
9046
9042
  }
9047
9043
  if (this.getType() === "dcat:Catalog") {
9048
- return await this.getDcatDataset();
9044
+ return this.getDcatDataset();
9049
9045
  }
9050
9046
  return null;
9051
9047
  }
@@ -9108,8 +9104,8 @@ class CustomGetter {
9108
9104
  /**
9109
9105
  * Remove the resource from the cache
9110
9106
  */
9111
- async clearCache() {
9112
- await store.clearCache(this.resourceId);
9107
+ clearCache() {
9108
+ store.clearCache(this.resourceId);
9113
9109
  }
9114
9110
  getExpandedPredicate(property) {
9115
9111
  const context2 = normalizeContext(
@@ -9176,7 +9172,7 @@ class CustomGetter {
9176
9172
  });
9177
9173
  }
9178
9174
  }
9179
- class InMemoryCacheManager {
9175
+ class CacheManager {
9180
9176
  constructor() {
9181
9177
  __publicField(this, "resourceCache", /* @__PURE__ */ new Map());
9182
9178
  __publicField(this, "urlToIdMap", /* @__PURE__ */ new Map());
@@ -9188,8 +9184,7 @@ class InMemoryCacheManager {
9188
9184
  * @param url - The original URL used to fetch the resource.
9189
9185
  * @returns The cached resource, or undefined if not found.
9190
9186
  */
9191
- // biome-ignore lint/suspicious/useAwait: necessary for interface compatibility
9192
- async getByUrl(url2) {
9187
+ getByUrl(url2) {
9193
9188
  const id = this.urlToIdMap.get(url2);
9194
9189
  if (!id) return void 0;
9195
9190
  return this.resourceCache.get(id);
@@ -9204,8 +9199,7 @@ class InMemoryCacheManager {
9204
9199
  * @param id - The @id of the resource (can be a URI, URN, or UUID).
9205
9200
  * @returns The cached resource, or undefined if not found.
9206
9201
  */
9207
- // biome-ignore lint/suspicious/useAwait: necessary for interface compatibility
9208
- async getById(id) {
9202
+ getById(id) {
9209
9203
  return this.resourceCache.get(id);
9210
9204
  }
9211
9205
  /**
@@ -9216,8 +9210,7 @@ class InMemoryCacheManager {
9216
9210
  * @param idOrUrl - A resource @id or its original fetch URL.
9217
9211
  * @returns The cached resource, or undefined if not found.
9218
9212
  */
9219
- // biome-ignore lint/suspicious/useAwait: necessary for interface compatibility
9220
- async get(ref) {
9213
+ get(ref) {
9221
9214
  if (this.resourceCache.has(ref)) {
9222
9215
  return this.resourceCache.get(ref);
9223
9216
  }
@@ -9227,8 +9220,7 @@ class InMemoryCacheManager {
9227
9220
  }
9228
9221
  return void 0;
9229
9222
  }
9230
- // biome-ignore lint/suspicious/useAwait: necessary for interface compatibility
9231
- async length() {
9223
+ length() {
9232
9224
  return this.resourceCache.size;
9233
9225
  }
9234
9226
  /**
@@ -9237,8 +9229,7 @@ class InMemoryCacheManager {
9237
9229
  * @param url - The URL from which the resource was fetched.
9238
9230
  * @param resource - The JSON-LD resource to store. Must contain a valid @id.
9239
9231
  */
9240
- // biome-ignore lint/suspicious/useAwait: necessary for interface compatibility
9241
- async set(url2, resource) {
9232
+ set(url2, resource) {
9242
9233
  const id = resource == null ? void 0 : resource["@id"];
9243
9234
  if (!id) {
9244
9235
  console.warn("[CacheManager] Resource has no @id", resource);
@@ -9256,11 +9247,10 @@ class InMemoryCacheManager {
9256
9247
  * @param url - Data source (absolute or relative path).
9257
9248
  * @param emptyResource - The resource to associate with this URL. Must include a valid `@id`.
9258
9249
  */
9259
- // biome-ignore lint/suspicious/useAwait: necessary for interface compatibility
9260
- async linkUrlWithId(url2, emptyResource) {
9250
+ linkUrlWithId(url2, emptyResource) {
9261
9251
  if (!isUrlOrRelativePath(url2)) return;
9262
9252
  if (this.hasUrlMatch(url2)) return;
9263
- await this.set(url2, emptyResource);
9253
+ this.set(url2, emptyResource);
9264
9254
  }
9265
9255
  /**
9266
9256
  * Checks if a resource is cached.
@@ -9269,8 +9259,7 @@ class InMemoryCacheManager {
9269
9259
  * @param urlOrId - The @id or URL to check for.
9270
9260
  * @returns True if the resource exists in cache, false otherwise.
9271
9261
  */
9272
- // biome-ignore lint/suspicious/useAwait: necessary for interface compatibility
9273
- async has(urlOrId) {
9262
+ has(urlOrId) {
9274
9263
  if (this.resourceCache.has(urlOrId)) return true;
9275
9264
  const id = this.urlToIdMap.get(urlOrId);
9276
9265
  return id ? this.resourceCache.has(id) : false;
@@ -9281,15 +9270,13 @@ class InMemoryCacheManager {
9281
9270
  * @param url - The original fetch URL.
9282
9271
  * @returns The associated @id, or undefined if no mapping exists.
9283
9272
  */
9284
- // biome-ignore lint/suspicious/useAwait: necessary for interface compatibility
9285
- async getIdByUrl(url2) {
9273
+ getIdByUrl(url2) {
9286
9274
  return this.urlToIdMap.get(url2);
9287
9275
  }
9288
9276
  /**
9289
9277
  * Clears the entire cache and all URL-to-ID mappings.
9290
9278
  */
9291
- // biome-ignore lint/suspicious/useAwait: necessary for interface compatibility
9292
- async clear() {
9279
+ clear() {
9293
9280
  this.resourceCache.clear();
9294
9281
  this.urlToIdMap.clear();
9295
9282
  }
@@ -9300,8 +9287,7 @@ class InMemoryCacheManager {
9300
9287
  * @param idOrUrl - The @id or URL of the resource to delete.
9301
9288
  * @returns True if the resource was found and deleted, false otherwise.
9302
9289
  */
9303
- // biome-ignore lint/suspicious/useAwait: necessary for interface compatibility
9304
- async delete(idOrUrl) {
9290
+ delete(idOrUrl) {
9305
9291
  if (this.resourceCache.has(idOrUrl)) {
9306
9292
  this.resourceCache.delete(idOrUrl);
9307
9293
  for (const [url2, id2] of this.urlToIdMap.entries()) {
@@ -9373,7 +9359,7 @@ class Store {
9373
9359
  return handler;
9374
9360
  });
9375
9361
  this.storeOptions = storeOptions;
9376
- this.cache = this.storeOptions.cacheManager ?? new InMemoryCacheManager();
9362
+ this.cache = new CacheManager();
9377
9363
  this.subscriptionIndex = /* @__PURE__ */ new Map();
9378
9364
  this.subscriptionVirtualContainersIndex = /* @__PURE__ */ new Map();
9379
9365
  this.loadingList = /* @__PURE__ */ new Set();
@@ -9401,7 +9387,7 @@ class Store {
9401
9387
  *
9402
9388
  * @async
9403
9389
  */
9404
- async getData(id, context2 = [], parentId = "", localData, forceFetch = false, serverPagination, serverSearch) {
9390
+ async getData(id, context2 = [], parentId = "", localData, forceFetch = false, serverPagination, serverSearch, headers) {
9405
9391
  var _a;
9406
9392
  let key = id;
9407
9393
  if (serverPagination) {
@@ -9410,8 +9396,8 @@ class Store {
9410
9396
  if (serverSearch) {
9411
9397
  key = appendServerSearchToIri(key, serverSearch);
9412
9398
  }
9413
- if (localData == null && await this.cache.has(key) && !this.loadingList.has(key)) {
9414
- const resource = await this.get(key);
9399
+ if (localData == null && this.cache.has(key) && !this.loadingList.has(key)) {
9400
+ const resource = this.get(key);
9415
9401
  if (((_a = resource == null ? void 0 : resource.isFullResource) == null ? void 0 : _a.call(resource)) && !forceFetch) return await resource;
9416
9402
  }
9417
9403
  return new Promise(async (resolve) => {
@@ -9421,7 +9407,7 @@ class Store {
9421
9407
  );
9422
9408
  if (this.loadingList.has(key)) return;
9423
9409
  this.loadingList.add(key);
9424
- let clientContext = await this.contextParser.parse(
9410
+ const clientContext = await this.contextParser.parse(
9425
9411
  getRawContext(context2)
9426
9412
  );
9427
9413
  let resource = null;
@@ -9436,7 +9422,8 @@ class Store {
9436
9422
  clientContext,
9437
9423
  parentId,
9438
9424
  serverPagination,
9439
- serverSearch
9425
+ serverSearch,
9426
+ headers
9440
9427
  );
9441
9428
  } catch (error) {
9442
9429
  console.error(error);
@@ -9450,14 +9437,6 @@ class Store {
9450
9437
  );
9451
9438
  return;
9452
9439
  }
9453
- const rawCtx = resource["@context"] || base_context;
9454
- const normalizedRawContext = await this.contextParser.parse(
9455
- Array.isArray(rawCtx) ? rawCtx : [rawCtx]
9456
- );
9457
- if (resource)
9458
- clientContext = normalizeContext(
9459
- mergeContexts(clientContext, normalizedRawContext)
9460
- );
9461
9440
  const serverContext = await this.contextParser.parse([
9462
9441
  resource["@context"] || base_context
9463
9442
  ]);
@@ -9470,12 +9449,11 @@ class Store {
9470
9449
  serverSearch
9471
9450
  );
9472
9451
  this.loadingList.delete(key);
9473
- const finalResource = await this.get(key);
9474
9452
  document.dispatchEvent(
9475
9453
  new CustomEvent("resourceReady", {
9476
9454
  detail: {
9477
9455
  id: key,
9478
- resource: finalResource,
9456
+ resource: this.get(key),
9479
9457
  fetchedResource: resource
9480
9458
  }
9481
9459
  })
@@ -9501,19 +9479,20 @@ class Store {
9501
9479
  * @param serverSearch - Server search query params
9502
9480
  * @returns data in json
9503
9481
  */
9504
- async fetchData(id, context2 = null, parentId = "", serverPagination, serverSearch) {
9482
+ async fetchData(id, context2 = null, parentId = "", serverPagination, serverSearch, headers) {
9505
9483
  let iri = this._getAbsoluteIri(id, context2, parentId);
9506
9484
  if (serverPagination)
9507
9485
  iri = appendServerPaginationToIri(iri, serverPagination);
9508
9486
  if (serverSearch) iri = appendServerSearchToIri(iri, serverSearch);
9509
- const headers = {
9487
+ let requestHeaders = {
9510
9488
  ...this.headers,
9511
9489
  "accept-language": this._getLanguage()
9512
9490
  // 'Prefer' : 'return=representation; max-triple-count="100"' // Commenting out for now as it raises CORS errors
9513
9491
  };
9492
+ if (headers) requestHeaders = { ...requestHeaders, ...headers };
9514
9493
  return this.fetchAuthn(iri, {
9515
9494
  method: "GET",
9516
- headers,
9495
+ headers: requestHeaders,
9517
9496
  credentials: "include"
9518
9497
  }).then((response) => {
9519
9498
  if (!response.ok) return;
@@ -9530,7 +9509,8 @@ class Store {
9530
9509
  * @param serverSearch - Server search query params
9531
9510
  */
9532
9511
  async cacheGraph(resources, clientContext, parentContext, parentId, serverPagination, serverSearch) {
9533
- await this.cache.linkUrlWithId(
9512
+ var _a;
9513
+ this.cache.linkUrlWithId(
9534
9514
  parentId,
9535
9515
  CustomGetter.getEmptyResource(
9536
9516
  resources["@id"],
@@ -9540,7 +9520,7 @@ class Store {
9540
9520
  );
9541
9521
  const flattenedResources = await jsonld.flatten(resources);
9542
9522
  const compactedResources = await Promise.all(
9543
- flattenedResources.map(async (r) => jsonld.compact(await r, {}))
9523
+ flattenedResources.map((r) => jsonld.compact(r, {}))
9544
9524
  );
9545
9525
  for (const resource of compactedResources) {
9546
9526
  const id = resource["@id"] || resource.id;
@@ -9563,14 +9543,11 @@ class Store {
9563
9543
  serverSearch
9564
9544
  ).getProxy();
9565
9545
  if (resourceProxy.isContainer())
9566
- await this.subscribeChildren(resourceProxy, id);
9567
- if (await this.get(key)) {
9568
- const resourceFromCache = await this.cache.get(key);
9569
- if (resourceFromCache) {
9570
- resourceFromCache.merge(resourceProxy);
9571
- }
9546
+ this.subscribeChildren(resourceProxy, id);
9547
+ if (this.get(key)) {
9548
+ (_a = this.cache.get(key)) == null ? void 0 : _a.merge(resourceProxy);
9572
9549
  } else {
9573
- await this.cacheResource(key, resourceProxy);
9550
+ this.cacheResource(key, resourceProxy);
9574
9551
  }
9575
9552
  }
9576
9553
  }
@@ -9579,8 +9556,8 @@ class Store {
9579
9556
  * @param key
9580
9557
  * @param resourceProxy
9581
9558
  */
9582
- async cacheResource(key, resourceProxy) {
9583
- await this.cache.set(key, resourceProxy);
9559
+ cacheResource(key, resourceProxy) {
9560
+ this.cache.set(key, resourceProxy);
9584
9561
  }
9585
9562
  /**
9586
9563
  * Update fetch
@@ -9597,18 +9574,18 @@ class Store {
9597
9574
  body: JSON.stringify(resource),
9598
9575
  credentials: "include"
9599
9576
  });
9600
- const resourceProxy = await this.get(id);
9577
+ const resourceProxy = store.get(id);
9601
9578
  const clientContext = resourceProxy ? mergeContexts(resourceProxy.clientContext, resource["@context"]) : resource["@context"];
9602
- await this.clearCache(id);
9603
- await this.getData(id, clientContext, "", resource, true);
9579
+ this.clearCache(id);
9580
+ await this.getData(id, clientContext, "", resource);
9604
9581
  return { ok: true };
9605
9582
  }
9606
9583
  /**
9607
9584
  * Subscribe all the children of a container to its parent
9608
9585
  * @param container
9609
9586
  */
9610
- async subscribeChildren(container, containerId) {
9611
- const children = await container["listPredicate"];
9587
+ subscribeChildren(container, containerId) {
9588
+ const children = container["listPredicate"];
9612
9589
  if (!children) return;
9613
9590
  for (const res of children) {
9614
9591
  this.subscribeResourceTo(containerId, res["@id"] || res.id);
@@ -9621,7 +9598,7 @@ class Store {
9621
9598
  * @param id - id of the resource to update
9622
9599
  * @returns void
9623
9600
  */
9624
- async _updateResource(method, resource, id, skipFetch = false) {
9601
+ async _updateResource(method, resource, id) {
9625
9602
  if (!["POST", "PUT", "PATCH", "_LOCAL"].includes(method))
9626
9603
  throw new Error("Error: method not allowed");
9627
9604
  const context2 = await this.contextParser.parse([
@@ -9632,15 +9609,14 @@ class Store {
9632
9609
  return this._fetch(method, resource, id).then(async (response) => {
9633
9610
  var _a;
9634
9611
  if (response.ok) {
9635
- if (!skipFetch) {
9636
- if (method !== "_LOCAL") {
9637
- await this.clearCache(expandedId);
9638
- }
9639
- await this.getData(expandedId, resource["@context"]);
9612
+ if (method !== "_LOCAL") {
9613
+ this.clearCache(expandedId);
9614
+ }
9615
+ this.getData(expandedId, resource["@context"]).then(async () => {
9640
9616
  const nestedResources = await this.getNestedResources(resource, id);
9641
9617
  const resourcesToRefresh = this.subscriptionVirtualContainersIndex.get(expandedId) || [];
9642
9618
  const resourcesToNotify = this.subscriptionIndex.get(expandedId) || [];
9643
- await this.refreshResources([
9619
+ return this.refreshResources([
9644
9620
  ...nestedResources,
9645
9621
  ...resourcesToRefresh
9646
9622
  ]).then(
@@ -9650,7 +9626,7 @@ class Store {
9650
9626
  ...resourcesToNotify
9651
9627
  ])
9652
9628
  );
9653
- }
9629
+ });
9654
9630
  return ((_a = response.headers) == null ? void 0 : _a.get("Location")) || null;
9655
9631
  }
9656
9632
  throw response;
@@ -9662,29 +9638,21 @@ class Store {
9662
9638
  * @returns - all the resource ids
9663
9639
  */
9664
9640
  async refreshResources(resourceIds) {
9665
- const uniqueIds = Array.from(new Set(resourceIds));
9666
- const maybe = await Promise.all(
9667
- uniqueIds.map(
9668
- async (id) => await this.cache.has(id).then((ok) => ok ? id : null)
9669
- )
9670
- );
9671
- resourceIds = maybe.filter((id) => id !== null);
9672
- const resourceWithContexts = await Promise.all(
9673
- resourceIds.map(async (resourceId) => {
9674
- const res = await this.get(resourceId);
9675
- return {
9676
- id: resourceId,
9677
- context: res == null ? void 0 : res.clientContext
9678
- };
9679
- })
9680
- );
9641
+ resourceIds = [...new Set(resourceIds.filter((id) => this.cache.has(id)))];
9642
+ const resourceWithContexts = resourceIds.map((resourceId) => {
9643
+ var _a;
9644
+ return {
9645
+ id: resourceId,
9646
+ context: (_a = store.get(resourceId)) == null ? void 0 : _a.clientContext
9647
+ };
9648
+ });
9681
9649
  for (const resource of resourceWithContexts) {
9682
- if (!this._isLocalId(resource.id)) await this.clearCache(resource.id);
9650
+ if (!this._isLocalId(resource.id)) this.clearCache(resource.id);
9683
9651
  }
9684
9652
  await Promise.all(
9685
- resourceWithContexts.map(async ({ id, context: context2 }) => {
9686
- await this.getData(id, context2 || base_context);
9687
- })
9653
+ resourceWithContexts.map(
9654
+ ({ id, context: context2 }) => this.getData(id, context2 || base_context)
9655
+ )
9688
9656
  );
9689
9657
  return resourceIds;
9690
9658
  }
@@ -9701,9 +9669,9 @@ class Store {
9701
9669
  * @param resource - object
9702
9670
  * @param id - string
9703
9671
  */
9704
- async getNestedResources(resource, id) {
9672
+ getNestedResources(resource, id) {
9705
9673
  var _a;
9706
- const cachedResource = await this.get(id);
9674
+ const cachedResource = store.get(id);
9707
9675
  if (!cachedResource || ((_a = cachedResource.isContainer) == null ? void 0 : _a.call(cachedResource))) return [];
9708
9676
  const nestedProperties = [];
9709
9677
  const excludeKeys = ["@context"];
@@ -9720,31 +9688,30 @@ class Store {
9720
9688
  *
9721
9689
  * @returns Resource (Proxy) if in the cache, null otherwise
9722
9690
  */
9723
- async get(id, serverPagination, serverSearch) {
9691
+ get(id, serverPagination, serverSearch) {
9724
9692
  if (serverPagination) {
9725
9693
  id = appendServerPaginationToIri(id, serverPagination);
9726
9694
  }
9727
9695
  if (serverSearch) {
9728
9696
  id = appendServerSearchToIri(id, serverSearch);
9729
9697
  }
9730
- const resource = await this.cache.get(id) || null;
9731
- return resource;
9698
+ return this.cache.get(id) || null;
9732
9699
  }
9733
9700
  /**
9734
9701
  * Removes a resource from the cache
9735
9702
  * @param id - id of the resource to remove from the cache
9736
9703
  */
9737
- async clearCache(id) {
9738
- if (await this.cache.has(id)) {
9739
- const resource = await this.cache.get(id);
9740
- const predicate = resource ? await resource["listPredicate"] : null;
9704
+ clearCache(id) {
9705
+ if (this.cache.has(id)) {
9706
+ const resource = this.cache.get(id);
9707
+ const predicate = resource ? resource["listPredicate"] : null;
9741
9708
  if (predicate) {
9742
9709
  for (const child of predicate) {
9743
9710
  if ((child == null ? void 0 : child["@type"]) && doesResourceContainList(child))
9744
- await this.cache.delete(child["@id"]);
9711
+ this.cache.delete(child["@id"]);
9745
9712
  }
9746
9713
  }
9747
- await this.cache.delete(id);
9714
+ this.cache.delete(id);
9748
9715
  }
9749
9716
  }
9750
9717
  /**
@@ -9754,8 +9721,8 @@ class Store {
9754
9721
  *
9755
9722
  * @returns id of the posted resource
9756
9723
  */
9757
- setLocalData(resource, id, skipFetch = false) {
9758
- return this._updateResource("_LOCAL", resource, id, skipFetch);
9724
+ setLocalData(resource, id) {
9725
+ return this._updateResource("_LOCAL", resource, id);
9759
9726
  }
9760
9727
  /**
9761
9728
  * Send a POST request to create a resource in a container
@@ -9764,8 +9731,8 @@ class Store {
9764
9731
  *
9765
9732
  * @returns id of the posted resource
9766
9733
  */
9767
- post(resource, id, skipFetch = false) {
9768
- return this._updateResource("POST", resource, id, skipFetch);
9734
+ post(resource, id) {
9735
+ return this._updateResource("POST", resource, id);
9769
9736
  }
9770
9737
  /**
9771
9738
  * Send a PUT request to edit a resource
@@ -9774,8 +9741,8 @@ class Store {
9774
9741
  *
9775
9742
  * @returns id of the edited resource
9776
9743
  */
9777
- put(resource, id, skipFetch = false) {
9778
- return this._updateResource("PUT", resource, id, skipFetch);
9744
+ put(resource, id) {
9745
+ return this._updateResource("PUT", resource, id);
9779
9746
  }
9780
9747
  /**
9781
9748
  * Send a PATCH request to edit a resource
@@ -9784,8 +9751,8 @@ class Store {
9784
9751
  *
9785
9752
  * @returns id of the edited resource
9786
9753
  */
9787
- async patch(resource, id, skipFetch = false) {
9788
- return await this._updateResource("PATCH", resource, id, skipFetch);
9754
+ patch(resource, id) {
9755
+ return this._updateResource("PATCH", resource, id);
9789
9756
  }
9790
9757
  /**
9791
9758
  * Send a DELETE request to delete a resource
package/dist/store.js CHANGED
@@ -1,4 +1,4 @@
1
- import { b, s } from "./store-Clion-HD.js";
1
+ import { b, s } from "./store-1t_BHzwg.js";
2
2
  export {
3
3
  b as baseContext,
4
4
  s as store
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startinblox/core",
3
- "version": "2.0.1-beta.1",
3
+ "version": "2.0.1",
4
4
  "description": "This is a series of web component respecting both the web components standards and the Linked Data Platform convention.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",