@typespec/compiler 0.61.0-dev.1 → 0.61.0-dev.11
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/binder.d.ts +4 -4
- package/dist/src/core/checker.js +1 -1
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/cli/actions/compile/compile.js +0 -1
- package/dist/src/core/cli/actions/compile/compile.js.map +1 -1
- package/dist/src/core/cli/actions/compile/watch.js +3 -0
- package/dist/src/core/cli/actions/compile/watch.js.map +1 -1
- package/dist/src/core/helpers/index.d.ts.map +1 -1
- package/dist/src/core/helpers/index.js +1 -3
- package/dist/src/core/helpers/index.js.map +1 -1
- package/dist/src/core/index.d.ts +1 -1
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +2 -6
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/library.js +1 -1
- package/dist/src/core/library.js.map +1 -1
- package/dist/src/core/logger/support-hyperlinks.d.ts.map +1 -1
- package/dist/src/core/logger/support-hyperlinks.js +0 -1
- package/dist/src/core/logger/support-hyperlinks.js.map +1 -1
- package/dist/src/core/numeric.js +1 -1
- package/dist/src/core/numeric.js.map +1 -1
- package/dist/src/core/program.d.ts.map +1 -1
- package/dist/src/core/program.js +17 -14
- package/dist/src/core/program.js.map +1 -1
- package/dist/src/core/projector.js +5 -5
- package/dist/src/core/projector.js.map +1 -1
- package/dist/src/core/source-loader.d.ts +2 -2
- package/dist/src/core/source-loader.d.ts.map +1 -1
- package/dist/src/core/source-loader.js +1 -1
- package/dist/src/core/source-loader.js.map +1 -1
- package/dist/src/core/state-accessors.d.ts +8 -8
- package/dist/src/core/types.d.ts +1 -1
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/emitter-framework/type-emitter.d.ts.map +1 -1
- package/dist/src/emitter-framework/type-emitter.js +0 -1
- package/dist/src/emitter-framework/type-emitter.js.map +1 -1
- package/dist/src/experimental/index.d.ts +5 -0
- package/dist/src/experimental/index.d.ts.map +1 -0
- package/dist/src/experimental/index.js +5 -0
- package/dist/src/experimental/index.js.map +1 -0
- package/dist/src/experimental/mutators.d.ts +57 -0
- package/dist/src/experimental/mutators.d.ts.map +1 -0
- package/dist/src/experimental/mutators.js +173 -0
- package/dist/src/experimental/mutators.js.map +1 -0
- package/dist/src/experimental/realm.d.ts +34 -0
- package/dist/src/experimental/realm.d.ts.map +1 -0
- package/dist/src/experimental/realm.js +128 -0
- package/dist/src/experimental/realm.js.map +1 -0
- package/dist/src/experimental/state-accessor.d.ts +13 -0
- package/dist/src/experimental/state-accessor.d.ts.map +1 -0
- package/dist/src/experimental/state-accessor.js +14 -0
- package/dist/src/experimental/state-accessor.js.map +1 -0
- package/dist/src/experimental/typekit/define-kit.d.ts +28 -0
- package/dist/src/experimental/typekit/define-kit.d.ts.map +1 -0
- package/dist/src/experimental/typekit/define-kit.js +45 -0
- package/dist/src/experimental/typekit/define-kit.js.map +1 -0
- package/dist/src/experimental/typekit/index.d.ts +3 -0
- package/dist/src/experimental/typekit/index.d.ts.map +1 -0
- package/dist/src/experimental/typekit/index.js +3 -0
- package/dist/src/experimental/typekit/index.js.map +1 -0
- package/dist/src/experimental/typekit/kits/index.d.ts +9 -0
- package/dist/src/experimental/typekit/kits/index.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/index.js +9 -0
- package/dist/src/experimental/typekit/kits/index.js.map +1 -0
- package/dist/src/experimental/typekit/kits/literal.d.ts +59 -0
- package/dist/src/experimental/typekit/kits/literal.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/literal.js +51 -0
- package/dist/src/experimental/typekit/kits/literal.js.map +1 -0
- package/dist/src/experimental/typekit/kits/model-property.d.ts +45 -0
- package/dist/src/experimental/typekit/kits/model-property.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/model-property.js +19 -0
- package/dist/src/experimental/typekit/kits/model-property.js.map +1 -0
- package/dist/src/experimental/typekit/kits/model.d.ts +48 -0
- package/dist/src/experimental/typekit/kits/model.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/model.js +26 -0
- package/dist/src/experimental/typekit/kits/model.js.map +1 -0
- package/dist/src/experimental/typekit/kits/realm.d.ts +24 -0
- package/dist/src/experimental/typekit/kits/realm.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/realm.js +17 -0
- package/dist/src/experimental/typekit/kits/realm.js.map +1 -0
- package/dist/src/experimental/typekit/kits/scalar.d.ts +354 -0
- package/dist/src/experimental/typekit/kits/scalar.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/scalar.js +91 -0
- package/dist/src/experimental/typekit/kits/scalar.js.map +1 -0
- package/dist/src/experimental/typekit/kits/type.d.ts +25 -0
- package/dist/src/experimental/typekit/kits/type.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/type.js +55 -0
- package/dist/src/experimental/typekit/kits/type.js.map +1 -0
- package/dist/src/experimental/typekit/kits/union-variant.d.ts +43 -0
- package/dist/src/experimental/typekit/kits/union-variant.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/union-variant.js +22 -0
- package/dist/src/experimental/typekit/kits/union-variant.js.map +1 -0
- package/dist/src/experimental/typekit/kits/union.d.ts +56 -0
- package/dist/src/experimental/typekit/kits/union.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/union.js +69 -0
- package/dist/src/experimental/typekit/kits/union.js.map +1 -0
- package/dist/src/experimental/typekit/utils.d.ts +8 -0
- package/dist/src/experimental/typekit/utils.d.ts.map +1 -0
- package/dist/src/experimental/typekit/utils.js +28 -0
- package/dist/src/experimental/typekit/utils.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/init/scaffold.d.ts.map +1 -1
- package/dist/src/init/scaffold.js.map +1 -1
- package/dist/src/lib/decorators.d.ts +35 -19
- package/dist/src/lib/decorators.d.ts.map +1 -1
- package/dist/src/lib/decorators.js +71 -91
- package/dist/src/lib/decorators.js.map +1 -1
- package/dist/src/lib/encoded-names.js +6 -8
- package/dist/src/lib/encoded-names.js.map +1 -1
- package/dist/src/lib/examples.d.ts.map +1 -1
- package/dist/src/lib/examples.js +5 -2
- package/dist/src/lib/examples.js.map +1 -1
- package/dist/src/lib/service.d.ts +3 -1
- package/dist/src/lib/service.d.ts.map +1 -1
- package/dist/src/lib/service.js +6 -9
- package/dist/src/lib/service.js.map +1 -1
- package/dist/src/lib/tsp-index.d.ts.map +1 -1
- package/dist/src/lib/tsp-index.js +0 -1
- package/dist/src/lib/tsp-index.js.map +1 -1
- package/dist/src/lib/utils.d.ts +4 -0
- package/dist/src/lib/utils.d.ts.map +1 -0
- package/dist/src/lib/utils.js +11 -0
- package/dist/src/lib/utils.js.map +1 -0
- package/dist/src/{core → module-resolver}/module-resolver.d.ts +2 -21
- package/dist/src/module-resolver/module-resolver.d.ts.map +1 -0
- package/dist/src/{core → module-resolver}/module-resolver.js +1 -1
- package/dist/src/module-resolver/module-resolver.js.map +1 -0
- package/dist/src/runner.js +1 -1
- package/dist/src/runner.js.map +1 -1
- package/dist/src/server/completion.d.ts.map +1 -1
- package/dist/src/server/completion.js.map +1 -1
- package/dist/src/server/file-system-cache.js +2 -2
- package/dist/src/server/file-system-cache.js.map +1 -1
- package/dist/src/server/server.js +0 -2
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/serverlib.js +6 -6
- package/dist/src/server/serverlib.js.map +1 -1
- package/dist/src/types/package-json.d.ts +40 -0
- package/dist/src/types/package-json.d.ts.map +1 -0
- package/dist/src/types/package-json.js +2 -0
- package/dist/src/types/package-json.js.map +1 -0
- package/dist/src/utils/misc.d.ts.map +1 -1
- package/dist/src/utils/misc.js +1 -3
- package/dist/src/utils/misc.js.map +1 -1
- package/package.json +16 -12
- package/templates/emitter-ts/eslint.config.js +1 -1
- package/templates/library-ts/eslint.config.js +1 -1
- package/templates/scaffolding.json +4 -4
- package/dist/src/core/module-resolver.d.ts.map +0 -1
- package/dist/src/core/module-resolver.js.map +0 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { CustomKeyMap } from "../emitter-framework/custom-key-map.js";
|
|
2
|
+
import { Realm } from "./realm.js";
|
|
3
|
+
import { $ } from "./typekit/index.js";
|
|
4
|
+
/** @experimental */
|
|
5
|
+
export var MutatorFlow;
|
|
6
|
+
(function (MutatorFlow) {
|
|
7
|
+
MutatorFlow[MutatorFlow["MutateAndRecurse"] = 0] = "MutateAndRecurse";
|
|
8
|
+
MutatorFlow[MutatorFlow["DoNotMutate"] = 1] = "DoNotMutate";
|
|
9
|
+
MutatorFlow[MutatorFlow["DoNotRecurse"] = 2] = "DoNotRecurse";
|
|
10
|
+
})(MutatorFlow || (MutatorFlow = {}));
|
|
11
|
+
const typeId = CustomKeyMap.objectKeyer();
|
|
12
|
+
const mutatorId = CustomKeyMap.objectKeyer();
|
|
13
|
+
const seen = new CustomKeyMap(([type, mutators]) => {
|
|
14
|
+
const key = `${typeId.getKey(type)}-${[...mutators.values()]
|
|
15
|
+
.map((v) => mutatorId.getKey(v))
|
|
16
|
+
.join("-")}`;
|
|
17
|
+
return key;
|
|
18
|
+
});
|
|
19
|
+
/** @experimental */
|
|
20
|
+
export function mutateSubgraph(program, mutators, type) {
|
|
21
|
+
const realm = new Realm(program, "realm for mutation");
|
|
22
|
+
const interstitialFunctions = [];
|
|
23
|
+
const mutated = mutateSubgraphWorker(type, new Set(mutators));
|
|
24
|
+
if (mutated === type) {
|
|
25
|
+
return { realm: null, type };
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return { realm, type: mutated };
|
|
29
|
+
}
|
|
30
|
+
function mutateSubgraphWorker(type, activeMutators) {
|
|
31
|
+
let existing = seen.get([type, activeMutators]);
|
|
32
|
+
if (existing) {
|
|
33
|
+
clearInterstitialFunctions();
|
|
34
|
+
return existing;
|
|
35
|
+
}
|
|
36
|
+
let clone = null;
|
|
37
|
+
const mutatorsWithOptions = [];
|
|
38
|
+
// step 1: see what mutators to run
|
|
39
|
+
const newMutators = new Set(activeMutators.values());
|
|
40
|
+
for (const mutator of activeMutators) {
|
|
41
|
+
const record = mutator[type.kind];
|
|
42
|
+
if (!record) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
let mutationFn = null;
|
|
46
|
+
let replaceFn = null;
|
|
47
|
+
let mutate = false;
|
|
48
|
+
let recurse = false;
|
|
49
|
+
if (typeof record === "function") {
|
|
50
|
+
mutationFn = record;
|
|
51
|
+
mutate = true;
|
|
52
|
+
recurse = true;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
mutationFn = "mutate" in record ? record.mutate : null;
|
|
56
|
+
replaceFn = "replace" in record ? record.replace : null;
|
|
57
|
+
if (record.filter) {
|
|
58
|
+
const filterResult = record.filter(type, program, realm);
|
|
59
|
+
if (filterResult === true) {
|
|
60
|
+
mutate = true;
|
|
61
|
+
recurse = true;
|
|
62
|
+
}
|
|
63
|
+
else if (filterResult === false) {
|
|
64
|
+
mutate = false;
|
|
65
|
+
recurse = true;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
mutate = (filterResult & MutatorFlow.DoNotMutate) === 0;
|
|
69
|
+
recurse = (filterResult & MutatorFlow.DoNotRecurse) === 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
mutate = true;
|
|
74
|
+
recurse = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!recurse) {
|
|
78
|
+
newMutators.delete(mutator);
|
|
79
|
+
}
|
|
80
|
+
if (mutate) {
|
|
81
|
+
mutatorsWithOptions.push({ mutator, mutationFn, replaceFn });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const mutatorsToApply = mutatorsWithOptions.map((v) => v.mutator);
|
|
85
|
+
// if we have no mutators to apply, let's bail out.
|
|
86
|
+
if (mutatorsWithOptions.length === 0) {
|
|
87
|
+
if (newMutators.size > 0) {
|
|
88
|
+
// we might need to clone this type later if something in our subgraph needs mutated.
|
|
89
|
+
interstitialFunctions.push(initializeClone);
|
|
90
|
+
visitSubgraph();
|
|
91
|
+
interstitialFunctions.pop();
|
|
92
|
+
return clone ?? type;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// we don't need to clone this type, so let's just return it.
|
|
96
|
+
return type;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// step 2: see if we need to mutate based on the set of mutators we're actually going to run
|
|
100
|
+
existing = seen.get([type, mutatorsToApply]);
|
|
101
|
+
if (existing) {
|
|
102
|
+
clearInterstitialFunctions();
|
|
103
|
+
return existing;
|
|
104
|
+
}
|
|
105
|
+
// step 3: run the mutators
|
|
106
|
+
clearInterstitialFunctions();
|
|
107
|
+
initializeClone();
|
|
108
|
+
for (const { mutationFn, replaceFn } of mutatorsWithOptions) {
|
|
109
|
+
// todo: handle replace earlier in the mutation chain
|
|
110
|
+
const result = (mutationFn ?? replaceFn)(type, clone, program, realm);
|
|
111
|
+
if (replaceFn && result !== undefined) {
|
|
112
|
+
clone = result;
|
|
113
|
+
seen.set([type, activeMutators], clone);
|
|
114
|
+
seen.set([type, mutatorsToApply], clone);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (newMutators.size > 0) {
|
|
118
|
+
visitSubgraph();
|
|
119
|
+
}
|
|
120
|
+
$.type.finishType(clone);
|
|
121
|
+
return clone;
|
|
122
|
+
function initializeClone() {
|
|
123
|
+
clone = $.type.clone(type);
|
|
124
|
+
seen.set([type, activeMutators], clone);
|
|
125
|
+
seen.set([type, mutatorsToApply], clone);
|
|
126
|
+
}
|
|
127
|
+
function clearInterstitialFunctions() {
|
|
128
|
+
for (const interstitial of interstitialFunctions) {
|
|
129
|
+
interstitial();
|
|
130
|
+
}
|
|
131
|
+
interstitialFunctions.length = 0;
|
|
132
|
+
}
|
|
133
|
+
function visitSubgraph() {
|
|
134
|
+
const root = clone ?? type;
|
|
135
|
+
switch (root.kind) {
|
|
136
|
+
case "Model":
|
|
137
|
+
for (const prop of root.properties.values()) {
|
|
138
|
+
const newProp = mutateSubgraphWorker(prop, newMutators);
|
|
139
|
+
if (clone) {
|
|
140
|
+
clone.properties.set(prop.name, newProp);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (root.indexer) {
|
|
144
|
+
const res = mutateSubgraphWorker(root.indexer.value, newMutators);
|
|
145
|
+
if (clone) {
|
|
146
|
+
clone.indexer.value = res;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
case "ModelProperty":
|
|
151
|
+
const newType = mutateSubgraphWorker(root.type, newMutators);
|
|
152
|
+
if (clone) {
|
|
153
|
+
clone.type = newType;
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
case "Operation":
|
|
157
|
+
const newParams = mutateSubgraphWorker(root.parameters, newMutators);
|
|
158
|
+
if (clone) {
|
|
159
|
+
clone.parameters = newParams;
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case "Scalar":
|
|
163
|
+
const newBaseScalar = root.baseScalar
|
|
164
|
+
? mutateSubgraphWorker(root.baseScalar, newMutators)
|
|
165
|
+
: undefined;
|
|
166
|
+
if (clone) {
|
|
167
|
+
clone.baseScalar = newBaseScalar;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=mutators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutators.js","sourceRoot":"","sources":["../../../src/experimental/mutators.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAC;AAkDvC,oBAAoB;AACpB,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,qEAAoB,CAAA;IACpB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,EAAE,CAAC;wBACT,KAAa,CAAC,UAAU,GAAG,aAAa,CAAC;oBAC5C,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Program } from "../core/program.js";
|
|
2
|
+
import { Type } from "../core/types.js";
|
|
3
|
+
declare class StateMapRealmView<V> implements Map<Type, V> {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(realm: Realm, realmState: Map<Type, V>, parentState: Map<Type, V>);
|
|
6
|
+
has(t: Type): boolean;
|
|
7
|
+
set(t: Type, v: any): this;
|
|
8
|
+
get(t: Type): V | undefined;
|
|
9
|
+
delete(t: Type): boolean;
|
|
10
|
+
forEach(cb: (value: V, key: Type, map: Map<Type, V>) => void, thisArg?: any): this;
|
|
11
|
+
get size(): number;
|
|
12
|
+
clear(): void;
|
|
13
|
+
entries(): IterableIterator<[Type, V]>;
|
|
14
|
+
values(): IterableIterator<V>;
|
|
15
|
+
keys(): IterableIterator<Type>;
|
|
16
|
+
[Symbol.iterator](): IterableIterator<[Type, V]>;
|
|
17
|
+
[Symbol.toStringTag]: string;
|
|
18
|
+
dispatch(keyType: Type): Map<Type, V>;
|
|
19
|
+
}
|
|
20
|
+
/** @experimental */
|
|
21
|
+
export declare class Realm {
|
|
22
|
+
#private;
|
|
23
|
+
key: symbol;
|
|
24
|
+
constructor(program: Program, description: string);
|
|
25
|
+
stateMap(stateKey: symbol): StateMapRealmView<any>;
|
|
26
|
+
clone<T extends Type>(type: T): T;
|
|
27
|
+
remove(type: Type): void;
|
|
28
|
+
hasType(type: Type): boolean;
|
|
29
|
+
addType(type: Type): void;
|
|
30
|
+
static realmForKey(key: symbol, parentRealm?: Realm): Realm | undefined;
|
|
31
|
+
static realmForType: Map<Type, Realm>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=realm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realm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E,MAAM;IAWzB,KAAK,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC;IASjC,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAIxB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAI5B,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAczB,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,KAAK;IAInD,MAAM,CAAC,YAAY,mBAA0B;CAC9C"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { compilerAssert } from "../core/diagnostics.js";
|
|
3
|
+
import { $ } from "./typekit/define-kit.js";
|
|
4
|
+
class StateMapRealmView {
|
|
5
|
+
#realm;
|
|
6
|
+
#parentState;
|
|
7
|
+
#realmState;
|
|
8
|
+
constructor(realm, realmState, parentState) {
|
|
9
|
+
this.#realm = realm;
|
|
10
|
+
this.#parentState = parentState;
|
|
11
|
+
this.#realmState = realmState;
|
|
12
|
+
}
|
|
13
|
+
has(t) {
|
|
14
|
+
return this.dispatch(t).has(t) ?? false;
|
|
15
|
+
}
|
|
16
|
+
set(t, v) {
|
|
17
|
+
this.dispatch(t).set(t, v);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
get(t) {
|
|
21
|
+
return this.dispatch(t).get(t);
|
|
22
|
+
}
|
|
23
|
+
delete(t) {
|
|
24
|
+
return this.dispatch(t).delete(t);
|
|
25
|
+
}
|
|
26
|
+
forEach(cb, thisArg) {
|
|
27
|
+
for (const item of this.entries()) {
|
|
28
|
+
cb.call(thisArg, item[1], item[0], this);
|
|
29
|
+
}
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
get size() {
|
|
33
|
+
// extremely non-optimal, maybe worth not offering it?
|
|
34
|
+
return [...this.entries()].length;
|
|
35
|
+
}
|
|
36
|
+
clear() {
|
|
37
|
+
this.#realmState.clear();
|
|
38
|
+
}
|
|
39
|
+
*entries() {
|
|
40
|
+
for (const item of this.#realmState) {
|
|
41
|
+
yield item;
|
|
42
|
+
}
|
|
43
|
+
for (const item of this.#parentState) {
|
|
44
|
+
yield item;
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
*values() {
|
|
49
|
+
for (const item of this.entries()) {
|
|
50
|
+
yield item[1];
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
*keys() {
|
|
55
|
+
for (const item of this.entries()) {
|
|
56
|
+
yield item[0];
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
[Symbol.iterator]() {
|
|
61
|
+
return this.entries();
|
|
62
|
+
}
|
|
63
|
+
[Symbol.toStringTag] = "StateMap";
|
|
64
|
+
dispatch(keyType) {
|
|
65
|
+
if (this.#realm.hasType(keyType)) {
|
|
66
|
+
return this.#realmState;
|
|
67
|
+
}
|
|
68
|
+
return this.#parentState;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** @experimental */
|
|
72
|
+
export class Realm {
|
|
73
|
+
#program;
|
|
74
|
+
// Type registry
|
|
75
|
+
/**
|
|
76
|
+
* Stores all types owned by this realm.
|
|
77
|
+
*/
|
|
78
|
+
#types = new Set();
|
|
79
|
+
/**
|
|
80
|
+
* Stores types that are deleted in this realm. When a realm is active and doing a traversal, you will
|
|
81
|
+
* not find this type in e.g. collections. Deleted types are mapped to `null` if you ask for it.
|
|
82
|
+
*/
|
|
83
|
+
#deletedTypes = new Set();
|
|
84
|
+
#stateMaps = new Map();
|
|
85
|
+
key;
|
|
86
|
+
constructor(program, description) {
|
|
87
|
+
this.key = Symbol(description);
|
|
88
|
+
this.#program = program;
|
|
89
|
+
_a.#knownRealms.set(this.key, this);
|
|
90
|
+
}
|
|
91
|
+
stateMap(stateKey) {
|
|
92
|
+
let m = this.#stateMaps.get(stateKey);
|
|
93
|
+
if (!m) {
|
|
94
|
+
m = new Map();
|
|
95
|
+
this.#stateMaps.set(stateKey, m);
|
|
96
|
+
}
|
|
97
|
+
return new StateMapRealmView(this, m, this.#program.stateMap(stateKey));
|
|
98
|
+
}
|
|
99
|
+
clone(type) {
|
|
100
|
+
compilerAssert(type, "Undefined type passed to clone");
|
|
101
|
+
const clone = this.#cloneIntoRealm(type);
|
|
102
|
+
$.type.finishType(clone);
|
|
103
|
+
return clone;
|
|
104
|
+
}
|
|
105
|
+
remove(type) {
|
|
106
|
+
this.#deletedTypes.add(type);
|
|
107
|
+
}
|
|
108
|
+
hasType(type) {
|
|
109
|
+
return this.#types.has(type);
|
|
110
|
+
}
|
|
111
|
+
addType(type) {
|
|
112
|
+
this.#types.add(type);
|
|
113
|
+
_a.realmForType.set(type, this);
|
|
114
|
+
}
|
|
115
|
+
#cloneIntoRealm(type) {
|
|
116
|
+
const clone = $.type.clone(type);
|
|
117
|
+
this.#types.add(clone);
|
|
118
|
+
_a.realmForType.set(clone, this);
|
|
119
|
+
return clone;
|
|
120
|
+
}
|
|
121
|
+
static #knownRealms = new Map();
|
|
122
|
+
static realmForKey(key, parentRealm) {
|
|
123
|
+
return this.#knownRealms.get(key);
|
|
124
|
+
}
|
|
125
|
+
static realmForType = new Map();
|
|
126
|
+
}
|
|
127
|
+
_a = Realm;
|
|
128
|
+
//# sourceMappingURL=realm.js.map
|
|
@@ -0,0 +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;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AAC,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,GAAG,EAAe,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Program } from "../core/program.js";
|
|
2
|
+
import type { Type } from "../core/types.js";
|
|
3
|
+
type StateMapGetter<K extends Type, V> = (program: Program, type: K) => V | undefined;
|
|
4
|
+
type StateMapSetter<K extends Type, V> = (program: Program, type: K, value: V) => void;
|
|
5
|
+
type StateMapMapGetter<K extends Type, V> = (program: Program) => Map<K, V>;
|
|
6
|
+
/** @experimental */
|
|
7
|
+
export declare function unsafe_useStateMap<K extends Type, V>(key: symbol): [StateMapGetter<K, V>, StateMapSetter<K, V>, StateMapMapGetter<K, V>];
|
|
8
|
+
type StateSetGetter<K extends Type> = (program: Program, type: K) => boolean;
|
|
9
|
+
type StateSetSetter<K extends Type> = (program: Program, type: K) => void;
|
|
10
|
+
/** @experimental */
|
|
11
|
+
export declare function unsafe_useStateSet<K extends Type>(key: symbol): [StateSetGetter<K>, StateSetSetter<K>];
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=state-accessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-accessor.d.ts","sourceRoot":"","sources":["../../../src/experimental/state-accessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,KAAK,cAAc,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;AACtF,KAAK,cAAc,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AACvF,KAAK,iBAAiB,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE5E,oBAAoB;AACpB,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,EAClD,GAAG,EAAE,MAAM,GACV,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAMvE;AAED,KAAK,cAAc,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;AAC7E,KAAK,cAAc,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;AAE1E,oBAAoB;AACpB,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,IAAI,EAC/C,GAAG,EAAE,MAAM,GACV,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAKxC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @experimental */
|
|
2
|
+
export function unsafe_useStateMap(key) {
|
|
3
|
+
const getter = (program, target) => program.stateMap(key).get(target);
|
|
4
|
+
const setter = (program, target, value) => program.stateMap(key).set(target, value);
|
|
5
|
+
const mapGetter = (program) => program.stateMap(key);
|
|
6
|
+
return [getter, setter, mapGetter];
|
|
7
|
+
}
|
|
8
|
+
/** @experimental */
|
|
9
|
+
export function unsafe_useStateSet(key) {
|
|
10
|
+
const getter = (program, target) => program.stateSet(key).has(target);
|
|
11
|
+
const setter = (program, target) => program.stateSet(key).add(target);
|
|
12
|
+
return [getter, setter];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=state-accessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-accessor.js","sourceRoot":"","sources":["../../../src/experimental/state-accessor.ts"],"names":[],"mappings":"AAOA,oBAAoB;AACpB,MAAM,UAAU,kBAAkB,CAChC,GAAW;IAEX,MAAM,MAAM,GAAG,CAAC,OAAgB,EAAE,MAAS,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,CAAC,OAAgB,EAAE,MAAS,EAAE,KAAQ,EAAE,EAAE,CACvD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC9D,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,SAAgB,CAAC,CAAC;AAC5C,CAAC;AAKD,oBAAoB;AACpB,MAAM,UAAU,kBAAkB,CAChC,GAAW;IAEX,MAAM,MAAM,GAAG,CAAC,OAAgB,EAAE,MAAS,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,CAAC,OAAgB,EAAE,MAAS,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAElF,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* contextual typing to type guards is annoying (often have to restate the signature),
|
|
18
|
+
* so this helper will remove the type assertions from the interface you are currently defining.
|
|
19
|
+
* @experimental
|
|
20
|
+
*/
|
|
21
|
+
export type StripGuards<T> = {
|
|
22
|
+
[K in keyof T]: T[K] extends (...args: infer P) => infer R ? (...args: P) => R : StripGuards<T[K]>;
|
|
23
|
+
};
|
|
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;
|
|
28
|
+
//# sourceMappingURL=define-kit.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
let currentProgram;
|
|
2
|
+
/** @experimental */
|
|
3
|
+
export function setCurrentProgram(program) {
|
|
4
|
+
currentProgram = program;
|
|
5
|
+
}
|
|
6
|
+
/** @experimental */
|
|
7
|
+
export const TypekitPrototype = {};
|
|
8
|
+
/** @experimental */
|
|
9
|
+
export function createTypekit() {
|
|
10
|
+
const tk = Object.create(TypekitPrototype);
|
|
11
|
+
Object.defineProperty(tk, "program", {
|
|
12
|
+
get() {
|
|
13
|
+
return currentProgram;
|
|
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 */
|
|
38
|
+
export function defineKit(source) {
|
|
39
|
+
for (const [name, fnOrNs] of Object.entries(source)) {
|
|
40
|
+
TypekitPrototype[name] = fnOrNs;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** @experimental */
|
|
44
|
+
export const $ = createTypekit();
|
|
45
|
+
//# sourceMappingURL=define-kit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-kit.js","sourceRoot":"","sources":["../../../../src/experimental/typekit/define-kit.ts"],"names":[],"mappings":"AAEA,IAAI,cAAmC,CAAC;AAExC,oBAAoB;AACpB,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,cAAc,GAAG,OAAO,CAAC;AAC3B,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,OAAO,cAAc,CAAC;QACxB,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,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAElD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,qFAAqF;gBACrF,OAAO,KAAK,CAAC;YACf,CAAC;YAED,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,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,KAAK,CAAC;AACf,CAAC;AAkBD,oBAAoB;AACpB,MAAM,UAAU,SAAS,CACvB,MAAmD;IAEnD,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;AAED,oBAAoB;AACpB,MAAM,CAAC,MAAM,CAAC,GAAqB,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/experimental/typekit/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./literal.js";
|
|
2
|
+
export * from "./model-property.js";
|
|
3
|
+
export * from "./model.js";
|
|
4
|
+
export * from "./realm.js";
|
|
5
|
+
export * from "./scalar.js";
|
|
6
|
+
export * from "./type.js";
|
|
7
|
+
export * from "./union-variant.js";
|
|
8
|
+
export * from "./union.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./literal.js";
|
|
2
|
+
export * from "./model-property.js";
|
|
3
|
+
export * from "./model.js";
|
|
4
|
+
export * from "./realm.js";
|
|
5
|
+
export * from "./scalar.js";
|
|
6
|
+
export * from "./type.js";
|
|
7
|
+
export * from "./union-variant.js";
|
|
8
|
+
export * from "./union.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { BooleanLiteral, NumericLiteral, StringLiteral, Type } from "../../../core/types.js";
|
|
2
|
+
interface LiteralKit {
|
|
3
|
+
literal: {
|
|
4
|
+
/**
|
|
5
|
+
* Create a literal type from a JavaScript value.
|
|
6
|
+
*
|
|
7
|
+
* @param value The JavaScript value to turn into a TypeSpec literal type.
|
|
8
|
+
*/
|
|
9
|
+
create(value: string | number | boolean): StringLiteral | NumericLiteral | BooleanLiteral;
|
|
10
|
+
/**
|
|
11
|
+
* Create a string literal type from a JavaScript string value.
|
|
12
|
+
*
|
|
13
|
+
* @param value The string value.
|
|
14
|
+
*/
|
|
15
|
+
createString(value: string): StringLiteral;
|
|
16
|
+
/**
|
|
17
|
+
* Create a numeric literal type from a JavaScript number value.
|
|
18
|
+
*
|
|
19
|
+
* @param value The numeric value.
|
|
20
|
+
*/
|
|
21
|
+
createNumeric(value: number): NumericLiteral;
|
|
22
|
+
/**
|
|
23
|
+
* Create a boolean literal type from a JavaScript boolean value.
|
|
24
|
+
*
|
|
25
|
+
* @param value The boolean value.
|
|
26
|
+
*/
|
|
27
|
+
createBoolean(value: boolean): BooleanLiteral;
|
|
28
|
+
/**
|
|
29
|
+
* Check if `type` is a literal type.
|
|
30
|
+
*
|
|
31
|
+
* @param type The type to check.
|
|
32
|
+
*/
|
|
33
|
+
is(type: Type): type is StringLiteral | NumericLiteral | BooleanLiteral;
|
|
34
|
+
/**
|
|
35
|
+
* Check if `type` is a string literal type.
|
|
36
|
+
*
|
|
37
|
+
* @param type The type to check.
|
|
38
|
+
*/
|
|
39
|
+
isString(type: Type): type is StringLiteral;
|
|
40
|
+
/**
|
|
41
|
+
* Check if `type` is a numeric literal type.
|
|
42
|
+
*
|
|
43
|
+
* @param type The type to check.
|
|
44
|
+
*/
|
|
45
|
+
isNumeric(type: Type): type is NumericLiteral;
|
|
46
|
+
/**
|
|
47
|
+
* Check if `type` is a boolean literal type.
|
|
48
|
+
*
|
|
49
|
+
* @param type The type to check.
|
|
50
|
+
*/
|
|
51
|
+
isBoolean(type: Type): type is BooleanLiteral;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
declare module "../define-kit.js" {
|
|
55
|
+
interface TypekitPrototype extends LiteralKit {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=literal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/literal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAGlG,UAAU,UAAU;IAClB,OAAO,EAAE;QACP;;;;WAIG;QACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,GAAG,cAAc,GAAG,cAAc,CAAC;QAE1F;;;;WAIG;QACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC;QAE3C;;;;WAIG;QACH,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC;QAE7C;;;;WAIG;QACH,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAAC;QAE9C;;;;WAIG;QACH,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,aAAa,GAAG,cAAc,GAAG,cAAc,CAAC;QAExE;;;;WAIG;QACH,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,aAAa,CAAC;QAE5C;;;;WAIG;QACH,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,cAAc,CAAC;QAE9C;;;;WAIG;QACH,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,cAAc,CAAC;KAC/C,CAAC;CACH;AAED,OAAO,QAAQ,kBAAkB,CAAC;IAChC,UAAU,gBAAiB,SAAQ,UAAU;KAAG;CACjD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Numeric } from "../../../core/numeric.js";
|
|
2
|
+
import { defineKit } from "../define-kit.js";
|
|
3
|
+
defineKit({
|
|
4
|
+
literal: {
|
|
5
|
+
create(value) {
|
|
6
|
+
if (typeof value === "string") {
|
|
7
|
+
return this.literal.createString(value);
|
|
8
|
+
}
|
|
9
|
+
else if (typeof value === "number") {
|
|
10
|
+
return this.literal.createNumeric(value);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return this.literal.createBoolean(value);
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
createString(value) {
|
|
17
|
+
return this.program.checker.createType({
|
|
18
|
+
kind: "String",
|
|
19
|
+
value,
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
createNumeric(value) {
|
|
23
|
+
const valueAsString = String(value);
|
|
24
|
+
return this.program.checker.createType({
|
|
25
|
+
kind: "Number",
|
|
26
|
+
value,
|
|
27
|
+
valueAsString,
|
|
28
|
+
numericValue: Numeric(valueAsString),
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
createBoolean(value) {
|
|
32
|
+
return this.program.checker.createType({
|
|
33
|
+
kind: "Boolean",
|
|
34
|
+
value,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
isBoolean(type) {
|
|
38
|
+
return type.kind === "Boolean";
|
|
39
|
+
},
|
|
40
|
+
isString(type) {
|
|
41
|
+
return type.kind === "String";
|
|
42
|
+
},
|
|
43
|
+
isNumeric(type) {
|
|
44
|
+
return type.kind === "Number";
|
|
45
|
+
},
|
|
46
|
+
is(type) {
|
|
47
|
+
return (this.literal.isBoolean(type) || this.literal.isNumeric(type) || this.literal.isString(type));
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=literal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/literal.ts"],"names":[],"mappings":"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