@lmzhen/dsh-evolution-client-kit 0.46.0 → 0.47.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/lib/generated/fallbacks.generated.js +1 -2
- package/lib/generated/routes.generated.js +1 -5
- package/lib/index.js +1 -258
- package/lib/types/generated/fallbacks.generated.d.ts +1 -1
- package/lib/types/generated/fallbacks.generated.js +0 -3
- package/lib/types/generated/routes.generated.d.ts +1 -5
- package/lib/types/generated/routes.generated.js +0 -4
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.js +0 -2
- package/package.json +1 -1
- package/lib/types/settings-gateway.d.ts +0 -68
- package/lib/types/settings-gateway.js +0 -52
- package/lib/types/settings-seat.d.ts +0 -21
- package/lib/types/settings-seat.js +0 -172
|
@@ -12,8 +12,7 @@ const FALLBACKS = {
|
|
|
12
12
|
diagnostics: {
|
|
13
13
|
command: "/evolution doctor",
|
|
14
14
|
platformCli: "dsh --json /evolution doctor"
|
|
15
|
-
}
|
|
16
|
-
settings: { command: "/evolution params --group deployment(写入由平台插件管理的 row 配置页承载)" }
|
|
15
|
+
}
|
|
17
16
|
};
|
|
18
17
|
//#endregion
|
|
19
18
|
export { FALLBACKS };
|
|
@@ -30,11 +30,7 @@ const ROUTES = {
|
|
|
30
30
|
body: "/api/dsh-evolution/merge/body",
|
|
31
31
|
history: "/api/dsh-evolution/merge/history"
|
|
32
32
|
},
|
|
33
|
-
diagnostics: { view: "/api/dsh-evolution/diagnostics" }
|
|
34
|
-
settings: {
|
|
35
|
-
describe: "/api/dsh-evolution/settings/describe",
|
|
36
|
-
mutate: "/api/dsh-evolution/settings/mutate"
|
|
37
|
-
}
|
|
33
|
+
diagnostics: { view: "/api/dsh-evolution/diagnostics" }
|
|
38
34
|
};
|
|
39
35
|
//#endregion
|
|
40
36
|
export { ROUTES };
|
package/lib/index.js
CHANGED
|
@@ -133,202 +133,6 @@ function registerWorkbenchView(ctx, spec) {
|
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
//#endregion
|
|
136
|
-
//#region lib/types/settings-seat.js
|
|
137
|
-
const SETTINGS_DESCRIBE = ROUTES.settings.describe;
|
|
138
|
-
const SETTINGS_MUTATE = ROUTES.settings.mutate;
|
|
139
|
-
const EMPTY = Object.freeze({
|
|
140
|
-
status: "unavailable",
|
|
141
|
-
value: void 0,
|
|
142
|
-
user: void 0,
|
|
143
|
-
writable: false,
|
|
144
|
-
base: void 0,
|
|
145
|
-
revision: void 0,
|
|
146
|
-
reason: "transport"
|
|
147
|
-
});
|
|
148
|
-
function snapshotFrom(value, ns) {
|
|
149
|
-
if (typeof value !== "object" || value === null) return EMPTY;
|
|
150
|
-
const list = value.namespaces;
|
|
151
|
-
if (!Array.isArray(list)) return EMPTY;
|
|
152
|
-
const item = list.find((candidate) => typeof candidate === "object" && candidate !== null && candidate.ns === ns);
|
|
153
|
-
return item === void 0 ? {
|
|
154
|
-
...EMPTY,
|
|
155
|
-
reason: "not-served"
|
|
156
|
-
} : item;
|
|
157
|
-
}
|
|
158
|
-
async function describe(namespace) {
|
|
159
|
-
try {
|
|
160
|
-
const response = await fetch(SETTINGS_DESCRIBE, { headers: { accept: "application/json" } });
|
|
161
|
-
if (!response.ok) return EMPTY;
|
|
162
|
-
const body = await response.json();
|
|
163
|
-
if (body.ok !== true) return EMPTY;
|
|
164
|
-
return snapshotFrom(body.data, namespace);
|
|
165
|
-
} catch {
|
|
166
|
-
return EMPTY;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Classify one refused write from the exact route's response: the route answers 409 for a revision
|
|
171
|
-
* CAS loss and 400 with an "invalid config" error for a schema refusal, so the card can name the
|
|
172
|
-
* right cause instead of calling every refusal a concurrent edit.
|
|
173
|
-
* @param response - the non-ok response.
|
|
174
|
-
* @returns the refusal class; anything the route did not name stays transport.
|
|
175
|
-
*/
|
|
176
|
-
async function refusalKind(response) {
|
|
177
|
-
if (response.status === 409) return "conflict";
|
|
178
|
-
try {
|
|
179
|
-
const body = await response.json();
|
|
180
|
-
return typeof body.error === "string" && body.error.startsWith("invalid config") ? "validation" : "transport";
|
|
181
|
-
} catch {
|
|
182
|
-
return "transport";
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
async function write(namespace, ops, expectedRevision) {
|
|
186
|
-
try {
|
|
187
|
-
const response = await fetch(SETTINGS_MUTATE, {
|
|
188
|
-
method: "POST",
|
|
189
|
-
headers: {
|
|
190
|
-
"content-type": "application/json",
|
|
191
|
-
accept: "application/json"
|
|
192
|
-
},
|
|
193
|
-
body: JSON.stringify({
|
|
194
|
-
ns: namespace,
|
|
195
|
-
ops,
|
|
196
|
-
...expectedRevision === void 0 ? {} : { expectedRevision }
|
|
197
|
-
})
|
|
198
|
-
});
|
|
199
|
-
if (!response.ok) return {
|
|
200
|
-
ok: false,
|
|
201
|
-
kind: await refusalKind(response)
|
|
202
|
-
};
|
|
203
|
-
const body = await response.json();
|
|
204
|
-
return {
|
|
205
|
-
ok: body.ok === true,
|
|
206
|
-
snapshot: snapshotFrom(body.data, namespace)
|
|
207
|
-
};
|
|
208
|
-
} catch {
|
|
209
|
-
return {
|
|
210
|
-
ok: false,
|
|
211
|
-
kind: "transport"
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
function createForm(namespace, ctx) {
|
|
216
|
-
let snapshot = {
|
|
217
|
-
...EMPTY,
|
|
218
|
-
reason: "seat-missing"
|
|
219
|
-
};
|
|
220
|
-
let lastReady;
|
|
221
|
-
let generation = 0;
|
|
222
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
223
|
-
let remoteOff;
|
|
224
|
-
const notify = () => {
|
|
225
|
-
for (const listener of listeners) listener();
|
|
226
|
-
};
|
|
227
|
-
const absorb = (next) => {
|
|
228
|
-
if (next.status === "ready") {
|
|
229
|
-
lastReady = next;
|
|
230
|
-
snapshot = next;
|
|
231
|
-
} else if (lastReady !== void 0) snapshot = {
|
|
232
|
-
...lastReady,
|
|
233
|
-
stale: true,
|
|
234
|
-
reason: next.reason ?? "readback-failed"
|
|
235
|
-
};
|
|
236
|
-
else snapshot = next;
|
|
237
|
-
notify();
|
|
238
|
-
};
|
|
239
|
-
const refresh = async () => {
|
|
240
|
-
startRemote();
|
|
241
|
-
const ticket = ++generation;
|
|
242
|
-
const next = await describe(namespace);
|
|
243
|
-
if (ticket !== generation) return;
|
|
244
|
-
absorb(next);
|
|
245
|
-
};
|
|
246
|
-
const remote = () => ctx.get?.("remote");
|
|
247
|
-
const stopRemote = () => {
|
|
248
|
-
remoteOff?.();
|
|
249
|
-
remoteOff = void 0;
|
|
250
|
-
};
|
|
251
|
-
const startRemote = () => {
|
|
252
|
-
if (remoteOff !== void 0) return;
|
|
253
|
-
remoteOff = remote()?.$on?.("settings/document-updated", (changed) => {
|
|
254
|
-
if (changed === namespace) refresh();
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
const form = {
|
|
258
|
-
getSnapshot: () => snapshot,
|
|
259
|
-
subscribe: (listener) => {
|
|
260
|
-
listeners.add(listener);
|
|
261
|
-
startRemote();
|
|
262
|
-
refresh();
|
|
263
|
-
return () => {
|
|
264
|
-
listeners.delete(listener);
|
|
265
|
-
if (listeners.size === 0) stopRemote();
|
|
266
|
-
};
|
|
267
|
-
},
|
|
268
|
-
set: async (field, value) => await form.mutate([{
|
|
269
|
-
op: "set",
|
|
270
|
-
path: [field],
|
|
271
|
-
value
|
|
272
|
-
}]),
|
|
273
|
-
unset: async (field) => await form.mutate([{
|
|
274
|
-
op: "unset",
|
|
275
|
-
path: [field]
|
|
276
|
-
}]),
|
|
277
|
-
save: async (ops, expectedRevision) => {
|
|
278
|
-
const outcome = await write(namespace, ops, expectedRevision ?? snapshot.revision);
|
|
279
|
-
if (outcome.snapshot !== void 0) absorb(outcome.snapshot);
|
|
280
|
-
else await refresh();
|
|
281
|
-
return outcome.ok ? { written: true } : {
|
|
282
|
-
written: false,
|
|
283
|
-
kind: outcome.kind ?? "transport"
|
|
284
|
-
};
|
|
285
|
-
},
|
|
286
|
-
mutate: async (ops, expectedRevision) => {
|
|
287
|
-
const outcome = await write(namespace, ops, expectedRevision ?? snapshot.revision);
|
|
288
|
-
if (outcome.snapshot !== void 0) absorb(outcome.snapshot);
|
|
289
|
-
else await refresh();
|
|
290
|
-
return outcome.ok;
|
|
291
|
-
},
|
|
292
|
-
refresh,
|
|
293
|
-
dispose: () => {
|
|
294
|
-
stopRemote();
|
|
295
|
-
listeners.clear();
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
return form;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Build/return the ONE seat for one ClientContext. All panels share the same form,
|
|
302
|
-
* snapshot and revision; dispose removes the seat so a replacement context starts clean.
|
|
303
|
-
*/
|
|
304
|
-
const seats = /* @__PURE__ */ new WeakMap();
|
|
305
|
-
function createSettingsSeat(ctx) {
|
|
306
|
-
const key = ctx;
|
|
307
|
-
const existing = seats.get(key);
|
|
308
|
-
if (existing !== void 0) return existing;
|
|
309
|
-
const forms = /* @__PURE__ */ new Map();
|
|
310
|
-
const seat = {
|
|
311
|
-
get(namespace) {
|
|
312
|
-
let form = forms.get(namespace);
|
|
313
|
-
if (form === void 0) {
|
|
314
|
-
form = createForm(namespace, ctx);
|
|
315
|
-
forms.set(namespace, form);
|
|
316
|
-
}
|
|
317
|
-
return form;
|
|
318
|
-
},
|
|
319
|
-
dispose: () => {
|
|
320
|
-
for (const form of forms.values()) form.dispose?.();
|
|
321
|
-
forms.clear();
|
|
322
|
-
seats.delete(key);
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
seats.set(key, seat);
|
|
326
|
-
ctx.inject?.(["remote"], () => {
|
|
327
|
-
for (const form of forms.values()) form.refresh?.();
|
|
328
|
-
});
|
|
329
|
-
return seat;
|
|
330
|
-
}
|
|
331
|
-
//#endregion
|
|
332
136
|
//#region lib/types/workspace.js
|
|
333
137
|
/**
|
|
334
138
|
* Best-effort workspace id; a seat that is absent or refuses leaves the panel in local scope.
|
|
@@ -807,65 +611,4 @@ const PAGE_SURFACE_CLASS = "evolution-page-surface";
|
|
|
807
611
|
/** Stylesheet for {@link PAGE_SURFACE_CLASS}; consumers append it to their own CSS. */
|
|
808
612
|
const PAGE_SURFACE_CSS = ".evolution-page-surface{min-height:100%;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary)}";
|
|
809
613
|
//#endregion
|
|
810
|
-
|
|
811
|
-
/**
|
|
812
|
-
* Save one atomic op list and always read back.
|
|
813
|
-
* @param options - namespace, bound scope, mutation transport, and ops.
|
|
814
|
-
* @returns the write verdict plus the separate read-back verdict.
|
|
815
|
-
*/
|
|
816
|
-
async function saveSettings(options) {
|
|
817
|
-
const revision = options.scope.getSnapshot().revision;
|
|
818
|
-
let written = false;
|
|
819
|
-
let failure;
|
|
820
|
-
try {
|
|
821
|
-
written = (await options.api.mutate({
|
|
822
|
-
ns: options.namespace,
|
|
823
|
-
ops: options.ops,
|
|
824
|
-
...revision === void 0 ? {} : { expectedRevision: revision }
|
|
825
|
-
})).result.ok;
|
|
826
|
-
} catch (error) {
|
|
827
|
-
failure = error;
|
|
828
|
-
}
|
|
829
|
-
let readback = "ok";
|
|
830
|
-
try {
|
|
831
|
-
await options.scope.load();
|
|
832
|
-
} catch (error) {
|
|
833
|
-
readback = "failed";
|
|
834
|
-
failure ??= error;
|
|
835
|
-
}
|
|
836
|
-
return failure === void 0 ? {
|
|
837
|
-
written,
|
|
838
|
-
readback
|
|
839
|
-
} : {
|
|
840
|
-
written,
|
|
841
|
-
readback,
|
|
842
|
-
failure
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Bind each namespace once and reuse that scope for every later save.
|
|
847
|
-
* @param binder - the platform settings-scope service.
|
|
848
|
-
* @param api - the mutation transport.
|
|
849
|
-
* @returns a lookup that creates one gateway per namespace.
|
|
850
|
-
*/
|
|
851
|
-
function createSettingsGatewayCache(binder, api) {
|
|
852
|
-
const cache = /* @__PURE__ */ new Map();
|
|
853
|
-
return (namespace) => {
|
|
854
|
-
const existing = cache.get(namespace);
|
|
855
|
-
if (existing !== void 0) return existing;
|
|
856
|
-
const scope = binder.bind({ namespace });
|
|
857
|
-
const gateway = {
|
|
858
|
-
scope,
|
|
859
|
-
save: async (ops) => await saveSettings({
|
|
860
|
-
namespace,
|
|
861
|
-
scope,
|
|
862
|
-
api,
|
|
863
|
-
ops
|
|
864
|
-
})
|
|
865
|
-
};
|
|
866
|
-
cache.set(namespace, gateway);
|
|
867
|
-
return gateway;
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
//#endregion
|
|
871
|
-
export { ActionMenu, AsyncResource, Block, CommandCopyButton, DecisionFrame, DisclosureGroup, EmptyState, FALLBACKS, FailureBlock, FilterChip, PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS, PLATFORM_MENU, RESPONSIVE_TABLE_CSS, ROUTES, StateNotice, StatusChip, TOKENS, TOKEN_CSS, TaskBanner, TimeText, copyAction, createSettingsGatewayCache, createSettingsSeat, failureText, formatLocalClock, formatLocalDateTime, isSameLocalDay, loadStateOf, menuPrimitivesFrom, panelWorkspaceId, registerSidebarPanel, registerWorkbenchView, renderPlatformMenu, requireClientSeats, saveSettings, tokenVars };
|
|
614
|
+
export { ActionMenu, AsyncResource, Block, CommandCopyButton, DecisionFrame, DisclosureGroup, EmptyState, FALLBACKS, FailureBlock, FilterChip, PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS, PLATFORM_MENU, RESPONSIVE_TABLE_CSS, ROUTES, StateNotice, StatusChip, TOKENS, TOKEN_CSS, TaskBanner, TimeText, copyAction, failureText, formatLocalClock, formatLocalDateTime, isSameLocalDay, loadStateOf, menuPrimitivesFrom, panelWorkspaceId, registerSidebarPanel, registerWorkbenchView, renderPlatformMenu, requireClientSeats, tokenVars };
|
|
@@ -4,5 +4,5 @@ import type { FallbackHint } from './contracts.generated.ts';
|
|
|
4
4
|
* COMMAND_FALLBACKS (the ONE home). When the platform's connection carrier is absent (E-325) the
|
|
5
5
|
* panels render this hint instead of a bare HTTP failure — same use case, command face.
|
|
6
6
|
*/
|
|
7
|
-
export declare const FALLBACKS: Readonly<Record<'approval' | 'skill-history' | 'skill-health' | 'merge' | 'diagnostics'
|
|
7
|
+
export declare const FALLBACKS: Readonly<Record<'approval' | 'skill-history' | 'skill-health' | 'merge' | 'diagnostics', FallbackHint>>;
|
|
8
8
|
//# sourceMappingURL=fallbacks.generated.d.ts.map
|
|
@@ -21,8 +21,5 @@ export const FALLBACKS = {
|
|
|
21
21
|
command: '/evolution doctor',
|
|
22
22
|
platformCli: 'dsh --json /evolution doctor',
|
|
23
23
|
},
|
|
24
|
-
settings: {
|
|
25
|
-
command: '/evolution params --group deployment(写入由平台插件管理的 row 配置页承载)',
|
|
26
|
-
},
|
|
27
24
|
};
|
|
28
25
|
//# sourceMappingURL=fallbacks.generated.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** One host data-plane surface the browser half can call. */
|
|
2
|
-
export type SurfaceId = 'approval' | 'skill-history' | 'skill-health' | 'merge' | 'diagnostics'
|
|
2
|
+
export type SurfaceId = 'approval' | 'skill-history' | 'skill-health' | 'merge' | 'diagnostics';
|
|
3
3
|
/**
|
|
4
4
|
* Every family host path, generated from evolution-core's HOST_ROUTES (the ONE declaration).
|
|
5
5
|
* A browser half cannot import the host package at runtime (client bundles keep @deepseek-ai/*
|
|
@@ -36,9 +36,5 @@ export declare const ROUTES: {
|
|
|
36
36
|
readonly diagnostics: {
|
|
37
37
|
readonly view: "/api/dsh-evolution/diagnostics";
|
|
38
38
|
};
|
|
39
|
-
readonly settings: {
|
|
40
|
-
readonly describe: "/api/dsh-evolution/settings/describe";
|
|
41
|
-
readonly mutate: "/api/dsh-evolution/settings/mutate";
|
|
42
|
-
};
|
|
43
39
|
};
|
|
44
40
|
//# sourceMappingURL=routes.generated.d.ts.map
|
|
@@ -35,9 +35,5 @@ export const ROUTES = {
|
|
|
35
35
|
diagnostics: {
|
|
36
36
|
view: '/api/dsh-evolution/diagnostics',
|
|
37
37
|
},
|
|
38
|
-
settings: {
|
|
39
|
-
describe: '/api/dsh-evolution/settings/describe',
|
|
40
|
-
mutate: '/api/dsh-evolution/settings/mutate',
|
|
41
|
-
},
|
|
42
38
|
};
|
|
43
39
|
//# sourceMappingURL=routes.generated.js.map
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
export type { ClientSeam, ConfigFormLike, ConfigFormSnapshotLike, ConfigFormsSeat, ConfigPathOpLike, ConfigWriteKind, ConfigWriteOutcome, LocaleSeat, PanelBodyOptions, PanelRowOptions, SettingsFace, SlotsSeat } from './seam.ts';
|
|
3
3
|
export { registerSidebarPanel, requireClientSeats, type SidebarPanelSpec, type Translate } from './panel.ts';
|
|
4
4
|
export { registerWorkbenchView } from './workbench-view.ts';
|
|
5
|
-
export { createSettingsSeat } from './settings-seat.ts';
|
|
6
5
|
export type { WorkbenchViewSpec } from './workbench-view.ts';
|
|
7
6
|
export { panelWorkspaceId } from './workspace.ts';
|
|
8
7
|
export { AsyncResource } from './async-resource.ts';
|
|
@@ -26,6 +25,4 @@ export * from './generated/contracts.generated.ts';
|
|
|
26
25
|
export * from './generated/states.generated.ts';
|
|
27
26
|
export { TOKEN_CSS, TOKENS, tokenVars } from './tokens.ts';
|
|
28
27
|
export { PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS } from './surface.ts';
|
|
29
|
-
export { createSettingsGatewayCache, saveSettings } from './settings-gateway.ts';
|
|
30
|
-
export type { SettingsBinderLike, SettingsGateway, SettingsMutationApi, SettingsSaveResult, SettingsScopeLike } from './settings-gateway.ts';
|
|
31
28
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/types/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { registerSidebarPanel, requireClientSeats } from "./panel.js";
|
|
2
2
|
export { registerWorkbenchView } from "./workbench-view.js";
|
|
3
|
-
export { createSettingsSeat } from "./settings-seat.js";
|
|
4
3
|
export { panelWorkspaceId } from "./workspace.js";
|
|
5
4
|
export { AsyncResource } from "./async-resource.js";
|
|
6
5
|
export { formatLocalClock, formatLocalDateTime, isSameLocalDay } from "./format.js";
|
|
@@ -20,5 +19,4 @@ export * from "./generated/contracts.generated.js";
|
|
|
20
19
|
export * from "./generated/states.generated.js";
|
|
21
20
|
export { TOKEN_CSS, TOKENS, tokenVars } from "./tokens.js";
|
|
22
21
|
export { PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS } from "./surface.js";
|
|
23
|
-
export { createSettingsGatewayCache, saveSettings } from "./settings-gateway.js";
|
|
24
22
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-client-kit",
|
|
3
3
|
"description": "Shared browser seams and lifecycle for the evolution family sidebar panels (community build)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.47.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One namespace's settings gateway: one scope for reads, one revision-fenced
|
|
3
|
-
* write, and a read-back in `finally`. The gateway owns no subscription — the
|
|
4
|
-
* platform settings scope already listens to document updates and resets.
|
|
5
|
-
* @module @lmzhen/dsh-evolution-client-kit
|
|
6
|
-
*/
|
|
7
|
-
import type { ConfigPathOpLike } from './seam.ts';
|
|
8
|
-
/** The read side of a platform settings scope. */
|
|
9
|
-
export interface SettingsScopeLike {
|
|
10
|
-
/** @returns the current namespace snapshot; only `revision` is read here. */
|
|
11
|
-
getSnapshot(): {
|
|
12
|
-
readonly revision?: number | undefined;
|
|
13
|
-
};
|
|
14
|
-
/** Queue a fresh describe and settle after it publishes or is superseded. */
|
|
15
|
-
load(): Promise<void>;
|
|
16
|
-
}
|
|
17
|
-
/** The write transport; one call carries the complete op list. */
|
|
18
|
-
export interface SettingsMutationApi {
|
|
19
|
-
mutate(input: {
|
|
20
|
-
readonly ns: string;
|
|
21
|
-
readonly ops: readonly ConfigPathOpLike[];
|
|
22
|
-
readonly expectedRevision?: number;
|
|
23
|
-
}): Promise<{
|
|
24
|
-
readonly result: {
|
|
25
|
-
readonly ok: boolean;
|
|
26
|
-
};
|
|
27
|
-
}>;
|
|
28
|
-
}
|
|
29
|
-
/** Write verdict and the independent read-back verdict. */
|
|
30
|
-
export interface SettingsSaveResult {
|
|
31
|
-
/** True only when the Host accepted the write. */
|
|
32
|
-
readonly written: boolean;
|
|
33
|
-
/** Read-back outcome; never derived from `written`. */
|
|
34
|
-
readonly readback: 'ok' | 'failed';
|
|
35
|
-
/** Transport/write failure, retained when the read-back was still attempted. */
|
|
36
|
-
readonly failure?: unknown;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Save one atomic op list and always read back.
|
|
40
|
-
* @param options - namespace, bound scope, mutation transport, and ops.
|
|
41
|
-
* @returns the write verdict plus the separate read-back verdict.
|
|
42
|
-
*/
|
|
43
|
-
export declare function saveSettings(options: {
|
|
44
|
-
readonly namespace: string;
|
|
45
|
-
readonly scope: SettingsScopeLike;
|
|
46
|
-
readonly api: SettingsMutationApi;
|
|
47
|
-
readonly ops: readonly ConfigPathOpLike[];
|
|
48
|
-
}): Promise<SettingsSaveResult>;
|
|
49
|
-
/** The platform binder face; one call per namespace is the whole contract. */
|
|
50
|
-
export interface SettingsBinderLike {
|
|
51
|
-
bind(spec: {
|
|
52
|
-
readonly namespace: string;
|
|
53
|
-
}): SettingsScopeLike;
|
|
54
|
-
}
|
|
55
|
-
/** One cached namespace gateway. */
|
|
56
|
-
export interface SettingsGateway {
|
|
57
|
-
readonly scope: SettingsScopeLike;
|
|
58
|
-
/** Save through this gateway's cached scope. */
|
|
59
|
-
save(ops: readonly ConfigPathOpLike[]): Promise<SettingsSaveResult>;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Bind each namespace once and reuse that scope for every later save.
|
|
63
|
-
* @param binder - the platform settings-scope service.
|
|
64
|
-
* @param api - the mutation transport.
|
|
65
|
-
* @returns a lookup that creates one gateway per namespace.
|
|
66
|
-
*/
|
|
67
|
-
export declare function createSettingsGatewayCache(binder: SettingsBinderLike, api: SettingsMutationApi): (namespace: string) => SettingsGateway;
|
|
68
|
-
//# sourceMappingURL=settings-gateway.d.ts.map
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Save one atomic op list and always read back.
|
|
3
|
-
* @param options - namespace, bound scope, mutation transport, and ops.
|
|
4
|
-
* @returns the write verdict plus the separate read-back verdict.
|
|
5
|
-
*/
|
|
6
|
-
export async function saveSettings(options) {
|
|
7
|
-
const revision = options.scope.getSnapshot().revision;
|
|
8
|
-
let written = false;
|
|
9
|
-
let failure;
|
|
10
|
-
try {
|
|
11
|
-
const response = await options.api.mutate({
|
|
12
|
-
ns: options.namespace,
|
|
13
|
-
ops: options.ops,
|
|
14
|
-
...(revision === undefined ? {} : { expectedRevision: revision }),
|
|
15
|
-
});
|
|
16
|
-
written = response.result.ok;
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
failure = error;
|
|
20
|
-
}
|
|
21
|
-
let readback = 'ok';
|
|
22
|
-
try {
|
|
23
|
-
await options.scope.load();
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
readback = 'failed';
|
|
27
|
-
failure ??= error;
|
|
28
|
-
}
|
|
29
|
-
return failure === undefined ? { written, readback } : { written, readback, failure };
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Bind each namespace once and reuse that scope for every later save.
|
|
33
|
-
* @param binder - the platform settings-scope service.
|
|
34
|
-
* @param api - the mutation transport.
|
|
35
|
-
* @returns a lookup that creates one gateway per namespace.
|
|
36
|
-
*/
|
|
37
|
-
export function createSettingsGatewayCache(binder, api) {
|
|
38
|
-
const cache = new Map();
|
|
39
|
-
return (namespace) => {
|
|
40
|
-
const existing = cache.get(namespace);
|
|
41
|
-
if (existing !== undefined)
|
|
42
|
-
return existing;
|
|
43
|
-
const scope = binder.bind({ namespace });
|
|
44
|
-
const gateway = {
|
|
45
|
-
scope,
|
|
46
|
-
save: async (ops) => await saveSettings({ namespace, scope, api, ops }),
|
|
47
|
-
};
|
|
48
|
-
cache.set(namespace, gateway);
|
|
49
|
-
return gateway;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=settings-gateway.js.map
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Family settings data plane, adapted to the card's form shape.
|
|
3
|
-
*
|
|
4
|
-
* The platform RPC only serves its own namespace allowlist, so `connection.api.settings`
|
|
5
|
-
* cannot read family namespaces even though the host settings provider has them.
|
|
6
|
-
* These forms talk to the family's exact routes, which call the SAME platform
|
|
7
|
-
* settings provider (schema validation, revision fencing, redaction and storage
|
|
8
|
-
* stay platform-owned).
|
|
9
|
-
* @module @lmzhen/dsh-evolution-client-kit
|
|
10
|
-
*/
|
|
11
|
-
import type { ConfigFormsSeat } from './seam.ts';
|
|
12
|
-
interface ContextLike {
|
|
13
|
-
get?: (name: string) => unknown;
|
|
14
|
-
inject?: (deps: string[], callback: () => void) => void;
|
|
15
|
-
remote?: {
|
|
16
|
-
$on?: (event: string, listener: (namespace: string) => void) => () => void;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export declare function createSettingsSeat(ctx: ContextLike): ConfigFormsSeat;
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=settings-seat.d.ts.map
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { ROUTES } from "./generated/routes.generated.js";
|
|
2
|
-
const SETTINGS_DESCRIBE = ROUTES.settings.describe;
|
|
3
|
-
const SETTINGS_MUTATE = ROUTES.settings.mutate;
|
|
4
|
-
const EMPTY = Object.freeze({
|
|
5
|
-
status: 'unavailable', value: undefined, user: undefined, writable: false, base: undefined, revision: undefined, reason: 'transport',
|
|
6
|
-
});
|
|
7
|
-
function snapshotFrom(value, ns) {
|
|
8
|
-
if (typeof value !== 'object' || value === null)
|
|
9
|
-
return EMPTY;
|
|
10
|
-
const list = value.namespaces;
|
|
11
|
-
if (!Array.isArray(list))
|
|
12
|
-
return EMPTY;
|
|
13
|
-
const item = list.find(candidate => typeof candidate === 'object' && candidate !== null && candidate.ns === ns);
|
|
14
|
-
return item === undefined ? { ...EMPTY, reason: 'not-served' } : item;
|
|
15
|
-
}
|
|
16
|
-
async function describe(namespace) {
|
|
17
|
-
try {
|
|
18
|
-
const response = await fetch(SETTINGS_DESCRIBE, { headers: { accept: 'application/json' } });
|
|
19
|
-
if (!response.ok)
|
|
20
|
-
return EMPTY;
|
|
21
|
-
const body = await response.json();
|
|
22
|
-
if (body.ok !== true)
|
|
23
|
-
return EMPTY;
|
|
24
|
-
return snapshotFrom(body.data, namespace);
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
return EMPTY;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Classify one refused write from the exact route's response: the route answers 409 for a revision
|
|
32
|
-
* CAS loss and 400 with an "invalid config" error for a schema refusal, so the card can name the
|
|
33
|
-
* right cause instead of calling every refusal a concurrent edit.
|
|
34
|
-
* @param response - the non-ok response.
|
|
35
|
-
* @returns the refusal class; anything the route did not name stays transport.
|
|
36
|
-
*/
|
|
37
|
-
async function refusalKind(response) {
|
|
38
|
-
if (response.status === 409)
|
|
39
|
-
return 'conflict';
|
|
40
|
-
try {
|
|
41
|
-
const body = await response.json();
|
|
42
|
-
return typeof body.error === 'string' && body.error.startsWith('invalid config') ? 'validation' : 'transport';
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
return 'transport';
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function write(namespace, ops, expectedRevision) {
|
|
49
|
-
try {
|
|
50
|
-
const response = await fetch(SETTINGS_MUTATE, {
|
|
51
|
-
method: 'POST',
|
|
52
|
-
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
53
|
-
body: JSON.stringify({ ns: namespace, ops, ...(expectedRevision === undefined ? {} : { expectedRevision }) }),
|
|
54
|
-
});
|
|
55
|
-
if (!response.ok)
|
|
56
|
-
return { ok: false, kind: await refusalKind(response) };
|
|
57
|
-
const body = await response.json();
|
|
58
|
-
return { ok: body.ok === true, snapshot: snapshotFrom(body.data, namespace) };
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return { ok: false, kind: 'transport' };
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function createForm(namespace, ctx) {
|
|
65
|
-
let snapshot = { ...EMPTY, reason: 'seat-missing' };
|
|
66
|
-
let lastReady;
|
|
67
|
-
let generation = 0;
|
|
68
|
-
const listeners = new Set();
|
|
69
|
-
let remoteOff;
|
|
70
|
-
const notify = () => { for (const listener of listeners)
|
|
71
|
-
listener(); };
|
|
72
|
-
const absorb = (next) => {
|
|
73
|
-
if (next.status === 'ready') {
|
|
74
|
-
lastReady = next;
|
|
75
|
-
snapshot = next;
|
|
76
|
-
}
|
|
77
|
-
else if (lastReady !== undefined) {
|
|
78
|
-
// A failed re-read must not erase the last usable values. Keep ready + mark stale;
|
|
79
|
-
// the card shows the values with a warning instead of claiming the plugin is absent.
|
|
80
|
-
snapshot = { ...lastReady, stale: true, reason: next.reason ?? 'readback-failed' };
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
snapshot = next;
|
|
84
|
-
}
|
|
85
|
-
notify();
|
|
86
|
-
};
|
|
87
|
-
const refresh = async () => {
|
|
88
|
-
startRemote();
|
|
89
|
-
const ticket = ++generation;
|
|
90
|
-
const next = await describe(namespace);
|
|
91
|
-
if (ticket !== generation)
|
|
92
|
-
return;
|
|
93
|
-
absorb(next);
|
|
94
|
-
};
|
|
95
|
-
const remote = () => ctx.get?.('remote');
|
|
96
|
-
const stopRemote = () => { remoteOff?.(); remoteOff = undefined; };
|
|
97
|
-
const startRemote = () => {
|
|
98
|
-
if (remoteOff !== undefined)
|
|
99
|
-
return;
|
|
100
|
-
remoteOff = remote()?.$on?.('settings/document-updated', (changed) => { if (changed === namespace)
|
|
101
|
-
void refresh(); });
|
|
102
|
-
};
|
|
103
|
-
const form = {
|
|
104
|
-
getSnapshot: () => snapshot,
|
|
105
|
-
subscribe: (listener) => {
|
|
106
|
-
listeners.add(listener);
|
|
107
|
-
startRemote();
|
|
108
|
-
void refresh();
|
|
109
|
-
return () => {
|
|
110
|
-
listeners.delete(listener);
|
|
111
|
-
if (listeners.size === 0)
|
|
112
|
-
stopRemote();
|
|
113
|
-
};
|
|
114
|
-
},
|
|
115
|
-
set: async (field, value) => (await form.mutate([{ op: 'set', path: [field], value }])),
|
|
116
|
-
unset: async (field) => (await form.mutate([{ op: 'unset', path: [field] }])),
|
|
117
|
-
save: async (ops, expectedRevision) => {
|
|
118
|
-
const revision = expectedRevision ?? snapshot.revision;
|
|
119
|
-
const outcome = await write(namespace, ops, revision);
|
|
120
|
-
if (outcome.snapshot !== undefined)
|
|
121
|
-
absorb(outcome.snapshot);
|
|
122
|
-
else
|
|
123
|
-
await refresh();
|
|
124
|
-
return outcome.ok ? { written: true } : { written: false, kind: outcome.kind ?? 'transport' };
|
|
125
|
-
},
|
|
126
|
-
mutate: async (ops, expectedRevision) => {
|
|
127
|
-
const revision = expectedRevision ?? snapshot.revision;
|
|
128
|
-
const outcome = await write(namespace, ops, revision);
|
|
129
|
-
if (outcome.snapshot !== undefined)
|
|
130
|
-
absorb(outcome.snapshot);
|
|
131
|
-
else
|
|
132
|
-
await refresh();
|
|
133
|
-
return outcome.ok;
|
|
134
|
-
},
|
|
135
|
-
refresh,
|
|
136
|
-
dispose: () => { stopRemote(); listeners.clear(); },
|
|
137
|
-
};
|
|
138
|
-
return form;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Build/return the ONE seat for one ClientContext. All panels share the same form,
|
|
142
|
-
* snapshot and revision; dispose removes the seat so a replacement context starts clean.
|
|
143
|
-
*/
|
|
144
|
-
const seats = new WeakMap();
|
|
145
|
-
export function createSettingsSeat(ctx) {
|
|
146
|
-
const key = ctx;
|
|
147
|
-
const existing = seats.get(key);
|
|
148
|
-
if (existing !== undefined)
|
|
149
|
-
return existing;
|
|
150
|
-
const forms = new Map();
|
|
151
|
-
const seat = {
|
|
152
|
-
get(namespace) {
|
|
153
|
-
let form = forms.get(namespace);
|
|
154
|
-
if (form === undefined) {
|
|
155
|
-
form = createForm(namespace, ctx);
|
|
156
|
-
forms.set(namespace, form);
|
|
157
|
-
}
|
|
158
|
-
return form;
|
|
159
|
-
},
|
|
160
|
-
dispose: () => {
|
|
161
|
-
for (const form of forms.values())
|
|
162
|
-
form.dispose?.();
|
|
163
|
-
forms.clear();
|
|
164
|
-
seats.delete(key);
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
seats.set(key, seat);
|
|
168
|
-
ctx.inject?.(['remote'], () => { for (const form of forms.values())
|
|
169
|
-
void form.refresh?.(); });
|
|
170
|
-
return seat;
|
|
171
|
-
}
|
|
172
|
-
//# sourceMappingURL=settings-seat.js.map
|