20231230.0.0 #6
@@ -23,7 +23,7 @@ local build_step = {
|
|||||||
local pack_step = {
|
local pack_step = {
|
||||||
name: "pack",
|
name: "pack",
|
||||||
image: node_image,
|
image: node_image,
|
||||||
commands: ["npm pack"],
|
commands: ["npm pack --dry-run"],
|
||||||
};
|
};
|
||||||
|
|
||||||
local publish_step = {
|
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",
|
"name": "@thilawyn/thilatrait",
|
||||||
"version": "20231229.0.0",
|
"version": "20231230.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://git.jvalver.de/api/packages/thilawyn/npm/"
|
"registry": "https://git.jvalver.de/api/packages/thilawyn/npm/"
|
||||||
},
|
},
|
||||||
|
"files": [
|
||||||
|
"./dist"
|
||||||
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"import": {
|
"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.
|
* Represents the static members of a class.
|
||||||
* @template C - The class type.
|
* @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[] = []
|
* static readonly defaultPermissions: string[] = []
|
||||||
* permissions: 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[]) {
|
* constructor(...args: any[]) {
|
||||||
* super(...args)
|
* super(...args)
|
||||||
* }
|
* }
|
||||||
@@ -70,6 +75,7 @@ export type UnwrapTraitC<T> =
|
|||||||
* return this.id === el.id
|
* return this.id === el.id
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
|
* // Optional
|
||||||
* constructor(...args: any[]) {
|
* constructor(...args: any[]) {
|
||||||
* super(...args)
|
* super(...args)
|
||||||
* }
|
* }
|
||||||
@@ -78,6 +84,25 @@ export type UnwrapTraitC<T> =
|
|||||||
* return Identifiable
|
* 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<
|
export function trait<
|
||||||
C extends AbstractClass<any>
|
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>() =>
|
const Identifiable = <ID>() =>
|
||||||
@@ -21,8 +21,16 @@ const Identifiable = <ID>() =>
|
|||||||
|
|
||||||
const ImplementsIdentifiable = <ID>(defaultID: ID) =>
|
const ImplementsIdentifiable = <ID>(defaultID: ID) =>
|
||||||
trait(Parent => {
|
trait(Parent => {
|
||||||
abstract class ImplementsIdentifiable extends Identifiable<ID>()(Parent) {
|
abstract class ImplementsIdentifiable extends extendsAndExpresses(
|
||||||
|
Parent,
|
||||||
|
[Identifiable<ID>()],
|
||||||
|
) {
|
||||||
id: ID = defaultID
|
id: ID = defaultID
|
||||||
|
|
||||||
|
constructor(...args: any[]) {
|
||||||
|
super(...args)
|
||||||
|
console.log("ImplementsIdentifiable constructor")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ImplementsIdentifiable
|
return ImplementsIdentifiable
|
||||||
|
|||||||
Reference in New Issue
Block a user