@dxos/config 0.8.4-main.84f28bd → 0.8.4-main.ae835ea

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 (34) hide show
  1. package/dist/lib/browser/index.mjs +1 -0
  2. package/dist/lib/browser/index.mjs.map +2 -2
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +7 -6
  5. package/dist/lib/node-esm/index.mjs.map +3 -3
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/plugin/node-esm/{chunk-HYTOW36U.mjs → chunk-C4YHC2RN.mjs} +6 -5
  8. package/dist/plugin/node-esm/chunk-C4YHC2RN.mjs.map +7 -0
  9. package/dist/plugin/node-esm/esbuild-plugin.mjs +1 -1
  10. package/dist/plugin/node-esm/meta.json +1 -1
  11. package/dist/plugin/node-esm/rollup-plugin.mjs +1 -1
  12. package/dist/plugin/node-esm/vite-plugin.mjs +1 -1
  13. package/dist/plugin/node-esm/vite-plugin.mjs.map +2 -2
  14. package/dist/types/src/loaders/index.d.ts.map +1 -1
  15. package/dist/types/src/plugin/definitions.d.ts.map +1 -1
  16. package/dist/types/src/plugin/index.d.ts +1 -1
  17. package/dist/types/src/plugin/index.d.ts.map +1 -1
  18. package/dist/types/src/plugin/vite-plugin.d.ts.map +1 -1
  19. package/dist/types/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +11 -7
  21. package/src/loaders/index.ts +2 -1
  22. package/src/plugin/definitions.ts +4 -2
  23. package/src/plugin/index.ts +1 -1
  24. package/src/plugin/vite-plugin.ts +1 -0
  25. package/dist/plugin/browser/chunk-AN62TER6.mjs +0 -231
  26. package/dist/plugin/browser/chunk-AN62TER6.mjs.map +0 -7
  27. package/dist/plugin/browser/esbuild-plugin.mjs +0 -25
  28. package/dist/plugin/browser/esbuild-plugin.mjs.map +0 -7
  29. package/dist/plugin/browser/meta.json +0 -1
  30. package/dist/plugin/browser/rollup-plugin.mjs +0 -19
  31. package/dist/plugin/browser/rollup-plugin.mjs.map +0 -7
  32. package/dist/plugin/browser/vite-plugin.mjs +0 -30
  33. package/dist/plugin/browser/vite-plugin.mjs.map +0 -7
  34. package/dist/plugin/node-esm/chunk-HYTOW36U.mjs.map +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/config",
3
- "version": "0.8.4-main.84f28bd",
3
+ "version": "0.8.4-main.ae835ea",
4
4
  "description": "Config utilities",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -10,6 +10,7 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
13
+ "source": "./src/index.ts",
13
14
  "types": "./dist/types/src/index.d.ts",
14
15
  "browser": "./dist/lib/browser/index.mjs",
15
16
  "node": {
@@ -18,16 +19,19 @@
18
19
  }
19
20
  },
20
21
  "./esbuild-plugin": {
22
+ "source": "./src/esbuild-plugin/index.ts",
21
23
  "types": "./dist/types/src/esbuild-plugin/index.d.ts",
22
24
  "import": "./dist/plugin/node-esm/esbuild-plugin.mjs",
23
25
  "require": "./dist/plugin/node/esbuild-plugin.cjs"
24
26
  },
25
27
  "./rollup-plugin": {
28
+ "source": "./src/rollup-plugin/index.ts",
26
29
  "types": "./dist/types/src/rollup-plugin/index.d.ts",
27
30
  "import": "./dist/plugin/node-esm/rollup-plugin.mjs",
28
31
  "require": "./dist/plugin/node/rollup-plugin.cjs"
29
32
  },
30
33
  "./vite-plugin": {
34
+ "source": "./src/vite-plugin/index.ts",
31
35
  "types": "./dist/types/src/vite-plugin/index.d.ts",
32
36
  "import": "./dist/plugin/node-esm/vite-plugin.mjs",
33
37
  "require": "./dist/plugin/node/vite-plugin.cjs"
@@ -65,12 +69,12 @@
65
69
  "lodash.defaultsdeep": "^4.6.1",
66
70
  "lodash.ismatch": "^4.4.0",
67
71
  "pkg-up": "^3.1.0",
68
- "@dxos/invariant": "0.8.4-main.84f28bd",
69
- "@dxos/log": "0.8.4-main.84f28bd",
70
- "@dxos/node-std": "0.8.4-main.84f28bd",
71
- "@dxos/protocols": "0.8.4-main.84f28bd",
72
- "@dxos/tracing": "0.8.4-main.84f28bd",
73
- "@dxos/util": "0.8.4-main.84f28bd"
72
+ "@dxos/invariant": "0.8.4-main.ae835ea",
73
+ "@dxos/log": "0.8.4-main.ae835ea",
74
+ "@dxos/node-std": "0.8.4-main.ae835ea",
75
+ "@dxos/protocols": "0.8.4-main.ae835ea",
76
+ "@dxos/tracing": "0.8.4-main.ae835ea",
77
+ "@dxos/util": "0.8.4-main.ae835ea"
74
78
  },
