astro-loader-pocketbase 2.7.1-next.1 → 2.7.1-next.2
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.7.1-next.
|
|
3
|
+
"version": "2.7.1-next.2",
|
|
4
4
|
"description": "A content loader for Astro that uses the PocketBase API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"scripts": {
|
|
30
30
|
"format": "npx prettier . --write --cache",
|
|
31
31
|
"format:check": "npx prettier . --check --cache",
|
|
32
|
-
"lint": "
|
|
33
|
-
"lint:fix": "
|
|
32
|
+
"lint": "oxlint",
|
|
33
|
+
"lint:fix": "oxlint --fix",
|
|
34
34
|
"prepare": "husky",
|
|
35
35
|
"test": "vitest run",
|
|
36
36
|
"test:e2e": "vitest run $(find test -name '*.e2e-spec.ts')",
|
|
@@ -45,27 +45,23 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@commitlint/cli": "^19.8.1",
|
|
47
47
|
"@commitlint/config-conventional": "^19.8.1",
|
|
48
|
-
"@eslint/js": "^9.30.1",
|
|
49
|
-
"@stylistic/eslint-plugin": "^5.1.0",
|
|
50
48
|
"@types/node": "^22.14.1",
|
|
51
49
|
"@vitest/coverage-v8": "^3.2.4",
|
|
52
|
-
"astro": "^5.
|
|
53
|
-
"eslint": "^9.30.1",
|
|
54
|
-
"eslint-config-prettier": "^10.1.5",
|
|
50
|
+
"astro": "^5.12.8",
|
|
55
51
|
"globals": "^16.3.0",
|
|
56
52
|
"husky": "^9.1.7",
|
|
57
|
-
"lint-staged": "^16.1.
|
|
53
|
+
"lint-staged": "^16.1.4",
|
|
54
|
+
"oxlint": "^1.10.0",
|
|
58
55
|
"prettier": "^3.6.2",
|
|
59
|
-
"prettier-plugin-organize-imports": "^4.
|
|
60
|
-
"prettier-plugin-packagejson": "^2.5.
|
|
61
|
-
"typescript": "^5.
|
|
62
|
-
"typescript-eslint": "^8.35.1",
|
|
56
|
+
"prettier-plugin-organize-imports": "^4.2.0",
|
|
57
|
+
"prettier-plugin-packagejson": "^2.5.19",
|
|
58
|
+
"typescript": "^5.9.2",
|
|
63
59
|
"vitest": "^3.2.4"
|
|
64
60
|
},
|
|
65
61
|
"peerDependencies": {
|
|
66
62
|
"astro": "^5.0.0"
|
|
67
63
|
},
|
|
68
|
-
"packageManager": "npm@11.
|
|
64
|
+
"packageManager": "npm@11.5.2",
|
|
69
65
|
"publishConfig": {
|
|
70
66
|
"access": "public",
|
|
71
67
|
"provenance": true
|
package/src/pocketbase-loader.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ZodSchema } from "astro/zod";
|
|
|
3
3
|
import { loader } from "./loader/loader";
|
|
4
4
|
import { generateSchema } from "./schema/generate-schema";
|
|
5
5
|
import type { PocketBaseLoaderOptions } from "./types/pocketbase-loader-options.type";
|
|
6
|
-
import {
|
|
6
|
+
import { createTokenPromise } from "./utils/create-token-promise";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Loader for collections stored in PocketBase.
|
|
@@ -11,24 +11,8 @@ import { getSuperuserToken } from "./utils/get-superuser-token";
|
|
|
11
11
|
* @param options Options for the loader. See {@link PocketBaseLoaderOptions} for more details.
|
|
12
12
|
*/
|
|
13
13
|
export function pocketbaseLoader(options: PocketBaseLoaderOptions): Loader {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if ("impersonateToken" in options.superuserCredentials) {
|
|
17
|
-
// Impersonate token provided, so use it directly.
|
|
18
|
-
tokenPromise = Promise.resolve(
|
|
19
|
-
options.superuserCredentials.impersonateToken
|
|
20
|
-
);
|
|
21
|
-
} else {
|
|
22
|
-
// Email and password provided, so get a temporary superuser token.
|
|
23
|
-
tokenPromise = getSuperuserToken(
|
|
24
|
-
options.url,
|
|
25
|
-
options.superuserCredentials
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
// No credentials provided, so no token can be used.
|
|
30
|
-
tokenPromise = Promise.resolve(undefined);
|
|
31
|
-
}
|
|
14
|
+
// Create shared promise for the superuser token, which can be reused
|
|
15
|
+
const tokenPromise = createTokenPromise(options);
|
|
32
16
|
|
|
33
17
|
return {
|
|
34
18
|
name: "pocketbase-loader",
|
|
@@ -41,7 +41,7 @@ export function parseSchema(
|
|
|
41
41
|
lat: z.number()
|
|
42
42
|
});
|
|
43
43
|
break;
|
|
44
|
-
case "select":
|
|
44
|
+
case "select": {
|
|
45
45
|
if (!field.values) {
|
|
46
46
|
throw new Error(
|
|
47
47
|
`Field ${field.name} is of type "select" but has no values defined.`
|
|
@@ -55,6 +55,7 @@ export function parseSchema(
|
|
|
55
55
|
// Parse the field type based on the number of values it can have
|
|
56
56
|
fieldType = parseSingleOrMultipleValues(field, values);
|
|
57
57
|
break;
|
|
58
|
+
}
|
|
58
59
|
case "relation":
|
|
59
60
|
case "file":
|
|
60
61
|
// NOTE: Relations are currently not supported and are treated as strings
|
|
@@ -116,7 +117,7 @@ function parseSingleOrMultipleValues(
|
|
|
116
117
|
// If the select allows multiple values, create an array of the enum
|
|
117
118
|
if (field.maxSelect === undefined || field.maxSelect === 1) {
|
|
118
119
|
return type;
|
|
119
|
-
} else {
|
|
120
|
-
return z.array(type);
|
|
121
120
|
}
|
|
121
|
+
|
|
122
|
+
return z.array(type);
|
|
122
123
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PocketBaseLoaderOptions } from "../types/pocketbase-loader-options.type";
|
|
2
|
+
import { getSuperuserToken } from "./get-superuser-token";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a promise that resolves to a superuser token or undefined.
|
|
6
|
+
*/
|
|
7
|
+
export async function createTokenPromise(
|
|
8
|
+
options: Pick<PocketBaseLoaderOptions, "url" | "superuserCredentials">
|
|
9
|
+
): Promise<string | undefined> {
|
|
10
|
+
if (options.superuserCredentials) {
|
|
11
|
+
if ("impersonateToken" in options.superuserCredentials) {
|
|
12
|
+
// Impersonate token provided, so use it directly.
|
|
13
|
+
return options.superuserCredentials.impersonateToken;
|
|
14
|
+
}
|
|
15
|
+
// Email and password provided, so get a temporary superuser token.
|
|
16
|
+
const token = await getSuperuserToken(
|
|
17
|
+
options.url,
|
|
18
|
+
options.superuserCredentials
|
|
19
|
+
);
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// No credentials provided, so no token can be used.
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
package/src/utils/slugify.ts
CHANGED
|
@@ -10,13 +10,13 @@ export function slugify(input: string): string {
|
|
|
10
10
|
return input
|
|
11
11
|
.toString()
|
|
12
12
|
.toLowerCase()
|
|
13
|
-
.
|
|
14
|
-
.
|
|
15
|
-
.
|
|
16
|
-
.
|
|
17
|
-
.
|
|
18
|
-
.
|
|
19
|
-
.
|
|
13
|
+
.replaceAll(/\s+/g, "-") // Replace spaces with -
|
|
14
|
+
.replaceAll("ä", "ae") // Replace umlauts
|
|
15
|
+
.replaceAll("ö", "oe")
|
|
16
|
+
.replaceAll("ü", "ue")
|
|
17
|
+
.replaceAll("ß", "ss")
|
|
18
|
+
.replaceAll(/[^\w-]+/g, "") // Remove all non-word chars
|
|
19
|
+
.replaceAll(/--+/g, "-") // Replace multiple - with single -
|
|
20
20
|
.replace(/^-+/, "") // Trim - from start of text
|
|
21
21
|
.replace(/-+$/, ""); // Trim - from end of text
|
|
22
22
|
}
|