@trpc/server 11.0.0-alpha-tmp-export-from-main.213 → 11.0.0-alpha-tmp-export-from-main-nuke-core.236

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 (277) hide show
  1. package/dist/@trpc/server/http.d.ts +7 -0
  2. package/dist/@trpc/server/http.d.ts.map +1 -0
  3. package/dist/@trpc/server/index.d.ts +69 -0
  4. package/dist/@trpc/server/index.d.ts.map +1 -0
  5. package/dist/@trpc/server/rpc.d.ts +3 -0
  6. package/dist/@trpc/server/rpc.d.ts.map +1 -0
  7. package/dist/adapters/aws-lambda/index.d.ts +1 -2
  8. package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
  9. package/dist/adapters/aws-lambda/index.js +20 -109
  10. package/dist/adapters/aws-lambda/index.mjs +5 -92
  11. package/dist/adapters/aws-lambda/utils.d.ts +2 -3
  12. package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
  13. package/dist/adapters/aws-lambda/utils.js +101 -0
  14. package/dist/adapters/aws-lambda/utils.mjs +94 -0
  15. package/dist/adapters/express.d.ts +1 -2
  16. package/dist/adapters/express.d.ts.map +1 -1
  17. package/dist/adapters/express.js +1 -6
  18. package/dist/adapters/express.mjs +1 -4
  19. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
  20. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  21. package/dist/adapters/fastify/fastifyRequestHandler.js +84 -0
  22. package/dist/adapters/fastify/fastifyRequestHandler.mjs +82 -0
  23. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -2
  24. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
  25. package/dist/adapters/fastify/fastifyTRPCPlugin.js +50 -0
  26. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +48 -0
  27. package/dist/adapters/fastify/index.js +4 -125
  28. package/dist/adapters/fastify/index.mjs +2 -125
  29. package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -2
  30. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  31. package/dist/adapters/fetch/fetchRequestHandler.js +120 -0
  32. package/dist/adapters/fetch/fetchRequestHandler.mjs +118 -0
  33. package/dist/adapters/fetch/index.js +2 -115
  34. package/dist/adapters/fetch/index.mjs +1 -116
  35. package/dist/adapters/fetch/types.d.ts +2 -3
  36. package/dist/adapters/fetch/types.d.ts.map +1 -1
  37. package/dist/adapters/next.d.ts +1 -2
  38. package/dist/adapters/next.d.ts.map +1 -1
  39. package/dist/adapters/next.js +7 -9
  40. package/dist/adapters/next.mjs +5 -5
  41. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +161 -0
  42. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +157 -0
  43. package/dist/adapters/node-http/content-type/form-data/index.js +20 -646
  44. package/dist/adapters/node-http/content-type/form-data/index.mjs +9 -631
  45. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +29 -0
  46. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +27 -0
  47. package/dist/adapters/node-http/content-type/form-data/streamSlice.js +46 -0
  48. package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +44 -0
  49. package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +30 -0
  50. package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +26 -0
  51. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +1 -1
  52. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
  53. package/dist/adapters/node-http/content-type/json/getPostBody.js +44 -0
  54. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +42 -0
  55. package/dist/adapters/node-http/content-type/json/index.js +7 -43
  56. package/dist/adapters/node-http/content-type/json/index.mjs +5 -39
  57. package/dist/adapters/node-http/index.js +1 -6
  58. package/dist/adapters/node-http/index.mjs +1 -4
  59. package/dist/adapters/node-http/internals/contentType.d.ts +2 -2
  60. package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
  61. package/dist/{contentType-72ed9df5.mjs → adapters/node-http/internals/contentType.mjs} +1 -1
  62. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -2
  63. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  64. package/dist/{nodeHTTPRequestHandler-55f05150.js → adapters/node-http/nodeHTTPRequestHandler.js} +8 -6
  65. package/dist/{nodeHTTPRequestHandler-2d5c8791.mjs → adapters/node-http/nodeHTTPRequestHandler.mjs} +6 -4
  66. package/dist/adapters/node-http/types.d.ts +3 -4
  67. package/dist/adapters/node-http/types.d.ts.map +1 -1
  68. package/dist/adapters/standalone.d.ts +1 -2
  69. package/dist/adapters/standalone.d.ts.map +1 -1
  70. package/dist/adapters/standalone.js +3 -11
  71. package/dist/adapters/standalone.mjs +3 -5
  72. package/dist/adapters/ws.d.ts +3 -2
  73. package/dist/adapters/ws.d.ts.map +1 -1
  74. package/dist/adapters/ws.js +33 -28
  75. package/dist/adapters/ws.mjs +8 -1
  76. package/dist/bundle-analysis.json +757 -0
  77. package/dist/http.d.ts +1 -6
  78. package/dist/http.d.ts.map +1 -1
  79. package/dist/http.js +11 -23
  80. package/dist/http.mjs +6 -1
  81. package/dist/index.d.ts +1 -68
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +18 -43
  84. package/dist/index.mjs +8 -1
  85. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +203 -0
  86. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +201 -0
  87. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +167 -0
  88. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +163 -0
  89. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +35 -0
  90. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +30 -0
  91. package/dist/observable/index.d.ts +5 -0
  92. package/dist/observable/index.d.ts.map +1 -0
  93. package/dist/observable/index.js +13 -0
  94. package/dist/observable/index.mjs +2 -0
  95. package/dist/observable/observable.d.ts +13 -0
  96. package/dist/observable/observable.d.ts.map +1 -0
  97. package/dist/observable/observable.js +126 -0
  98. package/dist/observable/observable.mjs +122 -0
  99. package/dist/observable/operators.d.ts +8 -0
  100. package/dist/observable/operators.d.ts.map +1 -0
  101. package/dist/observable/operators.js +103 -0
  102. package/dist/observable/operators.mjs +99 -0
  103. package/dist/observable/types.d.ts +26 -0
  104. package/dist/observable/types.d.ts.map +1 -0
  105. package/dist/rpc.d.ts +1 -2
  106. package/dist/rpc.d.ts.map +1 -1
  107. package/dist/rpc.js +6 -15
  108. package/dist/rpc.mjs +3 -1
  109. package/dist/shared.d.ts +1 -1
  110. package/dist/shared.d.ts.map +1 -1
  111. package/dist/shared.js +6 -11
  112. package/dist/shared.mjs +4 -1
  113. package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +6 -0
  114. package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +1 -0
  115. package/dist/unstable-core-do-not-import/createProxy.d.ts +19 -0
  116. package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
  117. package/dist/unstable-core-do-not-import/createProxy.js +52 -0
  118. package/dist/unstable-core-do-not-import/createProxy.mjs +49 -0
  119. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +13 -0
  120. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
  121. package/dist/unstable-core-do-not-import/error/TRPCError.js +67 -0
  122. package/dist/unstable-core-do-not-import/error/TRPCError.mjs +63 -0
  123. package/dist/unstable-core-do-not-import/error/formatter.d.ts +33 -0
  124. package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -0
  125. package/dist/unstable-core-do-not-import/error/formatter.js +7 -0
  126. package/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
  127. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +15 -0
  128. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +1 -0
  129. package/dist/unstable-core-do-not-import/error/getErrorShape.js +31 -0
  130. package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
  131. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +24 -0
  132. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
  133. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +32 -0
  134. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +30 -0
  135. package/dist/unstable-core-do-not-import/http/contentType.d.ts +29 -0
  136. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
  137. package/dist/unstable-core-do-not-import/http/contentType.js +54 -0
  138. package/dist/unstable-core-do-not-import/http/contentType.mjs +52 -0
  139. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +5 -0
  140. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -0
  141. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +51 -0
  142. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +48 -0
  143. package/dist/unstable-core-do-not-import/http/index.d.ts +7 -0
  144. package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
  145. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +51 -0
  146. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
  147. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +295 -0
  148. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +293 -0
  149. package/dist/unstable-core-do-not-import/http/types.d.ts +96 -0
  150. package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
  151. package/dist/unstable-core-do-not-import/index.d.ts +37 -0
  152. package/dist/unstable-core-do-not-import/index.d.ts.map +1 -0
  153. package/dist/unstable-core-do-not-import/index.js +48 -0
  154. package/dist/unstable-core-do-not-import/index.mjs +16 -0
  155. package/dist/unstable-core-do-not-import/initTRPC.d.ts +96 -0
  156. package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
  157. package/dist/unstable-core-do-not-import/initTRPC.js +95 -0
  158. package/dist/unstable-core-do-not-import/initTRPC.mjs +93 -0
  159. package/dist/unstable-core-do-not-import/middleware.d.ts +105 -0
  160. package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
  161. package/dist/unstable-core-do-not-import/middleware.js +95 -0
  162. package/dist/unstable-core-do-not-import/middleware.mjs +89 -0
  163. package/dist/unstable-core-do-not-import/parser.d.ts +30 -0
  164. package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -0
  165. package/dist/unstable-core-do-not-import/parser.js +37 -0
  166. package/dist/unstable-core-do-not-import/parser.mjs +35 -0
  167. package/dist/unstable-core-do-not-import/procedure.d.ts +72 -0
  168. package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -0
  169. package/dist/unstable-core-do-not-import/procedure.js +9 -0
  170. package/dist/unstable-core-do-not-import/procedure.mjs +7 -0
  171. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +101 -0
  172. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
  173. package/dist/unstable-core-do-not-import/procedureBuilder.js +176 -0
  174. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +173 -0
  175. package/dist/unstable-core-do-not-import/rootConfig.d.ts +75 -0
  176. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -0
  177. package/dist/unstable-core-do-not-import/rootConfig.js +8 -0
  178. package/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
  179. package/dist/unstable-core-do-not-import/router.d.ts +85 -0
  180. package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
  181. package/dist/unstable-core-do-not-import/router.js +156 -0
  182. package/dist/unstable-core-do-not-import/router.mjs +151 -0
  183. package/dist/unstable-core-do-not-import/rpc/codes.d.ts +51 -0
  184. package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
  185. package/dist/unstable-core-do-not-import/rpc/codes.js +38 -0
  186. package/dist/unstable-core-do-not-import/rpc/codes.mjs +35 -0
  187. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +97 -0
  188. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -0
  189. package/dist/unstable-core-do-not-import/rpc/index.d.ts +5 -0
  190. package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -0
  191. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +5 -0
  192. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
  193. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +59 -0
  194. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +57 -0
  195. package/dist/unstable-core-do-not-import/serialize.d.ts +62 -0
  196. package/dist/unstable-core-do-not-import/serialize.d.ts.map +1 -0
  197. package/dist/unstable-core-do-not-import/transformer.d.ts +107 -0
  198. package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
  199. package/dist/unstable-core-do-not-import/transformer.js +107 -0
  200. package/dist/unstable-core-do-not-import/transformer.mjs +102 -0
  201. package/dist/unstable-core-do-not-import/types.d.ts +98 -0
  202. package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
  203. package/dist/unstable-core-do-not-import/utils.d.ts +27 -0
  204. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
  205. package/dist/unstable-core-do-not-import/utils.js +44 -0
  206. package/dist/unstable-core-do-not-import/utils.mjs +39 -0
  207. package/package.json +54 -126
  208. package/src/@trpc/server/http.ts +26 -0
  209. package/src/@trpc/server/index.ts +105 -0
  210. package/src/@trpc/server/rpc.ts +26 -0
  211. package/src/adapters/aws-lambda/index.ts +4 -5
  212. package/src/adapters/aws-lambda/utils.ts +3 -4
  213. package/src/adapters/express.ts +1 -3
  214. package/src/adapters/fastify/fastifyRequestHandler.ts +6 -4
  215. package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -2
  216. package/src/adapters/fetch/fetchRequestHandler.ts +6 -4
  217. package/src/adapters/fetch/types.ts +2 -3
  218. package/src/adapters/next.ts +2 -3
  219. package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
  220. package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
  221. package/src/adapters/node-http/content-type/json/index.ts +1 -1
  222. package/src/adapters/node-http/internals/contentType.ts +2 -2
  223. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +6 -4
  224. package/src/adapters/node-http/types.ts +4 -5
  225. package/src/adapters/standalone.ts +3 -3
  226. package/src/adapters/ws.ts +14 -13
  227. package/src/http.ts +1 -26
  228. package/src/index.ts +1 -105
  229. package/src/observable/index.ts +10 -0
  230. package/src/observable/observable.ts +158 -0
  231. package/src/observable/operators.ts +119 -0
  232. package/src/observable/types.ts +76 -0
  233. package/src/rpc.ts +1 -26
  234. package/src/shared.ts +1 -1
  235. package/src/unstable-core-do-not-import/TRPCInferrable.ts +9 -0
  236. package/src/unstable-core-do-not-import/createProxy.ts +59 -0
  237. package/src/unstable-core-do-not-import/error/TRPCError.ts +82 -0
  238. package/src/unstable-core-do-not-import/error/formatter.ts +51 -0
  239. package/src/unstable-core-do-not-import/error/getErrorShape.ts +36 -0
  240. package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +29 -0
  241. package/src/unstable-core-do-not-import/http/contentType.ts +99 -0
  242. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +57 -0
  243. package/src/unstable-core-do-not-import/http/index.ts +23 -0
  244. package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +458 -0
  245. package/src/unstable-core-do-not-import/http/types.ts +111 -0
  246. package/src/unstable-core-do-not-import/index.ts +110 -0
  247. package/src/unstable-core-do-not-import/initTRPC.ts +206 -0
  248. package/src/unstable-core-do-not-import/middleware.ts +233 -0
  249. package/src/unstable-core-do-not-import/parser.ts +94 -0
  250. package/src/unstable-core-do-not-import/procedure.ts +108 -0
  251. package/src/unstable-core-do-not-import/procedureBuilder.ts +458 -0
  252. package/src/unstable-core-do-not-import/rootConfig.ts +90 -0
  253. package/src/unstable-core-do-not-import/router.ts +370 -0
  254. package/src/unstable-core-do-not-import/rpc/codes.ts +44 -0
  255. package/src/unstable-core-do-not-import/rpc/envelopes.ts +136 -0
  256. package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
  257. package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +85 -0
  258. package/src/unstable-core-do-not-import/serialize.ts +122 -0
  259. package/src/unstable-core-do-not-import/transformer.ts +202 -0
  260. package/src/unstable-core-do-not-import/types.ts +151 -0
  261. package/src/unstable-core-do-not-import/utils.ts +59 -0
  262. package/unstable-core-do-not-import/index.d.ts +1 -0
  263. package/unstable-core-do-not-import/index.js +1 -0
  264. package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +0 -10
  265. package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +0 -1
  266. package/dist/@trpc-server/http.d.ts +0 -2
  267. package/dist/@trpc-server/http.d.ts.map +0 -1
  268. package/dist/contentType-24c44bba.js +0 -5
  269. package/dist/nodeHTTPRequestHandler-7691fc79.js +0 -105
  270. package/dist/observable.d.ts +0 -3
  271. package/dist/observable.d.ts.map +0 -1
  272. package/dist/observable.js +0 -32
  273. package/dist/observable.mjs +0 -1
  274. package/src/@trpc-core-unstable-do-not-import-this-please.ts +0 -146
  275. package/src/@trpc-server/http.ts +0 -2
  276. package/src/observable.ts +0 -16
  277. /package/dist/{contentType-d9d22104.js → adapters/node-http/internals/contentType.js} +0 -0
