@xwiki/cristal-sharedworker-impl 0.9.0 → 0.10.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 +17 -0
- package/dist/assets/{worker-CSpj1p6r.js → worker-Beh36sMF.js} +20 -20
- package/dist/assets/worker-Beh36sMF.js.map +1 -0
- package/dist/index.es.js +10 -8
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +11 -12
- package/src/components/defaultQueueWorker.ts +3 -1
- package/src/components/worker.ts +8 -0
- package/src/components/workerCristalApp.ts +4 -0
- package/dist/assets/worker-CSpj1p6r.js.map +0 -1
package/dist/index.es.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { injectable as d, inject as i } from "inversify";
|
|
2
2
|
import * as c from "comlink";
|
|
3
|
-
function
|
|
3
|
+
function h(e) {
|
|
4
4
|
return new SharedWorker(
|
|
5
|
-
"/assets/worker-
|
|
5
|
+
"/assets/worker-Beh36sMF.js",
|
|
6
6
|
{
|
|
7
7
|
name: e == null ? void 0 : e.name
|
|
8
8
|
}
|
|
9
9
|
);
|
|
10
10
|
}
|
|
11
|
-
var w = Object.defineProperty,
|
|
12
|
-
for (var t =
|
|
13
|
-
(l = e[
|
|
14
|
-
return
|
|
15
|
-
}, u = (e, r) => (n,
|
|
11
|
+
var w = Object.defineProperty, g = Object.getOwnPropertyDescriptor, k = (e, r, n, a) => {
|
|
12
|
+
for (var t = a > 1 ? void 0 : a ? g(r, n) : r, o = e.length - 1, l; o >= 0; o--)
|
|
13
|
+
(l = e[o]) && (t = (a ? l(r, n, t) : l(t)) || t);
|
|
14
|
+
return a && t && w(r, n, t), t;
|
|
15
|
+
}, u = (e, r) => (n, a) => r(n, a, e);
|
|
16
16
|
let s = class {
|
|
17
17
|
constructor(e, r) {
|
|
18
18
|
this.initialize(), this.logger = e, this.cristalApp = r;
|
|
@@ -35,7 +35,9 @@ let s = class {
|
|
|
35
35
|
initialize() {
|
|
36
36
|
try {
|
|
37
37
|
if (this.workerInstance == null) {
|
|
38
|
-
const e = new
|
|
38
|
+
const e = new h({
|
|
39
|
+
name: "cristal-sharedworker"
|
|
40
|
+
});
|
|
39
41
|
this.workerInstance = c.wrap(e.port);
|
|
40
42
|
const r = this;
|
|
41
43
|
this.workerInstance.setPageLoadedCallback(
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/components/defaultQueueWorker.ts","../src/components/componentsInit.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 { inject, injectable } from \"inversify\";\nimport type { MyWorker, QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport * as Comlink from \"comlink\";\nimport Worker from \"./worker?sharedworker\";\nimport { type CristalApp, type Logger } from \"@xwiki/cristal-api\";\n\n@injectable()\nexport default class DefaultQueueWorker implements QueueWorker {\n // TODO remove use of any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private workerInstance: any;\n private cristalApp: CristalApp;\n private logger: Logger;\n\n public constructor(\n @inject<Logger>(\"Logger\") logger: Logger,\n @inject<CristalApp>(\"CristalApp\") cristalApp: CristalApp,\n ) {\n this.initialize();\n this.logger = logger;\n this.cristalApp = cristalApp;\n }\n\n public pageLoaded(page: string): void {\n try {\n this.logger.debug(\n \"Received callback that new document has been loaded\",\n page,\n );\n // When reloading the page for the worker, prevents a requeue to avoid\n // an endless re-fetch of the current page.\n this.cristalApp.loadPage({\n requeue: false,\n });\n this.logger.debug(\n \"Done callback that new document has been loaded\",\n page,\n );\n } catch (e) {\n this.logger.error(\"Error calling loadPage\", e);\n }\n }\n\n public initialize(): void {\n try {\n if (this.workerInstance == null) {\n // this.workerInstance = new ComlinkWorker<typeof import('./worker')>(new URL('./worker',\n // import.meta.url), {/* normal Worker options*/})\n const sworker = new Worker();\n this.workerInstance = Comlink.wrap<MyWorker>(sworker.port);\n // TODO get rid of aliasing\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const that = this;\n this.workerInstance.setPageLoadedCallback(\n Comlink.proxy(function (page: string) {\n that.pageLoaded(page);\n }),\n );\n\n console.debug(\"Worker initialized\", this.workerInstance);\n } else {\n console.debug(\"Already initialized\");\n }\n } catch (e) {\n console.error(\"Failed to initialize shared worker\", e);\n }\n }\n\n public getStatus(): boolean {\n if (this.workerInstance != null) {\n console.log(\"workerInstance is ready\");\n return true;\n } else {\n console.log(\"workerInstance is null. Cannot call\");\n return false;\n }\n }\n\n public async increment(): Promise<number> {\n if (this.workerInstance == null) {\n console.log(\"workerInstance is null. Cannot call\");\n return -1;\n } else {\n const result = await this.workerInstance.add(1);\n console.log(\"Results from shared worker: \", result);\n return result;\n }\n }\n\n public async addToQueue(page: string): Promise<void> {\n console.log(\"worker Calling addToQueue\", page);\n if (this.workerInstance != null) {\n await this.workerInstance.addToQueue(page);\n } else {\n console.log(\"workerInstance is null. Cannot call\");\n }\n }\n\n public async getQueueSize(): Promise<number> {\n console.log(\"worker Calling getQueueSize\");\n if (this.workerInstance == null) return -1;\n else return await this.workerInstance.getQueueSize();\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 { Container } from \"inversify\";\nimport type { QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport DefaultQueueWorker from \"./defaultQueueWorker\";\n\nexport default class ComponentInit {\n constructor(container: Container) {\n container.bind<QueueWorker>(\"QueueWorker\").to(DefaultQueueWorker);\n }\n}\n"],"names":["DefaultQueueWorker","logger","cristalApp","page","e","sworker","Worker","Comlink","that","result","__decorateClass","injectable","__decorateParam","ComponentInit","container"],"mappings":";;;;;;;;;;;;;;;AA2BA,IAAqBA,IAArB,MAA+D;AAAA,EAOtD,YACqBC,GACQC,GAClC;AACA,SAAK,WAAW,GAChB,KAAK,SAASD,GACd,KAAK,aAAaC;AAAA,EACpB;AAAA,EAEO,WAAWC,GAAoB;AAChC,QAAA;AACF,WAAK,OAAO;AAAA,QACV;AAAA,QACAA;AAAA,MAAA,GAIF,KAAK,WAAW,SAAS;AAAA,QACvB,SAAS;AAAA,MAAA,CACV,GACD,KAAK,OAAO;AAAA,QACV;AAAA,QACAA;AAAA,MAAA;AAAA,aAEKC,GAAG;AACL,WAAA,OAAO,MAAM,0BAA0BA,CAAC;AAAA,IAC/C;AAAA,EACF;AAAA,EAEO,aAAmB;AACpB,QAAA;AACE,UAAA,KAAK,kBAAkB,MAAM;AAGzB,cAAAC,IAAU,IAAIC;
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/components/defaultQueueWorker.ts","../src/components/componentsInit.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 { inject, injectable } from \"inversify\";\nimport type { MyWorker, QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport * as Comlink from \"comlink\";\nimport Worker from \"./worker?sharedworker\";\nimport { type CristalApp, type Logger } from \"@xwiki/cristal-api\";\n\n@injectable()\nexport default class DefaultQueueWorker implements QueueWorker {\n // TODO remove use of any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private workerInstance: any;\n private cristalApp: CristalApp;\n private logger: Logger;\n\n public constructor(\n @inject<Logger>(\"Logger\") logger: Logger,\n @inject<CristalApp>(\"CristalApp\") cristalApp: CristalApp,\n ) {\n this.initialize();\n this.logger = logger;\n this.cristalApp = cristalApp;\n }\n\n public pageLoaded(page: string): void {\n try {\n this.logger.debug(\n \"Received callback that new document has been loaded\",\n page,\n );\n // When reloading the page for the worker, prevents a requeue to avoid\n // an endless re-fetch of the current page.\n this.cristalApp.loadPage({\n requeue: false,\n });\n this.logger.debug(\n \"Done callback that new document has been loaded\",\n page,\n );\n } catch (e) {\n this.logger.error(\"Error calling loadPage\", e);\n }\n }\n\n public initialize(): void {\n try {\n if (this.workerInstance == null) {\n // this.workerInstance = new ComlinkWorker<typeof import('./worker')>(new URL('./worker',\n // import.meta.url), {/* normal Worker options*/})\n const sworker = new Worker({\n name: \"cristal-sharedworker\",\n });\n this.workerInstance = Comlink.wrap<MyWorker>(sworker.port);\n // TODO get rid of aliasing\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const that = this;\n this.workerInstance.setPageLoadedCallback(\n Comlink.proxy(function (page: string) {\n that.pageLoaded(page);\n }),\n );\n\n console.debug(\"Worker initialized\", this.workerInstance);\n } else {\n console.debug(\"Already initialized\");\n }\n } catch (e) {\n console.error(\"Failed to initialize shared worker\", e);\n }\n }\n\n public getStatus(): boolean {\n if (this.workerInstance != null) {\n console.log(\"workerInstance is ready\");\n return true;\n } else {\n console.log(\"workerInstance is null. Cannot call\");\n return false;\n }\n }\n\n public async increment(): Promise<number> {\n if (this.workerInstance == null) {\n console.log(\"workerInstance is null. Cannot call\");\n return -1;\n } else {\n const result = await this.workerInstance.add(1);\n console.log(\"Results from shared worker: \", result);\n return result;\n }\n }\n\n public async addToQueue(page: string): Promise<void> {\n console.log(\"worker Calling addToQueue\", page);\n if (this.workerInstance != null) {\n await this.workerInstance.addToQueue(page);\n } else {\n console.log(\"workerInstance is null. Cannot call\");\n }\n }\n\n public async getQueueSize(): Promise<number> {\n console.log(\"worker Calling getQueueSize\");\n if (this.workerInstance == null) return -1;\n else return await this.workerInstance.getQueueSize();\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 { Container } from \"inversify\";\nimport type { QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport DefaultQueueWorker from \"./defaultQueueWorker\";\n\nexport default class ComponentInit {\n constructor(container: Container) {\n container.bind<QueueWorker>(\"QueueWorker\").to(DefaultQueueWorker);\n }\n}\n"],"names":["DefaultQueueWorker","logger","cristalApp","page","e","sworker","Worker","Comlink","that","result","__decorateClass","injectable","__decorateParam","ComponentInit","container"],"mappings":";;;;;;;;;;;;;;;AA2BA,IAAqBA,IAArB,MAA+D;AAAA,EAOtD,YACqBC,GACQC,GAClC;AACA,SAAK,WAAW,GAChB,KAAK,SAASD,GACd,KAAK,aAAaC;AAAA,EACpB;AAAA,EAEO,WAAWC,GAAoB;AAChC,QAAA;AACF,WAAK,OAAO;AAAA,QACV;AAAA,QACAA;AAAA,MAAA,GAIF,KAAK,WAAW,SAAS;AAAA,QACvB,SAAS;AAAA,MAAA,CACV,GACD,KAAK,OAAO;AAAA,QACV;AAAA,QACAA;AAAA,MAAA;AAAA,aAEKC,GAAG;AACL,WAAA,OAAO,MAAM,0BAA0BA,CAAC;AAAA,IAC/C;AAAA,EACF;AAAA,EAEO,aAAmB;AACpB,QAAA;AACE,UAAA,KAAK,kBAAkB,MAAM;AAGzB,cAAAC,IAAU,IAAIC,EAAO;AAAA,UACzB,MAAM;AAAA,QAAA,CACP;AACD,aAAK,iBAAiBC,EAAQ,KAAeF,EAAQ,IAAI;AAGzD,cAAMG,IAAO;AACb,aAAK,eAAe;AAAA,UAClBD,EAAQ,MAAM,SAAUJ,GAAc;AACpC,YAAAK,EAAK,WAAWL,CAAI;AAAA,UAAA,CACrB;AAAA,QAAA,GAGK,QAAA,MAAM,sBAAsB,KAAK,cAAc;AAAA,MAAA;AAEvD,gBAAQ,MAAM,qBAAqB;AAAA,aAE9B,GAAG;AACF,cAAA,MAAM,sCAAsC,CAAC;AAAA,IACvD;AAAA,EACF;AAAA,EAEO,YAAqB;AACtB,WAAA,KAAK,kBAAkB,QACzB,QAAQ,IAAI,yBAAyB,GAC9B,OAEP,QAAQ,IAAI,qCAAqC,GAC1C;AAAA,EAEX;AAAA,EAEA,MAAa,YAA6B;AACpC,QAAA,KAAK,kBAAkB;AACzB,qBAAQ,IAAI,qCAAqC,GAC1C;AACF;AACL,YAAMM,IAAS,MAAM,KAAK,eAAe,IAAI,CAAC;AACtC,qBAAA,IAAI,gCAAgCA,CAAM,GAC3CA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAa,WAAWN,GAA6B;AAC3C,YAAA,IAAI,6BAA6BA,CAAI,GACzC,KAAK,kBAAkB,OACnB,MAAA,KAAK,eAAe,WAAWA,CAAI,IAEzC,QAAQ,IAAI,qCAAqC;AAAA,EAErD;AAAA,EAEA,MAAa,eAAgC;AAEvC,WADJ,QAAQ,IAAI,6BAA6B,GACrC,KAAK,kBAAkB,OAAa,KAC5B,MAAM,KAAK,eAAe;EACxC;AACF;AAlGqBH,IAArBU,EAAA;AAAA,EADCC,EAAW;AAAA,EASPC,OAAe,QAAQ,CAAA;AAAA,EACvBA,OAAmB,YAAY,CAAA;AAAA,GATfZ,CAAA;ACHrB,MAAqBa,EAAc;AAAA,EACjC,YAAYC,GAAsB;AAChC,IAAAA,EAAU,KAAkB,aAAa,EAAE,GAAGd,CAAkB;AAAA,EAClE;AACF;"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(o,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("inversify"),require("comlink")):typeof define=="function"&&define.amd?define(["exports","inversify","comlink"],a):(o=typeof globalThis<"u"?globalThis:o||self,a(o.cristal_impl={},o.inversify,o.Comlink))})(this,function(o,a,f){"use strict";function g(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const u=g(f);function h(e){return new SharedWorker("/assets/worker-
|
|
1
|
+
(function(o,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("inversify"),require("comlink")):typeof define=="function"&&define.amd?define(["exports","inversify","comlink"],a):(o=typeof globalThis<"u"?globalThis:o||self,a(o.cristal_impl={},o.inversify,o.Comlink))})(this,function(o,a,f){"use strict";function g(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const u=g(f);function h(e){return new SharedWorker("/assets/worker-Beh36sMF.js",{name:e==null?void 0:e.name})}var w=Object.defineProperty,k=Object.getOwnPropertyDescriptor,p=(e,r,t,n)=>{for(var s=n>1?void 0:n?k(r,t):r,i=e.length-1,c;i>=0;i--)(c=e[i])&&(s=(n?c(r,t,s):c(s))||s);return n&&s&&w(r,t,s),s},d=(e,r)=>(t,n)=>r(t,n,e);let l=class{constructor(e,r){this.initialize(),this.logger=e,this.cristalApp=r}pageLoaded(e){try{this.logger.debug("Received callback that new document has been loaded",e),this.cristalApp.loadPage({requeue:!1}),this.logger.debug("Done callback that new document has been loaded",e)}catch(r){this.logger.error("Error calling loadPage",r)}}initialize(){try{if(this.workerInstance==null){const e=new h({name:"cristal-sharedworker"});this.workerInstance=u.wrap(e.port);const r=this;this.workerInstance.setPageLoadedCallback(u.proxy(function(t){r.pageLoaded(t)})),console.debug("Worker initialized",this.workerInstance)}else console.debug("Already initialized")}catch(e){console.error("Failed to initialize shared worker",e)}}getStatus(){return this.workerInstance!=null?(console.log("workerInstance is ready"),!0):(console.log("workerInstance is null. Cannot call"),!1)}async increment(){if(this.workerInstance==null)return console.log("workerInstance is null. Cannot call"),-1;{const e=await this.workerInstance.add(1);return console.log("Results from shared worker: ",e),e}}async addToQueue(e){console.log("worker Calling addToQueue",e),this.workerInstance!=null?await this.workerInstance.addToQueue(e):console.log("workerInstance is null. Cannot call")}async getQueueSize(){return console.log("worker Calling getQueueSize"),this.workerInstance==null?-1:await this.workerInstance.getQueueSize()}};l=p([a.injectable(),d(0,a.inject("Logger")),d(1,a.inject("CristalApp"))],l);class m{constructor(r){r.bind("QueueWorker").to(l)}}o.ComponentInit=m,Object.defineProperty(o,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/components/defaultQueueWorker.ts","../src/components/componentsInit.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 { inject, injectable } from \"inversify\";\nimport type { MyWorker, QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport * as Comlink from \"comlink\";\nimport Worker from \"./worker?sharedworker\";\nimport { type CristalApp, type Logger } from \"@xwiki/cristal-api\";\n\n@injectable()\nexport default class DefaultQueueWorker implements QueueWorker {\n // TODO remove use of any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private workerInstance: any;\n private cristalApp: CristalApp;\n private logger: Logger;\n\n public constructor(\n @inject<Logger>(\"Logger\") logger: Logger,\n @inject<CristalApp>(\"CristalApp\") cristalApp: CristalApp,\n ) {\n this.initialize();\n this.logger = logger;\n this.cristalApp = cristalApp;\n }\n\n public pageLoaded(page: string): void {\n try {\n this.logger.debug(\n \"Received callback that new document has been loaded\",\n page,\n );\n // When reloading the page for the worker, prevents a requeue to avoid\n // an endless re-fetch of the current page.\n this.cristalApp.loadPage({\n requeue: false,\n });\n this.logger.debug(\n \"Done callback that new document has been loaded\",\n page,\n );\n } catch (e) {\n this.logger.error(\"Error calling loadPage\", e);\n }\n }\n\n public initialize(): void {\n try {\n if (this.workerInstance == null) {\n // this.workerInstance = new ComlinkWorker<typeof import('./worker')>(new URL('./worker',\n // import.meta.url), {/* normal Worker options*/})\n const sworker = new Worker();\n this.workerInstance = Comlink.wrap<MyWorker>(sworker.port);\n // TODO get rid of aliasing\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const that = this;\n this.workerInstance.setPageLoadedCallback(\n Comlink.proxy(function (page: string) {\n that.pageLoaded(page);\n }),\n );\n\n console.debug(\"Worker initialized\", this.workerInstance);\n } else {\n console.debug(\"Already initialized\");\n }\n } catch (e) {\n console.error(\"Failed to initialize shared worker\", e);\n }\n }\n\n public getStatus(): boolean {\n if (this.workerInstance != null) {\n console.log(\"workerInstance is ready\");\n return true;\n } else {\n console.log(\"workerInstance is null. Cannot call\");\n return false;\n }\n }\n\n public async increment(): Promise<number> {\n if (this.workerInstance == null) {\n console.log(\"workerInstance is null. Cannot call\");\n return -1;\n } else {\n const result = await this.workerInstance.add(1);\n console.log(\"Results from shared worker: \", result);\n return result;\n }\n }\n\n public async addToQueue(page: string): Promise<void> {\n console.log(\"worker Calling addToQueue\", page);\n if (this.workerInstance != null) {\n await this.workerInstance.addToQueue(page);\n } else {\n console.log(\"workerInstance is null. Cannot call\");\n }\n }\n\n public async getQueueSize(): Promise<number> {\n console.log(\"worker Calling getQueueSize\");\n if (this.workerInstance == null) return -1;\n else return await this.workerInstance.getQueueSize();\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 { Container } from \"inversify\";\nimport type { QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport DefaultQueueWorker from \"./defaultQueueWorker\";\n\nexport default class ComponentInit {\n constructor(container: Container) {\n container.bind<QueueWorker>(\"QueueWorker\").to(DefaultQueueWorker);\n }\n}\n"],"names":["DefaultQueueWorker","logger","cristalApp","page","e","sworker","Worker","Comlink","that","result","__decorateClass","injectable","__decorateParam","ComponentInit","container"],"mappings":"g5BA2BA,IAAqBA,EAArB,KAA+D,CAOtD,YACqBC,EACQC,EAClC,CACA,KAAK,WAAW,EAChB,KAAK,OAASD,EACd,KAAK,WAAaC,CACpB,CAEO,WAAWC,EAAoB,CAChC,GAAA,CACF,KAAK,OAAO,MACV,sDACAA,CAAA,EAIF,KAAK,WAAW,SAAS,CACvB,QAAS,EAAA,CACV,EACD,KAAK,OAAO,MACV,kDACAA,CAAA,QAEKC,EAAG,CACL,KAAA,OAAO,MAAM,yBAA0BA,CAAC,CAC/C,CACF,CAEO,YAAmB,CACpB,GAAA,CACE,GAAA,KAAK,gBAAkB,KAAM,CAGzB,MAAAC,EAAU,IAAIC,
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/components/defaultQueueWorker.ts","../src/components/componentsInit.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 { inject, injectable } from \"inversify\";\nimport type { MyWorker, QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport * as Comlink from \"comlink\";\nimport Worker from \"./worker?sharedworker\";\nimport { type CristalApp, type Logger } from \"@xwiki/cristal-api\";\n\n@injectable()\nexport default class DefaultQueueWorker implements QueueWorker {\n // TODO remove use of any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private workerInstance: any;\n private cristalApp: CristalApp;\n private logger: Logger;\n\n public constructor(\n @inject<Logger>(\"Logger\") logger: Logger,\n @inject<CristalApp>(\"CristalApp\") cristalApp: CristalApp,\n ) {\n this.initialize();\n this.logger = logger;\n this.cristalApp = cristalApp;\n }\n\n public pageLoaded(page: string): void {\n try {\n this.logger.debug(\n \"Received callback that new document has been loaded\",\n page,\n );\n // When reloading the page for the worker, prevents a requeue to avoid\n // an endless re-fetch of the current page.\n this.cristalApp.loadPage({\n requeue: false,\n });\n this.logger.debug(\n \"Done callback that new document has been loaded\",\n page,\n );\n } catch (e) {\n this.logger.error(\"Error calling loadPage\", e);\n }\n }\n\n public initialize(): void {\n try {\n if (this.workerInstance == null) {\n // this.workerInstance = new ComlinkWorker<typeof import('./worker')>(new URL('./worker',\n // import.meta.url), {/* normal Worker options*/})\n const sworker = new Worker({\n name: \"cristal-sharedworker\",\n });\n this.workerInstance = Comlink.wrap<MyWorker>(sworker.port);\n // TODO get rid of aliasing\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const that = this;\n this.workerInstance.setPageLoadedCallback(\n Comlink.proxy(function (page: string) {\n that.pageLoaded(page);\n }),\n );\n\n console.debug(\"Worker initialized\", this.workerInstance);\n } else {\n console.debug(\"Already initialized\");\n }\n } catch (e) {\n console.error(\"Failed to initialize shared worker\", e);\n }\n }\n\n public getStatus(): boolean {\n if (this.workerInstance != null) {\n console.log(\"workerInstance is ready\");\n return true;\n } else {\n console.log(\"workerInstance is null. Cannot call\");\n return false;\n }\n }\n\n public async increment(): Promise<number> {\n if (this.workerInstance == null) {\n console.log(\"workerInstance is null. Cannot call\");\n return -1;\n } else {\n const result = await this.workerInstance.add(1);\n console.log(\"Results from shared worker: \", result);\n return result;\n }\n }\n\n public async addToQueue(page: string): Promise<void> {\n console.log(\"worker Calling addToQueue\", page);\n if (this.workerInstance != null) {\n await this.workerInstance.addToQueue(page);\n } else {\n console.log(\"workerInstance is null. Cannot call\");\n }\n }\n\n public async getQueueSize(): Promise<number> {\n console.log(\"worker Calling getQueueSize\");\n if (this.workerInstance == null) return -1;\n else return await this.workerInstance.getQueueSize();\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 { Container } from \"inversify\";\nimport type { QueueWorker } from \"@xwiki/cristal-sharedworker-api\";\nimport DefaultQueueWorker from \"./defaultQueueWorker\";\n\nexport default class ComponentInit {\n constructor(container: Container) {\n container.bind<QueueWorker>(\"QueueWorker\").to(DefaultQueueWorker);\n }\n}\n"],"names":["DefaultQueueWorker","logger","cristalApp","page","e","sworker","Worker","Comlink","that","result","__decorateClass","injectable","__decorateParam","ComponentInit","container"],"mappings":"g5BA2BA,IAAqBA,EAArB,KAA+D,CAOtD,YACqBC,EACQC,EAClC,CACA,KAAK,WAAW,EAChB,KAAK,OAASD,EACd,KAAK,WAAaC,CACpB,CAEO,WAAWC,EAAoB,CAChC,GAAA,CACF,KAAK,OAAO,MACV,sDACAA,CAAA,EAIF,KAAK,WAAW,SAAS,CACvB,QAAS,EAAA,CACV,EACD,KAAK,OAAO,MACV,kDACAA,CAAA,QAEKC,EAAG,CACL,KAAA,OAAO,MAAM,yBAA0BA,CAAC,CAC/C,CACF,CAEO,YAAmB,CACpB,GAAA,CACE,GAAA,KAAK,gBAAkB,KAAM,CAGzB,MAAAC,EAAU,IAAIC,EAAO,CACzB,KAAM,sBAAA,CACP,EACD,KAAK,eAAiBC,EAAQ,KAAeF,EAAQ,IAAI,EAGzD,MAAMG,EAAO,KACb,KAAK,eAAe,sBAClBD,EAAQ,MAAM,SAAUJ,EAAc,CACpCK,EAAK,WAAWL,CAAI,CAAA,CACrB,CAAA,EAGK,QAAA,MAAM,qBAAsB,KAAK,cAAc,CAAA,MAEvD,QAAQ,MAAM,qBAAqB,QAE9B,EAAG,CACF,QAAA,MAAM,qCAAsC,CAAC,CACvD,CACF,CAEO,WAAqB,CACtB,OAAA,KAAK,gBAAkB,MACzB,QAAQ,IAAI,yBAAyB,EAC9B,KAEP,QAAQ,IAAI,qCAAqC,EAC1C,GAEX,CAEA,MAAa,WAA6B,CACpC,GAAA,KAAK,gBAAkB,KACzB,eAAQ,IAAI,qCAAqC,EAC1C,GACF,CACL,MAAMM,EAAS,MAAM,KAAK,eAAe,IAAI,CAAC,EACtC,eAAA,IAAI,+BAAgCA,CAAM,EAC3CA,CACT,CACF,CAEA,MAAa,WAAWN,EAA6B,CAC3C,QAAA,IAAI,4BAA6BA,CAAI,EACzC,KAAK,gBAAkB,KACnB,MAAA,KAAK,eAAe,WAAWA,CAAI,EAEzC,QAAQ,IAAI,qCAAqC,CAErD,CAEA,MAAa,cAAgC,CAEvC,OADJ,QAAQ,IAAI,6BAA6B,EACrC,KAAK,gBAAkB,KAAa,GAC5B,MAAM,KAAK,eAAe,cACxC,CACF,EAlGqBH,EAArBU,EAAA,CADCC,aAAW,EASPC,aAAe,QAAQ,CAAA,EACvBA,aAAmB,YAAY,CAAA,CAAA,EATfZ,CAAA,ECHrB,MAAqBa,CAAc,CACjC,YAAYC,EAAsB,CAChCA,EAAU,KAAkB,aAAa,EAAE,GAAGd,CAAkB,CAClE,CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xwiki/cristal-sharedworker-impl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"license": "LGPL 2.1",
|
|
5
5
|
"author": "XWiki Org Community <contact@xwiki.org>",
|
|
6
6
|
"homepage": "https://cristal.xwiki.org/",
|
|
@@ -25,20 +25,19 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"comlink": "4.4.1",
|
|
27
27
|
"inversify": "6.0.2",
|
|
28
|
-
"vue": "3.4.
|
|
29
|
-
"vue-router": "4.
|
|
30
|
-
"@xwiki/cristal-api": "0.
|
|
31
|
-
"@xwiki/cristal-backend-dexie": "0.
|
|
32
|
-
"@xwiki/cristal-backend-github": "0.
|
|
33
|
-
"@xwiki/cristal-backend-
|
|
34
|
-
"@xwiki/cristal-backend-
|
|
35
|
-
"@xwiki/cristal-extension-manager": "0.
|
|
36
|
-
"@xwiki/cristal-sharedworker-api": "0.
|
|
28
|
+
"vue": "3.4.31",
|
|
29
|
+
"vue-router": "4.4.0",
|
|
30
|
+
"@xwiki/cristal-api": "0.10.0",
|
|
31
|
+
"@xwiki/cristal-backend-dexie": "0.10.0",
|
|
32
|
+
"@xwiki/cristal-backend-github": "0.10.0",
|
|
33
|
+
"@xwiki/cristal-backend-nextcloud": "0.10.0",
|
|
34
|
+
"@xwiki/cristal-backend-xwiki": "0.10.0",
|
|
35
|
+
"@xwiki/cristal-extension-manager": "0.10.0",
|
|
36
|
+
"@xwiki/cristal-sharedworker-api": "0.10.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"rimraf": "5.0.7",
|
|
40
39
|
"vite-plugin-comlink": "4.1.0",
|
|
41
|
-
"vue-tsc": "2.0.
|
|
40
|
+
"vue-tsc": "2.0.22"
|
|
42
41
|
},
|
|
43
42
|
"scripts": {
|
|
44
43
|
"build": "pnpm compile",
|
|
@@ -66,7 +66,9 @@ export default class DefaultQueueWorker implements QueueWorker {
|
|
|
66
66
|
if (this.workerInstance == null) {
|
|
67
67
|
// this.workerInstance = new ComlinkWorker<typeof import('./worker')>(new URL('./worker',
|
|
68
68
|
// import.meta.url), {/* normal Worker options*/})
|
|
69
|
-
const sworker = new Worker(
|
|
69
|
+
const sworker = new Worker({
|
|
70
|
+
name: "cristal-sharedworker",
|
|
71
|
+
});
|
|
70
72
|
this.workerInstance = Comlink.wrap<MyWorker>(sworker.port);
|
|
71
73
|
// TODO get rid of aliasing
|
|
72
74
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
package/src/components/worker.ts
CHANGED
|
@@ -34,10 +34,18 @@ import WorkerQueueWorker from "./workerQueueWorker";
|
|
|
34
34
|
export class Worker implements MyWorker {
|
|
35
35
|
private currentNumber: number = 0;
|
|
36
36
|
private queue: Array<string> = [];
|
|
37
|
+
// @ts-expect-error container is temporarily undefined during class
|
|
38
|
+
// initialization
|
|
37
39
|
private container: Container;
|
|
40
|
+
// @ts-expect-error cristal is temporarily undefined during class
|
|
41
|
+
// initialization
|
|
38
42
|
private cristal: CristalApp;
|
|
43
|
+
// @ts-expect-error configMap is temporarily undefined during class
|
|
44
|
+
// initialization
|
|
39
45
|
private configMap: Map<string, object>;
|
|
40
46
|
private initialized: boolean = false;
|
|
47
|
+
// @ts-expect-error fct is temporarily undefined during class
|
|
48
|
+
// initialization
|
|
41
49
|
private fct: (a: string) => void;
|
|
42
50
|
|
|
43
51
|
/*
|
|
@@ -33,7 +33,11 @@ import type { Router } from "vue-router";
|
|
|
33
33
|
|
|
34
34
|
@injectable()
|
|
35
35
|
export class WorkerCristalApp implements CristalApp {
|
|
36
|
+
// @ts-expect-error wikiConfig is temporarily undefined during class
|
|
37
|
+
// initialization
|
|
36
38
|
private wikiConfig: WikiConfig;
|
|
39
|
+
// @ts-expect-error container is temporarily undefined during class
|
|
40
|
+
// initialization
|
|
37
41
|
private container: Container;
|
|
38
42
|
private availableConfigurations: Map<string, WikiConfig>;
|
|
39
43
|
|