@cloud-copilot/iam-shrink 0.1.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.
Files changed (85) hide show
  1. package/LICENSE.txt +674 -0
  2. package/README.md +187 -0
  3. package/dist/cjs/cli.d.ts +2 -0
  4. package/dist/cjs/cli.d.ts.map +1 -0
  5. package/dist/cjs/cli.js +78 -0
  6. package/dist/cjs/cli.js.map +1 -0
  7. package/dist/cjs/cli_utils.d.ts +30 -0
  8. package/dist/cjs/cli_utils.d.ts.map +1 -0
  9. package/dist/cjs/cli_utils.js +75 -0
  10. package/dist/cjs/cli_utils.js.map +1 -0
  11. package/dist/cjs/errors.d.ts +13 -0
  12. package/dist/cjs/errors.d.ts.map +1 -0
  13. package/dist/cjs/errors.js +56 -0
  14. package/dist/cjs/errors.js.map +1 -0
  15. package/dist/cjs/index.d.ts +3 -0
  16. package/dist/cjs/index.d.ts.map +1 -0
  17. package/dist/cjs/index.js +8 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/package.json +3 -0
  20. package/dist/cjs/shrink.d.ts +131 -0
  21. package/dist/cjs/shrink.d.ts.map +1 -0
  22. package/dist/cjs/shrink.js +358 -0
  23. package/dist/cjs/shrink.js.map +1 -0
  24. package/dist/cjs/shrink_file.d.ts +12 -0
  25. package/dist/cjs/shrink_file.d.ts.map +1 -0
  26. package/dist/cjs/shrink_file.js +38 -0
  27. package/dist/cjs/shrink_file.js.map +1 -0
  28. package/dist/cjs/stdin.d.ts +7 -0
  29. package/dist/cjs/stdin.d.ts.map +1 -0
  30. package/dist/cjs/stdin.js +34 -0
  31. package/dist/cjs/stdin.js.map +1 -0
  32. package/dist/cjs/validate.d.ts +11 -0
  33. package/dist/cjs/validate.d.ts.map +1 -0
  34. package/dist/cjs/validate.js +30 -0
  35. package/dist/cjs/validate.js.map +1 -0
  36. package/dist/esm/cli.d.ts +2 -0
  37. package/dist/esm/cli.d.ts.map +1 -0
  38. package/dist/esm/cli.js +76 -0
  39. package/dist/esm/cli.js.map +1 -0
  40. package/dist/esm/cli_utils.d.ts +30 -0
  41. package/dist/esm/cli_utils.d.ts.map +1 -0
  42. package/dist/esm/cli_utils.js +69 -0
  43. package/dist/esm/cli_utils.js.map +1 -0
  44. package/dist/esm/errors.d.ts +13 -0
  45. package/dist/esm/errors.d.ts.map +1 -0
  46. package/dist/esm/errors.js +50 -0
  47. package/dist/esm/errors.js.map +1 -0
  48. package/dist/esm/index.d.ts +3 -0
  49. package/dist/esm/index.d.ts.map +1 -0
  50. package/dist/esm/index.js +3 -0
  51. package/dist/esm/index.js.map +1 -0
  52. package/dist/esm/package.json +3 -0
  53. package/dist/esm/shrink.d.ts +131 -0
  54. package/dist/esm/shrink.d.ts.map +1 -0
  55. package/dist/esm/shrink.js +343 -0
  56. package/dist/esm/shrink.js.map +1 -0
  57. package/dist/esm/shrink_file.d.ts +12 -0
  58. package/dist/esm/shrink_file.d.ts.map +1 -0
  59. package/dist/esm/shrink_file.js +35 -0
  60. package/dist/esm/shrink_file.js.map +1 -0
  61. package/dist/esm/stdin.d.ts +7 -0
  62. package/dist/esm/stdin.d.ts.map +1 -0
  63. package/dist/esm/stdin.js +31 -0
  64. package/dist/esm/stdin.js.map +1 -0
  65. package/dist/esm/validate.d.ts +11 -0
  66. package/dist/esm/validate.d.ts.map +1 -0
  67. package/dist/esm/validate.js +27 -0
  68. package/dist/esm/validate.js.map +1 -0
  69. package/package.json +43 -0
  70. package/postbuild.sh +13 -0
  71. package/src/cli.ts +83 -0
  72. package/src/cli_utils.test.ts +117 -0
  73. package/src/cli_utils.ts +82 -0
  74. package/src/errors.ts +52 -0
  75. package/src/index.ts +3 -0
  76. package/src/shrink.test.ts +594 -0
  77. package/src/shrink.ts +385 -0
  78. package/src/shrink_file.test.ts +72 -0
  79. package/src/shrink_file.ts +38 -0
  80. package/src/stdin.ts +34 -0
  81. package/src/validate.test.ts +55 -0
  82. package/src/validate.ts +29 -0
  83. package/tsconfig.cjs.json +12 -0
  84. package/tsconfig.esm.json +15 -0
  85. package/tsconfig.json +23 -0
