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