@fibery/schema 8.4.0 → 9.0.0

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/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./src/factory";
2
+ export * from "./src/schema";
3
+ export * from "./src/type-object";
4
+ export * from "./src/field-object";
5
+ export * from "./src/utils";
6
+ export * from "./src/errors";
package/lib/index.js CHANGED
@@ -51,8 +51,24 @@ __webpack_require__.r(__webpack_exports__);
51
51
 
52
52
  // EXPORTS
53
53
  __webpack_require__.d(__webpack_exports__, {
54
- factory: () => (/* binding */ factory),
55
- protectiveFactory: () => (/* binding */ protectiveFactory)
54
+ FieldObject: () => (/* reexport */ FieldObject),
55
+ NotDefinedGetError: () => (/* reexport */ NotDefinedGetError),
56
+ Schema: () => (/* reexport */ Schema),
57
+ TypeObject: () => (/* reexport */ TypeObject),
58
+ attachEnumNamespace: () => (/* reexport */ attachEnumNamespace),
59
+ capitalizeFirstChar: () => (/* reexport */ capitalizeFirstChar),
60
+ factory: () => (/* reexport */ factory),
61
+ makeEnumTypeNamePart: () => (/* reexport */ makeEnumTypeNamePart),
62
+ parseEnumType: () => (/* reexport */ parseEnumType),
63
+ parseType: () => (/* reexport */ parseType),
64
+ protectiveFactory: () => (/* reexport */ protectiveFactory),
65
+ removeDeletedTypesAndFields: () => (/* reexport */ removeDeletedTypesAndFields),
66
+ toNonEnumTitle: () => (/* reexport */ toNonEnumTitle),
67
+ toPascalCase: () => (/* reexport */ toPascalCase),
68
+ toTitle: () => (/* reexport */ toTitle),
69
+ toTypeOrFieldNamePartTitle: () => (/* reexport */ toTypeOrFieldNamePartTitle),
70
+ toTypeOrFieldTitle: () => (/* reexport */ toTypeOrFieldTitle),
71
+ withOnlyDefinedGets: () => (/* reexport */ withOnlyDefinedGets)
56
72
  });
57
73
 
58
74
  ;// CONCATENATED MODULE: external "lodash"
@@ -168,7 +184,7 @@ function withErrorTrace(f) {
168
184
  }
169
185
  };
170
186
  }
171
- ;// CONCATENATED MODULE: ./utils.ts
187
+ ;// CONCATENATED MODULE: ./src/utils.ts
172
188
 
173
189
 
174
190
 
@@ -297,7 +313,11 @@ const removeDeletedTypesAndFields = rawSchema => {
297
313
  "fibery/types": filteredRawTypeObjects
298
314
  };
299
315
  };
300
- ;// CONCATENATED MODULE: ./FieldObject.js
316
+ ;// CONCATENATED MODULE: ./src/field-object.ts
317
+ 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; }
318
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
319
+ 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); }
320
+ /* eslint-disable no-use-before-define */
301
321
 
302
322
 
