@yuhere/js-jsonrpc2 2.1.13 → 2.1.15

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.
@@ -9204,7 +9204,8 @@ var KIND_COLORS$1 = {
9204
9204
  enum: "var(--syn-union)",
9205
9205
  unknown: "var(--syn-muted)",
9206
9206
  null: "var(--syn-muted)",
9207
- stream: "var(--syn-container)"
9207
+ stream: "var(--syn-container)",
9208
+ void: "var(--syn-muted)"
9208
9209
  };
9209
9210
  function colorOf$1(kind) {
9210
9211
  return KIND_COLORS$1[kind] ?? "var(--fg)";
@@ -9214,21 +9215,37 @@ function formatConstraints$1(constraints) {
9214
9215
  if (!constraints) return "";
9215
9216
  const entries = Object.entries(constraints).filter(([, v]) => v !== void 0);
9216
9217
  if (entries.length === 0) return "";
9217
- return entries.map(([k, v]) => `${k}=${typeof v === "string" ? JSON.stringify(v) : JSON.stringify(v)}`).join(", ");
9218
+ return entries.map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(", ");
9219
+ }
9220
+ function isSchemaDescription(v) {
9221
+ return !!v && typeof v === "object" && typeof v.kind === "string";
9222
+ }
9223
+ function hasChildNodes(schema) {
9224
+ switch (schema.kind) {
9225
+ case "array": return isSchemaDescription(schema.element);
9226
+ case "record": return isSchemaDescription(schema.value);
9227
+ case "tuple": return Array.isArray(schema.elements) && schema.elements.some(isSchemaDescription);
9228
+ case "union": return Array.isArray(schema.options) && schema.options.some(isSchemaDescription);
9229
+ case "object": return !!schema.properties && typeof schema.properties === "object" && !Array.isArray(schema.properties) && Object.values(schema.properties).some(isSchemaDescription);
9230
+ case "stream": return !!(isSchemaDescription(schema.inner) ? schema.inner : void 0);
9231
+ default: return false;
9232
+ }
9218
9233
  }
9219
9234
  function SchemaNode({ schema, depth, defaultOpen, label }) {
9220
9235
  const t = useT();
9221
9236
  const [open, setOpen] = (0, import_react.useState)(defaultOpen);
9222
- const hasChildren = schema.children && Object.keys(schema.children).length > 0;
9237
+ const anySchema = schema;
9238
+ const expandable = hasChildNodes(anySchema);
9223
9239
  const constraintsText = formatConstraints$1(schema.constraints);
9240
+ const validationOff = anySchema.validate === false;
9224
9241
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
9225
9242
  className: "schema-node",
9226
9243
  style: { paddingLeft: depth * 14 },
9227
9244
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
9228
9245
  className: "schema-head",
9229
- onClick: () => hasChildren && setOpen((o) => !o),
9246
+ onClick: () => expandable && setOpen((o) => !o),
9230
9247
  children: [
9231
- hasChildren ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9248
+ expandable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9232
9249
  className: "schema-expander",
9233
9250
  children: open ? "▾" : "▸"
9234
9251
  }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "schema-expander" }),
@@ -9249,76 +9266,94 @@ function SchemaNode({ schema, depth, defaultOpen, label }) {
9249
9266
  className: "schema-nullable-badge",
9250
9267
  children: "nullable"
9251
9268
  }),
9252
- constraintsText && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9269
+ validationOff && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9270
+ className: "schema-nullable-badge",
9271
+ title: t("schema.validationOff"),
9272
+ children: "no-validate"
9273
+ }),
9274
+ constraintsText ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9253
9275
  className: "schema-constraints",
9254
9276
  children: `{ ${constraintsText} }`
9255
- }),
9256
- schema.description && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
9277
+ }) : null,
9278
+ schema.description ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
9257
9279
  className: "schema-description",
9258
- title: schema.description,
9259
- children: [
9260
- " ",
9261
- "// ",
9262
- schema.description
9263
- ]
9264
- })
9280
+ children: ["— ", schema.description]
9281
+ }) : null
9265
9282
  ]
9266
- }), open && hasChildren && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
9283
+ }), expandable && open && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
9267
9284
  className: "schema-children",
