@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
package/README.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # 👷 Omni Worker - A Versatile Worker for Typescript
2
- Webworkers (browser) and thread workers (NodeJS) are usually limiting in their application, since the code that runs on a worker needs to be serializable. Therefore, most interfaces aren't fully supported, and also 3rd party modules usually don't work or give you a serious headache when implementing them...
2
+ Webworkers (browser) and thread workers (NodeJS) are usually hard to implement, since the code that runs on a worker needs to be serializable and have complex interfaces to transfer the data into the workers. 3rd party modules are usually hard to get working or don't work at all giving you a serious headache when implementing them...
3
3
 
4
- Enter the stage, OmniWorkers! These workers allow you to simply declare any interface with functions that will actually run inside a worker. Whether it be on the web (webworker) or on NodeJS (thread worker), these workers will run your code, period.
4
+ Enter the stage, OmniWorkers! These workers allow you to simply declare an interface with functions (currently with the exception of callbacks) that will actually run inside a worker. Whether it be on the web (webworker) or on NodeJS (thread worker), these workers will run your code inside a worker, period.
5
5
 
6
6
  ## How does it Work?
7
- In the case of using typescript for front-end projects, a UI will simply block at certain tasks if they're too heavy. Alternatively, in case of Node, load times can significantly increase since the JavaScript V8 engine only runs one event loop thread. Even when using asynchronous code, the event loop is still just one thread.
7
+ In the case of using typescript for front-end projects, a UI will simply block at certain tasks if they're too heavy. You could use yielding functions, but that will slow your code down as a result. Similarly, in case of NodeJS, load times can significantly increase since the JavaScript V8 engine only runs one event loop thread. Even when using asynchronous code, the event loop is still just running on one thread.
8
8
 
9
9
  ### Workers
