diff --git a/package-lock.json b/package-lock.json index fc1a7be..7949108 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "@commitlint/cli": "^11.0.0", "@commitlint/config-conventional": "^11.0.0", "@map-colonies/eslint-config": "^4.0.0", + "@map-colonies/tsconfig": "^1.0.0", "@types/config": "^3.3.4", "@types/debug": "^4.1.12", "@types/jest": "^29.5.12", @@ -3128,6 +3129,16 @@ "license": "MIT", "peer": true }, + "node_modules/@map-colonies/tsconfig": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@map-colonies/tsconfig/-/tsconfig-1.0.0.tgz", + "integrity": "sha512-POVvNJXvlnw7WxxL69Pz1qutn6EiCoCqYpB0304IwGjvNGMi2UqhTvroA/GruXX9rzkVfGp8IGn4kxO5m0kCcQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/@nicolo-ribaudo/eslint-scope-5-internals": { "version": "5.1.1-v1", "resolved": "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz", diff --git a/package.json b/package.json index 405d150..2c31e0d 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "ts-jest": "^29.1.5", "typescript": "^5.4.5", "prom-client": "^15.0.0", - "jest-extended": "^4.0.2" + "jest-extended": "^4.0.2", + "@map-colonies/tsconfig": "^1.0.0" } } diff --git a/src/env.ts b/src/env.ts index cc53820..0fed720 100644 --- a/src/env.ts +++ b/src/env.ts @@ -53,7 +53,7 @@ function parseSchemaEnv(schema: JSONSchema): EnvMap { debug('going over object properties at path %s', key, path); const subSchema = schema.properties[key]; - if (typeof subSchema !== 'boolean') { + if (typeof subSchema !== 'boolean' && subSchema !== undefined) { iterateOverSchemaObject(subSchema, path === '' ? key : `${path}.${key}`); } } diff --git a/src/index.ts b/src/index.ts index ba7c5cc..7d77add 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ -export { ConfigOptions, ConfigInstance } from './types'; +export type { ConfigOptions, ConfigInstance } from './types'; export { config } from './config'; -export { ConfigErrors, isConfigError, ConfigError } from './errors'; +export { type ConfigErrors, isConfigError, ConfigError } from './errors'; diff --git a/src/options.ts b/src/options.ts index 5b1796c..6ef024d 100644 --- a/src/options.ts +++ b/src/options.ts @@ -38,7 +38,7 @@ export function initializeOptions(options: Partial): BaseOptions { const [errors, validatedOptions] = validate(ajvOptionsValidator, optionsSchema, mergedOptions); if (errors) { - debug('error validating options: %s', errors[0].message); + debug('error validating options: %s', errors[0] !== undefined ? errors[0].message : 'unknown error'); throw createConfigError( 'optionValidationError', 'An error occurred while validating the given options. please check both arguments and environment variables', diff --git a/src/schemas.ts b/src/schemas.ts index fafb65f..ad6024b 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -36,6 +36,10 @@ export async function loadSchema(schema: JSONSchema): ReturnType { const subPath = file.url.split(SCHEMA_DOMAIN)[1]; + if (subPath === undefined) { + throw createConfigError(`schemaNotFoundError`, `Schema url is not valid`, { schemaPath: file.url }); + } + return loadSpecificSchema(subPath); }, }, diff --git a/tsconfig.json b/tsconfig.json index ed338ea..5007944 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,5 @@ { - "compilerOptions": { - "target": "ES2022", - "allowSyntheticDefaultImports": true, - "strict": true, - "module": "NodeNext", - "esModuleInterop": true, - "moduleResolution": "NodeNext", - "resolveJsonModule": true, - "outDir": "dist", - "sourceMap": true, - "declaration": true, - "declarationMap": true, - "noEmit": true, - "strictNullChecks": true - }, + "extends": "@map-colonies/tsconfig/tsconfig-library", "include": ["src"], "exclude": ["dist", "node_modules"] }