@typespec/http 0.41.0

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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +106 -0
  3. package/dist/src/content-types.d.ts +15 -0
  4. package/dist/src/content-types.d.ts.map +1 -0
  5. package/dist/src/content-types.js +42 -0
  6. package/dist/src/content-types.js.map +1 -0
  7. package/dist/src/decorators.d.ts +82 -0
  8. package/dist/src/decorators.d.ts.map +1 -0
  9. package/dist/src/decorators.js +513 -0
  10. package/dist/src/decorators.js.map +1 -0
  11. package/dist/src/index.d.ts +11 -0
  12. package/dist/src/index.d.ts.map +1 -0
  13. package/dist/src/index.js +11 -0
  14. package/dist/src/index.js.map +1 -0
  15. package/dist/src/lib.d.ts +294 -0
  16. package/dist/src/lib.d.ts.map +1 -0
  17. package/dist/src/lib.js +121 -0
  18. package/dist/src/lib.js.map +1 -0
  19. package/dist/src/metadata.d.ts +129 -0
  20. package/dist/src/metadata.d.ts.map +1 -0
  21. package/dist/src/metadata.js +323 -0
  22. package/dist/src/metadata.js.map +1 -0
  23. package/dist/src/operations.d.ts +31 -0
  24. package/dist/src/operations.d.ts.map +1 -0
  25. package/dist/src/operations.js +162 -0
  26. package/dist/src/operations.js.map +1 -0
  27. package/dist/src/parameters.d.ts +4 -0
  28. package/dist/src/parameters.d.ts.map +1 -0
  29. package/dist/src/parameters.js +142 -0
  30. package/dist/src/parameters.js.map +1 -0
  31. package/dist/src/responses.d.ts +7 -0
  32. package/dist/src/responses.d.ts.map +1 -0
  33. package/dist/src/responses.js +186 -0
  34. package/dist/src/responses.js.map +1 -0
  35. package/dist/src/route.d.ts +23 -0
  36. package/dist/src/route.d.ts.map +1 -0
  37. package/dist/src/route.js +149 -0
  38. package/dist/src/route.js.map +1 -0
  39. package/dist/src/testing/index.d.ts +3 -0
  40. package/dist/src/testing/index.d.ts.map +1 -0
  41. package/dist/src/testing/index.js +8 -0
  42. package/dist/src/testing/index.js.map +1 -0
  43. package/dist/src/types.d.ts +254 -0
  44. package/dist/src/types.d.ts.map +1 -0
  45. package/dist/src/types.js +2 -0
  46. package/dist/src/types.js.map +1 -0
  47. package/dist/src/utils.d.ts +8 -0
  48. package/dist/src/utils.d.ts.map +1 -0
  49. package/dist/src/utils.js +11 -0
  50. package/dist/src/utils.js.map +1 -0
  51. package/dist/src/validate.d.ts +3 -0
  52. package/dist/src/validate.d.ts.map +1 -0
  53. package/dist/src/validate.js +9 -0
  54. package/dist/src/validate.js.map +1 -0
  55. package/lib/auth.tsp +185 -0
  56. package/lib/http-decorators.tsp +206 -0
  57. package/lib/http.tsp +57 -0
  58. package/package.json +72 -0
