@prettier-ai/dsh-client-ui-settings 0.1.2-alpha.1
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/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +107 -0
- package/README.zh.md +107 -0
- package/lib/client.js +1377 -0
- package/lib/index.js +6 -0
- package/lib/invariant.js +25 -0
- package/lib/types/client/contract/slots.d.ts +161 -0
- package/lib/types/client/index.d.ts +36 -0
- package/lib/types/client/schema.d.ts +72 -0
- package/lib/types/client/settings-contract.d.ts +86 -0
- package/lib/types/client/settings-mirror.d.ts +130 -0
- package/lib/types/client/settings-scope.d.ts +139 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/invariant.d.ts +16 -0
- package/package.json +74 -0
package/lib/index.js
ADDED
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
/**
|
|
3
|
+
* Package-owned invariant companion for `@prettier-ai/dsh-client-ui-settings`.
|
|
4
|
+
* @module @prettier-ai/dsh-client-ui-settings/invariant
|
|
5
|
+
*/
|
|
6
|
+
const PACKAGE_NAME = "@prettier-ai/dsh-client-ui-settings";
|
|
7
|
+
/** Cordis companion plugin name. */
|
|
8
|
+
const name = "client-ui-settings-invariant";
|
|
9
|
+
/** Service required before the companion can reserve package ownership. */
|
|
10
|
+
const inject = ["invariants"];
|
|
11
|
+
/**
|
|
12
|
+
* No runtime invariant: a presentation shell projecting the settings.section
|
|
13
|
+
* ledger into navigation — it emits no cordis events and owns no cross-plugin
|
|
14
|
+
* mutable relation; slot declaration/registration conflicts already fail loud
|
|
15
|
+
* in the slot core at load time.
|
|
16
|
+
*/
|
|
17
|
+
const install = () => {};
|
|
18
|
+
/**
|
|
19
|
+
* Register this package's invariant companion.
|
|
20
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
21
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
22
|
+
*/
|
|
23
|
+
const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
24
|
+
//#endregion
|
|
25
|
+
export { apply, inject, name };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings slot contract — the canonical home of every settings slot type,
|
|
3
|
+
* owned by the settings domain base rather than by the shell that renders
|
|
4
|
+
* them (ui-settings-general, which occupies `sidebar.settings`). The shell has
|
|
5
|
+
* zero copy of its own: ALL text (trigger label, panel title, header actions,
|
|
6
|
+
* close aria, section content) arrives from registrants. A feature owns its
|
|
7
|
+
* own settings pages — adding a setting never means editing the shell; copy
|
|
8
|
+
* that belongs to no single feature (chrome, the General section) is owned by
|
|
9
|
+
* ui-settings-general too.
|
|
10
|
+
*/
|
|
11
|
+
declare module '@prettier-ai/dsh-client-ui-slots' {
|
|
12
|
+
interface SlotMap {
|
|
13
|
+
/**
|
|
14
|
+
* The sidebar-foot trigger row content: icon + label, supplied as slot
|
|
15
|
+
* content (the accessible name comes from the content — rail state
|
|
16
|
+
* renders the label visually hidden). The shell renders the button
|
|
17
|
+
* chrome and owns open state. Absent contribution degrades to an
|
|
18
|
+
* icon-only button without an accessible name (broken-composition state;
|
|
19
|
+
* the shipped composition always registers the seat).
|
|
20
|
+
*/
|
|
21
|
+
'settings.trigger': {
|
|
22
|
+
kind: 'single';
|
|
23
|
+
scope: 'root';
|
|
24
|
+
owner: SettingsTriggerOwnerProps;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The panel title text seat. Content renders inside the nav heading row;
|
|
28
|
+
* the dialog's accessible name points at that node via aria-labelledby.
|
|
29
|
+
* Absent contribution leaves the heading empty.
|
|
30
|
+
*/
|
|
31
|
+
'settings.header': {
|
|
32
|
+
kind: 'single';
|
|
33
|
+
scope: 'root';
|
|
34
|
+
owner: SettingsHeaderOwnerProps;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Optional actions rendered in the content-column header before Close.
|
|
38
|
+
* Registrants own visibility, behavior, copy, and failure presentation;
|
|
39
|
+
* the shell supplies only the ordered render site.
|
|
40
|
+
*/
|
|
41
|
+
'settings.action': {
|
|
42
|
+
kind: 'list';
|
|
43
|
+
scope: 'root';
|
|
44
|
+
owner: SettingsHeaderOwnerProps;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The close button's visually-hidden label text (the button itself —
|
|
48
|
+
* icon, geometry, focus — is shell chrome). Absent contribution leaves
|
|
49
|
+
* the button without an accessible name (broken-composition state).
|
|
50
|
+
*/
|
|
51
|
+
'settings.close': {
|
|
52
|
+
kind: 'single';
|
|
53
|
+
scope: 'root';
|
|
54
|
+
owner: SettingsHeaderOwnerProps;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* One settings page per list entry. Registrant options carry the nav
|
|
58
|
+
* identity: `id` (section key, drives `only` filtering), `order` (nav
|
|
59
|
+
* position), `label` (registrant-localized display text — the registrant
|
|
60
|
+
* re-registers with fresh text on locale change, so the shell never
|
|
61
|
+
* subscribes locale state; the ledger bump doubles as the shell's
|
|
62
|
+
* re-render trigger). Sections render inside the panel content column.
|
|
63
|
+
* (`settings.general.item`, declared by ui-settings-general's General
|
|
64
|
+
* entry, is typed in the locale package — the common dependency of every
|
|
65
|
+
* item registrant; the shell neither declares nor renders it.)
|
|
66
|
+
*/
|
|
67
|
+
'settings.section': {
|
|
68
|
+
kind: 'list';
|
|
69
|
+
scope: 'root';
|
|
70
|
+
owner: SettingsSectionOwnerProps;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* One page inside the Plugins settings section. The section owner renders
|
|
74
|
+
* localized entry labels as tabs and mounts each contribution inside its
|
|
75
|
+
* corresponding tab panel. Options: `id` (tab key), `order` (tab order),
|
|
76
|
+
* and `label` (registrant-localized tab text). Declared at runtime by the
|
|
77
|
+
* feature that owns the Plugins section; the type lives here so inventory
|
|
78
|
+
* and configuration plugins collaborate without depending on one another.
|
|
79
|
+
*/
|
|
80
|
+
'settings.plugins.tab': {
|
|
81
|
+
kind: 'list';
|
|
82
|
+
scope: 'root';
|
|
83
|
+
owner: SettingsPluginsTabOwnerProps;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Root-scoped onboarding steps contributed by settings features. The
|
|
87
|
+
* shell mounts one ordered step at a time; the active registrant either
|
|
88
|
+
* completes itself or keeps ownership until the user completes its sole
|
|
89
|
+
* path. Registrants own readiness, copy, dialog behavior, AND visible
|
|
90
|
+
* chrome: a step wraps its visible content in its modal surface (including
|
|
91
|
+
* `#root` inert ownership) and renders null while private facts are still
|
|
92
|
+
* loading. The shell paints no chrome of its own, so a mounted-but-deciding
|
|
93
|
+
* step shows and blocks nothing.
|
|
94
|
+
*/
|
|
95
|
+
'settings.onboarding': {
|
|
96
|
+
kind: 'list';
|
|
97
|
+
scope: 'root';
|
|
98
|
+
owner: SettingsOnboardingOwnerProps;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* One preference row inside the General section — the additive seat for a
|
|
102
|
+
* single setting that needs no page of its own (a whole page is
|
|
103
|
+
* `settings.section`), contributed by the feature plugin that owns the
|
|
104
|
+
* preference (locale → Language, ui-theme → Appearance, ui-conversation →
|
|
105
|
+
* Composer Enter). Options: `id` (row key), `order` (row position). The
|
|
106
|
+
* section column only stacks rows, so a row draws its own internals,
|
|
107
|
+
* including its label: nothing projects a `label` here and the owner passes
|
|
108
|
+
* no props at all — copy, current value, and the write path are all yours,
|
|
109
|
+
* through your own inject face and `host.call`. Declared at runtime by
|
|
110
|
+
* ui-settings-general's General entry; the type lives here with every other
|
|
111
|
+
* settings slot type, because this package is the settings domain's base
|
|
112
|
+
* layer and every registrant already depends on it for `ctx.settingsScope`.
|
|
113
|
+
*/
|
|
114
|
+
'settings.general.item': {
|
|
115
|
+
kind: 'list';
|
|
116
|
+
scope: 'root';
|
|
117
|
+
owner: SettingsGeneralItemOwnerProps;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Owner share of a General preference row (the section supplies nothing). */
|
|
122
|
+
export interface SettingsGeneralItemOwnerProps {
|
|
123
|
+
/** Marker field: item owner props are intentionally empty. */
|
|
124
|
+
children?: never;
|
|
125
|
+
}
|
|
126
|
+
/** Owner share of a Plugins tab (the section supplies nothing). */
|
|
127
|
+
export interface SettingsPluginsTabOwnerProps {
|
|
128
|
+
/** Marker field: tab owner props are intentionally empty. */
|
|
129
|
+
children?: never;
|
|
130
|
+
}
|
|
131
|
+
/** Owner share of the trigger content seat: the sidebar column state. */
|
|
132
|
+
export interface SettingsTriggerOwnerProps {
|
|
133
|
+
/** Whether the sidebar renders wide content (false = 56px rail, icon only). */
|
|
134
|
+
wide: boolean;
|
|
135
|
+
}
|
|
136
|
+
/** Owner share of the header title seat (the shell supplies nothing). */
|
|
137
|
+
export interface SettingsHeaderOwnerProps {
|
|
138
|
+
/** Marker field: header owner props are intentionally empty. */
|
|
139
|
+
children?: never;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Owner share of a settings section entry. The shell owns modal visibility
|
|
143
|
+
* and navigation; a section's data arrives through its own inject faces and
|
|
144
|
+
* stores. `close` is the one shell affordance a section receives, for flows
|
|
145
|
+
* that leave settings altogether (starting a session from a section) — the
|
|
146
|
+
* onboarding coordinator's `openSection`/`complete` precedent, inverted.
|
|
147
|
+
*/
|
|
148
|
+
export interface SettingsSectionOwnerProps {
|
|
149
|
+
/** Close the settings panel (the shell owns the open state). */
|
|
150
|
+
close: () => void;
|
|
151
|
+
}
|
|
152
|
+
/** Owner share of the currently active settings-backed onboarding step. */
|
|
153
|
+
export interface SettingsOnboardingOwnerProps {
|
|
154
|
+
/** Stable id of the step currently selected by the coordinator. */
|
|
155
|
+
stepId: string;
|
|
156
|
+
/** Complete or skip this step and transfer ownership to the next entry. */
|
|
157
|
+
complete: () => void;
|
|
158
|
+
/** Open the settings panel directly on one registered section. */
|
|
159
|
+
openSection: (id: string) => void;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=slots.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings domain base plugin, browser half. Provides `ctx.settingsScope`, the
|
|
3
|
+
* settings-namespace scope service every preference row binds its durable
|
|
4
|
+
* section through, and owns the one `settings.describe` reader in the browser:
|
|
5
|
+
* the describe mirror, whose invalidation subscriptions
|
|
6
|
+
* (`settings/document-updated`, `connection/reset`) live here so every derived
|
|
7
|
+
* surface refreshes from a single wire read. It depends on no `ui-*`
|
|
8
|
+
* presentation package, so any feature that owns a preference can reach it:
|
|
9
|
+
* the settings SHELL — the `sidebar.settings` occupant, its navigation, and
|
|
10
|
+
* the chrome — lives in ui-settings-general, because a shell dependency on
|
|
11
|
+
* ui-sidebar would close a reference cycle through ui-layout and ui-theme.
|
|
12
|
+
* Export discipline: packages/client/AGENTS.md.
|
|
13
|
+
*/
|
|
14
|
+
import type { Context } from '@prettier-ai/cordis';
|
|
15
|
+
export type { SettingsGeneralItemOwnerProps, SettingsHeaderOwnerProps, SettingsOnboardingOwnerProps, SettingsPluginsTabOwnerProps, SettingsSectionOwnerProps, SettingsTriggerOwnerProps, } from './contract/slots.ts';
|
|
16
|
+
export type { SettingsScopeController, SettingsScopeBinder } from './settings-scope.ts';
|
|
17
|
+
export type { SettingsScope, SettingsScopeSnapshot, SettingsScopeSpec } from './settings-contract.ts';
|
|
18
|
+
export type { SettingsSchemaService } from './schema.ts';
|
|
19
|
+
export type { SchemaNode } from './schema.ts';
|
|
20
|
+
export type { SettingsDescribeFace, SettingsDescribeView, SettingsMirrorSnapshot, SettingsRemote, SettingsWireFace, } from './settings-mirror.ts';
|
|
21
|
+
/**
|
|
22
|
+
* Required services: the wire handle for the mirror's reads and the forwarded
|
|
23
|
+
* settings invalidation the mirror refreshes on.
|
|
24
|
+
*/
|
|
25
|
+
export declare const inject: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Provide the settings-namespace scope service over one shared describe
|
|
28
|
+
* mirror, and keep that mirror fresh on the two signals that can move the
|
|
29
|
+
* settings document: a document commit and a (re)connect.
|
|
30
|
+
*
|
|
31
|
+
* Constructing the service in this plugin's fiber keeps its traced methods
|
|
32
|
+
* bound to each consuming plugin's context.
|
|
33
|
+
* @param ctx - client root context.
|
|
34
|
+
*/
|
|
35
|
+
export declare function apply(ctx: Context): void;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** Synchronous schema introspection and immutable settings-draft edits. */
|
|
2
|
+
import { Service } from '@prettier-ai/cordis';
|
|
3
|
+
import type { Context } from '@prettier-ai/cordis';
|
|
4
|
+
import Schema from '@prettier-ai/schemastery';
|
|
5
|
+
/** Live schemastery node used for settings introspection and validation. */
|
|
6
|
+
export type SchemaNode = Schema;
|
|
7
|
+
/**
|
|
8
|
+
* Settings-owned synchronous schema service. Dynamic client plugins receive
|
|
9
|
+
* this Cordis entity instead of importing executable helpers from one another.
|
|
10
|
+
*/
|
|
11
|
+
export declare class SettingsSchemaService extends Service {
|
|
12
|
+
/** @param ctx - providing ui-settings context. */
|
|
13
|
+
constructor(ctx: Context);
|
|
14
|
+
/**
|
|
15
|
+
* Rehydrate one serialized `schema.toJSON()` envelope.
|
|
16
|
+
* @param serialized - serialized Schemastery node.
|
|
17
|
+
* @returns live schema node.
|
|
18
|
+
*/
|
|
19
|
+
rehydrate(serialized: unknown): SchemaNode;
|
|
20
|
+
/**
|
|
21
|
+
* Validate a settings draft.
|
|
22
|
+
* @param schema - live schema node.
|
|
23
|
+
* @param draft - candidate settings value.
|
|
24
|
+
* @returns validation failure text, or `undefined` when valid.
|
|
25
|
+
*/
|
|
26
|
+
validate(schema: SchemaNode, draft: unknown): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve an object, dict, or array schema node at a settings path.
|
|
29
|
+
* @param root - schema node to traverse.
|
|
30
|
+
* @param path - object keys or array indexes.
|
|
31
|
+
* @returns the resolved node, or `undefined` when the path is absent.
|
|
32
|
+
*/
|
|
33
|
+
nodeAtPath(root: SchemaNode, path: readonly string[]): SchemaNode | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Read a nested value by a string-key or array-index path.
|
|
36
|
+
* @param value - value to traverse.
|
|
37
|
+
* @param path - object keys or array indexes.
|
|
38
|
+
* @returns the resolved value, or `undefined` when the path is absent.
|
|
39
|
+
*/
|
|
40
|
+
getPath(value: unknown, path: readonly string[]): unknown;
|
|
41
|
+
/**
|
|
42
|
+
* Report whether the final path key exists independently of its value.
|
|
43
|
+
* @param value - value to traverse.
|
|
44
|
+
* @param path - object keys or array indexes.
|
|
45
|
+
* @returns whether the path exists.
|
|
46
|
+
*/
|
|
47
|
+
hasPath(value: unknown, path: readonly string[]): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Immutably set a nested value, materializing missing containers.
|
|
50
|
+
* @param root - settings object to copy.
|
|
51
|
+
* @param path - non-empty object-key or array-index path.
|
|
52
|
+
* @param value - replacement value.
|
|
53
|
+
* @returns copied root containing the replacement.
|
|
54
|
+
* @throws when `path` is empty.
|
|
55
|
+
*/
|
|
56
|
+
setPath(root: Record<string, unknown>, path: readonly string[], value: unknown): Record<string, unknown>;
|
|
57
|
+
/**
|
|
58
|
+
* Immutably remove a nested key, preserving an unchanged missing root.
|
|
59
|
+
* @param root - settings object to copy.
|
|
60
|
+
* @param path - non-empty object-key or array-index path.
|
|
61
|
+
* @returns copied root without the key, or `root` when the path is absent.
|
|
62
|
+
* @throws when `path` is empty.
|
|
63
|
+
*/
|
|
64
|
+
deletePath(root: Record<string, unknown>, path: readonly string[]): Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
declare module '@prettier-ai/cordis' {
|
|
67
|
+
interface Context {
|
|
68
|
+
/** Settings-owned synchronous schema and immutable path operations. */
|
|
69
|
+
settingsSchema: SettingsSchemaService;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings-namespace scope contracts owned beside the settings transport.
|
|
3
|
+
*/
|
|
4
|
+
import type { SettingsPathOpView } from '@prettier-ai/dsh-api-remotes/client';
|
|
5
|
+
/** Client-side sync state of one settings namespace. */
|
|
6
|
+
export interface SettingsScopeSnapshot<T> {
|
|
7
|
+
/**
|
|
8
|
+
* `loading` until the first accepted section, `ready` while one stands, and
|
|
9
|
+
* `unavailable` when the namespace is not exposed to this client or the
|
|
10
|
+
* connection keeps preferences process-local (memory mode).
|
|
11
|
+
*/
|
|
12
|
+
status: 'loading' | 'ready' | 'unavailable';
|
|
13
|
+
/** Last accepted schema-resolved section; undefined before the first acceptance. */
|
|
14
|
+
value: T | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Composition layer the Host resolved {@link value} over, when the owning
|
|
17
|
+
* plugin declared one. What a field reverts to once cleared.
|
|
18
|
+
*/
|
|
19
|
+
base: unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Raw user layer as stored, when one exists. A field's PRESENCE here is what
|
|
22
|
+
* marks it overridden — an override whose value equals the composition
|
|
23
|
+
* default is still an override, and comparing values could not see it.
|
|
24
|
+
*/
|
|
25
|
+
user: unknown;
|
|
26
|
+
/** Namespace revision fencing the next write; undefined before the first Host view. */
|
|
27
|
+
revision: number | undefined;
|
|
28
|
+
/** Whether the Host document accepts writes; memory mode never does. */
|
|
29
|
+
writable: boolean;
|
|
30
|
+
/** `host` syncs with the Host document; `memory` keeps a remote browser process-local. */
|
|
31
|
+
mode: 'host' | 'memory';
|
|
32
|
+
}
|
|
33
|
+
/** Domain-owned description of one settings namespace consumed by a browser plugin. */
|
|
34
|
+
export interface SettingsScopeSpec<T> {
|
|
35
|
+
/** Settings namespace registered by the owning Host plugin. */
|
|
36
|
+
namespace: string;
|
|
37
|
+
/**
|
|
38
|
+
* Narrow one wire section; undefined keeps the last accepted value. The
|
|
39
|
+
* default validates the section against the namespace's own serialized wire
|
|
40
|
+
* schema, so domains add a decoder only to narrow beyond that schema.
|
|
41
|
+
*/
|
|
42
|
+
decode?: (section: unknown) => T | undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Reactive owner handle over one namespace's durable section — the browser
|
|
46
|
+
* mirror of the Host-side `SettingsScope` owner seam. Domain services read
|
|
47
|
+
* and observe the snapshot and route explicit user choices through its
|
|
48
|
+
* mutation methods.
|
|
49
|
+
*/
|
|
50
|
+
export interface SettingsScope<T> {
|
|
51
|
+
/** @returns the current sync snapshot (stable reference until the next change). */
|
|
52
|
+
getSnapshot(): SettingsScopeSnapshot<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Observe snapshot replacements.
|
|
55
|
+
* @param listener - invoked after each snapshot change.
|
|
56
|
+
* @returns the disposer removing this listener.
|
|
57
|
+
*/
|
|
58
|
+
subscribe(listener: () => void): () => void;
|
|
59
|
+
/**
|
|
60
|
+
* Queue one atomic namespace mutation. All operations share one revision
|
|
61
|
+
* fence, Host validation, persistence decision, and recovery read. Supplying
|
|
62
|
+
* `expectedRevision` preserves an earlier read as the fence instead of using
|
|
63
|
+
* the latest queued or mirrored revision.
|
|
64
|
+
* @param ops - ordered field operations copied when queued.
|
|
65
|
+
* @param expectedRevision - optional fixed revision read by the domain editor.
|
|
66
|
+
* @returns settlement after the mutation and any latest-write recovery read.
|
|
67
|
+
*/
|
|
68
|
+
mutate(ops: readonly SettingsPathOpView[], expectedRevision?: number): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Queue one field write. Rapid writes preserve mutation order, each carries
|
|
71
|
+
* the latest known namespace revision, and only the latest settlement may
|
|
72
|
+
* publish; a rejected or failed latest write reloads Host state instead.
|
|
73
|
+
* @param field - scalar field inside the namespace section.
|
|
74
|
+
* @param value - JSON-shaped value selected by the user.
|
|
75
|
+
* @returns settlement after the write and any latest-write recovery read.
|
|
76
|
+
*/
|
|
77
|
+
set(field: string, value: unknown): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Queue one field clear, so the field re-inherits the composition layer.
|
|
80
|
+
* Shares {@link set}'s ordering, revision, and recovery contract.
|
|
81
|
+
* @param field - scalar field inside the namespace section.
|
|
82
|
+
* @returns settlement after the clear and any latest-write recovery read.
|
|
83
|
+
*/
|
|
84
|
+
unset(field: string): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=settings-contract.d.ts.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client mirror of the Host settings document: the one `settings.describe`
|
|
3
|
+
* reader in the browser. Every settings consumer derives from this store —
|
|
4
|
+
* per-namespace scopes through `SettingsScopeBinder.bind`, cross-namespace
|
|
5
|
+
* surfaces through the binder's shared describe face — so startup cost and
|
|
6
|
+
* freshness are properties of this class, not of how many features own a
|
|
7
|
+
* preference. The Host stays the fact source: the mirror re-reads on the
|
|
8
|
+
* invalidations its owning plugin subscribes to and folds write answers in
|
|
9
|
+
* through {@link SettingsDescribeMirror.acceptView}.
|
|
10
|
+
*/
|
|
11
|
+
import type { ClientRemote, SettingsNamespaceView } from '@prettier-ai/dsh-api-remotes/client';
|
|
12
|
+
/**
|
|
13
|
+
* The settings Remote methods browser configuration surfaces may reach: the
|
|
14
|
+
* redacted read plus merge, replacement, and path-addressed writes.
|
|
15
|
+
* Named once here so the consumers share one face instead of each re-deriving
|
|
16
|
+
* it from the namespace.
|
|
17
|
+
*/
|
|
18
|
+
export type SettingsRemote = Pick<ClientRemote['settings'], 'describe' | 'update' | 'replace' | 'mutate'>;
|
|
19
|
+
/** Wire face carrying the settings Remote namespace. */
|
|
20
|
+
export interface SettingsWireFace {
|
|
21
|
+
/** The settings Remote namespace. */
|
|
22
|
+
settings: SettingsRemote;
|
|
23
|
+
}
|
|
24
|
+
type SettingsFace = SettingsWireFace;
|
|
25
|
+
/** The full `settings.describe` answer the mirror serves. */
|
|
26
|
+
export interface SettingsDescribeView {
|
|
27
|
+
/** Every namespace a live Host plugin registered, as the Host reported it. */
|
|
28
|
+
namespaces: readonly SettingsNamespaceView[];
|
|
29
|
+
/** Whether the settings provider accepts writes. */
|
|
30
|
+
writable: boolean;
|
|
31
|
+
/** Whether a native settings document exists for the Host to open. */
|
|
32
|
+
hasDocument: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Mirror state every derived settings surface renders from. */
|
|
35
|
+
export interface SettingsMirrorSnapshot {
|
|
36
|
+
/**
|
|
37
|
+
* `unavailable` is the terminal non-loopback state; `ready` persists across
|
|
38
|
+
* later failed refreshes (the held view keeps serving); `idle` means no
|
|
39
|
+
* answer is held and no read is running, so `ensure` will start one.
|
|
40
|
+
*/
|
|
41
|
+
status: 'idle' | 'loading' | 'ready' | 'unavailable';
|
|
42
|
+
/** The last good answer; undefined until the first success. */
|
|
43
|
+
view: SettingsDescribeView | undefined;
|
|
44
|
+
/** The latest refresh failure message, cleared by the next success. */
|
|
45
|
+
error: string | null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The mirror as cross-namespace surfaces consume it: current answer,
|
|
49
|
+
* subscription, first-use read, and the write-answer fold. `load` stays off
|
|
50
|
+
* this face — invalidation refreshes belong to the mirror's owning plugin.
|
|
51
|
+
*/
|
|
52
|
+
export interface SettingsDescribeFace {
|
|
53
|
+
/** @returns the current sync snapshot (stable reference until the next change). */
|
|
54
|
+
getSnapshot(): SettingsMirrorSnapshot;
|
|
55
|
+
/**
|
|
56
|
+
* Observe snapshot replacements.
|
|
57
|
+
* @param listener - invoked after each snapshot change.
|
|
58
|
+
* @returns the disposer removing this listener.
|
|
59
|
+
*/
|
|
60
|
+
subscribe(listener: () => void): () => void;
|
|
61
|
+
/**
|
|
62
|
+
* Resolve once an answer is held (or the mirror is terminally unavailable),
|
|
63
|
+
* reading only from `idle`.
|
|
64
|
+
* @returns settlement of the current or newly started read, if any.
|
|
65
|
+
*/
|
|
66
|
+
ensure(): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Fold one write answer's namespace view into the held view without a wire
|
|
69
|
+
* read, invalidating any older read still in flight.
|
|
70
|
+
* @param view - the namespace view a settings write answered with.
|
|
71
|
+
*/
|
|
72
|
+
acceptView(view: SettingsNamespaceView): void;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Serializes every Host `settings.describe` read behind one snapshot store.
|
|
76
|
+
* Concurrent {@link load} calls fold into the in-flight read plus one rerun,
|
|
77
|
+
* so an invalidation arriving mid-read is never lost and never duplicated.
|
|
78
|
+
*/
|
|
79
|
+
export declare class SettingsDescribeMirror implements SettingsDescribeFace {
|
|
80
|
+
private readonly api;
|
|
81
|
+
private readonly persistence;
|
|
82
|
+
private readonly store;
|
|
83
|
+
private inFlight;
|
|
84
|
+
private rerun;
|
|
85
|
+
private generation;
|
|
86
|
+
/**
|
|
87
|
+
* @param api - settings wire face.
|
|
88
|
+
* @param persistence - client-selected Host persistence; non-loopback pages may remain process-local.
|
|
89
|
+
*/
|
|
90
|
+
constructor(api: SettingsFace, persistence?: 'host' | 'memory');
|
|
91
|
+
/** @returns the current sync snapshot (stable reference until the next change). */
|
|
92
|
+
getSnapshot(): SettingsMirrorSnapshot;
|
|
93
|
+
/**
|
|
94
|
+
* Observe snapshot replacements.
|
|
95
|
+
* @param listener - invoked after each snapshot change.
|
|
96
|
+
* @returns the disposer removing this listener.
|
|
97
|
+
*/
|
|
98
|
+
subscribe(listener: () => void): () => void;
|
|
99
|
+
/**
|
|
100
|
+
* Refresh from the Host. A call during an in-flight read marks one rerun
|
|
101
|
+
* after it settles instead of racing a second wire read.
|
|
102
|
+
* @returns settlement after this call's freshness is reflected.
|
|
103
|
+
*/
|
|
104
|
+
load(): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Resolve once an answer is held (or the mirror is terminally unavailable),
|
|
107
|
+
* reading only from `idle`. The cheap idempotent entry for surfaces that
|
|
108
|
+
* render on first use.
|
|
109
|
+
* @returns settlement of the current or newly started read, if any.
|
|
110
|
+
*/
|
|
111
|
+
ensure(): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Fold one write answer's namespace view into the held view without a wire
|
|
114
|
+
* read, and invalidate any read still in flight. With no held document, the
|
|
115
|
+
* answer is not published as a partial document; an in-flight read reruns so
|
|
116
|
+
* it cannot publish a document fetched before the write committed.
|
|
117
|
+
* @param view - the namespace view a settings write answered with.
|
|
118
|
+
*/
|
|
119
|
+
acceptView(view: SettingsNamespaceView): void;
|
|
120
|
+
/**
|
|
121
|
+
* Convenience row lookup on the held view.
|
|
122
|
+
* @param ns - namespace identity.
|
|
123
|
+
* @returns the namespace view, or undefined while unanswered or unregistered.
|
|
124
|
+
*/
|
|
125
|
+
namespace(ns: string): SettingsNamespaceView | undefined;
|
|
126
|
+
private run;
|
|
127
|
+
private shouldRerun;
|
|
128
|
+
}
|
|
129
|
+
export {};
|
|
130
|
+
//# sourceMappingURL=settings-mirror.d.ts.map
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host transport for the settings-namespace scope contract. This file owns the
|
|
3
|
+
* per-namespace derivation over the shared {@link SettingsDescribeMirror} and
|
|
4
|
+
* the serialized write path. Reads never touch the wire here: the
|
|
5
|
+
* mirror is the one `settings.describe` reader, and every scope is a selector
|
|
6
|
+
* over its snapshot.
|
|
7
|
+
*/
|
|
8
|
+
import { Service } from '@prettier-ai/cordis';
|
|
9
|
+
import type { Context } from '@prettier-ai/cordis';
|
|
10
|
+
import type { SettingsPathOpView } from '@prettier-ai/dsh-api-remotes/client';
|
|
11
|
+
import type { SettingsSchemaService } from './schema.ts';
|
|
12
|
+
import type { SettingsScope, SettingsScopeSnapshot, SettingsScopeSpec } from './settings-contract.ts';
|
|
13
|
+
import { SettingsDescribeMirror, type SettingsDescribeFace, type SettingsWireFace } from './settings-mirror.ts';
|
|
14
|
+
type SettingsFace = SettingsWireFace;
|
|
15
|
+
/**
|
|
16
|
+
* One namespace's derived view over the shared describe mirror, plus that
|
|
17
|
+
* namespace's serialized Host writes. Writes carry the latest known namespace
|
|
18
|
+
* revision, fold their answers back into the mirror, and teardown waits for
|
|
19
|
+
* the operation already crossing the wire.
|
|
20
|
+
*/
|
|
21
|
+
export declare class SettingsScopeController<T> implements SettingsScope<T> {
|
|
22
|
+
private readonly api;
|
|
23
|
+
private readonly spec;
|
|
24
|
+
private readonly mirror;
|
|
25
|
+
private readonly persistence;
|
|
26
|
+
private readonly schema;
|
|
27
|
+
private readonly store;
|
|
28
|
+
private tail;
|
|
29
|
+
private writeGeneration;
|
|
30
|
+
private disposed;
|
|
31
|
+
private readonly unsubscribe;
|
|
32
|
+
/**
|
|
33
|
+
* Revision answered by a superseded write still ahead of the mirror: the
|
|
34
|
+
* mirror only folds the LATEST settlement in, so a queued successor takes
|
|
35
|
+
* its fence from here first.
|
|
36
|
+
*/
|
|
37
|
+
private pendingRevision;
|
|
38
|
+
/**
|
|
39
|
+
* @param api - settings wire face (writes only; reads ride the mirror).
|
|
40
|
+
* @param spec - namespace identity and optional narrowing decoder.
|
|
41
|
+
* @param mirror - the shared describe mirror this scope derives from.
|
|
42
|
+
* @param persistence - client-selected Host persistence; non-loopback pages may remain process-local.
|
|
43
|
+
* @param schema - settings-owned schema operations.
|
|
44
|
+
*/
|
|
45
|
+
constructor(api: SettingsFace, spec: SettingsScopeSpec<T>, mirror: SettingsDescribeMirror, persistence: 'host' | 'memory', schema: SettingsSchemaService);
|
|
46
|
+
/** @returns the current sync snapshot (stable reference until the next change). */
|
|
47
|
+
getSnapshot(): SettingsScopeSnapshot<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Observe snapshot replacements.
|
|
50
|
+
* @param listener - invoked after each snapshot change.
|
|
51
|
+
* @returns the disposer removing this listener.
|
|
52
|
+
*/
|
|
53
|
+
subscribe(listener: () => void): () => void;
|
|
54
|
+
/**
|
|
55
|
+
* Queue one field write; see {@link SettingsScope.set} for the ordering,
|
|
56
|
+
* revision, and recovery contract.
|
|
57
|
+
* @param field - scalar field inside the namespace section.
|
|
58
|
+
* @param value - JSON-shaped value selected by the user.
|
|
59
|
+
* @returns settlement after the write and any latest-write recovery read.
|
|
60
|
+
*/
|
|
61
|
+
set(field: string, value: unknown): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Queue one field clear; see {@link SettingsScope.unset} for the ordering,
|
|
64
|
+
* revision, and recovery contract.
|
|
65
|
+
* @param field - scalar field inside the namespace section.
|
|
66
|
+
* @returns settlement after the clear and any latest-write recovery read.
|
|
67
|
+
*/
|
|
68
|
+
unset(field: string): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Queue one atomic namespace mutation; see {@link SettingsScope.mutate}.
|
|
71
|
+
* @param ops - ordered field operations copied when queued.
|
|
72
|
+
* @param expectedRevision - optional fixed revision read by the domain editor.
|
|
73
|
+
* @returns settlement after the mutation and any latest-write recovery read.
|
|
74
|
+
*/
|
|
75
|
+
mutate(ops: readonly SettingsPathOpView[], expectedRevision?: number): Promise<void>;
|
|
76
|
+
/** Reload Host state for the latest failed write; superseded failures leave recovery to it. */
|
|
77
|
+
private recover;
|
|
78
|
+
/**
|
|
79
|
+
* Stop queued operations, stop deriving, and wait for the current wire call
|
|
80
|
+
* to settle.
|
|
81
|
+
* @returns settlement after the controller reaches quiescence.
|
|
82
|
+
*/
|
|
83
|
+
dispose(): Promise<void>;
|
|
84
|
+
private enqueue;
|
|
85
|
+
private derive;
|
|
86
|
+
private decode;
|
|
87
|
+
}
|
|
88
|
+
declare module '@prettier-ai/cordis' {
|
|
89
|
+
interface Context {
|
|
90
|
+
settingsScope: SettingsScopeBinder;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The settings domain's base service. Features that own a preference reach the
|
|
95
|
+
* settings transport through this service rather than a shared function: the
|
|
96
|
+
* client bundle purity gate forbids cross-plugin value imports and directs
|
|
97
|
+
* cross-plugin collaboration through cordis services
|
|
98
|
+
* (`packages/client/tsdown.client.ts`).
|
|
99
|
+
*/
|
|
100
|
+
export declare class SettingsScopeBinder extends Service {
|
|
101
|
+
private readonly mirror;
|
|
102
|
+
private readonly schema;
|
|
103
|
+
private readonly wire;
|
|
104
|
+
/**
|
|
105
|
+
* @param ctx - the providing plugin's context.
|
|
106
|
+
* @param config - the shared describe mirror every bound scope derives from,
|
|
107
|
+
* the settings-owned schema operations, and the settings Remote namespace the
|
|
108
|
+
* bound scopes write through. The namespace is captured here rather than read
|
|
109
|
+
* inside {@link bind}, because a Service reads `ctx` as its *consumer's*
|
|
110
|
+
* fiber: reading it there would make every caller declare `remote.settings`
|
|
111
|
+
* in its own `inject`.
|
|
112
|
+
*/
|
|
113
|
+
constructor(ctx: Context, config: {
|
|
114
|
+
mirror: SettingsDescribeMirror;
|
|
115
|
+
schema: SettingsSchemaService;
|
|
116
|
+
wire: SettingsWireFace;
|
|
117
|
+
});
|
|
118
|
+
/**
|
|
119
|
+
* The shared mirror's read/fold face for cross-namespace surfaces (schema
|
|
120
|
+
* introspection, the served-namespace directory). Per-namespace consumers
|
|
121
|
+
* use {@link bind}; both derive from the same snapshot, so they can never
|
|
122
|
+
* disagree about the document.
|
|
123
|
+
* @returns the describe face over the shared mirror.
|
|
124
|
+
*/
|
|
125
|
+
describe(): SettingsDescribeFace;
|
|
126
|
+
/**
|
|
127
|
+
* Bind one namespace scope on the CALLER's plugin lifecycle — the service
|
|
128
|
+
* proxy binds `this.ctx` to the caller at call time, so the scope's disposer
|
|
129
|
+
* belongs to the calling fiber. The scope derives from the shared mirror
|
|
130
|
+
* (whose invalidation subscriptions live with the providing plugin), so
|
|
131
|
+
* binding adds no wire read of its own and activation never blocks on the
|
|
132
|
+
* settings transport.
|
|
133
|
+
* @param spec - domain-owned namespace contract.
|
|
134
|
+
* @returns the bound scope consumed by the domain's services and rows.
|
|
135
|
+
*/
|
|
136
|
+
bind<T>(spec: SettingsScopeSpec<T>): SettingsScope<T>;
|
|
137
|
+
}
|
|
138
|
+
export {};
|
|
139
|
+
//# sourceMappingURL=settings-scope.d.ts.map
|