mnemonica 1.0.9 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,7 @@ const {
22
22
 
23
23
  // here is TypesCollection.define() method
24
24
  import {
25
- define, lookup, type TypesMap
25
+ define, lookup, type TypesMap
26
26
  } from '../../api/types';
27
27
 
28
28
  import * as hooksAPI from '../../api/hooks';
@@ -35,27 +35,27 @@ const {
35
35
 
36
36
  const typesCollections = new Map();
37
37
 
38
- const TypesCollection = function ( _config: Record<string, unknown> ) {
39
-
38
+ const TypesCollection = function (_config: Record<string, unknown>) {
39
+
40
40
  const self = this;
41
41
 
42
42
  const subtypes = new Map();
43
43
 
44
44
  // default config is less important than types collection config
45
45
  const config = defaultOptionsKeys.reduce(
46
- ( o: Record<string, unknown>, key: string ) => {
46
+ (o: Record<string, unknown>, key: string) => {
47
47
  const value = _config[ key ];
48
48
  const option = defaultOptions[ key ];
49
49
  const t_conf = typeof value;
50
50
  const t_opts = typeof option;
51
- if ( t_conf === t_opts ) {
51
+ if (t_conf === t_opts) {
52
52
  o[ key ] = value;
53
53
  } else {
54
54
  o[ key ] = option;
55
55
  }
56
56
  return o;
57
57
  },
58
- {}
58
+ {}
59
59
  );
60
60
 
61
61
  odp(
@@ -65,7 +65,7 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
65
65
  get () {
66
66
  return config;
67
67
  }
68
- }
68
+ }
69
69
  );
70
70
 
71
71
  odp(
@@ -73,13 +73,13 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
73
73
  Symbol.hasInstance,
74
74
  {
75
75
  get () {
76
- const result = ( instance: { [SymbolConstructorName]?: string } ) => {
76
+ const result = (instance: { [SymbolConstructorName]?: string }) => {
77
77
  const checkResult = instance[ SymbolConstructorName ] === MNEMONICA;
78
78
  return checkResult;
79
79
  };
80
80
  return result;
81
81
  }
82
- }
82
+ }
83
83
  );
84
84
 
85
85
  odp(
@@ -89,7 +89,7 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
89
89
  get () {
90
90
  return subtypes;
91
91
  }
92
- }
92
+ }
93
93
  );
94
94
 
95
95
  // For instanceof MNEMOSYNE
@@ -98,11 +98,11 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
98
98
  MNEMOSYNE,
99
99
  {
100
100
  get () {
101
- // returning proxy
102
- const result = typesCollections.get( self );
101
+ // returning proxy
102
+ const result = typesCollections.get(self);
103
103
  return result;
104
104
  }
105
- }
105
+ }
106
106
  );
107
107
 
108
108
  // For instanceof MNEMOSYNE
@@ -111,14 +111,14 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
111
111
  MNEMOSYNE,
112
112
  {
113
113
  get () {
114
- // returning proxy
115
- const result = typesCollections.get( self );
114
+ // returning proxy
115
+ const result = typesCollections.get(self);
116
116
  return result;
117
117
  }
118
- }
118
+ }
119
119
  );
120
120
 
121
- const hooks = Object.create( null );
121
+ const hooks = Object.create(null);
122
122
  odp(
123
123
  this,
124
124
  'hooks',
@@ -126,7 +126,7 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
126
126
  get () {
127
127
  return hooks;
128
128
  }
129
- }
129
+ }
130
130
  );
131
131
 
132
132
  } as _Internal_TC_<object>;
@@ -136,10 +136,10 @@ odp(
136
136
  MNEMONICA,
137
137
  {
138
138
  get () {
139
- const result = typesCollections.get( this );
139
+ const result = typesCollections.get(this);
140
140
  return result;
141
141
  }
142
- }
142
+ }
143
143
  );
144
144
 