303
323
  class FieldObject {
@@ -309,6 +329,41 @@ class FieldObject {
309
329
  version,
310
330
  resolveMultiRelatedFieldObjects
311
331
  } = _ref;
332
+ _defineProperty(this, "name", void 0);
333
+ _defineProperty(this, "description", void 0);
334
+ _defineProperty(this, "id", void 0);
335
+ _defineProperty(this, "type", void 0);
336
+ _defineProperty(this, "rawMeta", void 0);
337
+ _defineProperty(this, "holderType", void 0);
338
+ _defineProperty(this, "isCollection", void 0);
339
+ _defineProperty(this, "isTitle", void 0);
340
+ _defineProperty(this, "isId", void 0);
341
+ _defineProperty(this, "isPublicId", void 0);
342
+ _defineProperty(this, "isReadOnly", void 0);
343
+ _defineProperty(this, "isFormula", void 0);
344
+ _defineProperty(this, "isFormulaDisabled", void 0);
345
+ _defineProperty(this, "formulaDisableReason", void 0);
346
+ _defineProperty(this, "formula", void 0);
347
+ _defineProperty(this, "isLookup", void 0);
348
+ _defineProperty(this, "hasLinkRule", void 0);
349
+ _defineProperty(this, "linkRule", void 0);
350
+ _defineProperty(this, "isLinkRuleDisabled", void 0);
351
+ _defineProperty(this, "linkRuleDisableReason", void 0);
352
+ _defineProperty(this, "relation", void 0);
353
+ _defineProperty(this, "multiRelation", void 0);
354
+ _defineProperty(this, "defaultValue", void 0);
355
+ _defineProperty(this, "objectEditorOrder", void 0);
356
+ _defineProperty(this, "isRequired", void 0);
357
+ _defineProperty(this, "isHidden", void 0);
358
+ _defineProperty(this, "isDeleted", void 0);
359
+ _defineProperty(this, "disableLinkExistingItems", void 0);
360
+ _defineProperty(this, "version", void 0);
361
+ _defineProperty(this, "typeObject", void 0);
362
+ _defineProperty(this, "mixinTypeObject", void 0);
363
+ _defineProperty(this, "holderTypeObject", void 0);
364
+ _defineProperty(this, "nameParts", void 0);
365
+ _defineProperty(this, "title", void 0);
366
+ _defineProperty(this, "multiRelatedFieldObjects", void 0);
312
367
  if (!external_lodash_default().isPlainObject(rawFieldObject)) {
313
368
  throw new Error("rawFieldObject arg must be plain object");
314
369
  }
@@ -361,7 +416,9 @@ class FieldObject {
361
416
  configurable: false,
362
417
  enumerable: true,
363
418
  get: external_lodash_default().once(() => {
364
- return this.holderTypeObject.installedMixinTypeObjects.find(mixinTypeObject => mixinTypeObject.fieldObjectsByName.hasOwnProperty(this.name) || this.name === "workflow/state" && mixinTypeObject.name === "workflow/workflow");
419
+ return this.holderTypeObject.installedMixinTypeObjects.find(mixinTypeObject =>
420
+ // eslint-disable-next-line prefer-object-has-own
421
+ Object.prototype.hasOwnProperty.call(mixinTypeObject.fieldObjectsByName, this.name) || this.name === "workflow/state" && mixinTypeObject.name === "workflow/workflow");
365
422
  })
366
423
  },
367
424
  holderTypeObject: {
@@ -474,7 +531,10 @@ class FieldObject {
474
531
  }
475
532
  }
476
533
  }
477
- ;// CONCATENATED MODULE: ./Schema.js
534
+ ;// CONCATENATED MODULE: ./src/schema.ts
535
+ function schema_defineProperty(obj, key, value) { key = schema_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
536
+ function schema_toPropertyKey(arg) { var key = schema_toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
537
+ function schema_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); }
478
538
 
479
539
  class Schema {
480
540
  constructor(_ref) {
@@ -486,6 +546,11 @@ class Schema {
486
546
  "fibery/version": version
487
547
  }
488
548
  } = _ref;
549
+ schema_defineProperty(this, "typeObjects", void 0);
550
+ schema_defineProperty(this, "typeObjectsById", void 0);
551
+ schema_defineProperty(this, "typeObjectsByName", void 0);
552
+ schema_defineProperty(this, "id", void 0);
553
+ schema_defineProperty(this, "version", void 0);
489
554
  if (!Array.isArray(rawTypeObjects)) {
490
555
  throw new Error("rawTypeObjects arg must be array");
491
556
  }
@@ -509,7 +574,7 @@ class Schema {
509
574
  });
510
575
  return typeComponentTypeToFieldObject;
511
576
  });
