-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update page api, update init command
- Loading branch information
Showing
10 changed files
with
90 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,40 @@ | ||
import {Type} from './Type.js' | ||
import {FieldsDefinition, Type} from './Type.js' | ||
|
||
export interface PageSeedData { | ||
export interface PageData { | ||
type: Type | ||
partial: Record<string, any> | ||
fields: Record<string, any> | ||
} | ||
|
||
export type PageSeed< | ||
Definition = object, | ||
Children extends Record<string, PageSeed> = Record<string, PageSeed<any, any>> | ||
export type Page< | ||
Children extends Record<string, Page> = Record<string, never> | ||
> = Children & { | ||
[PageSeed.Data]: PageSeedData | ||
[Page.Data]: PageData | ||
} | ||
|
||
export namespace PageSeed { | ||
export namespace Page { | ||
export const Data = Symbol.for('@alinea/Page.Data') | ||
|
||
export function data(page: PageSeed): PageSeedData { | ||
return page[PageSeed.Data] | ||
export function data(page: Page): PageData { | ||
return page[Page.Data] | ||
} | ||
|
||
export function isPageSeed(page: any): page is PageSeed { | ||
return Boolean(page && page[PageSeed.Data]) | ||
export function isPage(page: any): page is Page { | ||
return Boolean(page && page[Page.Data]) | ||
} | ||
} | ||
|
||
export function page< | ||
Definition, | ||
Children extends Record<string, PageSeed<any, any>> | ||
>( | ||
type: Type<Definition>, | ||
partial: Partial<Type.Infer<Definition>> = {}, | ||
export interface PageConfig<Definition, Children> { | ||
type: Type<Definition> | ||
fields?: Partial<Type.Infer<Definition>> | ||
children?: Children | ||
): PageSeed<Definition> { | ||
children = children ?? ({} as Children) | ||
} | ||
|
||
export function page< | ||
Fields extends FieldsDefinition, | ||
Children extends Record<string, Page> | ||
>(config: PageConfig<Fields, Children>): Page<Children> { | ||
return { | ||
...children, | ||
[PageSeed.Data]: { | ||
type: type, | ||
partial: partial | ||
} | ||
} | ||
...config.children, | ||
[Page.Data]: config | ||
} as any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters