@distilled.cloud/core 1.0.0-rc.13 → 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.
Files changed (235) hide show
  1. package/lib/api.d.ts +4 -4
  2. package/lib/api.d.ts.map +1 -1
  3. package/lib/api.js +3 -5
  4. package/lib/api.js.map +1 -1
  5. package/lib/category.d.ts.map +1 -1
  6. package/lib/category.js +3 -5
  7. package/lib/category.js.map +1 -1
  8. package/lib/codegen/boolean-string-enums.d.ts.map +1 -1
  9. package/lib/codegen/boolean-string-enums.js +2 -6
  10. package/lib/codegen/boolean-string-enums.js.map +1 -1
  11. package/lib/codegen/boolean-string-enums.test.js +3 -5
  12. package/lib/codegen/boolean-string-enums.test.js.map +1 -1
  13. package/lib/codegen/cli.d.ts +5 -4
  14. package/lib/codegen/cli.d.ts.map +1 -1
  15. package/lib/codegen/cli.js +12 -9
  16. package/lib/codegen/cli.js.map +1 -1
  17. package/lib/codegen/defer-naming.test.d.ts +2 -0
  18. package/lib/codegen/defer-naming.test.d.ts.map +1 -0
  19. package/lib/codegen/defer-naming.test.js +105 -0
  20. package/lib/codegen/defer-naming.test.js.map +1 -0
  21. package/lib/codegen/emit.d.ts.map +1 -1
  22. package/lib/codegen/emit.js +1 -3
  23. package/lib/codegen/emit.js.map +1 -1
  24. package/lib/codegen/format.d.ts +0 -12
  25. package/lib/codegen/format.d.ts.map +1 -1
  26. package/lib/codegen/format.js +10 -6
  27. package/lib/codegen/format.js.map +1 -1
  28. package/lib/codegen/generated-at.d.ts +29 -0
  29. package/lib/codegen/generated-at.d.ts.map +1 -0
  30. package/lib/codegen/generated-at.js +78 -0
  31. package/lib/codegen/generated-at.js.map +1 -0
  32. package/lib/codegen/generated-at.test.d.ts +2 -0
  33. package/lib/codegen/generated-at.test.d.ts.map +1 -0
  34. package/lib/codegen/generated-at.test.js +81 -0
  35. package/lib/codegen/generated-at.test.js.map +1 -0
  36. package/lib/codegen/generator.d.ts +4 -2
  37. package/lib/codegen/generator.d.ts.map +1 -1
  38. package/lib/codegen/generator.js +37 -75
  39. package/lib/codegen/generator.js.map +1 -1
  40. package/lib/codegen/generator.test.js +4 -9
  41. package/lib/codegen/generator.test.js.map +1 -1
  42. package/lib/codegen/graphql-client.d.ts.map +1 -1
  43. package/lib/codegen/graphql-client.js +12 -33
  44. package/lib/codegen/graphql-client.js.map +1 -1
  45. package/lib/codegen/graphql-client.test.js +4 -12
  46. package/lib/codegen/graphql-client.test.js.map +1 -1
  47. package/lib/codegen/graphql.d.ts.map +1 -1
  48. package/lib/codegen/graphql.js +7 -20
  49. package/lib/codegen/graphql.js.map +1 -1
  50. package/lib/codegen/model-diff.d.ts +10 -0
  51. package/lib/codegen/model-diff.d.ts.map +1 -0
  52. package/lib/codegen/model-diff.js +67 -0
  53. package/lib/codegen/model-diff.js.map +1 -0
  54. package/lib/codegen/naming.d.ts.map +1 -1
  55. package/lib/codegen/naming.js.map +1 -1
  56. package/lib/codegen/openapi-binary.test.js +1 -1
  57. package/lib/codegen/openapi-binary.test.js.map +1 -1
  58. package/lib/codegen/openapi-cli.d.ts +11 -11
  59. package/lib/codegen/openapi-cli.d.ts.map +1 -1
  60. package/lib/codegen/openapi-cli.js +26 -51
  61. package/lib/codegen/openapi-cli.js.map +1 -1
  62. package/lib/codegen/openapi.d.ts +9 -1
  63. package/lib/codegen/openapi.d.ts.map +1 -1
  64. package/lib/codegen/openapi.js +48 -42
  65. package/lib/codegen/openapi.js.map +1 -1
  66. package/lib/codegen/operations.d.ts.map +1 -1
  67. package/lib/codegen/operations.js.map +1 -1
  68. package/lib/codegen/pagination.d.ts.map +1 -1
  69. package/lib/codegen/pagination.js +2 -4
  70. package/lib/codegen/pagination.js.map +1 -1
  71. package/lib/codegen/patch-audit.d.ts +84 -0
  72. package/lib/codegen/patch-audit.d.ts.map +1 -0
  73. package/lib/codegen/patch-audit.js +366 -0
  74. package/lib/codegen/patch-audit.js.map +1 -0
  75. package/lib/codegen/patch-audit.test.d.ts +2 -0
  76. package/lib/codegen/patch-audit.test.d.ts.map +1 -0
  77. package/lib/codegen/patch-audit.test.js +141 -0
  78. package/lib/codegen/patch-audit.test.js.map +1 -0
  79. package/lib/codegen/patches.d.ts +59 -10
  80. package/lib/codegen/patches.d.ts.map +1 -1
  81. package/lib/codegen/patches.js +233 -63
  82. package/lib/codegen/patches.js.map +1 -1
  83. package/lib/codegen/patches.test.js +8 -4
  84. package/lib/codegen/patches.test.js.map +1 -1
  85. package/lib/codegen/prelude.js +1 -1
  86. package/lib/codegen/prelude.js.map +1 -1
  87. package/lib/codegen/proto.d.ts.map +1 -1
  88. package/lib/codegen/proto.js +2 -4
  89. package/lib/codegen/proto.js.map +1 -1
  90. package/lib/codegen/protocol-imports.test.d.ts +2 -0
  91. package/lib/codegen/protocol-imports.test.d.ts.map +1 -0
  92. package/lib/codegen/protocol-imports.test.js +36 -0
  93. package/lib/codegen/protocol-imports.test.js.map +1 -0
  94. package/lib/codegen/rewrite-operation-ids.d.ts +23 -0
  95. package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -1
  96. package/lib/codegen/rewrite-operation-ids.js +97 -59
  97. package/lib/codegen/rewrite-operation-ids.js.map +1 -1
  98. package/lib/codegen/rewrite-operation-ids.test.js +19 -101
  99. package/lib/codegen/rewrite-operation-ids.test.js.map +1 -1
  100. package/lib/codegen/spec-path.d.ts +1 -1
  101. package/lib/codegen/spec-path.d.ts.map +1 -1
  102. package/lib/codegen/spec-path.js +1 -1
  103. package/lib/codegen/spec-path.js.map +1 -1
  104. package/lib/codegen/untagged-unions.test.js +1 -1
  105. package/lib/codegen/untagged-unions.test.js.map +1 -1
  106. package/lib/error-category.d.ts.map +1 -1
  107. package/lib/error-category.js.map +1 -1
  108. package/lib/errors.d.ts.map +1 -1
  109. package/lib/errors.js +7 -5
  110. package/lib/errors.js.map +1 -1
  111. package/lib/graphql.d.ts +4 -8
  112. package/lib/graphql.d.ts.map +1 -1
  113. package/lib/graphql.js +20 -48
  114. package/lib/graphql.js.map +1 -1
  115. package/lib/graphql.test.js +6 -6
  116. package/lib/graphql.test.js.map +1 -1
  117. package/lib/graphql.types.d.ts.map +1 -1
  118. package/lib/graphql.types.js.map +1 -1
  119. package/lib/json-patch.d.ts +13 -6
  120. package/lib/json-patch.d.ts.map +1 -1
  121. package/lib/json-patch.js +34 -19
  122. package/lib/json-patch.js.map +1 -1
  123. package/lib/json-patch.test.d.ts +2 -0
  124. package/lib/json-patch.test.d.ts.map +1 -0
  125. package/lib/json-patch.test.js +65 -0
  126. package/lib/json-patch.test.js.map +1 -0
  127. package/lib/pagination.d.ts.map +1 -1
  128. package/lib/pagination.js +6 -16
  129. package/lib/pagination.js.map +1 -1
  130. package/lib/pagination.test.js +3 -6
  131. package/lib/pagination.test.js.map +1 -1
  132. package/lib/protocol-http.d.ts +20 -1
  133. package/lib/protocol-http.d.ts.map +1 -1
  134. package/lib/protocol-http.js +41 -47
  135. package/lib/protocol-http.js.map +1 -1
  136. package/lib/protocol-http.test.js +20 -10
  137. package/lib/protocol-http.test.js.map +1 -1
  138. package/lib/protocol-rest.d.ts.map +1 -1
  139. package/lib/protocol-rest.js +9 -18
  140. package/lib/protocol-rest.js.map +1 -1
  141. package/lib/protocol-rest.test.d.ts +2 -0
  142. package/lib/protocol-rest.test.d.ts.map +1 -0
  143. package/lib/protocol-rest.test.js +498 -0
  144. package/lib/protocol-rest.test.js.map +1 -0
  145. package/lib/response-validation.d.ts.map +1 -1
  146. package/lib/response-validation.js.map +1 -1
  147. package/lib/response-validation.test.js +10 -5
  148. package/lib/response-validation.test.js.map +1 -1
  149. package/lib/retry-after.d.ts.map +1 -1
  150. package/lib/retry-after.js +1 -1
  151. package/lib/retry-after.js.map +1 -1
  152. package/lib/retry-after.test.d.ts +2 -0
  153. package/lib/retry-after.test.d.ts.map +1 -0
  154. package/lib/retry-after.test.js +204 -0
  155. package/lib/retry-after.test.js.map +1 -0
  156. package/lib/retry.d.ts.map +1 -1
  157. package/lib/retry.js +1 -2
  158. package/lib/retry.js.map +1 -1
  159. package/lib/retry.test.d.ts +2 -0
  160. package/lib/retry.test.d.ts.map +1 -0
  161. package/lib/retry.test.js +407 -0
  162. package/lib/retry.test.js.map +1 -0
  163. package/lib/sdks.test.d.ts +2 -0
  164. package/lib/sdks.test.d.ts.map +1 -0
  165. package/lib/sdks.test.js +76 -0
  166. package/lib/sdks.test.js.map +1 -0
  167. package/lib/testing.d.ts +2 -2
  168. package/lib/testing.d.ts.map +1 -1
  169. package/lib/testing.js +1 -1
  170. package/lib/testing.js.map +1 -1
  171. package/lib/trait.d.ts.map +1 -1
  172. package/lib/trait.js.map +1 -1
  173. package/lib/xml.d.ts.map +1 -1
  174. package/lib/xml.js +3 -7
  175. package/lib/xml.js.map +1 -1
  176. package/lib/xml.test.js +11 -12
  177. package/lib/xml.test.js.map +1 -1
  178. package/package.json +7 -10
  179. package/src/api.ts +38 -55
  180. package/src/category.ts +21 -50
  181. package/src/codegen/boolean-string-enums.test.ts +12 -28
  182. package/src/codegen/boolean-string-enums.ts +2 -10
  183. package/src/codegen/cli.ts +29 -47
  184. package/src/codegen/defer-naming.test.ts +113 -0
  185. package/src/codegen/emit.ts +2 -5
  186. package/src/codegen/format.ts +12 -10
  187. package/src/codegen/generated-at.test.ts +89 -0
  188. package/src/codegen/generated-at.ts +88 -0
  189. package/src/codegen/generator.test.ts +8 -22
  190. package/src/codegen/generator.ts +72 -191
  191. package/src/codegen/graphql-client.test.ts +12 -42
  192. package/src/codegen/graphql-client.ts +30 -95
  193. package/src/codegen/graphql.ts +22 -94
  194. package/src/codegen/model-diff.ts +67 -0
  195. package/src/codegen/naming.ts +1 -2
  196. package/src/codegen/openapi-binary.test.ts +5 -12
  197. package/src/codegen/openapi-cli.ts +38 -79
  198. package/src/codegen/openapi.ts +79 -136
  199. package/src/codegen/operations.ts +2 -5
  200. package/src/codegen/pagination.ts +4 -11
  201. package/src/codegen/patch-audit.test.ts +160 -0
  202. package/src/codegen/patch-audit.ts +480 -0
  203. package/src/codegen/patches.test.ts +14 -21
  204. package/src/codegen/patches.ts +313 -103
  205. package/src/codegen/prelude.ts +1 -1
  206. package/src/codegen/proto.ts +18 -54
  207. package/src/codegen/protocol-imports.test.ts +39 -0
  208. package/src/codegen/rewrite-operation-ids.test.ts +23 -114
  209. package/src/codegen/rewrite-operation-ids.ts +111 -98
  210. package/src/codegen/spec-path.ts +3 -6
  211. package/src/codegen/untagged-unions.test.ts +3 -7
  212. package/src/error-category.ts +5 -17
  213. package/src/errors.ts +16 -31
  214. package/src/graphql.test.ts +6 -8
  215. package/src/graphql.ts +76 -219
  216. package/src/graphql.types.ts +10 -25
  217. package/src/json-patch.test.ts +77 -0
  218. package/src/json-patch.ts +54 -60
  219. package/src/pagination.test.ts +13 -35
  220. package/src/pagination.ts +44 -111
  221. package/src/protocol-http.test.ts +36 -30
  222. package/src/protocol-http.ts +73 -138
  223. package/src/protocol-rest.test.ts +703 -0
  224. package/src/protocol-rest.ts +24 -62
  225. package/src/response-validation.test.ts +12 -18
  226. package/src/response-validation.ts +3 -12
  227. package/src/retry-after.test.ts +267 -0
  228. package/src/retry-after.ts +4 -10
  229. package/src/retry.test.ts +566 -0
  230. package/src/retry.ts +6 -21
  231. package/src/sdks.test.ts +87 -0
  232. package/src/testing.ts +4 -10
  233. package/src/trait.ts +21 -67
  234. package/src/xml.test.ts +15 -33
  235. package/src/xml.ts +9 -25
