Skip to content

Commit

Permalink
Format on Index Mapped Result
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 16, 2024
1 parent 83979c4 commit ff615ab
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions src/type/indexed/indexed-from-mapped-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,11 @@ import { Index, type TIndex } from './index'
// FromProperties
// ------------------------------------------------------------------
// prettier-ignore
type TFromProperties<
Type extends TSchema,
Properties extends TProperties
> = (
type TFromProperties<Type extends TSchema, Properties extends TProperties> = (
{ [K2 in keyof Properties]: TIndex<Type, TIndexPropertyKeys<Properties[K2]>> }
)
// prettier-ignore
function FromProperties<
Type extends TSchema,
Properties extends TProperties
>(type: Type, properties: Properties, options?: SchemaOptions): TFromProperties<Type, Properties> {
function FromProperties<Type extends TSchema, Properties extends TProperties>(type: Type, properties: Properties, options?: SchemaOptions): TFromProperties<Type, Properties> {
const result = {} as Record<PropertyKey, TSchema>
for(const K2 of Object.getOwnPropertyNames(properties)) {
const keys = IndexPropertyKeys(properties[K2])
Expand All @@ -58,36 +52,26 @@ function FromProperties<
// FromMappedResult
// ------------------------------------------------------------------
// prettier-ignore
type TFromMappedResult<
T extends TSchema,
R extends TMappedResult
> = (
TFromProperties<T, R['properties']>
type TFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult> = (
TFromProperties<Type, MappedResult['properties']>
)
// prettier-ignore
function FromMappedResult<
T extends TSchema,
R extends TMappedResult
>(T: T, R: R, options?: SchemaOptions): TFromMappedResult<T, R> {
return FromProperties(T, R.properties, options) as never
function FromMappedResult<Type extends TSchema, MappedResult extends TMappedResult>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TFromMappedResult<Type, MappedResult> {
return FromProperties(type, mappedResult.properties, options) as never
}
// ------------------------------------------------------------------
// TIndexFromMappedResult
// ------------------------------------------------------------------
// prettier-ignore
export type TIndexFromMappedResult<
T extends TSchema,
R extends TMappedResult,
P extends TProperties = TFromMappedResult<T, R>
export type TIndexFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult,
Properties extends TProperties = TFromMappedResult<Type, MappedResult>
> = (
TMappedResult<P>
TMappedResult<Properties>
)
// prettier-ignore
export function IndexFromMappedResult<
T extends TSchema,
R extends TMappedResult,
P extends TProperties = TFromMappedResult<T, R>
>(T: T, R: R, options?: SchemaOptions): TMappedResult<P> {
const P = FromMappedResult(T, R, options)
return MappedResult(P) as never
export function IndexFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult,
Properties extends TProperties = TFromMappedResult<Type, MappedResult>
>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TMappedResult<Properties> {
const properties = FromMappedResult(type, mappedResult, options)
return MappedResult(properties) as never
}

0 comments on commit ff615ab

Please sign in to comment.