@serfab/quereus-plugin-sereus 1.6.0 → 1.8.0
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/README.md +15 -5
- package/dist/cluster-size.d.ts +74 -51
- package/dist/cluster-size.js +74 -51
- package/dist/cluster-size.js.map +1 -1
- package/dist/compose-strand.d.ts +13 -0
- package/dist/compose-strand.js +35 -10
- package/dist/compose-strand.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/parse-config.d.ts +33 -2
- package/dist/parse-config.js +123 -46
- package/dist/parse-config.js.map +1 -1
- package/dist/plugin-browser.d.ts +3 -3
- package/dist/plugin-browser.js +27 -27
- package/dist/plugin-browser.js.map +4 -4
- package/dist/plugin.js +3 -7
- package/dist/plugin.js.map +1 -1
- package/package.json +36 -16
- package/src/cluster-size.ts +74 -51
- package/src/compose-strand.ts +37 -10
- package/src/index.ts +1 -0
- package/src/parse-config.ts +189 -70
- package/src/plugin-browser.ts +32 -29
- package/src/plugin.ts +35 -39
package/dist/parse-config.js
CHANGED
|
@@ -1,59 +1,136 @@
|
|
|
1
|
-
const
|
|
1
|
+
const TEXT = {
|
|
2
|
+
expected: 'a string',
|
|
3
|
+
read: raw => (typeof raw === 'string' ? raw : undefined),
|
|
4
|
+
emptyIsAbsent: true,
|
|
5
|
+
};
|
|
6
|
+
const COMMA_LIST = {
|
|
7
|
+
...TEXT,
|
|
8
|
+
expected: 'a comma-separated string',
|
|
9
|
+
read: raw => (typeof raw === 'string' ? raw.split(',').map(s => s.trim()).filter(Boolean) : undefined),
|
|
10
|
+
};
|
|
11
|
+
// NOTE: no numeric strings here or in FLAG, so a `${VAR}` in quoomb.config.json
|
|
12
|
+
// (whose env interpolation always yields a string) cannot supply port or
|
|
13
|
+
// enable_cache; if that is ever needed, accept decimal-integer strings here.
|
|
14
|
+
const PORT = {
|
|
15
|
+
expected: 'an integer from 0 to 65535',
|
|
16
|
+
read: raw => (typeof raw === 'number' && Number.isInteger(raw) && raw >= 0 && raw <= 65535 ? raw : undefined),
|
|
17
|
+
};
|
|
18
|
+
/** 0 and 1 are accepted because SQL has no boolean type. */
|
|
19
|
+
const FLAG = {
|
|
20
|
+
expected: 'true, false, 1 or 0',
|
|
21
|
+
read: raw => {
|
|
22
|
+
if (raw === true || raw === 1)
|
|
23
|
+
return true;
|
|
24
|
+
if (raw === false || raw === 0)
|
|
25
|
+
return false;
|
|
26
|
+
return undefined;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
2
29
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* mistake that only surfaces as a mysterious hang on a machine with no peers.
|
|
30
|
+
* One of a closed set of strings. The set is written as an object with every
|
|
31
|
+
* member as a key so it is checked against the union: `oneOf<StrandTransactor>`
|
|
32
|
+
* stops compiling when the union gains or loses a member.
|
|
7
33
|
*/
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
34
|
+
function oneOf(members) {
|
|
35
|
+
const values = Object.keys(members);
|
|
36
|
+
return {
|
|
37
|
+
expected: `one of ${values.join(', ')}`,
|
|
38
|
+
read: raw => values.find(v => v === raw),
|
|
39
|
+
emptyIsAbsent: true,
|
|
40
|
+
};
|
|
15
41
|
}
|
|
42
|
+
const SETTINGS = {
|
|
43
|
+
strand_id: { ...TEXT, required: true },
|
|
44
|
+
bootstrap_nodes: COMMA_LIST,
|
|
45
|
+
schema: TEXT,
|
|
46
|
+
sapp_id: TEXT,
|
|
47
|
+
sapp_version: TEXT,
|
|
48
|
+
port: PORT,
|
|
49
|
+
enable_cache: FLAG,
|
|
50
|
+
fret_profile: oneOf({ edge: true, core: true }),
|
|
51
|
+
transactor: oneOf({ local: true, network: true, test: true }),
|
|
52
|
+
storage_path: TEXT,
|
|
53
|
+
};
|
|
54
|
+
/** Every key the plugin accepts; the package manifest's `quereus.settings` must list the same. */
|
|
55
|
+
export const PLUGIN_SETTING_KEYS = Object.keys(SETTINGS);
|
|
56
|
+
const PROBLEM_HEADER = 'quereus-plugin-sereus: invalid plugin settings';
|
|
57
|
+
/** A string echoed in a problem is cut here: enough to recognise a typo, not a pasted schema. */
|
|
58
|
+
const MAX_ECHOED_CHARS = 120;
|
|
16
59
|
/**
|
|
17
60
|
* Parse the plugin-loader SqlValue config into typed StrandConnectionOptions.
|
|
18
61
|
* Shared by the Node (`plugin.ts`) and browser (`plugin-browser.ts`) entries.
|
|
62
|
+
*
|
|
63
|
+
* Strict: an unknown key or a value of the wrong type throws one error listing
|
|
64
|
+
* every problem, rather than falling back to a default the user never chose.
|
|
19
65
|
*/
|
|
20
66
|
export function parseConfig(config) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
67
|
+
const problems = [];
|
|
68
|
+
const values = readSettings(config, problems);
|
|
69
|
+
problems.push(...unknownKeyProblems(config));
|
|
70
|
+
// `strand_id` is undefined only alongside its own "required" problem.
|
|
71
|
+
const strandId = values.strand_id;
|
|
72
|
+
if (problems.length > 0 || strandId === undefined) {
|
|
73
|
+
throw new Error([PROBLEM_HEADER, ...problems.map(p => ` - ${p}`)].join('\n'));
|
|
24
74
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
75
|
+
return toParsedConfig(strandId, values);
|
|
76
|
+
}
|
|
77
|
+
function readSettings(config, problems) {
|
|
78
|
+
const values = {};
|
|
79
|
+
for (const key of PLUGIN_SETTING_KEYS)
|
|
80
|
+
readSettingInto(values, key, config[key], problems);
|
|
81
|
+
return values;
|
|
82
|
+
}
|
|
83
|
+
function readSettingInto(values, key, raw, problems) {
|
|
84
|
+
const setting = SETTINGS[key];
|
|
85
|
+
if (raw === undefined || raw === null || (raw === '' && setting.emptyIsAbsent)) {
|
|
86
|
+
if (setting.required)
|
|
87
|
+
problems.push(`${key} is required`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const value = setting.read(raw);
|
|
91
|
+
if (value === undefined) {
|
|
92
|
+
problems.push(`${key} must be ${setting.expected} (got ${describeValue(raw)})`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
values[key] = value;
|
|
96
|
+
}
|
|
97
|
+
function unknownKeyProblems(config) {
|
|
98
|
+
return Object.keys(config)
|
|
99
|
+
.filter(key => !Object.hasOwn(SETTINGS, key))
|
|
100
|
+
.map(key => key === 'mode'
|
|
101
|
+
? 'mode was removed: a lone node now coordinates for itself, and transactor selects the storage engine'
|
|
102
|
+
: `unknown setting ${JSON.stringify(key)}; accepted settings are ${PLUGIN_SETTING_KEYS.join(', ')}`);
|
|
103
|
+
}
|
|
104
|
+
function describeValue(raw) {
|
|
105
|
+
if (typeof raw === 'string') {
|
|
106
|
+
return raw.length > MAX_ECHOED_CHARS
|
|
107
|
+
? `${JSON.stringify(raw.slice(0, MAX_ECHOED_CHARS))}… (${raw.length} characters)`
|
|
108
|
+
: JSON.stringify(raw);
|
|
109
|
+
}
|
|
110
|
+
if (typeof raw === 'bigint')
|
|
111
|
+
return `${raw}n`;
|
|
112
|
+
if (typeof raw === 'number' || typeof raw === 'boolean')
|
|
113
|
+
return String(raw);
|
|
114
|
+
if (raw instanceof Uint8Array)
|
|
115
|
+
return `a blob of ${raw.length} bytes`;
|
|
116
|
+
return 'a JSON value';
|
|
117
|
+
}
|
|
118
|
+
function toParsedConfig(strandId, values) {
|
|
119
|
+
const { transactor } = values;
|
|
47
120
|
return {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
121
|
+
options: {
|
|
122
|
+
strandId,
|
|
123
|
+
bootstrapNodes: values.bootstrap_nodes ?? [],
|
|
124
|
+
schema: values.schema,
|
|
125
|
+
sAppId: values.sapp_id ?? 'unknown',
|
|
126
|
+
sAppVersion: values.sapp_version ?? '1.0.0',
|
|
127
|
+
port: values.port ?? 0,
|
|
128
|
+
enableCache: values.enable_cache ?? true,
|
|
129
|
+
fretProfile: values.fret_profile ?? 'edge',
|
|
130
|
+
// Left out entirely when unset so `composeStrand` applies its own default.
|
|
131
|
+
...(transactor && { transactor }),
|
|
132
|
+
},
|
|
133
|
+
storagePath: values.storage_path,
|
|
57
134
|
};
|
|
58
135
|
}
|
|
59
136
|
//# sourceMappingURL=parse-config.js.map
|
package/dist/parse-config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-config.js","sourceRoot":"","sources":["../src/parse-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-config.js","sourceRoot":"","sources":["../src/parse-config.ts"],"names":[],"mappings":"AA0CA,MAAM,IAAI,GAAoB;IAC7B,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IACxD,aAAa,EAAE,IAAI;CACnB,CAAC;AAEF,MAAM,UAAU,GAAsB;IACrC,GAAG,IAAI;IACP,QAAQ,EAAE,0BAA0B;IACpC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,C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@@ -12,8 +12,8 @@ export { parseConfig };
|
|
|
12
12
|
/**
|
|
13
13
|
* Default export: Quereus plugin registration function (browser).
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
* `FileRawStorage` in `./plugin`)
|
|
17
|
-
* storage to IndexedDB via `connectToStrandBrowser`.
|
|
15
|
+
* The `storage_path` setting is Node-only (it resolves to a filesystem
|
|
16
|
+
* `FileRawStorage` in `./plugin`), so it is rejected here rather than ignored;
|
|
17
|
+
* storage defaults to IndexedDB via `connectToStrandBrowser`.
|
|
18
18
|
*/
|
|
19
19
|
export default function register(db: Database, config?: Record<string, SqlValue>): Promise<SereusPluginResult>;
|