@fibery/schema 10.3.2 → 11.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/errors.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  //#region src/errors.d.ts
2
2
  declare class NotDefinedGetError extends Error {}
3
+ declare class NotFoundError extends Error {}
3
4
  //#endregion
4
- export { NotDefinedGetError };
5
+ export { NotDefinedGetError, NotFoundError };
package/lib/errors.js CHANGED
@@ -1,4 +1,5 @@
1
1
  //#region src/errors.ts
2
2
  var NotDefinedGetError = class extends Error {};
3
+ var NotFoundError = class extends Error {};
3
4
  //#endregion
4
- export { NotDefinedGetError };
5
+ export { NotDefinedGetError, NotFoundError };
package/lib/factory.d.ts CHANGED
@@ -1,23 +1,23 @@
1
1
  import { TypeObject, TypeObjectParams } from "./type-object.js";
2
- import { FieldObject, FieldObjectParams } from "./field-object.js";
3
2
  import { Schema } from "./schema.js";
3
+ import { FieldObject, FieldObjectParams } from "./field-object.js";
4
4
  //#region src/factory.d.ts
5
5
  type Factory = {
6
6
  makeSchema: (rawSchema: Record<string, unknown>, options?: {
7
7
  shouldRemoveDeletedTypesAndFields: boolean;
8
8
  }) => Schema;
9
9
  makeTypeObject: (params: Omit<TypeObjectParams, "factory">) => TypeObject;
10
- makeTypeObjectsById: (typeObjects: TypeObject[]) => Record<string, TypeObject>;
11
- makeTypeObjectsByName: (typeObjects: TypeObject[]) => Record<string, TypeObject>;
10
+ makeTypeObjectsById: (typeObjects: ReadonlyArray<TypeObject>) => Readonly<Record<string, TypeObject>>;
11
+ makeTypeObjectsByName: (typeObjects: ReadonlyArray<TypeObject>) => Readonly<Record<string, TypeObject>>;
12
12
  makeFieldObject: (params: FieldObjectParams) => FieldObject;
13
13
  makeFieldObjectsById: (params: {
14
14
  type: string;
15
- fieldObjects: FieldObject[];
16
- }) => Record<string, FieldObject>;
15
+ fieldObjects: ReadonlyArray<FieldObject>;
16
+ }) => Readonly<Record<string, FieldObject>>;
17
17
  makeFieldObjectsByName: (params: {
18
18
  type: string;
19
- fieldObjects: FieldObject[];
20
- }) => Record<string, FieldObject>;
19
+ fieldObjects: ReadonlyArray<FieldObject>;
20
+ }) => Readonly<Record<string, FieldObject>>;
21
21
  };
22
22
  declare const factory: Factory;
23
23
  declare const protectiveFactory: Factory;
@@ -1,4 +1,5 @@
1
1
  import { TypeObject } from "./type-object.js";
2
+ import { SchemaRef } from "./schema.js";
2
3
  //#region src/field-object.d.ts
3
4
  type Cardinality = ":cardinality/one-to-one" | ":cardinality/one-to-many" | ":cardinality/many-to-many" | ":cardinality/many-to-one";
