@songtonyli/dsh-cli 0.1.32 → 0.1.34

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.
Files changed (190) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@bufbuild/protobuf/README.md +41 -0
  4. package/node_modules/@bufbuild/protobuf/dist/commonjs/clone.js +66 -0
  5. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv1/boot.js +18 -0
  6. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv1/enum.js +31 -0
  7. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv1/extension.js +28 -0
  8. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv1/file.js +18 -0
  9. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv1/index.js +39 -0
  10. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv1/message.js +24 -0
  11. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv1/service.js +27 -0
  12. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv1/symbols.js +43 -0
  13. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv1/types.js +15 -0
  14. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/boot.js +105 -0
  15. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/embed.js +244 -0
  16. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/enum.js +58 -0
  17. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/extension.js +28 -0
  18. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/file.js +35 -0
  19. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/index.js +39 -0
  20. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/message.js +24 -0
  21. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/restore-json-names.js +29 -0
  22. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/scalar.js +67 -0
  23. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/service.js +27 -0
  24. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/symbols.js +74 -0
  25. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/types.js +15 -0
  26. package/node_modules/@bufbuild/protobuf/dist/commonjs/create.js +296 -0
  27. package/node_modules/@bufbuild/protobuf/dist/commonjs/descriptors.js +53 -0
  28. package/node_modules/@bufbuild/protobuf/dist/commonjs/equals.js +209 -0
  29. package/node_modules/@bufbuild/protobuf/dist/commonjs/extensions.js +168 -0
  30. package/node_modules/@bufbuild/protobuf/dist/commonjs/fields.js +45 -0
  31. package/node_modules/@bufbuild/protobuf/dist/commonjs/from-binary.js +415 -0
  32. package/node_modules/@bufbuild/protobuf/dist/commonjs/from-json.js +1037 -0
  33. package/node_modules/@bufbuild/protobuf/dist/commonjs/index.js +55 -0
  34. package/node_modules/@bufbuild/protobuf/dist/commonjs/is-message.js +33 -0
  35. package/node_modules/@bufbuild/protobuf/dist/commonjs/json-value.js +15 -0
  36. package/node_modules/@bufbuild/protobuf/dist/commonjs/merge.js +70 -0
  37. package/node_modules/@bufbuild/protobuf/dist/commonjs/package.json +4 -0
  38. package/node_modules/@bufbuild/protobuf/dist/commonjs/proto-int64.js +131 -0
  39. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/error.js +36 -0
  40. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/guard.js +78 -0
  41. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/index.js +41 -0
  42. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/message.js +157 -0
  43. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/names.js +115 -0
  44. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/nested-types.js +110 -0
  45. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/path.js +376 -0
  46. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/reflect-check.js +292 -0
  47. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/reflect-types.js +16 -0
  48. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/reflect.js +469 -0
  49. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/scalar.js +129 -0
  50. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/unsafe.js +149 -0
  51. package/node_modules/@bufbuild/protobuf/dist/commonjs/registry.js +954 -0
  52. package/node_modules/@bufbuild/protobuf/dist/commonjs/to-binary.js +437 -0
  53. package/node_modules/@bufbuild/protobuf/dist/commonjs/to-json.js +625 -0
  54. package/node_modules/@bufbuild/protobuf/dist/commonjs/txtpb/from-text.js +684 -0
  55. package/node_modules/@bufbuild/protobuf/dist/commonjs/txtpb/index.js +21 -0
  56. package/node_modules/@bufbuild/protobuf/dist/commonjs/txtpb/is-group-like.js +47 -0
  57. package/node_modules/@bufbuild/protobuf/dist/commonjs/txtpb/reader.js +481 -0
  58. package/node_modules/@bufbuild/protobuf/dist/commonjs/txtpb/to-text.js +358 -0
  59. package/node_modules/@bufbuild/protobuf/dist/commonjs/txtpb/writer.js +220 -0
  60. package/node_modules/@bufbuild/protobuf/dist/commonjs/types.js +15 -0
  61. package/node_modules/@bufbuild/protobuf/dist/commonjs/unknown-enum.js +26 -0
  62. package/node_modules/@bufbuild/protobuf/dist/commonjs/wire/base64-encoding.js +188 -0
  63. package/node_modules/@bufbuild/protobuf/dist/commonjs/wire/binary-encoding.js +726 -0
  64. package/node_modules/@bufbuild/protobuf/dist/commonjs/wire/index.js +37 -0
  65. package/node_modules/@bufbuild/protobuf/dist/commonjs/wire/size-delimited.js +191 -0
  66. package/node_modules/@bufbuild/protobuf/dist/commonjs/wire/text-encoding.js +106 -0
  67. package/node_modules/@bufbuild/protobuf/dist/commonjs/wire/text-format.js +199 -0
  68. package/node_modules/@bufbuild/protobuf/dist/commonjs/wire/varint.js +334 -0
  69. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/any.js +75 -0
  70. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/duration.js +39 -0
  71. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/any_pb.js +27 -0
  72. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/api_pb.js +39 -0
  73. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/compiler/plugin_pb.js +68 -0
  74. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/cpp_features_pb.js +60 -0
  75. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/descriptor_pb.js +892 -0
  76. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/duration_pb.js +27 -0
  77. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/empty_pb.js +27 -0
  78. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/field_mask_pb.js +27 -0
  79. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/go_features_pb.js +126 -0
  80. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/java_features_pb.js +106 -0
  81. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/source_context_pb.js +27 -0
  82. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/struct_pb.js +59 -0
  83. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/timestamp_pb.js +27 -0
  84. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/type_pb.js +242 -0
  85. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/gen/google/protobuf/wrappers_pb.js +67 -0
  86. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/index.js +48 -0
  87. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/json.js +44 -0
  88. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/timestamp.js +57 -0
  89. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/wrappers.js +66 -0
  90. package/node_modules/@bufbuild/protobuf/dist/esm/clone.js +63 -0
  91. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv1/boot.js +14 -0
  92. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv1/enum.js +26 -0
  93. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv1/extension.js +25 -0
  94. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv1/file.js +14 -0
  95. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv1/index.js +23 -0
  96. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv1/message.js +21 -0
  97. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv1/service.js +24 -0
  98. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv1/symbols.js +40 -0
  99. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv1/types.js +14 -0
  100. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/boot.js +101 -0
  101. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/embed.js +239 -0
  102. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/enum.js +53 -0
  103. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/extension.js +25 -0
  104. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/file.js +32 -0
  105. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/index.js +23 -0
  106. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/message.js +21 -0
  107. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/restore-json-names.js +26 -0
  108. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/scalar.js +63 -0
  109. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/service.js +24 -0
  110. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/symbols.js +71 -0
  111. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/types.js +14 -0
  112. package/node_modules/@bufbuild/protobuf/dist/esm/create.js +293 -0
  113. package/node_modules/@bufbuild/protobuf/dist/esm/descriptors.js +50 -0
  114. package/node_modules/@bufbuild/protobuf/dist/esm/equals.js +206 -0
  115. package/node_modules/@bufbuild/protobuf/dist/esm/extensions.js +159 -0
  116. package/node_modules/@bufbuild/protobuf/dist/esm/fields.js +41 -0
  117. package/node_modules/@bufbuild/protobuf/dist/esm/from-binary.js +409 -0
  118. package/node_modules/@bufbuild/protobuf/dist/esm/from-json.js +1029 -0
  119. package/node_modules/@bufbuild/protobuf/dist/esm/index.js +29 -0
  120. package/node_modules/@bufbuild/protobuf/dist/esm/is-message.js +30 -0
  121. package/node_modules/@bufbuild/protobuf/dist/esm/json-value.js +14 -0
  122. package/node_modules/@bufbuild/protobuf/dist/esm/merge.js +67 -0
  123. package/node_modules/@bufbuild/protobuf/dist/esm/package.json +4 -0
  124. package/node_modules/@bufbuild/protobuf/dist/esm/proto-int64.js +128 -0
  125. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/error.js +31 -0
  126. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/guard.js +71 -0
  127. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/index.js +21 -0
  128. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/message.js +152 -0
  129. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/names.js +109 -0
  130. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/nested-types.js +105 -0
  131. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/path.js +369 -0
  132. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/reflect-check.js +284 -0
  133. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/reflect-types.js +14 -0
  134. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/reflect.js +464 -0
  135. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/scalar.js +124 -0
  136. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/unsafe.js +140 -0
  137. package/node_modules/@bufbuild/protobuf/dist/esm/registry.js +948 -0
  138. package/node_modules/@bufbuild/protobuf/dist/esm/to-binary.js +433 -0
  139. package/node_modules/@bufbuild/protobuf/dist/esm/to-json.js +620 -0
  140. package/node_modules/@bufbuild/protobuf/dist/esm/txtpb/from-text.js +680 -0
  141. package/node_modules/@bufbuild/protobuf/dist/esm/txtpb/index.js +15 -0
  142. package/node_modules/@bufbuild/protobuf/dist/esm/txtpb/is-group-like.js +44 -0
  143. package/node_modules/@bufbuild/protobuf/dist/esm/txtpb/reader.js +477 -0
  144. package/node_modules/@bufbuild/protobuf/dist/esm/txtpb/to-text.js +355 -0
  145. package/node_modules/@bufbuild/protobuf/dist/esm/txtpb/writer.js +214 -0
  146. package/node_modules/@bufbuild/protobuf/dist/esm/types.js +14 -0
  147. package/node_modules/@bufbuild/protobuf/dist/esm/unknown-enum.js +23 -0
  148. package/node_modules/@bufbuild/protobuf/dist/esm/wire/base64-encoding.js +184 -0
  149. package/node_modules/@bufbuild/protobuf/dist/esm/wire/binary-encoding.js +721 -0
  150. package/node_modules/@bufbuild/protobuf/dist/esm/wire/index.js +18 -0
  151. package/node_modules/@bufbuild/protobuf/dist/esm/wire/size-delimited.js +186 -0
  152. package/node_modules/@bufbuild/protobuf/dist/esm/wire/text-encoding.js +101 -0
  153. package/node_modules/@bufbuild/protobuf/dist/esm/wire/text-format.js +195 -0
  154. package/node_modules/@bufbuild/protobuf/dist/esm/wire/varint.js +325 -0
  155. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/any.js +69 -0
  156. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/duration.js +35 -0
  157. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/any_pb.js +24 -0
  158. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/api_pb.js +36 -0
  159. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.js +65 -0
  160. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/cpp_features_pb.js +57 -0
  161. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js +888 -0
  162. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/duration_pb.js +24 -0
  163. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/empty_pb.js +24 -0
  164. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/field_mask_pb.js +24 -0
  165. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/go_features_pb.js +123 -0
  166. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/java_features_pb.js +103 -0
  167. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/source_context_pb.js +24 -0
  168. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/struct_pb.js +56 -0
  169. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/timestamp_pb.js +24 -0
  170. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/type_pb.js +239 -0
  171. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/wrappers_pb.js +64 -0
  172. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/index.js +32 -0
  173. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/json.js +41 -0
  174. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/timestamp.js +50 -0
  175. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/wrappers.js +61 -0
  176. package/node_modules/@bufbuild/protobuf/package.json +136 -0
  177. package/node_modules/@deepseek-ai/dsh-base/package.json +1 -0
  178. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +2 -2
  179. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  180. package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +2 -2
  181. package/node_modules/@deepseek-ai/dsh-llm-cursor/README.i18n.yaml +6 -0
  182. package/node_modules/@deepseek-ai/dsh-llm-cursor/README.md +143 -0
  183. package/node_modules/@deepseek-ai/dsh-llm-cursor/README.zh.md +143 -0
  184. package/node_modules/@deepseek-ai/dsh-llm-cursor/lib/index.js +3557 -0
  185. package/node_modules/@deepseek-ai/dsh-llm-cursor/package.json +61 -0
  186. package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +2 -2
  187. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +39 -26
  188. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +39 -26
  189. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +1121 -223
  190. package/package.json +5 -1
