@xwiki/cristal-backend-dexie 0.11.0 → 0.12.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 +13 -0
- package/dist/dexieOfflineStorage.d.ts +1 -1
- package/dist/dexiePageStorage.d.ts +1 -1
- package/dist/index.es.js +18 -15
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/wrappingOfflineStorage.d.ts +4 -3
- package/package.json +5 -5
- package/src/dexieOfflineStorage.ts +3 -3
- package/src/dexiePageStorage.ts +2 -1
- package/src/index.ts +3 -3
- package/src/wrappingOfflineStorage.ts +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @xwiki/cristal-backend-dexie
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 681a9b7: Cristal 0.12 Release
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [681a9b7]
|
|
12
|
+
- @xwiki/cristal-api@0.12.0
|
|
13
|
+
- @xwiki/cristal-backend-api@0.12.0
|
|
14
|
+
- @xwiki/cristal-sharedworker-api@0.12.0
|
|
15
|
+
|
|
3
16
|
## 0.11.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { default as DexiePageStorage } from './dexiePageStorage';
|
|
1
2
|
import { PageData, Logger } from '@xwiki/cristal-api';
|
|
2
3
|
import { OfflineStorage } from '@xwiki/cristal-backend-api';
|
|
3
|
-
import { default as DexiePageStorage } from './dexiePageStorage';
|
|
4
4
|
export default class DexieOfflineStorage implements OfflineStorage {
|
|
5
5
|
private pageStorageMap;
|
|
6
6
|
private logger;
|
package/dist/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import u from "
|
|
3
|
-
import { injectable as
|
|
4
|
-
class d extends
|
|
1
|
+
import h from "dexie";
|
|
2
|
+
import { DefaultPageData as u } from "@xwiki/cristal-api";
|
|
3
|
+
import { injectable as f, inject as i } from "inversify";
|
|
4
|
+
class d extends h {
|
|
5
5
|
constructor(t) {
|
|
6
6
|
super("pages_" + t), this.version(2).stores({
|
|
7
7
|
pages: (
|
|
@@ -29,7 +29,7 @@ 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 g = await o.pages.get(t), r = new
|
|
32
|
+
const g = await o.pages.get(t), r = new u();
|
|
33
33
|
return r.fromObject(g), r;
|
|
34
34
|
} catch (o) {
|
|
35
35
|
this.logger.debug("Exception while trying to read from local storage", o);
|
|
@@ -65,7 +65,7 @@ let l = class {
|
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
l = P([
|
|
68
|
-
|
|
68
|
+
f(),
|
|
69
69
|
v(0, i("Logger"))
|
|
70
70
|
], l);
|
|
71
71
|
var m = Object.defineProperty, b = Object.getOwnPropertyDescriptor, _ = (e, t, o, g) => {
|
|
@@ -73,7 +73,7 @@ var m = Object.defineProperty, b = Object.getOwnPropertyDescriptor, _ = (e, t, o
|
|
|
73
73
|
(s = e[a]) && (r = (g ? s(t, o, r) : s(r)) || r);
|
|
74
74
|
return g && r && m(t, o, r), r;
|
|
75
75
|
}, n = (e, t) => (o, g) => t(o, g, e);
|
|
76
|
-
let
|
|
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
|
}
|
|
@@ -101,16 +101,16 @@ let f = class {
|
|
|
101
101
|
getImageURL(e, t) {
|
|
102
102
|
return this.storage.getImageURL(e, t);
|
|
103
103
|
}
|
|
104
|
-
async getPageContent(e, t, o) {
|
|
104
|
+
async getPageContent(e, t, o, g) {
|
|
105
105
|
if (this.logger.debug("Trying to get data for page ", e), this.offlineStorage) {
|
|
106
106
|
this.logger.debug("Asking offline storage for ", e);
|
|
107
|
-
const
|
|
107
|
+
const r = await this.offlineStorage.getPage(
|
|
108
108
|
this.getWikiConfig().name,
|
|
109
109
|
e + "_" + t
|
|
110
110
|
);
|
|
111
|
-
return
|
|
111
|
+
return r != null && r != null ? (this.logger.debug("Loading data from local storage for page", e), (g == null || g) && this.queueWorker.addToQueue(
|
|
112
112
|
this.getWikiConfig().name + ":" + e + "_" + t
|
|
113
|
-
),
|
|
113
|
+
), r) : (this.logger.debug(
|
|
114
114
|
"Could not find data in local storage for page",
|
|
115
115
|
e
|
|
116
116
|
), this.savePageContent(e, t));
|
|
@@ -120,6 +120,9 @@ let f = class {
|
|
|
120
120
|
getAttachments(e) {
|
|
121
121
|
return this.storage.getAttachments(e);
|
|
122
122
|
}
|
|
123
|
+
getAttachment(e, t) {
|
|
124
|
+
return this.storage.getAttachment(e, t);
|
|
125
|
+
}
|
|
123
126
|
async savePageContent(e, t) {
|
|
124
127
|
const o = await this.storage.getPageContent(e, t);
|
|
125
128
|
if (o)
|
|
@@ -163,15 +166,15 @@ let f = class {
|
|
|
163
166
|
return this.storage.delete(e);
|
|
164
167
|
}
|
|
165
168
|
};
|
|
166
|
-
|
|
167
|
-
|
|
169
|
+
c = _([
|
|
170
|
+
f(),
|
|
168
171
|
n(0, i("Logger")),
|
|
169
172
|
n(1, i("OfflineStorage")),
|
|
170
173
|
n(2, i("QueueWorker"))
|
|
171
|
-
],
|
|
174
|
+
], c);
|
|
172
175
|
class W {
|
|
173
176
|
constructor(t) {
|
|
174
|
-
t.bind("WrappingStorage").to(
|
|
177
|
+
t.bind("WrappingStorage").to(c).inSingletonScope(), t.bind("OfflineStorage").to(l).inSingletonScope();
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
export {
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.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 type { Table } from \"dexie\";\nimport Dexie 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 type { PageData } from \"@xwiki/cristal-api\";\nimport { DefaultPageData, type Logger } from \"@xwiki/cristal-api\";\nimport type { OfflineStorage } from \"@xwiki/cristal-backend-api\";\nimport DexiePageStorage from \"./dexiePageStorage\";\nimport { inject, injectable } from \"inversify\";\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: 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 PageData,\n Storage,\n WikiConfig,\n WrappingStorage,\n} from \"@xwiki/cristal-api\";\nimport type { QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport { type OfflineStorage } from \"@xwiki/cristal-backend-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: Logger,\n @inject<OfflineStorage>(\"OfflineStorage\") offlineStorage: OfflineStorage,\n @inject<QueueWorker>(\"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 public async getPageContent(\n page: string,\n syntax: 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 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 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","/*\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 { Container } from \"inversify\";\nimport { OfflineStorage } from \"@xwiki/cristal-backend-api\";\nimport { WrappingStorage } from \"@xwiki/cristal-api\";\nimport { WrappingOfflineStorage } from \"./wrappingOfflineStorage\";\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","requeue","currentPageData","panel","contextPage","document","fieldName","title","content","files","ComponentInit","container"],"mappings":";;;AAuBA,MAAqBA,UAAyBC,EAAM;AAAA,EAGlD,YAAYC,GAAkB;AAC5B,UAAM,WAAWA,CAAQ,GACpB,KAAA,QAAQ,CAAC,EAAE,OAAO;AAAA,MACrB;AAAA;AAAA,QAEE;AAAA;AAAA,IAAA,CACH;AAAA,EACH;AACF;;;;;;ACPA,IAAqBC,IAArB,MAAmE;AAAA,EAOjE,YAAsCC,GAAgB;AAN9C,SAAA,qCAAoD,OAO1D,KAAK,SAASA,GACT,KAAA,OAAO,UAAU,wCAAwC;AAAA,EAChE;AAAA,EAEA,eAAeF,GAAoC;AACjD,QAAIG,IAAc,KAAK,eAAe,IAAIH,CAAQ;AAClD,WAAIG,KAAe,SACHA,IAAA,IAAIL,EAAiBE,CAAQ,GACtC,KAAA,eAAe,IAAIA,GAAUG,CAAW,IAExCA;AAAA,EACT;AAAA,EAEA,MAAM,QAAQH,GAAkBI,GAA2C;AACrE,QAAA;AACG,WAAA,OAAO,MAAM,yCAAyCA,CAAE;AACvD,YAAAD,IAAc,KAAK,eAAeH,CAAQ;AAC3C,WAAA,OAAO,MAAM,uCAAuC;AACzD,YAAMK,IAAa,MAAMF,EAAY,MAAM,IAAIC,CAAE,GAC3CE,IAAW,IAAIC;AACrB,aAAAD,EAAS,WAAWD,CAAU,GACvBC;AAAA,aACAE,GAAG;AACL,WAAA,OAAO,MAAM,qDAAqDA,CAAC;AACjE;AAAA,IACT;AAAA,EACF;AAAA,EAEA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H,EAAA;AAAA,EADNC,EAAW;AAAA,EAUPC,OAAe,QAAQ,CAAA;AAAA,EACvBA,OAAuB,gBAAgB,CAAA;AAAA,EACvCA,OAAoB,aAAa,CAAA;AAAA,GAXzBC,CAAA;ACRN,MAAMiB,EAAc;AAAA,EACzB,YAAYC,GAAsB;AAChC,IAAAA,EACG,KAAsB,iBAAiB,EACvC,GAAGlB,CAAsB,EACzB,oBACHkB,EACG,KAAqB,gBAAgB,EACrC,GAAG9B,CAAmB,EACtB;EACL;AACF;"}
|
|
1
|
+
{"version":3,"file":"index.es.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\n// eslint-disable-next-line import/no-named-as-default\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: 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: Logger,\n @inject<OfflineStorage>(\"OfflineStorage\") offlineStorage: OfflineStorage,\n @inject<QueueWorker>(\"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 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 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","/*\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","ComponentInit","container"],"mappings":";;;AAwBA,MAAqBA,UAAyBC,EAAM;AAAA,EAGlD,YAAYC,GAAkB;AAC5B,UAAM,WAAWA,CAAQ,GACpB,KAAA,QAAQ,CAAC,EAAE,OAAO;AAAA,MACrB;AAAA;AAAA,QAEE;AAAA;AAAA,IAAA,CACH;AAAA,EACH;AACF;;;;;;ACRA,IAAqBC,IAArB,MAAmE;AAAA,EAOjE,YAAsCC,GAAgB;AAN9C,SAAA,qCAAoD,OAO1D,KAAK,SAASA,GACT,KAAA,OAAO,UAAU,wCAAwC;AAAA,EAChE;AAAA,EAEA,eAAeF,GAAoC;AACjD,QAAIG,IAAc,KAAK,eAAe,IAAIH,CAAQ;AAClD,WAAIG,KAAe,SACHA,IAAA,IAAIL,EAAiBE,CAAQ,GACtC,KAAA,eAAe,IAAIA,GAAU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;AACnB,WAAO,KAAK,QAAQ,gBAAgBO,GAAOC,GAAaR,CAAM;AAAA,EAChE;AAAA,EAEA,MAAa,aACXS,GACAC,GACiB;AACjB,WAAO,MAAM,KAAK,QAAQ,aAAaD,GAAUC,CAAS;AAAA,EAC5D;AAAA,EAEA,KACEnB,GACAoB,GACAC,GACAZ,GACkB;AAClB,WAAO,KAAK,QAAQ,KAAKT,GAAMoB,GAAOC,GAASZ,CAAM;AAAA,EACvD;AAAA,EAEA,MAAM,gBAAgBT,GAAcsB,GAAiC;AACnE,WAAO,KAAK,QAAQ,gBAAgBtB,GAAMsB,CAAK;AAAA,EACjD;AAAA,EAEA,MAAM,OAAOtB,GAA6D;AACjE,WAAA,KAAK,QAAQ,OAAOA,CAAI;AAAA,EACjC;AACF;AAxLaI,IAANH,EAAA;AAAA,EADNC,EAAW;AAAA,EAUPC,OAAe,QAAQ,CAAA;AAAA,EACvBA,OAAuB,gBAAgB,CAAA;AAAA,EACvCA,OAAoB,aAAa,CAAA;AAAA,GAXzBC,CAAA;ACTN,MAAMmB,EAAc;AAAA,EACzB,YAAYC,GAAsB;AAChC,IAAAA,EACG,KAAsB,iBAAiB,EACvC,GAAGpB,CAAsB,EACzB,oBACHoB,EACG,KAAqB,gBAAgB,EACrC,GAAGhC,CAAmB,EACtB;EACL;AACF;"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@xwiki/cristal-api"),require("
|
|
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,n){"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,s;i>=0;i--)(s=e[i])&&(g=(r?s(t,o,g):s(g))||g);return r&&g&&p(t,o,g),g},v=(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([n.injectable(),v(0,n.inject("Logger"))],c);var m=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,s;i>=0;i--)(s=e[i])&&(g=(r?s(t,o,g):s(g))||g);return r&&g&&m(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)}};u=_([n.injectable(),f(0,n.inject("Logger")),f(1,n.inject("OfflineStorage")),f(2,n.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"})});
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -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 type { Table } from \"dexie\";\nimport Dexie 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 type { PageData } from \"@xwiki/cristal-api\";\nimport { DefaultPageData, type Logger } from \"@xwiki/cristal-api\";\nimport type { OfflineStorage } from \"@xwiki/cristal-backend-api\";\nimport DexiePageStorage from \"./dexiePageStorage\";\nimport { inject, injectable } from \"inversify\";\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: 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 PageData,\n Storage,\n WikiConfig,\n WrappingStorage,\n} from \"@xwiki/cristal-api\";\nimport type { QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport { type OfflineStorage } from \"@xwiki/cristal-backend-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: Logger,\n @inject<OfflineStorage>(\"OfflineStorage\") offlineStorage: OfflineStorage,\n @inject<QueueWorker>(\"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 public async getPageContent(\n page: string,\n syntax: 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 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 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","/*\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 { Container } from \"inversify\";\nimport { OfflineStorage } from \"@xwiki/cristal-backend-api\";\nimport { WrappingStorage } from \"@xwiki/cristal-api\";\nimport { WrappingOfflineStorage } from \"./wrappingOfflineStorage\";\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","requeue","currentPageData","panel","contextPage","document","fieldName","title","content","files","ComponentInit","container"],"mappings":"oYAuBA,MAAqBA,UAAyBC,CAAM,CAGlD,YAAYC,EAAkB,CAC5B,MAAM,SAAWA,CAAQ,EACpB,KAAA,QAAQ,CAAC,EAAE,OAAO,CACrB,MAEE,0FAAA,CACH,CACH,CACF,0NCPA,IAAqBC,EAArB,KAAmE,CAOjE,YAAsCC,EAAgB,CAN9C,KAAA,mBAAoD,IAO1D,KAAK,OAASA,EACT,KAAA,OAAO,UAAU,wCAAwC,CAChE,CAEA,eAAeF,EAAoC,CACjD,IAAIG,EAAc,KAAK,eAAe,IAAIH,CAAQ,EAClD,OAAIG,GAAe,OACHA,EAAA,IAAIL,EAAiBE,CAAQ,EACtC,KAAA,eAAe,IAAIA,EAAUG,CAAW,GAExCA,CACT,CAEA,MAAM,QAAQH,EAAkBI,EAA2C,CACrE,GAAA,CACG,KAAA,OAAO,MAAM,wCAAyCA,CAAE,EACvD,MAAAD,EAAc,KAAK,eAAeH,CAAQ,EAC3C,KAAA,OAAO,MAAM,uCAAuC,EACzD,MAAMK,EAAa,MAAMF,EAAY,MAAM,IAAIC,CAAE,EAC3CE,EAAW,IAAIC,EAAAA,gBACrB,OAAAD,EAAS,WAAWD,CAAU,EACvBC,QACAE,EAAG,CACL,KAAA,OAAO,MAAM,oDAAqDA,CAAC,EACjE,MACT,CACF,CAEA,MAAM,SAASR,EAAkBI,EAAYK,EAA+B,CACtE,GAAA,CAIF,MAH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U,UAAWA,GACjDA,EAAA,GAAKG,EAAO,IAAMS,EACtB,KAAA,OAAO,MAAM,mCAAoCT,CAAI,EAC1D,KAAK,eAAe,WAClB,KAAK,gBAAgB,KACrBA,EAAO,IAAMS,EACbZ,CAAA,EAEK,KAEP,KAAK,OAAO,MACV,0DAAA,EAEK,GAEX,CAEA,MAAa,gBACXiB,EACAC,EACAN,EACmB,CACnB,OAAO,KAAK,QAAQ,gBAAgBK,EAAOC,EAAaN,CAAM,CAChE,CAEA,MAAa,aACXO,EACAC,EACiB,CACjB,OAAO,MAAM,KAAK,QAAQ,aAAaD,EAAUC,CAAS,CAC5D,CAEA,KACEjB,EACAkB,EACAC,EACAV,EACkB,CAClB,OAAO,KAAK,QAAQ,KAAKT,EAAMkB,EAAOC,EAASV,CAAM,CACvD,CAEA,MAAM,gBAAgBT,EAAcoB,EAAiC,CACnE,OAAO,KAAK,QAAQ,gBAAgBpB,EAAMoB,CAAK,CACjD,CAEA,MAAM,OAAOpB,EAA6D,CACjE,OAAA,KAAK,QAAQ,OAAOA,CAAI,CACjC,CACF,EAhLaI,EAANH,EAAA,CADNC,aAAW,EAUPC,aAAe,QAAQ,CAAA,EACvBA,aAAuB,gBAAgB,CAAA,EACvCA,aAAoB,aAAa,CAAA,CAAA,EAXzBC,CAAA,ECRN,MAAMiB,CAAc,CACzB,YAAYC,EAAsB,CAChCA,EACG,KAAsB,iBAAiB,EACvC,GAAGlB,CAAsB,EACzB,mBACHkB,EACG,KAAqB,gBAAgB,EACrC,GAAG9B,CAAmB,EACtB,kBACL,CACF"}
|
|
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\n// eslint-disable-next-line import/no-named-as-default\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: 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: Logger,\n @inject<OfflineStorage>(\"OfflineStorage\") offlineStorage: OfflineStorage,\n @inject<QueueWorker>(\"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 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 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","/*\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","ComponentInit","container"],"mappings":"oYAwBA,MAAqBA,UAAyBC,CAAM,CAGlD,YAAYC,EAAkB,CAC5B,MAAM,SAAWA,CAAQ,EACpB,KAAA,QAAQ,CAAC,EAAE,OAAO,CACrB,MAEE,0FAAA,CACH,CACH,CACF,0NCRA,IAAqBC,EAArB,KAAmE,CAOjE,YAAsCC,EAAgB,CAN9C,KAAA,mBAAoD,IAO1D,KAAK,OAASA,EACT,KAAA,OAAO,UAAU,wCAAwC,CAChE,CAEA,eAAeF,EAAoC,CACjD,IAAIG,EAAc,KAAK,eAAe,IAAIH,CAAQ,EAClD,OAAIG,GAAe,OACHA,EAAA,IAAIL,EAAiBE,CAAQ,EACtC,KAAA,eAAe,IAAIA,EAAUG,CAAW,GAExCA,CACT,CAEA,MAAM,QAAQH,EAAkBI,EAA2C,CACrE,GAAA,CACG,KAAA,OAAO,MAAM,wCAAyCA,CAAE,EACvD,MAAAD,EAAc,KAAK,eAAeH,CAAQ,EAC3C,KAAA,OAAO,MAAM,uCAAuC,EACzD,MAAMK,EAAa,MAAMF,EAAY,MAAM,IAAIC,CAAE,EAC3CE,EAAW,IAAIC,EAAAA,gBACrB,OAAAD,EAAS,WAAWD,CAAU,EACvBC,QACAE,EAAG,CACL,KAAA,OAAO,MAAM,oDAAqDA,CAAC,EACjE,MACT,CACF,CAEA,MAAM,SAASR,EAAkBI,EAAYK,EAA+B,CACtE,GAAA,CAIF,MAHoB,KAAK,eAAeT,CAAQ,EAG9B,MAAM,IAAIS,EAAK,SAAA,EAAYL,CAAE,QACxCI,EAAG,CACV,KAAK,OAAO,MACV,mDACAR,EACAI,EACAK,EACAD,CAAA,CAEJ,CACF,CAEA,MAAM,WACJR,EACAI,EACAK,EACe,CACX,GAAA,CACI,MAAAN,EAAc,KAAK,eAA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MS,EACbZ,CAAA,EAEK,KAEP,KAAK,OAAO,MACV,0DAAA,EAEK,GAEX,CAEA,MAAa,gBACXmB,EACAC,EACAR,EACmB,CACnB,OAAO,KAAK,QAAQ,gBAAgBO,EAAOC,EAAaR,CAAM,CAChE,CAEA,MAAa,aACXS,EACAC,EACiB,CACjB,OAAO,MAAM,KAAK,QAAQ,aAAaD,EAAUC,CAAS,CAC5D,CAEA,KACEnB,EACAoB,EACAC,EACAZ,EACkB,CAClB,OAAO,KAAK,QAAQ,KAAKT,EAAMoB,EAAOC,EAASZ,CAAM,CACvD,CAEA,MAAM,gBAAgBT,EAAcsB,EAAiC,CACnE,OAAO,KAAK,QAAQ,gBAAgBtB,EAAMsB,CAAK,CACjD,CAEA,MAAM,OAAOtB,EAA6D,CACjE,OAAA,KAAK,QAAQ,OAAOA,CAAI,CACjC,CACF,EAxLaI,EAANH,EAAA,CADNC,aAAW,EAUPC,aAAe,QAAQ,CAAA,EACvBA,aAAuB,gBAAgB,CAAA,EACvCA,aAAoB,aAAa,CAAA,CAAA,EAXzBC,CAAA,ECTN,MAAMmB,CAAc,CACzB,YAAYC,EAAsB,CAChCA,EACG,KAAsB,iBAAiB,EACvC,GAAGpB,CAAsB,EACzB,mBACHoB,EACG,KAAqB,gBAAgB,EACrC,GAAGhC,CAAmB,EACtB,kBACL,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AttachmentsData, Document, Logger, PageData, Storage, WikiConfig, WrappingStorage } from '@xwiki/cristal-api';
|
|
2
|
-
import { QueueWorker } from '@xwiki/cristal-sharedworker-api';
|
|
1
|
+
import { AttachmentsData, Document, Logger, PageAttachment, PageData, Storage, WikiConfig, WrappingStorage } from '@xwiki/cristal-api';
|
|
3
2
|
import { OfflineStorage } from '@xwiki/cristal-backend-api';
|
|
3
|
+
import { QueueWorker } from '@xwiki/cristal-sharedworker-api';
|
|
4
4
|
export declare class WrappingOfflineStorage implements WrappingStorage {
|
|
5
5
|
logger: Logger;
|
|
6
6
|
storage: Storage;
|
|
@@ -15,8 +15,9 @@ export declare class WrappingOfflineStorage implements WrappingStorage {
|
|
|
15
15
|
getPageRestURL(page: string, syntax: string): string;
|
|
16
16
|
getPageFromViewURL(url: string): string | null;
|
|
17
17
|
getImageURL(page: string, image: string): string;
|
|
18
|
-
getPageContent(page: string, syntax: string, requeue?: boolean): Promise<PageData | undefined>;
|
|
18
|
+
getPageContent(page: string, syntax: string, _revision?: string, requeue?: boolean): Promise<PageData | undefined>;
|
|
19
19
|
getAttachments(page: string): Promise<AttachmentsData | undefined>;
|
|
20
|
+
getAttachment(page: string, name: string): Promise<PageAttachment | undefined>;
|
|
20
21
|
private savePageContent;
|
|
21
22
|
updatePageContent(page: string, syntax: string): Promise<boolean>;
|
|
22
23
|
getPanelContent(panel: string, contextPage: string, syntax: string): Promise<PageData>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xwiki/cristal-backend-dexie",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"license": "LGPL 2.1",
|
|
5
5
|
"author": "XWiki Org Community <contact@xwiki.org>",
|
|
6
6
|
"homepage": "https://cristal.xwiki.org/",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"main": "./dist/index.es.js",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"dexie": "4.0.8",
|
|
26
|
-
"inversify": "6.0.
|
|
27
|
-
"@xwiki/cristal-api": "0.
|
|
28
|
-
"@xwiki/cristal-sharedworker-api": "0.
|
|
29
|
-
"@xwiki/cristal-
|
|
26
|
+
"inversify": "6.0.3",
|
|
27
|
+
"@xwiki/cristal-backend-api": "0.12.0",
|
|
28
|
+
"@xwiki/cristal-sharedworker-api": "0.12.0",
|
|
29
|
+
"@xwiki/cristal-api": "0.12.0"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsc --project tsconfig.json && vite build",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import type { PageData } from "@xwiki/cristal-api";
|
|
22
|
-
import { DefaultPageData, type Logger } from "@xwiki/cristal-api";
|
|
23
|
-
import type { OfflineStorage } from "@xwiki/cristal-backend-api";
|
|
24
21
|
import DexiePageStorage from "./dexiePageStorage";
|
|
22
|
+
import { DefaultPageData, PageData } from "@xwiki/cristal-api";
|
|
25
23
|
import { inject, injectable } from "inversify";
|
|
24
|
+
import type { Logger } from "@xwiki/cristal-api";
|
|
25
|
+
import type { OfflineStorage } from "@xwiki/cristal-backend-api";
|
|
26
26
|
|
|
27
27
|
@injectable()
|
|
28
28
|
export default class DexieOfflineStorage implements OfflineStorage {
|
package/src/dexiePageStorage.ts
CHANGED
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
// eslint-disable-next-line import/no-named-as-default
|
|
22
22
|
import Dexie from "dexie";
|
|
23
|
+
import type { Table } from "dexie";
|
|
23
24
|
|
|
24
25
|
export default class DexiePageStorage extends Dexie {
|
|
25
26
|
pages!: Table<object>;
|
package/src/index.ts
CHANGED
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import DexieOfflineStorage from "./dexieOfflineStorage";
|
|
22
|
-
import { Container } from "inversify";
|
|
23
|
-
import { OfflineStorage } from "@xwiki/cristal-backend-api";
|
|
24
|
-
import { WrappingStorage } from "@xwiki/cristal-api";
|
|
25
22
|
import { WrappingOfflineStorage } from "./wrappingOfflineStorage";
|
|
23
|
+
import { WrappingStorage } from "@xwiki/cristal-api";
|
|
24
|
+
import { OfflineStorage } from "@xwiki/cristal-backend-api";
|
|
25
|
+
import { Container } from "inversify";
|
|
26
26
|
|
|
27
27
|
export class ComponentInit {
|
|
28
28
|
constructor(container: Container) {
|
|
@@ -23,13 +23,14 @@ import type {
|
|
|
23
23
|
AttachmentsData,
|
|
24
24
|
Document,
|
|
25
25
|
Logger,
|
|
26
|
+
PageAttachment,
|
|
26
27
|
PageData,
|
|
27
28
|
Storage,
|
|
28
29
|
WikiConfig,
|
|
29
30
|
WrappingStorage,
|
|
30
31
|
} from "@xwiki/cristal-api";
|
|
32
|
+
import type { OfflineStorage } from "@xwiki/cristal-backend-api";
|
|
31
33
|
import type { QueueWorker } from "@xwiki/cristal-sharedworker-api";
|
|
32
|
-
import { type OfflineStorage } from "@xwiki/cristal-backend-api";
|
|
33
34
|
|
|
34
35
|
@injectable()
|
|
35
36
|
export class WrappingOfflineStorage implements WrappingStorage {
|
|
@@ -86,6 +87,7 @@ export class WrappingOfflineStorage implements WrappingStorage {
|
|
|
86
87
|
public async getPageContent(
|
|
87
88
|
page: string,
|
|
88
89
|
syntax: string,
|
|
90
|
+
_revision?: string,
|
|
89
91
|
requeue?: boolean,
|
|
90
92
|
): Promise<PageData | undefined> {
|
|
91
93
|
this.logger.debug("Trying to get data for page ", page);
|
|
@@ -122,6 +124,13 @@ export class WrappingOfflineStorage implements WrappingStorage {
|
|
|
122
124
|
return this.storage.getAttachments(page);
|
|
123
125
|
}
|
|
124
126
|
|
|
127
|
+
getAttachment(
|
|
128
|
+
page: string,
|
|
129
|
+
name: string,
|
|
130
|
+
): Promise<PageAttachment | undefined> {
|
|
131
|
+
return this.storage.getAttachment(page, name);
|
|
132
|
+
}
|
|
133
|
+
|
|
125
134
|
private async savePageContent(
|
|
126
135
|
page: string,
|
|
127
136
|
syntax: string,
|