@arvo-tools/postgres 1.0.0 → 1.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.
@@ -0,0 +1,96 @@
1
+ import type { QueuePolicy } from 'pg-boss';
2
+ /**
3
+ * Job-level options that control how individual jobs are processed by PgBoss.
4
+ * These options are applied when sending jobs to queues.
5
+ */
6
+ export type WorkerJobOptions = {
7
+ /** Job priority. Higher numbers have higher priority */
8
+ priority?: number;
9
+ /** Number of retries to complete a job. Default: 2 */
10
+ retryLimit?: number;
11
+ /** Delay between retries of failed jobs, in seconds. Default: 0 */
12
+ retryDelay?: number;
13
+ /** Enables exponential backoff retries based on retryDelay. Default: false */
14
+ retryBackoff?: boolean;
15
+ /** Maximum delay between retries when retryBackoff is true, in seconds */
16
+ retryDelayMax?: number;
17
+ /** How many seconds a job may be in active state before being retried or failed. Default: 15 minutes */
18
+ expireInSeconds?: number;
19
+ /** How many seconds a job may be in created or retry state before deletion. Default: 14 days */
20
+ retentionSeconds?: number;
21
+ /** How long a job should be retained after completion, in seconds. Default: 7 days */
22
+ deleteAfterSeconds?: number;
23
+ /** Delay job execution. Can be seconds (number), ISO 8601 string, or Date object */
24
+ startAfter?: number | string | Date;
25
+ /** Throttle to one job per time slot, in seconds */
26
+ singletonSeconds?: number;
27
+ /** Schedule throttled job for next time slot. Default: false */
28
+ singletonNextSlot?: boolean;
29
+ /** Extend throttling to allow one job per key within the time slot */
30
+ singletonKey?: string;
31
+ };
32
+ /**
33
+ * Worker-level configuration options that control how the worker processes jobs.
34
+ * These options are not sent with individual jobs.
35
+ */
36
+ export type WorkerConfigOptions = {
37
+ /** Polling interval for checking new jobs, in seconds. Default: 2 */
38
+ pollingIntervalSeconds?: number;
39
+ /** Number of concurrent worker instances to spawn for this handler. Default: 1 */
40
+ concurrency?: number;
41
+ };
42
+ /**
43
+ * Combined worker options including both configuration and job-level settings.
44
+ */
45
+ export type WorkerOptions = WorkerConfigOptions & WorkerJobOptions;
46
+ /**
47
+ * Queue configuration options that define queue behavior and policies.
48
+ */
49
+ export type QueueOptions = {
50
+ /** Queue policy determining job uniqueness and processing behavior */
51
+ policy?: QueuePolicy;
52
+ /** Enable queue partitioning for scalability */
53
+ partition?: boolean;
54
+ /** Name of the dead letter queue for failed jobs */
55
+ deadLetter?: string;
56
+ /** Queue size threshold for warnings */
57
+ warningQueueSize?: number;
58
+ };
59
+ /**
60
+ * Options for registering an event handler with the ArvoPgBoss system.
61
+ */
62
+ export type HandlerRegistrationOptions = {
63
+ /** Delete and recreate the queue before registration. Default: false */
64
+ recreateQueue?: boolean;
65
+ /** Queue-level configuration options */
66
+ queue?: QueueOptions;
67
+ /** Worker-level configuration and job options */
68
+ worker?: WorkerOptions;
69
+ };
70
+ /**
71
+ * Logger interface for broker operations.
72
+ *
73
+ * Allows users to inject their own logging implementation (Winston, Pino, etc.)
74
+ * or use the default console logger. All broker operational logs use this interface.
75
+ */
76
+ export interface ILogger {
77
+ /**
78
+ * Log informational messages about broker operations.
79
+ * @param message - Primary log message
80
+ * @param optionalParams - Additional context or data
81
+ */
82
+ log(message?: any, ...optionalParams: any[]): void;
83
+ /**
84
+ * Log error messages for failures or exceptions.
85
+ * @param message - Error message or description
86
+ * @param optionalParams - Error object or additional context
87
+ */
88
+ error(message?: any, ...optionalParams: any[]): void;
89
+ /**
90
+ * Log informational messages (alias for log).
91
+ * @param message - Primary log message
92
+ * @param optionalParams - Additional context or data
93
+ */
94
+ info(message?: any, ...optionalParams: any[]): void;
95
+ }
96
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/broker/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;I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IACrB,iDAAiD;IACjD,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB;;;;OAIG;IAEH,GAAG,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAEnD;;;;OAIG;IAEH,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAErD;;;;OAIG;IAEH,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CACrD"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/broker/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { ArvoEvent } from 'arvo-core';
2
+ import type { Job } from 'pg-boss';
3
+ export declare const createArvoEventFromJob: (job: Job<ReturnType<ArvoEvent["toJSON"]>>) => ArvoEvent;
4
+ /**
5
+ * Extracts and creates an OpenTelemetry context from an ArvoEvent's traceparent.
6
+ *
7
+ * @param event - The ArvoEvent containing trace information
8
+ * @returns OpenTelemetry context with the event's trace information
9
+ */
10
+ export declare const otelParentContext: (event: ArvoEvent) => import("@opentelemetry/api").Context;
11
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/broker/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAEnC,eAAO,MAAM,sBAAsB,GAAI,KAAK,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAG,SA2ClF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,SAAS,yCAejD,CAAC"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.otelParentContext = exports.createArvoEventFromJob = void 0;
31
+ var api_1 = require("@opentelemetry/api");
32
+ var arvo_core_1 = require("arvo-core");
33
+ var createArvoEventFromJob = function (job) {
34
+ var _a = job.data, id = _a.id, source = _a.source, type = _a.type, subject = _a.subject, time = _a.time, specversion = _a.specversion, datacontenttype = _a.datacontenttype, dataschema = _a.dataschema, to = _a.to, accesscontrol = _a.accesscontrol, redirectto = _a.redirectto, executionunits = _a.executionunits, parentid = _a.parentid, domain = _a.domain, traceparent = _a.traceparent, tracestate = _a.tracestate, data = _a.data, extensions = __rest(_a, ["id", "source", "type", "subject", "time", "specversion", "datacontenttype", "dataschema", "to", "accesscontrol", "redirectto", "executionunits", "parentid", "domain", "traceparent", "tracestate", "data"]);
35
+ return new arvo_core_1.ArvoEvent({
36
+ id: id,
37
+ source: source,
38
+ type: type,
39
+ subject: subject,
40
+ time: time,
41
+ specversion: specversion,
42
+ datacontenttype: datacontenttype,
43
+ dataschema: dataschema,
44
+ to: to,
45
+ accesscontrol: accesscontrol,
46
+ redirectto: redirectto,
47
+ executionunits: executionunits,
48
+ parentid: parentid,
49
+ domain: domain,
50
+ traceparent: traceparent,
51
+ tracestate: tracestate,
52
+ }, data, extensions !== null && extensions !== void 0 ? extensions : {});
53
+ };
54
+ exports.createArvoEventFromJob = createArvoEventFromJob;
55
+ /**
56
+ * Extracts and creates an OpenTelemetry context from an ArvoEvent's traceparent.
57
+ *
58
+ * @param event - The ArvoEvent containing trace information
59
+ * @returns OpenTelemetry context with the event's trace information
60
+ */
61
+ var otelParentContext = function (event) {
62
+ var parentContext = api_1.context.active();
63
+ if (event.traceparent) {
64
+ var parts = event.traceparent.split('-');
65
+ if (parts.length === 4) {
66
+ var _a = __read(parts, 4), _ = _a[0], traceId = _a[1], spanId = _a[2], traceFlags = _a[3];
67
+ var spanContext = {
68
+ traceId: traceId,
69
+ spanId: spanId,
70
+ traceFlags: Number.parseInt(traceFlags, 10),
71
+ };
72
+ parentContext = api_1.trace.setSpanContext(api_1.context.active(), spanContext);
73
+ }
74
+ }
75
+ return parentContext;
76
+ };
77
+ exports.otelParentContext = otelParentContext;
78
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/broker/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAsE;AACtE,uCAAsC;AAG/B,IAAM,sBAAsB,GAAG,UAAC,GAAyC;IAC9E,IAAM,KAmBF,GAAG,CAAC,IAAI,EAlBV,EAAE,QAAA,EACF,MAAM,YAAA,EACN,IAAI,UAAA,EACJ,OAAO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EAAE,EAAE,CAAC;aAC5C,CAAC;YACF,aAAa,GAAG,WAAK,CAAC,cAAc,CAAC,aAAO,CAAC,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAfW,QAAA,iBAAiB,qBAe5B"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export { connectPostgresMachineMemory, createPostgresMachineMemoryTables, releasePostgressMachineMemory, } from './memory/factory';
1
+ export { PostgresEventBroker } from './broker';
2
+ export type { HandlerRegistrationOptions, QueueOptions, WorkerConfigOptions, WorkerJobOptions, WorkerOptions, } from './broker/types';
3
+ export { connectPostgresMachineMemory, releasePostgressMachineMemory, } from './memory/factory';
2
4
  export type { ConnectPostgresMachineMemoryParam, PostgresMachineMemory, } from './memory/factory/type';
