@bemoje/composition 2.1.5 → 3.0.1

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.
package/lib/index.js CHANGED
@@ -116,9 +116,7 @@ __name(hasOwnProperty, "hasOwnProperty");
116
116
 
117
117
  // ../object/src/hasPrototypeChainProperty.ts
118
118
  function hasPrototypeChainProperty(object, key) {
119
- return getClassChain(object).some((ctor) => {
120
- return hasOwnProperty(ctor.prototype, key);
121
- });
119
+ return getClassChain(object).some((ctor) => hasOwnProperty(ctor.prototype, key));
122
120
  }
123
121
  __name(hasPrototypeChainProperty, "hasPrototypeChainProperty");
124
122
 
@@ -134,16 +132,12 @@ function OptionsConfigurator(schemaOrProps, defaultKeys) {
134
132
  const schema = KindGuard.IsObject(schemaOrProps) ? schemaOrProps : Type.Object(props);
135
133
  const defaults = entriesOf(props).reduce((acc, [key, prop]) => {
136
134
  if ("default" in prop) {
137
- Reflect.set(acc, key, typeof prop.default === "function" ? prop.default : () => {
138
- return prop.default;
139
- });
135
+ Reflect.set(acc, key, typeof prop.default === "function" ? prop.default : () => prop.default);
140
136
  }
141
137
  return acc;
142
138
  }, {});
143
139
  const requiredKeys = schema.required;
144
- const optionalKeys = keysOf(props).filter((k) => {
145
- return !requiredKeys.includes(k);
146
- });
140
+ const optionalKeys = keysOf(props).filter((k) => !requiredKeys.includes(k));
147
141
  const create = createConfigurator({
148
142
  defaults,
149
143
  requiredKeys,
@@ -154,27 +148,13 @@ function OptionsConfigurator(schemaOrProps, defaultKeys) {
154
148
  const options = callback(builder);
155
149
  return options;
156
150
  }, "build");
157
- build.getSchemaProps = () => {
158
- return props;
159
- };
160
- build.getSchema = () => {
161
- return schema;
162
- };
163
- build.getDefaults = () => {
164
- return defaults;
165
- };
166
- build.getDefaultKeys = () => {
167
- return defaultKeys;
168
- };
169
- build.cast = (v) => {
170
- return v;
171
- };
172
- build.getCreate = () => {
173
- return create;
174
- };
175
- build.getBuild = () => {
176
- return build;
177
- };
151
+ build.getSchemaProps = () => props;
152
+ build.getSchema = () => schema;
153
+ build.getDefaults = () => defaults;
154
+ build.getDefaultKeys = () => defaultKeys;
155
+ build.cast = (v) => v;
156
+ build.getCreate = () => create;
157
+ build.getBuild = () => build;
178
158
  build.createFunction = (func) => {
179
159
  function fn(arg0) {
180
160
  const options = typeof arg0 === "function" ? build(arg0) : Value.Default(schema, arg0);
@@ -196,32 +176,30 @@ function OptionsConfigurator(schemaOrProps, defaultKeys) {
196
176
  });
197
177
  return fn;
198
178
  };
199
- build.createBaseClass = () => {
200
- return class Base {
201
- static {
202
- __name(this, "Base");
203
- }
204
- static get OptionsConfigurator() {
205
- return build;
206
- }
207
- options;
208
- constructor(arg0) {
209
- this.options = typeof arg0 === "function" ? build(arg0) : Value.Default(schema, arg0);
210
- this.initialize();
211
- }
212
- /**
213
- * Called by the constructor
214
- */
215
- initialize() {
216
- this.assertValidOptions();
217
- }
218
- isValidOptions() {
219
- return Value.Check(schema, this.options);
220
- }
221
- assertValidOptions() {
222
- assertValidSchema(schema, this.options, "Invalid options");
223
- }
224
- };
179
+ build.createBaseClass = () => class Base {
180
+ static {
181
+ __name(this, "Base");
182
+ }
183
+ static get OptionsConfigurator() {
184
+ return build;
185
+ }
186
+ options;
187
+ constructor(arg0) {
188
+ this.options = typeof arg0 === "function" ? build(arg0) : Value.Default(schema, arg0);
189
+ this.initialize();
190
+ }
191
+ /**
192
+ * Called by the constructor
193
+ */
194
+ initialize() {
195
+ this.assertValidOptions();
196
+ }
197
+ isValidOptions() {
198
+ return Value.Check(schema, this.options);
199
+ }
200
+ assertValidOptions() {
201
+ assertValidSchema(schema, this.options, "Invalid options");
202
+ }
225
203
  };
226
204
  return build;
227
205
  }
@@ -346,34 +324,18 @@ __name(inheritProxifiedPrototypeProperty, "inheritProxifiedPrototypeProperty");
346
324
 
347
325
  // src/inheritProxifiedPrototype.ts
348
326
  function inheritProxifiedPrototype(ViewerClass, TargetClass, omitKeys) {
349
- Reflect.ownKeys(TargetClass.prototype).filter((k) => {
350
- return k !== "constructor" && k !== Symbol.toStringTag;
351
- }).filter((k) => {
352
- return omitKeys ? !omitKeys.includes(k) : true;
353
- }).forEach((k) => {
354
- return inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, k);
355
- });
327
+ Reflect.ownKeys(TargetClass.prototype).filter((k) => k !== "constructor" && k !== Symbol.toStringTag).filter((k) => omitKeys ? !omitKeys.includes(k) : true).forEach((k) => inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, k));
356
328
  return ViewerClass;
357
329
  }