@@ -0,0 +1,294 @@
1
+ declare const httpLib: import("@typespec/compiler").TypeSpecLibrary<{
2
+ "http-verb-duplicate": {
3
+ readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>;
4
+ };
5
+ "http-verb-wrong-type": {
6
+ readonly default: import("@typespec/compiler").CallableMessage<["verb", "entityKind"]>;
7
+ };
8
+ "missing-path-param": {
9
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
10
+ };
11
+ "optional-path-param": {
12
+ readonly default: import("@typespec/compiler").CallableMessage<["paramName"]>;
13
+ };
14
+ "missing-server-param": {
15
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
16
+ };
17
+ "duplicate-body": {
18
+ readonly default: "Operation has multiple @body parameters declared";
19
+ readonly duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body";
20
+ readonly bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body";
21
+ };
22
+ "duplicate-route-decorator": {
23
+ readonly namespace: "@route was defined twice on this namespace and has different values.";
24
+ };
25
+ "operation-param-duplicate-type": {
26
+ readonly default: import("@typespec/compiler").CallableMessage<["paramName", "types"]>;
27
+ };
28
+ "duplicate-operation": {
29
+ readonly default: import("@typespec/compiler").CallableMessage<["operationName", "verb", "path"]>;
30
+ };
31
+ "status-code-invalid": {
32
+ readonly default: "statusCode value must be a numeric or string literal or union of numeric or string literals";
33
+ readonly value: "statusCode value must be a three digit code between 100 and 599";
34
+ };
35
+ "content-type-string": {
36
+ readonly default: "contentType parameter must be a string literal or union of string literals";
37
+ };
38
+ "duplicate-response": {
39
+ readonly default: import("@typespec/compiler").CallableMessage<["contentType", "statusCode"]>;
40
+ };
41
+ "content-type-ignored": {
42
+ readonly default: "`Content-Type` header ignored because there is no body.";
43
+ };
44
+ "no-routes": {
45
+ readonly default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service.";
46
+ };
47
+ "invalid-type-for-auth": {
48
+ readonly default: import("@typespec/compiler").CallableMessage<["kind"]>;
49
+ };
50
+ "shared-boolean": {
51
+ readonly default: "shared parameter must be a boolean.";
52
+ };
53
+ "write-visibility-not-supported": {
54
+ readonly default: "@visibility(\"write\") is not supported. Use @visibility(\"update\"), @visibility(\"create\") or @visibility(\"create\", \"update\") as appropriate.";
55
+ };
56
+ "multipart-model": {
57
+ readonly default: "Multipart request body must be a model.";
58
+ };
59
+ }, Record<string, any>>;
60
+ declare const reportDiagnostic: <C extends "http-verb-duplicate" | "http-verb-wrong-type" | "missing-path-param" | "optional-path-param" | "missing-server-param" | "duplicate-body" | "duplicate-route-decorator" | "operation-param-duplicate-type" | "duplicate-operation" | "status-code-invalid" | "content-type-string" | "duplicate-response" | "content-type-ignored" | "no-routes" | "invalid-type-for-auth" | "shared-boolean" | "write-visibility-not-supported" | "multipart-model", M extends keyof {
61
+ "http-verb-duplicate": {
62
+ readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>;
63
+ };
64
+ "http-verb-wrong-type": {
65
+ readonly default: import("@typespec/compiler").CallableMessage<["verb", "entityKind"]>;
66
+ };
67
+ "missing-path-param": {
68
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
69
+ };
70
+ "optional-path-param": {
71
+ readonly default: import("@typespec/compiler").CallableMessage<["paramName"]>;
72
+ };
73
+ "missing-server-param": {
74
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
75
+ };
76
+ "duplicate-body": {
77
+ readonly default: "Operation has multiple @body parameters declared";
78
+ readonly duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body";
79
+ readonly bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body";
80
+ };
81
+ "duplicate-route-decorator": {
82
+ readonly namespace: "@route was defined twice on this namespace and has different values.";
83
+ };
84
+ "operation-param-duplicate-type": {
85
+ readonly default: import("@typespec/compiler").CallableMessage<["paramName", "types"]>;
86
+ };
87
+ "duplicate-operation": {
88
+ readonly default: import("@typespec/compiler").CallableMessage<["operationName", "verb", "path"]>;
89
+ };
90
+ "status-code-invalid": {
91
+ readonly default: "statusCode value must be a numeric or string literal or union of numeric or string literals";
92
+ readonly value: "statusCode value must be a three digit code between 100 and 599";
93
+ };
94
+ "content-type-string": {
95
+ readonly default: "contentType parameter must be a string literal or union of string literals";
96
+ };
97
+ "duplicate-response": {
98
+ readonly default: import("@typespec/compiler").CallableMessage<["contentType", "statusCode"]>;
99
+ };
100
+ "content-type-ignored": {
101
+ readonly default: "`Content-Type` header ignored because there is no body.";
102
+ };
103
+ "no-routes": {
104
+ readonly default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service.";
105
+ };
106
+ "invalid-type-for-auth": {
107
+ readonly default: import("@typespec/compiler").CallableMessage<["kind"]>;
108
+ };
109
+ "shared-boolean": {
110
+ readonly default: "shared parameter must be a boolean.";
111
+ };
112
+ "write-visibility-not-supported": {
113
+ readonly default: "@visibility(\"write\") is not supported. Use @visibility(\"update\"), @visibility(\"create\") or @visibility(\"create\", \"update\") as appropriate.";
114
+ };
115
+ "multipart-model": {
116
+ readonly default: "Multipart request body must be a model.";
117
+ };
118
+ }[C]>(program: import("@typespec/compiler").Program, diag: import("@typespec/compiler").DiagnosticReport<{
119
+ "http-verb-duplicate": {
120
+ readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>;
121
+ };
122
+ "http-verb-wrong-type": {
123
+ readonly default: import("@typespec/compiler").CallableMessage<["verb", "entityKind"]>;
124
+ };
125
+ "missing-path-param": {
126
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
127
+ };
128
+ "optional-path-param": {
129
+ readonly default: import("@typespec/compiler").CallableMessage<["paramName"]>;
130
+ };
131
+ "missing-server-param": {
132
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
133
+ };
134
+ "duplicate-body": {
135
+ readonly default: "Operation has multiple @body parameters declared";
136
+ readonly duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body";
137
+ readonly bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body";
138
+ };
139
+ "duplicate-route-decorator": {
140
+ readonly namespace: "@route was defined twice on this namespace and has different values.";
141
+ };
142
+ "operation-param-duplicate-type": {
143
+ readonly default: import("@typespec/compiler").CallableMessage<["paramName", "types"]>;
144
+ };
145
+ "duplicate-operation": {
146
+ readonly default: import("@typespec/compiler").CallableMessage<["operationName", "verb", "path"]>;
147
+ };
148
+ "status-code-invalid": {
149
+ readonly default: "statusCode value must be a numeric or string literal or union of numeric or string literals";
150
+ readonly value: "statusCode value must be a three digit code between 100 and 599";
151
+ };
152
+ "content-type-string": {
153
+ readonly default: "contentType parameter must be a string literal or union of string literals";
154
+ };
155
+ "duplicate-response": {
156
+ readonly default: import("@typespec/compiler").CallableMessage<["contentType", "statusCode"]>;
157
+ };
158
+ "content-type-ignored": {
159
+ readonly default: "`Content-Type` header ignored because there is no body.";
160
+ };
161
+ "no-routes": {
162
+ readonly default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service.";
163
+ };
164
+ "invalid-type-for-auth": {
165
+ readonly default: import("@typespec/compiler").CallableMessage<["kind"]>;
166
+ };
167
+ "shared-boolean": {
168
+ readonly default: "shared parameter must be a boolean.";
169
+ };
170
+ "write-visibility-not-supported": {
171
+ readonly default: "@visibility(\"write\") is not supported. Use @visibility(\"update\"), @visibility(\"create\") or @visibility(\"create\", \"update\") as appropriate.";
172
+ };
173
+ "multipart-model": {
174
+ readonly default: "Multipart request body must be a model.";
175
+ };
176
+ }, C, M>) => void, createDiagnostic: <C extends "http-verb-duplicate" | "http-verb-wrong-type" | "missing-path-param" | "optional-path-param" | "missing-server-param" | "duplicate-body" | "duplicate-route-decorator" | "operation-param-duplicate-type" | "duplicate-operation" | "status-code-invalid" | "content-type-string" | "duplicate-response" | "content-type-ignored" | "no-routes" | "invalid-type-for-auth" | "shared-boolean" | "write-visibility-not-supported" | "multipart-model", M extends keyof {
177
+ "http-verb-duplicate": {
178
+ readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>;
179
+ };
180
+ "http-verb-wrong-type": {
181
+ readonly default: import("@typespec/compiler").CallableMessage<["verb", "entityKind"]>;
182
+ };
183
+ "missing-path-param": {
184
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
185
+ };
186
+ "optional-path-param": {
187
+ readonly default: import("@typespec/compiler").CallableMessage<["paramName"]>;
188
+ };
189
+ "missing-server-param": {
190
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
191
+ };
192
+ "duplicate-body": {
193
+ readonly default: "Operation has multiple @body parameters declared";
194
+ readonly duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body";
195
+ readonly bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body";
196
+ };
197
+ "duplicate-route-decorator": {
198
+ readonly namespace: "@route was defined twice on this namespace and has different values.";
199
+ };
200
+ "operation-param-duplicate-type": {
201
+ readonly default: import("@typespec/compiler").CallableMessage<["paramName", "types"]>;
202
+ };
203
+ "duplicate-operation": {
204
+ readonly default: import("@typespec/compiler").CallableMessage<["operationName", "verb", "path"]>;
205
+ };
206
+ "status-code-invalid": {
207
+ readonly default: "statusCode value must be a numeric or string literal or union of numeric or string literals";
208
+ readonly value: "statusCode value must be a three digit code between 100 and 599";
209
+ };
210
+ "content-type-string": {
211
+ readonly default: "contentType parameter must be a string literal or union of string literals";
212
+ };
213
+ "duplicate-response": {
214
+ readonly default: import("@typespec/compiler").CallableMessage<["contentType", "statusCode"]>;
215
+ };
216
+ "content-type-ignored": {
217
+ readonly default: "`Content-Type` header ignored because there is no body.";
218
+ };
219
+ "no-routes": {
220
+ readonly default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service.";
221
+ };
222
+ "invalid-type-for-auth": {
223
+ readonly default: import("@typespec/compiler").CallableMessage<["kind"]>;
224
+ };
225
+ "shared-boolean": {
226
+ readonly default: "shared parameter must be a boolean.";
227
+ };
228
+ "write-visibility-not-supported": {
229
+ readonly default: "@visibility(\"write\") is not supported. Use @visibility(\"update\"), @visibility(\"create\") or @visibility(\"create\", \"update\") as appropriate.";
230
+ };
231
+ "multipart-model": {
232
+ readonly default: "Multipart request body must be a model.";
233
+ };
234
+ }[C]>(diag: import("@typespec/compiler").DiagnosticReport<{
235
+ "http-verb-duplicate": {
236
+ readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>;
237
+ };
238
+ "http-verb-wrong-type": {
239
+ readonly default: import("@typespec/compiler").CallableMessage<["verb", "entityKind"]>;
240
+ };
241
+ "missing-path-param": {
242
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
243
+ };
244
+ "optional-path-param": {
245
+ readonly default: import("@typespec/compiler").CallableMessage<["paramName"]>;
246
+ };
247
+ "missing-server-param": {
248
+ readonly default: import("@typespec/compiler").CallableMessage<["param"]>;
249
+ };
250
+ "duplicate-body": {
251
+ readonly default: "Operation has multiple @body parameters declared";
252
+ readonly duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body";
253
+ readonly bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body";
254
+ };
255
+ "duplicate-route-decorator": {
256
+ readonly namespace: "@route was defined twice on this namespace and has different values.";
257
+ };
258
+ "operation-param-duplicate-type": {
259
+ readonly default: import("@typespec/compiler").CallableMessage<["paramName", "types"]>;
260
+ };
261
+ "duplicate-operation": {
262
+ readonly default: import("@typespec/compiler").CallableMessage<["operationName", "verb", "path"]>;
263
+ };
264
+ "status-code-invalid": {
265
+ readonly default: "statusCode value must be a numeric or string literal or union of numeric or string literals";
266
+ readonly value: "statusCode value must be a three digit code between 100 and 599";
267
+ };
268
+ "content-type-string": {
269
+ readonly default: "contentType parameter must be a string literal or union of string literals";
270
+ };
271
+ "duplicate-response": {
272
+ readonly default: import("@typespec/compiler").CallableMessage<["contentType", "statusCode"]>;
273
+ };
274
+ "content-type-ignored": {
275
+ readonly default: "`Content-Type` header ignored because there is no body.";
276
+ };
277
+ "no-routes": {
278
+ readonly default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service.";
279
+ };
280
+ "invalid-type-for-auth": {
281
+ readonly default: import("@typespec/compiler").CallableMessage<["kind"]>;
282
+ };
283
+ "shared-boolean": {
284
+ readonly default: "shared parameter must be a boolean.";
285
+ };
286
+ "write-visibility-not-supported": {
287
+ readonly default: "@visibility(\"write\") is not supported. Use @visibility(\"update\"), @visibility(\"create\") or @visibility(\"create\", \"update\") as appropriate.";
288
+ };
289
+ "multipart-model": {
290
+ readonly default: "Multipart request body must be a model.";
291
+ };
292
+ }, C, M>) => import("@typespec/compiler").Diagnostic, createStateSymbol: (name: string) => symbol;
293
+ export { httpLib, reportDiagnostic, createDiagnostic, createStateSymbol };
294
+ //# sourceMappingURL=lib.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AA2HA,QAAA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAAuC,CAAC;AACrD,QAAA,MAAQ,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sDAAE,iBAAiB,0BAAY,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,121 @@
1
+ import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler";
2
+ const libDefinition = {
3
+ name: "@typespec/http",
4
+ diagnostics: {
5
+ "http-verb-duplicate": {
6
+ severity: "error",
7
+ messages: {
8
+ default: paramMessage `HTTP verb already applied to ${"entityName"}`,
9
+ },
10
+ },
11
+ "http-verb-wrong-type": {
12
+ severity: "error",
13
+ messages: {
14
+ default: paramMessage `Cannot use @${"verb"} on a ${"entityKind"}`,
15
+ },
16
+ },
17
+ "missing-path-param": {
18
+ severity: "error",
19
+ messages: {
20
+ default: paramMessage `Path contains parameter ${"param"} but wasn't found in given parameters`,
21
+ },
22
+ },
23
+ "optional-path-param": {
24
+ severity: "error",
25
+ messages: {
26
+ default: paramMessage `Path parameter '${"paramName"}' cannot be optional.`,
27
+ },
28
+ },
29
+ "missing-server-param": {
30
+ severity: "error",
31
+ messages: {
32
+ default: paramMessage `Server url contains parameter '${"param"}' but wasn't found in given parameters`,
33
+ },
34
+ },
35
+ "duplicate-body": {
36
+ severity: "error",
37
+ messages: {
38
+ default: "Operation has multiple @body parameters declared",
39
+ duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body",
40
+ bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body",
41
+ },
42
+ },
43
+ "duplicate-route-decorator": {
44
+ severity: "error",
45
+ messages: {
46
+ namespace: "@route was defined twice on this namespace and has different values.",
47
+ },
48
+ },
49
+ "operation-param-duplicate-type": {
50
+ severity: "error",
51
+ messages: {
52
+ default: paramMessage `Param ${"paramName"} has multiple types: [${"types"}]`,
53
+ },
54
+ },
55
+ "duplicate-operation": {
56
+ severity: "error",
57
+ messages: {
58
+ default: paramMessage `Duplicate operation "${"operationName"}" routed at "${"verb"} ${"path"}".`,
59
+ },
60
+ },
61
+ "status-code-invalid": {
62
+ severity: "error",
63
+ messages: {
64
+ default: "statusCode value must be a numeric or string literal or union of numeric or string literals",
65
+ value: "statusCode value must be a three digit code between 100 and 599",
66
+ },
67
+ },
68
+ "content-type-string": {
69
+ severity: "error",
70
+ messages: {
71
+ default: "contentType parameter must be a string literal or union of string literals",
72
+ },
73
+ },
74
+ "duplicate-response": {
75
+ severity: "error",
76
+ messages: {
77
+ default: paramMessage `Multiple return types for content type ${"contentType"} and status code ${"statusCode"}`,
78
+ },
79
+ },
80
+ "content-type-ignored": {
81
+ severity: "warning",
82
+ messages: {
83
+ default: "`Content-Type` header ignored because there is no body.",
84
+ },
85
+ },
86
+ "no-routes": {
87
+ severity: "warning",
88
+ messages: {
89
+ default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service.",
90
+ },
91
+ },
92
+ "invalid-type-for-auth": {
93
+ severity: "error",
94
+ messages: {
95
+ default: paramMessage `@useAuth ${"kind"} only accept Auth model, Tuple of auth model or union of auth model.`,
96
+ },
97
+ },
98
+ "shared-boolean": {
99
+ severity: "error",
100
+ messages: {
101
+ default: "shared parameter must be a boolean.",
102
+ },
103
+ },
104
+ "write-visibility-not-supported": {
105
+ severity: "warning",
106
+ messages: {
107
+ default: `@visibility("write") is not supported. Use @visibility("update"), @visibility("create") or @visibility("create", "update") as appropriate.`,
108
+ },
109
+ },
110
+ "multipart-model": {
111
+ severity: "error",
112
+ messages: {
113
+ default: "Multipart request body must be a model.",
114
+ },
115
+ },
116
+ },
117
+ };
118
+ const httpLib = createTypeSpecLibrary(libDefinition);
119
+ const { reportDiagnostic, createDiagnostic, createStateSymbol } = httpLib;
120
+ export { httpLib, reportDiagnostic, createDiagnostic, createStateSymbol };
121
+ //# sourceMappingURL=lib.js.map
@@ -0,0 +1 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CAAC,CAAC;AACrD,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,129 @@
1
+ import { DiagnosticCollector, ModelProperty, Program, Type } from "@typespec/compiler";
2
+ import { HttpVerb } from "./types.js";
3
+ /**
4
+ * Flags enum representation of well-known visibilities that are used in
5
+ * REST API.
6
+ */
7
+ export declare enum Visibility {
8
+ Read = 1,
9
+ Create = 2,
10
+ Update = 4,
11
+ Delete = 8,
12
+ Query = 16,
13
+ All = 31,
14
+ /**
15
+ * Additional flag to indicate when something is nested in a collection
16
+ * and therefore no metadata is applicable.
17
+ */
18
+ Item = 1048576
19
+ }
20
+ /**
21
+ * Provides a naming suffix to create a unique name for a type with this
22
+ * visibility.
23
+ *
24
+ * `Visibility.All` gets empty suffix, otherwise visibilities are joined in
25
+ * pascal-case with `Or`. And `Item` is if `Visibility.Item` is produced.
26
+ *
27
+ * Examples:
28
+ * - Visibility.All => ""
29
+ * - Visibility.Read => "Read"
30
+ * - Visibility.Create | Visibility.Update => "CreateOrUpdate"
31
+ * - Visibility.Create | Visibility.Item => "CreateItem"
32
+ * - Visibility.Create | Visibility.Update | Visibility.Item => "CreateOrUpdateItem"
33
+ * */
34
+ export declare function getVisibilitySuffix(visibility: Visibility): string;
35
+ /**
36
+ * Determines the visibility to use for a request with the given verb.
37
+ *
38
+ * - GET | HEAD => Visibility.Query
39
+ * - POST => Visibility.Update
40
+ * - PUT => Visibility.Create | Update
41
+ * - DELETE => Visibility.Delete
42
+ */
43
+ export declare function getRequestVisibility(verb: HttpVerb): Visibility;
44
+ /**
45
+ * Walks the given type and collects all applicable metadata and `@body`
46
+ * properties recursively.
47
+ */
48
+ export declare function gatherMetadata(program: Program, diagnostics: DiagnosticCollector, // currently unused, but reserved for future diagnostics
49
+ type: Type, visibility: Visibility, isMetadataCallback?: typeof isMetadata): Set<ModelProperty>;
50
+ /**
51
+ * Determines if a property is metadata. A property is defined to be
52
+ * metadata if it is marked `@header`, `@query`, `@path`, or `@statusCode`.
53
+ */
54
+ export declare function isMetadata(program: Program, property: ModelProperty): boolean;
55
+ /**
56
+ * Determines if the given property is visible with the given visibility.
57
+ */
58
+ export declare function isVisible(program: Program, property: ModelProperty, visibility: Visibility): boolean;
59
+ /**
60
+ * Determines if the given property is metadata that is applicable with the
61
+ * given visibility.
62
+ *
63
+ * - No metadata is applicable with Visibility.Item present.
64
+ * - If only Visibility.Read is present, then only `@header` and `@status`
65
+ * properties are applicable.
66
+ * - If Visibility.Read is not present, all metadata properties other than
67
+ * `@statusCode` are applicable.
68
+ */
69
+ export declare function isApplicableMetadata(program: Program, property: ModelProperty, visibility: Visibility, isMetadataCallback?: typeof isMetadata): boolean;
70
+ /**
71
+ * Determines if the given property is metadata or marked `@body` and
72
+ * applicable with the given visibility.
73
+ */
74
+ export declare function isApplicableMetadataOrBody(program: Program, property: ModelProperty, visibility: Visibility, isMetadataCallback?: typeof isMetadata): boolean;
75
+ /**
76
+ * Provides information about changes that happen to a data type's payload
77
+ * when inapplicable metadata is added or invisible properties are removed.
78
+ *
79
+ * Results are computed on demand and expensive computations are memoized.
80
+ */
81
+ export interface MetadataInfo {
82
+ /**
83
+ * Determines if the given type is a model that becomes empty once
84
+ * applicable metadata is removed and visibility is applied.
85
+ *
86
+ * Note that a model is not considered emptied if it was already empty in
87
+ * the first place, or has a base model or indexer.
88
+ *
89
+ * When the type of a property is emptied by visibility, the property
90
+ * itself is also removed.
91
+ */
92
+ isEmptied(type: Type | undefined, visibility: Visibility): boolean;
93
+ /**
94
+ * Determines if the given type is transformed by applying the given
95
+ * visibility and removing invisible properties or adding inapplicable
96
+ * metadata properties.
97
+ */
98
+ isTransformed(type: Type | undefined, visibility: Visibility): boolean;
99
+ /**
100
+ * Determines if the given property is part of the request or response
101
+ * payload and not applicable metadata (@see isApplicableMetadata) or
102
+ * filtered out by the given visibility.
103
+ */
104
+ isPayloadProperty(property: ModelProperty, visibility: Visibility): boolean;
105
+ /**
106
+ * Determines if the given property is optional in the request or
107
+ * response payload for the given visibility.
108
+ */
109
+ isOptional(property: ModelProperty, visibility: Visibility): boolean;
110
+ /**
111
+ * If type is an anonymous model, tries to find a named model that has the
112
+ * same set of properties when non-payload properties are excluded.
113
+ */
114
+ getEffectivePayloadType(type: Type, visibility: Visibility): Type;
115
+ }
116
+ export interface MetadataInfoOptions {
117
+ /**
118
+ * Optional callback to indicate that a property can be shared with
119
+ * `Visibility.All` representation even for visibilities where it is not
120
+ * visible.
121
+ *
122
+ * This is used, for example, in OpenAPI emit where a property can be
123
+ * marked `readOnly: true` to represent @visibility("read") without
124
+ * creating a separate schema schema for Visibility.Read.
125
+ */
126
+ canShareProperty?(property: ModelProperty): boolean;
127
+ }
128
+ export declare function createMetadataInfo(program: Program, options?: MetadataInfoOptions): MetadataInfo;
129
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAInB,aAAa,EACb,OAAO,EAGP,IAAI,EAGL,MAAM,oBAAoB,CAAC;AAS5B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;GAGG;AACH,oBAAY,UAAU;IACpB,IAAI,IAAS;IACb,MAAM,IAAS;IACf,MAAM,IAAS;IACf,MAAM,IAAS;IACf,KAAK,KAAS;IAEd,GAAG,KAA0C;IAE7C;;;OAGG;IACH,IAAI,UAAU;CACf;AAkCD;;;;;;;;;;;;;MAaM;AACN,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,UAAU,UAazD;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAiB/D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5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