@fibery/schema 11.1.0 → 11.2.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 +20 -0
- package/lib/brands.js +0 -0
- package/lib/field-object.d.ts +2 -0
- package/lib/field-object.js +14 -11
- package/lib/index.d.ts +2 -1
- package/lib/schema.d.ts +6 -5
- package/lib/schema.js +1 -1
- package/lib/type-object.d.ts +5 -4
- package/package.json +1 -1
package/lib/brands.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/brands.d.ts
|
|
2
|
+
declare const HOLDER: unique symbol;
|
|
3
|
+
declare const KIND: unique symbol;
|
|
4
|
+
type HolderBrand<H extends string> = {
|
|
5
|
+
readonly [HOLDER]?: H;
|
|
6
|
+
};
|
|
7
|
+
type KindBrand<K extends string> = {
|
|
8
|
+
readonly [KIND]?: K;
|
|
9
|
+
};
|
|
10
|
+
type Id = string & KindBrand<"id">;
|
|
11
|
+
type PublicId = string & KindBrand<"publicId">;
|
|
12
|
+
type Name = string & KindBrand<"name">;
|
|
13
|
+
type TypeId = Id & HolderBrand<"type">;
|
|
14
|
+
type FieldId = Id & HolderBrand<"field">;
|
|
15
|
+
type EntityId = Id & HolderBrand<"entity">;
|
|
16
|
+
type TypeName = Name & HolderBrand<"type">;
|
|
17
|
+
type FieldName = Name & HolderBrand<"field">;
|
|
18
|
+
type SpaceName = Name & HolderBrand<"space">;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { EntityId, FieldId, FieldName, Id, Name, PublicId, SpaceName, TypeId, TypeName };
|
package/lib/brands.js
ADDED
|
File without changes
|
package/lib/field-object.d.ts
CHANGED
|
@@ -122,6 +122,8 @@ declare class FieldObject {
|
|
|
122
122
|
name: string;
|
|
123
123
|
}>;
|
|
124
124
|
get title(): string;
|
|
125
|
+
/** the target type object, or null when the relation points at a removed Database */
|
|
126
|
+
resolveTypeObject(): TypeObject | null;
|
|
125
127
|
get typeObject(): TypeObject;
|
|
126
128
|
get holderTypeObject(): TypeObject;
|
|
127
129
|
get mixinTypeObject(): TypeObject | null;
|
package/lib/field-object.js
CHANGED
|
@@ -132,19 +132,22 @@ var FieldObject = class {
|
|
|
132
132
|
}
|
|
133
133
|
return value;
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
/** the target type object, or null when the relation points at a removed Database */
|
|
136
|
+
resolveTypeObject() {
|
|
136
137
|
const cache = this.cache ??= {};
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
138
|
+
const value = cache.typeObject;
|
|
139
|
+
if (value) return value;
|
|
140
|
+
const typeObject = this.schema.resolveTypeObject(this.type);
|
|
141
|
+
if (typeObject) cache.typeObject = typeObject;
|
|
142
|
+
return typeObject;
|
|
143
|
+
}
|
|
144
|
+
get typeObject() {
|
|
145
|
+
const typeObject = this.resolveTypeObject();
|
|
146
|
+
if (!typeObject) {
|
|
147
|
+
if (relaxable("fieldObject.typeObject")) return;
|
|
148
|
+
throw new NotFoundError(`!schema.typeObjectsByName["${this.type}"]`);
|
|
146
149
|
}
|
|
147
|
-
return
|
|
150
|
+
return typeObject;
|
|
148
151
|
}
|
|
149
152
|
get holderTypeObject() {
|
|
150
153
|
const cache = this.cache ??= {};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { EntityId, FieldId, FieldName, Id, Name, PublicId, SpaceName, TypeId, TypeName } from "./brands.js";
|
|
1
2
|
import { NotDefinedGetError, NotFoundError } from "./errors.js";
|
|
2
3
|
import { RawTypeObject, SyncSource, TypeObject, TypeObjectFactory, TypeObjectParams } from "./type-object.js";
|
|
3
4
|
import { RawSchema, Schema, SchemaRef } from "./schema.js";
|
|
4
5
|
import { Cardinality, FieldObject, FieldObjectParams, LinkRule, LinkRuleOperand, RawFieldObject, SyncField, SyncRelation } from "./field-object.js";
|
|
5
6
|
import { Factory, factory, protectiveFactory } from "./factory.js";
|
|
6
7
|
import { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets } from "./utils.js";
|
|
7
|
-
export { Cardinality, Factory, FieldObject, FieldObjectParams, LinkRule, LinkRuleOperand, NotDefinedGetError, NotFoundError, RawFieldObject, RawSchema, RawTypeObject, Schema, SchemaRef, SyncField, SyncRelation, SyncSource, TypeObject, TypeObjectFactory, TypeObjectParams, attachEnumNamespace, capitalizeFirstChar, factory, getTypeObjectTitle, 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, 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 };
|
package/lib/schema.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TypeId, TypeName } from "./brands.js";
|
|
1
2
|
import { RawTypeObject, TypeObject } from "./type-object.js";
|
|
2
3
|
import { FieldObject } from "./field-object.js";
|
|
3
4
|
import { Factory } from "./factory.js";
|
|
@@ -35,15 +36,15 @@ declare class Schema implements SchemaRef {
|
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
38
|
/** @internal resolves a field's `fibery/type` to its type object */
|
|
38
|
-
resolveTypeObject(type:
|
|
39
|
+
resolveTypeObject(type: TypeName): TypeObject | null;
|
|
39
40
|
/** @internal the type-component field pointing at `type`, if any */
|
|
40
41
|
resolveTypeComponentFieldObject(type: string): FieldObject | null;
|
|
41
42
|
/** @internal the non-entity-ref ends of a multi-relation */
|
|
42
43
|
resolveMultiRelatedFieldObjects(multiRelation: string): ReadonlyArray<FieldObject>;
|
|
43
|
-
getTypeObjectById(typeId:
|
|
44
|
-
getTypeObjectByName(typeName:
|
|
45
|
-
getTypeObjectByIdOrThrow(typeId:
|
|
46
|
-
getTypeObjectByNameOrThrow(typeName:
|
|
44
|
+
getTypeObjectById(typeId: TypeId): TypeObject | null;
|
|
45
|
+
getTypeObjectByName(typeName: TypeName): TypeObject | null;
|
|
46
|
+
getTypeObjectByIdOrThrow(typeId: TypeId): TypeObject;
|
|
47
|
+
getTypeObjectByNameOrThrow(typeName: TypeName): TypeObject;
|
|
47
48
|
}
|
|
48
49
|
//#endregion
|
|
49
50
|
export { RawSchema, Schema, SchemaRef };
|
package/lib/schema.js
CHANGED
|
@@ -31,7 +31,7 @@ var Schema = class {
|
|
|
31
31
|
}
|
|
32
32
|
/** @internal resolves a field's `fibery/type` to its type object */
|
|
33
33
|
resolveTypeObject(type) {
|
|
34
|
-
return this.
|
|
34
|
+
return this.getTypeObjectByName(type);
|
|
35
35
|
}
|
|
36
36
|
/** @internal the type-component field pointing at `type`, if any */
|
|
37
37
|
resolveTypeComponentFieldObject(type) {
|
package/lib/type-object.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FieldId, FieldName } from "./brands.js";
|
|
1
2
|
import { SchemaRef } from "./schema.js";
|
|
2
3
|
import { FieldObject, FieldObjectParams, RawFieldObject } from "./field-object.js";
|
|
3
4
|
//#region src/type-object.d.ts
|
|
@@ -57,10 +58,10 @@ declare class TypeObject {
|
|
|
57
58
|
private cache;
|
|
58
59
|
constructor({ rawTypeObject, schema, factory }: TypeObjectParams);
|
|
59
60
|
toJSON(): string | RawTypeObject;
|
|
60
|
-
getFieldObjectById(fieldId:
|
|
61
|
-
getFieldObjectByName(fieldName:
|
|
62
|
-
getFieldObjectByIdOrThrow(fieldId:
|
|
63
|
-
getFieldObjectByNameOrThrow(fieldName:
|
|
61
|
+
getFieldObjectById(fieldId: FieldId): FieldObject | null;
|
|
62
|
+
getFieldObjectByName(fieldName: FieldName): FieldObject | null;
|
|
63
|
+
getFieldObjectByIdOrThrow(fieldId: FieldId): FieldObject;
|
|
64
|
+
getFieldObjectByNameOrThrow(fieldName: FieldName): FieldObject;
|
|
64
65
|
get rawMeta(): Readonly<RawTypeObject["fibery/meta"]>;
|
|
65
66
|
get name(): string;
|
|
66
67
|
get description(): string | null;
|