@dxos/config 0.8.3 → 0.8.4-main.1068cf700f
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 +138 -209
- 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 +135 -290
- 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-PAFU3TJI.mjs → chunk-QQKWALKX.mjs} +33 -16
- package/dist/plugin/node-esm/chunk-QQKWALKX.mjs.map +7 -0
- package/dist/plugin/node-esm/esbuild-plugin.mjs +2 -2
- package/dist/plugin/node-esm/meta.json +1 -1
- package/dist/plugin/node-esm/rollup-plugin.mjs +2 -2
- package/dist/plugin/node-esm/vite-plugin.mjs +6 -6
- package/dist/plugin/node-esm/vite-plugin.mjs.map +3 -3
- package/dist/types/src/config-service.d.ts +19 -0
- package/dist/types/src/config-service.d.ts.map +1 -0
- 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 +5 -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/loaders/index.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/plugin/definitions.d.ts +3 -3
- package/dist/types/src/plugin/definitions.d.ts.map +1 -1
- package/dist/types/src/plugin/index.d.ts +1 -1
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/types.d.ts +4 -0
- package/dist/types/src/plugin/types.d.ts.map +1 -1
- package/dist/types/src/plugin/vite-plugin.d.ts +1 -1
- package/dist/types/src/plugin/vite-plugin.d.ts.map +1 -1
- package/dist/types/src/preset.d.ts +10 -0
- package/dist/types/src/preset.d.ts.map +1 -0
- 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 +49 -15
- package/src/config-service.ts +118 -0
- package/src/config.ts +3 -5
- package/src/index.ts +5 -3
- package/src/loaders/{browser.js → browser.ts} +15 -9
- package/src/loaders/index.ts +3 -2
- package/src/plugin/browser.ts +11 -0
- package/src/plugin/definitions.ts +8 -6
- package/src/plugin/index.ts +1 -1
- package/src/plugin/types.ts +5 -0
- package/src/plugin/vite-plugin.ts +9 -5
- package/src/preset.ts +40 -0
- package/src/savers/{browser.js → browser.ts} +2 -2
- package/src/testing/build.js +1 -1
- package/README.yml +0 -1
- package/dist/lib/node/index.cjs +0 -357
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/plugin/node/chunk-SLXRWZWZ.cjs +0 -249
- package/dist/plugin/node/chunk-SLXRWZWZ.cjs.map +0 -7
- package/dist/plugin/node/esbuild-plugin.cjs +0 -45
- package/dist/plugin/node/esbuild-plugin.cjs.map +0 -7
- package/dist/plugin/node/meta.json +0 -1
- package/dist/plugin/node/rollup-plugin.cjs +0 -39
- package/dist/plugin/node/rollup-plugin.cjs.map +0 -7
- package/dist/plugin/node/vite-plugin.cjs +0 -50
- package/dist/plugin/node/vite-plugin.cjs.map +0 -7
- package/dist/plugin/node-esm/chunk-PAFU3TJI.mjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,15 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/config",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.1068cf700f",
|
|
4
4
|
"description": "Config utilities",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
10
14
|
"type": "module",
|
|
15
|
+
"imports": {
|
|
16
|
+
"#loaders": {
|
|
17
|
+
"source": {
|
|
18
|
+
"browser": "./src/loaders/browser.ts",
|
|
19
|
+
"default": "./src/loaders/index.ts"
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/types/src/loaders/index.d.ts",
|
|
22
|
+
"browser": "./dist/lib/browser/loaders/browser.mjs",
|
|
23
|
+
"default": "./dist/lib/node-esm/loaders/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"#savers": {
|
|
26
|
+
"source": {
|
|
27
|
+
"browser": "./src/savers/browser.ts",
|
|
28
|
+
"default": "./src/savers/index.ts"
|
|
29
|
+
},
|
|
30
|
+
"types": "./dist/types/src/savers/index.d.ts",
|
|
31
|
+
"browser": "./dist/lib/browser/savers/browser.mjs",
|
|
32
|
+
"default": "./dist/lib/node-esm/savers/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"#plugin": {
|
|
35
|
+
"source": {
|
|
36
|
+
"browser": "./src/plugin/browser.ts",
|
|
37
|
+
"default": "./src/plugin/index.ts"
|
|
38
|
+
},
|
|
39
|
+
"types": "./dist/types/src/plugin/index.d.ts",
|
|
40
|
+
"browser": "./dist/lib/browser/plugin/browser.mjs",
|
|
41
|
+
"default": "./dist/lib/node-esm/plugin/index.mjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
11
44
|
"exports": {
|
|
12
45
|
".": {
|
|
46
|
+
"source": "./src/index.ts",
|
|
13
47
|
"types": "./dist/types/src/index.d.ts",
|
|
14
48
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
49
|
"node": {
|
|
@@ -18,28 +52,25 @@
|
|
|
18
52
|
}
|
|
19
53
|
},
|
|
20
54
|
"./esbuild-plugin": {
|
|
55
|
+
"source": "./src/esbuild-plugin/index.ts",
|
|
21
56
|
"types": "./dist/types/src/esbuild-plugin/index.d.ts",
|
|
22
57
|
"import": "./dist/plugin/node-esm/esbuild-plugin.mjs",
|
|
23
58
|
"require": "./dist/plugin/node/esbuild-plugin.cjs"
|
|
24
59
|
},
|
|
25
60
|
"./rollup-plugin": {
|
|
61
|
+
"source": "./src/rollup-plugin/index.ts",
|
|
26
62
|
"types": "./dist/types/src/rollup-plugin/index.d.ts",
|
|
27
63
|
"import": "./dist/plugin/node-esm/rollup-plugin.mjs",
|
|
28
64
|
"require": "./dist/plugin/node/rollup-plugin.cjs"
|
|
29
65
|
},
|
|
30
66
|
"./vite-plugin": {
|
|
67
|
+
"source": "./src/vite-plugin/index.ts",
|
|
31
68
|
"types": "./dist/types/src/vite-plugin/index.d.ts",
|
|
32
69
|
"import": "./dist/plugin/node-esm/vite-plugin.mjs",
|
|
33
70
|
"require": "./dist/plugin/node/vite-plugin.cjs"
|
|
34
71
|
}
|
|
35
72
|
},
|
|
36
73
|
"main": "dist/lib/node/index.cjs",
|
|
37
|
-
"browser": {
|
|
38
|
-
"./src/loaders/index.ts": "./src/loaders/browser.js",
|
|
39
|
-
"./src/savers/index.ts": "./src/savers/browser.js",
|
|
40
|
-
"./src/plugin/index.ts": false,
|
|
41
|
-
"./dist/lib/node/index.cjs": "./dist/lib/browser/index.mjs"
|
|
42
|
-
},
|
|
43
74
|
"types": "dist/types/src/index.d.ts",
|
|
44
75
|
"typesVersions": {
|
|
45
76
|
"*": {
|
|
@@ -59,20 +90,23 @@
|
|
|
59
90
|
"src"
|
|
60
91
|
],
|
|
61
92
|
"dependencies": {
|
|
93
|
+
"@effect/platform": "0.94.4",
|
|
62
94
|
"boolean": "^3.0.1",
|
|
63
|
-
"
|
|
95
|
+
"effect": "3.19.16",
|
|
64
96
|
"localforage": "^1.10.0",
|
|
65
97
|
"lodash.defaultsdeep": "^4.6.1",
|
|
66
98
|
"lodash.ismatch": "^4.4.0",
|
|
67
99
|
"pkg-up": "^3.1.0",
|
|
68
|
-
"
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/tracing": "0.8.
|
|
100
|
+
"yaml": "^2.7.0",
|
|
101
|
+
"@dxos/client-protocol": "0.8.4-main.1068cf700f",
|
|
102
|
+
"@dxos/invariant": "0.8.4-main.1068cf700f",
|
|
103
|
+
"@dxos/log": "0.8.4-main.1068cf700f",
|
|
104
|
+
"@dxos/tracing": "0.8.4-main.1068cf700f",
|
|
105
|
+
"@dxos/protocols": "0.8.4-main.1068cf700f",
|
|
106
|
+
"@dxos/util": "0.8.4-main.1068cf700f",
|
|
107
|
+
"@dxos/node-std": "0.8.4-main.1068cf700f"
|
|
73
108
|
},
|
|
74
109
|
"devDependencies": {
|
|
75
|
-
"@types/js-yaml": "^4.0.5",
|
|
76
110
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
77
111
|
"@types/lodash.ismatch": "^4.4.9",
|
|
78
112
|
"webpack": "^5.88.2"
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { dirname } from 'node:path';
|
|
6
|
+
|
|
7
|
+
import * as FileSystem from '@effect/platform/FileSystem';
|
|
8
|
+
import * as Context from 'effect/Context';
|
|
9
|
+
import * as Effect from 'effect/Effect';
|
|
10
|
+
import * as Layer from 'effect/Layer';
|
|
11
|
+
import * as Option from 'effect/Option';
|
|
12
|
+
import * as Yaml from 'yaml';
|
|
13
|
+
|
|
14
|
+
import { DX_CONFIG, DX_DATA } from '@dxos/client-protocol';
|
|
15
|
+
import { getProfilePath } from '@dxos/client-protocol';
|
|
16
|
+
import { invariant } from '@dxos/invariant';
|
|
17
|
+
|
|
18
|
+
import { Config } from './config';
|
|
19
|
+
|
|
20
|
+
export const memoryConfig = new Config({
|
|
21
|
+
runtime: {
|
|
22
|
+
client: {
|
|
23
|
+
edgeFeatures: {
|
|
24
|
+
echoReplicator: true,
|
|
25
|
+
feedReplicator: true,
|
|
26
|
+
signaling: true,
|
|
27
|
+
agents: true,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const defaultConfig = new Config({
|
|
34
|
+
runtime: {
|
|
35
|
+
client: {
|
|
36
|
+
edgeFeatures: {
|
|
37
|
+
echoReplicator: true,
|
|
38
|
+
feedReplicator: true,
|
|
39
|
+
signaling: true,
|
|
40
|
+
agents: true,
|
|
41
|
+
},
|
|
42
|
+
storage: {
|
|
43
|
+
persistent: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
services: {
|
|
47
|
+
edge: {
|
|
48
|
+
url: 'wss://edge-production.dxos.workers.dev/',
|
|
49
|
+
},
|
|
50
|
+
iceProviders: [
|
|
51
|
+
{
|
|
52
|
+
urls: 'https://edge-production.dxos.workers.dev/ice',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
ai: {
|
|
56
|
+
server: 'https://ai-service.dxos.workers.dev',
|
|
57
|
+
},
|
|
58
|
+
ipfs: {
|
|
59
|
+
server: 'https://api.ipfs.dxos.network/api/v0',
|
|
60
|
+
gateway: 'https://gateway.ipfs.dxos.network/ipfs',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export class ConfigService extends Context.Tag('ConfigService')<ConfigService, Config>() {
|
|
67
|
+
static layerMemory = Layer.effect(ConfigService, Effect.succeed(memoryConfig));
|
|
68
|
+
|
|
69
|
+
static fromConfig = (config: Config) => Layer.succeed(ConfigService, config);
|
|
70
|
+
|
|
71
|
+
static load = (args: { config: Option.Option<string>; profile: string }) => {
|
|
72
|
+
const defaultConfigPath = `${getProfilePath(DX_CONFIG, args.profile)}.yml`;
|
|
73
|
+
return Effect.gen(function* () {
|
|
74
|
+
const fs = yield* FileSystem.FileSystem;
|
|
75
|
+
const configPath = Option.getOrElse(args.config, () => defaultConfigPath);
|
|
76
|
+
const configContent = yield* fs.readFileString(configPath);
|
|
77
|
+
const configValues = Yaml.parse(configContent);
|
|
78
|
+
return ConfigService.of(new Config(configValues, profileBuiltinDefaults(args.profile).values));
|
|
79
|
+
}).pipe(
|
|
80
|
+
// If the config file doesn't exist, create it.
|
|
81
|
+
Effect.catchTag('SystemError', () =>
|
|
82
|
+
Effect.gen(function* () {
|
|
83
|
+
const configValues = defaultConfig.values;
|
|
84
|
+
const fs = yield* FileSystem.FileSystem;
|
|
85
|
+
yield* fs.makeDirectory(dirname(defaultConfigPath), { recursive: true });
|
|
86
|
+
yield* fs.writeFileString(defaultConfigPath, Yaml.stringify(configValues));
|
|
87
|
+
|
|
88
|
+
return ConfigService.of(new Config(configValues));
|
|
89
|
+
}),
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Default config for a profile.
|
|
97
|
+
* Always merged with the default config.
|
|
98
|
+
*/
|
|
99
|
+
const profileBuiltinDefaults = (profile: string) => {
|
|
100
|
+
invariant(!profile.endsWith('.yml'));
|
|
101
|
+
|
|
102
|
+
return new Config({
|
|
103
|
+
runtime: {
|
|
104
|
+
client: {
|
|
105
|
+
edgeFeatures: {
|
|
106
|
+
echoReplicator: true,
|
|
107
|
+
feedReplicator: true,
|
|
108
|
+
signaling: true,
|
|
109
|
+
agents: true,
|
|
110
|
+
},
|
|
111
|
+
storage: {
|
|
112
|
+
persistent: true,
|
|
113
|
+
dataRoot: getProfilePath(DX_DATA, profile),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
};
|
package/src/config.ts
CHANGED
|
@@ -19,7 +19,6 @@ const configRootType = schema.getCodecForType('dxos.config.Config');
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Maps the given objects onto a flattened set of (key x values).
|
|
22
|
-
*
|
|
23
22
|
* Expects parsed yaml content of the form:
|
|
24
23
|
*
|
|
25
24
|
* ```
|
|
@@ -36,7 +35,6 @@ export const mapFromKeyValues = (spec: MappingSpec, values: Record<string, any>)
|
|
|
36
35
|
|
|
37
36
|
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
38
37
|
let value = values[key];
|
|
39
|
-
|
|
40
38
|
if (value !== undefined) {
|
|
41
39
|
if (type) {
|
|
42
40
|
switch (type) {
|
|
@@ -101,16 +99,16 @@ export const mapToKeyValues = (spec: MappingSpec, values: any) => {
|
|
|
101
99
|
*/
|
|
102
100
|
export const validateConfig = (config: ConfigProto): ConfigProto => {
|
|
103
101
|
if (!('version' in config)) {
|
|
104
|
-
throw new InvalidConfigError('Version not specified');
|
|
102
|
+
throw new InvalidConfigError({ message: 'Version not specified' });
|
|
105
103
|
}
|
|
106
104
|
|
|
107
105
|
if (config?.version !== 1) {
|
|
108
|
-
throw new InvalidConfigError(`Invalid config version: ${config.version}`);
|
|
106
|
+
throw new InvalidConfigError({ message: `Invalid config version: ${config.version}` });
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
const error = configRootType.protoType.verify(config);
|
|
112
110
|
if (error) {
|
|
113
|
-
throw new InvalidConfigError(error);
|
|
111
|
+
throw new InvalidConfigError({ message: String(error) });
|
|
114
112
|
}
|
|
115
113
|
|
|
116
114
|
return config;
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,9 @@ export * as defs from '@dxos/protocols/proto/dxos/config';
|
|
|
8
8
|
export { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';
|
|
9
9
|
|
|
10
10
|
export * from './config';
|
|
11
|
-
export * from './
|
|
12
|
-
export * from '
|
|
13
|
-
export * from '
|
|
11
|
+
export * from './config-service';
|
|
12
|
+
export * from '#loaders';
|
|
13
|
+
export * from '#savers';
|
|
14
|
+
export * from '#plugin';
|
|
14
15
|
export * from './types';
|
|
16
|
+
export * from './preset';
|
|
@@ -4,19 +4,25 @@
|
|
|
4
4
|
|
|
5
5
|
/* THIS FILE WILL BE LOADED BY CONTEXT REPLACEMENT PLUGIN IN BROWSER ENVS. */
|
|
6
6
|
|
|
7
|
-
/* global __DXOS_CONFIG__ __CONFIG_ENVS__ __CONFIG_DEFAULTS__ __CONFIG_LOCAL__ */
|
|
8
|
-
|
|
9
7
|
import localforage from 'localforage';
|
|
10
8
|
|
|
11
9
|
import { log } from '@dxos/log';
|
|
10
|
+
import { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';
|
|
11
|
+
|
|
12
|
+
declare const __DXOS_CONFIG__: { publicUrl?: string; dynamic?: boolean };
|
|
13
|
+
declare const __CONFIG_ENVS__: Partial<ConfigProto> | undefined;
|
|
14
|
+
declare const __CONFIG_DEFAULTS__: Partial<ConfigProto> | undefined;
|
|
15
|
+
declare const __CONFIG_LOCAL__: Partial<ConfigProto> | undefined;
|
|
12
16
|
|
|
13
17
|
const CONFIG_ENDPOINT = '/.well-known/dx/config';
|
|
14
18
|
|
|
15
|
-
export const
|
|
19
|
+
export const Profile = (_profile = 'default'): Partial<ConfigProto> => ({});
|
|
20
|
+
|
|
21
|
+
export const Local = (): Partial<ConfigProto> => {
|
|
16
22
|
return typeof __CONFIG_LOCAL__ !== 'undefined' ? __CONFIG_LOCAL__ : {};
|
|
17
23
|
};
|
|
18
24
|
|
|
19
|
-
export const Dynamics = async () => {
|
|
25
|
+
export const Dynamics = async (): Promise<Partial<ConfigProto>> => {
|
|
20
26
|
const { publicUrl = '', dynamic } = __DXOS_CONFIG__;
|
|
21
27
|
if (!dynamic) {
|
|
22
28
|
log('dynamics disabled');
|
|
@@ -32,20 +38,20 @@ export const Dynamics = async () => {
|
|
|
32
38
|
});
|
|
33
39
|
};
|
|
34
40
|
|
|
35
|
-
export const Envs = () => {
|
|
41
|
+
export const Envs = (_basePath?: string): Partial<ConfigProto> => {
|
|
36
42
|
return typeof __CONFIG_ENVS__ !== 'undefined' ? __CONFIG_ENVS__ : {};
|
|
37
43
|
};
|
|
38
44
|
|
|
39
|
-
export const Defaults = () => {
|
|
45
|
+
export const Defaults = (_basePath?: string): Partial<ConfigProto> => {
|
|
40
46
|
return typeof __CONFIG_DEFAULTS__ !== 'undefined' ? __CONFIG_DEFAULTS__ : {};
|
|
41
47
|
};
|
|
42
48
|
|
|
43
49
|
/**
|
|
44
50
|
* Settings config from browser storage.
|
|
45
51
|
*/
|
|
46
|
-
export const Storage = async () => {
|
|
52
|
+
export const Storage = async (): Promise<Partial<ConfigProto>> => {
|
|
47
53
|
try {
|
|
48
|
-
const config = await localforage.getItem('dxos.org/settings/config');
|
|
54
|
+
const config = await localforage.getItem<Partial<ConfigProto>>('dxos.org/settings/config');
|
|
49
55
|
if (config) {
|
|
50
56
|
return config;
|
|
51
57
|
}
|
|
@@ -55,7 +61,7 @@ export const Storage = async () => {
|
|
|
55
61
|
return {};
|
|
56
62
|
};
|
|
57
63
|
|
|
58
|
-
export const Remote = (target, authenticationToken) => {
|
|
64
|
+
export const Remote = (target: string | undefined, authenticationToken?: string): Partial<ConfigProto> => {
|
|
59
65
|
if (!target) {
|
|
60
66
|
return {};
|
|
61
67
|
}
|
package/src/loaders/index.ts
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import yaml from 'js-yaml';
|
|
6
5
|
import fs from 'node:fs';
|
|
7
6
|
import path from 'node:path';
|
|
8
7
|
|
|
8
|
+
import { parse } from 'yaml';
|
|
9
|
+
|
|
9
10
|
import { log } from '@dxos/log';
|
|
10
11
|
import { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';
|
|
11
12
|
|
|
@@ -18,7 +19,7 @@ const DEFAULT_BASE_PATH = path.resolve(process.cwd(), 'config');
|
|
|
18
19
|
|
|
19
20
|
const maybeLoadFile = (file: string): any => {
|
|
20
21
|
try {
|
|
21
|
-
return
|
|
22
|
+
return parse(fs.readFileSync(file, { encoding: 'utf8' }));
|
|
22
23
|
} catch (err: any) {
|
|
23
24
|
// Ignored.
|
|
24
25
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// Browser stub for plugin module - plugins are build-time only.
|
|
6
|
+
|
|
7
|
+
export type * from './types';
|
|
8
|
+
|
|
9
|
+
export const definitions = (): Record<string, unknown> => {
|
|
10
|
+
throw new Error('Config plugin definitions are not available in the browser');
|
|
11
|
+
};
|
|
@@ -2,18 +2,21 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import yaml from 'js-yaml';
|
|
6
5
|
import { execSync } from 'node:child_process';
|
|
7
6
|
import { readFileSync } from 'node:fs';
|
|
8
7
|
import { resolve } from 'node:path';
|
|
8
|
+
|
|
9
9
|
import pkgUp from 'pkg-up';
|
|
10
|
+
import { parse } from 'yaml';
|
|
10
11
|
|
|
12
|
+
import { invariant } from '@dxos/invariant';
|
|
11
13
|
import { log } from '@dxos/log';
|
|
12
14
|
import { setDeep } from '@dxos/util';
|
|
13
15
|
|
|
14
|
-
import { type ConfigPluginOpts } from './types';
|
|
15
16
|
import { mapFromKeyValues } from '../config';
|
|
16
17
|
|
|
18
|
+
import { type ConfigPluginOpts } from './types';
|
|
19
|
+
|
|
17
20
|
const CWD = process.cwd();
|
|
18
21
|
|
|
19
22
|
export const definitions = ({
|
|
@@ -28,17 +31,16 @@ export const definitions = ({
|
|
|
28
31
|
__CONFIG_DEFAULTS__: configPath?.length ? configPath : resolve(CWD, 'dx.yml'),
|
|
29
32
|
__CONFIG_ENVS__: envPath?.length ? envPath : resolve(CWD, 'dx-env.yml'),
|
|
30
33
|
} as { [key: string]: string };
|
|
31
|
-
|
|
32
34
|
if (mode !== 'production') {
|
|
33
35
|
KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? resolve(CWD, 'dx-local.yml');
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
return Object.entries(KEYS_TO_FILE).reduce(
|
|
37
39
|
(prev, [key, value]) => {
|
|
40
|
+
invariant(key);
|
|
38
41
|
let content = {};
|
|
39
|
-
|
|
40
42
|
try {
|
|
41
|
-
content =
|
|
43
|
+
content = parse(readFileSync(value, 'utf-8')) as any;
|
|
42
44
|
|
|
43
45
|
// Map environment variables to config values.
|
|
44
46
|
if (key === '__CONFIG_ENVS__') {
|
|
@@ -85,10 +87,10 @@ export const definitions = ({
|
|
|
85
87
|
};
|
|
86
88
|
},
|
|
87
89
|
{
|
|
88
|
-
__DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },
|
|
89
90
|
__CONFIG_DEFAULTS__: {},
|
|
90
91
|
__CONFIG_ENVS__: {},
|
|
91
92
|
__CONFIG_LOCAL__: {},
|
|
93
|
+
__DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },
|
|
92
94
|
},
|
|
93
95
|
);
|
|
94
96
|
};
|
package/src/plugin/index.ts
CHANGED
package/src/plugin/types.ts
CHANGED
|
@@ -3,17 +3,21 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { resolve } from 'node:path';
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
import { type Plugin } from 'vite';
|
|
7
8
|
|
|
8
9
|
import { definitions } from './definitions';
|
|
9
10
|
import { type ConfigPluginOpts } from './types';
|
|
10
11
|
|
|
11
12
|
export const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => ({
|
|
12
13
|
name: 'dxos-config',
|
|
13
|
-
config: (
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
14
|
+
config: () => {
|
|
15
|
+
// Update paths.
|
|
16
|
+
const configPath = options.root && resolve(options.root, options.configPath ?? 'dx.yml');
|
|
17
|
+
const envPath = options.root && resolve(options.root, options.envPath ?? 'dx-env.yml');
|
|
18
|
+
// TODO(burdon): Change to dx-dev.yml?
|
|
19
|
+
const devPath = options.root && resolve(options.root, options.devPath ?? 'dx-local.yml');
|
|
20
|
+
|
|
17
21
|
const define = Object.entries(definitions({ ...options, configPath, envPath, devPath })).reduce(
|
|
18
22
|
(define, [key, value]) => {
|
|
19
23
|
define[key] = JSON.stringify(value);
|
package/src/preset.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Match from 'effect/Match';
|
|
6
|
+
|
|
7
|
+
import { Config } from './config';
|
|
8
|
+
|
|
9
|
+
export type ConfigPresetOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* Edge service.
|
|
12
|
+
* @default main
|
|
13
|
+
*/
|
|
14
|
+
edge?: 'local' | 'dev' | 'main' | 'production';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const configPreset = ({ edge = 'main' }: ConfigPresetOptions = {}) =>
|
|
18
|
+
new Config({
|
|
19
|
+
version: 1,
|
|
20
|
+
runtime: {
|
|
21
|
+
client: {
|
|
22
|
+
edgeFeatures: {
|
|
23
|
+
signaling: true,
|
|
24
|
+
echoReplicator: true,
|
|
25
|
+
feedReplicator: true,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
services: {
|
|
29
|
+
edge: {
|
|
30
|
+
url: Match.value(edge).pipe(
|
|
31
|
+
Match.when('local', () => 'http://localhost:8787'),
|
|
32
|
+
Match.when('dev', () => 'https://edge.dxos.workers.dev'),
|
|
33
|
+
Match.when('main', () => 'https://edge-main.dxos.workers.dev'),
|
|
34
|
+
Match.when('production', () => 'https://edge-production.dxos.workers.dev'),
|
|
35
|
+
Match.exhaustive,
|
|
36
|
+
),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
import localforage from 'localforage';
|
|
8
8
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
|
+
import { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';
|
|
10
11
|
|
|
11
12
|
let PERFORMING_CONFIG_SAVE = false;
|
|
12
13
|
|
|
13
|
-
export const SaveConfig = async (config) => {
|
|
14
|
+
export const SaveConfig = async (config: ConfigProto): Promise<void> => {
|
|
14
15
|
if (PERFORMING_CONFIG_SAVE) {
|
|
15
16
|
log.warn('Already performing config save');
|
|
16
17
|
return;
|
|
@@ -21,7 +22,6 @@ export const SaveConfig = async (config) => {
|
|
|
21
22
|
await localforage.setItem('dxos.org/settings/config', config);
|
|
22
23
|
} catch (err) {
|
|
23
24
|
log.warn('Failed to save config', { err });
|
|
24
|
-
return {};
|
|
25
25
|
} finally {
|
|
26
26
|
PERFORMING_CONFIG_SAVE = false;
|
|
27
27
|
}
|
package/src/testing/build.js
CHANGED
package/README.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
apiReferenceUrl: https://docs.dxos.org/api/@dxos/config
|