carlin 1.49.14 → 1.49.15

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/bin/carlin.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import '../dist/index.js';
2
+ import '../dist/index.mjs';
@@ -0,0 +1,32 @@
1
+ //#region src/defineConfig.d.ts
2
+ type CarlinParameterValue = string | number | undefined;
3
+ type CarlinParameter = {
4
+ key: string;
5
+ value?: string | number;
6
+ usePreviousValue?: boolean;
7
+ resolvedValue?: string;
8
+ };
9
+ type CarlinParameters = CarlinParameter[] | Record<string, CarlinParameterValue>;
10
+ type CarlinConfigContext = {
11
+ branch?: string;
12
+ environment?: string;
13
+ project?: string;
14
+ };
15
+ type CarlinConfig = {
16
+ parameters?: CarlinParameters;
17
+ environments?: Record<string, CarlinConfig>;
18
+ [key: string]: unknown;
19
+ };
20
+ type CarlinConfigFactory<Config extends CarlinConfig = CarlinConfig> = (context: CarlinConfigContext) => Config | Promise<Config>;
21
+ type RequiredEnvOptions = {
22
+ name: string;
23
+ message?: string;
24
+ };
25
+ declare function defineConfig<Config extends CarlinConfig>(config: Config): Config;
26
+ declare function defineConfig<Config extends CarlinConfig>(config: CarlinConfigFactory<Config>): CarlinConfigFactory<Config>;
27
+ declare const requiredEnv: ({
28
+ name,
29
+ message
30
+ }: RequiredEnvOptions) => string;
31
+ //#endregion
32
+ export { CarlinConfig, CarlinConfigContext, CarlinConfigFactory, CarlinParameter, CarlinParameterValue, CarlinParameters, RequiredEnvOptions, defineConfig, requiredEnv };
@@ -0,0 +1,103 @@
1
+ //#region src/defineConfig.ts
2
+ const isRecord = (value) => {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ };
5
+ const isPromise = (value) => {
6
+ return isRecord(value) && typeof value.then === "function";
7
+ };
8
+ const getConfigRecord = ({ config, path }) => {
9
+ if (!isRecord(config)) throw new Error(`${path} must resolve to an object.`);
10
+ return config;
11
+ };
12
+ const assertParameterValue = ({ key, path, usePreviousValue, value }) => {
13
+ if (usePreviousValue) return;
14
+ if (value === void 0 || value === null || value === "") throw new Error(`${path}.${key} must have a value.`);
15
+ if (typeof value !== "string" && typeof value !== "number") throw new Error(`${path}.${key} must be a string or number.`);
16
+ };
17
+ const validateParameterArray = ({ parameters, path }) => {
18
+ for (const [index, parameter] of parameters.entries()) {
19
+ if (!isRecord(parameter)) throw new Error(`${path}[${index}] must be an object.`);
20
+ if (typeof parameter.key !== "string" || parameter.key.length === 0) throw new Error(`${path}[${index}].key must be a non-empty string.`);
21
+ assertParameterValue({
22
+ key: parameter.key,
23
+ path,
24
+ usePreviousValue: parameter.usePreviousValue === true,
25
+ value: parameter.value
26
+ });
27
+ }
28
+ };
29
+ const validateParameterRecord = ({ parameters, path }) => {
30
+ for (const [key, value] of Object.entries(parameters)) assertParameterValue({
31
+ key,
32
+ path,
33
+ value
34
+ });
35
+ };
36
+ const validateParameters = ({ parameters, path }) => {
37
+ if (parameters === void 0) return;
38
+ if (Array.isArray(parameters)) {
39
+ validateParameterArray({
40
+ parameters,
41
+ path
42
+ });
43
+ return;
44
+ }
45
+ if (isRecord(parameters)) {
46
+ validateParameterRecord({
47
+ parameters,
48
+ path
49
+ });
50
+ return;
51
+ }
52
+ throw new Error(`${path} must be an object or an array.`);
53
+ };
54
+ const validateConfig = ({ config, path }) => {
55
+ const pendingConfigs = [{
56
+ config,
57
+ path
58
+ }];
59
+ const configRecord = getConfigRecord({
60
+ config,
61
+ path
62
+ });
63
+ for (const pendingConfig of pendingConfigs) {
64
+ const currentConfig = getConfigRecord(pendingConfig);
65
+ validateParameters({
66
+ parameters: currentConfig.parameters,
67
+ path: `${pendingConfig.path}.parameters`
68
+ });
69
+ if (currentConfig.environments === void 0) continue;
70
+ if (!isRecord(currentConfig.environments)) throw new Error(`${pendingConfig.path}.environments must be an object.`);
71
+ for (const [environment, environmentConfig] of Object.entries(currentConfig.environments)) pendingConfigs.push({
72
+ config: environmentConfig,
73
+ path: `${pendingConfig.path}.environments.${environment}`
74
+ });
75
+ }
76
+ return configRecord;
77
+ };
78
+ function defineConfig(config) {
79
+ if (typeof config === "function") return (context) => {
80
+ const resolvedConfig = config(context);
81
+ if (isPromise(resolvedConfig)) return resolvedConfig.then((asyncConfig) => {
82
+ return validateConfig({
83
+ config: asyncConfig,
84
+ path: "config"
85
+ });
86
+ });
87
+ return validateConfig({
88
+ config: resolvedConfig,
89
+ path: "config"
90
+ });
91
+ };
92
+ return validateConfig({
93
+ config,
94
+ path: "config"
95
+ });
96
+ }
97
+ const requiredEnv = ({ name, message }) => {
98
+ const value = process.env[name];
99
+ if (!value) throw new Error(message || `Missing required environment variable: ${name}`);
100
+ return value;
101
+ };
102
+ //#endregion
103
+ export { defineConfig, requiredEnv };
@@ -0,0 +1 @@
1
+ export { };