@nestjs/workflows 0.0.2 → 0.0.4

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 (35) hide show
  1. package/dist/core/interfaces/result-waiter-options.interface.d.ts +6 -2
  2. package/dist/core/results/result-waiter.d.ts +5 -3
  3. package/dist/core/results/result-waiter.js +34 -10
  4. package/dist/core/utils/timer.util.d.ts +12 -0
  5. package/dist/core/utils/timer.util.js +16 -0
  6. package/dist/core/workers/leased-worker.js +4 -3
  7. package/dist/cqrs/workflow-event.publisher.js +3 -3
  8. package/dist/index.d.ts +1 -1
  9. package/dist/interfaces/workflow-client.interface.d.ts +4 -1
  10. package/dist/interfaces/workflow-context.interface.d.ts +2 -2
  11. package/dist/interfaces/workflow-store.interface.d.ts +29 -1
  12. package/dist/mysql/interfaces/mysql-workflow-store-options.interface.d.ts +1 -1
  13. package/dist/mysql/mysql-workflow.store.d.ts +10 -2
  14. package/dist/mysql/mysql-workflow.store.js +27 -4
  15. package/dist/postgres/interfaces/postgres-workflow-store-options.interface.d.ts +1 -1
  16. package/dist/postgres/postgres-workflow.store.d.ts +6 -1
  17. package/dist/postgres/postgres-workflow.store.js +8 -0
  18. package/dist/services/workflow-client.service.d.ts +11 -2
  19. package/dist/services/workflow-client.service.js +23 -5
  20. package/dist/services/workflow-execution.service.d.ts +11 -0
  21. package/dist/services/workflow-execution.service.js +61 -4
  22. package/dist/services/workflow-scheduler.service.d.ts +8 -0
  23. package/dist/services/workflow-scheduler.service.js +20 -1
  24. package/dist/services/workflow-schedules.service.js +2 -0
  25. package/dist/services/workflow-worker.service.js +3 -0
  26. package/dist/storage/encoded-workflow.store.d.ts +12 -0
  27. package/dist/storage/encoded-workflow.store.js +42 -3
  28. package/dist/utils/index.d.ts +1 -0
  29. package/dist/utils/index.js +1 -0
  30. package/dist/utils/new-instance.util.d.ts +3 -0
  31. package/dist/utils/new-instance.util.js +9 -2
  32. package/dist/utils/serialize-error.util.js +25 -1
  33. package/dist/utils/storable-text.util.d.ts +36 -0
  34. package/dist/utils/storable-text.util.js +96 -0
  35. package/package.json +27 -26
@@ -0,0 +1,96 @@
1
+ /** `'U+0000'` when `text` holds it (PostgreSQL keeps it in neither `text` nor `jsonb`), else `undefined`. */
2
+ export function nulIn(text) {
3
+ return text.includes('\u0000') ? 'U+0000' : undefined;
4
+ }
5
+ /** `'a lone UTF-16 surrogate'` when `text` holds one (PostgreSQL and MySQL refuse it in JSON), else `undefined`. */
6
+ export function loneSurrogateIn(text) {
7
+ return text.isWellFormed() ? undefined : 'a lone UTF-16 surrogate';
8
+ }
9
+ /**
10
+ * The first string of a JSON value (what `JSON.parse()` returns), a value or an object's key, that `check` refuses,
11
+ * with its path (`$.lines[0].note`), or `undefined`. Walks with a stack of its own, so a value as deep as
12
+ * `JSON.stringify()` takes can't overflow the call stack; the path is built only for what it finds.
13
+ */
14
+ export function findUnstorableText(value, check) {
15
+ const pending = [{ value, parent: undefined, at: undefined }];
16
+ for (let step = pending.pop(); step; step = pending.pop()) {
17
+ if (step.keyProblem) {
18
+ return { path: `${pathOf(step)} (its key)`, problem: step.keyProblem };
19
+ }
20
+ const current = step.value;
21
+ if (typeof current === 'string') {
22
+ const problem = check(current);
23
+ if (problem) {
24
+ return { path: pathOf(step), problem };
25
+ }
26
+ }
27
+ else if (Array.isArray(current)) {
28
+ // Last first, so the first is checked first. Numbers, booleans and null hold no text.
29
+ for (let i = current.length - 1; i >= 0; i--) {
30
+ if (holdsText(current[i])) {
31
+ pending.push({ value: current[i], parent: step, at: i });
32
+ }
33
+ }
34
+ }
35
+ else if (current !== null && typeof current === 'object') {
36
+ const keys = Object.keys(current);
37
+ for (let i = keys.length - 1; i >= 0; i--) {
38
+ const key = keys[i];
39
+ const child = current[key];
40
+ const keyProblem = check(key);
41
+ if (keyProblem || holdsText(child)) {
42
+ pending.push({ value: child, parent: step, at: key, keyProblem });
43
+ }
44
+ }
45
+ }
46
+ }
47
+ return undefined;
48
+ }
49
+ /** Throws a `TypeError` that names `what` when `check` refuses `text`. */
50
+ export function assertStorableText(what, text, check) {
51
+ const problem = check && typeof text === 'string' ? check(text) : undefined;
52
+ if (problem) {
53
+ throw unstorable(what, problem);
54
+ }
55
+ }
56
+ /** The same for a JSON value (what `normalize()` returns), naming where in `what` the text sits. */
57
+ export function assertStorableJson(what, value, check) {
58
+ const refused = unstorableJson(what, value, check);
59
+ if (refused) {
60
+ throw refused;
61
+ }
62
+ }
63
+ /** `assertStorableJson()`'s error, for a caller that reports it in its own way, or `undefined`. */
64
+ export function unstorableJson(what, value, check) {
65
+ const found = check && findUnstorableText(value, check);
66
+ return found ? unstorable(`${what} at ${found.path}`, found.problem) : undefined;
67
+ }
68
+ /**
69
+ * `text`, with U+0000 and lone surrogates replaced with U+FFFD when `check` refuses it: for an error's text, which is
70
+ * recorded whatever it holds.
71
+ */
72
+ export function storableText(text, check) {
73
+ return check?.(text) === undefined ? text : text.replaceAll('\u0000', '�').toWellFormed();
74
+ }
75
+ function unstorable(where, problem) {
76
+ return new TypeError(`${where} holds ${problem}, which the workflow store can't keep.`);
77
+ }
78
+ function holdsText(value) {
79
+ return typeof value === 'string' || (value !== null && typeof value === 'object');
80
+ }
81
+ function pathOf(step) {
82
+ let path = '';
83
+ for (let at = step; at; at = at.parent) {
84
+ path = segment(at.at) + path;
85
+ }
86
+ return path;
87
+ }
88
+ function segment(at) {
89
+ if (at === undefined) {
90
+ return '$';
91
+ }
92
+ if (typeof at === 'number') {
93
+ return `[${at}]`;
94
+ }
95
+ return /^[A-Za-z_$][\w$]*$/.test(at) ? `.${at}` : `[${JSON.stringify(at)}]`;
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/workflows",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@workflows)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -51,6 +51,7 @@
51
51
  "build": "rm -rf dist && tsc -p tsconfig.build.json",
52
52
  "format": "prettier --write \"**/*.ts\"",
53
53
  "lint": "oxlint lib/",
54
+ "typecheck": "tsc --noEmit -p tsconfig.json",
54
55
  "generate:prisma": "prisma generate --config tests/fixtures/prisma/prisma.config.ts && prisma generate --config tests/fixtures/prisma-mysql/prisma.config.ts",
55
56
  "prepublish:npm": "npm run build",
56
57
  "publish:npm": "npm publish --access public",
@@ -66,40 +67,40 @@
66
67
  "@nestjs/store-kit": "^0.1.0"
67
68
  },
