@quadnix/octo-build 0.0.8 → 0.0.9

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 (135) hide show
  1. package/dist/commands/create-anchor/create-anchor.command.d.ts +13 -0
  2. package/dist/commands/create-anchor/create-anchor.command.js +67 -0
  3. package/dist/commands/create-anchor/create-anchor.command.js.map +1 -0
  4. package/dist/commands/create-anchor/generator-octo-anchor-template/generators/app/index.d.ts +13 -0
  5. package/dist/commands/create-anchor/generator-octo-anchor-template/generators/app/index.js +59 -0
  6. package/dist/commands/create-anchor/generator-octo-anchor-template/generators/app/index.js.map +1 -0
  7. package/dist/commands/create-anchor/generator-octo-anchor-template/generators/app/templates/anchors/anchor/anchor.schema.ts.ejs +23 -0
  8. package/dist/commands/create-anchor/generator-octo-anchor-template/generators/app/templates/anchors/anchor/anchor.ts.ejs +15 -0
  9. package/dist/commands/create-anchor/index.d.ts +1 -0
  10. package/dist/commands/create-anchor/index.js +2 -0
  11. package/dist/commands/create-anchor/index.js.map +1 -0
  12. package/dist/commands/{create/create.command.d.ts → create-app/create-app.command.d.ts} +1 -1
  13. package/dist/commands/{create/create.command.js → create-app/create-app.command.js} +3 -3
  14. package/dist/commands/create-app/create-app.command.js.map +1 -0
  15. package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/index.d.ts +0 -1
  16. package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/index.js +18 -29
  17. package/dist/commands/create-app/generator-octo-app-template/generators/app/index.js.map +1 -0
  18. package/dist/commands/create-app/generator-octo-app-template/generators/app/templates/README.md.ejs +58 -0
  19. package/dist/commands/create-app/generator-octo-app-template/generators/app/templates/eslint.config.js.ejs +118 -0
  20. package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/package.json.ejs +1 -4
  21. package/dist/commands/{create/generator-octo-app-template/generators/app/templates/src/aws-s3-website → create-app/generator-octo-app-template/generators/app/templates/src/aws-ecs-server}/main.ts.ejs +3 -3
  22. package/dist/commands/{create/generator-octo-app-template/generators/app/templates/src/aws-ecs-server → create-app/generator-octo-app-template/generators/app/templates/src/aws-s3-website}/main.ts.ejs +3 -3
  23. package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/src/aws-s3-website/module-definitions.ts.ejs +1 -1
  24. package/dist/commands/create-app/index.d.ts +1 -0
  25. package/dist/commands/create-app/index.js +2 -0
  26. package/dist/commands/create-app/index.js.map +1 -0
  27. package/dist/commands/create-cdk/create-cdk.command.d.ts +11 -0
  28. package/dist/commands/create-cdk/create-cdk.command.js +70 -0
  29. package/dist/commands/create-cdk/create-cdk.command.js.map +1 -0
  30. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/index.d.ts +10 -0
  31. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/index.js +107 -0
  32. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/index.js.map +1 -0
  33. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/README.md.ejs +23 -0
  34. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/eslint.config.js.ejs +337 -0
  35. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/gitignore.ejs +82 -0
  36. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/package.json.ejs +57 -0
  37. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/prettierrc.ejs +5 -0
  38. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/anchors/app/app.anchor.schema.ts.ejs +19 -0
  39. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/anchors/app/app.anchor.ts.ejs +17 -0
  40. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/factories/dummy-credentials.factory.ts.ejs +28 -0
  41. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/modules/app/dummy-app/dummy-app.module.spec.ts.ejs +90 -0
  42. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/modules/app/dummy-app/dummy-app.module.ts.ejs +16 -0
  43. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/modules/app/dummy-app/index.schema.ts.ejs +10 -0
  44. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/modules/app/dummy-app/index.ts.ejs +3 -0
  45. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/modules/app/dummy-app/models/app/actions/add-dummy-app.model.action.ts.ejs +59 -0
  46. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/modules/app/dummy-app/models/app/index.ts.ejs +1 -0
  47. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/resources/http-fetch/actions/add-http-fetch.resource.action.ts.ejs +55 -0
  48. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/resources/http-fetch/http-fetch.resource.ts.ejs +12 -0
  49. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/resources/http-fetch/index.schema.ts.ejs +35 -0
  50. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/resources/http-fetch/index.ts.ejs +3 -0
  51. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/src/utilities/dummy/dummy.utility.ts.ejs +11 -0
  52. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/tsconfig.build.json.ejs +11 -0
  53. package/dist/commands/create-cdk/generator-octo-cdk-template/generators/app/templates/tsconfig.json.ejs +39 -0
  54. package/dist/commands/create-cdk/index.d.ts +1 -0
  55. package/dist/commands/create-cdk/index.js +2 -0
  56. package/dist/commands/create-cdk/index.js.map +1 -0
  57. package/dist/commands/create-model/create-model.command.d.ts +12 -0
  58. package/dist/commands/create-model/create-model.command.js +62 -0
  59. package/dist/commands/create-model/create-model.command.js.map +1 -0
  60. package/dist/commands/create-model/generator-octo-model-template/generators/app/index.d.ts +11 -0
  61. package/dist/commands/create-model/generator-octo-model-template/generators/app/index.js +68 -0
  62. package/dist/commands/create-model/generator-octo-model-template/generators/app/index.js.map +1 -0
  63. package/dist/commands/create-model/generator-octo-model-template/generators/app/templates/models/model/actions/add.model.action.ts.ejs +50 -0
  64. package/dist/commands/create-model/generator-octo-model-template/generators/app/templates/models/model/index.ts.ejs +3 -0
  65. package/dist/commands/create-model/generator-octo-model-template/generators/app/templates/models/model/model.ts.ejs +29 -0
  66. package/dist/commands/create-model/generator-octo-model-template/generators/app/templates/models/model/schema.ts.ejs +8 -0
  67. package/dist/commands/create-model/index.d.ts +1 -0
  68. package/dist/commands/create-model/index.js +2 -0
  69. package/dist/commands/create-model/index.js.map +1 -0
  70. package/dist/commands/create-module/create-module.command.d.ts +12 -0
  71. package/dist/commands/create-module/create-module.command.js +62 -0
  72. package/dist/commands/create-module/create-module.command.js.map +1 -0
  73. package/dist/commands/create-module/generator-octo-module-template/generators/app/index.d.ts +11 -0
  74. package/dist/commands/create-module/generator-octo-module-template/generators/app/index.js +60 -0
  75. package/dist/commands/create-module/generator-octo-module-template/generators/app/index.js.map +1 -0
  76. package/dist/commands/create-module/generator-octo-module-template/generators/app/templates/index.schema.ts.ejs +3 -0
  77. package/dist/commands/create-module/generator-octo-module-template/generators/app/templates/index.ts.ejs +1 -0
  78. package/dist/commands/create-module/generator-octo-module-template/generators/app/templates/module.ts.ejs +9 -0
  79. package/dist/commands/create-module/index.d.ts +1 -0
  80. package/dist/commands/create-module/index.js +2 -0
  81. package/dist/commands/create-module/index.js.map +1 -0
  82. package/dist/commands/create-overlay/create-overlay.command.d.ts +13 -0
  83. package/dist/commands/create-overlay/create-overlay.command.js +67 -0
  84. package/dist/commands/create-overlay/create-overlay.command.js.map +1 -0
  85. package/dist/commands/create-overlay/generator-octo-overlay-template/generators/app/index.d.ts +12 -0
  86. package/dist/commands/create-overlay/generator-octo-overlay-template/generators/app/index.js +72 -0
  87. package/dist/commands/create-overlay/generator-octo-overlay-template/generators/app/index.js.map +1 -0
  88. package/dist/commands/create-overlay/generator-octo-overlay-template/generators/app/templates/overlays/overlay/actions/add.overlay.action.ts.ejs +50 -0
  89. package/dist/commands/create-overlay/generator-octo-overlay-template/generators/app/templates/overlays/overlay/index.ts.ejs +3 -0
  90. package/dist/commands/create-overlay/generator-octo-overlay-template/generators/app/templates/overlays/overlay/overlay.schema.ts.ejs +13 -0
  91. package/dist/commands/create-overlay/generator-octo-overlay-template/generators/app/templates/overlays/overlay/overlay.ts.ejs +22 -0
  92. package/dist/commands/create-overlay/index.d.ts +1 -0
  93. package/dist/commands/create-overlay/index.js +2 -0
  94. package/dist/commands/create-overlay/index.js.map +1 -0
  95. package/dist/commands/create-resource/create-resource.command.d.ts +11 -0
  96. package/dist/commands/create-resource/create-resource.command.js +55 -0
  97. package/dist/commands/create-resource/create-resource.command.js.map +1 -0
  98. package/dist/commands/create-resource/generator-octo-resource-template/generators/app/index.d.ts +10 -0
  99. package/dist/commands/create-resource/generator-octo-resource-template/generators/app/index.js +71 -0
  100. package/dist/commands/create-resource/generator-octo-resource-template/generators/app/index.js.map +1 -0
  101. package/dist/commands/create-resource/generator-octo-resource-template/generators/app/templates/resources/resource/actions/add.resource.action.ts.ejs +65 -0
  102. package/dist/commands/create-resource/generator-octo-resource-template/generators/app/templates/resources/resource/actions/delete.resource.action.ts.ejs +58 -0
  103. package/dist/commands/create-resource/generator-octo-resource-template/generators/app/templates/resources/resource/actions/update-tags.resource.action.ts.ejs +95 -0
  104. package/dist/commands/create-resource/generator-octo-resource-template/generators/app/templates/resources/resource/index.schema.ts.ejs +31 -0
  105. package/dist/commands/create-resource/generator-octo-resource-template/generators/app/templates/resources/resource/index.ts.ejs +5 -0
  106. package/dist/commands/create-resource/generator-octo-resource-template/generators/app/templates/resources/resource/resource.ts.ejs +12 -0
  107. package/dist/commands/create-resource/index.d.ts +1 -0
  108. package/dist/commands/create-resource/index.js +2 -0
  109. package/dist/commands/create-resource/index.js.map +1 -0
  110. package/dist/index.js +14 -2
  111. package/dist/index.js.map +1 -1
  112. package/dist/utilities/string/string.utility.d.ts +5 -0
  113. package/dist/utilities/string/string.utility.js +26 -0
  114. package/dist/utilities/string/string.utility.js.map +1 -0
  115. package/package.json +2 -2
  116. package/dist/commands/create/create.command.js.map +0 -1
  117. package/dist/commands/create/generator-octo-app-template/generators/app/index.js.map +0 -1
  118. package/dist/commands/create/generator-octo-app-template/generators/app/templates/README.md.ejs +0 -84
  119. package/dist/commands/create/generator-octo-app-template/generators/app/templates/eslint.config.js.ejs +0 -130
  120. package/dist/commands/create/index.d.ts +0 -1
  121. package/dist/commands/create/index.js +0 -2
  122. package/dist/commands/create/index.js.map +0 -1
  123. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/gitignore.ejs +0 -0
  124. /package/dist/commands/{create/generator-octo-app-template/generators/app/templates/src/aws-ecs-server/octo → create-app/generator-octo-app-template/generators/app/templates}/gitkeep.ejs +0 -0
  125. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/prettierrc.ejs +0 -0
  126. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/src/aws-ecs-server/app.config.ts.ejs +0 -0
  127. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/src/aws-ecs-server/env.ejs +0 -0
  128. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/src/aws-ecs-server/module-definitions.ts.ejs +0 -0
  129. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/src/aws-s3-website/app.config.ts.ejs +0 -0
  130. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/src/aws-s3-website/env.ejs +0 -0
  131. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/src/aws-s3-website/website/error.html.ejs +0 -0
  132. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/src/aws-s3-website/website/index.html.ejs +0 -0
  133. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/tsconfig.build.json.ejs +0 -0
  134. /package/dist/commands/{create → create-app}/generator-octo-app-template/generators/app/templates/tsconfig.json.ejs +0 -0
  135. /package/dist/commands/{create/generator-octo-app-template/generators/app/templates/src/aws-s3-website/octo → create-cdk/generator-octo-cdk-template/generators/app/templates}/gitkeep.ejs +0 -0
