@typespec/http-server-js 0.58.0-alpha.10-dev.3

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 (215) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/LICENSE +21 -0
  3. package/README.md +183 -0
  4. package/build-helpers.ts +170 -0
  5. package/dist/generated-defs/helpers/header.d.ts +4 -0
  6. package/dist/generated-defs/helpers/header.d.ts.map +1 -0
  7. package/dist/generated-defs/helpers/header.js +76 -0
  8. package/dist/generated-defs/helpers/header.js.map +1 -0
  9. package/dist/generated-defs/helpers/http.d.ts +4 -0
  10. package/dist/generated-defs/helpers/http.d.ts.map +1 -0
  11. package/dist/generated-defs/helpers/http.js +134 -0
  12. package/dist/generated-defs/helpers/http.js.map +1 -0
  13. package/dist/generated-defs/helpers/index.d.ts +4 -0
  14. package/dist/generated-defs/helpers/index.d.ts.map +1 -0
  15. package/dist/generated-defs/helpers/index.js +21 -0
  16. package/dist/generated-defs/helpers/index.js.map +1 -0
  17. package/dist/generated-defs/helpers/multipart.d.ts +4 -0
  18. package/dist/generated-defs/helpers/multipart.d.ts.map +1 -0
  19. package/dist/generated-defs/helpers/multipart.js +249 -0
  20. package/dist/generated-defs/helpers/multipart.js.map +1 -0
  21. package/dist/generated-defs/helpers/router.d.ts +4 -0
  22. package/dist/generated-defs/helpers/router.d.ts.map +1 -0
  23. package/dist/generated-defs/helpers/router.js +259 -0
  24. package/dist/generated-defs/helpers/router.js.map +1 -0
  25. package/dist/src/common/declaration.d.ts +13 -0
  26. package/dist/src/common/declaration.d.ts.map +1 -0
  27. package/dist/src/common/declaration.js +45 -0
  28. package/dist/src/common/declaration.js.map +1 -0
  29. package/dist/src/common/documentation.d.ts +12 -0
  30. package/dist/src/common/documentation.d.ts.map +1 -0
  31. package/dist/src/common/documentation.js +21 -0
  32. package/dist/src/common/documentation.js.map +1 -0
  33. package/dist/src/common/enum.d.ts +10 -0
  34. package/dist/src/common/enum.d.ts.map +1 -0
  35. package/dist/src/common/enum.js +21 -0
  36. package/dist/src/common/enum.js.map +1 -0
  37. package/dist/src/common/interface.d.ts +50 -0
  38. package/dist/src/common/interface.d.ts.map +1 -0
  39. package/dist/src/common/interface.js +194 -0
  40. package/dist/src/common/interface.js.map +1 -0
  41. package/dist/src/common/model.d.ts +26 -0
  42. package/dist/src/common/model.d.ts.map +1 -0
  43. package/dist/src/common/model.js +115 -0
  44. package/dist/src/common/model.js.map +1 -0
  45. package/dist/src/common/namespace.d.ts +38 -0
  46. package/dist/src/common/namespace.d.ts.map +1 -0
  47. package/dist/src/common/namespace.js +184 -0
  48. package/dist/src/common/namespace.js.map +1 -0
  49. package/dist/src/common/reference.d.ts +46 -0
  50. package/dist/src/common/reference.d.ts.map +1 -0
  51. package/dist/src/common/reference.js +243 -0
  52. package/dist/src/common/reference.js.map +1 -0
  53. package/dist/src/common/scalar.d.ts +50 -0
  54. package/dist/src/common/scalar.d.ts.map +1 -0
  55. package/dist/src/common/scalar.js +144 -0
  56. package/dist/src/common/scalar.js.map +1 -0
  57. package/dist/src/common/serialization/index.d.ts +11 -0
  58. package/dist/src/common/serialization/index.d.ts.map +1 -0
  59. package/dist/src/common/serialization/index.js +72 -0
  60. package/dist/src/common/serialization/index.js.map +1 -0
  61. package/dist/src/common/serialization/json.d.ts +6 -0
  62. package/dist/src/common/serialization/json.d.ts.map +1 -0
  63. package/dist/src/common/serialization/json.js +341 -0
  64. package/dist/src/common/serialization/json.js.map +1 -0
  65. package/dist/src/common/union.d.ts +23 -0
  66. package/dist/src/common/union.d.ts.map +1 -0
  67. package/dist/src/common/union.js +57 -0
  68. package/dist/src/common/union.js.map +1 -0
  69. package/dist/src/ctx.d.ts +242 -0
  70. package/dist/src/ctx.d.ts.map +1 -0
  71. package/dist/src/ctx.js +211 -0
  72. package/dist/src/ctx.js.map +1 -0
  73. package/dist/src/helpers/header.d.ts +14 -0
  74. package/dist/src/helpers/header.d.ts.map +1 -0
  75. package/dist/src/helpers/header.js +38 -0
  76. package/dist/src/helpers/header.js.map +1 -0
  77. package/dist/src/helpers/http.d.ts +70 -0
  78. package/dist/src/helpers/http.d.ts.map +1 -0
  79. package/dist/src/helpers/http.js +86 -0
  80. package/dist/src/helpers/http.js.map +1 -0
  81. package/dist/src/helpers/multipart.d.ts +26 -0
  82. package/dist/src/helpers/multipart.d.ts.map +1 -0
  83. package/dist/src/helpers/multipart.js +182 -0
  84. package/dist/src/helpers/multipart.js.map +1 -0
  85. package/dist/src/helpers/router.d.ts +176 -0
  86. package/dist/src/helpers/router.d.ts.map +1 -0
  87. package/dist/src/helpers/router.js +55 -0
  88. package/dist/src/helpers/router.js.map +1 -0
  89. package/dist/src/http/index.d.ts +24 -0
  90. package/dist/src/http/index.d.ts.map +1 -0
  91. package/dist/src/http/index.js +52 -0
  92. package/dist/src/http/index.js.map +1 -0
  93. package/dist/src/http/server/index.d.ts +11 -0
  94. package/dist/src/http/server/index.d.ts.map +1 -0
  95. package/dist/src/http/server/index.js +413 -0
  96. package/dist/src/http/server/index.js.map +1 -0
  97. package/dist/src/http/server/multipart.d.ts +16 -0
  98. package/dist/src/http/server/multipart.d.ts.map +1 -0
  99. package/dist/src/http/server/multipart.js +214 -0
  100. package/dist/src/http/server/multipart.js.map +1 -0
  101. package/dist/src/http/server/router.d.ts +15 -0
  102. package/dist/src/http/server/router.d.ts.map +1 -0
  103. package/dist/src/http/server/router.js +459 -0
  104. package/dist/src/http/server/router.js.map +1 -0
  105. package/dist/src/index.d.ts +5 -0
  106. package/dist/src/index.d.ts.map +1 -0
  107. package/dist/src/index.js +38 -0
  108. package/dist/src/index.js.map +1 -0
  109. package/dist/src/lib.d.ts +141 -0
  110. package/dist/src/lib.d.ts.map +1 -0
  111. package/dist/src/lib.js +116 -0
  112. package/dist/src/lib.js.map +1 -0
  113. package/dist/src/scripts/scaffold/bin.d.mts +14 -0
  114. package/dist/src/scripts/scaffold/bin.d.mts.map +1 -0
  115. package/dist/src/scripts/scaffold/bin.mjs +559 -0
  116. package/dist/src/scripts/scaffold/bin.mjs.map +1 -0
  117. package/dist/src/testing/index.d.ts +3 -0
  118. package/dist/src/testing/index.d.ts.map +1 -0
  119. package/dist/src/testing/index.js +6 -0
  120. package/dist/src/testing/index.js.map +1 -0
  121. package/dist/src/util/case.d.ts +81 -0
  122. package/dist/src/util/case.d.ts.map +1 -0
  123. package/dist/src/util/case.js +111 -0
  124. package/dist/src/util/case.js.map +1 -0
  125. package/dist/src/util/differentiate.d.ts +251 -0
  126. package/dist/src/util/differentiate.d.ts.map +1 -0
  127. package/dist/src/util/differentiate.js +580 -0
  128. package/dist/src/util/differentiate.js.map +1 -0
  129. package/dist/src/util/error.d.ts +13 -0
  130. package/dist/src/util/error.d.ts.map +1 -0
  131. package/dist/src/util/error.js +25 -0
  132. package/dist/src/util/error.js.map +1 -0
  133. package/dist/src/util/extends.d.ts +10 -0
  134. package/dist/src/util/extends.d.ts.map +1 -0
  135. package/dist/src/util/extends.js +31 -0
  136. package/dist/src/util/extends.js.map +1 -0
  137. package/dist/src/util/iter.d.ts +39 -0
  138. package/dist/src/util/iter.d.ts.map +1 -0
  139. package/dist/src/util/iter.js +72 -0
  140. package/dist/src/util/iter.js.map +1 -0
  141. package/dist/src/util/keywords.d.ts +10 -0
  142. package/dist/src/util/keywords.d.ts.map +1 -0
  143. package/dist/src/util/keywords.js +85 -0
  144. package/dist/src/util/keywords.js.map +1 -0
  145. package/dist/src/util/name.d.ts +12 -0
  146. package/dist/src/util/name.d.ts.map +1 -0
  147. package/dist/src/util/name.js +26 -0
  148. package/dist/src/util/name.js.map +1 -0
  149. package/dist/src/util/once-queue.d.ts +24 -0
  150. package/dist/src/util/once-queue.d.ts.map +1 -0
  151. package/dist/src/util/once-queue.js +34 -0
  152. package/dist/src/util/once-queue.js.map +1 -0
  153. package/dist/src/util/openapi3.d.ts +23 -0
  154. package/dist/src/util/openapi3.d.ts.map +1 -0
  155. package/dist/src/util/openapi3.js +40 -0
  156. package/dist/src/util/openapi3.js.map +1 -0
  157. package/dist/src/util/pluralism.d.ts +23 -0
  158. package/dist/src/util/pluralism.d.ts.map +1 -0
  159. package/dist/src/util/pluralism.js +36 -0
  160. package/dist/src/util/pluralism.js.map +1 -0
  161. package/dist/src/util/scope.d.ts +85 -0
  162. package/dist/src/util/scope.d.ts.map +1 -0
  163. package/dist/src/util/scope.js +111 -0
  164. package/dist/src/util/scope.js.map +1 -0
  165. package/dist/src/write.d.ts +23 -0
  166. package/dist/src/write.d.ts.map +1 -0
  167. package/dist/src/write.js +62 -0
  168. package/dist/src/write.js.map +1 -0
  169. package/generated-defs/helpers/header.ts +83 -0
  170. package/generated-defs/helpers/http.ts +141 -0
  171. package/generated-defs/helpers/index.ts +27 -0
  172. package/generated-defs/helpers/multipart.ts +256 -0
  173. package/generated-defs/helpers/router.ts +266 -0
  174. package/package.json +71 -0
  175. package/src/common/declaration.ts +52 -0
  176. package/src/common/documentation.ts +26 -0
  177. package/src/common/enum.ts +28 -0
  178. package/src/common/interface.ts +264 -0
  179. package/src/common/model.ts +160 -0
  180. package/src/common/namespace.ts +243 -0
  181. package/src/common/reference.ts +319 -0
  182. package/src/common/scalar.ts +173 -0
  183. package/src/common/serialization/index.ts +124 -0
  184. package/src/common/serialization/json.ts +444 -0
  185. package/src/common/union.ts +76 -0
  186. package/src/ctx.ts +497 -0
  187. package/src/helpers/header.ts +55 -0
  188. package/src/helpers/http.ts +113 -0
  189. package/src/helpers/multipart.ts +228 -0
  190. package/src/helpers/router.ts +238 -0
  191. package/src/http/index.ts +81 -0
  192. package/src/http/server/index.ts +548 -0
  193. package/src/http/server/multipart.ts +272 -0
  194. package/src/http/server/router.ts +686 -0
  195. package/src/index.ts +56 -0
  196. package/src/lib.ts +130 -0
  197. package/src/scripts/scaffold/bin.mts +781 -0
  198. package/src/testing/index.ts +10 -0
  199. package/src/util/case.ts +182 -0
  200. package/src/util/differentiate.ts +957 -0
  201. package/src/util/error.ts +28 -0
  202. package/src/util/extends.ts +43 -0
  203. package/src/util/iter.ts +85 -0
  204. package/src/util/keywords.ts +90 -0
  205. package/src/util/name.ts +33 -0
  206. package/src/util/once-queue.ts +55 -0
  207. package/src/util/openapi3.ts +53 -0
  208. package/src/util/pluralism.ts +37 -0
  209. package/src/util/scope.ts +211 -0
  210. package/src/write.ts +88 -0
  211. package/temp/tsconfig.tsbuildinfo +1 -0
  212. package/test/header.test.ts +26 -0
  213. package/test/multipart.test.ts +169 -0
  214. package/tsconfig.json +10 -0
  215. package/vitest.config.ts +4 -0
