@typespec/compiler 0.63.0-dev.6 → 0.63.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.
Files changed (62) hide show
  1. package/dist/manifest.js +2 -2
  2. package/dist/src/core/program.js +1 -1
  3. package/dist/src/core/program.js.map +1 -1
  4. package/dist/src/experimental/mutators.d.ts +184 -47
  5. package/dist/src/experimental/mutators.d.ts.map +1 -1
  6. package/dist/src/experimental/mutators.js +69 -11
  7. package/dist/src/experimental/mutators.js.map +1 -1
  8. package/dist/src/experimental/realm.d.ts +70 -3
  9. package/dist/src/experimental/realm.d.ts.map +1 -1
  10. package/dist/src/experimental/realm.js +84 -14
  11. package/dist/src/experimental/realm.js.map +1 -1
  12. package/dist/src/experimental/typekit/define-kit.d.ts +17 -17
  13. package/dist/src/experimental/typekit/define-kit.d.ts.map +1 -1
  14. package/dist/src/experimental/typekit/define-kit.js +15 -38
  15. package/dist/src/experimental/typekit/define-kit.js.map +1 -1
  16. package/dist/src/experimental/typekit/index.d.ts +79 -0
  17. package/dist/src/experimental/typekit/index.d.ts.map +1 -1
  18. package/dist/src/experimental/typekit/index.js +127 -0
  19. package/dist/src/experimental/typekit/index.js.map +1 -1
  20. package/dist/src/experimental/typekit/kits/index.d.ts +0 -1
  21. package/dist/src/experimental/typekit/kits/index.d.ts.map +1 -1
  22. package/dist/src/experimental/typekit/kits/index.js +0 -1
  23. package/dist/src/experimental/typekit/kits/index.js.map +1 -1
  24. package/dist/src/experimental/typekit/kits/literal.d.ts +2 -1
  25. package/dist/src/experimental/typekit/kits/literal.d.ts.map +1 -1
  26. package/dist/src/experimental/typekit/kits/literal.js.map +1 -1
  27. package/dist/src/experimental/typekit/kits/model-property.d.ts +2 -1
  28. package/dist/src/experimental/typekit/kits/model-property.d.ts.map +1 -1
  29. package/dist/src/experimental/typekit/kits/model-property.js.map +1 -1
  30. package/dist/src/experimental/typekit/kits/model.d.ts +2 -1
  31. package/dist/src/experimental/typekit/kits/model.d.ts.map +1 -1
  32. package/dist/src/experimental/typekit/kits/model.js +1 -1
  33. package/dist/src/experimental/typekit/kits/model.js.map +1 -1
  34. package/dist/src/experimental/typekit/kits/scalar.d.ts +2 -1
  35. package/dist/src/experimental/typekit/kits/scalar.d.ts.map +1 -1
  36. package/dist/src/experimental/typekit/kits/scalar.js.map +1 -1
  37. package/dist/src/experimental/typekit/kits/type.d.ts +1 -1
  38. package/dist/src/experimental/typekit/kits/type.d.ts.map +1 -1
  39. package/dist/src/experimental/typekit/kits/type.js +19 -13
  40. package/dist/src/experimental/typekit/kits/type.js.map +1 -1
  41. package/dist/src/experimental/typekit/kits/union-variant.d.ts +1 -1
  42. package/dist/src/experimental/typekit/kits/union-variant.d.ts.map +1 -1
  43. package/dist/src/experimental/typekit/kits/union-variant.js +1 -1
  44. package/dist/src/experimental/typekit/kits/union-variant.js.map +1 -1
  45. package/dist/src/experimental/typekit/kits/union.d.ts +1 -1
  46. package/dist/src/experimental/typekit/kits/union.d.ts.map +1 -1
  47. package/dist/src/experimental/typekit/kits/union.js +1 -1
  48. package/dist/src/experimental/typekit/kits/union.js.map +1 -1
  49. package/dist/src/experimental/typekit/utils.d.ts +28 -4
  50. package/dist/src/experimental/typekit/utils.d.ts.map +1 -1
  51. package/dist/src/experimental/typekit/utils.js +34 -23
  52. package/dist/src/experimental/typekit/utils.js.map +1 -1
  53. package/dist/src/lib/visibility.js +5 -5
  54. package/dist/src/lib/visibility.js.map +1 -1
  55. package/dist/src/utils/misc.d.ts +1 -1
  56. package/dist/src/utils/misc.d.ts.map +1 -1
  57. package/dist/src/utils/misc.js.map +1 -1
  58. package/package.json +1 -1
  59. package/dist/src/experimental/typekit/kits/realm.d.ts +0 -24
  60. package/dist/src/experimental/typekit/kits/realm.d.ts.map +0 -1
  61. package/dist/src/experimental/typekit/kits/realm.js +0 -17
  62. package/dist/src/experimental/typekit/kits/realm.js.map +0 -1