512
- let multiRelatedFieldsObjectsMap = null;
577
+ let multiRelatedFieldsObjectsMap;
513
578
  const initMultiRelatedFieldsObjectsMap = () => {
514
579
  multiRelatedFieldsObjectsMap = new Map();
515
580
  this.typeObjects.forEach(typeObject => {
@@ -543,10 +608,11 @@ class Schema {
543
608
  ;// CONCATENATED MODULE: external "pluralize"
544
609
  const external_pluralize_namespaceObject = require("pluralize");
545
610
  var external_pluralize_default = /*#__PURE__*/__webpack_require__.n(external_pluralize_namespaceObject);
546
- ;// CONCATENATED MODULE: ./TypeObject.js
547
- 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; }
548
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
549
- 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); }
611
+ ;// CONCATENATED MODULE: ./src/type-object.ts
612
+ function type_object_defineProperty(obj, key, value) { key = type_object_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
613
+ function type_object_toPropertyKey(arg) { var key = type_object_toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
614
+ function type_object_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); }
615
+ /* eslint-disable no-use-before-define */
550
616
 
551
617
 
552
618
 
@@ -560,7 +626,34 @@ class TypeObject {
560
626
  factory,
561
627
  resolveMultiRelatedFieldObjects
562
628
  } = _ref;
563
- _defineProperty(this, "_getFieldObjectShortcuts", external_lodash_default().once(() => {
629
+ type_object_defineProperty(this, "name", void 0);
630
+ type_object_defineProperty(this, "description", void 0);
631
+ type_object_defineProperty(this, "id", void 0);
632
+ type_object_defineProperty(this, "rawMeta", void 0);
633
+ type_object_defineProperty(this, "isDomain", void 0);
634
+ type_object_defineProperty(this, "isPlatform", void 0);
635
+ type_object_defineProperty(this, "isHighlight", void 0);
636
+ type_object_defineProperty(this, "isMixin", void 0);
637
+ type_object_defineProperty(this, "mixinIcon", void 0);
638
+ type_object_defineProperty(this, "isEnum", void 0);
639
+ type_object_defineProperty(this, "isPrimitive", void 0);
640
+ type_object_defineProperty(this, "isWriterModeByDefault", void 0);
641
+ type_object_defineProperty(this, "nameParts", void 0);
642
+ type_object_defineProperty(this, "color", void 0);
643
+ type_object_defineProperty(this, "units", void 0);
644
+ type_object_defineProperty(this, "installedMixins", void 0);
645
+ type_object_defineProperty(this, "syncSource", void 0);
646
+ type_object_defineProperty(this, "version", void 0);
647
+ type_object_defineProperty(this, "installedMixinTypeObjects", void 0);
648
+ type_object_defineProperty(this, "title", void 0);
649
+ type_object_defineProperty(this, "pluralTitle", void 0);
650
+ type_object_defineProperty(this, "fieldObjects", void 0);
651
+ type_object_defineProperty(this, "fieldObjectsById", void 0);
652
+ type_object_defineProperty(this, "fieldObjectsByName", void 0);
653
+ type_object_defineProperty(this, "typeComponentFieldObject", void 0);
654
+ type_object_defineProperty(this, "isDeleted", void 0);
655
+ type_object_defineProperty(this, "isEntityRef", void 0);
656
+ type_object_defineProperty(this, "_getFieldObjectShortcuts", external_lodash_default().once(() => {
564
657
  const hasRank = this.installedMixins.has("fibery/rank-mixin");
565
658
  return this.fieldObjects.reduce((result, fieldObject) => {
566
659
  if (fieldObject.isId) {
@@ -707,7 +800,7 @@ class TypeObject {
707
800
  return this._getFieldObjectShortcuts().rankFieldObject;
708
801
  }
709
802
  }
710
- ;// CONCATENATED MODULE: ./index.js
803
+ ;// CONCATENATED MODULE: ./src/factory.ts
711
804
 
712
805
 
713
806
 
@@ -732,14 +825,12 @@ const factory = {
732
825
  makeFieldObject: args => new FieldObject(args),
733
826
  makeFieldObjectsById: _ref => {
734
827
  let {
735
- type,
736
828
  fieldObjects
737
829
  } = _ref;
738
830
  return external_lodash_default().keyBy(fieldObjects, x => x.id);
739
831
  },
740
832
  makeFieldObjectsByName: _ref2 => {
741
833
  let {
742
- type,
743
834
  fieldObjects
744
835
  } = _ref2;
745
836
  return external_lodash_default().keyBy(fieldObjects, x => x.name);
@@ -783,6 +874,15 @@ const protectiveFactory = {
783
874
  return withOnlyDefinedGets(external_lodash_default().keyBy(fieldObjects, x => x.name), `schema.typeObjectsByName["${type}"].fieldObjectsByName`);
784
875
  }
785
876
  };
877
+ ;// CONCATENATED MODULE: ./src/errors.ts
878
+ class NotDefinedGetError extends Error {}
879
+ ;// CONCATENATED MODULE: ./index.ts
880
+
881
+
882
+
883
+
884
+
885
+
786
886
  module.exports = __webpack_exports__;
787
887
  /******/ })()
788
888
  ;
package/package.json CHANGED
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "name": "@fibery/schema",
3
- "version": "8.4.0",
3
+ "version": "9.0.0",
4
4
  "description": "utils for working with fibery schema",
5
5
  "main": "./lib/index.js",
6
- "browser": "./index.js",
7
- "types": "./types.d.ts",
6
+ "browser": "./index.ts",
8
7
  "files": [
9
- "./lib",
10
- "types.d.ts"
8
+ "./lib"
11
9
  ],
12
10
  "private": false,
13
11
  "dependencies": {
@@ -18,8 +16,9 @@
18
16
  },
19
17
  "devDependencies": {
20
18
  "@babel/core": "7.20.5",
19
+ "@swc/jest": "0.2.29",
21
20
  "@types/lodash": "4.14.172",
22
- "babel-jest": "27.5.1",
21
+ "@types/pluralize": "0.0.29",
23
22
  "babel-loader": "9.1.0",
24
23
  "jest": "27.5.1",
25
24
  "jest-junit": "13.0.0",
@@ -45,7 +44,24 @@
45
44
  "<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
46
45
  ],
47
46
  "transform": {
48
- "^.+\\.(js|jsx|ts|tsx)$": "../../fibery-ui/config/jest/babel.js"
47
+ "^.+\\.(js|jsx|ts|tsx)$": [
48
+ "@swc/jest",
49
+ {
50
+ "jsc": {
51
+ "parser": {
52
+ "syntax": "typescript",
53
+ "tsx": true,
54
+ "decorators": true,
55
+ "dynamicImport": true
56
+ },
57
+ "transform": {
58
+ "react": {
59
+ "runtime": "automatic"
60
+ }
61
+ }
62
+ }
63
+ }
64
+ ]
49
65
  },
50
66
  "testURL": "http://localhost"
51
67
  },
package/index.js DELETED
@@ -1,61 +0,0 @@
1
- import _ from "lodash";
2
- import {FieldObject} from "./FieldObject";
3
- import {Schema} from "./Schema";
4
- import {TypeObject} from "./TypeObject";
5
- import {removeDeletedTypesAndFields, withOnlyDefinedGets} from "./utils";
6
-
7
- export const factory = {
8
- makeSchema: (rawSchema, options = {shouldRemoveDeletedTypesAndFields: true}) =>
9
- new Schema({
10
- rawSchema: options.shouldRemoveDeletedTypesAndFields ? removeDeletedTypesAndFields(rawSchema) : rawSchema,
11
- factory,
12
- }),
13
- makeTypeObject: (args) => new TypeObject({...args, factory}),
14
- makeTypeObjectsById: (typeObjects) => _.keyBy(typeObjects, (x) => x.id),
15
- makeTypeObjectsByName: (typeObjects) => _.keyBy(typeObjects, (x) => x.name),
16
- makeFieldObject: (args) => new FieldObject(args),
17
- makeFieldObjectsById: ({type, fieldObjects}) => _.keyBy(fieldObjects, (x) => x.id),
18
- makeFieldObjectsByName: ({type, fieldObjects}) => _.keyBy(fieldObjects, (x) => x.name),
19
- };
20
-
21
- export const protectiveFactory = {
22
- makeSchema: (rawSchema, options = {shouldRemoveDeletedTypesAndFields: true}) =>
23
- withOnlyDefinedGets(
24
- new Schema({
25
- rawSchema: options.shouldRemoveDeletedTypesAndFields ? removeDeletedTypesAndFields(rawSchema) : rawSchema,
26
- factory: protectiveFactory,
27
- }),
28
- `schema`
29
- ),
30
- makeTypeObject: (args) => {
31
- const typeObject = new TypeObject({...args, factory: protectiveFactory});
32
- return withOnlyDefinedGets(typeObject, `schema.typeObjectsByName["${typeObject.name}"]`);
33
- },
34
- makeTypeObjectsById: (typeObjects) =>
35
- withOnlyDefinedGets(
36
- _.keyBy(typeObjects, (x) => x.id),
37
- "schema.typeObjectsById"
38
- ),
39
- makeTypeObjectsByName: (typeObjects) =>
40
- withOnlyDefinedGets(
41
- _.keyBy(typeObjects, (x) => x.name),
42
- "schema.typeObjectsByName"
43
- ),
44
- makeFieldObject: (args) => {
45
- const fieldObject = new FieldObject(args);
46
- return withOnlyDefinedGets(
47
- fieldObject,
48
- `schema.typeObjectsByName["${fieldObject.holderType}"].fieldObjectsByName["${fieldObject.name}"]`
49
- );
50
- },
51
- makeFieldObjectsById: ({type, fieldObjects}) =>
52
- withOnlyDefinedGets(
53
- _.keyBy(fieldObjects, (x) => x.id),
54
- `schema.typeObjectsByName["${type}"].fieldObjectsById`
55
- ),
56
- makeFieldObjectsByName: ({type, fieldObjects}) =>
57
- withOnlyDefinedGets(
58
- _.keyBy(fieldObjects, (x) => x.name),
59
- `schema.typeObjectsByName["${type}"].fieldObjectsByName`
60
- ),
61
- };
package/types.d.ts DELETED
@@ -1,101 +0,0 @@
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
- description: string | null;
9
- id: string;
10
- type: string;
11
- rawMeta: Record<string, unknown>;
12
- holderType: string;
13
- isCollection: boolean;
14
- isTitle: boolean;
15
- isId: boolean;
16
- isPublicId: boolean;
17
- isReadOnly: boolean;
18
- isFormula: boolean;
19
- formula: unknown | null;
20
- isLookup: boolean;
21
- hasLinkRule: boolean;
22
- linkRule: unknown | null;
23
- relation: string | null;
24
- multiRelation: string | null;
25
- defaultValue: unknown | null;
26
- objectEditorOrder: number;
27
- isRequired: boolean;
28
- isHidden: boolean;
29
- disableLinkExistingItems: boolean;
30
- version: string;
31
- // eslint-disable-next-line no-use-before-define
32
- typeObject: TypeObject;
33
- mixinTypeObject: unknown;
34
- // eslint-disable-next-line no-use-before-define
35
- holderTypeObject: TypeObject;
36
- nameParts: {
37
- namespace: string;
38
- name: string;
39
- };
40
- title: string;
41
- relatedFieldObject: FieldObject | null;
42
- cardinality: Cardinality;
43
- kind: ":field/reference" | ":field/reference-collection" | ":field/basic";
44
- multiRelatedFieldObjects: Array<FieldObject>;
45
- };
46
-
47
- export type TypeObject = {
48
- name: string;
49
- description: string | null;
50
- id: string;
51
- idField: string;
52
- idFieldObject: FieldObject;
53
- publicIdField: string;
54
- publicIdFieldObject: FieldObject;
55
- titleField: string;
56
- titleFieldObject: FieldObject;
57
- rankField: string | null;
58
- rawMeta: Record<string, unknown>;
59
- isDomain: boolean;
60
- isHighlight: boolean;
61
- isMixin: boolean;
62
- mixinIcon: string | null;
63
- isEnum: boolean;
64
- isPrimitive: boolean;
65
- isRequired: boolean;
66
- isWriterModeByDefault: boolean;
67
- nameParts: {
68
- namespace: string;
69
- name: string;
70
- };
71
- color: string;
72
- units: unknown | null;
73
- installedMixins: Set<string>;
74
- syncSource: {appId: string; appName: string; id: string; state: string; type: string} | null;
75
- version: string;
76
- installedMixinTypeObjects: unknown;
77
- title: string;
78
- pluralTitle: string;
79
- fieldObjects: Array<FieldObject>;
80
- fieldObjectsById: Record<string, FieldObject>;
81
- fieldObjectsByName: Record<string, FieldObject>;
82
- typeComponentFieldObject: FieldObject | undefined;
83
- isDeleted: boolean;
84
- isEntityRef: boolean;
85
- };
86
-
87
- export type Schema = {
88
- typeObjects: Array<TypeObject>;
89
- typeObjectsById: Record<string, TypeObject>;
90
- typeObjectsByName: Record<string, TypeObject>;
91
- id: string;
92
- version: string;
93
- };
94
-
95
- interface Factory {
96
- makeSchema: (rawSchema: Record<string, unknown>, options?: {shouldRemoveDeletedTypesAndFields: boolean}) => Schema;
97
- }
98
-
99
- export const factory: Factory;
100
-
101
- export const protectiveFactory: Factory;