@typespec/html-program-viewer 0.70.0-dev.0 → 0.70.0-dev.2

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.
@@ -1,6 +1,6 @@
1
1
  const manifest = {
2
2
  "version": "1.0.0-rc.1",
3
- "commit": "8d8982d1807b64ff053bcf9ed89a22c8d1d994fe"
3
+ "commit": "34733d7d8f55b3bd12be9f3b2be115dbde3c014b"
4
4
  };
5
5
 
6
6
  export { manifest as default };
@@ -28794,6 +28794,14 @@ defineKit({
28794
28794
  },
28795
28795
  });
28796
28796
 
28797
+ defineKit({
28798
+ entity: {
28799
+ isAssignableTo: createDiagnosable(function (source, target, diagnosticTarget) {
28800
+ return this.program.checker.isTypeAssignableTo(source, target, diagnosticTarget ?? source);
28801
+ }),
28802
+ },
28803
+ });
28804
+
28797
28805
  /**
28798
28806
  * Creates a shallow copy of a rekeyable map.
28799
28807
  *
@@ -31165,6 +31173,26 @@ defineKit({
31165
31173
  },
31166
31174
  });
31167
31175
 
31176
+ defineKit({
31177
+ intrinsic: {
31178
+ get any() {
31179
+ return this.program.checker.anyType;
31180
+ },
31181
+ get error() {
31182
+ return this.program.checker.errorType;
31183
+ },
31184
+ get never() {
31185
+ return this.program.checker.neverType;
31186
+ },
31187
+ get null() {
31188
+ return this.program.checker.nullType;
31189
+ },
31190
+ get void() {
31191
+ return this.program.checker.voidType;
31192
+ },
31193
+ },
31194
+ });
31195
+
31168
31196
  class InvalidNumericError extends Error {
31169
31197
  code = "InvalidNumeric";
31170
31198
  }
@@ -31571,6 +31599,12 @@ defineKit({
31571
31599
  },
31572
31600
  });
31573
31601
 
31602
+ defineKit({
31603
+ resolve: createDiagnosable(function (reference) {
31604
+ return this.program.resolveTypeOrValueReference(reference);
31605
+ }),
31606
+ });
31607
+
31574
31608
  defineKit({
31575
31609
  scalar: {
31576
31610
  is(type) {
@@ -31828,6 +31862,46 @@ defineKit({
31828
31862
  isUserDefined(type) {
31829
31863
  return getLocationContext(this.program, type).type === "project";
31830
31864
  },
31865
+ inNamespace(type, namespace) {
31866
+ // A namespace is always in itself
31867
+ if (type === namespace) {
31868
+ return true;
31869
+ }
31870
+ // Handle types with known containers
31871
+ switch (type.kind) {
31872
+ case "ModelProperty":
31873
+ if (type.model) {
31874
+ return this.type.inNamespace(type.model, namespace);
31875
+ }
31876
+ break;
31877
+ case "EnumMember":
31878
+ return this.type.inNamespace(type.enum, namespace);
31879
+ case "UnionVariant":
31880
+ return this.type.inNamespace(type.union, namespace);
31881
+ case "Operation":
31882
+ if (type.interface) {
31883
+ return this.type.inNamespace(type.interface, namespace);
31884
+ }
31885
+ // Operations that belong to a namespace directly will be handled in the generic case
31886
+ break;
31887
+ }
31888
+ // Generic case handles all other types
31889
+ if ("namespace" in type && type.namespace) {
31890
+ return this.type.inNamespace(type.namespace, namespace);
31891
+ }
31892
+ // If we got this far, the type does not belong to the namespace
31893
+ return false;
31894
+ },
31895
+ isAssignableTo: createDiagnosable(function (source, target, diagnosticTarget) {
31896
+ return this.program.checker.isTypeAssignableTo(source, target, diagnosticTarget ?? source);
31897
+ }),
31898
+ resolve: createDiagnosable(function (reference, kind) {
31899
+ const [type, diagnostics] = this.program.resolveTypeReference(reference);
31900
+ if (type && kind && type.kind !== kind) {
31901
+ throw new Error(`Type kind mismatch: expected ${kind}, got ${type.kind}`);
31902
+ }
31903
+ return [type, diagnostics];
31904
+ }),
31831
31905
  },
31832
31906
  });
31833
31907
 
@@ -31856,25 +31930,43 @@ defineKit({
31856
31930
  const variants = Array.from(union.variants.values()).filter(filterFn);
31857
31931
  return this.union.create({ variants });
31858
31932
  },
31859
- create(desc) {
31933
+ create(descOrChildren) {
31934
+ let descriptor;
31935
+ if (Array.isArray(descOrChildren)) {
31936
+ // Build a descriptor from the children
31937
+ descriptor = {
31938
+ decorators: [],
31939
+ variants: descOrChildren.map((child) => {
31940
+ const memberDoc = getDoc(this.program, child);
31941
+ return this.unionVariant.create({
31942
+ type: child,
31943
+ decorators: memberDoc ? [[$doc, memberDoc]] : undefined,
31944
+ });
31945
+ }),
31946
+ };
31947
+ }
31948
+ else {
31949
+ // Already a descriptor
31950
+ descriptor = descOrChildren;
31951
+ }
31860
31952
  const union = this.program.checker.createType({
31861
31953
  kind: "Union",
31862
- name: desc.name,
31863
- decorators: decoratorApplication(this, desc.decorators),
31954
+ name: descriptor.name,
31955
+ decorators: decoratorApplication(this, descriptor.decorators),
31864
31956
  variants: createRekeyableMap(),
31865
31957
  get options() {
31866
31958
  return Array.from(this.variants.values()).map((v) => v.type);
31867
31959
  },
31868
- expression: desc.name === undefined,
31960
+ expression: descriptor.name === undefined,
31869
31961
  });
31870
- if (Array.isArray(desc.variants)) {
31871
- for (const variant of desc.variants) {
31962
+ if (Array.isArray(descriptor.variants)) {
31963
+ for (const variant of descriptor.variants) {
31872
31964
  union.variants.set(variant.name, variant);
31873
31965
  variant.union = union;
31874
31966
  }
31875
31967
  }
31876
- else if (desc.variants) {
31877
- for (const [name, value] of Object.entries(desc.variants)) {
31968
+ else if (descriptor.variants) {
31969
+ for (const [name, value] of Object.entries(descriptor.variants)) {
31878
31970
  union.variants.set(name, this.unionVariant.create({ name, type: this.literal.create(value) }));
31879
31971
  }
31880
31972
  }
@@ -32016,6 +32108,19 @@ defineKit({
32016
32108
  isScalar(type) {
32017
32109
  return type.valueKind === "ScalarValue";
32018
32110
  },
32111
+ isAssignableTo: createDiagnosable(function (source, target, diagnosticTarget) {
32112
+ return this.program.checker.isTypeAssignableTo(source, target, diagnosticTarget ?? source);
32113
+ }),
32114
+ resolve: createDiagnosable(function (reference, kind) {
32115
+ const [value, diagnostics] = this.program.resolveTypeOrValueReference(reference);
32116
+ if (value && !isValue(value)) {
32117
+ return [undefined, diagnostics];
32118
+ }
32119
+ if (value && kind && value.valueKind !== kind) {
32120
+ throw new Error(`Value kind mismatch: expected ${kind}, got ${value.valueKind}`);
32121
+ }
32122
+ return [value, diagnostics];
32123
+ }),
32019
32124
  },
32020
32125
  });
32021
32126
 
@@ -32067,9 +32172,11 @@ function createTypekit(realm) {
32067
32172
  }
32068
32173
  return proxyWrapper;
32069
32174
  }
32070
- // Only wrap objects marked as Typekit namespaces
32071
- if (typeof value === "object" && value !== null && isTypekitNamespace(value)) {
32072
- return new Proxy(value, handler); // Wrap namespace objects
32175
+ // Wrap objects to ensure their functions are bound correctly, avoid wrapping `get` accessors
32176
+ if (typeof value === "object" &&
32177
+ value !== null &&
32178
+ !Reflect.getOwnPropertyDescriptor(target, prop)?.get) {
32179
+ return new Proxy(value, handler);
32073
32180
  }
32074
32181
  return value;
32075
32182
  },
@@ -32077,10 +32184,6 @@ function createTypekit(realm) {
32077
32184
  const proxy = new Proxy(tk, handler);
32078
32185
  return proxy;
32079
32186
  }
32080
- // Helper function to check if an object is a Typekit namespace
32081
- function isTypekitNamespace(obj) {
32082
- return obj && !!obj[TypekitNamespaceSymbol];
32083
- }
32084
32187
  // #region Default Typekit
32085
32188
  const DEFAULT_REALM = Symbol.for("TypeSpec.Typekit.DEFAULT_TYPEKIT_REALM");
32086
32189
  function _$(arg) {
@@ -32320,9 +32423,22 @@ class Realm {
32320
32423
  get types() {
32321
32424
  return this.#types;
32322
32425
  }
32323
- static realmForType = new WeakMap();
32426
+ static realmForType = singleton("Realm.realmForType", () => new WeakMap());
32324
32427
  }
32325
32428
  _a = Realm;
32429
+ /**
32430
+ * Create a singleton instance that is shared across the process.
32431
+ * This is to have a true singleton even if multiple instance of the compiler/library are loaded.
32432
+ * @param key - The key to use for the singleton.
32433
+ * @param init - The function to call to create the singleton.
32434
+ */
32435
+ function singleton(key, init) {
32436
+ const sym = Symbol.for(key);
32437
+ if (!globalThis[sym]) {
32438
+ globalThis[sym] = init();
32439
+ }
32440
+ return globalThis[sym];
32441
+ }
32326
32442
 
