@hamur/content 0.0.1 → 0.0.3
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/dist/chunks/{bun-render-7jxnxg3v.js → bun-render-wckjnzsa.js} +5 -3
- package/dist/src/index.js +132 -73
- package/dist/src/query.js +4 -2
- package/dist/src/server/index.js +1 -1
- package/dist/types/src/adapters/ContentRenderer.svelte +27 -0
- package/dist/types/src/adapters/ProseA.svelte +11 -0
- package/dist/types/src/adapters/ProseBlockquote.svelte +7 -0
- package/dist/types/src/adapters/ProseCode.svelte +7 -0
- package/dist/types/src/adapters/ProseEm.svelte +7 -0
- package/dist/types/src/adapters/ProseH1.svelte +7 -0
- package/dist/types/src/adapters/ProseH2.svelte +7 -0
- package/dist/types/src/adapters/ProseH3.svelte +7 -0
- package/dist/types/src/adapters/ProseH4.svelte +7 -0
- package/dist/types/src/adapters/ProseH5.svelte +7 -0
- package/dist/types/src/adapters/ProseH6.svelte +7 -0
- package/dist/types/src/adapters/ProseHr.svelte +5 -0
- package/dist/types/src/adapters/ProseImg.svelte +5 -0
- package/dist/types/src/adapters/ProseLi.svelte +7 -0
- package/dist/types/src/adapters/ProseOl.svelte +7 -0
- package/dist/types/src/adapters/ProseP.svelte +7 -0
- package/dist/types/src/adapters/ProsePre.svelte +21 -0
- package/dist/types/src/adapters/ProseStrong.svelte +7 -0
- package/dist/types/src/adapters/ProseTable.svelte +7 -0
- package/dist/types/src/adapters/ProseUl.svelte +7 -0
- package/dist/types/src/build/access.d.ts +15 -0
- package/dist/types/src/build/query.d.ts +8 -4
- package/dist/types/src/build/search.d.ts +2 -1
- package/dist/types/src/runtime/client.d.ts +2 -1
- package/dist/types/src/runtime/query.d.ts +12 -3
- package/dist/types/src/server/access.d.ts +4 -0
- package/dist/types/src/server/graphql.d.ts +3 -2
- package/dist/types/src/server/rest.d.ts +4 -4
- package/package.json +48 -18
- package/src/build/access.ts +37 -0
- package/src/build/api.ts +1 -1
- package/src/build/dev.ts +3 -1
- package/src/build/graphql.ts +5 -2
- package/src/build/query.ts +47 -8
- package/src/build/raw.ts +9 -2
- package/src/build/search.ts +9 -4
- package/src/module.ts +2 -2
- package/src/runtime/client.ts +7 -2
- package/src/runtime/query.ts +30 -4
- package/src/server/access.ts +26 -0
- package/src/server/endpoint.ts +3 -2
- package/src/server/graphql.ts +13 -6
- package/src/server/rest.ts +14 -6
package/src/server/endpoint.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/// <reference path="../env.d.ts" />
|
|
2
2
|
import store from "#hamur/content/store"
|
|
3
3
|
import { createError, defineHandler } from "hamur/server"
|
|
4
|
+
import { accessFor } from "./access.ts"
|
|
4
5
|
import { answerQuery, QueryError } from "../runtime/query.ts"
|
|
5
6
|
|
|
6
7
|
export const contentQuery = defineHandler({
|
|
7
8
|
route: "/_hamur/content/query",
|
|
8
9
|
method: "POST",
|
|
9
|
-
async handler(input: unknown) {
|
|
10
|
+
async handler(input: unknown, { event }) {
|
|
10
11
|
try {
|
|
11
|
-
return await answerQuery(store, input)
|
|
12
|
+
return await answerQuery(store, input, accessFor(event))
|
|
12
13
|
} catch (error) {
|
|
13
14
|
if (error instanceof QueryError) throw createError({ status: 400, message: error.message })
|
|
14
15
|
throw error
|
package/src/server/graphql.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HamurEvent } from "hamur/server"
|
|
1
2
|
import type { CollectionQuery, QueryClause } from "../runtime/query.ts"
|
|
2
3
|
import type { ContentStore } from "../runtime/store.ts"
|
|
3
4
|
import { answerExposed, condition, REST_LIMIT } from "./rest.ts"
|
|
@@ -35,8 +36,8 @@ export function graphqlQuery({ where, order, limit, skip }: ListArgs): Collectio
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/** `Query.<collection>`: the entries the arguments select. */
|
|
38
|
-
export const contentList = (store: ContentStore, name: string, args: ListArgs): Promise<unknown> =>
|
|
39
|
-
answerExposed(store, name, () => graphqlQuery(args))
|
|
39
|
+
export const contentList = (store: ContentStore, name: string, args: ListArgs, event?: HamurEvent): Promise<unknown> =>
|
|
40
|
+
answerExposed(store, name, () => graphqlQuery(args), event)
|
|
40
41
|
|
|
41
42
|
/** `Query.<collection>Item`: the entry whose `key` (`path` for a page, `id` for data) is `value`, or null. */
|
|
42
43
|
export async function contentItem(
|
|
@@ -44,11 +45,17 @@ export async function contentItem(
|
|
|
44
45
|
name: string,
|
|
45
46
|
key: "path" | "id",
|
|
46
47
|
value: string,
|
|
48
|
+
event?: HamurEvent,
|
|
47
49
|
): Promise<unknown> {
|
|
48
|
-
const found = (await answerExposed(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const found = (await answerExposed(
|
|
51
|
+
store,
|
|
52
|
+
name,
|
|
53
|
+
() => ({
|
|
54
|
+
where: [{ join: "AND", field: key, operator: "=", value }],
|
|
55
|
+
limit: 1,
|
|
56
|
+
}),
|
|
57
|
+
event,
|
|
58
|
+
)) as unknown[]
|
|
52
59
|
return found[0] ?? null
|
|
53
60
|
}
|
|
54
61
|
|
package/src/server/rest.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createError, type StandardJSONSchemaV1, type StandardSchemaV1 } from "hamur/server"
|
|
1
|
+
import { createError, type HamurEvent, type StandardJSONSchemaV1, type StandardSchemaV1 } from "hamur/server"
|
|
2
2
|
import {
|
|
3
3
|
QueryError,
|
|
4
4
|
runQuery,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type QueryOperator,
|
|
9
9
|
} from "../runtime/query.ts"
|
|
10
10
|
import type { ContentStore } from "../runtime/store.ts"
|
|
11
|
+
import { accessFor } from "./access.ts"
|
|
11
12
|
|
|
12
13
|
/** The most entries one REST answer holds, and its `limit` when none is sent. */
|
|
13
14
|
export const REST_LIMIT = 100
|
|
@@ -86,12 +87,19 @@ export function restQuery(input: unknown): CollectionQuery {
|
|
|
86
87
|
return query
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
/** Runs `query` (built by `build`, which may throw a `QueryError`) over an exposed collection: 404 for one the store does not expose, 400 for a query the engine refuses. REST and GraphQL both answer through it. */
|
|
90
|
-
export async function answerExposed(
|
|
90
|
+
/** Runs `query` (built by `build`, which may throw a `QueryError`) over an exposed collection: 404 for one the store does not expose, 400 for a query the engine refuses. REST and GraphQL both answer through it, with the documents `event` may read. */
|
|
91
|
+
export async function answerExposed(
|
|
92
|
+
store: ContentStore,
|
|
93
|
+
name: string,
|
|
94
|
+
build: () => CollectionQuery,
|
|
95
|
+
event?: HamurEvent,
|
|
96
|
+
): Promise<unknown> {
|
|
91
97
|
const meta = Object.hasOwn(store.collections, name) ? store.collections[name] : undefined
|
|
92
98
|
if (!meta?.expose) throw createError({ status: 404, message: `unknown collection ${shown(name)}` })
|
|
93
99
|
try {
|
|
94
|
-
|
|
100
|
+
const entries = await store.entries(name)
|
|
101
|
+
const visible = event && meta.type === "page" ? await accessFor(event).visible(entries) : undefined
|
|
102
|
+
return runQuery(name, meta, entries, build(), visible)
|
|
95
103
|
} catch (error) {
|
|
96
104
|
if (error instanceof QueryError) throw createError({ status: 400, message: error.message })
|
|
97
105
|
throw error
|
|
@@ -99,8 +107,8 @@ export async function answerExposed(store: ContentStore, name: string, build: ()
|
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
/** The answer of `GET /api/_content/<name>`. */
|
|
102
|
-
export const answerRest = (store: ContentStore, name: string, input: unknown): Promise<unknown> =>
|
|
103
|
-
answerExposed(store, name, () => restQuery(input))
|
|
110
|
+
export const answerRest = (store: ContentStore, name: string, input: unknown, event?: HamurEvent): Promise<unknown> =>
|
|
111
|
+
answerExposed(store, name, () => restQuery(input), event)
|
|
104
112
|
|
|
105
113
|
/** `GET /api/_content/<name>` of a name with no route: unknown, or not exposed. */
|
|
106
114
|
export function missingCollection(input: unknown): never {
|