@message-queue-toolkit/core
Advanced tools
Comparing version 13.2.0 to 13.3.0
@@ -1,87 +0,1 @@ | ||
import type { ZodLiteral, ZodObject, ZodOptional, ZodString } from 'zod'; | ||
import z from 'zod'; | ||
import type { ZodRawShape } from 'zod/lib/types'; | ||
export declare const GENERATED_BASE_EVENT_SCHEMA: ZodObject<{ | ||
id: ZodString; | ||
timestamp: ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
id: string; | ||
timestamp: string; | ||
}, { | ||
id: string; | ||
timestamp: string; | ||
}>; | ||
export declare const OPTIONAL_GENERATED_BASE_EVENT_SCHEMA: ZodObject<{ | ||
id: ZodOptional<ZodString>; | ||
timestamp: ZodOptional<ZodString>; | ||
}, "strip", z.ZodTypeAny, { | ||
id?: string | undefined; | ||
timestamp?: string | undefined; | ||
}, { | ||
id?: string | undefined; | ||
timestamp?: string | undefined; | ||
}>; | ||
export declare const CORE_EVENT_SCHEMA: ZodObject<{ | ||
type: ZodLiteral<string>; | ||
payload: ZodOptional<ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: string; | ||
payload?: {} | undefined; | ||
}, { | ||
type: string; | ||
payload?: {} | undefined; | ||
}>; | ||
export declare const CONSUMER_BASE_EVENT_SCHEMA: ZodObject<z.objectUtil.extendShape<{ | ||
id: ZodString; | ||
timestamp: ZodString; | ||
}, { | ||
type: ZodLiteral<string>; | ||
payload: ZodOptional<ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>; | ||
}>, "strip", z.ZodTypeAny, { | ||
id: string; | ||
timestamp: string; | ||
type: string; | ||
payload?: {} | undefined; | ||
}, { | ||
id: string; | ||
timestamp: string; | ||
type: string; | ||
payload?: {} | undefined; | ||
}>; | ||
export declare const PUBLISHER_BASE_EVENT_SCHEMA: ZodObject<z.objectUtil.extendShape<{ | ||
id: ZodOptional<ZodString>; | ||
timestamp: ZodOptional<ZodString>; | ||
}, { | ||
type: ZodLiteral<string>; | ||
payload: ZodOptional<ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>; | ||
}>, "strip", z.ZodTypeAny, { | ||
type: string; | ||
id?: string | undefined; | ||
timestamp?: string | undefined; | ||
payload?: {} | undefined; | ||
}, { | ||
type: string; | ||
id?: string | undefined; | ||
timestamp?: string | undefined; | ||
payload?: {} | undefined; | ||
}>; | ||
export type ConsumerBaseEventType = z.infer<typeof CONSUMER_BASE_EVENT_SCHEMA>; | ||
export type PublisherBaseEventType = z.infer<typeof PUBLISHER_BASE_EVENT_SCHEMA>; | ||
export type CoreEventType = z.infer<typeof CORE_EVENT_SCHEMA>; | ||
export type GeneratedBaseEventType = z.infer<typeof GENERATED_BASE_EVENT_SCHEMA>; | ||
type ReturnType<T extends ZodObject<Y>, Y extends ZodRawShape, Z extends string> = { | ||
consumerSchema: ZodObject<{ | ||
id: ZodString; | ||
timestamp: ZodString; | ||
type: ZodLiteral<Z>; | ||
payload: T; | ||
}>; | ||
publisherSchema: ZodObject<{ | ||
id: ZodOptional<ZodString>; | ||
timestamp: ZodOptional<ZodString>; | ||
type: ZodLiteral<Z>; | ||
payload: T; | ||
}>; | ||
}; | ||
export declare function enrichEventSchemaWithBase<T extends ZodObject<Y>, Y extends ZodRawShape, Z extends string>(type: Z, payloadSchema: T): ReturnType<T, Y, Z>; | ||
export {}; | ||
export { GENERATED_BASE_EVENT_SCHEMA, OPTIONAL_GENERATED_BASE_EVENT_SCHEMA, CORE_EVENT_SCHEMA, CONSUMER_BASE_EVENT_SCHEMA, PUBLISHER_BASE_EVENT_SCHEMA, ConsumerBaseEventType, PublisherBaseEventType, CoreEventType, GeneratedBaseEventType, enrichEventSchemaWithBase, } from '@message-queue-toolkit/schemas'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.enrichEventSchemaWithBase = exports.PUBLISHER_BASE_EVENT_SCHEMA = exports.CONSUMER_BASE_EVENT_SCHEMA = exports.CORE_EVENT_SCHEMA = exports.OPTIONAL_GENERATED_BASE_EVENT_SCHEMA = exports.GENERATED_BASE_EVENT_SCHEMA = void 0; | ||
const tslib_1 = require("tslib"); | ||
const zod_1 = tslib_1.__importDefault(require("zod")); | ||
// Base event fields that are typically autogenerated | ||
exports.GENERATED_BASE_EVENT_SCHEMA = zod_1.default.object({ | ||
id: zod_1.default.string().describe('event unique identifier'), | ||
timestamp: zod_1.default.string().datetime().describe('iso 8601 datetime'), | ||
}); | ||
// Base event fields that are typically autogenerated, marked as optional | ||
exports.OPTIONAL_GENERATED_BASE_EVENT_SCHEMA = zod_1.default.object({ | ||
id: zod_1.default.string().describe('event unique identifier').optional(), | ||
timestamp: zod_1.default.string().datetime().describe('iso 8601 datetime').optional(), | ||
}); | ||
// Base event fields that are always defined manually | ||
exports.CORE_EVENT_SCHEMA = zod_1.default.object({ | ||
type: zod_1.default.literal('<replace.me>').describe('event type name'), | ||
payload: zod_1.default.optional(zod_1.default.object({})).describe('event payload based on type'), | ||
}); | ||
// Core fields that describe either internal event or external message | ||
exports.CONSUMER_BASE_EVENT_SCHEMA = exports.GENERATED_BASE_EVENT_SCHEMA.extend(exports.CORE_EVENT_SCHEMA.shape); | ||
exports.PUBLISHER_BASE_EVENT_SCHEMA = exports.OPTIONAL_GENERATED_BASE_EVENT_SCHEMA.extend(exports.CORE_EVENT_SCHEMA.shape); | ||
function enrichEventSchemaWithBase(type, payloadSchema) { | ||
const baseSchema = zod_1.default.object({ | ||
type: zod_1.default.literal(type), | ||
payload: payloadSchema, | ||
}); | ||
const consumerSchema = exports.GENERATED_BASE_EVENT_SCHEMA.merge(baseSchema); | ||
const publisherSchema = exports.OPTIONAL_GENERATED_BASE_EVENT_SCHEMA.merge(baseSchema); | ||
return { | ||
consumerSchema: consumerSchema, | ||
publisherSchema: publisherSchema, | ||
}; | ||
} | ||
exports.enrichEventSchemaWithBase = enrichEventSchemaWithBase; | ||
var schemas_1 = require("@message-queue-toolkit/schemas"); | ||
Object.defineProperty(exports, "GENERATED_BASE_EVENT_SCHEMA", { enumerable: true, get: function () { return schemas_1.GENERATED_BASE_EVENT_SCHEMA; } }); | ||
Object.defineProperty(exports, "OPTIONAL_GENERATED_BASE_EVENT_SCHEMA", { enumerable: true, get: function () { return schemas_1.OPTIONAL_GENERATED_BASE_EVENT_SCHEMA; } }); | ||
Object.defineProperty(exports, "CORE_EVENT_SCHEMA", { enumerable: true, get: function () { return schemas_1.CORE_EVENT_SCHEMA; } }); | ||
Object.defineProperty(exports, "CONSUMER_BASE_EVENT_SCHEMA", { enumerable: true, get: function () { return schemas_1.CONSUMER_BASE_EVENT_SCHEMA; } }); | ||
Object.defineProperty(exports, "PUBLISHER_BASE_EVENT_SCHEMA", { enumerable: true, get: function () { return schemas_1.PUBLISHER_BASE_EVENT_SCHEMA; } }); | ||
Object.defineProperty(exports, "enrichEventSchemaWithBase", { enumerable: true, get: function () { return schemas_1.enrichEventSchemaWithBase; } }); | ||
//# sourceMappingURL=baseEventSchemas.js.map |
@@ -1,25 +0,1 @@ | ||
import type { ZodObject, ZodTypeAny } from 'zod'; | ||
import type z from 'zod'; | ||
import type { MessageMetadataType } from '../messages/baseMessageSchemas'; | ||
import type { CONSUMER_BASE_EVENT_SCHEMA, PUBLISHER_BASE_EVENT_SCHEMA } from './baseEventSchemas'; | ||
export type EventTypeNames<EventDefinition extends CommonEventDefinition> = CommonEventDefinitionConsumerSchemaType<EventDefinition>['type']; | ||
export type CommonEventDefinition = { | ||
consumerSchema: ZodObject<Omit<(typeof CONSUMER_BASE_EVENT_SCHEMA)['shape'], 'payload'> & { | ||
payload: ZodTypeAny; | ||
}>; | ||
publisherSchema: ZodObject<Omit<(typeof PUBLISHER_BASE_EVENT_SCHEMA)['shape'], 'payload'> & { | ||
payload: ZodTypeAny; | ||
}>; | ||
schemaVersion?: string; | ||
}; | ||
export type CommonEventDefinitionConsumerSchemaType<T extends CommonEventDefinition> = z.infer<T['consumerSchema']>; | ||
export type CommonEventDefinitionPublisherSchemaType<T extends CommonEventDefinition> = z.infer<T['publisherSchema']>; | ||
export type EventHandler<EventDefinitionSchema extends CommonEventDefinitionConsumerSchemaType<CommonEventDefinition> = CommonEventDefinitionConsumerSchemaType<CommonEventDefinition>, MetadataDefinitionSchema extends Partial<MessageMetadataType> = Partial<MessageMetadataType>> = { | ||
handleEvent(event: EventDefinitionSchema, metadata?: MetadataDefinitionSchema): void | Promise<void>; | ||
}; | ||
export type AnyEventHandler<EventDefinitions extends CommonEventDefinition[]> = EventHandler<CommonEventDefinitionConsumerSchemaType<EventDefinitions[number]>>; | ||
export type SingleEventHandler<EventDefinition extends CommonEventDefinition[], EventTypeName extends EventTypeNames<EventDefinition[number]>> = EventHandler<EventFromArrayByTypeName<EventDefinition, EventTypeName>>; | ||
type EventFromArrayByTypeName<EventDefinition extends CommonEventDefinition[], EventTypeName extends EventTypeNames<EventDefinition[number]>> = Extract<CommonEventDefinitionConsumerSchemaType<EventDefinition[number]>, { | ||
type: EventTypeName; | ||
}>; | ||
export {}; | ||
export { EventTypeNames, CommonEventDefinition, CommonEventDefinitionConsumerSchemaType, CommonEventDefinitionPublisherSchemaType, EventHandler, AnyEventHandler, SingleEventHandler, } from '@message-queue-toolkit/schemas'; |
@@ -1,114 +0,1 @@ | ||
import z, { type ZodLiteral, type ZodObject, type ZodOptional, type ZodString } from 'zod'; | ||
import type { ZodRawShape } from 'zod/lib/types'; | ||
import type { CommonEventDefinition } from '../events/eventTypes'; | ||
export declare const MESSAGE_METADATA_SCHEMA: z.ZodObject<{ | ||
schemaVersion: z.ZodString; | ||
producedBy: z.ZodString; | ||
originatedFrom: z.ZodString; | ||
correlationId: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
schemaVersion: string; | ||
producedBy: string; | ||
originatedFrom: string; | ||
correlationId: string; | ||
}, { | ||
schemaVersion: string; | ||
producedBy: string; | ||
originatedFrom: string; | ||
correlationId: string; | ||
}>; | ||
export declare const MESSAGE_SCHEMA_EXTENSION: { | ||
metadata: z.ZodOptional<z.ZodObject<{ | ||
schemaVersion: z.ZodString; | ||
producedBy: z.ZodString; | ||
originatedFrom: z.ZodString; | ||
correlationId: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
schemaVersion: string; | ||
producedBy: string; | ||
originatedFrom: string; | ||
correlationId: string; | ||
}, { | ||
schemaVersion: string; | ||
producedBy: string; | ||
originatedFrom: string; | ||
correlationId: string; | ||
}>>; | ||
}; | ||
export declare const BASE_MESSAGE_SCHEMA: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{ | ||
id: z.ZodString; | ||
timestamp: z.ZodString; | ||
}, { | ||
type: z.ZodLiteral<string>; | ||
payload: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>; | ||
}>, { | ||
metadata: z.ZodOptional<z.ZodObject<{ | ||
schemaVersion: z.ZodString; | ||
producedBy: z.ZodString; | ||
originatedFrom: z.ZodString; | ||
correlationId: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
schemaVersion: string; | ||
producedBy: string; | ||
originatedFrom: string; | ||
correlationId: string; | ||
}, { | ||
schemaVersion: string; | ||
producedBy: string; | ||
originatedFrom: string; | ||
correlationId: string; | ||
}>>; | ||
}>, "strip", z.ZodTypeAny, { | ||
id: string; | ||
timestamp: string; | ||
type: string; | ||
payload?: {} | undefined; | ||
metadata?: { | ||
schemaVersion: string; | ||
producedBy: string; | ||
originatedFrom: string; | ||
correlationId: string; | ||
} | undefined; | ||
}, { | ||
id: string; | ||
timestamp: string; | ||
type: string; | ||
payload?: {} | undefined; | ||
metadata?: { | ||
schemaVersion: string; | ||
producedBy: string; | ||
originatedFrom: string; | ||
correlationId: string; | ||
} | undefined; | ||
}>; | ||
export type BaseMessageType = z.infer<typeof BASE_MESSAGE_SCHEMA>; | ||
export type MessageMetadataType = z.infer<typeof MESSAGE_METADATA_SCHEMA>; | ||
export type CommonMessageDefinitionSchemaType<T extends CommonEventDefinition> = z.infer<T['consumerSchema']>; | ||
type ReturnType<T extends ZodObject<Y>, Y extends ZodRawShape, Z extends string> = { | ||
consumerSchema: ZodObject<{ | ||
id: ZodString; | ||
timestamp: ZodString; | ||
type: ZodLiteral<Z>; | ||
payload: T; | ||
metadata: ZodOptional<ZodObject<{ | ||
schemaVersion: ZodString; | ||
producedBy: ZodString; | ||
originatedFrom: ZodString; | ||
correlationId: ZodString; | ||
}>>; | ||
}>; | ||
publisherSchema: ZodObject<{ | ||
id: ZodOptional<ZodString>; | ||
timestamp: ZodOptional<ZodString>; | ||
type: ZodLiteral<Z>; | ||
payload: T; | ||
metadata: ZodOptional<ZodObject<{ | ||
schemaVersion: ZodString; | ||
producedBy: ZodString; | ||
originatedFrom: ZodString; | ||
correlationId: ZodString; | ||
}>>; | ||
}>; | ||
}; | ||
export declare function enrichMessageSchemaWithBase<T extends ZodObject<Y>, Y extends ZodRawShape, Z extends string>(type: Z, payloadSchema: T): ReturnType<T, Y, Z>; | ||
export {}; | ||
export { MESSAGE_METADATA_SCHEMA, MESSAGE_SCHEMA_EXTENSION, BASE_MESSAGE_SCHEMA, BaseMessageType, MessageMetadataType, CommonMessageDefinitionSchemaType, enrichMessageSchemaWithBase, } from '@message-queue-toolkit/schemas'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.enrichMessageSchemaWithBase = exports.BASE_MESSAGE_SCHEMA = exports.MESSAGE_SCHEMA_EXTENSION = exports.MESSAGE_METADATA_SCHEMA = void 0; | ||
const tslib_1 = require("tslib"); | ||
const zod_1 = tslib_1.__importDefault(require("zod")); | ||
const baseEventSchemas_1 = require("../events/baseEventSchemas"); | ||
// External message metadata that describe the context in which the message was created, primarily used for debugging purposes | ||
exports.MESSAGE_METADATA_SCHEMA = zod_1.default | ||
.object({ | ||
schemaVersion: zod_1.default.string().min(1).describe('message schema version'), | ||
// this is always set to a service that created the message | ||
producedBy: zod_1.default.string().min(1).describe('app/service that produced the message'), | ||
// this is always propagated within the message chain. For the first message in the chain it is equal to "producedBy" | ||
originatedFrom: zod_1.default | ||
.string() | ||
.min(1) | ||
.describe('app/service that initiated entire workflow that led to creating this message'), | ||
// this is always propagated within the message chain. | ||
correlationId: zod_1.default.string().describe('unique identifier passed to all events in workflow chain'), | ||
}) | ||
.describe('external message metadata'); | ||
exports.MESSAGE_SCHEMA_EXTENSION = { | ||
// For internal domain events that did not originate within a message chain metadata field can be omitted, producer should then assume it is initiating a new chain | ||
metadata: exports.MESSAGE_METADATA_SCHEMA.optional(), | ||
}; | ||
exports.BASE_MESSAGE_SCHEMA = baseEventSchemas_1.CONSUMER_BASE_EVENT_SCHEMA.extend(exports.MESSAGE_SCHEMA_EXTENSION); | ||
function enrichMessageSchemaWithBase(type, payloadSchema) { | ||
const baseSchema = zod_1.default.object({ | ||
type: zod_1.default.literal(type), | ||
payload: payloadSchema, | ||
}); | ||
const consumerSchema = baseEventSchemas_1.GENERATED_BASE_EVENT_SCHEMA.merge(baseSchema).extend(exports.MESSAGE_SCHEMA_EXTENSION); | ||
const publisherSchema = baseEventSchemas_1.OPTIONAL_GENERATED_BASE_EVENT_SCHEMA.merge(baseSchema).extend(exports.MESSAGE_SCHEMA_EXTENSION); | ||
return { | ||
consumerSchema: consumerSchema, | ||
publisherSchema: publisherSchema, | ||
}; | ||
} | ||
exports.enrichMessageSchemaWithBase = enrichMessageSchemaWithBase; | ||
var schemas_1 = require("@message-queue-toolkit/schemas"); | ||
Object.defineProperty(exports, "MESSAGE_METADATA_SCHEMA", { enumerable: true, get: function () { return schemas_1.MESSAGE_METADATA_SCHEMA; } }); | ||
Object.defineProperty(exports, "MESSAGE_SCHEMA_EXTENSION", { enumerable: true, get: function () { return schemas_1.MESSAGE_SCHEMA_EXTENSION; } }); | ||
Object.defineProperty(exports, "BASE_MESSAGE_SCHEMA", { enumerable: true, get: function () { return schemas_1.BASE_MESSAGE_SCHEMA; } }); | ||
Object.defineProperty(exports, "enrichMessageSchemaWithBase", { enumerable: true, get: function () { return schemas_1.enrichMessageSchemaWithBase; } }); | ||
//# sourceMappingURL=baseMessageSchemas.js.map |
@@ -1,1 +0,1 @@ | ||
export declare const toDatePreprocessor: (value: unknown) => unknown; | ||
export { toDatePreprocessor } from '@message-queue-toolkit/schemas'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toDatePreprocessor = void 0; | ||
const toDatePreprocessor = (value) => { | ||
switch (typeof value) { | ||
case 'string': | ||
case 'number': | ||
return new Date(value); | ||
default: | ||
return value; // could not coerce, return the original and face the consequences during validation | ||
} | ||
}; | ||
exports.toDatePreprocessor = toDatePreprocessor; | ||
var schemas_1 = require("@message-queue-toolkit/schemas"); | ||
Object.defineProperty(exports, "toDatePreprocessor", { enumerable: true, get: function () { return schemas_1.toDatePreprocessor; } }); | ||
//# sourceMappingURL=toDateProcessor.js.map |
{ | ||
"name": "@message-queue-toolkit/core", | ||
"version": "13.2.0", | ||
"version": "13.3.0", | ||
"private": false, | ||
@@ -29,2 +29,3 @@ "license": "MIT", | ||
"@lokalise/node-core": "^9.17.0", | ||
"@message-queue-toolkit/schemas": "^1.0.0", | ||
"fast-equals": "^5.0.1", | ||
@@ -31,0 +32,0 @@ "toad-cache": "^3.7.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96329
5
1346
+ Added@message-queue-toolkit/schemas@1.3.0(transitive)