@arvo-tools/postgres 1.0.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.
Files changed (37) hide show
  1. package/dist/index.d.ts +5 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +10 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/memory/factory/defaults.d.ts +5 -0
  6. package/dist/memory/factory/defaults.d.ts.map +1 -0
  7. package/dist/memory/factory/defaults.js +9 -0
  8. package/dist/memory/factory/defaults.js.map +1 -0
  9. package/dist/memory/factory/index.d.ts +117 -0
  10. package/dist/memory/factory/index.d.ts.map +1 -0
  11. package/dist/memory/factory/index.js +202 -0
  12. package/dist/memory/factory/index.js.map +1 -0
  13. package/dist/memory/factory/type.d.ts +29 -0
  14. package/dist/memory/factory/type.d.ts.map +1 -0
  15. package/dist/memory/factory/type.js +3 -0
  16. package/dist/memory/factory/type.js.map +1 -0
  17. package/dist/memory/types.d.ts +49 -0
  18. package/dist/memory/types.d.ts.map +1 -0
  19. package/dist/memory/types.js +3 -0
  20. package/dist/memory/types.js.map +1 -0
  21. package/dist/memory/v1/helper.d.ts +9 -0
  22. package/dist/memory/v1/helper.d.ts.map +1 -0
  23. package/dist/memory/v1/helper.js +84 -0
  24. package/dist/memory/v1/helper.js.map +1 -0
  25. package/dist/memory/v1/index.d.ts +88 -0
  26. package/dist/memory/v1/index.d.ts.map +1 -0
  27. package/dist/memory/v1/index.js +667 -0
  28. package/dist/memory/v1/index.js.map +1 -0
  29. package/dist/memory/v1/schema.d.ts +334 -0
  30. package/dist/memory/v1/schema.d.ts.map +1 -0
  31. package/dist/memory/v1/schema.js +159 -0
  32. package/dist/memory/v1/schema.js.map +1 -0
  33. package/dist/memory/v1/types.d.ts +28 -0
  34. package/dist/memory/v1/types.d.ts.map +1 -0
  35. package/dist/memory/v1/types.js +3 -0
  36. package/dist/memory/v1/types.js.map +1 -0
  37. package/package.json +54 -0
@@ -0,0 +1,5 @@
1
+ export { connectPostgresMachineMemory, createPostgresMachineMemoryTables, releasePostgressMachineMemory, } from './memory/factory';
2
+ export type { ConnectPostgresMachineMemoryParam, PostgresMachineMemory, } from './memory/factory/type';
3
+ export type { PostgressConnectionConfig } from './memory/types';
4
+ export { PostgressMachineMemoryV1 } from './memory/v1';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PostgressMachineMemoryV1 = exports.releasePostgressMachineMemory = exports.createPostgresMachineMemoryTables = exports.connectPostgresMachineMemory = void 0;
4
+ var factory_1 = require("./memory/factory");
5
+ 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
+ Object.defineProperty(exports, "releasePostgressMachineMemory", { enumerable: true, get: function () { return factory_1.releasePostgressMachineMemory; } });
8
+ var v1_1 = require("./memory/v1");
9
+ Object.defineProperty(exports, "PostgressMachineMemoryV1", { enumerable: true, get: function () { return v1_1.PostgressMachineMemoryV1; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,5 @@
1
+ import type { ConnectPostgresMachineMemoryParam } from './type';
2
+ export declare const DEFAULT_V1_TABLE_NAMES: NonNullable<Extract<ConnectPostgresMachineMemoryParam, {
3
+ version: 1;
4
+ }>['tables']>;
5
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../src/memory/factory/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,QAAQ,CAAC;AAEhE,eAAO,MAAM,sBAAsB,EAAE,WAAW,CAC9C,OAAO,CAAC,iCAAiC,EAAE;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC,QAAQ,CAAC,CAKrE,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_V1_TABLE_NAMES = void 0;
4
+ exports.DEFAULT_V1_TABLE_NAMES = {
5
+ state: 'arvopg_mm_state',
6
+ lock: 'arvopg_mm_lock',
7
+ hierarchy: 'arvopg_mm_hierarchy',
8
+ };
9
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../src/memory/factory/defaults.ts"],"names":[],"mappings":";;;AAEa,QAAA,sBAAsB,GAE/B;IACF,KAAK,EAAE,iBAAiB;IACxB,IAAI,EAAE,gBAAgB;IACtB,SAAS,EAAE,qBAAqB;CACjC,CAAC"}
@@ -0,0 +1,117 @@
1
+ import type { ConnectPostgresMachineMemoryParam, PostgresMachineMemory } from './type';
2
+ /**
3
+ * Connects to and validates a PostgreSQL-backed machine memory instance.
4
+ *
5
+ * This function establishes a PostgreSQL connection pool, validates that the required
6
+ * database tables exist with the correct schema, and returns a ready-to-use machine
7
+ * memory instance for workflow state management.
8
+ *
9
+ * The connection pool will remain open until explicitly closed via `releasePostgressMachineMemory`.
10
+ *
11
+ * @param params - Configuration including version, table names, and connection settings
12
+ * @returns A validated PostgreSQL machine memory instance with an active connection pool
13
+ *
14
+ * @throws Error if the specified version is not supported
15
+ * @throws Error if table validation fails (missing tables or incorrect schema)
16
+ * @throws Error if database connection fails
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const memory = await connectPostgresMachineMemory({
21
+ * version: 1,
22
+ * tables: {
23
+ * state: 'machine_memory_state',
24
+ * lock: 'machine_memory_lock',
25
+ * hierarchy: 'machine_memory_hierarchy'
26
+ * },
27
+ * config: {
28
+ * connectionString: 'postgresql://user:pass@localhost:5432/mydb',
29
+ * enableCleanup: true,
30
+ * lockConfig: {
31
+ * maxRetries: 3,
32
+ * ttlMs: 120000
33
+ * }
34
+ * }
35
+ * });
36
+ *
37
+ * // Use the memory instance...
38
+ *
39
+ * // Clean up when done
40
+ * await releasePostgressMachineMemory(memory);
41
+ * ```
42
+ */
43
+ export declare const connectPostgresMachineMemory: <T extends Record<string, unknown> = Record<string, unknown>>({ version, tables, config, }: ConnectPostgresMachineMemoryParam) => Promise<PostgresMachineMemory<T>>;
44
+ /**
45
+ * Releases all resources held by a PostgreSQL machine memory instance.
46
+ *
47
+ * This function gracefully closes the underlying connection pool, releasing all database
48
+ * connections and terminating any idle connections. Should be called when the machine
49
+ * memory instance is no longer needed to prevent connection leaks and ensure proper
50
+ * resource cleanup.
51
+ *
52
+ * After calling this function, the memory instance should not be used for any further operations.
53
+ *
54
+ * @param memory - The PostgreSQL machine memory instance to release
55
+ */
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
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.createPostgresMachineMemoryTables = exports.releasePostgressMachineMemory = exports.connectPostgresMachineMemory = void 0;
40
+ var v1_1 = require("../v1");
41
+ var helper_1 = require("../v1/helper");
42
+ var defaults_1 = require("./defaults");
43
+ /**
44
+ * Connects to and validates a PostgreSQL-backed machine memory instance.
45
+ *
46
+ * This function establishes a PostgreSQL connection pool, validates that the required
47
+ * database tables exist with the correct schema, and returns a ready-to-use machine
48
+ * memory instance for workflow state management.
49
+ *
50
+ * The connection pool will remain open until explicitly closed via `releasePostgressMachineMemory`.
51
+ *
52
+ * @param params - Configuration including version, table names, and connection settings
53
+ * @returns A validated PostgreSQL machine memory instance with an active connection pool
54
+ *
55
+ * @throws Error if the specified version is not supported
56
+ * @throws Error if table validation fails (missing tables or incorrect schema)
57
+ * @throws Error if database connection fails
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const memory = await connectPostgresMachineMemory({
62
+ * version: 1,
63
+ * tables: {
64
+ * state: 'machine_memory_state',
65
+ * lock: 'machine_memory_lock',
66
+ * hierarchy: 'machine_memory_hierarchy'
67
+ * },
68
+ * config: {
69
+ * connectionString: 'postgresql://user:pass@localhost:5432/mydb',
70
+ * enableCleanup: true,
71
+ * lockConfig: {
72
+ * maxRetries: 3,
73
+ * ttlMs: 120000
74
+ * }
75
+ * }
76
+ * });
77
+ *
78
+ * // Use the memory instance...
79
+ *
80
+ * // Clean up when done
81
+ * await releasePostgressMachineMemory(memory);
82
+ * ```
83
+ */
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) {
89
+ 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));
100
+ }
101
+ });
102
+ }); };
103
+ exports.connectPostgresMachineMemory = connectPostgresMachineMemory;
104
+ /**
105
+ * Releases all resources held by a PostgreSQL machine memory instance.
106
+ *
107
+ * This function gracefully closes the underlying connection pool, releasing all database
108
+ * connections and terminating any idle connections. Should be called when the machine
109
+ * memory instance is no longer needed to prevent connection leaks and ensure proper
110
+ * resource cleanup.
111
+ *
112
+ * After calling this function, the memory instance should not be used for any further operations.
113
+ *
114
+ * @param memory - The PostgreSQL machine memory instance to release
115
+ */
116
+ var releasePostgressMachineMemory = function (memory) { return __awaiter(void 0, void 0, void 0, function () {
117
+ return __generator(this, function (_a) {
118
+ switch (_a.label) {
119
+ case 0: return [4 /*yield*/, memory.close()];
120
+ case 1:
121
+ _a.sent();
122
+ return [2 /*return*/];
123
+ }
124
+ });
125
+ }); };
126
+ 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
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/memory/factory/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAAiD;AACjD,uCAA6C;AAC7C,uCAAoD;AAGpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACI,IAAM,4BAA4B,GAAG,iEAE1C,EAIkC;;QAHlC,OAAO,aAAA,EACP,MAAM,YAAA,EACN,MAAM,YAAA;;;;qBAEF,CAAA,OAAO,KAAK,CAAC,CAAA,EAAb,wBAAa;gBACT,MAAM,GAAG,IAAI,6BAAwB,CAAI;oBAC7C,MAAM,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,iCAAsB;oBACxC,MAAM,QAAA;iBACP,CAAC,CAAC;gBACH,qBAAM,MAAM,CAAC,sBAAsB,EAAE,EAAA;;gBAArC,SAAqC,CAAC;gBACtC,sBAAO,MAAM,EAAC;oBAEhB,MAAM,IAAI,KAAK,CAAC,yDAAkD,OAAO,CAAE,CAAC,CAAC;;;KAC9E,CAAC;AAhBW,QAAA,4BAA4B,gCAgBvC;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;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACI,IAAM,iCAAiC,GAAG,UAC/C,gBAAwB,EACxB,MAEC;;;;;qBAEG,CAAA,MAAM,CAAC,OAAO,KAAK,CAAC,CAAA,EAApB,wBAAoB;gBACtB,qBAAM,IAAA,sBAAa,EAAC,gBAAgB,EAAE;wBACpC,WAAW,EAAE,MAAM,CAAC,4BAA4B;wBAChD,MAAM,EAAE,MAAA,MAAM,CAAC,MAAM,mCAAI,iCAAsB;qBAChD,CAAC,EAAA;;gBAHF,SAGE,CAAC;gBACH,sBAAO;oBAET,MAAM,IAAI,KAAK,CAAC,yDAAkD,MAAM,CAAC,OAAO,CAAE,CAAC,CAAC;;;KACrF,CAAC;AAdW,QAAA,iCAAiC,qCAc5C"}
@@ -0,0 +1,29 @@
1
+ import type { PostgressConnectionConfig } from '../types';
2
+ import type { PostgressMachineMemoryV1 } from '../v1';
3
+ import type { PostgressMachineMemoryV1Param } from '../v1/types';
4
+ /**
5
+ * Configuration parameters for connecting a PostgreSQL-backed machine memory instance.
6
+ */
7
+ export type ConnectPostgresMachineMemoryParam = {
8
+ /**
9
+ * Schema version of the PostgreSQL machine memory implementation.
10
+ * Currently only version 1 is supported.
11
+ */
12
+ version: 1;
13
+ /**
14
+ * Names of the PostgreSQL tables used by the machine memory.
15
+ * These tables must exist and match the expected schema structure.
16
+ */
17
+ tables?: PostgressMachineMemoryV1Param['tables'];
18
+ } & {
19
+ /** PostgreSQL connection and behavioral configuration. Optional, uses defaults if not provided */
20
+ config?: PostgressConnectionConfig;
21
+ };
22
+ /**
23
+ * Type alias for PostgreSQL-backed machine memory instances.
24
+ *
25
+ * Provides a version-agnostic interface for PostgreSQL machine memory,
26
+ * abstracting the underlying implementation version from consumers.
27
+ */
28
+ export type PostgresMachineMemory<T extends Record<string, unknown> = Record<string, unknown>> = PostgressMachineMemoryV1<T>;
29
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/memory/factory/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * PostgreSQL connection configuration for machine memory.
3
+ *
4
+ * Supports two connection modes:
5
+ * - Connection string: A single URL containing all connection parameters
6
+ * - Individual parameters: Separate host, port, user, password, and database fields
7
+ */
8
+ export type PostgressConnectionConfig = ({
9
+ /** PostgreSQL connection string (e.g., "postgresql://user:password@localhost:5432/dbname") */
10
+ connectionString: string;
11
+ } | {
12
+ /** Database host address. Defaults to "localhost" */
13
+ host?: string;
14
+ /** Database port. Defaults to 5432 */
15
+ port?: number;
16
+ /** Database user. Defaults to "postgres" */
17
+ user?: string;
18
+ /** Database password. Defaults to "postgres" */
19
+ password?: string;
20
+ /** Database name. Defaults to "postgres" */
21
+ database?: string;
22
+ }) & {
23
+ /** Maximum number of clients in the connection pool. Defaults to 10 */
24
+ max?: number;
25
+ /** Time in milliseconds a client must sit idle before being removed from pool. Defaults to 30000 (30 seconds) */
26
+ idleTimeoutMillis?: number;
27
+ /** Time in milliseconds to wait for a connection from the pool. Defaults to 5000 (5 seconds) */
28
+ connectionTimeoutMillis?: number;
29
+ /** Time in milliseconds before a statement in a query is cancelled. Optional */
30
+ statementTimeoutMillis?: number;
31
+ /** Time in milliseconds before a query is cancelled. Optional */
32
+ queryTimeoutMillis?: number;
33
+ /** Configuration for distributed locking behavior */
34
+ lockConfig?: {
35
+ /** Maximum number of lock acquisition retry attempts. Defaults to 3 */
36
+ maxRetries?: number;
37
+ /** Initial delay in milliseconds before first retry. Defaults to 100 */
38
+ initialDelayMs?: number;
39
+ /** Exponential backoff multiplier for subsequent retries. Defaults to 1.5 */
40
+ backoffExponent?: number;
41
+ /** Lock time-to-live in milliseconds. Prevents deadlocks via automatic expiration. Defaults to 120000 (2 minutes) */
42
+ ttlMs?: number;
43
+ };
44
+ /** Whether to enable automatic cleanup of completed workflows. Defaults to false */
45
+ enableCleanup?: boolean;
46
+ /** Whether to enable OpenTelemetry tracing. Defaults to false */
47
+ enableOtel?: boolean;
48
+ };
49
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/memory/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,CACpC;IACE,8FAA8F;IAC9F,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GACD;IACE,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CACJ,GAAG;IACF,uEAAuE;IACvE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iHAAiH;IACjH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gGAAgG;IAChG,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,gFAAgF;IAChF,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,iEAAiE;IACjE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qDAAqD;IACrD,UAAU,CAAC,EAAE;QACX,uEAAuE;QACvE,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,wEAAwE;QACxE,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,6EAA6E;QAC7E,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,qHAAqH;QACrH,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,oFAAoF;IACpF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iEAAiE;IACjE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC"}
@@ -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/memory/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export declare function createTableV1(connectionString: string, config: {
2
+ tables: {
3
+ state: string;
4
+ lock: string;
5
+ hierarchy: string;
6
+ };
7
+ dropIfExist?: boolean;
8
+ }): Promise<void>;
9
+ //# sourceMappingURL=helper.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.createTableV1 = createTableV1;
40
+ var pg_1 = require("pg");
41
+ function createTableV1(connectionString, config) {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ var client;
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0:
47
+ client = new pg_1.Client({ connectionString: connectionString });
48
+ return [4 /*yield*/, client.connect()];
49
+ case 1:
50
+ _a.sent();
51
+ _a.label = 2;
52
+ case 2:
53
+ _a.trys.push([2, , 10, 12]);
54
+ 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, ";"))];
56
+ case 3:
57
+ _a.sent();
58
+ return [4 /*yield*/, client.query("DROP TABLE IF EXISTS ".concat(config.tables.lock, ";"))];
59
+ case 4:
60
+ _a.sent();
61
+ return [4 /*yield*/, client.query("DROP TABLE IF EXISTS ".concat(config.tables.hierarchy, ";"))];
62
+ case 5:
63
+ _a.sent();
64
+ _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 "))];
66
+ case 7:
67
+ _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 "))];
69
+ case 8:
70
+ _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 "))];
72
+ case 9:
73
+ _a.sent();
74
+ return [3 /*break*/, 12];
75
+ case 10: return [4 /*yield*/, client.end()];
76
+ case 11:
77
+ _a.sent();
78
+ return [7 /*endfinally*/];
79
+ case 12: return [2 /*return*/];
80
+ }
81
+ });
82
+ });
83
+ }
84
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +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,gBAAgB,kBAAA,EAAE,CAAC,CAAC;oBAEhD,qBAAM,MAAM,CAAC,OAAO,EAAE,EAAA;;oBAAtB,SAAsB,CAAC;;;;yBAGjB,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,CAAA,EAAnB,wBAAmB;oBACrB,qBAAM,MAAM,CAAC,KAAK,CAAC,+BAAwB,MAAM,CAAC,MAAM,CAAC,KAAK,MAAG,CAAC,EAAA;;oBAAlE,SAAkE,CAAC;oBACnE,qBAAM,MAAM,CAAC,KAAK,CAAC,+BAAwB,MAAM,CAAC,MAAM,CAAC,IAAI,MAAG,CAAC,EAAA;;oBAAjE,SAAiE,CAAC;oBAClE,qBAAM,MAAM,CAAC,KAAK,CAAC,+BAAwB,MAAM,CAAC,MAAM,CAAC,SAAS,MAAG,CAAC,EAAA;;oBAAtE,SAAsE,CAAC;;wBAGzE,qBAAM,MAAM,CAAC,KAAK,CAAC,6CACY,MAAM,CAAC,MAAM,CAAC,KAAK,6ZAWjD,CAAC,EAAA;;oBAZF,SAYE,CAAC;oBAEH,qBAAM,MAAM,CAAC,KAAK,CAAC,6CACY,MAAM,CAAC,MAAM,CAAC,IAAI,yMAMhD,CAAC,EAAA;;oBAPF,SAOE,CAAC;oBAEH,qBAAM,MAAM,CAAC,KAAK,CAAC,6CACY,MAAM,CAAC,MAAM,CAAC,SAAS,6MAMrD,CAAC,EAAA;;oBAPF,SAOE,CAAC;;yBAEH,qBAAM,MAAM,CAAC,GAAG,EAAE,EAAA;;oBAAlB,SAAkB,CAAC;;;;;;CAEtB"}