zcb 0.2.10 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zcb",
3
3
  "description": "Build configs with type safety from zod schema.",
4
- "version": "0.2.10",
4
+ "version": "0.3.0",
5
5
  "author": "Dylan Aubrey",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/zod-config-builder",
@@ -28,7 +28,7 @@ describe('createConfigReader', () => {
28
28
  const reader = createReader();
29
29
 
30
30
  // @ts-expect-error path does not resovle to a string
31
- expect(() => reader.read('pages.contactDetails', { vars })).toThrow(
31
+ expect(() => reader.read('pages.contactDetails', vars)).toThrow(
32
32
  new Error(
33
33
  'config reader received variables to use in string template, but the path did not resolve to a string.',
34
34
  ),
@@ -39,7 +39,7 @@ describe('createConfigReader', () => {
39
39
  describe('when a user accesses a property that is a string', () => {
40
40
  it('should return the correct string value with template placeholders populated', () => {
41
41
  const reader = createReader();
42
- const value = reader.read('templateString', { vars });
42
+ const value = reader.read('templateString', vars);
43
43
  expect(value).toBe('Simple Simon met a pieman going to the fair');
44
44
  });
45
45
  });
@@ -2,12 +2,8 @@ import { get, isString } from 'lodash-es';
2
2
  import { type Get } from 'type-fest';
3
3
  import { type Path, type Scope } from './types.ts';
4
4
 
5
- export type ReadOptions = {
6
- vars?: Record<string, string | number>;
7
- };
8
-
9
5
  export interface ConfigReader<Config extends object> {
10
- read: <P extends Path<Config>>(path: P, options?: ReadOptions) => Get<Config, P>;
6
+ read: <P extends Path<Config>>(path: P, variables?: Record<string, string | number>) => Get<Config, P>;
11
7
  scope: <S extends Scope<Config>>(scope: S) => ConfigReader<Get<Config, S>>;
12
8
  }
13
9
 
@@ -15,8 +11,8 @@ export const createConfigReader = <Config extends object>(config: Config): Confi
15
11
  // Aimed at reducing the amount of work for typescript to resolve type.
16
12
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
17
13
  const configReader = {
18
- read: <P extends Path<Config>>(path: P, { vars }: ReadOptions = {}) => {
19
- if (!vars) {
14
+ read: <P extends Path<Config>>(path: P, variables?: Record<string, string | number>) => {
15
+ if (!variables) {
20
16
  return get(config, path);
21
17
  }
22
18
 
@@ -28,8 +24,8 @@ export const createConfigReader = <Config extends object>(config: Config): Confi
28
24
  );
29
25
  }
30
26
 
31
- return Object.keys(vars).reduce<string>((acc, key) => {
32
- return acc.replace(new RegExp(`{{${key}}}`), String(vars[key]));
27
+ return Object.keys(variables).reduce<string>((acc, key) => {
28
+ return acc.replace(new RegExp(`{{${key}}}`), String(variables[key]));
33
29
  }, output);
34
30
  },
35
31
  // Aimed at reducing the amount of work for typescript to resolve type.