@treeseed/sdk 0.13.0-rc.100 → 0.13.0-rc.102

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.
@@ -0,0 +1,418 @@
1
+ import { z } from 'zod';
2
+ /** Package-owned requirements, not an instruction to start another server. */
3
+ export declare const postgresRequirementSchema: z.ZodObject<{
4
+ id: z.ZodString;
5
+ componentId: z.ZodString;
6
+ enabled: z.ZodBoolean;
7
+ supportedMajors: z.ZodEffects<z.ZodArray<z.ZodNumber, "atleastone">, [number, ...number[]], [number, ...number[]]>;
8
+ extensions: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">, string[], string[]>;
9
+ runtimeConnectionLimit: z.ZodNumber;
10
+ }, "strict", z.ZodTypeAny, {
11
+ id: string;
12
+ componentId: string;
13
+ enabled: boolean;
14
+ supportedMajors: [number, ...number[]];
15
+ extensions: string[];
16
+ runtimeConnectionLimit: number;
17
+ }, {
18
+ id: string;
19
+ componentId: string;
20
+ enabled: boolean;
21
+ supportedMajors: [number, ...number[]];
22
+ extensions: string[];
23
+ runtimeConnectionLimit: number;
24
+ }>;
25
+ /** Immutable component requirement. Installation activation supplies componentId/enabled. */
26
+ export declare const postgresComponentRequirementSchema: z.ZodObject<Omit<{
27
+ id: z.ZodString;
28
+ componentId: z.ZodString;
29
+ enabled: z.ZodBoolean;
30
+ supportedMajors: z.ZodEffects<z.ZodArray<z.ZodNumber, "atleastone">, [number, ...number[]], [number, ...number[]]>;
31
+ extensions: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">, string[], string[]>;
32
+ runtimeConnectionLimit: z.ZodNumber;
33
+ }, "componentId" | "enabled">, "strict", z.ZodTypeAny, {
34
+ id: string;
35
+ supportedMajors: [number, ...number[]];
36
+ extensions: string[];
37
+ runtimeConnectionLimit: number;
38
+ }, {
39
+ id: string;
40
+ supportedMajors: [number, ...number[]];
41
+ extensions: string[];
42
+ runtimeConnectionLimit: number;
43
+ }>;
44
+ /** Deployment owns the selected server and its bootstrap authority. No credentials here. */
45
+ export declare const postgresServerSchema: z.ZodObject<{
46
+ id: z.ZodString;
47
+ installationId: z.ZodString;
48
+ environment: z.ZodEnum<["staging", "production"]>;
49
+ mode: z.ZodEnum<["shared", "dedicated", "external"]>;
50
+ hostname: z.ZodString;
51
+ port: z.ZodNumber;
52
+ major: z.ZodNumber;
53
+ extensions: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">, string[], string[]>;
54
+ tls: z.ZodObject<{
55
+ mode: z.ZodLiteral<"verify-full">;
56
+ trustReference: z.ZodString;
57
+ }, "strict", z.ZodTypeAny, {
58
+ mode: "verify-full";
59
+ trustReference: string;
60
+ }, {
61
+ mode: "verify-full";
62
+ trustReference: string;
63
+ }>;
64
+ }, "strict", z.ZodTypeAny, {
65
+ id: string;
66
+ mode: "shared" | "dedicated" | "external";
67
+ environment: "production" | "staging";
68
+ port: number;
69
+ major: number;
70
+ extensions: string[];
71
+ installationId: string;
72
+ hostname: string;
73
+ tls: {
74
+ mode: "verify-full";
75
+ trustReference: string;
76
+ };
77
+ }, {
78
+ id: string;
79
+ mode: "shared" | "dedicated" | "external";
80
+ environment: "production" | "staging";
81
+ port: number;
82
+ major: number;
83
+ extensions: string[];
84
+ installationId: string;
85
+ hostname: string;
86
+ tls: {
87
+ mode: "verify-full";
88
+ trustReference: string;
89
+ };
90
+ }>;
91
+ export declare const postgresAllocationSchema: z.ZodEffects<z.ZodObject<{
92
+ requirementId: z.ZodString;
93
+ serverId: z.ZodString;
94
+ database: z.ZodEffects<z.ZodString, string, string>;
95
+ ownerRole: z.ZodEffects<z.ZodString, string, string>;
96
+ migrationRole: z.ZodEffects<z.ZodString, string, string>;
97
+ runtimeRole: z.ZodEffects<z.ZodString, string, string>;
98
+ migrationCredentialReference: z.ZodString;
99
+ runtimeCredentialReference: z.ZodString;
100
+ onDisable: z.ZodLiteral<"preserve">;
101
+ }, "strict", z.ZodTypeAny, {
102
+ requirementId: string;
103
+ serverId: string;
104
+ database: string;
105
+ ownerRole: string;
106
+ migrationRole: string;
107
+ runtimeRole: string;
108
+ migrationCredentialReference: string;
109
+ runtimeCredentialReference: string;
110
+ onDisable: "preserve";
111
+ }, {
112
+ requirementId: string;
113
+ serverId: string;
114
+ database: string;
115
+ ownerRole: string;
116
+ migrationRole: string;
117
+ runtimeRole: string;
118
+ migrationCredentialReference: string;
119
+ runtimeCredentialReference: string;
120
+ onDisable: "preserve";
121
+ }>, {
122
+ requirementId: string;
123
+ serverId: string;
124
+ database: string;
125
+ ownerRole: string;
126
+ migrationRole: string;
127
+ runtimeRole: string;
128
+ migrationCredentialReference: string;
129
+ runtimeCredentialReference: string;
130
+ onDisable: "preserve";
131
+ }, {
132
+ requirementId: string;
133
+ serverId: string;
134
+ database: string;
135
+ ownerRole: string;
136
+ migrationRole: string;
137
+ runtimeRole: string;
138
+ migrationCredentialReference: string;
139
+ runtimeCredentialReference: string;
140
+ onDisable: "preserve";
141
+ }>;
142
+ /** One installation/environment. Explicit allocations may select dedicated servers. */
143
+ export declare const postgresTopologySchema: z.ZodEffects<z.ZodObject<{
144
+ schemaVersion: z.ZodLiteral<"treeseed.postgres-topology/v1">;
145
+ installationId: z.ZodString;
146
+ environment: z.ZodEnum<["staging", "production"]>;
147
+ servers: z.ZodArray<z.ZodObject<{
148
+ id: z.ZodString;
149
+ installationId: z.ZodString;
150
+ environment: z.ZodEnum<["staging", "production"]>;
151
+ mode: z.ZodEnum<["shared", "dedicated", "external"]>;
152
+ hostname: z.ZodString;
153
+ port: z.ZodNumber;
154
+ major: z.ZodNumber;
155
+ extensions: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">, string[], string[]>;
156
+ tls: z.ZodObject<{
157
+ mode: z.ZodLiteral<"verify-full">;
158
+ trustReference: z.ZodString;
159
+ }, "strict", z.ZodTypeAny, {
160
+ mode: "verify-full";
161
+ trustReference: string;
162
+ }, {
163
+ mode: "verify-full";
164
+ trustReference: string;
165
+ }>;
166
+ }, "strict", z.ZodTypeAny, {
167
+ id: string;
168
+ mode: "shared" | "dedicated" | "external";
169
+ environment: "production" | "staging";
170
+ port: number;
171
+ major: number;
172
+ extensions: string[];
173
+ installationId: string;
174
+ hostname: string;
175
+ tls: {
176
+ mode: "verify-full";
177
+ trustReference: string;
178
+ };
179
+ }, {
180
+ id: string;
181
+ mode: "shared" | "dedicated" | "external";
182
+ environment: "production" | "staging";
183
+ port: number;
184
+ major: number;
185
+ extensions: string[];
186
+ installationId: string;
187
+ hostname: string;
188
+ tls: {
189
+ mode: "verify-full";
190
+ trustReference: string;
191
+ };
192
+ }>, "many">;
193
+ requirements: z.ZodArray<z.ZodObject<{
194
+ id: z.ZodString;
195
+ componentId: z.ZodString;
196
+ enabled: z.ZodBoolean;
197
+ supportedMajors: z.ZodEffects<z.ZodArray<z.ZodNumber, "atleastone">, [number, ...number[]], [number, ...number[]]>;
198
+ extensions: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">, string[], string[]>;
199
+ runtimeConnectionLimit: z.ZodNumber;
200
+ }, "strict", z.ZodTypeAny, {
201
+ id: string;
202
+ componentId: string;
203
+ enabled: boolean;
204
+ supportedMajors: [number, ...number[]];
205
+ extensions: string[];
206
+ runtimeConnectionLimit: number;
207
+ }, {
208
+ id: string;
209
+ componentId: string;
210
+ enabled: boolean;
211
+ supportedMajors: [number, ...number[]];
212
+ extensions: string[];
213
+ runtimeConnectionLimit: number;
214
+ }>, "many">;
215
+ allocations: z.ZodArray<z.ZodEffects<z.ZodObject<{
216
+ requirementId: z.ZodString;
217
+ serverId: z.ZodString;
218
+ database: z.ZodEffects<z.ZodString, string, string>;
219
+ ownerRole: z.ZodEffects<z.ZodString, string, string>;
220
+ migrationRole: z.ZodEffects<z.ZodString, string, string>;
221
+ runtimeRole: z.ZodEffects<z.ZodString, string, string>;
222
+ migrationCredentialReference: z.ZodString;
223
+ runtimeCredentialReference: z.ZodString;
224
+ onDisable: z.ZodLiteral<"preserve">;
225
+ }, "strict", z.ZodTypeAny, {
226
+ requirementId: string;
227
+ serverId: string;
228
+ database: string;
229
+ ownerRole: string;
230
+ migrationRole: string;
231
+ runtimeRole: string;
232
+ migrationCredentialReference: string;
233
+ runtimeCredentialReference: string;
234
+ onDisable: "preserve";
235
+ }, {
236
+ requirementId: string;
237
+ serverId: string;
238
+ database: string;
239
+ ownerRole: string;
240
+ migrationRole: string;
241
+ runtimeRole: string;
242
+ migrationCredentialReference: string;
243
+ runtimeCredentialReference: string;
244
+ onDisable: "preserve";
245
+ }>, {
246
+ requirementId: string;
247
+ serverId: string;
248
+ database: string;
249
+ ownerRole: string;
250
+ migrationRole: string;
251
+ runtimeRole: string;
252
+ migrationCredentialReference: string;
253
+ runtimeCredentialReference: string;
254
+ onDisable: "preserve";
255
+ }, {
256
+ requirementId: string;
257
+ serverId: string;
258
+ database: string;
259
+ ownerRole: string;
260
+ migrationRole: string;
261
+ runtimeRole: string;
262
+ migrationCredentialReference: string;
263
+ runtimeCredentialReference: string;
264
+ onDisable: "preserve";
265
+ }>, "many">;
266
+ }, "strict", z.ZodTypeAny, {
267
+ schemaVersion: "treeseed.postgres-topology/v1";
268
+ environment: "production" | "staging";
269
+ installationId: string;
270
+ servers: {
271
+ id: string;
272
+ mode: "shared" | "dedicated" | "external";
273
+ environment: "production" | "staging";
274
+ port: number;
275
+ major: number;
276
+ extensions: string[];
277
+ installationId: string;
278
+ hostname: string;
279
+ tls: {
280
+ mode: "verify-full";
281
+ trustReference: string;
282
+ };
283
+ }[];
284
+ requirements: {
285
+ id: string;
286
+ componentId: string;
287
+ enabled: boolean;
288
+ supportedMajors: [number, ...number[]];
289
+ extensions: string[];
290
+ runtimeConnectionLimit: number;
291
+ }[];
292
+ allocations: {
293
+ requirementId: string;
294
+ serverId: string;
295
+ database: string;
296
+ ownerRole: string;
297
+ migrationRole: string;
298
+ runtimeRole: string;
299
+ migrationCredentialReference: string;
300
+ runtimeCredentialReference: string;
301
+ onDisable: "preserve";
302
+ }[];
303
+ }, {
304
+ schemaVersion: "treeseed.postgres-topology/v1";
305
+ environment: "production" | "staging";
306
+ installationId: string;
307
+ servers: {
308
+ id: string;
309
+ mode: "shared" | "dedicated" | "external";
310
+ environment: "production" | "staging";
311
+ port: number;
312
+ major: number;
313
+ extensions: string[];
314
+ installationId: string;
315
+ hostname: string;
316
+ tls: {
317
+ mode: "verify-full";
318
+ trustReference: string;
319
+ };
320
+ }[];
321
+ requirements: {
322
+ id: string;
323
+ componentId: string;
324
+ enabled: boolean;
325
+ supportedMajors: [number, ...number[]];
326
+ extensions: string[];
327
+ runtimeConnectionLimit: number;
328
+ }[];
329
+ allocations: {
330
+ requirementId: string;
331
+ serverId: string;
332
+ database: string;
333
+ ownerRole: string;
334
+ migrationRole: string;
335
+ runtimeRole: string;
336
+ migrationCredentialReference: string;
337
+ runtimeCredentialReference: string;
338
+ onDisable: "preserve";
339
+ }[];
340
+ }>, {
341
+ schemaVersion: "treeseed.postgres-topology/v1";
342
+ environment: "production" | "staging";
343
+ installationId: string;
344
+ servers: {
345
+ id: string;
346
+ mode: "shared" | "dedicated" | "external";
347
+ environment: "production" | "staging";
348
+ port: number;
349
+ major: number;
350
+ extensions: string[];
351
+ installationId: string;
352
+ hostname: string;
353
+ tls: {
354
+ mode: "verify-full";
355
+ trustReference: string;
356
+ };
357
+ }[];
358
+ requirements: {
359
+ id: string;
360
+ componentId: string;
361
+ enabled: boolean;
362
+ supportedMajors: [number, ...number[]];
363
+ extensions: string[];
364
+ runtimeConnectionLimit: number;
365
+ }[];
366
+ allocations: {
367
+ requirementId: string;
368
+ serverId: string;
369
+ database: string;
370
+ ownerRole: string;
371
+ migrationRole: string;
372
+ runtimeRole: string;
373
+ migrationCredentialReference: string;
374
+ runtimeCredentialReference: string;
375
+ onDisable: "preserve";
376
+ }[];
377
+ }, {
378
+ schemaVersion: "treeseed.postgres-topology/v1";
379
+ environment: "production" | "staging";
380
+ installationId: string;
381
+ servers: {
382
+ id: string;
383
+ mode: "shared" | "dedicated" | "external";
384
+ environment: "production" | "staging";
385
+ port: number;
386
+ major: number;
387
+ extensions: string[];
388
+ installationId: string;
389
+ hostname: string;
390
+ tls: {
391
+ mode: "verify-full";
392
+ trustReference: string;
393
+ };
394
+ }[];
395
+ requirements: {
396
+ id: string;
397
+ componentId: string;
398
+ enabled: boolean;
399
+ supportedMajors: [number, ...number[]];
400
+ extensions: string[];
401
+ runtimeConnectionLimit: number;
402
+ }[];
403
+ allocations: {
404
+ requirementId: string;
405
+ serverId: string;
406
+ database: string;
407
+ ownerRole: string;
408
+ migrationRole: string;
409
+ runtimeRole: string;
410
+ migrationCredentialReference: string;
411
+ runtimeCredentialReference: string;
412
+ onDisable: "preserve";
413
+ }[];
414
+ }>;
415
+ export type PostgresRequirement = z.infer<typeof postgresRequirementSchema>;
416
+ export type PostgresServer = z.infer<typeof postgresServerSchema>;
417
+ export type PostgresAllocation = z.infer<typeof postgresAllocationSchema>;
418
+ export type PostgresTopology = z.infer<typeof postgresTopologySchema>;
@@ -0,0 +1,79 @@
1
+ import { z } from "zod";
2
+ const id = z.string().regex(/^[a-z][a-z0-9-]{0,62}$/u);
3
+ const sqlName = z.string().regex(/^[a-z][a-z0-9_]{0,62}$/u).refine((value) => value !== "postgres" && !value.startsWith("pg_"), "Application identifiers must not use PostgreSQL administrative names.");
4
+ const unique = (values) => new Set(values).size === values.length;
5
+ const postgresRequirementSchema = z.object({
6
+ id,
7
+ componentId: id,
8
+ enabled: z.boolean(),
9
+ supportedMajors: z.array(z.number().int().min(14).max(99)).nonempty().refine(unique),
10
+ extensions: z.array(sqlName).refine(unique),
11
+ runtimeConnectionLimit: z.number().int().min(1).max(1e3)
12
+ }).strict();
13
+ const postgresComponentRequirementSchema = postgresRequirementSchema.omit({ componentId: true, enabled: true });
14
+ const postgresServerSchema = z.object({
15
+ id,
16
+ installationId: id,
17
+ environment: z.enum(["staging", "production"]),
18
+ mode: z.enum(["shared", "dedicated", "external"]),
19
+ hostname: z.string().max(253).regex(/^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/u),
20
+ port: z.number().int().min(1).max(65535),
21
+ major: z.number().int().min(14).max(99),
22
+ extensions: z.array(sqlName).refine(unique),
23
+ tls: z.object({ mode: z.literal("verify-full"), trustReference: id }).strict()
24
+ }).strict();
25
+ const postgresAllocationSchema = z.object({
26
+ requirementId: id,
27
+ serverId: id,
28
+ database: sqlName,
29
+ ownerRole: sqlName,
30
+ migrationRole: sqlName,
31
+ runtimeRole: sqlName,
32
+ migrationCredentialReference: id,
33
+ runtimeCredentialReference: id,
34
+ onDisable: z.literal("preserve")
35
+ }).strict().superRefine((value, context) => {
36
+ if (!unique([value.ownerRole, value.migrationRole, value.runtimeRole])) context.addIssue({ code: z.ZodIssueCode.custom, message: "Owner, migration and runtime roles must be distinct." });
37
+ if (value.migrationCredentialReference === value.runtimeCredentialReference) context.addIssue({ code: z.ZodIssueCode.custom, message: "Migration and runtime credentials must be distinct." });
38
+ });
39
+ const postgresTopologySchema = z.object({
40
+ schemaVersion: z.literal("treeseed.postgres-topology/v1"),
41
+ installationId: id,
42
+ environment: z.enum(["staging", "production"]),
43
+ servers: z.array(postgresServerSchema),
44
+ requirements: z.array(postgresRequirementSchema),
45
+ allocations: z.array(postgresAllocationSchema)
46
+ }).strict().superRefine((value, context) => {
47
+ const fail = (message) => context.addIssue({ code: z.ZodIssueCode.custom, message });
48
+ if (!unique(value.servers.map((server) => server.id)) || !unique(value.requirements.map((requirement) => requirement.id)) || !unique(value.allocations.map((allocation) => allocation.requirementId))) fail("Server, requirement and allocation identities must be unique.");
49
+ if (value.servers.filter((server) => server.mode === "shared").length > 1) fail("An environment has at most one default shared server.");
50
+ if (value.servers.some((server) => server.installationId !== value.installationId || server.environment !== value.environment)) fail("Servers must belong to this installation and environment.");
51
+ const databases = /* @__PURE__ */ new Set(), roles = /* @__PURE__ */ new Set();
52
+ for (const allocation of value.allocations) {
53
+ const server = value.servers.find((entry) => entry.id === allocation.serverId);
54
+ const requirement = value.requirements.find((entry) => entry.id === allocation.requirementId);
55
+ if (!server || !requirement) {
56
+ fail("Allocation references an unknown server or requirement.");
57
+ continue;
58
+ }
59
+ if (!requirement.supportedMajors.includes(server.major) || requirement.extensions.some((extension) => !server.extensions.includes(extension))) fail("Server does not satisfy package version/extension requirements.");
60
+ const databaseKey = `${server.id}:${allocation.database}`;
61
+ if (databases.has(databaseKey)) fail("Applications must not share an allocated database.");
62
+ databases.add(databaseKey);
63
+ for (const role of [allocation.ownerRole, allocation.migrationRole, allocation.runtimeRole]) {
64
+ const key = `${server.id}:${role}`;
65
+ if (roles.has(key)) fail("Applications must not share database roles.");
66
+ roles.add(key);
67
+ }
68
+ }
69
+ for (const requirement of value.requirements) {
70
+ if (requirement.enabled && !value.allocations.some((allocation) => allocation.requirementId === requirement.id)) fail("Enabled database requirements need explicit allocations.");
71
+ }
72
+ });
73
+ export {
74
+ postgresAllocationSchema,
75
+ postgresComponentRequirementSchema,
76
+ postgresRequirementSchema,
77
+ postgresServerSchema,
78
+ postgresTopologySchema
79
+ };