-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de9267f
commit 1403cf5
Showing
8 changed files
with
140 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createResolver } from '@powership/schema'; | ||
|
||
import { AnyEntity } from './EntityInterfaces'; | ||
|
||
export class EntityResolversChain<TEntity extends AnyEntity = AnyEntity> { | ||
private entity: TEntity; | ||
|
||
constructor(entity: TEntity) { | ||
this.entity = entity; | ||
} | ||
|
||
create = <Name extends string>(name: Name) => { | ||
const { | ||
type, | ||
edgeType, | ||
databaseType, | ||
inputType, | ||
paginationType, | ||
originType, | ||
indexGraphTypes, | ||
} = this.entity; | ||
|
||
const current = { | ||
name, | ||
} as const; | ||
}; | ||
} | ||
|
||
|
||
|
||
|
||
const x = |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { $cast, $isKnown } from './index'; | ||
|
||
export type __$array<Value = any> = Value extends ReadonlyArray<infer T> | ||
? T[] | ||
: Value extends Array<infer T> | ||
? T[] | ||
: never; | ||
|
||
export type _$array<Value = any> = [$isKnown<Value>] extends [1] | ||
? __$array<Value> | ||
: never; | ||
|
||
export type $array<Value = any> = Value extends unknown | ||
? $cast<_$array<Value>, any[]> | ||
: never; | ||
|
||
export function $array<T>(value: T): $array<T> { | ||
return ((): any => { | ||
if (value && typeof value === 'object' && !Array.isArray(value)) { | ||
return value; | ||
} | ||
return Object.create(null); | ||
})(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { IsAny, IsNever, IsUnknown } from '@powership/utils'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export type $isAny<T> = IsAny<T>; | ||
export type $isNever<T> = IsNever<T>; | ||
export type $isUnknown<T> = IsUnknown<T>; | ||
|
||
export type $isKnown<T> = $isAny<T> extends true | ||
? 0 | ||
: $isNever<T> extends true | ||
? 0 | ||
: $isUnknown<T> extends true | ||
? 0 | ||
: 1; | ||
|
||
export type $cast<Value, Target> = [$isKnown<Value>] extends [1] | ||
? Value extends Target | ||
? Value | ||
: Target | ||
: never; | ||
|
||
export {}; |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { captureStackTrace } from '@powership/utils'; | ||
|
||
import type { $cast } from './index'; | ||
|
||
export type $number<T = any> = $cast<T, number>; | ||
|
||
export function $number<T>(value: T, defaults?: number): $number<T> { | ||
return ((): any => { | ||
if (typeof value === 'number') { | ||
return value; | ||
} | ||
const s = `${defaults}`; | ||
|
||
return s.match(/^\d+$/) | ||
? +s | ||
: (() => { | ||
const err = new Error(`Expected value to be an number, found ${s}`); | ||
captureStackTrace(err, $number); | ||
throw err; | ||
})(); | ||
})(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { $cast } from './index'; | ||
|
||
export type $object<T = any> = $cast<T, Record<string, any>>; | ||
|
||
export function $object<T>(value: T): $object<T> { | ||
return ((): any => { | ||
if (value && typeof value === 'object' && !Array.isArray(value)) { | ||
return value; | ||
} | ||
return Object.create(null); | ||
})(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { $cast } from './index'; | ||
|
||
export type $string<T = any> = $cast<T, string>; | ||
|
||
export function $string<T>(value: T): $string<T> { | ||
return ((): any => { | ||
if (typeof value === 'string') { | ||
return value; | ||
} | ||
return ''; | ||
})(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './$array'; | ||
export * from './$cast'; | ||
export * from './$number'; | ||
export * from './$object'; | ||
export * from './$string'; |