@distilled.cloud/core 1.0.0-rc.17 → 1.0.0-rc.19

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 (314) hide show
  1. package/lib/_bundle/base.js +2 -2
  2. package/lib/_bundle/base.js.map +1 -1
  3. package/lib/_bundle/graphql.js +2 -2
  4. package/lib/_bundle/graphql.js.map +1 -1
  5. package/lib/_bundle/grpc.js +2 -0
  6. package/lib/_bundle/grpc.js.map +1 -0
  7. package/lib/_bundle/rest.js +1 -1
  8. package/lib/_bundle/rest.js.map +1 -1
  9. package/lib/_bundle/xml.js +1 -1
  10. package/lib/_bundle/xml.js.map +1 -1
  11. package/lib/annotations.d.ts +17 -0
  12. package/lib/annotations.d.ts.map +1 -0
  13. package/lib/annotations.js +2 -0
  14. package/lib/annotations.js.map +1 -0
  15. package/lib/api.d.ts +52 -1
  16. package/lib/api.d.ts.map +1 -1
  17. package/lib/api.js +1 -1
  18. package/lib/category.d.ts.map +1 -1
  19. package/lib/config.d.ts +54 -13
  20. package/lib/config.d.ts.map +1 -1
  21. package/lib/config.js +1 -1
  22. package/lib/error-category.d.ts.map +1 -1
  23. package/lib/errors.d.ts +3 -13
  24. package/lib/errors.d.ts.map +1 -1
  25. package/lib/errors.js +1 -1
  26. package/lib/graphql.d.ts +26 -5
  27. package/lib/graphql.d.ts.map +1 -1
  28. package/lib/graphql.types.d.ts.map +1 -1
  29. package/lib/grpc-transport-cloudflare-http2.d.ts +7 -0
  30. package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -0
  31. package/lib/grpc-transport-cloudflare-http2.js +6 -0
  32. package/lib/grpc-transport-cloudflare-http2.js.map +1 -0
  33. package/lib/grpc-transport-cloudflare-sockets.d.ts +7 -0
  34. package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -0
  35. package/lib/grpc-transport-cloudflare-sockets.js +5 -0
  36. package/lib/grpc-transport-cloudflare-sockets.js.map +1 -0
  37. package/lib/grpc-transport-node-http2.d.ts +19 -0
  38. package/lib/grpc-transport-node-http2.d.ts.map +1 -0
  39. package/lib/grpc-transport-node-http2.js +2 -0
  40. package/lib/grpc-transport-node-http2.js.map +1 -0
  41. package/lib/grpc-transport.d.ts +76 -0
  42. package/lib/grpc-transport.d.ts.map +1 -0
  43. package/lib/grpc-transport.js +1 -0
  44. package/lib/hpack.d.ts +34 -0
  45. package/lib/hpack.d.ts.map +1 -0
  46. package/lib/hpack.js +2 -0
  47. package/lib/hpack.js.map +1 -0
  48. package/lib/index.d.ts +6 -2
  49. package/lib/index.d.ts.map +1 -1
  50. package/lib/index.js +4 -0
  51. package/lib/pagination.d.ts +55 -3
  52. package/lib/pagination.d.ts.map +1 -1
  53. package/lib/pagination.js +1 -1
  54. package/lib/protobuf.d.ts +92 -0
  55. package/lib/protobuf.d.ts.map +1 -0
  56. package/lib/protobuf.js +1 -0
  57. package/lib/protocol-grpc.d.ts +86 -0
  58. package/lib/protocol-grpc.d.ts.map +1 -0
  59. package/lib/protocol-grpc.js +1 -0
  60. package/lib/protocol-http.d.ts +38 -9
  61. package/lib/protocol-http.d.ts.map +1 -1
  62. package/lib/protocol-http.js +1 -1
  63. package/lib/protocol-rest.d.ts +60 -42
  64. package/lib/protocol-rest.d.ts.map +1 -1
  65. package/lib/protocol-rest.js +1 -1
  66. package/lib/response-validation.d.ts +5 -4
  67. package/lib/response-validation.d.ts.map +1 -1
  68. package/lib/schema-lite-typed.js +1 -2
  69. package/lib/sdk-error.d.ts +27 -0
  70. package/lib/sdk-error.d.ts.map +1 -0
  71. package/lib/sdk-error.js +1 -0
  72. package/lib/sensitive.d.ts +28 -0
  73. package/lib/sensitive.d.ts.map +1 -0
  74. package/lib/sensitive.js +2 -0
  75. package/lib/sensitive.js.map +1 -0
  76. package/lib/telemetry-debug.d.ts +6 -0
  77. package/lib/telemetry-debug.d.ts.map +1 -0
  78. package/lib/telemetry-debug.js +2 -0
  79. package/lib/telemetry-debug.js.map +1 -0
  80. package/lib/telemetry-hooks.d.ts +32 -0
  81. package/lib/telemetry-hooks.d.ts.map +1 -0
  82. package/lib/telemetry-hooks.js +2 -0
  83. package/lib/telemetry-hooks.js.map +1 -0
  84. package/lib/telemetry-host-rules.d.ts +23 -0
  85. package/lib/telemetry-host-rules.d.ts.map +1 -0
  86. package/lib/telemetry-host-rules.js +2 -0
  87. package/lib/telemetry-host-rules.js.map +1 -0
  88. package/lib/telemetry-lambda-context.d.ts +17 -0
  89. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  90. package/lib/telemetry-lambda-context.js +2 -0
  91. package/lib/telemetry-lambda-context.js.map +1 -0
  92. package/lib/telemetry-message-context.d.ts +52 -0
  93. package/lib/telemetry-message-context.d.ts.map +1 -0
  94. package/lib/telemetry-message-context.js +2 -0
  95. package/lib/telemetry-message-context.js.map +1 -0
  96. package/lib/telemetry-metrics.d.ts +6 -0
  97. package/lib/telemetry-metrics.d.ts.map +1 -0
  98. package/lib/telemetry-metrics.js +2 -0
  99. package/lib/telemetry-metrics.js.map +1 -0
  100. package/lib/telemetry-name-template.d.ts +13 -0
  101. package/lib/telemetry-name-template.d.ts.map +1 -0
  102. package/lib/telemetry-name-template.js +2 -0
  103. package/lib/telemetry-name-template.js.map +1 -0
  104. package/lib/telemetry-stream.d.ts +11 -0
  105. package/lib/telemetry-stream.d.ts.map +1 -0
  106. package/lib/telemetry-stream.js +2 -0
  107. package/lib/telemetry-stream.js.map +1 -0
  108. package/lib/telemetry-xray.d.ts +28 -0
  109. package/lib/telemetry-xray.d.ts.map +1 -0
  110. package/lib/telemetry-xray.js +2 -0
  111. package/lib/telemetry-xray.js.map +1 -0
  112. package/lib/telemetry.d.ts +288 -0
  113. package/lib/telemetry.d.ts.map +1 -0
  114. package/lib/telemetry.js +3 -0
  115. package/lib/telemetry.js.map +1 -0
  116. package/lib/trait.d.ts +7 -0
  117. package/lib/trait.d.ts.map +1 -1
  118. package/lib/trait.js +1 -1
  119. package/lib/xml.d.ts.map +1 -1
  120. package/package.json +3 -5
  121. package/src/annotations.ts +53 -0
  122. package/src/api.ts +316 -43
  123. package/src/category.ts +21 -22
  124. package/src/config.ts +58 -29
  125. package/src/error-category.ts +12 -14
  126. package/src/errors.ts +11 -7
  127. package/src/graphql.ts +191 -63
  128. package/src/graphql.types.ts +5 -1
  129. package/src/grpc-transport-cloudflare-http2.ts +494 -0
  130. package/src/grpc-transport-cloudflare-sockets.ts +299 -0
  131. package/src/grpc-transport-node-http2.ts +234 -0
  132. package/src/grpc-transport.ts +118 -0
  133. package/src/hpack.ts +331 -0
  134. package/src/index.ts +6 -2
  135. package/src/pagination.ts +193 -8
  136. package/src/protobuf.ts +1332 -0
  137. package/src/protocol-grpc.ts +641 -0
  138. package/src/protocol-http.ts +87 -67
  139. package/src/protocol-rest.ts +183 -191
  140. package/src/response-validation.ts +8 -5
  141. package/src/sdk-error.ts +33 -0
  142. package/src/sensitive.ts +154 -0
  143. package/src/telemetry-debug.ts +179 -0
  144. package/src/telemetry-hooks.ts +33 -0
  145. package/src/telemetry-host-rules.ts +39 -0
  146. package/src/telemetry-lambda-context.ts +46 -0
  147. package/src/telemetry-message-context.ts +170 -0
  148. package/src/telemetry-metrics.ts +69 -0
  149. package/src/telemetry-name-template.ts +26 -0
  150. package/src/telemetry-stream.ts +100 -0
  151. package/src/telemetry-xray.ts +66 -0
  152. package/src/telemetry.ts +832 -0
  153. package/src/trait.ts +10 -0
  154. package/src/xml.ts +10 -1
  155. package/lib/codegen/boolean-string-enums.d.ts +0 -36
  156. package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
  157. package/lib/codegen/boolean-string-enums.js +0 -147
  158. package/lib/codegen/boolean-string-enums.js.map +0 -1
  159. package/lib/codegen/chunk.d.ts +0 -7
  160. package/lib/codegen/chunk.d.ts.map +0 -1
  161. package/lib/codegen/chunk.js +0 -139
  162. package/lib/codegen/chunk.js.map +0 -1
  163. package/lib/codegen/cli.d.ts +0 -80
  164. package/lib/codegen/cli.d.ts.map +0 -1
  165. package/lib/codegen/cli.js +0 -166
  166. package/lib/codegen/cli.js.map +0 -1
  167. package/lib/codegen/datafy.d.ts +0 -14
  168. package/lib/codegen/datafy.d.ts.map +0 -1
  169. package/lib/codegen/datafy.js +0 -853
  170. package/lib/codegen/datafy.js.map +0 -1
  171. package/lib/codegen/dedupe.d.ts +0 -5
  172. package/lib/codegen/dedupe.d.ts.map +0 -1
  173. package/lib/codegen/dedupe.js +0 -153
  174. package/lib/codegen/dedupe.js.map +0 -1
  175. package/lib/codegen/emit.d.ts +0 -125
  176. package/lib/codegen/emit.d.ts.map +0 -1
  177. package/lib/codegen/emit.js +0 -99
  178. package/lib/codegen/emit.js.map +0 -1
  179. package/lib/codegen/format.d.ts +0 -11
  180. package/lib/codegen/format.d.ts.map +0 -1
  181. package/lib/codegen/format.js +0 -32
  182. package/lib/codegen/format.js.map +0 -1
  183. package/lib/codegen/generated-at.d.ts +0 -29
  184. package/lib/codegen/generated-at.d.ts.map +0 -1
  185. package/lib/codegen/generated-at.js +0 -78
  186. package/lib/codegen/generated-at.js.map +0 -1
  187. package/lib/codegen/generator.d.ts +0 -353
  188. package/lib/codegen/generator.d.ts.map +0 -1
  189. package/lib/codegen/generator.js +0 -810
  190. package/lib/codegen/generator.js.map +0 -1
  191. package/lib/codegen/graph.d.ts +0 -36
  192. package/lib/codegen/graph.d.ts.map +0 -1
  193. package/lib/codegen/graph.js +0 -136
  194. package/lib/codegen/graph.js.map +0 -1
  195. package/lib/codegen/graphql-client.d.ts +0 -70
  196. package/lib/codegen/graphql-client.d.ts.map +0 -1
  197. package/lib/codegen/graphql-client.js +0 -439
  198. package/lib/codegen/graphql-client.js.map +0 -1
  199. package/lib/codegen/graphql.d.ts +0 -207
  200. package/lib/codegen/graphql.d.ts.map +0 -1
  201. package/lib/codegen/graphql.js +0 -786
  202. package/lib/codegen/graphql.js.map +0 -1
  203. package/lib/codegen/latin1.d.ts +0 -3
  204. package/lib/codegen/latin1.d.ts.map +0 -1
  205. package/lib/codegen/latin1.js +0 -126
  206. package/lib/codegen/latin1.js.map +0 -1
  207. package/lib/codegen/members.d.ts +0 -32
  208. package/lib/codegen/members.d.ts.map +0 -1
  209. package/lib/codegen/members.js +0 -62
  210. package/lib/codegen/members.js.map +0 -1
  211. package/lib/codegen/model-diff.d.ts +0 -10
  212. package/lib/codegen/model-diff.d.ts.map +0 -1
  213. package/lib/codegen/model-diff.js +0 -67
  214. package/lib/codegen/model-diff.js.map +0 -1
  215. package/lib/codegen/naming.d.ts +0 -29
  216. package/lib/codegen/naming.d.ts.map +0 -1
  217. package/lib/codegen/naming.js +0 -74
  218. package/lib/codegen/naming.js.map +0 -1
  219. package/lib/codegen/openapi-cli.d.ts +0 -52
  220. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  221. package/lib/codegen/openapi-cli.js +0 -84
  222. package/lib/codegen/openapi-cli.js.map +0 -1
  223. package/lib/codegen/openapi.d.ts +0 -209
  224. package/lib/codegen/openapi.d.ts.map +0 -1
  225. package/lib/codegen/openapi.js +0 -1548
  226. package/lib/codegen/openapi.js.map +0 -1
  227. package/lib/codegen/operations.d.ts +0 -24
  228. package/lib/codegen/operations.d.ts.map +0 -1
  229. package/lib/codegen/operations.js +0 -56
  230. package/lib/codegen/operations.js.map +0 -1
  231. package/lib/codegen/pagination.d.ts +0 -39
  232. package/lib/codegen/pagination.d.ts.map +0 -1
  233. package/lib/codegen/pagination.js +0 -31
  234. package/lib/codegen/pagination.js.map +0 -1
  235. package/lib/codegen/patch-audit.d.ts +0 -84
  236. package/lib/codegen/patch-audit.d.ts.map +0 -1
  237. package/lib/codegen/patch-audit.js +0 -366
  238. package/lib/codegen/patch-audit.js.map +0 -1
  239. package/lib/codegen/patches.d.ts +0 -129
  240. package/lib/codegen/patches.d.ts.map +0 -1
  241. package/lib/codegen/patches.js +0 -472
  242. package/lib/codegen/patches.js.map +0 -1
  243. package/lib/codegen/prelude.d.ts +0 -15
  244. package/lib/codegen/prelude.d.ts.map +0 -1
  245. package/lib/codegen/prelude.js +0 -60
  246. package/lib/codegen/prelude.js.map +0 -1
  247. package/lib/codegen/privatize.d.ts +0 -21
  248. package/lib/codegen/privatize.d.ts.map +0 -1
  249. package/lib/codegen/privatize.js +0 -176
  250. package/lib/codegen/privatize.js.map +0 -1
  251. package/lib/codegen/proto.d.ts +0 -121
  252. package/lib/codegen/proto.d.ts.map +0 -1
  253. package/lib/codegen/proto.js +0 -960
  254. package/lib/codegen/proto.js.map +0 -1
  255. package/lib/codegen/pure.d.ts +0 -6
  256. package/lib/codegen/pure.d.ts.map +0 -1
  257. package/lib/codegen/pure.js +0 -91
  258. package/lib/codegen/pure.js.map +0 -1
  259. package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
  260. package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
  261. package/lib/codegen/rewrite-operation-ids.js +0 -1117
  262. package/lib/codegen/rewrite-operation-ids.js.map +0 -1
  263. package/lib/codegen/spec-path.d.ts +0 -16
  264. package/lib/codegen/spec-path.d.ts.map +0 -1
  265. package/lib/codegen/spec-path.js +0 -101
  266. package/lib/codegen/spec-path.js.map +0 -1
  267. package/lib/codegen/table.d.ts +0 -5
  268. package/lib/codegen/table.d.ts.map +0 -1
  269. package/lib/codegen/table.js +0 -249
  270. package/lib/codegen/table.js.map +0 -1
  271. package/lib/debug.d.ts +0 -2
  272. package/lib/debug.d.ts.map +0 -1
  273. package/lib/debug.js +0 -1
  274. package/lib/json-patch.d.ts +0 -58
  275. package/lib/json-patch.d.ts.map +0 -1
  276. package/lib/json-patch.js +0 -2
  277. package/lib/json-patch.js.map +0 -1
  278. package/lib/schema-lite-typed.js.map +0 -1
  279. package/lib/testing.d.ts +0 -40
  280. package/lib/testing.d.ts.map +0 -1
  281. package/lib/testing.js +0 -2
  282. package/lib/testing.js.map +0 -1
  283. package/src/codegen/boolean-string-enums.ts +0 -155
  284. package/src/codegen/chunk.ts +0 -147
  285. package/src/codegen/cli.ts +0 -293
  286. package/src/codegen/datafy.ts +0 -874
  287. package/src/codegen/dedupe.ts +0 -173
  288. package/src/codegen/emit.ts +0 -200
  289. package/src/codegen/format.ts +0 -49
  290. package/src/codegen/generated-at.ts +0 -88
  291. package/src/codegen/generator.ts +0 -1229
  292. package/src/codegen/graph.ts +0 -151
  293. package/src/codegen/graphql-client.ts +0 -545
  294. package/src/codegen/graphql.ts +0 -1145
  295. package/src/codegen/latin1.ts +0 -131
  296. package/src/codegen/members.ts +0 -79
  297. package/src/codegen/model-diff.ts +0 -67
  298. package/src/codegen/naming.ts +0 -85
  299. package/src/codegen/openapi-cli.ts +0 -141
  300. package/src/codegen/openapi.ts +0 -1845
  301. package/src/codegen/operations.ts +0 -73
  302. package/src/codegen/pagination.ts +0 -64
  303. package/src/codegen/patch-audit.ts +0 -480
  304. package/src/codegen/patches.ts +0 -581
  305. package/src/codegen/prelude.ts +0 -70
  306. package/src/codegen/privatize.ts +0 -200
  307. package/src/codegen/proto.ts +0 -1092
  308. package/src/codegen/pure.ts +0 -94
  309. package/src/codegen/rewrite-operation-ids.ts +0 -1219
  310. package/src/codegen/spec-path.ts +0 -112
  311. package/src/codegen/table.ts +0 -254
  312. package/src/debug.ts +0 -8
  313. package/src/json-patch.ts +0 -273
  314. package/src/testing.ts +0 -74
