@conloca/content-api 0.1.16 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/dist/asset-constraints.d.ts +16 -0
  2. package/dist/asset-constraints.d.ts.map +1 -0
  3. package/dist/asset-constraints.js +29 -0
  4. package/dist/asset-constraints.js.map +1 -0
  5. package/dist/asset-metadata-store.d.ts +60 -0
  6. package/dist/asset-metadata-store.d.ts.map +1 -0
  7. package/dist/asset-metadata-store.js +335 -0
  8. package/dist/asset-metadata-store.js.map +1 -0
  9. package/dist/asset-operations.d.ts +18 -13
  10. package/dist/asset-operations.d.ts.map +1 -1
  11. package/dist/asset-operations.js +302 -254
  12. package/dist/asset-operations.js.map +1 -0
  13. package/dist/asset-types.d.ts +23 -7
  14. package/dist/asset-types.d.ts.map +1 -1
  15. package/dist/asset-types.js +8 -2
  16. package/dist/asset-types.js.map +1 -0
  17. package/dist/asset-usage.d.ts +10 -0
  18. package/dist/asset-usage.d.ts.map +1 -0
  19. package/dist/asset-usage.js +49 -0
  20. package/dist/asset-usage.js.map +1 -0
  21. package/dist/base-content-index.d.ts +8 -2
  22. package/dist/base-content-index.d.ts.map +1 -1
  23. package/dist/base-content-index.js +24 -3
  24. package/dist/base-content-index.js.map +1 -0
  25. package/dist/cf-access.js +1 -0
  26. package/dist/cf-access.js.map +1 -0
  27. package/dist/component-registry.d.ts +1 -1
  28. package/dist/component-registry.d.ts.map +1 -1
  29. package/dist/component-registry.js +2 -1
  30. package/dist/component-registry.js.map +1 -0
  31. package/dist/component-registry.types.js +1 -0
  32. package/dist/component-registry.types.js.map +1 -0
  33. package/dist/component-vocabulary.d.ts +33 -0
  34. package/dist/component-vocabulary.d.ts.map +1 -0
  35. package/dist/component-vocabulary.js +105 -0
  36. package/dist/component-vocabulary.js.map +1 -0
  37. package/dist/content-api.interface.d.ts +5 -5
  38. package/dist/content-api.interface.d.ts.map +1 -1
  39. package/dist/content-api.interface.js +1 -0
  40. package/dist/content-api.interface.js.map +1 -0
  41. package/dist/content-filters.d.ts +2 -2
  42. package/dist/content-filters.d.ts.map +1 -1
  43. package/dist/content-filters.js +9 -8
  44. package/dist/content-filters.js.map +1 -0
  45. package/dist/content-index.d.ts +74 -16
  46. package/dist/content-index.d.ts.map +1 -1
  47. package/dist/content-index.js +183 -55
  48. package/dist/content-index.js.map +1 -0
  49. package/dist/content-operations.d.ts +71 -7
  50. package/dist/content-operations.d.ts.map +1 -1
  51. package/dist/content-operations.js +166 -82
  52. package/dist/content-operations.js.map +1 -0
  53. package/dist/content-path.d.ts +59 -0
  54. package/dist/content-path.d.ts.map +1 -0
  55. package/dist/content-path.js +88 -0
  56. package/dist/content-path.js.map +1 -0
  57. package/dist/content-reader.d.ts +2 -2
  58. package/dist/content-reader.d.ts.map +1 -1
  59. package/dist/content-reader.js +2 -1
  60. package/dist/content-reader.js.map +1 -0
  61. package/dist/content-utils.d.ts +53 -10
  62. package/dist/content-utils.d.ts.map +1 -1
  63. package/dist/content-utils.js +103 -34
  64. package/dist/content-utils.js.map +1 -0
  65. package/dist/content-watcher.d.ts +3 -3
  66. package/dist/content-watcher.d.ts.map +1 -1
  67. package/dist/content-watcher.js +13 -10
  68. package/dist/content-watcher.js.map +1 -0
  69. package/dist/data-index.d.ts +1 -1
  70. package/dist/data-index.d.ts.map +1 -1
  71. package/dist/data-index.js +2 -1
  72. package/dist/data-index.js.map +1 -0
  73. package/dist/data.d.ts +5 -13
  74. package/dist/data.d.ts.map +1 -1
  75. package/dist/data.js +7 -6
  76. package/dist/data.js.map +1 -0
  77. package/dist/editor-data-bindings.d.ts +10 -0
  78. package/dist/editor-data-bindings.d.ts.map +1 -0
  79. package/dist/editor-data-bindings.js +67 -0
  80. package/dist/editor-data-bindings.js.map +1 -0
  81. package/dist/etag-utils.d.ts.map +1 -1
  82. package/dist/etag-utils.js +5 -4
  83. package/dist/etag-utils.js.map +1 -0
  84. package/dist/filesystem-content-api.d.ts +45 -18
  85. package/dist/filesystem-content-api.d.ts.map +1 -1
  86. package/dist/filesystem-content-api.js +407 -281
  87. package/dist/filesystem-content-api.js.map +1 -0
  88. package/dist/filesystem-reader-backend.d.ts +46 -0
  89. package/dist/filesystem-reader-backend.d.ts.map +1 -0
  90. package/dist/filesystem-reader-backend.js +119 -0
  91. package/dist/filesystem-reader-backend.js.map +1 -0
  92. package/dist/fragment-index.d.ts +8 -0
  93. package/dist/fragment-index.d.ts.map +1 -0
  94. package/dist/fragment-index.js +8 -0
  95. package/dist/fragment-index.js.map +1 -0
  96. package/dist/fragments.d.ts +16 -0
  97. package/dist/fragments.d.ts.map +1 -0
  98. package/dist/fragments.js +104 -0
  99. package/dist/fragments.js.map +1 -0
  100. package/dist/git-operations.d.ts.map +1 -1
  101. package/dist/git-operations.js +5 -1
  102. package/dist/git-operations.js.map +1 -0
  103. package/dist/header-parser.d.ts +4 -4
  104. package/dist/header-parser.d.ts.map +1 -1
  105. package/dist/header-parser.js +8 -61
  106. package/dist/header-parser.js.map +1 -0
  107. package/dist/in-memory-content-api.d.ts +7 -7
  108. package/dist/in-memory-content-api.d.ts.map +1 -1
  109. package/dist/in-memory-content-api.js +74 -56
  110. package/dist/in-memory-content-api.js.map +1 -0
  111. package/dist/index.d.ts +19 -12
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +21 -9
  114. package/dist/index.js.map +1 -0
  115. package/dist/indexing.d.ts +4 -4
  116. package/dist/indexing.d.ts.map +1 -1
  117. package/dist/indexing.js +6 -5
  118. package/dist/indexing.js.map +1 -0
  119. package/dist/json-whitespace-view.js +1 -0
  120. package/dist/json-whitespace-view.js.map +1 -0
  121. package/dist/middleware.d.ts +6 -6
  122. package/dist/middleware.d.ts.map +1 -1
  123. package/dist/middleware.js +170 -119
  124. package/dist/middleware.js.map +1 -0
  125. package/dist/node.d.ts +24 -17
  126. package/dist/node.d.ts.map +1 -1
  127. package/dist/node.js +17 -14
  128. package/dist/node.js.map +1 -0
  129. package/dist/page-references.d.ts +21 -0
  130. package/dist/page-references.d.ts.map +1 -0
  131. package/dist/page-references.js +50 -0
  132. package/dist/page-references.js.map +1 -0
  133. package/dist/read-date.d.ts +3 -0
  134. package/dist/read-date.d.ts.map +1 -0
  135. package/dist/read-date.js +9 -0
  136. package/dist/read-date.js.map +1 -0
  137. package/dist/reader-backend.d.ts +54 -0
  138. package/dist/reader-backend.d.ts.map +1 -0
  139. package/dist/reader-backend.js +2 -0
  140. package/dist/reader-backend.js.map +1 -0
  141. package/dist/reader.d.ts +8 -8
  142. package/dist/reader.d.ts.map +1 -1
  143. package/dist/reader.js +8 -7
  144. package/dist/reader.js.map +1 -0
  145. package/dist/schemas/index.d.ts +6 -6
  146. package/dist/schemas/index.d.ts.map +1 -1
  147. package/dist/schemas/index.js +9 -8
  148. package/dist/schemas/index.js.map +1 -0
  149. package/dist/site-index.d.ts +3 -3
  150. package/dist/site-index.d.ts.map +1 -1
  151. package/dist/site-index.js +9 -5
  152. package/dist/site-index.js.map +1 -0
  153. package/dist/site.d.ts +5 -3
  154. package/dist/site.d.ts.map +1 -1
  155. package/dist/site.js +14 -2
  156. package/dist/site.js.map +1 -0
  157. package/dist/types.d.ts +203 -15
  158. package/dist/types.d.ts.map +1 -1
  159. package/dist/types.js +9 -0
  160. package/dist/types.js.map +1 -0
  161. package/dist/url-safe-base64.js +1 -0
  162. package/dist/url-safe-base64.js.map +1 -0
  163. package/dist/url-validation.d.ts +14 -0
  164. package/dist/url-validation.d.ts.map +1 -1
  165. package/dist/url-validation.js +56 -14
  166. package/dist/url-validation.js.map +1 -0
  167. package/dist/utils/atomic-write.js +1 -0
  168. package/dist/utils/atomic-write.js.map +1 -0
  169. package/dist/utils.d.ts +1 -1
  170. package/dist/utils.js +2 -1
  171. package/dist/utils.js.map +1 -0
  172. package/dist/vite-plugin.d.ts +2 -2
  173. package/dist/vite-plugin.js +5 -4
  174. package/dist/vite-plugin.js.map +1 -0
  175. package/dist/vxjson-serialize.d.ts +5 -6
  176. package/dist/vxjson-serialize.d.ts.map +1 -1
  177. package/dist/vxjson-serialize.js +13 -10
  178. package/dist/vxjson-serialize.js.map +1 -0
  179. package/dist/vxjson.d.ts +4 -3
  180. package/dist/vxjson.d.ts.map +1 -1
  181. package/dist/vxjson.js +10 -20
  182. package/dist/vxjson.js.map +1 -0
  183. package/dist/xxhash.d.ts.map +1 -1
  184. package/dist/xxhash.js +6 -2
  185. package/dist/xxhash.js.map +1 -0
  186. package/package.json +92 -56
  187. package/src/asset-constraints.ts +33 -0
  188. package/src/asset-metadata-store.ts +401 -0
  189. package/src/asset-operations.ts +914 -0
  190. package/src/asset-types.ts +74 -0
  191. package/src/asset-usage.ts +47 -0
  192. package/src/base-content-index.ts +227 -0
  193. package/src/cf-access.ts +85 -0
  194. package/src/component-registry.ts +145 -0
  195. package/src/component-registry.types.ts +12 -0
  196. package/src/component-vocabulary.ts +87 -0
  197. package/src/content-api.interface.ts +94 -0
  198. package/src/content-filters.ts +278 -0
  199. package/src/content-index.ts +642 -0
  200. package/src/content-operations.ts +497 -0
  201. package/src/content-path.ts +113 -0
  202. package/src/content-reader.ts +18 -0
  203. package/src/content-utils.ts +474 -0
  204. package/src/content-watcher.ts +122 -0
  205. package/src/data-index.ts +7 -0
  206. package/src/data.ts +134 -0
  207. package/src/editor-data-bindings.ts +66 -0
  208. package/src/etag-utils.ts +204 -0
  209. package/src/filesystem-content-api.ts +2685 -0
  210. package/src/filesystem-reader-backend.ts +135 -0
  211. package/src/fragment-index.ts +7 -0
  212. package/src/fragments.ts +113 -0
  213. package/src/git-operations.ts +340 -0
  214. package/src/header-parser.ts +272 -0
  215. package/src/in-memory-content-api.ts +760 -0
  216. package/src/index.ts +45 -0
  217. package/src/indexing.ts +8 -0
  218. package/src/json-whitespace-view.ts +155 -0
  219. package/src/middleware.ts +1341 -0
  220. package/src/node.ts +40 -0
  221. package/src/page-references.ts +76 -0
  222. package/src/read-date.ts +7 -0
  223. package/src/reader-backend.ts +54 -0
  224. package/src/reader.ts +15 -0
  225. package/src/schemas/index.ts +113 -0
  226. package/src/site-index.ts +330 -0
  227. package/src/site.ts +198 -0
  228. package/src/types.ts +759 -0
  229. package/src/url-safe-base64.ts +38 -0
  230. package/src/url-validation.ts +121 -0
  231. package/src/utils/atomic-write.ts +20 -0
  232. package/src/utils.ts +84 -0
  233. package/src/vite-plugin.ts +45 -0
  234. package/src/vxjson-serialize.ts +66 -0
  235. package/src/vxjson.ts +442 -0
  236. package/src/xxhash.ts +43 -0
  237. package/dist/asset-manifest.d.ts +0 -23
  238. package/dist/asset-manifest.d.ts.map +0 -1
  239. package/dist/asset-manifest.js +0 -73
  240. package/dist/block-index.d.ts +0 -9
  241. package/dist/block-index.d.ts.map +0 -1
  242. package/dist/block-index.js +0 -11
  243. package/dist/blocks.d.ts +0 -16
  244. package/dist/blocks.d.ts.map +0 -1
  245. package/dist/blocks.js +0 -103
  246. package/dist/component-registry.types-C0ctF9nh.d.mts +0 -71
  247. package/dist/component-registry.types-C0ctF9nh.d.mts.map +0 -1
  248. package/dist/content-index-D092_vk1.mjs +0 -629
  249. package/dist/content-index-D092_vk1.mjs.map +0 -1
  250. package/dist/content-index-D6IVMmAB.d.mts +0 -127
  251. package/dist/content-index-D6IVMmAB.d.mts.map +0 -1
  252. package/dist/content-operations-DIbsxG5A.d.mts +0 -354
  253. package/dist/content-operations-DIbsxG5A.d.mts.map +0 -1
  254. package/dist/content-utils-fWNHTrPy.mjs +0 -280
  255. package/dist/content-utils-fWNHTrPy.mjs.map +0 -1
  256. package/dist/data-DquNIEnQ.mjs +0 -62
  257. package/dist/data-DquNIEnQ.mjs.map +0 -1
  258. package/dist/filesystem-content-api-B1KIQJfk.mjs +0 -2
  259. package/dist/filesystem-content-api-C0HIhqZi.mjs +0 -1620
  260. package/dist/filesystem-content-api-C0HIhqZi.mjs.map +0 -1
  261. package/dist/filesystem-content-api-DCdNi-co.d.mts +0 -134
  262. package/dist/filesystem-content-api-DCdNi-co.d.mts.map +0 -1
  263. package/dist/index-DxVTFK66.d.mts +0 -105
  264. package/dist/index-DxVTFK66.d.mts.map +0 -1
  265. package/dist/index.d.mts +0 -80
  266. package/dist/index.d.mts.map +0 -1
  267. package/dist/index.mjs +0 -78
  268. package/dist/index.mjs.map +0 -1
  269. package/dist/indexing.d.mts +0 -152
  270. package/dist/indexing.d.mts.map +0 -1
  271. package/dist/indexing.mjs +0 -255
  272. package/dist/indexing.mjs.map +0 -1
  273. package/dist/node.d.mts +0 -373
  274. package/dist/node.d.mts.map +0 -1
  275. package/dist/node.mjs +0 -2572
  276. package/dist/node.mjs.map +0 -1
  277. package/dist/reader.d.mts +0 -15
  278. package/dist/reader.d.mts.map +0 -1
  279. package/dist/reader.mjs +0 -22
  280. package/dist/reader.mjs.map +0 -1
  281. package/dist/schemas/index.d.mts +0 -2
  282. package/dist/schemas/index.mjs +0 -2
  283. package/dist/schemas-CFRD0FIQ.mjs +0 -84
  284. package/dist/schemas-CFRD0FIQ.mjs.map +0 -1
  285. package/dist/site-8oaj1Q60.mjs +0 -366
  286. package/dist/site-8oaj1Q60.mjs.map +0 -1
  287. package/dist/site-index-B_254bCc.d.mts +0 -136
  288. package/dist/site-index-B_254bCc.d.mts.map +0 -1
  289. package/dist/types-DOdldbfD.mjs +0 -34
  290. package/dist/types-DOdldbfD.mjs.map +0 -1
  291. package/dist/types-DjfhS272.d.mts +0 -456
  292. package/dist/types-DjfhS272.d.mts.map +0 -1
  293. package/dist/vxjson-qHrgLGip.mjs +0 -555
  294. package/dist/vxjson-qHrgLGip.mjs.map +0 -1
  295. package/dist/vxjson-serialize-geF6qvpn.mjs +0 -34
  296. package/dist/vxjson-serialize-geF6qvpn.mjs.map +0 -1
  297. package/dist/vxjson-serialize.d.mts +0 -17
  298. package/dist/vxjson-serialize.d.mts.map +0 -1
  299. package/dist/vxjson-serialize.mjs +0 -2
