@shisho/plugin-sdk 0.0.21 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shisho/plugin-sdk",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "TypeScript SDK for Shisho plugin development — types, host API declarations, and test utilities",
5
5
  "homepage": "https://github.com/shishobooks/shisho/blob/master/packages/plugin-sdk/README.md",
6
6
  "types": "index.d.ts",
package/testing/index.js CHANGED
@@ -59,24 +59,26 @@ function parseXML(content) {
59
59
  const parsed = parser.parse(content);
60
60
  return convertXMLNode(parsed[0] ?? {});
61
61
  }
62
- function convertXMLNode(node) {
63
- const keys = Object.keys(node).filter((k) => k !== ":@" && k !== "#text" && k !== "#cdata" && k !== "#comment");
64
- const tagWithNs = keys[0] ?? "";
65
- const colonIdx = tagWithNs.indexOf(":");
66
- const tag = colonIdx >= 0 ? tagWithNs.slice(colonIdx + 1) : tagWithNs;
67
- const nsPrefix = colonIdx >= 0 ? tagWithNs.slice(0, colonIdx) : "";
62
+ function convertXMLNode(node, inheritedNamespaces) {
63
+ // Inherit parent namespace map and add any new declarations from this element
64
+ const namespaces = { ...(inheritedNamespaces ?? {}) };
68
65
  const attrs = node[":@"] ?? {};
69
66
  const attributes = {};
70
- let namespace = "";
71
67
  for (const [k, v] of Object.entries(attrs)) {
72
- if (k === `xmlns:${nsPrefix}` && nsPrefix) {
73
- namespace = String(v);
68
+ if (k.startsWith("xmlns:")) {
69
+ namespaces[k.slice(6)] = String(v);
74
70
  }
75
- else if (k === "xmlns" && !nsPrefix) {
76
- namespace = String(v);
71
+ else if (k === "xmlns") {
72
+ namespaces[""] = String(v);
77
73
  }
78
74
  attributes[k] = String(v);
79
75
  }
76
+ const keys = Object.keys(node).filter((k) => k !== ":@" && k !== "#text" && k !== "#cdata" && k !== "#comment");
77
+ const tagWithNs = keys[0] ?? "";
78
+ const colonIdx = tagWithNs.indexOf(":");
79
+ const tag = colonIdx >= 0 ? tagWithNs.slice(colonIdx + 1) : tagWithNs;
80
+ const nsPrefix = colonIdx >= 0 ? tagWithNs.slice(0, colonIdx) : "";
81
+ const namespace = namespaces[nsPrefix] ?? "";
80
82
  const childNodes = node[tagWithNs] ?? [];
81
83
  let text = "";
82
84
  const children = [];
@@ -87,7 +89,7 @@ function convertXMLNode(node) {
87
89
  text += String(c["#text"]);
88
90
  }
89
91
  else {
90
- children.push(convertXMLNode(c));
92
+ children.push(convertXMLNode(c, namespaces));
91
93
  }
92
94
  }
93
95
  }
@@ -308,7 +310,7 @@ export function createMockShisho(options = {}) {
308
310
  parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
309
311
  }
310
312
  }
311
- return parts.join("&");
313
+ return parts.join("&").replace(/%20/g, "+");
312
314
  },
313
315
  parse(urlStr) {
314
316
  const parsed = new URL(urlStr);
package/testing/index.ts CHANGED
@@ -108,28 +108,34 @@ function parseXML(content: string): XMLElement {
108
108
  return convertXMLNode(parsed[0] ?? {});
109
109
  }
110
110
 
111
- function convertXMLNode(node: Record<string, unknown>): XMLElement {
112
- const keys = Object.keys(node).filter(
113
- (k) => k !== ":@" && k !== "#text" && k !== "#cdata" && k !== "#comment",
114
- );
115
- const tagWithNs = keys[0] ?? "";
116
- const colonIdx = tagWithNs.indexOf(":");
117
- const tag = colonIdx >= 0 ? tagWithNs.slice(colonIdx + 1) : tagWithNs;
118
- const nsPrefix = colonIdx >= 0 ? tagWithNs.slice(0, colonIdx) : "";
111
+ function convertXMLNode(
112
+ node: Record<string, unknown>,
113
+ inheritedNamespaces?: Record<string, string>,
114
+ ): XMLElement {
115
+ // Inherit parent namespace map and add any new declarations from this element
116
+ const namespaces = { ...(inheritedNamespaces ?? {}) };
119
117
 
120
118
  const attrs: Record<string, unknown> =
121
119
  (node[":@"] as Record<string, unknown>) ?? {};
122
120
  const attributes: Record<string, string> = {};
123
- let namespace = "";
124
121
  for (const [k, v] of Object.entries(attrs)) {
125
- if (k === `xmlns:${nsPrefix}` && nsPrefix) {
126
- namespace = String(v);
127
- } else if (k === "xmlns" && !nsPrefix) {
128
- namespace = String(v);
122
+ if (k.startsWith("xmlns:")) {
123
+ namespaces[k.slice(6)] = String(v);
124
+ } else if (k === "xmlns") {
125
+ namespaces[""] = String(v);
129
126
  }
130
127
  attributes[k] = String(v);
131
128
  }
132
129
 
130
+ const keys = Object.keys(node).filter(
131
+ (k) => k !== ":@" && k !== "#text" && k !== "#cdata" && k !== "#comment",
132
+ );
133
+ const tagWithNs = keys[0] ?? "";
134
+ const colonIdx = tagWithNs.indexOf(":");
135
+ const tag = colonIdx >= 0 ? tagWithNs.slice(colonIdx + 1) : tagWithNs;
136
+ const nsPrefix = colonIdx >= 0 ? tagWithNs.slice(0, colonIdx) : "";
137
+ const namespace = namespaces[nsPrefix] ?? "";
138
+
133
139
  const childNodes = (node[tagWithNs] as unknown[]) ?? [];
134
140
  let text = "";
135
141
  const children: XMLElement[] = [];
@@ -139,7 +145,7 @@ function convertXMLNode(node: Record<string, unknown>): XMLElement {
139
145
  if ("#text" in c) {
140
146
  text += String(c["#text"]);
141
147
  } else {
142
- children.push(convertXMLNode(c));
148
+ children.push(convertXMLNode(c, namespaces));
143
149
  }
144
150
  }
145
151
  }
@@ -417,7 +423,7 @@ export function createMockShisho(
417
423
  }
418
424
  }
419
425
 
420
- return parts.join("&");
426
+ return parts.join("&").replace(/%20/g, "+");
421
427
  },
422
428
 
423
429
  parse(urlStr: string): ParsedURL {