astro-loader-pocketbase 2.4.1 → 2.5.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,6 @@
1
1
  {
2
2
  "name": "astro-loader-pocketbase",
3
- "version": "2.4.1",
3
+ "version": "2.5.0-next.1",
4
4
  "description": "A content loader for Astro that uses the PocketBase API",
5
5
  "keywords": [
6
6
  "astro",
@@ -10,6 +10,13 @@
10
10
  "withastro"
11
11
  ],
12
12
  "homepage": "https://github.com/pawcoding/astro-loader-pocketbase",
13
+ "bugs": {
14
+ "url": "https://github.com/pawcoding/astro-loader-pocketbase/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/pawcoding/astro-loader-pocketbase.git"
19
+ },
13
20
  "license": "MIT",
14
21
  "author": "Luis Wolf <development@pawcode.de> (https://pawcode.de)",
15
22
  "type": "module",
@@ -35,26 +42,30 @@
35
42
  "test:watch": "vitest watch"
36
43
  },
37
44
  "devDependencies": {
38
- "@commitlint/cli": "^19.7.1",
39
- "@commitlint/config-conventional": "^19.7.1",
40
- "@eslint/js": "^9.20.0",
41
- "@stylistic/eslint-plugin": "^3.1.0",
42
- "@types/node": "^22.13.4",
43
- "@vitest/coverage-v8": "^3.0.5",
44
- "astro": "^5.3.0",
45
- "eslint": "^9.20.1",
46
- "eslint-config-prettier": "^10.0.1",
47
- "globals": "^15.15.0",
45
+ "@commitlint/cli": "^19.8.0",
46
+ "@commitlint/config-conventional": "^19.8.0",
47
+ "@eslint/js": "^9.23.0",
48
+ "@stylistic/eslint-plugin": "^4.2.0",
49
+ "@types/node": "^22.13.14",
50
+ "@vitest/coverage-v8": "^3.0.9",
51
+ "astro": "^5.5.5",
52
+ "eslint": "^9.23.0",
53
+ "eslint-config-prettier": "^10.1.1",
54
+ "globals": "^16.0.0",
48
55
  "husky": "^9.1.7",
49
- "lint-staged": "^15.4.3",
50
- "prettier": "^3.5.1",
56
+ "lint-staged": "^15.5.0",
57
+ "prettier": "^3.5.3",
51
58
  "prettier-plugin-organize-imports": "^4.1.0",
52
- "prettier-plugin-packagejson": "^2.5.8",
53
- "typescript": "^5.7.3",
54
- "typescript-eslint": "^8.24.0",
55
- "vitest": "^3.0.5"
59
+ "prettier-plugin-packagejson": "^2.5.10",
60
+ "typescript": "^5.8.2",
61
+ "typescript-eslint": "^8.28.0",
62
+ "vitest": "^3.0.9"
56
63
  },
57
64
  "peerDependencies": {
58
65
  "astro": "^5.0.0"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public",
69
+ "provenance": true
59
70
  }
60
71
  }
@@ -12,6 +12,14 @@ export async function handleRealtimeUpdates(
12
12
  context: LoaderContext,
13
13
  options: PocketBaseLoaderOptions
14
14
  ): Promise<boolean> {
15
+ // Check if a custom filter is set
16
+ if (options.filter) {
17
+ // Updating an entry directly via realtime updates is not supported when using a custom filter.
18
+ // This is because the filter can only be applied via the get request and is not considered in the realtime updates.
19
+ // Updating the entry directly would bypass the filter and could lead to inconsistent data.
20
+ return false;
21
+ }
22
+
15
23
  // Check if data was provided via the refresh context
16
24
  if (!context.refreshContextData?.data) {
17
25
  return false;
@@ -44,14 +44,31 @@ export async function loadEntries(
44
44
 
45
45
  // Fetch all (modified) entries
46
46
  do {
47
+ // Build search parameters
48
+ const searchParams = new URLSearchParams({
49
+ page: `${++page}`,
50
+ perPage: "100"
51
+ });
52
+
53
+ const filters = [];
54
+ if (lastModified && options.updatedField) {
55
+ // If `lastModified` is set, only fetch entries that have been modified since the last fetch
56
+ filters.push(`(${options.updatedField}>"${lastModified}")`);
57
+ // Sort by the updated field and id
58
+ searchParams.set("sort", `-${options.updatedField},id`);
59
+ }
60
+ if (options.filter) {
61
+ filters.push(`(${options.filter})`);
62
+ }
63
+
64
+ // Add filters to search parameters
65
+ if (filters.length > 0) {
66
+ searchParams.set("filter", filters.join("&&"));
67
+ }
68
+
47
69
  // Fetch entries from the collection
48
- // If `lastModified` is set, only fetch entries that have been modified since the last fetch
49
70
  const collectionRequest = await fetch(
50
- `${collectionUrl}?page=${++page}&perPage=100${
51
- lastModified && options.updatedField
52
- ? `&sort=-${options.updatedField},id&filter=(${options.updatedField}>"${lastModified}")`
53
- : ""
54
- }`,
71
+ `${collectionUrl}?${searchParams.toString()}`,
55
72
  {
56
73
  headers: collectionHeaders
57
74
  }
@@ -73,4 +73,21 @@ export interface PocketBaseLoaderOptions {
73
73
  * The PocketBase API does always return at least `0` or `false` as the default values, even though the fields are not marked as required in the schema.
74
74
  */
75
75
  improveTypes?: boolean;
76
+ /**
77
+ * Custom filter that is applied when loading data from PocketBase.
78
+ * Valid syntax can be found in the [PocketBase documentation](https://pocketbase.io/docs/api-records/#listsearch-records)
79
+ *
80
+ * The loader will also add it's own filters for incremental builds.
81
+ * These will be added to your custom filter query.
82
+ *
83
+ * Example:
84
+ * ```ts
85
+ * // config:
86
+ * filter: 'release >= @now && deleted = false'
87
+ *
88
+ * // request
89
+ * `?filter=(${loaderFilter})&&(release >= @now && deleted = false)`
90
+ * ```
91
+ */
92
+ filter?: string;
76
93
  }