@typespec/compiler 0.61.0-dev.6 → 0.61.0-dev.8

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.
Files changed (67) hide show
  1. package/dist/manifest.js +2 -2
  2. package/dist/src/core/numeric.js +1 -1
  3. package/dist/src/core/numeric.js.map +1 -1
  4. package/dist/src/core/program.d.ts.map +1 -1
  5. package/dist/src/core/program.js +2 -0
  6. package/dist/src/core/program.js.map +1 -1
  7. package/dist/src/experimental/index.d.ts +3 -0
  8. package/dist/src/experimental/index.d.ts.map +1 -1
  9. package/dist/src/experimental/index.js +3 -0
  10. package/dist/src/experimental/index.js.map +1 -1
  11. package/dist/src/experimental/mutators.d.ts +57 -0
  12. package/dist/src/experimental/mutators.d.ts.map +1 -0
  13. package/dist/src/experimental/mutators.js +173 -0
  14. package/dist/src/experimental/mutators.js.map +1 -0
  15. package/dist/src/experimental/realm.d.ts +34 -0
  16. package/dist/src/experimental/realm.d.ts.map +1 -0
  17. package/dist/src/experimental/realm.js +128 -0
  18. package/dist/src/experimental/realm.js.map +1 -0
  19. package/dist/src/experimental/typekit/define-kit.d.ts +28 -0
  20. package/dist/src/experimental/typekit/define-kit.d.ts.map +1 -0
  21. package/dist/src/experimental/typekit/define-kit.js +45 -0
  22. package/dist/src/experimental/typekit/define-kit.js.map +1 -0
  23. package/dist/src/experimental/typekit/index.d.ts +3 -0
  24. package/dist/src/experimental/typekit/index.d.ts.map +1 -0
  25. package/dist/src/experimental/typekit/index.js +3 -0
  26. package/dist/src/experimental/typekit/index.js.map +1 -0
  27. package/dist/src/experimental/typekit/kits/index.d.ts +9 -0
  28. package/dist/src/experimental/typekit/kits/index.d.ts.map +1 -0
  29. package/dist/src/experimental/typekit/kits/index.js +9 -0
  30. package/dist/src/experimental/typekit/kits/index.js.map +1 -0
  31. package/dist/src/experimental/typekit/kits/literal.d.ts +59 -0
  32. package/dist/src/experimental/typekit/kits/literal.d.ts.map +1 -0
  33. package/dist/src/experimental/typekit/kits/literal.js +51 -0
  34. package/dist/src/experimental/typekit/kits/literal.js.map +1 -0
  35. package/dist/src/experimental/typekit/kits/model-property.d.ts +45 -0
  36. package/dist/src/experimental/typekit/kits/model-property.d.ts.map +1 -0
  37. package/dist/src/experimental/typekit/kits/model-property.js +19 -0
  38. package/dist/src/experimental/typekit/kits/model-property.js.map +1 -0
  39. package/dist/src/experimental/typekit/kits/model.d.ts +48 -0
  40. package/dist/src/experimental/typekit/kits/model.d.ts.map +1 -0
  41. package/dist/src/experimental/typekit/kits/model.js +26 -0
  42. package/dist/src/experimental/typekit/kits/model.js.map +1 -0
  43. package/dist/src/experimental/typekit/kits/realm.d.ts +24 -0
  44. package/dist/src/experimental/typekit/kits/realm.d.ts.map +1 -0
  45. package/dist/src/experimental/typekit/kits/realm.js +17 -0
  46. package/dist/src/experimental/typekit/kits/realm.js.map +1 -0
  47. package/dist/src/experimental/typekit/kits/scalar.d.ts +354 -0
  48. package/dist/src/experimental/typekit/kits/scalar.d.ts.map +1 -0
  49. package/dist/src/experimental/typekit/kits/scalar.js +91 -0
  50. package/dist/src/experimental/typekit/kits/scalar.js.map +1 -0
  51. package/dist/src/experimental/typekit/kits/type.d.ts +25 -0
  52. package/dist/src/experimental/typekit/kits/type.d.ts.map +1 -0
  53. package/dist/src/experimental/typekit/kits/type.js +55 -0
  54. package/dist/src/experimental/typekit/kits/type.js.map +1 -0
  55. package/dist/src/experimental/typekit/kits/union-variant.d.ts +43 -0
  56. package/dist/src/experimental/typekit/kits/union-variant.d.ts.map +1 -0
  57. package/dist/src/experimental/typekit/kits/union-variant.js +22 -0
  58. package/dist/src/experimental/typekit/kits/union-variant.js.map +1 -0
  59. package/dist/src/experimental/typekit/kits/union.d.ts +56 -0
  60. package/dist/src/experimental/typekit/kits/union.d.ts.map +1 -0
  61. package/dist/src/experimental/typekit/kits/union.js +69 -0
  62. package/dist/src/experimental/typekit/kits/union.js.map +1 -0
  63. package/dist/src/experimental/typekit/utils.d.ts +8 -0
  64. package/dist/src/experimental/typekit/utils.d.ts.map +1 -0
  65. package/dist/src/experimental/typekit/utils.js +28 -0
  66. package/dist/src/experimental/typekit/utils.js.map +1 -0
  67. package/package.json +1 -1
