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

fix(schema): HookContext is now typed in schema #3306

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/generators/src/service/templates/schema.json.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const authFieldsTemplate = (authStrategies: string[]) =>
const template = ({
camelName,
upperName,
fileName,
relative,
authStrategies,
isEntityService,
Expand All @@ -35,6 +36,7 @@ import type { HookContext } from '${relative}/declarations'
import { dataValidator, queryValidator } from '${relative}/${
fileExists(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
}validators'
import type { ${upperName}Service } from './${fileName}.class'

// Main data model schema
export const ${camelName}Schema = {
Expand All @@ -54,9 +56,9 @@ export const ${camelName}Schema = {
} as const
export type ${upperName} = FromSchema<typeof ${camelName}Schema>
export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
export const ${camelName}Resolver = resolve<${upperName}, HookContext<${upperName}Service>>({})

export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext<${upperName}Service>>({
${localTemplate(
authStrategies,
`// The password should never be visible externally
Expand All @@ -76,7 +78,7 @@ export const ${camelName}DataSchema = {
} as const
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext<${upperName}Service>>({
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
})

Expand All @@ -92,7 +94,7 @@ export const ${camelName}PatchSchema = {
} as const
export type ${upperName}Patch = FromSchema<typeof ${camelName}PatchSchema>
export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({
export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext<${upperName}Service>>({
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
})

Expand All @@ -107,7 +109,7 @@ export const ${camelName}QuerySchema = {
} as const
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext<${upperName}Service>>({
${
isEntityService
? `
Expand Down
12 changes: 7 additions & 5 deletions packages/generators/src/service/templates/schema.typebox.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const authFieldsTemplate = (authStrategies: string[]) =>
const template = ({
camelName,
upperName,
fileName,
relative,
authStrategies,
isEntityService,
Expand All @@ -36,6 +37,7 @@ import type { HookContext } from '${relative}/declarations'
import { dataValidator, queryValidator } from '${relative}/${
fileExists(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
}validators'
import type { ${upperName}Service } from './${fileName}.class'

// Main data model schema
export const ${camelName}Schema = Type.Object({
Expand All @@ -44,9 +46,9 @@ export const ${camelName}Schema = Type.Object({
}, { $id: '${upperName}', additionalProperties: false })
export type ${upperName} = Static<typeof ${camelName}Schema>
export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
export const ${camelName}Resolver = resolve<${upperName}, HookContext<${upperName}Service>>({})

export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext<${upperName}Service>>({
${localTemplate(
authStrategies,
`// The password should never be visible externally
Expand All @@ -66,7 +68,7 @@ export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
})
export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({
export const ${camelName}DataResolver = resolve<${upperName}, HookContext<${upperName}Service>>({
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
})

Expand All @@ -76,7 +78,7 @@ export const ${camelName}PatchSchema = Type.Partial(${camelName}Schema, {
})
export type ${upperName}Patch = Static<typeof ${camelName}PatchSchema>
export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
export const ${camelName}PatchResolver = resolve<${upperName}, HookContext>({
export const ${camelName}PatchResolver = resolve<${upperName}, HookContext<${upperName}Service>>({
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
})

Expand All @@ -95,7 +97,7 @@ export const ${camelName}QuerySchema = Type.Intersect([
], { additionalProperties: false })
export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext<${upperName}Service>>({
${
isEntityService
? `
Expand Down
Loading