@fibery/schema 11.3.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 -11
- package/lib/field-object.d.ts +4 -4
- package/lib/index.d.ts +2 -2
- package/lib/schema.d.ts +7 -7
- package/lib/type-object.d.ts +6 -6
- package/lib/utils.d.ts +5 -4
- package/lib/utils.js +1 -0
- package/package.json +2 -2
package/lib/brands.d.ts
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Holder, Kind } from "@fibery/helpers/utils/types";
|
|
2
2
|
//#region src/brands.d.ts
|
|
3
|
-
type Id = string &
|
|
4
|
-
type PublicId = string &
|
|
5
|
-
type Name = string &
|
|
6
|
-
type TypeId =
|
|
7
|
-
type FieldId =
|
|
8
|
-
type EntityId =
|
|
9
|
-
type
|
|
10
|
-
type
|
|
11
|
-
type
|
|
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>;
|
|
12
25
|
//#endregion
|
|
13
|
-
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,4 +1,4 @@
|
|
|
1
|
-
import { FieldId, FieldName, TypeName } from "./brands.js";
|
|
1
|
+
import { FieldId, FieldName, SpaceName, TypeName } from "./brands.js";
|
|
2
2
|
import { TypeObject } from "./type-object.js";
|
|
3
3
|
import { SchemaRef } from "./schema.js";
|
|
4
4
|
//#region src/field-object.d.ts
|
|
@@ -77,12 +77,12 @@ type RawFieldObject = {
|
|
|
77
77
|
};
|
|
78
78
|
type FieldObjectParams = {
|
|
79
79
|
rawFieldObject: RawFieldObject;
|
|
80
|
-
holderType:
|
|
80
|
+
holderType: TypeName;
|
|
81
81
|
schema: SchemaRef;
|
|
82
82
|
};
|
|
83
83
|
declare class FieldObject {
|
|
84
84
|
private readonly raw;
|
|
85
|
-
readonly holderType:
|
|
85
|
+
readonly holderType: TypeName;
|
|
86
86
|
private readonly schema;
|
|
87
87
|
/** Lazily filled; declared here so all instances share one hidden class. */
|
|
88
88
|
private cache;
|
|
@@ -119,7 +119,7 @@ declare class FieldObject {
|
|
|
119
119
|
get isDependency(): boolean;
|
|
120
120
|
get isDependencyStart(): boolean;
|
|
121
121
|
get nameParts(): Readonly<{
|
|
122
|
-
namespace:
|
|
122
|
+
namespace: SpaceName;
|
|
123
123
|
name: string;
|
|
124
124
|
}>;
|
|
125
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
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, PublicId, RawFieldObject, RawSchema, RawTypeObject, Schema, SchemaRef, 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 };
|
|
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/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, TypeId, TypeName } 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
|
|
@@ -58,10 +58,10 @@ 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
66
|
get name(): TypeName;
|
|
67
67
|
get description(): string | null;
|
|
@@ -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,3 +1,4 @@
|
|
|
1
|
+
import { SpaceName, TypeName } from "./brands.js";
|
|
1
2
|
import { RawTypeObject, TypeObject } from "./type-object.js";
|
|
2
3
|
import { RawSchema } from "./schema.js";
|
|
3
4
|
//#region src/utils.d.ts
|
|
@@ -9,13 +10,13 @@ declare const toPascalCase: (lispCasedString?: string) => string;
|
|
|
9
10
|
declare const toNonEnumTitle: (strName: string) => string;
|
|
10
11
|
declare const parseEnumType: (type: string) => {
|
|
11
12
|
templateName: string;
|
|
12
|
-
templateNamespace:
|
|
13
|
+
templateNamespace: SpaceName;
|
|
13
14
|
targetName: string;
|
|
14
|
-
targetNamespace:
|
|
15
|
+
targetNamespace: SpaceName;
|
|
15
16
|
};
|
|
16
17
|
declare const toTitle: (typeOrAttr: string) => string;
|
|
17
18
|
declare const parseType: (type: string) => {
|
|
18
|
-
namespace:
|
|
19
|
+
namespace: SpaceName;
|
|
19
20
|
name: string;
|
|
20
21
|
};
|
|
21
22
|
declare const makeEnumTypeNamePart: ({ holderType, enumName }: {
|
|
@@ -25,7 +26,7 @@ declare const makeEnumTypeNamePart: ({ holderType, enumName }: {
|
|
|
25
26
|
declare const attachEnumNamespace: ({ enumNamespace, typeNamePart }: {
|
|
26
27
|
enumNamespace: string;
|
|
27
28
|
typeNamePart: string;
|
|
28
|
-
}) =>
|
|
29
|
+
}) => TypeName;
|
|
29
30
|
declare const removeDeletedTypesAndFields: (rawSchema: RawSchema) => {
|
|
30
31
|
"fibery/types": RawTypeObject[];
|
|
31
32
|
"fibery/id": string;
|
package/lib/utils.js
CHANGED
|
@@ -104,6 +104,7 @@ const attachEnumNamespace = ({ enumNamespace, typeNamePart }) => {
|
|
|
104
104
|
const reportedStrippedFields = /* @__PURE__ */ new Set();
|
|
105
105
|
const reportStrippedField = (holderTypeName, rawFieldObject, isTypeSoftDeleted) => {
|
|
106
106
|
if (!relaxableRealm()) return;
|
|
107
|
+
if (process.env.NODE_ENV === "production") return;
|
|
107
108
|
const key = `${holderTypeName} ${rawFieldObject["fibery/name"]} ${rawFieldObject["fibery/type"]}`;
|
|
108
109
|
if (reportedStrippedFields.has(key)) return;
|
|
109
110
|
reportedStrippedFields.add(key);
|
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
|
}
|