@@ -1,1117 +0,0 @@
1
-
2
- const VERB_ALIAS = {
3
- show: "get",
4
- index: "list",
5
- retrieve: "get",
6
- };
7
-
8
-
9
-
10
-
11
-
12
- const isIndexVerb = (raw) => raw.toLowerCase() === "index";
13
-
14
-
15
-
16
-
17
-
18
-
19
- const STRONG_VERBS = new Set([
20
- "get",
21
- "list",
22
- "create",
23
- "delete",
24
- "update",
25
- "patch",
26
- "put",
27
- "post",
28
- "show",
29
- "index",
30
- "retrieve",
31
- "watch",
32
- "read",
33
- "replace",
34
- "connect",
35
- "disconnect",
36
- "insert",
37
- "mutate",
38
- "fetch",
39
- "remove",
40
- "add",
41
- "upload",
42
- "download",
43
- "send",
44
- "resend",
45
- "validate",
46
- "verify",
47
- "enable",
48
- "disable",
49
- "start",
50
- "stop",
51
- "restart",
52
- "cancel",
53
- "search",
54
- "purge",
55
- "revoke",
56
- "approve",
57
- "reject",
58
- "accept",
59
- "invoke",
60
- "trigger",
61
- "deploy",
62
- "redeploy",
63
- "describe",
64
- "generate",
65
- "regenerate",
66
- "rotate",
67
- "restore",
68
- "suspend",
69
- "resume",
70
- "activate",
71
- "deactivate",
72
- "archive",
73
- "unarchive",
74
- "publish",
75
- "unpublish",
76
- "subscribe",
77
- "unsubscribe",
78
- "register",
79
- "unregister",
80
- "authenticate",
81
- "authorize",
82
- "deauthorize",
83
- "attach",
84
- "detach",
85
- "assign",
86
- "unassign",
87
- "import",
88
- "export",
89
- "copy",
90
- "move",
91
- "rename",
92
- "retry",
93
- "reset",
94
- "refresh",
95
- "encrypt",
96
- "decrypt",
97
- "sign",
98
- "edit",
99
- "bulk",
100
- "execute",
101
- "submit",
102
- "apply",
103
- "undelete",
104
- "redeliver",
105
- "invalidate",
106
- "upsert",
107
- "cordon",
108
- "uncordon",
109
- "exec",
110
- "reclaim",
111
- "modify",
112
- "install",
113
- "uninstall",
114
- "migrate",
115
- "terminate",
116
- "reboot",
117
- "rebuild",
118
- "resize",
119
- "clone",
120
- "duplicate",
121
- "acknowledge",
122
- "unpause",
123
- "unblock",
124
- "unlink",
125
- "unpin",
126
- "unmute",
127
- "unhide",
128
- "unstar",
129
- "unfollow",
130
- "unshare",
131
- "unban",
132
- "unlock",
133
- "unflag",
134
- "unclaim",
135
- ]);
136
-
137
-
138
-
139
-
140
-
141
-
142
- const TRAILING_VERBS = new Set([
143
- ...STRONG_VERBS,
144
- "notify",
145
- "set",
146
- "check",
147
- "run",
148
- "wait",
149
- "signal",
150
- "fork",
151
- "extend",
152
- "test",
153
- "sync",
154
- "review",
155
- "invite",
156
- "join",
157
- "leave",
158
- "capture",
159
- "refund",
160
- "settle",
161
- "void",
162
- "preview",
163
- "complete",
164
- "confirm",
165
- "abort",
166
- "kill",
167
- "scale",
168
- "promote",
169
- "demote",
170
- "renew",
171
- "recover",
172
- "reveal",
173
- "presign",
174
- "provision",
175
- "trim",
176
- "vacuum",
177
- "compact",
178
- "flush",
179
- "merge",
180
- "dispatch",
181
- "poll",
182
- "redeem",
183
- "claim",
184
- "lint",
185
- "toggle",
186
- "pin",
187
- "mute",
188
- "hide",
189
- "ban",
190
- "block",
191
- "lock",
192
- "share",
193
- "follow",
194
- "star",
195
- "pause",
196
- "finalize",
197
- "transfer",
198
- "lookup",
199
- "clear",
200
- "convert",
201
- "dismiss",
202
- "reply",
203
- "squash",
204
- "commit",
205
- "swap",
206
- "recreate",
207
- "seal",
208
- "ping",
209
- "login",
210
- "logout",
211
- ]);
212
-
213
-
214
-
215
-
216
-
217
- const WEAK_LEADING_VERBS = new Set([
218
- ...TRAILING_VERBS,
219
- "request",
220
- "release",
221
- "report",
222
- "query",
223
- "stream",
224
- "open",
225
- "close",
226
- "head",
227
- "options",
228
- "compute",
229
- "batch",
230
- "count",
231
- "link",
232
- "mark",
233
- "grant",
234
- "aggregate",
235
- "skip",
236
- "filter",
237
- "change",
238
- "vote",
239
- "debug",
240
- "expire",
241
- "process",
242
- "redirect",
243
- "estimate",
244
- "calculate",
245
- "evaluate",
246
- "resolve",
247
- "load",
248
- "unload",
249
- "backup",
250
- "snapshot",
251
- "rollback",
252
- "flag",
253
- "certify",
254
- "checkout",
255
- "checkin",
256
- "suggest",
257
- "predict",
258
- "analyze",
259
- "annotate",
260
- "translate",
261
- "recognize",
262
- "detect",
263
- "classify",
264
- "simulate",
265
- "take",
266
- "end",
267
- "reassign",
268
- "consume",
269
- "prepare",
270
- "action",
271
- "act",
272
- "ask",
273
- "answer",
274
- "handle",
275
- "trace",
276
- "track",
277
- "log",
278
- ]);
279
-
280
- const TOKEN_ALIAS = {
281
- secretkeys: "SecretKeys",
282
- secretkey: "SecretKey",
283
- };
284
- const IRREGULAR_SINGULAR = {
285
- processes: "process",
286
- statuses: "status",
287
- addresses: "address",
288
- aliases: "alias",
289
- indexes: "index",
290
- indices: "index",
291
- matrices: "matrix",
292
- vertices: "vertex",
293
- analyses: "analysis",
294
- bases: "base",
295
- cases: "case",
296
- databases: "database",
297
- releases: "release",
298
- responses: "response",
299
- licenses: "license",
300
- courses: "course",
301
- purchases: "purchase",
302
- phases: "phase",
303
- leases: "lease",
304
- clauses: "clause",
305
- causes: "cause",
306
- pauses: "pause",
307
- houses: "house",
308
- children: "child",
309
- people: "person",
310
- media: "media",
311
- data: "data",
312
- metadata: "metadata",
313
- schemas: "schema",
314
- criteria: "criterion",
315
- feet: "foot",
316
- teeth: "tooth",
317
- mice: "mouse",
318
- geese: "goose",
319
- };
320
-
321
-
322
-
323
-
324
- const UNCOUNTABLE = new Set([
325
- "postgres",
326
- "redis",
327
- "kubernetes",
328
- "ios",
329
- "macos",
330
- "windows",
331
- "dns",
332
- "tls",
333
- "https",
334
- "sms",
335
- "cors",
336
- "oidc",
337
- "sso",
338
- "saas",
339
- "aws",
340
- "gcs",
341
- "ecs",
342
- "eks",
343
- "rds",
344
- "sqs",
345
- "sns",
346
- "kms",
347
- "ses",
348
- "efs",
349
- "ebs",
350
- "status",
351
- "series",
352
- "timeseries",
353
- "analytics",
354
- "metrics",
355
- "settings",
356
- "credentials",
357
- "permissions",
358
- "news",
359
- "canvas",
360
- "lens",
361
- "bonus",
362
- "campus",
363
- "census",
364
- "focus",
365
- "virus",
366
- "corpus",
367
- "chorus",
368
- "genus",
369
- "radius",
370
- "consensus",
371
- "apparatus",
372
- "bus",
373
- "gas",
374
- "plus",
375
- "minus",
376
- "nexus",
377
- "prometheus",
378
- "chaos",
379
- "cosmos",
380
- "ethos",
381
- "pathos",
382
- "atlas",
383
- "bias",
384
- "gps",
385
- "cds",
386
- "css",
387
- "sass",
388
- "less",
389
- "js",
390
- "ts",
391
- "os",
392
- "fs",
393
- "vs",
394
- "as",
395
- "is",
396
- "has",
397
- "was",
398
- "this",
399
- "always",
400
- "sis",
401
- "axis",
402
- "basis",
403
- "crisis",
404
- "thesis",
405
- "diagnosis",
406
- "synthesis",
407
- "emphasis",
408
- "hypothesis",
409
- "oasis",
410
- "iris",
411
- "tennis",
412
- "chassis",
413
- "debris",
414
- "physics",
415
- "ethics",
416
- "economics",
417
- "logistics",
418
- "mathematics",
419
- "politics",
420
- "statistics",
421
- "dynamics",
422
- "graphics",
423
- "robotics",
424
- "genetics",
425
- "linguistics",
426
- "means",
427
- "species",
428
- "sheep",
429
- "fish",
430
- "deer",
431
- "aircraft",
432
- "software",
433
- "hardware",
434
- "firmware",
435
- "middleware",
436
- "access",
437
- "address",
438
- "progress",
439
- "success",
440
- "process",
441
- "business",
442
- "ingress",
443
- "egress",
444
- "express",
445
- "compress",
446
- "stress",
447
- "witness",
448
- "fitness",
449
- "wellness",
450
- "readiness",
451
- "liveness",
452
- "awareness",
453
- "class",
454
- "pass",
455
- "mass",
456
- "glass",
457
- "grass",
458
- "bypass",
459
- "compass",
460
- "kms",
461
- "eos",
462
- "nas",
463
- "ras",
464
- "sas",
465
- "das",
466
- "pas",
467
- "s3",
468
- "k8s",
469
- "kubeadm",
470
- ]);
471
-
472
- const QUALIFIERS = new Set(["acme", "custom"]);
473
- export const operationNameKey = (ctx) => `${ctx.method.toUpperCase()} ${ctx.path}`;
474
-
475
- export const resolveOperationName = (rewrite, operationId, ctx) => {
476
- if (typeof rewrite === "function")
477
- return rewrite(operationId, ctx);
478
- return rewrite[operationNameKey(ctx)] ?? rewrite[operationId];
479
- };
480
-
481
- const pascalToken = (raw) => {
482
- const alias = TOKEN_ALIAS[raw.toLowerCase()];
483
- if (alias !== undefined)
484
- return alias;
485
- return raw.charAt(0).toUpperCase() + raw.slice(1);
486
- };
487
-
488
-
489
-
490
-
491
-
492
- export const singularize = (raw) => {
493
- const lower = raw.toLowerCase();
494
- const keepCase = (s) => raw[0] === raw[0]?.toUpperCase() ? s.charAt(0).toUpperCase() + s.slice(1) : s;
495
- const alias = TOKEN_ALIAS[lower];
496
- if (alias !== undefined) {
497
- return alias.endsWith("s") ? alias.slice(0, -1) : alias;
498
- }
499
- const irregular = IRREGULAR_SINGULAR[lower];
500
- if (irregular !== undefined)
501
- return keepCase(irregular);
502
- if (UNCOUNTABLE.has(lower))
503
- return raw;
504
- // All-caps acronyms (`IPs`, `CIDRs`, `DNS`) — only trim a lowercase `s`
505
- // after an acronym.
506
- if (/^[A-Z0-9]+s$/.test(raw))
507
- return raw.slice(0, -1);
508
- if (raw !== lower && raw.toUpperCase() === raw)
509
- return raw;
510
- if (lower.length <= 3)
511
- return raw;
512
- if (!lower.endsWith("s"))
513
- return raw;
514
- // Vowel + `ys` is a regular plural (`keys`, `days`); consonant + `ys` is not.
515
- if (/(?:ss|us|is|os|as|[^aeiou]ys)$/.test(lower))
516
- return raw;
517
- if (lower.endsWith("ies") && lower.length > 4)
518
- return `${raw.slice(0, -3)}y`;
519
- if (/(?:ches|shes|xes|zes|sses)$/.test(lower))
520
- return raw.slice(0, -2);
521
- if (lower.endsWith("oes") && lower.length > 4)
522
- return raw.slice(0, -2);
523
- // `-ses` after a vowel is usually a regular `-se` noun (`Response`,
524
- // `Release`, `Database`), not an `-s` + `es` plural.
525
- if (/[aeiou]ses$/.test(lower))
526
- return raw.slice(0, -1);
527
- if (lower.endsWith("ses"))
528
- return raw.slice(0, -2);
529
- return raw.slice(0, -1);
530
- };
531
- const lowerFirst = (s) => s.length === 0 ? s : s.charAt(0).toLowerCase() + s.slice(1);
532
-
533
-
534
-
535
-
536
- const splitIdent = (s) => {
537
- const parts = [];
538
- for (const chunk of s.split(/[_/\-.\s]+/).filter(Boolean)) {
539
- const split = chunk
540
- .replace(/([a-z0-9])([A-Z])/g, "$1\0$2")
541
- .replace(/([A-Z]+)([A-Z][a-z])/g, "$1\0$2");
542
- for (const p of split.split("\0")) {
543
- if (p)
544
- parts.push(p);
545
- }
546
- }
547
- return parts;
548
- };
549
- const isStrongVerb = (raw) => STRONG_VERBS.has(raw.toLowerCase());
550
- const isTrailingVerb = (raw) => TRAILING_VERBS.has(raw.toLowerCase());
551
- const isWeakLeadingVerb = (raw) => WEAK_LEADING_VERBS.has(raw.toLowerCase());
552
- const alias = (raw) => VERB_ALIAS[raw.toLowerCase()] ?? raw.toLowerCase();
553
-
554
- const isVersionToken = (raw) => /^[vV]\d/.test(raw);
555
-
556
- const MODIFIERS = new Set(["partial", "bulk", "batch", "all", "many"]);
557
-
558
-
559
-
560
-
561
-
562
- const assemble = (verb, nouns, tail = []) => {
563
- // `App_Certificates_acme_create`: the qualifier trails the resource in
564
- // the id but reads better in front of it (`createAppAcmeCertificate`).
565
- let ordered = [...nouns];
566
- if (ordered.length >= 2 && QUALIFIERS.has(ordered.at(-1).toLowerCase())) {
567
- const q = ordered.pop();
568
- ordered.splice(ordered.length - 1, 0, q);
569
- }
570
- const shaped = ordered.map((p, i) => {
571
- const isLast = i === ordered.length - 1;
572
- if (!isLast || isVersionToken(p))
573
- return pascalToken(p);
574
- if (verb === "list" && tail.length === 0)
575
- return pascalToken(p);
576
- return pascalToken(singularize(p));
577
- });
578
- return verb + shaped.join("") + tail.map(pascalToken).join("");
579
- };
580
-
581
-
582
-
583
-
584
-
585
-
586
-
587
-
588
-
589
-
590
-
591
-
592
-
593
-
594
-
595
- export const toVerbNoun = (operationId) => {
596
- const trimmed = operationId.trim();
597
- if (trimmed === "")
598
- return trimmed;
599
- const segments = trimmed.split(/[_/]+/).filter(Boolean);
600
- if (segments.length >= 2) {
601
- // snake_case verb-first (`get_apps`, `list_all_users`): join.
602
- const lead = splitIdent(segments[0]);
603
- if (lead.length === 1 && isStrongVerb(lead[0])) {
604
- const rest = segments.slice(1).flatMap(splitIdent);
605
- return alias(lead[0]) + rest.map(pascalToken).join("");
606
- }
607
- // Segments before the verb are the resource by construction, so a
608
- // verb-looking token inside them (`OpenIdConnectProvider_get`) is a
609
- // noun. Only the object after the verb can make this a compound.
610
- const verbSeg = segments.findIndex((seg, i) => {
611
- if (i === 0)
612
- return false;
613
- const tokens = splitIdent(seg);
614
- const head = tokens[0] ?? "";
615
- // `Apps_index` lists; `Apps_indexInfo` is about the index entity.
616
- if (isIndexVerb(head))
617
- return tokens.length === 1;
618
- return isTrailingVerb(head);
619
- });
620
- if (verbSeg > 0) {
621
- const head = segments.slice(0, verbSeg).flatMap(splitIdent);
622
- const [verb, ...objectHere] = splitIdent(segments[verbSeg]);
623
- const object = [...objectHere, ...segments.slice(verbSeg + 1).flatMap(splitIdent)];
624
- const compound = object.some((t) => isStrongVerb(t) || /^(or|and)$/i.test(t));
625
- if (!compound)
626
- return assemble(alias(verb), head, object);
627
- }
628
- return lowerFirst(trimmed);
629
- }
630
- const parts = splitIdent(trimmed);
631
- // `Index1`, `Index2`: a converter's duplicate-route suffix on a bare id.
632
- if (parts.length <= 1 || parts.slice(1).every((p) => /^\d+$/.test(p))) {
633
- return parts.length >= 1 && isTrailingVerb(parts[0])
634
- ? alias(parts[0]) + parts.slice(1).join("")
635
- : lowerFirst(trimmed);
636
- }
637
- const first = parts[0];
638
- const last = parts.at(-1);
639
- // A camel id never uses Rails `index` as its verb: `InfoIndex`,
640
- // `IndexCreate`, `IndexDocument` all name the index entity.
641
- const strong = (raw) => !isIndexVerb(raw) && isStrongVerb(raw);
642
- const trailing = (raw) => !isIndexVerb(raw) && isTrailingVerb(raw);
643
- const weakLeading = (raw) => !isIndexVerb(raw) && isWeakLeadingVerb(raw);
644
- if (strong(first)) {
645
- return alias(first) + parts.slice(1).map(pascalToken).join("");
646
- }
647
- if (parts.some((p) => /^(or|and)$/i.test(p)))
648
- return lowerFirst(trimmed);
649
- // Swagger tag-prefixed ids whose object repeats the tag (`issueListIssues`,
650
- // `repoGetRepo`): the tag is redundant, drop it. Other tag-prefixed shapes
651
- // (`userGetCurrent`, `notifyGetList`) are left for per-package
652
- // `operationNames`; a middle verb is too often a noun (`environmentPatchCommit`).
653
- if (parts.length >= 3 &&
654
- !weakLeading(first) &&
655
- !isVersionToken(first) &&
656
- strong(parts[1]) &&
657
- singularize(parts[2]).toLowerCase() === singularize(first).toLowerCase() &&
658
- !parts.slice(2).some(strong)) {
659
- return alias(parts[1]) + parts.slice(2).map(pascalToken).join("");
660
- }
661
- const reorder = weakLeading(first) ? strong(last) : trailing(last);
662
- if (!reorder) {
663
- return weakLeading(first)
664
- ? alias(first) + parts.slice(1).map(pascalToken).join("")
665
- : lowerFirst(trimmed);
666
- }
667
- const nouns = parts.slice(0, -1);
668
- if (nouns.slice(1).some(strong))
669
- return lowerFirst(trimmed);
670
- const modifier = nouns.at(-1);
671
- if (nouns.length > 1 && modifier !== undefined && MODIFIERS.has(modifier.toLowerCase())) {
672
- return assemble(alias(last), nouns.slice(0, -1), [modifier]);
673
- }
674
- return assemble(alias(last), nouns);
675
- };
676
- const COMPANION_SUFFIXES = ["Request", "Response", "Input", "Output", "Error", "Result"];
677
- const remapTargets = (node, mapping) => {
678
- if (Array.isArray(node)) {
679
- return node.map((item) => remapTargets(item, mapping));
680
- }
681
- if (node === null || typeof node !== "object")
682
- return node;
683
- const out = {};
684
- for (const [key, value] of Object.entries(node)) {
685
- if (key === "target" && typeof value === "string") {
686
- out[key] = mapping.get(value) ?? value;
687
- }
688
- else {
689
- out[key] = remapTargets(value, mapping);
690
- }
691
- }
692
- return out;
693
- };
694
-
695
-
696
-
697
-
698
-
699
- export const RENAME_METADATA_KEY = "distilled.rename";
700
-
701
-
702
-
703
-
704
- export const applyDeferredRename = (model) => {
705
- const rename = model.metadata?.[RENAME_METADATA_KEY];
706
- if (rename === undefined)
707
- return 0;
708
- delete model.metadata[RENAME_METADATA_KEY];
709
- const shapes = model.shapes ?? {};
710
- // A patch may have moved or removed a shape; only rename what is there.
711
- const mapping = new Map(Object.entries(rename).filter(([from]) => from in shapes));
712
- if (mapping.size > 0)
713
- renameShapes(model, mapping);
714
- return mapping.size;
715
- };
716
-
717
-
718
-
719
-
720
-
721
-
722
- export const renameShapes = (model, mapping) => {
723
- const shapes = model.shapes ?? {};
724
- const nextShapes = {};
725
- for (const [id, def] of Object.entries(shapes)) {
726
- const newId = mapping.get(id) ?? id;
727
- if (Object.prototype.hasOwnProperty.call(nextShapes, newId)) {
728
- throw new Error(`renaming ${id} → ${newId}: that shape id is already taken`);
729
- }
730
- nextShapes[newId] = remapTargets(def, mapping);
731
- }
732
- model.shapes = nextShapes;
733
- };
734
-
735
- const NOISE_SEGMENTS = new Set(["api", "rest", "v", "public"]);
736
- const isNoiseSegment = (seg) => {
737
- const lower = seg.toLowerCase();
738
- return NOISE_SEGMENTS.has(lower) || /^v\d+(\.\d+)*$/.test(lower);
739
- };
740
- const HTTP_METHOD_ID = /^(get|post|put|patch|delete|head|options)(?=$|[-_./]|[A-Z0-9])/i;
741
-
742
-
743
-
744
-
745
-
746
-
747
-
748
-
749
-
750
-
751
-
752
-
753
-
754
-
755
-
756
-
757
-
758
-
759
-
760
-
761
- export const isVerbatimRouteId = (operationId, ctx) => {
762
- if (!operationId)
763
- return true;
764
- if (!isMechanicalOperationId(operationId, ctx))
765
- return false;
766
- const id = stripTag(operationId);
767
- const m = HTTP_METHOD_ID.exec(id);
768
- const norm = (t) => singularize(t.toLowerCase()).toLowerCase();
769
- const idTokens = splitIdent(id.slice(m ? m[0].length : 0)).map(norm);
770
- const literal = new Set();
771
- const params = [];
772
- for (const seg of ctx.path.split(/[?#]/)[0].split("/")) {
773
- for (const mm of seg.matchAll(/\{([^}]+)\}/g)) {
774
- params.push(splitIdent(mm[1]).map(norm));
775
- }
776
- for (const t of splitIdent(seg.replace(/\{[^}]*\}/g, " ")).map(norm)) {
777
- literal.add(t);
778
- }
779
- }
780
- const paramTokens = new Set(params.flat());
781
- const clauses = [[]];
782
- for (const t of idTokens) {
783
- if (t === "by")
784
- clauses.push([]);
785
- else
786
- clauses.at(-1).push(t);
787
- }
788
- const [head, ...byClauses] = clauses;
789
- if (!head.every((t) => literal.has(t) || paramTokens.has(t)))
790
- return false;
791
- // `ByAppIdPromote`: a whole parameter, then route literals.
792
- return byClauses.every((c) => {
793
- const lengths = [
794
- ...params.filter((p) => p.every((t, i) => t === c[i])).map((p) => p.length),
795
- ...(c[0] === "id" ? [1] : []),
796
- ];
797
- return lengths.some((n) => n <= c.length && c.slice(n).every((t) => literal.has(t)));
798
- });
799
- };
800
-
801
- const stripTag = (operationId) => operationId.includes("/") ? operationId.slice(operationId.lastIndexOf("/") + 1) : operationId;
802
- export const isMechanicalOperationId = (operationId, ctx) => {
803
- if (!operationId)
804
- return true;
805
- const id = stripTag(operationId);
806
- const m = HTTP_METHOD_ID.exec(id);
807
- if (!m || m[1].toLowerCase() !== ctx.method.toLowerCase())
808
- return false;
809
- const norm = (t) => singularize(t.toLowerCase()).toLowerCase();
810
- const joiners = new Set(["by", "for", "of", "in", "with", "and", "to"]);
811
- const idTokens = splitIdent(id.slice(m[0].length))
812
- .map(norm)
813
- .filter((t) => !joiners.has(t));
814
- const segments = ctx.path.split(/[?#]/)[0].split("/").filter(Boolean);
815
- // Route tokens in order; literals are required, params and `/api`,
816
- // `/v2` roots are optional (`getApiV1Foo` and `getFoo` both count).
817
- const route = [];
818
- for (const seg of segments) {
819
- const param = /^\{(.*)\}$/.exec(seg);
820
- const required = param === null && !isNoiseSegment(seg);
821
- for (const t of splitIdent(param ? param[1] : seg).map(norm)) {
822
- route.push({ token: t, required });
823
- }
824
- }
825
- if (idTokens.length === 0)
826
- return !route.some((r) => r.required);
827
- // The id must read the route left to right, skipping only optional
828
- // tokens. `delete-package-for-org` on /orgs/{org}/packages/… reads
829
- // `package, org` — out of order — and stays a hand-written name.
830
- let i = 0;
831
- for (const r of route) {
832
- if (i < idTokens.length && idTokens[i] === r.token) {
833
- i++;
834
- }
835
- else if (r.required) {
836
- return false;
837
- }
838
- }
839
- return i === idTokens.length;
840
- };
841
- export const pathToVerbNoun = (ctx, hints = {}) => {
842
- const method = ctx.method.toLowerCase();
843
- const segments = ctx.path.split(/[?#]/)[0].split("/").filter(Boolean);
844
- const literal = [];
845
- // `{id}`, `:id`, and composite segments such as `{slug}-{id}`.
846
- const isParam = (seg) => /\{[^}]*\}/.test(seg) || seg.startsWith(":");
847
- let endsWithParam = false;
848
- for (let i = 0; i < segments.length; i++) {
849
- const seg = segments[i];
850
- if (isParam(seg)) {
851
- endsWithParam = i === segments.length - 1;
852
- continue;
853
- }
854
- endsWithParam = false;
855
- if (isNoiseSegment(seg))
856
- continue;
857
- literal.push(seg);
858
- }
859
- if (literal.length === 0)
860
- return lowerFirst(method + "Root");
861
- if (hints.nouns !== undefined) {
862
- // `activity/get-feeds`: a tag prefix before the method is not a noun.
863
- const id = hints.nouns.includes("/")
864
- ? hints.nouns.slice(hints.nouns.lastIndexOf("/") + 1)
865
- : hints.nouns;
866
- const m = HTTP_METHOD_ID.exec(id);
867
- const rest = m ? id.slice(m[0].length) : id;
868
- // Route literals, both as written and singularised, so a parameter
869
- // that echoes a literal (`{team}` under `/teams/`) is not mistaken
870
- // for a parameter token.
871
- const literal = new Set(segments
872
- .filter((seg) => !isParam(seg))
873
- .flatMap((seg) => splitIdent(seg))
874
- .flatMap((t) => [t.toLowerCase(), singularize(t).toLowerCase()]));
875
- const routeNoise = new Set(segments
876
- .filter((seg) => !isParam(seg) && isNoiseSegment(seg))
877
- .flatMap((seg) => splitIdent(seg).map((t) => t.toLowerCase())));
878
-
879
- const params = segments
880
- .flatMap((seg) => [...seg.matchAll(/\{([^}]+)\}/g)])
881
- .map((mm) => splitIdent(mm[1]).map((t) => t.toLowerCase()));
882
- const raw = splitIdent(rest);
883
-
884
- const matchParam = (at) => {
885
- let best = 0;
886
- for (const prm of params) {
887
- if (prm.length > best && prm.every((t, k) => raw[at + k]?.toLowerCase() === t)) {
888
- best = prm.length;
889
- }
890
- }
891
- if (best === 0 && raw[at]?.toLowerCase() === "id")
892
- best = 1;
893
- return best;
894
- };
895
- const tokens = [];
896
-
897
- const followedByParam = new Set();
898
- for (let i = 0; i < raw.length; i++) {
899
- const t = raw[i];
900
- const lower = t.toLowerCase();
901
- // `getApiV1Foo` → drop the api/version root the id copied from the
902
- // route; a token the route does not have (`…DataAPI`) is kept.
903
- if (isNoiseSegment(t) && routeNoise.has(lower))
904
- continue;
905
- let n = 0;
906
- let skip = 0;
907
- if (/^(by|for|of|in|with|and|to)$/.test(lower)) {
908
- n = matchParam(i + 1);
909
- skip = n + 1;
910
- // Non-verbatim ids only drop a TRAILING `ById`; a `By` in the
911
- // middle (`getBalanceByAsset`) is part of the chosen name.
912
- if (n > 0 && !hints.verbatim && i + skip !== raw.length)
913
- n = 0;
914
- }
915
- else if (hints.verbatim && i > 0) {
916
- // `get_v1_users_id`, `GetAccountsAccount`: a whole parameter name
917
- // with no `By`. When the parameter echoes the resource it follows
918
- // (`/accounts/{account}`, `/teams/{team}`) the previous token has
919
- // to be that resource; otherwise (`deleteProjectBranchCustomDomain`
920
- // on `/custom-domains/{domain}`) it is the literal.
921
- n = matchParam(i);
922
- skip = n;
923
- const echoes = raw.slice(i, i + n).some((x) => literal.has(x.toLowerCase()));
924
- const prev = tokens.at(-1)?.toLowerCase();
925
- const prevIsResource = prev !== undefined &&
926
- raw
927
- .slice(i, i + n)
928
- .some((x) => singularize(prev) === singularize(x.toLowerCase()) || prev === x.toLowerCase());
929
- if (echoes && !prevIsResource)
930
- n = 0;
931
- }
932
- if (n > 0) {
933
- if (tokens.length)
934
- followedByParam.add(tokens.length - 1);
935
- i += skip - 1;
936
- continue;
937
- }
938
- tokens.push(t);
939
- }
940
- if (hints.verbatim) {
941
- for (const i of followedByParam)
942
- tokens[i] = singularize(tokens[i]);
943
- // `PostAccounts` → createAccount: a create makes one member.
944
- if (method === "post" && !endsWithParam && tokens.length > 0) {
945
- tokens[tokens.length - 1] = singularize(tokens.at(-1));
946
- }
947
- }
948
- if (tokens.length > 0) {
949
- // A POST that addresses one member (`POST /accounts/{account}`,
950
- // Stripe-style) updates it; a POST on a collection creates.
951
- const verb = method === "get"
952
- ? !endsWithParam && hints.returnsCollection === true
953
- ? "list"
954
- : "get"
955
- : method === "post"
956
- ? endsWithParam
957
- ? "update"
958
- : "create"
959
- : method === "patch"
960
- ? "update"
961
- : method;
962
- return verb + tokens.map(pascalToken).join("");
963
- }
964
- }
965
- const tokens = literal.map((seg) => splitIdent(seg));
966
- const lastTokens = tokens.at(-1);
967
- // `/papers/index`, `/opensearch/index` address an index resource, not a
968
- // Rails `index` action.
969
- const lastIsVerb = lastTokens.length > 0 &&
970
- !isIndexVerb(lastTokens[0]) &&
971
- (isTrailingVerb(lastTokens[0]) || isStrongVerb(lastTokens[0])) &&
972
- !endsWithParam &&
973
- method === "post";
974
- // POST /things/{id}/publish → publishThing; POST /login → login.
975
- if (lastIsVerb) {
976
- const [verb, ...rest] = lastTokens;
977
- const parents = tokens.slice(0, -1);
978
- const nouns = parents.map((t, i) => i === parents.length - 1 ? t.map((x, j) => (j === t.length - 1 ? singularize(x) : x)) : t);
979
- return alias(verb) + nouns.flat().map(pascalToken).join("") + rest.map(pascalToken).join("");
980
- }
981
- // GET is `list` only when the body is known to be a collection; an
982
- // unknown or non-JSON body (`/zen`, `/octocat`) is a plain `get`.
983
- const verb = method === "get"
984
- ? !endsWithParam && hints.returnsCollection === true
985
- ? "list"
986
- : "get"
987
- : method === "post"
988
- ? endsWithParam
989
- ? "update"
990
- : "create"
991
- : method === "patch"
992
- ? "update"
993
- : method === "put"
994
- ? "put"
995
- : method === "delete"
996
- ? "delete"
997
- : method;
998
- // A GET/DELETE/PATCH/PUT on a collection route (no trailing parameter)
999
- // addresses the collection itself — keep its plural. With a trailing
1000
- // parameter the route addresses one member, and `create` always makes
1001
- // one — singular.
1002
- const plural = !endsWithParam && verb !== "create";
1003
- const shaped = tokens.map((t, i) => {
1004
- const isResource = i === tokens.length - 1;
1005
- return t.map((x, j) => {
1006
- const last = j === t.length - 1;
1007
- if (!last)
1008
- return pascalToken(x);
1009
- // Parents are singular (`Org` in listOrgRepos).
1010
- if (!isResource || !plural)
1011
- return pascalToken(singularize(x));
1012
- return pascalToken(x);
1013
- });
1014
- });
1015
- return verb + shaped.flat().join("");
1016
- };
1017
-
1018
-
1019
-
1020
-
1021
-
1022
-
1023
- export const verbNounSmithyModel = (model) => {
1024
- const shapes = model.shapes ?? {};
1025
- const mapping = new Map();
1026
- const mappedTo = new Set();
1027
- const collisions = [];
1028
- const ids = Object.keys(shapes);
1029
- const taken = new Set(ids);
1030
- const order = new Map(ids.map((id, i) => [id, i]));
1031
- const split = (id) => {
1032
- const hash = id.indexOf("#");
1033
- return hash >= 0 ? [id.slice(0, hash), id.slice(hash + 1)] : ["", id];
1034
- };
1035
- // Local names per namespace in code-unit order, so the shapes whose name
1036
- // starts with an operation's are one contiguous run (found by binary
1037
- // search) instead of a scan of every shape per operation.
1038
- const localsByNs = new Map();
1039
- for (const id of ids) {
1040
- const [ns, local] = split(id);
1041
- const list = localsByNs.get(ns);
1042
- if (list)
1043
- list.push(local);
1044
- else
1045
- localsByNs.set(ns, [local]);
1046
- }
1047
- for (const list of localsByNs.values())
1048
- list.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
1049
- const withPrefix = (ns, prefix) => {
1050
- const list = localsByNs.get(ns) ?? [];
1051
- let lo = 0;
1052
- let hi = list.length;
1053
- while (lo < hi) {
1054
- const mid = (lo + hi) >>> 1;
1055
- if (list[mid] < prefix)
1056
- lo = mid + 1;
1057
- else
1058
- hi = mid;
1059
- }
1060
- const out = [];
1061
- for (let i = lo; i < list.length && list[i].startsWith(prefix); i++) {
1062
- out.push(ns ? `${ns}#${list[i]}` : list[i]);
1063
- }
1064
- // Model order, as a scan of every shape would visit them.
1065
- return out.sort((a, b) => order.get(a) - order.get(b));
1066
- };
1067
- const ops = Object.entries(shapes).filter(([, def]) => def?.type === "operation");
1068
- for (const [id] of ops) {
1069
- const [ns, local] = split(id);
1070
- const camel = toVerbNoun(local);
1071
- const nextLocal = camel.charAt(0).toUpperCase() + camel.slice(1);
1072
- if (nextLocal === local)
1073
- continue;
1074
- const nextId = ns ? `${ns}#${nextLocal}` : nextLocal;
1075
- if (taken.has(nextId) && !mapping.has(nextId)) {
1076
- collisions.push(`${local} → ${nextLocal}`);
1077
- continue;
1078
- }
1079
- if (mappedTo.has(nextId)) {
1080
- collisions.push(`${local} → ${nextLocal}`);
1081
- continue;
1082
- }
1083
- mapping.set(id, nextId);
1084
- mappedTo.add(nextId);
1085
- taken.add(nextId);
1086
- // Companions: `<Op>Request`, `<Op>Response…`, and anything derived
1087
- // from them by the converters' `${opName}Request${Member}` naming.
1088
- // Skip prefixes that are themselves another operation's name
1089
- // (`Get` vs `GetObject`) — only exact suffix matches count there.
1090
- for (const candidate of withPrefix(ns, local)) {
1091
- if (candidate === id || mapping.has(candidate))
1092
- continue;
1093
- const tail = split(candidate)[1].slice(local.length);
1094
- if (tail === "")
1095
- continue;
1096
- const suffixed = COMPANION_SUFFIXES.some((s) => tail.startsWith(s));
1097
- if (!suffixed)
1098
- continue;
1099
- // `ListAppsRequest` vs op `List` + `AppsRequest`: require the tail to
1100
- // start with a companion suffix immediately after the op name.
1101
- const to = ns ? `${ns}#${nextLocal}${tail}` : `${nextLocal}${tail}`;
1102
- if (taken.has(to))
1103
- continue;
1104
- mapping.set(candidate, to);
1105
- mappedTo.add(to);
1106
- taken.add(to);
1107
- }
1108
- }
1109
- if (mapping.size === 0)
1110
- return { renamed: 0, collisions };
1111
- renameShapes(model, mapping);
1112
- return {
1113
- renamed: ops.filter(([opId]) => mapping.has(opId)).length,
1114
- collisions,
1115
- };
1116
- };
1117
- //# sourceMappingURL=rewrite-operation-ids.js.map