@anonaddy/omni-worker 0.1.0 → 0.2.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.
Files changed (127) hide show
  1. package/README.md +22 -14
  2. package/dist/cjs/helpers/builder.js +22 -0
  3. package/dist/cjs/helpers/builder.js.map +1 -0
  4. package/dist/cjs/helpers/pool.js +9 -0
  5. package/dist/cjs/helpers/pool.js.map +1 -0
  6. package/dist/cjs/node/builder/helpers.js +14 -28
  7. package/dist/cjs/node/builder/helpers.js.map +1 -1
  8. package/dist/cjs/node/builder/index.js +2 -1
  9. package/dist/cjs/node/builder/index.js.map +1 -1
  10. package/dist/cjs/node/index.js +110 -51
  11. package/dist/cjs/node/index.js.map +1 -1
  12. package/dist/cjs/node/pool.js +131 -73
  13. package/dist/cjs/node/pool.js.map +1 -1
  14. package/dist/cjs/node.js +6 -0
  15. package/dist/cjs/node.js.map +1 -0
  16. package/dist/cjs/types/helpers.js +11 -0
  17. package/dist/cjs/types/helpers.js.map +1 -0
  18. package/dist/cjs/types/node-omni-worker.js +3 -0
  19. package/dist/cjs/types/node-omni-worker.js.map +1 -0
  20. package/dist/cjs/types/web-omni-worker.js +3 -0
  21. package/dist/cjs/types/web-omni-worker.js.map +1 -0
  22. package/dist/cjs/web/builder/helpers.js +9 -0
  23. package/dist/cjs/web/builder/helpers.js.map +1 -0
  24. package/dist/cjs/{node/builder/node.js → web/builder/index.js} +10 -17
  25. package/dist/cjs/web/builder/index.js.map +1 -0
  26. package/dist/cjs/web/builder/model.js +3 -0
  27. package/dist/cjs/web/builder/model.js.map +1 -0
  28. package/dist/cjs/web/index.js +156 -0
  29. package/dist/cjs/web/index.js.map +1 -0
  30. package/dist/cjs/web/pool.js +143 -0
  31. package/dist/cjs/web/pool.js.map +1 -0
  32. package/dist/cjs/web/provider/helpers.js +9 -0
  33. package/dist/cjs/web/provider/helpers.js.map +1 -0
  34. package/dist/cjs/web/provider/index.js +69 -0
  35. package/dist/cjs/web/provider/index.js.map +1 -0
  36. package/dist/cjs/web/provider/model.js +3 -0
  37. package/dist/cjs/web/provider/model.js.map +1 -0
  38. package/dist/cjs/web.js +8 -0
  39. package/dist/cjs/web.js.map +1 -0
  40. package/dist/mjs/helpers/builder.js +16 -0
  41. package/dist/mjs/helpers/builder.js.map +1 -0
  42. package/dist/mjs/helpers/pool.js +6 -0
  43. package/dist/mjs/helpers/pool.js.map +1 -0
  44. package/dist/mjs/node/builder/helpers.js +14 -27
  45. package/dist/mjs/node/builder/helpers.js.map +1 -1
  46. package/dist/mjs/node/builder/index.js +4 -3
  47. package/dist/mjs/node/builder/index.js.map +1 -1
  48. package/dist/mjs/node/index.js +111 -51
  49. package/dist/mjs/node/index.js.map +1 -1
  50. package/dist/mjs/node/pool.js +132 -73
  51. package/dist/mjs/node/pool.js.map +1 -1
  52. package/dist/mjs/node.js +2 -0
  53. package/dist/mjs/node.js.map +1 -0
  54. package/dist/mjs/types/helpers.js +8 -0
  55. package/dist/mjs/types/helpers.js.map +1 -0
  56. package/dist/mjs/types/node-omni-worker.js +2 -0
  57. package/dist/mjs/types/node-omni-worker.js.map +1 -0
  58. package/dist/mjs/types/web-omni-worker.js +2 -0
  59. package/dist/mjs/types/web-omni-worker.js.map +1 -0
  60. package/dist/mjs/web/builder/helpers.js +6 -0
  61. package/dist/mjs/web/builder/helpers.js.map +1 -0
  62. package/dist/mjs/web/builder/index.js +10 -0
  63. package/dist/mjs/web/builder/index.js.map +1 -0
  64. package/dist/mjs/web/builder/model.js +2 -0
  65. package/dist/mjs/web/builder/model.js.map +1 -0
  66. package/dist/mjs/web/index.js +120 -0
  67. package/dist/mjs/web/index.js.map +1 -0
  68. package/dist/mjs/web/pool.js +140 -0
  69. package/dist/mjs/web/pool.js.map +1 -0
  70. package/dist/mjs/web/provider/helpers.js +6 -0
  71. package/dist/mjs/web/provider/helpers.js.map +1 -0
  72. package/dist/mjs/web/provider/index.js +32 -0
  73. package/dist/mjs/web/provider/index.js.map +1 -0
  74. package/dist/mjs/web/provider/model.js +2 -0
  75. package/dist/mjs/web/provider/model.js.map +1 -0
  76. package/dist/mjs/web.js +3 -0
  77. package/dist/mjs/web.js.map +1 -0
  78. package/dist/types/helpers/builder.d.ts +2 -0
  79. package/dist/types/helpers/builder.d.ts.map +1 -0
  80. package/dist/types/helpers/pool.d.ts +2 -0
  81. package/dist/types/helpers/pool.d.ts.map +1 -0
  82. package/dist/types/node/builder/helpers.d.ts +0 -1
  83. package/dist/types/node/builder/helpers.d.ts.map +1 -1
  84. package/dist/types/node/builder/index.d.ts +2 -2
  85. package/dist/types/node/builder/index.d.ts.map +1 -1
  86. package/dist/types/node/index.d.ts +15 -13
  87. package/dist/types/node/index.d.ts.map +1 -1
  88. package/dist/types/node/pool.d.ts +4 -3
  89. package/dist/types/node/pool.d.ts.map +1 -1
  90. package/dist/types/node.d.ts +3 -0
  91. package/dist/types/node.d.ts.map +1 -0
  92. package/dist/types/types/helpers.d.ts +6 -0
  93. package/dist/types/types/helpers.d.ts.map +1 -0
  94. package/dist/types/types/node-omni-worker.d.ts +90 -0
  95. package/dist/types/types/node-omni-worker.d.ts.map +1 -0
  96. package/dist/types/types/web-omni-worker.d.ts +103 -0
  97. package/dist/types/types/web-omni-worker.d.ts.map +1 -0
  98. package/dist/types/web/builder/helpers.d.ts +3 -0
  99. package/dist/types/web/builder/helpers.d.ts.map +1 -0
  100. package/dist/types/web/builder/index.d.ts +8 -0
  101. package/dist/types/web/builder/index.d.ts.map +1 -0
  102. package/dist/types/web/builder/model.d.ts +11 -0
  103. package/dist/types/web/builder/model.d.ts.map +1 -0
  104. package/dist/types/web/index.d.ts +35 -0
  105. package/dist/types/web/index.d.ts.map +1 -0
  106. package/dist/types/web/pool.d.ts +31 -0
  107. package/dist/types/web/pool.d.ts.map +1 -0
  108. package/dist/types/web/provider/helpers.d.ts +2 -0
  109. package/dist/types/web/provider/helpers.d.ts.map +1 -0
  110. package/dist/types/web/provider/index.d.ts +16 -0
  111. package/dist/types/web/provider/index.d.ts.map +1 -0
  112. package/dist/types/web/provider/model.d.ts +7 -0
  113. package/dist/types/web/provider/model.d.ts.map +1 -0
  114. package/dist/types/web.d.ts +4 -0
  115. package/dist/types/web.d.ts.map +1 -0
  116. package/package.json +23 -9
  117. package/dist/cjs/index.js +0 -8
  118. package/dist/cjs/index.js.map +0 -1
  119. package/dist/cjs/node/builder/node.js.map +0 -1
  120. package/dist/mjs/index.js +0 -3
  121. package/dist/mjs/index.js.map +0 -1
  122. package/dist/mjs/node/builder/node.js +0 -14
  123. package/dist/mjs/node/builder/node.js.map +0 -1
  124. package/dist/types/index.d.ts +0 -4
  125. package/dist/types/index.d.ts.map +0 -1
  126. package/dist/types/node/builder/node.d.ts +0 -7
  127. package/dist/types/node/builder/node.d.ts.map +0 -1
