@dxos/config 0.4.9 → 0.4.10-main.06ef97a
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/dist/lib/browser/index.mjs +20 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +19 -0
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/plugin/node/{chunk-LSZOKWT5.cjs → chunk-XX2MVHOV.cjs} +91 -4
- package/dist/plugin/node/chunk-XX2MVHOV.cjs.map +7 -0
- package/dist/plugin/node/esbuild-plugin.cjs +2 -2
- package/dist/plugin/node/meta.json +1 -1
- package/dist/plugin/node/rollup-plugin.cjs +2 -2
- package/dist/plugin/node/vite-plugin.cjs +2 -2
- package/dist/types/src/config.d.ts +1 -0
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/src/loaders/browser.d.ts.map +1 -1
- package/package.json +5 -4
- package/dist/plugin/node/chunk-LSZOKWT5.cjs.map +0 -7
|
@@ -8,6 +8,17 @@ import get from "lodash.get";
|
|
|
8
8
|
import isMatch from "lodash.ismatch";
|
|
9
9
|
import set from "lodash.set";
|
|
10
10
|
import { InvalidConfigError, schema } from "@dxos/protocols";
|
|
11
|
+
import { trace } from "@dxos/tracing";
|
|
12
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
13
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
15
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
else
|
|
17
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
18
|
+
if (d = decorators[i])
|
|
19
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
20
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
|
+
}
|
|
11
22
|
var configRootType = schema.getCodecForType("dxos.config.Config");
|
|
12
23
|
var mapFromKeyValues = (spec, values) => {
|
|
13
24
|
const config = {};
|
|
@@ -70,6 +81,7 @@ var validateConfig = (config) => {
|
|
|
70
81
|
}
|
|
71
82
|
return config;
|
|
72
83
|
};
|
|
84
|
+
var ConfigResource = Symbol.for("dxos.resource.Config");
|
|
73
85
|
var Config = class {
|
|
74
86
|
/**
|
|
75
87
|
* Creates an immutable instance.
|
|
@@ -127,8 +139,14 @@ var Config = class {
|
|
|
127
139
|
return value;
|
|
128
140
|
}
|
|
129
141
|
};
|
|
142
|
+
Config = _ts_decorate([
|
|
143
|
+
trace.resource({
|
|
144
|
+
annotation: ConfigResource
|
|
145
|
+
})
|
|
146
|
+
], Config);
|
|
130
147
|
|
|
131
148
|
// packages/sdk/config/src/loaders/browser.js
|
|
149
|
+
import localforage from "localforage";
|
|
132
150
|
import { log } from "@dxos/log";
|
|
133
151
|
var CONFIG_ENDPOINT = "/.well-known/dx/config";
|
|
134
152
|
var Local = () => {
|
|
@@ -152,18 +170,14 @@ var Envs = () => {
|
|
|
152
170
|
var Defaults = () => {
|
|
153
171
|
return __CONFIG_DEFAULTS__;
|
|
154
172
|
};
|
|
155
|
-
var localforage = null;
|
|
156
173
|
var Storage = async () => {
|
|
157
174
|
try {
|
|
158
|
-
if (!localforage) {
|
|
159
|
-
localforage = await import("localforage");
|
|
160
|
-
}
|
|
161
175
|
const config = await localforage.getItem("dxos.org/settings/config");
|
|
162
176
|
if (config) {
|
|
163
177
|
return config;
|
|
164
178
|
}
|
|
165
179
|
} catch (err) {
|
|
166
|
-
log("Failed to load config", { err });
|
|
180
|
+
log.warn("Failed to load config", { err });
|
|
167
181
|
}
|
|
168
182
|
return {};
|
|
169
183
|
};
|
|
@@ -194,6 +208,7 @@ var FILE_ENVS = "envs-map.yml";
|
|
|
194
208
|
var FILE_DYNAMICS = "config.yml";
|
|
195
209
|
export {
|
|
196
210
|
Config,
|
|
211
|
+
ConfigResource,
|
|
197
212
|
Defaults,
|
|
198
213
|
Dynamics,
|
|
199
214
|
Envs,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/config.ts", "../../../src/loaders/browser.js", "../../../src/savers/browser.js", "../../../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\n// TODO(burdon): Why is this exported? (Rename).\nexport * as defs from '@dxos/protocols/proto/dxos/config';\n\nexport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport * from './config';\nexport * from './loaders';\nexport * from './savers';\nexport * from './plugin';\nexport * from './types';\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { boolean } from 'boolean';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport get from 'lodash.get';\nimport isMatch from 'lodash.ismatch';\nimport set from 'lodash.set';\n\nimport { InvalidConfigError, schema } from '@dxos/protocols';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\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 set(config, path, 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 = get(values, path);\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\n/**\n * Global configuration object.\n * NOTE: Config objects are immutable.\n */\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>> {\n return get(this._config, key, defaultValue);\n }\n\n /**\n * Get unique key.\n */\n find<T = any>(path: string, test: object): T | undefined {\n const values = get(this._config, path);\n if (!Array.isArray(values)) {\n return;\n }\n\n return values.find((value) => isMatch(value, test));\n }\n\n /**\n * Returns config key without type checking.\n *\n * @deprecated Use the type-checked version.\n */\n getUnchecked<T>(key: string, defaultValue?: T): T {\n return get(this._config, key, defaultValue);\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 = get(this._config, key);\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n", "//\n// Copyright 2021 DXOS.org\n//\n\n/* THIS FILE WILL BE LOADED BY CONTEXT REPLACEMENT PLUGIN IN BROWSER ENVS. */\n\n/* global __DXOS_CONFIG__ __CONFIG_ENVS__ __CONFIG_DEFAULTS__ __CONFIG_LOCAL__ */\n\nimport { log } from '@dxos/log';\n\nconst CONFIG_ENDPOINT = '/.well-known/dx/config';\n\nexport const Local = () => {\n return __CONFIG_LOCAL__;\n};\n\nexport const Dynamics = async () => {\n const { publicUrl = '', dynamic } = __DXOS_CONFIG__;\n if (!dynamic) {\n log('dynamics disabled');\n return {};\n }\n\n log('fetching config...', { publicUrl });\n return await fetch(`${publicUrl}${CONFIG_ENDPOINT}`)\n .then((res) => res.json())\n .catch((error) => {\n log.warn('Failed to fetch dynamic config.', error);\n return {};\n });\n};\n\nexport const Envs = () => {\n return __CONFIG_ENVS__;\n};\n\nexport const Defaults = () => {\n return __CONFIG_DEFAULTS__;\n};\n\
|
|
5
|
-
"mappings": ";AAKA,YAAYA,UAAU;;;ACDtB,SAASC,eAAe;AACxB,OAAOC,kBAAkB;AACzB,OAAOC,SAAS;AAChB,OAAOC,aAAa;AACpB,OAAOC,SAAS;AAEhB,SAASC,oBAAoBC,cAAc;
|
|
6
|
-
"names": ["defs", "boolean", "defaultsDeep", "get", "isMatch", "set", "InvalidConfigError", "schema", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "set", "mapToKeyValues", "get", "stringify", "validateConfig", "InvalidConfigError", "version", "error", "protoType", "verify", "Config", "constructor", "objects", "_config", "defaultsDeep", "defaultValue", "find", "test", "Array", "isArray", "isMatch", "getUnchecked", "getOrThrow", "localforage", "log", "FILE_DEFAULTS", "FILE_ENVS", "FILE_DYNAMICS"]
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\n// TODO(burdon): Why is this exported? (Rename).\nexport * as defs from '@dxos/protocols/proto/dxos/config';\n\nexport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport * from './config';\nexport * from './loaders';\nexport * from './savers';\nexport * from './plugin';\nexport * from './types';\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { boolean } from 'boolean';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport get from 'lodash.get';\nimport isMatch from 'lodash.ismatch';\nimport set from 'lodash.set';\n\nimport { InvalidConfigError, schema } from '@dxos/protocols';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\nimport { trace } from '@dxos/tracing';\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 set(config, path, 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 = get(values, path);\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>> {\n return get(this._config, key, defaultValue);\n }\n\n /**\n * Get unique key.\n */\n find<T = any>(path: string, test: object): T | undefined {\n const values = get(this._config, path);\n if (!Array.isArray(values)) {\n return;\n }\n\n return values.find((value) => isMatch(value, test));\n }\n\n /**\n * Returns config key without type checking.\n *\n * @deprecated Use the type-checked version.\n */\n getUnchecked<T>(key: string, defaultValue?: T): T {\n return get(this._config, key, defaultValue);\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 = get(this._config, key);\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n", "//\n// Copyright 2021 DXOS.org\n//\n\n/* THIS FILE WILL BE LOADED BY CONTEXT REPLACEMENT PLUGIN IN BROWSER ENVS. */\n\n/* global __DXOS_CONFIG__ __CONFIG_ENVS__ __CONFIG_DEFAULTS__ __CONFIG_LOCAL__ */\n\nimport localforage from 'localforage';\n\nimport { log } from '@dxos/log';\n\nconst CONFIG_ENDPOINT = '/.well-known/dx/config';\n\nexport const Local = () => {\n return __CONFIG_LOCAL__;\n};\n\nexport const Dynamics = async () => {\n const { publicUrl = '', dynamic } = __DXOS_CONFIG__;\n if (!dynamic) {\n log('dynamics disabled');\n return {};\n }\n\n log('fetching config...', { publicUrl });\n return await fetch(`${publicUrl}${CONFIG_ENDPOINT}`)\n .then((res) => res.json())\n .catch((error) => {\n log.warn('Failed to fetch dynamic config.', error);\n return {};\n });\n};\n\nexport const Envs = () => {\n return __CONFIG_ENVS__;\n};\n\nexport const Defaults = () => {\n return __CONFIG_DEFAULTS__;\n};\n\n/**\n * Settings config from browser storage.\n */\nexport const Storage = async () => {\n try {\n const config = await localforage.getItem('dxos.org/settings/config');\n if (config) {\n return config;\n }\n } catch (err) {\n log.warn('Failed to load config', { err });\n }\n return {};\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\n/* THIS FILE WILL BE LOADED BY CONTEXT REPLACEMENT PLUGIN IN BROWSER ENVS. */\n\nimport localforage from 'localforage';\n\nimport { log } from '@dxos/log';\n\nlet PERFORMING_CONFIG_SAVE = false;\n\nexport const SaveConfig = async (config) => {\n if (PERFORMING_CONFIG_SAVE) {\n log.warn('Already performing config save');\n return;\n }\n PERFORMING_CONFIG_SAVE = true;\n\n try {\n await localforage.setItem('dxos.org/settings/config', config);\n } catch (err) {\n log.warn('Failed to save config', { err });\n return {};\n } finally {\n PERFORMING_CONFIG_SAVE = false;\n }\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport const FILE_DEFAULTS = 'defaults.yml';\nexport const FILE_ENVS = 'envs-map.yml';\nexport const FILE_DYNAMICS = 'config.yml';\n\ntype DotPrefix<T extends string> = T extends '' ? '' : `.${T}`;\n\n/**\n * Returns all dot-separated nested keys for an object.\n *\n * Read more: https://stackoverflow.com/a/68404823.\n */\ntype DotNestedKeys<T> = (\n T extends object\n ? {\n [K in Exclude<keyof T, symbol>]: `${K}${DotPrefix<DotNestedKeys<T[K]>>}`;\n }[Exclude<keyof T, symbol>]\n : ''\n) extends infer D\n ? Extract<D, string>\n : never;\n\n/**\n * Parse a dot separated nested key into an array of keys.\n *\n * Example: 'services.signal.server' -> ['services', 'signal', 'server'].\n */\nexport type ParseKey<K extends string> = K extends `${infer L}.${infer Rest}` ? [L, ...ParseKey<Rest>] : [K];\n\n/**\n * Array of types that can act as an object key.\n */\ntype Keys = (keyof any)[];\n\n/**\n * Retrieves a property type in a series of nested objects.\n *\n * Read more: https://stackoverflow.com/a/61648690.\n */\nexport type DeepIndex<T, KS extends Keys, Fail = undefined> = KS extends [infer F, ...infer R]\n ? F extends keyof Exclude<T, undefined>\n ? R extends Keys\n ? DeepIndex<Exclude<T, undefined>[F], R, Fail>\n : Fail\n : Fail\n : T;\n\n/**\n * Any nested dot separated key that can be in config.\n */\n// TODO(egorgripasov): Clean once old config deprecated.\nexport type ConfigKey = DotNestedKeys<ConfigProto>;\n"],
|
|
5
|
+
"mappings": ";AAKA,YAAYA,UAAU;;;ACDtB,SAASC,eAAe;AACxB,OAAOC,kBAAkB;AACzB,OAAOC,SAAS;AAChB,OAAOC,aAAa;AACpB,OAAOC,SAAS;AA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"isMatch", "set", "InvalidConfigError", "schema", "trace", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "set", "mapToKeyValues", "get", "stringify", "validateConfig", "InvalidConfigError", "version", "error", "protoType", "verify", "ConfigResource", "Symbol", "for", "Config", "constructor", "objects", "_config", "defaultsDeep", "defaultValue", "find", "test", "Array", "isArray", "isMatch", "getUnchecked", "getOrThrow", "trace", "resource", "annotation", "localforage", "log", "FILE_DEFAULTS", "FILE_ENVS", "FILE_DYNAMICS"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/config/src/config.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/config/src/config.ts":{"bytes":16025,"imports":[{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.ismatch","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/tracing","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/config/src/loaders/browser.js":{"bytes":1206,"imports":[{"path":"localforage","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/config/src/savers/browser.js":{"bytes":613,"imports":[{"path":"localforage","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"(disabled):packages/sdk/config/src/plugin":{"bytes":0,"imports":[]},"packages/sdk/config/src/types.ts":{"bytes":2748,"imports":[],"format":"esm"},"packages/sdk/config/src/index.ts":{"bytes":1229,"imports":[{"path":"@dxos/protocols/proto/dxos/config","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/sdk/config/src/loaders/browser.js","kind":"import-statement","original":"./loaders"},{"path":"packages/sdk/config/src/savers/browser.js","kind":"import-statement","original":"./savers"},{"path":"(disabled):packages/sdk/config/src/plugin","kind":"import-statement","original":"./plugin"},{"path":"packages/sdk/config/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"}},"outputs":{"packages/sdk/config/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":13033},"packages/sdk/config/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/protocols/proto/dxos/config","kind":"import-statement","external":true},{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.ismatch","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/tracing","kind":"import-statement","external":true},{"path":"localforage","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"localforage","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["Config","ConfigResource","Defaults","Dynamics","Envs","FILE_DEFAULTS","FILE_DYNAMICS","FILE_ENVS","Local","SaveConfig","Storage","defs","mapFromKeyValues","mapToKeyValues","validateConfig"],"entryPoint":"packages/sdk/config/src/index.ts","inputs":{"packages/sdk/config/src/index.ts":{"bytesInOutput":59},"packages/sdk/config/src/config.ts":{"bytesInOutput":4087},"packages/sdk/config/src/loaders/browser.js":{"bytesInOutput":890},"packages/sdk/config/src/savers/browser.js":{"bytesInOutput":499},"packages/sdk/config/src/types.ts":{"bytesInOutput":102}},"bytes":6092}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var node_exports = {};
|
|
30
30
|
__export(node_exports, {
|
|
31
31
|
Config: () => Config,
|
|
32
|
+
ConfigResource: () => ConfigResource,
|
|
32
33
|
Defaults: () => Defaults,
|
|
33
34
|
Dynamics: () => Dynamics,
|
|
34
35
|
Envs: () => Envs,
|
|
@@ -53,6 +54,7 @@ var import_lodash2 = __toESM(require("lodash.get"));
|
|
|
53
54
|
var import_lodash3 = __toESM(require("lodash.ismatch"));
|
|
54
55
|
var import_lodash4 = __toESM(require("lodash.set"));
|
|
55
56
|
var import_protocols = require("@dxos/protocols");
|
|
57
|
+
var import_tracing = require("@dxos/tracing");
|
|
56
58
|
var import_js_yaml = __toESM(require("js-yaml"));
|
|
57
59
|
var import_node_fs = __toESM(require("node:fs"));
|
|
58
60
|
var import_node_path = __toESM(require("node:path"));
|
|
@@ -63,6 +65,16 @@ var import_node_fs2 = require("node:fs");
|
|
|
63
65
|
var import_node_path2 = require("node:path");
|
|
64
66
|
var import_pkg_up = __toESM(require("pkg-up"));
|
|
65
67
|
var import_log = require("@dxos/log");
|
|
68
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
69
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
70
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
71
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
72
|
+
else
|
|
73
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
74
|
+
if (d = decorators[i])
|
|
75
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
76
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
77
|
+
}
|
|
66
78
|
var configRootType = import_protocols.schema.getCodecForType("dxos.config.Config");
|
|
67
79
|
var mapFromKeyValues = (spec, values) => {
|
|
68
80
|
const config = {};
|
|
@@ -125,6 +137,7 @@ var validateConfig = (config) => {
|
|
|
125
137
|
}
|
|
126
138
|
return config;
|
|
127
139
|
};
|
|
140
|
+
var ConfigResource = Symbol.for("dxos.resource.Config");
|
|
128
141
|
var Config = class {
|
|
129
142
|
/**
|
|
130
143
|
* Creates an immutable instance.
|
|
@@ -182,6 +195,11 @@ var Config = class {
|
|
|
182
195
|
return value;
|
|
183
196
|
}
|
|
184
197
|
};
|
|
198
|
+
Config = _ts_decorate([
|
|
199
|
+
import_tracing.trace.resource({
|
|
200
|
+
annotation: ConfigResource
|
|
201
|
+
})
|
|
202
|
+
], Config);
|
|
185
203
|
var FILE_DEFAULTS = "defaults.yml";
|
|
186
204
|
var FILE_ENVS = "envs-map.yml";
|
|
187
205
|
var FILE_DYNAMICS = "config.yml";
|
|
@@ -292,6 +310,7 @@ var definitions = ({ configPath, envPath, devPath, mode = process.env.NODE_ENV,
|
|
|
292
310
|
// Annotate the CommonJS export names for ESM import in node:
|
|
293
311
|
0 && (module.exports = {
|
|
294
312
|
Config,
|
|
313
|
+
ConfigResource,
|
|
295
314
|
Defaults,
|
|
296
315
|
Dynamics,
|
|
297
316
|
Envs,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/config.ts", "../../../src/loaders/index.ts", "../../../src/types.ts", "../../../src/savers/index.ts", "../../../src/plugin/definitions.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\n// TODO(burdon): Why is this exported? (Rename).\nexport * as defs from '@dxos/protocols/proto/dxos/config';\n\nexport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport * from './config';\nexport * from './loaders';\nexport * from './savers';\nexport * from './plugin';\nexport * from './types';\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { boolean } from 'boolean';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport get from 'lodash.get';\nimport isMatch from 'lodash.ismatch';\nimport set from 'lodash.set';\n\nimport { InvalidConfigError, schema } from '@dxos/protocols';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\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 set(config, path, 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 = get(values, path);\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\n/**\n * Global configuration object.\n * NOTE: Config objects are immutable.\n */\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>> {\n return get(this._config, key, defaultValue);\n }\n\n /**\n * Get unique key.\n */\n find<T = any>(path: string, test: object): T | undefined {\n const values = get(this._config, path);\n if (!Array.isArray(values)) {\n return;\n }\n\n return values.find((value) => isMatch(value, test));\n }\n\n /**\n * Returns config key without type checking.\n *\n * @deprecated Use the type-checked version.\n */\n getUnchecked<T>(key: string, defaultValue?: T): T {\n return get(this._config, key, defaultValue);\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 = get(this._config, key);\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nimport { mapFromKeyValues } from '../config';\nimport { FILE_DEFAULTS, FILE_ENVS } from '../types';\n\n// TODO(burdon): Move code out of index file.\n\nconst DEFAULT_BASE_PATH = path.resolve(process.cwd(), 'config');\n\nconst maybeLoadFile = (file: string): any => {\n try {\n return yaml.load(fs.readFileSync(file, { encoding: 'utf8' }));\n } catch (err: any) {\n // Ignored.\n }\n};\n\n//\n// NOTE: Export LocalStorage and Dynamics for typescript to typecheck browser code (see ConfigPlugin).\n//\n\n/**\n * Profile\n */\nexport const Profile = (profile = 'default') => {\n const configFile = path.join(process.env.HOME ?? '~', `.config/dx/profile/${profile}.yml`);\n return maybeLoadFile(configFile) as ConfigProto;\n};\n\n/**\n * Development config.\n */\n// TODO(burdon): Rename or reconcile with Profile above?\nexport const Local = (): Partial<ConfigProto> => ({});\n\n/**\n * Provided dynamically by server.\n */\nexport const Dynamics = (): Partial<ConfigProto> => ({});\n\n/**\n * ENV variable (key/value) map.\n */\nexport const Envs = (basePath = DEFAULT_BASE_PATH): Partial<ConfigProto> => {\n const content = maybeLoadFile(path.resolve(basePath, FILE_ENVS));\n return content ? mapFromKeyValues(content, process.env) : {};\n};\n\n/**\n * JSON config.\n */\nexport const Defaults = (basePath = DEFAULT_BASE_PATH): Partial<ConfigProto> =>\n maybeLoadFile(path.resolve(basePath, FILE_DEFAULTS)) ?? {};\n\n/**\n * Load config from storage.\n */\nexport const Storage = async (): Promise<Partial<ConfigProto>> => ({});\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport const FILE_DEFAULTS = 'defaults.yml';\nexport const FILE_ENVS = 'envs-map.yml';\nexport const FILE_DYNAMICS = 'config.yml';\n\ntype DotPrefix<T extends string> = T extends '' ? '' : `.${T}`;\n\n/**\n * Returns all dot-separated nested keys for an object.\n *\n * Read more: https://stackoverflow.com/a/68404823.\n */\ntype DotNestedKeys<T> = (\n T extends object\n ? {\n [K in Exclude<keyof T, symbol>]: `${K}${DotPrefix<DotNestedKeys<T[K]>>}`;\n }[Exclude<keyof T, symbol>]\n : ''\n) extends infer D\n ? Extract<D, string>\n : never;\n\n/**\n * Parse a dot separated nested key into an array of keys.\n *\n * Example: 'services.signal.server' -> ['services', 'signal', 'server'].\n */\nexport type ParseKey<K extends string> = K extends `${infer L}.${infer Rest}` ? [L, ...ParseKey<Rest>] : [K];\n\n/**\n * Array of types that can act as an object key.\n */\ntype Keys = (keyof any)[];\n\n/**\n * Retrieves a property type in a series of nested objects.\n *\n * Read more: https://stackoverflow.com/a/61648690.\n */\nexport type DeepIndex<T, KS extends Keys, Fail = undefined> = KS extends [infer F, ...infer R]\n ? F extends keyof Exclude<T, undefined>\n ? R extends Keys\n ? DeepIndex<Exclude<T, undefined>[F], R, Fail>\n : Fail\n : Fail\n : T;\n\n/**\n * Any nested dot separated key that can be in config.\n */\n// TODO(egorgripasov): Clean once old config deprecated.\nexport type ConfigKey = DotNestedKeys<ConfigProto>;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport const SaveConfig = async (_: ConfigProto) => {};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport set from 'lodash.set';\nimport { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport pkgUp from 'pkg-up';\n\nimport { log } from '@dxos/log';\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 ?? resolve(CWD, 'dx.yml'),\n __CONFIG_ENVS__: envPath ?? resolve(CWD, 'dx-env.yml'),\n } as { [key: string]: string };\n\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 let content = {};\n\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 set(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 set(content, ['runtime', 'app', 'build', 'timestamp'], timestamp);\n set(content, ['runtime', 'app', 'build', 'commitHash'], commitHash);\n set(content, ['runtime', 'app', 'build', 'version'], packageJson?.version);\n } catch {}\n }\n } catch (err: any) {\n log(`Failed to load file ${value}:`, err);\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 __DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },\n __CONFIG_DEFAULTS__: {},\n __CONFIG_ENVS__: {},\n __CONFIG_LOCAL__: {},\n },\n );\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["import_lodash", "import_js_yaml", "import_node_fs", "import_node_path", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "set", "mapToKeyValues", "get", "stringify", "validateConfig", "InvalidConfigError", "version", "error", "protoType", "verify", "Config", "constructor", "objects", "_config", "defaultsDeep", "defaultValue", "find", "test", "Array", "isArray", "isMatch", "getUnchecked", "getOrThrow", "FILE_DEFAULTS", "FILE_ENVS", "FILE_DYNAMICS", "DEFAULT_BASE_PATH", "resolve", "process", "cwd", "maybeLoadFile", "file", "yaml", "load", "fs", "readFileSync", "encoding", "err", "Profile", "profile", "configFile", "join", "env", "HOME", "Local", "Dynamics", "Envs", "basePath", "content", "Defaults", "Storage", "SaveConfig", "_", "CWD", "definitions", "configPath", "envPath", "devPath", "mode", "NODE_ENV", "publicUrl", "KEYS_TO_FILE", "__CONFIG_DEFAULTS__", "__CONFIG_ENVS__", "__CONFIG_LOCAL__", "reduce", "prev", "forEach", "startsWith", "includes", "timestamp", "Date", "toISOString", "commitHash", "DX_COMMIT_HASH", "execSync", "replace", "packagePath", "pkgUp", "sync", "packageJson", "log", "__DXOS_CONFIG__", "dynamic"]
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\n// TODO(burdon): Why is this exported? (Rename).\nexport * as defs from '@dxos/protocols/proto/dxos/config';\n\nexport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport * from './config';\nexport * from './loaders';\nexport * from './savers';\nexport * from './plugin';\nexport * from './types';\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { boolean } from 'boolean';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport get from 'lodash.get';\nimport isMatch from 'lodash.ismatch';\nimport set from 'lodash.set';\n\nimport { InvalidConfigError, schema } from '@dxos/protocols';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\nimport { trace } from '@dxos/tracing';\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 set(config, path, 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 = get(values, path);\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>> {\n return get(this._config, key, defaultValue);\n }\n\n /**\n * Get unique key.\n */\n find<T = any>(path: string, test: object): T | undefined {\n const values = get(this._config, path);\n if (!Array.isArray(values)) {\n return;\n }\n\n return values.find((value) => isMatch(value, test));\n }\n\n /**\n * Returns config key without type checking.\n *\n * @deprecated Use the type-checked version.\n */\n getUnchecked<T>(key: string, defaultValue?: T): T {\n return get(this._config, key, defaultValue);\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 = get(this._config, key);\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nimport { mapFromKeyValues } from '../config';\nimport { FILE_DEFAULTS, FILE_ENVS } from '../types';\n\n// TODO(burdon): Move code out of index file.\n\nconst DEFAULT_BASE_PATH = path.resolve(process.cwd(), 'config');\n\nconst maybeLoadFile = (file: string): any => {\n try {\n return yaml.load(fs.readFileSync(file, { encoding: 'utf8' }));\n } catch (err: any) {\n // Ignored.\n }\n};\n\n//\n// NOTE: Export LocalStorage and Dynamics for typescript to typecheck browser code (see ConfigPlugin).\n//\n\n/**\n * Profile\n */\nexport const Profile = (profile = 'default') => {\n const configFile = path.join(process.env.HOME ?? '~', `.config/dx/profile/${profile}.yml`);\n return maybeLoadFile(configFile) as ConfigProto;\n};\n\n/**\n * Development config.\n */\n// TODO(burdon): Rename or reconcile with Profile above?\nexport const Local = (): Partial<ConfigProto> => ({});\n\n/**\n * Provided dynamically by server.\n */\nexport const Dynamics = (): Partial<ConfigProto> => ({});\n\n/**\n * ENV variable (key/value) map.\n */\nexport const Envs = (basePath = DEFAULT_BASE_PATH): Partial<ConfigProto> => {\n const content = maybeLoadFile(path.resolve(basePath, FILE_ENVS));\n return content ? mapFromKeyValues(content, process.env) : {};\n};\n\n/**\n * JSON config.\n */\nexport const Defaults = (basePath = DEFAULT_BASE_PATH): Partial<ConfigProto> =>\n maybeLoadFile(path.resolve(basePath, FILE_DEFAULTS)) ?? {};\n\n/**\n * Load config from storage.\n */\nexport const Storage = async (): Promise<Partial<ConfigProto>> => ({});\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport const FILE_DEFAULTS = 'defaults.yml';\nexport const FILE_ENVS = 'envs-map.yml';\nexport const FILE_DYNAMICS = 'config.yml';\n\ntype DotPrefix<T extends string> = T extends '' ? '' : `.${T}`;\n\n/**\n * Returns all dot-separated nested keys for an object.\n *\n * Read more: https://stackoverflow.com/a/68404823.\n */\ntype DotNestedKeys<T> = (\n T extends object\n ? {\n [K in Exclude<keyof T, symbol>]: `${K}${DotPrefix<DotNestedKeys<T[K]>>}`;\n }[Exclude<keyof T, symbol>]\n : ''\n) extends infer D\n ? Extract<D, string>\n : never;\n\n/**\n * Parse a dot separated nested key into an array of keys.\n *\n * Example: 'services.signal.server' -> ['services', 'signal', 'server'].\n */\nexport type ParseKey<K extends string> = K extends `${infer L}.${infer Rest}` ? [L, ...ParseKey<Rest>] : [K];\n\n/**\n * Array of types that can act as an object key.\n */\ntype Keys = (keyof any)[];\n\n/**\n * Retrieves a property type in a series of nested objects.\n *\n * Read more: https://stackoverflow.com/a/61648690.\n */\nexport type DeepIndex<T, KS extends Keys, Fail = undefined> = KS extends [infer F, ...infer R]\n ? F extends keyof Exclude<T, undefined>\n ? R extends Keys\n ? DeepIndex<Exclude<T, undefined>[F], R, Fail>\n : Fail\n : Fail\n : T;\n\n/**\n * Any nested dot separated key that can be in config.\n */\n// TODO(egorgripasov): Clean once old config deprecated.\nexport type ConfigKey = DotNestedKeys<ConfigProto>;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport const SaveConfig = async (_: ConfigProto) => {};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport set from 'lodash.set';\nimport { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport pkgUp from 'pkg-up';\n\nimport { log } from '@dxos/log';\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 ?? resolve(CWD, 'dx.yml'),\n __CONFIG_ENVS__: envPath ?? resolve(CWD, 'dx-env.yml'),\n } as { [key: string]: string };\n\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 let content = {};\n\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 set(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 set(content, ['runtime', 'app', 'build', 'timestamp'], timestamp);\n set(content, ['runtime', 'app', 'build', 'commitHash'], commitHash);\n set(content, ['runtime', 'app', 'build', 'version'], packageJson?.version);\n } catch {}\n }\n } catch (err: any) {\n log(`Failed to load file ${value}:`, err);\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 __DXOS_CONFIG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vC,UAAU;UAAQ,CAAA,EAAGwC,QAAQ,MAAM,EAAA;AAC9E,gBAAMC,cAAcC,cAAAA,QAAMC,KAAI;AAC9B,gBAAMC,cAAcH,eAAetF,KAAKC,UAAM2C,8BAAa0C,aAAa,OAAA,CAAA;AACxEnF,6BAAAA,SAAIsD,SAAS;YAAC;YAAW;YAAO;YAAS;aAAcsB,SAAAA;AACvD5E,6BAAAA,SAAIsD,SAAS;YAAC;YAAW;YAAO;YAAS;aAAeyB,UAAAA;AACxD/E,6BAAAA,SAAIsD,SAAS;YAAC;YAAW;YAAO;YAAS;aAAYgC,aAAahF,OAAAA;QACpE,QAAQ;QAAC;MACX;IACF,SAASqC,KAAU;AACjB4C,0BAAI,uBAAuB9F,KAAAA,KAAUkD,KAAAA;;;;;;AAErC,UAAIvD,QAAQ,uBAAuB;AAEjC,cAAM,IAAIW,MAAM,2CAA2CN,KAAAA,EAAO;MACpE;IACF;AAEA,WAAO;MACL,GAAG+E;MACH,CAACpF,GAAAA,GAAMkE;IACT;EACF,GACA;IACEkC,iBAAiB;MAAEC,SAASzB,SAAS;MAAcE;IAAU;IAC7DE,qBAAqB,CAAC;IACtBC,iBAAiB,CAAC;IAClBC,kBAAkB,CAAC;EACrB,CAAA;AAEJ;",
|
|
6
|
+
"names": ["import_lodash", "import_js_yaml", "import_node_fs", "import_node_path", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "set", "mapToKeyValues", "get", "stringify", "validateConfig", "InvalidConfigError", "version", "error", "protoType", "verify", "ConfigResource", "Symbol", "for", "Config", "constructor", "objects", "_config", "defaultsDeep", "defaultValue", "find", "test", "Array", "isArray", "isMatch", "getUnchecked", "getOrThrow", "trace", "resource", "annotation", "FILE_DEFAULTS", "FILE_ENVS", "FILE_DYNAMICS", "DEFAULT_BASE_PATH", "resolve", "process", "cwd", "maybeLoadFile", "file", "yaml", "load", "fs", "readFileSync", "encoding", "err", "Profile", "profile", "configFile", "join", "env", "HOME", "Local", "Dynamics", "Envs", "basePath", "content", "Defaults", "Storage", "SaveConfig", "_", "CWD", "definitions", "configPath", "envPath", "devPath", "mode", "NODE_ENV", "publicUrl", "KEYS_TO_FILE", "__CONFIG_DEFAULTS__", "__CONFIG_ENVS__", "__CONFIG_LOCAL__", "reduce", "prev", "forEach", "startsWith", "includes", "timestamp", "Date", "toISOString", "commitHash", "DX_COMMIT_HASH", "execSync", "replace", "packagePath", "pkgUp", "sync", "packageJson", "log", "__DXOS_CONFIG__", "dynamic"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/config/src/config.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/config/src/config.ts":{"bytes":16025,"imports":[{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.ismatch","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/tracing","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/config/src/types.ts":{"bytes":2748,"imports":[],"format":"esm"},"packages/sdk/config/src/loaders/index.ts":{"bytes":5858,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/sdk/config/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/sdk/config/src/savers/index.ts":{"bytes":679,"imports":[],"format":"esm"},"packages/sdk/config/src/plugin/definitions.ts":{"bytes":10742,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"../config"}],"format":"esm"},"packages/sdk/config/src/plugin/types.ts":{"bytes":1498,"imports":[],"format":"esm"},"packages/sdk/config/src/plugin/index.ts":{"bytes":558,"imports":[{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"},{"path":"packages/sdk/config/src/plugin/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"packages/sdk/config/src/index.ts":{"bytes":1229,"imports":[{"path":"@dxos/protocols/proto/dxos/config","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/sdk/config/src/loaders/index.ts","kind":"import-statement","original":"./loaders"},{"path":"packages/sdk/config/src/savers/index.ts","kind":"import-statement","original":"./savers"},{"path":"packages/sdk/config/src/plugin/index.ts","kind":"import-statement","original":"./plugin"},{"path":"packages/sdk/config/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"}},"outputs":{"packages/sdk/config/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":18315},"packages/sdk/config/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/protocols/proto/dxos/config","kind":"import-statement","external":true},{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.ismatch","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/tracing","kind":"import-statement","external":true},{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"js-yaml","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["Config","ConfigResource","Defaults","Dynamics","Envs","FILE_DEFAULTS","FILE_DYNAMICS","FILE_ENVS","Local","Profile","SaveConfig","Storage","definitions","defs","mapFromKeyValues","mapToKeyValues","validateConfig"],"entryPoint":"packages/sdk/config/src/index.ts","inputs":{"packages/sdk/config/src/index.ts":{"bytesInOutput":59},"packages/sdk/config/src/config.ts":{"bytesInOutput":4105},"packages/sdk/config/src/loaders/index.ts":{"bytesInOutput":837},"packages/sdk/config/src/types.ts":{"bytesInOutput":102},"packages/sdk/config/src/savers/index.ts":{"bytesInOutput":35},"packages/sdk/config/src/plugin/definitions.ts":{"bytesInOutput":2721},"packages/sdk/config/src/plugin/index.ts":{"bytesInOutput":0}},"bytes":8431}}}
|
|
@@ -26,11 +26,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_XX2MVHOV_exports = {};
|
|
30
|
+
__export(chunk_XX2MVHOV_exports, {
|
|
31
31
|
definitions: () => definitions
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(chunk_XX2MVHOV_exports);
|
|
34
34
|
var import_js_yaml = __toESM(require("js-yaml"));
|
|
35
35
|
var import_lodash = __toESM(require("lodash.set"));
|
|
36
36
|
var import_node_child_process = require("node:child_process");
|
|
@@ -44,6 +44,17 @@ var import_lodash3 = __toESM(require("lodash.get"));
|
|
|
44
44
|
var import_lodash4 = __toESM(require("lodash.ismatch"));
|
|
45
45
|
var import_lodash5 = __toESM(require("lodash.set"));
|
|
46
46
|
var import_protocols = require("@dxos/protocols");
|
|
47
|
+
var import_tracing = require("@dxos/tracing");
|
|
48
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
49
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
50
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
51
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
52
|
+
else
|
|
53
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
54
|
+
if (d = decorators[i])
|
|
55
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
56
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
57
|
+
}
|
|
47
58
|
var configRootType = import_protocols.schema.getCodecForType("dxos.config.Config");
|
|
48
59
|
var mapFromKeyValues = (spec, values) => {
|
|
49
60
|
const config = {};
|
|
@@ -77,6 +88,82 @@ var mapFromKeyValues = (spec, values) => {
|
|
|
77
88
|
}
|
|
78
89
|
return config;
|
|
79
90
|
};
|
|
91
|
+
var validateConfig = (config) => {
|
|
92
|
+
if (!("version" in config)) {
|
|
93
|
+
throw new import_protocols.InvalidConfigError("Version not specified");
|
|
94
|
+
}
|
|
95
|
+
if (config?.version !== 1) {
|
|
96
|
+
throw new import_protocols.InvalidConfigError(`Invalid config version: ${config.version}`);
|
|
97
|
+
}
|
|
98
|
+
const error = configRootType.protoType.verify(config);
|
|
99
|
+
if (error) {
|
|
100
|
+
throw new import_protocols.InvalidConfigError(error);
|
|
101
|
+
}
|
|
102
|
+
return config;
|
|
103
|
+
};
|
|
104
|
+
var ConfigResource = Symbol.for("dxos.resource.Config");
|
|
105
|
+
var Config = class {
|
|
106
|
+
/**
|
|
107
|
+
* Creates an immutable instance.
|
|
108
|
+
* @constructor
|
|
109
|
+
*/
|
|
110
|
+
constructor(config = {}, ...objects) {
|
|
111
|
+
this._config = validateConfig((0, import_lodash2.default)(config, ...objects, {
|
|
112
|
+
version: 1
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns an immutable config JSON object.
|
|
117
|
+
*/
|
|
118
|
+
get values() {
|
|
119
|
+
return this._config;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns the given config property.
|
|
123
|
+
*
|
|
124
|
+
* @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
|
|
125
|
+
* @param defaultValue Default value to return if option is not present in the config.
|
|
126
|
+
* @returns The config value or undefined if the option is not present.
|
|
127
|
+
*/
|
|
128
|
+
get(key, defaultValue) {
|
|
129
|
+
return (0, import_lodash3.default)(this._config, key, defaultValue);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get unique key.
|
|
133
|
+
*/
|
|
134
|
+
find(path, test) {
|
|
135
|
+
const values = (0, import_lodash3.default)(this._config, path);
|
|
136
|
+
if (!Array.isArray(values)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
return values.find((value) => (0, import_lodash4.default)(value, test));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Returns config key without type checking.
|
|
143
|
+
*
|
|
144
|
+
* @deprecated Use the type-checked version.
|
|
145
|
+
*/
|
|
146
|
+
getUnchecked(key, defaultValue) {
|
|
147
|
+
return (0, import_lodash3.default)(this._config, key, defaultValue);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Returns the given config property or throw if it doesn't exist.
|
|
151
|
+
*
|
|
152
|
+
* @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
|
|
153
|
+
*/
|
|
154
|
+
getOrThrow(key) {
|
|
155
|
+
const value = (0, import_lodash3.default)(this._config, key);
|
|
156
|
+
if (!value) {
|
|
157
|
+
throw new Error(`Config option not present: ${key}`);
|
|
158
|
+
}
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
Config = _ts_decorate([
|
|
163
|
+
import_tracing.trace.resource({
|
|
164
|
+
annotation: ConfigResource
|
|
165
|
+
})
|
|
166
|
+
], Config);
|
|
80
167
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/config/src/plugin/definitions.ts";
|
|
81
168
|
var CWD = process.cwd();
|
|
82
169
|
var definitions = ({ configPath, envPath, devPath, mode = process.env.NODE_ENV, publicUrl = "", env }) => {
|
|
@@ -162,4 +249,4 @@ var definitions = ({ configPath, envPath, devPath, mode = process.env.NODE_ENV,
|
|
|
162
249
|
0 && (module.exports = {
|
|
163
250
|
definitions
|
|
164
251
|
});
|
|
165
|
-
//# sourceMappingURL=chunk-
|
|
252
|
+
//# sourceMappingURL=chunk-XX2MVHOV.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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 set from 'lodash.set';\nimport { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport pkgUp from 'pkg-up';\n\nimport { log } from '@dxos/log';\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 ?? resolve(CWD, 'dx.yml'),\n __CONFIG_ENVS__: envPath ?? resolve(CWD, 'dx-env.yml'),\n } as { [key: string]: string };\n\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 let content = {};\n\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 set(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 set(content, ['runtime', 'app', 'build', 'timestamp'], timestamp);\n set(content, ['runtime', 'app', 'build', 'commitHash'], commitHash);\n set(content, ['runtime', 'app', 'build', 'version'], packageJson?.version);\n } catch {}\n }\n } catch (err: any) {\n log(`Failed to load file ${value}:`, err);\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 __DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },\n __CONFIG_DEFAULTS__: {},\n __CONFIG_ENVS__: {},\n __CONFIG_LOCAL__: {},\n },\n );\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { boolean } from 'boolean';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport get from 'lodash.get';\nimport isMatch from 'lodash.ismatch';\nimport set from 'lodash.set';\n\nimport { InvalidConfigError, schema } from '@dxos/protocols';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\nimport { trace } from '@dxos/tracing';\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 set(config, path, 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 = get(values, path);\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>> {\n return get(this._config, key, defaultValue);\n }\n\n /**\n * Get unique key.\n */\n find<T = any>(path: string, test: object): T | undefined {\n const values = get(this._config, path);\n if (!Array.isArray(values)) {\n return;\n }\n\n return values.find((value) => isMatch(value, test));\n }\n\n /**\n * Returns config key without type checking.\n *\n * @deprecated Use the type-checked version.\n */\n getUnchecked<T>(key: string, defaultValue?: T): T {\n return get(this._config, key, defaultValue);\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 = get(this._config, key);\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,qBAAiB;AACjB,oBAAgB;AAChB,gCAAyB;AACzB,qBAA6B;AAC7B,uBAAwB;AACxB,oBAAkB;AAElB,iBAAoB;ACPpB,qBAAwB;AACxB,IAAAA,iBAAyB;AACzB,IAAAA,iBAAgB;AAChB,IAAAA,iBAAoB;AACpB,IAAAA,iBAAgB;AAEhB,uBAA2C;AAE3C,qBAAsB;;;;;;;;;;;AAKtB,IAAMC,iBAAiBC,wBAAOC,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,OAA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QAAQO,GAAG,EAAEc,QAAQ,CAAC,CAAC7D,MAAKK,MAAAA,MAAM;AAC/C,cAAIL,KAAI8D,WAAW,KAAA,KAAUf,KAAKgB,SAAS/D,IAAAA,GAAM;AAC/CY,8BAAAA,SAAI6C,SAAS;cAAC;cAAW;cAAO;cAAOzD;eAAMK,MAAAA;UAC/C;QACF,CAAA;AAGA,YAAI;AACF,gBAAM2D,aAAY,oBAAIC,KAAAA,GAAOC,YAAW;AACxC,gBAAMC,aACJ3B,QAAQO,IAAIqB,sBACZC,oCAAS,8BAA8B;YAAEC,UAAU;UAAQ,CAAA,EAAGC,QAAQ,MAAM,EAAA;AAC9E,gBAAMC,cAAcC,cAAAA,QAAMC,KAAI;AAC9B,gBAAMC,cAAcH,eAAe/D,KAAKC,UAAMkD,6BAAaY,aAAa,OAAA,CAAA;AACxE5D,4BAAAA,SAAI6C,SAAS;YAAC;YAAW;YAAO;YAAS;aAAcO,SAAAA;AACvDpD,4BAAAA,SAAI6C,SAAS;YAAC;YAAW;YAAO;YAAS;aAAeU,UAAAA;AACxDvD,4BAAAA,SAAI6C,SAAS;YAAC;YAAW;YAAO;YAAS;aAAYkB,aAAa5D,OAAAA;QACpE,QAAQ;QAAC;MACX;IACF,SAAS6D,KAAU;AACjBC,0BAAI,uBAAuBxE,KAAAA,KAAUuE,KAAAA;;;;;;AAErC,UAAI5E,QAAQ,uBAAuB;AAEjC,cAAM,IAAIW,MAAM,2CAA2CN,KAAAA,EAAO;MACpE;IACF;AAEA,WAAO;MACL,GAAGmD;MACH,CAACxD,GAAAA,GAAMyD;IACT;EACF,GACA;IACEqB,iBAAiB;MAAEC,SAASjC,SAAS;MAAcG;IAAU;IAC7DE,qBAAqB,CAAC;IACtBE,iBAAiB,CAAC;IAClBC,kBAAkB,CAAC;EACrB,CAAA;AAEJ;",
|
|
6
|
+
"names": ["import_lodash", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "set", "validateConfig", "InvalidConfigError", "version", "error", "protoType", "verify", "ConfigResource", "Symbol", "for", "Config", "constructor", "objects", "_config", "defaultsDeep", "get", "defaultValue", "find", "test", "Array", "isArray", "isMatch", "getUnchecked", "getOrThrow", "trace", "resource", "annotation", "CWD", "process", "cwd", "definitions", "configPath", "envPath", "devPath", "mode", "env", "NODE_ENV", "publicUrl", "KEYS_TO_FILE", "__CONFIG_DEFAULTS__", "resolve", "__CONFIG_ENVS__", "__CONFIG_LOCAL__", "reduce", "prev", "content", "yaml", "load", "readFileSync", "forEach", "startsWith", "includes", "timestamp", "Date", "toISOString", "commitHash", "DX_COMMIT_HASH", "execSync", "encoding", "replace", "packagePath", "pkgUp", "sync", "packageJson", "err", "log", "__DXOS_CONFIG__", "dynamic"]
|
|
7
|
+
}
|
|
@@ -21,14 +21,14 @@ __export(esbuild_plugin_exports, {
|
|
|
21
21
|
ConfigPlugin: () => ConfigPlugin
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(esbuild_plugin_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_chunk_XX2MVHOV = require("./chunk-XX2MVHOV.cjs");
|
|
25
25
|
var ConfigPlugin = (options = {}) => {
|
|
26
26
|
return {
|
|
27
27
|
name: "dxos-config",
|
|
28
28
|
setup: ({ initialOptions }) => {
|
|
29
29
|
const esbuildOptions = initialOptions;
|
|
30
30
|
esbuildOptions.define ||= {};
|
|
31
|
-
Object.entries((0,
|
|
31
|
+
Object.entries((0, import_chunk_XX2MVHOV.definitions)({
|
|
32
32
|
...options,
|
|
33
33
|
mode: process.env.NODE_ENV
|
|
34
34
|
})).reduce((define, [key, value]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/config/src/config.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/config/src/config.ts":{"bytes":16025,"imports":[{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.ismatch","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/tracing","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/config/src/plugin/definitions.ts":{"bytes":10742,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"../config"}],"format":"esm"},"packages/sdk/config/src/plugin/esbuild-plugin.ts":{"bytes":2584,"imports":[{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"},"packages/sdk/config/src/plugin/rollup-plugin.ts":{"bytes":2068,"imports":[{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"},"packages/sdk/config/src/plugin/vite-plugin.ts":{"bytes":3319,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"}},"outputs":{"packages/sdk/config/dist/plugin/node/esbuild-plugin.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1346},"packages/sdk/config/dist/plugin/node/esbuild-plugin.cjs":{"imports":[{"path":"packages/sdk/config/dist/plugin/node/chunk-XX2MVHOV.cjs","kind":"import-statement"}],"exports":["ConfigPlugin"],"entryPoint":"packages/sdk/config/src/plugin/esbuild-plugin.ts","inputs":{"packages/sdk/config/src/plugin/esbuild-plugin.ts":{"bytesInOutput":443}},"bytes":621},"packages/sdk/config/dist/plugin/node/rollup-plugin.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1102},"packages/sdk/config/dist/plugin/node/rollup-plugin.cjs":{"imports":[{"path":"packages/sdk/config/dist/plugin/node/chunk-XX2MVHOV.cjs","kind":"import-statement"}],"exports":["ConfigPlugin"],"entryPoint":"packages/sdk/config/src/plugin/rollup-plugin.ts","inputs":{"packages/sdk/config/src/plugin/rollup-plugin.ts":{"bytesInOutput":288}},"bytes":464},"packages/sdk/config/dist/plugin/node/vite-plugin.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1707},"packages/sdk/config/dist/plugin/node/vite-plugin.cjs":{"imports":[{"path":"packages/sdk/config/dist/plugin/node/chunk-XX2MVHOV.cjs","kind":"import-statement"},{"path":"node:path","kind":"import-statement","external":true}],"exports":["ConfigPlugin"],"entryPoint":"packages/sdk/config/src/plugin/vite-plugin.ts","inputs":{"packages/sdk/config/src/plugin/vite-plugin.ts":{"bytesInOutput":634}},"bytes":806},"packages/sdk/config/dist/plugin/node/chunk-XX2MVHOV.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12715},"packages/sdk/config/dist/plugin/node/chunk-XX2MVHOV.cjs":{"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.ismatch","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/tracing","kind":"import-statement","external":true}],"exports":["definitions"],"inputs":{"packages/sdk/config/src/plugin/definitions.ts":{"bytesInOutput":2719},"packages/sdk/config/src/config.ts":{"bytesInOutput":3705}},"bytes":6632}}}
|
|
@@ -21,9 +21,9 @@ __export(rollup_plugin_exports, {
|
|
|
21
21
|
ConfigPlugin: () => ConfigPlugin
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(rollup_plugin_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_chunk_XX2MVHOV = require("./chunk-XX2MVHOV.cjs");
|
|
25
25
|
var ConfigPlugin = (options = {}) => {
|
|
26
|
-
const contents = Object.entries((0,
|
|
26
|
+
const contents = Object.entries((0, import_chunk_XX2MVHOV.definitions)({
|
|
27
27
|
...options,
|
|
28
28
|
mode: process.env.NODE_ENV
|
|
29
29
|
})).map(([key, value]) => `globalThis.${key} = ${JSON.stringify(value)};`).join("\n");
|
|
@@ -21,7 +21,7 @@ __export(vite_plugin_exports, {
|
|
|
21
21
|
ConfigPlugin: () => ConfigPlugin
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(vite_plugin_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_chunk_XX2MVHOV = require("./chunk-XX2MVHOV.cjs");
|
|
25
25
|
var import_node_path = require("node:path");
|
|
26
26
|
var ConfigPlugin = (options = {}) => ({
|
|
27
27
|
name: "dxos-config",
|
|
@@ -29,7 +29,7 @@ var ConfigPlugin = (options = {}) => ({
|
|
|
29
29
|
const configPath = root && (0, import_node_path.resolve)(root, options.configPath ?? "dx.yml");
|
|
30
30
|
const envPath = root && (0, import_node_path.resolve)(root, options.envPath ?? "dx-env.yml");
|
|
31
31
|
const devPath = root && (0, import_node_path.resolve)(root, options.devPath ?? "dx-local.yml");
|
|
32
|
-
const define = Object.entries((0,
|
|
32
|
+
const define = Object.entries((0, import_chunk_XX2MVHOV.definitions)({
|
|
33
33
|
...options,
|
|
34
34
|
configPath,
|
|
35
35
|
envPath,
|
|
@@ -29,6 +29,7 @@ export declare const mapToKeyValues: (spec: MappingSpec, values: any) => Record<
|
|
|
29
29
|
* Validate config object.
|
|
30
30
|
*/
|
|
31
31
|
export declare const validateConfig: (config: ConfigProto) => ConfigProto;
|
|
32
|
+
export declare const ConfigResource: unique symbol;
|
|
32
33
|
/**
|
|
33
34
|
* Global configuration object.
|
|
34
35
|
* NOTE: Config objects are immutable.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,MAAM,IAAI,WAAW,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,MAAM,IAAI,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAG/E,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExE,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAGnE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,SAAU,WAAW,UAAU,OAAO,MAAM,EAAE,GAAG,CAAC,OAuC9E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,SAAU,WAAW,UAAU,GAAG,wBAiB5D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,WAAY,WAAW,KAAG,WAepD,CAAC;AAEF,eAAO,MAAM,cAAc,eAAqC,CAAC;AAEjE;;;GAGG;AACH,qBACa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;IAE9B;;;OAGG;gBACS,MAAM,GAAE,WAAgB,EAAE,GAAG,OAAO,EAAE,WAAW,EAAE;IAI/D;;OAEG;IACH,IAAI,MAAM,IAAI,WAAW,CAExB;IAED;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,SAAS,SAAS,EACrB,GAAG,EAAE,CAAC,EACN,YAAY,CAAC,EAAE,SAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,GACjD,SAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAItC;;OAEG;IACH,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IASxD;;;;OAIG;IACH,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC;IAIjD;;;;OAIG;IACH,UAAU,CAAC,CAAC,SAAS,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC;CAOjG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/loaders/browser.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/loaders/browser.js"],"names":[],"mappings":"AAcO,6BAEN;AAEM,yCAcN;AAEM,4BAEN;AAEM,gCAEN;AAKM,wCAUN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/config",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10-main.06ef97a",
|
|
4
4
|
"description": "Config utilities",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -34,9 +34,10 @@
|
|
|
34
34
|
"lodash.ismatch": "^4.4.0",
|
|
35
35
|
"lodash.set": "^4.3.2",
|
|
36
36
|
"pkg-up": "^3.1.0",
|
|
37
|
-
"@dxos/log": "0.4.
|
|
38
|
-
"@dxos/node-std": "0.4.
|
|
39
|
-
"@dxos/
|
|
37
|
+
"@dxos/log": "0.4.10-main.06ef97a",
|
|
38
|
+
"@dxos/node-std": "0.4.10-main.06ef97a",
|
|
39
|
+
"@dxos/tracing": "0.4.10-main.06ef97a",
|
|
40
|
+
"@dxos/protocols": "0.4.10-main.06ef97a"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@types/js-yaml": "^4.0.5",
|
|
@@ -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 set from 'lodash.set';\nimport { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport pkgUp from 'pkg-up';\n\nimport { log } from '@dxos/log';\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 ?? resolve(CWD, 'dx.yml'),\n __CONFIG_ENVS__: envPath ?? resolve(CWD, 'dx-env.yml'),\n } as { [key: string]: string };\n\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 let content = {};\n\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 set(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 set(content, ['runtime', 'app', 'build', 'timestamp'], timestamp);\n set(content, ['runtime', 'app', 'build', 'commitHash'], commitHash);\n set(content, ['runtime', 'app', 'build', 'version'], packageJson?.version);\n } catch {}\n }\n } catch (err: any) {\n log(`Failed to load file ${value}:`, err);\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 __DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },\n __CONFIG_DEFAULTS__: {},\n __CONFIG_ENVS__: {},\n __CONFIG_LOCAL__: {},\n },\n );\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { boolean } from 'boolean';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport get from 'lodash.get';\nimport isMatch from 'lodash.ismatch';\nimport set from 'lodash.set';\n\nimport { InvalidConfigError, schema } from '@dxos/protocols';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\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 set(config, path, 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 = get(values, path);\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\n/**\n * Global configuration object.\n * NOTE: Config objects are immutable.\n */\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>> {\n return get(this._config, key, defaultValue);\n }\n\n /**\n * Get unique key.\n */\n find<T = any>(path: string, test: object): T | undefined {\n const values = get(this._config, path);\n if (!Array.isArray(values)) {\n return;\n }\n\n return values.find((value) => isMatch(value, test));\n }\n\n /**\n * Returns config key without type checking.\n *\n * @deprecated Use the type-checked version.\n */\n getUnchecked<T>(key: string, defaultValue?: T): T {\n return get(this._config, key, defaultValue);\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 = get(this._config, key);\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,qBAAiB;AACjB,oBAAgB;AAChB,gCAAyB;AACzB,qBAA6B;AAC7B,uBAAwB;AACxB,oBAAkB;AAElB,iBAAoB;ACPpB,qBAAwB;AACxB,IAAAA,iBAAyB;AACzB,IAAAA,iBAAgB;AAChB,IAAAA,iBAAoB;AACpB,IAAAA,iBAAgB;AAEhB,uBAA2C;AAM3C,IAAMC,iBAAiBC,wBAAOC,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,wBAAQE,wBAAQF,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;UACF;UAEA,SAAS;AACP,kBAAM,IAAIM,MAAM,iB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BAAMC,cAAcH,eAAerC,KAAKC,UAAMwB,6BAAaY,aAAa,OAAA,CAAA;AACxElC,4BAAAA,SAAImB,SAAS;YAAC;YAAW;YAAO;YAAS;aAAcO,SAAAA;AACvD1B,4BAAAA,SAAImB,SAAS;YAAC;YAAW;YAAO;YAAS;aAAeU,UAAAA;AACxD7B,4BAAAA,SAAImB,SAAS;YAAC;YAAW;YAAO;YAAS;aAAYkB,aAAaC,OAAAA;QACpE,QAAQ;QAAC;MACX;IACF,SAASC,KAAU;AACjBC,0BAAI,uBAAuB/C,KAAAA,KAAU8C,KAAAA;;;;;;AAErC,UAAInD,QAAQ,uBAAuB;AAEjC,cAAM,IAAIW,MAAM,2CAA2CN,KAAAA,EAAO;MACpE;IACF;AAEA,WAAO;MACL,GAAGyB;MACH,CAAC9B,GAAAA,GAAM+B;IACT;EACF,GACA;IACEsB,iBAAiB;MAAEC,SAASlC,SAAS;MAAcG;IAAU;IAC7DE,qBAAqB,CAAC;IACtBE,iBAAiB,CAAC;IAClBC,kBAAkB,CAAC;EACrB,CAAA;AAEJ;",
|
|
6
|
-
"names": ["import_lodash", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "set", "CWD", "process", "cwd", "definitions", "configPath", "envPath", "devPath", "mode", "env", "NODE_ENV", "publicUrl", "KEYS_TO_FILE", "__CONFIG_DEFAULTS__", "resolve", "__CONFIG_ENVS__", "__CONFIG_LOCAL__", "reduce", "prev", "content", "yaml", "load", "readFileSync", "forEach", "startsWith", "includes", "timestamp", "Date", "toISOString", "commitHash", "DX_COMMIT_HASH", "execSync", "encoding", "replace", "packagePath", "pkgUp", "sync", "packageJson", "version", "err", "log", "__DXOS_CONFIG__", "dynamic"]
|
|
7
|
-
}
|