astro-loader-pocketbase 2.2.0-next.1 → 2.2.0

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/README.md CHANGED
@@ -108,9 +108,9 @@ The loader will also automatically convert the value into a slug to be easily us
108
108
  It's recommended to use e.g. the title of the entry to be easily searchable and readable.
109
109
  **Do not use e.g. rich text fields as ids.**
110
110
 
111
- ### Improved type safety
111
+ ### Improved types
112
112
 
113
- By default PocketBase reports `number` and `boolean` fields as not required.
113
+ By default PocketBase reports `number` and `boolean` fields as not required, even though the API will always return `0` and `false` respectively if no value is set.
114
114
  This means that the loader will add `undefined` to the type of these fields.
115
115
  If you want to enforce that these fields are always present, you can set the `improveTypes` option to `true`.
116
116
 
@@ -123,8 +123,7 @@ const blog = defineCollection({
123
123
  });
124
124
  ```
125
125
 
126
- This will remove `undefined` from the type of these fields and provide default values with `0` and `false` respectively.
127
- PocketBase will also use these default values when creating new entries in the dashboard.
126
+ This will remove `undefined` from the type of these fields and mark them as required.
128
127
 
129
128
  ## Type generation
130
129
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-loader-pocketbase",
3
- "version": "2.2.0-next.1",
3
+ "version": "2.2.0",
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)",
@@ -22,14 +22,14 @@
22
22
  },
23
23
  "devDependencies": {
24
24
  "@eslint/js": "^9.18.0",
25
- "@stylistic/eslint-plugin": "^2.12.1",
26
- "@types/node": "^22.10.5",
27
- "astro": "^5.1.5",
25
+ "@stylistic/eslint-plugin": "^2.13.0",
26
+ "@types/node": "^22.10.7",
27
+ "astro": "^5.1.8",
28
28
  "eslint": "^9.18.0",
29
29
  "globals": "^15.14.0",
30
30
  "husky": "^9.1.7",
31
31
  "typescript": "^5.7.3",
32
- "typescript-eslint": "^8.19.1"
32
+ "typescript-eslint": "^8.21.0"
33
33
  },
34
34
  "keywords": [
35
35
  "astro",
@@ -67,11 +67,10 @@ export interface PocketBaseLoaderOptions {
67
67
  jsonSchemas?: Record<string, z.ZodSchema>;
68
68
  /**
69
69
  * Whether to improve the types of the generated schema.
70
- * This includes providing `0` or `false` as default values for number and boolean fields, respectively.
71
- * With this option enabled, the schema will not generate `undefined` as possible value for number and boolean fields.
70
+ * With this option enabled, the schema will not include `undefined` as possible value for number and boolean fields and mark them as required.
72
71
  *
73
72
  * Why do we need this option?
74
- * PocketBase does use these values as the default values, even though it's not specified in the schema.
73
+ * The PocketBase API does always return at least `0` or `false` as the default values, even though the fields are not marked as required in the schema.
75
74
  */
76
75
  improveTypes?: boolean;
77
76
  }
@@ -25,12 +25,10 @@ export function parseSchema(
25
25
  // Determine the field type and create the corresponding Zod type
26
26
  switch (field.type) {
27
27
  case "number":
28
- // Coerce the value to a number
29
- fieldType = z.coerce.number();
28
+ fieldType = z.number();
30
29
  break;
31
30
  case "bool":
32
- // Coerce the value to a boolean
33
- fieldType = z.coerce.boolean();
31
+ fieldType = z.boolean();
34
32
  break;
35
33
  case "date":
36
34
  case "autodate":
@@ -82,19 +80,6 @@ export function parseSchema(
82
80
  // Improve number and boolean types by providing default values
83
81
  (improveTypes && (field.type === "number" || field.type === "bool"));
84
82
 
85
- if (improveTypes) {
86
- switch (field.type) {
87
- case "number":
88
- // If the field is a number, provide a default value of 0
89
- fieldType = fieldType.default(0);
90
- break;
91
- case "bool":
92
- // If the field is a boolean, provide a default value of false
93
- fieldType = fieldType.default(false);
94
- break;
95
- }
96
- }
97
-
98
83
  // If the field is not required, mark it as optional
99
84
  if (!isRequired) {
100
85
  fieldType = z.preprocess(