@fibery/schema 10.2.17 → 10.3.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/lib/index.d.ts +7 -6
- package/lib/index.js +7 -22
- package/lib/src/errors.d.ts +4 -2
- package/lib/src/errors.js +4 -6
- package/lib/src/factory.d.ts +24 -21
- package/lib/src/factory.js +42 -43
- package/lib/src/field-keys.d.ts +7 -4
- package/lib/src/field-keys.js +0 -2
- package/lib/src/field-object.d.ts +88 -85
- package/lib/src/field-object.js +172 -224
- package/lib/src/print-utils.d.ts +5 -2
- package/lib/src/print-utils.js +4 -6
- package/lib/src/schema.d.ts +19 -16
- package/lib/src/schema.js +57 -65
- package/lib/src/type-object.d.ts +99 -96
- package/lib/src/type-object.js +185 -198
- package/lib/src/utils.d.ts +54 -50
- package/lib/src/utils.js +93 -146
- package/package.json +16 -14
package/lib/src/utils.d.ts
CHANGED
|
@@ -1,57 +1,61 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { SyncSource, TypeObject } from "./type-object.js";
|
|
2
|
+
import { RawFieldObject } from "./field-object.js";
|
|
3
|
+
import { RawSchema } from "./schema.js";
|
|
4
|
+
//#region src/utils.d.ts
|
|
5
|
+
declare const withOnlyDefinedGets: (target: any, targetKind?: string) => any;
|
|
6
|
+
declare const capitalizeFirstChar: (input: string) => string;
|
|
7
|
+
declare const toTypeOrFieldNamePartTitle: (str: string | null | undefined) => string;
|
|
8
|
+
declare const toTypeOrFieldTitle: (str: string | null | undefined) => string;
|
|
9
|
+
declare const toPascalCase: (lispCasedString?: string) => string;
|
|
10
|
+
declare const toNonEnumTitle: (strName: string) => string;
|
|
11
|
+
declare const parseEnumType: (type: string) => {
|
|
12
|
+
templateName: string;
|
|
13
|
+
templateNamespace: string;
|
|
14
|
+
targetName: string;
|
|
15
|
+
targetNamespace: string;
|
|
14
16
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
declare const toTitle: (typeOrAttr: string) => string;
|
|
18
|
+
declare const parseType: ((arg: string) => {
|
|
19
|
+
namespace: string;
|
|
20
|
+
name: string;
|
|
19
21
|
}) & import("@fibery/helpers/src/_").MemoizedFunction<string, {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
namespace: string;
|
|
23
|
+
name: string;
|
|
22
24
|
}>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
declare const makeEnumTypeNamePart: ({ holderType, enumName }: {
|
|
26
|
+
holderType: string;
|
|
27
|
+
enumName: string;
|
|
26
28
|
}) => string;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
declare const attachEnumNamespace: ({ enumNamespace, typeNamePart }: {
|
|
30
|
+
enumNamespace: string;
|
|
31
|
+
typeNamePart: string;
|
|
30
32
|
}) => string;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"fibery/description"?: string | null;
|
|
37
|
-
"fibery/deleted?"?: boolean;
|
|
38
|
-
"fibery/meta": {
|
|
39
|
-
"fibery/domain?"?: boolean;
|
|
40
|
-
"fibery/platform?"?: boolean;
|
|
41
|
-
"fibery/highlight?"?: boolean;
|
|
42
|
-
"app/mixin?"?: boolean;
|
|
43
|
-
"ui/mixin-icon"?: string;
|
|
44
|
-
"fibery/enum?"?: boolean;
|
|
45
|
-
"fibery/primitive?"?: boolean;
|
|
46
|
-
"ui/writer-mode?"?: boolean;
|
|
47
|
-
"ui/color"?: string;
|
|
48
|
-
"ui/units"?: unknown[];
|
|
49
|
-
"app/mixins"?: Record<string, boolean>;
|
|
50
|
-
"sync/source"?: import("./type-object").SyncSource;
|
|
51
|
-
"fibery/secured?"?: boolean;
|
|
52
|
-
};
|
|
53
|
-
}[];
|
|
33
|
+
declare const removeDeletedTypesAndFields: (rawSchema: RawSchema) => {
|
|
34
|
+
"fibery/id": string;
|
|
35
|
+
"fibery/version": string;
|
|
36
|
+
"fibery/types": {
|
|
37
|
+
"fibery/fields": RawFieldObject[];
|
|
54
38
|
"fibery/id": string;
|
|
55
|
-
"fibery/
|
|
39
|
+
"fibery/name": string;
|
|
40
|
+
"fibery/description"?: string | null;
|
|
41
|
+
"fibery/deleted?"?: boolean;
|
|
42
|
+
"fibery/meta": {
|
|
43
|
+
"fibery/domain?"?: boolean;
|
|
44
|
+
"fibery/platform?"?: boolean;
|
|
45
|
+
"fibery/highlight?"?: boolean;
|
|
46
|
+
"app/mixin?"?: boolean;
|
|
47
|
+
"ui/mixin-icon"?: string;
|
|
48
|
+
"fibery/enum?"?: boolean;
|
|
49
|
+
"fibery/primitive?"?: boolean;
|
|
50
|
+
"ui/writer-mode?"?: boolean;
|
|
51
|
+
"ui/color"?: string;
|
|
52
|
+
"ui/units"?: unknown[];
|
|
53
|
+
"app/mixins"?: Record<string, boolean>;
|
|
54
|
+
"sync/source"?: SyncSource;
|
|
55
|
+
"fibery/secured?"?: boolean;
|
|
56
|
+
};
|
|
57
|
+
}[];
|
|
56
58
|
};
|
|
57
|
-
|
|
59
|
+
declare const getTypeObjectTitle: (typeObject: TypeObject, form?: "singular" | "plural") => string;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
|
package/lib/src/utils.js
CHANGED
|
@@ -1,172 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (key === "inspect") {
|
|
39
|
-
// greetings from vitest/node console implementation
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
if (key === "@@toStringTag") {
|
|
43
|
-
// greetings from prop-types isSymbol
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
if (key === "$$typeof") {
|
|
47
|
-
// greetings from react-developer-tools
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
if (process.env.NODE_ENV === "test") {
|
|
51
|
-
// greetings from vitest serializer
|
|
52
|
-
if (typeof key === "string" && testRunnerKeys.has(key)) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
if (key === "@@__IMMUTABLE_ITERABLE__@@") {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
if (key === "@@__IMMUTABLE_RECORD__@@") {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
if (key === "_isMockFunction") {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
if (key === "asymmetricMatch") {
|
|
65
|
-
// greetings from vitest expect().toEqual
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
if (key === "then") {
|
|
69
|
-
// Promise.resolve(schema)
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
if (key === "toJSON") {
|
|
73
|
-
return () => "<" + targetKind + ">";
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (typeof key === "symbol") {
|
|
77
|
-
// greetings from Object.prototype.toString (Symbol.toStringTag), from react-developer-tools (Symbol.iterator)
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
throw new errors_1.NotDefinedGetError(`${targetKind}${(0, print_utils_1.printJsPath)([key])} is undefined`);
|
|
81
|
-
}
|
|
82
|
-
return target[key];
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
exports.withOnlyDefinedGets = withOnlyDefinedGets;
|
|
1
|
+
import { NotDefinedGetError } from "./errors.js";
|
|
2
|
+
import { printJsPath } from "./print-utils.js";
|
|
3
|
+
import { memoize } from "@fibery/helpers/src/_";
|
|
4
|
+
import { traceError } from "@fibery/helpers/utils/trace";
|
|
5
|
+
import capitalize from "lodash/capitalize.js";
|
|
6
|
+
import flow from "lodash/flow.js";
|
|
7
|
+
import last from "lodash/last.js";
|
|
8
|
+
//#region src/utils.ts
|
|
9
|
+
const testRunnerKeys = /* @__PURE__ */ new Set([
|
|
10
|
+
"nodeType",
|
|
11
|
+
"tagName",
|
|
12
|
+
"hasAttribute"
|
|
13
|
+
]);
|
|
14
|
+
const withOnlyDefinedGets = (target, targetKind = "object") => new Proxy(target, { get(target, key) {
|
|
15
|
+
if (!(key in target) && process.env.NODE_ENV !== "production") {
|
|
16
|
+
if (key === "__target__") return target;
|
|
17
|
+
if (key === "_reactFragment") return;
|
|
18
|
+
if (key === "_error") return;
|
|
19
|
+
if (key === "_warning") return;
|
|
20
|
+
if (key === "length") return;
|
|
21
|
+
if (key === "inspect") return;
|
|
22
|
+
if (key === "@@toStringTag") return;
|
|
23
|
+
if (key === "$$typeof") return;
|
|
24
|
+
if (process.env.NODE_ENV === "test") {
|
|
25
|
+
if (typeof key === "string" && testRunnerKeys.has(key)) return;
|
|
26
|
+
if (key === "@@__IMMUTABLE_ITERABLE__@@") return;
|
|
27
|
+
if (key === "@@__IMMUTABLE_RECORD__@@") return;
|
|
28
|
+
if (key === "_isMockFunction") return;
|
|
29
|
+
if (key === "asymmetricMatch") return;
|
|
30
|
+
if (key === "then") return;
|
|
31
|
+
if (key === "toJSON") return () => "<" + targetKind + ">";
|
|
32
|
+
}
|
|
33
|
+
if (typeof key === "symbol") return;
|
|
34
|
+
throw new NotDefinedGetError(`${targetKind}${printJsPath([key])} is undefined`);
|
|
35
|
+
}
|
|
36
|
+
return target[key];
|
|
37
|
+
} });
|
|
86
38
|
const getNamePart = (str) => splitKeyword(str).name;
|
|
87
39
|
const capitalizeFirstChar = (input) => {
|
|
88
|
-
|
|
89
|
-
|
|
40
|
+
const str = input || "";
|
|
41
|
+
return str ? str.charAt(0).toUpperCase() + str.slice(1) : str;
|
|
90
42
|
};
|
|
91
|
-
exports.capitalizeFirstChar = capitalizeFirstChar;
|
|
92
43
|
const replaceTildes = (str) => (str || "").split("~").join(" ");
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const toPascalCase = (lispCasedString = "") => lispCasedString && ((
|
|
96
|
-
exports.toPascalCase = toPascalCase;
|
|
44
|
+
const toTypeOrFieldNamePartTitle = flow([capitalizeFirstChar, replaceTildes]);
|
|
45
|
+
const toTypeOrFieldTitle = flow([getNamePart, toTypeOrFieldNamePartTitle]);
|
|
46
|
+
const toPascalCase = (lispCasedString = "") => lispCasedString && (last(lispCasedString.split("/")) || "").split("-").map(capitalize).join(" ");
|
|
97
47
|
const isObsoleteTitle = (str) => {
|
|
98
|
-
|
|
99
|
-
|
|
48
|
+
const { name } = splitKeyword(str);
|
|
49
|
+
return name.toLowerCase() === name && !hasTildes(name);
|
|
100
50
|
};
|
|
101
51
|
const hasTildes = (str) => str.includes("~");
|
|
102
52
|
const nameOverrides = {
|
|
103
|
-
|
|
104
|
-
|
|
53
|
+
"fibery/type": "fibery/Database",
|
|
54
|
+
"fibery/app": "fibery/Space"
|
|
105
55
|
};
|
|
106
56
|
const toNonEnumTitle = (strName) => {
|
|
107
|
-
|
|
108
|
-
|
|
57
|
+
const str = nameOverrides[strName] || strName;
|
|
58
|
+
return isObsoleteTitle(str) ? toPascalCase(str) : toTypeOrFieldTitle(str);
|
|
109
59
|
};
|
|
110
|
-
exports.toNonEnumTitle = toNonEnumTitle;
|
|
111
60
|
const parseEnumType = (type) => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
61
|
+
const [templateType, targetType] = type.split("_");
|
|
62
|
+
const { name: templateName, namespace: templateNamespace } = parseType(templateType);
|
|
63
|
+
const { name: targetName, namespace: targetNamespace } = parseType(targetType);
|
|
64
|
+
return {
|
|
65
|
+
templateName,
|
|
66
|
+
templateNamespace,
|
|
67
|
+
targetName,
|
|
68
|
+
targetNamespace
|
|
69
|
+
};
|
|
116
70
|
};
|
|
117
|
-
exports.parseEnumType = parseEnumType;
|
|
118
71
|
const toEnumTitle = (type) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return (0, exports.toTitle)(targetName) + " " + (0, exports.toTitle)(templateName);
|
|
72
|
+
const { templateName, targetName } = parseEnumType(type);
|
|
73
|
+
return toTitle(targetName) + " " + toTitle(templateName);
|
|
122
74
|
};
|
|
123
75
|
const toTitle = (typeOrAttr) => {
|
|
124
|
-
|
|
125
|
-
|
|
76
|
+
const str = typeOrAttr || "";
|
|
77
|
+
return str.includes("_") ? toEnumTitle(str) : toNonEnumTitle(str);
|
|
126
78
|
};
|
|
127
|
-
exports.toTitle = toTitle;
|
|
128
79
|
const splitKeyword = (keyword) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
namespace,
|
|
141
|
-
name,
|
|
142
|
-
};
|
|
80
|
+
const str = keyword || "";
|
|
81
|
+
const index = str.indexOf("/");
|
|
82
|
+
if (index === -1) return {
|
|
83
|
+
namespace: "",
|
|
84
|
+
name: str
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
namespace: str.substring(0, index),
|
|
88
|
+
name: str.substring(index + 1)
|
|
89
|
+
};
|
|
143
90
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
return splitKeyword(type);
|
|
91
|
+
const parseType = memoize((type) => {
|
|
92
|
+
if (!type.includes("/")) traceError(`parseType invalid usage: passed type is '${type}'`);
|
|
93
|
+
return splitKeyword(type);
|
|
149
94
|
});
|
|
150
95
|
const makeEnumTypeNamePart = ({ holderType, enumName }) => {
|
|
151
|
-
|
|
152
|
-
|
|
96
|
+
const { namespace, name } = parseType(holderType);
|
|
97
|
+
return `${enumName}_${namespace}/${name}`;
|
|
153
98
|
};
|
|
154
|
-
exports.makeEnumTypeNamePart = makeEnumTypeNamePart;
|
|
155
99
|
const attachEnumNamespace = ({ enumNamespace, typeNamePart }) => {
|
|
156
|
-
|
|
100
|
+
return `${enumNamespace}/${typeNamePart}`;
|
|
157
101
|
};
|
|
158
|
-
exports.attachEnumNamespace = attachEnumNamespace;
|
|
159
102
|
const removeDeletedTypesAndFields = (rawSchema) => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
103
|
+
const { "fibery/types": rawTypeObjects, ...schemaRest } = rawSchema;
|
|
104
|
+
const filteredRawTypeObjects = rawTypeObjects.filter((rawTypeObject) => rawTypeObject["fibery/deleted?"] !== true).map((rawTypeObject) => {
|
|
105
|
+
const { "fibery/fields": rawFieldObjects, ...rawTypeObjectRest } = rawTypeObject;
|
|
106
|
+
const filteredRawFieldObjects = rawFieldObjects.filter((rawFieldObject) => rawFieldObject["fibery/deleted?"] !== true);
|
|
107
|
+
return {
|
|
108
|
+
...rawTypeObjectRest,
|
|
109
|
+
"fibery/fields": filteredRawFieldObjects
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
...schemaRest,
|
|
114
|
+
"fibery/types": filteredRawTypeObjects
|
|
115
|
+
};
|
|
169
116
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
117
|
+
const getTypeObjectTitle = (typeObject, form) => form ? form === "singular" ? typeObject.singularTitle : typeObject.pluralTitle : typeObject.title;
|
|
118
|
+
//#endregion
|
|
119
|
+
export { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/schema",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Fibery schema utils",
|
|
6
6
|
"files": [
|
|
7
7
|
"./lib"
|
|
8
8
|
],
|
|
9
|
+
"type": "module",
|
|
9
10
|
"main": "./lib/index.js",
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
@@ -17,27 +18,28 @@
|
|
|
17
18
|
"dependencies": {
|
|
18
19
|
"lodash": "4.17.21",
|
|
19
20
|
"memoize-one": "6.0.0",
|
|
20
|
-
"@fibery/pluralize": "1.
|
|
21
|
-
"@fibery/helpers": "3.
|
|
21
|
+
"@fibery/pluralize": "1.2.0",
|
|
22
|
+
"@fibery/helpers": "3.2.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
|
-
"@babel/core": "7.28.5",
|
|
25
25
|
"@types/lodash": "4.14.172",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"typescript": "6.0.1-rc",
|
|
29
|
-
"webpack": "5.87.0",
|
|
30
|
-
"webpack-cli": "6.0.1",
|
|
31
|
-
"@fibery/babel-preset": "7.4.2"
|
|
26
|
+
"tsdown": "0.22.7",
|
|
27
|
+
"typescript": "rc"
|
|
32
28
|
},
|
|
29
|
+
"size-limit": [
|
|
30
|
+
{
|
|
31
|
+
"path": "lib/**/*.js",
|
|
32
|
+
"limit": "7 kB"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
33
35
|
"scripts": {
|
|
34
|
-
"build": "
|
|
36
|
+
"build": "pnpm run typecheck && tsdown",
|
|
35
37
|
"test": "../../scripts/test.sh",
|
|
36
38
|
"test:ci": "../../scripts/test.sh --ci",
|
|
37
39
|
"test:coverage": "../../scripts/test.sh --ci --coverage",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
40
|
+
"lint": "pnpm -w lint .",
|
|
41
|
+
"typecheck": "../../scripts/typecheck.sh",
|
|
42
|
+
"check": "../../scripts/check.sh"
|
|
41
43
|
},
|
|
42
44
|
"types": "./lib/index.d.ts"
|
|
43
45
|
}
|