@fibery/schema 10.2.18 → 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.
@@ -1,57 +1,61 @@
1
- import type { RawSchema } from "./schema";
2
- import type { TypeObject } from "./type-object";
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 | null | undefined) => string;
6
- export declare const toTypeOrFieldTitle: (str: string | null | undefined) => string;
7
- export declare const toPascalCase: (lispCasedString?: string) => string;
8
- export declare const toNonEnumTitle: (strName: string) => string;
9
- export declare const parseEnumType: (type: string) => {
10
- templateName: string;
11
- templateNamespace: string;
12
- targetName: string;
13
- targetNamespace: string;
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
- export declare const toTitle: (typeOrAttr: string) => string;
16
- export declare const parseType: ((arg: string) => {
17
- namespace: string;
18
- name: string;
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
- namespace: string;
21
- name: string;
22
+ namespace: string;
23
+ name: string;
22
24
  }>;
23
- export declare const makeEnumTypeNamePart: ({ holderType, enumName }: {
24
- holderType: string;
25
- enumName: string;
25
+ declare const makeEnumTypeNamePart: ({ holderType, enumName }: {
26
+ holderType: string;
27
+ enumName: string;
26
28
  }) => string;
27
- export declare const attachEnumNamespace: ({ enumNamespace, typeNamePart }: {
28
- enumNamespace: string;
29
- typeNamePart: string;
29
+ declare const attachEnumNamespace: ({ enumNamespace, typeNamePart }: {
30
+ enumNamespace: string;
31
+ typeNamePart: string;
30
32
  }) => string;
31
- export declare const removeDeletedTypesAndFields: (rawSchema: RawSchema) => {
32
- "fibery/types": {
33
- "fibery/fields": import("./field-object").RawFieldObject[];
34
- "fibery/id": string;
35
- "fibery/name": string;
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/version": string;
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
- export declare const getTypeObjectTitle: (typeObject: TypeObject, form?: "singular" | "plural") => string;
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
- "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.getTypeObjectTitle = 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 _1 = require("@fibery/helpers/src/_");
8
- const trace_1 = require("@fibery/helpers/utils/trace");
9
- const capitalize_1 = __importDefault(require("lodash/capitalize"));
10
- const flow_1 = __importDefault(require("lodash/flow"));
11
- const last_1 = __importDefault(require("lodash/last"));
12
- const errors_1 = require("./errors");
13
- const print_utils_1 = require("./print-utils");
14
- const testRunnerKeys = new Set(["nodeType", "tagName", "hasAttribute"]);
15
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- const withOnlyDefinedGets = (target, targetKind = "object") => new Proxy(target, {
17
- get(target, key) {
18
- if (!(key in target) && process.env.NODE_ENV !== "production") {
19
- if (key === "__target__") {
20
- return target;
21
- }
22
- if (key === "_reactFragment") {
23
- // greetings from react-developer-tools
24
- return undefined;
25
- }
26
- if (key === "_error") {
27
- // greetings from redux-form.deepEqual
28
- return undefined;
29
- }
30
- if (key === "_warning") {
31
- // greetings from redux-form.deepEqual
32
- return undefined;
33
- }
34
- if (key === "length") {
35
- // greetings from lodash isArrayLike
36
- return undefined;
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
- const str = input || "";
89
- return str ? str.charAt(0).toUpperCase() + str.slice(1) : str;
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
- exports.toTypeOrFieldNamePartTitle = (0, flow_1.default)([exports.capitalizeFirstChar, replaceTildes]);
94
- exports.toTypeOrFieldTitle = (0, flow_1.default)([getNamePart, exports.toTypeOrFieldNamePartTitle]);
95
- const toPascalCase = (lispCasedString = "") => lispCasedString && ((0, last_1.default)(lispCasedString.split("/")) || "").split("-").map(capitalize_1.default).join(" ");
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
- const { name } = splitKeyword(str);
99
- return name.toLowerCase() === name && !hasTildes(name);
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
- "fibery/type": "fibery/Database",
104
- "fibery/app": "fibery/Space",
53
+ "fibery/type": "fibery/Database",
54
+ "fibery/app": "fibery/Space"
105
55
  };
106
56
  const toNonEnumTitle = (strName) => {
107
- const str = nameOverrides[strName] || strName;
108
- return isObsoleteTitle(str) ? (0, exports.toPascalCase)(str) : (0, exports.toTypeOrFieldTitle)(str);
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
- const [templateType, targetType] = type.split("_");
113
- const { name: templateName, namespace: templateNamespace } = (0, exports.parseType)(templateType);
114
- const { name: targetName, namespace: targetNamespace } = (0, exports.parseType)(targetType);
115
- return { templateName, templateNamespace, targetName, targetNamespace };
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
- // enum logic
120
- const { templateName, targetName } = (0, exports.parseEnumType)(type);
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
- const str = typeOrAttr || "";
125
- return str.includes("_") ? toEnumTitle(str) : (0, exports.toNonEnumTitle)(str);
76
+ const str = typeOrAttr || "";
77
+ return str.includes("_") ? toEnumTitle(str) : toNonEnumTitle(str);
126
78
  };
127
- exports.toTitle = toTitle;
128
79
  const splitKeyword = (keyword) => {
129
- const str = keyword || "";
130
- const index = str.indexOf("/");
131
- if (index === -1) {
132
- return {
133
- namespace: "",
134
- name: str,
135
- };
136
- }
137
- const namespace = str.substring(0, index);
138
- const name = str.substring(index + 1);
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
- exports.parseType = (0, _1.memoize)((type) => {
145
- if (!type.includes("/")) {
146
- (0, trace_1.traceError)(`parseType invalid usage: passed type is '${type}'`);
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
- const { namespace, name } = (0, exports.parseType)(holderType);
152
- return `${enumName}_${namespace}/${name}`;
96
+ const { namespace, name } = parseType(holderType);
97
+ return `${enumName}_${namespace}/${name}`;
153
98
  };
154
- exports.makeEnumTypeNamePart = makeEnumTypeNamePart;
155
99
  const attachEnumNamespace = ({ enumNamespace, typeNamePart }) => {
156
- return `${enumNamespace}/${typeNamePart}`;
100
+ return `${enumNamespace}/${typeNamePart}`;
157
101
  };
158
- exports.attachEnumNamespace = attachEnumNamespace;
159
102
  const removeDeletedTypesAndFields = (rawSchema) => {
160
- const { "fibery/types": rawTypeObjects, ...schemaRest } = rawSchema;
161
- const filteredRawTypeObjects = rawTypeObjects
162
- .filter((rawTypeObject) => rawTypeObject["fibery/deleted?"] !== true)
163
- .map((rawTypeObject) => {
164
- const { "fibery/fields": rawFieldObjects, ...rawTypeObjectRest } = rawTypeObject;
165
- const filteredRawFieldObjects = rawFieldObjects.filter((rawFieldObject) => rawFieldObject["fibery/deleted?"] !== true);
166
- return { ...rawTypeObjectRest, "fibery/fields": filteredRawFieldObjects };
167
- });
168
- return { ...schemaRest, "fibery/types": filteredRawTypeObjects };
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
- exports.removeDeletedTypesAndFields = removeDeletedTypesAndFields;
171
- const getTypeObjectTitle = (typeObject, form) => form ? (form === "singular" ? typeObject.singularTitle : typeObject.pluralTitle) : typeObject.title;
172
- exports.getTypeObjectTitle = getTypeObjectTitle;
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.2.18",
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/helpers": "3.1.0",
21
- "@fibery/pluralize": "1.1.2"
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
- "@typescript/native-preview": "beta",
27
- "babel-loader": "10.0.0",
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": "rm -rf lib && tsc --project tsconfig.build.json",
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
- "check": "../../scripts/check.sh",
39
40
  "lint": "pnpm -w lint .",
40
- "typecheck": "../../scripts/typecheck.sh"
41
+ "typecheck": "../../scripts/typecheck.sh",
42
+ "check": "../../scripts/check.sh"
41
43
  },
42
44
  "types": "./lib/index.d.ts"
43
45
  }