zcb 0.2.4 → 0.2.6

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.
Files changed (74) hide show
  1. package/README.md +15 -3
  2. package/dist/cjs/cli.cjs +1 -185
  3. package/dist/cjs/cli.cjs.map +1 -1
  4. package/dist/cjs/index.cjs +1 -384
  5. package/dist/cjs/index.cjs.map +1 -1
  6. package/dist/esm/cli.mjs +1 -182
  7. package/dist/esm/cli.mjs.map +1 -1
  8. package/dist/esm/index.mjs +1 -372
  9. package/dist/esm/index.mjs.map +1 -1
  10. package/dist/production.analysis.txt +72 -0
  11. package/dist/types/cjs/createConfigParser.d.cts +1 -1
  12. package/dist/types/cjs/createConfigParser.d.cts.map +1 -1
  13. package/dist/types/cjs/createConfigReader.d.cts +6 -3
  14. package/dist/types/cjs/createConfigReader.d.cts.map +1 -1
  15. package/dist/types/cjs/types.d.cts +2 -2
  16. package/dist/types/cjs/types.d.cts.map +1 -1
  17. package/dist/types/cjs/utils/arrayHasInvalidDefaults.d.cts +1 -1
  18. package/dist/types/cjs/utils/arrayHasInvalidDefaults.d.cts.map +1 -1
  19. package/dist/types/cjs/utils/collateObjectPropertyDefaults.d.cts +2 -2
  20. package/dist/types/cjs/utils/collateObjectPropertyDefaults.d.cts.map +1 -1
  21. package/dist/types/cjs/utils/importValidateTransformWriteConfig.d.cts +1 -1
  22. package/dist/types/cjs/utils/importValidateTransformWriteConfig.d.cts.map +1 -1
  23. package/dist/types/cjs/utils/isSchemaValid.d.cts +1 -1
  24. package/dist/types/cjs/utils/isSchemaValid.d.cts.map +1 -1
  25. package/dist/types/cjs/utils/isValidPropertyDefinition.d.cts +1 -1
  26. package/dist/types/cjs/utils/isValidPropertyDefinition.d.cts.map +1 -1
  27. package/dist/types/cjs/utils/jsonStringifyReplacer.d.cts +1 -1
  28. package/dist/types/cjs/utils/jsonStringifyReplacer.d.cts.map +1 -1
  29. package/dist/types/cjs/utils/objectPropertyHasDefaults.d.cts +1 -1
  30. package/dist/types/cjs/utils/objectPropertyHasDefaults.d.cts.map +1 -1
  31. package/dist/types/cjs/utils/recordHasInvalidDefaults.d.cts +1 -1
  32. package/dist/types/cjs/utils/recordHasInvalidDefaults.d.cts.map +1 -1
  33. package/dist/types/cjs/utils/transformWriteConfig.d.cts +1 -1
  34. package/dist/types/cjs/utils/transformWriteConfig.d.cts.map +1 -1
  35. package/dist/types/esm/createConfigParser.d.ts +1 -1
  36. package/dist/types/esm/createConfigParser.d.ts.map +1 -1
  37. package/dist/types/esm/createConfigReader.d.ts +6 -3
  38. package/dist/types/esm/createConfigReader.d.ts.map +1 -1
  39. package/dist/types/esm/types.d.ts +2 -2
  40. package/dist/types/esm/types.d.ts.map +1 -1
  41. package/dist/types/esm/utils/arrayHasInvalidDefaults.d.ts +1 -1
  42. package/dist/types/esm/utils/arrayHasInvalidDefaults.d.ts.map +1 -1
  43. package/dist/types/esm/utils/collateObjectPropertyDefaults.d.ts +2 -2
  44. package/dist/types/esm/utils/collateObjectPropertyDefaults.d.ts.map +1 -1
  45. package/dist/types/esm/utils/importValidateTransformWriteConfig.d.ts +1 -1
  46. package/dist/types/esm/utils/importValidateTransformWriteConfig.d.ts.map +1 -1
  47. package/dist/types/esm/utils/isSchemaValid.d.ts +1 -1
  48. package/dist/types/esm/utils/isSchemaValid.d.ts.map +1 -1
  49. package/dist/types/esm/utils/isValidPropertyDefinition.d.ts +1 -1
  50. package/dist/types/esm/utils/isValidPropertyDefinition.d.ts.map +1 -1
  51. package/dist/types/esm/utils/jsonStringifyReplacer.d.ts +1 -1
  52. package/dist/types/esm/utils/jsonStringifyReplacer.d.ts.map +1 -1
  53. package/dist/types/esm/utils/objectPropertyHasDefaults.d.ts +1 -1
  54. package/dist/types/esm/utils/objectPropertyHasDefaults.d.ts.map +1 -1
  55. package/dist/types/esm/utils/recordHasInvalidDefaults.d.ts +1 -1
  56. package/dist/types/esm/utils/recordHasInvalidDefaults.d.ts.map +1 -1
  57. package/dist/types/esm/utils/transformWriteConfig.d.ts +1 -1
  58. package/dist/types/esm/utils/transformWriteConfig.d.ts.map +1 -1
  59. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  60. package/package.json +22 -32
  61. package/src/__testUtils__/builtConfig.ts +1 -0
  62. package/src/createConfigParser.ts +1 -1
  63. package/src/createConfigReader.test.ts +28 -0
  64. package/src/createConfigReader.ts +25 -5
  65. package/src/types.ts +2 -2
  66. package/src/utils/arrayHasInvalidDefaults.ts +1 -1
  67. package/src/utils/collateObjectPropertyDefaults.ts +2 -2
  68. package/src/utils/importValidateTransformWriteConfig.ts +3 -3
  69. package/src/utils/isSchemaValid.ts +1 -1
  70. package/src/utils/isValidPropertyDefinition.ts +1 -1
  71. package/src/utils/jsonStringifyReplacer.ts +1 -1
  72. package/src/utils/objectPropertyHasDefaults.ts +1 -1
  73. package/src/utils/recordHasInvalidDefaults.ts +1 -1
  74. package/src/utils/transformWriteConfig.ts +1 -1
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.4",
4
+ "version": "0.2.6",
5
5
  "author": "Dylan Aubrey",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/zod-config-builder",