145
145
  odp(
@@ -154,7 +154,7 @@ odp(
154
154
  constructHandlerOrConfig?: CallableFunction | object,
155
155
  config?: object
156
156
  ) {
157
- // this - define function of mnemonica interface
157
+ // this - define function of mnemonica interface
158
158
  const defineResult = define.call(
159
159
  this as unknown,
160
160
  subtypes as TypesMap,
@@ -167,7 +167,7 @@ odp(
167
167
  return result;
168
168
  },
169
169
  enumerable : true
170
- }
170
+ }
171
171
  );
172
172
 
173
173
  odp(
@@ -180,15 +180,15 @@ odp(
180
180
  TypeNestedPath: string
181
181
  ) {
182
182
  const lookupResult = lookup.call(
183
- this.subtypes as unknown as TypesMap,
184
- TypeNestedPath
183
+ this.subtypes as unknown as TypesMap,
184
+ TypeNestedPath
185
185
  );
186
186
  return lookupResult;
187
- }.bind( this );
187
+ }.bind(this);
188
188
  return result;
189
189
  },
190
190
  enumerable : true
191
- }
191
+ }
192
192
  );
193
193
 
194
194
  odp(
@@ -196,21 +196,21 @@ odp(
196
196
  'registerHook',
197
197
  {
198
198
  get (this: TypesCollection) {
199
-
199
+
200
200
  const self = this;
201
- const result = function ( hookName: string, hookCallback: hook ) {
202
- // return proto.registerHook.call( typesCollections.get( self ), hookName, hookCallback );
201
+ const result = function (hookName: string, hookCallback: hook) {
202
+ // return proto.registerHook.call( typesCollections.get( self ), hookName, hookCallback );
203
203
  const hookResult = registerHook.call(
204
204
  self,
205
205
  hookName,
206
- hookCallback
206
+ hookCallback
207
207
  );
208
208
  return hookResult;
209
- }.bind( this );
209
+ }.bind(this);
210
210
  return result;
211
211
  },
212
212
  enumerable : true
213
- }
213
+ }
214
214
  );
215
215
 