358
330
  __name(inheritProxifiedPrototype, "inheritProxifiedPrototype");
359
331
 
360
332
  // src/inspector/defaults/ignoreValuesFilterDefaults.ts
361
333
  var ignoreValuesFilterDefaults = {
362
- noFalse: /* @__PURE__ */ __name((value) => {
363
- return value !== false;
364
- }, "noFalse"),
365
- noNull: /* @__PURE__ */ __name((value) => {
366
- return value !== null;
367
- }, "noNull"),
368
- noUndefined: /* @__PURE__ */ __name((value) => {
369
- return value !== void 0;
370
- }, "noUndefined"),
371
- noEmptyArray: /* @__PURE__ */ __name((value) => {
372
- return !Array.isArray(value) || !!value.length;
373
- }, "noEmptyArray"),
374
- noEmptyObject: /* @__PURE__ */ __name((value) => {
375
- return !value || typeof value !== "object" || Array.isArray(value) || !!Object.keys(value).length;
376
- }, "noEmptyObject")
334
+ noFalse: /* @__PURE__ */ __name((value) => value !== false, "noFalse"),
335
+ noNull: /* @__PURE__ */ __name((value) => value !== null, "noNull"),
336
+ noUndefined: /* @__PURE__ */ __name((value) => value !== void 0, "noUndefined"),
337
+ noEmptyArray: /* @__PURE__ */ __name((value) => !Array.isArray(value) || !!value.length, "noEmptyArray"),
338
+ noEmptyObject: /* @__PURE__ */ __name((value) => !value || typeof value !== "object" || Array.isArray(value) || !!Object.keys(value).length, "noEmptyObject")
377
339
  };
378
340
 
379
341
  // src/inspector/defaults/ignoreValuesDefaults.ts
