@hotmeshio/hotmesh 0.23.0 → 0.24.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.
- package/build/package.json +1 -1
- package/build/services/durable/worker.js +6 -1
- package/build/services/escalations/client.d.ts +14 -0
- package/build/services/escalations/client.js +16 -2
- package/build/services/store/providers/postgres/postgres.js +26 -10
- package/build/types/hmsh_escalations.d.ts +19 -0
- package/package.json +1 -1
package/build/package.json
CHANGED
|
@@ -885,7 +885,12 @@ class WorkerService {
|
|
|
885
885
|
code: enums_1.HMSH_CODE_DURABLE_ALL,
|
|
886
886
|
items: [...interruptionRegistry],
|
|
887
887
|
size: interruptionRegistry.length,
|
|
888
|
-
|
|
888
|
+
// Use the items' execution dimension (all items in one Promise.all share it),
|
|
889
|
+
// not the raw input dimension. In a continued generation (post-continueAsNew)
|
|
890
|
+
// the effective dimension is the generation prefix `$N`, which the items carry
|
|
891
|
+
// but `workflowInput.workflowDimension` does not — mirrors the single-condition
|
|
892
|
+
// path above so the collator's harvested markers land where condition() replays.
|
|
893
|
+
workflowDimension: interruptionRegistry[0].workflowDimension || workflowDimension || '',
|
|
889
894
|
index: execIndex,
|
|
890
895
|
originJobId: originJobId || workflowId,
|
|
891
896
|
parentWorkflowId: workflowId,
|
|
@@ -143,11 +143,21 @@ export declare class EscalationClientService {
|
|
|
143
143
|
* durable proof. Signal delivery is best-effort post-commit — the resolved
|
|
144
144
|
* row is the recovery record for any missed delivery. Returns the updated
|
|
145
145
|
* row as `entry` on success.
|
|
146
|
+
*
|
|
147
|
+
* Pass `params.metadata` to merge the resolution outcome ("what actually
|
|
148
|
+
* happened") into the row's GIN-indexed `metadata` in the same atomic UPDATE,
|
|
149
|
+
* making it `@>`-queryable alongside the creation metadata ("what was
|
|
150
|
+
* intended"). This is distinct from `resolverPayload`, which is delivered to
|
|
151
|
+
* the waiting workflow as `condition()`'s return value and is not GIN-indexed.
|
|
146
152
|
*/
|
|
147
153
|
resolve(params: ResolveEscalationParams, namespace?: string): Promise<ResolveEscalationResult>;
|
|
148
154
|
/**
|
|
149
155
|
* Resolves the highest-priority matching escalation by metadata filter,
|
|
150
156
|
* then delivers its signal. Same transaction + WHERE guard semantics as `resolve()`.
|
|
157
|
+
*
|
|
158
|
+
* The `key`/`value` are the *selector* used to find the row; pass
|
|
159
|
+
* `params.metadata` to additionally merge a resolution patch into that row's
|
|
160
|
+
* GIN-indexed `metadata` in the same atomic UPDATE. See {@link resolve}.
|
|
151
161
|
*/
|
|
152
162
|
resolveByMetadata(params: ResolveByMetadataParams, namespace?: string): Promise<ResolveEscalationResult>;
|
|
153
163
|
/**
|
|
@@ -182,6 +192,10 @@ export declare class EscalationClientService {
|
|
|
182
192
|
* Bulk-resolves pending escalations by id-set. No signal delivery — intended
|
|
183
193
|
* for redirect-to-triage flows where no workflow is waiting. Returns the
|
|
184
194
|
* resolved rows.
|
|
195
|
+
*
|
|
196
|
+
* Pass `params.metadata` to merge a resolution patch into every winning
|
|
197
|
+
* (still-pending) row's GIN-indexed `metadata` in the single atomic UPDATE.
|
|
198
|
+
* See {@link resolve}.
|
|
185
199
|
*/
|
|
186
200
|
resolveMany(params: ResolveManyParams): Promise<EscalationEntry[]>;
|
|
187
201
|
/**
|
|
@@ -281,12 +281,18 @@ class EscalationClientService {
|
|
|
281
281
|
* durable proof. Signal delivery is best-effort post-commit — the resolved
|
|
282
282
|
* row is the recovery record for any missed delivery. Returns the updated
|
|
283
283
|
* row as `entry` on success.
|
|
284
|
+
*
|
|
285
|
+
* Pass `params.metadata` to merge the resolution outcome ("what actually
|
|
286
|
+
* happened") into the row's GIN-indexed `metadata` in the same atomic UPDATE,
|
|
287
|
+
* making it `@>`-queryable alongside the creation metadata ("what was
|
|
288
|
+
* intended"). This is distinct from `resolverPayload`, which is delivered to
|
|
289
|
+
* the waiting workflow as `condition()`'s return value and is not GIN-indexed.
|
|
284
290
|
*/
|
|
285
291
|
async resolve(params, namespace) {
|
|
286
292
|
const ns = (params.namespace ?? namespace) ?? factory_1.APP_ID;
|
|
287
293
|
const hm = await this._engine(null, ns);
|
|
288
294
|
const store = hm.engine.store;
|
|
289
|
-
const dbResult = await store.resolveEscalation({ id: params.id, resolverPayload: params.resolverPayload });
|
|
295
|
+
const dbResult = await store.resolveEscalation({ id: params.id, resolverPayload: params.resolverPayload, metadata: params.metadata });
|
|
290
296
|
if (!dbResult.ok)
|
|
291
297
|
return dbResult;
|
|
292
298
|
if (dbResult.signalKey) {
|
|
@@ -301,12 +307,16 @@ class EscalationClientService {
|
|
|
301
307
|
/**
|
|
302
308
|
* Resolves the highest-priority matching escalation by metadata filter,
|
|
303
309
|
* then delivers its signal. Same transaction + WHERE guard semantics as `resolve()`.
|
|
310
|
+
*
|
|
311
|
+
* The `key`/`value` are the *selector* used to find the row; pass
|
|
312
|
+
* `params.metadata` to additionally merge a resolution patch into that row's
|
|
313
|
+
* GIN-indexed `metadata` in the same atomic UPDATE. See {@link resolve}.
|
|
304
314
|
*/
|
|
305
315
|
async resolveByMetadata(params, namespace) {
|
|
306
316
|
const ns = (params.namespace ?? namespace) ?? factory_1.APP_ID;
|
|
307
317
|
const hm = await this._engine(null, ns);
|
|
308
318
|
const store = hm.engine.store;
|
|
309
|
-
const dbResult = await store.resolveEscalationByMetadata({ key: params.key, value: params.value, resolverPayload: params.resolverPayload, roles: params.roles });
|
|
319
|
+
const dbResult = await store.resolveEscalationByMetadata({ key: params.key, value: params.value, resolverPayload: params.resolverPayload, roles: params.roles, metadata: params.metadata });
|
|
310
320
|
if (!dbResult.ok)
|
|
311
321
|
return dbResult;
|
|
312
322
|
if (dbResult.signalKey) {
|
|
@@ -366,6 +376,10 @@ class EscalationClientService {
|
|
|
366
376
|
* Bulk-resolves pending escalations by id-set. No signal delivery — intended
|
|
367
377
|
* for redirect-to-triage flows where no workflow is waiting. Returns the
|
|
368
378
|
* resolved rows.
|
|
379
|
+
*
|
|
380
|
+
* Pass `params.metadata` to merge a resolution patch into every winning
|
|
381
|
+
* (still-pending) row's GIN-indexed `metadata` in the single atomic UPDATE.
|
|
382
|
+
* See {@link resolve}.
|
|
369
383
|
*/
|
|
370
384
|
async resolveMany(params) {
|
|
371
385
|
const hm = await this._engine(null, params.namespace);
|
|
@@ -1769,8 +1769,11 @@ class PostgresStoreService extends __1.StoreService {
|
|
|
1769
1769
|
return { ok: true, entry: row.entry_json };
|
|
1770
1770
|
}
|
|
1771
1771
|
async resolveEscalation(params) {
|
|
1772
|
-
const { id, namespace, resolverPayload } = params;
|
|
1772
|
+
const { id, namespace, resolverPayload, metadata } = params;
|
|
1773
1773
|
const payloadJson = resolverPayload ? JSON.stringify(resolverPayload) : null;
|
|
1774
|
+
// metaJson is bound at a fixed index; the CASE no-ops when null so resolution
|
|
1775
|
+
// can merge into the GIN-indexed metadata without disturbing the param layout.
|
|
1776
|
+
const metaJson = metadata ? JSON.stringify(metadata) : null;
|
|
1774
1777
|
// Explicit transaction: FOR UPDATE locks the row; WHERE guard on UPDATE is the TOCTOU
|
|
1775
1778
|
// barrier — a concurrent caller whose UPDATE matches 0 rows sees 'already-resolved'.
|
|
1776
1779
|
// On crash before COMMIT neither write lands; on crash after COMMIT both are durable.
|
|
@@ -1789,9 +1792,13 @@ class PostgresStoreService extends __1.StoreService {
|
|
|
1789
1792
|
return { ok: false, reason: 'already-cancelled' };
|
|
1790
1793
|
}
|
|
1791
1794
|
const updateResult = await this.pgClient.query(`UPDATE public.hmsh_escalations
|
|
1792
|
-
SET status = 'resolved', resolved_at = NOW(), resolver_payload = $2,
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
+
SET status = 'resolved', resolved_at = NOW(), resolver_payload = $2,
|
|
1796
|
+
metadata = CASE WHEN $3::jsonb IS NOT NULL
|
|
1797
|
+
THEN COALESCE(metadata, '{}'::jsonb) || $3::jsonb
|
|
1798
|
+
ELSE metadata END,
|
|
1799
|
+
updated_at = NOW()
|
|
1800
|
+
WHERE id = $1 ${namespace ? 'AND namespace = $4' : ''} AND status = 'pending'
|
|
1801
|
+
RETURNING *`, namespace ? [id, payloadJson, metaJson, namespace] : [id, payloadJson, metaJson]);
|
|
1795
1802
|
if (!updateResult.rows[0]) {
|
|
1796
1803
|
await this.pgClient.query('ROLLBACK');
|
|
1797
1804
|
return { ok: false, reason: 'already-resolved' };
|
|
@@ -1805,9 +1812,10 @@ class PostgresStoreService extends __1.StoreService {
|
|
|
1805
1812
|
}
|
|
1806
1813
|
}
|
|
1807
1814
|
async resolveEscalationByMetadata(params) {
|
|
1808
|
-
const { key, value, namespace, resolverPayload, roles } = params;
|
|
1815
|
+
const { key, value, namespace, resolverPayload, roles, metadata } = params;
|
|
1809
1816
|
const filter = JSON.stringify({ [key]: value });
|
|
1810
1817
|
const payloadJson = resolverPayload ? JSON.stringify(resolverPayload) : null;
|
|
1818
|
+
const metaJson = metadata ? JSON.stringify(metadata) : null;
|
|
1811
1819
|
await this.pgClient.query('BEGIN');
|
|
1812
1820
|
try {
|
|
1813
1821
|
const lockResult = await this.pgClient.query(`SELECT id, signal_key, topic, status FROM public.hmsh_escalations
|
|
@@ -1827,9 +1835,13 @@ class PostgresStoreService extends __1.StoreService {
|
|
|
1827
1835
|
return { ok: false, reason: 'already-cancelled' };
|
|
1828
1836
|
}
|
|
1829
1837
|
const updateResult = await this.pgClient.query(`UPDATE public.hmsh_escalations
|
|
1830
|
-
SET status = 'resolved', resolved_at = NOW(), resolver_payload = $2,
|
|
1838
|
+
SET status = 'resolved', resolved_at = NOW(), resolver_payload = $2,
|
|
1839
|
+
metadata = CASE WHEN $3::jsonb IS NOT NULL
|
|
1840
|
+
THEN COALESCE(metadata, '{}'::jsonb) || $3::jsonb
|
|
1841
|
+
ELSE metadata END,
|
|
1842
|
+
updated_at = NOW()
|
|
1831
1843
|
WHERE id = $1 AND status = 'pending'
|
|
1832
|
-
RETURNING *`, [id, payloadJson]);
|
|
1844
|
+
RETURNING *`, [id, payloadJson, metaJson]);
|
|
1833
1845
|
if (!updateResult.rows[0]) {
|
|
1834
1846
|
await this.pgClient.query('ROLLBACK');
|
|
1835
1847
|
return { ok: false, reason: 'already-resolved' };
|
|
@@ -2007,17 +2019,21 @@ class PostgresStoreService extends __1.StoreService {
|
|
|
2007
2019
|
return result.rowCount ?? 0;
|
|
2008
2020
|
}
|
|
2009
2021
|
async resolveManyEscalations(params) {
|
|
2010
|
-
const { ids, namespace, resolverPayload } = params;
|
|
2022
|
+
const { ids, namespace, resolverPayload, metadata } = params;
|
|
2011
2023
|
const payloadJson = resolverPayload ? JSON.stringify(resolverPayload) : null;
|
|
2024
|
+
const metaJson = metadata ? JSON.stringify(metadata) : null;
|
|
2012
2025
|
const result = await this.pgClient.query(`UPDATE public.hmsh_escalations
|
|
2013
2026
|
SET status = 'resolved',
|
|
2014
2027
|
resolved_at = NOW(),
|
|
2015
2028
|
resolver_payload = $1,
|
|
2029
|
+
metadata = CASE WHEN $3::jsonb IS NOT NULL
|
|
2030
|
+
THEN COALESCE(metadata, '{}'::jsonb) || $3::jsonb
|
|
2031
|
+
ELSE metadata END,
|
|
2016
2032
|
updated_at = NOW()
|
|
2017
2033
|
WHERE id = ANY($2::uuid[])
|
|
2018
|
-
${namespace ? 'AND namespace = $
|
|
2034
|
+
${namespace ? 'AND namespace = $4' : ''}
|
|
2019
2035
|
AND status = 'pending'
|
|
2020
|
-
RETURNING *`, namespace ? [payloadJson, ids, namespace] : [payloadJson, ids]);
|
|
2036
|
+
RETURNING *`, namespace ? [payloadJson, ids, metaJson, namespace] : [payloadJson, ids, metaJson]);
|
|
2021
2037
|
return result.rows;
|
|
2022
2038
|
}
|
|
2023
2039
|
async escalationStats(params = {}) {
|
|
@@ -256,6 +256,14 @@ export interface ResolveEscalationParams {
|
|
|
256
256
|
id: string;
|
|
257
257
|
namespace?: string;
|
|
258
258
|
resolverPayload?: Record<string, unknown>;
|
|
259
|
+
/**
|
|
260
|
+
* Merged (not replaced) into the resolved row's `metadata` in the same atomic
|
|
261
|
+
* UPDATE — and only on the winning resolve. Records "what actually happened"
|
|
262
|
+
* into the GIN-indexed (`@>`-queryable) surface alongside the creation metadata.
|
|
263
|
+
* Distinct from `resolverPayload`, which is delivered to the waiting workflow as
|
|
264
|
+
* `condition()`'s return value and is not GIN-indexed.
|
|
265
|
+
*/
|
|
266
|
+
metadata?: Record<string, unknown>;
|
|
259
267
|
}
|
|
260
268
|
export interface ResolveByMetadataParams {
|
|
261
269
|
key: string;
|
|
@@ -263,6 +271,12 @@ export interface ResolveByMetadataParams {
|
|
|
263
271
|
namespace?: string;
|
|
264
272
|
resolverPayload?: Record<string, unknown>;
|
|
265
273
|
roles?: string[];
|
|
274
|
+
/**
|
|
275
|
+
* Merge patch applied to the matched row's `metadata` (shallow, not replaced) in
|
|
276
|
+
* the same atomic UPDATE. Note this is the resolution patch — distinct from the
|
|
277
|
+
* `key`/`value` selector used to find the row. See {@link ResolveEscalationParams.metadata}.
|
|
278
|
+
*/
|
|
279
|
+
metadata?: Record<string, unknown>;
|
|
266
280
|
}
|
|
267
281
|
export interface EscalateToRoleParams {
|
|
268
282
|
id: string;
|
|
@@ -289,6 +303,11 @@ export interface ResolveManyParams {
|
|
|
289
303
|
ids: string[];
|
|
290
304
|
namespace?: string;
|
|
291
305
|
resolverPayload?: Record<string, unknown>;
|
|
306
|
+
/**
|
|
307
|
+
* Merged (not replaced) into every winning (still-pending) row's `metadata` in
|
|
308
|
+
* the single bulk UPDATE. See {@link ResolveEscalationParams.metadata}.
|
|
309
|
+
*/
|
|
310
|
+
metadata?: Record<string, unknown>;
|
|
292
311
|
}
|
|
293
312
|
/**
|
|
294
313
|
* Full-fidelity migration params. Extends `CreateEscalationParams` with:
|