@conloca/astro-cms 0.2.1 → 0.2.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/README.md +21 -19
- package/dist/internal/page-handler.astro +8 -2
- package/dist/ts/node/content.d.ts +1 -2
- package/dist/ts/node/content.d.ts.map +1 -1
- package/dist/ts/node/content.js +1 -1
- package/dist/ts/node/content.js.map +1 -1
- package/dist/ts/src/collections.d.ts +31 -53
- package/dist/ts/src/collections.d.ts.map +1 -1
- package/dist/ts/src/collections.js +66 -71
- package/dist/ts/src/collections.js.map +1 -1
- package/dist/ts/src/entries.d.ts +44 -0
- package/dist/ts/src/entries.d.ts.map +1 -0
- package/dist/ts/src/entries.js +48 -0
- package/dist/ts/src/entries.js.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -1
- package/dist/ts/src/handlers/collection-content-api.js +7 -2
- package/dist/ts/src/handlers/collection-content-api.js.map +1 -1
- package/dist/ts/src/handlers/collection-names.d.ts +9 -0
- package/dist/ts/src/handlers/collection-names.d.ts.map +1 -0
- package/dist/ts/src/handlers/collection-names.js +9 -0
- package/dist/ts/src/handlers/collection-names.js.map +1 -0
- package/dist/ts/src/handlers/page-render-core.d.ts +31 -12
- package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -1
- package/dist/ts/src/handlers/page-render-core.js +38 -17
- package/dist/ts/src/handlers/page-render-core.js.map +1 -1
- package/dist/ts/src/index.d.ts +2 -2
- package/dist/ts/src/index.d.ts.map +1 -1
- package/dist/ts/src/index.js +1 -3
- package/dist/ts/src/index.js.map +1 -1
- package/dist/ts/src/internal/collection-parsers.d.ts +26 -0
- package/dist/ts/src/internal/collection-parsers.d.ts.map +1 -0
- package/dist/ts/src/internal/collection-parsers.js +34 -0
- package/dist/ts/src/internal/collection-parsers.js.map +1 -0
- package/dist/ts/src/internal/entry-issues.d.ts +8 -0
- package/dist/ts/src/internal/entry-issues.d.ts.map +1 -0
- package/dist/ts/src/internal/entry-issues.js +19 -0
- package/dist/ts/src/internal/entry-issues.js.map +1 -0
- package/dist/ts/src/internal/entry-validation.d.ts +93 -0
- package/dist/ts/src/internal/entry-validation.d.ts.map +1 -0
- package/dist/ts/src/internal/entry-validation.js +228 -0
- package/dist/ts/src/internal/entry-validation.js.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts +13 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -1
- package/dist/ts/src/lib/virtual-module-generators.js +18 -0
- package/dist/ts/src/lib/virtual-module-generators.js.map +1 -1
- package/dist/ts/src/loader.d.ts +9 -12
- package/dist/ts/src/loader.d.ts.map +1 -1
- package/dist/ts/src/loader.js +19 -16
- package/dist/ts/src/loader.js.map +1 -1
- package/dist/ts/src/page-schemas.d.ts +1 -1
- package/dist/ts/src/page-schemas.d.ts.map +1 -1
- package/dist/ts/src/page-schemas.js +1 -1
- package/dist/ts/src/page-schemas.js.map +1 -1
- package/dist/ts/src/plugin-spa.d.ts +12 -0
- package/dist/ts/src/plugin-spa.d.ts.map +1 -1
- package/dist/ts/src/plugin-spa.js +9 -2
- package/dist/ts/src/plugin-spa.js.map +1 -1
- package/dist/virtual-modules.d.ts +14 -0
- package/node/content.ts +10 -1
- package/package.json +12 -9
- package/src/collections.ts +107 -76
- package/src/entries.ts +111 -0
- package/src/handlers/collection-content-api.ts +7 -2
- package/src/handlers/collection-names.ts +8 -0
- package/src/handlers/page-handler.astro +8 -2
- package/src/handlers/page-render-core.ts +65 -17
- package/src/index.ts +6 -7
- package/src/internal/collection-parsers.ts +51 -0
- package/src/internal/entry-issues.ts +23 -0
- package/src/internal/entry-validation.ts +305 -0
- package/src/lib/virtual-module-generators.ts +20 -0
- package/src/loader.ts +33 -17
- package/src/page-schemas.ts +4 -0
- package/src/plugin-spa.ts +24 -1
- package/src/virtual-modules.d.ts +14 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts +0 -44
- package/dist/ts/src/internal/page-collection-schema.d.ts.map +0 -1
- package/dist/ts/src/internal/page-collection-schema.js +0 -152
- package/dist/ts/src/internal/page-collection-schema.js.map +0 -1
- package/src/internal/page-collection-schema.ts +0 -210
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ workflow, accessible at `/__cms` routes without requiring authentication or comp
|
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
13
|
npm install @conloca/astro-cms
|
|
14
|
-
npm install @astrojs/react @vitejs/plugin-react astro react react-dom vite
|
|
14
|
+
npm install @astrojs/react @vitejs/plugin-react astro react react-dom vite typia
|
|
15
|
+
npm install -D ttsc @ttsc/unplugin
|
|
15
16
|
```
|
|
16
17
|
|
|
17
18
|
The second line is the full peer set — the CMS expects the host site to own those packages. `@astrojs/react` is not
|
|
@@ -168,24 +169,25 @@ With those four files in place, run the Astro dev server and open `/__cms`.
|
|
|
168
169
|
|
|
169
170
|
Passed to `conlocaCMS({ ... })`. Only two are required.
|
|
170
171
|
|
|
171
|
-
| Option | Required | What it does
|
|
172
|
-
| ---------------------- | -------- |
|
|
173
|
-
| `contentRoot` | yes | Directory holding `sites.json` and the content files. Also handed to the collection factories, so the content config needs no copy of it.
|
|
174
|
-
| `puckConfigPath` | yes | Module whose default export is the Puck `Config`. Supplies the visual editor's component palette and seeds component auto-discovery.
|
|
175
|
-
| `canvasDir` | no | Directory for canvas documents.
|
|
176
|
-
| `route` | no | Where the CMS mounts. Defaults to `/__cms`.
|
|
177
|
-
| `layout` | no | Default layout for content pages. On its own it enables routing with a catch-all pattern.
|
|
178
|
-
| `routing` | no | Full routing configuration, for sites with more than one content route.
|
|
179
|
-
| `templates` | no | Page templates offered in the create-page dialog.
|
|
180
|
-
| `schemasPath` | no | Module exporting `dataSchemas`, `pageSchemas` and `mdxComponents`. Drives the page-settings form and the MDX component registry.
|
|
181
|
-
| `
|
|
182
|
-
| `
|
|
183
|
-
| `
|
|
184
|
-
| `
|
|
185
|
-
| `
|
|
186
|
-
| `
|
|
187
|
-
| `
|
|
188
|
-
| `
|
|
172
|
+
| Option | Required | What it does |
|
|
173
|
+
| ---------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
174
|
+
| `contentRoot` | yes | Directory holding `sites.json` and the content files. Also handed to the collection factories, so the content config needs no copy of it. |
|
|
175
|
+
| `puckConfigPath` | yes | Module whose default export is the Puck `Config`. Supplies the visual editor's component palette and seeds component auto-discovery. |
|
|
176
|
+
| `canvasDir` | no | Directory for canvas documents. |
|
|
177
|
+
| `route` | no | Where the CMS mounts. Defaults to `/__cms`. |
|
|
178
|
+
| `layout` | no | Default layout for content pages. On its own it enables routing with a catch-all pattern. |
|
|
179
|
+
| `routing` | no | Full routing configuration, for sites with more than one content route. |
|
|
180
|
+
| `templates` | no | Page templates offered in the create-page dialog. |
|
|
181
|
+
| `schemasPath` | no | Module exporting `dataSchemas`, `pageSchemas` and `mdxComponents`. Drives the page-settings form and the MDX component registry. |
|
|
182
|
+
| `contentSchemasPath` | no | Schema-only module exporting the `pageSchemas` / `dataSchemas` your content config passes to `conlocaPages()` / `conlocaData()`. Draft previews parse entries with the entry parsers built from it, as the build does. |
|
|
183
|
+
| `componentPaths` | no | Extra folders to scan for components wrapped in `withHydration()`. |
|
|
184
|
+
| `mdxComponentFolders` | no | Folders scanned for locally authored MDX components, whose `interface Props` becomes the editor's prop panel. Defaults to `['src/components/mdx']`. |
|
|
185
|
+
| `assetsPath` | no | Upload directory; enables the Media Library. The site must serve it from `publicDir`, directly or through a link there, or dev and build fail. |
|
|
186
|
+
| `siteStyles` | no | CSS injected into the Puck preview iframe so components render with site styling. |
|
|
187
|
+
| `editorStyles` | no | CSS injected into the MDX editor's admin document. Host-component selectors only — see the file's own notes on what does not belong. |
|
|
188
|
+
| `editorCSS` | no | Raw CSS applied after auto-discovered host styles in the editor's host-preview layer. |
|
|
189
|
+
| `fragmentPreviewRoute` | no | Route whose styles and content wrapper frame the standalone fragment editor. Defaults to `/`. |
|
|
190
|
+
| `locales` | no | The site's locales and default locale. Without it: the site's `locales` and `defaultLocale` in `sites.json`, else `globalLocales`. |
|
|
189
191
|
|
|
190
192
|
`ConlocaCMSOptions` also extends the editor's `UIConfig` (minus `basename`), so fields such as `apiBaseUrl`,
|
|
191
193
|
`siteBaseUrl`, `enableDevtools`, `queryClientOptions`, `projectRoot` and `hosted` are accepted as well. Those exist for
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { getCollection } from 'astro:content';
|
|
13
|
+
import { loadContentSchemas } from 'virtual:conloca-content-schemas';
|
|
13
14
|
import Layout from 'virtual:conloca-layout';
|
|
14
15
|
import puckConfig from 'virtual:conloca-puck-config';
|
|
15
16
|
import routingConfig from 'virtual:conloca-routing-config';
|
|
@@ -37,6 +38,7 @@ import {
|
|
|
37
38
|
pageNotFoundResponse,
|
|
38
39
|
resolvePuckData,
|
|
39
40
|
} from '../ts/src/handlers/page-render-core.js';
|
|
41
|
+
import { previewEntryParsers } from '../ts/src/internal/collection-parsers.js';
|
|
40
42
|
|
|
41
43
|
// prerender is controlled by injectRoute({ prerender }) in plugin-spa.ts
|
|
42
44
|
// Do not hardcode here — it overrides the route-level config
|
|
@@ -148,11 +150,15 @@ if (!routeName || !collection || !pathname) {
|
|
|
148
150
|
|
|
149
151
|
// Content-access seam. A caller can install a ContentAPI on
|
|
150
152
|
// `Astro.locals.contentApi`; when present we read through it, so the page shows
|
|
151
|
-
// what that reader serves
|
|
153
|
+
// what that reader serves, parsed with each collection's entry parser as the build
|
|
154
|
+
// parses its entries. Absent — the normal render — we read Astro content
|
|
152
155
|
// collections, byte-for-byte identically to before the extraction.
|
|
153
156
|
const previewContentApi = (Astro.locals as { contentApi?: ContentAPI }).contentApi;
|
|
154
157
|
const source: PageContentSource = previewContentApi
|
|
155
|
-
? createReaderContentSource(previewContentApi,
|
|
158
|
+
? createReaderContentSource(previewContentApi, {
|
|
159
|
+
renderLocale: config.locale,
|
|
160
|
+
parsers: previewEntryParsers(config, await loadContentSchemas()),
|
|
161
|
+
})
|
|
156
162
|
: createCollectionContentSource({
|
|
157
163
|
getCollection: (name) => getCollection(name as never) as Promise<{ data: unknown }[]>,
|
|
158
164
|
isDev: import.meta.env.DEV,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { ALL_FRAGMENTS_COLLECTION, type ConlocaCollectionsResult, type ConlocaDataOptions, type ConlocaPagesOptions, type CreateConlocaCollectionsOptions, conlocaData, conlocaFragments, conlocaPages, createConlocaCollections, pageSchemasOf, } from '../src/collections.js';
|
|
2
|
-
export type { ConlocaPageEntry } from '../src/internal/page-collection-schema.js';
|
|
1
|
+
export { ALL_FRAGMENTS_COLLECTION, type CollectionEntryLike, type ConlocaCollectionsResult, type ConlocaDataEntry, type ConlocaDataOptions, type ConlocaFragmentEntry, type ConlocaPageEntry, type ConlocaPagesOptions, type CreateConlocaCollectionsOptions, conlocaData, conlocaDataEntries, conlocaFragmentEntries, conlocaFragments, conlocaPageEntries, conlocaPages, createConlocaCollections, type EntryParser, entryParserOf, pageSchemasOf, type TypedCollectionEntry, } from '../src/collections.js';
|
|
3
2
|
export { type ConlocaLoaderOptions, conlocaLoader } from '../src/loader.js';
|
|
4
3
|
//# sourceMappingURL=content.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../../node/content.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,EACpC,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,wBAAwB,EACxB,
|
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../../node/content.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,EACpC,WAAW,EACX,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,wBAAwB,EACxB,KAAK,WAAW,EAChB,aAAa,EACb,aAAa,EACb,KAAK,oBAAoB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/ts/node/content.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { ALL_FRAGMENTS_COLLECTION, conlocaData, conlocaFragments, conlocaPages, createConlocaCollections, pageSchemasOf, } from '../src/collections.js';
|
|
1
|
+
export { ALL_FRAGMENTS_COLLECTION, conlocaData, conlocaDataEntries, conlocaFragmentEntries, conlocaFragments, conlocaPageEntries, conlocaPages, createConlocaCollections, entryParserOf, pageSchemasOf, } from '../src/collections.js';
|
|
2
2
|
export { conlocaLoader } from '../src/loader.js';
|
|
3
3
|
//# sourceMappingURL=content.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../../node/content.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../../node/content.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EASxB,WAAW,EACX,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,wBAAwB,EAExB,aAAa,EACb,aAAa,GAEd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAA6B,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { defineCollection } from 'astro:content';
|
|
2
|
-
import type { DataSchemas, PageSchemas } from '@conloca/cms-spa/page-schema-define';
|
|
3
|
-
import {
|
|
4
|
-
import { ALL_FRAGMENTS_COLLECTION } from './handlers/
|
|
2
|
+
import type { DataSchemas, HostSchema, PageSchemas } from '@conloca/cms-spa/page-schema-define';
|
|
3
|
+
import type { Loader } from 'astro/loaders';
|
|
4
|
+
import { ALL_FRAGMENTS_COLLECTION } from './handlers/collection-names.js';
|
|
5
|
+
import { type EntryParser } from './internal/entry-validation.js';
|
|
6
|
+
export { type CollectionEntryLike, type ConlocaDataEntry, type ConlocaFragmentEntry, type ConlocaPageEntry, conlocaDataEntries, conlocaFragmentEntries, conlocaPageEntries, type TypedCollectionEntry, } from './entries.js';
|
|
7
|
+
export type { EntryParser };
|
|
5
8
|
export { ALL_FRAGMENTS_COLLECTION };
|
|
6
9
|
/**
|
|
7
10
|
* Options for createConlocaCollections().
|
|
@@ -16,8 +19,8 @@ export interface CreateConlocaCollectionsOptions {
|
|
|
16
19
|
site?: string;
|
|
17
20
|
/**
|
|
18
21
|
* The same `pageSchemas` object the editor loads. Host meta fields are
|
|
19
|
-
* validated on every page collection at build time (
|
|
20
|
-
* the editor scopes a descriptor to a prefix while Astro
|
|
22
|
+
* validated on every page collection at build time (optional, because
|
|
23
|
+
* the editor scopes a descriptor to a prefix while Astro builds the
|
|
21
24
|
* whole pile). Pass the object itself — not a hand-copied field list — so
|
|
22
25
|
* the form and the build cannot drift. Listing types come from augmenting
|
|
23
26
|
* `HostPageMeta`, not from Astro `entry.data`.
|
|
@@ -35,10 +38,8 @@ export interface ConlocaCollectionsResult {
|
|
|
35
38
|
}
|
|
36
39
|
/**
|
|
37
40
|
* @deprecated Declare collections explicitly with {@link conlocaPages},
|
|
38
|
-
* {@link conlocaData} and {@link conlocaFragments} —
|
|
39
|
-
*
|
|
40
|
-
* fails the build instead of silently not building. This wrapper still
|
|
41
|
-
* works but returns untyped entries.
|
|
41
|
+
* {@link conlocaData} and {@link conlocaFragments} — undeclared content fails
|
|
42
|
+
* the build instead of silently not building. This wrapper still works.
|
|
42
43
|
*
|
|
43
44
|
* Creates Astro Content Collections by discovering from indexed content.
|
|
44
45
|
* Uses content-api to find collections that have content.
|
|
@@ -47,7 +48,7 @@ export interface ConlocaCollectionsResult {
|
|
|
47
48
|
* ```typescript
|
|
48
49
|
* // src/content.config.ts
|
|
49
50
|
* import { createConlocaCollections } from '@conloca/astro-cms/node/content';
|
|
50
|
-
* import { pageSchemas } from './page-schemas';
|
|
51
|
+
* import { pageSchemas } from './page-schemas.js';
|
|
51
52
|
*
|
|
52
53
|
* export const { collections } = await createConlocaCollections({ pageSchemas });
|
|
53
54
|
* ```
|
|
@@ -77,17 +78,22 @@ export interface ConlocaPagesOptions {
|
|
|
77
78
|
*/
|
|
78
79
|
export declare function pageSchemasOf(collection: object): PageSchemas | undefined;
|
|
79
80
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
81
|
+
* The entry parser a Conloca-built collection's loader validates every entry
|
|
82
|
+
* with before storing it, or undefined for any other collection.
|
|
83
|
+
*/
|
|
84
|
+
export declare function entryParserOf(collection: object): EntryParser<Record<string, unknown>> | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* One Astro collection for Conloca pages — the explicit, Starlight-shaped
|
|
87
|
+
* declaration:
|
|
82
88
|
*
|
|
83
89
|
* ```ts
|
|
84
90
|
* export const collections = { pages: conlocaPages({ pageSchemas }) };
|
|
85
91
|
* ```
|
|
86
92
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
93
|
+
* Every page is validated as {@link ConlocaPageEntry} while it loads; read it
|
|
94
|
+
* typed with `conlocaPageEntries(await getCollection('pages'), pageSchemas)`.
|
|
89
95
|
*/
|
|
90
|
-
export declare function conlocaPages(options?: ConlocaPagesOptions): import("astro/content/config").CollectionConfig<
|
|
96
|
+
export declare function conlocaPages(options?: ConlocaPagesOptions): import("astro/content/config").CollectionConfig<import("astro:content").BaseSchema, Loader>;
|
|
91
97
|
/** Options for conlocaData(). */
|
|
92
98
|
export interface ConlocaDataOptions<DS extends DataSchemas> {
|
|
93
99
|
/**
|
|
@@ -103,34 +109,22 @@ export interface ConlocaDataOptions<DS extends DataSchemas> {
|
|
|
103
109
|
}
|
|
104
110
|
/**
|
|
105
111
|
* Deliberate asymmetry with pages: a data schema is validated AS GIVEN —
|
|
106
|
-
* requiredness preserved
|
|
107
|
-
*
|
|
108
|
-
* pages schema. The flip side, accepted for now: a .transform or .default in
|
|
109
|
-
* a dataSchema runs at build time but not in the editor form, so the two can
|
|
110
|
-
* diverge.
|
|
112
|
+
* requiredness preserved — because the site owns it whole for exactly one
|
|
113
|
+
* collection, unlike host page fields checked across the shared pages pile.
|
|
111
114
|
*/
|
|
112
|
-
declare function conlocaDataCollection
|
|
113
|
-
title: z.ZodString;
|
|
114
|
-
description: z.ZodOptional<z.ZodString>;
|
|
115
|
-
category: z.ZodOptional<z.ZodString>;
|
|
116
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
117
|
-
id: z.ZodString;
|
|
118
|
-
locale: z.ZodString;
|
|
119
|
-
name: z.ZodString;
|
|
120
|
-
data: z.ZodOptional<T>;
|
|
121
|
-
}, z.core.$loose>, import("astro/loaders").Loader>;
|
|
115
|
+
declare function conlocaDataCollection(name: string, payload: HostSchema, contentRoot: string, site: string): import("astro/content/config").CollectionConfig<import("astro:content").BaseSchema, Loader>;
|
|
122
116
|
/**
|
|
123
|
-
*
|
|
117
|
+
* Astro collections for Conloca data, one per `dataSchemas` key:
|
|
124
118
|
*
|
|
125
119
|
* ```ts
|
|
126
120
|
* export const collections = { ...conlocaData({ dataSchemas }) };
|
|
127
121
|
* ```
|
|
128
122
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
123
|
+
* A stored entry whose payload fails its schema fails the build instead of
|
|
124
|
+
* rendering blank. Read entries typed by that key's schema with
|
|
125
|
+
* `conlocaDataEntries(dataSchemas, 'testimonials', await getCollection('testimonials'))`.
|
|
132
126
|
*/
|
|
133
|
-
export declare function conlocaData<DS extends DataSchemas>(options: ConlocaDataOptions<DS>): { [K in keyof DS]: ReturnType<typeof conlocaDataCollection
|
|
127
|
+
export declare function conlocaData<DS extends DataSchemas>(options: ConlocaDataOptions<DS>): { [K in keyof DS]: ReturnType<typeof conlocaDataCollection>; };
|
|
134
128
|
/**
|
|
135
129
|
* The fragments aggregate (always) plus one collection per named fragment
|
|
136
130
|
* folder: `...conlocaFragments('general')`. No arguments declares only the
|
|
@@ -140,22 +134,6 @@ export declare function conlocaData<DS extends DataSchemas>(options: ConlocaData
|
|
|
140
134
|
* contentRoot (via CONLOCA_CONTENT_ROOT) and the site is always 'default'.
|
|
141
135
|
*/
|
|
142
136
|
export declare function conlocaFragments<const N extends readonly string[]>(...names: N): {
|
|
143
|
-
[ALL_FRAGMENTS_COLLECTION]: ReturnType<(collection?: string) => import("astro/content/config").CollectionConfig<
|
|
144
|
-
|
|
145
|
-
description: z.ZodOptional<z.ZodString>;
|
|
146
|
-
category: z.ZodOptional<z.ZodString>;
|
|
147
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
148
|
-
id: z.ZodString;
|
|
149
|
-
locale: z.ZodString;
|
|
150
|
-
name: z.ZodString;
|
|
151
|
-
}, z.core.$loose>, import("astro/loaders").Loader>>;
|
|
152
|
-
} & { [K in N[number]]: ReturnType<(collection?: string) => import("astro/content/config").CollectionConfig<z.ZodObject<{
|
|
153
|
-
title: z.ZodString;
|
|
154
|
-
description: z.ZodOptional<z.ZodString>;
|
|
155
|
-
category: z.ZodOptional<z.ZodString>;
|
|
156
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
157
|
-
id: z.ZodString;
|
|
158
|
-
locale: z.ZodString;
|
|
159
|
-
name: z.ZodString;
|
|
160
|
-
}, z.core.$loose>, import("astro/loaders").Loader>>; };
|
|
137
|
+
[ALL_FRAGMENTS_COLLECTION]: ReturnType<(collection?: string) => import("astro/content/config").CollectionConfig<import("astro:content").BaseSchema, Loader>>;
|
|
138
|
+
} & { [K in N[number]]: ReturnType<(collection?: string) => import("astro/content/config").CollectionConfig<import("astro:content").BaseSchema, Loader>>; };
|
|
161
139
|
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../../src/collections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../../src/collections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAGhG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAE1E,OAAO,EAGL,KAAK,WAAW,EAEjB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,oBAAoB,GAC1B,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,CAAC;AAC5B,OAAO,EAAE,wBAAwB,EAAE,CAAC;AAuBpC;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;OASG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,2EAA2E;IAC3E,WAAW,EAAE,MAAM,CAAC,MAAM,E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,UAAU,CAAC,OAAO,qBAAqB,CAAC,GAAE,CACpF;AASD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC,GAqBJ;IACvE,CAAC,wBAAwB,CAAC,EAAE,UAAU,eAlBC,MAAM,iGAkBoB,CAAC;CACnE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,UAAU,eAnBO,MAAM,iGAmBc,GAAE,CAChE"}
|
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
import { defineCollection } from 'astro:content';
|
|
2
2
|
import { createContentAPI } from '@conloca/content-api/reader';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ALL_FRAGMENTS_COLLECTION } from './handlers/page-render-core.js';
|
|
3
|
+
import { parseLooseDataMeta } from '@conloca/content-api/schemas';
|
|
4
|
+
import { ALL_FRAGMENTS_COLLECTION } from './handlers/collection-names.js';
|
|
6
5
|
import { declareConlocaCollection, withDeclarationCheck } from './internal/declared-collections.js';
|
|
7
|
-
import {
|
|
6
|
+
import { createDataEntryParser, createPageEntryParser, parseFragmentEntry, } from './internal/entry-validation.js';
|
|
8
7
|
import { conlocaLoader } from './loader.js';
|
|
8
|
+
export { conlocaDataEntries, conlocaFragmentEntries, conlocaPageEntries, } from './entries.js';
|
|
9
9
|
export { ALL_FRAGMENTS_COLLECTION };
|
|
10
|
+
/**
|
|
11
|
+
* How every collection below is declared: a loader and NO `schema`.
|
|
12
|
+
*
|
|
13
|
+
* Astro's `schema` option only accepts Zod; it is optional, and without it
|
|
14
|
+
* `parseData` stores the loader's data unchanged. Validation therefore runs in
|
|
15
|
+
* the loader, before `store.set`, with the generated Typia validators for the
|
|
16
|
+
* collection (see `internal/entry-validation.ts`) — a stored entry that fails
|
|
17
|
+
* them still fails the build. Entry typing comes from the typed accessors
|
|
18
|
+
* (`conlocaPageEntries` / `conlocaDataEntries` / `conlocaFragmentEntries`),
|
|
19
|
+
* because Astro infers `getCollection` types from a Zod schema only.
|
|
20
|
+
*/
|
|
21
|
+
function conlocaCollection(loader, parseEntry) {
|
|
22
|
+
const defined = defineCollection({ loader });
|
|
23
|
+
entryParsersByCollection.set(defined, parseEntry);
|
|
24
|
+
return defined;
|
|
25
|
+
}
|
|
26
|
+
// The entry parser each Conloca-built collection's loader validates with, so a
|
|
27
|
+
// test (or a host) can run exactly the build's validation without a content root.
|
|
28
|
+
const entryParsersByCollection = new WeakMap();
|
|
10
29
|
/**
|
|
11
30
|
* @deprecated Declare collections explicitly with {@link conlocaPages},
|
|
12
|
-
* {@link conlocaData} and {@link conlocaFragments} —
|
|
13
|
-
*
|
|
14
|
-
* fails the build instead of silently not building. This wrapper still
|
|
15
|
-
* works but returns untyped entries.
|
|
31
|
+
* {@link conlocaData} and {@link conlocaFragments} — undeclared content fails
|
|
32
|
+
* the build instead of silently not building. This wrapper still works.
|
|
16
33
|
*
|
|
17
34
|
* Creates Astro Content Collections by discovering from indexed content.
|
|
18
35
|
* Uses content-api to find collections that have content.
|
|
@@ -21,7 +38,7 @@ export { ALL_FRAGMENTS_COLLECTION };
|
|
|
21
38
|
* ```typescript
|
|
22
39
|
* // src/content.config.ts
|
|
23
40
|
* import { createConlocaCollections } from '@conloca/astro-cms/node/content';
|
|
24
|
-
* import { pageSchemas } from './page-schemas';
|
|
41
|
+
* import { pageSchemas } from './page-schemas.js';
|
|
25
42
|
*
|
|
26
43
|
* export const { collections } = await createConlocaCollections({ pageSchemas });
|
|
27
44
|
* ```
|
|
@@ -34,32 +51,17 @@ export async function createConlocaCollections(options = {}) {
|
|
|
34
51
|
const { contentRoot = process.env.CONLOCA_CONTENT_ROOT ?? './content', site = 'default', pageSchemas } = options;
|
|
35
52
|
const api = await createContentAPI({ contentRoot });
|
|
36
53
|
const collections = {};
|
|
37
|
-
collections[ALL_FRAGMENTS_COLLECTION] =
|
|
38
|
-
loader: conlocaLoader({ contentRoot, site, kind: 'fragment' }),
|
|
39
|
-
schema: fragmentMetaSchema.loose(),
|
|
40
|
-
});
|
|
54
|
+
collections[ALL_FRAGMENTS_COLLECTION] = conlocaCollection(conlocaLoader({ contentRoot, site, kind: 'fragment', parseEntry: parseFragmentEntry }), parseFragmentEntry);
|
|
41
55
|
for (const name of api.fragments.collections) {
|
|
42
|
-
collections[name] =
|
|
43
|
-
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'fragment' }),
|
|
44
|
-
schema: fragmentMetaSchema.loose(),
|
|
45
|
-
});
|
|
56
|
+
collections[name] = conlocaCollection(conlocaLoader({ collection: name, contentRoot, site, kind: 'fragment', parseEntry: parseFragmentEntry }), parseFragmentEntry);
|
|
46
57
|
}
|
|
47
58
|
for (const name of api.data.collections) {
|
|
48
|
-
collections[name] =
|
|
49
|
-
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }),
|
|
50
|
-
schema: dataMetaSchema.loose(),
|
|
51
|
-
});
|
|
59
|
+
collections[name] = conlocaCollection(conlocaLoader({ collection: name, contentRoot, site, kind: 'data', parseEntry: parseLooseDataMeta }), parseLooseDataMeta);
|
|
52
60
|
}
|
|
53
|
-
const
|
|
54
|
-
const pageSchema = hostFields && Object.keys(hostFields.shape).length > 0
|
|
55
|
-
? buildPageCollectionSchema(hostFields)
|
|
56
|
-
: pageMetaSchema.loose();
|
|
61
|
+
const parsePage = createPageEntryParser(pageSchemas);
|
|
57
62
|
const siteCollections = api.getSite(site)?.collections ?? new Set();
|
|
58
63
|
for (const name of siteCollections) {
|
|
59
|
-
collections[name] =
|
|
60
|
-
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'page' }),
|
|
61
|
-
schema: pageSchema,
|
|
62
|
-
});
|
|
64
|
+
collections[name] = conlocaCollection(conlocaLoader({ collection: name, contentRoot, site, kind: 'page', parseEntry: parsePage }), parsePage);
|
|
63
65
|
}
|
|
64
66
|
return { collections };
|
|
65
67
|
}
|
|
@@ -77,69 +79,68 @@ export function pageSchemasOf(collection) {
|
|
|
77
79
|
return pageSchemasByCollection.get(collection);
|
|
78
80
|
}
|
|
79
81
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
+
* The entry parser a Conloca-built collection's loader validates every entry
|
|
83
|
+
* with before storing it, or undefined for any other collection.
|
|
84
|
+
*/
|
|
85
|
+
export function entryParserOf(collection) {
|
|
86
|
+
return entryParsersByCollection.get(collection);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* One Astro collection for Conloca pages — the explicit, Starlight-shaped
|
|
90
|
+
* declaration:
|
|
82
91
|
*
|
|
83
92
|
* ```ts
|
|
84
93
|
* export const collections = { pages: conlocaPages({ pageSchemas }) };
|
|
85
94
|
* ```
|
|
86
95
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
96
|
+
* Every page is validated as {@link ConlocaPageEntry} while it loads; read it
|
|
97
|
+
* typed with `conlocaPageEntries(await getCollection('pages'), pageSchemas)`.
|
|
89
98
|
*/
|
|
90
99
|
export function conlocaPages(options = {}) {
|
|
91
100
|
const { contentRoot = defaultContentRoot(), site = 'default', collection = 'pages', pageSchemas } = options;
|
|
92
101
|
declareConlocaCollection('page', collection);
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
schema: buildPageCollectionSchema(pageSchemas ? hostFieldsFromPageSchemas(pageSchemas) : z.object({})),
|
|
99
|
-
});
|
|
102
|
+
const parseEntry = createPageEntryParser(pageSchemas);
|
|
103
|
+
const defined = conlocaCollection(withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'page', parseEntry }), {
|
|
104
|
+
contentRoot,
|
|
105
|
+
site,
|
|
106
|
+
}), parseEntry);
|
|
100
107
|
if (pageSchemas)
|
|
101
108
|
pageSchemasByCollection.set(defined, pageSchemas);
|
|
102
109
|
return defined;
|
|
103
110
|
}
|
|
104
111
|
/**
|
|
105
112
|
* Deliberate asymmetry with pages: a data schema is validated AS GIVEN —
|
|
106
|
-
* requiredness preserved
|
|
107
|
-
*
|
|
108
|
-
* pages schema. The flip side, accepted for now: a .transform or .default in
|
|
109
|
-
* a dataSchema runs at build time but not in the editor form, so the two can
|
|
110
|
-
* diverge.
|
|
113
|
+
* requiredness preserved — because the site owns it whole for exactly one
|
|
114
|
+
* collection, unlike host page fields checked across the shared pages pile.
|
|
111
115
|
*/
|
|
112
116
|
function conlocaDataCollection(name, payload, contentRoot, site) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// Base meta plus this collection's payload under `data`. `data` stays
|
|
119
|
-
// optional: an entry saved before any payload exists is not an error.
|
|
120
|
-
schema: z.looseObject({ ...dataMetaSchema.shape, data: payload.optional() }),
|
|
121
|
-
});
|
|
117
|
+
const parseEntry = createDataEntryParser(payload);
|
|
118
|
+
return conlocaCollection(withDeclarationCheck(conlocaLoader({ collection: name, contentRoot, site, kind: 'data', parseEntry }), {
|
|
119
|
+
contentRoot,
|
|
120
|
+
site,
|
|
121
|
+
}), parseEntry);
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
|
-
*
|
|
124
|
+
* Astro collections for Conloca data, one per `dataSchemas` key:
|
|
125
125
|
*
|
|
126
126
|
* ```ts
|
|
127
127
|
* export const collections = { ...conlocaData({ dataSchemas }) };
|
|
128
128
|
* ```
|
|
129
129
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
130
|
+
* A stored entry whose payload fails its schema fails the build instead of
|
|
131
|
+
* rendering blank. Read entries typed by that key's schema with
|
|
132
|
+
* `conlocaDataEntries(dataSchemas, 'testimonials', await getCollection('testimonials'))`.
|
|
133
133
|
*/
|
|
134
134
|
export function conlocaData(options) {
|
|
135
135
|
const { dataSchemas, contentRoot = defaultContentRoot(), site = 'default' } = options;
|
|
136
|
-
const
|
|
136
|
+
const collections = {};
|
|
137
|
+
for (const [name, payload] of Object.entries(dataSchemas)) {
|
|
137
138
|
declareConlocaCollection('data', name);
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
return
|
|
139
|
+
collections[name] = conlocaDataCollection(name, payload, contentRoot, site);
|
|
140
|
+
}
|
|
141
|
+
// The loop built exactly one collection per dataSchemas key; the record type
|
|
142
|
+
// keeps those keys for the content.config `collections` export.
|
|
143
|
+
return collections;
|
|
143
144
|
}
|
|
144
145
|
/**
|
|
145
146
|
* The folder the editor saves every new fragment to (content/fragments/fragments/).
|
|
@@ -159,13 +160,7 @@ export function conlocaFragments(...names) {
|
|
|
159
160
|
const contentRoot = defaultContentRoot();
|
|
160
161
|
const site = 'default';
|
|
161
162
|
declareConlocaCollection('fragment', EDITOR_FRAGMENT_FOLDER);
|
|
162
|
-
const fragmentCollection = (collection) =>
|
|
163
|
-
loader: withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'fragment' }), {
|
|
164
|
-
contentRoot,
|
|
165
|
-
site,
|
|
166
|
-
}),
|
|
167
|
-
schema: fragmentMetaSchema.loose(),
|
|
168
|
-
});
|
|
163
|
+
const fragmentCollection = (collection) => conlocaCollection(withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'fragment', parseEntry: parseFragmentEntry }), { contentRoot, site }), parseFragmentEntry);
|
|
169
164
|
const named = Object.fromEntries(names.map((name) => {
|
|
170
165
|
declareConlocaCollection('fragment', name);
|
|
171
166
|
return [name, fragmentCollection(name)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../../../src/collections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../../../src/collections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EA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IACJ,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACjB,wBAAwB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAU,CAAC;IACnD,CAAC,CAAC,CACH,CAAC;IACF,uEAAuE;IACvE,qEAAqE;IACrE,uBAAuB;IACvB,OAAO,EAAE,CAAC,wBAAwB,CAAC,EAAE,kBAAkB,EAAE,EAAE,GAAG,KAAK,EAEJ,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { DataSchemas, HostSchemaType, PageSchemas } from '@conloca/cms-spa/page-schema-define';
|
|
2
|
+
import { type ConlocaDataEntry, type ConlocaFragmentEntry, type ConlocaPageEntry } from './internal/entry-validation.js';
|
|
3
|
+
/**
|
|
4
|
+
* Typed reads of Conloca collections.
|
|
5
|
+
*
|
|
6
|
+
* Astro types `getCollection()` entries from a collection's Zod `schema`; the
|
|
7
|
+
* Conloca factories declare none (the loader validates with generated Typia
|
|
8
|
+
* validators instead), so Astro's own entry type for them is `any`. These
|
|
9
|
+
* accessors take what `getCollection()` returned and hand back entries typed
|
|
10
|
+
* by the same declarations the build validated with — re-running those
|
|
11
|
+
* validators, so the type is earned at runtime rather than asserted:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { getCollection } from 'astro:content';
|
|
15
|
+
* import { conlocaPageEntries } from '@conloca/astro-cms/collections';
|
|
16
|
+
* import { pageSchemas } from '../page-schemas';
|
|
17
|
+
*
|
|
18
|
+
* const pages = conlocaPageEntries(await getCollection('pages'), pageSchemas);
|
|
19
|
+
* pages[0].data.title; // string
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* They take the entries rather than calling `getCollection` themselves so they
|
|
23
|
+
* stay importable (and testable) outside Astro's virtual modules.
|
|
24
|
+
*
|
|
25
|
+
* Each call re-validates every entry it is given; call once per collection
|
|
26
|
+
* read (e.g. in `getStaticPaths` or once per page) rather than per access.
|
|
27
|
+
*/
|
|
28
|
+
/** The fields every Astro collection entry carries besides `data`. */
|
|
29
|
+
export interface CollectionEntryLike {
|
|
30
|
+
id: string;
|
|
31
|
+
data: unknown;
|
|
32
|
+
}
|
|
33
|
+
/** An Astro collection entry with `data` replaced by its validated, typed form. */
|
|
34
|
+
export type TypedCollectionEntry<E extends CollectionEntryLike, T> = Omit<E, 'data'> & {
|
|
35
|
+
data: T;
|
|
36
|
+
};
|
|
37
|
+
/** `getCollection('pages')` entries, validated and typed as {@link ConlocaPageEntry}. */
|
|
38
|
+
export declare function conlocaPageEntries<E extends CollectionEntryLike>(entries: readonly E[], pageSchemas?: PageSchemas): TypedCollectionEntry<E, ConlocaPageEntry>[];
|
|
39
|
+
/** A `conlocaData` collection's entries, with `data` validated and typed by that key's host schema. */
|
|
40
|
+
export declare function conlocaDataEntries<E extends CollectionEntryLike, DS extends DataSchemas, K extends keyof DS & string>(dataSchemas: DS, collection: K, entries: readonly E[]): TypedCollectionEntry<E, ConlocaDataEntry<HostSchemaType<DS[K]>>>[];
|
|
41
|
+
/** Fragment collection entries, validated and typed as {@link ConlocaFragmentEntry}. */
|
|
42
|
+
export declare function conlocaFragmentEntries<E extends CollectionEntryLike>(entries: readonly E[]): TypedCollectionEntry<E, ConlocaFragmentEntry>[];
|
|
43
|
+
export type { ConlocaDataEntry, ConlocaFragmentEntry, ConlocaPageEntry };
|
|
44
|
+
//# sourceMappingURL=entries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../../../src/entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAEpG,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,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