@typespec/html-program-viewer 0.63.0-dev.1 → 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.
@@ -0,0 +1,6 @@
1
+ const manifest = {
2
+ "version": "0.63.0",
3
+ "commit": "7e344d4ae6af65297adaac7b874218e703bbbdfa"
4
+ };
5
+
6
+ export { manifest as default };
@@ -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-seJyOKYj.js')).default;
17823
+ manifest = (await import('../manifest-BeToQ_PI.js')).default;
17824
17824
  }
17825
17825
  catch {
17826
17826
  const name = "../dist/manifest.js";
@@ -18764,6 +18764,12 @@ const diagnostics = {
18764
18764
  /**
18765
18765
  * Decorator
18766
18766
  */
18767
+ "invalid-pattern-regex": {
18768
+ severity: "warning",
18769
+ messages: {
18770
+ default: "@pattern decorator expects a valid regular expression pattern.",
18771
+ },
18772
+ },
18767
18773
  "decorator-wrong-target": {
18768
18774
  severity: "error",
18769
18775
  messages: {
@@ -30919,158 +30925,15 @@ new Set([
30919
30925
  "intrinsic",
30920
30926
  ]);
30921
30927
 
30922
- const CURRENT_PROGRAM = Symbol.for("TypeSpec.currentProgram");
30923
- /** @experimental */
30924
- const TypekitPrototype = {};
30925
- /** @experimental */
30926
- function createTypekit() {
30927
- const tk = Object.create(TypekitPrototype);
30928
- Object.defineProperty(tk, "program", {
30929
- get() {
30930
- return globalThis[CURRENT_PROGRAM];
30931
- },
30932
- });
30933
- const handler = {
30934
- get(target, prop, receiver) {
30935
- const value = Reflect.get(target, prop, receiver);
30936
- if (prop === "program") {
30937
- // don't wrap program (probably need to ensure this isn't a nested program somewhere)
30938
- return value;
30939
- }
30940
- if (typeof value === "function") {
30941
- return function (...args) {
30942
- return value.apply(proxy, args);
30943
- };
30944
- }
30945
- if (typeof value === "object" && value !== null) {
30946
- return new Proxy(value, handler);
30947
- }
30948
- return value;
30949
- },
30950
- };
30951
- const proxy = new Proxy(tk, handler);
30952
- return proxy;
30953
- }
30954
- /** @experimental */
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
30928
+ var _a$1;
31056
30929
  /**
31057
- * Returns the active visibility modifiers for a property in a given visibility class.
30930
+ * A Realm's view of a Program's state map for a given state key.
31058
30931
  *
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.
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.
31061
30934
  *
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
30935
+ * @experimental
31066
30936
  */
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
30937
  class StateMapRealmView {
31075
30938
  #realm;
31076
30939
  #parentState;
@@ -31081,17 +30944,17 @@ class StateMapRealmView {
31081
30944
  this.#realmState = realmState;
31082
30945
  }
31083
30946
  has(t) {
31084
- return this.dispatch(t).has(t) ?? false;
30947
+ return this.#select(t).has(t) ?? false;
31085
30948
  }
31086
30949
  set(t, v) {
31087
- this.dispatch(t).set(t, v);
30950
+ this.#select(t).set(t, v);
31088
30951
  return this;
31089
30952
  }
31090
30953
  get(t) {
31091
- return this.dispatch(t).get(t);
30954
+ return this.#select(t).get(t);
31092
30955
  }
31093
30956
  delete(t) {
31094
- return this.dispatch(t).delete(t);
30957
+ return this.#select(t).delete(t);
31095
30958
  }
31096
30959
  forEach(cb, thisArg) {
31097
30960
  for (const item of this.entries()) {
@@ -31100,8 +30963,7 @@ class StateMapRealmView {
31100
30963
  return this;
31101
30964
  }
31102
30965
  get size() {
31103
- // extremely non-optimal, maybe worth not offering it?
31104
- return [...this.entries()].length;
30966
+ return this.#realmState.size + this.#parentState.size;
31105
30967
  }
31106
30968
  clear() {
31107
30969
  this.#realmState.clear();
@@ -31131,17 +30993,24 @@ class StateMapRealmView {
31131
30993
  return this.entries();
31132
30994
  }
31133
30995
  [Symbol.toStringTag] = "StateMap";
31134
- dispatch(keyType) {
30996
+ #select(keyType) {
31135
30997
  if (this.#realm.hasType(keyType)) {
31136
30998
  return this.#realmState;
31137
30999
  }
31138
31000
  return this.#parentState;
31139
31001
  }
31140
31002
  }
31141
- /** @experimental */
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
+ */
31142
31012
  class Realm {
31143
31013
  #program;
31144
- // Type registry
31145
31014
  /**
31146
31015
  * Stores all types owned by this realm.
31147
31016
  */
@@ -31150,14 +31019,44 @@ class Realm {
31150
31019
  * Stores types that are deleted in this realm. When a realm is active and doing a traversal, you will
31151
31020
  * not find this type in e.g. collections. Deleted types are mapped to `null` if you ask for it.
31152
31021
  */
31153
- #deletedTypes = new Set();
31022
+ #deletedTypes = new WeakSet();
31154
31023
  #stateMaps = new Map();
31155
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
+ */
31156
31031
  constructor(program, description) {
31157
31032
  this.key = Symbol(description);
31158
31033
  this.#program = program;
31159
31034
  _a$1.#knownRealms.set(this.key, this);
31160
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
+ */
31161
31060
  stateMap(stateKey) {
31162
31061
  let m = this.#stateMaps.get(stateKey);
31163
31062
  if (!m) {
@@ -31166,24 +31065,50 @@ class Realm {
31166
31065
  }
31167
31066
  return new StateMapRealmView(this, m, this.#program.stateMap(stateKey));
31168
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
+ */
31169
31074
  clone(type) {
31170
31075
  compilerAssert(type, "Undefined type passed to clone");
31171
31076
  const clone = this.#cloneIntoRealm(type);
31172
- $.type.finishType(clone);
31077
+ this.typekit.type.finishType(clone);
31173
31078
  return clone;
31174
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
+ */
31175
31086
  remove(type) {
31176
31087
  this.#deletedTypes.add(type);
31177
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
+ */
31178
31095
  hasType(type) {
31179
31096
  return this.#types.has(type);
31180
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
+ */
31181
31106
  addType(type) {
31182
31107
  this.#types.add(type);
31183
31108
  _a$1.realmForType.set(type, this);
31184
31109
  }
31185
31110
  #cloneIntoRealm(type) {
31186
- const clone = $.type.clone(type);
31111
+ const clone = this.typekit.type.clone(type);
31187
31112
  this.#types.add(clone);
31188
31113
  _a$1.realmForType.set(clone, this);
31189
31114
  return clone;
@@ -31192,10 +31117,32 @@ class Realm {
31192
31117
  static realmForKey(key, parentRealm) {
31193
31118
  return this.#knownRealms.get(key);
31194
31119
  }
31195
- static realmForType = new Map();
31120
+ static realmForType = new WeakMap();
31196
31121
  }
31197
31122
  _a$1 = Realm;
31198
31123
 
31124
+ /**
31125
+ * The prototype object for Typekit instances.
31126
+ *
31127
+ * @see {@link defineKit}
31128
+ *
31129
+ * @experimental
31130
+ * @internal
31131
+ */
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
+
31199
31146
  defineKit({
31200
31147
  literal: {
31201
31148
  create(value) {
@@ -31245,6 +31192,156 @@ defineKit({
31245
31192
  },
31246
31193
  });
31247
31194
 
31195
+ /** @experimental */
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
+
31248
31345
  defineKit({
31249
31346
  modelProperty: {
31250
31347
  is(type) {
@@ -31262,30 +31359,42 @@ defineKit({
31262
31359
  },
31263
31360
  });
31264
31361
 
31265
- /** @experimental */
31362
+ /**
31363
+ * Creates a shallow copy of a rekeyable map.
31364
+ *
31365
+ * @experimental
31366
+ */
31266
31367
  function copyMap(map) {
31267
- return createRekeyableMap(Array.from(map.entries()));
31368
+ return createRekeyableMap(map.entries());
31268
31369
  }
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;
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
+ }) ?? []);
31289
31398
  }
31290
31399
 
31291
31400
  defineKit({
@@ -31295,7 +31404,7 @@ defineKit({
31295
31404
  const model = this.program.checker.createType({
31296
31405
  kind: "Model",
31297
31406
  name: desc.name ?? "",
31298
- decorators: decoratorApplication(desc.decorators),
31407
+ decorators: decoratorApplication(this, desc.decorators),
31299
31408
  properties: properties,
31300
31409
  expression: desc.name === undefined,
31301
31410
  node: undefined,
@@ -31311,21 +31420,6 @@ defineKit({
31311
31420
  },
31312
31421
  });
31313
31422
 
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
31423
  defineKit({
31330
31424
  scalar: {
31331
31425
  is(type) {
@@ -31463,27 +31557,33 @@ defineKit({
31463
31557
  projections: [...type.projections],
31464
31558
  });
31465
31559
  const clonedNamespace = clone;
31466
- clonedNamespace.decoratorDeclarations = cloneTypeCollection(type.decoratorDeclarations, {
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, {
31467
31570
  namespace: clonedNamespace,
31468
31571
  });
31469
- clonedNamespace.models = cloneTypeCollection(type.models, { namespace: clonedNamespace });
31470
- clonedNamespace.enums = cloneTypeCollection(type.enums, { namespace: clonedNamespace });
31471
- clonedNamespace.functionDeclarations = cloneTypeCollection(type.functionDeclarations, {
31572
+ clonedNamespace.interfaces = cloneTypeCollection(this, type.interfaces, {
31472
31573
  namespace: clonedNamespace,
31473
31574
  });
31474
- clonedNamespace.interfaces = cloneTypeCollection(type.interfaces, {
31575
+ clonedNamespace.namespaces = cloneTypeCollection(this, type.namespaces, {
31475
31576
  namespace: clonedNamespace,
31476
31577
  });
31477
- clonedNamespace.namespaces = cloneTypeCollection(type.namespaces, {
31578
+ clonedNamespace.operations = cloneTypeCollection(this, type.operations, {
31478
31579
  namespace: clonedNamespace,
31479
31580
  });
31480
- clonedNamespace.operations = cloneTypeCollection(type.operations, {
31581
+ clonedNamespace.scalars = cloneTypeCollection(this, type.scalars, {
31481
31582
  namespace: clonedNamespace,
31482
31583
  });
31483
- clonedNamespace.scalars = cloneTypeCollection(type.scalars, {
31584
+ clonedNamespace.unions = cloneTypeCollection(this, type.unions, {
31484
31585
  namespace: clonedNamespace,
31485
31586
  });
31486
- clonedNamespace.unions = cloneTypeCollection(type.unions, { namespace: clonedNamespace });
31487
31587
  break;
31488
31588
  default:
31489
31589
  clone = this.program.checker.createType({
@@ -31492,15 +31592,15 @@ defineKit({
31492
31592
  });
31493
31593
  break;
31494
31594
  }
31495
- this.realm.get().addType(clone);
31595
+ this.realm.addType(clone);
31496
31596
  return clone;
31497
31597
  },
31498
31598
  },
31499
31599
  });
31500
- function cloneTypeCollection(collection, options = {}) {
31600
+ function cloneTypeCollection(kit, collection, options = {}) {
31501
31601
  const cloneCollection = new Map();
31502
31602
  for (const [key, type] of collection) {
31503
- const clone = $.type.clone(type);
31603
+ const clone = kit.type.clone(type);
31504
31604
  if ("namespace" in clone && options.namespace) {
31505
31605
  clone.namespace = options.namespace;
31506
31606
  }
@@ -31515,7 +31615,7 @@ defineKit({
31515
31615
  const variant = this.program.checker.createType({
31516
31616
  kind: "UnionVariant",
31517
31617
  name: desc.name ?? Symbol("name"),
31518
- decorators: decoratorApplication(desc.decorators),
31618
+ decorators: decoratorApplication(this, desc.decorators),
31519
31619
  type: desc.type,
31520
31620
  node: undefined,
31521
31621
  union: desc.union,
@@ -31535,7 +31635,7 @@ defineKit({
31535
31635
  const union = this.program.checker.createType({
31536
31636
  kind: "Union",
31537
31637
  name: desc.name,
31538
- decorators: decoratorApplication(desc.decorators),
31638
+ decorators: decoratorApplication(this, desc.decorators),
31539
31639
  variants: createRekeyableMap(),
31540
31640
  get options() {
31541
31641
  return Array.from(this.variants.values()).map((v) => v.type);
@@ -31594,26 +31694,117 @@ defineKit({
31594
31694
  },
31595
31695
  });
31596
31696
 
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 = {}));
31604
-
31605
31697
  /**
31606
- * Get the documentation string for the given type.
31607
- * @param program Program
31608
- * @param target Type
31609
- * @returns Documentation value
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
31610
31707
  */
31611
- function getDoc(program, target) {
31612
- return getDocDataInternal(program, target, "self")?.value;
31708
+ function createTypekit(realm) {
31709
+ const tk = Object.create(TypekitPrototype);
31710
+ const handler = {
31711
+ get(target, prop, receiver) {
31712
+ if (prop === "program") {
31713
+ // don't wrap program (probably need to ensure this isn't a nested program somewhere)
31714
+ return realm.program;
31715
+ }
31716
+ if (prop === "realm") {
31717
+ return realm;
31718
+ }
31719
+ const value = Reflect.get(target, prop, receiver);
31720
+ if (typeof value === "function") {
31721
+ return function (...args) {
31722
+ return value.apply(proxy, args);
31723
+ };
31724
+ }
31725
+ if (typeof value === "object" && value !== null) {
31726
+ return new Proxy(value, handler);
31727
+ }
31728
+ return value;
31729
+ },
31730
+ };
31731
+ const proxy = new Proxy(tk, handler);
31732
+ return proxy;
31613
31733
  }
31614
- // -- @format decorator ---------------------
31615
- const [getFormat, setFormat] = useStateMap("format");
31616
- const [getEncode, setEncodeData] = useStateMap("encode");
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
+ }
31752
+ /**
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
31793
+ */
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
31617
31808
 
31618
31809
  const globalLibraryUrlsLoadedSym = Symbol.for("TYPESPEC_LIBRARY_URLS_LOADED");
31619
31810
  if (globalThis[globalLibraryUrlsLoadedSym] === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/html-program-viewer",
3
- "version": "0.63.0-dev.1",
3
+ "version": "0.63.0",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec library for emitting an html view of the program.",
6
6
  "homepage": "https://typespec.io",
@@ -36,7 +36,7 @@
36
36
  "!dist/test/**"
37
37
  ],
38
38
  "peerDependencies": {
39
- "@typespec/compiler": "~0.62.0 || >=0.63.0-dev <0.63.0"
39
+ "@typespec/compiler": "~0.63.0"
40
40
  },
41
41
  "dependencies": {
42
42
  "@fluentui/react-components": "~9.55.0",
@@ -54,7 +54,6 @@
54
54
  "@types/node": "~22.7.9",
55
55
  "@types/react": "~18.3.11",
56
56
  "@types/react-dom": "~18.3.0",
57
- "@typespec/compiler": "~0.62.0 || >=0.63.0-dev <0.63.0",
58
57
  "@vitejs/plugin-react": "~4.3.2",
59
58
  "@vitest/coverage-v8": "^2.1.5",
60
59
  "@vitest/ui": "^2.1.2",
@@ -65,6 +64,7 @@
65
64
  "vite-plugin-checker": "^0.8.0",
66
65
  "vite-plugin-dts": "4.2.3",
67
66
  "vitest": "^2.1.5",
67
+ "@typespec/compiler": "~0.63.0",
68
68
  "@typespec/react-components": "~0.57.0"
69
69
  },
70
70
  "scripts": {
@@ -1,6 +0,0 @@
1
- const manifest = {
2
- "version": "0.62.0",
3
- "commit": "0f8b1e27e64c6c1d2938404b6d67f2809c6c11fc"
4
- };
5
-
6
- export { manifest as default };