astro-loader-pocketbase 2.3.0-next.1 → 2.3.1-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,35 +1,41 @@
1
1
  {
2
2
  "name": "astro-loader-pocketbase",
3
- "version": "2.3.0-next.1",
3
+ "version": "2.3.1-next.1",
4
4
  "description": "A content loader for Astro that uses the PocketBase API",
5
5
  "license": "MIT",
6
6
  "author": "Luis Wolf <development@pawcode.de> (https://pawcode.de)",
7
7
  "homepage": "https://github.com/pawcoding/astro-loader-pocketbase",
8
8
  "type": "module",
9
9
  "exports": {
10
- ".": "./index.ts"
10
+ ".": "./src/index.ts"
11
11
  },
12
12
  "files": [
13
- "index.ts",
14
13
  "src"
15
14
  ],
16
15
  "scripts": {
17
- "lint": "npx eslint",
16
+ "lint": "npx eslint --cache",
17
+ "lint:fix": "npx eslint --fix --cache",
18
+ "format": "npx prettier . --write --cache",
19
+ "format:check": "npx prettier . --check --cache",
18
20
  "prepare": "husky"
19
21
  },
20
22
  "peerDependencies": {
21
23
  "astro": "^5.0.0"
22
24
  },
23
25
  "devDependencies": {
24
- "@eslint/js": "^9.18.0",
25
- "@stylistic/eslint-plugin": "^2.13.0",
26
- "@types/node": "^22.10.7",
27
- "astro": "^5.1.8",
28
- "eslint": "^9.18.0",
26
+ "@commitlint/cli": "^19.6.1",
27
+ "@commitlint/config-conventional": "^19.6.0",
28
+ "@eslint/js": "^9.19.0",
29
+ "@stylistic/eslint-plugin": "^3.0.1",
30
+ "@types/node": "^22.13.0",
31
+ "astro": "^5.2.3",
32
+ "eslint": "^9.19.0",
33
+ "eslint-config-prettier": "^10.0.1",
29
34
  "globals": "^15.14.0",
30
35
  "husky": "^9.1.7",
36
+ "prettier": "3.4.2",
31
37
  "typescript": "^5.7.3",
32
- "typescript-eslint": "^8.21.0"
38
+ "typescript-eslint": "^8.22.0"
33
39
  },
34
40
  "keywords": [
35
41
  "astro",
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { pocketbaseLoader } from "./pocketbase-loader";
2
+ import type { PocketBaseLoaderOptions } from "./types/pocketbase-loader-options.type";
3
+
4
+ export { pocketbaseLoader };
5
+ export type { PocketBaseLoaderOptions };
@@ -1,5 +1,5 @@
1
1
  import type { LoaderContext } from "astro/loaders";
2
- import type { PocketBaseLoaderOptions } from "./types/pocketbase-loader-options.type";
2
+ import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
3
3
 
4
4
  /**
5
5
  * Cleanup entries that are no longer in the collection.
@@ -1,7 +1,7 @@
1
1
  import type { LoaderContext } from "astro/loaders";
2
- import type { PocketBaseLoaderOptions } from "./types/pocketbase-loader-options.type";
3
- import { isRealtimeData } from "./utils/is-realtime-data";
4
- import { parseEntry } from "./utils/parse-entry";
2
+ import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
3
+ import { isRealtimeData } from "../utils/is-realtime-data";
4
+ import { parseEntry } from "./parse-entry";
5
5
 
6
6
  /**
7
7
  * Handles realtime updates for the loader without making any new network requests.
@@ -1,6 +1,6 @@
1
1
  import type { LoaderContext } from "astro/loaders";
2
- import type { PocketBaseLoaderOptions } from "./types/pocketbase-loader-options.type";
3
- import { parseEntry } from "./utils/parse-entry";
2
+ import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
3
+ import { parseEntry } from "./parse-entry";
4
4
 
5
5
  /**
6
6
  * Load (modified) entries from a PocketBase collection.
@@ -0,0 +1,78 @@
1
+ import type { LoaderContext } from "astro/loaders";
2
+ import packageJson from "../../package.json";
3
+ import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
4
+ import { getSuperuserToken } from "../utils/get-superuser-token";
5
+ import { shouldRefresh } from "../utils/should-refresh";
6
+ import { cleanupEntries } from "./cleanup-entries";
7
+ import { handleRealtimeUpdates } from "./handle-realtime-updates";
8
+ import { loadEntries } from "./load-entries";
9
+
10
+ export async function loader(
11
+ context: LoaderContext,
12
+ options: PocketBaseLoaderOptions
13
+ ): Promise<void> {
14
+ context.logger.label = `pocketbase-loader:${options.collectionName}`;
15
+
16
+ // Check if the collection should be refreshed.
17
+ const refresh = shouldRefresh(
18
+ context.refreshContextData,
19
+ options.collectionName
20
+ );
21
+ if (!refresh) {
22
+ return;
23
+ }
24
+
25
+ // Handle realtime updates
26
+ const handled = await handleRealtimeUpdates(context, options);
27
+ if (handled) {
28
+ return;
29
+ }
30
+
31
+ // Get the date of the last fetch to only update changed entries.
32
+ let lastModified = context.meta.get("last-modified");
33
+
34
+ // Check if the version has changed to force an update
35
+ const lastVersion = context.meta.get("version");
36
+ if (lastVersion !== packageJson.version) {
37
+ if (lastVersion) {
38
+ context.logger.info(
39
+ `PocketBase loader was updated from ${lastVersion} to ${packageJson.version}. All entries will be loaded again.`
40
+ );
41
+ }
42
+
43
+ // Disable incremental builds and clear the store
44
+ lastModified = undefined;
45
+ context.store.clear();
46
+ }
47
+
48
+ // Disable incremental builds if no updated field is provided
49
+ if (!options.updatedField) {
50
+ context.logger.info(
51
+ `No "updatedField" was provided. Incremental builds are disabled.`
52
+ );
53
+ lastModified = undefined;
54
+ }
55
+
56
+ // Try to get a superuser token to access all resources.
57
+ let token: string | undefined;
58
+ if (options.superuserCredentials) {
59
+ token = await getSuperuserToken(
60
+ options.url,
61
+ options.superuserCredentials,
62
+ context.logger
63
+ );
64
+ }
65
+
66
+ if (context.store.keys().length > 0) {
67
+ // Cleanup entries that are no longer in the collection
68
+ await cleanupEntries(options, context, token);
69
+ }
70
+
71
+ // Load the (modified) entries
72
+ await loadEntries(options, context, token, lastModified);
73
+
74
+ // Set the last modified date to the current date
75
+ context.meta.set("last-modified", new Date().toISOString().replace("T", " "));
76
+
77
+ context.meta.set("version", packageJson.version);
78
+ }
@@ -1,7 +1,7 @@
1
1
  import type { LoaderContext } from "astro/loaders";
2
2
  import type { PocketBaseEntry } from "../types/pocketbase-entry.type";
3
3
  import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
4
- import { slugify } from "./slugify";
4
+ import { slugify } from "../utils/slugify";
5
5
 
6
6
  /**
7
7
  * Parse an entry from PocketBase to match the schema and store it in the store.
@@ -1,12 +1,7 @@
1
- import type { Loader, LoaderContext } from "astro/loaders";
2
- import packageJson from "./../package.json";
3
- import { cleanupEntries } from "./cleanup-entries";
4
- import { generateSchema } from "./generate-schema";
5
- import { handleRealtimeUpdates } from "./handle-realtime-updates";
6
- import { loadEntries } from "./load-entries";
1
+ import type { Loader } from "astro/loaders";
2
+ import { loader } from "./loader/loader";
3
+ import { generateSchema } from "./schema/generate-schema";
7
4
  import type { PocketBaseLoaderOptions } from "./types/pocketbase-loader-options.type";
8
- import { getSuperuserToken } from "./utils/get-superuser-token";
9
- import { shouldRefresh } from "./utils/should-refresh";
10
5
 
11
6
  /**
12
7
  * Loader for collections stored in PocketBase.
@@ -16,78 +11,9 @@ import { shouldRefresh } from "./utils/should-refresh";
16
11
  export function pocketbaseLoader(options: PocketBaseLoaderOptions): Loader {
17
12
  return {
18
13
  name: "pocketbase-loader",
19
- load: async (context: LoaderContext): Promise<void> => {
20
- context.logger.label = `pocketbase-loader:${options.collectionName}`;
21
-
22
- // Check if the collection should be refreshed.
23
- const refresh = shouldRefresh(
24
- context.refreshContextData,
25
- options.collectionName
26
- );
27
- if (!refresh) {
28
- return;
29
- }
30
-
31
- // Handle realtime updates
32
- const handled = await handleRealtimeUpdates(context, options);
33
- if (handled) {
34
- return;
35
- }
36
-
37
- // Get the date of the last fetch to only update changed entries.
38
- let lastModified = context.meta.get("last-modified");
39
-
40
- // Check if the version has changed to force an update
41
- const lastVersion = context.meta.get("version");
42
- if (lastVersion !== packageJson.version) {
43
- if (lastVersion) {
44
- context.logger.info(
45
- `PocketBase loader was updated from ${lastVersion} to ${packageJson.version}. All entries will be loaded again.`
46
- );
47
- }
48
-
49
- // Disable incremental builds and clear the store
50
- lastModified = undefined;
51
- context.store.clear();
52
- }
53
-
54
- // Disable incremental builds if no updated field is provided
55
- if (!options.updatedField) {
56
- context.logger.info(
57
- `No "updatedField" was provided. Incremental builds are disabled.`
58
- );
59
- lastModified = undefined;
60
- }
61
-
62
- // Try to get a superuser token to access all resources.
63
- let token: string | undefined;
64
- if (options.superuserCredentials) {
65
- token = await getSuperuserToken(
66
- options.url,
67
- options.superuserCredentials,
68
- context.logger
69
- );
70
- }
71
-
72
- if (context.store.keys().length > 0) {
73
- // Cleanup entries that are no longer in the collection
74
- await cleanupEntries(options, context, token);
75
- }
76
-
77
- // Load the (modified) entries
78
- await loadEntries(options, context, token, lastModified);
79
-
80
- // Set the last modified date to the current date
81
- context.meta.set(
82
- "last-modified",
83
- new Date().toISOString().replace("T", " ")
84
- );
85
-
86
- context.meta.set("version", packageJson.version);
87
- },
88
- schema: async () => {
89
- // Generate the schema for the collection according to the API
90
- return await generateSchema(options);
91
- }
14
+ // Load the entries from the collection
15
+ load: async (context) => loader(context, options),
16
+ // Generate the schema for the collection according to the API
17
+ schema: async () => await generateSchema(options)
92
18
  };
93
19
  }
@@ -1,11 +1,11 @@
1
1
  import type { ZodSchema } from "astro/zod";
2
2
  import { z } from "astro/zod";
3
- import type { PocketBaseLoaderOptions } from "./types/pocketbase-loader-options.type";
4
- import type { PocketBaseCollection } from "./types/pocketbase-schema.type";
5
- import { getRemoteSchema } from "./utils/get-remote-schema";
6
- import { parseSchema } from "./utils/parse-schema";
7
- import { readLocalSchema } from "./utils/read-local-schema";
8
- import { transformFiles } from "./utils/transform-files";
3
+ import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
4
+ import type { PocketBaseCollection } from "../types/pocketbase-schema.type";
5
+ import { getRemoteSchema } from "./get-remote-schema";
6
+ import { parseSchema } from "./parse-schema";
7
+ import { readLocalSchema } from "./read-local-schema";
8
+ import { transformFiles } from "./transform-files";
9
9
 
10
10
  /**
11
11
  * Basic schema for every PocketBase collection.
@@ -1,6 +1,6 @@
1
1
  import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
2
2
  import type { PocketBaseCollection } from "../types/pocketbase-schema.type";
3
- import { getSuperuserToken } from "./get-superuser-token";
3
+ import { getSuperuserToken } from "../utils/get-superuser-token";
4
4
 
5
5
  /**
6
6
  * Fetches the schema for the specified collection from the PocketBase instance.
@@ -106,7 +106,7 @@ export function parseSchema(
106
106
  function parseSingleOrMultipleValues(
107
107
  field: PocketBaseSchemaEntry,
108
108
  type: z.ZodType
109
- ) {
109
+ ): z.ZodType {
110
110
  // If the select allows multiple values, create an array of the enum
111
111
  if (field.maxSelect === undefined || field.maxSelect === 1) {
112
112
  return type;
package/index.ts DELETED
@@ -1,5 +0,0 @@
1
- import { pocketbaseLoader } from "./src/pocketbase-loader";
2
- import type { PocketBaseLoaderOptions } from "./src/types/pocketbase-loader-options.type";
3
-
4
- export { pocketbaseLoader };
5
- export type { PocketBaseLoaderOptions };
File without changes
File without changes