Skip to content

Commit

Permalink
revert keychanges
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Malcolm-Fischer committed Jan 13, 2025
1 parent ed06844 commit d7da32c
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions packages/config-dug/src/config-dug.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import EventEmitter from 'events';
import createDebug from 'debug';
import { z } from 'zod';
import * as changeKeys from './lib/change-case-keys';

import { getOptions, ConfigDugOptions, ConfigDugOptionsWithDefaults } from './lib/options.js';
import { recordOrigin, recordOriginDefaults, mergeOrigins } from './lib/origins.js';
import { ConfigDugOptions, ConfigDugOptionsWithDefaults, getOptions } from './lib/options.js';
import { mergeOrigins, recordOrigin, recordOriginDefaults } from './lib/origins.js';
import { logger } from './lib/logger.js';
import { ConfigDugError } from './lib/errors.js';
import { loadConfigFile } from './lib/config-file.js';
Expand Down Expand Up @@ -191,7 +192,7 @@ class ConfigDug<T extends ConfigDugSchema> extends EventEmitter {
const keyCorrectedValues = changeKeys[this.options.keyStyle](values);

if (resolvedFilename) {
this.valueOrigins = recordOrigin(this.valueOrigins, values, resolvedFilename);
this.valueOrigins = recordOrigin(this.valueOrigins, keyCorrectedValues, resolvedFilename);
}

return keyCorrectedValues;
Expand Down Expand Up @@ -227,43 +228,38 @@ class ConfigDug<T extends ConfigDugSchema> extends EventEmitter {
}

const values = loadEnvironment(keys);

this.valueOrigins = recordOrigin(this.valueOrigins, values, 'environment');

return values;
}

private async initializePlugins(environmentVariables: UntypedConfig): Promise<void> {
debug('initialize plugins');

for (const plugin of this.options.plugins) {
if (typeof plugin.initialize === 'function') {
await plugin.initialize(this.options, environmentVariables);
}
}
}

