20231230.0.0 #6
@@ -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 = {
|
||||
|
||||
10
.npmignore
10
.npmignore
@@ -1,10 +0,0 @@
|
||||
/node_modules/
|
||||
/src/
|
||||
/.drone.jsonnet
|
||||
/.gitignore
|
||||
/.npmignore
|
||||
/bun.lockb
|
||||
/README.md
|
||||
/rollup.config.js
|
||||
/tsconfig.json
|
||||
/tsconfig.tsbuildinfo
|
||||
@@ -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": {
|
||||
|
||||
27
src/index.ts
27
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<C> = Pick<C, keyof C>
|
||||
export type StaticMembers<C> = {
|
||||
[Key in keyof C as Key extends "prototype" ? never : Key]: C[Key]
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,6 +53,9 @@ export type UnwrapTraitC<T> =
|
||||
* 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<T> =
|
||||
* return this.id === el.id
|
||||
* }
|
||||
*
|
||||
* // Optional
|
||||
* constructor(...args: any[]) {
|
||||
* super(...args)
|
||||
* }
|
||||
@@ -78,6 +84,25 @@ export type UnwrapTraitC<T> =
|
||||
* return Identifiable
|
||||
* })
|
||||
* ```
|
||||
* Creates a subtrait:
|
||||
* ```ts
|
||||
* const ImplementsIdentifiable = <ID>(defaultID: ID) =>
|
||||
* trait(Parent => {
|
||||
* abstract class ImplementsIdentifiable extends extendsAndExpresses(
|
||||
* Parent,
|
||||
* [Identifiable<ID>()],
|
||||
* ) {
|
||||
* id: ID = defaultID
|
||||
*
|
||||
* // Optional
|
||||
* constructor(...args: any[]) {
|
||||
* super(...args)
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* return ImplementsIdentifiable
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
export function trait<
|
||||
C extends AbstractClass<any>
|
||||
|
||||
12
src/tests.ts
12
src/tests.ts
@@ -1,4 +1,4 @@
|
||||
import { expresses, trait } from "."
|
||||
import { expresses, extendsAndExpresses, trait } from "."
|
||||
|
||||
|
||||
const Identifiable = <ID>() =>
|
||||
@@ -21,8 +21,16 @@ const Identifiable = <ID>() =>
|
||||
|
||||
const ImplementsIdentifiable = <ID>(defaultID: ID) =>
|
||||
trait(Parent => {
|
||||
abstract class ImplementsIdentifiable extends Identifiable<ID>()(Parent) {
|
||||
abstract class ImplementsIdentifiable extends extendsAndExpresses(
|
||||
Parent,
|
||||
[Identifiable<ID>()],
|
||||
) {
|
||||
id: ID = defaultID
|
||||
|
||||
constructor(...args: any[]) {
|
||||
super(...args)
|
||||
console.log("ImplementsIdentifiable constructor")
|
||||
}
|
||||
}
|
||||
|
||||
return ImplementsIdentifiable
|
||||
|
||||
Reference in New Issue
Block a user