@fibery/schema 10.2.17 → 10.3.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/index.d.ts +7 -6
- package/lib/index.js +7 -22
- package/lib/src/errors.d.ts +4 -2
- package/lib/src/errors.js +4 -6
- package/lib/src/factory.d.ts +24 -21
- package/lib/src/factory.js +42 -43
- package/lib/src/field-keys.d.ts +7 -4
- package/lib/src/field-keys.js +0 -2
- package/lib/src/field-object.d.ts +88 -85
- package/lib/src/field-object.js +172 -224
- package/lib/src/print-utils.d.ts +5 -2
- package/lib/src/print-utils.js +4 -6
- package/lib/src/schema.d.ts +19 -16
- package/lib/src/schema.js +57 -65
- package/lib/src/type-object.d.ts +99 -96
- package/lib/src/type-object.js +185 -198
- package/lib/src/utils.d.ts +54 -50
- package/lib/src/utils.js +93 -146
- package/package.json +16 -14
package/lib/src/field-object.js
CHANGED
|
@@ -1,225 +1,173 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { parseType, toNonEnumTitle } from "./utils.js";
|
|
2
|
+
import { once } from "@fibery/helpers/src/_";
|
|
3
|
+
import isFunction from "lodash/isFunction.js";
|
|
4
|
+
import isPlainObject from "lodash/isPlainObject.js";
|
|
5
|
+
import isString from "lodash/isString.js";
|
|
6
|
+
//#region src/field-object.ts
|
|
7
|
+
var FieldObject = class {
|
|
8
|
+
name;
|
|
9
|
+
description;
|
|
10
|
+
id;
|
|
11
|
+
type;
|
|
12
|
+
rawMeta;
|
|
13
|
+
holderType;
|
|
14
|
+
isCollection;
|
|
15
|
+
isTitle;
|
|
16
|
+
isId;
|
|
17
|
+
isPublicId;
|
|
18
|
+
isReadOnly;
|
|
19
|
+
isFormula;
|
|
20
|
+
isFormulaDisabled;
|
|
21
|
+
formulaDisableReason;
|
|
22
|
+
formula;
|
|
23
|
+
isLookup;
|
|
24
|
+
hasLinkRule;
|
|
25
|
+
linkRule;
|
|
26
|
+
isLinkRuleDisabled;
|
|
27
|
+
linkRuleDisableReason;
|
|
28
|
+
relation;
|
|
29
|
+
multiRelation;
|
|
30
|
+
defaultValue;
|
|
31
|
+
objectEditorOrder;
|
|
32
|
+
isRequired;
|
|
33
|
+
isHidden;
|
|
34
|
+
isDeleted;
|
|
35
|
+
disableLinkExistingItems;
|
|
36
|
+
version;
|
|
37
|
+
typeObject;
|
|
38
|
+
mixinTypeObject;
|
|
39
|
+
holderTypeObject;
|
|
40
|
+
nameParts;
|
|
41
|
+
title;
|
|
42
|
+
multiRelatedFieldObjects;
|
|
43
|
+
isMultiField;
|
|
44
|
+
isDependency;
|
|
45
|
+
isDependencyStart;
|
|
46
|
+
constructor({ rawFieldObject, holderType, resolveTypeObject, version, resolveMultiRelatedFieldObjects }) {
|
|
47
|
+
if (!isPlainObject(rawFieldObject)) throw new Error("rawFieldObject arg must be plain object");
|
|
48
|
+
if (!isString(holderType)) throw new Error("holderType arg must be string");
|
|
49
|
+
if (!isFunction(resolveTypeObject)) throw new Error("resolveTypeObject arg must be function");
|
|
50
|
+
if (!isFunction(resolveMultiRelatedFieldObjects)) throw new Error("resolveMultiRelationFieldObjects arg must be function");
|
|
51
|
+
this.name = rawFieldObject["fibery/name"];
|
|
52
|
+
this.description = rawFieldObject["fibery/description"] || null;
|
|
53
|
+
this.id = rawFieldObject["fibery/id"];
|
|
54
|
+
this.type = rawFieldObject["fibery/type"];
|
|
55
|
+
const rawMeta = rawFieldObject["fibery/meta"] || {};
|
|
56
|
+
this.rawMeta = rawMeta;
|
|
57
|
+
this.holderType = holderType;
|
|
58
|
+
this.isCollection = rawMeta["fibery/collection?"] || false;
|
|
59
|
+
this.isTitle = rawMeta["ui/title?"] || false;
|
|
60
|
+
this.isId = rawMeta["fibery/id?"] || false;
|
|
61
|
+
this.isPublicId = rawMeta["fibery/public-id?"] || false;
|
|
62
|
+
this.isReadOnly = rawMeta["fibery/readonly?"] || false;
|
|
63
|
+
this.isFormula = rawMeta["formula/formula?"] || false;
|
|
64
|
+
this.isFormulaDisabled = rawMeta["formula/disabled?"] || false;
|
|
65
|
+
this.formulaDisableReason = rawMeta["formula/disable-reason"] || null;
|
|
66
|
+
this.formula = rawMeta["formula/formula"] || null;
|
|
67
|
+
this.isLookup = rawMeta["formula/lookup?"] || false;
|
|
68
|
+
this.hasLinkRule = rawMeta["link-rule/link-rule?"] || false;
|
|
69
|
+
this.linkRule = rawMeta["link-rule/link-rule"] || null;
|
|
70
|
+
this.isLinkRuleDisabled = rawMeta["link-rule/disabled?"] || false;
|
|
71
|
+
this.linkRuleDisableReason = rawMeta["link-rule/disable-reason"] || null;
|
|
72
|
+
this.relation = rawMeta["fibery/relation"] || null;
|
|
73
|
+
this.defaultValue = rawMeta["fibery/default-value"] ?? null;
|
|
74
|
+
this.objectEditorOrder = rawMeta["ui/object-editor-order"] || 0;
|
|
75
|
+
this.isRequired = rawMeta["fibery/required?"] === true;
|
|
76
|
+
this.isHidden = rawMeta["ui/hidden?"] === true;
|
|
77
|
+
this.isDeleted = rawFieldObject["fibery/deleted?"] || false;
|
|
78
|
+
this.disableLinkExistingItems = rawMeta["ui/disable-link-existing-items"] || false;
|
|
79
|
+
this.version = version;
|
|
80
|
+
this.multiRelation = rawMeta["fibery/multi-relation"] || null;
|
|
81
|
+
this.isDependency = rawMeta["fibery/dependency?"] || false;
|
|
82
|
+
this.isDependencyStart = rawMeta["fibery/dependency-start?"] || false;
|
|
83
|
+
Object.defineProperties(this, {
|
|
84
|
+
typeObject: {
|
|
85
|
+
configurable: false,
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: once(() => resolveTypeObject(this.type))
|
|
88
|
+
},
|
|
89
|
+
mixinTypeObject: {
|
|
90
|
+
configurable: false,
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: once(() => {
|
|
93
|
+
return this.holderTypeObject.installedMixinTypeObjects.find((mixinTypeObject) => Object.hasOwn(mixinTypeObject.fieldObjectsByName, this.name) || this.name === "workflow/state" && mixinTypeObject.name === "workflow/workflow");
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
holderTypeObject: {
|
|
97
|
+
configurable: false,
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: once(() => {
|
|
100
|
+
return resolveTypeObject(holderType);
|
|
101
|
+
})
|
|
102
|
+
},
|
|
103
|
+
nameParts: {
|
|
104
|
+
configurable: false,
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: once(() => parseType(rawFieldObject["fibery/name"]))
|
|
107
|
+
},
|
|
108
|
+
title: {
|
|
109
|
+
configurable: false,
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: once(() => {
|
|
112
|
+
if (this.name === "fibery/role" && this.holderType === "fibery/user") return "User Role";
|
|
113
|
+
return toNonEnumTitle(rawFieldObject["fibery/name"]);
|
|
114
|
+
})
|
|
115
|
+
},
|
|
116
|
+
multiRelatedFieldObjects: {
|
|
117
|
+
configurable: false,
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: once(() => {
|
|
120
|
+
const { multiRelation, typeObject } = this;
|
|
121
|
+
if (!multiRelation || !typeObject.isEntityRef) return [];
|
|
122
|
+
return resolveMultiRelatedFieldObjects(multiRelation);
|
|
123
|
+
})
|
|
124
|
+
},
|
|
125
|
+
isMultiField: {
|
|
126
|
+
configurable: false,
|
|
127
|
+
enumerable: true,
|
|
128
|
+
get: once(() => {
|
|
129
|
+
return this.typeObject.isEntityRef;
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
get relatedFieldObject() {
|
|
135
|
+
const { name, relation, multiRelation, typeObject } = this;
|
|
136
|
+
if (!relation && !multiRelation) return null;
|
|
137
|
+
if (!relation && multiRelation && typeObject.isEntityRef) return null;
|
|
138
|
+
let relationKey;
|
|
139
|
+
let relationId;
|
|
140
|
+
if (relation) {
|
|
141
|
+
relationKey = "relation";
|
|
142
|
+
relationId = relation;
|
|
143
|
+
} else {
|
|
144
|
+
relationId = multiRelation;
|
|
145
|
+
relationKey = "multiRelation";
|
|
146
|
+
}
|
|
147
|
+
const selector = this.type !== this.holderType ? (fieldObject) => fieldObject[relationKey] === relationId : (fieldObject) => fieldObject[relationKey] === relationId && fieldObject.name !== name;
|
|
148
|
+
const fieldObject = this.typeObject.fieldObjects.find(selector);
|
|
149
|
+
if (!fieldObject) throw new Error(`there no other end for ${relationKey} ${relationId}`);
|
|
150
|
+
return fieldObject;
|
|
151
|
+
}
|
|
152
|
+
get cardinality() {
|
|
153
|
+
const { isCollection, relatedFieldObject, typeObject } = this;
|
|
154
|
+
if (typeObject.isPrimitive) throw new Error("Only non-basic fields have cardinality");
|
|
155
|
+
if (isCollection && this.rawMeta["fibery/field-reversed-collection?"]) return ":cardinality/many-to-many";
|
|
156
|
+
if (!relatedFieldObject) return isCollection ? ":cardinality/one-to-many" : ":cardinality/many-to-one";
|
|
157
|
+
const isRelationCollection = relatedFieldObject.isCollection;
|
|
158
|
+
if (!isCollection && !isRelationCollection) return ":cardinality/one-to-one";
|
|
159
|
+
if (isCollection && !isRelationCollection) return ":cardinality/one-to-many";
|
|
160
|
+
if (!isCollection && isRelationCollection) return ":cardinality/many-to-one";
|
|
161
|
+
if (isCollection && isRelationCollection) return ":cardinality/many-to-many";
|
|
162
|
+
throw new Error("get cardinality invariant");
|
|
163
|
+
}
|
|
164
|
+
/** @deprecated use !typeObject.isPrimitive && cardinality === ... instead */
|
|
165
|
+
get kind() {
|
|
166
|
+
if (this.typeObject.isPrimitive) if (this.isCollection) throw new Error("basic collection is not implemented");
|
|
167
|
+
else return ":field/basic";
|
|
168
|
+
else if (this.isCollection) return ":field/reference-collection";
|
|
169
|
+
else return ":field/reference";
|
|
170
|
+
}
|
|
4
171
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const _1 = require("@fibery/helpers/src/_");
|
|
8
|
-
const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
9
|
-
const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
|
|
10
|
-
const isString_1 = __importDefault(require("lodash/isString"));
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
|
-
class FieldObject {
|
|
13
|
-
name;
|
|
14
|
-
description;
|
|
15
|
-
id;
|
|
16
|
-
type;
|
|
17
|
-
rawMeta;
|
|
18
|
-
holderType;
|
|
19
|
-
isCollection;
|
|
20
|
-
isTitle;
|
|
21
|
-
isId;
|
|
22
|
-
isPublicId;
|
|
23
|
-
isReadOnly;
|
|
24
|
-
isFormula;
|
|
25
|
-
isFormulaDisabled;
|
|
26
|
-
formulaDisableReason;
|
|
27
|
-
formula;
|
|
28
|
-
isLookup;
|
|
29
|
-
hasLinkRule;
|
|
30
|
-
linkRule;
|
|
31
|
-
isLinkRuleDisabled;
|
|
32
|
-
linkRuleDisableReason;
|
|
33
|
-
relation;
|
|
34
|
-
multiRelation;
|
|
35
|
-
defaultValue;
|
|
36
|
-
objectEditorOrder;
|
|
37
|
-
isRequired;
|
|
38
|
-
isHidden;
|
|
39
|
-
isDeleted;
|
|
40
|
-
disableLinkExistingItems;
|
|
41
|
-
version;
|
|
42
|
-
typeObject;
|
|
43
|
-
mixinTypeObject;
|
|
44
|
-
holderTypeObject;
|
|
45
|
-
nameParts;
|
|
46
|
-
title;
|
|
47
|
-
multiRelatedFieldObjects;
|
|
48
|
-
isMultiField;
|
|
49
|
-
isDependency;
|
|
50
|
-
isDependencyStart;
|
|
51
|
-
constructor({ rawFieldObject, holderType, resolveTypeObject, version, resolveMultiRelatedFieldObjects, }) {
|
|
52
|
-
if (!(0, isPlainObject_1.default)(rawFieldObject)) {
|
|
53
|
-
throw new Error("rawFieldObject arg must be plain object");
|
|
54
|
-
}
|
|
55
|
-
if (!(0, isString_1.default)(holderType)) {
|
|
56
|
-
throw new Error("holderType arg must be string");
|
|
57
|
-
}
|
|
58
|
-
if (!(0, isFunction_1.default)(resolveTypeObject)) {
|
|
59
|
-
throw new Error("resolveTypeObject arg must be function");
|
|
60
|
-
}
|
|
61
|
-
if (!(0, isFunction_1.default)(resolveMultiRelatedFieldObjects)) {
|
|
62
|
-
throw new Error("resolveMultiRelationFieldObjects arg must be function");
|
|
63
|
-
}
|
|
64
|
-
this.name = rawFieldObject["fibery/name"];
|
|
65
|
-
this.description = rawFieldObject["fibery/description"] || null;
|
|
66
|
-
this.id = rawFieldObject["fibery/id"];
|
|
67
|
-
this.type = rawFieldObject["fibery/type"];
|
|
68
|
-
const rawMeta = rawFieldObject["fibery/meta"] || {};
|
|
69
|
-
this.rawMeta = rawMeta;
|
|
70
|
-
this.holderType = holderType;
|
|
71
|
-
this.isCollection = rawMeta["fibery/collection?"] || false;
|
|
72
|
-
this.isTitle = rawMeta["ui/title?"] || false;
|
|
73
|
-
this.isId = rawMeta["fibery/id?"] || false;
|
|
74
|
-
this.isPublicId = rawMeta["fibery/public-id?"] || false;
|
|
75
|
-
this.isReadOnly = rawMeta["fibery/readonly?"] || false;
|
|
76
|
-
this.isFormula = rawMeta["formula/formula?"] || false;
|
|
77
|
-
this.isFormulaDisabled = rawMeta["formula/disabled?"] || false;
|
|
78
|
-
this.formulaDisableReason = rawMeta["formula/disable-reason"] || null;
|
|
79
|
-
this.formula = rawMeta["formula/formula"] || null;
|
|
80
|
-
this.isLookup = rawMeta["formula/lookup?"] || false;
|
|
81
|
-
this.hasLinkRule = rawMeta["link-rule/link-rule?"] || false;
|
|
82
|
-
this.linkRule = rawMeta["link-rule/link-rule"] || null;
|
|
83
|
-
this.isLinkRuleDisabled = rawMeta["link-rule/disabled?"] || false;
|
|
84
|
-
this.linkRuleDisableReason = rawMeta["link-rule/disable-reason"] || null;
|
|
85
|
-
this.relation = rawMeta["fibery/relation"] || null;
|
|
86
|
-
this.defaultValue = rawMeta["fibery/default-value"] ?? null;
|
|
87
|
-
this.objectEditorOrder = rawMeta["ui/object-editor-order"] || 0;
|
|
88
|
-
this.isRequired = rawMeta["fibery/required?"] === true;
|
|
89
|
-
this.isHidden = rawMeta["ui/hidden?"] === true;
|
|
90
|
-
this.isDeleted = rawFieldObject["fibery/deleted?"] || false;
|
|
91
|
-
this.disableLinkExistingItems = rawMeta["ui/disable-link-existing-items"] || false;
|
|
92
|
-
this.version = version;
|
|
93
|
-
this.multiRelation = rawMeta["fibery/multi-relation"] || null;
|
|
94
|
-
this.isDependency = rawMeta["fibery/dependency?"] || false;
|
|
95
|
-
this.isDependencyStart = rawMeta["fibery/dependency-start?"] || false;
|
|
96
|
-
Object.defineProperties(this, {
|
|
97
|
-
typeObject: {
|
|
98
|
-
configurable: false,
|
|
99
|
-
enumerable: true,
|
|
100
|
-
get: (0, _1.once)(() => resolveTypeObject(this.type)),
|
|
101
|
-
},
|
|
102
|
-
mixinTypeObject: {
|
|
103
|
-
configurable: false,
|
|
104
|
-
enumerable: true,
|
|
105
|
-
get: (0, _1.once)(() => {
|
|
106
|
-
return this.holderTypeObject.installedMixinTypeObjects.find((mixinTypeObject) => Object.hasOwn(mixinTypeObject.fieldObjectsByName, this.name) ||
|
|
107
|
-
(this.name === "workflow/state" && mixinTypeObject.name === "workflow/workflow"));
|
|
108
|
-
}),
|
|
109
|
-
},
|
|
110
|
-
holderTypeObject: {
|
|
111
|
-
configurable: false,
|
|
112
|
-
enumerable: true,
|
|
113
|
-
get: (0, _1.once)(() => {
|
|
114
|
-
return resolveTypeObject(holderType);
|
|
115
|
-
}),
|
|
116
|
-
},
|
|
117
|
-
nameParts: {
|
|
118
|
-
configurable: false,
|
|
119
|
-
enumerable: true,
|
|
120
|
-
get: (0, _1.once)(() => (0, utils_1.parseType)(rawFieldObject["fibery/name"])),
|
|
121
|
-
},
|
|
122
|
-
title: {
|
|
123
|
-
configurable: false,
|
|
124
|
-
enumerable: true,
|
|
125
|
-
get: (0, _1.once)(() => {
|
|
126
|
-
if (this.name === "fibery/role" && this.holderType === "fibery/user") {
|
|
127
|
-
return "User Role";
|
|
128
|
-
}
|
|
129
|
-
return (0, utils_1.toNonEnumTitle)(rawFieldObject["fibery/name"]);
|
|
130
|
-
}),
|
|
131
|
-
},
|
|
132
|
-
multiRelatedFieldObjects: {
|
|
133
|
-
configurable: false,
|
|
134
|
-
enumerable: true,
|
|
135
|
-
get: (0, _1.once)(() => {
|
|
136
|
-
const { multiRelation, typeObject } = this;
|
|
137
|
-
if (!multiRelation || !typeObject.isEntityRef) {
|
|
138
|
-
return [];
|
|
139
|
-
}
|
|
140
|
-
return resolveMultiRelatedFieldObjects(multiRelation);
|
|
141
|
-
}),
|
|
142
|
-
},
|
|
143
|
-
isMultiField: {
|
|
144
|
-
configurable: false,
|
|
145
|
-
enumerable: true,
|
|
146
|
-
get: (0, _1.once)(() => {
|
|
147
|
-
return this.typeObject.isEntityRef;
|
|
148
|
-
}),
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
get relatedFieldObject() {
|
|
153
|
-
const { name, relation, multiRelation, typeObject } = this;
|
|
154
|
-
if (!relation && !multiRelation) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
if (!relation && multiRelation && typeObject.isEntityRef) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
let relationKey;
|
|
161
|
-
let relationId;
|
|
162
|
-
if (relation) {
|
|
163
|
-
relationKey = "relation";
|
|
164
|
-
relationId = relation;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
relationId = multiRelation;
|
|
168
|
-
relationKey = "multiRelation";
|
|
169
|
-
}
|
|
170
|
-
const selector = this.type !== this.holderType
|
|
171
|
-
? (fieldObject) => fieldObject[relationKey] === relationId
|
|
172
|
-
: (fieldObject) => fieldObject[relationKey] === relationId && fieldObject.name !== name;
|
|
173
|
-
const fieldObject = this.typeObject.fieldObjects.find(selector);
|
|
174
|
-
if (!fieldObject) {
|
|
175
|
-
throw new Error(`there no other end for ${relationKey} ${relationId}`);
|
|
176
|
-
}
|
|
177
|
-
return fieldObject;
|
|
178
|
-
}
|
|
179
|
-
get cardinality() {
|
|
180
|
-
const { isCollection, relatedFieldObject, typeObject } = this;
|
|
181
|
-
if (typeObject.isPrimitive) {
|
|
182
|
-
throw new Error("Only non-basic fields have cardinality");
|
|
183
|
-
}
|
|
184
|
-
if (isCollection && this.rawMeta["fibery/field-reversed-collection?"]) {
|
|
185
|
-
return ":cardinality/many-to-many";
|
|
186
|
-
}
|
|
187
|
-
if (!relatedFieldObject) {
|
|
188
|
-
return isCollection ? ":cardinality/one-to-many" : ":cardinality/many-to-one";
|
|
189
|
-
}
|
|
190
|
-
const isRelationCollection = relatedFieldObject.isCollection;
|
|
191
|
-
if (!isCollection && !isRelationCollection) {
|
|
192
|
-
return ":cardinality/one-to-one";
|
|
193
|
-
}
|
|
194
|
-
if (isCollection && !isRelationCollection) {
|
|
195
|
-
return ":cardinality/one-to-many";
|
|
196
|
-
}
|
|
197
|
-
if (!isCollection && isRelationCollection) {
|
|
198
|
-
return ":cardinality/many-to-one";
|
|
199
|
-
}
|
|
200
|
-
if (isCollection && isRelationCollection) {
|
|
201
|
-
return ":cardinality/many-to-many";
|
|
202
|
-
}
|
|
203
|
-
throw new Error("get cardinality invariant");
|
|
204
|
-
}
|
|
205
|
-
/** @deprecated use !typeObject.isPrimitive && cardinality === ... instead */
|
|
206
|
-
get kind() {
|
|
207
|
-
if (this.typeObject.isPrimitive) {
|
|
208
|
-
if (this.isCollection) {
|
|
209
|
-
throw new Error("basic collection is not implemented");
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
return ":field/basic";
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
if (this.isCollection) {
|
|
217
|
-
return ":field/reference-collection";
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
return ":field/reference";
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
exports.FieldObject = FieldObject;
|
|
172
|
+
//#endregion
|
|
173
|
+
export { FieldObject };
|
package/lib/src/print-utils.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/print-utils.d.ts
|
|
2
|
+
declare const isValidIdentifier: (x: string) => boolean;
|
|
3
|
+
declare const printJsPath: (keys: string[]) => string;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { isValidIdentifier, printJsPath };
|
package/lib/src/print-utils.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.printJsPath = exports.isValidIdentifier = void 0;
|
|
1
|
+
//#region src/print-utils.ts
|
|
4
2
|
const validIdentifierRegExp = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
5
3
|
const isValidIdentifier = (x) => validIdentifierRegExp.test(x);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const printJsPath = (keys) => keys.map((key) => isValidIdentifier(key) ? "." + key : `["${key}"]`).join("");
|
|
5
|
+
//#endregion
|
|
6
|
+
export { isValidIdentifier, printJsPath };
|
package/lib/src/schema.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { RawTypeObject, TypeObject } from "./type-object.js";
|
|
2
|
+
import { Factory } from "./factory.js";
|
|
3
|
+
//#region src/schema.d.ts
|
|
4
|
+
type RawSchema = {
|
|
5
|
+
"fibery/id": string;
|
|
6
|
+
"fibery/types": RawTypeObject[];
|
|
7
|
+
"fibery/version": string;
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
declare class Schema {
|
|
10
|
+
typeObjects: Array<TypeObject>;
|
|
11
|
+
typeObjectsById: Record<string, TypeObject>;
|
|
12
|
+
typeObjectsByName: Record<string, TypeObject>;
|
|
13
|
+
id: string;
|
|
14
|
+
version: string;
|
|
15
|
+
constructor({ factory, rawSchema: { "fibery/id": id, "fibery/types": rawTypeObjects, "fibery/version": version } }: {
|
|
16
|
+
factory: Factory;
|
|
17
|
+
rawSchema: RawSchema;
|
|
18
|
+
});
|
|
18
19
|
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { RawSchema, Schema };
|
package/lib/src/schema.js
CHANGED
|
@@ -1,65 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}));
|
|
59
|
-
this.typeObjectsById = factory.makeTypeObjectsById(this.typeObjects);
|
|
60
|
-
this.typeObjectsByName = factory.makeTypeObjectsByName(this.typeObjects);
|
|
61
|
-
this.id = id;
|
|
62
|
-
this.version = version;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.Schema = Schema;
|
|
1
|
+
import { once } from "@fibery/helpers/src/_";
|
|
2
|
+
//#region src/schema.ts
|
|
3
|
+
var Schema = class {
|
|
4
|
+
typeObjects;
|
|
5
|
+
typeObjectsById;
|
|
6
|
+
typeObjectsByName;
|
|
7
|
+
id;
|
|
8
|
+
version;
|
|
9
|
+
constructor({ factory, rawSchema: { "fibery/id": id, "fibery/types": rawTypeObjects, "fibery/version": version } }) {
|
|
10
|
+
if (!Array.isArray(rawTypeObjects)) throw new Error("rawTypeObjects arg must be array");
|
|
11
|
+
Object.defineProperties(this, { toJSON: {
|
|
12
|
+
value: () => ({
|
|
13
|
+
"fibery/types": rawTypeObjects,
|
|
14
|
+
"fibery/meta": { "fibery/version": version }
|
|
15
|
+
}),
|
|
16
|
+
enumerable: false
|
|
17
|
+
} });
|
|
18
|
+
const getTypeComponentTypeToFieldObject = once(() => {
|
|
19
|
+
const typeComponentTypeToFieldObject = /* @__PURE__ */ new Map();
|
|
20
|
+
this.typeObjects.flatMap((typeObject) => typeObject.fieldObjects).filter((fieldObject) => {
|
|
21
|
+
return fieldObject.rawMeta["fibery/type-component?"] === true && fieldObject.typeObject.rawMeta["fibery/type-component?"] === true;
|
|
22
|
+
}).forEach((fieldObject) => {
|
|
23
|
+
typeComponentTypeToFieldObject.set(fieldObject.type, fieldObject);
|
|
24
|
+
});
|
|
25
|
+
return typeComponentTypeToFieldObject;
|
|
26
|
+
});
|
|
27
|
+
let multiRelatedFieldsObjectsMap;
|
|
28
|
+
const initMultiRelatedFieldsObjectsMap = () => {
|
|
29
|
+
multiRelatedFieldsObjectsMap = /* @__PURE__ */ new Map();
|
|
30
|
+
this.typeObjects.forEach((typeObject) => {
|
|
31
|
+
typeObject.fieldObjects.forEach((fieldObject) => {
|
|
32
|
+
if (fieldObject.multiRelation && !fieldObject.typeObject.isEntityRef) {
|
|
33
|
+
const store = multiRelatedFieldsObjectsMap.get(fieldObject.multiRelation) || [];
|
|
34
|
+
store.push(fieldObject);
|
|
35
|
+
multiRelatedFieldsObjectsMap.set(fieldObject.multiRelation, store);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
this.typeObjects = rawTypeObjects.map((rawTypeObject) => factory.makeTypeObject({
|
|
41
|
+
rawTypeObject,
|
|
42
|
+
resolveTypeObject: (type) => this.typeObjectsByName[type] || null,
|
|
43
|
+
getTypeComponentTypeToFieldObject: (type) => getTypeComponentTypeToFieldObject().get(type),
|
|
44
|
+
resolveMultiRelatedFieldObjects: (multiRelation) => {
|
|
45
|
+
if (!multiRelatedFieldsObjectsMap) initMultiRelatedFieldsObjectsMap();
|
|
46
|
+
return multiRelatedFieldsObjectsMap.get(multiRelation) || [];
|
|
47
|
+
},
|
|
48
|
+
version
|
|
49
|
+
}));
|
|
50
|
+
this.typeObjectsById = factory.makeTypeObjectsById(this.typeObjects);
|
|
51
|
+
this.typeObjectsByName = factory.makeTypeObjectsByName(this.typeObjects);
|
|
52
|
+
this.id = id;
|
|
53
|
+
this.version = version;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
export { Schema };
|