Skip to content

Commit

Permalink
feat: begin v6 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ndianabasi committed Jun 26, 2024
1 parent 53e3160 commit a338e79
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 227 deletions.
8 changes: 4 additions & 4 deletions providers/responsive_attachment_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* file that was distributed with this source code.
*/

import { ApplicationContract } from '@ioc:Adonis/Core/Application'
import type { ApplicationService } from '@adonisjs/core/types'

export default class ResponsiveAttachmentProvider {
constructor(protected application: ApplicationContract) {}
constructor(protected application: ApplicationService) {}

/**
* Extends the validator by defining validation rules
Expand All @@ -19,7 +19,7 @@ export default class ResponsiveAttachmentProvider {
/**
* Do not register validation rules in the "repl" environment
*/
if (this.application.environment === 'repl') {
if (this.application.nodeEnvironment === 'repl') {
return
}

Expand All @@ -33,7 +33,7 @@ export default class ResponsiveAttachmentProvider {
}

public register() {
this.application.container.bind('Adonis/Addons/ResponsiveAttachment', () => {
this.application.container.singleton('adonis-responsive-attachment', () => {
const { ResponsiveAttachment } = require('../src/Attachment')
const { responsiveAttachment } = require('../src/Attachment/decorator')

Expand Down
23 changes: 13 additions & 10 deletions src/bindings/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

import { readFile } from 'fs/promises'
import { Exception } from '@poppinss/utils'
import { LoggerContract } from '@ioc:Adonis/Core/Logger'
import type { Logger } from '@adonisjs/logger'
import { ValidationRuntimeOptions, validator as validatorStatic } from '@ioc:Adonis/Core/Validator'
import { getMetaData } from '../services/image_manipulation_service'
import type { MultipartFileContract } from '@ioc:Adonis/Core/BodyParser'
import type { MultipartFile } from '@adonisjs/bodyparser'

type NormalizedOptions = { validationValue: number }

Expand All @@ -29,7 +29,10 @@ enum ImageDimensionsValidationRule {
* Ensure image is complaint with expected dimensions validations
*/
class ImageDimensionsCheck {
constructor(public ruleName: ImageDimensionsValidationRule, protected logger: LoggerContract) {}
constructor(
public ruleName: ImageDimensionsValidationRule,
protected logger: Logger
) {}

/**
* Compile validation options
Expand All @@ -51,7 +54,7 @@ class ImageDimensionsCheck {
* Validate the file
*/
public async validate(
file: MultipartFileContract,
file: MultipartFile,
{ validationValue }: NormalizedOptions,
{ pointer, errorReporter, arrayExpressionPointer }: ValidationRuntimeOptions
) {
Expand Down Expand Up @@ -122,15 +125,15 @@ function throwCatchallError(error: Error) {
/**
* Extends the validator by adding `unique` and `exists`
*/
export function extendValidator(validator: typeof validatorStatic, logger: LoggerContract) {
export function extendValidator(validator: typeof validatorStatic, logger: Logger) {
const minImageWidthRuleChecker = new ImageDimensionsCheck(
ImageDimensionsValidationRule.minImageWidth,
logger
)

validator.rule<ReturnType<(typeof minImageWidthRuleChecker)['compile']>>(
minImageWidthRuleChecker.ruleName,
async (value: MultipartFileContract, compiledOptions, options) => {
async (value: MultipartFile, compiledOptions, options) => {
try {
await minImageWidthRuleChecker.validate(value, compiledOptions, options)
} catch (error) {
Expand Down Expand Up @@ -163,7 +166,7 @@ export function extendValidator(validator: typeof validatorStatic, logger: Logge

validator.rule<ReturnType<(typeof minImageHeightRuleChecker)['compile']>>(
minImageHeightRuleChecker.ruleName,
async (value: MultipartFileContract, compiledOptions, options) => {
async (value: MultipartFile, compiledOptions, options) => {
try {
await minImageHeightRuleChecker.validate(value, compiledOptions, options)
} catch (error) {
Expand Down Expand Up @@ -196,7 +199,7 @@ export function extendValidator(validator: typeof validatorStatic, logger: Logge

validator.rule<ReturnType<(typeof maxImageWidthRuleChecker)['compile']>>(
maxImageWidthRuleChecker.ruleName,
async (value: MultipartFileContract, compiledOptions, options) => {
async (value: MultipartFile, compiledOptions, options) => {
try {
await maxImageWidthRuleChecker.validate(value, compiledOptions, options)
} catch (error) {
Expand Down Expand Up @@ -229,7 +232,7 @@ export function extendValidator(validator: typeof validatorStatic, logger: Logge

validator.rule<ReturnType<(typeof maxImageHeightRuleChecker)['compile']>>(
maxImageHeightRuleChecker.ruleName,
async (value: MultipartFileContract, compiledOptions, options) => {
async (value: MultipartFile, compiledOptions, options) => {
try {
await maxImageHeightRuleChecker.validate(value, compiledOptions, options)
} catch (error) {
Expand Down Expand Up @@ -262,7 +265,7 @@ export function extendValidator(validator: typeof validatorStatic, logger: Logge

validator.rule<ReturnType<(typeof aspectRatioRuleChecker)['compile']>>(
aspectRatioRuleChecker.ruleName,
async (value: MultipartFileContract, compiledOptions, options) => {
async (value: MultipartFile, compiledOptions, options) => {
try {
await aspectRatioRuleChecker.validate(value, compiledOptions, options)
} catch (error) {
Expand Down
Loading

0 comments on commit a338e79

Please sign in to comment.