@@ -0,0 +1,44 @@
1
+ // Copyright 2021-2026 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ /**
15
+ * Returns true if the field is structured like a proto2 group: a delimited
16
+ * message field whose name is the lowercase of its message type name, declared
17
+ * in the same scope as that message.
18
+ *
19
+ * The text format addresses such fields by their message type name (e.g.
20
+ * `MyGroup`) rather than their field name. This is a faithful port of
21
+ * protobuf-go's isGroupLike (internal/filedesc/desc.go), so editions delimited
22
+ * fields are treated exactly like proto2 groups.
23
+ *
24
+ * Testing `field.message` first narrows the DescField union to its three
25
+ * message-bearing variants (singular, list, and map value) — all of which carry
26
+ * `delimitedEncoding` — so it is in scope below without a cast. Maps are
27
+ * excluded automatically, because their `delimitedEncoding` is always false.
28
+ */
29
+ export function isGroupLike(field) {
30
+ // Groups are always delimited-encoded message fields.
31
+ if (field.message === undefined || !field.delimitedEncoding) {
32
+ return false;
33
+ }
34
+ // Group fields are always named after the lowercase message type name.
35
+ if (field.message.name.toLowerCase() !== field.name) {
36
+ return false;
37
+ }
38
+ // Groups can only be defined in the file they are used in.
39
+ if (field.message.file !== field.parent.file) {
40
+ return false;
41
+ }
42
+ // Group messages are always defined in the same scope as the field.
43
+ return field.message.parent === field.parent;
44
+ }
@@ -0,0 +1,477 @@
1
+ // Copyright 2021-2026 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { getTextEncoding } from "../wire/text-encoding.js";
15
+ const tokenEof = { type: "eof" };
16
+ /**
17
+ * A tokenizer for the protobuf text format.
18
+ *
19
+ * The parser drives it with `peek()` and `next()` (one-token lookahead) and,
20
+ * once it knows it is in a field-name position, asks for the contents of a
21
+ * bracketed name with `readTypeName()` — the `[...]` syntax for extensions and
22
+ * Any type URLs is ambiguous with the list syntax at the lexical level. The
23
+ * structure is modeled on the graphql-js lexer: a single scan position and a
24
+ * per-token reader that returns the decoded value.
25
+ */
26
+ export class Reader {
27
+ constructor(input) {
28
+ this.pos = 0;
29
+ // A leading byte-order mark is insignificant; skip it like protobuf-go's
30
+ // tokenizer does.
31
+ this.input = input.charCodeAt(0) === 0xfeff ? input.slice(1) : input;
32
+ this.length = this.input.length;
33
+ }
34
+ /**
35
+ * Return the next token without consuming it.
36
+ */
37
+ peek() {
38
+ if (this.lookahead === undefined) {
39
+ this.lookahead = this.scan();
40
+ }
41
+ return this.lookahead;
42
+ }
43
+ /**
44
+ * Consume and return the next token.
45
+ */
46
+ next() {
47
+ const tok = this.peek();
48
+ this.lookahead = undefined;
49
+ return tok;
50
+ }
51
+ /**
52
+ * Read the contents of a bracketed name, used for extension fields and the
53
+ * expanded form of google.protobuf.Any. The opening `[` must already have
54
+ * been consumed with `next()`. Whitespace and comments inside the brackets
55
+ * are insignificant. Returns the inner name with the brackets removed, e.g.
56
+ * "pkg.Message.field" or "type.googleapis.com/pkg.Message".
57
+ *
58
+ * The text format grammar for this is incomplete, so we follow protobuf-go's
59
+ * parseTypeName: the prefix may contain URL characters, `/` separators, and
60
+ * well-formed percent-escapes, and the type name after the last `/` must be a
61
+ * dotted identifier.
62
+ */
63
+ readTypeName() {
64
+ let name = "";
65
+ for (;;) {
66
+ this.skipSpace();
67
+ const c = this.charAt(this.pos);
68
+ if (c === undefined) {
69
+ throw new Error("unterminated [...] name");
70
+ }
71
+ if (c === "]") {
72
+ this.pos++;
73
+ break;
74
+ }
75
+ if (c === "/") {
76
+ name += "/";
77
+ this.pos++;
78
+ }
79
+ else if (c === "%") {
80
+ if (!isHexDigit(this.charAt(this.pos + 1)) ||
81
+ !isHexDigit(this.charAt(this.pos + 2))) {
82
+ throw new Error("invalid percent-escape in [...] name");
83
+ }
84
+ name += this.input.substring(this.pos, this.pos + 3);
85
+ this.pos += 3;
86
+ }
87
+ else if (isUrlChar(c)) {
88
+ name += c;
89
+ this.pos++;
90
+ }
91
+ else {
92
+ throw new Error(`unexpected ${quoteChar(c)} in [...] name`);
93
+ }
94
+ }
95
+ validateTypeName(name);
96
+ return name;
97
+ }
98
+ scan() {
99
+ this.skipSpace();
100
+ const c = this.charAt(this.pos);
101
+ if (c === undefined) {
102
+ return tokenEof;
103
+ }
104
+ switch (c) {
105
+ case "{":
106
+ case "}":
107
+ case "<":
108
+ case ">":
109
+ case "[":
110
+ case "]":
111
+ case ":":
112
+ case ",":
113
+ case ";":
114
+ this.pos++;
115
+ return { type: c };
116
+ case "-":
117
+ // A "-" glued to a letter begins a negative identifier (-inf or
118
+ // -infinity); otherwise it is a sign token. A number may have whitespace
119
+ // between the sign and the digits, so the sign is a separate token the
120
+ // parser reassembles; a float literal may not, matching protobuf-go,
121
+ // where inf/infinity parse through the identifier path with the sign
122
+ // glued (so "- inf" is an error but "- 42" is -42).
123
+ if (isLetter(this.charAt(this.pos + 1))) {
124
+ return this.scanIdentifier();
125
+ }
126
+ this.pos++;
127
+ return { type: "-" };
128
+ case '"':
129
+ case "'":
130
+ return this.scanString(c);
131
+ }
132
+ if (isDigit(c)) {
133
+ return this.scanNumber();
134
+ }
135
+ if (c === "." && isDigit(this.charAt(this.pos + 1))) {
136
+ return this.scanNumber();
137
+ }
138
+ if (isLetter(c)) {
139
+ return this.scanIdentifier();
140
+ }
141
+ throw new Error(`unexpected ${quoteChar(c)}`);
142
+ }
143
+ skipSpace() {
144
+ for (;;) {
145
+ const c = this.input[this.pos];
146
+ if (c === " " ||
147
+ c === "\t" ||
148
+ c === "\n" ||
149
+ c === "\r" ||
150
+ c === "\v" ||
151
+ c === "\f") {
152
+ this.pos++;
153
+ }
154
+ else if (c === "#") {
155
+ // A comment runs to the end of the line.
156
+ this.pos++;
157
+ while (this.pos < this.length && this.input[this.pos] !== "\n") {
158
+ this.pos++;
159
+ }
160
+ }
161
+ else {
162
+ return;
163
+ }
164
+ }
165
+ }
166
+ scanIdentifier() {
167
+ const start = this.pos;
168
+ if (this.charAt(this.pos) === "-") {
169
+ this.pos++; // a glued negative identifier such as -inf
170
+ }
171
+ this.pos++; // the first letter (the caller guarantees one is present)
172
+ while (isLetterOrDigit(this.charAt(this.pos))) {
173
+ this.pos++;
174
+ }
175
+ return { type: "identifier", value: this.input.substring(start, this.pos) };
176
+ }
177
+ /**
178
+ * Scan a numeric literal. The sign is a separate token, so a number never
179
+ * starts with `-`. The literal must end at a delimiter, so `10f` is a float
180
+ * but `10bar`, `1.2.3`, `09`, and `0xZ` are errors.
181
+ */
182
+ scanNumber() {
183
+ var _a, _b, _c, _d;
184
+ const start = this.pos;
185
+ if (this.input[this.pos] === "0" &&
186
+ /[xX]/.test((_a = this.charAt(this.pos + 1)) !== null && _a !== void 0 ? _a : "")) {
187
+ // Hexadecimal: `0x` followed by one or more hex digits.
188
+ this.pos += 2;
189
+ const digits = this.pos;
190
+ while (isHexDigit(this.charAt(this.pos))) {
191
+ this.pos++;
192
+ }
193
+ if (this.pos === digits) {
194
+ throw new Error("invalid hexadecimal literal");
195
+ }
196
+ this.expectDelimiter();
197
+ return {
198
+ type: "int",
199
+ text: this.input.substring(start, this.pos),
200
+ base: 16,
201
+ };
202
+ }
203
+ if (this.input[this.pos] === "0" &&
204
+ isOctalDigit(this.charAt(this.pos + 1))) {
205
+ // Octal: a leading `0` followed by octal digits. A subsequent non-octal
206
+ // digit (as in `078`) ends the run, and the delimiter check rejects it.
207
+ this.pos++;
208
+ while (isOctalDigit(this.charAt(this.pos))) {
209
+ this.pos++;
210
+ }
211
+ this.expectDelimiter();
212
+ return {
213
+ type: "int",
214
+ text: this.input.substring(start, this.pos),
215
+ base: 8,
216
+ };
217
+ }
218
+ // A decimal integer or a floating point literal. A leading "0" stands
219
+ // alone (octal and hex were handled above), so the delimiter check below
220
+ // rejects a following digit — `08` and `09` are malformed, not decimal.
221
+ let isFloat = false;
222
+ if (this.charAt(this.pos) === "0") {
223
+ this.pos++;
224
+ }
225
+ else {
226
+ while (isDigit(this.charAt(this.pos))) {
227
+ this.pos++;
228
+ }
229
+ }
230
+ if (this.charAt(this.pos) === ".") {
231
+ isFloat = true;
232
+ this.pos++;
233
+ while (isDigit(this.charAt(this.pos))) {
234
+ this.pos++;
235
+ }
236
+ }
237
+ if (/[eE]/.test((_b = this.charAt(this.pos)) !== null && _b !== void 0 ? _b : "")) {
238
+ isFloat = true;
239
+ this.pos++;
240
+ if (/[+-]/.test((_c = this.charAt(this.pos)) !== null && _c !== void 0 ? _c : "")) {
241
+ this.pos++;
242
+ }
243
+ const digits = this.pos;
244
+ while (isDigit(this.charAt(this.pos))) {
245
+ this.pos++;
246
+ }
247
+ if (this.pos === digits) {
248
+ throw new Error("invalid exponent");
249
+ }
250
+ }
251
+ // A trailing `f`/`F` marks a float and is not part of the value passed to
252
+ // Number(); capture the end before consuming it so it stays out of the text.
253
+ const end = this.pos;
254
+ if (/[fF]/.test((_d = this.charAt(this.pos)) !== null && _d !== void 0 ? _d : "")) {
255
+ isFloat = true;
256
+ this.pos++;
257
+ }
258
+ this.expectDelimiter();
259
+ const text = this.input.substring(start, end);
260
+ return isFloat ? { type: "float", text } : { type: "int", text, base: 10 };
261
+ }
262
+ // A number must be terminated by a delimiter — any character that cannot
263
+ // continue a name or number. This rejects `09`, `0xZ`, `1.2.3`, and `5bar`.
264
+ expectDelimiter() {
265
+ const c = this.charAt(this.pos);
266
+ if (c !== undefined &&
267
+ (isLetterOrDigit(c) || c === "-" || c === "+" || c === ".")) {
268
+ throw new Error("invalid number");
269
+ }
270
+ }
271
+ scanString(quote) {
272
+ this.pos++; // opening quote
273
+ const bytes = [];
274
+ // Literal characters are accumulated as a run and encoded as UTF-8 in one
275
+ // batch when the run ends (at an escape or the closing quote). Escapes
276
+ // contribute their bytes directly.
277
+ let runStart = this.pos;
278
+ for (;;) {
279
+ const c = this.charAt(this.pos);
280
+ if (c === undefined) {
281
+ throw new Error("unterminated string");
282
+ }
283
+ if (c === quote) {
284
+ pushUtf8(bytes, this.input.substring(runStart, this.pos));
285
+ this.pos++; // closing quote
286
+ return { type: "string", value: new Uint8Array(bytes) };
287
+ }
288
+ if (c === "\\") {
289
+ pushUtf8(bytes, this.input.substring(runStart, this.pos));
290
+ this.pos++; // backslash
291
+ this.scanEscape(bytes);
292
+ runStart = this.pos;
293
+ continue;
294
+ }
295
+ // A raw newline or NUL is not allowed in a string, matching protobuf-go.
296
+ if (c === "\n" || c === "\0") {
297
+ throw new Error(`invalid ${quoteChar(c)} in string`);
298
+ }
299
+ this.pos++;
300
+ }
301
+ }
302
+ scanEscape(bytes) {
303
+ const c = this.charAt(this.pos);
304
+ if (c === undefined) {
305
+ throw new Error("unterminated escape sequence");
306
+ }
307
+ switch (c) {
308
+ case '"':
309
+ case "'":
310
+ case "\\":
311
+ case "?":
312
+ bytes.push(c.charCodeAt(0));
313
+ this.pos++;
314
+ return;
315
+ case "a":
316
+ bytes.push(0x07);
317
+ this.pos++;
318
+ return;
319
+ case "b":
320
+ bytes.push(0x08);
321
+ this.pos++;
322
+ return;
323
+ case "f":
324
+ bytes.push(0x0c);
325
+ this.pos++;
326
+ return;
327
+ case "n":
328
+ bytes.push(0x0a);
329
+ this.pos++;
330
+ return;
331
+ case "r":
332
+ bytes.push(0x0d);
333
+ this.pos++;
334
+ return;
335
+ case "t":
336
+ bytes.push(0x09);
337
+ this.pos++;
338
+ return;
339
+ case "v":
340
+ bytes.push(0x0b);
341
+ this.pos++;
342
+ return;
343
+ case "x": {
344
+ this.pos++;
345
+ const hex = this.takeWhile(isHexDigit, 2);
346
+ if (hex.length === 0) {
347
+ throw new Error("invalid hex escape \\x");
348
+ }
349
+ bytes.push(parseInt(hex, 16));
350
+ return;
351
+ }
352
+ case "u":
353
+ case "U": {
354
+ this.pos++;
355
+ const width = c === "u" ? 4 : 8;
356
+ const hex = this.takeWhile(isHexDigit, width);
357
+ if (hex.length !== width) {
358
+ throw new Error(`invalid unicode escape \\${c}`);
359
+ }
360
+ const code = parseInt(hex, 16);
361
+ // Reject surrogate code points and values beyond U+10FFFF. We
362
+ // deliberately do NOT combine an adjacent `\u` low surrogate into a
363
+ // pair the way protobuf-go does: the conformance suite (the
364
+ // StringLiteral*Surrogate* cases) requires every surrogate escape, lone
365
+ // or paired, to be a parse error. Do not "fix" this toward Go.
366
+ if (code > 0x10ffff || (code >= 0xd800 && code <= 0xdfff)) {
367
+ throw new Error(`invalid unicode escape \\${c}${hex}`);
368
+ }
369
+ pushUtf8(bytes, String.fromCodePoint(code));
370
+ return;
371
+ }
372
+ default:
373
+ if (isOctalDigit(c)) {
374
+ const oct = this.takeWhile(isOctalDigit, 3);
375
+ const value = parseInt(oct, 8);
376
+ if (value > 0xff) {
377
+ throw new Error(`octal escape \\${oct} out of range`);
378
+ }
379
+ bytes.push(value);
380
+ return;
381
+ }
382
+ throw new Error(`invalid escape \\${c}`);
383
+ }
384
+ }
385
+ // Consume up to `max` consecutive characters matching `pred` and return them.
386
+ takeWhile(pred, max) {
387
+ const start = this.pos;
388
+ while (this.pos < start + max && pred(this.charAt(this.pos))) {
389
+ this.pos++;
390
+ }
391
+ return this.input.substring(start, this.pos);
392
+ }
393
+ charAt(index) {
394
+ return index < this.length ? this.input[index] : undefined;
395
+ }
396
+ }
397
+ /**
398
+ * Validate a type name (and URL prefix) from a bracketed name, mirroring
399
+ * protobuf-go's parseTypeName. The type name is everything after the last `/`;
400
+ * the prefix before it is a URL that may carry extra characters and
401
+ * percent-escapes, but must not begin with `/`.
402
+ */
403
+ function validateTypeName(name) {
404
+ const lastSlash = name.lastIndexOf("/");
405
+ if (lastSlash >= 0 && name[0] === "/") {
406
+ throw new Error("invalid type name: empty URL host");
407
+ }
408
+ const typeName = name.substring(lastSlash + 1);
409
+ if (typeName.length === 0) {
410
+ throw new Error("invalid type name: empty");
411
+ }
412
+ for (const part of typeName.split(".")) {
413
+ if (part.length === 0) {
414
+ throw new Error("invalid type name: empty component");
415
+ }
416
+ }
417
+ for (const c of typeName) {
418
+ if (!(isLetterOrDigit(c) || c === "." || c === "-")) {
419
+ throw new Error(`unexpected ${quoteChar(c)} in type name`);
420
+ }
421
+ }
422
+ }
423
+ function isDigit(c) {
424
+ return c !== undefined && c >= "0" && c <= "9";
425
+ }
426
+ function isOctalDigit(c) {
427
+ return c !== undefined && c >= "0" && c <= "7";
428
+ }
429
+ function isHexDigit(c) {
430
+ return (c !== undefined &&
431
+ ((c >= "0" && c <= "9") || (c >= "a" && c <= "f") || (c >= "A" && c <= "F")));
432
+ }
433
+ function isLetter(c) {
434
+ return (c !== undefined &&
435
+ ((c >= "a" && c <= "z") || (c >= "A" && c <= "Z") || c === "_"));
436
+ }
437
+ function isLetterOrDigit(c) {
438
+ return isLetter(c) || isDigit(c);
439
+ }
440
+ /**
441
+ * A character permitted in the URL prefix of an Any type name, matching
442
+ * protobuf-go's isUrlChar plus the type-name characters.
443
+ */
444
+ function isUrlChar(c) {
445
+ return (isLetterOrDigit(c) ||
446
+ c === "-" ||
447
+ c === "." ||
448
+ c === "~" ||
449
+ c === "!" ||
450
+ c === "$" ||
451
+ c === "&" ||
452
+ c === "(" ||
453
+ c === ")" ||
454
+ c === "*" ||
455
+ c === "+" ||
456
+ c === "," ||
457
+ c === ";" ||
458
+ c === "=");
459
+ }
460
+ function quoteChar(c) {
461
+ var _a;
462
+ const code = (_a = c.codePointAt(0)) !== null && _a !== void 0 ? _a : 0;
463
+ return code >= 0x20 && code <= 0x7e
464
+ ? `"${c}"`
465
+ : `U+${code.toString(16).toUpperCase().padStart(4, "0")}`;
466
+ }
467
+ // Append the UTF-8 encoding of `text` to `out`, using the same Text Encoding
468
+ // API as the rest of the library. Unpaired surrogates become U+FFFD (the
469
+ // standard TextEncoder behavior), matching binary serialization.
470
+ function pushUtf8(out, text) {
471
+ if (text.length === 0) {
472
+ return;
473
+ }
474
+ for (const byte of getTextEncoding().encodeUtf8(text)) {
475
+ out.push(byte);
476
+ }
477
+ }