@fibery/schema 8.4.0 → 10.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.
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TypeObject = void 0;
7
+ /* eslint-disable no-use-before-define */
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const utils_1 = require("./utils");
10
+ const pluralize_1 = __importDefault(require("pluralize"));
11
+ class TypeObject {
12
+ name;
13
+ description;
14
+ id;
15
+ rawMeta;
16
+ isDomain;
17
+ isPlatform;
18
+ isHighlight;
19
+ isMixin;
20
+ mixinIcon;
21
+ isEnum;
22
+ isPrimitive;
23
+ isWriterModeByDefault;
24
+ nameParts;
25
+ color;
26
+ units;
27
+ installedMixins;
28
+ syncSource;
29
+ version;
30
+ installedMixinTypeObjects;
31
+ title;
32
+ pluralTitle;
33
+ fieldObjects;
34
+ fieldObjectsById;
35
+ fieldObjectsByName;
36
+ typeComponentFieldObject;
37
+ isDeleted;
38
+ isEntityRef;
39
+ constructor({ rawTypeObject, resolveTypeObject, getTypeComponentTypeToFieldObject, version, factory, resolveMultiRelatedFieldObjects, }) {
40
+ if (!lodash_1.default.isPlainObject(rawTypeObject)) {
41
+ throw new Error("rawTypeObject arg must be plain object");
42
+ }
43
+ if (!lodash_1.default.isFunction(resolveTypeObject)) {
44
+ throw new Error("resolveTypeObject arg must be function");
45
+ }
46
+ this.name = rawTypeObject["fibery/name"];
47
+ this.description = rawTypeObject["fibery/description"] || null;
48
+ this.id = rawTypeObject["fibery/id"];
49
+ const rawMeta = rawTypeObject["fibery/meta"] || {};
50
+ this.rawMeta = rawMeta;
51
+ this.isDomain = rawMeta["fibery/domain?"] || false;
52
+ this.isPlatform = rawMeta["fibery/platform?"] || false;
53
+ this.isHighlight = rawMeta["fibery/highlight?"] || false;
54
+ this.isMixin = rawMeta["app/mixin?"] || false;
55
+ this.mixinIcon = rawMeta["ui/mixin-icon"] || null;
56
+ this.isEnum = rawMeta["fibery/enum?"] || false;
57
+ this.isPrimitive = rawMeta["fibery/primitive?"] || false;
58
+ this.isWriterModeByDefault = rawMeta["ui/writer-mode?"] || false;
59
+ this.isDeleted = rawTypeObject["fibery/deleted?"] || false;
60
+ this.nameParts = (0, utils_1.parseType)(this.name);
61
+ this.color = rawMeta["ui/color"] || "#4568FB";
62
+ this.units = rawMeta["ui/units"] || null;
63
+ this.installedMixins = new Set(Object.keys(rawMeta["app/mixins"] || {}));
64
+ this.syncSource = rawMeta["sync/source"] || null;
65
+ this.version = version;
66
+ this.isEntityRef = rawTypeObject["fibery/name"] === "fibery/entity-ref";
67
+ const fieldObjectsByNameOnceGetter = lodash_1.default.once(() => {
68
+ return factory.makeFieldObjectsByName({
69
+ type: this.name,
70
+ fieldObjects: this.fieldObjects,
71
+ });
72
+ });
73
+ const fieldObjectsGetter = lodash_1.default.once(() => rawTypeObject["fibery/fields"].map((rawFieldObject) => {
74
+ return factory.makeFieldObject({
75
+ rawFieldObject,
76
+ holderType: this.name,
77
+ resolveTypeObject,
78
+ version,
79
+ resolveMultiRelatedFieldObjects,
80
+ });
81
+ }));
82
+ Object.defineProperties(this, {
83
+ toJSON: {
84
+ value() {
85
+ if (process.env.NODE_ENV === "test") {
86
+ return `<schema.typeObjectsByName["${rawTypeObject["fibery/name"]}"]>`;
87
+ }
88
+ return rawTypeObject;
89
+ },
90
+ enumerable: false,
91
+ },
92
+ fieldObjects: {
93
+ configurable: false,
94
+ enumerable: true,
95
+ get: fieldObjectsGetter,
96
+ },
97
+ typeComponentFieldObject: {
98
+ configurable: false,
99
+ enumerable: true,
100
+ get: () => {
101
+ return getTypeComponentTypeToFieldObject(this.name);
102
+ },
103
+ },
104
+ fieldObjectsById: {
105
+ configurable: false,
106
+ enumerable: true,
107
+ get: lodash_1.default.once(() => {
108
+ return factory.makeFieldObjectsById({
109
+ type: this.name,
110
+ fieldObjects: this.fieldObjects,
111
+ });
112
+ }),
113
+ },
114
+ fieldObjectsByName: {
115
+ configurable: false,
116
+ enumerable: true,
117
+ get: fieldObjectsByNameOnceGetter,
118
+ },
119
+ installedMixinTypeObjects: {
120
+ configurable: false,
121
+ enumerable: true,
122
+ get: lodash_1.default.once(() => [...this.installedMixins].map(resolveTypeObject).filter((typeObject) => typeObject)),
123
+ },
124
+ title: {
125
+ configurable: false,
126
+ enumerable: true,
127
+ get: lodash_1.default.once(() => (0, utils_1.toTitle)(this.name)),
128
+ },
129
+ pluralTitle: {
130
+ configurable: false,
131
+ enumerable: true,
132
+ get: lodash_1.default.once(() => (0, utils_1.toTitle)(pluralize_1.default.plural(this.name))),
133
+ },
134
+ });
135
+ }
136
+ _getFieldObjectShortcuts = lodash_1.default.once(() => {
137
+ const hasRank = this.installedMixins.has("fibery/rank-mixin");
138
+ return this.fieldObjects.reduce((result, fieldObject) => {
139
+ if (fieldObject.isId) {
140
+ result.idField = fieldObject.name;
141
+ result.idFieldObject = fieldObject;
142
+ }
143
+ else if (fieldObject.isPublicId) {
144
+ result.publicIdField = fieldObject.name;
145
+ result.publicIdFieldObject = fieldObject;
146
+ }
147
+ else if (fieldObject.isTitle) {
148
+ result.titleField = fieldObject.name;
149
+ result.titleFieldObject = fieldObject;
150
+ }
151
+ else if (hasRank && fieldObject.name === "fibery/rank") {
152
+ result.rankField = fieldObject.name;
153
+ result.rankFieldObject = fieldObject;
154
+ }
155
+ return result;
156
+ }, {
157
+ idField: null,
158
+ idFieldObject: null,
159
+ publicIdField: null,
160
+ publicIdFieldObject: null,
161
+ titleField: null,
162
+ titleFieldObject: null,
163
+ rankField: null,
164
+ rankFieldObject: null,
165
+ });
166
+ });
167
+ get idField() {
168
+ return this._getFieldObjectShortcuts().idField;
169
+ }
170
+ get idFieldObject() {
171
+ return this._getFieldObjectShortcuts().idFieldObject;
172
+ }
173
+ get publicIdField() {
174
+ return this._getFieldObjectShortcuts().publicIdField;
175
+ }
176
+ get publicIdFieldObject() {
177
+ return this._getFieldObjectShortcuts().publicIdFieldObject;
178
+ }
179
+ get titleField() {
180
+ return this._getFieldObjectShortcuts().titleField;
181
+ }
182
+ get titleFieldObject() {
183
+ return this._getFieldObjectShortcuts().titleFieldObject;
184
+ }
185
+ get rankField() {
186
+ return this._getFieldObjectShortcuts().rankField;
187
+ }
188
+ get rankFieldObject() {
189
+ return this._getFieldObjectShortcuts().rankFieldObject;
190
+ }
191
+ }
192
+ exports.TypeObject = TypeObject;
@@ -0,0 +1,59 @@
1
+ import _ from "lodash";
2
+ import { RawSchema } from "./schema";
3
+ export declare const withOnlyDefinedGets: (target: any, targetKind?: string) => any;
4
+ export declare const capitalizeFirstChar: (input: string) => string;
5
+ export declare const toTypeOrFieldNamePartTitle: (str: string) => string;
6
+ export declare const toTypeOrFieldTitle: (str: string) => string;
7
+ export declare const toPascalCase: (lispCasedString?: string) => string;
8
+ export declare const toNonEnumTitle: (str: string) => string;
9
+ export declare const parseEnumType: (type: string) => {
10
+ templateName: string;
11
+ templateNamespace: string;
12
+ targetName: string;
13
+ targetNamespace: string;
14
+ };
15
+ export declare const toTitle: (typeOrAttr: string) => string;
16
+ export declare const parseType: ((type: any) => {
17
+ namespace: string;
18
+ name: string;
19
+ }) & _.MemoizedFunction;
20
+ export declare const makeEnumTypeNamePart: ({ holderType, enumName }: {
21
+ holderType: string;
22
+ enumName: string;
23
+ }) => string;
24
+ export declare const attachEnumNamespace: ({ enumNamespace, typeNamePart }: {
25
+ enumNamespace: string;
26
+ typeNamePart: string;
27
+ }) => string;
28
+ export declare const removeDeletedTypesAndFields: (rawSchema: RawSchema) => {
29
+ "fibery/types": {
30
+ "fibery/fields": import("./field-object").RawFieldObject[];
31
+ "fibery/id": string;
32
+ "fibery/name": string;
33
+ "fibery/description"?: string | null | undefined;
34
+ "fibery/deleted?"?: boolean | undefined;
35
+ "fibery/meta": {
36
+ "fibery/domain?"?: boolean | undefined;
37
+ "fibery/platform?"?: boolean | undefined;
38
+ "fibery/highlight?"?: boolean | undefined;
39
+ "app/mixin?"?: boolean | undefined;
40
+ "ui/mixin-icon"?: string | undefined;
41
+ "fibery/enum?"?: boolean | undefined;
42
+ "fibery/primitive?"?: boolean | undefined;
43
+ "ui/writer-mode?"?: boolean | undefined;
44
+ "ui/color"?: string | undefined;
45
+ "ui/units"?: unknown[] | undefined;
46
+ "app/mixins"?: Record<string, boolean> | undefined;
47
+ "sync/source"?: {
48
+ appId: string;
49
+ appName: string;
50
+ id: string;
51
+ state: string;
52
+ type: string;
53
+ } | undefined;
54
+ "fibery/secured?"?: boolean | undefined;
55
+ };
56
+ }[];
57
+ "fibery/id": string;
58
+ "fibery/version": string;
59
+ };
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.removeDeletedTypesAndFields = exports.attachEnumNamespace = exports.makeEnumTypeNamePart = exports.parseType = exports.toTitle = exports.parseEnumType = exports.toNonEnumTitle = exports.toPascalCase = exports.toTypeOrFieldTitle = exports.toTypeOrFieldNamePartTitle = exports.capitalizeFirstChar = exports.withOnlyDefinedGets = void 0;
7
+ const trace_1 = require("@fibery/helpers/utils/trace");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const errors_1 = require("./errors");
10
+ const print_utils_1 = require("./print-utils");
11
+ const jestKey = new Set(["nodeType", "tagName", "hasAttribute"]);
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ const withOnlyDefinedGets = (target, targetKind = "object") => new Proxy(target, {
14
+ get(target, key) {
15
+ if (!(key in target) && process.env.NODE_ENV !== "production") {
16
+ if (key === "__target__") {
17
+ return target;
18
+ }
19
+ if (key === "_reactFragment") {
20
+ // greetings from react-developer-tools
21
+ return undefined;
22
+ }
23
+ if (key === "_error") {
24
+ // greetings from redux-form.deepEqual
25
+ return undefined;
26
+ }
27
+ if (key === "_warning") {
28
+ // greetings from redux-form.deepEqual
29
+ return undefined;
30
+ }
31
+ if (key === "length") {
32
+ // greetings from lodash isArrayLike
33
+ return undefined;
34
+ }
35
+ if (key === "inspect") {
36
+ // greetings from jest console implementation
37
+ return undefined;
38
+ }
39
+ if (key === "@@toStringTag") {
40
+ // greetings from prop-types isSymbol
41
+ return undefined;
42
+ }
43
+ if (key === "$$typeof") {
44
+ // greetings from react-developer-tools
45
+ return undefined;
46
+ }
47
+ if (process.env.NODE_ENV === "test") {
48
+ // greetings from jest
49
+ if (typeof key === "string" && jestKey.has(key)) {
50
+ return undefined;
51
+ }
52
+ if (key === "@@__IMMUTABLE_ITERABLE__@@") {
53
+ return undefined;
54
+ }
55
+ if (key === "@@__IMMUTABLE_RECORD__@@") {
56
+ return undefined;
57
+ }
58
+ if (key === "_isMockFunction") {
59
+ return undefined;
60
+ }
61
+ if (key === "asymmetricMatch") {
62
+ // greetings from jest expect().toEqual
63
+ return undefined;
64
+ }
65
+ if (key === "then") {
66
+ // Promise.resolve(schema)
67
+ return undefined;
68
+ }
69
+ if (key === "toJSON") {
70
+ return () => "<" + targetKind + ">";
71
+ }
72
+ }
73
+ if (typeof key === "symbol") {
74
+ // greetings from Object.prototype.toString (Symbol.toStringTag), from react-developer-tools (Symbol.iterator)
75
+ return undefined;
76
+ }
77
+ throw new errors_1.NotDefinedGetError(`${targetKind}${(0, print_utils_1.printJsPath)([key])} is undefined`);
78
+ }
79
+ return target[key];
80
+ },
81
+ });
82
+ exports.withOnlyDefinedGets = withOnlyDefinedGets;
83
+ const getNamePart = (str) => splitKeyword(str).name;
84
+ const capitalizeFirstChar = (input) => {
85
+ const str = input || "";
86
+ return str ? str.charAt(0).toUpperCase() + str.slice(1) : str;
87
+ };
88
+ exports.capitalizeFirstChar = capitalizeFirstChar;
89
+ const replaceTildes = (str) => (str || "").split("~").join(" ");
90
+ exports.toTypeOrFieldNamePartTitle = lodash_1.default.flow([exports.capitalizeFirstChar, replaceTildes]);
91
+ exports.toTypeOrFieldTitle = lodash_1.default.flow([getNamePart, exports.toTypeOrFieldNamePartTitle]);
92
+ const toPascalCase = (lispCasedString = "") => lispCasedString && (lodash_1.default.last(lispCasedString.split("/")) || "").split("-").map(lodash_1.default.capitalize).join(" ");
93
+ exports.toPascalCase = toPascalCase;
94
+ const isObsoleteTitle = (str) => {
95
+ const { name } = splitKeyword(str);
96
+ return name.toLowerCase() === name && !hasTildes(name);
97
+ };
98
+ const hasTildes = (str) => str.includes("~");
99
+ const toNonEnumTitle = (str) => {
100
+ return isObsoleteTitle(str) ? (0, exports.toPascalCase)(str) : (0, exports.toTypeOrFieldTitle)(str);
101
+ };
102
+ exports.toNonEnumTitle = toNonEnumTitle;
103
+ const parseEnumType = (type) => {
104
+ const [templateType, targetType] = type.split("_");
105
+ const { name: templateName, namespace: templateNamespace } = (0, exports.parseType)(templateType);
106
+ const { name: targetName, namespace: targetNamespace } = (0, exports.parseType)(targetType);
107
+ return { templateName, templateNamespace, targetName, targetNamespace };
108
+ };
109
+ exports.parseEnumType = parseEnumType;
110
+ const toEnumTitle = (type) => {
111
+ // enum logic
112
+ const { templateName, targetName } = (0, exports.parseEnumType)(type);
113
+ return (0, exports.toTitle)(targetName) + " " + (0, exports.toTitle)(templateName);
114
+ };
115
+ const toTitle = (typeOrAttr) => {
116
+ const str = typeOrAttr || "";
117
+ return str.includes("_") ? toEnumTitle(str) : (0, exports.toNonEnumTitle)(str);
118
+ };
119
+ exports.toTitle = toTitle;
120
+ const splitKeyword = (keyword) => {
121
+ const str = keyword || "";
122
+ const index = str.indexOf("/");
123
+ if (index === -1) {
124
+ return {
125
+ namespace: "",
126
+ name: str,
127
+ };
128
+ }
129
+ const namespace = str.substring(0, index);
130
+ const name = str.substring(index + 1);
131
+ return {
132
+ namespace,
133
+ name,
134
+ };
135
+ };
136
+ exports.parseType = lodash_1.default.memoize((type) => {
137
+ if (!type.includes("/")) {
138
+ (0, trace_1.traceError)(`parseType invalid usage: passed type is '${type}'`);
139
+ }
140
+ return splitKeyword(type);
141
+ });
142
+ const makeEnumTypeNamePart = ({ holderType, enumName }) => {
143
+ const { namespace, name } = (0, exports.parseType)(holderType);
144
+ return `${enumName}_${namespace}/${name}`;
145
+ };
146
+ exports.makeEnumTypeNamePart = makeEnumTypeNamePart;
147
+ const attachEnumNamespace = ({ enumNamespace, typeNamePart }) => {
148
+ return `${enumNamespace}/${typeNamePart}`;
149
+ };
150
+ exports.attachEnumNamespace = attachEnumNamespace;
151
+ const removeDeletedTypesAndFields = (rawSchema) => {
152
+ const { "fibery/types": rawTypeObjects, ...schemaRest } = rawSchema;
153
+ const filteredRawTypeObjects = rawTypeObjects
154
+ .filter((rawTypeObject) => rawTypeObject["fibery/deleted?"] !== true)
155
+ .map((rawTypeObject) => {
156
+ const { "fibery/fields": rawFieldObjects, ...rawTypeObjectRest } = rawTypeObject;
157
+ const filteredRawFieldObjects = rawFieldObjects.filter((rawFieldObject) => rawFieldObject["fibery/deleted?"] !== true);
158
+ return { ...rawTypeObjectRest, "fibery/fields": filteredRawFieldObjects };
159
+ });
160
+ return { ...schemaRest, "fibery/types": filteredRawTypeObjects };
161
+ };
162
+ exports.removeDeletedTypesAndFields = removeDeletedTypesAndFields;
package/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "@fibery/schema",
3
- "version": "8.4.0",
4
- "description": "utils for working with fibery schema",
3
+ "version": "10.0.0",
4
+ "description": "Fibery schema utils",
5
5
  "main": "./lib/index.js",
