@cortexkit/common-auth 0.48.0 → 0.49.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/dist/settings/edit.d.ts
CHANGED
package/dist/settings/edit.js
CHANGED
|
@@ -37,7 +37,12 @@ function descriptorAtPath(descriptor, path) {
|
|
|
37
37
|
}
|
|
38
38
|
return current;
|
|
39
39
|
}
|
|
40
|
-
function destination(declaration, setting, value, { host, model }) {
|
|
40
|
+
function destination(declaration, setting, value, { host, model }, level) {
|
|
41
|
+
if (level !== undefined) {
|
|
42
|
+
return level === 'default' && !isJsonObject(value)
|
|
43
|
+
? [setting]
|
|
44
|
+
: [setting, level];
|
|
45
|
+
}
|
|
41
46
|
if (declaration.overrides !== undefined && isJsonObject(value)) {
|
|
42
47
|
if (declaration.overrides.model &&
|
|
43
48
|
model !== undefined &&
|
|
@@ -75,6 +80,20 @@ function checkPath(parsed, path) {
|
|
|
75
80
|
invalid();
|
|
76
81
|
}
|
|
77
82
|
}
|
|
83
|
+
function preservePlainDefault(parsed, setting) {
|
|
84
|
+
const node = parsed.tree && findNodeAtLocation(parsed.tree, [setting]);
|
|
85
|
+
if (!node)
|
|
86
|
+
invalid();
|
|
87
|
+
// Keep the original value text so comments inside a list survive promotion.
|
|
88
|
+
const value = parsed.text.slice(node.offset, node.offset + node.length);
|
|
89
|
+
return parseForEdit(applyEdits(parsed.text, [
|
|
90
|
+
{
|
|
91
|
+
offset: node.offset,
|
|
92
|
+
length: node.length,
|
|
93
|
+
content: `{ "default": ${value} }`,
|
|
94
|
+
},
|
|
95
|
+
]));
|
|
96
|
+
}
|
|
78
97
|
/** Remove only the member's own tokens; intervening comment lines belong to neither neighbor. */
|
|
79
98
|
function removeMember(text, tree, path) {
|
|
80
99
|
const property = tree && findNodeAtLocation(tree, path)?.parent;
|
|
@@ -157,6 +176,18 @@ export function applySettingsEdits(definition, source, edits, context) {
|
|
|
157
176
|
if (!Object.hasOwn(definition.settings, edit.setting))
|
|
158
177
|
invalid();
|
|
159
178
|
const declaration = definition.settings[edit.setting];
|
|
179
|
+
if (edit.level !== undefined) {
|
|
180
|
+
if (edit.path !== undefined)
|
|
181
|
+
invalid();
|
|
182
|
+
if (edit.level === 'default') {
|
|
183
|
+
if (declaration.overrides === undefined)
|
|
184
|
+
invalid();
|
|
185
|
+
}
|
|
186
|
+
else if ((edit.level !== 'opencode' && edit.level !== 'pi') ||
|
|
187
|
+
!declaration.overrides?.host) {
|
|
188
|
+
invalid();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
160
191
|
if (edit.path !== undefined &&
|
|
161
192
|
declaration.value.kind !== 'object' &&
|
|
162
193
|
declaration.value.kind !== 'record')
|
|
@@ -170,9 +201,24 @@ export function applySettingsEdits(definition, source, edits, context) {
|
|
|
170
201
|
const units = [];
|
|
171
202
|
for (const edit of edits) {
|
|
172
203
|
const declaration = definition.settings[edit.setting];
|
|
204
|
+
if (edit.level !== undefined &&
|
|
205
|
+
edit.level !== 'default' &&
|
|
206
|
+
!isJsonObject(working.value[edit.setting])) {
|
|
207
|
+
if (edit.remove === true)
|
|
208
|
+
continue;
|
|
209
|
+
if (Object.hasOwn(working.value, edit.setting)) {
|
|
210
|
+
working = preservePlainDefault(working, edit.setting);
|
|
211
|
+
}
|
|
212
|
+
// Earlier root edits now refer to the override's default, if it exists.
|
|
213
|
+
for (const unit of units) {
|
|
214
|
+
if (unit.path.length === 1 && unit.path[0] === edit.setting) {
|
|
215
|
+
unit.path.push('default');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
173
219
|
const base = edit.path !== undefined
|
|
174
220
|
? [edit.setting]
|
|
175
|
-
: destination(declaration, edit.setting, working.value[edit.setting], context);
|
|
221
|
+
: destination(declaration, edit.setting, working.value[edit.setting], context, edit.level);
|
|
176
222
|
const path = [...base, ...(edit.path ?? [])];
|
|
177
223
|
checkPath(working, path);
|
|
178
224
|
units.push(resolutionUnit(declaration.value, base, edit.path ?? []));
|
|
@@ -4,6 +4,7 @@ import { type ValueOf } from './descriptors.js';
|
|
|
4
4
|
import type { SettingsEdit, UpdateResult } from './edit.js';
|
|
5
5
|
import { type GetOptions } from './resolve.js';
|
|
6
6
|
import { type ReportEntry } from './snapshot.js';
|
|
7
|
+
import { type SettingsUpdatePlan } from './update.js';
|
|
7
8
|
export interface LegacyProjectSource {
|
|
8
9
|
readonly path: string;
|
|
9
10
|
read(text: string): unknown;
|
|
@@ -22,7 +23,7 @@ export interface SettingsHandle<S extends Readonly<Record<string, SettingDeclara
|
|
|
22
23
|
}): Promise<void>;
|
|
23
24
|
get<K extends keyof S & string>(name: K, options: GetOptions): Promise<ValueOf<S[K]['value']>>;
|
|
24
25
|
report(): ReportEntry[];
|
|
25
|
-
update(edits: readonly SettingsEdit[], options: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
|
|
26
|
+
update(edits: readonly SettingsEdit[] | SettingsUpdatePlan, options: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
|
|
26
27
|
watch(onChange: () => void): () => void;
|
|
27
28
|
}
|
|
28
29
|
/** Internal test hook; not part of the settings package exports. */
|
package/dist/settings/index.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export { SETTINGS_REFUSAL_CODES, SettingsRefusal, type SettingsRefusalCode, } fr
|
|
|
8
8
|
export type { GetOptions } from './resolve.js';
|
|
9
9
|
export { settingsJsonSchema } from './schema.js';
|
|
10
10
|
export type { ReportEntry, ReportReason } from './snapshot.js';
|
|
11
|
+
export type { SettingsCurrent, SettingsUpdatePlan } from './update.js';
|
|
@@ -2,5 +2,13 @@ import type { SettingsDefinition } from './define.js';
|
|
|
2
2
|
import { type SettingsEdit, type UpdateResult } from './edit.js';
|
|
3
3
|
import type { OpenSettingsOptions } from './handle.js';
|
|
4
4
|
import type { GetOptions } from './resolve.js';
|
|
5
|
+
export type SettingsCurrent = {
|
|
6
|
+
readonly status: 'missing';
|
|
7
|
+
} | {
|
|
8
|
+
readonly status: 'ready';
|
|
9
|
+
readonly document: Readonly<Record<string, unknown>>;
|
|
10
|
+
};
|
|
11
|
+
/** Compute edits synchronously from an immutable copy read under the write lock. */
|
|
12
|
+
export type SettingsUpdatePlan = (current: SettingsCurrent) => readonly SettingsEdit[];
|
|
5
13
|
/** Lock the canonical user file so symlink aliases serialize the same edits. */
|
|
6
|
-
export declare function updateSettings(definition: SettingsDefinition, options: OpenSettingsOptions, edits: readonly SettingsEdit[], context: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
|
|
14
|
+
export declare function updateSettings(definition: SettingsDefinition, options: OpenSettingsOptions, edits: readonly SettingsEdit[] | SettingsUpdatePlan, context: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
|
package/dist/settings/update.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { basename, dirname, join } from 'node:path';
|
|
2
2
|
import { ensurePrivateDirectory } from '../fs/private-files.js';
|
|
3
3
|
import { withLock } from '../fs/with-lock.js';
|
|
4
|
+
import { deepFreeze } from './descriptors.js';
|
|
4
5
|
import { applySettingsEdits, } from './edit.js';
|
|
5
6
|
import { SettingsFs } from './fs.js';
|
|
6
7
|
import { rethrowSettingsLockError } from './lock-errors.js';
|
|
@@ -97,6 +98,21 @@ export async function updateSettings(definition, options, edits, context) {
|
|
|
97
98
|
if (Number.isInteger(version) && version > 1) {
|
|
98
99
|
throw new SettingsRefusal('settings-newer-version', 'Settings were written by a newer version');
|
|
99
100
|
}
|
|
101
|
+
if (typeof edits === 'function') {
|
|
102
|
+
const planned = edits(deepFreeze(missing
|
|
103
|
+
? { status: 'missing' }
|
|
104
|
+
: {
|
|
105
|
+
status: 'ready',
|
|
106
|
+
document: structuredClone(parsed.value),
|
|
107
|
+
}));
|
|
108
|
+
if (planned !== null &&
|
|
109
|
+
(typeof planned === 'object' || typeof planned === 'function') &&
|
|
110
|
+
'then' in planned &&
|
|
111
|
+
typeof planned.then === 'function') {
|
|
112
|
+
throw new SettingsRefusal('settings-invalid-value', 'Settings update plans must be synchronous');
|
|
113
|
+
}
|
|
114
|
+
edits = planned;
|
|
115
|
+
}
|
|
100
116
|
if (!parsed.tree) {
|
|
101
117
|
source = `${parsed.hasBom ? '\uFEFF' : ''}// ${definition.plugin} settings\n{\n "schema_version": 1\n}\n`;
|
|
102
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/common-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"description": "Shared code for the CortexKit auth plugins: account pool, quota and routing, commands and auth menu, OpenCode 2 hooks, Claustrum custody, and plumbing (loopback RPC, file locks, logger, sidebar state, TUI preferences and build).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|