@distilled.cloud/core 1.0.0-rc.12 → 1.0.0-rc.14
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/lib/api.d.ts +4 -4
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +3 -5
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +3 -5
- package/lib/category.js.map +1 -1
- package/lib/codegen/boolean-string-enums.d.ts +8 -8
- package/lib/codegen/boolean-string-enums.d.ts.map +1 -1
- package/lib/codegen/boolean-string-enums.js +83 -30
- package/lib/codegen/boolean-string-enums.js.map +1 -1
- package/lib/codegen/boolean-string-enums.test.js +130 -2
- package/lib/codegen/boolean-string-enums.test.js.map +1 -1
- package/lib/codegen/cli.d.ts +5 -4
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +12 -9
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/defer-naming.test.d.ts +2 -0
- package/lib/codegen/defer-naming.test.d.ts.map +1 -0
- package/lib/codegen/defer-naming.test.js +105 -0
- package/lib/codegen/defer-naming.test.js.map +1 -0
- package/lib/codegen/emit.d.ts.map +1 -1
- package/lib/codegen/emit.js +1 -3
- package/lib/codegen/emit.js.map +1 -1
- package/lib/codegen/format.d.ts +0 -12
- package/lib/codegen/format.d.ts.map +1 -1
- package/lib/codegen/format.js +10 -6
- package/lib/codegen/format.js.map +1 -1
- package/lib/codegen/generated-at.d.ts +29 -0
- package/lib/codegen/generated-at.d.ts.map +1 -0
- package/lib/codegen/generated-at.js +78 -0
- package/lib/codegen/generated-at.js.map +1 -0
- package/lib/codegen/generated-at.test.d.ts +2 -0
- package/lib/codegen/generated-at.test.d.ts.map +1 -0
- package/lib/codegen/generated-at.test.js +81 -0
- package/lib/codegen/generated-at.test.js.map +1 -0
- package/lib/codegen/generator.d.ts +24 -5
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +69 -80
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/generator.test.d.ts +2 -0
- package/lib/codegen/generator.test.d.ts.map +1 -0
- package/lib/codegen/generator.test.js +121 -0
- package/lib/codegen/generator.test.js.map +1 -0
- package/lib/codegen/graphql-client.d.ts +7 -1
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +264 -148
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql-client.test.js +98 -238
- package/lib/codegen/graphql-client.test.js.map +1 -1
- package/lib/codegen/graphql.d.ts.map +1 -1
- package/lib/codegen/graphql.js +7 -20
- package/lib/codegen/graphql.js.map +1 -1
- package/lib/codegen/model-diff.d.ts +10 -0
- package/lib/codegen/model-diff.d.ts.map +1 -0
- package/lib/codegen/model-diff.js +67 -0
- package/lib/codegen/model-diff.js.map +1 -0
- package/lib/codegen/naming.d.ts.map +1 -1
- package/lib/codegen/naming.js.map +1 -1
- package/lib/codegen/openapi-binary.test.d.ts +2 -0
- package/lib/codegen/openapi-binary.test.d.ts.map +1 -0
- package/lib/codegen/openapi-binary.test.js +67 -0
- package/lib/codegen/openapi-binary.test.js.map +1 -0
- package/lib/codegen/openapi-cli.d.ts +11 -11
- package/lib/codegen/openapi-cli.d.ts.map +1 -1
- package/lib/codegen/openapi-cli.js +26 -51
- package/lib/codegen/openapi-cli.js.map +1 -1
- package/lib/codegen/openapi.d.ts +16 -2
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +56 -39
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.d.ts.map +1 -1
- package/lib/codegen/operations.js.map +1 -1
- package/lib/codegen/pagination.d.ts.map +1 -1
- package/lib/codegen/pagination.js +2 -4
- package/lib/codegen/pagination.js.map +1 -1
- package/lib/codegen/patch-audit.d.ts +84 -0
- package/lib/codegen/patch-audit.d.ts.map +1 -0
- package/lib/codegen/patch-audit.js +366 -0
- package/lib/codegen/patch-audit.js.map +1 -0
- package/lib/codegen/patch-audit.test.d.ts +2 -0
- package/lib/codegen/patch-audit.test.d.ts.map +1 -0
- package/lib/codegen/patch-audit.test.js +141 -0
- package/lib/codegen/patch-audit.test.js.map +1 -0
- package/lib/codegen/patches.d.ts +75 -11
- package/lib/codegen/patches.d.ts.map +1 -1
- package/lib/codegen/patches.js +301 -65
- package/lib/codegen/patches.js.map +1 -1
- package/lib/codegen/patches.test.js +55 -5
- package/lib/codegen/patches.test.js.map +1 -1
- package/lib/codegen/prelude.js +1 -1
- package/lib/codegen/prelude.js.map +1 -1
- package/lib/codegen/proto.d.ts.map +1 -1
- package/lib/codegen/proto.js +2 -4
- package/lib/codegen/proto.js.map +1 -1
- package/lib/codegen/protocol-imports.test.d.ts +2 -0
- package/lib/codegen/protocol-imports.test.d.ts.map +1 -0
- package/lib/codegen/protocol-imports.test.js +36 -0
- package/lib/codegen/protocol-imports.test.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.d.ts +23 -0
- package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -1
- package/lib/codegen/rewrite-operation-ids.js +97 -59
- package/lib/codegen/rewrite-operation-ids.js.map +1 -1
- package/lib/codegen/rewrite-operation-ids.test.js +19 -101
- package/lib/codegen/rewrite-operation-ids.test.js.map +1 -1
- package/lib/codegen/spec-path.d.ts +1 -1
- package/lib/codegen/spec-path.d.ts.map +1 -1
- package/lib/codegen/spec-path.js +1 -1
- package/lib/codegen/spec-path.js.map +1 -1
- package/lib/codegen/untagged-unions.test.d.ts +2 -0
- package/lib/codegen/untagged-unions.test.d.ts.map +1 -0
- package/lib/codegen/untagged-unions.test.js +80 -0
- package/lib/codegen/untagged-unions.test.js.map +1 -0
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts +2 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +9 -4
- package/lib/errors.js.map +1 -1
- package/lib/fixtures/xml/upstream-validator.json +397 -0
- package/lib/graphql.d.ts +292 -205
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +945 -636
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.test.js +135 -764
- package/lib/graphql.test.js.map +1 -1
- package/lib/graphql.types.d.ts +10 -0
- package/lib/graphql.types.d.ts.map +1 -1
- package/lib/graphql.types.js +4 -44
- package/lib/graphql.types.js.map +1 -1
- package/lib/index.d.ts +27 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +27 -0
- package/lib/index.js.map +1 -0
- package/lib/json-patch.d.ts +13 -6
- package/lib/json-patch.d.ts.map +1 -1
- package/lib/json-patch.js +34 -19
- package/lib/json-patch.js.map +1 -1
- package/lib/json-patch.test.d.ts +2 -0
- package/lib/json-patch.test.d.ts.map +1 -0
- package/lib/json-patch.test.js +65 -0
- package/lib/json-patch.test.js.map +1 -0
- package/lib/pagination.d.ts +2 -1
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +28 -30
- package/lib/pagination.js.map +1 -1
- package/lib/pagination.test.d.ts +2 -0
- package/lib/pagination.test.d.ts.map +1 -0
- package/lib/pagination.test.js +131 -0
- package/lib/pagination.test.js.map +1 -0
- package/lib/protocol-http.d.ts +30 -16
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +133 -84
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-http.test.js +141 -1
- package/lib/protocol-http.test.js.map +1 -1
- package/lib/protocol-rest.d.ts +18 -1
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +32 -21
- package/lib/protocol-rest.js.map +1 -1
- package/lib/protocol-rest.test.d.ts +2 -0
- package/lib/protocol-rest.test.d.ts.map +1 -0
- package/lib/protocol-rest.test.js +498 -0
- package/lib/protocol-rest.test.js.map +1 -0
- package/lib/query.d.ts +29 -0
- package/lib/query.d.ts.map +1 -0
- package/lib/query.js +27 -0
- package/lib/query.js.map +1 -0
- package/lib/response-validation.d.ts +67 -0
- package/lib/response-validation.d.ts.map +1 -0
- package/lib/response-validation.js +76 -0
- package/lib/response-validation.js.map +1 -0
- package/lib/response-validation.test.d.ts +2 -0
- package/lib/response-validation.test.d.ts.map +1 -0
- package/lib/response-validation.test.js +72 -0
- package/lib/response-validation.test.js.map +1 -0
- package/lib/retry-after.d.ts.map +1 -1
- package/lib/retry-after.js +1 -1
- package/lib/retry-after.js.map +1 -1
- package/lib/retry-after.test.d.ts +2 -0
- package/lib/retry-after.test.d.ts.map +1 -0
- package/lib/retry-after.test.js +204 -0
- package/lib/retry-after.test.js.map +1 -0
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -2
- package/lib/retry.js.map +1 -1
- package/lib/retry.test.d.ts +2 -0
- package/lib/retry.test.d.ts.map +1 -0
- package/lib/retry.test.js +407 -0
- package/lib/retry.test.js.map +1 -0
- package/lib/sdks.test.d.ts +2 -0
- package/lib/sdks.test.d.ts.map +1 -0
- package/lib/sdks.test.js +76 -0
- package/lib/sdks.test.js.map +1 -0
- package/lib/testing.d.ts +39 -0
- package/lib/testing.d.ts.map +1 -0
- package/lib/testing.js +41 -0
- package/lib/testing.js.map +1 -0
- package/lib/trait.d.ts +29 -9
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +8 -0
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts +44 -0
- package/lib/xml.d.ts.map +1 -0
- package/lib/xml.js +311 -0
- package/lib/xml.js.map +1 -0
- package/lib/xml.test.d.ts +2 -0
- package/lib/xml.test.d.ts.map +1 -0
- package/lib/xml.test.js +210 -0
- package/lib/xml.test.js.map +1 -0
- package/package.json +8 -11
- package/src/api.ts +38 -55
- package/src/category.ts +21 -50
- package/src/codegen/boolean-string-enums.test.ts +148 -17
- package/src/codegen/boolean-string-enums.ts +81 -32
- package/src/codegen/cli.ts +29 -47
- package/src/codegen/defer-naming.test.ts +113 -0
- package/src/codegen/emit.ts +2 -5
- package/src/codegen/format.ts +12 -10
- package/src/codegen/generated-at.test.ts +89 -0
- package/src/codegen/generated-at.ts +88 -0
- package/src/codegen/generator.test.ts +137 -0
- package/src/codegen/generator.ts +132 -193
- package/src/codegen/graphql-client.test.ts +100 -297
- package/src/codegen/graphql-client.ts +302 -210
- package/src/codegen/graphql.ts +22 -94
- package/src/codegen/model-diff.ts +67 -0
- package/src/codegen/naming.ts +1 -2
- package/src/codegen/openapi-binary.test.ts +91 -0
- package/src/codegen/openapi-cli.ts +38 -79
- package/src/codegen/openapi.ts +98 -133
- package/src/codegen/operations.ts +2 -5
- package/src/codegen/pagination.ts +4 -11
- package/src/codegen/patch-audit.test.ts +160 -0
- package/src/codegen/patch-audit.ts +480 -0
- package/src/codegen/patches.test.ts +73 -15
- package/src/codegen/patches.ts +389 -99
- package/src/codegen/prelude.ts +1 -1
- package/src/codegen/proto.ts +18 -54
- package/src/codegen/protocol-imports.test.ts +39 -0
- package/src/codegen/rewrite-operation-ids.test.ts +23 -114
- package/src/codegen/rewrite-operation-ids.ts +111 -98
- package/src/codegen/spec-path.ts +3 -6
- package/src/codegen/untagged-unions.test.ts +85 -0
- package/src/error-category.ts +5 -17
- package/src/errors.ts +18 -30
- package/src/fixtures/xml/upstream-validator.json +397 -0
- package/src/graphql.test.ts +173 -949
- package/src/graphql.ts +1468 -1186
- package/src/graphql.types.ts +78 -164
- package/src/index.ts +26 -0
- package/src/json-patch.test.ts +77 -0
- package/src/json-patch.ts +54 -60
- package/src/pagination.test.ts +169 -0
- package/src/pagination.ts +46 -103
- package/src/protocol-http.test.ts +178 -9
- package/src/protocol-http.ts +174 -163
- package/src/protocol-rest.test.ts +703 -0
- package/src/protocol-rest.ts +76 -65
- package/src/query.ts +39 -0
- package/src/response-validation.test.ts +89 -0
- package/src/response-validation.ts +107 -0
- package/src/retry-after.test.ts +267 -0
- package/src/retry-after.ts +4 -10
- package/src/retry.test.ts +566 -0
- package/src/retry.ts +6 -21
- package/src/sdks.test.ts +87 -0
- package/src/testing.ts +72 -0
- package/src/trait.ts +48 -63
- package/src/xml.test.ts +251 -0
- package/src/xml.ts +323 -0
- package/lib/graphql.fixture.d.ts +0 -249
- package/lib/graphql.fixture.d.ts.map +0 -1
- package/lib/graphql.fixture.js +0 -240
- package/lib/graphql.fixture.js.map +0 -1
- package/src/graphql.fixture.ts +0 -371
|
@@ -542,9 +542,7 @@ const pascalToken = (raw: string): string => {
|
|
|
542
542
|
export const singularize = (raw: string): string => {
|
|
543
543
|
const lower = raw.toLowerCase();
|
|
544
544
|
const keepCase = (s: string): string =>
|
|
545
|
-
raw[0] === raw[0]?.toUpperCase()
|
|
546
|
-
? s.charAt(0).toUpperCase() + s.slice(1)
|
|
547
|
-
: s;
|
|
545
|
+
raw[0] === raw[0]?.toUpperCase() ? s.charAt(0).toUpperCase() + s.slice(1) : s;
|
|
548
546
|
const alias = TOKEN_ALIAS[lower];
|
|
549
547
|
if (alias !== undefined) {
|
|
550
548
|
return alias.endsWith("s") ? alias.slice(0, -1) : alias;
|
|
@@ -590,15 +588,11 @@ const splitIdent = (s: string): string[] => {
|
|
|
590
588
|
return parts;
|
|
591
589
|
};
|
|
592
590
|
|
|
593
|
-
const isStrongVerb = (raw: string): boolean =>
|
|
594
|
-
|
|
595
|
-
const
|
|
596
|
-
TRAILING_VERBS.has(raw.toLowerCase());
|
|
597
|
-
const isWeakLeadingVerb = (raw: string): boolean =>
|
|
598
|
-
WEAK_LEADING_VERBS.has(raw.toLowerCase());
|
|
591
|
+
const isStrongVerb = (raw: string): boolean => STRONG_VERBS.has(raw.toLowerCase());
|
|
592
|
+
const isTrailingVerb = (raw: string): boolean => TRAILING_VERBS.has(raw.toLowerCase());
|
|
593
|
+
const isWeakLeadingVerb = (raw: string): boolean => WEAK_LEADING_VERBS.has(raw.toLowerCase());
|
|
599
594
|
|
|
600
|
-
const alias = (raw: string): string =>
|
|
601
|
-
VERB_ALIAS[raw.toLowerCase()] ?? raw.toLowerCase();
|
|
595
|
+
const alias = (raw: string): string => VERB_ALIAS[raw.toLowerCase()] ?? raw.toLowerCase();
|
|
602
596
|
|
|
603
597
|
/** `version`-like tokens (`V1`, `v1beta1`, `V2`) are never nouns to singularise. */
|
|
604
598
|
const isVersionToken = (raw: string): boolean => /^[vV]\d/.test(raw);
|
|
@@ -611,11 +605,7 @@ const MODIFIERS = new Set(["partial", "bulk", "batch", "all", "many"]);
|
|
|
611
605
|
* is singularised, and only for non-list verbs (`getApp`, `listApps`,
|
|
612
606
|
* `listMachineEvents`). Parent tokens keep their spelling.
|
|
613
607
|
*/
|
|
614
|
-
const assemble = (
|
|
615
|
-
verb: string,
|
|
616
|
-
nouns: readonly string[],
|
|
617
|
-
tail: readonly string[] = [],
|
|
618
|
-
): string => {
|
|
608
|
+
const assemble = (verb: string, nouns: readonly string[], tail: readonly string[] = []): string => {
|
|
619
609
|
// `App_Certificates_acme_create`: the qualifier trails the resource in
|
|
620
610
|
// the id but reads better in front of it (`createAppAcmeCertificate`).
|
|
621
611
|
let ordered = [...nouns];
|
|
@@ -673,13 +663,8 @@ export const toVerbNoun = (operationId: string): string => {
|
|
|
673
663
|
if (verbSeg > 0) {
|
|
674
664
|
const head = segments.slice(0, verbSeg).flatMap(splitIdent);
|
|
675
665
|
const [verb, ...objectHere] = splitIdent(segments[verbSeg]!);
|
|
676
|
-
const object = [
|
|
677
|
-
|
|
678
|
-
...segments.slice(verbSeg + 1).flatMap(splitIdent),
|
|
679
|
-
];
|
|
680
|
-
const compound = object.some(
|
|
681
|
-
(t) => isStrongVerb(t) || /^(or|and)$/i.test(t),
|
|
682
|
-
);
|
|
666
|
+
const object = [...objectHere, ...segments.slice(verbSeg + 1).flatMap(splitIdent)];
|
|
667
|
+
const compound = object.some((t) => isStrongVerb(t) || /^(or|and)$/i.test(t));
|
|
683
668
|
if (!compound) return assemble(alias(verb!), head, object);
|
|
684
669
|
}
|
|
685
670
|
return lowerFirst(trimmed);
|
|
@@ -700,8 +685,7 @@ export const toVerbNoun = (operationId: string): string => {
|
|
|
700
685
|
// `IndexCreate`, `IndexDocument` all name the index entity.
|
|
701
686
|
const strong = (raw: string) => !isIndexVerb(raw) && isStrongVerb(raw);
|
|
702
687
|
const trailing = (raw: string) => !isIndexVerb(raw) && isTrailingVerb(raw);
|
|
703
|
-
const weakLeading = (raw: string) =>
|
|
704
|
-
!isIndexVerb(raw) && isWeakLeadingVerb(raw);
|
|
688
|
+
const weakLeading = (raw: string) => !isIndexVerb(raw) && isWeakLeadingVerb(raw);
|
|
705
689
|
|
|
706
690
|
if (strong(first)) {
|
|
707
691
|
return alias(first) + parts.slice(1).map(pascalToken).join("");
|
|
@@ -733,29 +717,15 @@ export const toVerbNoun = (operationId: string): string => {
|
|
|
733
717
|
const nouns = parts.slice(0, -1);
|
|
734
718
|
if (nouns.slice(1).some(strong)) return lowerFirst(trimmed);
|
|
735
719
|
const modifier = nouns.at(-1);
|
|
736
|
-
if (
|
|
737
|
-
nouns.length > 1 &&
|
|
738
|
-
modifier !== undefined &&
|
|
739
|
-
MODIFIERS.has(modifier.toLowerCase())
|
|
740
|
-
) {
|
|
720
|
+
if (nouns.length > 1 && modifier !== undefined && MODIFIERS.has(modifier.toLowerCase())) {
|
|
741
721
|
return assemble(alias(last), nouns.slice(0, -1), [modifier]);
|
|
742
722
|
}
|
|
743
723
|
return assemble(alias(last), nouns);
|
|
744
724
|
};
|
|
745
725
|
|
|
746
|
-
const COMPANION_SUFFIXES = [
|
|
747
|
-
"Request",
|
|
748
|
-
"Response",
|
|
749
|
-
"Input",
|
|
750
|
-
"Output",
|
|
751
|
-
"Error",
|
|
752
|
-
"Result",
|
|
753
|
-
] as const;
|
|
726
|
+
const COMPANION_SUFFIXES = ["Request", "Response", "Input", "Output", "Error", "Result"] as const;
|
|
754
727
|
|
|
755
|
-
const remapTargets = (
|
|
756
|
-
node: unknown,
|
|
757
|
-
mapping: ReadonlyMap<string, string>,
|
|
758
|
-
): unknown => {
|
|
728
|
+
const remapTargets = (node: unknown, mapping: ReadonlyMap<string, string>): unknown => {
|
|
759
729
|
if (Array.isArray(node)) {
|
|
760
730
|
return node.map((item) => remapTargets(item, mapping));
|
|
761
731
|
}
|
|
@@ -771,6 +741,53 @@ const remapTargets = (
|
|
|
771
741
|
return out;
|
|
772
742
|
};
|
|
773
743
|
|
|
744
|
+
/**
|
|
745
|
+
* `metadata` key of a model whose final names are deferred (the OpenAPI
|
|
746
|
+
* converter's `deferNaming`): upstream shape id → final shape id.
|
|
747
|
+
* `finalizeConvert` applies it after the Smithy patches and removes it.
|
|
748
|
+
*/
|
|
749
|
+
export const RENAME_METADATA_KEY = "distilled.rename";
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Apply and remove a model's deferred rename ({@link RENAME_METADATA_KEY}).
|
|
753
|
+
* Returns how many shapes it renamed.
|
|
754
|
+
*/
|
|
755
|
+
export const applyDeferredRename = (model: {
|
|
756
|
+
metadata?: Record<string, any>;
|
|
757
|
+
shapes?: Record<string, any>;
|
|
758
|
+
}): number => {
|
|
759
|
+
const rename = model.metadata?.[RENAME_METADATA_KEY] as Record<string, string> | undefined;
|
|
760
|
+
if (rename === undefined) return 0;
|
|
761
|
+
delete model.metadata![RENAME_METADATA_KEY];
|
|
762
|
+
const shapes = model.shapes ?? {};
|
|
763
|
+
// A patch may have moved or removed a shape; only rename what is there.
|
|
764
|
+
const mapping = new Map(Object.entries(rename).filter(([from]) => from in shapes));
|
|
765
|
+
if (mapping.size > 0) renameShapes(model, mapping);
|
|
766
|
+
return mapping.size;
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Rename shapes by id and rewrite every `target` that points at a renamed
|
|
771
|
+
* one, keeping the model's shape order. All renames happen at once, so a
|
|
772
|
+
* mapping may swap names. Throws when a new id is already taken by a shape
|
|
773
|
+
* that keeps its name, or two shapes would land on one id.
|
|
774
|
+
*/
|
|
775
|
+
export const renameShapes = (
|
|
776
|
+
model: { shapes?: Record<string, any> },
|
|
777
|
+
mapping: ReadonlyMap<string, string>,
|
|
778
|
+
): void => {
|
|
779
|
+
const shapes = model.shapes ?? {};
|
|
780
|
+
const nextShapes: Record<string, any> = {};
|
|
781
|
+
for (const [id, def] of Object.entries(shapes)) {
|
|
782
|
+
const newId = mapping.get(id) ?? id;
|
|
783
|
+
if (Object.prototype.hasOwnProperty.call(nextShapes, newId)) {
|
|
784
|
+
throw new Error(`renaming ${id} → ${newId}: that shape id is already taken`);
|
|
785
|
+
}
|
|
786
|
+
nextShapes[newId] = remapTargets(def, mapping);
|
|
787
|
+
}
|
|
788
|
+
model.shapes = nextShapes;
|
|
789
|
+
};
|
|
790
|
+
|
|
774
791
|
/** Version prefixes and API roots that carry no meaning in a name. */
|
|
775
792
|
const NOISE_SEGMENTS = new Set(["api", "rest", "v", "public"]);
|
|
776
793
|
const isNoiseSegment = (seg: string): boolean => {
|
|
@@ -778,8 +795,7 @@ const isNoiseSegment = (seg: string): boolean => {
|
|
|
778
795
|
return NOISE_SEGMENTS.has(lower) || /^v\d+(\.\d+)*$/.test(lower);
|
|
779
796
|
};
|
|
780
797
|
|
|
781
|
-
const HTTP_METHOD_ID =
|
|
782
|
-
/^(get|post|put|patch|delete|head|options)(?=$|[-_./]|[A-Z0-9])/i;
|
|
798
|
+
const HTTP_METHOD_ID = /^(get|post|put|patch|delete|head|options)(?=$|[-_./]|[A-Z0-9])/i;
|
|
783
799
|
|
|
784
800
|
/**
|
|
785
801
|
* Whether an OpenAPI `operationId` carries no information beyond the
|
|
@@ -832,22 +848,16 @@ export const isVerbatimRouteId = (
|
|
|
832
848
|
// `ByAppIdPromote`: a whole parameter, then route literals.
|
|
833
849
|
return byClauses.every((c) => {
|
|
834
850
|
const lengths = [
|
|
835
|
-
...params
|
|
836
|
-
.filter((p) => p.every((t, i) => t === c[i]))
|
|
837
|
-
.map((p) => p.length),
|
|
851
|
+
...params.filter((p) => p.every((t, i) => t === c[i])).map((p) => p.length),
|
|
838
852
|
...(c[0] === "id" ? [1] : []),
|
|
839
853
|
];
|
|
840
|
-
return lengths.some(
|
|
841
|
-
(n) => n <= c.length && c.slice(n).every((t) => literal.has(t)),
|
|
842
|
-
);
|
|
854
|
+
return lengths.some((n) => n <= c.length && c.slice(n).every((t) => literal.has(t)));
|
|
843
855
|
});
|
|
844
856
|
};
|
|
845
857
|
|
|
846
858
|
/** `activity/get-feeds` → `get-feeds`: a tag prefix is not part of the name. */
|
|
847
859
|
const stripTag = (operationId: string): string =>
|
|
848
|
-
operationId.includes("/")
|
|
849
|
-
? operationId.slice(operationId.lastIndexOf("/") + 1)
|
|
850
|
-
: operationId;
|
|
860
|
+
operationId.includes("/") ? operationId.slice(operationId.lastIndexOf("/") + 1) : operationId;
|
|
851
861
|
|
|
852
862
|
export const isMechanicalOperationId = (
|
|
853
863
|
operationId: string | undefined,
|
|
@@ -928,10 +938,7 @@ export interface PathNamingHints {
|
|
|
928
938
|
readonly verbatim?: boolean;
|
|
929
939
|
}
|
|
930
940
|
|
|
931
|
-
export const pathToVerbNoun = (
|
|
932
|
-
ctx: OperationIdContext,
|
|
933
|
-
hints: PathNamingHints = {},
|
|
934
|
-
): string => {
|
|
941
|
+
export const pathToVerbNoun = (ctx: OperationIdContext, hints: PathNamingHints = {}): string => {
|
|
935
942
|
const method = ctx.method.toLowerCase();
|
|
936
943
|
const segments = ctx.path.split(/[?#]/)[0]!.split("/").filter(Boolean);
|
|
937
944
|
const literal: string[] = [];
|
|
@@ -980,10 +987,7 @@ export const pathToVerbNoun = (
|
|
|
980
987
|
const matchParam = (at: number): number => {
|
|
981
988
|
let best = 0;
|
|
982
989
|
for (const prm of params) {
|
|
983
|
-
if (
|
|
984
|
-
prm.length > best &&
|
|
985
|
-
prm.every((t, k) => raw[at + k]?.toLowerCase() === t)
|
|
986
|
-
) {
|
|
990
|
+
if (prm.length > best && prm.every((t, k) => raw[at + k]?.toLowerCase() === t)) {
|
|
987
991
|
best = prm.length;
|
|
988
992
|
}
|
|
989
993
|
}
|
|
@@ -1015,18 +1019,14 @@ export const pathToVerbNoun = (
|
|
|
1015
1019
|
// on `/custom-domains/{domain}`) it is the literal.
|
|
1016
1020
|
n = matchParam(i);
|
|
1017
1021
|
skip = n;
|
|
1018
|
-
const echoes = raw
|
|
1019
|
-
.slice(i, i + n)
|
|
1020
|
-
.some((x) => literal.has(x.toLowerCase()));
|
|
1022
|
+
const echoes = raw.slice(i, i + n).some((x) => literal.has(x.toLowerCase()));
|
|
1021
1023
|
const prev = tokens.at(-1)?.toLowerCase();
|
|
1022
1024
|
const prevIsResource =
|
|
1023
1025
|
prev !== undefined &&
|
|
1024
1026
|
raw
|
|
1025
1027
|
.slice(i, i + n)
|
|
1026
1028
|
.some(
|
|
1027
|
-
(x) =>
|
|
1028
|
-
singularize(prev) === singularize(x.toLowerCase()) ||
|
|
1029
|
-
prev === x.toLowerCase(),
|
|
1029
|
+
(x) => singularize(prev) === singularize(x.toLowerCase()) || prev === x.toLowerCase(),
|
|
1030
1030
|
);
|
|
1031
1031
|
if (echoes && !prevIsResource) n = 0;
|
|
1032
1032
|
}
|
|
@@ -1079,15 +1079,9 @@ export const pathToVerbNoun = (
|
|
|
1079
1079
|
const [verb, ...rest] = lastTokens;
|
|
1080
1080
|
const parents = tokens.slice(0, -1);
|
|
1081
1081
|
const nouns = parents.map((t, i) =>
|
|
1082
|
-
i === parents.length - 1
|
|
1083
|
-
? t.map((x, j) => (j === t.length - 1 ? singularize(x) : x))
|
|
1084
|
-
: t,
|
|
1085
|
-
);
|
|
1086
|
-
return (
|
|
1087
|
-
alias(verb!) +
|
|
1088
|
-
nouns.flat().map(pascalToken).join("") +
|
|
1089
|
-
rest.map(pascalToken).join("")
|
|
1082
|
+
i === parents.length - 1 ? t.map((x, j) => (j === t.length - 1 ? singularize(x) : x)) : t,
|
|
1090
1083
|
);
|
|
1084
|
+
return alias(verb!) + nouns.flat().map(pascalToken).join("") + rest.map(pascalToken).join("");
|
|
1091
1085
|
}
|
|
1092
1086
|
|
|
1093
1087
|
// GET is `list` only when the body is known to be a collection; an
|
|
@@ -1137,22 +1131,48 @@ export const verbNounSmithyModel = (model: {
|
|
|
1137
1131
|
}): { renamed: number; collisions: string[] } => {
|
|
1138
1132
|
const shapes = model.shapes ?? {};
|
|
1139
1133
|
const mapping = new Map<string, string>();
|
|
1134
|
+
const mappedTo = new Set<string>();
|
|
1140
1135
|
const collisions: string[] = [];
|
|
1141
|
-
const
|
|
1136
|
+
const ids = Object.keys(shapes);
|
|
1137
|
+
const taken = new Set(ids);
|
|
1138
|
+
const order = new Map(ids.map((id, i) => [id, i]));
|
|
1142
1139
|
|
|
1143
|
-
const
|
|
1144
|
-
([, def]) => def?.type === "operation",
|
|
1145
|
-
);
|
|
1146
|
-
const opLocals = new Set<string>();
|
|
1147
|
-
for (const [id] of ops) {
|
|
1140
|
+
const split = (id: string): [ns: string, local: string] => {
|
|
1148
1141
|
const hash = id.indexOf("#");
|
|
1149
|
-
|
|
1142
|
+
return hash >= 0 ? [id.slice(0, hash), id.slice(hash + 1)] : ["", id];
|
|
1143
|
+
};
|
|
1144
|
+
// Local names per namespace in code-unit order, so the shapes whose name
|
|
1145
|
+
// starts with an operation's are one contiguous run (found by binary
|
|
1146
|
+
// search) instead of a scan of every shape per operation.
|
|
1147
|
+
const localsByNs = new Map<string, string[]>();
|
|
1148
|
+
for (const id of ids) {
|
|
1149
|
+
const [ns, local] = split(id);
|
|
1150
|
+
const list = localsByNs.get(ns);
|
|
1151
|
+
if (list) list.push(local);
|
|
1152
|
+
else localsByNs.set(ns, [local]);
|
|
1150
1153
|
}
|
|
1154
|
+
for (const list of localsByNs.values()) list.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
1155
|
+
const withPrefix = (ns: string, prefix: string): string[] => {
|
|
1156
|
+
const list = localsByNs.get(ns) ?? [];
|
|
1157
|
+
let lo = 0;
|
|
1158
|
+
let hi = list.length;
|
|
1159
|
+
while (lo < hi) {
|
|
1160
|
+
const mid = (lo + hi) >>> 1;
|
|
1161
|
+
if (list[mid]! < prefix) lo = mid + 1;
|
|
1162
|
+
else hi = mid;
|
|
1163
|
+
}
|
|
1164
|
+
const out: string[] = [];
|
|
1165
|
+
for (let i = lo; i < list.length && list[i]!.startsWith(prefix); i++) {
|
|
1166
|
+
out.push(ns ? `${ns}#${list[i]}` : list[i]!);
|
|
1167
|
+
}
|
|
1168
|
+
// Model order, as a scan of every shape would visit them.
|
|
1169
|
+
return out.sort((a, b) => order.get(a)! - order.get(b)!);
|
|
1170
|
+
};
|
|
1171
|
+
|
|
1172
|
+
const ops = Object.entries(shapes).filter(([, def]) => def?.type === "operation");
|
|
1151
1173
|
|
|
1152
1174
|
for (const [id] of ops) {
|
|
1153
|
-
const
|
|
1154
|
-
const ns = hash >= 0 ? id.slice(0, hash) : "";
|
|
1155
|
-
const local = hash >= 0 ? id.slice(hash + 1) : id;
|
|
1175
|
+
const [ns, local] = split(id);
|
|
1156
1176
|
const camel = toVerbNoun(local);
|
|
1157
1177
|
const nextLocal = camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
1158
1178
|
if (nextLocal === local) continue;
|
|
@@ -1161,24 +1181,21 @@ export const verbNounSmithyModel = (model: {
|
|
|
1161
1181
|
collisions.push(`${local} → ${nextLocal}`);
|
|
1162
1182
|
continue;
|
|
1163
1183
|
}
|
|
1164
|
-
if (
|
|
1184
|
+
if (mappedTo.has(nextId)) {
|
|
1165
1185
|
collisions.push(`${local} → ${nextLocal}`);
|
|
1166
1186
|
continue;
|
|
1167
1187
|
}
|
|
1168
1188
|
mapping.set(id, nextId);
|
|
1189
|
+
mappedTo.add(nextId);
|
|
1169
1190
|
taken.add(nextId);
|
|
1170
1191
|
|
|
1171
1192
|
// Companions: `<Op>Request`, `<Op>Response…`, and anything derived
|
|
1172
1193
|
// from them by the converters' `${opName}Request${Member}` naming.
|
|
1173
1194
|
// Skip prefixes that are themselves another operation's name
|
|
1174
1195
|
// (`Get` vs `GetObject`) — only exact suffix matches count there.
|
|
1175
|
-
for (const candidate of
|
|
1196
|
+
for (const candidate of withPrefix(ns, local)) {
|
|
1176
1197
|
if (candidate === id || mapping.has(candidate)) continue;
|
|
1177
|
-
const
|
|
1178
|
-
const cNs = cHash >= 0 ? candidate.slice(0, cHash) : "";
|
|
1179
|
-
const cLocal = cHash >= 0 ? candidate.slice(cHash + 1) : candidate;
|
|
1180
|
-
if (cNs !== ns || !cLocal.startsWith(local)) continue;
|
|
1181
|
-
const tail = cLocal.slice(local.length);
|
|
1198
|
+
const tail = split(candidate)[1].slice(local.length);
|
|
1182
1199
|
if (tail === "") continue;
|
|
1183
1200
|
const suffixed = COMPANION_SUFFIXES.some((s) => tail.startsWith(s));
|
|
1184
1201
|
if (!suffixed) continue;
|
|
@@ -1187,18 +1204,14 @@ export const verbNounSmithyModel = (model: {
|
|
|
1187
1204
|
const to = ns ? `${ns}#${nextLocal}${tail}` : `${nextLocal}${tail}`;
|
|
1188
1205
|
if (taken.has(to)) continue;
|
|
1189
1206
|
mapping.set(candidate, to);
|
|
1207
|
+
mappedTo.add(to);
|
|
1190
1208
|
taken.add(to);
|
|
1191
1209
|
}
|
|
1192
1210
|
}
|
|
1193
1211
|
|
|
1194
1212
|
if (mapping.size === 0) return { renamed: 0, collisions };
|
|
1195
1213
|
|
|
1196
|
-
|
|
1197
|
-
for (const [id, def] of Object.entries(shapes)) {
|
|
1198
|
-
const newId = mapping.get(id) ?? id;
|
|
1199
|
-
nextShapes[newId] = remapTargets(def, mapping);
|
|
1200
|
-
}
|
|
1201
|
-
model.shapes = nextShapes;
|
|
1214
|
+
renameShapes(model, mapping);
|
|
1202
1215
|
return {
|
|
1203
1216
|
renamed: ops.filter(([opId]) => mapping.has(opId)).length,
|
|
1204
1217
|
collisions,
|
package/src/codegen/spec-path.ts
CHANGED
|
@@ -44,8 +44,7 @@ export const LOCAL_DIR = path.join("specs", ".local");
|
|
|
44
44
|
export const mirrorRepositoryName = (pkg: string) => `spec-mirror-${pkg}`;
|
|
45
45
|
|
|
46
46
|
/** Whether this process reads specs from `specs/.local`. */
|
|
47
|
-
export const isLocalSpecs = (): boolean =>
|
|
48
|
-
(process.env[LOCAL_ENV] ?? "").trim() !== "";
|
|
47
|
+
export const isLocalSpecs = (): boolean => (process.env[LOCAL_ENV] ?? "").trim() !== "";
|
|
49
48
|
|
|
50
49
|
let announced = false;
|
|
51
50
|
|
|
@@ -73,7 +72,7 @@ const tailWithinSpecs = (specPath: string): string | undefined => {
|
|
|
73
72
|
/**
|
|
74
73
|
* Resolve a package-relative spec path to an absolute one.
|
|
75
74
|
*
|
|
76
|
-
* @param root absolute package root (`path.resolve(import.meta.
|
|
75
|
+
* @param root absolute package root (`path.resolve(import.meta.dirname, "..")`)
|
|
77
76
|
* @param specPath the production path, relative to `root` (or absolute)
|
|
78
77
|
*/
|
|
79
78
|
export const resolveSpecPath = (root: string, specPath: string): string => {
|
|
@@ -94,9 +93,7 @@ export const resolveSpecPath = (root: string, specPath: string): string => {
|
|
|
94
93
|
// stderr, not stdout: generate-all captures stdout per package and only
|
|
95
94
|
// prints it on failure, and this is exactly the line you need to see on
|
|
96
95
|
// a run that succeeded against the wrong specs.
|
|
97
|
-
console.error(
|
|
98
|
-
`⚠ ${LOCAL_ENV} — reading specs from ${LOCAL_DIR}, not the mirror submodule.`,
|
|
99
|
-
);
|
|
96
|
+
console.error(`⚠ ${LOCAL_ENV} — reading specs from ${LOCAL_DIR}, not the mirror submodule.`);
|
|
100
97
|
}
|
|
101
98
|
|
|
102
99
|
const local = path.join(root, LOCAL_DIR, "specs", tail);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { generateService } from "./generator.ts";
|
|
3
|
+
|
|
4
|
+
const model = {
|
|
5
|
+
smithy: "2.0",
|
|
6
|
+
shapes: {
|
|
7
|
+
"com.example#Service": {
|
|
8
|
+
type: "service",
|
|
9
|
+
version: "1",
|
|
10
|
+
operations: [{ target: "com.example#GetValue" }],
|
|
11
|
+
},
|
|
12
|
+
"com.example#GetValue": {
|
|
13
|
+
type: "operation",
|
|
14
|
+
input: { target: "com.example#Input" },
|
|
15
|
+
output: { target: "com.example#Output" },
|
|
16
|
+
traits: {
|
|
17
|
+
"smithy.api#http": { method: "GET", uri: "/value", code: 200 },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
"com.example#Input": { type: "structure", members: {} },
|
|
21
|
+
"com.example#Output": {
|
|
22
|
+
type: "structure",
|
|
23
|
+
members: { value: { target: "com.example#Choice" } },
|
|
24
|
+
},
|
|
25
|
+
"com.example#Choice": {
|
|
26
|
+
type: "union",
|
|
27
|
+
members: {
|
|
28
|
+
boolean: { target: "smithy.api#Boolean" },
|
|
29
|
+
paths: { target: "com.example#Paths" },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
"com.example#Paths": {
|
|
33
|
+
type: "list",
|
|
34
|
+
member: { target: "smithy.api#String" },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const operationDecl = {
|
|
40
|
+
contextType: "ExampleOpContext",
|
|
41
|
+
commonErrorType: "ExampleOpError",
|
|
42
|
+
commonErrorClasses: [],
|
|
43
|
+
protocol: "ExampleProtocol",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
test("untagged unions validate primitive and collection alternatives", () => {
|
|
47
|
+
const { code } = generateService(model, {
|
|
48
|
+
unionStyle: "untagged",
|
|
49
|
+
operationDecl,
|
|
50
|
+
});
|
|
51
|
+
expect(code).toContain("export type Choice = boolean | Paths;");
|
|
52
|
+
expect(code).toContain("S.Union([S.Boolean, Paths])");
|
|
53
|
+
expect(code).not.toContain("S.Unknown as any as S.Schema<Choice>");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("untagged unions honor the configured schema type", () => {
|
|
57
|
+
for (const schemaType of ["Schema", "Codec"] as const) {
|
|
58
|
+
const { code } = generateService(model, {
|
|
59
|
+
unionStyle: "untagged",
|
|
60
|
+
schemaType,
|
|
61
|
+
operationDecl,
|
|
62
|
+
});
|
|
63
|
+
expect(code).toContain(`S.Union([S.Boolean, Paths]) as any as S.${schemaType}<Choice>`);
|
|
64
|
+
expect(code).toContain(`S.Array(S.String) as any as S.${schemaType}<Paths>`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("omitting a retry policy emits neither a retry import nor an operation setting", () => {
|
|
69
|
+
const { code } = generateService(model, {
|
|
70
|
+
unionStyle: "untagged",
|
|
71
|
+
operationDecl,
|
|
72
|
+
});
|
|
73
|
+
expect(code).not.toContain("../retry.ts");
|
|
74
|
+
expect(code).not.toContain("retry:");
|
|
75
|
+
expect(code).not.toContain('import { } from "../errors.ts"');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("an explicit retry policy retains the existing import and operation setting", () => {
|
|
79
|
+
const { code } = generateService(model, {
|
|
80
|
+
unionStyle: "untagged",
|
|
81
|
+
operationDecl: { ...operationDecl, retry: "Retry.Retry" },
|
|
82
|
+
});
|
|
83
|
+
expect(code).toContain('import * as Retry from "../retry.ts"');
|
|
84
|
+
expect(code).toContain("retry: Retry.Retry");
|
|
85
|
+
});
|
package/src/error-category.ts
CHANGED
|
@@ -26,9 +26,7 @@ export const withCategory =
|
|
|
26
26
|
return Mixed as any;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
export type AllKeys<E> = E extends { [categoriesKey]: infer Q }
|
|
30
|
-
? keyof Q
|
|
31
|
-
: never;
|
|
29
|
+
export type AllKeys<E> = E extends { [categoriesKey]: infer Q } ? keyof Q : never;
|
|
32
30
|
|
|
33
31
|
export type ExtractAll<E, Cats extends PropertyKey> = Cats extends any
|
|
34
32
|
? Extract<E, { [categoriesKey]: { [K in Cats]: any } }>
|
|
@@ -40,9 +38,7 @@ export type ExtractAll<E, Cats extends PropertyKey> = Cats extends any
|
|
|
40
38
|
*/
|
|
41
39
|
export const hasCategory =
|
|
42
40
|
<const Cat extends PropertyKey>(category: Cat) =>
|
|
43
|
-
(
|
|
44
|
-
value: unknown,
|
|
45
|
-
): value is { readonly [categoriesKey]: { readonly [K in Cat]: true } } => {
|
|
41
|
+
(value: unknown): value is { readonly [categoriesKey]: { readonly [K in Cat]: true } } => {
|
|
46
42
|
if (!Predicate.isObject(value)) return false;
|
|
47
43
|
if (!Predicate.hasProperty(categoriesKey)(value)) return false;
|
|
48
44
|
return category in (value as any)[categoriesKey];
|
|
@@ -68,17 +64,9 @@ export const catchCategory =
|
|
|
68
64
|
) =>
|
|
69
65
|
<A, R>(
|
|
70
66
|
effect: Effect.Effect<A, E, R>,
|
|
71
|
-
): Effect.Effect<
|
|
72
|
-
|
|
73
|
-
E2 | Exclude<E, ExtractAll<E, Categories[number]>>,
|
|
74
|
-
R | R2
|
|
75
|
-
> => {
|
|
76
|
-
const f = args.pop()! as (
|
|
77
|
-
err: ExtractAll<E, Categories[number]>,
|
|
78
|
-
) => Effect.Effect<A2, E2, R2>;
|
|
67
|
+
): Effect.Effect<A | A2, E2 | Exclude<E, ExtractAll<E, Categories[number]>>, R | R2> => {
|
|
68
|
+
const f = args.pop()! as (err: ExtractAll<E, Categories[number]>) => Effect.Effect<A2, E2, R2>;
|
|
79
69
|
const categories = args as Array<PropertyKey>;
|
|
80
70
|
const matches = hasAnyCategory(...categories);
|
|
81
|
-
return Effect.catchIf(effect, matches, (e) =>
|
|
82
|
-
f(e as ExtractAll<E, Categories[number]>),
|
|
83
|
-
) as any;
|
|
71
|
+
return Effect.catchIf(effect, matches, (e) => f(e as ExtractAll<E, Categories[number]>)) as any;
|
|
84
72
|
};
|
package/src/errors.ts
CHANGED
|
@@ -22,9 +22,7 @@ import * as Category from "./category.ts";
|
|
|
22
22
|
* whatever the service actually returns (delay-seconds, HTTP-date, epoch, etc.)
|
|
23
23
|
* and consumed at runtime by the retry policy.
|
|
24
24
|
*/
|
|
25
|
-
export const DurationSchema = Schema.declare<Duration.Duration>(
|
|
26
|
-
Duration.isDuration,
|
|
27
|
-
);
|
|
25
|
+
export const DurationSchema = Schema.declare<Duration.Duration>(Duration.isDuration);
|
|
28
26
|
|
|
29
27
|
// ============================================================================
|
|
30
28
|
// Common HTTP Status Error Classes
|
|
@@ -33,10 +31,9 @@ export const DurationSchema = Schema.declare<Duration.Duration>(
|
|
|
33
31
|
/**
|
|
34
32
|
* Unauthorized - Authentication failure (401).
|
|
35
33
|
*/
|
|
36
|
-
export class Unauthorized extends Schema.TaggedError<Unauthorized>()(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
).pipe(Category.withAuthError) {}
|
|
34
|
+
export class Unauthorized extends Schema.TaggedError<Unauthorized>()("Unauthorized", {
|
|
35
|
+
message: Schema.String,
|
|
36
|
+
}).pipe(Category.withAuthError) {}
|
|
40
37
|
|
|
41
38
|
/**
|
|
42
39
|
* Forbidden - Access denied (403).
|
|
@@ -77,16 +74,10 @@ export class UnprocessableEntity extends Schema.TaggedError<UnprocessableEntity>
|
|
|
77
74
|
/**
|
|
78
75
|
* TooManyRequests - Rate limited (429).
|
|
79
76
|
*/
|
|
80
|
-
export class TooManyRequests extends Schema.TaggedError<TooManyRequests>()(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
retryAfter: Schema.optional(DurationSchema),
|
|
85
|
-
},
|
|
86
|
-
).pipe(
|
|
87
|
-
Category.withThrottlingError,
|
|
88
|
-
Category.withRetryable({ throttling: true }),
|
|
89
|
-
) {}
|
|
77
|
+
export class TooManyRequests extends Schema.TaggedError<TooManyRequests>()("TooManyRequests", {
|
|
78
|
+
message: Schema.String,
|
|
79
|
+
retryAfter: Schema.optional(DurationSchema),
|
|
80
|
+
}).pipe(Category.withThrottlingError, Category.withRetryable({ throttling: true })) {}
|
|
90
81
|
|
|
91
82
|
/**
|
|
92
83
|
* Locked - Resource locked (423).
|
|
@@ -133,23 +124,19 @@ export class ServiceUnavailable extends Schema.TaggedError<ServiceUnavailable>()
|
|
|
133
124
|
).pipe(Category.withServerError, Category.withRetryable()) {}
|
|
134
125
|
|
|
135
126
|
/**
|
|
136
|
-
* GatewayTimeout -
|
|
127
|
+
* GatewayTimeout - HTTP request or gateway timeout (408, 504).
|
|
137
128
|
*/
|
|
138
|
-
export class GatewayTimeout extends Schema.TaggedError<GatewayTimeout>()(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
retryAfter: Schema.optional(DurationSchema),
|
|
143
|
-
},
|
|
144
|
-
).pipe(Category.withServerError, Category.withRetryable()) {}
|
|
129
|
+
export class GatewayTimeout extends Schema.TaggedError<GatewayTimeout>()("GatewayTimeout", {
|
|
130
|
+
message: Schema.String,
|
|
131
|
+
retryAfter: Schema.optional(DurationSchema),
|
|
132
|
+
}).pipe(Category.withServerError, Category.withRetryable()) {}
|
|
145
133
|
|
|
146
134
|
/**
|
|
147
135
|
* Configuration error - missing or invalid configuration.
|
|
148
136
|
*/
|
|
149
|
-
export class ConfigError extends Schema.TaggedError<ConfigError>()(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
).pipe(Category.withConfigurationError) {}
|
|
137
|
+
export class ConfigError extends Schema.TaggedError<ConfigError>()("ConfigError", {
|
|
138
|
+
message: Schema.String,
|
|
139
|
+
}).pipe(Category.withConfigurationError) {}
|
|
153
140
|
|
|
154
141
|
// ============================================================================
|
|
155
142
|
// Error Maps
|
|
@@ -163,6 +150,7 @@ export const HTTP_STATUS_MAP = {
|
|
|
163
150
|
401: Unauthorized,
|
|
164
151
|
403: Forbidden,
|
|
165
152
|
404: NotFound,
|
|
153
|
+
408: GatewayTimeout,
|
|
166
154
|
409: Conflict,
|
|
167
155
|
422: UnprocessableEntity,
|
|
168
156
|
423: Locked,
|
|
@@ -189,7 +177,7 @@ export const DEFAULT_ERROR_STATUSES = new Set([401, 429, 500, 502, 503, 504]);
|
|
|
189
177
|
* classes (BadRequest/Unauthorized/etc.) would silently retain it as a
|
|
190
178
|
* stale field on the instance and pollute serialized output.
|
|
191
179
|
*/
|
|
192
|
-
export const RETRYABLE_HTTP_STATUSES = new Set([423, 429, 500, 502, 503, 504]);
|
|
180
|
+
export const RETRYABLE_HTTP_STATUSES = new Set([408, 423, 429, 500, 502, 503, 504]);
|
|
193
181
|
|
|
194
182
|
/**
|
|
195
183
|
* All common API error classes.
|