@xwiki/cristal-sharedworker-impl 0.9.0 → 0.11.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 +36 -0
- package/dist/assets/worker-DhHDiwPg.js +47 -0
- package/dist/assets/worker-DhHDiwPg.js.map +1 -0
- package/dist/components/componentsInit.d.ts +0 -1
- package/dist/components/defaultQueueWorker.d.ts +0 -1
- package/dist/components/worker.d.ts +0 -1
- package/dist/components/workerCristalApp.d.ts +0 -1
- package/dist/components/workerQueueWorker.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.es.js +20 -19
- 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 +15 -15
- package/src/components/defaultQueueWorker.ts +14 -6
- package/src/components/worker.ts +12 -3
- package/src/components/workerCristalApp.ts +4 -0
- package/dist/assets/worker-CSpj1p6r.js +0 -47
- package/dist/assets/worker-CSpj1p6r.js.map +0 -1
- package/src/vite-env.d.ts +0 -22
- package/src/vue.d.ts +0 -27
- package/vite-env.d.ts +0 -21
|
@@ -2,7 +2,6 @@ import { CristalApp as CristalApp, Logger, LoggerConfig, PageData, SkinManager,
|
|
|
2
2
|
import { Container } from 'inversify';
|
|
3
3
|
import { App, Component } from 'vue';
|
|
4
4
|
import { Router } from 'vue-router';
|
|
5
|
-
|
|
6
5
|
export declare class WorkerCristalApp implements CristalApp {
|
|
7
6
|
private wikiConfig;
|
|
8
7
|
private container;
|
package/dist/index.d.ts
CHANGED
package/dist/index.es.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { injectable as d, inject as i } from "inversify";
|
|
2
2
|
import * as c from "comlink";
|
|
3
|
-
|
|
3
|
+
import { name as g } from "@xwiki/cristal-document-api";
|
|
4
|
+
function h(e) {
|
|
4
5
|
return new SharedWorker(
|
|
5
|
-
"/assets/worker-
|
|
6
|
+
"/assets/worker-DhHDiwPg.js",
|
|
6
7
|
{
|
|
7
8
|
name: e == null ? void 0 : e.name
|
|
8
9
|
}
|
|
9
10
|
);
|
|
10
11
|
}
|
|
11
|
-
var w = Object.defineProperty,
|
|
12
|
-
for (var
|
|
13
|
-
(
|
|
14
|
-
return o &&
|
|
15
|
-
}, u = (e, r) => (
|
|
16
|
-
let
|
|
12
|
+
var w = Object.defineProperty, k = Object.getOwnPropertyDescriptor, m = (e, r, t, o) => {
|
|
13
|
+
for (var n = o > 1 ? void 0 : o ? k(r, t) : r, a = e.length - 1, s; a >= 0; a--)
|
|
14
|
+
(s = e[a]) && (n = (o ? s(r, t, n) : s(n)) || n);
|
|
15
|
+
return o && n && w(r, t, n), n;
|
|
16
|
+
}, u = (e, r) => (t, o) => r(t, o, e);
|
|
17
|
+
let l = class {
|
|
17
18
|
constructor(e, r) {
|
|
18
19
|
this.initialize(), this.logger = e, this.cristalApp = r;
|
|
19
20
|
}
|
|
@@ -22,9 +23,7 @@ let s = class {
|
|
|
22
23
|
this.logger.debug(
|
|
23
24
|
"Received callback that new document has been loaded",
|
|
24
25
|
e
|
|
25
|
-
), this.cristalApp.
|
|
26
|
-
requeue: !1
|
|
27
|
-
}), this.logger.debug(
|
|
26
|
+
), this.cristalApp.getContainer().get(g).refreshCurrentDocument(), this.logger.debug(
|
|
28
27
|
"Done callback that new document has been loaded",
|
|
29
28
|
e
|
|
30
29
|
);
|
|
@@ -35,12 +34,14 @@ let s = class {
|
|
|
35
34
|
initialize() {
|
|
36
35
|
try {
|
|
37
36
|
if (this.workerInstance == null) {
|
|
38
|
-
const e = new
|
|
37
|
+
const e = new h({
|
|
38
|
+
name: "cristal-sharedworker"
|
|
39
|
+
});
|
|
39
40
|
this.workerInstance = c.wrap(e.port);
|
|
40
41
|
const r = this;
|
|
41
42
|
this.workerInstance.setPageLoadedCallback(
|
|
42
|
-
c.proxy(function(
|
|
43
|
-
r.pageLoaded(
|
|
43
|
+
c.proxy(function(t) {
|
|
44
|
+
r.pageLoaded(t);
|
|
44
45
|
})
|
|
45
46
|
), console.debug("Worker initialized", this.workerInstance);
|
|
46
47
|
} else
|
|
@@ -67,17 +68,17 @@ let s = class {
|
|
|
67
68
|
return console.log("worker Calling getQueueSize"), this.workerInstance == null ? -1 : await this.workerInstance.getQueueSize();
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
|
-
|
|
71
|
+
l = m([
|
|
71
72
|
d(),
|
|
72
73
|
u(0, i("Logger")),
|
|
73
74
|
u(1, i("CristalApp"))
|
|
74
|
-
],
|
|
75
|
-
class
|
|
75
|
+
], l);
|
|
76
|
+
class I {
|
|
76
77
|
constructor(r) {
|
|
77
|
-
r.bind("QueueWorker").to(
|
|
78
|
+
r.bind("QueueWorker").to(l);
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
export {
|
|
81
|
-
|
|
82
|
+
I as ComponentInit
|
|
82
83
|
};
|
|
83
84
|
//# sourceMappingURL=index.es.js.map
|
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 //
|
|
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\";\nimport {\n type DocumentService,\n name as documentServiceName,\n} from \"@xwiki/cristal-document-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 // We need to access the DocumentService lasily as otherwise the\n // internal pinia instance is initialized too early.\n const documentService = this.cristalApp\n .getContainer()\n .get<DocumentService>(documentServiceName);\n documentService.refreshCurrentDocument();\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","documentServiceName","e","sworker","Worker","Comlink","that","result","__decorateClass","injectable","__decorateParam","ComponentInit","container"],"mappings":";;;;;;;;;;;;;;;;AA+BA,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,GAIsB,KAAK,WAC1B,aAAa,EACb,IAAqBC,CAAmB,EAC3B,uBAAuB,GAEvC,KAAK,OAAO;AAAA,QACV;AAAA,QACAD;AAAA,MAAA;AAAA,aAEKE,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,SAAUL,GAAc;AACpC,YAAAM,EAAK,WAAWN,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,YAAMO,IAAS,MAAM,KAAK,eAAe,IAAI,CAAC;AACtC,qBAAA,IAAI,gCAAgCA,CAAM,GAC3CA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAa,WAAWP,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;AApGqBH,IAArBW,EAAA;AAAA,EADCC,EAAW;AAAA,EASPC,OAAe,QAAQ,CAAA;AAAA,EACvBA,OAAmB,YAAY,CAAA;AAAA,GATfb,CAAA;ACPrB,MAAqBc,EAAc;AAAA,EACjC,YAAYC,GAAsB;AAChC,IAAAA,EAAU,KAAkB,aAAa,EAAE,GAAGf,CAAkB;AAAA,EAClE;AACF;"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("inversify"),require("comlink"),require("@xwiki/cristal-document-api")):typeof define=="function"&&define.amd?define(["exports","inversify","comlink","@xwiki/cristal-document-api"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.cristal_impl={},n.inversify,n.Comlink,n.cristalDocumentApi))})(this,function(n,i,f,g){"use strict";function h(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const u=h(f);function w(e){return new SharedWorker("/assets/worker-DhHDiwPg.js",{name:e==null?void 0:e.name})}var k=Object.defineProperty,p=Object.getOwnPropertyDescriptor,m=(e,r,t,o)=>{for(var a=o>1?void 0:o?p(r,t):r,l=e.length-1,c;l>=0;l--)(c=e[l])&&(a=(o?c(r,t,a):c(a))||a);return o&&a&&k(r,t,a),a},d=(e,r)=>(t,o)=>r(t,o,e);let s=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.getContainer().get(g.name).refreshCurrentDocument(),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 w({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()}};s=m([i.injectable(),d(0,i.inject("Logger")),d(1,i.inject("CristalApp"))],s);class b{constructor(r){r.bind("QueueWorker").to(s)}}n.ComponentInit=b,Object.defineProperty(n,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 //
|
|
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\";\nimport {\n type DocumentService,\n name as documentServiceName,\n} from \"@xwiki/cristal-document-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 // We need to access the DocumentService lasily as otherwise the\n // internal pinia instance is initialized too early.\n const documentService = this.cristalApp\n .getContainer()\n .get<DocumentService>(documentServiceName);\n documentService.refreshCurrentDocument();\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","documentServiceName","e","sworker","Worker","Comlink","that","result","__decorateClass","injectable","__decorateParam","ComponentInit","container"],"mappings":"4+BA+BA,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,EAIsB,KAAK,WAC1B,aAAa,EACb,IAAqBC,EAAAA,IAAmB,EAC3B,uBAAuB,EAEvC,KAAK,OAAO,MACV,kDACAD,CAAA,QAEKE,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,SAAUL,EAAc,CACpCM,EAAK,WAAWN,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,MAAMO,EAAS,MAAM,KAAK,eAAe,IAAI,CAAC,EACtC,eAAA,IAAI,+BAAgCA,CAAM,EAC3CA,CACT,CACF,CAEA,MAAa,WAAWP,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,EApGqBH,EAArBW,EAAA,CADCC,aAAW,EASPC,aAAe,QAAQ,CAAA,EACvBA,aAAmB,YAAY,CAAA,CAAA,EATfb,CAAA,ECPrB,MAAqBc,CAAc,CACjC,YAAYC,EAAsB,CAChCA,EAAU,KAAkB,aAAa,EAAE,GAAGf,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.11.0",
|
|
4
4
|
"license": "LGPL 2.1",
|
|
5
5
|
"author": "XWiki Org Community <contact@xwiki.org>",
|
|
6
6
|
"homepage": "https://cristal.xwiki.org/",
|
|
@@ -25,26 +25,26 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"comlink": "4.4.1",
|
|
27
27
|
"inversify": "6.0.2",
|
|
28
|
-
"vue": "3.
|
|
29
|
-
"vue-router": "4.
|
|
30
|
-
"@xwiki/cristal-api": "0.
|
|
31
|
-
"@xwiki/cristal-
|
|
32
|
-
"@xwiki/cristal-backend-github": "0.
|
|
33
|
-
"@xwiki/cristal-backend-
|
|
34
|
-
"@xwiki/cristal-backend-
|
|
35
|
-
"@xwiki/cristal-
|
|
36
|
-
"@xwiki/cristal-
|
|
28
|
+
"vue": "3.5.12",
|
|
29
|
+
"vue-router": "4.4.5",
|
|
30
|
+
"@xwiki/cristal-api": "0.11.0",
|
|
31
|
+
"@xwiki/cristal-authentication-api": "0.11.0",
|
|
32
|
+
"@xwiki/cristal-backend-github": "0.11.0",
|
|
33
|
+
"@xwiki/cristal-backend-nextcloud": "0.11.0",
|
|
34
|
+
"@xwiki/cristal-backend-dexie": "0.11.0",
|
|
35
|
+
"@xwiki/cristal-backend-xwiki": "0.11.0",
|
|
36
|
+
"@xwiki/cristal-document-api": "0.11.0",
|
|
37
|
+
"@xwiki/cristal-extension-manager": "0.11.0",
|
|
38
|
+
"@xwiki/cristal-sharedworker-api": "0.11.0"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"vue-tsc": "2.0.21"
|
|
41
|
+
"vite-plugin-comlink": "5.0.1",
|
|
42
|
+
"vue-tsc": "2.1.6"
|
|
42
43
|
},
|
|
43
44
|
"scripts": {
|
|
44
45
|
"build": "pnpm compile",
|
|
45
46
|
"clean": "rimraf dist",
|
|
46
47
|
"compile": "vue-tsc --project tsconfig.json && vite build",
|
|
47
|
-
"lint": "eslint \"./src/**/*.{ts,tsx}\" --max-warnings=0"
|
|
48
|
-
"test": "echo 'no test'"
|
|
48
|
+
"lint": "eslint \"./src/**/*.{ts,tsx}\" --max-warnings=0"
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -23,6 +23,10 @@ import type { MyWorker, QueueWorker } from "@xwiki/cristal-sharedworker-api";
|
|
|
23
23
|
import * as Comlink from "comlink";
|
|
24
24
|
import Worker from "./worker?sharedworker";
|
|
25
25
|
import { type CristalApp, type Logger } from "@xwiki/cristal-api";
|
|
26
|
+
import {
|
|
27
|
+
type DocumentService,
|
|
28
|
+
name as documentServiceName,
|
|
29
|
+
} from "@xwiki/cristal-document-api";
|
|
26
30
|
|
|
27
31
|
@injectable()
|
|
28
32
|
export default class DefaultQueueWorker implements QueueWorker {
|
|
@@ -47,11 +51,13 @@ export default class DefaultQueueWorker implements QueueWorker {
|
|
|
47
51
|
"Received callback that new document has been loaded",
|
|
48
52
|
page,
|
|
49
53
|
);
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
this.cristalApp
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
// We need to access the DocumentService lasily as otherwise the
|
|
55
|
+
// internal pinia instance is initialized too early.
|
|
56
|
+
const documentService = this.cristalApp
|
|
57
|
+
.getContainer()
|
|
58
|
+
.get<DocumentService>(documentServiceName);
|
|
59
|
+
documentService.refreshCurrentDocument();
|
|
60
|
+
|
|
55
61
|
this.logger.debug(
|
|
56
62
|
"Done callback that new document has been loaded",
|
|
57
63
|
page,
|
|
@@ -66,7 +72,9 @@ export default class DefaultQueueWorker implements QueueWorker {
|
|
|
66
72
|
if (this.workerInstance == null) {
|
|
67
73
|
// this.workerInstance = new ComlinkWorker<typeof import('./worker')>(new URL('./worker',
|
|
68
74
|
// import.meta.url), {/* normal Worker options*/})
|
|
69
|
-
const sworker = new Worker(
|
|
75
|
+
const sworker = new Worker({
|
|
76
|
+
name: "cristal-sharedworker",
|
|
77
|
+
});
|
|
70
78
|
this.workerInstance = Comlink.wrap<MyWorker>(sworker.port);
|
|
71
79
|
// TODO get rid of aliasing
|
|
72
80
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
package/src/components/worker.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { ComponentInit as DexieBackendComponentInit } from "@xwiki/cristal-backe
|
|
|
27
27
|
import { ComponentInit as GithubBackendComponentInit } from "@xwiki/cristal-backend-github";
|
|
28
28
|
import { ComponentInit as NextcloudBackendComponentInit } from "@xwiki/cristal-backend-nextcloud";
|
|
29
29
|
import { ComponentInit as XWikiBackendComponentInit } from "@xwiki/cristal-backend-xwiki";
|
|
30
|
+
import { ComponentInit as AuthenticationAPIComponentInit } from "@xwiki/cristal-authentication-api";
|
|
30
31
|
import type { Container } from "inversify";
|
|
31
32
|
import { WorkerCristalApp } from "./workerCristalApp";
|
|
32
33
|
import WorkerQueueWorker from "./workerQueueWorker";
|
|
@@ -34,10 +35,18 @@ import WorkerQueueWorker from "./workerQueueWorker";
|
|
|
34
35
|
export class Worker implements MyWorker {
|
|
35
36
|
private currentNumber: number = 0;
|
|
36
37
|
private queue: Array<string> = [];
|
|
38
|
+
// @ts-expect-error container is temporarily undefined during class
|
|
39
|
+
// initialization
|
|
37
40
|
private container: Container;
|
|
41
|
+
// @ts-expect-error cristal is temporarily undefined during class
|
|
42
|
+
// initialization
|
|
38
43
|
private cristal: CristalApp;
|
|
44
|
+
// @ts-expect-error configMap is temporarily undefined during class
|
|
45
|
+
// initialization
|
|
39
46
|
private configMap: Map<string, object>;
|
|
40
47
|
private initialized: boolean = false;
|
|
48
|
+
// @ts-expect-error fct is temporarily undefined during class
|
|
49
|
+
// initialization
|
|
41
50
|
private fct: (a: string) => void;
|
|
42
51
|
|
|
43
52
|
/*
|
|
@@ -45,11 +54,10 @@ export class Worker implements MyWorker {
|
|
|
45
54
|
*/
|
|
46
55
|
public async start(): Promise<void> {
|
|
47
56
|
console.log("Starting worker thread");
|
|
48
|
-
this.initialize();
|
|
49
|
-
// eslint-disable-next-line no-constant-condition
|
|
57
|
+
await this.initialize();
|
|
50
58
|
while (true) {
|
|
51
59
|
await this.sleep(1000);
|
|
52
|
-
this.checkQueue();
|
|
60
|
+
await this.checkQueue();
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
|
|
@@ -210,6 +218,7 @@ export class Worker implements MyWorker {
|
|
|
210
218
|
new GithubBackendComponentInit(cristalLoader.container);
|
|
211
219
|
new NextcloudBackendComponentInit(cristalLoader.container);
|
|
212
220
|
new XWikiBackendComponentInit(cristalLoader.container);
|
|
221
|
+
new AuthenticationAPIComponentInit(cristalLoader.container);
|
|
213
222
|
console.log("Loading storage components");
|
|
214
223
|
this.initialized = true;
|
|
215
224
|
console.log("Finished initialize");
|
|
@@ -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
|
|