10
10
  The [Webworker API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) for the web and [Worker Threads](https://nodejs.org/api/worker_threads.html) for NodeJS allow us to declare code inside a seperate file, which will run in its own context (event loop). The advantage of this is that we now have more than one event loop thread to work with.
11
11
 
12
- The drawback here, is that all code executed inside these (contexed) workers needs to be serializable, since your code is basically shipped into the worker for execution. This is done through the Worker communication interface. Should your code depend on other 3rd party libraries, your code will most-likely not execute, since the code inside the worker context is mostly closed off.
12
+ The drawback here, is that all code executed inside these (contexed) workers needs to be serializable, since your code is basically shipped into the worker for execution. This is done through the Worker communication interface. Should your code depend on other 3rd party libraries, your code would have most-likely not executed, since the code inside the worker context is closed off from the main thread context.
13
13
 
14
14
  ### 👷 OmniWorkers
15
- So how do OmniWorkers stand out from normal workers? First off, their simplicity. Simply declare your code and expose it to the main event loop. Then build the OmniWorker by simply referencing you file. Now, the OmniWorker will expose the object with functions you've injected into the worker container. You can use your own functions with primitive types, functions directly taken from 3rd party modules or a hybrid mix of both. Let's look at an example:
15
+ So what makes OmniWorkers to special? First off, their simplicity. Simply declare your code and expose it to the main event loop. Then build the OmniWorker by simply referencing you file. Now, the OmniWorker will expose the object with functions or a class you've injected into the worker container. You can use your own functions with primitive types, functions directly taken from 3rd party modules or a hybrid mix of both. Let's first look at an example for NodeJS:
16
16
 
17
17
  #### `👷‍♀️ workers/worker.ts`
18
18
  ```javascript
@@ -33,9 +33,9 @@ const fnObj: IMyOmniWorkerFunctions = {
33
33
  // In this case, diamond interface can even be omitted, since inferred
34
34
  NodeOmniWorker.expose<IMyOmniWorkerFunctions>(fnObj);
35
35
  ```
36
- The worker.ts file contains the logic you would like to run inside the container. In our example above we created our own function, but we also included a 3rd party module (lodash) to demonstrate that an OmniWorker can just as well use any other 3rd party module.
36
+ The worker.ts file contains the logic you would like to run inside the container. In our example above we created our own function inside a object containing functions, but notice how we included a 3rd party module (lodash). This demonstrates that an OmniWorker can just as well use any other 3rd party module as well as logic defined by you.
37
37
 
38
- What's important, is to expose your logic using the expose function. This will make sure that the container exposes (or shares) your code logic with the main event loop thread, for you to access it in your code.
38
+ What's important, is to expose your logic using the expose function. This will make sure that the container exposes (or shares) your code logic with the main event loop, for you to access it in the rest of your code:
39
39
 
40
40
  #### `🏭 index.ts`
41
41
  ```javascript
@@ -46,7 +46,7 @@ import { IMyOmniWorkerFunctions } from "./worker-model";
46
46
  const WORKER_DIR = "./src/workers";
47
47
 
48
48
  // Placing anonymous async function on the event loop
49
- setTimeout(async () => {
49
+ (async () => {
50
50
 
51
51
  // Build the worker from the file you specified and the
52
52
  // functions that were exposed
@@ -64,7 +64,7 @@ setTimeout(async () => {
64
64
 
65
65
  // Release resources once you're done!
66
66
  await worker.destroy();
67
- }, 0);
67
+ })();
68
68
  ```
69
69
  Your code can now just **asynchronously** call the logic you have declared and exposed inside your worker.ts. Simply call the `worker.use()` function and you'll have access to all the functions defined by you inside your `IMyOwnWorkerFunctions` interface.
70
70
 
@@ -78,7 +78,7 @@ Sometimes, having one worker just isn't enough. Worker pools are capable of inst
78
78
  import { NodeOmniWorkerPool } from '@anonaddy/omni-worker';
79
79
  import { IMyOmniWorkerFunctions } from "./worker-model";
80
80
 
81
- setTimeout(async () => {
81
+ (async () => {
82
82
 
83
83
  const pool = await NodeOmniWorkerPool
84
84
  .buildAndLaunch<IMyOmniWorkerFunctions>(
@@ -104,10 +104,17 @@ setTimeout(async () => {
104
104
  // Release resources once you're done!
105
105
  await pool.destroy();
106
106
 
107
- }, 0);
107
+ })();
108
108
 
109
109
  ```
110
- The code example above will create a worker pool of 4 workers with the code you specified. All work will be distributed round-robin across the OmniWorkers.
110
+ The code example above will create a worker pool of 4 workers with the code you specified. All work will be distributed round-robin across the OmniWorkers. We recommend using as many workers inside the pool as you have threads on the processor running the code. This will make sure that performance is optimal. Too many workers can AND WILL degrade performance in JavaScript.
111
+
112
+ ### 🕸️ WebOmniWorkers
113
+ When you're building a module for the web, you can't use Node's module resolution. Instead, you will use a bundler (e.g. Webpack, Rollup) to bundle your code, usually in a format like ESM. This use case is covered by WebOmniWorkers.
114
+
115
+ The only difference when instantiating a WebOmniWorker is that instead of a project file path, a URL object needs to be parsed into the build function. Also, when using any 3rd party modules, these need to be statically linked inside your `worker.ts` file and can't be linked using Node's module resolution.
116
+
117
+ Please see the [demos](https://github.com/avluent/omni-worker-demos) project to see how a WebOmniWorker(pool) can be instantiated on a JavaScript module project.
111
118
 
112
119
  ### Under the Hood
113
120
  This modules leverages [Webpack](https://www.npmjs.com/package/webpack) to parse your container code and build it. From there, it's wired up to the main event loop using a great module called [Comlink](https://github.com/GoogleChromeLabs/comlink). This module abstracts away the communication between the main event loop and Workers.
@@ -129,14 +136,15 @@ rm -rf node_modules
129
136
  mv package-lock.json package-lock.json.backup # make sure to make a backup!
130
137
  npm i
131
138
  ```
132
- Should you not be able to solve your issue, please drop me an email so we can try and analyze the issue together.
139
+ Should you not be able to solve your issue, please drop me an email so we can have a look at your case. We're constantly attempt at improving compatitiblity for these types of use cases. Should you have an idea of you own, also feel free to provide a pull request.
133
140
 
134
141
  # Project Status
135
- Currently, only `NodeOmniWorker`s and `NodeOmniWorkerPool`s are available. The `WebOmniWorker`s along with their pools will also be available soon. Please stay tuned! In case you have any questions, make sure to drop me an [email](mailto:7ebr7fa0@anonaddy.com) and I will try to get back to you asap.
142
+ We're happy to announce that `WebOmniWorker`s along with their pools are now available. In case you have any questions, make sure to drop me an [email](mailto:7ebr7fa0@anonaddy.com) and I will get back to you asap.
136
143
 
137
144
  ## Change Log
138
145
  |Version|Description|
139
146
  |:-:|-|
147
+ |**v0.2.0**|Introduced the WebOmniWorker and the WebOmniWorker pool. Split the project for Node and Web|
140
148
  |**v0.1.0**|Switched from ESBuild to Webpack for NodeJS and introduced the NodeOmniWorkerPool|
141
149
  |**v0.0.1**|Basic of single NodeOmniWorker with code having native dependencies still crashing|
142
150
 
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCallerDir = getCallerDir;
7
+ const path_1 = __importDefault(require("path"));
8
+ function getCallerDir() {
9
+ try {
10
+ const stack = new Error().stack;
11
+ const line = stack.split('\n')[1].trim();
12
+ const segment = line.split(' ')[1];
13
+ const part = segment.split(':')[0];
14
+ const dirName = path_1.default.dirname(part);
15
+ return dirName;
16
+ }
17
+ catch (e) {
18
+ // console.error('building caller path failed', e);
19
+ return './';
20
+ }
21
+ }
22
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../src/helpers/builder.ts"],"names":[],"mappings":";;;;;AAEA,oCAaC;AAfD,gDAAwB;AAExB,SAAgB,YAAY;IAC1B,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAM,CAAC;QACjC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEnC,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mDAAmD;QACnD,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.doYield = doYield;
4
+ function doYield() {
5
+ return new Promise((resolve) => {
6
+ setTimeout(resolve, 0);
7
+ });
8
+ }
9
+ //# sourceMappingURL=pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/helpers/pool.ts"],"names":[],"mappings":";;AAAA,0BAIC;AAJD,SAAgB,OAAO;IACrB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getCallerDir = getCallerDir;
7
6
  exports.buildWorkerCode = buildWorkerCode;
8
7
  const webpack_node_externals_1 = __importDefault(require("webpack-node-externals"));
9
8
  const path_1 = __importDefault(require("path"));
@@ -13,27 +12,13 @@ const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin")
13
12
  const BUILD_PATH = path_1.default.join(__dirname, '.out');
14
13
  const BUILD_FILENAME = 'bundle.js';
15
14
  const BUILD_FILE_PATH = path_1.default.join(BUILD_PATH, BUILD_FILENAME);
16
- function getCallerDir() {
17
- try {
18
- const stack = new Error().stack;
19
- const line = stack.split('\n')[1].trim();
20
- const segment = line.split(' ')[1];
21
- const part = segment.split(':')[0];
22
- const dirName = path_1.default.dirname(part);
23
- return dirName;
24
- }
25
- catch (e) {
26
- // console.error('building caller path failed', e);
27
- return './';
28
- }
29
- }
30
15
  function buildWorkerCode(entryFile) {
16
+ if (!fs_1.default.existsSync(BUILD_PATH)) {
17
+ fs_1.default.mkdirSync(BUILD_PATH, { recursive: true });
18
+ }
19
+ const config = getWebpackConfig(entryFile);
20
+ const compiler = (0, webpack_1.webpack)(config);
31
21
  return new Promise((resolve, reject) => {
32
- if (!fs_1.default.existsSync(BUILD_PATH)) {
33
- fs_1.default.mkdirSync(BUILD_PATH, { recursive: true });
34
- }
35
- const config = getWebpackConfig(entryFile);
36
- const compiler = (0, webpack_1.webpack)(config);
37
22
  compiler.run((err, stats) => {
38
23
  if (err) {
39
24
  reject(err);
@@ -47,21 +32,16 @@ function buildWorkerCode(entryFile) {
47
32
  */
48
33
  const bundledCode = fs_1.default
49
34
  .readFileSync(BUILD_FILE_PATH, 'utf8');
50
- resolve(bundledCode);
51
35
  // clean up the build folder
52
- fs_1.default.rm(BUILD_PATH, { recursive: true, force: true }, (err) => {
36
+ fs_1.default.rm(BUILD_PATH, { recursive: true, force: false }, (err) => {
53
37
  if (err) {
54
38
  reject(err);
55
39
  }
56
40
  });
41
+ resolve(bundledCode);
57
42
  });
58
43
  });
59
44
  }
60
- const resolveNodeModules = (packageName) => require.resolve(packageName, {
61
- paths: [
62
- path_1.default.resolve(__dirname, 'node_modules')
63
- ]
64
- });
65
45
  const getWebpackConfig = (entry) => ({
66
46
  entry,
67
47
  output: {
@@ -139,7 +119,8 @@ const getWebpackConfig = (entry) => ({
139
119
  resolveNodeModules('@babel/preset-typescript')
140
120
  ],
141
121
  plugins: [
142
- resolveNodeModules('@babel/plugin-transform-modules-commonjs')
122
+ resolveNodeModules('@babel/plugin-transform-modules-commonjs'),
123
+ [resolveNodeModules('@babel/plugin-proposal-decorators'), { "legacy": true }],
143
124
  ]
144
125
  },
145
126
  }
@@ -155,4 +136,9 @@ const getWebpackConfig = (entry) => ({
155
136
  })],
156
137
  cache: false
157
138
  });
139
+ const resolveNodeModules = (packageName) => require.resolve(packageName, {
140
+ paths: [
141
+ path_1.default.resolve(__dirname, 'node_modules')
142
+ ]
143
+ });
158
144
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/node/builder/helpers.ts"],"names":[],"mappings":";;;;;AAWA,oCAaC;AAED,0CA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AO,CAAC,SAAS,EAAE,cAAc,CAAC;KACxC;CACF,CAAC,CAAC"}
@@ -9,8 +9,9 @@ const worker_threads_1 = require("worker_threads");
9
9
  const node_adapter_js_1 = __importDefault(require("comlink/dist/umd/node-adapter.js"));
10
10
  const helpers_1 = require("./helpers");
11
11
  const path_1 = __importDefault(require("path"));
12
+ const builder_1 = require("../../helpers/builder");
12
13
  const genWorkerCodeFromFile = async (workerPath) => {
13
- const callerDir = (0, helpers_1.getCallerDir)();
14
+ const callerDir = (0, builder_1.getCallerDir)();
14
15
  const resolvedPath = path_1.default.resolve(callerDir, workerPath);
15
16
  const code = await (0, helpers_1.buildWorkerCode)(resolvedPath);
16
17
  return code;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/node/builder/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,mDAAwC;AACxC,uFAA4D;AAC5D,uCAA0D;AAC1D,gDAAwB;AAEjB,MAAM,qBAAqB,GAAG,KAAK,EACxC,UAAkB,EACD,EAAE;IACnB,MAAM,SAAS,GAAG,IAAA,sBAAY,GAAE,CAAC;IACjC,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACzD,MAAM,IAAI,GAAG,MAAM,IAAA,yBAAe,EAAC,YAAY,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC;AACd,CAAC,CAAA;AAPY,QAAA,qBAAqB,yBAOjC;AAEM,MAAM,6BAA6B,GAAG,CAC3C,IAAY,EACsC,EAAE;IAEpD,MAAM,MAAM,GAAG,IAAI,uBAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,iBAAO,CAAC,IAAI,CAAI,IAAA,yBAAY,EAAC,MAAM,CAAC,CAAC,CAAC;IAElD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AACzB,CAAC,CAAA;AARY,QAAA,6BAA6B,iCAQzC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/node/builder/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,mDAAwD;AACxD,uFAA4D;AAC5D,uCAA4C;AAC5C,gDAAwB;AACxB,mDAAqD;AAE9C,MAAM,qBAAqB,GAAG,KAAK,EACxC,UAAkB,EACD,EAAE;IACnB,MAAM,SAAS,GAAG,IAAA,sBAAY,GAAE,CAAC;IACjC,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACzD,MAAM,IAAI,GAAG,MAAM,IAAA,yBAAe,EAAC,YAAY,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC;AACd,CAAC,CAAA;AAPY,QAAA,qBAAqB,yBAOjC;AAEM,MAAM,6BAA6B,GAAG,CAC3C,IAAY,EAC4C,EAAE;IAE1D,MAAM,MAAM,GAAG,IAAI,uBAAY,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,MAAM,GAAG,GAAG,iBAAO,CAAC,IAAI,CAAI,IAAA,yBAAY,EAAC,MAAM,CAAC,CAAC,CAAC;IAElD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AACzB,CAAC,CAAA;AARY,QAAA,6BAA6B,iCAQzC"}
@@ -1,4 +1,42 @@
1
1
  "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
2
40
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
41
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
42
  };
@@ -8,59 +46,80 @@ const worker_threads_1 = require("worker_threads");
8
46
  const comlink_1 = __importDefault(require("comlink"));
9
47
  const node_adapter_1 = __importDefault(require("comlink/dist/umd/node-adapter"));
10
48
  const builder_1 = require("./builder");
11
- class NodeOmniWorker {
12
- constructor(code, worker, api) {
13
- this.isInitialized = () => (this._api !== undefined);
14
- this.use = () => {
15
- const isInitialized = this.isInitialized();
16
- if (isInitialized) {
17
- return this._api;
18
- }
19
- else {
20
- throw Error('worker is not yet initialized. make sure to call the .set() function, first');
21
- }
22
- };
23
- this.clone = (numOfTimes) => {
24
- const workers = [];
25
- for (let i = 0; i <= numOfTimes; i++) {
49
+ const helpers_1 = require("../types/helpers");
50
+ /**
51
+ * OmniWorker for NodeJS
52
+ */
53
+ let NodeOmniWorker = (() => {
54
+ let _classDecorators = [(0, helpers_1.staticImplements)(), (0, helpers_1.staticImplements)()];
55
+ let _classDescriptor;
56
+ let _classExtraInitializers = [];
57
+ let _classThis;
58
+ var NodeOmniWorker = _classThis = class {
59
+ constructor(code, worker, api) {
60
+ this.isInitialized = () => (this._api !== undefined);
61
+ this.use = () => {
62
+ const isInitialized = this.isInitialized();
63
+ if (isInitialized) {
64
+ return this._api;
65
+ }
66
+ else {
67
+ throw Error('worker is not yet initialized. make sure to call the build() function, first');
68
+ }
69
+ };
70
+ this.clone = (numOfTimes) => {
71
+ const workers = [];
26
72
  const code = this._code;
27
- const { worker, api } = (0, builder_1.buildNodeApiAndWorkerFromCode)(code);
28
- workers.push(new NodeOmniWorker(code, worker, api));
29
- }
30
- return workers;
31
- };
32
- this.destroy = async () => {
33
- await this._worker.terminate();
34
- };
35
- this._code = code;
36
- this._worker = worker;
37
- this._api = api;
38
- return this;
39
- }
73
+ for (let i = 0; i <= numOfTimes; i++) {
74
+ const { worker, api } = (0, builder_1.buildNodeApiAndWorkerFromCode)(code);
75
+ workers.push(new NodeOmniWorker(code, worker, api));
76
+ }
77
+ return workers;
78
+ };
79
+ this.destroy = async () => {
80
+ await this._worker.terminate();
81
+ };
82
+ this._code = code;
83
+ this._worker = worker;
84
+ this._api = api;
85
+ return this;
86
+ }
87
+ /**
88
+ * Handles the building of the necessary resources for an OmniWorker to function.
89
+ * This usually means, building from the consumer's code, creating the comlink
90
+ * interface between the worker and the main thread as well as the worker itself.
91
+ *
92
+ * @param path Relative path FROM YOUR PROJECT's ROOT to the file to be the worker
93
+ * @returns An OmniWorker
94
+ */
95
+ static async build(path) {
96
+ const code = await (0, builder_1.genWorkerCodeFromFile)(path);
97
+ const { worker, api } = (0, builder_1.buildNodeApiAndWorkerFromCode)(code);
98
+ return new NodeOmniWorker(code, worker, api);
99
+ }
100
+ };
101
+ __setFunctionName(_classThis, "NodeOmniWorker");
102
+ (() => {
103
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
104
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
105
+ NodeOmniWorker = _classThis = _classDescriptor.value;
106
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
107
+ })();
40
108
  /**
41
- * Build the OmniWorker from a worker file. Please note that the functions
42
- * on the worker file need to first be exposed using the expose({ <functions> })
43
- * functions, in order to start this build step.
44
- *
45
- * @param path The relative path to where the worker module is located
46
- * @returns A new Node OmniWorker
109
+ * Expose the functions inside the worker to the rest of the application.
110
+ * After having exposed the functions, the build step can be initiated.
111
+ * @param exposable A class, object with functions or a single function to be
112
+ * exposed to the main thread.
47
113
  */
48
- static async build(path) {
49
- const code = await (0, builder_1.genWorkerCodeFromFile)(path);
50
- const { worker, api } = (0, builder_1.buildNodeApiAndWorkerFromCode)(code);
51
- return new NodeOmniWorker(code, worker, api);
52
- }
53
- }
114
+ _classThis.expose = (exposable) => {
115
+ if (worker_threads_1.parentPort) {
116
+ comlink_1.default.expose(exposable, (0, node_adapter_1.default)(worker_threads_1.parentPort));
117
+ }
118
+ };
119
+ (() => {
120
+ __runInitializers(_classThis, _classExtraInitializers);
121
+ })();
122
+ return NodeOmniWorker = _classThis;
123
+ })();
54
124
  exports.NodeOmniWorker = NodeOmniWorker;
55
- /**
56
- * Expose the functions inside the worker to the rest of the application.
57
- * After having exposed the functions, the build step can be initiated.
58
- * @param functions An object with functions inside the worker to be exposed to
59
- * the rest of the application.
60
- */
61
- NodeOmniWorker.expose = (functions) => {
62
- if (worker_threads_1.parentPort) {
63
- comlink_1.default.expose(functions, (0, node_adapter_1.default)(worker_threads_1.parentPort));
64
- }
65
- };
66
125
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":";;;;;;AACA,mDAAoD;AACpD,sDAA8B;AAC9B,iFAAyD;AACzD,uCAAiF;AAGjF,MAAa,cAAc;IAKzB,YACE,IAAY,EACZ,MAAc,EACd,GAA4B;QAoCvB,kBAAa,GAAG,GAAY,EAAE,CAAC,CACpC,IAAI,CAAC,IAAI,KAAK,SAAS,CACxB,CAAC;QAEK,QAAG,GAAG,GAAG,EAAE;YAChB,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YAC3C,IAAI,aAAa,EAAE,CAAC;gBAClB,OAAO,IAAI,CAAC,IAAK,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,CAAC,6EAA6E,CAAC,CAAC;YAC7F,CAAC;QACH,CAAC,CAAA;QAEM,UAAK,GAAG,CAAC,UAAkB,EAAE,EAAE;YACpC,MAAM,OAAO,GAAwB,EAAE,CAAC;YACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;gBACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;gBACxB,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,uCAA6B,EAAI,IAAI,CAAC,CAAC;gBAC/D,OAAO,CAAC,IAAI,CAAC,IAAI,cAAc,CAAI,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;YACzD,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC,CAAA;QAEM,YAAO,GAAG,KAAK,IAAI,EAAE;YAC1B,MAAM,IAAI,CAAC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