@azure-tools/typespec-azure-core 0.62.0-dev.3 → 0.62.0-dev.5
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/src/decorators/unique-items.d.ts.map +1 -1
- package/dist/src/decorators/unique-items.js +16 -2
- package/dist/src/decorators/unique-items.js.map +1 -1
- package/dist/src/decorators.d.ts +2 -2
- package/dist/src/decorators.d.ts.map +1 -1
- package/dist/src/decorators.js +1 -1
- package/dist/src/decorators.js.map +1 -1
- package/lib/experimental/lib.tsp +48 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unique-items.d.ts","sourceRoot":"","sources":["../../../src/decorators/unique-items.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"unique-items.d.ts","sourceRoot":"","sources":["../../../src/decorators/unique-items.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,IAAI,EACL,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAG/E,eAAO,MAAM,YAAY,EAAE,oBA0B1B,CAAC;AAEF,eAAO,MAAO,cAAc,sFAAE,cAAc,qFAE3C,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isArrayModelType } from "@typespec/compiler";
|
|
1
|
+
import { isArrayModelType, isNullType, } from "@typespec/compiler";
|
|
2
2
|
import { useStateMap } from "@typespec/compiler/utils";
|
|
3
3
|
import { AzureCoreStateKeys, reportDiagnostic } from "../lib.js";
|
|
4
4
|
export const $uniqueItems = (context, entity) => {
|
|
5
5
|
const { program } = context;
|
|
6
6
|
if (entity.kind === "ModelProperty") {
|
|
7
|
-
if (entity.type.kind
|
|
7
|
+
if (!isTypeOrNullableType(entity.type, (t) => t.kind === "Model" && isArrayModelType(program, t))) {
|
|
8
8
|
reportDiagnostic(program, {
|
|
9
9
|
code: "unique-items-invalid-type",
|
|
10
10
|
target: entity,
|
|
@@ -24,4 +24,18 @@ export const $uniqueItems = (context, entity) => {
|
|
|
24
24
|
setUniqueItems(program, entity, true);
|
|
25
25
|
};
|
|
26
26
|
export const [getUniqueItems, setUniqueItems] = useStateMap(AzureCoreStateKeys.uniqueItems);
|
|
27
|
+
function isTypeOrNullableType(type, filter) {
|
|
28
|
+
if (filter(type)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (type.kind !== "Union") {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (type.variants.size !== 2)
|
|
35
|
+
return false;
|
|
36
|
+
const variants = [...type.variants.values()];
|
|
37
|
+
if (!filter(variants[0].type))
|
|
38
|
+
return false;
|
|
39
|
+
return isNullType(variants[1].type);
|
|
40
|
+
}
|
|
27
41
|
//# sourceMappingURL=unique-items.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unique-items.js","sourceRoot":"","sources":["../../../src/decorators/unique-items.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"unique-items.js","sourceRoot":"","sources":["../../../src/decorators/unique-items.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,UAAU,GAIX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,CAAC,MAAM,YAAY,GAAyB,CAChD,OAAyB,EACzB,MAA6B,EAC7B,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,IAAI,MAAM,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QACpC,IACE,CAAC,oBAAoB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,IAAI,gBAAgB,CAAC,OA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,4 @@
|
|
|
1
|
-
import { DecoratorContext, Model, ModelProperty, Program } from "@typespec/compiler";
|
|
1
|
+
import { DecoratorContext, Model, ModelProperty, Program, Type } from "@typespec/compiler";
|
|
2
2
|
export declare const $requestParameter: (context: DecoratorContext, entity: Model, name: string) => void;
|
|
3
3
|
export declare function getRequestParameter(program: Program, entity: ModelProperty): string | undefined;
|
|
4
4
|
export declare const $responseProperty: (context: DecoratorContext, entity: Model, name: string) => void;
|
|
@@ -9,5 +9,5 @@ export declare function getResponseProperty(program: Program, entity: ModelPrope
|
|
|
9
9
|
* @param type The model or model property to check.
|
|
10
10
|
* @returns True if the model or model property has unique items, false otherwise.
|
|
11
11
|
*/
|
|
12
|
-
export declare function hasUniqueItems(program: Program, type:
|
|
12
|
+
export declare function hasUniqueItems(program: Program, type: Type): boolean;
|
|
13
13
|
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG3F,eAAO,MAAM,iBAAiB,GAAI,SAAS,gBAAgB,EAAE,QAAQ,KAAK,EAAE,MAAM,MAAM,SAEvF,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS,CAM/F;AAED,eAAO,MAAM,iBAAiB,GAAI,SAAS,gBAAgB,EAAE,QAAQ,KAAK,EAAE,MAAM,MAAM,SAEvF,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS,CAM/F;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CA4BpE"}
|
package/dist/src/decorators.js
CHANGED
|
@@ -47,7 +47,7 @@ export function hasUniqueItems(program, type) {
|
|
|
47
47
|
type.sourceModels.some((sourceModel) => hasUniqueItemsCached(sourceModel.model))));
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
if (type.
|
|
50
|
+
if (type.kind !== "ModelProperty") {
|
|
51
51
|
return cacheResult(type, false);
|
|
52
52
|
}
|
|
53
53
|
return cacheResult(type, getUniqueItems(program, type) || hasUniqueItemsCached(type.type));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAyB,EAAE,MAAa,EAAE,IAAY,EAAE,EAAE;IAC1F,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAClF,CAAC,CAAC;AAEF,MAAM,UAAU,mBAAmB,CAAC,OAAgB,EAAE,MAAqB;IACzE,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,SAAS,CAAC;IACnD,MAAM,aAAa,GAAuB,OAAO;SAC9C,QAAQ,CAAC,kBAAkB,CAAC,gBAAgB,CAAC;SAC7C,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,M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AAS,CAAC,CAAC;gBACtE,CAAC,IAAI,CAAC,WAAW,KAAK,SAAS,IAAI,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBAC1E,CAAC,IAAI,CAAC,YAAY,KAAK,SAAS;oBAC9B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,oBAAoB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CACtF,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;gBAClC,OAAO,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;YACD,OAAO,WAAW,CAAC,IAAI,EAAE,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7F,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import "../../dist/src/experimental/tsp-index.js";
|
|
5
|
+
|
|
6
|
+
namespace Azure.Core.Experimental;
|
|
7
|
+
|
|
8
|
+
using Reflection;
|
|
9
|
+
|
|
10
|
+
// #region Mutative Decorators
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Changes the type of a model property to a new type.
|
|
14
|
+
*
|
|
15
|
+
* This can be used in situations where an existing model property type needs to be changed because it cannot be redefined.
|
|
16
|
+
*
|
|
17
|
+
* WARNING: This decorator mutates the model property in place and should be used with EXTREME caution.
|
|
18
|
+
*
|
|
19
|
+
* @param target The model property to change.
|
|
20
|
+
* @param newType The new type to assign to the model property.
|
|
21
|
+
*/
|
|
22
|
+
extern dec changePropertyType(target: ModelProperty, newType: Model | Union | Scalar | Enum);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Copies the properties of `source` that do not already exist on `target` into `target`.
|
|
26
|
+
*
|
|
27
|
+
* This can be used to add a group of properties to an existing model in cases where the model cannot be redefined.
|
|
28
|
+
*
|
|
29
|
+
* WARNING: This decorator mutates the target model in place and should be used with EXTREME caution.
|
|
30
|
+
*
|
|
31
|
+
* @param target The model to copy properties to.
|
|
32
|
+
* @param sourceModel The model to copy properties from.
|
|
33
|
+
*/
|
|
34
|
+
extern dec copyProperties(target: Model, sourceModel: Model);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Copies the variants of `sourceUnion` that do not already exist on `target` into `target`.
|
|
38
|
+
*
|
|
39
|
+
* This can be used to add a group of variants to an existing union in cases where the union cannot be redefined.
|
|
40
|
+
*
|
|
41
|
+
* WARNING: This decorator mutates the target union in place and should be used with EXTREME caution.
|
|
42
|
+
*
|
|
43
|
+
* @param target The union to copy variants to.
|
|
44
|
+
* @param sourceUnion The union to copy variants from.
|
|
45
|
+
*/
|
|
46
|
+
extern dec copyVariants(target: Union, sourceUnion: Union);
|
|
47
|
+
|
|
48
|
+
// #endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-azure-core",
|
|
3
|
-
"version": "0.62.0-dev.
|
|
3
|
+
"version": "0.62.0-dev.5",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec Azure Core library",
|
|
6
6
|
"homepage": "https://azure.github.io/typespec-azure",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"node": ">=20.0.0"
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
|
-
"lib
|
|
45
|
+
"lib/**/*.tsp",
|
|
46
46
|
"dist/**",
|
|
47
47
|
"!dist/test/**"
|
|
48
48
|
],
|