@treeseed/sdk 0.13.0-rc.101 → 0.13.0-rc.103

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.
@@ -22,6 +22,25 @@ export declare const postgresRequirementSchema: z.ZodObject<{
22
22
  extensions: string[];
23
23
  runtimeConnectionLimit: number;
24
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
+ }>;
25
44
  /** Deployment owns the selected server and its bootstrap authority. No credentials here. */
26
45
  export declare const postgresServerSchema: z.ZodObject<{
27
46
  id: z.ZodString;
@@ -44,30 +63,30 @@ export declare const postgresServerSchema: z.ZodObject<{
44
63
  }>;
45
64
  }, "strict", z.ZodTypeAny, {
46
65
  id: string;
47
- mode: "external" | "shared" | "dedicated";
66
+ mode: "shared" | "dedicated" | "external";
48
67
  environment: "production" | "staging";
49
68
  port: number;
50
69
  major: number;
70
+ extensions: string[];
71
+ installationId: string;
72
+ hostname: string;
51
73
  tls: {
52
74
  mode: "verify-full";
53
75
  trustReference: string;
54
76
  };
55
- extensions: string[];
56
- installationId: string;
57
- hostname: string;
58
77
  }, {
59
78
  id: string;
60
- mode: "external" | "shared" | "dedicated";
79
+ mode: "shared" | "dedicated" | "external";
61
80
  environment: "production" | "staging";
62
81
  port: number;
63
82
  major: number;
83
+ extensions: string[];
84
+ installationId: string;
85
+ hostname: string;
64
86
  tls: {
65
87
  mode: "verify-full";
66
88
  trustReference: string;
67
89
  };
68
- extensions: string[];
69
- installationId: string;
70
- hostname: string;
71
90
  }>;
72
91
  export declare const postgresAllocationSchema: z.ZodEffects<z.ZodObject<{
73
92
  requirementId: z.ZodString;
@@ -146,30 +165,30 @@ export declare const postgresTopologySchema: z.ZodEffects<z.ZodObject<{
146
165
  }>;
147
166
  }, "strict", z.ZodTypeAny, {
148
167
  id: string;
149
- mode: "external" | "shared" | "dedicated";
168
+ mode: "shared" | "dedicated" | "external";
150
169
  environment: "production" | "staging";
151
170
  port: number;
152
171
  major: number;
172
+ extensions: string[];
173
+ installationId: string;
174
+ hostname: string;
153
175
  tls: {
154
176
  mode: "verify-full";
155
177
  trustReference: string;
156
178
  };
157
- extensions: string[];
158
- installationId: string;
159
- hostname: string;
160
179
  }, {
161
180
  id: string;
162
- mode: "external" | "shared" | "dedicated";
181
+ mode: "shared" | "dedicated" | "external";
163
182
  environment: "production" | "staging";
164
183
  port: number;
165
184
  major: number;
185
+ extensions: string[];
186
+ installationId: string;
187
+ hostname: string;
166
188
  tls: {
167
189
  mode: "verify-full";
168
190
  trustReference: string;
169
191
  };
170
- extensions: string[];
171
- installationId: string;
172
- hostname: string;
173
192
  }>, "many">;
