@codifycli/plugin-core 1.0.0-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 (152) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.json +30 -0
  3. package/.github/workflows/release.yaml +19 -0
  4. package/.github/workflows/unit-test-ci.yaml +18 -0
  5. package/.prettierrc.json +1 -0
  6. package/bin/build.js +189 -0
  7. package/dist/bin/build.d.ts +1 -0
  8. package/dist/bin/build.js +80 -0
  9. package/dist/bin/deploy-plugin.d.ts +2 -0
  10. package/dist/bin/deploy-plugin.js +8 -0
  11. package/dist/common/errors.d.ts +8 -0
  12. package/dist/common/errors.js +24 -0
  13. package/dist/entities/change-set.d.ts +24 -0
  14. package/dist/entities/change-set.js +152 -0
  15. package/dist/entities/errors.d.ts +4 -0
  16. package/dist/entities/errors.js +7 -0
  17. package/dist/entities/plan-types.d.ts +25 -0
  18. package/dist/entities/plan-types.js +1 -0
  19. package/dist/entities/plan.d.ts +15 -0
  20. package/dist/entities/plan.js +127 -0
  21. package/dist/entities/plugin.d.ts +16 -0
  22. package/dist/entities/plugin.js +80 -0
  23. package/dist/entities/resource-options.d.ts +31 -0
  24. package/dist/entities/resource-options.js +76 -0
  25. package/dist/entities/resource-types.d.ts +11 -0
  26. package/dist/entities/resource-types.js +1 -0
  27. package/dist/entities/resource.d.ts +42 -0
  28. package/dist/entities/resource.js +303 -0
  29. package/dist/entities/stateful-parameter.d.ts +29 -0
  30. package/dist/entities/stateful-parameter.js +46 -0
  31. package/dist/entities/transform-parameter.d.ts +4 -0
  32. package/dist/entities/transform-parameter.js +2 -0
  33. package/dist/errors.d.ts +4 -0
  34. package/dist/errors.js +7 -0
  35. package/dist/index.d.ts +20 -0
  36. package/dist/index.js +26 -0
  37. package/dist/messages/handlers.d.ts +14 -0
  38. package/dist/messages/handlers.js +134 -0
  39. package/dist/messages/sender.d.ts +11 -0
  40. package/dist/messages/sender.js +57 -0
  41. package/dist/plan/change-set.d.ts +53 -0
  42. package/dist/plan/change-set.js +153 -0
  43. package/dist/plan/plan-types.d.ts +23 -0
  44. package/dist/plan/plan-types.js +1 -0
  45. package/dist/plan/plan.d.ts +66 -0
  46. package/dist/plan/plan.js +328 -0
  47. package/dist/plugin/plugin.d.ts +24 -0
  48. package/dist/plugin/plugin.js +200 -0
  49. package/dist/pty/background-pty.d.ts +21 -0
  50. package/dist/pty/background-pty.js +127 -0
  51. package/dist/pty/index.d.ts +50 -0
  52. package/dist/pty/index.js +20 -0
  53. package/dist/pty/promise-queue.d.ts +5 -0
  54. package/dist/pty/promise-queue.js +26 -0
  55. package/dist/pty/seqeuntial-pty.d.ts +17 -0
  56. package/dist/pty/seqeuntial-pty.js +119 -0
  57. package/dist/pty/vitest.config.d.ts +2 -0
  58. package/dist/pty/vitest.config.js +11 -0
  59. package/dist/resource/config-parser.d.ts +11 -0
  60. package/dist/resource/config-parser.js +21 -0
  61. package/dist/resource/parsed-resource-settings.d.ts +47 -0
  62. package/dist/resource/parsed-resource-settings.js +196 -0
  63. package/dist/resource/resource-controller.d.ts +36 -0
  64. package/dist/resource/resource-controller.js +402 -0
  65. package/dist/resource/resource-settings.d.ts +303 -0
  66. package/dist/resource/resource-settings.js +147 -0
  67. package/dist/resource/resource.d.ts +144 -0
  68. package/dist/resource/resource.js +44 -0
  69. package/dist/resource/stateful-parameter.d.ts +165 -0
  70. package/dist/resource/stateful-parameter.js +94 -0
  71. package/dist/scripts/deploy.d.ts +1 -0
  72. package/dist/scripts/deploy.js +2 -0
  73. package/dist/stateful-parameter/stateful-parameter-controller.d.ts +21 -0
  74. package/dist/stateful-parameter/stateful-parameter-controller.js +81 -0
  75. package/dist/stateful-parameter/stateful-parameter.d.ts +144 -0
  76. package/dist/stateful-parameter/stateful-parameter.js +43 -0
  77. package/dist/test.d.ts +1 -0
  78. package/dist/test.js +5 -0
  79. package/dist/utils/codify-spawn.d.ts +29 -0
  80. package/dist/utils/codify-spawn.js +136 -0
  81. package/dist/utils/debug.d.ts +2 -0
  82. package/dist/utils/debug.js +10 -0
  83. package/dist/utils/file-utils.d.ts +23 -0
  84. package/dist/utils/file-utils.js +186 -0
  85. package/dist/utils/functions.d.ts +12 -0
  86. package/dist/utils/functions.js +74 -0
  87. package/dist/utils/index.d.ts +46 -0
  88. package/dist/utils/index.js +271 -0
  89. package/dist/utils/internal-utils.d.ts +12 -0
  90. package/dist/utils/internal-utils.js +74 -0
  91. package/dist/utils/load-resources.d.ts +1 -0
  92. package/dist/utils/load-resources.js +46 -0
  93. package/dist/utils/package-json-utils.d.ts +12 -0
  94. package/dist/utils/package-json-utils.js +34 -0
  95. package/dist/utils/pty-local-storage.d.ts +2 -0
  96. package/dist/utils/pty-local-storage.js +2 -0
  97. package/dist/utils/spawn-2.d.ts +5 -0
  98. package/dist/utils/spawn-2.js +7 -0
  99. package/dist/utils/spawn.d.ts +29 -0
  100. package/dist/utils/spawn.js +124 -0
  101. package/dist/utils/utils.d.ts +18 -0
  102. package/dist/utils/utils.js +86 -0
  103. package/dist/utils/verbosity-level.d.ts +5 -0
  104. package/dist/utils/verbosity-level.js +9 -0
  105. package/package.json +59 -0
  106. package/rollup.config.js +24 -0
  107. package/src/common/errors.test.ts +43 -0
  108. package/src/common/errors.ts +31 -0
  109. package/src/errors.ts +8 -0
  110. package/src/index.test.ts +6 -0
  111. package/src/index.ts +30 -0
  112. package/src/messages/handlers.test.ts +329 -0
  113. package/src/messages/handlers.ts +181 -0
  114. package/src/messages/sender.ts +69 -0
  115. package/src/plan/change-set.test.ts +280 -0
  116. package/src/plan/change-set.ts +236 -0
  117. package/src/plan/plan-types.ts +27 -0
  118. package/src/plan/plan.test.ts +413 -0
  119. package/src/plan/plan.ts +499 -0
  120. package/src/plugin/plugin.test.ts +533 -0
  121. package/src/plugin/plugin.ts +291 -0
  122. package/src/pty/background-pty.test.ts +69 -0
  123. package/src/pty/background-pty.ts +154 -0
  124. package/src/pty/index.test.ts +129 -0
  125. package/src/pty/index.ts +66 -0
  126. package/src/pty/promise-queue.ts +33 -0
  127. package/src/pty/seqeuntial-pty.ts +151 -0
  128. package/src/pty/sequential-pty.test.ts +194 -0
  129. package/src/resource/config-parser.ts +42 -0
  130. package/src/resource/parsed-resource-settings.test.ts +186 -0
  131. package/src/resource/parsed-resource-settings.ts +307 -0
  132. package/src/resource/resource-controller-stateful-mode.test.ts +253 -0
  133. package/src/resource/resource-controller.test.ts +1081 -0
  134. package/src/resource/resource-controller.ts +563 -0
  135. package/src/resource/resource-settings.test.ts +1213 -0
  136. package/src/resource/resource-settings.ts +545 -0
  137. package/src/resource/resource.ts +157 -0
  138. package/src/stateful-parameter/stateful-parameter-controller.test.ts +244 -0
  139. package/src/stateful-parameter/stateful-parameter-controller.ts +111 -0
  140. package/src/stateful-parameter/stateful-parameter.ts +160 -0
  141. package/src/utils/debug.ts +11 -0
  142. package/src/utils/file-utils.test.ts +7 -0
  143. package/src/utils/file-utils.ts +231 -0
  144. package/src/utils/functions.ts +103 -0
  145. package/src/utils/index.ts +340 -0
  146. package/src/utils/internal-utils.test.ts +52 -0
  147. package/src/utils/pty-local-storage.ts +3 -0
  148. package/src/utils/test-utils.test.ts +96 -0
  149. package/src/utils/verbosity-level.ts +11 -0
  150. package/tsconfig.json +26 -0
  151. package/tsconfig.test.json +9 -0
  152. package/vitest.config.ts +10 -0
