codify-plugin-lib 1.0.181 → 1.0.182-beta1

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.
Files changed (34) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/plugin/plugin.js +5 -2
  4. package/dist/pty/background-pty.js +12 -4
  5. package/dist/pty/index.d.ts +17 -1
  6. package/dist/pty/seqeuntial-pty.d.ts +16 -0
  7. package/dist/pty/seqeuntial-pty.js +84 -0
  8. package/dist/resource/parsed-resource-settings.d.ts +3 -1
  9. package/dist/resource/parsed-resource-settings.js +4 -6
  10. package/dist/resource/resource-settings.d.ts +5 -1
  11. package/dist/resource/resource-settings.js +1 -1
  12. package/dist/utils/index.d.ts +25 -0
  13. package/dist/utils/index.js +108 -0
  14. package/dist/utils/internal-utils.d.ts +18 -0
  15. package/dist/utils/internal-utils.js +86 -0
  16. package/package.json +2 -2
  17. package/src/index.ts +1 -1
  18. package/src/plan/plan.test.ts +6 -1
  19. package/src/plugin/plugin.test.ts +11 -2
  20. package/src/plugin/plugin.ts +5 -2
  21. package/src/pty/background-pty.ts +14 -4
  22. package/src/pty/index.test.ts +7 -4
  23. package/src/pty/index.ts +17 -1
  24. package/src/pty/seqeuntial-pty.ts +105 -0
  25. package/src/pty/sequential-pty.test.ts +61 -0
  26. package/src/resource/parsed-resource-settings.ts +8 -7
  27. package/src/resource/resource-controller-stateful-mode.test.ts +2 -1
  28. package/src/resource/resource-controller.test.ts +22 -4
  29. package/src/resource/resource-settings.test.ts +29 -2
  30. package/src/resource/resource-settings.ts +13 -2
  31. package/src/utils/index.ts +140 -0
  32. package/src/utils/{utils.test.ts → internal-utils.test.ts} +1 -1
  33. package/src/utils/test-utils.test.ts +5 -2
  34. /package/src/utils/{utils.ts → internal-utils.ts} +0 -0
package/dist/index.d.ts CHANGED
@@ -10,5 +10,5 @@ export * from './resource/parsed-resource-settings.js';
10
10
  export * from './resource/resource.js';
11
11
  export * from './resource/resource-settings.js';
12
12
  export * from './stateful-parameter/stateful-parameter.js';
13
- export * from './utils/utils.js';
13
+ export * from './utils/index.js';
14
14
  export declare function runPlugin(plugin: Plugin): Promise<void>;
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ export * from './resource/parsed-resource-settings.js';
10
10
  export * from './resource/resource.js';
11
11
  export * from './resource/resource-settings.js';
12
12
  export * from './stateful-parameter/stateful-parameter.js';
13
- export * from './utils/utils.js';
13
+ export * from './utils/index.js';
14
14
  export async function runPlugin(plugin) {
15
15
  const messageHandler = new MessageHandler(plugin);
16
16
  process.on('message', (message) => messageHandler.onMessage(message));
@@ -2,9 +2,10 @@ import { ApplyValidationError } from '../common/errors.js';
2
2
  import { Plan } from '../plan/plan.js';
3
3
  import { BackgroundPty } from '../pty/background-pty.js';
4
4
  import { getPty } from '../pty/index.js';
5
+ import { SequentialPty } from '../pty/seqeuntial-pty.js';
5
6
  import { ResourceController } from '../resource/resource-controller.js';
7
+ import { VerbosityLevel } from '../utils/internal-utils.js';
6
8
  import { ptyLocalStorage } from '../utils/pty-local-storage.js';
7
- import { VerbosityLevel } from '../utils/utils.js';
8
9
  export class Plugin {
9
10
  name;
10
11
  resourceControllers;
@@ -44,6 +45,7 @@ export class Plugin {
44
45
  dependencies: r.dependencies,
45
46
  type: r.typeId,
46
47
  sensitiveParameters,
48
+ operatingSystems: r.settings.operatingSystems,
47
49
  };
48
50
  })
49
51
  };
