@typespec/html-program-viewer 0.63.0-dev.0 → 0.63.0
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/emitter/index.js +221 -278
- package/dist/manifest-BeToQ_PI.js +6 -0
- package/dist/react/index.js +992 -51
- package/package.json +6 -6
- package/dist/manifest-CoFoVY97.js +0 -6
package/dist/react/index.js
CHANGED
|
@@ -17820,7 +17820,7 @@ let manifest;
|
|
|
17820
17820
|
try {
|
|
17821
17821
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17822
17822
|
// @ts-ignore
|
|
17823
|
-
manifest = (await import('../manifest-
|
|
17823
|
+
manifest = (await import('../manifest-BeToQ_PI.js')).default;
|
|
17824
17824
|
}
|
|
17825
17825
|
catch {
|
|
17826
17826
|
const name = "../dist/manifest.js";
|
|
@@ -17861,6 +17861,87 @@ function isDefined(arg) {
|
|
|
17861
17861
|
function mutate(value) {
|
|
17862
17862
|
return value;
|
|
17863
17863
|
}
|
|
17864
|
+
function createRekeyableMap(entries) {
|
|
17865
|
+
return new RekeyableMapImpl(entries);
|
|
17866
|
+
}
|
|
17867
|
+
class RekeyableMapImpl {
|
|
17868
|
+
#keys = new Map();
|
|
17869
|
+
#values = new Map();
|
|
17870
|
+
constructor(entries) {
|
|
17871
|
+
if (entries) {
|
|
17872
|
+
for (const [key, value] of entries) {
|
|
17873
|
+
this.set(key, value);
|
|
17874
|
+
}
|
|
17875
|
+
}
|
|
17876
|
+
}
|
|
17877
|
+
clear() {
|
|
17878
|
+
this.#keys.clear();
|
|
17879
|
+
this.#values.clear();
|
|
17880
|
+
}
|
|
17881
|
+
delete(key) {
|
|
17882
|
+
const keyItem = this.#keys.get(key);
|
|
17883
|
+
if (keyItem) {
|
|
17884
|
+
this.#keys.delete(key);
|
|
17885
|
+
return this.#values.delete(keyItem);
|
|
17886
|
+
}
|
|
17887
|
+
return false;
|
|
17888
|
+
}
|
|
17889
|
+
forEach(callbackfn, thisArg) {
|
|
17890
|
+
this.#values.forEach((value, keyItem) => {
|
|
17891
|
+
callbackfn(value, keyItem.key, this);
|
|
17892
|
+
}, thisArg);
|
|
17893
|
+
}
|
|
17894
|
+
get(key) {
|
|
17895
|
+
const keyItem = this.#keys.get(key);
|
|
17896
|
+
return keyItem ? this.#values.get(keyItem) : undefined;
|
|
17897
|
+
}
|
|
17898
|
+
has(key) {
|
|
17899
|
+
return this.#keys.has(key);
|
|
17900
|
+
}
|
|
17901
|
+
set(key, value) {
|
|
17902
|
+
let keyItem = this.#keys.get(key);
|
|
17903
|
+
if (!keyItem) {
|
|
17904
|
+
keyItem = { key };
|
|
17905
|
+
this.#keys.set(key, keyItem);
|
|
17906
|
+
}
|
|
17907
|
+
this.#values.set(keyItem, value);
|
|
17908
|
+
return this;
|
|
17909
|
+
}
|
|
17910
|
+
get size() {
|
|
17911
|
+
return this.#values.size;
|
|
17912
|
+
}
|
|
17913
|
+
*entries() {
|
|
17914
|
+
for (const [k, v] of this.#values) {
|
|
17915
|
+
yield [k.key, v];
|
|
17916
|
+
}
|
|
17917
|
+
}
|
|
17918
|
+
*keys() {
|
|
17919
|
+
for (const k of this.#values.keys()) {
|
|
17920
|
+
yield k.key;
|
|
17921
|
+
}
|
|
17922
|
+
}
|
|
17923
|
+
values() {
|
|
17924
|
+
return this.#values.values();
|
|
17925
|
+
}
|
|
17926
|
+
[Symbol.iterator]() {
|
|
17927
|
+
return this.entries();
|
|
17928
|
+
}
|
|
17929
|
+
[Symbol.toStringTag] = "RekeyableMap";
|
|
17930
|
+
rekey(existingKey, newKey) {
|
|
17931
|
+
const keyItem = this.#keys.get(existingKey);
|
|
17932
|
+
if (!keyItem) {
|
|
17933
|
+
return false;
|
|
17934
|
+
}
|
|
17935
|
+
this.#keys.delete(existingKey);
|
|
17936
|
+
const newKeyItem = this.#keys.get(newKey);
|
|
17937
|
+
if (newKeyItem) {
|
|
17938
|
+
this.#values.delete(newKeyItem);
|
|
17939
|
+
}
|
|
17940
|
+
keyItem.key = newKey;
|
|
17941
|
+
this.#keys.set(newKey, keyItem);
|
|
17942
|
+
return true;
|
|
17943
|
+
}
|
|
17944
|
+
}
|
|
17864
17945
|
|
|
17865
17946
|
/**
|
|
17866
17947
|
* Create a new diagnostics creator.
|
|
@@ -18065,12 +18146,6 @@ const diagnostics = {
|
|
|
18065
18146
|
typeofTarget: "Typeof expects a value literal or value reference.",
|
|
18066
18147
|
},
|
|
18067
18148
|
},
|
|
18068
|
-
"trailing-token": {
|
|
18069
|
-
severity: "error",
|
|
18070
|
-
messages: {
|
|
18071
|
-
default: paramMessage `Trailing ${"token"}`,
|
|
18072
|
-
},
|
|
18073
|
-
},
|
|
18074
18149
|
"unknown-directive": {
|
|
18075
18150
|
severity: "error",
|
|
18076
18151
|
messages: {
|
|
@@ -18689,6 +18764,12 @@ const diagnostics = {
|
|
|
18689
18764
|
/**
|
|
18690
18765
|
* Decorator
|
|
18691
18766
|
*/
|
|
18767
|
+
"invalid-pattern-regex": {
|
|
18768
|
+
severity: "warning",
|
|
18769
|
+
messages: {
|
|
18770
|
+
default: "@pattern decorator expects a valid regular expression pattern.",
|
|
18771
|
+
},
|
|
18772
|
+
},
|
|
18692
18773
|
"decorator-wrong-target": {
|
|
18693
18774
|
severity: "error",
|
|
18694
18775
|
messages: {
|
|
@@ -18914,6 +18995,26 @@ const diagnostics = {
|
|
|
18914
18995
|
default: "Conflict marker encountered.",
|
|
18915
18996
|
},
|
|
18916
18997
|
},
|
|
18998
|
+
// #region Visibility
|
|
18999
|
+
"visibility-sealed": {
|
|
19000
|
+
severity: "error",
|
|
19001
|
+
messages: {
|
|
19002
|
+
default: paramMessage `Visibility of property '${"propName"}' is sealed and cannot be changed.`,
|
|
19003
|
+
},
|
|
19004
|
+
},
|
|
19005
|
+
"visibility-mixed-legacy": {
|
|
19006
|
+
severity: "error",
|
|
19007
|
+
messages: {
|
|
19008
|
+
default: "Cannot apply both string (legacy) visibility modifiers and enum-based visibility modifiers to a property.",
|
|
19009
|
+
},
|
|
19010
|
+
},
|
|
19011
|
+
"default-visibility-not-member": {
|
|
19012
|
+
severity: "error",
|
|
19013
|
+
messages: {
|
|
19014
|
+
default: "The default visibility modifiers of a class must be members of the class enum.",
|
|
19015
|
+
},
|
|
19016
|
+
},
|
|
19017
|
+
// #endregion
|
|
18917
19018
|
// #region CLI
|
|
18918
19019
|
"no-compatible-vs-installed": {
|
|
18919
19020
|
severity: "error",
|
|
@@ -22671,8 +22772,7 @@ function serialize (cmpts, opts) {
|
|
|
22671
22772
|
}
|
|
22672
22773
|
|
|
22673
22774
|
if (options.reference !== 'suffix' && components.scheme) {
|
|
22674
|
-
uriTokens.push(components.scheme);
|
|
22675
|
-
uriTokens.push(':');
|
|
22775
|
+
uriTokens.push(components.scheme, ':');
|
|
22676
22776
|
}
|
|
22677
22777
|
|
|
22678
22778
|
const authority = recomposeAuthority(components, options);
|
|
@@ -22702,13 +22802,11 @@ function serialize (cmpts, opts) {
|
|
|
22702
22802
|
}
|
|
22703
22803
|
|
|
22704
22804
|
if (components.query !== undefined) {
|
|
22705
|
-
uriTokens.push('?');
|
|
22706
|
-
uriTokens.push(components.query);
|
|
22805
|
+
uriTokens.push('?', components.query);
|
|
22707
22806
|
}
|
|
22708
22807
|
|
|
22709
22808
|
if (components.fragment !== undefined) {
|
|
22710
|
-
uriTokens.push('#');
|
|
22711
|
-
uriTokens.push(components.fragment);
|
|
22809
|
+
uriTokens.push('#', components.fragment);
|
|
22712
22810
|
}
|
|
22713
22811
|
return uriTokens.join('')
|
|
22714
22812
|
}
|
|
@@ -22806,9 +22904,6 @@ function parse$2 (uri, opts) {
|
|
|
22806
22904
|
if (gotEncoding && parsed.scheme !== undefined) {
|
|
22807
22905
|
parsed.scheme = unescape(parsed.scheme);
|
|
22808
22906
|
}
|
|
22809
|
-
if (gotEncoding && parsed.userinfo !== undefined) {
|
|
22810
|
-
parsed.userinfo = unescape(parsed.userinfo);
|
|
22811
|
-
}
|
|
22812
22907
|
if (gotEncoding && parsed.host !== undefined) {
|
|
22813
22908
|
parsed.host = unescape(parsed.host);
|
|
22814
22909
|
}
|
|
@@ -27603,6 +27698,14 @@ function compilerAssert(condition, message, target) {
|
|
|
27603
27698
|
}
|
|
27604
27699
|
throw new Error(message);
|
|
27605
27700
|
}
|
|
27701
|
+
/**
|
|
27702
|
+
* Ignore the diagnostics emitted by the diagnostic accessor pattern and just return the actual result.
|
|
27703
|
+
* @param result Accessor pattern tuple result including the actual result and the list of diagnostics.
|
|
27704
|
+
* @returns Actual result.
|
|
27705
|
+
*/
|
|
27706
|
+
function ignoreDiagnostics(result) {
|
|
27707
|
+
return result[0];
|
|
27708
|
+
}
|
|
27606
27709
|
|
|
27607
27710
|
function absolutePathStatus(path) {
|
|
27608
27711
|
if (path.startsWith(".") || !isPathAbsolute(path)) {
|
|
@@ -27831,22 +27934,22 @@ createJSONSchemaValidator(TypeSpecConfigJsonSchema);
|
|
|
27831
27934
|
|
|
27832
27935
|
// Contains all intrinsic data setter or getter
|
|
27833
27936
|
// Anything that the TypeSpec check might should be here.
|
|
27834
|
-
function createStateSymbol(name) {
|
|
27937
|
+
function createStateSymbol$1(name) {
|
|
27835
27938
|
return Symbol.for(`TypeSpec.${name}`);
|
|
27836
27939
|
}
|
|
27837
27940
|
const stateKeys = {
|
|
27838
|
-
minValues: createStateSymbol("minValues"),
|
|
27839
|
-
maxValues: createStateSymbol("maxValues"),
|
|
27840
|
-
minValueExclusive: createStateSymbol("minValueExclusive"),
|
|
27841
|
-
maxValueExclusive: createStateSymbol("maxValueExclusive"),
|
|
27842
|
-
minLength: createStateSymbol("minLengthValues"),
|
|
27843
|
-
maxLength: createStateSymbol("maxLengthValues"),
|
|
27844
|
-
minItems: createStateSymbol("minItems"),
|
|
27845
|
-
maxItems: createStateSymbol("maxItems"),
|
|
27846
|
-
docs: createStateSymbol("docs"),
|
|
27847
|
-
returnDocs: createStateSymbol("returnsDocs"),
|
|
27848
|
-
errorsDocs: createStateSymbol("errorDocs"),
|
|
27849
|
-
discriminator: createStateSymbol("discriminator"),
|
|
27941
|
+
minValues: createStateSymbol$1("minValues"),
|
|
27942
|
+
maxValues: createStateSymbol$1("maxValues"),
|
|
27943
|
+
minValueExclusive: createStateSymbol$1("minValueExclusive"),
|
|
27944
|
+
maxValueExclusive: createStateSymbol$1("maxValueExclusive"),
|
|
27945
|
+
minLength: createStateSymbol$1("minLengthValues"),
|
|
27946
|
+
maxLength: createStateSymbol$1("maxLengthValues"),
|
|
27947
|
+
minItems: createStateSymbol$1("minItems"),
|
|
27948
|
+
maxItems: createStateSymbol$1("maxItems"),
|
|
27949
|
+
docs: createStateSymbol$1("docs"),
|
|
27950
|
+
returnDocs: createStateSymbol$1("returnsDocs"),
|
|
27951
|
+
errorsDocs: createStateSymbol$1("errorDocs"),
|
|
27952
|
+
discriminator: createStateSymbol$1("discriminator"),
|
|
27850
27953
|
};
|
|
27851
27954
|
function getDocKey(target) {
|
|
27852
27955
|
switch (target) {
|
|
@@ -28904,7 +29007,6 @@ var ListKind;
|
|
|
28904
29007
|
const PropertiesBase = {
|
|
28905
29008
|
allowEmpty: true,
|
|
28906
29009
|
toleratedDelimiterIsValid: true,
|
|
28907
|
-
trailingDelimiterIsValid: true,
|
|
28908
29010
|
allowedStatementKeyword: Token.None,
|
|
28909
29011
|
};
|
|
28910
29012
|
ListKind.OperationParameters = {
|
|
@@ -28970,7 +29072,6 @@ var ListKind;
|
|
|
28970
29072
|
delimiter: Token.Comma,
|
|
28971
29073
|
toleratedDelimiter: Token.Semicolon,
|
|
28972
29074
|
toleratedDelimiterIsValid: false,
|
|
28973
|
-
trailingDelimiterIsValid: false,
|
|
28974
29075
|
invalidAnnotationTarget: "expression",
|
|
28975
29076
|
allowedStatementKeyword: Token.None,
|
|
28976
29077
|
};
|
|
@@ -29508,6 +29609,10 @@ var ResolutionKind;
|
|
|
29508
29609
|
ResolutionKind[ResolutionKind["Constraint"] = 3] = "Constraint";
|
|
29509
29610
|
})(ResolutionKind || (ResolutionKind = {}));
|
|
29510
29611
|
|
|
29612
|
+
function isIntrinsicType(program, type, kind) {
|
|
29613
|
+
return ignoreDiagnostics(program.checker.isTypeAssignableTo(type.projectionBase ?? type, program.checker.getStdType(kind), type));
|
|
29614
|
+
}
|
|
29615
|
+
|
|
29511
29616
|
var yu=Object.create;var He=Object.defineProperty;var Au=Object.getOwnPropertyDescriptor;var Bu=Object.getOwnPropertyNames;var wu=Object.getPrototypeOf,xu=Object.prototype.hasOwnProperty;var sr=e=>{throw TypeError(e)};var _u=(e,t)=>()=>(e&&(t=e(e=0)),t);var At=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),We=(e,t)=>{for(var r in t)He(e,r,{get:t[r],enumerable:!0});},ar=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bu(t))!xu.call(e,o)&&o!==r&&He(e,o,{get:()=>t[o],enumerable:!(n=Au(t,o))||n.enumerable});return e};var Me=(e,t,r)=>(r=e!=null?yu(wu(e)):{},ar(He(r,"default",{value:e,enumerable:!0}),e)),vu=e=>ar(He({},"__esModule",{value:!0}),e);var bu=(e,t,r)=>t.has(e)||sr("Cannot "+r);var Dr=(e,t,r)=>t.has(e)?sr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r);var pe=(e,t,r)=>(bu(e,t,"access private method"),r);var it=At((ia,sn)=>{var on=new Proxy(String,{get:()=>on});sn.exports=on;});var Tn={};We(Tn,{default:()=>_o,shouldHighlight:()=>xo});var xo,_o,kn=_u(()=>{xo=()=>!1,_o=String;});var Pn=At((bD,Xt)=>{var g=String,Ln=function(){return {isColorSupported:!1,reset:g,bold:g,dim:g,italic:g,underline:g,inverse:g,hidden:g,strikethrough:g,black:g,red:g,green:g,yellow:g,blue:g,magenta:g,cyan:g,white:g,gray:g,bgBlack:g,bgRed:g,bgGreen:g,bgYellow:g,bgBlue:g,bgMagenta:g,bgCyan:g,bgWhite:g}};Xt.exports=Ln();Xt.exports.createColors=Ln;});var $n=At(Ct=>{Object.defineProperty(Ct,"__esModule",{value:!0});Ct.codeFrameColumns=Mn;Ct.default=To;var In=(kn(),vu(Tn)),Hn=vo(Pn(),!0);function Wn(e){if(typeof WeakMap!="function")return null;var t=new WeakMap,r=new WeakMap;return (Wn=function(n){return n?r:t})(e)}function vo(e,t){if(e===null||typeof e!="object"&&typeof e!="function")return {default:e};var r=Wn(t);if(r&&r.has(e))return r.get(e);var n={__proto__:null},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if(u!=="default"&&{}.hasOwnProperty.call(e,u)){var i=o?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,r&&r.set(e,n),n}var bo=Hn.default,Rn=(e,t)=>r=>e(t(r)),Zt;function Oo(e){if(e){return (Zt)!=null||(Zt=(0, Hn.createColors)(!0)),Zt}return bo}var Yn=!1;function So(e){return {gutter:e.gray,marker:Rn(e.red,e.bold),message:Rn(e.red,e.bold)}}var jn=/\r\n|[\n\r\u2028\u2029]/;function No(e,t,r){let n=Object.assign({column:0,line:-1},e.start),o=Object.assign({},n,e.end),{linesAbove:u=2,linesBelow:i=3}=r||{},s=n.line,a=n.column,D=o.line,l=o.column,d=Math.max(s-(u+1),0),f=Math.min(t.length,D+i);s===-1&&(d=0),D===-1&&(f=t.length);let p=D-s,c={};if(p)for(let F=0;F<=p;F++){let m=F+s;if(!a)c[m]=!0;else if(F===0){let E=t[m-1].length;c[m]=[a,E-a+1];}else if(F===p)c[m]=[0,l];else {let E=t[m-F].length;c[m]=[0,E];}}else a===l?a?c[s]=[a,0]:c[s]=!0:c[s]=[a,l-a];return {start:d,end:f,markerLines:c}}function Mn(e,t,r={}){let n=(r.highlightCode||r.forceColor)&&(0, In.shouldHighlight)(r),o=Oo(r.forceColor),u=So(o),i=(F,m)=>n?F(m):m,s=e.split(jn),{start:a,end:D,markerLines:l}=No(t,s,r),d=t.start&&typeof t.start.column=="number",f=String(D).length,c=(n?(0, In.default)(e,r):e).split(jn,D).slice(a,D).map((F,m)=>{let E=a+1+m,w=` ${` ${E}`.slice(-f)} |`,h=l[E],C=!l[E+1];if(h){let k="";if(Array.isArray(h)){let v=F.slice(0,Math.max(h[0]-1,0)).replace(/[^\t]/g," "),$=h[1]||1;k=[`
|
|
29512
29617
|
`,i(u.gutter,w.replace(/\d/g," "))," ",v,i(u.marker,"^").repeat($)].join(""),C&&r.message&&(k+=" "+i(u.message,r.message));}return [i(u.marker,">"),i(u.gutter,w),F.length>0?` ${F}`:"",k].join("")}else return ` ${i(u.gutter,w)}${F.length>0?` ${F}`:""}`}).join(`
|
|
29513
29618
|
`);return r.message&&!d&&(c=`${" ".repeat(f+1)}${r.message}
|
|
@@ -30820,24 +30925,798 @@ new Set([
|
|
|
30820
30925
|
"intrinsic",
|
|
30821
30926
|
]);
|
|
30822
30927
|
|
|
30823
|
-
|
|
30824
|
-
/**
|
|
30928
|
+
var _a$1;
|
|
30929
|
+
/**
|
|
30930
|
+
* A Realm's view of a Program's state map for a given state key.
|
|
30931
|
+
*
|
|
30932
|
+
* For all operations, if a type was created within the realm, the realm's own state map is used. Otherwise, the owning'
|
|
30933
|
+
* Program's state map is used.
|
|
30934
|
+
*
|
|
30935
|
+
* @experimental
|
|
30936
|
+
*/
|
|
30937
|
+
class StateMapRealmView {
|
|
30938
|
+
#realm;
|
|
30939
|
+
#parentState;
|
|
30940
|
+
#realmState;
|
|
30941
|
+
constructor(realm, realmState, parentState) {
|
|
30942
|
+
this.#realm = realm;
|
|
30943
|
+
this.#parentState = parentState;
|
|
30944
|
+
this.#realmState = realmState;
|
|
30945
|
+
}
|
|
30946
|
+
has(t) {
|
|
30947
|
+
return this.#select(t).has(t) ?? false;
|
|
30948
|
+
}
|
|
30949
|
+
set(t, v) {
|
|
30950
|
+
this.#select(t).set(t, v);
|
|
30951
|
+
return this;
|
|
30952
|
+
}
|
|
30953
|
+
get(t) {
|
|
30954
|
+
return this.#select(t).get(t);
|
|
30955
|
+
}
|
|
30956
|
+
delete(t) {
|
|
30957
|
+
return this.#select(t).delete(t);
|
|
30958
|
+
}
|
|
30959
|
+
forEach(cb, thisArg) {
|
|
30960
|
+
for (const item of this.entries()) {
|
|
30961
|
+
cb.call(thisArg, item[1], item[0], this);
|
|
30962
|
+
}
|
|
30963
|
+
return this;
|
|
30964
|
+
}
|
|
30965
|
+
get size() {
|
|
30966
|
+
return this.#realmState.size + this.#parentState.size;
|
|
30967
|
+
}
|
|
30968
|
+
clear() {
|
|
30969
|
+
this.#realmState.clear();
|
|
30970
|
+
}
|
|
30971
|
+
*entries() {
|
|
30972
|
+
for (const item of this.#realmState) {
|
|
30973
|
+
yield item;
|
|
30974
|
+
}
|
|
30975
|
+
for (const item of this.#parentState) {
|
|
30976
|
+
yield item;
|
|
30977
|
+
}
|
|
30978
|
+
return undefined;
|
|
30979
|
+
}
|
|
30980
|
+
*values() {
|
|
30981
|
+
for (const item of this.entries()) {
|
|
30982
|
+
yield item[1];
|
|
30983
|
+
}
|
|
30984
|
+
return undefined;
|
|
30985
|
+
}
|
|
30986
|
+
*keys() {
|
|
30987
|
+
for (const item of this.entries()) {
|
|
30988
|
+
yield item[0];
|
|
30989
|
+
}
|
|
30990
|
+
return undefined;
|
|
30991
|
+
}
|
|
30992
|
+
[Symbol.iterator]() {
|
|
30993
|
+
return this.entries();
|
|
30994
|
+
}
|
|
30995
|
+
[Symbol.toStringTag] = "StateMap";
|
|
30996
|
+
#select(keyType) {
|
|
30997
|
+
if (this.#realm.hasType(keyType)) {
|
|
30998
|
+
return this.#realmState;
|
|
30999
|
+
}
|
|
31000
|
+
return this.#parentState;
|
|
31001
|
+
}
|
|
31002
|
+
}
|
|
31003
|
+
/**
|
|
31004
|
+
* A Realm is an alternate view of a Program where types can be cloned, deleted, and modified without affecting the
|
|
31005
|
+
* original types in the Program.
|
|
31006
|
+
*
|
|
31007
|
+
* The realm stores the types that exist within the realm, views of state maps that only apply within the realm,
|
|
31008
|
+
* and a view of types that have been removed from the realm's view.
|
|
31009
|
+
*
|
|
31010
|
+
* @experimental
|
|
31011
|
+
*/
|
|
31012
|
+
class Realm {
|
|
31013
|
+
#program;
|
|
31014
|
+
/**
|
|
31015
|
+
* Stores all types owned by this realm.
|
|
31016
|
+
*/
|
|
31017
|
+
#types = new Set();
|
|
31018
|
+
/**
|
|
31019
|
+
* Stores types that are deleted in this realm. When a realm is active and doing a traversal, you will
|
|
31020
|
+
* not find this type in e.g. collections. Deleted types are mapped to `null` if you ask for it.
|
|
31021
|
+
*/
|
|
31022
|
+
#deletedTypes = new WeakSet();
|
|
31023
|
+
#stateMaps = new Map();
|
|
31024
|
+
key;
|
|
31025
|
+
/**
|
|
31026
|
+
* Create a new realm in the given program.
|
|
31027
|
+
*
|
|
31028
|
+
* @param program - The program to create the realm in.
|
|
31029
|
+
* @param description - A short description of the realm's purpose.
|
|
31030
|
+
*/
|
|
31031
|
+
constructor(program, description) {
|
|
31032
|
+
this.key = Symbol(description);
|
|
31033
|
+
this.#program = program;
|
|
31034
|
+
_a$1.#knownRealms.set(this.key, this);
|
|
31035
|
+
}
|
|
31036
|
+
#_typekit;
|
|
31037
|
+
/**
|
|
31038
|
+
* The typekit instance bound to this realm.
|
|
31039
|
+
*
|
|
31040
|
+
* If the realm does not already have a typekit associated with it, one will be created and bound to this realm.
|
|
31041
|
+
*/
|
|
31042
|
+
get typekit() {
|
|
31043
|
+
return (this.#_typekit ??= createTypekit(this));
|
|
31044
|
+
}
|
|
31045
|
+
/**
|
|
31046
|
+
* The program that this realm is associated with.
|
|
31047
|
+
*/
|
|
31048
|
+
get program() {
|
|
31049
|
+
return this.#program;
|
|
31050
|
+
}
|
|
31051
|
+
/**
|
|
31052
|
+
* Gets a state map for the given state key symbol.
|
|
31053
|
+
*
|
|
31054
|
+
* This state map is a view of the program's state map for the given state key, with modifications made to the realm's
|
|
31055
|
+
* own state.
|
|
31056
|
+
*
|
|
31057
|
+
* @param stateKey - The symbol to use as the state key.
|
|
31058
|
+
* @returns The realm's state map for the given state key.
|
|
31059
|
+
*/
|
|
31060
|
+
stateMap(stateKey) {
|
|
31061
|
+
let m = this.#stateMaps.get(stateKey);
|
|
31062
|
+
if (!m) {
|
|
31063
|
+
m = new Map();
|
|
31064
|
+
this.#stateMaps.set(stateKey, m);
|
|
31065
|
+
}
|
|
31066
|
+
return new StateMapRealmView(this, m, this.#program.stateMap(stateKey));
|
|
31067
|
+
}
|
|
31068
|
+
/**
|
|
31069
|
+
* Clones a type and adds it to the realm. This operation will use the realm's typekit to clone the type.
|
|
31070
|
+
*
|
|
31071
|
+
* @param type - The type to clone.
|
|
31072
|
+
* @returns A clone of the input type that exists within this realm.
|
|
31073
|
+
*/
|
|
31074
|
+
clone(type) {
|
|
31075
|
+
compilerAssert(type, "Undefined type passed to clone");
|
|
31076
|
+
const clone = this.#cloneIntoRealm(type);
|
|
31077
|
+
this.typekit.type.finishType(clone);
|
|
31078
|
+
return clone;
|
|
31079
|
+
}
|
|
31080
|
+
/**
|
|
31081
|
+
* Removes a type from this realm. This operation will not affect the type in the program, only this realm's view
|
|
31082
|
+
* of the type.
|
|
31083
|
+
*
|
|
31084
|
+
* @param type - The TypeSpec type to remove from this realm.
|
|
31085
|
+
*/
|
|
31086
|
+
remove(type) {
|
|
31087
|
+
this.#deletedTypes.add(type);
|
|
31088
|
+
}
|
|
31089
|
+
/**
|
|
31090
|
+
* Determines whether or not this realm contains a given type.
|
|
31091
|
+
*
|
|
31092
|
+
* @param type - The type to check.
|
|
31093
|
+
* @returns true if the type was created within this realm or added to this realm, false otherwise.
|
|
31094
|
+
*/
|
|
31095
|
+
hasType(type) {
|
|
31096
|
+
return this.#types.has(type);
|
|
31097
|
+
}
|
|
31098
|
+
/**
|
|
31099
|
+
* Adds a type to this realm. Once a type is added to the realm, the realm considers it part of itself.
|
|
31100
|
+
*
|
|
31101
|
+
* A type can be present in multiple realms, but `Realm.realmForType` will only return the last realm that the type
|
|
31102
|
+
* was added to.
|
|
31103
|
+
*
|
|
31104
|
+
* @param type - The type to add to this realm.
|
|
31105
|
+
*/
|
|
31106
|
+
addType(type) {
|
|
31107
|
+
this.#types.add(type);
|
|
31108
|
+
_a$1.realmForType.set(type, this);
|
|
31109
|
+
}
|
|
31110
|
+
#cloneIntoRealm(type) {
|
|
31111
|
+
const clone = this.typekit.type.clone(type);
|
|
31112
|
+
this.#types.add(clone);
|
|
31113
|
+
_a$1.realmForType.set(clone, this);
|
|
31114
|
+
return clone;
|
|
31115
|
+
}
|
|
31116
|
+
static #knownRealms = new Map();
|
|
31117
|
+
static realmForKey(key, parentRealm) {
|
|
31118
|
+
return this.#knownRealms.get(key);
|
|
31119
|
+
}
|
|
31120
|
+
static realmForType = new WeakMap();
|
|
31121
|
+
}
|
|
31122
|
+
_a$1 = Realm;
|
|
31123
|
+
|
|
31124
|
+
/**
|
|
31125
|
+
* The prototype object for Typekit instances.
|
|
31126
|
+
*
|
|
31127
|
+
* @see {@link defineKit}
|
|
31128
|
+
*
|
|
31129
|
+
* @experimental
|
|
31130
|
+
* @internal
|
|
31131
|
+
*/
|
|
30825
31132
|
const TypekitPrototype = {};
|
|
31133
|
+
/**
|
|
31134
|
+
* Defines an extension to the Typekit interface.
|
|
31135
|
+
*
|
|
31136
|
+
* All Typekit instances will inherit the functionality defined by calls to this function.
|
|
31137
|
+
*
|
|
31138
|
+
* @experimental
|
|
31139
|
+
*/
|
|
31140
|
+
function defineKit(source) {
|
|
31141
|
+
for (const [name, fnOrNs] of Object.entries(source)) {
|
|
31142
|
+
TypekitPrototype[name] = fnOrNs;
|
|
31143
|
+
}
|
|
31144
|
+
}
|
|
31145
|
+
|
|
31146
|
+
defineKit({
|
|
31147
|
+
literal: {
|
|
31148
|
+
create(value) {
|
|
31149
|
+
if (typeof value === "string") {
|
|
31150
|
+
return this.literal.createString(value);
|
|
31151
|
+
}
|
|
31152
|
+
else if (typeof value === "number") {
|
|
31153
|
+
return this.literal.createNumeric(value);
|
|
31154
|
+
}
|
|
31155
|
+
else {
|
|
31156
|
+
return this.literal.createBoolean(value);
|
|
31157
|
+
}
|
|
31158
|
+
},
|
|
31159
|
+
createString(value) {
|
|
31160
|
+
return this.program.checker.createType({
|
|
31161
|
+
kind: "String",
|
|
31162
|
+
value,
|
|
31163
|
+
});
|
|
31164
|
+
},
|
|
31165
|
+
createNumeric(value) {
|
|
31166
|
+
const valueAsString = String(value);
|
|
31167
|
+
return this.program.checker.createType({
|
|
31168
|
+
kind: "Number",
|
|
31169
|
+
value,
|
|
31170
|
+
valueAsString,
|
|
31171
|
+
numericValue: Numeric(valueAsString),
|
|
31172
|
+
});
|
|
31173
|
+
},
|
|
31174
|
+
createBoolean(value) {
|
|
31175
|
+
return this.program.checker.createType({
|
|
31176
|
+
kind: "Boolean",
|
|
31177
|
+
value,
|
|
31178
|
+
});
|
|
31179
|
+
},
|
|
31180
|
+
isBoolean(type) {
|
|
31181
|
+
return type.kind === "Boolean";
|
|
31182
|
+
},
|
|
31183
|
+
isString(type) {
|
|
31184
|
+
return type.kind === "String";
|
|
31185
|
+
},
|
|
31186
|
+
isNumeric(type) {
|
|
31187
|
+
return type.kind === "Number";
|
|
31188
|
+
},
|
|
31189
|
+
is(type) {
|
|
31190
|
+
return (this.literal.isBoolean(type) || this.literal.isNumeric(type) || this.literal.isString(type));
|
|
31191
|
+
},
|
|
31192
|
+
},
|
|
31193
|
+
});
|
|
31194
|
+
|
|
30826
31195
|
/** @experimental */
|
|
30827
|
-
function
|
|
30828
|
-
const
|
|
30829
|
-
|
|
30830
|
-
|
|
30831
|
-
|
|
31196
|
+
function unsafe_useStateMap(key) {
|
|
31197
|
+
const getter = (program, target) => program.stateMap(key).get(target);
|
|
31198
|
+
const setter = (program, target, value) => program.stateMap(key).set(target, value);
|
|
31199
|
+
const mapGetter = (program) => program.stateMap(key);
|
|
31200
|
+
return [getter, setter, mapGetter];
|
|
31201
|
+
}
|
|
31202
|
+
|
|
31203
|
+
function createStateSymbol(name) {
|
|
31204
|
+
return Symbol.for(`TypeSpec.${name}`);
|
|
31205
|
+
}
|
|
31206
|
+
function useStateMap(key) {
|
|
31207
|
+
return unsafe_useStateMap(typeof key === "string" ? createStateSymbol(key) : key);
|
|
31208
|
+
}
|
|
31209
|
+
|
|
31210
|
+
// Copyright (c) Microsoft Corporation
|
|
31211
|
+
// Licensed under the MIT license.
|
|
31212
|
+
// TypeSpec Visibility System
|
|
31213
|
+
// --------------------------
|
|
31214
|
+
// This module defines the core visibility system of the TypeSpec language. The
|
|
31215
|
+
// visibility system is used to decide when properties of a _conceptual resource_
|
|
31216
|
+
// are present. The system is based on the concept of _visibility classes_,
|
|
31217
|
+
// represented by TypeSpec enums. Each visibility class has a set of _visibility
|
|
31218
|
+
// modifiers_ that can be applied to a model property, each modifier represented
|
|
31219
|
+
// by a member of the visibility class enum.
|
|
31220
|
+
//
|
|
31221
|
+
// Each visibility class has a _default modifier set_ that is used when no
|
|
31222
|
+
// modifiers are specified for a property, and each property has an _active
|
|
31223
|
+
// modifier set_ that is used when analyzing the visibility of the property.
|
|
31224
|
+
//
|
|
31225
|
+
// Visibility can be _sealed_ for a program, property, or visibility class
|
|
31226
|
+
// within a property. Once visibility is sealed, it cannot be unsealed, and any
|
|
31227
|
+
// attempts to modify a sealed visibility will fail.
|
|
31228
|
+
/**
|
|
31229
|
+
* The global visibility store.
|
|
31230
|
+
*
|
|
31231
|
+
* This store is used to track the visibility modifiers
|
|
31232
|
+
*/
|
|
31233
|
+
const [getVisibilityStore, setVisibilityStore] = useStateMap("visibilityStore");
|
|
31234
|
+
/**
|
|
31235
|
+
* Returns the visibility modifiers for a given `property` within a `program`.
|
|
31236
|
+
*/
|
|
31237
|
+
function getOrInitializeVisibilityModifiers(program, property) {
|
|
31238
|
+
let visibilityModifiers = getVisibilityStore(program, property);
|
|
31239
|
+
if (!visibilityModifiers) {
|
|
31240
|
+
visibilityModifiers = new Map();
|
|
31241
|
+
setVisibilityStore(program, property, visibilityModifiers);
|
|
31242
|
+
}
|
|
31243
|
+
return visibilityModifiers;
|
|
31244
|
+
}
|
|
31245
|
+
/**
|
|
31246
|
+
* Returns the active visibility modifier set for a given `property` and `visibilityClass`.
|
|
31247
|
+
*
|
|
31248
|
+
* If no visibility modifiers have been set for the given `property` and `visibilityClass`, the function will use the
|
|
31249
|
+
* provided `defaultSet` to initialize the visibility modifiers.
|
|
31250
|
+
*
|
|
31251
|
+
* @param program - the program in which the property occurs
|
|
31252
|
+
* @param property - the property to get visibility modifiers for
|
|
31253
|
+
* @param visibilityClass - the visibility class to get visibility modifiers for
|
|
31254
|
+
* @param defaultSet - the default set to use if no set has been initialized
|
|
31255
|
+
* @returns the active visibility modifier set for the given property and visibility class
|
|
31256
|
+
*/
|
|
31257
|
+
function getOrInitializeActiveModifierSetForClass(program, property, visibilityClass, defaultSet) {
|
|
31258
|
+
const visibilityModifiers = getOrInitializeVisibilityModifiers(program, property);
|
|
31259
|
+
let visibilityModifierSet = visibilityModifiers.get(visibilityClass);
|
|
31260
|
+
if (!visibilityModifierSet) {
|
|
31261
|
+
visibilityModifierSet = defaultSet;
|
|
31262
|
+
visibilityModifiers.set(visibilityClass, visibilityModifierSet);
|
|
31263
|
+
}
|
|
31264
|
+
return visibilityModifierSet;
|
|
31265
|
+
}
|
|
31266
|
+
/**
|
|
31267
|
+
* Stores the default modifier set for a given visibility class.
|
|
31268
|
+
*/
|
|
31269
|
+
const [getDefaultModifiers, setDefaultModifiers] = useStateMap("defaultVisibilityModifiers");
|
|
31270
|
+
/**
|
|
31271
|
+
* Gets the default modifier set for a visibility class. If no default modifier set has been set, this function will
|
|
31272
|
+
* initialize the default modifier set to ALL the visibility class's members.
|
|
31273
|
+
*
|
|
31274
|
+
* @param program - the program in which the visibility class occurs
|
|
31275
|
+
* @param visibilityClass - the visibility class to get the default modifier set for
|
|
31276
|
+
* @returns the default modifier set for the visibility class
|
|
31277
|
+
*/
|
|
31278
|
+
function getDefaultModifierSetForClass(program, visibilityClass) {
|
|
31279
|
+
const cached = getDefaultModifiers(program, visibilityClass);
|
|
31280
|
+
if (cached)
|
|
31281
|
+
return cached;
|
|
31282
|
+
const defaultModifierSet = new Set(visibilityClass.members.values());
|
|
31283
|
+
setDefaultModifiers(program, visibilityClass, defaultModifierSet);
|
|
31284
|
+
return defaultModifierSet;
|
|
31285
|
+
}
|
|
31286
|
+
// #endregion
|
|
31287
|
+
// #region Visibility Analysis API
|
|
31288
|
+
/**
|
|
31289
|
+
* Returns the active visibility modifiers for a property in a given visibility class.
|
|
31290
|
+
*
|
|
31291
|
+
* This function is infallible. If the visibility modifiers for the given class have not been set explicitly, it will
|
|
31292
|
+
* return the default visibility modifiers for the class.
|
|
31293
|
+
*
|
|
31294
|
+
* @param program - the program in which the property occurs
|
|
31295
|
+
* @param property - the property to get visibility modifiers for
|
|
31296
|
+
* @param visibilityClass - the visibility class to get visibility modifiers for
|
|
31297
|
+
* @returns the set of active modifiers (enum members) for the property and visibility class
|
|
31298
|
+
*/
|
|
31299
|
+
function getVisibilityForClass(program, property, visibilityClass) {
|
|
31300
|
+
return getOrInitializeActiveModifierSetForClass(program, property, visibilityClass,
|
|
31301
|
+
/* defaultSet: */ getDefaultModifierSetForClass(program, visibilityClass));
|
|
31302
|
+
}
|
|
31303
|
+
// #endregion
|
|
31304
|
+
|
|
31305
|
+
/**
|
|
31306
|
+
* Flow control for mutators.
|
|
31307
|
+
*
|
|
31308
|
+
* When filtering types in a mutator, the filter function may return MutatorFlow flags to control how mutation should
|
|
31309
|
+
* proceed.
|
|
31310
|
+
*
|
|
31311
|
+
* @see {@link MutatorFilterFn}
|
|
31312
|
+
*
|
|
31313
|
+
* @experimental
|
|
31314
|
+
*/
|
|
31315
|
+
var MutatorFlow;
|
|
31316
|
+
(function (MutatorFlow) {
|
|
31317
|
+
/**
|
|
31318
|
+
* Mutate the type and recur, further mutating the type's children. This is the default behavior.
|
|
31319
|
+
*/
|
|
31320
|
+
MutatorFlow[MutatorFlow["MutateAndRecur"] = 0] = "MutateAndRecur";
|
|
31321
|
+
/**
|
|
31322
|
+
* If this flag is set, the type will not be mutated.
|
|
31323
|
+
*/
|
|
31324
|
+
MutatorFlow[MutatorFlow["DoNotMutate"] = 1] = "DoNotMutate";
|
|
31325
|
+
/**
|
|
31326
|
+
* If this flag is set, the mutator will not proceed recursively into the children of the type.
|
|
31327
|
+
*/
|
|
31328
|
+
MutatorFlow[MutatorFlow["DoNotRecur"] = 2] = "DoNotRecur";
|
|
31329
|
+
})(MutatorFlow || (MutatorFlow = {}));
|
|
31330
|
+
// #endregion
|
|
31331
|
+
|
|
31332
|
+
/**
|
|
31333
|
+
* Get the documentation string for the given type.
|
|
31334
|
+
* @param program Program
|
|
31335
|
+
* @param target Type
|
|
31336
|
+
* @returns Documentation value
|
|
31337
|
+
*/
|
|
31338
|
+
function getDoc(program, target) {
|
|
31339
|
+
return getDocDataInternal(program, target, "self")?.value;
|
|
31340
|
+
}
|
|
31341
|
+
// -- @format decorator ---------------------
|
|
31342
|
+
const [getFormat, setFormat] = useStateMap("format");
|
|
31343
|
+
const [getEncode, setEncodeData] = useStateMap("encode");
|
|
31344
|
+
|
|
31345
|
+
defineKit({
|
|
31346
|
+
modelProperty: {
|
|
31347
|
+
is(type) {
|
|
31348
|
+
return type.kind === "ModelProperty";
|
|
30832
31349
|
},
|
|
30833
|
-
|
|
31350
|
+
getEncoding(type) {
|
|
31351
|
+
return getEncode(this.program, type) ?? getEncode(this.program, type.type);
|
|
31352
|
+
},
|
|
31353
|
+
getFormat(type) {
|
|
31354
|
+
return getFormat(this.program, type) ?? getFormat(this.program, type.type);
|
|
31355
|
+
},
|
|
31356
|
+
getVisibilityForClass(property, visibilityClass) {
|
|
31357
|
+
return getVisibilityForClass(this.program, property, visibilityClass);
|
|
31358
|
+
},
|
|
31359
|
+
},
|
|
31360
|
+
});
|
|
31361
|
+
|
|
31362
|
+
/**
|
|
31363
|
+
* Creates a shallow copy of a rekeyable map.
|
|
31364
|
+
*
|
|
31365
|
+
* @experimental
|
|
31366
|
+
*/
|
|
31367
|
+
function copyMap(map) {
|
|
31368
|
+
return createRekeyableMap(map.entries());
|
|
31369
|
+
}
|
|
31370
|
+
/**
|
|
31371
|
+
* Utility function for converting a list of decorators and arguments into structure decorator applications that are
|
|
31372
|
+
* compatible with the TypeSpec type graph.
|
|
31373
|
+
*
|
|
31374
|
+
* Note: Not all JavaScript values can be converted faithfully to TypeSpec values. This function will attempt to convert
|
|
31375
|
+
* the value to a literal TypeSpec value if it is a primitive value, otherwise it will be left as a JavaScript value.
|
|
31376
|
+
* The `jsValue` property of the argument will always contain the original JavaScript value passed to the decorator.
|
|
31377
|
+
*
|
|
31378
|
+
* @param typekit - The Typekit instance to use for creating types and values.
|
|
31379
|
+
* @param decorators - The list of decorators and arguments to apply.
|
|
31380
|
+
*
|
|
31381
|
+
* @see {@link DecoratorArgs}
|
|
31382
|
+
*
|
|
31383
|
+
* @experimental
|
|
31384
|
+
*/
|
|
31385
|
+
function decoratorApplication(typekit, decorators) {
|
|
31386
|
+
return (decorators?.map((arg) => {
|
|
31387
|
+
const [decorator, args] = Array.isArray(arg) ? [arg[0], arg.slice(1)] : [arg, []];
|
|
31388
|
+
return {
|
|
31389
|
+
decorator,
|
|
31390
|
+
args: args.map((rawValue) => ({
|
|
31391
|
+
value: typeof rawValue === "object" && rawValue !== null
|
|
31392
|
+
? rawValue
|
|
31393
|
+
: typekit.literal.create(rawValue),
|
|
31394
|
+
jsValue: rawValue,
|
|
31395
|
+
})),
|
|
31396
|
+
};
|
|
31397
|
+
}) ?? []);
|
|
31398
|
+
}
|
|
31399
|
+
|
|
31400
|
+
defineKit({
|
|
31401
|
+
model: {
|
|
31402
|
+
create(desc) {
|
|
31403
|
+
const properties = createRekeyableMap(Array.from(Object.entries(desc.properties)));
|
|
31404
|
+
const model = this.program.checker.createType({
|
|
31405
|
+
kind: "Model",
|
|
31406
|
+
name: desc.name ?? "",
|
|
31407
|
+
decorators: decoratorApplication(this, desc.decorators),
|
|
31408
|
+
properties: properties,
|
|
31409
|
+
expression: desc.name === undefined,
|
|
31410
|
+
node: undefined,
|
|
31411
|
+
derivedModels: desc.derivedModels ?? [],
|
|
31412
|
+
sourceModels: desc.sourceModels ?? [],
|
|
31413
|
+
});
|
|
31414
|
+
this.program.checker.finishType(model);
|
|
31415
|
+
return model;
|
|
31416
|
+
},
|
|
31417
|
+
is(type) {
|
|
31418
|
+
return type.kind === "Model";
|
|
31419
|
+
},
|
|
31420
|
+
},
|
|
31421
|
+
});
|
|
31422
|
+
|
|
31423
|
+
defineKit({
|
|
31424
|
+
scalar: {
|
|
31425
|
+
is(type) {
|
|
31426
|
+
return type.kind === "Scalar";
|
|
31427
|
+
},
|
|
31428
|
+
extendsBoolean: extendsStdType("boolean"),
|
|
31429
|
+
extendsBytes: extendsStdType("bytes"),
|
|
31430
|
+
extendsDecimal: extendsStdType("decimal"),
|
|
31431
|
+
extendsDecimal128: extendsStdType("decimal128"),
|
|
31432
|
+
extendsDuration: extendsStdType("duration"),
|
|
31433
|
+
extendsFloat: extendsStdType("float"),
|
|
31434
|
+
extendsFloat32: extendsStdType("float32"),
|
|
31435
|
+
extendsFloat64: extendsStdType("float64"),
|
|
31436
|
+
extendsInt8: extendsStdType("int8"),
|
|
31437
|
+
extendsInt16: extendsStdType("int16"),
|
|
31438
|
+
extendsInt32: extendsStdType("int32"),
|
|
31439
|
+
extendsInt64: extendsStdType("int64"),
|
|
31440
|
+
extendsInteger: extendsStdType("integer"),
|
|
31441
|
+
extendsNumeric: extendsStdType("numeric"),
|
|
31442
|
+
extendsOffsetDateTime: extendsStdType("offsetDateTime"),
|
|
31443
|
+
extendsPlainDate: extendsStdType("plainDate"),
|
|
31444
|
+
extendsPlainTime: extendsStdType("plainTime"),
|
|
31445
|
+
extendsSafeint: extendsStdType("safeint"),
|
|
31446
|
+
extendsString: extendsStdType("string"),
|
|
31447
|
+
extendsUint8: extendsStdType("uint8"),
|
|
31448
|
+
extendsUint16: extendsStdType("uint16"),
|
|
31449
|
+
extendsUint32: extendsStdType("uint32"),
|
|
31450
|
+
extendsUint64: extendsStdType("uint64"),
|
|
31451
|
+
extendsUrl: extendsStdType("url"),
|
|
31452
|
+
extendsUtcDateTime: extendsStdType("utcDateTime"),
|
|
31453
|
+
isBoolean: isStdType("boolean"),
|
|
31454
|
+
isBytes: isStdType("bytes"),
|
|
31455
|
+
isDecimal: isStdType("decimal"),
|
|
31456
|
+
isDecimal128: isStdType("decimal128"),
|
|
31457
|
+
isDuration: isStdType("duration"),
|
|
31458
|
+
isFloat: isStdType("float"),
|
|
31459
|
+
isFloat32: isStdType("float32"),
|
|
31460
|
+
isFloat64: isStdType("float64"),
|
|
31461
|
+
isInt8: isStdType("int8"),
|
|
31462
|
+
isInt16: isStdType("int16"),
|
|
31463
|
+
isInt32: isStdType("int32"),
|
|
31464
|
+
isInt64: isStdType("int64"),
|
|
31465
|
+
isInteger: isStdType("integer"),
|
|
31466
|
+
isNumeric: isStdType("numeric"),
|
|
31467
|
+
isOffsetDateTime: isStdType("offsetDateTime"),
|
|
31468
|
+
isPlainDate: isStdType("plainDate"),
|
|
31469
|
+
isPlainTime: isStdType("plainTime"),
|
|
31470
|
+
isSafeint: isStdType("safeint"),
|
|
31471
|
+
isString: isStdType("string"),
|
|
31472
|
+
isUint8: isStdType("uint8"),
|
|
31473
|
+
isUint16: isStdType("uint16"),
|
|
31474
|
+
isUint32: isStdType("uint32"),
|
|
31475
|
+
isUint64: isStdType("uint64"),
|
|
31476
|
+
isUrl: isStdType("url"),
|
|
31477
|
+
isUtcDateTime: isStdType("utcDateTime"),
|
|
31478
|
+
getStdBase(type) {
|
|
31479
|
+
const tspNamespace = this.program.resolveTypeReference("TypeSpec")[0];
|
|
31480
|
+
let current = type;
|
|
31481
|
+
while (current) {
|
|
31482
|
+
if (current.namespace === tspNamespace) {
|
|
31483
|
+
return current;
|
|
31484
|
+
}
|
|
31485
|
+
current = current.baseScalar;
|
|
31486
|
+
}
|
|
31487
|
+
return null;
|
|
31488
|
+
},
|
|
31489
|
+
getEncoding(type) {
|
|
31490
|
+
return getEncode(this.program, type);
|
|
31491
|
+
},
|
|
31492
|
+
getFormat(type) {
|
|
31493
|
+
return getFormat(this.program, type);
|
|
31494
|
+
},
|
|
31495
|
+
},
|
|
31496
|
+
});
|
|
31497
|
+
function isStdType(typeName) {
|
|
31498
|
+
return function (type) {
|
|
31499
|
+
return type === this.program.checker.getStdType(typeName);
|
|
31500
|
+
};
|
|
31501
|
+
}
|
|
31502
|
+
function extendsStdType(typeName) {
|
|
31503
|
+
return function (type) {
|
|
31504
|
+
if (!this.scalar.is(type)) {
|
|
31505
|
+
return false;
|
|
31506
|
+
}
|
|
31507
|
+
return isIntrinsicType(this.program, type, typeName);
|
|
31508
|
+
};
|
|
31509
|
+
}
|
|
31510
|
+
|
|
31511
|
+
defineKit({
|
|
31512
|
+
type: {
|
|
31513
|
+
finishType(type) {
|
|
31514
|
+
this.program.checker.finishType(type);
|
|
31515
|
+
},
|
|
31516
|
+
clone(type) {
|
|
31517
|
+
let clone;
|
|
31518
|
+
switch (type.kind) {
|
|
31519
|
+
case "Model":
|
|
31520
|
+
clone = this.program.checker.createType({
|
|
31521
|
+
...type,
|
|
31522
|
+
decorators: [...type.decorators],
|
|
31523
|
+
properties: copyMap(type.properties),
|
|
31524
|
+
indexer: type.indexer ? { ...type.indexer } : undefined,
|
|
31525
|
+
});
|
|
31526
|
+
break;
|
|
31527
|
+
case "Union":
|
|
31528
|
+
clone = this.program.checker.createType({
|
|
31529
|
+
...type,
|
|
31530
|
+
decorators: [...type.decorators],
|
|
31531
|
+
variants: copyMap(type.variants),
|
|
31532
|
+
get options() {
|
|
31533
|
+
return Array.from(this.variants.values()).map((v) => v.type);
|
|
31534
|
+
},
|
|
31535
|
+
});
|
|
31536
|
+
break;
|
|
31537
|
+
case "Interface":
|
|
31538
|
+
clone = this.program.checker.createType({
|
|
31539
|
+
...type,
|
|
31540
|
+
decorators: [...type.decorators],
|
|
31541
|
+
operations: copyMap(type.operations),
|
|
31542
|
+
});
|
|
31543
|
+
break;
|
|
31544
|
+
case "Enum":
|
|
31545
|
+
clone = this.program.checker.createType({
|
|
31546
|
+
...type,
|
|
31547
|
+
members: copyMap(type.members),
|
|
31548
|
+
});
|
|
31549
|
+
break;
|
|
31550
|
+
case "Namespace":
|
|
31551
|
+
clone = this.program.checker.createType({
|
|
31552
|
+
...type,
|
|
31553
|
+
decorators: [...type.decorators],
|
|
31554
|
+
instantiationParameters: type.instantiationParameters
|
|
31555
|
+
? [...type.instantiationParameters]
|
|
31556
|
+
: undefined,
|
|
31557
|
+
projections: [...type.projections],
|
|
31558
|
+
});
|
|
31559
|
+
const clonedNamespace = clone;
|
|
31560
|
+
clonedNamespace.decoratorDeclarations = cloneTypeCollection(this, type.decoratorDeclarations, {
|
|
31561
|
+
namespace: clonedNamespace,
|
|
31562
|
+
});
|
|
31563
|
+
clonedNamespace.models = cloneTypeCollection(this, type.models, {
|
|
31564
|
+
namespace: clonedNamespace,
|
|
31565
|
+
});
|
|
31566
|
+
clonedNamespace.enums = cloneTypeCollection(this, type.enums, {
|
|
31567
|
+
namespace: clonedNamespace,
|
|
31568
|
+
});
|
|
31569
|
+
clonedNamespace.functionDeclarations = cloneTypeCollection(this, type.functionDeclarations, {
|
|
31570
|
+
namespace: clonedNamespace,
|
|
31571
|
+
});
|
|
31572
|
+
clonedNamespace.interfaces = cloneTypeCollection(this, type.interfaces, {
|
|
31573
|
+
namespace: clonedNamespace,
|
|
31574
|
+
});
|
|
31575
|
+
clonedNamespace.namespaces = cloneTypeCollection(this, type.namespaces, {
|
|
31576
|
+
namespace: clonedNamespace,
|
|
31577
|
+
});
|
|
31578
|
+
clonedNamespace.operations = cloneTypeCollection(this, type.operations, {
|
|
31579
|
+
namespace: clonedNamespace,
|
|
31580
|
+
});
|
|
31581
|
+
clonedNamespace.scalars = cloneTypeCollection(this, type.scalars, {
|
|
31582
|
+
namespace: clonedNamespace,
|
|
31583
|
+
});
|
|
31584
|
+
clonedNamespace.unions = cloneTypeCollection(this, type.unions, {
|
|
31585
|
+
namespace: clonedNamespace,
|
|
31586
|
+
});
|
|
31587
|
+
break;
|
|
31588
|
+
default:
|
|
31589
|
+
clone = this.program.checker.createType({
|
|
31590
|
+
...type,
|
|
31591
|
+
...("decorators" in type ? { decorators: [...type.decorators] } : {}),
|
|
31592
|
+
});
|
|
31593
|
+
break;
|
|
31594
|
+
}
|
|
31595
|
+
this.realm.addType(clone);
|
|
31596
|
+
return clone;
|
|
31597
|
+
},
|
|
31598
|
+
},
|
|
31599
|
+
});
|
|
31600
|
+
function cloneTypeCollection(kit, collection, options = {}) {
|
|
31601
|
+
const cloneCollection = new Map();
|
|
31602
|
+
for (const [key, type] of collection) {
|
|
31603
|
+
const clone = kit.type.clone(type);
|
|
31604
|
+
if ("namespace" in clone && options.namespace) {
|
|
31605
|
+
clone.namespace = options.namespace;
|
|
31606
|
+
}
|
|
31607
|
+
cloneCollection.set(key, clone);
|
|
31608
|
+
}
|
|
31609
|
+
return cloneCollection;
|
|
31610
|
+
}
|
|
31611
|
+
|
|
31612
|
+
defineKit({
|
|
31613
|
+
unionVariant: {
|
|
31614
|
+
create(desc) {
|
|
31615
|
+
const variant = this.program.checker.createType({
|
|
31616
|
+
kind: "UnionVariant",
|
|
31617
|
+
name: desc.name ?? Symbol("name"),
|
|
31618
|
+
decorators: decoratorApplication(this, desc.decorators),
|
|
31619
|
+
type: desc.type,
|
|
31620
|
+
node: undefined,
|
|
31621
|
+
union: desc.union,
|
|
31622
|
+
});
|
|
31623
|
+
this.program.checker.finishType(variant);
|
|
31624
|
+
return variant;
|
|
31625
|
+
},
|
|
31626
|
+
is(type) {
|
|
31627
|
+
return type.kind === "UnionVariant";
|
|
31628
|
+
},
|
|
31629
|
+
},
|
|
31630
|
+
});
|
|
31631
|
+
|
|
31632
|
+
defineKit({
|
|
31633
|
+
union: {
|
|
31634
|
+
create(desc) {
|
|
31635
|
+
const union = this.program.checker.createType({
|
|
31636
|
+
kind: "Union",
|
|
31637
|
+
name: desc.name,
|
|
31638
|
+
decorators: decoratorApplication(this, desc.decorators),
|
|
31639
|
+
variants: createRekeyableMap(),
|
|
31640
|
+
get options() {
|
|
31641
|
+
return Array.from(this.variants.values()).map((v) => v.type);
|
|
31642
|
+
},
|
|
31643
|
+
expression: desc.name === undefined,
|
|
31644
|
+
node: undefined,
|
|
31645
|
+
});
|
|
31646
|
+
if (Array.isArray(desc.variants)) {
|
|
31647
|
+
for (const variant of desc.variants) {
|
|
31648
|
+
union.variants.set(variant.name, variant);
|
|
31649
|
+
variant.union = union;
|
|
31650
|
+
}
|
|
31651
|
+
}
|
|
31652
|
+
else if (desc.variants) {
|
|
31653
|
+
for (const [name, value] of Object.entries(desc.variants)) {
|
|
31654
|
+
union.variants.set(name, this.unionVariant.create({ name, type: this.literal.create(value) }));
|
|
31655
|
+
}
|
|
31656
|
+
}
|
|
31657
|
+
this.program.checker.finishType(union);
|
|
31658
|
+
return union;
|
|
31659
|
+
},
|
|
31660
|
+
is(type) {
|
|
31661
|
+
return type.kind === "Union";
|
|
31662
|
+
},
|
|
31663
|
+
isValidEnum(type) {
|
|
31664
|
+
for (const variant of type.variants.values()) {
|
|
31665
|
+
if (!this.literal.isString(variant.type) && !this.literal.isNumeric(variant.type)) {
|
|
31666
|
+
return false;
|
|
31667
|
+
}
|
|
31668
|
+
}
|
|
31669
|
+
return true;
|
|
31670
|
+
},
|
|
31671
|
+
isExtensible(type) {
|
|
31672
|
+
const variants = Array.from(type.variants.values());
|
|
31673
|
+
if (variants.length === 0) {
|
|
31674
|
+
return false;
|
|
31675
|
+
}
|
|
31676
|
+
for (let i = 0; i < variants.length; i++) {
|
|
31677
|
+
let isCommon = true;
|
|
31678
|
+
for (let j = 0; j < variants.length; j++) {
|
|
31679
|
+
if (i === j) {
|
|
31680
|
+
continue;
|
|
31681
|
+
}
|
|
31682
|
+
const assignable = ignoreDiagnostics(this.program.checker.isTypeAssignableTo(variants[j].type, variants[i].type, type));
|
|
31683
|
+
if (!assignable) {
|
|
31684
|
+
isCommon = false;
|
|
31685
|
+
break;
|
|
31686
|
+
}
|
|
31687
|
+
}
|
|
31688
|
+
if (isCommon) {
|
|
31689
|
+
return true;
|
|
31690
|
+
}
|
|
31691
|
+
}
|
|
31692
|
+
return false;
|
|
31693
|
+
},
|
|
31694
|
+
},
|
|
31695
|
+
});
|
|
31696
|
+
|
|
31697
|
+
/**
|
|
31698
|
+
* Create a new Typekit that operates in the given realm.
|
|
31699
|
+
*
|
|
31700
|
+
* Ordinarily, you should use the default typekit `$` to manipulate types in the current program, or call `$` with a
|
|
31701
|
+
* Realm or Program as the first argument if you want to work in a specific realm or in the default typekit realm of
|
|
31702
|
+
* a specific program.
|
|
31703
|
+
*
|
|
31704
|
+
* @param realm - The realm to create the typekit in.
|
|
31705
|
+
*
|
|
31706
|
+
* @experimental
|
|
31707
|
+
*/
|
|
31708
|
+
function createTypekit(realm) {
|
|
31709
|
+
const tk = Object.create(TypekitPrototype);
|
|
30834
31710
|
const handler = {
|
|
30835
31711
|
get(target, prop, receiver) {
|
|
30836
|
-
const value = Reflect.get(target, prop, receiver);
|
|
30837
31712
|
if (prop === "program") {
|
|
30838
31713
|
// don't wrap program (probably need to ensure this isn't a nested program somewhere)
|
|
30839
|
-
return
|
|
31714
|
+
return realm.program;
|
|
31715
|
+
}
|
|
31716
|
+
if (prop === "realm") {
|
|
31717
|
+
return realm;
|
|
30840
31718
|
}
|
|
31719
|
+
const value = Reflect.get(target, prop, receiver);
|
|
30841
31720
|
if (typeof value === "function") {
|
|
30842
31721
|
return function (...args) {
|
|
30843
31722
|
return value.apply(proxy, args);
|
|
@@ -30852,18 +31731,80 @@ function createTypekit() {
|
|
|
30852
31731
|
const proxy = new Proxy(tk, handler);
|
|
30853
31732
|
return proxy;
|
|
30854
31733
|
}
|
|
30855
|
-
|
|
30856
|
-
|
|
30857
|
-
|
|
31734
|
+
// #region Default Typekit
|
|
31735
|
+
const CURRENT_PROGRAM = Symbol.for("TypeSpec.Typekit.CURRENT_PROGRAM");
|
|
31736
|
+
const DEFAULT_REALM = Symbol.for("TypeSpec.Typekit.DEFAULT_TYPEKIT_REALM");
|
|
31737
|
+
function getCurrentProgram() {
|
|
31738
|
+
return globalThis[CURRENT_PROGRAM];
|
|
31739
|
+
}
|
|
31740
|
+
function _$(arg) {
|
|
31741
|
+
let realm;
|
|
31742
|
+
if (Object.hasOwn(arg, "projectRoot")) {
|
|
31743
|
+
// arg is a Program
|
|
31744
|
+
realm = arg[DEFAULT_REALM] ??= new Realm(arg, "default typekit realm");
|
|
31745
|
+
}
|
|
31746
|
+
else {
|
|
31747
|
+
// arg is a Realm
|
|
31748
|
+
realm = arg;
|
|
31749
|
+
}
|
|
31750
|
+
return realm.typekit;
|
|
31751
|
+
}
|
|
30858
31752
|
/**
|
|
30859
|
-
*
|
|
30860
|
-
*
|
|
30861
|
-
*
|
|
30862
|
-
*
|
|
31753
|
+
* Typekit - Utilities for working with TypeSpec types.
|
|
31754
|
+
*
|
|
31755
|
+
* The default typekit `$` can be used to manipulate types in the current program.
|
|
31756
|
+
*
|
|
31757
|
+
* Each typekit is associated with a Realm in which it operates. The default typekit
|
|
31758
|
+
* will use the default typekit realm for the current program.
|
|
31759
|
+
*
|
|
31760
|
+
* Alternatively, to work in a specific realm, you can get the typekit associated
|
|
31761
|
+
* with that realm by calling `$` with the realm as an argument, or by calling
|
|
31762
|
+
* `$` with a program as an argument (in this case, it will use that program's
|
|
31763
|
+
* default typekit realm or create one if it does not already exist).
|
|
31764
|
+
*
|
|
31765
|
+
* @example
|
|
31766
|
+
* ```ts
|
|
31767
|
+
* import { $ } from "@typespec/compiler/experimental";
|
|
31768
|
+
*
|
|
31769
|
+
* const clone = $.type.clone(inputType);
|
|
31770
|
+
* ```
|
|
31771
|
+
*
|
|
31772
|
+
* @example
|
|
31773
|
+
* ```ts
|
|
31774
|
+
* import { $, Realm } from "@typespec/compiler/experimental";
|
|
31775
|
+
*
|
|
31776
|
+
* const realm = new Realm(program, "my custom realm");
|
|
31777
|
+
*
|
|
31778
|
+
* const clone = $(realm).type.clone(inputType);
|
|
31779
|
+
* ```
|
|
31780
|
+
*
|
|
31781
|
+
* @example
|
|
31782
|
+
* ```ts
|
|
31783
|
+
* import { $ } from "@typespec/compiler/experimental";
|
|
31784
|
+
*
|
|
31785
|
+
* const projectedProgram = projectProgram(program, ...);
|
|
31786
|
+
*
|
|
31787
|
+
* const clone = $(projectedProgram).type.clone(inputType);
|
|
31788
|
+
* ```
|
|
31789
|
+
*
|
|
31790
|
+
* @see {@link Realm}
|
|
31791
|
+
*
|
|
31792
|
+
* @experimental
|
|
30863
31793
|
*/
|
|
30864
|
-
|
|
30865
|
-
|
|
30866
|
-
|
|
31794
|
+
new Proxy(_$, {
|
|
31795
|
+
get(_target, prop, _receiver) {
|
|
31796
|
+
const currentProgram = getCurrentProgram();
|
|
31797
|
+
compilerAssert(currentProgram !== undefined, "Default typekits may not be used until a program is set in the compiler.");
|
|
31798
|
+
if (prop === "program")
|
|
31799
|
+
return currentProgram;
|
|
31800
|
+
const realm = (currentProgram[DEFAULT_REALM] ??= new Realm(currentProgram, "default typekit realm"));
|
|
31801
|
+
if (prop === "realm")
|
|
31802
|
+
return realm;
|
|
31803
|
+
const tk = _$(realm);
|
|
31804
|
+
return Reflect.get(tk, prop, tk);
|
|
31805
|
+
},
|
|
31806
|
+
});
|
|
31807
|
+
// #endregion
|
|
30867
31808
|
|
|
30868
31809
|
const globalLibraryUrlsLoadedSym = Symbol.for("TYPESPEC_LIBRARY_URLS_LOADED");
|
|
30869
31810
|
if (globalThis[globalLibraryUrlsLoadedSym] === undefined) {
|