carlin 1.49.7 → 1.49.9
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/README.md +20 -0
- package/dist/chunk-3GQAWCBQ.js +10 -0
- package/dist/defineConfig.d.ts +28 -0
- package/dist/defineConfig.js +136 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +412 -359
- package/package.json +21 -11
package/README.md
CHANGED
|
@@ -8,6 +8,26 @@ pnpm add -D carlin
|
|
|
8
8
|
|
|
9
9
|
**[Documentation →](https://ttoss.dev/docs/carlin/)**
|
|
10
10
|
|
|
11
|
+
## Typed Configuration
|
|
12
|
+
|
|
13
|
+
Use `defineConfig` from `carlin/config` for typed `carlin.ts` files:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { defineConfig, requiredEnv } from 'carlin/config';
|
|
17
|
+
|
|
18
|
+
export default defineConfig(({ environment }) => {
|
|
19
|
+
return {
|
|
20
|
+
environment,
|
|
21
|
+
parameters: {
|
|
22
|
+
DomainName: 'api.example.com',
|
|
23
|
+
DatabasePassword: requiredEnv({ name: 'DATABASE_PASSWORD' }),
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
See the [configuration docs](https://ttoss.dev/docs/carlin/core-concepts/configuration) for the full flow from environment variables to CloudFormation parameters.
|
|
30
|
+
|
|
11
31
|
## License
|
|
12
32
|
|
|
13
33
|
MIT © [Pedro Arantes](https://twitter.com/arantespp)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export { __name, __require };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type CarlinParameterValue = string | number | undefined;
|
|
2
|
+
type CarlinParameter = {
|
|
3
|
+
key: string;
|
|
4
|
+
value?: string | number;
|
|
5
|
+
usePreviousValue?: boolean;
|
|
6
|
+
resolvedValue?: string;
|
|
7
|
+
};
|
|
8
|
+
type CarlinParameters = CarlinParameter[] | Record<string, CarlinParameterValue>;
|
|
9
|
+
type CarlinConfigContext = {
|
|
10
|
+
branch?: string;
|
|
11
|
+
environment?: string;
|
|
12
|
+
project?: string;
|
|
13
|
+
};
|
|
14
|
+
type CarlinConfig = {
|
|
15
|
+
parameters?: CarlinParameters;
|
|
16
|
+
environments?: Record<string, CarlinConfig>;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
type CarlinConfigFactory<Config extends CarlinConfig = CarlinConfig> = (context: CarlinConfigContext) => Config | Promise<Config>;
|
|
20
|
+
type RequiredEnvOptions = {
|
|
21
|
+
name: string;
|
|
22
|
+
message?: string;
|
|
23
|
+
};
|
|
24
|
+
declare function defineConfig<Config extends CarlinConfig>(config: Config): Config;
|
|
25
|
+
declare function defineConfig<Config extends CarlinConfig>(config: CarlinConfigFactory<Config>): CarlinConfigFactory<Config>;
|
|
26
|
+
declare const requiredEnv: ({ name, message }: RequiredEnvOptions) => string;
|
|
27
|
+
|
|
28
|
+
export { type CarlinConfig, type CarlinConfigContext, type CarlinConfigFactory, type CarlinParameter, type CarlinParameterValue, type CarlinParameters, type RequiredEnvOptions, defineConfig, requiredEnv };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { __name } from './chunk-3GQAWCBQ.js';
|
|
2
|
+
|
|
3
|
+
// src/defineConfig.ts
|
|
4
|
+
var isRecord = /* @__PURE__ */ __name((value) => {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}, "isRecord");
|
|
7
|
+
var isPromise = /* @__PURE__ */ __name((value) => {
|
|
8
|
+
return isRecord(value) && typeof value.then === "function";
|
|
9
|
+
}, "isPromise");
|
|
10
|
+
var getConfigRecord = /* @__PURE__ */ __name(({ config, path }) => {
|
|
11
|
+
if (!isRecord(config)) {
|
|
12
|
+
throw new Error(`${path} must resolve to an object.`);
|
|
13
|
+
}
|
|
14
|
+
return config;
|
|
15
|
+
}, "getConfigRecord");
|
|
16
|
+
var assertParameterValue = /* @__PURE__ */ __name(({ key, path, usePreviousValue, value }) => {
|
|
17
|
+
if (usePreviousValue) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (value === void 0 || value === null || value === "") {
|
|
21
|
+
throw new Error(`${path}.${key} must have a value.`);
|
|
22
|
+
}
|
|
23
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
|
24
|
+
throw new Error(`${path}.${key} must be a string or number.`);
|
|
25
|
+
}
|
|
26
|
+
}, "assertParameterValue");
|
|
27
|
+
var validateParameterArray = /* @__PURE__ */ __name(({ parameters, path }) => {
|
|
28
|
+
for (const [index, parameter] of parameters.entries()) {
|
|
29
|
+
if (!isRecord(parameter)) {
|
|
30
|
+
throw new Error(`${path}[${index}] must be an object.`);
|
|
31
|
+
}
|
|
32
|
+
if (typeof parameter.key !== "string" || parameter.key.length === 0) {
|
|
33
|
+
throw new Error(`${path}[${index}].key must be a non-empty string.`);
|
|
34
|
+
}
|
|
35
|
+
assertParameterValue({
|
|
36
|
+
key: parameter.key,
|
|
37
|
+
path,
|
|
38
|
+
usePreviousValue: parameter.usePreviousValue === true,
|
|
39
|
+
value: parameter.value
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}, "validateParameterArray");
|
|
43
|
+
var validateParameterRecord = /* @__PURE__ */ __name(({ parameters, path }) => {
|
|
44
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
45
|
+
assertParameterValue({
|
|
46
|
+
key,
|
|
47
|
+
path,
|
|
48
|
+
value
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}, "validateParameterRecord");
|
|
52
|
+
var validateParameters = /* @__PURE__ */ __name(({ parameters, path }) => {
|
|
53
|
+
if (parameters === void 0) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(parameters)) {
|
|
57
|
+
validateParameterArray({
|
|
58
|
+
parameters,
|
|
59
|
+
path
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (isRecord(parameters)) {
|
|
64
|
+
validateParameterRecord({
|
|
65
|
+
parameters,
|
|
66
|
+
path
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
throw new Error(`${path} must be an object or an array.`);
|
|
71
|
+
}, "validateParameters");
|
|
72
|
+
var validateConfig = /* @__PURE__ */ __name(({ config, path }) => {
|
|
73
|
+
const pendingConfigs = [
|
|
74
|
+
{
|
|
75
|
+
config,
|
|
76
|
+
path
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
const configRecord = getConfigRecord({
|
|
80
|
+
config,
|
|
81
|
+
path
|
|
82
|
+
});
|
|
83
|
+
for (const pendingConfig of pendingConfigs) {
|
|
84
|
+
const currentConfig = getConfigRecord(pendingConfig);
|
|
85
|
+
validateParameters({
|
|
86
|
+
parameters: currentConfig.parameters,
|
|
87
|
+
path: `${pendingConfig.path}.parameters`
|
|
88
|
+
});
|
|
89
|
+
if (currentConfig.environments === void 0) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!isRecord(currentConfig.environments)) {
|
|
93
|
+
throw new Error(`${pendingConfig.path}.environments must be an object.`);
|
|
94
|
+
}
|
|
95
|
+
for (const [environment, environmentConfig] of Object.entries(currentConfig.environments)) {
|
|
96
|
+
pendingConfigs.push({
|
|
97
|
+
config: environmentConfig,
|
|
98
|
+
path: `${pendingConfig.path}.environments.${environment}`
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return configRecord;
|
|
103
|
+
}, "validateConfig");
|
|
104
|
+
function defineConfig(config) {
|
|
105
|
+
if (typeof config === "function") {
|
|
106
|
+
return (context) => {
|
|
107
|
+
const resolvedConfig = config(context);
|
|
108
|
+
if (isPromise(resolvedConfig)) {
|
|
109
|
+
return resolvedConfig.then((asyncConfig) => {
|
|
110
|
+
return validateConfig({
|
|
111
|
+
config: asyncConfig,
|
|
112
|
+
path: "config"
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return validateConfig({
|
|
117
|
+
config: resolvedConfig,
|
|
118
|
+
path: "config"
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return validateConfig({
|
|
123
|
+
config,
|
|
124
|
+
path: "config"
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
__name(defineConfig, "defineConfig");
|
|
128
|
+
var requiredEnv = /* @__PURE__ */ __name(({ name, message }) => {
|
|
129
|
+
const value = process.env[name];
|
|
130
|
+
if (!value) {
|
|
131
|
+
throw new Error(message || `Missing required environment variable: ${name}`);
|
|
132
|
+
}
|
|
133
|
+
return value;
|
|
134
|
+
}, "requiredEnv");
|
|
135
|
+
|
|
136
|
+
export { defineConfig, requiredEnv };
|
package/dist/index.d.ts
ADDED