@xwiki/cristal-backend-dexie 1.3.0 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwiki/cristal-backend-dexie",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "license": "LGPL 2.1",
5
5
  "author": "XWiki Org Community <contact@xwiki.org>",
6
6
  "homepage": "https://cristal.xwiki.org/",
@@ -28,10 +28,10 @@
28
28
  "main": "./dist/index.es.js",
29
29
  "types": "./dist/index.d.ts",
30
30
  "dependencies": {
31
- "@xwiki/platform-api": "18.3.0",
32
- "@xwiki/platform-backend-api": "18.3.0",
31
+ "@xwiki/platform-api": "18.4.0",
32
+ "@xwiki/platform-backend-api": "18.4.0",
33
33
  "dexie": "4.3.0",
34
- "@xwiki/cristal-sharedworker-api": "1.3.0"
34
+ "@xwiki/cristal-sharedworker-api": "1.4.0"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "inversify": "8.x",
@@ -42,7 +42,7 @@
42
42
  "reflect-metadata": "0.2.2",
43
43
  "typescript": "5.9.3",
44
44
  "vite": "7.3.2",
45
- "@xwiki/cristal-dev-config": "1.3.0"
45
+ "@xwiki/cristal-dev-config": "1.4.0"
46
46
  },
47
47
  "scripts": {
48
48
  "api-extractor:local": "api-extractor run --local",
@@ -1,12 +0,0 @@
1
- import { default as DexiePageStorage } from './dexiePageStorage';
2
- import { Logger, PageData } from '@xwiki/platform-api';
3
- import { OfflineStorage } from '@xwiki/platform-backend-api';
4
- export default class DexieOfflineStorage implements OfflineStorage {
5
- private pageStorageMap;
6
- private logger;
7
- constructor(logger: Logger);
8
- getPageStorage(wikiName: string): DexiePageStorage;
9
- getPage(wikiName: string, id: string): Promise<PageData | undefined>;
10
- savePage(wikiName: string, id: string, page: PageData): Promise<void>;
11
- updatePage(wikiName: string, id: string, page: PageData): Promise<void>;
12
- }
@@ -1,5 +0,0 @@
1
- import { default as Dexie, Table } from 'dexie';
2
- export default class DexiePageStorage extends Dexie {
3
- pages: Table<object>;
4
- constructor(wikiName: string);
5
- }
package/dist/index.d.cts DELETED
@@ -1,7 +0,0 @@
1
- import { Container } from 'inversify';
2
- /**
3
- * @beta
4
- */
5
- export declare class ComponentInit {
6
- constructor(container: Container);
7
- }
package/dist/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Container } from 'inversify';
2
- /**
3
- * @beta
4
- */
5
- export declare class ComponentInit {
6
- constructor(container: Container);
7
- }
package/dist/index.es.js DELETED
@@ -1,199 +0,0 @@
1
- import h from "dexie";
2
- import { DefaultPageData as f } from "@xwiki/platform-api";
3
- import { injectable as u, inject as i } from "inversify";
4
- class d extends h {
5
- pages;
6
- constructor(t) {
7
- super("pages_" + t), this.version(2).stores({
8
- pages: (
9
- // Primary key and indexed props
10
- "id, name, content, document, css, js, document.name, document.headline, document.creator"
11
- )
12
- });
13
- }
14
- }
15
- var p = Object.getOwnPropertyDescriptor, S = (e, t, g, o) => {
16
- for (var r = o > 1 ? void 0 : o ? p(t, g) : t, a = e.length - 1, s; a >= 0; a--)
17
- (s = e[a]) && (r = s(r) || r);
18
- return r;
19
- }, m = (e, t) => (g, o) => t(g, o, e);
20
- let l = class {
21
- pageStorageMap = /* @__PURE__ */ new Map();
22
- logger;
23
- constructor(e) {
24
- this.logger = e, this.logger.setModule("storage.components.dexieOfflineStorage");
25
- }
26
- getPageStorage(e) {
27
- let t = this.pageStorageMap.get(e);
28
- return t == null && (t = new d(e), this.pageStorageMap.set(e, t)), t;
29
- }
30
- async getPage(e, t) {
31
- try {
32
- this.logger.debug("Ready to load page from local storage", t);
33
- const g = this.getPageStorage(e);
34
- this.logger.debug("pageStorage is ready, asking for page");
35
- const o = await g.pages.get(t), r = new f();
36
- return r.fromObject(o), r;
37
- } catch (g) {
38
- this.logger.debug("Exception while trying to read from local storage", g);
39
- return;
40
- }
41
- }
42
- async savePage(e, t, g) {
43
- try {
44
- await this.getPageStorage(e).pages.put(g.toObject(), t);
45
- } catch (o) {
46
- this.logger.debug(
47
- "Exception while trying to store in local storage",
48
- e,
49
- t,
50
- g,
51
- o
52
- );
53
- }
54
- }
55
- async updatePage(e, t, g) {
56
- try {
57
- const o = this.getPageStorage(e);
58
- this.logger.debug("Ready to store", g), await o.pages.update(t, g.toObject());
59
- } catch (o) {
60
- this.logger.debug(
61
- "Exception while trying to store in local storage",
62
- e,
63
- t,
64
- g,
65
- o
66
- );
67
- }
68
- }
69
- };
70
- l = S([
71
- u(),
72
- m(0, i("Logger"))
73
- ], l);
74
- var v = Object.getOwnPropertyDescriptor, P = (e, t, g, o) => {
75
- for (var r = o > 1 ? void 0 : o ? v(t, g) : t, a = e.length - 1, s; a >= 0; a--)
76
- (s = e[a]) && (r = s(r) || r);
77
- return r;
78
- }, n = (e, t) => (g, o) => t(g, o, e);
79
- let c = class {
80
- logger;
81
- // @ts-expect-error storage can be temporarily undefined during class
82
- // initialization
83
- storage;
84
- offlineStorage;
85
- queueWorker;
86
- constructor(e, t, g) {
87
- this.logger = e, this.logger.setModule("storage.components.wrappingOfflineStorage"), this.offlineStorage = t, this.queueWorker = g;
88
- }
89
- setStorage(e) {
90
- this.storage = e;
91
- }
92
- getStorage() {
93
- return this.storage;
94
- }
95
- setWikiConfig(e) {
96
- return this.storage.setWikiConfig(e);
97
- }
98
- getWikiConfig() {
99
- return this.storage.getWikiConfig();
100
- }
101
- async isStorageReady() {
102
- return this.storage.isStorageReady();
103
- }
104
- getPageRestURL(e, t) {
105
- return this.storage.getPageRestURL(e, t);
106
- }
107
- getPageFromViewURL(e) {
108
- return this.storage.getPageFromViewURL(e);
109
- }
110
- getImageURL(e, t) {
111
- return this.storage.getImageURL(e, t);
112
- }
113
- // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.
114
- // eslint-disable-next-line max-statements
115
- async getPageContent(e, t, g, o) {
116
- if (this.logger.debug("Trying to get data for page ", e), this.offlineStorage) {
117
- this.logger.debug("Asking offline storage for ", e);
118
- const r = await this.offlineStorage.getPage(
119
- this.getWikiConfig().name,
120
- e + "_" + t
121
- );
122
- return r != null && r != null ? (this.logger.debug("Loading data from local storage for page", e), (o == null || o) && this.queueWorker.addToQueue(
123
- this.getWikiConfig().name + ":" + e + "_" + t
124
- ), r) : (this.logger.debug(
125
- "Could not find data in local storage for page",
126
- e
127
- ), this.savePageContent(e, t));
128
- } else
129
- return this.logger.debug("No offline local storage available"), this.storage.getPageContent(e, t);
130
- }
131
- getAttachments(e) {
132
- return this.storage.getAttachments(e);
133
- }
134
- getAttachment(e, t) {
135
- return this.storage.getAttachment(e, t);
136
- }
137
- async savePageContent(e, t) {
138
- const g = await this.storage.getPageContent(e, t);
139
- if (g)
140
- return g.id = e + "_" + t, this.logger.debug("Saving page to offline storage", e), this.offlineStorage.savePage(
141
- this.getWikiConfig().name,
142
- e + "_" + t,
143
- g
144
- ), g;
145
- throw new Error("Can't save missing page.");
146
- }
147
- // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.
148
- // eslint-disable-next-line max-statements
149
- async updatePageContent(e, t) {
150
- const g = await this.offlineStorage.getPage(
151
- this.getWikiConfig().name,
152
- e + "_" + t
153
- ), o = await this.storage.getPageContent(e, t);
154
- return g && o ? (o.id = e + "_" + t, this.logger.debug("Saving page to offline storage", e), this.offlineStorage.savePage(
155
- this.getWikiConfig().name,
156
- e + "_" + t,
157
- o
158
- ), !0) : g?.version != o?.version && o ? (o.id = e + "_" + t, this.logger.debug("Updating page to offline storage", e), this.offlineStorage.updatePage(
159
- this.getWikiConfig().name,
160
- e + "_" + t,
161
- o
162
- ), !0) : (this.logger.debug(
163
- "Local storage not updated, because version are identical"
164
- ), !1);
165
- }
166
- async getPanelContent(e, t, g) {
167
- return this.storage.getPanelContent(e, t, g);
168
- }
169
- async getEditField(e, t) {
170
- return await this.storage.getEditField(e, t);
171
- }
172
- save(e, t, g, o) {
173
- return this.storage.save(e, t, g, o);
174
- }
175
- async saveAttachments(e, t) {
176
- return this.storage.saveAttachments(e, t);
177
- }
178
- async delete(e) {
179
- return this.storage.delete(e);
180
- }
181
- async move(e, t, g) {
182
- return this.storage.move(e, t, g);
183
- }
184
- };
185
- c = P([
186
- u(),
187
- n(0, i("Logger")),
188
- n(1, i("OfflineStorage")),
189
- n(2, i("QueueWorker"))
190
- ], c);
191
- class w {
192
- constructor(t) {
193
- t.bind("WrappingStorage").to(c).inSingletonScope(), t.bind("OfflineStorage").to(l).inSingletonScope();
194
- }
195
- }
196
- export {
197
- w as ComponentInit
198
- };
199
- //# sourceMappingURL=index.es.js.map
@@ -1 +0,0 @@
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 { default as 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 } from \"@xwiki/platform-api\";\nimport { inject, injectable } from \"inversify\";\nimport type { Logger, PageData } from \"@xwiki/platform-api\";\nimport type { OfflineStorage } from \"@xwiki/platform-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 { QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport type {\n AttachmentsData,\n Document,\n Logger,\n PageAttachment,\n PageData,\n Storage,\n WikiConfig,\n WrappingStorage,\n} from \"@xwiki/platform-api\";\nimport type { OfflineStorage } from \"@xwiki/platform-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,\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(\n page: string,\n files: File[],\n ): Promise<undefined | (undefined | string)[]> {\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 { Container } from \"inversify\";\nimport type { WrappingStorage } from \"@xwiki/platform-api\";\nimport type { OfflineStorage } from \"@xwiki/platform-backend-api\";\n\n/**\n * @beta\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":";;;AAuBA,MAAqBA,UAAyBC,EAAM;AAAA,EAClD;AAAA,EAEA,YAAYC,GAAkB;AAC5B,UAAM,WAAWA,CAAQ,GACzB,KAAK,QAAQ,CAAC,EAAE,OAAO;AAAA,MACrB;AAAA;AAAA,QAEE;AAAA;AAAA,IAAA,CACH;AAAA,EACH;AACF;;;;;;ACPA,IAAqBC,IA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GtB,CAAsB,EACzB,iBAAA,GACHsB,EACG,KAAqB,gBAAgB,EACrC,GAAGlC,CAAmB,EACtB,iBAAA;AAAA,EACL;AACF;"}
package/dist/index.umd.js DELETED
@@ -1,2 +0,0 @@
1
- (function(g,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("dexie"),require("@xwiki/platform-api"),require("inversify")):typeof define=="function"&&define.amd?define(["exports","dexie","@xwiki/platform-api","inversify"],n):(g=typeof globalThis<"u"?globalThis:g||self,n(g["cristal_backend-dexie"]={},g.Dexie,g.platformApi,g.inversify))})(this,(function(g,n,h,s){"use strict";class d extends n{pages;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 a=r>1?void 0:r?p(t,o):t,i=e.length-1,l;i>=0;i--)(l=e[i])&&(a=l(a)||a);return a},m=(e,t)=>(o,r)=>t(o,r,e);let c=class{pageStorageMap=new Map;logger;constructor(e){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),a=new h.DefaultPageData;return a.fromObject(r),a}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 P=Object.getOwnPropertyDescriptor,v=(e,t,o,r)=>{for(var a=r>1?void 0:r?P(t,o):t,i=e.length-1,l;i>=0;i--)(l=e[i])&&(a=l(a)||a);return a},u=(e,t)=>(o,r)=>t(o,r,e);let f=class{logger;storage;offlineStorage;queueWorker;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 a=await this.offlineStorage.getPage(this.getWikiConfig().name,e+"_"+t);return a!=null&&a!=null?(this.logger.debug("Loading data from local storage for page",e),(r==null||r)&&this.queueWorker.addToQueue(this.getWikiConfig().name+":"+e+"_"+t),a):(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?.version!=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)}};f=v([s.injectable(),u(0,s.inject("Logger")),u(1,s.inject("OfflineStorage")),u(2,s.inject("QueueWorker"))],f);class b{constructor(t){t.bind("WrappingStorage").to(f).inSingletonScope(),t.bind("OfflineStorage").to(c).inSingletonScope()}}g.ComponentInit=b,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
2
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
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 { default as 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 } from \"@xwiki/platform-api\";\nimport { inject, injectable } from \"inversify\";\nimport type { Logger, PageData } from \"@xwiki/platform-api\";\nimport type { OfflineStorage } from \"@xwiki/platform-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 { QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport type {\n AttachmentsData,\n Document,\n Logger,\n PageAttachment,\n PageData,\n Storage,\n WikiConfig,\n WrappingStorage,\n} from \"@xwiki/platform-api\";\nimport type { OfflineStorage } from \"@xwiki/platform-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,\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(\n page: string,\n files: File[],\n ): Promise<undefined | (undefined | string)[]> {\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 { Container } from \"inversify\";\nimport type { WrappingStorage } from \"@xwiki/platform-api\";\nimport type { OfflineStorage } from \"@xwiki/platform-backend-api\";\n\n/**\n * @beta\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":"wYAuBA,MAAqBA,UAAyBC,CAAM,CAClD,MAEA,YAAYC,EAAkB,CAC5B,MAAM,SAAWA,CAAQ,EACzB,KAAK,QAAQ,CAAC,EAAE,OAAO,CACrB,MAEE,0FAAA,CACH,CACH,CACF,sKCPA,IAAqBC,EAArB,KAAmE,CACzD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,EAAMoB,EAAOC,EAASZ,CAAM,CACvD,CAEA,MAAM,gBACJT,EACAsB,EAC6C,CAC7C,OAAO,KAAK,QAAQ,gBAAgBtB,EAAMsB,CAAK,CACjD,CAEA,MAAM,OAAOtB,EAA6D,CACxE,OAAO,KAAK,QAAQ,OAAOA,CAAI,CACjC,CAEA,MAAM,KACJA,EACAuB,EACAC,EAC+C,CAC/C,OAAO,KAAK,QAAQ,KAAKxB,EAAMuB,EAASC,CAAgB,CAC1D,CACF,EAvMapB,EAANH,EAAA,CADNC,aAAA,EAUIC,aAAO,QAAQ,CAAA,EACfA,aAAO,gBAAgB,CAAA,EACvBA,aAAO,aAAa,CAAA,CAAA,EAXZC,CAAA,ECNN,MAAMqB,CAAc,CACzB,YAAYC,EAAsB,CAChCA,EACG,KAAsB,iBAAiB,EACvC,GAAGtB,CAAsB,EACzB,iBAAA,EACHsB,EACG,KAAqB,gBAAgB,EACrC,GAAGlC,CAAmB,EACtB,iBAAA,CACL,CACF"}
@@ -1,35 +0,0 @@
1
- import { QueueWorker } from '@xwiki/cristal-sharedworker-api';
2
- import { AttachmentsData, Document, Logger, PageAttachment, PageData, Storage, WikiConfig, WrappingStorage } from '@xwiki/platform-api';
3
- import { OfflineStorage } from '@xwiki/platform-backend-api';
4
- export declare class WrappingOfflineStorage implements WrappingStorage {
5
- logger: Logger;
6
- storage: Storage;
7
- offlineStorage: OfflineStorage;
8
- queueWorker: QueueWorker;
9
- constructor(logger: Logger, offlineStorage: OfflineStorage, queueWorker: QueueWorker);
10
- setStorage(storage: Storage): void;
11
- getStorage(): Storage;
12
- setWikiConfig(config: WikiConfig): void;
13
- getWikiConfig(): WikiConfig;
14
- isStorageReady(): Promise<boolean>;
15
- getPageRestURL(page: string, syntax: string): string;
16
- getPageFromViewURL(url: string): string | null;
17
- getImageURL(page: string, image: string): string;
18
- getPageContent(page: string, syntax: string, _revision?: string, requeue?: boolean): Promise<PageData | undefined>;
19
- getAttachments(page: string): Promise<AttachmentsData | undefined>;
20
- getAttachment(page: string, name: string): Promise<PageAttachment | undefined>;
21
- private savePageContent;
22
- updatePageContent(page: string, syntax: string): Promise<boolean>;
23
- getPanelContent(panel: string, contextPage: string, syntax: string): Promise<PageData>;
24
- getEditField(document: Document, fieldName: string): Promise<string>;
25
- save(page: string, title: string, content: string, syntax: string): Promise<unknown>;
26
- saveAttachments(page: string, files: File[]): Promise<undefined | (undefined | string)[]>;
27
- delete(page: string): Promise<{
28
- success: boolean;
29
- error?: string;
30
- }>;
31
- move(page: string, newPage: string, preserveChildren: boolean): Promise<{
32
- success: boolean;
33
- error?: string;
34
- }>;
35
- }