@sanity/agent-schema 0.2.0 → 0.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/agent-schema",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Schema processing utilities for Sanity Agent",
5
5
  "keywords": [
6
6
  "sanity",
@@ -41,7 +41,7 @@
41
41
  "@types/node": "^22.19.7",
42
42
  "groq-js": "^1.30.1",
43
43
  "typescript": "^5.9.3",
44
- "vitest": "^4.0.18",
44
+ "vitest": "^4.1.10",
45
45
  "@repo/package.config": "0.0.0",
46
46
  "@repo/tsconfig": "0.0.0"
47
47
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"navigateToField.js","sources":["../../src/navigate/constants.ts","../../src/navigate/path.ts","../../src/navigate/types.ts","../../src/navigate/navigateAllUnions.ts","../../src/navigate/navigateToField.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"],"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,M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