@bemoje/composition 2.0.1 → 2.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.
- package/lib/IView.cjs +2 -0
- package/lib/IView.d.cts +12 -0
- package/lib/IView.d.ts +12 -0
- package/lib/IView.js +1 -0
- package/lib/OptionsConfigurator.cjs +166 -0
- package/lib/OptionsConfigurator.d.cts +2229 -0
- package/lib/OptionsConfigurator.d.ts +2229 -0
- package/lib/OptionsConfigurator.js +163 -0
- package/lib/View.cjs +22 -0
- package/lib/View.d.cts +14 -0
- package/lib/View.d.ts +14 -0
- package/lib/View.js +20 -0
- package/lib/index.cjs +103 -0
- package/lib/index.d.cts +16 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +14 -0
- package/lib/inheritProxifiedPrototype.cjs +19 -0
- package/lib/inheritProxifiedPrototype.d.cts +11 -0
- package/lib/inheritProxifiedPrototype.d.ts +11 -0
- package/lib/inheritProxifiedPrototype.js +16 -0
- package/lib/inheritProxifiedPrototypeProperty.cjs +45 -0
- package/lib/inheritProxifiedPrototypeProperty.d.cts +9 -0
- package/lib/inheritProxifiedPrototypeProperty.d.ts +9 -0
- package/lib/inheritProxifiedPrototypeProperty.js +43 -0
- package/lib/inspector/Inspector.cjs +227 -0
- package/lib/inspector/Inspector.d.cts +4 -0
- package/lib/inspector/Inspector.d.ts +4 -0
- package/lib/inspector/Inspector.js +220 -0
- package/lib/inspector/defaults/ignoreValuesDefaults.cjs +11 -0
- package/lib/inspector/defaults/ignoreValuesDefaults.d.cts +11 -0
- package/lib/inspector/defaults/ignoreValuesDefaults.d.ts +11 -0
- package/lib/inspector/defaults/ignoreValuesDefaults.js +11 -0
- package/lib/inspector/defaults/ignoreValuesFilterDefaults.cjs +23 -0
- package/lib/inspector/defaults/ignoreValuesFilterDefaults.d.cts +11 -0
- package/lib/inspector/defaults/ignoreValuesFilterDefaults.d.ts +11 -0
- package/lib/inspector/defaults/ignoreValuesFilterDefaults.js +21 -0
- package/lib/inspector/defaults/inspectDefaults.cjs +17 -0
- package/lib/inspector/defaults/inspectDefaults.d.cts +8 -0
- package/lib/inspector/defaults/inspectDefaults.d.ts +8 -0
- package/lib/inspector/defaults/inspectDefaults.js +16 -0
- package/lib/inspector/defaults/inspectorDefaults.cjs +15 -0
- package/lib/inspector/defaults/inspectorDefaults.d.cts +11 -0
- package/lib/inspector/defaults/inspectorDefaults.d.ts +11 -0
- package/lib/inspector/defaults/inspectorDefaults.js +14 -0
- package/lib/inspector/types.cjs +2 -0
- package/lib/inspector/types.d.cts +4 -0
- package/lib/inspector/types.d.ts +4 -0
- package/lib/inspector/types.js +1 -0
- package/lib/parenting/ParentRelationTypes.cjs +130 -0
- package/lib/parenting/ParentRelationTypes.d.cts +4 -0
- package/lib/parenting/ParentRelationTypes.d.ts +4 -0
- package/lib/parenting/ParentRelationTypes.js +123 -0
- package/lib/parenting/Parenting.cjs +88 -0
- package/lib/parenting/Parenting.d.cts +4 -0
- package/lib/parenting/Parenting.d.ts +4 -0
- package/lib/parenting/Parenting.js +85 -0
- package/lib/parenting/types.cjs +2 -0
- package/lib/parenting/types.d.cts +4 -0
- package/lib/parenting/types.d.ts +4 -0
- package/lib/parenting/types.js +1 -0
- package/package.json +239 -21
- package/index.d.ts +0 -193
- package/index.mjs +0 -628
package/lib/IView.cjs
ADDED
package/lib/IView.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for a View that wraps a target object.
|
|
3
|
+
* View methods are redirected to the wrapped object which acts as
|
|
4
|
+
* a surrogate 'this'.
|
|
5
|
+
*
|
|
6
|
+
* To create a method that redirects to 'target', @see {@link defineProxifiedPrototypeProperty}
|
|
7
|
+
*/
|
|
8
|
+
interface IView<T extends object> {
|
|
9
|
+
readonly target: T;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type { IView };
|
package/lib/IView.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for a View that wraps a target object.
|
|
3
|
+
* View methods are redirected to the wrapped object which acts as
|
|
4
|
+
* a surrogate 'this'.
|
|
5
|
+
*
|
|
6
|
+
* To create a method that redirects to 'target', @see {@link defineProxifiedPrototypeProperty}
|
|
7
|
+
*/
|
|
8
|
+
interface IView<T extends object> {
|
|
9
|
+
readonly target: T;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type { IView };
|
package/lib/IView.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typebox = require('@sinclair/typebox');
|
|
4
|
+
var value = require('@sinclair/typebox/value');
|
|
5
|
+
var tschema = require('@mono/tschema');
|
|
6
|
+
var object = require('@mono/object');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
function OptionsConfigurator(schemaOrProps, defaultKeys) {
|
|
11
|
+
const props = typebox.KindGuard.IsObject(schemaOrProps) ? schemaOrProps.properties : schemaOrProps;
|
|
12
|
+
const schema = typebox.KindGuard.IsObject(schemaOrProps) ? schemaOrProps : typebox.Type.Object(props);
|
|
13
|
+
const defaults = object.entriesOf(props).reduce((acc, [key, prop]) => {
|
|
14
|
+
if ("default" in prop) {
|
|
15
|
+
Reflect.set(acc, key, typeof prop.default === "function" ? prop.default : () => {
|
|
16
|
+
return prop.default;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
21
|
+
const requiredKeys = schema.required;
|
|
22
|
+
const optionalKeys = object.keysOf(props).filter((k) => {
|
|
23
|
+
return !requiredKeys.includes(k);
|
|
24
|
+
});
|
|
25
|
+
const create = createConfigurator({
|
|
26
|
+
defaults,
|
|
27
|
+
requiredKeys,
|
|
28
|
+
optionalKeys
|
|
29
|
+
});
|
|
30
|
+
const build = /* @__PURE__ */ __name((callback) => {
|
|
31
|
+
const builder = create();
|
|
32
|
+
const options = callback(builder);
|
|
33
|
+
return options;
|
|
34
|
+
}, "build");
|
|
35
|
+
build.getSchemaProps = () => {
|
|
36
|
+
return props;
|
|
37
|
+
};
|
|
38
|
+
build.getSchema = () => {
|
|
39
|
+
return schema;
|
|
40
|
+
};
|
|
41
|
+
build.getDefaults = () => {
|
|
42
|
+
return defaults;
|
|
43
|
+
};
|
|
44
|
+
build.getDefaultKeys = () => {
|
|
45
|
+
return defaultKeys;
|
|
46
|
+
};
|
|
47
|
+
build.cast = (v) => {
|
|
48
|
+
return v;
|
|
49
|
+
};
|
|
50
|
+
build.getCreate = () => {
|
|
51
|
+
return create;
|
|
52
|
+
};
|
|
53
|
+
build.getBuild = () => {
|
|
54
|
+
return build;
|
|
55
|
+
};
|
|
56
|
+
build.createFunction = (func) => {
|
|
57
|
+
function fn(arg0) {
|
|
58
|
+
const options = typeof arg0 === "function" ? build(arg0) : value.Value.Default(schema, arg0);
|
|
59
|
+
tschema.assertValidSchema(schema, options, "Invalid options");
|
|
60
|
+
return func(options);
|
|
61
|
+
}
|
|
62
|
+
__name(fn, "fn");
|
|
63
|
+
if (func.name) {
|
|
64
|
+
Object.defineProperty(fn, "name", {
|
|
65
|
+
value: func.name,
|
|
66
|
+
configurable: true
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
Object.defineProperty(fn, "OptionsConfigurator", {
|
|
70
|
+
get() {
|
|
71
|
+
return build;
|
|
72
|
+
},
|
|
73
|
+
enumerable: true
|
|
74
|
+
});
|
|
75
|
+
return fn;
|
|
76
|
+
};
|
|
77
|
+
build.createBaseClass = () => {
|
|
78
|
+
return class Base {
|
|
79
|
+
static {
|
|
80
|
+
__name(this, "Base");
|
|
81
|
+
}
|
|
82
|
+
static get OptionsConfigurator() {
|
|
83
|
+
return build;
|
|
84
|
+
}
|
|
85
|
+
options;
|
|
86
|
+
constructor(arg0) {
|
|
87
|
+
this.options = typeof arg0 === "function" ? build(arg0) : value.Value.Default(schema, arg0);
|
|
88
|
+
this.initialize();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Called by the constructor
|
|
92
|
+
*/
|
|
93
|
+
initialize() {
|
|
94
|
+
this.assertValidOptions();
|
|
95
|
+
}
|
|
96
|
+
isValidOptions() {
|
|
97
|
+
return value.Value.Check(schema, this.options);
|
|
98
|
+
}
|
|
99
|
+
assertValidOptions() {
|
|
100
|
+
tschema.assertValidSchema(schema, this.options, "Invalid options");
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
return build;
|
|
105
|
+
}
|
|
106
|
+
__name(OptionsConfigurator, "OptionsConfigurator");
|
|
107
|
+
function createConfigurator(options) {
|
|
108
|
+
let CFG = class CFG {
|
|
109
|
+
static {
|
|
110
|
+
__name(this, "CFG");
|
|
111
|
+
}
|
|
112
|
+
$data;
|
|
113
|
+
constructor($data) {
|
|
114
|
+
this.$data = $data;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Applies defaults for missing values and then returns data.
|
|
118
|
+
*/
|
|
119
|
+
done() {
|
|
120
|
+
this.applyDefaults();
|
|
121
|
+
return this.$data;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Set default values for missing keys.
|
|
125
|
+
*/
|
|
126
|
+
applyDefaults() {
|
|
127
|
+
object.entriesOf(options.defaults).forEach(([key, dfValue]) => {
|
|
128
|
+
if (this.$data[key] === void 0) {
|
|
129
|
+
const df = dfValue?.();
|
|
130
|
+
if (df !== void 0) {
|
|
131
|
+
this.$data[key] = df;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const keys = /* @__PURE__ */ new Set([
|
|
139
|
+
...options.requiredKeys,
|
|
140
|
+
...object.keysOf(options.defaults),
|
|
141
|
+
...options.optionalKeys
|
|
142
|
+
]);
|
|
143
|
+
for (const key of keys) {
|
|
144
|
+
Object.defineProperty(CFG.prototype, key, {
|
|
145
|
+
value: /* @__PURE__ */ __name(function(value) {
|
|
146
|
+
if (value === void 0) {
|
|
147
|
+
if (key in options.defaults) {
|
|
148
|
+
this.$data[key] = options.defaults[key]();
|
|
149
|
+
} else {
|
|
150
|
+
delete this.$data[key];
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
this.$data[key] = value;
|
|
154
|
+
}
|
|
155
|
+
return new CFG(this.$data);
|
|
156
|
+
}, "value")
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return /* @__PURE__ */ __name(function configurator() {
|
|
160
|
+
const ins = new CFG({});
|
|
161
|
+
return ins;
|
|
162
|
+
}, "configurator");
|
|
163
|
+
}
|
|
164
|
+
__name(createConfigurator, "createConfigurator");
|
|
165
|
+
|
|
166
|
+
exports.OptionsConfigurator = OptionsConfigurator;
|