0.1.20 #20
17
package.json
17
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thilawyn/traitify-ts",
|
"name": "@thilawyn/traitify-ts",
|
||||||
"version": "0.1.19",
|
"version": "0.1.20",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://git.jvalver.de/api/packages/thilawyn/npm/"
|
"registry": "https://git.jvalver.de/api/packages/thilawyn/npm/"
|
||||||
@@ -29,16 +29,19 @@
|
|||||||
"clean:node": "rm -rf node_modules"
|
"clean:node": "rm -rf node_modules"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash-es": "^4.17.21",
|
"remeda": "^1.61.0",
|
||||||
"type-fest": "^4.14.0"
|
"type-fest": "^4.18.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash-es": "^4.17.12",
|
|
||||||
"bun-types": "latest",
|
"bun-types": "latest",
|
||||||
"npm-check-updates": "^16.14.17",
|
"npm-check-updates": "^16.14.20",
|
||||||
"npm-sort": "^0.0.4",
|
"npm-sort": "^0.0.4",
|
||||||
"tsup": "^8.0.2",
|
"tsup": "^8.0.2",
|
||||||
"tsx": "^4.7.1",
|
"tsx": "^4.7.3",
|
||||||
"typescript": "^5.4.3"
|
"typescript": "^5.4.5"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@effect/schema": "^0.66.12",
|
||||||
|
"effect": "^3.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,14 +13,13 @@ export class TraitExpression<
|
|||||||
readonly traits: Traits,
|
readonly traits: Traits,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|
||||||
get extends(): (
|
get extends(): (
|
||||||
AbstractClass<
|
AbstractClass<
|
||||||
InstanceType<Superclass> & // Keep the instance of the superclass outside of any kind of type manipulation
|
InstanceType<Superclass> & // Keep the instance of the superclass outside of any kind of type manipulation
|
||||||
// as it can accidentely remove abstract properties
|
// as it can accidentely remove abstract properties
|
||||||
Simplify<
|
Simplify<
|
||||||
Extend<
|
Extend<TraitTuple.MapImplInstance<Traits>>
|
||||||
TraitTuple.MapImplInstance<Traits>
|
|
||||||
>
|
|
||||||
>,
|
>,
|
||||||
|
|
||||||
ConstructorParameters<Superclass>
|
ConstructorParameters<Superclass>
|
||||||
@@ -39,16 +38,20 @@ export class TraitExpression<
|
|||||||
) as any
|
) as any
|
||||||
}
|
}
|
||||||
|
|
||||||
staticImplements(target: StaticImplements<typeof this>, context: any) {}
|
|
||||||
|
staticImplements(_target: StaticImplements<typeof this>, _context: any) {}
|
||||||
|
|
||||||
|
get staticImplementsStage2() {
|
||||||
|
return (_target: StaticImplements<typeof this>) => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
subtrait<
|
subtrait<
|
||||||
This extends TraitExpression<typeof TraitExpression.NullSuperclass, any>
|
This extends TraitExpression<typeof TraitExpression.NullSuperclass, any>
|
||||||
>(
|
>(
|
||||||
this: This
|
this: This
|
||||||
) {
|
) {
|
||||||
return new TraitBuilder<
|
return new TraitBuilder<This,
|
||||||
This,
|
|
||||||
|
|
||||||
Simplify<
|
Simplify<
|
||||||
Extend<TraitTuple.MapAbstract<Traits>>
|
Extend<TraitTuple.MapAbstract<Traits>>
|
||||||
>,
|
>,
|
||||||
@@ -77,7 +80,7 @@ export namespace TraitExpression {
|
|||||||
const nullSuperclassSymbol = Symbol()
|
const nullSuperclassSymbol = Symbol()
|
||||||
export class NullSuperclass {
|
export class NullSuperclass {
|
||||||
static readonly [nullSuperclassSymbol]: true
|
static readonly [nullSuperclassSymbol]: true
|
||||||
constructor(...args: any[]) {}
|
constructor(..._args: any[]) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Superclass<T> = (
|
export type Superclass<T> = (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { uniq } from "lodash-es"
|
import { unique } from "remeda"
|
||||||
import { AbstractClass, IsEqual } from "type-fest"
|
import { AbstractClass, IsEqual } from "type-fest"
|
||||||
import { Trait, TraitTuple } from "./Trait"
|
import { Trait, TraitTuple } from "./Trait"
|
||||||
import { TraitExpression } from "./TraitExpression"
|
import { TraitExpression } from "./TraitExpression"
|
||||||
@@ -36,7 +36,7 @@ export class TraitExpressionBuilder<
|
|||||||
]) as readonly Trait<any, any, any, any>[] as TraitExpressionBuilder.SpreadSupertraits<T>
|
]) as readonly Trait<any, any, any, any>[] as TraitExpressionBuilder.SpreadSupertraits<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
static traitsUniq<
|
static traitsUnique<
|
||||||
const T extends readonly Trait<
|
const T extends readonly Trait<
|
||||||
TraitExpression<
|
TraitExpression<
|
||||||
typeof TraitExpression.NullSuperclass,
|
typeof TraitExpression.NullSuperclass,
|
||||||
@@ -49,7 +49,7 @@ export class TraitExpressionBuilder<
|
|||||||
>(
|
>(
|
||||||
traits: T
|
traits: T
|
||||||
) {
|
) {
|
||||||
return uniq(traits) as readonly Trait<any, any, any, any>[] as TraitExpressionBuilder.TraitsUniq<T>
|
return unique(traits) as readonly Trait<any, any, any, any>[] as TraitExpressionBuilder.TraitsUnique<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ export class TraitExpressionBuilder<
|
|||||||
return new this.constructor(
|
return new this.constructor(
|
||||||
this.expressionSuperclass,
|
this.expressionSuperclass,
|
||||||
|
|
||||||
this.constructor.traitsUniq([
|
this.constructor.traitsUnique([
|
||||||
...this.expressionTraits,
|
...this.expressionTraits,
|
||||||
...this.constructor.spreadSupertraits(traits),
|
...this.constructor.spreadSupertraits(traits),
|
||||||
]),
|
]),
|
||||||
@@ -109,7 +109,7 @@ export class TraitExpressionBuilder<
|
|||||||
return new this.constructor(
|
return new this.constructor(
|
||||||
this.expressionSuperclass,
|
this.expressionSuperclass,
|
||||||
|
|
||||||
this.constructor.traitsUniq([
|
this.constructor.traitsUnique([
|
||||||
...this.constructor.spreadSupertraits(traits),
|
...this.constructor.spreadSupertraits(traits),
|
||||||
...this.expressionTraits,
|
...this.expressionTraits,
|
||||||
]),
|
]),
|
||||||
@@ -154,14 +154,14 @@ export namespace TraitExpressionBuilder {
|
|||||||
: readonly []
|
: readonly []
|
||||||
)
|
)
|
||||||
|
|
||||||
export type TraitsUniq<Traits> = (
|
export type TraitsUnique<Traits> = (
|
||||||
Traits extends readonly [
|
Traits extends readonly [
|
||||||
...infer Rest,
|
...infer Rest,
|
||||||
infer El extends Trait<any, any, any, any>,
|
infer El extends Trait<any, any, any, any>,
|
||||||
]
|
]
|
||||||
? IsTraitInTupleFromRight<Rest, El> extends true
|
? IsTraitInTupleFromRight<Rest, El> extends true
|
||||||
? TraitsUniq<Rest>
|
? TraitsUnique<Rest>
|
||||||
: readonly [...TraitsUniq<Rest>, El]
|
: readonly [...TraitsUnique<Rest>, El]
|
||||||
: readonly []
|
: readonly []
|
||||||
)
|
)
|
||||||
type IsTraitInTupleFromRight<Traits, T> = (
|
type IsTraitInTupleFromRight<Traits, T> = (
|
||||||
@@ -176,7 +176,7 @@ export namespace TraitExpressionBuilder {
|
|||||||
Traits extends readonly Trait<any, any, any, any>[],
|
Traits extends readonly Trait<any, any, any, any>[],
|
||||||
T extends readonly Trait<any, any, any, any>[],
|
T extends readonly Trait<any, any, any, any>[],
|
||||||
> = (
|
> = (
|
||||||
TraitExpressionBuilder.TraitsUniq<readonly [
|
TraitExpressionBuilder.TraitsUnique<readonly [
|
||||||
...Traits,
|
...Traits,
|
||||||
...TraitExpressionBuilder.SpreadSupertraits<T>,
|
...TraitExpressionBuilder.SpreadSupertraits<T>,
|
||||||
]>
|
]>
|
||||||
@@ -186,7 +186,7 @@ export namespace TraitExpressionBuilder {
|
|||||||
Traits extends readonly Trait<any, any, any, any>[],
|
Traits extends readonly Trait<any, any, any, any>[],
|
||||||
T extends readonly Trait<any, any, any, any>[],
|
T extends readonly Trait<any, any, any, any>[],
|
||||||
> = (
|
> = (
|
||||||
TraitExpressionBuilder.TraitsUniq<readonly [
|
TraitExpressionBuilder.TraitsUnique<readonly [
|
||||||
...TraitExpressionBuilder.SpreadSupertraits<T>,
|
...TraitExpressionBuilder.SpreadSupertraits<T>,
|
||||||
...Traits,
|
...Traits,
|
||||||
]>
|
]>
|
||||||
|
|||||||
39
src/effect.ts
Normal file
39
src/effect.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { Schema as S } from "@effect/schema"
|
||||||
|
import { Simplify } from "type-fest"
|
||||||
|
import { Trait, TraitTuple } from "./Trait"
|
||||||
|
import { TraitExpression } from "./TraitExpression"
|
||||||
|
import { Extend } from "./util"
|
||||||
|
|
||||||
|
|
||||||
|
export function extendsEffectSchemaExpression<
|
||||||
|
Fields extends S.Struct.Fields,
|
||||||
|
A, I, R, C,
|
||||||
|
Inherited extends object,
|
||||||
|
Proto,
|
||||||
|
|
||||||
|
const Traits extends readonly Trait<any, any, any, any>[],
|
||||||
|
>(
|
||||||
|
expression: TraitExpression<
|
||||||
|
S.Class<unknown, Fields, A, I, R, C, Inherited, Proto>,
|
||||||
|
Traits
|
||||||
|
>
|
||||||
|
) {
|
||||||
|
return <Self>(): (
|
||||||
|
S.Class<
|
||||||
|
Self,
|
||||||
|
Fields,
|
||||||
|
A, I, R, C,
|
||||||
|
Simplify<
|
||||||
|
Extend<[
|
||||||
|
Inherited,
|
||||||
|
...TraitTuple.MapImplInstance<Traits>
|
||||||
|
]>
|
||||||
|
>,
|
||||||
|
Proto
|
||||||
|
> &
|
||||||
|
|
||||||
|
Simplify<
|
||||||
|
Extend<TraitTuple.MapImplStaticMembers<Traits>>
|
||||||
|
>
|
||||||
|
) => expression.extends as any
|
||||||
|
}
|
||||||
@@ -2,3 +2,4 @@ export { Trait, TraitClass, TraitConcreteClass, TraitInstance, TraitStaticMember
|
|||||||
export { ImplStatic, TraitBuilder, implStaticInstantiableThis, implStaticThis, trait } from "./TraitBuilder"
|
export { ImplStatic, TraitBuilder, implStaticInstantiableThis, implStaticThis, trait } from "./TraitBuilder"
|
||||||
export { Implements, StaticImplements, TraitExpression, TraitExpressionClass, TraitExpressionConcreteClass, TraitExpressionInstance, TraitExpressionStaticMembers } from "./TraitExpression"
|
export { Implements, StaticImplements, TraitExpression, TraitExpressionClass, TraitExpressionConcreteClass, TraitExpressionInstance, TraitExpressionStaticMembers } from "./TraitExpression"
|
||||||
export { TraitExpressionBuilder, expression } from "./TraitExpressionBuilder"
|
export { TraitExpressionBuilder, expression } from "./TraitExpressionBuilder"
|
||||||
|
export { extendsEffectSchemaExpression } from "./effect"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { defineConfig } from "tsup"
|
|||||||
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
entry: ["src/lib.ts"],
|
entry: ["./src/lib.ts"],
|
||||||
format: ["esm", "cjs"],
|
format: ["esm", "cjs"],
|
||||||
dts: true,
|
dts: true,
|
||||||
splitting: false,
|
splitting: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user