mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-27 23:36:39 +00:00
Fix blueprints zod update
This commit is contained in:
@@ -328,10 +328,8 @@ export const ConfigSchema = z
|
|||||||
sites: Record<string, z.infer<typeof SiteSchema>>;
|
sites: Record<string, z.infer<typeof SiteSchema>>;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.refine(
|
.superRefine((config, ctx) => {
|
||||||
// Enforce the full-domain uniqueness across resources in the same stack
|
// Enforce the full-domain uniqueness across resources in the same stack
|
||||||
(config) => {
|
|
||||||
// Extract duplicates for error message
|
|
||||||
const fullDomainMap = new Map<string, string[]>();
|
const fullDomainMap = new Map<string, string[]>();
|
||||||
|
|
||||||
Object.entries(config["proxy-resources"]).forEach(
|
Object.entries(config["proxy-resources"]).forEach(
|
||||||
@@ -347,7 +345,7 @@ export const ConfigSchema = z
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const duplicates = Array.from(fullDomainMap.entries())
|
const fullDomainDuplicates = Array.from(fullDomainMap.entries())
|
||||||
.filter(([_, resourceKeys]) => resourceKeys.length > 1)
|
.filter(([_, resourceKeys]) => resourceKeys.length > 1)
|
||||||
.map(
|
.map(
|
||||||
([fullDomain, resourceKeys]) =>
|
([fullDomain, resourceKeys]) =>
|
||||||
@@ -355,18 +353,15 @@ export const ConfigSchema = z
|
|||||||
)
|
)
|
||||||
.join("; ");
|
.join("; ");
|
||||||
|
|
||||||
if (duplicates.length !== 0) {
|
if (fullDomainDuplicates.length !== 0) {
|
||||||
return {
|
ctx.addIssue({
|
||||||
path: ["resources"],
|
code: z.ZodIssueCode.custom,
|
||||||
error: `Duplicate 'full-domain' values found: ${duplicates}`
|
path: ["proxy-resources"],
|
||||||
};
|
message: `Duplicate 'full-domain' values found: ${fullDomainDuplicates}`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
.refine(
|
|
||||||
// Enforce proxy-port uniqueness within proxy-resources per protocol
|
// Enforce proxy-port uniqueness within proxy-resources per protocol
|
||||||
(config) => {
|
|
||||||
// Extract duplicates for error message
|
|
||||||
const protocolPortMap = new Map<string, string[]>();
|
const protocolPortMap = new Map<string, string[]>();
|
||||||
|
|
||||||
Object.entries(config["proxy-resources"]).forEach(
|
Object.entries(config["proxy-resources"]).forEach(
|
||||||
@@ -383,7 +378,7 @@ export const ConfigSchema = z
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const duplicates = Array.from(protocolPortMap.entries())
|
const portDuplicates = Array.from(protocolPortMap.entries())
|
||||||
.filter(([_, resourceKeys]) => resourceKeys.length > 1)
|
.filter(([_, resourceKeys]) => resourceKeys.length > 1)
|
||||||
.map(([protocolPort, resourceKeys]) => {
|
.map(([protocolPort, resourceKeys]) => {
|
||||||
const [protocol, port] = protocolPort.split(":");
|
const [protocol, port] = protocolPort.split(":");
|
||||||
@@ -391,18 +386,15 @@ export const ConfigSchema = z
|
|||||||
})
|
})
|
||||||
.join("; ");
|
.join("; ");
|
||||||
|
|
||||||
if (duplicates.length !== 0) {
|
if (portDuplicates.length !== 0) {
|
||||||
return {
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
path: ["proxy-resources"],
|
path: ["proxy-resources"],
|
||||||
error: `Duplicate 'proxy-port' values found in proxy-resources: ${duplicates}`
|
message: `Duplicate 'proxy-port' values found in proxy-resources: ${portDuplicates}`
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
.refine(
|
|
||||||
// Enforce alias uniqueness within client-resources
|
// Enforce alias uniqueness within client-resources
|
||||||
(config) => {
|
|
||||||
// Extract duplicates for error message
|
|
||||||
const aliasMap = new Map<string, string[]>();
|
const aliasMap = new Map<string, string[]>();
|
||||||
|
|
||||||
Object.entries(config["client-resources"]).forEach(
|
Object.entries(config["client-resources"]).forEach(
|
||||||
@@ -417,7 +409,7 @@ export const ConfigSchema = z
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const duplicates = Array.from(aliasMap.entries())
|
const aliasDuplicates = Array.from(aliasMap.entries())
|
||||||
.filter(([_, resourceKeys]) => resourceKeys.length > 1)
|
.filter(([_, resourceKeys]) => resourceKeys.length > 1)
|
||||||
.map(
|
.map(
|
||||||
([alias, resourceKeys]) =>
|
([alias, resourceKeys]) =>
|
||||||
@@ -425,14 +417,14 @@ export const ConfigSchema = z
|
|||||||
)
|
)
|
||||||
.join("; ");
|
.join("; ");
|
||||||
|
|
||||||
if (duplicates.length !== 0) {
|
if (aliasDuplicates.length !== 0) {
|
||||||
return {
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
path: ["client-resources"],
|
path: ["client-resources"],
|
||||||
error: `Duplicate 'alias' values found in client-resources: ${duplicates}`
|
message: `Duplicate 'alias' values found in client-resources: ${aliasDuplicates}`
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
// Type inference from the schema
|
// Type inference from the schema
|
||||||
export type Site = z.infer<typeof SiteSchema>;
|
export type Site = z.infer<typeof SiteSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user