@@ -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
- STRONG_VERBS.has(raw.toLowerCase());
595
- const isTrailingVerb = (raw: string): boolean =>
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
- ...objectHere,
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 taken = new Set(Object.keys(shapes));
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 ops = Object.entries(shapes).filter(
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
- opLocals.add(hash >= 0 ? id.slice(hash + 1) : id);
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 hash = id.indexOf("#");
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 ([...mapping.values()].includes(nextId)) {
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 Object.keys(shapes)) {
1196
+ for (const candidate of withPrefix(ns, local)) {
1176
1197
  if (candidate === id || mapping.has(candidate)) continue;
1177
- const cHash = candidate.indexOf("#");
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
- const nextShapes: Record<string, any> = {};
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,
@@ -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.dir, "..")`)
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);
@@ -1,4 +1,4 @@
1
- import { expect, test } from "bun:test";
1
+ import { expect, test } from "vitest";
2
2
  import { generateService } from "./generator.ts";
3
3
 
4
4
  const model = {
@@ -60,12 +60,8 @@ test("untagged unions honor the configured schema type", () => {
60
60
  schemaType,
61
61
  operationDecl,
62
62
  });
63
- expect(code).toContain(
64
- `S.Union([S.Boolean, Paths]) as any as S.${schemaType}<Choice>`,
65
- );
66
- expect(code).toContain(
67
- `S.Array(S.String) as any as S.${schemaType}<Paths>`,
68
- );
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>`);
69
65
  }
