@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,31 @@
1
+ // Copyright (c) Microsoft Corporation
2
+ // Licensed under the MIT license.
3
+ /**
4
+ * Recursively collects all properties of a model, including inherited properties.
5
+ */
6
+ export function getAllProperties(model, visited = new Set()) {
7
+ if (visited.has(model))
8
+ return [];
9
+ visited.add(model);
10
+ const properties = [...model.properties.values()];
11
+ if (model.baseModel) {
12
+ properties.push(...getAllProperties(model.baseModel, visited));
13
+ }
14
+ return properties;
15
+ }
16
+ /**
17
+ * Recursively collects all operations in an interface, including those inherited from source interfaces.
18
+ */
19
+ export function getAllOperations(iface, visited = new Set()) {
20
+ if (visited.has(iface))
21
+ return [];
22
+ visited.add(iface);
23
+ const operations = [...iface.operations.values()];
24
+ if (iface.sourceInterfaces) {
25
+ for (const source of iface.sourceInterfaces) {
26
+ operations.push(...getAllOperations(source, visited));
27
+ }
28
+ }
29
+ return operations;
30
+ }
31
+ //# sourceMappingURL=extends.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extends.js","sourceRoot":"","sources":["../../../src/util/extends.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,kCAAkC;AAIlC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAY,EAAE,UAAsB,IAAI,GAAG,EAAE;IAC5E,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAElC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAEnB,MAAM,UAAU,GAAG,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;IAElD,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QACpB,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAgB,EAChB,UAA0B,IAAI,GAAG,EAAE;IAEnC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAElC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAEnB,MAAM,UAAU,GAAG,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;IAElD,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC3B,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC;YAC5C,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Returns true if a value implements the ECMAScript Iterable interface.
3
+ */
4
+ export declare function isIterable(value: unknown): value is object & Iterable<unknown>;
5
+ /**
6
+ * Concatenate multiple iterables into a single iterable.
7
+ */
8
+ export declare function cat<T>(...iterables: Iterable<T>[]): Iterable<T>;
9
+ /**
10
+ * Filter and collect an iterable into multiple groups based on a categorization function.
11
+ *
12
+ * The categorization function returns a string key for each value, and the values are returned in an object where each
13
+ * key is a category returned by the categorization function and the value is an array of values in that category.
14
+ *
15
+ * @param values - an iterable of values to categorize
16
+ * @param categorize - a categorization function that returns a string key for each value
17
+ * @returns an object where each key is a category and the value is an array of values in that category
18
+ */
19
+ export declare function categorize<T, K extends string>(values: Iterable<T>, categorize: (o: T) => K): Partial<Record<K, T[]>>;
20
+ /**
21
+ * Filter and collect an iterable into two categorizations based on a predicate function.
22
+ *
23
+ * Items for which the predicate returns true will be returned in the first array.
24
+ * Items for which the predicate returns false will be returned in the second array.
25
+ *
26
+ * @param values - an iterable of values to filter
27
+ * @param predicate - a predicate function that decides whether a value should be included in the first or second array
28
+ *
29
+ * @returns a tuple of two arrays of values filtered by the predicate
30
+ */
31
+ export declare function bifilter<T>(values: Iterable<T>, predicate: (o: T) => boolean): [T[], T[]];
32
+ /**
33
+ * Prepends a string `indentation` to each value in `values`.
34
+ *
35
+ * @param values - an iterable of strings to indent
36
+ * @param indentation - the string to prepend to the beginning of each value
37
+ */
38
+ export declare function indent(values: Iterable<string>, indentation?: string): Iterable<string>;
39
+ //# sourceMappingURL=iter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iter.d.ts","sourceRoot":"","sources":["../../../src/util/iter.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAO9E;AAED;;GAEG;AACH,wBAAiB,GAAG,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAIhE;AAED;;;;;;;;;GASG;AAEH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAC5C,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACtB,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAQzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAazF;AAED;;;;;GAKG;AACH,wBAAiB,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAE,MAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,CAI9F"}
@@ -0,0 +1,72 @@
1
+ // Copyright (c) Microsoft Corporation
2
+ // Licensed under the MIT license.
3
+ /**
4
+ * Returns true if a value implements the ECMAScript Iterable interface.
5
+ */
6
+ export function isIterable(value) {
7
+ return (typeof value === "object" &&
8
+ value !== null &&
9
+ Symbol.iterator in value &&
10
+ typeof value[Symbol.iterator] === "function");
11
+ }
12
+ /**
13
+ * Concatenate multiple iterables into a single iterable.
14
+ */
15
+ export function* cat(...iterables) {
16
+ for (const iterable of iterables) {
17
+ yield* iterable;
18
+ }
19
+ }
20
+ /**
21
+ * Filter and collect an iterable into multiple groups based on a categorization function.
22
+ *
23
+ * The categorization function returns a string key for each value, and the values are returned in an object where each
24
+ * key is a category returned by the categorization function and the value is an array of values in that category.
25
+ *
26
+ * @param values - an iterable of values to categorize
27
+ * @param categorize - a categorization function that returns a string key for each value
28
+ * @returns an object where each key is a category and the value is an array of values in that category
29
+ */
30
+ export function categorize(values, categorize) {
31
+ const result = {};
32
+ for (const value of values) {
33
+ (result[categorize(value)] ??= []).push(value);
34
+ }
35
+ return result;
36
+ }
37
+ /**
38
+ * Filter and collect an iterable into two categorizations based on a predicate function.
39
+ *
40
+ * Items for which the predicate returns true will be returned in the first array.
41
+ * Items for which the predicate returns false will be returned in the second array.
42
+ *
43
+ * @param values - an iterable of values to filter
44
+ * @param predicate - a predicate function that decides whether a value should be included in the first or second array
45
+ *
46
+ * @returns a tuple of two arrays of values filtered by the predicate
47
+ */
48
+ export function bifilter(values, predicate) {
49
+ const pass = [];
50
+ const fail = [];
51
+ for (const value of values) {
52
+ if (predicate(value)) {
53
+ pass.push(value);
54
+ }
55
+ else {
56
+ fail.push(value);
57
+ }
58
+ }
59
+ return [pass, fail];
60
+ }
61
+ /**
62
+ * Prepends a string `indentation` to each value in `values`.
63
+ *
64
+ * @param values - an iterable of strings to indent
65
+ * @param indentation - the string to prepend to the beginning of each value
66
+ */
67
+ export function* indent(values, indentation = " ") {
68
+ for (const value of values) {
69
+ yield indentation + value;
70
+ }
71
+ }
72
+ //# sourceMappingURL=iter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iter.js","sourceRoot":"","sources":["../../../src/util/iter.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,kCAAkC;AAElC;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,CAAC,QAAQ,IAAI,KAAK;QACxB,OAAQ,KAA2B,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAU,CACpE,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,SAAS,CAAC,CAAC,GAAG,CAAI,GAAG,SAAwB;IACjD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,KAAK,CAAC,CAAC,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AAEH,MAAM,UAAU,UAAU,CACxB,MAAmB,EACnB,UAAuB;IAEvB,MAAM,MAAM,GAAmB,EAAS,CAAC;IAEzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ,CAAI,MAAmB,EAAE,SAA4B;IAC3E,MAAM,IAAI,GAAQ,EAAE,CAAC;IACrB,MAAM,IAAI,GAAQ,EAAE,CAAC;IAErB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,MAAwB,EAAE,cAAsB,IAAI;IAC1E,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,WAAW,GAAG,KAAK,CAAC;IAC5B,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A set of reserved keywords that should not be used as identifiers.
3
+ */
4
+ export declare const KEYWORDS: Set<string>;
5
+ /**
6
+ * Makes a name safe to use as an identifier by prefixing it with an underscore
7
+ * if it would conflict with a keyword.
8
+ */
9
+ export declare function keywordSafe(name: string): string;
10
+ //# sourceMappingURL=keywords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../../src/util/keywords.ts"],"names":[],"mappings":"AA8EA;;GAEG;AACH,eAAO,MAAM,QAAQ,aAA8E,CAAC;AAEpG;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD"}
@@ -0,0 +1,85 @@
1
+ // Copyright (c) Microsoft Corporation
2
+ // Licensed under the MIT license.
3
+ const KEYWORDS_CONTEXTUAL = [
4
+ "any",
5
+ "boolean",
6
+ "constructor",
7
+ "declare",
8
+ "get",
9
+ "module",
10
+ "require",
11
+ "number",
12
+ "set",
13
+ "string",
14
+ ];
15
+ const KEYWORDS_STRICT = [
16
+ "as",
17
+ "implements",
18
+ "interface",
19
+ "let",
20
+ "package",
21
+ "private",
22
+ "protected",
23
+ "public",
24
+ "static",
25
+ "yield",
26
+ "symbol",
27
+ "type",
28
+ "from",
29
+ "of",
30
+ ];
31
+ const KEYWORDS_RESERVED = [
32
+ "break",
33
+ "case",
34
+ "catch",
35
+ "class",
36
+ "const",
37
+ "continue",
38
+ "debugger",
39
+ "default",
40
+ "delete",
41
+ "do",
42
+ "else",
43
+ "enum",
44
+ "export",
45
+ "extends",
46
+ "false",
47
+ "finally",
48
+ "for",
49
+ "function",
50
+ "if",
51
+ "import",
52
+ "in",
53
+ "instanceof",
54
+ "new",
55
+ "null",
56
+ "return",
57
+ "super",
58
+ "switch",
59
+ "this",
60
+ "throw",
61
+ "true",
62
+ "try",
63
+ "typeof",
64
+ "var",
65
+ "void",
66
+ "while",
67
+ "with",
68
+ "namespace",
69
+ "async",
70
+ "await",
71
+ "module",
72
+ "delete",
73
+ ];
74
+ /**
75
+ * A set of reserved keywords that should not be used as identifiers.
76
+ */
77
+ export const KEYWORDS = new Set([...KEYWORDS_STRICT, ...KEYWORDS_RESERVED, ...KEYWORDS_CONTEXTUAL]);
78
+ /**
79
+ * Makes a name safe to use as an identifier by prefixing it with an underscore
80
+ * if it would conflict with a keyword.
81
+ */
82
+ export function keywordSafe(name) {
83
+ return KEYWORDS.has(name) ? `_${name}` : name;
84
+ }
85
+ //# sourceMappingURL=keywords.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keywords.js","sourceRoot":"","sources":["../../../src/util/keywords.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,kCAAkC;AAElC,MAAM,mBAAmB,GAAG;IAC1B,KAAK;IACL,SAAS;IACT,aAAa;IACb,SAAS;IACT,KAAK;IACL,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,KAAK;IACL,QAAQ;CACT,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,IAAI;IACJ,YAAY;IACZ,WAAW;IACX,KAAK;IACL,SAAS;IACT,SAAS;IACT,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,MAAM;IACN,MAAM;IACN,IAAI;CACL,CAAC;AAEF,MAAM,iBAAiB,GAAG;IACxB,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,UAAU;IACV,UAAU;IACV,SAAS;IACT,QAAQ;IACR,IAAI;IACJ,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,KAAK;IACL,UAAU;IACV,IAAI;IACJ,QAAQ;IACR,IAAI;IACJ,YAAY;IACZ,KAAK;IACL,MAAM;IACN,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,KAAK;IACL,QAAQ;IACR,KAAK;IACL,MAAM;IACN,OAAO;IACP,MAAM;IAEN,WAAW;IACX,OAAO;IACP,OAAO;IACP,QAAQ;IACR,QAAQ;CACT,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,eAAe,EAAE,GAAG,iBAAiB,EAAE,GAAG,mBAAmB,CAAC,CAAC,CAAC;AAEpG;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Namespace, Type } from "@typespec/compiler";
2
+ /**
3
+ * A TypeSpec type that may be attached to a namespace.
4
+ */
5
+ export type NamespacedType = Extract<Type, {
6
+ namespace?: Namespace | undefined;
7
+ }>;
8
+ /**
9
+ * Computes the fully-qualified name of a TypeSpec type, i.e. `TypeSpec.boolean` for the built-in `boolean` scalar.
10
+ */
11
+ export declare function getFullyQualifiedTypeName(type: NamespacedType): string;
12
+ //# sourceMappingURL=name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../../../src/util/name.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,EAAE;IAAE,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAAA;CAAE,CAAC,CAAC;AAElF;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAStE"}
@@ -0,0 +1,26 @@
1
+ // Copyright (c) Microsoft Corporation
2
+ // Licensed under the MIT license.
3
+ /**
4
+ * Computes the fully-qualified name of a TypeSpec type, i.e. `TypeSpec.boolean` for the built-in `boolean` scalar.
5
+ */
6
+ export function getFullyQualifiedTypeName(type) {
7
+ const name = type.name ?? "<unknown>";
8
+ if (type.namespace) {
9
+ const nsPath = getFullyQualifiedNamespacePath(type.namespace);
10
+ return (nsPath[0] === "" ? nsPath.slice(1) : nsPath).join(".") + "." + name;
11
+ }
12
+ else {
13
+ return name;
14
+ }
15
+ }
16
+ function getFullyQualifiedNamespacePath(ns) {
17
+ if (ns.namespace) {
18
+ const innerPath = getFullyQualifiedNamespacePath(ns.namespace);
19
+ innerPath.push(ns.name);
20
+ return innerPath;
21
+ }
22
+ else {
23
+ return [ns.name];
24
+ }
25
+ }
26
+ //# sourceMappingURL=name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name.js","sourceRoot":"","sources":["../../../src/util/name.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,kCAAkC;AASlC;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,IAAoB;IAC5D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,WAAW,CAAC;IACtC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,MAAM,GAAG,8BAA8B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAE9D,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;IAC9E,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,8BAA8B,CAAC,EAAa;IACnD,IAAI,EAAE,CAAC,SAAS,EAAE,CAAC;QACjB,MAAM,SAAS,GAAG,8BAA8B,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/D,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A deduplicating queue that only allows elements to be enqueued once.
3
+ *
4
+ * This uses a Set to track visited elements.
5
+ */
6
+ export interface OnceQueue<T> {
7
+ /**
8
+ * Enqueue a value if it has not been enqueued before.
9
+ */
10
+ add(value: T): void;
11
+ /**
12
+ * Dequeue the next value.
13
+ */
14
+ take(): T | undefined;
15
+ /**
16
+ * Check if the queue is empty.
17
+ */
18
+ isEmpty(): boolean;
19
+ }
20
+ /**
21
+ * Creates a new OnceQueue with the given initial values.
22
+ */
23
+ export declare function createOnceQueue<T>(...initialValues: T[]): OnceQueue<T>;
24
+ //# sourceMappingURL=once-queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"once-queue.d.ts","sourceRoot":"","sources":["../../../src/util/once-queue.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACpB;;OAEG;IACH,IAAI,IAAI,CAAC,GAAG,SAAS,CAAC;IACtB;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,aAAa,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CA4BtE"}
@@ -0,0 +1,34 @@
1
+ // Copyright (c) Microsoft Corporation
2
+ // Licensed under the MIT license.
3
+ /**
4
+ * Creates a new OnceQueue with the given initial values.
5
+ */
6
+ export function createOnceQueue(...initialValues) {
7
+ const visited = new Set();
8
+ const queue = [];
9
+ let idx = 0;
10
+ const oncequeue = {
11
+ add(value) {
12
+ if (!visited.has(value)) {
13
+ visited.add(value);
14
+ queue.push(value);
15
+ }
16
+ },
17
+ take() {
18
+ if (idx < queue.length) {
19
+ return queue[idx++];
20
+ }
21
+ else {
22
+ return undefined;
23
+ }
24
+ },
25
+ isEmpty() {
26
+ return idx >= queue.length;
27
+ },
28
+ };
29
+ for (const value of initialValues) {
30
+ oncequeue.add(value);
31
+ }
32
+ return oncequeue;
33
+ }
34
+ //# sourceMappingURL=once-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"once-queue.js","sourceRoot":"","sources":["../../../src/util/once-queue.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,kCAAkC;AAsBlC;;GAEG;AACH,MAAM,UAAU,eAAe,CAAI,GAAG,aAAkB;IACtD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAK,CAAC;IAC7B,MAAM,KAAK,GAAG,EAAS,CAAC;IACxB,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,MAAM,SAAS,GAAiB;QAC9B,GAAG,CAAC,KAAQ;YACV,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACnB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QACD,IAAI;YACF,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;QACD,OAAO;YACL,OAAO,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC;QAC7B,CAAC;KACF,CAAC;IAEF,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE,CAAC;QAClC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Program, Service } from "@typespec/compiler";
2
+ import type { OpenAPI3ServiceRecord, SupportedOpenAPIDocuments } from "@typespec/openapi3";
3
+ /**
4
+ * Attempts to import the OpenAPI 3 emitter if it is installed.
5
+ *
6
+ * @returns the OpenAPI 3 emitter module or undefined
7
+ */
8
+ export declare function getOpenApi3Emitter(): Promise<typeof import("@typespec/openapi3") | undefined>;
9
+ /**
10
+ * Gets the OpenAPI 3 service record for a given service.
11
+ *
12
+ * @param program - the program in which the service occurs
13
+ * @param service - the service to check
14
+ */
15
+ export declare function getOpenApi3ServiceRecord(program: Program, service: Service): Promise<OpenAPI3ServiceRecord | undefined>;
16
+ /**
17
+ * Determines if an OpenAPI3 document can be generated for the given service.
18
+ *
19
+ * @param program - the program in which the service occurs
20
+ * @param service - the service to check
21
+ */
22
+ export declare function tryGetOpenApi3(program: Program, service: Service): Promise<SupportedOpenAPIDocuments | undefined>;
23
+ //# sourceMappingURL=openapi3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi3.d.ts","sourceRoot":"","sources":["../../../src/util/openapi3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAE3F;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,cAAc,oBAAoB,CAAC,GAAG,SAAS,CAAC,CAE7F;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAY5C;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC,CAQhD"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Attempts to import the OpenAPI 3 emitter if it is installed.
3
+ *
4
+ * @returns the OpenAPI 3 emitter module or undefined
5
+ */
6
+ export function getOpenApi3Emitter() {
7
+ return import("@typespec/openapi3").catch(() => undefined);
8
+ }
9
+ /**
10
+ * Gets the OpenAPI 3 service record for a given service.
11
+ *
12
+ * @param program - the program in which the service occurs
13
+ * @param service - the service to check
14
+ */
15
+ export async function getOpenApi3ServiceRecord(program, service) {
16
+ const openapi3 = await getOpenApi3Emitter();
17
+ if (!openapi3)
18
+ return undefined;
19
+ const serviceRecords = await openapi3.getOpenAPI3(program, {
20
+ "include-x-typespec-name": "never",
21
+ "omit-unreachable-types": true,
22
+ "safeint-strategy": "int64",
23
+ });
24
+ return serviceRecords.find((r) => r.service === service);
25
+ }
26
+ /**
27
+ * Determines if an OpenAPI3 document can be generated for the given service.
28
+ *
29
+ * @param program - the program in which the service occurs
30
+ * @param service - the service to check
31
+ */
32
+ export async function tryGetOpenApi3(program, service) {
33
+ const serviceRecord = await getOpenApi3ServiceRecord(program, service);
34
+ if (!serviceRecord)
35
+ return undefined;
36
+ if (serviceRecord.versioned)
37
+ return undefined;
38
+ return serviceRecord.document;
39
+ }
40
+ //# sourceMappingURL=openapi3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi3.js","sourceRoot":"","sources":["../../../src/util/openapi3.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,MAAM,CAAC,oBAAoB,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAAgB,EAChB,OAAgB;IAEhB,MAAM,QAAQ,GAAG,MAAM,kBAAkB,EAAE,CAAC;IAE5C,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAEhC,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE;QACzD,yBAAyB,EAAE,OAAO;QAClC,wBAAwB,EAAE,IAAI;QAC9B,kBAAkB,EAAE,OAAO;KAC5B,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAgB,EAChB,OAAgB;IAEhB,MAAM,aAAa,GAAG,MAAM,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAEvE,IAAI,CAAC,aAAa;QAAE,OAAO,SAAS,CAAC;IAErC,IAAI,aAAa,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IAE9C,OAAO,aAAa,CAAC,QAAQ,CAAC;AAChC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Provides an alternative name for anonymous TypeSpec.Array elements.
3
+ * @param typeName
4
+ * @returns
5
+ */
6
+ export declare function getArrayElementName(typeName: string): string;
7
+ /**
8
+ * Provides an alternative name for anonymous TypeSpec.Record values.
9
+ * @param typeName
10
+ * @returns
11
+ */
12
+ export declare function getRecordValueName(typeName: string): string;
13
+ /**
14
+ * Produces the name of an array type for a given base type.
15
+ *
16
+ * If the type name is a simple identifier, this will use the `[]` syntax,
17
+ * otherwise it will use the `Array<>` type constructor.
18
+ *
19
+ * @param typeName - the base type to make an array of
20
+ * @returns a good representation of an array of the base type
21
+ */
22
+ export declare function asArrayType(typeName: string): string;
23
+ //# sourceMappingURL=pluralism.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluralism.d.ts","sourceRoot":"","sources":["../../../src/util/pluralism.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMpD"}
@@ -0,0 +1,36 @@
1
+ // Copyright (c) Microsoft Corporation
2
+ // Licensed under the MIT license.
3
+ /**
4
+ * Provides an alternative name for anonymous TypeSpec.Array elements.
5
+ * @param typeName
6
+ * @returns
7
+ */
8
+ export function getArrayElementName(typeName) {
9
+ return typeName + "Element";
10
+ }
11
+ /**
12
+ * Provides an alternative name for anonymous TypeSpec.Record values.
13
+ * @param typeName
14
+ * @returns
15
+ */
16
+ export function getRecordValueName(typeName) {
17
+ return typeName + "Value";
18
+ }
19
+ /**
20
+ * Produces the name of an array type for a given base type.
21
+ *
22
+ * If the type name is a simple identifier, this will use the `[]` syntax,
23
+ * otherwise it will use the `Array<>` type constructor.
24
+ *
25
+ * @param typeName - the base type to make an array of
26
+ * @returns a good representation of an array of the base type
27
+ */
28
+ export function asArrayType(typeName) {
29
+ if (/^[a-zA-Z_]+$/.test(typeName)) {
30
+ return typeName + "[]";
31
+ }
32
+ else {
33
+ return `Array<${typeName}>`;
34
+ }
35
+ }
36
+ //# sourceMappingURL=pluralism.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluralism.js","sourceRoot":"","sources":["../../../src/util/pluralism.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,kCAAkC;AAElC;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAClD,OAAO,QAAQ,GAAG,SAAS,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,OAAO,QAAQ,GAAG,OAAO,CAAC;AAC5B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,IAAI,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,OAAO,QAAQ,GAAG,IAAI,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,QAAQ,GAAG,CAAC;IAC9B,CAAC;AACH,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { DiagnosticTarget, NoTarget } from "@typespec/compiler";
2
+ import { JsContext } from "../ctx.js";
3
+ /**
4
+ * A conceptual lexical scope.
5
+ */
6
+ export interface Scope {
7
+ /**
8
+ * Declare a name in the scope, applying the appropriate resolution strategy if necessary.
9
+ *
10
+ * @param primaryName - the primary name we want to declare in this scope
11
+ * @param options - options for the declaration
12
+ * @returns the name that was finally declared in the scope
13
+ */
14
+ declare(primaryName: string, options?: DeclarationOptions): string;
15
+ /**
16
+ * Determines whether or not a given name is declared in the scope.
17
+ *
18
+ * @param name - the name to check for declaration
19
+ */
20
+ isDeclared(name: string): boolean;
21
+ }
22
+ export interface DeclarationOptions {
23
+ /**
24
+ * The source of the declaration, to be used when raising diagnostics.
25
+ *
26
+ * Default: NoTarget
27
+ */
28
+ source?: DiagnosticTarget | typeof NoTarget;
29
+ /**
30
+ * The resolution strategy to use if the declared name conflicts with an already declared name.
31
+ *
32
+ * Default: "shadow"
33
+ */
34
+ resolutionStrategy?: ResolutionStrategy;
35
+ }
36
+ /**
37
+ * A strategy to use when attempting to resolve naming conflicts. This can be one of the following types:
38
+ *
39
+ * - `none`: no attempt will be made to resolve the naming conflict.
40
+ * - `shadow`: if the scope does not directly declare the name, this declaration will shadow it.
41
+ * - `prefix`: if the name is already declared, a prefix will be added to the name to resolve the conflict.
42
+ * - `alt-name`: if the name is already declared, an alternative name will be used to resolve the conflict.
43
+ */
44
+ export type ResolutionStrategy = PrefixResolution | AltNameResolution | "shadow" | "none";
45
+ /**
46
+ * A resolution strategy that prepends a prefix.
47
+ */
48
+ export interface PrefixResolution {
49
+ kind: "prefix";
50
+ /**
51
+ * The prefix to append to the name.
52
+ *
53
+ * Default: "_".
54
+ */
55
+ prefix?: string;
56
+ /**
57
+ * Whether or not to repeat the prefix until the conflict is resolved.
58
+ */
59
+ repeated?: boolean;
60
+ /**
61
+ * Whether or not the name should shadow existing declarations.
62
+ *
63
+ * This setting applies to the primary name as well, so if the primary name is not own-declared in the scope, no
64
+ * prefix will be added.
65
+ */
66
+ shadow?: boolean;
67
+ }
68
+ /**
69
+ * A resolution strategy that attempts to use an alternative name to resolve conflicts.
70
+ */
71
+ export interface AltNameResolution {
72
+ kind: "alt-name";
73
+ /**
74
+ * The alternative name for this declaration.
75
+ */
76
+ altName: string;
77
+ }
78
+ /**
79
+ * Create a new scope.
80
+ *
81
+ * @param ctx - the JS emitter context.
82
+ * @param parent - an optional parent scope for this scope. It will consider declarations in the parent scope for some conflicts.
83
+ */
84
+ export declare function createScope(ctx: JsContext, parent?: Scope): Scope;
85
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../src/util/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAAC;IAEnE;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACnC;AAED,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,QAAQ,CAAC;IAC5C;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAOD;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG,gBAAgB,GAAG,iBAAiB,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,UAAU,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAWD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,GAAE,KAAiB,GAAG,KAAK,CAwG5E"}