codify-plugin-lib 1.0.182-beta12 → 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.
@@ -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>;
@@ -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(this.planPty, () => this.resourceControllers
106
- .get(core.type)
107
- ?.import(core, parameters, autoSearchAll));
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(this.planPty, async () => this.resourceControllers.get(type).plan(data.core, data.desired ?? null, data.state ?? null, data.isStateful));
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 this.planPty.kill();
184
+ await getPty()?.kill();
178
185
  }
179
186
  resolvePlan(data) {
180
187
  const { plan: planRequest, planId } = data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.182-beta12",
3
+ "version": "1.0.182-beta14",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -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(this.planPty, () =>
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(this.planPty, async () => this.resourceControllers.get(type)!.plan(
215
- data.core,
216
- data.desired ?? null,
217
- data.state ?? null,
218
- data.isStateful
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 this.planPty.kill();
268
+ await getPty()?.kill();
262
269
  }
263
270
 
264
271
  private resolvePlan(data: ApplyRequestData): Plan<ResourceConfig> {