@@ -0,0 +1,30 @@
1
+ import { ShrinkOptions } from "./shrink.js";
2
+ interface CliOptions extends ShrinkOptions {
3
+ showDataVersion: boolean;
4
+ readWaitMs: string;
5
+ }
6
+ /**
7
+ * Convert a dash-case string to camelCase
8
+ * @param str the string to convert
9
+ * @returns the camelCase string
10
+ */
11
+ export declare function dashToCamelCase(str: string): string;
12
+ /**
13
+ * Convert an array of option strings to an object
14
+ *
15
+ * @param optionArgs the array of option strings to convert
16
+ * @returns the object representation of the options
17
+ */
18
+ export declare function convertOptions(optionArgs: string[]): Partial<CliOptions>;
19
+ export declare function extractActionsFromLineOfInput(line: string): string[];
20
+ /**
21
+ * Parse the actions from stdin
22
+ *
23
+ * @returns an array of strings from stdin
24
+ */
25
+ export declare function parseStdIn(options: Partial<CliOptions>): Promise<{
26
+ strings?: string[];
27
+ object?: any;
28
+ }>;
29
+ export {};
30
+ //# sourceMappingURL=cli_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli_utils.d.ts","sourceRoot":"","sources":["../../src/cli_utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,UAAU,UAAW,SAAQ,aAAa;IACxC,eAAe,EAAE,OAAO,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAwBxE;AAGD,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAMpE;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,GAAG,CAAA;CAAC,CAAC,CAgB1G"}
@@ -0,0 +1,69 @@
1
+ import { shrinkJsonDocument } from "./shrink_file.js";
2
+ import { readStdin } from "./stdin.js";
3
+ /**
4
+ * Convert a dash-case string to camelCase
5
+ * @param str the string to convert
6
+ * @returns the camelCase string
7
+ */
8
+ export function dashToCamelCase(str) {
9
+ str = str.substring(2);
10
+ return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
11
+ }
12
+ /**
13
+ * Convert an array of option strings to an object
14
+ *
15
+ * @param optionArgs the array of option strings to convert
16
+ * @returns the object representation of the options
17
+ */
18
+ export function convertOptions(optionArgs) {
19
+ const options = {};
20
+ for (const option of optionArgs) {
21
+ let key = option;
22
+ let value = true;
23
+ if (option.includes('=')) {
24
+ [key, value] = option.split('=');
25
+ }
26
+ options[dashToCamelCase(key)] = value;
27
+ }
28
+ if (options.iterations) {
29
+ const iterationNumber = parseInt(options.iterations);
30
+ if (isNaN(iterationNumber)) {
31
+ delete options.iterations;
32
+ }
33
+ else if (iterationNumber <= 0) {
34
+ options.iterations = Infinity;
35
+ }
36
+ else {
37
+ options.iterations = iterationNumber;
38
+ }
39
+ }
40
+ return options;
41
+ }
42
+ const actionPattern = /\:?([a-zA-Z0-9-]+:[a-zA-Z0-9*]+)/g;
43
+ export function extractActionsFromLineOfInput(line) {
44
+ const matches = line.matchAll(actionPattern);
45
+ return Array.from(matches)
46
+ .filter((match) => !match[0].startsWith('arn:') && !match[0].startsWith(':'))
47
+ .map((match) => match[1]);
48
+ }
49
+ /**
50
+ * Parse the actions from stdin
51
+ *
52
+ * @returns an array of strings from stdin
53
+ */
54
+ export async function parseStdIn(options) {
55
+ const delay = options.readWaitMs ? parseInt(options.readWaitMs.replaceAll(/\D/g, '')) : undefined;
56
+ const data = await readStdin(delay);
57
+ if (data.length === 0) {
58
+ return {};
59
+ }
60
+ try {
61
+ const object = await shrinkJsonDocument(options, JSON.parse(data));
62
+ return { object };
63
+ }
64
+ catch (err) { }
65
+ const lines = data.split('\n');
66
+ const actions = lines.flatMap(line => extractActionsFromLineOfInput(line));
67
+ return { strings: actions };
68
+ }
69
+ //# sourceMappingURL=cli_utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli_utils.js","sourceRoot":"","sources":["../../src/cli_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAOvC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACtB,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,UAAoB;IACjD,MAAM,OAAO,GAA8C,EAAE,CAAE;IAE/D,KAAI,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;QAC/B,IAAI,GAAG,GAAW,MAAM,CAAA;QACxB,IAAI,KAAK,GAAqB,IAAI,CAAA;QAClC,IAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,CAAC,GAAG,EAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACjC,CAAC;QAED,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAA;IACvC,CAAC;IACD,IAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QACtB,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,UAAoB,CAAC,CAAA;QAC9D,IAAG,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC;YAC1B,OAAO,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,EAAC,MAAM,EAAC,CAAA;IACjB,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC,CAAA,CAAC;IAGrB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC,CAAA;IAC1E,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,13 @@
1
+ export declare class ShrinkValidationError extends Error {
2
+ readonly desiredPatterns: string[];
3
+ readonly errorMatch: string;
4
+ /**
5
+ * Capture a validation error from a shrink operation
6
+ *
7
+ * @param desiredPatterns the patterns the user wanted to shrink
8
+ * @param excludedPatterns the patterns the user wanted to exclude
9
+ * @param errorMatch the undesired match that triggered the bug
10
+ */
11
+ constructor(desiredPatterns: string[], errorMatch: string);
12
+ }
13
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAmCA,qBAAa,qBAAsB,SAAQ,KAAK;aAQlB,eAAe,EAAE,MAAM,EAAE;aAAkB,UAAU,EAAE,MAAM;IAPzF;;;;;;OAMG;gBACyB,eAAe,EAAE,MAAM,EAAE,EAAkB,UAAU,EAAE,MAAM;CAO1F"}
@@ -0,0 +1,50 @@
1
+ const bugBaseUrl = 'https://github.com/cloud-copilot/iam-shrink/issues/new';
2
+ /**
3
+ * The title of the bug report
4
+ * @param errorMatch The undesired match
5
+ * @returns the title of the bug report
6
+ */
7
+ function bugTitle(errorMatch) {
8
+ return `Bug: ShrinkValidationError. ${errorMatch}`;
9
+ }
10
+ /**
11
+ * The body of the bug report
12
+ *
13
+ * @param errorMatch The undesired match
14
+ * @param desiredPatterns The desired patterns
15
+ * @param excludedPatterns The excluded patterns
16
+ * @returns the body of the bug report
17
+ */
18
+ function bugBody(errorMatch, desiredPatterns) {
19
+ return `${errorMatch} while shrinking patterns ${JSON.stringify(desiredPatterns)}`;
20
+ }
21
+ /**
22
+ * Get the full url of the full bug report
23
+ *
24
+ * @param desiredPatterns The desired patterns
25
+ * @param excludedPatterns The excluded patterns
26
+ * @param errorMatch The undesired match that caused the bug
27
+ * @returns the full url to create a new bug report
28
+ */
29
+ function bugUrl(desiredPatterns, errorMatch) {
30
+ return `${bugBaseUrl}?labels=bug&title=${encodeURIComponent(bugTitle(errorMatch))}&body=${encodeURIComponent(bugBody(errorMatch, desiredPatterns))}`;
31
+ }
32
+ export class ShrinkValidationError extends Error {
33
+ /**
34
+ * Capture a validation error from a shrink operation
35
+ *
36
+ * @param desiredPatterns the patterns the user wanted to shrink
37
+ * @param excludedPatterns the patterns the user wanted to exclude
38
+ * @param errorMatch the undesired match that triggered the bug
39
+ */
40
+ constructor(desiredPatterns, errorMatch) {
41
+ super([
42
+ `@cloud-copilot/iam-shrink has failed validation and this is a bug.`,
43
+ `Please file a bug at ${bugUrl(desiredPatterns, errorMatch)}`,
44
+ ].join("\n"));
45
+ this.desiredPatterns = desiredPatterns;
46
+ this.errorMatch = errorMatch;
47
+ this.name = "ShrinkValidationError"; // Set the name of the error
48
+ }
49
+ }
50
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,wDAAwD,CAAA;AAE3E;;;;GAIG;AACH,SAAS,QAAQ,CAAC,UAAkB;IAClC,OAAO,+BAA+B,UAAU,EAAE,CAAC;AACrD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,OAAO,CAAC,UAAkB,EAAE,eAAyB;IAC5D,OAAO,GAAG,UAAU,6BAA6B,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC;AACrF,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,MAAM,CAAC,eAAyB,EAAE,UAAkB;IAC3D,OAAO,GAAG,UAAU,qBAAqB,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,SAAS,kBAAkB,CAAC,OAAO,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC;AACvJ,CAAC;AAED,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C;;;;;;OAMG;IACH,YAA4B,eAAyB,EAAkB,UAAkB;QACvF,KAAK,CAAC;YACJ,oEAAoE;YACpE,wBAAwB,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,EAAE;SAC9D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAJY,oBAAe,GAAf,eAAe,CAAU;QAAkB,eAAU,GAAV,UAAU,CAAQ;QAKvF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC,CAAC,4BAA4B;IACnE,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export { shrink } from './shrink.js';
2
+ export { shrinkJsonDocument } from './shrink_file.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { shrink } from './shrink.js';
2
+ export { shrinkJsonDocument } from './shrink_file.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,131 @@
1
+ export interface ShrinkOptions {
2
+ iterations: number;
3
+ }
4
+ /**
5
+ * Shrink the list of desired patterns minus the excluded patterns to the smallest list of patterns
6
+ * that still includes the actions you want and only the actions you want.
7
+ *
8
+ * This will create a Target Set of actions that match the patterns in {@link desiredPatterns}, and do
9
+ * not match any pattern in {@link excludedPatterns}.
10
+ *
11
+ * It will then derive the list of wildcard patterns that match the Target Set and no other actions.
12
+ *
13
+ * @param desiredPatterns the list of patterns you want to include, e.g. ['s3:Get*', 's3:PutObject', 's3:*Tag*']
14
+ * @param iterations the number of iterations to run the shrink operations
15
+ * @returns the smallest list of patterns that will match only the actions specified by desiredPatterns and not match any of the excludedPatterns or any actions not specified by desiredPatterns.
16
+ */
17
+ export declare function shrink(desiredPatterns: string[], shrinkOptions?: Partial<ShrinkOptions>): Promise<string[]>;
18
+ /**
19
+ * Map an array of service:action strings to just the action
20
+ *
21
+ * @param actions the array of service:action strings such as ['s3:GetObject', 'ec2:DescribeInstances']
22
+ * @returns an array of just the action strings such as ['GetObject', 'DescribeInstances']
23
+ */
24
+ export declare function mapActions(actions: string[]): string[];
25
+ /**
26
+ * Groups an array of service:action strings by service
27
+ *
28
+ * Returns a map of service to an object with two arrays: withService and withoutService
29
+ * * withService contains the full service:action strings
30
+ * * withoutService contains just the action strings
31
+ *
32
+ * @param actions the array of service:action strings such as ['s3:GetObject', 'ec2:DescribeInstances']
33
+ * @returns a map of service to an object with two arrays: withService and withoutService
34
+ */
35
+ export declare function groupActionsByService(actions: string[]): Map<string, {
36
+ withService: string[];
37
+ withoutService: string[];
38
+ }>;
39
+ /**
40
+ * Shrink a list of desired actions to the smallest number of patterns that match the desired actions
41
+ * from the possible actions and no other actions.
42
+ *
43
+ * @param desiredActions the list of actions you want to include
44
+ * @param possibleActions the list of actions that are possible
45
+ * @param iterations the number of iterations to run the shrink operations
46
+ * @returns the smallest list of patterns that when compared to possibleActions will match only the desiredActions and no others
47
+ */
48
+ export declare function shrinkResolvedList(desiredActions: string[], possibleActions: string[], iterations: number): string[];
49
+ /**
50
+ * Shrink the list of desired actions for while excluding the undesired actions
51
+ *
52
+ * @param desiredActions the list of actions you want to include, can be a mix of full actions and wildcards
53
+ * @param undesiredActions the list of actions you want to exclude no matter what
54
+ * @param deep if true, will shrink based on all common sequences, otherwise will only shrink based on the most common sequence
55
+ * @returns the smallest list of actions that will match only the desiredActions and not match any of the undesiredActions or any actions not specified by desiredActions.
56
+ */
57
+ export declare function shrinkIteration(desiredActions: string[], undesiredActions: string[], deep: boolean): string[];
58
+ /**
59
+ * Reduces a singele action into a smaller number of parts by replace one part at a time with an asterisk
60
+ * and validating that there are no undesired actions that match the new action
61
+ *
62
+ * @param desiredAction the action to reduce
63
+ * @param sequence the sequence to reduce the action by
64
+ * @param undesiredActions the list of actions that should not match the reduced action
65
+ * @returns the reduced action with as many parts replaced with asterisks as possible while still matching the desired actions and not matching any of the undesired actions
66
+ */
67
+ export declare function reduceAction(desiredAction: string, sequence: string, undesiredActions: string[]): string;
68
+ /**
69
+ * Consolidate multile consecutive asterisks into a single asterisk
70
+ *
71
+ * @param wildcardAction the action to collapse
72
+ * @returns the action with consecutive asterisks collapsed into a single asterisk
73
+ */
74
+ export declare function collapseAsterisks(wildcardAction: string): string;
75
+ /**
76
+ * Convert a wildcard action into a regular expression
77
+ *
78
+ * @param wildcardAction the wildcard action to convert
79
+ * @returns a regular expression that will match the wildcard action
80
+ */
81
+ export declare function regexForWildcardAction(wildcardAction: string): RegExp;
82
+ /**
83
+ * Checks to see if a wildcard action matches any of the strings in a list
84
+ *
85
+ * @param wildcardAction the wildcard action to check
86
+ * @param strings the list of strings to check against
87
+ * @returns true if the wildcard action matches any of the strings
88
+ */
89
+ export declare function wildcardActionMatchesAnyString(wildcardAction: string, strings: string[]): boolean;
90
+ /**
91
+ * Split an IAM Action into parts based on capital letters and asterisks
92
+ * For a new part to start there must be a transition from a lowercase letter to an uppercase letter or an asterisk
93
+ * For example :
94
+ * * "CreateAccessPointForObjectLambda" would be split into ["Create", "Access", "Point", "For", "Object", "Lambda"]
95
+ * * "*ObjectTagging*" would be split into ["*", "Object", "Tagging", "*"]
96
+ *
97
+ * @param input the IAM Action to split
98
+ * @returns the parts of the IAM Action
99
+ */
100
+ export declare function splitActionIntoParts(input: string): string[];
101
+ /**
102
+ * Given a list of strings and a list of strings those parts are in, count the number of times each part appears in the strings
103
+ *
104
+ * @param substrings the sub strings to count
105
+ * @param actions the list of strings to count the substrings in
106
+ * @returns Returns a map of the substring to the number of times it appears in the actions
107
+ */
108
+ export declare function countSubstrings(substrings: string[], actions: string[]): Map<string, number>;
109
+ /**
110
+ * Finds all the the common sequences in a list of actions strings and counts their frequency and length.
111
+ *
112
+ * @param actions the list of actions to find common sequences in
113
+ * @returns an array of objects with the sequence, frequency, and length of the common sequences
114
+ */
115
+ export declare function findCommonSequences(actions: string[]): {
116
+ sequence: string;
117
+ frequency: number;
118
+ length: number;
119
+ }[];
120
+ /**
121
+ * Consolidates overlapping wildcards into their most general form
122
+ *
123
+ * For example:
124
+ * ['*Object', 'Object*', '*Object*'] will be consolidated into ['*Object*']
125
+ * ['Get*', '*Get*'] will be consolidated into ['*Get*']
126
+ *
127
+ * @param patterns the list of patterns to consolidate
128
+ * @returns the consolidated list of patterns
129
+ */
130
+ export declare function consolidateWildcardPatterns(patterns: string[]): string[];
131
+ //# sourceMappingURL=shrink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shrink.d.ts","sourceRoot":"","sources":["../../src/shrink.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAA;CACnB;AAQD;;;;;;;;;;;;GAYG;AACH,wBAAsB,MAAM,CAAC,eAAe,EAAE,MAAM,EAAE,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA4BjH;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAEtD;AAED;;;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