codify-plugin-lib 1.0.182-beta14 → 1.0.182-beta16
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 +8 -13
- package/dist/pty/background-pty.js +8 -4
- package/package.json +1 -1
- package/src/plugin/plugin.ts +15 -18
- package/src/pty/background-pty.ts +11 -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
|
}
|
|
@@ -173,7 +166,9 @@ export class Plugin {
|
|
|
173
166
|
// Default back desired back to current if it is not defined (for destroys only)
|
|
174
167
|
const validationPlan = await ptyLocalStorage.run(new BackgroundPty(), async () => {
|
|
175
168
|
const result = await resource.plan(plan.coreParameters, plan.desiredConfig, plan.desiredConfig ?? plan.currentConfig, plan.isStateful, 'validationPlan');
|
|
169
|
+
process.stdout.write(`Validation plan ${result}`);
|
|
176
170
|
await getPty().kill();
|
|
171
|
+
process.stdout.write('Killed');
|
|
177
172
|
return result;
|
|
178
173
|
});
|
|
179
174
|
if (validationPlan.requiresChanges()) {
|
|
@@ -181,7 +176,7 @@ export class Plugin {
|
|
|
181
176
|
}
|
|
182
177
|
}
|
|
183
178
|
async kill() {
|
|
184
|
-
await
|
|
179
|
+
await this.planPty.kill();
|
|
185
180
|
}
|
|
186
181
|
resolvePlan(data) {
|
|
187
182
|
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,7 +50,9 @@ 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
|
+
process.stdout.write('Done flag detected');
|
|
55
56
|
const truncOutput = output.replace('%%%done%%%"\n', '');
|
|
56
57
|
const [data, exit] = truncOutput.split('%%%');
|
|
57
58
|
// Clean up trailing \n newline if it exists
|
|
@@ -59,6 +60,9 @@ export class BackgroundPty {
|
|
|
59
60
|
if (strippedData.endsWith('\n')) {
|
|
60
61
|
strippedData = strippedData.slice(0, -1);
|
|
61
62
|
}
|
|
63
|
+
process.stdout.write(`Resolved exit ${exit}`);
|
|
64
|
+
process.stdout.write(`Raw data ${data}`);
|
|
65
|
+
process.stdout.write(`Stripped data ${strippedData}`);
|
|
62
66
|
resolve({
|
|
63
67
|
status: Number.parseInt(exit ?? 1, 10) === 0 ? 'success' : 'error',
|
|
64
68
|
exitCode: Number.parseInt(exit ?? 1, 10),
|
|
@@ -67,9 +71,9 @@ export class BackgroundPty {
|
|
|
67
71
|
}
|
|
68
72
|
else {
|
|
69
73
|
// Print to stdout if the verbosity level is above 0
|
|
70
|
-
if (VerbosityLevel.get() > 0) {
|
|
71
|
-
|
|
72
|
-
}
|
|
74
|
+
// if (VerbosityLevel.get() > 0) {
|
|
75
|
+
// process.stdout.write(data);
|
|
76
|
+
// }
|
|
73
77
|
}
|
|
74
78
|
});
|
|
75
79
|
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
|
|
|
@@ -255,7 +248,11 @@ export class Plugin {
|
|
|
255
248
|
'validationPlan'
|
|
256
249
|
);
|
|
257
250
|
|
|
251
|
+
process.stdout.write(`Validation plan ${result}`);
|
|
252
|
+
|
|
258
253
|
await getPty().kill();
|
|
254
|
+
|
|
255
|
+
process.stdout.write('Killed')
|
|
259
256
|
return result;
|
|
260
257
|
})
|
|
261
258
|
|
|
@@ -265,7 +262,7 @@ export class Plugin {
|
|
|
265
262
|
}
|
|
266
263
|
|
|
267
264
|
async kill() {
|
|
268
|
-
await
|
|
265
|
+
await this.planPty.kill();
|
|
269
266
|
}
|
|
270
267
|
|
|
271
268
|
private resolvePlan(data: ApplyRequestData): Plan<ResourceConfig> {
|
|
@@ -10,6 +10,7 @@ import { Shell, Utils } from '../utils/index.js';
|
|
|
10
10
|
import { VerbosityLevel } from '../utils/verbosity-level.js';
|
|
11
11
|
import { IPty, SpawnError, SpawnOptions, SpawnResult } from './index.js';
|
|
12
12
|
import { PromiseQueue } from './promise-queue.js';
|
|
13
|
+
import { str } from 'ajv';
|
|
13
14
|
|
|
14
15
|
EventEmitter.defaultMaxListeners = 1000;
|
|
15
16
|
|
|
@@ -64,7 +65,10 @@ export class BackgroundPty implements IPty {
|
|
|
64
65
|
cat.stdout.on('data', (data) => {
|
|
65
66
|
output += data.toString();
|
|
66
67
|
|
|
68
|
+
process.stdout.write(data);
|
|
69
|
+
|
|
67
70
|
if (output.includes('%%%done%%%"')) {
|
|
71
|
+
process.stdout.write('Done flag detected')
|
|
68
72
|
const truncOutput = output.replace('%%%done%%%"\n', '');
|
|
69
73
|
const [data, exit] = truncOutput.split('%%%');
|
|
70
74
|
|
|
@@ -74,6 +78,10 @@ export class BackgroundPty implements IPty {
|
|
|
74
78
|
strippedData = strippedData.slice(0, -1);
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
process.stdout.write(`Resolved exit ${exit}`);
|
|
82
|
+
process.stdout.write(`Raw data ${data}`);
|
|
83
|
+
process.stdout.write(`Stripped data ${strippedData}`);
|
|
84
|
+
|
|
77
85
|
resolve(<SpawnResult>{
|
|
78
86
|
status: Number.parseInt(exit ?? 1, 10) === 0 ? 'success' : 'error',
|
|
79
87
|
exitCode: Number.parseInt(exit ?? 1, 10),
|
|
@@ -81,9 +89,9 @@ export class BackgroundPty implements IPty {
|
|
|
81
89
|
});
|
|
82
90
|
} else {
|
|
83
91
|
// Print to stdout if the verbosity level is above 0
|
|
84
|
-
if (VerbosityLevel.get() > 0) {
|
|
85
|
-
|
|
86
|
-
}
|
|
92
|
+
// if (VerbosityLevel.get() > 0) {
|
|
93
|
+
// process.stdout.write(data);
|
|
94
|
+
// }
|
|
87
95
|
}
|
|
88
96
|
})
|
|
89
97
|
|