astro-loader-pocketbase 2.3.1 → 2.4.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-loader-pocketbase",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "A content loader for Astro that uses the PocketBase API",
5
5
  "keywords": [
6
6
  "astro",
@@ -89,7 +89,11 @@ export async function loadEntries(
89
89
  } while (page < totalPages);
90
90
 
91
91
  // Log the number of fetched entries
92
- context.logger.info(
93
- `Fetched ${entries}${lastModified ? " changed" : ""} entries.`
94
- );
92
+ if (lastModified) {
93
+ context.logger.info(
94
+ `Updated ${entries}/${context.store.keys().length} entries.`
95
+ );
96
+ } else {
97
+ context.logger.info(`Fetched ${entries} entries.`);
98
+ }
95
99
  }
@@ -18,7 +18,7 @@ export async function loader(
18
18
  context.refreshContextData,
19
19
  options.collectionName
20
20
  );
21
- if (!refresh) {
21
+ if (refresh === "skip") {
22
22
  return;
23
23
  }
24
24
 
@@ -31,6 +31,12 @@ export async function loader(
31
31
  // Get the date of the last fetch to only update changed entries.
32
32
  let lastModified = context.meta.get("last-modified");
33
33
 
34
+ // Force a full update if the refresh is forced
35
+ if (refresh === "force") {
36
+ lastModified = undefined;
37
+ context.store.clear();
38
+ }
39
+
34
40
  // Check if the version has changed to force an update
35
41
  const lastVersion = context.meta.get("version");
36
42
  if (lastVersion !== packageJson.version) {
@@ -6,27 +6,32 @@ import type { LoaderContext } from "astro/loaders";
6
6
  export function shouldRefresh(
7
7
  context: LoaderContext["refreshContextData"],
8
8
  collectionName: string
9
- ): boolean {
9
+ ): "refresh" | "skip" | "force" {
10
10
  // Check if the refresh was triggered by the `astro-integration-pocketbase`
11
11
  // and the correct metadata is provided.
12
- if (
13
- !context ||
14
- context.source !== "astro-integration-pocketbase" ||
15
- !context.collection
16
- ) {
17
- return true;
12
+ if (!context || context.source !== "astro-integration-pocketbase") {
13
+ return "refresh";
14
+ }
15
+
16
+ // Check if all collections should be refreshed.
17
+ if (context.force) {
18
+ return "force";
19
+ }
20
+
21
+ if (!context.collection) {
22
+ return "refresh";
18
23
  }
19
24
 
20
25
  // Check if the collection name matches the current collection.
21
26
  if (typeof context.collection === "string") {
22
- return context.collection === collectionName;
27
+ return context.collection === collectionName ? "refresh" : "skip";
23
28
  }
24
29
 
25
30
  // Check if the collection is included in the list of collections.
26
31
  if (Array.isArray(context.collection)) {
27
- return context.collection.includes(collectionName);
32
+ return context.collection.includes(collectionName) ? "refresh" : "skip";
28
33
  }
29
34
 
30
35
  // Should not happen but return true to be safe.
31
- return true;
36
+ return "refresh";
32
37
  }