@typespec/html-program-viewer 0.62.0 → 0.63.0-dev.1

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.
@@ -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-CoFoVY97.js')).default;
17823
+ manifest = (await import('../manifest-seJyOKYj.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: {
@@ -18914,6 +18989,26 @@ const diagnostics = {
18914
18989
  default: "Conflict marker encountered.",
18915
18990
  },
18916
18991
  },
18992
+ // #region Visibility
18993
+ "visibility-sealed": {
18994
+ severity: "error",
18995
+ messages: {
18996
+ default: paramMessage `Visibility of property '${"propName"}' is sealed and cannot be changed.`,
18997
+ },
18998
+ },
18999
+ "visibility-mixed-legacy": {
19000
+ severity: "error",
19001
+ messages: {
19002
+ default: "Cannot apply both string (legacy) visibility modifiers and enum-based visibility modifiers to a property.",
19003
+ },
19004
+ },
19005
+ "default-visibility-not-member": {
19006
+ severity: "error",
19007
+ messages: {
19008
+ default: "The default visibility modifiers of a class must be members of the class enum.",
19009
+ },
19010
+ },
19011
+ // #endregion
18917
19012
  // #region CLI
18918
19013
  "no-compatible-vs-installed": {
18919
19014
  severity: "error",
@@ -22671,8 +22766,7 @@ function serialize (cmpts, opts) {
22671
22766
  }
22672
22767
 
22673
22768
  if (options.reference !== 'suffix' && components.scheme) {
22674
- uriTokens.push(components.scheme);
22675
- uriTokens.push(':');
22769
+ uriTokens.push(components.scheme, ':');
22676
22770
  }
22677
22771
 
22678
22772
  const authority = recomposeAuthority(components, options);
@@ -22702,13 +22796,11 @@ function serialize (cmpts, opts) {
22702
22796
  }
22703
22797
 
22704
22798
  if (components.query !== undefined) {
22705
- uriTokens.push('?');
22706
- uriTokens.push(components.query);
22799
+ uriTokens.push('?', components.query);
22707
22800
  }
22708
22801
 
22709
22802
  if (components.fragment !== undefined) {
22710
- uriTokens.push('#');
22711
- uriTokens.push(components.fragment);
22803
+ uriTokens.push('#', components.fragment);
22712
22804
  }
22713
22805
  return uriTokens.join('')
22714
22806
  }
@@ -22806,9 +22898,6 @@ function parse$2 (uri, opts) {
22806
22898
  if (gotEncoding && parsed.scheme !== undefined) {
22807
22899
  parsed.scheme = unescape(parsed.scheme);
22808
22900
  }
22809
- if (gotEncoding && parsed.userinfo !== undefined) {
22810
- parsed.userinfo = unescape(parsed.userinfo);
22811
- }
22812
22901
  if (gotEncoding && parsed.host !== undefined) {
22813
22902
  parsed.host = unescape(parsed.host);
22814
22903
  }
@@ -27603,6 +27692,14 @@ function compilerAssert(condition, message, target) {
27603
27692
  }
27604
27693
  throw new Error(message);
27605
27694
  }
27695
+ /**
27696
+ * Ignore the diagnostics emitted by the diagnostic accessor pattern and just return the actual result.
27697
+ * @param result Accessor pattern tuple result including the actual result and the list of diagnostics.
27698
+ * @returns Actual result.
27699
+ */
27700
+ function ignoreDiagnostics(result) {
27701
+ return result[0];
27702
+ }
27606
27703
 
27607
27704
  function absolutePathStatus(path) {
27608
27705
  if (path.startsWith(".") || !isPathAbsolute(path)) {
@@ -27831,22 +27928,22 @@ createJSONSchemaValidator(TypeSpecConfigJsonSchema);
27831
27928
 
27832
27929
  // Contains all intrinsic data setter or getter
27833
27930
  // Anything that the TypeSpec check might should be here.
27834
- function createStateSymbol(name) {
27931
+ function createStateSymbol$1(name) {
27835
27932
  return Symbol.for(`TypeSpec.${name}`);
27836
27933
  }
27837
27934
  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"),
27935
+ minValues: createStateSymbol$1("minValues"),
27936
+ maxValues: createStateSymbol$1("maxValues"),
27937
+ minValueExclusive: createStateSymbol$1("minValueExclusive"),
27938
+ maxValueExclusive: createStateSymbol$1("maxValueExclusive"),
27939
+ minLength: createStateSymbol$1("minLengthValues"),
27940
+ maxLength: createStateSymbol$1("maxLengthValues"),
27941
+ minItems: createStateSymbol$1("minItems"),
27942
+ maxItems: createStateSymbol$1("maxItems"),
27943
+ docs: createStateSymbol$1("docs"),
27944
+ returnDocs: createStateSymbol$1("returnsDocs"),
27945
+ errorsDocs: createStateSymbol$1("errorDocs"),
27946
+ discriminator: createStateSymbol$1("discriminator"),
27850
27947
  };
27851
27948
  function getDocKey(target) {
27852
27949
  switch (target) {
@@ -28904,7 +29001,6 @@ var ListKind;
28904
29001
  const PropertiesBase = {
28905
29002
  allowEmpty: true,
28906
29003
  toleratedDelimiterIsValid: true,
28907
- trailingDelimiterIsValid: true,
28908
29004
  allowedStatementKeyword: Token.None,
28909
29005
  };
28910
29006
  ListKind.OperationParameters = {
@@ -28970,7 +29066,6 @@ var ListKind;
28970
29066
  delimiter: Token.Comma,
28971
29067
  toleratedDelimiter: Token.Semicolon,
28972
29068
  toleratedDelimiterIsValid: false,
28973
- trailingDelimiterIsValid: false,
28974
29069
  invalidAnnotationTarget: "expression",
28975
29070
  allowedStatementKeyword: Token.None,
28976
29071
  };
@@ -29508,6 +29603,10 @@ var ResolutionKind;
29508
29603
  ResolutionKind[ResolutionKind["Constraint"] = 3] = "Constraint";
29509
29604
  })(ResolutionKind || (ResolutionKind = {}));
29510
29605
 
29606
+ function isIntrinsicType(program, type, kind) {
29607
+ return ignoreDiagnostics(program.checker.isTypeAssignableTo(type.projectionBase ?? type, program.checker.getStdType(kind), type));
29608
+ }
29609
+
29511
29610
  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
29611
  `,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
29612
  `);return r.message&&!d&&(c=`${" ".repeat(f+1)}${r.message}
@@ -30820,7 +30919,7 @@ new Set([
30820
30919
  "intrinsic",
30821
30920
  ]);
30822
30921
 
30823
- let currentProgram;
30922
+ const CURRENT_PROGRAM = Symbol.for("TypeSpec.currentProgram");
30824
30923
  /** @experimental */
30825
30924
  const TypekitPrototype = {};
30826
30925
  /** @experimental */
@@ -30828,7 +30927,7 @@ function createTypekit() {
30828
30927
  const tk = Object.create(TypekitPrototype);
30829
30928
  Object.defineProperty(tk, "program", {
30830
30929
  get() {
30831
- return currentProgram;
30930
+ return globalThis[CURRENT_PROGRAM];
30832
30931
  },
30833
30932
  });
30834
30933
  const handler = {
@@ -30853,7 +30952,655 @@ function createTypekit() {
30853
30952
  return proxy;
30854
30953
  }
30855
30954
  /** @experimental */
30856
- createTypekit();
30955
+ function defineKit(source) {
30956
+ for (const [name, fnOrNs] of Object.entries(source)) {
30957
+ TypekitPrototype[name] = fnOrNs;
30958
+ }
30959
+ }
30960
+ /** @experimental */
30961
+ const $ = createTypekit();
30962
+
30963
+ /** @experimental */
30964
+ function unsafe_useStateMap(key) {
30965
+ const getter = (program, target) => program.stateMap(key).get(target);
30966
+ const setter = (program, target, value) => program.stateMap(key).set(target, value);
30967
+ const mapGetter = (program) => program.stateMap(key);
30968
+ return [getter, setter, mapGetter];
30969
+ }
30970
+
30971
+ function createStateSymbol(name) {
30972
+ return Symbol.for(`TypeSpec.${name}`);
30973
+ }
30974
+ function useStateMap(key) {
30975
+ return unsafe_useStateMap(typeof key === "string" ? createStateSymbol(key) : key);
30976
+ }
30977
+
30978
+ // Copyright (c) Microsoft Corporation
30979
+ // Licensed under the MIT license.
30980
+ // TypeSpec Visibility System
30981
+ // --------------------------
30982
+ // This module defines the core visibility system of the TypeSpec language. The
30983
+ // visibility system is used to decide when properties of a _conceptual resource_
30984
+ // are present. The system is based on the concept of _visibility classes_,
30985
+ // represented by TypeSpec enums. Each visibility class has a set of _visibility
30986
+ // modifiers_ that can be applied to a model property, each modifier represented
30987
+ // by a member of the visibility class enum.
30988
+ //
30989
+ // Each visibility class has a _default modifier set_ that is used when no
30990
+ // modifiers are specified for a property, and each property has an _active
30991
+ // modifier set_ that is used when analyzing the visibility of the property.
30992
+ //
30993
+ // Visibility can be _sealed_ for a program, property, or visibility class
30994
+ // within a property. Once visibility is sealed, it cannot be unsealed, and any
30995
+ // attempts to modify a sealed visibility will fail.
30996
+ /**
30997
+ * The global visibility store.
30998
+ *
30999
+ * This store is used to track the visibility modifiers
31000
+ */
31001
+ const [getVisibilityStore, setVisibilityStore] = useStateMap("visibilityStore");
31002
+ /**
31003
+ * Returns the visibility modifiers for a given `property` within a `program`.
31004
+ */
31005
+ function getOrInitializeVisibilityModifiers(program, property) {
31006
+ let visibilityModifiers = getVisibilityStore(program, property);
31007
+ if (!visibilityModifiers) {
31008
+ visibilityModifiers = new Map();
31009
+ setVisibilityStore(program, property, visibilityModifiers);
31010
+ }
31011
+ return visibilityModifiers;
31012
+ }
31013
+ /**
31014
+ * Returns the active visibility modifier set for a given `property` and `visibilityClass`.
31015
+ *
31016
+ * If no visibility modifiers have been set for the given `property` and `visibilityClass`, the function will use the
31017
+ * provided `defaultSet` to initialize the visibility modifiers.
31018
+ *
31019
+ * @param program - the program in which the property occurs
31020
+ * @param property - the property to get visibility modifiers for
31021
+ * @param visibilityClass - the visibility class to get visibility modifiers for
31022
+ * @param defaultSet - the default set to use if no set has been initialized
31023
+ * @returns the active visibility modifier set for the given property and visibility class
31024
+ */
31025
+ function getOrInitializeActiveModifierSetForClass(program, property, visibilityClass, defaultSet) {
31026
+ const visibilityModifiers = getOrInitializeVisibilityModifiers(program, property);
31027
+ let visibilityModifierSet = visibilityModifiers.get(visibilityClass);
31028
+ if (!visibilityModifierSet) {
31029
+ visibilityModifierSet = defaultSet;
31030
+ visibilityModifiers.set(visibilityClass, visibilityModifierSet);
31031
+ }
31032
+ return visibilityModifierSet;
31033
+ }
31034
+ /**
31035
+ * Stores the default modifier set for a given visibility class.
31036
+ */
31037
+ const [getDefaultModifiers, setDefaultModifiers] = useStateMap("defaultVisibilityModifiers");
31038
+ /**
31039
+ * Gets the default modifier set for a visibility class. If no default modifier set has been set, this function will
31040
+ * initialize the default modifier set to ALL the visibility class's members.
31041
+ *
31042
+ * @param program - the program in which the visibility class occurs
31043
+ * @param visibilityClass - the visibility class to get the default modifier set for
31044
+ * @returns the default modifier set for the visibility class
31045
+ */
31046
+ function getDefaultModifierSetForClass(program, visibilityClass) {
31047
+ const cached = getDefaultModifiers(program, visibilityClass);
31048
+ if (cached)
31049
+ return cached;
31050
+ const defaultModifierSet = new Set(visibilityClass.members.values());
31051
+ setDefaultModifiers(program, visibilityClass, defaultModifierSet);
31052
+ return defaultModifierSet;
31053
+ }
31054
+ // #endregion
31055
+ // #region Visibility Analysis API
31056
+ /**
31057
+ * Returns the active visibility modifiers for a property in a given visibility class.
31058
+ *
31059
+ * This function is infallible. If the visibility modifiers for the given class have not been set explicitly, it will
31060
+ * return the default visibility modifiers for the class.
31061
+ *
31062
+ * @param program - the program in which the property occurs
31063
+ * @param property - the property to get visibility modifiers for
31064
+ * @param visibilityClass - the visibility class to get visibility modifiers for
31065
+ * @returns the set of active modifiers (enum members) for the property and visibility class
31066
+ */
31067
+ function getVisibilityForClass(program, property, visibilityClass) {
31068
+ return getOrInitializeActiveModifierSetForClass(program, property, visibilityClass,
31069
+ /* defaultSet: */ getDefaultModifierSetForClass(program, visibilityClass));
31070
+ }
31071
+ // #endregion
31072
+
31073
+ var _a$1;
31074
+ class StateMapRealmView {
31075
+ #realm;
31076
+ #parentState;
31077
+ #realmState;
31078
+ constructor(realm, realmState, parentState) {
31079
+ this.#realm = realm;
31080
+ this.#parentState = parentState;
31081
+ this.#realmState = realmState;
31082
+ }
31083
+ has(t) {
31084
+ return this.dispatch(t).has(t) ?? false;
31085
+ }
31086
+ set(t, v) {
31087
+ this.dispatch(t).set(t, v);
31088
+ return this;
31089
+ }
31090
+ get(t) {
31091
+ return this.dispatch(t).get(t);
31092
+ }
31093
+ delete(t) {
31094
+ return this.dispatch(t).delete(t);
31095
+ }
31096
+ forEach(cb, thisArg) {
31097
+ for (const item of this.entries()) {
31098
+ cb.call(thisArg, item[1], item[0], this);
31099
+ }
31100
+ return this;
31101
+ }
31102
+ get size() {
31103
+ // extremely non-optimal, maybe worth not offering it?
31104
+ return [...this.entries()].length;
31105
+ }
31106
+ clear() {
31107
+ this.#realmState.clear();
31108
+ }
31109
+ *entries() {
31110
+ for (const item of this.#realmState) {
31111
+ yield item;
31112
+ }
31113
+ for (const item of this.#parentState) {
31114
+ yield item;
31115
+ }
31116
+ return undefined;
31117
+ }
31118
+ *values() {
31119
+ for (const item of this.entries()) {
31120
+ yield item[1];
31121
+ }
31122
+ return undefined;
31123
+ }
31124
+ *keys() {
31125
+ for (const item of this.entries()) {
31126
+ yield item[0];
31127
+ }
31128
+ return undefined;
31129
+ }
31130
+ [Symbol.iterator]() {
31131
+ return this.entries();
31132
+ }
31133
+ [Symbol.toStringTag] = "StateMap";
31134
+ dispatch(keyType) {
31135
+ if (this.#realm.hasType(keyType)) {
31136
+ return this.#realmState;
31137
+ }
31138
+ return this.#parentState;
31139
+ }
31140
+ }
31141
+ /** @experimental */
31142
+ class Realm {
31143
+ #program;
31144
+ // Type registry
31145
+ /**
31146
+ * Stores all types owned by this realm.
31147
+ */
31148
+ #types = new Set();
31149
+ /**
31150
+ * Stores types that are deleted in this realm. When a realm is active and doing a traversal, you will
31151
+ * not find this type in e.g. collections. Deleted types are mapped to `null` if you ask for it.
31152
+ */
31153
+ #deletedTypes = new Set();
31154
+ #stateMaps = new Map();
31155
+ key;
31156
+ constructor(program, description) {
31157
+ this.key = Symbol(description);
31158
+ this.#program = program;
31159
+ _a$1.#knownRealms.set(this.key, this);
31160
+ }
31161
+ stateMap(stateKey) {
31162
+ let m = this.#stateMaps.get(stateKey);
31163
+ if (!m) {
31164
+ m = new Map();
31165
+ this.#stateMaps.set(stateKey, m);
31166
+ }
31167
+ return new StateMapRealmView(this, m, this.#program.stateMap(stateKey));
31168
+ }
31169
+ clone(type) {
31170
+ compilerAssert(type, "Undefined type passed to clone");
31171
+ const clone = this.#cloneIntoRealm(type);
31172
+ $.type.finishType(clone);
31173
+ return clone;
31174
+ }
31175
+ remove(type) {
31176
+ this.#deletedTypes.add(type);
31177
+ }
31178
+ hasType(type) {
31179
+ return this.#types.has(type);
31180
+ }
31181
+ addType(type) {
31182
+ this.#types.add(type);
31183
+ _a$1.realmForType.set(type, this);
31184
+ }
31185
+ #cloneIntoRealm(type) {
31186
+ const clone = $.type.clone(type);
31187
+ this.#types.add(clone);
31188
+ _a$1.realmForType.set(clone, this);
31189
+ return clone;
31190
+ }
31191
+ static #knownRealms = new Map();
31192
+ static realmForKey(key, parentRealm) {
31193
+ return this.#knownRealms.get(key);
31194
+ }
31195
+ static realmForType = new Map();
31196
+ }
31197
+ _a$1 = Realm;
31198
+
31199
+ defineKit({
31200
+ literal: {
31201
+ create(value) {
31202
+ if (typeof value === "string") {
31203
+ return this.literal.createString(value);
31204
+ }
31205
+ else if (typeof value === "number") {
31206
+ return this.literal.createNumeric(value);
31207
+ }
31208
+ else {
31209
+ return this.literal.createBoolean(value);
31210
+ }
31211
+ },
31212
+ createString(value) {
31213
+ return this.program.checker.createType({
31214
+ kind: "String",
31215
+ value,
31216
+ });
31217
+ },
31218
+ createNumeric(value) {
31219
+ const valueAsString = String(value);
31220
+ return this.program.checker.createType({
31221
+ kind: "Number",
31222
+ value,
31223
+ valueAsString,
31224
+ numericValue: Numeric(valueAsString),
31225
+ });
31226
+ },
31227
+ createBoolean(value) {
31228
+ return this.program.checker.createType({
31229
+ kind: "Boolean",
31230
+ value,
31231
+ });
31232
+ },
31233
+ isBoolean(type) {
31234
+ return type.kind === "Boolean";
31235
+ },
31236
+ isString(type) {
31237
+ return type.kind === "String";
31238
+ },
31239
+ isNumeric(type) {
31240
+ return type.kind === "Number";
31241
+ },
31242
+ is(type) {
31243
+ return (this.literal.isBoolean(type) || this.literal.isNumeric(type) || this.literal.isString(type));
31244
+ },
31245
+ },
31246
+ });
31247
+
31248
+ defineKit({
31249
+ modelProperty: {
31250
+ is(type) {
31251
+ return type.kind === "ModelProperty";
31252
+ },
31253
+ getEncoding(type) {
31254
+ return getEncode(this.program, type) ?? getEncode(this.program, type.type);
31255
+ },
31256
+ getFormat(type) {
31257
+ return getFormat(this.program, type) ?? getFormat(this.program, type.type);
31258
+ },
31259
+ getVisibilityForClass(property, visibilityClass) {
31260
+ return getVisibilityForClass(this.program, property, visibilityClass);
31261
+ },
31262
+ },
31263
+ });
31264
+
31265
+ /** @experimental */
31266
+ function copyMap(map) {
31267
+ return createRekeyableMap(Array.from(map.entries()));
31268
+ }
31269
+ /** @experimental */
31270
+ function decoratorApplication(args) {
31271
+ if (!args) {
31272
+ return [];
31273
+ }
31274
+ const decorators = [];
31275
+ for (const arg of args) {
31276
+ decorators.push({
31277
+ decorator: Array.isArray(arg) ? arg[0] : arg,
31278
+ args: Array.isArray(arg)
31279
+ ? arg.slice(1).map((rawValue) => ({
31280
+ value: typeof rawValue === "object" && rawValue !== null
31281
+ ? rawValue
31282
+ : $.literal.create(rawValue),
31283
+ jsValue: rawValue,
31284
+ }))
31285
+ : [],
31286
+ });
31287
+ }
31288
+ return decorators;
31289
+ }
31290
+
31291
+ defineKit({
31292
+ model: {
31293
+ create(desc) {
31294
+ const properties = createRekeyableMap(Array.from(Object.entries(desc.properties)));
31295
+ const model = this.program.checker.createType({
31296
+ kind: "Model",
31297
+ name: desc.name ?? "",
31298
+ decorators: decoratorApplication(desc.decorators),
31299
+ properties: properties,
31300
+ expression: desc.name === undefined,
31301
+ node: undefined,
31302
+ derivedModels: desc.derivedModels ?? [],
31303
+ sourceModels: desc.sourceModels ?? [],
31304
+ });
31305
+ this.program.checker.finishType(model);
31306
+ return model;
31307
+ },
31308
+ is(type) {
31309
+ return type.kind === "Model";
31310
+ },
31311
+ },
31312
+ });
31313
+
31314
+ let _realm;
31315
+ defineKit({
31316
+ realm: {
31317
+ get() {
31318
+ if (!_realm) {
31319
+ _realm = new Realm(this.program, " typekit realm");
31320
+ }
31321
+ return _realm;
31322
+ },
31323
+ set(realm) {
31324
+ _realm = realm;
31325
+ },
31326
+ },
31327
+ });
31328
+
31329
+ defineKit({
31330
+ scalar: {
31331
+ is(type) {
31332
+ return type.kind === "Scalar";
31333
+ },
31334
+ extendsBoolean: extendsStdType("boolean"),
31335
+ extendsBytes: extendsStdType("bytes"),
31336
+ extendsDecimal: extendsStdType("decimal"),
31337
+ extendsDecimal128: extendsStdType("decimal128"),
31338
+ extendsDuration: extendsStdType("duration"),
31339
+ extendsFloat: extendsStdType("float"),
31340
+ extendsFloat32: extendsStdType("float32"),
31341
+ extendsFloat64: extendsStdType("float64"),
31342
+ extendsInt8: extendsStdType("int8"),
31343
+ extendsInt16: extendsStdType("int16"),
31344
+ extendsInt32: extendsStdType("int32"),
31345
+ extendsInt64: extendsStdType("int64"),
31346
+ extendsInteger: extendsStdType("integer"),
31347
+ extendsNumeric: extendsStdType("numeric"),
31348
+ extendsOffsetDateTime: extendsStdType("offsetDateTime"),
31349
+ extendsPlainDate: extendsStdType("plainDate"),
31350
+ extendsPlainTime: extendsStdType("plainTime"),
31351
+ extendsSafeint: extendsStdType("safeint"),
31352
+ extendsString: extendsStdType("string"),
31353
+ extendsUint8: extendsStdType("uint8"),
31354
+ extendsUint16: extendsStdType("uint16"),
31355
+ extendsUint32: extendsStdType("uint32"),
31356
+ extendsUint64: extendsStdType("uint64"),
31357
+ extendsUrl: extendsStdType("url"),
31358
+ extendsUtcDateTime: extendsStdType("utcDateTime"),
31359
+ isBoolean: isStdType("boolean"),
31360
+ isBytes: isStdType("bytes"),
31361
+ isDecimal: isStdType("decimal"),
31362
+ isDecimal128: isStdType("decimal128"),
31363
+ isDuration: isStdType("duration"),
31364
+ isFloat: isStdType("float"),
31365
+ isFloat32: isStdType("float32"),
31366
+ isFloat64: isStdType("float64"),
31367
+ isInt8: isStdType("int8"),
31368
+ isInt16: isStdType("int16"),
31369
+ isInt32: isStdType("int32"),
31370
+ isInt64: isStdType("int64"),
31371
+ isInteger: isStdType("integer"),
31372
+ isNumeric: isStdType("numeric"),
31373
+ isOffsetDateTime: isStdType("offsetDateTime"),
31374
+ isPlainDate: isStdType("plainDate"),
31375
+ isPlainTime: isStdType("plainTime"),
31376
+ isSafeint: isStdType("safeint"),
31377
+ isString: isStdType("string"),
31378
+ isUint8: isStdType("uint8"),
31379
+ isUint16: isStdType("uint16"),
31380
+ isUint32: isStdType("uint32"),
31381
+ isUint64: isStdType("uint64"),
31382
+ isUrl: isStdType("url"),
31383
+ isUtcDateTime: isStdType("utcDateTime"),
31384
+ getStdBase(type) {
31385
+ const tspNamespace = this.program.resolveTypeReference("TypeSpec")[0];
31386
+ let current = type;
31387
+ while (current) {
31388
+ if (current.namespace === tspNamespace) {
31389
+ return current;
31390
+ }
31391
+ current = current.baseScalar;
31392
+ }
31393
+ return null;
31394
+ },
31395
+ getEncoding(type) {
31396
+ return getEncode(this.program, type);
31397
+ },
31398
+ getFormat(type) {
31399
+ return getFormat(this.program, type);
31400
+ },
31401
+ },
31402
+ });
31403
+ function isStdType(typeName) {
31404
+ return function (type) {
31405
+ return type === this.program.checker.getStdType(typeName);
31406
+ };
31407
+ }
31408
+ function extendsStdType(typeName) {
31409
+ return function (type) {
31410
+ if (!this.scalar.is(type)) {
31411
+ return false;
31412
+ }
31413
+ return isIntrinsicType(this.program, type, typeName);
31414
+ };
31415
+ }
31416
+
31417
+ defineKit({
31418
+ type: {
31419
+ finishType(type) {
31420
+ this.program.checker.finishType(type);
31421
+ },
31422
+ clone(type) {
31423
+ let clone;
31424
+ switch (type.kind) {
31425
+ case "Model":
31426
+ clone = this.program.checker.createType({
31427
+ ...type,
31428
+ decorators: [...type.decorators],
31429
+ properties: copyMap(type.properties),
31430
+ indexer: type.indexer ? { ...type.indexer } : undefined,
31431
+ });
31432
+ break;
31433
+ case "Union":
31434
+ clone = this.program.checker.createType({
31435
+ ...type,
31436
+ decorators: [...type.decorators],
31437
+ variants: copyMap(type.variants),
31438
+ get options() {
31439
+ return Array.from(this.variants.values()).map((v) => v.type);
31440
+ },
31441
+ });
31442
+ break;
31443
+ case "Interface":
31444
+ clone = this.program.checker.createType({
31445
+ ...type,
31446
+ decorators: [...type.decorators],
31447
+ operations: copyMap(type.operations),
31448
+ });
31449
+ break;
31450
+ case "Enum":
31451
+ clone = this.program.checker.createType({
31452
+ ...type,
31453
+ members: copyMap(type.members),
31454
+ });
31455
+ break;
31456
+ case "Namespace":
31457
+ clone = this.program.checker.createType({
31458
+ ...type,
31459
+ decorators: [...type.decorators],
31460
+ instantiationParameters: type.instantiationParameters
31461
+ ? [...type.instantiationParameters]
31462
+ : undefined,
31463
+ projections: [...type.projections],
31464
+ });
31465
+ const clonedNamespace = clone;
31466
+ clonedNamespace.decoratorDeclarations = cloneTypeCollection(type.decoratorDeclarations, {
31467
+ namespace: clonedNamespace,
31468
+ });
31469
+ clonedNamespace.models = cloneTypeCollection(type.models, { namespace: clonedNamespace });
31470
+ clonedNamespace.enums = cloneTypeCollection(type.enums, { namespace: clonedNamespace });
31471
+ clonedNamespace.functionDeclarations = cloneTypeCollection(type.functionDeclarations, {
31472
+ namespace: clonedNamespace,
31473
+ });
31474
+ clonedNamespace.interfaces = cloneTypeCollection(type.interfaces, {
31475
+ namespace: clonedNamespace,
31476
+ });
31477
+ clonedNamespace.namespaces = cloneTypeCollection(type.namespaces, {
31478
+ namespace: clonedNamespace,
31479
+ });
31480
+ clonedNamespace.operations = cloneTypeCollection(type.operations, {
31481
+ namespace: clonedNamespace,
31482
+ });
31483
+ clonedNamespace.scalars = cloneTypeCollection(type.scalars, {
31484
+ namespace: clonedNamespace,
31485
+ });
31486
+ clonedNamespace.unions = cloneTypeCollection(type.unions, { namespace: clonedNamespace });
31487
+ break;
31488
+ default:
31489
+ clone = this.program.checker.createType({
31490
+ ...type,
31491
+ ...("decorators" in type ? { decorators: [...type.decorators] } : {}),
31492
+ });
31493
+ break;
31494
+ }
31495
+ this.realm.get().addType(clone);
31496
+ return clone;
31497
+ },
31498
+ },
31499
+ });
31500
+ function cloneTypeCollection(collection, options = {}) {
31501
+ const cloneCollection = new Map();
31502
+ for (const [key, type] of collection) {
31503
+ const clone = $.type.clone(type);
31504
+ if ("namespace" in clone && options.namespace) {
31505
+ clone.namespace = options.namespace;
31506
+ }
31507
+ cloneCollection.set(key, clone);
31508
+ }
31509
+ return cloneCollection;
31510
+ }
31511
+
31512
+ defineKit({
31513
+ unionVariant: {
31514
+ create(desc) {
31515
+ const variant = this.program.checker.createType({
31516
+ kind: "UnionVariant",
31517
+ name: desc.name ?? Symbol("name"),
31518
+ decorators: decoratorApplication(desc.decorators),
31519
+ type: desc.type,
31520
+ node: undefined,
31521
+ union: desc.union,
31522
+ });
31523
+ this.program.checker.finishType(variant);
31524
+ return variant;
31525
+ },
31526
+ is(type) {
31527
+ return type.kind === "UnionVariant";
31528
+ },
31529
+ },
31530
+ });
31531
+
31532
+ defineKit({
31533
+ union: {
31534
+ create(desc) {
31535
+ const union = this.program.checker.createType({
31536
+ kind: "Union",
31537
+ name: desc.name,
31538
+ decorators: decoratorApplication(desc.decorators),
31539
+ variants: createRekeyableMap(),
31540
+ get options() {
31541
+ return Array.from(this.variants.values()).map((v) => v.type);
31542
+ },
31543
+ expression: desc.name === undefined,
31544
+ node: undefined,
31545
+ });
31546
+ if (Array.isArray(desc.variants)) {
31547
+ for (const variant of desc.variants) {
31548
+ union.variants.set(variant.name, variant);
31549
+ variant.union = union;
31550
+ }
31551
+ }
31552
+ else if (desc.variants) {
31553
+ for (const [name, value] of Object.entries(desc.variants)) {
31554
+ union.variants.set(name, this.unionVariant.create({ name, type: this.literal.create(value) }));
31555
+ }
31556
+ }
31557
+ this.program.checker.finishType(union);
31558
+ return union;
31559
+ },
31560
+ is(type) {
31561
+ return type.kind === "Union";
31562
+ },
31563
+ isValidEnum(type) {
31564
+ for (const variant of type.variants.values()) {
31565
+ if (!this.literal.isString(variant.type) && !this.literal.isNumeric(variant.type)) {
31566
+ return false;
31567
+ }
31568
+ }
31569
+ return true;
31570
+ },
31571
+ isExtensible(type) {
31572
+ const variants = Array.from(type.variants.values());
31573
+ if (variants.length === 0) {
31574
+ return false;
31575
+ }
31576
+ for (let i = 0; i < variants.length; i++) {
31577
+ let isCommon = true;
31578
+ for (let j = 0; j < variants.length; j++) {
31579
+ if (i === j) {
31580
+ continue;
31581
+ }
31582
+ const assignable = ignoreDiagnostics(this.program.checker.isTypeAssignableTo(variants[j].type, variants[i].type, type));
31583
+ if (!assignable) {
31584
+ isCommon = false;
31585
+ break;
31586
+ }
31587
+ }
31588
+ if (isCommon) {
31589
+ return true;
31590
+ }
31591
+ }
31592
+ return false;
31593
+ },
31594
+ },
31595
+ });
31596
+
31597
+ /** @experimental */
31598
+ var MutatorFlow;
31599
+ (function (MutatorFlow) {
31600
+ MutatorFlow[MutatorFlow["MutateAndRecurse"] = 0] = "MutateAndRecurse";
31601
+ MutatorFlow[MutatorFlow["DoNotMutate"] = 1] = "DoNotMutate";
31602
+ MutatorFlow[MutatorFlow["DoNotRecurse"] = 2] = "DoNotRecurse";
31603
+ })(MutatorFlow || (MutatorFlow = {}));
30857
31604
 
30858
31605
  /**
30859
31606
  * Get the documentation string for the given type.
@@ -30864,6 +31611,9 @@ createTypekit();
30864
31611
  function getDoc(program, target) {
30865
31612
  return getDocDataInternal(program, target, "self")?.value;
30866
31613
  }
31614
+ // -- @format decorator ---------------------
31615
+ const [getFormat, setFormat] = useStateMap("format");
31616
+ const [getEncode, setEncodeData] = useStateMap("encode");
30867
31617
 
30868
31618
  const globalLibraryUrlsLoadedSym = Symbol.for("TYPESPEC_LIBRARY_URLS_LOADED");
30869
31619
  if (globalThis[globalLibraryUrlsLoadedSym] === undefined) {