astro-integration-pocketbase 0.1.0 → 0.2.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/package.json
CHANGED
package/src/middleware/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineMiddleware } from "astro/middleware";
|
|
2
|
-
import { isPocketbaseEntry } from "./is-pocketbase-entry";
|
|
2
|
+
import { isPocketbaseEntry, type PocketBaseEntry } from "./is-pocketbase-entry";
|
|
3
3
|
|
|
4
4
|
export const onRequest = defineMiddleware(async (context, next) => {
|
|
5
5
|
// Look for entities given as props to the page
|
|
6
6
|
const props = Object.values(context.props);
|
|
7
|
-
const entities = props
|
|
7
|
+
const entities = findEntitiesRecursive(props).map((entity) => entity.data);
|
|
8
8
|
|
|
9
9
|
const response = await next();
|
|
10
10
|
const body = await response.text();
|
|
@@ -18,3 +18,26 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
|
|
18
18
|
|
|
19
19
|
return new Response(newBody, response);
|
|
20
20
|
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Find PocketBase entities in the given data.
|
|
24
|
+
*/
|
|
25
|
+
function findEntitiesRecursive(data: unknown): Array<PocketBaseEntry> {
|
|
26
|
+
// Check if the data is an array and search for entities in each element
|
|
27
|
+
if (Array.isArray(data)) {
|
|
28
|
+
return data.flatMap(findEntitiesRecursive);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (typeof data === "object" && data !== null) {
|
|
32
|
+
// Check if the data is an object and a PocketBase entry
|
|
33
|
+
if (isPocketbaseEntry(data)) {
|
|
34
|
+
return [data];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Search for entities in all values
|
|
38
|
+
return findEntitiesRecursive(Object.values(data));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// No entities found
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
@@ -4,7 +4,7 @@ import { z } from "astro/zod";
|
|
|
4
4
|
* Schema for a PocketBase entry created with [astro-loader-pocketbase](https://github.com/pawcoding/astro-loader-pocketbase)
|
|
5
5
|
*/
|
|
6
6
|
const pocketbaseEntrySchema = z.object({
|
|
7
|
-
id: z.string()
|
|
7
|
+
id: z.string(),
|
|
8
8
|
data: z.object({
|
|
9
9
|
id: z.string().length(15),
|
|
10
10
|
collectionId: z.string().length(15),
|
|
@@ -34,7 +34,6 @@ export function createEntity(data: Entity, baseUrl?: string): DevToolbarCard {
|
|
|
34
34
|
const entity = document.createElement("pre");
|
|
35
35
|
entity.style.margin = "0";
|
|
36
36
|
entity.style.overflow = "auto";
|
|
37
|
-
entity.style.height = "300px";
|
|
38
37
|
entity.textContent = JSON.stringify(data, null, 2);
|
|
39
38
|
content.appendChild(entity);
|
|
40
39
|
|
|
@@ -30,6 +30,11 @@ export async function initToolbar(
|
|
|
30
30
|
|
|
31
31
|
// Container for the main content
|
|
32
32
|
const contentContainer = document.createElement("div");
|
|
33
|
+
contentContainer.style.display = "flex";
|
|
34
|
+
contentContainer.style.flexDirection = "column";
|
|
35
|
+
contentContainer.style.gap = "8px";
|
|
36
|
+
contentContainer.style.maxHeight = "400px";
|
|
37
|
+
contentContainer.style.overflowY = "auto";
|
|
33
38
|
container.appendChild(contentContainer);
|
|
34
39
|
|
|
35
40
|
const placeholder = createPlaceholder();
|