4
5
  type LinkRuleOperand = {
@@ -10,6 +11,18 @@ type LinkRule = {
10
11
  logicalOperator: string;
11
12
  operands: Array<LinkRuleOperand>;
12
13
  };
14
+ type SyncField = {
15
+ id: string;
16
+ type: string;
17
+ };
18
+ type SyncRelation = {
19
+ id: string;
20
+ name: string;
21
+ type: string;
22
+ part: string;
23
+ targetName: string;
24
+ targetFieldId: string;
25
+ };
13
26
  type RawFieldObject = {
14
27
  "fibery/id": string;
15
28
  "fibery/name": string;
@@ -40,62 +53,86 @@ type RawFieldObject = {
40
53
  "fibery/multi-relation"?: string;
41
54
  "fibery/dependency?"?: boolean;
42
55
  "fibery/dependency-start?"?: boolean;
56
+ "fibery/field-reversed-collection?"?: boolean;
57
+ "fibery/type-component?"?: boolean;
58
+ "fibery/creation-date?"?: boolean;
59
+ "fibery/modification-date?"?: boolean;
60
+ "fibery/unique?"?: boolean;
61
+ "fibery/case-insensitive-text-unique?"?: boolean;
62
+ "fibery/user-group?"?: boolean;
63
+ "fibery/app-contributors-source?"?: boolean;
64
+ "fibery/entity-of-field-type-can-be-created-by-creator-only?"?: boolean;
65
+ "fibery/entity-update-field-only-effect?"?: boolean;
66
+ "history/disabled?"?: boolean;
67
+ "sync/field"?: SyncField;
68
+ "sync/relation"?: SyncRelation;
69
+ "ui/number-precision"?: unknown;
70
+ "ui/number-unit"?: unknown;
71
+ "ui/number-currency-code"?: unknown;
72
+ "ui/number-thousand-separator?"?: unknown;
73
+ "ui/number-format"?: unknown;
74
+ "ui/type"?: string;
43
75
  };
44
76
  };
45
77
  type FieldObjectParams = {
46
78
  rawFieldObject: RawFieldObject;
47
79
  holderType: string;
48
- resolveTypeObject: (type: string) => TypeObject;
49
- version: string;
50
- resolveMultiRelatedFieldObjects: (multiRelation: string) => FieldObject[];
80
+ schema: SchemaRef;
51
81
  };
52
82
  declare class FieldObject {
53
- name: string;
54
- description: string | null;
55
- id: string;
56
- type: string;
57
- rawMeta: Record<string, unknown>;
58
- holderType: string;
59
- isCollection: boolean;
60
- isTitle: boolean;
61
- isId: boolean;
62
- isPublicId: boolean;
63
- isReadOnly: boolean;
64
- isFormula: boolean;
65
- isFormulaDisabled: boolean;
66
- formulaDisableReason: string | null;
67
- formula: unknown | null;
68
- isLookup: boolean;
69
- hasLinkRule: boolean;
70
- linkRule: LinkRule | null;
71
- isLinkRuleDisabled: boolean;
72
- linkRuleDisableReason: string | null;
73
- relation: string | null;
74
- multiRelation: string | null;
75
- defaultValue: unknown | null;
76
- objectEditorOrder: number;
77
- isRequired: boolean;
78
- isHidden: boolean;
79
- isDeleted: boolean;
80
- disableLinkExistingItems: boolean;
81
- version: string;
82
- typeObject: TypeObject;
83
- mixinTypeObject: TypeObject | undefined;
84
- holderTypeObject: TypeObject;
85
- nameParts: {
83
+ private readonly raw;
84
+ readonly holderType: string;
85
+ private readonly schema;
86
+ /** Lazily filled; declared here so all instances share one hidden class. */
87
+ private cache;
88
+ constructor({ rawFieldObject, holderType, schema }: FieldObjectParams);
89
+ toJSON(): string | RawFieldObject;
90
+ get rawMeta(): Readonly<RawFieldObject["fibery/meta"]>;
91
+ get name(): string;
92
+ get description(): string | null;
93
+ get id(): string;
94
+ get type(): string;
95
+ get version(): string;
96
+ get isDeleted(): boolean;
97
+ get isCollection(): boolean;
98
+ get isTitle(): boolean;
99
+ get isId(): boolean;
100
+ get isPublicId(): boolean;
101
+ get isReadOnly(): boolean;
102
+ get isFormula(): boolean;
103
+ get isFormulaDisabled(): boolean;
104
+ get formulaDisableReason(): string | null;
105
+ get formula(): {} | null;
106
+ get isLookup(): boolean;
107
+ get hasLinkRule(): boolean;
108
+ get linkRule(): LinkRule | null;
109
+ get isLinkRuleDisabled(): boolean;
110
+ get linkRuleDisableReason(): string | null;
111
+ get relation(): string | null;
112
+ get multiRelation(): string | null;
113
+ get defaultValue(): {} | null;
114
+ get objectEditorOrder(): number;
115
+ get isRequired(): boolean;
116
+ get isHidden(): boolean;
117
+ get disableLinkExistingItems(): boolean;
118
+ get isDependency(): boolean;
119
+ get isDependencyStart(): boolean;
120
+ get nameParts(): Readonly<{
86
121
  namespace: string;
87
122
  name: string;
88
- };
89
- title: string;
90
- multiRelatedFieldObjects: Array<FieldObject>;
91
- isMultiField: boolean;
92
- isDependency: boolean;
93
- isDependencyStart: boolean;
94
- constructor({ rawFieldObject, holderType, resolveTypeObject, version, resolveMultiRelatedFieldObjects }: FieldObjectParams);
123
+ }>;
124
+ get title(): string;
125
+ get typeObject(): TypeObject;
126
+ get holderTypeObject(): TypeObject;
127
+ get mixinTypeObject(): TypeObject | null;
128
+ private findMixinTypeObject;
129
+ get isMultiField(): boolean;
130
+ get multiRelatedFieldObjects(): readonly FieldObject[];
95
131
  get relatedFieldObject(): FieldObject | null;
132
+ private findRelatedFieldObject;
96
133
  get cardinality(): Cardinality;
97
134
  /** @deprecated use !typeObject.isPrimitive && cardinality === ... instead */
98
135
  get kind(): ":field/basic" | ":field/reference" | ":field/reference-collection";
99
136
  }
100
137
  //#endregion
101
- export { Cardinality, FieldObject, FieldObjectParams, LinkRule, LinkRuleOperand, RawFieldObject };
138
+ export { Cardinality, FieldObject, FieldObjectParams, LinkRule, LinkRuleOperand, RawFieldObject, SyncField, SyncRelation };
@@ -1,137 +1,187 @@
1
1
  import { parseType, toNonEnumTitle } from "./utils.js";
2
- import { once } from "@fibery/helpers/src/_";
3
- import isFunction from "lodash/isFunction.js";
4
- import isPlainObject from "lodash/isPlainObject.js";
5
- import isString from "lodash/isString.js";
2
+ import { isPlainObject } from "@fibery/helpers/src/_";
6
3
  //#region src/field-object.ts
4
+ const EMPTY_META = Object.freeze({});
5
+ const EMPTY_FIELD_OBJECTS = Object.freeze([]);
6
+ const nameParts = /* @__PURE__ */ new WeakMap();
7
7
  var FieldObject = class {
8
- name;
9
- description;
10
- id;
11
- type;
12
- rawMeta;
8
+ raw;
13
9
  holderType;
14
- isCollection;
15
- isTitle;
16
- isId;
17
- isPublicId;
18
- isReadOnly;
19
- isFormula;
20
- isFormulaDisabled;
21
- formulaDisableReason;
22
- formula;
23
- isLookup;
24
- hasLinkRule;
25
- linkRule;
26
- isLinkRuleDisabled;
27
- linkRuleDisableReason;
28
- relation;
29
- multiRelation;
30
- defaultValue;
31
- objectEditorOrder;
32
- isRequired;
33
- isHidden;
34
- isDeleted;
35
- disableLinkExistingItems;
36
- version;
37
- typeObject;
38
- mixinTypeObject;
39
- holderTypeObject;
40
- nameParts;
41
- title;
42
- multiRelatedFieldObjects;
43
- isMultiField;
44
- isDependency;
45
- isDependencyStart;
46
- constructor({ rawFieldObject, holderType, resolveTypeObject, version, resolveMultiRelatedFieldObjects }) {
10
+ schema;
11
+ /** Lazily filled; declared here so all instances share one hidden class. */
12
+ cache;
13
+ constructor({ rawFieldObject, holderType, schema }) {
47
14
  if (!isPlainObject(rawFieldObject)) throw new Error("rawFieldObject arg must be plain object");
48
- if (!isString(holderType)) throw new Error("holderType arg must be string");
49
- if (!isFunction(resolveTypeObject)) throw new Error("resolveTypeObject arg must be function");
50
- if (!isFunction(resolveMultiRelatedFieldObjects)) throw new Error("resolveMultiRelationFieldObjects arg must be function");
51
- this.name = rawFieldObject["fibery/name"];
52
- this.description = rawFieldObject["fibery/description"] || null;
53
- this.id = rawFieldObject["fibery/id"];
54
- this.type = rawFieldObject["fibery/type"];
55
- const rawMeta = rawFieldObject["fibery/meta"] || {};
56
- this.rawMeta = rawMeta;
15
+ if (typeof holderType !== "string") throw new Error("holderType arg must be string");
16
+ if (!schema) throw new Error("schema arg must be provided");
17
+ this.raw = rawFieldObject;
57
18
  this.holderType = holderType;
58
- this.isCollection = rawMeta["fibery/collection?"] || false;
59
- this.isTitle = rawMeta["ui/title?"] || false;
60
- this.isId = rawMeta["fibery/id?"] || false;
61
- this.isPublicId = rawMeta["fibery/public-id?"] || false;
62
- this.isReadOnly = rawMeta["fibery/readonly?"] || false;
63
- this.isFormula = rawMeta["formula/formula?"] || false;
64
- this.isFormulaDisabled = rawMeta["formula/disabled?"] || false;
65
- this.formulaDisableReason = rawMeta["formula/disable-reason"] || null;
66
- this.formula = rawMeta["formula/formula"] || null;
67
- this.isLookup = rawMeta["formula/lookup?"] || false;
68
- this.hasLinkRule = rawMeta["link-rule/link-rule?"] || false;
69
- this.linkRule = rawMeta["link-rule/link-rule"] || null;
70
- this.isLinkRuleDisabled = rawMeta["link-rule/disabled?"] || false;
71
- this.linkRuleDisableReason = rawMeta["link-rule/disable-reason"] || null;
72
- this.relation = rawMeta["fibery/relation"] || null;
73
- this.defaultValue = rawMeta["fibery/default-value"] ?? null;
74
- this.objectEditorOrder = rawMeta["ui/object-editor-order"] || 0;
75
- this.isRequired = rawMeta["fibery/required?"] === true;
76
- this.isHidden = rawMeta["ui/hidden?"] === true;
77
- this.isDeleted = rawFieldObject["fibery/deleted?"] || false;
78
- this.disableLinkExistingItems = rawMeta["ui/disable-link-existing-items"] || false;
79
- this.version = version;
80
- this.multiRelation = rawMeta["fibery/multi-relation"] || null;
81
- this.isDependency = rawMeta["fibery/dependency?"] || false;
82
- this.isDependencyStart = rawMeta["fibery/dependency-start?"] || false;
83
- Object.defineProperties(this, {
84
- typeObject: {
85
- configurable: false,
86
- enumerable: true,
87
- get: once(() => resolveTypeObject(this.type))
88
- },
89
- mixinTypeObject: {
90
- configurable: false,
91
- enumerable: true,
92
- get: once(() => {
93
- return this.holderTypeObject.installedMixinTypeObjects.find((mixinTypeObject) => Object.hasOwn(mixinTypeObject.fieldObjectsByName, this.name) || this.name === "workflow/state" && mixinTypeObject.name === "workflow/workflow");
94
- })
95
- },
96
- holderTypeObject: {
97
- configurable: false,
98
- enumerable: true,
99
- get: once(() => {
100
- return resolveTypeObject(holderType);
101
- })
102
- },
103
- nameParts: {
104
- configurable: false,
105
- enumerable: true,
106
- get: once(() => parseType(rawFieldObject["fibery/name"]))
107
- },
108
- title: {
109
- configurable: false,
110
- enumerable: true,
111
- get: once(() => {
112
- if (this.name === "fibery/role" && this.holderType === "fibery/user") return "User Role";
113
- return toNonEnumTitle(rawFieldObject["fibery/name"]);
114
- })
115
- },
116
- multiRelatedFieldObjects: {
117
- configurable: false,
118
- enumerable: true,
119
- get: once(() => {
120
- const { multiRelation, typeObject } = this;
121
- if (!multiRelation || !typeObject.isEntityRef) return [];
122
- return resolveMultiRelatedFieldObjects(multiRelation);
123
- })
124
- },
125
- isMultiField: {
126
- configurable: false,
127
- enumerable: true,
128
- get: once(() => {
129
- return this.typeObject.isEntityRef;
130
- })
131
- }
132
- });
19
+ this.schema = schema;
20
+ this.cache = void 0;
21
+ }
22
+ toJSON() {
23
+ if (process.env.NODE_ENV === "test") return `<schema.typeObjectsByName["${this.holderType}"].fieldObjectsByName["${this.name}"]>`;
24
+ return this.raw;
25
+ }
26
+ get rawMeta() {
27
+ return this.raw["fibery/meta"] || EMPTY_META;
28
+ }
29
+ get name() {
30
+ return this.raw["fibery/name"];
31
+ }
32
+ get description() {
33
+ return this.raw["fibery/description"] || null;
34
+ }
35
+ get id() {
36
+ return this.raw["fibery/id"];
37
+ }
38
+ get type() {
39
+ return this.raw["fibery/type"];
40
+ }
41
+ get version() {
42
+ return this.schema.version;
43
+ }
44
+ get isDeleted() {
45
+ return this.raw["fibery/deleted?"] || false;
46
+ }
47
+ get isCollection() {
48
+ return this.rawMeta["fibery/collection?"] || false;
49
+ }
50
+ get isTitle() {
51
+ return this.rawMeta["ui/title?"] || false;
52
+ }
53
+ get isId() {
54
+ return this.rawMeta["fibery/id?"] || false;
55
+ }
56
+ get isPublicId() {
57
+ return this.rawMeta["fibery/public-id?"] || false;
58
+ }
59
+ get isReadOnly() {
60
+ return this.rawMeta["fibery/readonly?"] || false;
61
+ }
62
+ get isFormula() {
63
+ return this.rawMeta["formula/formula?"] || false;
64
+ }
65
+ get isFormulaDisabled() {
66
+ return this.rawMeta["formula/disabled?"] || false;
67
+ }
68
+ get formulaDisableReason() {
69
+ return this.rawMeta["formula/disable-reason"] || null;
70
+ }
71
+ get formula() {
72
+ return this.rawMeta["formula/formula"] || null;
73
+ }
74
+ get isLookup() {
75
+ return this.rawMeta["formula/lookup?"] || false;
76
+ }
77
+ get hasLinkRule() {
78
+ return this.rawMeta["link-rule/link-rule?"] || false;
79
+ }
80
+ get linkRule() {
81
+ return this.rawMeta["link-rule/link-rule"] || null;
82
+ }
83
+ get isLinkRuleDisabled() {
84
+ return this.rawMeta["link-rule/disabled?"] || false;
85
+ }
86
+ get linkRuleDisableReason() {
87
+ return this.rawMeta["link-rule/disable-reason"] || null;
88
+ }
89
+ get relation() {
90
+ return this.rawMeta["fibery/relation"] || null;
91
+ }
92
+ get multiRelation() {
93
+ return this.rawMeta["fibery/multi-relation"] || null;
94
+ }
95
+ get defaultValue() {
96
+ return this.rawMeta["fibery/default-value"] ?? null;
97
+ }
98
+ get objectEditorOrder() {
99
+ return this.rawMeta["ui/object-editor-order"] || 0;
100
+ }
101
+ get isRequired() {
102
+ return this.rawMeta["fibery/required?"] === true;
103
+ }
104
+ get isHidden() {
105
+ return this.rawMeta["ui/hidden?"] === true;
106
+ }
107
+ get disableLinkExistingItems() {
108
+ return this.rawMeta["ui/disable-link-existing-items"] || false;
109
+ }
110
+ get isDependency() {
111
+ return this.rawMeta["fibery/dependency?"] || false;
112
+ }
113
+ get isDependencyStart() {
114
+ return this.rawMeta["fibery/dependency-start?"] || false;
115
+ }
116
+ get nameParts() {
117
+ let value = nameParts.get(this.raw);
118
+ if (!value) {
119
+ value = parseType(this.raw["fibery/name"]);
120
+ nameParts.set(this.raw, value);
121
+ }
122
+ return value;
123
+ }
124
+ get title() {
125
+ const cache = this.cache ??= {};
126
+ let value = cache.title;
127
+ if (value === void 0) {
128
+ value = this.name === "fibery/role" && this.holderType === "fibery/user" ? "User Role" : toNonEnumTitle(this.raw["fibery/name"]);
129
+ cache.title = value;
130
+ }
131
+ return value;
132
+ }
133
+ get typeObject() {
134
+ const cache = this.cache ??= {};
135
+ let value = cache.typeObject;
136
+ if (!value) {
137
+ value = this.schema.resolveTypeObject(this.type);
138
+ cache.typeObject = value;
139
+ }
140
+ return value;
141
+ }
142
+ get holderTypeObject() {
143
+ const cache = this.cache ??= {};
144
+ let value = cache.holderTypeObject;
145
+ if (!value) {
146
+ value = this.schema.resolveTypeObject(this.holderType);
147
+ cache.holderTypeObject = value;
148
+ }
149
+ return value;
150
+ }
151
+ get mixinTypeObject() {
152
+ const cache = this.cache ??= {};
153
+ if (!cache.hasMixinTypeObject) {
154
+ cache.mixinTypeObject = this.findMixinTypeObject();
155
+ cache.hasMixinTypeObject = true;
156
+ }
157
+ return cache.mixinTypeObject ?? null;
158
+ }
159
+ findMixinTypeObject() {
160
+ for (const mixinTypeObject of this.holderTypeObject.installedMixinTypeObjects) if (mixinTypeObject.getFieldObjectByName(this.name) || this.name === "workflow/state" && mixinTypeObject.name === "workflow/workflow") return mixinTypeObject;
161
+ return null;
162
+ }
163
+ get isMultiField() {
164
+ return this.typeObject.isEntityRef;
165
+ }
166
+ get multiRelatedFieldObjects() {
167
+ const cache = this.cache ??= {};
168
+ let value = cache.multiRelatedFieldObjects;
169
+ if (!value) {
170
+ const { multiRelation, typeObject } = this;
171
+ value = !multiRelation || !typeObject.isEntityRef ? EMPTY_FIELD_OBJECTS : this.schema.resolveMultiRelatedFieldObjects(multiRelation);
172
+ cache.multiRelatedFieldObjects = value;
173
+ }
174
+ return value;
133
175
  }
134
176
  get relatedFieldObject() {
177
+ const cache = this.cache ??= {};
178
+ if (!cache.hasRelatedFieldObject) {
179
+ cache.relatedFieldObject = this.findRelatedFieldObject();
180
+ cache.hasRelatedFieldObject = true;
181
+ }
182
+ return cache.relatedFieldObject ?? null;
183
+ }
184
+ findRelatedFieldObject() {
135
185
  const { name, relation, multiRelation, typeObject } = this;
136
186
  if (!relation && !multiRelation) return null;
137
187
  if (!relation && multiRelation && typeObject.isEntityRef) return null;
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { NotDefinedGetError } from "./errors.js";
2
- import { RawTypeObject, SyncSource, TypeObject, TypeObjectParams } from "./type-object.js";
3
- import { Cardinality, FieldObject, FieldObjectParams, LinkRule, LinkRuleOperand, RawFieldObject } from "./field-object.js";
4
- import { RawSchema, Schema } from "./schema.js";
1
+ import { NotDefinedGetError, NotFoundError } from "./errors.js";
2
+ import { RawTypeObject, SyncSource, TypeObject, TypeObjectFactory, TypeObjectParams } from "./type-object.js";
3
+ import { RawSchema, Schema, SchemaRef } from "./schema.js";
4
+ import { Cardinality, FieldObject, FieldObjectParams, LinkRule, LinkRuleOperand, RawFieldObject, SyncField, SyncRelation } from "./field-object.js";
5
5
  import { Factory, factory, protectiveFactory } from "./factory.js";
6
6
  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, RawFieldObject, RawSchema, RawTypeObject, Schema, SyncSource, TypeObject, TypeObjectParams, attachEnumNamespace, capitalizeFirstChar, factory, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, protectiveFactory, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
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 };
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { NotDefinedGetError } from "./errors.js";
1
+ import { NotDefinedGetError, NotFoundError } from "./errors.js";
2
2
  import { attachEnumNamespace, capitalizeFirstChar, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets } from "./utils.js";
3
3
  import { FieldObject } from "./field-object.js";
4
4
  import { Schema } from "./schema.js";
5
5
  import { TypeObject } from "./type-object.js";
6
6
  import { factory, protectiveFactory } from "./factory.js";
7
- export { FieldObject, NotDefinedGetError, Schema, TypeObject, attachEnumNamespace, capitalizeFirstChar, factory, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, protectiveFactory, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
7
+ export { FieldObject, NotDefinedGetError, NotFoundError, Schema, TypeObject, attachEnumNamespace, capitalizeFirstChar, factory, getTypeObjectTitle, makeEnumTypeNamePart, parseEnumType, parseType, protectiveFactory, removeDeletedTypesAndFields, toNonEnumTitle, toPascalCase, toTitle, toTypeOrFieldNamePartTitle, toTypeOrFieldTitle, withOnlyDefinedGets };
@@ -0,0 +1,4 @@
1
+ //#region src/relaxable.d.ts
2
+ declare function relaxable(method: string): boolean;
3
+ //#endregion
4
+ export { relaxable };
@@ -0,0 +1,10 @@
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 };
package/lib/schema.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RawTypeObject, TypeObject } from "./type-object.js";
2
+ import { FieldObject } from "./field-object.js";
2
3
  import { Factory } from "./factory.js";
3
4
  //#region src/schema.d.ts
4
5
  type RawSchema = {
@@ -6,16 +7,43 @@ type RawSchema = {
6
7
  "fibery/types": RawTypeObject[];
7
8
  "fibery/version": string;
8
9
  };
9
- declare class Schema {
10
- typeObjects: Array<TypeObject>;
11
- typeObjectsById: Record<string, TypeObject>;
12
- typeObjectsByName: Record<string, TypeObject>;
13
- id: string;
14
- version: string;
10
+ /**
11
+ * @internal the wiring TypeObject/FieldObject need from their owning schema. A structural
12
+ * type rather than `Schema` so standalone type objects can supply a stub.
13
+ */
14
+ type SchemaRef = {
15
+ readonly version: string;
16
+ resolveTypeObject: (type: string) => TypeObject;
17
+ resolveTypeComponentFieldObject: (type: string) => FieldObject | null;
18
+ resolveMultiRelatedFieldObjects: (multiRelation: string) => ReadonlyArray<FieldObject>;
19
+ };
20
+ declare class Schema implements SchemaRef {
21
+ readonly typeObjects: ReadonlyArray<TypeObject>;
22
+ private readonly typeObjectsById;
23
+ private readonly typeObjectsByName;
24
+ readonly id: string;
25
+ readonly version: string;
26
+ private readonly rawTypeObjects;
15
27
  constructor({ factory, rawSchema: { "fibery/id": id, "fibery/types": rawTypeObjects, "fibery/version": version } }: {
16
28
  factory: Factory;
17
29
  rawSchema: RawSchema;
18
30
  });
31
+ toJSON(): {
32
+ "fibery/types": readonly RawTypeObject[];
33
+ "fibery/meta": {
34
+ "fibery/version": string;
35
+ };
36
+ };
37
+ /** @internal resolves a field's `fibery/type` to its type object */
38
+ resolveTypeObject(type: string): TypeObject;
39
+ /** @internal the type-component field pointing at `type`, if any */
40
+ resolveTypeComponentFieldObject(type: string): FieldObject | null;
41
+ /** @internal the non-entity-ref ends of a multi-relation */
42
+ resolveMultiRelatedFieldObjects(multiRelation: string): ReadonlyArray<FieldObject>;
43
+ getTypeObjectById(typeId: string): TypeObject | null;
44
+ getTypeObjectByName(typeName: string): TypeObject | null;
45
+ getTypeObjectByIdOrThrow(typeId: string): TypeObject;
46
+ getTypeObjectByNameOrThrow(typeName: string): TypeObject;
19
47
  }
20
48
  //#endregion
21
- export { RawSchema, Schema };
49
+ export { RawSchema, Schema, SchemaRef };