@@ -0,0 +1,10 @@
1
+ import {
2
+ TypeSpecTestLibrary,
3
+ createTestLibrary,
4
+ findTestPackageRoot,
5
+ } from "@typespec/compiler/testing";
6
+
7
+ export const HttpServerJavaScriptTestLibrary: TypeSpecTestLibrary = createTestLibrary({
8
+ name: "@typespec/http-server-js",
9
+ packageRoot: await findTestPackageRoot(import.meta.url),
10
+ });
@@ -0,0 +1,182 @@
1
+ // Copyright (c) Microsoft Corporation
2
+ // Licensed under the MIT license.
3
+
4
+ /**
5
+ * Separators recognized by the case parser.
6
+ */
7
+ const SEPARATORS = /[\s:_\-./\\]/;
8
+
9
+ /**
10
+ * Returns true if a name cannot be spoken. A name is unspeakable if:
11
+ *
12
+ * - It contains only separators and whitespace.
13
+ *
14
+ * OR
15
+ *
16
+ * - The first non-separator, non-whitespace character is a digit.
17
+ *
18
+ * @param name - a name in any case
19
+ * @returns true if the name is unspeakable
20
+ */
21
+ export function isUnspeakable(name: string): boolean {
22
+ for (const c of name) {
23
+ if (!SEPARATORS.test(c)) {
24
+ return /[0-9]/.test(c);
25
+ }
26
+ }
27
+
28
+ return true;
29
+ }
30
+
31
+ /**
32
+ * Destructures a name into its components.
33
+ *
34
+ * The following case conventions are supported:
35
+ * - PascalCase (["pascal", "case"])
36
+ * - camelCase (["camel", "case"])
37
+ * - snake_case (["snake", "case"])
38
+ * - kebab-case (["kebab", "case"])
39
+ * - dot.separated (["dot", "separated"])
40
+ * - path/separated (["path", "separated"])
41
+ * - double::colon::separated (["double", "colon", "separated"])
42
+ * - space separated (["space", "separated"])
43
+ *
44
+ * - AND any combination of the above, or any other separators or combination of separators.
45
+ *
46
+ * @param name - a name in any case
47
+ */
48
+ export function parseCase(name: string): ReCase {
49
+ const components: string[] = [];
50
+
51
+ let currentComponent = "";
52
+ let inAcronym = false;
53
+
54
+ for (let i = 0; i < name.length; i++) {
55
+ const char = name[i];
56
+
57
+ // cSpell:ignore presponse
58
+ // Special case acronym handling. We want to treat acronyms as a single component,
59
+ // but we also want the last capitalized letter in an all caps sequence to start a new
60
+ // component if the next letter is lower case.
61
+ // For example : "HTTPResponse" => ["http", "response"]
62
+ // : "OpenAIContext" => ["open", "ai", "context"]
63
+ // but : "HTTPresponse" (wrong) => ["htt", "presponse"]
64
+ // however : "HTTP_response" (okay I guess) => ["http", "response"]
65
+
66
+ // If the character is a separator or an upper case character, we push the current component and start a new one.
67
+ if (char === char.toUpperCase() && !/[0-9]/.test(char)) {
68
+ // If we're in an acronym, we need to check if the next character is lower case.
69
+ // If it is, then this is the start of a new component.
70
+ const acronymRestart =
71
+ inAcronym && /[A-Z]/.test(char) && i + 1 < name.length && /[^A-Z]/.test(name[i + 1]);
72
+
73
+ if (currentComponent.length > 0 && (acronymRestart || !inAcronym)) {
74
+ components.push(currentComponent.trim());
75
+ currentComponent = "";
76
+ }
77
+ }
78
+
79
+ if (!SEPARATORS.test(char)) {
80
+ currentComponent += char.toLowerCase();
81
+ }
82
+
83
+ inAcronym = /[A-Z]/.test(char);
84
+ }
85
+
86
+ if (currentComponent.length > 0) {
87
+ components.push(currentComponent);
88
+ }
89
+
90
+ return recase(components);
91
+ }
92
+
93
+ /**
94
+ * An object allowing a name to be converted into various case conventions.
95
+ */
96
+ export interface ReCase extends ReCaseUpper {
97
+ /**
98
+ * The components of the name with the first letter of each component capitalized and joined by an empty string.
99
+ */
100
+ readonly pascalCase: string;
101
+ /**
102
+ * The components of the name with the first letter of the second and all subsequent components capitalized and joined
103
+ * by an empty string.
104
+ */
105
+ readonly camelCase: string;
106
+
107
+ /**
108
+ * Convert the components of the name into all uppercase letters.
109
+ */
110
+ readonly upper: ReCaseUpper;
111
+ }
112
+
113
+ interface ReCaseUpper {
114
+ /**
115
+ * The components of the name.
116
+ */
117
+ readonly components: readonly string[];
118
+
119
+ /**
120
+ * The components of the name joined by underscores.
121
+ */
122
+ readonly snakeCase: string;
123
+ /**
124
+ * The components of the name joined by hyphens.
125
+ */
126
+ readonly kebabCase: string;
127
+ /**
128
+ * The components of the name joined by periods.
129
+ */
130
+ readonly dotCase: string;
131
+ /**
132
+ * The components of the name joined by slashes.
133
+ *
134
+ * This uses forward slashes in the unix convention.
135
+ */
136
+ readonly pathCase: string;
137
+
138
+ /**
139
+ * Join the components with any given string.
140
+ *
141
+ * @param separator - the separator to join the components with
142
+ */
143
+ join(separator: string): string;
144
+ }
145
+
146
+ function recase(components: readonly string[]): ReCase {
147
+ return Object.freeze({
148
+ components,
149
+ get pascalCase() {
150
+ return components
151
+ .map((component) => component[0].toUpperCase() + component.slice(1))
152
+ .join("");
153
+ },
154
+ get camelCase() {
155
+ return components
156
+ .map((component, index) =>
157
+ index === 0 ? component : component[0].toUpperCase() + component.slice(1),
158
+ )
159
+ .join("");
160
+ },
161
+ get snakeCase() {
162
+ return components.join("_");
163
+ },
164
+ get kebabCase() {
165
+ return components.join("-");
166
+ },
167
+ get dotCase() {
168
+ return components.join(".");
169
+ },
170
+ get pathCase() {
171
+ return components.join("/");
172
+ },
173
+
174
+ get upper() {
175
+ return recase(components.map((component) => component.toUpperCase()));
176
+ },
177
+
178
+ join(separator: string) {
179
+ return components.join(separator);
180
+ },
181
+ });
182
+ }