@zodmire/config 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/mod.d.mts +317 -0
  3. package/mod.mjs +126 -0
  4. package/package.json +18 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Vercel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/mod.d.mts ADDED
@@ -0,0 +1,317 @@
1
+ import { z } from "zod";
2
+
3
+ //#region packages/config/codegen_meta.d.ts
4
+ type CommandEffect = {
5
+ kind: "set-field" | "raise-event" | "increment" | "decrement" | "push-to-collection";
6
+ target: string;
7
+ value?: string;
8
+ };
9
+ type InvariantRule = {
10
+ name: string;
11
+ rule: string;
12
+ errorType: string;
13
+ errorMessage: string;
14
+ };
15
+ type AggregateMeta = {
16
+ kind: "aggregate";
17
+ tableName: string;
18
+ idField: string;
19
+ idType?: string;
20
+ invariants?: InvariantRule[];
21
+ };
22
+ type EntityMeta = {
23
+ kind: "entity";
24
+ tableName?: string;
25
+ idField: string;
26
+ idType?: string;
27
+ };
28
+ type ValueObjectMeta = {
29
+ kind: "value-object";
30
+ };
31
+ type CommandInputMeta = {
32
+ kind: "command-input";
33
+ commandName: string;
34
+ targetAggregate: string;
35
+ commandKind: "create" | "update";
36
+ lifecycle?: "create" | "mutate";
37
+ loadBy?: string;
38
+ preconditions?: string[];
39
+ emits?: string[];
40
+ effects?: CommandEffect[];
41
+ };
42
+ type FilterOperator = "eq" | "in" | "gt" | "gte" | "lt" | "lte" | "contains" | "startsWith";
43
+ type ComputedFieldSpec = {
44
+ kind: "builtin";
45
+ source: "children";
46
+ collection: string;
47
+ fn: "count" | "exists";
48
+ } | {
49
+ kind: "builtin";
50
+ source: "children";
51
+ collection: string;
52
+ field: string;
53
+ fn: "sum" | "min" | "max";
54
+ } | {
55
+ kind: "custom";
56
+ };
57
+ type FindByIdQueryInputMeta = {
58
+ kind: "query-input";
59
+ queryKind: "findById";
60
+ queryName: string;
61
+ targetAggregate: string;
62
+ readSide: {
63
+ readModelName: string;
64
+ };
65
+ };
66
+ type ListQueryInputMeta = {
67
+ kind: "query-input";
68
+ queryKind: "list";
69
+ queryName: string;
70
+ targetAggregate: string;
71
+ readSide: {
72
+ readModelName: string;
73
+ searchFields?: string[];
74
+ };
75
+ pagination: {
76
+ style: "offset";
77
+ } | {
78
+ style: "cursor";
79
+ };
80
+ filters: Record<string, FilterOperator[]>;
81
+ sorting: {
82
+ sortableFields: string[];
83
+ defaultSort: {
84
+ field: string;
85
+ direction: "asc" | "desc";
86
+ };
87
+ };
88
+ };
89
+ type QueryInputMeta = FindByIdQueryInputMeta | ListQueryInputMeta;
90
+ type QueryOutputMeta = {
91
+ kind: "query-output";
92
+ queryName: string;
93
+ };
94
+ type ReadModelIndexMeta = {
95
+ name: string;
96
+ fields: string[];
97
+ };
98
+ type ReadModelUniqueConstraintMeta = {
99
+ name: string;
100
+ fields: string[];
101
+ };
102
+ type ReadModelMeta = {
103
+ kind: "read-model";
104
+ readModelName: string;
105
+ ownerContext: string;
106
+ ownerAggregate: string;
107
+ tableName: string;
108
+ primaryKey: string[];
109
+ indexes?: ReadModelIndexMeta[];
110
+ uniqueConstraints?: ReadModelUniqueConstraintMeta[];
111
+ servesQueries?: string[];
112
+ };
113
+ type ProjectionValueSourceMeta = {
114
+ kind: "event-field";
115
+ field: string;
116
+ } | {
117
+ kind: "literal";
118
+ value: string | number | boolean | null;
119
+ } | {
120
+ kind: "expression";
121
+ expression: string;
122
+ };
123
+ type ProjectionMutationMeta = {
124
+ kind: "upsert";
125
+ matchOn: string[];
126
+ set?: Record<string, ProjectionValueSourceMeta>;
127
+ } | {
128
+ kind: "delete";
129
+ matchOn: string[];
130
+ } | {
131
+ kind: "custom";
132
+ handlerName: string;
133
+ };
134
+ type ProjectionSourceMeta = {
135
+ role: "primary" | "enrichment";
136
+ contextName: string;
137
+ aggregateName: string;
138
+ eventName: string;
139
+ mutation: ProjectionMutationMeta;
140
+ };
141
+ type ProjectionRebuildMeta = {
142
+ enabled: false;
143
+ } | {
144
+ enabled: true;
145
+ strategy: "full-replay";
146
+ batchSize?: number;
147
+ };
148
+ type ProjectionSubscriptionMeta = {
149
+ subscriptionName?: string;
150
+ consumerGroup?: string;
151
+ };
152
+ type ProjectionMeta = {
153
+ kind: "projection";
154
+ projectionName: string;
155
+ readModelName: string;
156
+ sources: ProjectionSourceMeta[];
157
+ rebuild?: ProjectionRebuildMeta;
158
+ subscription?: ProjectionSubscriptionMeta;
159
+ };
160
+ type DomainEventMeta = {
161
+ kind: "domain-event";
162
+ };
163
+ type FieldMeta = {
164
+ kind: "field";
165
+ columnType?: string;
166
+ indexed?: boolean;
167
+ };
168
+ type DomainErrorMeta = {
169
+ kind: "domain-error";
170
+ invariantName: string;
171
+ errorTypeName: string;
172
+ defaultMessage: string;
173
+ };
174
+ type ApplicationErrorMeta = {
175
+ kind: "application-error";
176
+ errorTypeName: string;
177
+ aggregateName: string;
178
+ };
179
+ type CodegenMeta = AggregateMeta | EntityMeta | ValueObjectMeta | CommandInputMeta | QueryInputMeta | QueryOutputMeta | ReadModelMeta | ProjectionMeta | DomainEventMeta | FieldMeta | DomainErrorMeta | ApplicationErrorMeta;
180
+ /**
181
+ * Creates a Zod v4 registry typed to CodegenMeta.
182
+ * Attach metadata to any schema with `schema.register(registry, meta)`.
183
+ * Retrieve with `registry.get(schema)`.
184
+ */
185
+ declare function createCodegenRegistry(): ReturnType<typeof z.registry<CodegenMeta>>;
186
+ /**
187
+ * Identity factory for CodegenMeta — validates the shape at the type level
188
+ * and returns it unchanged. Useful in tests and schema annotations.
189
+ */
190
+ declare function createCodegenMeta<T extends CodegenMeta>(meta: T): T;
191
+ //#endregion
192
+ //#region packages/config/context_config.d.ts
193
+ declare const ContextConfigSchema: z.ZodObject<{
194
+ name: z.ZodString;
195
+ modulePath: z.ZodString;
196
+ schemaFiles: z.ZodArray<z.ZodString>;
197
+ ports: z.ZodArray<z.ZodObject<{
198
+ name: z.ZodString;
199
+ kind: z.ZodEnum<{
200
+ repository: "repository";
201
+ service: "service";
202
+ acl: "acl";
203
+ }>;
204
+ target: z.ZodOptional<z.ZodString>;
205
+ }, z.core.$strict>>;
206
+ adapters: z.ZodArray<z.ZodObject<{
207
+ name: z.ZodString;
208
+ port: z.ZodString;
209
+ kind: z.ZodEnum<{
210
+ "drizzle-repository": "drizzle-repository";
211
+ "external-service": "external-service";
212
+ }>;
213
+ }, z.core.$strict>>;
214
+ acls: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
215
+ name: z.ZodString;
216
+ port: z.ZodString;
217
+ kind: z.ZodLiteral<"read">;
218
+ source: z.ZodObject<{
219
+ context: z.ZodString;
220
+ query: z.ZodString;
221
+ }, z.core.$strict>;
222
+ request: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
223
+ from: z.ZodString;
224
+ }, z.core.$strict>, z.ZodObject<{
225
+ const: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
226
+ }, z.core.$strict>]>>;
227
+ response: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
228
+ from: z.ZodString;
229
+ }, z.core.$strict>, z.ZodObject<{
230
+ const: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
231
+ }, z.core.$strict>]>>;
232
+ }, z.core.$strict>, z.ZodObject<{
233
+ name: z.ZodString;
234
+ port: z.ZodString;
235
+ kind: z.ZodLiteral<"write">;
236
+ target: z.ZodObject<{
237
+ context: z.ZodString;
238
+ command: z.ZodString;
239
+ }, z.core.$strict>;
240
+ request: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
241
+ from: z.ZodString;
242
+ }, z.core.$strict>, z.ZodObject<{
243
+ const: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
244
+ }, z.core.$strict>]>>;
245
+ response: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
246
+ from: z.ZodString;
247
+ }, z.core.$strict>, z.ZodObject<{
248
+ const: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
249
+ }, z.core.$strict>]>>;
250
+ }, z.core.$strict>, z.ZodObject<{
251
+ name: z.ZodString;
252
+ port: z.ZodString;
253
+ kind: z.ZodLiteral<"ack">;
254
+ target: z.ZodObject<{
255
+ context: z.ZodString;
256
+ command: z.ZodString;
257
+ }, z.core.$strict>;
258
+ request: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
259
+ from: z.ZodString;
260
+ }, z.core.$strict>, z.ZodObject<{
261
+ const: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
262
+ }, z.core.$strict>]>>;
263
+ }, z.core.$strict>], "kind">>>;
264
+ presentation: z.ZodObject<{
265
+ trpcRouter: z.ZodString;
266
+ procedures: z.ZodArray<z.ZodObject<{
267
+ name: z.ZodString;
268
+ kind: z.ZodEnum<{
269
+ query: "query";
270
+ command: "command";
271
+ }>;
272
+ operation: z.ZodString;
273
+ }, z.core.$strict>>;
274
+ }, z.core.$strict>;
275
+ materialization: z.ZodObject<{
276
+ targetRoot: z.ZodString;
277
+ }, z.core.$strict>;
278
+ }, z.core.$strict>;
279
+ type ContextConfig = z.output<typeof ContextConfigSchema>;
280
+ declare function defineContext(config: unknown): ContextConfig;
281
+ //#endregion
282
+ //#region packages/config/composition_config.d.ts
283
+ declare const SubscriptionSchema: z.ZodObject<{
284
+ targetContext: z.ZodString;
285
+ action: z.ZodString;
286
+ }, z.core.$strip>;
287
+ declare const CrossContextEventSchema: z.ZodObject<{
288
+ eventType: z.ZodString;
289
+ sourceContext: z.ZodString;
290
+ payloadSchema: z.ZodAny;
291
+ subscriptions: z.ZodArray<z.ZodObject<{
292
+ targetContext: z.ZodString;
293
+ action: z.ZodString;
294
+ }, z.core.$strip>>;
295
+ }, z.core.$strip>;
296
+ declare const CompositionConfigSchema: z.ZodObject<{
297
+ name: z.ZodString;
298
+ contexts: z.ZodArray<z.ZodString>;
299
+ crossContextEvents: z.ZodDefault<z.ZodArray<z.ZodObject<{
300
+ eventType: z.ZodString;
301
+ sourceContext: z.ZodString;
302
+ payloadSchema: z.ZodAny;
303
+ subscriptions: z.ZodArray<z.ZodObject<{
304
+ targetContext: z.ZodString;
305
+ action: z.ZodString;
306
+ }, z.core.$strip>>;
307
+ }, z.core.$strip>>>;
308
+ materialization: z.ZodObject<{
309
+ targetRoot: z.ZodString;
310
+ }, z.core.$strip>;
311
+ }, z.core.$strip>;
312
+ type CompositionConfig = z.infer<typeof CompositionConfigSchema>;
313
+ type CrossContextEvent = z.infer<typeof CrossContextEventSchema>;
314
+ type Subscription = z.infer<typeof SubscriptionSchema>;
315
+ declare function defineComposition(config: z.input<typeof CompositionConfigSchema>): CompositionConfig;
316
+ //#endregion
317
+ export { AggregateMeta, ApplicationErrorMeta, CodegenMeta, CommandEffect, CommandInputMeta, CompositionConfig, CompositionConfigSchema, ComputedFieldSpec, ContextConfig, ContextConfigSchema, CrossContextEvent, DomainErrorMeta, DomainEventMeta, EntityMeta, FieldMeta, FilterOperator, FindByIdQueryInputMeta, InvariantRule, ListQueryInputMeta, ProjectionMeta, ProjectionMutationMeta, ProjectionRebuildMeta, ProjectionSourceMeta, ProjectionSubscriptionMeta, ProjectionValueSourceMeta, QueryInputMeta, QueryOutputMeta, ReadModelIndexMeta, ReadModelMeta, ReadModelUniqueConstraintMeta, Subscription, ValueObjectMeta, createCodegenMeta, createCodegenRegistry, defineComposition, defineContext };
package/mod.mjs ADDED
@@ -0,0 +1,126 @@
1
+ import { z } from "zod";
2
+
3
+ //#region packages/config/codegen_meta.ts
4
+ /**
5
+ * Creates a Zod v4 registry typed to CodegenMeta.
6
+ * Attach metadata to any schema with `schema.register(registry, meta)`.
7
+ * Retrieve with `registry.get(schema)`.
8
+ */
9
+ function createCodegenRegistry() {
10
+ return z.registry();
11
+ }
12
+ /**
13
+ * Identity factory for CodegenMeta — validates the shape at the type level
14
+ * and returns it unchanged. Useful in tests and schema annotations.
15
+ */
16
+ function createCodegenMeta(meta) {
17
+ return meta;
18
+ }
19
+
20
+ //#endregion
21
+ //#region packages/config/context_config.ts
22
+ const MappingExprSchema = z.union([z.strictObject({ from: z.string().min(1) }), z.strictObject({ const: z.union([
23
+ z.string(),
24
+ z.number(),
25
+ z.boolean(),
26
+ z.null()
27
+ ]) })]);
28
+ const AclSourceSchema = z.strictObject({
29
+ context: z.string().min(1),
30
+ query: z.string().min(1)
31
+ });
32
+ const AclTargetSchema = z.strictObject({
33
+ context: z.string().min(1),
34
+ command: z.string().min(1)
35
+ });
36
+ const ReadAclSchema = z.strictObject({
37
+ name: z.string().min(1),
38
+ port: z.string().min(1),
39
+ kind: z.literal("read"),
40
+ source: AclSourceSchema,
41
+ request: z.record(z.string(), MappingExprSchema),
42
+ response: z.record(z.string(), MappingExprSchema)
43
+ });
44
+ const WriteAclSchema = z.strictObject({
45
+ name: z.string().min(1),
46
+ port: z.string().min(1),
47
+ kind: z.literal("write"),
48
+ target: AclTargetSchema,
49
+ request: z.record(z.string(), MappingExprSchema),
50
+ response: z.record(z.string(), MappingExprSchema)
51
+ });
52
+ const AckSchema = z.strictObject({
53
+ name: z.string().min(1),
54
+ port: z.string().min(1),
55
+ kind: z.literal("ack"),
56
+ target: AclTargetSchema,
57
+ request: z.record(z.string(), MappingExprSchema)
58
+ });
59
+ const PortSchema = z.strictObject({
60
+ name: z.string().min(1),
61
+ kind: z.enum([
62
+ "repository",
63
+ "service",
64
+ "acl"
65
+ ]),
66
+ target: z.string().min(1).optional()
67
+ });
68
+ const AdapterSchema = z.strictObject({
69
+ name: z.string().min(1),
70
+ port: z.string().min(1),
71
+ kind: z.enum(["drizzle-repository", "external-service"])
72
+ });
73
+ const ProcedureSchema = z.strictObject({
74
+ name: z.string().min(1),
75
+ kind: z.enum(["command", "query"]),
76
+ operation: z.string().min(1)
77
+ });
78
+ const PresentationSchema = z.strictObject({
79
+ trpcRouter: z.string().min(1),
80
+ procedures: z.array(ProcedureSchema)
81
+ });
82
+ const MaterializationSchema = z.strictObject({ targetRoot: z.string().min(1) });
83
+ const AclSchema = z.discriminatedUnion("kind", [
84
+ ReadAclSchema,
85
+ WriteAclSchema,
86
+ AckSchema
87
+ ]);
88
+ const ContextConfigSchema = z.strictObject({
89
+ name: z.string().min(1),
90
+ modulePath: z.string().min(1),
91
+ schemaFiles: z.array(z.string().min(1)).min(1),
92
+ ports: z.array(PortSchema),
93
+ adapters: z.array(AdapterSchema),
94
+ acls: z.array(AclSchema).default([]),
95
+ presentation: PresentationSchema,
96
+ materialization: MaterializationSchema
97
+ });
98
+ function defineContext(config) {
99
+ return ContextConfigSchema.parse(config);
100
+ }
101
+
102
+ //#endregion
103
+ //#region packages/config/composition_config.ts
104
+ const SubscriptionSchema = z.object({
105
+ targetContext: z.string().min(1),
106
+ action: z.string().min(1)
107
+ });
108
+ const CrossContextEventSchema = z.object({
109
+ eventType: z.string().regex(/^[A-Z][a-zA-Z]+\.[A-Z][a-zA-Z]+$/),
110
+ sourceContext: z.string().min(1),
111
+ payloadSchema: z.any(),
112
+ subscriptions: z.array(SubscriptionSchema).min(1)
113
+ });
114
+ const CompositionMaterializationSchema = z.object({ targetRoot: z.string().min(1) });
115
+ const CompositionConfigSchema = z.object({
116
+ name: z.string().min(1),
117
+ contexts: z.array(z.string().min(1)).min(1),
118
+ crossContextEvents: z.array(CrossContextEventSchema).default([]),
119
+ materialization: CompositionMaterializationSchema
120
+ });
121
+ function defineComposition(config) {
122
+ return CompositionConfigSchema.parse(config);
123
+ }
124
+
125
+ //#endregion
126
+ export { CompositionConfigSchema, ContextConfigSchema, createCodegenMeta, createCodegenRegistry, defineComposition, defineContext };
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@zodmire/config",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "./mod.mjs",
7
+ "module": "./mod.mjs",
8
+ "types": "./mod.d.mts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./mod.d.mts",
12
+ "import": "./mod.mjs"
13
+ }
14
+ },
15
+ "dependencies": {
16
+ "zod": "^4.3.6"
17
+ }
18
+ }