astro-integration-pocketbase 1.2.0-next.2 → 1.3.0-next.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/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "astro-integration-pocketbase",
3
- "version": "1.2.0-next.2",
3
+ "version": "1.3.0-next.1",
4
+ "description": "An Astro integration to support developers working with astro-loader-pocketbase.",
4
5
  "license": "MIT",
5
6
  "author": "Luis Wolf <development@pawcode.de> (https://pawcode.de)",
6
7
  "homepage": "https://github.com/pawcoding/astro-integration-pocketbase",
@@ -36,6 +37,10 @@
36
37
  "astro",
37
38
  "astro-integration",
38
39
  "pocketbase",
39
- "withastro"
40
+ "withastro",
41
+ "devtools",
42
+ "dev-overlay",
43
+ "dev-toolbar",
44
+ "tooling"
40
45
  ]
41
46
  }
@@ -69,7 +69,7 @@ export function refreshCollectionsRealtime(
69
69
 
70
70
  // Add event listeners for all collections
71
71
  for (const collection of remoteCollections) {
72
- eventSource.addEventListener(`${collection}/*`, async () => {
72
+ eventSource.addEventListener(`${collection}/*`, async (event) => {
73
73
  // Do not refresh if the refresh is disabled
74
74
  if (!refreshEnabled) {
75
75
  return;
@@ -81,7 +81,8 @@ export function refreshCollectionsRealtime(
81
81
  loaders: ["pocketbase-loader"],
82
82
  context: {
83
83
  source: "astro-integration-pocketbase",
84
- collection: collectionsMap.get(collection)
84
+ collection: collectionsMap.get(collection),
85
+ data: JSON.parse(event.data)
85
86
  }
86
87
  });
87
88
  });
@@ -6,11 +6,9 @@ import { z } from "astro/zod";
6
6
  const pocketbaseEntrySchema = z.object({
7
7
  id: z.string(),
8
8
  data: z.object({
9
- id: z.string().length(15),
10
- collectionId: z.string().length(15),
11
- collectionName: z.string(),
12
- updated: z.optional(z.date()),
13
- created: z.optional(z.date())
9
+ id: z.string(),
10
+ collectionId: z.string(),
11
+ collectionName: z.string()
14
12
  }),
15
13
  digest: z.string().length(16),
16
14
  collection: z.string()
@@ -9,6 +9,7 @@ export function pocketbaseIntegration(
9
9
  options: PocketBaseIntegrationOptions
10
10
  ): AstroIntegration {
11
11
  let eventSource: EventSource | undefined = undefined;
12
+ let initialSetupDone = false;
12
13
 
13
14
  return {
14
15
  name: "pocketbase-integration",
@@ -34,10 +35,16 @@ export function pocketbaseIntegration(
34
35
  });
35
36
  },
36
37
  "astro:server:setup": (setupOptions) => {
37
- // Listen for the refresh event of the toolbar
38
- handleRefreshCollections(setupOptions);
38
+ if (!initialSetupDone) {
39
+ // Listen for the refresh event of the toolbar
40
+ handleRefreshCollections(setupOptions);
41
+ }
39
42
 
40
43
  // Subscribe to PocketBase realtime API
44
+ if (eventSource) {
45
+ eventSource.close();
46
+ eventSource = undefined;
47
+ }
41
48
  eventSource = refreshCollectionsRealtime(options, setupOptions);
42
49
 
43
50
  // Send settings to the toolbar on initialization
@@ -48,11 +55,15 @@ export function pocketbaseIntegration(
48
55
  baseUrl: options.url
49
56
  } satisfies ToolbarOptions);
50
57
  });
58
+
59
+ initialSetupDone = true;
51
60
  },
52
- "astro:server:done": () => {
61
+ "astro:server:done": ({ logger }) => {
53
62
  // Close the EventSource connection when the server is done
54
63
  if (eventSource) {
64
+ logger.info("Closing EventSource connection");
55
65
  eventSource.close();
66
+ eventSource = undefined;
56
67
  }
57
68
  }
58
69
  }