From d14d8b4837a6bfa736983814c6f29674865ae1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 6 Feb 2024 04:59:06 +0100 Subject: [PATCH 01/17] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3826504..32265d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@thilawyn/traitify-ts", - "version": "0.1.1", + "version": "0.1.3", "type": "module", "publishConfig": { "registry": "https://git.jvalver.de/api/packages/thilawyn/npm/" -- 2.49.1 From 1f19da761faa38ba99a08a9bcb658a543c10ed7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 6 Feb 2024 17:27:00 +0100 Subject: [PATCH 02/17] Trait opaque fix --- src/Trait.ts | 14 ++++++-------- src/TraitExpression.ts | 24 ++++++++++-------------- src/TraitExpressionBuilder.ts | 22 +++++++++++----------- src/lib.ts | 7 ++++++- src/tests.ts | 8 +++++--- 5 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/Trait.ts b/src/Trait.ts index 6018376..76228c6 100644 --- a/src/Trait.ts +++ b/src/Trait.ts @@ -1,5 +1,5 @@ import { Fn, Pipe, Tuples } from "hotscript" -import { AbstractClass, Class, Opaque } from "type-fest" +import { AbstractClass, Class, Opaque, UnwrapOpaque } from "type-fest" import { AbstractTag, TraitExpression, emptyTraitExpression } from "." import { ExtendFn, SimplifyFn, StaticMembers, StaticMembersFn } from "./util" @@ -16,14 +16,14 @@ export type AddAbstractToImplClass< ) export type RemoveAbstractFromImplClass< - ImplClassWithAbstract extends Class, + ImplClassWithAbstract extends Opaque, TraitApplierSuperTag>, Abstract extends {}, > = ( Class< Omit, keyof Abstract>, ConstructorParameters > & - StaticMembers + UnwrapOpaque> ) @@ -138,12 +138,10 @@ export type TraitApplierSuperTag = "@thilawyn/traitify-ts/TraitApplierSuper" export function trait< Abstract extends {}, - ImplClassWithAbstract extends Class, + ImplClassWithAbstract extends Opaque, TraitApplierSuperTag>, >( - abstract: Opaque, - apply: (Super: Opaque, TraitApplierSuperTag>) => ( - Opaque - ), + abstract: Opaque, + apply: (Super: Opaque, TraitApplierSuperTag>) => ImplClassWithAbstract, ) { return new Trait( emptyTraitExpression, diff --git a/src/TraitExpression.ts b/src/TraitExpression.ts index 9bbdbb2..cd58e47 100644 --- a/src/TraitExpression.ts +++ b/src/TraitExpression.ts @@ -12,9 +12,9 @@ import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util" export class TraitExpression< - Superclass extends AbstractClass<{}>, - OwnTraits extends Trait[], - AllTraits extends Trait[], + Superclass extends AbstractClass<{}>, + const OwnTraits extends Trait[], + const AllTraits extends Trait[], > { constructor( readonly superclass: Superclass, @@ -51,13 +51,13 @@ export class TraitExpression< } subtrait< - SubtraitAbstract extends Implements, - SubtraitImplClassWithAbstract extends Class, + This extends TraitExpression, + SubtraitAbstract extends Implements, + SubtraitImplClassWithAbstract extends Opaque, TraitApplierSuperTag>, >( - abstract: (expression: typeof this) => Opaque, - apply: (Super: Opaque, TraitApplierSuperTag>) => ( - Opaque - ), + this: This, + abstract: (expression: This) => Opaque, + apply: (Super: Opaque, TraitApplierSuperTag>) => SubtraitImplClassWithAbstract, ) { return new Trait( this, @@ -99,11 +99,7 @@ export namespace TraitExpression { } } -export const emptyTraitExpression = new TraitExpression( - TraitExpression.NullSuperclass, - [] as const, - [] as const, -) +export const emptyTraitExpression = new TraitExpression(TraitExpression.NullSuperclass, [], []) export type Implements> = ( diff --git a/src/TraitExpressionBuilder.ts b/src/TraitExpressionBuilder.ts index a4b5b67..fc7c04e 100644 --- a/src/TraitExpressionBuilder.ts +++ b/src/TraitExpressionBuilder.ts @@ -66,11 +66,11 @@ type BuildTraitExpression< class TraitExpressionBuilder< - Super extends AbstractClass<{}>, - OwnTraits extends Trait[], - AllTraits extends Trait[], + Superclass extends AbstractClass<{}>, + const OwnTraits extends Trait[], + const AllTraits extends Trait[], > { - constructor(private expression: TraitExpression) {} + constructor(private expression: TraitExpression) {} extends< Super extends AbstractClass @@ -87,25 +87,25 @@ class TraitExpressionBuilder< } expresses< - Traits extends Trait[] + const Traits extends Trait[] >( ...traits: Traits ): TraitExpressionBuilder< - Super, + Superclass, [...OwnTraits, ...Traits], [...AllTraits, ...SpreadSupertraits] > { return new TraitExpressionBuilder( new TraitExpression( this.expression.superclass, - [...this.expression.ownTraits, ...traits] as const, - [...this.expression.allTraits, ...this.spreadSupertraits(traits)] as const, + [...this.expression.ownTraits, ...traits], + [...this.expression.allTraits, ...this.spreadSupertraits(traits)], ) - ) as any + ) } private spreadSupertraits< - Traits extends Trait< + const Traits extends Trait< TraitExpression[]>, any, any @@ -120,7 +120,7 @@ class TraitExpressionBuilder< } build() { - return this.expression as BuildTraitExpression + return this.expression as BuildTraitExpression } then(fn: (expression: ReturnType) => V): V { diff --git a/src/lib.ts b/src/lib.ts index 9c96c68..9fc1b8f 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,3 +1,8 @@ export { - AbstractTag, Implements, TraitApplierSuperTag, abstract, expression, trait, type Trait, type TraitExpression + Implements, + abstract, + expression, + trait, + type Trait, + type TraitExpression, } from "." diff --git a/src/tests.ts b/src/tests.ts index f8bede5..dd89c0e 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -1,17 +1,18 @@ -import { Simplify } from "type-fest" import { Implements, Trait, abstract, expression, trait } from "." -import { Pipe } from "hotscript" const PrintsHelloOnNew = trait( abstract(), Super => class PrintsHelloOnNew extends Super { + static readonly isPrintsHelloOnNew = true + constructor(...args: any[]) { super(...args) console.log("Hello!") } }, ) +type PrintsHelloOnNewClass = Trait.Class const Identifiable = () => trait( abstract<{ readonly id: ID }>(), @@ -34,6 +35,7 @@ const StatefulSubscription = trait( Super => class StatefulSubscription extends Super {}, ) +type StatefulSubscriptionClass = Trait.Class const ActiveStatefulSubscription = expression .expresses(StatefulSubscription) @@ -51,7 +53,7 @@ const ActiveStatefulSubscription = expression Super => class ActiveStatefulSubscription extends Super {}, ) -type T = Trait.Instance +// type T = Trait.Instance class TestSuperclass { -- 2.49.1 From da17765276c6d4a674a51def2f9983c444df3f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 6 Feb 2024 17:43:44 +0100 Subject: [PATCH 03/17] Opaque unwraping fix --- src/Trait.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Trait.ts b/src/Trait.ts index 76228c6..0d836f9 100644 --- a/src/Trait.ts +++ b/src/Trait.ts @@ -1,5 +1,6 @@ import { Fn, Pipe, Tuples } from "hotscript" -import { AbstractClass, Class, Opaque, UnwrapOpaque } from "type-fest" +import { AbstractClass, Class, Opaque } from "type-fest" +import { tag } from "type-fest/source/opaque" import { AbstractTag, TraitExpression, emptyTraitExpression } from "." import { ExtendFn, SimplifyFn, StaticMembers, StaticMembersFn } from "./util" @@ -23,7 +24,7 @@ export type RemoveAbstractFromImplClass< Omit, keyof Abstract>, ConstructorParameters > & - UnwrapOpaque> + Omit, typeof tag> ) -- 2.49.1 From 2bfb770e05c687a4d29ec4b2dfb65b53f0906d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 6 Feb 2024 22:02:26 +0100 Subject: [PATCH 04/17] Trait applier super tag as symbol --- rollup.config.ts | 2 +- src/Trait.ts | 12 +++++++----- src/TraitExpression.ts | 6 +++--- src/lib.ts | 1 + 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/rollup.config.ts b/rollup.config.ts index 67c2c78..f395890 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -39,6 +39,6 @@ export const createBundleConfig = ( export default [ - createBundleConfig("src/lib.ts", "."), + createBundleConfig("src/index.ts", "."), createBundleConfig("src/util/lib.ts", "./util"), ] diff --git a/src/Trait.ts b/src/Trait.ts index 0d836f9..4de0dc0 100644 --- a/src/Trait.ts +++ b/src/Trait.ts @@ -1,10 +1,12 @@ import { Fn, Pipe, Tuples } from "hotscript" import { AbstractClass, Class, Opaque } from "type-fest" -import { tag } from "type-fest/source/opaque" import { AbstractTag, TraitExpression, emptyTraitExpression } from "." import { ExtendFn, SimplifyFn, StaticMembers, StaticMembersFn } from "./util" +export const isTraitApplierSuper = Symbol("isTraitApplierSuper") + + export type AddAbstractToImplClass< ImplClass extends Class<{}, []>, Abstract extends {}, @@ -17,14 +19,14 @@ export type AddAbstractToImplClass< ) export type RemoveAbstractFromImplClass< - ImplClassWithAbstract extends Opaque, TraitApplierSuperTag>, + ImplClassWithAbstract extends Class & { [isTraitApplierSuper]: true }, Abstract extends {}, > = ( Class< Omit, keyof Abstract>, ConstructorParameters > & - Omit, typeof tag> + Omit, typeof isTraitApplierSuper> ) @@ -139,10 +141,10 @@ export type TraitApplierSuperTag = "@thilawyn/traitify-ts/TraitApplierSuper" export function trait< Abstract extends {}, - ImplClassWithAbstract extends Opaque, TraitApplierSuperTag>, + ImplClassWithAbstract extends Class & { [isTraitApplierSuper]: true }, >( abstract: Opaque, - apply: (Super: Opaque, TraitApplierSuperTag>) => ImplClassWithAbstract, + apply: (Super: AbstractClass & { [isTraitApplierSuper]: true }) => ImplClassWithAbstract, ) { return new Trait( emptyTraitExpression, diff --git a/src/TraitExpression.ts b/src/TraitExpression.ts index cd58e47..8651ca8 100644 --- a/src/TraitExpression.ts +++ b/src/TraitExpression.ts @@ -1,6 +1,6 @@ import { Call, Fn, Pipe, Tuples } from "hotscript" import { AbstractClass, Class, Opaque } from "type-fest" -import { AbstractTag, RemoveAbstractFromImplClass, Trait, TraitApplierSuperTag } from "." +import { AbstractTag, RemoveAbstractFromImplClass, Trait, TraitApplierSuperTag, isTraitApplierSuper } from "." import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util" @@ -53,11 +53,11 @@ export class TraitExpression< subtrait< This extends TraitExpression, SubtraitAbstract extends Implements, - SubtraitImplClassWithAbstract extends Opaque, TraitApplierSuperTag>, + SubtraitImplClassWithAbstract extends Class & { [isTraitApplierSuper]: true }, >( this: This, abstract: (expression: This) => Opaque, - apply: (Super: Opaque, TraitApplierSuperTag>) => SubtraitImplClassWithAbstract, + apply: (Super: AbstractClass & { [isTraitApplierSuper]: true }) => SubtraitImplClassWithAbstract, ) { return new Trait( this, diff --git a/src/lib.ts b/src/lib.ts index 9fc1b8f..8b575d1 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -5,4 +5,5 @@ export { trait, type Trait, type TraitExpression, + isTraitApplierSuper, } from "." -- 2.49.1 From b2b81d613440bcec4b5e04d0b4571e5e23148e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 6 Feb 2024 22:33:47 +0100 Subject: [PATCH 05/17] Switched branding to string litteral --- src/Trait.ts | 12 +++++------- src/TraitExpression.ts | 6 +++--- src/lib.ts | 1 - 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Trait.ts b/src/Trait.ts index 4de0dc0..9514d72 100644 --- a/src/Trait.ts +++ b/src/Trait.ts @@ -4,7 +4,7 @@ import { AbstractTag, TraitExpression, emptyTraitExpression } from "." import { ExtendFn, SimplifyFn, StaticMembers, StaticMembersFn } from "./util" -export const isTraitApplierSuper = Symbol("isTraitApplierSuper") +export type TraitApplierSuperTag = "@thilawyn/traitify-ts/TraitApplierSuper" export type AddAbstractToImplClass< @@ -19,14 +19,14 @@ export type AddAbstractToImplClass< ) export type RemoveAbstractFromImplClass< - ImplClassWithAbstract extends Class & { [isTraitApplierSuper]: true }, + ImplClassWithAbstract extends Class & { _tag: TraitApplierSuperTag }, Abstract extends {}, > = ( Class< Omit, keyof Abstract>, ConstructorParameters > & - Omit, typeof isTraitApplierSuper> + Omit, "_tag"> ) @@ -137,14 +137,12 @@ export namespace Trait { } -export type TraitApplierSuperTag = "@thilawyn/traitify-ts/TraitApplierSuper" - export function trait< Abstract extends {}, - ImplClassWithAbstract extends Class & { [isTraitApplierSuper]: true }, + ImplClassWithAbstract extends Class & { _tag: TraitApplierSuperTag }, >( abstract: Opaque, - apply: (Super: AbstractClass & { [isTraitApplierSuper]: true }) => ImplClassWithAbstract, + apply: (Super: AbstractClass & { _tag: TraitApplierSuperTag }) => ImplClassWithAbstract, ) { return new Trait( emptyTraitExpression, diff --git a/src/TraitExpression.ts b/src/TraitExpression.ts index 8651ca8..fd0d7ca 100644 --- a/src/TraitExpression.ts +++ b/src/TraitExpression.ts @@ -1,6 +1,6 @@ import { Call, Fn, Pipe, Tuples } from "hotscript" import { AbstractClass, Class, Opaque } from "type-fest" -import { AbstractTag, RemoveAbstractFromImplClass, Trait, TraitApplierSuperTag, isTraitApplierSuper } from "." +import { AbstractTag, RemoveAbstractFromImplClass, Trait, TraitApplierSuperTag } from "." import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util" @@ -53,11 +53,11 @@ export class TraitExpression< subtrait< This extends TraitExpression, SubtraitAbstract extends Implements, - SubtraitImplClassWithAbstract extends Class & { [isTraitApplierSuper]: true }, + SubtraitImplClassWithAbstract extends Class & { _tag: TraitApplierSuperTag }, >( this: This, abstract: (expression: This) => Opaque, - apply: (Super: AbstractClass & { [isTraitApplierSuper]: true }) => SubtraitImplClassWithAbstract, + apply: (Super: AbstractClass & { _tag: TraitApplierSuperTag }) => SubtraitImplClassWithAbstract, ) { return new Trait( this, diff --git a/src/lib.ts b/src/lib.ts index 8b575d1..9fc1b8f 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -5,5 +5,4 @@ export { trait, type Trait, type TraitExpression, - isTraitApplierSuper, } from "." -- 2.49.1 From 9071a4fc9ec87c395b2357c58d6133d5a01d0c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 6 Feb 2024 22:36:58 +0100 Subject: [PATCH 06/17] Build lib instead of index --- rollup.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup.config.ts b/rollup.config.ts index f395890..67c2c78 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -39,6 +39,6 @@ export const createBundleConfig = ( export default [ - createBundleConfig("src/index.ts", "."), + createBundleConfig("src/lib.ts", "."), createBundleConfig("src/util/lib.ts", "./util"), ] -- 2.49.1 From 01a950ca95c14bfbb25469ed41d3c9c36ae9391c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Wed, 7 Feb 2024 18:53:28 +0100 Subject: [PATCH 07/17] Code improvement --- src/TraitExpression.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/TraitExpression.ts b/src/TraitExpression.ts index fd0d7ca..2f71cef 100644 --- a/src/TraitExpression.ts +++ b/src/TraitExpression.ts @@ -1,4 +1,4 @@ -import { Call, Fn, Pipe, Tuples } from "hotscript" +import { Fn, Pipe, Tuples } from "hotscript" import { AbstractClass, Class, Opaque } from "type-fest" import { AbstractTag, RemoveAbstractFromImplClass, Trait, TraitApplierSuperTag } from "." import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util" @@ -24,24 +24,22 @@ export class TraitExpression< get extends(): ( AbstractClass< - Pipe<[ - InstanceType, - ...Call, AllTraits>, - ], [ - ExtendFn, - SimplifyFn, + Pipe, // Map all the traits to the instance of their implementation class + Tuples.Prepend>, // Add the instance of the superclass at the top of the list + ExtendFn, // Reduce to a single instance that extends all the instances in the list + SimplifyFn, // Make readable for IDEs ]>, ConstructorParameters > & - Pipe<[ - Superclass, - ...Call, AllTraits>, - ], [ - Tuples.Map, - ExtendFn, - SimplifyFn, + Pipe, // Map all the traits to their implementation class + Tuples.Prepend, // Add the superclass at the top of the list + Tuples.Map, // Map all the classes to an object containing their static members + ExtendFn, // Reduce to a single object that extends all the objects in the list + SimplifyFn, // Make readable for IDEs ]> ) { return this.allTraits.reduce( -- 2.49.1 From c5c01111ba2509b76cbcfa087d628396a7a00e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Wed, 7 Feb 2024 18:54:31 +0100 Subject: [PATCH 08/17] Cleanup --- src/TraitExpression.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TraitExpression.ts b/src/TraitExpression.ts index 2f71cef..5170012 100644 --- a/src/TraitExpression.ts +++ b/src/TraitExpression.ts @@ -44,7 +44,7 @@ export class TraitExpression< ) { return this.allTraits.reduce( (previous, trait) => trait.apply(previous), - this.superclass as Opaque, + this.superclass, ) as any } -- 2.49.1 From 3e8cb15809bea26611b79e7bc9726e039ef0fd2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Wed, 7 Feb 2024 20:30:39 +0100 Subject: [PATCH 09/17] Code improvement --- src/TraitExpression.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/TraitExpression.ts b/src/TraitExpression.ts index 5170012..19a536a 100644 --- a/src/TraitExpression.ts +++ b/src/TraitExpression.ts @@ -67,7 +67,9 @@ export class TraitExpression< } export namespace TraitExpression { - export class NullSuperclass {} + export class NullSuperclass { + static readonly _tag = "@thilawyn/traitify-ts/TraitExpression.NullSuperclass" + } export type Superclass = ( T extends TraitExpression @@ -101,11 +103,10 @@ export const emptyTraitExpression = new TraitExpression(TraitExpression.NullSupe export type Implements> = ( - Exp extends TraitExpression - ? Pipe, - ExtendFn, - SimplifyFn, - ]> - : never + Pipe, + ExtendFn, + SimplifyFn, + ]> ) -- 2.49.1 From 4b142c28f5ba995fb009bc186a1be2029c3d48f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Wed, 7 Feb 2024 21:14:52 +0100 Subject: [PATCH 10/17] Code improvement --- src/TraitExpressionBuilder.ts | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/TraitExpressionBuilder.ts b/src/TraitExpressionBuilder.ts index fc7c04e..53abdf4 100644 --- a/src/TraitExpressionBuilder.ts +++ b/src/TraitExpressionBuilder.ts @@ -19,9 +19,9 @@ type AbstractMembersExtendable< Superclass extends AbstractClass<{}>, Traits extends Trait[], > = ( - Call, - ...Call, Traits>, + Pipe, + Tuples.Prepend>, ]> ) @@ -29,9 +29,9 @@ type ImplInstanceExtendable< Superclass extends AbstractClass<{}>, Traits extends Trait[], > = ( - Call, - ...Call, Traits>, + Pipe, + Tuples.Prepend>, ]> ) @@ -39,10 +39,9 @@ type ImplStaticMembersExtendable< Superclass extends AbstractClass<{}>, Traits extends Trait[], > = ( - Pipe<[ - Superclass, - ...Call, Traits>, - ], [ + Pipe, + Tuples.Prepend, Tuples.Map, ExtendableFn, ]> @@ -53,15 +52,13 @@ type BuildTraitExpression< OwnTraits extends Trait[], AllTraits extends Trait[], > = ( - Call extends true - ? "Cannot express an empty list of traits." - : AbstractMembersExtendable extends false - ? "Type conflict between the traits abstract members and/or the superclass instance." - : ImplInstanceExtendable extends false - ? "Type conflict between the traits implementation instances and/or the superclass instance." - : ImplStaticMembersExtendable extends false - ? "Type conflict between the traits implementation static members and/or the superclass static members." - : TraitExpression + AbstractMembersExtendable extends false + ? "Type conflict between the traits abstract members and/or the superclass instance." + : ImplInstanceExtendable extends false + ? "Type conflict between the traits implementation instances and/or the superclass instance." + : ImplStaticMembersExtendable extends false + ? "Type conflict between the traits implementation static members and/or the superclass static members." + : TraitExpression ) -- 2.49.1 From 051105414c966bef9525634ba73c10d99d8a56e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Wed, 7 Feb 2024 21:32:30 +0100 Subject: [PATCH 11/17] Code improvement --- src/Trait.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Trait.ts b/src/Trait.ts index 9514d72..eb8d353 100644 --- a/src/Trait.ts +++ b/src/Trait.ts @@ -113,7 +113,9 @@ export namespace Trait { Trait.Instance, any[] > & - Pipe<[...Trait.Supertraits, T], [ + Pipe, Tuples.Map, Tuples.Map, ExtendFn, @@ -125,7 +127,9 @@ export namespace Trait { } export type Instance = ( - Pipe<[...Trait.Supertraits, T], [ + Pipe, Tuples.Map, ExtendFn, SimplifyFn, -- 2.49.1 From 7e474e2de973a9356127a1dc347678cf56d9e386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Wed, 7 Feb 2024 21:38:11 +0100 Subject: [PATCH 12/17] Trait fix --- src/Trait.ts | 4 ++-- src/tests.ts | 2 +- src/util/index.ts | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Trait.ts b/src/Trait.ts index eb8d353..c92ebd6 100644 --- a/src/Trait.ts +++ b/src/Trait.ts @@ -115,7 +115,7 @@ export namespace Trait { > & Pipe, + Tuples.Append, Tuples.Map, Tuples.Map, ExtendFn, @@ -129,7 +129,7 @@ export namespace Trait { export type Instance = ( Pipe, + Tuples.Append, Tuples.Map, ExtendFn, SimplifyFn, diff --git a/src/tests.ts b/src/tests.ts index dd89c0e..eebcd3c 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -53,7 +53,7 @@ const ActiveStatefulSubscription = expression Super => class ActiveStatefulSubscription extends Super {}, ) -// type T = Trait.Instance +type ActiveStatefulSubscriptionClass = Trait.Class class TestSuperclass { diff --git a/src/util/index.ts b/src/util/index.ts index 720a972..8407008 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -1,3 +1,7 @@ export * from "./extend" export * from "./inheritance" export * from "./misc" + +export namespace util { + +} -- 2.49.1 From 864ab2becbb94d5d3f1ba2f1608e8453dada9dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Thu, 8 Feb 2024 00:05:12 +0100 Subject: [PATCH 13/17] Cleanup --- src/util/index.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/util/index.ts b/src/util/index.ts index 8407008..720a972 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -1,7 +1,3 @@ export * from "./extend" export * from "./inheritance" export * from "./misc" - -export namespace util { - -} -- 2.49.1 From 1b93f84d4e21d9140a86285c331586e5f6a7b3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Thu, 8 Feb 2024 00:06:27 +0100 Subject: [PATCH 14/17] Cleanup --- src/util/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/index.ts b/src/util/index.ts index 720a972..b529558 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -1,3 +1,2 @@ export * from "./extend" -export * from "./inheritance" export * from "./misc" -- 2.49.1 From 23a22360f90548304c2d807c7a7da8ba2f878346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Thu, 8 Feb 2024 03:50:07 +0100 Subject: [PATCH 15/17] Removed util bundle --- rollup.config.ts | 1 - src/util/lib.ts | 6 ------ 2 files changed, 7 deletions(-) delete mode 100644 src/util/lib.ts diff --git a/rollup.config.ts b/rollup.config.ts index 67c2c78..a9e1bd7 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -40,5 +40,4 @@ export const createBundleConfig = ( export default [ createBundleConfig("src/lib.ts", "."), - createBundleConfig("src/util/lib.ts", "./util"), ] diff --git a/src/util/lib.ts b/src/util/lib.ts deleted file mode 100644 index 4e2038a..0000000 --- a/src/util/lib.ts +++ /dev/null @@ -1,6 +0,0 @@ -export { - Extend, - ExtendFn, - Extendable, - ExtendableFn -} from "." -- 2.49.1 From ab00c0b6bdd471715b728feea291ac92ba447f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Thu, 8 Feb 2024 03:51:41 +0100 Subject: [PATCH 16/17] package.json cleanup --- package.json | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/package.json b/package.json index 32265d7..1b4681c 100644 --- a/package.json +++ b/package.json @@ -18,16 +18,6 @@ "types": "./dist/lib.d.cts", "default": "./dist/lib.cjs" } - }, - "./util": { - "import": { - "types": "./dist/util.d.mts", - "default": "./dist/util.mjs" - }, - "require": { - "types": "./dist/util.d.cts", - "default": "./dist/util.cjs" - } } }, "scripts": { -- 2.49.1 From 8b95793e70a281eff768c504a1dbe627acbde3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Thu, 8 Feb 2024 18:48:03 +0100 Subject: [PATCH 17/17] Module refactoring --- src/Trait.ts | 3 ++- src/TraitExpression.ts | 3 ++- src/TraitExpressionBuilder.ts | 3 ++- src/index.ts | 4 ---- src/lib.ts | 12 ++++-------- src/tests.ts | 5 ++++- 6 files changed, 14 insertions(+), 16 deletions(-) delete mode 100644 src/index.ts diff --git a/src/Trait.ts b/src/Trait.ts index c92ebd6..84516b2 100644 --- a/src/Trait.ts +++ b/src/Trait.ts @@ -1,6 +1,7 @@ import { Fn, Pipe, Tuples } from "hotscript" import { AbstractClass, Class, Opaque } from "type-fest" -import { AbstractTag, TraitExpression, emptyTraitExpression } from "." +import { TraitExpression, emptyTraitExpression } from "./TraitExpression" +import { AbstractTag } from "./abstract" import { ExtendFn, SimplifyFn, StaticMembers, StaticMembersFn } from "./util" diff --git a/src/TraitExpression.ts b/src/TraitExpression.ts index 19a536a..d5bfed3 100644 --- a/src/TraitExpression.ts +++ b/src/TraitExpression.ts @@ -1,6 +1,7 @@ import { Fn, Pipe, Tuples } from "hotscript" import { AbstractClass, Class, Opaque } from "type-fest" -import { AbstractTag, RemoveAbstractFromImplClass, Trait, TraitApplierSuperTag } from "." +import { RemoveAbstractFromImplClass, Trait, TraitApplierSuperTag } from "./Trait" +import { AbstractTag } from "./abstract" import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util" diff --git a/src/TraitExpressionBuilder.ts b/src/TraitExpressionBuilder.ts index 53abdf4..c1f5064 100644 --- a/src/TraitExpressionBuilder.ts +++ b/src/TraitExpressionBuilder.ts @@ -1,6 +1,7 @@ import { Call, Fn, Pipe, Tuples } from "hotscript" import { AbstractClass } from "type-fest" -import { Trait, TraitExpression, emptyTraitExpression } from "." +import { Trait } from "./Trait" +import { TraitExpression, emptyTraitExpression } from "./TraitExpression" import { ExtendableFn, StaticMembersFn } from "./util" diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index bf1c52b..0000000 --- a/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from "./Trait" -export * from "./TraitExpression" -export * from "./TraitExpressionBuilder" -export * from "./abstract" diff --git a/src/lib.ts b/src/lib.ts index 9fc1b8f..e7f6bb7 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,8 +1,4 @@ -export { - Implements, - abstract, - expression, - trait, - type Trait, - type TraitExpression, -} from "." +export { trait, type Trait } from "./Trait" +export { Implements, type TraitExpression } from "./TraitExpression" +export { expression } from "./TraitExpressionBuilder" +export { abstract } from "./abstract" diff --git a/src/tests.ts b/src/tests.ts index eebcd3c..7773ed8 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -1,4 +1,7 @@ -import { Implements, Trait, abstract, expression, trait } from "." +import { Trait, trait } from "./Trait" +import { Implements } from "./TraitExpression" +import { expression } from "./TraitExpressionBuilder" +import { abstract } from "./abstract" const PrintsHelloOnNew = trait( -- 2.49.1