9268
- children: renderChildren(schema, depth + 1, t)
9285
+ children: renderChildren(anySchema, depth + 1, t)
9269
9286
  })]
9270
9287
  });
9271
9288
  }
9289
+ /**
9290
+ * 子节点渲染约定:
9291
+ * - array / record / stream:直接展开,不挂 element / value / inner 标签
9292
+ * - object:属性名作标签
9293
+ * - union:option[i]
9294
+ * - tuple:[i]
9295
+ */
9272
9296
  function renderChildren(schema, depth, t) {
9273
- const c = schema.children ?? {};
9274
9297
  const out = [];
9275
- if (c.inner && isSchemaDescription(c.inner)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9276
- schema: c.inner,
9277
- depth,
9278
- defaultOpen: true,
9279
- label: t("schema.inner")
9280
- }, "inner"));
9281
- if (Array.isArray(c.items)) c.items.forEach((item, i) => {
9282
- if (isSchemaDescription(item)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9283
- schema: item,
9284
- depth,
9285
- defaultOpen: true,
9286
- label: String(i)
9287
- }, `item-${i}`));
9288
- });
9289
- else if (c.items && isSchemaDescription(c.items)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9290
- schema: c.items,
9291
- depth,
9292
- defaultOpen: true,
9293
- label: t("schema.items")
9294
- }, "items"));
9295
- if (Array.isArray(c.options)) c.options.forEach((opt, i) => {
9296
- if (isSchemaDescription(opt)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9297
- schema: opt,
9298
- depth,
9299
- defaultOpen: false,
9300
- label: t("schema.optionIndex", { index: i })
9301
- }, `opt-${i}`));
9302
- });
9303
- if (c.properties && typeof c.properties === "object" && !Array.isArray(c.properties)) {
9304
- for (const [key, prop] of Object.entries(c.properties)) if (isSchemaDescription(prop)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9305
- schema: prop,
9306
- depth,
9307
- defaultOpen: true,
9308
- label: key
9309
- }, `prop-${key}`));
9298
+ switch (schema.kind) {
9299
+ case "array":
9300
+ if (isSchemaDescription(schema.element)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9301
+ schema: schema.element,
9302
+ depth,
9303
+ defaultOpen: true
9304
+ }, "element"));
9305
+ break;
9306
+ case "record":
9307
+ if (isSchemaDescription(schema.value)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9308
+ schema: schema.value,
9309
+ depth,
9310
+ defaultOpen: true
9311
+ }, "value"));
9312
+ break;
9313
+ case "tuple":
9314
+ if (Array.isArray(schema.elements)) schema.elements.forEach((item, i) => {
9315
+ if (isSchemaDescription(item)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9316
+ schema: item,
9317
+ depth,
9318
+ defaultOpen: true,
9319
+ label: String(i)
9320
+ }, `el-${i}`));
9321
+ });
9322
+ break;
9323
+ case "union":
9324
+ if (Array.isArray(schema.options)) schema.options.forEach((opt, i) => {
9325
+ if (isSchemaDescription(opt)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9326
+ schema: opt,
9327
+ depth,
9328
+ defaultOpen: false,
9329
+ label: t("schema.optionIndex", { index: i })
9330
+ }, `opt-${i}`));
9331
+ });
9332
+ break;
9333
+ case "object": {
9334
+ const props = schema.properties;
9335
+ if (props && typeof props === "object" && !Array.isArray(props)) {
9336
+ for (const [key, prop] of Object.entries(props)) if (isSchemaDescription(prop)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9337
+ schema: prop,
9338
+ depth,
9339
+ defaultOpen: true,
9340
+ label: key
9341
+ }, `prop-${key}`));
9342
+ }
9343
+ break;
9344
+ }
9345
+ case "stream": {
9346
+ const inner = isSchemaDescription(schema.inner) ? schema.inner : void 0;
9347
+ if (inner) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9348
+ schema: inner,
9349
+ depth,
9350
+ defaultOpen: true
9351
+ }, "inner"));
9352
+ break;
9353
+ }
9310
9354
  }
9311
- if (c.values && isSchemaDescription(c.values)) out.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9312
- schema: c.values,
9313
- depth,
9314
- defaultOpen: true,
9315
- label: t("schema.values")
9316
- }, "values"));
9317
9355
  return out;