3
5
  export type { PostgressConnectionConfig } from './memory/types';
4
6
  export { PostgressMachineMemoryV1 } from './memory/v1';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,iCAAiC,EACjC,6BAA6B,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,iCAAiC,EACjC,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,YAAY,EACV,0BAA0B,EAC1B,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,iCAAiC,EACjC,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PostgressMachineMemoryV1 = exports.releasePostgressMachineMemory = exports.createPostgresMachineMemoryTables = exports.connectPostgresMachineMemory = void 0;
3
+ exports.PostgressMachineMemoryV1 = exports.releasePostgressMachineMemory = exports.connectPostgresMachineMemory = exports.PostgresEventBroker = void 0;
4
+ var broker_1 = require("./broker");
5
+ Object.defineProperty(exports, "PostgresEventBroker", { enumerable: true, get: function () { return broker_1.PostgresEventBroker; } });
4
6
  var factory_1 = require("./memory/factory");
5
7
  Object.defineProperty(exports, "connectPostgresMachineMemory", { enumerable: true, get: function () { return factory_1.connectPostgresMachineMemory; } });
6
- Object.defineProperty(exports, "createPostgresMachineMemoryTables", { enumerable: true, get: function () { return factory_1.createPostgresMachineMemoryTables; } });
7
8
  Object.defineProperty(exports, "releasePostgressMachineMemory", { enumerable: true, get: function () { return factory_1.releasePostgressMachineMemory; } });
