@livetronics/wocul-domain 1.2.0 → 1.3.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/events/message.d.ts +2 -2
- package/dist/events/types.d.ts +8 -0
- package/dist/intents.d.ts +99 -4
- package/dist/intents.js +16 -2
- package/package.json +1 -1
package/dist/events/message.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { RealtimeEventType } from './types';
|
|
2
|
+
import type { KnownFields, RealtimeEventType } from './types';
|
|
3
3
|
import type { EventData } from './data';
|
|
4
4
|
/**
|
|
5
5
|
* The frame a realtime subscriber receives. core-ts's relay and
|
|
@@ -103,7 +103,7 @@ export declare const frameSchema: z.ZodObject<{
|
|
|
103
103
|
export type Frame = z.infer<typeof frameSchema>;
|
|
104
104
|
/** A frame whose type this package knows, with its `data` typed. */
|
|
105
105
|
export type RealtimeMessage = {
|
|
106
|
-
[T in RealtimeEventType]: Omit<Frame
|
|
106
|
+
[T in RealtimeEventType]: Omit<KnownFields<Frame>, 'type' | 'data'> & {
|
|
107
107
|
type: T;
|
|
108
108
|
data: EventData<T>;
|
|
109
109
|
};
|
package/dist/events/types.d.ts
CHANGED
|
@@ -25,3 +25,11 @@ export type ActorType = (typeof ACTOR_TYPES)[number];
|
|
|
25
25
|
export declare const isDomainEventType: (value: unknown) => value is DomainEventType;
|
|
26
26
|
export declare const isRealtimeEventType: (value: unknown) => value is RealtimeEventType;
|
|
27
27
|
export declare const isIntentType: (value: unknown) => value is IntentType;
|
|
28
|
+
/**
|
|
29
|
+
* A passthrough schema's type without its index signature. `Omit` over a
|
|
30
|
+
* type with one keeps only the signature, so every named field would read
|
|
31
|
+
* as `unknown`; strip it first.
|
|
32
|
+
*/
|
|
33
|
+
export type KnownFields<T> = {
|
|
34
|
+
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
|
|
35
|
+
};
|
package/dist/intents.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { DomainEventType, IntentType } from './events/types';
|
|
2
|
+
import type { DomainEventType, IntentType, KnownFields } from './events/types';
|
|
3
3
|
import type { EventData } from './events/data';
|
|
4
4
|
/**
|
|
5
5
|
* Intents: outbox rows core-ts's relay sends to one service's Redis stream
|
|
@@ -281,7 +281,7 @@ export declare const intentMessageSchema: z.ZodObject<{
|
|
|
281
281
|
export type IntentEnvelope = z.infer<typeof intentMessageSchema>;
|
|
282
282
|
/** An intent whose type this package knows, with its payload typed. */
|
|
283
283
|
export type IntentMessage = {
|
|
284
|
-
[T in IntentType]: Omit<IntentEnvelope
|
|
284
|
+
[T in IntentType]: Omit<KnownFields<IntentEnvelope>, 'type' | 'data'> & {
|
|
285
285
|
type: T;
|
|
286
286
|
data: IntentPayload<T>;
|
|
287
287
|
};
|
|
@@ -313,9 +313,104 @@ export declare function parseIntent(raw: unknown): IntentParseResult;
|
|
|
313
313
|
* Delivery is at-least-once: dedupe on `eventId`.
|
|
314
314
|
*/
|
|
315
315
|
export declare const DOMAIN_EVENT_STREAM = "wocul:events:domain";
|
|
316
|
+
/**
|
|
317
|
+
* A domain-stream entry: the intent envelope plus who made the change
|
|
318
|
+
* (`actor`, null for the system with nobody behind it) and the entity's
|
|
319
|
+
* `version`. Both are optional: entries written before core 4.5 lack them.
|
|
320
|
+
* The actor type is a string, so a newer type does not invalidate an entry.
|
|
321
|
+
*/
|
|
322
|
+
export declare const domainStreamEnvelopeSchema: z.ZodObject<{
|
|
323
|
+
eventId: z.ZodString;
|
|
324
|
+
type: z.ZodString;
|
|
325
|
+
idOrganisation: z.ZodNumber;
|
|
326
|
+
idProject: z.ZodNullable<z.ZodNumber>;
|
|
327
|
+
entity: z.ZodObject<{
|
|
328
|
+
type: z.ZodString;
|
|
329
|
+
id: z.ZodString;
|
|
330
|
+
}, "strip", z.ZodTypeAny, {
|
|
331
|
+
type: string;
|
|
332
|
+
id: string;
|
|
333
|
+
}, {
|
|
334
|
+
type: string;
|
|
335
|
+
id: string;
|
|
336
|
+
}>;
|
|
337
|
+
createdAt: z.ZodString;
|
|
338
|
+
data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
339
|
+
} & {
|
|
340
|
+
version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
341
|
+
actor: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
342
|
+
type: z.ZodString;
|
|
343
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
344
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
345
|
+
type: z.ZodString;
|
|
346
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
347
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
348
|
+
type: z.ZodString;
|
|
349
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
350
|
+
}, z.ZodTypeAny, "passthrough">>>>;
|
|
351
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
352
|
+
eventId: z.ZodString;
|
|
353
|
+
type: z.ZodString;
|
|
354
|
+
idOrganisation: z.ZodNumber;
|
|
355
|
+
idProject: z.ZodNullable<z.ZodNumber>;
|
|
356
|
+
entity: z.ZodObject<{
|
|
357
|
+
type: z.ZodString;
|
|
358
|
+
id: z.ZodString;
|
|
359
|
+
}, "strip", z.ZodTypeAny, {
|
|
360
|
+
type: string;
|
|
361
|
+
id: string;
|
|
362
|
+
}, {
|
|
363
|
+
type: string;
|
|
364
|
+
id: string;
|
|
365
|
+
}>;
|
|
366
|
+
createdAt: z.ZodString;
|
|
367
|
+
data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
368
|
+
} & {
|
|
369
|
+
version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
370
|
+
actor: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
371
|
+
type: z.ZodString;
|
|
372
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
373
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
374
|
+
type: z.ZodString;
|
|
375
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
376
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
377
|
+
type: z.ZodString;
|
|
378
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
379
|
+
}, z.ZodTypeAny, "passthrough">>>>;
|
|
380
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
381
|
+
eventId: z.ZodString;
|
|
382
|
+
type: z.ZodString;
|
|
383
|
+
idOrganisation: z.ZodNumber;
|
|
384
|
+
idProject: z.ZodNullable<z.ZodNumber>;
|
|
385
|
+
entity: z.ZodObject<{
|
|
386
|
+
type: z.ZodString;
|
|
387
|
+
id: z.ZodString;
|
|
388
|
+
}, "strip", z.ZodTypeAny, {
|
|
389
|
+
type: string;
|
|
390
|
+
id: string;
|
|
391
|
+
}, {
|
|
392
|
+
type: string;
|
|
393
|
+
id: string;
|
|
394
|
+
}>;
|
|
395
|
+
createdAt: z.ZodString;
|
|
396
|
+
data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
397
|
+
} & {
|
|
398
|
+
version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
399
|
+
actor: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
400
|
+
type: z.ZodString;
|
|
401
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
402
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
403
|
+
type: z.ZodString;
|
|
404
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
405
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
406
|
+
type: z.ZodString;
|
|
407
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
408
|
+
}, z.ZodTypeAny, "passthrough">>>>;
|
|
409
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
410
|
+
export type DomainStreamEnvelope = z.infer<typeof domainStreamEnvelopeSchema>;
|
|
316
411
|
/** A domain-stream entry whose type this package knows, `data` typed. */
|
|
317
412
|
export type DomainStreamMessage = {
|
|
318
|
-
[T in DomainEventType]: Omit<
|
|
413
|
+
[T in DomainEventType]: Omit<KnownFields<DomainStreamEnvelope>, 'type' | 'data'> & {
|
|
319
414
|
type: T;
|
|
320
415
|
data: EventData<T>;
|
|
321
416
|
};
|
|
@@ -333,7 +428,7 @@ export type DomainStreamParseResult =
|
|
|
333
428
|
/** A well-formed entry of a type this version does not know. */
|
|
334
429
|
| {
|
|
335
430
|
kind: 'unknown';
|
|
336
|
-
message:
|
|
431
|
+
message: DomainStreamEnvelope;
|
|
337
432
|
} | {
|
|
338
433
|
kind: 'invalid';
|
|
339
434
|
error: string;
|
package/dist/intents.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DOMAIN_EVENT_STREAM = exports.intentMessageSchema = exports.intentPayloadSchemas = exports.INTENT_FIELD = exports.INTENT_STREAM_OF = exports.INTENT_STREAMS = void 0;
|
|
3
|
+
exports.domainStreamEnvelopeSchema = exports.DOMAIN_EVENT_STREAM = exports.intentMessageSchema = exports.intentPayloadSchemas = exports.INTENT_FIELD = exports.INTENT_STREAM_OF = exports.INTENT_STREAMS = void 0;
|
|
4
4
|
exports.parseIntent = parseIntent;
|
|
5
5
|
exports.parseDomainStreamEntry = parseDomainStreamEntry;
|
|
6
6
|
const zod_1 = require("zod");
|
|
@@ -158,12 +158,26 @@ function parseIntent(raw) {
|
|
|
158
158
|
* Delivery is at-least-once: dedupe on `eventId`.
|
|
159
159
|
*/
|
|
160
160
|
exports.DOMAIN_EVENT_STREAM = 'wocul:events:domain';
|
|
161
|
+
/**
|
|
162
|
+
* A domain-stream entry: the intent envelope plus who made the change
|
|
163
|
+
* (`actor`, null for the system with nobody behind it) and the entity's
|
|
164
|
+
* `version`. Both are optional: entries written before core 4.5 lack them.
|
|
165
|
+
* The actor type is a string, so a newer type does not invalidate an entry.
|
|
166
|
+
*/
|
|
167
|
+
exports.domainStreamEnvelopeSchema = exports.intentMessageSchema.extend({
|
|
168
|
+
version: zod_1.z.number().int().nullable().optional(),
|
|
169
|
+
actor: zod_1.z
|
|
170
|
+
.object({ type: zod_1.z.string(), idStaff: zod_1.z.number().int().nullable() })
|
|
171
|
+
.passthrough()
|
|
172
|
+
.nullable()
|
|
173
|
+
.optional()
|
|
174
|
+
});
|
|
161
175
|
/**
|
|
162
176
|
* Validates one domain-stream entry: pass `JSON.parse(entry[INTENT_FIELD])`.
|
|
163
177
|
* Never throws. Unknown fields, facts included, pass through.
|
|
164
178
|
*/
|
|
165
179
|
function parseDomainStreamEntry(raw) {
|
|
166
|
-
const envelope = exports.
|
|
180
|
+
const envelope = exports.domainStreamEnvelopeSchema.safeParse(raw);
|
|
167
181
|
if (!envelope.success) {
|
|
168
182
|
const issue = envelope.error.issues[0];
|
|
169
183
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livetronics/wocul-domain",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Shared Wocul domain contracts: realtime event and intent schemas, channel names, and Core API types generated from the OpenAPI spec",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|