@@ -1,7 +1,7 @@
1
- import type { Blocks } from './blocks';
2
- import { generateContentId, isContentPublished } from './content-utils';
3
- import type { Site } from './site';
4
- import type { ContentMeta, CreateContentInput, LocaleUpdateData, LocaleVersion } from './types';
1
+ import { generateContentId, isContentPublished } from './content-utils.js';
2
+ import type { Fragments } from './fragments.js';
3
+ import type { Site } from './site.js';
4
+ import type { ContentMeta, CreateContentInput, LocaleUpdateData, LocaleVersion } from './types.js';
5
5
  /**
6
6
  * Shared business logic for content operations
7
7
  * Used by both FileSystemContentAPI and InMemoryContentAPI
@@ -15,8 +15,10 @@ export interface ValidationResult {
15
15
  export interface CreateValidationResult {
16
16
  valid: boolean;
17
17
  error?: string;
18
- reason?: 'metadata_too_large' | 'pathname_taken' | 'pathname_in_redirects' | 'invalid_pathname' | 'invalid_name' | 'name_taken';
18
+ reason?: 'metadata_too_large' | 'pathname_taken' | 'pathname_in_redirects' | 'invalid_pathname' | 'invalid_name' | 'name_taken' | 'invalid_collection' | 'invalid_locale' | 'missing_field' | 'unknown_site' | 'no_sites_configured';
19
19
  existingId?: string;
20
+ /** The input field a caller has to change, when the validator knows which one it is. */
21
+ field?: string;
20
22
  }