70
66
  });
71
67
 
@@ -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
- A | A2,
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
- "Unauthorized",
38
- { message: Schema.String },
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
- "TooManyRequests",
82
- {
83
- message: Schema.String,
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).
@@ -135,21 +126,17 @@ export class ServiceUnavailable extends Schema.TaggedError<ServiceUnavailable>()
135
126
  /**
136
127
  * GatewayTimeout - HTTP request or gateway timeout (408, 504).
137
128
  */
138
- export class GatewayTimeout extends Schema.TaggedError<GatewayTimeout>()(
139
- "GatewayTimeout",
140
- {
141
- message: Schema.String,
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
- "ConfigError",
151
- { message: Schema.String },
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
@@ -190,9 +177,7 @@ export const DEFAULT_ERROR_STATUSES = new Set([401, 429, 500, 502, 503, 504]);
190
177
  * classes (BadRequest/Unauthorized/etc.) would silently retain it as a
191
178
  * stale field on the instance and pollute serialized output.
192
179
  */
193
- export const RETRYABLE_HTTP_STATUSES = new Set([
194
- 408, 423, 429, 500, 502, 503, 504,
195
- ]);
180
+ export const RETRYABLE_HTTP_STATUSES = new Set([408, 423, 429, 500, 502, 503, 504]);
196
181
 
197
182
  /**
198
183
  * All common API error classes.
@@ -1,6 +1,6 @@
1
- import { describe, expect, test } from "bun:test";
2
1
  import * as Effect from "effect/Effect";
3
2
  import * as Layer from "effect/Layer";
3
+ import { describe, expect, test } from "vitest";
4
4
  import {
5
5
  GqlTransport,
6
6
  connectionField,
@@ -88,10 +88,7 @@ describe("Query.fn", () => {
88
88
  return {
89
89
  data: {
90
90
  projects: {
91
- edges: [
92
- { node: { name: "engine" } },
93
- { node: { name: "bombe" } },
94
- ],
91
+ edges: [{ node: { name: "engine" } }, { node: { name: "bombe" } }],
95
92
  },
96
93
  },
97
94
  };
@@ -193,8 +190,9 @@ describe("Query.fn", () => {
193
190
  ),
194
191
  ).toEqual({ name: "web", deployment: { id: "d1", status: "SUCCESS" } });
195
192
  expect(documents[0]).toMatch(/latestDeployment \{\s+id\s+status/);
196
- expect(
197
- await Effect.runPromise(program.pipe(Effect.provide(respond(null)))),
198
- ).toEqual({ name: "web", deployment: null });
193
+ expect(await Effect.runPromise(program.pipe(Effect.provide(respond(null))))).toEqual({
194
+ name: "web",
195
+ deployment: null,
196
+ });
199
197
  });
200
198
  });