9318
9356
  }
9319
- function isSchemaDescription(v) {
9320
- return !!v && typeof v === "object" && typeof v.kind === "string";
9321
- }
9322
9357
  function SchemaView({ schema, defaultOpen = true, depth = 0 }) {
9323
9358
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaNode, {
9324
9359
  schema,
@@ -9387,12 +9422,11 @@ function isSchema$1(v) {
9387
9422
  * - 原始类型返回零值(''、0、false)
9388
9423
  * - literal 返回固定值
9389
9424
  * - enum 返回第一个枚举值
9390
- * - 容器类型递归展开
9425
+ * - 容器类型递归展开(按新字段:element / value / properties / options / elements)
9391
9426
  * - unknown 返回 null
9392
9427
  */
9393
9428
  function sampleFromSchema(schema) {
9394
9429
  if (schema.nullable) return null;
9395
- const c = schema.children ?? {};
9396
9430
  switch (schema.kind) {
9397
9431
  case "string": return "";
9398
9432
  case "number": return 0;
@@ -9403,19 +9437,19 @@ function sampleFromSchema(schema) {
9403
9437
  const values = schema.constraints?.values;
9404
9438
  return Array.isArray(values) && values.length > 0 ? values[0] : "";
9405
9439
  }
9406
- case "array": return [isSchema$1(c.items) ? sampleFromSchema(c.items) : null];
9407
- case "tuple": return (Array.isArray(c.items) ? c.items : []).map((it) => isSchema$1(it) ? sampleFromSchema(it) : null);
9440
+ case "array": return [isSchema$1(schema.element) ? sampleFromSchema(schema.element) : null];
9441
+ case "tuple": return (Array.isArray(schema.elements) ? schema.elements : []).map((it) => isSchema$1(it) ? sampleFromSchema(it) : null);
9408
9442
  case "union": {
9409
- const options = Array.isArray(c.options) ? c.options : [];
9443
+ const options = Array.isArray(schema.options) ? schema.options : [];
9410
9444
  return options.length > 0 && isSchema$1(options[0]) ? sampleFromSchema(options[0]) : null;
9411
9445
  }
9412
9446
  case "object": {
9413
- const props = c.properties ?? {};
9447
+ const props = schema.properties ?? {};
9414
9448
  const out = {};
9415
9449
  for (const [k, v] of Object.entries(props)) if (isSchema$1(v)) out[k] = sampleFromSchema(v);
9416
9450
  return out;
9417
9451
  }
9418
- case "record": return { key: isSchema$1(c.values) ? sampleFromSchema(c.values) : null };
9452
+ case "record": return { key: isSchema$1(schema.value) ? sampleFromSchema(schema.value) : null };
9419
9453
  default: return null;
9420
9454
  }
9421
9455
  }
@@ -9558,7 +9592,7 @@ function SchemaField({ schema, value, onChange, label, depth = 0, defaultOpen =
9558
9592
  })]
9559
9593
  });
9560
9594
  if (kind === "union") {
9561
- const options = Array.isArray(schema.children?.options) ? schema.children.options.filter(isSchema$1) : [];
9595
+ const options = Array.isArray(schema.options) ? schema.options.filter(isSchema$1) : [];
9562
9596
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
9563
9597
  className: "sf-node sf-row",
9564
9598
  style: { paddingLeft: depth * 14 },
@@ -9744,9 +9778,8 @@ function UnionField({ options, value, onChange, depth, disabled }) {
9744
9778
  }
9745
9779
  function ContainerChildren({ schema, value, onChange, depth, disabled }) {
9746
9780
  const t = useT();
9747
- const c = schema.children ?? {};
9748
9781
  if (schema.kind === "array") {
9749
- const itemSchema = isSchema$1(c.items) ? c.items : void 0;
9782
+ const itemSchema = isSchema$1(schema.element) ? schema.element : void 0;
9750
9783
  if (!itemSchema) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
9751
9784
  className: "hint",
9752
9785
  children: t("schema.arrayNoItem")
@@ -9782,7 +9815,7 @@ function ContainerChildren({ schema, value, onChange, depth, disabled }) {
9782
9815
  })] });