8
9
  var v1_1 = require("./memory/v1");
9
10
  Object.defineProperty(exports, "PostgressMachineMemoryV1", { enumerable: true, get: function () { return v1_1.PostgressMachineMemoryV1; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4CAI0B;AAHxB,uHAAA,4BAA4B,OAAA;AAC5B,4HAAA,iCAAiC,OAAA;AACjC,wHAAA,6BAA6B,OAAA;AAO/B,kCAAuD;AAA9C,8GAAA,wBAAwB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA+C;AAAtC,6GAAA,mBAAmB,OAAA;AAQ5B,4CAG0B;AAFxB,uHAAA,4BAA4B,OAAA;AAC5B,wHAAA,6BAA6B,OAAA;AAO/B,kCAAuD;AAA9C,8GAAA,wBAAwB,OAAA"}
@@ -40,7 +40,7 @@ import type { ConnectPostgresMachineMemoryParam, PostgresMachineMemory } from '.
40
40
  * await releasePostgressMachineMemory(memory);
41
41
  * ```
42
42
  */
43
- export declare const connectPostgresMachineMemory: <T extends Record<string, unknown> = Record<string, unknown>>({ version, tables, config, }: ConnectPostgresMachineMemoryParam) => Promise<PostgresMachineMemory<T>>;
43
+ export declare const connectPostgresMachineMemory: <T extends Record<string, unknown> = Record<string, unknown>>({ version, tables, config, migrate, }: ConnectPostgresMachineMemoryParam) => Promise<PostgresMachineMemory<T>>;
44
44
  /**
45
45
  * Releases all resources held by a PostgreSQL machine memory instance.
46
46
  *
@@ -54,64 +54,4 @@ export declare const connectPostgresMachineMemory: <T extends Record<string, unk
54
54
  * @param memory - The PostgreSQL machine memory instance to release
55
55
  */
56
56
  export declare const releasePostgressMachineMemory: (memory: PostgresMachineMemory) => Promise<void>;
57
- /**
58
- * Creates PostgreSQL machine memory tables with the specified schema version.
59
- *
60
- * ⚠️ **WARNING**: Setting `dangerouslyDropTablesIfExist` to true will DROP existing tables and ALL their data.
61
- * Use this option with extreme caution, and never in production environments.
62
- *
63
- * This utility function creates the required database tables (state, lock, and hierarchy) for the
64
- * PostgreSQL machine memory implementation. It supports version-specific schema creation and
65
- * optionally drops existing tables before recreating them (useful for testing and development).
66
- *
67
- * @param connectionString - PostgreSQL connection string (e.g., "postgresql://user:pass@localhost:5432/mydb")
68
- * @param config - Table creation configuration
69
- * @param config.version - Schema version to use (currently only version 1 is supported)
70
- * @param config.tables - Custom table names configuration
71
- * @param config.tables.state - Name for the state table (stores workflow data, versions, execution status, metadata)
72
- * @param config.tables.lock - Name for the lock table (manages distributed locks with TTL-based expiration)
73
- * @param config.tables.hierarchy - Name for the hierarchy table (tracks workflow parent-child relationships)
74
- * @param config.dangerouslyDropTablesIfExist - If true, drops existing tables before creating them (⚠️ DANGEROUS - causes data loss)
75
- *
76
- * @throws Error if the specified version is not supported
77
- * @throws Error if database connection fails
78
- * @throws Error if table creation fails
79
- *
80
- * @example
81
- * ```typescript
82
- * // Create tables with default behavior (doesn't drop existing tables)
83
- * await createPostgresMachineMemoryTables(connectionString, {
84
- * version: 1,
85
- * tables: {
86
- * state: 'machine_memory_state',
87
- * lock: 'machine_memory_lock',
88
- * hierarchy: 'machine_memory_hierarchy'
89
- * }
90
- * });
91
- *
92
- * // DANGEROUS: Drop and recreate tables (useful for testing and development)
93
- * await createPostgresMachineMemoryTables(connectionString, {
94
- * version: 1,
95
- * tables: {
96
- * state: 'machine_memory_state',
97
- * lock: 'machine_memory_lock',
98
- * hierarchy: 'machine_memory_hierarchy'
99
- * },
100
- * dangerouslyDropTablesIfExist: true // ⚠️ This will delete all existing data!
101
- * });
102
- *
103
- * // Use custom table names
104
- * await createPostgresMachineMemoryTables(connectionString, {
105
- * version: 1,
106
- * tables: {
107
- * state: 'my_workflow_state',
108
- * lock: 'my_workflow_locks',
109
- * hierarchy: 'my_workflow_hierarchy'
110
- * }
111
- * });
112
- * ```
113
- */
114
- export declare const createPostgresMachineMemoryTables: (connectionString: string, config: Pick<ConnectPostgresMachineMemoryParam, "version" | "tables"> & {
115
- dangerouslyDropTablesIfExist?: boolean;
116
- }) => Promise<void>;
117
57
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/factory/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,4BAA4B,GACvC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,8BAIC,iCAAiC,KAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAUtE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,6BAA6B,GAAU,QAAQ,qBAAqB,kBAEhF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,eAAO,MAAM,iCAAiC,GAC5C,kBAAkB,MAAM,EACxB,QAAQ,IAAI,CAAC,iCAAiC,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG;IACtE,4BAA4B,CAAC,EAAE,OAAO,CAAC;CACxC,kBAUF,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/factory/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,4BAA4B,GACvC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,uCAKC,iCAAiC,KAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CA+BtE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,6BAA6B,GAAU,QAAQ,qBAAqB,kBAEhF,CAAC"}
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.createPostgresMachineMemoryTables = exports.releasePostgressMachineMemory = exports.connectPostgresMachineMemory = void 0;
39
+ exports.releasePostgressMachineMemory = exports.connectPostgresMachineMemory = void 0;
40
40
  var v1_1 = require("../v1");
41
41
  var helper_1 = require("../v1/helper");
42
42
  var defaults_1 = require("./defaults");
@@ -82,21 +82,51 @@ var defaults_1 = require("./defaults");
82
82
  * ```
83
83
  */
84
84
  var connectPostgresMachineMemory = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
85
- var memory;
86
- var version = _b.version, tables = _b.tables, config = _b.config;
87
- return __generator(this, function (_c) {
88
- switch (_c.label) {
85
+ var connectionString, versionToActionMap, action;
86
+ var _c, _d, _e, _f, _g;
87
+ var version = _b.version, tables = _b.tables, config = _b.config, _h = _b.migrate, migrate = _h === void 0 ? 'noop' : _h;
88
+ return __generator(this, function (_j) {
89
+ switch (_j.label) {
89
90
  case 0:
90
- if (!(version === 1)) return [3 /*break*/, 2];
91
- memory = new v1_1.PostgressMachineMemoryV1({
92
- tables: tables !== null && tables !== void 0 ? tables : defaults_1.DEFAULT_V1_TABLE_NAMES,
93
- config: config,
94
- });
95
- return [4 /*yield*/, memory.validateTableStructure()];
96
- case 1:
97
- _c.sent();
98
- return [2 /*return*/, memory];
99
- case 2: throw new Error("Unsupported PostgreSQL machine memory version: ".concat(version));
91
+ if ('connectionString' in config) {
92
+ connectionString = config.connectionString;
93
+ }
94
+ else {
95
+ connectionString = "postgresql://".concat((_c = config.user) !== null && _c !== void 0 ? _c : 'postgres', ":").concat((_d = config.password) !== null && _d !== void 0 ? _d : 'postgres', "@").concat((_e = config.host) !== null && _e !== void 0 ? _e : 'localhost', ":").concat((_f = config.port) !== null && _f !== void 0 ? _f : 5432, "/").concat((_g = config.database) !== null && _g !== void 0 ? _g : 'postgres');
96
+ }
97
+ versionToActionMap = {
98
+ 1: function () { return __awaiter(void 0, void 0, void 0, function () {
99
+ var memory;
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0:
103
+ if (!(migrate && migrate !== 'noop')) return [3 /*break*/, 2];
104
+ return [4 /*yield*/, (0, helper_1.createTableV1)(connectionString, {
105
+ dropIfExist: migrate === 'dangerousely_force_migration',
106
+ tables: tables !== null && tables !== void 0 ? tables : defaults_1.DEFAULT_V1_TABLE_NAMES,
107
+ })];
108
+ case 1:
109
+ _a.sent();
110
+ _a.label = 2;
111
+ case 2:
112
+ memory = new v1_1.PostgressMachineMemoryV1({
113
+ tables: tables !== null && tables !== void 0 ? tables : defaults_1.DEFAULT_V1_TABLE_NAMES,
114
+ config: config,
115
+ });
116
+ return [4 /*yield*/, memory.validateTableStructure()];
117
+ case 3:
118
+ _a.sent();
119
+ return [2 /*return*/, memory];
120
+ }
121
+ });
122
+ }); },
123
+ };
124
+ action = versionToActionMap[version];
125
+ if (!action) {
126
+ throw new Error("Unsupported PostgreSQL machine memory version: ".concat(version));
127
+ }
128
+ return [4 /*yield*/, action()];
129
+ case 1: return [2 /*return*/, _j.sent()];
100
130
  }
101
131
  });
102
132
  }); };