@@ -0,0 +1,57 @@
1
+ {
2
+ "dependencies": {},
3
+ "description": "<%= description %>",
4
+ "devDependencies": {},
5
+ "engines": {
6
+ "node": ">=20.0.0"
7
+ },
8
+ "jest": {
9
+ "coverageDirectory": "./coverage",
10
+ "extensionsToTreatAsEsm": [
11
+ ".ts"
12
+ ],
13
+ "moduleFileExtensions": [
14
+ "js",
15
+ "json",
16
+ "ts"
17
+ ],
18
+ "moduleNameMapper": {
19
+ "(.+)\\.js": "$1"
20
+ },
21
+ "preset": "ts-jest/presets/default-esm",
22
+ "rootDir": ".",
23
+ "testEnvironment": "node",
24
+ "testRegex": ".*spec\\.ts$",
25
+ "transform": {
26
+ "^.+\\.ts$": [
27
+ "ts-jest",
28
+ {
29
+ "useESM": true
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ "keywords": [
35
+ "cdk",
36
+ "cicd",
37
+ "infrastructure",
38
+ "octo"
39
+ ],
40
+ "main": "./dist/index.js",
41
+ "name": "<%= name %>",
42
+ "private": true,
43
+ "scripts": {
44
+ "build": "rimraf dist && tsc -p tsconfig.build.json",
45
+ "check:circular-dependency": "dpdm --no-tree --exit-code circular:1 --no-warning ./dist/**/*.js",
46
+ "format": "prettier --write \"src/**/*.ts\"",
47
+ "lint": "eslint .",
48
+ "lint:fix": "eslint . --fix",
49
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --testRegex=\"\\.spec.ts$\"",
50
+ "test:cov": "NODE_OPTIONS=--experimental-vm-modules jest --coverage --testRegex=\"\\.spec.ts$\"",
51
+ "test:e2e": "NODE_OPTIONS=--experimental-vm-modules jest --testRegex=\"\\.e2e-spec.ts$\"",
52
+ "test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --testRegex=\"\\.ispec.ts$\""
53
+ },
54
+ "type": "module",
55
+ "types": "./dist/index.d.ts",
56
+ "version": "<%= version %>"
57
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "printWidth": 120,
3
+ "singleQuote": true,
4
+ "trailingComma": "all"
5
+ }
@@ -0,0 +1,19 @@
1
+ import { App, BaseAnchorSchema, Schema, Validate } from '@quadnix/octo';
2
+
3
+ /**
4
+ * This is an example anchor schema to demonstrate how to create a custom anchor schema.
5
+ * This anchor is for the `App` model, and exposes a `name` property.
6
+ * Validation for the property is also included using the `@Validate` decorator.
7
+ * In this case, the `name` property is required and must be at least 1 character long.
8
+ */
9
+ export class AppAnchorSchema extends BaseAnchorSchema {
10
+ parentInstance: App;
11
+
12
+ @Validate({
13
+ destruct: (value: AppAnchorSchema['properties']): string[] => [value.name],
14
+ options: { minLength: 1 },
15
+ })
16
+ override properties = Schema<{
17
+ name: string;
18
+ }>();
19
+ }
@@ -0,0 +1,17 @@
1
+ import { AAnchor, Anchor } from '@quadnix/octo';
2
+ import type { AppAnchorSchema } from './app.anchor.schema.js';
3
+
4
+ /**
5
+ * This is an example anchor to demonstrate how to create a custom anchor.
6
+ * It uses the `@Anchor` decorator to create an anchor for the `App` model,
7
+ * and it must extend the `AAnchor` class.
8
+ * The `AppAnchorSchema` type is used to define the properties of the anchor.
9
+ */
10
+ @Anchor('@<%= name %>')
11
+ export class AppAnchor extends AAnchor<AppAnchorSchema, AppAnchorSchema['parentInstance']> {
12
+ declare properties: AppAnchorSchema['properties'];
13
+
14
+ constructor(anchorId: string, properties: AppAnchorSchema['properties'], parent: AppAnchorSchema['parentInstance']) {
15
+ super(anchorId, properties, parent);
16
+ }
17
+ }
@@ -0,0 +1,28 @@
1
+ import { Factory } from '@quadnix/octo';
2
+
3
+ /**
4
+ * This is a dummy credentials class to demonstrate how to create a custom factory and use it across your CDK.
5
+ */
6
+ export class DummyCredentials {
7
+ readonly username = 'dummy';
8
+ readonly password = 'dummy';
9
+ }
10
+
11
+ /**
12
+ * This is a factory exposing a singleton instance of the `DummyCredentials` class.
13
+ * It uses the `@Factory` decorator to register with the Octo container.
14
+ * It defines some unique metadata which uniquely identifies the factory category.
15
+ * Calling the factory using the container will always execute the `create` method,
16
+ * and return an instance of the `DummyCredentials` class.
17
+ */
18
+ @Factory<DummyCredentials>(DummyCredentials, { metadata: { package: '@<%= name %>' } })
19
+ export class DummyCredentialsFactory {
20
+ private static instance: DummyCredentials;
21
+
22
+ static async create(): Promise<DummyCredentials> {
23
+ if (!this.instance) {
24
+ this.instance = new DummyCredentials();
25
+ }
26
+ return this.instance;
27
+ }
28
+ }
@@ -0,0 +1,90 @@
1
+ import { TestContainer, TestModuleContainer, TestStateProvider } from '@quadnix/octo';
2
+ import { DummyAppModule } from './index.js';
3
+
4
+ describe('DummyAppModule UT', () => {
5
+ let testModuleContainer: TestModuleContainer;
6
+
7
+ beforeEach(async () => {
8
+ await TestContainer.create(
9
+ {
10
+ mocks: [],
11
+ },
12
+ { factoryTimeoutInMs: 500 },
13
+ );
14
+
15
+ testModuleContainer = new TestModuleContainer();
16
+ await testModuleContainer.initialize(new TestStateProvider());
17
+ });
18
+
19
+ afterEach(async () => {
20
+ await testModuleContainer.reset();
21
+ await TestContainer.reset();
22
+ });
23
+
24
+ it('should call correct actions', async () => {
25
+ const { 'app-module.model.app': app } = await testModuleContainer.runModule<DummyAppModule>({
26
+ inputs: { name: '<%= name %>' },
27
+ moduleId: 'app-module',
28
+ type: DummyAppModule,
29
+ });
30
+
31
+ const result = await testModuleContainer.commit(app, {
32
+ enableResourceCapture: false,
33
+ filterByModuleIds: ['app-module'],
34
+ });
35
+
36
+ // Correct actions are called.
37
+ expect(testModuleContainer.mapTransactionActions(result.modelTransaction)).toMatchInlineSnapshot(`
38
+ [
39
+ [
40
+ "AddDummyAppModelAction",
41
+ ],
42
+ ]
43
+ `);
44
+ expect(testModuleContainer.mapTransactionActions(result.resourceTransaction)).toMatchInlineSnapshot(`
45
+ [
46
+ [
47
+ "AddHttpFetchResourceAction",
48
+ ],
49
+ ]
50
+ `);
51
+
52
+ // Correct resources are added.
53
+ expect(result.resourceDiffs).toMatchInlineSnapshot(`
54
+ [
55
+ [
56
+ {
57
+ "action": "add",
58
+ "field": "resourceId",
59
+ "node": "@<%= name %>/http-fetch=http-fetch-<%= name %>",
60
+ "value": "@<%= name %>/http-fetch=http-fetch-<%= name %>",
61
+ },
62
+ ],
63
+ ]
64
+ `);
65
+
66
+ // Resource action executed.
67
+ expect(result.resourceDiffs[0][0].node.synth()).toMatchInlineSnapshot(`
68
+ {
69
+ "parents": [],
70
+ "properties": {
71
+ "url": "https://dummy.com/echo/get/json",
72
+ },
73
+ "resourceId": "http-fetch-<%= name %>",
74
+ "response": {
75
+ "urlContent": {
76
+ "credentials": {
77
+ "password": "dummy",
78
+ "username": "dummy",
79
+ },
80
+ "data": {
81
+ "success": true,
82
+ "url": "https://dummy.com/echo/get/json",
83
+ },
84
+ },
85
+ },
86
+ "tags": {},
87
+ }
88
+ `);
89
+ });
90
+ });
@@ -0,0 +1,16 @@
1
+ import { AModule, App, Module } from '@quadnix/octo';
2
+ import { AppAnchor } from '../../../anchors/app/app.anchor.js';
3
+ import { DummyAppModuleSchema } from './index.schema.js';
4
+
5
+ /**
6
+ * This is a dummy app module that creates a new `App` model.
7
+ * It also creates an anchor for the `App` model.
8
+ */
9
+ @Module<DummyAppModule>('@<%= name %>', DummyAppModuleSchema)
10
+ export class DummyAppModule extends AModule<DummyAppModuleSchema, App> {
11
+ async onInit(inputs: DummyAppModuleSchema): Promise<App> {
12
+ const app = new App(inputs.name);
13
+ app.addAnchor(new AppAnchor('AppAnchor', { name: inputs.name }, app));
14
+ return app;
15
+ }
16
+ }
@@ -0,0 +1,10 @@
1
+ import { Schema, Validate } from '@quadnix/octo';
2
+
3
+ /**
4
+ * This is a dummy app module schema to demonstrate how to create a custom module schema.
5
+ * In this case, the `name` property is required and must be at least 1 character long.
6
+ */
7
+ export class DummyAppModuleSchema {
8
+ @Validate({ options: { minLength: 1 } })
9
+ name = Schema<string>();
10
+ }
@@ -0,0 +1,3 @@
1
+ import './models/app/index.js';
2
+
3
+ export { DummyAppModule } from './dummy-app.module.js';
@@ -0,0 +1,59 @@
1
+ import {
2
+ Action,
3
+ type ActionOutputs,
4
+ App,
5
+ type Diff,
6
+ DiffAction,
7
+ type EnhancedModuleSchema,
8
+ Factory,
9
+ type IModelAction,
10
+ hasNodeName,
11
+ } from '@quadnix/octo';
12
+ import { HttpFetch } from '../../../../../../resources/http-fetch/index.js';
13
+ import type { DummyAppModule } from '../../../dummy-app.module.js';
14
+
15
+ /**
16
+ * This dummy app model action executes when a new `App` model is added.
17
+ * It adds a new `HttpFetch` resource.
18
+ */
19
+ @Action(App)
20
+ export class AddDummyAppModelAction implements IModelAction<DummyAppModule> {
21
+ filter(diff: Diff): boolean {
22
+ return (
23
+ diff.action === DiffAction.ADD &&
24
+ diff.node instanceof App &&
25
+ hasNodeName(diff.node, 'app') &&
26
+ diff.field === 'name'
27
+ );
28
+ }
29
+
30
+ async handle(
31
+ _diff: Diff,
32
+ actionInputs: EnhancedModuleSchema<DummyAppModule>,
33
+ actionOutputs: ActionOutputs,
34
+ ): Promise<ActionOutputs> {
35
+ const { name } = actionInputs.inputs;
36
+ const httpFetch = new HttpFetch(
37
+ `http-fetch-${name}`,
38
+ {
39
+ url: 'https://dummy.com/echo/get/json',
40
+ },
41
+ [],
42
+ );
43
+
44
+ actionOutputs[httpFetch.resourceId] = httpFetch;
45
+ return actionOutputs;
46
+ }
47
+ }
48
+
49
+ @Factory<AddDummyAppModelAction>(AddDummyAppModelAction)
50
+ export class AddDummyAppModelActionFactory {
51
+ private static instance: AddDummyAppModelAction;
52
+
53
+ static async create(): Promise<AddDummyAppModelAction> {
54
+ if (!this.instance) {
55
+ this.instance = new AddDummyAppModelAction();
56
+ }
57
+ return this.instance;
58
+ }
59
+ }
@@ -0,0 +1,55 @@
1
+ import { ANodeAction, Action, Diff, DiffAction, Factory, type IResourceAction, hasNodeName } from '@quadnix/octo';
2
+ import { DummyCredentials } from '../../../factories/dummy-credentials.factory.js';
3
+ import { DummyUtility } from '../../../utilities/dummy/dummy.utility.js';
4
+ import { HttpFetch } from '../http-fetch.resource.js';
5
+
6
+ /**
7
+ * This action is executed when a new `HttpFetch` resource is added.
8
+ * It fetches content from a URL and sets the response.
9
+ */
10
+ @Action(HttpFetch)
11
+ export class AddHttpFetchResourceAction extends ANodeAction implements IResourceAction<HttpFetch> {
12
+ constructor() {
13
+ super();
14
+ }
15
+
16
+ filter(diff: Diff): boolean {
17
+ return (
18
+ diff.action === DiffAction.ADD &&
19
+ diff.node instanceof HttpFetch &&
20
+ hasNodeName(diff.node, 'http-fetch') &&
21
+ diff.field === 'resourceId'
22
+ );
23
+ }
24
+
25
+ async handle(diff: Diff<HttpFetch>): Promise<void> {
26
+ // Get properties.
27
+ const httpFetch = diff.node;
28
+ const properties = httpFetch.properties;
29
+ const response = httpFetch.response;
30
+
31
+ // Get instances.
32
+ const dummyCredentials = await this.container.get(DummyCredentials, { metadata: { package: '@<%= name %>' } });
33
+
34
+ // Fetch content and set response.
35
+ response.urlContent = await DummyUtility.httpGet(properties.url, dummyCredentials);
36
+ }
37
+
38
+ async mock(_diff: Diff<HttpFetch>, capture: Partial<HttpFetch['response']>): Promise<void> {
39
+ DummyUtility.httpGet = async (): Promise<object> => {
40
+ return capture.urlContent ?? {};
41
+ };
42
+ }
43
+ }
44
+
45
+ @Factory<AddHttpFetchResourceAction>(AddHttpFetchResourceAction)
46
+ export class AddHttpFetchResourceActionFactory {
47
+ private static instance: AddHttpFetchResourceAction;
48
+
49
+ static async create(): Promise<AddHttpFetchResourceAction> {
50
+ if (!this.instance) {
51
+ this.instance = new AddHttpFetchResourceAction();
52
+ }
53
+ return this.instance;
54
+ }
55
+ }
@@ -0,0 +1,12 @@
1
+ import { AResource, Resource } from '@quadnix/octo';
2
+ import { HttpFetchSchema } from './index.schema.js';
3
+
4
+ /**
5
+ * This is an example resource that demonstrates how to create a custom resource.
6
+ */
7
+ @Resource<HttpFetch>('@<%= name %>', 'http-fetch', HttpFetchSchema)
8
+ export class HttpFetch extends AResource<HttpFetchSchema, HttpFetch> {
9
+ constructor(resourceId: string, properties: HttpFetchSchema['properties'], parents: []) {
10
+ super(resourceId, properties, parents);
11
+ }
12
+ }
@@ -0,0 +1,35 @@
1
+ import { BaseResourceSchema, Schema, Validate } from '@quadnix/octo';
2
+
3
+ /**
4
+ * This is an example resource schema to demonstrate how to create a custom resource schema.
5
+ * This resource is for the `HttpFetch` resource, and exposes a `url` property.
6
+ * Validation for the property is also included using the `@Validate` decorator.
7
+ * In this case, the `url` property is required and must be at least 1 character long.
8
+ *
9
+ * Once the resource is run, the resource actions will fetch the content of the URL
10
+ * and store it in the `urlContent` property.
11
+ * The content validation can be done here as well, and it automatically validates when the response is set
12
+ * in the resource actions.
13
+ */
14
+ export class HttpFetchSchema extends BaseResourceSchema {
15
+ @Validate({
16
+ destruct: (value: HttpFetchSchema['properties']): string[] => [value.url],
17
+ options: { minLength: 1 },
18
+ })
19
+ override properties = Schema<{
20
+ url: string;
21
+ }>();
22
+
23
+ @Validate({
24
+ destruct: (value: HttpFetchSchema['response']): string[] => {
25
+ if (value.urlContent) {
26
+ return [JSON.stringify(value.urlContent)];
27
+ }
28
+ return [];
29
+ },
30
+ options: { minLength: 1 },
31
+ })
32
+ override response = Schema<{
33
+ urlContent?: object;
34
+ }>();
35
+ }
@@ -0,0 +1,3 @@
1
+ import './actions/add-http-fetch.resource.action.js';
2
+
3
+ export { HttpFetch } from './http-fetch.resource.js';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * This is a dummy utility exposing some dummy methods.
3
+ */
4
+ export class DummyUtility {
5
+ static async httpGet(url: string, credentials: { username: string; password: string }): Promise<object> {
6
+ return {
7
+ credentials: { password: credentials.password, username: credentials.username },
8
+ data: { success: true, url },
9
+ };
10
+ }
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "exclude": [
3
+ "**/*spec.ts",
4
+ "eslint.config.js",
5
+ "coverage",
6
+ "dist",
7
+ "node_modules",
8
+ "test"
9
+ ],
10
+ "extends": "./tsconfig.json"
11
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowSyntheticDefaultImports": true,
4
+ "baseUrl": "./",
5
+ "declaration": true,
6
+ "emitDecoratorMetadata": true,
7
+ "experimentalDecorators": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "incremental": true,
10
+ "isolatedModules": true,
11
+ "module": "Node16",
12
+ "moduleResolution": "Node16",
13
+ "noFallthroughCasesInSwitch": true,
14
+ "noImplicitAny": false,
15
+ "noImplicitOverride": true,
16
+ "outDir": "./dist",
17
+ "removeComments": false,
18
+ "skipLibCheck": true,
19
+ "sourceMap": true,
20
+ "strictBindCallApply": true,
21
+ "strictNullChecks": true,
22
+ "target": "ES2022",
23
+ "typeRoots": [
24
+ "node_modules/@types"
25
+ ],
26
+ "useDefineForClassFields": false,
27
+ "verbatimModuleSyntax": true
28
+ },
29
+ "exclude": [
30
+ "coverage",
31
+ "dist",
32
+ "node_modules"
33
+ ],
34
+ "include": [
35
+ "eslint.config.js",
36
+ "**/*.json",
37
+ "**/*.ts"
38
+ ]
39
+ }
@@ -0,0 +1 @@
1
+ export { createCdkCommand } from './create-cdk.command.js';
@@ -0,0 +1,2 @@
1
+ export { createCdkCommand } from './create-cdk.command.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/create-cdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ArgumentsCamelCase, Argv } from 'yargs';
2
+ export declare const createModelCommand: {
3
+ builder: (yargs: Argv) => Argv;
4
+ command: string;
5
+ describe: string;
6
+ handler: (argv: ArgumentsCamelCase<{
7
+ name: string;
8
+ package: string;
9
+ path: string;
10
+ type: string;
11
+ }>) => Promise<void>;
12
+ };
@@ -0,0 +1,62 @@
1
+ import { dirname, resolve } from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import chalk from 'chalk';
4
+ import { createEnv } from 'yeoman-environment';
5
+ import { StringUtility } from '../../utilities/string/string.utility.js';
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+ export const createModelCommand = {
8
+ builder: (yargs) => {
9
+ return yargs
10
+ .option('name', {
11
+ alias: 'n',
12
+ demandOption: true,
13
+ description: 'Name of the module where the model is created. Should be in kebab-case (e.g., my-awesome-region).',
14
+ type: 'string',
15
+ })
16
+ .option('type', {
17
+ alias: 't',
18
+ choices: StringUtility.AVAILABLE_MODEL_TYPES,
19
+ demandOption: true,
20
+ description: 'Type of model this custom model is extending.',
21
+ type: 'string',
22
+ })
23
+ .option('package', {
24
+ demandOption: true,
25
+ description: 'Package name for the model.',
26
+ type: 'string',
27
+ })
28
+ .option('path', {
29
+ alias: 'p',
30
+ default: '.',
31
+ description: 'Root directory path of the CDK.',
32
+ type: 'string',
33
+ });
34
+ },
35
+ command: 'create-model',
36
+ describe: 'Create a new Octo model.',
37
+ handler: async (argv) => {
38
+ const { name, package: packageName, path, type } = argv;
39
+ // Validate module name format (should be kebab-case)
40
+ if (!StringUtility.isKebabCase(name)) {
41
+ console.error(chalk.red('Module name must be in kebab-case format (e.g., my-awesome-region)'));
42
+ process.exit(1);
43
+ }
44
+ console.log(chalk.blue(`Creating model for module "${name}" of type "${type}"...`));
45
+ const env = createEnv();
46
+ env.register(resolve(__dirname, 'generator-octo-model-template/generators/app/index.js'), {
47
+ namespace: 'generator-octo-model-template:app',
48
+ });
49
+ try {
50
+ await env.run(['generator-octo-model-template:app', name, type, packageName, path], {
51
+ skipCache: true,
52
+ skipInstall: true,
53
+ });
54
+ console.log(chalk.green(`Successfully created model!`));
55
+ }
56
+ catch (error) {
57
+ console.error(chalk.red(`Failed to create model! ${error.message}`));
58
+ process.exit(1);
59
+ }
60
+ },
61
+ };
62
+ //# sourceMappingURL=create-model.command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-model.command.js","sourceRoot":"","sources":["../../../src/commands/create-model/create-model.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAEzE,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,OAAO,EAAE,CAAC,KAAW,EAAQ,EAAE;QAC7B,OAAO,KAAK;aACT,MAAM,CAAC,MAAM,EAAE;YACd,KAAK,EAAE,GAAG;YACV,YAAY,EAAE,IAAI;YAClB,WAAW,EACT,mGAAmG;YACrG,IAAI,EAAE,QAAQ;SACf,CAAC;aACD,MAAM,CAAC,MAAM,EAAE;YACd,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,aAAa,CAAC,qBAAqB;YAC5C,YAAY,EAAE,IAAI;YAClB,WAAW,EAAE,+CAA+C;YAC5D,IAAI,EAAE,QAAQ;SACf,CAAC;aACD,MAAM,CAAC,SAAS,EAAE;YACjB,YAAY,EAAE,IAAI;YAClB,WAAW,EAAE,6BAA6B;YAC1C,IAAI,EAAE,QAAQ;SACf,CAAC;aACD,MAAM,CAAC,MAAM,EAAE;YACd,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,GAAG;YACZ,WAAW,EAAE,iCAAiC;YAC9C,IAAI,EAAE,QAAQ;SACf,CAAC,CAAC;IACP,CAAC;IACD,OAAO,EAAE,cAAc;IACvB,QAAQ,EAAE,0BAA0B;IACpC,OAAO,EAAE,KAAK,EACZ,IAAuF,EACxE,EAAE;QACjB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAExD,qDAAqD;QACrD,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;YACrC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC,CAAC;YAC/F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,8BAA8B,IAAI,cAAc,IAAI,MAAM,CAAC,CAAC,CAAC;QAEpF,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;QACxB,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,uDAAuD,CAAC,EAAE;YACxF,SAAS,EAAE,mCAAmC;SAC/C,CAAC,CAAC;QAEH,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,mCAAmC,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE;gBAClF,SAAS,EAAE,IAAI;gBACf,WAAW,EAAE,IAAI;aAClB,CAAC,CAAC;YAEH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAAC;QAC1D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,2BAA2B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,11 @@
1
+ import Generator, { type BaseOptions } from 'yeoman-generator';
2
+ export default class extends Generator {
3
+ private readonly modelType;
4
+ private readonly cdkRootDir;
5
+ private readonly moduleName;
6
+ private readonly packageName;
7
+ constructor(args: string[], opts: BaseOptions);
8
+ initializing(): Promise<void>;
9
+ writing(): Promise<void>;
10
+ end(): void;
11
+ }