@xwiki/cristal-sharedworker-impl 0.8.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 +29 -0
- package/LICENSE +505 -0
- package/dist/assets/worker-D2exZhnK.js +231 -0
- package/dist/assets/worker-D2exZhnK.js.map +1 -0
- package/dist/components/componentsInit.d.ts +5 -0
- package/dist/components/defaultQueueWorker.d.ts +15 -0
- package/dist/components/worker.d.ts +22 -0
- package/dist/components/workerCristalApp.d.ts +36 -0
- package/dist/components/workerQueueWorker.d.ts +10 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.es.js +107 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +25 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +49 -0
- package/src/components/componentsInit.ts +34 -0
- package/src/components/defaultQueueWorker.ts +129 -0
- package/src/components/worker.ts +225 -0
- package/src/components/workerCristalApp.ts +146 -0
- package/src/components/workerQueueWorker.ts +50 -0
- package/src/index.ts +29 -0
- package/src/vite-env.d.ts +27 -0
- package/src/vue.d.ts +32 -0
- package/tsconfig.json +10 -0
- package/vite-env.d.ts +26 -0
- package/vite.config.ts +38 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { QueueWorker } from '@xwiki/cristal-sharedworker-api';
|
|
2
|
+
import { CristalApp, Logger } from '@xwiki/cristal-api';
|
|
3
|
+
|
|
4
|
+
export default class DefaultQueueWorker implements QueueWorker {
|
|
5
|
+
private workerInstance;
|
|
6
|
+
private cristalApp;
|
|
7
|
+
private logger;
|
|
8
|
+
constructor(logger: Logger, cristalApp: CristalApp);
|
|
9
|
+
pageLoaded(page: string): void;
|
|
10
|
+
initialize(): void;
|
|
11
|
+
getStatus(): boolean;
|
|
12
|
+
increment(): Promise<number>;
|
|
13
|
+
addToQueue(page: string): Promise<void>;
|
|
14
|
+
getQueueSize(): Promise<number>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MyWorker } from '@xwiki/cristal-sharedworker-api';
|
|
2
|
+
import { WikiConfig } from '@xwiki/cristal-api';
|
|
3
|
+
|
|
4
|
+
export declare class Worker implements MyWorker {
|
|
5
|
+
private currentNumber;
|
|
6
|
+
private queue;
|
|
7
|
+
private container;
|
|
8
|
+
private cristal;
|
|
9
|
+
private configMap;
|
|
10
|
+
private initialized;
|
|
11
|
+
private fct;
|
|
12
|
+
start(): Promise<void>;
|
|
13
|
+
setPageLoadedCallback(fct: (a: string) => void): void;
|
|
14
|
+
sleep(ms: number): Promise<unknown>;
|
|
15
|
+
checkQueue(): Promise<void>;
|
|
16
|
+
handleQueueItem(page: string): Promise<void>;
|
|
17
|
+
add(a: number): number;
|
|
18
|
+
addToQueue(page: string): void;
|
|
19
|
+
getQueueSize(): number;
|
|
20
|
+
getWikiConfig(configName: string): WikiConfig | undefined;
|
|
21
|
+
initialize(): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CristalApp as CristalApp, Logger, LoggerConfig, PageData, SkinManager, WikiConfig } from '@xwiki/cristal-api';
|
|
2
|
+
import { Container } from 'inversify';
|
|
3
|
+
import { App, Component } from 'vue';
|
|
4
|
+
import { Router } from 'vue-router';
|
|
5
|
+
|
|
6
|
+
export declare class WorkerCristalApp implements CristalApp {
|
|
7
|
+
private wikiConfig;
|
|
8
|
+
private container;
|
|
9
|
+
private availableConfigurations;
|
|
10
|
+
constructor();
|
|
11
|
+
getApp(): App;
|
|
12
|
+
getRouter(): Router;
|
|
13
|
+
getContainer(): Container;
|
|
14
|
+
setContainer(container: Container): void;
|
|
15
|
+
getWikiConfig(): WikiConfig;
|
|
16
|
+
setWikiConfig(wikiConfig: WikiConfig): void;
|
|
17
|
+
getSkinManager(): SkinManager;
|
|
18
|
+
switchConfig(): void;
|
|
19
|
+
setAvailableConfigurations(config: Map<string, any>): void;
|
|
20
|
+
getAvailableConfigurations(): Map<string, WikiConfig>;
|
|
21
|
+
run(): Promise<void>;
|
|
22
|
+
getUIXTemplates(): Component[];
|
|
23
|
+
getMenuEntries(): string[];
|
|
24
|
+
getCurrentPage(): string;
|
|
25
|
+
getCurrentContent(): string;
|
|
26
|
+
getCurrentSource(): string;
|
|
27
|
+
getCurrentSyntax(): string;
|
|
28
|
+
setCurrentPage(): void;
|
|
29
|
+
setContentRef(): void;
|
|
30
|
+
loadPageFromURL(): Promise<void>;
|
|
31
|
+
loadPage(): Promise<void>;
|
|
32
|
+
getPage(): Promise<PageData>;
|
|
33
|
+
getLogger(): Logger;
|
|
34
|
+
getLoggerConfig(): LoggerConfig;
|
|
35
|
+
renderContent(): Promise<string>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { QueueWorker } from '@xwiki/cristal-sharedworker-api';
|
|
2
|
+
|
|
3
|
+
export default class WorkerQueueWorker implements QueueWorker {
|
|
4
|
+
constructor();
|
|
5
|
+
initialize(): void;
|
|
6
|
+
getStatus(): boolean;
|
|
7
|
+
increment(): Promise<number>;
|
|
8
|
+
addToQueue(): Promise<void>;
|
|
9
|
+
getQueueSize(): Promise<number>;
|
|
10
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { injectable as d, inject as i } from "inversify";
|
|
2
|
+
import * as c from "comlink";
|
|
3
|
+
function g(e) {
|
|
4
|
+
return new SharedWorker(
|
|
5
|
+
"/assets/worker-D2exZhnK.js",
|
|
6
|
+
{
|
|
7
|
+
name: e == null ? void 0 : e.name
|
|
8
|
+
}
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
var h = Object.defineProperty, w = Object.getOwnPropertyDescriptor, k = (e, r, n, o) => {
|
|
12
|
+
for (var t = o > 1 ? void 0 : o ? w(r, n) : r, a = e.length - 1, l; a >= 0; a--)
|
|
13
|
+
(l = e[a]) && (t = (o ? l(r, n, t) : l(t)) || t);
|
|
14
|
+
return o && t && h(r, n, t), t;
|
|
15
|
+
}, u = (e, r) => (n, o) => r(n, o, e);
|
|
16
|
+
let s = class {
|
|
17
|
+
constructor(e, r) {
|
|
18
|
+
this.initialize(), this.logger = e, this.cristalApp = r;
|
|
19
|
+
}
|
|
20
|
+
pageLoaded(e) {
|
|
21
|
+
try {
|
|
22
|
+
this.logger.debug(
|
|
23
|
+
"Received callback that new document has been loaded",
|
|
24
|
+
e
|
|
25
|
+
), this.cristalApp.loadPage({
|
|
26
|
+
requeue: !1
|
|
27
|
+
}), this.logger.debug(
|
|
28
|
+
"Done callback that new document has been loaded",
|
|
29
|
+
e
|
|
30
|
+
);
|
|
31
|
+
} catch (r) {
|
|
32
|
+
this.logger.error("Error calling loadPage", r);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
initialize() {
|
|
36
|
+
try {
|
|
37
|
+
if (this.workerInstance == null) {
|
|
38
|
+
const e = new g();
|
|
39
|
+
this.workerInstance = c.wrap(e.port);
|
|
40
|
+
const r = this;
|
|
41
|
+
this.workerInstance.setPageLoadedCallback(
|
|
42
|
+
c.proxy(function(n) {
|
|
43
|
+
r.pageLoaded(n);
|
|
44
|
+
})
|
|
45
|
+
), console.debug("Worker initialized", this.workerInstance);
|
|
46
|
+
} else
|
|
47
|
+
console.debug("Already initialized");
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.error("Failed to initialize shared worker", e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
getStatus() {
|
|
53
|
+
return this.workerInstance != null ? (console.log("workerInstance is ready"), !0) : (console.log("workerInstance is null. Cannot call"), !1);
|
|
54
|
+
}
|
|
55
|
+
async increment() {
|
|
56
|
+
if (this.workerInstance == null)
|
|
57
|
+
return console.log("workerInstance is null. Cannot call"), -1;
|
|
58
|
+
{
|
|
59
|
+
const e = await this.workerInstance.add(1);
|
|
60
|
+
return console.log("Results from shared worker: ", e), e;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async addToQueue(e) {
|
|
64
|
+
console.log("worker Calling addToQueue", e), this.workerInstance != null ? await this.workerInstance.addToQueue(e) : console.log("workerInstance is null. Cannot call");
|
|
65
|
+
}
|
|
66
|
+
async getQueueSize() {
|
|
67
|
+
return console.log("worker Calling getQueueSize"), this.workerInstance == null ? -1 : await this.workerInstance.getQueueSize();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
s = k([
|
|
71
|
+
d(),
|
|
72
|
+
u(0, i("Logger")),
|
|
73
|
+
u(1, i("CristalApp"))
|
|
74
|
+
], s);
|
|
75
|
+
/**
|
|
76
|
+
* See the LICENSE file distributed with this work for additional
|
|
77
|
+
* information regarding copyright ownership.
|
|
78
|
+
*
|
|
79
|
+
* This is free software; you can redistribute it and/or modify it
|
|
80
|
+
* under the terms of the GNU Affero General Public License as
|
|
81
|
+
* published by the Free Software Foundation; either version 2.1 of
|
|
82
|
+
* the License, or (at your option) any later version.
|
|
83
|
+
*
|
|
84
|
+
* This software is distributed in the hope that it will be useful,
|
|
85
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
86
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
87
|
+
* Lesser General Public License for more details.
|
|
88
|
+
*
|
|
89
|
+
* You should have received a copy of the GNU Affero General Public
|
|
90
|
+
* License along with this software; if not, write to the Free
|
|
91
|
+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
92
|
+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
93
|
+
*
|
|
94
|
+
* This file is part of the Cristal Wiki software prototype
|
|
95
|
+
* @copyright Copyright (c) 2023 XWiki SAS
|
|
96
|
+
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
|
|
97
|
+
*
|
|
98
|
+
**/
|
|
99
|
+
class p {
|
|
100
|
+
constructor(r) {
|
|
101
|
+
r.bind("QueueWorker").to(s);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export {
|
|
105
|
+
p as ComponentInit
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=index.es.js.map
|
|
@@ -0,0 +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 Affero 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 Affero 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 * This file is part of the Cristal Wiki software prototype\n * @copyright Copyright (c) 2023 XWiki SAS\n * @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0\n *\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) {\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() {\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 Affero 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 Affero 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 * This file is part of the Cristal Wiki software prototype\n * @copyright Copyright (c) 2023 XWiki SAS\n * @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0\n *\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":";;;;;;;;;;;;;;;AAgCA,IAAqBA,IAArB,MAA+D;AAAA,EAOtD,YACqBC,GACQC,GAClC;AACA,SAAK,WAAW,GAChB,KAAK,SAASD,GACd,KAAK,aAAaC;AAAA,EACpB;AAAA,EAEO,WAAWC,GAAc;AAC1B,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,aAAa;AACd,QAAA;AACE,UAAA,KAAK,kBAAkB,MAAM;AAGzB,cAAAC,IAAU,IAAIC;AACpB,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;AAE3C,WADA,QAAQ,IAAI,6BAA6B,GACrC,KAAK,kBAAkB,OAAa,KAC5B,MAAM,KAAK,eAAe;EACxC;AACF;AAhGqBH,IAArBU,EAAA;AAAA,EADCC,EAAW;AAAA,EASPC,OAAe,QAAQ,CAAA;AAAA,EACvBA,OAAmB,YAAY,CAAA;AAAA,GATfZ,CAAA;AChCrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6BA,MAAqBa,EAAc;AAAA,EACjC,YAAYC,GAAsB;AAChC,IAAAA,EAAU,KAAkB,aAAa,EAAE,GAAGd,CAAkB;AAAA,EAClE;AACF;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 n in e)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const u=g(f);function h(e){return new SharedWorker("/assets/worker-D2exZhnK.js",{name:e==null?void 0:e.name})}var w=Object.defineProperty,k=Object.getOwnPropertyDescriptor,p=(e,r,n,t)=>{for(var l=t>1?void 0:t?k(r,n):r,i=e.length-1,c;i>=0;i--)(c=e[i])&&(l=(t?c(r,n,l):c(l))||l);return t&&l&&w(r,n,l),l},d=(e,r)=>(n,t)=>r(n,t,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.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;this.workerInstance=u.wrap(e.port);const r=this;this.workerInstance.setPageLoadedCallback(u.proxy(function(n){r.pageLoaded(n)})),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=p([a.injectable(),d(0,a.inject("Logger")),d(1,a.inject("CristalApp"))],s);/**
|
|
2
|
+
* See the LICENSE file distributed with this work for additional
|
|
3
|
+
* information regarding copyright ownership.
|
|
4
|
+
*
|
|
5
|
+
* This is free software; you can redistribute it and/or modify it
|
|
6
|
+
* under the terms of the GNU Affero General Public License as
|
|
7
|
+
* published by the Free Software Foundation; either version 2.1 of
|
|
8
|
+
* the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This software is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
+
* Lesser General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public
|
|
16
|
+
* License along with this software; if not, write to the Free
|
|
17
|
+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
18
|
+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
|
+
*
|
|
20
|
+
* This file is part of the Cristal Wiki software prototype
|
|
21
|
+
* @copyright Copyright (c) 2023 XWiki SAS
|
|
22
|
+
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
|
|
23
|
+
*
|
|
24
|
+
**/class m{constructor(r){r.bind("QueueWorker").to(s)}}o.ComponentInit=m,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
|
25
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +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 Affero 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 Affero 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 * This file is part of the Cristal Wiki software prototype\n * @copyright Copyright (c) 2023 XWiki SAS\n * @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0\n *\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) {\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() {\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 Affero 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 Affero 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 * This file is part of the Cristal Wiki software prototype\n * @copyright Copyright (c) 2023 XWiki SAS\n * @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0\n *\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":"g5BAgCA,IAAqBA,EAArB,KAA+D,CAOtD,YACqBC,EACQC,EAClC,CACA,KAAK,WAAW,EAChB,KAAK,OAASD,EACd,KAAK,WAAaC,CACpB,CAEO,WAAWC,EAAc,CAC1B,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,YAAa,CACd,GAAA,CACE,GAAA,KAAK,gBAAkB,KAAM,CAGzB,MAAAC,EAAU,IAAIC,EACpB,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,CAE3C,OADA,QAAQ,IAAI,6BAA6B,EACrC,KAAK,gBAAkB,KAAa,GAC5B,MAAM,KAAK,eAAe,cACxC,CACF,EAhGqBH,EAArBU,EAAA,CADCC,aAAW,EASPC,aAAe,QAAQ,CAAA,EACvBA,aAAmB,YAAY,CAAA,CAAA,EATfZ,CAAA,EChCrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IA6BA,MAAqBa,CAAc,CACjC,YAAYC,EAAsB,CAChCA,EAAU,KAAkB,aAAa,EAAE,GAAGd,CAAkB,CAClE,CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xwiki/cristal-sharedworker-impl",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"license": "AGPL-3.0",
|
|
5
|
+
"author": "XWiki Org Community <contact@xwiki.org>",
|
|
6
|
+
"homepage": "https://cristal.xwiki.org/",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"directory": "sharedworker/impl",
|
|
10
|
+
"url": "https://github.com/xwiki-contrib/cristal/"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://jira.xwiki.org/projects/CRISTAL/"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.es.js",
|
|
19
|
+
"require": "./dist/index.umd.js",
|
|
20
|
+
"types": "./dist/index.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.es.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"comlink": "4.4.1",
|
|
27
|
+
"inversify": "6.0.2",
|
|
28
|
+
"vue": "3.4.27",
|
|
29
|
+
"vue-i18n": "9.13.1",
|
|
30
|
+
"vue-router": "4.3.2",
|
|
31
|
+
"@xwiki/cristal-api": "0.8.0",
|
|
32
|
+
"@xwiki/cristal-sharedworker-api": "0.8.0",
|
|
33
|
+
"@xwiki/cristal-storage": "0.8.0",
|
|
34
|
+
"@xwiki/cristal-extension-manager": "0.8.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"rimraf": "5.0.7",
|
|
38
|
+
"vite": "5.2.11",
|
|
39
|
+
"vite-plugin-comlink": "4.0.2",
|
|
40
|
+
"vue-tsc": "2.0.19"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "pnpm compile",
|
|
44
|
+
"clean": "rimraf dist",
|
|
45
|
+
"compile": "vue-tsc --project tsconfig.json --noEmit && vite build",
|
|
46
|
+
"lint": "eslint \"./src/**/*.{ts,tsx}\" --max-warnings=0",
|
|
47
|
+
"test": "echo 'no test'"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See the LICENSE file distributed with this work for additional
|
|
3
|
+
* information regarding copyright ownership.
|
|
4
|
+
*
|
|
5
|
+
* This is free software; you can redistribute it and/or modify it
|
|
6
|
+
* under the terms of the GNU Affero General Public License as
|
|
7
|
+
* published by the Free Software Foundation; either version 2.1 of
|
|
8
|
+
* the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This software is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
+
* Lesser General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public
|
|
16
|
+
* License along with this software; if not, write to the Free
|
|
17
|
+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
18
|
+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
|
+
*
|
|
20
|
+
* This file is part of the Cristal Wiki software prototype
|
|
21
|
+
* @copyright Copyright (c) 2023 XWiki SAS
|
|
22
|
+
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
|
|
23
|
+
*
|
|
24
|
+
**/
|
|
25
|
+
|
|
26
|
+
import type { Container } from "inversify";
|
|
27
|
+
import type { QueueWorker } from "@xwiki/cristal-sharedworker-api";
|
|
28
|
+
import DefaultQueueWorker from "./defaultQueueWorker";
|
|
29
|
+
|
|
30
|
+
export default class ComponentInit {
|
|
31
|
+
constructor(container: Container) {
|
|
32
|
+
container.bind<QueueWorker>("QueueWorker").to(DefaultQueueWorker);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See the LICENSE file distributed with this work for additional
|
|
3
|
+
* information regarding copyright ownership.
|
|
4
|
+
*
|
|
5
|
+
* This is free software; you can redistribute it and/or modify it
|
|
6
|
+
* under the terms of the GNU Affero General Public License as
|
|
7
|
+
* published by the Free Software Foundation; either version 2.1 of
|
|
8
|
+
* the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This software is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
+
* Lesser General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public
|
|
16
|
+
* License along with this software; if not, write to the Free
|
|
17
|
+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
18
|
+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
|
+
*
|
|
20
|
+
* This file is part of the Cristal Wiki software prototype
|
|
21
|
+
* @copyright Copyright (c) 2023 XWiki SAS
|
|
22
|
+
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
|
|
23
|
+
*
|
|
24
|
+
**/
|
|
25
|
+
|
|
26
|
+
import { inject, injectable } from "inversify";
|
|
27
|
+
import type { MyWorker, QueueWorker } from "@xwiki/cristal-sharedworker-api";
|
|
28
|
+
import * as Comlink from "comlink";
|
|
29
|
+
import Worker from "./worker?sharedworker";
|
|
30
|
+
import { type CristalApp, type Logger } from "@xwiki/cristal-api";
|
|
31
|
+
|
|
32
|
+
@injectable()
|
|
33
|
+
export default class DefaultQueueWorker implements QueueWorker {
|
|
34
|
+
// TODO remove use of any
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
private workerInstance: any;
|
|
37
|
+
private cristalApp: CristalApp;
|
|
38
|
+
private logger: Logger;
|
|
39
|
+
|
|
40
|
+
public constructor(
|
|
41
|
+
@inject<Logger>("Logger") logger: Logger,
|
|
42
|
+
@inject<CristalApp>("CristalApp") cristalApp: CristalApp,
|
|
43
|
+
) {
|
|
44
|
+
this.initialize();
|
|
45
|
+
this.logger = logger;
|
|
46
|
+
this.cristalApp = cristalApp;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public pageLoaded(page: string) {
|
|
50
|
+
try {
|
|
51
|
+
this.logger.debug(
|
|
52
|
+
"Received callback that new document has been loaded",
|
|
53
|
+
page,
|
|
54
|
+
);
|
|
55
|
+
// When reloading the page for the worker, prevents a requeue to avoid
|
|
56
|
+
// an endless re-fetch of the current page.
|
|
57
|
+
this.cristalApp.loadPage({
|
|
58
|
+
requeue: false,
|
|
59
|
+
});
|
|
60
|
+
this.logger.debug(
|
|
61
|
+
"Done callback that new document has been loaded",
|
|
62
|
+
page,
|
|
63
|
+
);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
this.logger.error("Error calling loadPage", e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public initialize() {
|
|
70
|
+
try {
|
|
71
|
+
if (this.workerInstance == null) {
|
|
72
|
+
// this.workerInstance = new ComlinkWorker<typeof import('./worker')>(new URL('./worker',
|
|
73
|
+
// import.meta.url), {/* normal Worker options*/})
|
|
74
|
+
const sworker = new Worker();
|
|
75
|
+
this.workerInstance = Comlink.wrap<MyWorker>(sworker.port);
|
|
76
|
+
// TODO get rid of aliasing
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
78
|
+
const that = this;
|
|
79
|
+
this.workerInstance.setPageLoadedCallback(
|
|
80
|
+
Comlink.proxy(function (page: string) {
|
|
81
|
+
that.pageLoaded(page);
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
console.debug("Worker initialized", this.workerInstance);
|
|
86
|
+
} else {
|
|
87
|
+
console.debug("Already initialized");
|
|
88
|
+
}
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.error("Failed to initialize shared worker", e);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public getStatus(): boolean {
|
|
95
|
+
if (this.workerInstance != null) {
|
|
96
|
+
console.log("workerInstance is ready");
|
|
97
|
+
return true;
|
|
98
|
+
} else {
|
|
99
|
+
console.log("workerInstance is null. Cannot call");
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public async increment(): Promise<number> {
|
|
105
|
+
if (this.workerInstance == null) {
|
|
106
|
+
console.log("workerInstance is null. Cannot call");
|
|
107
|
+
return -1;
|
|
108
|
+
} else {
|
|
109
|
+
const result = await this.workerInstance.add(1);
|
|
110
|
+
console.log("Results from shared worker: ", result);
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public async addToQueue(page: string): Promise<void> {
|
|
116
|
+
console.log("worker Calling addToQueue", page);
|
|
117
|
+
if (this.workerInstance != null) {
|
|
118
|
+
await this.workerInstance.addToQueue(page);
|
|
119
|
+
} else {
|
|
120
|
+
console.log("workerInstance is null. Cannot call");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public async getQueueSize(): Promise<number> {
|
|
125
|
+
console.log("worker Calling getQueueSize");
|
|
126
|
+
if (this.workerInstance == null) return -1;
|
|
127
|
+
else return await this.workerInstance.getQueueSize();
|
|
128
|
+
}
|
|
129
|
+
}
|