@fibery/schema 11.2.0 → 12.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/lib/brands.d.ts +24 -18
- package/lib/field-object.d.ts +11 -10
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -2
- package/lib/relaxable.d.ts +2 -1
- package/lib/relaxable.js +1 -1
- package/lib/schema.d.ts +7 -7
- package/lib/type-object.d.ts +10 -10
- package/lib/utils.d.ts +10 -32
- package/lib/utils.js +40 -13
- package/package.json +2 -2
package/lib/brands.d.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
+
import { Holder, Kind } from "@fibery/helpers/utils/types";
|
|
1
2
|
//#region src/brands.d.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
type Id = string & Kind<"id">;
|
|
4
|
+
type PublicId = string & Kind<"publicId">;
|
|
5
|
+
type Name = string & Kind<"name">;
|
|
6
|
+
type TypeId = string & Kind<"id"> & Holder<"type">;
|
|
7
|
+
type FieldId = string & Kind<"id"> & Holder<"field">;
|
|
8
|
+
type EntityId = string & Kind<"id"> & Holder<"entity">;
|
|
9
|
+
type SpaceId = string & Kind<"id"> & Holder<"space">;
|
|
10
|
+
type TypeName = string & Kind<"name"> & Holder<"type">;
|
|
11
|
+
type FieldName = string & Kind<"name"> & Holder<"field">;
|
|
12
|
+
type SpaceName = string & Kind<"name"> & Holder<"space">;
|
|
13
|
+
/**
|
|
14
|
+
* A brand with its tags made optional, for lookup parameters.
|
|
15
|
+
*
|
|
16
|
+
* `Partial` turns the required `Kind`/`Holder` into optional properties, so a
|
|
17
|
+
* plain string or literal passes. Sibling brands still carry a *conflicting*
|
|
18
|
+
* tag, so `getTypeObjectByName(fieldName)` remains an error.
|
|
19
|
+
*
|
|
20
|
+
* The leading `string &` is load-bearing: `Partial` also makes
|
|
21
|
+
* `String.prototype` optional, and the getters index a lookup map with the
|
|
22
|
+
* parameter.
|
|
23
|
+
*/
|
|
24
|
+
type Permissive<B extends string> = string & Partial<B>;
|
|
19
25
|
//#endregion
|
|
20
|
-
export { EntityId, FieldId, FieldName, Id, Name, PublicId, SpaceName, TypeId, TypeName };
|
|
26
|
+
export { EntityId, FieldId, FieldName, Id, Name, Permissive, PublicId, SpaceId, SpaceName, TypeId, TypeName };
|
package/lib/field-object.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FieldId, FieldName, SpaceName, TypeName } from "./brands.js";
|
|
1
2
|
import { TypeObject } from "./type-object.js";
|
|
2
3
|
import { SchemaRef } from "./schema.js";
|
|
3
4
|
//#region src/field-object.d.ts
|
|
@@ -21,12 +22,12 @@ type SyncRelation = {
|
|
|
21
22
|
type: string;
|
|
22
23
|
part: string;
|
|
23
24
|
targetName: string;
|
|
24
|
-
targetFieldId:
|
|
25
|
+
targetFieldId: FieldId;
|
|
25
26
|
};
|
|
26
27
|
type RawFieldObject = {
|
|
27
|
-
"fibery/id":
|
|
28
|
-
"fibery/name":
|
|
29
|
-
"fibery/type":
|
|
28
|
+
"fibery/id": FieldId;
|
|
29
|
+
"fibery/name": FieldName;
|
|
30
|
+
"fibery/type": TypeName;
|
|
30
31
|
"fibery/description"?: string;
|
|
31
32
|
"fibery/deleted?"?: boolean;
|
|
32
33
|
"fibery/meta": {
|
|
@@ -76,22 +77,22 @@ type RawFieldObject = {
|
|
|
76
77
|
};
|
|
77
78
|
type FieldObjectParams = {
|
|
78
79
|
rawFieldObject: RawFieldObject;
|
|
79
|
-
holderType:
|
|
80
|
+
holderType: TypeName;
|
|
80
81
|
schema: SchemaRef;
|
|
81
82
|
};
|
|
82
83
|
declare class FieldObject {
|
|
83
84
|
private readonly raw;
|
|
84
|
-
readonly holderType:
|
|
85
|
+
readonly holderType: TypeName;
|
|
85
86
|
private readonly schema;
|
|
86
87
|
/** Lazily filled; declared here so all instances share one hidden class. */
|
|
87
88
|
private cache;
|
|
88
89
|
constructor({ rawFieldObject, holderType, schema }: FieldObjectParams);
|
|
89
90
|
toJSON(): string | RawFieldObject;
|
|
90
91
|
get rawMeta(): Readonly<RawFieldObject["fibery/meta"]>;
|
|
91
|
-
get name():
|
|
92
|
+
get name(): FieldName;
|
|
92
93
|
get description(): string | null;
|
|
93
|
-
get id():
|
|
94
|
-
get type():
|
|
94
|
+
get id(): FieldId;
|
|
95
|
+
get type(): TypeName;
|
|
95
96
|
get version(): string;
|
|
96
97
|
get isDeleted(): boolean;
|
|
97
98
|
get isCollection(): boolean;
|
|
@@ -118,7 +119,7 @@ declare class FieldObject {
|
|
|
118
119
|
get isDependency(): boolean;
|
|
119
120
|
get isDependencyStart(): boolean;
|
|
120
121
|
get nameParts(): Readonly<{
|
|
121
|
-
namespace:
|
|
122
|
+
namespace: SpaceName;
|
|
122
123
|
name: string;
|
|
123
124
|
}>;
|
|
124
125
|
get title(): string;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EntityId, FieldId, FieldName, Id, Name, PublicId, SpaceName, TypeId, TypeName } from "./brands.js";
|
|
1
|
+
import { EntityId, FieldId, FieldName, Id, Name, Permissive, PublicId, SpaceId, SpaceName, TypeId, TypeName } from "./brands.js";
|
|
2
2
|
import { NotDefinedGetError, NotFoundError } from "./errors.js";
|
|
3
3
|
import { RawTypeObject, SyncSource, TypeObject, TypeObjectFactory, TypeObjectParams } from "./type-object.js";
|
|
4
4
|
import { RawSchema, Schema, SchemaRef } from "./schema.js";
|
|
5
5
|
import { Cardinality, FieldObject, FieldObjectParams, LinkRule, LinkRuleOperand, RawFieldObject, SyncField, SyncRelation } from "./field-object.js";
|
|
6
6
|
import { Factory, factory, protectiveFactory } from "./factory.js";
|
|
7
|
-
import { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets } from "./utils.js";
|
|
8
|
-
export { Cardinality, EntityId, Factory, FieldId, FieldName, FieldObject, FieldObjectParams, Id, LinkRule, LinkRuleOperand, Name, NotDefinedGetError, NotFoundError, PublicId, RawFieldObject, RawSchema, RawTypeObject, Schema, SchemaRef, SpaceName, SyncField, SyncRelation, SyncSource, TypeId, TypeName, TypeObject, TypeObjectFactory, TypeObjectParams, attachEnumNamespace, capitalizeFirstChar, factory, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, protectiveFactory, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
|
|
7
|
+
import { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, isOneOf, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets } from "./utils.js";
|
|
8
|
+
export { Cardinality, EntityId, Factory, FieldId, FieldName, FieldObject, FieldObjectParams, Id, LinkRule, LinkRuleOperand, Name, NotDefinedGetError, NotFoundError, Permissive, PublicId, RawFieldObject, RawSchema, RawTypeObject, Schema, SchemaRef, SpaceId, SpaceName, SyncField, SyncRelation, SyncSource, TypeId, TypeName, TypeObject, TypeObjectFactory, TypeObjectParams, attachEnumNamespace, capitalizeFirstChar, factory, getTypeObjectTitle, isOneOf, makeEnumTypeNamePart, parseEnumType, parseType, protectiveFactory, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NotDefinedGetError, NotFoundError } from "./errors.js";
|
|
2
|
-
import { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets } from "./utils.js";
|
|
2
|
+
import { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, isOneOf, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets } from "./utils.js";
|
|
3
3
|
import { FieldObject } from "./field-object.js";
|
|
4
4
|
import { Schema } from "./schema.js";
|
|
5
5
|
import { TypeObject } from "./type-object.js";
|
|
6
6
|
import { factory, protectiveFactory } from "./factory.js";
|
|
7
|
-
export { FieldObject, NotDefinedGetError, NotFoundError, Schema, TypeObject, attachEnumNamespace, capitalizeFirstChar, factory, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, protectiveFactory, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
|
|
7
|
+
export { FieldObject, NotDefinedGetError, NotFoundError, Schema, TypeObject, attachEnumNamespace, capitalizeFirstChar, factory, getTypeObjectTitle, isOneOf, makeEnumTypeNamePart, parseEnumType, parseType, protectiveFactory, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
|
package/lib/relaxable.d.ts
CHANGED
package/lib/relaxable.js
CHANGED
package/lib/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TypeId, TypeName } from "./brands.js";
|
|
1
|
+
import { Permissive, TypeId, TypeName } from "./brands.js";
|
|
2
2
|
import { RawTypeObject, TypeObject } from "./type-object.js";
|
|
3
3
|
import { FieldObject } from "./field-object.js";
|
|
4
4
|
import { Factory } from "./factory.js";
|
|
@@ -14,7 +14,7 @@ type RawSchema = {
|
|
|
14
14
|
*/
|
|
15
15
|
type SchemaRef = {
|
|
16
16
|
readonly version: string;
|
|
17
|
-
resolveTypeObject: (type:
|
|
17
|
+
resolveTypeObject: (type: Permissive<TypeName>) => TypeObject | null;
|
|
18
18
|
resolveTypeComponentFieldObject: (type: string) => FieldObject | null;
|
|
19
19
|
resolveMultiRelatedFieldObjects: (multiRelation: string) => ReadonlyArray<FieldObject>;
|
|
20
20
|
};
|
|
@@ -36,15 +36,15 @@ declare class Schema implements SchemaRef {
|
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
/** @internal resolves a field's `fibery/type` to its type object */
|
|
39
|
-
resolveTypeObject(type: TypeName): TypeObject | null;
|
|
39
|
+
resolveTypeObject(type: Permissive<TypeName>): TypeObject | null;
|
|
40
40
|
/** @internal the type-component field pointing at `type`, if any */
|
|
41
41
|
resolveTypeComponentFieldObject(type: string): FieldObject | null;
|
|
42
42
|
/** @internal the non-entity-ref ends of a multi-relation */
|
|
43
43
|
resolveMultiRelatedFieldObjects(multiRelation: string): ReadonlyArray<FieldObject>;
|
|
44
|
-
getTypeObjectById(typeId: TypeId): TypeObject | null;
|
|
45
|
-
getTypeObjectByName(typeName: TypeName): TypeObject | null;
|
|
46
|
-
getTypeObjectByIdOrThrow(typeId: TypeId): TypeObject;
|
|
47
|
-
getTypeObjectByNameOrThrow(typeName: TypeName): TypeObject;
|
|
44
|
+
getTypeObjectById(typeId: Permissive<TypeId>): TypeObject | null;
|
|
45
|
+
getTypeObjectByName(typeName: Permissive<TypeName>): TypeObject | null;
|
|
46
|
+
getTypeObjectByIdOrThrow(typeId: Permissive<TypeId>): TypeObject;
|
|
47
|
+
getTypeObjectByNameOrThrow(typeName: Permissive<TypeName>): TypeObject;
|
|
48
48
|
}
|
|
49
49
|
//#endregion
|
|
50
50
|
export { RawSchema, Schema, SchemaRef };
|
package/lib/type-object.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldId, FieldName } from "./brands.js";
|
|
1
|
+
import { FieldId, FieldName, Permissive, SpaceName, TypeId, TypeName } from "./brands.js";
|
|
2
2
|
import { SchemaRef } from "./schema.js";
|
|
3
3
|
import { FieldObject, FieldObjectParams, RawFieldObject } from "./field-object.js";
|
|
4
4
|
//#region src/type-object.d.ts
|
|
@@ -10,8 +10,8 @@ type SyncSource = {
|
|
|
10
10
|
type: string;
|
|
11
11
|
};
|
|
12
12
|
type RawTypeObject = {
|
|
13
|
-
"fibery/id":
|
|
14
|
-
"fibery/name":
|
|
13
|
+
"fibery/id": TypeId;
|
|
14
|
+
"fibery/name": TypeName;
|
|
15
15
|
"fibery/description"?: string | null;
|
|
16
16
|
"fibery/deleted?"?: boolean;
|
|
17
17
|
"fibery/fields": RawFieldObject[];
|
|
@@ -58,14 +58,14 @@ declare class TypeObject {
|
|
|
58
58
|
private cache;
|
|
59
59
|
constructor({ rawTypeObject, schema, factory }: TypeObjectParams);
|
|
60
60
|
toJSON(): string | RawTypeObject;
|
|
61
|
-
getFieldObjectById(fieldId: FieldId): FieldObject | null;
|
|
62
|
-
getFieldObjectByName(fieldName: FieldName): FieldObject | null;
|
|
63
|
-
getFieldObjectByIdOrThrow(fieldId: FieldId): FieldObject;
|
|
64
|
-
getFieldObjectByNameOrThrow(fieldName: FieldName): FieldObject;
|
|
61
|
+
getFieldObjectById(fieldId: Permissive<FieldId>): FieldObject | null;
|
|
62
|
+
getFieldObjectByName(fieldName: Permissive<FieldName>): FieldObject | null;
|
|
63
|
+
getFieldObjectByIdOrThrow(fieldId: Permissive<FieldId>): FieldObject;
|
|
64
|
+
getFieldObjectByNameOrThrow(fieldName: Permissive<FieldName>): FieldObject;
|
|
65
65
|
get rawMeta(): Readonly<RawTypeObject["fibery/meta"]>;
|
|
66
|
-
get name():
|
|
66
|
+
get name(): TypeName;
|
|
67
67
|
get description(): string | null;
|
|
68
|
-
get id():
|
|
68
|
+
get id(): TypeId;
|
|
69
69
|
get isDeleted(): boolean;
|
|
70
70
|
get version(): string;
|
|
71
71
|
get isEntityRef(): boolean;
|
|
@@ -81,7 +81,7 @@ declare class TypeObject {
|
|
|
81
81
|
get units(): unknown[] | null;
|
|
82
82
|
get syncSource(): SyncSource | null;
|
|
83
83
|
get nameParts(): Readonly<{
|
|
84
|
-
namespace:
|
|
84
|
+
namespace: SpaceName;
|
|
85
85
|
name: string;
|
|
86
86
|
}>;
|
|
87
87
|
get installedMixins(): ReadonlySet<string>;
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SpaceName, TypeName } from "./brands.js";
|
|
2
|
+
import { RawTypeObject, TypeObject } from "./type-object.js";
|
|
2
3
|
import { RawSchema } from "./schema.js";
|
|
3
|
-
import { RawFieldObject } from "./field-object.js";
|
|
4
4
|
//#region src/utils.d.ts
|
|
5
5
|
declare const withOnlyDefinedGets: (target: any, targetKind?: string) => any;
|
|
6
6
|
declare const capitalizeFirstChar: (input: string) => string;
|
|
@@ -10,13 +10,13 @@ declare const toPascalCase: (lispCasedString?: string) => string;
|
|
|
10
10
|
declare const toNonEnumTitle: (strName: string) => string;
|
|
11
11
|
declare const parseEnumType: (type: string) => {
|
|
12
12
|
templateName: string;
|
|
13
|
-
templateNamespace:
|
|
13
|
+
templateNamespace: SpaceName;
|
|
14
14
|
targetName: string;
|
|
15
|
-
targetNamespace:
|
|
15
|
+
targetNamespace: SpaceName;
|
|
16
16
|
};
|
|
17
17
|
declare const toTitle: (typeOrAttr: string) => string;
|
|
18
18
|
declare const parseType: (type: string) => {
|
|
19
|
-
namespace:
|
|
19
|
+
namespace: SpaceName;
|
|
20
20
|
name: string;
|
|
21
21
|
};
|
|
22
22
|
declare const makeEnumTypeNamePart: ({ holderType, enumName }: {
|
|
@@ -26,36 +26,14 @@ declare const makeEnumTypeNamePart: ({ holderType, enumName }: {
|
|
|
26
26
|
declare const attachEnumNamespace: ({ enumNamespace, typeNamePart }: {
|
|
27
27
|
enumNamespace: string;
|
|
28
28
|
typeNamePart: string;
|
|
29
|
-
}) =>
|
|
29
|
+
}) => TypeName;
|
|
30
30
|
declare const removeDeletedTypesAndFields: (rawSchema: RawSchema) => {
|
|
31
|
-
"fibery/types":
|
|
32
|
-
"fibery/fields": RawFieldObject[];
|
|
33
|
-
"fibery/id": string;
|
|
34
|
-
"fibery/name": string;
|
|
35
|
-
"fibery/description"?: string | null;
|
|
36
|
-
"fibery/deleted?"?: boolean;
|
|
37
|
-
"fibery/meta": {
|
|
38
|
-
"fibery/domain?"?: boolean;
|
|
39
|
-
"fibery/platform?"?: boolean;
|
|
40
|
-
"fibery/highlight?"?: boolean;
|
|
41
|
-
"app/mixin?"?: boolean;
|
|
42
|
-
"ui/mixin-icon"?: string;
|
|
43
|
-
"fibery/enum?"?: boolean;
|
|
44
|
-
"fibery/primitive?"?: boolean;
|
|
45
|
-
"ui/writer-mode?"?: boolean;
|
|
46
|
-
"ui/color"?: string;
|
|
47
|
-
"ui/units"?: unknown[];
|
|
48
|
-
"app/mixins"?: Record<string, boolean>;
|
|
49
|
-
"sync/source"?: SyncSource;
|
|
50
|
-
"fibery/secured?"?: boolean;
|
|
51
|
-
"fibery/type-component?"?: boolean;
|
|
52
|
-
"ref/ref-db?"?: boolean;
|
|
53
|
-
"semantic-index/enabled"?: boolean;
|
|
54
|
-
};
|
|
55
|
-
}[];
|
|
31
|
+
"fibery/types": RawTypeObject[];
|
|
56
32
|
"fibery/id": string;
|
|
57
33
|
"fibery/version": string;
|
|
58
34
|
};
|
|
59
35
|
declare const getTypeObjectTitle: (typeObject: TypeObject, form?: "singular" | "plural") => string;
|
|
36
|
+
/** `===` does not narrow a branded string (`TypeName`, `FieldName`) to a literal; this does. */
|
|
37
|
+
declare const isOneOf: <const L extends readonly string[]>(value: string, literals: L) => value is L[number];
|
|
60
38
|
//#endregion
|
|
61
|
-
export { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
|
|
39
|
+
export { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, isOneOf, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
|
package/lib/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NotDefinedGetError } from "./errors.js";
|
|
2
|
+
import { relaxableRealm } from "./relaxable.js";
|
|
2
3
|
import { printJsPath } from "./print-utils.js";
|
|
3
4
|
import { traceError } from "@fibery/helpers/utils/trace";
|
|
4
5
|
//#region src/utils.ts
|
|
@@ -43,7 +44,11 @@ const capitalizeWord = (str) => str.charAt(0).toUpperCase() + str.slice(1).toLow
|
|
|
43
44
|
const toPascalCase = (lispCasedString = "") => lispCasedString && (lispCasedString.split("/").at(-1) || "").split("-").map(capitalizeWord).join(" ");
|
|
44
45
|
const isObsoleteTitle = (str) => {
|
|
45
46
|
const { name } = splitKeyword(str);
|
|
46
|
-
return name.toLowerCase() === name && !hasTildes(name);
|
|
47
|
+
return startsWithLowercaseLetter(name) && name.toLowerCase() === name && !hasTildes(name);
|
|
48
|
+
};
|
|
49
|
+
const startsWithLowercaseLetter = (str) => {
|
|
50
|
+
const first = str.charAt(0);
|
|
51
|
+
return first !== "" && first !== first.toUpperCase();
|
|
47
52
|
};
|
|
48
53
|
const hasTildes = (str) => str.includes("~");
|
|
49
54
|
const nameOverrides = {
|
|
@@ -96,21 +101,43 @@ const makeEnumTypeNamePart = ({ holderType, enumName }) => {
|
|
|
96
101
|
const attachEnumNamespace = ({ enumNamespace, typeNamePart }) => {
|
|
97
102
|
return `${enumNamespace}/${typeNamePart}`;
|
|
98
103
|
};
|
|
104
|
+
const reportedStrippedFields = /* @__PURE__ */ new Set();
|
|
105
|
+
const reportStrippedField = (holderTypeName, rawFieldObject, isTypeSoftDeleted) => {
|
|
106
|
+
if (!relaxableRealm()) return;
|
|
107
|
+
if (process.env.NODE_ENV === "production") return;
|
|
108
|
+
const key = `${holderTypeName} ${rawFieldObject["fibery/name"]} ${rawFieldObject["fibery/type"]}`;
|
|
109
|
+
if (reportedStrippedFields.has(key)) return;
|
|
110
|
+
reportedStrippedFields.add(key);
|
|
111
|
+
traceError(`Stripped field "${rawFieldObject["fibery/name"]}" of "${holderTypeName}": its type "${rawFieldObject["fibery/type"]}" is ${isTypeSoftDeleted ? "soft-deleted" : "not in schema"}`);
|
|
112
|
+
};
|
|
99
113
|
const removeDeletedTypesAndFields = (rawSchema) => {
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
const rawTypeObjects = rawSchema["fibery/types"];
|
|
115
|
+
const survivingTypeNames = /* @__PURE__ */ new Set();
|
|
116
|
+
const deletedTypeNames = /* @__PURE__ */ new Set();
|
|
117
|
+
for (const rawTypeObject of rawTypeObjects) if (rawTypeObject["fibery/deleted?"] === true) deletedTypeNames.add(rawTypeObject["fibery/name"]);
|
|
118
|
+
else survivingTypeNames.add(rawTypeObject["fibery/name"]);
|
|
119
|
+
const survivingRawTypeObjects = [];
|
|
120
|
+
for (const rawTypeObject of rawTypeObjects) {
|
|
121
|
+
if (rawTypeObject["fibery/deleted?"] === true) continue;
|
|
122
|
+
const rawFieldObjects = rawTypeObject["fibery/fields"];
|
|
123
|
+
const survivingRawFieldObjects = rawFieldObjects.filter((rawFieldObject) => {
|
|
124
|
+
if (rawFieldObject["fibery/deleted?"] === true) return false;
|
|
125
|
+
if (survivingTypeNames.has(rawFieldObject["fibery/type"])) return true;
|
|
126
|
+
reportStrippedField(rawTypeObject["fibery/name"], rawFieldObject, deletedTypeNames.has(rawFieldObject["fibery/type"]));
|
|
127
|
+
return false;
|
|
128
|
+
});
|
|
129
|
+
survivingRawTypeObjects.push(survivingRawFieldObjects.length === rawFieldObjects.length ? rawTypeObject : {
|
|
130
|
+
...rawTypeObject,
|
|
131
|
+
"fibery/fields": survivingRawFieldObjects
|
|
132
|
+
});
|
|
133
|
+
}
|
|
109
134
|
return {
|
|
110
|
-
...
|
|
111
|
-
"fibery/types":
|
|
135
|
+
...rawSchema,
|
|
136
|
+
"fibery/types": survivingRawTypeObjects
|
|
112
137
|
};
|
|
113
138
|
};
|
|
114
139
|
const getTypeObjectTitle = (typeObject, form) => form ? form === "singular" ? typeObject.singularTitle : typeObject.pluralTitle : typeObject.title;
|
|
140
|
+
/** `===` does not narrow a branded string (`TypeName`, `FieldName`) to a literal; this does. */
|
|
141
|
+
const isOneOf = (value, literals) => literals.includes(value);
|
|
115
142
|
//#endregion
|
|
116
|
-
export { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
|
|
143
|
+
export { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, isOneOf, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/schema",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Fibery schema utils",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"files": [
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"lodash": "4.17.21",
|
|
25
|
-
"@fibery/helpers": "
|
|
25
|
+
"@fibery/helpers": "4.0.0",
|
|
26
26
|
"@fibery/pluralize": "1.2.1"
|
|
27
27
|
}
|
|
28
28
|
}
|