@sanity/agent-schema 0.4.0 → 0.6.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/README.md +0 -4
- package/dist/_chunks-es/walkTree.js +2 -13
- package/dist/_chunks-es/walkTree.js.map +1 -1
- package/dist/index.d.ts +19 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -11
- package/dist/index.js.map +1 -1
- package/dist/validation/index.d.ts.map +1 -1
- package/dist/validation/index.js +34 -6
- package/dist/validation/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -385,10 +385,6 @@ ARRAY_ITEM_SYSTEM_FIELDS._key; // { name: "_key", type: "string" }
|
|
|
385
385
|
ARRAY_ITEM_SYSTEM_FIELDS._type; // { name: "_type", type: "string" }
|
|
386
386
|
```
|
|
387
387
|
|
|
388
|
-
#### `DEFAULT_LINK_ANNOTATION`
|
|
389
|
-
|
|
390
|
-
The default link annotation Sanity adds to Portable Text blocks when no `marks.annotations` are declared.
|
|
391
|
-
|
|
392
388
|
#### `SCHEMA_CONSTANTS`
|
|
393
389
|
|
|
394
390
|
Internal constants used by the schema processor (skip patterns, title field candidates, default limits). Exported for consumers that need to extend the defaults.
|
|
@@ -67,13 +67,6 @@ const BUILT_IN_TYPE_FIELDS = {
|
|
|
67
67
|
},
|
|
68
68
|
_type: { name: "_type", type: "string" }
|
|
69
69
|
}
|
|
70
|
-
}, DEFAULT_LINK_ANNOTATION = {
|
|
71
|
-
name: "link",
|
|
72
|
-
type: "object",
|
|
73
|
-
fields: [
|
|
74
|
-
{ name: "href", type: "string" },
|
|
75
|
-
{ name: "blank", type: "boolean" }
|
|
76
|
-
]
|
|
77
70
|
}, ARRAY_ITEM_SYSTEM_FIELDS = {
|
|
78
71
|
_key: { name: "_key", type: "string" },
|
|
79
72
|
_type: { name: "_type", type: "string" }
|
|
@@ -161,12 +154,9 @@ function getBuiltInFieldSchema(segment, currentSchema) {
|
|
|
161
154
|
of: [...builtInField.of || [], ...currentSchema.of]
|
|
162
155
|
}), currentSchema.type === "block" && segment === "markDefs") {
|
|
163
156
|
const annotations = currentSchema.marks?.annotations;
|
|
164
|
-
|
|
157
|
+
builtInField = {
|
|
165
158
|
...builtInField,
|
|
166
|
-
of: [...builtInField.of || [], ...annotations]
|
|
167
|
-
} : builtInField = {
|
|
168
|
-
...builtInField,
|
|
169
|
-
of: [...builtInField.of || [], DEFAULT_LINK_ANNOTATION]
|
|
159
|
+
of: [...builtInField.of || [], ...annotations || []]
|
|
170
160
|
};
|
|
171
161
|
}
|
|
172
162
|
return builtInField;
|
|
@@ -299,7 +289,6 @@ function walkSchemaTree(documentType, schema, visit) {
|
|
|
299
289
|
export {
|
|
300
290
|
ARRAY_ITEM_SYSTEM_FIELDS,
|
|
301
291
|
BUILT_IN_TYPE_FIELDS,
|
|
302
|
-
DEFAULT_LINK_ANNOTATION,
|
|
303
292
|
isBuiltInType,
|
|
304
293
|
isGenericObject,
|
|
305
294
|
isPrimitiveType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walkTree.js","sources":["../../src/navigate/constants.ts","../../src/navigate/path.ts","../../src/navigate/types.ts","../../src/navigate/navigateAllUnions.ts","../../src/navigate/navigateToField.ts","../../src/navigate/walkTree.ts"],"sourcesContent":["import type { ManifestSchemaType } from '../types.js'\n\n/**\n * Built-in Sanity type fields that exist implicitly (not in schema).\n * Maps type name to field definitions.\n */\nexport const BUILT_IN_TYPE_FIELDS: Record<string, Record<string, ManifestSchemaType>> = {\n slug: {\n current: { name: 'current', type: 'string' } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n geopoint: {\n lat: { name: 'lat', type: 'number' } as ManifestSchemaType,\n lng: { name: 'lng', type: 'number' } as ManifestSchemaType,\n alt: { name: 'alt', type: 'number' } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n reference: {\n _ref: { name: '_ref', type: 'string' } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n _weak: { name: '_weak', type: 'boolean' } as ManifestSchemaType,\n },\n image: {\n asset: { name: 'asset', type: 'reference' } as ManifestSchemaType,\n hotspot: {\n name: 'hotspot',\n type: 'object',\n fields: [\n { name: 'x', type: 'number' },\n { name: 'y', type: 'number' },\n { name: 'height', type: 'number' },\n { name: 'width', type: 'number' },\n ],\n } as ManifestSchemaType,\n crop: {\n name: 'crop',\n type: 'object',\n fields: [\n { name: 'top', type: 'number' },\n { name: 'bottom', type: 'number' },\n { name: 'left', type: 'number' },\n { name: 'right', type: 'number' },\n ],\n } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n file: {\n asset: { name: 'asset', type: 'reference' } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n block: {\n style: { name: 'style', type: 'string' } as ManifestSchemaType,\n listItem: { name: 'listItem', type: 'string' } as ManifestSchemaType,\n level: { name: 'level', type: 'number' } as ManifestSchemaType,\n children: {\n name: 'children',\n type: 'array',\n of: [{ name: 'span', type: 'span' }],\n } as ManifestSchemaType,\n markDefs: {\n name: 'markDefs',\n type: 'array',\n of: [{ name: 'object', type: 'object' }],\n } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n span: {\n text: { name: 'text', type: 'string' } as ManifestSchemaType,\n marks: {\n name: 'marks',\n type: 'array',\n of: [{ name: 'string', type: 'string' }],\n } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n}\n\n/**\n * Default annotation type for Portable Text blocks.\n * Sanity implicitly includes \"link\" when no marks.annotations are declared.\n */\nexport const DEFAULT_LINK_ANNOTATION: ManifestSchemaType = {\n name: 'link',\n type: 'object',\n fields: [\n { name: 'href', type: 'string' },\n { name: 'blank', type: 'boolean' },\n ],\n} as ManifestSchemaType\n\n/**\n * System fields that exist on all array items.\n */\nexport const ARRAY_ITEM_SYSTEM_FIELDS: Record<string, ManifestSchemaType> = {\n _key: { name: '_key', type: 'string' } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n}\n","/**\n * Convert a document path string to a schema path string.\n * Strips array indices, _key selectors, and internal markers.\n *\n * Examples:\n * - `\"content[_key==\\\"abc\\\"].children[0].text\"` → `\"content.children.text\"`\n * - `\"tags[0]\"` → `\"tags\"`\n * - `\"seo.image.asset\"` → `\"seo.image.asset\"`\n * - `\"items[append:3]\"` → `\"items\"`\n *\n * This is a self-contained implementation that avoids depending on\n * `@sanity/types` for path segment parsing.\n */\nexport function toSchemaPath(path: string): string {\n if (!path) return ''\n\n return (\n path\n // Strip internal markers: [append:N]\n .replace(/\\[append:\\d+\\]/g, '')\n // Strip _key selectors: [_key==\"value\"] or [_key=='value']\n .replace(/\\[_key\\s*==\\s*[\"'][^\"']*[\"']\\]/g, '')\n // Strip numeric indices: [0], [123]\n .replace(/\\[\\d+\\]/g, '')\n // Strip empty brackets: []\n .replace(/\\[\\]/g, '')\n // Collapse any resulting double dots\n .replace(/\\.{2,}/g, '.')\n // Trim leading/trailing dots\n .replace(/^\\.+|\\.+$/g, '')\n )\n}\n","const BASE_PRIMITIVES = ['string', 'number', 'boolean', 'date', 'datetime', 'text', 'url', 'email']\n\nconst BLOCK_TYPES = ['block', 'reference']\n\n/**\n * Check if a type name represents a primitive type.\n *\n * When `includeBlockTypes` is true, 'block' and 'reference' are also\n * considered primitive (useful for navigator/large-node detection where\n * you don't want to drill into these).\n */\nexport function isPrimitiveType(\n typeName: string | undefined,\n options: { includeBlockTypes?: boolean } = {},\n): boolean {\n if (!typeName) return false\n if (options.includeBlockTypes) {\n return BASE_PRIMITIVES.includes(typeName) || BLOCK_TYPES.includes(typeName)\n }\n return BASE_PRIMITIVES.includes(typeName)\n}\n\n/**\n * Check if a type is a built-in Sanity type (superset of primitives).\n * Includes complex built-in types like array, object, image, file, slug, etc.\n */\nexport function isBuiltInType(type: string): boolean {\n return BUILT_IN_TYPES.has(type)\n}\n\nconst BUILT_IN_TYPES = new Set([\n 'string',\n 'text',\n 'number',\n 'boolean',\n 'array',\n 'object',\n 'reference',\n 'image',\n 'file',\n 'date',\n 'datetime',\n 'url',\n 'slug',\n 'block',\n 'geopoint',\n])\n\n/**\n * Check if a node is a generic object-like node.\n * Generic objects are objects that don't have a `fields` array and\n * aren't array types with `of`. These include block types and other\n * object-shaped schemas with properties like marks, lists, styles, etc.\n */\nexport function isGenericObject(node: unknown): boolean {\n if (typeof node !== 'object' || node === null || Array.isArray(node)) return false\n const obj = node as Record<string, unknown>\n return !obj.fields && !(obj.type === 'array' && Array.isArray(obj.of))\n}\n","import type { ManifestSchemaType } from '../types.js'\nimport { toSchemaPath } from './path.js'\nimport { isBuiltInType } from './types.js'\n\n/**\n * Resolves a document path to field schemas, returning ALL possible schemas for union types.\n * This is important for arrays with multiple `of` types where a field might exist\n * in some but not all union types.\n */\nexport function resolveFieldSchemaAllUnions(\n path: string,\n typeSchema: ManifestSchemaType,\n schema: ManifestSchemaType[],\n): ManifestSchemaType[] {\n const pathParts = toSchemaPath(path).split('.').filter(Boolean)\n\n let currentSchemas: ManifestSchemaType[] = [typeSchema]\n\n for (let i = 0; i < pathParts.length; i++) {\n const part = pathParts[i]\n const isLastPart = i === pathParts.length - 1\n const nextSchemas: ManifestSchemaType[] = []\n\n for (const currentSchema of currentSchemas) {\n if (!currentSchema?.fields || !Array.isArray(currentSchema.fields)) {\n continue\n }\n\n const field = currentSchema.fields.find((f) => f.name === part)\n if (!field) continue\n\n if (field.type === 'array' && field.of && field.of.length > 0) {\n for (const itemSchema of field.of) {\n const itemType = typeof itemSchema.type === 'string' ? itemSchema.type : undefined\n if (isLastPart && (itemType === 'image' || itemType === 'file')) {\n nextSchemas.push(itemSchema as ManifestSchemaType)\n } else if (itemType && !isBuiltInType(itemType)) {\n const foundSchema = schema.find((s) => s.name === itemType)\n if (foundSchema) nextSchemas.push(foundSchema)\n } else if ((itemSchema as ManifestSchemaType).fields) {\n nextSchemas.push(itemSchema as ManifestSchemaType)\n }\n }\n } else if (field.type && !isBuiltInType(field.type)) {\n const foundSchema = schema.find((s) => s.name === field.type)\n if (foundSchema) {\n if (foundSchema.type === 'array' && foundSchema.of && foundSchema.of.length > 0) {\n for (const itemSchema of foundSchema.of) {\n const itemType = typeof itemSchema.type === 'string' ? itemSchema.type : undefined\n if (isLastPart && (itemType === 'image' || itemType === 'file')) {\n nextSchemas.push(itemSchema as ManifestSchemaType)\n } else if (itemType && !isBuiltInType(itemType)) {\n const itemFoundSchema = schema.find((s) => s.name === itemType)\n if (itemFoundSchema) nextSchemas.push(itemFoundSchema)\n } else if ((itemSchema as ManifestSchemaType).fields) {\n nextSchemas.push(itemSchema as ManifestSchemaType)\n }\n }\n } else {\n nextSchemas.push(foundSchema)\n }\n }\n } else {\n nextSchemas.push(field as ManifestSchemaType)\n }\n }\n\n currentSchemas = nextSchemas\n }\n\n return currentSchemas\n}\n","import type { ManifestField, ManifestSchemaType } from '../types.js'\nimport {\n ARRAY_ITEM_SYSTEM_FIELDS,\n BUILT_IN_TYPE_FIELDS,\n DEFAULT_LINK_ANNOTATION,\n} from './constants.js'\nimport { toSchemaPath } from './path.js'\nimport { isPrimitiveType } from './types.js'\n\ninterface SchemaResolutionResult {\n schema: ManifestSchemaType | null\n earlyReturn: ManifestSchemaType | null\n}\n\nfunction getBuiltInFieldSchema(\n segment: string,\n currentSchema: ManifestSchemaType,\n): ManifestSchemaType | null {\n if (!currentSchema?.type || !BUILT_IN_TYPE_FIELDS[currentSchema.type]?.[segment]) {\n return null\n }\n\n let builtInField: ManifestSchemaType = BUILT_IN_TYPE_FIELDS[currentSchema.type][segment]\n\n // For block.children, merge in block.of (inline objects) from the schema\n if (currentSchema.type === 'block' && segment === 'children' && currentSchema.of) {\n builtInField = {\n ...builtInField,\n of: [...(builtInField.of || []), ...(currentSchema.of as ManifestSchemaType[])],\n }\n }\n\n // For block.markDefs, merge in block.marks.annotations from the schema\n // If no annotations are declared, add default \"link\" annotation (Sanity built-in)\n if (currentSchema.type === 'block' && segment === 'markDefs') {\n const annotations = (\n currentSchema as ManifestSchemaType & { marks?: { annotations?: ManifestSchemaType[] } }\n ).marks?.annotations\n if (annotations) {\n builtInField = {\n ...builtInField,\n of: [...(builtInField.of || []), ...annotations],\n }\n } else {\n builtInField = {\n ...builtInField,\n of: [...(builtInField.of || []), DEFAULT_LINK_ANNOTATION],\n }\n }\n }\n\n return builtInField\n}\n\nfunction findSchemaInUnionArray(\n segment: string,\n arraySchema: ManifestSchemaType,\n allSchemas: ManifestSchemaType[],\n isLastSegment: boolean,\n): SchemaResolutionResult {\n if (!arraySchema.of || arraySchema.of.length === 0) {\n return { schema: null, earlyReturn: null }\n }\n\n for (const itemSchema of arraySchema.of as ManifestSchemaType[]) {\n if (BUILT_IN_TYPE_FIELDS[itemSchema.type]?.[segment]) {\n const builtInField = BUILT_IN_TYPE_FIELDS[itemSchema.type][segment]\n if (isLastSegment) {\n return { schema: null, earlyReturn: builtInField }\n }\n return { schema: builtInField, earlyReturn: null }\n }\n\n if (itemSchema.fields?.some((f) => f.name === segment)) {\n return { schema: itemSchema, earlyReturn: null }\n }\n\n if (itemSchema.type && !isPrimitiveType(itemSchema.type)) {\n const referencedSchema = allSchemas.find((s) => s.name === itemSchema.type)\n if (referencedSchema?.fields?.some((f) => f.name === segment)) {\n return { schema: referencedSchema, earlyReturn: null }\n }\n }\n }\n\n const firstItem = arraySchema.of[0] as ManifestSchemaType\n if (firstItem.fields) {\n return { schema: firstItem, earlyReturn: null }\n }\n\n const referencedSchema = allSchemas.find((s) => s.name === firstItem.type)\n if (referencedSchema?.fields) {\n return { schema: referencedSchema, earlyReturn: null }\n }\n\n return { schema: null, earlyReturn: null }\n}\n\nfunction resolveCurrentSchema(\n segment: string,\n currentSchema: ManifestSchemaType,\n allSchemas: ManifestSchemaType[],\n isLastSegment: boolean,\n): SchemaResolutionResult {\n if (!currentSchema?.type) {\n return { schema: null, earlyReturn: null }\n }\n\n if (currentSchema.type === 'array' && currentSchema.of && currentSchema.of.length > 0) {\n return findSchemaInUnionArray(segment, currentSchema, allSchemas, isLastSegment)\n }\n\n const referencedSchema = allSchemas.find((s) => s.name === currentSchema.type)\n if (referencedSchema?.fields) {\n return { schema: referencedSchema, earlyReturn: null }\n }\n\n if (BUILT_IN_TYPE_FIELDS[currentSchema.type]?.[segment]) {\n const builtInField = BUILT_IN_TYPE_FIELDS[currentSchema.type][segment]\n if (isLastSegment) {\n return { schema: null, earlyReturn: builtInField }\n }\n return { schema: builtInField, earlyReturn: null }\n }\n\n return { schema: null, earlyReturn: null }\n}\n\nfunction getNextSchemaForField(\n field: ManifestField,\n nextSegment: string,\n allSchemas: ManifestSchemaType[],\n): ManifestSchemaType {\n let resolvedField: ManifestSchemaType = field as ManifestSchemaType\n if (field.type && !isPrimitiveType(field.type) && field.type !== 'array') {\n const referencedSchema = allSchemas.find((s) => s.name === field.type)\n if (referencedSchema) {\n resolvedField = referencedSchema\n }\n }\n\n if (resolvedField.type === 'array' && resolvedField.of && resolvedField.of.length > 0) {\n for (const itemSchema of resolvedField.of as ManifestSchemaType[]) {\n if (BUILT_IN_TYPE_FIELDS[itemSchema.type]?.[nextSegment]) {\n return itemSchema\n }\n if (itemSchema.fields?.some((f) => f.name === nextSegment)) {\n return itemSchema\n }\n if (itemSchema.type && !isPrimitiveType(itemSchema.type)) {\n const refSchema = allSchemas.find((s) => s.name === itemSchema.type)\n if (refSchema?.fields?.some((f) => f.name === nextSegment)) {\n return refSchema\n }\n }\n }\n return resolvedField.of[0] as ManifestSchemaType\n }\n\n return resolvedField\n}\n\n/**\n * Resolves a document path to the field schema at that location.\n * Handles nested paths like \"author.name\" and array paths like \"tags[0]\".\n *\n * Returns the field schema at the path, NOT navigating into arrays.\n * For \"tags\" (an array field), returns the array field schema (with 'of').\n * For \"tags[0].foo\", returns the \"foo\" field from the array item schema.\n */\nexport function resolveFieldSchema(\n path: string,\n typeSchema: ManifestSchemaType,\n schema: ManifestSchemaType[],\n): ManifestSchemaType | null {\n const segments = toSchemaPath(path).split('.').filter(Boolean)\n\n let currentSchema: ManifestSchemaType | undefined = typeSchema\n\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i]\n const isLastSegment = i === segments.length - 1\n\n if (ARRAY_ITEM_SYSTEM_FIELDS[segment]) {\n return ARRAY_ITEM_SYSTEM_FIELDS[segment]\n }\n\n const builtInField = getBuiltInFieldSchema(segment, currentSchema!)\n if (builtInField) {\n if (isLastSegment) return builtInField\n currentSchema = builtInField\n continue\n }\n\n if (!currentSchema?.fields) {\n const resolved = resolveCurrentSchema(segment, currentSchema!, schema, isLastSegment)\n if (resolved.earlyReturn) return resolved.earlyReturn\n if (!resolved.schema) return null\n currentSchema = resolved.schema\n\n const resolvedBuiltInField = getBuiltInFieldSchema(segment, currentSchema)\n if (resolvedBuiltInField) {\n if (isLastSegment) return resolvedBuiltInField\n currentSchema = resolvedBuiltInField\n continue\n }\n }\n\n if (!currentSchema?.fields) return null\n\n const field = currentSchema.fields.find((f) => f.name === segment)\n if (!field) return null\n if (isLastSegment) return field\n\n currentSchema = getNextSchemaForField(field, segments[i + 1], schema)\n }\n\n return currentSchema || null\n}\n","/**\n * Whole-tree schema walker.\n *\n * Where `navigateToField` and `navigateAllUnions` resolve a single path string\n * to its field schema, this walks every reachable field in a document type.\n * Used by validators that need to inspect the full schema graph (required\n * fields, custom validators).\n *\n * Handles:\n * - Inline objects (`field.fields`)\n * - Aliased object types (looked up in the schema array)\n * - Arrays of objects (`field.of` items recursed with the same logic)\n *\n * Cycles are guarded by tracking visited type names. Built-in primitive types\n * are skipped: there's nothing to walk into.\n */\n\nimport type { ManifestField, ManifestSchemaType } from '../types.js'\nimport { isPrimitiveType } from './types.js'\n\nexport type WalkVisitor = (field: ManifestField, path: string) => void\n\nexport const joinSchemaPath = (parent: string, child: string): string =>\n parent ? `${parent}.${child}` : child\n\nconst findReferencedType = (\n field: ManifestField,\n schema: ManifestSchemaType[],\n): ManifestSchemaType | undefined => {\n if (isPrimitiveType(field.type)) return undefined\n return schema.find((s) => s.name === field.type)\n}\n\nfunction walkArrayItems(\n field: ManifestField,\n path: string,\n schema: ManifestSchemaType[],\n visited: Set<string>,\n visit: WalkVisitor,\n): void {\n if (!field.of?.length) return\n\n for (const rawItem of field.of) {\n const item = rawItem as ManifestSchemaType\n // Inline object items in `of` carry their own fields; aliased items just\n // reference a type by name and need a schema lookup.\n if (item.fields?.length) {\n walkFields(item.fields, path, schema, visited, visit)\n continue\n }\n if (!item.type || isPrimitiveType(item.type)) continue\n const referenced = schema.find((s) => s.name === item.type)\n if (!referenced || visited.has(referenced.name)) continue\n if (referenced.fields?.length) {\n visited.add(referenced.name)\n walkFields(referenced.fields, path, schema, visited, visit)\n }\n }\n}\n\nfunction walkFields(\n fields: ManifestField[],\n path: string,\n schema: ManifestSchemaType[],\n visited: Set<string>,\n visit: WalkVisitor,\n): void {\n for (const field of fields) {\n const fieldPath = joinSchemaPath(path, field.name)\n visit(field, fieldPath)\n\n if (field.fields?.length) {\n walkFields(field.fields, fieldPath, schema, visited, visit)\n continue\n }\n\n if (field.of?.length) {\n walkArrayItems(field, fieldPath, schema, visited, visit)\n continue\n }\n\n const referenced = findReferencedType(field, schema)\n if (!referenced?.fields?.length) continue\n if (visited.has(referenced.name)) continue\n\n visited.add(referenced.name)\n walkFields(referenced.fields, fieldPath, schema, visited, visit)\n }\n}\n\n/**\n * Visit every field reachable from a document type. The visitor is called once\n * per field with the field schema and its dotted path from the document root.\n */\nexport function walkSchemaTree(\n documentType: string,\n schema: ManifestSchemaType[],\n visit: WalkVisitor,\n): void {\n const typeSchema = schema.find((s) => s.name === documentType)\n if (!typeSchema?.fields?.length) return\n\n walkFields(typeSchema.fields, '', schema, new Set([typeSchema.name]), visit)\n}\n"],"names":["referencedSchema"],"mappings":"AAMO,MAAM,uBAA2E;AAAA,EACtF,MAAM;AAAA,IACJ,SAAS,EAAE,MAAM,WAAW,MAAM,SAAA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,IAAI,WAAW,IAAI,GAC3B,WAAW,WAAW,QAAQ,WAAW,QAAQ,SAAS,KAAK;AAAA,EACjE;AACF;AAMO,SAAS,eACd,cACA,QACA,OACM;AACN,QAAM,aAAa,OAAO,KAAK,CAAC,MAAM,EAAE,SAAS,YAAY;AACxD,cAAY,QAAQ,UAEzB,WAAW,WAAW,QAAQ,IAAI,QAAQ,oBAAI,IAAI,CAAC,WAAW,IAAI,CAAC,GAAG,KAAK;AAC7E;"}
|
|
1
|
+
{"version":3,"file":"walkTree.js","sources":["../../src/navigate/constants.ts","../../src/navigate/path.ts","../../src/navigate/types.ts","../../src/navigate/navigateAllUnions.ts","../../src/navigate/navigateToField.ts","../../src/navigate/walkTree.ts"],"sourcesContent":["import type { ManifestSchemaType } from '../types.js'\n\n/**\n * Built-in Sanity type fields that exist implicitly (not in schema).\n * Maps type name to field definitions.\n */\nexport const BUILT_IN_TYPE_FIELDS: Record<string, Record<string, ManifestSchemaType>> = {\n slug: {\n current: { name: 'current', type: 'string' } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n geopoint: {\n lat: { name: 'lat', type: 'number' } as ManifestSchemaType,\n lng: { name: 'lng', type: 'number' } as ManifestSchemaType,\n alt: { name: 'alt', type: 'number' } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n reference: {\n _ref: { name: '_ref', type: 'string' } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n _weak: { name: '_weak', type: 'boolean' } as ManifestSchemaType,\n },\n image: {\n asset: { name: 'asset', type: 'reference' } as ManifestSchemaType,\n hotspot: {\n name: 'hotspot',\n type: 'object',\n fields: [\n { name: 'x', type: 'number' },\n { name: 'y', type: 'number' },\n { name: 'height', type: 'number' },\n { name: 'width', type: 'number' },\n ],\n } as ManifestSchemaType,\n crop: {\n name: 'crop',\n type: 'object',\n fields: [\n { name: 'top', type: 'number' },\n { name: 'bottom', type: 'number' },\n { name: 'left', type: 'number' },\n { name: 'right', type: 'number' },\n ],\n } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n file: {\n asset: { name: 'asset', type: 'reference' } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n block: {\n style: { name: 'style', type: 'string' } as ManifestSchemaType,\n listItem: { name: 'listItem', type: 'string' } as ManifestSchemaType,\n level: { name: 'level', type: 'number' } as ManifestSchemaType,\n children: {\n name: 'children',\n type: 'array',\n of: [{ name: 'span', type: 'span' }],\n } as ManifestSchemaType,\n markDefs: {\n name: 'markDefs',\n type: 'array',\n of: [{ name: 'object', type: 'object' }],\n } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n span: {\n text: { name: 'text', type: 'string' } as ManifestSchemaType,\n marks: {\n name: 'marks',\n type: 'array',\n of: [{ name: 'string', type: 'string' }],\n } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n },\n}\n\n/**\n * System fields that exist on all array items.\n */\nexport const ARRAY_ITEM_SYSTEM_FIELDS: Record<string, ManifestSchemaType> = {\n _key: { name: '_key', type: 'string' } as ManifestSchemaType,\n _type: { name: '_type', type: 'string' } as ManifestSchemaType,\n}\n","/**\n * Convert a document path string to a schema path string.\n * Strips array indices, _key selectors, and internal markers.\n *\n * Examples:\n * - `\"content[_key==\\\"abc\\\"].children[0].text\"` → `\"content.children.text\"`\n * - `\"tags[0]\"` → `\"tags\"`\n * - `\"seo.image.asset\"` → `\"seo.image.asset\"`\n * - `\"items[append:3]\"` → `\"items\"`\n *\n * This is a self-contained implementation that avoids depending on\n * `@sanity/types` for path segment parsing.\n */\nexport function toSchemaPath(path: string): string {\n if (!path) return ''\n\n return (\n path\n // Strip internal markers: [append:N]\n .replace(/\\[append:\\d+\\]/g, '')\n // Strip _key selectors: [_key==\"value\"] or [_key=='value']\n .replace(/\\[_key\\s*==\\s*[\"'][^\"']*[\"']\\]/g, '')\n // Strip numeric indices: [0], [123]\n .replace(/\\[\\d+\\]/g, '')\n // Strip empty brackets: []\n .replace(/\\[\\]/g, '')\n // Collapse any resulting double dots\n .replace(/\\.{2,}/g, '.')\n // Trim leading/trailing dots\n .replace(/^\\.+|\\.+$/g, '')\n )\n}\n","const BASE_PRIMITIVES = ['string', 'number', 'boolean', 'date', 'datetime', 'text', 'url', 'email']\n\nconst BLOCK_TYPES = ['block', 'reference']\n\n/**\n * Check if a type name represents a primitive type.\n *\n * When `includeBlockTypes` is true, 'block' and 'reference' are also\n * considered primitive (useful for navigator/large-node detection where\n * you don't want to drill into these).\n */\nexport function isPrimitiveType(\n typeName: string | undefined,\n options: { includeBlockTypes?: boolean } = {},\n): boolean {\n if (!typeName) return false\n if (options.includeBlockTypes) {\n return BASE_PRIMITIVES.includes(typeName) || BLOCK_TYPES.includes(typeName)\n }\n return BASE_PRIMITIVES.includes(typeName)\n}\n\n/**\n * Check if a type is a built-in Sanity type (superset of primitives).\n * Includes complex built-in types like array, object, image, file, slug, etc.\n */\nexport function isBuiltInType(type: string): boolean {\n return BUILT_IN_TYPES.has(type)\n}\n\nconst BUILT_IN_TYPES = new Set([\n 'string',\n 'text',\n 'number',\n 'boolean',\n 'array',\n 'object',\n 'reference',\n 'image',\n 'file',\n 'date',\n 'datetime',\n 'url',\n 'slug',\n 'block',\n 'geopoint',\n])\n\n/**\n * Check if a node is a generic object-like node.\n * Generic objects are objects that don't have a `fields` array and\n * aren't array types with `of`. These include block types and other\n * object-shaped schemas with properties like marks, lists, styles, etc.\n */\nexport function isGenericObject(node: unknown): boolean {\n if (typeof node !== 'object' || node === null || Array.isArray(node)) return false\n const obj = node as Record<string, unknown>\n return !obj.fields && !(obj.type === 'array' && Array.isArray(obj.of))\n}\n","import type { ManifestSchemaType } from '../types.js'\nimport { toSchemaPath } from './path.js'\nimport { isBuiltInType } from './types.js'\n\n/**\n * Resolves a document path to field schemas, returning ALL possible schemas for union types.\n * This is important for arrays with multiple `of` types where a field might exist\n * in some but not all union types.\n */\nexport function resolveFieldSchemaAllUnions(\n path: string,\n typeSchema: ManifestSchemaType,\n schema: ManifestSchemaType[],\n): ManifestSchemaType[] {\n const pathParts = toSchemaPath(path).split('.').filter(Boolean)\n\n let currentSchemas: ManifestSchemaType[] = [typeSchema]\n\n for (let i = 0; i < pathParts.length; i++) {\n const part = pathParts[i]\n const isLastPart = i === pathParts.length - 1\n const nextSchemas: ManifestSchemaType[] = []\n\n for (const currentSchema of currentSchemas) {\n if (!currentSchema?.fields || !Array.isArray(currentSchema.fields)) {\n continue\n }\n\n const field = currentSchema.fields.find((f) => f.name === part)\n if (!field) continue\n\n if (field.type === 'array' && field.of && field.of.length > 0) {\n for (const itemSchema of field.of) {\n const itemType = typeof itemSchema.type === 'string' ? itemSchema.type : undefined\n if (isLastPart && (itemType === 'image' || itemType === 'file')) {\n nextSchemas.push(itemSchema as ManifestSchemaType)\n } else if (itemType && !isBuiltInType(itemType)) {\n const foundSchema = schema.find((s) => s.name === itemType)\n if (foundSchema) nextSchemas.push(foundSchema)\n } else if ((itemSchema as ManifestSchemaType).fields) {\n nextSchemas.push(itemSchema as ManifestSchemaType)\n }\n }\n } else if (field.type && !isBuiltInType(field.type)) {\n const foundSchema = schema.find((s) => s.name === field.type)\n if (foundSchema) {\n if (foundSchema.type === 'array' && foundSchema.of && foundSchema.of.length > 0) {\n for (const itemSchema of foundSchema.of) {\n const itemType = typeof itemSchema.type === 'string' ? itemSchema.type : undefined\n if (isLastPart && (itemType === 'image' || itemType === 'file')) {\n nextSchemas.push(itemSchema as ManifestSchemaType)\n } else if (itemType && !isBuiltInType(itemType)) {\n const itemFoundSchema = schema.find((s) => s.name === itemType)\n if (itemFoundSchema) nextSchemas.push(itemFoundSchema)\n } else if ((itemSchema as ManifestSchemaType).fields) {\n nextSchemas.push(itemSchema as ManifestSchemaType)\n }\n }\n } else {\n nextSchemas.push(foundSchema)\n }\n }\n } else {\n nextSchemas.push(field as ManifestSchemaType)\n }\n }\n\n currentSchemas = nextSchemas\n }\n\n return currentSchemas\n}\n","import type { ManifestField, ManifestSchemaType } from '../types.js'\nimport { ARRAY_ITEM_SYSTEM_FIELDS, BUILT_IN_TYPE_FIELDS } from './constants.js'\nimport { toSchemaPath } from './path.js'\nimport { isPrimitiveType } from './types.js'\n\ninterface SchemaResolutionResult {\n schema: ManifestSchemaType | null\n earlyReturn: ManifestSchemaType | null\n}\n\nfunction getBuiltInFieldSchema(\n segment: string,\n currentSchema: ManifestSchemaType,\n): ManifestSchemaType | null {\n if (!currentSchema?.type || !BUILT_IN_TYPE_FIELDS[currentSchema.type]?.[segment]) {\n return null\n }\n\n let builtInField: ManifestSchemaType = BUILT_IN_TYPE_FIELDS[currentSchema.type][segment]\n\n // For block.children, merge in block.of (inline objects) from the schema\n if (currentSchema.type === 'block' && segment === 'children' && currentSchema.of) {\n builtInField = {\n ...builtInField,\n of: [...(builtInField.of || []), ...(currentSchema.of as ManifestSchemaType[])],\n }\n }\n\n // For block.markDefs, merge in block.marks.annotations from the schema.\n // The compiled schema materializes supported annotations explicitly\n // (including Sanity's default `link`), so absent/empty annotations means the\n // field supports none — do NOT fall back to an implicit link (SAGE-1134).\n if (currentSchema.type === 'block' && segment === 'markDefs') {\n const annotations = (\n currentSchema as ManifestSchemaType & { marks?: { annotations?: ManifestSchemaType[] } }\n ).marks?.annotations\n builtInField = {\n ...builtInField,\n of: [...(builtInField.of || []), ...(annotations || [])],\n }\n }\n\n return builtInField\n}\n\nfunction findSchemaInUnionArray(\n segment: string,\n arraySchema: ManifestSchemaType,\n allSchemas: ManifestSchemaType[],\n isLastSegment: boolean,\n): SchemaResolutionResult {\n if (!arraySchema.of || arraySchema.of.length === 0) {\n return { schema: null, earlyReturn: null }\n }\n\n for (const itemSchema of arraySchema.of as ManifestSchemaType[]) {\n if (BUILT_IN_TYPE_FIELDS[itemSchema.type]?.[segment]) {\n const builtInField = BUILT_IN_TYPE_FIELDS[itemSchema.type][segment]\n if (isLastSegment) {\n return { schema: null, earlyReturn: builtInField }\n }\n return { schema: builtInField, earlyReturn: null }\n }\n\n if (itemSchema.fields?.some((f) => f.name === segment)) {\n return { schema: itemSchema, earlyReturn: null }\n }\n\n if (itemSchema.type && !isPrimitiveType(itemSchema.type)) {\n const referencedSchema = allSchemas.find((s) => s.name === itemSchema.type)\n if (referencedSchema?.fields?.some((f) => f.name === segment)) {\n return { schema: referencedSchema, earlyReturn: null }\n }\n }\n }\n\n const firstItem = arraySchema.of[0] as ManifestSchemaType\n if (firstItem.fields) {\n return { schema: firstItem, earlyReturn: null }\n }\n\n const referencedSchema = allSchemas.find((s) => s.name === firstItem.type)\n if (referencedSchema?.fields) {\n return { schema: referencedSchema, earlyReturn: null }\n }\n\n return { schema: null, earlyReturn: null }\n}\n\nfunction resolveCurrentSchema(\n segment: string,\n currentSchema: ManifestSchemaType,\n allSchemas: ManifestSchemaType[],\n isLastSegment: boolean,\n): SchemaResolutionResult {\n if (!currentSchema?.type) {\n return { schema: null, earlyReturn: null }\n }\n\n if (currentSchema.type === 'array' && currentSchema.of && currentSchema.of.length > 0) {\n return findSchemaInUnionArray(segment, currentSchema, allSchemas, isLastSegment)\n }\n\n const referencedSchema = allSchemas.find((s) => s.name === currentSchema.type)\n if (referencedSchema?.fields) {\n return { schema: referencedSchema, earlyReturn: null }\n }\n\n if (BUILT_IN_TYPE_FIELDS[currentSchema.type]?.[segment]) {\n const builtInField = BUILT_IN_TYPE_FIELDS[currentSchema.type][segment]\n if (isLastSegment) {\n return { schema: null, earlyReturn: builtInField }\n }\n return { schema: builtInField, earlyReturn: null }\n }\n\n return { schema: null, earlyReturn: null }\n}\n\nfunction getNextSchemaForField(\n field: ManifestField,\n nextSegment: string,\n allSchemas: ManifestSchemaType[],\n): ManifestSchemaType {\n let resolvedField: ManifestSchemaType = field as ManifestSchemaType\n if (field.type && !isPrimitiveType(field.type) && field.type !== 'array') {\n const referencedSchema = allSchemas.find((s) => s.name === field.type)\n if (referencedSchema) {\n resolvedField = referencedSchema\n }\n }\n\n if (resolvedField.type === 'array' && resolvedField.of && resolvedField.of.length > 0) {\n for (const itemSchema of resolvedField.of as ManifestSchemaType[]) {\n if (BUILT_IN_TYPE_FIELDS[itemSchema.type]?.[nextSegment]) {\n return itemSchema\n }\n if (itemSchema.fields?.some((f) => f.name === nextSegment)) {\n return itemSchema\n }\n if (itemSchema.type && !isPrimitiveType(itemSchema.type)) {\n const refSchema = allSchemas.find((s) => s.name === itemSchema.type)\n if (refSchema?.fields?.some((f) => f.name === nextSegment)) {\n return refSchema\n }\n }\n }\n return resolvedField.of[0] as ManifestSchemaType\n }\n\n return resolvedField\n}\n\n/**\n * Resolves a document path to the field schema at that location.\n * Handles nested paths like \"author.name\" and array paths like \"tags[0]\".\n *\n * Returns the field schema at the path, NOT navigating into arrays.\n * For \"tags\" (an array field), returns the array field schema (with 'of').\n * For \"tags[0].foo\", returns the \"foo\" field from the array item schema.\n */\nexport function resolveFieldSchema(\n path: string,\n typeSchema: ManifestSchemaType,\n schema: ManifestSchemaType[],\n): ManifestSchemaType | null {\n const segments = toSchemaPath(path).split('.').filter(Boolean)\n\n let currentSchema: ManifestSchemaType | undefined = typeSchema\n\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i]\n const isLastSegment = i === segments.length - 1\n\n if (ARRAY_ITEM_SYSTEM_FIELDS[segment]) {\n return ARRAY_ITEM_SYSTEM_FIELDS[segment]\n }\n\n const builtInField = getBuiltInFieldSchema(segment, currentSchema!)\n if (builtInField) {\n if (isLastSegment) return builtInField\n currentSchema = builtInField\n continue\n }\n\n if (!currentSchema?.fields) {\n const resolved = resolveCurrentSchema(segment, currentSchema!, schema, isLastSegment)\n if (resolved.earlyReturn) return resolved.earlyReturn\n if (!resolved.schema) return null\n currentSchema = resolved.schema\n\n const resolvedBuiltInField = getBuiltInFieldSchema(segment, currentSchema)\n if (resolvedBuiltInField) {\n if (isLastSegment) return resolvedBuiltInField\n currentSchema = resolvedBuiltInField\n continue\n }\n }\n\n if (!currentSchema?.fields) return null\n\n const field = currentSchema.fields.find((f) => f.name === segment)\n if (!field) return null\n if (isLastSegment) return field\n\n currentSchema = getNextSchemaForField(field, segments[i + 1], schema)\n }\n\n return currentSchema || null\n}\n","/**\n * Whole-tree schema walker.\n *\n * Where `navigateToField` and `navigateAllUnions` resolve a single path string\n * to its field schema, this walks every reachable field in a document type.\n * Used by validators that need to inspect the full schema graph (required\n * fields, custom validators).\n *\n * Handles:\n * - Inline objects (`field.fields`)\n * - Aliased object types (looked up in the schema array)\n * - Arrays of objects (`field.of` items recursed with the same logic)\n *\n * Cycles are guarded by tracking visited type names. Built-in primitive types\n * are skipped: there's nothing to walk into.\n */\n\nimport type { ManifestField, ManifestSchemaType } from '../types.js'\nimport { isPrimitiveType } from './types.js'\n\nexport type WalkVisitor = (field: ManifestField, path: string) => void\n\nexport const joinSchemaPath = (parent: string, child: string): string =>\n parent ? `${parent}.${child}` : child\n\nconst findReferencedType = (\n field: ManifestField,\n schema: ManifestSchemaType[],\n): ManifestSchemaType | undefined => {\n if (isPrimitiveType(field.type)) return undefined\n return schema.find((s) => s.name === field.type)\n}\n\nfunction walkArrayItems(\n field: ManifestField,\n path: string,\n schema: ManifestSchemaType[],\n visited: Set<string>,\n visit: WalkVisitor,\n): void {\n if (!field.of?.length) return\n\n for (const rawItem of field.of) {\n const item = rawItem as ManifestSchemaType\n // Inline object items in `of` carry their own fields; aliased items just\n // reference a type by name and need a schema lookup.\n if (item.fields?.length) {\n walkFields(item.fields, path, schema, visited, visit)\n continue\n }\n if (!item.type || isPrimitiveType(item.type)) continue\n const referenced = schema.find((s) => s.name === item.type)\n if (!referenced || visited.has(referenced.name)) continue\n if (referenced.fields?.length) {\n visited.add(referenced.name)\n walkFields(referenced.fields, path, schema, visited, visit)\n }\n }\n}\n\nfunction walkFields(\n fields: ManifestField[],\n path: string,\n schema: ManifestSchemaType[],\n visited: Set<string>,\n visit: WalkVisitor,\n): void {\n for (const field of fields) {\n const fieldPath = joinSchemaPath(path, field.name)\n visit(field, fieldPath)\n\n if (field.fields?.length) {\n walkFields(field.fields, fieldPath, schema, visited, visit)\n continue\n }\n\n if (field.of?.length) {\n walkArrayItems(field, fieldPath, schema, visited, visit)\n continue\n }\n\n const referenced = findReferencedType(field, schema)\n if (!referenced?.fields?.length) continue\n if (visited.has(referenced.name)) continue\n\n visited.add(referenced.name)\n walkFields(referenced.fields, fieldPath, schema, visited, visit)\n }\n}\n\n/**\n * Visit every field reachable from a document type. The visitor is called once\n * per field with the field schema and its dotted path from the document root.\n */\nexport function walkSchemaTree(\n documentType: string,\n schema: ManifestSchemaType[],\n visit: WalkVisitor,\n): void {\n const typeSchema = schema.find((s) => s.name === documentType)\n if (!typeSchema?.fields?.length) return\n\n walkFields(typeSchema.fields, '', schema, new Set([typeSchema.name]), visit)\n}\n"],"names":["referencedSchema"],"mappings":"AAMO,MAAM,uBAA2E;AAAA,EACtF,MAAM;AAAA,IACJ,SAAS,EAAE,MAAM,WAAW,MAAM,SAAA;AAAA,IAClC,OAAO,EAAE,MAAM,SAAS,MAAM,SAAA;AAAA,EAAS;AAAA,EAEzC,UAAU;AAAA,IACR,KAAK,EAAE,MAAM,OAAO,MAAM,SAAA;AAAA,IAC1B,KAAK,EAAE,MAAM,OAAO,MAAM,SAAA;AAAA,IAC1B,KAAK,EAAE,MAAM,OAAO,MAAM,SAAA;AAAA,IAC1B,OAAO,EAAE,MAAM,SAAS,MAAM,SAAA;AAAA,EAAS;AAAA,EAEzC,WAAW;AAAA,IACT,MAAM,EAAE,MAAM,QAAQ,MAAM,SAAA;AAAA,IAC5B,OAAO,EAAE,MAAM,SAAS,MAAM,SAAA;AAAA,IAC9B,OAAO,EAAE,MAAM,SAAS,MAAM,UAAA;AAAA,EAAU;AAAA,EAE1C,OAAO;AAAA,IACL,OAAO,EAAE,MAAM,SAAS,MAAM,YAAA;AAAA,IAC9B,SAAS;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,MACN,QAAQ;AAAA,QACN,EAAE,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,eAAe,MAAM,MAAM,IAAI;AAGjD,QAFA,MAAM,OAAO,SAAS,GAElB,MAAM,QAAQ,QAAQ;AACxB,iBAAW,MAAM,QAAQ,WAAW,QAAQ,SAAS,KAAK;AAC1D;AAAA,IACF;AAEA,QAAI,MAAM,IAAI,QAAQ;AACpB,qBAAe,OAAO,WAAW,QAAQ,SAAS,KAAK;AACvD;AAAA,IACF;AAEA,UAAM,aAAa,mBAAmB,OAAO,MAAM;AAC9C,gBAAY,QAAQ,WACrB,QAAQ,IAAI,WAAW,IAAI,MAE/B,QAAQ,IAAI,WAAW,IAAI,GAC3B,WAAW,WAAW,QAAQ,WAAW,QAAQ,SAAS,KAAK;AAAA,EACjE;AACF;AAMO,SAAS,eACd,cACA,QACA,OACM;AACN,QAAM,aAAa,OAAO,KAAK,CAAC,MAAM,EAAE,SAAS,YAAY;AACxD,cAAY,QAAQ,UAEzB,WAAW,WAAW,QAAQ,IAAI,QAAQ,oBAAI,IAAI,CAAC,WAAW,IAAI,CAAC,GAAG,KAAK;AAC7E;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -64,11 +64,6 @@ declare function processSchema(schema: ManifestSchemaType[], options?: SchemaPro
|
|
|
64
64
|
* Maps type name to field definitions.
|
|
65
65
|
*/
|
|
66
66
|
declare const BUILT_IN_TYPE_FIELDS: Record<string, Record<string, ManifestSchemaType>>;
|
|
67
|
-
/**
|
|
68
|
-
* Default annotation type for Portable Text blocks.
|
|
69
|
-
* Sanity implicitly includes "link" when no marks.annotations are declared.
|
|
70
|
-
*/
|
|
71
|
-
declare const DEFAULT_LINK_ANNOTATION: ManifestSchemaType;
|
|
72
67
|
/**
|
|
73
68
|
* System fields that exist on all array items.
|
|
74
69
|
*/
|
|
@@ -188,6 +183,24 @@ declare const SCHEMA_CONSTANTS: {
|
|
|
188
183
|
readonly maxDocDescriptionLength: number;
|
|
189
184
|
};
|
|
190
185
|
};
|
|
186
|
+
type GroqFilter = {
|
|
187
|
+
read?: string;
|
|
188
|
+
write?: string;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Resolves a `SchemaFilter` into a string array of document type names.
|
|
192
|
+
* - `string[]` is returned as-is (empty array means zero types)
|
|
193
|
+
* - `{ read?, write? }` GROQ expressions are evaluated against the schema
|
|
194
|
+
* - `undefined` returns `undefined` (no filtering)
|
|
195
|
+
*/
|
|
196
|
+
/**
|
|
197
|
+
* Extracts document type names to include based on read/write GROQ filter expressions.
|
|
198
|
+
* Returns the union of types allowed by either filter.
|
|
199
|
+
*
|
|
200
|
+
* Without a filter, returns all document type names.
|
|
201
|
+
* With a filter that matches nothing, returns an empty array.
|
|
202
|
+
*/
|
|
203
|
+
declare function getFilteredDocumentTypes(schema: ManifestSchemaType[], filter: GroqFilter | undefined): Promise<string[]>;
|
|
191
204
|
declare function shouldSkipType(typeName: string): boolean;
|
|
192
205
|
/**
|
|
193
206
|
* Generates a compressed text representation of a schema for agent consumption.
|
|
@@ -199,5 +212,5 @@ declare function shouldSkipType(typeName: string): boolean;
|
|
|
199
212
|
* a pre-resolved `string[]` of document type names.
|
|
200
213
|
*/
|
|
201
214
|
declare function compressedSchema(types: ManifestSchemaType[], options?: CompressedSchemaOptions): Promise<string>;
|
|
202
|
-
export { ARRAY_ITEM_SYSTEM_FIELDS, BUILT_IN_TYPE_FIELDS, type CompressedSchemaOptions,
|
|
215
|
+
export { ARRAY_ITEM_SYSTEM_FIELDS, BUILT_IN_TYPE_FIELDS, type CompressedSchemaOptions, type DatasetStats, DatasetStatsSchema, type FetchSchemaOptions, type FetchSchemaSummaryOptions, type FieldSchemaLookupResult, type FullSchemaOptions, type InsertOperation, type LexiconResponse, 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, type WalkVisitor, compressedSchema, fetchDatasetStats, fetchSchemaByDescriptorId, filterToPath, fullSchema, getFilteredDocumentTypes, isBuiltInType, isGenericObject, isPrimitiveType, resolveFieldSchema as navigateToFieldSchema, resolveFieldSchema, resolveFieldSchemaAllUnions as navigateToFieldSchemaAllUnions, resolveFieldSchemaAllUnions, processSchema, shouldSkipType, toSchemaPath, walkSchemaTree };
|
|
203
216
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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/navigate/walkTree.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,WDrCA;ECuCA,MAAA;AAAA;AAAA,KAGU,yBAAA,GAA4B,IAAA,CAAK,kBAAA;ED9BN,8FCgCrC,MAAA;AAAA;;;;;;;;;;;iBAac,yBAAA,CACd,MAAA,EAAQ,YAAA,EACR,YAAA,UACA,OAAA,EAAS,yBAAA,GACR,OAAA,CAAQ,eAAA;AAAA,iBACK,yBAAA,CACd,MAAA,EAAQ,YAAA,EACR,YAAA,UACA,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,kBAAA;;;ADzEmC;;iBEqJ9B,aAAA,CACd,MAAA,EAAQ,kBAAA,IACR,OAAA,GAAU,sBAAA,GACT,WAAA;;;AFxJ2C;;cGKjC,oBAAA,EAAsB,MAAA,SAAe,MAAA,SAAe,kBAAA
|
|
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/navigate/walkTree.ts","../src/fullSchema.ts","../src/constants.ts","../src/filterDocumentTypes.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,WDrCA;ECuCA,MAAA;AAAA;AAAA,KAGU,yBAAA,GAA4B,IAAA,CAAK,kBAAA;ED9BN,8FCgCrC,MAAA;AAAA;;;;;;;;;;;iBAac,yBAAA,CACd,MAAA,EAAQ,YAAA,EACR,YAAA,UACA,O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B,UAAA,CACd,MAAA,EAAQ,kBAAA,IACR,OAAA,EAAS,iBAAA,GACR,MAAA,oBAA0B,kBAAA;AAAA,cCpChB,gBAAA;EAAA,wBAkBH,MAAA;EAAA;;;;;;;;;;;;;;KCdL,UAAA;EAAe,IAAA;EAAe,KAAA;AAAA;;;;;;;;AZD0C;;;;;;iBYyBvD,wBAAA,CACpB,MAAA,EAAQ,kBAAA,IACR,MAAA,EAAQ,UAAA,eACP,OAAA;AAAA,iBC3Ba,cAAA,CAAe,QAAA;;;;AbgB/B;;;;;;iBcuFsB,gBAAA,CACpB,KAAA,EAAO,kBAAA,IACP,OAAA,GAAS,uBAAA,GACR,OAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { convertToDefinition } from "@sanity/schema-descriptor-utils";
|
|
2
2
|
import { isPrimitiveType, isGenericObject } from "./_chunks-es/walkTree.js";
|
|
3
|
-
import { ARRAY_ITEM_SYSTEM_FIELDS, BUILT_IN_TYPE_FIELDS,
|
|
3
|
+
import { ARRAY_ITEM_SYSTEM_FIELDS, BUILT_IN_TYPE_FIELDS, isBuiltInType, resolveFieldSchema, resolveFieldSchemaAllUnions, resolveFieldSchema as resolveFieldSchema2, resolveFieldSchemaAllUnions as resolveFieldSchemaAllUnions2, toSchemaPath, walkSchemaTree } from "./_chunks-es/walkTree.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
async function fetchDatasetStats(client, options) {
|
|
6
6
|
const { organizationId, projectId, dataset } = options, response = await client.request({
|
|
@@ -58,7 +58,7 @@ const SCHEMA_CONSTANTS = {
|
|
|
58
58
|
};
|
|
59
59
|
function resolveFilterSync(filter) {
|
|
60
60
|
if (filter && Array.isArray(filter))
|
|
61
|
-
return filter
|
|
61
|
+
return filter;
|
|
62
62
|
}
|
|
63
63
|
const TITLE_FIELD_CANDIDATES = SCHEMA_CONSTANTS.TITLE_FIELD_CANDIDATES;
|
|
64
64
|
function isTextLike(type) {
|
|
@@ -130,7 +130,7 @@ function collectReferences(fields, path, included, trackPaths, outgoing, outgoin
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
function processSchema(schema, options) {
|
|
133
|
-
const trackPaths = SCHEMA_CONSTANTS.DEFAULT_OPTIONS.trackPaths, includeList = resolveFilterSync(options?.filter), includeSet = includeList
|
|
133
|
+
const trackPaths = SCHEMA_CONSTANTS.DEFAULT_OPTIONS.trackPaths, includeList = resolveFilterSync(options?.filter), includeSet = includeList ? new Set(includeList) : null, included = (name) => !includeSet || includeSet.has(name), maxDepth = SCHEMA_CONSTANTS.DEFAULT_OPTIONS.maxExpansionDepth, documentTypes = /* @__PURE__ */ new Map(), objectTypes = /* @__PURE__ */ new Map();
|
|
134
134
|
for (const type of schema)
|
|
135
135
|
if (type.type === "document") {
|
|
136
136
|
if (!included(type.name)) continue;
|
|
@@ -442,14 +442,12 @@ const InOutCountsSchema = z.object({
|
|
|
442
442
|
referenceCount: z.record(InOutCountsSchema).optional()
|
|
443
443
|
});
|
|
444
444
|
async function resolveFilter(schema, filter) {
|
|
445
|
-
if (
|
|
446
|
-
|
|
447
|
-
const result = await getFilteredDocumentTypes(schema, filter);
|
|
448
|
-
return result.length > 0 ? result : void 0;
|
|
445
|
+
if (filter)
|
|
446
|
+
return Array.isArray(filter) ? filter : await getFilteredDocumentTypes(schema, filter);
|
|
449
447
|
}
|
|
450
448
|
async function getFilteredDocumentTypes(schema, filter) {
|
|
451
|
-
if (!filter || !filter.read && !filter.write) return [];
|
|
452
449
|
const allDocTypes = schema.filter((s) => s.type === "document").map((s) => s.name);
|
|
450
|
+
if (!filter || !filter.read && !filter.write) return allDocTypes;
|
|
453
451
|
if (allDocTypes.length === 0) return [];
|
|
454
452
|
const combined = /* @__PURE__ */ new Set();
|
|
455
453
|
if (filter.read)
|
|
@@ -458,14 +456,14 @@ async function getFilteredDocumentTypes(schema, filter) {
|
|
|
458
456
|
if (filter.write)
|
|
459
457
|
for (const type of await filterTypesByExpression(filter.write, allDocTypes))
|
|
460
458
|
combined.add(type);
|
|
461
|
-
return
|
|
459
|
+
return Array.from(combined);
|
|
462
460
|
}
|
|
463
461
|
async function filterTypesByExpression(filterExpr, allTypes) {
|
|
464
462
|
if (!filterExpr?.trim() || allTypes.length === 0)
|
|
465
463
|
return new Set(allTypes);
|
|
466
464
|
try {
|
|
467
465
|
const { parse } = await import("groq-js"), ast = parse(filterExpr), matching = allTypes.filter((type) => evaluateForType(ast, type) !== !1);
|
|
468
|
-
return
|
|
466
|
+
return new Set(matching);
|
|
469
467
|
} catch {
|
|
470
468
|
return new Set(allTypes);
|
|
471
469
|
}
|
|
@@ -677,7 +675,6 @@ async function compressedSchema(types, options = {}) {
|
|
|
677
675
|
export {
|
|
678
676
|
ARRAY_ITEM_SYSTEM_FIELDS,
|
|
679
677
|
BUILT_IN_TYPE_FIELDS,
|
|
680
|
-
DEFAULT_LINK_ANNOTATION,
|
|
681
678
|
DatasetStatsSchema,
|
|
682
679
|
SCHEMA_CONSTANTS,
|
|
683
680
|
compressedSchema,
|
|
@@ -685,6 +682,7 @@ export {
|
|
|
685
682
|
fetchSchemaByDescriptorId,
|
|
686
683
|
filterToPath,
|
|
687
684
|
fullSchema,
|
|
685
|
+
getFilteredDocumentTypes,
|
|
688
686
|
isBuiltInType,
|
|
689
687
|
isGenericObject,
|
|
690
688
|
isPrimitiveType,
|