@usegraft/sdk-astro 0.1.1 → 1.0.0-beta.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.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @usegraft/sdk-astro
2
+
3
+ > Astro adapter: typed content reads and endpoint mounts over the same handlers every other surface serves.
4
+
5
+ Part of [Graft](https://github.com/AndersonDesign1/graft), a CMS built so an AI agent is the primary operator.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm i @usegraft/sdk-astro
11
+ ```
12
+
13
+ ## Read content
14
+
15
+ Build the handle once in a server-only module, then import it from frontmatter, endpoints, and middleware. Never from a client island: it holds a database handle.
16
+
17
+ ```ts
18
+ // src/lib/graft.ts
19
+ import { createDb } from "@usegraft/db";
20
+ import { createGraft } from "@usegraft/sdk-astro";
21
+ import { collections } from "../../graft.config";
22
+
23
+ export const graft = createGraft({ db: createDb(process.env.DATABASE_URL!).db, collections });
24
+ ```
25
+
26
+ ```astro
27
+ ---
28
+ // src/pages/[slug].astro
29
+ import { graft } from "../lib/graft";
30
+
31
+ const page = await graft.getContent("pages", Astro.params.slug!);
32
+ ---
33
+ ```
34
+
35
+ Return types come from your `defineCollection` schemas, so a renamed field is a build error rather than a runtime `undefined`.
36
+
37
+ There is no request-level memo here, because `React.cache` has no Astro equivalent. Reads go straight to the index, which is the right default: prerendered pages read at build time, and an SSR page makes a handful of reads.
38
+
39
+ ## Read with no database
40
+
41
+ Pass `index` instead of `db` and the same surface reads the SQLite artifact `graft compile` writes.
42
+
43
+ ```ts
44
+ import { openStaticIndex } from "@usegraft/db";
45
+
46
+ export const graft = createGraft({
47
+ index: await openStaticIndex(".graft/index.db"),
48
+ collections,
49
+ });
50
+ ```
51
+
52
+ ## Mount the runtime
53
+
54
+ `graftRoute` binds a Graft handler to an Astro endpoint, so typed functions and MCP are served from your own app rather than a separate process. It takes the handler, not a config object: Astro hands over an `APIContext`, and the handlers want its `request`.
55
+
56
+ ```ts
57
+ // src/pages/api/fn/[name].ts
58
+ import { createFunctionsHandler } from "@usegraft/core";
59
+ import { graftRoute } from "@usegraft/sdk-astro";
60
+
61
+ const handler = createFunctionsHandler({ db, collections, functions });
62
+
63
+ export const POST = graftRoute(handler);
64
+ export const GET = graftRoute(handler); // 405s with Allow and a fix
65
+ ```
66
+
67
+ ```ts
68
+ // src/pages/api/mcp.ts
69
+ import { createGraftMcpHandler } from "@usegraft/mcp";
70
+ import { graftRoute } from "@usegraft/sdk-astro";
71
+
72
+ export const POST = graftRoute(createGraftMcpHandler({ db, collections, functions, actor }));
73
+ ```
74
+
75
+ The parameter is typed structurally as `{ request: Request }`, so this package needs no `astro` dependency and every `APIContext` satisfies it.
76
+
77
+ ## MDX
78
+
79
+ Bodies come back as authored source. Render them with Astro's own MDX pipeline rather than a runtime evaluator, which is why this package ships no `MdxBody` equivalent.
80
+
81
+ ## Cache invalidation
82
+
83
+ Astro has no tag-based data cache, so the [`@usegraft/sdk-core`](https://www.npmjs.com/package/@usegraft/sdk-core) tag contract maps onto HTTP. Stamp `tagsFor(...)` into a CDN surrogate-key header on SSR responses, and purge `tagsForChanges(branch, changeSet)` from your compile webhook.
84
+
85
+ ```astro
86
+ ---
87
+ Astro.response.headers.set("Cache-Tag", tagsFor(branch, "pages", slug).join(","));
88
+ ---
89
+ ```
90
+
91
+ ---
92
+
93
+ MIT. [Repository](https://github.com/AndersonDesign1/graft) · [Changelog](https://github.com/AndersonDesign1/graft/blob/main/packages/sdk-astro/CHANGELOG.md)
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { DbClientOptions } from '@usegraft/sdk-core/db';
1
2
  import { AnyCollection, ReadOptions, Document, ListOptions, SearchOptions, SearchHit, GraftClient, ClientOptions } from '@usegraft/sdk-core';
2
3
  export { AnyCollection, ChangeSet, ClientOptions, Document, GraftClient, ListOptions, ReadOptions, SearchHit, SearchOptions, TAG_NAMESPACE, collectionTag, createClient, documentTag, tagsFor, tagsForChanges, toDocument } from '@usegraft/sdk-core';
3
4
 
@@ -29,7 +30,15 @@ interface Graft<TCollections extends Record<string, AnyCollection>> {
29
30
  /** The underlying sdk-core client, for anything the helpers don't cover. */
30
31
  client: GraftClient<TCollections>;
31
32
  }
32
- declare function createGraft<TCollections extends Record<string, AnyCollection>>(options: ClientOptions<TCollections>): Graft<TCollections>;
33
+ /**
34
+ * Either an index this adapter reads through, or a Postgres handle it builds
35
+ * the reader for. Two shapes rather than one optional field so that neither can
36
+ * be omitted: `createClient` no longer accepts `db`, because taking it there
37
+ * meant every consumer of `@usegraft/sdk-core` — the browser client included —
38
+ * carried a Postgres driver in its dependency graph.
39
+ */
40
+ type GraftOptions<TCollections extends Record<string, AnyCollection>> = ClientOptions<TCollections> | DbClientOptions<TCollections>;
41
+ declare function createGraft<TCollections extends Record<string, AnyCollection>>(options: GraftOptions<TCollections>): Graft<TCollections>;
33
42
 
34
43
  /**
35
44
  * Mounting the Graft runtime in Astro — endpoints are already Web-standard,
@@ -58,4 +67,4 @@ declare function graftRoute(handler: FetchHandler): (context: {
58
67
  request: Request;
59
68
  }) => Promise<Response>;
60
69
 
61
- export { type FetchHandler, type Graft, createGraft, graftRoute };
70
+ export { type FetchHandler, type Graft, type GraftOptions, createGraft, graftRoute };
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  // src/graft.ts
2
+ import { createDbClient } from "@usegraft/sdk-core/db";
2
3
  import {
3
4
  createClient
4
5
  } from "@usegraft/sdk-core";
5
6
  function createGraft(options) {
6
- const client = createClient(options);
7
+ const client = "db" in options ? createDbClient(options) : createClient(options);
7
8
  return {
8
9
  client,
9
10
  getContent: (collection, slug, opts) => client.getDocument(collection, slug, opts),
package/package.json CHANGED
@@ -1,6 +1,20 @@
1
1
  {
2
2
  "name": "@usegraft/sdk-astro",
3
- "version": "0.1.1",
3
+ "version": "1.0.0-beta.0",
4
+ "description": "Astro adapter: typed content reads and endpoint mounts over Graft's stateless handlers.",
5
+ "keywords": [
6
+ "agent",
7
+ "ai",
8
+ "astro",
9
+ "cms",
10
+ "content",
11
+ "graft",
12
+ "headless-cms",
13
+ "mcp",
14
+ "ssr",
15
+ "typescript"
16
+ ],
17
+ "homepage": "https://github.com/AndersonDesign1/graft#readme",
4
18
  "license": "MIT",
5
19
  "repository": {
6
20
  "type": "git",
@@ -24,10 +38,11 @@
24
38
  "access": "public"
25
39
  },
26
40
  "dependencies": {
27
- "@usegraft/sdk-core": "0.1.1"
41
+ "@usegraft/db": "1.0.0-beta.0",
42
+ "@usegraft/sdk-core": "1.0.0-beta.0"
28
43
  },
29
44
  "devDependencies": {
30
- "@usegraft/core": "0.1.1"
45
+ "@usegraft/core": "1.0.0-beta.0"
31
46
  },
32
47
  "engines": {
33
48
  "node": ">=22.16"
@@ -36,7 +51,6 @@
36
51
  "build": "tsup src/index.ts --format esm --dts --clean",
37
52
  "dev": "tsup src/index.ts --format esm --watch",
38
53
  "typecheck": "tsc --noEmit",
39
- "test": "vitest run --passWithNoTests",
40
- "lint": "oxlint ."
54
+ "test": "vitest run --passWithNoTests"
41
55
  }
42
56
  }