@dxos/config 0.8.4-main.7ace549 → 0.8.4-main.937b3ca
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/chunk-WETPAQBA.mjs +147 -0
- package/dist/lib/browser/chunk-WETPAQBA.mjs.map +7 -0
- package/dist/lib/browser/chunk-ZI5JXCYY.mjs +11 -0
- package/dist/lib/browser/chunk-ZI5JXCYY.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +45 -232
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/loaders/browser.mjs +98 -0
- package/dist/lib/browser/loaders/browser.mjs.map +7 -0
- package/dist/lib/browser/loaders/index.mjs +71 -0
- package/dist/lib/browser/loaders/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/plugin/browser.mjs +8 -0
- package/dist/lib/browser/plugin/browser.mjs.map +7 -0
- package/dist/lib/browser/plugin/index.mjs +116 -0
- package/dist/lib/browser/plugin/index.mjs.map +7 -0
- package/dist/lib/browser/savers/browser.mjs +35 -0
- package/dist/lib/browser/savers/browser.mjs.map +7 -0
- package/dist/lib/browser/savers/index.mjs +7 -0
- package/dist/lib/browser/savers/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-FVCGIRXP.mjs +149 -0
- package/dist/lib/node-esm/chunk-FVCGIRXP.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-ODEKAZ4J.mjs +13 -0
- package/dist/lib/node-esm/chunk-ODEKAZ4J.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +49 -330
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/loaders/browser.mjs +100 -0
- package/dist/lib/node-esm/loaders/browser.mjs.map +7 -0
- package/dist/lib/node-esm/loaders/index.mjs +72 -0
- package/dist/lib/node-esm/loaders/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/plugin/browser.mjs +10 -0
- package/dist/lib/node-esm/plugin/browser.mjs.map +7 -0
- package/dist/lib/node-esm/plugin/index.mjs +117 -0
- package/dist/lib/node-esm/plugin/index.mjs.map +7 -0
- package/dist/lib/node-esm/savers/browser.mjs +37 -0
- package/dist/lib/node-esm/savers/browser.mjs.map +7 -0
- package/dist/lib/node-esm/savers/index.mjs +9 -0
- package/dist/lib/node-esm/savers/index.mjs.map +7 -0
- package/dist/plugin/node-esm/{chunk-V3PJG4GW.mjs → chunk-QQKWALKX.mjs} +1 -1
- package/dist/plugin/node-esm/chunk-QQKWALKX.mjs.map +7 -0
- package/dist/plugin/node-esm/esbuild-plugin.mjs +1 -1
- package/dist/plugin/node-esm/meta.json +1 -1
- package/dist/plugin/node-esm/rollup-plugin.mjs +1 -1
- package/dist/plugin/node-esm/vite-plugin.mjs +1 -1
- package/dist/types/src/config-service.d.ts +1 -0
- package/dist/types/src/config-service.d.ts.map +1 -1
- package/dist/types/src/config.d.ts +0 -1
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/loaders/browser.d.ts +11 -15
- package/dist/types/src/loaders/browser.d.ts.map +1 -1
- package/dist/types/src/plugin/browser.d.ts +3 -0
- package/dist/types/src/plugin/browser.d.ts.map +1 -0
- package/dist/types/src/preset.d.ts +1 -1
- package/dist/types/src/preset.d.ts.map +1 -1
- package/dist/types/src/savers/browser.d.ts +2 -1
- package/dist/types/src/savers/browser.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +45 -18
- package/src/config-service.ts +29 -13
- package/src/config.ts +0 -2
- package/src/index.ts +3 -3
- package/src/loaders/{browser.js → browser.ts} +15 -9
- package/src/plugin/browser.ts +11 -0
- package/src/preset.ts +2 -1
- package/src/savers/{browser.js → browser.ts} +2 -2
- package/dist/plugin/node-esm/chunk-V3PJG4GW.mjs.map +0 -7
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
import { boolean } from "boolean";
|
|
3
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
4
|
+
import isMatch from "lodash.ismatch";
|
|
5
|
+
import { InvalidConfigError } from "@dxos/protocols";
|
|
6
|
+
import { schema } from "@dxos/protocols/proto";
|
|
7
|
+
import { trace } from "@dxos/tracing";
|
|
8
|
+
import { getDeep, setDeep } from "@dxos/util";
|
|
9
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
10
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
|
+
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;
|
|
13
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
|
+
}
|
|
15
|
+
var configRootType = schema.getCodecForType("dxos.config.Config");
|
|
16
|
+
var mapFromKeyValues = (spec, values) => {
|
|
17
|
+
const config = {};
|
|
18
|
+
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
19
|
+
let value = values[key];
|
|
20
|
+
if (value !== void 0) {
|
|
21
|
+
if (type) {
|
|
22
|
+
switch (type) {
|
|
23
|
+
case "boolean": {
|
|
24
|
+
value = boolean(value);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case "number": {
|
|
28
|
+
value = Number(value);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
case "string": {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
case "json": {
|
|
35
|
+
value = value ? JSON.parse(value) : null;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
default: {
|
|
39
|
+
throw new Error(`Invalid type: ${type}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
setDeep(config, path.split("."), value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return config;
|
|
47
|
+
};
|
|
48
|
+
var mapToKeyValues = (spec, values) => {
|
|
49
|
+
const config = {};
|
|
50
|
+
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
51
|
+
const value = getDeep(values, path.split("."));
|
|
52
|
+
if (value !== void 0) {
|
|
53
|
+
switch (type) {
|
|
54
|
+
case "json":
|
|
55
|
+
config[key] = JSON.stringify(value);
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
config[key] = value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return config;
|
|
63
|
+
};
|
|
64
|
+
var validateConfig = (config) => {
|
|
65
|
+
if (!("version" in config)) {
|
|
66
|
+
throw new InvalidConfigError({
|
|
67
|
+
message: "Version not specified"
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (config?.version !== 1) {
|
|
71
|
+
throw new InvalidConfigError({
|
|
72
|
+
message: `Invalid config version: ${config.version}`
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const error = configRootType.protoType.verify(config);
|
|
76
|
+
if (error) {
|
|
77
|
+
throw new InvalidConfigError({
|
|
78
|
+
message: String(error)
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return config;
|
|
82
|
+
};
|
|
83
|
+
var ConfigResource = Symbol.for("dxos.resource.Config");
|
|
84
|
+
var Config = class {
|
|
85
|
+
_config;
|
|
86
|
+
/**
|
|
87
|
+
* Creates an immutable instance.
|
|
88
|
+
* @constructor
|
|
89
|
+
*/
|
|
90
|
+
constructor(config = {}, ...objects) {
|
|
91
|
+
this._config = validateConfig(defaultsDeep(config, ...objects, {
|
|
92
|
+
version: 1
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns an immutable config JSON object.
|
|
97
|
+
*/
|
|
98
|
+
get values() {
|
|
99
|
+
return this._config;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns the given config property.
|
|
103
|
+
*
|
|
104
|
+
* @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
|
|
105
|
+
* @param defaultValue Default value to return if option is not present in the config.
|
|
106
|
+
* @returns The config value or undefined if the option is not present.
|
|
107
|
+
*/
|
|
108
|
+
get(key, defaultValue) {
|
|
109
|
+
return getDeep(this._config, key.split(".")) ?? defaultValue;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get unique key.
|
|
113
|
+
*/
|
|
114
|
+
find(path, test) {
|
|
115
|
+
const values = getDeep(this._config, path.split("."));
|
|
116
|
+
if (!Array.isArray(values)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
return values.find((value) => isMatch(value, test));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns the given config property or throw if it doesn't exist.
|
|
123
|
+
*
|
|
124
|
+
* @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
|
|
125
|
+
*/
|
|
126
|
+
getOrThrow(key) {
|
|
127
|
+
const value = getDeep(this._config, key.split("."));
|
|
128
|
+
if (!value) {
|
|
129
|
+
throw new Error(`Config option not present: ${key}`);
|
|
130
|
+
}
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
Config = _ts_decorate([
|
|
135
|
+
trace.resource({
|
|
136
|
+
annotation: ConfigResource
|
|
137
|
+
})
|
|
138
|
+
], Config);
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
mapFromKeyValues,
|
|
142
|
+
mapToKeyValues,
|
|
143
|
+
validateConfig,
|
|
144
|
+
ConfigResource,
|
|
145
|
+
Config
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=chunk-WETPAQBA.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/config.ts"],
|
|
4
|
+
"sourcesContent": ["//\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 * 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 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({ message: 'Version not specified' });\n }\n\n if (config?.version !== 1) {\n throw new InvalidConfigError({ message: `Invalid config version: ${config.version}` });\n }\n\n const error = configRootType.protoType.verify(config);\n if (error) {\n throw new InvalidConfigError({ message: String(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,SAASA,eAAe;AACxB,OAAOC,kBAAkB;AACzB,OAAOC,aAAa;AAEpB,SAASC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names": ["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", "mapToKeyValues", "getDeep", "stringify", "validateConfig", "InvalidConfigError", "message", "version", "error", "protoType", "verify", "String", "ConfigResource", "Symbol", "for", "Config", "_config", "objects", "defaultsDeep", "get", "defaultValue", "find", "test", "Array", "isArray", "isMatch", "getOrThrow", "resource", "annotation"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["//\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": ";AAMO,IAAMA,gBAAgB;AACtB,IAAMC,YAAY;AAClB,IAAMC,gBAAgB;",
|
|
6
|
+
"names": ["FILE_DEFAULTS", "FILE_ENVS", "FILE_DYNAMICS"]
|
|
7
|
+
}
|
|
@@ -1,145 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FILE_DEFAULTS,
|
|
3
|
+
FILE_DYNAMICS,
|
|
4
|
+
FILE_ENVS
|
|
5
|
+
} from "./chunk-ZI5JXCYY.mjs";
|
|
6
|
+
import {
|
|
7
|
+
Config,
|
|
8
|
+
ConfigResource,
|
|
9
|
+
mapFromKeyValues,
|
|
10
|
+
mapToKeyValues,
|
|
11
|
+
validateConfig
|
|
12
|
+
} from "./chunk-WETPAQBA.mjs";
|
|
13
|
+
|
|
1
14
|
// src/index.ts
|
|
2
15
|
import * as defs from "@dxos/protocols/proto/dxos/config";
|
|
3
16
|
|
|
4
|
-
// src/config.ts
|
|
5
|
-
import { boolean } from "boolean";
|
|
6
|
-
import defaultsDeep from "lodash.defaultsdeep";
|
|
7
|
-
import isMatch from "lodash.ismatch";
|
|
8
|
-
import { InvalidConfigError } from "@dxos/protocols";
|
|
9
|
-
import { schema } from "@dxos/protocols/proto";
|
|
10
|
-
import { trace } from "@dxos/tracing";
|
|
11
|
-
import { getDeep, setDeep } from "@dxos/util";
|
|
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") r = Reflect.decorate(decorators, target, key, desc);
|
|
15
|
-
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;
|
|
16
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
17
|
-
}
|
|
18
|
-
var configRootType = schema.getCodecForType("dxos.config.Config");
|
|
19
|
-
var mapFromKeyValues = (spec, values) => {
|
|
20
|
-
const config = {};
|
|
21
|
-
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
22
|
-
let value2 = values[key];
|
|
23
|
-
if (value2 !== void 0) {
|
|
24
|
-
if (type) {
|
|
25
|
-
switch (type) {
|
|
26
|
-
case "boolean": {
|
|
27
|
-
value2 = boolean(value2);
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
case "number": {
|
|
31
|
-
value2 = Number(value2);
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
case "string": {
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
case "json": {
|
|
38
|
-
value2 = value2 ? JSON.parse(value2) : null;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
default: {
|
|
42
|
-
throw new Error(`Invalid type: ${type}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
setDeep(config, path.split("."), value2);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return config;
|
|
50
|
-
};
|
|
51
|
-
var mapToKeyValues = (spec, values) => {
|
|
52
|
-
const config = {};
|
|
53
|
-
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
54
|
-
const value2 = getDeep(values, path.split("."));
|
|
55
|
-
if (value2 !== void 0) {
|
|
56
|
-
switch (type) {
|
|
57
|
-
case "json":
|
|
58
|
-
config[key] = JSON.stringify(value2);
|
|
59
|
-
break;
|
|
60
|
-
default:
|
|
61
|
-
config[key] = value2;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return config;
|
|
66
|
-
};
|
|
67
|
-
var validateConfig = (config) => {
|
|
68
|
-
if (!("version" in config)) {
|
|
69
|
-
throw new InvalidConfigError({
|
|
70
|
-
message: "Version not specified"
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
if (config?.version !== 1) {
|
|
74
|
-
throw new InvalidConfigError({
|
|
75
|
-
message: `Invalid config version: ${config.version}`
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
const error = configRootType.protoType.verify(config);
|
|
79
|
-
if (error) {
|
|
80
|
-
throw new InvalidConfigError({
|
|
81
|
-
message: String(error)
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return config;
|
|
85
|
-
};
|
|
86
|
-
var ConfigResource = Symbol.for("dxos.resource.Config");
|
|
87
|
-
var Config = class {
|
|
88
|
-
_config;
|
|
89
|
-
/**
|
|
90
|
-
* Creates an immutable instance.
|
|
91
|
-
* @constructor
|
|
92
|
-
*/
|
|
93
|
-
constructor(config = {}, ...objects) {
|
|
94
|
-
this._config = validateConfig(defaultsDeep(config, ...objects, {
|
|
95
|
-
version: 1
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Returns an immutable config JSON object.
|
|
100
|
-
*/
|
|
101
|
-
get values() {
|
|
102
|
-
return this._config;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Returns the given config property.
|
|
106
|
-
*
|
|
107
|
-
* @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
|
|
108
|
-
* @param defaultValue Default value to return if option is not present in the config.
|
|
109
|
-
* @returns The config value or undefined if the option is not present.
|
|
110
|
-
*/
|
|
111
|
-
get(key, defaultValue) {
|
|
112
|
-
return getDeep(this._config, key.split(".")) ?? defaultValue;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Get unique key.
|
|
116
|
-
*/
|
|
117
|
-
find(path, test) {
|
|
118
|
-
const values = getDeep(this._config, path.split("."));
|
|
119
|
-
if (!Array.isArray(values)) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
return values.find((value2) => isMatch(value2, test));
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Returns the given config property or throw if it doesn't exist.
|
|
126
|
-
*
|
|
127
|
-
* @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
|
|
128
|
-
*/
|
|
129
|
-
getOrThrow(key) {
|
|
130
|
-
const value2 = getDeep(this._config, key.split("."));
|
|
131
|
-
if (!value2) {
|
|
132
|
-
throw new Error(`Config option not present: ${key}`);
|
|
133
|
-
}
|
|
134
|
-
return value2;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
Config = _ts_decorate([
|
|
138
|
-
trace.resource({
|
|
139
|
-
annotation: ConfigResource
|
|
140
|
-
})
|
|
141
|
-
], Config);
|
|
142
|
-
|
|
143
17
|
// src/config-service.ts
|
|
144
18
|
import { dirname } from "@dxos/node-std/path";
|
|
145
19
|
import * as FileSystem from "@effect/platform/FileSystem";
|
|
@@ -150,6 +24,8 @@ import * as Option from "effect/Option";
|
|
|
150
24
|
import * as Yaml from "yaml";
|
|
151
25
|
import { DX_CONFIG, DX_DATA } from "@dxos/client-protocol";
|
|
152
26
|
import { getProfilePath } from "@dxos/client-protocol";
|
|
27
|
+
import { invariant } from "@dxos/invariant";
|
|
28
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/config/src/config-service.ts";
|
|
153
29
|
var memoryConfig = new Config({
|
|
154
30
|
runtime: {
|
|
155
31
|
client: {
|
|
@@ -196,6 +72,7 @@ var defaultConfig = new Config({
|
|
|
196
72
|
});
|
|
197
73
|
var ConfigService = class _ConfigService extends Context.Tag("ConfigService")() {
|
|
198
74
|
static layerMemory = Layer.effect(_ConfigService, Effect.succeed(memoryConfig));
|
|
75
|
+
static fromConfig = (config) => Layer.succeed(_ConfigService, config);
|
|
199
76
|
static load = (args) => {
|
|
200
77
|
const defaultConfigPath = `${getProfilePath(DX_CONFIG, args.profile)}.yml`;
|
|
201
78
|
return Effect.gen(function* () {
|
|
@@ -203,17 +80,11 @@ var ConfigService = class _ConfigService extends Context.Tag("ConfigService")()
|
|
|
203
80
|
const configPath = Option.getOrElse(args.config, () => defaultConfigPath);
|
|
204
81
|
const configContent = yield* fs.readFileString(configPath);
|
|
205
82
|
const configValues = Yaml.parse(configContent);
|
|
206
|
-
return _ConfigService.of(new Config(configValues));
|
|
83
|
+
return _ConfigService.of(new Config(configValues, profileBuiltinDefaults(args.profile).values));
|
|
207
84
|
}).pipe(
|
|
208
85
|
// If the config file doesn't exist, create it.
|
|
209
86
|
Effect.catchTag("SystemError", () => Effect.gen(function* () {
|
|
210
87
|
const configValues = defaultConfig.values;
|
|
211
|
-
{
|
|
212
|
-
configValues.runtime ??= {};
|
|
213
|
-
configValues.runtime.client ??= {};
|
|
214
|
-
configValues.runtime.client.storage ??= {};
|
|
215
|
-
configValues.runtime.client.storage.dataRoot = getProfilePath(configValues.runtime.client.storage.dataRoot ?? DX_DATA, args.profile);
|
|
216
|
-
}
|
|
217
88
|
const fs = yield* FileSystem.FileSystem;
|
|
218
89
|
yield* fs.makeDirectory(dirname(defaultConfigPath), {
|
|
219
90
|
recursive: true
|
|
@@ -224,89 +95,38 @@ var ConfigService = class _ConfigService extends Context.Tag("ConfigService")()
|
|
|
224
95
|
);
|
|
225
96
|
};
|
|
226
97
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const { publicUrl = "", dynamic } = __DXOS_CONFIG__;
|
|
237
|
-
if (!dynamic) {
|
|
238
|
-
log("dynamics disabled");
|
|
239
|
-
return {};
|
|
240
|
-
}
|
|
241
|
-
log("fetching config...", { publicUrl });
|
|
242
|
-
return await fetch(`${publicUrl}${CONFIG_ENDPOINT}`).then((res) => res.json()).catch((error) => {
|
|
243
|
-
log.warn("Failed to fetch dynamic config.", error);
|
|
244
|
-
return {};
|
|
98
|
+
var profileBuiltinDefaults = (profile) => {
|
|
99
|
+
invariant(!profile.endsWith(".yml"), void 0, {
|
|
100
|
+
F: __dxlog_file,
|
|
101
|
+
L: 100,
|
|
102
|
+
S: void 0,
|
|
103
|
+
A: [
|
|
104
|
+
"!profile.endsWith('.yml')",
|
|
105
|
+
""
|
|
106
|
+
]
|
|
245
107
|
});
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
} catch (err) {
|
|
260
|
-
log.warn("Failed to load config", { err });
|
|
261
|
-
}
|
|
262
|
-
return {};
|
|
263
|
-
};
|
|
264
|
-
var Remote = (target, authenticationToken) => {
|
|
265
|
-
if (!target) {
|
|
266
|
-
return {};
|
|
267
|
-
}
|
|
268
|
-
try {
|
|
269
|
-
const url = new URL(target);
|
|
270
|
-
const protocol = url.protocol.slice(0, -1);
|
|
271
|
-
return {
|
|
272
|
-
runtime: {
|
|
273
|
-
client: {
|
|
274
|
-
// TODO(burdon): Remove vault.html.
|
|
275
|
-
remoteSource: url.origin + (protocol.startsWith("http") ? "/vault.html" : ""),
|
|
276
|
-
remoteSourceAuthenticationToken: authenticationToken
|
|
108
|
+
return new Config({
|
|
109
|
+
runtime: {
|
|
110
|
+
client: {
|
|
111
|
+
edgeFeatures: {
|
|
112
|
+
echoReplicator: true,
|
|
113
|
+
feedReplicator: true,
|
|
114
|
+
signaling: true,
|
|
115
|
+
agents: true
|
|
116
|
+
},
|
|
117
|
+
storage: {
|
|
118
|
+
persistent: true,
|
|
119
|
+
dataRoot: getProfilePath(DX_DATA, profile)
|
|
277
120
|
}
|
|
278
121
|
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
log.catch(err);
|
|
282
|
-
return {};
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
// src/savers/browser.js
|
|
287
|
-
import localforage2 from "localforage";
|
|
288
|
-
import { log as log2 } from "@dxos/log";
|
|
289
|
-
var PERFORMING_CONFIG_SAVE = false;
|
|
290
|
-
var SaveConfig = async (config) => {
|
|
291
|
-
if (PERFORMING_CONFIG_SAVE) {
|
|
292
|
-
log2.warn("Already performing config save");
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
PERFORMING_CONFIG_SAVE = true;
|
|
296
|
-
try {
|
|
297
|
-
await localforage2.setItem("dxos.org/settings/config", config);
|
|
298
|
-
} catch (err) {
|
|
299
|
-
log2.warn("Failed to save config", { err });
|
|
300
|
-
return {};
|
|
301
|
-
} finally {
|
|
302
|
-
PERFORMING_CONFIG_SAVE = false;
|
|
303
|
-
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
304
124
|
};
|
|
305
125
|
|
|
306
|
-
// src/
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
126
|
+
// src/index.ts
|
|
127
|
+
export * from "#loaders";
|
|
128
|
+
export * from "#savers";
|
|
129
|
+
export * from "#plugin";
|
|
310
130
|
|
|
311
131
|
// src/preset.ts
|
|
312
132
|
import * as Match from "effect/Match";
|
|
@@ -322,7 +142,7 @@ var configPreset = ({ edge = "main" } = {}) => new Config({
|
|
|
322
142
|
},
|
|
323
143
|
services: {
|
|
324
144
|
edge: {
|
|
325
|
-
url: Match.value(edge).pipe(Match.when("local", () => "http://localhost:8787"), Match.when("dev", () => "https://edge.dxos.workers.dev"), Match.when("main", () => "https://edge-main.dxos.workers.dev"), Match.exhaustive)
|
|
145
|
+
url: Match.value(edge).pipe(Match.when("local", () => "http://localhost:8787"), Match.when("dev", () => "https://edge.dxos.workers.dev"), Match.when("main", () => "https://edge-main.dxos.workers.dev"), Match.when("production", () => "https://edge-production.dxos.workers.dev"), Match.exhaustive)
|
|
326
146
|
}
|
|
327
147
|
}
|
|
328
148
|
}
|
|
@@ -331,16 +151,9 @@ export {
|
|
|
331
151
|
Config,
|
|
332
152
|
ConfigResource,
|
|
333
153
|
ConfigService,
|
|
334
|
-
Defaults,
|
|
335
|
-
Dynamics,
|
|
336
|
-
Envs,
|
|
337
154
|
FILE_DEFAULTS,
|
|
338
155
|
FILE_DYNAMICS,
|
|
339
156
|
FILE_ENVS,
|
|
340
|
-
Local,
|
|
341
|
-
Remote,
|
|
342
|
-
SaveConfig,
|
|
343
|
-
Storage,
|
|
344
157
|
configPreset,
|
|
345
158
|
defaultConfig,
|
|
346
159
|
defs,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/config
|
|
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 './config-service';\nexport * from './loaders';\nexport * from './savers';\nexport * from './plugin';\nexport * from './types';\nexport * from './preset';\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({ message: 'Version not specified' });\n }\n\n if (config?.version !== 1) {\n throw new InvalidConfigError({ message: `Invalid config version: ${config.version}` });\n }\n\n const error = configRootType.protoType.verify(config);\n if (error) {\n throw new InvalidConfigError({ message: String(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", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { dirname } from 'node:path';\n\nimport * as FileSystem from '@effect/platform/FileSystem';\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport * as Yaml from 'yaml';\n\nimport { DX_CONFIG, DX_DATA } from '@dxos/client-protocol';\nimport { getProfilePath } from '@dxos/client-protocol';\n\nimport { Config } from './config';\n\nexport const memoryConfig = new Config({\n runtime: {\n client: {\n edgeFeatures: {\n echoReplicator: true,\n feedReplicator: true,\n signaling: true,\n agents: true,\n },\n },\n },\n});\n\nexport const defaultConfig = new Config({\n runtime: {\n client: {\n edgeFeatures: {\n echoReplicator: true,\n feedReplicator: true,\n signaling: true,\n agents: true,\n },\n storage: {\n persistent: true,\n },\n },\n services: {\n edge: {\n url: 'wss://edge-production.dxos.workers.dev/',\n },\n iceProviders: [\n {\n urls: 'https://edge-production.dxos.workers.dev/ice',\n },\n ],\n ai: {\n server: 'https://ai-service.dxos.workers.dev',\n },\n ipfs: {\n server: 'https://api.ipfs.dxos.network/api/v0',\n gateway: 'https://gateway.ipfs.dxos.network/ipfs',\n },\n },\n },\n});\n\n// TODO(wittjosiah): Factor out.\nexport class ConfigService extends Context.Tag('ConfigService')<ConfigService, Config>() {\n static layerMemory = Layer.effect(ConfigService, Effect.succeed(memoryConfig));\n\n static load = (args: { config: Option.Option<string>; profile: string }) => {\n const defaultConfigPath = `${getProfilePath(DX_CONFIG, args.profile)}.yml`;\n return Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const configPath = Option.getOrElse(args.config, () => defaultConfigPath);\n const configContent = yield* fs.readFileString(configPath);\n const configValues = Yaml.parse(configContent);\n return ConfigService.of(new Config(configValues));\n }).pipe(\n // If the config file doesn't exist, create it.\n Effect.catchTag('SystemError', () =>\n Effect.gen(function* () {\n const configValues = defaultConfig.values;\n {\n // Isolate DX_PROFILE storages.\n configValues.runtime ??= {};\n configValues.runtime.client ??= {};\n configValues.runtime.client.storage ??= {};\n configValues.runtime.client.storage.dataRoot = getProfilePath(\n configValues.runtime.client.storage.dataRoot ?? DX_DATA,\n args.profile,\n );\n }\n\n const fs = yield* FileSystem.FileSystem;\n yield* fs.makeDirectory(dirname(defaultConfigPath), { recursive: true });\n yield* fs.writeFileString(defaultConfigPath, Yaml.stringify(configValues));\n\n return ConfigService.of(new Config(configValues));\n }),\n ),\n );\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 typeof __CONFIG_LOCAL__ !== 'undefined' ? __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 typeof __CONFIG_ENVS__ !== 'undefined' ? __CONFIG_ENVS__ : {};\n};\n\nexport const Defaults = () => {\n return typeof __CONFIG_DEFAULTS__ !== 'undefined' ? __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\nexport const Remote = (target, authenticationToken) => {\n if (!target) {\n return {};\n }\n\n try {\n const url = new URL(target);\n const protocol = url.protocol.slice(0, -1);\n\n return {\n runtime: {\n client: {\n // TODO(burdon): Remove vault.html.\n remoteSource: url.origin + (protocol.startsWith('http') ? '/vault.html' : ''),\n remoteSourceAuthenticationToken: authenticationToken,\n },\n },\n };\n } catch (err) {\n log.catch(err);\n return {};\n }\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", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Match from 'effect/Match';\n\nimport { Config } from './config';\n\nexport type ConfigPresetOptions = {\n /**\n * Edge service.\n * @default main\n */\n edge?: 'local' | 'dev' | 'main';\n};\n\nexport const configPreset = ({ edge = 'main' }: ConfigPresetOptions = {}) =>\n new Config({\n version: 1,\n runtime: {\n client: {\n edgeFeatures: {\n signaling: true,\n echoReplicator: true,\n feedReplicator: true,\n },\n },\n services: {\n edge: {\n url: Match.value(edge).pipe(\n Match.when('local', () => 'http://localhost:8787'),\n Match.when('dev', () => 'https://edge.dxos.workers.dev'),\n Match.when('main', () => 'https://edge-main.dxos.workers.dev'),\n Match.exhaustive,\n ),\n },\n },\n },\n });\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["defs", "
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/config-service.ts", "../../../src/preset.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 './config-service';\nexport * from '#loaders';\nexport * from '#savers';\nexport * from '#plugin';\nexport * from './types';\nexport * from './preset';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { dirname } from 'node:path';\n\nimport * as FileSystem from '@effect/platform/FileSystem';\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport * as Yaml from 'yaml';\n\nimport { DX_CONFIG, DX_DATA } from '@dxos/client-protocol';\nimport { getProfilePath } from '@dxos/client-protocol';\nimport { invariant } from '@dxos/invariant';\n\nimport { Config } from './config';\n\nexport const memoryConfig = new Config({\n runtime: {\n client: {\n edgeFeatures: {\n echoReplicator: true,\n feedReplicator: true,\n signaling: true,\n agents: true,\n },\n },\n },\n});\n\nexport const defaultConfig = new Config({\n runtime: {\n client: {\n edgeFeatures: {\n echoReplicator: true,\n feedReplicator: true,\n signaling: true,\n agents: true,\n },\n storage: {\n persistent: true,\n },\n },\n services: {\n edge: {\n url: 'wss://edge-production.dxos.workers.dev/',\n },\n iceProviders: [\n {\n urls: 'https://edge-production.dxos.workers.dev/ice',\n },\n ],\n ai: {\n server: 'https://ai-service.dxos.workers.dev',\n },\n ipfs: {\n server: 'https://api.ipfs.dxos.network/api/v0',\n gateway: 'https://gateway.ipfs.dxos.network/ipfs',\n },\n },\n },\n});\n\nexport class ConfigService extends Context.Tag('ConfigService')<ConfigService, Config>() {\n static layerMemory = Layer.effect(ConfigService, Effect.succeed(memoryConfig));\n\n static fromConfig = (config: Config) => Layer.succeed(ConfigService, config);\n\n static load = (args: { config: Option.Option<string>; profile: string }) => {\n const defaultConfigPath = `${getProfilePath(DX_CONFIG, args.profile)}.yml`;\n return Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const configPath = Option.getOrElse(args.config, () => defaultConfigPath);\n const configContent = yield* fs.readFileString(configPath);\n const configValues = Yaml.parse(configContent);\n return ConfigService.of(new Config(configValues, profileBuiltinDefaults(args.profile).values));\n }).pipe(\n // If the config file doesn't exist, create it.\n Effect.catchTag('SystemError', () =>\n Effect.gen(function* () {\n const configValues = defaultConfig.values;\n const fs = yield* FileSystem.FileSystem;\n yield* fs.makeDirectory(dirname(defaultConfigPath), { recursive: true });\n yield* fs.writeFileString(defaultConfigPath, Yaml.stringify(configValues));\n\n return ConfigService.of(new Config(configValues));\n }),\n ),\n );\n };\n}\n\n/**\n * Default config for a profile.\n * Always merged with the default config.\n */\nconst profileBuiltinDefaults = (profile: string) => {\n invariant(!profile.endsWith('.yml'));\n\n return new Config({\n runtime: {\n client: {\n edgeFeatures: {\n echoReplicator: true,\n feedReplicator: true,\n signaling: true,\n agents: true,\n },\n storage: {\n persistent: true,\n dataRoot: getProfilePath(DX_DATA, profile),\n },\n },\n },\n });\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Match from 'effect/Match';\n\nimport { Config } from './config';\n\nexport type ConfigPresetOptions = {\n /**\n * Edge service.\n * @default main\n */\n edge?: 'local' | 'dev' | 'main' | 'production';\n};\n\nexport const configPreset = ({ edge = 'main' }: ConfigPresetOptions = {}) =>\n new Config({\n version: 1,\n runtime: {\n client: {\n edgeFeatures: {\n signaling: true,\n echoReplicator: true,\n feedReplicator: true,\n },\n },\n services: {\n edge: {\n url: Match.value(edge).pipe(\n Match.when('local', () => 'http://localhost:8787'),\n Match.when('dev', () => 'https://edge.dxos.workers.dev'),\n Match.when('main', () => 'https://edge-main.dxos.workers.dev'),\n Match.when('production', () => 'https://edge-production.dxos.workers.dev'),\n Match.exhaustive,\n ),\n },\n },\n },\n });\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAKA,YAAYA,UAAU;;;ACDtB,SAASC,eAAe;AAExB,YAAYC,gBAAgB;AAC5B,YAAYC,aAAa;AACzB,YAAYC,YAAY;AACxB,YAAYC,WAAW;AACvB,YAAYC,YAAY;AACxB,YAAYC,UAAU;AAEtB,SAASC,WAAWC,eAAe;AACnC,SAASC,sBAAsB;AAC/B,SAASC,iBAAiB;;AAInB,IAAMC,eAAe,IAAIC,OAAO;EACrCC,SAAS;IACPC,QAAQ;MACNC,cAAc;QACZC,gBAAgB;QAChBC,gBAAgB;QAChBC,WAAW;QACXC,QAAQ;MACV;IACF;EACF;AACF,CAAA;AAEO,IAAMC,gBAAgB,IAAIR,OAAO;EACtCC,SAAS;IACPC,QAAQ;MACNC,cAAc;QACZC,gBAAgB;QAChBC,gBAAgB;QAChBC,WAAW;QACXC,QAAQ;MACV;MACAE,SAAS;QACPC,YAAY;MACd;IACF;IACAC,UAAU;MACRC,MAAM;QACJC,KAAK;MACP;MACAC,cAAc;QACZ;UACEC,MAAM;QACR;;MAEFC,IAAI;QACFC,QAAQ;MACV;MACAC,MAAM;QACJD,QAAQ;QACRE,SAAS;MACX;IACF;EACF;AACF,CAAA;AAEO,IAAMC,gBAAN,MAAMA,uBAA8BC,YAAI,eAAA,EAAA,EAAA;EAC7C,OAAOC,cAAoBC,aAAOH,gBAAsBI,eAAQzB,YAAAA,CAAAA;EAEhE,OAAO0B,aAAa,CAACC,WAAyBF,cAAQJ,gBAAeM,MAAAA;EAErE,OAAOC,OAAO,CAACC,SAAAA;AACb,UAAMC,oBAAoB,GAAGC,eAAeC,WAAWH,KAAKI,OAAO,CAAA;AACnE,WAAcC,WAAI,aAAA;AAChB,YAAMC,KAAK,OAAkBC;AAC7B,YAAMC,aAAoBC,iBAAUT,KAAKF,QAAQ,MAAM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AAA,GAClBA,WAAK,QAAQ,MAAM,oCAAA,GACnBA,WAAK,cAAc,MAAM,0CAAA,GACzBC,gBAAU;MAEpB;IACF;EACF;AACF,CAAA;",
|
|
6
|
+
"names": ["defs", "dirname", "FileSystem", "Context", "Effect", "Layer", "Option", "Yaml", "DX_CONFIG", "DX_DATA", "getProfilePath", "invariant", "memoryConfig", "Config", "runtime", "client", "edgeFeatures", "echoReplicator", "feedReplicator", "signaling", "agents", "defaultConfig", "storage", "persistent", "services", "edge", "url", "iceProviders", "urls", "ai", "server", "ipfs", "gateway", "ConfigService", "Tag", "layerMemory", "effect", "succeed", "fromConfig", "config", "load", "args", "defaultConfigPath", "getProfilePath", "DX_CONFIG", "profile", "gen", "fs", "FileSystem", "configPath", "getOrElse", "configContent", "readFileString", "configValues", "parse", "of", "profileBuiltinDefaults", "values", "pipe", "catchTag", "makeDirectory", "dirname", "recursive", "writeFileString", "stringify", "invariant", "endsWith", "dataRoot", "DX_DATA", "Match", "configPreset", "edge", "Config", "version", "runtime", "client", "edgeFeatures", "signaling", "echoReplicator", "feedReplicator", "services", "url", "value", "pipe", "when", "exhaustive"]
|
|
7
7
|
}
|