Improve schema validation errors and clean up review fixes
- Use superRefine in jsonSchemaSchema to preserve the detailed error message from validateMetaSchema instead of swallowing it - Revert CatalogModelSources to silent dedup with uniqBy since user layers intentionally take precedence over the default model - Clean up unnecessary `as void` cast in ModelHolder iterator cleanup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Fredrik Adelöw <freben@spotify.com>
This commit is contained in:
@@ -25,13 +25,16 @@ export const jsonObjectSchema = z
|
||||
message: 'Invalid JSON schema',
|
||||
});
|
||||
|
||||
export const jsonSchemaSchema = z.record(z.string(), z.unknown()).refine(
|
||||
(x): x is JsonObject => {
|
||||
export const jsonSchemaSchema = z
|
||||
.record(z.string(), z.unknown())
|
||||
.superRefine((x, ctx): x is JsonObject => {
|
||||
try {
|
||||
return validateMetaSchema(x);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: error instanceof Error ? error.message : 'Invalid JSON schema',
|
||||
});
|
||||
return false;
|
||||
}
|
||||
},
|
||||
{ message: 'Invalid JSON schema' },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -19,6 +19,7 @@ import { defaultCatalogEntityModel } from '../defaultCatalogEntityModel';
|
||||
import { StaticCatalogModelSource } from './StaticCatalogModelSource';
|
||||
import { CatalogModelSource } from './types';
|
||||
import { CatalogModelLayer } from '../types';
|
||||
import uniqBy from 'lodash/uniqBy';
|
||||
|
||||
/**
|
||||
* A helper for creating common catalog model sources.
|
||||
@@ -35,24 +36,13 @@ export class CatalogModelSources {
|
||||
|
||||
/**
|
||||
* Provides a static catalog model on top of the default one (which is
|
||||
* included automatically).
|
||||
* included automatically). User-provided layers take precedence over the
|
||||
* default model when layer IDs overlap.
|
||||
*/
|
||||
static static(layers: CatalogModelLayer[]): CatalogModelSource {
|
||||
const allLayers = [...layers, defaultCatalogEntityModel];
|
||||
const seen = new Set<string>();
|
||||
const deduped: CatalogModelLayer[] = [];
|
||||
for (const layer of allLayers) {
|
||||
if (seen.has(layer.layerId)) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`Duplicate catalog model layer ID "${layer.layerId}" detected; only the first occurrence will be used`,
|
||||
);
|
||||
} else {
|
||||
seen.add(layer.layerId);
|
||||
deduped.push(layer);
|
||||
}
|
||||
}
|
||||
return new StaticCatalogModelSource(deduped);
|
||||
return new StaticCatalogModelSource(
|
||||
uniqBy([...layers, defaultCatalogEntityModel], 'layerId'),
|
||||
);
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
|
||||
@@ -68,7 +68,7 @@ export class ModelHolder {
|
||||
}
|
||||
return ls;
|
||||
} finally {
|
||||
await iter.return(undefined as void);
|
||||
await iter.return(undefined);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user