@dxos/config 0.8.4-main.bc674ce → 0.8.4-main.bcb3aa67d6
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 → chunk-54W4ZP5U.mjs} +3 -4
- package/dist/lib/browser/chunk-54W4ZP5U.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +7 -7
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/loaders/browser.mjs +1 -1
- package/dist/lib/browser/loaders/browser.mjs.map +1 -1
- package/dist/lib/browser/loaders/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/plugin/index.mjs +1 -1
- package/dist/lib/browser/savers/browser.mjs +1 -1
- package/dist/lib/browser/savers/browser.mjs.map +1 -1
- package/dist/lib/node-esm/{chunk-FVCGIRXP.mjs → chunk-YHGABJ7Y.mjs} +3 -4
- package/dist/lib/node-esm/chunk-YHGABJ7Y.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +7 -7
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/loaders/browser.mjs +1 -1
- package/dist/lib/node-esm/loaders/browser.mjs.map +1 -1
- package/dist/lib/node-esm/loaders/index.mjs +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/plugin/index.mjs +1 -1
- package/dist/lib/node-esm/savers/browser.mjs +1 -1
- package/dist/lib/node-esm/savers/browser.mjs.map +1 -1
- package/dist/plugin/node-esm/{chunk-QQKWALKX.mjs → chunk-4OOW7ZFE.mjs} +3 -4
- package/dist/plugin/node-esm/chunk-4OOW7ZFE.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.map +1 -1
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -13
- package/src/config-service.ts +5 -6
- package/src/config.ts +1 -2
- package/src/loaders/browser.ts +1 -1
- package/src/savers/browser.ts +1 -1
- package/src/testing/build.js +2 -1
- package/dist/lib/browser/chunk-WETPAQBA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-FVCGIRXP.mjs.map +0 -7
- package/dist/plugin/node-esm/chunk-QQKWALKX.mjs.map +0 -7
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// src/config.ts
|
|
2
|
-
import { boolean } from "boolean";
|
|
3
2
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
4
3
|
import isMatch from "lodash.ismatch";
|
|
5
4
|
import { InvalidConfigError } from "@dxos/protocols";
|
|
@@ -21,7 +20,7 @@ var mapFromKeyValues = (spec, values) => {
|
|
|
21
20
|
if (type) {
|
|
22
21
|
switch (type) {
|
|
23
22
|
case "boolean": {
|
|
24
|
-
value =
|
|
23
|
+
value = String(value).toLowerCase() === "true" || value === "1";
|
|
25
24
|
break;
|
|
26
25
|
}
|
|
27
26
|
case "number": {
|
|
@@ -80,7 +79,7 @@ var validateConfig = (config) => {
|
|
|
80
79
|
}
|
|
81
80
|
return config;
|
|
82
81
|
};
|
|
83
|
-
var ConfigResource = Symbol.for("dxos.resource.Config");
|
|
82
|
+
var ConfigResource = /* @__PURE__ */ Symbol.for("dxos.resource.Config");
|
|
84
83
|
var Config = class {
|
|
85
84
|
_config;
|
|
86
85
|
/**
|
|
@@ -144,4 +143,4 @@ export {
|
|
|
144
143
|
ConfigResource,
|
|
145
144
|
Config
|
|
146
145
|
};
|
|
147
|
-
//# sourceMappingURL=chunk-
|
|
146
|
+
//# sourceMappingURL=chunk-54W4ZP5U.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 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 = String(value).toLowerCase() === 'true' || value === '1';\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,OAAOA,kBAAkB;AACzB,OAAOC,aAAa;AAEpB,SAASC,0BAA0B;AACnC,SAASC,cAAc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
|
|
6
|
+
"names": ["defaultsDeep", "isMatch", "InvalidConfigError", "schema", "trace", "getDeep", "setDeep", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "String", "toLowerCase", "Number", "JSON", "parse", "Error", "setDeep", "split", "mapToKeyValues", "getDeep", "stringify", "validateConfig", "InvalidConfigError", "message", "version", "error", "protoType", "verify", "ConfigResource", "Symbol", "for", "Config", "_config", "objects", "defaultsDeep", "get", "defaultValue", "find", "test", "Array", "isArray", "isMatch", "getOrThrow", "resource", "annotation"]
|
|
7
|
+
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
mapFromKeyValues,
|
|
10
10
|
mapToKeyValues,
|
|
11
11
|
validateConfig
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-54W4ZP5U.mjs";
|
|
13
13
|
|
|
14
14
|
// src/index.ts
|
|
15
15
|
import * as defs from "@dxos/protocols/proto/dxos/config";
|
|
@@ -22,8 +22,7 @@ import * as Effect from "effect/Effect";
|
|
|
22
22
|
import * as Layer from "effect/Layer";
|
|
23
23
|
import * as Option from "effect/Option";
|
|
24
24
|
import * as Yaml from "yaml";
|
|
25
|
-
import { DX_CONFIG, DX_DATA } from "@dxos/client-protocol";
|
|
26
|
-
import { getProfilePath } from "@dxos/client-protocol";
|
|
25
|
+
import { DX_CONFIG, DX_DATA, getProfileConfigPath, getProfilePath } from "@dxos/client-protocol";
|
|
27
26
|
import { invariant } from "@dxos/invariant";
|
|
28
27
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/config/src/config-service.ts";
|
|
29
28
|
var memoryConfig = new Config({
|
|
@@ -74,7 +73,7 @@ var ConfigService = class _ConfigService extends Context.Tag("ConfigService")()
|
|
|
74
73
|
static layerMemory = Layer.effect(_ConfigService, Effect.succeed(memoryConfig));
|
|
75
74
|
static fromConfig = (config) => Layer.succeed(_ConfigService, config);
|
|
76
75
|
static load = (args) => {
|
|
77
|
-
const defaultConfigPath =
|
|
76
|
+
const defaultConfigPath = getProfileConfigPath(DX_CONFIG, args.profile);
|
|
78
77
|
return Effect.gen(function* () {
|
|
79
78
|
const fs = yield* FileSystem.FileSystem;
|
|
80
79
|
const configPath = Option.getOrElse(args.config, () => defaultConfigPath);
|
|
@@ -86,10 +85,11 @@ var ConfigService = class _ConfigService extends Context.Tag("ConfigService")()
|
|
|
86
85
|
Effect.catchTag("SystemError", () => Effect.gen(function* () {
|
|
87
86
|
const configValues = defaultConfig.values;
|
|
88
87
|
const fs = yield* FileSystem.FileSystem;
|
|
89
|
-
|
|
88
|
+
const pathToCreate = Option.getOrElse(args.config, () => defaultConfigPath);
|
|
89
|
+
yield* fs.makeDirectory(dirname(pathToCreate), {
|
|
90
90
|
recursive: true
|
|
91
91
|
});
|
|
92
|
-
yield* fs.writeFileString(
|
|
92
|
+
yield* fs.writeFileString(pathToCreate, Yaml.stringify(configValues));
|
|
93
93
|
return _ConfigService.of(new Config(configValues));
|
|
94
94
|
}))
|
|
95
95
|
);
|
|
@@ -98,7 +98,7 @@ var ConfigService = class _ConfigService extends Context.Tag("ConfigService")()
|
|
|
98
98
|
var profileBuiltinDefaults = (profile) => {
|
|
99
99
|
invariant(!profile.endsWith(".yml"), void 0, {
|
|
100
100
|
F: __dxlog_file,
|
|
101
|
-
L:
|
|
101
|
+
L: 99,
|
|
102
102
|
S: void 0,
|
|
103
103
|
A: [
|
|
104
104
|
"!profile.endsWith('.yml')",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
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
|
|
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,
|
|
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", "
|
|
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, getProfileConfigPath, 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 = getProfileConfigPath(DX_CONFIG, args.profile);\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 const pathToCreate = Option.getOrElse(args.config, () => defaultConfigPath);\n yield* fs.makeDirectory(dirname(pathToCreate), { recursive: true });\n yield* fs.writeFileString(pathToCreate, Yaml.stringify(configValues));\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,SAASC,sBAAsBC,sBAAsB;AACzE,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,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;IAAA;EAGN;AACF;AAMA,IAAMG,yBAAyB,CAACX,YAAAA;AAC9BqB,YAAU,CAACrB,QAAQsB,SAAS,MAAA,GAAA,QAAA;;;;;;;;;AAE5B,SAAO,IAAItD,OAAO;IAChBC,SAAS;MACPC,QAAQ;QACNC,cAAc;UACZC,gBAAgB;UAChBC,gBAAgB;UAChBC,WAAW;UACXC,QAAQ;QACV;QACAE,SAAS;UACPC,YAAY;UACZ6C,UAAUC,eAAeC,SAASzB,OAAAA;QACpC;MACF;IACF;EACF,CAAA;AACF;;;ADzGA,cAAc;AACd,cAAc;AACd,cAAc;;;AETd,YAAY0B,WAAW;AAYhB,IAAMC,eAAe,CAAC,EAAEC,OAAO,OAAM,IAA0B,CAAC,MACrE,IAAIC,OAAO;EACTC,SAAS;EACTC,SAAS;IACPC,QAAQ;MACNC,cAAc;QACZC,WAAW;QACXC,gBAAgB;QAChBC,gBAAgB;MAClB;IACF;IACAC,UAAU;MACRT,MAAM;QACJU,KAAWC,YAAMX,IAAAA,EAAMY,KACfC,WAAK,SAAS,MAAM,uBAAA,GACpBA,WAAK,OAAO,MAAM,+BAAA,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", "getProfileConfigPath", "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", "getProfileConfigPath", "DX_CONFIG", "profile", "gen", "fs", "FileSystem", "configPath", "getOrElse", "configContent", "readFileString", "configValues", "parse", "of", "profileBuiltinDefaults", "values", "pipe", "catchTag", "pathToCreate", "makeDirectory", "dirname", "recursive", "writeFileString", "stringify", "invariant", "endsWith", "dataRoot", "getProfilePath", "DX_DATA", "Match", "configPreset", "edge", "Config", "version", "runtime", "client", "edgeFeatures", "signaling", "echoReplicator", "feedReplicator", "services", "url", "value", "pipe", "when", "exhaustive"]
|
|
7
7
|
}
|
|
@@ -44,7 +44,7 @@ var Defaults = (_basePath) => {
|
|
|
44
44
|
};
|
|
45
45
|
var Storage = async () => {
|
|
46
46
|
try {
|
|
47
|
-
const config = await localforage.getItem("dxos.
|
|
47
|
+
const config = await localforage.getItem("org.dxos.settings.config");
|
|
48
48
|
if (config) {
|
|
49
49
|
return config;
|
|
50
50
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/loaders/browser.ts"],
|
|
4
|
-
"sourcesContent": ["//\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';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\ndeclare const __DXOS_CONFIG__: { publicUrl?: string; dynamic?: boolean };\ndeclare const __CONFIG_ENVS__: Partial<ConfigProto> | undefined;\ndeclare const __CONFIG_DEFAULTS__: Partial<ConfigProto> | undefined;\ndeclare const __CONFIG_LOCAL__: Partial<ConfigProto> | undefined;\n\nconst CONFIG_ENDPOINT = '/.well-known/dx/config';\n\nexport const Profile = (_profile = 'default'): Partial<ConfigProto> => ({});\n\nexport const Local = (): Partial<ConfigProto> => {\n return typeof __CONFIG_LOCAL__ !== 'undefined' ? __CONFIG_LOCAL__ : {};\n};\n\nexport const Dynamics = async (): Promise<Partial<ConfigProto>> => {\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 = (_basePath?: string): Partial<ConfigProto> => {\n return typeof __CONFIG_ENVS__ !== 'undefined' ? __CONFIG_ENVS__ : {};\n};\n\nexport const Defaults = (_basePath?: string): Partial<ConfigProto> => {\n return typeof __CONFIG_DEFAULTS__ !== 'undefined' ? __CONFIG_DEFAULTS__ : {};\n};\n\n/**\n * Settings config from browser storage.\n */\nexport const Storage = async (): Promise<Partial<ConfigProto>> => {\n try {\n const config = await localforage.getItem<Partial<ConfigProto>>('dxos.
|
|
4
|
+
"sourcesContent": ["//\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';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\ndeclare const __DXOS_CONFIG__: { publicUrl?: string; dynamic?: boolean };\ndeclare const __CONFIG_ENVS__: Partial<ConfigProto> | undefined;\ndeclare const __CONFIG_DEFAULTS__: Partial<ConfigProto> | undefined;\ndeclare const __CONFIG_LOCAL__: Partial<ConfigProto> | undefined;\n\nconst CONFIG_ENDPOINT = '/.well-known/dx/config';\n\nexport const Profile = (_profile = 'default'): Partial<ConfigProto> => ({});\n\nexport const Local = (): Partial<ConfigProto> => {\n return typeof __CONFIG_LOCAL__ !== 'undefined' ? __CONFIG_LOCAL__ : {};\n};\n\nexport const Dynamics = async (): Promise<Partial<ConfigProto>> => {\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 = (_basePath?: string): Partial<ConfigProto> => {\n return typeof __CONFIG_ENVS__ !== 'undefined' ? __CONFIG_ENVS__ : {};\n};\n\nexport const Defaults = (_basePath?: string): Partial<ConfigProto> => {\n return typeof __CONFIG_DEFAULTS__ !== 'undefined' ? __CONFIG_DEFAULTS__ : {};\n};\n\n/**\n * Settings config from browser storage.\n */\nexport const Storage = async (): Promise<Partial<ConfigProto>> => {\n try {\n const config = await localforage.getItem<Partial<ConfigProto>>('org.dxos.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: string | undefined, authenticationToken?: string): Partial<ConfigProto> => {\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"],
|
|
5
5
|
"mappings": ";AAMA,OAAOA,iBAAiB;AAExB,SAASC,WAAW;AAJuD,IAAA,eAAA;AAY3E,IAAMC,kBAAkB;AAEjB,IAAMC,UAAU,CAACC,WAAW,eAAqC,CAAC;AAElE,IAAMC,QAAQ,MAAA;AACnB,SAAO,OAAOC,qBAAqB,cAAcA,mBAAmB,CAAC;AACvE;AAEO,IAAMC,WAAW,YAAA;AACtB,QAAM,EAAEC,YAAY,IAAIC,QAAO,IAAKC;AACpC,MAAI,CAACD,SAAS;AACZR,QAAI,qBAAA,QAAA;;;;;;AACJ,WAAO,CAAC;EACV;AAEAA,MAAI,sBAAsB;IAAEO;EAAU,GAAA;;;;;;AACtC,SAAO,MAAMG,MAAM,GAAGH,SAAAA,GAAYN,eAAAA,EAAiB,EAChDU,KAAK,CAACC,QAAQA,IAAIC,KAAI,CAAA,EACtBC,MAAM,CAACC,UAAAA;AACNf,QAAIgB,KAAK,mCAAmCD,OAAAA;;;;;;AAC5C,WAAO,CAAC;EACV,CAAA;AACJ;AAEO,IAAME,OAAO,CAACC,cAAAA;AACnB,SAAO,OAAOC,oBAAoB,cAAcA,kBAAkB,CAAC;AACrE;AAEO,IAAMC,WAAW,CAACF,cAAAA;AACvB,SAAO,OAAOG,wBAAwB,cAAcA,sBAAsB,CAAC;AAC7E;AAKO,IAAMC,UAAU,YAAA;AACrB,MAAI;AACF,UAAMC,SAAS,MAAMxB,YAAYyB,QAA8B,0BAAA;AAC/D,QAAID,QAAQ;AACV,aAAOA;IACT;EACF,SAASE,KAAK;AACZzB,QAAIgB,KAAK,yBAAyB;MAAES;IAAI,GAAA;;;;;;EAC1C;AACA,SAAO,CAAC;AACV;AAEO,IAAMC,SAAS,CAACC,QAA4BC,wBAAAA;AACjD,MAAI,CAACD,QAAQ;AACX,WAAO,CAAC;EACV;AAEA,MAAI;AACF,UAAME,MAAM,IAAIC,IAAIH,MAAAA;AACpB,UAAMI,WAAWF,IAAIE,SAASC,MAAM,GAAG,EAAC;AAExC,WAAO;MACLC,SAAS;QACPC,QAAQ;;UAENC,cAAcN,IAAIO,UAAUL,SAASM,WAAW,MAAA,IAAU,gBAAgB;UAC1EC,iCAAiCV;QACnC;MACF;IACF;EACF,SAASH,KAAK;AACZzB,QAAIc,MAAMW,KAAAA,QAAAA;;;;;;AACV,WAAO,CAAC;EACV;AACF;",
|
|
6
6
|
"names": ["localforage", "log", "CONFIG_ENDPOINT", "Profile", "_profile", "Local", "__CONFIG_LOCAL__", "Dynamics", "publicUrl", "dynamic", "__DXOS_CONFIG__", "fetch", "then", "res", "json", "catch", "error", "warn", "Envs", "_basePath", "__CONFIG_ENVS__", "Defaults", "__CONFIG_DEFAULTS__", "Storage", "config", "getItem", "err", "Remote", "target", "authenticationToken", "url", "URL", "protocol", "slice", "runtime", "client", "remoteSource", "origin", "startsWith", "remoteSourceAuthenticationToken"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/config.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/config.ts":{"bytes":16016,"imports":[{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.ismatch","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"@dxos/tracing","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/config-service.ts":{"bytes":12328,"imports":[{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"@effect/platform/FileSystem","kind":"import-statement","external":true},{"path":"effect/Context","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true},{"path":"yaml","kind":"import-statement","external":true},{"path":"@dxos/client-protocol","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"src/config.ts","kind":"import-statement","original":"./config"}],"format":"esm"},"src/types.ts":{"bytes":2735,"imports":[],"format":"esm"},"src/preset.ts":{"bytes":3324,"imports":[{"path":"effect/Match","kind":"import-statement","external":true},{"path":"src/config.ts","kind":"import-statement","original":"./config"}],"format":"esm"},"src/index.ts":{"bytes":1397,"imports":[{"path":"@dxos/protocols/proto/dxos/config","kind":"import-statement","external":true},{"path":"src/config.ts","kind":"import-statement","original":"./config"},{"path":"src/config-service.ts","kind":"import-statement","original":"./config-service"},{"path":"#loaders","kind":"import-statement","external":true},{"path":"#savers","kind":"import-statement","external":true},{"path":"#plugin","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"src/preset.ts","kind":"import-statement","original":"./preset"}],"format":"esm"},"src/loaders/index.ts":{"bytes":8224,"imports":[{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"yaml","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/config.ts","kind":"import-statement","original":"../config"},{"path":"src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"src/loaders/browser.ts":{"bytes":8612,"imports":[{"path":"localforage","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/savers/index.ts":{"bytes":666,"imports":[],"format":"esm"},"src/savers/browser.ts":{"bytes":2707,"imports":[{"path":"localforage","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/plugin/definitions.ts":{"bytes":12031,"imports":[{"path":"@dxos/node-std/child_process","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"yaml","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/config.ts","kind":"import-statement","original":"../config"}],"format":"esm"},"src/plugin/index.ts":{"bytes":504,"imports":[{"path":"src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"},"src/plugin/browser.ts":{"bytes":1003,"imports":[],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":8367},"dist/lib/browser/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-ZI5JXCYY.mjs","kind":"import-statement"},{"path":"dist/lib/browser/chunk-54W4ZP5U.mjs","kind":"import-statement"},{"path":"@dxos/protocols/proto/dxos/config","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"@effect/platform/FileSystem","kind":"import-statement","external":true},{"path":"effect/Context","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true},{"path":"yaml","kind":"import-statement","external":true},{"path":"@dxos/client-protocol","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"#loaders","kind":"import-statement","external":true},{"path":"#savers","kind":"import-statement","external":true},{"path":"#plugin","kind":"import-statement","external":true},{"path":"effect/Match","kind":"import-statement","external":true}],"exports":["Config","ConfigResource","ConfigService","FILE_DEFAULTS","FILE_DYNAMICS","FILE_ENVS","configPreset","defaultConfig","defs","mapFromKeyValues","mapToKeyValues","memoryConfig","validateConfig"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":135},"src/config-service.ts":{"bytesInOutput":3269},"src/preset.ts":{"bytesInOutput":617}},"bytes":4559},"dist/lib/browser/loaders/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4121},"dist/lib/browser/loaders/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-ZI5JXCYY.mjs","kind":"import-statement"},{"path":"dist/lib/browser/chunk-54W4ZP5U.mjs","kind":"import-statement"},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"yaml","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["Defaults","Dynamics","Envs","Local","Profile","Remote","Storage"],"entryPoint":"src/loaders/index.ts","inputs":{"src/loaders/index.ts":{"bytesInOutput":1567}},"bytes":1841},"dist/lib/browser/chunk-ZI5JXCYY.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1813},"dist/lib/browser/chunk-ZI5JXCYY.mjs":{"imports":[],"exports":["FILE_DEFAULTS","FILE_DYNAMICS","FILE_ENVS"],"inputs":{"src/types.ts":{"bytesInOutput":102}},"bytes":221},"dist/lib/browser/loaders/browser.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4405},"dist/lib/browser/loaders/browser.mjs":{"imports":[{"path":"localforage","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["Defaults","Dynamics","Envs","Local","Profile","Remote","Storage"],"entryPoint":"src/loaders/browser.ts","inputs":{"src/loaders/browser.ts":{"bytesInOutput":2148}},"bytes":2295},"dist/lib/browser/savers/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":358},"dist/lib/browser/savers/index.mjs":{"imports":[],"exports":["SaveConfig"],"entryPoint":"src/savers/index.ts","inputs":{"src/savers/index.ts":{"bytesInOutput":35}},"bytes":118},"dist/lib/browser/savers/browser.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1280},"dist/lib/browser/savers/browser.mjs":{"imports":[{"path":"localforage","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["SaveConfig"],"entryPoint":"src/savers/browser.ts","inputs":{"src/savers/browser.ts":{"bytesInOutput":747}},"bytes":834},"dist/lib/browser/plugin/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5718},"dist/lib/browser/plugin/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-54W4ZP5U.mjs","kind":"import-statement"},{"path":"@dxos/node-std/child_process","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"yaml","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["definitions"],"entryPoint":"src/plugin/index.ts","inputs":{"src/plugin/definitions.ts":{"bytesInOutput":3216},"src/plugin/index.ts":{"bytesInOutput":0}},"bytes":3367},"dist/lib/browser/chunk-54W4ZP5U.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7889},"dist/lib/browser/chunk-54W4ZP5U.mjs":{"imports":[{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.ismatch","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"@dxos/tracing","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Config","ConfigResource","mapFromKeyValues","mapToKeyValues","validateConfig"],"inputs":{"src/config.ts":{"bytesInOutput":4083}},"bytes":4240},"dist/lib/browser/plugin/browser.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":494},"dist/lib/browser/plugin/browser.mjs":{"imports":[],"exports":["definitions"],"entryPoint":"src/plugin/browser.ts","inputs":{"src/plugin/browser.ts":{"bytesInOutput":110}},"bytes":198}}}
|
|
@@ -15,7 +15,7 @@ var SaveConfig = async (config) => {
|
|
|
15
15
|
}
|
|
16
16
|
PERFORMING_CONFIG_SAVE = true;
|
|
17
17
|
try {
|
|
18
|
-
await localforage.setItem("dxos.
|
|
18
|
+
await localforage.setItem("org.dxos.settings.config", config);
|
|
19
19
|
} catch (err) {
|
|
20
20
|
log.warn("Failed to save config", {
|
|
21
21
|
err
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/savers/browser.ts"],
|
|
4
|
-
"sourcesContent": ["//\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';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nlet PERFORMING_CONFIG_SAVE = false;\n\nexport const SaveConfig = async (config: ConfigProto): Promise<void> => {\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.
|
|
4
|
+
"sourcesContent": ["//\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';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nlet PERFORMING_CONFIG_SAVE = false;\n\nexport const SaveConfig = async (config: ConfigProto): Promise<void> => {\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('org.dxos.settings.config', config);\n } catch (err) {\n log.warn('Failed to save config', { err });\n } finally {\n PERFORMING_CONFIG_SAVE = false;\n }\n};\n"],
|
|
5
5
|
"mappings": ";AAMA,OAAOA,iBAAiB;AAExB,SAASC,WAAW;AAJuD,IAAA,eAAA;AAO3E,IAAIC,yBAAyB;AAEtB,IAAMC,aAAa,OAAOC,WAAAA;AAC/B,MAAIF,wBAAwB;AAC1BD,QAAII,KAAK,kCAAA,QAAA;;;;;;AACT;EACF;AACAH,2BAAyB;AAEzB,MAAI;AACF,UAAMF,YAAYM,QAAQ,4BAA4BF,MAAAA;EACxD,SAASG,KAAK;AACZN,QAAII,KAAK,yBAAyB;MAAEE;IAAI,GAAA;;;;;;EAC1C,UAAA;AACEL,6BAAyB;EAC3B;AACF;",
|
|
6
6
|
"names": ["localforage", "log", "PERFORMING_CONFIG_SAVE", "SaveConfig", "config", "warn", "setItem", "err"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// src/config.ts
|
|
4
|
-
import { boolean } from "boolean";
|
|
5
4
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
6
5
|
import isMatch from "lodash.ismatch";
|
|
7
6
|
import { InvalidConfigError } from "@dxos/protocols";
|
|
@@ -23,7 +22,7 @@ var mapFromKeyValues = (spec, values) => {
|
|
|
23
22
|
if (type) {
|
|
24
23
|
switch (type) {
|
|
25
24
|
case "boolean": {
|
|
26
|
-
value =
|
|
25
|
+
value = String(value).toLowerCase() === "true" || value === "1";
|
|
27
26
|
break;
|
|
28
27
|
}
|
|
29
28
|
case "number": {
|
|
@@ -82,7 +81,7 @@ var validateConfig = (config) => {
|
|
|
82
81
|
}
|
|
83
82
|
return config;
|
|
84
83
|
};
|
|
85
|
-
var ConfigResource = Symbol.for("dxos.resource.Config");
|
|
84
|
+
var ConfigResource = /* @__PURE__ */ Symbol.for("dxos.resource.Config");
|
|
86
85
|
var Config = class {
|
|
87
86
|
_config;
|
|
88
87
|
/**
|
|
@@ -146,4 +145,4 @@ export {
|
|
|
146
145
|
ConfigResource,
|
|
147
146
|
Config
|
|
148
147
|
};
|
|
149
|
-
//# sourceMappingURL=chunk-
|
|
148
|
+
//# sourceMappingURL=chunk-YHGABJ7Y.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 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 = String(value).toLowerCase() === 'true' || value === '1';\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,OAAOA,kBAAkB;AACzB,OAAOC,aAAa;AAEpB,SAASC,0BAA0B;AACnC,SAASC,cAAc;AAEvB,SAASC,aAAa;AACtB,SAASC,SAASC,eAAe;;;;;;;AAKjC,IAAMC,iBAAiBC,OAAOC,gBAAgB,oBAAA;AAevC,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;AACnB,QAAIK,UAAUC,QAAW;AACvB,UAAIJ,MAAM;AACR,gBAAQA,MAAAA;UACN,KAAK,WAAW;AACdG,oBAAQE,OAAOF,KAAAA,EAAOG,YAAW,MAAO,UAAUH,UAAU;AAC5D;UACF;UAEA,KAAK,UAAU;AACbA,oBAAQI,OAAOJ,KAAAA;AACf;UACF;UAEA,KAAK,UAAU;AACb;UACF;UAEA,KAAK,QAAQ;AACXA,oBAAQA,QAAQK,KAAKC,MAAMN,KAAAA,IAAS;AACpC;UACF;UAEA,SAAS;AACP,kBAAM,IAAIO,MAAM,iBAAiBV,IAAAA,EAAM;UACzC;QAC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jB,QAAQ,KAAKa,SAAS7B,IAAIc,MAAM,GAAA,CAAA,KAASmB;EAClD;;;;EAKAC,KAAcjC,MAAckC,MAA6B;AACvD,UAAMrC,SAASkB,QAAQ,KAAKa,SAAS5B,KAAKa,MAAM,GAAA,CAAA;AAChD,QAAI,CAACsB,MAAMC,QAAQvC,MAAAA,GAAS;AAC1B;IACF;AAEA,WAAOA,OAAOoC,KAAK,CAAC7B,UAAUiC,QAAQjC,OAAO8B,IAAAA,CAAAA;EAC/C;;;;;;EAOAI,WAAgCvC,KAAiE;AAC/F,UAAMK,QAAyDW,QAAQ,KAAKa,SAAS7B,IAAIc,MAAM,GAAA,CAAA;AAC/F,QAAI,CAACT,OAAO;AACV,YAAM,IAAIO,MAAM,8BAA8BZ,GAAAA,EAAK;IACrD;AACA,WAAOK;EACT;AACF;;QAzDOmC,SAAAA;IAAWC,YAAYhB;;;",
|
|
6
|
+
"names": ["defaultsDeep", "isMatch", "InvalidConfigError", "schema", "trace", "getDeep", "setDeep", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "String", "toLowerCase", "Number", "JSON", "parse", "Error", "setDeep", "split", "mapToKeyValues", "getDeep", "stringify", "validateConfig", "InvalidConfigError", "message", "version", "error", "protoType", "verify", "ConfigResource", "Symbol", "for", "Config", "_config", "objects", "defaultsDeep", "get", "defaultValue", "find", "test", "Array", "isArray", "isMatch", "getOrThrow", "resource", "annotation"]
|
|
7
|
+
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
mapFromKeyValues,
|
|
11
11
|
mapToKeyValues,
|
|
12
12
|
validateConfig
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-YHGABJ7Y.mjs";
|
|
14
14
|
|
|
15
15
|
// src/index.ts
|
|
16
16
|
import * as defs from "@dxos/protocols/proto/dxos/config";
|
|
@@ -23,8 +23,7 @@ import * as Effect from "effect/Effect";
|
|
|
23
23
|
import * as Layer from "effect/Layer";
|
|
24
24
|
import * as Option from "effect/Option";
|
|
25
25
|
import * as Yaml from "yaml";
|
|
26
|
-
import { DX_CONFIG, DX_DATA } from "@dxos/client-protocol";
|
|
27
|
-
import { getProfilePath } from "@dxos/client-protocol";
|
|
26
|
+
import { DX_CONFIG, DX_DATA, getProfileConfigPath, getProfilePath } from "@dxos/client-protocol";
|
|
28
27
|
import { invariant } from "@dxos/invariant";
|
|
29
28
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/config/src/config-service.ts";
|
|
30
29
|
var memoryConfig = new Config({
|
|
@@ -75,7 +74,7 @@ var ConfigService = class _ConfigService extends Context.Tag("ConfigService")()
|
|
|
75
74
|
static layerMemory = Layer.effect(_ConfigService, Effect.succeed(memoryConfig));
|
|
76
75
|
static fromConfig = (config) => Layer.succeed(_ConfigService, config);
|
|
77
76
|
static load = (args) => {
|
|
78
|
-
const defaultConfigPath =
|
|
77
|
+
const defaultConfigPath = getProfileConfigPath(DX_CONFIG, args.profile);
|
|
79
78
|
return Effect.gen(function* () {
|
|
80
79
|
const fs = yield* FileSystem.FileSystem;
|
|
81
80
|
const configPath = Option.getOrElse(args.config, () => defaultConfigPath);
|
|
@@ -87,10 +86,11 @@ var ConfigService = class _ConfigService extends Context.Tag("ConfigService")()
|
|
|
87
86
|
Effect.catchTag("SystemError", () => Effect.gen(function* () {
|
|
88
87
|
const configValues = defaultConfig.values;
|
|
89
88
|
const fs = yield* FileSystem.FileSystem;
|
|
90
|
-
|
|
89
|
+
const pathToCreate = Option.getOrElse(args.config, () => defaultConfigPath);
|
|
90
|
+
yield* fs.makeDirectory(dirname(pathToCreate), {
|
|
91
91
|
recursive: true
|
|
92
92
|
});
|
|
93
|
-
yield* fs.writeFileString(
|
|
93
|
+
yield* fs.writeFileString(pathToCreate, Yaml.stringify(configValues));
|
|
94
94
|
return _ConfigService.of(new Config(configValues));
|
|
95
95
|
}))
|
|
96
96
|
);
|
|
@@ -99,7 +99,7 @@ var ConfigService = class _ConfigService extends Context.Tag("ConfigService")()
|
|
|
99
99
|
var profileBuiltinDefaults = (profile) => {
|
|
100
100
|
invariant(!profile.endsWith(".yml"), void 0, {
|
|
101
101
|
F: __dxlog_file,
|
|
102
|
-
L:
|
|
102
|
+
L: 99,
|
|
103
103
|
S: void 0,
|
|
104
104
|
A: [
|
|
105
105
|
"!profile.endsWith('.yml')",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
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
|
|
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,
|
|
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", "
|
|
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, getProfileConfigPath, 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 = getProfileConfigPath(DX_CONFIG, args.profile);\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 const pathToCreate = Option.getOrElse(args.config, () => defaultConfigPath);\n yield* fs.makeDirectory(dirname(pathToCreate), { recursive: true });\n yield* fs.writeFileString(pathToCreate, Yaml.stringify(configValues));\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,SAASC,sBAAsBC,sBAAsB;AACzE,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,oBAAoBC,qBAAqBC,WAAWH,KAAKI,OAAO;AACtE,WAAcC,WAAI,aAAA;AAChB,YAAMC,KAAK,OAAkBC;AAC7B,YAAMC,aAAoBC,iBAAUT,KAAKF,QAAQ,MAAMG,iBAAAA;AACvD,YAAMS,gBAAgB,O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K,OAAO,MAAM,+BAAA,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", "getProfileConfigPath", "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", "getProfileConfigPath", "DX_CONFIG", "profile", "gen", "fs", "FileSystem", "configPath", "getOrElse", "configContent", "readFileString", "configValues", "parse", "of", "profileBuiltinDefaults", "values", "pipe", "catchTag", "pathToCreate", "makeDirectory", "dirname", "recursive", "writeFileString", "stringify", "invariant", "endsWith", "dataRoot", "getProfilePath", "DX_DATA", "Match", "configPreset", "edge", "Config", "version", "runtime", "client", "edgeFeatures", "signaling", "echoReplicator", "feedReplicator", "services", "url", "value", "pipe", "when", "exhaustive"]
|
|
7
7
|
}
|
|
@@ -46,7 +46,7 @@ var Defaults = (_basePath) => {
|
|
|
46
46
|
};
|
|
47
47
|
var Storage = async () => {
|
|
48
48
|
try {
|
|
49
|
-
const config = await localforage.getItem("dxos.
|
|
49
|
+
const config = await localforage.getItem("org.dxos.settings.config");
|
|
50
50
|
if (config) {
|
|
51
51
|
return config;
|
|
52
52
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/loaders/browser.ts"],
|
|
4
|
-
"sourcesContent": ["//\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';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\ndeclare const __DXOS_CONFIG__: { publicUrl?: string; dynamic?: boolean };\ndeclare const __CONFIG_ENVS__: Partial<ConfigProto> | undefined;\ndeclare const __CONFIG_DEFAULTS__: Partial<ConfigProto> | undefined;\ndeclare const __CONFIG_LOCAL__: Partial<ConfigProto> | undefined;\n\nconst CONFIG_ENDPOINT = '/.well-known/dx/config';\n\nexport const Profile = (_profile = 'default'): Partial<ConfigProto> => ({});\n\nexport const Local = (): Partial<ConfigProto> => {\n return typeof __CONFIG_LOCAL__ !== 'undefined' ? __CONFIG_LOCAL__ : {};\n};\n\nexport const Dynamics = async (): Promise<Partial<ConfigProto>> => {\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 = (_basePath?: string): Partial<ConfigProto> => {\n return typeof __CONFIG_ENVS__ !== 'undefined' ? __CONFIG_ENVS__ : {};\n};\n\nexport const Defaults = (_basePath?: string): Partial<ConfigProto> => {\n return typeof __CONFIG_DEFAULTS__ !== 'undefined' ? __CONFIG_DEFAULTS__ : {};\n};\n\n/**\n * Settings config from browser storage.\n */\nexport const Storage = async (): Promise<Partial<ConfigProto>> => {\n try {\n const config = await localforage.getItem<Partial<ConfigProto>>('dxos.
|
|
4
|
+
"sourcesContent": ["//\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';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\ndeclare const __DXOS_CONFIG__: { publicUrl?: string; dynamic?: boolean };\ndeclare const __CONFIG_ENVS__: Partial<ConfigProto> | undefined;\ndeclare const __CONFIG_DEFAULTS__: Partial<ConfigProto> | undefined;\ndeclare const __CONFIG_LOCAL__: Partial<ConfigProto> | undefined;\n\nconst CONFIG_ENDPOINT = '/.well-known/dx/config';\n\nexport const Profile = (_profile = 'default'): Partial<ConfigProto> => ({});\n\nexport const Local = (): Partial<ConfigProto> => {\n return typeof __CONFIG_LOCAL__ !== 'undefined' ? __CONFIG_LOCAL__ : {};\n};\n\nexport const Dynamics = async (): Promise<Partial<ConfigProto>> => {\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 = (_basePath?: string): Partial<ConfigProto> => {\n return typeof __CONFIG_ENVS__ !== 'undefined' ? __CONFIG_ENVS__ : {};\n};\n\nexport const Defaults = (_basePath?: string): Partial<ConfigProto> => {\n return typeof __CONFIG_DEFAULTS__ !== 'undefined' ? __CONFIG_DEFAULTS__ : {};\n};\n\n/**\n * Settings config from browser storage.\n */\nexport const Storage = async (): Promise<Partial<ConfigProto>> => {\n try {\n const config = await localforage.getItem<Partial<ConfigProto>>('org.dxos.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: string | undefined, authenticationToken?: string): Partial<ConfigProto> => {\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"],
|
|
5
5
|
"mappings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,SAAS;QACPC,QAAQ;;UAENC,cAAcN,IAAIO,UAAUL,SAASM,WAAW,MAAA,IAAU,gBAAgB;UAC1EC,iCAAiCV;QACnC;MACF;IACF;EACF,SAASH,KAAK;AACZzB,QAAIc,MAAMW,KAAAA,QAAAA;;;;;;AACV,WAAO,CAAC;EACV;AACF;",
|
|
6
6
|
"names": ["localforage", "log", "CONFIG_ENDPOINT", "Profile", "_profile", "Local", "__CONFIG_LOCAL__", "Dynamics", "publicUrl", "dynamic", "__DXOS_CONFIG__", "fetch", "then", "res", "json", "catch", "error", "warn", "Envs", "_basePath", "__CONFIG_ENVS__", "Defaults", "__CONFIG_DEFAULTS__", "Storage", "config", "getItem", "err", "Remote", "target", "authenticationToken", "url", "URL", "protocol", "slice", "runtime", "client", "remoteSource", "origin", "startsWith", "remoteSourceAuthenticationToken"]
|
|
7
7
|
}
|