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

nodenext compatibility #158

Merged
merged 2 commits into from
Dec 3, 2022
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
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fp = require('fastify-plugin')
const envSchema = require('env-schema')

function loadAndValidateEnvironment (fastify, opts, done) {
function fastifyEnv (fastify, opts, done) {
try {
const config = envSchema(opts)
const confKey = opts.confKey || 'config'
Expand All @@ -14,7 +14,9 @@ function loadAndValidateEnvironment (fastify, opts, done) {
}
}

module.exports = fp(loadAndValidateEnvironment, {
module.exports = fp(fastifyEnv, {
fastify: '4.x',
name: '@fastify/env'
})
module.exports.default = fastifyEnv
module.exports.fastifyEnv = fastifyEnv
30 changes: 0 additions & 30 deletions test/types/types.test.ts

This file was deleted.

25 changes: 20 additions & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { EnvSchemaOpt } from "env-schema";
import { FastifyPluginCallback } from "fastify";
import { EnvSchemaOpt } from "env-schema"
import { FastifyPluginCallback } from "fastify"

export type fastifyEnvOpt = EnvSchemaOpt & { confKey?: string };
type FastifyEnv = FastifyPluginCallback<fastifyEnv.FastifyEnvOptions>

declare namespace fastifyEnv {
export interface FastifyEnvOptions extends EnvSchemaOpt {
confKey?: string
}

/**
* @deprecated Use FastifyEnvOptions instead
*/
export type fastifyEnvOpt = FastifyEnvOptions

export const fastifyEnv: FastifyEnv
export { fastifyEnv as default }
}

declare function fastifyEnv(...params: Parameters<FastifyEnv>): ReturnType<FastifyEnv>
export = fastifyEnv

export const fastifyEnv: FastifyPluginCallback<fastifyEnvOpt>;
export default fastifyEnv;
36 changes: 32 additions & 4 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
import fastify from 'fastify';
import fastifyEnv from '..';
import Fastify from 'fastify'
import { expectDeprecated, expectType } from 'tsd'
import fastifyEnv, { FastifyEnvOptions, fastifyEnvOpt } from '..'

const server = fastify();
const fastify = Fastify()

server.register(fastifyEnv, { confKey: 'test' });
fastify.register(fastifyEnv, { confKey: 'test' })

fastify.register(fastifyEnv)
fastify.register(fastifyEnv, {})
fastify.register(fastifyEnv, {
schema: {},
})
fastify.register(fastifyEnv, {
data: {},
})
fastify.register(fastifyEnv, {
data: [{}],
})
fastify.register(fastifyEnv, {
env: true,
})
fastify.register(fastifyEnv, {
dotenv: true,
})
fastify.register(fastifyEnv, {
dotenv: {},
})
fastify.register(fastifyEnv, {
confKey: 'config'
})

expectDeprecated({} as fastifyEnvOpt)
expectType<FastifyEnvOptions>({} as fastifyEnvOpt)