Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when object key is a number #63

Open
lousolverson opened this issue Jul 14, 2024 · 1 comment
Open

Error when object key is a number #63

lousolverson opened this issue Jul 14, 2024 · 1 comment

Comments

@lousolverson
Copy link

lousolverson commented Jul 14, 2024

Package version

2.1.0

Describe the bug

I am looking to use the following scheme:

export const days_availablesValidator = vine.compile(
  vine.object({
    day_init : vine.string().regex(/^\d{4}\-\d{2}\-\d{2}$/),
        day_end : vine.string().regex(/^\d{4}\-\d{2}\-\d{2}$/).nullable(),
        days_of_week : vine.object({
            '0' : vine.string(),
            '1' : vine.string(),
            '2' : vine.string(),
            '3' : vine.string(),
            '4' : vine.string(),
            '5' : vine.string(),
            '6' : vine.string()
        })
    })
)

and it produces the following error:

[16:26:58.517] ERROR (13439): Numeric separator can not be used after leading 0.
    request_id: "vy66l4s8pvs5e8qm2ols2llg"
    x-request-id: "vy66l4s8pvs5e8qm2ols2llg"
    err: {
      "type": "SyntaxError",
      "message": "Numeric separator can not be used after leading 0.",
      "stack":
          SyntaxError: Numeric separator can not be used after leading 0.
              at new AsyncFunction (<anonymous>)
              at Compiler.#toAsyncFunction (path/to/my/project/node_modules/@vinejs/compiler/src/compiler/main.ts:119:12)
              at Compiler.compile (path/to/my/project/node_modules/@vinejs/compiler/src/compiler/main.ts:181:33)
              at VineValidator (path/to/my/project/node_modules/@vinejs/vine/src/vine/validator.ts:120:8)
              at Vine.compile (path/to/my/project/node_modules/@vinejs/vine/src/vine/main.ts:67:12)
              at <anonymous> (path/to/my/projectapp/validators/secretariats_controller.ts:49:37)
              at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
              at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:485:26)
              at importDefault (path/to/my/project/node_modules/@poppinss/utils/src/import_default.ts:19:25)
              at Object.handle (path/to/my/project/node_modules/@adonisjs/fold/src/module_importer.ts:157:29)
      "status": 500
    }

Finally if I make the following changes it solves the problem:

export const days_availablesValidator = vine.compile(
    vine.object({
        day_init : vine.string().regex(/^\d{4}\-\d{2}\-\d{2}$/),
        day_end : vine.string().regex(/^\d{4}\-\d{2}\-\d{2}$/).nullable(),
        days_of_week : vine.object({
            'd0' : vine.string(),
            'd1' : vine.string(),
            'd2' : vine.string(),
            'd3' : vine.string(),
            'd4' : vine.string(),
            'd5' : vine.string(),
            'd6' : vine.string()
        })
    })
)

Thanks a lot for any solution

Reproduction repo

No response

@mekto
Copy link

mekto commented Jul 15, 2024

It could be connected to this issue. If the field name contains dashes the schema won't compile.

v.compile(
  v.object({
    'g-recaptcha-response': v.string().optional(),
  })
);

throws

SyntaxError: Missing initializer in const declaration
    at new AsyncFunction (<anonymous>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants