@fibery/schema 8.1.4 → 8.1.6
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.js +140 -146
- package/package.json +8 -7
- package/types.d.ts +1 -0
package/lib/index.js
CHANGED
|
@@ -75,30 +75,35 @@ const formatWithCustomInspectParams = values => {
|
|
|
75
75
|
maxArrayLength: null
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
|
|
79
78
|
return value;
|
|
80
79
|
}).join(" ");
|
|
81
80
|
};
|
|
82
|
-
function assert(condition
|
|
81
|
+
function assert(condition) {
|
|
83
82
|
if (!condition) {
|
|
83
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
84
|
+
args[_key - 1] = arguments[_key];
|
|
85
|
+
}
|
|
84
86
|
const message = args.length > 0 ? formatWithCustomInspectParams(args) : `Assertion failed with no details`;
|
|
85
87
|
throw new Error(message);
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
|
-
function assertWithTraceError(condition
|
|
90
|
+
function assertWithTraceError(condition) {
|
|
89
91
|
if (!condition) {
|
|
92
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
93
|
+
args[_key2 - 1] = arguments[_key2];
|
|
94
|
+
}
|
|
90
95
|
const message = args.length > 0 ? formatWithCustomInspectParams(args) : `Assertion failed with no details`;
|
|
91
96
|
traceError(message);
|
|
92
97
|
}
|
|
93
|
-
}
|
|
98
|
+
}
|
|
94
99
|
|
|
100
|
+
// eslint-disable-next-line no-console
|
|
95
101
|
let traceErrorSubscribers = [console.error.bind(console)];
|
|
96
102
|
const overridden = false;
|
|
97
103
|
function subscribeOnTraceError(fn) {
|
|
98
104
|
if (overridden) {
|
|
99
105
|
throw new Error("cannot subscribe while overridden");
|
|
100
106
|
}
|
|
101
|
-
|
|
102
107
|
traceErrorSubscribers.push(fn);
|
|
103
108
|
let unsubscribed = false;
|
|
104
109
|
return function unsubscribe() {
|
|
@@ -107,12 +112,16 @@ function subscribeOnTraceError(fn) {
|
|
|
107
112
|
traceErrorSubscribers = traceErrorSubscribers.filter(x => x !== fn);
|
|
108
113
|
};
|
|
109
114
|
}
|
|
110
|
-
const traceError = external_memoize_one_default()(function traceError(
|
|
115
|
+
const traceError = external_memoize_one_default()(function traceError() {
|
|
116
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
117
|
+
args[_key3] = arguments[_key3];
|
|
118
|
+
}
|
|
111
119
|
traceErrorSubscribers.forEach(fn => {
|
|
112
120
|
fn(...args);
|
|
113
121
|
});
|
|
114
|
-
});
|
|
122
|
+
});
|
|
115
123
|
|
|
124
|
+
// eslint-disable-next-line no-console
|
|
116
125
|
let captureMessageSubscribers = [console.info.bind(console)];
|
|
117
126
|
function subscribeOnCaptureMessage(fn) {
|
|
118
127
|
captureMessageSubscribers.push(fn);
|
|
@@ -123,7 +132,10 @@ function subscribeOnCaptureMessage(fn) {
|
|
|
123
132
|
captureMessageSubscribers = captureMessageSubscribers.filter(x => x !== fn);
|
|
124
133
|
};
|
|
125
134
|
}
|
|
126
|
-
const captureMessage = external_memoize_one_default()(function captureMessage(
|
|
135
|
+
const captureMessage = external_memoize_one_default()(function captureMessage() {
|
|
136
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
137
|
+
args[_key4] = arguments[_key4];
|
|
138
|
+
}
|
|
127
139
|
captureMessageSubscribers.forEach(fn => {
|
|
128
140
|
fn(...args);
|
|
129
141
|
});
|
|
@@ -133,7 +145,6 @@ const traceErrorOncePerSession = (seed, err) => {
|
|
|
133
145
|
if (tracedErrorTracker[seed]) {
|
|
134
146
|
return;
|
|
135
147
|
}
|
|
136
|
-
|
|
137
148
|
tracedErrorTracker[seed] = true;
|
|
138
149
|
const message = [seed, err].filter(Boolean).join(": ");
|
|
139
150
|
traceError(message);
|
|
@@ -143,15 +154,14 @@ const captureMessageOncePerSession = (seed, err) => {
|
|
|
143
154
|
if (capturedMessageTracker[seed]) {
|
|
144
155
|
return;
|
|
145
156
|
}
|
|
146
|
-
|
|
147
157
|
capturedMessageTracker[seed] = true;
|
|
148
158
|
const message = [seed, err].filter(Boolean).join(": ");
|
|
149
159
|
captureMessage(message);
|
|
150
160
|
};
|
|
151
161
|
function withErrorTrace(f) {
|
|
152
|
-
return async function (
|
|
162
|
+
return async function () {
|
|
153
163
|
try {
|
|
154
|
-
return await f(...
|
|
164
|
+
return await f(...arguments);
|
|
155
165
|
} catch (err) {
|
|
156
166
|
traceError(err);
|
|
157
167
|
throw err;
|
|
@@ -166,37 +176,34 @@ class NotDefinedGetError extends Error {}
|
|
|
166
176
|
|
|
167
177
|
|
|
168
178
|
const jestKey = new Set(["nodeType", "tagName", "hasAttribute"]);
|
|
169
|
-
const withOnlyDefinedGets = (target
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
});
|
|
177
|
-
|
|
179
|
+
const withOnlyDefinedGets = function (target) {
|
|
180
|
+
let targetKind = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "object";
|
|
181
|
+
return new Proxy(target, {
|
|
182
|
+
get(target, key) {
|
|
183
|
+
if (!(key in target) && "production" !== "production") {}
|
|
184
|
+
return target[key];
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
};
|
|
178
188
|
const getNamePart = str => splitKeyword(str).name;
|
|
179
|
-
|
|
180
189
|
const capitalizeFirstChar = input => {
|
|
181
190
|
const str = input || "";
|
|
182
191
|
return str ? str.charAt(0).toUpperCase() + str.slice(1) : str;
|
|
183
192
|
};
|
|
184
|
-
|
|
185
193
|
const replaceTildes = str => (str || "").split("~").join(" ");
|
|
186
|
-
|
|
187
194
|
const toTypeOrFieldNamePartTitle = external_lodash_default().flow([capitalizeFirstChar, replaceTildes]);
|
|
188
195
|
const toTypeOrFieldTitle = external_lodash_default().flow([getNamePart, toTypeOrFieldNamePartTitle]);
|
|
189
|
-
const toPascalCase =
|
|
190
|
-
|
|
196
|
+
const toPascalCase = function () {
|
|
197
|
+
let lispCasedString = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
198
|
+
return lispCasedString && external_lodash_default().last(lispCasedString.split("/")).split("-").map((external_lodash_default()).capitalize).join(" ");
|
|
199
|
+
};
|
|
191
200
|
const isObsoleteTitle = str => {
|
|
192
201
|
const {
|
|
193
202
|
name
|
|
194
203
|
} = splitKeyword(str);
|
|
195
204
|
return name.toLowerCase() === name && !hasTildes(name);
|
|
196
205
|
};
|
|
197
|
-
|
|
198
206
|
const hasTildes = str => str.includes("~");
|
|
199
|
-
|
|
200
207
|
const toNonEnumTitle = str => {
|
|
201
208
|
return isObsoleteTitle(str) ? toPascalCase(str) : toTypeOrFieldTitle(str);
|
|
202
209
|
};
|
|
@@ -217,7 +224,6 @@ const parseEnumType = type => {
|
|
|
217
224
|
targetNamespace
|
|
218
225
|
};
|
|
219
226
|
};
|
|
220
|
-
|
|
221
227
|
const toEnumTitle = type => {
|
|
222
228
|
// enum logic
|
|
223
229
|
const {
|
|
@@ -226,23 +232,19 @@ const toEnumTitle = type => {
|
|
|
226
232
|
} = parseEnumType(type);
|
|
227
233
|
return toTitle(targetName) + " " + toTitle(templateName);
|
|
228
234
|
};
|
|
229
|
-
|
|
230
235
|
const toTitle = typeOrAttr => {
|
|
231
236
|
const str = typeOrAttr || "";
|
|
232
237
|
return str.includes("_") ? toEnumTitle(str) : toNonEnumTitle(str);
|
|
233
238
|
};
|
|
234
|
-
|
|
235
239
|
const splitKeyword = keyword => {
|
|
236
240
|
const str = keyword || "";
|
|
237
241
|
const index = str.indexOf("/");
|
|
238
|
-
|
|
239
242
|
if (index === -1) {
|
|
240
243
|
return {
|
|
241
244
|
namespace: "",
|
|
242
245
|
name: str
|
|
243
246
|
};
|
|
244
247
|
}
|
|
245
|
-
|
|
246
248
|
const namespace = str.substring(0, index);
|
|
247
249
|
const name = str.substring(index + 1);
|
|
248
250
|
return {
|
|
@@ -250,28 +252,28 @@ const splitKeyword = keyword => {
|
|
|
250
252
|
name
|
|
251
253
|
};
|
|
252
254
|
};
|
|
253
|
-
|
|
254
255
|
const parseType = external_lodash_default().memoize(type => {
|
|
255
256
|
if (!type.includes("/")) {
|
|
256
257
|
traceError(`parseType invalid usage: passed type is '${type}'`);
|
|
257
258
|
}
|
|
258
|
-
|
|
259
259
|
return splitKeyword(type);
|
|
260
260
|
});
|
|
261
|
-
const makeEnumTypeNamePart =
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
const makeEnumTypeNamePart = _ref => {
|
|
262
|
+
let {
|
|
263
|
+
holderType,
|
|
264
|
+
enumName
|
|
265
|
+
} = _ref;
|
|
265
266
|
const {
|
|
266
267
|
namespace,
|
|
267
268
|
name
|
|
268
269
|
} = parseType(holderType);
|
|
269
270
|
return `${enumName}_${namespace}/${name}`;
|
|
270
271
|
};
|
|
271
|
-
const attachEnumNamespace =
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
272
|
+
const attachEnumNamespace = _ref2 => {
|
|
273
|
+
let {
|
|
274
|
+
enumNamespace,
|
|
275
|
+
typeNamePart
|
|
276
|
+
} = _ref2;
|
|
275
277
|
return `${enumNamespace}/${typeNamePart}`;
|
|
276
278
|
};
|
|
277
279
|
const removeDeletedTypesAndFields = rawSchema => {
|
|
@@ -285,11 +287,13 @@ const removeDeletedTypesAndFields = rawSchema => {
|
|
|
285
287
|
...rawTypeObjectRest
|
|
286
288
|
} = rawTypeObject;
|
|
287
289
|
const filteredRawFieldObjects = rawFieldObjects.filter(rawFieldObject => rawFieldObject["fibery/deleted?"] !== true);
|
|
288
|
-
return {
|
|
290
|
+
return {
|
|
291
|
+
...rawTypeObjectRest,
|
|
289
292
|
"fibery/fields": filteredRawFieldObjects
|
|
290
293
|
};
|
|
291
294
|
});
|
|
292
|
-
return {
|
|
295
|
+
return {
|
|
296
|
+
...schemaRest,
|
|
293
297
|
"fibery/types": filteredRawTypeObjects
|
|
294
298
|
};
|
|
295
299
|
};
|
|
@@ -297,24 +301,22 @@ const removeDeletedTypesAndFields = rawSchema => {
|
|
|
297
301
|
|
|
298
302
|
|
|
299
303
|
class FieldObject {
|
|
300
|
-
constructor({
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
304
|
+
constructor(_ref) {
|
|
305
|
+
let {
|
|
306
|
+
rawFieldObject,
|
|
307
|
+
holderType,
|
|
308
|
+
resolveTypeObject,
|
|
309
|
+
version
|
|
310
|
+
} = _ref;
|
|
306
311
|
if (!external_lodash_default().isPlainObject(rawFieldObject)) {
|
|
307
312
|
throw new Error("rawFieldObject arg must be plain object");
|
|
308
313
|
}
|
|
309
|
-
|
|
310
314
|
if (!external_lodash_default().isString(holderType)) {
|
|
311
315
|
throw new Error("holderType arg must be string");
|
|
312
316
|
}
|
|
313
|
-
|
|
314
317
|
if (!external_lodash_default().isFunction(resolveTypeObject)) {
|
|
315
318
|
throw new Error("resolveTypeObject arg must be function");
|
|
316
319
|
}
|
|
317
|
-
|
|
318
320
|
this.name = rawFieldObject["fibery/name"];
|
|
319
321
|
this.description = rawFieldObject["fibery/description"] || null;
|
|
320
322
|
this.id = rawFieldObject["fibery/id"];
|
|
@@ -334,6 +336,8 @@ class FieldObject {
|
|
|
334
336
|
this.isLookup = rawMeta["formula/lookup?"] || false;
|
|
335
337
|
this.hasLinkRule = rawMeta["link-rule/link-rule?"] || false;
|
|
336
338
|
this.linkRule = rawMeta["link-rule/link-rule"] || null;
|
|
339
|
+
this.isLinkRuleDisabled = rawMeta["link-rule/disabled?"] || false;
|
|
340
|
+
this.linkRuleDisableReason = rawMeta["link-rule/disable-reason"] || null;
|
|
337
341
|
this.relation = rawMeta["fibery/relation"] || null;
|
|
338
342
|
this.defaultValue = rawMeta["fibery/default-value"] || null;
|
|
339
343
|
this.objectEditorOrder = rawMeta["ui/object-editor-order"] || 0;
|
|
@@ -374,69 +378,53 @@ class FieldObject {
|
|
|
374
378
|
}
|
|
375
379
|
});
|
|
376
380
|
}
|
|
377
|
-
|
|
378
381
|
get relatedFieldObject() {
|
|
379
382
|
const {
|
|
380
383
|
name,
|
|
381
384
|
relation
|
|
382
385
|
} = this;
|
|
383
|
-
|
|
384
386
|
if (!relation) {
|
|
385
387
|
return null;
|
|
386
388
|
}
|
|
387
|
-
|
|
388
389
|
const selector = this.type !== this.holderType ? fieldObject => fieldObject.relation === relation : fieldObject => fieldObject.relation === relation && fieldObject.name !== name;
|
|
389
390
|
const fieldObject = this.typeObject.fieldObjects.find(selector);
|
|
390
|
-
|
|
391
391
|
if (!fieldObject) {
|
|
392
392
|
throw new Error(`there no other end for relation ${relation}`);
|
|
393
393
|
}
|
|
394
|
-
|
|
395
394
|
return fieldObject;
|
|
396
395
|
}
|
|
397
|
-
|
|
398
396
|
get cardinality() {
|
|
399
397
|
const {
|
|
400
398
|
isCollection,
|
|
401
399
|
relatedFieldObject,
|
|
402
400
|
typeObject
|
|
403
401
|
} = this;
|
|
404
|
-
|
|
405
402
|
if (typeObject.isPrimitive) {
|
|
406
403
|
throw new Error("Only non-basic fields have cardinality");
|
|
407
404
|
}
|
|
408
|
-
|
|
409
405
|
if (isCollection && this.rawMeta["fibery/field-reversed-collection?"]) {
|
|
410
406
|
return ":cardinality/many-to-many";
|
|
411
407
|
}
|
|
412
|
-
|
|
413
408
|
if (!relatedFieldObject) {
|
|
414
409
|
return isCollection ? ":cardinality/one-to-many" : ":cardinality/many-to-one";
|
|
415
410
|
}
|
|
416
|
-
|
|
417
411
|
const isRelationCollection = relatedFieldObject.isCollection;
|
|
418
|
-
|
|
419
412
|
if (!isCollection && !isRelationCollection) {
|
|
420
413
|
return ":cardinality/one-to-one";
|
|
421
414
|
}
|
|
422
|
-
|
|
423
415
|
if (isCollection && !isRelationCollection) {
|
|
424
416
|
return ":cardinality/one-to-many";
|
|
425
417
|
}
|
|
426
|
-
|
|
427
418
|
if (!isCollection && isRelationCollection) {
|
|
428
419
|
return ":cardinality/many-to-one";
|
|
429
420
|
}
|
|
430
|
-
|
|
431
421
|
if (isCollection && isRelationCollection) {
|
|
432
422
|
return ":cardinality/many-to-many";
|
|
433
423
|
}
|
|
434
|
-
|
|
435
424
|
throw new Error("get cardinality invariant");
|
|
436
425
|
}
|
|
437
|
-
/** @deprecated use !typeObject.isPrimitive && cardinality === ... instead */
|
|
438
|
-
|
|
439
426
|
|
|
427
|
+
/** @deprecated use !typeObject.isPrimitive && cardinality === ... instead */
|
|
440
428
|
get kind() {
|
|
441
429
|
if (this.typeObject.isPrimitive) {
|
|
442
430
|
if (this.isCollection) {
|
|
@@ -452,22 +440,22 @@ class FieldObject {
|
|
|
452
440
|
}
|
|
453
441
|
}
|
|
454
442
|
}
|
|
455
|
-
|
|
456
443
|
}
|
|
457
444
|
;// CONCATENATED MODULE: ./Schema.js
|
|
445
|
+
|
|
458
446
|
class Schema {
|
|
459
|
-
constructor({
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
447
|
+
constructor(_ref) {
|
|
448
|
+
let {
|
|
449
|
+
factory,
|
|
450
|
+
rawSchema: {
|
|
451
|
+
"fibery/id": id,
|
|
452
|
+
"fibery/types": rawTypeObjects,
|
|
453
|
+
"fibery/version": version
|
|
454
|
+
}
|
|
455
|
+
} = _ref;
|
|
467
456
|
if (!Array.isArray(rawTypeObjects)) {
|
|
468
457
|
throw new Error("rawTypeObjects arg must be array");
|
|
469
458
|
}
|
|
470
|
-
|
|
471
459
|
Object.defineProperties(this, {
|
|
472
460
|
toJSON: {
|
|
473
461
|
value: () => ({
|
|
@@ -479,42 +467,46 @@ class Schema {
|
|
|
479
467
|
enumerable: false
|
|
480
468
|
}
|
|
481
469
|
});
|
|
482
|
-
const
|
|
470
|
+
const getTypeComponentTypeToFieldObject = external_lodash_default().once(() => {
|
|
471
|
+
const typeComponentTypeToFieldObject = new Map();
|
|
472
|
+
this.typeObjects.flatMap(typeObject => typeObject.fieldObjects).filter(fieldObject => {
|
|
473
|
+
return fieldObject.rawMeta["fibery/type-component?"] === true && fieldObject.typeObject.rawMeta["fibery/type-component?"] === true;
|
|
474
|
+
}).forEach(fieldObject => {
|
|
475
|
+
typeComponentTypeToFieldObject.set(fieldObject.type, fieldObject);
|
|
476
|
+
});
|
|
477
|
+
return typeComponentTypeToFieldObject;
|
|
478
|
+
});
|
|
483
479
|
this.typeObjects = rawTypeObjects.map(rawTypeObject => factory.makeTypeObject({
|
|
484
480
|
rawTypeObject,
|
|
485
481
|
resolveTypeObject: type => this.typeObjectsByName[type] || null,
|
|
486
|
-
getTypeComponentTypeToFieldObject: type =>
|
|
482
|
+
getTypeComponentTypeToFieldObject: type => getTypeComponentTypeToFieldObject().get(type),
|
|
487
483
|
version
|
|
488
484
|
}));
|
|
489
485
|
this.typeObjectsById = factory.makeTypeObjectsById(this.typeObjects);
|
|
490
486
|
this.typeObjectsByName = factory.makeTypeObjectsByName(this.typeObjects);
|
|
491
|
-
this.typeObjects.flatMap(typeObject => typeObject.fieldObjects).filter(fieldObject => {
|
|
492
|
-
return fieldObject.rawMeta["fibery/type-component?"] === true && fieldObject.typeObject.rawMeta["fibery/type-component?"] === true;
|
|
493
|
-
}).forEach(fieldObject => {
|
|
494
|
-
typeComponentTypeToFieldObject.set(fieldObject.type, fieldObject);
|
|
495
|
-
});
|
|
496
487
|
this.id = id;
|
|
497
488
|
this.version = version;
|
|
498
489
|
}
|
|
499
|
-
|
|
500
490
|
}
|
|
501
491
|
;// CONCATENATED MODULE: external "pluralize"
|
|
502
492
|
const external_pluralize_namespaceObject = require("pluralize");
|
|
503
493
|
var external_pluralize_default = /*#__PURE__*/__webpack_require__.n(external_pluralize_namespaceObject);
|
|
504
494
|
;// CONCATENATED MODULE: ./TypeObject.js
|
|
505
|
-
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; }
|
|
506
|
-
|
|
495
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
496
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
497
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
507
498
|
|
|
508
499
|
|
|
509
500
|
|
|
510
501
|
class TypeObject {
|
|
511
|
-
constructor({
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
502
|
+
constructor(_ref) {
|
|
503
|
+
let {
|
|
504
|
+
rawTypeObject,
|
|
505
|
+
resolveTypeObject,
|
|
506
|
+
getTypeComponentTypeToFieldObject,
|
|
507
|
+
version,
|
|
508
|
+
factory
|
|
509
|
+
} = _ref;
|
|
518
510
|
_defineProperty(this, "_getFieldObjectShortcuts", external_lodash_default().once(() => {
|
|
519
511
|
const hasRank = this.installedMixins.has("fibery/rank-mixin");
|
|
520
512
|
return this.fieldObjects.reduce((result, fieldObject) => {
|
|
@@ -531,7 +523,6 @@ class TypeObject {
|
|
|
531
523
|
result.rankField = fieldObject.name;
|
|
532
524
|
result.rankFieldObject = fieldObject;
|
|
533
525
|
}
|
|
534
|
-
|
|
535
526
|
return result;
|
|
536
527
|
}, {
|
|
537
528
|
idField: null,
|
|
@@ -544,15 +535,12 @@ class TypeObject {
|
|
|
544
535
|
rankFieldObject: null
|
|
545
536
|
});
|
|
546
537
|
}));
|
|
547
|
-
|
|
548
538
|
if (!external_lodash_default().isPlainObject(rawTypeObject)) {
|
|
549
539
|
throw new Error("rawTypeObject arg must be plain object");
|
|
550
540
|
}
|
|
551
|
-
|
|
552
541
|
if (!external_lodash_default().isFunction(resolveTypeObject)) {
|
|
553
542
|
throw new Error("resolveTypeObject arg must be function");
|
|
554
543
|
}
|
|
555
|
-
|
|
556
544
|
this.name = rawTypeObject["fibery/name"];
|
|
557
545
|
this.description = rawTypeObject["fibery/description"] || null;
|
|
558
546
|
this.id = rawTypeObject["fibery/id"];
|
|
@@ -571,14 +559,12 @@ class TypeObject {
|
|
|
571
559
|
this.installedMixins = new Set(Object.keys(rawMeta["app/mixins"] || {}));
|
|
572
560
|
this.syncSource = rawMeta["sync/source"] || null;
|
|
573
561
|
this.version = version;
|
|
574
|
-
|
|
575
562
|
const fieldObjectsByNameOnceGetter = external_lodash_default().once(() => {
|
|
576
563
|
return factory.makeFieldObjectsByName({
|
|
577
564
|
type: this.name,
|
|
578
565
|
fieldObjects: this.fieldObjects
|
|
579
566
|
});
|
|
580
567
|
});
|
|
581
|
-
|
|
582
568
|
const fieldObjectsGetter = external_lodash_default().once(() => rawTypeObject["fibery/fields"].map(rawFieldObject => {
|
|
583
569
|
return factory.makeFieldObject({
|
|
584
570
|
rawFieldObject,
|
|
@@ -587,15 +573,12 @@ class TypeObject {
|
|
|
587
573
|
version
|
|
588
574
|
});
|
|
589
575
|
}));
|
|
590
|
-
|
|
591
576
|
Object.defineProperties(this, {
|
|
592
577
|
toJSON: {
|
|
593
578
|
value() {
|
|
594
579
|
if (false) {}
|
|
595
|
-
|
|
596
580
|
return rawTypeObject;
|
|
597
581
|
},
|
|
598
|
-
|
|
599
582
|
enumerable: false
|
|
600
583
|
},
|
|
601
584
|
fieldObjects: {
|
|
@@ -642,39 +625,30 @@ class TypeObject {
|
|
|
642
625
|
}
|
|
643
626
|
});
|
|
644
627
|
}
|
|
645
|
-
|
|
646
628
|
get idField() {
|
|
647
629
|
return this._getFieldObjectShortcuts().idField;
|
|
648
630
|
}
|
|
649
|
-
|
|
650
631
|
get idFieldObject() {
|
|
651
632
|
return this._getFieldObjectShortcuts().idFieldObject;
|
|
652
633
|
}
|
|
653
|
-
|
|
654
634
|
get publicIdField() {
|
|
655
635
|
return this._getFieldObjectShortcuts().publicIdField;
|
|
656
636
|
}
|
|
657
|
-
|
|
658
637
|
get publicIdFieldObject() {
|
|
659
638
|
return this._getFieldObjectShortcuts().publicIdFieldObject;
|
|
660
639
|
}
|
|
661
|
-
|
|
662
640
|
get titleField() {
|
|
663
641
|
return this._getFieldObjectShortcuts().titleField;
|
|
664
642
|
}
|
|
665
|
-
|
|
666
643
|
get titleFieldObject() {
|
|
667
644
|
return this._getFieldObjectShortcuts().titleFieldObject;
|
|
668
645
|
}
|
|
669
|
-
|
|
670
646
|
get rankField() {
|
|
671
647
|
return this._getFieldObjectShortcuts().rankField;
|
|
672
648
|
}
|
|
673
|
-
|
|
674
649
|
get rankFieldObject() {
|
|
675
650
|
return this._getFieldObjectShortcuts().rankFieldObject;
|
|
676
651
|
}
|
|
677
|
-
|
|
678
652
|
}
|
|
679
653
|
;// CONCATENATED MODULE: ./index.js
|
|
680
654
|
|
|
@@ -683,36 +657,50 @@ class TypeObject {
|
|
|
683
657
|
|
|
684
658
|
|
|
685
659
|
const factory = {
|
|
686
|
-
makeSchema: (rawSchema
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
660
|
+
makeSchema: function (rawSchema) {
|
|
661
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
662
|
+
shouldRemoveDeletedTypesAndFields: true
|
|
663
|
+
};
|
|
664
|
+
return new Schema({
|
|
665
|
+
rawSchema: options.shouldRemoveDeletedTypesAndFields ? removeDeletedTypesAndFields(rawSchema) : rawSchema,
|
|
666
|
+
factory
|
|
667
|
+
});
|
|
668
|
+
},
|
|
669
|
+
makeTypeObject: args => new TypeObject({
|
|
670
|
+
...args,
|
|
693
671
|
factory
|
|
694
672
|
}),
|
|
695
673
|
makeTypeObjectsById: typeObjects => external_lodash_default().keyBy(typeObjects, x => x.id),
|
|
696
674
|
makeTypeObjectsByName: typeObjects => external_lodash_default().keyBy(typeObjects, x => x.name),
|
|
697
675
|
makeFieldObject: args => new FieldObject(args),
|
|
698
|
-
makeFieldObjectsById:
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
676
|
+
makeFieldObjectsById: _ref => {
|
|
677
|
+
let {
|
|
678
|
+
type,
|
|
679
|
+
fieldObjects
|
|
680
|
+
} = _ref;
|
|
681
|
+
return external_lodash_default().keyBy(fieldObjects, x => x.id);
|
|
682
|
+
},
|
|
683
|
+
makeFieldObjectsByName: _ref2 => {
|
|
684
|
+
let {
|
|
685
|
+
type,
|
|
686
|
+
fieldObjects
|
|
687
|
+
} = _ref2;
|
|
688
|
+
return external_lodash_default().keyBy(fieldObjects, x => x.name);
|
|
689
|
+
}
|
|
706
690
|
};
|
|
707
691
|
const protectiveFactory = {
|
|
708
|
-
makeSchema: (rawSchema
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
692
|
+
makeSchema: function (rawSchema) {
|
|
693
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
694
|
+
shouldRemoveDeletedTypesAndFields: true
|
|
695
|
+
};
|
|
696
|
+
return withOnlyDefinedGets(new Schema({
|
|
697
|
+
rawSchema: options.shouldRemoveDeletedTypesAndFields ? removeDeletedTypesAndFields(rawSchema) : rawSchema,
|
|
698
|
+
factory: protectiveFactory
|
|
699
|
+
}), `schema`);
|
|
700
|
+
},
|
|
714
701
|
makeTypeObject: args => {
|
|
715
|
-
const typeObject = new TypeObject({
|
|
702
|
+
const typeObject = new TypeObject({
|
|
703
|
+
...args,
|
|
716
704
|
factory: protectiveFactory
|
|
717
705
|
});
|
|
718
706
|
return withOnlyDefinedGets(typeObject, `schema.typeObjectsByName["${typeObject.name}"]`);
|
|
@@ -723,14 +711,20 @@ const protectiveFactory = {
|
|
|
723
711
|
const fieldObject = new FieldObject(args);
|
|
724
712
|
return withOnlyDefinedGets(fieldObject, `schema.typeObjectsByName["${fieldObject.holderType}"].fieldObjectsByName["${fieldObject.name}"]`);
|
|
725
713
|
},
|
|
726
|
-
makeFieldObjectsById:
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
type
|
|
732
|
-
|
|
733
|
-
|
|
714
|
+
makeFieldObjectsById: _ref3 => {
|
|
715
|
+
let {
|
|
716
|
+
type,
|
|
717
|
+
fieldObjects
|
|
718
|
+
} = _ref3;
|
|
719
|
+
return withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.id), `schema.typeObjectsByName["${type}"].fieldObjectsById`);
|
|
720
|
+
},
|
|
721
|
+
makeFieldObjectsByName: _ref4 => {
|
|
722
|
+
let {
|
|
723
|
+
type,
|
|
724
|
+
fieldObjects
|
|
725
|
+
} = _ref4;
|
|
726
|
+
return withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.name), `schema.typeObjectsByName["${type}"].fieldObjectsByName`);
|
|
727
|
+
}
|
|
734
728
|
};
|
|
735
729
|
module.exports = __webpack_exports__;
|
|
736
730
|
/******/ })()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/schema",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.6",
|
|
4
4
|
"description": "utils for working with fibery schema",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"browser": "./index.js",
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
"private": false,
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"lodash": "^4.17.21",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"memoize-one": "^6.0.0",
|
|
16
|
+
"pluralize": "^8.0.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@babel/core": "7.
|
|
20
|
-
"babel-jest": "27.5.1",
|
|
21
|
-
"babel-loader": "8.2.5",
|
|
19
|
+
"@babel/core": "7.20.5",
|
|
22
20
|
"@fibery/babel-preset": "7.2.0",
|
|
23
21
|
"@fibery/eslint-config": "8.2.0",
|
|
24
22
|
"@fibery/helpers": "1.0.2",
|
|
23
|
+
"babel-jest": "27.5.1",
|
|
24
|
+
"babel-loader": "9.1.0",
|
|
25
25
|
"jest": "27.5.1",
|
|
26
26
|
"jest-junit": "13.0.0",
|
|
27
27
|
"webpack": "5.74.0",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "BABEL_ENV=production webpack",
|
|
32
32
|
"test": "node scripts/test.js",
|
|
33
|
-
"test:ci": "yarn test --
|
|
33
|
+
"test:ci": "yarn test --reporters=default --reporters=jest-junit",
|
|
34
|
+
"test:coverage": "yarn test --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/schema --reporters=default --reporters=jest-junit",
|
|
34
35
|
"lint": "eslint ."
|
|
35
36
|
},
|
|
36
37
|
"jest": {
|
package/types.d.ts
CHANGED