75
79
  "devDependencies": {
76
80
  "@types/js-yaml": "^4.0.5",
@@ -2,10 +2,11 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import yaml from 'js-yaml';
6
5
  import fs from 'node:fs';
7
6
  import path from 'node:path';
8
7
 
8
+ import yaml from 'js-yaml';
9
+
9
10
  import { log } from '@dxos/log';
10
11
  import { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';
11
12
 
@@ -2,19 +2,21 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import yaml from 'js-yaml';
6
5
  import { execSync } from 'node:child_process';
7
6
  import { readFileSync } from 'node:fs';
8
7
  import { resolve } from 'node:path';
8
+
9
+ import yaml from 'js-yaml';
9
10
  import pkgUp from 'pkg-up';
10
11
 
11
12
  import { invariant } from '@dxos/invariant';
12
13
  import { log } from '@dxos/log';
13
14
  import { setDeep } from '@dxos/util';
14
15
 
15
- import { type ConfigPluginOpts } from './types';
16
16
  import { mapFromKeyValues } from '../config';
17
17
 
18
+ import { type ConfigPluginOpts } from './types';
19
+
18
20
  const CWD = process.cwd();
19
21
 
20
22
  export const definitions = ({
@@ -3,4 +3,4 @@
3
3
  //
4
4
 
5
5
  export * from './definitions';
6
- export * from './types';
6
+ export type * from './types';
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  import { resolve } from 'node:path';
6
+
6
7
  import { type Plugin } from 'vite';
7
8
 
8
9
  import { definitions } from './definitions';
@@ -1,231 +0,0 @@
1
- // src/plugin/definitions.ts
2
- import yaml from "js-yaml";
3
- import { execSync } from "@dxos/node-std/child_process";
4
- import { readFileSync } from "@dxos/node-std/fs";
5
- import { resolve } from "@dxos/node-std/path";
6
- import pkgUp from "pkg-up";
7
- import { invariant } from "@dxos/invariant";
8
- import { log } from "@dxos/log";
9
- import { setDeep as setDeep2 } from "@dxos/util";
10
-
11
- // src/config.ts
12
- import { boolean } from "boolean";
13
- import defaultsDeep from "lodash.defaultsdeep";
14
- import isMatch from "lodash.ismatch";
15
- import { InvalidConfigError } from "@dxos/protocols";
16
- import { schema } from "@dxos/protocols/proto";
17
- import { trace } from "@dxos/tracing";
18
- import { getDeep, setDeep } from "@dxos/util";
19
- function _ts_decorate(decorators, target, key, desc) {
20
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
21
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
22
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
23
- return c > 3 && r && Object.defineProperty(target, key, r), r;
24
- }
25
- var configRootType = schema.getCodecForType("dxos.config.Config");
26
- var mapFromKeyValues = (spec, values) => {
27
- const config = {};
28
- for (const [key, { path, type }] of Object.entries(spec)) {
29
- let value = values[key];
30
- if (value !== void 0) {
31
- if (type) {
32
- switch (type) {
33
- case "boolean": {
34
- value = boolean(value);
35
- break;
36
- }
37
- case "number": {
38
- value = Number(value);
39
- break;
40
- }
41
- case "string": {
42
- break;
43
- }
44
- case "json": {
45
- value = value ? JSON.parse(value) : null;
46
- break;
47
- }
48
- default: {
49
- throw new Error(`Invalid type: ${type}`);
50
- }
51
- }
52
- }
53
- setDeep(config, path.split("."), value);
54
- }
55
- }
56
- return config;
57
- };
58
- var validateConfig = (config) => {
59
- if (!("version" in config)) {
60
- throw new InvalidConfigError("Version not specified");
61
- }
62
- if (config?.version !== 1) {
63
- throw new InvalidConfigError(`Invalid config version: ${config.version}`);
64
- }
65
- const error = configRootType.protoType.verify(config);
66
- if (error) {
67
- throw new InvalidConfigError(error);
68
- }
69
- return config;
70
- };
71
- var ConfigResource = Symbol.for("dxos.resource.Config");
72
- var Config = class {
73
- /**
74
- * Creates an immutable instance.
75
- * @constructor
76
- */
77
- constructor(config = {}, ...objects) {
78
- this._config = validateConfig(defaultsDeep(config, ...objects, {
79
- version: 1
80
- }));
81
- }
82
- /**
83
- * Returns an immutable config JSON object.
84
- */
85
- get values() {
86
- return this._config;
87
- }
88
- /**
89
- * Returns the given config property.
90
- *
91
- * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
92
- * @param defaultValue Default value to return if option is not present in the config.
93
- * @returns The config value or undefined if the option is not present.
94
- */
95
- get(key, defaultValue) {
96
- return getDeep(this._config, key.split(".")) ?? defaultValue;
97
- }
98
- /**
99
- * Get unique key.
100
- */
101
- find(path, test) {
102
- const values = getDeep(this._config, path.split("."));
103
- if (!Array.isArray(values)) {
104
- return;
105
- }
106
- return values.find((value) => isMatch(value, test));
107
- }
108
- /**
109
- * Returns the given config property or throw if it doesn't exist.
110
- *
111
- * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
112
- */
113
- getOrThrow(key) {
114
- const value = getDeep(this._config, key.split("."));
115
- if (!value) {
116
- throw new Error(`Config option not present: ${key}`);
117
- }
118
- return value;
119
- }
120
- };
121
- Config = _ts_decorate([
122
- trace.resource({
123
- annotation: ConfigResource
124
- })
125
- ], Config);
126
-
127
- // src/plugin/definitions.ts
128
- var __dxlog_file = "/__w/dxos/dxos/packages/sdk/config/src/plugin/definitions.ts";
129
- var CWD = process.cwd();
130
- var definitions = ({ configPath, envPath, devPath, mode = "development", publicUrl = "", env }) => {
131
- const KEYS_TO_FILE = {
132
- __CONFIG_DEFAULTS__: configPath?.length ? configPath : resolve(CWD, "dx.yml"),
133
- __CONFIG_ENVS__: envPath?.length ? envPath : resolve(CWD, "dx-env.yml")
134
- };
135
- if (mode !== "production") {
136
- KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? resolve(CWD, "dx-local.yml");
137
- }
138
- return Object.entries(KEYS_TO_FILE).reduce((prev, [key, value]) => {
139
- invariant(key, void 0, {
140
- F: __dxlog_file,
141
- L: 38,
142
- S: void 0,
143
- A: [
144
- "key",
145
- ""
146
- ]
147
- });
148
- let content = {};
149
- try {
150
- content = yaml.load(readFileSync(value, "utf-8"));
151
- if (key === "__CONFIG_ENVS__") {
152
- content = mapFromKeyValues(content, process.env);
153
- }
154
- if (key === "__CONFIG_DEFAULTS__") {
155
- Object.entries(process.env).forEach(([key2, value2]) => {
156
- if (key2.startsWith("DX_") || env?.includes(key2)) {
157
- setDeep2(content, [
158
- "runtime",
159
- "app",
160
- "env",
161
- key2
162
- ], value2);
163
- }
164
- });
165
- try {
166
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
167
- const commitHash = process.env.DX_COMMIT_HASH ?? execSync("git rev-parse --short HEAD", {
168
- encoding: "utf-8"
169
- }).replace("\n", "");
170
- const packagePath = pkgUp.sync();
171
- const packageJson = packagePath && JSON.parse(readFileSync(packagePath, "utf-8"));
172
- setDeep2(content, [
173
- "runtime",
174
- "app",
175
- "build",
176
- "timestamp"
177
- ], timestamp);
178
- setDeep2(content, [
179
- "runtime",
180
- "app",
181
- "build",
182
- "commitHash"
183
- ], commitHash);
184
- setDeep2(content, [
185
- "runtime",
186
- "app",
187
- "build",
188
- "version"
189
- ], packageJson?.version);
190
- } catch {
191
- }
192
- }
193
- } catch (err) {
194
- if (err.message.includes("YAMLException")) {
195
- log.error(`Failed to parse file ${value}:`, err, {
196
- F: __dxlog_file,
197
- L: 71,
198
- S: void 0,
199
- C: (f, a) => f(...a)
200
- });
201
- } else {
202
- log(`Failed to load file ${value}:`, err, {
203
- F: __dxlog_file,
204
- L: 73,
205
- S: void 0,
206
- C: (f, a) => f(...a)
207
- });
208
- }
209
- if (key === "__CONFIG_DEFAULTS__") {
210
- throw new Error(`Failed to load default config file from ${value}`);
211
- }
212
- }
213
- return {
214
- ...prev,
215
- [key]: content
216
- };
217
- }, {
218
- __CONFIG_DEFAULTS__: {},
219
- __CONFIG_ENVS__: {},
220
- __CONFIG_LOCAL__: {},
221
- __DXOS_CONFIG__: {
222
- dynamic: mode === "production",
223
- publicUrl
224
- }
225
- });
226
- };
227
-
228
- export {
229
- definitions
230
- };
231
- //# sourceMappingURL=chunk-AN62TER6.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/plugin/definitions.ts", "../../../src/config.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport pkgUp from 'pkg-up';\n\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { setDeep } from '@dxos/util';\n\nimport { type ConfigPluginOpts } from './types';\nimport { mapFromKeyValues } from '../config';\n\nconst CWD = process.cwd();\n\nexport const definitions = ({\n configPath,\n envPath,\n devPath,\n mode = process.env.NODE_ENV,\n publicUrl = '',\n env,\n}: ConfigPluginOpts) => {\n const KEYS_TO_FILE = {\n __CONFIG_DEFAULTS__: configPath?.length ? configPath : resolve(CWD, 'dx.yml'),\n __CONFIG_ENVS__: envPath?.length ? envPath : resolve(CWD, 'dx-env.yml'),\n } as { [key: string]: string };\n if (mode !== 'production') {\n KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? resolve(CWD, 'dx-local.yml');\n }\n\n return Object.entries(KEYS_TO_FILE).reduce(\n (prev, [key, value]) => {\n invariant(key);\n let content = {};\n try {\n content = yaml.load(readFileSync(value, 'utf-8')) as any;\n\n // Map environment variables to config values.\n if (key === '__CONFIG_ENVS__') {\n content = mapFromKeyValues(content, process.env);\n }\n\n if (key === '__CONFIG_DEFAULTS__') {\n // Load app environment variables into default config.\n Object.entries(process.env).forEach(([key, value]) => {\n if (key.startsWith('DX_') || env?.includes(key)) {\n setDeep(content, ['runtime', 'app', 'env', key], value);\n }\n });\n\n // Set build info automatically if available.\n try {\n const timestamp = new Date().toISOString();\n const commitHash =\n process.env.DX_COMMIT_HASH ??\n execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).replace('\\n', '');\n const packagePath = pkgUp.sync();\n const packageJson = packagePath && JSON.parse(readFileSync(packagePath, 'utf-8'));\n setDeep(content, ['runtime', 'app', 'build', 'timestamp'], timestamp);\n setDeep(content, ['runtime', 'app', 'build', 'commitHash'], commitHash);\n setDeep(content, ['runtime', 'app', 'build', 'version'], packageJson?.version);\n } catch {}\n }\n } catch (err: any) {\n if (err.message.includes('YAMLException')) {\n log.error(`Failed to parse file ${value}:`, err);\n } else {\n log(`Failed to load file ${value}:`, err);\n }\n\n if (key === '__CONFIG_DEFAULTS__') {\n // Default config is required.\n throw new Error(`Failed to load default config file from ${value}`);\n }\n }\n\n return {\n ...prev,\n [key]: content,\n };\n },\n {\n __CONFIG_DEFAULTS__: {},\n __CONFIG_ENVS__: {},\n __CONFIG_LOCAL__: {},\n __DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },\n },\n );\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { boolean } from 'boolean';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport isMatch from 'lodash.ismatch';\n\nimport { InvalidConfigError } from '@dxos/protocols';\nimport { schema } from '@dxos/protocols/proto';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\nimport { trace } from '@dxos/tracing';\nimport { getDeep, setDeep } from '@dxos/util';\n\nimport { type ConfigKey, type DeepIndex, type ParseKey } from './types';\n\ntype MappingSpec = Record<string, { path: string; type?: string }>;\nconst configRootType = schema.getCodecForType('dxos.config.Config');\n\n/**\n * Maps the given objects onto a flattened set of (key x values).\n *\n * Expects parsed yaml content of the form:\n *\n * ```\n * ENV_VAR:\n * path: config.selector.path\n * ```\n *\n * @param {object} spec\n * @param {object} values\n * @return {object}\n */\nexport const mapFromKeyValues = (spec: MappingSpec, values: Record<string, any>) => {\n const config = {};\n\n for (const [key, { path, type }] of Object.entries(spec)) {\n let value = values[key];\n\n if (value !== undefined) {\n if (type) {\n switch (type) {\n case 'boolean': {\n value = boolean(value);\n break;\n }\n\n case 'number': {\n value = Number(value);\n break;\n }\n\n case 'string': {\n break;\n }\n\n case 'json': {\n value = value ? JSON.parse(value) : null;\n break;\n }\n\n default: {\n throw new Error(`Invalid type: ${type}`);\n }\n }\n }\n\n setDeep(config, path.split('.'), value);\n }\n }\n\n return config;\n};\n\n/**\n * Maps the given flattend set of (key x values) onto a JSON object.\n * @param {object} spec\n * @param {object} values\n */\nexport const mapToKeyValues = (spec: MappingSpec, values: any) => {\n const config: Record<string, any> = {};\n\n for (const [key, { path, type }] of Object.entries(spec)) {\n const value = getDeep(values, path.split('.'));\n if (value !== undefined) {\n switch (type) {\n case 'json':\n config[key] = JSON.stringify(value);\n break;\n default:\n config[key] = value;\n }\n }\n }\n\n return config;\n};\n\n/**\n * Validate config object.\n */\nexport const validateConfig = (config: ConfigProto): ConfigProto => {\n if (!('version' in config)) {\n throw new InvalidConfigError('Version not specified');\n }\n\n if (config?.version !== 1) {\n throw new InvalidConfigError(`Invalid config version: ${config.version}`);\n }\n\n const error = configRootType.protoType.verify(config);\n if (error) {\n throw new InvalidConfigError(error);\n }\n\n return config;\n};\n\nexport const ConfigResource = Symbol.for('dxos.resource.Config');\n\n/**\n * Global configuration object.\n * NOTE: Config objects are immutable.\n */\n@trace.resource({ annotation: ConfigResource })\nexport class Config {\n private readonly _config: any;\n\n /**\n * Creates an immutable instance.\n * @constructor\n */\n constructor(config: ConfigProto = {}, ...objects: ConfigProto[]) {\n this._config = validateConfig(defaultsDeep(config, ...objects, { version: 1 }));\n }\n\n /**\n * Returns an immutable config JSON object.\n */\n get values(): ConfigProto {\n return this._config;\n }\n\n /**\n * Returns the given config property.\n *\n * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.\n * @param defaultValue Default value to return if option is not present in the config.\n * @returns The config value or undefined if the option is not present.\n */\n get<K extends ConfigKey>(\n key: K,\n defaultValue?: DeepIndex<ConfigProto, ParseKey<K>>,\n ): DeepIndex<ConfigProto, ParseKey<K>> | undefined {\n return getDeep(this._config, key.split('.')) ?? defaultValue;\n }\n\n /**\n * Get unique key.\n */\n find<T = any>(path: string, test: object): T | undefined {\n const values = getDeep(this._config, path.split('.'));\n if (!Array.isArray(values)) {\n return;\n }\n\n return values.find((value) => isMatch(value, test));\n }\n\n /**\n * Returns the given config property or throw if it doesn't exist.\n *\n * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.\n */\n getOrThrow<K extends ConfigKey>(key: K): Exclude<DeepIndex<ConfigProto, ParseKey<K>>, undefined> {\n const value: DeepIndex<ConfigProto, ParseKey<K>> | undefined = getDeep(this._config, key.split('.'));\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n"],
5
- "mappings": ";AAIA,OAAOA,UAAU;AACjB,SAASC,gBAAgB;AACzB,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AACxB,OAAOC,WAAW;AAElB,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AACpB,SAASC,WAAAA,gBAAe;;;ACRxB,SAASC,eAAe;AACxB,OAAOC,kBAAkB;AACzB,OAAOC,aAAa;AAEpB,SAASC,0BAA0B;AACnC,SAASC,cAAc;AAEvB,SAASC,aAAa;AACtB,SAASC,SAASC,eAAe;;;;;;;AAKjC,IAAMC,iBAAiBC,OAAOC,gBAAgB,oBAAA;AAgBvC,IAAMC,mBAAmB,CAACC,MAAmBC,WAAAA;AAClD,QAAMC,SAAS,CAAC;AAEhB,aAAW,CAACC,KAAK,EAAEC,MAAMC,KAAI,CAAE,KAAKC,OA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AAA,KAAUpB,KAAKqB,SAASV,IAAAA,GAAM;AAC/CW,YAAAA,SAAQR,SAAS;cAAC;cAAW;cAAO;cAAOH;eAAMC,MAAAA;UACnD;QACF,CAAA;AAGA,YAAI;AACF,gBAAMW,aAAY,oBAAIC,KAAAA,GAAOC,YAAW;AACxC,gBAAMC,aACJlC,QAAQQ,IAAI2B,kBACZC,SAAS,8BAA8B;YAAEC,UAAU;UAAQ,CAAA,EAAGC,QAAQ,MAAM,EAAA;AAC9E,gBAAMC,cAAcC,MAAMC,KAAI;AAC9B,gBAAMC,cAAcH,eAAeI,KAAKC,MAAMnB,aAAac,aAAa,OAAA,CAAA;AACxET,UAAAA,SAAQR,SAAS;YAAC;YAAW;YAAO;YAAS;aAAcS,SAAAA;AAC3DD,UAAAA,SAAQR,SAAS;YAAC;YAAW;YAAO;YAAS;aAAeY,UAAAA;AAC5DJ,UAAAA,SAAQR,SAAS;YAAC;YAAW;YAAO;YAAS;aAAYoB,aAAaG,OAAAA;QACxE,QAAQ;QAAC;MACX;IACF,SAASC,KAAU;AACjB,UAAIA,IAAIC,QAAQlB,SAAS,eAAA,GAAkB;AACzCmB,YAAIC,MAAM,wBAAwB7B,KAAAA,KAAU0B,KAAAA;;;;;;MAC9C,OAAO;AACLE,YAAI,uBAAuB5B,KAAAA,KAAU0B,KAAAA;;;;;;MACvC;AAEA,UAAI3B,QAAQ,uBAAuB;AAEjC,cAAM,IAAI+B,MAAM,2CAA2C9B,KAAAA,EAAO;MACpE;IACF;AAEA,WAAO;MACL,GAAGF;MACH,CAACC,GAAAA,GAAMG;IACT;EACF,GACA;IACEZ,qBAAqB,CAAC;IACtBG,iBAAiB,CAAC;IAClBC,kBAAkB,CAAC;IACnBqC,iBAAiB;MAAEC,SAAS9C,SAAS;MAAcC;IAAU;EAC/D,CAAA;AAEJ;",
6
- "names": ["yaml", "execSync", "readFileSync", "resolve", "pkgUp", "invariant", "log", "setDeep", "boolean", "defaultsDeep", "isMatch", "InvalidConfigError", "schema", "trace", "getDeep", "setDeep", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "setDeep", "split", "validateConfig", "config", "InvalidConfigError", "version", "error", "configRootType", "protoType", "verify", "ConfigResource", "Symbol", "for", "Config", "objects", "_config", "defaultsDeep", "values", "get", "key", "defaultValue", "getDeep", "split", "find", "path", "test", "Array", "isArray", "value", "isMatch", "getOrThrow", "Error", "resource", "annotation", "CWD", "process", "cwd", "definitions", "configPath", "envPath", "devPath", "mode", "publicUrl", "env", "KEYS_TO_FILE", "__CONFIG_DEFAULTS__", "length", "resolve", "__CONFIG_ENVS__", "__CONFIG_LOCAL__", "Object", "entries", "reduce", "prev", "key", "value", "invariant", "content", "yaml", "load", "readFileSync", "mapFromKeyValues", "forEach", "startsWith", "includes", "setDeep", "timestamp", "Date", "toISOString", "commitHash", "DX_COMMIT_HASH", "execSync", "encoding", "replace", "packagePath", "pkgUp", "sync", "packageJson", "JSON", "parse", "version", "err", "message", "log", "error", "Error", "__DXOS_CONFIG__", "dynamic"]
7
- }
@@ -1,25 +0,0 @@
1
- import {
2
- definitions
3
- } from "./chunk-AN62TER6.mjs";
4
-
5
- // src/plugin/esbuild-plugin.ts
6
- var ConfigPlugin = (options = {}) => {
7
- return {
8
- name: "dxos-config",
9
- setup: ({ initialOptions }) => {
10
- const esbuildOptions = initialOptions;
11
- esbuildOptions.define ||= {};
12
- Object.entries(definitions({
13
- ...options,
14
- mode: "development"
15
- })).reduce((define, [key, value]) => {
16
- define[key] = JSON.stringify(value);
17
- return define;
18
- }, esbuildOptions.define);
19
- }
20
- };
21
- };
22
- export {
23
- ConfigPlugin
24
- };
25
- //# sourceMappingURL=esbuild-plugin.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/plugin/esbuild-plugin.ts"],
4
- "sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nimport type { Plugin } from 'esbuild';\n\nimport { definitions } from './definitions';\nimport { type ConfigPluginOpts } from './types';\n\nexport const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => {\n return {\n name: 'dxos-config',\n setup: ({ initialOptions }) => {\n const esbuildOptions = initialOptions;\n esbuildOptions.define ||= {};\n\n Object.entries(definitions({ ...options, mode: process.env.NODE_ENV })).reduce((define, [key, value]) => {\n define[key] = JSON.stringify(value);\n return define;\n }, esbuildOptions.define);\n },\n };\n};\n"],
5
- "mappings": ";;;;;AASO,IAAMA,eAAe,CAACC,UAA4B,CAAC,MAAC;AACzD,SAAO;IACLC,MAAM;IACNC,OAAO,CAAC,EAAEC,eAAc,MAAE;AACxB,YAAMC,iBAAiBD;AACvBC,qBAAeC,WAAW,CAAC;AAE3BC,aAAOC,QAAQC,YAAY;QAAE,GAAGR;QAASS,MAAMC;MAAqB,CAAA,CAAA,EAAIC,OAAO,CAACN,QAAQ,CAACO,KAAKC,KAAAA,MAAM;AAClGR,eAAOO,GAAAA,IAAOE,KAAKC,UAAUF,KAAAA;AAC7B,eAAOR;MACT,GAAGD,eAAeC,MAAM;IAC1B;EACF;AACF;",
6
- "names": ["ConfigPlugin", "options", "name", "setup", "initialOptions", "esbuildOptions", "define", "Object", "entries", "definitions", "mode", "process", "reduce", "key", "value", "JSON", "stringify"]
7
- }
@@ -1 +0,0 @@
1
- {"inputs":{"src/config.ts":{"bytes":15734,"imports":[{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.ismatch","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"@dxos/tracing","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/plugin/definitions.ts":{"bytes":12061,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"@dxos/node-std/child_process","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/config.ts","kind":"import-statement","original":"../config"}],"format":"esm"},"src/plugin/esbuild-plugin.ts":{"bytes":2571,"imports":[{"path":"src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"},"src/plugin/rollup-plugin.ts":{"bytes":2055,"imports":[{"path":"src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"},"src/plugin/vite-plugin.ts":{"bytes":3666,"imports":[{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"}},"outputs":{"dist/plugin/browser/esbuild-plugin.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1316},"dist/plugin/browser/esbuild-plugin.mjs":{"imports":[{"path":"dist/plugin/browser/chunk-AN62TER6.mjs","kind":"import-statement"}],"exports":["ConfigPlugin"],"entryPoint":"src/plugin/esbuild-plugin.ts","inputs":{"src/plugin/esbuild-plugin.ts":{"bytesInOutput":436}},"bytes":594},"dist/plugin/browser/rollup-plugin.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1072},"dist/plugin/browser/rollup-plugin.mjs":{"imports":[{"path":"dist/plugin/browser/chunk-AN62TER6.mjs","kind":"import-statement"}],"exports":["ConfigPlugin"],"entryPoint":"src/plugin/rollup-plugin.ts","inputs":{"src/plugin/rollup-plugin.ts":{"bytesInOutput":281}},"bytes":437},"dist/plugin/browser/vite-plugin.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1835},"dist/plugin/browser/vite-plugin.mjs":{"imports":[{"path":"dist/plugin/browser/chunk-AN62TER6.mjs","kind":"import-statement"},{"path":"@dxos/node-std/path","kind":"import-statement","external":true}],"exports":["ConfigPlugin"],"entryPoint":"src/plugin/vite-plugin.ts","inputs":{"src/plugin/vite-plugin.ts":{"bytesInOutput":684}},"bytes":836},"dist/plugin/browser/chunk-AN62TER6.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":13091},"dist/plugin/browser/chunk-AN62TER6.mjs":{"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"@dxos/node-std/child_process","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.ismatch","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"@dxos/tracing","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["definitions"],"inputs":{"src/plugin/definitions.ts":{"bytesInOutput":3234},"src/config.ts":{"bytesInOutput":3576}},"bytes":6958}}}
@@ -1,19 +0,0 @@
1
- import {
2
- definitions
3
- } from "./chunk-AN62TER6.mjs";
4
-
5
- // src/plugin/rollup-plugin.ts
6
- var ConfigPlugin = (options = {}) => {
7
- const contents = Object.entries(definitions({
8
- ...options,
9
- mode: "development"
10
- })).map(([key, value]) => `globalThis.${key} = ${JSON.stringify(value)};`).join("\n");
11
- return {
12
- name: "dxos-config",
13
- banner: contents
14
- };
15
- };
16
- export {
17
- ConfigPlugin
18
- };
19
- //# sourceMappingURL=rollup-plugin.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/plugin/rollup-plugin.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type Plugin } from 'rollup';\n\nimport { definitions } from './definitions';\nimport { type ConfigPluginOpts } from './types';\n\nexport const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => {\n const contents = Object.entries(definitions({ ...options, mode: process.env.NODE_ENV }))\n .map(([key, value]) => `globalThis.${key} = ${JSON.stringify(value)};`)\n .join('\\n');\n\n return {\n name: 'dxos-config',\n banner: contents,\n };\n};\n"],
5
- "mappings": ";;;;;AASO,IAAMA,eAAe,CAACC,UAA4B,CAAC,MAAC;AACzD,QAAMC,WAAWC,OAAOC,QAAQC,YAAY;IAAE,GAAGJ;IAASK,MAAMC;EAAqB,CAAA,CAAA,EAClFC,IAAI,CAAC,CAACC,KAAKC,KAAAA,MAAW,cAAcD,GAAAA,MAASE,KAAKC,UAAUF,KAAAA,CAAAA,GAAS,EACrEG,KAAK,IAAA;AAER,SAAO;IACLC,MAAM;IACNC,QAAQb;EACV;AACF;",
6
- "names": ["ConfigPlugin", "options", "contents", "Object", "entries", "definitions", "mode", "process", "map", "key", "value", "JSON", "stringify", "join", "name", "banner"]
7
- }
@@ -1,30 +0,0 @@
1
- import {
2
- definitions
3
- } from "./chunk-AN62TER6.mjs";
4
-
5
- // src/plugin/vite-plugin.ts
6
- import { resolve } from "@dxos/node-std/path";
7
- var ConfigPlugin = (options = {}) => ({
8
- name: "dxos-config",
9
- config: () => {
10
- const configPath = options.root && resolve(options.root, options.configPath ?? "dx.yml");
11
- const envPath = options.root && resolve(options.root, options.envPath ?? "dx-env.yml");
12
- const devPath = options.root && resolve(options.root, options.devPath ?? "dx-local.yml");
13
- const define = Object.entries(definitions({
14
- ...options,
15
- configPath,
16
- envPath,
17
- devPath
18
- })).reduce((define2, [key, value]) => {
19
- define2[key] = JSON.stringify(value);
20
- return define2;
21
- }, {});
22
- return {
23
- define
24
- };
25
- }
26
- });
27
- export {
28
- ConfigPlugin
29
- };
30
- //# sourceMappingURL=vite-plugin.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/plugin/vite-plugin.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { resolve } from 'node:path';\nimport { type Plugin } from 'vite';\n\nimport { definitions } from './definitions';\nimport { type ConfigPluginOpts } from './types';\n\nexport const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => ({\n name: 'dxos-config',\n config: () => {\n // Update paths.\n const configPath = options.root && resolve(options.root, options.configPath ?? 'dx.yml');\n const envPath = options.root && resolve(options.root, options.envPath ?? 'dx-env.yml');\n // TODO(burdon): Change to dx-dev.yml?\n const devPath = options.root && resolve(options.root, options.devPath ?? 'dx-local.yml');\n\n const define = Object.entries(definitions({ ...options, configPath, envPath, devPath })).reduce(\n (define, [key, value]) => {\n define[key] = JSON.stringify(value);\n return define;\n },\n {} as { [key: string]: string },\n );\n\n return { define };\n },\n});\n"],
5
- "mappings": ";;;;;AAIA,SAASA,eAAe;AAMjB,IAAMC,eAAe,CAACC,UAA4B,CAAC,OAAe;EACvEC,MAAM;EACNC,QAAQ,MAAA;AAEN,UAAMC,aAAaH,QAAQI,QAAQC,QAAQL,QAAQI,MAAMJ,QAAQG,cAAc,QAAA;AAC/E,UAAMG,UAAUN,QAAQI,QAAQC,QAAQL,QAAQI,MAAMJ,QAAQM,WAAW,YAAA;AAEzE,UAAMC,UAAUP,QAAQI,QAAQC,QAAQL,QAAQI,MAAMJ,QAAQO,WAAW,cAAA;AAEzE,UAAMC,SAASC,OAAOC,QAAQC,YAAY;MAAE,GAAGX;MAASG;MAAYG;MAASC;IAAQ,CAAA,CAAA,EAAIK,OACvF,CAACJ,SAAQ,CAACK,KAAKC,KAAAA,MAAM;AACnBN,MAAAA,QAAOK,GAAAA,IAAOE,KAAKC,UAAUF,KAAAA;AAC7B,aAAON;IACT,GACA,CAAC,CAAA;AAGH,WAAO;MAAEA;IAAO;EAClB;AACF;",
6
- "names": ["resolve", "ConfigPlugin", "options", "name", "config", "configPath", "root", "resolve", "envPath", "devPath", "define", "Object", "entries", "definitions", "reduce", "key", "value", "JSON", "stringify"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/plugin/definitions.ts", "../../../src/config.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport pkgUp from 'pkg-up';\n\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { setDeep } from '@dxos/util';\n\nimport { type ConfigPluginOpts } from './types';\nimport { mapFromKeyValues } from '../config';\n\nconst CWD = process.cwd();\n\nexport const definitions = ({\n configPath,\n envPath,\n devPath,\n mode = process.env.NODE_ENV,\n publicUrl = '',\n env,\n}: ConfigPluginOpts) => {\n const KEYS_TO_FILE = {\n __CONFIG_DEFAULTS__: configPath?.length ? configPath : resolve(CWD, 'dx.yml'),\n __CONFIG_ENVS__: envPath?.length ? envPath : resolve(CWD, 'dx-env.yml'),\n } as { [key: string]: string };\n if (mode !== 'production') {\n KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? resolve(CWD, 'dx-local.yml');\n }\n\n return Object.entries(KEYS_TO_FILE).reduce(\n (prev, [key, value]) => {\n invariant(key);\n let content = {};\n try {\n content = yaml.load(readFileSync(value, 'utf-8')) as any;\n\n // Map environment variables to config values.\n if (key === '__CONFIG_ENVS__') {\n content = mapFromKeyValues(content, process.env);\n }\n\n if (key === '__CONFIG_DEFAULTS__') {\n // Load app environment variables into default config.\n Object.entries(process.env).forEach(([key, value]) => {\n if (key.startsWith('DX_') || env?.includes(key)) {\n setDeep(content, ['runtime', 'app', 'env', key], value);\n }\n });\n\n // Set build info automatically if available.\n try {\n const timestamp = new Date().toISOString();\n const commitHash =\n process.env.DX_COMMIT_HASH ??\n execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).replace('\\n', '');\n const packagePath = pkgUp.sync();\n const packageJson = packagePath && JSON.parse(readFileSync(packagePath, 'utf-8'));\n setDeep(content, ['runtime', 'app', 'build', 'timestamp'], timestamp);\n setDeep(content, ['runtime', 'app', 'build', 'commitHash'], commitHash);\n setDeep(content, ['runtime', 'app', 'build', 'version'], packageJson?.version);\n } catch {}\n }\n } catch (err: any) {\n if (err.message.includes('YAMLException')) {\n log.error(`Failed to parse file ${value}:`, err);\n } else {\n log(`Failed to load file ${value}:`, err);\n }\n\n if (key === '__CONFIG_DEFAULTS__') {\n // Default config is required.\n throw new Error(`Failed to load default config file from ${value}`);\n }\n }\n\n return {\n ...prev,\n [key]: content,\n };\n },\n {\n __CONFIG_DEFAULTS__: {},\n __CONFIG_ENVS__: {},\n __CONFIG_LOCAL__: {},\n __DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },\n },\n );\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { boolean } from 'boolean';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport isMatch from 'lodash.ismatch';\n\nimport { InvalidConfigError } from '@dxos/protocols';\nimport { schema } from '@dxos/protocols/proto';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\nimport { trace } from '@dxos/tracing';\nimport { getDeep, setDeep } from '@dxos/util';\n\nimport { type ConfigKey, type DeepIndex, type ParseKey } from './types';\n\ntype MappingSpec = Record<string, { path: string; type?: string }>;\nconst configRootType = schema.getCodecForType('dxos.config.Config');\n\n/**\n * Maps the given objects onto a flattened set of (key x values).\n *\n * Expects parsed yaml content of the form:\n *\n * ```\n * ENV_VAR:\n * path: config.selector.path\n * ```\n *\n * @param {object} spec\n * @param {object} values\n * @return {object}\n */\nexport const mapFromKeyValues = (spec: MappingSpec, values: Record<string, any>) => {\n const config = {};\n\n for (const [key, { path, type }] of Object.entries(spec)) {\n let value = values[key];\n\n if (value !== undefined) {\n if (type) {\n switch (type) {\n case 'boolean': {\n value = boolean(value);\n break;\n }\n\n case 'number': {\n value = Number(value);\n break;\n }\n\n case 'string': {\n break;\n }\n\n case 'json': {\n value = value ? JSON.parse(value) : null;\n break;\n }\n\n default: {\n throw new Error(`Invalid type: ${type}`);\n }\n }\n }\n\n setDeep(config, path.split('.'), value);\n }\n }\n\n return config;\n};\n\n/**\n * Maps the given flattend set of (key x values) onto a JSON object.\n * @param {object} spec\n * @param {object} values\n */\nexport const mapToKeyValues = (spec: MappingSpec, values: any) => {\n const config: Record<string, any> = {};\n\n for (const [key, { path, type }] of Object.entries(spec)) {\n const value = getDeep(values, path.split('.'));\n if (value !== undefined) {\n switch (type) {\n case 'json':\n config[key] = JSON.stringify(value);\n break;\n default:\n config[key] = value;\n }\n }\n }\n\n return config;\n};\n\n/**\n * Validate config object.\n */\nexport const validateConfig = (config: ConfigProto): ConfigProto => {\n if (!('version' in config)) {\n throw new InvalidConfigError('Version not specified');\n }\n\n if (config?.version !== 1) {\n throw new InvalidConfigError(`Invalid config version: ${config.version}`);\n }\n\n const error = configRootType.protoType.verify(config);\n if (error) {\n throw new InvalidConfigError(error);\n }\n\n return config;\n};\n\nexport const ConfigResource = Symbol.for('dxos.resource.Config');\n\n/**\n * Global configuration object.\n * NOTE: Config objects are immutable.\n */\n@trace.resource({ annotation: ConfigResource })\nexport class Config {\n private readonly _config: any;\n\n /**\n * Creates an immutable instance.\n * @constructor\n */\n constructor(config: ConfigProto = {}, ...objects: ConfigProto[]) {\n this._config = validateConfig(defaultsDeep(config, ...objects, { version: 1 }));\n }\n\n /**\n * Returns an immutable config JSON object.\n */\n get values(): ConfigProto {\n return this._config;\n }\n\n /**\n * Returns the given config property.\n *\n * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.\n * @param defaultValue Default value to return if option is not present in the config.\n * @returns The config value or undefined if the option is not present.\n */\n get<K extends ConfigKey>(\n key: K,\n defaultValue?: DeepIndex<ConfigProto, ParseKey<K>>,\n ): DeepIndex<ConfigProto, ParseKey<K>> | undefined {\n return getDeep(this._config, key.split('.')) ?? defaultValue;\n }\n\n /**\n * Get unique key.\n */\n find<T = any>(path: string, test: object): T | undefined {\n const values = getDeep(this._config, path.split('.'));\n if (!Array.isArray(values)) {\n return;\n }\n\n return values.find((value) => isMatch(value, test));\n }\n\n /**\n * Returns the given config property or throw if it doesn't exist.\n *\n * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.\n */\n getOrThrow<K extends ConfigKey>(key: K): Exclude<DeepIndex<ConfigProto, ParseKey<K>>, undefined> {\n const value: DeepIndex<ConfigProto, ParseKey<K>> | undefined = getDeep(this._config, key.split('.'));\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n"],
5
- "mappings": ";;;AAIA,OAAOA,UAAU;AACjB,SAASC,gBAAgB;AACzB,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AACxB,OAAOC,WAAW;AAElB,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AACpB,SAASC,WAAAA,gBAAe;;;ACRxB,SAASC,eAAe;AACxB,OAAOC,kBAAkB;AACzB,OAAOC,aAAa;AAEpB,SAASC,0BAA0B;AACnC,SAASC,cAAc;AAEvB,SAASC,aAAa;AACtB,SAASC,SAASC,eAAe;;;;;;;AAKjC,IAAMC,iBAAiBC,OAAOC,gBAAgB,oBAAA;AAgBvC,IAAMC,mBAAmB,CAACC,MAAmBC,WAAAA;AAClD,QAAMC,SAAS,CAAC;AAEhB,aAAW,CAACC,KAAK,EAAEC,MAAMC,KAAI,CAAE,KAAKC,OAAOC,QAAQP,IAAAA,GAAO;AACxD,QAAIQ,QAAQP,OAAOE,GAAAA;AAEnB,QAAIK,UAAUC,QAAW;AACvB,UAAIJ,MAAM;AACR,gBAAQA,MAAAA;UACN,KAAK,WAAW;AACdG,oBAAQE,QAAQF,KAAAA;AAChB;UACF;UAEA,KAAK,UAAU;AACbA,oBAAQG,OAAOH,KAAAA;AACf;UACF;UAEA,KAAK,UAAU;AACb;UACF;UAEA,KAAK,QAAQ;AACXA,oBAAQA,QAAQI,KAAKC,MAAML,KAAAA,IAAS;AACpC;U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I;AAC9B,gBAAMC,cAAcH,eAAeI,KAAKC,MAAMnB,aAAac,aAAa,OAAA,CAAA;AACxET,UAAAA,SAAQR,SAAS;YAAC;YAAW;YAAO;YAAS;aAAcS,SAAAA;AAC3DD,UAAAA,SAAQR,SAAS;YAAC;YAAW;YAAO;YAAS;aAAeY,UAAAA;AAC5DJ,UAAAA,SAAQR,SAAS;YAAC;YAAW;YAAO;YAAS;aAAYoB,aAAaG,OAAAA;QACxE,QAAQ;QAAC;MACX;IACF,SAASC,KAAU;AACjB,UAAIA,IAAIC,QAAQlB,SAAS,eAAA,GAAkB;AACzCmB,YAAIC,MAAM,wBAAwB7B,KAAAA,KAAU0B,KAAAA;;;;;;MAC9C,OAAO;AACLE,YAAI,uBAAuB5B,KAAAA,KAAU0B,KAAAA;;;;;;MACvC;AAEA,UAAI3B,QAAQ,uBAAuB;AAEjC,cAAM,IAAI+B,MAAM,2CAA2C9B,KAAAA,EAAO;MACpE;IACF;AAEA,WAAO;MACL,GAAGF;MACH,CAACC,GAAAA,GAAMG;IACT;EACF,GACA;IACEZ,qBAAqB,CAAC;IACtBG,iBAAiB,CAAC;IAClBC,kBAAkB,CAAC;IACnBqC,iBAAiB;MAAEC,SAAS/C,SAAS;MAAcG;IAAU;EAC/D,CAAA;AAEJ;",
6
- "names": ["yaml", "execSync", "readFileSync", "resolve", "pkgUp", "invariant", "log", "setDeep", "boolean", "defaultsDeep", "isMatch", "InvalidConfigError", "schema", "trace", "getDeep", "setDeep", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "setDeep", "split", "validateConfig", "config", "InvalidConfigError", "version", "error", "configRootType", "protoType", "verify", "ConfigResource", "Symbol", "for", "Config", "objects", "_config", "defaultsDeep", "values", "get", "key", "defaultValue", "getDeep", "split", "find", "path", "test", "Array", "isArray", "value", "isMatch", "getOrThrow", "Error", "resource", "annotation", "CWD", "process", "cwd", "definitions", "configPath", "envPath", "devPath", "mode", "env", "NODE_ENV", "publicUrl", "KEYS_TO_FILE", "__CONFIG_DEFAULTS__", "length", "resolve", "__CONFIG_ENVS__", "__CONFIG_LOCAL__", "Object", "entries", "reduce", "prev", "key", "value", "invariant", "content", "yaml", "load", "readFileSync", "mapFromKeyValues", "forEach", "startsWith", "includes", "setDeep", "timestamp", "Date", "toISOString", "commitHash", "DX_COMMIT_HASH", "execSync", "encoding", "replace", "packagePath", "pkgUp", "sync", "packageJson", "JSON", "parse", "version", "err", "message", "log", "error", "Error", "__DXOS_CONFIG__", "dynamic"]
7
- }