@fibery/schema 12.0.0 → 12.0.2
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 +10 -9
- package/lib/index.d.ts +2 -2
- package/lib/schema.js +29 -10
- package/lib/type-object.js +10 -9
- package/lib/utils.js +2 -2
- package/package.json +2 -2
- package/lib/relaxable.d.ts +0 -5
- package/lib/relaxable.js +0 -10
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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NotFoundError } from "./errors.js";
|
|
2
|
-
import { relaxable } from "./relaxable.js";
|
|
3
2
|
import { parseType, toNonEnumTitle } from "./utils.js";
|
|
4
3
|
import { isPlainObject } from "@fibery/helpers/src/_";
|
|
5
4
|
//#region src/field-object.ts
|
|
@@ -143,10 +142,11 @@ var FieldObject = class {
|
|
|
143
142
|
}
|
|
144
143
|
get typeObject() {
|
|
145
144
|
const typeObject = this.resolveTypeObject();
|
|
146
|
-
if (!typeObject) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
if (!typeObject) throw new NotFoundError("type", {
|
|
146
|
+
typeName: this.type,
|
|
147
|
+
fieldId: this.id,
|
|
148
|
+
fieldName: this.name
|
|
149
|
+
});
|
|
150
150
|
return typeObject;
|
|
151
151
|
}
|
|
152
152
|
get holderTypeObject() {
|
|
@@ -154,10 +154,11 @@ var FieldObject = class {
|
|
|
154
154
|
let value = cache.holderTypeObject;
|
|
155
155
|
if (!value) {
|
|
156
156
|
const holderTypeObject = this.schema.resolveTypeObject(this.holderType);
|
|
157
|
-
if (!holderTypeObject) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
if (!holderTypeObject) throw new NotFoundError("type", {
|
|
158
|
+
typeName: this.holderType,
|
|
159
|
+
fieldId: this.id,
|
|
160
|
+
fieldName: this.name
|
|
161
|
+
});
|
|
161
162
|
value = holderTypeObject;
|
|
162
163
|
cache.holderTypeObject = value;
|
|
163
164
|
}
|
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/schema.js
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
import { NotFoundError } from "./errors.js";
|
|
2
|
-
import { relaxable } from "./relaxable.js";
|
|
3
2
|
//#region src/schema.ts
|
|
4
3
|
const EMPTY_FIELD_OBJECTS = Object.freeze([]);
|
|
5
4
|
const typeComponentFieldObjects = /* @__PURE__ */ new WeakMap();
|
|
6
5
|
const multiRelatedFieldObjects = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
/**
|
|
7
|
+
* Children's view of their schema. Methods live on the prototype and the Schema itself in a
|
|
8
|
+
* WeakMap, so the only own property is `version` — a deep-equal walking a type object stops
|
|
9
|
+
* here and compares schema versions instead of re-entering the whole graph.
|
|
10
|
+
*/
|
|
11
|
+
const backRefSchemas = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
var SchemaBackRef = class {
|
|
13
|
+
version;
|
|
14
|
+
constructor(schema) {
|
|
15
|
+
this.version = schema.version;
|
|
16
|
+
backRefSchemas.set(this, schema);
|
|
17
|
+
}
|
|
18
|
+
get schema() {
|
|
19
|
+
return backRefSchemas.get(this);
|
|
20
|
+
}
|
|
21
|
+
resolveTypeObject(type) {
|
|
22
|
+
return this.schema.resolveTypeObject(type);
|
|
23
|
+
}
|
|
24
|
+
resolveTypeComponentFieldObject(type) {
|
|
25
|
+
return this.schema.resolveTypeComponentFieldObject(type);
|
|
26
|
+
}
|
|
27
|
+
resolveMultiRelatedFieldObjects(multiRelation) {
|
|
28
|
+
return this.schema.resolveMultiRelatedFieldObjects(multiRelation);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
7
31
|
var Schema = class {
|
|
8
32
|
typeObjects;
|
|
9
33
|
typeObjectsById;
|
|
@@ -16,9 +40,10 @@ var Schema = class {
|
|
|
16
40
|
this.id = id;
|
|
17
41
|
this.version = version;
|
|
18
42
|
this.rawTypeObjects = rawTypeObjects;
|
|
43
|
+
const schemaRef = new SchemaBackRef(this);
|
|
19
44
|
this.typeObjects = rawTypeObjects.map((rawTypeObject) => factory.makeTypeObject({
|
|
20
45
|
rawTypeObject,
|
|
21
|
-
schema:
|
|
46
|
+
schema: schemaRef
|
|
22
47
|
}));
|
|
23
48
|
this.typeObjectsById = factory.makeTypeObjectsById(this.typeObjects);
|
|
24
49
|
this.typeObjectsByName = factory.makeTypeObjectsByName(this.typeObjects);
|
|
@@ -65,18 +90,12 @@ var Schema = class {
|
|
|
65
90
|
}
|
|
66
91
|
getTypeObjectByIdOrThrow(typeId) {
|
|
67
92
|
const typeObject = this.getTypeObjectById(typeId);
|
|
68
|
-
if (!typeObject) {
|
|
69
|
-
if (relaxable("getTypeObjectByIdOrThrow")) return;
|
|
70
|
-
throw new NotFoundError(`!schema.typeObjectsById["${typeId}"]`);
|
|
71
|
-
}
|
|
93
|
+
if (!typeObject) throw new NotFoundError("type", { typeId });
|
|
72
94
|
return typeObject;
|
|
73
95
|
}
|
|
74
96
|
getTypeObjectByNameOrThrow(typeName) {
|
|
75
97
|
const typeObject = this.getTypeObjectByName(typeName);
|
|
76
|
-
if (!typeObject) {
|
|
77
|
-
if (relaxable("getTypeObjectByNameOrThrow")) return;
|
|
78
|
-
throw new NotFoundError(`!schema.typeObjectsByName["${typeName}"]`);
|
|
79
|
-
}
|
|
98
|
+
if (!typeObject) throw new NotFoundError("type", { typeName });
|
|
80
99
|
return typeObject;
|
|
81
100
|
}
|
|
82
101
|
};
|
package/lib/type-object.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NotFoundError } from "./errors.js";
|
|
2
|
-
import { relaxable } from "./relaxable.js";
|
|
3
2
|
import { parseType, toTitle } from "./utils.js";
|
|
4
3
|
import { isPlainObject, truthy } from "@fibery/helpers/src/_";
|
|
5
4
|
import { pluralize } from "@fibery/pluralize";
|
|
@@ -32,18 +31,20 @@ var TypeObject = class {
|
|
|
32
31
|
}
|
|
33
32
|
getFieldObjectByIdOrThrow(fieldId) {
|
|
34
33
|
const fieldObject = this.getFieldObjectById(fieldId);
|
|
35
|
-
if (!fieldObject) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
if (!fieldObject) throw new NotFoundError("field", {
|
|
35
|
+
typeId: this.id,
|
|
36
|
+
typeName: this.name,
|
|
37
|
+
fieldId
|
|
38
|
+
});
|
|
39
39
|
return fieldObject;
|
|
40
40
|
}
|
|
41
41
|
getFieldObjectByNameOrThrow(fieldName) {
|
|
42
42
|
const fieldObject = this.getFieldObjectByName(fieldName);
|
|
43
|
-
if (!fieldObject) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if (!fieldObject) throw new NotFoundError("field", {
|
|
44
|
+
typeId: this.id,
|
|
45
|
+
typeName: this.name,
|
|
46
|
+
fieldName
|
|
47
|
+
});
|
|
47
48
|
return fieldObject;
|
|
48
49
|
}
|
|
49
50
|
get rawMeta() {
|
package/lib/utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NotDefinedGetError } from "./errors.js";
|
|
2
|
-
import { relaxableRealm } from "./relaxable.js";
|
|
3
2
|
import { printJsPath } from "./print-utils.js";
|
|
4
3
|
import { traceError } from "@fibery/helpers/utils/trace";
|
|
5
4
|
//#region src/utils.ts
|
|
@@ -101,9 +100,10 @@ const makeEnumTypeNamePart = ({ holderType, enumName }) => {
|
|
|
101
100
|
const attachEnumNamespace = ({ enumNamespace, typeNamePart }) => {
|
|
102
101
|
return `${enumNamespace}/${typeNamePart}`;
|
|
103
102
|
};
|
|
103
|
+
const insideApplication = () => typeof window !== "undefined" && Boolean(window["x-ui-version"]);
|
|
104
104
|
const reportedStrippedFields = /* @__PURE__ */ new Set();
|
|
105
105
|
const reportStrippedField = (holderTypeName, rawFieldObject, isTypeSoftDeleted) => {
|
|
106
|
-
if (!
|
|
106
|
+
if (!insideApplication()) return;
|
|
107
107
|
if (process.env.NODE_ENV === "production") return;
|
|
108
108
|
const key = `${holderTypeName} ${rawFieldObject["fibery/name"]} ${rawFieldObject["fibery/type"]}`;
|
|
109
109
|
if (reportedStrippedFields.has(key)) return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/schema",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.2",
|
|
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.1",
|
|
26
26
|
"@fibery/pluralize": "1.2.1"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/lib/relaxable.d.ts
DELETED
package/lib/relaxable.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { traceError } from "@fibery/helpers/utils/trace";
|
|
2
|
-
//#region src/relaxable.ts
|
|
3
|
-
const relaxableRealm = () => typeof window !== "undefined" && Boolean(window["x-ui-version"]);
|
|
4
|
-
function relaxable(method) {
|
|
5
|
-
if (!relaxableRealm()) return false;
|
|
6
|
-
traceError(/* @__PURE__ */ new Error(`Relaxed ${method}, return undefined`));
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
export { relaxable, relaxableRealm };
|