Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Jan 19, 2023
1 parent be901dc commit e36f310
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/astro/src/content/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ export function createGetEntryBySlug({
// This is not an optimized lookup. Should look into an O(1) implementation
// as it's probably that people will have very large collections.
const entries = await getCollection(collection);
let candidate: typeof entries[number] | undefined = undefined;
for(let entry of entries) {
if(entry.slug === slug) {
let candidate: (typeof entries)[number] | undefined = undefined;
for (let entry of entries) {
if (entry.slug === slug) {
candidate = entry;
break;
}
}

if(typeof candidate === 'undefined') {
if (typeof candidate === 'undefined') {
return undefined;
}

Expand Down
15 changes: 9 additions & 6 deletions packages/astro/src/content/template/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ declare module 'astro:content' {

type EntryMapKeys = keyof typeof entryMap;
type AllValuesOf<T> = T extends any ? T[keyof T] : never;
type ValidEntrySlug<C extends EntryMapKeys> = AllValuesOf<typeof entryMap[C]>['slug'];
type ValidEntrySlug<C extends EntryMapKeys> = AllValuesOf<(typeof entryMap)[C]>['slug'];

export function getEntryBySlug<C extends keyof typeof entryMap, E extends ValidEntrySlug<C> | (string & {})>(
export function getEntryBySlug<
C extends keyof typeof entryMap,
E extends ValidEntrySlug<C> | (string & {})
>(
collection: C,
// Note that this has to accept a regular string too, for SSR
entrySlug: E
): E extends ValidEntrySlug<C> ? Promise<CollectionEntry<C>> : Promise<CollectionEntry<C> | undefined>;
export function getCollection<
C extends keyof typeof entryMap,
>(
): E extends ValidEntrySlug<C>
? Promise<CollectionEntry<C>>
: Promise<CollectionEntry<C> | undefined>;
export function getCollection<C extends keyof typeof entryMap>(
collection: C,
filter?: (data: CollectionEntry<C>) => boolean
): Promise<CollectionEntry<C>[]>;
Expand Down

0 comments on commit e36f310

Please sign in to comment.