@@ -45,47 +45,37 @@
45
45
  "zod-to-json-schema": "^3.21.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "@babel/runtime": "<8",
49
48
  "core-js": "<4",
50
49
  "lodash-es": "<5",
51
50
  "ts-node": "<11"
52
51
  },
53
52
  "devDependencies": {
54
- "@babel/cli": "^7.21.5",
55
- "@babel/core": "^7.21.8",
56
- "@babel/eslint-parser": "^7.21.8",
57
- "@babel/plugin-proposal-decorators": "^7.23.3",
58
- "@babel/plugin-syntax-import-assertions": "^7.20.0",
59
- "@babel/plugin-transform-class-properties": "^7.23.3",
60
- "@babel/plugin-transform-export-namespace-from": "^7.23.4",
61
- "@babel/plugin-transform-modules-commonjs": "^7.23.3",
62
- "@babel/plugin-transform-runtime": "^7.21.4",
63
- "@babel/preset-env": "^7.21.5",
64
- "@babel/preset-react": "^7.18.6",
65
- "@babel/preset-typescript": "^7.21.5",
66
- "@babel/runtime": "^7.21.5",
67
53
  "@commitlint/cli": "^17.6.3",
68
54
  "@commitlint/config-conventional": "^17.6.3",
69
55
  "@commitlint/prompt-cli": "^17.6.3",
70
- "@jest/globals": "^29.5.0",
71
- "@repodog/babel-config": "^1.1.11",
72
- "@repodog/cli": "^1.4.1",
73
- "@repodog/commitlint-config": "^1.1.6",
74
- "@repodog/eslint-config": "^1.1.19",
75
- "@repodog/eslint-config-jest": "^1.1.10",
76
- "@repodog/jest-config": "^1.1.11",
77
- "@repodog/markdownlint-config": "^1.1.5",
78
- "@repodog/prettier-config": "^1.1.5",
79
- "@repodog/rollup-config": "^1.1.8",
80
- "@repodog/syncpack-config": "^1.2.3",
81
- "@repodog/ts-config": "^1.3.0",
56
+ "@jest/globals": "^29.7.0",
57
+ "@repodog/babel-config": "^1.2.1",
58
+ "@repodog/cli": "^1.6.24",
59
+ "@repodog/commitlint-config": "^1.2.2",
60
+ "@repodog/eslint-config": "^1.2.2",
61
+ "@repodog/eslint-config-jest": "^1.2.1",
62
+ "@repodog/jest-config": "^1.2.3",
63
+ "@repodog/markdownlint-config": "^1.2.1",
64
+ "@repodog/prettier-config": "^1.2.1",
65
+ "@repodog/rollup-config": "^1.2.2",
66
+ "@repodog/swc-config": "^0.2.5",
67
+ "@repodog/syncpack-config": "^1.3.1",
68
+ "@repodog/ts-config": "^1.4.1",
82
69
  "@rollup/plugin-babel": "^6.0.3",
83
70
  "@rollup/plugin-commonjs": "^25.0.7",
84
71
  "@rollup/plugin-image": "^3.0.2",
85
72
  "@rollup/plugin-json": "^6.0.0",
86
73
  "@rollup/plugin-node-resolve": "^15.0.2",
74
+ "@rollup/plugin-swc": "^0.3.0",
87
75
  "@rollup/plugin-terser": "^0.4.1",
88
- "@types/jest": "^25.2.3",
76
+ "@swc/core": "^1.4.1",
77
+ "@swc/jest": "^0.2.36",
78
+ "@types/jest": "^29.5.12",
89
79
  "@types/lodash-es": "^4.17.9",
90
80
  "@types/node": "^20.11.0",
91
81
  "@typescript-eslint/eslint-plugin": "^5.59.5",
@@ -111,17 +101,17 @@
111
101
  "generate-changelog": "^1.8.0",
112
102
  "husky": "^8.0.3",
113
103
  "identity-obj-proxy": "^3.0.0",
114
- "jest": "^29.5.0",
104
+ "jest": "^29.7.0",
115
105
  "jest-environment-jsdom": "^29.7.0",
116
106
  "jest-environment-node": "^29.7.0",
117
107
  "lodash-es": "^4.17.21",
118
- "markdownlint-cli": "^0.34.0",
108
+ "markdownlint-cli2": "^0.12.1",
119
109
  "prettier": "^2.8.8",
120
110
  "rollup": "^3.21.6",
121
111
  "rollup-plugin-analyzer": "^4.0.0",
122
112
  "rollup-plugin-copy": "^3.4.0",
123
113
  "rollup-plugin-sourcemaps": "^0.6.3",
124
- "suppress-experimental-warnings": "^1.1.17",
114
+ "suppress-experimental-warnings": "^2.0.0",
125
115
  "syncpack": "^12.3.0",
126
116
  "ts-node": "^10.9.1",
127
117
  "typescript": "^5.0.4"
@@ -145,7 +135,7 @@
145
135
  "lint": "eslint . --ext .ts,.cjs",
146
136
  "repodog": "repodog",
147
137
  "syncpack": "syncpack format && syncpack list-mismatches && syncpack lint-semver-ranges",
148
- "test": "node --require=suppress-experimental-warnings --experimental-vm-modules node_modules/jest/bin/jest.js",
138
+ "test": "COMPILER=swc node --require=suppress-experimental-warnings --experimental-vm-modules node_modules/jest/bin/jest.js",
149
139
  "type-check": "tsc --noEmit",
150
140
  "validate": "pnpm run syncpack && pnpm run build && pnpm run lint && pnpm run type-check && pnpm run test",
151
141
  "zcb:build": "NODE_OPTIONS=\"--loader ts-node/esm\" node ./bin/zcb.mjs build ./src/__testUtils__/configBuilder.ts ./src/__testUtils__/builtConfig.ts",
@@ -68,6 +68,7 @@ export default {
68
68
  path: "contact-details"
69
69
  }
70
70
  ],