9783
9816
  }
9784
9817
  if (schema.kind === "tuple") {
9785
- const items = Array.isArray(c.items) ? c.items.filter(isSchema$1) : [];
9818
+ const items = Array.isArray(schema.elements) ? schema.elements.filter(isSchema$1) : [];
9786
9819
  const arr = Array.isArray(value) ? value : [];
9787
9820
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: items.map((itemSchema, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaField, {
9788
9821
  schema: itemSchema,
@@ -9799,9 +9832,9 @@ function ContainerChildren({ schema, value, onChange, depth, disabled }) {
9799
9832
  }, i)) });
9800
9833
  }
9801
9834
  if (schema.kind === "object") {
9802
- const props = c.properties ?? {};
9835
+ const props = schema.properties ?? {};
9803
9836
  const obj = value && typeof value === "object" && !Array.isArray(value) ? value : {};
9804
- const strict = Boolean(schema.constraints?.strict);
9837
+ const allowUnknown = schema.constraints?.allowUnknownProps !== false;
9805
9838
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [Object.entries(props).map(([key, prop]) => {
9806
9839
  if (!isSchema$1(prop)) return null;
9807
9840
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SchemaField, {
@@ -9818,7 +9851,7 @@ function ContainerChildren({ schema, value, onChange, depth, disabled }) {
9818
9851
  disabled,
9819
9852
  defaultOpen: false
9820
9853
  }, key);
9821
- }), !strict && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
9854
+ }), allowUnknown && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
9822
9855
  className: "hint",
9823
9856
  style: {
9824
9857
  paddingLeft: depth * 14,
@@ -9828,7 +9861,7 @@ function ContainerChildren({ schema, value, onChange, depth, disabled }) {
9828
9861
  })] });
9829
9862
  }