6
- "browser": "./index.js",
7
- "types": "./types.d.ts",
8
6
  "files": [
9
- "./lib",
10
- "types.d.ts"
7
+ "./lib"
11
8
  ],
12
9
  "private": false,
13
10
  "dependencies": {
@@ -18,15 +15,18 @@
18
15
  },
19
16
  "devDependencies": {
20
17
  "@babel/core": "7.20.5",
18
+ "@swc/jest": "0.2.29",
21
19
  "@types/lodash": "4.14.172",
22
- "babel-jest": "27.5.1",
20
+ "@types/node": "18.11.17",
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",
25
+ "typescript": "5.1.6",
26
26
  "webpack": "5.87.0",
27
27
  "webpack-cli": "4.10.0",
28
- "@fibery/eslint-config": "8.5.0",
29
- "@fibery/babel-preset": "7.3.0"
28
+ "@fibery/babel-preset": "7.3.0",
29
+ "@fibery/eslint-config": "8.5.0"
30
30
  },
31
31
  "jest": {
32
32
  "testEnvironment": "node",
@@ -45,13 +45,30 @@
45
45
  "<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
46
46
  ],
47
47
  "transform": {
48
- "^.+\\.(js|jsx|ts|tsx)$": "../../fibery-ui/config/jest/babel.js"
48
+ "^.+\\.(js|jsx|ts|tsx)$": [
49
+ "@swc/jest",
50
+ {
51
+ "jsc": {
52
+ "parser": {
53
+ "syntax": "typescript",
54
+ "tsx": true,
55
+ "decorators": true,
56
+ "dynamicImport": true
57
+ },
58
+ "transform": {
59
+ "react": {
60
+ "runtime": "automatic"
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ]
49
66
  },
50
67
  "testURL": "http://localhost"
51
68
  },
52
69
  "scripts": {
53
- "build": "BABEL_ENV=production webpack",
54
- "test": "node scripts/test.js",
70
+ "build": "rm -rf lib && pnpm exec tsc --project tsconfig.build.json",
71
+ "test": "jest",
55
72
  "test:ci": "pnpm run test --reporters=default --reporters=jest-junit",
56
73
  "test:coverage": "pnpm run test --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/schema --reporters=default --reporters=jest-junit",
57
74
  "lint": "eslint ."
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;