@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.
- package/dist/@trpc/server/http.d.ts +7 -0
- package/dist/@trpc/server/http.d.ts.map +1 -0
- package/dist/@trpc/server/index.d.ts +69 -0
- package/dist/@trpc/server/index.d.ts.map +1 -0
- package/dist/@trpc/server/rpc.d.ts +3 -0
- package/dist/@trpc/server/rpc.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/index.d.ts +1 -2
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +20 -109
- package/dist/adapters/aws-lambda/index.mjs +5 -92
- package/dist/adapters/aws-lambda/utils.d.ts +2 -3
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +101 -0
- package/dist/adapters/aws-lambda/utils.mjs +94 -0
- package/dist/adapters/express.d.ts +1 -2
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +1 -6
- package/dist/adapters/express.mjs +1 -4
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +84 -0
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +82 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +50 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +48 -0
- package/dist/adapters/fastify/index.js +4 -125
- package/dist/adapters/fastify/index.mjs +2 -125
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +120 -0
- package/dist/adapters/fetch/fetchRequestHandler.mjs +118 -0
- package/dist/adapters/fetch/index.js +2 -115
- package/dist/adapters/fetch/index.mjs +1 -116
- package/dist/adapters/fetch/types.d.ts +2 -3
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.d.ts +1 -2
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +7 -9
- package/dist/adapters/next.mjs +5 -5
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +161 -0
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +157 -0
- package/dist/adapters/node-http/content-type/form-data/index.js +20 -646
- package/dist/adapters/node-http/content-type/form-data/index.mjs +9 -631
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +29 -0
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +27 -0
- package/dist/adapters/node-http/content-type/form-data/streamSlice.js +46 -0
- package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +44 -0
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +30 -0
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +26 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +44 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +42 -0
- package/dist/adapters/node-http/content-type/json/index.js +7 -43
- package/dist/adapters/node-http/content-type/json/index.mjs +5 -39
- package/dist/adapters/node-http/index.js +1 -6
- package/dist/adapters/node-http/index.mjs +1 -4
- package/dist/adapters/node-http/internals/contentType.d.ts +2 -2
- package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
- package/dist/{contentType-72ed9df5.mjs → adapters/node-http/internals/contentType.mjs} +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/{nodeHTTPRequestHandler-55f05150.js → adapters/node-http/nodeHTTPRequestHandler.js} +8 -6
- package/dist/{nodeHTTPRequestHandler-2d5c8791.mjs → adapters/node-http/nodeHTTPRequestHandler.mjs} +6 -4
- package/dist/adapters/node-http/types.d.ts +3 -4
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -2
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +3 -11
- package/dist/adapters/standalone.mjs +3 -5
- package/dist/adapters/ws.d.ts +3 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +33 -28
- package/dist/adapters/ws.mjs +8 -1
- package/dist/bundle-analysis.json +757 -0
- package/dist/http.d.ts +1 -6
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +11 -23
- package/dist/http.mjs +6 -1
- package/dist/index.d.ts +1 -68
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -43
- package/dist/index.mjs +8 -1
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +203 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +201 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +167 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +163 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +35 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +30 -0
- package/dist/observable/index.d.ts +5 -0
- package/dist/observable/index.d.ts.map +1 -0
- package/dist/observable/index.js +13 -0
- package/dist/observable/index.mjs +2 -0
- package/dist/observable/observable.d.ts +13 -0
- package/dist/observable/observable.d.ts.map +1 -0
- package/dist/observable/observable.js +126 -0
- package/dist/observable/observable.mjs +122 -0
- package/dist/observable/operators.d.ts +8 -0
- package/dist/observable/operators.d.ts.map +1 -0
- package/dist/observable/operators.js +103 -0
- package/dist/observable/operators.mjs +99 -0
- package/dist/observable/types.d.ts +26 -0
- package/dist/observable/types.d.ts.map +1 -0
- package/dist/rpc.d.ts +1 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +6 -15
- package/dist/rpc.mjs +3 -1
- package/dist/shared.d.ts +1 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +6 -11
- package/dist/shared.mjs +4 -1
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +6 -0
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts +19 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.js +52 -0
- package/dist/unstable-core-do-not-import/createProxy.mjs +49 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +13 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.js +67 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +63 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +33 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/formatter.js +7 -0
- package/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +15 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +31 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +24 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +32 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +30 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +29 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentType.js +54 -0
- package/dist/unstable-core-do-not-import/http/contentType.mjs +52 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +5 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +51 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +48 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts +7 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +51 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +295 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +293 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts +96 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.d.ts +37 -0
- package/dist/unstable-core-do-not-import/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.js +48 -0
- package/dist/unstable-core-do-not-import/index.mjs +16 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +96 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/initTRPC.js +95 -0
- package/dist/unstable-core-do-not-import/initTRPC.mjs +93 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts +105 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/middleware.js +95 -0
- package/dist/unstable-core-do-not-import/middleware.mjs +89 -0
- package/dist/unstable-core-do-not-import/parser.d.ts +30 -0
- package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/parser.js +37 -0
- package/dist/unstable-core-do-not-import/parser.mjs +35 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts +72 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedure.js +9 -0
- package/dist/unstable-core-do-not-import/procedure.mjs +7 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +101 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.js +176 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +173 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +75 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rootConfig.js +8 -0
- package/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
- package/dist/unstable-core-do-not-import/router.d.ts +85 -0
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/router.js +156 -0
- package/dist/unstable-core-do-not-import/router.mjs +151 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +51 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/codes.js +38 -0
- package/dist/unstable-core-do-not-import/rpc/codes.mjs +35 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +97 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +59 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +57 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts +62 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +107 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.js +107 -0
- package/dist/unstable-core-do-not-import/transformer.mjs +102 -0
- package/dist/unstable-core-do-not-import/types.d.ts +98 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.d.ts +27 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.js +44 -0
- package/dist/unstable-core-do-not-import/utils.mjs +39 -0
- package/package.json +54 -126
- package/src/@trpc/server/http.ts +26 -0
- package/src/@trpc/server/index.ts +105 -0
- package/src/@trpc/server/rpc.ts +26 -0
- package/src/adapters/aws-lambda/index.ts +4 -5
- package/src/adapters/aws-lambda/utils.ts +3 -4
- package/src/adapters/express.ts +1 -3
- package/src/adapters/fastify/fastifyRequestHandler.ts +6 -4
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -2
- package/src/adapters/fetch/fetchRequestHandler.ts +6 -4
- package/src/adapters/fetch/types.ts +2 -3
- package/src/adapters/next.ts +2 -3
- package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
- package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
- package/src/adapters/node-http/content-type/json/index.ts +1 -1
- package/src/adapters/node-http/internals/contentType.ts +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +6 -4
- package/src/adapters/node-http/types.ts +4 -5
- package/src/adapters/standalone.ts +3 -3
- package/src/adapters/ws.ts +14 -13
- package/src/http.ts +1 -26
- package/src/index.ts +1 -105
- package/src/observable/index.ts +10 -0
- package/src/observable/observable.ts +158 -0
- package/src/observable/operators.ts +119 -0
- package/src/observable/types.ts +76 -0
- package/src/rpc.ts +1 -26
- package/src/shared.ts +1 -1
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +9 -0
- package/src/unstable-core-do-not-import/createProxy.ts +59 -0
- package/src/unstable-core-do-not-import/error/TRPCError.ts +82 -0
- package/src/unstable-core-do-not-import/error/formatter.ts +51 -0
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +36 -0
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +29 -0
- package/src/unstable-core-do-not-import/http/contentType.ts +99 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +57 -0
- package/src/unstable-core-do-not-import/http/index.ts +23 -0
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +458 -0
- package/src/unstable-core-do-not-import/http/types.ts +111 -0
- package/src/unstable-core-do-not-import/index.ts +110 -0
- package/src/unstable-core-do-not-import/initTRPC.ts +206 -0
- package/src/unstable-core-do-not-import/middleware.ts +233 -0
- package/src/unstable-core-do-not-import/parser.ts +94 -0
- package/src/unstable-core-do-not-import/procedure.ts +108 -0
- package/src/unstable-core-do-not-import/procedureBuilder.ts +458 -0
- package/src/unstable-core-do-not-import/rootConfig.ts +90 -0
- package/src/unstable-core-do-not-import/router.ts +370 -0
- package/src/unstable-core-do-not-import/rpc/codes.ts +44 -0
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +136 -0
- package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +85 -0
- package/src/unstable-core-do-not-import/serialize.ts +122 -0
- package/src/unstable-core-do-not-import/transformer.ts +202 -0
- package/src/unstable-core-do-not-import/types.ts +151 -0
- package/src/unstable-core-do-not-import/utils.ts +59 -0
- package/unstable-core-do-not-import/index.d.ts +1 -0
- package/unstable-core-do-not-import/index.js +1 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +0 -10
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +0 -1
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/contentType-24c44bba.js +0 -5
- package/dist/nodeHTTPRequestHandler-7691fc79.js +0 -105
- package/dist/observable.d.ts +0 -3
- package/dist/observable.d.ts.map +0 -1
- package/dist/observable.js +0 -32
- package/dist/observable.mjs +0 -1
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +0 -146
- package/src/@trpc-server/http.ts +0 -2
- package/src/observable.ts +0 -16
- /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,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
|