@typespec/compiler 0.63.0-dev.1 → 0.63.0-dev.3
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.Prototypes.d.ts +1 -1
- package/dist/generated-defs/TypeSpec.Prototypes.d.ts.map +1 -1
- package/dist/generated-defs/TypeSpec.d.ts +198 -79
- package/dist/generated-defs/TypeSpec.d.ts.map +1 -1
- package/dist/manifest.js +2 -2
- package/dist/src/core/index.d.ts +1 -0
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +1 -0
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/logger/logger.js +1 -1
- package/dist/src/core/logger/logger.js.map +1 -1
- package/dist/src/core/messages.d.ts +56 -2
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +20 -0
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/visibility/core.d.ts +240 -0
- package/dist/src/core/visibility/core.d.ts.map +1 -0
- package/dist/src/core/visibility/core.js +483 -0
- package/dist/src/core/visibility/core.js.map +1 -0
- package/dist/src/core/visibility/index.d.ts +3 -0
- package/dist/src/core/visibility/index.d.ts.map +1 -0
- package/dist/src/core/visibility/index.js +5 -0
- package/dist/src/core/visibility/index.js.map +1 -0
- package/dist/src/core/visibility/lifecycle.d.ts +28 -0
- package/dist/src/core/visibility/lifecycle.d.ts.map +1 -0
- package/dist/src/core/visibility/lifecycle.js +68 -0
- package/dist/src/core/visibility/lifecycle.js.map +1 -0
- package/dist/src/experimental/mutators.d.ts +4 -0
- package/dist/src/experimental/mutators.d.ts.map +1 -1
- package/dist/src/experimental/mutators.js +17 -0
- package/dist/src/experimental/mutators.js.map +1 -1
- package/dist/src/experimental/typekit/define-kit.js +3 -3
- package/dist/src/experimental/typekit/define-kit.js.map +1 -1
- package/dist/src/experimental/typekit/kits/model-property.d.ts +2 -2
- package/dist/src/experimental/typekit/kits/model-property.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/model-property.js +4 -3
- package/dist/src/experimental/typekit/kits/model-property.js.map +1 -1
- package/dist/src/lib/decorators.d.ts +5 -28
- package/dist/src/lib/decorators.d.ts.map +1 -1
- package/dist/src/lib/decorators.js +6 -83
- package/dist/src/lib/decorators.js.map +1 -1
- package/dist/src/lib/key.d.ts +6 -0
- package/dist/src/lib/key.d.ts.map +1 -0
- package/dist/src/lib/key.js +7 -0
- package/dist/src/lib/key.js.map +1 -0
- package/dist/src/lib/tsp-index.d.ts.map +1 -1
- package/dist/src/lib/tsp-index.js +10 -4
- package/dist/src/lib/tsp-index.js.map +1 -1
- package/dist/src/lib/utils.d.ts +9 -1
- package/dist/src/lib/utils.d.ts.map +1 -1
- package/dist/src/lib/utils.js +14 -0
- package/dist/src/lib/utils.js.map +1 -1
- package/dist/src/lib/visibility.d.ts +33 -0
- package/dist/src/lib/visibility.d.ts.map +1 -0
- package/dist/src/lib/visibility.js +367 -0
- package/dist/src/lib/visibility.js.map +1 -0
- package/lib/std/decorators.tsp +1 -100
- package/lib/std/main.tsp +1 -0
- package/lib/std/visibility.tsp +400 -0
- package/package.json +1 -1
package/dist/src/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type { Type } from "../core/types.js";
|
|
1
|
+
import type { Model, ModelProperty, Type } from "../core/types.js";
|
|
2
2
|
export declare function useStateMap<K extends Type, V>(key: string | symbol): [(program: import("../index.js").Program, type: K) => V | undefined, (program: import("../index.js").Program, type: K, value: V) => void, (program: import("../index.js").Program) => Map<K, V>];
|
|
3
3
|
export declare function useStateSet<K extends Type>(key: string | symbol): [(program: import("../index.js").Program, type: K) => boolean, (program: import("../index.js").Program, type: K) => void];
|
|
4
|
+
/**
|
|
5
|
+
* Filters the properties of a model by removing them from the model instance if
|
|
6
|
+
* a given `filter` predicate is not satisfied.
|
|
7
|
+
*
|
|
8
|
+
* @param model - the model to filter properties on
|
|
9
|
+
* @param filter - the predicate to filter properties with
|
|
10
|
+
*/
|
|
11
|
+
export declare function filterModelPropertiesInPlace(model: Model, filter: (prop: ModelProperty) => boolean): void;
|
|
4
12
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAOnE,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,oMAElE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,6HAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,QAOzC"}
|
package/dist/src/lib/utils.js
CHANGED
|
@@ -8,4 +8,18 @@ export function useStateMap(key) {
|
|
|
8
8
|
export function useStateSet(key) {
|
|
9
9
|
return unsafe_useStateSet(typeof key === "string" ? createStateSymbol(key) : key);
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Filters the properties of a model by removing them from the model instance if
|
|
13
|
+
* a given `filter` predicate is not satisfied.
|
|
14
|
+
*
|
|
15
|
+
* @param model - the model to filter properties on
|
|
16
|
+
* @param filter - the predicate to filter properties with
|
|
17
|
+
*/
|
|
18
|
+
export function filterModelPropertiesInPlace(model, filter) {
|
|
19
|
+
for (const [key, prop] of model.properties) {
|
|
20
|
+
if (!filter(prop)) {
|
|
21
|
+
model.properties.delete(key);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
11
25
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAE3F,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,MAAM,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,WAAW,CAAoB,GAAoB;IACjE,OAAO,kBAAkB,CAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,WAAW,CAAiB,GAAoB;IAC9D,OAAO,kBAAkB,CAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACvF,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAE3F,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,MAAM,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,WAAW,CAAoB,GAAoB;IACjE,OAAO,kBAAkB,CAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,WAAW,CAAiB,GAAoB;IAC9D,OAAO,kBAAkB,CAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACvF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,4BAA4B,CAC1C,KAAY,EACZ,MAAwC;IAExC,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAClB,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DefaultVisibilityDecorator, InvisibleDecorator, ParameterVisibilityDecorator, RemoveVisibilityDecorator, ReturnTypeVisibilityDecorator, VisibilityDecorator, WithDefaultKeyVisibilityDecorator, WithLifecycleUpdateDecorator, WithUpdateablePropertiesDecorator, WithVisibilityDecorator, WithVisibilityFilterDecorator } from "../../generated-defs/TypeSpec.js";
|
|
2
|
+
import type { Program } from "../core/program.js";
|
|
3
|
+
import { Operation } from "../core/types.js";
|
|
4
|
+
export declare const $withDefaultKeyVisibility: WithDefaultKeyVisibilityDecorator;
|
|
5
|
+
export declare const $parameterVisibility: ParameterVisibilityDecorator;
|
|
6
|
+
/**
|
|
7
|
+
* Returns the visibilities of the parameters of the given operation, if provided with `@parameterVisibility`.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link $parameterVisibility}
|
|
10
|
+
*/
|
|
11
|
+
export declare function getParameterVisibility(program: Program, entity: Operation): string[] | undefined;
|
|
12
|
+
export declare const $returnTypeVisibility: ReturnTypeVisibilityDecorator;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the visibilities of the return type of the given operation, if provided with `@returnTypeVisibility`.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link $returnTypeVisibility}
|
|
17
|
+
*/
|
|
18
|
+
export declare function getReturnTypeVisibility(program: Program, entity: Operation): string[] | undefined;
|
|
19
|
+
export declare const $visibility: VisibilityDecorator;
|
|
20
|
+
export declare const $removeVisibility: RemoveVisibilityDecorator;
|
|
21
|
+
export declare const $invisible: InvisibleDecorator;
|
|
22
|
+
export declare const $defaultVisibility: DefaultVisibilityDecorator;
|
|
23
|
+
export declare const $withVisibility: WithVisibilityDecorator;
|
|
24
|
+
/**
|
|
25
|
+
* Filters a model for properties that are updateable.
|
|
26
|
+
*
|
|
27
|
+
* @param context - the program context
|
|
28
|
+
* @param target - Model to filter for updateable properties
|
|
29
|
+
*/
|
|
30
|
+
export declare const $withUpdateableProperties: WithUpdateablePropertiesDecorator;
|
|
31
|
+
export declare const $withVisibilityFilter: WithVisibilityFilterDecorator;
|
|
32
|
+
export declare const $withLifecycleUpdate: WithLifecycleUpdateDecorator;
|
|
33
|
+
//# sourceMappingURL=visibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.d.ts","sourceRoot":"","sources":["../../../src/lib/visibility.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,0BAA0B,EAC1B,kBAAkB,EAClB,4BAA4B,EAC5B,yBAAyB,EACzB,6BAA6B,EAC7B,mBAAmB,EACnB,iCAAiC,EACjC,4BAA4B,EAC5B,iCAAiC,EACjC,uBAAuB,EACvB,6BAA6B,EAC9B,MAAM,kCAAkC,CAAC;AAG1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EASL,SAAS,EAGV,MAAM,kBAAkB,CAAC;AAiD1B,eAAO,MAAM,yBAAyB,EAAE,iCAsCvC,CAAC;AAoCF,eAAO,MAAM,oBAAoB,EAAE,4BAuBlC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,CAMhG;AAED,eAAO,MAAM,qBAAqB,EAAE,6BAuBnC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,CAMjG;AAQD,eAAO,MAAM,WAAW,EAAE,mBA+BzB,CAAC;AAIF,eAAO,MAAM,iBAAiB,EAAE,yBAU/B,CAAC;AAIF,eAAO,MAAM,UAAU,EAAE,kBAMxB,CAAC;AAIF,eAAO,MAAM,kBAAkB,EAAE,0BAqBhC,CAAC;AAQF,eAAO,MAAM,eAAe,EAAE,uBA+C7B,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,EAAE,iCAUvC,CAAC;AAQF,eAAO,MAAM,qBAAqB,EAAE,6BAcnC,CAAC;AAIF,eAAO,MAAM,oBAAoB,EAAE,4BAuBlC,CAAC"}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { validateDecoratorTarget, validateDecoratorUniqueOnNode } from "../core/decorator-utils.js";
|
|
4
|
+
import { reportDiagnostic } from "../core/messages.js";
|
|
5
|
+
import { addVisibilityModifiers, clearLegacyVisibility, clearVisibilityModifiersForClass, getLegacyVisibility, getVisibility, isVisible, removeVisibilityModifiers, resetVisibilityModifiersForClass, setDefaultModifierSetForVisibilityClass, setLegacyVisibility, VisibilityFilter, } from "../core/visibility/core.js";
|
|
6
|
+
import { getLifecycleVisibilityEnum, normalizeVisibilityToLegacyLifecycleString, } from "../core/visibility/lifecycle.js";
|
|
7
|
+
import { isMutableType, mutateSubgraph, MutatorFlow } from "../experimental/mutators.js";
|
|
8
|
+
import { isKey } from "./key.js";
|
|
9
|
+
import { filterModelPropertiesInPlace, useStateMap } from "./utils.js";
|
|
10
|
+
// #region Legacy Visibility Utilities
|
|
11
|
+
/**
|
|
12
|
+
* Takes a list of visibilities that possibly include both legacy visibility
|
|
13
|
+
* strings and visibility class members, and returns two lists containing only
|
|
14
|
+
* each type.
|
|
15
|
+
*
|
|
16
|
+
* @param visibilities - The list of visibilities to split
|
|
17
|
+
* @returns a tuple containing visibility enum members in the first position and
|
|
18
|
+
* legacy visibility strings in the second position
|
|
19
|
+
*/
|
|
20
|
+
function splitLegacyVisibility(visibilities) {
|
|
21
|
+
const legacyVisibilities = [];
|
|
22
|
+
const modifiers = [];
|
|
23
|
+
for (const visibility of visibilities) {
|
|
24
|
+
if (typeof visibility === "string") {
|
|
25
|
+
legacyVisibilities.push(visibility);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
modifiers.push(visibility.value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return [modifiers, legacyVisibilities];
|
|
32
|
+
}
|
|
33
|
+
export const $withDefaultKeyVisibility = (context, entity, visibility) => {
|
|
34
|
+
const keyProperties = [];
|
|
35
|
+
entity.properties.forEach((prop) => {
|
|
36
|
+
// Keep track of any key property without a visibility
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
38
|
+
if (isKey(context.program, prop) && !getVisibility(context.program, prop)) {
|
|
39
|
+
keyProperties.push(prop);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
// For each key property without a visibility, clone it and add the specified
|
|
43
|
+
// default visibility value
|
|
44
|
+
keyProperties.forEach((keyProp) => {
|
|
45
|
+
entity.properties.set(keyProp.name, context.program.checker.cloneType(keyProp, {
|
|
46
|
+
decorators: [
|
|
47
|
+
...keyProp.decorators,
|
|
48
|
+
{
|
|
49
|
+
decorator: $visibility,
|
|
50
|
+
args: [
|
|
51
|
+
{
|
|
52
|
+
value: typeof visibility === "string"
|
|
53
|
+
? context.program.checker.createLiteralType(visibility)
|
|
54
|
+
: visibility,
|
|
55
|
+
jsValue: visibility,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
}));
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const [getOperationVisibilityConfigRaw, setOperationVisibilityConfigRaw] = useStateMap("operationVisibilityConfig");
|
|
64
|
+
function getOperationVisibilityConfig(program, operation) {
|
|
65
|
+
let config = getOperationVisibilityConfigRaw(program, operation);
|
|
66
|
+
if (!config) {
|
|
67
|
+
config = {};
|
|
68
|
+
setOperationVisibilityConfigRaw(program, operation, config);
|
|
69
|
+
}
|
|
70
|
+
return config;
|
|
71
|
+
}
|
|
72
|
+
export const $parameterVisibility = (context, operation, ...visibilities) => {
|
|
73
|
+
validateDecoratorUniqueOnNode(context, operation, $parameterVisibility);
|
|
74
|
+
const [modifiers, legacyVisibilities] = splitLegacyVisibility(visibilities);
|
|
75
|
+
if (modifiers.length > 0 && legacyVisibilities.length > 0) {
|
|
76
|
+
reportDiagnostic(context.program, {
|
|
77
|
+
code: "visibility-mixed-legacy",
|
|
78
|
+
target: context.decoratorTarget,
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (modifiers.length > 0) {
|
|
83
|
+
getOperationVisibilityConfig(context.program, operation).parameters = modifiers;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
getOperationVisibilityConfig(context.program, operation).parameters = legacyVisibilities;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Returns the visibilities of the parameters of the given operation, if provided with `@parameterVisibility`.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link $parameterVisibility}
|
|
93
|
+
*/
|
|
94
|
+
export function getParameterVisibility(program, entity) {
|
|
95
|
+
return getOperationVisibilityConfig(program, entity)
|
|
96
|
+
.parameters?.map((p) => typeof p === "string" ? p : normalizeVisibilityToLegacyLifecycleString(program, p))
|
|
97
|
+
.filter((p) => !!p);
|
|
98
|
+
}
|
|
99
|
+
export const $returnTypeVisibility = (context, operation, ...visibilities) => {
|
|
100
|
+
validateDecoratorUniqueOnNode(context, operation, $parameterVisibility);
|
|
101
|
+
const [modifiers, legacyVisibilities] = splitLegacyVisibility(visibilities);
|
|
102
|
+
if (modifiers.length > 0 && legacyVisibilities.length > 0) {
|
|
103
|
+
reportDiagnostic(context.program, {
|
|
104
|
+
code: "visibility-mixed-legacy",
|
|
105
|
+
target: context.decoratorTarget,
|
|
106
|
+
});
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (modifiers.length > 0) {
|
|
110
|
+
getOperationVisibilityConfig(context.program, operation).returnType = modifiers;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
getOperationVisibilityConfig(context.program, operation).returnType = legacyVisibilities;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Returns the visibilities of the return type of the given operation, if provided with `@returnTypeVisibility`.
|
|
118
|
+
*
|
|
119
|
+
* @see {@link $returnTypeVisibility}
|
|
120
|
+
*/
|
|
121
|
+
export function getReturnTypeVisibility(program, entity) {
|
|
122
|
+
return getOperationVisibilityConfig(program, entity)
|
|
123
|
+
.returnType?.map((p) => typeof p === "string" ? p : normalizeVisibilityToLegacyLifecycleString(program, p))
|
|
124
|
+
.filter((p) => !!p);
|
|
125
|
+
}
|
|
126
|
+
// #endregion
|
|
127
|
+
// #region Core Visibility Decorators
|
|
128
|
+
// -- @visibility decorator ---------------------
|
|
129
|
+
export const $visibility = (context, target, ...visibilities) => {
|
|
130
|
+
const [modifiers, legacyVisibilities] = splitLegacyVisibility(visibilities);
|
|
131
|
+
if (legacyVisibilities.length > 0 || visibilities.length === 0) {
|
|
132
|
+
const isUnique = validateDecoratorUniqueOnNode(context, target, $visibility);
|
|
133
|
+
if (modifiers.length > 0) {
|
|
134
|
+
reportDiagnostic(context.program, {
|
|
135
|
+
code: "visibility-mixed-legacy",
|
|
136
|
+
target: context.decoratorTarget,
|
|
137
|
+
});
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Only attempt to set the legacy visibility modifiers if the visibility invocation is unique. Otherwise, a compiler
|
|
141
|
+
// assertion will fail inside the legacy visibility management API.
|
|
142
|
+
if (isUnique)
|
|
143
|
+
setLegacyVisibility(context, target, legacyVisibilities);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
if (getLegacyVisibility(context.program, target)) {
|
|
147
|
+
reportDiagnostic(context.program, {
|
|
148
|
+
code: "visibility-mixed-legacy",
|
|
149
|
+
target: context.decoratorTarget,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
addVisibilityModifiers(context.program, target, modifiers, context);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
// -- @removeVisibility decorator ---------------------
|
|
156
|
+
export const $removeVisibility = (context, target, ...visibilities) => {
|
|
157
|
+
removeVisibilityModifiers(context.program, target, visibilities.map((v) => v.value));
|
|
158
|
+
};
|
|
159
|
+
// -- @invisible decorator ---------------------
|
|
160
|
+
export const $invisible = (context, target, visibilityClass) => {
|
|
161
|
+
clearVisibilityModifiersForClass(context.program, target, visibilityClass);
|
|
162
|
+
};
|
|
163
|
+
// -- @defaultVisibility decorator ------------------
|
|
164
|
+
export const $defaultVisibility = (context, target, ...visibilities) => {
|
|
165
|
+
validateDecoratorUniqueOnNode(context, target, $defaultVisibility);
|
|
166
|
+
const modifierSet = new Set();
|
|
167
|
+
for (const visibility of visibilities) {
|
|
168
|
+
if (visibility.value.enum !== target) {
|
|
169
|
+
reportDiagnostic(context.program, {
|
|
170
|
+
code: "default-visibility-not-member",
|
|
171
|
+
target: context.decoratorTarget,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
modifierSet.add(visibility.value);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
setDefaultModifierSetForVisibilityClass(context.program, target, modifierSet);
|
|
179
|
+
};
|
|
180
|
+
// #endregion
|
|
181
|
+
// #region Legacy Visibility Transforms
|
|
182
|
+
// -- @withVisibility decorator ---------------------
|
|
183
|
+
export const $withVisibility = (context, target, ...visibilities) => {
|
|
184
|
+
const [modifiers, legacyVisibilities] = splitLegacyVisibility(visibilities);
|
|
185
|
+
if (legacyVisibilities.length > 0) {
|
|
186
|
+
if (modifiers.length > 0) {
|
|
187
|
+
reportDiagnostic(context.program, {
|
|
188
|
+
code: "visibility-mixed-legacy",
|
|
189
|
+
target: context.decoratorTarget,
|
|
190
|
+
});
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
194
|
+
filterModelPropertiesInPlace(target, (p) => isVisible(context.program, p, legacyVisibilities));
|
|
195
|
+
for (const p of target.properties.values()) {
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
197
|
+
const legacyModifiers = getVisibility(context.program, p);
|
|
198
|
+
if (legacyModifiers && legacyModifiers.length > 0) {
|
|
199
|
+
clearLegacyVisibility(context.program, p);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
resetVisibilityModifiersForClass(context.program, p, getLifecycleVisibilityEnum(context.program));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
const filter = {
|
|
208
|
+
all: new Set(modifiers),
|
|
209
|
+
};
|
|
210
|
+
const visibilityClasses = new Set(modifiers.map((m) => m.enum));
|
|
211
|
+
filterModelPropertiesInPlace(target, (p) => isVisible(context.program, p, filter));
|
|
212
|
+
for (const p of target.properties.values()) {
|
|
213
|
+
for (const c of visibilityClasses) {
|
|
214
|
+
resetVisibilityModifiersForClass(context.program, p, c);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
// -- @withUpdateableProperties decorator ----------------------
|
|
220
|
+
/**
|
|
221
|
+
* Filters a model for properties that are updateable.
|
|
222
|
+
*
|
|
223
|
+
* @param context - the program context
|
|
224
|
+
* @param target - Model to filter for updateable properties
|
|
225
|
+
*/
|
|
226
|
+
export const $withUpdateableProperties = (context, target) => {
|
|
227
|
+
if (!validateDecoratorTarget(context, target, "@withUpdateableProperties", "Model")) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
231
|
+
filterModelPropertiesInPlace(target, (p) => isVisible(context.program, p, ["update"]));
|
|
232
|
+
};
|
|
233
|
+
// #endregion
|
|
234
|
+
// #region Mutator Driven Transforms
|
|
235
|
+
// -- @withVisibilityFilter decorator ----------------------
|
|
236
|
+
export const $withVisibilityFilter = (context, target, _filter) => {
|
|
237
|
+
const filter = VisibilityFilter.fromDecoratorArgument(_filter);
|
|
238
|
+
const vfMutator = createVisibilityFilterMutator(filter, {
|
|
239
|
+
decoratorFn: $withVisibilityFilter,
|
|
240
|
+
});
|
|
241
|
+
const { type } = mutateSubgraph(context.program, [vfMutator], target);
|
|
242
|
+
target.properties = type.properties;
|
|
243
|
+
};
|
|
244
|
+
// -- @withLifecycleUpdate decorator ----------------------
|
|
245
|
+
export const $withLifecycleUpdate = (context, target) => {
|
|
246
|
+
const lifecycle = getLifecycleVisibilityEnum(context.program);
|
|
247
|
+
const lifecycleUpdate = {
|
|
248
|
+
all: new Set([lifecycle.members.get("Update")]),
|
|
249
|
+
};
|
|
250
|
+
const lifecycleCreateOrUpdate = {
|
|
251
|
+
any: new Set([lifecycle.members.get("Create"), lifecycle.members.get("Update")]),
|
|
252
|
+
};
|
|
253
|
+
const createOrUpdateMutator = createVisibilityFilterMutator(lifecycleCreateOrUpdate);
|
|
254
|
+
const updateMutator = createVisibilityFilterMutator(lifecycleUpdate, {
|
|
255
|
+
recur: createOrUpdateMutator,
|
|
256
|
+
decoratorFn: $withLifecycleUpdate,
|
|
257
|
+
});
|
|
258
|
+
const { type } = mutateSubgraph(context.program, [updateMutator], target);
|
|
259
|
+
target.properties = type.properties;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Create a mutator that applies a visibility filter to a type.
|
|
263
|
+
*
|
|
264
|
+
* @param filter - The visibility filter to apply
|
|
265
|
+
* @param options - optional settings for the mutator
|
|
266
|
+
* @returns
|
|
267
|
+
*/
|
|
268
|
+
function createVisibilityFilterMutator(filter, options = {}) {
|
|
269
|
+
const visibilityClasses = VisibilityFilter.getVisibilityClasses(filter);
|
|
270
|
+
const mpMutator = {
|
|
271
|
+
name: "VisibilityFilterProperty",
|
|
272
|
+
ModelProperty: {
|
|
273
|
+
filter: () => MutatorFlow.DoNotRecurse,
|
|
274
|
+
mutate: (prop, clone, program) => {
|
|
275
|
+
// We need to create a copy of the decorators array to avoid modifying the original.
|
|
276
|
+
// Decorators are _NOT_ cloned by the type kit, so we have to be careful not to modify the decorator arguments
|
|
277
|
+
// of the original type.
|
|
278
|
+
const decorators = [];
|
|
279
|
+
for (const decorator of prop.decorators) {
|
|
280
|
+
const decFn = decorator.decorator;
|
|
281
|
+
if (decFn === $visibility || decFn === $removeVisibility) {
|
|
282
|
+
const nextArgs = decorator.args.filter((arg) => {
|
|
283
|
+
if (arg.value.entityKind !== "Value")
|
|
284
|
+
return false;
|
|
285
|
+
const isString = arg.value.valueKind === "StringValue";
|
|
286
|
+
const isOperativeVisibility = arg.value.valueKind === "EnumValue" && visibilityClasses.has(arg.value.value.enum);
|
|
287
|
+
return !(isString || isOperativeVisibility);
|
|
288
|
+
});
|
|
289
|
+
if (nextArgs.length > 0) {
|
|
290
|
+
decorators.push({
|
|
291
|
+
...decorator,
|
|
292
|
+
args: nextArgs,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else if (decFn !== $invisible) {
|
|
297
|
+
decorators.push(decorator);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
clone.decorators = decorators;
|
|
301
|
+
for (const visibilityClass of visibilityClasses) {
|
|
302
|
+
resetVisibilityModifiersForClass(program, clone, visibilityClass);
|
|
303
|
+
}
|
|
304
|
+
if (isMutableType(prop.type)) {
|
|
305
|
+
clone.type = mutateSubgraph(program, [options.recur ?? self], prop.type).type;
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
const self = {
|
|
311
|
+
name: "VisibilityFilter",
|
|
312
|
+
Union: {
|
|
313
|
+
filter: () => MutatorFlow.DoNotRecurse,
|
|
314
|
+
mutate: (union, clone, program) => {
|
|
315
|
+
for (const [key, member] of union.variants) {
|
|
316
|
+
if (member.type.kind === "Model" || member.type.kind === "Union") {
|
|
317
|
+
const variant = {
|
|
318
|
+
...member,
|
|
319
|
+
type: mutateSubgraph(program, [self], member.type).type,
|
|
320
|
+
};
|
|
321
|
+
clone.variants.set(key, variant);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
Model: {
|
|
327
|
+
filter: () => MutatorFlow.DoNotRecurse,
|
|
328
|
+
mutate: (model, clone, program, realm) => {
|
|
329
|
+
for (const [key, prop] of model.properties) {
|
|
330
|
+
if (!isVisible(program, prop, filter)) {
|
|
331
|
+
// Property is not visible, remove it
|
|
332
|
+
clone.properties.delete(key);
|
|
333
|
+
realm.remove(clone);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
const mutated = mutateSubgraph(program, [mpMutator], prop);
|
|
337
|
+
clone.properties.set(key, mutated.type);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (options.decoratorFn) {
|
|
341
|
+
clone.decorators = clone.decorators.filter((d) => d.decorator !== options.decoratorFn);
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
ModelProperty: {
|
|
346
|
+
filter: () => MutatorFlow.DoNotRecurse,
|
|
347
|
+
mutate: (prop, clone, program) => {
|
|
348
|
+
if (isMutableType(prop.type)) {
|
|
349
|
+
clone.type = mutateSubgraph(program, [self], prop.type).type;
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
Tuple: {
|
|
354
|
+
filter: () => MutatorFlow.DoNotRecurse,
|
|
355
|
+
mutate: (tuple, clone, program) => {
|
|
356
|
+
for (const [index, element] of tuple.values.entries()) {
|
|
357
|
+
if (isMutableType(element)) {
|
|
358
|
+
clone.values[index] = mutateSubgraph(program, [self], element).type;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
return self;
|
|
365
|
+
}
|
|
366
|
+
// #endregion
|
|
367
|
+
//# sourceMappingURL=visibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.js","sourceRoot":"","sources":["../../../src/lib/visibility.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAelC,OAAO,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAevD,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,gCAAgC,EAEhC,mBAAmB,EACnB,aAAa,EACb,SAAS,EACT,yBAAyB,EACzB,gCAAgC,EAChC,uCAAuC,EACvC,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,0BAA0B,EAC1B,0CAA0C,GAC3C,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAW,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,4BAA4B,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEvE,sCAAsC;AAEtC;;;;;;;;GAQG;AACH,SAAS,qBAAqB,CAAC,YAAoC;IACjE,MAAM,kBAAkB,GAAG,EAAc,CAAC;IAC1C,MAAM,SAAS,GAAG,EAAkB,CAAC;IAErC,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;QACtC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACtC,CAAC;aA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CAAC;wBAC3B,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;oBACtE,CAAC;gBACH,CAAC;YACH,CAAC;SACF;KACF,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AAED,aAAa"}
|
package/lib/std/decorators.tsp
CHANGED
|
@@ -60,7 +60,7 @@ extern dec errorsDoc(target: Operation, doc: valueof string);
|
|
|
60
60
|
*
|
|
61
61
|
* NOTE: This decorator **should not** be used, use the `#deprecated` directive instead.
|
|
62
62
|
*
|
|
63
|
-
* @deprecated Use the `#deprecated` directive instead.
|
|
63
|
+
* @deprecated Use the `#deprecated` [directive](https://typespec.io/docs/language-basics/directives/#deprecated) instead.
|
|
64
64
|
* @param message Deprecation message.
|
|
65
65
|
*
|
|
66
66
|
* @example
|
|
@@ -572,93 +572,6 @@ extern dec opExample(
|
|
|
572
572
|
example: valueof OperationExample,
|
|
573
573
|
options?: valueof ExampleOptions
|
|
574
574
|
);
|
|
575
|
-
/**
|
|
576
|
-
* Indicates that a property is only considered to be present or applicable ("visible") with
|
|
577
|
-
* the in the given named contexts ("visibilities"). When a property has no visibilities applied
|
|
578
|
-
* to it, it is implicitly visible always.
|
|
579
|
-
*
|
|
580
|
-
* As far as the TypeSpec core library is concerned, visibilities are open-ended and can be arbitrary
|
|
581
|
-
* strings, but the following visibilities are well-known to standard libraries and should be used
|
|
582
|
-
* with standard emitters that interpret them as follows:
|
|
583
|
-
*
|
|
584
|
-
* - "read": output of any operation.
|
|
585
|
-
* - "create": input to operations that create an entity..
|
|
586
|
-
* - "query": input to operations that read data.
|
|
587
|
-
* - "update": input to operations that update data.
|
|
588
|
-
* - "delete": input to operations that delete data.
|
|
589
|
-
*
|
|
590
|
-
* See also: [Automatic visibility](https://typespec.io/docs/libraries/http/operations#automatic-visibility)
|
|
591
|
-
*
|
|
592
|
-
* @param visibilities List of visibilities which apply to this property.
|
|
593
|
-
*
|
|
594
|
-
* @example
|
|
595
|
-
*
|
|
596
|
-
* ```typespec
|
|
597
|
-
* model Dog {
|
|
598
|
-
* // the service will generate an ID, so you don't need to send it.
|
|
599
|
-
* @visibility("read") id: int32;
|
|
600
|
-
* // the service will store this secret name, but won't ever return it
|
|
601
|
-
* @visibility("create", "update") secretName: string;
|
|
602
|
-
* // the regular name is always present
|
|
603
|
-
* name: string;
|
|
604
|
-
* }
|
|
605
|
-
* ```
|
|
606
|
-
*/
|
|
607
|
-
extern dec visibility(target: ModelProperty, ...visibilities: valueof string[]);
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* Removes properties that are not considered to be present or applicable
|
|
611
|
-
* ("visible") in the given named contexts ("visibilities"). Can be used
|
|
612
|
-
* together with spread to effectively spread only visible properties into
|
|
613
|
-
* a new model.
|
|
614
|
-
*
|
|
615
|
-
* See also: [Automatic visibility](https://typespec.io/docs/libraries/http/operations#automatic-visibility)
|
|
616
|
-
*
|
|
617
|
-
* When using an emitter that applies visibility automatically, it is generally
|
|
618
|
-
* not necessary to use this decorator.
|
|
619
|
-
*
|
|
620
|
-
* @param visibilities List of visibilities which apply to this property.
|
|
621
|
-
*
|
|
622
|
-
* @example
|
|
623
|
-
* ```typespec
|
|
624
|
-
* model Dog {
|
|
625
|
-
* @visibility("read") id: int32;
|
|
626
|
-
* @visibility("create", "update") secretName: string;
|
|
627
|
-
* name: string;
|
|
628
|
-
* }
|
|
629
|
-
*
|
|
630
|
-
* // The spread operator will copy all the properties of Dog into DogRead,
|
|
631
|
-
* // and @withVisibility will then remove those that are not visible with
|
|
632
|
-
* // create or update visibility.
|
|
633
|
-
* //
|
|
634
|
-
* // In this case, the id property is removed, and the name and secretName
|
|
635
|
-
* // properties are kept.
|
|
636
|
-
* @withVisibility("create", "update")
|
|
637
|
-
* model DogCreateOrUpdate {
|
|
638
|
-
* ...Dog;
|
|
639
|
-
* }
|
|
640
|
-
*
|
|
641
|
-
* // In this case the id and name properties are kept and the secretName property
|
|
642
|
-
* // is removed.
|
|
643
|
-
* @withVisibility("read")
|
|
644
|
-
* model DogRead {
|
|
645
|
-
* ...Dog;
|
|
646
|
-
* }
|
|
647
|
-
* ```
|
|
648
|
-
*/
|
|
649
|
-
extern dec withVisibility(target: Model, ...visibilities: valueof string[]);
|
|
650
|
-
|
|
651
|
-
/**
|
|
652
|
-
* Set the visibility of key properties in a model if not already set.
|
|
653
|
-
*
|
|
654
|
-
* @param visibility The desired default visibility value. If a key property already has a `visibility` decorator then the default visibility is not applied.
|
|
655
|
-
*/
|
|
656
|
-
extern dec withDefaultKeyVisibility(target: Model, visibility: valueof string);
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* Returns the model with non-updateable properties removed.
|
|
660
|
-
*/
|
|
661
|
-
extern dec withUpdateableProperties(target: Model);
|
|
662
575
|
|
|
663
576
|
/**
|
|
664
577
|
* Returns the model with required properties removed.
|
|
@@ -848,15 +761,3 @@ extern dec inspectType(target: unknown, text: valueof string);
|
|
|
848
761
|
* @param text Custom text to log
|
|
849
762
|
*/
|
|
850
763
|
extern dec inspectTypeName(target: unknown, text: valueof string);
|
|
851
|
-
|
|
852
|
-
/**
|
|
853
|
-
* Sets which visibilities apply to parameters for the given operation.
|
|
854
|
-
* @param visibilities List of visibility strings which apply to this operation.
|
|
855
|
-
*/
|
|
856
|
-
extern dec parameterVisibility(target: Operation, ...visibilities: valueof string[]);
|
|
857
|
-
|
|
858
|
-
/**
|
|
859
|
-
* Sets which visibilities apply to the return type for the given operation.
|
|
860
|
-
* @param visibilities List of visibility strings which apply to this operation.
|
|
861
|
-
*/
|
|
862
|
-
extern dec returnTypeVisibility(target: Operation, ...visibilities: valueof string[]);
|
package/lib/std/main.tsp
CHANGED