@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.
Files changed (97) hide show
  1. package/dist/lib/browser/chunk-WETPAQBA.mjs +147 -0
  2. package/dist/lib/browser/chunk-WETPAQBA.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-ZI5JXCYY.mjs +11 -0
  4. package/dist/lib/browser/chunk-ZI5JXCYY.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +138 -209
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/loaders/browser.mjs +98 -0
  8. package/dist/lib/browser/loaders/browser.mjs.map +7 -0
  9. package/dist/lib/browser/loaders/index.mjs +71 -0
  10. package/dist/lib/browser/loaders/index.mjs.map +7 -0
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/plugin/browser.mjs +8 -0
  13. package/dist/lib/browser/plugin/browser.mjs.map +7 -0
  14. package/dist/lib/browser/plugin/index.mjs +116 -0
  15. package/dist/lib/browser/plugin/index.mjs.map +7 -0
  16. package/dist/lib/browser/savers/browser.mjs +35 -0
  17. package/dist/lib/browser/savers/browser.mjs.map +7 -0
  18. package/dist/lib/browser/savers/index.mjs +7 -0
  19. package/dist/lib/browser/savers/index.mjs.map +7 -0
  20. package/dist/lib/node-esm/chunk-FVCGIRXP.mjs +149 -0
  21. package/dist/lib/node-esm/chunk-FVCGIRXP.mjs.map +7 -0
  22. package/dist/lib/node-esm/chunk-ODEKAZ4J.mjs +13 -0
  23. package/dist/lib/node-esm/chunk-ODEKAZ4J.mjs.map +7 -0
  24. package/dist/lib/node-esm/index.mjs +135 -290
  25. package/dist/lib/node-esm/index.mjs.map +4 -4
  26. package/dist/lib/node-esm/loaders/browser.mjs +100 -0
  27. package/dist/lib/node-esm/loaders/browser.mjs.map +7 -0
  28. package/dist/lib/node-esm/loaders/index.mjs +72 -0
  29. package/dist/lib/node-esm/loaders/index.mjs.map +7 -0
  30. package/dist/lib/node-esm/meta.json +1 -1
  31. package/dist/lib/node-esm/plugin/browser.mjs +10 -0
  32. package/dist/lib/node-esm/plugin/browser.mjs.map +7 -0
  33. package/dist/lib/node-esm/plugin/index.mjs +117 -0
  34. package/dist/lib/node-esm/plugin/index.mjs.map +7 -0
  35. package/dist/lib/node-esm/savers/browser.mjs +37 -0
  36. package/dist/lib/node-esm/savers/browser.mjs.map +7 -0
  37. package/dist/lib/node-esm/savers/index.mjs +9 -0
  38. package/dist/lib/node-esm/savers/index.mjs.map +7 -0
  39. package/dist/plugin/node-esm/{chunk-PAFU3TJI.mjs → chunk-QQKWALKX.mjs} +33 -16
  40. package/dist/plugin/node-esm/chunk-QQKWALKX.mjs.map +7 -0
  41. package/dist/plugin/node-esm/esbuild-plugin.mjs +2 -2
  42. package/dist/plugin/node-esm/meta.json +1 -1
  43. package/dist/plugin/node-esm/rollup-plugin.mjs +2 -2
  44. package/dist/plugin/node-esm/vite-plugin.mjs +6 -6
  45. package/dist/plugin/node-esm/vite-plugin.mjs.map +3 -3
  46. package/dist/types/src/config-service.d.ts +19 -0
  47. package/dist/types/src/config-service.d.ts.map +1 -0
  48. package/dist/types/src/config.d.ts +0 -1
  49. package/dist/types/src/config.d.ts.map +1 -1
  50. package/dist/types/src/index.d.ts +5 -3
  51. package/dist/types/src/index.d.ts.map +1 -1
  52. package/dist/types/src/loaders/browser.d.ts +11 -15
  53. package/dist/types/src/loaders/browser.d.ts.map +1 -1
  54. package/dist/types/src/loaders/index.d.ts.map +1 -1
  55. package/dist/types/src/plugin/browser.d.ts +3 -0
  56. package/dist/types/src/plugin/browser.d.ts.map +1 -0
  57. package/dist/types/src/plugin/definitions.d.ts +3 -3
  58. package/dist/types/src/plugin/definitions.d.ts.map +1 -1
  59. package/dist/types/src/plugin/index.d.ts +1 -1
  60. package/dist/types/src/plugin/index.d.ts.map +1 -1
  61. package/dist/types/src/plugin/types.d.ts +4 -0
  62. package/dist/types/src/plugin/types.d.ts.map +1 -1
  63. package/dist/types/src/plugin/vite-plugin.d.ts +1 -1
  64. package/dist/types/src/plugin/vite-plugin.d.ts.map +1 -1
  65. package/dist/types/src/preset.d.ts +10 -0
  66. package/dist/types/src/preset.d.ts.map +1 -0
  67. package/dist/types/src/savers/browser.d.ts +2 -1
  68. package/dist/types/src/savers/browser.d.ts.map +1 -1
  69. package/dist/types/tsconfig.tsbuildinfo +1 -1
  70. package/package.json +49 -15
  71. package/src/config-service.ts +118 -0
  72. package/src/config.ts +3 -5
  73. package/src/index.ts +5 -3
  74. package/src/loaders/{browser.js → browser.ts} +15 -9
  75. package/src/loaders/index.ts +3 -2
  76. package/src/plugin/browser.ts +11 -0
  77. package/src/plugin/definitions.ts +8 -6
  78. package/src/plugin/index.ts +1 -1
  79. package/src/plugin/types.ts +5 -0
  80. package/src/plugin/vite-plugin.ts +9 -5
  81. package/src/preset.ts +40 -0
  82. package/src/savers/{browser.js → browser.ts} +2 -2
  83. package/src/testing/build.js +1 -1
  84. package/README.yml +0 -1
  85. package/dist/lib/node/index.cjs +0 -357
  86. package/dist/lib/node/index.cjs.map +0 -7
  87. package/dist/lib/node/meta.json +0 -1
  88. package/dist/plugin/node/chunk-SLXRWZWZ.cjs +0 -249
  89. package/dist/plugin/node/chunk-SLXRWZWZ.cjs.map +0 -7
  90. package/dist/plugin/node/esbuild-plugin.cjs +0 -45
  91. package/dist/plugin/node/esbuild-plugin.cjs.map +0 -7
  92. package/dist/plugin/node/meta.json +0 -1
  93. package/dist/plugin/node/rollup-plugin.cjs +0 -39
  94. package/dist/plugin/node/rollup-plugin.cjs.map +0 -7
  95. package/dist/plugin/node/vite-plugin.cjs +0 -50
  96. package/dist/plugin/node/vite-plugin.cjs.map +0 -7
  97. package/dist/plugin/node-esm/chunk-PAFU3TJI.mjs.map +0 -7
