@usegraft/sdk-next 0.2.0 → 1.0.0-beta.1

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 CHANGED
@@ -15,11 +15,15 @@ npm i @usegraft/sdk-next
15
15
  `createGraft` wraps the read client with `React.cache`, so repeated reads of the same document within one render are deduped. Server-only: it holds a database handle.
16
16
 
17
17
  ```ts
18
+ // lib/graft.ts
19
+ import { createDb } from "@usegraft/db";
18
20
  import { createGraft } from "@usegraft/sdk-next";
19
21
  import { collections } from "@/graft.config";
20
22
 
21
- export const graft = createGraft({ db, collections });
23
+ export const graft = createGraft({ db: createDb(process.env.DATABASE_URL!).db, collections });
24
+ ```
22
25
 
26
+ ```ts
23
27
  // in a Server Component
24
28
  const page = await graft.getContent("pages", "home");
25
29
  const posts = await graft.listContent("posts", { limit: 10 });
@@ -27,6 +31,19 @@ const posts = await graft.listContent("posts", { limit: 10 });
27
31
 
28
32
  Return types come from your `defineCollection` schemas, so a renamed field is a build error rather than a runtime `undefined`.
29
33
 
34
+ ### With no database
35
+
36
+ Pass `index` instead of `db` and the same surface reads the SQLite artifact `graft compile` writes. Nothing else has to be running.
37
+
38
+ ```ts
39
+ import { openStaticIndex } from "@usegraft/db";
40
+
41
+ export const graft = createGraft({
42
+ index: await openStaticIndex(".graft/index.db"),
43
+ collections,
44
+ });
45
+ ```
46
+
30
47
  ## Render MDX bodies
31
48
 
32
49
  ```tsx
@@ -56,4 +73,4 @@ Both turn a compile's `ChangeSet` into the exact `revalidateTag` / `updateTag` c
56
73
 
57
74
  ---
58
75
 
59
- MIT. [Repository](https://github.com/AndersonDesign1/graft) · [Changelog](https://github.com/AndersonDesign1/graft/blob/feat/core/packages/sdk-next/CHANGELOG.md)
76
+ MIT. [Repository](https://github.com/AndersonDesign1/graft) · [Changelog](https://github.com/AndersonDesign1/graft/blob/main/packages/sdk-next/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, ChangeSet } 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
  import { MdxTrust } from '@usegraft/mdx-safety';
@@ -15,7 +16,15 @@ interface Graft<TCollections extends Record<string, AnyCollection>> {
15
16
  /** The underlying sdk-core client, for anything the helpers don't cover. */
16
17
  client: GraftClient<TCollections>;
17
18
  }
18
- declare function createGraft<TCollections extends Record<string, AnyCollection>>(options: ClientOptions<TCollections>): Graft<TCollections>;
19
+ /**
20
+ * Either an index this adapter reads through, or a Postgres handle it builds
21
+ * the reader for. Two shapes rather than one optional field so that neither can
22
+ * be omitted: `createClient` no longer accepts `db`, because taking it there
23
+ * meant every consumer of `@usegraft/sdk-core` — the browser client included —
24
+ * carried a Postgres driver in its dependency graph.
25
+ */
26
+ type GraftOptions<TCollections extends Record<string, AnyCollection>> = ClientOptions<TCollections> | DbClientOptions<TCollections>;
27
+ declare function createGraft<TCollections extends Record<string, AnyCollection>>(options: GraftOptions<TCollections>): Graft<TCollections>;
19
28
  /** How long a background-revalidated tag may keep serving stale before it hard-expires. */
20
29
  type RevalidateProfile = string | {
21
30
  expire?: number;
@@ -73,4 +82,4 @@ interface MdxBodyProps {
73
82
  */
74
83
  declare function MdxBody({ source, components, trust, }: MdxBodyProps): Promise<ReactElement | null>;
75
84
 
76
- export { type Graft, MdxBody, type MdxBodyProps, type MdxComponents, type RevalidateProfile, createGraft, revalidateContent, updateContent };
85
+ export { type Graft, type GraftOptions, MdxBody, type MdxBodyProps, type MdxComponents, type RevalidateProfile, createGraft, revalidateContent, updateContent };
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  // src/graft.ts
2
2
  import { revalidateTag, updateTag } from "next/cache";
3
3
  import { cache } from "react";
4
+ import { createDbClient } from "@usegraft/sdk-core/db";
4
5
  import {
5
6
  createClient,
6
7
  tagsForChanges
7
8
  } from "@usegraft/sdk-core";
8
9
  function createGraft(options) {
9
- const client = createClient(options);
10
+ const client = "db" in options ? createDbClient(options) : createClient(options);
10
11
  const cachedGet = cache(
11
12
  (collection, slug, branch) => client.getDocument(
12
13
  collection,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usegraft/sdk-next",
3
- "version": "0.2.0",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "Next.js App Router adapter: typed content reads in Server Components, cache-tag invalidation, and real MDX rendering.",
5
5
  "keywords": [
6
6
  "agent",
@@ -46,16 +46,17 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@mdx-js/mdx": "^3.1.1",
49
- "@usegraft/mdx-safety": "0.2.0",
50
- "@usegraft/sdk-core": "0.2.0",
49
+ "@usegraft/db": "1.0.0-beta.1",
50
+ "@usegraft/mdx-safety": "1.0.0-beta.1",
51
+ "@usegraft/sdk-core": "1.0.0-beta.1",
51
52
  "remark-gfm": "^4.0.1"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@types/mdx": "^2.0.14",
55
- "@types/react": "^19.0.0",
56
- "@usegraft/core": "0.2.0",
57
- "next": "^16.0.0",
58
- "react": "^19.0.0"
56
+ "@types/react": "^19.2.18",
57
+ "@usegraft/core": "1.0.0-beta.1",
58
+ "next": "^16.3.3",
59
+ "react": "^19.2.8"
59
60
  },
60
61
  "peerDependencies": {
61
62
  "next": ">=15.0.0",