Closed tvld closed 1 year ago
When in the schema file, I replace :
// _id: ObjectIdSchema(), // this causes the error
_id: Type.Number(), // >> this works
Weird, as all my other services use _id: ObjectIdSchema(),
happily
I was going to say that it needs the objectid
keyword (https://feathersjs.com/api/databases/mongodb.html#ajv-keyword) in the validators
file but it looks like that is already in there?
In validators I have:
const formats: FormatsPluginOptions = [
'date-time',
'time',
'date',
'email',
'hostname',
'ipv4',
'ipv6',
'uri',
'uri-reference',
'uuid',
'uri-template',
'json-pointer',
'relative-json-pointer',
'regex'
]
I can not add 'objectid' to that array as TS complains: Type '"objectid"' is not assignable to type 'FormatName'
Plus, in that case why would all my other _id: ObjectIdSchema() work nicely?
My whole project gives zero hits on searching for objectid
, all lowercase.
Do you have this code in your validators file?
import { keywordObjectId } from '@feathersjs/mongodb'
const validator = new Ajv()
validator.addKeyword(keywordObjectId)
That code should prevent the error message you're seeing.
// validator.ts is now:
import { keywordObjectId } from '@feathersjs/mongodb'
// For more information about this file see https://dove.feathersjs.com/guides/cli/validators.html
import { Ajv, addFormats } from '@feathersjs/schema'
import type { FormatsPluginOptions } from '@feathersjs/schema'
const formats: FormatsPluginOptions = [
'date-time',
'time',
'date',
'email',
'hostname',
'ipv4',
'ipv6',
'uri',
'uri-reference',
'uuid',
'uri-template',
'json-pointer',
'relative-json-pointer',
'regex'
]
export const dataValidator: Ajv = addFormats(new Ajv({}), formats)
export const queryValidator: Ajv = addFormats(
new Ajv({
coerceTypes: true
}),
formats
)
dataValidator.addKeyword(keywordObjectId)
queryValidator.addKeyword(keywordObjectId)
I checked in .git and I never touched that file myself
It's very weird. I compared an existing service line-by-line to the new one, and they are practically the same. Starting to get worried something strange is left over from my whole v33-34-35-37 journey...Also considering the 12-second time before the server is running...Could there be multiple ajv's or whatever busy? ... Guessing now )
It does seem like something (possibly simple) is off but it's hard to tell without being able to have a look. If the app isn't that big, a 12 second startup time also seems pretty long.
I would be really happy if you could look at the whole repo, but it's in GitLab. I could add you by email... There are 5 services total now, including the new 'invites'..).
Oops... going to close this... I had two files: ../valdiator.ts
and ../schemas/validator.ts
And only one got the right keyword registration This is an inheritance from v35 ...
Server is humming fine, (latest v5.0.0) but generating any new service fails:
Gives when
npm run dev
:I do not use the word "objectid" in my code... I will ask around on Discord, but it seems some kind of bug for sure...