@arvo-tools/postgres 1.1.0 → 1.2.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.
@@ -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,3 +1,5 @@
1
+ export { PostgresEventBroker } from './broker';
2
+ export type { HandlerRegistrationOptions, QueueOptions, WorkerConfigOptions, WorkerJobOptions, WorkerOptions, } from './broker/types';
1
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';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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"}
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,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PostgressMachineMemoryV1 = exports.releasePostgressMachineMemory = 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
8
  Object.defineProperty(exports, "releasePostgressMachineMemory", { enumerable: true, get: function () { return factory_1.releasePostgressMachineMemory; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4CAG0B;AAFxB,uHAAA,4BAA4B,OAAA;AAC5B,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"}
@@ -95,6 +95,10 @@ declare const tableSchema: {
95
95
  is_nullable: "YES";
96
96
  }>;
97
97
  }, "strip", z.ZodTypeAny, {
98
+ source: {
99
+ data_type: "character varying";
100
+ is_nullable: "NO";
101
+ };
98
102
  subject: {
99
103
  data_type: "character varying";
100
104
  is_nullable: "NO";
@@ -119,10 +123,6 @@ declare const tableSchema: {
119
123
  data_type: "character varying";
120
124
  is_nullable: "YES";
121
125
  };
122
- source: {
123
- data_type: "character varying";
124
- is_nullable: "NO";
125
- };
126
126
  created_at: {
127
127
  data_type: "timestamp without time zone";
128
128
  is_nullable: "YES";
@@ -132,6 +132,10 @@ declare const tableSchema: {
132
132
  is_nullable: "YES";
133
133
  };
134
134
  }, {
135
+ source: {
136
+ data_type: "character varying";
137
+ is_nullable: "NO";
138
+ };
135
139
  subject: {
136
140
  data_type: "character varying";
137
141
  is_nullable: "NO";
@@ -156,10 +160,6 @@ declare const tableSchema: {
156
160
  data_type: "character varying";
157
161
  is_nullable: "YES";
158
162
  };
159
- source: {
160
- data_type: "character varying";
161
- is_nullable: "NO";
162
- };
163
163
  created_at: {
164
164
  data_type: "timestamp without time zone";
165
165
  is_nullable: "YES";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arvo-tools/postgres",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "The official package for Arvo's execution components in Postgres",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,6 +29,7 @@
29
29
  "dependencies": {
30
30
  "arvo-core": "3.0.28",
31
31
  "pg": "8.16.3",
32
+ "pg-boss": "12.5.4",
32
33
  "pg-format": "1.0.4",
33
34
  "zod": "3.25.76"
34
35
  },
@@ -41,7 +42,7 @@
41
42
  "vitest": "4.0.13"
42
43
  },
43
44
  "engines": {
44
- "node": ">=18.0.0"
45
+ "node": ">=22.12.0"
45
46
  },
46
47
  "scripts": {
47
48
  "build": "tsc",