@@ -124,79 +154,4 @@ var releasePostgressMachineMemory = function (memory) { return __awaiter(void 0,
124
154
  });
125
155
  }); };
126
156
  exports.releasePostgressMachineMemory = releasePostgressMachineMemory;
127
- /**
128
- * Creates PostgreSQL machine memory tables with the specified schema version.
129
- *
130
- * ⚠️ **WARNING**: Setting `dangerouslyDropTablesIfExist` to true will DROP existing tables and ALL their data.
131
- * Use this option with extreme caution, and never in production environments.
132
- *
133
- * This utility function creates the required database tables (state, lock, and hierarchy) for the
134
- * PostgreSQL machine memory implementation. It supports version-specific schema creation and
135
- * optionally drops existing tables before recreating them (useful for testing and development).
136
- *
137
- * @param connectionString - PostgreSQL connection string (e.g., "postgresql://user:pass@localhost:5432/mydb")
138
- * @param config - Table creation configuration
139
- * @param config.version - Schema version to use (currently only version 1 is supported)
140
- * @param config.tables - Custom table names configuration
141
- * @param config.tables.state - Name for the state table (stores workflow data, versions, execution status, metadata)
142
- * @param config.tables.lock - Name for the lock table (manages distributed locks with TTL-based expiration)
143
- * @param config.tables.hierarchy - Name for the hierarchy table (tracks workflow parent-child relationships)
144
- * @param config.dangerouslyDropTablesIfExist - If true, drops existing tables before creating them (⚠️ DANGEROUS - causes data loss)
145
- *
146
- * @throws Error if the specified version is not supported
147
- * @throws Error if database connection fails
148
- * @throws Error if table creation fails
149
- *
150
- * @example
151
- * ```typescript
152
- * // Create tables with default behavior (doesn't drop existing tables)
153
- * await createPostgresMachineMemoryTables(connectionString, {
154
- * version: 1,
155
- * tables: {
156
- * state: 'machine_memory_state',
157
- * lock: 'machine_memory_lock',
158
- * hierarchy: 'machine_memory_hierarchy'
159
- * }
160
- * });
161
- *
162
- * // DANGEROUS: Drop and recreate tables (useful for testing and development)
163
- * await createPostgresMachineMemoryTables(connectionString, {
164
- * version: 1,
165
- * tables: {
166
- * state: 'machine_memory_state',
167
- * lock: 'machine_memory_lock',
168
- * hierarchy: 'machine_memory_hierarchy'
169
- * },
170
- * dangerouslyDropTablesIfExist: true // ⚠️ This will delete all existing data!
171
- * });
172
- *
173
- * // Use custom table names
174
- * await createPostgresMachineMemoryTables(connectionString, {
175
- * version: 1,
176
- * tables: {
177
- * state: 'my_workflow_state',
178
- * lock: 'my_workflow_locks',
179
- * hierarchy: 'my_workflow_hierarchy'
180
- * }
181
- * });
182
- * ```
183
- */
184
- var createPostgresMachineMemoryTables = function (connectionString, config) { return __awaiter(void 0, void 0, void 0, function () {
185
- var _a;
186
- return __generator(this, function (_b) {
187
- switch (_b.label) {
188
- case 0:
189
- if (!(config.version === 1)) return [3 /*break*/, 2];
190
- return [4 /*yield*/, (0, helper_1.createTableV1)(connectionString, {
191
- dropIfExist: config.dangerouslyDropTablesIfExist,
192
- tables: (_a = config.tables) !== null && _a !== void 0 ? _a : defaults_1.DEFAULT_V1_TABLE_NAMES,
193
- })];
194
- case 1:
195
- _b.sent();
196
- return [2 /*return*/];
197
- case 2: throw new Error("Unsupported PostgreSQL machine memory version: ".concat(config.version));
198
- }
199
- });
200
- }); };
201
- exports.createPostgresMachineMemoryTables = createPostgresMachineMemoryTables;
202
157
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/memory/factory/index.ts"],"names":[],"mappings":";;;;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MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,iCAAsB;wCACxC,MAAM,QAAA;qCACP,CAAC,CAAC;oCACH,qBAAM,MAAM,CAAC,sBAAsB,EAAE,EAAA;;oCAArC,SAAqC,CAAC;oCACtC,sBAAO,MAAM,EAAC;;;yBACf;iBACF,CAAC;gBAEI,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;gBAC3C,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,MAAM,IAAI,KAAK,CAAC,yDAAkD,OAAO,CAAE,CAAC,CAAC;gBAC/E,CAAC;gBAEM,qBAAM,MAAM,EAAE,EAAA;oBAArB,sBAAO,SAAc,EAAC;;;KACvB,CAAC;AAtCW,QAAA,4BAA4B,gCAsCvC;AAEF;;;;;;;;;;;GAWG;AACI,IAAM,6BAA6B,GAAG,UAAO,MAA6B;;;oBAC/E,qBAAM,MAAM,CAAC,KAAK,EAAE,EAAA;;gBAApB,SAAoB,CAAC;;;;KACtB,CAAC;AAFW,QAAA,6BAA6B,iCAExC"}
@@ -16,8 +16,18 @@ export type ConnectPostgresMachineMemoryParam = {
16
16
  */
17
17
  tables?: PostgressMachineMemoryV1Param['tables'];
18
18
  } & {
19
- /** PostgreSQL connection and behavioral configuration. Optional, uses defaults if not provided */
20
- config?: PostgressConnectionConfig;
19
+ /** PostgreSQL connection and behavioral configuration */
20
+ config: PostgressConnectionConfig;
21
+ /**
22
+ * Database migration strategy when connecting to PostgreSQL machine memory.
23
+ *
24
+ * - `'if_tables_dont_exist'`: Creates tables if they don't exist. Safe for production use.
25
+ * - `'dangerousely_force_migration'`: Drops and recreates all tables, destroying existing data. **DANGEROUS** - use only in development/testing.
26
+ * - [DEFAULT] `'noop'`: No migration performed. Tables must already exist with correct schema or connection will fail during validation.
27
+ *
28
+ * @default 'noop'
29
+ */
30
+ migrate?: 'if_tables_dont_exist' | 'dangerousely_force_migration' | 'noop';
21
31
  };
