@typespec/compiler 0.63.0-dev.6 → 0.63.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.
- package/dist/manifest.js +2 -2
- package/dist/src/core/messages.d.ts +20 -2
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +6 -0
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/program.js +1 -1
- package/dist/src/core/program.js.map +1 -1
- package/dist/src/experimental/mutators.d.ts +184 -47
- package/dist/src/experimental/mutators.d.ts.map +1 -1
- package/dist/src/experimental/mutators.js +69 -11
- package/dist/src/experimental/mutators.js.map +1 -1
- package/dist/src/experimental/realm.d.ts +70 -3
- package/dist/src/experimental/realm.d.ts.map +1 -1
- package/dist/src/experimental/realm.js +84 -14
- package/dist/src/experimental/realm.js.map +1 -1
- package/dist/src/experimental/typekit/define-kit.d.ts +17 -17
- package/dist/src/experimental/typekit/define-kit.d.ts.map +1 -1
- package/dist/src/experimental/typekit/define-kit.js +15 -38
- package/dist/src/experimental/typekit/define-kit.js.map +1 -1
- package/dist/src/experimental/typekit/index.d.ts +79 -0
- package/dist/src/experimental/typekit/index.d.ts.map +1 -1
- package/dist/src/experimental/typekit/index.js +127 -0
- package/dist/src/experimental/typekit/index.js.map +1 -1
- package/dist/src/experimental/typekit/kits/index.d.ts +0 -1
- package/dist/src/experimental/typekit/kits/index.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/index.js +0 -1
- package/dist/src/experimental/typekit/kits/index.js.map +1 -1
- package/dist/src/experimental/typekit/kits/literal.d.ts +2 -1
- package/dist/src/experimental/typekit/kits/literal.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/literal.js.map +1 -1
- package/dist/src/experimental/typekit/kits/model-property.d.ts +2 -1
- package/dist/src/experimental/typekit/kits/model-property.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/model-property.js.map +1 -1
- package/dist/src/experimental/typekit/kits/model.d.ts +2 -1
- package/dist/src/experimental/typekit/kits/model.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/model.js +1 -1
- package/dist/src/experimental/typekit/kits/model.js.map +1 -1
- package/dist/src/experimental/typekit/kits/scalar.d.ts +2 -1
- package/dist/src/experimental/typekit/kits/scalar.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/scalar.js.map +1 -1
- package/dist/src/experimental/typekit/kits/type.d.ts +1 -1
- package/dist/src/experimental/typekit/kits/type.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/type.js +19 -13
- package/dist/src/experimental/typekit/kits/type.js.map +1 -1
- package/dist/src/experimental/typekit/kits/union-variant.d.ts +1 -1
- package/dist/src/experimental/typekit/kits/union-variant.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/union-variant.js +1 -1
- package/dist/src/experimental/typekit/kits/union-variant.js.map +1 -1
- package/dist/src/experimental/typekit/kits/union.d.ts +1 -1
- package/dist/src/experimental/typekit/kits/union.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/union.js +1 -1
- package/dist/src/experimental/typekit/kits/union.js.map +1 -1
- package/dist/src/experimental/typekit/utils.d.ts +28 -4
- package/dist/src/experimental/typekit/utils.d.ts.map +1 -1
- package/dist/src/experimental/typekit/utils.js +34 -23
- package/dist/src/experimental/typekit/utils.js.map +1 -1
- package/dist/src/lib/decorators.d.ts.map +1 -1
- package/dist/src/lib/decorators.js +9 -0
- package/dist/src/lib/decorators.js.map +1 -1
- package/dist/src/lib/visibility.js +5 -5
- package/dist/src/lib/visibility.js.map +1 -1
- package/dist/src/utils/misc.d.ts +1 -1
- package/dist/src/utils/misc.d.ts.map +1 -1
- package/dist/src/utils/misc.js.map +1 -1
- package/package.json +1 -1
- package/dist/src/experimental/typekit/kits/realm.d.ts +0 -24
- package/dist/src/experimental/typekit/kits/realm.d.ts.map +0 -1
- package/dist/src/experimental/typekit/kits/realm.js +0 -17
- package/dist/src/experimental/typekit/kits/realm.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutators.d.ts","sourceRoot":"","sources":["../../../src/experimental/mutators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACL,SAAS,EACT,
|
|
1
|
+
{"version":3,"file":"mutators.d.ts","sourceRoot":"","sources":["../../../src/experimental/mutators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,SAAS,EACT,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,IAAI,EACL,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAKnC;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,IAAI,IACpC,oBAAoB,CAAC,CAAC,CAAC,GACvB,mBAAmB,CAAC,CAAC,CAAC,GACtB,SAAS,CAAC,CAAC,CAAC,CAAC;AAEjB;;;;GAIG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,IAAI;IACjD;;OAEG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,IAAI,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IAClF;;OAEG;IACH,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;CAC9B;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,IAAI,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IACjF;;OAEG;IACH,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,IAAI,IA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AE,IAAI,GAAG,IAAI,IAAI,WAAW,CAe7D;AAED;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG,WAAW,GAAG,SAAS,CAAC;AAe/D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,wBAAwB,EAC5E,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,oBAAoB,EAAE,EAChC,IAAI,EAAE,CAAC,GACN;IAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,wBAAwB,CAAA;CAAE,CAEzD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,WAAW,EAClD,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,OAAO,EAAE,EACnB,IAAI,EAAE,CAAC,GACN;IAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CAyL5C"}
|
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
import { CustomKeyMap } from "../emitter-framework/custom-key-map.js";
|
|
2
2
|
import { Realm } from "./realm.js";
|
|
3
3
|
import { $ } from "./typekit/index.js";
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Flow control for mutators.
|
|
6
|
+
*
|
|
7
|
+
* When filtering types in a mutator, the filter function may return MutatorFlow flags to control how mutation should
|
|
8
|
+
* proceed.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link MutatorFilterFn}
|
|
11
|
+
*
|
|
12
|
+
* @experimental
|
|
13
|
+
*/
|
|
5
14
|
export var MutatorFlow;
|
|
6
15
|
(function (MutatorFlow) {
|
|
7
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Mutate the type and recur, further mutating the type's children. This is the default behavior.
|
|
18
|
+
*/
|
|
19
|
+
MutatorFlow[MutatorFlow["MutateAndRecur"] = 0] = "MutateAndRecur";
|
|
20
|
+
/**
|
|
21
|
+
* If this flag is set, the type will not be mutated.
|
|
22
|
+
*/
|
|
8
23
|
MutatorFlow[MutatorFlow["DoNotMutate"] = 1] = "DoNotMutate";
|
|
9
|
-
|
|
24
|
+
/**
|
|
25
|
+
* If this flag is set, the mutator will not proceed recursively into the children of the type.
|
|
26
|
+
*/
|
|
27
|
+
MutatorFlow[MutatorFlow["DoNotRecur"] = 2] = "DoNotRecur";
|
|
10
28
|
})(MutatorFlow || (MutatorFlow = {}));
|
|
11
29
|
/**
|
|
12
30
|
* Determines if a type is mutable.
|
|
31
|
+
*
|
|
32
|
+
* @experimental
|
|
13
33
|
*/
|
|
14
34
|
export function isMutableType(type) {
|
|
15
35
|
switch (type.kind) {
|
|
@@ -20,11 +40,15 @@ export function isMutableType(type) {
|
|
|
20
40
|
case "FunctionParameter":
|
|
21
41
|
case "Object":
|
|
22
42
|
case "Projection":
|
|
43
|
+
case "Namespace":
|
|
23
44
|
return false;
|
|
24
45
|
default:
|
|
46
|
+
void type;
|
|
25
47
|
return true;
|
|
26
48
|
}
|
|
27
49
|
}
|
|
50
|
+
// #endregion
|
|
51
|
+
// #region Mutator Application
|
|
28
52
|
const typeId = CustomKeyMap.objectKeyer();
|
|
29
53
|
const mutatorId = CustomKeyMap.objectKeyer();
|
|
30
54
|
const seen = new CustomKeyMap(([type, mutators]) => {
|
|
@@ -34,16 +58,49 @@ const seen = new CustomKeyMap(([type, mutators]) => {
|
|
|
34
58
|
return key;
|
|
35
59
|
});
|
|
36
60
|
/**
|
|
37
|
-
* Mutate the type graph
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
61
|
+
* Mutate the type graph, allowing namespaces to be mutated.
|
|
62
|
+
*
|
|
63
|
+
* **Warning**: This function will likely mutate the entire type graph. Most TypeSpec types relate to namespaces
|
|
64
|
+
* in some way (e.g. through namespace parent links, or the `namespace` property of a Model).
|
|
65
|
+
*
|
|
66
|
+
* @param program - The program in which the `type` occurs.
|
|
67
|
+
* @param mutators - An array of mutators to apply to the type graph rooted at `type`.
|
|
68
|
+
* @param type - The type to mutate.
|
|
69
|
+
*
|
|
70
|
+
* @returns an object containing the mutated `type` and a nullable `Realm` in which the mutated type resides.
|
|
71
|
+
*
|
|
72
|
+
* @see {@link mutateSubgraph}
|
|
73
|
+
*
|
|
41
74
|
* @experimental
|
|
42
75
|
*/
|
|
43
76
|
export function mutateSubgraphWithNamespace(program, mutators, type) {
|
|
44
77
|
return mutateSubgraph(program, mutators, type);
|
|
45
78
|
}
|
|
46
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Mutate the type graph.
|
|
81
|
+
*
|
|
82
|
+
* Mutators clone the input `type`, creating a new type instance that is mutated in place.
|
|
83
|
+
*
|
|
84
|
+
* The mutator returns the mutated type and optionally a `realm` in which the mutated clone resides.
|
|
85
|
+
*
|
|
86
|
+
* @see {@link Mutator}
|
|
87
|
+
* @see {@link Realm}
|
|
88
|
+
*
|
|
89
|
+
* **Warning**: Mutators _SHOULD NOT_ modify the source type. Modifications to the source type
|
|
90
|
+
* will be visible to other emitters or libraries that view the original source type, and will
|
|
91
|
+
* be sensitive to the order in which the mutator was applied. Only edit the `clone` type.
|
|
92
|
+
* Furthermore, mutators must take care not to modify elements of the source and clone types
|
|
93
|
+
* that are shared between the two types, such as the properties of any parent references
|
|
94
|
+
* or the `decorators` of the type without taking care to clone them first.
|
|
95
|
+
*
|
|
96
|
+
* @param program - The program in which the `type` occurs.
|
|
97
|
+
* @param mutators - An array of mutators to apply to the type graph rooted at `type`.
|
|
98
|
+
* @param type - The type to mutate.
|
|
99
|
+
*
|
|
100
|
+
* @returns an object containing the mutated `type` and a nullable `Realm` in which the mutated type resides.
|
|
101
|
+
*
|
|
102
|
+
* @experimental
|
|
103
|
+
*/
|
|
47
104
|
export function mutateSubgraph(program, mutators, type) {
|
|
48
105
|
const realm = new Realm(program, "realm for mutation");
|
|
49
106
|
const interstitialFunctions = [];
|
|
@@ -93,7 +150,7 @@ export function mutateSubgraph(program, mutators, type) {
|
|
|
93
150
|
}
|
|
94
151
|
else {
|
|
95
152
|
mutate = (filterResult & MutatorFlow.DoNotMutate) === 0;
|
|
96
|
-
recurse = (filterResult & MutatorFlow.
|
|
153
|
+
recurse = (filterResult & MutatorFlow.DoNotRecur) === 0;
|
|
97
154
|
}
|
|
98
155
|
}
|
|
99
156
|
else {
|
|
@@ -144,10 +201,10 @@ export function mutateSubgraph(program, mutators, type) {
|
|
|
144
201
|
if (newMutators.size > 0) {
|
|
145
202
|
visitSubgraph();
|
|
146
203
|
}
|
|
147
|
-
|
|
204
|
+
$(realm).type.finishType(clone);
|
|
148
205
|
return clone;
|
|
149
206
|
function initializeClone() {
|
|
150
|
-
clone =
|
|
207
|
+
clone = $(realm).type.clone(type);
|
|
151
208
|
seen.set([type, activeMutators], clone);
|
|
152
209
|
seen.set([type, mutatorsToApply], clone);
|
|
153
210
|
}
|
|
@@ -197,4 +254,5 @@ export function mutateSubgraph(program, mutators, type) {
|
|
|
197
254
|
}
|
|
198
255
|
}
|
|
199
256
|
}
|
|
257
|
+
// #endregion
|
|
200
258
|
//# sourceMappingURL=mutators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutators.js","sourceRoot":"","sources":["../../../src/experimental/mutators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutators.js","sourceRoot":"","sources":["../../../src/experimental/mutators.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAC;AAuJvC;;;;;;;;;GASG;AACH,MAAM,CAAN,IAAY,WAaX;AAbD,WAAY,WAAW;IACrB;;OAEG;IACH,iEAAkB,CAAA;IAClB;;OAEG;IACH,2DAAoB,CAAA;IACpB;;OAEG;IACH,yDAAmB,CAAA;AACrB,CAAC,EAbW,WAAW,KAAX,WAAW,QAatB;A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Ae;oBAClB,MAAM,OAAO,GAAG,oBAAoB,CAAC,IAAI,CAAC,IAAmB,EAAE,WAAW,CAAC,CAAC;oBAC5E,IAAI,KAAK,EAAE,CAAC;wBACT,KAAa,CAAC,IAAI,GAAG,OAAO,CAAC;oBAChC,CAAC;oBAED,MAAM;gBACR,KAAK,WAAW;oBACd,MAAM,SAAS,GAAG,oBAAoB,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;oBACrE,IAAI,KAAK,EAAE,CAAC;wBACT,KAAa,CAAC,UAAU,GAAG,SAAS,CAAC;oBACxC,CAAC;oBAED,MAAM;gBACR,KAAK,QAAQ;oBACX,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU;wBACnC,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC;wBACpD,CAAC,CAAC,SAAS,CAAC;oBACd,IAAI,KAAK,EAAE,CAAC;wBACT,KAAa,CAAC,UAAU,GAAG,aAAa,CAAC;oBAC5C,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,aAAa"}
|
|
@@ -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
|
-
/**
|
|
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:
|
|
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;
|
|
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;AACxC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,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 {
|
|
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
|
|
22
|
+
return this.#select(t).has(t) ?? false;
|
|
15
23
|
}
|
|
16
24
|
set(t, v) {
|
|
17
|
-
this
|
|
25
|
+
this.#select(t).set(t, v);
|
|
18
26
|
return this;
|
|
19
27
|
}
|
|
20
28
|
get(t) {
|
|
21
|
-
return this
|
|
29
|
+
return this.#select(t).get(t);
|
|
22
30
|
}
|
|
23
31
|
delete(t) {
|
|
24
|
-
return this
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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":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
|
|
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
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"define-kit.js","sourceRoot":"","sources":["../../../../src/experimental/typekit/define-kit.ts"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA4B,EAAE,CAAC;AAa5D;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CACvB,MAA0C;IAE1C,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACpD,gBAAgB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;IAClC,CAAC;AACH,CAAC"}
|