@fibery/schema 8.1.0 → 8.1.2
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/package.json +2 -2
- package/types.d.ts +2 -0
- package/lib/index.js +0 -721
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/schema",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.2",
|
|
4
4
|
"description": "utils for working with fibery schema",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"browser": "./index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"babel-jest": "27.5.1",
|
|
21
21
|
"babel-loader": "8.2.5",
|
|
22
22
|
"@fibery/babel-preset": "7.2.0",
|
|
23
|
-
"@fibery/eslint-config": "8.
|
|
23
|
+
"@fibery/eslint-config": "8.2.0",
|
|
24
24
|
"@fibery/helpers": "1.0.2",
|
|
25
25
|
"jest": "27.5.1",
|
|
26
26
|
"jest-junit": "13.0.0",
|
package/types.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export type FieldObject = {
|
|
|
43
43
|
|
|
44
44
|
export type TypeObject = {
|
|
45
45
|
name: string;
|
|
46
|
+
description: string | null;
|
|
46
47
|
id: string;
|
|
47
48
|
idField: string;
|
|
48
49
|
publicIdField: string;
|
|
@@ -71,6 +72,7 @@ export type TypeObject = {
|
|
|
71
72
|
fieldObjects: Array<FieldObject>;
|
|
72
73
|
fieldObjectsById: Record<string, FieldObject>;
|
|
73
74
|
fieldObjectsByName: Record<string, FieldObject>;
|
|
75
|
+
typeComponentFieldObject: FieldObject | undefined;
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
export type Schema = {
|
package/lib/index.js
DELETED
|
@@ -1,721 +0,0 @@
|
|
|
1
|
-
/******/ (() => { // webpackBootstrap
|
|
2
|
-
/******/ "use strict";
|
|
3
|
-
/******/ // The require scope
|
|
4
|
-
/******/ var __webpack_require__ = {};
|
|
5
|
-
/******/
|
|
6
|
-
/************************************************************************/
|
|
7
|
-
/******/ /* webpack/runtime/compat get default export */
|
|
8
|
-
/******/ (() => {
|
|
9
|
-
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
10
|
-
/******/ __webpack_require__.n = (module) => {
|
|
11
|
-
/******/ var getter = module && module.__esModule ?
|
|
12
|
-
/******/ () => (module['default']) :
|
|
13
|
-
/******/ () => (module);
|
|
14
|
-
/******/ __webpack_require__.d(getter, { a: getter });
|
|
15
|
-
/******/ return getter;
|
|
16
|
-
/******/ };
|
|
17
|
-
/******/ })();
|
|
18
|
-
/******/
|
|
19
|
-
/******/ /* webpack/runtime/define property getters */
|
|
20
|
-
/******/ (() => {
|
|
21
|
-
/******/ // define getter functions for harmony exports
|
|
22
|
-
/******/ __webpack_require__.d = (exports, definition) => {
|
|
23
|
-
/******/ for(var key in definition) {
|
|
24
|
-
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
25
|
-
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
26
|
-
/******/ }
|
|
27
|
-
/******/ }
|
|
28
|
-
/******/ };
|
|
29
|
-
/******/ })();
|
|
30
|
-
/******/
|
|
31
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
32
|
-
/******/ (() => {
|
|
33
|
-
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
34
|
-
/******/ })();
|
|
35
|
-
/******/
|
|
36
|
-
/******/ /* webpack/runtime/make namespace object */
|
|
37
|
-
/******/ (() => {
|
|
38
|
-
/******/ // define __esModule on exports
|
|
39
|
-
/******/ __webpack_require__.r = (exports) => {
|
|
40
|
-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
41
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
42
|
-
/******/ }
|
|
43
|
-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
44
|
-
/******/ };
|
|
45
|
-
/******/ })();
|
|
46
|
-
/******/
|
|
47
|
-
/************************************************************************/
|
|
48
|
-
var __webpack_exports__ = {};
|
|
49
|
-
// ESM COMPAT FLAG
|
|
50
|
-
__webpack_require__.r(__webpack_exports__);
|
|
51
|
-
|
|
52
|
-
// EXPORTS
|
|
53
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
54
|
-
"factory": () => (/* binding */ factory),
|
|
55
|
-
"protectiveFactory": () => (/* binding */ protectiveFactory)
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
;// CONCATENATED MODULE: external "lodash"
|
|
59
|
-
const external_lodash_namespaceObject = require("lodash");
|
|
60
|
-
var external_lodash_default = /*#__PURE__*/__webpack_require__.n(external_lodash_namespaceObject);
|
|
61
|
-
;// CONCATENATED MODULE: external "util"
|
|
62
|
-
const external_util_namespaceObject = require("util");
|
|
63
|
-
;// CONCATENATED MODULE: external "memoize-one"
|
|
64
|
-
const external_memoize_one_namespaceObject = require("memoize-one");
|
|
65
|
-
var external_memoize_one_default = /*#__PURE__*/__webpack_require__.n(external_memoize_one_namespaceObject);
|
|
66
|
-
;// CONCATENATED MODULE: ../helpers/utils/trace.ts
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const formatWithCustomInspectParams = values => {
|
|
70
|
-
return values.map(value => {
|
|
71
|
-
if (typeof value === "object") {
|
|
72
|
-
return util.inspect(value, {
|
|
73
|
-
showHidden: false,
|
|
74
|
-
depth: null,
|
|
75
|
-
maxArrayLength: null
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return value;
|
|
80
|
-
}).join(" ");
|
|
81
|
-
};
|
|
82
|
-
function assert(condition, ...args) {
|
|
83
|
-
if (!condition) {
|
|
84
|
-
const message = args.length > 0 ? formatWithCustomInspectParams(args) : "Assertion failed with no details";
|
|
85
|
-
throw new Error(message);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function assertWithTraceError(condition, ...args) {
|
|
89
|
-
if (!condition) {
|
|
90
|
-
const message = args.length > 0 ? formatWithCustomInspectParams(args) : "Assertion failed with no details";
|
|
91
|
-
traceError(message);
|
|
92
|
-
}
|
|
93
|
-
} // eslint-disable-next-line no-console
|
|
94
|
-
|
|
95
|
-
let traceErrorSubscribers = [console.error.bind(console)];
|
|
96
|
-
let overridden = false;
|
|
97
|
-
function subscribeOnTraceError(fn) {
|
|
98
|
-
if (overridden) {
|
|
99
|
-
throw new Error("cannot subscribe while overridden");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
traceErrorSubscribers.push(fn);
|
|
103
|
-
let unsubscribed = false;
|
|
104
|
-
return function unsubscribe() {
|
|
105
|
-
assert(!unsubscribed, "Cannot unsubscribe more than once");
|
|
106
|
-
unsubscribed = true;
|
|
107
|
-
traceErrorSubscribers = traceErrorSubscribers.filter(x => x !== fn);
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
const traceError = external_memoize_one_default()(function traceError(...args) {
|
|
111
|
-
traceErrorSubscribers.forEach(fn => {
|
|
112
|
-
fn(...args);
|
|
113
|
-
});
|
|
114
|
-
}); // eslint-disable-next-line no-console
|
|
115
|
-
|
|
116
|
-
let captureMessageSubscribers = [console.info.bind(console)];
|
|
117
|
-
function subscribeOnCaptureMessage(fn) {
|
|
118
|
-
captureMessageSubscribers.push(fn);
|
|
119
|
-
let unsubscribed = false;
|
|
120
|
-
return function unsubscribe() {
|
|
121
|
-
assert(!unsubscribed, "Cannot unsubscribe more than once");
|
|
122
|
-
unsubscribed = true;
|
|
123
|
-
captureMessageSubscribers = captureMessageSubscribers.filter(x => x !== fn);
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
const captureMessage = external_memoize_one_default()(function captureMessage(...args) {
|
|
127
|
-
captureMessageSubscribers.forEach(fn => {
|
|
128
|
-
fn(...args);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
const tracedErrorTracker = {};
|
|
132
|
-
const traceErrorOncePerSession = (seed, err) => {
|
|
133
|
-
if (tracedErrorTracker[seed]) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
tracedErrorTracker[seed] = true;
|
|
138
|
-
const message = [seed, err].filter(Boolean).join(": ");
|
|
139
|
-
traceError(message);
|
|
140
|
-
};
|
|
141
|
-
const capturedMessageTracker = {};
|
|
142
|
-
const captureMessageOncePerSession = (seed, err) => {
|
|
143
|
-
if (capturedMessageTracker[seed]) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
capturedMessageTracker[seed] = true;
|
|
148
|
-
const message = [seed, err].filter(Boolean).join(": ");
|
|
149
|
-
captureMessage(message);
|
|
150
|
-
};
|
|
151
|
-
function withErrorTrace(f) {
|
|
152
|
-
return async function (...args) {
|
|
153
|
-
try {
|
|
154
|
-
return await f(...args);
|
|
155
|
-
} catch (err) {
|
|
156
|
-
traceError(err);
|
|
157
|
-
throw err;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
;// CONCATENATED MODULE: ./errors.js
|
|
162
|
-
class NotDefinedGetError extends Error {}
|
|
163
|
-
;// CONCATENATED MODULE: ./utils.js
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const jestKey = new Set(["nodeType", "tagName", "hasAttribute"]);
|
|
169
|
-
const withOnlyDefinedGets = (target, targetKind = "object") => new Proxy(target, {
|
|
170
|
-
get(target, key) {
|
|
171
|
-
if (!(key in target) && "production" !== "production") {}
|
|
172
|
-
|
|
173
|
-
return target[key];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const getNamePart = str => splitKeyword(str).name;
|
|
179
|
-
|
|
180
|
-
const capitalizeFirstChar = input => {
|
|
181
|
-
const str = input || "";
|
|
182
|
-
return str ? str.charAt(0).toUpperCase() + str.slice(1) : str;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const replaceTildes = str => (str || "").split("~").join(" ");
|
|
186
|
-
|
|
187
|
-
const toTypeOrFieldNamePartTitle = external_lodash_default().flow([capitalizeFirstChar, replaceTildes]);
|
|
188
|
-
const toTypeOrFieldTitle = external_lodash_default().flow([getNamePart, toTypeOrFieldNamePartTitle]);
|
|
189
|
-
const toPascalCase = (lispCasedString = "") => lispCasedString && external_lodash_default().last(lispCasedString.split("/")).split("-").map((external_lodash_default()).capitalize).join(" ");
|
|
190
|
-
|
|
191
|
-
const isObsoleteTitle = str => {
|
|
192
|
-
const {
|
|
193
|
-
name
|
|
194
|
-
} = splitKeyword(str);
|
|
195
|
-
return name.toLowerCase() === name && !hasTildes(name);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const hasTildes = str => str.includes("~");
|
|
199
|
-
|
|
200
|
-
const toNonEnumTitle = str => {
|
|
201
|
-
return isObsoleteTitle(str) ? toPascalCase(str) : toTypeOrFieldTitle(str);
|
|
202
|
-
};
|
|
203
|
-
const parseEnumType = type => {
|
|
204
|
-
const [templateType, targetType] = type.split("_");
|
|
205
|
-
const {
|
|
206
|
-
name: templateName,
|
|
207
|
-
namespace: templateNamespace
|
|
208
|
-
} = parseType(templateType);
|
|
209
|
-
const {
|
|
210
|
-
name: targetName,
|
|
211
|
-
namespace: targetNamespace
|
|
212
|
-
} = parseType(targetType);
|
|
213
|
-
return {
|
|
214
|
-
templateName,
|
|
215
|
-
templateNamespace,
|
|
216
|
-
targetName,
|
|
217
|
-
targetNamespace
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const toEnumTitle = type => {
|
|
222
|
-
// enum logic
|
|
223
|
-
const {
|
|
224
|
-
templateName,
|
|
225
|
-
targetName
|
|
226
|
-
} = parseEnumType(type);
|
|
227
|
-
return toTitle(targetName) + " " + toTitle(templateName);
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
const toTitle = typeOrAttr => {
|
|
231
|
-
const str = typeOrAttr || "";
|
|
232
|
-
return str.includes("_") ? toEnumTitle(str) : toNonEnumTitle(str);
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
const splitKeyword = keyword => {
|
|
236
|
-
const str = keyword || "";
|
|
237
|
-
const index = str.indexOf("/");
|
|
238
|
-
|
|
239
|
-
if (index === -1) {
|
|
240
|
-
return {
|
|
241
|
-
namespace: "",
|
|
242
|
-
name: str
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const namespace = str.substring(0, index);
|
|
247
|
-
const name = str.substring(index + 1);
|
|
248
|
-
return {
|
|
249
|
-
namespace,
|
|
250
|
-
name
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
const parseType = external_lodash_default().memoize(type => {
|
|
255
|
-
if (!type.includes("/")) {
|
|
256
|
-
traceError("parseType invalid usage: passed type is '".concat(type, "'"));
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return splitKeyword(type);
|
|
260
|
-
});
|
|
261
|
-
const makeEnumTypeNamePart = ({
|
|
262
|
-
holderType,
|
|
263
|
-
enumName
|
|
264
|
-
}) => {
|
|
265
|
-
const {
|
|
266
|
-
namespace,
|
|
267
|
-
name
|
|
268
|
-
} = parseType(holderType);
|
|
269
|
-
return "".concat(enumName, "_").concat(namespace, "/").concat(name);
|
|
270
|
-
};
|
|
271
|
-
const attachEnumNamespace = ({
|
|
272
|
-
enumNamespace,
|
|
273
|
-
typeNamePart
|
|
274
|
-
}) => {
|
|
275
|
-
return "".concat(enumNamespace, "/").concat(typeNamePart);
|
|
276
|
-
};
|
|
277
|
-
const removeDeletedTypesAndFields = rawSchema => {
|
|
278
|
-
const {
|
|
279
|
-
"fibery/types": rawTypeObjects,
|
|
280
|
-
...schemaRest
|
|
281
|
-
} = rawSchema;
|
|
282
|
-
const filteredRawTypeObjects = rawTypeObjects.filter(rawTypeObject => rawTypeObject["fibery/deleted?"] !== true).map(rawTypeObject => {
|
|
283
|
-
const {
|
|
284
|
-
"fibery/fields": rawFieldObjects,
|
|
285
|
-
...rawTypeObjectRest
|
|
286
|
-
} = rawTypeObject;
|
|
287
|
-
const filteredRawFieldObjects = rawFieldObjects.filter(rawFieldObject => rawFieldObject["fibery/deleted?"] !== true);
|
|
288
|
-
return { ...rawTypeObjectRest,
|
|
289
|
-
"fibery/fields": filteredRawFieldObjects
|
|
290
|
-
};
|
|
291
|
-
});
|
|
292
|
-
return { ...schemaRest,
|
|
293
|
-
"fibery/types": filteredRawTypeObjects
|
|
294
|
-
};
|
|
295
|
-
};
|
|
296
|
-
;// CONCATENATED MODULE: ./FieldObject.js
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
class FieldObject {
|
|
300
|
-
constructor({
|
|
301
|
-
rawFieldObject,
|
|
302
|
-
holderType,
|
|
303
|
-
resolveTypeObject,
|
|
304
|
-
version
|
|
305
|
-
}) {
|
|
306
|
-
if (!external_lodash_default().isPlainObject(rawFieldObject)) {
|
|
307
|
-
throw new Error("rawFieldObject arg must be plain object");
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
if (!external_lodash_default().isString(holderType)) {
|
|
311
|
-
throw new Error("holderType arg must be string");
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (!external_lodash_default().isFunction(resolveTypeObject)) {
|
|
315
|
-
throw new Error("resolveTypeObject arg must be function");
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
this.name = rawFieldObject["fibery/name"];
|
|
319
|
-
this.description = rawFieldObject["fibery/description"] || null;
|
|
320
|
-
this.id = rawFieldObject["fibery/id"];
|
|
321
|
-
this.type = rawFieldObject["fibery/type"];
|
|
322
|
-
const rawMeta = rawFieldObject["fibery/meta"] || {};
|
|
323
|
-
this.rawMeta = rawMeta;
|
|
324
|
-
this.holderType = holderType;
|
|
325
|
-
this.isCollection = rawMeta["fibery/collection?"] || false;
|
|
326
|
-
this.isTitle = rawMeta["ui/title?"] || false;
|
|
327
|
-
this.isId = rawMeta["fibery/id?"] || false;
|
|
328
|
-
this.isPublicId = rawMeta["fibery/public-id?"] || false;
|
|
329
|
-
this.isReadOnly = rawMeta["fibery/readonly?"] || false;
|
|
330
|
-
this.isFormula = rawMeta["formula/formula?"] || false;
|
|
331
|
-
this.isFormulaDisabled = rawMeta["formula/disabled?"] || false;
|
|
332
|
-
this.formulaDisableReason = rawMeta["formula/disable-reason"] || null;
|
|
333
|
-
this.formula = rawMeta["formula/formula"] || null;
|
|
334
|
-
this.isLookup = rawMeta["formula/lookup?"] || false;
|
|
335
|
-
this.hasLinkRule = rawMeta["link-rule/link-rule?"] || false;
|
|
336
|
-
this.linkRule = rawMeta["link-rule/link-rule"] || null;
|
|
337
|
-
this.relation = rawMeta["fibery/relation"] || null;
|
|
338
|
-
this.defaultValue = rawMeta["fibery/default-value"] || null;
|
|
339
|
-
this.objectEditorOrder = rawMeta["ui/object-editor-order"] || 0;
|
|
340
|
-
this.isRequired = rawMeta["fibery/required?"] === true;
|
|
341
|
-
this.isHidden = rawMeta["ui/hidden?"] === true;
|
|
342
|
-
this.isDeleted = rawFieldObject["fibery/deleted?"] || false;
|
|
343
|
-
this.disableLinkExistingItems = rawMeta["ui/disable-link-existing-items"] || false;
|
|
344
|
-
this.version = version;
|
|
345
|
-
Object.defineProperties(this, {
|
|
346
|
-
typeObject: {
|
|
347
|
-
configurable: false,
|
|
348
|
-
enumerable: true,
|
|
349
|
-
get: external_lodash_default().once(() => resolveTypeObject(this.type))
|
|
350
|
-
},
|
|
351
|
-
mixinTypeObject: {
|
|
352
|
-
configurable: false,
|
|
353
|
-
enumerable: true,
|
|
354
|
-
get: external_lodash_default().once(() => {
|
|
355
|
-
return this.holderTypeObject.installedMixinTypeObjects.find(mixinTypeObject => mixinTypeObject.fieldObjectsByName.hasOwnProperty(this.name) || this.name === "workflow/state" && mixinTypeObject.name === "workflow/workflow");
|
|
356
|
-
})
|
|
357
|
-
},
|
|
358
|
-
holderTypeObject: {
|
|
359
|
-
configurable: false,
|
|
360
|
-
enumerable: true,
|
|
361
|
-
get: external_lodash_default().once(() => {
|
|
362
|
-
return resolveTypeObject(holderType);
|
|
363
|
-
})
|
|
364
|
-
},
|
|
365
|
-
nameParts: {
|
|
366
|
-
configurable: false,
|
|
367
|
-
enumerable: true,
|
|
368
|
-
get: external_lodash_default().once(() => parseType(rawFieldObject["fibery/name"]))
|
|
369
|
-
},
|
|
370
|
-
title: {
|
|
371
|
-
configurable: false,
|
|
372
|
-
enumerable: true,
|
|
373
|
-
get: external_lodash_default().once(() => toNonEnumTitle(rawFieldObject["fibery/name"]))
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
get relatedFieldObject() {
|
|
379
|
-
const {
|
|
380
|
-
name,
|
|
381
|
-
relation
|
|
382
|
-
} = this;
|
|
383
|
-
|
|
384
|
-
if (!relation) {
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const selector = this.type !== this.holderType ? fieldObject => fieldObject.relation === relation : fieldObject => fieldObject.relation === relation && fieldObject.name !== name;
|
|
389
|
-
const fieldObject = this.typeObject.fieldObjects.find(selector);
|
|
390
|
-
|
|
391
|
-
if (!fieldObject) {
|
|
392
|
-
throw new Error("there no other end for relation ".concat(relation));
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return fieldObject;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
get cardinality() {
|
|
399
|
-
const {
|
|
400
|
-
isCollection,
|
|
401
|
-
relatedFieldObject,
|
|
402
|
-
typeObject
|
|
403
|
-
} = this;
|
|
404
|
-
|
|
405
|
-
if (typeObject.isPrimitive) {
|
|
406
|
-
throw new Error("Only non-basic fields have cardinality");
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (isCollection && this.rawMeta["fibery/field-reversed-collection?"]) {
|
|
410
|
-
return ":cardinality/many-to-many";
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (!relatedFieldObject) {
|
|
414
|
-
return isCollection ? ":cardinality/one-to-many" : ":cardinality/many-to-one";
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const isRelationCollection = relatedFieldObject.isCollection;
|
|
418
|
-
|
|
419
|
-
if (!isCollection && !isRelationCollection) {
|
|
420
|
-
return ":cardinality/one-to-one";
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
if (isCollection && !isRelationCollection) {
|
|
424
|
-
return ":cardinality/one-to-many";
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
if (!isCollection && isRelationCollection) {
|
|
428
|
-
return ":cardinality/many-to-one";
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
if (isCollection && isRelationCollection) {
|
|
432
|
-
return ":cardinality/many-to-many";
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
throw new Error("get cardinality invariant");
|
|
436
|
-
}
|
|
437
|
-
/** @deprecated use !typeObject.isPrimitive && cardinality === ... instead */
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
get kind() {
|
|
441
|
-
if (this.typeObject.isPrimitive) {
|
|
442
|
-
if (this.isCollection) {
|
|
443
|
-
throw new Error("basic collection is not implemented");
|
|
444
|
-
} else {
|
|
445
|
-
return ":field/basic";
|
|
446
|
-
}
|
|
447
|
-
} else {
|
|
448
|
-
if (this.isCollection) {
|
|
449
|
-
return ":field/reference-collection";
|
|
450
|
-
} else {
|
|
451
|
-
return ":field/reference";
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
;// CONCATENATED MODULE: ./Schema.js
|
|
458
|
-
class Schema {
|
|
459
|
-
constructor({
|
|
460
|
-
factory,
|
|
461
|
-
rawSchema: {
|
|
462
|
-
"fibery/id": id,
|
|
463
|
-
"fibery/types": rawTypeObjects,
|
|
464
|
-
"fibery/version": version
|
|
465
|
-
}
|
|
466
|
-
}) {
|
|
467
|
-
if (!Array.isArray(rawTypeObjects)) {
|
|
468
|
-
throw new Error("rawTypeObjects arg must be array");
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
Object.defineProperties(this, {
|
|
472
|
-
toJSON: {
|
|
473
|
-
value: () => ({
|
|
474
|
-
"fibery/types": rawTypeObjects,
|
|
475
|
-
"fibery/meta": {
|
|
476
|
-
"fibery/version": version
|
|
477
|
-
}
|
|
478
|
-
}),
|
|
479
|
-
enumerable: false
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
this.typeObjects = rawTypeObjects.map(rawTypeObject => factory.makeTypeObject({
|
|
483
|
-
rawTypeObject,
|
|
484
|
-
resolveTypeObject: type => this.typeObjectsByName[type] || null,
|
|
485
|
-
version
|
|
486
|
-
}));
|
|
487
|
-
this.typeObjectsById = factory.makeTypeObjectsById(this.typeObjects);
|
|
488
|
-
this.typeObjectsByName = factory.makeTypeObjectsByName(this.typeObjects);
|
|
489
|
-
this.id = id;
|
|
490
|
-
this.version = version;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
;// CONCATENATED MODULE: external "pluralize"
|
|
495
|
-
const external_pluralize_namespaceObject = require("pluralize");
|
|
496
|
-
var external_pluralize_default = /*#__PURE__*/__webpack_require__.n(external_pluralize_namespaceObject);
|
|
497
|
-
;// CONCATENATED MODULE: ./TypeObject.js
|
|
498
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
class TypeObject {
|
|
504
|
-
constructor({
|
|
505
|
-
rawTypeObject,
|
|
506
|
-
resolveTypeObject,
|
|
507
|
-
version,
|
|
508
|
-
factory
|
|
509
|
-
}) {
|
|
510
|
-
_defineProperty(this, "_getFieldObjectShortcuts", external_lodash_default().once(() => {
|
|
511
|
-
const hasRank = this.installedMixins.has("fibery/rank-mixin");
|
|
512
|
-
return this.fieldObjects.reduce((result, fieldObject) => {
|
|
513
|
-
if (fieldObject.isId) {
|
|
514
|
-
result.idField = fieldObject.name;
|
|
515
|
-
result.idFieldObject = fieldObject;
|
|
516
|
-
} else if (fieldObject.isPublicId) {
|
|
517
|
-
result.publicIdField = fieldObject.name;
|
|
518
|
-
result.publicIdFieldObject = fieldObject;
|
|
519
|
-
} else if (fieldObject.isTitle) {
|
|
520
|
-
result.titleField = fieldObject.name;
|
|
521
|
-
result.titleFieldObject = fieldObject;
|
|
522
|
-
} else if (hasRank && fieldObject.name === "fibery/rank") {
|
|
523
|
-
result.rankField = fieldObject.name;
|
|
524
|
-
result.rankFieldObject = fieldObject;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
return result;
|
|
528
|
-
}, {
|
|
529
|
-
idField: null,
|
|
530
|
-
idFieldObject: null,
|
|
531
|
-
publicIdField: null,
|
|
532
|
-
publicIdFieldObject: null,
|
|
533
|
-
titleField: null,
|
|
534
|
-
titleFieldObject: null,
|
|
535
|
-
rankField: null,
|
|
536
|
-
rankFieldObject: null
|
|
537
|
-
});
|
|
538
|
-
}));
|
|
539
|
-
|
|
540
|
-
if (!external_lodash_default().isPlainObject(rawTypeObject)) {
|
|
541
|
-
throw new Error("rawTypeObject arg must be plain object");
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
if (!external_lodash_default().isFunction(resolveTypeObject)) {
|
|
545
|
-
throw new Error("resolveTypeObject arg must be function");
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
this.name = rawTypeObject["fibery/name"];
|
|
549
|
-
this.id = rawTypeObject["fibery/id"];
|
|
550
|
-
const rawMeta = rawTypeObject["fibery/meta"] || {};
|
|
551
|
-
this.rawMeta = rawMeta;
|
|
552
|
-
this.isDomain = rawMeta["fibery/domain?"] || false;
|
|
553
|
-
this.isMixin = rawMeta["app/mixin?"] || false;
|
|
554
|
-
this.mixinIcon = rawMeta["ui/mixin-icon"] || null;
|
|
555
|
-
this.isEnum = rawMeta["fibery/enum?"] || false;
|
|
556
|
-
this.isPrimitive = rawMeta["fibery/primitive?"] || false;
|
|
557
|
-
this.isWriterModeByDefault = rawMeta["ui/writer-mode?"] || false;
|
|
558
|
-
this.isDeleted = rawTypeObject["fibery/deleted?"] || false;
|
|
559
|
-
this.nameParts = parseType(this.name);
|
|
560
|
-
this.color = rawMeta["ui/color"] || "#4568FB";
|
|
561
|
-
this.units = rawMeta["ui/units"] || null;
|
|
562
|
-
this.installedMixins = new Set(Object.keys(rawMeta["app/mixins"] || {}));
|
|
563
|
-
this.syncSource = rawMeta["sync/source"] || null;
|
|
564
|
-
this.version = version;
|
|
565
|
-
|
|
566
|
-
const fieldObjectsByNameOnceGetter = external_lodash_default().once(() => {
|
|
567
|
-
return factory.makeFieldObjectsByName({
|
|
568
|
-
type: this.name,
|
|
569
|
-
fieldObjects: this.fieldObjects
|
|
570
|
-
});
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
const fieldObjectsGetter = external_lodash_default().once(() => rawTypeObject["fibery/fields"].map(rawFieldObject => {
|
|
574
|
-
return factory.makeFieldObject({
|
|
575
|
-
rawFieldObject,
|
|
576
|
-
holderType: this.name,
|
|
577
|
-
resolveTypeObject,
|
|
578
|
-
version
|
|
579
|
-
});
|
|
580
|
-
}));
|
|
581
|
-
|
|
582
|
-
Object.defineProperties(this, {
|
|
583
|
-
toJSON: {
|
|
584
|
-
value() {
|
|
585
|
-
if (false) {}
|
|
586
|
-
|
|
587
|
-
return rawTypeObject;
|
|
588
|
-
},
|
|
589
|
-
|
|
590
|
-
enumerable: false
|
|
591
|
-
},
|
|
592
|
-
fieldObjects: {
|
|
593
|
-
configurable: false,
|
|
594
|
-
enumerable: true,
|
|
595
|
-
get: fieldObjectsGetter
|
|
596
|
-
},
|
|
597
|
-
fieldObjectsById: {
|
|
598
|
-
configurable: false,
|
|
599
|
-
enumerable: true,
|
|
600
|
-
get: external_lodash_default().once(() => {
|
|
601
|
-
return factory.makeFieldObjectsById({
|
|
602
|
-
type: this.name,
|
|
603
|
-
fieldObjects: this.fieldObjects
|
|
604
|
-
});
|
|
605
|
-
})
|
|
606
|
-
},
|
|
607
|
-
fieldObjectsByName: {
|
|
608
|
-
configurable: false,
|
|
609
|
-
enumerable: true,
|
|
610
|
-
get: fieldObjectsByNameOnceGetter
|
|
611
|
-
},
|
|
612
|
-
installedMixinTypeObjects: {
|
|
613
|
-
configurable: false,
|
|
614
|
-
enumerable: true,
|
|
615
|
-
get: external_lodash_default().once(() => [...this.installedMixins].map(resolveTypeObject))
|
|
616
|
-
},
|
|
617
|
-
title: {
|
|
618
|
-
configurable: false,
|
|
619
|
-
enumerable: true,
|
|
620
|
-
get: external_lodash_default().once(() => toTitle(this.name))
|
|
621
|
-
},
|
|
622
|
-
pluralTitle: {
|
|
623
|
-
configurable: false,
|
|
624
|
-
enumerable: true,
|
|
625
|
-
get: external_lodash_default().once(() => toTitle(external_pluralize_default().plural(this.name)))
|
|
626
|
-
}
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
get idField() {
|
|
631
|
-
return this._getFieldObjectShortcuts().idField;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
get idFieldObject() {
|
|
635
|
-
return this._getFieldObjectShortcuts().idFieldObject;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
get publicIdField() {
|
|
639
|
-
return this._getFieldObjectShortcuts().publicIdField;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
get publicIdFieldObject() {
|
|
643
|
-
return this._getFieldObjectShortcuts().publicIdFieldObject;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
get titleField() {
|
|
647
|
-
return this._getFieldObjectShortcuts().titleField;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
get titleFieldObject() {
|
|
651
|
-
return this._getFieldObjectShortcuts().titleFieldObject;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
get rankField() {
|
|
655
|
-
return this._getFieldObjectShortcuts().rankField;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
get rankFieldObject() {
|
|
659
|
-
return this._getFieldObjectShortcuts().rankFieldObject;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
}
|
|
663
|
-
;// CONCATENATED MODULE: ./index.js
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
const factory = {
|
|
670
|
-
makeSchema: (rawSchema, options = {
|
|
671
|
-
shouldRemoveDeletedTypesAndFields: true
|
|
672
|
-
}) => new Schema({
|
|
673
|
-
rawSchema: options.shouldRemoveDeletedTypesAndFields ? removeDeletedTypesAndFields(rawSchema) : rawSchema,
|
|
674
|
-
factory
|
|
675
|
-
}),
|
|
676
|
-
makeTypeObject: args => new TypeObject({ ...args,
|
|
677
|
-
factory
|
|
678
|
-
}),
|
|
679
|
-
makeTypeObjectsById: typeObjects => external_lodash_default().keyBy(typeObjects, x => x.id),
|
|
680
|
-
makeTypeObjectsByName: typeObjects => external_lodash_default().keyBy(typeObjects, x => x.name),
|
|
681
|
-
makeFieldObject: args => new FieldObject(args),
|
|
682
|
-
makeFieldObjectsById: ({
|
|
683
|
-
type,
|
|
684
|
-
fieldObjects
|
|
685
|
-
}) => external_lodash_default().keyBy(fieldObjects, x => x.id),
|
|
686
|
-
makeFieldObjectsByName: ({
|
|
687
|
-
type,
|
|
688
|
-
fieldObjects
|
|
689
|
-
}) => external_lodash_default().keyBy(fieldObjects, x => x.name)
|
|
690
|
-
};
|
|
691
|
-
const protectiveFactory = {
|
|
692
|
-
makeSchema: (rawSchema, options = {
|
|
693
|
-
shouldRemoveDeletedTypesAndFields: true
|
|
694
|
-
}) => withOnlyDefinedGets(new Schema({
|
|
695
|
-
rawSchema: options.shouldRemoveDeletedTypesAndFields ? removeDeletedTypesAndFields(rawSchema) : rawSchema,
|
|
696
|
-
factory: protectiveFactory
|
|
697
|
-
}), "schema"),
|
|
698
|
-
makeTypeObject: args => {
|
|
699
|
-
const typeObject = new TypeObject({ ...args,
|
|
700
|
-
factory: protectiveFactory
|
|
701
|
-
});
|
|
702
|
-
return withOnlyDefinedGets(typeObject, "schema.typeObjectsByName[\"".concat(typeObject.name, "\"]"));
|
|
703
|
-
},
|
|
704
|
-
makeTypeObjectsById: typeObjects => withOnlyDefinedGets(external_lodash_default().keyBy(typeObjects, x => x.id), "schema.typeObjectsById"),
|
|
705
|
-
makeTypeObjectsByName: typeObjects => withOnlyDefinedGets(external_lodash_default().keyBy(typeObjects, x => x.name), "schema.typeObjectsByName"),
|
|
706
|
-
makeFieldObject: args => {
|
|
707
|
-
const fieldObject = new FieldObject(args);
|
|
708
|
-
return withOnlyDefinedGets(fieldObject, "schema.typeObjectsByName[\"".concat(fieldObject.holderType, "\"].fieldObjectsByName[\"").concat(fieldObject.name, "\"]"));
|
|
709
|
-
},
|
|
710
|
-
makeFieldObjectsById: ({
|
|
711
|
-
type,
|
|
712
|
-
fieldObjects
|
|
713
|
-
}) => withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.id), "schema.typeObjectsByName[\"".concat(type, "\"].fieldObjectsById")),
|
|
714
|
-
makeFieldObjectsByName: ({
|
|
715
|
-
type,
|
|
716
|
-
fieldObjects
|
|
717
|
-
}) => withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.name), "schema.typeObjectsByName[\"".concat(type, "\"].fieldObjectsByName"))
|
|
718
|
-
};
|
|
719
|
-
module.exports = __webpack_exports__;
|
|
720
|
-
/******/ })()
|
|
721
|
-
;
|