@@ -484,62 +446,34 @@ var Inspector = class _Inspector extends View {
484
446
  const options = this.mergePrototypeOptions();
485
447
  const keys = new Set(options.keys);
486
448
  if (options.autoAddBooleanKeys) {
487
- const insBooleanValueKeys = Object.entries(this.target).filter(([_key, value]) => {
488
- return typeof value === "boolean";
489
- }).map(([key]) => {
490
- return key;
491
- });
449
+ const insBooleanValueKeys = Object.entries(this.target).filter(([_key, value]) => typeof value === "boolean").map(([key]) => key);
492
450
  const protoGetterKeys = getClassChain(this.target, {
493
451
  includeSelf: false
494
- }).map((cls) => {
495
- return Object.getOwnPropertyNames(cls.prototype).filter((key) => {
496
- return hasOwnProperty(Reflect.getOwnPropertyDescriptor(cls.prototype, key), "get");
497
- });
498
- }).flat(2);
499
- const booleanKeys = insBooleanValueKeys.concat(protoGetterKeys).filter((key) => {
500
- return /^(is|was|has|should)[A-Z]/.test(key);
501
- });
502
- booleanKeys.forEach((key) => {
503
- return keys.add(key);
504
- });
452
+ }).map((cls) => Object.getOwnPropertyNames(cls.prototype).filter((key) => hasOwnProperty(Reflect.getOwnPropertyDescriptor(cls.prototype, key), "get"))).flat(2);
453
+ const booleanKeys = insBooleanValueKeys.concat(protoGetterKeys).filter((key) => /^(is|was|has|should)[A-Z]/.test(key));
454
+ booleanKeys.forEach((key) => keys.add(key));
505
455
  }
506
- const ignoreFilters = Object.entries(options.ignoreValues).filter(([_name, enabled]) => {
507
- return enabled;
508
- }).map(([name]) => {
509
- return ignoreValuesFilterDefaults[name];
510
- });
456
+ const ignoreFilters = Object.entries(options.ignoreValues).filter(([_name, enabled]) => enabled).map(([name]) => ignoreValuesFilterDefaults[name]);
511
457
  const objectValues = [];
512
458
  const arrayValues = [];
