Skip to content

Commit

Permalink
chore: update TS types
Browse files Browse the repository at this point in the history
  • Loading branch information
k0stik committed Dec 14, 2024
1 parent d77ba96 commit 6894ec8
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 78 deletions.
19 changes: 10 additions & 9 deletions dist/js/entity/mixins/props.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type ConsistencyCheck } from "@mat3ra/esse/dist/js/types";
import { InMemoryEntityConstructor } from "../in_memory";
export declare function DefaultableMixin<T extends InMemoryEntityConstructor>(superclass: T): {
import type { Constructor } from "../../utils/types";
import { type InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";
export declare function DefaultableMixin<T extends Constructor<InMemoryEntity> = Constructor<InMemoryEntity>>(superclass: T): {
new (...args: any[]): {
readonly isDefault: boolean;
_json: import("@mat3ra/esse/dist/js/esse/types").AnyObject;
Expand All @@ -19,7 +20,7 @@ export declare function DefaultableMixin<T extends InMemoryEntityConstructor>(su
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
Expand Down Expand Up @@ -50,7 +51,7 @@ export declare function TaggableMixin<T extends InMemoryEntityConstructor>(super
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
Expand Down Expand Up @@ -78,7 +79,7 @@ export declare function HasScopeTrackMixin<T extends InMemoryEntityConstructor>(
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
Expand Down Expand Up @@ -107,7 +108,7 @@ export declare function HasMetadataMixin<T extends InMemoryEntityConstructor>(su
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
Expand Down Expand Up @@ -136,7 +137,7 @@ export declare function HasDescriptionMixin<T extends InMemoryEntityConstructor>
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
Expand Down Expand Up @@ -165,7 +166,7 @@ export declare function NamedEntityMixin<T extends InMemoryEntityConstructor>(su
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
Expand Down Expand Up @@ -194,7 +195,7 @@ export declare function HasConsistencyChecksMixin<T extends InMemoryEntityConstr
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
Expand Down
95 changes: 88 additions & 7 deletions dist/js/entity/other.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export declare const NamedDefaultableInMemoryEntity: {
readonly defaultConfig: object | null;
createDefault(): any;
} & typeof InMemoryEntity;
declare const HasMetadataNamedDefaultableInMemoryEntity_base: {
export declare const HasMetadataNamedDefaultableInMemoryEntity: {
new (...args: any[]): {
metadata: object;
updateMetadata(object: object): void;
Expand Down Expand Up @@ -204,9 +204,7 @@ declare const HasMetadataNamedDefaultableInMemoryEntity_base: {
readonly defaultConfig: object | null;
createDefault(): any;
} & typeof InMemoryEntity;
export declare class HasMetadataNamedDefaultableInMemoryEntity extends HasMetadataNamedDefaultableInMemoryEntity_base {
}
declare const HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity_base: {
export declare const HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity: {
new (...args: any[]): {
consistencyChecks: import("@mat3ra/esse/dist/js/types").ConsistencyCheck[];
addConsistencyChecks(array: import("@mat3ra/esse/dist/js/types").ConsistencyCheck[]): void;
Expand Down Expand Up @@ -234,9 +232,92 @@ declare const HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity_base
readonly slug: string;
readonly isSystemEntity: boolean;
};
} & typeof HasMetadataNamedDefaultableInMemoryEntity;
export declare class HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity extends HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity_base {
}
} & {
new (...args: any[]): {
metadata: object;
updateMetadata(object: object): void;
_json: import("@mat3ra/esse/dist/js/esse/types").AnyObject;
prop<T = undefined>(name: string, defaultValue: T): T;
prop<T = undefined>(name: string): T | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any;
toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
clone(extraContext?: object): /*elided*/ any;
validate(): void;
clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
isValid(): boolean;
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
systemName: string;
readonly slug: string;
readonly isSystemEntity: boolean;
};
} & {
new (...args: any[]): {
name: string;
setName(name: string): void;
_json: import("@mat3ra/esse/dist/js/esse/types").AnyObject;
prop<T = undefined>(name: string, defaultValue: T): T;
prop<T = undefined>(name: string): T | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any;
toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
clone(extraContext?: object): /*elided*/ any;
validate(): void;
clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
isValid(): boolean;
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
systemName: string;
readonly slug: string;
readonly isSystemEntity: boolean;
};
} & {
new (...args: any[]): {
readonly isDefault: boolean;
_json: import("@mat3ra/esse/dist/js/esse/types").AnyObject;
prop<T = undefined>(name: string, defaultValue: T): T;
prop<T = undefined>(name: string): T | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any;
toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
clone(extraContext?: object): /*elided*/ any;
validate(): void;
clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
isValid(): boolean;
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
systemName: string;
readonly slug: string;
readonly isSystemEntity: boolean;
};
readonly defaultConfig: object | null;
createDefault(): any;
} & typeof InMemoryEntity;
export declare const NamedDefaultableRepetitionImportantSettingsInMemoryEntity: {
new (...args: any[]): {
readonly important: any;
Expand Down
8 changes: 2 additions & 6 deletions dist/js/entity/other.js

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

41 changes: 1 addition & 40 deletions dist/js/entity/set.d.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,7 @@
import { InMemoryEntity } from "./in_memory";
declare const InMemoryEntitySet_base: {
new (...args: any[]): {
containsEntity<T extends {
inSet: import("./set/mixins").InSet[];
getInSetFilteredByCls(cls: string): {
_id: string;
cls?: string;
slug?: string;
type?: string;
index?: number;
}[];
readonly parentEntitySetReference: {
_id: string;
cls?: string;
slug?: string;
type?: string;
index?: number;
} | undefined;
_json: import("@mat3ra/esse/dist/js/esse/types").AnyObject;
prop<T_1 = undefined>(name: string, defaultValue: T_1): T_1;
prop<T_1 = undefined>(name: string): T_1 | undefined;
setProp(name: string, value: unknown): void;
unsetProp(name: string): void;
setProps(json?: import("@mat3ra/esse/dist/js/esse/types").AnyObject): /*elided*/ any;
toJSON(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
toJSONSafe(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
toJSONQuick(exclude?: string[]): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
clone(extraContext?: object): /*elided*/ any;
validate(): void;
clean(config: import("@mat3ra/esse/dist/js/esse/types").AnyObject): import("@mat3ra/esse/dist/js/esse/types").AnyObject;
isValid(): boolean;
readonly cls: string;
getClsName(): string;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: InMemoryEntity[], entity: string, name: string): InMemoryEntity;
id: string;
_id: string;
schemaVersion: string;
systemName: string;
readonly slug: string;
readonly isSystemEntity: boolean;
} & InMemoryEntity>(entity?: T | undefined): boolean | undefined;
containsEntity<T extends import("@mat3ra/esse/dist/js/types").SystemInSetSchema>(entity?: T | undefined): boolean;
_json: import("@mat3ra/esse/dist/js/esse/types").AnyObject;
prop<T = undefined>(name: string, defaultValue: T): T;
prop<T = undefined>(name: string): T | undefined;
Expand Down
4 changes: 1 addition & 3 deletions dist/js/entity/set/mixins.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ export declare function InMemoryEntityInSetMixin<T extends InMemoryEntityConstru
readonly isSystemEntity: boolean;
};
} & T;
type BaseEntityInSet = InstanceType<ReturnType<typeof InMemoryEntityInSetMixin>>;
export declare function InMemoryEntitySetMixin<T extends InMemoryEntityConstructor>(superclass: T): {
new (...args: any[]): {
containsEntity<T_1 extends BaseEntityInSet>(entity?: T_1 | undefined): boolean | undefined;
containsEntity<T_1 extends SystemInSetSchema>(entity?: T_1 | undefined): boolean;
_json: import("@mat3ra/esse/dist/js/esse/types").AnyObject;
prop<T_1 = undefined>(name: string, defaultValue: T_1): T_1;
prop<T_1 = undefined>(name: string): T_1 | undefined;
Expand All @@ -73,4 +72,3 @@ export declare function InMemoryEntitySetMixin<T extends InMemoryEntityConstruct
readonly isSystemEntity: boolean;
};
} & T;
export {};
3 changes: 2 additions & 1 deletion dist/js/entity/set/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function InMemoryEntityInSetMixin(superclass) {
function InMemoryEntitySetMixin(superclass) {
return class InMemoryEntitySetMixin extends superclass {
containsEntity(entity) {
return entity === null || entity === void 0 ? void 0 : entity.inSet.some((ref) => ref._id === this.id);
var _a;
return Boolean((_a = entity === null || entity === void 0 ? void 0 : entity.inSet) === null || _a === void 0 ? void 0 : _a.some((ref) => ref._id === this.id));
}
};
}
2 changes: 2 additions & 0 deletions dist/js/utils/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type Constructor<T> = new (...args: any[]) => T;
export type AbstractConstructor<T> = abstract new (...args: any[]) => T;
2 changes: 2 additions & 0 deletions dist/js/utils/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 1 addition & 1 deletion src/js/entity/in_memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class InMemoryEntity implements BaseInMemoryEntitySchema {
}
}

static get cls() {
static get cls(): string {
return this.prototype.constructor.name;
}

Expand Down
7 changes: 5 additions & 2 deletions src/js/entity/mixins/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import {
type NameEntitySchema,
} from "@mat3ra/esse/dist/js/types";

import { InMemoryEntityConstructor } from "../in_memory";
import type { Constructor } from "../../utils/types";
import { type InMemoryEntity, InMemoryEntityConstructor } from "../in_memory";

export function DefaultableMixin<T extends InMemoryEntityConstructor>(superclass: T) {
export function DefaultableMixin<
T extends Constructor<InMemoryEntity> = Constructor<InMemoryEntity>,
>(superclass: T) {
class DefaultableMixin extends superclass implements DefaultableEntitySchema {
get isDefault() {
return this.prop("isDefault", false);
Expand Down
9 changes: 4 additions & 5 deletions src/js/entity/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ export const NamedInMemoryEntity = NamedEntityMixin(InMemoryEntity);

export const NamedDefaultableInMemoryEntity = NamedEntityMixin(DefaultableMixin(InMemoryEntity));

export class HasMetadataNamedDefaultableInMemoryEntity extends HasMetadataMixin(
export const HasMetadataNamedDefaultableInMemoryEntity = HasMetadataMixin(
NamedEntityMixin(DefaultableMixin(InMemoryEntity)),
) {}
);

export class HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity extends HasConsistencyChecksMixin(
HasMetadataNamedDefaultableInMemoryEntity,
) {}
export const HasConsistencyChecksHasMetadataNamedDefaultableInMemoryEntity =
HasConsistencyChecksMixin(HasMetadataNamedDefaultableInMemoryEntity);

export const NamedDefaultableRepetitionImportantSettingsInMemoryEntity =
ImportantSettingsProviderMixin(
Expand Down
6 changes: 2 additions & 4 deletions src/js/entity/set/mixins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ export function InMemoryEntityInSetMixin<T extends InMemoryEntityConstructor>(su
};
}

type BaseEntityInSet = InstanceType<ReturnType<typeof InMemoryEntityInSetMixin>>;

export function InMemoryEntitySetMixin<T extends InMemoryEntityConstructor>(superclass: T) {
return class InMemoryEntitySetMixin extends superclass {
containsEntity<T extends BaseEntityInSet>(entity?: T) {
return entity?.inSet.some((ref) => ref._id === this.id);
containsEntity<T extends SystemInSetSchema>(entity?: T) {
return Boolean(entity?.inSet?.some((ref) => ref._id === this.id));
}
};
}
4 changes: 4 additions & 0 deletions src/js/utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
export type Constructor<T> = new (...args: any[]) => T;

export type AbstractConstructor<T> = abstract new (...args: any[]) => T;

0 comments on commit 6894ec8

Please sign in to comment.