22
32
  /**
23
33
  * Type alias for PostgreSQL-backed machine memory instances.
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/memory/factory/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC;IACX;;;OAGG;IACH,MAAM,CAAC,EAAE,6BAA6B,CAAC,QAAQ,CAAC,CAAC;CAClD,GAAG;IACF,kGAAkG;IAClG,MAAM,CAAC,EAAE,yBAAyB,CAAC;CACpC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC3F,wBAAwB,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/memory/factory/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC;IACX;;;OAGG;IACH,MAAM,CAAC,EAAE,6BAA6B,CAAC,QAAQ,CAAC,CAAC;CAClD,GAAG;IACF,yDAAyD;IACzD,MAAM,EAAE,yBAAyB,CAAC;IAClC;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,sBAAsB,GAAG,8BAA8B,GAAG,MAAM,CAAC;CAC5E,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC3F,wBAAwB,CAAC,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/memory/v1/helper.ts"],"names":[],"mappings":"AAEA,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,MAAM,EACxB,MAAM,EAAE;IACN,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GACA,OAAO,CAAC,IAAI,CAAC,CA8Cf"}
1
+ {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/memory/v1/helper.ts"],"names":[],"mappings":"AAGA,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,MAAM,EACxB,MAAM,EAAE;IACN,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GACA,OAAO,CAAC,IAAI,CAAC,CAuDf"}
@@ -35,9 +35,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
38
41
  Object.defineProperty(exports, "__esModule", { value: true });
39
42
  exports.createTableV1 = createTableV1;
40
43
  var pg_1 = require("pg");
44
+ var pg_format_1 = __importDefault(require("pg-format"));
41
45
  function createTableV1(connectionString, config) {
42
46
  return __awaiter(this, void 0, void 0, function () {
43
47
  var client;
@@ -52,23 +56,23 @@ function createTableV1(connectionString, config) {
52
56
  case 2:
53
57
  _a.trys.push([2, , 10, 12]);
54
58
  if (!(config === null || config === void 0 ? void 0 : config.dropIfExist)) return [3 /*break*/, 6];
