@gradial/aci 0.1.5 → 0.1.7

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.
@@ -92,6 +92,7 @@ export interface RenderInput<TPage extends KernelPage = KernelPage, TSiteConfig
92
92
  locale: string;
93
93
  siteConfig: TSiteConfig;
94
94
  page: TPage | null;
95
+ fragments?: Record<string, unknown>;
95
96
  }
96
97
  export interface RenderOutput {
97
98
  route: string;
@@ -20,6 +20,7 @@ export interface GradialRenderInput<TPage, TSite extends GradialSiteConfig = Gra
20
20
  locale: string;
21
21
  siteConfig: TSite;
22
22
  page: TPage;
23
+ fragments?: Record<string, unknown>;
23
24
  }
24
25
  export interface GradialSiteConfig {
25
26
  domain?: string;
@@ -20,6 +20,13 @@ export async function getSiteConfig(config = {}) {
20
20
  return await provider.getSiteConfig();
21
21
  }
22
22
  export async function getFragment(name, config = {}) {
23
+ const runtimeInput = await getPageRuntimeRenderInput();
24
+ if (runtimeInput) {
25
+ const fragments = runtimeInput.fragments || {};
26
+ if (name in fragments)
27
+ return fragments[name];
28
+ throw new FragmentNotFoundError(name);
29
+ }
23
30
  const provider = await resolveProviderWithFallback(config);
24
31
  return await provider.getFragment(name);
25
32
  }
@@ -36,14 +36,23 @@ export class FileContentProvider {
36
36
  async getFragment(id) {
37
37
  const manifest = await this.manifest();
38
38
  const entry = manifest.fragments[id];
39
- if (!entry) {
40
- throw new FragmentNotFoundError(id);
39
+ if (entry) {
40
+ try {
41
+ return await this.readJSON(entry.payloadRef);
42
+ }
43
+ catch (error) {
44
+ throw new FragmentNotFoundError(id, error);
45
+ }
41
46
  }
47
+ // Raw content directory stores fragments as flat files
48
+ const contentRoot = process.env.ACI_CONTENT_DIR || path.join(path.resolve(process.cwd()), '.content');
49
+ const rawPath = path.join(contentRoot, 'fragments', `${id}.json`);
42
50
  try {
43
- return await this.readJSON(entry.payloadRef);
51
+ const raw = await fs.readFile(rawPath, 'utf8');
52
+ return JSON.parse(raw);
44
53
  }
45
- catch (error) {
46
- throw new FragmentNotFoundError(id, error);
54
+ catch {
55
+ throw new FragmentNotFoundError(id);
47
56
  }
48
57
  }
49
58
  async manifest() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradial/aci",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",