@bemoje/composition 2.1.2 → 2.1.5

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.
Files changed (62) hide show
  1. package/README.md +19 -35
  2. package/lib/index.cjs +823 -101
  3. package/lib/index.d.cts +2429 -16
  4. package/lib/index.d.ts +2429 -16
  5. package/lib/index.js +809 -14
  6. package/package.json +23 -209
  7. package/lib/IView.cjs +0 -2
  8. package/lib/IView.d.cts +0 -12
  9. package/lib/IView.d.ts +0 -12
  10. package/lib/IView.js +0 -1
  11. package/lib/OptionsConfigurator.cjs +0 -166
  12. package/lib/OptionsConfigurator.d.cts +0 -2229
  13. package/lib/OptionsConfigurator.d.ts +0 -2229
  14. package/lib/OptionsConfigurator.js +0 -163
  15. package/lib/View.cjs +0 -22
  16. package/lib/View.d.cts +0 -14
  17. package/lib/View.d.ts +0 -14
  18. package/lib/View.js +0 -20
  19. package/lib/inheritProxifiedPrototype.cjs +0 -19
  20. package/lib/inheritProxifiedPrototype.d.cts +0 -11
  21. package/lib/inheritProxifiedPrototype.d.ts +0 -11
  22. package/lib/inheritProxifiedPrototype.js +0 -16
  23. package/lib/inheritProxifiedPrototypeProperty.cjs +0 -45
  24. package/lib/inheritProxifiedPrototypeProperty.d.cts +0 -9
  25. package/lib/inheritProxifiedPrototypeProperty.d.ts +0 -9
  26. package/lib/inheritProxifiedPrototypeProperty.js +0 -43
  27. package/lib/inspector/Inspector.cjs +0 -227
  28. package/lib/inspector/Inspector.d.cts +0 -4
  29. package/lib/inspector/Inspector.d.ts +0 -4
  30. package/lib/inspector/Inspector.js +0 -220
  31. package/lib/inspector/defaults/ignoreValuesDefaults.cjs +0 -11
  32. package/lib/inspector/defaults/ignoreValuesDefaults.d.cts +0 -11
  33. package/lib/inspector/defaults/ignoreValuesDefaults.d.ts +0 -11
  34. package/lib/inspector/defaults/ignoreValuesDefaults.js +0 -11
  35. package/lib/inspector/defaults/ignoreValuesFilterDefaults.cjs +0 -23
  36. package/lib/inspector/defaults/ignoreValuesFilterDefaults.d.cts +0 -11
  37. package/lib/inspector/defaults/ignoreValuesFilterDefaults.d.ts +0 -11
  38. package/lib/inspector/defaults/ignoreValuesFilterDefaults.js +0 -21
  39. package/lib/inspector/defaults/inspectDefaults.cjs +0 -17
  40. package/lib/inspector/defaults/inspectDefaults.d.cts +0 -8
  41. package/lib/inspector/defaults/inspectDefaults.d.ts +0 -8
  42. package/lib/inspector/defaults/inspectDefaults.js +0 -16
  43. package/lib/inspector/defaults/inspectorDefaults.cjs +0 -15
  44. package/lib/inspector/defaults/inspectorDefaults.d.cts +0 -11
  45. package/lib/inspector/defaults/inspectorDefaults.d.ts +0 -11
  46. package/lib/inspector/defaults/inspectorDefaults.js +0 -14
  47. package/lib/inspector/types.cjs +0 -2
  48. package/lib/inspector/types.d.cts +0 -4
  49. package/lib/inspector/types.d.ts +0 -4
  50. package/lib/inspector/types.js +0 -1
  51. package/lib/parenting/ParentRelationTypes.cjs +0 -130
  52. package/lib/parenting/ParentRelationTypes.d.cts +0 -4
  53. package/lib/parenting/ParentRelationTypes.d.ts +0 -4
  54. package/lib/parenting/ParentRelationTypes.js +0 -123
  55. package/lib/parenting/Parenting.cjs +0 -88
  56. package/lib/parenting/Parenting.d.cts +0 -4
  57. package/lib/parenting/Parenting.d.ts +0 -4
  58. package/lib/parenting/Parenting.js +0 -85
  59. package/lib/parenting/types.cjs +0 -2
  60. package/lib/parenting/types.d.cts +0 -4
  61. package/lib/parenting/types.d.ts +0 -4
  62. package/lib/parenting/types.js +0 -1
package/lib/index.cjs CHANGED
@@ -1,103 +1,825 @@
1
1
  'use strict';
2
2
 
