@fibery/schema 8.1.3 → 8.1.5

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 +24 -18
  2. package/package.json +1 -1
  3. package/types.d.ts +3 -0
package/lib/index.js CHANGED
@@ -81,13 +81,13 @@ const formatWithCustomInspectParams = values => {
81
81
  };
82
82
  function assert(condition, ...args) {
83
83
  if (!condition) {
84
- const message = args.length > 0 ? formatWithCustomInspectParams(args) : "Assertion failed with no details";
84
+ const message = args.length > 0 ? formatWithCustomInspectParams(args) : `Assertion failed with no details`;
85
85
  throw new Error(message);
86
86
  }
87
87
  }
88
88
  function assertWithTraceError(condition, ...args) {
89
89
  if (!condition) {
90
- const message = args.length > 0 ? formatWithCustomInspectParams(args) : "Assertion failed with no details";
90
+ const message = args.length > 0 ? formatWithCustomInspectParams(args) : `Assertion failed with no details`;
91
91
  traceError(message);
92
92
  }
93
93
  } // eslint-disable-next-line no-console
@@ -253,7 +253,7 @@ const splitKeyword = keyword => {
253
253
 
254
254
  const parseType = external_lodash_default().memoize(type => {
255
255
  if (!type.includes("/")) {
256
- traceError("parseType invalid usage: passed type is '".concat(type, "'"));
256
+ traceError(`parseType invalid usage: passed type is '${type}'`);
257
257
  }
258
258
 
259
259
  return splitKeyword(type);
@@ -266,13 +266,13 @@ const makeEnumTypeNamePart = ({
266
266
  namespace,
267
267
  name
268
268
  } = parseType(holderType);
269
- return "".concat(enumName, "_").concat(namespace, "/").concat(name);
269
+ return `${enumName}_${namespace}/${name}`;
270
270
  };
271
271
  const attachEnumNamespace = ({
272
272
  enumNamespace,
273
273
  typeNamePart
274
274
  }) => {
275
- return "".concat(enumNamespace, "/").concat(typeNamePart);
275
+ return `${enumNamespace}/${typeNamePart}`;
276
276
  };
277
277
  const removeDeletedTypesAndFields = rawSchema => {
278
278
  const {
@@ -389,7 +389,7 @@ class FieldObject {
389
389
  const fieldObject = this.typeObject.fieldObjects.find(selector);
390
390
 
391
391
  if (!fieldObject) {
392
- throw new Error("there no other end for relation ".concat(relation));
392
+ throw new Error(`there no other end for relation ${relation}`);
393
393
  }
394
394
 
395
395
  return fieldObject;
@@ -455,6 +455,7 @@ class FieldObject {
455
455
 
456
456
  }
457
457
  ;// CONCATENATED MODULE: ./Schema.js
458
+
458
459
  class Schema {
459
460
  constructor({
460
461
  factory,
@@ -479,20 +480,25 @@ class Schema {
479
480
  enumerable: false
480
481
  }
481
482
  });
482
- const typeComponentTypeToFieldObject = new Map();
483
+
484
+ const getTypeComponentTypeToFieldObject = external_lodash_default().once(() => {
485
+ const typeComponentTypeToFieldObject = new Map();
486
+ this.typeObjects.flatMap(typeObject => typeObject.fieldObjects).filter(fieldObject => {
487
+ return fieldObject.rawMeta["fibery/type-component?"] === true && fieldObject.typeObject.rawMeta["fibery/type-component?"] === true;
488
+ }).forEach(fieldObject => {
489
+ typeComponentTypeToFieldObject.set(fieldObject.type, fieldObject);
490
+ });
491
+ return typeComponentTypeToFieldObject;
492
+ });
493
+
483
494
  this.typeObjects = rawTypeObjects.map(rawTypeObject => factory.makeTypeObject({
484
495
  rawTypeObject,
485
496
  resolveTypeObject: type => this.typeObjectsByName[type] || null,
486
- getTypeComponentTypeToFieldObject: type => typeComponentTypeToFieldObject.get(type),
497
+ getTypeComponentTypeToFieldObject: type => getTypeComponentTypeToFieldObject().get(type),
487
498
  version
488
499
  }));
489
500
  this.typeObjectsById = factory.makeTypeObjectsById(this.typeObjects);
490
501
  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
502
  this.id = id;
497
503
  this.version = version;
498
504
  }
@@ -710,27 +716,27 @@ const protectiveFactory = {
710
716
  }) => withOnlyDefinedGets(new Schema({
711
717
  rawSchema: options.shouldRemoveDeletedTypesAndFields ? removeDeletedTypesAndFields(rawSchema) : rawSchema,
712
718
  factory: protectiveFactory
713
- }), "schema"),
719
+ }), `schema`),
714
720
  makeTypeObject: args => {
715
721
  const typeObject = new TypeObject({ ...args,
716
722
  factory: protectiveFactory
717
723
  });
718
- return withOnlyDefinedGets(typeObject, "schema.typeObjectsByName[\"".concat(typeObject.name, "\"]"));
724
+ return withOnlyDefinedGets(typeObject, `schema.typeObjectsByName["${typeObject.name}"]`);
719
725
  },
720
726
  makeTypeObjectsById: typeObjects => withOnlyDefinedGets(external_lodash_default().keyBy(typeObjects, x => x.id), "schema.typeObjectsById"),
721
727
  makeTypeObjectsByName: typeObjects => withOnlyDefinedGets(external_lodash_default().keyBy(typeObjects, x => x.name), "schema.typeObjectsByName"),
722
728
  makeFieldObject: args => {
723
729
  const fieldObject = new FieldObject(args);
724
- return withOnlyDefinedGets(fieldObject, "schema.typeObjectsByName[\"".concat(fieldObject.holderType, "\"].fieldObjectsByName[\"").concat(fieldObject.name, "\"]"));
730
+ return withOnlyDefinedGets(fieldObject, `schema.typeObjectsByName["${fieldObject.holderType}"].fieldObjectsByName["${fieldObject.name}"]`);
725
731
  },
726
732
  makeFieldObjectsById: ({
727
733
  type,
728
734
  fieldObjects
729
- }) => withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.id), "schema.typeObjectsByName[\"".concat(type, "\"].fieldObjectsById")),
735
+ }) => withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.id), `schema.typeObjectsByName["${type}"].fieldObjectsById`),
730
736
  makeFieldObjectsByName: ({
731
737
  type,
732
738
  fieldObjects
733
- }) => withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.name), "schema.typeObjectsByName[\"".concat(type, "\"].fieldObjectsByName"))
739
+ }) => withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.name), `schema.typeObjectsByName["${type}"].fieldObjectsByName`)
734
740
  };
735
741
  module.exports = __webpack_exports__;
736
742
  /******/ })()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/schema",
3
- "version": "8.1.3",
3
+ "version": "8.1.5",
4
4
  "description": "utils for working with fibery schema",
5
5
  "main": "./lib/index.js",
6
6
  "browser": "./index.js",
package/types.d.ts CHANGED
@@ -46,8 +46,10 @@ export type TypeObject = {
46
46
  description: string | null;
47
47
  id: string;
48
48
  idField: string;
49
+ idFieldObject: FieldObject;
49
50
  publicIdField: string;
50
51
  titleField: string;
52
+ titleFieldObject: FieldObject;
51
53
  rankField: string | null;
52
54
  rawMeta: Record<string, unknown>;
53
55
  isDomain: boolean;
@@ -73,6 +75,7 @@ export type TypeObject = {
73
75
  fieldObjectsById: Record<string, FieldObject>;
74
76
  fieldObjectsByName: Record<string, FieldObject>;
75
77
  typeComponentFieldObject: FieldObject | undefined;
78
+ isDeleted: boolean;
76
79
  };
77
80
 
78
81
  export type Schema = {