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 #139

Merged
merged 1 commit into from
Dec 5, 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
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const sharedAjvInstance = getDefaultInstance()

const optsSchemaValidator = sharedAjvInstance.compile(optsSchema)

function loadAndValidateEnvironment (_opts) {
function envSchema (_opts) {
const opts = Object.assign({}, _opts)

if (opts.schema && opts.schema[Symbol.for('fluent-schema-object')]) {
Expand Down Expand Up @@ -114,7 +114,8 @@ function getDefaultInstance () {
})
}

module.exports = loadAndValidateEnvironment
module.exports.default = loadAndValidateEnvironment
module.exports.envSchema = loadAndValidateEnvironment
module.exports.envSchema.keywords = { separator }
envSchema.keywords = { separator }

module.exports = envSchema
module.exports.default = envSchema
module.exports.envSchema = envSchema
48 changes: 26 additions & 22 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@ import Ajv, { KeywordDefinition, JSONSchemaType } from 'ajv';
import { AnySchema } from 'ajv/dist/core';
import { DotenvConfigOptions } from 'dotenv';

export type { JSONSchemaType };
type EnvSchema = typeof envSchema

export type EnvSchemaData = {
[key: string]: unknown;
};
declare namespace envSchema {
export type { JSONSchemaType };

export type EnvSchemaOpt<T = EnvSchemaData> = {
schema?: JSONSchemaType<T> | AnySchema;
data?: [EnvSchemaData, ...EnvSchemaData[]] | EnvSchemaData;
env?: boolean;
dotenv?: boolean | DotenvConfigOptions;
expandEnv?: boolean;
ajv?:
export type EnvSchemaData = {
[key: string]: unknown;
};

export type EnvSchemaOpt<T = EnvSchemaData> = {
schema?: JSONSchemaType<T> | AnySchema;
data?: [EnvSchemaData, ...EnvSchemaData[]] | EnvSchemaData;
env?: boolean;
dotenv?: boolean | DotenvConfigOptions;
expandEnv?: boolean;
ajv?:
| Ajv
| {
customOptions(ajvInstance: Ajv): Ajv;
};
};

declare const loadAndValidateEnvironment: {
<T = EnvSchemaData>(_opts?: EnvSchemaOpt<T>): T;
keywords: {
separator: KeywordDefinition;
customOptions(ajvInstance: Ajv): Ajv;
};
};
};

export default loadAndValidateEnvironment;
export { loadAndValidateEnvironment as envSchema };
export const keywords: {
separator: KeywordDefinition
}

export const envSchema: EnvSchema
export { envSchema as default }
}

declare function envSchema<T = envSchema.EnvSchemaData>(_opts?: envSchema.EnvSchemaOpt<T>): T
export = envSchema
4 changes: 4 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expectError, expectType } from 'tsd';
import envSchema, {
EnvSchemaData,
EnvSchemaOpt,
keywords,
envSchema as envSchemaNamed,
default as envSchemaDefault,
} from '..';
Expand Down Expand Up @@ -109,3 +110,6 @@ expectType<EnvData>(envSchemaWithType);

const envSchemaTypebox = envSchema<SchemaTypebox>({ schema: schemaTypebox });
expectType<SchemaTypebox>(envSchemaTypebox);

expectType<KeywordDefinition>(keywords.separator)
expectType<KeywordDefinition>(envSchema.keywords.separator)