From 85d97e0ec8abfd169c2557b37272ad7fc2e8d69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Fri, 29 Dec 2023 20:52:03 +0100 Subject: [PATCH 1/4] Fixed packaging --- .drone.jsonnet | 2 +- .npmignore | 10 ---------- package.json | 3 +++ 3 files changed, 4 insertions(+), 11 deletions(-) delete mode 100644 .npmignore diff --git a/.drone.jsonnet b/.drone.jsonnet index bdff652..fefec26 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -23,7 +23,7 @@ local build_step = { local pack_step = { name: "pack", image: node_image, - commands: ["npm pack"], + commands: ["npm pack --dry-run"], }; local publish_step = { diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 1b733b1..0000000 --- a/.npmignore +++ /dev/null @@ -1,10 +0,0 @@ -/node_modules/ -/src/ -/.drone.jsonnet -/.gitignore -/.npmignore -/bun.lockb -/README.md -/rollup.config.js -/tsconfig.json -/tsconfig.tsbuildinfo diff --git a/package.json b/package.json index 42b8618..af08db8 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ "publishConfig": { "registry": "https://git.jvalver.de/api/packages/thilawyn/npm/" }, + "files": [ + "./dist" + ], "exports": { ".": { "import": { -- 2.49.1 From cabf2e0d742b7866ddf9a78d3a1889327cecc843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Fri, 29 Dec 2023 23:47:24 +0100 Subject: [PATCH 2/4] Fixed StaticMembers and subtraiting --- src/index.ts | 4 +++- src/tests.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index fc70958..ea9832d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,9 @@ import { AbstractClass, AbstractConstructor, Opaque, UnionToIntersection } from * Represents the static members of a class. * @template C - The class type. */ -export type StaticMembers = Pick +export type StaticMembers = { + [Key in keyof C as Key extends "prototype" ? never : Key]: C[Key] +} /** diff --git a/src/tests.ts b/src/tests.ts index 37e9412..30e12c5 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -1,4 +1,4 @@ -import { expresses, trait } from "." +import { expresses, extendsAndExpresses, trait } from "." const Identifiable = () => @@ -21,8 +21,13 @@ const Identifiable = () => const ImplementsIdentifiable = (defaultID: ID) => trait(Parent => { - abstract class ImplementsIdentifiable extends Identifiable()(Parent) { + abstract class ImplementsIdentifiable extends extendsAndExpresses(Parent, [Identifiable()]) { id: ID = defaultID + + constructor(...args: any[]) { + super(...args) + console.log("ImplementsIdentifiable constructor") + } } return ImplementsIdentifiable -- 2.49.1 From 9391cbf4b3755f85bea50bb6b7aede77f4460fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sat, 30 Dec 2023 00:36:15 +0100 Subject: [PATCH 3/4] Added doc --- src/index.ts | 23 +++++++++++++++++++++++ src/tests.ts | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index ea9832d..8351eca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,6 +53,9 @@ export type UnwrapTraitC = * static readonly defaultPermissions: string[] = [] * permissions: string[] = [] * + * // Constructor is optional + * // If you wish to use it, make sure it takes any[] as an args array and passes it to the super call. This is necessary for inheritance to work properly. + * // Trait constructors cannot have typed arguments of their own, they only serve to run logic during object instantiation. * constructor(...args: any[]) { * super(...args) * } @@ -72,6 +75,7 @@ export type UnwrapTraitC = * return this.id === el.id * } * + * // Optional * constructor(...args: any[]) { * super(...args) * } @@ -80,6 +84,25 @@ export type UnwrapTraitC = * return Identifiable * }) * ``` + * Creates a subtrait: + * ```ts + * const ImplementsIdentifiable = (defaultID: ID) => + * trait(Parent => { + * abstract class ImplementsIdentifiable extends extendsAndExpresses( + * Parent, + * [Identifiable()], + * ) { + * id: ID = defaultID + * + * // Optional + * constructor(...args: any[]) { + * super(...args) + * } + * } + * + * return ImplementsIdentifiable + * }) + * ``` */ export function trait< C extends AbstractClass diff --git a/src/tests.ts b/src/tests.ts index 30e12c5..bb49d1f 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -21,7 +21,10 @@ const Identifiable = () => const ImplementsIdentifiable = (defaultID: ID) => trait(Parent => { - abstract class ImplementsIdentifiable extends extendsAndExpresses(Parent, [Identifiable()]) { + abstract class ImplementsIdentifiable extends extendsAndExpresses( + Parent, + [Identifiable()], + ) { id: ID = defaultID constructor(...args: any[]) { -- 2.49.1 From a428980d837f7ad18a078befedbb776ae1279b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sat, 30 Dec 2023 00:38:01 +0100 Subject: [PATCH 4/4] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index af08db8..66b5586 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@thilawyn/thilatrait", - "version": "20231229.0.0", + "version": "20231230.0.0", "type": "module", "publishConfig": { "registry": "https://git.jvalver.de/api/packages/thilawyn/npm/" -- 2.49.1