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

fix: Expose config schema #13

Merged
merged 3 commits into from
Feb 28, 2024
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
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type { IAppCache, IAppCacheKeys } from './helpers/cache';
* Export classes and utils
*/
export { FumeServer } from './server';
export { FumeConfigSchema } from './serverConfigSchema';
export { FhirClient } from './helpers/fhirServer';
export const fumeUtils = {
duplicate,
Expand Down
19 changes: 2 additions & 17 deletions src/serverConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,10 @@
* Project name: FUME
*/

import z from 'zod';
import * as dotenv from 'dotenv';
import { IConfig } from './types';
import { FumeConfigSchema } from './serverConfigSchema';

dotenv.config();

export const configSchema = z.object({
SERVER_PORT: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(42420)),
SERVER_STATELESS: z.preprocess((a) => a === 'true', z.boolean().default(false)),
FHIR_SERVER_BASE: z.string().min(1).url().default('http://hapi-fhir.outburn.co.il/fhir'),
FHIR_SERVER_AUTH_TYPE: z.string().default('NONE'),
FHIR_SERVER_UN: z.string().default(''),
FHIR_SERVER_PW: z.string().default(''),
FHIR_SERVER_TIMEOUT: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(30000)),
FHIR_VERSION: z.string().min(1).default('4.0.1'),
SEARCH_BUNDLE_PAGE_SIZE: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(20)),
FHIR_PACKAGES: z.string().default(''),
EXCLUDE_FHIR_PACKAGES: z.string().default('')
});

export const config: IConfig = configSchema.parse(process.env);
export const config: IConfig = FumeConfigSchema.parse(process.env);
export default config;
26 changes: 26 additions & 0 deletions src/serverConfigSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* © Copyright Outburn Ltd. 2022-2023 All Rights Reserved
* Project name: FUME
*/

import { FumeConfigSchema } from './serverConfigSchema';
import { test } from '@jest/globals';

describe('FumeConfigSchema', () => {
test('Check schema defaults', async () => {
const config = FumeConfigSchema.parse({});
expect(config).toStrictEqual({
EXCLUDE_FHIR_PACKAGES: '',
FHIR_PACKAGES: '',
FHIR_SERVER_AUTH_TYPE: 'NONE',
FHIR_SERVER_BASE: 'http://hapi-fhir.outburn.co.il/fhir',
FHIR_SERVER_PW: '',
FHIR_SERVER_TIMEOUT: 30000,
FHIR_SERVER_UN: '',
FHIR_VERSION: '4.0.1',
SEARCH_BUNDLE_PAGE_SIZE: 20,
SERVER_PORT: 42420,
SERVER_STATELESS: false
});
});
});
15 changes: 15 additions & 0 deletions src/serverConfigSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { z } from 'zod';

export const FumeConfigSchema = z.object({
SERVER_PORT: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(42420)),
SERVER_STATELESS: z.preprocess((a) => a === 'true', z.boolean().default(false)),
FHIR_SERVER_BASE: z.string().min(1).url().default('http://hapi-fhir.outburn.co.il/fhir'),
FHIR_SERVER_AUTH_TYPE: z.string().default('NONE'),
FHIR_SERVER_UN: z.string().default(''),
FHIR_SERVER_PW: z.string().default(''),
FHIR_SERVER_TIMEOUT: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(30000)),
FHIR_VERSION: z.string().min(1).default('4.0.1'),
SEARCH_BUNDLE_PAGE_SIZE: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(20)),
FHIR_PACKAGES: z.string().default(''),
EXCLUDE_FHIR_PACKAGES: z.string().default('')
});