Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
busma13 committed Apr 11, 2024
1 parent 1f2c8be commit bacd4e9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
4 changes: 3 additions & 1 deletion packages/terafoundation/src/connector-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export function getConnectorModule(name: string, reason: string): any {
return null;
}

export function getConnectorInitializers(name: string): Terafoundation.Initializers {
export function getConnectorInitializers<S>(
name: string
): Terafoundation.Initializers<S> {
const reason = `Could not retrieve schema code for: ${name}\n`;

const mod = getConnectorModule(name, reason);
Expand Down
12 changes: 6 additions & 6 deletions packages/terafoundation/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import convict from 'convict';
import { cpus } from 'os';
import { PartialDeep, Terafoundation } from '@terascope/types';
import { Terafoundation } from '@terascope/types';

const workerCount = cpus().length;
const DEFAULT_ASSET_STORAGE_CONNECTION_TYPE = 'elasticsearch-next';

export function getFoundationInitializers(): Terafoundation.Initializers {
const schema: convict.Schema<any> = {
export function getFoundationInitializers<S>(): Terafoundation.Initializers<S> {
const schema: convict.Schema<Record<string, any>> = {
environment: {
doc: 'If set to `production`, console logging will be disabled and logs will be sent to a file',
default: 'development',
Expand Down Expand Up @@ -88,10 +88,10 @@ export function getFoundationInitializers(): Terafoundation.Initializers {
}
};

function validate_config(sysconfig: Terafoundation.SysConfig<any>,
subconfig: PartialDeep<Terafoundation.SysConfig<any>>
function validate_config(_sysconfig: Terafoundation.SysConfig<S>,
subconfig: Record<string, any>
): void {
const typedSubconfig = subconfig as unknown as Terafoundation.Foundation;
const typedSubconfig = subconfig as Terafoundation.Foundation;
const connectionType = typedSubconfig.asset_storage_connection_type
|| DEFAULT_ASSET_STORAGE_CONNECTION_TYPE;
const connectionTypesPresent = Object.keys(typedSubconfig.connectors);
Expand Down
10 changes: 5 additions & 5 deletions packages/terafoundation/src/validate-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function validateConfig(
function extractInitializers<S>(
fn: any,
sysconfig: PartialDeep<i.FoundationSysConfig<S>>
): Terafoundation.Initializers {
): Terafoundation.Initializers<S> {
if (isFunction(fn)) {
const result = fn(sysconfig);
if (result.schema) {
Expand Down Expand Up @@ -81,16 +81,16 @@ export default function validateConfigs<
throw new Error('Terafoundation requires a valid system configuration');
}

const listOfValidations: Record<string, Terafoundation.ValidationObj> = {};
const listOfValidations: Record<string, Terafoundation.ValidationObj<S>> = {};
const {
schema: sysconfigSchema,
validatorFn: terasliceValidatorFn
} = extractInitializers(config.config_schema, sysconfig);
} = extractInitializers<S>(config.config_schema, sysconfig);
listOfValidations.teraslice = { validatorFn: terasliceValidatorFn, subconfig: {} };
const {
schema: foundationSchema,
validatorFn: foundationValidatorFn
} = getFoundationInitializers();
} = getFoundationInitializers<S>();
listOfValidations.terafoundation = { validatorFn: foundationValidatorFn, subconfig: {} };
sysconfigSchema.terafoundation = foundationSchema;

Expand Down Expand Up @@ -126,7 +126,7 @@ export default function validateConfigs<
const {
schema: connSchema,
validatorFn: connValidatorFn
} = getConnectorInitializers(connector);
} = getConnectorInitializers<S>(connector);

result[schemaKey].connectors[connector] = {};
for (const [connection, connectionConfig] of Object.entries(connectorConfig)) {
Expand Down
24 changes: 12 additions & 12 deletions packages/types/src/terafoundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Cluster as NodeJSCluster,
Worker as NodeJSWorker
} from 'node:cluster';
import type { Overwrite, PartialDeep } from './utility';
import type { Overwrite } from './utility';
import type { Logger } from './logger';

interface Format {
Expand All @@ -27,22 +27,22 @@ export type Schema<T> = {
[P in keyof T]: Schema<T[P]> | SchemaObj<T[P]>;
};

export type Initializers = {
schema: Schema<any>,
validatorFn?: ValidatorFn
export type Initializers<S> = {
schema: Schema<Record<string, any>>
validatorFn?: ValidatorFn<S>
}

export type ValidatorFn = (
sysconfig: SysConfig<any>,
subConfig: PartialDeep<SysConfig<any>>,
export type ValidationObj<S>= {
subconfig: Record<string, any>,
validatorFn?: ValidatorFn<S>
}

export type ValidatorFn<S> = (
sysconfig: SysConfig<S>,
subconfig: Record<string, any>,
name: string
) => void

export type ValidationObj= {
validatorFn: ValidatorFn | undefined,
subconfig: PartialDeep<SysConfig<any>>
}

export type Config<
S = Record<string, any>,
A = Record<string, any>,
Expand Down

0 comments on commit bacd4e9

Please sign in to comment.