@typespec/compiler 0.55.0-dev.1 → 0.55.0-dev.10
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/core/binder.d.ts.map +1 -1
- package/dist/src/core/binder.js +3 -0
- package/dist/src/core/binder.js.map +1 -1
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +5 -0
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/messages.js +1 -1
- package/dist/src/core/parser.d.ts.map +1 -1
- package/dist/src/core/parser.js +8 -1
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/program.d.ts.map +1 -1
- package/dist/src/core/program.js +6 -2
- package/dist/src/core/program.js.map +1 -1
- package/dist/src/core/projection-members.d.ts.map +1 -1
- package/dist/src/core/projection-members.js +4 -0
- package/dist/src/core/projection-members.js.map +1 -1
- package/dist/src/core/types.d.ts +34 -30
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js +29 -28
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/formatter/print/printer.d.ts.map +1 -1
- package/dist/src/formatter/print/printer.js +2 -0
- package/dist/src/formatter/print/printer.js.map +1 -1
- 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 +89 -89
- 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/classify.d.ts.map +1 -1
- package/dist/src/server/classify.js +3 -0
- package/dist/src/server/classify.js.map +1 -1
- package/dist/src/server/serverlib.d.ts.map +1 -1
- package/dist/src/server/serverlib.js +7 -11
- package/dist/src/server/serverlib.js.map +1 -1
- package/dist/src/server/tmlanguage.d.ts.map +1 -1
- package/dist/src/server/tmlanguage.js +64 -11
- package/dist/src/server/tmlanguage.js.map +1 -1
- package/dist/typespec.tmLanguage +226 -42
- package/lib/decorators.tsp +1 -0
- package/package.json +11 -10
- 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,39 +487,37 @@ 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
|
-
if (targetType.kind !== "Scalar") {
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
511
|
validateEncodeData(context, targetType, encodeData);
|
|
513
512
|
context.program.stateMap(encodeKey).set(target, encodeData);
|
|
514
|
-
}
|
|
513
|
+
};
|
|
515
514
|
function validateEncodeData(context, target, encodeData) {
|
|
516
515
|
function check(validTargets, validEncodeTypes) {
|
|
517
|
-
var _a;
|
|
516
|
+
var _a, _b;
|
|
518
517
|
const checker = context.program.checker;
|
|
519
|
-
const isTargetValid = validTargets.some((validTarget) => {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
});
|
|
518
|
+
const isTargetValid = isTypeIn((_a = target.projectionBase) !== null && _a !== void 0 ? _a : target, (type) => validTargets.some((validTarget) => {
|
|
519
|
+
return ignoreDiagnostics(checker.isTypeAssignableTo(type, checker.getStdType(validTarget), target));
|
|
520
|
+
}));
|
|
523
521
|
if (!isTargetValid) {
|
|
524
522
|
reportDiagnostic(context.program, {
|
|
525
523
|
code: "invalid-encode",
|
|
@@ -537,7 +535,7 @@ function validateEncodeData(context, target, encodeData) {
|
|
|
537
535
|
return ignoreDiagnostics(checker.isTypeAssignableTo((_a = encodeData.type.projectionBase) !== null && _a !== void 0 ? _a : encodeData.type, checker.getStdType(validEncoding), target));
|
|
538
536
|
});
|
|
539
537
|
if (!isEncodingTypeValid) {
|
|
540
|
-
const typeName = getTypeName((
|
|
538
|
+
const typeName = getTypeName((_b = encodeData.type.projectionBase) !== null && _b !== void 0 ? _b : encodeData.type);
|
|
541
539
|
reportDiagnostic(context.program, {
|
|
542
540
|
code: "invalid-encode",
|
|
543
541
|
messageId: ["unixTimestamp", "seconds"].includes(encodeData.encoding)
|
|
@@ -573,20 +571,20 @@ export function getEncode(program, target) {
|
|
|
573
571
|
}
|
|
574
572
|
// -- @visibility decorator ---------------------
|
|
575
573
|
const visibilitySettingsKey = createStateSymbol("visibilitySettings");
|
|
576
|
-
export
|
|
574
|
+
export const $visibility = (context, target, ...visibilities) => {
|
|
577
575
|
validateDecoratorUniqueOnNode(context, target, $visibility);
|
|
578
576
|
context.program.stateMap(visibilitySettingsKey).set(target, visibilities);
|
|
579
|
-
}
|
|
577
|
+
};
|
|
580
578
|
export function getVisibility(program, target) {
|
|
581
579
|
return program.stateMap(visibilitySettingsKey).get(target);
|
|
582
580
|
}
|
|
583
581
|
function clearVisibilities(program, target) {
|
|
584
582
|
program.stateMap(visibilitySettingsKey).delete(target);
|
|
585
583
|
}
|
|
586
|
-
export
|
|
584
|
+
export const $withVisibility = (context, target, ...visibilities) => {
|
|
587
585
|
filterModelPropertiesInPlace(target, (p) => isVisible(context.program, p, visibilities));
|
|
588
586
|
[...target.properties.values()].forEach((p) => clearVisibilities(context.program, p));
|
|
589
|
-
}
|
|
587
|
+
};
|
|
590
588
|
export function isVisible(program, property, visibilities) {
|
|
591
589
|
const propertyVisibilities = getVisibility(program, property);
|
|
592
590
|
return !propertyVisibilities || propertyVisibilities.some((v) => visibilities.includes(v));
|
|
@@ -599,25 +597,25 @@ function filterModelPropertiesInPlace(model, filter) {
|
|
|
599
597
|
}
|
|
600
598
|
}
|
|
601
599
|
// -- @withOptionalProperties decorator ---------------------
|
|
602
|
-
export
|
|
600
|
+
export const $withOptionalProperties = (context, target) => {
|
|
603
601
|
// Make all properties of the target type optional
|
|
604
602
|
target.properties.forEach((p) => (p.optional = true));
|
|
605
|
-
}
|
|
603
|
+
};
|
|
606
604
|
// -- @withUpdateableProperties decorator ----------------------
|
|
607
|
-
export
|
|
605
|
+
export const $withUpdateableProperties = (context, target) => {
|
|
608
606
|
if (!validateDecoratorTarget(context, target, "@withUpdateableProperties", "Model")) {
|
|
609
607
|
return;
|
|
610
608
|
}
|
|
611
609
|
filterModelPropertiesInPlace(target, (p) => isVisible(context.program, p, ["update"]));
|
|
612
|
-
}
|
|
610
|
+
};
|
|
613
611
|
// -- @withoutOmittedProperties decorator ----------------------
|
|
614
|
-
export
|
|
612
|
+
export const $withoutOmittedProperties = (context, target, omitProperties) => {
|
|
615
613
|
// Get the property or properties to omit
|
|
616
614
|
const omitNames = new Set();
|
|
617
615
|
if (omitProperties.kind === "String") {
|
|
618
616
|
omitNames.add(omitProperties.value);
|
|
619
617
|
}
|
|
620
|
-
else {
|
|
618
|
+
else if (omitProperties.kind === "Union") {
|
|
621
619
|
for (const variant of omitProperties.variants.values()) {
|
|
622
620
|
if (variant.type.kind === "String") {
|
|
623
621
|
omitNames.add(variant.type.value);
|
|
@@ -626,18 +624,19 @@ export function $withoutOmittedProperties(context, target, omitProperties) {
|
|
|
626
624
|
}
|
|
627
625
|
// Remove all properties to be omitted
|
|
628
626
|
filterModelPropertiesInPlace(target, (prop) => !omitNames.has(prop.name));
|
|
629
|
-
}
|
|
627
|
+
};
|
|
630
628
|
// -- @withoutDefaultValues decorator ----------------------
|
|
631
|
-
export
|
|
629
|
+
export const $withoutDefaultValues = (context, target) => {
|
|
632
630
|
// remove all read-only properties from the target type
|
|
633
631
|
target.properties.forEach((p) => delete p.default);
|
|
634
|
-
}
|
|
632
|
+
};
|
|
635
633
|
// -- @list decorator ---------------------
|
|
636
634
|
const listPropertiesKey = createStateSymbol("listProperties");
|
|
637
635
|
/**
|
|
638
636
|
* @deprecated Use the `listsResource` decorator in `@typespec/rest` instead.
|
|
639
637
|
*/
|
|
640
|
-
|
|
638
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
639
|
+
export const $list = (context, target, listedType) => {
|
|
641
640
|
if (listedType && listedType.kind === "TemplateParameter") {
|
|
642
641
|
// Silently return because this is probably being used in a templated interface
|
|
643
642
|
return;
|
|
@@ -650,7 +649,7 @@ export function $list(context, target, listedType) {
|
|
|
650
649
|
return;
|
|
651
650
|
}
|
|
652
651
|
context.program.stateMap(listPropertiesKey).set(target, listedType);
|
|
653
|
-
}
|
|
652
|
+
};
|
|
654
653
|
/**
|
|
655
654
|
* @deprecated This function is unused and will be removed in a future release.
|
|
656
655
|
*/
|
|
@@ -668,7 +667,7 @@ export function isListOperation(program, target) {
|
|
|
668
667
|
const tagPropertiesKey = createStateSymbol("tagProperties");
|
|
669
668
|
// Set a tag on an operation, interface, or namespace. There can be multiple tags on an
|
|
670
669
|
// operation, interface, or namespace.
|
|
671
|
-
export
|
|
670
|
+
export const $tag = (context, target, tag) => {
|
|
672
671
|
const tags = context.program.stateMap(tagPropertiesKey).get(target);
|
|
673
672
|
if (tags) {
|
|
674
673
|
tags.push(tag);
|
|
@@ -676,7 +675,7 @@ export function $tag(context, target, tag) {
|
|
|
676
675
|
else {
|
|
677
676
|
context.program.stateMap(tagPropertiesKey).set(target, [tag]);
|
|
678
677
|
}
|
|
679
|
-
}
|
|
678
|
+
};
|
|
680
679
|
// Return the tags set on an operation or namespace
|
|
681
680
|
export function getTags(program, target) {
|
|
682
681
|
return program.stateMap(tagPropertiesKey).get(target) || [];
|
|
@@ -704,13 +703,13 @@ export function getAllTags(program, target) {
|
|
|
704
703
|
}
|
|
705
704
|
// -- @friendlyName decorator ---------------------
|
|
706
705
|
const friendlyNamesKey = createStateSymbol("friendlyNames");
|
|
707
|
-
export
|
|
706
|
+
export const $friendlyName = (context, target, friendlyName, sourceObject) => {
|
|
708
707
|
// If an object was passed in, use it to format the friendly name
|
|
709
708
|
if (sourceObject) {
|
|
710
709
|
friendlyName = replaceTemplatedStringFromProperties(friendlyName, sourceObject);
|
|
711
710
|
}
|
|
712
711
|
context.program.stateMap(friendlyNamesKey).set(target, friendlyName);
|
|
713
|
-
}
|
|
712
|
+
};
|
|
714
713
|
export function getFriendlyName(program, target) {
|
|
715
714
|
return program.stateMap(friendlyNamesKey).get(target);
|
|
716
715
|
}
|
|
@@ -726,7 +725,7 @@ const knownValuesKey = createStateSymbol("knownValues");
|
|
|
726
725
|
* @param target Decorator target. Must be a string. (model Foo extends string)
|
|
727
726
|
* @param knownValues Must be an enum.
|
|
728
727
|
*/
|
|
729
|
-
export
|
|
728
|
+
export const $knownValues = (context, target, knownValues) => {
|
|
730
729
|
const type = getPropertyType(target);
|
|
731
730
|
if (!isStringType(context.program, type) && !isNumericType(context.program, type)) {
|
|
732
731
|
context.program.reportDiagnostic(createDiagnostic({
|
|
@@ -751,7 +750,7 @@ export function $knownValues(context, target, knownValues) {
|
|
|
751
750
|
}
|
|
752
751
|
}
|
|
753
752
|
context.program.stateMap(knownValuesKey).set(target, knownValues);
|
|
754
|
-
}
|
|
753
|
+
};
|
|
755
754
|
function isEnumMemberAssignableToType(program, typeName, member) {
|
|
756
755
|
const memberType = member.value !== undefined ? typeof member.value : "string";
|
|
757
756
|
switch (memberType) {
|
|
@@ -775,7 +774,7 @@ const keyKey = createStateSymbol("key");
|
|
|
775
774
|
*
|
|
776
775
|
* `@key` can only be applied to model properties.
|
|
777
776
|
*/
|
|
778
|
-
export
|
|
777
|
+
export const $key = (context, entity, altName) => {
|
|
779
778
|
// Ensure that the key property is not marked as optional
|
|
780
779
|
if (entity.optional) {
|
|
781
780
|
reportDiagnostic(context.program, {
|
|
@@ -787,14 +786,14 @@ export function $key(context, entity, altName) {
|
|
|
787
786
|
}
|
|
788
787
|
// Register the key property
|
|
789
788
|
context.program.stateMap(keyKey).set(entity, altName || entity.name);
|
|
790
|
-
}
|
|
789
|
+
};
|
|
791
790
|
export function isKey(program, property) {
|
|
792
791
|
return program.stateMap(keyKey).has(property);
|
|
793
792
|
}
|
|
794
793
|
export function getKeyName(program, property) {
|
|
795
794
|
return program.stateMap(keyKey).get(property);
|
|
796
795
|
}
|
|
797
|
-
export
|
|
796
|
+
export const $withDefaultKeyVisibility = (context, entity, visibility) => {
|
|
798
797
|
const keyProperties = [];
|
|
799
798
|
entity.properties.forEach((prop) => {
|
|
800
799
|
// Keep track of any key property without a visibility
|
|
@@ -817,7 +816,7 @@ export function $withDefaultKeyVisibility(context, entity, visibility) {
|
|
|
817
816
|
],
|
|
818
817
|
}));
|
|
819
818
|
});
|
|
820
|
-
}
|
|
819
|
+
};
|
|
821
820
|
/**
|
|
822
821
|
* Mark a type as deprecated
|
|
823
822
|
* @param context DecoratorContext
|
|
@@ -829,9 +828,10 @@ export function $withDefaultKeyVisibility(context, entity, visibility) {
|
|
|
829
828
|
* model Foo {}
|
|
830
829
|
* ```
|
|
831
830
|
*/
|
|
832
|
-
|
|
831
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
832
|
+
export const $deprecated = (context, target, message) => {
|
|
833
833
|
markDeprecated(context.program, target, { message });
|
|
834
|
-
}
|
|
834
|
+
};
|
|
835
835
|
/**
|
|
836
836
|
* Return the deprecated message or undefined if not deprecated
|
|
837
837
|
* @param program Program
|
|
@@ -849,7 +849,7 @@ const overloadsOperationKey = createStateSymbol("overloadsOperation");
|
|
|
849
849
|
* @param target The specializing operation declaration
|
|
850
850
|
* @param overloadBase The operation to be overloaded.
|
|
851
851
|
*/
|
|
852
|
-
export
|
|
852
|
+
export const $overload = (context, target, overloadBase) => {
|
|
853
853
|
var _a, _b, _c, _d;
|
|
854
854
|
// Ensure that the overloaded method arguments are a subtype of the original operation.
|
|
855
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);
|
|
@@ -868,7 +868,7 @@ export function $overload(context, target, overloadBase) {
|
|
|
868
868
|
context.program.stateMap(overloadsOperationKey).set(target, overloadBase);
|
|
869
869
|
const existingOverloads = getOverloads(context.program, overloadBase) || new Array();
|
|
870
870
|
context.program.stateMap(overloadedByKey).set(overloadBase, existingOverloads.concat(target));
|
|
871
|
-
}
|
|
871
|
+
};
|
|
872
872
|
function areOperationsInSameContainer(op1, op2) {
|
|
873
873
|
return op1.interface || op2.interface
|
|
874
874
|
? equalsWithoutProjection(op1.interface, op2.interface)
|
|
@@ -914,14 +914,14 @@ const projectedNameKey = createStateSymbol("projectedNameKey");
|
|
|
914
914
|
* @param projectionName Name of the projection (e.g. "toJson", "toCSharp")
|
|
915
915
|
* @param projectedName Name of the type should have in the scope of the projection specified.
|
|
916
916
|
*/
|
|
917
|
-
export
|
|
917
|
+
export const $projectedName = (context, target, projectionName, projectedName) => {
|
|
918
918
|
let map = context.program.stateMap(projectedNameKey).get(target);
|
|
919
919
|
if (map === undefined) {
|
|
920
920
|
map = new Map();
|
|
921
921
|
context.program.stateMap(projectedNameKey).set(target, map);
|
|
922
922
|
}
|
|
923
923
|
map.set(projectionName, projectedName);
|
|
924
|
-
}
|
|
924
|
+
};
|
|
925
925
|
/**
|
|
926
926
|
* @param program Program
|
|
927
927
|
* @param target Target
|
|
@@ -965,7 +965,7 @@ function validateRange(context, min, max) {
|
|
|
965
965
|
return true;
|
|
966
966
|
}
|
|
967
967
|
const discriminatorKey = createStateSymbol("discriminator");
|
|
968
|
-
export
|
|
968
|
+
export const $discriminator = (context, entity, propertyName) => {
|
|
969
969
|
const discriminator = { propertyName };
|
|
970
970
|
if (entity.kind === "Union") {
|
|
971
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.
|
|
@@ -976,7 +976,7 @@ export function $discriminator(context, entity, propertyName) {
|
|
|
976
976
|
}
|
|
977
977
|
}
|
|
978
978
|
context.program.stateMap(discriminatorKey).set(entity, discriminator);
|
|
979
|
-
}
|
|
979
|
+
};
|
|
980
980
|
export function getDiscriminator(program, entity) {
|
|
981
981
|
return program.stateMap(discriminatorKey).get(entity);
|
|
982
982
|
}
|
|
@@ -984,10 +984,10 @@ export function getDiscriminatedTypes(program) {
|
|
|
984
984
|
return [...program.stateMap(discriminatorKey).entries()];
|
|
985
985
|
}
|
|
986
986
|
const parameterVisibilityKey = createStateSymbol("parameterVisibility");
|
|
987
|
-
export
|
|
987
|
+
export const $parameterVisibility = (context, entity, ...visibilities) => {
|
|
988
988
|
validateDecoratorUniqueOnNode(context, entity, $parameterVisibility);
|
|
989
989
|
context.program.stateMap(parameterVisibilityKey).set(entity, visibilities);
|
|
990
|
-
}
|
|
990
|
+
};
|
|
991
991
|
/**
|
|
992
992
|
* Returns the visibilities of the parameters of the given operation, if provided with `@parameterVisibility`.
|
|
993
993
|
*
|
|
@@ -997,10 +997,10 @@ export function getParameterVisibility(program, entity) {
|
|
|
997
997
|
return program.stateMap(parameterVisibilityKey).get(entity);
|
|
998
998
|
}
|
|
999
999
|
const returnTypeVisibilityKey = createStateSymbol("returnTypeVisibility");
|
|
1000
|
-
export
|
|
1000
|
+
export const $returnTypeVisibility = (context, entity, ...visibilities) => {
|
|
1001
1001
|
validateDecoratorUniqueOnNode(context, entity, $returnTypeVisibility);
|
|
1002
1002
|
context.program.stateMap(returnTypeVisibilityKey).set(entity, visibilities);
|
|
1003
|
-
}
|
|
1003
|
+
};
|
|
1004
1004
|
/**
|
|
1005
1005
|
* Returns the visibilities of the return type of the given operation, if provided with `@returnTypeVisibility`.
|
|
1006
1006
|
*
|