@@ -1,5 +1,14 @@
1
1
  import { Program } from "../core/program.js";
2
2
  import { Type } from "../core/types.js";
3
+ import { Typekit } from "./typekit/index.js";
4
+ /**
5
+ * A Realm's view of a Program's state map for a given state key.
6
+ *
7
+ * For all operations, if a type was created within the realm, the realm's own state map is used. Otherwise, the owning'
8
+ * Program's state map is used.
9
+ *
10
+ * @experimental
11
+ */
3
12
  declare class StateMapRealmView<V> implements Map<Type, V> {
4
13
  #private;
5
14
  constructor(realm: Realm, realmState: Map<Type, V>, parentState: Map<Type, V>);
@@ -15,20 +24,78 @@ declare class StateMapRealmView<V> implements Map<Type, V> {
15
24
  keys(): IterableIterator<Type>;
16
25
  [Symbol.iterator](): IterableIterator<[Type, V]>;
17
26
  [Symbol.toStringTag]: string;
18
- dispatch(keyType: Type): Map<Type, V>;
19
27
  }
20
- /** @experimental */
28
+ /**
29
+ * A Realm is an alternate view of a Program where types can be cloned, deleted, and modified without affecting the
30
+ * original types in the Program.
31
+ *
32
+ * The realm stores the types that exist within the realm, views of state maps that only apply within the realm,
33
+ * and a view of types that have been removed from the realm's view.
34
+ *
35
+ * @experimental
36
+ */
21
37
  export declare class Realm {
22
38
  #private;
23
39
  key: symbol;
40
+ /**
41
+ * Create a new realm in the given program.
42
+ *
43
+ * @param program - The program to create the realm in.
44
+ * @param description - A short description of the realm's purpose.
45
+ */
24
46
  constructor(program: Program, description: string);
47
+ /**
48
+ * The typekit instance bound to this realm.
49
+ *
50
+ * If the realm does not already have a typekit associated with it, one will be created and bound to this realm.
51
+ */
52
+ get typekit(): Typekit;
53
+ /**
54
+ * The program that this realm is associated with.
55
+ */
56
+ get program(): Program;
57
+ /**
58
+ * Gets a state map for the given state key symbol.
59
+ *
60
+ * This state map is a view of the program's state map for the given state key, with modifications made to the realm's
61
+ * own state.
62
+ *
63
+ * @param stateKey - The symbol to use as the state key.
64
+ * @returns The realm's state map for the given state key.
65
+ */
25
66
  stateMap(stateKey: symbol): StateMapRealmView<any>;
67
+ /**
68
+ * Clones a type and adds it to the realm. This operation will use the realm's typekit to clone the type.
69
+ *
70
+ * @param type - The type to clone.
71
+ * @returns A clone of the input type that exists within this realm.
72
+ */
26
73
  clone<T extends Type>(type: T): T;
74
+ /**
75
+ * Removes a type from this realm. This operation will not affect the type in the program, only this realm's view
76
+ * of the type.
77
+ *
78
+ * @param type - The TypeSpec type to remove from this realm.
79
+ */
27
80
  remove(type: Type): void;
81
+ /**
82
+ * Determines whether or not this realm contains a given type.
83
+ *
84
+ * @param type - The type to check.
85
+ * @returns true if the type was created within this realm or added to this realm, false otherwise.
86
+ */
28
87
  hasType(type: Type): boolean;
88
+ /**
89
+ * Adds a type to this realm. Once a type is added to the realm, the realm considers it part of itself.
90
+ *
91
+ * A type can be present in multiple realms, but `Realm.realmForType` will only return the last realm that the type
92
+ * was added to.
93
+ *
94
+ * @param type - The type to add to this realm.
95
+ */
29
96
  addType(type: Type): void;
30
97
  static realmForKey(key: symbol, parentRealm?: Realm): Realm | undefined;
31
- static realmForType: Map<Type, Realm>;
98
+ static realmForType: WeakMap<Type, Realm>;
32
99
  }
33
100
  export {};
34
101
  //# sourceMappingURL=realm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"realm.d.ts","sourceRoot":"","sources":["../../../src/experimental/realm.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,cAAM,iBAAiB,CAAC,CAAC,CAAE,YAAW,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;;gBAK7B,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAMpF,GAAG,CAAC,CAAC,EAAE,IAAI;IAIX,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG;IAKnB,GAAG,CAAC,CAAC,EAAE,IAAI;IAIX,MAAM,CAAC,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AK,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC;IASjC;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAIxB;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAI5B;;;;;;;OAOG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAczB,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,KAAK;IAInD,MAAM,CAAC,YAAY,uBAA8B;CAClD"}
@@ -1,6 +1,14 @@
1
1
  var _a;
2
2
  import { compilerAssert } from "../core/diagnostics.js";
3
- import { $ } from "./typekit/define-kit.js";
3
+ import { createTypekit } from "./typekit/index.js";
4
+ /**
5
+ * A Realm's view of a Program's state map for a given state key.
6
+ *
7
+ * For all operations, if a type was created within the realm, the realm's own state map is used. Otherwise, the owning'
8
+ * Program's state map is used.
9
+ *
10
+ * @experimental
11
+ */
4
12
  class StateMapRealmView {
5
13
  #realm;
6
14
  #parentState;
@@ -11,17 +19,17 @@ class StateMapRealmView {
11
19
  this.#realmState = realmState;
12
20
  }
13
21
  has(t) {
14
- return this.dispatch(t).has(t) ?? false;
22
+ return this.#select(t).has(t) ?? false;
15
23
  }
16
24
  set(t, v) {
17
- this.dispatch(t).set(t, v);
25
+ this.#select(t).set(t, v);
18
26
  return this;
19
27
  }
20
28
  get(t) {
21
- return this.dispatch(t).get(t);
29
+ return this.#select(t).get(t);
22
30
  }
23
31
  delete(t) {
24
- return this.dispatch(t).delete(t);
32
+ return this.#select(t).delete(t);
25
33
  }
26
34
  forEach(cb, thisArg) {
27
35
  for (const item of this.entries()) {
@@ -30,8 +38,7 @@ class StateMapRealmView {
30
38
  return this;
31
39
  }
32
40
  get size() {
33
- // extremely non-optimal, maybe worth not offering it?
34
- return [...this.entries()].length;
41
+ return this.#realmState.size + this.#parentState.size;
35
42
  }
36
43
  clear() {
37
44
  this.#realmState.clear();
@@ -61,17 +68,24 @@ class StateMapRealmView {
61
68
  return this.entries();
62
69
  }
63
70
  [Symbol.toStringTag] = "StateMap";
64
- dispatch(keyType) {
71
+ #select(keyType) {
65
72
  if (this.#realm.hasType(keyType)) {
66
73
  return this.#realmState;
67
74
  }
68
75
  return this.#parentState;
69
76
  }
70
77
  }
71
- /** @experimental */
78
+ /**
79
+ * A Realm is an alternate view of a Program where types can be cloned, deleted, and modified without affecting the
80
+ * original types in the Program.
81
+ *
82
+ * The realm stores the types that exist within the realm, views of state maps that only apply within the realm,
83
+ * and a view of types that have been removed from the realm's view.
84
+ *
85
+ * @experimental
86
+ */
72
87
  export class Realm {
73
88
  #program;
74
- // Type registry
75
89
  /**
76
90
  * Stores all types owned by this realm.
77
91
  */
@@ -80,14 +94,44 @@ export class Realm {
80
94
  * Stores types that are deleted in this realm. When a realm is active and doing a traversal, you will
81
95
  * not find this type in e.g. collections. Deleted types are mapped to `null` if you ask for it.
82
96
  */
83
- #deletedTypes = new Set();
97
+ #deletedTypes = new WeakSet();
84
98
  #stateMaps = new Map();
85
99
  key;
100
+ /**
101
+ * Create a new realm in the given program.
102
+ *
103
+ * @param program - The program to create the realm in.
104
+ * @param description - A short description of the realm's purpose.
105
+ */
86
106
  constructor(program, description) {
87
107
  this.key = Symbol(description);
88
108
  this.#program = program;
89
109
  _a.#knownRealms.set(this.key, this);
90
110
  }
111
+ #_typekit;
112
+ /**
113
+ * The typekit instance bound to this realm.
114
+ *
115
+ * If the realm does not already have a typekit associated with it, one will be created and bound to this realm.
116
+ */
117
+ get typekit() {
118
+ return (this.#_typekit ??= createTypekit(this));
119
+ }
120
+ /**
121
+ * The program that this realm is associated with.
122
+ */
123
+ get program() {
124
+ return this.#program;
125
+ }
126
+ /**
127
+ * Gets a state map for the given state key symbol.
128
+ *
129
+ * This state map is a view of the program's state map for the given state key, with modifications made to the realm's
130
+ * own state.
131
+ *
132
+ * @param stateKey - The symbol to use as the state key.
133
+ * @returns The realm's state map for the given state key.
134
+ */
91
135
  stateMap(stateKey) {
92
136
  let m = this.#stateMaps.get(stateKey);
93
137
  if (!m) {
@@ -96,24 +140,50 @@ export class Realm {
96
140
  }
97
141
  return new StateMapRealmView(this, m, this.#program.stateMap(stateKey));
98
142
  }
143
+ /**
144
+ * Clones a type and adds it to the realm. This operation will use the realm's typekit to clone the type.
145
+ *
146
+ * @param type - The type to clone.
147
+ * @returns A clone of the input type that exists within this realm.
148
+ */
99
149
  clone(type) {
100
150
  compilerAssert(type, "Undefined type passed to clone");
101
151
  const clone = this.#cloneIntoRealm(type);
102
- $.type.finishType(clone);
152
+ this.typekit.type.finishType(clone);
103
153
  return clone;
104
154
  }
155
+ /**
156
+ * Removes a type from this realm. This operation will not affect the type in the program, only this realm's view
157
+ * of the type.
158
+ *
159
+ * @param type - The TypeSpec type to remove from this realm.
160
+ */
105
161
  remove(type) {
106
162
  this.#deletedTypes.add(type);
107
163
  }
164
+ /**
165
+ * Determines whether or not this realm contains a given type.
166
+ *
167
+ * @param type - The type to check.
168
+ * @returns true if the type was created within this realm or added to this realm, false otherwise.
169
+ */
108
170
  hasType(type) {
109
171
  return this.#types.has(type);
110
172
  }
173
+ /**
174
+ * Adds a type to this realm. Once a type is added to the realm, the realm considers it part of itself.
175
+ *
176
+ * A type can be present in multiple realms, but `Realm.realmForType` will only return the last realm that the type
177
+ * was added to.
178
+ *
179
+ * @param type - The type to add to this realm.
180
+ */
111
181
  addType(type) {
112
182
  this.#types.add(type);
113
183
  _a.realmForType.set(type, this);
114
184
  }
115
185
  #cloneIntoRealm(type) {
116
- const clone = $.type.clone(type);
186
+ const clone = this.typekit.type.clone(type);
117
187
  this.#types.add(clone);
118
188
  _a.realmForType.set(clone, this);
119
189
  return clone;
@@ -122,7 +192,7 @@ export class Realm {
122
192
  static realmForKey(key, parentRealm) {
123
193
  return this.#knownRealms.get(key);
124
194
  }
125
- static realmForType = new Map();
195
+ static realmForType = new WeakMap();
126
196
  }
127
197
  _a = Realm;
128
198
  //# sourceMappingURL=realm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"realm.js","sourceRoot":"","sources":["../../../src/experimental/realm.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD,OAAO,EAAE,CAAC,EAAE,MAAM,yBAAyB,CAAC;AAE5C,MAAM,iBAAiB;IACrB,MAAM,CAAQ;IACd,YAAY,CAAe;IAC3B,WAAW,CAAe;IAE1B,YAAmB,KAAY,EAAE,UAAwB,EAAE,WAAyB;QAClF,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,GAAG,CAAC,CAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;IAC1C,CAAC;IAED,GAAG,CAAC,CAAO,EAAE,CAAM;QACjB,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG,CAAC,CAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,CAAO;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,CAAC,EAAoD,EAAE,OAAa;QACzE,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YAClC,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CA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C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACvB,EAAK,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,YAAY,GAAG,IAAI,GAAG,EAAiB,CAAC;IAE/C,MAAM,CAAC,WAAW,CAAC,GAAW,EAAE,WAAmB;QACjD,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,YAAY,GAAG,IAAI,OAAO,EAAe,CAAC"}
@@ -1,17 +1,13 @@
1
1
  import { type Program } from "../../core/program.js";
2
- /** @experimental */
3
- export declare function setCurrentProgram(program: Program): void;
4
- /** @experimental */
5
- export interface TypekitPrototype {
6
- program: Program;
7
- }
8
- /** @experimental */
9
- export declare const TypekitPrototype: Record<string, unknown>;
10
- /** @experimental */
11
- export declare function createTypekit(): TypekitPrototype;
12
- /** @experimental */
13
- export interface TypekitContext {
14
- program: Program;
2
+ import { Realm } from "../realm.js";
3
+ /**
4
+ * A Typekit is a collection of utility functions and namespaces that allow you to work with TypeSpec types.
5
+ *
6
+ * @experimental
7
+ */
8
+ export interface Typekit {
9
+ readonly program: Program;
10
+ readonly realm: Realm;
15
11
  }
16
12
  /**
17
13
  * contextual typing to type guards is annoying (often have to restate the signature),
@@ -21,8 +17,12 @@ export interface TypekitContext {
21
17
  export type StripGuards<T> = {
22
18
  [K in keyof T]: T[K] extends (...args: infer P) => infer R ? (...args: P) => R : StripGuards<T[K]>;
23
19
  };
24
- /** @experimental */
25
- export declare function defineKit<T extends Record<string, any>>(source: StripGuards<T> & ThisType<TypekitPrototype>): void;
26
- /** @experimental */
27
- export declare const $: TypekitPrototype;
20
+ /**
21
+ * Defines an extension to the Typekit interface.
22
+ *
23
+ * All Typekit instances will inherit the functionality defined by calls to this function.
24
+ *
25
+ * @experimental
26
+ */
27
+ export declare function defineKit<T extends Record<string, any>>(source: StripGuards<T> & ThisType<Typekit>): void;
28
28
  //# sourceMappingURL=define-kit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"define-kit.d.ts","sourceRoot":"","sources":["../../../../src/experimental/typekit/define-kit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAIrD,oBAAoB;AACpB,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAExD;AAED,oBAAoB;AACpB,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,oBAAoB;AACpB,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,CAAC;AAE5D,oBAAoB;AACpB,wBAAgB,aAAa,IAAI,gBAAgB,CAkChD;AAED,oBAAoB;AACpB,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,GACtD,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GACjB,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACtB,CAAC;AAEF,oBAAoB;AACpB,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrD,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,gBAAgB,CAAC,GAClD,IAAI,CAIN;AAED,oBAAoB;AACpB,eAAO,MAAM,CAAC,EAAE,gBAAkC,CAAC"}
1
+ {"version":3,"file":"define-kit.d.ts","sourceRoot":"","sources":["../../../../src/experimental/typekit/define-kit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAYD;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,GACtD,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GACjB,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrD,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,GACzC,IAAI,CAIN"}
@@ -1,45 +1,22 @@
1
- const CURRENT_PROGRAM = Symbol.for("TypeSpec.currentProgram");
2
- /** @experimental */
3
- export function setCurrentProgram(program) {
4
- globalThis[CURRENT_PROGRAM] = program;
5
- }
6
- /** @experimental */
1
+ /**
2
+ * The prototype object for Typekit instances.
3
+ *
4
+ * @see {@link defineKit}
5
+ *
6
+ * @experimental
7
+ * @internal
8
+ */
7
9
  export const TypekitPrototype = {};
8
- /** @experimental */
9
- export function createTypekit() {
10
- const tk = Object.create(TypekitPrototype);
11
- Object.defineProperty(tk, "program", {
12
- get() {
13
- return globalThis[CURRENT_PROGRAM];
14
- },
15
- });
16
- const handler = {
17
- get(target, prop, receiver) {
18
- const value = Reflect.get(target, prop, receiver);
19
- if (prop === "program") {
20
- // don't wrap program (probably need to ensure this isn't a nested program somewhere)
21
- return value;
22
- }
23
- if (typeof value === "function") {
24
- return function (...args) {
25
- return value.apply(proxy, args);
26
- };
27
- }
28
- if (typeof value === "object" && value !== null) {
29
- return new Proxy(value, handler);
30
- }
31
- return value;
32
- },
33
- };
34
- const proxy = new Proxy(tk, handler);
35
- return proxy;
36
- }
37
- /** @experimental */
10
+ /**
11
+ * Defines an extension to the Typekit interface.
12
+ *
13
+ * All Typekit instances will inherit the functionality defined by calls to this function.
14
+ *
15
+ * @experimental
16
+ */
38
17
  export function defineKit(source) {
39
18
  for (const [name, fnOrNs] of Object.entries(source)) {
40
19
  TypekitPrototype[name] = fnOrNs;
41
20
  }
42
21
  }
43
- /** @experimental */
44
- export const $ = createTypekit();
45
22
  //# sourceMappingURL=define-kit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"define-kit.js","sourceRoot":"","sources":["../../../../src/experimental/typekit/define-kit.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAE9D,oBAAoB;AACpB,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAC/C,UAAkB,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC;AACjD,CAAC;AAOD,oBAAoB;AACpB,MAAM,CAAC,MAAM,gBAAgB,GAA4B,EAAE,CAAC;AAE5D,oBAAoB;AACpB,MAAM,UAAU,aAAa;IAC3B,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAE3C,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE;QACnC,GAAG;YACD,OAAQ,UAAkB,CAAC,eAAe,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC,CAAC;IAEH,MAAM,OAAO,GAAmC;QAC9C,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,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CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;IAClC,CAAC;AACH,CAAC"}
@@ -1,3 +1,82 @@
1
+ import { Program } from "../../core/index.js";
2
+ import { Realm } from "../realm.js";
3
+ import { Typekit } from "./define-kit.js";
1
4
  export * from "./define-kit.js";
2
5
  export * from "./kits/index.js";
6
+ /**
7
+ * Create a new Typekit that operates in the given realm.
8
+ *
9
+ * Ordinarily, you should use the default typekit `$` to manipulate types in the current program, or call `$` with a
10
+ * Realm or Program as the first argument if you want to work in a specific realm or in the default typekit realm of
11
+ * a specific program.
12
+ *
13
+ * @param realm - The realm to create the typekit in.
14
+ *
15
+ * @experimental
16
+ */
17
+ export declare function createTypekit(realm: Realm): Typekit;
18
+ /** @experimental */
19
+ interface DefaultTypekit extends Typekit {
20
+ /**
21
+ * Create or get the default typekit for the given Realm.
22
+ *
23
+ * @see {@link Realm}
24
+ *
25
+ * @param realm - The realm to get the typekit for.
26
+ * @returns The default typekit for the realm.
27
+ */
28
+ (realm: Realm): Typekit;
29
+ /**
30
+ * Create or get the default typekit for the given Program.
31
+ *
32
+ * If a default typekit realm for the given program does not exist, one will be created.
33
+ *
34
+ * @param program - The program to get the typekit for.
35
+ * @returns The default typekit for the program.
36
+ */
37
+ (program: Program): Typekit;
38
+ }
39
+ /**
40
+ * Typekit - Utilities for working with TypeSpec types.
41
+ *
42
+ * The default typekit `$` can be used to manipulate types in the current program.
43
+ *
44
+ * Each typekit is associated with a Realm in which it operates. The default typekit
45
+ * will use the default typekit realm for the current program.
46
+ *
47
+ * Alternatively, to work in a specific realm, you can get the typekit associated
48
+ * with that realm by calling `$` with the realm as an argument, or by calling
49
+ * `$` with a program as an argument (in this case, it will use that program's
50
+ * default typekit realm or create one if it does not already exist).
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { $ } from "@typespec/compiler/experimental";
55
+ *
56
+ * const clone = $.type.clone(inputType);
57
+ * ```
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import { $, Realm } from "@typespec/compiler/experimental";
62
+ *
63
+ * const realm = new Realm(program, "my custom realm");
64
+ *
65
+ * const clone = $(realm).type.clone(inputType);
66
+ * ```
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import { $ } from "@typespec/compiler/experimental";
71
+ *
72
+ * const projectedProgram = projectProgram(program, ...);
73
+ *
74
+ * const clone = $(projectedProgram).type.clone(inputType);
75
+ * ```
76
+ *
77
+ * @see {@link Realm}
78
+ *
79
+ * @experimental
80
+ */
81
+ export declare const $: DefaultTypekit;
3
82
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/experimental/typekit/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/experimental/typekit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,OAAO,EAAoB,MAAM,iBAAiB,CAAC;AAE5D,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAEhC;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAgCnD;AA6BD,oBAAoB;AACpB,UAAU,cAAe,SAAQ,OAAO;IACtC;;;;;;;OAOG;IACH,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;IAExB;;;;;;;OAOG;IACH,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;CAC7B;AAoBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,CAAC,EAAE,cAsBe,CAAC"}
@@ -1,3 +1,130 @@
1
+ import { compilerAssert } from "../../core/index.js";
2
+ import { Realm } from "../realm.js";
3
+ import { TypekitPrototype } from "./define-kit.js";
1
4
  export * from "./define-kit.js";
2
5
  export * from "./kits/index.js";
6
+ /**
7
+ * Create a new Typekit that operates in the given realm.
8
+ *
9
+ * Ordinarily, you should use the default typekit `$` to manipulate types in the current program, or call `$` with a
10
+ * Realm or Program as the first argument if you want to work in a specific realm or in the default typekit realm of
11
+ * a specific program.
12
+ *
13
+ * @param realm - The realm to create the typekit in.
14
+ *
15
+ * @experimental
16
+ */
17
+ export function createTypekit(realm) {
18
+ const tk = Object.create(TypekitPrototype);
19
+ const handler = {
20
+ get(target, prop, receiver) {
21
+ if (prop === "program") {
22
+ // don't wrap program (probably need to ensure this isn't a nested program somewhere)
23
+ return realm.program;
24
+ }
25
+ if (prop === "realm") {
26
+ return realm;
27
+ }
28
+ const value = Reflect.get(target, prop, receiver);
29
+ if (typeof value === "function") {
30
+ return function (...args) {
31
+ return value.apply(proxy, args);
32
+ };
33
+ }
34
+ if (typeof value === "object" && value !== null) {
35
+ return new Proxy(value, handler);
36
+ }
37
+ return value;
38
+ },
39
+ };
40
+ const proxy = new Proxy(tk, handler);
41
+ return proxy;
42
+ }
43
+ // #region Default Typekit
44
+ const CURRENT_PROGRAM = Symbol.for("TypeSpec.Typekit.CURRENT_PROGRAM");
45
+ const DEFAULT_REALM = Symbol.for("TypeSpec.Typekit.DEFAULT_TYPEKIT_REALM");
46
+ function getCurrentProgram() {
47
+ return globalThis[CURRENT_PROGRAM];
48
+ }
49
+ /**
50
+ * Sets a given program as the current program for Typekit operations.
51
+ *
52
+ * This is necessary to enable use of the default Typekit `$` and should be
53
+ * called whenever the compiler is working with a specific program
54
+ *
55
+ * @param program - The program to set as the current program.
56
+ *
57
+ * @internal
58
+ */
59
+ export function setCurrentProgram(program) {
60
+ globalThis[CURRENT_PROGRAM] = program;
61
+ }
62
+ function _$(arg) {
63
+ let realm;
64
+ if (Object.hasOwn(arg, "projectRoot")) {
65
+ // arg is a Program
66
+ realm = arg[DEFAULT_REALM] ??= new Realm(arg, "default typekit realm");
67
+ }
68
+ else {
69
+ // arg is a Realm
70
+ realm = arg;
71
+ }
72
+ return realm.typekit;
73
+ }
74
+ /**
75
+ * Typekit - Utilities for working with TypeSpec types.
76
+ *
77
+ * The default typekit `$` can be used to manipulate types in the current program.
78
+ *
79
+ * Each typekit is associated with a Realm in which it operates. The default typekit
80
+ * will use the default typekit realm for the current program.
81
+ *
82
+ * Alternatively, to work in a specific realm, you can get the typekit associated
83
+ * with that realm by calling `$` with the realm as an argument, or by calling
84
+ * `$` with a program as an argument (in this case, it will use that program's
85
+ * default typekit realm or create one if it does not already exist).
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * import { $ } from "@typespec/compiler/experimental";
90
+ *
91
+ * const clone = $.type.clone(inputType);
92
+ * ```
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import { $, Realm } from "@typespec/compiler/experimental";
97
+ *
98
+ * const realm = new Realm(program, "my custom realm");
99
+ *
100
+ * const clone = $(realm).type.clone(inputType);
101
+ * ```
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { $ } from "@typespec/compiler/experimental";
106
+ *
107
+ * const projectedProgram = projectProgram(program, ...);
108
+ *
109
+ * const clone = $(projectedProgram).type.clone(inputType);
110
+ * ```
111
+ *
112
+ * @see {@link Realm}
113
+ *
114
+ * @experimental
115
+ */
116
+ export const $ = new Proxy(_$, {
117
+ get(_target, prop, _receiver) {
118
+ const currentProgram = getCurrentProgram();
119
+ compilerAssert(currentProgram !== undefined, "Default typekits may not be used until a program is set in the compiler.");
120
+ if (prop === "program")
121
+ return currentProgram;
122
+ const realm = (currentProgram[DEFAULT_REALM] ??= new Realm(currentProgram, "default typekit realm"));
123
+ if (prop === "realm")
124
+ return realm;
125
+ const tk = _$(realm);
126
+ return Reflect.get(tk, prop, tk);
127
+ },
128
+ });
129
+ // #endregion
3
130
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/experimental/typekit/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/experimental/typekit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAW,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAW,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAEhC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,KAAY;IACxC,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAE3C,MAAM,OAAO,GAA0B;QACrC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,qFAAqF;gBACrF,OAAO,KAAK,CAAC,OAAO,CAAC;YACvB,CAAC;YAED,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;gBACrB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAElD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;gBAChC,OAAO,UAAqB,GAAG,IAAW;oBACxC,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBAClC,CAAC,CAAC;YACJ,CAAC;YAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBAChD,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACnC,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;IAEF,MAAM,KAAK,GAAG,IAAI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d,uBAAuB,CACxB,CAAC,CAAC;QAEH,IAAI,IAAI,KAAK,OAAO;YAAE,OAAO,KAAK,CAAC;QAEnC,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QAErB,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC;CACF,CAA8B,CAAC;AAEhC,aAAa"}
@@ -1,7 +1,6 @@
1
1
  export * from "./literal.js";
2
2
  export * from "./model-property.js";
3
3
  export * from "./model.js";
4
- export * from "./realm.js";
5
4
  export * from "./scalar.js";
6
5
  export * from "./type.js";
7
6
  export * from "./union-variant.js";