generated from AltNext/ts-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/npm_and_yarn/path-parse-1.0.7
- Loading branch information
Showing
18 changed files
with
135 additions
and
249 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"oxidation-ts": minor | ||
--- | ||
|
||
feat: change api to use runtypes |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,6 +1,2 @@ | ||
export type { IFunction } from './function'; | ||
|
||
export type { ITrait } from './trait'; | ||
export { Trait } from './trait'; | ||
export type { IType } from './type'; | ||
export { Type } from './type'; |
This file was deleted.
Oops, something went wrong.
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,17 +1,34 @@ | ||
import { Type } from '../../type'; | ||
import { Trait } from '../trait'; | ||
import type { Static } from 'runtypes'; | ||
import { Record, String } from 'runtypes'; | ||
|
||
import { Trait } from '../..'; | ||
|
||
describe('traits', () => { | ||
it('implements', () => { | ||
const Foo = Trait.create(); | ||
it('create', () => { | ||
const Foo = Trait.create<{ | ||
print(): typeof String; | ||
}>(); | ||
|
||
expect(Foo).toBeDefined(); | ||
}); | ||
|
||
it('impl', () => { | ||
const Foo = Trait.create<{ | ||
print(self: any): string; | ||
}>(); | ||
|
||
const Bar = Foo.implFor(Type.create<string>(), { | ||
foo(): string { | ||
return 'bar'; | ||
const MyType = Foo.impl( | ||
Record({ | ||
foobar: String, | ||
}), | ||
{ | ||
print(self: Static<typeof MyType>) { | ||
return self.foobar; | ||
}, | ||
}, | ||
}); | ||
); | ||
|
||
expect(Bar.foo).toBeDefined(); | ||
expect(Bar.foo()).toStrictEqual('bar'); | ||
expect(MyType.print).toBeDefined(); | ||
expect(MyType.print({ foobar: 'baz' })).toStrictEqual('baz'); | ||
}); | ||
}); |
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,13 +1,84 @@ | ||
import type { IBaseType } from '../interfaces'; | ||
import type { IType, ImplementedType } from '../type'; | ||
import type { Runtype, Static } from 'runtypes'; | ||
|
||
export interface ITrait<Definition> extends IBaseType<Definition> { | ||
implFor<TraitDefinition, Static, Type extends IType<Static>>( | ||
type: Type, | ||
definition: ImplementedType<TraitDefinition>, | ||
): ImplementedType<TraitDefinition> & Type; | ||
export interface ITrait<Definition> { | ||
impl<Type extends Runtype>(type: Type, definition: StaticDefinition<Definition>): StaticDefinition<Definition> & Type; | ||
} | ||
|
||
export interface ITraitApi { | ||
create<Definition>(): ITrait<Definition>; | ||
} | ||
|
||
export type StaticDefinition<Definition> = Definition extends Runtype | ||
? Static<Definition> | ||
: Definition extends () => infer Result | ||
? () => StaticDefinition<Result> | ||
: Definition extends (arg1: infer Arg1) => infer Result | ||
? (arg1: StaticDefinition<Arg1>) => StaticDefinition<Result> | ||
: Definition extends (arg1: infer Arg1, arg2: infer Arg2) => infer Result | ||
? (arg1: StaticDefinition<Arg1>, arg2: StaticDefinition<Arg2>) => StaticDefinition<Result> | ||
: Definition extends (arg1: infer Arg1, arg2: infer Arg2, arg3: infer Arg3) => infer Result | ||
? ( | ||
arg1: StaticDefinition<Arg1>, | ||
arg2: StaticDefinition<Arg2>, | ||
arg3: StaticDefinition<Arg3>, | ||
) => StaticDefinition<Result> | ||
: Definition extends (arg1: infer Arg1, arg2: infer Arg2, arg3: infer Arg3, arg4: infer Arg4) => infer Result | ||
? ( | ||
arg1: StaticDefinition<Arg1>, | ||
arg2: StaticDefinition<Arg2>, | ||
arg3: StaticDefinition<Arg3>, | ||
arg4: StaticDefinition<Arg4>, | ||
) => StaticDefinition<Result> | ||
: Definition extends ( | ||
arg1: infer Arg1, | ||
arg2: infer Arg2, | ||
arg3: infer Arg3, | ||
arg4: infer Arg4, | ||
arg5: infer Arg5, | ||
) => infer Result | ||
? ( | ||
arg1: StaticDefinition<Arg1>, | ||
arg2: StaticDefinition<Arg2>, | ||
arg3: StaticDefinition<Arg3>, | ||
arg4: StaticDefinition<Arg4>, | ||
arg5: StaticDefinition<Arg5>, | ||
) => StaticDefinition<Result> | ||
: Definition extends ( | ||
arg1: infer Arg1, | ||
arg2: infer Arg2, | ||
arg3: infer Arg3, | ||
arg4: infer Arg4, | ||
arg5: infer Arg5, | ||
arg6: infer Arg6, | ||
) => infer Result | ||
? ( | ||
arg1: StaticDefinition<Arg1>, | ||
arg2: StaticDefinition<Arg2>, | ||
arg3: StaticDefinition<Arg3>, | ||
arg4: StaticDefinition<Arg4>, | ||
arg5: StaticDefinition<Arg5>, | ||
arg6: StaticDefinition<Arg6>, | ||
) => StaticDefinition<Result> | ||
: Definition extends ( | ||
arg1: infer Arg1, | ||
arg2: infer Arg2, | ||
arg3: infer Arg3, | ||
arg4: infer Arg4, | ||
arg5: infer Arg5, | ||
arg6: infer Arg6, | ||
arg7: infer Arg7, | ||
) => infer Result | ||
? ( | ||
arg1: StaticDefinition<Arg1>, | ||
arg2: StaticDefinition<Arg2>, | ||
arg3: StaticDefinition<Arg3>, | ||
arg4: StaticDefinition<Arg4>, | ||
arg5: StaticDefinition<Arg5>, | ||
arg6: StaticDefinition<Arg6>, | ||
arg7: StaticDefinition<Arg7>, | ||
) => StaticDefinition<Result> | ||
: Definition extends (...args: infer Args) => infer Result | ||
? (...args: StaticDefinition<Args[keyof Args]>[]) => StaticDefinition<Result> | ||
: Definition extends Record<string, any> | ||
? { [Key in keyof Definition]: StaticDefinition<Definition[Key]> } | ||
: unknown; |
Oops, something went wrong.