astro-loader-pocketbase 3.0.0 → 3.1.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": "3.0.0",
3
+ "version": "3.1.0-next.1",
4
4
  "description": "A content loader for Astro that uses the PocketBase API",
5
5
  "keywords": [
6
6
  "astro",
@@ -44,26 +44,26 @@
44
44
  "test:unit": "vitest run $(find test -name '*.spec.ts')",
45
45
  "test:unit:watch": "vitest watch $(find test -name '*.spec.ts')",
46
46
  "test:watch": "vitest watch",
47
- "typecheck": "npx @typescript/native-preview --noEmit"
47
+ "typecheck": "npx @typescript/native-preview --noEmit -p src/tsconfig.json && npx @typescript/native-preview --noEmit -p test/tsconfig.json"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@commitlint/cli": "20.5.0",
51
51
  "@commitlint/config-conventional": "20.5.0",
52
52
  "@types/node": "24.10.1",
53
- "@vitest/coverage-v8": "4.1.0",
54
- "astro": "6.0.8",
55
- "globals": "17.4.0",
53
+ "@vitest/coverage-v8": "4.1.4",
54
+ "astro": "6.1.8",
55
+ "globals": "17.5.0",
56
56
  "husky": "9.1.7",
57
57
  "lint-staged": "16.4.0",
58
- "oxfmt": "0.41.0",
59
- "oxlint": "1.56.0",
60
- "oxlint-tsgolint": "0.17.1",
61
- "vitest": "4.1.0",
58
+ "oxfmt": "0.45.0",
59
+ "oxlint": "1.60.0",
60
+ "oxlint-tsgolint": "0.21.1",
61
+ "vitest": "4.1.4",
62
62
  "zod-to-ts": "2.0.0"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "astro": "^6.0.0",
66
66
  "zod-to-ts": "^2.0.0"
67
67
  },
68
- "packageManager": "npm@11.12.0"
68
+ "packageManager": "npm@11.12.1"
69
69
  }
@@ -43,7 +43,6 @@ export function pocketbaseLoader(options: PocketBaseLoaderOptions) {
43
43
  // Load the entries from the collection
44
44
  await loader(context, options, token);
45
45
  },
46
- // oxlint-disable-next-line explicit-module-boundary-types
47
46
  createSchema: async () => {
48
47
  const token = await tokenPromise;
49
48
 
@@ -13,9 +13,19 @@ import { transformFiles } from "./transform-files";
13
13
  * Basic schema for every PocketBase collection.
14
14
  */
15
15
  const BASIC_SCHEMA = z.object({
16
- id: z.string(),
17
- collectionId: z.string(),
18
- collectionName: z.string()
16
+ id: z.string().meta({
17
+ title: "id",
18
+ description: "The unique identifier for the entry."
19
+ }),
20
+ collectionId: z.string().meta({
21
+ title: "collectionId",
22
+ description:
23
+ "The unique identifier for the collection the entity belongs to."
24
+ }),
25
+ collectionName: z.string().meta({
26
+ title: "collectionName",
27
+ description: "The name of the collection the entity belongs to."
28
+ })
19
29
  });
20
30
 
21
31
  /**
@@ -45,7 +45,6 @@ export function parseSchema(
45
45
  let fieldType: z.ZodType;
46
46
 
47
47
  // Determine the field type and create the corresponding Zod type
48
- // oxlint-disable-next-line switch-exhaustiveness-check
49
48
  switch (field.type) {
50
49
  case "number":
51
50
  fieldType = z.number();
@@ -93,13 +92,8 @@ export function parseSchema(
93
92
  fieldType = parseSingleOrMultipleValues(field, z.string());
94
93
  break;
95
94
  case "json":
96
- if (customSchemas?.[field.name]) {
97
- // Use the user defined custom schema for the field
98
- fieldType = customSchemas[field.name];
99
- } else {
100
- // Parse the field as unknown JSON
101
- fieldType = z.unknown();
102
- }
95
+ // Use the user defined custom schema for the field or fallback to unknown
96
+ fieldType = customSchemas?.[field.name] ?? z.unknown();
103
97
  break;
104
98
  default:
105
99
  // Default to a string
@@ -125,7 +119,11 @@ export function parseSchema(
125
119
  }
126
120
 
127
121
  // Add the field to the fields object
128
- fields[field.name] = fieldType;
122
+ fields[field.name] = fieldType.meta({
123
+ id: field.id,
124
+ title: field.name,
125
+ description: getFieldDescription(field)
126
+ });
129
127
  }
130
128
 
131
129
  return fields;
@@ -150,3 +148,23 @@ function parseSingleOrMultipleValues(
150
148
 
151
149
  return z.array(type);
152
150
  }
151
+
152
+ /**
153
+ * Get the description for a field based on its help text and type.
154
+ */
155
+ function getFieldDescription(field: PocketBaseSchemaEntry): string | undefined {
156
+ switch (true) {
157
+ case !!field.help:
158
+ return field.help;
159
+ case field.type === "autodate" && field.onUpdate:
160
+ return "Date when the entry was last updated. This field is automatically updated by PocketBase whenever the entry is updated.";
161
+ case field.type === "autodate" && field.onCreate:
162
+ return "Date when the entry was created. This field is automatically set by PocketBase when the entry is created.";
163
+ case field.name === "id":
164
+ return "The unique identifier for the entry.";
165
+ case field.hidden:
166
+ return "This field is hidden and may require superuser credentials to access.";
167
+ default:
168
+ return undefined;
169
+ }
170
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "include": ["./**/*"],
4
+ "compilerOptions": {
5
+ "noUncheckedIndexedAccess": true
6
+ }
7
+ }
@@ -9,10 +9,19 @@ export const pocketBaseSchemaEntry = z.object({
9
9
  * Hidden fields are not returned in the API response.
10
10
  */
11
11
  hidden: z.optional(z.boolean()),
12
+ /**
13
+ * Unique identifier for the field.
14
+ */
15
+ id: z.string(),
12
16
  /**
13
17
  * Name of the field.
14
18
  */
15
19
  name: z.string(),
20
+ /**
21
+ * Help text for the field.
22
+ * This is only present if the field has help text defined.
23
+ */
24
+ help: z.optional(z.string()),
16
25
  /**
17
26
  * Type of the field.
18
27
  */
@@ -11,5 +11,5 @@ export function extractFieldNames(
11
11
  return undefined;
12
12
  }
13
13
 
14
- return fields.map((field) => field.split(":")[0]);
14
+ return fields.map((field) => field.split(":").at(0) ?? field);
15
15
  }
@@ -49,7 +49,10 @@ function splitFieldsString(fieldsString: string): Array<string> {
49
49
 
50
50
  const fields: Array<string> = [];
51
51
  for (let i = 0; i < initialSplit.length; i++) {
52
- const part = initialSplit[i];
52
+ const part = initialSplit.at(i);
53
+ if (!part) {
54
+ continue;
55
+ }
53
56
 
54
57
  if (part.includes("(") && !part.includes(")")) {
55
58
  fields.push(`${part},${initialSplit[++i]}`);