@typespec/rest 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.
@@ -0,0 +1,74 @@
1
+ import { DecoratorContext, Interface, Model, ModelProperty, Operation, Program, Scalar, Type } from "@typespec/compiler";
2
+ export interface FilteredRouteParam {
3
+ routeParamString?: string;
4
+ excludeFromOperationParams?: boolean;
5
+ }
6
+ export interface AutoRouteOptions {
7
+ routeParamFilter?: (op: Operation, param: ModelProperty) => FilteredRouteParam | undefined;
8
+ }
9
+ /**
10
+ * `@autoRoute` enables automatic route generation for an operation or interface.
11
+ *
12
+ * When applied to an operation, it automatically generates the operation's route based on path parameter
13
+ * metadata. When applied to an interface, it causes all operations under that scope to have
14
+ * auto-generated routes.
15
+ */
16
+ export declare function $autoRoute(context: DecoratorContext, entity: Interface | Operation): void;
17
+ export declare function isAutoRoute(program: Program, entity: Operation | Interface): boolean;
18
+ /**
19
+ * `@segment` defines the preceding path segment for a `@path` parameter in auto-generated routes
20
+ *
21
+ * The first argument should be a string that will be inserted into the operation route before the
22
+ * path parameter's name field.
23
+ *
24
+ * `@segment` can only be applied to model properties, operation parameters, or operations.
25
+ */
26
+ export declare function $segment(context: DecoratorContext, entity: Model | ModelProperty | Operation, name: string): void;
27
+ export declare function $segmentOf(context: DecoratorContext, entity: Operation, resourceType: Model): void;
28
+ export declare function getSegment(program: Program, entity: Type): string | undefined;
29
+ /**
30
+ * `@actionSeparator` defines the separator string that is used to precede the action name
31
+ * in auto-generated actions.
32
+ *
33
+ * `@actionSeparator` can only be applied to model properties, operation parameters, or operations.
34
+ */
35
+ export declare function $actionSeparator(context: DecoratorContext, entity: Model | ModelProperty | Operation, separator: "/" | ":" | "/:"): void;
36
+ /**
37
+ * @param program the TypeSpec program
38
+ * @param entity the target entity
39
+ * @returns the action separator string
40
+ */
41
+ export declare function getActionSeparator(program: Program, entity: Type): string | undefined;
42
+ /**
43
+ * `@resource` marks a model as a resource type.
44
+ *
45
+ * The first argument should be the name of the collection that the resources
46
+ * belong to. For example, a resource type `Widget` might have a collection
47
+ * name of `widgets`.
48
+ *
49
+ * `@resource` can only be applied to models.
50
+ */
51
+ export declare function $resource(context: DecoratorContext, entity: Model, collectionName: string): void;
52
+ export type ResourceOperations = "read" | "create" | "createOrReplace" | "createOrUpdate" | "update" | "delete" | "list";
53
+ export interface ResourceOperation {
54
+ operation: string;
55
+ resourceType: Model;
56
+ }
57
+ export declare function setResourceOperation(context: DecoratorContext, entity: Operation, resourceType: Model, operation: ResourceOperations): void;
58
+ export declare function getResourceOperation(program: Program, typespecOperation: Operation): ResourceOperation | undefined;
59
+ export declare function $readsResource(context: DecoratorContext, entity: Operation, resourceType: Model): void;
60
+ export declare function $createsResource(context: DecoratorContext, entity: Operation, resourceType: Model): void;
61
+ export declare function $createsOrReplacesResource(context: DecoratorContext, entity: Operation, resourceType: Model): void;
62
+ export declare function $createsOrUpdatesResource(context: DecoratorContext, entity: Operation, resourceType: Model): void;
63
+ export declare function $updatesResource(context: DecoratorContext, entity: Operation, resourceType: Model): void;
64
+ export declare function $deletesResource(context: DecoratorContext, entity: Operation, resourceType: Model): void;
65
+ export declare function $listsResource(context: DecoratorContext, entity: Operation, resourceType: Model): void;
66
+ export declare function $actionSegment(context: DecoratorContext, entity: Operation, name: string): void;
67
+ export declare function getActionSegment(program: Program, entity: Type): string | undefined;
68
+ export declare function $action(context: DecoratorContext, entity: Operation, name?: string): void;
69
+ export declare function getAction(program: Program, operation: Operation): string | null | undefined;
70
+ export declare function $collectionAction(context: DecoratorContext, entity: Operation, resourceType: Model, name?: string): void;
71
+ export declare function getCollectionAction(program: Program, operation: Operation): string | null | undefined;
72
+ export declare function $resourceLocation(context: DecoratorContext, entity: Model, resourceType: Model): void;
73
+ export declare function getResourceLocationType(program: Program, entity: Scalar): Model | undefined;
74
+ //# sourceMappingURL=rest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../src/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,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,QAQ/F;AAYD,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,QAExF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAEnF;AAGD,wBAAgB,OAAO,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,QAIlF;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAE3F;AAID,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE,KAAK,EACnB,IAAI,CAAC,EAAE,MAAM,QAiBd;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,GACnB,MAAM,GAAG,IAAI,GAAG,SAAS,CAE3B;AAID,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,KAAK,EACb,YAAY,EAAE,KAAK,GAClB,IAAI,CAON;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAE3F"}
@@ -0,0 +1,318 @@
1
+ import { $list, createDiagnosticCollector, setTypeSpecNamespace, } from "@typespec/compiler";
2
+ import { DefaultRouteProducer, getOperationParameters, getOperationVerb, getRoutePath, getRouteProducer, setRouteProducer, } from "@typespec/http";
3
+ import { createStateSymbol, reportDiagnostic } from "./lib.js";
4
+ import { getResourceTypeKey } from "./resource.js";
5
+ // ----------------- @autoRoute -----------------
6
+ function addActionFragment(program, target, pathFragments) {
7
+ var _a;
8
+ // add the action segment, if present
9
+ const defaultSeparator = "/";
10
+ const actionSegment = getActionSegment(program, target);
11
+ if (actionSegment && actionSegment !== "") {
12
+ const actionSeparator = (_a = getActionSeparator(program, target)) !== null && _a !== void 0 ? _a : defaultSeparator;
13
+ pathFragments.push(`${actionSeparator}${actionSegment}`);
14
+ }
15
+ }
16
+ function addSegmentFragment(program, target, pathFragments) {
17
+ // Don't add the segment prefix if it is meant to be excluded
18
+ // (empty string means exclude the segment)
19
+ const segment = getSegment(program, target);
20
+ if (segment && segment !== "") {
21
+ pathFragments.push(`/${segment}`);
22
+ }
23
+ }
24
+ // TODO: Make this overridable by libraries
25
+ const resourceOperationToVerb = {
26
+ read: "get",
27
+ create: "post",
28
+ createOrUpdate: "patch",
29
+ createOrReplace: "put",
30
+ update: "patch",
31
+ delete: "delete",
32
+ list: "get",
33
+ };
34
+ function getResourceOperationHttpVerb(program, operation) {
35
+ var _a, _b;
36
+ const resourceOperation = getResourceOperation(program, operation);
37
+ return ((_b = (_a = getOperationVerb(program, operation)) !== null && _a !== void 0 ? _a : (resourceOperation && resourceOperationToVerb[resourceOperation.operation])) !== null && _b !== void 0 ? _b : (getAction(program, operation) || getCollectionAction(program, operation) ? "post" : undefined));
38
+ }
39
+ function autoRouteProducer(program, operation, parentSegments, overloadBase, options) {
40
+ var _a, _b, _c, _d;
41
+ const diagnostics = createDiagnosticCollector();
42
+ const routePath = (_a = getRoutePath(program, operation)) === null || _a === void 0 ? void 0 : _a.path;
43
+ const segments = [...parentSegments, ...(routePath ? [routePath] : [])];
44
+ const filteredParameters = [];
45
+ const paramOptions = {
46
+ ...((_b = options === null || options === void 0 ? void 0 : options.paramOptions) !== null && _b !== void 0 ? _b : {}),
47
+ verbSelector: getResourceOperationHttpVerb,
48
+ };
49
+ const parameters = diagnostics.pipe(getOperationParameters(program, operation, undefined, [], paramOptions));
50
+ for (const httpParam of parameters.parameters) {
51
+ const { type, param } = httpParam;
52
+ if (type === "path") {
53
+ addSegmentFragment(program, param, segments);
54
+ const filteredParam = (_d = (_c = options.autoRouteOptions) === null || _c === void 0 ? void 0 : _c.routeParamFilter) === null || _d === void 0 ? void 0 : _d.call(_c, operation, param);
55
+ if (filteredParam === null || filteredParam === void 0 ? void 0 : filteredParam.routeParamString) {
56
+ segments.push(`/${filteredParam.routeParamString}`);
57
+ if ((filteredParam === null || filteredParam === void 0 ? void 0 : filteredParam.excludeFromOperationParams) === true) {
58
+ // Skip the rest of the loop so that we don't add the parameter to the final list
59
+ continue;
60
+ }
61
+ }
62
+ else {
63
+ // Add the path variable for the parameter
64
+ if (param.type.kind === "String") {
65
+ segments.push(`/${param.type.value}`);
66
+ continue; // Skip adding to the parameter list
67
+ }
68
+ else {
69
+ segments.push(`/{${param.name}}`);
70
+ }
71
+ }
72
+ }
73
+ // Push all usable parameters to the filtered list
74
+ filteredParameters.push(httpParam);
75
+ }
76
+ // Replace the original parameters with filtered set
77
+ parameters.parameters = filteredParameters;
78
+ // Add the operation's own segment if present
79
+ addSegmentFragment(program, operation, segments);
80
+ // Add the operation's action segment if present
81
+ addActionFragment(program, operation, segments);
82
+ return diagnostics.wrap({
83
+ segments,
84
+ parameters: {
85
+ ...parameters,
86
+ parameters: filteredParameters,
87
+ },
88
+ });
89
+ }
90
+ const autoRouteKey = createStateSymbol("autoRoute");
91
+ /**
92
+ * `@autoRoute` enables automatic route generation for an operation or interface.
93
+ *
94
+ * When applied to an operation, it automatically generates the operation's route based on path parameter
95
+ * metadata. When applied to an interface, it causes all operations under that scope to have
96
+ * auto-generated routes.
97
+ */
98
+ export function $autoRoute(context, entity) {
99
+ if (entity.kind === "Operation") {
100
+ setRouteProducer(context.program, entity, autoRouteProducer);
101
+ }
102
+ else {
103
+ for (const [_, op] of entity.operations) {
104
+ // Instantly apply the decorator to the operation
105
+ context.call($autoRoute, op);
106
+ // Manually push the decorator onto the property so that it gets applied
107
+ // to operations which reference the operation with `is`
108
+ op.decorators.push({
109
+ decorator: $autoRoute,
110
+ args: [],
111
+ });
112
+ }
113
+ }
114
+ context.program.stateSet(autoRouteKey).add(entity);
115
+ }
116
+ export function isAutoRoute(program, entity) {
117
+ return program.stateSet(autoRouteKey).has(entity);
118
+ }
119
+ // ------------------ @segment ------------------
120
+ const segmentsKey = createStateSymbol("segments");
121
+ /**
122
+ * `@segment` defines the preceding path segment for a `@path` parameter in auto-generated routes
123
+ *
124
+ * The first argument should be a string that will be inserted into the operation route before the
125
+ * path parameter's name field.
126
+ *
127
+ * `@segment` can only be applied to model properties, operation parameters, or operations.
128
+ */
129
+ export function $segment(context, entity, name) {
130
+ context.program.stateMap(segmentsKey).set(entity, name);
131
+ }
132
+ function getResourceSegment(program, resourceType) {
133
+ // Add path segment for resource type key (if it has one)
134
+ const resourceKey = getResourceTypeKey(program, resourceType);
135
+ return resourceKey
136
+ ? getSegment(program, resourceKey.keyProperty)
137
+ : getSegment(program, resourceType);
138
+ }
139
+ export function $segmentOf(context, entity, resourceType) {
140
+ if (resourceType.kind === "TemplateParameter") {
141
+ // Skip it, this operation is in a templated interface
142
+ return;
143
+ }
144
+ // Add path segment for resource type key (if it has one)
145
+ const segment = getResourceSegment(context.program, resourceType);
146
+ if (segment) {
147
+ context.call($segment, entity, segment);
148
+ }
149
+ }
150
+ export function getSegment(program, entity) {
151
+ return program.stateMap(segmentsKey).get(entity);
152
+ }
153
+ const actionSeparatorKey = createStateSymbol("actionSeparator");
154
+ /**
155
+ * `@actionSeparator` defines the separator string that is used to precede the action name
156
+ * in auto-generated actions.
157
+ *
158
+ * `@actionSeparator` can only be applied to model properties, operation parameters, or operations.
159
+ */
160
+ export function $actionSeparator(context, entity, separator) {
161
+ context.program.stateMap(actionSeparatorKey).set(entity, separator);
162
+ }
163
+ /**
164
+ * @param program the TypeSpec program
165
+ * @param entity the target entity
166
+ * @returns the action separator string
167
+ */
168
+ export function getActionSeparator(program, entity) {
169
+ return program.stateMap(actionSeparatorKey).get(entity);
170
+ }
171
+ /**
172
+ * `@resource` marks a model as a resource type.
173
+ *
174
+ * The first argument should be the name of the collection that the resources
175
+ * belong to. For example, a resource type `Widget` might have a collection
176
+ * name of `widgets`.
177
+ *
178
+ * `@resource` can only be applied to models.
179
+ */
180
+ export function $resource(context, entity, collectionName) {
181
+ // Ensure type has a key property
182
+ const key = getResourceTypeKey(context.program, entity);
183
+ // A resource type must have a key property
184
+ if (!key) {
185
+ reportDiagnostic(context.program, {
186
+ code: "resource-missing-key",
187
+ format: {
188
+ modelName: entity.name,
189
+ },
190
+ target: entity,
191
+ });
192
+ return;
193
+ }
194
+ // Apply the @segment decorator with the collection name
195
+ context.call($segment, key.keyProperty, collectionName);
196
+ // Manually push the decorator onto the property so that it's copyable in KeysOf<T>
197
+ key.keyProperty.decorators.push({
198
+ decorator: $segment,
199
+ args: [{ value: context.program.checker.createLiteralType(collectionName) }],
200
+ });
201
+ }
202
+ const resourceOperationsKey = createStateSymbol("resourceOperations");
203
+ function resourceRouteProducer(program, operation, parentSegments, overloadBase, options) {
204
+ // NOTE: The purpose of this producer is to pass along the behavior of the
205
+ // DefaultRouteProducer while setting the appropriate HTTP verb based on any
206
+ // resource operation decorators that have been applied. This behavior will
207
+ // be overridden by the `autoRouteProducer` if `autoRoute` is also applied to
208
+ // the same operation.
209
+ var _a;
210
+ // Set the OperationVerbSelector to pick verbs based on resource operation type
211
+ const paramOptions = {
212
+ ...((_a = options === null || options === void 0 ? void 0 : options.paramOptions) !== null && _a !== void 0 ? _a : {}),
213
+ verbSelector: getResourceOperationHttpVerb,
214
+ };
215
+ return DefaultRouteProducer(program, operation, parentSegments, overloadBase, {
216
+ ...options,
217
+ paramOptions,
218
+ });
219
+ }
220
+ export function setResourceOperation(context, entity, resourceType, operation) {
221
+ if (resourceType.kind === "TemplateParameter") {
222
+ // Skip it, this operation is in a templated interface
223
+ return;
224
+ }
225
+ context.program.stateMap(resourceOperationsKey).set(entity, {
226
+ operation,
227
+ resourceType,
228
+ });
229
+ // Set a custom RouteProducer on the operation if one hasn't already been
230
+ // established yet. This is intended to translate lifecycle operations to
231
+ // HTTP verbs.
232
+ if (!getRouteProducer(context.program, entity)) {
233
+ setRouteProducer(context.program, entity, resourceRouteProducer);
234
+ }
235
+ }
236
+ export function getResourceOperation(program, typespecOperation) {
237
+ return program.stateMap(resourceOperationsKey).get(typespecOperation);
238
+ }
239
+ export function $readsResource(context, entity, resourceType) {
240
+ setResourceOperation(context, entity, resourceType, "read");
241
+ }
242
+ export function $createsResource(context, entity, resourceType) {
243
+ // Add path segment for resource type key
244
+ context.call($segmentOf, entity, resourceType);
245
+ setResourceOperation(context, entity, resourceType, "create");
246
+ }
247
+ export function $createsOrReplacesResource(context, entity, resourceType) {
248
+ setResourceOperation(context, entity, resourceType, "createOrReplace");
249
+ }
250
+ export function $createsOrUpdatesResource(context, entity, resourceType) {
251
+ setResourceOperation(context, entity, resourceType, "createOrUpdate");
252
+ }
253
+ export function $updatesResource(context, entity, resourceType) {
254
+ setResourceOperation(context, entity, resourceType, "update");
255
+ }
256
+ export function $deletesResource(context, entity, resourceType) {
257
+ setResourceOperation(context, entity, resourceType, "delete");
258
+ }
259
+ export function $listsResource(context, entity, resourceType) {
260
+ // Add the @list decorator too so that collection routes are generated correctly
261
+ context.call($list, entity, resourceType);
262
+ // Add path segment for resource type key
263
+ context.call($segmentOf, entity, resourceType);
264
+ setResourceOperation(context, entity, resourceType, "list");
265
+ }
266
+ function lowerCaseFirstChar(str) {
267
+ return str[0].toLocaleLowerCase() + str.substring(1);
268
+ }
269
+ function makeActionName(op, name) {
270
+ return lowerCaseFirstChar(name || op.name);
271
+ }
272
+ const actionsSegmentKey = createStateSymbol("actionSegment");
273
+ export function $actionSegment(context, entity, name) {
274
+ context.program.stateMap(actionsSegmentKey).set(entity, name);
275
+ }
276
+ export function getActionSegment(program, entity) {
277
+ return program.stateMap(actionsSegmentKey).get(entity);
278
+ }
279
+ const actionsKey = createStateSymbol("actions");
280
+ export function $action(context, entity, name) {
281
+ const action = makeActionName(entity, name);
282
+ context.call($actionSegment, entity, action);
283
+ context.program.stateMap(actionsKey).set(entity, action);
284
+ }
285
+ export function getAction(program, operation) {
286
+ return program.stateMap(actionsKey).get(operation);
287
+ }
288
+ const collectionActionsKey = createStateSymbol("collectionActions");
289
+ export function $collectionAction(context, entity, resourceType, name) {
290
+ if (resourceType.kind === "TemplateParameter") {
291
+ // Skip it, this operation is in a templated interface
292
+ return;
293
+ }
294
+ // only add the resource portion of the segment
295
+ const segment = getResourceSegment(context.program, resourceType);
296
+ if (segment) {
297
+ context.call($segment, entity, segment);
298
+ }
299
+ const action = makeActionName(entity, name);
300
+ context.call($actionSegment, entity, action);
301
+ context.program.stateMap(collectionActionsKey).set(entity, `${segment}/${action}`);
302
+ }
303
+ export function getCollectionAction(program, operation) {
304
+ return program.stateMap(collectionActionsKey).get(operation);
305
+ }
306
+ const resourceLocationsKey = createStateSymbol("resourceLocations");
307
+ export function $resourceLocation(context, entity, resourceType) {
308
+ if (resourceType.kind === "TemplateParameter") {
309
+ // Skip it, this operation is in a templated interface
310
+ return;
311
+ }
312
+ context.program.stateMap(resourceLocationsKey).set(entity, resourceType);
313
+ }
314
+ export function getResourceLocationType(program, entity) {
315
+ return program.stateMap(resourceLocationsKey).get(entity);
316
+ }
317
+ setTypeSpecNamespace("Private", $resourceLocation, $actionSegment, getActionSegment);
318
+ //# sourceMappingURL=rest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/rest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,yBAAyB,EASzB,oBAAoB,GAErB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAOhB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,e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,MAAM,UAAU,iBAAiB,CAC/B,OAAyB,EACzB,MAAa,EACb,YAAmB;IAEnB,IAAK,YAAqB,CAAC,IAAI,KAAK,mBAAmB,EAAE;QACvD,sDAAsD;QACtD,OAAO;KACR;IAED,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAgB,EAAE,MAAc;IACtE,OAAO,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC5D,CAAC;AAED,oBAAoB,CAAC,SAAS,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { TypeSpecTestLibrary } from "@typespec/compiler/testing";
2
+ export declare const RestTestLibrary: TypeSpecTestLibrary;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGpF,eAAO,MAAM,eAAe,EAAE,mBAG5B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { resolvePath } from "@typespec/compiler";
2
+ import { createTestLibrary } from "@typespec/compiler/testing";
3
+ import { fileURLToPath } from "url";
4
+ export const RestTestLibrary = createTestLibrary({
5
+ name: "@typespec/rest",
6
+ packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"),
7
+ });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAuB,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,CAAC,MAAM,eAAe,GAAwB,iBAAiB,CAAC;IACpE,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC;CACzE,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Program } from "@typespec/compiler";
2
+ export declare function $onValidate(program: Program): void;
3
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,OAAO,EACR,MAAM,oBAAoB,CAAC;AAsD5B,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,QAI3C"}
@@ -0,0 +1,54 @@
1
+ import { DuplicateTracker, getKeyName, getTypeName, listServices, navigateTypesInNamespace, } from "@typespec/compiler";
2
+ import { reportDiagnostic } from "./lib.js";
3
+ import { getParentResource, getResourceTypeKey } from "./resource.js";
4
+ function checkForDuplicateResourceKeyNames(program) {
5
+ const seenTypes = new Set();
6
+ function checkResourceModelKeys(model) {
7
+ if (model.name === "") {
8
+ return;
9
+ }
10
+ let currentType = model;
11
+ const keyProperties = new DuplicateTracker();
12
+ while (currentType) {
13
+ const resourceKey = getResourceTypeKey(program, currentType);
14
+ if (resourceKey) {
15
+ const keyName = getKeyName(program, resourceKey.keyProperty);
16
+ keyProperties.track(keyName, resourceKey);
17
+ }
18
+ currentType = getParentResource(program, currentType);
19
+ }
20
+ // Report a diagnostic for each duplicate key
21
+ for (const [keyName, dupes] of keyProperties.entries()) {
22
+ for (const key of dupes) {
23
+ // Make sure we don't report a duplicate for a particular
24
+ // resource type and key name more than once
25
+ const fullName = `${getTypeName(key.resourceType)}.${keyName}`;
26
+ if (!seenTypes.has(fullName)) {
27
+ seenTypes.add(fullName);
28
+ reportDiagnostic(program, {
29
+ code: "duplicate-parent-key",
30
+ format: {
31
+ resourceName: key.resourceType.name,
32
+ keyName,
33
+ },
34
+ target: key.keyProperty,
35
+ });
36
+ }
37
+ }
38
+ }
39
+ }
40
+ for (const service of listServices(program)) {
41
+ // If the model type is defined under the service namespace, check that the
42
+ // parent resource type(s) don't have the same key name as the
43
+ // current resource type.
44
+ navigateTypesInNamespace(service.type, {
45
+ model: (model) => checkResourceModelKeys(model),
46
+ });
47
+ }
48
+ }
49
+ export function $onValidate(program) {
50
+ // Make sure any defined resource types don't have any conflicts with parent
51
+ // resource type key names
52
+ checkForDuplicateResourceKeyNames(program);
53
+ }
54
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,YAAY,EAEZ,wBAAwB,GAEzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAe,MAAM,eAAe,CAAC;AAEnF,SAAS,iCAAiC,CAAC,OAAgB;IACzD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IAEpC,SAAS,sBAAsB,CAAC,KAAY;QAC1C,IAAI,KAAK,CAAC,IAAI,KAAK,EAAE,EAAE;YACrB,OAAO;SACR;QACD,IAAI,WAAW,GAAsB,KAAK,CAAC;QAC3C,MAAM,aAAa,GAAG,IAAI,gBAAgB,EAAuB,CAAC;QAClE,OAAO,WAAW,EAAE;YAClB,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YAC7D,IAAI,WAAW,EAAE;gBACf,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;gBAC7D,aAAa,CAAC,KAAK,CAAC,OA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