3
- var IView = require('./IView');
4
- var OptionsConfigurator = require('./OptionsConfigurator');
5
- var View = require('./View');
6
- var inheritProxifiedPrototype = require('./inheritProxifiedPrototype');
7
- var inheritProxifiedPrototypeProperty = require('./inheritProxifiedPrototypeProperty');
8
- var Inspector = require('./inspector/Inspector');
9
- var ignoreValuesDefaults = require('./inspector/defaults/ignoreValuesDefaults');
10
- var ignoreValuesFilterDefaults = require('./inspector/defaults/ignoreValuesFilterDefaults');
11
- var inspectDefaults = require('./inspector/defaults/inspectDefaults');
12
- var inspectorDefaults = require('./inspector/defaults/inspectorDefaults');
13
- var types = require('./inspector/types');
14
- var ParentRelationTypes = require('./parenting/ParentRelationTypes');
15
- var Parenting = require('./parenting/Parenting');
16
- var types$1 = require('./parenting/types');
17
-
18
-
19
-
20
- Object.keys(IView).forEach(function (k) {
21
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
22
- enumerable: true,
23
- get: function () { return IView[k]; }
24
- });
25
- });
26
- Object.keys(OptionsConfigurator).forEach(function (k) {
27
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
28
- enumerable: true,
29
- get: function () { return OptionsConfigurator[k]; }
30
- });
31
- });
32
- Object.keys(View).forEach(function (k) {
33
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
34
- enumerable: true,
35
- get: function () { return View[k]; }
36
- });
37
- });
38
- Object.keys(inheritProxifiedPrototype).forEach(function (k) {
39
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
40
- enumerable: true,
41
- get: function () { return inheritProxifiedPrototype[k]; }
42
- });
43
- });
44
- Object.keys(inheritProxifiedPrototypeProperty).forEach(function (k) {
45
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
46
- enumerable: true,
47
- get: function () { return inheritProxifiedPrototypeProperty[k]; }
48
- });
49
- });
50
- Object.keys(Inspector).forEach(function (k) {
51
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
52
- enumerable: true,
53
- get: function () { return Inspector[k]; }
54
- });
55
- });
56
- Object.keys(ignoreValuesDefaults).forEach(function (k) {
57
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
58
- enumerable: true,
59
- get: function () { return ignoreValuesDefaults[k]; }
60
- });
61
- });
62
- Object.keys(ignoreValuesFilterDefaults).forEach(function (k) {
63
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
64
- enumerable: true,
65
- get: function () { return ignoreValuesFilterDefaults[k]; }
66
- });
67
- });
68
- Object.keys(inspectDefaults).forEach(function (k) {
69
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
70
- enumerable: true,
71
- get: function () { return inspectDefaults[k]; }
72
- });
73
- });
74
- Object.keys(inspectorDefaults).forEach(function (k) {
75
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
76
- enumerable: true,
77
- get: function () { return inspectorDefaults[k]; }
78
- });
79
- });
80
- Object.keys(types).forEach(function (k) {
81
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
82
- enumerable: true,
83
- get: function () { return types[k]; }
84
- });
85
- });
86
- Object.keys(ParentRelationTypes).forEach(function (k) {
87
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
88
- enumerable: true,
89
- get: function () { return ParentRelationTypes[k]; }
90
- });
91
- });
92
- Object.keys(Parenting).forEach(function (k) {
93
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
94
- enumerable: true,
95
- get: function () { return Parenting[k]; }
96
- });
97
- });
98
- Object.keys(types$1).forEach(function (k) {
99
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
100
- enumerable: true,
101
- get: function () { return types$1[k]; }
102
- });
103
- });
3
+ var typebox = require('@sinclair/typebox');
4
+ var value = require('@sinclair/typebox/value');
5
+ var compiler = require('@sinclair/typebox/compiler');
6
+ var object = require('es-toolkit/object');
7
+ var colors2 = require('ansi-colors');
8
+ var util = require('util');
9
+ var compat = require('es-toolkit/compat');
10
+ var esToolkit = require('es-toolkit');
11
+ var mnemonist = require('mnemonist');
12
+
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
+
15
+ var colors2__default = /*#__PURE__*/_interopDefault(colors2);
16
+
17
+ var __defProp = Object.defineProperty;
18
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
19
+ var SchemaValidationError = class extends Error {
20
+ static {
21
+ __name(this, "SchemaValidationError");
22
+ }
23
+ value;
24
+ errors;
25
+ constructor(errors, value$1, message) {
26
+ super(message);
27
+ this.name = "SchemaValidationError";
28
+ this.value = value$1;
29
+ this.errors = Array.isArray(errors) ? errors : errors instanceof compiler.ValueErrorIterator ? Array.from(errors) : Array.from(value.Value.Errors(errors, value$1));
30
+ }
31
+ };
32
+ function assertValidSchema(schema, data, message) {
33
+ const isValid = value.Value.Check(schema, data);
34
+ if (!isValid) {
35
+ throw new SchemaValidationError(value.Value.Errors(schema, data), data, message);
36
+ }
37
+ }
38
+ __name(assertValidSchema, "assertValidSchema");
39
+
40
+ // ../object/src/defineGetter.ts
41
+ function defineGetter(obj, key, get, des = {}) {
42
+ return Object.defineProperty(obj, key, {
43
+ configurable: true,
44
+ enumerable: false,
45
+ get,
46
+ ...des
47
+ });
48
+ }
49
+ __name(defineGetter, "defineGetter");
50
+
51
+ // ../object/src/defineValue.ts
52
+ function defineValue(obj, key, value, des = {}) {
53
+ return Object.defineProperty(obj, key, {
54
+ configurable: true,
55
+ value,
56
+ enumerable: true,
57
+ ...des
58
+ });
59
+ }
60
+ __name(defineValue, "defineValue");
61
+
62
+ // ../object/src/defineLazyProperty.ts
63
+ function defineLazyProperty(obj, key, get, des = {}) {
64
+ function getter() {
65
+ const value = get.call(this);
66
+ defineValue(this, key, value);
67
+ return value;
68
+ }
69
+ __name(getter, "getter");
70
+ return defineGetter(obj, key, getter, des);
71
+ }
72
+ __name(defineLazyProperty, "defineLazyProperty");
73
+
74
+ // ../object/src/defineMethod.ts
75
+ function defineMethod(obj, key, value, des = {}) {
76
+ return Object.defineProperty(obj, key, {
77
+ value,
78
+ configurable: true,
79
+ writable: true,
80
+ enumerable: false,
81
+ ...des
82
+ });
83
+ }
84
+ __name(defineMethod, "defineMethod");
85
+
86
+ // ../object/src/entriesOf.ts
87
+ function entriesOf(obj) {
88
+ return Object.entries(obj);
89
+ }
90
+ __name(entriesOf, "entriesOf");
91
+
92
+ // ../object/src/keysOf.ts
93
+ function keysOf(obj) {
94
+ return Object.keys(obj);
95
+ }
96
+ __name(keysOf, "keysOf");
97
+
98
+ // ../object/src/getClassChain.ts
99
+ function getClassChain(target, options) {
100
+ const ctor = typeof target === "function" ? target : target.constructor;
101
+ const result = [];
102
+ if (options?.includeSelf) {
103
+ result.push(ctor);
104
+ }
105
+ let current = ctor;
106
+ while (current = Reflect.getPrototypeOf(current)) {
107
+ if (current === Function.prototype || current === Object.prototype) {
108
+ result.push(Object);
109
+ break;
110
+ }
111
+ result.push(current);
112
+ }
113
+ return result;
114
+ }
115
+ __name(getClassChain, "getClassChain");
116
+
117
+ // ../object/src/hasOwnProperty.ts
118
+ function hasOwnProperty(object, key) {
119
+ return Object.prototype.hasOwnProperty.call(object, key);
120
+ }
121
+ __name(hasOwnProperty, "hasOwnProperty");
122
+
123
+ // ../object/src/hasPrototypeChainProperty.ts
124
+ function hasPrototypeChainProperty(object, key) {
125
+ return getClassChain(object).some((ctor) => {
126
+ return hasOwnProperty(ctor.prototype, key);
127
+ });
128
+ }
129
+ __name(hasPrototypeChainProperty, "hasPrototypeChainProperty");
130
+
131
+ // ../object/src/hasProperty.ts
132
+ function hasProperty(object, key) {
133
+ return hasOwnProperty(object, key) || hasPrototypeChainProperty(object, key);
134
+ }
135
+ __name(hasProperty, "hasProperty");
136
+
137
+ // src/OptionsConfigurator.ts
138
+ function OptionsConfigurator(schemaOrProps, defaultKeys) {
139
+ const props = typebox.KindGuard.IsObject(schemaOrProps) ? schemaOrProps.properties : schemaOrProps;
140
+ const schema = typebox.KindGuard.IsObject(schemaOrProps) ? schemaOrProps : typebox.Type.Object(props);
141
+ const defaults = entriesOf(props).reduce((acc, [key, prop]) => {
142
+ if ("default" in prop) {
143
+ Reflect.set(acc, key, typeof prop.default === "function" ? prop.default : () => {
144
+ return prop.default;
145
+ });
146
+ }
147
+ return acc;
148
+ }, {});
149
+ const requiredKeys = schema.required;
150
+ const optionalKeys = keysOf(props).filter((k) => {
151
+ return !requiredKeys.includes(k);
152
+ });
153
+ const create = createConfigurator({
154
+ defaults,
155
+ requiredKeys,
156
+ optionalKeys
157
+ });
158
+ const build = /* @__PURE__ */ __name((callback) => {
159
+ const builder = create();
160
+ const options = callback(builder);
161
+ return options;
162
+ }, "build");
163
+ build.getSchemaProps = () => {
164
+ return props;
165
+ };
166
+ build.getSchema = () => {
167
+ return schema;
168
+ };
169
+ build.getDefaults = () => {
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
+ };
184
+ build.createFunction = (func) => {
185
+ function fn(arg0) {
186
+ const options = typeof arg0 === "function" ? build(arg0) : value.Value.Default(schema, arg0);
187
+ assertValidSchema(schema, options, "Invalid options");
188
+ return func(options);
189
+ }
190
+ __name(fn, "fn");
191
+ if (func.name) {
192
+ Object.defineProperty(fn, "name", {
193
+ value: func.name,
194
+ configurable: true
195
+ });
196
+ }
197
+ Object.defineProperty(fn, "OptionsConfigurator", {
198
+ get() {
199
+ return build;
200
+ },
201
+ enumerable: true
202
+ });
203
+ return fn;
204
+ };
205
+ build.createBaseClass = () => {
206
+ return class Base {
207
+ static {
208
+ __name(this, "Base");
209
+ }
210
+ static get OptionsConfigurator() {
211
+ return build;
212
+ }
213
+ options;
214
+ constructor(arg0) {
215
+ this.options = typeof arg0 === "function" ? build(arg0) : value.Value.Default(schema, arg0);
216
+ this.initialize();
217
+ }
218
+ /**
219
+ * Called by the constructor
220
+ */
221
+ initialize() {
222
+ this.assertValidOptions();
223
+ }
224
+ isValidOptions() {
225
+ return value.Value.Check(schema, this.options);
226
+ }
227
+ assertValidOptions() {
228
+ assertValidSchema(schema, this.options, "Invalid options");
229
+ }
230
+ };
231
+ };
232
+ return build;
233
+ }
234
+ __name(OptionsConfigurator, "OptionsConfigurator");
235
+ function createConfigurator(options) {
236
+ let CFG = class CFG {
237
+ static {
238
+ __name(this, "CFG");
239
+ }
240
+ $data;
241
+ constructor($data) {
242
+ this.$data = $data;
243
+ }
244
+ /**
245
+ * Applies defaults for missing values and then returns data.
246
+ */
247
+ done() {
248
+ this.applyDefaults();
249
+ return this.$data;
250
+ }
251
+ /**
252
+ * Set default values for missing keys.
253
+ */
254
+ applyDefaults() {
255
+ entriesOf(options.defaults).forEach(([key, dfValue]) => {
256
+ if (this.$data[key] === void 0) {
257
+ const df = dfValue?.();
258
+ if (df !== void 0) {
259
+ this.$data[key] = df;
260
+ }
261
+ }
262
+ });
263
+ return this;
264
+ }
265
+ };
266
+ const keys = /* @__PURE__ */ new Set([
267
+ ...options.requiredKeys,
268
+ ...keysOf(options.defaults),
269
+ ...options.optionalKeys
270
+ ]);
271
+ for (const key of keys) {
272
+ Object.defineProperty(CFG.prototype, key, {
273
+ value: /* @__PURE__ */ __name(function(value) {
274
+ if (value === void 0) {
275
+ if (key in options.defaults) {
276
+ this.$data[key] = options.defaults[key]();
277
+ } else {
278
+ delete this.$data[key];
279
+ }
280
+ } else {
281
+ this.$data[key] = value;
282
+ }
283
+ return new CFG(this.$data);
284
+ }, "value")
285
+ });
286
+ }
287
+ return /* @__PURE__ */ __name(function configurator() {
288
+ const ins = new CFG({});
289
+ return ins;
290
+ }, "configurator");
291
+ }
292
+ __name(createConfigurator, "createConfigurator");
293
+
294
+ // src/View.ts
295
+ var TARGET_SYMBOL = /* @__PURE__ */ Symbol("target");
296
+ var View = class {
297
+ static {
298
+ __name(this, "View");
299
+ }
300
+ [TARGET_SYMBOL];
301
+ constructor(target) {
302
+ this[TARGET_SYMBOL] = target;
303
+ }
304
+ get [Symbol.toStringTag]() {
305
+ return this.constructor.name;
306
+ }
307
+ get target() {
308
+ return this[TARGET_SYMBOL];
309
+ }
310
+ };
311
+
312
+ // src/inheritProxifiedPrototypeProperty.ts
313
+ function inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, key) {
314
+ const des = Reflect.getOwnPropertyDescriptor(TargetClass.prototype, key);
315
+ if (!des) {
316
+ return;
317
+ }
318
+ if (des.value && typeof des.value === "function") {
319
+ return Object.defineProperty(ViewerClass.prototype, key, {
320
+ value(...args) {
321
+ return this.target[key](...args);
322
+ },
323
+ writable: true,
324
+ configurable: true,
325
+ enumerable: false
326
+ });
327
+ } else if (des && !des.get && !des.set) {
328
+ return Object.defineProperty(ViewerClass.prototype, key, {
329
+ get() {
330
+ return this.target[key];
331
+ },
332
+ set: des.writable ? /* @__PURE__ */ __name(function set(value) {
333
+ this.target[key] = value;
334
+ }, "set") : void 0,
335
+ configurable: true,
336
+ enumerable: false
337
+ });
338
+ } else {
339
+ Object.defineProperty(ViewerClass.prototype, key, {
340
+ get: des.get ? function() {
341
+ return this.target[key];
342
+ } : void 0,
343
+ set: des.set ? function(value) {
344
+ this.target[key] = value;
345
+ } : void 0,
346
+ configurable: true,
347
+ enumerable: false
348
+ });
349
+ }
350
+ }
351
+ __name(inheritProxifiedPrototypeProperty, "inheritProxifiedPrototypeProperty");
352
+
353
+ // src/inheritProxifiedPrototype.ts
354
+ 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
+ });
362
+ return ViewerClass;
363
+ }
364
+ __name(inheritProxifiedPrototype, "inheritProxifiedPrototype");
365
+
366
+ // src/inspector/defaults/ignoreValuesFilterDefaults.ts
367
+ var ignoreValuesFilterDefaults = {
368
+ noFalse: /* @__PURE__ */ __name((value) => {
369
+ return value !== false;
370
+ }, "noFalse"),
371
+ noNull: /* @__PURE__ */ __name((value) => {
372
+ return value !== null;
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")
383
+ };
384
+
385
+ // src/inspector/defaults/ignoreValuesDefaults.ts
386
+ var ignoreValuesDefaults = {
387
+ noEmptyArray: true,
388
+ noEmptyObject: true,
389
+ noNull: true,
390
+ noUndefined: true,
391
+ noFalse: false
392
+ };
393
+ var inspectDefaults = {
394
+ ...util.inspect.defaultOptions,
395
+ customInspect: true,
396
+ maxStringLength: 500,
397
+ maxArrayLength: 200,
398
+ breakLength: 100,
399
+ colors: true,
400
+ depth: 100,
401
+ compact: false,
402
+ numericSeparator: true
403
+ };
404
+
405
+ // src/inspector/defaults/inspectorDefaults.ts
406
+ var inspectorDefaults = {
407
+ inspect: inspectDefaults,
408
+ ignoreValues: ignoreValuesDefaults,
409
+ keys: [],
410
+ autoAddBooleanKeys: false,
411
+ ignoreKeys: [],
412
+ filters: []
413
+ };
414
+ var Inspector = class _Inspector extends View {
415
+ static {
416
+ __name(this, "Inspector");
417
+ }
418
+ /**
419
+ * Composes a class with Inspector capabilities by adding inspection methods to its prototype.
420
+ * This follows the Composition pattern to extend classes without inheritance.
421
+ */
422
+ static compose(cls, options = {}) {
423
+ if (!hasProperty(cls.prototype, util.inspect.custom)) {
424
+ defineMethod(cls.prototype, util.inspect.custom, function(depth, options2) {
425
+ return this.inspector.inspect(depth, options2);
426
+ });
427
+ }
428
+ if (!hasProperty(cls.prototype, "inspector")) {
429
+ defineLazyProperty(cls.prototype, "inspector", /* @__PURE__ */ __name(function get() {
430
+ return new _Inspector(this);
431
+ }, "get"));
432
+ }
433
+ if (!hasProperty(cls.prototype, "toJSON")) {
434
+ defineMethod(cls.prototype, "toJSON", function() {
435
+ return this.inspector.toObject();
436
+ });
437
+ }
438
+ return options;
439
+ }
440
+ /**
441
+ * Compile the target object and return the output as an object.
442
+ */
443
+ toObject(depth = 0) {
444
+ const result = esToolkit.mapValues(this.compile(depth).output, (value) => {
445
+ if (!value) {
446
+ return value;
447
+ }
448
+ if (typeof value !== "object") {
449
+ return value;
450
+ }
451
+ if (Array.isArray(value)) {
452
+ return value.map((v) => {
453
+ if (v.inspector && v.inspector instanceof _Inspector) {
454
+ return v.inspector.toObject(depth + 1);
455
+ }
456
+ return v;
457
+ });
458
+ }
459
+ if (value.inspector && value.inspector instanceof _Inspector) {
460
+ return value.inspector.toObject(depth + 1);
461
+ }
462
+ return value;
463
+ });
464
+ return {
465
+ T: this.target.constructor.name,
466
+ ...result
467
+ };
468
+ }
469
+ /**
470
+ * Inspect the target object.
471
+ */
472
+ inspect(depth = 0, options = {}) {
473
+ const { output, inspectOptions } = this.compile(depth);
474
+ Object.assign(inspectOptions, options);
475
+ const result = util.inspect(output, options);
476
+ return result.replaceAll(/Object \[\w+] {/gm, (match) => {
477
+ match = match.substring(8, match.length - 3);
478
+ return `[${inspectOptions.colors ? colors2__default.default.magenta(match) : match}] {`;
479
+ });
480
+ }
481
+ /**
482
+ * Compiles the output object and inspect options.
483
+ * Merges prototype chain options and applies filters to determine which properties to include.
484
+ */
485
+ compile(depth = 0) {
486
+ const output = Object.defineProperty({}, Symbol.toStringTag, {
487
+ value: this.target.constructor.name,
488
+ configurable: true
489
+ });
490
+ const options = this.mergePrototypeOptions();
491
+ const keys = new Set(options.keys);
492
+ 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
+ });
498
+ const protoGetterKeys = getClassChain(this.target, {
499
+ includeSelf: false
500
+ }).map((cls) => {
501
+ return Object.getOwnPropertyNames(cls.prototype).filter((key) => {
502
+ return hasOwnProperty(Reflect.getOwnPropertyDescriptor(cls.prototype, key), "get");
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
+ });
511
+ }
512
+ const ignoreFilters = Object.entries(options.ignoreValues).filter(([_name, enabled]) => {
513
+ return enabled;
514
+ }).map(([name]) => {
515
+ return ignoreValuesFilterDefaults[name];
516
+ });
517
+ const objectValues = [];
518
+ const arrayValues = [];
519
+ for (const key of keys) {
520
+ const value = this.target[key];
521
+ if (!ignoreFilters.every((filter) => {
522
+ return filter(value);
523
+ })) {
524
+ continue;
525
+ }
526
+ if (!options.filters.every((filter) => {
527
+ return filter.call(this.target, value, key, depth, output);
528
+ })) {
529
+ continue;
530
+ }
531
+ if (Array.isArray(value)) {
532
+ arrayValues.push(() => {
533
+ return defineValue(output, key, value);
534
+ });
535
+ } else if (compat.isObjectLike(value)) {
536
+ objectValues.push(() => {
537
+ return defineValue(output, key, value);
538
+ });
539
+ } else {
540
+ defineValue(output, key, value);
541
+ }
542
+ }
543
+ objectValues.forEach((fn) => {
544
+ return fn();
545
+ });
546
+ arrayValues.forEach((fn) => {
547
+ return fn();
548
+ });
549
+ return {
550
+ output,
551
+ inspectOptions: options.inspect
552
+ };
553
+ }
554
+ /**
555
+ * Walks the prototype chain and merges Inspector options from all classes.
556
+ * Subclass options override superclass options following inheritance semantics.
557
+ */
558
+ mergePrototypeOptions() {
559
+ const defaults = this.getDefaults();
560
+ let inspectOptions = defaults.inspect;
561
+ const keys = new Set(defaults.keys);
562
+ let autoAddBooleanKeys = defaults.autoAddBooleanKeys;
563
+ const ignoreKeys = new Set(defaults.ignoreKeys);
564
+ const ignoreValues = defaults.ignoreValues;
565
+ const customFilters = defaults.filters;
566
+ const prototypeChainOptions = getClassChain(this.target.constructor, {
567
+ includeSelf: true
568
+ }).reverse().map((cls) => {
569
+ return cls.inspector ?? {};
570
+ });
571
+ for (const options of prototypeChainOptions) {
572
+ if (options.inspect) {
573
+ inspectOptions = {
574
+ ...inspectOptions,
575
+ ...options.inspect
576
+ };
577
+ }
578
+ options.keys?.forEach((elem) => {
579
+ return keys.add(elem);
580
+ });
581
+ if (options.autoAddBooleanKeys != null) {
582
+ autoAddBooleanKeys = options.autoAddBooleanKeys;
583
+ }
584
+ keys.forEach((elem) => {
585
+ return ignoreKeys.delete(elem);
586
+ });
587
+ options.ignoreKeys?.forEach((elem) => {
588
+ return ignoreKeys.add(elem);
589
+ });
590
+ ignoreKeys.forEach((elem) => {
591
+ return keys.delete(elem);
592
+ });
593
+ if (options.ignoreValues) {
594
+ Object.assign(ignoreValues, options.ignoreValues);
595
+ }
596
+ options.filters?.forEach((filter) => {
597
+ return customFilters.push(filter);
598
+ });
599
+ }
600
+ return {
601
+ inspect: inspectOptions,
602
+ ignoreValues,
603
+ autoAddBooleanKeys,
604
+ keys: Array.from(keys),
605
+ ignoreKeys: Array.from(ignoreKeys),
606
+ filters: customFilters
607
+ };
608
+ }
609
+ /**
610
+ * Returns a deep clone of the default Inspector options.
611
+ */
612
+ getDefaults() {
613
+ const filters = inspectorDefaults.filters.slice();
614
+ const rest = object.cloneDeep(compat.omit(inspectorDefaults, "filters"));
615
+ return {
616
+ ...rest,
617
+ filters
618
+ };
619
+ }
620
+ };
621
+ var ParentRelationTypes = class _ParentRelationTypes extends View {
622
+ static {
623
+ __name(this, "ParentRelationTypes");
624
+ }
625
+ registerParent(parentType) {
626
+ _ParentRelationTypes.parentTypesStats.get(this.target).add(parentType);
627
+ _ParentRelationTypes.childTypesStats.get(parentType).add(this.target);
628
+ }
629
+ get hasParent() {
630
+ return _ParentRelationTypes.parentTypesStats.has(this.target);
631
+ }
632
+ get getParentTypes() {
633
+ return _ParentRelationTypes.parentTypesStats.get(this.target);
634
+ }
635
+ get hasChildren() {
636
+ return _ParentRelationTypes.childTypesStats.has(this.target);
637
+ }
638
+ get getChildTypes() {
639
+ return _ParentRelationTypes.childTypesStats.get(this.target);
640
+ }
641
+ get isRoot() {
642
+ return !this.hasParent && this.hasChildren;
643
+ }
644
+ get isLeaf() {
645
+ return this.hasParent && !this.hasChildren;
646
+ }
647
+ get isIsolated() {
648
+ return !this.hasParent && !this.hasChildren;
649
+ }
650
+ static getAllChildTypesStats() {
651
+ const res = {};
652
+ Array.from(this.childTypesStats.entries()).map(([cls, multimap]) => {
653
+ multimap.forEachMultiplicity((count, key) => {
654
+ if (!res[cls.name]) {
655
+ res[cls.name] = {};
656
+ }
657
+ if (!res[cls.name][key.name]) {
658
+ res[cls.name][key.name] = count;
659
+ }
660
+ });
661
+ });
662
+ return res;
663
+ }
664
+ static getAllParentTypesStats() {
665
+ const res = {};
666
+ Array.from(this.parentTypesStats.entries()).map(([cls, multimap]) => {
667
+ multimap.forEachMultiplicity((count, key) => {
668
+ if (!res[cls.name]) {
669
+ res[cls.name] = {};
670
+ }
671
+ if (!res[cls.name][key.name]) {
672
+ res[cls.name][key.name] = count;
673
+ }
674
+ });
675
+ });
676
+ return res;
677
+ }
678
+ static getAllStats() {
679
+ const classes = /* @__PURE__ */ new Set([
680
+ ...Array.from(this.childTypesStats.keys()),
681
+ ...Array.from(this.parentTypesStats.keys())
682
+ ]);
683
+ return Array.from(classes).map((cls) => {
684
+ const parents = Array.from(this.parentTypesStats.get(cls).multiplicities()).map(([cls2, count]) => {
685
+ return [
686
+ cls2.name,
687
+ count
688
+ ];
689
+ });
690
+ const children = Array.from(this.childTypesStats.get(cls).multiplicities()).map(([cls2, count]) => {
691
+ return [
692
+ cls2.name,
693
+ count
694
+ ];
695
+ });
696
+ const result = {
697
+ class: cls.name
698
+ };
699
+ if (parents.length) {
700
+ result.parents = Object.fromEntries(parents);
701
+ }
702
+ if (children.length) {
703
+ result.children = Object.fromEntries(children);
704
+ }
705
+ return result;
706
+ });
707
+ }
708
+ static printAllStats() {
709
+ console.log();
710
+ console.log(colors2__default.default.bold.yellow("Parent-Child Relation Stats"));
711
+ for (const stats of this.getAllStats()) {
712
+ console.log(stats.class);
713
+ if (stats.parents) {
714
+ let prefix = ` ${colors2__default.default.dim("parents : ")}`;
715
+ for (const [parent, count] of Object.entries(stats.parents)) {
716
+ console.log(`${prefix}${colors2__default.default.blue(parent)}: ${colors2__default.default.yellow(String(count))}`);
717
+ prefix = " ".repeat(12);
718
+ }
719
+ }
720
+ if (stats.children) {
721
+ let prefix = ` ${colors2__default.default.dim("children : ")}`;
722
+ for (const [child, count] of Object.entries(stats.children)) {
723
+ console.log(`${prefix}${colors2__default.default.green(child)}: ${colors2__default.default.yellow(String(count))}`);
724
+ prefix = " ".repeat(12);
725
+ }
726
+ }
727
+ console.log();
728
+ }
729
+ }
730
+ static childTypesStats = new mnemonist.DefaultMap(() => {
731
+ return new mnemonist.MultiSet();
732
+ });
733
+ static parentTypesStats = new mnemonist.DefaultMap(() => {
734
+ return new mnemonist.MultiSet();
735
+ });
736
+ };
737
+ var Parenting = class _Parenting extends View {
738
+ static {
739
+ __name(this, "Parenting");
740
+ }
741
+ /**
742
+ * Class decorator to register and correctly initialize a class as a 'parentingTarget'.
743
+ */
744
+ static compose(cls) {
745
+ if (!hasProperty(cls, "parenting")) {
746
+ defineLazyProperty(cls, "parenting", function() {
747
+ return new ParentRelationTypes(this);
748
+ });
749
+ }
750
+ if (!hasProperty(cls.prototype, "parenting")) {
751
+ defineLazyProperty(cls.prototype, "parenting", function() {
752
+ return new _Parenting(this);
753
+ });
754
+ }
755
+ }
756
+ /**
757
+ * Store a weak refences to the target object's parent.
758
+ */
759
+ onInstance(parent) {
760
+ if (!parent) {
761
+ return;
762
+ }
763
+ const targetClass = this.parentingTargetConstructor;
764
+ _Parenting.parentWeakRefMap.get(targetClass).set(this.target, parent);
765
+ targetClass.parenting?.registerParent(parent.constructor);
766
+ }
767
+ /**
768
+ * Retrieve the parent object of 'target' object.
769
+ */
770
+ getParent() {
771
+ const map = _Parenting.parentWeakRefMap.get(this.parentingTargetConstructor);
772
+ const parent = map.get(this.target);
773
+ return parent;
774
+ }
775
+ /**
776
+ * Recursively get parent until no parent is found or a circular reference is detected.
777
+ */
778
+ *iterateAncestors() {
779
+ let node = this.target.parenting.getParent();
780
+ if (!node) {
781
+ return;
782
+ }
783
+ const seen = /* @__PURE__ */ new Set();
784
+ while (node) {
785
+ if (seen.has(node)) {
786
+ return;
787
+ }
788
+ seen.add(node);
789
+ yield node;
790
+ node = node?.parenting?.getParent();
791
+ }
792
+ }
793
+ /**
794
+ * The depth of the object in the parent-child hierarchy.
795
+ */
796
+ get depth() {
797
+ return [
798
+ ...this.iterateAncestors()
799
+ ].length;
800
+ }
801
+ /**
802
+ * The class constructor of the target object.
803
+ */
804
+ get parentingTargetConstructor() {
805
+ return this.target.constructor;
806
+ }
807
+ /**
808
+ * A WeakMap for parent references.
809
+ */
810
+ static parentWeakRefMap = new mnemonist.DefaultMap(() => {
811
+ return /* @__PURE__ */ new WeakMap();
812
+ });
813
+ };
814
+
815
+ exports.Inspector = Inspector;
816
+ exports.OptionsConfigurator = OptionsConfigurator;
817
+ exports.ParentRelationTypes = ParentRelationTypes;
818
+ exports.Parenting = Parenting;
819
+ exports.View = View;
820
+ exports.ignoreValuesDefaults = ignoreValuesDefaults;
821
+ exports.ignoreValuesFilterDefaults = ignoreValuesFilterDefaults;
822
+ exports.inheritProxifiedPrototype = inheritProxifiedPrototype;
823
+ exports.inheritProxifiedPrototypeProperty = inheritProxifiedPrototypeProperty;
824
+ exports.inspectDefaults = inspectDefaults;
825
+ exports.inspectorDefaults = inspectorDefaults;