@@ -81,6 +83,7 @@ export class Plugin {
81
83
  import: {
82
84
  requiredParameters: requiredPropertyNames,
83
85
  },
86
+ operatingSystems: resource.settings.operatingSystems,
84
87
  sensitiveParameters,
85
88
  allowMultiple
86
89
  };
@@ -158,7 +161,7 @@ export class Plugin {
158
161
  if (!resource) {
159
162
  throw new Error('Malformed plan with resource that cannot be found');
160
163
  }
161
- await resource.apply(plan);
164
+ await ptyLocalStorage.run(new SequentialPty(), async () => resource.apply(plan));
162
165
  // Validate using desired/desired. If the apply was successful, no changes should be reported back.
163
166
  // Default back desired back to current if it is not defined (for destroys only)
164
167
  const validationPlan = await ptyLocalStorage.run(new BackgroundPty(), async () => {
@@ -5,7 +5,8 @@ import { EventEmitter } from 'node:events';
5
5
  import * as fs from 'node:fs/promises';
6
6
  import stripAnsi from 'strip-ansi';
7
7
  import { debugLog } from '../utils/debug.js';
8
- import { VerbosityLevel } from '../utils/utils.js';
8
+ import { Shell, Utils } from '../utils/index.js';
9
+ import { VerbosityLevel } from '../utils/internal-utils.js';
9
10
  import { SpawnError } from './index.js';
10
11
  import { PromiseQueue } from './promise-queue.js';
11
12
  EventEmitter.defaultMaxListeners = 1000;
@@ -104,8 +105,15 @@ export class BackgroundPty {
104
105
  let outputBuffer = '';
105
106
  return new Promise(resolve => {
106
107
  // zsh-specific commands
107
- if (this.getDefaultShell() === 'zsh') {
108
- this.basePty.write('setopt hist_ignore_space;\n');
108
+ switch (Utils.getShell()) {
109
+ case Shell.ZSH: {
110
+ this.basePty.write('setopt HIST_NO_STORE;\n');
111
+ break;
112
+ }
113
+ default: {
114
+ this.basePty.write('export HISTIGNORE=\'history*\';\n');
115
+ break;
116
+ }
109
117
  }
110
118
  this.basePty.write(' unset PS1;\n');
111
119
  this.basePty.write(' unset PS0;\n');
@@ -121,6 +129,6 @@ export class BackgroundPty {
121
129
  });
122
130
  }
123
131
  getDefaultShell() {
124
- return process.platform === 'darwin' ? 'zsh' : 'bash';
132
+ return process.env.SHELL;
125
133
  }
126
134
  }
@@ -1,5 +1,5 @@
1
1
  export interface SpawnResult {
2
- status: 'success' | 'error';
2
+ status: 'error' | 'success';
3
3
  exitCode: number;
4
4
  data: string;
5
5
  }
@@ -7,9 +7,25 @@ export declare enum SpawnStatus {
7
7
  SUCCESS = "success",
8
8
  ERROR = "error"
9
9
  }
10
+ /**
11
+ * Represents the configuration options for spawning a child process.
12
+ *
13
+ * @interface SpawnOptions
14
+ *
15
+ * @property {string} [cwd] - Specifies the working directory of the child process.
16
+ * If not provided, the current working directory of the parent process is used.
17
+ *
18
+ * @property {Record<string, unknown>} [env] - Defines environment key-value pairs
19
+ * that will be available to the child process. If not specified, the child process
20
+ * will inherit the environment variables of the parent process.
21
+ *
22
+ * @property {boolean} [interactive] - Indicates whether the spawned process needs
23
+ * to be interactive. Only works within apply (not plan). Defaults to true.
24
+ */
10
25
  export interface SpawnOptions {
11
26
  cwd?: string;
12
27
  env?: Record<string, unknown>;
28
+ interactive?: boolean;
13
29
  }
14
30
  export declare class SpawnError extends Error {
15
31
  data: string;
@@ -0,0 +1,16 @@
1
+ import { IPty, SpawnOptions, SpawnResult } from './index.js';
2
+ /**
3
+ * The background pty is a specialized pty designed for speed. It can launch multiple tasks
4
+ * in parallel by moving them to the background. It attaches unix FIFO pipes to each process
5
+ * to listen to stdout and stderr. One limitation of the BackgroundPty is that the tasks run
6
+ * without a tty (or even a stdin) attached so interactive commands will not work.
7
+ */
8
+ export declare class SequentialPty implements IPty {
9
+ spawn(cmd: string, options?: SpawnOptions): Promise<SpawnResult>;
10
+ spawnSafe(cmd: string, options?: SpawnOptions): Promise<SpawnResult>;
11
+ kill(): Promise<{
12
+ exitCode: number;
13
+ signal?: number | undefined;
14
+ }>;
15
+ private getDefaultShell;
16
+ }
@@ -0,0 +1,84 @@
1
+ import pty from '@homebridge/node-pty-prebuilt-multiarch';
2
+ import { EventEmitter } from 'node:events';
3
+ import stripAnsi from 'strip-ansi';
4
+ import { Shell, Utils } from '../utils/index.js';
5
+ import { VerbosityLevel } from '../utils/internal-utils.js';
6
+ import { SpawnError, SpawnStatus } from './index.js';
7
+ EventEmitter.defaultMaxListeners = 1000;
8
+ /**
9
+ * The background pty is a specialized pty designed for speed. It can launch multiple tasks
10
+ * in parallel by moving them to the background. It attaches unix FIFO pipes to each process
11
+ * to listen to stdout and stderr. One limitation of the BackgroundPty is that the tasks run
12
+ * without a tty (or even a stdin) attached so interactive commands will not work.
13
+ */
14
+ export class SequentialPty {
15
+ async spawn(cmd, options) {
16
+ const spawnResult = await this.spawnSafe(cmd, options);
17
+ if (spawnResult.status !== 'success') {
18
+ throw new SpawnError(cmd, spawnResult.exitCode, spawnResult.data);
19
+ }
20
+ return spawnResult;
21
+ }
22
+ async spawnSafe(cmd, options) {
23
+ console.log(`Running command: ${cmd}` + (options?.cwd ? `(${options?.cwd})` : ''));
24
+ return new Promise((resolve) => {
25
+ const output = [];
26
+ const historyIgnore = Utils.getShell() === Shell.ZSH ? { HISTORY_IGNORE: '*' } : { HISTIGNORE: '*' };
27
+ // If TERM_PROGRAM=Apple_Terminal is set then ANSI escape characters may be included
28
+ // in the response.
29
+ const env = {
30
+ ...process.env, ...options?.env,
31
+ TERM_PROGRAM: 'codify',
32
+ COMMAND_MODE: 'unix2003',
33
+ COLORTERM: 'truecolor', ...historyIgnore
34
+ };
35
+ // Initial terminal dimensions
36
+ const initialCols = process.stdout.columns ?? 80;
37
+ const initialRows = process.stdout.rows ?? 24;
38
+ const args = (options?.interactive ?? true) ? ['-i', '-c', `"${cmd}"`] : ['-c', `"${cmd}"`];
39
+ // Run the command in a pty for interactivity
40
+ const mPty = pty.spawn(this.getDefaultShell(), args, {
41
+ ...options,
42
+ cols: initialCols,
43
+ rows: initialRows,
44
+ env
45
+ });
46
+ mPty.onData((data) => {
47
+ if (VerbosityLevel.get() > 0) {
48
+ process.stdout.write(data);
49
+ }
50
+ output.push(data.toString());
51
+ });
52
+ const stdinListener = (data) => {
53
+ mPty.write(data.toString());
54
+ };
55
+ const resizeListener = () => {
56
+ const { columns, rows } = process.stdout;
57
+ mPty.resize(columns, rows);
58
+ };
59
+ // Listen to resize events for the terminal window;
60
+ process.stdout.on('resize', resizeListener);
61
+ // Listen for user input
62
+ process.stdin.on('data', stdinListener);
63
+ mPty.onExit((result) => {
64
+ process.stdout.off('resize', resizeListener);
65
+ process.stdin.off('data', stdinListener);
66
+ resolve({
67
+ status: result.exitCode === 0 ? SpawnStatus.SUCCESS : SpawnStatus.ERROR,
68
+ exitCode: result.exitCode,
69
+ data: stripAnsi(output.join('\n').trim()),
70
+ });
71
+ });
72
+ });
73
+ }
74
+ async kill() {
75
+ // No-op here. Each pty instance is stand alone and tied to the parent process. Everything should be killed as expected.
76
+ return {
77
+ exitCode: 0,
78
+ signal: 0,
79
+ };
80
+ }
81
+ getDefaultShell() {
82
+ return process.env.SHELL;
83
+ }
84
+ }
@@ -1,5 +1,5 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
- import { StringIndexedObject } from 'codify-schemas';
2
+ import { OS, StringIndexedObject } from 'codify-schemas';
3
3
  import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
4
4
  import { ArrayParameterSetting, DefaultParameterSetting, InputTransformation, ResourceSettings } from './resource-settings.js';
5
5
  export interface ParsedStatefulParameterSetting extends DefaultParameterSetting {
@@ -26,6 +26,8 @@ export declare class ParsedResourceSettings<T extends StringIndexedObject> imple
26
26
  removeStatefulParametersBeforeDestroy?: boolean | undefined;
27
27
  dependencies?: string[] | undefined;
28
28
  transformation?: InputTransformation;
29
+ operatingSystems: Array<OS>;
30
+ isSensitive?: boolean;
29
31
  private settings;
30
32
  constructor(settings: ResourceSettings<T>);
31
33
  get typeId(): string;
@@ -8,15 +8,13 @@ export class ParsedResourceSettings {
8
8
  removeStatefulParametersBeforeDestroy;
9
9
  dependencies;
10
10
  transformation;
11
+ operatingSystems;
12
+ isSensitive;
11
13
  settings;
12
14
  constructor(settings) {
13
15
  this.settings = settings;
14
- this.id = settings.id;
15
- this.schema = settings.schema;
16
- this.allowMultiple = settings.allowMultiple;
17
- this.removeStatefulParametersBeforeDestroy = settings.removeStatefulParametersBeforeDestroy;
18
- this.dependencies = settings.dependencies;
19
- this.transformation = settings.transformation;
16
+ const { parameterSettings, ...rest } = settings;
17
+ Object.assign(this, rest);
20
18
  this.validateSettings();
21
19
  }
22
20
  get typeId() {
@@ -1,5 +1,5 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
- import { StringIndexedObject } from 'codify-schemas';
2
+ import { OS, StringIndexedObject } from 'codify-schemas';
3
3
  import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
4
4
  import { RefreshContext } from './resource.js';
5
5
  export interface InputTransformation {
@@ -14,6 +14,10 @@ export interface ResourceSettings<T extends StringIndexedObject> {
14
14
  * The typeId of the resource.
15
15
  */
16
16
  id: string;
17
+ /**
18
+ * List of supported operating systems
19
+ */
20
+ operatingSystems: Array<OS>;
17
21
  /**
18
22
  * Schema to validate user configs with. Must be in the format JSON Schema draft07
19
23
  */
@@ -1,6 +1,6 @@
1
1
  import isObjectsEqual from 'lodash.isequal';
2
2
  import path from 'node:path';
3
- import { addVariablesToPath, areArraysEqual, resolvePathWithVariables, tildify, untildify } from '../utils/utils.js';
3
+ import { addVariablesToPath, areArraysEqual, resolvePathWithVariables, tildify, untildify } from '../utils/internal-utils.js';
4
4
  const ParameterEqualsDefaults = {
5
5
  'boolean': (a, b) => Boolean(a) === Boolean(b),
6
6
  'directory': (a, b) => {
@@ -0,0 +1,25 @@
1
+ import { OS } from 'codify-schemas';
2
+ export declare enum Shell {
3
+ ZSH = "zsh",
4
+ BASH = "bash",
5
+ SH = "sh",
6
+ KSH = "ksh",
7
+ CSH = "csh",
8
+ FISH = "fish"
9
+ }
10
+ export interface SystemInfo {
11
+ os: OS;
12
+ shell: Shell;
13
+ }
14
+ export declare const Utils: {
15
+ getUser(): string;
16
+ getSystemInfo(): {
17
+ os: string;
18
+ shell: Shell | undefined;
19
+ };
20
+ isMacOS(): boolean;
21
+ isLinux(): boolean;
22
+ getShell(): Shell | undefined;
23
+ getPrimaryShellRc(): string;
24
+ getShellRcFiles(): string[];
25
+ };
@@ -0,0 +1,108 @@
1
+ import os from 'node:os';
2
+ import path from 'node:path';
3
+ export var Shell;
4
+ (function (Shell) {
5
+ Shell["ZSH"] = "zsh";
6
+ Shell["BASH"] = "bash";
7
+ Shell["SH"] = "sh";
8
+ Shell["KSH"] = "ksh";
9
+ Shell["CSH"] = "csh";
10
+ Shell["FISH"] = "fish";
11
+ })(Shell || (Shell = {}));
12
+ export const Utils = {
13
+ getUser() {
14
+ return os.userInfo().username;
15
+ },
16
+ getSystemInfo() {
17
+ return {
18
+ os: os.type(),
19
+ shell: this.getShell(),
20
+ };
21
+ },
22
+ isMacOS() {
23
+ return os.platform() === 'darwin';
24
+ },
25
+ isLinux() {
26
+ return os.platform() === 'linux';
27
+ },
28
+ getShell() {
29
+ const shell = process.env.SHELL || '';
30
+ if (shell.endsWith('bash')) {
31
+ return Shell.BASH;
32
+ }
33
+ if (shell.endsWith('zsh')) {
34
+ return Shell.ZSH;
35
+ }
36
+ if (shell.endsWith('sh')) {
37
+ return Shell.SH;
38
+ }
39
+ if (shell.endsWith('csh')) {
40
+ return Shell.CSH;
41
+ }
42
+ if (shell.endsWith('ksh')) {
43
+ return Shell.KSH;
44
+ }
45
+ if (shell.endsWith('fish')) {
46
+ return Shell.FISH;
47
+ }
48
+ return undefined;
49
+ },
50
+ getPrimaryShellRc() {
51
+ return this.getShellRcFiles()[0];
52
+ },
53
+ getShellRcFiles() {
54
+ const shell = process.env.SHELL || '';
55
+ const homeDir = os.homedir();
56
+ if (shell.endsWith('bash')) {
57
+ // Linux typically uses .bashrc, macOS uses .bash_profile
58
+ if (Utils.isLinux()) {
59
+ return [
60
+ path.join(homeDir, '.bashrc'),
61
+ path.join(homeDir, '.bash_profile'),
62
+ path.join(homeDir, '.profile'),
63
+ ];
64
+ }
65
+ return [
66
+ path.join(homeDir, '.bash_profile'),
67
+ path.join(homeDir, '.bashrc'),
68
+ path.join(homeDir, '.profile'),
69
+ ];
70
+ }
71
+ if (shell.endsWith('zsh')) {
72
+ return [
73
+ path.join(homeDir, '.zshrc'),
74
+ path.join(homeDir, '.zprofile'),
75
+ path.join(homeDir, '.zshenv'),
76
+ ];
77
+ }
78
+ if (shell.endsWith('sh')) {
79
+ return [
80
+ path.join(homeDir, '.profile'),
81
+ ];
82
+ }
83
+ if (shell.endsWith('ksh')) {
84
+ return [
85
+ path.join(homeDir, '.profile'),
86
+ path.join(homeDir, '.kshrc'),
87
+ ];
88
+ }
89
+ if (shell.endsWith('csh')) {
90
+ return [
91
+ path.join(homeDir, '.cshrc'),
92
+ path.join(homeDir, '.login'),
93
+ path.join(homeDir, '.logout'),
94
+ ];
95
+ }
96
+ if (shell.endsWith('fish')) {
97
+ return [
98
+ path.join(homeDir, '.config/fish/config.fish'),
99
+ ];
100
+ }
101
+ // Default to bash-style files
102
+ return [
103
+ path.join(homeDir, '.bashrc'),
104
+ path.join(homeDir, '.bash_profile'),
105
+ path.join(homeDir, '.profile'),
106
+ ];
107
+ },
108
+ };
@@ -0,0 +1,18 @@
1
+ import { ResourceConfig, StringIndexedObject } from 'codify-schemas';
2
+ export declare const VerbosityLevel: {
3
+ level: number;
4
+ get(): number;
5
+ set(level: number): void;
6
+ };
7
+ export declare function isDebug(): boolean;
8
+ export declare function splitUserConfig<T extends StringIndexedObject>(config: ResourceConfig & T): {
9
+ parameters: T;
10
+ coreParameters: ResourceConfig;
11
+ };
12
+ export declare function setsEqual(set1: Set<unknown>, set2: Set<unknown>): boolean;
13
+ export declare function untildify(pathWithTilde: string): string;
14
+ export declare function tildify(pathWithTilde: string): string;
15
+ export declare function resolvePathWithVariables(pathWithVariables: string): string;
16
+ export declare function addVariablesToPath(pathWithoutVariables: string): string;
17
+ export declare function unhome(pathWithHome: string): string;
18
+ export declare function areArraysEqual(isElementEqual: ((desired: unknown, current: unknown) => boolean) | undefined, desired: unknown, current: unknown): boolean;
@@ -0,0 +1,86 @@
1
+ import os from 'node:os';
2
+ import path from 'node:path';
3
+ export const VerbosityLevel = new class {
4
+ level = 0;
5
+ get() {
6
+ return this.level;
7
+ }
8
+ set(level) {
9
+ this.level = level;
10
+ }
11
+ };
12
+ export function isDebug() {
13
+ return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
14
+ }
15
+ export function splitUserConfig(config) {
16
+ const coreParameters = {
17
+ type: config.type,
18
+ ...(config.name ? { name: config.name } : {}),
19
+ ...(config.dependsOn ? { dependsOn: config.dependsOn } : {}),
20
+ };
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+ const { type, name, dependsOn, ...parameters } = config;
23
+ return {
24
+ parameters: parameters,
25
+ coreParameters,
26
+ };
27
+ }
28
+ export function setsEqual(set1, set2) {
29
+ return set1.size === set2.size && [...set1].every((v) => set2.has(v));
30
+ }
31
+ const homeDirectory = os.homedir();
32
+ export function untildify(pathWithTilde) {
33
+ return homeDirectory ? pathWithTilde.replace(/^~(?=$|\/|\\)/, homeDirectory) : pathWithTilde;
34
+ }
35
+ export function tildify(pathWithTilde) {
36
+ return homeDirectory ? pathWithTilde.replace(homeDirectory, '~') : pathWithTilde;
37
+ }
38
+ export function resolvePathWithVariables(pathWithVariables) {
39
+ // @ts-expect-error Ignore this for now
40
+ return pathWithVariables.replace(/\$([A-Z_]+[A-Z0-9_]*)|\${([A-Z0-9_]*)}/ig, (_, a, b) => process.env[a || b]);
41
+ }
42
+ export function addVariablesToPath(pathWithoutVariables) {
43
+ let result = pathWithoutVariables;
44
+ for (const [key, value] of Object.entries(process.env)) {
45
+ if (!value || !path.isAbsolute(value) || value === '/' || key === 'HOME' || key === 'PATH' || key === 'SHELL' || key === 'PWD') {
46
+ continue;
47
+ }
48
+ result = result.replaceAll(value, `$${key}`);
49
+ }
50
+ return result;
51
+ }
52
+ export function unhome(pathWithHome) {
53
+ return pathWithHome.includes('$HOME') ? pathWithHome.replaceAll('$HOME', os.homedir()) : pathWithHome;
54
+ }
55
+ export function areArraysEqual(isElementEqual, desired, current) {
56
+ if (!desired || !current) {
57
+ return false;
58
+ }
59
+ if (!Array.isArray(desired) || !Array.isArray(current)) {
60
+ throw new Error(`A non-array value:
61
+
62
+ Desired: ${JSON.stringify(desired, null, 2)}
63
+
64
+ Current: ${JSON.stringify(desired, null, 2)}
65
+
66
+ Was provided even though type array was specified.
67
+ `);
68
+ }
69
+ if (desired.length !== current.length) {
70
+ return false;
71
+ }
72
+ const desiredCopy = [...desired];
73
+ const currentCopy = [...current];
74
+ // Algorithm for to check equality between two un-ordered; un-hashable arrays using
75
+ // an isElementEqual method. Time: O(n^2)
76
+ for (let counter = desiredCopy.length - 1; counter >= 0; counter--) {
77
+ const idx = currentCopy.findIndex((e2) => (isElementEqual
78
+ ?? ((a, b) => a === b))(desiredCopy[counter], e2));
79
+ if (idx === -1) {
80
+ return false;
81
+ }
82
+ desiredCopy.splice(counter, 1);
83
+ currentCopy.splice(idx, 1);
84
+ }
85
+ return currentCopy.length === 0;
86
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.181",
3
+ "version": "1.0.182-beta1",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "ajv": "^8.12.0",
23
23
  "ajv-formats": "^2.1.1",
24
24
  "clean-deep": "^3.4.0",
25
- "codify-schemas": "1.0.83",
25
+ "codify-schemas": "1.0.86",
26
26
  "lodash.isequal": "^4.5.0",
27
27
  "nanoid": "^5.0.9",
28
28
  "strip-ansi": "^7.1.0",
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@ export * from './resource/parsed-resource-settings.js';
12
12
  export * from './resource/resource.js'
13
13
  export * from './resource/resource-settings.js'
14
14
  export * from './stateful-parameter/stateful-parameter.js'
15
- export * from './utils/utils.js'
15
+ export * from './utils/index.js'
16
16
 
17
17
  export async function runPlugin(plugin: Plugin) {
18
18
  const messageHandler = new MessageHandler(plugin);
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import { Plan } from './plan.js';
3
- import { ParameterOperation, ResourceOperation } from 'codify-schemas';
3
+ import { OS, ParameterOperation, ResourceOperation } from 'codify-schemas';
4
4
  import { TestConfig, TestResource } from '../utils/test-utils.test.js';
5
5
  import { ResourceController } from '../resource/resource-controller.js';
6
6
  import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js';
@@ -152,6 +152,7 @@ describe('Plan entity tests', () => {
152
152
  getSettings(): ResourceSettings<any> {
153
153
  return {
154
154
  id: 'type',
155
+ operatingSystems: [OS.Darwin],
155
156
  parameterSettings: {
156
157
  propZ: { type: 'array', isElementEqual: (a, b) => b.includes(a) }
157
158
  }
@@ -184,6 +185,7 @@ describe('Plan entity tests', () => {
184
185
  getSettings(): ResourceSettings<any> {
185
186
  return {
186
187
  id: 'type',
188
+ operatingSystems: [OS.Darwin],
187
189
  parameterSettings: {
188
190
  propZ: {
189
191
  type: 'array',
@@ -236,6 +238,7 @@ describe('Plan entity tests', () => {
236
238
  getSettings(): ResourceSettings<TestConfig> {
237
239
  return {
238
240
  id: 'type',
241
+ operatingSystems: [OS.Darwin],
239
242
  parameterSettings: {
240
243
  propA: { type: 'string' },
241
244
  propB: { type: 'string', canModify: true },
@@ -289,6 +292,7 @@ describe('Plan entity tests', () => {
289
292
  getSettings(): ResourceSettings<TestConfig> {
290
293
  return {
291
294
  id: 'type',
295
+ operatingSystems: [OS.Darwin],
292
296
  parameterSettings: {
293
297
  propA: { type: 'string' },
294
298
  propB: { type: 'string', canModify: true },
@@ -351,6 +355,7 @@ function createTestResource() {
351
355
  getSettings(): ResourceSettings<TestConfig> {
352
356
  return {
353
357
  id: 'type',
358
+ operatingSystems: [OS.Darwin],
354
359
  parameterSettings: {
355
360
  propA: {
356
361
  default: 'defaultA'