21
23
  /**
22
24
  * Validate and prepare metadata for storage
@@ -36,7 +38,7 @@ export declare function buildLocaleVersion(params: {
36
38
  created: string;
37
39
  modified: string;
38
40
  meta: ContentMeta;
39
- kind: 'block' | 'page' | 'data';
41
+ kind: 'fragment' | 'page' | 'data';
40
42
  publishAt?: string;
41
43
  unpublishAt?: string;
42
44
  pathname?: string;
@@ -50,10 +52,72 @@ export declare function updatePublishDates(manifest: LocaleVersion, data: Locale
50
52
  /**
51
53
  * Validate content creation data
52
54
  */
53
- export declare function validateCreateContent(data: CreateContentInput, sites: Record<string, Site>, blocks: Blocks, dataApi?: {
55
+ export declare function validateCreateContent(data: CreateContentInput, sites: Record<string, Site>, fragments: Fragments, dataApi?: {
54
56
  isDataNameValid: (name: string) => boolean;
55
57
  getNameConflict: (collection: string, name: string) => string | null;
56
58
  }): CreateValidationResult;
59
+ /** Why a new entry's collection or one of its locales cannot be part of its file path. */
60
+ export interface PlaceRefusal {
61
+ valid: false;
62
+ reason: 'invalid_collection' | 'invalid_locale';
63
+ error: string;
64
+ field: 'collection' | 'locales';
65
+ }
66
+ /**
67
+ * Why a new entry cannot be stored in `collection` under `locales`, or null when it can. Both are
68
+ * part of the entry's file path, so a collection must be a plain folder name and a locale a
69
+ * language code the file layout reads back: '../x' in either would put the file somewhere else.
70
+ */
71
+ export declare function checkEntryPlace(collection: string | undefined, locales: string[]): PlaceRefusal | null;
72
+ /**
73
+ * Why a new page of `site` cannot be stored under `locales`, or null when it can: each must be a
74
+ * language the site is set up for (`siteLocales`), in the same capitals. The site's pages are read
75
+ * back only in those languages, and a file in another one lands on a page's file: 'EN' on a macOS
76
+ * or Windows disk is the 'en' file, and in an MDX pages folder 'fr' is read as a path folder.
77
+ */
78
+ export declare function checkPageLocales(site: string, siteLocales: readonly string[], locales: string[]): PlaceRefusal | null;
79
+ /** Why a name cannot be a fragment or data entry's name, and the entry that has it when it is taken. */
80
+ export interface NameRefusal {
81
+ valid: false;
82
+ reason: 'invalid_name' | 'name_taken';
83
+ error: string;
84
+ existingId?: string;
85
+ }
86
+ /**
87
+ * Why `name` cannot be the name of a `kind` entry in `collection`, or null when it can: it is
88
+ * missing or malformed, or `conflictOf` finds another entry of the collection with it. The name is
89
+ * part of the entry's file path, so 'a/b' or '../x' would put the file somewhere else.
90
+ */
91
+ export declare function checkEntryName(kind: 'fragment' | 'data', collection: string, name: string | undefined, isValid: (name: string) => boolean, conflictOf: (name: string) => string | null): NameRefusal | null;
92
+ /** Why a path cannot be a page's path, and the page that has it when it is taken. */
93
+ export interface PathnameRefusal {
94
+ valid: false;
95
+ reason: 'invalid_pathname' | 'pathname_taken';
96
+ error: string;
97
+ existingId?: string;
98
+ }
99
+ /**
100
+ * `pathname` tidied as a page's path in `locale`, or why it cannot be one: it is malformed, or
101
+ * another page has it. The path names the page's file, so '/../x' would write it outside the
102
+ * content folder, and '/about/' is the file of the page at '/about'. `excludeId` is a page whose
103
+ * own path is changing; it never blocks itself. Without a `site`, only the path's form is checked.
104
+ */
105
+ export declare function checkPagePathname(site: Site | undefined, pathname: string, locale: string, excludeId?: string): {
106
+ valid: true;
107
+ pathname: string;
108
+ } | PathnameRefusal;
109
+ /**
110
+ * Why a page cannot have `pathname` in `locale` in a site's MDX pages folder (sites.json
111
+ * `mdxPages`), or null when it can. In that folder a page's language is its first folder and a
112
+ * default-language page has none, so '/de/x' in the default language would be written to
113
+ * <folder>/de/x.mdx, the file of the German page at '/x', and read back as that page. `locales`
114
+ * are the languages the folder reads as a first folder. They match in any capitals: macOS and
115
+ * Windows disks treat <folder>/pt-br/x.mdx and <folder>/pt-BR/x.mdx as one file.
116
+ */
117
+ export declare function checkMdxPagesPathname(pathname: string, locale: string, folder: {
118
+ defaultLocale: string;
119
+ locales: Iterable<string>;
120
+ }): PathnameRefusal | null;
57
121
  /**
58
122
  * Generate a new content ID
59
123
  */
@@ -1 +1 @@
1
- {"version":3,"file":"content-operations.d.ts","sourceRoot":"","sources":["../src/content-operations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAgC,MAAM,iBAAiB,CAAC;AACtG,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEhG;;;GAGG;AAGH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EACH,oBAAoB,GACpB,gBAAgB,GAChB,uBAAuB,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AK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,kBAAkB,GAAG,gBAAgB,CAAC;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,IAAI,GAAG,SAAS,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GACjB;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,eAAe,CAerD;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;CAAE,GAC3D,eAAe,GAAG,IAAI,CAWxB;AAED;;GAEG;AACH;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,YAAY;aACvB,IAAI,EAAE,CAAC;aACP,IAAI;aACJ,OAAO;aACP,IAAI,EAAE,CAAC;CACC,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE3E;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,WAAW,CAetE;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAG7E"}
@@ -1,5 +1,6 @@
1
1
  import sortKeys from 'sort-keys';
2
- import { generateContentId, isContentPublished, normalizeAndValidatePathname } from './content-utils';
2
+ import { isContentLocale } from './content-path.js';
3
+ import { generateContentId, isContentPublished, normalizeAndValidatePathname } from './content-utils.js';
3
4
  /**
4
5
  * Validate and prepare metadata for storage
5
6
  * Ensures title exists and metadata doesn't exceed 4KB
@@ -59,7 +60,7 @@ export function buildLocaleVersion(params) {
59
60
  if (params.pathname && params.kind === 'page') {
60
61
  manifest.pathname = params.pathname;
61
62
  }
62
- if (params.name && (params.kind === 'block' || params.kind === 'data')) {
63
+ if (params.name && (params.kind === 'fragment' || params.kind === 'data')) {
63
64
  manifest.name = params.name;
64
65
  }
65
66
  if (params.previousPathnames && Object.keys(params.previousPathnames).length > 0) {
@@ -95,7 +96,10 @@ export function updatePublishDates(manifest, data) {
95
96
  /**
96
97
  * Validate content creation data
97
98
  */
98
- export function validateCreateContent(data, sites, blocks, dataApi) {
99
+ export function validateCreateContent(data, sites, fragments, dataApi) {
100
+ const misplaced = checkEntryPlace(data.collection, Object.keys(data.locales));
101
+ if (misplaced)
102
+ return misplaced;
99
103
  // Validate metadata for all locales
100
104
  for (const localeData of Object.values(data.locales)) {
101
105
  const meta = { ...data.meta, ...localeData.meta };
@@ -110,19 +114,39 @@ export function validateCreateContent(data, sites, blocks, dataApi) {
110
114
  }
111
115
  // Validate pathname for pages
112
116
  if (data.kind === 'page') {
117
+ // A content root that declares no sites at all cannot take a page, whatever
118
+ // site the caller names. Blaming the `site` field here sends people hunting
119
+ // for a site name when the real cause is the missing config file.
120
+ if (Object.keys(sites).length === 0) {
121
+ return {
122
+ valid: false,
123
+ error: 'No sites are configured. Create content/sites.json, or run `conloca init <directory> <site-name>`.',
124
+ reason: 'no_sites_configured',
125
+ field: 'site',
126
+ };
127
+ }
113
128
  if (!data.site) {
114
129
  return {
115
130
  valid: false,
116
131
  error: 'Site is required for pages',
132
+ reason: 'missing_field',
133
+ field: 'site',
117
134
  };
118
135
  }
119
- const site = sites[data.site];
136
+ // Own-key only: the site name is caller-supplied, so an inherited key like
137
+ // `constructor` used to pass this gate and then break on the non-Site.
138
+ const site = Object.hasOwn(sites, data.site) ? sites[data.site] : undefined;
120
139
  if (!site) {
121
140
  return {
122
141
  valid: false,
123
142
  error: `Site ${data.site} not found`,
143
+ reason: 'unknown_site',
144
+ field: 'site',
124
145
  };
125
146
  }
147
+ const unsupported = checkPageLocales(data.site, site.locales, Object.keys(data.locales));
148
+ if (unsupported)
149
+ return unsupported;
126
150
  for (const [locale, localeData] of Object.entries(data.locales)) {
127
151
  const pathname = localeData.pathname;
128
152
  // Pathname is required for pages
@@ -130,99 +154,158 @@ export function validateCreateContent(data, sites, blocks, dataApi) {
130
154
  return {
131
155
  valid: false,
132
156
  error: `Pathname is required for pages (locale: ${locale})`,
157
+ reason: 'missing_field',
158
+ field: 'pathname',
133
159
  };
134
160
  }
135
- // Validate and normalize pathname shape. The normalized value is
136
- // written back to localeData so the rest of the create flow (file
137
- // writes, indexing) sees the cleaned form.
138
- const validation = normalizeAndValidatePathname(pathname);
139
- if (!validation.valid) {
140
- return {
141
- valid: false,
142
- error: `Invalid pathname for locale ${locale}: ${validation.message}`,
143
- reason: 'invalid_pathname',
144
- };
145
- }
146
- localeData.pathname = validation.value;
147
- const normalized = validation.value;
148
- // Check if pathname is already taken
149
- const existingId = site.getPathnameConflict(normalized, locale);
150
- if (existingId) {
151
- return {
152
- valid: false,
153
- error: `Pathname ${normalized} already exists`,
154
- reason: 'pathname_taken',
155
- existingId,
156
- };
157
- }
161
+ // The tidied path is written back to localeData so the rest of the
162
+ // create flow (file writes, indexing) sees the cleaned form.
163
+ const checked = checkPagePathname(site, pathname, locale);
164
+ if (!checked.valid)
165
+ return checked;
166
+ localeData.pathname = checked.pathname;
158
167
  // Check if pathname is in redirects
159
- if (site.isPathnameInRedirects(normalized, locale)) {
168
+ if (site.isPathnameInRedirects(checked.pathname, locale)) {
160
169
  return {
161
170
  valid: false,
162
- error: `Pathname ${normalized} is already in use as a redirect`,
171
+ error: `Pathname ${checked.pathname} is already in use as a redirect`,
163
172
  reason: 'pathname_in_redirects',
173
+ field: 'pathname',
164
174
  };
165
175
  }
166
176
  }
167
177
  }
168
- // Validate block name uniqueness
169
- if (data.kind === 'block') {
170
- if (!data.name) {
171
- return {
172
- valid: false,
173
- error: 'Block name is required',
174
- reason: 'invalid_name',
175
- };
176
- }
177
- // Validate block name format
178
- if (!blocks.isBlockNameValid(data.name)) {
179
- return {
180
- valid: false,
181
- error: `Invalid block name: ${data.name}. Block names must contain only alphanumeric characters, hyphens, and underscores.`,
182
- reason: 'invalid_name',
183
- };
184
- }
185
- // Check if name is already taken in any locale
186
- const existingId = blocks.getNameConflict(data.collection, data.name);
187
- if (existingId) {
188
- return {
189
- valid: false,
190
- error: `Block name ${data.name} already exists in collection ${data.collection}`,
191
- reason: 'name_taken',
192
- existingId,
193
- };
194
- }
178
+ // A fragment or data entry's name
179
+ if (data.kind === 'fragment') {
180
+ const refused = checkEntryName('fragment', data.collection, data.name, (name) => fragments.isFragmentNameValid(name), (name) => fragments.getNameConflict(data.collection, name));
181
+ if (refused)
182
+ return refused;
195
183
  }
196
- // Validate data entry name uniqueness
197
184
  if (data.kind === 'data' && dataApi) {
198
- if (!data.name) {
199
- return {
200
- valid: false,
201
- error: 'Data name is required',
202
- reason: 'invalid_name',
203
- };
204
- }
205
- // Validate data name format
206
- if (!dataApi.isDataNameValid(data.name)) {
207
- return {
208
- valid: false,
209
- error: `Invalid data name: ${data.name}. Data names must contain only alphanumeric characters, hyphens, and underscores.`,
210
- reason: 'invalid_name',
211
- };
212
- }
213
- // Check if name is already taken in any locale
214
- const existingId = dataApi.getNameConflict(data.collection, data.name);
215
- if (existingId) {
216
- return {
217
- valid: false,
218
- error: `Data name ${data.name} already exists in collection ${data.collection}`,
219
- reason: 'name_taken',
220
- existingId,
221
- };
222
- }
185
+ const refused = checkEntryName('data', data.collection, data.name, (name) => dataApi.isDataNameValid(name), (name) => dataApi.getNameConflict(data.collection, name));
186
+ if (refused)
187
+ return refused;
223
188
  }
224
189
  return { valid: true };
225
190
  }
191
+ /**
192
+ * Why a new entry cannot be stored in `collection` under `locales`, or null when it can. Both are
193
+ * part of the entry's file path, so a collection must be a plain folder name and a locale a
194
+ * language code the file layout reads back: '../x' in either would put the file somewhere else.
195
+ */
196
+ export function checkEntryPlace(collection, locales) {
197
+ if (!collection) {
198
+ return { valid: false, reason: 'invalid_collection', error: 'Collection name is required', field: 'collection' };
199
+ }
200
+ if (!/^[a-zA-Z0-9_-]+$/.test(collection)) {
201
+ return {
202
+ valid: false,
203
+ reason: 'invalid_collection',
204
+ error: `Invalid collection name: ${collection}. Collection names must contain only alphanumeric characters, hyphens, and underscores.`,
205
+ field: 'collection',
206
+ };
207
+ }
208
+ const malformed = locales.find((locale) => !isContentLocale(locale));
209
+ if (malformed !== undefined) {
210
+ return {
211
+ valid: false,
212
+ reason: 'invalid_locale',
213
+ error: `Invalid locale: ${malformed}. A locale is a two-letter language code, optionally with a region, like en or en-US.`,
214
+ field: 'locales',
215
+ };
216
+ }
217
+ return null;
218
+ }
219
+ /**
220
+ * Why a new page of `site` cannot be stored under `locales`, or null when it can: each must be a
221
+ * language the site is set up for (`siteLocales`), in the same capitals. The site's pages are read
222
+ * back only in those languages, and a file in another one lands on a page's file: 'EN' on a macOS
223
+ * or Windows disk is the 'en' file, and in an MDX pages folder 'fr' is read as a path folder.
224
+ */
225
+ export function checkPageLocales(site, siteLocales, locales) {
226
+ const unsupported = locales.find((locale) => !siteLocales.includes(locale));
227
+ if (unsupported === undefined)
228
+ return null;
229
+ return {
230
+ valid: false,
231
+ reason: 'invalid_locale',
232
+ error: `Invalid locale: ${unsupported}. Site ${site} is set up for ${siteLocales.join(', ')}.`,
233
+ field: 'locales',
234
+ };
235
+ }
236
+ /**
237
+ * Why `name` cannot be the name of a `kind` entry in `collection`, or null when it can: it is
238
+ * missing or malformed, or `conflictOf` finds another entry of the collection with it. The name is
239
+ * part of the entry's file path, so 'a/b' or '../x' would put the file somewhere else.
240
+ */
241
+ export function checkEntryName(kind, collection, name, isValid, conflictOf) {
242
+ const label = kind === 'fragment' ? 'Fragment' : 'Data';
243
+ if (!name) {
244
+ return { valid: false, reason: 'invalid_name', error: `${label} name is required` };
245
+ }
246
+ if (!isValid(name)) {
247
+ return {
248
+ valid: false,
249
+ reason: 'invalid_name',
250
+ error: `Invalid ${kind} name: ${name}. ${label} names must contain only alphanumeric characters, hyphens, and underscores.`,
251
+ };
252
+ }
253
+ const existingId = conflictOf(name);
254
+ if (existingId) {
255
+ return {
256
+ valid: false,
257
+ reason: 'name_taken',
258
+ error: `${label} name ${name} already exists in collection ${collection}`,
259
+ existingId,
260
+ };
261
+ }
262
+ return null;
263
+ }
264
+ /**
265
+ * `pathname` tidied as a page's path in `locale`, or why it cannot be one: it is malformed, or
266
+ * another page has it. The path names the page's file, so '/../x' would write it outside the
267
+ * content folder, and '/about/' is the file of the page at '/about'. `excludeId` is a page whose
268
+ * own path is changing; it never blocks itself. Without a `site`, only the path's form is checked.
269
+ */
270
+ export function checkPagePathname(site, pathname, locale, excludeId) {
271
+ const validation = normalizeAndValidatePathname(pathname);
272
+ if (!validation.valid) {
273
+ return {
274
+ valid: false,
275
+ reason: 'invalid_pathname',
276
+ error: `Invalid pathname for locale ${locale}: ${validation.message}`,
277
+ };
278
+ }
279
+ const tidied = validation.value;
280
+ const existingId = site?.getPathnameConflict(tidied, locale, excludeId);
281
+ if (existingId) {
282
+ return { valid: false, reason: 'pathname_taken', error: `Pathname ${tidied} already exists`, existingId };
283
+ }
284
+ return { valid: true, pathname: tidied };
285
+ }
286
+ /**
287
+ * Why a page cannot have `pathname` in `locale` in a site's MDX pages folder (sites.json
288
+ * `mdxPages`), or null when it can. In that folder a page's language is its first folder and a
289
+ * default-language page has none, so '/de/x' in the default language would be written to
290
+ * <folder>/de/x.mdx, the file of the German page at '/x', and read back as that page. `locales`
291
+ * are the languages the folder reads as a first folder. They match in any capitals: macOS and
292
+ * Windows disks treat <folder>/pt-br/x.mdx and <folder>/pt-BR/x.mdx as one file.
293
+ */
294
+ export function checkMdxPagesPathname(pathname, locale, folder) {
295
+ if (locale !== folder.defaultLocale)
296
+ return null;
297
+ const [first, ...rest] = pathname.slice(1).split('/');
298
+ if (rest.length === 0)
299
+ return null;
300
+ const kept = [...folder.locales].find((folderLocale) => folderLocale.toLowerCase() === first.toLowerCase());
301
+ if (kept === undefined)
302
+ return null;
303
+ return {
304
+ valid: false,
305
+ reason: 'invalid_pathname',
306
+ error: `Invalid pathname for locale ${locale}: Path cannot start with \`/${first}/\`: the MDX pages folder keeps the ${kept} pages there`,
307
+ };
308
+ }
226
309
  /**
227
310
  * Generate a new content ID
228
311
  */
@@ -273,3 +356,4 @@ export function shouldUpdateModifiedTimestamp(data) {
273
356
  const scope = analyzeUpdateScope(data);
274
357
  return scope !== UPDATE_SCOPE.NONE;
275
358
  }
359
+ //# sourceMappingURL=content-operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-operations.js","sourceRoot":"","sources":["../src/content-operations.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAsCzG;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAA0B;IACnE,0BAA0B;IAC1B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,+BAA+B;SACvC,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAgB,CAAC,CAAC,+BAA+B;IACjG,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;IAE3D,IAAI,QAAQ,GAAG,IAAI,EAAE,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;IAChE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9F,KAAK,IAAI,YAAY,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAC/B,KAAK,IAAI,YAAY,CAAC,OAAO,CAAC;IAChC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAAC,IAAsB;IAClE,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,KAAK,KAAK,YAAY,CAAC,IAAI,CAAC;AACrC,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The ONE locale/path grammar for content files.
3
+ *
4
+ * Every reader that turns a storage path back into content identity parses it
5
+ * here: the pure header parser, the filesystem indexer, and any other reader
6
+ * of content files. Each of those used to carry its own copy of the
7
+ * regex and the copies disagreed — a copy that refused `about.EN.mdx`
8
+ * made content the index had accepted unreadable, and an indexer copy
9
+ * matching `\w+` filed `about.en-US.mdx` under a fallback locale with no
10
+ * pathname at all.
11
+ *
12
+ * Zero imports on purpose: some consumers embed this module where nothing
13
+ * effectful may run at import time.
14
+ */
15
+ /**
16
+ * Whether `locale` is one this grammar reads back. A writer checks a new entry's locale with it:
17
+ * the locale is spliced into the file path, so anything else is either unreadable or, like
18
+ * '../x', a path out of the entry's folder.
19
+ */
20
+ export declare function isContentLocale(locale: string): boolean;
21
+ export type ContentFileExtension = 'mdx' | 'vxjson' | 'json';
22
+ export interface LocaleFilename {
23
+ /** Filename with the `.<locale>.<ext>` suffix removed. */
24
+ base: string;
25
+ /** Locale exactly as written in the filename. */
26
+ locale: string;
27
+ extension: ContentFileExtension;
28
+ }
29
+ /** Split `<base>.<locale>.<ext>`. Null when the filename carries no locale suffix. */
30
+ export declare function parseLocaleFilename(filename: string): LocaleFilename | null;
31
+ export interface ContentPathLayout {
32
+ kind: 'fragment' | 'page' | 'data';
33
+ site?: string;
34
+ collection: string;
35
+ locale: string;
36
+ pathname?: string;
37
+ name?: string;
38
+ }
39
+ /**
40
+ * Pure path → identity mapper. Returns null when the path doesn't match any
41
+ * supported layout or lacks an explicit locale suffix.
42
+ *
43
+ * Layouts honoured here mirror filesystem-content-api.ts:137-144:
44
+ *
45
+ * - `fragments/<collection>/<name>.<locale>.{mdx,vxjson}` (collection required;
46
+ * `fragments/<name>.<locale>.ext` is a legacy form that FileSystemContentAPI
47
+ * repairs by renaming. The pure parser refuses it.)
48
+ * - `data/<collection>/<name>.<locale>.json`
49
+ * - `<site>/<collection>/<path...>/<file>.<locale>.{vxjson,mdx}` (pages; `index`
50
+ * basename maps to the parent path).
51
+ *
52
+ * Reads accept .mdx pages even though the filesystem writer emits main-layout
53
+ * pages as .vxjson only (its mdx pages live under the separate mdxPagesRoot):
54
+ * another writer may derive the extension from the content type, so an
55
+ * mdx-typed page can land here as <site>/pages/<f>.<l>.mdx and must re-parse —
56
+ * dropping it made written pages unreadable.
57
+ */
58
+ export declare function parseContentPathLayout(path: string): ContentPathLayout | null;
59
+ //# sourceMappingURL=content-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-path.d.ts","sourceRoot":"","sources":["../src/content-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAiBH;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEvD;AAKD,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE7D,MAAM,WAAW,cAAc;IAC7B,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,oBAAoB,CAAC;CACjC;AAED,sFAAsF;AACtF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAI3E;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAyB7E"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The ONE locale/path grammar for content files.
3
+ *
4
+ * Every reader that turns a storage path back into content identity parses it
5
+ * here: the pure header parser, the filesystem indexer, and any other reader
6
+ * of content files. Each of those used to carry its own copy of the
7
+ * regex and the copies disagreed — a copy that refused `about.EN.mdx`
8
+ * made content the index had accepted unreadable, and an indexer copy
9
+ * matching `\w+` filed `about.en-US.mdx` under a fallback locale with no
10
+ * pathname at all.
11
+ *
12
+ * Zero imports on purpose: some consumers embed this module where nothing
13
+ * effectful may run at import time.
14
+ */
15
+ /**
16
+ * A two-letter language subtag, optionally followed by a two-letter upper-case
17
+ * region (`en`, `nl`, `en-US`). Case is PRESERVED, never normalized: writers
18
+ * splice this exact string back into the filename (`getFilePath`, and any other
19
+ * writer of content files), so lower-casing it here would make a repo holding
20
+ * `about.EN.mdx` save its next edit to `about.en.mdx` and orphan the original.
21
+ *
22
+ * Wider BCP-47 forms (three-letter languages, script subtags like `zh-Hans`,
23
+ * lower-case regions) are deliberately NOT accepted: no spec text defines the
24
+ * grammar, and every writer in the system emits this shape today.
25
+ */
26
+ const LOCALE_SUBTAG = '[a-zA-Z]{2}(?:-[A-Z]{2})?';
27
+ const LOCALE = new RegExp(`^${LOCALE_SUBTAG}$`);
28
+ /**
29
+ * Whether `locale` is one this grammar reads back. A writer checks a new entry's locale with it:
30
+ * the locale is spliced into the file path, so anything else is either unreadable or, like
31
+ * '../x', a path out of the entry's folder.
32
+ */
33
+ export function isContentLocale(locale) {
34
+ return LOCALE.test(locale);
35
+ }
36
+ /** `<base>.<locale>.<ext>` — the filename half of every content layout. */
37
+ const LOCALE_FILENAME = new RegExp(`^(.+)\\.(${LOCALE_SUBTAG})\\.(mdx|vxjson|json)$`);
38
+ /** Split `<base>.<locale>.<ext>`. Null when the filename carries no locale suffix. */
39
+ export function parseLocaleFilename(filename) {
40
+ const match = LOCALE_FILENAME.exec(filename);
41
+ if (!match)
42
+ return null;
43
+ return { base: match[1], locale: match[2], extension: match[3] };
44
+ }
45
+ /**
46
+ * Pure path → identity mapper. Returns null when the path doesn't match any
47
+ * supported layout or lacks an explicit locale suffix.
48
+ *
49
+ * Layouts honoured here mirror filesystem-content-api.ts:137-144:
50
+ *
51
+ * - `fragments/<collection>/<name>.<locale>.{mdx,vxjson}` (collection required;
52
+ * `fragments/<name>.<locale>.ext` is a legacy form that FileSystemContentAPI
53
+ * repairs by renaming. The pure parser refuses it.)
54
+ * - `data/<collection>/<name>.<locale>.json`
55
+ * - `<site>/<collection>/<path...>/<file>.<locale>.{vxjson,mdx}` (pages; `index`
56
+ * basename maps to the parent path).
57
+ *
58
+ * Reads accept .mdx pages even though the filesystem writer emits main-layout
59
+ * pages as .vxjson only (its mdx pages live under the separate mdxPagesRoot):
60
+ * another writer may derive the extension from the content type, so an
61
+ * mdx-typed page can land here as <site>/pages/<f>.<l>.mdx and must re-parse —
62
+ * dropping it made written pages unreadable.
63
+ */
64
+ export function parseContentPathLayout(path) {
65
+ const parts = path.split('/').filter(Boolean);
66
+ if (parts.length < 3)
67
+ return null;
68
+ const suffix = parseLocaleFilename(parts[parts.length - 1]);
69
+ if (!suffix)
70
+ return null;
71
+ if (parts[0] === 'fragments') {
72
+ if (parts.length !== 3 || suffix.extension === 'json')
73
+ return null;
74
+ return { kind: 'fragment', collection: parts[1], name: suffix.base, locale: suffix.locale };
75
+ }
76
+ if (parts[0] === 'data') {
77
+ if (parts.length !== 3 || suffix.extension !== 'json')
78
+ return null;
79
+ return { kind: 'data', collection: parts[1], name: suffix.base, locale: suffix.locale };
80
+ }
81
+ if (suffix.extension === 'json')
82
+ return null;
83
+ const pathParts = parts.slice(2);
84
+ pathParts[pathParts.length - 1] = suffix.base;
85
+ const pathname = pathParts[pathParts.length - 1] === 'index' ? `/${pathParts.slice(0, -1).join('/')}` : `/${pathParts.join('/')}`;
86
+ return { kind: 'page', site: parts[0], collection: parts[1], locale: suffix.locale, pathname };
87
+ }
88
+ //# sourceMappingURL=content-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-path.js","sourceRoot":"","sources":["../src/content-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAElD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,aAAa,GAAG,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED,2EAA2E;AAC3E,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,YAAY,aAAa,wBAAwB,CAAC,CAAC;AAYtF,sFAAsF;AACtF,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAClD,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAyB,EAAE,CAAC;AAC3F,CAAC;AAWD;;;;;;;;;;;;;;;;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M,CAAC,IAAI,CAAC;IAC9C,MAAM,QAAQ,GACZ,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAEnH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;AACjG,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { ContentAPIOptions } from './types';
1
+ import type { ContentAPIOptions } from './types.js';
2
2
  export type ContentReaderOptions = ContentAPIOptions;
3
3
  /**
4
4
  * Creates a read-oriented content API instance for build-time consumers.
@@ -6,5 +6,5 @@ export type ContentReaderOptions = ContentAPIOptions;
6
6
  * The filesystem implementation is loaded lazily so build tooling does not
7
7
  * eagerly traverse native hashing dependencies through the reader entrypoint.
8
8
  */
9
- export declare function createContentAPI(options: ContentReaderOptions): Promise<import("./filesystem-content-api").FileSystemContentAPI>;
9
+ export declare function createContentAPI(options: ContentReaderOptions): Promise<import("./filesystem-content-api.js").FileSystemContentAPI>;
10
10
  //# sourceMappingURL=content-reader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"content-reader.d.ts","sourceRoot":"","sources":["../src/content-reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAErD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,oEAOnE"}
1
+ {"version":3,"file":"content-reader.d.ts","sourceRoot":"","sources":["../src/content-reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAErD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,uEAOnE"}
@@ -5,9 +5,10 @@
5
5
  * eagerly traverse native hashing dependencies through the reader entrypoint.
6
6
  */
7
7
  export async function createContentAPI(options) {
8
- const { FileSystemContentAPI: ReaderAPI } = await import('./filesystem-content-api');
8
+ const { FileSystemContentAPI: ReaderAPI } = await import('./filesystem-content-api.js');
9
9
  return ReaderAPI.create({
10
10
  ...options,
11
11
  canvasDir: options.canvasDir || './canvas',
12
12
  });
13
13
  }
14
+ //# sourceMappingURL=content-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-reader.js","sourceRoot":"","sources":["../src/content-reader.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAA6B;IAClE,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC;IAExF,OAAO,SAAS,CAAC,MAAM,CAAC;QACtB,GAAG,OAAO;QACV,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,UAAU;KAC3C,CAAC,CAAC;AACL,CAAC"}