@palmetto/pubsub 3.2.2 → 3.2.3

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/README.md CHANGED
@@ -55,7 +55,7 @@ yarn add @palmetto/pubsub zod @palmetto/trace dd-trace
55
55
  const publisher = new Publisher(console, [rabbitMqPublisher]);
56
56
 
57
57
  const message: Model = {
58
- id: undefined,
58
+ id: undefined, // leave id and meta undefined, the publisher will set these
59
59
  meta: undefined,
60
60
  message: "Hello, world!",
61
61
  };
@@ -1,22 +1,28 @@
1
1
  import { z } from "zod";
2
+ /**
3
+ * 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
+ */
2
5
  export declare const MetaSchema: z.ZodObject<{
3
- createdAt: z.ZodISODateTime;
4
- schemaId: z.ZodString;
5
- publishedBy: z.ZodString;
6
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
7
+ schemaId: z.ZodOptional<z.ZodString>;
8
+ publishedBy: z.ZodOptional<z.ZodString>;
6
9
  }, z.core.$strip>;
10
+ /**
11
+ * The id and meta fields that are added to all messages by the publisher if not provided.
12
+ */
7
13
  export declare const IdMetaSchema: z.ZodObject<{
8
14
  id: z.ZodOptional<z.ZodString>;
9
15
  meta: z.ZodOptional<z.ZodObject<{
10
- createdAt: z.ZodISODateTime;
11
- schemaId: z.ZodString;
12
- publishedBy: z.ZodString;
16
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
17
+ schemaId: z.ZodOptional<z.ZodString>;
18
+ publishedBy: z.ZodOptional<z.ZodString>;
13
19
  }, z.core.$strip>>;
14
20
  }, z.core.$strip>;
15
21
  export type Meta = z.infer<typeof MetaSchema>;
16
22
  /**
17
23
  * All messages should be based on this schema
18
24
  */
19
- export type BaseMessage = z.infer<typeof IdMetaSchema>;
25
+ export type BaseMessage = Record<string, unknown> & z.infer<typeof IdMetaSchema>;
20
26
  export interface PublishMessageOptions {
21
27
  /**
22
28
  * The date and time at which the message should be published. Only supported by BullMq at this time.
@@ -2,13 +2,35 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MessageResult = exports.IdMetaSchema = exports.MetaSchema = void 0;
4
4
  const zod_1 = require("zod");
5
+ /**
6
+ * 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.
7
+ */
5
8
  exports.MetaSchema = zod_1.z.object({
6
- createdAt: zod_1.z.iso.datetime(),
7
- schemaId: zod_1.z.string(),
8
- publishedBy: zod_1.z.string(),
9
+ /**
10
+ * The date and time at which the message was created.
11
+ */
12
+ createdAt: zod_1.z.iso.datetime().optional(),
13
+ /**
14
+ * The unique identifier for the schema used by the message. Currently a hash of the JSON schema definition, but could be changed in the future to for example a UUID or a URL where the schema can be found.
15
+ */
16
+ schemaId: zod_1.z.string().optional(),
17
+ /**
18
+ * The identifier of the entity that published the message. (currently an empty string, but could be used to identify the service that published the message)
19
+ */
20
+ publishedBy: zod_1.z.string().optional(),
9
21
  });
22
+ /**
23
+ * The id and meta fields that are added to all messages by the publisher if not provided.
24
+ */
10
25
  exports.IdMetaSchema = zod_1.z.object({
26
+ /**
27
+ * A unique identifier for the message. If not provided, one will be generated during publish.
28
+ */
11
29
  id: zod_1.z.string().optional(),
30
+ /**
31
+ * Metadata about the message, such as when it was created, which schema it uses, etc.
32
+ * This is optional when publishing a message, but will be added by the publisher if not provided.
33
+ */
12
34
  meta: exports.MetaSchema.optional(),
13
35
  });
14
36
  var MessageResult;
package/dist/publisher.js CHANGED
@@ -80,6 +80,7 @@ class Publisher {
80
80
  }
81
81
  else {
82
82
  msg.meta.schemaId = schemaId;
83
+ msg.meta.createdAt = new Date().toISOString();
83
84
  }
84
85
  const check = schema.safeEncode(msg);
85
86
  if (!check.success) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palmetto/pubsub",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/palmetto/galaxy"