@conloca/astro-cms 0.1.15 → 0.1.16

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 (160) hide show
  1. package/README.md +65 -5
  2. package/dist/collections-Bd7EME4b.mjs +129 -0
  3. package/dist/collections-Bd7EME4b.mjs.map +1 -0
  4. package/dist/collections.d.mts +0 -1
  5. package/dist/collections.d.mts.map +1 -1
  6. package/dist/collections.mjs +1 -64
  7. package/dist/components.d.mts +2 -7
  8. package/dist/components.d.mts.map +1 -1
  9. package/dist/components.mjs +3 -6
  10. package/dist/components.mjs.map +1 -1
  11. package/dist/hydration.d.mts +2 -2
  12. package/dist/hydration.mjs +2 -3
  13. package/dist/index.d.mts +6 -37
  14. package/dist/index.d.mts.map +1 -1
  15. package/dist/index.mjs +7 -6
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/internal/cms-handler.d.mts +0 -1
  18. package/dist/internal/cms-handler.d.mts.map +1 -1
  19. package/dist/internal/cms-handler.mjs +55 -8
  20. package/dist/internal/cms-handler.mjs.map +1 -1
  21. package/dist/lib/hydration-script.d.mts +1 -2
  22. package/dist/lib/hydration-script.d.mts.map +1 -1
  23. package/dist/lib/hydration-script.mjs +1 -2
  24. package/dist/lib/hydration-script.mjs.map +1 -1
  25. package/dist/locales-helpers-BvYYqnJ5.d.mts +64 -0
  26. package/dist/locales-helpers-BvYYqnJ5.d.mts.map +1 -0
  27. package/dist/locales-helpers-qiwh7nxS.mjs +54 -0
  28. package/dist/locales-helpers-qiwh7nxS.mjs.map +1 -0
  29. package/dist/node/content.d.mts +0 -1
  30. package/dist/node/content.d.mts.map +1 -1
  31. package/dist/node/content.d.ts +3 -0
  32. package/dist/node/content.d.ts.map +1 -0
  33. package/dist/node/content.js +2 -0
  34. package/dist/node/content.mjs +2 -4
  35. package/dist/node/index.d.mts +151 -3
  36. package/dist/node/index.d.mts.map +1 -1
  37. package/dist/node/index.d.ts +4 -0
  38. package/dist/node/index.d.ts.map +1 -0
  39. package/dist/node/index.js +3 -0
  40. package/dist/node/index.mjs +1857 -97
  41. package/dist/node/index.mjs.map +1 -1
  42. package/dist/{serialize-props-Dhv_MnkY.mjs → serialize-props-BHoNpzH6.mjs} +2 -3
  43. package/dist/{serialize-props-Dhv_MnkY.mjs.map → serialize-props-BHoNpzH6.mjs.map} +1 -1
  44. package/dist/src/cms-handler.d.ts +19 -0
  45. package/dist/src/cms-handler.d.ts.map +1 -0
  46. package/dist/src/cms-handler.js +366 -0
  47. package/dist/src/collections.d.ts +32 -0
  48. package/dist/src/collections.d.ts.map +1 -0
  49. package/dist/src/collections.js +50 -0
  50. package/dist/src/components/HydrationWrapper.d.ts +18 -0
  51. package/dist/src/components/HydrationWrapper.d.ts.map +1 -0
  52. package/dist/src/components/HydrationWrapper.js +21 -0
  53. package/dist/src/components/RenderWithBlocks.d.ts +23 -0
  54. package/dist/src/components/RenderWithBlocks.d.ts.map +1 -0
  55. package/dist/src/components/RenderWithBlocks.js +129 -0
  56. package/dist/src/components/RenderWithHydration.d.ts +17 -0
  57. package/dist/src/components/RenderWithHydration.d.ts.map +1 -0
  58. package/dist/src/components/RenderWithHydration.js +36 -0
  59. package/dist/src/components.d.ts +4 -0
  60. package/dist/src/components.d.ts.map +1 -0
  61. package/dist/src/components.js +3 -0
  62. package/dist/src/discovery/astro-frontmatter.d.ts +18 -0
  63. package/dist/src/discovery/astro-frontmatter.d.ts.map +1 -0
  64. package/dist/src/discovery/astro-frontmatter.js +24 -0
  65. package/dist/src/discovery/extract-props-ts.d.ts +41 -0
  66. package/dist/src/discovery/extract-props-ts.d.ts.map +1 -0
  67. package/dist/src/discovery/extract-props-ts.js +231 -0
  68. package/dist/src/discovery/merge-registry.d.ts +58 -0
  69. package/dist/src/discovery/merge-registry.d.ts.map +1 -0
  70. package/dist/src/discovery/merge-registry.js +332 -0
  71. package/dist/src/discovery/registry-endpoint.d.ts +42 -0
  72. package/dist/src/discovery/registry-endpoint.d.ts.map +1 -0
  73. package/dist/src/discovery/registry-endpoint.js +81 -0
  74. package/dist/src/discovery/scan-components.d.ts +98 -0
  75. package/dist/src/discovery/scan-components.d.ts.map +1 -0
  76. package/dist/src/discovery/scan-components.js +399 -0
  77. package/dist/src/discovery/scan-mdx.d.ts +63 -0
  78. package/dist/src/discovery/scan-mdx.d.ts.map +1 -0
  79. package/dist/src/discovery/scan-mdx.js +112 -0
  80. package/dist/src/discovery/scan-overrides.d.ts +71 -0
  81. package/dist/src/discovery/scan-overrides.d.ts.map +1 -0
  82. package/dist/src/discovery/scan-overrides.js +33 -0
  83. package/dist/src/hydration.d.ts +4 -0
  84. package/dist/src/hydration.d.ts.map +1 -0
  85. package/dist/src/hydration.js +4 -0
  86. package/dist/src/index.d.ts +11 -0
  87. package/dist/src/index.d.ts.map +1 -0
  88. package/dist/src/index.js +25 -0
  89. package/dist/src/lib/hydration-scanner.d.ts +47 -0
  90. package/dist/src/lib/hydration-scanner.d.ts.map +1 -0
  91. package/dist/src/lib/hydration-scanner.js +135 -0
  92. package/dist/src/lib/hydration-script.d.ts +28 -0
  93. package/dist/src/lib/hydration-script.d.ts.map +1 -0
  94. package/dist/src/lib/hydration-script.js +88 -0
  95. package/dist/src/lib/hydration-utils.d.ts +51 -0
  96. package/dist/src/lib/hydration-utils.d.ts.map +1 -0
  97. package/dist/src/lib/hydration-utils.js +83 -0
  98. package/dist/src/lib/page-api.d.ts +77 -0
  99. package/dist/src/lib/page-api.d.ts.map +1 -0
  100. package/dist/src/lib/page-api.js +121 -0
  101. package/dist/src/lib/route-utils.d.ts +41 -0
  102. package/dist/src/lib/route-utils.d.ts.map +1 -0
  103. package/dist/src/lib/route-utils.js +78 -0
  104. package/dist/src/lib/routing-config.d.ts +32 -0
  105. package/dist/src/lib/routing-config.d.ts.map +1 -0
  106. package/dist/src/lib/routing-config.js +93 -0
  107. package/dist/src/lib/serialize-props.d.ts +6 -0
  108. package/dist/src/lib/serialize-props.d.ts.map +1 -0
  109. package/dist/src/lib/serialize-props.js +7 -0
  110. package/dist/src/lib/virtual-module-generators.d.ts +57 -0
  111. package/dist/src/lib/virtual-module-generators.d.ts.map +1 -0
  112. package/dist/src/lib/virtual-module-generators.js +263 -0
  113. package/dist/src/lib/withHydration.d.ts +51 -0
  114. package/dist/src/lib/withHydration.d.ts.map +1 -0
  115. package/dist/src/lib/withHydration.js +49 -0
  116. package/dist/src/loader.d.ts +14 -0
  117. package/dist/src/loader.d.ts.map +1 -0
  118. package/dist/src/loader.js +89 -0
  119. package/dist/src/locales-helpers.d.ts +61 -0
  120. package/dist/src/locales-helpers.d.ts.map +1 -0
  121. package/dist/src/locales-helpers.js +49 -0
  122. package/dist/src/mime-types.d.ts +3 -0
  123. package/dist/src/mime-types.d.ts.map +1 -0
  124. package/dist/src/mime-types.js +19 -0
  125. package/dist/src/path-validation.d.ts +8 -0
  126. package/dist/src/path-validation.d.ts.map +1 -0
  127. package/dist/src/path-validation.js +12 -0
  128. package/dist/src/plugin-spa.d.ts +164 -0
  129. package/dist/src/plugin-spa.d.ts.map +1 -0
  130. package/dist/src/plugin-spa.js +972 -0
  131. package/dist/src/safe-json-stringify.d.ts +13 -0
  132. package/dist/src/safe-json-stringify.d.ts.map +1 -0
  133. package/dist/src/safe-json-stringify.js +6 -0
  134. package/dist/src/site-styles/content-wrapper-endpoint.d.ts +76 -0
  135. package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
  136. package/dist/src/site-styles/content-wrapper-endpoint.js +227 -0
  137. package/dist/src/site-styles/render-endpoint.d.ts +55 -0
  138. package/dist/src/site-styles/render-endpoint.d.ts.map +1 -0
  139. package/dist/src/site-styles/render-endpoint.js +263 -0
  140. package/dist/src/site-styles/styles-endpoint.d.ts +61 -0
  141. package/dist/src/site-styles/styles-endpoint.d.ts.map +1 -0
  142. package/dist/src/site-styles/styles-endpoint.js +158 -0
  143. package/dist/src/types.d.ts +627 -0
  144. package/dist/src/types.d.ts.map +1 -0
  145. package/dist/src/types.js +1 -0
  146. package/dist/{types-CVQNmPxF.d.mts → types-CS9neadI.d.mts} +193 -3
  147. package/dist/types-CS9neadI.d.mts.map +1 -0
  148. package/dist/virtual-modules.d.ts +155 -0
  149. package/dist/{withHydration-EzyzBQ-Y.mjs → withHydration-C256ox_6.mjs} +2 -2
  150. package/dist/{withHydration-EzyzBQ-Y.mjs.map → withHydration-C256ox_6.mjs.map} +1 -1
  151. package/dist/{withHydration-HIvO9ysY.d.mts → withHydration-DkKpkmzJ.d.mts} +1 -2
  152. package/dist/withHydration-DkKpkmzJ.d.mts.map +1 -0
  153. package/package.json +82 -26
  154. package/dist/collections.mjs.map +0 -1
  155. package/dist/hydration-scanner-B0NjYkZ_.mjs +0 -109
  156. package/dist/hydration-scanner-B0NjYkZ_.mjs.map +0 -1
  157. package/dist/loader-By-AQWHc.mjs +0 -68
  158. package/dist/loader-By-AQWHc.mjs.map +0 -1
  159. package/dist/types-CVQNmPxF.d.mts.map +0 -1
  160. package/dist/withHydration-HIvO9ysY.d.mts.map +0 -1
