@velastack/patterns 0.15.0 → 0.15.2
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/chunks/_page-BFUn0CG1.js +5 -0
- package/dist/chunks/{_page-6d3DCr0p.js.map → _page-BFUn0CG1.js.map} +1 -1
- package/dist/chunks/auth-pages-D8n8gfCL.js +311 -0
- package/dist/chunks/auth-pages-D8n8gfCL.js.map +1 -0
- package/dist/chunks/{collections-FKsKGtaH.js → collections-Daxlnbm0.js} +2 -2
- package/dist/chunks/{collections-FKsKGtaH.js.map → collections-Daxlnbm0.js.map} +1 -1
- package/dist/chunks/{constants-BHuzzsKu.js → constants-E1I-__KI.js} +20 -20
- package/dist/chunks/{constants-BHuzzsKu.js.map → constants-E1I-__KI.js.map} +1 -1
- package/dist/chunks/{currency.server-DRuEFc6D.js → currency.server-BkzwY17R.js} +2 -2
- package/dist/chunks/{currency.server-DRuEFc6D.js.map → currency.server-BkzwY17R.js.map} +1 -1
- package/dist/chunks/{env-vars-BcHu8247.js → env-vars-C3TSZc4f.js} +3 -3
- package/dist/chunks/{env-vars-BcHu8247.js.map → env-vars-C3TSZc4f.js.map} +1 -1
- package/dist/chunks/{generate-CXAKf1Hh.js → generate-CAYM7OUF.js} +2 -2
- package/dist/chunks/{generate-CXAKf1Hh.js.map → generate-CAYM7OUF.js.map} +1 -1
- package/dist/chunks/{generate-rcDj36TD.js → generate-CL7wG0ZC.js} +3 -3
- package/dist/chunks/{generate-rcDj36TD.js.map → generate-CL7wG0ZC.js.map} +1 -1
- package/dist/chunks/{generate-CkfJrlEg.js → generate-CbchamhA.js} +3 -3
- package/dist/chunks/{generate-CkfJrlEg.js.map → generate-CbchamhA.js.map} +1 -1
- package/dist/chunks/{generate-9O0VdZOl.js → generate-DI58vuk1.js} +2 -2
- package/dist/chunks/{generate-9O0VdZOl.js.map → generate-DI58vuk1.js.map} +1 -1
- package/dist/chunks/{generate-a3U8uDzW.js → generate-DR2wkVPY.js} +2 -2
- package/dist/chunks/{generate-a3U8uDzW.js.map → generate-DR2wkVPY.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BmdO8oKV.js → generate.runtime-B11mOr45.js} +3 -3
- package/dist/chunks/{generate.runtime-BmdO8oKV.js.map → generate.runtime-B11mOr45.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BDVPJJbh.js → generate.runtime-B1Y2JrGW.js} +5 -5
- package/dist/chunks/{generate.runtime-BDVPJJbh.js.map → generate.runtime-B1Y2JrGW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cxa24AOd.js → generate.runtime-B7VubPTW.js} +3 -3
- package/dist/chunks/{generate.runtime-Cxa24AOd.js.map → generate.runtime-B7VubPTW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DsW0Q5S5.js → generate.runtime-BCv4F1Wm.js} +5 -5
- package/dist/chunks/{generate.runtime-DsW0Q5S5.js.map → generate.runtime-BCv4F1Wm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-COo85dGX.js → generate.runtime-BEWp57Y7.js} +2 -2
- package/dist/chunks/{generate.runtime-COo85dGX.js.map → generate.runtime-BEWp57Y7.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BKsrh3ZN.js → generate.runtime-BH6hHygm.js} +3 -3
- package/dist/chunks/{generate.runtime-BKsrh3ZN.js.map → generate.runtime-BH6hHygm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D7EETq9M.js → generate.runtime-BL6DpWFI.js} +3 -3
- package/dist/chunks/{generate.runtime-D7EETq9M.js.map → generate.runtime-BL6DpWFI.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dp3x08St.js → generate.runtime-BRV9hIl5.js} +2 -2
- package/dist/chunks/{generate.runtime-Dp3x08St.js.map → generate.runtime-BRV9hIl5.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CGbSe_nd.js → generate.runtime-BRcP6sFt.js} +2 -2
- package/dist/chunks/{generate.runtime-CGbSe_nd.js.map → generate.runtime-BRcP6sFt.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DcBEbV-k.js → generate.runtime-Bhs7ttZS.js} +2 -2
- package/dist/chunks/{generate.runtime-DcBEbV-k.js.map → generate.runtime-Bhs7ttZS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BGLekCHZ.js → generate.runtime-BjrtdoYE.js} +2 -2
- package/dist/chunks/{generate.runtime-BGLekCHZ.js.map → generate.runtime-BjrtdoYE.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CtV9Gn9T.js → generate.runtime-Bo_s7gYB.js} +2 -2
- package/dist/chunks/{generate.runtime-CtV9Gn9T.js.map → generate.runtime-Bo_s7gYB.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CnGVlvxN.js → generate.runtime-Bs77Oc8P.js} +3 -3
- package/dist/chunks/{generate.runtime-CnGVlvxN.js.map → generate.runtime-Bs77Oc8P.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B5SP9iyN.js → generate.runtime-C3IswX7B.js} +2 -2
- package/dist/chunks/{generate.runtime-B5SP9iyN.js.map → generate.runtime-C3IswX7B.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DtcKbzOm.js → generate.runtime-C90_2L-8.js} +3 -3
- package/dist/chunks/{generate.runtime-DtcKbzOm.js.map → generate.runtime-C90_2L-8.js.map} +1 -1
- package/dist/chunks/{generate.runtime-As1It8o7.js → generate.runtime-CDY0Ot_t.js} +6 -6
- package/dist/chunks/{generate.runtime-As1It8o7.js.map → generate.runtime-CDY0Ot_t.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CI_rUVZo.js → generate.runtime-CZMVPVjS.js} +6 -6
- package/dist/chunks/{generate.runtime-CI_rUVZo.js.map → generate.runtime-CZMVPVjS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BYhWm9JA.js → generate.runtime-C_hrLPD4.js} +3 -3
- package/dist/chunks/{generate.runtime-BYhWm9JA.js.map → generate.runtime-C_hrLPD4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BKA41qV0.js → generate.runtime-CdZ3GzPS.js} +6 -6
- package/dist/chunks/{generate.runtime-BKA41qV0.js.map → generate.runtime-CdZ3GzPS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cqbsn5Ov.js → generate.runtime-ChSVP7cD.js} +6 -6
- package/dist/chunks/{generate.runtime-Cqbsn5Ov.js.map → generate.runtime-ChSVP7cD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BL7O2fy8.js → generate.runtime-Cs73i6Zf.js} +2 -2
- package/dist/chunks/{generate.runtime-BL7O2fy8.js.map → generate.runtime-Cs73i6Zf.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C7NexMXs.js → generate.runtime-D7KYlnvb.js} +3 -3
- package/dist/chunks/{generate.runtime-C7NexMXs.js.map → generate.runtime-D7KYlnvb.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CTQvLaU0.js → generate.runtime-DG9LRwbt.js} +3 -3
- package/dist/chunks/{generate.runtime-CTQvLaU0.js.map → generate.runtime-DG9LRwbt.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DiAnQ9MW.js → generate.runtime-DKL7VAAd.js} +6 -6
- package/dist/chunks/{generate.runtime-DiAnQ9MW.js.map → generate.runtime-DKL7VAAd.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DaJ4gLPv.js → generate.runtime-DP63Wwea.js} +4 -4
- package/dist/chunks/{generate.runtime-DaJ4gLPv.js.map → generate.runtime-DP63Wwea.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CFSBH8yG.js → generate.runtime-DRPxOLnB.js} +4 -4
- package/dist/chunks/{generate.runtime-CFSBH8yG.js.map → generate.runtime-DRPxOLnB.js.map} +1 -1
- package/dist/chunks/{generate.runtime-SZInujfP.js → generate.runtime-DW9bqOtC.js} +2 -2
- package/dist/chunks/{generate.runtime-SZInujfP.js.map → generate.runtime-DW9bqOtC.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cc5Aw1zc.js → generate.runtime-DdY44Ulv.js} +6 -6
- package/dist/chunks/{generate.runtime-Cc5Aw1zc.js.map → generate.runtime-DdY44Ulv.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BOtYaNA5.js → generate.runtime-DjEj-n6m.js} +7 -7
- package/dist/chunks/{generate.runtime-BOtYaNA5.js.map → generate.runtime-DjEj-n6m.js.map} +1 -1
- package/dist/chunks/{generate.runtime-ICaKVEuW.js → generate.runtime-DlAJQ5Js.js} +4 -4
- package/dist/chunks/{generate.runtime-ICaKVEuW.js.map → generate.runtime-DlAJQ5Js.js.map} +1 -1
- package/dist/chunks/{generate.runtime-4gS2ZHpj.js → generate.runtime-JftBoKYS.js} +5 -5
- package/dist/chunks/{generate.runtime-4gS2ZHpj.js.map → generate.runtime-JftBoKYS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B8t8HtB6.js → generate.runtime-_426A1Ij.js} +3 -3
- package/dist/chunks/{generate.runtime-B8t8HtB6.js.map → generate.runtime-_426A1Ij.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CyteiEzT.js → generate.runtime-fs6GEMx-.js} +5 -5
- package/dist/chunks/{generate.runtime-CyteiEzT.js.map → generate.runtime-fs6GEMx-.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B9U3kzHD.js → generate.runtime-jIlQ2GMh.js} +2 -2
- package/dist/chunks/{generate.runtime-B9U3kzHD.js.map → generate.runtime-jIlQ2GMh.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BY5VmBG4.js → generate.runtime-v3KCv1B6.js} +2 -2
- package/dist/chunks/{generate.runtime-BY5VmBG4.js.map → generate.runtime-v3KCv1B6.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CG3udLj8.js → generate.runtime-xrxAElb3.js} +3 -3
- package/dist/chunks/{generate.runtime-CG3udLj8.js.map → generate.runtime-xrxAElb3.js.map} +1 -1
- package/dist/chunks/{gitignore-CPardo4E.js → gitignore-CBiWFRif.js} +3 -3
- package/dist/chunks/{gitignore-CPardo4E.js.map → gitignore-CBiWFRif.js.map} +1 -1
- package/dist/chunks/{i18n-C8OfN_nr.js → i18n-Ho8H91Ze.js} +3 -3
- package/dist/chunks/{i18n-C8OfN_nr.js.map → i18n-Ho8H91Ze.js.map} +1 -1
- package/dist/chunks/{modify-file-DvIwtj4o.js → modify-file-BOEKlIDw.js} +2 -2
- package/dist/chunks/{modify-file-DvIwtj4o.js.map → modify-file-BOEKlIDw.js.map} +1 -1
- package/dist/chunks/{pocketbase-Ir-TPv7H.js → pocketbase-B2ksFrvH.js} +2 -2
- package/dist/chunks/{pocketbase-Ir-TPv7H.js.map → pocketbase-B2ksFrvH.js.map} +1 -1
- package/dist/chunks/{providers-B386TYCN.js → providers-BEjDonyG.js} +2 -2
- package/dist/chunks/{providers-B386TYCN.js.map → providers-BEjDonyG.js.map} +1 -1
- package/dist/chunks/{route-BJBV1DtX.js → route-9ZVJZkYu.js} +23 -19
- package/dist/chunks/route-9ZVJZkYu.js.map +1 -0
- package/dist/chunks/{schema-DSNYWlel.js → schema-DnMqw2Hn.js} +3 -3
- package/dist/chunks/{schema-DSNYWlel.js.map → schema-DnMqw2Hn.js.map} +1 -1
- package/dist/chunks/{shared-CZHopdly.js → shared-CSwGWMcN.js} +2 -2
- package/dist/chunks/{shared-CZHopdly.js.map → shared-CSwGWMcN.js.map} +1 -1
- package/dist/chunks/{shared-BofFBVmT.js → shared-Cdwm_-Nl.js} +40 -40
- package/dist/chunks/{shared-BofFBVmT.js.map → shared-Cdwm_-Nl.js.map} +1 -1
- package/dist/chunks/{site-B9-emR6D.js → site-B5zrFba9.js} +2 -2
- package/dist/chunks/{site-B9-emR6D.js.map → site-B5zrFba9.js.map} +1 -1
- package/dist/chunks/{table-core-CHsfbi-n.js → table-core-ux1xEJxN.js} +2 -2
- package/dist/chunks/{table-core-CHsfbi-n.js.map → table-core-ux1xEJxN.js.map} +1 -1
- package/dist/chunks/{translations-CiJnl574.js → translations-B5hX0Qq-.js} +5 -2
- package/dist/chunks/{translations-CiJnl574.js.map → translations-B5hX0Qq-.js.map} +1 -1
- package/dist/chunks/{ui-BUhkIHse.js → ui-CpjUq_lm.js} +3 -3
- package/dist/chunks/{ui-BUhkIHse.js.map → ui-CpjUq_lm.js.map} +1 -1
- package/dist/chunks/{whatsapp-DFZUsKWe.js → whatsapp-DOSZ_zwn.js} +2 -2
- package/dist/chunks/{whatsapp-DFZUsKWe.js.map → whatsapp-DOSZ_zwn.js.map} +1 -1
- package/dist/chunks/{write-result-Bkdkp7u2.js → write-result-DlB-id5k.js} +50 -26
- package/dist/chunks/write-result-DlB-id5k.js.map +1 -0
- package/dist/index.js +1864 -1842
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/_page-6d3DCr0p.js +0 -5
- package/dist/chunks/auth-pages-DHzh31mw.js +0 -285
- package/dist/chunks/auth-pages-DHzh31mw.js.map +0 -1
- package/dist/chunks/route-BJBV1DtX.js.map +0 -1
- package/dist/chunks/write-result-Bkdkp7u2.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-9ZVJZkYu.js","names":["changeCase.kebabCase","InvalidArgumentError","SPLIT_LOWER_UPPER_RE","SPLIT_UPPER_UPPER_RE","SPLIT_SEPARATE_NUMBER_RE","DEFAULT_STRIP_REGEXP","SPLIT_REPLACE_VALUE","DEFAULT_PREFIX_SUFFIX_CHARACTERS","split","result","value","start","end","splitSeparateNumbers","words","i","word","match","offset","noCase","prefix","suffix","splitPrefixSuffix","input","options","lowerFactory","camelCase","lower","upper","upperFactory","transform","capitalCaseTransformFactory","pascalCaseTransformFactory","index","pascalCase","capitalCase","kebabCase","snakeCase","locale","char0","splitFn","prefixCharacters","suffixCharacters","prefixIndex","suffixIndex","char","ROUTES_ROOT","DYNAMIC_PARAM_RE","VALID_SEGMENT_RE","defaultGroup","groups","routeGroups","features","isProtectedRoute","app","route","routeFileBase","group","defaultRouteSegment","kind","model","stripRouteGroups","filePath","segment","extractDynamicParams","params","validateRouteInput","segments","hasRouteGroup","parseRoute","routeInput","fileBase","scaffoldFilePaths","scaffoldUrls"],"sources":["../../node_modules/change-case/dist/index.js","../../src/parse/route.ts"],"sourcesContent":["// Regexps involved with splitting words in various case formats.\nconst SPLIT_LOWER_UPPER_RE = /([\\p{Ll}\\d])(\\p{Lu})/gu;\nconst SPLIT_UPPER_UPPER_RE = /(\\p{Lu})([\\p{Lu}][\\p{Ll}])/gu;\n// Used to iterate over the initial split result and separate numbers.\nconst SPLIT_SEPARATE_NUMBER_RE = /(\\d)\\p{Ll}|(\\p{L})\\d/u;\n// Regexp involved with stripping non-word characters from the result.\nconst DEFAULT_STRIP_REGEXP = /[^\\p{L}\\d]+/giu;\n// The replacement value for splits.\nconst SPLIT_REPLACE_VALUE = \"$1\\0$2\";\n// The default characters to keep after transforming case.\nconst DEFAULT_PREFIX_SUFFIX_CHARACTERS = \"\";\n/**\n * Split any cased input strings into an array of words.\n */\nexport function split(value) {\n let result = value.trim();\n result = result\n .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)\n .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);\n result = result.replace(DEFAULT_STRIP_REGEXP, \"\\0\");\n let start = 0;\n let end = result.length;\n // Trim the delimiter from around the output string.\n while (result.charAt(start) === \"\\0\")\n start++;\n if (start === end)\n return [];\n while (result.charAt(end - 1) === \"\\0\")\n end--;\n return result.slice(start, end).split(/\\0/g);\n}\n/**\n * Split the input string into an array of words, separating numbers.\n */\nexport function splitSeparateNumbers(value) {\n const words = split(value);\n for (let i = 0; i < words.length; i++) {\n const word = words[i];\n const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);\n if (match) {\n const offset = match.index + (match[1] ?? match[2]).length;\n words.splice(i, 1, word.slice(0, offset), word.slice(offset));\n }\n }\n return words;\n}\n/**\n * Convert a string to space separated lower case (`foo bar`).\n */\nexport function noCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (prefix +\n words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to camel case (`fooBar`).\n */\nexport function camelCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return (prefix +\n words\n .map((word, index) => {\n if (index === 0)\n return lower(word);\n return transform(word, index);\n })\n .join(options?.delimiter ?? \"\") +\n suffix);\n}\n/**\n * Convert a string to pascal case (`FooBar`).\n */\nexport function pascalCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return prefix + words.map(transform).join(options?.delimiter ?? \"\") + suffix;\n}\n/**\n * Convert a string to pascal snake case (`Foo_Bar`).\n */\nexport function pascalSnakeCase(input, options) {\n return capitalCase(input, { delimiter: \"_\", ...options });\n}\n/**\n * Convert a string to capital case (`Foo Bar`).\n */\nexport function capitalCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n return (prefix +\n words\n .map(capitalCaseTransformFactory(lower, upper))\n .join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to constant case (`FOO_BAR`).\n */\nexport function constantCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (prefix +\n words.map(upperFactory(options?.locale)).join(options?.delimiter ?? \"_\") +\n suffix);\n}\n/**\n * Convert a string to dot case (`foo.bar`).\n */\nexport function dotCase(input, options) {\n return noCase(input, { delimiter: \".\", ...options });\n}\n/**\n * Convert a string to kebab case (`foo-bar`).\n */\nexport function kebabCase(input, options) {\n return noCase(input, { delimiter: \"-\", ...options });\n}\n/**\n * Convert a string to path case (`foo/bar`).\n */\nexport function pathCase(input, options) {\n return noCase(input, { delimiter: \"/\", ...options });\n}\n/**\n * Convert a string to path case (`Foo bar`).\n */\nexport function sentenceCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = capitalCaseTransformFactory(lower, upper);\n return (prefix +\n words\n .map((word, index) => {\n if (index === 0)\n return transform(word);\n return lower(word);\n })\n .join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to snake case (`foo_bar`).\n */\nexport function snakeCase(input, options) {\n return noCase(input, { delimiter: \"_\", ...options });\n}\n/**\n * Convert a string to header case (`Foo-Bar`).\n */\nexport function trainCase(input, options) {\n return capitalCase(input, { delimiter: \"-\", ...options });\n}\nfunction lowerFactory(locale) {\n return locale === false\n ? (input) => input.toLowerCase()\n : (input) => input.toLocaleLowerCase(locale);\n}\nfunction upperFactory(locale) {\n return locale === false\n ? (input) => input.toUpperCase()\n : (input) => input.toLocaleUpperCase(locale);\n}\nfunction capitalCaseTransformFactory(lower, upper) {\n return (word) => `${upper(word[0])}${lower(word.slice(1))}`;\n}\nfunction pascalCaseTransformFactory(lower, upper) {\n return (word, index) => {\n const char0 = word[0];\n const initial = index > 0 && char0 >= \"0\" && char0 <= \"9\" ? \"_\" + char0 : upper(char0);\n return initial + lower(word.slice(1));\n };\n}\nfunction splitPrefixSuffix(input, options = {}) {\n const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);\n const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n let prefixIndex = 0;\n let suffixIndex = input.length;\n while (prefixIndex < input.length) {\n const char = input.charAt(prefixIndex);\n if (!prefixCharacters.includes(char))\n break;\n prefixIndex++;\n }\n while (suffixIndex > prefixIndex) {\n const index = suffixIndex - 1;\n const char = input.charAt(index);\n if (!suffixCharacters.includes(char))\n break;\n suffixIndex = index;\n }\n return [\n input.slice(0, prefixIndex),\n splitFn(input.slice(prefixIndex, suffixIndex)),\n input.slice(suffixIndex),\n ];\n}\n//# sourceMappingURL=index.js.map","import * as changeCase from \"change-case\";\nimport { APP_DIR, PUBLIC_DIR } from \"../core/constants\";\nimport { InvalidArgumentError } from \"../core/errors\";\nimport type { Options } from \"../core/types\";\nimport type {\n Model,\n RouteInfo,\n RouteKind,\n ScaffoldFilePaths,\n ScaffoldUrls,\n} from \"./types\";\n\nconst ROUTES_ROOT = \"src/routes\";\nconst DYNAMIC_PARAM_RE = /\\[([^\\]]+)\\]/g;\nconst VALID_SEGMENT_RE = /^[a-zA-Z0-9_\\-[\\]()]+$/;\n\ntype RouteOptions = Pick<Options, \"features\" | \"routeGroups\">;\n\n/**\n * The group a route lands in when none is given, or null for a project that\n * has no such group. Without `routeGroups` this is the vela layout.\n */\nexport function defaultGroup({\n features,\n routeGroups,\n}: RouteOptions): string | null {\n const groups = routeGroups ?? { public: PUBLIC_DIR, app: APP_DIR };\n return features.auth ? (groups.app ?? groups.public) : groups.public;\n}\n\n/**\n * Whether a route is in the group that needs a session (`(app)`), in a\n * project with auth: `protectedRoutes` covers its pages, form actions and\n * endpoints. It does not cover a remote function written there, which is why\n * the generators ask: such a function checks the session itself.\n */\nexport function isProtectedRoute(\n route: { fileBase: string },\n { features, routeGroups }: RouteOptions,\n): boolean {\n const app = (routeGroups ?? { app: APP_DIR }).app;\n return Boolean(\n features.auth && app && route.fileBase.split(\"/\").includes(app),\n );\n}\n\nfunction routeFileBase(group: string | null, route: string): string {\n return [ROUTES_ROOT, group, route].filter(Boolean).join(\"/\");\n}\n\nfunction defaultRouteSegment(model: Model, kind: RouteKind): string {\n return kind === \"scaffold\"\n ? changeCase.kebabCase(model.pluralDisplayName)\n : changeCase.kebabCase(model.displayName);\n}\n\nfunction stripRouteGroups(filePath: string): string {\n const withoutRoot = filePath.startsWith(`${ROUTES_ROOT}/`)\n ? filePath.slice(ROUTES_ROOT.length + 1)\n : filePath;\n const segments = withoutRoot.split(\"/\").filter((segment) => {\n return !(segment.startsWith(\"(\") && segment.endsWith(\")\"));\n });\n return `/${segments.join(\"/\")}`;\n}\n\nfunction extractDynamicParams(filePath: string): string[] {\n const params: string[] = [];\n for (const match of filePath.matchAll(DYNAMIC_PARAM_RE)) {\n params.push(match[1]);\n }\n return params;\n}\n\nfunction validateRouteInput(input: string): void {\n if (input.startsWith(\"/\")) {\n throw new InvalidArgumentError(\n `Route must not start with \"/\". Got: \"${input}\"`,\n );\n }\n if (input.startsWith(`${ROUTES_ROOT}/`) || input === ROUTES_ROOT) {\n throw new InvalidArgumentError(\n `Route must not start with \"${ROUTES_ROOT}/\" — paths are rooted there automatically. Got: \"${input}\"`,\n );\n }\n const segments = input.split(\"/\");\n for (const segment of segments) {\n if (segment.length === 0) {\n throw new InvalidArgumentError(\n `Route must not contain empty segments. Got: \"${input}\"`,\n );\n }\n if (segment === \".\" || segment === \"..\") {\n throw new InvalidArgumentError(\n `Route must not contain \".\" or \"..\" segments. Got: \"${input}\"`,\n );\n }\n if (segment.startsWith(\"_\")) {\n throw new InvalidArgumentError(\n `Route segments must not start with underscore. Got: \"${segment}\"`,\n );\n }\n if (!VALID_SEGMENT_RE.test(segment)) {\n throw new InvalidArgumentError(\n `Route segment \"${segment}\" contains invalid characters. Allowed: letters, digits, underscore, dash, brackets, parentheses.`,\n );\n }\n }\n}\n\nfunction hasRouteGroup(input: string): boolean {\n return input\n .split(\"/\")\n .some((segment) => segment.startsWith(\"(\") && segment.endsWith(\")\"));\n}\n\nexport function parseRoute(\n routeInput: string | undefined,\n model: Model,\n options: RouteOptions,\n kind: RouteKind,\n): RouteInfo {\n if (routeInput === undefined || routeInput === \"\") {\n const segment = defaultRouteSegment(model, kind);\n const fileBase = routeFileBase(defaultGroup(options), segment);\n return {\n fileBase,\n urlBase: stripRouteGroups(fileBase),\n dynamicParams: extractDynamicParams(fileBase),\n };\n }\n\n validateRouteInput(routeInput);\n\n const fileBase = routeFileBase(\n hasRouteGroup(routeInput) ? null : defaultGroup(options),\n routeInput,\n );\n\n return {\n fileBase,\n urlBase: stripRouteGroups(fileBase),\n dynamicParams: extractDynamicParams(fileBase),\n };\n}\n\nexport function scaffoldFilePaths(route: RouteInfo): ScaffoldFilePaths {\n return {\n list: route.fileBase,\n new: `${route.fileBase}/new`,\n show: `${route.fileBase}/[id]`,\n edit: `${route.fileBase}/[id]/edit`,\n };\n}\n\nexport function scaffoldUrls(route: RouteInfo): ScaffoldUrls {\n return {\n list: route.urlBase,\n new: `${route.urlBase}/new`,\n show: `${route.urlBase}/[id]`,\n edit: `${route.urlBase}/[id]/edit`,\n };\n}\n"],"ignoreList":[0],"mappings":";;;AACA,IAAME,IAAuB,0BACvBC,IAAuB,gCAEvBC,IAA2B,yBAE3BC,IAAuB,kBAEvBC,IAAsB,UAEtBC,IAAmC;AAIzC,SAAgBC,EAAM,GAAO;CACzB,IAAIC,IAASC,EAAM,KAAK;CAIxB,AAHA,IAASD,EACJ,QAAQP,GAAsBI,CAAmB,CAAC,CAClD,QAAQH,GAAsBG,CAAmB,GACtD,IAASG,EAAO,QAAQJ,GAAsB,IAAI;CAClD,IAAIM,IAAQ,GACRC,IAAMH,EAAO;CAEjB,OAAOA,EAAO,OAAOE,CAAK,MAAM,OAC5B;CACJ,IAAIA,MAAUC,GACV,OAAO,CAAC;CACZ,OAAOH,EAAO,OAAOG,IAAM,CAAC,MAAM,OAC9B;CACJ,OAAOH,EAAO,MAAME,GAAOC,CAAG,CAAC,CAAC,MAAM,KAAK;AAC/C;AAIA,SAAgBC,EAAqB,GAAO;CACxC,IAAMC,IAAQN,EAAME,CAAK;CACzB,KAAK,IAAIK,IAAI,GAAGA,IAAID,EAAM,QAAQ,KAAK;EACnC,IAAME,IAAOF,EAAMC,IACbE,IAAQb,EAAyB,KAAKY,CAAI;EAChD,IAAIC,GAAO;GACP,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B,IAAMC,IAAWf,EACfY,EAAcE,CAAU,IAAI,OAAOrB,EAAazB,CAAO,GACvD8C,CACF;CAEA,OAAO;EACL;EACA,SAAST,EAAiBU,CAAQ;EAClC,eAAeP,EAAqBO,CAAQ;CAC9C;AACF;AAEA,SAAgBC,EAAkB,GAAqC;CACrE,OAAO;EACL,MAAMjB,EAAM;EACZ,KAAK,GAAGA,EAAM,SAAS;EACvB,MAAM,GAAGA,EAAM,SAAS;EACxB,MAAM,GAAGA,EAAM,SAAS;CAC1B;AACF;AAEA,SAAgBkB,EAAa,GAAgC;CAC3D,OAAO;EACL,MAAMlB,EAAM;EACZ,KAAK,GAAGA,EAAM,QAAQ;EACtB,MAAM,GAAGA,EAAM,QAAQ;EACvB,MAAM,GAAGA,EAAM,QAAQ;CACzB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as e } from "./shared-
|
|
2
|
-
import { r as t } from "./modify-file-
|
|
1
|
+
import { d as e } from "./shared-Cdwm_-Nl.js";
|
|
2
|
+
import { r as t } from "./modify-file-BOEKlIDw.js";
|
|
3
3
|
import { o as n } from "./ts-morph-helpers-B4KZXP44.js";
|
|
4
4
|
import r from "node:fs";
|
|
5
5
|
import i from "node:path";
|
|
@@ -113,4 +113,4 @@ function g(n, { model: a, added: o, changes: s }) {
|
|
|
113
113
|
}
|
|
114
114
|
export { g as modifySchemaForMigration };
|
|
115
115
|
|
|
116
|
-
//# sourceMappingURL=schema-
|
|
116
|
+
//# sourceMappingURL=schema-DnMqw2Hn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-DSNYWlel.js","names":["schemaEntriesForFields","modifyOutcomeToFile","formatLikeSource","fs","path","KEY_SUFFIXES","propertyKey","name","unquote","findZodObject","declarations","sourceFile","candidates","d","schemaName","found","declaration","node","Node","callee","shape","findProperty","property","describeChange","change","entry","applyChange","changed","suffix","to","modifySchema","schemaPath","changes","Project","backsRemoteForm","routes","root","imported","modelName","file","modifySchemaForMigration","model","schemaChanges","added"],"sources":["../../src/patterns/generate/migration/modifies/schema.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n Node,\n Project,\n SyntaxKind,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n type ShorthandPropertyAssignment,\n type SourceFile,\n} from \"ts-morph\";\nimport { schemaEntriesForFields } from \"../../../../core/shared\";\nimport type { File, ModifyOutcome } from \"../../../../core/types\";\nimport { modifyOutcomeToFile } from \"../../../../runtime/modify-file\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ResolvedMigration } from \"../generate\";\n\n/** One key of a zod object: its name and the schema it is given. */\nexport interface SchemaEntry {\n name: string;\n schema: string;\n}\n\n/**\n * What a migration did to a collection, as it applies to the zod schema that\n * describes it. An `add` carries every key its field needs (a multi-file\n * field has three); `remove` and `rename` name the field, and take its\n * `name+` / `name-` keys along.\n */\nexport type SchemaChange =\n | { op: \"add\"; entries: SchemaEntry[] }\n | { op: \"remove\"; fieldName: string }\n | { op: \"rename\"; from: string; to: string };\n\n/** The keys a field may have in a schema: its own, and a multi-file field's two. */\nconst KEY_SUFFIXES = [\"\", \"+\", \"-\"];\n\nfunction propertyKey(name: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name) ? name : `'${name}'`;\n}\n\nfunction unquote(name: string): string {\n return name.replace(/^([\"'`])(.*)\\1$/, \"$2\");\n}\n\n/**\n * The object literal of `export const <name> = z.object({ ... })`, through a\n * trailing `satisfies` / `as` and any methods chained on (`.strict()`,\n * `.refine(...)`).\n */\nfunction findZodObject(\n sourceFile: SourceFile,\n schemaName: string,\n): ObjectLiteralExpression | undefined {\n const declarations = sourceFile.getVariableDeclarations();\n const candidates = [\n ...declarations.filter((d) => d.getName() === schemaName),\n ...declarations.filter((d) => d.getName() !== schemaName),\n ];\n\n const found: ObjectLiteralExpression[] = [];\n for (const declaration of candidates) {\n let node: Node | undefined = declaration.getInitializer();\n while (node) {\n if (\n Node.isSatisfiesExpression(node) ||\n Node.isAsExpression(node) ||\n Node.isParenthesizedExpression(node)\n ) {\n node = node.getExpression();\n continue;\n }\n if (!Node.isCallExpression(node)) break;\n const callee = node.getExpression();\n if (\n Node.isPropertyAccessExpression(callee) &&\n callee.getName() === \"object\" &&\n callee.getExpression().getText() === \"z\"\n ) {\n const [shape] = node.getArguments();\n if (shape && Node.isObjectLiteralExpression(shape)) found.push(shape);\n break;\n }\n // `<something>.method(...)`: look at what the method was called on.\n node = Node.isPropertyAccessExpression(callee)\n ? callee.getExpression()\n : undefined;\n }\n // The schema under its generated name wins; otherwise the file has to\n // hold exactly one, or there is no telling which the collection's is.\n if (declaration.getName() === schemaName && found.length === 1) {\n return found[0];\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n\nfunction findProperty(\n shape: ObjectLiteralExpression,\n name: string,\n): PropertyAssignment | ShorthandPropertyAssignment | undefined {\n return shape\n .getProperties()\n .filter(\n (property) =>\n Node.isPropertyAssignment(property) ||\n Node.isShorthandPropertyAssignment(property),\n )\n .find((property) => unquote(property.getName()) === name);\n}\n\n/** What the user would write to make the change by hand. */\nfunction describeChange(change: SchemaChange): string {\n if (change.op === \"add\") {\n return change.entries\n .map((entry) => `add \\`${propertyKey(entry.name)}: ${entry.schema}\\``)\n .join(\", \");\n }\n if (change.op === \"remove\") return `remove \\`${change.fieldName}\\``;\n return `rename \\`${change.from}\\` to \\`${change.to}\\``;\n}\n\nfunction applyChange(\n shape: ObjectLiteralExpression,\n change: SchemaChange,\n): boolean {\n let changed = false;\n\n if (change.op === \"add\") {\n for (const entry of change.entries) {\n // Already there: added by hand, most likely. Theirs stands.\n if (findProperty(shape, entry.name)) continue;\n shape.addPropertyAssignment({\n name: propertyKey(entry.name),\n initializer: entry.schema,\n });\n changed = true;\n }\n return changed;\n }\n\n for (const suffix of KEY_SUFFIXES) {\n const name =\n (change.op === \"remove\" ? change.fieldName : change.from) + suffix;\n const property = findProperty(shape, name);\n if (!property) continue;\n\n if (change.op === \"remove\") {\n property.remove();\n changed = true;\n continue;\n }\n\n const to = change.to + suffix;\n if (findProperty(shape, to)) continue;\n if (Node.isPropertyAssignment(property)) {\n property.getNameNode().replaceWithText(propertyKey(to));\n } else {\n // `{ title }` → `{ heading: title }`: the value keeps its name.\n property.replaceWithText(`${propertyKey(to)}: ${property.getName()}`);\n }\n changed = true;\n }\n return changed;\n}\n\n/**\n * Brings the zod schema of a collection in line with a migration just applied\n * to it: `generate resource` and the scaffolds write the schema once, and a\n * field added later is optional, so nothing else notices it is missing.\n *\n * Only the keys the migration names are touched. A file without a\n * recognisable `z.object({ ... })` is left as it is and reported, with the\n * edit to make by hand.\n */\nexport function modifySchema(\n schemaPath: string,\n schemaName: string,\n changes: SchemaChange[],\n): ModifyOutcome {\n if (!fs.existsSync(schemaPath) || changes.length === 0) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n skipFileDependencyResolution: true,\n });\n const sourceFile = project.addSourceFileAtPath(schemaPath);\n const shape = findZodObject(sourceFile, schemaName);\n\n if (!shape) {\n return {\n status: \"failed\",\n message: `The collection changed, but no \\`z.object({ ... })\\` schema was found in this file to change with it. Update it by hand: ${changes.map(describeChange).join(\"; \")}.`,\n };\n }\n\n let changed = false;\n for (const change of changes) {\n changed = applyChange(shape, change) || changed;\n }\n if (!changed) {\n return { status: \"success\", changed: false };\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n\n/**\n * Whether a remote form validates with the model's schema. Its json fields\n * are then typed as the text a textarea posts, not `z.any()`; see\n * `generateSchemaSnippet`.\n */\nfunction backsRemoteForm(root: string, modelName: string): boolean {\n const routes = path.join(root, \"src\", \"routes\");\n if (!fs.existsSync(routes)) return false;\n const imported = new RegExp(`lib/schemas/${modelName}(\\\\.js|\\\\.ts)?[\"']`);\n return fs\n .readdirSync(routes, { recursive: true, encoding: \"utf8\" })\n .filter((file) => file.endsWith(\".remote.ts\"))\n .some((file) =>\n imported.test(fs.readFileSync(path.join(routes, file), \"utf8\")),\n );\n}\n\n/**\n * `modifySchema` for a migration the generator just applied, on the schema\n * file `generate resource` and the scaffolds write for its collection. `null`\n * when there is nothing to report: no such file, or nothing to change in it.\n */\nexport function modifySchemaForMigration(\n root: string,\n { model, added, changes }: ResolvedMigration,\n): File | null {\n const schemaPath = path.join(\n root,\n \"src\",\n \"lib\",\n \"schemas\",\n `${model.name}.ts`,\n );\n if (!fs.existsSync(schemaPath)) return null;\n\n const schemaChanges: SchemaChange[] = [];\n if (added.length > 0) {\n schemaChanges.push({\n op: \"add\",\n entries: schemaEntriesForFields(added, {\n forForm: true,\n remote: backsRemoteForm(root, model.name),\n }),\n });\n }\n for (const change of changes) {\n if (change.op !== \"add\") schemaChanges.push(change);\n }\n\n return modifyOutcomeToFile(\n schemaPath,\n modifySchema(schemaPath, model.schemaName, schemaChanges),\n );\n}\n"],"mappings":";;;;;;;AAmCA,IAAMK,IAAe;CAAC;CAAI;CAAK;AAAG;AAElC,SAASC,EAAY,GAAsB;CACzC,OAAO,6BAA6B,KAAKC,CAAI,IAAIA,IAAO,IAAIA,EAAK;AACnE;AAEA,SAASC,EAAQ,GAAsB;CACrC,OAAOD,EAAK,QAAQ,mBAAmB,IAAI;AAC7C;AAOA,SAASE,EACP,GACA,GACqC;CACrC,IAAMC,IAAeC,EAAW,wBAAwB,GAClDC,IAAa,CACjB,GAAGF,EAAa,QAAQ,MAAMG,EAAE,QAAQ,MAAMC,CAAU,GACxD,GAAGJ,EAAa,QAAQ,MAAMG,EAAE,QAAQ,MAAMC,CAAU,CAC1D,GAEMC,IAAmC,CAAC;CAC1C,KAAK,IAAMC,KAAeJ,GAAY;EACpC,IAAIK,IAAyBD,EAAY,eAAe;EACxD,OAAOC,IAAM;GACX,IACEC,EAAK,sBAAsBD,CAAI,KAC/BC,EAAK,eAAeD,CAAI,KACxBC,EAAK,0BAA0BD,CAAI,GACnC;IACA,IAAOA,E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AAO,QAAQ;CAC9C,IAAI,CAACjC,EAAG,WAAWgC,CAAM,GAAG,OAAO;CACnC,IAAME,IAAe,OAAO,eAAeC,EAAU,mBAAmB;CACxE,OAAOnC,EACJ,YAAYgC,GAAQ;EAAE,WAAW;EAAM,UAAU;CAAO,CAAC,CAAC,CAC1D,QAAQ,MAASI,EAAK,SAAS,YAAY,CAAC,CAAC,CAC7C,MAAM,MACLF,EAAS,KAAKlC,EAAG,aAAaC,EAAK,KAAK+B,GAAQI,CAAI,GAAG,MAAM,CAAC,CAChE;AACJ;AAOA,SAAgBC,EACd,GACA,EAAE,UAAO,UAAO,cACH;CACb,IAAMT,IAAa3B,EAAK,KACtBgC,GACA,OACA,OACA,WACA,GAAGK,EAAM,KAAK,IAChB;CACA,IAAI,CAACtC,EAAG,WAAW4B,CAAU,GAAG,OAAO;CAEvC,IAAMW,IAAgC,CAAC;CACvC,AAAIC,EAAM,SAAS,KACjBD,EAAc,KAAK;EACjB,IAAI;EACJ,SAAS1C,EAAuB2C,GAAO;GACrC,SAAS;GACT,QAAQT,EAAgBE,GAAMK,EAAM,IAAI;EAC1C,CAAC;CACH,CAAC;CAEH,KAAK,IAAMjB,KAAUQ,GACnB,AAAIR,EAAO,OAAO,SAAOkB,EAAc,KAAKlB,CAAM;CAGpD,OAAOvB,EACL8B,GACAD,EAAaC,GAAYU,EAAM,YAAYC,CAAa,CAC1D;AACF"}
|
|
1
|
+
{"version":3,"file":"schema-DnMqw2Hn.js","names":["schemaEntriesForFields","modifyOutcomeToFile","formatLikeSource","fs","path","KEY_SUFFIXES","propertyKey","name","unquote","findZodObject","declarations","sourceFile","candidates","d","schemaName","found","declaration","node","Node","callee","shape","findProperty","property","describeChange","change","entry","applyChange","changed","suffix","to","modifySchema","schemaPath","changes","Project","backsRemoteForm","routes","root","imported","modelName","file","modifySchemaForMigration","model","schemaChanges","added"],"sources":["../../src/patterns/generate/migration/modifies/schema.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n Node,\n Project,\n SyntaxKind,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n type ShorthandPropertyAssignment,\n type SourceFile,\n} from \"ts-morph\";\nimport { schemaEntriesForFields } from \"../../../../core/shared\";\nimport type { File, ModifyOutcome } from \"../../../../core/types\";\nimport { modifyOutcomeToFile } from \"../../../../runtime/modify-file\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ResolvedMigration } from \"../generate\";\n\n/** One key of a zod object: its name and the schema it is given. */\nexport interface SchemaEntry {\n name: string;\n schema: string;\n}\n\n/**\n * What a migration did to a collection, as it applies to the zod schema that\n * describes it. An `add` carries every key its field needs (a multi-file\n * field has three); `remove` and `rename` name the field, and take its\n * `name+` / `name-` keys along.\n */\nexport type SchemaChange =\n | { op: \"add\"; entries: SchemaEntry[] }\n | { op: \"remove\"; fieldName: string }\n | { op: \"rename\"; from: string; to: string };\n\n/** The keys a field may have in a schema: its own, and a multi-file field's two. */\nconst KEY_SUFFIXES = [\"\", \"+\", \"-\"];\n\nfunction propertyKey(name: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name) ? name : `'${name}'`;\n}\n\nfunction unquote(name: string): string {\n return name.replace(/^([\"'`])(.*)\\1$/, \"$2\");\n}\n\n/**\n * The object literal of `export const <name> = z.object({ ... })`, through a\n * trailing `satisfies` / `as` and any methods chained on (`.strict()`,\n * `.refine(...)`).\n */\nfunction findZodObject(\n sourceFile: SourceFile,\n schemaName: string,\n): ObjectLiteralExpression | undefined {\n const declarations = sourceFile.getVariableDeclarations();\n const candidates = [\n ...declarations.filter((d) => d.getName() === schemaName),\n ...declarations.filter((d) => d.getName() !== schemaName),\n ];\n\n const found: ObjectLiteralExpression[] = [];\n for (const declaration of candidates) {\n let node: Node | undefined = declaration.getInitializer();\n while (node) {\n if (\n Node.isSatisfiesExpression(node) ||\n Node.isAsExpression(node) ||\n Node.isParenthesizedExpression(node)\n ) {\n node = node.getExpression();\n continue;\n }\n if (!Node.isCallExpression(node)) break;\n const callee = node.getExpression();\n if (\n Node.isPropertyAccessExpression(callee) &&\n callee.getName() === \"object\" &&\n callee.getExpression().getText() === \"z\"\n ) {\n const [shape] = node.getArguments();\n if (shape && Node.isObjectLiteralExpression(shape)) found.push(shape);\n break;\n }\n // `<something>.method(...)`: look at what the method was called on.\n node = Node.isPropertyAccessExpression(callee)\n ? callee.getExpression()\n : undefined;\n }\n // The schema under its generated name wins; otherwise the file has to\n // hold exactly one, or there is no telling which the collection's is.\n if (declaration.getName() === schemaName && found.length === 1) {\n return found[0];\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n\nfunction findProperty(\n shape: ObjectLiteralExpression,\n name: string,\n): PropertyAssignment | ShorthandPropertyAssignment | undefined {\n return shape\n .getProperties()\n .filter(\n (property) =>\n Node.isPropertyAssignment(property) ||\n Node.isShorthandPropertyAssignment(property),\n )\n .find((property) => unquote(property.getName()) === name);\n}\n\n/** What the user would write to make the change by hand. */\nfunction describeChange(change: SchemaChange): string {\n if (change.op === \"add\") {\n return change.entries\n .map((entry) => `add \\`${propertyKey(entry.name)}: ${entry.schema}\\``)\n .join(\", \");\n }\n if (change.op === \"remove\") return `remove \\`${change.fieldName}\\``;\n return `rename \\`${change.from}\\` to \\`${change.to}\\``;\n}\n\nfunction applyChange(\n shape: ObjectLiteralExpression,\n change: SchemaChange,\n): boolean {\n let changed = false;\n\n if (change.op === \"add\") {\n for (const entry of change.entries) {\n // Already there: added by hand, most likely. Theirs stands.\n if (findProperty(shape, entry.name)) continue;\n shape.addPropertyAssignment({\n name: propertyKey(entry.name),\n initializer: entry.schema,\n });\n changed = true;\n }\n return changed;\n }\n\n for (const suffix of KEY_SUFFIXES) {\n const name =\n (change.op === \"remove\" ? change.fieldName : change.from) + suffix;\n const property = findProperty(shape, name);\n if (!property) continue;\n\n if (change.op === \"remove\") {\n property.remove();\n changed = true;\n continue;\n }\n\n const to = change.to + suffix;\n if (findProperty(shape, to)) continue;\n if (Node.isPropertyAssignment(property)) {\n property.getNameNode().replaceWithText(propertyKey(to));\n } else {\n // `{ title }` → `{ heading: title }`: the value keeps its name.\n property.replaceWithText(`${propertyKey(to)}: ${property.getName()}`);\n }\n changed = true;\n }\n return changed;\n}\n\n/**\n * Brings the zod schema of a collection in line with a migration just applied\n * to it: `generate resource` and the scaffolds write the schema once, and a\n * field added later is optional, so nothing else notices it is missing.\n *\n * Only the keys the migration names are touched. A file without a\n * recognisable `z.object({ ... })` is left as it is and reported, with the\n * edit to make by hand.\n */\nexport function modifySchema(\n schemaPath: string,\n schemaName: string,\n changes: SchemaChange[],\n): ModifyOutcome {\n if (!fs.existsSync(schemaPath) || changes.length === 0) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n skipFileDependencyResolution: true,\n });\n const sourceFile = project.addSourceFileAtPath(schemaPath);\n const shape = findZodObject(sourceFile, schemaName);\n\n if (!shape) {\n return {\n status: \"failed\",\n message: `The collection changed, but no \\`z.object({ ... })\\` schema was found in this file to change with it. Update it by hand: ${changes.map(describeChange).join(\"; \")}.`,\n };\n }\n\n let changed = false;\n for (const change of changes) {\n changed = applyChange(shape, change) || changed;\n }\n if (!changed) {\n return { status: \"success\", changed: false };\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n\n/**\n * Whether a remote form validates with the model's schema. Its json fields\n * are then typed as the text a textarea posts, not `z.any()`; see\n * `generateSchemaSnippet`.\n */\nfunction backsRemoteForm(root: string, modelName: string): boolean {\n const routes = path.join(root, \"src\", \"routes\");\n if (!fs.existsSync(routes)) return false;\n const imported = new RegExp(`lib/schemas/${modelName}(\\\\.js|\\\\.ts)?[\"']`);\n return fs\n .readdirSync(routes, { recursive: true, encoding: \"utf8\" })\n .filter((file) => file.endsWith(\".remote.ts\"))\n .some((file) =>\n imported.test(fs.readFileSync(path.join(routes, file), \"utf8\")),\n );\n}\n\n/**\n * `modifySchema` for a migration the generator just applied, on the schema\n * file `generate resource` and the scaffolds write for its collection. `null`\n * when there is nothing to report: no such file, or nothing to change in it.\n */\nexport function modifySchemaForMigration(\n root: string,\n { model, added, changes }: ResolvedMigration,\n): File | null {\n const schemaPath = path.join(\n root,\n \"src\",\n \"lib\",\n \"schemas\",\n `${model.name}.ts`,\n );\n if (!fs.existsSync(schemaPath)) return null;\n\n const schemaChanges: SchemaChange[] = [];\n if (added.length > 0) {\n schemaChanges.push({\n op: \"add\",\n entries: schemaEntriesForFields(added, {\n forForm: true,\n remote: backsRemoteForm(root, model.name),\n }),\n });\n }\n for (const change of changes) {\n if (change.op !== \"add\") schemaChanges.push(change);\n }\n\n return modifyOutcomeToFile(\n schemaPath,\n modifySchema(schemaPath, model.schemaName, schemaChanges),\n );\n}\n"],"mappings":";;;;;;;AAmCA,IAAMK,IAAe;CAAC;CAAI;CAAK;AAAG;AAElC,SAASC,EAAY,GAAsB;CACzC,OAAO,6BAA6B,KAAKC,CAAI,IAAIA,IAAO,IAAIA,EAAK;AACnE;AAEA,SAASC,EAAQ,GAAsB;CACrC,OAAOD,EAAK,QAAQ,mBAAmB,IAAI;AAC7C;AAOA,SAASE,EACP,GACA,GACqC;CACrC,IAAMC,IAAeC,EAAW,wBAAwB,GAClDC,IAAa,CACjB,GAAGF,EAAa,QAAQ,MAAMG,EAAE,QAAQ,MAAMC,CAAU,GACxD,GAAGJ,EAAa,QAAQ,MAAMG,EAAE,QAAQ,MAAMC,CAAU,CAC1D,GAEMC,IAAmC,CAAC;CAC1C,KAAK,IAAMC,KAAeJ,GAAY;EACpC,IAAIK,IAAyBD,EAAY,eAAe;EACxD,OAAOC,IAAM;GACX,IACEC,EAAK,sBAAsBD,CAAI,KAC/BC,EAAK,eAAeD,CAAI,KACxBC,EAAK,0BAA0BD,CAAI,GACnC;IACA,IAAOA,EAAK,cAAc;IAC1B;GACF;GACA,IAAI,CAACC,EAAK,iBAAiBD,CAAI,GAAG;GAClC,IAAME,IAASF,EAAK,cAAc;GA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U,mBAAmB;CACxE,OAAOnC,EACJ,YAAYgC,GAAQ;EAAE,WAAW;EAAM,UAAU;CAAO,CAAC,CAAC,CAC1D,QAAQ,MAASI,EAAK,SAAS,YAAY,CAAC,CAAC,CAC7C,MAAM,MACLF,EAAS,KAAKlC,EAAG,aAAaC,EAAK,KAAK+B,GAAQI,CAAI,GAAG,MAAM,CAAC,CAChE;AACJ;AAOA,SAAgBC,EACd,GACA,EAAE,UAAO,UAAO,cACH;CACb,IAAMT,IAAa3B,EAAK,KACtBgC,GACA,OACA,OACA,WACA,GAAGK,EAAM,KAAK,IAChB;CACA,IAAI,CAACtC,EAAG,WAAW4B,CAAU,GAAG,OAAO;CAEvC,IAAMW,IAAgC,CAAC;CACvC,AAAIC,EAAM,SAAS,KACjBD,EAAc,KAAK;EACjB,IAAI;EACJ,SAAS1C,EAAuB2C,GAAO;GACrC,SAAS;GACT,QAAQT,EAAgBE,GAAMK,EAAM,IAAI;EAC1C,CAAC;CACH,CAAC;CAEH,KAAK,IAAMjB,KAAUQ,GACnB,AAAIR,EAAO,OAAO,SAAOkB,EAAc,KAAKlB,CAAM;CAGpD,OAAOvB,EACL8B,GACAD,EAAaC,GAAYU,EAAM,YAAYC,CAAa,CAC1D;AACF"}
|
|
@@ -15,7 +15,7 @@ async function n(e, t) {
|
|
|
15
15
|
exists: !0,
|
|
16
16
|
rowCount: 0
|
|
17
17
|
}));
|
|
18
|
-
let { withPocketbase: n } = await import("./pocketbase-
|
|
18
|
+
let { withPocketbase: n } = await import("./pocketbase-B2ksFrvH.js").then((e) => e.r), { planCollectionDrops: r } = await import("./collections-Daxlnbm0.js").then((e) => e.n), i = [];
|
|
19
19
|
return await n(t.root, async (t) => {
|
|
20
20
|
let n = await r(t, e);
|
|
21
21
|
i.push(...n);
|
|
@@ -23,4 +23,4 @@ async function n(e, t) {
|
|
|
23
23
|
}
|
|
24
24
|
export { t as n, n as t };
|
|
25
25
|
|
|
26
|
-
//# sourceMappingURL=shared-
|
|
26
|
+
//# sourceMappingURL=shared-CSwGWMcN.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-CSwGWMcN.js","names":["languageFromPath","toDeleteEntry","path","planDropsForCollections","collectionNames","options","n","drops","withPocketbase","plans","planCollectionDrops","pb"],"sources":["../../src/patterns/destroy/shared.ts"],"sourcesContent":["import type { CollectionDropSpec, File, Options } from \"../../core/types\";\nimport { languageFromPath } from \"../../core/util\";\n\nexport function toDeleteEntry(path: string): File {\n return {\n path,\n language: languageFromPath(path),\n content: \"\",\n status: \"success\",\n };\n}\n\n/**\n * Build `CollectionDropSpec` entries for each collection name, with live row\n * counts from PocketBase when `env === \"runtime\"`. In preview mode, returns\n * `{ exists: true, rowCount: 0 }` placeholders.\n */\nexport async function planDropsForCollections(\n collectionNames: string[],\n options: Options,\n): Promise<CollectionDropSpec[]> {\n if (collectionNames.length === 0) return [];\n\n if (options.env !== \"runtime\") {\n return collectionNames.map((name) => ({\n name,\n exists: true,\n rowCount: 0,\n }));\n }\n\n const { withPocketbase } = await import(\"../../runtime/pocketbase\");\n const { planCollectionDrops } = await import(\"../../runtime/collections\");\n const drops: CollectionDropSpec[] = [];\n await withPocketbase(options.root, async (pb) => {\n const plans = await planCollectionDrops(pb, collectionNames);\n drops.push(...plans);\n });\n return drops;\n}\n"],"mappings":";;AAGA,SAAgBC,EAAc,GAAoB;CAChD,OAAO;EACL;EACA,UAAUD,EAAiBE,CAAI;EAC/B,SAAS;EACT,QAAQ;CACV;AACF;AAOA,eAAsBC,EACpB,GACA,GAC+B;CAC/B,IAAIC,EAAgB,WAAW,GAAG,OAAO,CAAC;CAE1C,IAAIC,EAAQ,QAAQ,WAClB,OAAOD,EAAgB,KAAK,OAAU;EACpC;EACA,QAAQ;EACR,UAAU;CACZ,EAAE;CAGJ,IAAM,EAAE,sBAAmB,MAAM,OAAO,2BAAA,CAAA,MAAA,MAAAE,EAAA,CAAA,GAClC,EAAE,2BAAwB,MAAM,OAAO,4BAAA,CAAA,MAAA,MAAAA,EAAA,CAAA,GACvCC,IAA8B,CAAC;CAKrC,OAJA,MAAMC,EAAeH,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAMI,IAAQ,MAAMC,EAAoBC,GAAIP,CAAe;EAC3D,EAAM,KAAK,GAAGK,CAAK;CACrB,CAAC,GACMF;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as e, r as t, t as n } from "./rolldown-runtime-CwxnZyOB.js";
|
|
2
|
-
import {
|
|
2
|
+
import { l as r, o as i, s as a, u as o } from "./route-9ZVJZkYu.js";
|
|
3
3
|
import { t as s } from "./dedent-CCUOcPFW.js";
|
|
4
4
|
import { t as c } from "./errors-DdSUZI8f.js";
|
|
5
5
|
// src/parse/syntax.ts
|
|
@@ -464,12 +464,12 @@ function w(e) {
|
|
|
464
464
|
if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(e)) throw new c("Model name must start with a letter and contain only alphanumeric characters, dash, or underscore. Use --route to specify a custom route path.");
|
|
465
465
|
}
|
|
466
466
|
function T(e) {
|
|
467
|
-
let t = S.default.singular(
|
|
467
|
+
let t = S.default.singular(a(e)), n = S.default.plural(t), s = i(t);
|
|
468
468
|
return {
|
|
469
469
|
name: C(s),
|
|
470
|
-
pluralName: C(
|
|
471
|
-
typeName:
|
|
472
|
-
tableName:
|
|
470
|
+
pluralName: C(i(n)),
|
|
471
|
+
typeName: r(t),
|
|
472
|
+
tableName: o(n),
|
|
473
473
|
displayName: t,
|
|
474
474
|
pluralDisplayName: n,
|
|
475
475
|
schemaName: `${C(s)}Schema`
|
|
@@ -678,14 +678,14 @@ function F(e) {
|
|
|
678
678
|
let t = S.default.singular(e);
|
|
679
679
|
return e === S.default.plural(t) ? 99 : 1;
|
|
680
680
|
}
|
|
681
|
-
function I(e, t, n,
|
|
681
|
+
function I(e, t, n, r, a) {
|
|
682
682
|
let o = T(t), s = S.default.singular(e), c = S.default.plural(s);
|
|
683
683
|
return {
|
|
684
|
-
collectionId:
|
|
684
|
+
collectionId: r[t],
|
|
685
685
|
displayField: a[t] ?? "id",
|
|
686
686
|
relatedModel: o,
|
|
687
|
-
singularRelationName:
|
|
688
|
-
pluralRelationName:
|
|
687
|
+
singularRelationName: i(`${n.displayName} ${o.displayName}`),
|
|
688
|
+
pluralRelationName: i(`${n.displayName} ${o.pluralDisplayName}`),
|
|
689
689
|
maxSelect: e === c ? 999 : 1
|
|
690
690
|
};
|
|
691
691
|
}
|
|
@@ -720,7 +720,7 @@ function R(e, t, n) {
|
|
|
720
720
|
return e;
|
|
721
721
|
}
|
|
722
722
|
function z(e, t, n, r, i) {
|
|
723
|
-
let
|
|
723
|
+
let o = a(e), { type: s, required: u, selectOptions: d } = t, f = re(r), p = ie(r), m = D(r), h = f.map((e) => S.default.singular(e));
|
|
724
724
|
if (s === "current_user") {
|
|
725
725
|
if (!i.features.auth) throw new c("Field type \"current_user\" requires the auth feature. Run `vela enable auth` to enable it.");
|
|
726
726
|
if (!p.users) throw new c("Field type \"current_user\" requires a \"users\" collection but none was found.");
|
|
@@ -728,7 +728,7 @@ function z(e, t, n, r, i) {
|
|
|
728
728
|
return {
|
|
729
729
|
type: "relation",
|
|
730
730
|
name: e,
|
|
731
|
-
title:
|
|
731
|
+
title: o,
|
|
732
732
|
required: !0,
|
|
733
733
|
collectionId: t.collectionId,
|
|
734
734
|
maxSelect: 1,
|
|
@@ -747,7 +747,7 @@ function z(e, t, n, r, i) {
|
|
|
747
747
|
return {
|
|
748
748
|
type: "relation",
|
|
749
749
|
name: e,
|
|
750
|
-
title:
|
|
750
|
+
title: o,
|
|
751
751
|
required: !0,
|
|
752
752
|
collectionId: t.collectionId,
|
|
753
753
|
maxSelect: 1,
|
|
@@ -765,7 +765,7 @@ function z(e, t, n, r, i) {
|
|
|
765
765
|
return {
|
|
766
766
|
type: "autodate",
|
|
767
767
|
name: e,
|
|
768
|
-
title:
|
|
768
|
+
title: o,
|
|
769
769
|
required: u,
|
|
770
770
|
...t
|
|
771
771
|
};
|
|
@@ -773,7 +773,7 @@ function z(e, t, n, r, i) {
|
|
|
773
773
|
if (s === "select") return {
|
|
774
774
|
type: "select",
|
|
775
775
|
name: e,
|
|
776
|
-
title:
|
|
776
|
+
title: o,
|
|
777
777
|
required: u,
|
|
778
778
|
maxSelect: Math.max(1, Math.min(F(e), d.length)),
|
|
779
779
|
options: d
|
|
@@ -781,7 +781,7 @@ function z(e, t, n, r, i) {
|
|
|
781
781
|
if (s === "file") return {
|
|
782
782
|
type: "file",
|
|
783
783
|
name: e,
|
|
784
|
-
title:
|
|
784
|
+
title: o,
|
|
785
785
|
required: u,
|
|
786
786
|
maxSelect: F(e)
|
|
787
787
|
};
|
|
@@ -791,7 +791,7 @@ function z(e, t, n, r, i) {
|
|
|
791
791
|
return {
|
|
792
792
|
type: "relation",
|
|
793
793
|
name: e,
|
|
794
|
-
title:
|
|
794
|
+
title: o,
|
|
795
795
|
required: u,
|
|
796
796
|
...I(e, r, n, p, m),
|
|
797
797
|
isCurrentUser: !1,
|
|
@@ -801,7 +801,7 @@ function z(e, t, n, r, i) {
|
|
|
801
801
|
if (f.includes(s)) return {
|
|
802
802
|
type: "relation",
|
|
803
803
|
name: e,
|
|
804
|
-
title:
|
|
804
|
+
title: o,
|
|
805
805
|
required: u,
|
|
806
806
|
...I(e, s, n, p, m),
|
|
807
807
|
isCurrentUser: !1,
|
|
@@ -814,7 +814,7 @@ function z(e, t, n, r, i) {
|
|
|
814
814
|
return {
|
|
815
815
|
type: "relation",
|
|
816
816
|
name: e,
|
|
817
|
-
title:
|
|
817
|
+
title: o,
|
|
818
818
|
required: u,
|
|
819
819
|
collectionId: r.collectionId,
|
|
820
820
|
displayField: r.displayField,
|
|
@@ -839,7 +839,7 @@ function z(e, t, n, r, i) {
|
|
|
839
839
|
return {
|
|
840
840
|
type: s,
|
|
841
841
|
name: e,
|
|
842
|
-
title:
|
|
842
|
+
title: o,
|
|
843
843
|
required: u
|
|
844
844
|
};
|
|
845
845
|
}
|
|
@@ -1013,31 +1013,31 @@ function fe(e) {
|
|
|
1013
1013
|
return t;
|
|
1014
1014
|
}
|
|
1015
1015
|
function pe(e, t, n) {
|
|
1016
|
-
let
|
|
1017
|
-
if (!
|
|
1018
|
-
let
|
|
1019
|
-
for (let t of
|
|
1016
|
+
let r = t.find((t) => t.name === e.tableName);
|
|
1017
|
+
if (!r) throw Error(`Collection "${e.tableName}" not found`);
|
|
1018
|
+
let o = D(t), s = new Map(t.map((e) => [e.id, e])), c = [];
|
|
1019
|
+
for (let t of r.fields) {
|
|
1020
1020
|
if (t.name === "id" || t.system || t.type === "autodate" && X(t.name)) continue;
|
|
1021
|
-
let
|
|
1022
|
-
if (
|
|
1023
|
-
let
|
|
1024
|
-
if (!
|
|
1025
|
-
let
|
|
1021
|
+
let r = fe(t.type), l = !!t.required, u = a(t.name);
|
|
1022
|
+
if (r === "relation") {
|
|
1023
|
+
let r = t.collectionId ? s.get(t.collectionId) : void 0;
|
|
1024
|
+
if (!r) continue;
|
|
1025
|
+
let a = T(r.name);
|
|
1026
1026
|
c.push({
|
|
1027
1027
|
name: t.name,
|
|
1028
1028
|
title: u,
|
|
1029
1029
|
type: "relation",
|
|
1030
1030
|
required: l,
|
|
1031
|
-
collectionId:
|
|
1031
|
+
collectionId: r.id,
|
|
1032
1032
|
maxSelect: t.maxSelect ?? 1,
|
|
1033
|
-
displayField:
|
|
1034
|
-
relatedModel:
|
|
1035
|
-
singularRelationName:
|
|
1036
|
-
pluralRelationName:
|
|
1037
|
-
isCurrentUser: n.features.auth &&
|
|
1038
|
-
isCurrentTeam: n.features.teams &&
|
|
1033
|
+
displayField: o[r.name] ?? "id",
|
|
1034
|
+
relatedModel: a,
|
|
1035
|
+
singularRelationName: i(`${e.displayName} ${a.displayName}`),
|
|
1036
|
+
pluralRelationName: i(`${e.displayName} ${a.pluralDisplayName}`),
|
|
1037
|
+
isCurrentUser: n.features.auth && r.name === "users" && /user|owner|author/i.test(t.name),
|
|
1038
|
+
isCurrentTeam: n.features.teams && r.name === "teams" && /team/i.test(t.name)
|
|
1039
1039
|
});
|
|
1040
|
-
} else
|
|
1040
|
+
} else r === "select" ? c.push({
|
|
1041
1041
|
name: t.name,
|
|
1042
1042
|
title: u,
|
|
1043
1043
|
type: "select",
|
|
@@ -1047,13 +1047,13 @@ function pe(e, t, n) {
|
|
|
1047
1047
|
label: e,
|
|
1048
1048
|
value: e
|
|
1049
1049
|
}))
|
|
1050
|
-
}) :
|
|
1050
|
+
}) : r === "file" ? c.push({
|
|
1051
1051
|
name: t.name,
|
|
1052
1052
|
title: u,
|
|
1053
1053
|
type: "file",
|
|
1054
1054
|
required: l,
|
|
1055
1055
|
maxSelect: t.maxSelect ?? 1
|
|
1056
|
-
}) :
|
|
1056
|
+
}) : r === "autodate" ? c.push({
|
|
1057
1057
|
name: t.name,
|
|
1058
1058
|
title: u,
|
|
1059
1059
|
type: "autodate",
|
|
@@ -1063,7 +1063,7 @@ function pe(e, t, n) {
|
|
|
1063
1063
|
}) : c.push({
|
|
1064
1064
|
name: t.name,
|
|
1065
1065
|
title: u,
|
|
1066
|
-
type:
|
|
1066
|
+
type: r,
|
|
1067
1067
|
required: l
|
|
1068
1068
|
});
|
|
1069
1069
|
}
|
|
@@ -1179,4 +1179,4 @@ function Ce(e, t, n, r) {
|
|
|
1179
1179
|
}
|
|
1180
1180
|
export { w as _, me as a, ue as c, K as d, J as f, T as g, B as h, G as i, xe as l, q as m, Ce as n, he as o, $ as p, de as r, ge as s, Z as t, be as u, x as v, b as y };
|
|
1181
1181
|
|
|
1182
|
-
//# sourceMappingURL=shared-
|
|
1182
|
+
//# sourceMappingURL=shared-Cdwm_-Nl.js.map
|