@ttoss/cloudformation 0.2.1 → 0.3.0

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/esm/index.js CHANGED
@@ -15,7 +15,7 @@ import * as path2 from "path";
15
15
  import * as fs from "fs";
16
16
  import * as path from "path";
17
17
 
18
- // src/cloudFormationTemplate.ts
18
+ // src/cloudFormationYamlTemplate.ts
19
19
  import yaml from "js-yaml";
20
20
  var cloudFormationTypes = [
21
21
  {
@@ -172,6 +172,9 @@ var readObjectFile = ({ path: path3 }) => {
172
172
  if (extension === "ts") {
173
173
  __require("ts-node").register({
174
174
  compilerOptions: { module: "commonjs" },
175
+ moduleTypes: {
176
+ "carlin.*": "cjs"
177
+ },
175
178
  transpileOnly: true
176
179
  });
177
180
  const tsObj = __require(path3);
@@ -217,5 +220,6 @@ var findAndReadCloudFormationTemplate = ({
217
220
  return readObjectFile({ path: fullPath });
218
221
  };
219
222
  export {
220
- findAndReadCloudFormationTemplate
223
+ findAndReadCloudFormationTemplate,
224
+ readObjectFile as unstable_readObjectFile
221
225
  };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,9 @@ interface Parameter {
5
5
  Type: string;
6
6
  NoEcho?: boolean;
7
7
  }
8
+ type Parameters = {
9
+ [key: string]: Parameter;
10
+ };
8
11
  interface Resource {
9
12
  Type: string;
10
13
  DeletionPolicy?: 'Delete' | 'Retain';
@@ -13,6 +16,39 @@ interface Resource {
13
16
  Condition?: string;
14
17
  Properties: any;
15
18
  }
19
+ interface IAMRoleResource extends Resource {
20
+ Type: 'AWS::IAM::Role';
21
+ Properties: {
22
+ AssumeRolePolicyDocument: {
23
+ Version: '2012-10-17';
24
+ Statement: {
25
+ Effect: 'Allow' | 'Deny';
26
+ Action: string;
27
+ Principal: any;
28
+ }[];
29
+ };
30
+ ManagedPolicyArns?: string[];
31
+ Path?: string;
32
+ Policies?: {
33
+ PolicyName: string;
34
+ PolicyDocument: {
35
+ Version: '2012-10-17';
36
+ Statement: {
37
+ Effect: 'Allow' | 'Deny';
38
+ Action: string | string[];
39
+ Resource: string | string[] | {
40
+ [key: string]: string;
41
+ } | {
42
+ [key: string]: string;
43
+ }[];
44
+ }[];
45
+ };
46
+ }[];
47
+ };
48
+ }
49
+ type Resources = {
50
+ [key: string]: IAMRoleResource | Resource;
51
+ };
16
52
  type Output = {
17
53
  Description?: string;
18
54
  Value: string | any;
@@ -20,24 +56,26 @@ type Output = {
20
56
  Name: string | any;
21
57
  };
22
58
  };
23
- interface CloudFormationTemplate {
59
+ type Outputs = {
60
+ [key: string]: Output;
61
+ };
62
+ type CloudFormationTemplate = {
24
63
  AWSTemplateFormatVersion: '2010-09-09';
64
+ Description?: string;
25
65
  Transform?: 'AWS::Serverless-2016-10-31';
26
66
  Mappings?: any;
27
67
  Conditions?: any;
28
- Parameters?: {
29
- [key: string]: Parameter;
30
- };
31
- Resources: {
32
- [key: string]: Resource;
33
- };
34
- Outputs?: {
35
- [key: string]: Output;
36
- };
37
- }
68
+ Parameters?: Parameters;
69
+ Resources: Resources;
70
+ Outputs?: Outputs;
71
+ };
38
72
 
39
73
  declare const findAndReadCloudFormationTemplate: ({ templatePath: defaultTemplatePath, }: {
40
74
  templatePath?: string;
41
75
  }) => CloudFormationTemplate;
42
76
 
43
- export { findAndReadCloudFormationTemplate };
77
+ declare const readObjectFile: ({ path }: {
78
+ path: string;
79
+ }) => any;
80
+
81
+ export { CloudFormationTemplate, IAMRoleResource, Output, Outputs, Parameter, Parameters, Resource, Resources, findAndReadCloudFormationTemplate, readObjectFile as unstable_readObjectFile };
package/dist/index.js CHANGED
@@ -27,7 +27,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
27
27
  // src/index.ts
28
28
  var src_exports = {};
29
29
  __export(src_exports, {
30
- findAndReadCloudFormationTemplate: () => findAndReadCloudFormationTemplate
30
+ findAndReadCloudFormationTemplate: () => findAndReadCloudFormationTemplate,
31
+ unstable_readObjectFile: () => readObjectFile
31
32
  });
32
33
  module.exports = __toCommonJS(src_exports);
33
34
 
@@ -39,7 +40,7 @@ var path2 = __toESM(require("path"));
39
40
  var fs = __toESM(require("fs"));
40
41
  var path = __toESM(require("path"));
41
42
 
42
- // src/cloudFormationTemplate.ts
43
+ // src/cloudFormationYamlTemplate.ts
43
44
  var import_js_yaml = __toESM(require("js-yaml"));
44
45
  var cloudFormationTypes = [
45
46
  {
@@ -196,6 +197,9 @@ var readObjectFile = ({ path: path3 }) => {
196
197
  if (extension === "ts") {
197
198
  require("ts-node").register({
198
199
  compilerOptions: { module: "commonjs" },
200
+ moduleTypes: {
201
+ "carlin.*": "cjs"
202
+ },
199
203
  transpileOnly: true
200
204
  });
201
205
  const tsObj = require(path3);
@@ -242,5 +246,6 @@ var findAndReadCloudFormationTemplate = ({
242
246
  };
243
247
  // Annotate the CommonJS export names for ESM import in node:
244
248
  0 && (module.exports = {
245
- findAndReadCloudFormationTemplate
249
+ findAndReadCloudFormationTemplate,
250
+ unstable_readObjectFile
246
251
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/cloudformation",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "CloudFormation utils.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "ttoss",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "build": "tsup",
18
- "test": "echo test"
18
+ "test": "jest"
19
19
  },
20
20
  "typings": "dist/index.d.ts",
21
21
  "dependencies": {
@@ -23,11 +23,14 @@
23
23
  "ts-node": "^10.9.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@ttoss/config": "^1.26.0"
26
+ "@ttoss/config": "^1.26.0",
27
+ "@ttoss/test-utils": "^1.20.0",
28
+ "@types/jest": "^29.2.4",
29
+ "jest": "^29.3.1"
27
30
  },
28
31
  "keywords": [],
29
32
  "publishConfig": {
30
33
  "access": "public"
31
34
  },
32
- "gitHead": "98cf227311c2f28ab73520c793bfe0bf0df27530"
35
+ "gitHead": "f7fcb1caa22adf045f0ec7d15a678bfe48a3913d"
33
36
  }
@@ -0,0 +1,72 @@
1
+ export interface Parameter {
2
+ AllowedValues?: string[];
3
+ Default?: string | number;
4
+ Description?: string;
5
+ Type: string;
6
+ NoEcho?: boolean;
7
+ }
8
+
9
+ export type Parameters = { [key: string]: Parameter };
10
+
11
+ export interface Resource {
12
+ Type: string;
13
+ DeletionPolicy?: 'Delete' | 'Retain';
14
+ Description?: string;
15
+ DependsOn?: string[] | string;
16
+ Condition?: string;
17
+ Properties: any;
18
+ }
19
+
20
+ export interface IAMRoleResource extends Resource {
21
+ Type: 'AWS::IAM::Role';
22
+ Properties: {
23
+ AssumeRolePolicyDocument: {
24
+ Version: '2012-10-17';
25
+ Statement: {
26
+ Effect: 'Allow' | 'Deny';
27
+ Action: string;
28
+ Principal: any;
29
+ }[];
30
+ };
31
+ ManagedPolicyArns?: string[];
32
+ Path?: string;
33
+ Policies?: {
34
+ PolicyName: string;
35
+ PolicyDocument: {
36
+ Version: '2012-10-17';
37
+ Statement: {
38
+ Effect: 'Allow' | 'Deny';
39
+ Action: string | string[];
40
+ Resource:
41
+ | string
42
+ | string[]
43
+ | { [key: string]: string }
44
+ | { [key: string]: string }[];
45
+ }[];
46
+ };
47
+ }[];
48
+ };
49
+ }
50
+
51
+ export type Resources = { [key: string]: IAMRoleResource | Resource };
52
+
53
+ export type Output = {
54
+ Description?: string;
55
+ Value: string | any;
56
+ Export?: {
57
+ Name: string | any;
58
+ };
59
+ };
60
+
61
+ export type Outputs = { [key: string]: Output };
62
+
63
+ export type CloudFormationTemplate = {
64
+ AWSTemplateFormatVersion: '2010-09-09';
65
+ Description?: string;
66
+ Transform?: 'AWS::Serverless-2016-10-31';
67
+ Mappings?: any;
68
+ Conditions?: any;
69
+ Parameters?: Parameters;
70
+ Resources: Resources;
71
+ Outputs?: Outputs;
72
+ };
@@ -1,40 +1,6 @@
1
+ import { CloudFormationTemplate } from './CloudFormationTemplate';
1
2
  import yaml from 'js-yaml';
2
3
 
3
- interface Parameter {
4
- AllowedValues?: string[];
5
- Default?: string | number;
6
- Description?: string;
7
- Type: string;
8
- NoEcho?: boolean;
9
- }
10
-
11
- export interface Resource {
12
- Type: string;
13
- DeletionPolicy?: 'Delete' | 'Retain';
14
- Description?: string;
15
- DependsOn?: string[] | string;
16
- Condition?: string;
17
- Properties: any;
18
- }
19
-
20
- export type Output = {
21
- Description?: string;
22
- Value: string | any;
23
- Export?: {
24
- Name: string | any;
25
- };
26
- };
27
-
28
- export interface CloudFormationTemplate {
29
- AWSTemplateFormatVersion: '2010-09-09';
30
- Transform?: 'AWS::Serverless-2016-10-31';
31
- Mappings?: any;
32
- Conditions?: any;
33
- Parameters?: { [key: string]: Parameter };
34
- Resources: { [key: string]: Resource };
35
- Outputs?: { [key: string]: Output };
36
- }
37
-
38
4
  export interface TagAndType {
39
5
  tag: string;
40
6
  options: yaml.TypeConstructorOptions;
@@ -1,6 +1,6 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
- import { CloudFormationTemplate } from './cloudFormationTemplate';
3
+ import { CloudFormationTemplate } from './CloudFormationTemplate';
4
4
  import { readCloudFormationYamlTemplate } from './readCloudFormationYamlTemplate';
5
5
  import { readObjectFile } from './readObjectFile';
6
6
 
package/src/index.ts CHANGED
@@ -1 +1,7 @@
1
1
  export { findAndReadCloudFormationTemplate } from './findAndReadCloudFormationTemplate';
2
+ export * from './CloudFormationTemplate';
3
+
4
+ /**
5
+ * Unstable API.
6
+ */
7
+ export { readObjectFile as unstable_readObjectFile } from './readObjectFile';
@@ -1,10 +1,10 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
+ import { CloudFormationTemplate } from './CloudFormationTemplate';
3
4
  import {
4
- CloudFormationTemplate,
5
5
  TagAndType,
6
6
  loadCloudFormationTemplate,
7
- } from './cloudFormationTemplate';
7
+ } from './cloudFormationYamlTemplate';
8
8
 
9
9
  const getTypes = (): TagAndType[] => {
10
10
  return [
@@ -7,13 +7,6 @@ export const readYaml = ({ path }: { path: string }) => {
7
7
  return yaml.load(template);
8
8
  };
9
9
 
10
- /**
11
- * If your file is `.ts`, you must you must export the final object
12
- * `export default { ... }`. If your file is `.js`, you must you must export
13
- * the final object `module.exports = { ... }`. `.json` and `.yml/yaml` must
14
- * define the resources in [JSON](https://www.json.org/json-en.html) and
15
- * [YAML](https://yaml.org/) format respectively.
16
- */
17
10
  export const readObjectFile = ({ path }: { path: string }) => {
18
11
  if (!fs.existsSync(path)) {
19
12
  return {};
@@ -24,6 +17,9 @@ export const readObjectFile = ({ path }: { path: string }) => {
24
17
  if (extension === 'ts') {
25
18
  require('ts-node').register({
26
19
  compilerOptions: { module: 'commonjs' },
20
+ moduleTypes: {
21
+ 'carlin.*': 'cjs',
22
+ },
27
23
  transpileOnly: true,
28
24
  });
29
25
  const tsObj = require(path);