codify-plugin-lib 1.0.182-beta14 → 1.0.182-beta15
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 +2 -0
- package/dist/plugin/plugin.js +6 -13
- package/dist/pty/background-pty.js +4 -4
- package/package.json +1 -1
- package/src/plugin/plugin.ts +11 -18
- package/src/pty/background-pty.ts +5 -3
package/dist/plugin/plugin.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
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';
|
|
3
4
|
import { Resource } from '../resource/resource.js';
|
|
4
5
|
import { ResourceController } from '../resource/resource-controller.js';
|
|
5
6
|
export declare class Plugin {
|
|
6
7
|
name: string;
|
|
7
8
|
resourceControllers: Map<string, ResourceController<ResourceConfig>>;
|
|
8
9
|
planStorage: Map<string, Plan<any>>;
|
|
10
|
+
planPty: BackgroundPty;
|
|
9
11
|
constructor(name: string, resourceControllers: Map<string, ResourceController<ResourceConfig>>);
|
|
10
12
|
static create(name: string, resources: Resource<any>[]): Plugin;
|
|
11
13
|
initialize(data: InitializeRequestData): Promise<InitializeResponseData>;
|
package/dist/plugin/plugin.js
CHANGED
|
@@ -10,6 +10,7 @@ export class Plugin {
|
|
|
10
10
|
name;
|
|
11
11
|
resourceControllers;
|
|
12
12
|
planStorage;
|
|
13
|
+
planPty = new BackgroundPty();
|
|
13
14
|
constructor(name, resourceControllers) {
|
|
14
15
|
this.name = name;
|
|
15
16
|
this.resourceControllers = resourceControllers;
|
|
@@ -101,13 +102,9 @@ export class Plugin {
|
|
|
101
102
|
if (!this.resourceControllers.has(core.type)) {
|
|
102
103
|
throw new Error(`Cannot get info for resource ${core.type}, resource doesn't exist`);
|
|
103
104
|
}
|
|
104
|
-
const result = await ptyLocalStorage.run(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
?.import(core, parameters, autoSearchAll);
|
|
108
|
-
await getPty().kill();
|
|
109
|
-
return result;
|
|
110
|
-
});
|
|
105
|
+
const result = await ptyLocalStorage.run(this.planPty, () => this.resourceControllers
|
|
106
|
+
.get(core.type)
|
|
107
|
+
?.import(core, parameters, autoSearchAll));
|
|
111
108
|
return {
|
|
112
109
|
request: data,
|
|
113
110
|
result: result ?? [],
|
|
@@ -151,11 +148,7 @@ export class Plugin {
|
|
|
151
148
|
if (!this.resourceControllers.has(type)) {
|
|
152
149
|
throw new Error(`Resource type not found: ${type}`);
|
|
153
150
|
}
|
|
154
|
-
const plan = await ptyLocalStorage.run(
|
|
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
|
-
});
|
|
151
|
+
const plan = await ptyLocalStorage.run(this.planPty, async () => this.resourceControllers.get(type).plan(data.core, data.desired ?? null, data.state ?? null, data.isStateful));
|
|
159
152
|
this.planStorage.set(plan.id, plan);
|
|
160
153
|
return plan.toResponse();
|
|
161
154
|
}
|
|
@@ -181,7 +174,7 @@ export class Plugin {
|
|
|
181
174
|
}
|
|
182
175
|
}
|
|
183
176
|
async kill() {
|
|
184
|
-
await
|
|
177
|
+
await this.planPty.kill();
|
|
185
178
|
}
|
|
186
179
|
resolvePlan(data) {
|
|
187
180
|
const { plan: planRequest, planId } = data;
|
|
@@ -6,7 +6,6 @@ import * as fs from 'node:fs/promises';
|
|
|
6
6
|
import stripAnsi from 'strip-ansi';
|
|
7
7
|
import { debugLog } from '../utils/debug.js';
|
|
8
8
|
import { Shell, Utils } from '../utils/index.js';
|
|
9
|
-
import { VerbosityLevel } from '../utils/verbosity-level.js';
|
|
10
9
|
import { SpawnError } from './index.js';
|
|
11
10
|
import { PromiseQueue } from './promise-queue.js';
|
|
12
11
|
EventEmitter.defaultMaxListeners = 1000;
|
|
@@ -51,6 +50,7 @@ export class BackgroundPty {
|
|
|
51
50
|
let output = '';
|
|
52
51
|
cat.stdout.on('data', (data) => {
|
|
53
52
|
output += data.toString();
|
|
53
|
+
process.stdout.write(data);
|
|
54
54
|
if (output.includes('%%%done%%%"')) {
|
|
55
55
|
const truncOutput = output.replace('%%%done%%%"\n', '');
|
|
56
56
|
const [data, exit] = truncOutput.split('%%%');
|
|
@@ -67,9 +67,9 @@ export class BackgroundPty {
|
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
69
|
// Print to stdout if the verbosity level is above 0
|
|
70
|
-
if (VerbosityLevel.get() > 0) {
|
|
71
|
-
|
|
72
|
-
}
|
|
70
|
+
// if (VerbosityLevel.get() > 0) {
|
|
71
|
+
// process.stdout.write(data);
|
|
72
|
+
// }
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
75
|
this.promiseQueue.run(async () => new Promise((resolve) => {
|
package/package.json
CHANGED
package/src/plugin/plugin.ts
CHANGED
|
@@ -29,6 +29,7 @@ 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();
|
|
32
33
|
|
|
33
34
|
constructor(
|
|
34
35
|
public name: string,
|
|
@@ -147,14 +148,11 @@ export class Plugin {
|
|
|
147
148
|
throw new Error(`Cannot get info for resource ${core.type}, resource doesn't exist`);
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
const result = await ptyLocalStorage.run(
|
|
151
|
-
|
|
151
|
+
const result = await ptyLocalStorage.run(this.planPty, () =>
|
|
152
|
+
this.resourceControllers
|
|
152
153
|
.get(core.type!)
|
|
153
154
|
?.import(core, parameters, autoSearchAll)
|
|
154
|
-
|
|
155
|
-
await getPty().kill()
|
|
156
|
-
return result;
|
|
157
|
-
})
|
|
155
|
+
)
|
|
158
156
|
|
|
159
157
|
return {
|
|
160
158
|
request: data,
|
|
@@ -213,17 +211,12 @@ export class Plugin {
|
|
|
213
211
|
throw new Error(`Resource type not found: ${type}`);
|
|
214
212
|
}
|
|
215
213
|
|
|
216
|
-
const plan = await ptyLocalStorage.run(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
)
|
|
223
|
-
|
|
224
|
-
await getPty().kill();
|
|
225
|
-
return result;
|
|
226
|
-
})
|
|
214
|
+
const plan = await ptyLocalStorage.run(this.planPty, async () => this.resourceControllers.get(type)!.plan(
|
|
215
|
+
data.core,
|
|
216
|
+
data.desired ?? null,
|
|
217
|
+
data.state ?? null,
|
|
218
|
+
data.isStateful
|
|
219
|
+
))
|
|
227
220
|
|
|
228
221
|
this.planStorage.set(plan.id, plan);
|
|
229
222
|
|
|
@@ -265,7 +258,7 @@ export class Plugin {
|
|
|
265
258
|
}
|
|
266
259
|
|
|
267
260
|
async kill() {
|
|
268
|
-
await
|
|
261
|
+
await this.planPty.kill();
|
|
269
262
|
}
|
|
270
263
|
|
|
271
264
|
private resolvePlan(data: ApplyRequestData): Plan<ResourceConfig> {
|
|
@@ -64,6 +64,8 @@ export class BackgroundPty implements IPty {
|
|
|
64
64
|
cat.stdout.on('data', (data) => {
|
|
65
65
|
output += data.toString();
|
|
66
66
|
|
|
67
|
+
process.stdout.write(data);
|
|
68
|
+
|
|
67
69
|
if (output.includes('%%%done%%%"')) {
|
|
68
70
|
const truncOutput = output.replace('%%%done%%%"\n', '');
|
|
69
71
|
const [data, exit] = truncOutput.split('%%%');
|
|
@@ -81,9 +83,9 @@ export class BackgroundPty implements IPty {
|
|
|
81
83
|
});
|
|
82
84
|
} else {
|
|
83
85
|
// Print to stdout if the verbosity level is above 0
|
|
84
|
-
if (VerbosityLevel.get() > 0) {
|
|
85
|
-
|
|
86
|
-
}
|
|
86
|
+
// if (VerbosityLevel.get() > 0) {
|
|
87
|
+
// process.stdout.write(data);
|
|
88
|
+
// }
|
|
87
89
|
}
|
|
88
90
|
})
|
|
89
91
|
|