@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.cjs +68 -156
- package/lib/index.d.cts +94 -1007
- package/lib/index.d.ts +94 -1007
- package/lib/index.js +68 -156
- package/package.json +4 -4
package/lib/index.cjs
CHANGED
|
@@ -122,9 +122,7 @@ __name(hasOwnProperty, "hasOwnProperty");
|
|
|
122
122
|
|
|
123
123
|
// ../object/src/hasPrototypeChainProperty.ts
|
|
124
124
|
function hasPrototypeChainProperty(object, key) {
|
|
125
|
-
return getClassChain(object).some((ctor) =>
|
|
126
|
-
return hasOwnProperty(ctor.prototype, key);
|
|
127
|
-
});
|
|
125
|
+
return getClassChain(object).some((ctor) => hasOwnProperty(ctor.prototype, key));
|
|
128
126
|
}
|
|
129
127
|
__name(hasPrototypeChainProperty, "hasPrototypeChainProperty");
|
|
130
128
|
|
|
@@ -140,16 +138,12 @@ function OptionsConfigurator(schemaOrProps, defaultKeys) {
|
|
|
140
138
|
const schema = typebox.KindGuard.IsObject(schemaOrProps) ? schemaOrProps : typebox.Type.Object(props);
|
|
141
139
|
const defaults = entriesOf(props).reduce((acc, [key, prop]) => {
|
|
142
140
|
if ("default" in prop) {
|
|
143
|
-
Reflect.set(acc, key, typeof prop.default === "function" ? prop.default : () =>
|
|
144
|
-
return prop.default;
|
|
145
|
-
});
|
|
141
|
+
Reflect.set(acc, key, typeof prop.default === "function" ? prop.default : () => prop.default);
|
|
146
142
|
}
|
|
147
143
|
return acc;
|
|
148
144
|
}, {});
|
|
149
145
|
const requiredKeys = schema.required;
|
|
150
|
-
const optionalKeys = keysOf(props).filter((k) =>
|
|
151
|
-
return !requiredKeys.includes(k);
|
|
152
|
-
});
|
|
146
|
+
const optionalKeys = keysOf(props).filter((k) => !requiredKeys.includes(k));
|
|
153
147
|
const create = createConfigurator({
|
|
154
148
|
defaults,
|
|
155
149
|
requiredKeys,
|
|
@@ -160,27 +154,13 @@ function OptionsConfigurator(schemaOrProps, defaultKeys) {
|
|
|
160
154
|
const options = callback(builder);
|
|
161
155
|
return options;
|
|
162
156
|
}, "build");
|
|
163
|
-
build.getSchemaProps = () =>
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
build.
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
build.
|
|
170
|
-
return defaults;
|
|
171
|
-
};
|
|
172
|
-
build.getDefaultKeys = () => {
|
|
173
|
-
return defaultKeys;
|
|
174
|
-
};
|
|
175
|
-
build.cast = (v) => {
|
|
176
|
-
return v;
|
|
177
|
-
};
|
|
178
|
-
build.getCreate = () => {
|
|
179
|
-
return create;
|
|
180
|
-
};
|
|
181
|
-
build.getBuild = () => {
|
|
182
|
-
return build;
|
|
183
|
-
};
|
|
157
|
+
build.getSchemaProps = () => props;
|
|
158
|
+
build.getSchema = () => schema;
|
|
159
|
+
build.getDefaults = () => defaults;
|
|
160
|
+
build.getDefaultKeys = () => defaultKeys;
|
|
161
|
+
build.cast = (v) => v;
|
|
162
|
+
build.getCreate = () => create;
|
|
163
|
+
build.getBuild = () => build;
|
|
184
164
|
build.createFunction = (func) => {
|
|
185
165
|
function fn(arg0) {
|
|
186
166
|
const options = typeof arg0 === "function" ? build(arg0) : value.Value.Default(schema, arg0);
|
|
@@ -202,32 +182,30 @@ function OptionsConfigurator(schemaOrProps, defaultKeys) {
|
|
|
202
182
|
});
|
|
203
183
|
return fn;
|
|
204
184
|
};
|
|
205
|
-
build.createBaseClass = () => {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
};
|
|
185
|
+
build.createBaseClass = () => class Base {
|
|
186
|
+
static {
|
|
187
|
+
__name(this, "Base");
|
|
188
|
+
}
|
|
189
|
+
static get OptionsConfigurator() {
|
|
190
|
+
return build;
|
|
191
|
+
}
|
|
192
|
+
options;
|
|
193
|
+
constructor(arg0) {
|
|
194
|
+
this.options = typeof arg0 === "function" ? build(arg0) : value.Value.Default(schema, arg0);
|
|
195
|
+
this.initialize();
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Called by the constructor
|
|
199
|
+
*/
|
|
200
|
+
initialize() {
|
|
201
|
+
this.assertValidOptions();
|
|
202
|
+
}
|
|
203
|
+
isValidOptions() {
|
|
204
|
+
return value.Value.Check(schema, this.options);
|
|
205
|
+
}
|
|
206
|
+
assertValidOptions() {
|
|
207
|
+
assertValidSchema(schema, this.options, "Invalid options");
|
|
208
|
+
}
|
|
231
209
|
};
|
|
232
210
|
return build;
|
|
233
211
|
}
|
|
@@ -352,34 +330,18 @@ __name(inheritProxifiedPrototypeProperty, "inheritProxifiedPrototypeProperty");
|
|
|
352
330
|
|
|
353
331
|
// src/inheritProxifiedPrototype.ts
|
|
354
332
|
function inheritProxifiedPrototype(ViewerClass, TargetClass, omitKeys) {
|
|
355
|
-
Reflect.ownKeys(TargetClass.prototype).filter((k) =>
|
|
356
|
-
return k !== "constructor" && k !== Symbol.toStringTag;
|
|
357
|
-
}).filter((k) => {
|
|
358
|
-
return omitKeys ? !omitKeys.includes(k) : true;
|
|
359
|
-
}).forEach((k) => {
|
|
360
|
-
return inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, k);
|
|
361
|
-
});
|
|
333
|
+
Reflect.ownKeys(TargetClass.prototype).filter((k) => k !== "constructor" && k !== Symbol.toStringTag).filter((k) => omitKeys ? !omitKeys.includes(k) : true).forEach((k) => inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, k));
|
|
362
334
|
return ViewerClass;
|
|
363
335
|
}
|
|
364
336
|
__name(inheritProxifiedPrototype, "inheritProxifiedPrototype");
|
|
365
337
|
|
|
366
338
|
// src/inspector/defaults/ignoreValuesFilterDefaults.ts
|
|
367
339
|
var ignoreValuesFilterDefaults = {
|
|
368
|
-
noFalse: /* @__PURE__ */ __name((value) =>
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}, "noNull"),
|
|
374
|
-
noUndefined: /* @__PURE__ */ __name((value) => {
|
|
375
|
-
return value !== void 0;
|
|
376
|
-
}, "noUndefined"),
|
|
377
|
-
noEmptyArray: /* @__PURE__ */ __name((value) => {
|
|
378
|
-
return !Array.isArray(value) || !!value.length;
|
|
379
|
-
}, "noEmptyArray"),
|
|
380
|
-
noEmptyObject: /* @__PURE__ */ __name((value) => {
|
|
381
|
-
return !value || typeof value !== "object" || Array.isArray(value) || !!Object.keys(value).length;
|
|
382
|
-
}, "noEmptyObject")
|
|
340
|
+
noFalse: /* @__PURE__ */ __name((value) => value !== false, "noFalse"),
|
|
341
|
+
noNull: /* @__PURE__ */ __name((value) => value !== null, "noNull"),
|
|
342
|
+
noUndefined: /* @__PURE__ */ __name((value) => value !== void 0, "noUndefined"),
|
|
343
|
+
noEmptyArray: /* @__PURE__ */ __name((value) => !Array.isArray(value) || !!value.length, "noEmptyArray"),
|
|
344
|
+
noEmptyObject: /* @__PURE__ */ __name((value) => !value || typeof value !== "object" || Array.isArray(value) || !!Object.keys(value).length, "noEmptyObject")
|
|
383
345
|
};
|
|
384
346
|
|
|
385
347
|
// src/inspector/defaults/ignoreValuesDefaults.ts
|
|
@@ -490,62 +452,34 @@ var Inspector = class _Inspector extends View {
|
|
|
490
452
|
const options = this.mergePrototypeOptions();
|
|
491
453
|
const keys = new Set(options.keys);
|
|
492
454
|
if (options.autoAddBooleanKeys) {
|
|
493
|
-
const insBooleanValueKeys = Object.entries(this.target).filter(([_key, value]) =>
|
|
494
|
-
return typeof value === "boolean";
|
|
495
|
-
}).map(([key]) => {
|
|
496
|
-
return key;
|
|
497
|
-
});
|
|
455
|
+
const insBooleanValueKeys = Object.entries(this.target).filter(([_key, value]) => typeof value === "boolean").map(([key]) => key);
|
|
498
456
|
const protoGetterKeys = getClassChain(this.target, {
|
|
499
457
|
includeSelf: false
|
|
500
|
-
}).map((cls) =>
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
});
|
|
504
|
-
}).flat(2);
|
|
505
|
-
const booleanKeys = insBooleanValueKeys.concat(protoGetterKeys).filter((key) => {
|
|
506
|
-
return /^(is|was|has|should)[A-Z]/.test(key);
|
|
507
|
-
});
|
|
508
|
-
booleanKeys.forEach((key) => {
|
|
509
|
-
return keys.add(key);
|
|
510
|
-
});
|
|
458
|
+
}).map((cls) => Object.getOwnPropertyNames(cls.prototype).filter((key) => hasOwnProperty(Reflect.getOwnPropertyDescriptor(cls.prototype, key), "get"))).flat(2);
|
|
459
|
+
const booleanKeys = insBooleanValueKeys.concat(protoGetterKeys).filter((key) => /^(is|was|has|should)[A-Z]/.test(key));
|
|
460
|
+
booleanKeys.forEach((key) => keys.add(key));
|
|
511
461
|
}
|
|
512
|
-
const ignoreFilters = Object.entries(options.ignoreValues).filter(([_name, enabled]) =>
|
|
513
|
-
return enabled;
|
|
514
|
-
}).map(([name]) => {
|
|
515
|
-
return ignoreValuesFilterDefaults[name];
|
|
516
|
-
});
|
|
462
|
+
const ignoreFilters = Object.entries(options.ignoreValues).filter(([_name, enabled]) => enabled).map(([name]) => ignoreValuesFilterDefaults[name]);
|
|
517
463
|
const objectValues = [];
|
|
518
464
|
const arrayValues = [];
|
|
519
465
|
for (const key of keys) {
|
|
520
466
|
const value = this.target[key];
|
|
521
|
-
if (!ignoreFilters.every((filter) => {
|
|
522
|
-
return filter(value);
|
|
523
|
-
})) {
|
|
467
|
+
if (!ignoreFilters.every((filter) => filter(value))) {
|
|
524
468
|
continue;
|
|
525
469
|
}
|
|
526
|
-
if (!options.filters.every((filter) => {
|
|
527
|
-
return filter.call(this.target, value, key, depth, output);
|
|
528
|
-
})) {
|
|
470
|
+
if (!options.filters.every((filter) => filter.call(this.target, value, key, depth, output))) {
|
|
529
471
|
continue;
|
|
530
472
|
}
|
|
531
473
|
if (Array.isArray(value)) {
|
|
532
|
-
arrayValues.push(() =>
|
|
533
|
-
return defineValue(output, key, value);
|
|
534
|
-
});
|
|
474
|
+
arrayValues.push(() => defineValue(output, key, value));
|
|
535
475
|
} else if (compat.isObjectLike(value)) {
|
|
536
|
-
objectValues.push(() =>
|
|
537
|
-
return defineValue(output, key, value);
|
|
538
|
-
});
|
|
476
|
+
objectValues.push(() => defineValue(output, key, value));
|
|
539
477
|
} else {
|
|
540
478
|
defineValue(output, key, value);
|
|
541
479
|
}
|
|
542
480
|
}
|
|
543
|
-
objectValues.forEach((fn) =>
|
|
544
|
-
|
|
545
|
-
});
|
|
546
|
-
arrayValues.forEach((fn) => {
|
|
547
|
-
return fn();
|
|
548
|
-
});
|
|
481
|
+
objectValues.forEach((fn) => fn());
|
|
482
|
+
arrayValues.forEach((fn) => fn());
|
|
549
483
|
return {
|
|
550
484
|
output,
|
|
551
485
|
inspectOptions: options.inspect
|
|
@@ -565,9 +499,7 @@ var Inspector = class _Inspector extends View {
|
|
|
565
499
|
const customFilters = defaults.filters;
|
|
566
500
|
const prototypeChainOptions = getClassChain(this.target.constructor, {
|
|
567
501
|
includeSelf: true
|
|
568
|
-
}).reverse().map((cls) => {
|
|
569
|
-
return cls.inspector ?? {};
|
|
570
|
-
});
|
|
502
|
+
}).reverse().map((cls) => cls.inspector ?? {});
|
|
571
503
|
for (const options of prototypeChainOptions) {
|
|
572
504
|
if (options.inspect) {
|
|
573
505
|
inspectOptions = {
|
|
@@ -575,27 +507,17 @@ var Inspector = class _Inspector extends View {
|
|
|
575
507
|
...options.inspect
|
|
576
508
|
};
|
|
577
509
|
}
|
|
578
|
-
options.keys?.forEach((elem) =>
|
|
579
|
-
return keys.add(elem);
|
|
580
|
-
});
|
|
510
|
+
options.keys?.forEach((elem) => keys.add(elem));
|
|
581
511
|
if (options.autoAddBooleanKeys != null) {
|
|
582
512
|
autoAddBooleanKeys = options.autoAddBooleanKeys;
|
|
583
513
|
}
|
|
584
|
-
keys.forEach((elem) =>
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
options.ignoreKeys?.forEach((elem) => {
|
|
588
|
-
return ignoreKeys.add(elem);
|
|
589
|
-
});
|
|
590
|
-
ignoreKeys.forEach((elem) => {
|
|
591
|
-
return keys.delete(elem);
|
|
592
|
-
});
|
|
514
|
+
keys.forEach((elem) => ignoreKeys.delete(elem));
|
|
515
|
+
options.ignoreKeys?.forEach((elem) => ignoreKeys.add(elem));
|
|
516
|
+
ignoreKeys.forEach((elem) => keys.delete(elem));
|
|
593
517
|
if (options.ignoreValues) {
|
|
594
518
|
Object.assign(ignoreValues, options.ignoreValues);
|
|
595
519
|
}
|
|
596
|
-
options.filters?.forEach((filter) =>
|
|
597
|
-
return customFilters.push(filter);
|
|
598
|
-
});
|
|
520
|
+
options.filters?.forEach((filter) => customFilters.push(filter));
|
|
599
521
|
}
|
|
600
522
|
return {
|
|
601
523
|
inspect: inspectOptions,
|
|
@@ -681,18 +603,14 @@ var ParentRelationTypes = class _ParentRelationTypes extends View {
|
|
|
681
603
|
...Array.from(this.parentTypesStats.keys())
|
|
682
604
|
]);
|
|
683
605
|
return Array.from(classes).map((cls) => {
|
|
684
|
-
const parents = Array.from(this.parentTypesStats.get(cls).multiplicities()).map(([cls2, count]) =>
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
cls2.name,
|
|
693
|
-
count
|
|
694
|
-
];
|
|
695
|
-
});
|
|
606
|
+
const parents = Array.from(this.parentTypesStats.get(cls).multiplicities()).map(([cls2, count]) => [
|
|
607
|
+
cls2.name,
|
|
608
|
+
count
|
|
609
|
+
]);
|
|
610
|
+
const children = Array.from(this.childTypesStats.get(cls).multiplicities()).map(([cls2, count]) => [
|
|
611
|
+
cls2.name,
|
|
612
|
+
count
|
|
613
|
+
]);
|
|
696
614
|
const result = {
|
|
697
615
|
class: cls.name
|
|
698
616
|
};
|
|
@@ -727,12 +645,8 @@ var ParentRelationTypes = class _ParentRelationTypes extends View {
|
|
|
727
645
|
console.log();
|
|
728
646
|
}
|
|
729
647
|
}
|
|
730
|
-
static childTypesStats = new mnemonist.DefaultMap(() =>
|
|
731
|
-
|
|
732
|
-
});
|
|
733
|
-
static parentTypesStats = new mnemonist.DefaultMap(() => {
|
|
734
|
-
return new mnemonist.MultiSet();
|
|
735
|
-
});
|
|
648
|
+
static childTypesStats = new mnemonist.DefaultMap(() => new mnemonist.MultiSet());
|
|
649
|
+
static parentTypesStats = new mnemonist.DefaultMap(() => new mnemonist.MultiSet());
|
|
736
650
|
};
|
|
737
651
|
var Parenting = class _Parenting extends View {
|
|
738
652
|
static {
|
|
@@ -807,9 +721,7 @@ var Parenting = class _Parenting extends View {
|
|
|
807
721
|
/**
|
|
808
722
|
* A WeakMap for parent references.
|
|
809
723
|
*/
|
|
810
|
-
static parentWeakRefMap = new mnemonist.DefaultMap(() =>
|
|
811
|
-
return /* @__PURE__ */ new WeakMap();
|
|
812
|
-
});
|
|
724
|
+
static parentWeakRefMap = new mnemonist.DefaultMap(() => /* @__PURE__ */ new WeakMap());
|
|
813
725
|
};
|
|
814
726
|
|
|
815
727
|
exports.Inspector = Inspector;
|