@@ -0,0 +1,149 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // src/config.ts
4
+ import { boolean } from "boolean";
5
+ import defaultsDeep from "lodash.defaultsdeep";
6
+ import isMatch from "lodash.ismatch";
7
+ import { InvalidConfigError } from "@dxos/protocols";
8
+ import { schema } from "@dxos/protocols/proto";
9
+ import { trace } from "@dxos/tracing";
10
+ import { getDeep, setDeep } from "@dxos/util";
11
+ function _ts_decorate(decorators, target, key, desc) {
12
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
14
+ 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;
15
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
16
+ }
17
+ var configRootType = schema.getCodecForType("dxos.config.Config");
18
+ var mapFromKeyValues = (spec, values) => {
19
+ const config = {};
20
+ for (const [key, { path, type }] of Object.entries(spec)) {
21
+ let value = values[key];
22
+ if (value !== void 0) {
23
+ if (type) {
24
+ switch (type) {
25
+ case "boolean": {
26
+ value = boolean(value);
27
+ break;
28
+ }
29
+ case "number": {
30
+ value = Number(value);
31
+ break;
32
+ }
33
+ case "string": {
34
+ break;
35
+ }
36
+ case "json": {
37
+ value = value ? JSON.parse(value) : null;
38
+ break;
39
+ }
40
+ default: {
41
+ throw new Error(`Invalid type: ${type}`);
42
+ }
43
+ }
44
+ }
45
+ setDeep(config, path.split("."), value);
46
+ }
47
+ }
48
+ return config;
49
+ };
50
+ var mapToKeyValues = (spec, values) => {
51
+ const config = {};
52
+ for (const [key, { path, type }] of Object.entries(spec)) {
53
+ const value = getDeep(values, path.split("."));
54
+ if (value !== void 0) {
55
+ switch (type) {
56
+ case "json":
57
+ config[key] = JSON.stringify(value);
58
+ break;
59
+ default:
60
+ config[key] = value;
61
+ }
62
+ }
63
+ }
64
+ return config;
65
+ };
66
+ var validateConfig = (config) => {
67
+ if (!("version" in config)) {
68
+ throw new InvalidConfigError({
69
+ message: "Version not specified"
70
+ });
71
+ }
72
+ if (config?.version !== 1) {
73
+ throw new InvalidConfigError({
74
+ message: `Invalid config version: ${config.version}`
75
+ });
76
+ }
77
+ const error = configRootType.protoType.verify(config);
78
+ if (error) {
79
+ throw new InvalidConfigError({
80
+ message: String(error)
81
+ });
82
+ }
83
+ return config;
84
+ };
85
+ var ConfigResource = Symbol.for("dxos.resource.Config");
86
+ var Config = class {
87
+ _config;
88
+ /**
89
+ * Creates an immutable instance.
90
+ * @constructor
91
+ */
92
+ constructor(config = {}, ...objects) {
93
+ this._config = validateConfig(defaultsDeep(config, ...objects, {
94
+ version: 1
95
+ }));
96
+ }
97
+ /**
98
+ * Returns an immutable config JSON object.
99
+ */
100
+ get values() {
101
+ return this._config;
102
+ }
103
+ /**
104
+ * Returns the given config property.
105
+ *
106
+ * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
107
+ * @param defaultValue Default value to return if option is not present in the config.
108
+ * @returns The config value or undefined if the option is not present.
109
+ */
110
+ get(key, defaultValue) {
111
+ return getDeep(this._config, key.split(".")) ?? defaultValue;
112
+ }
113
+ /**
114
+ * Get unique key.
115
+ */
116
+ find(path, test) {
117
+ const values = getDeep(this._config, path.split("."));
118
+ if (!Array.isArray(values)) {
119
+ return;
120
+ }
121
+ return values.find((value) => isMatch(value, test));
122
+ }
123
+ /**
124
+ * Returns the given config property or throw if it doesn't exist.
125
+ *
126
+ * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
127
+ */
128
+ getOrThrow(key) {
129
+ const value = getDeep(this._config, key.split("."));
130
+ if (!value) {
131
+ throw new Error(`Config option not present: ${key}`);
132
+ }
133
+ return value;
134
+ }
135
+ };
136
+ Config = _ts_decorate([
137
+ trace.resource({
138
+ annotation: ConfigResource
139
+ })
140
+ ], Config);
141
+
142
+ export {
143
+ mapFromKeyValues,
144
+ mapToKeyValues,
145
+ validateConfig,
146
+ ConfigResource,
147
+ Config
148
+ };
149
+ //# sourceMappingURL=chunk-FVCGIRXP.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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,GAAAA,EAAK;IACrD;AACA,WAAOK;EACT;AACF;;QAzDOmC,SAAAA;IAAWC,YAAYhB;;;",
6
+ "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,13 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // src/types.ts
4
+ var FILE_DEFAULTS = "defaults.yml";
5
+ var FILE_ENVS = "envs-map.yml";
6
+ var FILE_DYNAMICS = "config.yml";
7
+
8
+ export {
9
+ FILE_DEFAULTS,
10
+ FILE_ENVS,
11
+ FILE_DYNAMICS
12
+ };
13
+ //# sourceMappingURL=chunk-ODEKAZ4J.mjs.map
@@ -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,321 +1,166 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ FILE_DEFAULTS,
4
+ FILE_DYNAMICS,
5
+ FILE_ENVS
6
+ } from "./chunk-ODEKAZ4J.mjs";
7
+ import {
8
+ Config,
9
+ ConfigResource,
10
+ mapFromKeyValues,
11
+ mapToKeyValues,
12
+ validateConfig
13
+ } from "./chunk-FVCGIRXP.mjs";
2
14
 