9830
9863
  if (schema.kind === "record") {
9831
- const valueSchema = isSchema$1(c.values) ? c.values : void 0;
9864
+ const valueSchema = isSchema$1(schema.value) ? schema.value : void 0;
9832
9865
  if (!valueSchema) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
9833
9866
  className: "hint",
9834
9867
  children: t("schema.recordNoValue")
@@ -10640,7 +10673,7 @@ function Footer() {
10640
10673
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
10641
10674
  className: "footer-version",
10642
10675
  title: t("footer.version"),
10643
- children: ["v", "2.1.13"]
10676
+ children: ["v", "2.1.15"]
10644
10677
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
10645
10678
  className: "footer-links",
10646
10679
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
@@ -10746,11 +10779,20 @@ async function collectApiDoc(rpc, methods, onProgress) {
10746
10779
  methods: out
10747
10780
  };
10748
10781
  }
10782
+ /**
10783
+ * 树状渲染 schema。
10784
+ * - array / record / stream:直接展开子节点,不挂 element / value / inner 标签
10785
+ * - object:属性名作标签
10786
+ * - union:option[i]
10787
+ * - tuple:[i]
10788
+ * - validate === false 时在行尾标注 _(no validate)_
10789
+ */
10749
10790
  function renderSchemaTree(schema, indent = 0) {
10750
10791
  const pad = " ".repeat(indent);
10751
10792
  const lines = [];
10752
10793
  let head = `${pad}- \`${schema.kind}\``;
10753
10794
  if (schema.nullable) head += " _(nullable)_";
10795
+ if (schema.validate === false) head += " _(no validate)_";
10754
10796
  if (schema.description) head += ` — ${schema.description}`;
10755
10797
  const c = schema.constraints;
10756
10798
  if (c && Object.keys(c).length > 0) {
@@ -10758,26 +10800,57 @@ function renderSchemaTree(schema, indent = 0) {
10758
10800
  if (parts.length) head += ` \`{ ${parts.join(", ")} }\``;
10759
10801
  }
10760
10802
  lines.push(head);
10761
- const ch = schema.children ?? {};
10762
- const pushChild = (label, child) => {
10803
+ /** 带标签的子节点(object 属性 / union 分支 / tuple 位) */
10804
+ const pushLabeled = (label, child) => {
10763
10805
  const sub = renderSchemaTree(child, indent + 1);
10764
10806
  if (sub.length) {
10765
10807
  sub[0] = `${" ".repeat(indent + 1)}- **${label}**: ${sub[0].trim().replace(/^- /, "")}`;
10766
10808
  lines.push(...sub);
10767
10809
  }
10768
10810
  };
10769
- if (isSchema(ch.inner)) pushChild("inner", ch.inner);
10770
- if (Array.isArray(ch.items)) ch.items.forEach((it, i) => {
10771
- if (isSchema(it)) pushChild(`[${i}]`, it);
10772
- });
10773
- else if (isSchema(ch.items)) pushChild("items", ch.items);
10774
- if (Array.isArray(ch.options)) ch.options.forEach((opt, i) => {
10775
- if (isSchema(opt)) pushChild(`option[${i}]`, opt);
10776
- });
10777
- if (ch.properties && typeof ch.properties === "object") {
10778
- for (const [k, v] of Object.entries(ch.properties)) if (isSchema(v)) pushChild(k, v);
10811
+ /** 无标签,直接展开(array element / record value / stream inner) */
10812
+ const pushPlain = (child) => {
10813
+ lines.push(...renderSchemaTree(child, indent + 1));
10814
+ };
10815
+ switch (schema.kind) {
10816
+ case "array": {
10817
+ const element = schema.element;
10818
+ if (isSchema(element)) pushPlain(element);
10819
+ break;
10820
+ }
10821
+ case "record": {
10822
+ const value = schema.value;
10823
+ if (isSchema(value)) pushPlain(value);
10824
+ break;
10825
+ }
10826
+ case "tuple": {
10827
+ const elements = schema.elements;
10828
+ if (Array.isArray(elements)) elements.forEach((it, i) => {
10829
+ if (isSchema(it)) pushLabeled(`[${i}]`, it);
10830
+ });
10831
+ break;
10832
+ }
10833
+ case "union": {
10834
+ const options = schema.options;
10835
+ if (Array.isArray(options)) options.forEach((opt, i) => {
10836
+ if (isSchema(opt)) pushLabeled(`option[${i}]`, opt);
10837
+ });
10838
+ break;
10839
+ }
10840
+ case "object": {
10841
+ const props = schema.properties;
10842
+ if (props && typeof props === "object" && !Array.isArray(props)) {
10843
+ for (const [k, v] of Object.entries(props)) if (isSchema(v)) pushLabeled(k, v);
10844
+ }
10845
+ break;
10846
+ }
10847
+ case "stream": {
10848
+ const any = schema;
10849
+ const inner = isSchema(any.inner) ? any.inner : void 0;
10850
+ if (inner) pushPlain(inner);
10851
+ break;
10852
+ }
10779
10853
  }
10780
- if (isSchema(ch.values)) pushChild("values", ch.values);
10781
10854
  return lines;
10782
10855
  }
10783
10856
  function renderMarkdown(doc) {
@@ -10814,7 +10887,7 @@ function renderMarkdown(doc) {
10814
10887
  const [ret, ...params] = m.signature;
10815
10888
  lines.push("**返回类型**");
10816
10889
  lines.push("");
10817
- lines.push(...renderSchemaTree(ret, 0));
10890
+ if (ret) lines.push(...renderSchemaTree(ret, 0));
10818
10891
  lines.push("");
10819
10892
  lines.push(`**参数**(${params.length} 个)`);
10820
10893
  lines.push("");
@@ -10832,7 +10905,6 @@ function renderMarkdown(doc) {
10832
10905
  }
10833
10906
  return lines.join("\n");
10834
10907
  }
10835
- /** 触发浏览器下载 */
10836
10908
  function downloadText(filename, text, mime = "text/plain") {
10837
10909
  const blob = new Blob([text], { type: `${mime};charset=utf-8` });
10838
10910
  const url = URL.createObjectURL(blob);
@@ -11019,4 +11091,4 @@ function App() {
11019
11091
  import_client.createRoot(document.getElementById("root")).render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(I18nProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {}) }) }) }));
11020
11092
  //#endregion
11021
11093
 
11022
- //# sourceMappingURL=index-CqI7vRAS.js.map
11094
+ //# sourceMappingURL=index-WpdfQ_L9.js.map