agentmail 0.4.13 → 0.4.15
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 +46 -14
- package/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/Client.d.ts +12 -0
- package/dist/cjs/Client.js +74 -0
- package/dist/cjs/api/errors/UnprocessableError.d.ts +6 -0
- package/dist/cjs/api/errors/UnprocessableError.js +54 -0
- package/dist/cjs/api/errors/index.d.ts +1 -0
- package/dist/cjs/api/errors/index.js +1 -0
- package/dist/cjs/api/resources/agent/exports.d.ts +2 -0
- package/dist/cjs/api/resources/agent/exports.js +21 -0
- package/dist/cjs/api/resources/apiKeys/exports.d.ts +2 -0
- package/dist/cjs/api/resources/apiKeys/exports.js +21 -0
- package/dist/cjs/api/resources/attachments/exports.d.ts +1 -0
- package/dist/cjs/api/resources/attachments/exports.js +18 -0
- package/dist/cjs/api/resources/domains/exports.d.ts +2 -0
- package/dist/cjs/api/resources/domains/exports.js +21 -0
- package/dist/cjs/api/resources/drafts/exports.d.ts +2 -0
- package/dist/cjs/api/resources/drafts/exports.js +21 -0
- package/dist/cjs/api/resources/events/exports.d.ts +1 -0
- package/dist/cjs/api/resources/events/exports.js +18 -0
- package/dist/cjs/api/resources/inboxes/exports.d.ts +3 -0
- package/dist/cjs/api/resources/inboxes/exports.js +22 -0
- package/dist/cjs/api/resources/inboxes/resources/apiKeys/exports.d.ts +2 -0
- package/dist/cjs/api/resources/inboxes/resources/apiKeys/exports.js +21 -0
- package/dist/cjs/api/resources/inboxes/resources/drafts/exports.d.ts +2 -0
- package/dist/cjs/api/resources/inboxes/resources/drafts/exports.js +21 -0
- package/dist/cjs/api/resources/inboxes/resources/lists/exports.d.ts +2 -0
- package/dist/cjs/api/resources/inboxes/resources/lists/exports.js +21 -0
- package/dist/cjs/api/resources/inboxes/resources/messages/client/Client.d.ts +1 -1
- package/dist/cjs/api/resources/inboxes/resources/messages/client/Client.js +1 -1
- package/dist/cjs/api/resources/inboxes/resources/messages/exports.d.ts +2 -0
- package/dist/cjs/api/resources/inboxes/resources/messages/exports.js +21 -0
- package/dist/cjs/api/resources/inboxes/resources/metrics/exports.d.ts +2 -0
- package/dist/cjs/api/resources/inboxes/resources/metrics/exports.js +21 -0
- package/dist/cjs/api/resources/inboxes/resources/threads/client/Client.d.ts +17 -0
- package/dist/cjs/api/resources/inboxes/resources/threads/client/Client.js +90 -0
- package/dist/cjs/api/resources/inboxes/resources/threads/exports.d.ts +2 -0
- package/dist/cjs/api/resources/inboxes/resources/threads/exports.js +21 -0
- package/dist/cjs/api/resources/lists/exports.d.ts +2 -0
- package/dist/cjs/api/resources/lists/exports.js +21 -0
- package/dist/cjs/api/resources/messages/exports.d.ts +1 -0
- package/dist/cjs/api/resources/messages/exports.js +18 -0
- package/dist/cjs/api/resources/messages/types/UpdateMessageResponse.d.ts +5 -0
- package/dist/cjs/api/resources/messages/types/UpdateMessageResponse.js +3 -0
- package/dist/cjs/api/resources/messages/types/index.d.ts +1 -0
- package/dist/cjs/api/resources/messages/types/index.js +1 -0
- package/dist/cjs/api/resources/metrics/exports.d.ts +2 -0
- package/dist/cjs/api/resources/metrics/exports.js +21 -0
- package/dist/cjs/api/resources/metrics/types/QueryMetricsResponse.d.ts +1 -1
- package/dist/cjs/api/resources/organizations/exports.d.ts +2 -0
- package/dist/cjs/api/resources/organizations/exports.js +21 -0
- package/dist/cjs/api/resources/pods/exports.d.ts +3 -0
- package/dist/cjs/api/resources/pods/exports.js +22 -0
- package/dist/cjs/api/resources/pods/resources/apiKeys/exports.d.ts +2 -0
- package/dist/cjs/api/resources/pods/resources/apiKeys/exports.js +21 -0
- package/dist/cjs/api/resources/pods/resources/domains/exports.d.ts +2 -0
- package/dist/cjs/api/resources/pods/resources/domains/exports.js +21 -0
- package/dist/cjs/api/resources/pods/resources/drafts/exports.d.ts +2 -0
- package/dist/cjs/api/resources/pods/resources/drafts/exports.js +21 -0
- package/dist/cjs/api/resources/pods/resources/inboxes/exports.d.ts +2 -0
- package/dist/cjs/api/resources/pods/resources/inboxes/exports.js +21 -0
- package/dist/cjs/api/resources/pods/resources/lists/exports.d.ts +2 -0
- package/dist/cjs/api/resources/pods/resources/lists/exports.js +21 -0
- package/dist/cjs/api/resources/pods/resources/metrics/exports.d.ts +2 -0
- package/dist/cjs/api/resources/pods/resources/metrics/exports.js +21 -0
- package/dist/cjs/api/resources/pods/resources/threads/client/Client.d.ts +17 -0
- package/dist/cjs/api/resources/pods/resources/threads/client/Client.js +90 -0
- package/dist/cjs/api/resources/pods/resources/threads/exports.d.ts +2 -0
- package/dist/cjs/api/resources/pods/resources/threads/exports.js +21 -0
- package/dist/cjs/api/resources/threads/client/Client.d.ts +16 -0
- package/dist/cjs/api/resources/threads/client/Client.js +89 -0
- package/dist/cjs/api/resources/threads/exports.d.ts +2 -0
- package/dist/cjs/api/resources/threads/exports.js +21 -0
- package/dist/cjs/api/resources/threads/types/UpdateThreadRequest.d.ts +6 -0
- package/dist/cjs/api/resources/threads/types/UpdateThreadRequest.js +3 -0
- package/dist/cjs/api/resources/threads/types/UpdateThreadResponse.d.ts +5 -0
- package/dist/cjs/api/resources/threads/types/UpdateThreadResponse.js +3 -0
- package/dist/cjs/api/resources/threads/types/index.d.ts +2 -0
- package/dist/cjs/api/resources/threads/types/index.js +2 -0
- package/dist/cjs/api/resources/webhooks/exports.d.ts +3 -0
- package/dist/cjs/api/resources/webhooks/exports.js +22 -0
- package/dist/cjs/api/resources/webhooks/resources/events/exports.d.ts +1 -0
- package/dist/cjs/api/resources/webhooks/resources/events/exports.js +18 -0
- package/dist/cjs/api/resources/websockets/client/Client.d.ts +6 -0
- package/dist/cjs/api/resources/websockets/client/Client.js +8 -3
- package/dist/cjs/api/resources/websockets/client/Socket.d.ts +2 -2
- package/dist/cjs/api/resources/websockets/client/Socket.js +2 -2
- package/dist/cjs/api/resources/websockets/exports.d.ts +3 -0
- package/dist/cjs/api/resources/websockets/exports.js +23 -0
- package/dist/cjs/core/fetcher/BinaryResponse.d.ts +1 -1
- package/dist/cjs/core/fetcher/Fetcher.js +8 -2
- package/dist/cjs/core/fetcher/index.d.ts +2 -0
- package/dist/cjs/core/fetcher/index.js +3 -1
- package/dist/cjs/core/fetcher/makePassthroughRequest.d.ts +49 -0
- package/dist/cjs/core/fetcher/makePassthroughRequest.js +135 -0
- package/dist/cjs/core/fetcher/makeRequest.d.ts +6 -1
- package/dist/cjs/core/fetcher/makeRequest.js +30 -9
- package/dist/cjs/core/runtime/runtime.js +8 -7
- package/dist/cjs/core/schemas/builders/list/list.js +12 -17
- package/dist/cjs/core/schemas/builders/object/object.js +102 -40
- package/dist/cjs/core/schemas/builders/object-like/getObjectLikeUtils.js +10 -3
- package/dist/cjs/core/schemas/builders/record/index.d.ts +2 -2
- package/dist/cjs/core/schemas/builders/record/index.js +2 -1
- package/dist/cjs/core/schemas/builders/record/record.d.ts +2 -1
- package/dist/cjs/core/schemas/builders/record/record.js +63 -25
- package/dist/cjs/core/schemas/builders/record/types.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/union/union.js +9 -12
- package/dist/cjs/core/schemas/utils/isPlainObject.js +4 -6
- package/dist/cjs/core/websocket/ws.d.ts +14 -2
- package/dist/cjs/core/websocket/ws.js +51 -7
- package/dist/cjs/serialization/resources/messages/types/UpdateMessageResponse.d.ts +12 -0
- package/dist/cjs/serialization/resources/messages/types/UpdateMessageResponse.js +44 -0
- package/dist/cjs/serialization/resources/messages/types/index.d.ts +1 -0
- package/dist/cjs/serialization/resources/messages/types/index.js +1 -0
- package/dist/cjs/serialization/resources/metrics/types/QueryMetricsResponse.js +1 -1
- package/dist/cjs/serialization/resources/threads/types/UpdateThreadRequest.d.ts +10 -0
- package/dist/cjs/serialization/resources/threads/types/UpdateThreadRequest.js +42 -0
- package/dist/cjs/serialization/resources/threads/types/UpdateThreadResponse.d.ts +12 -0
- package/dist/cjs/serialization/resources/threads/types/UpdateThreadResponse.js +44 -0
- package/dist/cjs/serialization/resources/threads/types/index.d.ts +2 -0
- package/dist/cjs/serialization/resources/threads/types/index.js +2 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/Client.d.mts +12 -0
- package/dist/esm/Client.mjs +41 -0
- package/dist/esm/api/errors/UnprocessableError.d.mts +6 -0
- package/dist/esm/api/errors/UnprocessableError.mjs +17 -0
- package/dist/esm/api/errors/index.d.mts +1 -0
- package/dist/esm/api/errors/index.mjs +1 -0
- package/dist/esm/api/resources/agent/exports.d.mts +2 -0
- package/dist/esm/api/resources/agent/exports.mjs +3 -0
- package/dist/esm/api/resources/apiKeys/exports.d.mts +2 -0
- package/dist/esm/api/resources/apiKeys/exports.mjs +3 -0
- package/dist/esm/api/resources/attachments/exports.d.mts +1 -0
- package/dist/esm/api/resources/attachments/exports.mjs +2 -0
- package/dist/esm/api/resources/domains/exports.d.mts +2 -0
- package/dist/esm/api/resources/domains/exports.mjs +3 -0
- package/dist/esm/api/resources/drafts/exports.d.mts +2 -0
- package/dist/esm/api/resources/drafts/exports.mjs +3 -0
- package/dist/esm/api/resources/events/exports.d.mts +1 -0
- package/dist/esm/api/resources/events/exports.mjs +2 -0
- package/dist/esm/api/resources/inboxes/exports.d.mts +3 -0
- package/dist/esm/api/resources/inboxes/exports.mjs +4 -0
- package/dist/esm/api/resources/inboxes/resources/apiKeys/exports.d.mts +2 -0
- package/dist/esm/api/resources/inboxes/resources/apiKeys/exports.mjs +3 -0
- package/dist/esm/api/resources/inboxes/resources/drafts/exports.d.mts +2 -0
- package/dist/esm/api/resources/inboxes/resources/drafts/exports.mjs +3 -0
- package/dist/esm/api/resources/inboxes/resources/lists/exports.d.mts +2 -0
- package/dist/esm/api/resources/inboxes/resources/lists/exports.mjs +3 -0
- package/dist/esm/api/resources/inboxes/resources/messages/client/Client.d.mts +1 -1
- package/dist/esm/api/resources/inboxes/resources/messages/client/Client.mjs +1 -1
- package/dist/esm/api/resources/inboxes/resources/messages/exports.d.mts +2 -0
- package/dist/esm/api/resources/inboxes/resources/messages/exports.mjs +3 -0
- package/dist/esm/api/resources/inboxes/resources/metrics/exports.d.mts +2 -0
- package/dist/esm/api/resources/inboxes/resources/metrics/exports.mjs +3 -0
- package/dist/esm/api/resources/inboxes/resources/threads/client/Client.d.mts +17 -0
- package/dist/esm/api/resources/inboxes/resources/threads/client/Client.mjs +90 -0
- package/dist/esm/api/resources/inboxes/resources/threads/exports.d.mts +2 -0
- package/dist/esm/api/resources/inboxes/resources/threads/exports.mjs +3 -0
- package/dist/esm/api/resources/lists/exports.d.mts +2 -0
- package/dist/esm/api/resources/lists/exports.mjs +3 -0
- package/dist/esm/api/resources/messages/exports.d.mts +1 -0
- package/dist/esm/api/resources/messages/exports.mjs +2 -0
- package/dist/esm/api/resources/messages/types/UpdateMessageResponse.d.mts +5 -0
- package/dist/esm/api/resources/messages/types/UpdateMessageResponse.mjs +2 -0
- package/dist/esm/api/resources/messages/types/index.d.mts +1 -0
- package/dist/esm/api/resources/messages/types/index.mjs +1 -0
- package/dist/esm/api/resources/metrics/exports.d.mts +2 -0
- package/dist/esm/api/resources/metrics/exports.mjs +3 -0
- package/dist/esm/api/resources/metrics/types/QueryMetricsResponse.d.mts +1 -1
- package/dist/esm/api/resources/organizations/exports.d.mts +2 -0
- package/dist/esm/api/resources/organizations/exports.mjs +3 -0
- package/dist/esm/api/resources/pods/exports.d.mts +3 -0
- package/dist/esm/api/resources/pods/exports.mjs +4 -0
- package/dist/esm/api/resources/pods/resources/apiKeys/exports.d.mts +2 -0
- package/dist/esm/api/resources/pods/resources/apiKeys/exports.mjs +3 -0
- package/dist/esm/api/resources/pods/resources/domains/exports.d.mts +2 -0
- package/dist/esm/api/resources/pods/resources/domains/exports.mjs +3 -0
- package/dist/esm/api/resources/pods/resources/drafts/exports.d.mts +2 -0
- package/dist/esm/api/resources/pods/resources/drafts/exports.mjs +3 -0
- package/dist/esm/api/resources/pods/resources/inboxes/exports.d.mts +2 -0
- package/dist/esm/api/resources/pods/resources/inboxes/exports.mjs +3 -0
- package/dist/esm/api/resources/pods/resources/lists/exports.d.mts +2 -0
- package/dist/esm/api/resources/pods/resources/lists/exports.mjs +3 -0
- package/dist/esm/api/resources/pods/resources/metrics/exports.d.mts +2 -0
- package/dist/esm/api/resources/pods/resources/metrics/exports.mjs +3 -0
- package/dist/esm/api/resources/pods/resources/threads/client/Client.d.mts +17 -0
- package/dist/esm/api/resources/pods/resources/threads/client/Client.mjs +90 -0
- package/dist/esm/api/resources/pods/resources/threads/exports.d.mts +2 -0
- package/dist/esm/api/resources/pods/resources/threads/exports.mjs +3 -0
- package/dist/esm/api/resources/threads/client/Client.d.mts +16 -0
- package/dist/esm/api/resources/threads/client/Client.mjs +89 -0
- package/dist/esm/api/resources/threads/exports.d.mts +2 -0
- package/dist/esm/api/resources/threads/exports.mjs +3 -0
- package/dist/esm/api/resources/threads/types/UpdateThreadRequest.d.mts +6 -0
- package/dist/esm/api/resources/threads/types/UpdateThreadRequest.mjs +2 -0
- package/dist/esm/api/resources/threads/types/UpdateThreadResponse.d.mts +5 -0
- package/dist/esm/api/resources/threads/types/UpdateThreadResponse.mjs +2 -0
- package/dist/esm/api/resources/threads/types/index.d.mts +2 -0
- package/dist/esm/api/resources/threads/types/index.mjs +2 -0
- package/dist/esm/api/resources/webhooks/exports.d.mts +3 -0
- package/dist/esm/api/resources/webhooks/exports.mjs +4 -0
- package/dist/esm/api/resources/webhooks/resources/events/exports.d.mts +1 -0
- package/dist/esm/api/resources/webhooks/resources/events/exports.mjs +2 -0
- package/dist/esm/api/resources/websockets/client/Client.d.mts +6 -0
- package/dist/esm/api/resources/websockets/client/Client.mjs +8 -3
- package/dist/esm/api/resources/websockets/client/Socket.d.mts +2 -2
- package/dist/esm/api/resources/websockets/client/Socket.mjs +2 -2
- package/dist/esm/api/resources/websockets/exports.d.mts +3 -0
- package/dist/esm/api/resources/websockets/exports.mjs +4 -0
- package/dist/esm/core/fetcher/BinaryResponse.d.mts +1 -1
- package/dist/esm/core/fetcher/Fetcher.mjs +8 -2
- package/dist/esm/core/fetcher/index.d.mts +2 -0
- package/dist/esm/core/fetcher/index.mjs +1 -0
- package/dist/esm/core/fetcher/makePassthroughRequest.d.mts +49 -0
- package/dist/esm/core/fetcher/makePassthroughRequest.mjs +132 -0
- package/dist/esm/core/fetcher/makeRequest.d.mts +6 -1
- package/dist/esm/core/fetcher/makeRequest.mjs +28 -9
- package/dist/esm/core/runtime/runtime.mjs +8 -7
- package/dist/esm/core/schemas/builders/list/list.mjs +12 -17
- package/dist/esm/core/schemas/builders/object/object.mjs +102 -40
- package/dist/esm/core/schemas/builders/object-like/getObjectLikeUtils.mjs +10 -3
- package/dist/esm/core/schemas/builders/record/index.d.mts +2 -2
- package/dist/esm/core/schemas/builders/record/index.mjs +1 -1
- package/dist/esm/core/schemas/builders/record/record.d.mts +2 -1
- package/dist/esm/core/schemas/builders/record/record.mjs +62 -25
- package/dist/esm/core/schemas/builders/record/types.d.mts +2 -0
- package/dist/esm/core/schemas/builders/union/union.mjs +9 -12
- package/dist/esm/core/schemas/utils/isPlainObject.mjs +4 -6
- package/dist/esm/core/websocket/ws.d.mts +14 -2
- package/dist/esm/core/websocket/ws.mjs +51 -7
- package/dist/esm/serialization/resources/messages/types/UpdateMessageResponse.d.mts +12 -0
- package/dist/esm/serialization/resources/messages/types/UpdateMessageResponse.mjs +8 -0
- package/dist/esm/serialization/resources/messages/types/index.d.mts +1 -0
- package/dist/esm/serialization/resources/messages/types/index.mjs +1 -0
- package/dist/esm/serialization/resources/metrics/types/QueryMetricsResponse.mjs +1 -1
- package/dist/esm/serialization/resources/threads/types/UpdateThreadRequest.d.mts +10 -0
- package/dist/esm/serialization/resources/threads/types/UpdateThreadRequest.mjs +6 -0
- package/dist/esm/serialization/resources/threads/types/UpdateThreadResponse.d.mts +12 -0
- package/dist/esm/serialization/resources/threads/types/UpdateThreadResponse.mjs +8 -0
- package/dist/esm/serialization/resources/threads/types/index.d.mts +2 -0
- package/dist/esm/serialization/resources/threads/types/index.mjs +2 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +305 -13
- package/reference.md +231 -1
|
@@ -10,8 +10,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.makeRequest = void 0;
|
|
13
|
+
exports.isCacheNoStoreSupported = isCacheNoStoreSupported;
|
|
14
|
+
exports.resetCacheNoStoreSupported = resetCacheNoStoreSupported;
|
|
13
15
|
const signals_js_1 = require("./signals.js");
|
|
14
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Cached result of checking whether the current runtime supports
|
|
18
|
+
* the `cache` option in `Request`. Some runtimes (e.g. Cloudflare Workers)
|
|
19
|
+
* throw a TypeError when this option is used.
|
|
20
|
+
*/
|
|
21
|
+
let _cacheNoStoreSupported;
|
|
22
|
+
function isCacheNoStoreSupported() {
|
|
23
|
+
if (_cacheNoStoreSupported != null) {
|
|
24
|
+
return _cacheNoStoreSupported;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
new Request("http://localhost", { cache: "no-store" });
|
|
28
|
+
_cacheNoStoreSupported = true;
|
|
29
|
+
}
|
|
30
|
+
catch (_a) {
|
|
31
|
+
_cacheNoStoreSupported = false;
|
|
32
|
+
}
|
|
33
|
+
return _cacheNoStoreSupported;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reset the cached result of `isCacheNoStoreSupported`. Exposed for testing only.
|
|
37
|
+
*/
|
|
38
|
+
function resetCacheNoStoreSupported() {
|
|
39
|
+
_cacheNoStoreSupported = undefined;
|
|
40
|
+
}
|
|
41
|
+
const makeRequest = (fetchFn, url, method, headers, requestBody, timeoutMs, abortSignal, withCredentials, duplex, disableCache) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
42
|
const signals = [];
|
|
16
43
|
let timeoutAbortId;
|
|
17
44
|
if (timeoutMs != null) {
|
|
@@ -23,15 +50,9 @@ const makeRequest = (fetchFn, url, method, headers, requestBody, timeoutMs, abor
|
|
|
23
50
|
signals.push(abortSignal);
|
|
24
51
|
}
|
|
25
52
|
const newSignals = (0, signals_js_1.anySignal)(signals);
|
|
26
|
-
const response = yield fetchFn(url, {
|
|
27
|
-
method: method,
|
|
28
|
-
headers,
|
|
29
|
-
body: requestBody,
|
|
30
|
-
signal: newSignals,
|
|
31
|
-
credentials: withCredentials ? "include" : undefined,
|
|
53
|
+
const response = yield fetchFn(url, Object.assign({ method: method, headers, body: requestBody, signal: newSignals, credentials: withCredentials ? "include" : undefined,
|
|
32
54
|
// @ts-ignore
|
|
33
|
-
duplex,
|
|
34
|
-
});
|
|
55
|
+
duplex }, (disableCache && isCacheNoStoreSupported() ? { cache: "no-store" } : {})));
|
|
35
56
|
if (timeoutAbortId != null) {
|
|
36
57
|
clearTimeout(timeoutAbortId);
|
|
37
58
|
}
|
|
@@ -84,17 +84,18 @@ function evaluateRuntime() {
|
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* A constant that indicates whether the environment the code is running is Node.JS.
|
|
87
|
+
*
|
|
88
|
+
* We assign `process` to a local variable first to avoid being flagged by
|
|
89
|
+
* bundlers that perform static analysis on `process.versions` (e.g. Next.js
|
|
90
|
+
* Edge Runtime warns about Node.js APIs even when they are guarded).
|
|
87
91
|
*/
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
!!process.version &&
|
|
91
|
-
"versions" in process &&
|
|
92
|
-
!!((_e = process.versions) === null || _e === void 0 ? void 0 : _e.node);
|
|
92
|
+
const _process = typeof process !== "undefined" ? process : undefined;
|
|
93
|
+
const isNode = typeof _process !== "undefined" && typeof ((_e = _process.versions) === null || _e === void 0 ? void 0 : _e.node) === "string";
|
|
93
94
|
if (isNode) {
|
|
94
95
|
return {
|
|
95
96
|
type: "node",
|
|
96
|
-
version:
|
|
97
|
-
parsedVersion: Number(
|
|
97
|
+
version: _process.versions.node,
|
|
98
|
+
parsedVersion: Number(_process.versions.node.split(".")[0]),
|
|
98
99
|
};
|
|
99
100
|
}
|
|
100
101
|
return {
|
|
@@ -31,24 +31,19 @@ function validateAndTransformArray(value, transformItem) {
|
|
|
31
31
|
],
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
34
|
+
const result = [];
|
|
35
|
+
const errors = [];
|
|
36
|
+
for (let i = 0; i < value.length; i++) {
|
|
37
|
+
const item = transformItem(value[i], i);
|
|
38
|
+
if (item.ok) {
|
|
39
|
+
result.push(item.value);
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
if (!acc.ok) {
|
|
44
|
-
errors.push(...acc.errors);
|
|
45
|
-
}
|
|
46
|
-
if (!item.ok) {
|
|
41
|
+
else {
|
|
47
42
|
errors.push(...item.errors);
|
|
48
43
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
}
|
|
45
|
+
if (errors.length === 0) {
|
|
46
|
+
return { ok: true, value: result };
|
|
47
|
+
}
|
|
48
|
+
return { ok: false, errors };
|
|
54
49
|
}
|
|
@@ -13,63 +13,113 @@ const partition_js_1 = require("../../utils/partition.js");
|
|
|
13
13
|
const index_js_1 = require("../object-like/index.js");
|
|
14
14
|
const index_js_2 = require("../schema-utils/index.js");
|
|
15
15
|
const property_js_1 = require("./property.js");
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
17
|
+
const _hasOwn = Object.prototype.hasOwnProperty;
|
|
16
18
|
function object(schemas) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
// All property metadata is lazily computed on first use.
|
|
20
|
+
// This keeps schema construction free of iteration, which matters when
|
|
21
|
+
// many schemas are defined but only some are exercised at runtime.
|
|
22
|
+
// Required-key computation is also deferred because lazy() schemas may
|
|
23
|
+
// not be resolved at construction time.
|
|
24
|
+
let _rawKeyToProperty;
|
|
25
|
+
function getRawKeyToProperty() {
|
|
26
|
+
if (_rawKeyToProperty == null) {
|
|
27
|
+
_rawKeyToProperty = {};
|
|
23
28
|
for (const [parsedKey, schemaOrObjectProperty] of (0, entries_js_1.entries)(schemas)) {
|
|
24
|
-
const rawKey = (0, property_js_1.isProperty)(schemaOrObjectProperty)
|
|
29
|
+
const rawKey = (0, property_js_1.isProperty)(schemaOrObjectProperty)
|
|
30
|
+
? schemaOrObjectProperty.rawKey
|
|
31
|
+
: parsedKey;
|
|
25
32
|
const valueSchema = (0, property_js_1.isProperty)(schemaOrObjectProperty)
|
|
26
33
|
? schemaOrObjectProperty.valueSchema
|
|
27
34
|
: schemaOrObjectProperty;
|
|
28
|
-
|
|
35
|
+
_rawKeyToProperty[rawKey] = {
|
|
29
36
|
rawKey,
|
|
30
37
|
parsedKey: parsedKey,
|
|
31
38
|
valueSchema,
|
|
32
39
|
};
|
|
33
|
-
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return _rawKeyToProperty;
|
|
43
|
+
}
|
|
44
|
+
let _parseRequiredKeys;
|
|
45
|
+
let _jsonRequiredKeys;
|
|
46
|
+
let _parseRequiredKeysSet;
|
|
47
|
+
let _jsonRequiredKeysSet;
|
|
48
|
+
function getParseRequiredKeys() {
|
|
49
|
+
if (_parseRequiredKeys == null) {
|
|
50
|
+
_parseRequiredKeys = [];
|
|
51
|
+
_jsonRequiredKeys = [];
|
|
52
|
+
for (const [parsedKey, schemaOrObjectProperty] of (0, entries_js_1.entries)(schemas)) {
|
|
53
|
+
const rawKey = (0, property_js_1.isProperty)(schemaOrObjectProperty)
|
|
54
|
+
? schemaOrObjectProperty.rawKey
|
|
55
|
+
: parsedKey;
|
|
56
|
+
const valueSchema = (0, property_js_1.isProperty)(schemaOrObjectProperty)
|
|
57
|
+
? schemaOrObjectProperty.valueSchema
|
|
58
|
+
: schemaOrObjectProperty;
|
|
34
59
|
if (isSchemaRequired(valueSchema)) {
|
|
35
|
-
|
|
60
|
+
_parseRequiredKeys.push(rawKey);
|
|
61
|
+
_jsonRequiredKeys.push(parsedKey);
|
|
36
62
|
}
|
|
37
63
|
}
|
|
64
|
+
_parseRequiredKeysSet = new Set(_parseRequiredKeys);
|
|
65
|
+
_jsonRequiredKeysSet = new Set(_jsonRequiredKeys);
|
|
66
|
+
}
|
|
67
|
+
return _parseRequiredKeys;
|
|
68
|
+
}
|
|
69
|
+
function getJsonRequiredKeys() {
|
|
70
|
+
if (_jsonRequiredKeys == null) {
|
|
71
|
+
getParseRequiredKeys();
|
|
72
|
+
}
|
|
73
|
+
return _jsonRequiredKeys;
|
|
74
|
+
}
|
|
75
|
+
function getParseRequiredKeysSet() {
|
|
76
|
+
if (_parseRequiredKeysSet == null) {
|
|
77
|
+
getParseRequiredKeys();
|
|
78
|
+
}
|
|
79
|
+
return _parseRequiredKeysSet;
|
|
80
|
+
}
|
|
81
|
+
function getJsonRequiredKeysSet() {
|
|
82
|
+
if (_jsonRequiredKeysSet == null) {
|
|
83
|
+
getParseRequiredKeys();
|
|
84
|
+
}
|
|
85
|
+
return _jsonRequiredKeysSet;
|
|
86
|
+
}
|
|
87
|
+
const baseSchema = {
|
|
88
|
+
_getRawProperties: () => Object.entries(schemas).map(([parsedKey, propertySchema]) => (0, property_js_1.isProperty)(propertySchema) ? propertySchema.rawKey : parsedKey),
|
|
89
|
+
_getParsedProperties: () => (0, keys_js_1.keys)(schemas),
|
|
90
|
+
parse: (raw, opts) => {
|
|
91
|
+
var _a;
|
|
92
|
+
const breadcrumbsPrefix = (_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : [];
|
|
38
93
|
return validateAndTransformObject({
|
|
39
94
|
value: raw,
|
|
40
|
-
requiredKeys,
|
|
95
|
+
requiredKeys: getParseRequiredKeys(),
|
|
96
|
+
requiredKeysSet: getParseRequiredKeysSet(),
|
|
41
97
|
getProperty: (rawKey) => {
|
|
42
|
-
const property =
|
|
98
|
+
const property = getRawKeyToProperty()[rawKey];
|
|
43
99
|
if (property == null) {
|
|
44
100
|
return undefined;
|
|
45
101
|
}
|
|
46
102
|
return {
|
|
47
103
|
transformedKey: property.parsedKey,
|
|
48
104
|
transform: (propertyValue) => {
|
|
49
|
-
|
|
50
|
-
return property.valueSchema.parse(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix:
|
|
105
|
+
const childBreadcrumbs = [...breadcrumbsPrefix, rawKey];
|
|
106
|
+
return property.valueSchema.parse(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: childBreadcrumbs }));
|
|
51
107
|
},
|
|
52
108
|
};
|
|
53
109
|
},
|
|
54
110
|
unrecognizedObjectKeys: opts === null || opts === void 0 ? void 0 : opts.unrecognizedObjectKeys,
|
|
55
111
|
skipValidation: opts === null || opts === void 0 ? void 0 : opts.skipValidation,
|
|
56
|
-
breadcrumbsPrefix
|
|
112
|
+
breadcrumbsPrefix,
|
|
57
113
|
omitUndefined: opts === null || opts === void 0 ? void 0 : opts.omitUndefined,
|
|
58
114
|
});
|
|
59
115
|
},
|
|
60
116
|
json: (parsed, opts) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const valueSchema = (0, property_js_1.isProperty)(schemaOrObjectProperty)
|
|
64
|
-
? schemaOrObjectProperty.valueSchema
|
|
65
|
-
: schemaOrObjectProperty;
|
|
66
|
-
if (isSchemaRequired(valueSchema)) {
|
|
67
|
-
requiredKeys.push(parsedKey);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
117
|
+
var _a;
|
|
118
|
+
const breadcrumbsPrefix = (_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : [];
|
|
70
119
|
return validateAndTransformObject({
|
|
71
120
|
value: parsed,
|
|
72
|
-
requiredKeys,
|
|
121
|
+
requiredKeys: getJsonRequiredKeys(),
|
|
122
|
+
requiredKeysSet: getJsonRequiredKeysSet(),
|
|
73
123
|
getProperty: (parsedKey) => {
|
|
74
124
|
const property = schemas[parsedKey];
|
|
75
125
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -80,8 +130,8 @@ function object(schemas) {
|
|
|
80
130
|
return {
|
|
81
131
|
transformedKey: property.rawKey,
|
|
82
132
|
transform: (propertyValue) => {
|
|
83
|
-
|
|
84
|
-
return property.valueSchema.json(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix:
|
|
133
|
+
const childBreadcrumbs = [...breadcrumbsPrefix, parsedKey];
|
|
134
|
+
return property.valueSchema.json(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: childBreadcrumbs }));
|
|
85
135
|
},
|
|
86
136
|
};
|
|
87
137
|
}
|
|
@@ -89,15 +139,15 @@ function object(schemas) {
|
|
|
89
139
|
return {
|
|
90
140
|
transformedKey: parsedKey,
|
|
91
141
|
transform: (propertyValue) => {
|
|
92
|
-
|
|
93
|
-
return property.json(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix:
|
|
142
|
+
const childBreadcrumbs = [...breadcrumbsPrefix, parsedKey];
|
|
143
|
+
return property.json(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: childBreadcrumbs }));
|
|
94
144
|
},
|
|
95
145
|
};
|
|
96
146
|
}
|
|
97
147
|
},
|
|
98
148
|
unrecognizedObjectKeys: opts === null || opts === void 0 ? void 0 : opts.unrecognizedObjectKeys,
|
|
99
149
|
skipValidation: opts === null || opts === void 0 ? void 0 : opts.skipValidation,
|
|
100
|
-
breadcrumbsPrefix
|
|
150
|
+
breadcrumbsPrefix,
|
|
101
151
|
omitUndefined: opts === null || opts === void 0 ? void 0 : opts.omitUndefined,
|
|
102
152
|
});
|
|
103
153
|
},
|
|
@@ -105,7 +155,7 @@ function object(schemas) {
|
|
|
105
155
|
};
|
|
106
156
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, (0, maybeSkipValidation_js_1.maybeSkipValidation)(baseSchema)), (0, index_js_2.getSchemaUtils)(baseSchema)), (0, index_js_1.getObjectLikeUtils)(baseSchema)), getObjectUtils(baseSchema));
|
|
107
157
|
}
|
|
108
|
-
function validateAndTransformObject({ value, requiredKeys, getProperty, unrecognizedObjectKeys = "fail", skipValidation = false, breadcrumbsPrefix = [], }) {
|
|
158
|
+
function validateAndTransformObject({ value, requiredKeys, requiredKeysSet, getProperty, unrecognizedObjectKeys = "fail", skipValidation = false, breadcrumbsPrefix = [], }) {
|
|
109
159
|
if (!(0, isPlainObject_js_1.isPlainObject)(value)) {
|
|
110
160
|
return {
|
|
111
161
|
ok: false,
|
|
@@ -117,13 +167,21 @@ function validateAndTransformObject({ value, requiredKeys, getProperty, unrecogn
|
|
|
117
167
|
],
|
|
118
168
|
};
|
|
119
169
|
}
|
|
120
|
-
|
|
170
|
+
// Track which required keys have been seen.
|
|
171
|
+
// Use a counter instead of copying the Set to avoid per-call allocation.
|
|
172
|
+
let missingRequiredCount = requiredKeys.length;
|
|
121
173
|
const errors = [];
|
|
122
174
|
const transformed = {};
|
|
123
|
-
for (const
|
|
175
|
+
for (const preTransformedKey in value) {
|
|
176
|
+
if (!_hasOwn.call(value, preTransformedKey)) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const preTransformedItemValue = value[preTransformedKey];
|
|
124
180
|
const property = getProperty(preTransformedKey);
|
|
125
181
|
if (property != null) {
|
|
126
|
-
|
|
182
|
+
if (missingRequiredCount > 0 && requiredKeysSet.has(preTransformedKey)) {
|
|
183
|
+
missingRequiredCount--;
|
|
184
|
+
}
|
|
127
185
|
const value = property.transform(preTransformedItemValue);
|
|
128
186
|
if (value.ok) {
|
|
129
187
|
transformed[property.transformedKey] = value.value;
|
|
@@ -149,12 +207,16 @@ function validateAndTransformObject({ value, requiredKeys, getProperty, unrecogn
|
|
|
149
207
|
}
|
|
150
208
|
}
|
|
151
209
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
210
|
+
if (missingRequiredCount > 0) {
|
|
211
|
+
for (const key of requiredKeys) {
|
|
212
|
+
if (!(key in value)) {
|
|
213
|
+
errors.push({
|
|
214
|
+
path: breadcrumbsPrefix,
|
|
215
|
+
message: `Missing required key "${key}"`,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
158
220
|
if (errors.length === 0 || skipValidation) {
|
|
159
221
|
return {
|
|
160
222
|
ok: true,
|
|
@@ -6,6 +6,8 @@ const filterObject_js_1 = require("../../utils/filterObject.js");
|
|
|
6
6
|
const getErrorMessageForIncorrectType_js_1 = require("../../utils/getErrorMessageForIncorrectType.js");
|
|
7
7
|
const isPlainObject_js_1 = require("../../utils/isPlainObject.js");
|
|
8
8
|
const index_js_1 = require("../schema-utils/index.js");
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
10
|
+
const _hasOwn = Object.prototype.hasOwnProperty;
|
|
9
11
|
function getObjectLikeUtils(schema) {
|
|
10
12
|
return {
|
|
11
13
|
withParsedProperties: (properties) => withParsedProperties(schema, properties),
|
|
@@ -21,9 +23,14 @@ function withParsedProperties(objectLike, properties) {
|
|
|
21
23
|
if (!parsedObject.ok) {
|
|
22
24
|
return parsedObject;
|
|
23
25
|
}
|
|
24
|
-
const additionalProperties =
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
const additionalProperties = {};
|
|
27
|
+
for (const key in properties) {
|
|
28
|
+
if (_hasOwn.call(properties, key)) {
|
|
29
|
+
const value = properties[key];
|
|
30
|
+
additionalProperties[key] =
|
|
31
|
+
typeof value === "function" ? value(parsedObject.value) : value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
27
34
|
return {
|
|
28
35
|
ok: true,
|
|
29
36
|
value: Object.assign(Object.assign({}, parsedObject.value), additionalProperties),
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { record } from "./record.js";
|
|
2
|
-
export type { BaseRecordSchema, RecordSchema } from "./types.js";
|
|
1
|
+
export { partialRecord, record } from "./record.js";
|
|
2
|
+
export type { BasePartialRecordSchema, BaseRecordSchema, PartialRecordSchema, RecordSchema } from "./types.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.record = void 0;
|
|
3
|
+
exports.record = exports.partialRecord = void 0;
|
|
4
4
|
var record_js_1 = require("./record.js");
|
|
5
|
+
Object.defineProperty(exports, "partialRecord", { enumerable: true, get: function () { return record_js_1.partialRecord; } });
|
|
5
6
|
Object.defineProperty(exports, "record", { enumerable: true, get: function () { return record_js_1.record; } });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type Schema } from "../../Schema.js";
|
|
2
|
-
import type { RecordSchema } from "./types.js";
|
|
2
|
+
import type { PartialRecordSchema, RecordSchema } from "./types.js";
|
|
3
3
|
export declare function record<RawKey extends string | number, RawValue, ParsedValue, ParsedKey extends string | number>(keySchema: Schema<RawKey, ParsedKey>, valueSchema: Schema<RawValue, ParsedValue>): RecordSchema<RawKey, RawValue, ParsedKey, ParsedValue>;
|
|
4
|
+
export declare function partialRecord<RawKey extends string | number, RawValue, ParsedValue, ParsedKey extends string | number>(keySchema: Schema<RawKey, ParsedKey>, valueSchema: Schema<RawValue, ParsedValue>): PartialRecordSchema<RawKey, RawValue, ParsedKey, ParsedValue>;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.record = record;
|
|
4
|
+
exports.partialRecord = partialRecord;
|
|
4
5
|
const Schema_js_1 = require("../../Schema.js");
|
|
5
|
-
const entries_js_1 = require("../../utils/entries.js");
|
|
6
6
|
const getErrorMessageForIncorrectType_js_1 = require("../../utils/getErrorMessageForIncorrectType.js");
|
|
7
7
|
const isPlainObject_js_1 = require("../../utils/isPlainObject.js");
|
|
8
8
|
const maybeSkipValidation_js_1 = require("../../utils/maybeSkipValidation.js");
|
|
9
9
|
const index_js_1 = require("../schema-utils/index.js");
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
11
|
+
const _hasOwn = Object.prototype.hasOwnProperty;
|
|
10
12
|
function record(keySchema, valueSchema) {
|
|
11
13
|
const baseSchema = {
|
|
12
14
|
parse: (raw, opts) => {
|
|
@@ -43,6 +45,42 @@ function record(keySchema, valueSchema) {
|
|
|
43
45
|
};
|
|
44
46
|
return Object.assign(Object.assign({}, (0, maybeSkipValidation_js_1.maybeSkipValidation)(baseSchema)), (0, index_js_1.getSchemaUtils)(baseSchema));
|
|
45
47
|
}
|
|
48
|
+
function partialRecord(keySchema, valueSchema) {
|
|
49
|
+
const baseSchema = {
|
|
50
|
+
parse: (raw, opts) => {
|
|
51
|
+
return validateAndTransformRecord({
|
|
52
|
+
value: raw,
|
|
53
|
+
isKeyNumeric: keySchema.getType() === Schema_js_1.SchemaType.NUMBER,
|
|
54
|
+
transformKey: (key) => {
|
|
55
|
+
var _a;
|
|
56
|
+
return keySchema.parse(key, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), `${key} (key)`] }));
|
|
57
|
+
},
|
|
58
|
+
transformValue: (value, key) => {
|
|
59
|
+
var _a;
|
|
60
|
+
return valueSchema.parse(value, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), `${key}`] }));
|
|
61
|
+
},
|
|
62
|
+
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
json: (parsed, opts) => {
|
|
66
|
+
return validateAndTransformRecord({
|
|
67
|
+
value: parsed,
|
|
68
|
+
isKeyNumeric: keySchema.getType() === Schema_js_1.SchemaType.NUMBER,
|
|
69
|
+
transformKey: (key) => {
|
|
70
|
+
var _a;
|
|
71
|
+
return keySchema.json(key, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), `${key} (key)`] }));
|
|
72
|
+
},
|
|
73
|
+
transformValue: (value, key) => {
|
|
74
|
+
var _a;
|
|
75
|
+
return valueSchema.json(value, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), `${key}`] }));
|
|
76
|
+
},
|
|
77
|
+
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
getType: () => Schema_js_1.SchemaType.RECORD,
|
|
81
|
+
};
|
|
82
|
+
return Object.assign(Object.assign({}, (0, maybeSkipValidation_js_1.maybeSkipValidation)(baseSchema)), (0, index_js_1.getSchemaUtils)(baseSchema));
|
|
83
|
+
}
|
|
46
84
|
function validateAndTransformRecord({ value, isKeyNumeric, transformKey, transformValue, breadcrumbsPrefix = [], }) {
|
|
47
85
|
if (!(0, isPlainObject_js_1.isPlainObject)(value)) {
|
|
48
86
|
return {
|
|
@@ -55,11 +93,16 @@ function validateAndTransformRecord({ value, isKeyNumeric, transformKey, transfo
|
|
|
55
93
|
],
|
|
56
94
|
};
|
|
57
95
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
96
|
+
const result = {};
|
|
97
|
+
const errors = [];
|
|
98
|
+
for (const stringKey in value) {
|
|
99
|
+
if (!_hasOwn.call(value, stringKey)) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const entryValue = value[stringKey];
|
|
103
|
+
if (entryValue === undefined) {
|
|
104
|
+
continue;
|
|
61
105
|
}
|
|
62
|
-
const acc = accPromise;
|
|
63
106
|
let key = stringKey;
|
|
64
107
|
if (isKeyNumeric) {
|
|
65
108
|
const numberKey = stringKey.length > 0 ? Number(stringKey) : NaN;
|
|
@@ -68,26 +111,21 @@ function validateAndTransformRecord({ value, isKeyNumeric, transformKey, transfo
|
|
|
68
111
|
}
|
|
69
112
|
}
|
|
70
113
|
const transformedKey = transformKey(key);
|
|
71
|
-
const transformedValue = transformValue(
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
ok: true,
|
|
75
|
-
value: Object.assign(Object.assign({}, acc.value), { [transformedKey.value]: transformedValue.value }),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
const errors = [];
|
|
79
|
-
if (!acc.ok) {
|
|
80
|
-
errors.push(...acc.errors);
|
|
114
|
+
const transformedValue = transformValue(entryValue, key);
|
|
115
|
+
if (transformedKey.ok && transformedValue.ok) {
|
|
116
|
+
result[transformedKey.value] = transformedValue.value;
|
|
81
117
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
118
|
+
else {
|
|
119
|
+
if (!transformedKey.ok) {
|
|
120
|
+
errors.push(...transformedKey.errors);
|
|
121
|
+
}
|
|
122
|
+
if (!transformedValue.ok) {
|
|
123
|
+
errors.push(...transformedValue.errors);
|
|
124
|
+
}
|
|
87
125
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
126
|
+
}
|
|
127
|
+
if (errors.length === 0) {
|
|
128
|
+
return { ok: true, value: result };
|
|
129
|
+
}
|
|
130
|
+
return { ok: false, errors };
|
|
93
131
|
}
|
|
@@ -2,3 +2,5 @@ import type { BaseSchema } from "../../Schema.js";
|
|
|
2
2
|
import type { SchemaUtils } from "../schema-utils/index.js";
|
|
3
3
|
export type RecordSchema<RawKey extends string | number, RawValue, ParsedKey extends string | number, ParsedValue> = BaseRecordSchema<RawKey, RawValue, ParsedKey, ParsedValue> & SchemaUtils<Record<RawKey, RawValue>, Record<ParsedKey, ParsedValue>>;
|
|
4
4
|
export type BaseRecordSchema<RawKey extends string | number, RawValue, ParsedKey extends string | number, ParsedValue> = BaseSchema<Record<RawKey, RawValue>, Record<ParsedKey, ParsedValue>>;
|
|
5
|
+
export type PartialRecordSchema<RawKey extends string | number, RawValue, ParsedKey extends string | number, ParsedValue> = BasePartialRecordSchema<RawKey, RawValue, ParsedKey, ParsedValue> & SchemaUtils<Record<RawKey, RawValue>, Partial<Record<ParsedKey, ParsedValue>>>;
|
|
6
|
+
export type BasePartialRecordSchema<RawKey extends string | number, RawValue, ParsedKey extends string | number, ParsedValue> = BaseSchema<Record<RawKey, RawValue>, Partial<Record<ParsedKey, ParsedValue>>>;
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.union = union;
|
|
15
4
|
const Schema_js_1 = require("../../Schema.js");
|
|
@@ -20,6 +9,8 @@ const maybeSkipValidation_js_1 = require("../../utils/maybeSkipValidation.js");
|
|
|
20
9
|
const index_js_1 = require("../enum/index.js");
|
|
21
10
|
const index_js_2 = require("../object-like/index.js");
|
|
22
11
|
const index_js_3 = require("../schema-utils/index.js");
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
13
|
+
const _hasOwn = Object.prototype.hasOwnProperty;
|
|
23
14
|
function union(discriminant, union) {
|
|
24
15
|
const rawDiscriminant = typeof discriminant === "string" ? discriminant : discriminant.rawDiscriminant;
|
|
25
16
|
const parsedDiscriminant = typeof discriminant === "string"
|
|
@@ -79,7 +70,13 @@ function transformAndValidateUnion({ value, discriminant, transformedDiscriminan
|
|
|
79
70
|
],
|
|
80
71
|
};
|
|
81
72
|
}
|
|
82
|
-
const
|
|
73
|
+
const discriminantValue = value[discriminant];
|
|
74
|
+
const additionalProperties = {};
|
|
75
|
+
for (const key in value) {
|
|
76
|
+
if (_hasOwn.call(value, key) && key !== discriminant) {
|
|
77
|
+
additionalProperties[key] = value[key];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
83
80
|
if (discriminantValue == null) {
|
|
84
81
|
return {
|
|
85
82
|
ok: false,
|
|
@@ -6,12 +6,10 @@ function isPlainObject(value) {
|
|
|
6
6
|
if (typeof value !== "object" || value === null) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
const proto = Object.getPrototypeOf(value);
|
|
10
|
+
if (proto === null) {
|
|
10
11
|
return true;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
proto = Object.getPrototypeOf(proto);
|
|
15
|
-
}
|
|
16
|
-
return Object.getPrototypeOf(value) === proto;
|
|
13
|
+
// Check that the prototype chain has exactly one level (i.e., proto is Object.prototype)
|
|
14
|
+
return Object.getPrototypeOf(proto) === null;
|
|
17
15
|
}
|
|
@@ -9,6 +9,7 @@ export declare namespace ReconnectingWebSocket {
|
|
|
9
9
|
options?: ReconnectingWebSocket.Options;
|
|
10
10
|
headers?: Record<string, unknown>;
|
|
11
11
|
queryParameters?: Record<string, unknown>;
|
|
12
|
+
abortSignal?: AbortSignal;
|
|
12
13
|
}
|
|
13
14
|
type Options = {
|
|
14
15
|
WebSocket?: any;
|
|
@@ -47,7 +48,8 @@ export declare class ReconnectingWebSocket {
|
|
|
47
48
|
private readonly _options;
|
|
48
49
|
private readonly _headers?;
|
|
49
50
|
private readonly _queryParameters?;
|
|
50
|
-
|
|
51
|
+
private readonly _abortSignal?;
|
|
52
|
+
constructor({ url, protocols, options, headers, queryParameters, abortSignal }: ReconnectingWebSocket.Args);
|
|
51
53
|
static readonly CONNECTING = 0;
|
|
52
54
|
static readonly OPEN = 1;
|
|
53
55
|
static readonly CLOSING = 2;
|
|
@@ -83,7 +85,7 @@ export declare class ReconnectingWebSocket {
|
|
|
83
85
|
/**
|
|
84
86
|
* The current state of the connection; this is one of the Ready state constants
|
|
85
87
|
*/
|
|
86
|
-
get readyState():
|
|
88
|
+
get readyState(): ReconnectingWebSocket.ReadyState;
|
|
87
89
|
/**
|
|
88
90
|
* The URL as resolved by the constructor
|
|
89
91
|
*/
|
|
@@ -133,6 +135,7 @@ export declare class ReconnectingWebSocket {
|
|
|
133
135
|
private _wait;
|
|
134
136
|
private _getNextUrl;
|
|
135
137
|
private _connect;
|
|
138
|
+
private _handleAbort;
|
|
136
139
|
private _handleTimeout;
|
|
137
140
|
private _disconnect;
|
|
138
141
|
private _acceptOpen;
|
|
@@ -145,3 +148,12 @@ export declare class ReconnectingWebSocket {
|
|
|
145
148
|
private _addListeners;
|
|
146
149
|
private _clearTimeouts;
|
|
147
150
|
}
|
|
151
|
+
export declare namespace ReconnectingWebSocket {
|
|
152
|
+
const ReadyState: {
|
|
153
|
+
readonly CONNECTING: 0;
|
|
154
|
+
readonly OPEN: 1;
|
|
155
|
+
readonly CLOSING: 2;
|
|
156
|
+
readonly CLOSED: 3;
|
|
157
|
+
};
|
|
158
|
+
type ReadyState = (typeof ReadyState)[keyof typeof ReadyState];
|
|
159
|
+
}
|