@autometa/config 0.0.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/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ /dist
2
+ /out
3
+ node_modules
package/.eslintrc.cjs ADDED
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ["custom"],
4
+ };
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) undefined Ben Aherne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Introduction
2
+
3
+ There's nothing here yet
@@ -0,0 +1,130 @@
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
4
+ };
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
8
+ };
9
+ var __privateAdd = (obj, member, value) => {
10
+ if (member.has(obj))
11
+ throw TypeError("Cannot add the same private member more than once");
12
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
+ };
14
+ var __privateSet = (obj, member, value, setter) => {
15
+ __accessCheck(obj, member, "write to private field");
16
+ setter ? setter.call(obj, value) : member.set(obj, value);
17
+ return value;
18
+ };
19
+
20
+ // src/config-object.ts
21
+ import { AutomationError, raise } from "@autometa/errors";
22
+
23
+ // src/environment-reader.ts
24
+ var _envVar, _factory, _literal;
25
+ var EnvironmentReader = class {
26
+ constructor() {
27
+ __privateAdd(this, _envVar, void 0);
28
+ __privateAdd(this, _factory, void 0);
29
+ __privateAdd(this, _literal, void 0);
30
+ }
31
+ /**
32
+ * Returns the configuration object for the selected
33
+ * environment by weighting.
34
+ *
35
+ * By priority the environment is selected by:
36
+ * 1. Literal
37
+ * 2. Environment Variable
38
+ * 3. Factory
39
+ */
40
+ get value() {
41
+ if (__privateGet(this, _literal)) {
42
+ return __privateGet(this, _literal);
43
+ }
44
+ if (__privateGet(this, _envVar)) {
45
+ const value = process.env[__privateGet(this, _envVar)];
46
+ if (value) {
47
+ return value;
48
+ }
49
+ }
50
+ if (__privateGet(this, _factory)) {
51
+ return __privateGet(this, _factory).call(this);
52
+ }
53
+ }
54
+ byEnvironmentVariable(envVar) {
55
+ __privateSet(this, _envVar, envVar);
56
+ return this;
57
+ }
58
+ byFactory(factory) {
59
+ __privateSet(this, _factory, factory);
60
+ return this;
61
+ }
62
+ byLiteral(literal) {
63
+ __privateSet(this, _literal, literal);
64
+ return this;
65
+ }
66
+ };
67
+ _envVar = new WeakMap();
68
+ _factory = new WeakMap();
69
+ _literal = new WeakMap();
70
+
71
+ // src/config-object.ts
72
+ var Config = class {
73
+ constructor(envMap) {
74
+ this.envMap = envMap;
75
+ this.environments = new EnvironmentReader();
76
+ }
77
+ get current() {
78
+ const key = this.environments.value;
79
+ if (!key) {
80
+ if (!this.envMap.has("default")) {
81
+ throw new AutomationError(
82
+ `No environment is defined. Define an environment with 'env.byLiteral("my-environment")' or 'env.byEnvironmentVariable("MY_ENVIRONMENT")' or 'env.byFactory(() => "my-environment")' or 'env.byLiteral("default")'`
83
+ );
84
+ }
85
+ return this.envMap.get("default");
86
+ }
87
+ if (!this.envMap.has(key)) {
88
+ throw new AutomationError(
89
+ `Environment ${key} is not defined. Options are:
90
+ ${Object.keys(
91
+ this.envMap
92
+ ).join("\n")}`
93
+ );
94
+ }
95
+ return this.envMap.get(key) ?? raise(`Environment ${key} is not defined`);
96
+ }
97
+ };
98
+
99
+ // src/define-config.ts
100
+ import { AutomationError as AutomationError2 } from "@autometa/errors";
101
+ function defineConfig(config, ...configs) {
102
+ const envs = [];
103
+ const envMap = config.envMap;
104
+ for (const config2 of configs) {
105
+ if (config2.environment) {
106
+ if (envs.includes(config2.environment)) {
107
+ throw new AutomationError2(
108
+ `Environment ${config2.environment} is defined more than once`
109
+ );
110
+ }
111
+ envMap.set(config2.environment, config2);
112
+ envs.push(config2.environment);
113
+ } else if (!config2.environment && envs.includes("default")) {
114
+ throw new AutomationError2(`Only one default environment can be defined`);
115
+ } else {
116
+ envMap.set("default", config2);
117
+ envs.push("default");
118
+ config2.environment = "default";
119
+ }
120
+ }
121
+ const setters = config.environments;
122
+ return {
123
+ env: setters
124
+ };
125
+ }
126
+ export {
127
+ Config,
128
+ EnvironmentReader,
129
+ defineConfig
130
+ };
@@ -0,0 +1,42 @@
1
+ declare class EnvironmentReader {
2
+ #private;
3
+ /**
4
+ * Returns the configuration object for the selected
5
+ * environment by weighting.
6
+ *
7
+ * By priority the environment is selected by:
8
+ * 1. Literal
9
+ * 2. Environment Variable
10
+ * 3. Factory
11
+ */
12
+ get value(): string | undefined;
13
+ byEnvironmentVariable(envVar: string): this;
14
+ byFactory(factory: () => string): this;
15
+ byLiteral(literal: string): this;
16
+ }
17
+
18
+ type TestExecutorConfig = {
19
+ runner: "jest" | "vitest";
20
+ environment?: string;
21
+ test?: {
22
+ timeout?: number;
23
+ tagFilter?: string;
24
+ };
25
+ };
26
+
27
+ declare class Config {
28
+ envMap: Map<string, TestExecutorConfig>;
29
+ readonly environments: EnvironmentReader;
30
+ constructor(envMap: Map<string, TestExecutorConfig>);
31
+ get current(): TestExecutorConfig | undefined;
32
+ }
33
+
34
+ declare function defineConfig(config: Config, ...configs: TestExecutorConfig[]): {
35
+ env: {
36
+ byLiteral: (literal: string) => EnvironmentReader;
37
+ byEnvironmentVariable: (literal: string) => EnvironmentReader;
38
+ byFactory: (literal: () => string) => EnvironmentReader;
39
+ };
40
+ };
41
+
42
+ export { Config, EnvironmentReader, TestExecutorConfig, defineConfig };
package/dist/index.js ADDED
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __accessCheck = (obj, member, msg) => {
20
+ if (!member.has(obj))
21
+ throw TypeError("Cannot " + msg);
22
+ };
23
+ var __privateGet = (obj, member, getter) => {
24
+ __accessCheck(obj, member, "read from private field");
25
+ return getter ? getter.call(obj) : member.get(obj);
26
+ };
27
+ var __privateAdd = (obj, member, value) => {
28
+ if (member.has(obj))
29
+ throw TypeError("Cannot add the same private member more than once");
30
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
31
+ };
32
+ var __privateSet = (obj, member, value, setter) => {
33
+ __accessCheck(obj, member, "write to private field");
34
+ setter ? setter.call(obj, value) : member.set(obj, value);
35
+ return value;
36
+ };
37
+
38
+ // src/index.ts
39
+ var src_exports = {};
40
+ __export(src_exports, {
41
+ Config: () => Config,
42
+ EnvironmentReader: () => EnvironmentReader,
43
+ defineConfig: () => defineConfig
44
+ });
45
+ module.exports = __toCommonJS(src_exports);
46
+
47
+ // src/config-object.ts
48
+ var import_errors = require("@autometa/errors");
49
+
50
+ // src/environment-reader.ts
51
+ var _envVar, _factory, _literal;
52
+ var EnvironmentReader = class {
53
+ constructor() {
54
+ __privateAdd(this, _envVar, void 0);
55
+ __privateAdd(this, _factory, void 0);
56
+ __privateAdd(this, _literal, void 0);
57
+ }
58
+ /**
59
+ * Returns the configuration object for the selected
60
+ * environment by weighting.
61
+ *
62
+ * By priority the environment is selected by:
63
+ * 1. Literal
64
+ * 2. Environment Variable
65
+ * 3. Factory
66
+ */
67
+ get value() {
68
+ if (__privateGet(this, _literal)) {
69
+ return __privateGet(this, _literal);
70
+ }
71
+ if (__privateGet(this, _envVar)) {
72
+ const value = process.env[__privateGet(this, _envVar)];
73
+ if (value) {
74
+ return value;
75
+ }
76
+ }
77
+ if (__privateGet(this, _factory)) {
78
+ return __privateGet(this, _factory).call(this);
79
+ }
80
+ }
81
+ byEnvironmentVariable(envVar) {
82
+ __privateSet(this, _envVar, envVar);
83
+ return this;
84
+ }
85
+ byFactory(factory) {
86
+ __privateSet(this, _factory, factory);
87
+ return this;
88
+ }
89
+ byLiteral(literal) {
90
+ __privateSet(this, _literal, literal);
91
+ return this;
92
+ }
93
+ };
94
+ _envVar = new WeakMap();
95
+ _factory = new WeakMap();
96
+ _literal = new WeakMap();
97
+
98
+ // src/config-object.ts
99
+ var Config = class {
100
+ constructor(envMap) {
101
+ this.envMap = envMap;
102
+ this.environments = new EnvironmentReader();
103
+ }
104
+ get current() {
105
+ const key = this.environments.value;
106
+ if (!key) {
107
+ if (!this.envMap.has("default")) {
108
+ throw new import_errors.AutomationError(
109
+ `No environment is defined. Define an environment with 'env.byLiteral("my-environment")' or 'env.byEnvironmentVariable("MY_ENVIRONMENT")' or 'env.byFactory(() => "my-environment")' or 'env.byLiteral("default")'`
110
+ );
111
+ }
112
+ return this.envMap.get("default");
113
+ }
114
+ if (!this.envMap.has(key)) {
115
+ throw new import_errors.AutomationError(
116
+ `Environment ${key} is not defined. Options are:
117
+ ${Object.keys(
118
+ this.envMap
119
+ ).join("\n")}`
120
+ );
121
+ }
122
+ return this.envMap.get(key) ?? (0, import_errors.raise)(`Environment ${key} is not defined`);
123
+ }
124
+ };
125
+
126
+ // src/define-config.ts
127
+ var import_errors2 = require("@autometa/errors");
128
+ function defineConfig(config, ...configs) {
129
+ const envs = [];
130
+ const envMap = config.envMap;
131
+ for (const config2 of configs) {
132
+ if (config2.environment) {
133
+ if (envs.includes(config2.environment)) {
134
+ throw new import_errors2.AutomationError(
135
+ `Environment ${config2.environment} is defined more than once`
136
+ );
137
+ }
138
+ envMap.set(config2.environment, config2);
139
+ envs.push(config2.environment);
140
+ } else if (!config2.environment && envs.includes("default")) {
141
+ throw new import_errors2.AutomationError(`Only one default environment can be defined`);
142
+ } else {
143
+ envMap.set("default", config2);
144
+ envs.push("default");
145
+ config2.environment = "default";
146
+ }
147
+ }
148
+ const setters = config.environments;
149
+ return {
150
+ env: setters
151
+ };
152
+ }
153
+ // Annotate the CommonJS export names for ESM import in node:
154
+ 0 && (module.exports = {
155
+ Config,
156
+ EnvironmentReader,
157
+ defineConfig
158
+ });
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@autometa/config",
3
+ "version": "0.0.0",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/esm/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ "import": "./dist/esm/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/esm/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "license": "MIT",
16
+ "devDependencies": {
17
+ "@types/node": "^18.11.18",
18
+ "@types/uuid": "^9.0.1",
19
+ "@typescript-eslint/eslint-plugin": "^5.54.1",
20
+ "@typescript-eslint/parser": "^5.54.1",
21
+ "eslint": "^8.37.0",
22
+ "eslint-config-custom": "0.5.1",
23
+ "eslint-config-prettier": "^8.3.0",
24
+ "rimraf": "^4.1.2",
25
+ "tsconfig": " *",
26
+ "tsup": "^6.7.0",
27
+ "typescript": "^4.9.5",
28
+ "vitest": "^0.29.8"
29
+ },
30
+ "dependencies": {
31
+ "@autometa/app": "^0.0.0",
32
+ "@autometa/asserters": "^0.0.0",
33
+ "@autometa/errors": "^0.0.0",
34
+ "@autometa/types": "^0.3.1",
35
+ "zod": "^3.21.4"
36
+ },
37
+ "scripts": {
38
+ "test": "vitest run --passWithNoTests",
39
+ "prettify": "prettier --config .prettierrc 'src/**/*.ts' --write",
40
+ "lint": "eslint . --max-warnings 0",
41
+ "lint:fix": "eslint . --fix",
42
+ "clean": "rimraf dist",
43
+ "build": "tsup",
44
+ "build:watch": "tsup --watch"
45
+ },
46
+ "readme": "# Introduction\n\nThere's nothing here yet"
47
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ clean: true, // clean up the dist folder
5
+ format: ["cjs", "esm"], // generate cjs and esm files
6
+ dts: true,
7
+ sourcemap: false, // generate sourcemaps
8
+ skipNodeModulesBundle: true,
9
+ entryPoints: ["src/index.ts"],
10
+ target: "es2020",
11
+ outDir: "dist",
12
+ legacyOutput: true,
13
+ external: ["dist"],
14
+ });