astro-loader-pocketbase 2.8.0-next.4 → 2.8.0-next.6

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.8.0-next.4",
3
+ "version": "2.8.0-next.6",
4
4
  "description": "A content loader for Astro that uses the PocketBase API",
5
5
  "keywords": [
6
6
  "astro",
@@ -47,11 +47,11 @@
47
47
  "@commitlint/config-conventional": "^19.8.1",
48
48
  "@types/node": "^22.14.1",
49
49
  "@vitest/coverage-v8": "^3.2.4",
50
- "astro": "^5.13.2",
50
+ "astro": "^5.13.5",
51
51
  "globals": "^16.3.0",
52
52
  "husky": "^9.1.7",
53
53
  "lint-staged": "^16.1.5",
54
- "oxlint": "^1.12.0",
54
+ "oxlint": "^1.14.0",
55
55
  "prettier": "^3.6.2",
56
56
  "prettier-plugin-organize-imports": "^4.2.0",
57
57
  "prettier-plugin-packagejson": "^2.5.19",
@@ -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 { PocketBaseLoaderBaseOptions } from "../types/pocketbase-loader-options.type";
3
3
 
4
4
  /**
5
5
  * Cleanup entries that are no longer in the collection.
@@ -9,7 +9,7 @@ import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options
9
9
  * @param superuserToken Superuser token to access all resources.
10
10
  */
11
11
  export async function cleanupEntries(
12
- options: PocketBaseLoaderOptions,
12
+ options: PocketBaseLoaderBaseOptions,
13
13
  context: LoaderContext,
14
14
  superuserToken: string | undefined
15
15
  ): Promise<void> {
@@ -1,6 +1,6 @@
1
1
  import type { PocketBaseEntry } from "../types/pocketbase-entry.type";
2
2
  import type { ExperimentalPocketBaseLiveLoaderCollectionFilter } from "../types/pocketbase-live-loader-filter.type";
3
- import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
3
+ import type { PocketBaseLoaderBaseOptions } from "../types/pocketbase-loader-options.type";
4
4
  import { combineFieldsForRequest } from "../utils/combine-fields-for-request";
5
5
  import { formatFields } from "../utils/format-fields";
6
6
 
@@ -19,15 +19,7 @@ export type CollectionFilter = {
19
19
  * Fetches entries from a PocketBase collection, optionally filtering by modification date and supporting pagination.
20
20
  */
21
21
  export async function fetchCollection<TEntry extends PocketBaseEntry>(
22
- options: Pick<
23
- PocketBaseLoaderOptions,
24
- | "collectionName"
25
- | "url"
26
- | "updatedField"
27
- | "filter"
28
- | "fields"
29
- | "superuserCredentials"
30
- >,
22
+ options: PocketBaseLoaderBaseOptions,
31
23
  chunkLoaded: (entries: Array<TEntry>) => Promise<void>,
32
24
  token: string | undefined,
33
25
  collectionFilter: CollectionFilter | undefined
@@ -108,7 +100,7 @@ export async function fetchCollection<TEntry extends PocketBaseEntry>(
108
100
  * Build search parameters for the PocketBase collection request.
109
101
  */
110
102
  function buildSearchParams(
111
- loaderOptions: Pick<PocketBaseLoaderOptions, "updatedField" | "filter">,
103
+ loaderOptions: PocketBaseLoaderBaseOptions,
112
104
  combinedFields: Array<string> | undefined,
113
105
  collectionFilter: CollectionFilter
114
106
  ): URLSearchParams {
@@ -8,7 +8,7 @@ import type { PocketBaseCollection } from "../types/pocketbase-schema.type";
8
8
  * @param token The superuser token to authenticate the request.
9
9
  */
10
10
  export async function getRemoteSchema(
11
- options: PocketBaseLoaderOptions,
11
+ options: Pick<PocketBaseLoaderOptions, "collectionName" | "url">,
12
12
  token: string
13
13
  ): Promise<PocketBaseCollection | undefined> {
14
14
  // Build URL and headers for the schema request
@@ -20,8 +20,6 @@ export interface ExperimentalPocketBaseLiveLoaderCollectionFilter {
20
20
  * Additional filter to apply to the collection.
21
21
  * This will be added to the filter supplied in the {@link ExperimentalPocketBaseLiveLoaderOptions}.
22
22
  *
23
- * Valid syntax can be found in the [PocketBase documentation](https://pocketbase.io/docs/api-records/#listsearch-records)
24
- *
25
23
  * Example:
26
24
  * ```ts
27
25
  * // config:
@@ -30,6 +28,8 @@ export interface ExperimentalPocketBaseLiveLoaderCollectionFilter {
30
28
  * // request
31
29
  * `?filter=(${loaderFilter})&&(release >= @now && deleted = false)`
32
30
  * ```
31
+ *
32
+ * @see {@link https://pocketbase.io/docs/api-records/#listsearch-records PocketBase documentation} for valid syntax
33
33
  */
34
34
  filter?: string;
35
35
  /**
@@ -44,8 +44,6 @@ export interface ExperimentalPocketBaseLiveLoaderCollectionFilter {
44
44
  /**
45
45
  * Sort order in which the entries should be returned.
46
46
  *
47
- * Valid syntax can be found in the [PocketBase documentation](https://pocketbase.io/docs/api-records/#listsearch-records)
48
- *
49
47
  * Example:
50
48
  * ```ts
51
49
  * // config:
@@ -54,6 +52,8 @@ export interface ExperimentalPocketBaseLiveLoaderCollectionFilter {
54
52
  * // request
55
53
  * `?sort=-created,id`
56
54
  * ```
55
+ *
56
+ * @see {@link https://pocketbase.io/docs/api-records/#listsearch-records PocketBase documentation} for valid syntax
57
57
  */
58
58
  sort?: string;
59
59
  }
@@ -1,9 +1,9 @@
1
1
  import type { z } from "astro/zod";
2
2
 
3
3
  /**
4
- * Options for the PocketBase loader.
4
+ * Options for both build time and live collection loader
5
5
  */
6
- export interface PocketBaseLoaderOptions {
6
+ export interface PocketBaseLoaderBaseOptions {
7
7
  /**
8
8
  * URL of the PocketBase instance.
9
9
  */
@@ -12,15 +12,6 @@ export interface PocketBaseLoaderOptions {
12
12
  * Name of the collection in PocketBase.
13
13
  */
14
14
  collectionName: string;
15
- /**
16
- * Field that should be used as the unique identifier for the collection.
17
- * This must be the name of a field in the collection that contains unique values.
18
- * If not provided, the `id` field will be used.
19
- * The value of this field will be used in `getEntry` and `getEntries` to load the entry or entries.
20
- *
21
- * If the field is a string, it will be slugified to be used in the URL.
22
- */
23
- idField?: string;
24
15
  /**
25
16
  * Name of the field(s) containing the content of an entry.
26
17
  * This must be the name of a field in the PocketBase collection that contains the content.
@@ -34,7 +25,8 @@ export interface PocketBaseLoaderOptions {
34
25
  /**
35
26
  * Name of the field containing the last update date of an entry.
36
27
  * Ideally, this field should be of type `autodate` and have the value "Update" or "Create/Update".
37
- * This field is used to only fetch entries that have been modified since the last build.
28
+ * For the build time loader, this field is used to only fetch entries that have been modified since the last build.
29
+ * For the live collection loader, this field is used to set the `lastModified` cache hint.
38
30
  */
39
31
  updatedField?: string;
40
32
  /**
@@ -105,6 +97,21 @@ export interface PocketBaseLoaderOptions {
105
97
  */
106
98
  impersonateToken: string;
107
99
  };
100
+ }
101
+
102
+ /**
103
+ * Options for the PocketBase loader.
104
+ */
105
+ export type PocketBaseLoaderOptions = PocketBaseLoaderBaseOptions & {
106
+ /**
107
+ * Field that should be used as the unique identifier for the collection.
108
+ * This must be the name of a field in the collection that contains unique values.
109
+ * If not provided, the `id` field will be used.
110
+ * The value of this field will be used in `getEntry` and `getEntries` to load the entry or entries.
111
+ *
112
+ * If the field is a string, it will be slugified to be used in the URL.
113
+ */
114
+ idField?: string;
108
115
  /**
109
116
  * File path to the local schema file.
110
117
  * This file will be used to generate the schema for the collection.
@@ -141,20 +148,12 @@ export interface PocketBaseLoaderOptions {
141
148
  */
142
149
  liveTypesOnly?: boolean;
143
150
  };
144
- }
151
+ };
145
152
 
146
153
  /**
147
154
  * Options for the PocketBase live loader.
148
155
  *
149
156
  * @experimental Live content collections are still experimental
150
157
  */
151
- export type ExperimentalPocketBaseLiveLoaderOptions = Pick<
152
- PocketBaseLoaderOptions,
153
- | "url"
154
- | "collectionName"
155
- | "contentFields"
156
- | "updatedField"
157
- | "filter"
158
- | "fields"
159
- | "superuserCredentials"
160
- >;
158
+ export type ExperimentalPocketBaseLiveLoaderOptions =
159
+ PocketBaseLoaderBaseOptions;
@@ -1,4 +1,7 @@
1
- import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
1
+ import type {
2
+ PocketBaseLoaderBaseOptions,
3
+ PocketBaseLoaderOptions
4
+ } from "../types/pocketbase-loader-options.type";
2
5
 
3
6
  /**
4
7
  * Combine basic, special, and user-specified fields for PocketBase API requests.
@@ -10,10 +13,8 @@ import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options
10
13
  */
11
14
  export function combineFieldsForRequest(
12
15
  userFields: Array<string> | undefined,
13
- options: Pick<
14
- PocketBaseLoaderOptions,
15
- "idField" | "updatedField" | "contentFields"
16
- >
16
+ options: Pick<PocketBaseLoaderBaseOptions, "updatedField" | "contentFields"> &
17
+ Pick<PocketBaseLoaderOptions, "idField">
17
18
  ): Array<string> | undefined {
18
19
  // If no fields specified, return undefined to get all fields
19
20
  if (!userFields) {
@@ -1,11 +1,11 @@
1
- import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
1
+ import type { PocketBaseLoaderBaseOptions } from "../types/pocketbase-loader-options.type";
2
2
  import { getSuperuserToken } from "./get-superuser-token";
3
3
 
4
4
  /**
5
5
  * Creates a promise that resolves to a superuser token or undefined.
6
6
  */
7
7
  export async function createTokenPromise(
8
- options: Pick<PocketBaseLoaderOptions, "url" | "superuserCredentials">
8
+ options: Pick<PocketBaseLoaderBaseOptions, "superuserCredentials" | "url">
9
9
  ): Promise<string | undefined> {
10
10
  if (options.superuserCredentials) {
11
11
  if ("impersonateToken" in options.superuserCredentials) {
@@ -1,4 +1,4 @@
1
- import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
1
+ import type { PocketBaseLoaderBaseOptions } from "../types/pocketbase-loader-options.type";
2
2
 
3
3
  /**
4
4
  * Format fields option into an array and validate for expand usage.
@@ -8,7 +8,7 @@ import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options
8
8
  * @returns Formatted fields array, or undefined if no fields specified or "*" wildcard is used
9
9
  */
10
10
  export function formatFields(
11
- fields: PocketBaseLoaderOptions["fields"]
11
+ fields: PocketBaseLoaderBaseOptions["fields"]
12
12
  ): Array<string> | undefined {
13
13
  if (!fields || fields.length === 0) {
14
14
  return undefined;