Skip to content

Commit

Permalink
don't set schema field until in extractInitializers
Browse files Browse the repository at this point in the history
  • Loading branch information
busma13 committed Apr 10, 2024
1 parent 0b2a499 commit 1f2c8be
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/terafoundation/src/connectors/s3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '@terascope/utils';
import { createS3Client, S3ClientConfig } from '@terascope/file-asset-apis';
import * as i from '../interfaces';
import { Terafoundation } from '@terascope/types';

export default {
create() {
Expand Down Expand Up @@ -64,7 +64,7 @@ export default {
};
},
validate_config(
sysconfig: i.FoundationSysConfig<any>,
sysconfig: Terafoundation.SysConfig<any>,
subconfig: S3ClientConfig,
name: string
): void {
Expand Down
6 changes: 5 additions & 1 deletion packages/terafoundation/src/validate-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ function extractInitializers<S>(
sysconfig: PartialDeep<i.FoundationSysConfig<S>>
): Terafoundation.Initializers {
if (isFunction(fn)) {
return fn(sysconfig);
const result = fn(sysconfig);
if (result.schema) {
return result;
}
return { schema: fn(sysconfig) };
}
if (isPlainObject(fn)) {
return { schema: fn };
Expand Down
11 changes: 2 additions & 9 deletions packages/teraslice/src/lib/config/schemas/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
isInteger
} from '@terascope/utils';
import { cpus } from 'node:os';
import { Initializers } from 'packages/types/dist/src/terafoundation'; // FIXME

const workerCount = cpus().length;

Expand Down Expand Up @@ -323,14 +322,8 @@ export const schema = {
}
};

// This function is used to make cross-field validations if needed
export const validatorFn = () => {};

export function configSchema(): Initializers {
return {
schema: { teraslice: schema },
validatorFn
};
export function configSchema() {
return { teraslice: schema };
}

// TODO: fix this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { config_schema } from '../../../src/lib/config/schemas/system.js';
import('@terascope/job-components');

describe('system_schema', () => {
const schema = config_schema().schema.teraslice;
const schema = config_schema().teraslice;

function checkValidation(config: Record<string, any>) {
try {
Expand Down

0 comments on commit 1f2c8be

Please sign in to comment.