@palmetto/pubsub 3.4.1 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/interfaces.d.ts +2 -1
- package/dist/publisher.d.ts +1 -1
- package/dist/publisher.js +4 -5
- package/dist/subscriber.js +2 -1
- package/package.json +7 -9
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { $ZodType } from "zod/v4/core";
|
|
2
3
|
/**
|
|
3
4
|
* The schema for the metadata of a message. This is added by the publisher if not provided, but can also be provided by the publisher if they want to set specific values.
|
|
4
5
|
*/
|
|
@@ -52,7 +53,7 @@ export interface PubSubConfiguration {
|
|
|
52
53
|
/**
|
|
53
54
|
* The schema for the message - the message is verfied during publish and subscribe
|
|
54
55
|
*/
|
|
55
|
-
schema:
|
|
56
|
+
schema: $ZodType<BaseMessage>;
|
|
56
57
|
/**
|
|
57
58
|
* The message transport to use (defined by the event-pubsub implementations)
|
|
58
59
|
*/
|
package/dist/publisher.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare class Publisher {
|
|
|
59
59
|
addProvider(provider: PublisherProvider): void;
|
|
60
60
|
removeProvider(providerOrTransport: PublisherProvider | string): boolean;
|
|
61
61
|
init(config: PubSubConfiguration): Promise<void>;
|
|
62
|
-
publish(config: PubSubConfiguration, message:
|
|
62
|
+
publish<TMessage extends BaseMessage>(config: PubSubConfiguration, message: TMessage | TMessage[], options?: PublishMessageOptions): Promise<void>;
|
|
63
63
|
private publishImpl;
|
|
64
64
|
close(): Promise<void>;
|
|
65
65
|
private getProvider;
|
package/dist/publisher.js
CHANGED
|
@@ -11,8 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Publisher = void 0;
|
|
13
13
|
const zod_1 = require("zod");
|
|
14
|
-
const
|
|
15
|
-
const crypto_1 = require("crypto");
|
|
14
|
+
const node_crypto_1 = require("node:crypto");
|
|
16
15
|
const trace_1 = require("@palmetto/trace");
|
|
17
16
|
const errors_js_1 = require("./errors.js");
|
|
18
17
|
const message_logger_js_1 = require("./message-logger.js");
|
|
@@ -77,7 +76,7 @@ class Publisher {
|
|
|
77
76
|
const { schema, schemaId } = this.assertSchema(config);
|
|
78
77
|
const mappedMessages = messages.map((msg) => {
|
|
79
78
|
if (!msg.id) {
|
|
80
|
-
msg.id = (0,
|
|
79
|
+
msg.id = (0, node_crypto_1.randomUUID)();
|
|
81
80
|
}
|
|
82
81
|
if (!msg.meta) {
|
|
83
82
|
msg.meta = {
|
|
@@ -90,7 +89,7 @@ class Publisher {
|
|
|
90
89
|
msg.meta.schemaId = schemaId;
|
|
91
90
|
msg.meta.createdAt = new Date().toISOString();
|
|
92
91
|
}
|
|
93
|
-
const check =
|
|
92
|
+
const check = zod_1.z.safeEncode(schema, msg);
|
|
94
93
|
if (!check.success) {
|
|
95
94
|
(0, message_logger_js_1.logMessage)({
|
|
96
95
|
note: "Publish message failed schema validation",
|
|
@@ -174,7 +173,7 @@ class Publisher {
|
|
|
174
173
|
if (!hash) {
|
|
175
174
|
(_b = (_a = this.logger).debug) === null || _b === void 0 ? void 0 : _b.call(_a, `Calculating schema id for ${config.name}`);
|
|
176
175
|
const jsonSchema = JSON.stringify(zod_1.z.toJSONSchema(schema, { io: "input" }), null, 2);
|
|
177
|
-
hash = (0,
|
|
176
|
+
hash = (0, node_crypto_1.createHash)("sha256").update(jsonSchema).digest("hex");
|
|
178
177
|
this.hashes.set(schema, hash);
|
|
179
178
|
}
|
|
180
179
|
return {
|
package/dist/subscriber.js
CHANGED
|
@@ -15,6 +15,7 @@ const errors_js_1 = require("./errors.js");
|
|
|
15
15
|
const events_1 = require("events");
|
|
16
16
|
const message_logger_js_1 = require("./message-logger.js");
|
|
17
17
|
const create_log_error_payload_js_1 = require("./create-log-error-payload.js");
|
|
18
|
+
const zod_1 = require("zod");
|
|
18
19
|
class SubscribedMessage {
|
|
19
20
|
constructor(stop) {
|
|
20
21
|
this.stop = stop;
|
|
@@ -65,7 +66,7 @@ class Subscriber {
|
|
|
65
66
|
};
|
|
66
67
|
this.events.emit("messageReceived", messageReceivedEventContext);
|
|
67
68
|
const jsonObject = JSON.parse(jsonStr);
|
|
68
|
-
const decodeResult =
|
|
69
|
+
const decodeResult = zod_1.z.safeDecode(schema, jsonObject);
|
|
69
70
|
if (!decodeResult.success) {
|
|
70
71
|
const durationMs = (0, message_logger_js_1.getDuration)(start);
|
|
71
72
|
(0, message_logger_js_1.logMessage)({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@palmetto/pubsub",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/palmetto/galaxy"
|
|
@@ -10,18 +10,19 @@
|
|
|
10
10
|
"lint": "yarn run -T eslint --fix ./src",
|
|
11
11
|
"format": "yarn run -T prettier --write --loglevel warn .",
|
|
12
12
|
"tc": "tsc --noEmit",
|
|
13
|
-
"
|
|
13
|
+
"test": "yarn test-runner 'vitest run'",
|
|
14
|
+
"test:watch": "yarn test-runner 'vitest watch'",
|
|
15
|
+
"build": "yarn clean && yarn ci:build",
|
|
14
16
|
"clean": "rm -rf ./dist/",
|
|
15
17
|
"ci:build": "tsc -p tsconfig.build.json",
|
|
16
18
|
"ci:lint": "yarn run -T eslint . && yarn run -T prettier --check --loglevel warn .",
|
|
17
19
|
"ci:tc": "yarn tc",
|
|
20
|
+
"ci:test": "yarn run -T ci:test --project=@palmetto/pubsub",
|
|
18
21
|
"hook:lint": "eslint --cache --fix",
|
|
19
22
|
"hook:format": "prettier --write --loglevel warn",
|
|
20
23
|
"hook:tc": "yarn tc",
|
|
21
24
|
"prepublishOnly": "yarn build",
|
|
22
|
-
"test-runner": "../../scripts/test-runner.sh"
|
|
23
|
-
"test": "yarn run test-runner vitest run",
|
|
24
|
-
"test:watch": "yarn run test-runner vitest watch"
|
|
25
|
+
"test-runner": "../../scripts/test-runner.sh yarn run -T $0 --project @palmetto/pubsub"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@google-cloud/pubsub": "^5.2.3",
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"bullmq": "^5.70.2",
|
|
34
35
|
"ts-node": "^10.9.2",
|
|
35
36
|
"typescript": "^5.8.3",
|
|
36
|
-
"vitest": "^
|
|
37
|
+
"vitest": "^4.1.5",
|
|
37
38
|
"zod": "^4.1.13"
|
|
38
39
|
},
|
|
39
40
|
"files": [
|
|
@@ -46,9 +47,6 @@
|
|
|
46
47
|
"publishConfig": {
|
|
47
48
|
"access": "public"
|
|
48
49
|
},
|
|
49
|
-
"dependencies": {
|
|
50
|
-
"uuid": "^11.1.0"
|
|
51
|
-
},
|
|
52
50
|
"peerDependencies": {
|
|
53
51
|
"@google-cloud/pubsub": "^5.2",
|
|
54
52
|
"@palmetto/trace": "^0.1.1",
|