@fibery/schema 11.0.0 → 11.1.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/field-object.js +14 -2
- package/lib/schema.d.ts +2 -2
- package/lib/schema.js +1 -1
- package/lib/type-object.js +3 -3
- package/package.json +1 -1
package/lib/field-object.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { NotFoundError } from "./errors.js";
|
|
2
|
+
import { relaxable } from "./relaxable.js";
|
|
1
3
|
import { parseType, toNonEnumTitle } from "./utils.js";
|
|
2
4
|
import { isPlainObject } from "@fibery/helpers/src/_";
|
|
3
5
|
//#region src/field-object.ts
|
|
@@ -134,7 +136,12 @@ var FieldObject = class {
|
|
|
134
136
|
const cache = this.cache ??= {};
|
|
135
137
|
let value = cache.typeObject;
|
|
136
138
|
if (!value) {
|
|
137
|
-
|
|
139
|
+
const typeObject = this.schema.resolveTypeObject(this.type);
|
|
140
|
+
if (!typeObject) {
|
|
141
|
+
if (relaxable("fieldObject.typeObject")) return;
|
|
142
|
+
throw new NotFoundError(`!schema.typeObjectsByName["${this.type}"]`);
|
|
143
|
+
}
|
|
144
|
+
value = typeObject;
|
|
138
145
|
cache.typeObject = value;
|
|
139
146
|
}
|
|
140
147
|
return value;
|
|
@@ -143,7 +150,12 @@ var FieldObject = class {
|
|
|
143
150
|
const cache = this.cache ??= {};
|
|
144
151
|
let value = cache.holderTypeObject;
|
|
145
152
|
if (!value) {
|
|
146
|
-
|
|
153
|
+
const holderTypeObject = this.schema.resolveTypeObject(this.holderType);
|
|
154
|
+
if (!holderTypeObject) {
|
|
155
|
+
if (relaxable("fieldObject.holderTypeObject")) return;
|
|
156
|
+
throw new NotFoundError(`!schema.typeObjectsByName["${this.holderType}"]`);
|
|
157
|
+
}
|
|
158
|
+
value = holderTypeObject;
|
|
147
159
|
cache.holderTypeObject = value;
|
|
148
160
|
}
|
|
149
161
|
return value;
|
package/lib/schema.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ type RawSchema = {
|
|
|
13
13
|
*/
|
|
14
14
|
type SchemaRef = {
|
|
15
15
|
readonly version: string;
|
|
16
|
-
resolveTypeObject: (type: string) => TypeObject;
|
|
16
|
+
resolveTypeObject: (type: string) => TypeObject | null;
|
|
17
17
|
resolveTypeComponentFieldObject: (type: string) => FieldObject | null;
|
|
18
18
|
resolveMultiRelatedFieldObjects: (multiRelation: string) => ReadonlyArray<FieldObject>;
|
|
19
19
|
};
|
|
@@ -35,7 +35,7 @@ declare class Schema implements SchemaRef {
|
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
/** @internal resolves a field's `fibery/type` to its type object */
|
|
38
|
-
resolveTypeObject(type: string): TypeObject;
|
|
38
|
+
resolveTypeObject(type: string): TypeObject | null;
|
|
39
39
|
/** @internal the type-component field pointing at `type`, if any */
|
|
40
40
|
resolveTypeComponentFieldObject(type: string): FieldObject | null;
|
|
41
41
|
/** @internal the non-entity-ref ends of a multi-relation */
|
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.typeObjectsByName[type]
|
|
34
|
+
return this.typeObjectsByName[type] ?? null;
|
|
35
35
|
}
|
|
36
36
|
/** @internal the type-component field pointing at `type`, if any */
|
|
37
37
|
resolveTypeComponentFieldObject(type) {
|
package/lib/type-object.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NotFoundError } from "./errors.js";
|
|
2
|
-
import { parseType, toTitle } from "./utils.js";
|
|
3
2
|
import { relaxable } from "./relaxable.js";
|
|
4
|
-
import {
|
|
3
|
+
import { parseType, toTitle } from "./utils.js";
|
|
4
|
+
import { isPlainObject, truthy } from "@fibery/helpers/src/_";
|
|
5
5
|
import { pluralize } from "@fibery/pluralize";
|
|
6
6
|
//#region src/type-object.ts
|
|
7
7
|
const EMPTY_META = Object.freeze({});
|
|
@@ -122,7 +122,7 @@ var TypeObject = class {
|
|
|
122
122
|
const cache = this.cache ??= {};
|
|
123
123
|
let value = cache.installedMixinTypeObjects;
|
|
124
124
|
if (!value) {
|
|
125
|
-
value = [...this.installedMixins].map((mixinName) => this.schema.resolveTypeObject(mixinName)).filter(
|
|
125
|
+
value = [...this.installedMixins].map((mixinName) => this.schema.resolveTypeObject(mixinName)).filter(truthy);
|
|
126
126
|
cache.installedMixinTypeObjects = value;
|
|
127
127
|
}
|
|
128
128
|
return value;
|