@rvoh/psychic-workers 0.2.1

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 (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/cjs/src/background/BaseBackgroundedModel.js +50 -0
  4. package/dist/cjs/src/background/BaseBackgroundedService.js +40 -0
  5. package/dist/cjs/src/background/BaseScheduledService.js +31 -0
  6. package/dist/cjs/src/background/index.js +529 -0
  7. package/dist/cjs/src/background/types.js +2 -0
  8. package/dist/cjs/src/error/background/NoQueueForSpecifiedQueueName.js +15 -0
  9. package/dist/cjs/src/error/background/NoQueueForSpecifiedWorkstream.js +15 -0
  10. package/dist/cjs/src/helpers/EnvInternal.js +5 -0
  11. package/dist/cjs/src/index.js +19 -0
  12. package/dist/cjs/src/psychic-application-workers/cache.js +17 -0
  13. package/dist/cjs/src/psychic-application-workers/index.js +77 -0
  14. package/dist/esm/src/background/BaseBackgroundedModel.js +47 -0
  15. package/dist/esm/src/background/BaseBackgroundedService.js +37 -0
  16. package/dist/esm/src/background/BaseScheduledService.js +28 -0
  17. package/dist/esm/src/background/index.js +524 -0
  18. package/dist/esm/src/background/types.js +1 -0
  19. package/dist/esm/src/error/background/NoQueueForSpecifiedQueueName.js +12 -0
  20. package/dist/esm/src/error/background/NoQueueForSpecifiedWorkstream.js +12 -0
  21. package/dist/esm/src/helpers/EnvInternal.js +3 -0
  22. package/dist/esm/src/index.js +7 -0
  23. package/dist/esm/src/psychic-application-workers/cache.js +12 -0
  24. package/dist/esm/src/psychic-application-workers/index.js +74 -0
  25. package/dist/types/src/background/BaseBackgroundedModel.d.ts +15 -0
  26. package/dist/types/src/background/BaseBackgroundedService.d.ts +17 -0
  27. package/dist/types/src/background/BaseScheduledService.d.ts +11 -0
  28. package/dist/types/src/background/index.d.ts +101 -0
  29. package/dist/types/src/background/types.d.ts +7 -0
  30. package/dist/types/src/error/background/NoQueueForSpecifiedQueueName.d.ts +5 -0
  31. package/dist/types/src/error/background/NoQueueForSpecifiedWorkstream.d.ts +5 -0
  32. package/dist/types/src/helpers/EnvInternal.d.ts +6 -0
  33. package/dist/types/src/index.d.ts +7 -0
  34. package/dist/types/src/psychic-application-workers/cache.d.ts +4 -0
  35. package/dist/types/src/psychic-application-workers/index.d.ts +200 -0
  36. package/package.json +74 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 RVO Health
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ > ATTENTION: we are currently in the process of releasing this code to the world, as of the afternoon of March 10th, 2025. This notice will be removed, and the version of this repo will be bumped to 1.0.0, once all of the repos have been migrated to the new spaces and we can verify that it is all working. This is anticipated to take 1 day.
2
+
3
+ # Psychic workers
4
+
5
+ Documentation for this repo can be found at [https://psychic-docs.netlify.app/docs/plugins/workers/overview](https://psychic-docs.netlify.app/docs/plugins/workers/overview)
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dream_1 = require("@rvoh/dream");
4
+ const index_js_1 = require("./index.js");
5
+ class BaseBackgroundedModel extends dream_1.Dream {
6
+ static get backgroundJobConfig() {
7
+ return {};
8
+ }
9
+ get backgroundJobConfig() {
10
+ const klass = this.constructor;
11
+ return klass.backgroundJobConfig;
12
+ }
13
+ static async background(methodName, ...args) {
14
+ const safeThis = this;
15
+ return await index_js_1.default.staticMethod(safeThis, methodName, {
16
+ globalName: safeThis.globalName,
17
+ args,
18
+ jobConfig: safeThis.backgroundJobConfig,
19
+ });
20
+ }
21
+ static async backgroundWithDelay(delaySeconds, methodName, ...args) {
22
+ const safeThis = this;
23
+ return await index_js_1.default.staticMethod(safeThis, methodName, {
24
+ globalName: safeThis.globalName,
25
+ delaySeconds,
26
+ args,
27
+ jobConfig: safeThis.backgroundJobConfig,
28
+ });
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ get psychicTypes() {
32
+ throw new Error('Must define psychicTypes getter in BackgroundedService class within your application');
33
+ }
34
+ async background(methodName, ...args) {
35
+ const safeThis = this;
36
+ return await index_js_1.default.modelInstanceMethod(safeThis, methodName, {
37
+ args,
38
+ jobConfig: safeThis.backgroundJobConfig,
39
+ });
40
+ }
41
+ async backgroundWithDelay(delaySeconds, methodName, ...args) {
42
+ const safeThis = this;
43
+ return await index_js_1.default.modelInstanceMethod(safeThis, methodName, {
44
+ args,
45
+ delaySeconds,
46
+ jobConfig: safeThis.backgroundJobConfig,
47
+ });
48
+ }
49
+ }
50
+ exports.default = BaseBackgroundedModel;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dream_1 = require("@rvoh/dream");
4
+ const index_js_1 = require("./index.js");
5
+ class BaseBackgroundedService {
6
+ static get backgroundJobConfig() {
7
+ return {};
8
+ }
9
+ static get globalName() {
10
+ if (!this._globalName)
11
+ throw new dream_1.GlobalNameNotSet(this);
12
+ return this._globalName;
13
+ }
14
+ static setGlobalName(globalName) {
15
+ this._globalName = globalName;
16
+ }
17
+ static _globalName;
18
+ static async background(methodName, ...args) {
19
+ const safeThis = this;
20
+ return await index_js_1.default.staticMethod(safeThis, methodName, {
21
+ globalName: safeThis.globalName,
22
+ args,
23
+ jobConfig: safeThis.backgroundJobConfig,
24
+ });
25
+ }
26
+ static async backgroundWithDelay(delaySeconds, methodName, ...args) {
27
+ const safeThis = this;
28
+ return await index_js_1.default.staticMethod(safeThis, methodName, {
29
+ globalName: safeThis.globalName,
30
+ delaySeconds,
31
+ args,
32
+ jobConfig: safeThis.backgroundJobConfig,
33
+ });
34
+ }
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+ get psychicTypes() {
37
+ throw new Error('Must define psychicTypes getter in BackgroundedService class within your application');
38
+ }
39
+ }
40
+ exports.default = BaseBackgroundedService;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dream_1 = require("@rvoh/dream");
4
+ const index_js_1 = require("./index.js");
5
+ class BaseScheduledService {
6
+ static get backgroundJobConfig() {
7
+ return {};
8
+ }
9
+ static get globalName() {
10
+ if (!this._globalName)
11
+ throw new dream_1.GlobalNameNotSet(this);
12
+ return this._globalName;
13
+ }
14
+ static setGlobalName(globalName) {
15
+ this._globalName = globalName;
16
+ }
17
+ static _globalName;
18
+ static async schedule(pattern, methodName, ...args) {
19
+ const safeThis = this;
20
+ return await index_js_1.default.scheduledMethod(safeThis, pattern, methodName, {
21
+ globalName: safeThis.globalName,
22
+ args,
23
+ jobConfig: safeThis.backgroundJobConfig,
24
+ });
25
+ }
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ get psychicTypes() {
28
+ throw new Error('Must define psychicTypes getter in BackgroundedService class within your application');
29
+ }
30
+ }
31
+ exports.default = BaseScheduledService;