justus 0.5.0 → 0.5.1

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.
@@ -30,6 +30,11 @@ __export(arn_exports, {
30
30
  module.exports = __toCommonJS(arn_exports);
31
31
  var import_errors = require("../errors.cjs");
32
32
  var import_types = require("../types.cjs");
33
+ function assertComponent(actual, expected, kind) {
34
+ if (expected === void 0)
35
+ return;
36
+ (0, import_errors.assertValidation)(actual === expected, `ARN ${kind} "${actual}" mismatch (expected "${expected}")`);
37
+ }
33
38
  function parse(value, service, type) {
34
39
  (0, import_errors.assertValidation)(typeof value == "string", 'Value is not a "string"');
35
40
  const segments = value.split(":");
@@ -40,22 +45,20 @@ function parse(value, service, type) {
40
45
  (0, import_errors.assertValidation)(!!svc, "Missing service in ARN");
41
46
  (0, import_errors.assertValidation)(!!act, "Missing account ID in ARN");
42
47
  (0, import_errors.assertValidation)(!!res[0], "Missing resource ID in ARN");
43
- if (service !== void 0) {
44
- (0, import_errors.assertValidation)(svc === service, `ARN Service "${svc}" mismatch (expected "${service}")`);
45
- }
46
- const [resArray, resString] = res[0].includes("/") ? [res[0].split("/"), res[0]] : [res, res.join(":")];
47
- (0, import_errors.assertValidation)(!!resArray[0], "Invalid resource ID in ARN");
48
- if (type !== void 0) {
49
- (0, import_errors.assertValidation)(resArray[0] === type, `ARN Resource Type "${resArray[0]}" mismatch (expected "${type}")`);
50
- }
48
+ const [[resType, ...resArray], resString] = res[0].includes("/") ? [res[0].split("/"), res[0]] : [res, res.join(":")];
49
+ (0, import_errors.assertValidation)(!!resType, "Invalid resource ID in ARN");
50
+ assertComponent(svc, service, "Service");
51
+ assertComponent(resType, type, "Resource Type");
51
52
  const arn2 = `arn:${prt}:${svc}:${rgn}:${act}:${resString}`;
52
53
  return {
53
54
  Arn: arn2,
54
55
  Partition: prt,
55
56
  Service: svc,
57
+ // as Service,
56
58
  Region: rgn || "",
57
59
  Account: act,
58
- Resource: resArray
60
+ Resource: [resType, ...resArray]
61
+ // as [ ResourceType, ...string[] ],
59
62
  };
60
63
  }
61
64
  var ParsedArnValidator = class extends import_types.AbstractValidator {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/extra/arn.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,mBAAwD;AAoBxD,SAAS,MACL,OACA,SACA,MACkB;AACpB,sCAAiB,OAAO,SAAS,UAAU,yBAAyB;AAEpE,QAAM,WAAW,MAAM,MAAM,GAAG;AAEhC,sCAAiB,SAAS,UAAU,GAAG,2BAA2B;AAElE,QAAM,CAAE,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG,GAAI,IAAI;AAE5C,sCAAiB,QAAQ,OAAO,4BAA4B;AAC5D,sCAAiB,CAAC,CAAE,KAAK,0BAA0B;AACnD,sCAAiB,CAAC,CAAE,KAAK,wBAAwB;AACjD,sCAAiB,CAAC,CAAE,KAAK,2BAA2B;AACpD,sCAAiB,CAAC,CAAE,IAAI,CAAC,GAAG,4BAA4B;AAExD,MAAI,YAAY,QAAW;AACzB,wCAAiB,QAAQ,SAAS,gBAAgB,GAAG,yBAAyB,OAAO,IAAI;AAAA,EAC3F;AAEA,QAAM,CAAE,UAAU,SAAU,IAAI,IAAI,CAAC,EAAE,SAAS,GAAG,IACjD,CAAE,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,IAAI,CAAC,CAAE,IAC5B,CAAE,KAAK,IAAI,KAAK,GAAG,CAAE;AAEvB,sCAAiB,CAAC,CAAE,SAAS,CAAC,GAAG,4BAA4B;AAE7D,MAAI,SAAS,QAAW;AACtB,wCAAiB,SAAS,CAAC,MAAM,MAAM,sBAAsB,SAAS,CAAC,CAAC,yBAAyB,IAAI,IAAI;AAAA,EAC3G;AAEA,QAAMA,OAAM,OAAO,GAAG,IAAI,GAAG,IAAI,G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E;AAAA,EACjD;AACF;AAYO,SAAS,gBAGZ,SACA,cACyC;AAC3C,SAAO,IAAI,mBAAmB,SAAS,YAAY;AACrD;AAUO,SAAS,WAGZ,SACA,cACmC;AACrC,SAAO,IAAI,aAAa,SAAS,YAAY;AAC/C;AAKO,IAAM,eAAW,mCAAqB,IAAI,mBAAmB,GAAG,eAAe;AAG/E,IAAM,UAAM,mCAAqB,IAAI,aAAa,GAAG,UAAU;",
5
5
  "names": ["arn"]
6
6
  }
@@ -1,22 +1,24 @@
1
1
  import { AbstractValidator } from '../types';
2
2
  /** The type for a validated _string_ ARN (Amazon Resource Name) */
3
- export type ArnString<Service extends string = string> = string & {
3
+ export type ArnString<Service extends string = string, ResourceType extends string = string> = string & {
4
4
  __arn: never;
5
5
  } & (string extends Service ? string : {
6
- [k in `__arn_${Service}`]: never;
6
+ [k in `__arn_service_${Service}`]: never;
7
+ }) & (string extends ResourceType ? string : {
8
+ [k in `__arn_resource_${ResourceType}`]: never;
7
9
  });
8
10
  /** The type for a _parsed_ ARN (Amazon Resource Name) */
9
- export interface ParsedArn<Service extends string = string> {
11
+ export interface ParsedArn<Service extends string = string, ResourceType extends string = string> {
10
12
  /** The full */
11
- Arn: ArnString<Service>;
13
+ Arn: ArnString<Service, ResourceType>;
12
14
  Partition: string;
13
15
  Service: Service;
14
16
  Region: string;
15
17
  Account: string;
16
- Resource: [string, ...string[]];
18
+ Resource: [ResourceType, ...string[]];
17
19
  }
18
20
  /** Validator parsing an ARN (Amazon Resource Name) and returning its components */
19
- export declare class ParsedArnValidator<Service extends string = string> extends AbstractValidator<ParsedArn<Service>, string> {
21
+ export declare class ParsedArnValidator<Service extends string = string, ResourceType extends string = string> extends AbstractValidator<ParsedArn<Service, ResourceType>, string> {
20
22
  private _service?;
21
23
  private _type?;
22
24
  /**
@@ -28,11 +30,11 @@ export declare class ParsedArnValidator<Service extends string = string> extends
28
30
  * representing (e.g. `role` in the `iam` service, or
29
31
  * `targetgroup` in the `elasticloadbalancing` service)
30
32
  */
31
- constructor(service?: Service, resourceType?: string);
32
- validate(value: unknown): ParsedArn<Service>;
33
+ constructor(service?: Service, resourceType?: ResourceType);
34
+ validate(value: unknown): ParsedArn<Service, ResourceType>;
33
35
  }
34
36
  /** Validator validating an ARN (Amazon Resource Name) _string_ */
35
- export declare class ArnValidator<Service extends string = string> extends AbstractValidator<ArnString<Service>, string> {
37
+ export declare class ArnValidator<Service extends string = string, ResourceType extends string = string> extends AbstractValidator<ArnString<Service, ResourceType>, string> {
36
38
  private _service?;
37
39
  private _type?;
38
40
  /**
@@ -44,8 +46,8 @@ export declare class ArnValidator<Service extends string = string> extends Abstr
44
46
  * representing (e.g. `role` in the `iam` service, or
45
47
  * `targetgroup` in the `elasticloadbalancing` service)
46
48
  */
47
- constructor(service?: Service, resourceType?: string);
48
- validate(value: unknown): ArnString<Service>;
49
+ constructor(service?: Service, resourceType?: ResourceType);
50
+ validate(value: unknown): ArnString<Service, ResourceType>;
49
51
  }
50
52
  /**
51
53
  * Create a new {@link ParsedArnValidator} parsing an ARN referring to the
@@ -55,7 +57,7 @@ export declare class ArnValidator<Service extends string = string> extends Abstr
55
57
  * component of the ARN's resource (e.g. `role` in the `iam` service, or
56
58
  * `targetgroup` in the `elasticloadbalancing` service)
57
59
  */
58
- export declare function parseArnFactory<Service extends string = string>(service: Service, resourceType?: string): ParsedArnValidator<Service>;
60
+ export declare function parseArnFactory<Service extends string = string, ResourceType extends string = string>(service: Service, resourceType?: ResourceType): ParsedArnValidator<Service, ResourceType>;
59
61
  /**
60
62
  * Create a new {@link ArnValidator} validating an ARN referring to the
61
63
  * specified `service` (e.g. `iam` or `elasticloadbalancing`).
@@ -64,8 +66,8 @@ export declare function parseArnFactory<Service extends string = string>(service
64
66
  * component of the ARN's resource (e.g. `role` in the `iam` service, or
65
67
  * `targetgroup` in the `elasticloadbalancing` service)
66
68
  */
67
- export declare function arnFactory<Service extends string = string>(service: Service, resourceType?: string): ArnValidator<Service>;
69
+ export declare function arnFactory<Service extends string = string, ResourceType extends string = string>(service: Service, resourceType?: ResourceType): ArnValidator<Service, ResourceType>;
68
70
  /** Validate a string and parse it into into an {@link ParsedArn} */
69
- export declare const parseArn: typeof parseArnFactory & ParsedArnValidator<string>;
71
+ export declare const parseArn: typeof parseArnFactory & ParsedArnValidator<string, string>;
70
72
  /** Validate a ARN (Amazon Resource Name) string */
71
- export declare const arn: typeof arnFactory & ArnValidator<string>;
73
+ export declare const arn: typeof arnFactory & ArnValidator<string, string>;
@@ -1,6 +1,11 @@
1
1
  // extra/arn.ts
2
2
  import { assertValidation } from "../errors.mjs";
3
3
  import { AbstractValidator, makeValidatorFactory } from "../types.mjs";
4
+ function assertComponent(actual, expected, kind) {
5
+ if (expected === void 0)
6
+ return;
7
+ assertValidation(actual === expected, `ARN ${kind} "${actual}" mismatch (expected "${expected}")`);
8
+ }
4
9
  function parse(value, service, type) {
5
10
  assertValidation(typeof value == "string", 'Value is not a "string"');
6
11
  const segments = value.split(":");
@@ -11,22 +16,20 @@ function parse(value, service, type) {
11
16
  assertValidation(!!svc, "Missing service in ARN");
12
17
  assertValidation(!!act, "Missing account ID in ARN");
13
18
  assertValidation(!!res[0], "Missing resource ID in ARN");
14
- if (service !== void 0) {
15
- assertValidation(svc === service, `ARN Service "${svc}" mismatch (expected "${service}")`);
16
- }
17
- const [resArray, resString] = res[0].includes("/") ? [res[0].split("/"), res[0]] : [res, res.join(":")];
18
- assertValidation(!!resArray[0], "Invalid resource ID in ARN");
19
- if (type !== void 0) {
20
- assertValidation(resArray[0] === type, `ARN Resource Type "${resArray[0]}" mismatch (expected "${type}")`);
21
- }
19
+ const [[resType, ...resArray], resString] = res[0].includes("/") ? [res[0].split("/"), res[0]] : [res, res.join(":")];
20
+ assertValidation(!!resType, "Invalid resource ID in ARN");
21
+ assertComponent(svc, service, "Service");
22
+ assertComponent(resType, type, "Resource Type");
22
23
  const arn2 = `arn:${prt}:${svc}:${rgn}:${act}:${resString}`;
23
24
  return {
24
25
  Arn: arn2,
25
26
  Partition: prt,
26
27
  Service: svc,
28
+ // as Service,
27
29
  Region: rgn || "",
28
30
  Account: act,
29
- Resource: resArray
31
+ Resource: [resType, ...resArray]
32
+ // as [ ResourceType, ...string[] ],
30
33
  };
31
34
  }
32
35
  var ParsedArnValidator = class extends AbstractValidator {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/extra/arn.ts"],
4
- "mappings": ";AAAA,SAAS,wBAAwB;AACjC,SAAS,mBAAmB,4BAA4B;AAoBxD,SAAS,MACL,OACA,SACA,MACkB;AACpB,mBAAiB,OAAO,SAAS,UAAU,yBAAyB;AAEpE,QAAM,WAAW,MAAM,MAAM,GAAG;AAEhC,mBAAiB,SAAS,UAAU,GAAG,2BAA2B;AAElE,QAAM,CAAE,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG,GAAI,IAAI;AAE5C,mBAAiB,QAAQ,OAAO,4BAA4B;AAC5D,mBAAiB,CAAC,CAAE,KAAK,0BAA0B;AACnD,mBAAiB,CAAC,CAAE,KAAK,wBAAwB;AACjD,mBAAiB,CAAC,CAAE,KAAK,2BAA2B;AACpD,mBAAiB,CAAC,CAAE,IAAI,CAAC,GAAG,4BAA4B;AAExD,MAAI,YAAY,QAAW;AACzB,qBAAiB,QAAQ,SAAS,gBAAgB,GAAG,yBAAyB,OAAO,IAAI;AAAA,EAC3F;AAEA,QAAM,CAAE,UAAU,SAAU,IAAI,IAAI,CAAC,EAAE,SAAS,GAAG,IACjD,CAAE,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,IAAI,CAAC,CAAE,IAC5B,CAAE,KAAK,IAAI,KAAK,GAAG,CAAE;AAEvB,mBAAiB,CAAC,CAAE,SAAS,CAAC,GAAG,4BAA4B;AAE7D,MAAI,SAAS,QAAW;AACtB,qBAAiB,SAAS,CAAC,MAAM,MAAM,sBAAsB,SAAS,CAAC,CAAC,yBAAyB,IAAI,IAAI;AAAA,EAC3G;AAEA,QAAMA,OAA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S,gBAGZ,SACA,cACyC;AAC3C,SAAO,IAAI,mBAAmB,SAAS,YAAY;AACrD;AAUO,SAAS,WAGZ,SACA,cACmC;AACrC,SAAO,IAAI,aAAa,SAAS,YAAY;AAC/C;AAKO,IAAM,WAAW,qBAAqB,IAAI,mBAAmB,GAAG,eAAe;AAG/E,IAAM,MAAM,qBAAqB,IAAI,aAAa,GAAG,UAAU;",
5
5
  "names": ["arn"]
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "justus",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "A JavaScript validation library, with types!",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -78,8 +78,8 @@
78
78
  "author": "Juit Developers <developers@juit.com>",
79
79
  "license": "Apache-2.0",
80
80
  "devDependencies": {
81
- "@plugjs/build": "^0.4.30",
82
- "@plugjs/tsd": "^0.4.31",
81
+ "@plugjs/build": "^0.4.33",
82
+ "@plugjs/tsd": "^0.4.32",
83
83
  "@types/chai": "^4.3.5",
84
84
  "chai": "^4.3.8",
85
85
  "typescript": "^5.2.2"
package/src/extra/arn.ts CHANGED
@@ -1,29 +1,47 @@
1
1
  import { assertValidation } from '../errors'
2
2
  import { AbstractValidator, makeValidatorFactory } from '../types'
3
3
 
4
+ /* ===== TYPES ============================================================= */
5
+
4
6
  /** The type for a validated _string_ ARN (Amazon Resource Name) */
5
- export type ArnString<Service extends string = string> = string & { __arn: never }
6
- & ( string extends Service ? string : { [ k in `__arn_${Service}`] : never })
7
+ export type ArnString<
8
+ Service extends string = string,
9
+ ResourceType extends string = string,
10
+ > = string & { __arn: never }
11
+ & ( string extends Service ? string : { [ k in `__arn_service_${Service}`] : never })
12
+ & ( string extends ResourceType ? string : { [ k in `__arn_resource_${ResourceType}`] : never })
7
13
 
8
14
  /** The type for a _parsed_ ARN (Amazon Resource Name) */
9
- export interface ParsedArn<Service extends string = string> {
15
+ export interface ParsedArn<
16
+ Service extends string = string,
17
+ ResourceType extends string = string,
18
+ > {
10
19
  /** The full */
11
- Arn: ArnString<Service>,
20
+ Arn: ArnString<Service, ResourceType>,
12
21
  Partition: string,
13
22
  Service: Service,
14
23
  Region: string,
15
24
  Account: string,
16
- Resource: [ string, ...string[] ],
25
+ Resource: [ ResourceType, ...string[] ],
17
26
  }
18
27
 
19
- /* ========================================================================== */
28
+ /* ===== INTERNALS ========================================================== */
29
+
30
+ function assertComponent<T extends string>(
31
+ actual: string,
32
+ expected: T | undefined,
33
+ kind: string,
34
+ ): asserts actual is T {
35
+ if (expected === undefined) return
36
+ assertValidation(actual === expected, `ARN ${kind} "${actual}" mismatch (expected "${expected}")`)
37
+ }
20
38
 
21
39
  /** Validate a string and convert it into into an {@link ParsedArn} */
22
- function parse<Service extends string>(
40
+ function parse<Service extends string, ResourceType extends string>(
23
41
  value: unknown,
24
42
  service?: Service,
25
- type?: string,
26
- ): ParsedArn<Service> {
43
+ type?: ResourceType,
44
+ ): ParsedArn<Service, ResourceType> {
27
45
  assertValidation(typeof value == 'string', 'Value is not a "string"')
28
46
 
29
47
  const segments = value.split(':')
@@ -38,37 +56,34 @@ function parse<Service extends string>(
38
56
  assertValidation(!! act, 'Missing account ID in ARN')
39
57
  assertValidation(!! res[0], 'Missing resource ID in ARN')
40
58
 
41
- if (service !== undefined) {
42
- assertValidation(svc === service, `ARN Service "${svc}" mismatch (expected "${service}")`)
43
- }
44
-
45
- const [ resArray, resString ] = res[0].includes('/') ?
59
+ const [ [ resType, ...resArray ], resString ] = res[0].includes('/') ?
46
60
  [ res[0].split('/'), res[0] ] :
47
61
  [ res, res.join(':') ]
48
62
 
49
- assertValidation(!! resArray[0], 'Invalid resource ID in ARN')
63
+ assertValidation(!! resType, 'Invalid resource ID in ARN')
50
64
 
51
- if (type !== undefined) {
52
- assertValidation(resArray[0] === type, `ARN Resource Type "${resArray[0]}" mismatch (expected "${type}")`)
53
- }
65
+ assertComponent(svc, service, 'Service')
66
+ assertComponent(resType, type, 'Resource Type')
54
67
 
55
68
  const arn = `arn:${prt}:${svc}:${rgn}:${act}:${resString}`
56
69
 
57
70
  return {
58
- Arn: arn as ArnString<Service>,
71
+ Arn: arn as ArnString<Service, ResourceType>,
59
72
  Partition: prt,
60
- Service: svc as Service,
73
+ Service: svc, // as Service,
61
74
  Region: rgn || '',
62
75
  Account: act,
63
- Resource: resArray as [ string, ...string[] ],
76
+ Resource: [ resType, ...resArray ], // as [ ResourceType, ...string[] ],
64
77
  }
65
78
  }
66
79
 
67
- /* ========================================================================== */
80
+ /* ===== VALIDATOR CLASSES ================================================== */
68
81
 
69
82
  /** Validator parsing an ARN (Amazon Resource Name) and returning its components */
70
- export class ParsedArnValidator<Service extends string = string>
71
- extends AbstractValidator<ParsedArn<Service>, string> {
83
+ export class ParsedArnValidator<
84
+ Service extends string = string,
85
+ ResourceType extends string = string,
86
+ > extends AbstractValidator<ParsedArn<Service, ResourceType>, string> {
72
87
  /**
73
88
  * Create a new {@link ParsedArnValidator} instance.
74
89
  *
@@ -78,19 +93,21 @@ export class ParsedArnValidator<Service extends string = string>
78
93
  * representing (e.g. `role` in the `iam` service, or
79
94
  * `targetgroup` in the `elasticloadbalancing` service)
80
95
  */
81
- constructor(service?: Service, resourceType?: string)
82
- constructor(private _service?: Service, private _type?: string) {
96
+ constructor(service?: Service, resourceType?: ResourceType)
97
+ constructor(private _service?: Service, private _type?: ResourceType) {
83
98
  super()
84
99
  }
85
100
 
86
- validate(value: unknown): ParsedArn<Service> {
101
+ validate(value: unknown): ParsedArn<Service, ResourceType> {
87
102
  return parse(value, this._service, this._type)
88
103
  }
89
104
  }
90
105
 
91
106
  /** Validator validating an ARN (Amazon Resource Name) _string_ */
92
- export class ArnValidator<Service extends string = string>
93
- extends AbstractValidator<ArnString<Service>, string> {
107
+ export class ArnValidator<
108
+ Service extends string = string,
109
+ ResourceType extends string = string,
110
+ > extends AbstractValidator<ArnString<Service, ResourceType>, string> {
94
111
  /**
95
112
  * Create a new {@link ArnValidator} instance.
96
113
  *
@@ -100,17 +117,17 @@ export class ArnValidator<Service extends string = string>
100
117
  * representing (e.g. `role` in the `iam` service, or
101
118
  * `targetgroup` in the `elasticloadbalancing` service)
102
119
  */
103
- constructor(service?: Service, resourceType?: string)
104
- constructor(private _service?: Service, private _type?: string) {
120
+ constructor(service?: Service, resourceType?: ResourceType)
121
+ constructor(private _service?: Service, private _type?: ResourceType) {
105
122
  super()
106
123
  }
107
124
 
108
- validate(value: unknown): ArnString<Service> {
125
+ validate(value: unknown): ArnString<Service, ResourceType> {
109
126
  return parse(value, this._service, this._type).Arn
110
127
  }
111
128
  }
112
129
 
113
- /* ========================================================================== */
130
+ /* ===== VALIDATOR FACTORIES ================================================ */
114
131
 
115
132
  /**
116
133
  * Create a new {@link ParsedArnValidator} parsing an ARN referring to the
@@ -120,10 +137,12 @@ export class ArnValidator<Service extends string = string>
120
137
  * component of the ARN's resource (e.g. `role` in the `iam` service, or
121
138
  * `targetgroup` in the `elasticloadbalancing` service)
122
139
  */
123
- export function parseArnFactory<Service extends string = string>(
140
+ export function parseArnFactory<
141
+ Service extends string = string,
142
+ ResourceType extends string = string>(
124
143
  service: Service,
125
- resourceType?: string,
126
- ): ParsedArnValidator<Service> {
144
+ resourceType?: ResourceType,
145
+ ): ParsedArnValidator<Service, ResourceType> {
127
146
  return new ParsedArnValidator(service, resourceType)
128
147
  }
129
148
 
@@ -135,14 +154,16 @@ export function parseArnFactory<Service extends string = string>(
135
154
  * component of the ARN's resource (e.g. `role` in the `iam` service, or
136
155
  * `targetgroup` in the `elasticloadbalancing` service)
137
156
  */
138
- export function arnFactory<Service extends string = string>(
157
+ export function arnFactory<
158
+ Service extends string = string,
159
+ ResourceType extends string = string>(
139
160
  service: Service,
140
- resourceType?: string,
141
- ): ArnValidator<Service> {
161
+ resourceType?: ResourceType,
162
+ ): ArnValidator<Service, ResourceType> {
142
163
  return new ArnValidator(service, resourceType)
143
164
  }
144
165
 
145
- /* ========================================================================== */
166
+ /* ===== VALIDATOR CONSTANTS ================================================ */
146
167
 
147
168
  /** Validate a string and parse it into into an {@link ParsedArn} */
148
169
  export const parseArn = makeValidatorFactory(new ParsedArnValidator(), parseArnFactory)