1 Commits
v0.6.0 ... main

Author SHA1 Message Date
dc0ba32801 modernise file field type. 2025-10-22 16:49:00 +02:00
5 changed files with 21 additions and 41 deletions

View File

@@ -16,6 +16,7 @@ This repository is a continuation of [Gregory Bouteiller's zod-pocketbase](https
## Changes from Original ## Changes from Original
### Project Structure ### Project Structure
- Added `flake.nix` for **NixOS** development environment.
- Removed `doc/`, `playground/` and monorepo configuration - Removed `doc/`, `playground/` and monorepo configuration
- Replaced `pnpm` and `node` in favor of `bun` - Replaced `pnpm` and `node` in favor of `bun`
- Switched `.github/` to `.gitea/` and `gh` to `tea` - Switched `.github/` to `.gitea/` and `gh` to `tea`

View File

@@ -17,7 +17,6 @@
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
bun = pkgs.bun; bun = pkgs.bun;
in in
{ {
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
@@ -26,7 +25,6 @@
git git
nodejs_24 nodejs_24
tea tea
# nodePackages.node-inspector
]; ];
shellHook = '' shellHook = ''
@@ -36,9 +34,13 @@
echo "" echo ""
echo "Available commands:" echo "Available commands:"
echo " bun install - Install dependencies" echo " bun install - Install dependencies"
echo " bun run dev - Start development" echo " bun run dev - Start development (build with --watch flag)"
echo " bun build - Build with Bun's bundler" echo " bun run build - Build library"
echo " tea releases create - Create Gitea release" echo " bun run lint - Run Biome check"
echo " bun run lint:w - Run Biome check (with --write)"
echo " bun run format - Run Biome format"
echo " bun run format:w - Run Biome format (with --write)"
echo " bun run release - Run release script"
echo "" echo ""
if [ ! -d "node_modules" ]; then if [ ! -d "node_modules" ]; then
@@ -50,25 +52,6 @@
NODE_ENV = "development"; NODE_ENV = "development";
BUN_RUNTIME = "bun"; BUN_RUNTIME = "bun";
}; };
packages.default = pkgs.stdenv.mkDerivation {
name = "zod-pocketbase-continue";
src = ./.;
buildInputs = [ bun ];
buildPhase = ''
export HOME=$TMPDIR
bun install --frozen-lockfile
bun run build
'';
installPhase = ''
mkdir -p $out
cp -r dist $out/
cp package.json $out/
'';
};
} }
); );
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "zod-pocketbase-continue", "name": "zod-pocketbase-continue",
"version": "0.6.0", "version": "0.6.1",
"description": "Zod tooling for your PocketBase instance.", "description": "Zod tooling for your PocketBase instance.",
"author": { "author": {
"email": "garandplg@garandplg.com", "email": "garandplg@garandplg.com",

View File

@@ -89,15 +89,11 @@ export function stringifyContent(collections: CollectionModel[], opts: GenerateO
const fileFieldMaxSelect = maxSelectFile ? `.max(${maxSelectFile})` : '' const fileFieldMaxSelect = maxSelectFile ? `.max(${maxSelectFile})` : ''
const fileFieldTypeArray = maxSelectFile === 1 ? '' : `.array()${fileFieldMaxSelect}` const fileFieldTypeArray = maxSelectFile === 1 ? '' : `.array()${fileFieldMaxSelect}`
let fileValidation = 'z.instanceof(File)' const fileMaxSizeFile = maxSizeFile ? `.max(${maxSizeFile})` : ''
const fileMimeTypesArray =
mimeTypesArray.length > 0 ? `.mime(${JSON.stringify(mimeTypesArray)})` : ''
if (maxSizeFile) const baseFileSchema = `z.union([z.string(), z.file()${fileMaxSizeFile}${fileMimeTypesArray}])`
fileValidation += `.refine((file) => file.size <= ${maxSizeFile}, { message: "File size too large" })`
if (mimeTypesArray.length > 0)
fileValidation += `.refine((file) => ${JSON.stringify(mimeTypesArray)}.includes(file.type), { message: "Invalid file type" })`
const baseFileSchema = `z.union([z.string(), ${fileValidation}])`
schema = `${baseFileSchema}${fileFieldTypeArray}` schema = `${baseFileSchema}${fileFieldTypeArray}`
break break
} }

View File

@@ -94,8 +94,8 @@ function fieldsFromRec<S>(schema: S, prefix = '') {
function hasObjectSchemaDescendant(value: unknown): value is any { function hasObjectSchemaDescendant(value: unknown): value is any {
// Handle ZodPipe // Handle ZodPipe
if (value && typeof value === 'object' && 'constructor' in value) { if (value && typeof value === 'object' && 'constructor' in value) {
const constructor = (value as any).constructor const valueConstructor = value.constructor
if (constructor?.name === 'ZodPipe') { if (valueConstructor?.name === 'ZodPipe') {
const inputSchema = (value as any)._def?.in const inputSchema = (value as any)._def?.in
if (inputSchema) return hasObjectSchemaDescendant(inputSchema) if (inputSchema) return hasObjectSchemaDescendant(inputSchema)
} }
@@ -103,8 +103,8 @@ function hasObjectSchemaDescendant(value: unknown): value is any {
// Handle ZodTransform // Handle ZodTransform
if (value && typeof value === 'object' && 'constructor' in value) { if (value && typeof value === 'object' && 'constructor' in value) {
const constructor = (value as any).constructor const valueConstructor = value.constructor
if (constructor?.name === 'ZodTransform') { if (valueConstructor?.name === 'ZodTransform') {
const innerSchema = const innerSchema =
(value as any)._def?.input || (value as any)._def?.schema || (value as any).sourceType (value as any)._def?.input || (value as any)._def?.schema || (value as any).sourceType
if (innerSchema) return hasObjectSchemaDescendant(innerSchema) if (innerSchema) return hasObjectSchemaDescendant(innerSchema)
@@ -123,8 +123,8 @@ function hasObjectSchemaDescendant(value: unknown): value is any {
function getObjectSchemaDescendant<S>(schema: S): ZodObject | undefined { function getObjectSchemaDescendant<S>(schema: S): ZodObject | undefined {
// Handle ZodPipe // Handle ZodPipe
if (schema && typeof schema === 'object' && 'constructor' in schema) { if (schema && typeof schema === 'object' && 'constructor' in schema) {
const constructor = (schema as any).constructor const schemaConstructor = schema.constructor
if (constructor?.name === 'ZodPipe') { if (schemaConstructor?.name === 'ZodPipe') {
const inputSchema = (schema as any)._def?.in const inputSchema = (schema as any)._def?.in
if (inputSchema) return getObjectSchemaDescendant(inputSchema) if (inputSchema) return getObjectSchemaDescendant(inputSchema)
} }
@@ -132,8 +132,8 @@ function getObjectSchemaDescendant<S>(schema: S): ZodObject | undefined {
// Handle ZodTransform // Handle ZodTransform
if (schema && typeof schema === 'object' && 'constructor' in schema) { if (schema && typeof schema === 'object' && 'constructor' in schema) {
const constructor = (schema as any).constructor const schemaConstructor = schema.constructor
if (constructor?.name === 'ZodTransform') { if (schemaConstructor?.name === 'ZodTransform') {
const innerSchema = const innerSchema =
(schema as any)._def?.input || (schema as any)._def?.schema || (schema as any).sourceType (schema as any)._def?.input || (schema as any)._def?.schema || (schema as any).sourceType
if (innerSchema) return getObjectSchemaDescendant(innerSchema) if (innerSchema) return getObjectSchemaDescendant(innerSchema)