@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.
- package/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/src/content-types.d.ts +15 -0
- package/dist/src/content-types.d.ts.map +1 -0
- package/dist/src/content-types.js +42 -0
- package/dist/src/content-types.js.map +1 -0
- package/dist/src/decorators.d.ts +82 -0
- package/dist/src/decorators.d.ts.map +1 -0
- package/dist/src/decorators.js +513 -0
- package/dist/src/decorators.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib.d.ts +294 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +121 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/metadata.d.ts +129 -0
- package/dist/src/metadata.d.ts.map +1 -0
- package/dist/src/metadata.js +323 -0
- package/dist/src/metadata.js.map +1 -0
- package/dist/src/operations.d.ts +31 -0
- package/dist/src/operations.d.ts.map +1 -0
- package/dist/src/operations.js +162 -0
- package/dist/src/operations.js.map +1 -0
- package/dist/src/parameters.d.ts +4 -0
- package/dist/src/parameters.d.ts.map +1 -0
- package/dist/src/parameters.js +142 -0
- package/dist/src/parameters.js.map +1 -0
- package/dist/src/responses.d.ts +7 -0
- package/dist/src/responses.d.ts.map +1 -0
- package/dist/src/responses.js +186 -0
- package/dist/src/responses.js.map +1 -0
- package/dist/src/route.d.ts +23 -0
- package/dist/src/route.d.ts.map +1 -0
- package/dist/src/route.js +149 -0
- package/dist/src/route.js.map +1 -0
- package/dist/src/testing/index.d.ts +3 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +8 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/types.d.ts +254 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +8 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +11 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/validate.d.ts +3 -0
- package/dist/src/validate.d.ts.map +1 -0
- package/dist/src/validate.js +9 -0
- package/dist/src/validate.js.map +1 -0
- package/lib/auth.tsp +185 -0
- package/lib/http-decorators.tsp +206 -0
- package/lib/http.tsp +57 -0
- package/package.json +72 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { compilerAssert, getEffectiveModelType, isVisible as isVisibleCore, Queue, TwoLevelMap, walkPropertiesInherited, } from "@typespec/compiler";
|
|
2
|
+
import { includeInapplicableMetadataInPayload, isBody, isHeader, isPathParam, isQueryParam, isStatusCode, } from "./decorators.js";
|
|
3
|
+
/**
|
|
4
|
+
* Flags enum representation of well-known visibilities that are used in
|
|
5
|
+
* REST API.
|
|
6
|
+
*/
|
|
7
|
+
export var Visibility;
|
|
8
|
+
(function (Visibility) {
|
|
9
|
+
Visibility[Visibility["Read"] = 1] = "Read";
|
|
10
|
+
Visibility[Visibility["Create"] = 2] = "Create";
|
|
11
|
+
Visibility[Visibility["Update"] = 4] = "Update";
|
|
12
|
+
Visibility[Visibility["Delete"] = 8] = "Delete";
|
|
13
|
+
Visibility[Visibility["Query"] = 16] = "Query";
|
|
14
|
+
Visibility[Visibility["All"] = 31] = "All";
|
|
15
|
+
/**
|
|
16
|
+
* Additional flag to indicate when something is nested in a collection
|
|
17
|
+
* and therefore no metadata is applicable.
|
|
18
|
+
*/
|
|
19
|
+
Visibility[Visibility["Item"] = 1048576] = "Item";
|
|
20
|
+
})(Visibility = Visibility || (Visibility = {}));
|
|
21
|
+
const visibilityToArrayMap = new Map();
|
|
22
|
+
function visibilityToArray(visibility) {
|
|
23
|
+
// Item flag is not a real visibility.
|
|
24
|
+
visibility &= ~Visibility.Item;
|
|
25
|
+
let result = visibilityToArrayMap.get(visibility);
|
|
26
|
+
if (!result) {
|
|
27
|
+
result = [];
|
|
28
|
+
if (visibility & Visibility.Read) {
|
|
29
|
+
result.push("read");
|
|
30
|
+
}
|
|
31
|
+
if (visibility & Visibility.Create) {
|
|
32
|
+
result.push("create");
|
|
33
|
+
}
|
|
34
|
+
if (visibility & Visibility.Update) {
|
|
35
|
+
result.push("update");
|
|
36
|
+
}
|
|
37
|
+
if (visibility & Visibility.Delete) {
|
|
38
|
+
result.push("delete");
|
|
39
|
+
}
|
|
40
|
+
if (visibility & Visibility.Query) {
|
|
41
|
+
result.push("query");
|
|
42
|
+
}
|
|
43
|
+
compilerAssert(result.length > 0, "invalid visibility");
|
|
44
|
+
visibilityToArrayMap.set(visibility, result);
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Provides a naming suffix to create a unique name for a type with this
|
|
50
|
+
* visibility.
|
|
51
|
+
*
|
|
52
|
+
* `Visibility.All` gets empty suffix, otherwise visibilities are joined in
|
|
53
|
+
* pascal-case with `Or`. And `Item` is if `Visibility.Item` is produced.
|
|
54
|
+
*
|
|
55
|
+
* Examples:
|
|
56
|
+
* - Visibility.All => ""
|
|
57
|
+
* - Visibility.Read => "Read"
|
|
58
|
+
* - Visibility.Create | Visibility.Update => "CreateOrUpdate"
|
|
59
|
+
* - Visibility.Create | Visibility.Item => "CreateItem"
|
|
60
|
+
* - Visibility.Create | Visibility.Update | Visibility.Item => "CreateOrUpdateItem"
|
|
61
|
+
* */
|
|
62
|
+
export function getVisibilitySuffix(visibility) {
|
|
63
|
+
let suffix = "";
|
|
64
|
+
if ((visibility & ~Visibility.Item) !== Visibility.All) {
|
|
65
|
+
const visibilities = visibilityToArray(visibility);
|
|
66
|
+
suffix += visibilities.map((v) => v[0].toUpperCase() + v.slice(1)).join("Or");
|
|
67
|
+
}
|
|
68
|
+
if (visibility & Visibility.Item) {
|
|
69
|
+
suffix += "Item";
|
|
70
|
+
}
|
|
71
|
+
return suffix;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Determines the visibility to use for a request with the given verb.
|
|
75
|
+
*
|
|
76
|
+
* - GET | HEAD => Visibility.Query
|
|
77
|
+
* - POST => Visibility.Update
|
|
78
|
+
* - PUT => Visibility.Create | Update
|
|
79
|
+
* - DELETE => Visibility.Delete
|
|
80
|
+
*/
|
|
81
|
+
export function getRequestVisibility(verb) {
|
|
82
|
+
switch (verb) {
|
|
83
|
+
case "get":
|
|
84
|
+
case "head":
|
|
85
|
+
return Visibility.Query;
|
|
86
|
+
case "post":
|
|
87
|
+
return Visibility.Create;
|
|
88
|
+
case "put":
|
|
89
|
+
return Visibility.Create | Visibility.Update;
|
|
90
|
+
case "patch":
|
|
91
|
+
return Visibility.Update;
|
|
92
|
+
case "delete":
|
|
93
|
+
return Visibility.Delete;
|
|
94
|
+
default:
|
|
95
|
+
const _assertNever = verb;
|
|
96
|
+
compilerAssert(false, "unreachable");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Walks the given type and collects all applicable metadata and `@body`
|
|
101
|
+
* properties recursively.
|
|
102
|
+
*/
|
|
103
|
+
export function gatherMetadata(program, diagnostics, // currently unused, but reserved for future diagnostics
|
|
104
|
+
type, visibility, isMetadataCallback = isMetadata) {
|
|
105
|
+
const metadata = new Map();
|
|
106
|
+
if (type.kind !== "Model" || type.indexer || type.properties.size === 0) {
|
|
107
|
+
return new Set();
|
|
108
|
+
}
|
|
109
|
+
const visited = new Set();
|
|
110
|
+
const queue = new Queue([type]);
|
|
111
|
+
while (!queue.isEmpty()) {
|
|
112
|
+
const model = queue.dequeue();
|
|
113
|
+
visited.add(model);
|
|
114
|
+
for (const property of walkPropertiesInherited(model)) {
|
|
115
|
+
if (!isVisible(program, property, visibility)) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
// ISSUE: This should probably be an error, but that's a breaking
|
|
119
|
+
// change that currently breaks some samples and tests.
|
|
120
|
+
//
|
|
121
|
+
// The traversal here is level-order so that the preferred metadata in
|
|
122
|
+
// the case of duplicates, which is the most compatible with prior
|
|
123
|
+
// behavior where nested metadata was always dropped.
|
|
124
|
+
if (metadata.has(property.name)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (isApplicableMetadataOrBody(program, property, visibility, isMetadataCallback)) {
|
|
128
|
+
metadata.set(property.name, property);
|
|
129
|
+
}
|
|
130
|
+
if (property.type.kind === "Model" &&
|
|
131
|
+
!type.indexer &&
|
|
132
|
+
type.properties.size > 0 &&
|
|
133
|
+
!visited.has(property.type)) {
|
|
134
|
+
queue.enqueue(property.type);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return new Set(metadata.values());
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Determines if a property is metadata. A property is defined to be
|
|
142
|
+
* metadata if it is marked `@header`, `@query`, `@path`, or `@statusCode`.
|
|
143
|
+
*/
|
|
144
|
+
export function isMetadata(program, property) {
|
|
145
|
+
return (isHeader(program, property) ||
|
|
146
|
+
isQueryParam(program, property) ||
|
|
147
|
+
isPathParam(program, property) ||
|
|
148
|
+
isStatusCode(program, property));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Determines if the given property is visible with the given visibility.
|
|
152
|
+
*/
|
|
153
|
+
export function isVisible(program, property, visibility) {
|
|
154
|
+
return isVisibleCore(program, property, visibilityToArray(visibility));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Determines if the given property is metadata that is applicable with the
|
|
158
|
+
* given visibility.
|
|
159
|
+
*
|
|
160
|
+
* - No metadata is applicable with Visibility.Item present.
|
|
161
|
+
* - If only Visibility.Read is present, then only `@header` and `@status`
|
|
162
|
+
* properties are applicable.
|
|
163
|
+
* - If Visibility.Read is not present, all metadata properties other than
|
|
164
|
+
* `@statusCode` are applicable.
|
|
165
|
+
*/
|
|
166
|
+
export function isApplicableMetadata(program, property, visibility, isMetadataCallback = isMetadata) {
|
|
167
|
+
return isApplicableMetadataCore(program, property, visibility, false, isMetadataCallback);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Determines if the given property is metadata or marked `@body` and
|
|
171
|
+
* applicable with the given visibility.
|
|
172
|
+
*/
|
|
173
|
+
export function isApplicableMetadataOrBody(program, property, visibility, isMetadataCallback = isMetadata) {
|
|
174
|
+
return isApplicableMetadataCore(program, property, visibility, true, isMetadataCallback);
|
|
175
|
+
}
|
|
176
|
+
function isApplicableMetadataCore(program, property, visibility, treatBodyAsMetadata, isMetadataCallback) {
|
|
177
|
+
if (visibility & Visibility.Item) {
|
|
178
|
+
return false; // no metadata is applicable to collection items
|
|
179
|
+
}
|
|
180
|
+
if (treatBodyAsMetadata && isBody(program, property)) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
if (!isMetadataCallback(program, property)) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
if (visibility === Visibility.Read) {
|
|
187
|
+
return isHeader(program, property) || isStatusCode(program, property);
|
|
188
|
+
}
|
|
189
|
+
if (!(visibility & Visibility.Read)) {
|
|
190
|
+
return !isStatusCode(program, property);
|
|
191
|
+
}
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
export function createMetadataInfo(program, options) {
|
|
195
|
+
const stateMap = new TwoLevelMap();
|
|
196
|
+
return {
|
|
197
|
+
isEmptied,
|
|
198
|
+
isTransformed,
|
|
199
|
+
isPayloadProperty,
|
|
200
|
+
isOptional,
|
|
201
|
+
getEffectivePayloadType,
|
|
202
|
+
};
|
|
203
|
+
function isEmptied(type, visibility) {
|
|
204
|
+
if (!type) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
const state = getState(type, visibility);
|
|
208
|
+
return state === 2 /* State.Emptied */;
|
|
209
|
+
}
|
|
210
|
+
function isTransformed(type, visibility) {
|
|
211
|
+
if (!type) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
const state = getState(type, visibility);
|
|
215
|
+
switch (state) {
|
|
216
|
+
case 1 /* State.Transformed */:
|
|
217
|
+
return true;
|
|
218
|
+
case 2 /* State.Emptied */:
|
|
219
|
+
return visibility === Visibility.All || !isEmptied(type, Visibility.All);
|
|
220
|
+
default:
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function getState(type, visibility) {
|
|
225
|
+
return stateMap.getOrAdd(type, visibility, () => computeState(type, visibility), 3 /* State.ComputationInProgress */);
|
|
226
|
+
}
|
|
227
|
+
function computeState(type, visibility) {
|
|
228
|
+
switch (type.kind) {
|
|
229
|
+
case "Model":
|
|
230
|
+
return computeStateForModel(type, visibility);
|
|
231
|
+
case "Union":
|
|
232
|
+
return computeStateForUnion(type, visibility);
|
|
233
|
+
default:
|
|
234
|
+
return 0 /* State.NotTransformed */;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function computeStateForModel(model, visibility) {
|
|
238
|
+
var _a;
|
|
239
|
+
if (computeIsEmptied(model, visibility)) {
|
|
240
|
+
return 2 /* State.Emptied */;
|
|
241
|
+
}
|
|
242
|
+
if (isTransformed((_a = model.indexer) === null || _a === void 0 ? void 0 : _a.value, visibility | Visibility.Item) ||
|
|
243
|
+
isTransformed(model.baseModel, visibility)) {
|
|
244
|
+
return 1 /* State.Transformed */;
|
|
245
|
+
}
|
|
246
|
+
for (const property of model.properties.values()) {
|
|
247
|
+
if (isAddedRemovedOrMadeOptional(property, visibility) ||
|
|
248
|
+
isTransformed(property.type, visibility)) {
|
|
249
|
+
return 1 /* State.Transformed */;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return 0 /* State.NotTransformed */;
|
|
253
|
+
}
|
|
254
|
+
function computeStateForUnion(union, visibility) {
|
|
255
|
+
for (const variant of union.variants.values()) {
|
|
256
|
+
if (isTransformed(variant.type, visibility)) {
|
|
257
|
+
return 1 /* State.Transformed */;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return 0 /* State.NotTransformed */;
|
|
261
|
+
}
|
|
262
|
+
function isAddedRemovedOrMadeOptional(property, visibility) {
|
|
263
|
+
if (visibility === Visibility.All) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
if (isOptional(property, Visibility.All) !== isOptional(property, visibility)) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
return (isPayloadProperty(property, visibility, /* keep shared */ true) !==
|
|
270
|
+
isPayloadProperty(property, Visibility.All, /*keep shared*/ true));
|
|
271
|
+
}
|
|
272
|
+
function computeIsEmptied(model, visibility) {
|
|
273
|
+
if (model.baseModel || model.indexer || model.properties.size === 0) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
for (const property of model.properties.values()) {
|
|
277
|
+
if (isPayloadProperty(property, visibility, /* keep shared */ true)) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
function isOptional(property, visibility) {
|
|
284
|
+
// Properties are only made optional for update visibility
|
|
285
|
+
return property.optional || visibility === Visibility.Update;
|
|
286
|
+
}
|
|
287
|
+
function isPayloadProperty(property, visibility, keepShareableProperties) {
|
|
288
|
+
var _a;
|
|
289
|
+
if (isEmptied(property.type, visibility) ||
|
|
290
|
+
isApplicableMetadata(program, property, visibility) ||
|
|
291
|
+
(isMetadata(program, property) && !includeInapplicableMetadataInPayload(program, property))) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
if (!isVisible(program, property, visibility)) {
|
|
295
|
+
// NOTE: When we check if a model is transformed for a given
|
|
296
|
+
// visibility, we retain shared properties. It is not considered
|
|
297
|
+
// transformed if the only removed properties are shareable. However,,
|
|
298
|
+
// if we do create a unique schema for a visibility, then we still
|
|
299
|
+
// drop invisible shareable properties from other uses of
|
|
300
|
+
// isPayloadProperty.
|
|
301
|
+
//
|
|
302
|
+
// For OpenAPI emit, for example, this means that we won't put a
|
|
303
|
+
// readOnly: true property into a specialized schema for a non-read
|
|
304
|
+
// visibility.
|
|
305
|
+
return !!(keepShareableProperties && ((_a = options === null || options === void 0 ? void 0 : options.canShareProperty) === null || _a === void 0 ? void 0 : _a.call(options, property)));
|
|
306
|
+
}
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* If the type is an anonymous model, tries to find a named model that has the same
|
|
311
|
+
* set of properties when non-payload properties are excluded.
|
|
312
|
+
*/
|
|
313
|
+
function getEffectivePayloadType(type, visibility) {
|
|
314
|
+
if (type.kind === "Model" && !type.name) {
|
|
315
|
+
const effective = getEffectiveModelType(program, type, (p) => isPayloadProperty(p, visibility));
|
|
316
|
+
if (effective.name) {
|
|
317
|
+
return effective;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return type;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
//# sourceMappingURL=metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,qBAAqB,EACrB,SAAS,IAAI,aAAa,EAI1B,KAAK,EACL,WAAW,EAGX,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,oCAAoC,EACpC,MAAM,EACN,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,YAAY,GACb,MAAM,iBAAiB,CAAC;AAGzB;;;GAGG;AACH,MAAM,CAAN,IAAY,UAcX;AAdD,WAAY,UAAU;IACpB,2CAAa,CAAA;IACb,+CAAe,CAAA;IACf,+CAAe,CAAA;IACf,+CAAe,CAAA;IACf,8CAAc,CAAA;IAEd,0CAA6C,CAAA;IAE7C;;;OAGG;IACH,iDAAc,CAAA;AAChB,CAAC,EAdW,UAAU,GAAV,UAAU,KAAV,UAAU,QAcrB;AAED,MAAM,oBAAoB,GAA8B,IAAI,GAAG,EAAE,CAAC;AAClE,SAAS,iBAAiB,CAAC,UAAs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A,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,wDAAG,QAAQ,CAAC,CAAA,CAAC,CAAC;SAC7E;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,SAAS,uBAAuB,CAAC,IAAU,EAAE,UAAsB;QACjE,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACvC,MAAM,SAAS,GAAG,qBAAqB,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAC3D,iBAAiB,CAAC,CAAC,EAAE,UAAU,CAAC,CACjC,CAAC;YACF,IAAI,SAAS,CAAC,IAAI,EAAE;gBAClB,OAAO,SAAS,CAAC;aAClB;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Diagnostic, DiagnosticCollector, Namespace, Operation, Program } from "@typespec/compiler";
|
|
2
|
+
import { HttpOperation, HttpService, OperationContainer, RouteResolutionOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Return the Http Operation details for a given TypeSpec operation.
|
|
5
|
+
* @param operation Operation
|
|
6
|
+
* @param options Optional option on how to resolve the http details.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getHttpOperation(program: Program, operation: Operation, options?: RouteResolutionOptions): [HttpOperation, readonly Diagnostic[]];
|
|
9
|
+
/**
|
|
10
|
+
* Get all the Http Operation in the given container.
|
|
11
|
+
* @param program Program
|
|
12
|
+
* @param container Namespace or interface containing operations
|
|
13
|
+
* @param options Resolution options
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function listHttpOperationsIn(program: Program, container: OperationContainer, options?: RouteResolutionOptions): [HttpOperation[], readonly Diagnostic[]];
|
|
17
|
+
/**
|
|
18
|
+
* Returns all the services defined.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getAllHttpServices(program: Program, options?: RouteResolutionOptions): [HttpService[], readonly Diagnostic[]];
|
|
21
|
+
export declare function getHttpService(program: Program, serviceNamespace: Namespace, options?: RouteResolutionOptions): [HttpService, readonly Diagnostic[]];
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use `getAllHttpServices` or `resolveHttpOperations` manually
|
|
24
|
+
*/
|
|
25
|
+
export declare function getAllRoutes(program: Program, options?: RouteResolutionOptions): [HttpOperation[], readonly Diagnostic[]];
|
|
26
|
+
export declare function reportIfNoRoutes(program: Program, routes: HttpOperation[]): void;
|
|
27
|
+
export declare function validateRouteUnique(program: Program, diagnostics: DiagnosticCollector, operations: HttpOperation[]): void;
|
|
28
|
+
export declare function isOverloadSameEndpoint(overload: HttpOperation & {
|
|
29
|
+
overloading: HttpOperation;
|
|
30
|
+
}): boolean;
|
|
31
|
+
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,mBAAmB,EAOnB,SAAS,EAET,SAAS,EACT,OAAO,EAER,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EACL,aAAa,EACb,WAAW,EAEX,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,CAAC,aAAa,EAAE,SAAS,UAAU,EAAE,CAAC,CAExC;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,kBAAkB,EAC7B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,CAAC,aAAa,EAAE,EAAE,SAAS,UAAU,EAAE,CAAC,CAQ1C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,CAAC,WAAW,EAAE,EAAE,SAAS,UAAU,EAAE,CAAC,CAaxC;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,SAAS,EAC3B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC,CAmBtC;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,CAAC,aAAa,EAAE,EAAE,SAAS,UAAU,EAAE,CAAC,CAG1C;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,QAOzE;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,mBAAmB,EAChC,UAAU,EAAE,aAAa,EAAE,QA2C5B;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,aAAa,GAAG;IAAE,WAAW,EAAE,aAAa,CAAA;CAAE,WAE9F"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { $visibility, createDiagnosticCollector, getOverloadedOperation, getOverloads, getVisibility, listOperationsIn, listServices, navigateProgram, SyntaxKind, } from "@typespec/compiler";
|
|
2
|
+
import { createDiagnostic, reportDiagnostic } from "./lib.js";
|
|
3
|
+
import { getResponsesForOperation } from "./responses.js";
|
|
4
|
+
import { isSharedRoute, resolvePathAndParameters } from "./route.js";
|
|
5
|
+
/**
|
|
6
|
+
* Return the Http Operation details for a given TypeSpec operation.
|
|
7
|
+
* @param operation Operation
|
|
8
|
+
* @param options Optional option on how to resolve the http details.
|
|
9
|
+
*/
|
|
10
|
+
export function getHttpOperation(program, operation, options) {
|
|
11
|
+
return getHttpOperationInternal(program, operation, options, new Map());
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get all the Http Operation in the given container.
|
|
15
|
+
* @param program Program
|
|
16
|
+
* @param container Namespace or interface containing operations
|
|
17
|
+
* @param options Resolution options
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export function listHttpOperationsIn(program, container, options) {
|
|
21
|
+
const diagnostics = createDiagnosticCollector();
|
|
22
|
+
const operations = listOperationsIn(container, options === null || options === void 0 ? void 0 : options.listOptions);
|
|
23
|
+
const cache = new Map();
|
|
24
|
+
const httpOperations = operations.map((x) => diagnostics.pipe(getHttpOperationInternal(program, x, options, cache)));
|
|
25
|
+
return diagnostics.wrap(httpOperations);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns all the services defined.
|
|
29
|
+
*/
|
|
30
|
+
export function getAllHttpServices(program, options) {
|
|
31
|
+
const diagnostics = createDiagnosticCollector();
|
|
32
|
+
const serviceNamespaces = listServices(program);
|
|
33
|
+
const services = serviceNamespaces.map((x) => diagnostics.pipe(getHttpService(program, x.type, options)));
|
|
34
|
+
if (serviceNamespaces.length === 0) {
|
|
35
|
+
services.push(diagnostics.pipe(getHttpService(program, program.getGlobalNamespaceType(), options)));
|
|
36
|
+
}
|
|
37
|
+
return diagnostics.wrap(services);
|
|
38
|
+
}
|
|
39
|
+
export function getHttpService(program, serviceNamespace, options) {
|
|
40
|
+
const diagnostics = createDiagnosticCollector();
|
|
41
|
+
const httpOperations = diagnostics.pipe(listHttpOperationsIn(program, serviceNamespace, {
|
|
42
|
+
...options,
|
|
43
|
+
listOptions: {
|
|
44
|
+
recursive: serviceNamespace !== program.getGlobalNamespaceType(),
|
|
45
|
+
},
|
|
46
|
+
}));
|
|
47
|
+
validateProgram(program, diagnostics);
|
|
48
|
+
validateRouteUnique(program, diagnostics, httpOperations);
|
|
49
|
+
const service = {
|
|
50
|
+
namespace: serviceNamespace,
|
|
51
|
+
operations: httpOperations,
|
|
52
|
+
};
|
|
53
|
+
return diagnostics.wrap(service);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated use `getAllHttpServices` or `resolveHttpOperations` manually
|
|
57
|
+
*/
|
|
58
|
+
export function getAllRoutes(program, options) {
|
|
59
|
+
const [services, diagnostics] = getAllHttpServices(program, options);
|
|
60
|
+
return [services[0].operations, diagnostics];
|
|
61
|
+
}
|
|
62
|
+
export function reportIfNoRoutes(program, routes) {
|
|
63
|
+
if (routes.length === 0) {
|
|
64
|
+
reportDiagnostic(program, {
|
|
65
|
+
code: "no-routes",
|
|
66
|
+
target: program.getGlobalNamespaceType(),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function validateRouteUnique(program, diagnostics, operations) {
|
|
71
|
+
const grouped = new Map();
|
|
72
|
+
for (const operation of operations) {
|
|
73
|
+
const { verb, path } = operation;
|
|
74
|
+
if (operation.overloading !== undefined && isOverloadSameEndpoint(operation)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (isSharedRoute(program, operation.operation)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
let map = grouped.get(path);
|
|
81
|
+
if (map === undefined) {
|
|
82
|
+
map = new Map();
|
|
83
|
+
grouped.set(path, map);
|
|
84
|
+
}
|
|
85
|
+
let list = map.get(verb);
|
|
86
|
+
if (list === undefined) {
|
|
87
|
+
list = [];
|
|
88
|
+
map.set(verb, list);
|
|
89
|
+
}
|
|
90
|
+
list.push(operation);
|
|
91
|
+
}
|
|
92
|
+
for (const [path, map] of grouped) {
|
|
93
|
+
for (const [verb, routes] of map) {
|
|
94
|
+
if (routes.length >= 2) {
|
|
95
|
+
for (const route of routes) {
|
|
96
|
+
diagnostics.add(createDiagnostic({
|
|
97
|
+
code: "duplicate-operation",
|
|
98
|
+
format: { path, verb, operationName: route.operation.name },
|
|
99
|
+
target: route.operation,
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export function isOverloadSameEndpoint(overload) {
|
|
107
|
+
return overload.path === overload.overloading.path && overload.verb === overload.overloading.verb;
|
|
108
|
+
}
|
|
109
|
+
function getHttpOperationInternal(program, operation, options, cache) {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
const existing = cache.get(operation);
|
|
112
|
+
if (existing) {
|
|
113
|
+
return [existing, []];
|
|
114
|
+
}
|
|
115
|
+
const diagnostics = createDiagnosticCollector();
|
|
116
|
+
const httpOperationRef = { operation };
|
|
117
|
+
cache.set(operation, httpOperationRef);
|
|
118
|
+
const overloadBase = getOverloadedOperation(program, operation);
|
|
119
|
+
let overloading;
|
|
120
|
+
if (overloadBase) {
|
|
121
|
+
overloading = httpOperationRef.overloading = diagnostics.pipe(getHttpOperationInternal(program, overloadBase, options, cache));
|
|
122
|
+
}
|
|
123
|
+
const route = diagnostics.pipe(resolvePathAndParameters(program, operation, overloading, options !== null && options !== void 0 ? options : {}));
|
|
124
|
+
const responses = diagnostics.pipe(getResponsesForOperation(program, operation));
|
|
125
|
+
const httpOperation = {
|
|
126
|
+
path: route.path,
|
|
127
|
+
pathSegments: route.pathSegments,
|
|
128
|
+
verb: route.parameters.verb,
|
|
129
|
+
container: (_b = (_a = operation.interface) !== null && _a !== void 0 ? _a : operation.namespace) !== null && _b !== void 0 ? _b : program.getGlobalNamespaceType(),
|
|
130
|
+
parameters: route.parameters,
|
|
131
|
+
operation,
|
|
132
|
+
responses,
|
|
133
|
+
};
|
|
134
|
+
Object.assign(httpOperationRef, httpOperation);
|
|
135
|
+
const overloads = getOverloads(program, operation);
|
|
136
|
+
if (overloads) {
|
|
137
|
+
httpOperationRef.overloads = overloads.map((x) => diagnostics.pipe(getHttpOperationInternal(program, x, options, cache)));
|
|
138
|
+
}
|
|
139
|
+
return diagnostics.wrap(httpOperationRef);
|
|
140
|
+
}
|
|
141
|
+
function validateProgram(program, diagnostics) {
|
|
142
|
+
navigateProgram(program, {
|
|
143
|
+
modelProperty(property) {
|
|
144
|
+
checkForUnsupportedVisibility(property);
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
// NOTE: This is intentionally not checked in the visibility decorator
|
|
148
|
+
// itself as that would be a layering violation, putting a REST
|
|
149
|
+
// interpretation of visibility into the core.
|
|
150
|
+
function checkForUnsupportedVisibility(property) {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
if ((_a = getVisibility(program, property)) === null || _a === void 0 ? void 0 : _a.includes("write")) {
|
|
153
|
+
// NOTE: Check for name equality instead of function equality
|
|
154
|
+
// to deal with multiple copies of core being used.
|
|
155
|
+
const decorator = property.decorators.find((d) => d.decorator.name === $visibility.name);
|
|
156
|
+
const arg = decorator === null || decorator === void 0 ? void 0 : decorator.args.find((a) => { var _a; return ((_a = a.node) === null || _a === void 0 ? void 0 : _a.kind) === SyntaxKind.StringLiteral && a.node.value === "write"; });
|
|
157
|
+
const target = (_b = arg === null || arg === void 0 ? void 0 : arg.node) !== null && _b !== void 0 ? _b : property;
|
|
158
|
+
diagnostics.add(createDiagnostic({ code: "write-visibility-not-supported", target }));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAGzB,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,YAAY,EAGZ,eAAe,EAGf,UAAU,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AASrE;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAgB,EAChB,SAAoB,EACpB,OAAgC;IAEhC,O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C,OAAA,CAAA,MAAA,CAAC,CAAC,IAAI,0CAAE,IAAI,MAAK,UAAU,CAAC,aAAa,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,OAAO,CAAA,EAAA,CAC7E,CAAC;YACF,MAAM,MAAM,GAAG,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,mCAAI,QAAQ,CAAC;YACrC,WAAW,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,gCAAgC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;SACvF;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Diagnostic, Operation, Program } from "@typespec/compiler";
|
|
2
|
+
import { HttpOperation, HttpOperationParameters, OperationParameterOptions } from "./types.js";
|
|
3
|
+
export declare function getOperationParameters(program: Program, operation: Operation, overloadBase?: HttpOperation, knownPathParamNames?: string[], options?: OperationParameterOptions): [HttpOperationParameters, readonly Diagnostic[]];
|
|
4
|
+
//# sourceMappingURL=parameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameters.d.ts","sourceRoot":"","sources":["../../src/parameters.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAGV,SAAS,EACT,OAAO,EAER,MAAM,oBAAoB,CAAC;AAW5B,OAAO,EACL,aAAa,EAEb,uBAAuB,EAGvB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAEpB,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,YAAY,CAAC,EAAE,aAAa,EAC5B,mBAAmB,GAAE,MAAM,EAAO,EAClC,OAAO,GAAE,yBAA8B,GACtC,CAAC,uBAAuB,EAAE,SAAS,UAAU,EAAE,CAAC,CAkBlD"}
|