@fibery/schema 12.0.0 → 12.0.1
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/errors.d.ts +23 -2
- package/lib/errors.js +24 -1
- package/lib/field-object.js +12 -4
- package/lib/index.d.ts +2 -2
- package/lib/relaxable.d.ts +4 -2
- package/lib/relaxable.js +9 -6
- package/lib/schema.js +31 -5
- package/lib/type-object.js +12 -4
- package/package.json +2 -2
package/lib/errors.d.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
//#region src/errors.d.ts
|
|
2
2
|
declare class NotDefinedGetError extends Error {}
|
|
3
|
-
|
|
3
|
+
type NotFoundNames = {
|
|
4
|
+
typeId?: string;
|
|
5
|
+
typeName?: string;
|
|
6
|
+
fieldId?: string;
|
|
7
|
+
fieldName?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* `message` says only what kind of thing was missing, so it is a safe Sentry title and a
|
|
11
|
+
* bounded grouping key. The names are own enumerable properties, which is what
|
|
12
|
+
* `extraErrorDataIntegration` collects into the event, and what devtools shows on expand.
|
|
13
|
+
*
|
|
14
|
+
* Throw sites fill in both the id and the name wherever they can resolve one: a bare uuid is
|
|
15
|
+
* unactionable in an issue, and a name alone will not survive a rename.
|
|
16
|
+
*/
|
|
17
|
+
declare class NotFoundError extends Error {
|
|
18
|
+
readonly what: "type" | "field";
|
|
19
|
+
readonly typeId: string | undefined;
|
|
20
|
+
readonly typeName: string | undefined;
|
|
21
|
+
readonly fieldId: string | undefined;
|
|
22
|
+
readonly fieldName: string | undefined;
|
|
23
|
+
constructor(what: "type" | "field", { typeId, typeName, fieldId, fieldName }: NotFoundNames);
|
|
24
|
+
}
|
|
4
25
|
//#endregion
|
|
5
|
-
export { NotDefinedGetError, NotFoundError };
|
|
26
|
+
export { NotDefinedGetError, NotFoundError, NotFoundNames };
|
package/lib/errors.js
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
//#region src/errors.ts
|
|
2
2
|
var NotDefinedGetError = class extends Error {};
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* `message` says only what kind of thing was missing, so it is a safe Sentry title and a
|
|
5
|
+
* bounded grouping key. The names are own enumerable properties, which is what
|
|
6
|
+
* `extraErrorDataIntegration` collects into the event, and what devtools shows on expand.
|
|
7
|
+
*
|
|
8
|
+
* Throw sites fill in both the id and the name wherever they can resolve one: a bare uuid is
|
|
9
|
+
* unactionable in an issue, and a name alone will not survive a rename.
|
|
10
|
+
*/
|
|
11
|
+
var NotFoundError = class extends Error {
|
|
12
|
+
what;
|
|
13
|
+
typeId;
|
|
14
|
+
typeName;
|
|
15
|
+
fieldId;
|
|
16
|
+
fieldName;
|
|
17
|
+
constructor(what, { typeId, typeName, fieldId, fieldName }) {
|
|
18
|
+
super(`${what} not found`);
|
|
19
|
+
this.name = "NotFoundError";
|
|
20
|
+
this.what = what;
|
|
21
|
+
this.typeId = typeId;
|
|
22
|
+
this.typeName = typeName;
|
|
23
|
+
this.fieldId = fieldId;
|
|
24
|
+
this.fieldName = fieldName;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
4
27
|
//#endregion
|
|
5
28
|
export { NotDefinedGetError, NotFoundError };
|
package/lib/field-object.js
CHANGED
|
@@ -144,8 +144,12 @@ var FieldObject = class {
|
|
|
144
144
|
get typeObject() {
|
|
145
145
|
const typeObject = this.resolveTypeObject();
|
|
146
146
|
if (!typeObject) {
|
|
147
|
-
if (relaxable(
|
|
148
|
-
throw new NotFoundError(
|
|
147
|
+
if (relaxable()) return;
|
|
148
|
+
throw new NotFoundError("type", {
|
|
149
|
+
typeName: this.type,
|
|
150
|
+
fieldId: this.id,
|
|
151
|
+
fieldName: this.name
|
|
152
|
+
});
|
|
149
153
|
}
|
|
150
154
|
return typeObject;
|
|
151
155
|
}
|
|
@@ -155,8 +159,12 @@ var FieldObject = class {
|
|
|
155
159
|
if (!value) {
|
|
156
160
|
const holderTypeObject = this.schema.resolveTypeObject(this.holderType);
|
|
157
161
|
if (!holderTypeObject) {
|
|
158
|
-
if (relaxable(
|
|
159
|
-
throw new NotFoundError(
|
|
162
|
+
if (relaxable()) return;
|
|
163
|
+
throw new NotFoundError("type", {
|
|
164
|
+
typeName: this.holderType,
|
|
165
|
+
fieldId: this.id,
|
|
166
|
+
fieldName: this.name
|
|
167
|
+
});
|
|
160
168
|
}
|
|
161
169
|
value = holderTypeObject;
|
|
162
170
|
cache.holderTypeObject = value;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EntityId, FieldId, FieldName, Id, Name, Permissive, PublicId, SpaceId, SpaceName, TypeId, TypeName } from "./brands.js";
|
|
2
|
-
import { NotDefinedGetError, NotFoundError } from "./errors.js";
|
|
2
|
+
import { NotDefinedGetError, NotFoundError, NotFoundNames } 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, 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 };
|
|
8
|
+
export { Cardinality, EntityId, Factory, FieldId, FieldName, FieldObject, FieldObjectParams, Id, LinkRule, LinkRuleOperand, Name, NotDefinedGetError, NotFoundError, NotFoundNames, 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/relaxable.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
//#region src/relaxable.d.ts
|
|
2
2
|
declare const relaxableRealm: () => boolean;
|
|
3
|
-
declare
|
|
3
|
+
declare let relaxable: () => boolean;
|
|
4
|
+
/** Temporary application policy while strict lookups roll out. Standalone schema stays strict. */
|
|
5
|
+
declare function setRelaxablePredicate(next: () => boolean): () => void;
|
|
4
6
|
//#endregion
|
|
5
|
-
export { relaxable, relaxableRealm };
|
|
7
|
+
export { relaxable, relaxableRealm, setRelaxablePredicate };
|
package/lib/relaxable.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { traceError } from "@fibery/helpers/utils/trace";
|
|
2
1
|
//#region src/relaxable.ts
|
|
3
2
|
const relaxableRealm = () => typeof window !== "undefined" && Boolean(window["x-ui-version"]);
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
let relaxable = () => false;
|
|
4
|
+
/** Temporary application policy while strict lookups roll out. Standalone schema stays strict. */
|
|
5
|
+
function setRelaxablePredicate(next) {
|
|
6
|
+
const previous = relaxable;
|
|
7
|
+
relaxable = next;
|
|
8
|
+
return () => {
|
|
9
|
+
relaxable = previous;
|
|
10
|
+
};
|
|
8
11
|
}
|
|
9
12
|
//#endregion
|
|
10
|
-
export { relaxable, relaxableRealm };
|
|
13
|
+
export { relaxable, relaxableRealm, setRelaxablePredicate };
|
package/lib/schema.js
CHANGED
|
@@ -4,6 +4,31 @@ import { relaxable } from "./relaxable.js";
|
|
|
4
4
|
const EMPTY_FIELD_OBJECTS = Object.freeze([]);
|
|
5
5
|
const typeComponentFieldObjects = /* @__PURE__ */ new WeakMap();
|
|
6
6
|
const multiRelatedFieldObjects = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
/**
|
|
8
|
+
* Children's view of their schema. Methods live on the prototype and the Schema itself in a
|
|
9
|
+
* WeakMap, so the only own property is `version` — a deep-equal walking a type object stops
|
|
10
|
+
* here and compares schema versions instead of re-entering the whole graph.
|
|
11
|
+
*/
|
|
12
|
+
const backRefSchemas = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
var SchemaBackRef = class {
|
|
14
|
+
version;
|
|
15
|
+
constructor(schema) {
|
|
16
|
+
this.version = schema.version;
|
|
17
|
+
backRefSchemas.set(this, schema);
|
|
18
|
+
}
|
|
19
|
+
get schema() {
|
|
20
|
+
return backRefSchemas.get(this);
|
|
21
|
+
}
|
|
22
|
+
resolveTypeObject(type) {
|
|
23
|
+
return this.schema.resolveTypeObject(type);
|
|
24
|
+
}
|
|
25
|
+
resolveTypeComponentFieldObject(type) {
|
|
26
|
+
return this.schema.resolveTypeComponentFieldObject(type);
|
|
27
|
+
}
|
|
28
|
+
resolveMultiRelatedFieldObjects(multiRelation) {
|
|
29
|
+
return this.schema.resolveMultiRelatedFieldObjects(multiRelation);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
7
32
|
var Schema = class {
|
|
8
33
|
typeObjects;
|
|
9
34
|
typeObjectsById;
|
|
@@ -16,9 +41,10 @@ var Schema = class {
|
|
|
16
41
|
this.id = id;
|
|
17
42
|
this.version = version;
|
|
18
43
|
this.rawTypeObjects = rawTypeObjects;
|
|
44
|
+
const schemaRef = new SchemaBackRef(this);
|
|
19
45
|
this.typeObjects = rawTypeObjects.map((rawTypeObject) => factory.makeTypeObject({
|
|
20
46
|
rawTypeObject,
|
|
21
|
-
schema:
|
|
47
|
+
schema: schemaRef
|
|
22
48
|
}));
|
|
23
49
|
this.typeObjectsById = factory.makeTypeObjectsById(this.typeObjects);
|
|
24
50
|
this.typeObjectsByName = factory.makeTypeObjectsByName(this.typeObjects);
|
|
@@ -66,16 +92,16 @@ var Schema = class {
|
|
|
66
92
|
getTypeObjectByIdOrThrow(typeId) {
|
|
67
93
|
const typeObject = this.getTypeObjectById(typeId);
|
|
68
94
|
if (!typeObject) {
|
|
69
|
-
if (relaxable(
|
|
70
|
-
throw new NotFoundError(
|
|
95
|
+
if (relaxable()) return;
|
|
96
|
+
throw new NotFoundError("type", { typeId });
|
|
71
97
|
}
|
|
72
98
|
return typeObject;
|
|
73
99
|
}
|
|
74
100
|
getTypeObjectByNameOrThrow(typeName) {
|
|
75
101
|
const typeObject = this.getTypeObjectByName(typeName);
|
|
76
102
|
if (!typeObject) {
|
|
77
|
-
if (relaxable(
|
|
78
|
-
throw new NotFoundError(
|
|
103
|
+
if (relaxable()) return;
|
|
104
|
+
throw new NotFoundError("type", { typeName });
|
|
79
105
|
}
|
|
80
106
|
return typeObject;
|
|
81
107
|
}
|
package/lib/type-object.js
CHANGED
|
@@ -33,16 +33,24 @@ var TypeObject = class {
|
|
|
33
33
|
getFieldObjectByIdOrThrow(fieldId) {
|
|
34
34
|
const fieldObject = this.getFieldObjectById(fieldId);
|
|
35
35
|
if (!fieldObject) {
|
|
36
|
-
if (relaxable(
|
|
37
|
-
throw new NotFoundError(
|
|
36
|
+
if (relaxable()) return;
|
|
37
|
+
throw new NotFoundError("field", {
|
|
38
|
+
typeId: this.id,
|
|
39
|
+
typeName: this.name,
|
|
40
|
+
fieldId
|
|
41
|
+
});
|
|
38
42
|
}
|
|
39
43
|
return fieldObject;
|
|
40
44
|
}
|
|
41
45
|
getFieldObjectByNameOrThrow(fieldName) {
|
|
42
46
|
const fieldObject = this.getFieldObjectByName(fieldName);
|
|
43
47
|
if (!fieldObject) {
|
|
44
|
-
if (relaxable(
|
|
45
|
-
throw new NotFoundError(
|
|
48
|
+
if (relaxable()) return;
|
|
49
|
+
throw new NotFoundError("field", {
|
|
50
|
+
typeId: this.id,
|
|
51
|
+
typeName: this.name,
|
|
52
|
+
fieldName
|
|
53
|
+
});
|
|
46
54
|
}
|
|
47
55
|
return fieldObject;
|
|
48
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/schema",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.1",
|
|
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": "4.
|
|
25
|
+
"@fibery/helpers": "4.1.0",
|
|
26
26
|
"@fibery/pluralize": "1.2.1"
|
|
27
27
|
}
|
|
28
28
|
}
|