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
|
@@ -89,7 +89,11 @@ export async function loadEntries(
|
|
|
89
89
|
} while (page < totalPages);
|
|
90
90
|
|
|
91
91
|
// Log the number of fetched entries
|
|
92
|
-
|
|
93
|
-
|
|
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
|
}
|
package/src/loader/loader.ts
CHANGED
|
@@ -18,7 +18,7 @@ export async function loader(
|
|
|
18
18
|
context.refreshContextData,
|
|
19
19
|
options.collectionName
|
|
20
20
|
);
|
|
21
|
-
if (
|
|
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
|
-
):
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
36
|
+
return "refresh";
|
|
32
37
|
}
|