Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
export declare const baseTarget: (proto?: object | null) => any;
export declare const baseTarget: (_proto?: object) => any;
export declare const SymbolTypeomaticaProxyReference: unique symbol;
export declare const BaseConstructorPrototype: {
new (): unknown;
(): void;
new <T extends object | {}>(_target?: T): T;
<T extends object | {}, S extends T>(_target?: S extends infer S_1 ? S_1 : {}): S;
};
export declare class BaseClass<T extends object, S extends T> {
constructor(_target: S extends T ? S : never);
}
interface ITypeDefinition<T> {
new (): T;
(): void;
export declare class BaseClass {
constructor(_target?: object);
}
export declare const SymbolInitialValue: symbol;
export declare const Strict: <P extends object>(_target?: P | null) => <T extends ITypeDefinition<T>, M extends P & InstanceType<T>, IR extends { [key in keyof M]: M[key]; }>(cstr: T) => IR;
export {};
export declare const Strict: (_target?: object) => <T>(cstr: T) => T;
9 changes: 5 additions & 4 deletions lib/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typeomatica",
"version": "0.3.5",
"version": "0.3.55",
"description": "type logic against javascript metaprogramming",
"engines": {
"node": ">=16"
Expand Down
64 changes: 12 additions & 52 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ import {

import { FieldConstructor } from './fields';

// type Proto<P, T> = Pick<P, Exclude<keyof P, keyof T>> & T;
// type FlatProto<P, T, S = Proto<P, T>> = {
// [key in keyof S]: S[key]
// }


const resolver = Object.entries({
primitives,
special,
Expand Down Expand Up @@ -158,7 +152,8 @@ const handlers = {
Object.freeze(handlers);

// user have to precisely define all props
export const baseTarget = (proto: object | null = null) => {
export const baseTarget = (_proto?: object) => {
const proto = typeof _proto === 'object' ? _proto : null;
const answer = Object.create(proto);
return answer;
};
Expand All @@ -177,28 +172,7 @@ const getTypeomaticaProxyReference = (_target: object) => {
};


export const BaseConstructorPrototype = function <
T extends object,
M extends {
[SymbolTypeomaticaProxyReference]: number
},
K extends {
[key in keyof T]: T[key]
},
S extends {
(): void
new(): K
},
L extends M & T,
O extends {},
R extends {
(): S
new(): T extends L ? L : T | {}
}
>(
this: O extends M ? M : O,
_target: T | null = null
): M extends M ? M : R {
export const BaseConstructorPrototype = function <T extends object, S extends T>(this: S extends T ? S : {}, _target?: T ): T {
if (!new.target) {

const self: {
Expand Down Expand Up @@ -263,8 +237,8 @@ export const BaseConstructorPrototype = function <
return this;

} as {
new(): unknown
(): void
new<T extends object | {}>(_target?: T): T
<T extends object | {}, S extends T>(_target?: S extends infer S ? S : {}): S
};

Object.defineProperty(module, 'exports', {
Expand All @@ -274,8 +248,8 @@ Object.defineProperty(module, 'exports', {
enumerable: true
});

export class BaseClass<T extends object, S extends T> {
constructor(_target: S extends T ? S : never) {
export class BaseClass {
constructor(_target?: object) {
// @ts-ignore
if (this[SymbolTypeomaticaProxyReference]) {
return this;
Expand Down Expand Up @@ -305,37 +279,23 @@ export class BaseClass<T extends object, S extends T> {
}
}

interface ITypeDefinition<T> {
new(): T,
(): void
}

// interface IType<T, P> extends ITypeDefinition<T> {
// new(...args: unknown[]): FlatProto<P, T>
// }


const strict = function <P extends object>(_target: P | null = null) {
const decorator = function <
T extends ITypeDefinition<T>,
// S extends { [key in keyof P]: P[key] },
// R extends IType<S, T>,
M extends P & InstanceType<T>,
IR extends { [key in keyof M]: M[key] }
>(cstr: T): IR {
const strict = function (_target?: object) {
const decorator = function<T>(cstr: T): T {

// @ts-ignore
if (cstr.prototype[SymbolTypeomaticaProxyReference]) {
return cstr as unknown as IR;
return cstr;
}

const target = baseTarget(_target);
const proxy = getTypeomaticaProxyReference(target);
const _replacer = Object.create(proxy);

// @ts-ignore
Object.setPrototypeOf(cstr.prototype, _replacer);

return cstr as unknown as IR;
return cstr;


// const MyClassProxy = new Proxy(cstr, {
Expand Down
2 changes: 2 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// oxlint-disable no-unused-expressions
// oxlint-disable typescript/no-this-alias
/* eslint-disable no-debugger */

'use strict';
import { describe, expect, test } from '@jest/globals';

Expand Down Expand Up @@ -789,6 +790,7 @@ describe('coverage: ', () => {
expect(cov4.hidden).toBeTruthy();
expect(cov4.passed).toBeTruthy();


@Strict(hiddenValues)
class CovCLS5 {
starter = 5;
Expand Down
26 changes: 17 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@
"target": "es6",
"strict": true,
"alwaysStrict": true,
"strictFunctionTypes": true,

"esModuleInterop": false,
"allowSyntheticDefaultImports": false,

"declaration": true,
"diagnostics": true,
"noImplicitThis": true,
"experimentalDecorators": true,
"extendedDiagnostics": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"inlineSourceMap": true,
"inlineSources": true,

"isolatedModules": true,

"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"inlineSourceMap": true,
"inlineSources": true,
"outDir": "lib",
"traceResolution": false,
"removeComments": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"traceResolution": false,
"types": ["node"]
},
"include": [
Expand Down