@zudojs/rpc 1.4.2 → 1.5.0
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/README.md +22 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/rpc/client/index.d.ts +0 -1
- package/dist/rpc/client/index.js +0 -1
- package/dist/rpc/client/rpcClient.core.d.ts +0 -1
- package/dist/rpc/client/rpcClient.core.js +0 -1
- package/dist/rpc/client/rpcWireError.helper.d.ts +0 -1
- package/dist/rpc/client/rpcWireError.helper.js +0 -1
- package/dist/rpc/constants/index.d.ts +1 -2
- package/dist/rpc/constants/index.js +1 -2
- package/dist/rpc/constants/rpcConstants.core.d.ts +7 -1
- package/dist/rpc/constants/rpcConstants.core.js +7 -1
- package/dist/rpc/context/index.d.ts +0 -1
- package/dist/rpc/context/index.js +0 -1
- package/dist/rpc/context/rpcContext.type.d.ts +0 -1
- package/dist/rpc/context/rpcContext.type.js +0 -1
- package/dist/rpc/dispatcher/index.d.ts +0 -1
- package/dist/rpc/dispatcher/index.js +0 -1
- package/dist/rpc/dispatcher/rpcDispatcher.core.d.ts +0 -1
- package/dist/rpc/dispatcher/rpcDispatcher.core.js +10 -4
- package/dist/rpc/dispatcher/rpcDispatcher.downstream.d.ts +26 -0
- package/dist/rpc/dispatcher/rpcDispatcher.downstream.js +41 -0
- package/dist/rpc/errors/index.d.ts +0 -1
- package/dist/rpc/errors/index.js +0 -1
- package/dist/rpc/errors/rpc.errors.d.ts +0 -1
- package/dist/rpc/errors/rpc.errors.js +0 -1
- package/dist/rpc/errors/rpcErrorCause.helper.d.ts +10 -0
- package/dist/rpc/errors/rpcErrorCause.helper.js +18 -0
- package/dist/rpc/interceptor/index.d.ts +0 -1
- package/dist/rpc/interceptor/index.js +0 -1
- package/dist/rpc/interceptor/rpcInterceptor.type.d.ts +0 -1
- package/dist/rpc/interceptor/rpcInterceptor.type.js +0 -1
- package/dist/rpc/middleware/index.d.ts +0 -1
- package/dist/rpc/middleware/index.js +0 -1
- package/dist/rpc/middleware/rpcMiddleware.core.d.ts +0 -1
- package/dist/rpc/middleware/rpcMiddleware.core.js +0 -1
- package/dist/rpc/procedure/index.d.ts +0 -1
- package/dist/rpc/procedure/index.js +0 -1
- package/dist/rpc/procedure/rpcProcedure.type.d.ts +0 -1
- package/dist/rpc/procedure/rpcProcedure.type.js +0 -1
- package/dist/rpc/procedure/rpcProcedureRegistry.core.d.ts +0 -1
- package/dist/rpc/procedure/rpcProcedureRegistry.core.js +0 -1
- package/dist/rpc/procedure/rpcProcedureRouter.core.d.ts +0 -1
- package/dist/rpc/procedure/rpcProcedureRouter.core.js +0 -1
- package/dist/rpc/reliability/cancellation/rpcAbort.helper.d.ts +0 -1
- package/dist/rpc/reliability/cancellation/rpcAbort.helper.js +0 -1
- package/dist/rpc/reliability/cancellation/rpcCancellation.helper.d.ts +0 -1
- package/dist/rpc/reliability/cancellation/rpcCancellation.helper.js +0 -1
- package/dist/rpc/reliability/deadline/rpcDeadline.helper.d.ts +0 -1
- package/dist/rpc/reliability/deadline/rpcDeadline.helper.js +0 -1
- package/dist/rpc/reliability/index.d.ts +0 -1
- package/dist/rpc/reliability/index.js +0 -1
- package/dist/rpc/reliability/retry/rpcRetry.helper.d.ts +9 -1
- package/dist/rpc/reliability/retry/rpcRetry.helper.js +0 -1
- package/dist/rpc/reliability/timeout/rpcTimeout.helper.d.ts +0 -1
- package/dist/rpc/reliability/timeout/rpcTimeout.helper.js +0 -1
- package/dist/rpc/server/index.d.ts +0 -1
- package/dist/rpc/server/index.js +0 -1
- package/dist/rpc/server/rpcBaseErrorMapping.helper.d.ts +0 -1
- package/dist/rpc/server/rpcBaseErrorMapping.helper.js +0 -1
- package/dist/rpc/server/rpcDownstreamMapping.helper.d.ts +15 -0
- package/dist/rpc/server/rpcDownstreamMapping.helper.js +27 -0
- package/dist/rpc/server/rpcErrorMapping.helper.d.ts +2 -4
- package/dist/rpc/server/rpcErrorMapping.helper.js +6 -4
- package/dist/rpc/server/rpcServer.core.d.ts +0 -1
- package/dist/rpc/server/rpcServer.core.js +0 -1
- package/dist/rpc/streaming/index.d.ts +0 -1
- package/dist/rpc/streaming/index.js +0 -1
- package/dist/rpc/streaming/rpcStreaming.type.d.ts +0 -1
- package/dist/rpc/streaming/rpcStreaming.type.js +0 -1
- package/dist/rpc/transport/codec/index.d.ts +0 -1
- package/dist/rpc/transport/codec/index.js +0 -1
- package/dist/rpc/transport/codec/rpcBody.helper.d.ts +0 -1
- package/dist/rpc/transport/codec/rpcBody.helper.js +0 -1
- package/dist/rpc/transport/codec/rpcCodec.helper.d.ts +0 -1
- package/dist/rpc/transport/codec/rpcCodec.helper.js +0 -1
- package/dist/rpc/transport/http/index.d.ts +0 -1
- package/dist/rpc/transport/http/index.js +0 -1
- package/dist/rpc/transport/http/rpcFetchHandler.core.d.ts +0 -1
- package/dist/rpc/transport/http/rpcFetchHandler.core.js +0 -1
- package/dist/rpc/transport/http/rpcHttpExchange.helper.d.ts +0 -1
- package/dist/rpc/transport/http/rpcHttpExchange.helper.js +1 -10
- package/dist/rpc/transport/http/rpcHttpStatus.helper.d.ts +0 -1
- package/dist/rpc/transport/http/rpcHttpStatus.helper.js +0 -1
- package/dist/rpc/transport/http/rpcHttpTransport.core.d.ts +0 -1
- package/dist/rpc/transport/http/rpcHttpTransport.core.js +0 -1
- package/dist/rpc/transport/index.d.ts +0 -1
- package/dist/rpc/transport/index.js +0 -1
- package/dist/rpc/transport/memory/index.d.ts +0 -1
- package/dist/rpc/transport/memory/index.js +0 -1
- package/dist/rpc/transport/memory/rpcMemoryTransport.core.d.ts +0 -1
- package/dist/rpc/transport/memory/rpcMemoryTransport.core.js +0 -1
- package/dist/rpc/transport/rpcTransport.type.d.ts +0 -1
- package/dist/rpc/transport/rpcTransport.type.js +0 -1
- package/dist/rpc/types/index.d.ts +0 -1
- package/dist/rpc/types/index.js +0 -1
- package/dist/rpc/types/rpcMetadata.type.d.ts +0 -1
- package/dist/rpc/types/rpcMetadata.type.js +0 -1
- package/dist/rpc/types/rpcProcedureName.type.d.ts +0 -1
- package/dist/rpc/types/rpcProcedureName.type.js +0 -1
- package/dist/rpc/types/rpcRequest.type.d.ts +0 -1
- package/dist/rpc/types/rpcRequest.type.js +0 -1
- package/dist/rpc/types/rpcResponse.type.d.ts +0 -1
- package/dist/rpc/types/rpcResponse.type.js +0 -1
- package/dist/rpc/validation/index.d.ts +0 -1
- package/dist/rpc/validation/index.js +0 -1
- package/dist/rpc/validation/rpcValidation.core.d.ts +0 -1
- package/dist/rpc/validation/rpcValidation.core.js +0 -1
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +0 -1
- package/package.json +7 -7
- package/dist/rpc/validation/rpcUnsafeKey.helper.d.ts +0 -18
- package/dist/rpc/validation/rpcUnsafeKey.helper.js +0 -60
|
@@ -20,9 +20,8 @@ export interface RPCMappedError {
|
|
|
20
20
|
* `RPC_CONFLICT`, `RPC_VALIDATION_ERROR` …). Anything not built to be
|
|
21
21
|
* exposed — an `RPCInternalError`, a non-exposed custom `RPCError` or
|
|
22
22
|
* `BaseError`, or any other error — is answered with
|
|
23
|
-
* {@link INTERNAL_ERROR_MESSAGE}
|
|
24
|
-
*
|
|
25
|
-
* code ({@link withheldRPCErrorCode}).
|
|
23
|
+
* {@link INTERNAL_ERROR_MESSAGE} and its custom code withheld
|
|
24
|
+
* ({@link withheldRPCErrorCode}), so no server detail reaches the peer.
|
|
26
25
|
*/
|
|
27
26
|
export declare function mapRPCError(error: unknown): RPCMappedError;
|
|
28
27
|
/**
|
|
@@ -33,4 +32,3 @@ export declare function mapRPCError(error: unknown): RPCMappedError;
|
|
|
33
32
|
* reported by the server or raised locally (its own deadline, a cancel).
|
|
34
33
|
*/
|
|
35
34
|
export declare function rpcWireCodeOf(error: unknown): string | undefined;
|
|
36
|
-
//# sourceMappingURL=rpcErrorMapping.helper.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isRPCError, RPCAuthenticationError, RPCCancelledError, RPCDeadlineExceededError, RPCDeserializationError, RPCForbiddenError, RPCInternalError, RPCInvalidRequestError, RPCProcedureNotFoundError, RPCRateLimitedError, RPCSerializationError, RPCTimeoutError, RPCTransportError, RPCUnavailableError, RPCValidationError, } from "../errors/rpc.errors.js";
|
|
2
2
|
import { INTERNAL_ERROR_MESSAGE } from "../constants/rpcConstants.core.js";
|
|
3
3
|
import { mapExposedBaseError, withheldRPCErrorCode } from "./rpcBaseErrorMapping.helper.js";
|
|
4
|
+
import { mapDownstreamError } from "./rpcDownstreamMapping.helper.js";
|
|
4
5
|
/**
|
|
5
6
|
* Wire codes for the error types the server maps.
|
|
6
7
|
*
|
|
@@ -33,14 +34,16 @@ const ERROR_CODES = [
|
|
|
33
34
|
* `RPC_CONFLICT`, `RPC_VALIDATION_ERROR` …). Anything not built to be
|
|
34
35
|
* exposed — an `RPCInternalError`, a non-exposed custom `RPCError` or
|
|
35
36
|
* `BaseError`, or any other error — is answered with
|
|
36
|
-
* {@link INTERNAL_ERROR_MESSAGE}
|
|
37
|
-
*
|
|
38
|
-
* code ({@link withheldRPCErrorCode}).
|
|
37
|
+
* {@link INTERNAL_ERROR_MESSAGE} and its custom code withheld
|
|
38
|
+
* ({@link withheldRPCErrorCode}), so no server detail reaches the peer.
|
|
39
39
|
*/
|
|
40
40
|
export function mapRPCError(error) {
|
|
41
41
|
if (error instanceof RPCInternalError || !(error instanceof Error)) {
|
|
42
42
|
return internalFailure("RPC_INTERNAL_ERROR");
|
|
43
43
|
}
|
|
44
|
+
const downstream = mapDownstreamError(error);
|
|
45
|
+
if (downstream !== undefined)
|
|
46
|
+
return downstream;
|
|
44
47
|
for (const [type, code, internal] of ERROR_CODES) {
|
|
45
48
|
if (error instanceof type) {
|
|
46
49
|
return internal === true
|
|
@@ -99,4 +102,3 @@ function exposed(code, message, details) {
|
|
|
99
102
|
function internalFailure(code) {
|
|
100
103
|
return { payload: { code, message: INTERNAL_ERROR_MESSAGE }, internal: true };
|
|
101
104
|
}
|
|
102
|
-
//# sourceMappingURL=rpcErrorMapping.helper.js.map
|
|
@@ -28,4 +28,3 @@ export interface RPCStreamingProcedure<TInput = unknown, TOutput = unknown> {
|
|
|
28
28
|
* Creates a streaming RPC procedure.
|
|
29
29
|
*/
|
|
30
30
|
export declare function createRPCStreamingProcedure<TInput = unknown, TOutput = unknown>(name: string, handler: RPCStreamingHandler<TInput, TOutput>): RPCStreamingProcedure<TInput, TOutput>;
|
|
31
|
-
//# sourceMappingURL=rpcStreaming.type.d.ts.map
|
|
@@ -7,4 +7,3 @@ export type { RPCFrameSerializer, RPCJsonSerializerOptions, } from "./rpcCodec.h
|
|
|
7
7
|
export { createRPCJsonSerializer, isRPCResponseFrame } from "./rpcCodec.helper.js";
|
|
8
8
|
export type { RPCBodyReadResult, RPCBodySource } from "./rpcBody.helper.js";
|
|
9
9
|
export { readBoundedBody } from "./rpcBody.helper.js";
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -38,4 +38,3 @@ export declare function createRPCJsonSerializer(options?: RPCJsonSerializerOptio
|
|
|
38
38
|
* transport failure instead of being read as a result.
|
|
39
39
|
*/
|
|
40
40
|
export declare function isRPCResponseFrame(value: unknown): value is RPCResponse;
|
|
41
|
-
//# sourceMappingURL=rpcCodec.helper.d.ts.map
|
|
@@ -9,4 +9,3 @@ export { createRPCHttpTransport } from "./rpcHttpTransport.core.js";
|
|
|
9
9
|
export type { RPCFetchHandlerOptions } from "./rpcFetchHandler.core.js";
|
|
10
10
|
export { createRPCFetchHandler } from "./rpcFetchHandler.core.js";
|
|
11
11
|
export { RPC_HTTP_STATUS, rpcHttpStatus } from "./rpcHttpStatus.helper.js";
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -33,4 +33,3 @@ export interface RPCFetchHandlerOptions {
|
|
|
33
33
|
* disconnects cancels the procedure (its `context.signal` aborts).
|
|
34
34
|
*/
|
|
35
35
|
export declare function createRPCFetchHandler(server: RPCFrameHandler, options?: RPCFetchHandlerOptions): (request: Request) => Promise<Response>;
|
|
36
|
-
//# sourceMappingURL=rpcFetchHandler.core.d.ts.map
|
|
@@ -24,4 +24,3 @@ export declare function fetchOrThrow(run: () => Promise<Response>, signal: Abort
|
|
|
24
24
|
export declare function encode(serializer: RPCFrameSerializer, request: RPCRequest): string;
|
|
25
25
|
/** Reads, parses and shape-checks the reply to `request`. */
|
|
26
26
|
export declare function decode(serializer: RPCFrameSerializer, response: Response, maxBytes: number, request: RPCRequest): Promise<RPCResponse>;
|
|
27
|
-
//# sourceMappingURL=rpcHttpExchange.helper.d.ts.map
|
|
@@ -8,6 +8,7 @@ import { RPCSerializationError, RPCTimeoutError, RPCTransportError, } from "../.
|
|
|
8
8
|
import { combineSignals } from "../../reliability/cancellation/rpcCancellation.helper.js";
|
|
9
9
|
import { abortReasonToRPCError } from "../../reliability/cancellation/rpcAbort.helper.js";
|
|
10
10
|
import { MAX_TIMER_DELAY } from "../../constants/rpcConstants.core.js";
|
|
11
|
+
import { withCause } from "../../errors/rpcErrorCause.helper.js";
|
|
11
12
|
/**
|
|
12
13
|
* Links the caller signal and the deadline into one abort signal.
|
|
13
14
|
*
|
|
@@ -66,13 +67,3 @@ export async function decode(serializer, response, maxBytes, request) {
|
|
|
66
67
|
}
|
|
67
68
|
return frame;
|
|
68
69
|
}
|
|
69
|
-
function withCause(error, cause) {
|
|
70
|
-
Object.defineProperty(error, "cause", {
|
|
71
|
-
value: cause,
|
|
72
|
-
enumerable: false,
|
|
73
|
-
configurable: true,
|
|
74
|
-
writable: true,
|
|
75
|
-
});
|
|
76
|
-
return error;
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=rpcHttpExchange.helper.js.map
|
|
@@ -33,4 +33,3 @@ export interface RPCHttpTransportOptions {
|
|
|
33
33
|
* returned as a response for the client to rebuild into a typed error.
|
|
34
34
|
*/
|
|
35
35
|
export declare function createRPCHttpTransport(options: RPCHttpTransportOptions): RPCTransport;
|
|
36
|
-
//# sourceMappingURL=rpcHttpTransport.core.d.ts.map
|
|
@@ -11,4 +11,3 @@ export type { RPCFrameHandler, RPCMemoryTransportOptions, } from "./memory/index
|
|
|
11
11
|
export { createRPCMemoryTransport } from "./memory/index.js";
|
|
12
12
|
export type { RPCHttpHeaders, RPCHttpTransportOptions, RPCFetchHandlerOptions, } from "./http/index.js";
|
|
13
13
|
export { createRPCHttpTransport, createRPCFetchHandler, RPC_HTTP_STATUS, rpcHttpStatus, } from "./http/index.js";
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -7,4 +7,3 @@
|
|
|
7
7
|
export { createRPCJsonSerializer, isRPCResponseFrame, readBoundedBody, } from "./codec/index.js";
|
|
8
8
|
export { createRPCMemoryTransport } from "./memory/index.js";
|
|
9
9
|
export { createRPCHttpTransport, createRPCFetchHandler, RPC_HTTP_STATUS, rpcHttpStatus, } from "./http/index.js";
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -10,4 +10,3 @@ export type { RPCRequest, RPCRequestOptions } from "./rpcRequest.type.js";
|
|
|
10
10
|
export { createRPCRequest } from "./rpcRequest.type.js";
|
|
11
11
|
export type { RPCErrorPayload, RPCResponse } from "./rpcResponse.type.js";
|
|
12
12
|
export { createRPCErrorPayload, createRPCResponse, createRPCErrorResponse, } from "./rpcResponse.type.js";
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/rpc/types/index.js
CHANGED
|
@@ -29,4 +29,3 @@ export declare function createRPCResponse<TResult = unknown>(id: string, result:
|
|
|
29
29
|
* Creates a failed RPC response.
|
|
30
30
|
*/
|
|
31
31
|
export declare function createRPCErrorResponse(id: string, error: RPCErrorPayload, metadata?: RPCMetadata): RPCResponse<never>;
|
|
32
|
-
//# sourceMappingURL=rpcResponse.type.d.ts.map
|
|
@@ -106,4 +106,3 @@ export declare function parseInput<T>(schema: RPCSchema<T>, value: unknown, proc
|
|
|
106
106
|
* @throws {RPCInternalError}
|
|
107
107
|
*/
|
|
108
108
|
export declare function parseOutput<T>(schema: RPCSchema<T>, value: unknown, procedureName: string): T;
|
|
109
|
-
//# sourceMappingURL=rpcValidation.core.d.ts.map
|
|
@@ -152,4 +152,3 @@ export function parseOutput(schema, value, procedureName) {
|
|
|
152
152
|
.join(", ");
|
|
153
153
|
throw new RPCInternalError(`Procedure "${procedureName}" produced a response that does not match its output schema at ${where}.`, procedureName);
|
|
154
154
|
}
|
|
155
|
-
//# sourceMappingURL=rpcValidation.core.js.map
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -8,4 +8,3 @@ export { createRPCRequest } from "../rpc/types/rpcRequest.type.js";
|
|
|
8
8
|
export { createRPCProcedure } from "../rpc/procedure/rpcProcedure.type.js";
|
|
9
9
|
export { RPCServer } from "../rpc/server/rpcServer.core.js";
|
|
10
10
|
export { RPCClient } from "../rpc/client/rpcClient.core.js";
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/testing/index.js
CHANGED
|
@@ -7,4 +7,3 @@ export { createRPCRequest } from "../rpc/types/rpcRequest.type.js";
|
|
|
7
7
|
export { createRPCProcedure } from "../rpc/procedure/rpcProcedure.type.js";
|
|
8
8
|
export { RPCServer } from "../rpc/server/rpcServer.core.js";
|
|
9
9
|
export { RPCClient } from "../rpc/client/rpcClient.core.js";
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zudojs/rpc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Remote procedure call infrastructure for Zudojs applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"node": ">=24.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zudojs/constants": "1.
|
|
31
|
-
"@zudojs/errors": "1.
|
|
32
|
-
"@zudojs/schema": "1.
|
|
33
|
-
"@zudojs/security": "1.3.
|
|
34
|
-
"@zudojs/serialization": "1.
|
|
35
|
-
"@zudojs/types": "1.
|
|
30
|
+
"@zudojs/constants": "1.2.0",
|
|
31
|
+
"@zudojs/errors": "1.4.0",
|
|
32
|
+
"@zudojs/schema": "1.3.0",
|
|
33
|
+
"@zudojs/security": "1.3.4",
|
|
34
|
+
"@zudojs/serialization": "1.3.0",
|
|
35
|
+
"@zudojs/types": "1.3.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"typescript": "7.0.2",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detection of prototype-polluting keys in decoded, untrusted data.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Returns the first `__proto__`, `constructor` or `prototype` key found
|
|
6
|
-
* anywhere in `value`, or `undefined` when there is none.
|
|
7
|
-
*
|
|
8
|
-
* `JSON.parse` keeps such a key as an ordinary own property, so it reaches
|
|
9
|
-
* handlers intact; the moment one is copied with `Object.assign`, a
|
|
10
|
-
* `for…in` merge or a bracket assignment, it replaces the target's
|
|
11
|
-
* prototype. Transports refuse a frame that carries one rather than
|
|
12
|
-
* silently dropping it.
|
|
13
|
-
*
|
|
14
|
-
* Walks plain objects and arrays only, iteratively (no recursion limit)
|
|
15
|
-
* and cycle-safe, so it is safe on any decoded or in-process value.
|
|
16
|
-
*/
|
|
17
|
-
export declare function findUnsafeKey(value: unknown): string | undefined;
|
|
18
|
-
//# sourceMappingURL=rpcUnsafeKey.helper.d.ts.map
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detection of prototype-polluting keys in decoded, untrusted data.
|
|
3
|
-
*/
|
|
4
|
-
import { SCHEMA_FORBIDDEN_KEYS } from "@zudojs/constants";
|
|
5
|
-
function isTraversable(value) {
|
|
6
|
-
if (typeof value !== "object" || value === null) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
if (Array.isArray(value)) {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
const prototype = Object.getPrototypeOf(value);
|
|
13
|
-
return prototype === Object.prototype || prototype === null;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Returns the first `__proto__`, `constructor` or `prototype` key found
|
|
17
|
-
* anywhere in `value`, or `undefined` when there is none.
|
|
18
|
-
*
|
|
19
|
-
* `JSON.parse` keeps such a key as an ordinary own property, so it reaches
|
|
20
|
-
* handlers intact; the moment one is copied with `Object.assign`, a
|
|
21
|
-
* `for…in` merge or a bracket assignment, it replaces the target's
|
|
22
|
-
* prototype. Transports refuse a frame that carries one rather than
|
|
23
|
-
* silently dropping it.
|
|
24
|
-
*
|
|
25
|
-
* Walks plain objects and arrays only, iteratively (no recursion limit)
|
|
26
|
-
* and cycle-safe, so it is safe on any decoded or in-process value.
|
|
27
|
-
*/
|
|
28
|
-
export function findUnsafeKey(value) {
|
|
29
|
-
if (!isTraversable(value)) {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
const seen = new WeakSet();
|
|
33
|
-
const pending = [value];
|
|
34
|
-
while (pending.length > 0) {
|
|
35
|
-
const node = pending.pop();
|
|
36
|
-
if (seen.has(node)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
seen.add(node);
|
|
40
|
-
if (Array.isArray(node)) {
|
|
41
|
-
for (const child of node) {
|
|
42
|
-
if (isTraversable(child)) {
|
|
43
|
-
pending.push(child);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
for (const key of Object.keys(node)) {
|
|
49
|
-
if (SCHEMA_FORBIDDEN_KEYS.has(key)) {
|
|
50
|
-
return key;
|
|
51
|
-
}
|
|
52
|
-
const child = node[key];
|
|
53
|
-
if (isTraversable(child)) {
|
|
54
|
-
pending.push(child);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=rpcUnsafeKey.helper.js.map
|