@usegraft/sdk-astro 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +40 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anderson Joseph
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AnyCollection, ReadOptions, Document, ListOptions, SearchOptions, SearchHit, GraftClient, ClientOptions } from '@usegraft/sdk-core';
|
|
2
|
+
export { AnyCollection, ChangeSet, ClientOptions, Document, GraftClient, ListOptions, ReadOptions, SearchHit, SearchOptions, TAG_NAMESPACE, collectionTag, createClient, documentTag, tagsFor, tagsForChanges, toDocument } from '@usegraft/sdk-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Astro adapter over @usegraft/sdk-core — the same `getContent` / `listContent` /
|
|
6
|
+
* `searchContent` surface as @usegraft/sdk-next, so a schema types every read
|
|
7
|
+
* identically across frameworks.
|
|
8
|
+
*
|
|
9
|
+
* No request-level memo here (sdk-next's React.cache has no Astro
|
|
10
|
+
* equivalent): reads go straight to Postgres. In practice that's the right
|
|
11
|
+
* default — prerendered pages read at build time, and an SSR page makes a
|
|
12
|
+
* handful of reads. Server-only by nature (it holds a database handle); use
|
|
13
|
+
* it from .astro frontmatter, endpoints, and middleware — never client
|
|
14
|
+
* islands.
|
|
15
|
+
*
|
|
16
|
+
* Caching: Astro has no tag-based data cache, so the Phase 4 tag contract
|
|
17
|
+
* maps onto HTTP — stamp `tagsFor(...)` into a CDN surrogate-key header
|
|
18
|
+
* (`Cache-Tag` / `Surrogate-Key`) on SSR responses, and purge
|
|
19
|
+
* `tagsForChanges(branch, changeSet)` from your compile webhook.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
interface Graft<TCollections extends Record<string, AnyCollection>> {
|
|
23
|
+
/** Typed getDocument. */
|
|
24
|
+
getContent<K extends keyof TCollections & string>(collection: K, slug: string, options?: ReadOptions): Promise<Document<TCollections[K]> | null>;
|
|
25
|
+
/** Typed listDocuments. */
|
|
26
|
+
listContent<K extends keyof TCollections & string>(collection: K, options?: ListOptions): Promise<Document<TCollections[K]>[]>;
|
|
27
|
+
/** Typed searchDocuments (full-text, best-ranked first). */
|
|
28
|
+
searchContent<K extends keyof TCollections & string>(collection: K, query: string, options?: SearchOptions): Promise<SearchHit<TCollections[K]>[]>;
|
|
29
|
+
/** The underlying sdk-core client, for anything the helpers don't cover. */
|
|
30
|
+
client: GraftClient<TCollections>;
|
|
31
|
+
}
|
|
32
|
+
declare function createGraft<TCollections extends Record<string, AnyCollection>>(options: ClientOptions<TCollections>): Graft<TCollections>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Mounting the Graft runtime in Astro — endpoints are already Web-standard,
|
|
36
|
+
* so the "adapter" is one property access: Astro hands an APIContext, the
|
|
37
|
+
* handlers want its `request`.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* // src/pages/api/fn/[name].ts
|
|
41
|
+
* import { createFunctionsHandler } from "@usegraft/core";
|
|
42
|
+
* import { graftRoute } from "@usegraft/sdk-astro";
|
|
43
|
+
* const handler = createFunctionsHandler({ … });
|
|
44
|
+
* export const POST = graftRoute(handler);
|
|
45
|
+
* export const GET = graftRoute(handler); // 405s with Allow + fix
|
|
46
|
+
*
|
|
47
|
+
* // src/pages/api/mcp.ts
|
|
48
|
+
* import { createGraftMcpHandler } from "@usegraft/mcp";
|
|
49
|
+
* export const POST = graftRoute(createGraftMcpHandler({ … }));
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* Typed structurally (`{ request: Request }`) so this package needs no astro
|
|
53
|
+
* dependency — every APIContext satisfies it.
|
|
54
|
+
*/
|
|
55
|
+
type FetchHandler = (request: Request) => Promise<Response>;
|
|
56
|
+
/** An Astro APIRoute (or anything context-shaped) over a Graft handler. */
|
|
57
|
+
declare function graftRoute(handler: FetchHandler): (context: {
|
|
58
|
+
request: Request;
|
|
59
|
+
}) => Promise<Response>;
|
|
60
|
+
|
|
61
|
+
export { type FetchHandler, type Graft, createGraft, graftRoute };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/graft.ts
|
|
2
|
+
import {
|
|
3
|
+
createClient
|
|
4
|
+
} from "@usegraft/sdk-core";
|
|
5
|
+
function createGraft(options) {
|
|
6
|
+
const client = createClient(options);
|
|
7
|
+
return {
|
|
8
|
+
client,
|
|
9
|
+
getContent: (collection, slug, opts) => client.getDocument(collection, slug, opts),
|
|
10
|
+
listContent: (collection, opts) => client.listDocuments(collection, opts),
|
|
11
|
+
searchContent: (collection, query, opts) => client.searchDocuments(collection, query, opts)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/routes.ts
|
|
16
|
+
function graftRoute(handler) {
|
|
17
|
+
return (context) => handler(context.request);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
import {
|
|
22
|
+
createClient as createClient2,
|
|
23
|
+
toDocument,
|
|
24
|
+
collectionTag,
|
|
25
|
+
documentTag,
|
|
26
|
+
tagsFor,
|
|
27
|
+
tagsForChanges,
|
|
28
|
+
TAG_NAMESPACE
|
|
29
|
+
} from "@usegraft/sdk-core";
|
|
30
|
+
export {
|
|
31
|
+
TAG_NAMESPACE,
|
|
32
|
+
collectionTag,
|
|
33
|
+
createClient2 as createClient,
|
|
34
|
+
createGraft,
|
|
35
|
+
documentTag,
|
|
36
|
+
graftRoute,
|
|
37
|
+
tagsFor,
|
|
38
|
+
tagsForChanges,
|
|
39
|
+
toDocument
|
|
40
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@usegraft/sdk-astro",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/AndersonDesign1/graft.git",
|
|
8
|
+
"directory": "packages/sdk-astro"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@usegraft/sdk-core": "0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@usegraft/core": "0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=22.16"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
37
|
+
"dev": "tsup src/index.ts --format esm --watch",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"test": "vitest run --passWithNoTests",
|
|
40
|
+
"lint": "oxlint ."
|
|
41
|
+
}
|
|
42
|
+
}
|