@xwiki/cristal-electron-settings-main 0.21.1 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,13 +1,16 @@
1
1
  # @xwiki/cristal-electron-settings-main
2
2
 
3
- ## 0.21.1
3
+ ## 0.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Cristal 0.22 Release
4
8
 
5
9
  ### Patch Changes
6
10
 
7
- - Cristal 0.21.1 Release
8
11
  - Updated dependencies
9
- - @xwiki/cristal-configuration-api@0.21.1
10
- - @xwiki/cristal-settings-api@0.21.1
12
+ - @xwiki/cristal-configuration-api@0.22.0
13
+ - @xwiki/cristal-settings-api@0.22.0
11
14
 
12
15
  ## 0.21.0
13
16
 
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../../api-extractor.json"
4
+ }
package/dist/index.d.cts CHANGED
@@ -1,3 +1,7 @@
1
1
  import { getConfigurations } from './storage';
2
+ /**
3
+ * @since 0.18
4
+ * @beta
5
+ */
2
6
  declare function load(): void;
3
7
  export { getConfigurations, load };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  import { getConfigurations } from './storage';
2
+ /**
3
+ * @since 0.18
4
+ * @beta
5
+ */
2
6
  declare function load(): void;
3
7
  export { getConfigurations, load };
package/dist/index.es.js CHANGED
@@ -1,15 +1,15 @@
1
- import r from "electron-store";
2
- import { ipcMain as n } from "electron";
3
- const c = { FileSystem: { name: "FileSystem", configType: "FileSystem", serverRendering: !1, offline: !1, designSystem: "vuetify", editor: "tiptap" }, FileSystemSL: { name: "FileSystemSL", configType: "FileSystem", serverRendering: !1, offline: !1, designSystem: "shoelace", editor: "tiptap" }, XWiki: { name: "XWiki", configType: "XWiki", serverRendering: !1, offline: !1, baseURL: "https://cristal-backend.demo.xwiki.com/xwiki", baseRestURL: "/rest/cristal/page?media=json", homePage: "Main.WebHome", designSystem: "vuetify", editor: "tiptap", realtimeURL: "https://cristal.demo.xwiki.com:8093/collaboration" }, XWikiSL: { name: "XWikiSL", configType: "XWiki", serverRendering: !1, offline: !1, baseURL: "https://cristal-backend.demo.xwiki.com/xwiki", baseRestURL: "/rest/cristal/page?media=json", homePage: "Main.WebHome", designSystem: "shoelace", editor: "tiptap", realtimeURL: "https://cristal.demo.xwiki.com:8093/collaboration" } }, l = {
4
- configuration: c
5
- }, f = "configuration", s = "_raw", g = {
1
+ import o from "electron-store";
2
+ import { ipcMain as t } from "electron";
3
+ const r = { FileSystem: { name: "FileSystem", configType: "FileSystem", serverRendering: !1, offline: !1, designSystem: "vuetify", editor: "tiptap" }, FileSystemSL: { name: "FileSystemSL", configType: "FileSystem", serverRendering: !1, offline: !1, designSystem: "shoelace", editor: "tiptap" }, XWiki: { name: "XWiki", configType: "XWiki", serverRendering: !1, offline: !1, baseURL: "https://cristal-backend.demo.xwiki.com/xwiki", baseRestURL: "/rest/cristal/page?media=json", homePage: "Main.WebHome", designSystem: "vuetify", editor: "tiptap", realtimeURL: "https://cristal.demo.xwiki.com:8093/collaboration" }, XWikiSL: { name: "XWikiSL", configType: "XWiki", serverRendering: !1, offline: !1, baseURL: "https://cristal-backend.demo.xwiki.com/xwiki", baseRestURL: "/rest/cristal/page?media=json", homePage: "Main.WebHome", designSystem: "shoelace", editor: "tiptap", realtimeURL: "https://cristal.demo.xwiki.com:8093/collaboration" } }, c = {
4
+ configuration: r
5
+ }, l = "configuration", n = "_raw", f = {
6
6
  _raw: {
7
7
  type: "string"
8
8
  },
9
9
  configuration: {
10
10
  type: "object"
11
11
  }
12
- }, t = new r({
12
+ }, i = new o({
13
13
  name: "settings",
14
14
  // Here, we want to keep in the store the raw string representation of the
15
15
  // file, since it should be parsed and serialized by the SettingsManager
@@ -17,41 +17,35 @@ const c = { FileSystem: { name: "FileSystem", configType: "FileSystem", serverRe
17
17
  // some settings values on Electron's main process.
18
18
  serialize: (e) => e._raw,
19
19
  deserialize: (e) => ({ _raw: e, ...JSON.parse(e) }),
20
- schema: g
20
+ schema: f
21
21
  });
22
- function m(e, i) {
23
- t.set(e, i);
22
+ function s(e) {
23
+ i.set(n, e);
24
24
  }
25
- function a(e) {
26
- return t.get(e);
25
+ function g() {
26
+ return i.size < 2 && s(JSON.stringify(c, null, 2)), i.get(n);
27
27
  }
28
- function o(e) {
29
- m(s, e);
28
+ function S() {
29
+ return i.get(l);
30
30
  }
31
- function d() {
32
- return t.size < 2 && o(JSON.stringify(l, null, 2)), a(s);
33
- }
34
- function k() {
35
- return a(f);
31
+ function m(e) {
32
+ s(e);
36
33
  }
37
- function p(e) {
38
- o(e);
39
- }
40
- function y() {
41
- return d();
34
+ function d() {
35
+ return g();
42
36
  }
43
- function R() {
44
- n.handle(
37
+ function u() {
38
+ t.handle(
45
39
  "settings:save",
46
40
  async (e, {
47
- settings: i
41
+ settings: a
48
42
  }) => {
49
- p(i);
43
+ m(a);
50
44
  }
51
- ), n.handle("settings:load", async () => y());
45
+ ), t.handle("settings:load", async () => d());
52
46
  }
53
47
  export {
54
- k as getConfigurations,
55
- R as load
48
+ S as getConfigurations,
49
+ u as load
56
50
  };
57
51
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/storage.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 defaultSettings from \"./defaultSettings.json\";\nimport { Configurations } from \"@xwiki/cristal-configuration-api\";\nimport Store from \"electron-store\";\n\nconst configurationKey = \"configuration\";\nconst settingsKey = \"_raw\";\n\nconst schema = {\n _raw: {\n type: \"string\",\n },\n configuration: {\n type: \"object\",\n },\n};\n\nconst storeInstance: Store = new Store({\n name: \"settings\",\n // Here, we want to keep in the store the raw string representation of the\n // file, since it should be parsed and serialized by the SettingsManager\n // service. We still include the deserialized object in case we want to check\n // some settings values on Electron's main process.\n serialize: (value: Record<string, unknown>) => value._raw as string,\n deserialize: (value: string) => ({ _raw: value, ...JSON.parse(value) }),\n schema,\n});\n\nfunction set<T>(key: string, value: T) {\n // @ts-expect-error type resolution failing because of electron-store library bug\n storeInstance.set(key, value);\n}\n\nfunction get<T>(key: string): T {\n // @ts-expect-error type resolution failing because of electron-store library bug\n return storeInstance.get(key) as T;\n}\n\nfunction rm(key: string) {\n // @ts-expect-error type resolution failing because of electron-store library bug\n storeInstance.delete(key);\n}\n\nfunction setSettings(value: string): void {\n set(settingsKey, value);\n}\n\nfunction getSettings(): string {\n // @ts-expect-error type resolution failing because of electron-store library bug\n if (storeInstance.size < 2) {\n setSettings(JSON.stringify(defaultSettings, null, 2));\n }\n return get(settingsKey);\n}\n\nfunction deleteSettings(): void {\n rm(settingsKey);\n}\n\nfunction getConfigurations(): Configurations {\n return get(configurationKey);\n}\n\nexport { deleteSettings, getConfigurations, getSettings, setSettings };\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 { getConfigurations, getSettings, setSettings } from \"./storage\";\nimport { ipcMain } from \"electron\";\n\nfunction saveSettings(settings: string): void {\n setSettings(settings);\n}\n\nfunction loadSettings(): string {\n return getSettings();\n}\n\nfunction load(): void {\n ipcMain.handle(\n \"settings:save\",\n async (\n _event,\n {\n settings,\n }: {\n settings: string;\n },\n ): Promise<void> => {\n saveSettings(settings);\n },\n );\n\n ipcMain.handle(\"settings:load\", async (): Promise<string> => {\n return loadSettings();\n });\n}\n\nexport { getConfigurations, load };\n"],"names":["configurationKey","settingsKey","schema","storeInstance","Store","value","set","key","get","setSettings","getSettings","defaultSettings","getConfigurations","saveSettings","settings","loadSettings","load","ipcMain","_event"],"mappings":";;;;GAwBMA,IAAmB,iBACnBC,IAAc,QAEdC,IAAS;AAAA,EACb,MAAM;AAAA,IACJ,MAAM;AAAA,EAAA;AAAA,EAER,eAAe;AAAA,IACb,MAAM;AAAA,EAAA;AAEV,GAEMC,IAAuB,IAAIC,EAAM;AAAA,EACrC,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAKN,WAAW,CAACC,MAAmCA,EAAM;AAAA,EACrD,aAAa,CAACA,OAAmB,EAAE,MAAMA,GAAO,GAAG,KAAK,MAAMA,CAAK;EACnE,QAAAH;AACF,CAAC;AAED,SAASI,EAAOC,GAAaF,GAAU;AAErC,EAAAF,EAAc,IAAII,GAAKF,CAAK;AAC9B;AAEA,SAASG,EAAOD,GAAgB;AAE9B,SAAOJ,EAAc,IAAII,CAAG;AAC9B;AAOA,SAASE,EAAYJ,GAAqB;AACxC,EAAAC,EAAIL,GAAaI,CAAK;AACxB;AAEA,SAASK,IAAsB;AAE7B,SAAIP,EAAc,OAAO,KACvBM,EAAY,KAAK,UAAUE,GAAiB,MAAM,CAAC,CAAC,GAE/CH,EAAIP,CAAW;AACxB;AAMA,SAASW,IAAoC;AAC3C,SAAOJ,EAAIR,CAAgB;AAC7B;ACzDA,SAASa,EAAaC,GAAwB;AAC5C,EAAAL,EAAYK,CAAQ;AACtB;AAEA,SAASC,IAAuB;AAC9B,SAAOL,EAAA;AACT;AAEA,SAASM,IAAa;AACpB,EAAAC,EAAQ;AAAA,IACN;AAAA,IACA,OACEC,GACA;AAAA,MACE,UAAAJ;AAAA,IAAA,MAIgB;AAClB,MAAAD,EAAaC,CAAQ;AAAA,IACvB;AAAA,EAAA,GAGFG,EAAQ,OAAO,iBAAiB,YACvBF,EAAA,CACR;AACH;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/storage.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 defaultSettings from \"./defaultSettings.json\";\nimport Store from \"electron-store\";\nimport type { Configurations } from \"@xwiki/cristal-configuration-api\";\n\nconst configurationKey = \"configuration\";\nconst settingsKey = \"_raw\";\n\nconst schema = {\n _raw: {\n type: \"string\",\n },\n configuration: {\n type: \"object\",\n },\n};\n\ntype StoreType = {\n _raw: string;\n configuration: object;\n};\n\nconst storeInstance: Store<StoreType> = new Store<StoreType>({\n name: \"settings\",\n // Here, we want to keep in the store the raw string representation of the\n // file, since it should be parsed and serialized by the SettingsManager\n // service. We still include the deserialized object in case we want to check\n // some settings values on Electron's main process.\n serialize: (value: Record<string, unknown>) => value._raw as string,\n deserialize: (value: string) => ({ _raw: value, ...JSON.parse(value) }),\n schema,\n});\n\nfunction setSettings(value: string): void {\n storeInstance.set(settingsKey, value);\n}\n\nfunction getSettings(): string {\n if (storeInstance.size < 2) {\n setSettings(JSON.stringify(defaultSettings, null, 2));\n }\n return storeInstance.get(settingsKey);\n}\n\nfunction deleteSettings(): void {\n storeInstance.delete(settingsKey);\n}\n\n/**\n * @since 0.18\n * @beta\n */\nfunction getConfigurations(): Configurations {\n return storeInstance.get(configurationKey) as Configurations;\n}\n\nexport { deleteSettings, getConfigurations, getSettings, setSettings };\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 { getConfigurations, getSettings, setSettings } from \"./storage\";\nimport { ipcMain } from \"electron\";\n\nfunction saveSettings(settings: string): void {\n setSettings(settings);\n}\n\nfunction loadSettings(): string {\n return getSettings();\n}\n\n/**\n * @since 0.18\n * @beta\n */\nfunction load(): void {\n ipcMain.handle(\n \"settings:save\",\n async (\n _event,\n {\n settings,\n }: {\n settings: string;\n },\n ): Promise<void> => {\n saveSettings(settings);\n },\n );\n\n ipcMain.handle(\"settings:load\", async (): Promise<string> => {\n return loadSettings();\n });\n}\n\nexport { getConfigurations, load };\n"],"names":["configurationKey","settingsKey","schema","storeInstance","Store","value","setSettings","getSettings","defaultSettings","getConfigurations","saveSettings","settings","loadSettings","load","ipcMain","_event"],"mappings":";;;;GAwBMA,IAAmB,iBACnBC,IAAc,QAEdC,IAAS;AAAA,EACb,MAAM;AAAA,IACJ,MAAM;AAAA,EAAA;AAAA,EAER,eAAe;AAAA,IACb,MAAM;AAAA,EAAA;AAEV,GAOMC,IAAkC,IAAIC,EAAiB;AAAA,EAC3D,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAKN,WAAW,CAACC,MAAmCA,EAAM;AAAA,EACrD,aAAa,CAACA,OAAmB,EAAE,MAAMA,GAAO,GAAG,KAAK,MAAMA,CAAK;EACnE,QAAAH;AACF,CAAC;AAED,SAASI,EAAYD,GAAqB;AACxC,EAAAF,EAAc,IAAIF,GAAaI,CAAK;AACtC;AAEA,SAASE,IAAsB;AAC7B,SAAIJ,EAAc,OAAO,KACvBG,EAAY,KAAK,UAAUE,GAAiB,MAAM,CAAC,CAAC,GAE/CL,EAAc,IAAIF,CAAW;AACtC;AAUA,SAASQ,IAAoC;AAC3C,SAAON,EAAc,IAAIH,CAAgB;AAC3C;AClDA,SAASU,EAAaC,GAAwB;AAC5C,EAAAL,EAAYK,CAAQ;AACtB;AAEA,SAASC,IAAuB;AAC9B,SAAOL,EAAA;AACT;AAMA,SAASM,IAAa;AACpB,EAAAC,EAAQ;AAAA,IACN;AAAA,IACA,OACEC,GACA;AAAA,MACE,UAAAJ;AAAA,IAAA,MAIgB;AAClB,MAAAD,EAAaC,CAAQ;AAAA,IACvB;AAAA,EAAA,GAGFG,EAAQ,OAAO,iBAAiB,YACvBF,EAAA,CACR;AACH;"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(i,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("electron-store"),require("electron")):typeof define=="function"&&define.amd?define(["exports","electron-store","electron"],t):(i=typeof globalThis<"u"?globalThis:i||self,t(i["cristal_settings-main"]={},i.Store,i.electron))})(this,function(i,t,o){"use strict";const f={configuration:{FileSystem:{name:"FileSystem",configType:"FileSystem",serverRendering:!1,offline:!1,designSystem:"vuetify",editor:"tiptap"},FileSystemSL:{name:"FileSystemSL",configType:"FileSystem",serverRendering:!1,offline:!1,designSystem:"shoelace",editor:"tiptap"},XWiki:{name:"XWiki",configType:"XWiki",serverRendering:!1,offline:!1,baseURL:"https://cristal-backend.demo.xwiki.com/xwiki",baseRestURL:"/rest/cristal/page?media=json",homePage:"Main.WebHome",designSystem:"vuetify",editor:"tiptap",realtimeURL:"https://cristal.demo.xwiki.com:8093/collaboration"},XWikiSL:{name:"XWikiSL",configType:"XWiki",serverRendering:!1,offline:!1,baseURL:"https://cristal-backend.demo.xwiki.com/xwiki",baseRestURL:"/rest/cristal/page?media=json",homePage:"Main.WebHome",designSystem:"shoelace",editor:"tiptap",realtimeURL:"https://cristal.demo.xwiki.com:8093/collaboration"}}},l="configuration",a="_raw",g={_raw:{type:"string"},configuration:{type:"object"}},n=new t({name:"settings",serialize:e=>e._raw,deserialize:e=>({_raw:e,...JSON.parse(e)}),schema:g});function d(e,s){n.set(e,s)}function r(e){return n.get(e)}function c(e){d(a,e)}function m(){return n.size<2&&c(JSON.stringify(f,null,2)),r(a)}function u(){return r(l)}function p(e){c(e)}function y(){return m()}function S(){o.ipcMain.handle("settings:save",async(e,{settings:s})=>{p(s)}),o.ipcMain.handle("settings:load",async()=>y())}i.getConfigurations=u,i.load=S,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("electron-store"),require("electron")):typeof define=="function"&&define.amd?define(["exports","electron-store","electron"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e["cristal_settings-main"]={},e.Store,e.electron))})(this,(function(e,t,s){"use strict";const r={configuration:{FileSystem:{name:"FileSystem",configType:"FileSystem",serverRendering:!1,offline:!1,designSystem:"vuetify",editor:"tiptap"},FileSystemSL:{name:"FileSystemSL",configType:"FileSystem",serverRendering:!1,offline:!1,designSystem:"shoelace",editor:"tiptap"},XWiki:{name:"XWiki",configType:"XWiki",serverRendering:!1,offline:!1,baseURL:"https://cristal-backend.demo.xwiki.com/xwiki",baseRestURL:"/rest/cristal/page?media=json",homePage:"Main.WebHome",designSystem:"vuetify",editor:"tiptap",realtimeURL:"https://cristal.demo.xwiki.com:8093/collaboration"},XWikiSL:{name:"XWikiSL",configType:"XWiki",serverRendering:!1,offline:!1,baseURL:"https://cristal-backend.demo.xwiki.com/xwiki",baseRestURL:"/rest/cristal/page?media=json",homePage:"Main.WebHome",designSystem:"shoelace",editor:"tiptap",realtimeURL:"https://cristal.demo.xwiki.com:8093/collaboration"}}},c="configuration",o="_raw",f={_raw:{type:"string"},configuration:{type:"object"}},n=new t({name:"settings",serialize:i=>i._raw,deserialize:i=>({_raw:i,...JSON.parse(i)}),schema:f});function a(i){n.set(o,i)}function l(){return n.size<2&&a(JSON.stringify(r,null,2)),n.get(o)}function g(){return n.get(c)}function d(i){a(i)}function m(){return l()}function u(){s.ipcMain.handle("settings:save",async(i,{settings:p})=>{d(p)}),s.ipcMain.handle("settings:load",async()=>m())}e.getConfigurations=g,e.load=u,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/storage.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 defaultSettings from \"./defaultSettings.json\";\nimport { Configurations } from \"@xwiki/cristal-configuration-api\";\nimport Store from \"electron-store\";\n\nconst configurationKey = \"configuration\";\nconst settingsKey = \"_raw\";\n\nconst schema = {\n _raw: {\n type: \"string\",\n },\n configuration: {\n type: \"object\",\n },\n};\n\nconst storeInstance: Store = new Store({\n name: \"settings\",\n // Here, we want to keep in the store the raw string representation of the\n // file, since it should be parsed and serialized by the SettingsManager\n // service. We still include the deserialized object in case we want to check\n // some settings values on Electron's main process.\n serialize: (value: Record<string, unknown>) => value._raw as string,\n deserialize: (value: string) => ({ _raw: value, ...JSON.parse(value) }),\n schema,\n});\n\nfunction set<T>(key: string, value: T) {\n // @ts-expect-error type resolution failing because of electron-store library bug\n storeInstance.set(key, value);\n}\n\nfunction get<T>(key: string): T {\n // @ts-expect-error type resolution failing because of electron-store library bug\n return storeInstance.get(key) as T;\n}\n\nfunction rm(key: string) {\n // @ts-expect-error type resolution failing because of electron-store library bug\n storeInstance.delete(key);\n}\n\nfunction setSettings(value: string): void {\n set(settingsKey, value);\n}\n\nfunction getSettings(): string {\n // @ts-expect-error type resolution failing because of electron-store library bug\n if (storeInstance.size < 2) {\n setSettings(JSON.stringify(defaultSettings, null, 2));\n }\n return get(settingsKey);\n}\n\nfunction deleteSettings(): void {\n rm(settingsKey);\n}\n\nfunction getConfigurations(): Configurations {\n return get(configurationKey);\n}\n\nexport { deleteSettings, getConfigurations, getSettings, setSettings };\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 { getConfigurations, getSettings, setSettings } from \"./storage\";\nimport { ipcMain } from \"electron\";\n\nfunction saveSettings(settings: string): void {\n setSettings(settings);\n}\n\nfunction loadSettings(): string {\n return getSettings();\n}\n\nfunction load(): void {\n ipcMain.handle(\n \"settings:save\",\n async (\n _event,\n {\n settings,\n }: {\n settings: string;\n },\n ): Promise<void> => {\n saveSettings(settings);\n },\n );\n\n ipcMain.handle(\"settings:load\", async (): Promise<string> => {\n return loadSettings();\n });\n}\n\nexport { getConfigurations, load };\n"],"names":["configurationKey","settingsKey","schema","storeInstance","Store","value","set","key","get","setSettings","getSettings","defaultSettings","getConfigurations","saveSettings","settings","loadSettings","load","ipcMain","_event"],"mappings":"6rCAwBMA,EAAmB,gBACnBC,EAAc,OAEdC,EAAS,CACb,KAAM,CACJ,KAAM,QAAA,EAER,cAAe,CACb,KAAM,QAAA,CAEV,EAEMC,EAAuB,IAAIC,EAAM,CACrC,KAAM,WAKN,UAAYC,GAAmCA,EAAM,KACrD,YAAcA,IAAmB,CAAE,KAAMA,EAAO,GAAG,KAAK,MAAMA,CAAK,IACnE,OAAAH,CACF,CAAC,EAED,SAASI,EAAOC,EAAaF,EAAU,CAErCF,EAAc,IAAII,EAAKF,CAAK,CAC9B,CAEA,SAASG,EAAOD,EAAgB,CAE9B,OAAOJ,EAAc,IAAII,CAAG,CAC9B,CAOA,SAASE,EAAYJ,EAAqB,CACxCC,EAAIL,EAAaI,CAAK,CACxB,CAEA,SAASK,GAAsB,CAE7B,OAAIP,EAAc,KAAO,GACvBM,EAAY,KAAK,UAAUE,EAAiB,KAAM,CAAC,CAAC,EAE/CH,EAAIP,CAAW,CACxB,CAMA,SAASW,GAAoC,CAC3C,OAAOJ,EAAIR,CAAgB,CAC7B,CCzDA,SAASa,EAAaC,EAAwB,CAC5CL,EAAYK,CAAQ,CACtB,CAEA,SAASC,GAAuB,CAC9B,OAAOL,EAAA,CACT,CAEA,SAASM,GAAa,CACpBC,EAAAA,QAAQ,OACN,gBACA,MACEC,EACA,CACE,SAAAJ,CAAA,IAIgB,CAClBD,EAAaC,CAAQ,CACvB,CAAA,EAGFG,UAAQ,OAAO,gBAAiB,SACvBF,EAAA,CACR,CACH"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/storage.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 defaultSettings from \"./defaultSettings.json\";\nimport Store from \"electron-store\";\nimport type { Configurations } from \"@xwiki/cristal-configuration-api\";\n\nconst configurationKey = \"configuration\";\nconst settingsKey = \"_raw\";\n\nconst schema = {\n _raw: {\n type: \"string\",\n },\n configuration: {\n type: \"object\",\n },\n};\n\ntype StoreType = {\n _raw: string;\n configuration: object;\n};\n\nconst storeInstance: Store<StoreType> = new Store<StoreType>({\n name: \"settings\",\n // Here, we want to keep in the store the raw string representation of the\n // file, since it should be parsed and serialized by the SettingsManager\n // service. We still include the deserialized object in case we want to check\n // some settings values on Electron's main process.\n serialize: (value: Record<string, unknown>) => value._raw as string,\n deserialize: (value: string) => ({ _raw: value, ...JSON.parse(value) }),\n schema,\n});\n\nfunction setSettings(value: string): void {\n storeInstance.set(settingsKey, value);\n}\n\nfunction getSettings(): string {\n if (storeInstance.size < 2) {\n setSettings(JSON.stringify(defaultSettings, null, 2));\n }\n return storeInstance.get(settingsKey);\n}\n\nfunction deleteSettings(): void {\n storeInstance.delete(settingsKey);\n}\n\n/**\n * @since 0.18\n * @beta\n */\nfunction getConfigurations(): Configurations {\n return storeInstance.get(configurationKey) as Configurations;\n}\n\nexport { deleteSettings, getConfigurations, getSettings, setSettings };\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 { getConfigurations, getSettings, setSettings } from \"./storage\";\nimport { ipcMain } from \"electron\";\n\nfunction saveSettings(settings: string): void {\n setSettings(settings);\n}\n\nfunction loadSettings(): string {\n return getSettings();\n}\n\n/**\n * @since 0.18\n * @beta\n */\nfunction load(): void {\n ipcMain.handle(\n \"settings:save\",\n async (\n _event,\n {\n settings,\n }: {\n settings: string;\n },\n ): Promise<void> => {\n saveSettings(settings);\n },\n );\n\n ipcMain.handle(\"settings:load\", async (): Promise<string> => {\n return loadSettings();\n });\n}\n\nexport { getConfigurations, load };\n"],"names":["configurationKey","settingsKey","schema","storeInstance","Store","value","setSettings","getSettings","defaultSettings","getConfigurations","saveSettings","settings","loadSettings","load","ipcMain","_event"],"mappings":"8rCAwBMA,EAAmB,gBACnBC,EAAc,OAEdC,EAAS,CACb,KAAM,CACJ,KAAM,QAAA,EAER,cAAe,CACb,KAAM,QAAA,CAEV,EAOMC,EAAkC,IAAIC,EAAiB,CAC3D,KAAM,WAKN,UAAYC,GAAmCA,EAAM,KACrD,YAAcA,IAAmB,CAAE,KAAMA,EAAO,GAAG,KAAK,MAAMA,CAAK,IACnE,OAAAH,CACF,CAAC,EAED,SAASI,EAAYD,EAAqB,CACxCF,EAAc,IAAIF,EAAaI,CAAK,CACtC,CAEA,SAASE,GAAsB,CAC7B,OAAIJ,EAAc,KAAO,GACvBG,EAAY,KAAK,UAAUE,EAAiB,KAAM,CAAC,CAAC,EAE/CL,EAAc,IAAIF,CAAW,CACtC,CAUA,SAASQ,GAAoC,CAC3C,OAAON,EAAc,IAAIH,CAAgB,CAC3C,CClDA,SAASU,EAAaC,EAAwB,CAC5CL,EAAYK,CAAQ,CACtB,CAEA,SAASC,GAAuB,CAC9B,OAAOL,EAAA,CACT,CAMA,SAASM,GAAa,CACpBC,EAAAA,QAAQ,OACN,gBACA,MACEC,EACA,CACE,SAAAJ,CAAA,IAIgB,CAClBD,EAAaC,CAAQ,CACvB,CAAA,EAGFG,UAAQ,OAAO,gBAAiB,SACvBF,EAAA,CACR,CACH"}
package/dist/storage.d.ts CHANGED
@@ -2,5 +2,9 @@ import { Configurations } from '@xwiki/cristal-configuration-api';
2
2
  declare function setSettings(value: string): void;
3
3
  declare function getSettings(): string;
4
4
  declare function deleteSettings(): void;
5
+ /**
6
+ * @since 0.18
7
+ * @beta
8
+ */
5
9
  declare function getConfigurations(): Configurations;
6
10
  export { deleteSettings, getConfigurations, getSettings, setSettings };
@@ -0,0 +1,17 @@
1
+ ## API Report File for "@xwiki/cristal-electron-settings-main"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ import { Configurations } from '@xwiki/cristal-configuration-api';
8
+
9
+ // @beta (undocumented)
10
+ export function getConfigurations(): Configurations;
11
+
12
+ // @beta (undocumented)
13
+ export function load(): void;
14
+
15
+ // (No @packageDocumentation comment for this package)
16
+
17
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwiki/cristal-electron-settings-main",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "license": "LGPL 2.1",
5
5
  "author": "XWiki Org Community <contact@xwiki.org>",
6
6
  "homepage": "https://cristal.xwiki.org/",
@@ -26,24 +26,26 @@
26
26
  }
27
27
  },
28
28
  "main": "./dist/index.es.js",
29
+ "types": "./dist/index.d.ts",
29
30
  "dependencies": {
30
31
  "electron-store": "10.1.0",
31
- "@xwiki/cristal-configuration-api": "0.21.1",
32
- "@xwiki/cristal-settings-api": "0.21.1"
32
+ "@xwiki/cristal-configuration-api": "0.22.0",
33
+ "@xwiki/cristal-settings-api": "0.22.0"
33
34
  },
34
35
  "peerDependencies": {
35
- "electron": "37.2.5"
36
+ "electron": "37.4.0"
36
37
  },
37
38
  "devDependencies": {
38
39
  "typescript": "5.9.2",
39
- "vite": "7.0.6",
40
- "@xwiki/cristal-dev-config": "0.21.1"
40
+ "vite": "7.1.5",
41
+ "@xwiki/cristal-dev-config": "0.22.0"
41
42
  },
42
43
  "scripts": {
43
- "build": "tsc --project tsconfig.json && vite build",
44
+ "api-extractor:local": "api-extractor run --local",
45
+ "build": "vite build",
44
46
  "clean": "rimraf dist",
45
47
  "lint": "eslint \"./src/**/*.{ts,tsx,vue}\" --max-warnings=0",
46
- "test": "vitest --run"
47
- },
48
- "types": "./dist/index.d.ts"
48
+ "test": "vitest --run",
49
+ "typecheck": "tsc"
50
+ }
49
51
  }
package/src/index.ts CHANGED
@@ -29,6 +29,10 @@ function loadSettings(): string {
29
29
  return getSettings();
30
30
  }
31
31
 
32
+ /**
33
+ * @since 0.18
34
+ * @beta
35
+ */
32
36
  function load(): void {
33
37
  ipcMain.handle(
34
38
  "settings:save",
package/src/storage.ts CHANGED
@@ -19,8 +19,8 @@
19
19
  */
20
20
 
21
21
  import defaultSettings from "./defaultSettings.json";
22
- import { Configurations } from "@xwiki/cristal-configuration-api";
23
22
  import Store from "electron-store";
23
+ import type { Configurations } from "@xwiki/cristal-configuration-api";
24
24
 
25
25
  const configurationKey = "configuration";
26
26
  const settingsKey = "_raw";
@@ -34,7 +34,12 @@ const schema = {
34
34
  },
35
35
  };
36
36
 
37
- const storeInstance: Store = new Store({
37
+ type StoreType = {
38
+ _raw: string;
39
+ configuration: object;
40
+ };
41
+
42
+ const storeInstance: Store<StoreType> = new Store<StoreType>({
38
43
  name: "settings",
39
44
  // Here, we want to keep in the store the raw string representation of the
40
45
  // file, since it should be parsed and serialized by the SettingsManager
@@ -45,39 +50,27 @@ const storeInstance: Store = new Store({
45
50
  schema,
46
51
  });
47
52
 
48
- function set<T>(key: string, value: T) {
49
- // @ts-expect-error type resolution failing because of electron-store library bug
50
- storeInstance.set(key, value);
51
- }
52
-
53
- function get<T>(key: string): T {
54
- // @ts-expect-error type resolution failing because of electron-store library bug
55
- return storeInstance.get(key) as T;
56
- }
57
-
58
- function rm(key: string) {
59
- // @ts-expect-error type resolution failing because of electron-store library bug
60
- storeInstance.delete(key);
61
- }
62
-
63
53
  function setSettings(value: string): void {
64
- set(settingsKey, value);
54
+ storeInstance.set(settingsKey, value);
65
55
  }
66
56
 
67
57
  function getSettings(): string {
68
- // @ts-expect-error type resolution failing because of electron-store library bug
69
58
  if (storeInstance.size < 2) {
70
59
  setSettings(JSON.stringify(defaultSettings, null, 2));
71
60
  }
72
- return get(settingsKey);
61
+ return storeInstance.get(settingsKey);
73
62
  }
74
63
 
75
64
  function deleteSettings(): void {
76
- rm(settingsKey);
65
+ storeInstance.delete(settingsKey);
77
66
  }
78
67
 
68
+ /**
69
+ * @since 0.18
70
+ * @beta
71
+ */
79
72
  function getConfigurations(): Configurations {
80
- return get(configurationKey);
73
+ return storeInstance.get(configurationKey) as Configurations;
81
74
  }
82
75
 
83
76
  export { deleteSettings, getConfigurations, getSettings, setSettings };
package/tsdoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
3
+ "extends": ["../../../tsdoc.json"]
4
+ }
package/vitest.config.ts CHANGED
@@ -19,7 +19,7 @@
19
19
  */
20
20
 
21
21
  import localConfig from "./vite.config";
22
+ import { vitestVue as defaultConfig } from "@xwiki/cristal-dev-config";
22
23
  import { mergeConfig } from "vitest/config";
23
- import defaultConfig from "@xwiki/cristal-dev-config/vitest-vue.config";
24
24
 
25
25
  export default mergeConfig(defaultConfig, localConfig);