@sanity/agent-schema 0.0.4 → 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,171 +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
- type ManifestSerializable = string | number | boolean | {
4
- [k: string]: ManifestSerializable;
5
- } | ManifestSerializable[];
6
- type ManifestSchemaType = {
7
- type: string;
8
- name: string;
9
- title?: string;
10
- description?: string;
11
- deprecated?: {
12
- reason: string;
13
- };
14
- readOnly?: boolean | 'conditional';
15
- hidden?: boolean | 'conditional';
16
- validation?: ManifestValidationGroup[];
17
- fields?: ManifestField[];
18
- to?: ManifestReferenceMember[];
19
- of?: ManifestArrayMember[];
20
- preview?: {
21
- select: Record<string, string>;
22
- };
23
- fieldsets?: ManifestFieldset[];
24
- options?: Record<string, ManifestSerializable>;
25
- marks?: {
26
- annotations?: ManifestArrayMember[];
27
- decorators?: ManifestTitledValue[];
28
- };
29
- lists?: ManifestTitledValue[];
30
- styles?: ManifestTitledValue[];
31
- [index: string]: unknown;
32
- };
33
- type ManifestFieldset = {
34
- name: string;
35
- title?: string;
36
- [index: string]: ManifestSerializable | undefined;
37
- };
38
- type ManifestTitledValue = {
39
- value: string;
40
- title?: string;
41
- };
42
- type ManifestField = ManifestSchemaType & {
43
- fieldset?: string;
44
- };
45
- type ManifestArrayMember = Omit<ManifestSchemaType, 'name'> & {
46
- name?: string;
47
- };
48
- type ManifestReferenceMember = Omit<ManifestSchemaType, 'name'> & {
49
- name?: string;
50
- };
51
- type ManifestValidationGroup = {
52
- rules: ManifestValidationRule[];
53
- message?: string;
54
- level?: 'error' | 'warning' | 'info';
55
- };
56
- type ManifestValidationRule = {
57
- flag: 'presence' | string;
58
- constraint?: 'required' | ManifestSerializable;
59
- [index: string]: ManifestSerializable | undefined;
60
- };
61
- type HoistedEntry = {
62
- name: string;
63
- typeDef: TypeDef;
64
- groups?: unknown;
65
- fieldset?: unknown;
66
- };
67
- type HoistedMarker = {
68
- __type: 'hoisted';
69
- key: string;
70
- };
71
- type InlineOrHoisted = {
72
- name: string;
73
- typeDef: TypeDef;
74
- } | HoistedMarker;
75
- type LexiconResponse = {
76
- types: Record<string, TypeDef>;
77
- hoisted: Record<string, HoistedEntry>;
78
- registries?: string[];
79
- };
80
- type TypeDef = {
81
- extends: string;
82
- fields?: InlineOrHoisted[];
83
- to?: Array<{
84
- name: string;
85
- }>;
86
- of?: InlineOrHoisted[];
87
- fieldsets?: string[];
88
- validation?: unknown;
89
- [key: string]: unknown;
90
- };
91
- declare const DatasetStatsSchema: z.ZodObject<{
92
- documentCount: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
93
- referenceCount: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
94
- incoming: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodNumber, z.ZodLiteral<"unknown">]>>;
95
- outgoing: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodNumber, z.ZodLiteral<"unknown">]>>;
96
- }, "strip", z.ZodTypeAny, {
97
- incoming: Record<string, number | "unknown">;
98
- outgoing: Record<string, number | "unknown">;
99
- }, {
100
- incoming: Record<string, number | "unknown">;
101
- outgoing: Record<string, number | "unknown">;
102
- }>>>;
103
- }, "strip", z.ZodTypeAny, {
104
- documentCount?: Record<string, number> | undefined;
105
- referenceCount?: Record<string, {
106
- incoming: Record<string, number | "unknown">;
107
- outgoing: Record<string, number | "unknown">;
108
- }> | undefined;
109
- }, {
110
- documentCount?: Record<string, number> | undefined;
111
- referenceCount?: Record<string, {
112
- incoming: Record<string, number | "unknown">;
113
- outgoing: Record<string, number | "unknown">;
114
- }> | undefined;
115
- }>;
116
- type DatasetStats = z.infer<typeof DatasetStatsSchema>;
117
- type ReferenceInfo = {
118
- type: string;
119
- path: string;
120
- };
121
- type ProcessedDocumentType = {
122
- name: string;
123
- title?: string;
124
- description?: string;
125
- deprecated?: {
126
- reason: string;
127
- };
128
- liveEdit?: boolean;
129
- titleField: string;
130
- fields: ManifestField[];
131
- outgoingReferences: string[];
132
- incomingReferences: string[];
133
- outgoingReferencePaths?: ReferenceInfo[];
134
- incomingReferencePaths?: ReferenceInfo[];
135
- };
136
- type SchemaTypes = {
137
- documentTypes: Map<string, ProcessedDocumentType>;
138
- objectTypes: Map<string, ManifestSchemaType>;
139
- };
140
- /**
141
- * Filter document types by GROQ expressions or an explicit list.
142
- * - `{ read?, write? }` — GROQ boolean expressions (requires groq-js peer dep).
143
- * Types matching either expression are included (union).
144
- * - `string[]` — explicit list of document type names to include.
145
- * - `undefined` / empty — include all document types.
146
- */
147
- type SchemaFilter = {
148
- read?: string;
149
- write?: string;
150
- } | string[];
151
- type SchemaFieldDisplayOptions = {
152
- showAll?: boolean;
153
- maxCount?: number;
154
- includeDescription?: boolean;
155
- includeHidden?: boolean;
156
- includeDeprecated?: boolean;
157
- maxEnumValues?: number;
158
- maxDescriptionLength?: number;
159
- };
160
- type CompressedSchemaOptions = {
161
- datasetStats?: DatasetStats;
162
- filter?: SchemaFilter;
163
- fields?: SchemaFieldDisplayOptions;
164
- };
165
- type SchemaProcessorOptions = {
166
- filter?: SchemaFilter;
167
- fields?: SchemaFieldDisplayOptions;
168
- };
169
3
  type DatasetStatsResult = {
170
4
  status: 'ready';
171
5
  stats: DatasetStats;
@@ -353,5 +187,5 @@ declare function shouldSkipType(typeName: string): boolean;
353
187
  * a pre-resolved `string[]` of document type names.
354
188
  */
355
189
  declare function compressedSchema(types: ManifestSchemaType[], options?: CompressedSchemaOptions): Promise<string>;
356
- 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 };
357
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":";;KAMK,oBAAA;EAAA,CAIE,CAAA,WAAY,oBAAA;AAAA,IACf,oBAAA;AAAA,KAEQ,kBAAA;EACV,IAAA;EACA,IAAA;EACA,KAAA;EACA,WAAA;EACA,UAAA;IAAe,MAAA;EAAA;EACf,QAAA;EACA,MAAA;EACA,UAAA,GAAa,uBAAA;EACb,MAAA,GAAS,aAAA;EACT,EAAA,GAAK,uBAAA;EACL,EAAA,GAAK,mBAAA;EACL,OAAA;IAAY,MAAA,EAAQ,MAAA;EAAA;EACpB,SAAA,GAAY,gBAAA;EACZ,OAAA,GAAU,MAAA,SAAe,oBAAA;EAEzB,KAAA;IACE,WAAA,GAAc,mBAAA;IACd,UAAA,GAAa,mBAAA;EAAA;EAEf,KAAA,GAAQ,mBAAA;EACR,MAAA,GAAS,mBAAA;EAAA,CAER,KAAA;AAAA;AAAA,KAGE,gBAAA;EACH,IAAA;EACA,KAAA;EAAA,CACC,KAAA,WAAgB,oBAAA;AAAA;AAAA,KAGd,mBAAA;EACH,KAAA;EACA,KAAA;AAAA;AAAA,KAGU,aAAA,GAAgB,kBAAA;EAAuB,QAAA;AAAA;AAAA,KAE9C,mBAAA,GAAsB,IAAA,CAAK,kBAAA;EAAgC,IAAA;AAAA;AAAA,KAE3D,uBAAA,GAA0B,IAAA,CAAK,kBAAA;EAAgC,IAAA;AAAA;AAAA,KAE/D,uBAAA;EACH,KAAA,EAAO,sBAAA;EACP,OAAA;EACA,KAAA;AAAA;AAAA,KAGG,sBAAA;EACH,IAAA;EACA,UAAA,gBAA0B,oBAAA;EAAA,CACzB,KAAA,WAAgB,oBAAA;AAAA;AAAA,KAOP,YAAA;EACV,IAAA;EACA,OAAA,EAAS,OAAA;EACT,MAAA;EACA,QAAA;AAAA;AAAA,KA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Ab;;iBSagB,aAAA,CAAc,IAAA;;;;;;;iBA4Bd,eAAA,CAAgB,IAAA;AAAA,KCjDpB,iBAAA;wDAEV,IAAA,UVDuB;EUGvB,IAAA,WVEsB;EUAtB,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;;AAA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AA,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,3 +1,6 @@
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";
1
4
  import { z } from "zod";