@@ -0,0 +1,56 @@
1
+ import type { Type, Union, UnionVariant } from "../../../core/types.js";
2
+ import { DecoratorArgs } from "../utils.js";
3
+ interface UnionDescriptor {
4
+ /**
5
+ * The name of the union. If name is provided, it is a union declaration.
6
+ * Otherwise, it is a union expression.
7
+ */
8
+ name?: string;
9
+ /**
10
+ * Decorators to apply to the union.
11
+ */
12
+ decorators?: DecoratorArgs[];
13
+ /**
14
+ * The variants of the union. If a variant is a string, number, or boolean, it
15
+ * will be converted to a union variant with the same name and type.
16
+ */
17
+ variants?: Record<string | symbol, string | number> | UnionVariant[];
18
+ }
19
+ export interface UnionKit {
20
+ union: {
21
+ /**
22
+ * Create a union type.
23
+ *
24
+ * @param desc The descriptor of the union.
25
+ */
26
+ create(desc: UnionDescriptor): Union;
27
+ /**
28
+ * Check if the given `type` is a union.
29
+ *
30
+ * @param type The type to check.
31
+ */
32
+ is(type: Type): type is Union;
33
+ /**
34
+ * Check if the union is a valid enum. Specifically, this checks if the
35
+ * union has a name (since there are no enum expressions), and whether each
36
+ * of the variant types is a valid enum member value.
37
+ *
38
+ * @param type The union to check.
39
+ */
40
+ isValidEnum(type: Union): boolean;
41
+ /**
42
+ * Check if a union is extensible. Extensible unions are unions which contain a variant
43
+ * that is a supertype of all the other types. This means that the subtypes of the common
44
+ * supertype are known example values, but others may be present.
45
+ * @param type The union to check.
46
+ */
47
+ isExtensible(type: Union): boolean;
48
+ };
49
+ }
50
+ declare module "../define-kit.js" {
51
+ interface TypekitPrototype extends UnionKit {
52
+ }
53
+ }
54
+ export declare const UnionKit: void;
55
+ export {};
56
+ //# sourceMappingURL=union.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/union.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGxE,OAAO,EAAwB,aAAa,EAAE,MAAM,aAAa,CAAC;AAElE,UAAU,eAAe;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,YAAY,EAAE,CAAC;CACtE;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE;QACL;;;;WAIG;QACH,MAAM,CAAC,IAAI,EAAE,eAAe,GAAG,KAAK,CAAC;QAErC;;;;WAIG;QACH,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,KAAK,CAAC;QAE9B;;;;;;WAMG;QACH,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;QAElC;;;;;WAKG;QACH,YAAY,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;KACpC,CAAC;CACH;AAED,OAAO,QAAQ,kBAAkB,CAAC;IAChC,UAAU,gBAAiB,SAAQ,QAAQ;KAAG;CAC/C;AAED,eAAO,MAAM,QAAQ,MA8EnB,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { ignoreDiagnostics } from "../../../core/diagnostics.js";
2
+ import { createRekeyableMap } from "../../../utils/misc.js";
3
+ import { defineKit } from "../define-kit.js";
4
+ import { decoratorApplication } from "../utils.js";
5
+ export const UnionKit = defineKit({
6
+ union: {
7
+ create(desc) {
8
+ const union = this.program.checker.createType({
9
+ kind: "Union",
10
+ name: desc.name,
11
+ decorators: decoratorApplication(desc.decorators),
12
+ variants: createRekeyableMap(),
13
+ get options() {
14
+ return Array.from(this.variants.values()).map((v) => v.type);
15
+ },
16
+ expression: desc.name === undefined,
17
+ node: undefined,
18
+ });
19
+ if (Array.isArray(desc.variants)) {
20
+ for (const variant of desc.variants) {
21
+ union.variants.set(variant.name, variant);
22
+ variant.union = union;
23
+ }
24
+ }
25
+ else if (desc.variants) {
26
+ for (const [name, value] of Object.entries(desc.variants)) {
27
+ union.variants.set(name, this.unionVariant.create({ name, type: this.literal.create(value) }));
28
+ }
29
+ }
30
+ this.program.checker.finishType(union);
31
+ return union;
32
+ },
33
+ is(type) {
34
+ return type.kind === "Union";
35
+ },
36
+ isValidEnum(type) {
37
+ for (const variant of type.variants.values()) {
38
+ if (!this.literal.isString(variant.type) && !this.literal.isNumeric(variant.type)) {
39
+ return false;
40
+ }
41
+ }
42
+ return true;
43
+ },
44
+ isExtensible(type) {
45
+ const variants = Array.from(type.variants.values());
46
+ if (variants.length === 0) {
47
+ return false;
48
+ }
49
+ for (let i = 0; i < variants.length; i++) {
50
+ let isCommon = true;
51
+ for (let j = 0; j < variants.length; j++) {
52
+ if (i === j) {
53
+ continue;
54
+ }
55
+ const assignable = ignoreDiagnostics(this.program.checker.isTypeAssignableTo(variants[j].type, variants[i].type, type));
56
+ if (!assignable) {
57
+ isCommon = false;
58
+ break;
59
+ }
60
+ }
61
+ if (isCommon) {
62
+ return true;
63
+ }
64
+ }
65
+ return false;
66
+ },
67
+ },
68
+ });
69
+ //# sourceMappingURL=union.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union.js","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/union.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAiB,MAAM,aAAa,CAAC;AA4DlE,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAW;IAC1C,KAAK,EAAE;QACL,MAAM,CAAC,I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CAAC,UAAU,EAAE,CAAC;wBAChB,QAAQ,GAAG,KAAK,CAAC;wBACjB,MAAM;oBACR,CAAC;gBACH,CAAC;gBAED,IAAI,QAAQ,EAAE,CAAC;oBACb,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;KACF;CACF,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { DecoratorApplication, DecoratorFunction, RekeyableMap } from "../../core/types.js";
2
+ /** @experimental */
3
+ export declare function copyMap<T, U>(map: RekeyableMap<T, U>): RekeyableMap<T, U>;
4
+ /** @experimental */
5
+ export type DecoratorArgs = DecoratorFunction | [DecoratorFunction, ...any[]];
6
+ /** @experimental */
7
+ export declare function decoratorApplication(args?: DecoratorArgs[]): DecoratorApplication[];
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/experimental/typekit/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIjG,oBAAoB;AACpB,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAEzE;AAED,oBAAoB;AACpB,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,CAAC,iBAAiB,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC;AAE9E,oBAAoB;AACpB,wBAAgB,oBAAoB,CAAC,IAAI,CAAC,EAAE,aAAa,EAAE,GAAG,oBAAoB,EAAE,CAsBnF"}
@@ -0,0 +1,28 @@
1
+ import { createRekeyableMap } from "../../utils/misc.js";
2
+ import { $ } from "./define-kit.js";
3
+ /** @experimental */
4
+ export function copyMap(map) {
5
+ return createRekeyableMap(Array.from(map.entries()));
6
+ }
7
+ /** @experimental */
8
+ export function decoratorApplication(args) {
9
+ if (!args) {
10
+ return [];
11
+ }
12
+ const decorators = [];
13
+ for (const arg of args) {
14
+ decorators.push({
15
+ decorator: Array.isArray(arg) ? arg[0] : arg,
16
+ args: Array.isArray(arg)
17
+ ? arg.slice(1).map((rawValue) => ({
18
+ value: typeof rawValue === "object" && rawValue !== null
19
+ ? rawValue
20
+ : $.literal.create(rawValue),
21
+ jsValue: rawValue,
22
+ }))
23
+ : [],
24
+ });
25
+ }
26
+ return decorators;
27
+ }
28
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/experimental/typekit/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAC;AAEpC,oBAAoB;AACpB,MAAM,UAAU,OAAO,CAAO,GAAuB;IACnD,OAAO,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AACvD,CAAC;AAKD,oBAAoB;AACpB,MAAM,UAAU,oBAAoB,CAAC,IAAsB;IACzD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,UAAU,GAA2B,EAAE,CAAC;IAC9C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,UAAU,CAAC,IAAI,CAAC;YACd,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;YAC5C,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;gBACtB,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,QAAa,EAAE,EAAE,CAAC,CAAC;oBACnC,KAAK,EACH,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI;wBAC/C,CAAC,CAAC,QAAQ;wBACV,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;oBAChC,OAAO,EAAE,QAAQ;iBAClB,CAAC,CAAC;gBACL,CAAC,CAAC,EAAE;SACP,CAAC,CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/compiler",
3
- "version": "0.61.0-dev.6",
3
+ "version": "0.61.0-dev.8",
4
4
  "description": "TypeSpec Compiler Preview",
5
5
  "author": "Microsoft Corporation",
6
6
  "license": "MIT",