@@ -0,0 +1,52 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { addVariablesToPath, resolvePathWithVariables, splitUserConfig } from './functions.js';
3
+ import os from 'node:os';
4
+
5
+ describe('Utils tests', () => {
6
+ it('Can split a config correctly', () => {
7
+ const { parameters, coreParameters } = splitUserConfig({
8
+ type: 'type',
9
+ name: 'name',
10
+ dependsOn: ['a', 'b', 'c'],
11
+ os: ['linux'],
12
+ propA: 'propA',
13
+ propB: 'propB',
14
+ propC: 'propC',
15
+ propD: 'propD',
16
+ })
17
+
18
+ expect(coreParameters).toMatchObject({
19
+ type: 'type',
20
+ name: 'name',
21
+ dependsOn: ['a', 'b', 'c'],
22
+ })
23
+
24
+ expect(parameters).toMatchObject({
25
+ propA: 'propA',
26
+ propB: 'propB',
27
+ propC: 'propC',
28
+ propD: 'propD',
29
+ })
30
+ })
31
+
32
+ it('Can remove variables from a path', () => {
33
+ const testPath1 = '$HOME/my/path';
34
+ const result1 = resolvePathWithVariables(testPath1);
35
+
36
+ const home = os.homedir();
37
+ expect(result1).to.eq(home + '/my/path');
38
+
39
+
40
+ const testPath2 = '/var$HOME/my/path';
41
+ const result2 = resolvePathWithVariables(testPath2);
42
+ expect(result2).to.eq('/var' + home + '/my/path');
43
+ })
44
+
45
+ it('Can add variables to a path (ignores home)', () => {
46
+ const testPath1 = os.homedir() + '/my/path';
47
+ const result1 = addVariablesToPath(testPath1);
48
+
49
+ const home = os.homedir();
50
+ expect(result1).to.eq(home + '/my/path');
51
+ })
52
+ })
@@ -0,0 +1,3 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+
3
+ export const ptyLocalStorage = new AsyncLocalStorage();
@@ -0,0 +1,96 @@
1
+ import { OS, ResourceConfig, StringIndexedObject } from 'codify-schemas';
2
+ import { ResourceSettings } from '../resource/resource-settings.js';
3
+ import { Plan } from '../plan/plan.js';
4
+ import { Resource } from '../resource/resource.js';
5
+ import { CreatePlan, DestroyPlan } from '../plan/plan-types.js';
6
+ import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
7
+ import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js';
8
+ import { describe, it } from 'vitest';
9
+
10
+ export function testPlan<T extends StringIndexedObject>(params: {
11
+ desired?: Partial<T> | null;
12
+ current?: Partial<T>[] | null;
13
+ state?: Partial<T> | null;
14
+ core?: ResourceConfig;
15
+ settings?: ResourceSettings<T>;
16
+ isStateful?: boolean;
17
+ }) {
18
+ return Plan.calculate({
19
+ desired: params.desired ?? null,
20
+ currentArray: params.current ?? null,
21
+ state: params.state ?? null,
22
+ core: params.core ?? { type: 'type' },
23
+ settings: params.settings ?
24
+ new ParsedResourceSettings<T>(params.settings)
25
+ : new ParsedResourceSettings<T>({ id: 'type' }),
26
+ isStateful: params.isStateful ?? false,
27
+ })
28
+ }
29
+
30
+ export interface TestConfig extends StringIndexedObject {
31
+ propA: string;
32
+ propB: number;
33
+ propC?: string;
34
+ }
35
+
36
+ export class TestResource extends Resource<TestConfig> {
37
+ getSettings(): ResourceSettings<TestConfig> {
38
+ return {
39
+ id: 'type',
40
+ operatingSystems: [OS.Darwin]
41
+ }
42
+ }
43
+
44
+ create(plan: CreatePlan<TestConfig>): Promise<void> {
45
+ return Promise.resolve(undefined);
46
+ }
47
+
48
+ destroy(plan: DestroyPlan<TestConfig>): Promise<void> {
49
+ return Promise.resolve(undefined);
50
+ }
51
+
52
+ async refresh(parameters: Partial<TestConfig>): Promise<Partial<TestConfig> | null> {
53
+ return {
54
+ propA: 'a',
55
+ propB: 10,
56
+ propC: 'c',
57
+ };
58
+ }
59
+ }
60
+
61
+ export class TestStatefulParameter extends StatefulParameter<TestConfig, string> {
62
+ async refresh(desired: string | null): Promise<string | null> {
63
+ return 'd';
64
+ }
65
+
66
+ async add(valueToAdd: string, plan: Plan<TestConfig>): Promise<void> {
67
+ return;
68
+ }
69
+
70
+ async modify(newValue: string, previousValue: string, plan: Plan<TestConfig>): Promise<void> {
71
+ return;
72
+ }
73
+
74
+ async remove(valueToRemove: string, plan: Plan<TestConfig>): Promise<void> {
75
+ return;
76
+ }
77
+ }
78
+
79
+ export class TestArrayStatefulParameter extends ArrayStatefulParameter<TestConfig, string> {
80
+ async refresh(): Promise<any | null> {
81
+ return ['3.11.9']
82
+ }
83
+
84
+ addItem(item: string, plan: Plan<TestConfig>): Promise<void> {
85
+ return Promise.resolve(undefined);
86
+ }
87
+
88
+ removeItem(item: string, plan: Plan<TestConfig>): Promise<void> {
89
+ return Promise.resolve(undefined);
90
+ }
91
+ }
92
+
93
+ describe('Empty tests', () => {
94
+ it('empty', () => {
95
+ })
96
+ })
@@ -0,0 +1,11 @@
1
+ export const VerbosityLevel = new class {
2
+ level = 0;
3
+
4
+ get() {
5
+ return this.level;
6
+ }
7
+
8
+ set(level: number) {
9
+ this.level = level;
10
+ }
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "module": "Node16",
5
+ "moduleResolution": "Node16",
6
+ "alwaysStrict": true,
7
+ "noImplicitAny": true,
8
+ "resolveJsonModule": true,
9
+ "esModuleInterop": true,
10
+ "strictNullChecks": true,
11
+ "emitDecoratorMetadata": true,
12
+ "experimentalDecorators": true,
13
+ "outDir": "dist",
14
+ "rootDir": "src",
15
+ "strict": true,
16
+ "target": "es2022"
17
+ },
18
+ "include": [
19
+ "src/**/*.ts"
20
+ ],
21
+ "exclude": [
22
+ "node_modules",
23
+ "src/**/*.test.ts",
24
+ "**/vitest.config.ts"
25
+ ]
26
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "tsconfig.json",
3
+ "compilerOptions": {
4
+ "strictNullChecks": false
5
+ },
6
+ "include": [
7
+ "src/**/*.test.ts"
8
+ ],
9
+ }
@@ -0,0 +1,10 @@
1
+ import { defaultExclude, defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ pool: 'forks',
6
+ exclude: [
7
+ ...defaultExclude
8
+ ]
9
+ },
10
+ });