From 9a84c5973118392322f2f24fde7de4053f165b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sat, 30 Dec 2023 00:40:56 +0100 Subject: [PATCH] 20231230.0.0 (#6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes subtraiting Co-authored-by: Julien Valverdé Reviewed-on: https://git.jvalver.de/Thilawyn/thilatrait/pulls/6 --- .drone.jsonnet | 2 +- .npmignore | 10 ---------- package.json | 5 ++++- src/index.ts | 27 ++++++++++++++++++++++++++- src/tests.ts | 12 ++++++++++-- 5 files changed, 41 insertions(+), 15 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..66b5586 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,13 @@ { "name": "@thilawyn/thilatrait", - "version": "20231229.0.0", + "version": "20231230.0.0", "type": "module", "publishConfig": { "registry": "https://git.jvalver.de/api/packages/thilawyn/npm/" }, + "files": [ + "./dist" + ], "exports": { ".": { "import": { diff --git a/src/index.ts b/src/index.ts index fc70958..8351eca 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] +} /** @@ -51,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) * } @@ -70,6 +75,7 @@ export type UnwrapTraitC = * return this.id === el.id * } * + * // Optional * constructor(...args: any[]) { * super(...args) * } @@ -78,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 37e9412..bb49d1f 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,16 @@ 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