513
459
  for (const key of keys) {
514
460
  const value = this.target[key];
515
- if (!ignoreFilters.every((filter) => {
516
- return filter(value);
517
- })) {
461
+ if (!ignoreFilters.every((filter) => filter(value))) {
518
462
  continue;
519
463
  }
520
- if (!options.filters.every((filter) => {
521
- return filter.call(this.target, value, key, depth, output);
522
- })) {
464
+ if (!options.filters.every((filter) => filter.call(this.target, value, key, depth, output))) {
523
465
  continue;
524
466
  }
525
467
  if (Array.isArray(value)) {
526
- arrayValues.push(() => {
527
- return defineValue(output, key, value);
528
- });
468
+ arrayValues.push(() => defineValue(output, key, value));
529
469
  } else if (isObjectLike(value)) {
530
- objectValues.push(() => {
531
- return defineValue(output, key, value);
532
- });
470
+ objectValues.push(() => defineValue(output, key, value));
533
471
  } else {
534
472
  defineValue(output, key, value);
535
473
  }
536
474
  }
537
- objectValues.forEach((fn) => {
538
- return fn();
539
- });
540
- arrayValues.forEach((fn) => {
541
- return fn();
542
- });
475
+ objectValues.forEach((fn) => fn());
476
+ arrayValues.forEach((fn) => fn());
543
477
  return {
544
478
  output,
545
479
  inspectOptions: options.inspect
@@ -559,9 +493,7 @@ var Inspector = class _Inspector extends View {
559
493
  const customFilters = defaults.filters;
560
494
  const prototypeChainOptions = getClassChain(this.target.constructor, {
561
495
  includeSelf: true
562
- }).reverse().map((cls) => {
563
- return cls.inspector ?? {};
564
- });
496
+ }).reverse().map((cls) => cls.inspector ?? {});
565
497
  for (const options of prototypeChainOptions) {
566
498
  if (options.inspect) {
567
499
  inspectOptions = {
@@ -569,27 +501,17 @@ var Inspector = class _Inspector extends View {
569
501
  ...options.inspect
570
502
  };
571
503
  }
572
- options.keys?.forEach((elem) => {
573
- return keys.add(elem);
574
- });
504
+ options.keys?.forEach((elem) => keys.add(elem));
575
505
  if (options.autoAddBooleanKeys != null) {
576
506
  autoAddBooleanKeys = options.autoAddBooleanKeys;
577
507
  }
578
- keys.forEach((elem) => {
579
- return ignoreKeys.delete(elem);
580
- });
581
- options.ignoreKeys?.forEach((elem) => {
582
- return ignoreKeys.add(elem);
583
- });
584
- ignoreKeys.forEach((elem) => {
585
- return keys.delete(elem);
586
- });
508
+ keys.forEach((elem) => ignoreKeys.delete(elem));
509
+ options.ignoreKeys?.forEach((elem) => ignoreKeys.add(elem));
510
+ ignoreKeys.forEach((elem) => keys.delete(elem));
587
511
  if (options.ignoreValues) {
588
512
  Object.assign(ignoreValues, options.ignoreValues);
589
513
  }
590
- options.filters?.forEach((filter) => {
591
- return customFilters.push(filter);
592
- });
514
+ options.filters?.forEach((filter) => customFilters.push(filter));
593
515
  }
594
516
  return {
595
517
  inspect: inspectOptions,
@@ -675,18 +597,14 @@ var ParentRelationTypes = class _ParentRelationTypes extends View {
675
597
  ...Array.from(this.parentTypesStats.keys())
676
598
  ]);
677
599
  return Array.from(classes).map((cls) => {
678
- const parents = Array.from(this.parentTypesStats.get(cls).multiplicities()).map(([cls2, count]) => {
679
- return [
680
- cls2.name,
681
- count
682
- ];
683
- });
684
- const children = Array.from(this.childTypesStats.get(cls).multiplicities()).map(([cls2, count]) => {
685
- return [
686
- cls2.name,
687
- count
688
- ];
689
- });
600
+ const parents = Array.from(this.parentTypesStats.get(cls).multiplicities()).map(([cls2, count]) => [
601
+ cls2.name,
602
+ count
603
+ ]);
604
+ const children = Array.from(this.childTypesStats.get(cls).multiplicities()).map(([cls2, count]) => [
605
+ cls2.name,
606
+ count
607
+ ]);
690
608
  const result = {
691
609
  class: cls.name
692
610
  };
@@ -721,12 +639,8 @@ var ParentRelationTypes = class _ParentRelationTypes extends View {
721
639
  console.log();
722
640
  }
723
641
  }
724
- static childTypesStats = new DefaultMap(() => {
725
- return new MultiSet();
726
- });
727
- static parentTypesStats = new DefaultMap(() => {
728
- return new MultiSet();
729
- });
642
+ static childTypesStats = new DefaultMap(() => new MultiSet());
643
+ static parentTypesStats = new DefaultMap(() => new MultiSet());
730
644
  };
731
645
  var Parenting = class _Parenting extends View {
732
646
  static {
@@ -801,9 +715,7 @@ var Parenting = class _Parenting extends View {
801
715
  /**
802
716
  * A WeakMap for parent references.
803
717
  */
804
- static parentWeakRefMap = new DefaultMap(() => {
805
- return /* @__PURE__ */ new WeakMap();
806
- });
718
+ static parentWeakRefMap = new DefaultMap(() => /* @__PURE__ */ new WeakMap());
807
719
  };
808
720
 
809
721
  export { Inspector, OptionsConfigurator, ParentRelationTypes, Parenting, View, ignoreValuesDefaults, ignoreValuesFilterDefaults, inheritProxifiedPrototype, inheritProxifiedPrototypeProperty, inspectDefaults, inspectorDefaults };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemoje/composition",
3
- "version": "2.1.5",
3
+ "version": "3.0.1",
4
4
  "description": "Class composition utilities for views, proxy-based inheritance, object inspection, and parent-child relationships.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -8,10 +8,10 @@
8
8
  "access": "public"
9
9
  },
10
10
  "dependencies": {
11
- "@sinclair/typebox": "^0.34.48",
11
+ "@sinclair/typebox": "^0.34.52",
12
12
  "ansi-colors": "^4.1.3",
13
- "es-toolkit": "^1.45.1",
14
- "mnemonist": "^0.40.3"
13
+ "es-toolkit": "^1.53.2",
14
+ "mnemonist": "^0.40.8"
15
15
  },
16
16
  "keywords": [
17
17
  "composition",