2
5
  async function fetchDatasetStats(client, options) {
3
6
  const { organizationId, projectId, dataset } = options, response = await client.request({
@@ -5,116 +8,8 @@ async function fetchDatasetStats(client, options) {
5
8
  });
6
9
  return "status" in response && response.status === "processing" ? { status: "processing" } : { status: "ready", stats: response };
7
10
  }
8
- function isHoistedMarker(x) {
9
- if (x === null || typeof x != "object") return !1;
10
- const obj = x;
11
- return obj.__type === "hoisted" && typeof obj.key == "string";
12
- }
13
- function mapperWithHoisting(hoisted, map) {
14
- const cache = /* @__PURE__ */ new Map();
15
- return (entry) => {
16
- if (isHoistedMarker(entry)) {
17
- let result = cache.get(entry.key);
18
- if (!result) {
19
- const value = hoisted[entry.key];
20
- if (!value) throw new Error(`Unknown hoisted key: ${entry.key}`);
21
- result = map(value), cache.set(entry.key, result);
22
- }
23
- return result;
24
- }
25
- return map(entry);
26
- };
27
- }
28
- const STOP = /* @__PURE__ */ Symbol("STOP");
29
- function decodeWithMarkers(x) {
30
- const result = decodeWithMarkersOrStop(x);
31
- if (result !== STOP)
32
- return result;
33
- }
34
- function decodeWithMarkersOrStop(x) {
35
- if (x == null || typeof x != "object") return x;
36
- if (Array.isArray(x)) {
37
- const result2 = [];
38
- for (const item of x) {
39
- const decoded = decodeWithMarkers(item);
40
- if (decoded === STOP) return STOP;
41
- result2.push(decoded);
42
- }
43
- return result2;
44
- }
45
- if ("__type" in x) {
46
- const typed = x;
47
- switch (typed.__type) {
48
- case "function":
49
- case "jsx":
50
- case "unknown":
51
- case "cyclic":
52
- case "maxDepth":
53
- return STOP;
54
- case "number":
55
- return Number(typed.value);
56
- case "undefined":
57
- return;
58
- case "object":
59
- return decodeWithMarkersOrStop(typed.value);
60
- default:
61
- throw new Error(`unknown type: ${typed.__type}`);
62
- }
63
- }
64
- const result = {};
65
- for (const [key, value] of Object.entries(x)) {
66
- const decoded = decodeWithMarkers(value);
67
- result[key] = decoded;
68
- }
69
- return result;
70
- }
71
- function mutableSqueeze(obj) {
72
- for (const [key, value] of Object.entries(obj))
73
- value === void 0 && delete obj[key];
74
- return obj;
75
- }
76
- const STRIP_FIELDS_TYPES = /* @__PURE__ */ new Set([
77
- "block",
78
- "reference",
79
- "globalDocumentReference",
80
- "crossDatasetReference"
81
- ]);
82
- function convertToDefinition(input) {
83
- if (!input?.types || Object.keys(input.types).length === 0)
84
- return [];
85
- const hoisted = input.hoisted ?? {}, convertField = mapperWithHoisting(hoisted, (field) => ({
86
- groups: field.groups,
87
- fieldset: field.fieldset,
88
- ...convertTypeDef(field.name, field.typeDef)
89
- })), convertArrayElement = mapperWithHoisting(
90
- hoisted,
91
- (element) => convertTypeDef(element.name, element.typeDef)
92
- );
93
- function convertTypeDef(name, typeDef) {
94
- const { extends: type, fields, fieldsets, to, of, validation, ...rest } = typeDef;
95
- let marks;
96
- if (type === "block" && fields) {
97
- const markDefsOf = fields.find((f) => isHoistedMarker(f) ? !1 : f.name === "markDefs")?.typeDef?.of;
98
- markDefsOf && markDefsOf.length > 0 && (marks = {
99
- annotations: markDefsOf.map(convertArrayElement)
100
- });
101
- }
102
- return mutableSqueeze({
103
- name,
104
- type,
105
- fields: fields && !STRIP_FIELDS_TYPES.has(type) ? fields.map(convertField) : void 0,
106
- fieldsets: (fieldsets?.length || 0) > 0 ? fieldsets : void 0,
107
- of: of ? of.map(convertArrayElement) : void 0,
108
- to: to?.map(({ name: toName }) => mutableSqueeze({ type: toName })),
109
- validation,
110
- marks,
111
- ...decodeWithMarkers(rest)
112
- });
113
- }
114
- const types = [];
115
- for (const [name, typeDef] of Object.entries(input.types))
116
- types.push(convertTypeDef(name, typeDef));
117
- return types;
11
+ function convert(input) {
12
+ return convertToDefinition(input).types;
118
13
  }
119
14
  const DEFAULT_TTL_MS = 300 * 1e3, memoryCache = /* @__PURE__ */ new Map();
120
15
  function getFromMemoryCache(descriptorId) {
@@ -134,16 +29,16 @@ async function fetchSchemaByDescriptorId(client, descriptorId, options) {
134
29
  const { cache, ttlMs = DEFAULT_TTL_MS } = options ?? {};
135
30
  if (cache === !0) {
136
31
  const hit = getFromMemoryCache(descriptorId);
137
- if (hit) return convertToDefinition(hit);
32
+ if (hit) return convert(hit);
138
33
  } else if (cache) {
139
34
  const hit = await cache.get(descriptorId);
140
- if (hit) return convertToDefinition(hit);
35
+ if (hit) return convert(hit);
141
36
  }
142
37
  const response = await client.request({
143
38
  uri: `/descriptors/schemas/${descriptorId}`
144
39
  });
145
40
  return cache === !0 ? setInMemoryCache(descriptorId, response, ttlMs) : cache && await cache.set(descriptorId, response).catch(() => {
146
- }), convertToDefinition(response);
41
+ }), convert(response);
147
42
  }
148
43
  const SCHEMA_CONSTANTS = {
149
44
  SKIP_PATTERNS: /^(system\.|sanity\.|assist\.|media\.|mux\.)/,
@@ -288,86 +183,6 @@ function processSchema(schema, options) {
288
183
  doc.titleField = findTitleField(doc.fields);
289
184
  return { documentTypes, objectTypes };
290
185
  }
291
- const BUILT_IN_TYPE_FIELDS = {
292
- slug: {
293
- current: { name: "current", type: "string" },
294
- _type: { name: "_type", type: "string" }
295
- },
296
- geopoint: {
297
- lat: { name: "lat", type: "number" },
298
- lng: { name: "lng", type: "number" },
299
- alt: { name: "alt", type: "number" },
300
- _type: { name: "_type", type: "string" }
301
- },
302
- reference: {
303
- _ref: { name: "_ref", type: "string" },
304
- _type: { name: "_type", type: "string" },
305
- _weak: { name: "_weak", type: "boolean" }
306
- },
307
- image: {
308
- asset: { name: "asset", type: "reference" },
309
- hotspot: {
310
- name: "hotspot",
311
- type: "object",
312
- fields: [
313
- { name: "x", type: "number" },
314
- { name: "y", type: "number" },
315
- { name: "height", type: "number" },
316
- { name: "width", type: "number" }
317
- ]
318
- },
319
- crop: {
320
- name: "crop",
321
- type: "object",
322
- fields: [
323
- { name: "top", type: "number" },
324
- { name: "bottom", type: "number" },
325
- { name: "left", type: "number" },
326
- { name: "right", type: "number" }
327
- ]
328
- },
329
- _type: { name: "_type", type: "string" }
330
- },
331
- file: {
332
- asset: { name: "asset", type: "reference" },
333
- _type: { name: "_type", type: "string" }
334
- },
335
- block: {
336
- style: { name: "style", type: "string" },
337
- listItem: { name: "listItem", type: "string" },
338
- level: { name: "level", type: "number" },
339
- children: {
340
- name: "children",
341
- type: "array",
342
- of: [{ name: "span", type: "span" }]
343
- },
344
- markDefs: {
345
- name: "markDefs",
346
- type: "array",
347
- of: [{ name: "object", type: "object" }]
348
- },
349
- _type: { name: "_type", type: "string" }
350
- },
351
- span: {
352
- text: { name: "text", type: "string" },
353
- marks: {
354
- name: "marks",
355
- type: "array",
356
- of: [{ name: "string", type: "string" }]
357
- },
358
- _type: { name: "_type", type: "string" }
359
- }
360
- }, DEFAULT_LINK_ANNOTATION = {
361
- name: "link",
362
- type: "object",
363
- fields: [
364
- { name: "href", type: "string" },
365
- { name: "blank", type: "boolean" }
366
- ]
367
- }, ARRAY_ITEM_SYSTEM_FIELDS = {
368
- _key: { name: "_key", type: "string" },
369
- _type: { name: "_type", type: "string" }
370
- };
371
186
  function parseOfIndexSyntax(segment) {
372
187
  const match = segment.match(/^of\[(\d+)\]$/);
373
188
  return match ? parseInt(match[1], 10) : null;
@@ -539,188 +354,6 @@ function filterToPath(type, path, schema) {
539
354
  }
540
355
  return { ...type, fields: [] };
541
356
  }
542
- function toSchemaPath(path) {
543
- return path ? path.replace(/\[append:\d+\]/g, "").replace(/\[_key\s*==\s*["'][^"']*["']\]/g, "").replace(/\[\d+\]/g, "").replace(/\[\]/g, "").replace(/\.{2,}/g, ".").replace(/^\.+|\.+$/g, "") : "";
544
- }
545
- const BASE_PRIMITIVES = ["string", "number", "boolean", "date", "datetime", "text", "url", "email"], BLOCK_TYPES = ["block", "reference"];
546
- function isPrimitiveType(typeName, options = {}) {
547
- return typeName ? options.includeBlockTypes ? BASE_PRIMITIVES.includes(typeName) || BLOCK_TYPES.includes(typeName) : BASE_PRIMITIVES.includes(typeName) : !1;
548
- }
549
- function isBuiltInType(type) {
550
- return BUILT_IN_TYPES.has(type);
551
- }
552
- const BUILT_IN_TYPES = /* @__PURE__ */ new Set([
553
- "string",
554
- "text",
555
- "number",
556
- "boolean",
557
- "array",
558
- "object",
559
- "reference",
560
- "image",
561
- "file",
562
- "date",
563
- "datetime",
564
- "url",
565
- "slug",
566
- "block",
567
- "geopoint"
568
- ]);
569
- function isGenericObject(node) {
570
- if (typeof node != "object" || node === null || Array.isArray(node)) return !1;
571
- const obj = node;
572
- return !obj.fields && !(obj.type === "array" && Array.isArray(obj.of));
573
- }
574
- function resolveFieldSchemaAllUnions(path, typeSchema, schema) {
575
- const pathParts = toSchemaPath(path).split(".").filter(Boolean);
576
- let currentSchemas = [typeSchema];
577
- for (let i = 0; i < pathParts.length; i++) {
578
- const part = pathParts[i], isLastPart = i === pathParts.length - 1, nextSchemas = [];
579
- for (const currentSchema of currentSchemas) {
580
- if (!currentSchema?.fields || !Array.isArray(currentSchema.fields))
581
- continue;
582
- const field = currentSchema.fields.find((f) => f.name === part);
583
- if (field)
584
- if (field.type === "array" && field.of && field.of.length > 0)
585
- for (const itemSchema of field.of) {
586
- const itemType = typeof itemSchema.type == "string" ? itemSchema.type : void 0;
587
- if (isLastPart && (itemType === "image" || itemType === "file"))
588
- nextSchemas.push(itemSchema);
589
- else if (itemType && !isBuiltInType(itemType)) {
590
- const foundSchema = schema.find((s) => s.name === itemType);
591
- foundSchema && nextSchemas.push(foundSchema);
592
- } else itemSchema.fields && nextSchemas.push(itemSchema);
593
- }
594
- else if (field.type && !isBuiltInType(field.type)) {
595
- const foundSchema = schema.find((s) => s.name === field.type);
596
- if (foundSchema)
597
- if (foundSchema.type === "array" && foundSchema.of && foundSchema.of.length > 0)
598
- for (const itemSchema of foundSchema.of) {
599
- const itemType = typeof itemSchema.type == "string" ? itemSchema.type : void 0;
600
- if (isLastPart && (itemType === "image" || itemType === "file"))
601
- nextSchemas.push(itemSchema);
602
- else if (itemType && !isBuiltInType(itemType)) {
603
- const itemFoundSchema = schema.find((s) => s.name === itemType);
604
- itemFoundSchema && nextSchemas.push(itemFoundSchema);
605
- } else itemSchema.fields && nextSchemas.push(itemSchema);
606
- }
607
- else
608
- nextSchemas.push(foundSchema);
609
- } else
610
- nextSchemas.push(field);
611
- }
612
- currentSchemas = nextSchemas;
613
- }
614
- return currentSchemas;
615
- }
616
- function getBuiltInFieldSchema(segment, currentSchema) {
617
- if (!currentSchema?.type || !BUILT_IN_TYPE_FIELDS[currentSchema.type]?.[segment])
618
- return null;
619
- let builtInField = BUILT_IN_TYPE_FIELDS[currentSchema.type][segment];
620
- if (currentSchema.type === "block" && segment === "children" && currentSchema.of && (builtInField = {
621
- ...builtInField,
622
- of: [...builtInField.of || [], ...currentSchema.of]
623
- }), currentSchema.type === "block" && segment === "markDefs") {
624
- const annotations = currentSchema.marks?.annotations;
625
- annotations ? builtInField = {
626
- ...builtInField,
627
- of: [...builtInField.of || [], ...annotations]
628
- } : builtInField = {
629
- ...builtInField,
630
- of: [...builtInField.of || [], DEFAULT_LINK_ANNOTATION]
631
- };
632
- }
633
- return builtInField;
634
- }
635
- function findSchemaInUnionArray(segment, arraySchema, allSchemas, isLastSegment) {
636
- if (!arraySchema.of || arraySchema.of.length === 0)
637
- return { schema: null, earlyReturn: null };
638
- for (const itemSchema of arraySchema.of) {
639
- if (BUILT_IN_TYPE_FIELDS[itemSchema.type]?.[segment]) {
640
- const builtInField = BUILT_IN_TYPE_FIELDS[itemSchema.type][segment];
641
- return isLastSegment ? { schema: null, earlyReturn: builtInField } : { schema: builtInField, earlyReturn: null };
642
- }
643
- if (itemSchema.fields?.some((f) => f.name === segment))
644
- return { schema: itemSchema, earlyReturn: null };
645
- if (itemSchema.type && !isPrimitiveType(itemSchema.type)) {
646
- const referencedSchema2 = allSchemas.find((s) => s.name === itemSchema.type);
647
- if (referencedSchema2?.fields?.some((f) => f.name === segment))
648
- return { schema: referencedSchema2, earlyReturn: null };
649
- }
650
- }
651
- const firstItem = arraySchema.of[0];
652
- if (firstItem.fields)
653
- return { schema: firstItem, earlyReturn: null };
654
- const referencedSchema = allSchemas.find((s) => s.name === firstItem.type);
655
- return referencedSchema?.fields ? { schema: referencedSchema, earlyReturn: null } : { schema: null, earlyReturn: null };
656
- }
657
- function resolveCurrentSchema(segment, currentSchema, allSchemas, isLastSegment) {
658
- if (!currentSchema?.type)
659
- return { schema: null, earlyReturn: null };
660
- if (currentSchema.type === "array" && currentSchema.of && currentSchema.of.length > 0)
661
- return findSchemaInUnionArray(segment, currentSchema, allSchemas, isLastSegment);
662
- const referencedSchema = allSchemas.find((s) => s.name === currentSchema.type);
663
- if (referencedSchema?.fields)
664
- return { schema: referencedSchema, earlyReturn: null };
665
- if (BUILT_IN_TYPE_FIELDS[currentSchema.type]?.[segment]) {
666
- const builtInField = BUILT_IN_TYPE_FIELDS[currentSchema.type][segment];
667
- return isLastSegment ? { schema: null, earlyReturn: builtInField } : { schema: builtInField, earlyReturn: null };
668
- }
669
- return { schema: null, earlyReturn: null };
670
- }
671
- function getNextSchemaForField(field, nextSegment, allSchemas) {
672
- let resolvedField = field;
673
- if (field.type && !isPrimitiveType(field.type) && field.type !== "array") {
674
- const referencedSchema = allSchemas.find((s) => s.name === field.type);
675
- referencedSchema && (resolvedField = referencedSchema);
676
- }
677
- if (resolvedField.type === "array" && resolvedField.of && resolvedField.of.length > 0) {
678
- for (const itemSchema of resolvedField.of) {
679
- if (BUILT_IN_TYPE_FIELDS[itemSchema.type]?.[nextSegment] || itemSchema.fields?.some((f) => f.name === nextSegment))
680
- return itemSchema;
681
- if (itemSchema.type && !isPrimitiveType(itemSchema.type)) {
682
- const refSchema = allSchemas.find((s) => s.name === itemSchema.type);
683
- if (refSchema?.fields?.some((f) => f.name === nextSegment))
684
- return refSchema;
685
- }
686
- }
687
- return resolvedField.of[0];
688
- }
689
- return resolvedField;
690
- }
691
- function resolveFieldSchema(path, typeSchema, schema) {
692
- const segments = toSchemaPath(path).split(".").filter(Boolean);
693
- let currentSchema = typeSchema;
694
- for (let i = 0; i < segments.length; i++) {
695
- const segment = segments[i], isLastSegment = i === segments.length - 1;
696
- if (ARRAY_ITEM_SYSTEM_FIELDS[segment])
697
- return ARRAY_ITEM_SYSTEM_FIELDS[segment];
698
- const builtInField = getBuiltInFieldSchema(segment, currentSchema);
699
- if (builtInField) {
700
- if (isLastSegment) return builtInField;
701
- currentSchema = builtInField;
702
- continue;
703
- }
704
- if (!currentSchema?.fields) {
705
- const resolved = resolveCurrentSchema(segment, currentSchema, schema, isLastSegment);
706
- if (resolved.earlyReturn) return resolved.earlyReturn;
707
- if (!resolved.schema) return null;
708
- currentSchema = resolved.schema;
709
- const resolvedBuiltInField = getBuiltInFieldSchema(segment, currentSchema);
710
- if (resolvedBuiltInField) {
711
- if (isLastSegment) return resolvedBuiltInField;
712
- currentSchema = resolvedBuiltInField;
713
- continue;
714
- }
715
- }
716
- if (!currentSchema?.fields) return null;
717
- const field = currentSchema.fields.find((f) => f.name === segment);
718
- if (!field) return null;
719
- if (isLastSegment) return field;
720
- currentSchema = getNextSchemaForField(field, segments[i + 1], schema);
721
- }
722
- return currentSchema || null;
723
- }
724
357
  function shouldSkipType(typeName) {
725
358
  return SCHEMA_CONSTANTS.SKIP_PATTERNS.test(typeName);
726
359
  }
@@ -1005,14 +638,14 @@ function formatRefsSimple(doc) {
1005
638
  incoming: doc.incomingReferences.length > 0 ? [...doc.incomingReferences].sort().join(", ") : ""
1006
639
  };
1007
640
  }
1008
- function formatDocEntry(name, doc, objectTypes, fieldOptions, datasetStats) {
641
+ function formatDocEntry(name, doc, objectTypes, fieldOptions, datasetStats, includeEmpty = !1) {
1009
642
  if (shouldSkipType(name)) return null;
1010
- const { documentCount, referenceCount } = datasetStats ?? {}, hasDocumentCounts = !!documentCount, count = documentCount?.[name] ?? 0;
1011
- if (documentCount && documentCount[name] === 0) return null;
643
+ const { documentCount, referenceCount } = datasetStats ?? {}, hasDocumentCounts = !!documentCount, count = documentCount?.[name] ?? 0, isExplicitZero = !!documentCount && documentCount[name] === 0;
644
+ if (isExplicitZero && !includeEmpty) return null;
1012
645
  const useCount = formatDocumentCount(count, hasDocumentCounts);
1013
646
  if (doc.deprecated)
1014
647
  return `- ${name} (DEPRECATED: "${doc.deprecated.reason}", count: ${useCount})`;
1015
- const refs = referenceCount ? formatRefsWithCounts(doc, referenceCount) : formatRefsSimple(doc), depth = calculateMaxDepth(doc.fields, objectTypes), fieldNames = formatFieldNamesWithTypes(doc.fields, fieldOptions), indent = " ", liveEditFlag = doc.liveEdit ? "liveEdit, " : "", parts = [
648
+ const refs = referenceCount && !isExplicitZero ? formatRefsWithCounts(doc, referenceCount) : formatRefsSimple(doc), depth = calculateMaxDepth(doc.fields, objectTypes), fieldNames = formatFieldNamesWithTypes(doc.fields, fieldOptions), indent = " ", liveEditFlag = doc.liveEdit ? "liveEdit, " : "", parts = [
1016
649
  `- ${name} (${liveEditFlag}title: ${doc.titleField}, depth: ${depth}, count: ${useCount})`
1017
650
  ];
1018
651
  if (doc.description) {
@@ -1022,8 +655,10 @@ function formatDocEntry(name, doc, objectTypes, fieldOptions, datasetStats) {
1022
655
  return parts.push(`${indent}- fields: ${fieldNames}`), refs.outgoing && parts.push(`${indent}- references: ${refs.outgoing}`), refs.incoming && parts.push(`${indent}- referenced by: ${refs.incoming}`), parts.join(`
1023
656
  `);
1024
657
  }
1025
- function formatCompressedSchema(documentTypes, objectTypes, fieldOptions, datasetStats) {
1026
- return [...documentTypes.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([name, doc]) => formatDocEntry(name, doc, objectTypes, fieldOptions, datasetStats)).filter(Boolean).join(`
658
+ function formatCompressedSchema(documentTypes, objectTypes, fieldOptions, datasetStats, includeEmpty) {
659
+ return [...documentTypes.entries()].sort(([a], [b]) => a.localeCompare(b)).map(
660
+ ([name, doc]) => formatDocEntry(name, doc, objectTypes, fieldOptions, datasetStats, includeEmpty)
661
+ ).filter(Boolean).join(`
1027
662
  `);
1028
663
  }
1029
664
  async function compressedSchema(types, options = {}) {
@@ -1034,7 +669,8 @@ async function compressedSchema(types, options = {}) {
1034
669
  documentTypes,
1035
670
  objectTypes,
1036
671
  options.fields ?? {},
1037
- options.datasetStats
672
+ options.datasetStats,
673
+ options.includeEmpty
1038
674
  );
1039
675
  }
1040
676
  export {
@@ -1054,8 +690,8 @@ export {
1054
690
  resolveFieldSchema as navigateToFieldSchema,
1055
691
  resolveFieldSchemaAllUnions as navigateToFieldSchemaAllUnions,
1056
692
  processSchema,
1057
- resolveFieldSchema,
1058
- resolveFieldSchemaAllUnions,
693
+ resolveFieldSchema2 as resolveFieldSchema,
694
+ resolveFieldSchemaAllUnions2 as resolveFieldSchemaAllUnions,
1059
695
  shouldSkipType,
1060
696
  toSchemaPath
1061
697
  };