32327
32443
  /**
32328
32444
  * The fixed set of options for each of the kinds of delimited lists in TypeSpec.
@@ -34000,7 +34116,7 @@ let manifest;
34000
34116
  try {
34001
34117
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
34002
34118
  // @ts-ignore
34003
- manifest = (await import('../manifest-DR_CKuUi.js')).default;
34119
+ manifest = (await import('../manifest-uxZ2CVxd.js')).default;
34004
34120
  }
34005
34121
  catch {
34006
34122
  const name = "../dist/manifest.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/html-program-viewer",
3
- "version": "0.70.0-dev.0",
3
+ "version": "0.70.0-dev.2",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec library for emitting an html view of the program.",
6
6
  "homepage": "https://typespec.io",
@@ -56,8 +56,8 @@
56
56
  "@types/react-dom": "~18.3.0",
57
57
  "@typespec/compiler": "^1.0.0-rc.1",
58
58
  "@vitejs/plugin-react": "~4.3.4",
59
- "@vitest/coverage-v8": "^3.0.9",
60
- "@vitest/ui": "^3.0.9",
59
+ "@vitest/coverage-v8": "^3.1.2",
60
+ "@vitest/ui": "^3.1.2",
61
61
  "c8": "^10.1.3",
62
62
  "rimraf": "~6.0.1",
63
63
  "typescript": "~5.8.2",
@@ -65,7 +65,7 @@
65
65
  "vite-plugin-checker": "^0.9.1",
66
66
  "vite-plugin-dts": "4.5.3",
67
67
  "vite-plugin-node-polyfills": "^0.23.0",
68
- "vitest": "^3.0.9",
68
+ "vitest": "^3.1.2",
69
69
  "@typespec/react-components": "^0.57.0"
70
70
  },
71
71
  "scripts": {