71
+ templateString: 'Simple {{name}} met a {{profession}} going to the fair',
71
72
  timeouts: {
72
73
  apollo: 10000
73
74
  },
@@ -1,5 +1,5 @@
1
1
  import { runExperiments } from './transformers/runExperiments.ts';
2
- import type { ConfigParserOptions, TransformConfigHandler } from './types.ts';
2
+ import { type ConfigParserOptions, type TransformConfigHandler } from './types.ts';
3
3
  import { transformConfig } from './utils/transformConfig.ts';
4
4
 
5
5
  export const createConfigParser = async <Config extends object>(
@@ -17,6 +17,34 @@ describe('createConfigReader', () => {
17
17
  });
18
18
  });
19
19
 
20
+ describe('when vars options are passed in', () => {
21
+ const vars = {
22
+ name: 'Simon',
23
+ profession: 'pieman',
24
+ };
25
+
26
+ describe('when a user accesses a property that is not a string', () => {
27
+ it('should throw the correct error', () => {
28
+ const reader = createReader();
29
+
30
+ // @ts-expect-error path does not resovle to a string
31
+ expect(() => reader.read('pages.contactDetails', { vars })).toThrow(
32
+ new Error(
33
+ 'config reader received variables to use in string template, but the path did not resolve to a string.'
34
+ )
35
+ );
36
+ });
37
+ });
38
+
39
+ describe('when a user accesses a property that is a string', () => {
40
+ it('should return the correct string value with template placeholders populated', () => {
41
+ const reader = createReader();
42
+ const value = reader.read('templateString', { vars });
43
+ expect(value).toBe('Simple Simon met a pieman going to the fair');
44
+ });
45
+ });
46
+ });
47
+
20
48
  describe('when the reader is scoped', () => {
21
49
  describe('when a user accesses a known property', () => {
22
50
  it('should return the correct value', () => {
@@ -1,15 +1,35 @@
1
- import { get } from 'lodash-es';
2
- import type { Get } from 'type-fest';
3
- import type { Path, Scope } from './types.ts';
1
+ import { get, isString } from 'lodash-es';
2
+ import { type Get } from 'type-fest';
3
+ import { type Path, type Scope } from './types.ts';
4
+
5
+ export type ReadOptions = {
6
+ vars?: Record<string, string | number>;
7
+ };
4
8
 
5
9
  export interface ConfigReader<Config extends object> {
6
- read: <P extends Path<Config>>(path: P) => Get<Config, P>;
10
+ read: <P extends Path<Config>>(path: P, options?: ReadOptions) => Get<Config, P>;
7
11
  scope: <S extends Scope<Config>>(scope: S) => ConfigReader<Get<Config, S>>;
8
12
  }
9
13
 
10
14
  export const createConfigReader = <Config extends object>(config: Config): ConfigReader<Config> => {
11
15
  const configReader = {
12
- read: <P extends Path<Config>>(path: P) => get(config, path),
16
+ read: <P extends Path<Config>>(path: P, { vars }: ReadOptions = {}) => {
17
+ if (!vars) {
18
+ return get(config, path);
19
+ }
20
+
21
+ const output = get(config, path);
22
+
23
+ if (!isString(output)) {
24
+ throw new Error(
25
+ 'config reader received variables to use in string template, but the path did not resolve to a string.'
26
+ );
27
+ }
28
+
29
+ return Object.keys(vars).reduce<string>((acc, key) => {
30
+ return acc.replace(new RegExp(`{{${key}}}`), String(vars[key]));
31
+ }, output);
32
+ },
13
33
  scope: <S extends Scope<Config>>(scope: S) => createConfigReader(get(config, scope) as Get<Config, S>),
14
34
  } as ConfigReader<Config>;
15
35
 
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { List } from 'ts-toolbelt';
2
- import type { Includes, Join } from 'type-fest';
1
+ import { type List } from 'ts-toolbelt';
2
+ import { type Includes, type Join } from 'type-fest';
3
3
 
4
4
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
5
  export type AnyRecord = Record<string, any>;
@@ -1,4 +1,4 @@
1
- import type { JSONSchema7 } from 'json-schema';
1
+ import { type JSONSchema7 } from 'json-schema';
2
2
 
3
3
  export const arrayHasInvalidDefaults = (propertyDefinition: JSONSchema7) => {
4
4
  const { items } = propertyDefinition;
@@ -1,6 +1,6 @@
1
- import type { JSONSchema7 } from 'json-schema';
1
+ import { type JSONSchema7 } from 'json-schema';
2
2
  import { isBoolean, isUndefined } from 'lodash-es';
3
- import type { Jsonifiable } from 'type-fest';
3
+ import { type Jsonifiable } from 'type-fest';
4
4
  import { objectPropertyHasDefaults } from './objectPropertyHasDefaults.ts';
5
5
 
6
6
  export const collateObjectPropertyDefaults = (propertyDefinition: JSONSchema7) => {
@@ -1,8 +1,8 @@
1
1
  import { resolve } from 'node:path';
2
2
  import shelljs from 'shelljs';
3
- import type { Commands } from '../cli.ts';
4
- import type { ConfigBuilder } from '../createConfigBuilder.ts';
5
- import type { SetupExperimentsCallback } from '../types.ts';
3
+ import { type Commands } from '../cli.ts';
4
+ import { type ConfigBuilder } from '../createConfigBuilder.ts';
5
+ import { type SetupExperimentsCallback } from '../types.ts';
6
6
  import { transformWriteConfig } from './transformWriteConfig.ts';
7
7
 
8
8
  export const importValidateTransformWriteConfig = (
@@ -1,3 +1,3 @@
1
- import type { JSONSchema7 } from 'json-schema';
1
+ import { type JSONSchema7 } from 'json-schema';
2
2
 
3
3
  export const isSchemaValid = (schema: JSONSchema7) => schema.type !== 'object';
@@ -1,4 +1,4 @@
1
- import type { JSONSchema7, JSONSchema7Definition } from 'json-schema';
1
+ import { type JSONSchema7, type JSONSchema7Definition } from 'json-schema';
2
2
 
3
3
  export const isValidPropertyDefinition = (
4
4
  propertyDefinition: JSONSchema7Definition | undefined
@@ -1,4 +1,4 @@
1
- import type { Jsonifiable } from 'type-fest';
1
+ import { type Jsonifiable } from 'type-fest';
2
2
  import { ZodType } from 'zod';
3
3
  import { zodToJsonSchema } from 'zod-to-json-schema';
4
4
 
@@ -1,4 +1,4 @@
1
- import type { JSONSchema7 } from 'json-schema';
1
+ import { type JSONSchema7 } from 'json-schema';
2
2
 
3
3
  export const objectPropertyHasDefaults = (propertyDefinition: JSONSchema7) =>
4
4
  propertyDefinition.properties &&
@@ -1,4 +1,4 @@
1
- import type { JSONSchema7 } from 'json-schema';
1
+ import { type JSONSchema7 } from 'json-schema';
2
2
 
3
3
  export const recordHasInvalidDefaults = (propertyDefinition: JSONSchema7) =>
4
4
  propertyDefinition.additionalProperties &&
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url';
6
6
  import shelljs from 'shelljs';
7
7
  import { removeDisabledSlices } from '../transformers/removeDisabledSlices.ts';
8
8
  import { setupExperiments } from '../transformers/setupExperiments.ts';
9
- import type { TransformConfigHandler, WriteConfigOptions } from '../types.ts';
9
+ import { type TransformConfigHandler, type WriteConfigOptions } from '../types.ts';
10
10
  import { transformConfig } from './transformConfig.ts';
11
11
 
12
12
  export const transformWriteConfig = async <Config extends object>(