174
193
  requirements: z.ZodArray<z.ZodObject<{
175
194
  id: z.ZodString;
@@ -250,17 +269,17 @@ export declare const postgresTopologySchema: z.ZodEffects<z.ZodObject<{
250
269
  installationId: string;
251
270
  servers: {
252
271
  id: string;
253
- mode: "external" | "shared" | "dedicated";
272
+ mode: "shared" | "dedicated" | "external";
254
273
  environment: "production" | "staging";
255
274
  port: number;
256
275
  major: number;
276
+ extensions: string[];
277
+ installationId: string;
278
+ hostname: string;
257
279
  tls: {
258
280
  mode: "verify-full";
259
281
  trustReference: string;
260
282
  };
261
- extensions: string[];
262
- installationId: string;
263
- hostname: string;
264
283
  }[];
265
284
  requirements: {
266
285
  id: string;
@@ -287,17 +306,17 @@ export declare const postgresTopologySchema: z.ZodEffects<z.ZodObject<{
287
306
  installationId: string;
288
307
  servers: {
289
308
  id: string;
290
- mode: "external" | "shared" | "dedicated";
309
+ mode: "shared" | "dedicated" | "external";
291
310
  environment: "production" | "staging";
292
311
  port: number;
293
312
  major: number;
313
+ extensions: string[];
314
+ installationId: string;
315
+ hostname: string;
294
316
  tls: {
295
317
  mode: "verify-full";
296
318
  trustReference: string;
297
319
  };
298
- extensions: string[];
299
- installationId: string;
300
- hostname: string;
301
320
  }[];
302
321
  requirements: {
303
322
  id: string;
@@ -324,17 +343,17 @@ export declare const postgresTopologySchema: z.ZodEffects<z.ZodObject<{
324
343
  installationId: string;
325
344
  servers: {
326
345
  id: string;
327
- mode: "external" | "shared" | "dedicated";
346
+ mode: "shared" | "dedicated" | "external";
328
347
  environment: "production" | "staging";
329
348
  port: number;
330
349
  major: number;
350
+ extensions: string[];
351
+ installationId: string;
352
+ hostname: string;
331
353
  tls: {
332
354
  mode: "verify-full";
333
355
  trustReference: string;
334
356
  };
335
- extensions: string[];
336
- installationId: string;
337
- hostname: string;
338
357
  }[];
339
358
  requirements: {
340
359
  id: string;
@@ -361,17 +380,17 @@ export declare const postgresTopologySchema: z.ZodEffects<z.ZodObject<{
361
380
  installationId: string;
362
381
  servers: {
363
382
  id: string;
364
- mode: "external" | "shared" | "dedicated";
383
+ mode: "shared" | "dedicated" | "external";
365
384
  environment: "production" | "staging";
366
385
  port: number;
367
386
  major: number;
387
+ extensions: string[];
388
+ installationId: string;
389
+ hostname: string;
368
390
  tls: {
369
391
  mode: "verify-full";
370
392
  trustReference: string;
371
393
  };
372
- extensions: string[];
373
- installationId: string;
374
- hostname: string;
375
394
  }[];
376
395
  requirements: {
377
396
  id: string;
@@ -10,6 +10,7 @@ const postgresRequirementSchema = z.object({
10
10
  extensions: z.array(sqlName).refine(unique),
11
11
  runtimeConnectionLimit: z.number().int().min(1).max(1e3)
12
12
  }).strict();
13
+ const postgresComponentRequirementSchema = postgresRequirementSchema.omit({ componentId: true, enabled: true });
13
14
  const postgresServerSchema = z.object({
14
15
  id,
15
16
  installationId: id,
@@ -47,7 +48,7 @@ const postgresTopologySchema = z.object({
47
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.");
48
49
  if (value.servers.filter((server) => server.mode === "shared").length > 1) fail("An environment has at most one default shared server.");
49
50
  if (value.servers.some((server) => server.installationId !== value.installationId || server.environment !== value.environment)) fail("Servers must belong to this installation and environment.");
50
- const databases = /* @__PURE__ */ new Set(), roles = /* @__PURE__ */ new Set();
51
+ const databases = /* @__PURE__ */ new Set(), roles = /* @__PURE__ */ new Set(), credentials = /* @__PURE__ */ new Set();
51
52
  for (const allocation of value.allocations) {
52
53
  const server = value.servers.find((entry) => entry.id === allocation.serverId);
53
54
  const requirement = value.requirements.find((entry) => entry.id === allocation.requirementId);
@@ -59,6 +60,10 @@ const postgresTopologySchema = z.object({
59
60
  const databaseKey = `${server.id}:${allocation.database}`;
60
61
  if (databases.has(databaseKey)) fail("Applications must not share an allocated database.");
61
62
  databases.add(databaseKey);
63
+ for (const reference of [allocation.migrationCredentialReference, allocation.runtimeCredentialReference]) {
64
+ if (credentials.has(reference)) fail("Applications must not share database credential references.");
65
+ credentials.add(reference);
66
+ }
62
67
  for (const role of [allocation.ownerRole, allocation.migrationRole, allocation.runtimeRole]) {
63
68
  const key = `${server.id}:${role}`;
64
69
  if (roles.has(key)) fail("Applications must not share database roles.");
@@ -71,6 +76,7 @@ const postgresTopologySchema = z.object({
71
76
  });
72
77
  export {
73
78
  postgresAllocationSchema,
79
+ postgresComponentRequirementSchema,
74
80
  postgresRequirementSchema,
75
81
  postgresServerSchema,
76
82
  postgresTopologySchema
@@ -0,0 +1,14 @@
1
+ /** Call after artifact authenticity verification, with the complete selected
2
+ * component inventory. Host configuration cannot weaken a package requirement.
3
+ */
4
+ export declare function verifyHostPostgresRequirements(hostInput: unknown, releaseInputs: unknown[]): {
5
+ verified: true;
6
+ requirements: {
7
+ id: string;
8
+ componentId: string;
9
+ enabled: boolean;
10
+ supportedMajors: [number, ...number[]];
11
+ extensions: string[];
12
+ runtimeConnectionLimit: number;
13
+ }[];
14
+ };
@@ -0,0 +1,30 @@
1
+ import { componentReleaseSchema, hostConfigurationSchema } from "../schemas.js";
2
+ import { canonicalDeploymentJson, deploymentDigest } from "../canonical.js";
3
+ function verifyHostPostgresRequirements(hostInput, releaseInputs) {
4
+ const host = hostConfigurationSchema.parse(hostInput);
5
+ const releases = releaseInputs.map((input) => componentReleaseSchema.parse(input));
6
+ if (new Set(releases.map((item) => item.componentId)).size !== releases.length) throw new Error("Duplicate component release inventory");
7
+ if (Object.entries(host.components).some(([id, selection]) => selection.enabled && !releases.some((release) => release.componentId === id))) throw new Error("Selected component release inventory is incomplete");
8
+ const requirements = [];
9
+ for (const release of releases) {
10
+ const selection = host.components[release.componentId];
11
+ if (!selection) continue;
12
+ if (deploymentDigest(release.runtime) !== release.runtimeDigest) throw new Error("Component runtime digest mismatch");
13
+ for (const requirement of release.runtime.postgresRequirements ?? []) requirements.push({
14
+ ...requirement,
15
+ componentId: release.componentId,
16
+ enabled: selection.enabled
17
+ });
18
+ }
19
+ if (new Set(requirements.map((item) => item.id)).size !== requirements.length) throw new Error("Component database requirement identities collide");
20
+ const normalize = (items) => items.map((item) => ({
21
+ ...item,
22
+ supportedMajors: [...item.supportedMajors].sort((a, b) => a - b),
23
+ extensions: [...item.extensions].sort()
24
+ })).sort((a, b) => a.id.localeCompare(b.id));
25
+ if (canonicalDeploymentJson(normalize(requirements)) !== canonicalDeploymentJson(normalize(host.postgres?.requirements ?? []))) throw new Error("Host database requirements differ from selected immutable components");
26
+ return { verified: true, requirements };
27
+ }
28
+ export {
29
+ verifyHostPostgresRequirements
30
+ };