@@ -7,61 +7,45 @@ import { type InMemoryEntity } from "../in_memory";
77export type SystemInSet = Required < SystemInSetSchema > ;
88export type InSet = SystemInSet [ "inSet" ] [ 0 ] ;
99
10- type InMemoryEntityInSetSchema = ReturnType < typeof schemaMixin > ;
11-
12- function schemaMixin < E extends InMemoryEntity > ( item : E ) {
13- const schema = {
10+ export function inMemoryEntityInSetMixin < E extends InMemoryEntity > ( item : E ) {
11+ // @ts -expect-error
12+ const properties : SystemInSet & InSetPropertiesInMemoryEntity & E = {
1413 get inSet ( ) {
15- return item . prop < InSet [ ] > ( "inSet" , [ ] ) ;
14+ return this . prop < InSet [ ] > ( "inSet" , [ ] ) ;
1615 } ,
1716
1817 set inSet ( inSet : InSet [ ] ) {
19- item . setProp ( "inSet" , inSet ) ;
18+ this . setProp ( "inSet" , inSet ) ;
2019 } ,
21- } satisfies SystemInSetSchema ;
22-
23- Object . defineProperties ( item , Object . getOwnPropertyDescriptors ( schema ) ) ;
24-
25- return schema ;
26- }
2720
28- function propertiesMixin < E extends InMemoryEntity > ( item : E & InMemoryEntityInSetSchema ) {
29- const properties = {
3021 getInSetFilteredByCls ( cls : string ) {
31- return item . inSet . filter ( ( ref ) => ref . cls === cls ) ;
22+ return this . inSet . filter ( ( ref ) => ref . cls === cls ) ;
3223 } ,
3324
3425 // finds a parent entity set of the same cls (hence `cls` field is absent)
3526 // NOTE: assumes that only one entry of this kind is present => gets the first one
3627 get parentEntitySetReference ( ) {
37- return item . inSet . find ( ( item ) => item . _id && ! item . cls ) ;
28+ return this . inSet . find ( ( inSetItem ) => inSetItem . _id && ! inSetItem . cls ) ;
3829 } ,
3930 } ;
4031
4132 Object . defineProperties ( item , Object . getOwnPropertyDescriptors ( properties ) ) ;
42-
43- return properties ;
4433}
4534
46- export function inMemoryEntityInSetMixin < E extends InMemoryEntity > ( item : E ) {
47- return {
48- ...schemaMixin ( item ) ,
49- ...propertiesMixin ( item as E & InMemoryEntityInSetSchema ) ,
50- } ;
51- }
35+ export type InSetPropertiesInMemoryEntity = {
36+ getInSetFilteredByCls : ( cls : string ) => InSet [ ] ;
37+ parentEntitySetReference : InSet | undefined ;
38+ } ;
5239
53- export type InMemoryEntityInSet = ReturnType < typeof inMemoryEntityInSetMixin > ;
40+ export type InMemoryEntityInSet = SystemInSet & InSetPropertiesInMemoryEntity ;
5441export type InMemoryEntityInSetConstructor = Constructor < InMemoryEntityInSet > ;
5542
5643type Base = Constructor < InMemoryEntity > ;
5744
5845export default function InMemoryEntityInSetMixin < S extends Base = Base > ( superclass : S ) {
59- class InMemoryEntityInSetMixin extends superclass {
60- constructor ( ...args : any [ ] ) {
61- super ( ...args ) ;
62- inMemoryEntityInSetMixin ( this ) ;
63- }
64- }
46+ class InMemoryEntityInSetMixin extends superclass { }
47+
48+ inMemoryEntityInSetMixin ( InMemoryEntityInSetMixin . prototype ) ;
6549
6650 return InMemoryEntityInSetMixin as S & InMemoryEntityInSetConstructor ;
6751}
0 commit comments