68
69
  "devDependencies": {
69
- "@commitlint/cli": "21.2.3",
70
- "@commitlint/config-angular": "21.2.3",
71
- "@electric-sql/pglite": "0.5.8",
72
- "@nestjs/common": "12.1.2",
73
- "@nestjs/core": "12.1.2",
74
- "@nestjs/cqrs": "12.1.0",
75
- "@nestjs/drizzle": "0.0.1",
76
- "@nestjs/locks": "0.0.1",
70
+ "@commitlint/cli": "21.2.4",
71
+ "@commitlint/config-angular": "21.2.4",
72
+ "@electric-sql/pglite": "0.5.12",
73
+ "@nestjs/common": "12.2.0",
74
+ "@nestjs/core": "12.2.0",
75
+ "@nestjs/cqrs": "12.1.1",
76
+ "@nestjs/drizzle": "0.0.2",
77
+ "@nestjs/locks": "0.0.4",
77
78
  "@nestjs/mail": "0.0.1",
78
- "@nestjs/outbox": "0.1.0",
79
- "@nestjs/platform-express": "12.1.2",
80
- "@nestjs/platform-fastify": "12.1.2",
81
- "@nestjs/testing": "12.1.2",
82
- "@prisma/adapter-mariadb": "7.10.0",
83
- "@prisma/adapter-pg": "7.10.0",
84
- "@prisma/client": "7.10.0",
85
- "@types/node": "24.19.1",
79
+ "@nestjs/outbox": "0.1.3",
80
+ "@nestjs/platform-express": "12.2.0",
81
+ "@nestjs/platform-fastify": "12.2.0",
82
+ "@nestjs/testing": "12.2.0",
83
+ "@prisma/adapter-mariadb": "7.10.1",
84
+ "@prisma/adapter-pg": "7.10.1",
85
+ "@prisma/client": "7.10.1",
86
+ "@types/node": "24.19.2",
86
87
  "@types/pg": "8.23.1",
87
- "drizzle-orm": "0.45.3",
88
+ "drizzle-orm": "0.45.4",
88
89
  "husky": "9.1.7",
89
- "kysely": "0.29.6",
90
+ "kysely": "0.29.7",
90
91
  "lint-staged": "17.6.0",
91
- "mysql2": "3.24.5",
92
- "oxlint": "1.87.0",
92
+ "mysql2": "3.24.6",
93
+ "oxlint": "1.89.0",
93
94
  "pg": "8.23.1",
94
- "prettier": "3.9.9",
95
- "prisma": "7.10.0",
95
+ "prettier": "3.9.10",
96
+ "prisma": "7.10.1",
96
97
  "reflect-metadata": "0.2.2",
97
98
  "release-it": "21.1.1",
98
99
  "rxjs": "7.8.2",
99
- "typeorm": "1.1.1",
100
+ "typeorm": "1.1.2",
100
101
  "typescript": "7.0.2",
101
- "vite": "8.3.3",
102
- "vitest": "5.0.3"
102
+ "vite": "8.3.5",
103
+ "vitest": "5.0.5"
103
104
  },
104
105
  "peerDependencies": {
105
106
  "@nestjs/common": "^11.0.0 || ^12.0.0",