@typespec/compiler 0.55.0-dev.5 → 0.55.0-dev.7
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/dist/generated-defs/TypeSpec.d.ts +498 -0
- package/dist/generated-defs/TypeSpec.d.ts.map +1 -0
- package/dist/generated-defs/TypeSpec.js +2 -0
- package/dist/generated-defs/TypeSpec.js.map +1 -0
- package/dist/generated-defs/TypeSpec.ts-test.d.ts +2 -0
- package/dist/generated-defs/TypeSpec.ts-test.d.ts.map +1 -0
- package/dist/generated-defs/TypeSpec.ts-test.js +45 -0
- package/dist/generated-defs/TypeSpec.ts-test.js.map +1 -0
- package/dist/manifest.js +2 -2
- package/dist/src/lib/decorators.d.ts +40 -40
- package/dist/src/lib/decorators.d.ts.map +1 -1
- package/dist/src/lib/decorators.js +84 -80
- package/dist/src/lib/decorators.js.map +1 -1
- package/dist/src/lib/service.d.ts +3 -2
- package/dist/src/lib/service.d.ts.map +1 -1
- package/dist/src/lib/service.js +10 -2
- package/dist/src/lib/service.js.map +1 -1
- package/dist/src/server/tmlanguage.d.ts.map +1 -1
- package/dist/src/server/tmlanguage.js +3 -2
- package/dist/src/server/tmlanguage.js.map +1 -1
- package/dist/typespec.tmLanguage +12 -0
- package/package.json +2 -1
- package/dist/.scripts/build-init-templates.d.ts +0 -2
- package/dist/.scripts/build-init-templates.d.ts.map +0 -1
- package/dist/.scripts/build-init-templates.js +0 -48
- package/dist/.scripts/build-init-templates.js.map +0 -1
- package/dist/.scripts/helpers.d.ts +0 -4
- package/dist/.scripts/helpers.d.ts.map +0 -1
- package/dist/.scripts/helpers.js +0 -44
- package/dist/.scripts/helpers.js.map +0 -1
|
@@ -27,12 +27,12 @@ const summaryKey = createStateSymbol("summary");
|
|
|
27
27
|
*
|
|
28
28
|
* @summary can be specified on any language element -- a model, an operation, a namespace, etc.
|
|
29
29
|
*/
|
|
30
|
-
export
|
|
30
|
+
export const $summary = (context, target, text, sourceObject) => {
|
|
31
31
|
if (sourceObject) {
|
|
32
32
|
text = replaceTemplatedStringFromProperties(text, sourceObject);
|
|
33
33
|
}
|
|
34
34
|
context.program.stateMap(summaryKey).set(target, text);
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
36
|
export function getSummary(program, type) {
|
|
37
37
|
return program.stateMap(summaryKey).get(type);
|
|
38
38
|
}
|
|
@@ -47,19 +47,19 @@ const errorsDocsKey = createStateSymbol("errorDocs");
|
|
|
47
47
|
*
|
|
48
48
|
* @doc can be specified on any language element -- a model, an operation, a namespace, etc.
|
|
49
49
|
*/
|
|
50
|
-
export
|
|
50
|
+
export const $doc = (context, target, text, sourceObject) => {
|
|
51
51
|
validateDecoratorUniqueOnNode(context, target, $doc);
|
|
52
52
|
if (sourceObject) {
|
|
53
53
|
text = replaceTemplatedStringFromProperties(text, sourceObject);
|
|
54
54
|
}
|
|
55
55
|
setDocData(context.program, target, "self", { value: text, source: "decorator" });
|
|
56
|
-
}
|
|
56
|
+
};
|
|
57
57
|
/**
|
|
58
58
|
* @internal to be used to set the `@doc` from doc comment.
|
|
59
59
|
*/
|
|
60
|
-
export
|
|
60
|
+
export const $docFromComment = (context, target, key, text) => {
|
|
61
61
|
setDocData(context.program, target, key, { value: text, source: "comment" });
|
|
62
|
-
}
|
|
62
|
+
};
|
|
63
63
|
function getDocKey(target) {
|
|
64
64
|
switch (target) {
|
|
65
65
|
case "self":
|
|
@@ -101,10 +101,10 @@ export function getDoc(program, target) {
|
|
|
101
101
|
var _a;
|
|
102
102
|
return (_a = getDocDataInternal(program, target, "self")) === null || _a === void 0 ? void 0 : _a.value;
|
|
103
103
|
}
|
|
104
|
-
export
|
|
104
|
+
export const $returnsDoc = (context, target, text) => {
|
|
105
105
|
validateDecoratorUniqueOnNode(context, target, $doc);
|
|
106
106
|
setDocData(context.program, target, "returns", { value: text, source: "decorator" });
|
|
107
|
-
}
|
|
107
|
+
};
|
|
108
108
|
/**
|
|
109
109
|
* Get the documentation information for the return success types of an operation. In most cases you probably just want to use {@link getReturnsDoc}
|
|
110
110
|
* @param program Program
|
|
@@ -124,10 +124,10 @@ export function getReturnsDoc(program, target) {
|
|
|
124
124
|
var _a;
|
|
125
125
|
return (_a = getDocDataInternal(program, target, "returns")) === null || _a === void 0 ? void 0 : _a.value;
|
|
126
126
|
}
|
|
127
|
-
export
|
|
127
|
+
export const $errorsDoc = (context, target, text) => {
|
|
128
128
|
validateDecoratorUniqueOnNode(context, target, $doc);
|
|
129
129
|
setDocData(context.program, target, "errors", { value: text, source: "decorator" });
|
|
130
|
-
}
|
|
130
|
+
};
|
|
131
131
|
/**
|
|
132
132
|
* Get the documentation information for the return errors types of an operation. In most cases you probably just want to use {@link getErrorsDoc}
|
|
133
133
|
* @param program Program
|
|
@@ -147,25 +147,25 @@ export function getErrorsDoc(program, target) {
|
|
|
147
147
|
var _a;
|
|
148
148
|
return (_a = getDocDataInternal(program, target, "errors")) === null || _a === void 0 ? void 0 : _a.value;
|
|
149
149
|
}
|
|
150
|
-
export
|
|
150
|
+
export const $inspectType = (context, target, text) => {
|
|
151
151
|
// eslint-disable-next-line no-console
|
|
152
152
|
if (text)
|
|
153
153
|
console.log(text);
|
|
154
154
|
// eslint-disable-next-line no-console
|
|
155
155
|
console.dir(target, { depth: 3 });
|
|
156
|
-
}
|
|
157
|
-
export
|
|
156
|
+
};
|
|
157
|
+
export const $inspectTypeName = (context, target, text) => {
|
|
158
158
|
// eslint-disable-next-line no-console
|
|
159
159
|
if (text)
|
|
160
160
|
console.log(text);
|
|
161
161
|
// eslint-disable-next-line no-console
|
|
162
162
|
console.log(getTypeName(target));
|
|
163
|
-
}
|
|
163
|
+
};
|
|
164
164
|
const indexTypeKey = createStateSymbol("index");
|
|
165
|
-
export
|
|
165
|
+
export const $indexer = (context, target, key, value) => {
|
|
166
166
|
const indexer = { key, value };
|
|
167
167
|
context.program.stateMap(indexTypeKey).set(target, indexer);
|
|
168
|
-
}
|
|
168
|
+
};
|
|
169
169
|
export function getIndexer(program, target) {
|
|
170
170
|
return program.stateMap(indexTypeKey).get(target);
|
|
171
171
|
}
|
|
@@ -252,10 +252,10 @@ const errorKey = createStateSymbol("error");
|
|
|
252
252
|
* `@error` decorator marks a model as an error type.
|
|
253
253
|
* Any derived models (using extends) will also be seen as error types.
|
|
254
254
|
*/
|
|
255
|
-
export
|
|
255
|
+
export const $error = (context, entity) => {
|
|
256
256
|
validateDecoratorUniqueOnNode(context, entity, $error);
|
|
257
257
|
context.program.stateSet(errorKey).add(entity);
|
|
258
|
-
}
|
|
258
|
+
};
|
|
259
259
|
/**
|
|
260
260
|
* Check if the type is an error model or a descendant of an error model.
|
|
261
261
|
*/
|
|
@@ -287,7 +287,7 @@ const formatValuesKey = createStateSymbol("formatValues");
|
|
|
287
287
|
*
|
|
288
288
|
* `@format` can be specified on a type that extends from `string` or a `string`-typed model property.
|
|
289
289
|
*/
|
|
290
|
-
export
|
|
290
|
+
export const $format = (context, target, format) => {
|
|
291
291
|
validateDecoratorUniqueOnNode(context, target, $format);
|
|
292
292
|
if (!validateTargetingAString(context, target, "@format")) {
|
|
293
293
|
return;
|
|
@@ -297,13 +297,13 @@ export function $format(context, target, format) {
|
|
|
297
297
|
reportDeprecated(context.program, "Using `@format` on a bytes scalar is deprecated. Use `@encode` instead. https://github.com/microsoft/typespec/issues/1873", target);
|
|
298
298
|
}
|
|
299
299
|
context.program.stateMap(formatValuesKey).set(target, format);
|
|
300
|
-
}
|
|
300
|
+
};
|
|
301
301
|
export function getFormat(program, target) {
|
|
302
302
|
return program.stateMap(formatValuesKey).get(target);
|
|
303
303
|
}
|
|
304
304
|
// -- @pattern decorator ---------------------
|
|
305
305
|
const patternValuesKey = createStateSymbol("patternValues");
|
|
306
|
-
export
|
|
306
|
+
export const $pattern = (context, target, pattern, validationMessage) => {
|
|
307
307
|
validateDecoratorUniqueOnNode(context, target, $pattern);
|
|
308
308
|
if (!validateTargetingAString(context, target, "@pattern")) {
|
|
309
309
|
return;
|
|
@@ -313,7 +313,7 @@ export function $pattern(context, target, pattern, validationMessage) {
|
|
|
313
313
|
validationMessage,
|
|
314
314
|
};
|
|
315
315
|
context.program.stateMap(patternValuesKey).set(target, patternData);
|
|
316
|
-
}
|
|
316
|
+
};
|
|
317
317
|
/**
|
|
318
318
|
* Gets the pattern regular expression associated with a given type, if one has been set.
|
|
319
319
|
*
|
|
@@ -340,33 +340,33 @@ export function getPatternData(program, target) {
|
|
|
340
340
|
}
|
|
341
341
|
// -- @minLength decorator ---------------------
|
|
342
342
|
const minLengthValuesKey = createStateSymbol("minLengthValues");
|
|
343
|
-
export
|
|
343
|
+
export const $minLength = (context, target, minLength) => {
|
|
344
344
|
validateDecoratorUniqueOnNode(context, target, $minLength);
|
|
345
345
|
if (!validateTargetingAString(context, target, "@minLength") ||
|
|
346
346
|
!validateRange(context, minLength, getMaxLength(context.program, target))) {
|
|
347
347
|
return;
|
|
348
348
|
}
|
|
349
349
|
context.program.stateMap(minLengthValuesKey).set(target, minLength);
|
|
350
|
-
}
|
|
350
|
+
};
|
|
351
351
|
export function getMinLength(program, target) {
|
|
352
352
|
return program.stateMap(minLengthValuesKey).get(target);
|
|
353
353
|
}
|
|
354
354
|
// -- @maxLength decorator ---------------------
|
|
355
355
|
const maxLengthValuesKey = createStateSymbol("maxLengthValues");
|
|
356
|
-
export
|
|
356
|
+
export const $maxLength = (context, target, maxLength) => {
|
|
357
357
|
validateDecoratorUniqueOnNode(context, target, $maxLength);
|
|
358
358
|
if (!validateTargetingAString(context, target, "@maxLength") ||
|
|
359
359
|
!validateRange(context, getMinLength(context.program, target), maxLength)) {
|
|
360
360
|
return;
|
|
361
361
|
}
|
|
362
362
|
context.program.stateMap(maxLengthValuesKey).set(target, maxLength);
|
|
363
|
-
}
|
|
363
|
+
};
|
|
364
364
|
export function getMaxLength(program, target) {
|
|
365
365
|
return program.stateMap(maxLengthValuesKey).get(target);
|
|
366
366
|
}
|
|
367
367
|
// -- @minItems decorator ---------------------
|
|
368
368
|
const minItemsValuesKey = createStateSymbol("minItems");
|
|
369
|
-
export
|
|
369
|
+
export const $minItems = (context, target, minItems) => {
|
|
370
370
|
validateDecoratorUniqueOnNode(context, target, $minItems);
|
|
371
371
|
if (!isArrayModelType(context.program, target.kind === "Model" ? target : target.type)) {
|
|
372
372
|
reportDiagnostic(context.program, {
|
|
@@ -382,13 +382,13 @@ export function $minItems(context, target, minItems) {
|
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
384
|
context.program.stateMap(minItemsValuesKey).set(target, minItems);
|
|
385
|
-
}
|
|
385
|
+
};
|
|
386
386
|
export function getMinItems(program, target) {
|
|
387
387
|
return program.stateMap(minItemsValuesKey).get(target);
|
|
388
388
|
}
|
|
389
389
|
// -- @maxLength decorator ---------------------
|
|
390
390
|
const maxItemsValuesKey = createStateSymbol("maxItems");
|
|
391
|
-
export
|
|
391
|
+
export const $maxItems = (context, target, maxItems) => {
|
|
392
392
|
validateDecoratorUniqueOnNode(context, target, $maxItems);
|
|
393
393
|
if (!isArrayModelType(context.program, target.kind === "Model" ? target : target.type)) {
|
|
394
394
|
reportDiagnostic(context.program, {
|
|
@@ -404,13 +404,13 @@ export function $maxItems(context, target, maxItems) {
|
|
|
404
404
|
return;
|
|
405
405
|
}
|
|
406
406
|
context.program.stateMap(maxItemsValuesKey).set(target, maxItems);
|
|
407
|
-
}
|
|
407
|
+
};
|
|
408
408
|
export function getMaxItems(program, target) {
|
|
409
409
|
return program.stateMap(maxItemsValuesKey).get(target);
|
|
410
410
|
}
|
|
411
411
|
// -- @minValue decorator ---------------------
|
|
412
412
|
const minValuesKey = createStateSymbol("minValues");
|
|
413
|
-
export
|
|
413
|
+
export const $minValue = (context, target, minValue) => {
|
|
414
414
|
var _a;
|
|
415
415
|
validateDecoratorUniqueOnNode(context, target, $minValue);
|
|
416
416
|
validateDecoratorNotOnType(context, target, $minValueExclusive, $minValue);
|
|
@@ -422,13 +422,13 @@ export function $minValue(context, target, minValue) {
|
|
|
422
422
|
return;
|
|
423
423
|
}
|
|
424
424
|
program.stateMap(minValuesKey).set(target, minValue);
|
|
425
|
-
}
|
|
425
|
+
};
|
|
426
426
|
export function getMinValue(program, target) {
|
|
427
427
|
return program.stateMap(minValuesKey).get(target);
|
|
428
428
|
}
|
|
429
429
|
// -- @maxValue decorator ---------------------
|
|
430
430
|
const maxValuesKey = createStateSymbol("maxValues");
|
|
431
|
-
export
|
|
431
|
+
export const $maxValue = (context, target, maxValue) => {
|
|
432
432
|
var _a;
|
|
433
433
|
validateDecoratorUniqueOnNode(context, target, $maxValue);
|
|
434
434
|
validateDecoratorNotOnType(context, target, $maxValueExclusive, $maxValue);
|
|
@@ -440,13 +440,13 @@ export function $maxValue(context, target, maxValue) {
|
|
|
440
440
|
return;
|
|
441
441
|
}
|
|
442
442
|
program.stateMap(maxValuesKey).set(target, maxValue);
|
|
443
|
-
}
|
|
443
|
+
};
|
|
444
444
|
export function getMaxValue(program, target) {
|
|
445
445
|
return program.stateMap(maxValuesKey).get(target);
|
|
446
446
|
}
|
|
447
447
|
// -- @minValueExclusive decorator ---------------------
|
|
448
448
|
const minValueExclusiveKey = createStateSymbol("minValueExclusive");
|
|
449
|
-
export
|
|
449
|
+
export const $minValueExclusive = (context, target, minValueExclusive) => {
|
|
450
450
|
var _a;
|
|
451
451
|
validateDecoratorUniqueOnNode(context, target, $minValueExclusive);
|
|
452
452
|
validateDecoratorNotOnType(context, target, $minValue, $minValueExclusive);
|
|
@@ -458,13 +458,13 @@ export function $minValueExclusive(context, target, minValueExclusive) {
|
|
|
458
458
|
return;
|
|
459
459
|
}
|
|
460
460
|
program.stateMap(minValueExclusiveKey).set(target, minValueExclusive);
|
|
461
|
-
}
|
|
461
|
+
};
|
|
462
462
|
export function getMinValueExclusive(program, target) {
|
|
463
463
|
return program.stateMap(minValueExclusiveKey).get(target);
|
|
464
464
|
}
|
|
465
465
|
// -- @maxValueExclusive decorator ---------------------
|
|
466
466
|
const maxValueExclusiveKey = createStateSymbol("maxValueExclusive");
|
|
467
|
-
export
|
|
467
|
+
export const $maxValueExclusive = (context, target, maxValueExclusive) => {
|
|
468
468
|
var _a;
|
|
469
469
|
validateDecoratorUniqueOnNode(context, target, $maxValueExclusive);
|
|
470
470
|
validateDecoratorNotOnType(context, target, $maxValue, $maxValueExclusive);
|
|
@@ -476,7 +476,7 @@ export function $maxValueExclusive(context, target, maxValueExclusive) {
|
|
|
476
476
|
return;
|
|
477
477
|
}
|
|
478
478
|
program.stateMap(maxValueExclusiveKey).set(target, maxValueExclusive);
|
|
479
|
-
}
|
|
479
|
+
};
|
|
480
480
|
export function getMaxValueExclusive(program, target) {
|
|
481
481
|
return program.stateMap(maxValueExclusiveKey).get(target);
|
|
482
482
|
}
|
|
@@ -487,28 +487,30 @@ const secretTypesKey = createStateSymbol("secretTypes");
|
|
|
487
487
|
* @param context Decorator context
|
|
488
488
|
* @param target Decorator target, either a string model or a property with type string.
|
|
489
489
|
*/
|
|
490
|
-
export
|
|
490
|
+
export const $secret = (context, target) => {
|
|
491
491
|
validateDecoratorUniqueOnNode(context, target, $secret);
|
|
492
492
|
if (!validateTargetingAString(context, target, "@secret")) {
|
|
493
493
|
return;
|
|
494
494
|
}
|
|
495
495
|
context.program.stateMap(secretTypesKey).set(target, true);
|
|
496
|
-
}
|
|
496
|
+
};
|
|
497
497
|
export function isSecret(program, target) {
|
|
498
498
|
return program.stateMap(secretTypesKey).get(target);
|
|
499
499
|
}
|
|
500
500
|
const encodeKey = createStateSymbol("encode");
|
|
501
|
-
export
|
|
501
|
+
export const $encode = (context, target, encoding, encodeAs) => {
|
|
502
502
|
var _a, _b;
|
|
503
503
|
validateDecoratorUniqueOnNode(context, target, $encode);
|
|
504
504
|
const encodeData = {
|
|
505
|
-
encoding: typeof encoding === "string"
|
|
505
|
+
encoding: typeof encoding === "string"
|
|
506
|
+
? encoding
|
|
507
|
+
: (_b = (_a = encoding.value) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : encoding.name,
|
|
506
508
|
type: encodeAs !== null && encodeAs !== void 0 ? encodeAs : context.program.checker.getStdType("string"),
|
|
507
509
|
};
|
|
508
510
|
const targetType = getPropertyType(target);
|
|
509
511
|
validateEncodeData(context, targetType, encodeData);
|
|
510
512
|
context.program.stateMap(encodeKey).set(target, encodeData);
|
|
511
|
-
}
|
|
513
|
+
};
|
|
512
514
|
function validateEncodeData(context, target, encodeData) {
|
|
513
515
|
function check(validTargets, validEncodeTypes) {
|
|
514
516
|
var _a, _b;
|
|
@@ -569,20 +571,20 @@ export function getEncode(program, target) {
|
|
|
569
571
|
}
|
|
570
572
|
// -- @visibility decorator ---------------------
|
|
571
573
|
const visibilitySettingsKey = createStateSymbol("visibilitySettings");
|
|
572
|
-
export
|
|
574
|
+
export const $visibility = (context, target, ...visibilities) => {
|
|
573
575
|
validateDecoratorUniqueOnNode(context, target, $visibility);
|
|
574
576
|
context.program.stateMap(visibilitySettingsKey).set(target, visibilities);
|
|
575
|
-
}
|
|
577
|
+
};
|
|
576
578
|
export function getVisibility(program, target) {
|
|
577
579
|
return program.stateMap(visibilitySettingsKey).get(target);
|
|
578
580
|
}
|
|
579
581
|
function clearVisibilities(program, target) {
|
|
580
582
|
program.stateMap(visibilitySettingsKey).delete(target);
|
|
581
583
|
}
|
|
582
|
-
export
|
|
584
|
+
export const $withVisibility = (context, target, ...visibilities) => {
|
|
583
585
|
filterModelPropertiesInPlace(target, (p) => isVisible(context.program, p, visibilities));
|
|
584
586
|
[...target.properties.values()].forEach((p) => clearVisibilities(context.program, p));
|
|
585
|
-
}
|
|
587
|
+
};
|
|
586
588
|
export function isVisible(program, property, visibilities) {
|
|
587
589
|
const propertyVisibilities = getVisibility(program, property);
|
|
588
590
|
return !propertyVisibilities || propertyVisibilities.some((v) => visibilities.includes(v));
|
|
@@ -595,25 +597,25 @@ function filterModelPropertiesInPlace(model, filter) {
|
|
|
595
597
|
}
|
|
596
598
|
}
|
|
597
599
|
// -- @withOptionalProperties decorator ---------------------
|
|
598
|
-
export
|
|
600
|
+
export const $withOptionalProperties = (context, target) => {
|
|
599
601
|
// Make all properties of the target type optional
|
|
600
602
|
target.properties.forEach((p) => (p.optional = true));
|
|
601
|
-
}
|
|
603
|
+
};
|
|
602
604
|
// -- @withUpdateableProperties decorator ----------------------
|
|
603
|
-
export
|
|
605
|
+
export const $withUpdateableProperties = (context, target) => {
|
|
604
606
|
if (!validateDecoratorTarget(context, target, "@withUpdateableProperties", "Model")) {
|
|
605
607
|
return;
|
|
606
608
|
}
|
|
607
609
|
filterModelPropertiesInPlace(target, (p) => isVisible(context.program, p, ["update"]));
|
|
608
|
-
}
|
|
610
|
+
};
|
|
609
611
|
// -- @withoutOmittedProperties decorator ----------------------
|
|
610
|
-
export
|
|
612
|
+
export const $withoutOmittedProperties = (context, target, omitProperties) => {
|
|
611
613
|
// Get the property or properties to omit
|
|
612
614
|
const omitNames = new Set();
|
|
613
615
|
if (omitProperties.kind === "String") {
|
|
614
616
|
omitNames.add(omitProperties.value);
|
|
615
617
|
}
|
|
616
|
-
else {
|
|
618
|
+
else if (omitProperties.kind === "Union") {
|
|
617
619
|
for (const variant of omitProperties.variants.values()) {
|
|
618
620
|
if (variant.type.kind === "String") {
|
|
619
621
|
omitNames.add(variant.type.value);
|
|
@@ -622,18 +624,19 @@ export function $withoutOmittedProperties(context, target, omitProperties) {
|
|
|
622
624
|
}
|
|
623
625
|
// Remove all properties to be omitted
|
|
624
626
|
filterModelPropertiesInPlace(target, (prop) => !omitNames.has(prop.name));
|
|
625
|
-
}
|
|
627
|
+
};
|
|
626
628
|
// -- @withoutDefaultValues decorator ----------------------
|
|
627
|
-
export
|
|
629
|
+
export const $withoutDefaultValues = (context, target) => {
|
|
628
630
|
// remove all read-only properties from the target type
|
|
629
631
|
target.properties.forEach((p) => delete p.default);
|
|
630
|
-
}
|
|
632
|
+
};
|
|
631
633
|
// -- @list decorator ---------------------
|
|
632
634
|
const listPropertiesKey = createStateSymbol("listProperties");
|
|
633
635
|
/**
|
|
634
636
|
* @deprecated Use the `listsResource` decorator in `@typespec/rest` instead.
|
|
635
637
|
*/
|
|
636
|
-
|
|
638
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
639
|
+
export const $list = (context, target, listedType) => {
|
|
637
640
|
if (listedType && listedType.kind === "TemplateParameter") {
|
|
638
641
|
// Silently return because this is probably being used in a templated interface
|
|
639
642
|
return;
|
|
@@ -646,7 +649,7 @@ export function $list(context, target, listedType) {
|
|
|
646
649
|
return;
|
|
647
650
|
}
|
|
648
651
|
context.program.stateMap(listPropertiesKey).set(target, listedType);
|
|
649
|
-
}
|
|
652
|
+
};
|
|
650
653
|
/**
|
|
651
654
|
* @deprecated This function is unused and will be removed in a future release.
|
|
652
655
|
*/
|
|
@@ -664,7 +667,7 @@ export function isListOperation(program, target) {
|
|
|
664
667
|
const tagPropertiesKey = createStateSymbol("tagProperties");
|
|
665
668
|
// Set a tag on an operation, interface, or namespace. There can be multiple tags on an
|
|
666
669
|
// operation, interface, or namespace.
|
|
667
|
-
export
|
|
670
|
+
export const $tag = (context, target, tag) => {
|
|
668
671
|
const tags = context.program.stateMap(tagPropertiesKey).get(target);
|
|
669
672
|
if (tags) {
|
|
670
673
|
tags.push(tag);
|
|
@@ -672,7 +675,7 @@ export function $tag(context, target, tag) {
|
|
|
672
675
|
else {
|
|
673
676
|
context.program.stateMap(tagPropertiesKey).set(target, [tag]);
|
|
674
677
|
}
|
|
675
|
-
}
|
|
678
|
+
};
|
|
676
679
|
// Return the tags set on an operation or namespace
|
|
677
680
|
export function getTags(program, target) {
|
|
678
681
|
return program.stateMap(tagPropertiesKey).get(target) || [];
|
|
@@ -700,13 +703,13 @@ export function getAllTags(program, target) {
|
|
|
700
703
|
}
|
|
701
704
|
// -- @friendlyName decorator ---------------------
|
|
702
705
|
const friendlyNamesKey = createStateSymbol("friendlyNames");
|
|
703
|
-
export
|
|
706
|
+
export const $friendlyName = (context, target, friendlyName, sourceObject) => {
|
|
704
707
|
// If an object was passed in, use it to format the friendly name
|
|
705
708
|
if (sourceObject) {
|
|
706
709
|
friendlyName = replaceTemplatedStringFromProperties(friendlyName, sourceObject);
|
|
707
710
|
}
|
|
708
711
|
context.program.stateMap(friendlyNamesKey).set(target, friendlyName);
|
|
709
|
-
}
|
|
712
|
+
};
|
|
710
713
|
export function getFriendlyName(program, target) {
|
|
711
714
|
return program.stateMap(friendlyNamesKey).get(target);
|
|
712
715
|
}
|
|
@@ -722,7 +725,7 @@ const knownValuesKey = createStateSymbol("knownValues");
|
|
|
722
725
|
* @param target Decorator target. Must be a string. (model Foo extends string)
|
|
723
726
|
* @param knownValues Must be an enum.
|
|
724
727
|
*/
|
|
725
|
-
export
|
|
728
|
+
export const $knownValues = (context, target, knownValues) => {
|
|
726
729
|
const type = getPropertyType(target);
|
|
727
730
|
if (!isStringType(context.program, type) && !isNumericType(context.program, type)) {
|
|
728
731
|
context.program.reportDiagnostic(createDiagnostic({
|
|
@@ -747,7 +750,7 @@ export function $knownValues(context, target, knownValues) {
|
|
|
747
750
|
}
|
|
748
751
|
}
|
|
749
752
|
context.program.stateMap(knownValuesKey).set(target, knownValues);
|
|
750
|
-
}
|
|
753
|
+
};
|
|
751
754
|
function isEnumMemberAssignableToType(program, typeName, member) {
|
|
752
755
|
const memberType = member.value !== undefined ? typeof member.value : "string";
|
|
753
756
|
switch (memberType) {
|
|
@@ -771,7 +774,7 @@ const keyKey = createStateSymbol("key");
|
|
|
771
774
|
*
|
|
772
775
|
* `@key` can only be applied to model properties.
|
|
773
776
|
*/
|
|
774
|
-
export
|
|
777
|
+
export const $key = (context, entity, altName) => {
|
|
775
778
|
// Ensure that the key property is not marked as optional
|
|
776
779
|
if (entity.optional) {
|
|
777
780
|
reportDiagnostic(context.program, {
|
|
@@ -783,14 +786,14 @@ export function $key(context, entity, altName) {
|
|
|
783
786
|
}
|
|
784
787
|
// Register the key property
|
|
785
788
|
context.program.stateMap(keyKey).set(entity, altName || entity.name);
|
|
786
|
-
}
|
|
789
|
+
};
|
|
787
790
|
export function isKey(program, property) {
|
|
788
791
|
return program.stateMap(keyKey).has(property);
|
|
789
792
|
}
|
|
790
793
|
export function getKeyName(program, property) {
|
|
791
794
|
return program.stateMap(keyKey).get(property);
|
|
792
795
|
}
|
|
793
|
-
export
|
|
796
|
+
export const $withDefaultKeyVisibility = (context, entity, visibility) => {
|
|
794
797
|
const keyProperties = [];
|
|
795
798
|
entity.properties.forEach((prop) => {
|
|
796
799
|
// Keep track of any key property without a visibility
|
|
@@ -813,7 +816,7 @@ export function $withDefaultKeyVisibility(context, entity, visibility) {
|
|
|
813
816
|
],
|
|
814
817
|
}));
|
|
815
818
|
});
|
|
816
|
-
}
|
|
819
|
+
};
|
|
817
820
|
/**
|
|
818
821
|
* Mark a type as deprecated
|
|
819
822
|
* @param context DecoratorContext
|
|
@@ -825,9 +828,10 @@ export function $withDefaultKeyVisibility(context, entity, visibility) {
|
|
|
825
828
|
* model Foo {}
|
|
826
829
|
* ```
|
|
827
830
|
*/
|
|
828
|
-
|
|
831
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
832
|
+
export const $deprecated = (context, target, message) => {
|
|
829
833
|
markDeprecated(context.program, target, { message });
|
|
830
|
-
}
|
|
834
|
+
};
|
|
831
835
|
/**
|
|
832
836
|
* Return the deprecated message or undefined if not deprecated
|
|
833
837
|
* @param program Program
|
|
@@ -845,7 +849,7 @@ const overloadsOperationKey = createStateSymbol("overloadsOperation");
|
|
|
845
849
|
* @param target The specializing operation declaration
|
|
846
850
|
* @param overloadBase The operation to be overloaded.
|
|
847
851
|
*/
|
|
848
|
-
export
|
|
852
|
+
export const $overload = (context, target, overloadBase) => {
|
|
849
853
|
var _a, _b, _c, _d;
|
|
850
854
|
// Ensure that the overloaded method arguments are a subtype of the original operation.
|
|
851
855
|
const [paramValid, paramDiagnostics] = context.program.checker.isTypeAssignableTo((_a = target.parameters.projectionBase) !== null && _a !== void 0 ? _a : target.parameters, (_b = overloadBase.parameters.projectionBase) !== null && _b !== void 0 ? _b : overloadBase.parameters, target);
|
|
@@ -864,7 +868,7 @@ export function $overload(context, target, overloadBase) {
|
|
|
864
868
|
context.program.stateMap(overloadsOperationKey).set(target, overloadBase);
|
|
865
869
|
const existingOverloads = getOverloads(context.program, overloadBase) || new Array();
|
|
866
870
|
context.program.stateMap(overloadedByKey).set(overloadBase, existingOverloads.concat(target));
|
|
867
|
-
}
|
|
871
|
+
};
|
|
868
872
|
function areOperationsInSameContainer(op1, op2) {
|
|
869
873
|
return op1.interface || op2.interface
|
|
870
874
|
? equalsWithoutProjection(op1.interface, op2.interface)
|
|
@@ -910,14 +914,14 @@ const projectedNameKey = createStateSymbol("projectedNameKey");
|
|
|
910
914
|
* @param projectionName Name of the projection (e.g. "toJson", "toCSharp")
|
|
911
915
|
* @param projectedName Name of the type should have in the scope of the projection specified.
|
|
912
916
|
*/
|
|
913
|
-
export
|
|
917
|
+
export const $projectedName = (context, target, projectionName, projectedName) => {
|
|
914
918
|
let map = context.program.stateMap(projectedNameKey).get(target);
|
|
915
919
|
if (map === undefined) {
|
|
916
920
|
map = new Map();
|
|
917
921
|
context.program.stateMap(projectedNameKey).set(target, map);
|
|
918
922
|
}
|
|
919
923
|
map.set(projectionName, projectedName);
|
|
920
|
-
}
|
|
924
|
+
};
|
|
921
925
|
/**
|
|
922
926
|
* @param program Program
|
|
923
927
|
* @param target Target
|
|
@@ -961,7 +965,7 @@ function validateRange(context, min, max) {
|
|
|
961
965
|
return true;
|
|
962
966
|
}
|
|
963
967
|
const discriminatorKey = createStateSymbol("discriminator");
|
|
964
|
-
export
|
|
968
|
+
export const $discriminator = (context, entity, propertyName) => {
|
|
965
969
|
const discriminator = { propertyName };
|
|
966
970
|
if (entity.kind === "Union") {
|
|
967
971
|
// we can validate discriminator up front for unions. Models are validated in the accessor as we might not have the reference to all derived types at this time.
|
|
@@ -972,7 +976,7 @@ export function $discriminator(context, entity, propertyName) {
|
|
|
972
976
|
}
|
|
973
977
|
}
|
|
974
978
|
context.program.stateMap(discriminatorKey).set(entity, discriminator);
|
|
975
|
-
}
|
|
979
|
+
};
|
|
976
980
|
export function getDiscriminator(program, entity) {
|
|
977
981
|
return program.stateMap(discriminatorKey).get(entity);
|
|
978
982
|
}
|
|
@@ -980,10 +984,10 @@ export function getDiscriminatedTypes(program) {
|
|
|
980
984
|
return [...program.stateMap(discriminatorKey).entries()];
|
|
981
985
|
}
|
|
982
986
|
const parameterVisibilityKey = createStateSymbol("parameterVisibility");
|
|
983
|
-
export
|
|
987
|
+
export const $parameterVisibility = (context, entity, ...visibilities) => {
|
|
984
988
|
validateDecoratorUniqueOnNode(context, entity, $parameterVisibility);
|
|
985
989
|
context.program.stateMap(parameterVisibilityKey).set(entity, visibilities);
|
|
986
|
-
}
|
|
990
|
+
};
|
|
987
991
|
/**
|
|
988
992
|
* Returns the visibilities of the parameters of the given operation, if provided with `@parameterVisibility`.
|
|
989
993
|
*
|
|
@@ -993,10 +997,10 @@ export function getParameterVisibility(program, entity) {
|
|
|
993
997
|
return program.stateMap(parameterVisibilityKey).get(entity);
|
|
994
998
|
}
|
|
995
999
|
const returnTypeVisibilityKey = createStateSymbol("returnTypeVisibility");
|
|
996
|
-
export
|
|
1000
|
+
export const $returnTypeVisibility = (context, entity, ...visibilities) => {
|
|
997
1001
|
validateDecoratorUniqueOnNode(context, entity, $returnTypeVisibility);
|
|
998
1002
|
context.program.stateMap(returnTypeVisibilityKey).set(entity, visibilities);
|
|
999
|
-
}
|
|
1003
|
+
};
|
|
1000
1004
|
/**
|
|
1001
1005
|
* Returns the visibilities of the return type of the given operation, if provided with `@returnTypeVisibility`.
|
|
1002
1006
|
*
|