@@ -0,0 +1,167 @@
1
+ 'use strict';
2
+
3
+ var utils = require('./utils.js');
4
+
5
+ function coerce(a) {
6
+ if (a instanceof Uint8Array) {
7
+ return index => a[index];
8
+ }
9
+ return a;
10
+ }
11
+ function jsmemcmp(buf1, pos1, buf2, pos2, len) {
12
+ const fn1 = coerce(buf1);
13
+ const fn2 = coerce(buf2);
14
+ for (let i = 0; i < len; ++i) {
15
+ if (fn1(pos1 + i) !== fn2(pos2 + i)) {
16
+ return false;
17
+ }
18
+ }
19
+ return true;
20
+ }
21
+ function createOccurenceTable(s) {
22
+ const table = new Array(256).fill(s.length);
23
+ if (s.length > 1) {
24
+ for (let i = 0; i < s.length - 1; i++) {
25
+ table[s[i]] = s.length - 1 - i;
26
+ }
27
+ }
28
+ return table;
29
+ }
30
+ const MATCH = Symbol('Match');
31
+ class StreamSearch {
32
+ constructor(needle) {
33
+ this._lookbehind = new Uint8Array();
34
+ if (typeof needle === 'string') {
35
+ this._needle = needle = utils.stringToArray(needle);
36
+ } else {
37
+ this._needle = needle;
38
+ }
39
+ this._lastChar = needle[needle.length - 1];
40
+ this._occ = createOccurenceTable(needle);
41
+ }
42
+ feed(chunk) {
43
+ let pos = 0;
44
+ let tokens;
45
+ const allTokens = [];
46
+ while (pos !== chunk.length) {
47
+ [pos, ...tokens] = this._feed(chunk, pos);
48
+ allTokens.push(...tokens);
49
+ }
50
+ return allTokens;
51
+ }
52
+ end() {
53
+ const tail = this._lookbehind;
54
+ this._lookbehind = new Uint8Array();
55
+ return tail;
56
+ }
57
+ _feed(data, bufPos) {
58
+ const tokens = [];
59
+ let pos = -this._lookbehind.length;
60
+ if (pos < 0) {
61
+ while (pos < 0 && pos <= data.length - this._needle.length) {
62
+ const ch = this._charAt(data, pos + this._needle.length - 1);
63
+ if (ch === this._lastChar && this._memcmp(data, pos, this._needle.length - 1)) {
64
+ if (pos > -this._lookbehind.length) {
65
+ tokens.push(this._lookbehind.slice(0, this._lookbehind.length + pos));
66
+ }
67
+ tokens.push(MATCH);
68
+ this._lookbehind = new Uint8Array();
69
+ return [
70
+ pos + this._needle.length,
71
+ ...tokens
72
+ ];
73
+ } else {
74
+ pos += this._occ[ch];
75
+ }
76
+ }
77
+ if (pos < 0) {
78
+ while (pos < 0 && !this._memcmp(data, pos, data.length - pos)) {
79
+ pos++;
80
+ }
81
+ }
82
+ if (pos >= 0) {
83
+ tokens.push(this._lookbehind);
84
+ this._lookbehind = new Uint8Array();
85
+ } else {
86
+ const bytesToCutOff = this._lookbehind.length + pos;
87
+ if (bytesToCutOff > 0) {
88
+ tokens.push(this._lookbehind.slice(0, bytesToCutOff));
89
+ this._lookbehind = this._lookbehind.slice(bytesToCutOff);
90
+ }
91
+ this._lookbehind = Uint8Array.from(new Array(this._lookbehind.length + data.length), (_, i) => this._charAt(data, i - this._lookbehind.length));
92
+ return [
93
+ data.length,
94
+ ...tokens
95
+ ];
96
+ }
97
+ }
98
+ pos += bufPos;
99
+ while (pos <= data.length - this._needle.length) {
100
+ const ch = data[pos + this._needle.length - 1];
101
+ if (ch === this._lastChar && data[pos] === this._needle[0] && jsmemcmp(this._needle, 0, data, pos, this._needle.length - 1)) {
102
+ if (pos > bufPos) {
103
+ tokens.push(data.slice(bufPos, pos));
104
+ }
105
+ tokens.push(MATCH);
106
+ return [
107
+ pos + this._needle.length,
108
+ ...tokens
109
+ ];
110
+ } else {
111
+ pos += this._occ[ch];
112
+ }
113
+ }
114
+ if (pos < data.length) {
115
+ while (pos < data.length && (data[pos] !== this._needle[0] || !jsmemcmp(data, pos, this._needle, 0, data.length - pos))) {
116
+ ++pos;
117
+ }
118
+ if (pos < data.length) {
119
+ this._lookbehind = data.slice(pos);
120
+ }
121
+ }
122
+ if (pos > 0) {
123
+ tokens.push(data.slice(bufPos, pos < data.length ? pos : data.length));
124
+ }
125
+ return [
126
+ data.length,
127
+ ...tokens
128
+ ];
129
+ }
130
+ _charAt(data, pos) {
131
+ if (pos < 0) {
132
+ return this._lookbehind[this._lookbehind.length + pos];
133
+ }
134
+ return data[pos];
135
+ }
136
+ _memcmp(data, pos, len) {
137
+ return jsmemcmp(this._charAt.bind(this, data), pos, this._needle, 0, len);
138
+ }
139
+ }
140
+ class ReadableStreamSearch {
141
+ constructor(needle, _readableStream) {
142
+ this._readableStream = _readableStream;
143
+ this._search = new StreamSearch(needle);
144
+ }
145
+ async *[Symbol.asyncIterator]() {
146
+ const reader = this._readableStream.getReader();
147
+ try {
148
+ while (true) {
149
+ const result = await reader.read();
150
+ if (result.done) {
151
+ break;
152
+ }
153
+ yield* this._search.feed(result.value);
154
+ }
155
+ const tail = this._search.end();
156
+ if (tail.length) {
157
+ yield tail;
158
+ }
159
+ } finally {
160
+ reader.releaseLock();
161
+ }
162
+ }
163
+ }
164
+
165
+ exports.MATCH = MATCH;
166
+ exports.ReadableStreamSearch = ReadableStreamSearch;
167
+ exports.StreamSearch = StreamSearch;
@@ -0,0 +1,163 @@
1
+ import { stringToArray } from './utils.mjs';
2
+
3
+ function coerce(a) {
4
+ if (a instanceof Uint8Array) {
5
+ return index => a[index];
6
+ }
7
+ return a;
8
+ }
9
+ function jsmemcmp(buf1, pos1, buf2, pos2, len) {
10
+ const fn1 = coerce(buf1);
11
+ const fn2 = coerce(buf2);
12
+ for (let i = 0; i < len; ++i) {
13
+ if (fn1(pos1 + i) !== fn2(pos2 + i)) {
14
+ return false;
15
+ }
16
+ }
17
+ return true;
18
+ }
19
+ function createOccurenceTable(s) {
20
+ const table = new Array(256).fill(s.length);
21
+ if (s.length > 1) {
22
+ for (let i = 0; i < s.length - 1; i++) {
23
+ table[s[i]] = s.length - 1 - i;
24
+ }
25
+ }
26
+ return table;
27
+ }
28
+ const MATCH = Symbol('Match');
29
+ class StreamSearch {
30
+ constructor(needle) {
31
+ this._lookbehind = new Uint8Array();
32
+ if (typeof needle === 'string') {
33
+ this._needle = needle = stringToArray(needle);
34
+ } else {
35
+ this._needle = needle;
36
+ }
37
+ this._lastChar = needle[needle.length - 1];
38
+ this._occ = createOccurenceTable(needle);
39
+ }
40
+ feed(chunk) {
41
+ let pos = 0;
42
+ let tokens;
43
+ const allTokens = [];
44
+ while (pos !== chunk.length) {
45
+ [pos, ...tokens] = this._feed(chunk, pos);
46
+ allTokens.push(...tokens);
47
+ }
48
+ return allTokens;
49
+ }
50
+ end() {
51
+ const tail = this._lookbehind;
52
+ this._lookbehind = new Uint8Array();
53
+ return tail;
54
+ }
55
+ _feed(data, bufPos) {
56
+ const tokens = [];
57
+ let pos = -this._lookbehind.length;
58
+ if (pos < 0) {
59
+ while (pos < 0 && pos <= data.length - this._needle.length) {
60
+ const ch = this._charAt(data, pos + this._needle.length - 1);
61
+ if (ch === this._lastChar && this._memcmp(data, pos, this._needle.length - 1)) {
62
+ if (pos > -this._lookbehind.length) {
63
+ tokens.push(this._lookbehind.slice(0, this._lookbehind.length + pos));
64
+ }
65
+ tokens.push(MATCH);
66
+ this._lookbehind = new Uint8Array();
67
+ return [
68
+ pos + this._needle.length,
69
+ ...tokens
70
+ ];
71
+ } else {
72
+ pos += this._occ[ch];
73
+ }
74
+ }
75
+ if (pos < 0) {
76
+ while (pos < 0 && !this._memcmp(data, pos, data.length - pos)) {
77
+ pos++;
78
+ }
79
+ }
80
+ if (pos >= 0) {
81
+ tokens.push(this._lookbehind);
82
+ this._lookbehind = new Uint8Array();
83
+ } else {
84
+ const bytesToCutOff = this._lookbehind.length + pos;
85
+ if (bytesToCutOff > 0) {
86
+ tokens.push(this._lookbehind.slice(0, bytesToCutOff));
87
+ this._lookbehind = this._lookbehind.slice(bytesToCutOff);
88
+ }
89
+ this._lookbehind = Uint8Array.from(new Array(this._lookbehind.length + data.length), (_, i) => this._charAt(data, i - this._lookbehind.length));
90
+ return [
91
+ data.length,
92
+ ...tokens
93
+ ];
94
+ }
95
+ }
96
+ pos += bufPos;
97
+ while (pos <= data.length - this._needle.length) {
98
+ const ch = data[pos + this._needle.length - 1];
99
+ if (ch === this._lastChar && data[pos] === this._needle[0] && jsmemcmp(this._needle, 0, data, pos, this._needle.length - 1)) {
100
+ if (pos > bufPos) {
101
+ tokens.push(data.slice(bufPos, pos));
102
+ }
103
+ tokens.push(MATCH);
104
+ return [
105
+ pos + this._needle.length,
106
+ ...tokens
107
+ ];
108
+ } else {
109
+ pos += this._occ[ch];
110
+ }
111
+ }
112
+ if (pos < data.length) {
113
+ while (pos < data.length && (data[pos] !== this._needle[0] || !jsmemcmp(data, pos, this._needle, 0, data.length - pos))) {
114
+ ++pos;
115
+ }
116
+ if (pos < data.length) {
117
+ this._lookbehind = data.slice(pos);
118
+ }
119
+ }
120
+ if (pos > 0) {
121
+ tokens.push(data.slice(bufPos, pos < data.length ? pos : data.length));
122
+ }
123
+ return [
124
+ data.length,
125
+ ...tokens
126
+ ];
127
+ }
128
+ _charAt(data, pos) {
129
+ if (pos < 0) {
130
+ return this._lookbehind[this._lookbehind.length + pos];
131
+ }
132
+ return data[pos];
133
+ }
134
+ _memcmp(data, pos, len) {
135
+ return jsmemcmp(this._charAt.bind(this, data), pos, this._needle, 0, len);
136
+ }
137
+ }
138
+ class ReadableStreamSearch {
139
+ constructor(needle, _readableStream) {
140
+ this._readableStream = _readableStream;
141
+ this._search = new StreamSearch(needle);
142
+ }
143
+ async *[Symbol.asyncIterator]() {
144
+ const reader = this._readableStream.getReader();
145
+ try {
146
+ while (true) {
147
+ const result = await reader.read();
148
+ if (result.done) {
149
+ break;
150
+ }
151
+ yield* this._search.feed(result.value);
152
+ }
153
+ const tail = this._search.end();
154
+ if (tail.length) {
155
+ yield tail;
156
+ }
157
+ } finally {
158
+ reader.releaseLock();
159
+ }
160
+ }
161
+ }
162
+
163
+ export { MATCH, ReadableStreamSearch, StreamSearch };
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ function stringToArray(s) {
4
+ const utf8 = unescape(encodeURIComponent(s));
5
+ return Uint8Array.from(utf8, (_, i) => utf8.charCodeAt(i));
6
+ }
7
+ function arrayToString(a) {
8
+ const utf8 = String.fromCharCode.apply(null, a);
9
+ return decodeURIComponent(escape(utf8));
10
+ }
11
+ function mergeArrays(...arrays) {
12
+ const out = new Uint8Array(arrays.reduce((total, arr) => total + arr.length, 0));
13
+ let offset = 0;
14
+ for (const arr of arrays) {
15
+ out.set(arr, offset);
16
+ offset += arr.length;
17
+ }
18
+ return out;
19
+ }
20
+ function arraysEqual(a, b) {
21
+ if (a.length !== b.length) {
22
+ return false;
23
+ }
24
+ for (let i = 0; i < a.length; i++) {
25
+ if (a[i] !== b[i]) {
26
+ return false;
27
+ }
28
+ }
29
+ return true;
30
+ }
31
+
32
+ exports.arrayToString = arrayToString;
33
+ exports.arraysEqual = arraysEqual;
34
+ exports.mergeArrays = mergeArrays;
35
+ exports.stringToArray = stringToArray;
@@ -0,0 +1,30 @@
1
+ function stringToArray(s) {
2
+ const utf8 = unescape(encodeURIComponent(s));
3
+ return Uint8Array.from(utf8, (_, i) => utf8.charCodeAt(i));
4
+ }
5
+ function arrayToString(a) {
6
+ const utf8 = String.fromCharCode.apply(null, a);
7
+ return decodeURIComponent(escape(utf8));
8
+ }
9
+ function mergeArrays(...arrays) {
10
+ const out = new Uint8Array(arrays.reduce((total, arr) => total + arr.length, 0));
11
+ let offset = 0;
12
+ for (const arr of arrays) {
13
+ out.set(arr, offset);
14
+ offset += arr.length;
15
+ }
16
+ return out;
17
+ }
18
+ function arraysEqual(a, b) {
19
+ if (a.length !== b.length) {
20
+ return false;
21
+ }
22
+ for (let i = 0; i < a.length; i++) {
23
+ if (a[i] !== b[i]) {
24
+ return false;
25
+ }
26
+ }
27
+ return true;
28
+ }
29
+
30
+ export { arrayToString, arraysEqual, mergeArrays, stringToArray };
@@ -0,0 +1,5 @@
1
+ export type { inferObservableValue } from './observable';
2
+ export { isObservable, observable, observableToPromise } from './observable';
3
+ export { map, share, tap } from './operators';
4
+ export type { Observable, Observer, TeardownLogic, Unsubscribable, UnsubscribeFn, } from './types';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observable/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EACV,UAAU,EACV,QAAQ,EACR,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,SAAS,CAAC"}
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var observable = require('./observable.js');
4
+ var operators = require('./operators.js');
5
+
6
+
7
+
8
+ exports.isObservable = observable.isObservable;
9
+ exports.observable = observable.observable;
10
+ exports.observableToPromise = observable.observableToPromise;
11
+ exports.map = operators.map;
12
+ exports.share = operators.share;
13
+ exports.tap = operators.tap;
@@ -0,0 +1,2 @@
1
+ export { isObservable, observable, observableToPromise } from './observable.mjs';
2
+ export { map, share, tap } from './operators.mjs';
@@ -0,0 +1,13 @@
1
+ import type { Observable, Observer, TeardownLogic } from './types';
2
+ /** @public */
3
+ export type inferObservableValue<TObservable> = TObservable extends Observable<infer TValue, unknown> ? TValue : never;
4
+ /** @public */
5
+ export declare function isObservable(x: unknown): x is Observable<unknown, unknown>;
6
+ /** @public */
7
+ export declare function observable<TValue, TError = unknown>(subscribe: (observer: Observer<TValue, TError>) => TeardownLogic): Observable<TValue, TError>;
8
+ /** @internal */
9
+ export declare function observableToPromise<TValue>(observable: Observable<TValue, unknown>): {
10
+ promise: Promise<TValue>;
11
+ abort: () => void;
12
+ };
13
+ //# sourceMappingURL=observable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../src/observable/observable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EAER,aAAa,EAEd,MAAM,SAAS,CAAC;AAMjB,cAAc;AACd,MAAM,MAAM,oBAAoB,CAAC,WAAW,IAAI,WAAW,SAAS,UAAU,CAC5E,MAAM,MAAM,EACZ,OAAO,CACR,GACG,MAAM,GACN,KAAK,CAAC;AAEV,cAAc;AACd,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAE1E;AAED,cAAc;AACd,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,EACjD,SAAS,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,aAAa,GAC/D,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CA6D5B;AA8BD,gBAAgB;AAChB,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;;iBAEtB,IAAI;EAkCtB"}
@@ -0,0 +1,126 @@
1
+ 'use strict';
2
+
3
+ function identity(x) {
4
+ return x;
5
+ }
6
+ /** @public */ function isObservable(x) {
7
+ return typeof x === 'object' && x !== null && 'subscribe' in x;
8
+ }
9
+ /** @public */ function observable(subscribe) {
10
+ const self = {
11
+ subscribe (observer) {
12
+ let teardownRef = null;
13
+ let isDone = false;
14
+ let unsubscribed = false;
15
+ let teardownImmediately = false;
16
+ function unsubscribe() {
17
+ if (teardownRef === null) {
18
+ teardownImmediately = true;
19
+ return;
20
+ }
21
+ if (unsubscribed) {
22
+ return;
23
+ }
24
+ unsubscribed = true;
25
+ if (typeof teardownRef === 'function') {
26
+ teardownRef();
27
+ } else if (teardownRef) {
28
+ teardownRef.unsubscribe();
29
+ }
30
+ }
31
+ teardownRef = subscribe({
32
+ next (value) {
33
+ if (isDone) {
34
+ return;
35
+ }
36
+ observer.next?.(value);
37
+ },
38
+ error (err) {
39
+ if (isDone) {
40
+ return;
41
+ }
42
+ isDone = true;
43
+ observer.error?.(err);
44
+ unsubscribe();
45
+ },
46
+ complete () {
47
+ if (isDone) {
48
+ return;
49
+ }
50
+ isDone = true;
51
+ observer.complete?.();
52
+ unsubscribe();
53
+ }
54
+ });
55
+ if (teardownImmediately) {
56
+ unsubscribe();
57
+ }
58
+ return {
59
+ unsubscribe
60
+ };
61
+ },
62
+ pipe (...operations) {
63
+ return pipeFromArray(operations)(self);
64
+ }
65
+ };
66
+ return self;
67
+ }
68
+ function pipeFromArray(fns) {
69
+ if (fns.length === 0) {
70
+ return identity;
71
+ }
72
+ if (fns.length === 1) {
73
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
74
+ return fns[0];
75
+ }
76
+ return function piped(input) {
77
+ return fns.reduce((prev, fn)=>fn(prev), input);
78
+ };
79
+ }
80
+ class ObservableAbortError extends Error {
81
+ constructor(message){
82
+ super(message);
83
+ this.name = 'ObservableAbortError';
84
+ Object.setPrototypeOf(this, ObservableAbortError.prototype);
85
+ }
86
+ }
87
+ /** @internal */ function observableToPromise(observable) {
88
+ let abort;
89
+ const promise = new Promise((resolve, reject)=>{
90
+ let isDone = false;
91
+ function onDone() {
92
+ if (isDone) {
93
+ return;
94
+ }
95
+ isDone = true;
96
+ reject(new ObservableAbortError('This operation was aborted.'));
97
+ obs$.unsubscribe();
98
+ }
99
+ const obs$ = observable.subscribe({
100
+ next (data) {
101
+ isDone = true;
102
+ resolve(data);
103
+ onDone();
104
+ },
105
+ error (data) {
106
+ isDone = true;
107
+ reject(data);
108
+ onDone();
109
+ },
110
+ complete () {
111
+ isDone = true;
112
+ onDone();
113
+ }
114
+ });
115
+ abort = onDone;
116
+ });
117
+ return {
118
+ promise,
119
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
120
+ abort: abort
121
+ };
122
+ }
123
+
124
+ exports.isObservable = isObservable;
125
+ exports.observable = observable;
126
+ exports.observableToPromise = observableToPromise;
@@ -0,0 +1,122 @@
1
+ function identity(x) {
2
+ return x;
3
+ }
4
+ /** @public */ function isObservable(x) {
5
+ return typeof x === 'object' && x !== null && 'subscribe' in x;
6
+ }
7
+ /** @public */ function observable(subscribe) {
8
+ const self = {
9
+ subscribe (observer) {
10
+ let teardownRef = null;
11
+ let isDone = false;
12
+ let unsubscribed = false;
13
+ let teardownImmediately = false;
14
+ function unsubscribe() {
15
+ if (teardownRef === null) {
16
+ teardownImmediately = true;
17
+ return;
18
+ }
19
+ if (unsubscribed) {
20
+ return;
21
+ }
22
+ unsubscribed = true;
23
+ if (typeof teardownRef === 'function') {
24
+ teardownRef();
25
+ } else if (teardownRef) {
26
+ teardownRef.unsubscribe();
27
+ }
28
+ }
29
+ teardownRef = subscribe({
30
+ next (value) {
31
+ if (isDone) {
32
+ return;
33
+ }
34
+ observer.next?.(value);
35
+ },
36
+ error (err) {
37
+ if (isDone) {
38
+ return;
39
+ }
40
+ isDone = true;
41
+ observer.error?.(err);
42
+ unsubscribe();
43
+ },
44
+ complete () {
45
+ if (isDone) {
46
+ return;
47
+ }
48
+ isDone = true;
49
+ observer.complete?.();
50
+ unsubscribe();
51
+ }
52
+ });
53
+ if (teardownImmediately) {
54
+ unsubscribe();
55
+ }
56
+ return {
57
+ unsubscribe
58
+ };
59
+ },
60
+ pipe (...operations) {
61
+ return pipeFromArray(operations)(self);
62
+ }
63
+ };
64
+ return self;
65
+ }
66
+ function pipeFromArray(fns) {
67
+ if (fns.length === 0) {
68
+ return identity;
69
+ }
70
+ if (fns.length === 1) {
71
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
72
+ return fns[0];
73
+ }
74
+ return function piped(input) {
75
+ return fns.reduce((prev, fn)=>fn(prev), input);
76
+ };
77
+ }
78
+ class ObservableAbortError extends Error {
79
+ constructor(message){
80
+ super(message);
81
+ this.name = 'ObservableAbortError';
82
+ Object.setPrototypeOf(this, ObservableAbortError.prototype);
83
+ }
84
+ }
85
+ /** @internal */ function observableToPromise(observable) {
86
+ let abort;
87
+ const promise = new Promise((resolve, reject)=>{
88
+ let isDone = false;
89
+ function onDone() {
90
+ if (isDone) {
91
+ return;
92
+ }
93
+ isDone = true;
94
+ reject(new ObservableAbortError('This operation was aborted.'));
95
+ obs$.unsubscribe();
96
+ }
97
+ const obs$ = observable.subscribe({
98
+ next (data) {
99
+ isDone = true;
100
+ resolve(data);
101
+ onDone();
102
+ },
103
+ error (data) {
104
+ isDone = true;
105
+ reject(data);
106
+ onDone();
107
+ },
108
+ complete () {
109
+ isDone = true;
110
+ onDone();
111
+ }
112
+ });
113
+ abort = onDone;
114
+ });
115
+ return {
116
+ promise,
117
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118
+ abort: abort
119
+ };
120
+ }
121
+
122
+ export { isObservable, observable, observableToPromise };
@@ -0,0 +1,8 @@
1
+ import type { MonoTypeOperatorFunction, Observer, OperatorFunction } from './types';
2
+ export declare function map<TValueBefore, TError, TValueAfter>(project: (value: TValueBefore, index: number) => TValueAfter): OperatorFunction<TValueBefore, TError, TValueAfter, TError>;
3
+ interface ShareConfig {
4
+ }
5
+ export declare function share<TValue, TError>(_opts?: ShareConfig): MonoTypeOperatorFunction<TValue, TError>;
6
+ export declare function tap<TValue, TError>(observer: Partial<Observer<TValue, TError>>): MonoTypeOperatorFunction<TValue, TError>;
7
+ export {};
8
+ //# sourceMappingURL=operators.d.ts.map