@carbonenginejs/runtime-utils 0.1.1 → 0.1.3
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/LICENSE +21 -21
- package/NOTICE +23 -23
- package/README.md +69 -69
- package/THIRD-PARTY-NOTICES.md +64 -64
- package/docs/README.md +74 -73
- package/docs/architecture.md +101 -101
- package/docs/concepts/foundation-consolidation.md +85 -85
- package/docs/concepts/model-lifecycle.md +111 -0
- package/docs/const-kb.md +85 -87
- package/docs/core-types/DECORATOR-TODOS.md +25 -25
- package/docs/core-types/README.md +229 -168
- package/docs/reference/api.md +105 -102
- package/docs/reference/classes/README.md +135 -135
- package/package.json +139 -139
- package/src/arrays.js +5 -5
- package/src/audio/audioFormats.js +34 -34
- package/src/audio/index.js +1 -1
- package/src/box3.js +331 -331
- package/src/bytes.js +56 -56
- package/src/compression.js +56 -56
- package/src/constants/index.js +7 -7
- package/src/constants/trinity.js +13 -13
- package/src/constants.js +15 -15
- package/src/curve.js +79 -79
- package/src/d3d/dxgiFormats.js +46 -46
- package/src/d3d/index.js +2 -2
- package/src/d3d/primitiveTopology.js +11 -11
- package/src/document/CjsCarbonDocument.js +212 -212
- package/src/document/CjsClassRegistry.js +373 -373
- package/src/document/CjsDocumentDehydrator.js +142 -142
- package/src/document/CjsDocumentHydrator.js +156 -156
- package/src/document/CjsStructRegistry.js +348 -348
- package/src/document/hydrationAdapter.js +129 -129
- package/src/document/index.js +6 -6
- package/src/errors/CjsError.js +286 -286
- package/src/errors/index.js +5 -5
- package/src/geometry/box.js +22 -22
- package/src/geometry/cylinder.js +22 -22
- package/src/geometry/helpers/earcut.js +1 -1
- package/src/geometry/helpers/misc.js +3 -3
- package/src/geometry/index.js +8 -8
- package/src/geometry/json.js +67 -67
- package/src/geometry/lathe.js +44 -44
- package/src/geometry/plane.js +14 -14
- package/src/geometry/shape.js +4 -4
- package/src/geometry/sphere.js +24 -24
- package/src/geometry/torus.js +14 -14
- package/src/graphics/colorSpaces.js +22 -22
- package/src/graphics/index.js +4 -4
- package/src/graphics/pixelFormats.js +158 -158
- package/src/graphics/textureDimensions.js +22 -22
- package/src/graphics/trinityEnums.js +87 -87
- package/src/index.js +62 -62
- package/src/is.js +108 -46
- package/src/json.js +23 -23
- package/src/lifecycle/CjsLifecycleState.js +77 -77
- package/src/lifecycle/index.js +1 -1
- package/src/lne3.js +70 -70
- package/src/lookup.js +48 -48
- package/src/mat3.js +51 -51
- package/src/mat4.js +699 -699
- package/src/math/index.js +25 -25
- package/src/math/scalar.js +63 -63
- package/src/media/index.js +1 -1
- package/src/media/mediaTypes.js +50 -50
- package/src/mesh.js +424 -424
- package/src/model/CjsEventEmitter.js +333 -333
- package/src/model/CjsModel.js +1589 -1544
- package/src/model/CjsModelState.js +72 -72
- package/src/model/index.js +4 -4
- package/src/model/sourceRecordUtils.js +54 -54
- package/src/noise.js +310 -310
- package/src/num.js +827 -827
- package/src/object.js +39 -39
- package/src/path.js +53 -53
- package/src/pln.js +125 -125
- package/src/pool.js +9 -9
- package/src/quat.js +144 -144
- package/src/ray3.js +188 -188
- package/src/renderContext/formats.js +145 -145
- package/src/renderContext/index.js +5 -5
- package/src/renderContext/presentation.js +125 -125
- package/src/renderContext/resources.js +27 -27
- package/src/renderContext/upscaling.js +22 -22
- package/src/renderContext/window.js +20 -20
- package/src/runtime/CjsRuntimeState.js +50 -50
- package/src/schema/CjsSchema.js +555 -318
- package/src/schema/index.js +4 -4
- package/src/shader/index.js +1 -1
- package/src/shader/shaderStages.js +37 -37
- package/src/sph3.js +181 -181
- package/src/tangent.js +288 -288
- package/src/text.js +40 -40
- package/src/tri3.js +98 -98
- package/src/types/carbonTypes.js +635 -635
- package/src/types/index.js +2 -2
- package/src/utils.js +58 -58
- package/src/validation.js +46 -46
- package/src/vec2.js +229 -229
- package/src/vec3.js +1188 -1172
- package/src/vec4.js +347 -347
- package/src/vertex.js +108 -108
- package/src/webgpu/index.js +1 -1
- package/src/webgpu/textureFormats.js +121 -121
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
export const CARBON_DOCUMENT_SCHEMA = "carbon.document";
|
|
2
|
-
export const CARBON_DOCUMENT_VERSION = 1;
|
|
3
|
-
|
|
4
|
-
/** Represents one neutral Carbon document graph for hydration and dehydration. */
|
|
5
|
-
export class CjsCarbonDocument
|
|
6
|
-
{
|
|
7
|
-
constructor(options = {})
|
|
8
|
-
{
|
|
9
|
-
const normalized = CjsCarbonDocument.normalize(options);
|
|
10
|
-
|
|
11
|
-
this.schema = CARBON_DOCUMENT_SCHEMA;
|
|
12
|
-
this.version = CARBON_DOCUMENT_VERSION;
|
|
13
|
-
this.format = normalized.format;
|
|
14
|
-
this.roots = normalized.roots;
|
|
15
|
-
this.nodes = normalized.nodes;
|
|
16
|
-
|
|
17
|
-
if (normalized.refs) this.refs = normalized.refs;
|
|
18
|
-
if (normalized.metadata) this.metadata = normalized.metadata;
|
|
19
|
-
if (normalized.reports) this.reports = normalized.reports;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static create(options = {})
|
|
23
|
-
{
|
|
24
|
-
return new CjsCarbonDocument(options);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static createNode(options = {})
|
|
28
|
-
{
|
|
29
|
-
return CjsCarbonDocument.normalizeNode(options);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static createRef(id)
|
|
33
|
-
{
|
|
34
|
-
return { $ref: CjsCarbonDocument.normalizeId(id) };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static isDocument(value)
|
|
38
|
-
{
|
|
39
|
-
return Boolean(value && typeof value === "object" && value.schema === CARBON_DOCUMENT_SCHEMA);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static isRef(value)
|
|
43
|
-
{
|
|
44
|
-
return Boolean(value && typeof value === "object" && Object.keys(value).length === 1 && Object.hasOwn(value, "$ref"));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static normalize(value)
|
|
48
|
-
{
|
|
49
|
-
if (!value || typeof value !== "object")
|
|
50
|
-
{
|
|
51
|
-
throw new TypeError("CarbonDocument must be an object");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (value.schema != null && !CjsCarbonDocument.isDocument(value))
|
|
55
|
-
{
|
|
56
|
-
throw new TypeError(`Unsupported document schema: ${String(value.schema || "unknown")}`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return CjsCarbonDocument.normalizeOptions(value);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static normalizeOptions(options = {})
|
|
63
|
-
{
|
|
64
|
-
const result = {
|
|
65
|
-
schema: CARBON_DOCUMENT_SCHEMA,
|
|
66
|
-
version: CARBON_DOCUMENT_VERSION,
|
|
67
|
-
format: CjsCarbonDocument.normalizeFormat(options.format),
|
|
68
|
-
roots: CjsCarbonDocument.normalizeRoots(options.roots),
|
|
69
|
-
nodes: CjsCarbonDocument.normalizeNodes(options.nodes)
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const refs = CjsCarbonDocument.normalizeRefs(options.refs);
|
|
73
|
-
const metadata = CjsCarbonDocument.normalizeRecord(options.metadata);
|
|
74
|
-
const reports = CjsCarbonDocument.normalizeReports(options.reports);
|
|
75
|
-
|
|
76
|
-
if (!CjsCarbonDocument.isEmptyRecord(refs)) result.refs = refs;
|
|
77
|
-
if (!CjsCarbonDocument.isEmptyRecord(metadata)) result.metadata = metadata;
|
|
78
|
-
if (reports.length) result.reports = reports;
|
|
79
|
-
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
static normalizeNodes(nodes = [])
|
|
84
|
-
{
|
|
85
|
-
return CjsCarbonDocument.normalizeList(nodes).map(CjsCarbonDocument.normalizeNode);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static normalizeRoots(roots = [])
|
|
89
|
-
{
|
|
90
|
-
return CjsCarbonDocument.normalizeList(roots).map((root, index) => CjsCarbonDocument.normalizeRoot(root, index));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
static normalizeRefs(refs = {})
|
|
94
|
-
{
|
|
95
|
-
return CjsCarbonDocument.normalizeRecord(refs);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
static normalizeMetadata(metadata = {})
|
|
99
|
-
{
|
|
100
|
-
return CjsCarbonDocument.normalizeRecord(metadata);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
static normalizeReports(reports = [])
|
|
104
|
-
{
|
|
105
|
-
return CjsCarbonDocument.normalizeList(reports, report => ({ ...report }));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
static normalizeId(id)
|
|
109
|
-
{
|
|
110
|
-
if (typeof id === "number" && Number.isInteger(id) && id > 0) return id;
|
|
111
|
-
|
|
112
|
-
const number = Number(id);
|
|
113
|
-
if (Number.isInteger(number) && number > 0) return number;
|
|
114
|
-
|
|
115
|
-
throw new TypeError(`Invalid CarbonDocument id: ${String(id)}`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
static normalizeNode(node)
|
|
119
|
-
{
|
|
120
|
-
const id = CjsCarbonDocument.normalizeId(node.id);
|
|
121
|
-
const kind = String(node.kind || node.type || "");
|
|
122
|
-
|
|
123
|
-
if (!kind)
|
|
124
|
-
{
|
|
125
|
-
throw new TypeError(`CarbonDocument node ${id} is missing a kind`);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const result = {
|
|
129
|
-
id,
|
|
130
|
-
kind,
|
|
131
|
-
fields: CjsCarbonDocument.normalizeRecord(node.fields)
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const source = CjsCarbonDocument.normalizeRecord(node.source);
|
|
135
|
-
const meta = CjsCarbonDocument.normalizeRecord(node.meta);
|
|
136
|
-
const raw = CjsCarbonDocument.normalizeNullableRecord(node.raw);
|
|
137
|
-
|
|
138
|
-
if (!CjsCarbonDocument.isEmptyRecord(source)) result.source = source;
|
|
139
|
-
if (!CjsCarbonDocument.isEmptyRecord(meta)) result.meta = meta;
|
|
140
|
-
if (raw && !CjsCarbonDocument.isEmptyRecord(raw)) result.raw = raw;
|
|
141
|
-
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
static normalizeRoot(root, index)
|
|
146
|
-
{
|
|
147
|
-
if (CjsCarbonDocument.isRef(root))
|
|
148
|
-
{
|
|
149
|
-
return { name: index === 0 ? "default" : `root${index}`, ref: CjsCarbonDocument.createRef(root.$ref) };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const name = String(root?.name || (index === 0 ? "default" : `root${index}`));
|
|
153
|
-
const ref = root?.ref || root?.value || root?.root;
|
|
154
|
-
|
|
155
|
-
if (!CjsCarbonDocument.isRef(ref))
|
|
156
|
-
{
|
|
157
|
-
throw new TypeError(`CarbonDocument root ${name} is missing a ref`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return { name, ref: CjsCarbonDocument.createRef(ref.$ref) };
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
static normalizeFormat(format)
|
|
164
|
-
{
|
|
165
|
-
if (typeof format === "string") return { id: format, version: 1 };
|
|
166
|
-
return {
|
|
167
|
-
id: String(format?.id || "unknown"),
|
|
168
|
-
version: format?.version ?? 1
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
static clonePlainRecord(value)
|
|
173
|
-
{
|
|
174
|
-
return CjsCarbonDocument.normalizeRecord(value);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
static normalizeRecord(value, defaults = {})
|
|
178
|
-
{
|
|
179
|
-
if (!CjsCarbonDocument.isObject(value) || Array.isArray(value))
|
|
180
|
-
{
|
|
181
|
-
return { ...defaults };
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return { ...value, ...defaults };
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
static normalizeNullableRecord(value)
|
|
188
|
-
{
|
|
189
|
-
return value == null ? null : CjsCarbonDocument.normalizeRecord(value);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
static normalizeList(value, map = null)
|
|
193
|
-
{
|
|
194
|
-
const list = CjsCarbonDocument.isArray(value) ? value : [];
|
|
195
|
-
return map ? list.map(map) : list.slice();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
static isObject(value)
|
|
199
|
-
{
|
|
200
|
-
return value !== null && typeof value === "object";
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
static isArray(value)
|
|
204
|
-
{
|
|
205
|
-
return Array.isArray(value);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
static isEmptyRecord(value)
|
|
209
|
-
{
|
|
210
|
-
return !CjsCarbonDocument.isObject(value) || Array.isArray(value) || Object.keys(value).length === 0;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
1
|
+
export const CARBON_DOCUMENT_SCHEMA = "carbon.document";
|
|
2
|
+
export const CARBON_DOCUMENT_VERSION = 1;
|
|
3
|
+
|
|
4
|
+
/** Represents one neutral Carbon document graph for hydration and dehydration. */
|
|
5
|
+
export class CjsCarbonDocument
|
|
6
|
+
{
|
|
7
|
+
constructor(options = {})
|
|
8
|
+
{
|
|
9
|
+
const normalized = CjsCarbonDocument.normalize(options);
|
|
10
|
+
|
|
11
|
+
this.schema = CARBON_DOCUMENT_SCHEMA;
|
|
12
|
+
this.version = CARBON_DOCUMENT_VERSION;
|
|
13
|
+
this.format = normalized.format;
|
|
14
|
+
this.roots = normalized.roots;
|
|
15
|
+
this.nodes = normalized.nodes;
|
|
16
|
+
|
|
17
|
+
if (normalized.refs) this.refs = normalized.refs;
|
|
18
|
+
if (normalized.metadata) this.metadata = normalized.metadata;
|
|
19
|
+
if (normalized.reports) this.reports = normalized.reports;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static create(options = {})
|
|
23
|
+
{
|
|
24
|
+
return new CjsCarbonDocument(options);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static createNode(options = {})
|
|
28
|
+
{
|
|
29
|
+
return CjsCarbonDocument.normalizeNode(options);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static createRef(id)
|
|
33
|
+
{
|
|
34
|
+
return { $ref: CjsCarbonDocument.normalizeId(id) };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static isDocument(value)
|
|
38
|
+
{
|
|
39
|
+
return Boolean(value && typeof value === "object" && value.schema === CARBON_DOCUMENT_SCHEMA);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static isRef(value)
|
|
43
|
+
{
|
|
44
|
+
return Boolean(value && typeof value === "object" && Object.keys(value).length === 1 && Object.hasOwn(value, "$ref"));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static normalize(value)
|
|
48
|
+
{
|
|
49
|
+
if (!value || typeof value !== "object")
|
|
50
|
+
{
|
|
51
|
+
throw new TypeError("CarbonDocument must be an object");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (value.schema != null && !CjsCarbonDocument.isDocument(value))
|
|
55
|
+
{
|
|
56
|
+
throw new TypeError(`Unsupported document schema: ${String(value.schema || "unknown")}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return CjsCarbonDocument.normalizeOptions(value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static normalizeOptions(options = {})
|
|
63
|
+
{
|
|
64
|
+
const result = {
|
|
65
|
+
schema: CARBON_DOCUMENT_SCHEMA,
|
|
66
|
+
version: CARBON_DOCUMENT_VERSION,
|
|
67
|
+
format: CjsCarbonDocument.normalizeFormat(options.format),
|
|
68
|
+
roots: CjsCarbonDocument.normalizeRoots(options.roots),
|
|
69
|
+
nodes: CjsCarbonDocument.normalizeNodes(options.nodes)
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const refs = CjsCarbonDocument.normalizeRefs(options.refs);
|
|
73
|
+
const metadata = CjsCarbonDocument.normalizeRecord(options.metadata);
|
|
74
|
+
const reports = CjsCarbonDocument.normalizeReports(options.reports);
|
|
75
|
+
|
|
76
|
+
if (!CjsCarbonDocument.isEmptyRecord(refs)) result.refs = refs;
|
|
77
|
+
if (!CjsCarbonDocument.isEmptyRecord(metadata)) result.metadata = metadata;
|
|
78
|
+
if (reports.length) result.reports = reports;
|
|
79
|
+
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static normalizeNodes(nodes = [])
|
|
84
|
+
{
|
|
85
|
+
return CjsCarbonDocument.normalizeList(nodes).map(CjsCarbonDocument.normalizeNode);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static normalizeRoots(roots = [])
|
|
89
|
+
{
|
|
90
|
+
return CjsCarbonDocument.normalizeList(roots).map((root, index) => CjsCarbonDocument.normalizeRoot(root, index));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static normalizeRefs(refs = {})
|
|
94
|
+
{
|
|
95
|
+
return CjsCarbonDocument.normalizeRecord(refs);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static normalizeMetadata(metadata = {})
|
|
99
|
+
{
|
|
100
|
+
return CjsCarbonDocument.normalizeRecord(metadata);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static normalizeReports(reports = [])
|
|
104
|
+
{
|
|
105
|
+
return CjsCarbonDocument.normalizeList(reports, report => ({ ...report }));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static normalizeId(id)
|
|
109
|
+
{
|
|
110
|
+
if (typeof id === "number" && Number.isInteger(id) && id > 0) return id;
|
|
111
|
+
|
|
112
|
+
const number = Number(id);
|
|
113
|
+
if (Number.isInteger(number) && number > 0) return number;
|
|
114
|
+
|
|
115
|
+
throw new TypeError(`Invalid CarbonDocument id: ${String(id)}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static normalizeNode(node)
|
|
119
|
+
{
|
|
120
|
+
const id = CjsCarbonDocument.normalizeId(node.id);
|
|
121
|
+
const kind = String(node.kind || node.type || "");
|
|
122
|
+
|
|
123
|
+
if (!kind)
|
|
124
|
+
{
|
|
125
|
+
throw new TypeError(`CarbonDocument node ${id} is missing a kind`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const result = {
|
|
129
|
+
id,
|
|
130
|
+
kind,
|
|
131
|
+
fields: CjsCarbonDocument.normalizeRecord(node.fields)
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const source = CjsCarbonDocument.normalizeRecord(node.source);
|
|
135
|
+
const meta = CjsCarbonDocument.normalizeRecord(node.meta);
|
|
136
|
+
const raw = CjsCarbonDocument.normalizeNullableRecord(node.raw);
|
|
137
|
+
|
|
138
|
+
if (!CjsCarbonDocument.isEmptyRecord(source)) result.source = source;
|
|
139
|
+
if (!CjsCarbonDocument.isEmptyRecord(meta)) result.meta = meta;
|
|
140
|
+
if (raw && !CjsCarbonDocument.isEmptyRecord(raw)) result.raw = raw;
|
|
141
|
+
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static normalizeRoot(root, index)
|
|
146
|
+
{
|
|
147
|
+
if (CjsCarbonDocument.isRef(root))
|
|
148
|
+
{
|
|
149
|
+
return { name: index === 0 ? "default" : `root${index}`, ref: CjsCarbonDocument.createRef(root.$ref) };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const name = String(root?.name || (index === 0 ? "default" : `root${index}`));
|
|
153
|
+
const ref = root?.ref || root?.value || root?.root;
|
|
154
|
+
|
|
155
|
+
if (!CjsCarbonDocument.isRef(ref))
|
|
156
|
+
{
|
|
157
|
+
throw new TypeError(`CarbonDocument root ${name} is missing a ref`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return { name, ref: CjsCarbonDocument.createRef(ref.$ref) };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static normalizeFormat(format)
|
|
164
|
+
{
|
|
165
|
+
if (typeof format === "string") return { id: format, version: 1 };
|
|
166
|
+
return {
|
|
167
|
+
id: String(format?.id || "unknown"),
|
|
168
|
+
version: format?.version ?? 1
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
static clonePlainRecord(value)
|
|
173
|
+
{
|
|
174
|
+
return CjsCarbonDocument.normalizeRecord(value);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static normalizeRecord(value, defaults = {})
|
|
178
|
+
{
|
|
179
|
+
if (!CjsCarbonDocument.isObject(value) || Array.isArray(value))
|
|
180
|
+
{
|
|
181
|
+
return { ...defaults };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return { ...value, ...defaults };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
static normalizeNullableRecord(value)
|
|
188
|
+
{
|
|
189
|
+
return value == null ? null : CjsCarbonDocument.normalizeRecord(value);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static normalizeList(value, map = null)
|
|
193
|
+
{
|
|
194
|
+
const list = CjsCarbonDocument.isArray(value) ? value : [];
|
|
195
|
+
return map ? list.map(map) : list.slice();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
static isObject(value)
|
|
199
|
+
{
|
|
200
|
+
return value !== null && typeof value === "object";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
static isArray(value)
|
|
204
|
+
{
|
|
205
|
+
return Array.isArray(value);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
static isEmptyRecord(value)
|
|
209
|
+
{
|
|
210
|
+
return !CjsCarbonDocument.isObject(value) || Array.isArray(value) || Object.keys(value).length === 0;
|
|
211
|
+
}
|
|
212
|
+
}
|