55
- return [4 /*yield*/, client.query("DROP TABLE IF EXISTS ".concat(config.tables.state, ";"))];
59
+ return [4 /*yield*/, client.query((0, pg_format_1.default)('DROP TABLE IF EXISTS %I CASCADE;', config.tables.state))];
56
60
  case 3:
57
61
  _a.sent();
58
- return [4 /*yield*/, client.query("DROP TABLE IF EXISTS ".concat(config.tables.lock, ";"))];
62
+ return [4 /*yield*/, client.query((0, pg_format_1.default)('DROP TABLE IF EXISTS %I CASCADE;', config.tables.lock))];
59
63
  case 4:
60
64
  _a.sent();
61
- return [4 /*yield*/, client.query("DROP TABLE IF EXISTS ".concat(config.tables.hierarchy, ";"))];
65
+ return [4 /*yield*/, client.query((0, pg_format_1.default)('DROP TABLE IF EXISTS %I CASCADE;', config.tables.hierarchy))];
62
66
  case 5:
63
67
  _a.sent();
64
68
  _a.label = 6;
65
- case 6: return [4 /*yield*/, client.query("\n CREATE TABLE IF NOT EXISTS ".concat(config.tables.state, " (\n subject VARCHAR(255) PRIMARY KEY,\n data JSONB NOT NULL,\n version INTEGER NOT NULL DEFAULT 1,\n execution_status VARCHAR(255) NOT NULL,\n parent_subject VARCHAR(255),\n initiator VARCHAR(255),\n source VARCHAR(255) NOT NULL,\n created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n );\n "))];
69
+ case 6: return [4 /*yield*/, client.query((0, pg_format_1.default)("CREATE TABLE IF NOT EXISTS %I (\n subject VARCHAR(255) PRIMARY KEY,\n data JSONB NOT NULL,\n version INTEGER NOT NULL DEFAULT 1,\n execution_status VARCHAR(255) NOT NULL,\n parent_subject VARCHAR(255),\n initiator VARCHAR(255),\n source VARCHAR(255) NOT NULL,\n created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n )", config.tables.state))];
66
70
  case 7:
