@fibery/schema 8.1.5 → 8.1.7

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 (4) hide show
  1. package/LICENSE +214 -0
  2. package/lib/index.js +129 -141
  3. package/package.json +14 -13
  4. package/types.d.ts +1 -0
package/LICENSE ADDED
@@ -0,0 +1,214 @@
1
+ THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
2
+ LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
3
+ CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4
+
5
+ 1. DEFINITIONS
6
+
7
+ "Contribution" means:
8
+
9
+ a) in the case of the initial Contributor, the initial code and
10
+ documentation distributed under this Agreement, and
11
+
12
+ b) in the case of each subsequent Contributor:
13
+
14
+ i) changes to the Program, and
15
+
16
+ ii) additions to the Program;
17
+
18
+ where such changes and/or additions to the Program originate from and are
19
+ distributed by that particular Contributor. A Contribution 'originates' from
20
+ a Contributor if it was added to the Program by such Contributor itself or
21
+ anyone acting on such Contributor's behalf. Contributions do not include
22
+ additions to the Program which: (i) are separate modules of software
23
+ distributed in conjunction with the Program under their own license
24
+ agreement, and (ii) are not derivative works of the Program.
25
+
26
+ "Contributor" means any person or entity that distributes the Program.
27
+
28
+ "Licensed Patents" mean patent claims licensable by a Contributor which are
29
+ necessarily infringed by the use or sale of its Contribution alone or when
30
+ combined with the Program.
31
+
32
+ "Program" means the Contributions distributed in accordance with this
33
+ Agreement.
34
+
35
+ "Recipient" means anyone who receives the Program under this Agreement,
36
+ including all Contributors.
37
+
38
+ 2. GRANT OF RIGHTS
39
+
40
+ a) Subject to the terms of this Agreement, each Contributor hereby grants
41
+ Recipient a non-exclusive, worldwide, royalty-free copyright license to
42
+ reproduce, prepare derivative works of, publicly display, publicly perform,
43
+ distribute and sublicense the Contribution of such Contributor, if any, and
44
+ such derivative works, in source code and object code form.
45
+
46
+ b) Subject to the terms of this Agreement, each Contributor hereby grants
47
+ Recipient a non-exclusive, worldwide, royalty-free patent license under
48
+ Licensed Patents to make, use, sell, offer to sell, import and otherwise
49
+ transfer the Contribution of such Contributor, if any, in source code and
50
+ object code form. This patent license shall apply to the combination of the
51
+ Contribution and the Program if, at the time the Contribution is added by the
52
+ Contributor, such addition of the Contribution causes such combination to be
53
+ covered by the Licensed Patents. The patent license shall not apply to any
54
+ other combinations which include the Contribution. No hardware per se is
55
+ licensed hereunder.
56
+
57
+ c) Recipient understands that although each Contributor grants the licenses
58
+ to its Contributions set forth herein, no assurances are provided by any
59
+ Contributor that the Program does not infringe the patent or other
60
+ intellectual property rights of any other entity. Each Contributor disclaims
61
+ any liability to Recipient for claims brought by any other entity based on
62
+ infringement of intellectual property rights or otherwise. As a condition to
63
+ exercising the rights and licenses granted hereunder, each Recipient hereby
64
+ assumes sole responsibility to secure any other intellectual property rights
65
+ needed, if any. For example, if a third party patent license is required to
66
+ allow Recipient to distribute the Program, it is Recipient's responsibility
67
+ to acquire that license before distributing the Program.
68
+
69
+ d) Each Contributor represents that to its knowledge it has sufficient
70
+ copyright rights in its Contribution, if any, to grant the copyright license
71
+ set forth in this Agreement.
72
+
73
+ 3. REQUIREMENTS
74
+
75
+ A Contributor may choose to distribute the Program in object code form under
76
+ its own license agreement, provided that:
77
+
78
+ a) it complies with the terms and conditions of this Agreement; and
79
+
80
+ b) its license agreement:
81
+
82
+ i) effectively disclaims on behalf of all Contributors all warranties and
83
+ conditions, express and implied, including warranties or conditions of title
84
+ and non-infringement, and implied warranties or conditions of merchantability
85
+ and fitness for a particular purpose;
86
+
87
+ ii) effectively excludes on behalf of all Contributors all liability for
88
+ damages, including direct, indirect, special, incidental and consequential
89
+ damages, such as lost profits;
90
+
91
+ iii) states that any provisions which differ from this Agreement are offered
92
+ by that Contributor alone and not by any other party; and
93
+
94
+ iv) states that source code for the Program is available from such
95
+ Contributor, and informs licensees how to obtain it in a reasonable manner on
96
+ or through a medium customarily used for software exchange.
97
+
98
+ When the Program is made available in source code form:
99
+
100
+ a) it must be made available under this Agreement; and
101
+
102
+ b) a copy of this Agreement must be included with each copy of the Program.
103
+
104
+ Contributors may not remove or alter any copyright notices contained within
105
+ the Program.
106
+
107
+ Each Contributor must identify itself as the originator of its Contribution,
108
+ if any, in a manner that reasonably allows subsequent Recipients to identify
109
+ the originator of the Contribution.
110
+
111
+ 4. COMMERCIAL DISTRIBUTION
112
+
113
+ Commercial distributors of software may accept certain responsibilities with
114
+ respect to end users, business partners and the like. While this license is
115
+ intended to facilitate the commercial use of the Program, the Contributor who
116
+ includes the Program in a commercial product offering should do so in a
117
+ manner which does not create potential liability for other Contributors.
118
+ Therefore, if a Contributor includes the Program in a commercial product
119
+ offering, such Contributor ("Commercial Contributor") hereby agrees to defend
120
+ and indemnify every other Contributor ("Indemnified Contributor") against any
121
+ losses, damages and costs (collectively "Losses") arising from claims,
122
+ lawsuits and other legal actions brought by a third party against the
123
+ Indemnified Contributor to the extent caused by the acts or omissions of such
124
+ Commercial Contributor in connection with its distribution of the Program in
125
+ a commercial product offering. The obligations in this section do not apply
126
+ to any claims or Losses relating to any actual or alleged intellectual
127
+ property infringement. In order to qualify, an Indemnified Contributor must:
128
+ a) promptly notify the Commercial Contributor in writing of such claim, and
129
+ b) allow the Commercial Contributor to control, and cooperate with the
130
+ Commercial Contributor in, the defense and any related settlement
131
+ negotiations. The Indemnified Contributor may participate in any such claim
132
+ at its own expense.
133
+
134
+ For example, a Contributor might include the Program in a commercial product
135
+ offering, Product X. That Contributor is then a Commercial Contributor. If
136
+ that Commercial Contributor then makes performance claims, or offers
137
+ warranties related to Product X, those performance claims and warranties are
138
+ such Commercial Contributor's responsibility alone. Under this section, the
139
+ Commercial Contributor would have to defend claims against the other
140
+ Contributors related to those performance claims and warranties, and if a
141
+ court requires any other Contributor to pay any damages as a result, the
142
+ Commercial Contributor must pay those damages.
143
+
144
+ 5. NO WARRANTY
145
+
146
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
147
+ AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
148
+ EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
149
+ CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
150
+ PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
151
+ appropriateness of using and distributing the Program and assumes all risks
152
+ associated with its exercise of rights under this Agreement , including but
153
+ not limited to the risks and costs of program errors, compliance with
154
+ applicable laws, damage to or loss of data, programs or equipment, and
155
+ unavailability or interruption of operations.
156
+
157
+ 6. DISCLAIMER OF LIABILITY
158
+
159
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
160
+ CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
161
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
162
+ LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
163
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
164
+ ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
165
+ EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
166
+ OF SUCH DAMAGES.
167
+
168
+ 7. GENERAL
169
+
170
+ If any provision of this Agreement is invalid or unenforceable under
171
+ applicable law, it shall not affect the validity or enforceability of the
172
+ remainder of the terms of this Agreement, and without further action by the
173
+ parties hereto, such provision shall be reformed to the minimum extent
174
+ necessary to make such provision valid and enforceable.
175
+
176
+ If Recipient institutes patent litigation against any entity (including a
177
+ cross-claim or counterclaim in a lawsuit) alleging that the Program itself
178
+ (excluding combinations of the Program with other software or hardware)
179
+ infringes such Recipient's patent(s), then such Recipient's rights granted
180
+ under Section 2(b) shall terminate as of the date such litigation is filed.
181
+
182
+ All Recipient's rights under this Agreement shall terminate if it fails to
183
+ comply with any of the material terms or conditions of this Agreement and
184
+ does not cure such failure in a reasonable period of time after becoming
185
+ aware of such noncompliance. If all Recipient's rights under this Agreement
186
+ terminate, Recipient agrees to cease use and distribution of the Program as
187
+ soon as reasonably practicable. However, Recipient's obligations under this
188
+ Agreement and any licenses granted by Recipient relating to the Program shall
189
+ continue and survive.
190
+
191
+ Everyone is permitted to copy and distribute copies of this Agreement, but in
192
+ order to avoid inconsistency the Agreement is copyrighted and may only be
193
+ modified in the following manner. The Agreement Steward reserves the right to
194
+ publish new versions (including revisions) of this Agreement from time to
195
+ time. No one other than the Agreement Steward has the right to modify this
196
+ Agreement. The Eclipse Foundation is the initial Agreement Steward. The
197
+ Eclipse Foundation may assign the responsibility to serve as the Agreement
198
+ Steward to a suitable separate entity. Each new version of the Agreement will
199
+ be given a distinguishing version number. The Program (including
200
+ Contributions) may always be distributed subject to the version of the
201
+ Agreement under which it was received. In addition, after a new version of
202
+ the Agreement is published, Contributor may elect to distribute the Program
203
+ (including its Contributions) under the new version. Except as expressly
204
+ stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
205
+ licenses to the intellectual property of any Contributor under this
206
+ Agreement, whether expressly, by implication, estoppel or otherwise. All
207
+ rights in the Program not expressly granted under this Agreement are
208
+ reserved.
209
+
210
+ This Agreement is governed by the laws of the State of New York and the
211
+ intellectual property laws of the United States of America. No party to this
212
+ Agreement will bring a legal action under this Agreement more than one year
213
+ after the cause of action arose. Each party waives its rights to a jury trial
214
+ in any resulting litigation.
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, ...args) {
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, ...args) {
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
- } // eslint-disable-next-line no-console
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(...args) {
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
- }); // eslint-disable-next-line no-console
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(...args) {
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 (...args) {
162
+ return async function () {
153
163
  try {
154
- return await f(...args);
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, 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
-
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 = (lispCasedString = "") => lispCasedString && external_lodash_default().last(lispCasedString.split("/")).split("-").map((external_lodash_default()).capitalize).join(" ");
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
- holderType,
263
- enumName
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
- enumNamespace,
273
- typeNamePart
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 { ...rawTypeObjectRest,
290
+ return {
291
+ ...rawTypeObjectRest,
289
292
  "fibery/fields": filteredRawFieldObjects
290
293
  };
291
294
  });
292
- return { ...schemaRest,
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
- rawFieldObject,
302
- holderType,
303
- resolveTypeObject,
304
- version
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,23 +440,22 @@ class FieldObject {
452
440
  }
453
441
  }
454
442
  }
455
-
456
443
  }
457
444
  ;// CONCATENATED MODULE: ./Schema.js
458
445
 
459
446
  class Schema {
460
- constructor({
461
- factory,
462
- rawSchema: {
463
- "fibery/id": id,
464
- "fibery/types": rawTypeObjects,
465
- "fibery/version": version
466
- }
467
- }) {
447
+ constructor(_ref) {
448
+ let {
449
+ factory,
450
+ rawSchema: {
451
+ "fibery/id": id,
452
+ "fibery/types": rawTypeObjects,
453
+ "fibery/version": version
454
+ }
455
+ } = _ref;
468
456
  if (!Array.isArray(rawTypeObjects)) {
469
457
  throw new Error("rawTypeObjects arg must be array");
470
458
  }
471
-
472
459
  Object.defineProperties(this, {
473
460
  toJSON: {
474
461
  value: () => ({
@@ -480,7 +467,6 @@ class Schema {
480
467
  enumerable: false
481
468
  }
482
469
  });
483
-
484
470
  const getTypeComponentTypeToFieldObject = external_lodash_default().once(() => {
485
471
  const typeComponentTypeToFieldObject = new Map();
486
472
  this.typeObjects.flatMap(typeObject => typeObject.fieldObjects).filter(fieldObject => {
@@ -490,7 +476,6 @@ class Schema {
490
476
  });
491
477
  return typeComponentTypeToFieldObject;
492
478
  });
493
-
494
479
  this.typeObjects = rawTypeObjects.map(rawTypeObject => factory.makeTypeObject({
495
480
  rawTypeObject,
496
481
  resolveTypeObject: type => this.typeObjectsByName[type] || null,
@@ -502,25 +487,26 @@ class Schema {
502
487
  this.id = id;
503
488
  this.version = version;
504
489
  }
505
-
506
490
  }
507
491
  ;// CONCATENATED MODULE: external "pluralize"
508
492
  const external_pluralize_namespaceObject = require("pluralize");
509
493
  var external_pluralize_default = /*#__PURE__*/__webpack_require__.n(external_pluralize_namespaceObject);
510
494
  ;// CONCATENATED MODULE: ./TypeObject.js
511
- 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; }
512
-
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); }
513
498
 
514
499
 
515
500
 
516
501
  class TypeObject {
517
- constructor({
518
- rawTypeObject,
519
- resolveTypeObject,
520
- getTypeComponentTypeToFieldObject,
521
- version,
522
- factory
523
- }) {
502
+ constructor(_ref) {
503
+ let {
504
+ rawTypeObject,
505
+ resolveTypeObject,
506
+ getTypeComponentTypeToFieldObject,
507
+ version,
508
+ factory
509
+ } = _ref;
524
510
  _defineProperty(this, "_getFieldObjectShortcuts", external_lodash_default().once(() => {
525
511
  const hasRank = this.installedMixins.has("fibery/rank-mixin");
526
512
  return this.fieldObjects.reduce((result, fieldObject) => {
@@ -537,7 +523,6 @@ class TypeObject {
537
523
  result.rankField = fieldObject.name;
538
524
  result.rankFieldObject = fieldObject;
539
525
  }
540
-
541
526
  return result;
542
527
  }, {
543
528
  idField: null,
@@ -550,15 +535,12 @@ class TypeObject {
550
535
  rankFieldObject: null
551
536
  });
552
537
  }));
553
-
554
538
  if (!external_lodash_default().isPlainObject(rawTypeObject)) {
555
539
  throw new Error("rawTypeObject arg must be plain object");
556
540
  }
557
-
558
541
  if (!external_lodash_default().isFunction(resolveTypeObject)) {
559
542
  throw new Error("resolveTypeObject arg must be function");
560
543
  }
561
-
562
544
  this.name = rawTypeObject["fibery/name"];
563
545
  this.description = rawTypeObject["fibery/description"] || null;
564
546
  this.id = rawTypeObject["fibery/id"];
@@ -577,14 +559,12 @@ class TypeObject {
577
559
  this.installedMixins = new Set(Object.keys(rawMeta["app/mixins"] || {}));
578
560
  this.syncSource = rawMeta["sync/source"] || null;
579
561
  this.version = version;
580
-
581
562
  const fieldObjectsByNameOnceGetter = external_lodash_default().once(() => {
582
563
  return factory.makeFieldObjectsByName({
583
564
  type: this.name,
584
565
  fieldObjects: this.fieldObjects
585
566
  });
586
567
  });
587
-
588
568
  const fieldObjectsGetter = external_lodash_default().once(() => rawTypeObject["fibery/fields"].map(rawFieldObject => {
589
569
  return factory.makeFieldObject({
590
570
  rawFieldObject,
@@ -593,15 +573,12 @@ class TypeObject {
593
573
  version
594
574
  });
595
575
  }));
596
-
597
576
  Object.defineProperties(this, {
598
577
  toJSON: {
599
578
  value() {
600
579
  if (false) {}
601
-
602
580
  return rawTypeObject;
603
581
  },
604
-
605
582
  enumerable: false
606
583
  },
607
584
  fieldObjects: {
@@ -648,39 +625,30 @@ class TypeObject {
648
625
  }
649
626
  });
650
627
  }
651
-
652
628
  get idField() {
653
629
  return this._getFieldObjectShortcuts().idField;
654
630
  }
655
-
656
631
  get idFieldObject() {
657
632
  return this._getFieldObjectShortcuts().idFieldObject;
658
633
  }
659
-
660
634
  get publicIdField() {
661
635
  return this._getFieldObjectShortcuts().publicIdField;
662
636
  }
663
-
664
637
  get publicIdFieldObject() {
665
638
  return this._getFieldObjectShortcuts().publicIdFieldObject;
666
639
  }
667
-
668
640
  get titleField() {
669
641
  return this._getFieldObjectShortcuts().titleField;
670
642
  }
671
-
672
643
  get titleFieldObject() {
673
644
  return this._getFieldObjectShortcuts().titleFieldObject;
674
645
  }
675
-
676
646
  get rankField() {
677
647
  return this._getFieldObjectShortcuts().rankField;
678
648
  }
679
-
680
649
  get rankFieldObject() {
681
650
  return this._getFieldObjectShortcuts().rankFieldObject;
682
651
  }
683
-
684
652
  }
685
653
  ;// CONCATENATED MODULE: ./index.js
686
654
 
@@ -689,36 +657,50 @@ class TypeObject {
689
657
 
690
658
 
691
659
  const factory = {
692
- makeSchema: (rawSchema, options = {
693
- shouldRemoveDeletedTypesAndFields: true
694
- }) => new Schema({
695
- rawSchema: options.shouldRemoveDeletedTypesAndFields ? removeDeletedTypesAndFields(rawSchema) : rawSchema,
696
- factory
697
- }),
698
- makeTypeObject: args => new TypeObject({ ...args,
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,
699
671
  factory
700
672
  }),
701
673
  makeTypeObjectsById: typeObjects => external_lodash_default().keyBy(typeObjects, x => x.id),
702
674
  makeTypeObjectsByName: typeObjects => external_lodash_default().keyBy(typeObjects, x => x.name),
703
675
  makeFieldObject: args => new FieldObject(args),
704
- makeFieldObjectsById: ({
705
- type,
706
- fieldObjects
707
- }) => external_lodash_default().keyBy(fieldObjects, x => x.id),
708
- makeFieldObjectsByName: ({
709
- type,
710
- fieldObjects
711
- }) => external_lodash_default().keyBy(fieldObjects, x => x.name)
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
+ }
712
690
  };
713
691
  const protectiveFactory = {
714
- makeSchema: (rawSchema, options = {
715
- shouldRemoveDeletedTypesAndFields: true
716
- }) => withOnlyDefinedGets(new Schema({
717
- rawSchema: options.shouldRemoveDeletedTypesAndFields ? removeDeletedTypesAndFields(rawSchema) : rawSchema,
718
- factory: protectiveFactory
719
- }), `schema`),
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
+ },
720
701
  makeTypeObject: args => {
721
- const typeObject = new TypeObject({ ...args,
702
+ const typeObject = new TypeObject({
703
+ ...args,
722
704
  factory: protectiveFactory
723
705
  });
724
706
  return withOnlyDefinedGets(typeObject, `schema.typeObjectsByName["${typeObject.name}"]`);
@@ -729,14 +711,20 @@ const protectiveFactory = {
729
711
  const fieldObject = new FieldObject(args);
730
712
  return withOnlyDefinedGets(fieldObject, `schema.typeObjectsByName["${fieldObject.holderType}"].fieldObjectsByName["${fieldObject.name}"]`);
731
713
  },
732
- makeFieldObjectsById: ({
733
- type,
734
- fieldObjects
735
- }) => withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.id), `schema.typeObjectsByName["${type}"].fieldObjectsById`),
736
- makeFieldObjectsByName: ({
737
- type,
738
- fieldObjects
739
- }) => withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.name), `schema.typeObjectsByName["${type}"].fieldObjectsByName`)
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
+ }
740
728
  };
741
729
  module.exports = __webpack_exports__;
742
730
  /******/ })()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/schema",
3
- "version": "8.1.5",
3
+ "version": "8.1.7",
4
4
  "description": "utils for working with fibery schema",
5
5
  "main": "./lib/index.js",
6
6
  "browser": "./index.js",
@@ -12,27 +12,21 @@
12
12
  "private": false,
13
13
  "dependencies": {
14
14
  "lodash": "^4.17.21",
15
- "pluralize": "^8.0.0",
16
- "memoize-one": "^6.0.0"
15
+ "memoize-one": "^6.0.0",
16
+ "pluralize": "^8.0.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@babel/core": "7.15.0",
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",
28
28
  "webpack-cli": "4.10.0"
29
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
30
  "jest": {
37
31
  "testEnvironment": "node",
38
32
  "coveragePathIgnorePatterns": [
@@ -53,5 +47,12 @@
53
47
  "^.+\\.(js|jsx|ts|tsx)$": "../../fibery-ui/config/jest/babel.js"
54
48
  },
55
49
  "testURL": "http://localhost"
50
+ },
51
+ "scripts": {
52
+ "build": "BABEL_ENV=production webpack",
53
+ "test": "node scripts/test.js",
54
+ "test:ci": "yarn test --reporters=default --reporters=jest-junit",
55
+ "test:coverage": "yarn test --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/schema --reporters=default --reporters=jest-junit",
56
+ "lint": "eslint ."
56
57
  }
57
- }
58
+ }
package/types.d.ts CHANGED
@@ -30,6 +30,7 @@ export type FieldObject = {
30
30
  // eslint-disable-next-line no-use-before-define
31
31
  typeObject: TypeObject;
32
32
  mixinTypeObject: unknown;
33
+ // eslint-disable-next-line no-use-before-define
33
34
  holderTypeObject: TypeObject;
34
35
  nameParts: {
35
36
  namespace: string;