@@ -1,82 +1,141 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
36
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
37
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
38
+ };
1
39
  import { NodeOmniWorker } from ".";
2
- export class NodeOmniWorkerPool {
3
- constructor(from, options) {
4
- this._pool = [];
5
- this._count = 0;
6
- this._lastUseIdx = -1;
7
- this.isInitialized = () => this._count > 0;
8
- this.getNumOfWorkers = () => this._count;
9
- this.use = () => {
10
- if (!this.isInitialized()) {
11
- return this._from.use();
12
- }
13
- else {
14
- const lastIdx = this._lastUseIdx;
15
- // first run or maxed out
16
- if (lastIdx === this._count - 1 ||
17
- lastIdx === -1) {
18
- this._lastUseIdx = 0;
19
- return this._pool[0].use();
20
- // any other run
40
+ import { staticImplements } from "../types/helpers";
41
+ let NodeOmniWorkerPool = (() => {
42
+ let _classDecorators = [staticImplements()];
43
+ let _classDescriptor;
44
+ let _classExtraInitializers = [];
45
+ let _classThis;
46
+ var NodeOmniWorkerPool = _classThis = class {
47
+ constructor(from, options) {
48
+ this._pool = [];
49
+ this._count = 0;
50
+ this._lastUseIdx = -1;
51
+ this.isInitialized = () => this._count > 0;
52
+ this.getNumOfWorkers = () => this._count;
53
+ this.use = () => {
54
+ if (!this.isInitialized()) {
55
+ return this._from.use();
21
56
  }
22
57
  else {
23
- this._lastUseIdx = lastIdx + 1;
24
- return this._pool[lastIdx + 1].use();
58
+ const lastIdx = this._lastUseIdx;
59
+ // first run or maxed out
60
+ if (lastIdx === this._count - 1 ||
61
+ lastIdx === -1) {
62
+ this._lastUseIdx = 0;
63
+ return this._pool[0].use();
64
+ // any other run
65
+ }
66
+ else {
67
+ this._lastUseIdx = lastIdx + 1;
68
+ return this._pool[lastIdx + 1].use();
69
+ }
25
70
  }
26
- }
27
- };
28
- this.destroy = async () => {
29
- const fns = [];
30
- this._pool.forEach(w => {
31
- const fn = async () => {
32
- await w.destroy();
33
- };
34
- fns.push(fn);
35
- });
36
- await Promise.all(fns.map(fn => fn()));
37
- };
38
- this._from = from;
39
- this._options = options || { numOfWorkers: 1 };
40
- this.applyOptions();
41
- }
42
- /**
43
- * First builds the OmniWorkers and then launches a new NodeOmniWorker pool
44
- * @param from The (relative) file path from your project's root to the worker .ts file
45
- * @param options (Optional) Options object for launching the pool
46
- */
47
- static async buildAndLaunch(from, options) {
48
- const worker = await NodeOmniWorker.build(from);
49
- const pool = NodeOmniWorkerPool.launch(worker, options);
50
- return pool;
51
- }
52
- /**
53
- * Launches a new NodeOmniWorker pool according to the options provided
54
- * @param worker An already built NodeOmniWorker
55
- * @returns A newly created pool
56
- */
57
- static launch(worker, options) {
58
- const pool = new NodeOmniWorkerPool(worker, options);
59
- return pool;
60
- }
61
- /**
62
- * Applies the options provided
63
- */
64
- applyOptions() {
65
- const { numOfWorkers } = this._options;
66
- let count = 0;
67
- if (numOfWorkers === undefined) {
68
- count = 1;
71
+ };
72
+ this.destroy = async () => {
73
+ const fns = [];
74
+ this._pool.forEach(w => {
75
+ const fn = async () => {
76
+ await w.destroy();
77
+ };
78
+ fns.push(fn);
79
+ });
80
+ await Promise.all(fns.map(fn => fn()));
81
+ };
82
+ this._from = from;
83
+ this._options = options;
84
+ this.applyOptions();
69
85
  }
70
- else {
71
- count = numOfWorkers;
86
+ /**
87
+ * First builds the OmniWorkers and then launches a new NodeOmniWorker pool
88
+ * @param from The (relative) file path from your project's root to the worker .ts file
89
+ * @param options (Optional) Options object for launching the pool
90
+ */
91
+ static async buildAndLaunch(from, options = {
92
+ numOfWorkers: 1
93
+ }) {
94
+ const worker = await NodeOmniWorker.build(from);
95
+ const pool = NodeOmniWorkerPool.launch(worker, options);
96
+ return pool;
72
97
  }
73
- if (count < 1) {
74
- throw Error(`number of workers must be at least 1`);
98
+ /**
99
+ * Launches a new NodeOmniWorker pool according to the options provided
100
+ * @param worker An already built NodeOmniWorker
101
+ * @returns A newly created pool
102
+ */
103
+ static launch(worker, options = {
104
+ numOfWorkers: 1
105
+ }) {
106
+ const pool = new NodeOmniWorkerPool(worker, options);
107
+ return pool;
75
108
  }
76
- this._count = count;
77
- for (let i = 0; i <= count; i++) {
78
- this._pool = this._from.clone(count);
109
+ /**
110
+ * Applies the options provided
111
+ */
112
+ applyOptions() {
113
+ const { numOfWorkers } = this._options;
114
+ let count = 0;
115
+ if (numOfWorkers === undefined) {
116
+ count = 1;
117
+ }
118
+ else {
119
+ count = numOfWorkers;
120
+ }
121
+ if (count < 1) {
122
+ throw Error(`number of workers must be at least 1`);
123
+ }
124
+ this._count = count;
125
+ for (let i = 0; i <= count; i++) {
126
+ this._pool = this._from.clone(count);
127
+ }
79
128
  }
80
- }
81
- }
129
+ };
130
+ __setFunctionName(_classThis, "NodeOmniWorkerPool");
131
+ (() => {
132
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
133
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
134
+ NodeOmniWorkerPool = _classThis = _classDescriptor.value;
135
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
136
+ __runInitializers(_classThis, _classExtraInitializers);
137
+ })();
138
+ return NodeOmniWorkerPool = _classThis;
139
+ })();
140
+ export { N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,EACzB,UAAkC;YAChC,YAAY,EAAE,CAAC;SAChB;YAED,MAAM,IAAI,GAAG,IAAI,kBAAkB,CAAI,MAAM,EAAE,OAAO,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC;QACd,CAAC;QAED;;WAEG;QACK,YAAY;YAClB,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;YAEvC,IAAI,KAAK,GAAG,CAAC,CAAC;YACd,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;gBAC/B,KAAK,GAAG,CAAC,CAAC;YACZ,CAAC;iBAAM,CAAC;gBACN,KAAK,GAAG,YAAY,CAAC;YACvB,CAAC;YAED,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;gBACd,MAAM,KAAK,CAAC,sCAAsC,CAAC,CAAC;YACtD,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;gBAChC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;;;;;QApEH,6KA0GC;;;QA1GY,uDAAkB;;;;SAAlB,kBAAkB"}
@@ -0,0 +1,2 @@
1
+ export { NodeOmniWorker } from './node/index';
2
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,cAAc,EACf,MAAM,cAAc,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Applies an interface with static function definitions
3
+ * @returns The constructor of class T
4
+ */
5
+ export function staticImplements() {
6
+ return (constructor) => { constructor; };
7
+ }
8
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/types/helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC5B,OAAO,CAAc,WAAc,EAAE,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=node-omni-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-omni-worker.js","sourceRoot":"","sources":["../../../src/types/node-omni-worker.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=web-omni-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-omni-worker.js","sourceRoot":"","sources":["../../../src/types/web-omni-worker.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export function convertToJsUrl(tsUrl, extension) {
2
+ tsUrl.pathname = tsUrl.pathname.replace(/\.ts$/, extension);
3
+ tsUrl.href = tsUrl.href.replace(/\.ts$/, extension);
4
+ return tsUrl;
5
+ }
6
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/web/builder/helpers.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,KAAU,EAAE,SAAsB;IAC/D,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5D,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACpD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,10 @@
1
+ import * as Comlink from 'comlink/dist/esm/comlink';
2
+ import { convertToJsUrl } from './helpers';
3
+ export const buildWebApiAndWorker = (tsUrl, options) => {
4
+ const extension = options.extension || '.js';
5
+ const jsUrl = convertToJsUrl(tsUrl, extension);
6
+ const worker = new Worker(jsUrl, { type: 'module' });
7
+ const api = Comlink.wrap(worker);
8
+ return { jsUrl, worker, api };
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,KAAU,EACV,OAAqC,EACyB,EAAE;IAEhE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;IAC7C,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAE/C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAI,MAAM,CAAC,CAAC;IAEpC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAChC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../src/web/builder/model.ts"],"names":[],"mappings":""}
@@ -0,0 +1,120 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
36
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
37
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
38
+ };
39
+ import * as Comlink from 'comlink/dist/esm/comlink';
40
+ import { staticImplements } from "../types/helpers";
41
+ import { buildWebApiAndWorker } from "./builder";
42
+ /**
43
+ * OmniWorker for the web
44
+ */
45
+ let WebOmniWorker = (() => {
46
+ let _classDecorators = [staticImplements(), staticImplements()];
47
+ let _classDescriptor;
48
+ let _classExtraInitializers = [];
49
+ let _classThis;
50
+ var WebOmniWorker = _classThis = class {
51
+ constructor(url, options, worker, api) {
52
+ this.isInitialized = () => this._api !== undefined;
53
+ this.use = () => {
54
+ const isInitialized = this.isInitialized();
55
+ if (isInitialized) {
56
+ return this._api;
57
+ }
58
+ else {
59
+ throw Error(`worker is not yet initialized. make sure to call the build() function, first`);
60
+ }
61
+ };
62
+ this.destroy = async () => {
63
+ var _a;
64
+ (_a = this._worker) === null || _a === void 0 ? void 0 : _a.terminate();
65
+ };
66
+ this.clone = (numOfTimes) => {
67
+ const workers = [];
68
+ const url = this._url;
69
+ const options = this._options;
70
+ for (let i = 0; i <= numOfTimes; i++) {
71
+ const { worker, api } = buildWebApiAndWorker(url, options);
72
+ workers.push(new WebOmniWorker(url, options, worker, api));
73
+ }
74
+ return workers;
75
+ };
76
+ this._url = url;
77
+ this._options = options;
78
+ this._worker = worker;
79
+ this._api = api;
80
+ return this;
81
+ }
82
+ /**
83
+ * Handles the building of the necessary resources for an OmniWorker to function.
84
+ * This usually means, building from the consumer's code, creating the comlink
85
+ * interface between the worker and the main thread as well as the worker itself.
86
+ *
87
+ * @param tsUrl A URL object linking to the worker .ts file
88
+ * @param options Builder options
89
+ * @returns A WebOmniWorker
90
+ */
91
+ static async build(tsUrl, options = {
92
+ extension: '.js'
93
+ }) {
94
+ const { jsUrl, worker, api } = buildWebApiAndWorker(tsUrl, options);
95
+ return new WebOmniWorker(jsUrl, options, worker, api);
96
+ }
97
+ };
98
+ __setFunctionName(_classThis, "WebOmniWorker");
99
+ (() => {
100
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
101
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
102
+ WebOmniWorker = _classThis = _classDescriptor.value;
103
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
104
+ })();
105
+ /**
106
+ * Expose the functions inside the worker to the rest of the application.
107
+ * After having exposed the functions, the build step can be initiated.
108
+ * @param exposable A class, object with functions or a single function to be
109
+ * exposed to the main thread.
110
+ */
111
+ _classThis.expose = (exposable) => {
112
+ Comlink.expose(exposable);
113
+ };
114
+ (() => {
115
+ __runInitializers(_classThis, _classExtraInitializers);
116
+ })();
117
+ return WebOmniWorker = _classThis;
118
+ })();
119
+ export { WebOmniWorker };
120
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAGjD;;GAEG;IAGU,aAAa;4BAFzB,gBAAgB,EAAc,EAC9B,gBAAgB,EAAc;;;;;QAO7B,YACE,GAAQ,EACR,OAAqC,EACrC,MAAc,EACd,GAA4B;YAsC9B,kBAAa,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;YAE9C,QAAG,GAAG,GAAG,EAAE;gBACT,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;gBAC3C,IAAI,aAAa,EAAE,CAAC;oBAClB,OAAO,IAAI,CAAC,IAAK,CAAC;gBACpB,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC,8EAA8E,CAAC,CAAC;gBAC9F,CAAC;YACH,CAAC,CAAA;YAED,YAAO,GAAG,KAAK,IAAI,EAAE;;gBACnB,MAAA,IAAI,CAAC,OAAO,0CAAE,SAAS,EAAE,CAAC;YAC5B,CAAC,CAAC;YAEF,UAAK,GAAG,CAAC,UAAkB,EAAE,EAAE;gBAC7B,MAAM,OAAO,GAAuB,EAAE,CAAC;gBACvC,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;gBACtB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;gBAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;oBACrC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,oBAAoB,CAAI,GAAG,EAAE,OAAO,CAAC,CAAC;oBAC9D,OAAO,CAAC,IAAI,CAAC,IAAI,aAAa,CAAI,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;gBAChE,CAAC;gBACD,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC;YA5DA,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;YAChB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;YACtB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;YAChB,OAAO,IAAI,CAAC;QACd,CAAC;QAYD;;;;;;;;WAQG;QACI,MAAM,CAAC,KAAK,CAAC,KAAK,CACvB,KAAU,EACV,UAAwC;YACtC,SAAS,EAAE,KAAK;SACjB;YAED,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,oBAAoB,CAAI,KAAK,EAAE,OAAO,CAAC,CAAC;YACvE,OAAO,IAAI,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACxD,CAAC;;;;;QA9CH,6KAyEC;;;;IAtDC;;;;;OAKG;IACW,iBAAM,GAAG,CAAI,SAAY,EAAQ,EAAE;QAC/C,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,AAFmB,CAEnB;;QA3BU,uDAAa;;;;SAAb,aAAa"}
@@ -0,0 +1,140 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
36
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
37
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
38
+ };
39
+ import { WebOmniWorker } from ".";
40
+ import { staticImplements } from "../types/helpers";
41
+ let WebOmniWorkerPool = (() => {
42
+ let _classDecorators = [staticImplements()];
43
+ let _classDescriptor;
44
+ let _classExtraInitializers = [];
45
+ let _classThis;
46
+ var WebOmniWorkerPool = _classThis = class {
47
+ constructor(from, options) {
48
+ this._pool = [];
49
+ this._count = 0;
50
+ this._lastUseIdx = -1;
51
+ this.isInitialized = () => this._count > 0;
52
+ this.getNumOfWorkers = () => this._count;
53
+ this.use = () => {
54
+ if (!this.isInitialized()) {
55
+ return this._from.use();
56
+ }
57
+ else {
58
+ const lastIdx = this._lastUseIdx;
59
+ // first run or maxed out
60
+ if (lastIdx === this._count - 1 ||
61
+ lastIdx === -1) {
62
+ this._lastUseIdx = 0;
63
+ return this._pool[0].use();
64
+ // any other run
65
+ }
66
+ else {
67
+ this._lastUseIdx = lastIdx + 1;
68
+ return this._pool[lastIdx + 1].use();
69
+ }
70
+ }
71
+ };
72
+ this.destroy = async () => {
73
+ const fns = [];
74
+ this._pool.forEach(w => {
75
+ const fn = async () => {
76
+ await w.destroy();
77
+ };
78
+ fns.push(fn);
79
+ });
80
+ await Promise.all(fns.map(fn => fn()));
81
+ };
82
+ this._from = from;
83
+ this._options = options || { numOfWorkers: 1 };
84
+ this.applyOptions();
85
+ }
86
+ /**
87
+ * First builds the OmniWorkers and then launches a new WebOmniWorker pool
88
+ * @param url A URL with the relative file path to the worker .ts file
89
+ * @param options (Optional) Options object for launching the pool
90
+ */
91
+ static async buildAndLaunch(url, options = {
92
+ extension: '.js',
93
+ numOfWorkers: (navigator === null || navigator === void 0 ? void 0 : navigator.hardwareConcurrency) || 1
94
+ }) {
95
+ const worker = await WebOmniWorker.build(url, options);
96
+ const pool = WebOmniWorkerPool.launch(worker, options);
97
+ return pool;
98
+ }
99
+ /**
100
+ * Launches a new WebOmniWorker pool according to the options provided
101
+ * @param worker An already built WebOmniWorker
102
+ * @returns A newly created pool
103
+ */
104
+ static launch(worker, options) {
105
+ const pool = new WebOmniWorkerPool(worker, options);
106
+ return pool;
107
+ }
108
+ /**
109
+ * Applies the options provided
110
+ */
111
+ applyOptions() {
112
+ const { numOfWorkers } = this._options;
113
+ let count = 0;
114
+ if (numOfWorkers === undefined) {
115
+ count = 1;
116
+ }
117
+ else {
118
+ count = numOfWorkers;
119
+ }
120
+ if (count < 1) {
121
+ throw Error(`number of workers must be at least 1`);
122
+ }
123
+ this._count = count;
124
+ for (let i = 0; i <= count; i++) {
125
+ this._pool = this._from.clone(count);
126
+ }
127
+ }
128
+ };
129
+ __setFunctionName(_classThis, "WebOmniWorkerPool");
130
+ (() => {
131
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
132
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
133
+ WebOmniWorkerPool = _classThis = _classDescriptor.value;
134
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
135
+ __runInitializers(_classThis, _classExtraInitializers);
136
+ })();
137
+ return WebOmniWorkerPool = _classThis;
138
+ })();
139
+ export { WebOmniWorkerPool };
140
+ //# sourceMappingURL=pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/web/pool.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;IAIvC,iBAAiB;4BAD7B,gBAAgB,EAAe;;;;;QAS9B,YACE,IAAsB,EACtB,OAAgC;YAR1B,UAAK,GAAuB,EAAE,CAAC;YAG/B,WAAM,GAAW,CAAC,CAAC;YACnB,gBAAW,GAAW,CAAC,CAAC,CAAC;YA+D1B,kBAAa,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;YAEtC,oBAAe,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;YAEpC,QAAG,GAAG,GAAG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AAiB;;;;SAAjB,iBAAiB"}
@@ -0,0 +1,6 @@
1
+ export function convertToJsUrl(tsUrl, extension = '.js') {
2
+ tsUrl.pathname = tsUrl.pathname.replace(/\.ts$/, extension);
3
+ tsUrl.href = tsUrl.href.replace(/\.ts$/, extension);
4
+ return tsUrl;
5
+ }
6
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/web/provider/helpers.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAC,KAAU,EAAE,SAAS,GAAG,KAAK;IAC1D,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5D,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACpD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { convertToJsUrl } from "./helpers";
2
+ /**
3
+ * This provider is needed, since most bundlers will "tree shake"
4
+ * out worker files that are not imported. The reason for that,
5
+ * is that worker files aren't supposed to be imported.
6
+ * This wrapper function quickly imports the worker, before building
7
+ * it.
8
+ *
9
+ * @param tsUrl A URL object linking a worker .ts file, created using
10
+ * new URL('/path/to/your/file.ts', import.meta.url)
11
+ * @param options Optional options for the provisioning
12
+ * @returns A callback function, returning the the .js URL for building
13
+ * the worker
14
+ */
15
+ export const provideWorker = (tsUrl, options = {
16
+ extension: '.js'
17
+ }) => {
18
+ const jsUrl = convertToJsUrl(tsUrl, options.extension);
19
+ return () => {
20
+ const loadModule = (async () => {
21
+ try {
22
+ import(jsUrl.href);
23
+ }
24
+ catch (e) {
25
+ console.warn(e);
26
+ }
27
+ });
28
+ loadModule();
29
+ return jsUrl;
30
+ };
31
+ };
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAAU,EACV,UAAiC;IAC/B,SAAS,EAAE,KAAK;CACjB,EACD,EAAE;IAEF,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAEvD,OAAO,GAAQ,EAAE;QACf,MAAM,UAAU,GAAG,CAAC,KAAK,IAAI,EAAE;YAC7B,IAAI,CAAC;gBACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;YAAC,OAAM,CAAC,EAAE,CAAC;gBACV,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;QACH,CAAC,CAAC,CAAC;QACH,UAAU,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../src/web/provider/model.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export { WebOmniWorker } from './web/index';
2
+ export { WebOmniWorkerPool } from './web/pool';
3
+ //# sourceMappingURL=web.js.map