216
216
  odp(
@@ -218,17 +218,17 @@ odp(
218
218
  'invokeHook',
219
219
  {
220
220
  get (this: TypesCollection) {
221
- const result = ( hookName: string, opts: { [index: string]: unknown } ) => {
221
+ const result = (hookName: string, opts: { [index: string]: unknown }) => {
222
222
  const hookResult = invokeHook.call(
223
- typesCollections.get( this ),
223
+ typesCollections.get(this),
224
224
  hookName,
225
- opts as hooksOpts
225
+ opts as hooksOpts
226
226
  );
227
227
  return hookResult;
228
228
  };
229
229
  return result;
230
230
  }
231
- }
231
+ }
232
232
  );
233
233
 
234
234
  odp(
@@ -236,16 +236,16 @@ odp(
236
236
  'registerFlowChecker',
237
237
  {
238
238
  get (this: TypesCollection) {
239
- const result = ( flowCheckerCallback: () => unknown ) => {
239
+ const result = (flowCheckerCallback: () => unknown) => {
240
240
  const checkerResult = registerFlowChecker.call(
241
- typesCollections.get( this ),
242
- flowCheckerCallback
241
+ typesCollections.get(this),
242
+ flowCheckerCallback
243
243
  );
244
244
  return checkerResult;
245
245
  };
246
246
  return result;
247
247
  }
248
- }
248
+ }
249
249
  );
250
250
 
251
251
 
@@ -255,57 +255,57 @@ interface TypesCollectionTarget {
255
255
  }
256
256
 
257
257
  const typesCollectionProxyHandler = {
258
- get ( target: TypesCollectionTarget, prop: string ) {
259
- if ( target.subtypes.has( prop ) ) {
258
+ get (target: TypesCollectionTarget, prop: string) {
259
+ if (target.subtypes.has(prop)) {
260
260
  // access to subtype
261
261
  // for new call or defining new type
262
- const subtypeResult = target.subtypes.get( prop );
262
+ const subtypeResult = target.subtypes.get(prop);
263
263
  return subtypeResult;
264
264
  }
265
- if ( prop === 'define' ) {
265
+ if (prop === 'define') {
266
266
  // will hopefully define new type
267
267
  return target.define;
268
268
  }
269
269
  const reflectResult = Reflect.get(
270
270
  target,
271
- prop
271
+ prop
272
272
  );
273
273
  return reflectResult;
274
274
  },
275
- set ( target: TypesCollectionTarget, TypeName: string, Constructor: FunctionConstructor ) {
275
+ set (target: TypesCollectionTarget, TypeName: string, Constructor: FunctionConstructor) {
276
276
  target.define(
277
277
  TypeName,
278
- Constructor
278
+ Constructor
279
279
  );
280
280
  return true;
281
281
  },
282
282
  // Object.prototype.hasOwnProperty.call
283
- getOwnPropertyDescriptor ( target: TypesCollectionTarget, prop: string ) {
284
- if ( target.subtypes.has( prop ) ) {
283
+ getOwnPropertyDescriptor (target: TypesCollectionTarget, prop: string) {
284
+ if (target.subtypes.has(prop)) {
285
285
  const descriptorResult = {
286
286
  configurable : true,
287
287
  enumerable : true,
288
288
  writable : false,
289
- value : target.subtypes.get( prop )
289
+ value : target.subtypes.get(prop)
290
290
  };
291
291
  return descriptorResult;
292
292
  }
293
- const ownPropResult = Reflect.getOwnPropertyDescriptor( target, prop );
293
+ const ownPropResult = Reflect.getOwnPropertyDescriptor(target, prop);
294
294
  return ownPropResult;
295
295
  }
296
296
  };
297
297
 
298
- const createTypesCollection = ( config: Record<string, unknown> = {} ) => {
298
+ const createTypesCollection = (config: Record<string, unknown> = {}) => {
299
299
 
300
- const typesCollection = new TypesCollection( config );
300
+ const typesCollection = new TypesCollection(config);
301
301
  const typesCollectionProxy = new Proxy(
302
302
  typesCollection,
303
- typesCollectionProxyHandler
303
+ typesCollectionProxyHandler
304
304
  );
305
305
 
306
306
  typesCollections.set(
307
307
  typesCollection,
308
- typesCollectionProxy
308
+ typesCollectionProxy
309
309
  );
310
310
 
311
311
  return typesCollectionProxy;
@@ -320,13 +320,18 @@ odp(
320
320
  get () {
321
321
  return true;
322
322
  }
323
- }
323
+ }
324
324
  );
325
325
 
326
326
  export const types = {
327
327
  get createTypesCollection (): CreateTypesCollectionFunction {
328
- const result = function ( config: Record<string, unknown> = {} ): TypesCollection {
329
- const collectionResult = createTypesCollection( config ) as TypesCollection;
328
+ const result = <
329
+ T extends object = {},
330
+ Parent extends object = object
331
+ > (
332
+ config: Record<string, unknown> = {}
333
+ ): TypesCollection<T, Parent> => {
334
+ const collectionResult = createTypesCollection(config) as TypesCollection<T, Parent>;
330
335
  return collectionResult;
331
336
  };
332
337
  return result;
package/src/index.ts CHANGED
@@ -25,11 +25,25 @@ export const {
25
25
  } = TypesUtils;
26
26
 
27
27
  export type {
28
- IDEF, TypeConstructor, TypeConstructorBase,
29
- InstanceOfTypeRegistry, LiteralKeysOf, ParentPath, PathOfInstance,
30
- AllParentPrefixes, ParentPathOfInstance,
31
- _Internal_TC_, Proto, ProtoFlat,
32
- hooksOpts, hook, hooksTypes, TypesCollection
28
+ IDEF,
29
+ TypeConstructor,
30
+ TypeConstructorBase,
31
+ Proto,
32
+ ProtoFlat,
33
+ constructorOptions,
34
+ hooksOpts,
35
+ hook,
36
+ hooksTypes,
37
+ IDefinitorInstance,
38
+ InstanceResult,
39
+ Merge,
40
+ Constructor,
41
+ DecoratedClass,
42
+ TypeClass,
43
+ TypeAbsorber,
44
+ TypesCollection,
45
+ TypeLookup,
46
+ MnemonicaModule,
33
47
  } from './types';
34
48
 
35
49
  /**