3
- // packages/sdk/config/src/index.ts
15
+ // src/index.ts
4
16
  import * as defs from "@dxos/protocols/proto/dxos/config";
5
17
 
6
- // packages/sdk/config/src/config.ts
7
- import { boolean } from "boolean";
8
- import defaultsDeep from "lodash.defaultsdeep";
9
- import isMatch from "lodash.ismatch";
10
- import { InvalidConfigError } from "@dxos/protocols";
11
- import { schema } from "@dxos/protocols/proto";
12
- import { trace } from "@dxos/tracing";
13
- import { getDeep, setDeep } from "@dxos/util";
14
- function _ts_decorate(decorators, target, key, desc) {
15
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
- 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;
18
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19
- }
20
- var configRootType = schema.getCodecForType("dxos.config.Config");
21
- var mapFromKeyValues = (spec, values) => {
22
- const config = {};
23
- for (const [key, { path: path2, type }] of Object.entries(spec)) {
24
- let value = values[key];
25
- if (value !== void 0) {
26
- if (type) {
27
- switch (type) {
28
- case "boolean": {
29
- value = boolean(value);
30
- break;
31
- }
32
- case "number": {
33
- value = Number(value);
34
- break;
35
- }
36
- case "string": {
37
- break;
38
- }
39
- case "json": {
40
- value = value ? JSON.parse(value) : null;
41
- break;
42
- }
43
- default: {
44
- throw new Error(`Invalid type: ${type}`);
45
- }
46
- }
18
+ // src/config-service.ts
19
+ import { dirname } from "node:path";
20
+ import * as FileSystem from "@effect/platform/FileSystem";
21
+ import * as Context from "effect/Context";
22
+ import * as Effect from "effect/Effect";
23
+ import * as Layer from "effect/Layer";
24
+ import * as Option from "effect/Option";
25
+ import * as Yaml from "yaml";
26
+ import { DX_CONFIG, DX_DATA } from "@dxos/client-protocol";
27
+ import { getProfilePath } from "@dxos/client-protocol";
28
+ import { invariant } from "@dxos/invariant";
29
+ var __dxlog_file = "/__w/dxos/dxos/packages/sdk/config/src/config-service.ts";
30
+ var memoryConfig = new Config({
31
+ runtime: {
32
+ client: {
33
+ edgeFeatures: {
34
+ echoReplicator: true,
35
+ feedReplicator: true,
36
+ signaling: true,
37
+ agents: true
47
38
  }
48
- setDeep(config, path2.split("."), value);
49
39
  }
50
40
  }
51
- return config;
52
- };
53
- var mapToKeyValues = (spec, values) => {
54
- const config = {};
55
- for (const [key, { path: path2, type }] of Object.entries(spec)) {
56
- const value = getDeep(values, path2.split("."));
57
- if (value !== void 0) {
58
- switch (type) {
59
- case "json":
60
- config[key] = JSON.stringify(value);
61
- break;
62
- default:
63
- config[key] = value;
41
+ });
42
+ var defaultConfig = new Config({
43
+ runtime: {
44
+ client: {
45
+ edgeFeatures: {
46
+ echoReplicator: true,
47
+ feedReplicator: true,
48
+ signaling: true,
49
+ agents: true
50
+ },
51
+ storage: {
52
+ persistent: true
53
+ }
54
+ },
55
+ services: {
56
+ edge: {
57
+ url: "wss://edge-production.dxos.workers.dev/"
58
+ },
59
+ iceProviders: [
60
+ {
61
+ urls: "https://edge-production.dxos.workers.dev/ice"
62
+ }
63
+ ],
64
+ ai: {
65
+ server: "https://ai-service.dxos.workers.dev"
66
+ },
67
+ ipfs: {
68
+ server: "https://api.ipfs.dxos.network/api/v0",
69
+ gateway: "https://gateway.ipfs.dxos.network/ipfs"
64
70
  }
65
71
  }
66
72
  }
67
- return config;
68
- };
69
- var validateConfig = (config) => {
70
- if (!("version" in config)) {
71
- throw new InvalidConfigError("Version not specified");
72
- }
73
- if (config?.version !== 1) {
74
- throw new InvalidConfigError(`Invalid config version: ${config.version}`);
75
- }
76
- const error = configRootType.protoType.verify(config);
77
- if (error) {
78
- throw new InvalidConfigError(error);
79
- }
80
- return config;
81
- };
82
- var ConfigResource = Symbol.for("dxos.resource.Config");
83
- var Config = class {
84
- /**
85
- * Creates an immutable instance.
86
- * @constructor
87
- */
88
- constructor(config = {}, ...objects) {
89
- this._config = validateConfig(defaultsDeep(config, ...objects, {
90
- version: 1
91
- }));
92
- }
93
- /**
94
- * Returns an immutable config JSON object.
95
- */
96
- get values() {
97
- return this._config;
98
- }
99
- /**
100
- * Returns the given config property.
101
- *
102
- * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
103
- * @param defaultValue Default value to return if option is not present in the config.
104
- * @returns The config value or undefined if the option is not present.
105
- */
106
- get(key, defaultValue) {
107
- return getDeep(this._config, key.split(".")) ?? defaultValue;
108
- }
109
- /**
110
- * Get unique key.
111
- */
112
- find(path2, test) {
113
- const values = getDeep(this._config, path2.split("."));
114
- if (!Array.isArray(values)) {
115
- return;
116
- }
117
- return values.find((value) => isMatch(value, test));
118
- }
119
- /**
120
- * Returns the given config property or throw if it doesn't exist.
121
- *
122
- * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
123
- */
124
- getOrThrow(key) {
125
- const value = getDeep(this._config, key.split("."));
126
- if (!value) {
127
- throw new Error(`Config option not present: ${key}`);
128
- }
129
- return value;
130
- }
131
- };
132
- Config = _ts_decorate([
133
- trace.resource({
134
- annotation: ConfigResource
135
- })
136
- ], Config);
137
-
138
- // packages/sdk/config/src/loaders/index.ts
139
- import yaml from "js-yaml";
140
- import fs from "node:fs";
141
- import path from "node:path";
142
- import { log } from "@dxos/log";
143
-
144
- // packages/sdk/config/src/types.ts
145
- var FILE_DEFAULTS = "defaults.yml";
146
- var FILE_ENVS = "envs-map.yml";
147
- var FILE_DYNAMICS = "config.yml";
148
-
149
- // packages/sdk/config/src/loaders/index.ts
150
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/config/src/loaders/index.ts";
151
- var DEFAULT_BASE_PATH = path.resolve(process.cwd(), "config");
152
- var maybeLoadFile = (file) => {
153
- try {
154
- return yaml.load(fs.readFileSync(file, {
155
- encoding: "utf8"
156
- }));
157
- } catch (err) {
158
- }
159
- };
160
- var Profile = (profile = "default") => {
161
- const configFile = path.join(process.env.HOME ?? "~", `.config/dx/profile/${profile}.yml`);
162
- return maybeLoadFile(configFile);
163
- };
164
- var Local = () => ({});
165
- var Dynamics = () => ({});
166
- var Envs = (basePath = DEFAULT_BASE_PATH) => {
167
- const content = maybeLoadFile(path.resolve(basePath, FILE_ENVS));
168
- return content ? mapFromKeyValues(content, process.env) : {};
73
+ });
74
+ var ConfigService = class _ConfigService extends Context.Tag("ConfigService")() {
75
+ static layerMemory = Layer.effect(_ConfigService, Effect.succeed(memoryConfig));
76
+ static fromConfig = (config) => Layer.succeed(_ConfigService, config);
77
+ static load = (args) => {
78
+ const defaultConfigPath = `${getProfilePath(DX_CONFIG, args.profile)}.yml`;
79
+ return Effect.gen(function* () {
80
+ const fs = yield* FileSystem.FileSystem;
81
+ const configPath = Option.getOrElse(args.config, () => defaultConfigPath);
82
+ const configContent = yield* fs.readFileString(configPath);
83
+ const configValues = Yaml.parse(configContent);
84
+ return _ConfigService.of(new Config(configValues, profileBuiltinDefaults(args.profile).values));
85
+ }).pipe(
86
+ // If the config file doesn't exist, create it.
87
+ Effect.catchTag("SystemError", () => Effect.gen(function* () {
88
+ const configValues = defaultConfig.values;
89
+ const fs = yield* FileSystem.FileSystem;
90
+ yield* fs.makeDirectory(dirname(defaultConfigPath), {
91
+ recursive: true
92
+ });
93
+ yield* fs.writeFileString(defaultConfigPath, Yaml.stringify(configValues));
94
+ return _ConfigService.of(new Config(configValues));
95
+ }))
96
+ );
97
+ };
169
98
  };
170
- var Defaults = (basePath = DEFAULT_BASE_PATH) => maybeLoadFile(path.resolve(basePath, FILE_DEFAULTS)) ?? {};
171
- var Storage = async () => ({});
172
- var Remote = (target, authenticationToken) => {
173
- if (!target) {
174
- return {};
175
- }
176
- try {
177
- const url = new URL(target);
178
- const protocol = url.protocol.slice(0, -1);
179
- return {
180
- runtime: {
181
- client: {
182
- // TODO(burdon): Remove vault.html.
183
- remoteSource: url.origin + (protocol.startsWith("http") ? "/vault.html" : ""),
184
- remoteSourceAuthenticationToken: authenticationToken
99
+ var profileBuiltinDefaults = (profile) => {
100
+ invariant(!profile.endsWith(".yml"), void 0, {
101
+ F: __dxlog_file,
102
+ L: 100,
103
+ S: void 0,
104
+ A: [
105
+ "!profile.endsWith('.yml')",
106
+ ""
107
+ ]
108
+ });
109
+ return new Config({
110
+ runtime: {
111
+ client: {
112
+ edgeFeatures: {
113
+ echoReplicator: true,
114
+ feedReplicator: true,
115
+ signaling: true,
116
+ agents: true
117
+ },
118
+ storage: {
119
+ persistent: true,
120
+ dataRoot: getProfilePath(DX_DATA, profile)
185
121
  }
186
122
  }
187
- };
188
- } catch (err) {
189
- log.catch(err, void 0, {
190
- F: __dxlog_file,
191
- L: 87,
192
- S: void 0,
193
- C: (f, a) => f(...a)
194
- });
195
- return {};
196
- }
123
+ }
124
+ });
197
125
  };
198
126
 
199
- // packages/sdk/config/src/savers/index.ts
200
- var SaveConfig = async (_) => {
201
- };
127
+ // src/index.ts
128
+ export * from "#loaders";
129
+ export * from "#savers";
130
+ export * from "#plugin";
202
131
 
203
- // packages/sdk/config/src/plugin/definitions.ts
204
- import yaml2 from "js-yaml";
205
- import { execSync } from "node:child_process";
206
- import { readFileSync } from "node:fs";
207
- import { resolve } from "node:path";
208
- import pkgUp from "pkg-up";
209
- import { log as log2 } from "@dxos/log";
210
- import { setDeep as setDeep2 } from "@dxos/util";
211
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/config/src/plugin/definitions.ts";
212
- var CWD = process.cwd();
213
- var definitions = ({ configPath, envPath, devPath, mode = process.env.NODE_ENV, publicUrl = "", env }) => {
214
- const KEYS_TO_FILE = {
215
- __CONFIG_DEFAULTS__: configPath?.length ? configPath : resolve(CWD, "dx.yml"),
216
- __CONFIG_ENVS__: envPath?.length ? envPath : resolve(CWD, "dx-env.yml")
217
- };
218
- if (mode !== "production") {
219
- KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? resolve(CWD, "dx-local.yml");
220
- }
221
- return Object.entries(KEYS_TO_FILE).reduce((prev, [key, value]) => {
222
- let content = {};
223
- try {
224
- content = yaml2.load(readFileSync(value, "utf-8"));
225
- if (key === "__CONFIG_ENVS__") {
226
- content = mapFromKeyValues(content, process.env);
132
+ // src/preset.ts
133
+ import * as Match from "effect/Match";
134
+ var configPreset = ({ edge = "main" } = {}) => new Config({
135
+ version: 1,
136
+ runtime: {
137
+ client: {
138
+ edgeFeatures: {
139
+ signaling: true,
140
+ echoReplicator: true,
141
+ feedReplicator: true
227
142
  }
228
- if (key === "__CONFIG_DEFAULTS__") {
229
- Object.entries(process.env).forEach(([key2, value2]) => {
230
- if (key2.startsWith("DX_") || env?.includes(key2)) {
231
- setDeep2(content, [
232
- "runtime",
233
- "app",
234
- "env",
235
- key2
236
- ], value2);
237
- }
238
- });
239
- try {
240
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
241
- const commitHash = process.env.DX_COMMIT_HASH ?? execSync("git rev-parse --short HEAD", {
242
- encoding: "utf-8"
243
- }).replace("\n", "");
244
- const packagePath = pkgUp.sync();
245
- const packageJson = packagePath && JSON.parse(readFileSync(packagePath, "utf-8"));
246
- setDeep2(content, [
247
- "runtime",
248
- "app",
249
- "build",
250
- "timestamp"
251
- ], timestamp);
252
- setDeep2(content, [
253
- "runtime",
254
- "app",
255
- "build",
256
- "commitHash"
257
- ], commitHash);
258
- setDeep2(content, [
259
- "runtime",
260
- "app",
261
- "build",
262
- "version"
263
- ], packageJson?.version);
264
- } catch {
265
- }
266
- }
267
- } catch (err) {
268
- if (err.message.includes("YAMLException")) {
269
- log2.error(`Failed to parse file ${value}:`, err, {
270
- F: __dxlog_file2,
271
- L: 71,
272
- S: void 0,
273
- C: (f, a) => f(...a)
274
- });
275
- } else {
276
- log2(`Failed to load file ${value}:`, err, {
277
- F: __dxlog_file2,
278
- L: 73,
279
- S: void 0,
280
- C: (f, a) => f(...a)
281
- });
282
- }
283
- if (key === "__CONFIG_DEFAULTS__") {
284
- throw new Error(`Failed to load default config file from ${value}`);
143
+ },
144
+ services: {
145
+ edge: {
146
+ 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)
285
147
  }
286
148
  }
287
- return {
288
- ...prev,
289
- [key]: content
290
- };
291
- }, {
292
- __DXOS_CONFIG__: {
293
- dynamic: mode === "production",
294
- publicUrl
295
- },
296
- __CONFIG_DEFAULTS__: {},
297
- __CONFIG_ENVS__: {},
298
- __CONFIG_LOCAL__: {}
299
- });
300
- };
149
+ }
150
+ });
301
151
  export {
302
152
  Config,
303
153
  ConfigResource,
304
- Defaults,
305
- Dynamics,
306
- Envs,
154
+ ConfigService,
307
155
  FILE_DEFAULTS,
308
156
  FILE_DYNAMICS,
309
157
  FILE_ENVS,
310
- Local,
311
- Profile,
312
- Remote,
313
- SaveConfig,
314
- Storage,
315
- definitions,
158
+ configPreset,
159
+ defaultConfig,
316
160
  defs,
317
161
  mapFromKeyValues,
318
162
  mapToKeyValues,
163
+ memoryConfig,
319
164
  validateConfig
320
165
  };
321
166
  //# sourceMappingURL=index.mjs.map