@stonecrop/schema 0.13.4 → 0.13.6

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/cli.js CHANGED
@@ -3,7 +3,7 @@ import { readFileSync as u, existsSync as S, mkdirSync as w, writeFileSync as x
3
3
  import { resolve as c, join as O } from "node:path";
4
4
  import { parseArgs as $ } from "node:util";
5
5
  import { getIntrospectionQuery as N } from "graphql";
6
- import { e as P, v as j } from "./index-Cu-6609R.js";
6
+ import { e as P, v as j } from "./index-COp1U6eU.js";
7
7
  async function C(e, m) {
8
8
  const t = await fetch(e, {
9
9
  method: "POST",
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/* eslint-disable no-console */\n\n/**\n * Stonecrop Schema CLI\n *\n * Converts GraphQL introspection results to Stonecrop doctype JSON schemas.\n *\n * Usage:\n * stonecrop-schema generate --endpoint <url> --output <dir>\n * stonecrop-schema generate --introspection <file.json> --output <dir>\n * stonecrop-schema generate --sdl <file.graphql> --output <dir>\n *\n * @packageDocumentation\n */\n\nimport { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { resolve, join } from 'node:path'\nimport { parseArgs } from 'node:util'\nimport { getIntrospectionQuery, type IntrospectionQuery } from 'graphql'\n\nimport { convertGraphQLSchema } from './converter/index'\nimport { validateDoctype } from './validation'\nimport type { GraphQLConversionOptions } from './converter/types'\n\n/**\n * Fetch an introspection result from a live GraphQL endpoint.\n *\n * @param endpoint - The GraphQL endpoint URL\n * @param headers - Optional HTTP headers\n * @returns The introspection query result\n */\nasync function fetchIntrospection(endpoint: string, headers?: Record<string, string>): Promise<IntrospectionQuery> {\n\tconst response = await fetch(endpoint, {\n\t\tmethod: 'POST',\n\t\theaders: {\n\t\t\t'Content-Type': 'application/json',\n\t\t\t...headers,\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\tquery: getIntrospectionQuery(),\n\t\t}),\n\t})\n\n\tif (!response.ok) {\n\t\tthrow new Error(`Failed to fetch introspection: ${response.status} ${response.statusText}`)\n\t}\n\n\tconst json = (await response.json()) as {\n\t\tdata?: IntrospectionQuery\n\t\terrors?: Array<{ message: string }>\n\t}\n\n\tif (json.errors?.length) {\n\t\tthrow new Error(`GraphQL errors: ${json.errors.map(e => e.message).join(', ')}`)\n\t}\n\n\tif (!json.data) {\n\t\tthrow new Error('No data in introspection response')\n\t}\n\n\treturn json.data\n}\n\nasync function main(): Promise<void> {\n\tconst { values, positionals } = parseArgs({\n\t\tallowPositionals: true,\n\t\toptions: {\n\t\t\tendpoint: { type: 'string', short: 'e' },\n\t\t\tintrospection: { type: 'string', short: 'i' },\n\t\t\tsdl: { type: 'string', short: 's' },\n\t\t\toutput: { type: 'string', short: 'o' },\n\t\t\tinclude: { type: 'string' },\n\t\t\texclude: { type: 'string' },\n\t\t\toverrides: { type: 'string' },\n\t\t\t'custom-scalars': { type: 'string' },\n\t\t\t'include-unmapped': { type: 'boolean', default: false },\n\t\t\thelp: { type: 'boolean', short: 'h' },\n\t\t},\n\t})\n\n\tconst command = positionals[0]\n\n\tif (values.help || !command) {\n\t\tprintHelp()\n\t\tprocess.exit(command ? 0 : 1)\n\t}\n\n\tif (command !== 'generate') {\n\t\tconsole.error(`Unknown command: ${command}`)\n\t\tconsole.error('Available commands: generate')\n\t\tprocess.exit(1)\n\t}\n\n\t// Determine source\n\tconst sourceCount = [values.endpoint, values.introspection, values.sdl].filter(Boolean).length\n\tif (sourceCount !== 1) {\n\t\tconsole.error('Exactly one of --endpoint, --introspection, or --sdl must be provided')\n\t\tprocess.exit(1)\n\t}\n\n\tif (!values.output) {\n\t\tconsole.error('--output <dir> is required')\n\t\tprocess.exit(1)\n\t}\n\n\tconst outputDir = resolve(values.output)\n\n\t// Build conversion options\n\tconst options: GraphQLConversionOptions = {\n\t\tincludeUnmappedMeta: values['include-unmapped'],\n\t}\n\n\tif (values.include) {\n\t\toptions.include = values.include.split(',').map(s => s.trim())\n\t}\n\n\tif (values.exclude) {\n\t\toptions.exclude = values.exclude.split(',').map(s => s.trim())\n\t}\n\n\tif (values.overrides) {\n\t\tconst overridesPath = resolve(values.overrides)\n\t\tconst overridesContent = readFileSync(overridesPath, 'utf-8')\n\t\toptions.typeOverrides = JSON.parse(overridesContent)\n\t}\n\n\tif (values['custom-scalars']) {\n\t\tconst scalarsPath = resolve(values['custom-scalars'])\n\t\tconst scalarsContent = readFileSync(scalarsPath, 'utf-8')\n\t\toptions.customScalars = JSON.parse(scalarsContent)\n\t}\n\n\t// Resolve source\n\tlet source: IntrospectionQuery | string\n\n\tif (values.endpoint) {\n\t\tconsole.log(`Fetching introspection from ${values.endpoint}...`)\n\t\tsource = await fetchIntrospection(values.endpoint)\n\t} else if (values.introspection) {\n\t\tconst filePath = resolve(values.introspection)\n\t\tconst content = readFileSync(filePath, 'utf-8')\n\t\tconst parsed = JSON.parse(content)\n\t\t// Handle both { data: { __schema: ... } } and { __schema: ... } formats\n\t\tsource = parsed.data ?? parsed\n\t} else {\n\t\tconst filePath = resolve(values.sdl!)\n\t\tsource = readFileSync(filePath, 'utf-8')\n\t}\n\n\t// Convert\n\tconst doctypes = convertGraphQLSchema(source, options)\n\n\tif (doctypes.length === 0) {\n\t\tconsole.warn('No entity types found in the schema. Check your include/exclude filters.')\n\t\tprocess.exit(0)\n\t}\n\n\t// Write output\n\tif (!existsSync(outputDir)) {\n\t\tmkdirSync(outputDir, { recursive: true })\n\t}\n\n\tlet warnings = 0\n\tlet errors = 0\n\n\tfor (const doctype of doctypes) {\n\t\tconst fileName = `${doctype.slug}.json`\n\t\tconst filePath = join(outputDir, fileName)\n\t\tconst json = JSON.stringify(doctype, null, '\\t')\n\n\t\twriteFileSync(filePath, json + '\\n', 'utf-8')\n\n\t\t// Validate the output\n\t\tconst validation = validateDoctype(doctype)\n\t\tif (!validation.success) {\n\t\t\terrors++\n\t\t\tconsole.error(` ERROR: ${fileName} failed validation:`)\n\t\t\tfor (const err of validation.errors) {\n\t\t\t\tconsole.error(` ${err.path.join('.')}: ${err.message}`)\n\t\t\t}\n\t\t} else {\n\t\t\t// Check for unmapped fields\n\t\t\tconst unmappedFields = doctype.fields.filter((f: any) => f._unmapped)\n\t\t\tif (unmappedFields.length > 0) {\n\t\t\t\twarnings++\n\t\t\t\tconsole.warn(\n\t\t\t\t\t` WARN: ${fileName} has ${unmappedFields.length} unmapped field(s): ${unmappedFields\n\t\t\t\t\t\t.map((f: any) => f.fieldname)\n\t\t\t\t\t\t.join(', ')}`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\tconsole.log(\n\t\t`\\nGenerated ${doctypes.length} doctype(s) in ${outputDir}` +\n\t\t\t(warnings ? ` (${warnings} with warnings)` : '') +\n\t\t\t(errors ? ` (${errors} with errors)` : '')\n\t)\n\n\tif (errors > 0) {\n\t\tprocess.exit(1)\n\t}\n}\n\nfunction printHelp(): void {\n\tconsole.log(`\nstonecrop-schema - Convert GraphQL schemas to Stonecrop doctypes\n\nUSAGE:\n stonecrop-schema generate [options]\n\nSOURCE (exactly one required):\n --endpoint, -e <url> Fetch introspection from a live GraphQL endpoint\n --introspection, -i <file> Read from a saved introspection JSON file\n --sdl, -s <file> Read from a GraphQL SDL (.graphql) file\n\nOUTPUT:\n --output, -o <dir> Directory to write doctype JSON files (required)\n\nOPTIONS:\n --include <types> Comma-separated list of type names to include\n --exclude <types> Comma-separated list of type names to exclude\n --overrides <file> JSON file with per-type field overrides\n --custom-scalars <file> JSON file mapping custom scalar names to field templates\n --include-unmapped Include _graphqlType metadata on unmapped fields\n --help, -h Show this help message\n\nEXAMPLES:\n # From a live PostGraphile server\n stonecrop-schema generate -e http://localhost:5000/graphql -o ./schemas\n\n # From a saved introspection result\n stonecrop-schema generate -i introspection.json -o ./schemas\n\n # From an SDL file with custom scalars\n stonecrop-schema generate -s schema.graphql -o ./schemas \\\\\n --custom-scalars custom-scalars.json\n\n # Only convert specific types\n stonecrop-schema generate -e http://localhost:5000/graphql -o ./schemas \\\\\n --include \"User,Post,Comment\"\n`)\n}\n\nmain().catch(err => {\n\tconsole.error('Error:', err.message)\n\tprocess.exit(1)\n})\n"],"names":["fetchIntrospection","endpoint","headers","response","getIntrospectionQuery","json","e","main","values","positionals","parseArgs","command","printHelp","outputDir","resolve","options","s","overridesPath","overridesContent","readFileSync","scalarsPath","scalarsContent","source","filePath","content","parsed","doctypes","convertGraphQLSchema","existsSync","mkdirSync","warnings","errors","doctype","fileName","join","writeFileSync","validation","validateDoctype","unmappedFields","f","err"],"mappings":";;;;;;AAgCA,eAAeA,EAAmBC,GAAkBC,GAA+D;AAClH,QAAMC,IAAW,MAAM,MAAMF,GAAU;AAAA,IACtC,QAAQ;AAAA,IACR,SAAS;AAAA,MACR,gBAAgB;AAAA,MAChB,GAAGC;AAAA,IAAA;AAAA,IAEJ,MAAM,KAAK,UAAU;AAAA,MACpB,OAAOE,EAAA;AAAA,IAAsB,CAC7B;AAAA,EAAA,CACD;AAED,MAAI,CAACD,EAAS;AACb,UAAM,IAAI,MAAM,kCAAkCA,EAAS,MAAM,IAAIA,EAAS,UAAU,EAAE;AAG3F,QAAME,IAAQ,MAAMF,EAAS,KAAA;AAK7B,MAAIE,EAAK,QAAQ;AAChB,UAAM,IAAI,MAAM,mBAAmBA,EAAK,OAAO,IAAI,CAAAC,MAAKA,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC,EAAE;AAGhF,MAAI,CAACD,EAAK;AACT,UAAM,IAAI,MAAM,mCAAmC;AAGpD,SAAOA,EAAK;AACb;AAEA,eAAeE,IAAsB;AACpC,QAAM,EAAE,QAAAC,GAAQ,aAAAC,EAAA,IAAgBC,EAAU;AAAA,IACzC,kBAAkB;AAAA,IAClB,SAAS;AAAA,MACR,UAAU,EAAE,MAAM,UAAU,OAAO,IAAA;AAAA,MACnC,eAAe,EAAE,MAAM,UAAU,OAAO,IAAA;AAAA,MACxC,KAAK,EAAE,MAAM,UAAU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,uBAAuBA,EACrE,IAAI,CAACC,MAAWA,EAAE,SAAS,EAC3B,KAAK,IAAI,CAAC;AAAA,MAAA;AAAA,IAGf,OAjByB;AACxB,MAAAR,KACA,QAAQ,MAAM,YAAYE,CAAQ,qBAAqB;AACvD,iBAAWO,KAAOJ,EAAW;AAC5B,gBAAQ,MAAM,OAAOI,EAAI,KAAK,KAAK,GAAG,CAAC,KAAKA,EAAI,OAAO,EAAE;AAAA,IAE3D;AAAA,EAYD;AAEA,UAAQ;AAAA,IACP;AAAA,YAAed,EAAS,MAAM,kBAAkBb,CAAS,MACvDiB,IAAW,KAAKA,CAAQ,oBAAoB,OAC5CC,IAAS,KAAKA,CAAM,kBAAkB;AAAA,EAAA,GAGrCA,IAAS,KACZ,QAAQ,KAAK,CAAC;AAEhB;AAEA,SAASnB,IAAkB;AAC1B,UAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAoCZ;AACD;AAEAL,IAAO,MAAM,CAAAiC,MAAO;AACnB,UAAQ,MAAM,UAAUA,EAAI,OAAO,GACnC,QAAQ,KAAK,CAAC;AACf,CAAC;"}
1
+ {"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/* oxlint-disable no-console */\n\n/**\n * Stonecrop Schema CLI\n *\n * Converts GraphQL introspection results to Stonecrop doctype JSON schemas.\n *\n * Usage:\n * stonecrop-schema generate --endpoint <url> --output <dir>\n * stonecrop-schema generate --introspection <file.json> --output <dir>\n * stonecrop-schema generate --sdl <file.graphql> --output <dir>\n *\n * @packageDocumentation\n */\n\nimport { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { resolve, join } from 'node:path'\nimport { parseArgs } from 'node:util'\nimport { getIntrospectionQuery, type IntrospectionQuery } from 'graphql'\n\nimport { convertGraphQLSchema } from './converter/index'\nimport { validateDoctype } from './validation'\nimport type { GraphQLConversionOptions } from './converter/types'\n\n/**\n * Fetch an introspection result from a live GraphQL endpoint.\n *\n * @param endpoint - The GraphQL endpoint URL\n * @param headers - Optional HTTP headers\n * @returns The introspection query result\n */\nasync function fetchIntrospection(endpoint: string, headers?: Record<string, string>): Promise<IntrospectionQuery> {\n\tconst response = await fetch(endpoint, {\n\t\tmethod: 'POST',\n\t\theaders: {\n\t\t\t'Content-Type': 'application/json',\n\t\t\t...headers,\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\tquery: getIntrospectionQuery(),\n\t\t}),\n\t})\n\n\tif (!response.ok) {\n\t\tthrow new Error(`Failed to fetch introspection: ${response.status} ${response.statusText}`)\n\t}\n\n\tconst json: { data?: IntrospectionQuery; errors?: Array<{ message: string }> } = await response.json()\n\n\tif (json.errors?.length) {\n\t\tthrow new Error(`GraphQL errors: ${json.errors.map(e => e.message).join(', ')}`)\n\t}\n\n\tif (!json.data) {\n\t\tthrow new Error('No data in introspection response')\n\t}\n\n\treturn json.data\n}\n\nasync function main(): Promise<void> {\n\tconst { values, positionals } = parseArgs({\n\t\tallowPositionals: true,\n\t\toptions: {\n\t\t\tendpoint: { type: 'string', short: 'e' },\n\t\t\tintrospection: { type: 'string', short: 'i' },\n\t\t\tsdl: { type: 'string', short: 's' },\n\t\t\toutput: { type: 'string', short: 'o' },\n\t\t\tinclude: { type: 'string' },\n\t\t\texclude: { type: 'string' },\n\t\t\toverrides: { type: 'string' },\n\t\t\t'custom-scalars': { type: 'string' },\n\t\t\t'include-unmapped': { type: 'boolean', default: false },\n\t\t\thelp: { type: 'boolean', short: 'h' },\n\t\t},\n\t})\n\n\tconst command = positionals[0]\n\n\tif (values.help || !command) {\n\t\tprintHelp()\n\t\tprocess.exit(command ? 0 : 1)\n\t}\n\n\tif (command !== 'generate') {\n\t\tconsole.error(`Unknown command: ${command}`)\n\t\tconsole.error('Available commands: generate')\n\t\tprocess.exit(1)\n\t}\n\n\t// Determine source\n\tconst sourceCount = [values.endpoint, values.introspection, values.sdl].filter(Boolean).length\n\tif (sourceCount !== 1) {\n\t\tconsole.error('Exactly one of --endpoint, --introspection, or --sdl must be provided')\n\t\tprocess.exit(1)\n\t}\n\n\tif (!values.output) {\n\t\tconsole.error('--output <dir> is required')\n\t\tprocess.exit(1)\n\t}\n\n\tconst outputDir = resolve(values.output)\n\n\t// Build conversion options\n\tconst options: GraphQLConversionOptions = {\n\t\tincludeUnmappedMeta: values['include-unmapped'],\n\t}\n\n\tif (values.include) {\n\t\toptions.include = values.include.split(',').map(s => s.trim())\n\t}\n\n\tif (values.exclude) {\n\t\toptions.exclude = values.exclude.split(',').map(s => s.trim())\n\t}\n\n\tif (values.overrides) {\n\t\tconst overridesPath = resolve(values.overrides)\n\t\tconst overridesContent = readFileSync(overridesPath, 'utf-8')\n\t\toptions.typeOverrides = JSON.parse(overridesContent)\n\t}\n\n\tif (values['custom-scalars']) {\n\t\tconst scalarsPath = resolve(values['custom-scalars'])\n\t\tconst scalarsContent = readFileSync(scalarsPath, 'utf-8')\n\t\toptions.customScalars = JSON.parse(scalarsContent)\n\t}\n\n\t// Resolve source\n\tlet source: IntrospectionQuery | string\n\n\tif (values.endpoint) {\n\t\tconsole.log(`Fetching introspection from ${values.endpoint}...`)\n\t\tsource = await fetchIntrospection(values.endpoint)\n\t} else if (values.introspection) {\n\t\tconst filePath = resolve(values.introspection)\n\t\tconst content = readFileSync(filePath, 'utf-8')\n\t\tconst parsed = JSON.parse(content)\n\t\t// Handle both { data: { __schema: ... } } and { __schema: ... } formats\n\t\tsource = parsed.data ?? parsed\n\t} else {\n\t\tconst filePath = resolve(values.sdl!)\n\t\tsource = readFileSync(filePath, 'utf-8')\n\t}\n\n\t// Convert\n\tconst doctypes = convertGraphQLSchema(source, options)\n\n\tif (doctypes.length === 0) {\n\t\tconsole.warn('No entity types found in the schema. Check your include/exclude filters.')\n\t\tprocess.exit(0)\n\t}\n\n\t// Write output\n\tif (!existsSync(outputDir)) {\n\t\tmkdirSync(outputDir, { recursive: true })\n\t}\n\n\tlet warnings = 0\n\tlet errors = 0\n\n\tfor (const doctype of doctypes) {\n\t\tconst fileName = `${doctype.slug}.json`\n\t\tconst filePath = join(outputDir, fileName)\n\t\tconst json = JSON.stringify(doctype, null, '\\t')\n\n\t\twriteFileSync(filePath, json + '\\n', 'utf-8')\n\n\t\t// Validate the output\n\t\tconst validation = validateDoctype(doctype)\n\t\tif (!validation.success) {\n\t\t\terrors++\n\t\t\tconsole.error(` ERROR: ${fileName} failed validation:`)\n\t\t\tfor (const err of validation.errors) {\n\t\t\t\tconsole.error(` ${err.path.join('.')}: ${err.message}`)\n\t\t\t}\n\t\t} else {\n\t\t\t// Check for unmapped fields\n\t\t\tconst unmappedFields = doctype.fields.filter((f: any) => f._unmapped)\n\t\t\tif (unmappedFields.length > 0) {\n\t\t\t\twarnings++\n\t\t\t\tconsole.warn(\n\t\t\t\t\t` WARN: ${fileName} has ${unmappedFields.length} unmapped field(s): ${unmappedFields\n\t\t\t\t\t\t.map((f: any) => f.fieldname)\n\t\t\t\t\t\t.join(', ')}`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\tconsole.log(\n\t\t`\\nGenerated ${doctypes.length} doctype(s) in ${outputDir}` +\n\t\t\t(warnings ? ` (${warnings} with warnings)` : '') +\n\t\t\t(errors ? ` (${errors} with errors)` : '')\n\t)\n\n\tif (errors > 0) {\n\t\tprocess.exit(1)\n\t}\n}\n\nfunction printHelp(): void {\n\tconsole.log(`\nstonecrop-schema - Convert GraphQL schemas to Stonecrop doctypes\n\nUSAGE:\n stonecrop-schema generate [options]\n\nSOURCE (exactly one required):\n --endpoint, -e <url> Fetch introspection from a live GraphQL endpoint\n --introspection, -i <file> Read from a saved introspection JSON file\n --sdl, -s <file> Read from a GraphQL SDL (.graphql) file\n\nOUTPUT:\n --output, -o <dir> Directory to write doctype JSON files (required)\n\nOPTIONS:\n --include <types> Comma-separated list of type names to include\n --exclude <types> Comma-separated list of type names to exclude\n --overrides <file> JSON file with per-type field overrides\n --custom-scalars <file> JSON file mapping custom scalar names to field templates\n --include-unmapped Include _graphqlType metadata on unmapped fields\n --help, -h Show this help message\n\nEXAMPLES:\n # From a live PostGraphile server\n stonecrop-schema generate -e http://localhost:5000/graphql -o ./schemas\n\n # From a saved introspection result\n stonecrop-schema generate -i introspection.json -o ./schemas\n\n # From an SDL file with custom scalars\n stonecrop-schema generate -s schema.graphql -o ./schemas \\\\\n --custom-scalars custom-scalars.json\n\n # Only convert specific types\n stonecrop-schema generate -e http://localhost:5000/graphql -o ./schemas \\\\\n --include \"User,Post,Comment\"\n`)\n}\n\nmain().catch(err => {\n\tconsole.error('Error:', err.message)\n\tprocess.exit(1)\n})\n"],"names":["fetchIntrospection","endpoint","headers","response","getIntrospectionQuery","json","e","main","values","positionals","parseArgs","command","printHelp","outputDir","resolve","options","s","overridesPath","overridesContent","readFileSync","scalarsPath","scalarsContent","source","filePath","content","parsed","doctypes","convertGraphQLSchema","existsSync","mkdirSync","warnings","errors","doctype","fileName","join","writeFileSync","validation","validateDoctype","unmappedFields","f","err"],"mappings":";;;;;;AAgCA,eAAeA,EAAmBC,GAAkBC,GAA+D;AAClH,QAAMC,IAAW,MAAM,MAAMF,GAAU;AAAA,IACtC,QAAQ;AAAA,IACR,SAAS;AAAA,MACR,gBAAgB;AAAA,MAChB,GAAGC;AAAA,IAAA;AAAA,IAEJ,MAAM,KAAK,UAAU;AAAA,MACpB,OAAOE,EAAA;AAAA,IAAsB,CAC7B;AAAA,EAAA,CACD;AAED,MAAI,CAACD,EAAS;AACb,UAAM,IAAI,MAAM,kCAAkCA,EAAS,MAAM,IAAIA,EAAS,UAAU,EAAE;AAG3F,QAAME,IAA2E,MAAMF,EAAS,KAAA;AAEhG,MAAIE,EAAK,QAAQ;AAChB,UAAM,IAAI,MAA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M,UAAUA,EAAI,OAAO,GACnC,QAAQ,KAAK,CAAC;AACf,CAAC;"}
@@ -0,0 +1,494 @@
1
+ import { z as e } from "zod";
2
+ import { isScalarType as x, isEnumType as N, isObjectType as T, isNonNullType as L, isListType as v, isNamedType as P, buildSchema as U, buildClientSchema as q } from "graphql";
3
+ const R = e.object({
4
+ /** The table view type */
5
+ view: e.enum(["list", "uncounted", "list-expansion", "tree", "gantt", "tree-gantt"]).optional(),
6
+ /** Allow the table to use the full width of its container */
7
+ fullWidth: e.boolean().optional(),
8
+ /** Default expansion state for tree views */
9
+ defaultTreeExpansion: e.enum(["root", "branch", "leaf"]).optional(),
10
+ /** Enable dependency graph connections for Gantt views */
11
+ dependencyGraph: e.boolean().optional()
12
+ }).meta({
13
+ title: "TableViewConfig",
14
+ description: "JSON-safe view configuration for table fields in doctype authoring"
15
+ }), V = [
16
+ "Data",
17
+ // Short text, varchar
18
+ "Text",
19
+ // Long text
20
+ "Int",
21
+ // Integer
22
+ "Float",
23
+ // Floating point (IEEE 754)
24
+ "Decimal",
25
+ // Arbitrary precision decimal
26
+ "Check",
27
+ // Boolean/checkbox
28
+ "Date",
29
+ // Date only
30
+ "Time",
31
+ // Time only
32
+ "Datetime",
33
+ // Date and time
34
+ "Duration",
35
+ // Time interval
36
+ "DateRange",
37
+ // Date range
38
+ "JSON",
39
+ // JSON data
40
+ "Code",
41
+ // Code/source (with syntax highlighting)
42
+ "Link",
43
+ // Reference to another doctype
44
+ "Attach",
45
+ // File attachment
46
+ "Currency",
47
+ // Currency value
48
+ "Quantity",
49
+ // Quantity with unit
50
+ "Select",
51
+ // Dropdown selection
52
+ "PrimaryKey"
53
+ // Primary key field — used by the middleware to identify the record's PK column
54
+ ], J = e.string().min(1).meta({
55
+ title: "StonecropFieldType",
56
+ description: "Semantic field types for Stonecrop doctypes, consistent across forms and tables"
57
+ });
58
+ function Q(t) {
59
+ return V.includes(t);
60
+ }
61
+ const W = {
62
+ // Text
63
+ Data: { component: "ATextInput", fieldtype: "Data" },
64
+ Text: { component: "ATextInput", fieldtype: "Text" },
65
+ // Numeric
66
+ Int: { component: "ANumericInput", fieldtype: "Int" },
67
+ Float: { component: "ANumericInput", fieldtype: "Float" },
68
+ Decimal: { component: "ADecimalInput", fieldtype: "Decimal" },
69
+ // Boolean
70
+ Check: { component: "ACheckbox", fieldtype: "Check" },
71
+ // Date/Time
72
+ Date: { component: "ADate", fieldtype: "Date" },
73
+ Time: { component: "ATimeInput", fieldtype: "Time" },
74
+ Datetime: { component: "ADatetimePicker", fieldtype: "Datetime" },
75
+ Duration: { component: "ADurationInput", fieldtype: "Duration" },
76
+ DateRange: { component: "ADateRangePicker", fieldtype: "DateRange" },
77
+ // Structured
78
+ JSON: { component: "ACodeEditor", fieldtype: "JSON" },
79
+ Code: { component: "ACodeEditor", fieldtype: "Code" },
80
+ // Relational
81
+ Link: { component: "ALink", fieldtype: "Link" },
82
+ // Files
83
+ Attach: { component: "AFileAttach", fieldtype: "Attach" },
84
+ // Specialized
85
+ Currency: { component: "ACurrencyInput", fieldtype: "Currency" },
86
+ Quantity: { component: "AQuantityInput", fieldtype: "Quantity" },
87
+ Select: { component: "ADropdown", fieldtype: "Select" },
88
+ // Identity — PK fields are typically hidden; no interactive component is needed
89
+ PrimaryKey: { component: "ATextInput", fieldtype: "PrimaryKey" }
90
+ };
91
+ function z(t) {
92
+ return W[t]?.component ?? "ATextInput";
93
+ }
94
+ function De(t) {
95
+ return Q(t) ? z(t) : "ATextInput";
96
+ }
97
+ const B = e.union([
98
+ e.string(),
99
+ // Link/Doctype target: "customer"
100
+ e.array(e.string()),
101
+ // Select choices: ["A", "B", "C"]
102
+ e.record(e.string(), e.unknown())
103
+ // Config: \{ precision: 10, scale: 2 \}
104
+ ]).meta({
105
+ title: "FieldOptions",
106
+ description: "Field options - flexible bag for type-specific configuration"
107
+ }), $ = e.looseObject({
108
+ /** Error message to display when validation fails */
109
+ errorMessage: e.string()
110
+ }).meta({
111
+ title: "FieldValidation",
112
+ description: "Validation configuration for form fields"
113
+ });
114
+ function G() {
115
+ const t = e.object({
116
+ kind: e.literal("field"),
117
+ fieldname: e.string().min(1),
118
+ fieldtype: J,
119
+ component: e.string().optional(),
120
+ label: e.string().optional(),
121
+ width: e.string().optional(),
122
+ align: e.enum(["left", "center", "right", "start", "end"]).optional(),
123
+ edit: e.boolean().optional(),
124
+ mask: e.string().optional(),
125
+ mode: e.enum(["edit", "read", "display"]).optional(),
126
+ options: B.optional(),
127
+ required: e.boolean().optional(),
128
+ readOnly: e.boolean().optional(),
129
+ hidden: e.boolean().optional(),
130
+ default: e.unknown().optional(),
131
+ validation: $.optional(),
132
+ cardinality: e.enum(["atMostOne", "one", "noneOrMany", "atLeastOne"]).optional()
133
+ }).meta({ title: "ValueField" }), n = e.object({
134
+ kind: e.literal("table"),
135
+ fieldname: e.string().min(1),
136
+ component: e.string().optional(),
137
+ label: e.string().optional(),
138
+ // Validates that each column has fieldname; allows all other ColumnSchema properties
139
+ columns: e.array(e.object({ fieldname: e.string().min(1) }).passthrough()),
140
+ config: R.optional(),
141
+ mode: e.enum(["edit", "read", "display"]).optional()
142
+ }).meta({ title: "TableField" });
143
+ let o = e.never();
144
+ const a = e.object({
145
+ kind: e.literal("fieldset"),
146
+ fieldname: e.string().min(1),
147
+ component: e.string().optional(),
148
+ label: e.string().optional(),
149
+ collapsible: e.boolean().optional(),
150
+ mode: e.enum(["edit", "read", "display"]).optional(),
151
+ schema: e.lazy(() => o.array())
152
+ }).meta({ title: "FieldsetField" });
153
+ return o = e.discriminatedUnion("kind", [t, a, n]), { ValueFieldSchema: t, TableFieldSchema: n, FieldsetFieldSchema: a, DoctypeFieldSchema: o };
154
+ }
155
+ const F = G(), be = F.ValueFieldSchema, ke = F.FieldsetFieldSchema, Ie = F.TableFieldSchema, k = F.DoctypeFieldSchema, K = e.enum(["atMostOne", "one", "noneOrMany", "atLeastOne"]).meta({
156
+ title: "Cardinality",
157
+ description: "Cardinality for relationship links between doctypes"
158
+ }), Y = e.object({
159
+ /** Fetch method type */
160
+ method: e.literal("sync"),
161
+ /** Optional limit on number of records to fetch */
162
+ limit: e.number().int().positive().optional()
163
+ }).meta({
164
+ title: "SyncFetch",
165
+ description: "Sync fetch strategy - data is fetched in the initial query"
166
+ }), Z = e.object({
167
+ /** Fetch method type */
168
+ method: e.literal("lazy")
169
+ }).meta({
170
+ title: "LazyFetch",
171
+ description: "Lazy fetch strategy - data is fetched on demand in a separate query"
172
+ }), H = e.object({
173
+ /** Fetch method type */
174
+ method: e.literal("custom"),
175
+ /** Serialized handler function to invoke */
176
+ handler: e.string()
177
+ }).meta({
178
+ title: "CustomFetch",
179
+ description: "Custom fetch strategy - uses a custom handler function"
180
+ }), X = e.discriminatedUnion("method", [Y, Z, H]).meta({
181
+ title: "FetchStrategy",
182
+ description: "Fetch strategy for link data loading"
183
+ }), ee = e.object({
184
+ /** Target doctype slug */
185
+ target: e.string().min(1),
186
+ /** Cardinality of the relationship */
187
+ cardinality: K,
188
+ /** Backlink fieldname on the target doctype that points back to this link */
189
+ backlink: e.string().optional(),
190
+ /** Override default rendering component (AForm for 1:1, ATable for 1:many) */
191
+ component: e.string().optional(),
192
+ /** Fieldname of the corresponding Link field in the fields array */
193
+ fieldname: e.string().min(1).optional(),
194
+ /** Fetch strategy for loading nested data */
195
+ fetch: X.optional(),
196
+ /** Whether to block workflow actions until nested data is loaded (default: true) */
197
+ blockWorkflows: e.boolean().optional()
198
+ }).meta({
199
+ title: "LinkDeclaration",
200
+ description: "Declares a relationship from one doctype to another"
201
+ }), te = e.object({
202
+ /** Display label for the action */
203
+ label: e.string().min(1),
204
+ /** Handler function name or path */
205
+ handler: e.string().min(1),
206
+ /** Fields that must have values before action can execute */
207
+ requiredFields: e.array(e.string()).optional(),
208
+ /** Workflow states where this action is available */
209
+ allowedStates: e.array(e.string()).optional(),
210
+ /** Whether to show a confirmation dialog */
211
+ confirm: e.boolean().optional(),
212
+ /** Additional arguments for the action */
213
+ args: e.record(e.string(), e.unknown()).optional()
214
+ }).meta({
215
+ title: "ActionDefinition",
216
+ description: "Action definition within a workflow"
217
+ }), ne = e.object({
218
+ /** List of workflow states */
219
+ states: e.array(e.string()).optional(),
220
+ /** Actions available in this workflow */
221
+ actions: e.record(e.string(), te).optional()
222
+ }).meta({
223
+ title: "WorkflowMeta",
224
+ description: "Workflow metadata - states and actions for a doctype"
225
+ }), _ = e.object({
226
+ /** Display name of the doctype */
227
+ name: e.string().min(1),
228
+ /** URL-friendly slug (kebab-case) */
229
+ slug: e.string().min(1).optional(),
230
+ /** Field definitions (including link fields with fieldtype: 'Link') */
231
+ fields: e.array(k),
232
+ /** Relationship links to other doctypes */
233
+ links: e.record(e.string(), ee).optional(),
234
+ /** Workflow configuration */
235
+ workflow: ne.optional(),
236
+ /** Parent doctype for inheritance */
237
+ inherits: e.string().optional()
238
+ }).meta({
239
+ title: "DoctypeMeta",
240
+ description: "Doctype metadata - complete definition of a doctype"
241
+ });
242
+ function Ce(t) {
243
+ const n = k.safeParse(t);
244
+ return n.success ? { success: !0, errors: [] } : {
245
+ success: !1,
246
+ errors: n.error.issues.map((o) => ({
247
+ path: o.path,
248
+ message: o.message
249
+ }))
250
+ };
251
+ }
252
+ function Le(t) {
253
+ const n = _.safeParse(t);
254
+ return n.success ? { success: !0, errors: [] } : {
255
+ success: !1,
256
+ errors: n.error.issues.map((o) => ({
257
+ path: o.path,
258
+ message: o.message
259
+ }))
260
+ };
261
+ }
262
+ function _e(t) {
263
+ return k.parse(t);
264
+ }
265
+ function we(t) {
266
+ return _.parse(t);
267
+ }
268
+ function Oe(t) {
269
+ return t.replace(/_([a-z])/g, (n, o) => o.toUpperCase());
270
+ }
271
+ function Me(t) {
272
+ return t.replace(/[A-Z]/g, (n) => `_${n.toLowerCase()}`);
273
+ }
274
+ function Ee(t) {
275
+ return t.split("_").map((n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()).join(" ");
276
+ }
277
+ function ie(t) {
278
+ const n = t.replace(/([A-Z])/g, " $1").trim();
279
+ return n.charAt(0).toUpperCase() + n.slice(1);
280
+ }
281
+ function oe(t) {
282
+ return t.split(/[-_\s]+/).map((n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()).join("");
283
+ }
284
+ function h(t) {
285
+ return t.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
286
+ }
287
+ function je(t) {
288
+ return t.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").toLowerCase();
289
+ }
290
+ const ae = {
291
+ String: { component: "ATextInput", fieldtype: "Data" },
292
+ Int: { component: "ANumericInput", fieldtype: "Int" },
293
+ Float: { component: "ANumericInput", fieldtype: "Float" },
294
+ Boolean: { component: "ACheckbox", fieldtype: "Check" },
295
+ ID: { component: "ATextInput", fieldtype: "Data" }
296
+ }, re = {
297
+ // Arbitrary precision / large numbers
298
+ BigFloat: { component: "ADecimalInput", fieldtype: "Decimal" },
299
+ BigDecimal: { component: "ADecimalInput", fieldtype: "Decimal" },
300
+ Decimal: { component: "ADecimalInput", fieldtype: "Decimal" },
301
+ BigInt: { component: "ANumericInput", fieldtype: "Int" },
302
+ Long: { component: "ANumericInput", fieldtype: "Int" },
303
+ // Identifiers
304
+ UUID: { component: "ATextInput", fieldtype: "Data" },
305
+ // Date / Time
306
+ DateTime: { component: "ADatetimePicker", fieldtype: "Datetime" },
307
+ Datetime: { component: "ADatetimePicker", fieldtype: "Datetime" },
308
+ Date: { component: "ADate", fieldtype: "Date" },
309
+ Time: { component: "ATimeInput", fieldtype: "Time" },
310
+ Interval: { component: "ADurationInput", fieldtype: "Duration" },
311
+ Duration: { component: "ADurationInput", fieldtype: "Duration" },
312
+ // Structured data
313
+ JSON: { component: "ACodeEditor", fieldtype: "JSON" },
314
+ JSONObject: { component: "ACodeEditor", fieldtype: "JSON" },
315
+ JsonNode: { component: "ACodeEditor", fieldtype: "JSON" }
316
+ }, le = /* @__PURE__ */ new Set(["Cursor"]);
317
+ function se(t) {
318
+ const n = { ...re };
319
+ for (const [o, a] of Object.entries(ae))
320
+ n[o] = a;
321
+ if (t)
322
+ for (const [o, a] of Object.entries(t))
323
+ n[o] = {
324
+ component: a.component ?? "ATextInput",
325
+ fieldtype: a.fieldtype ?? "Data"
326
+ };
327
+ return n;
328
+ }
329
+ const ce = [
330
+ "Connection",
331
+ "Edge",
332
+ "Input",
333
+ "Patch",
334
+ "Payload",
335
+ "Condition",
336
+ "Filter",
337
+ "OrderBy",
338
+ "Aggregate",
339
+ "AggregateResult",
340
+ "AggregateFilter",
341
+ "DeleteResponse",
342
+ "InsertResponse",
343
+ "UpdateResponse",
344
+ "MutationResponse"
345
+ ], pe = /* @__PURE__ */ new Set(["Query", "Mutation", "Subscription"]);
346
+ function de(t, n) {
347
+ if (t.startsWith("__") || pe.has(t) || t === "Node")
348
+ return !1;
349
+ for (const a of ce)
350
+ if (t.endsWith(a))
351
+ return !1;
352
+ const o = n.getFields();
353
+ return Object.keys(o).length !== 0;
354
+ }
355
+ const me = /* @__PURE__ */ new Set(["nodeId", "__typename", "clientMutationId"]);
356
+ function ue(t, n, o) {
357
+ return !me.has(t);
358
+ }
359
+ function b(t) {
360
+ let n = !1, o = !1, a = t;
361
+ if (L(a) && (n = !0, a = a.ofType), v(a) && (o = !0, a = a.ofType, L(a) && (a = a.ofType)), !P(a))
362
+ throw new Error(`Expected a named GraphQL type, got: ${String(a)}`);
363
+ return { namedType: a, required: n, isList: o };
364
+ }
365
+ function fe(t) {
366
+ const o = t.getFields().edges;
367
+ if (!o) return;
368
+ const { namedType: a, isList: r } = b(o.type);
369
+ if (!r || !T(a)) return;
370
+ const d = a.getFields().node;
371
+ if (!d) return;
372
+ const { namedType: m } = b(d.type);
373
+ if (T(m))
374
+ return m.name;
375
+ }
376
+ function ye(t, n, o, a = {}) {
377
+ const { namedType: r, required: y, isList: d } = b(n.type), m = se(a.customScalars), i = {
378
+ kind: "field",
379
+ fieldname: t,
380
+ label: ie(t),
381
+ component: "ATextInput",
382
+ fieldtype: "Data"
383
+ };
384
+ if (y && (i.required = !0), x(r)) {
385
+ if (le.has(r.name))
386
+ return i._unmapped = !0, a.includeUnmappedMeta && (i._graphqlType = r.name), i;
387
+ if (r.name === "ID") {
388
+ const u = oe(t);
389
+ if (o.has(u))
390
+ return i.component = "ALink", i.fieldtype = "Link", i.options = h(u), i;
391
+ }
392
+ const s = m[r.name];
393
+ return s ? (i.component = s.component, i.fieldtype = s.fieldtype) : (i._unmapped = !0, a.includeUnmappedMeta && (i._graphqlType = r.name)), i;
394
+ }
395
+ if (N(r))
396
+ return i.component = "ADropdown", i.fieldtype = "Select", i.options = r.getValues().map((s) => s.name), i;
397
+ if (T(r)) {
398
+ if (!d && o.has(r.name))
399
+ return i.component = "ALink", i.fieldtype = "Link", i.options = h(r.name), i;
400
+ const s = fe(r);
401
+ return s && o.has(s) ? (i.component = "ATable", i._isLink = !0, i.options = h(s), i.cardinality = "noneOrMany", delete i.fieldtype, i) : d && o.has(r.name) ? (i.component = "ATable", i._isLink = !0, i.options = h(r.name), i.cardinality = "noneOrMany", delete i.fieldtype, i) : (i._unmapped = !0, a.includeUnmappedMeta && (i._graphqlType = r.name), i);
402
+ }
403
+ return i._unmapped = !0, a.includeUnmappedMeta && (i._graphqlType = r.name), i;
404
+ }
405
+ function xe(t, n = {}) {
406
+ const o = ge(t), a = o.getTypeMap(), r = /* @__PURE__ */ new Set(), y = o.getQueryType(), d = o.getMutationType(), m = o.getSubscriptionType();
407
+ y && r.add(y.name), d && r.add(d.name), m && r.add(m.name);
408
+ const i = n.isEntityType ?? de, s = /* @__PURE__ */ new Set();
409
+ for (const [c, p] of Object.entries(a))
410
+ T(p) && (r.has(c) || i(c, p) && s.add(c));
411
+ let u = s;
412
+ if (n.include) {
413
+ const c = new Set(n.include);
414
+ u = new Set([...s].filter((p) => c.has(p)));
415
+ }
416
+ if (n.exclude) {
417
+ const c = new Set(n.exclude);
418
+ u = new Set([...u].filter((p) => !c.has(p)));
419
+ }
420
+ const w = n.isEntityField ?? ue, I = [];
421
+ for (const c of u) {
422
+ const p = a[c];
423
+ if (!T(p)) continue;
424
+ const O = p.getFields(), C = n.typeOverrides?.[c], M = Object.entries(O).filter(([l, g]) => w(l, g, p)).map(([l, g]) => {
425
+ if (n.classifyField) {
426
+ const f = n.classifyField(l, g, p);
427
+ if (f != null)
428
+ return {
429
+ kind: "field",
430
+ fieldname: l,
431
+ label: f.label ?? l,
432
+ component: f.component ?? "ATextInput",
433
+ fieldtype: f.fieldtype ?? "Data",
434
+ ...f
435
+ };
436
+ }
437
+ const S = ye(l, g, s, n);
438
+ return C?.[l] ? Object.assign(S, C[l]) : S;
439
+ }), A = {}, E = M.filter((l) => l._isLink && typeof l.options == "string" && l.cardinality ? (A[l.fieldname] = {
440
+ target: l.options,
441
+ cardinality: l.cardinality
442
+ }, !1) : !0).map((l) => {
443
+ if (!n.includeUnmappedMeta) {
444
+ const { _graphqlType: f, _unmapped: Te, _isLink: Se, ...j } = l;
445
+ return j;
446
+ }
447
+ const { _isLink: g, ...S } = l;
448
+ return S;
449
+ }), D = {
450
+ name: c,
451
+ slug: h(c),
452
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- safe: heuristics always set a fieldtype default ('Data'); the optional fieldtype on GraphQLConversionFieldMeta is for intermediate processing, not because output fields lack fieldtype
453
+ fields: E
454
+ };
455
+ Object.keys(A).length > 0 && (D.links = A), n.includeUnmappedMeta && (D._graphqlTypeName = c), I.push(D);
456
+ }
457
+ return I;
458
+ }
459
+ function ge(t) {
460
+ return typeof t == "string" ? U(t) : q(t);
461
+ }
462
+ export {
463
+ V as B,
464
+ k as D,
465
+ ke as F,
466
+ ae as G,
467
+ le as I,
468
+ J as S,
469
+ W as T,
470
+ be as V,
471
+ re as W,
472
+ Ie as a,
473
+ R as b,
474
+ se as c,
475
+ ie as d,
476
+ Me as e,
477
+ ye as f,
478
+ xe as g,
479
+ ue as h,
480
+ de as i,
481
+ z as j,
482
+ Q as k,
483
+ _e as l,
484
+ je as m,
485
+ Ee as n,
486
+ h as o,
487
+ we as p,
488
+ Ce as q,
489
+ De as r,
490
+ Oe as s,
491
+ oe as t,
492
+ Le as v
493
+ };
494
+ //# sourceMappingURL=index--rNo7Kel.js.map