@goodandready/dsh-model-sync 0.2.2 → 0.2.3
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/lib/index.js +13 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -23,8 +23,14 @@ export const Config = Schema.object({
|
|
|
23
23
|
export function apply(ctx, config) {
|
|
24
24
|
let liveConfig = Config(structuredClone(config || {}))
|
|
25
25
|
let reconfigure = () => {}
|
|
26
|
-
let
|
|
27
|
-
|
|
26
|
+
let saveConfigImpl
|
|
27
|
+
// ctx.inject starts a child fiber; keep a stable function reference for the
|
|
28
|
+
// synchronizer while that fiber connects to the Settings service.
|
|
29
|
+
const saveConfig = async (patch) => {
|
|
30
|
+
if (!saveConfigImpl) {
|
|
31
|
+
throw Object.assign(new Error('dsh-model-sync settings are not writable'), { code: 'CONFIG_UNAVAILABLE' })
|
|
32
|
+
}
|
|
33
|
+
return saveConfigImpl(patch)
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
// The settings capability is injected as sctx.settings; ctx.get('settings')
|
|
@@ -36,14 +42,17 @@ export function apply(ctx, config) {
|
|
|
36
42
|
liveConfig = Config(next || config)
|
|
37
43
|
reconfigure()
|
|
38
44
|
})
|
|
39
|
-
|
|
45
|
+
saveConfigImpl = async (patch) => {
|
|
40
46
|
const result = await scope.update(patch)
|
|
41
47
|
// Settings watchers are serialized asynchronously; refresh the snapshot
|
|
42
48
|
// synchronously as well so a following request sees the new allowlist.
|
|
43
49
|
liveConfig = Config(scope.get() || config)
|
|
44
50
|
return result
|
|
45
51
|
}
|
|
46
|
-
sctx.effect(() => () =>
|
|
52
|
+
sctx.effect(() => () => {
|
|
53
|
+
saveConfigImpl = undefined
|
|
54
|
+
stop()
|
|
55
|
+
}, 'dsh-model-sync: settings')
|
|
47
56
|
})
|
|
48
57
|
|
|
49
58
|
const service = createProviderService(ctx)
|