@xwiki/cristal-backend-dexie 0.17.0 → 0.18.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @xwiki/cristal-backend-dexie
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Cristal 0.18 Release
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @xwiki/cristal-api@0.18.0
13
+ - @xwiki/cristal-backend-api@0.18.0
14
+ - @xwiki/cristal-sharedworker-api@0.18.0
15
+
3
16
  ## 0.17.0
4
17
 
5
18
  ### Minor Changes
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import u from "dexie";
2
- import { DefaultPageData as h } from "@xwiki/cristal-api";
3
- import { injectable as c, inject as i } from "inversify";
2
+ import { DefaultPageData as f } from "@xwiki/cristal-api";
3
+ import { injectable as h, inject as i } from "inversify";
4
4
  class d extends u {
5
5
  constructor(t) {
6
6
  super("pages_" + t), this.version(2).stores({
@@ -11,11 +11,11 @@ class d extends u {
11
11
  });
12
12
  }
13
13
  }
14
- var p = Object.defineProperty, S = Object.getOwnPropertyDescriptor, m = (e, t, o, r) => {
15
- for (var g = r > 1 ? void 0 : r ? S(t, o) : t, a = e.length - 1, s; a >= 0; a--)
16
- (s = e[a]) && (g = (r ? s(t, o, g) : s(g)) || g);
17
- return r && g && p(t, o, g), g;
18
- }, P = (e, t) => (o, r) => t(o, r, e);
14
+ var p = Object.getOwnPropertyDescriptor, S = (e, t, o, g) => {
15
+ for (var r = g > 1 ? void 0 : g ? p(t, o) : t, a = e.length - 1, s; a >= 0; a--)
16
+ (s = e[a]) && (r = s(r) || r);
17
+ return r;
18
+ }, m = (e, t) => (o, g) => t(o, g, e);
19
19
  let l = class {
20
20
  constructor(e) {
21
21
  this.pageStorageMap = /* @__PURE__ */ new Map(), this.logger = e, this.logger.setModule("storage.components.dexieOfflineStorage");
@@ -29,8 +29,8 @@ let l = class {
29
29
  this.logger.debug("Ready to load page from local storage", t);
30
30
  const o = this.getPageStorage(e);
31
31
  this.logger.debug("pageStorage is ready, asking for page");
32
- const r = await o.pages.get(t), g = new h();
33
- return g.fromObject(r), g;
32
+ const g = await o.pages.get(t), r = new f();
33
+ return r.fromObject(g), r;
34
34
  } catch (o) {
35
35
  this.logger.debug("Exception while trying to read from local storage", o);
36
36
  return;
@@ -39,41 +39,41 @@ let l = class {
39
39
  async savePage(e, t, o) {
40
40
  try {
41
41
  await this.getPageStorage(e).pages.put(o.toObject(), t);
42
- } catch (r) {
42
+ } catch (g) {
43
43
  this.logger.debug(
44
44
  "Exception while trying to store in local storage",
45
45
  e,
46
46
  t,
47
47
  o,
48
- r
48
+ g
49
49
  );
50
50
  }
51
51
  }
52
52
  async updatePage(e, t, o) {
53
53
  try {
54
- const r = this.getPageStorage(e);
55
- this.logger.debug("Ready to store", o), await r.pages.update(t, o.toObject());
56
- } catch (r) {
54
+ const g = this.getPageStorage(e);
55
+ this.logger.debug("Ready to store", o), await g.pages.update(t, o.toObject());
56
+ } catch (g) {
57
57
  this.logger.debug(
58
58
  "Exception while trying to store in local storage",
59
59
  e,
60
60
  t,
61
61
  o,
62
- r
62
+ g
63
63
  );
64
64
  }
65
65
  }
66
66
  };
67
- l = m([
68
- c(),
69
- P(0, i("Logger"))
67
+ l = S([
68
+ h(),
69
+ m(0, i("Logger"))
70
70
  ], l);
71
- var v = Object.defineProperty, b = Object.getOwnPropertyDescriptor, _ = (e, t, o, r) => {
72
- for (var g = r > 1 ? void 0 : r ? b(t, o) : t, a = e.length - 1, s; a >= 0; a--)
73
- (s = e[a]) && (g = (r ? s(t, o, g) : s(g)) || g);
74
- return r && g && v(t, o, g), g;
75
- }, n = (e, t) => (o, r) => t(o, r, e);
76
- let f = class {
71
+ var v = Object.getOwnPropertyDescriptor, P = (e, t, o, g) => {
72
+ for (var r = g > 1 ? void 0 : g ? v(t, o) : t, a = e.length - 1, s; a >= 0; a--)
73
+ (s = e[a]) && (r = s(r) || r);
74
+ return r;
75
+ }, n = (e, t) => (o, g) => t(o, g, e);
76
+ let c = class {
77
77
  constructor(e, t, o) {
78
78
  this.logger = e, this.logger.setModule("storage.components.wrappingOfflineStorage"), this.offlineStorage = t, this.queueWorker = o;
79
79
  }
@@ -103,16 +103,16 @@ let f = class {
103
103
  }
104
104
  // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.
105
105
  // eslint-disable-next-line max-statements
106
- async getPageContent(e, t, o, r) {
106
+ async getPageContent(e, t, o, g) {
107
107
  if (this.logger.debug("Trying to get data for page ", e), this.offlineStorage) {
108
108
  this.logger.debug("Asking offline storage for ", e);
109
- const g = await this.offlineStorage.getPage(
109
+ const r = await this.offlineStorage.getPage(
110
110
  this.getWikiConfig().name,
111
111
  e + "_" + t
112
112
  );
113
- return g != null && g != null ? (this.logger.debug("Loading data from local storage for page", e), (r == null || r) && this.queueWorker.addToQueue(
113
+ return r != null && r != null ? (this.logger.debug("Loading data from local storage for page", e), (g == null || g) && this.queueWorker.addToQueue(
114
114
  this.getWikiConfig().name + ":" + e + "_" + t
115
- ), g) : (this.logger.debug(
115
+ ), r) : (this.logger.debug(
116
116
  "Could not find data in local storage for page",
117
117
  e
118
118
  ), this.savePageContent(e, t));
@@ -141,15 +141,15 @@ let f = class {
141
141
  const o = await this.offlineStorage.getPage(
142
142
  this.getWikiConfig().name,
143
143
  e + "_" + t
144
- ), r = await this.storage.getPageContent(e, t);
145
- return o && r ? (r.id = e + "_" + t, this.logger.debug("Saving page to offline storage", e), this.offlineStorage.savePage(
144
+ ), g = await this.storage.getPageContent(e, t);
145
+ return o && g ? (g.id = e + "_" + t, this.logger.debug("Saving page to offline storage", e), this.offlineStorage.savePage(
146
146
  this.getWikiConfig().name,
147
147
  e + "_" + t,
148
- r
149
- ), !0) : (o == null ? void 0 : o.version) != (r == null ? void 0 : r.version) && r ? (r.id = e + "_" + t, this.logger.debug("Updating page to offline storage", e), this.offlineStorage.updatePage(
148
+ g
149
+ ), !0) : (o == null ? void 0 : o.version) != (g == null ? void 0 : g.version) && g ? (g.id = e + "_" + t, this.logger.debug("Updating page to offline storage", e), this.offlineStorage.updatePage(
150
150
  this.getWikiConfig().name,
151
151
  e + "_" + t,
152
- r
152
+ g
153
153
  ), !0) : (this.logger.debug(
154
154
  "Local storage not updated, because version are identical"
155
155
  ), !1);
@@ -160,8 +160,8 @@ let f = class {
160
160
  async getEditField(e, t) {
161
161
  return await this.storage.getEditField(e, t);
162
162
  }
163
- save(e, t, o, r) {
164
- return this.storage.save(e, t, o, r);
163
+ save(e, t, o, g) {
164
+ return this.storage.save(e, t, o, g);
165
165
  }
166
166
  async saveAttachments(e, t) {
167
167
  return this.storage.saveAttachments(e, t);
@@ -173,18 +173,18 @@ let f = class {
173
173
  return this.storage.move(e, t, o);
174
174
  }
175
175
  };
176
- f = _([
177
- c(),
176
+ c = P([
177
+ h(),
178
178
  n(0, i("Logger")),
179
179
  n(1, i("OfflineStorage")),
180
180
  n(2, i("QueueWorker"))
181
- ], f);
182
- class W {
181
+ ], c);
182
+ class w {
183
183
  constructor(t) {
184
- t.bind("WrappingStorage").to(f).inSingletonScope(), t.bind("OfflineStorage").to(l).inSingletonScope();
184
+ t.bind("WrappingStorage").to(c).inSingletonScope(), t.bind("OfflineStorage").to(l).inSingletonScope();
185
185
  }
186
186
  }
187
187
  export {
188
- W as ComponentInit
188
+ w as ComponentInit
189
189
  };
190
190
  //# sourceMappingURL=index.es.js.map
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("dexie"),require("@xwiki/cristal-api"),require("inversify")):typeof define=="function"&&define.amd?define(["exports","dexie","@xwiki/cristal-api","inversify"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a["cristal_backend-dexie"]={},a.Dexie,a.cristalApi,a.inversify))})(this,function(a,l,h,s){"use strict";class d extends l{constructor(t){super("pages_"+t),this.version(2).stores({pages:"id, name, content, document, css, js, document.name, document.headline, document.creator"})}}var p=Object.defineProperty,S=Object.getOwnPropertyDescriptor,P=(e,t,o,r)=>{for(var g=r>1?void 0:r?S(t,o):t,i=e.length-1,n;i>=0;i--)(n=e[i])&&(g=(r?n(t,o,g):n(g))||g);return r&&g&&p(t,o,g),g},m=(e,t)=>(o,r)=>t(o,r,e);let c=class{constructor(e){this.pageStorageMap=new Map,this.logger=e,this.logger.setModule("storage.components.dexieOfflineStorage")}getPageStorage(e){let t=this.pageStorageMap.get(e);return t==null&&(t=new d(e),this.pageStorageMap.set(e,t)),t}async getPage(e,t){try{this.logger.debug("Ready to load page from local storage",t);const o=this.getPageStorage(e);this.logger.debug("pageStorage is ready, asking for page");const r=await o.pages.get(t),g=new h.DefaultPageData;return g.fromObject(r),g}catch(o){this.logger.debug("Exception while trying to read from local storage",o);return}}async savePage(e,t,o){try{await this.getPageStorage(e).pages.put(o.toObject(),t)}catch(r){this.logger.debug("Exception while trying to store in local storage",e,t,o,r)}}async updatePage(e,t,o){try{const r=this.getPageStorage(e);this.logger.debug("Ready to store",o),await r.pages.update(t,o.toObject())}catch(r){this.logger.debug("Exception while trying to store in local storage",e,t,o,r)}}};c=P([s.injectable(),m(0,s.inject("Logger"))],c);var v=Object.defineProperty,b=Object.getOwnPropertyDescriptor,_=(e,t,o,r)=>{for(var g=r>1?void 0:r?b(t,o):t,i=e.length-1,n;i>=0;i--)(n=e[i])&&(g=(r?n(t,o,g):n(g))||g);return r&&g&&v(t,o,g),g},f=(e,t)=>(o,r)=>t(o,r,e);let u=class{constructor(e,t,o){this.logger=e,this.logger.setModule("storage.components.wrappingOfflineStorage"),this.offlineStorage=t,this.queueWorker=o}setStorage(e){this.storage=e}getStorage(){return this.storage}setWikiConfig(e){return this.storage.setWikiConfig(e)}getWikiConfig(){return this.storage.getWikiConfig()}async isStorageReady(){return this.storage.isStorageReady()}getPageRestURL(e,t){return this.storage.getPageRestURL(e,t)}getPageFromViewURL(e){return this.storage.getPageFromViewURL(e)}getImageURL(e,t){return this.storage.getImageURL(e,t)}async getPageContent(e,t,o,r){if(this.logger.debug("Trying to get data for page ",e),this.offlineStorage){this.logger.debug("Asking offline storage for ",e);const g=await this.offlineStorage.getPage(this.getWikiConfig().name,e+"_"+t);return g!=null&&g!=null?(this.logger.debug("Loading data from local storage for page",e),(r==null||r)&&this.queueWorker.addToQueue(this.getWikiConfig().name+":"+e+"_"+t),g):(this.logger.debug("Could not find data in local storage for page",e),this.savePageContent(e,t))}else return this.logger.debug("No offline local storage available"),this.storage.getPageContent(e,t)}getAttachments(e){return this.storage.getAttachments(e)}getAttachment(e,t){return this.storage.getAttachment(e,t)}async savePageContent(e,t){const o=await this.storage.getPageContent(e,t);if(o)return o.id=e+"_"+t,this.logger.debug("Saving page to offline storage",e),this.offlineStorage.savePage(this.getWikiConfig().name,e+"_"+t,o),o;throw new Error("Can't save missing page.")}async updatePageContent(e,t){const o=await this.offlineStorage.getPage(this.getWikiConfig().name,e+"_"+t),r=await this.storage.getPageContent(e,t);return o&&r?(r.id=e+"_"+t,this.logger.debug("Saving page to offline storage",e),this.offlineStorage.savePage(this.getWikiConfig().name,e+"_"+t,r),!0):(o==null?void 0:o.version)!=(r==null?void 0:r.version)&&r?(r.id=e+"_"+t,this.logger.debug("Updating page to offline storage",e),this.offlineStorage.updatePage(this.getWikiConfig().name,e+"_"+t,r),!0):(this.logger.debug("Local storage not updated, because version are identical"),!1)}async getPanelContent(e,t,o){return this.storage.getPanelContent(e,t,o)}async getEditField(e,t){return await this.storage.getEditField(e,t)}save(e,t,o,r){return this.storage.save(e,t,o,r)}async saveAttachments(e,t){return this.storage.saveAttachments(e,t)}async delete(e){return this.storage.delete(e)}async move(e,t,o){return this.storage.move(e,t,o)}};u=_([s.injectable(),f(0,s.inject("Logger")),f(1,s.inject("OfflineStorage")),f(2,s.inject("QueueWorker"))],u);class C{constructor(t){t.bind("WrappingStorage").to(u).inSingletonScope(),t.bind("OfflineStorage").to(c).inSingletonScope()}}a.ComponentInit=C,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("dexie"),require("@xwiki/cristal-api"),require("inversify")):typeof define=="function"&&define.amd?define(["exports","dexie","@xwiki/cristal-api","inversify"],n):(a=typeof globalThis<"u"?globalThis:a||self,n(a["cristal_backend-dexie"]={},a.Dexie,a.cristalApi,a.inversify))})(this,function(a,n,f,s){"use strict";class d extends n{constructor(t){super("pages_"+t),this.version(2).stores({pages:"id, name, content, document, css, js, document.name, document.headline, document.creator"})}}var p=Object.getOwnPropertyDescriptor,S=(e,t,o,r)=>{for(var g=r>1?void 0:r?p(t,o):t,i=e.length-1,l;i>=0;i--)(l=e[i])&&(g=l(g)||g);return g},m=(e,t)=>(o,r)=>t(o,r,e);let c=class{constructor(e){this.pageStorageMap=new Map,this.logger=e,this.logger.setModule("storage.components.dexieOfflineStorage")}getPageStorage(e){let t=this.pageStorageMap.get(e);return t==null&&(t=new d(e),this.pageStorageMap.set(e,t)),t}async getPage(e,t){try{this.logger.debug("Ready to load page from local storage",t);const o=this.getPageStorage(e);this.logger.debug("pageStorage is ready, asking for page");const r=await o.pages.get(t),g=new f.DefaultPageData;return g.fromObject(r),g}catch(o){this.logger.debug("Exception while trying to read from local storage",o);return}}async savePage(e,t,o){try{await this.getPageStorage(e).pages.put(o.toObject(),t)}catch(r){this.logger.debug("Exception while trying to store in local storage",e,t,o,r)}}async updatePage(e,t,o){try{const r=this.getPageStorage(e);this.logger.debug("Ready to store",o),await r.pages.update(t,o.toObject())}catch(r){this.logger.debug("Exception while trying to store in local storage",e,t,o,r)}}};c=S([s.injectable(),m(0,s.inject("Logger"))],c);var v=Object.getOwnPropertyDescriptor,P=(e,t,o,r)=>{for(var g=r>1?void 0:r?v(t,o):t,i=e.length-1,l;i>=0;i--)(l=e[i])&&(g=l(g)||g);return g},u=(e,t)=>(o,r)=>t(o,r,e);let h=class{constructor(e,t,o){this.logger=e,this.logger.setModule("storage.components.wrappingOfflineStorage"),this.offlineStorage=t,this.queueWorker=o}setStorage(e){this.storage=e}getStorage(){return this.storage}setWikiConfig(e){return this.storage.setWikiConfig(e)}getWikiConfig(){return this.storage.getWikiConfig()}async isStorageReady(){return this.storage.isStorageReady()}getPageRestURL(e,t){return this.storage.getPageRestURL(e,t)}getPageFromViewURL(e){return this.storage.getPageFromViewURL(e)}getImageURL(e,t){return this.storage.getImageURL(e,t)}async getPageContent(e,t,o,r){if(this.logger.debug("Trying to get data for page ",e),this.offlineStorage){this.logger.debug("Asking offline storage for ",e);const g=await this.offlineStorage.getPage(this.getWikiConfig().name,e+"_"+t);return g!=null&&g!=null?(this.logger.debug("Loading data from local storage for page",e),(r==null||r)&&this.queueWorker.addToQueue(this.getWikiConfig().name+":"+e+"_"+t),g):(this.logger.debug("Could not find data in local storage for page",e),this.savePageContent(e,t))}else return this.logger.debug("No offline local storage available"),this.storage.getPageContent(e,t)}getAttachments(e){return this.storage.getAttachments(e)}getAttachment(e,t){return this.storage.getAttachment(e,t)}async savePageContent(e,t){const o=await this.storage.getPageContent(e,t);if(o)return o.id=e+"_"+t,this.logger.debug("Saving page to offline storage",e),this.offlineStorage.savePage(this.getWikiConfig().name,e+"_"+t,o),o;throw new Error("Can't save missing page.")}async updatePageContent(e,t){const o=await this.offlineStorage.getPage(this.getWikiConfig().name,e+"_"+t),r=await this.storage.getPageContent(e,t);return o&&r?(r.id=e+"_"+t,this.logger.debug("Saving page to offline storage",e),this.offlineStorage.savePage(this.getWikiConfig().name,e+"_"+t,r),!0):(o==null?void 0:o.version)!=(r==null?void 0:r.version)&&r?(r.id=e+"_"+t,this.logger.debug("Updating page to offline storage",e),this.offlineStorage.updatePage(this.getWikiConfig().name,e+"_"+t,r),!0):(this.logger.debug("Local storage not updated, because version are identical"),!1)}async getPanelContent(e,t,o){return this.storage.getPanelContent(e,t,o)}async getEditField(e,t){return await this.storage.getEditField(e,t)}save(e,t,o,r){return this.storage.save(e,t,o,r)}async saveAttachments(e,t){return this.storage.saveAttachments(e,t)}async delete(e){return this.storage.delete(e)}async move(e,t,o){return this.storage.move(e,t,o)}};h=P([s.injectable(),u(0,s.inject("Logger")),u(1,s.inject("OfflineStorage")),u(2,s.inject("QueueWorker"))],h);class b{constructor(t){t.bind("WrappingStorage").to(h).inSingletonScope(),t.bind("OfflineStorage").to(c).inSingletonScope()}}a.ComponentInit=b,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/dexiePageStorage.ts","../src/dexieOfflineStorage.ts","../src/wrappingOfflineStorage.ts","../src/index.ts"],"sourcesContent":["/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport Dexie from \"dexie\";\nimport type { Table } from \"dexie\";\n\nexport default class DexiePageStorage extends Dexie {\n pages!: Table<object>;\n\n constructor(wikiName: string) {\n super(\"pages_\" + wikiName);\n this.version(2).stores({\n pages:\n // Primary key and indexed props\n \"id, name, content, document, css, js, document.name, document.headline, document.creator\",\n });\n }\n}\n","/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport DexiePageStorage from \"./dexiePageStorage\";\nimport { DefaultPageData, PageData } from \"@xwiki/cristal-api\";\nimport { inject, injectable } from \"inversify\";\nimport type { Logger } from \"@xwiki/cristal-api\";\nimport type { OfflineStorage } from \"@xwiki/cristal-backend-api\";\n\n@injectable()\nexport default class DexieOfflineStorage implements OfflineStorage {\n private pageStorageMap: Map<string, DexiePageStorage> = new Map<\n string,\n DexiePageStorage\n >();\n private logger: Logger;\n\n constructor(@inject(\"Logger\") logger: Logger) {\n this.logger = logger;\n this.logger.setModule(\"storage.components.dexieOfflineStorage\");\n }\n\n getPageStorage(wikiName: string): DexiePageStorage {\n let pageStorage = this.pageStorageMap.get(wikiName);\n if (pageStorage == null) {\n pageStorage = new DexiePageStorage(wikiName);\n this.pageStorageMap.set(wikiName, pageStorage);\n }\n return pageStorage;\n }\n\n async getPage(wikiName: string, id: string): Promise<PageData | undefined> {\n try {\n this.logger.debug(\"Ready to load page from local storage\", id);\n const pageStorage = this.getPageStorage(wikiName);\n this.logger.debug(\"pageStorage is ready, asking for page\");\n const pageObject = await pageStorage.pages.get(id);\n const pageData = new DefaultPageData();\n pageData.fromObject(pageObject);\n return pageData;\n } catch (e) {\n this.logger.debug(\"Exception while trying to read from local storage\", e);\n return undefined;\n }\n }\n\n async savePage(wikiName: string, id: string, page: PageData): Promise<void> {\n try {\n const pageStorage = this.getPageStorage(wikiName);\n // Put must be used instead of get since the later does not allow for\n // content update.\n await pageStorage.pages.put(page.toObject(), id);\n } catch (e) {\n this.logger.debug(\n \"Exception while trying to store in local storage\",\n wikiName,\n id,\n page,\n e,\n );\n }\n }\n\n async updatePage(\n wikiName: string,\n id: string,\n page: PageData,\n ): Promise<void> {\n try {\n const pageStorage = this.getPageStorage(wikiName);\n this.logger.debug(\"Ready to store\", page);\n await pageStorage.pages.update(id, page.toObject());\n } catch (e) {\n this.logger.debug(\n \"Exception while trying to store in local storage\",\n wikiName,\n id,\n page,\n e,\n );\n }\n }\n}\n","/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { inject, injectable } from \"inversify\";\nimport type {\n AttachmentsData,\n Document,\n Logger,\n PageAttachment,\n PageData,\n Storage,\n WikiConfig,\n WrappingStorage,\n} from \"@xwiki/cristal-api\";\nimport type { OfflineStorage } from \"@xwiki/cristal-backend-api\";\nimport type { QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\n\n@injectable()\nexport class WrappingOfflineStorage implements WrappingStorage {\n public logger: Logger;\n // @ts-expect-error storage can be temporarily undefined during class\n // initialization\n public storage: Storage;\n public offlineStorage: OfflineStorage;\n public queueWorker: QueueWorker;\n\n constructor(\n @inject(\"Logger\") logger: Logger,\n @inject(\"OfflineStorage\") offlineStorage: OfflineStorage,\n @inject(\"QueueWorker\") queueWorker: QueueWorker,\n ) {\n this.logger = logger;\n this.logger.setModule(\"storage.components.wrappingOfflineStorage\");\n this.offlineStorage = offlineStorage;\n this.queueWorker = queueWorker;\n }\n\n public setStorage(storage: Storage): void {\n this.storage = storage;\n }\n\n public getStorage(): Storage {\n return this.storage;\n }\n\n public setWikiConfig(config: WikiConfig): void {\n return this.storage.setWikiConfig(config);\n }\n\n public getWikiConfig(): WikiConfig {\n return this.storage.getWikiConfig();\n }\n\n public async isStorageReady(): Promise<boolean> {\n return this.storage.isStorageReady();\n }\n\n public getPageRestURL(page: string, syntax: string): string {\n return this.storage.getPageRestURL(page, syntax);\n }\n\n public getPageFromViewURL(url: string): string | null {\n return this.storage.getPageFromViewURL(url);\n }\n\n public getImageURL(page: string, image: string): string {\n return this.storage.getImageURL(page, image);\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n public async getPageContent(\n page: string,\n syntax: string,\n _revision?: string,\n requeue?: boolean,\n ): Promise<PageData | undefined> {\n this.logger.debug(\"Trying to get data for page \", page);\n if (this.offlineStorage) {\n this.logger.debug(\"Asking offline storage for \", page);\n const pageData = await this.offlineStorage.getPage(\n this.getWikiConfig().name,\n page + \"_\" + syntax,\n );\n if (pageData != null && pageData != undefined) {\n this.logger.debug(\"Loading data from local storage for page\", page);\n // Adding page to refresh queue in shared worker\n if (requeue == undefined || requeue) {\n this.queueWorker.addToQueue(\n this.getWikiConfig().name + \":\" + page + \"_\" + syntax,\n );\n }\n return pageData;\n } else {\n this.logger.debug(\n \"Could not find data in local storage for page\",\n page,\n );\n return this.savePageContent(page, syntax);\n }\n } else {\n this.logger.debug(\"No offline local storage available\");\n return this.storage.getPageContent(page, syntax);\n }\n }\n\n public getAttachments(page: string): Promise<AttachmentsData | undefined> {\n // TODO: add support for offline storage of attachments.\n return this.storage.getAttachments(page);\n }\n\n getAttachment(\n page: string,\n name: string,\n ): Promise<PageAttachment | undefined> {\n return this.storage.getAttachment(page, name);\n }\n\n private async savePageContent(\n page: string,\n syntax: string,\n ): Promise<PageData> {\n const pageData = await this.storage.getPageContent(page, syntax);\n if (pageData) {\n pageData.id = page + \"_\" + syntax;\n this.logger.debug(\"Saving page to offline storage\", page);\n this.offlineStorage.savePage(\n this.getWikiConfig().name,\n page + \"_\" + syntax,\n pageData,\n );\n\n return pageData;\n } else {\n throw new Error(\"Can't save missing page.\");\n }\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n public async updatePageContent(\n page: string,\n syntax: string,\n ): Promise<boolean> {\n const currentPageData = await this.offlineStorage.getPage(\n this.getWikiConfig().name,\n page + \"_\" + syntax,\n );\n const pageData = await this.storage.getPageContent(page, syntax);\n if (currentPageData && pageData) {\n pageData.id = page + \"_\" + syntax;\n this.logger.debug(\"Saving page to offline storage\", page);\n this.offlineStorage.savePage(\n this.getWikiConfig().name,\n page + \"_\" + syntax,\n pageData,\n );\n return true;\n } else if (currentPageData?.version != pageData?.version && pageData) {\n pageData.id = page + \"_\" + syntax;\n this.logger.debug(\"Updating page to offline storage\", page);\n this.offlineStorage.updatePage(\n this.getWikiConfig().name,\n page + \"_\" + syntax,\n pageData,\n );\n return true;\n } else {\n this.logger.debug(\n \"Local storage not updated, because version are identical\",\n );\n return false;\n }\n }\n\n public async getPanelContent(\n panel: string,\n contextPage: string,\n syntax: string,\n ): Promise<PageData> {\n return this.storage.getPanelContent(panel, contextPage, syntax);\n }\n\n public async getEditField(\n document: Document,\n fieldName: string,\n ): Promise<string> {\n return await this.storage.getEditField(document, fieldName);\n }\n\n save(\n page: string,\n title: string,\n content: string,\n syntax: string,\n ): Promise<unknown> {\n return this.storage.save(page, title, content, syntax);\n }\n\n async saveAttachments(page: string, files: File[]): Promise<unknown> {\n return this.storage.saveAttachments(page, files);\n }\n\n async delete(page: string): Promise<{ success: boolean; error?: string }> {\n return this.storage.delete(page);\n }\n\n async move(\n page: string,\n newPage: string,\n preserveChildren: boolean,\n ): Promise<{ success: boolean; error?: string }> {\n return this.storage.move(page, newPage, preserveChildren);\n }\n}\n","/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport DexieOfflineStorage from \"./dexieOfflineStorage\";\nimport { WrappingOfflineStorage } from \"./wrappingOfflineStorage\";\nimport { WrappingStorage } from \"@xwiki/cristal-api\";\nimport { OfflineStorage } from \"@xwiki/cristal-backend-api\";\nimport { Container } from \"inversify\";\n\nexport class ComponentInit {\n constructor(container: Container) {\n container\n .bind<WrappingStorage>(\"WrappingStorage\")\n .to(WrappingOfflineStorage)\n .inSingletonScope();\n container\n .bind<OfflineStorage>(\"OfflineStorage\")\n .to(DexieOfflineStorage)\n .inSingletonScope();\n }\n}\n"],"names":["DexiePageStorage","Dexie","wikiName","DexieOfflineStorage","logger","pageStorage","id","pageObject","pageData","DefaultPageData","e","page","__decorateClass","injectable","__decorateParam","WrappingOfflineStorage","offlineStorage","queueWorker","storage","config","syntax","url","image","_revision","requeue","name","currentPageData","panel","contextPage","document","fieldName","title","content","files","newPage","preserveChildren","ComponentInit","container"],"mappings":"oYAuBA,MAAqBA,UAAyBC,CAAM,CAGlD,YAAYC,EAAkB,CAC5B,MAAM,SAAWA,CAAQ,EACpB,KAAA,QAAQ,CAAC,EAAE,OAAO,CACrB,MAEE,0FAAA,CACH,CAAA,CAEL,0NCPA,IAAqBC,EAArB,KAAmE,CAOjE,YAA8BC,EAAgB,CANtC,KAAA,mBAAoD,IAO1D,KAAK,OAASA,EACT,KAAA,OAAO,UAAU,wCAAwC,CAAA,CAGhE,eAAeF,E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,MAAM,OAAOtB,EAA6D,CACjE,OAAA,KAAK,QAAQ,OAAOA,CAAI,CAAA,CAGjC,MAAM,KACJA,EACAuB,EACAC,EAC+C,CAC/C,OAAO,KAAK,QAAQ,KAAKxB,EAAMuB,EAASC,CAAgB,CAAA,CAE5D,EApMapB,EAANH,EAAA,CADNC,aAAW,EAUPC,aAAO,QAAQ,CAAA,EACfA,aAAO,gBAAgB,CAAA,EACvBA,aAAO,aAAa,CAAA,CAAA,EAXZC,CAAA,ECTN,MAAMqB,CAAc,CACzB,YAAYC,EAAsB,CAChCA,EACG,KAAsB,iBAAiB,EACvC,GAAGtB,CAAsB,EACzB,iBAAiB,EACpBsB,EACG,KAAqB,gBAAgB,EACrC,GAAGlC,CAAmB,EACtB,iBAAiB,CAAA,CAExB"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/dexiePageStorage.ts","../src/dexieOfflineStorage.ts","../src/wrappingOfflineStorage.ts","../src/index.ts"],"sourcesContent":["/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport Dexie from \"dexie\";\nimport type { Table } from \"dexie\";\n\nexport default class DexiePageStorage extends Dexie {\n pages!: Table<object>;\n\n constructor(wikiName: string) {\n super(\"pages_\" + wikiName);\n this.version(2).stores({\n pages:\n // Primary key and indexed props\n \"id, name, content, document, css, js, document.name, document.headline, document.creator\",\n });\n }\n}\n","/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport DexiePageStorage from \"./dexiePageStorage\";\nimport { DefaultPageData, PageData } from \"@xwiki/cristal-api\";\nimport { inject, injectable } from \"inversify\";\nimport type { Logger } from \"@xwiki/cristal-api\";\nimport type { OfflineStorage } from \"@xwiki/cristal-backend-api\";\n\n@injectable()\nexport default class DexieOfflineStorage implements OfflineStorage {\n private pageStorageMap: Map<string, DexiePageStorage> = new Map<\n string,\n DexiePageStorage\n >();\n private logger: Logger;\n\n constructor(@inject(\"Logger\") logger: Logger) {\n this.logger = logger;\n this.logger.setModule(\"storage.components.dexieOfflineStorage\");\n }\n\n getPageStorage(wikiName: string): DexiePageStorage {\n let pageStorage = this.pageStorageMap.get(wikiName);\n if (pageStorage == null) {\n pageStorage = new DexiePageStorage(wikiName);\n this.pageStorageMap.set(wikiName, pageStorage);\n }\n return pageStorage;\n }\n\n async getPage(wikiName: string, id: string): Promise<PageData | undefined> {\n try {\n this.logger.debug(\"Ready to load page from local storage\", id);\n const pageStorage = this.getPageStorage(wikiName);\n this.logger.debug(\"pageStorage is ready, asking for page\");\n const pageObject = await pageStorage.pages.get(id);\n const pageData = new DefaultPageData();\n pageData.fromObject(pageObject);\n return pageData;\n } catch (e) {\n this.logger.debug(\"Exception while trying to read from local storage\", e);\n return undefined;\n }\n }\n\n async savePage(wikiName: string, id: string, page: PageData): Promise<void> {\n try {\n const pageStorage = this.getPageStorage(wikiName);\n // Put must be used instead of get since the later does not allow for\n // content update.\n await pageStorage.pages.put(page.toObject(), id);\n } catch (e) {\n this.logger.debug(\n \"Exception while trying to store in local storage\",\n wikiName,\n id,\n page,\n e,\n );\n }\n }\n\n async updatePage(\n wikiName: string,\n id: string,\n page: PageData,\n ): Promise<void> {\n try {\n const pageStorage = this.getPageStorage(wikiName);\n this.logger.debug(\"Ready to store\", page);\n await pageStorage.pages.update(id, page.toObject());\n } catch (e) {\n this.logger.debug(\n \"Exception while trying to store in local storage\",\n wikiName,\n id,\n page,\n e,\n );\n }\n }\n}\n","/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { inject, injectable } from \"inversify\";\nimport type {\n AttachmentsData,\n Document,\n Logger,\n PageAttachment,\n PageData,\n Storage,\n WikiConfig,\n WrappingStorage,\n} from \"@xwiki/cristal-api\";\nimport type { OfflineStorage } from \"@xwiki/cristal-backend-api\";\nimport type { QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\n\n@injectable()\nexport class WrappingOfflineStorage implements WrappingStorage {\n public logger: Logger;\n // @ts-expect-error storage can be temporarily undefined during class\n // initialization\n public storage: Storage;\n public offlineStorage: OfflineStorage;\n public queueWorker: QueueWorker;\n\n constructor(\n @inject(\"Logger\") logger: Logger,\n @inject(\"OfflineStorage\") offlineStorage: OfflineStorage,\n @inject(\"QueueWorker\") queueWorker: QueueWorker,\n ) {\n this.logger = logger;\n this.logger.setModule(\"storage.components.wrappingOfflineStorage\");\n this.offlineStorage = offlineStorage;\n this.queueWorker = queueWorker;\n }\n\n public setStorage(storage: Storage): void {\n this.storage = storage;\n }\n\n public getStorage(): Storage {\n return this.storage;\n }\n\n public setWikiConfig(config: WikiConfig): void {\n return this.storage.setWikiConfig(config);\n }\n\n public getWikiConfig(): WikiConfig {\n return this.storage.getWikiConfig();\n }\n\n public async isStorageReady(): Promise<boolean> {\n return this.storage.isStorageReady();\n }\n\n public getPageRestURL(page: string, syntax: string): string {\n return this.storage.getPageRestURL(page, syntax);\n }\n\n public getPageFromViewURL(url: string): string | null {\n return this.storage.getPageFromViewURL(url);\n }\n\n public getImageURL(page: string, image: string): string {\n return this.storage.getImageURL(page, image);\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n public async getPageContent(\n page: string,\n syntax: string,\n _revision?: string,\n requeue?: boolean,\n ): Promise<PageData | undefined> {\n this.logger.debug(\"Trying to get data for page \", page);\n if (this.offlineStorage) {\n this.logger.debug(\"Asking offline storage for \", page);\n const pageData = await this.offlineStorage.getPage(\n this.getWikiConfig().name,\n page + \"_\" + syntax,\n );\n if (pageData != null && pageData != undefined) {\n this.logger.debug(\"Loading data from local storage for page\", page);\n // Adding page to refresh queue in shared worker\n if (requeue == undefined || requeue) {\n this.queueWorker.addToQueue(\n this.getWikiConfig().name + \":\" + page + \"_\" + syntax,\n );\n }\n return pageData;\n } else {\n this.logger.debug(\n \"Could not find data in local storage for page\",\n page,\n );\n return this.savePageContent(page, syntax);\n }\n } else {\n this.logger.debug(\"No offline local storage available\");\n return this.storage.getPageContent(page, syntax);\n }\n }\n\n public getAttachments(page: string): Promise<AttachmentsData | undefined> {\n // TODO: add support for offline storage of attachments.\n return this.storage.getAttachments(page);\n }\n\n getAttachment(\n page: string,\n name: string,\n ): Promise<PageAttachment | undefined> {\n return this.storage.getAttachment(page, name);\n }\n\n private async savePageContent(\n page: string,\n syntax: string,\n ): Promise<PageData> {\n const pageData = await this.storage.getPageContent(page, syntax);\n if (pageData) {\n pageData.id = page + \"_\" + syntax;\n this.logger.debug(\"Saving page to offline storage\", page);\n this.offlineStorage.savePage(\n this.getWikiConfig().name,\n page + \"_\" + syntax,\n pageData,\n );\n\n return pageData;\n } else {\n throw new Error(\"Can't save missing page.\");\n }\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n public async updatePageContent(\n page: string,\n syntax: string,\n ): Promise<boolean> {\n const currentPageData = await this.offlineStorage.getPage(\n this.getWikiConfig().name,\n page + \"_\" + syntax,\n );\n const pageData = await this.storage.getPageContent(page, syntax);\n if (currentPageData && pageData) {\n pageData.id = page + \"_\" + syntax;\n this.logger.debug(\"Saving page to offline storage\", page);\n this.offlineStorage.savePage(\n this.getWikiConfig().name,\n page + \"_\" + syntax,\n pageData,\n );\n return true;\n } else if (currentPageData?.version != pageData?.version && pageData) {\n pageData.id = page + \"_\" + syntax;\n this.logger.debug(\"Updating page to offline storage\", page);\n this.offlineStorage.updatePage(\n this.getWikiConfig().name,\n page + \"_\" + syntax,\n pageData,\n );\n return true;\n } else {\n this.logger.debug(\n \"Local storage not updated, because version are identical\",\n );\n return false;\n }\n }\n\n public async getPanelContent(\n panel: string,\n contextPage: string,\n syntax: string,\n ): Promise<PageData> {\n return this.storage.getPanelContent(panel, contextPage, syntax);\n }\n\n public async getEditField(\n document: Document,\n fieldName: string,\n ): Promise<string> {\n return await this.storage.getEditField(document, fieldName);\n }\n\n save(\n page: string,\n title: string,\n content: string,\n syntax: string,\n ): Promise<unknown> {\n return this.storage.save(page, title, content, syntax);\n }\n\n async saveAttachments(page: string, files: File[]): Promise<unknown> {\n return this.storage.saveAttachments(page, files);\n }\n\n async delete(page: string): Promise<{ success: boolean; error?: string }> {\n return this.storage.delete(page);\n }\n\n async move(\n page: string,\n newPage: string,\n preserveChildren: boolean,\n ): Promise<{ success: boolean; error?: string }> {\n return this.storage.move(page, newPage, preserveChildren);\n }\n}\n","/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport DexieOfflineStorage from \"./dexieOfflineStorage\";\nimport { WrappingOfflineStorage } from \"./wrappingOfflineStorage\";\nimport { WrappingStorage } from \"@xwiki/cristal-api\";\nimport { OfflineStorage } from \"@xwiki/cristal-backend-api\";\nimport { Container } from \"inversify\";\n\nexport class ComponentInit {\n constructor(container: Container) {\n container\n .bind<WrappingStorage>(\"WrappingStorage\")\n .to(WrappingOfflineStorage)\n .inSingletonScope();\n container\n .bind<OfflineStorage>(\"OfflineStorage\")\n .to(DexieOfflineStorage)\n .inSingletonScope();\n }\n}\n"],"names":["DexiePageStorage","Dexie","wikiName","DexieOfflineStorage","logger","pageStorage","id","pageObject","pageData","DefaultPageData","e","page","__decorateClass","injectable","__decorateParam","WrappingOfflineStorage","offlineStorage","queueWorker","storage","config","syntax","url","image","_revision","requeue","name","currentPageData","panel","contextPage","document","fieldName","title","content","files","newPage","preserveChildren","ComponentInit","container"],"mappings":"oYAuBA,MAAqBA,UAAyBC,CAAM,CAGlD,YAAYC,EAAkB,CAC5B,MAAM,SAAWA,CAAQ,EACpB,KAAA,QAAQ,CAAC,EAAE,OAAO,CACrB,MAEE,0FAAA,CACH,CAAA,CAEL,sKCPA,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,EAAMoB,EAAOC,EAASZ,CAAM,CAAA,CAGvD,MAAM,gBAAgBT,EAAcsB,EAAiC,CACnE,OAAO,KAAK,QAAQ,gBAAgBtB,EAAMsB,CAAK,CAAA,CAGjD,MAAM,OAAOtB,EAA6D,CACjE,OAAA,KAAK,QAAQ,OAAOA,CAAI,CAAA,CAGjC,MAAM,KACJA,EACAuB,EACAC,EAC+C,CAC/C,OAAO,KAAK,QAAQ,KAAKxB,EAAMuB,EAASC,CAAgB,CAAA,CAE5D,EApMapB,EAANH,EAAA,CADNC,aAAW,EAUPC,aAAO,QAAQ,CAAA,EACfA,aAAO,gBAAgB,CAAA,EACvBA,aAAO,aAAa,CAAA,CAAA,EAXZC,CAAA,ECTN,MAAMqB,CAAc,CACzB,YAAYC,EAAsB,CAChCA,EACG,KAAsB,iBAAiB,EACvC,GAAGtB,CAAsB,EACzB,iBAAiB,EACpBsB,EACG,KAAqB,gBAAgB,EACrC,GAAGlC,CAAmB,EACtB,iBAAiB,CAAA,CAExB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwiki/cristal-backend-dexie",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "license": "LGPL 2.1",
5
5
  "author": "XWiki Org Community <contact@xwiki.org>",
6
6
  "homepage": "https://cristal.xwiki.org/",
@@ -23,19 +23,19 @@
23
23
  "main": "./dist/index.es.js",
24
24
  "dependencies": {
25
25
  "dexie": "4.0.11",
26
- "inversify": "7.5.0",
27
- "@xwiki/cristal-api": "0.17.0",
28
- "@xwiki/cristal-backend-api": "0.17.0",
29
- "@xwiki/cristal-sharedworker-api": "0.17.0"
26
+ "inversify": "7.5.1",
27
+ "@xwiki/cristal-api": "0.18.0",
28
+ "@xwiki/cristal-backend-api": "0.18.0",
29
+ "@xwiki/cristal-sharedworker-api": "0.18.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "reflect-metadata": "0.2.2"
33
33
  },
34
34
  "devDependencies": {
35
35
  "reflect-metadata": "0.2.2",
36
- "typescript": "5.8.2",
37
- "vite": "6.2.6",
38
- "@xwiki/cristal-dev-config": "0.17.0"
36
+ "typescript": "5.8.3",
37
+ "vite": "6.3.5",
38
+ "@xwiki/cristal-dev-config": "0.18.0"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsc --project tsconfig.json && vite build",