@@ -0,0 +1,121 @@
1
+ import { createContentAPI } from '@conloca/content-api/reader';
2
+ /**
3
+ * Error class for page not found scenarios.
4
+ */
5
+ export class PageNotFoundError extends Error {
6
+ code = 'PAGE_NOT_FOUND';
7
+ constructor(pathname) {
8
+ super(`Page not found: ${pathname}`);
9
+ this.name = 'PageNotFoundError';
10
+ }
11
+ }
12
+ /**
13
+ * Create a PageAPI instance for loading page data.
14
+ *
15
+ * Wraps ContentAPI with a cleaner interface focused on
16
+ * page rendering needs.
17
+ *
18
+ * @param options - Configuration for ContentAPI initialization
19
+ * @returns PageAPI instance
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const api = await createPageAPI({
24
+ * contentRoot: '../content',
25
+ * canvasDir: './canvas',
26
+ * });
27
+ *
28
+ * const pages = await api.getAllPages('pages');
29
+ * const page = await api.getPage('/about');
30
+ * ```
31
+ */
32
+ export async function createPageAPI(options) {
33
+ const contentApi = await createContentAPI({
34
+ contentRoot: options.contentRoot,
35
+ canvasDir: options.canvasDir,
36
+ });
37
+ const siteName = options.siteName || 'default';
38
+ const locale = options.locale || 'en';
39
+ // Get the site for page operations
40
+ const site = contentApi.getSite(siteName);
41
+ if (!site) {
42
+ throw new Error(`Site '${siteName}' not found in content configuration`);
43
+ }
44
+ return {
45
+ async getAllPages(collection) {
46
+ const pages = [];
47
+ // Use site.listPages() generator to get all pages
48
+ for (const manifest of site.listPages(locale)) {
49
+ // Filter by collection if specified
50
+ if (collection && manifest.collection !== collection) {
51
+ continue;
52
+ }
53
+ // Get the localized data for pathname
54
+ const localeData = manifest.locales[locale];
55
+ if (!localeData)
56
+ continue;
57
+ pages.push({
58
+ id: manifest.id,
59
+ pathname: localeData.pathname || `/${manifest.id.replace(/^index$/, '')}`,
60
+ title: localeData.meta?.title || manifest.id,
61
+ collection: manifest.collection || 'pages',
62
+ });
63
+ }
64
+ return pages;
65
+ },
66
+ async getPage(pathname, collection) {
67
+ // Use site.getByPathname to find the content by pathname
68
+ const manifest = site.getByPathname(pathname, locale);
69
+ if (!manifest) {
70
+ throw new PageNotFoundError(pathname);
71
+ }
72
+ // Optionally filter by collection
73
+ if (collection && manifest.collection !== collection) {
74
+ throw new PageNotFoundError(pathname);
75
+ }
76
+ // Get the full content with locale data
77
+ const content = await contentApi.getLocalized(manifest.id, locale);
78
+ if (!content) {
79
+ throw new PageNotFoundError(pathname);
80
+ }
81
+ const localeData = content.localized;
82
+ const meta = localeData.meta || {};
83
+ return {
84
+ id: manifest.id,
85
+ title: meta.title || manifest.id,
86
+ description: meta.description,
87
+ pathname,
88
+ puckData: localeData.content.puckData,
89
+ collection: manifest.collection || collection || 'pages',
90
+ route: {
91
+ // These will be overwritten by the caller with actual route info
92
+ name: 'pages',
93
+ pattern: '/[...slug]',
94
+ meta: {},
95
+ },
96
+ meta,
97
+ timestamps: {
98
+ created: localeData.created ? new Date(localeData.created) : undefined,
99
+ modified: localeData.modified ? new Date(localeData.modified) : undefined,
100
+ },
101
+ };
102
+ },
103
+ async pageExists(pathname, collection) {
104
+ try {
105
+ // Use site.getByPathname to check existence
106
+ const manifest = site.getByPathname(pathname, locale);
107
+ if (!manifest) {
108
+ return false;
109
+ }
110
+ // If collection filter specified, verify it matches
111
+ if (collection && manifest.collection !== collection) {
112
+ return false;
113
+ }
114
+ return true;
115
+ }
116
+ catch {
117
+ return false;
118
+ }
119
+ },
120
+ };
121
+ }
@@ -0,0 +1,41 @@
1
+ export declare function toDate(value: string | Date | null | undefined): Date | undefined;
2
+ interface PublishSchedule {
3
+ publishAt?: string | Date | null;
4
+ unpublishAt?: string | Date | null;
5
+ }
6
+ export declare function isPublished(data: PublishSchedule): boolean;
7
+ /**
8
+ * Extract slug from pathname given a route pattern.
9
+ *
10
+ * The slug is the portion of the pathname that comes after the
11
+ * static prefix of the pattern.
12
+ *
13
+ * @param pathname - URL pathname (e.g., '/about', '/blog/post-1')
14
+ * @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')
15
+ * @returns The extracted slug, or undefined for root paths
16
+ *
17
+ * @example
18
+ * extractSlugFromPathname('/about', '/[...slug]') // 'about'
19
+ * extractSlugFromPathname('/blog/post-1', '/blog/[...slug]') // 'post-1'
20
+ * extractSlugFromPathname('/', '/[...slug]') // undefined
21
+ * extractSlugFromPathname('/blog', '/blog/[...slug]') // undefined
22
+ */
23
+ export declare function extractSlugFromPathname(pathname: string, pattern: string): string | undefined;
24
+ /**
25
+ * Convert a slug back to a pathname given a route pattern.
26
+ *
27
+ * The inverse of extractSlugFromPathname.
28
+ *
29
+ * @param slug - The page slug (e.g., 'about', 'post-1'), or undefined for root
30
+ * @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')
31
+ * @returns Full URL pathname
32
+ *
33
+ * @example
34
+ * pathnameFromSlug('about', '/[...slug]') // '/about'
35
+ * pathnameFromSlug('post-1', '/blog/[...slug]') // '/blog/post-1'
36
+ * pathnameFromSlug(undefined, '/[...slug]') // '/'
37
+ * pathnameFromSlug(undefined, '/blog/[...slug]') // '/blog'
38
+ */
39
+ export declare function pathnameFromSlug(slug: string | undefined, pattern: string): string;
40
+ export {};
41
+ //# sourceMappingURL=route-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/route-utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,oBAY7D;AAED,UAAU,eAAe;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACpC;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,WAchD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAiB7F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAYlF"}
@@ -0,0 +1,78 @@
1
+ export function toDate(value) {
2
+ if (!value) {
3
+ return undefined;
4
+ }
5
+ if (value instanceof Date) {
6
+ return value;
7
+ }
8
+ const parsed = new Date(value);
9
+ return Number.isNaN(parsed.getTime()) ? undefined : parsed;
10
+ }
11
+ export function isPublished(data) {
12
+ const now = new Date();
13
+ const publishAt = toDate(data.publishAt);
14
+ const unpublishAt = toDate(data.unpublishAt);
15
+ if (publishAt && publishAt > now) {
16
+ return false;
17
+ }
18
+ if (unpublishAt && unpublishAt <= now) {
19
+ return false;
20
+ }
21
+ return true;
22
+ }
23
+ /**
24
+ * Extract slug from pathname given a route pattern.
25
+ *
26
+ * The slug is the portion of the pathname that comes after the
27
+ * static prefix of the pattern.
28
+ *
29
+ * @param pathname - URL pathname (e.g., '/about', '/blog/post-1')
30
+ * @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')
31
+ * @returns The extracted slug, or undefined for root paths
32
+ *
33
+ * @example
34
+ * extractSlugFromPathname('/about', '/[...slug]') // 'about'
35
+ * extractSlugFromPathname('/blog/post-1', '/blog/[...slug]') // 'post-1'
36
+ * extractSlugFromPathname('/', '/[...slug]') // undefined
37
+ * extractSlugFromPathname('/blog', '/blog/[...slug]') // undefined
38
+ */
39
+ export function extractSlugFromPathname(pathname, pattern) {
40
+ // Pattern: /[...slug] -> prefix: ''
41
+ // Pattern: /blog/[...slug] -> prefix: '/blog'
42
+ // Pattern: /docs/[...path] -> prefix: '/docs'
43
+ const prefixMatch = pattern.match(/^(.*?)\[/);
44
+ const prefix = prefixMatch ? prefixMatch[1].replace(/\/$/, '') : '';
45
+ // Remove prefix from pathname
46
+ const slugPart = pathname.slice(prefix.length);
47
+ // Remove leading slash
48
+ const slug = slugPart.replace(/^\//, '');
49
+ // Empty string means root page (e.g., /blog for /blog/[...slug])
50
+ // Return undefined for root to match [...slug] behavior
51
+ return slug || undefined;
52
+ }
53
+ /**
54
+ * Convert a slug back to a pathname given a route pattern.
55
+ *
56
+ * The inverse of extractSlugFromPathname.
57
+ *
58
+ * @param slug - The page slug (e.g., 'about', 'post-1'), or undefined for root
59
+ * @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')
60
+ * @returns Full URL pathname
61
+ *
62
+ * @example
63
+ * pathnameFromSlug('about', '/[...slug]') // '/about'
64
+ * pathnameFromSlug('post-1', '/blog/[...slug]') // '/blog/post-1'
65
+ * pathnameFromSlug(undefined, '/[...slug]') // '/'
66
+ * pathnameFromSlug(undefined, '/blog/[...slug]') // '/blog'
67
+ */
68
+ export function pathnameFromSlug(slug, pattern) {
69
+ // Extract the static prefix before the dynamic segment
70
+ const prefixMatch = pattern.match(/^(.*?)\[/);
71
+ const prefix = prefixMatch ? prefixMatch[1].replace(/\/$/, '') : '';
72
+ if (!slug) {
73
+ // No slug means root of this pattern
74
+ return prefix || '/';
75
+ }
76
+ // Combine prefix and slug
77
+ return `${prefix}/${slug}`;
78
+ }
@@ -0,0 +1,32 @@
1
+ import type { RouteConfig, RoutingConfig, RoutingConfigInput } from '../types.js';
2
+ /**
3
+ * Normalize routing config input to full RoutingConfig.
4
+ *
5
+ * Handles the `routing: true` shorthand, boolean values, and top-level layout option.
6
+ *
7
+ * @param input - The routing config input (boolean, object, or undefined)
8
+ * @param topLevelLayout - Optional top-level layout path (enables routing when provided)
9
+ * @returns Normalized RoutingConfig or undefined if not enabled
10
+ */
11
+ export declare function normalizeRoutingConfig(input: RoutingConfigInput | undefined, topLevelLayout?: string): RoutingConfig | undefined;
12
+ /**
13
+ * Apply defaults to a RouteConfig.
14
+ *
15
+ * Fills in missing optional fields with their default values.
16
+ *
17
+ * @param config - Partial route configuration
18
+ * @returns Complete route configuration with all fields
19
+ */
20
+ export declare function resolveRouteConfig(config: RouteConfig): Required<RouteConfig>;
21
+ /**
22
+ * Validate a route pattern.
23
+ *
24
+ * Ensures the pattern is a valid Astro route pattern.
25
+ * Throws descriptive error if invalid.
26
+ *
27
+ * @param pattern - The route pattern to validate
28
+ * @param routeName - Name of the route (for error messages)
29
+ * @throws Error if pattern is invalid
30
+ */
31
+ export declare function validateRoutePattern(pattern: string, routeName: string): void;
32
+ //# sourceMappingURL=routing-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routing-config.d.ts","sourceRoot":"","sources":["../../../src/lib/routing-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAElF;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,kBAAkB,GAAG,SAAS,EACrC,cAAc,CAAC,EAAE,MAAM,GACtB,aAAa,GAAG,SAAS,CA0C3B;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,CAS7E;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAkB7E"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Normalize routing config input to full RoutingConfig.
3
+ *
4
+ * Handles the `routing: true` shorthand, boolean values, and top-level layout option.
5
+ *
6
+ * @param input - The routing config input (boolean, object, or undefined)
7
+ * @param topLevelLayout - Optional top-level layout path (enables routing when provided)
8
+ * @returns Normalized RoutingConfig or undefined if not enabled
9
+ */
10
+ export function normalizeRoutingConfig(input, topLevelLayout) {
11
+ // If no routing config but layout provided, enable with defaults
12
+ if (input === undefined && topLevelLayout) {
13
+ return {
14
+ enabled: true,
15
+ routes: {
16
+ pages: {
17
+ pattern: '/[...slug]',
18
+ collection: 'pages',
19
+ layout: topLevelLayout,
20
+ prerender: true,
21
+ },
22
+ },
23
+ fallback: '404',
24
+ onConflict: 'warn',
25
+ };
26
+ }
27
+ if (input === undefined) {
28
+ return undefined;
29
+ }
30
+ if (input === true) {
31
+ return {
32
+ enabled: true,
33
+ routes: {
34
+ pages: {
35
+ pattern: '/[...slug]',
36
+ collection: 'pages',
37
+ prerender: true,
38
+ },
39
+ },
40
+ fallback: '404',
41
+ onConflict: 'warn',
42
+ };
43
+ }
44
+ if (input === false) {
45
+ return { enabled: false };
46
+ }
47
+ return input;
48
+ }
49
+ /**
50
+ * Apply defaults to a RouteConfig.
51
+ *
52
+ * Fills in missing optional fields with their default values.
53
+ *
54
+ * @param config - Partial route configuration
55
+ * @returns Complete route configuration with all fields
56
+ */
57
+ export function resolveRouteConfig(config) {
58
+ return {
59
+ pattern: config.pattern,
60
+ collection: config.collection ?? 'pages',
61
+ layout: config.layout ?? '',
62
+ prerender: config.prerender ?? true,
63
+ meta: config.meta ?? {},
64
+ dataBindings: config.dataBindings ?? { collections: [] },
65
+ };
66
+ }
67
+ /**
68
+ * Validate a route pattern.
69
+ *
70
+ * Ensures the pattern is a valid Astro route pattern.
71
+ * Throws descriptive error if invalid.
72
+ *
73
+ * @param pattern - The route pattern to validate
74
+ * @param routeName - Name of the route (for error messages)
75
+ * @throws Error if pattern is invalid
76
+ */
77
+ export function validateRoutePattern(pattern, routeName) {
78
+ if (!pattern.startsWith('/')) {
79
+ throw new Error(`Route '${routeName}': pattern must start with '/', got '${pattern}'`);
80
+ }
81
+ // Check for valid Astro route syntax
82
+ // Allow: a-zA-Z0-9, hyphen, underscore, slash, brackets, dots
83
+ const invalidChars = pattern.match(/[^a-zA-Z0-9\-_/[\].]/g);
84
+ if (invalidChars) {
85
+ throw new Error(`Route '${routeName}': pattern contains invalid characters: ${invalidChars.join(', ')}`);
86
+ }
87
+ // Check for balanced brackets
88
+ const openBrackets = (pattern.match(/\[/g) || []).length;
89
+ const closeBrackets = (pattern.match(/\]/g) || []).length;
90
+ if (openBrackets !== closeBrackets) {
91
+ throw new Error(`Route '${routeName}': pattern has unbalanced brackets: '${pattern}'`);
92
+ }
93
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Safely serialize props for embedding in HTML data attributes.
3
+ * Escapes < to prevent XSS when JSON is parsed in browser.
4
+ */
5
+ export declare function serializeProps(props: Record<string, unknown>): string;
6
+ //# sourceMappingURL=serialize-props.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-props.d.ts","sourceRoot":"","sources":["../../../src/lib/serialize-props.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAErE"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Safely serialize props for embedding in HTML data attributes.
3
+ * Escapes < to prevent XSS when JSON is parsed in browser.
4
+ */
5
+ export function serializeProps(props) {
6
+ return JSON.stringify(props).replace(/</g, '\\u003c');
7
+ }
@@ -0,0 +1,57 @@
1
+ import type { ResolvedRoutingConfig, RoutingConfig } from '../types.js';
2
+ /**
3
+ * Generate the virtual:conloca-routing-config module.
4
+ *
5
+ * Returns a module that exports the resolved routing configuration as default.
6
+ *
7
+ * @param config - Resolved routing configuration with all defaults applied
8
+ * @returns JavaScript module code as a string
9
+ */
10
+ export declare function generateRoutingConfigModule(config: ResolvedRoutingConfig): string;
11
+ /**
12
+ * Generate the virtual:conloca-layout module.
13
+ *
14
+ * Returns a module that re-exports the layout component or exports undefined
15
+ * if no layout is configured.
16
+ *
17
+ * Currently uses the first route's layout. Multi-layout support is future work.
18
+ *
19
+ * @param routing - Routing configuration (may be undefined if routing disabled)
20
+ * @returns JavaScript module code as a string
21
+ */
22
+ export declare function generateLayoutModule(routing: RoutingConfig | undefined): string;
23
+ /**
24
+ * Options for generating the page API module.
25
+ */
26
+ export interface PageApiModuleOptions {
27
+ contentRoot: string;
28
+ canvasDir: string;
29
+ /** Site name for content resolution. @default 'default' */
30
+ siteName: string;
31
+ /** Default locale for content resolution. @default 'en' */
32
+ locale: string;
33
+ }
34
+ /**
35
+ * Generate the virtual:conloca-page-api module.
36
+ *
37
+ * Returns a module that provides page loading functions wrapping ContentAPI:
38
+ * - getAllPages(collection?) - For getStaticPaths()
39
+ * - getPage(pathname, collection?) - For page data loading
40
+ * - pageExists(pathname, collection?) - For 404 checks
41
+ * - contentOptions - Configuration for ContentAPI (for MDX evaluation)
42
+ *
43
+ * @param options - Configuration for ContentAPI initialization
44
+ * @returns JavaScript module code as a string
45
+ */
46
+ export declare function generatePageApiModule(options: PageApiModuleOptions): string;
47
+ /**
48
+ * Generate the virtual:conloca-puck-config module.
49
+ *
50
+ * Returns a module that re-exports the Puck configuration.
51
+ * This is separate from the HMR-enabled puck-entry.js used by the CMS SPA.
52
+ *
53
+ * @param puckConfigPath - Path to the puck config module
54
+ * @returns JavaScript module code as a string
55
+ */
56
+ export declare function generatePuckConfigModule(puckConfigPath: string): string;
57
+ //# sourceMappingURL=virtual-module-generators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"virtual-module-generators.d.ts","sourceRoot":"","sources":["../../../src/lib/virtual-module-generators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAExE;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAEjF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,GAAG,MAAM,CAe/E;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAwM3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAMvE"}