@hotmeshio/hotmesh 0.9.0 → 0.10.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/README.md +38 -23
- package/build/index.d.ts +12 -11
- package/build/index.js +15 -13
- package/build/modules/enums.d.ts +23 -34
- package/build/modules/enums.js +26 -38
- package/build/modules/errors.d.ts +16 -16
- package/build/modules/errors.js +37 -37
- package/build/package.json +23 -22
- package/build/services/activities/activity.js +1 -1
- package/build/services/dba/index.d.ts +171 -0
- package/build/services/dba/index.js +280 -0
- package/build/services/{memflow → durable}/client.d.ts +3 -3
- package/build/services/{memflow → durable}/client.js +13 -13
- package/build/services/{memflow → durable}/connection.d.ts +2 -2
- package/build/services/{memflow → durable}/connection.js +1 -1
- package/build/services/{memflow → durable}/exporter.d.ts +6 -6
- package/build/services/{memflow → durable}/exporter.js +2 -2
- package/build/services/{memflow → durable}/handle.d.ts +4 -4
- package/build/services/{memflow → durable}/handle.js +2 -2
- package/build/services/{memflow → durable}/index.d.ts +125 -33
- package/build/services/{memflow → durable}/index.js +145 -49
- package/build/services/{memflow → durable}/interceptor.d.ts +45 -22
- package/build/services/{memflow → durable}/interceptor.js +54 -21
- package/build/services/{memflow → durable}/schemas/factory.d.ts +4 -4
- package/build/services/{memflow → durable}/schemas/factory.js +5 -5
- package/build/services/{memflow → durable}/search.d.ts +1 -1
- package/build/services/{memflow → durable}/search.js +4 -4
- package/build/services/{memflow → durable}/worker.d.ts +11 -11
- package/build/services/{memflow → durable}/worker.js +61 -60
- package/build/services/{memflow → durable}/workflow/all.d.ts +5 -5
- package/build/services/{memflow → durable}/workflow/all.js +5 -5
- package/build/services/{memflow → durable}/workflow/common.d.ts +5 -5
- package/build/services/durable/workflow/common.js +47 -0
- package/build/services/{memflow → durable}/workflow/context.d.ts +5 -5
- package/build/services/{memflow → durable}/workflow/context.js +5 -5
- package/build/services/{memflow → durable}/workflow/emit.d.ts +5 -5
- package/build/services/{memflow → durable}/workflow/emit.js +5 -5
- package/build/services/{memflow → durable}/workflow/enrich.d.ts +4 -4
- package/build/services/{memflow → durable}/workflow/enrich.js +4 -4
- package/build/services/{memflow → durable}/workflow/entityMethods.d.ts +4 -4
- package/build/services/{memflow → durable}/workflow/entityMethods.js +4 -4
- package/build/services/{memflow → durable}/workflow/execChild.d.ts +9 -9
- package/build/services/{memflow → durable}/workflow/execChild.js +22 -22
- package/build/services/{memflow → durable}/workflow/execHook.d.ts +8 -8
- package/build/services/{memflow → durable}/workflow/execHook.js +10 -10
- package/build/services/{memflow → durable}/workflow/execHookBatch.d.ts +5 -5
- package/build/services/{memflow → durable}/workflow/execHookBatch.js +8 -8
- package/build/services/{memflow → durable}/workflow/hook.d.ts +5 -5
- package/build/services/{memflow → durable}/workflow/hook.js +11 -11
- package/build/services/{memflow → durable}/workflow/index.d.ts +6 -6
- package/build/services/{memflow → durable}/workflow/index.js +6 -6
- package/build/services/{memflow → durable}/workflow/interrupt.d.ts +7 -7
- package/build/services/{memflow → durable}/workflow/interrupt.js +7 -7
- package/build/services/{memflow → durable}/workflow/interruption.d.ts +10 -10
- package/build/services/{memflow → durable}/workflow/interruption.js +19 -19
- package/build/services/{memflow → durable}/workflow/proxyActivities.d.ts +7 -7
- package/build/services/{memflow → durable}/workflow/proxyActivities.js +31 -21
- package/build/services/{memflow → durable}/workflow/random.d.ts +4 -4
- package/build/services/{memflow → durable}/workflow/random.js +4 -4
- package/build/services/{memflow → durable}/workflow/searchMethods.d.ts +5 -5
- package/build/services/{memflow → durable}/workflow/searchMethods.js +5 -5
- package/build/services/{memflow → durable}/workflow/signal.d.ts +8 -8
- package/build/services/{memflow → durable}/workflow/signal.js +8 -8
- package/build/services/{memflow → durable}/workflow/sleepFor.d.ts +7 -7
- package/build/services/{memflow → durable}/workflow/sleepFor.js +10 -10
- package/build/services/{memflow → durable}/workflow/trace.d.ts +5 -5
- package/build/services/{memflow → durable}/workflow/trace.js +5 -5
- package/build/services/{memflow → durable}/workflow/waitFor.d.ts +9 -9
- package/build/services/{memflow → durable}/workflow/waitFor.js +12 -12
- package/build/services/hotmesh/index.d.ts +3 -3
- package/build/services/hotmesh/index.js +3 -3
- package/build/services/{meshcall → virtual}/index.d.ts +29 -29
- package/build/services/{meshcall → virtual}/index.js +49 -49
- package/build/services/{meshcall → virtual}/schemas/factory.d.ts +1 -1
- package/build/services/{meshcall → virtual}/schemas/factory.js +1 -1
- package/build/types/dba.d.ts +64 -0
- package/build/types/{memflow.d.ts → durable.d.ts} +74 -18
- package/build/types/error.d.ts +5 -5
- package/build/types/exporter.d.ts +1 -1
- package/build/types/index.d.ts +5 -4
- package/build/types/{meshcall.d.ts → virtual.d.ts} +15 -15
- package/build/types/virtual.js +2 -0
- package/index.ts +15 -13
- package/package.json +23 -22
- package/.claude/settings.local.json +0 -8
- package/build/services/memflow/workflow/common.js +0 -47
- package/build/vitest.config.d.ts +0 -2
- package/build/vitest.config.js +0 -18
- /package/build/services/{memflow → durable}/entity.d.ts +0 -0
- /package/build/services/{memflow → durable}/entity.js +0 -0
- /package/build/services/{memflow → durable}/workflow/didRun.d.ts +0 -0
- /package/build/services/{memflow → durable}/workflow/didRun.js +0 -0
- /package/build/services/{memflow → durable}/workflow/isSideEffectAllowed.d.ts +0 -0
- /package/build/services/{memflow → durable}/workflow/isSideEffectAllowed.js +0 -0
- /package/build/types/{memflow.js → dba.js} +0 -0
- /package/build/types/{meshcall.js → durable.js} +0 -0
package/build/modules/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SetStateError = exports.RegisterTimeoutError = exports.MapDataError = exports.InactiveJobError = exports.GetStateError = exports.GenerationalError = exports.ExecActivityError = exports.DuplicateJobError = exports.
|
|
3
|
+
exports.SetStateError = exports.RegisterTimeoutError = exports.MapDataError = exports.InactiveJobError = exports.GetStateError = exports.GenerationalError = exports.ExecActivityError = exports.DuplicateJobError = exports.DurableWaitForError = exports.DurableWaitForAllError = exports.DurableTimeoutError = exports.DurableSleepError = exports.DurableRetryError = exports.DurableProxyError = exports.DurableMaxedError = exports.DurableFatalError = exports.DurableChildError = exports.CollationError = void 0;
|
|
4
4
|
const enums_1 = require("./enums");
|
|
5
5
|
class GetStateError extends Error {
|
|
6
6
|
constructor(jobId) {
|
|
@@ -16,21 +16,21 @@ class SetStateError extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.SetStateError = SetStateError;
|
|
19
|
-
class
|
|
19
|
+
class DurableWaitForError extends Error {
|
|
20
20
|
constructor(params) {
|
|
21
21
|
super(`WaitFor Interruption`);
|
|
22
|
-
this.type = '
|
|
22
|
+
this.type = 'DurableWaitForError';
|
|
23
23
|
this.signalId = params.signalId;
|
|
24
24
|
this.index = params.index;
|
|
25
25
|
this.workflowDimension = params.workflowDimension;
|
|
26
|
-
this.code = enums_1.
|
|
26
|
+
this.code = enums_1.HMSH_CODE_DURABLE_WAIT;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
exports.
|
|
30
|
-
class
|
|
29
|
+
exports.DurableWaitForError = DurableWaitForError;
|
|
30
|
+
class DurableProxyError extends Error {
|
|
31
31
|
constructor(params) {
|
|
32
32
|
super(`ProxyActivity Interruption`);
|
|
33
|
-
this.type = '
|
|
33
|
+
this.type = 'DurableProxyError';
|
|
34
34
|
this.arguments = params.arguments;
|
|
35
35
|
this.workflowId = params.workflowId;
|
|
36
36
|
this.workflowTopic = params.workflowTopic;
|
|
@@ -43,14 +43,14 @@ class MemFlowProxyError extends Error {
|
|
|
43
43
|
this.backoffCoefficient = params.backoffCoefficient;
|
|
44
44
|
this.maximumAttempts = params.maximumAttempts;
|
|
45
45
|
this.maximumInterval = params.maximumInterval;
|
|
46
|
-
this.code = enums_1.
|
|
46
|
+
this.code = enums_1.HMSH_CODE_DURABLE_PROXY;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
exports.
|
|
50
|
-
class
|
|
49
|
+
exports.DurableProxyError = DurableProxyError;
|
|
50
|
+
class DurableChildError extends Error {
|
|
51
51
|
constructor(params) {
|
|
52
52
|
super(`ExecChild Interruption`);
|
|
53
|
-
this.type = '
|
|
53
|
+
this.type = 'DurableChildError';
|
|
54
54
|
this.arguments = params.arguments;
|
|
55
55
|
this.workflowId = params.workflowId;
|
|
56
56
|
this.workflowTopic = params.workflowTopic;
|
|
@@ -62,18 +62,18 @@ class MemFlowChildError extends Error {
|
|
|
62
62
|
this.entity = params.entity;
|
|
63
63
|
this.index = params.index;
|
|
64
64
|
this.workflowDimension = params.workflowDimension;
|
|
65
|
-
this.code = enums_1.
|
|
65
|
+
this.code = enums_1.HMSH_CODE_DURABLE_CHILD;
|
|
66
66
|
this.await = params.await;
|
|
67
67
|
this.backoffCoefficient = params.backoffCoefficient;
|
|
68
68
|
this.maximumAttempts = params.maximumAttempts;
|
|
69
69
|
this.maximumInterval = params.maximumInterval;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
exports.
|
|
73
|
-
class
|
|
72
|
+
exports.DurableChildError = DurableChildError;
|
|
73
|
+
class DurableWaitForAllError extends Error {
|
|
74
74
|
constructor(params) {
|
|
75
75
|
super(`Collation Interruption`);
|
|
76
|
-
this.type = '
|
|
76
|
+
this.type = 'DurableWaitForAllError';
|
|
77
77
|
this.items = params.items;
|
|
78
78
|
this.size = params.size;
|
|
79
79
|
this.workflowId = params.workflowId;
|
|
@@ -82,66 +82,66 @@ class MemFlowWaitForAllError extends Error {
|
|
|
82
82
|
this.originJobId = params.originJobId;
|
|
83
83
|
this.index = params.index;
|
|
84
84
|
this.workflowDimension = params.workflowDimension;
|
|
85
|
-
this.code = enums_1.
|
|
85
|
+
this.code = enums_1.HMSH_CODE_DURABLE_ALL;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
exports.
|
|
89
|
-
class
|
|
88
|
+
exports.DurableWaitForAllError = DurableWaitForAllError;
|
|
89
|
+
class DurableSleepError extends Error {
|
|
90
90
|
constructor(params) {
|
|
91
91
|
super(`SleepFor Interruption`);
|
|
92
|
-
this.type = '
|
|
92
|
+
this.type = 'DurableSleepError';
|
|
93
93
|
this.duration = params.duration;
|
|
94
94
|
this.workflowId = params.workflowId;
|
|
95
95
|
this.index = params.index;
|
|
96
96
|
this.workflowDimension = params.workflowDimension;
|
|
97
|
-
this.code = enums_1.
|
|
97
|
+
this.code = enums_1.HMSH_CODE_DURABLE_SLEEP;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
exports.
|
|
101
|
-
class
|
|
100
|
+
exports.DurableSleepError = DurableSleepError;
|
|
101
|
+
class DurableTimeoutError extends Error {
|
|
102
102
|
constructor(message, stack) {
|
|
103
103
|
super(message);
|
|
104
|
-
this.type = '
|
|
104
|
+
this.type = 'DurableTimeoutError';
|
|
105
105
|
if (this.stack) {
|
|
106
106
|
this.stack = stack;
|
|
107
107
|
}
|
|
108
|
-
this.code = enums_1.
|
|
108
|
+
this.code = enums_1.HMSH_CODE_DURABLE_TIMEOUT;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
exports.
|
|
112
|
-
class
|
|
111
|
+
exports.DurableTimeoutError = DurableTimeoutError;
|
|
112
|
+
class DurableMaxedError extends Error {
|
|
113
113
|
constructor(message, stackTrace) {
|
|
114
114
|
super(message);
|
|
115
|
-
this.type = '
|
|
115
|
+
this.type = 'DurableMaxedError';
|
|
116
116
|
if (stackTrace) {
|
|
117
117
|
this.stack = stackTrace;
|
|
118
118
|
}
|
|
119
|
-
this.code = enums_1.
|
|
119
|
+
this.code = enums_1.HMSH_CODE_DURABLE_MAXED;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
exports.
|
|
123
|
-
class
|
|
122
|
+
exports.DurableMaxedError = DurableMaxedError;
|
|
123
|
+
class DurableFatalError extends Error {
|
|
124
124
|
constructor(message, stackTrace) {
|
|
125
125
|
super(message);
|
|
126
|
-
this.type = '
|
|
126
|
+
this.type = 'DurableFatalError';
|
|
127
127
|
if (stackTrace) {
|
|
128
128
|
this.stack = stackTrace;
|
|
129
129
|
}
|
|
130
|
-
this.code = enums_1.
|
|
130
|
+
this.code = enums_1.HMSH_CODE_DURABLE_FATAL;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
exports.
|
|
134
|
-
class
|
|
133
|
+
exports.DurableFatalError = DurableFatalError;
|
|
134
|
+
class DurableRetryError extends Error {
|
|
135
135
|
constructor(message, stackTrace) {
|
|
136
136
|
super(message);
|
|
137
|
-
this.type = '
|
|
137
|
+
this.type = 'DurableRetryError';
|
|
138
138
|
if (stackTrace) {
|
|
139
139
|
this.stack = stackTrace;
|
|
140
140
|
}
|
|
141
|
-
this.code = enums_1.
|
|
141
|
+
this.code = enums_1.HMSH_CODE_DURABLE_RETRYABLE;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
exports.
|
|
144
|
+
exports.DurableRetryError = DurableRetryError;
|
|
145
145
|
class MapDataError extends Error {
|
|
146
146
|
constructor() {
|
|
147
147
|
super('Error occurred while mapping data');
|
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hotmeshio/hotmesh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Permanent-Memory Workflows & AI Agents",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -26,26 +26,27 @@
|
|
|
26
26
|
"test:connect": "vitest run tests/unit/services/connector",
|
|
27
27
|
"test:connect:postgres": "vitest run tests/unit/services/connector/providers/postgres.test.ts",
|
|
28
28
|
"test:connect:nats": "vitest run tests/unit/services/connector/providers/nats.test.ts",
|
|
29
|
-
"test:
|
|
30
|
-
"test:
|
|
31
|
-
"test:
|
|
32
|
-
"test:
|
|
33
|
-
"test:
|
|
34
|
-
"test:
|
|
35
|
-
"test:
|
|
36
|
-
"test:
|
|
37
|
-
"test:
|
|
38
|
-
"test:
|
|
39
|
-
"test:
|
|
40
|
-
"test:
|
|
41
|
-
"test:
|
|
42
|
-
"test:
|
|
43
|
-
"test:
|
|
44
|
-
"test:
|
|
45
|
-
"test:
|
|
46
|
-
"test:
|
|
47
|
-
"test:
|
|
48
|
-
"test:
|
|
29
|
+
"test:durable": "vitest run tests/durable",
|
|
30
|
+
"test:durable:postgres": "HMSH_LOGLEVEL=info vitest run tests/durable",
|
|
31
|
+
"test:durable:basic": "HMSH_LOGLEVEL=info vitest run tests/durable/basic/postgres.test.ts",
|
|
32
|
+
"test:durable:collision": "vitest run tests/durable/collision/postgres.test.ts",
|
|
33
|
+
"test:durable:fatal": "vitest run tests/durable/fatal",
|
|
34
|
+
"test:durable:goodbye": "HMSH_LOGLEVEL=debug vitest run tests/durable/goodbye/postgres.test.ts",
|
|
35
|
+
"test:durable:interceptor": "HMSH_LOGLEVEL=info vitest run tests/durable/interceptor/postgres.test.ts",
|
|
36
|
+
"test:durable:entity": "HMSH_LOGLEVEL=debug vitest run tests/durable/entity/postgres.test.ts",
|
|
37
|
+
"test:durable:agent": "HMSH_LOGLEVEL=debug vitest run tests/durable/agent/postgres.test.ts",
|
|
38
|
+
"test:durable:hello": "HMSH_TELEMETRY=debug HMSH_LOGLEVEL=info vitest run tests/durable/helloworld/postgres.test.ts",
|
|
39
|
+
"test:durable:hook": "vitest run tests/durable/hook/postgres.test.ts",
|
|
40
|
+
"test:durable:interrupt": "vitest run tests/durable/interrupt/postgres.test.ts",
|
|
41
|
+
"test:durable:loopactivity": "vitest run tests/durable/loopactivity/postgres.test.ts",
|
|
42
|
+
"test:durable:nested": "vitest run tests/durable/nested/postgres.test.ts",
|
|
43
|
+
"test:durable:pipeline": "vitest run tests/durable/pipeline/postgres.test.ts",
|
|
44
|
+
"test:durable:retry": "vitest run tests/durable/retry/postgres.test.ts",
|
|
45
|
+
"test:durable:retrypolicy": "vitest run tests/durable/retry-policy",
|
|
46
|
+
"test:durable:sleep": "vitest run tests/durable/sleep/postgres.test.ts",
|
|
47
|
+
"test:durable:signal": "vitest run tests/durable/signal/postgres.test.ts",
|
|
48
|
+
"test:durable:unknown": "vitest run tests/durable/unknown/postgres.test.ts",
|
|
49
|
+
"test:dba": "vitest run tests/dba",
|
|
49
50
|
"test:cycle": "vitest run tests/functional/cycle",
|
|
50
51
|
"test:functional": "vitest run tests/functional",
|
|
51
52
|
"test:emit": "vitest run tests/functional/emit",
|
|
@@ -72,7 +73,7 @@
|
|
|
72
73
|
"test:sub:postgres": "vitest run tests/functional/sub/providers/postgres/postgres.test.ts",
|
|
73
74
|
"test:sub:nats": "vitest run tests/functional/sub/providers/nats/nats.test.ts",
|
|
74
75
|
"test:trigger": "vitest run tests/unit/services/activities/trigger.test.ts",
|
|
75
|
-
"test:
|
|
76
|
+
"test:virtual": "vitest run tests/virtual",
|
|
76
77
|
"test:unit": "vitest run tests/unit"
|
|
77
78
|
},
|
|
78
79
|
"keywords": [
|
|
@@ -195,7 +195,7 @@ class Activity {
|
|
|
195
195
|
this.context.data.done = true;
|
|
196
196
|
this.context.data.$error = {
|
|
197
197
|
message: this.data?.message || 'unknown error',
|
|
198
|
-
code: enums_1.
|
|
198
|
+
code: enums_1.HMSH_CODE_DURABLE_MAXED,
|
|
199
199
|
stack: this.data?.stack,
|
|
200
200
|
};
|
|
201
201
|
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { PruneOptions, PruneResult } from '../../types/dba';
|
|
2
|
+
import { PostgresClientType } from '../../types/postgres';
|
|
3
|
+
/**
|
|
4
|
+
* Database maintenance operations for HotMesh's Postgres backend.
|
|
5
|
+
*
|
|
6
|
+
* HotMesh uses soft-delete patterns: expired jobs and stream messages
|
|
7
|
+
* retain their rows with `expired_at` set but are never physically
|
|
8
|
+
* removed during normal operation. Over time, three tables accumulate
|
|
9
|
+
* dead rows:
|
|
10
|
+
*
|
|
11
|
+
* | Table | What accumulates |
|
|
12
|
+
* |---|---|
|
|
13
|
+
* | `{appId}.jobs` | Completed/expired jobs with `expired_at` set |
|
|
14
|
+
* | `{appId}.jobs_attributes` | Execution artifacts (`adata`, `hmark`, `jmark`, `status`, `other`) that are only needed during workflow execution |
|
|
15
|
+
* | `{appId}.streams` | Processed stream messages with `expired_at` set |
|
|
16
|
+
*
|
|
17
|
+
* The `DBA` service addresses this with two methods:
|
|
18
|
+
*
|
|
19
|
+
* - {@link DBA.prune | prune()} — Targets any combination of jobs,
|
|
20
|
+
* streams, and attributes independently. Each table can be pruned on
|
|
21
|
+
* its own schedule with its own retention window.
|
|
22
|
+
* - {@link DBA.deploy | deploy()} — Pre-deploys the Postgres function
|
|
23
|
+
* (e.g., during CI/CD migrations) without running a prune.
|
|
24
|
+
*
|
|
25
|
+
* ## Independent cron schedules (TypeScript)
|
|
26
|
+
*
|
|
27
|
+
* Each table can be targeted independently, allowing different retention
|
|
28
|
+
* windows and schedules:
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { Client as Postgres } from 'pg';
|
|
33
|
+
* import { DBA } from '@hotmeshio/hotmesh';
|
|
34
|
+
*
|
|
35
|
+
* const connection = {
|
|
36
|
+
* class: Postgres,
|
|
37
|
+
* options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' },
|
|
38
|
+
* };
|
|
39
|
+
*
|
|
40
|
+
* // Cron 1 — Nightly: strip execution artifacts from completed jobs
|
|
41
|
+
* // Keeps all jobs and their jdata/udata; keeps all streams.
|
|
42
|
+
* await DBA.prune({
|
|
43
|
+
* appId: 'myapp', connection,
|
|
44
|
+
* jobs: false, streams: false, attributes: true,
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Cron 2 — Hourly: remove processed stream messages older than 24h
|
|
48
|
+
* await DBA.prune({
|
|
49
|
+
* appId: 'myapp', connection,
|
|
50
|
+
* expire: '24 hours',
|
|
51
|
+
* jobs: false, streams: true,
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Cron 3 — Weekly: remove expired jobs older than 30 days
|
|
55
|
+
* await DBA.prune({
|
|
56
|
+
* appId: 'myapp', connection,
|
|
57
|
+
* expire: '30 days',
|
|
58
|
+
* jobs: true, streams: false,
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* ## Direct SQL (schedulable via pg_cron)
|
|
63
|
+
*
|
|
64
|
+
* The underlying Postgres function can be called directly, without
|
|
65
|
+
* the TypeScript SDK. Schedule it via `pg_cron`, `crontab`, or any
|
|
66
|
+
* SQL client:
|
|
67
|
+
*
|
|
68
|
+
* ```sql
|
|
69
|
+
* -- Strip attributes only (keep all jobs and streams)
|
|
70
|
+
* SELECT * FROM myapp.prune('0 seconds', false, false, true);
|
|
71
|
+
*
|
|
72
|
+
* -- Prune streams older than 24 hours (keep jobs)
|
|
73
|
+
* SELECT * FROM myapp.prune('24 hours', false, true, false);
|
|
74
|
+
*
|
|
75
|
+
* -- Prune expired jobs older than 30 days (keep streams)
|
|
76
|
+
* SELECT * FROM myapp.prune('30 days', true, false, false);
|
|
77
|
+
*
|
|
78
|
+
* -- Prune everything older than 7 days and strip attributes
|
|
79
|
+
* SELECT * FROM myapp.prune('7 days', true, true, true);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare class DBA {
|
|
83
|
+
/**
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
constructor();
|
|
87
|
+
/**
|
|
88
|
+
* Sanitizes an appId for use as a Postgres schema name.
|
|
89
|
+
* Mirrors the naming logic used during table deployment.
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
static safeName(input: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Acquires a Postgres client from the connection config.
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
static getClient(connection: PruneOptions['connection']): Promise<{
|
|
98
|
+
client: PostgresClientType;
|
|
99
|
+
release: () => Promise<void>;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns the SQL for the server-side `prune()` function.
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
static getPruneFunctionSQL(schema: string): string;
|
|
106
|
+
/**
|
|
107
|
+
* Deploys the `prune()` Postgres function into the target schema.
|
|
108
|
+
* Idempotent — uses `CREATE OR REPLACE` and can be called repeatedly.
|
|
109
|
+
*
|
|
110
|
+
* The function is automatically deployed when {@link DBA.prune} is called,
|
|
111
|
+
* but this method is exposed for explicit control (e.g., CI/CD
|
|
112
|
+
* migration scripts that provision database objects before the
|
|
113
|
+
* application starts).
|
|
114
|
+
*
|
|
115
|
+
* @param connection - Postgres provider configuration
|
|
116
|
+
* @param appId - Application identifier (schema name)
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* import { Client as Postgres } from 'pg';
|
|
121
|
+
* import { DBA } from '@hotmeshio/hotmesh';
|
|
122
|
+
*
|
|
123
|
+
* // Pre-deploy during CI/CD migration
|
|
124
|
+
* await DBA.deploy(
|
|
125
|
+
* {
|
|
126
|
+
* class: Postgres,
|
|
127
|
+
* options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
|
|
128
|
+
* },
|
|
129
|
+
* 'myapp',
|
|
130
|
+
* );
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
static deploy(connection: PruneOptions['connection'], appId: string): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Prunes expired data and/or strips execution artifacts from
|
|
136
|
+
* completed jobs. Each operation is independently controlled,
|
|
137
|
+
* so callers can target a single table per cron schedule.
|
|
138
|
+
*
|
|
139
|
+
* Operations (each enabled individually):
|
|
140
|
+
* 1. **jobs** — Hard-deletes expired jobs older than the retention
|
|
141
|
+
* window (FK CASCADE removes their attributes automatically)
|
|
142
|
+
* 2. **streams** — Hard-deletes expired stream messages older than
|
|
143
|
+
* the retention window
|
|
144
|
+
* 3. **attributes** — Strips non-essential attributes (`adata`,
|
|
145
|
+
* `hmark`, `jmark`, `status`, `other`) from completed jobs,
|
|
146
|
+
* retaining only `jdata` and `udata`
|
|
147
|
+
*
|
|
148
|
+
* @param options - Prune configuration
|
|
149
|
+
* @returns Counts of deleted/stripped rows
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* import { Client as Postgres } from 'pg';
|
|
154
|
+
* import { DBA } from '@hotmeshio/hotmesh';
|
|
155
|
+
*
|
|
156
|
+
* // Strip attributes only — keep all jobs and streams
|
|
157
|
+
* await DBA.prune({
|
|
158
|
+
* appId: 'myapp',
|
|
159
|
+
* connection: {
|
|
160
|
+
* class: Postgres,
|
|
161
|
+
* options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
|
|
162
|
+
* },
|
|
163
|
+
* jobs: false,
|
|
164
|
+
* streams: false,
|
|
165
|
+
* attributes: true,
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
static prune(options: PruneOptions): Promise<PruneResult>;
|
|
170
|
+
}
|
|
171
|
+
export { DBA };
|