codify-plugin-lib 1.0.182-beta13 → 1.0.182-beta14
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/plugin/plugin.d.ts +0 -2
- package/dist/plugin/plugin.js +13 -6
- package/dist/pty/background-pty.js +1 -1
- package/package.json +1 -1
- package/src/plugin/plugin.ts +18 -11
- package/src/pty/background-pty.ts +1 -1
package/dist/plugin/plugin.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { ApplyRequestData, GetResourceInfoRequestData, GetResourceInfoResponseData, ImportRequestData, ImportResponseData, InitializeRequestData, InitializeResponseData, MatchRequestData, MatchResponseData, PlanRequestData, PlanResponseData, ResourceConfig, ResourceJson, ValidateRequestData, ValidateResponseData } from 'codify-schemas';
|
|
2
2
|
import { Plan } from '../plan/plan.js';
|
|
3
|
-
import { BackgroundPty } from '../pty/background-pty.js';
|
|
4
3
|
import { Resource } from '../resource/resource.js';
|
|
5
4
|
import { ResourceController } from '../resource/resource-controller.js';
|
|
6
5
|
export declare class Plugin {
|
|
7
6
|
name: string;
|
|
8
7
|
resourceControllers: Map<string, ResourceController<ResourceConfig>>;
|
|
9
8
|
planStorage: Map<string, Plan<any>>;
|
|
10
|
-
planPty: BackgroundPty;
|
|
11
9
|
constructor(name: string, resourceControllers: Map<string, ResourceController<ResourceConfig>>);
|
|
12
10
|
static create(name: string, resources: Resource<any>[]): Plugin;
|
|
13
11
|
initialize(data: InitializeRequestData): Promise<InitializeResponseData>;
|
package/dist/plugin/plugin.js
CHANGED
|
@@ -10,7 +10,6 @@ export class Plugin {
|
|
|
10
10
|
name;
|
|
11
11
|
resourceControllers;
|
|
12
12
|
planStorage;
|
|
13
|
-
planPty = new BackgroundPty();
|
|
14
13
|
constructor(name, resourceControllers) {
|
|
15
14
|
this.name = name;
|
|
16
15
|
this.resourceControllers = resourceControllers;
|
|
@@ -102,9 +101,13 @@ export class Plugin {
|
|
|
102
101
|
if (!this.resourceControllers.has(core.type)) {
|
|
103
102
|
throw new Error(`Cannot get info for resource ${core.type}, resource doesn't exist`);
|
|
104
103
|
}
|
|
105
|
-
const result = await ptyLocalStorage.run(
|
|
106
|
-
.
|
|
107
|
-
|
|
104
|
+
const result = await ptyLocalStorage.run(new BackgroundPty(), async () => {
|
|
105
|
+
const result = await this.resourceControllers
|
|
106
|
+
.get(core.type)
|
|
107
|
+
?.import(core, parameters, autoSearchAll);
|
|
108
|
+
await getPty().kill();
|
|
109
|
+
return result;
|
|
110
|
+
});
|
|
108
111
|
return {
|
|
109
112
|
request: data,
|
|
110
113
|
result: result ?? [],
|
|
@@ -148,7 +151,11 @@ export class Plugin {
|
|
|
148
151
|
if (!this.resourceControllers.has(type)) {
|
|
149
152
|
throw new Error(`Resource type not found: ${type}`);
|
|
150
153
|
}
|
|
151
|
-
const plan = await ptyLocalStorage.run(
|
|
154
|
+
const plan = await ptyLocalStorage.run(new BackgroundPty(), async () => {
|
|
155
|
+
const result = await this.resourceControllers.get(type).plan(data.core, data.desired ?? null, data.state ?? null, data.isStateful);
|
|
156
|
+
await getPty().kill();
|
|
157
|
+
return result;
|
|
158
|
+
});
|
|
152
159
|
this.planStorage.set(plan.id, plan);
|
|
153
160
|
return plan.toResponse();
|
|
154
161
|
}
|
|
@@ -174,7 +181,7 @@ export class Plugin {
|
|
|
174
181
|
}
|
|
175
182
|
}
|
|
176
183
|
async kill() {
|
|
177
|
-
await
|
|
184
|
+
await getPty()?.kill();
|
|
178
185
|
}
|
|
179
186
|
resolvePlan(data) {
|
|
180
187
|
const { plan: planRequest, planId } = data;
|
|
@@ -19,7 +19,7 @@ EventEmitter.defaultMaxListeners = 1000;
|
|
|
19
19
|
export class BackgroundPty {
|
|
20
20
|
historyIgnore = Utils.getShell() === Shell.ZSH ? { HISTORY_IGNORE: '*' } : { HISTIGNORE: '*' };
|
|
21
21
|
basePty = pty.spawn(this.getDefaultShell(), ['-i'], {
|
|
22
|
-
env: { ...process.env },
|
|
22
|
+
env: { ...process.env, ...this.historyIgnore },
|
|
23
23
|
name: nanoid(6),
|
|
24
24
|
handleFlowControl: true
|
|
25
25
|
});
|
package/package.json
CHANGED
package/src/plugin/plugin.ts
CHANGED
|
@@ -29,7 +29,6 @@ import { VerbosityLevel } from '../utils/verbosity-level.js';
|
|
|
29
29
|
|
|
30
30
|
export class Plugin {
|
|
31
31
|
planStorage: Map<string, Plan<any>>;
|
|
32
|
-
planPty = new BackgroundPty();
|
|
33
32
|
|
|
34
33
|
constructor(
|
|
35
34
|
public name: string,
|
|
@@ -148,11 +147,14 @@ export class Plugin {
|
|
|
148
147
|
throw new Error(`Cannot get info for resource ${core.type}, resource doesn't exist`);
|
|
149
148
|
}
|
|
150
149
|
|
|
151
|
-
const result = await ptyLocalStorage.run(
|
|
152
|
-
this.resourceControllers
|
|
150
|
+
const result = await ptyLocalStorage.run(new BackgroundPty(), async () => {
|
|
151
|
+
const result = await this.resourceControllers
|
|
153
152
|
.get(core.type!)
|
|
154
153
|
?.import(core, parameters, autoSearchAll)
|
|
155
|
-
|
|
154
|
+
|
|
155
|
+
await getPty().kill()
|
|
156
|
+
return result;
|
|
157
|
+
})
|
|
156
158
|
|
|
157
159
|
return {
|
|
158
160
|
request: data,
|
|
@@ -211,12 +213,17 @@ export class Plugin {
|
|
|
211
213
|
throw new Error(`Resource type not found: ${type}`);
|
|
212
214
|
}
|
|
213
215
|
|
|
214
|
-
const plan = await ptyLocalStorage.run(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
const plan = await ptyLocalStorage.run(new BackgroundPty(), async () => {
|
|
217
|
+
const result = await this.resourceControllers.get(type)!.plan(
|
|
218
|
+
data.core,
|
|
219
|
+
data.desired ?? null,
|
|
220
|
+
data.state ?? null,
|
|
221
|
+
data.isStateful
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
await getPty().kill();
|
|
225
|
+
return result;
|
|
226
|
+
})
|
|
220
227
|
|
|
221
228
|
this.planStorage.set(plan.id, plan);
|
|
222
229
|
|
|
@@ -258,7 +265,7 @@ export class Plugin {
|
|
|
258
265
|
}
|
|
259
266
|
|
|
260
267
|
async kill() {
|
|
261
|
-
await
|
|
268
|
+
await getPty()?.kill();
|
|
262
269
|
}
|
|
263
270
|
|
|
264
271
|
private resolvePlan(data: ApplyRequestData): Plan<ResourceConfig> {
|
|
@@ -22,7 +22,7 @@ EventEmitter.defaultMaxListeners = 1000;
|
|
|
22
22
|
export class BackgroundPty implements IPty {
|
|
23
23
|
private historyIgnore = Utils.getShell() === Shell.ZSH ? { HISTORY_IGNORE: '*' } : { HISTIGNORE: '*' };
|
|
24
24
|
private basePty = pty.spawn(this.getDefaultShell(), ['-i'], {
|
|
25
|
-
env: { ...process.env },
|
|
25
|
+
env: { ...process.env, ...this.historyIgnore },
|
|
26
26
|
name: nanoid(6),
|
|
27
27
|
handleFlowControl: true
|
|
28
28
|
});
|