private async loadPlugins(initialValues: UntypedConfig): Promise<UntypedConfig> {
let values: UntypedConfig = { ...initialValues };
private async loadPlugins(values: UntypedConfig): Promise<UntypedConfig> {
let nextPluginReloadIn: number | undefined;

for (const plugin of this.options.plugins) {
if (!plugin.isInitialized()) {

Check failure on line 240 in packages/config-dug/src/config-dug.ts

View workflow job for this annotation

GitHub Actions / build (18)

packages/plugin-config-cat/test/config-cat-plugin.test.ts > configCatPlugin > should load config

ZodError: [ { "code": "invalid_return_type", "returnTypeError": { "issues": [ { "code": "invalid_type", "expected": "boolean", "received": "undefined", "path": [], "message": "Required" } ], "name": "ZodError" }, "path": [ "plugins", 0, "isInitialized" ], "message": "Invalid function return type" } ] ❯ Object.<anonymous> node_modules/zod/lib/index.mjs:3374:27 ❯ Object.isInitialized node_modules/zod/lib/index.mjs:3371:40 ❯ ConfigDug.loadPlugins packages/config-dug/src/config-dug.ts:240:19 ❯ ConfigDug.loadConfig packages/config-dug/src/config-dug.ts:160:22 ❯ ConfigDug.load packages/config-dug/src/config-dug.ts:134:5 ❯ packages/plugin-config-cat/test/config-cat-plugin.test.ts:91:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { issues: [ { code: 'invalid_return_type', returnTypeError: { stack: 'ZodError: [\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]\n at Object.get error [as error] (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:587:31)\n at Object.<anonymous> (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3374:80)\n at Object.isInitialized (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3371:40)\n at ConfigDug.loadPlugins (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:240:19)\n at ConfigDug.loadConfig (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:160:22)\n at ConfigDug.load (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:134:5)\n at /home/runner/work/config-dug/config-dug/packages/plugin-config-cat/test/config-cat-plugin.test.ts:91:5\n at file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:533:5\n at runTest (file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:1056:11)\n at runSuite (file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:1205:15)', issues: [ { code: 'invalid_type', expected: 'boolean', received: 'undefined', path: [], message: 'Required' } ], addIssue: 'Function<anonymous>', addIssues: 'Function<anonymous>', name: 'ZodError', constructor: 'Function<ZodError>', errors: [ { code: 'invalid_type', expected: 'boolean', received: 'undefined', path: [], message: 'Required' } ], format: 'Function<format>', toString: 'Function<toString>', message: '[\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]', isEmpty: false, flatten: 'Function<flatten>', formErrors: { formErrors: [ 'Required' ], fieldErrors: {} } }, path: [ 'plugins', +0, 'isInitialized' ], message: 'Invalid function return type' } ], addIssue: 'Function<anonymous>', addIssues: 'Function<anonymous>', errors: [ { code: 'invalid_return_type', returnTypeError: { stack: 'ZodError: [\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]\n at Object.get error [as error] (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:587:31)\n at Object.<anonymous> (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3374:80)\n at Object.isInitialized (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3371:40)\n at ConfigDug.loadPlugins (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:240:19)\n at ConfigDug.loadConfig (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:160:22)\n at ConfigDug.load (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:134:5)\n at /home/runner/work/config-dug/config-dug/packages/plugin-config-cat/test/config-cat-plugin.test.ts

Check failure on line 240 in packages/config-dug/src/config-dug.ts

View workflow job for this annotation

GitHub Actions / build (18)

packages/plugin-config-cat/test/config-cat-plugin.test.ts > configCatPlugin > should properly overwrite targeted flag functions

ZodError: [ { "code": "invalid_return_type", "returnTypeError": { "issues": [ { "code": "invalid_type", "expected": "boolean", "received": "undefined", "path": [], "message": "Required" } ], "name": "ZodError" }, "path": [ "plugins", 0, "isInitialized" ], "message": "Invalid function return type" } ] ❯ Object.<anonymous> node_modules/zod/lib/index.mjs:3374:27 ❯ Object.isInitialized node_modules/zod/lib/index.mjs:3371:40 ❯ ConfigDug.loadPlugins packages/config-dug/src/config-dug.ts:240:19 ❯ ConfigDug.loadConfig packages/config-dug/src/config-dug.ts:160:22 ❯ ConfigDug.load packages/config-dug/src/config-dug.ts:134:5 ❯ packages/plugin-config-cat/test/config-cat-plugin.test.ts:150:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { issues: [ { code: 'invalid_return_type', returnTypeError: { stack: 'ZodError: [\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]\n at Object.get error [as error] (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:587:31)\n at Object.<anonymous> (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3374:80)\n at Object.isInitialized (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3371:40)\n at ConfigDug.loadPlugins (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:240:19)\n at ConfigDug.loadConfig (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:160:22)\n at ConfigDug.load (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:134:5)\n at /home/runner/work/config-dug/config-dug/packages/plugin-config-cat/test/config-cat-plugin.test.ts:150:5\n at file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:533:5\n at runTest (file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:1056:11)\n at runSuite (file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:1205:15)', issues: [ { code: 'invalid_type', expected: 'boolean', received: 'undefined', path: [], message: 'Required' } ], addIssue: 'Function<anonymous>', addIssues: 'Function<anonymous>', name: 'ZodError', constructor: 'Function<ZodError>', errors: [ { code: 'invalid_type', expected: 'boolean', received: 'undefined', path: [], message: 'Required' } ], format: 'Function<format>', toString: 'Function<toString>', message: '[\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]', isEmpty: false, flatten: 'Function<flatten>', formErrors: { formErrors: [ 'Required' ], fieldErrors: {} } }, path: [ 'plugins', +0, 'isInitialized' ], message: 'Invalid function return type' } ], addIssue: 'Function<anonymous>', addIssues: 'Function<anonymous>', errors: [ { code: 'invalid_return_type', returnTypeError: { stack: 'ZodError: [\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]\n at Object.get error [as error] (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:587:31)\n at Object.<anonymous> (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3374:80)\n at Object.isInitialized (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3371:40)\n at ConfigDug.loadPlugins (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:240:19)\n at ConfigDug.loadConfig (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:160:22)\n at ConfigDug.load (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:134:5)\n at /home/runner/work/config-dug/config-dug/packages/plugin-config-cat/test/config-cat-plugin.test.

Check failure on line 240 in packages/config-dug/src/config-dug.ts

View workflow job for this annotation

GitHub Actions / build (20)

packages/plugin-config-cat/test/config-cat-plugin.test.ts > configCatPlugin > should load config

ZodError: [ { "code": "invalid_return_type", "returnTypeError": { "issues": [ { "code": "invalid_type", "expected": "boolean", "received": "undefined", "path": [], "message": "Required" } ], "name": "ZodError" }, "path": [ "plugins", 0, "isInitialized" ], "message": "Invalid function return type" } ] ❯ Object.<anonymous> node_modules/zod/lib/index.mjs:3374:27 ❯ Object.isInitialized node_modules/zod/lib/index.mjs:3371:40 ❯ ConfigDug.loadPlugins packages/config-dug/src/config-dug.ts:240:19 ❯ ConfigDug.loadConfig packages/config-dug/src/config-dug.ts:160:22 ❯ ConfigDug.load packages/config-dug/src/config-dug.ts:134:5 ❯ packages/plugin-config-cat/test/config-cat-plugin.test.ts:91:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { issues: [ { code: 'invalid_return_type', returnTypeError: { stack: 'ZodError: [\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]\n at Object.get error [as error] (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:587:31)\n at Object.<anonymous> (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3374:80)\n at Object.isInitialized (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3371:40)\n at ConfigDug.loadPlugins (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:240:19)\n at ConfigDug.loadConfig (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:160:22)\n at ConfigDug.load (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:134:5)\n at /home/runner/work/config-dug/config-dug/packages/plugin-config-cat/test/config-cat-plugin.test.ts:91:5\n at file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:533:5\n at runTest (file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:1056:11)\n at runSuite (file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:1205:15)', issues: [ { code: 'invalid_type', expected: 'boolean', received: 'undefined', path: [], message: 'Required' } ], addIssue: 'Function<anonymous>', addIssues: 'Function<anonymous>', name: 'ZodError', constructor: 'Function<ZodError>', errors: [ { code: 'invalid_type', expected: 'boolean', received: 'undefined', path: [], message: 'Required' } ], format: 'Function<format>', toString: 'Function<toString>', message: '[\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]', isEmpty: false, flatten: 'Function<flatten>', formErrors: { formErrors: [ 'Required' ], fieldErrors: {} } }, path: [ 'plugins', +0, 'isInitialized' ], message: 'Invalid function return type' } ], addIssue: 'Function<anonymous>', addIssues: 'Function<anonymous>', errors: [ { code: 'invalid_return_type', returnTypeError: { stack: 'ZodError: [\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]\n at Object.get error [as error] (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:587:31)\n at Object.<anonymous> (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3374:80)\n at Object.isInitialized (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3371:40)\n at ConfigDug.loadPlugins (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:240:19)\n at ConfigDug.loadConfig (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:160:22)\n at ConfigDug.load (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:134:5)\n at /home/runner/work/config-dug/config-dug/packages/plugin-config-cat/test/config-cat-plugin.test.ts

Check failure on line 240 in packages/config-dug/src/config-dug.ts

View workflow job for this annotation

GitHub Actions / build (20)

packages/plugin-config-cat/test/config-cat-plugin.test.ts > configCatPlugin > should properly overwrite targeted flag functions

ZodError: [ { "code": "invalid_return_type", "returnTypeError": { "issues": [ { "code": "invalid_type", "expected": "boolean", "received": "undefined", "path": [], "message": "Required" } ], "name": "ZodError" }, "path": [ "plugins", 0, "isInitialized" ], "message": "Invalid function return type" } ] ❯ Object.<anonymous> node_modules/zod/lib/index.mjs:3374:27 ❯ Object.isInitialized node_modules/zod/lib/index.mjs:3371:40 ❯ ConfigDug.loadPlugins packages/config-dug/src/config-dug.ts:240:19 ❯ ConfigDug.loadConfig packages/config-dug/src/config-dug.ts:160:22 ❯ ConfigDug.load packages/config-dug/src/config-dug.ts:134:5 ❯ packages/plugin-config-cat/test/config-cat-plugin.test.ts:150:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { issues: [ { code: 'invalid_return_type', returnTypeError: { stack: 'ZodError: [\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]\n at Object.get error [as error] (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:587:31)\n at Object.<anonymous> (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3374:80)\n at Object.isInitialized (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3371:40)\n at ConfigDug.loadPlugins (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:240:19)\n at ConfigDug.loadConfig (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:160:22)\n at ConfigDug.load (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:134:5)\n at /home/runner/work/config-dug/config-dug/packages/plugin-config-cat/test/config-cat-plugin.test.ts:150:5\n at file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:533:5\n at runTest (file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:1056:11)\n at runSuite (file:///home/runner/work/config-dug/config-dug/node_modules/@vitest/runner/dist/index.js:1205:15)', issues: [ { code: 'invalid_type', expected: 'boolean', received: 'undefined', path: [], message: 'Required' } ], addIssue: 'Function<anonymous>', addIssues: 'Function<anonymous>', name: 'ZodError', constructor: 'Function<ZodError>', errors: [ { code: 'invalid_type', expected: 'boolean', received: 'undefined', path: [], message: 'Required' } ], format: 'Function<format>', toString: 'Function<toString>', message: '[\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]', isEmpty: false, flatten: 'Function<flatten>', formErrors: { formErrors: [ 'Required' ], fieldErrors: {} } }, path: [ 'plugins', +0, 'isInitialized' ], message: 'Invalid function return type' } ], addIssue: 'Function<anonymous>', addIssues: 'Function<anonymous>', errors: [ { code: 'invalid_return_type', returnTypeError: { stack: 'ZodError: [\n {\n "code": "invalid_type",\n "expected": "boolean",\n "received": "undefined",\n "path": [],\n "message": "Required"\n }\n]\n at Object.get error [as error] (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:587:31)\n at Object.<anonymous> (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3374:80)\n at Object.isInitialized (file:///home/runner/work/config-dug/config-dug/node_modules/zod/lib/index.mjs:3371:40)\n at ConfigDug.loadPlugins (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:240:19)\n at ConfigDug.loadConfig (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:160:22)\n at ConfigDug.load (/home/runner/work/config-dug/config-dug/packages/config-dug/src/config-dug.ts:134:5)\n at /home/runner/work/config-dug/config-dug/packages/plugin-config-cat/test/config-cat-plugin.test.
plugin.initialize(this.options, values);
await plugin.initialize(this.options, values);
}

const pluginReturnValue: ConfigDugPluginOutput = await plugin.load();

values = { ...values, ...pluginReturnValue.values };

const keyCorrectedValues = changeKeys[this.options.keyStyle](pluginReturnValue.values);
values = { ...values, ...keyCorrectedValues };
this.valueOrigins = mergeOrigins(this.valueOrigins, pluginReturnValue.valueOrigins);

if (pluginReturnValue.nextReloadIn) {
this.reloadTimeout = setTimeout(async () => {
await this.reload();
}, pluginReturnValue.nextReloadIn);
// We will reload in time for the nearest plugin reload
nextPluginReloadIn = nextPluginReloadIn
? Math.min(nextPluginReloadIn, pluginReturnValue.nextReloadIn)
: pluginReturnValue.nextReloadIn;
}
}

if (nextPluginReloadIn) {
this.reloadTimeout = setTimeout(async () => {
await this.reload();
}, nextPluginReloadIn);
}

debug('plugin values', values);

return values;
Expand Down

0 comments on commit d7da32c

Please sign in to comment.