astro-loader-pocketbase 3.1.1 → 3.1.2-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/dist/index.d.mts +276 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +973 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +23 -14
- package/src/index.ts +0 -24
- package/src/loader/cleanup-entries.ts +0 -137
- package/src/loader/fetch-collection.ts +0 -177
- package/src/loader/fetch-entry.ts +0 -83
- package/src/loader/handle-realtime-updates.ts +0 -56
- package/src/loader/live-collection-loader.ts +0 -51
- package/src/loader/live-entry-loader.ts +0 -38
- package/src/loader/load-entries.ts +0 -52
- package/src/loader/loader.ts +0 -77
- package/src/loader/parse-entry.ts +0 -90
- package/src/loader/parse-live-entry.ts +0 -66
- package/src/pocketbase-loader.ts +0 -98
- package/src/schema/generate-schema.ts +0 -200
- package/src/schema/generate-type.ts +0 -23
- package/src/schema/get-remote-schema.ts +0 -43
- package/src/schema/parse-schema.ts +0 -170
- package/src/schema/read-local-schema.ts +0 -46
- package/src/schema/transform-files.ts +0 -67
- package/src/tsconfig.json +0 -7
- package/src/types/errors.ts +0 -19
- package/src/types/pocketbase-api-response.type.ts +0 -40
- package/src/types/pocketbase-entry.type.ts +0 -24
- package/src/types/pocketbase-live-loader-filter.type.ts +0 -55
- package/src/types/pocketbase-loader-options.type.ts +0 -146
- package/src/types/pocketbase-schema.type.ts +0 -101
- package/src/utils/combine-fields-for-request.ts +0 -55
- package/src/utils/create-token-promise.ts +0 -25
- package/src/utils/extract-field-names.ts +0 -15
- package/src/utils/format-fields.ts +0 -66
- package/src/utils/get-superuser-token.ts +0 -76
- package/src/utils/is-realtime-data.ts +0 -34
- package/src/utils/should-refresh.ts +0 -37
- package/src/utils/slugify.ts +0 -21
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { LiveCollectionError } from "astro/content/runtime";
|
|
2
|
+
import { ZodType, z } from "astro/zod";
|
|
3
|
+
import { LiveLoader, LoaderContext } from "astro/loaders";
|
|
4
|
+
|
|
5
|
+
//#region src/types/pocketbase-entry.type.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Schema for a PocketBase entry.
|
|
8
|
+
*/
|
|
9
|
+
declare const pocketBaseEntry: z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
collectionId: z.ZodString;
|
|
12
|
+
collectionName: z.ZodString;
|
|
13
|
+
}, z.core.$loose>;
|
|
14
|
+
/**
|
|
15
|
+
* Type for a PocketBase entry.
|
|
16
|
+
*/
|
|
17
|
+
type PocketBaseEntry = z.infer<typeof pocketBaseEntry>;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/types/pocketbase-live-loader-filter.type.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* Filter for a single entry
|
|
22
|
+
*/
|
|
23
|
+
interface PocketBaseLiveLoaderEntryFilter {
|
|
24
|
+
/**
|
|
25
|
+
* Id of the entry.
|
|
26
|
+
*/
|
|
27
|
+
id: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Filter for a collection of entries.
|
|
31
|
+
*/
|
|
32
|
+
interface PocketBaseLiveLoaderCollectionFilter {
|
|
33
|
+
/**
|
|
34
|
+
* Additional filter to apply to the collection.
|
|
35
|
+
* This will be added to the filter supplied in the {@link PocketBaseLiveLoaderOptions}.
|
|
36
|
+
*
|
|
37
|
+
* Example:
|
|
38
|
+
* ```ts
|
|
39
|
+
* // config:
|
|
40
|
+
* filter: 'release >= @now && deleted = false'
|
|
41
|
+
*
|
|
42
|
+
* // request
|
|
43
|
+
* `?filter=(${loaderFilter})&&(release >= @now && deleted = false)`
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @see {@link https://pocketbase.io/docs/api-records/#listsearch-records PocketBase documentation} for valid syntax
|
|
47
|
+
*/
|
|
48
|
+
filter?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Page number to load (1-indexed).
|
|
51
|
+
*/
|
|
52
|
+
page?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Number of entries to load per page.
|
|
55
|
+
* If not provided all entries will be loaded in chunks of 100.
|
|
56
|
+
*/
|
|
57
|
+
perPage?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Sort order in which the entries should be returned.
|
|
60
|
+
*
|
|
61
|
+
* Example:
|
|
62
|
+
* ```ts
|
|
63
|
+
* // config:
|
|
64
|
+
* sort: '-created,id'
|
|
65
|
+
*
|
|
66
|
+
* // request
|
|
67
|
+
* `?sort=-created,id`
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://pocketbase.io/docs/api-records/#listsearch-records PocketBase documentation} for valid syntax
|
|
71
|
+
*/
|
|
72
|
+
sort?: string;
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/types/pocketbase-loader-options.type.d.ts
|
|
76
|
+
/**
|
|
77
|
+
* Options for both build time and live collection loader
|
|
78
|
+
*/
|
|
79
|
+
interface PocketBaseLoaderBaseOptions {
|
|
80
|
+
/**
|
|
81
|
+
* URL of the PocketBase instance.
|
|
82
|
+
*/
|
|
83
|
+
url: string;
|
|
84
|
+
/**
|
|
85
|
+
* Name of the collection in PocketBase.
|
|
86
|
+
*/
|
|
87
|
+
collectionName: string;
|
|
88
|
+
/**
|
|
89
|
+
* Name of the field(s) containing the content of an entry.
|
|
90
|
+
* This must be the name of a field in the PocketBase collection that contains the content.
|
|
91
|
+
* The content will be parsed as HTML and rendered to the page.
|
|
92
|
+
*
|
|
93
|
+
* If you want to render multiple fields as main content, you can pass an array of field names.
|
|
94
|
+
* The loader will concatenate the content of all fields in the order they are defined in the array.
|
|
95
|
+
* Each block will be contained in a `<section>` element.
|
|
96
|
+
*/
|
|
97
|
+
contentFields?: string | Array<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Name of the field containing the last update date of an entry.
|
|
100
|
+
* Ideally, this field should be of type `autodate` and have the value "Update" or "Create/Update".
|
|
101
|
+
* For the build time loader, this field is used to only fetch entries that have been modified since the last build.
|
|
102
|
+
* For the live collection loader, this field is used to set the `lastModified` cache hint.
|
|
103
|
+
*/
|
|
104
|
+
updatedField?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Custom filter that is applied when loading data from PocketBase.
|
|
107
|
+
*
|
|
108
|
+
* The loader will also add it's own filters for incremental builds.
|
|
109
|
+
* These will be added to your custom filter query.
|
|
110
|
+
*
|
|
111
|
+
* Example:
|
|
112
|
+
* ```ts
|
|
113
|
+
* // config:
|
|
114
|
+
* filter: 'release >= @now && deleted = false'
|
|
115
|
+
*
|
|
116
|
+
* // request
|
|
117
|
+
* `?filter=(${loaderFilter})&&(release >= @now && deleted = false)`
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @see {@link https://pocketbase.io/docs/api-records/#listsearch-records PocketBase documentation} for valid syntax
|
|
121
|
+
*/
|
|
122
|
+
filter?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Specify which fields to return for each record.
|
|
125
|
+
* This can be either a comma-separated string of field names or an array of field names.
|
|
126
|
+
* Only the specified fields will be included in the response and schema.
|
|
127
|
+
*
|
|
128
|
+
* Use "*" to include all fields (same as not specifying the fields option).
|
|
129
|
+
*
|
|
130
|
+
* Note: The basic fields (`id`, `collectionId`, `collectionName`) are automatically included
|
|
131
|
+
* in API requests when using field filtering. Additionally, any custom fields specified in the
|
|
132
|
+
* loader options (`idField`, `updatedField`, `contentFields`) are also automatically included.
|
|
133
|
+
*
|
|
134
|
+
* Warning: Expand fields are not currently supported by this loader.
|
|
135
|
+
*
|
|
136
|
+
* Example:
|
|
137
|
+
* ```ts
|
|
138
|
+
* // Using string format:
|
|
139
|
+
* fields: 'title,content,author'
|
|
140
|
+
*
|
|
141
|
+
* // Using array format:
|
|
142
|
+
* fields: ['title', 'content', 'author']
|
|
143
|
+
*
|
|
144
|
+
* // Include all fields:
|
|
145
|
+
* fields: '*'
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @see {@link https://pocketbase.io/docs/api-records/#listsearch-records PocketBase documentation} for valid syntax
|
|
149
|
+
*/
|
|
150
|
+
fields?: string | Array<string>;
|
|
151
|
+
/**
|
|
152
|
+
* Credentials of a superuser to get full access to the PocketBase instance.
|
|
153
|
+
* This is required to get automatic type generation without a local schema, to access all resources even if they are not public and to fetch content of hidden fields.
|
|
154
|
+
*/
|
|
155
|
+
superuserCredentials?: {
|
|
156
|
+
/**
|
|
157
|
+
* Email of the superuser.
|
|
158
|
+
*/
|
|
159
|
+
email: string;
|
|
160
|
+
/**
|
|
161
|
+
* Password of the superuser.
|
|
162
|
+
*/
|
|
163
|
+
password: string;
|
|
164
|
+
} | {
|
|
165
|
+
/**
|
|
166
|
+
* Impersonate auth token of the superuser.
|
|
167
|
+
* This token will take precedence over the email and password.
|
|
168
|
+
*/
|
|
169
|
+
impersonateToken: string;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Options for the PocketBase loader.
|
|
174
|
+
*/
|
|
175
|
+
type PocketBaseLoaderOptions = PocketBaseLoaderBaseOptions & {
|
|
176
|
+
/**
|
|
177
|
+
* Field that should be used as the unique identifier for the collection.
|
|
178
|
+
* This must be the name of a field in the collection that contains unique values.
|
|
179
|
+
* If not provided, the `id` field will be used.
|
|
180
|
+
* The value of this field will be used in `getEntry` and `getEntries` to load the entry or entries.
|
|
181
|
+
*
|
|
182
|
+
* If the field is a string, it will be slugified to be used in the URL.
|
|
183
|
+
*/
|
|
184
|
+
idField?: string;
|
|
185
|
+
/**
|
|
186
|
+
* File path to the local schema file.
|
|
187
|
+
* This file will be used to generate the schema for the collection.
|
|
188
|
+
* If `superuserCredentials` are provided, this option will be ignored.
|
|
189
|
+
*/
|
|
190
|
+
localSchema?: string;
|
|
191
|
+
/**
|
|
192
|
+
* Record of zod schemas for all JSON fields in the collection.
|
|
193
|
+
* The key must be the name of a field in the collection.
|
|
194
|
+
* If no schema is provided for a field, the value will be treated as `unknown`.
|
|
195
|
+
*
|
|
196
|
+
* Note that this will only be used for fields of type `json`.
|
|
197
|
+
*/
|
|
198
|
+
jsonSchemas?: Record<string, ZodType>;
|
|
199
|
+
/**
|
|
200
|
+
* Experimental options for the loader.
|
|
201
|
+
*
|
|
202
|
+
* @experimental All of these options are experimental and may change in the future.
|
|
203
|
+
*/
|
|
204
|
+
experimental?: {
|
|
205
|
+
/**
|
|
206
|
+
* Whether to only create types for the live loader.
|
|
207
|
+
* This will not load any data, but only generate types that can be used with the live loader.
|
|
208
|
+
*/
|
|
209
|
+
liveTypesOnly?: boolean;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Options for the PocketBase live loader.
|
|
214
|
+
*/
|
|
215
|
+
type PocketBaseLiveLoaderOptions = PocketBaseLoaderBaseOptions;
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/pocketbase-loader.d.ts
|
|
218
|
+
/**
|
|
219
|
+
* Loader for collections stored in PocketBase.
|
|
220
|
+
*
|
|
221
|
+
* @param options Options for the loader. See {@link PocketBaseLoaderOptions} for more details.
|
|
222
|
+
*/
|
|
223
|
+
declare function pocketbaseLoader(options: PocketBaseLoaderOptions): {
|
|
224
|
+
name: string;
|
|
225
|
+
load: (context: LoaderContext) => Promise<void>;
|
|
226
|
+
createSchema: () => Promise<{
|
|
227
|
+
schema: import("zod/v4").ZodObject<{
|
|
228
|
+
id: import("zod/v4").ZodString;
|
|
229
|
+
collectionId: import("zod/v4").ZodString;
|
|
230
|
+
collectionName: import("zod/v4").ZodString;
|
|
231
|
+
}, import("zod/v4/core").$strip> | import("zod/v4").ZodPipe<import("zod/v4").ZodObject<{
|
|
232
|
+
id: import("zod/v4").ZodString;
|
|
233
|
+
collectionId: import("zod/v4").ZodString;
|
|
234
|
+
collectionName: import("zod/v4").ZodString;
|
|
235
|
+
}, import("zod/v4/core").$strip>, import("zod/v4").ZodTransform<{
|
|
236
|
+
[x: string]: unknown;
|
|
237
|
+
id: string;
|
|
238
|
+
collectionId: string;
|
|
239
|
+
collectionName: string;
|
|
240
|
+
}, {
|
|
241
|
+
id: string;
|
|
242
|
+
collectionId: string;
|
|
243
|
+
collectionName: string;
|
|
244
|
+
}>>;
|
|
245
|
+
types: string;
|
|
246
|
+
}>;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Live loader for collections stored in PocketBase.
|
|
250
|
+
*
|
|
251
|
+
* @param options Options for the live loader. See {@link PocketBaseLiveLoaderOptions} for more details.
|
|
252
|
+
*/
|
|
253
|
+
declare function pocketbaseLiveLoader<TEntry extends PocketBaseEntry>(options: PocketBaseLiveLoaderOptions): LiveLoader<TEntry, PocketBaseLiveLoaderEntryFilter, PocketBaseLiveLoaderCollectionFilter, LiveCollectionError>;
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/schema/transform-files.d.ts
|
|
256
|
+
/**
|
|
257
|
+
* Transforms a file name to a PocketBase file URL.
|
|
258
|
+
*
|
|
259
|
+
* @param base Base URL of the PocketBase instance.
|
|
260
|
+
* @param collectionName Name of the collection.
|
|
261
|
+
* @param entryId ID of the entry.
|
|
262
|
+
* @param file Name of the file.
|
|
263
|
+
*/
|
|
264
|
+
declare function transformFileUrl(base: string, collectionName: string, entryId: string, file: string): string;
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/types/errors.d.ts
|
|
267
|
+
/**
|
|
268
|
+
* Error thrown when there is an authentication issue with PocketBase.
|
|
269
|
+
*/
|
|
270
|
+
declare class PocketBaseAuthenticationError extends LiveCollectionError {
|
|
271
|
+
constructor(collection: string, message: string);
|
|
272
|
+
static is(error: unknown): error is PocketBaseAuthenticationError;
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
export { PocketBaseAuthenticationError, type PocketBaseLiveLoaderCollectionFilter, type PocketBaseLiveLoaderEntryFilter, type PocketBaseLiveLoaderOptions, type PocketBaseLoaderOptions, pocketbaseLiveLoader, pocketbaseLoader, transformFileUrl };
|
|
276
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/pocketbase-entry.type.ts","../src/types/pocketbase-live-loader-filter.type.ts","../src/types/pocketbase-loader-options.type.ts","../src/pocketbase-loader.ts","../src/schema/transform-files.ts","../src/types/errors.ts"],"mappings":";;;;;;;;cAKa,eAAA,EAAe,CAAA,CAAA,SAAA;;;;;;;;KAkBhB,eAAA,GAAkB,CAAA,CAAE,KAAK,QAAQ,eAAA;;;;;;UCpB5B,+BAAA;;ADEjB;;ECEE,EAAE;AAAA;;;;UAMa,oCAAA;EDRW;;;;;;;;;;;;;;;ECwB1B,MAAA;;;ADNF;ECUE,IAAA;;;;;EAKA,OAAA;EDf0D;AAAA;;;;ACpB5D;;;;AAII;AAMJ;;;;EAwCE,IAAA;AAAA;;;;;;UChDe,2BAAA;EFAJ;;;EEIX,GAAA;;;;EAIA,cAAA;EFR0B;;;;;;;;;EEkB1B,aAAA,YAAyB,KAAA;;;;;;;EAOzB,YAAA;;AFPF;;;;;;;;AAA4D;;;;ACpB5D;;;;EC6CE,MAAA;EDnCe;;;;;;;;;AAwCX;;;;AChDN;;;;;;;;;;;;;;EAuEE,MAAA,YAAkB,KAAK;EAqBjB;;AAAgB;AAOxB;EAvBE,oBAAA;IAuBiC;;;IAlB3B,KAAA;IAyCc;;;IArCd,QAAA;EAAA;IAqCN;;;;IA9BM,gBAAA;EAAA;AAAA;AAgDR;;;AAAA,KAzCY,uBAAA,GAA0B,2BAAA;EAyC+B;;;;ACxHrE;;;;EDwFE,OAAA;EClFwC;;;;;EDwFxC,WAAA;;;;;;;;EAQA,WAAA,GAAc,MAAA,SAAe,OAAA;;;;;;EAM7B,YAAA;;;;;IAKE,aAAA;EAAA;AAAA;;;;KAOQ,2BAAA,GAA8B,2BAA2B;;;AF5IrE;;;;;AAAA,iBGoBgB,gBAAA,CAAiB,OAAA,EAAS,uBAAA;;kBAMhB,aAAA,KAAgB,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AHRkB;iBG0C5C,oBAAA,gBAAoC,eAAA,CAAA,CAClD,OAAA,EAAS,2BAAA,GACR,UAAA,CACD,MAAA,EACA,+BAAA,EACA,oCAAA,EACA,mBAAA;;;;;;;;;;;iBCZc,gBAAA,CACd,IAAA,UACA,cAAA,UACA,OAAA,UACA,IAAA;;;;;;cC1DW,6BAAA,SAAsC,mBAAmB;cACxD,UAAA,UAAoB,OAAA;EAAA,OAKzB,EAAA,CAAG,KAAA,YAAiB,KAAA,IAAS,6BAAA;AAAA"}
|