@woosau/dsh-custom-env 0.1.1 → 0.1.6
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 +84 -53
- package/README.zh-CN.md +84 -53
- package/lib/client.js +138 -1
- package/lib/index.js +327 -180
- package/lib/typert.host.js +171 -1
- package/lib/typert.remote-client.js +143 -1
- package/lib/types/env-file.d.ts +59 -11
- package/lib/types/index.d.ts +33 -4
- package/lib/types/os-user-env/index.d.ts +15 -4
- package/lib/types/os-user-env/macos.d.ts +15 -1
- package/lib/types/os-user-env/windows.d.ts +20 -6
- package/lib/types/types.d.ts +5 -0
- package/package.json +1 -1
package/lib/typert.host.js
CHANGED
|
@@ -37,6 +37,33 @@ const upsert$parameter$2$schema = () => (upsert$parameter$2$schema$value ??= z.s
|
|
|
37
37
|
let remove$parameter$0$schema$value
|
|
38
38
|
const remove$parameter$0$schema = () => (remove$parameter$0$schema$value ??= z.string())
|
|
39
39
|
|
|
40
|
+
let setVar$parameter$0$schema$value
|
|
41
|
+
const setVar$parameter$0$schema = () => (setVar$parameter$0$schema$value ??= z.string())
|
|
42
|
+
let setVar$parameter$1$schema$value
|
|
43
|
+
const setVar$parameter$1$schema = () => (setVar$parameter$1$schema$value ??= z.string())
|
|
44
|
+
|
|
45
|
+
let setVars$parameter$0$schema$value
|
|
46
|
+
const setVars$parameter$0$schema = () => (setVars$parameter$0$schema$value ??= z.array(z.object({
|
|
47
|
+
name: z.string().readonly(),
|
|
48
|
+
value: z.string().readonly(),
|
|
49
|
+
}).readonly()).readonly())
|
|
50
|
+
|
|
51
|
+
let removeVar$parameter$0$schema$value
|
|
52
|
+
const removeVar$parameter$0$schema = () => (removeVar$parameter$0$schema$value ??= z.string())
|
|
53
|
+
|
|
54
|
+
let removeVars$parameter$0$schema$value
|
|
55
|
+
const removeVars$parameter$0$schema = () => (removeVars$parameter$0$schema$value ??= z.array(z.string()).readonly())
|
|
56
|
+
|
|
57
|
+
const envVarWriteJsonSchema = {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
name: { type: 'string' },
|
|
61
|
+
value: { type: 'string' },
|
|
62
|
+
},
|
|
63
|
+
required: ['name', 'value'],
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
}
|
|
66
|
+
|
|
40
67
|
let restore$parameter$0$schema$value
|
|
41
68
|
const restore$parameter$0$schema = () => (restore$parameter$0$schema$value ??= z.string())
|
|
42
69
|
|
|
@@ -126,7 +153,7 @@ const $remote = createTypertRemoteInfo({
|
|
|
126
153
|
},
|
|
127
154
|
{
|
|
128
155
|
name: 'value',
|
|
129
|
-
description: '
|
|
156
|
+
description: 'value (empty string allowed).',
|
|
130
157
|
source: 'json',
|
|
131
158
|
codec: {
|
|
132
159
|
mode: 'strict',
|
|
@@ -145,6 +172,121 @@ const $remote = createTypertRemoteInfo({
|
|
|
145
172
|
},
|
|
146
173
|
sourceLocation: { file: 'src/index.ts', line: 1, column: 1 },
|
|
147
174
|
},
|
|
175
|
+
'customEnv/setVars': {
|
|
176
|
+
service: 'customEnv',
|
|
177
|
+
description: 'Create or replace many variables by name in one rewrite. Empty values write NAME=.',
|
|
178
|
+
invocation: { kind: 'direct' },
|
|
179
|
+
parameters: [
|
|
180
|
+
{
|
|
181
|
+
name: 'entries',
|
|
182
|
+
description: 'name/value pairs (last duplicate name wins).',
|
|
183
|
+
source: 'json',
|
|
184
|
+
codec: {
|
|
185
|
+
mode: 'strict',
|
|
186
|
+
typeSymbol: 'readonly EnvVarWrite[]',
|
|
187
|
+
create: setVars$parameter$0$schema,
|
|
188
|
+
jsonSchema: { type: 'array', items: envVarWriteJsonSchema },
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
result: {
|
|
193
|
+
mode: 'strict',
|
|
194
|
+
typeSymbol: 'void',
|
|
195
|
+
create: () => z.undefined(),
|
|
196
|
+
description: 'no return value.',
|
|
197
|
+
jsonSchema: { type: 'null' },
|
|
198
|
+
},
|
|
199
|
+
sourceLocation: { file: 'src/index.ts', line: 1, column: 1 },
|
|
200
|
+
},
|
|
201
|
+
'customEnv/setVar': {
|
|
202
|
+
service: 'customEnv',
|
|
203
|
+
description: 'Create or replace one variable by name. Empty value writes NAME=.',
|
|
204
|
+
invocation: { kind: 'direct' },
|
|
205
|
+
parameters: [
|
|
206
|
+
{
|
|
207
|
+
name: 'name',
|
|
208
|
+
description: 'writable variable name.',
|
|
209
|
+
source: 'json',
|
|
210
|
+
codec: {
|
|
211
|
+
mode: 'strict',
|
|
212
|
+
typeSymbol: 'string',
|
|
213
|
+
create: setVar$parameter$0$schema,
|
|
214
|
+
jsonSchema: { type: 'string' },
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: 'value',
|
|
219
|
+
description: 'value to store (empty string allowed).',
|
|
220
|
+
source: 'json',
|
|
221
|
+
codec: {
|
|
222
|
+
mode: 'strict',
|
|
223
|
+
typeSymbol: 'string',
|
|
224
|
+
create: setVar$parameter$1$schema,
|
|
225
|
+
jsonSchema: { type: 'string' },
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
result: {
|
|
230
|
+
mode: 'strict',
|
|
231
|
+
typeSymbol: 'void',
|
|
232
|
+
create: () => z.undefined(),
|
|
233
|
+
description: 'no return value.',
|
|
234
|
+
jsonSchema: { type: 'null' },
|
|
235
|
+
},
|
|
236
|
+
sourceLocation: { file: 'src/index.ts', line: 1, column: 1 },
|
|
237
|
+
},
|
|
238
|
+
'customEnv/removeVars': {
|
|
239
|
+
service: 'customEnv',
|
|
240
|
+
description: 'Remove many variables by name from the file, Host, and OS user environment.',
|
|
241
|
+
invocation: { kind: 'direct' },
|
|
242
|
+
parameters: [
|
|
243
|
+
{
|
|
244
|
+
name: 'names',
|
|
245
|
+
description: 'writable variable names.',
|
|
246
|
+
source: 'json',
|
|
247
|
+
codec: {
|
|
248
|
+
mode: 'strict',
|
|
249
|
+
typeSymbol: 'readonly string[]',
|
|
250
|
+
create: removeVars$parameter$0$schema,
|
|
251
|
+
jsonSchema: { type: 'array', items: { type: 'string' } },
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
result: {
|
|
256
|
+
mode: 'strict',
|
|
257
|
+
typeSymbol: 'number',
|
|
258
|
+
create: () => z.number(),
|
|
259
|
+
description: 'number of .env lines removed.',
|
|
260
|
+
jsonSchema: { type: 'number' },
|
|
261
|
+
},
|
|
262
|
+
sourceLocation: { file: 'src/index.ts', line: 1, column: 1 },
|
|
263
|
+
},
|
|
264
|
+
'customEnv/removeVar': {
|
|
265
|
+
service: 'customEnv',
|
|
266
|
+
description: 'Remove one variable by name from the file, Host, and OS user environment.',
|
|
267
|
+
invocation: { kind: 'direct' },
|
|
268
|
+
parameters: [
|
|
269
|
+
{
|
|
270
|
+
name: 'name',
|
|
271
|
+
description: 'writable variable name.',
|
|
272
|
+
source: 'json',
|
|
273
|
+
codec: {
|
|
274
|
+
mode: 'strict',
|
|
275
|
+
typeSymbol: 'string',
|
|
276
|
+
create: removeVar$parameter$0$schema,
|
|
277
|
+
jsonSchema: { type: 'string' },
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
result: {
|
|
282
|
+
mode: 'strict',
|
|
283
|
+
typeSymbol: 'boolean',
|
|
284
|
+
create: () => z.boolean(),
|
|
285
|
+
description: 'true when a .env line was removed.',
|
|
286
|
+
jsonSchema: { type: 'boolean' },
|
|
287
|
+
},
|
|
288
|
+
sourceLocation: { file: 'src/index.ts', line: 1, column: 1 },
|
|
289
|
+
},
|
|
148
290
|
'customEnv/deleteEntry': {
|
|
149
291
|
service: 'customEnv',
|
|
150
292
|
description: 'Delete one entry from the file, Host, and OS user environment.',
|
|
@@ -257,6 +399,34 @@ export const TYPERT = {
|
|
|
257
399
|
summary: 'Create or update one row by id.',
|
|
258
400
|
jsDoc: '/** Create (`id === ""`) or update/rename one row. */',
|
|
259
401
|
},
|
|
402
|
+
{
|
|
403
|
+
kind: 'method',
|
|
404
|
+
name: 'setVars',
|
|
405
|
+
signature: "@Remote('setVars') async setVars(entries: readonly EnvVarWrite[]): Promise<void>",
|
|
406
|
+
summary: 'Create or replace many variables by name (empty values allowed).',
|
|
407
|
+
jsDoc: '/** Create or replace many variables by name. Empty values allowed. */',
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
kind: 'method',
|
|
411
|
+
name: 'setVar',
|
|
412
|
+
signature: "@Remote('setVar') async setVar(name: string, value: string): Promise<void>",
|
|
413
|
+
summary: 'Create or replace one variable by name (empty value allowed).',
|
|
414
|
+
jsDoc: '/** Create or replace one variable by name. Empty value allowed. */',
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
kind: 'method',
|
|
418
|
+
name: 'removeVars',
|
|
419
|
+
signature: "@Remote('removeVars') async removeVars(names: readonly string[]): Promise<number>",
|
|
420
|
+
summary: 'Remove many variables by name.',
|
|
421
|
+
jsDoc: '/** Remove many variables by name. Returns how many lines were removed. */',
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
kind: 'method',
|
|
425
|
+
name: 'removeVar',
|
|
426
|
+
signature: "@Remote('removeVar') async removeVar(name: string): Promise<boolean>",
|
|
427
|
+
summary: 'Remove one variable by name.',
|
|
428
|
+
jsDoc: '/** Remove one variable by name. Returns whether a line was removed. */',
|
|
429
|
+
},
|
|
260
430
|
{
|
|
261
431
|
kind: 'method',
|
|
262
432
|
name: 'deleteEntry',
|
|
@@ -37,6 +37,33 @@ const upsert$parameter$2$schema = () => (upsert$parameter$2$schema$value ??= z.s
|
|
|
37
37
|
let remove$parameter$0$schema$value
|
|
38
38
|
const remove$parameter$0$schema = () => (remove$parameter$0$schema$value ??= z.string())
|
|
39
39
|
|
|
40
|
+
let setVar$parameter$0$schema$value
|
|
41
|
+
const setVar$parameter$0$schema = () => (setVar$parameter$0$schema$value ??= z.string())
|
|
42
|
+
let setVar$parameter$1$schema$value
|
|
43
|
+
const setVar$parameter$1$schema = () => (setVar$parameter$1$schema$value ??= z.string())
|
|
44
|
+
|
|
45
|
+
let setVars$parameter$0$schema$value
|
|
46
|
+
const setVars$parameter$0$schema = () => (setVars$parameter$0$schema$value ??= z.array(z.object({
|
|
47
|
+
name: z.string().readonly(),
|
|
48
|
+
value: z.string().readonly(),
|
|
49
|
+
}).readonly()).readonly())
|
|
50
|
+
|
|
51
|
+
let removeVar$parameter$0$schema$value
|
|
52
|
+
const removeVar$parameter$0$schema = () => (removeVar$parameter$0$schema$value ??= z.string())
|
|
53
|
+
|
|
54
|
+
let removeVars$parameter$0$schema$value
|
|
55
|
+
const removeVars$parameter$0$schema = () => (removeVars$parameter$0$schema$value ??= z.array(z.string()).readonly())
|
|
56
|
+
|
|
57
|
+
const envVarWriteJsonSchema = {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
name: { type: 'string' },
|
|
61
|
+
value: { type: 'string' },
|
|
62
|
+
},
|
|
63
|
+
required: ['name', 'value'],
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
}
|
|
66
|
+
|
|
40
67
|
let restore$parameter$0$schema$value
|
|
41
68
|
const restore$parameter$0$schema = () => (restore$parameter$0$schema$value ??= z.string())
|
|
42
69
|
|
|
@@ -126,7 +153,7 @@ export const TYPERT_REMOTE = createTypertRemoteInfo({
|
|
|
126
153
|
},
|
|
127
154
|
{
|
|
128
155
|
name: 'value',
|
|
129
|
-
description: '
|
|
156
|
+
description: 'value (empty string allowed).',
|
|
130
157
|
source: 'json',
|
|
131
158
|
codec: {
|
|
132
159
|
mode: 'strict',
|
|
@@ -145,6 +172,121 @@ export const TYPERT_REMOTE = createTypertRemoteInfo({
|
|
|
145
172
|
},
|
|
146
173
|
sourceLocation: { file: 'src/index.ts', line: 1, column: 1 },
|
|
147
174
|
},
|
|
175
|
+
'customEnv/setVars': {
|
|
176
|
+
service: 'customEnv',
|
|
177
|
+
description: 'Create or replace many variables by name in one rewrite. Empty values write NAME=.',
|
|
178
|
+
invocation: { kind: 'direct' },
|
|
179
|
+
parameters: [
|
|
180
|
+
{
|
|
181
|
+
name: 'entries',
|
|
182
|
+
description: 'name/value pairs (last duplicate name wins).',
|
|
183
|
+
source: 'json',
|
|
184
|
+
codec: {
|
|
185
|
+
mode: 'strict',
|
|
186
|
+
typeSymbol: 'readonly EnvVarWrite[]',
|
|
187
|
+
create: setVars$parameter$0$schema,
|
|
188
|
+
jsonSchema: { type: 'array', items: envVarWriteJsonSchema },
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
result: {
|
|
193
|
+
mode: 'strict',
|
|
194
|
+
typeSymbol: 'void',
|
|
195
|
+
create: () => z.undefined(),
|
|
196
|
+
description: 'no return value.',
|
|
197
|
+
jsonSchema: { type: 'null' },
|
|
198
|
+
},
|
|
199
|
+
sourceLocation: { file: 'src/index.ts', line: 1, column: 1 },
|
|
200
|
+
},
|
|
201
|
+
'customEnv/setVar': {
|
|
202
|
+
service: 'customEnv',
|
|
203
|
+
description: 'Create or replace one variable by name. Empty value writes NAME=.',
|
|
204
|
+
invocation: { kind: 'direct' },
|
|
205
|
+
parameters: [
|
|
206
|
+
{
|
|
207
|
+
name: 'name',
|
|
208
|
+
description: 'writable variable name.',
|
|
209
|
+
source: 'json',
|
|
210
|
+
codec: {
|
|
211
|
+
mode: 'strict',
|
|
212
|
+
typeSymbol: 'string',
|
|
213
|
+
create: setVar$parameter$0$schema,
|
|
214
|
+
jsonSchema: { type: 'string' },
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: 'value',
|
|
219
|
+
description: 'value to store (empty string allowed).',
|
|
220
|
+
source: 'json',
|
|
221
|
+
codec: {
|
|
222
|
+
mode: 'strict',
|
|
223
|
+
typeSymbol: 'string',
|
|
224
|
+
create: setVar$parameter$1$schema,
|
|
225
|
+
jsonSchema: { type: 'string' },
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
result: {
|
|
230
|
+
mode: 'strict',
|
|
231
|
+
typeSymbol: 'void',
|
|
232
|
+
create: () => z.undefined(),
|
|
233
|
+
description: 'no return value.',
|
|
234
|
+
jsonSchema: { type: 'null' },
|
|
235
|
+
},
|
|
236
|
+
sourceLocation: { file: 'src/index.ts', line: 1, column: 1 },
|
|
237
|
+
},
|
|
238
|
+
'customEnv/removeVars': {
|
|
239
|
+
service: 'customEnv',
|
|
240
|
+
description: 'Remove many variables by name from the file, Host, and OS user environment.',
|
|
241
|
+
invocation: { kind: 'direct' },
|
|
242
|
+
parameters: [
|
|
243
|
+
{
|
|
244
|
+
name: 'names',
|
|
245
|
+
description: 'writable variable names.',
|
|
246
|
+
source: 'json',
|
|
247
|
+
codec: {
|
|
248
|
+
mode: 'strict',
|
|
249
|
+
typeSymbol: 'readonly string[]',
|
|
250
|
+
create: removeVars$parameter$0$schema,
|
|
251
|
+
jsonSchema: { type: 'array', items: { type: 'string' } },
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
result: {
|
|
256
|
+
mode: 'strict',
|
|
257
|
+
typeSymbol: 'number',
|
|
258
|
+
create: () => z.number(),
|
|
259
|
+
description: 'number of .env lines removed.',
|
|
260
|
+
jsonSchema: { type: 'number' },
|
|
261
|
+
},
|
|
262
|
+
sourceLocation: { file: 'src/index.ts', line: 1, column: 1 },
|
|
263
|
+
},
|
|
264
|
+
'customEnv/removeVar': {
|
|
265
|
+
service: 'customEnv',
|
|
266
|
+
description: 'Remove one variable by name from the file, Host, and OS user environment.',
|
|
267
|
+
invocation: { kind: 'direct' },
|
|
268
|
+
parameters: [
|
|
269
|
+
{
|
|
270
|
+
name: 'name',
|
|
271
|
+
description: 'writable variable name.',
|
|
272
|
+
source: 'json',
|
|
273
|
+
codec: {
|
|
274
|
+
mode: 'strict',
|
|
275
|
+
typeSymbol: 'string',
|
|
276
|
+
create: removeVar$parameter$0$schema,
|
|
277
|
+
jsonSchema: { type: 'string' },
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
result: {
|
|
282
|
+
mode: 'strict',
|
|
283
|
+
typeSymbol: 'boolean',
|
|
284
|
+
create: () => z.boolean(),
|
|
285
|
+
description: 'true when a .env line was removed.',
|
|
286
|
+
jsonSchema: { type: 'boolean' },
|
|
287
|
+
},
|
|
288
|
+
sourceLocation: { file: 'src/index.ts', line: 1, column: 1 },
|
|
289
|
+
},
|
|
148
290
|
'customEnv/deleteEntry': {
|
|
149
291
|
service: 'customEnv',
|
|
150
292
|
description: 'Delete one entry from the file, Host, and OS user environment.',
|
package/lib/types/env-file.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ export interface RawEnvEntry {
|
|
|
7
7
|
/** Absolute path of `$DSH_HOME/.env`. */
|
|
8
8
|
export declare function envFilePath(): string;
|
|
9
9
|
/**
|
|
10
|
-
* Read
|
|
10
|
+
* Read writable entries from `$DSH_HOME/.env` (empty values included).
|
|
11
11
|
* @returns Variable map, or `{}` when absent / empty.
|
|
12
12
|
*/
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function readEnvMap(): Readonly<Record<string, string>>;
|
|
14
14
|
/**
|
|
15
15
|
* List writable entries in `.env` file order (new keys stay at the end).
|
|
16
16
|
* @returns Path, existence, and ordered entries.
|
|
@@ -20,18 +20,66 @@ export declare function listEnvEntries(): {
|
|
|
20
20
|
exists: boolean;
|
|
21
21
|
entries: RawEnvEntry[];
|
|
22
22
|
};
|
|
23
|
+
/** Options for empty-value write policy. */
|
|
24
|
+
export interface WriteEnvOptions {
|
|
25
|
+
/**
|
|
26
|
+
* When true, empty values always create/replace.
|
|
27
|
+
* When false (default), empty values only create a missing key; existing keys
|
|
28
|
+
* in `$DSH_HOME/.env` or the OS user environment are left unchanged.
|
|
29
|
+
*/
|
|
30
|
+
readonly forceEmpty?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether `name` already exists in `$DSH_HOME/.env` or the OS user environment.
|
|
34
|
+
* Presence counts even when the current value is empty.
|
|
35
|
+
* @param name - Variable name.
|
|
36
|
+
* @returns true when a same-named entry is already present.
|
|
37
|
+
*/
|
|
38
|
+
export declare function hasEnvKey(name: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Drop empty writes that would clobber an existing key (unless `forceEmpty`).
|
|
41
|
+
* Non-empty values always pass; last duplicate name wins.
|
|
42
|
+
* @param entries - Candidate writes.
|
|
43
|
+
* @param options - Empty-value policy.
|
|
44
|
+
* @returns Entries that should be applied.
|
|
45
|
+
*/
|
|
46
|
+
export declare function selectEnvWrites(entries: readonly {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly value: string;
|
|
49
|
+
}[], options?: WriteEnvOptions): RawEnvEntry[];
|
|
23
50
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
51
|
+
* Create or replace many keys in one file rewrite (last duplicate name wins).
|
|
52
|
+
* Existing keys keep file order; new keys append in input order.
|
|
53
|
+
* Empty values write `NAME=` only when the key is absent (unless `forceEmpty`).
|
|
54
|
+
* @param entries - name/value pairs.
|
|
55
|
+
* @param options - Empty-value policy.
|
|
56
|
+
* @returns Entries actually written (may be empty when all empty writes were skipped).
|
|
57
|
+
*/
|
|
58
|
+
export declare function writeEnvEntries(entries: readonly {
|
|
59
|
+
readonly name: string;
|
|
60
|
+
readonly value: string;
|
|
61
|
+
}[], options?: WriteEnvOptions): RawEnvEntry[];
|
|
62
|
+
/**
|
|
63
|
+
* Create or replace one key (append when new). Honors empty-skip unless `forceEmpty`.
|
|
64
|
+
* @param name - Variable name.
|
|
65
|
+
* @param value - Value to store.
|
|
66
|
+
* @param options - Empty-value policy.
|
|
67
|
+
* @returns true when the file was rewritten.
|
|
68
|
+
*/
|
|
69
|
+
export declare function writeEnvEntry(name: string, value: string, options?: WriteEnvOptions): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Rename one key in place (keeps file order) and always write `value`.
|
|
72
|
+
* @param from - Existing name.
|
|
73
|
+
* @param to - New name.
|
|
74
|
+
* @param value - Value to store.
|
|
29
75
|
*/
|
|
30
|
-
export declare function writeEnvEntry(replaceName: string, name: string, value: string): void;
|
|
31
|
-
/** Create or replace one key (append when new). */
|
|
32
|
-
export declare function upsertEnvEntry(name: string, value: string): void;
|
|
33
|
-
/** Rename one key in place (keeps file order). */
|
|
34
76
|
export declare function renameEnvEntry(from: string, to: string, value: string): void;
|
|
77
|
+
/**
|
|
78
|
+
* Remove many keys from `$DSH_HOME/.env` in one rewrite.
|
|
79
|
+
* @param names - variable names (all must be writable).
|
|
80
|
+
* @returns number of assignment lines removed.
|
|
81
|
+
*/
|
|
82
|
+
export declare function removeEnvEntries(names: readonly string[]): number;
|
|
35
83
|
/**
|
|
36
84
|
* Remove one key from `$DSH_HOME/.env` when present.
|
|
37
85
|
* @param name - variable name.
|
package/lib/types/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import type { Context } from '@deepseek-ai/cordis';
|
|
5
5
|
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
6
6
|
import { envFilePath } from './env-file.ts';
|
|
7
|
-
import { type CliStatus, type EnvSnapshot } from './types.ts';
|
|
8
|
-
export type { BaselineRow, CliStatus, EnvEntry, EnvSnapshot } from './types.ts';
|
|
7
|
+
import { type CliStatus, type EnvSnapshot, type EnvVarWrite } from './types.ts';
|
|
8
|
+
export type { BaselineRow, CliStatus, EnvEntry, EnvSnapshot, EnvVarWrite } from './types.ts';
|
|
9
9
|
export { classifyEntry } from './types.ts';
|
|
10
10
|
declare module '@deepseek-ai/cordis' {
|
|
11
11
|
interface Context {
|
|
@@ -39,7 +39,10 @@ export default class CustomEnvController extends TypertRemoteService {
|
|
|
39
39
|
private bind;
|
|
40
40
|
private unbind;
|
|
41
41
|
private requireName;
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Write `name=value` replacing `from` in place; sync process.env / OS.
|
|
44
|
+
* Empty values create missing keys only, unless `forceEmpty` (restore).
|
|
45
|
+
*/
|
|
43
46
|
private commit;
|
|
44
47
|
/** @returns path, existence, and file-ordered entries. */
|
|
45
48
|
list(): Promise<EnvSnapshot>;
|
|
@@ -47,9 +50,35 @@ export default class CustomEnvController extends TypertRemoteService {
|
|
|
47
50
|
* Create or update one row. Empty `id` creates; otherwise keeps that baseline id across renames.
|
|
48
51
|
* @param id - row id, or `""` for a new row.
|
|
49
52
|
* @param name - variable name.
|
|
50
|
-
* @param value -
|
|
53
|
+
* @param value - value (empty creates only when missing; Settings UI may still reject empty drafts).
|
|
51
54
|
*/
|
|
52
55
|
upsert(id: string, name: string, value: string): Promise<EnvSnapshot>;
|
|
56
|
+
/**
|
|
57
|
+
* Create or replace many variables by name (plugin-facing).
|
|
58
|
+
* Non-empty values always write; empty values create missing keys only and do not
|
|
59
|
+
* clear existing `$DSH_HOME/.env` or OS user values. One file rewrite; last
|
|
60
|
+
* duplicate name wins. Invalid names reject the whole batch.
|
|
61
|
+
* @param entries - name/value pairs.
|
|
62
|
+
*/
|
|
63
|
+
setVars(entries: readonly EnvVarWrite[]): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Create or replace one variable by name (plugin-facing).
|
|
66
|
+
* @param name - writable variable name.
|
|
67
|
+
* @param value - non-empty always stores; `""` writes `NAME=` only when the key is absent.
|
|
68
|
+
*/
|
|
69
|
+
setVar(name: string, value: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Remove many variables by name (plugin-facing).
|
|
72
|
+
* @param names - writable variable names.
|
|
73
|
+
* @returns number of `.env` lines removed.
|
|
74
|
+
*/
|
|
75
|
+
removeVars(names: readonly string[]): Promise<number>;
|
|
76
|
+
/**
|
|
77
|
+
* Remove one variable by name (plugin-facing).
|
|
78
|
+
* @param name - writable variable name.
|
|
79
|
+
* @returns true when a `.env` line was removed.
|
|
80
|
+
*/
|
|
81
|
+
removeVar(name: string): Promise<boolean>;
|
|
53
82
|
/** @param id - row id from list(). */
|
|
54
83
|
deleteEntry(id: string): Promise<EnvSnapshot>;
|
|
55
84
|
/** Restore Host-start original name+value, or delete if added after start. */
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
/** OS user-environment sync for Windows and macOS (no-op elsewhere). */
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Whether `name` already exists in the OS user environment (Windows HKCU or macOS user domain).
|
|
4
|
+
* @param name - Variable name.
|
|
5
|
+
* @returns true when present (value may be empty); false on unsupported platforms.
|
|
6
|
+
*/
|
|
7
|
+
export declare function hasUserEnv(name: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Write entries into the current user's OS environment when supported.
|
|
4
10
|
* @param entries - Variable map to write.
|
|
5
11
|
*/
|
|
6
|
-
export declare function
|
|
12
|
+
export declare function writeUserEnv(entries: Readonly<Record<string, string>>): void;
|
|
13
|
+
/**
|
|
14
|
+
* Remove many keys from the current user's OS environment when supported.
|
|
15
|
+
* @param names - Variable names to delete.
|
|
16
|
+
*/
|
|
17
|
+
export declare function removeUserEnvs(names: readonly string[]): void;
|
|
7
18
|
/**
|
|
8
19
|
* Remove one key from the current user's OS environment when supported.
|
|
9
20
|
* @param name - Variable name to delete.
|
|
10
21
|
*/
|
|
11
22
|
export declare function removeUserEnv(name: string): void;
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
23
|
+
export { hasWindowsUserEnv, removeWindowsUserEnv, removeWindowsUserEnvs, writeWindowsUserEnv, } from './windows.ts';
|
|
24
|
+
export { hasMacosUserEnv, removeMacosUserEnv, removeMacosUserEnvs, writeMacosUserEnv, } from './macos.ts';
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Persist user environment variables on macOS via launchctl and a Login LaunchAgent.
|
|
3
3
|
*/
|
|
4
|
+
/**
|
|
5
|
+
* Whether `name` is present in this process's macOS user-env tracking
|
|
6
|
+
* (`process.env` or the in-memory LaunchAgent cache).
|
|
7
|
+
* @param name - Variable name.
|
|
8
|
+
* @param platform - Override for tests; defaults to `process.platform`.
|
|
9
|
+
* @returns true when the name is already managed/visible.
|
|
10
|
+
*/
|
|
11
|
+
export declare function hasMacosUserEnv(name: string, platform?: NodeJS.Platform): boolean;
|
|
4
12
|
/**
|
|
5
13
|
* Set user-domain environment variables for new GUI sessions and refresh the Login Agent.
|
|
6
14
|
* @param entries - Variable map to persist.
|
|
7
15
|
* @param platform - Override for tests; defaults to `process.platform`.
|
|
8
16
|
*/
|
|
9
|
-
export declare function
|
|
17
|
+
export declare function writeMacosUserEnv(entries: Readonly<Record<string, string>>, platform?: NodeJS.Platform): void;
|
|
18
|
+
/**
|
|
19
|
+
* Unset many user-domain environment variables and refresh the Login Agent once.
|
|
20
|
+
* @param names - Variable names to remove.
|
|
21
|
+
* @param platform - Override for tests; defaults to `process.platform`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function removeMacosUserEnvs(names: readonly string[], platform?: NodeJS.Platform): void;
|
|
10
24
|
/**
|
|
11
25
|
* Unset one user-domain environment variable and refresh the Login Agent.
|
|
12
26
|
* @param name - Variable name to remove.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Persist or delete variables in the Windows user environment (HKCU\\Environment)
|
|
3
|
-
* via koffi + advapi32
|
|
3
|
+
* via koffi + advapi32 — no WM_SETTINGCHANGE broadcast (Host already updates process.env).
|
|
4
4
|
*/
|
|
5
|
-
/** Win32 registry
|
|
5
|
+
/** Win32 registry calls used to persist user environment values. */
|
|
6
6
|
export interface WindowsUserEnvBindings {
|
|
7
7
|
readonly openKey: (hKey: number, subKey: string, options: number, samDesired: number, result: [unknown]) => number;
|
|
8
|
+
readonly queryValue: (hKey: unknown, valueName: string, reserved: unknown, type: [number] | null, data: Buffer | null, cbData: [number]) => number;
|
|
8
9
|
readonly setValue: (hKey: unknown, valueName: string, reserved: number, type: number, data: Buffer, cbData: number) => number;
|
|
9
10
|
readonly deleteValue: (hKey: unknown, valueName: string) => number;
|
|
10
11
|
readonly closeKey: (hKey: unknown) => number;
|
|
11
|
-
readonly sendMessageTimeout: (hWnd: number, msg: number, wParam: number, lParam: string, flags: number, timeoutMs: number, result: [number]) => number;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Install FFI bindings for tests (skips loading koffi).
|
|
@@ -22,16 +22,30 @@ export declare function setWindowsUserEnvBindingsForTests(next: WindowsUserEnvBi
|
|
|
22
22
|
*/
|
|
23
23
|
export declare function encodeRegSz(value: string): Buffer;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Whether `name` exists under HKCU\\Environment (value may be empty).
|
|
26
|
+
* @param name - Variable name.
|
|
27
|
+
* @param platform - Override for tests; defaults to `process.platform`.
|
|
28
|
+
* @returns true when the value name is present.
|
|
29
|
+
*/
|
|
30
|
+
export declare function hasWindowsUserEnv(name: string, platform?: NodeJS.Platform): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Write entries into HKCU\\Environment (no desktop-wide Environment broadcast).
|
|
26
33
|
* No-op on non-Windows hosts or when `entries` is empty.
|
|
27
34
|
* @param entries - Variable map to persist.
|
|
28
35
|
* @param platform - Override for tests; defaults to `process.platform`.
|
|
29
36
|
*/
|
|
30
|
-
export declare function
|
|
37
|
+
export declare function writeWindowsUserEnv(entries: Readonly<Record<string, string>>, platform?: NodeJS.Platform): void;
|
|
38
|
+
/**
|
|
39
|
+
* Delete many user environment values from HKCU\\Environment in one open.
|
|
40
|
+
* Missing values are ignored.
|
|
41
|
+
* @param names - Variable names to remove.
|
|
42
|
+
* @param platform - Override for tests; defaults to `process.platform`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function removeWindowsUserEnvs(names: readonly string[], platform?: NodeJS.Platform): void;
|
|
31
45
|
/**
|
|
32
46
|
* Delete one user environment value from HKCU\\Environment.
|
|
33
47
|
* Missing values are ignored.
|
|
34
|
-
* @param name - Variable name to
|
|
48
|
+
* @param name - Variable name to delete.
|
|
35
49
|
* @param platform - Override for tests; defaults to `process.platform`.
|
|
36
50
|
*/
|
|
37
51
|
export declare function removeWindowsUserEnv(name: string, platform?: NodeJS.Platform): void;
|
package/lib/types/types.d.ts
CHANGED
|
@@ -21,6 +21,11 @@ export interface EnvSnapshot {
|
|
|
21
21
|
readonly exists: boolean;
|
|
22
22
|
readonly entries: readonly EnvEntry[];
|
|
23
23
|
}
|
|
24
|
+
/** One name/value pair for plugin-facing `setVar` / `setVars`. */
|
|
25
|
+
export interface EnvVarWrite {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly value: string;
|
|
28
|
+
}
|
|
24
29
|
/** Snapshot returned by `customEnv/cliStatus` and `cliInstall`. */
|
|
25
30
|
export interface CliStatus {
|
|
26
31
|
readonly platform: string;
|