[ci] format

This commit is contained in:
Louis Escher 2025-01-22 21:06:29 +00:00 committed by astrobot-houston
parent 8f520f1cc6
commit a90f79fe59
3 changed files with 22 additions and 20 deletions

View file

@ -2,6 +2,7 @@ import { promises as fs, existsSync } from 'node:fs';
import PQueue from 'p-queue';
import type { FSWatcher } from 'vite';
import xxhash from 'xxhash-wasm';
import type { z } from 'zod';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import type { Logger } from '../core/logger/core.js';
import type { AstroSettings } from '../types/astro.js';
@ -23,7 +24,6 @@ import {
loaderReturnSchema,
safeStringify,
} from './utils.js';
import type { z } from 'zod';
import { type WrappedWatcher, createWatcherWrapper } from './watcher.js';
export interface ContentLayerOptions {
@ -353,17 +353,15 @@ export async function simpleLoader<TData extends { id: string }>(
// Due to this being a union, zod will always throw an "Expected array, received object" error along with the other errors.
// This error is in the second position if the data is an array, and in the first position if the data is an object.
const parseIssue = Array.isArray(unsafeData)
? issue.unionErrors[0]
: issue.unionErrors[1];
const parseIssue = Array.isArray(unsafeData) ? issue.unionErrors[0] : issue.unionErrors[1];
const error = parseIssue.errors[0];
const firstPathItem = error.path[0];
const entry = Array.isArray(unsafeData)
? unsafeData[firstPathItem as number]
const entry = Array.isArray(unsafeData)
? unsafeData[firstPathItem as number]
: unsafeData[firstPathItem as string];
throw new AstroError({
...AstroErrorData.ContentLoaderReturnsInvalidId,
message: AstroErrorData.ContentLoaderReturnsInvalidId.message(context.collection, entry),

View file

@ -38,22 +38,26 @@ export type ContentLookupMap = {
const entryTypeSchema = z
.object({
id: z
.string({
invalid_type_error: 'Content entry `id` must be a string',
// Default to empty string so we can validate properly in the loader
}),
}).passthrough();
id: z.string({
invalid_type_error: 'Content entry `id` must be a string',
// Default to empty string so we can validate properly in the loader
}),
})
.passthrough();
export const loaderReturnSchema = z.union([
z.array(entryTypeSchema),
z.record(
z.string(),
z.object({
id: z.string({
invalid_type_error: 'Content entry `id` must be a string'
}).optional()
}).passthrough()
z.string(),
z
.object({
id: z
.string({
invalid_type_error: 'Content entry `id` must be a string',
})
.optional(),
})
.passthrough(),
),
]);

View file

@ -311,7 +311,7 @@ describe('Content Collections', () => {
} catch (e) {
error = e.message;
}
assert.match(error, /returned an entry with an invalid `id`/);
assert.match(error, /returned an entry with an invalid `id`/);
});
});