67
71
  _a.sent();
68
- return [4 /*yield*/, client.query("\n CREATE TABLE IF NOT EXISTS ".concat(config.tables.lock, " (\n subject VARCHAR(255) PRIMARY KEY,\n locked_at TIMESTAMP NOT NULL,\n expires_at TIMESTAMP NOT NULL,\n created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n );\n "))];
72
+ return [4 /*yield*/, client.query((0, pg_format_1.default)("CREATE TABLE IF NOT EXISTS %I (\n subject VARCHAR(255) PRIMARY KEY,\n locked_at TIMESTAMP NOT NULL,\n expires_at TIMESTAMP NOT NULL,\n created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n )", config.tables.lock))];
69
73
  case 8:
70
74
  _a.sent();
71
- return [4 /*yield*/, client.query("\n CREATE TABLE IF NOT EXISTS ".concat(config.tables.hierarchy, " (\n subject VARCHAR(255) PRIMARY KEY,\n parent_subject VARCHAR(255),\n root_subject VARCHAR(255) NOT NULL,\n created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n );\n "))];
75
+ return [4 /*yield*/, client.query((0, pg_format_1.default)("CREATE TABLE IF NOT EXISTS %I (\n subject VARCHAR(255) PRIMARY KEY,\n parent_subject VARCHAR(255),\n root_subject VARCHAR(255) NOT NULL,\n created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n )", config.tables.hierarchy))];
72
76
  case 9:
73
77
  _a.sent();
74
78
  return [3 /*break*/, 12];
@@ -1 +1 @@
1
- {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/memory/v1/helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,sCAwDC;AA1DD,yBAA4B;AAE5B,SAAsB,aAAa,CACjC,gBAAwB,EACxB,MAOC;;;;;;oBAEK,MAAM,GAAG,IAAI,WAAM,CAAC,EAAE,g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