@sanity/agent-schema 0.1.0 → 0.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/dist/index.d.ts CHANGED
@@ -1,149 +1,5 @@
1
+ import { _ as SchemaFieldDisplayOptions, a as ValidateValueFn, b as SchemaTypes, c as ValidationErrorCode, d as DatasetStats, f as DatasetStatsSchema, g as ProcessedDocumentType, h as ManifestSchemaType, i as PatchOperations, l as ValidationResult, m as ManifestField, n as InsertOperation, o as ValidationContext, p as LexiconResponse, r as LocalizationConfig, s as ValidationError, t as FieldSchemaLookupResult, u as CompressedSchemaOptions, v as SchemaFilter, y as SchemaProcessorOptions } from "./_chunks-dts/types.js";
1
2
  import { SanityClient } from "@sanity/client";
2
- import { z } from "zod";
3
- import { LexiconResponse } from "@sanity/schema-descriptor-utils";
4
- type ManifestSerializable = string | number | boolean | {
5
- [k: string]: ManifestSerializable;
6
- } | ManifestSerializable[];
7
- type ManifestSchemaType = {
8
- type: string;
9
- name: string;
10
- title?: string;
11
- description?: string;
12
- deprecated?: {
13
- reason: string;
14
- };
15
- readOnly?: boolean | 'conditional';
16
- hidden?: boolean | 'conditional';
17
- validation?: ManifestValidationGroup[];
18
- fields?: ManifestField[];
19
- to?: ManifestReferenceMember[];
20
- of?: ManifestArrayMember[];
21
- preview?: {
22
- select: Record<string, string>;
23
- };
24
- fieldsets?: ManifestFieldset[];
25
- options?: Record<string, ManifestSerializable>;
26
- marks?: {
27
- annotations?: ManifestArrayMember[];
28
- decorators?: ManifestTitledValue[];
29
- };
30
- lists?: ManifestTitledValue[];
31
- styles?: ManifestTitledValue[];
32
- [index: string]: unknown;
33
- };
34
- type ManifestFieldset = {
35
- name: string;
36
- title?: string;
37
- [index: string]: ManifestSerializable | undefined;
38
- };
39
- type ManifestTitledValue = {
40
- value: string;
41
- title?: string;
42
- };
43
- type ManifestField = ManifestSchemaType & {
44
- fieldset?: string;
45
- };
46
- type ManifestArrayMember = Omit<ManifestSchemaType, 'name'> & {
47
- name?: string;
48
- };
49
- type ManifestReferenceMember = Omit<ManifestSchemaType, 'name'> & {
50
- name?: string;
51
- };
52
- type ManifestValidationGroup = {
53
- rules: ManifestValidationRule[];
54
- message?: string;
55
- level?: 'error' | 'warning' | 'info';
56
- };
57
- type ManifestValidationRule = {
58
- flag: 'presence' | string;
59
- constraint?: 'required' | ManifestSerializable;
60
- [index: string]: ManifestSerializable | undefined;
61
- };
62
- declare const DatasetStatsSchema: z.ZodObject<{
63
- documentCount: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
64
- referenceCount: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
65
- incoming: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodNumber, z.ZodLiteral<"unknown">]>>;
66
- outgoing: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodNumber, z.ZodLiteral<"unknown">]>>;
67
- }, "strip", z.ZodTypeAny, {
68
- incoming: Record<string, number | "unknown">;
69
- outgoing: Record<string, number | "unknown">;
70
- }, {
71
- incoming: Record<string, number | "unknown">;
72
- outgoing: Record<string, number | "unknown">;
73
- }>>>;
74
- }, "strip", z.ZodTypeAny, {
75
- documentCount?: Record<string, number> | undefined;
76
- referenceCount?: Record<string, {
77
- incoming: Record<string, number | "unknown">;
78
- outgoing: Record<string, number | "unknown">;
79
- }> | undefined;
80
- }, {
81
- documentCount?: Record<string, number> | undefined;
82
- referenceCount?: Record<string, {
83
- incoming: Record<string, number | "unknown">;
84
- outgoing: Record<string, number | "unknown">;
85
- }> | undefined;
86
- }>;
87
- type DatasetStats = z.infer<typeof DatasetStatsSchema>;
88
- type ReferenceInfo = {
89
- type: string;
90
- path: string;
91
- };
92
- type ProcessedDocumentType = {
93
- name: string;
94
- title?: string;
95
- description?: string;
96
- deprecated?: {
97
- reason: string;
98
- };
99
- liveEdit?: boolean;
100
- titleField: string;
101
- fields: ManifestField[];
102
- outgoingReferences: string[];
103
- incomingReferences: string[];
104
- outgoingReferencePaths?: ReferenceInfo[];
105
- incomingReferencePaths?: ReferenceInfo[];
106
- };
107
- type SchemaTypes = {
108
- documentTypes: Map<string, ProcessedDocumentType>;
109
- objectTypes: Map<string, ManifestSchemaType>;
110
- };
111
- /**
112
- * Filter document types by GROQ expressions or an explicit list.
113
- * - `{ read?, write? }` — GROQ boolean expressions (requires groq-js peer dep).
114
- * Types matching either expression are included (union).
115
- * - `string[]` — explicit list of document type names to include.
116
- * - `undefined` / empty — include all document types.
117
- */
118
- type SchemaFilter = {
119
- read?: string;
120
- write?: string;
121
- } | string[];
122
- type SchemaFieldDisplayOptions = {
123
- showAll?: boolean;
124
- maxCount?: number;
125
- includeDescription?: boolean;
126
- includeHidden?: boolean;
127
- includeDeprecated?: boolean;
128
- maxEnumValues?: number;
129
- maxDescriptionLength?: number;
130
- };
131
- type CompressedSchemaOptions = {
132
- datasetStats?: DatasetStats;
133
- filter?: SchemaFilter;
134
- fields?: SchemaFieldDisplayOptions;
135
- /**
136
- * When `true`, document types with `documentCount === 0` are still rendered
137
- * (and their references fall back to the count-less format, since all edges
138
- * would be zero anyway). Default `false` preserves the existing behavior of
139
- * dropping empty types when `datasetStats` is provided.
140
- */
141
- includeEmpty?: boolean;
142
- };
143
- type SchemaProcessorOptions = {
144
- filter?: SchemaFilter;
145
- fields?: SchemaFieldDisplayOptions;
146
- };
147
3
  type DatasetStatsResult = {
148
4
  status: 'ready';
149
5
  stats: DatasetStats;
@@ -331,5 +187,5 @@ declare function shouldSkipType(typeName: string): boolean;
331
187
  * a pre-resolved `string[]` of document type names.
332
188
  */
333
189
  declare function compressedSchema(types: ManifestSchemaType[], options?: CompressedSchemaOptions): Promise<string>;
334
- export { ARRAY_ITEM_SYSTEM_FIELDS, BUILT_IN_TYPE_FIELDS, type CompressedSchemaOptions, DEFAULT_LINK_ANNOTATION, type DatasetStats, DatasetStatsSchema, type FetchSchemaOptions, type FullSchemaOptions, type ManifestField, type ManifestSchemaType, type ProcessedDocumentType, SCHEMA_CONSTANTS, type SchemaCache, type SchemaFieldDisplayOptions, type SchemaFilter, type SchemaTypes, compressedSchema, fetchDatasetStats, fetchSchemaByDescriptorId, filterToPath, fullSchema, isBuiltInType, isGenericObject, isPrimitiveType, resolveFieldSchema as navigateToFieldSchema, resolveFieldSchema, resolveFieldSchemaAllUnions as navigateToFieldSchemaAllUnions, resolveFieldSchemaAllUnions, processSchema, shouldSkipType, toSchemaPath };
190
+ export { ARRAY_ITEM_SYSTEM_FIELDS, BUILT_IN_TYPE_FIELDS, type CompressedSchemaOptions, DEFAULT_LINK_ANNOTATION, type DatasetStats, DatasetStatsSchema, type FetchSchemaOptions, type FieldSchemaLookupResult, type FullSchemaOptions, type InsertOperation, type LocalizationConfig, type ManifestField, type ManifestSchemaType, type PatchOperations, type ProcessedDocumentType, SCHEMA_CONSTANTS, type SchemaCache, type SchemaFieldDisplayOptions, type SchemaFilter, type SchemaTypes, type ValidateValueFn, type ValidationContext, type ValidationError, type ValidationErrorCode, type ValidationResult, compressedSchema, fetchDatasetStats, fetchSchemaByDescriptorId, filterToPath, fullSchema, isBuiltInType, isGenericObject, isPrimitiveType, resolveFieldSchema as navigateToFieldSchema, resolveFieldSchema, resolveFieldSchemaAllUnions as navigateToFieldSchemaAllUnions, resolveFieldSchemaAllUnions, processSchema, shouldSkipType, toSchemaPath };
335
191
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/fetchDatasetStats.ts","../src/fetchSchemaByDescriptorId.ts","../src/processSchema.ts","../src/navigate/constants.ts","../src/navigate/filterToPath.ts","../src/navigate/navigateAllUnions.ts","../src/navigate/navigateToField.ts","../src/navigate/path.ts","../src/navigate/types.ts","../src/fullSchema.ts","../src/constants.ts","../src/utils.ts","../src/index.ts"],"mappings":";;;KAWK,oBAAA;EAAA,CAIE,CAAA,WAAY,oBAAA;AAAA,IACf,oBAAA;AAAA,KAEQ,kBAAA;EACV,IAA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,MAAA,SAAe,kBAAA;;;;;cA2EpD,uBAAA,EAAyB,kBAAA;;;AJ/DtC;cI2Ea,wBAAA,EAA0B,MAAA,SAAe,kBAAA;;;;;;;;;AJ3EtD;;;;;;iBKgJgB,YAAA,CACd,IAAA,EAAM,kBAAA,EACN,IAAA,UACA,MAAA,EAAQ,kBAAA,KACP,kBAAA;;;;AL7JqC;;iBMAxB,2BAAA,CACd,IAAA,UACA,UAAA,EAAY,kBAAA,EACZ,MAAA,EAAQ,kBAAA,KACP,kBAAA;;;;ANJqC;;;;;iBOiKxB,kBAAA,CACd,IAAA,UACA,UAAA,EAAY,kBAAA,EACZ,MAAA,EAAQ,kBAAA,KACP,kBAAA;;;;;APrKqC;;;;;;;;;iBQIxB,YAAA,CAAa,IAAA;;;;;ARJW;;;iBSExB,eAAA,CACd,QAAA,sBACA,OAAA;EAAW,iBAAA;AAAA;;;;ATKb;iBSQgB,aAAA,CAAc,IAAA;;;;;;;iBA4Bd,eAAA,CAAgB,IAAA;AAAA,KCjDpB,iBAAA;wDAEV,IAAA,UVIG;EUFH,IAAA;EAEA,aAAA;AAAA;AAAA,KAGG,kBAAA;EACH,aAAA;EACA,IAAA;EACA,IAAA;EACA,QAAA,EAAU,KAAA;IAAQ,IAAA;IAAc,IAAA;EAAA;EAChC,IAAA;AAAA;;;;;;;;;;;;iBAcc,UAAA,CACd,MAAA,EAAQ,kBAAA,IACR,OAAA,EAAS,iBAAA,GACR,MAAA,oBAA0B,kBAAA;AAAA,cCpChB,gBAAA;EAAA,wBAkBH,MAAA;EAAA;;;;;;;;;;;;;;iBChBM,cAAA,CAAe,QAAA;;;;;;;;;;iBCoFT,gBAAA,CACpB,KAAA,EAAO,kBAAA,IACP,OAAA,GAAS,uBAAA,GACR,OAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/fetchDatasetStats.ts","../src/fetchSchemaByDescriptorId.ts","../src/processSchema.ts","../src/navigate/constants.ts","../src/navigate/filterToPath.ts","../src/navigate/navigateAllUnions.ts","../src/navigate/navigateToField.ts","../src/navigate/path.ts","../src/navigate/types.ts","../src/fullSchema.ts","../src/constants.ts","../src/utils.ts","../src/index.ts"],"mappings":";;KAGK,kBAAA;EAAuB,MAAA;EAAiB,KAAA,EAAO,YAAA;AAAA;EAAmB,MAAA;AAAA;AAAA,KAElE,wBAAA;EACH,cAAA;EACA,SAAA;EACA,OAAA;AAAA;AAL2E;;;;;;;;;AAAA,iBAiBvD,iBAAA,CACpB,MAAA,EAAQ,YAAA,EACR,OAAA,EAAS,wBAAA,GACR,OAAA,CAAQ,kBAAA;;AAtBmC;;;KCelC,WAAA;EACV,GAAA,GAAM,YAAA,aAAyB,OAAA,CAAQ,eAAA;EACvC,GAAA,GAAM,YAAA,UAAsB,QAAA,EAAU,eAAA,KAAoB,OAAA;AAAA;AAAA,KAmBhD,kBAAA;EDlCiE;;AAAA;;;ECwC3E,KAAA,aAAkB,WAAA,EDrClB;ECuCA,KAAA;AAAA;;;ADzBF;;;;;;;iBCqCsB,yBAAA,CACpB,MAAA,EAAQ,YAAA,EACR,YAAA,UACA,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,kBAAA;;;AD5DmC;;iBEqJ9B,aAAA,CACd,MAAA,EAAQ,kBAAA,IACR,OAAA,GAAU,sBAAA,GACT,WAAA;;;AFxJ2C;;cGKjC,oBAAA,EAAsB,MAAA,SAAe,MAAA,SAAe,kBAAA;;;;;cA2EpD,uBAAA,EAAyB,kBAAA;;;AH9EuC;cG0FhE,wBAAA,EAA0B,MAAA,SAAe,kBAAA;;;;;;;;;AH1FuB;;;;;;iBI+J7D,YAAA,CACd,IAAA,EAAM,kBAAA,EACN,IAAA,UACA,MAAA,EAAQ,kBAAA,KACP,kBAAA;;;AJrK2C;;;iBKQ9B,2BAAA,CACd,IAAA,UACA,UAAA,EAAY,kBAAA,EACZ,MAAA,EAAQ,kBAAA,KACP,kBAAA;;;ALZ2C;;;;;;iBMyK9B,kBAAA,CACd,IAAA,UACA,UAAA,EAAY,kBAAA,EACZ,MAAA,EAAQ,kBAAA,KACP,kBAAA;;;;AN7K2C;;;;;;;;;;iBOY9B,YAAA,CAAa,IAAA;;;;APZiB;;;;iBQU9B,eAAA,CACd,QAAA,sBACA,OAAA;EAAW,iBAAA;AAAA;;;;ARVgE;iBQuB7D,aAAA,CAAc,IAAA;;;;;;;iBA4Bd,eAAA,CAAgB,IAAA;AAAA,KCjDpB,iBAAA;wDAEV,IAAA,UTJqB;ESMrB,IAAA,WTN8D;ESQ9D,aAAA;AAAA;AAAA,KAGG,kBAAA;EACH,aAAA;EACA,IAAA;EACA,IAAA;EACA,QAAA,EAAU,KAAA;IAAQ,IAAA;IAAc,IAAA;EAAA;EAChC,IAAA;AAAA;;;;ATCF;;;;;;;;iBSagB,UAAA,CACd,MAAA,EAAQ,kBAAA,IACR,OAAA,EAAS,iBAAA,GACR,MAAA,oBAA0B,kBAAA;AAAA,cCpChB,gBAAA;EAAA,wBAkBH,MAAA;EAAA;;;;;;;;;;;;;;iBChBM,cAAA,CAAe,QAAA;;;;;;;AXkB/B;;;iBYmFsB,gBAAA,CACpB,KAAA,EAAO,kBAAA,IACP,OAAA,GAAS,uBAAA,GACR,OAAA"}
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { convertToDefinition } from "@sanity/schema-descriptor-utils";
2
+ import { isPrimitiveType, isGenericObject } from "./_chunks-es/navigateToField.js";
3
+ import { ARRAY_ITEM_SYSTEM_FIELDS, BUILT_IN_TYPE_FIELDS, DEFAULT_LINK_ANNOTATION, isBuiltInType, resolveFieldSchema, resolveFieldSchemaAllUnions, resolveFieldSchema as resolveFieldSchema2, resolveFieldSchemaAllUnions as resolveFieldSchemaAllUnions2, toSchemaPath } from "./_chunks-es/navigateToField.js";
2
4
  import { z } from "zod";
3
5
  async function fetchDatasetStats(client, options) {
4
6
  const { organizationId, projectId, dataset } = options, response = await client.request({
@@ -181,86 +183,6 @@ function processSchema(schema, options) {
181
183
  doc.titleField = findTitleField(doc.fields);
182
184
  return { documentTypes, objectTypes };
183
185
  }
184
- const BUILT_IN_TYPE_FIELDS = {
185
- slug: {
186
- current: { name: "current", type: "string" },
187
- _type: { name: "_type", type: "string" }
188
- },
189
- geopoint: {
190
- lat: { name: "lat", type: "number" },
191
- lng: { name: "lng", type: "number" },
192
- alt: { name: "alt", type: "number" },
193
- _type: { name: "_type", type: "string" }
194
- },
195
- reference: {
196
- _ref: { name: "_ref", type: "string" },
197
- _type: { name: "_type", type: "string" },
198
- _weak: { name: "_weak", type: "boolean" }
199
- },
200
- image: {
201
- asset: { name: "asset", type: "reference" },
202
- hotspot: {
203
- name: "hotspot",
204
- type: "object",
205
- fields: [
206
- { name: "x", type: "number" },
207
- { name: "y", type: "number" },
208
- { name: "height", type: "number" },
209
- { name: "width", type: "number" }
210
- ]
211
- },
212
- crop: {
213
- name: "crop",
214
- type: "object",
215
- fields: [
216
- { name: "top", type: "number" },
217
- { name: "bottom", type: "number" },
218
- { name: "left", type: "number" },
219
- { name: "right", type: "number" }
220
- ]
221
- },
222
- _type: { name: "_type", type: "string" }
223
- },
224
- file: {
225
- asset: { name: "asset", type: "reference" },
226
- _type: { name: "_type", type: "string" }
227
- },
228
- block: {
229
- style: { name: "style", type: "string" },
230
- listItem: { name: "listItem", type: "string" },
231
- level: { name: "level", type: "number" },
232
- children: {
233
- name: "children",
234
- type: "array",
235
- of: [{ name: "span", type: "span" }]
236
- },
237
- markDefs: {
238
- name: "markDefs",
239
- type: "array",
240
- of: [{ name: "object", type: "object" }]
241
- },
242
- _type: { name: "_type", type: "string" }
243
- },
244
- span: {
245
- text: { name: "text", type: "string" },
246
- marks: {
247
- name: "marks",
248
- type: "array",
249
- of: [{ name: "string", type: "string" }]
250
- },
251
- _type: { name: "_type", type: "string" }
252
- }
253
- }, DEFAULT_LINK_ANNOTATION = {
254
- name: "link",
255
- type: "object",
256
- fields: [
257
- { name: "href", type: "string" },
258
- { name: "blank", type: "boolean" }
259
- ]
260
- }, ARRAY_ITEM_SYSTEM_FIELDS = {
261
- _key: { name: "_key", type: "string" },
262
- _type: { name: "_type", type: "string" }
263
- };
264
186
  function parseOfIndexSyntax(segment) {
265
187
  const match = segment.match(/^of\[(\d+)\]$/);
266
188
  return match ? parseInt(match[1], 10) : null;
@@ -432,188 +354,6 @@ function filterToPath(type, path, schema) {
432
354
  }
433
355
  return { ...type, fields: [] };
434
356
  }
435
- function toSchemaPath(path) {
436
- return path ? path.replace(/\[append:\d+\]/g, "").replace(/\[_key\s*==\s*["'][^"']*["']\]/g, "").replace(/\[\d+\]/g, "").replace(/\[\]/g, "").replace(/\.{2,}/g, ".").replace(/^\.+|\.+$/g, "") : "";
437
- }
438
- const BASE_PRIMITIVES = ["string", "number", "boolean", "date", "datetime", "text", "url", "email"], BLOCK_TYPES = ["block", "reference"];
439
- function isPrimitiveType(typeName, options = {}) {
440
- return typeName ? options.includeBlockTypes ? BASE_PRIMITIVES.includes(typeName) || BLOCK_TYPES.includes(typeName) : BASE_PRIMITIVES.includes(typeName) : !1;
441
- }
442
- function isBuiltInType(type) {
443
- return BUILT_IN_TYPES.has(type);
444
- }
445
- const BUILT_IN_TYPES = /* @__PURE__ */ new Set([
446
- "string",
447
- "text",
448
- "number",
449
- "boolean",
450
- "array",
451
- "object",
452
- "reference",
453
- "image",
454
- "file",
455
- "date",
456
- "datetime",
457
- "url",
458
- "slug",
459
- "block",
460
- "geopoint"
461
- ]);
462
- function isGenericObject(node) {
463
- if (typeof node != "object" || node === null || Array.isArray(node)) return !1;
464
- const obj = node;
465
- return !obj.fields && !(obj.type === "array" && Array.isArray(obj.of));
466
- }
467
- function resolveFieldSchemaAllUnions(path, typeSchema, schema) {
468
- const pathParts = toSchemaPath(path).split(".").filter(Boolean);
469
- let currentSchemas = [typeSchema];
470
- for (let i = 0; i < pathParts.length; i++) {
471
- const part = pathParts[i], isLastPart = i === pathParts.length - 1, nextSchemas = [];
472
- for (const currentSchema of currentSchemas) {
473
- if (!currentSchema?.fields || !Array.isArray(currentSchema.fields))
474
- continue;
475
- const field = currentSchema.fields.find((f) => f.name === part);
476
- if (field)
477
- if (field.type === "array" && field.of && field.of.length > 0)
478
- for (const itemSchema of field.of) {
479
- const itemType = typeof itemSchema.type == "string" ? itemSchema.type : void 0;
480
- if (isLastPart && (itemType === "image" || itemType === "file"))
481
- nextSchemas.push(itemSchema);
482
- else if (itemType && !isBuiltInType(itemType)) {
483
- const foundSchema = schema.find((s) => s.name === itemType);
484
- foundSchema && nextSchemas.push(foundSchema);
485
- } else itemSchema.fields && nextSchemas.push(itemSchema);
486
- }
487
- else if (field.type && !isBuiltInType(field.type)) {
488
- const foundSchema = schema.find((s) => s.name === field.type);
489
- if (foundSchema)
490
- if (foundSchema.type === "array" && foundSchema.of && foundSchema.of.length > 0)
491
- for (const itemSchema of foundSchema.of) {
492
- const itemType = typeof itemSchema.type == "string" ? itemSchema.type : void 0;
493
- if (isLastPart && (itemType === "image" || itemType === "file"))
494
- nextSchemas.push(itemSchema);
495
- else if (itemType && !isBuiltInType(itemType)) {
496
- const itemFoundSchema = schema.find((s) => s.name === itemType);
497
- itemFoundSchema && nextSchemas.push(itemFoundSchema);
498
- } else itemSchema.fields && nextSchemas.push(itemSchema);
499
- }
500
- else
501
- nextSchemas.push(foundSchema);
502
- } else
503
- nextSchemas.push(field);
504
- }
505
- currentSchemas = nextSchemas;
506
- }
507
- return currentSchemas;
508
- }
509
- function getBuiltInFieldSchema(segment, currentSchema) {
510
- if (!currentSchema?.type || !BUILT_IN_TYPE_FIELDS[currentSchema.type]?.[segment])
511
- return null;
512
- let builtInField = BUILT_IN_TYPE_FIELDS[currentSchema.type][segment];
513
- if (currentSchema.type === "block" && segment === "children" && currentSchema.of && (builtInField = {
514
- ...builtInField,
515
- of: [...builtInField.of || [], ...currentSchema.of]
516
- }), currentSchema.type === "block" && segment === "markDefs") {
517
- const annotations = currentSchema.marks?.annotations;
518
- annotations ? builtInField = {
519
- ...builtInField,
520
- of: [...builtInField.of || [], ...annotations]
521
- } : builtInField = {
522
- ...builtInField,
523
- of: [...builtInField.of || [], DEFAULT_LINK_ANNOTATION]
524
- };
525
- }
526
- return builtInField;
527
- }
528
- function findSchemaInUnionArray(segment, arraySchema, allSchemas, isLastSegment) {
529
- if (!arraySchema.of || arraySchema.of.length === 0)
530
- return { schema: null, earlyReturn: null };
531
- for (const itemSchema of arraySchema.of) {
532
- if (BUILT_IN_TYPE_FIELDS[itemSchema.type]?.[segment]) {
533
- const builtInField = BUILT_IN_TYPE_FIELDS[itemSchema.type][segment];
534
- return isLastSegment ? { schema: null, earlyReturn: builtInField } : { schema: builtInField, earlyReturn: null };
535
- }
536
- if (itemSchema.fields?.some((f) => f.name === segment))
537
- return { schema: itemSchema, earlyReturn: null };
538
- if (itemSchema.type && !isPrimitiveType(itemSchema.type)) {
539
- const referencedSchema2 = allSchemas.find((s) => s.name === itemSchema.type);
540
- if (referencedSchema2?.fields?.some((f) => f.name === segment))
541
- return { schema: referencedSchema2, earlyReturn: null };
542
- }
543
- }
544
- const firstItem = arraySchema.of[0];
545
- if (firstItem.fields)
546
- return { schema: firstItem, earlyReturn: null };
547
- const referencedSchema = allSchemas.find((s) => s.name === firstItem.type);
548
- return referencedSchema?.fields ? { schema: referencedSchema, earlyReturn: null } : { schema: null, earlyReturn: null };
549
- }
550
- function resolveCurrentSchema(segment, currentSchema, allSchemas, isLastSegment) {
551
- if (!currentSchema?.type)
552
- return { schema: null, earlyReturn: null };
553
- if (currentSchema.type === "array" && currentSchema.of && currentSchema.of.length > 0)
554
- return findSchemaInUnionArray(segment, currentSchema, allSchemas, isLastSegment);
555
- const referencedSchema = allSchemas.find((s) => s.name === currentSchema.type);
556
- if (referencedSchema?.fields)
557
- return { schema: referencedSchema, earlyReturn: null };
558
- if (BUILT_IN_TYPE_FIELDS[currentSchema.type]?.[segment]) {
559
- const builtInField = BUILT_IN_TYPE_FIELDS[currentSchema.type][segment];
560
- return isLastSegment ? { schema: null, earlyReturn: builtInField } : { schema: builtInField, earlyReturn: null };
561
- }
562
- return { schema: null, earlyReturn: null };
563
- }
564
- function getNextSchemaForField(field, nextSegment, allSchemas) {
565
- let resolvedField = field;
566
- if (field.type && !isPrimitiveType(field.type) && field.type !== "array") {
567
- const referencedSchema = allSchemas.find((s) => s.name === field.type);
568
- referencedSchema && (resolvedField = referencedSchema);
569
- }
570
- if (resolvedField.type === "array" && resolvedField.of && resolvedField.of.length > 0) {
571
- for (const itemSchema of resolvedField.of) {
572
- if (BUILT_IN_TYPE_FIELDS[itemSchema.type]?.[nextSegment] || itemSchema.fields?.some((f) => f.name === nextSegment))
573
- return itemSchema;
574
- if (itemSchema.type && !isPrimitiveType(itemSchema.type)) {
575
- const refSchema = allSchemas.find((s) => s.name === itemSchema.type);
576
- if (refSchema?.fields?.some((f) => f.name === nextSegment))
577
- return refSchema;
578
- }
579
- }
580
- return resolvedField.of[0];
581
- }
582
- return resolvedField;
583
- }
584
- function resolveFieldSchema(path, typeSchema, schema) {
585
- const segments = toSchemaPath(path).split(".").filter(Boolean);
586
- let currentSchema = typeSchema;
587
- for (let i = 0; i < segments.length; i++) {
588
- const segment = segments[i], isLastSegment = i === segments.length - 1;
589
- if (ARRAY_ITEM_SYSTEM_FIELDS[segment])
590
- return ARRAY_ITEM_SYSTEM_FIELDS[segment];
591
- const builtInField = getBuiltInFieldSchema(segment, currentSchema);
592
- if (builtInField) {
593
- if (isLastSegment) return builtInField;
594
- currentSchema = builtInField;
595
- continue;
596
- }
597
- if (!currentSchema?.fields) {
598
- const resolved = resolveCurrentSchema(segment, currentSchema, schema, isLastSegment);
599
- if (resolved.earlyReturn) return resolved.earlyReturn;
600
- if (!resolved.schema) return null;
601
- currentSchema = resolved.schema;
602
- const resolvedBuiltInField = getBuiltInFieldSchema(segment, currentSchema);
603
- if (resolvedBuiltInField) {
604
- if (isLastSegment) return resolvedBuiltInField;
605
- currentSchema = resolvedBuiltInField;
606
- continue;
607
- }
608
- }
609
- if (!currentSchema?.fields) return null;
610
- const field = currentSchema.fields.find((f) => f.name === segment);
611
- if (!field) return null;
612
- if (isLastSegment) return field;
613
- currentSchema = getNextSchemaForField(field, segments[i + 1], schema);
614
- }
615
- return currentSchema || null;
616
- }
617
357
  function shouldSkipType(typeName) {
618
358
  return SCHEMA_CONSTANTS.SKIP_PATTERNS.test(typeName);
619
359
  }
@@ -950,8 +690,8 @@ export {
950
690
  resolveFieldSchema as navigateToFieldSchema,
951
691
  resolveFieldSchemaAllUnions as navigateToFieldSchemaAllUnions,
952
692
  processSchema,
953
- resolveFieldSchema,
954
- resolveFieldSchemaAllUnions,
693
+ resolveFieldSchema2 as resolveFieldSchema,
694
+ resolveFieldSchemaAllUnions2 as resolveFieldSchemaAllUnions,
955
695
  shouldSkipType,
956
696
  toSchemaPath
957
697
  };