sebastianwessel / surrealdb-client-generator

Tool which generates a typescript client for SurrealDB and zod schema of a given database
MIT License
76 stars 12 forks source link

Incorrect handling of boolean value for --generateClient option in the CLI #11

Closed zvictor closed 4 months ago

zvictor commented 5 months ago

Description:

I have encountered an issue with the --generateClient option in surql-gen. I tried passing the values false, 'false', and 0 to the --generateClient option in the CLI, but all of them resulted in the attached error.

I assume that the lib has been tested mostly using config files instead of CLI options, so I assume that the problem must be in the cast from the CLI option (always a string) into a boolean at https://github.com/sebastianwessel/surrealdb-client-generator/blob/64770a16091d74f9495df8112b30a5911aa93ebd/src/config/configFileSchema.ts#L11

Environment:

Steps to reproduce:

  1. Run the following command with different values for the --generateClient option:
    surql-gen --generateClient false
    surql-gen --generateClient 'false'
    surql-gen --generateClient 0

Error:

$ ./node_modules/.bin/surql-gen --generateClient 'false' --ns plugat --db plugat --schemaFile /tmp/plugat.concatenated.surql --outputFolder models/plugat
No config file found.
/node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/types.js:55
                const error = new ZodError_1.ZodError(ctx.common.issues);
                              ^

ZodError: [
  {
    "code": "invalid_type",
    "expected": "boolean",
    "received": "string",
    "path": [
      "generateClient"
    ],
    "message": "Expected boolean, received string"
  }
]
    at get error (/node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/types.js:55:31)
    at ZodObject.parse (/node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/types.js:160:22)
    at main (/node_modules/.pnpm/@sebastianwessel+surql-gen@2.1.0/node_modules/@sebastianwessel/surql-gen/dist/commonjs/index.js:57:59) {
  issues: [
    {
      code: 'invalid_type',
      expected: 'boolean',
      received: 'string',
      path: [ 'generateClient' ],
      message: 'Expected boolean, received string'
    }
  ],
  addIssue: [Function (anonymous)],
  addIssues: [Function (anonymous)],
  errors: [
    {
      code: 'invalid_type',
      expected: 'boolean',
      received: 'string',
      path: [ 'generateClient' ],
      message: 'Expected boolean, received string'
    }
  ]
}

Node.js v22.1.0
file:///node_modules/.pnpm/zx@8.0.2/node_modules/zx/build/core.js:226
            const output = new ProcessOutput(
                           ^

ProcessOutput [Error]: /node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/types.js:55
                const error = new ZodError_1.ZodError(ctx.common.issues);
                              ^

ZodError: [
  {
    "code": "invalid_type",
    "expected": "boolean",
    "received": "string",
    "path": [
      "generateClient"
    ],
    "message": "Expected boolean, received string"
  }
]
    at get error (/node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/types.js:55:31)
    at ZodObject.parse (/node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/types.js:160:22)
    at main (/node_modules/.pnpm/@sebastianwessel+surql-gen@2.1.0/node_modules/@sebastianwessel/surql-gen/dist/commonjs/index.js:57:59) {
  issues: [
    {
      code: 'invalid_type',
      expected: 'boolean',
      received: 'string',
      path: [ 'generateClient' ],
      message: 'Expected boolean, received string'
    }
  ],
  addIssue: [Function (anonymous)],
  addIssues: [Function (anonymous)],
  errors: [
    {
      code: 'invalid_type',
      expected: 'boolean',
      received: 'string',
      path: [ 'generateClient' ],
      message: 'Expected boolean, received string'
    }
  ]
}

Node.js v22.1.0
    at <anonymous> (/surreal/scripts/generate-models.ts:21:9)
    exit code: 1
    at EventEmitter.end (file:///node_modules/.pnpm/zx@8.0.2/node_modules/zx/build/core.js:226:28)
    at EventEmitter.emit (node:events:520:28)
    at EventEmitter.emit (node:domain:488:12)
    at ChildProcess.<anonymous> (/node_modules/.pnpm/zx@8.0.2/node_modules/zx/build/vendor.js:20408:16)
    at ChildProcess.emit (node:events:520:28)
    at ChildProcess.emit (node:domain:488:12)
sebastianwessel commented 5 months ago

yes, that is an issue in the CLI. The transform is missing

sebastianwessel commented 4 months ago

use --no-generateClient flag in cli to disable client generation.

zvictor commented 4 months ago

Thank you!