diff --git a/packages/generators/src/service/templates/schema.json.tpl.ts b/packages/generators/src/service/templates/schema.json.tpl.ts index 531dfff7cc..1be7633af8 100644 --- a/packages/generators/src/service/templates/schema.json.tpl.ts +++ b/packages/generators/src/service/templates/schema.json.tpl.ts @@ -15,6 +15,7 @@ const authFieldsTemplate = (authStrategies: string[]) => const template = ({ camelName, upperName, + fileName, relative, authStrategies, isEntityService, @@ -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 = { @@ -54,9 +56,9 @@ export const ${camelName}Schema = { } as const export type ${upperName} = FromSchema 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 @@ -76,7 +78,7 @@ export const ${camelName}DataSchema = { } as const export type ${upperName}Data = FromSchema 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' })`)} }) @@ -92,7 +94,7 @@ export const ${camelName}PatchSchema = { } as const export type ${upperName}Patch = FromSchema 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' })`)} }) @@ -107,7 +109,7 @@ export const ${camelName}QuerySchema = { } as const export type ${upperName}Query = FromSchema 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 ? ` diff --git a/packages/generators/src/service/templates/schema.typebox.tpl.ts b/packages/generators/src/service/templates/schema.typebox.tpl.ts index 054e931397..44687b740d 100644 --- a/packages/generators/src/service/templates/schema.typebox.tpl.ts +++ b/packages/generators/src/service/templates/schema.typebox.tpl.ts @@ -15,6 +15,7 @@ const authFieldsTemplate = (authStrategies: string[]) => const template = ({ camelName, upperName, + fileName, relative, authStrategies, isEntityService, @@ -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({ @@ -44,9 +46,9 @@ export const ${camelName}Schema = Type.Object({ }, { $id: '${upperName}', additionalProperties: false }) export type ${upperName} = Static 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 @@ -66,7 +68,7 @@ export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [ }) export type ${upperName}Data = Static 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' })`)} }) @@ -76,7 +78,7 @@ export const ${camelName}PatchSchema = Type.Partial(${camelName}Schema, { }) export type ${upperName}Patch = Static 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' })`)} }) @@ -95,7 +97,7 @@ export const ${camelName}QuerySchema = Type.Intersect([ ], { additionalProperties: false }) export type ${upperName}Query = Static 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 ? `