@socketsecurity/lib 3.0.2 → 3.0.3
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/CHANGELOG.md +13 -0
- package/dist/abort.js +60 -1
- package/dist/abort.js.map +2 -2
- package/dist/agent.js +289 -1
- package/dist/agent.js.map +2 -2
- package/dist/ansi.js +60 -1
- package/dist/ansi.js.map +2 -2
- package/dist/argv/flags.js +282 -1
- package/dist/argv/flags.js.map +2 -2
- package/dist/argv/parse.js +171 -1
- package/dist/argv/parse.js.map +2 -2
- package/dist/arrays.js +85 -1
- package/dist/arrays.js.map +2 -2
- package/dist/bin.js +419 -5
- package/dist/bin.js.map +2 -2
- package/dist/cacache.js +139 -1
- package/dist/cacache.js.map +2 -2
- package/dist/cache-with-ttl.js +223 -1
- package/dist/cache-with-ttl.js.map +2 -2
- package/dist/constants/agents.js +126 -1
- package/dist/constants/agents.js.map +2 -2
- package/dist/constants/core.js +57 -2
- package/dist/constants/core.js.map +2 -2
- package/dist/constants/encoding.js +48 -1
- package/dist/constants/encoding.js.map +2 -2
- package/dist/constants/github.js +30 -1
- package/dist/constants/github.js.map +2 -2
- package/dist/constants/licenses.js +66 -1
- package/dist/constants/licenses.js.map +2 -2
- package/dist/constants/node.js +185 -1
- package/dist/constants/node.js.map +2 -2
- package/dist/constants/packages.js +128 -1
- package/dist/constants/packages.js.map +2 -2
- package/dist/constants/paths.js +150 -1
- package/dist/constants/paths.js.map +2 -2
- package/dist/constants/platform.js +41 -1
- package/dist/constants/platform.js.map +2 -2
- package/dist/constants/process.js +52 -1
- package/dist/constants/process.js.map +2 -2
- package/dist/constants/socket.js +102 -1
- package/dist/constants/socket.js.map +2 -2
- package/dist/constants/testing.js +36 -1
- package/dist/constants/testing.js.map +2 -2
- package/dist/constants/time.js +39 -1
- package/dist/constants/time.js.map +2 -2
- package/dist/constants/typescript.js +54 -1
- package/dist/constants/typescript.js.map +2 -2
- package/dist/cover/code.js +135 -1
- package/dist/cover/code.js.map +2 -2
- package/dist/cover/formatters.js +101 -11
- package/dist/cover/formatters.js.map +2 -2
- package/dist/cover/type.js +63 -1
- package/dist/cover/type.js.map +2 -2
- package/dist/cover/types.js +15 -1
- package/dist/cover/types.js.map +2 -2
- package/dist/debug.js +337 -2
- package/dist/debug.js.map +2 -2
- package/dist/dlx-binary.js +408 -7
- package/dist/dlx-binary.js.map +2 -2
- package/dist/dlx-package.js +278 -7
- package/dist/dlx-package.js.map +2 -2
- package/dist/dlx.js +214 -7
- package/dist/dlx.js.map +2 -2
- package/dist/effects/pulse-frames.js +64 -1
- package/dist/effects/pulse-frames.js.map +2 -2
- package/dist/effects/text-shimmer.js +174 -1
- package/dist/effects/text-shimmer.js.map +2 -2
- package/dist/effects/types.js +15 -1
- package/dist/effects/types.js.map +2 -2
- package/dist/effects/ultra.js +61 -1
- package/dist/effects/ultra.js.map +2 -2
- package/dist/env/ci.js +31 -1
- package/dist/env/ci.js.map +2 -2
- package/dist/env/debug.js +30 -1
- package/dist/env/debug.js.map +2 -2
- package/dist/env/github.js +65 -1
- package/dist/env/github.js.map +2 -2
- package/dist/env/helpers.js +47 -1
- package/dist/env/helpers.js.map +2 -2
- package/dist/env/home.js +30 -1
- package/dist/env/home.js.map +2 -2
- package/dist/env/locale.js +40 -1
- package/dist/env/locale.js.map +2 -2
- package/dist/env/node-auth-token.js +30 -1
- package/dist/env/node-auth-token.js.map +2 -2
- package/dist/env/node-env.js +30 -1
- package/dist/env/node-env.js.map +2 -2
- package/dist/env/npm.js +50 -1
- package/dist/env/npm.js.map +2 -2
- package/dist/env/package-manager.js +73 -1
- package/dist/env/package-manager.js.map +2 -2
- package/dist/env/path.js +30 -1
- package/dist/env/path.js.map +2 -2
- package/dist/env/pre-commit.js +31 -1
- package/dist/env/pre-commit.js.map +2 -2
- package/dist/env/rewire.js +72 -1
- package/dist/env/rewire.js.map +2 -2
- package/dist/env/shell.js +30 -1
- package/dist/env/shell.js.map +2 -2
- package/dist/env/socket-cli-shadow.js +51 -1
- package/dist/env/socket-cli-shadow.js.map +2 -2
- package/dist/env/socket-cli.js +86 -1
- package/dist/env/socket-cli.js.map +2 -2
- package/dist/env/socket.js +101 -1
- package/dist/env/socket.js.map +2 -2
- package/dist/env/temp-dir.js +40 -1
- package/dist/env/temp-dir.js.map +2 -2
- package/dist/env/term.js +30 -1
- package/dist/env/term.js.map +2 -2
- package/dist/env/test.js +43 -1
- package/dist/env/test.js.map +2 -2
- package/dist/env/windows.js +45 -1
- package/dist/env/windows.js.map +2 -2
- package/dist/env/xdg.js +40 -1
- package/dist/env/xdg.js.map +2 -2
- package/dist/env.js +170 -1
- package/dist/env.js.map +2 -2
- package/dist/fs.js +670 -7
- package/dist/fs.js.map +2 -2
- package/dist/functions.js +68 -1
- package/dist/functions.js.map +2 -2
- package/dist/git.js +329 -2
- package/dist/git.js.map +2 -2
- package/dist/github.js +202 -1
- package/dist/github.js.map +2 -2
- package/dist/globs.js +149 -1
- package/dist/globs.js.map +2 -2
- package/dist/http-request.js +335 -3
- package/dist/http-request.js.map +2 -2
- package/dist/index.js +69 -1
- package/dist/index.js.map +2 -2
- package/dist/ipc.js +244 -1
- package/dist/ipc.js.map +2 -2
- package/dist/json.js +73 -1
- package/dist/json.js.map +2 -2
- package/dist/links/index.js +60 -1
- package/dist/links/index.js.map +2 -2
- package/dist/logger.js +1383 -6
- package/dist/logger.js.map +2 -2
- package/dist/maintained-node-versions.js +35 -1
- package/dist/maintained-node-versions.js.map +2 -2
- package/dist/memoization.js +210 -1
- package/dist/memoization.js.map +2 -2
- package/dist/objects.js +311 -1
- package/dist/objects.js.map +2 -2
- package/dist/packages/editable.js +356 -9
- package/dist/packages/editable.js.map +2 -2
- package/dist/packages/exports.js +162 -1
- package/dist/packages/exports.js.map +2 -2
- package/dist/packages/isolation.js +187 -1
- package/dist/packages/isolation.js.map +2 -2
- package/dist/packages/licenses.js +214 -1
- package/dist/packages/licenses.js.map +2 -2
- package/dist/packages/manifest.js +190 -1
- package/dist/packages/manifest.js.map +2 -2
- package/dist/packages/normalize.js +132 -1
- package/dist/packages/normalize.js.map +2 -2
- package/dist/packages/operations.js +320 -1
- package/dist/packages/operations.js.map +2 -2
- package/dist/packages/paths.js +53 -1
- package/dist/packages/paths.js.map +2 -2
- package/dist/packages/provenance.js +178 -1
- package/dist/packages/provenance.js.map +2 -2
- package/dist/packages/specs.js +83 -1
- package/dist/packages/specs.js.map +2 -2
- package/dist/packages/validation.js +51 -1
- package/dist/packages/validation.js.map +2 -2
- package/dist/packages.js +129 -1
- package/dist/packages.js.map +2 -2
- package/dist/path.js +446 -1
- package/dist/path.js.map +2 -2
- package/dist/paths/rewire.js +79 -1
- package/dist/paths/rewire.js.map +2 -2
- package/dist/paths.js +190 -1
- package/dist/paths.js.map +2 -2
- package/dist/performance.js +216 -15
- package/dist/performance.js.map +2 -2
- package/dist/process-lock.js +287 -8
- package/dist/process-lock.js.map +2 -2
- package/dist/promise-queue.js +109 -1
- package/dist/promise-queue.js.map +2 -2
- package/dist/promises.js +267 -1
- package/dist/promises.js.map +2 -2
- package/dist/prompts/index.js +45 -1
- package/dist/prompts/index.js.map +2 -2
- package/dist/prompts.js +58 -1
- package/dist/prompts.js.map +2 -2
- package/dist/regexps.js +30 -1
- package/dist/regexps.js.map +2 -2
- package/dist/sea.js +44 -1
- package/dist/sea.js.map +2 -2
- package/dist/shadow.js +58 -1
- package/dist/shadow.js.map +2 -2
- package/dist/signal-exit.js +248 -1
- package/dist/signal-exit.js.map +2 -2
- package/dist/sorts.js +94 -1
- package/dist/sorts.js.map +2 -2
- package/dist/spawn.js +200 -1
- package/dist/spawn.js.map +2 -2
- package/dist/spinner.js +961 -1
- package/dist/spinner.js.map +2 -2
- package/dist/ssri.js +71 -1
- package/dist/ssri.js.map +2 -2
- package/dist/stdio/clear.js +82 -1
- package/dist/stdio/clear.js.map +2 -2
- package/dist/stdio/divider.js +89 -3
- package/dist/stdio/divider.js.map +2 -2
- package/dist/stdio/footer.js +94 -2
- package/dist/stdio/footer.js.map +2 -2
- package/dist/stdio/header.js +100 -2
- package/dist/stdio/header.js.map +2 -2
- package/dist/stdio/mask.js +207 -5
- package/dist/stdio/mask.js.map +2 -2
- package/dist/stdio/progress.js +209 -2
- package/dist/stdio/progress.js.map +2 -2
- package/dist/stdio/prompts.js +88 -1
- package/dist/stdio/prompts.js.map +2 -2
- package/dist/stdio/stderr.js +89 -2
- package/dist/stdio/stderr.js.map +2 -2
- package/dist/stdio/stdout.js +103 -2
- package/dist/stdio/stdout.js.map +2 -2
- package/dist/streams.js +78 -1
- package/dist/streams.js.map +2 -2
- package/dist/strings.js +251 -3
- package/dist/strings.js.map +2 -2
- package/dist/suppress-warnings.js +98 -1
- package/dist/suppress-warnings.js.map +2 -2
- package/dist/tables.js +128 -3
- package/dist/tables.js.map +2 -2
- package/dist/temporary-executor.js +53 -1
- package/dist/temporary-executor.js.map +2 -2
- package/dist/themes/context.js +71 -1
- package/dist/themes/context.js.map +2 -2
- package/dist/themes/index.js +57 -1
- package/dist/themes/index.js.map +2 -2
- package/dist/themes/themes.js +195 -1
- package/dist/themes/themes.js.map +2 -2
- package/dist/themes/types.js +15 -1
- package/dist/themes/types.js.map +2 -2
- package/dist/themes/utils.js +116 -1
- package/dist/themes/utils.js.map +2 -2
- package/dist/types.js +59 -1
- package/dist/types.js.map +2 -2
- package/dist/url.js +142 -1
- package/dist/url.js.map +2 -2
- package/dist/utils/get-ipc.js +58 -1
- package/dist/utils/get-ipc.js.map +2 -2
- package/dist/validation/json-parser.js +127 -1
- package/dist/validation/json-parser.js.map +2 -2
- package/dist/validation/types.js +15 -1
- package/dist/validation/types.js.map +2 -2
- package/dist/versions.js +154 -1
- package/dist/versions.js.map +2 -2
- package/dist/words.js +50 -1
- package/dist/words.js.map +2 -2
- package/dist/zod.js +27 -1
- package/dist/zod.js.map +2 -2
- package/package.json +1 -1
package/dist/url.js
CHANGED
|
@@ -1,3 +1,144 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var url_exports = {};
|
|
20
|
+
__export(url_exports, {
|
|
21
|
+
createRelativeUrl: () => createRelativeUrl,
|
|
22
|
+
isUrl: () => isUrl,
|
|
23
|
+
parseUrl: () => parseUrl,
|
|
24
|
+
urlSearchParamAsArray: () => urlSearchParamAsArray,
|
|
25
|
+
urlSearchParamAsBoolean: () => urlSearchParamAsBoolean,
|
|
26
|
+
urlSearchParamAsNumber: () => urlSearchParamAsNumber,
|
|
27
|
+
urlSearchParamAsString: () => urlSearchParamAsString,
|
|
28
|
+
urlSearchParamsGetArray: () => urlSearchParamsGetArray,
|
|
29
|
+
urlSearchParamsGetBoolean: () => urlSearchParamsGetBoolean
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(url_exports);
|
|
32
|
+
const BooleanCtor = Boolean;
|
|
33
|
+
const UrlCtor = URL;
|
|
34
|
+
// @__NO_SIDE_EFFECTS__
|
|
35
|
+
function isUrl(value) {
|
|
36
|
+
return (typeof value === "string" && value !== "" || value !== null && typeof value === "object") && !!/* @__PURE__ */ parseUrl(value);
|
|
37
|
+
}
|
|
38
|
+
// @__NO_SIDE_EFFECTS__
|
|
39
|
+
function parseUrl(value) {
|
|
40
|
+
try {
|
|
41
|
+
return new UrlCtor(value);
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
// @__NO_SIDE_EFFECTS__
|
|
47
|
+
function urlSearchParamAsArray(value) {
|
|
48
|
+
return typeof value === "string" ? value.trim().split(/, */).map((v) => v.trim()).filter(BooleanCtor) : [];
|
|
49
|
+
}
|
|
50
|
+
// @__NO_SIDE_EFFECTS__
|
|
51
|
+
function urlSearchParamAsBoolean(value, options) {
|
|
52
|
+
const { defaultValue = false } = {
|
|
53
|
+
__proto__: null,
|
|
54
|
+
...options
|
|
55
|
+
};
|
|
56
|
+
if (typeof value === "string") {
|
|
57
|
+
const trimmed = value.trim();
|
|
58
|
+
return trimmed === "1" || trimmed.toLowerCase() === "true";
|
|
59
|
+
}
|
|
60
|
+
if (value === null || value === void 0) {
|
|
61
|
+
return !!defaultValue;
|
|
62
|
+
}
|
|
63
|
+
return !!value;
|
|
64
|
+
}
|
|
65
|
+
// @__NO_SIDE_EFFECTS__
|
|
66
|
+
function urlSearchParamsGetArray(params, key) {
|
|
67
|
+
if (params && typeof params.getAll === "function") {
|
|
68
|
+
const values = params.getAll(key);
|
|
69
|
+
const firstValue = values[0];
|
|
70
|
+
if (values.length === 1 && firstValue && firstValue.includes(",")) {
|
|
71
|
+
return /* @__PURE__ */ urlSearchParamAsArray(firstValue);
|
|
72
|
+
}
|
|
73
|
+
return values;
|
|
74
|
+
}
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
// @__NO_SIDE_EFFECTS__
|
|
78
|
+
function urlSearchParamsGetBoolean(params, key, options) {
|
|
79
|
+
const { defaultValue = false } = {
|
|
80
|
+
__proto__: null,
|
|
81
|
+
...options
|
|
82
|
+
};
|
|
83
|
+
if (params && typeof params.get === "function") {
|
|
84
|
+
const value = params.get(key);
|
|
85
|
+
return value !== null ? /* @__PURE__ */ urlSearchParamAsBoolean(value, { defaultValue }) : defaultValue;
|
|
86
|
+
}
|
|
87
|
+
return defaultValue;
|
|
88
|
+
}
|
|
89
|
+
// @__NO_SIDE_EFFECTS__
|
|
90
|
+
function createRelativeUrl(path, options) {
|
|
91
|
+
const { base = "" } = {
|
|
92
|
+
__proto__: null,
|
|
93
|
+
...options
|
|
94
|
+
};
|
|
95
|
+
const relativePath = path.replace(/^\//, "");
|
|
96
|
+
if (base) {
|
|
97
|
+
let baseUrl = base;
|
|
98
|
+
if (!baseUrl.endsWith("/")) {
|
|
99
|
+
baseUrl += "/";
|
|
100
|
+
}
|
|
101
|
+
return baseUrl + relativePath;
|
|
102
|
+
}
|
|
103
|
+
return relativePath;
|
|
104
|
+
}
|
|
105
|
+
// @__NO_SIDE_EFFECTS__
|
|
106
|
+
function urlSearchParamAsString(params, key, options) {
|
|
107
|
+
const { defaultValue = "" } = {
|
|
108
|
+
__proto__: null,
|
|
109
|
+
...options
|
|
110
|
+
};
|
|
111
|
+
if (params && typeof params.get === "function") {
|
|
112
|
+
const value = params.get(key);
|
|
113
|
+
return value !== null ? value : defaultValue;
|
|
114
|
+
}
|
|
115
|
+
return defaultValue;
|
|
116
|
+
}
|
|
117
|
+
// @__NO_SIDE_EFFECTS__
|
|
118
|
+
function urlSearchParamAsNumber(params, key, options) {
|
|
119
|
+
const { defaultValue = 0 } = {
|
|
120
|
+
__proto__: null,
|
|
121
|
+
...options
|
|
122
|
+
};
|
|
123
|
+
if (params && typeof params.get === "function") {
|
|
124
|
+
const value = params.get(key);
|
|
125
|
+
if (value !== null) {
|
|
126
|
+
const num = Number(value);
|
|
127
|
+
return !Number.isNaN(num) ? num : defaultValue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return defaultValue;
|
|
131
|
+
}
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
createRelativeUrl,
|
|
135
|
+
isUrl,
|
|
136
|
+
parseUrl,
|
|
137
|
+
urlSearchParamAsArray,
|
|
138
|
+
urlSearchParamAsBoolean,
|
|
139
|
+
urlSearchParamAsNumber,
|
|
140
|
+
urlSearchParamAsString,
|
|
141
|
+
urlSearchParamsGetArray,
|
|
142
|
+
urlSearchParamsGetBoolean
|
|
143
|
+
});
|
|
3
144
|
//# sourceMappingURL=url.js.map
|
package/dist/url.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/url.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * @fileoverview URL parsing and validation utilities.\n * Provides URL validation, normalization, and parsing helpers.\n */\n\nconst BooleanCtor = Boolean\nconst UrlCtor = URL\n\n/**\n * Check if a value is a valid URL.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isUrl(value: string | URL | null | undefined): boolean {\n return (\n ((typeof value === 'string' && value !== '') ||\n (value !== null && typeof value === 'object')) &&\n !!parseUrl(value)\n )\n}\n\n/**\n * Parse a value as a URL.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function parseUrl(value: string | URL): URL | undefined {\n try {\n return new UrlCtor(value)\n } catch {}\n return undefined\n}\n\n/**\n * Convert a URL search parameter to an array.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function urlSearchParamAsArray(\n value: string | null | undefined,\n): string[] {\n return typeof value === 'string'\n ? value\n .trim()\n .split(/, */)\n .map(v => v.trim())\n .filter(BooleanCtor)\n : []\n}\n\nexport interface UrlSearchParamAsBooleanOptions {\n defaultValue?: boolean\n}\n\n/**\n * Convert a URL search parameter to a boolean.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function urlSearchParamAsBoolean(\n value: string | null | undefined,\n options?: UrlSearchParamAsBooleanOptions | undefined,\n): boolean {\n const { defaultValue = false } = {\n __proto__: null,\n ...options,\n } as UrlSearchParamAsBooleanOptions\n if (typeof value === 'string') {\n const trimmed = value.trim()\n return trimmed === '1' || trimmed.toLowerCase() === 'true'\n }\n if (value === null || value === undefined) {\n return !!defaultValue\n }\n return !!value\n}\n\n/**\n * Helper to get array from URLSearchParams.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function urlSearchParamsGetArray(\n params: URLSearchParams | null | undefined,\n key: string,\n): string[] {\n if (params && typeof params.getAll === 'function') {\n const values = params.getAll(key)\n // If single value contains commas, split it\n const firstValue = values[0]\n if (values.length === 1 && firstValue && firstValue.includes(',')) {\n return urlSearchParamAsArray(firstValue)\n }\n return values\n }\n return []\n}\n\nexport interface UrlSearchParamsGetBooleanOptions {\n defaultValue?: boolean\n}\n\n/**\n * Helper to get boolean from URLSearchParams.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function urlSearchParamsGetBoolean(\n params: URLSearchParams | null | undefined,\n key: string,\n options?: UrlSearchParamsGetBooleanOptions | undefined,\n): boolean {\n const { defaultValue = false } = {\n __proto__: null,\n ...options,\n } as UrlSearchParamsGetBooleanOptions\n if (params && typeof params.get === 'function') {\n const value = params.get(key)\n return value !== null\n ? urlSearchParamAsBoolean(value, { defaultValue })\n : defaultValue\n }\n return defaultValue\n}\n\nexport interface CreateRelativeUrlOptions {\n base?: string\n}\n\n/**\n * Create a relative URL for testing.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createRelativeUrl(\n path: string,\n options?: CreateRelativeUrlOptions | undefined,\n): string {\n const { base = '' } = {\n __proto__: null,\n ...options,\n } as CreateRelativeUrlOptions\n // Remove leading slash to make it relative.\n const relativePath = path.replace(/^\\//, '')\n\n if (base) {\n let baseUrl = base\n if (!baseUrl.endsWith('/')) {\n baseUrl += '/'\n }\n return baseUrl + relativePath\n }\n\n return relativePath\n}\n\nexport interface UrlSearchParamAsStringOptions {\n defaultValue?: string\n}\n\n/**\n * Get string value from URLSearchParams with a default.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function urlSearchParamAsString(\n params: URLSearchParams | null | undefined,\n key: string,\n options?: UrlSearchParamAsStringOptions | undefined,\n): string {\n const { defaultValue = '' } = {\n __proto__: null,\n ...options,\n } as UrlSearchParamAsStringOptions\n if (params && typeof params.get === 'function') {\n const value = params.get(key)\n return value !== null ? value : defaultValue\n }\n return defaultValue\n}\n\nexport interface UrlSearchParamAsNumberOptions {\n defaultValue?: number\n}\n\n/**\n * Get number value from URLSearchParams with a default.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function urlSearchParamAsNumber(\n params: URLSearchParams | null | undefined,\n key: string,\n options?: UrlSearchParamAsNumberOptions | undefined,\n): number {\n const { defaultValue = 0 } = {\n __proto__: null,\n ...options,\n } as UrlSearchParamAsNumberOptions\n if (params && typeof params.get === 'function') {\n const value = params.get(key)\n if (value !== null) {\n const num = Number(value)\n return !Number.isNaN(num) ? num : defaultValue\n }\n }\n return defaultValue\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/utils/get-ipc.js
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_ipc_exports = {};
|
|
20
|
+
__export(get_ipc_exports, {
|
|
21
|
+
default: () => get_ipc_default,
|
|
22
|
+
getIpc: () => getIpc
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(get_ipc_exports);
|
|
25
|
+
let _ipcObject;
|
|
26
|
+
async function getIpc(key) {
|
|
27
|
+
if (_ipcObject === void 0) {
|
|
28
|
+
_ipcObject = {};
|
|
29
|
+
const { env } = process;
|
|
30
|
+
if (env["SOCKET_CLI_FIX"]) {
|
|
31
|
+
_ipcObject.SOCKET_CLI_FIX = env["SOCKET_CLI_FIX"];
|
|
32
|
+
}
|
|
33
|
+
if (env["SOCKET_CLI_OPTIMIZE"]) {
|
|
34
|
+
_ipcObject.SOCKET_CLI_OPTIMIZE = env["SOCKET_CLI_OPTIMIZE"] === "true" || env["SOCKET_CLI_OPTIMIZE"] === "1";
|
|
35
|
+
}
|
|
36
|
+
if (env["SOCKET_CLI_SHADOW_ACCEPT_RISKS"]) {
|
|
37
|
+
_ipcObject.SOCKET_CLI_SHADOW_ACCEPT_RISKS = env["SOCKET_CLI_SHADOW_ACCEPT_RISKS"] === "true" || env["SOCKET_CLI_SHADOW_ACCEPT_RISKS"] === "1";
|
|
38
|
+
}
|
|
39
|
+
if (env["SOCKET_CLI_SHADOW_API_TOKEN"]) {
|
|
40
|
+
_ipcObject.SOCKET_CLI_SHADOW_API_TOKEN = env["SOCKET_CLI_SHADOW_API_TOKEN"];
|
|
41
|
+
}
|
|
42
|
+
if (env["SOCKET_CLI_SHADOW_BIN"]) {
|
|
43
|
+
_ipcObject.SOCKET_CLI_SHADOW_BIN = env["SOCKET_CLI_SHADOW_BIN"];
|
|
44
|
+
}
|
|
45
|
+
if (env["SOCKET_CLI_SHADOW_PROGRESS"]) {
|
|
46
|
+
_ipcObject.SOCKET_CLI_SHADOW_PROGRESS = env["SOCKET_CLI_SHADOW_PROGRESS"] === "true" || env["SOCKET_CLI_SHADOW_PROGRESS"] === "1";
|
|
47
|
+
}
|
|
48
|
+
if (env["SOCKET_CLI_SHADOW_SILENT"]) {
|
|
49
|
+
_ipcObject.SOCKET_CLI_SHADOW_SILENT = env["SOCKET_CLI_SHADOW_SILENT"] === "true" || env["SOCKET_CLI_SHADOW_SILENT"] === "1";
|
|
50
|
+
}
|
|
51
|
+
Object.freeze(_ipcObject);
|
|
52
|
+
}
|
|
53
|
+
return key ? _ipcObject[key] : _ipcObject;
|
|
54
|
+
}
|
|
55
|
+
var get_ipc_default = getIpc;
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
getIpc
|
|
59
|
+
});
|
|
3
60
|
//# sourceMappingURL=get-ipc.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/get-ipc.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * IPC (Inter-Process Communication) object getter.\n * Handles communication between parent and child processes.\n */\n\nexport interface IpcObject {\n SOCKET_CLI_FIX?: string | undefined\n SOCKET_CLI_OPTIMIZE?: boolean | undefined\n SOCKET_CLI_SHADOW_ACCEPT_RISKS?: boolean | undefined\n SOCKET_CLI_SHADOW_API_TOKEN?: string | undefined\n SOCKET_CLI_SHADOW_BIN?: string | undefined\n SOCKET_CLI_SHADOW_PROGRESS?: boolean | undefined\n SOCKET_CLI_SHADOW_SILENT?: boolean | undefined\n}\n\nlet _ipcObject: IpcObject | undefined\n\nexport async function getIpc(): Promise<IpcObject>\nexport async function getIpc<K extends keyof IpcObject>(\n key: K,\n): Promise<IpcObject[K]>\nexport async function getIpc(\n key?: keyof IpcObject,\n): Promise<IpcObject | IpcObject[keyof IpcObject]> {\n if (_ipcObject === undefined) {\n _ipcObject = {}\n\n // Check for IPC environment variables.\n const { env } = process\n\n if (env['SOCKET_CLI_FIX']) {\n _ipcObject.SOCKET_CLI_FIX = env['SOCKET_CLI_FIX']\n }\n\n if (env['SOCKET_CLI_OPTIMIZE']) {\n _ipcObject.SOCKET_CLI_OPTIMIZE =\n env['SOCKET_CLI_OPTIMIZE'] === 'true' ||\n env['SOCKET_CLI_OPTIMIZE'] === '1'\n }\n\n if (env['SOCKET_CLI_SHADOW_ACCEPT_RISKS']) {\n _ipcObject.SOCKET_CLI_SHADOW_ACCEPT_RISKS =\n env['SOCKET_CLI_SHADOW_ACCEPT_RISKS'] === 'true' ||\n env['SOCKET_CLI_SHADOW_ACCEPT_RISKS'] === '1'\n }\n\n if (env['SOCKET_CLI_SHADOW_API_TOKEN']) {\n _ipcObject.SOCKET_CLI_SHADOW_API_TOKEN =\n env['SOCKET_CLI_SHADOW_API_TOKEN']\n }\n\n if (env['SOCKET_CLI_SHADOW_BIN']) {\n _ipcObject.SOCKET_CLI_SHADOW_BIN = env['SOCKET_CLI_SHADOW_BIN']\n }\n\n if (env['SOCKET_CLI_SHADOW_PROGRESS']) {\n _ipcObject.SOCKET_CLI_SHADOW_PROGRESS =\n env['SOCKET_CLI_SHADOW_PROGRESS'] === 'true' ||\n env['SOCKET_CLI_SHADOW_PROGRESS'] === '1'\n }\n\n if (env['SOCKET_CLI_SHADOW_SILENT']) {\n _ipcObject.SOCKET_CLI_SHADOW_SILENT =\n env['SOCKET_CLI_SHADOW_SILENT'] === 'true' ||\n env['SOCKET_CLI_SHADOW_SILENT'] === '1'\n }\n\n Object.freeze(_ipcObject)\n }\n\n return key ? _ipcObject[key] : _ipcObject\n}\n\nexport default getIpc\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,IAAI;AAMJ,eAAsB,OACpB,KACiD;AACjD,MAAI,eAAe,QAAW;AAC5B,iBAAa,CAAC;AAGd,UAAM,EAAE,IAAI,IAAI;AAEhB,QAAI,IAAI,gBAAgB,GAAG;AACzB,iBAAW,iBAAiB,IAAI,gBAAgB;AAAA,IAClD;AAEA,QAAI,IAAI,qBAAqB,GAAG;AAC9B,iBAAW,sBACT,IAAI,qBAAqB,MAAM,UAC/B,IAAI,qBAAqB,MAAM;AAAA,IACnC;AAEA,QAAI,IAAI,gCAAgC,GAAG;AACzC,iBAAW,iCACT,IAAI,gCAAgC,MAAM,UAC1C,IAAI,gCAAgC,MAAM;AAAA,IAC9C;AAEA,QAAI,IAAI,6BAA6B,GAAG;AACtC,iBAAW,8BACT,IAAI,6BAA6B;AAAA,IACrC;AAEA,QAAI,IAAI,uBAAuB,GAAG;AAChC,iBAAW,wBAAwB,IAAI,uBAAuB;AAAA,IAChE;AAEA,QAAI,IAAI,4BAA4B,GAAG;AACrC,iBAAW,6BACT,IAAI,4BAA4B,MAAM,UACtC,IAAI,4BAA4B,MAAM;AAAA,IAC1C;AAEA,QAAI,IAAI,0BAA0B,GAAG;AACnC,iBAAW,2BACT,IAAI,0BAA0B,MAAM,UACpC,IAAI,0BAA0B,MAAM;AAAA,IACxC;AAEA,WAAO,OAAO,UAAU;AAAA,EAC1B;AAEA,SAAO,MAAM,WAAW,GAAG,IAAI;AACjC;AAEA,IAAO,kBAAQ;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,129 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var json_parser_exports = {};
|
|
20
|
+
__export(json_parser_exports, {
|
|
21
|
+
createJsonParser: () => createJsonParser,
|
|
22
|
+
parseJsonWithResult: () => parseJsonWithResult,
|
|
23
|
+
parseNdjson: () => parseNdjson,
|
|
24
|
+
safeJsonParse: () => safeJsonParse,
|
|
25
|
+
streamNdjson: () => streamNdjson,
|
|
26
|
+
tryJsonParse: () => tryJsonParse
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(json_parser_exports);
|
|
29
|
+
const { hasOwn: ObjectHasOwn } = Object;
|
|
30
|
+
function safeJsonParse(jsonString, schema, options = {}) {
|
|
31
|
+
const { allowPrototype = false, maxSize = 10 * 1024 * 1024 } = options;
|
|
32
|
+
const byteLength = Buffer.byteLength(jsonString, "utf8");
|
|
33
|
+
if (byteLength > maxSize) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`JSON string exceeds maximum size limit${maxSize !== 10 * 1024 * 1024 ? ` of ${maxSize} bytes` : ""}`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
let parsed;
|
|
39
|
+
try {
|
|
40
|
+
parsed = JSON.parse(jsonString);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new Error(`Failed to parse JSON: ${error}`);
|
|
43
|
+
}
|
|
44
|
+
if (!allowPrototype && typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
45
|
+
const dangerous = ["__proto__", "constructor", "prototype"];
|
|
46
|
+
for (const key of dangerous) {
|
|
47
|
+
if (ObjectHasOwn(parsed, key)) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"JSON contains potentially malicious prototype pollution keys"
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (schema) {
|
|
55
|
+
const result = schema.safeParse(parsed);
|
|
56
|
+
if (!result.success) {
|
|
57
|
+
const errors = result.error.issues.map(
|
|
58
|
+
(issue) => `${issue.path.join(".")}: ${issue.message}`
|
|
59
|
+
).join(", ");
|
|
60
|
+
throw new Error(`Validation failed: ${errors}`);
|
|
61
|
+
}
|
|
62
|
+
return result.data;
|
|
63
|
+
}
|
|
64
|
+
return parsed;
|
|
65
|
+
}
|
|
66
|
+
function tryJsonParse(jsonString, schema, options) {
|
|
67
|
+
try {
|
|
68
|
+
return safeJsonParse(jsonString, schema, options);
|
|
69
|
+
} catch {
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function parseJsonWithResult(jsonString, schema, options) {
|
|
74
|
+
try {
|
|
75
|
+
const data = safeJsonParse(jsonString, schema, options);
|
|
76
|
+
return { success: true, data };
|
|
77
|
+
} catch (error) {
|
|
78
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
79
|
+
return { success: false, error: message };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function createJsonParser(schema, defaultOptions) {
|
|
83
|
+
return (jsonString, options) => {
|
|
84
|
+
return safeJsonParse(jsonString, schema, { ...defaultOptions, ...options });
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function parseNdjson(ndjson, schema, options) {
|
|
88
|
+
const results = [];
|
|
89
|
+
const lines = ndjson.split(/\r?\n/);
|
|
90
|
+
for (let i = 0; i < lines.length; i++) {
|
|
91
|
+
const line = lines[i]?.trim();
|
|
92
|
+
if (!line || line === "") {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const parsed = safeJsonParse(line, schema, options);
|
|
97
|
+
results.push(parsed);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
100
|
+
throw new Error(`Failed to parse NDJSON at line ${i + 1}: ${message}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return results;
|
|
104
|
+
}
|
|
105
|
+
function* streamNdjson(ndjson, schema, options) {
|
|
106
|
+
const lines = ndjson.split(/\r?\n/);
|
|
107
|
+
for (let i = 0; i < lines.length; i++) {
|
|
108
|
+
const line = lines[i]?.trim();
|
|
109
|
+
if (!line || line === "") {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
yield safeJsonParse(line, schema, options);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
116
|
+
throw new Error(`Failed to parse NDJSON at line ${i + 1}: ${message}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
+
0 && (module.exports = {
|
|
122
|
+
createJsonParser,
|
|
123
|
+
parseJsonWithResult,
|
|
124
|
+
parseNdjson,
|
|
125
|
+
safeJsonParse,
|
|
126
|
+
streamNdjson,
|
|
127
|
+
tryJsonParse
|
|
128
|
+
});
|
|
3
129
|
//# sourceMappingURL=json-parser.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/validation/json-parser.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * @fileoverview Safe JSON parsing with validation and security controls.\n * Provides protection against prototype pollution, size limits, and schema validation.\n *\n * Key Features:\n * - Prototype pollution protection: Blocks `__proto__`, `constructor`, and `prototype` keys\n * - Size limits: Configurable maximum JSON string size (default 10MB)\n * - Schema validation: Optional Zod-compatible schema validation\n * - NDJSON support: Parse newline-delimited JSON streams\n * - Memory safety: Prevents memory exhaustion attacks\n */\n\nimport type { JsonParseOptions, JsonParseResult, Schema } from './types'\n\nconst { hasOwn: ObjectHasOwn } = Object\n\n/**\n * Safely parse JSON with optional schema validation and security controls.\n * Throws errors on parse failures, validation failures, or security violations.\n *\n * This is the recommended method for parsing untrusted JSON input as it provides\n * multiple layers of security including prototype pollution protection and size limits.\n *\n * @template T - The expected type of the parsed data\n * @param jsonString - The JSON string to parse\n * @param schema - Optional Zod-compatible schema for validation\n * @param options - Parsing options for security and behavior control\n * @returns The parsed and validated data\n *\n * @throws {Error} When JSON string exceeds `maxSize`\n * @throws {Error} When JSON parsing fails\n * @throws {Error} When prototype pollution keys are detected (unless `allowPrototype` is `true`)\n * @throws {Error} When schema validation fails\n *\n * @example\n * ```ts\n * // Basic parsing with type inference\n * const data = safeJsonParse<User>('{\"name\":\"Alice\",\"age\":30}')\n *\n * // With schema validation\n * import { z } from 'zod'\n * const userSchema = z.object({\n * name: z.string(),\n * age: z.number()\n * })\n * const user = safeJsonParse('{\"name\":\"Alice\",\"age\":30}', userSchema)\n *\n * // With size limit\n * const data = safeJsonParse(jsonString, undefined, {\n * maxSize: 1024 * 1024 // 1MB\n * })\n *\n * // Allow prototype keys (dangerous - only for trusted sources)\n * const data = safeJsonParse(jsonString, undefined, {\n * allowPrototype: true\n * })\n * ```\n */\nexport function safeJsonParse<T = unknown>(\n jsonString: string,\n schema?: Schema<T> | undefined,\n options: JsonParseOptions = {},\n): T {\n const { allowPrototype = false, maxSize = 10 * 1024 * 1024 } = options\n\n // Check size limit\n const byteLength = Buffer.byteLength(jsonString, 'utf8')\n if (byteLength > maxSize) {\n throw new Error(\n `JSON string exceeds maximum size limit${maxSize !== 10 * 1024 * 1024 ? ` of ${maxSize} bytes` : ''}`,\n )\n }\n\n // Parse JSON\n let parsed: unknown\n try {\n parsed = JSON.parse(jsonString)\n } catch (error) {\n throw new Error(`Failed to parse JSON: ${error}`)\n }\n\n // Check for prototype pollution\n if (\n !allowPrototype &&\n typeof parsed === 'object' &&\n parsed !== null &&\n !Array.isArray(parsed)\n ) {\n const dangerous = ['__proto__', 'constructor', 'prototype']\n for (const key of dangerous) {\n if (ObjectHasOwn(parsed, key)) {\n throw new Error(\n 'JSON contains potentially malicious prototype pollution keys',\n )\n }\n }\n }\n\n // Validate against schema if provided\n if (schema) {\n const result = schema.safeParse(parsed)\n if (!result.success) {\n const errors = result.error.issues\n .map(\n (issue: { path: Array<string | number>; message: string }) =>\n `${issue.path.join('.')}: ${issue.message}`,\n )\n .join(', ')\n throw new Error(`Validation failed: ${errors}`)\n }\n return result.data as T\n }\n\n return parsed as T\n}\n\n/**\n * Attempt to parse JSON, returning `undefined` on any error.\n * This is a non-throwing wrapper around `safeJsonParse` for cases where\n * you want to gracefully handle parse failures without try-catch blocks.\n *\n * Use this when parsing is optional or you have a fallback strategy.\n * For critical parsing where you need error details, use `safeJsonParse` or `parseJsonWithResult`.\n *\n * @template T - The expected type of the parsed data\n * @param jsonString - The JSON string to parse\n * @param schema - Optional Zod-compatible schema for validation\n * @param options - Parsing options for security and behavior control\n * @returns The parsed data on success, or `undefined` on any error\n *\n * @example\n * ```ts\n * // Graceful fallback to default\n * const config = tryJsonParse<Config>(jsonString) ?? defaultConfig\n *\n * // Optional parsing\n * const data = tryJsonParse(possiblyInvalidJson)\n * if (data) {\n * console.log('Parsed successfully:', data)\n * }\n *\n * // With schema validation\n * const user = tryJsonParse(jsonString, userSchema)\n * ```\n */\nexport function tryJsonParse<T = unknown>(\n jsonString: string,\n schema?: Schema<T> | undefined,\n options?: JsonParseOptions | undefined,\n): T | undefined {\n try {\n return safeJsonParse(jsonString, schema, options)\n } catch {\n return undefined\n }\n}\n\n/**\n * Parse JSON and return a discriminated union result.\n * Never throws - always returns a result object with success/failure information.\n *\n * This is ideal when you need detailed error messages and type-safe result handling.\n * The discriminated union allows TypeScript to narrow types based on the `success` flag.\n *\n * @template T - The expected type of the parsed data\n * @param jsonString - The JSON string to parse\n * @param schema - Optional Zod-compatible schema for validation\n * @param options - Parsing options for security and behavior control\n * @returns Result object with either `{success: true, data}` or `{success: false, error}`\n *\n * @example\n * ```ts\n * // Type-safe error handling\n * const result = parseJsonWithResult<User>(jsonString, userSchema)\n *\n * if (result.success) {\n * // TypeScript knows result.data is available\n * console.log(`User: ${result.data.name}`)\n * } else {\n * // TypeScript knows result.error is available\n * console.error(`Parse failed: ${result.error}`)\n * }\n *\n * // Early return pattern\n * const result = parseJsonWithResult(jsonString)\n * if (!result.success) {\n * logger.error(result.error)\n * return\n * }\n * processData(result.data)\n * ```\n */\nexport function parseJsonWithResult<T = unknown>(\n jsonString: string,\n schema?: Schema<T> | undefined,\n options?: JsonParseOptions | undefined,\n): JsonParseResult<T> {\n try {\n const data = safeJsonParse(jsonString, schema, options)\n return { success: true, data }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : 'Unknown error'\n return { success: false, error: message }\n }\n}\n\n/**\n * Create a reusable JSON parser with pre-configured schema and options.\n * Useful for parsing multiple JSON strings with the same validation rules.\n *\n * The returned parser function can accept per-call options that override the defaults.\n * This factory pattern reduces repetition when parsing many similar JSON payloads.\n *\n * @template T - The expected type of the parsed data\n * @param schema - Optional Zod-compatible schema for validation\n * @param defaultOptions - Default parsing options applied to all parse calls\n * @returns A parser function that accepts a JSON string and optional per-call options\n *\n * @example\n * ```ts\n * // Create a parser for API responses\n * import { z } from 'zod'\n * const apiResponseSchema = z.object({\n * status: z.string(),\n * data: z.unknown()\n * })\n *\n * const parseApiResponse = createJsonParser(apiResponseSchema, {\n * maxSize: 5 * 1024 * 1024 // 5MB limit for API responses\n * })\n *\n * // Use the parser multiple times\n * const response1 = parseApiResponse(json1)\n * const response2 = parseApiResponse(json2)\n *\n * // Override options for specific calls\n * const response3 = parseApiResponse(json3, { maxSize: 10 * 1024 * 1024 })\n * ```\n */\nexport function createJsonParser<T = unknown>(\n schema?: Schema<T> | undefined,\n defaultOptions?: JsonParseOptions | undefined,\n) {\n return (jsonString: string, options?: JsonParseOptions | undefined): T => {\n return safeJsonParse(jsonString, schema, { ...defaultOptions, ...options })\n }\n}\n\n/**\n * Parse newline-delimited JSON (NDJSON) into an array.\n * Each line is treated as a separate JSON object. Empty lines are skipped.\n *\n * NDJSON format is commonly used for streaming logs, bulk data transfers,\n * and event streams where each line represents a complete JSON document.\n *\n * @template T - The expected type of each parsed JSON object\n * @param ndjson - Newline-delimited JSON string (supports both `\\n` and `\\r\\n`)\n * @param schema - Optional Zod-compatible schema for validation of each line\n * @param options - Parsing options applied to each line\n * @returns Array of parsed objects, one per non-empty line\n *\n * @throws {Error} When any line fails to parse (includes line number in error message)\n *\n * @example\n * ```ts\n * // Parse NDJSON logs\n * const ndjsonString = `\n * {\"level\":\"info\",\"message\":\"Server started\"}\n * {\"level\":\"error\",\"message\":\"Connection failed\"}\n * {\"level\":\"info\",\"message\":\"Retrying...\"}\n * `\n * const logs = parseNdjson<LogEntry>(ndjsonString, logSchema)\n * console.log(logs.length) // 3\n *\n * // Parse with size limits per line\n * const entries = parseNdjson(ndjson, undefined, { maxSize: 1024 })\n *\n * // Empty lines are automatically skipped\n * const data = parseNdjson('{\"a\":1}\\n\\n{\"b\":2}\\n') // 2 objects\n * ```\n */\nexport function parseNdjson<T = unknown>(\n ndjson: string,\n schema?: Schema<T> | undefined,\n options?: JsonParseOptions | undefined,\n): T[] {\n const results: T[] = []\n const lines = ndjson.split(/\\r?\\n/)\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]?.trim()\n if (!line || line === '') {\n continue\n }\n\n try {\n const parsed = safeJsonParse<T>(line, schema, options)\n results.push(parsed)\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error)\n throw new Error(`Failed to parse NDJSON at line ${i + 1}: ${message}`)\n }\n }\n\n return results\n}\n\n/**\n * Stream-parse newline-delimited JSON (NDJSON) using a generator.\n * Yields one parsed object at a time, enabling memory-efficient processing of large NDJSON files.\n *\n * Unlike `parseNdjson` which loads all results into memory, this generator allows\n * processing each line individually, making it ideal for large datasets or streaming scenarios.\n *\n * @template T - The expected type of each parsed JSON object\n * @param ndjson - Newline-delimited JSON string (supports both `\\n` and `\\r\\n`)\n * @param schema - Optional Zod-compatible schema for validation of each line\n * @param options - Parsing options applied to each line\n * @yields Parsed objects one at a time as the generator iterates\n *\n * @throws {Error} When any line fails to parse (includes line number in error message)\n *\n * @example\n * ```ts\n * // Memory-efficient processing of large NDJSON files\n * const ndjsonString = readLargeFile('logs.ndjson')\n *\n * for (const log of streamNdjson<LogEntry>(ndjsonString, logSchema)) {\n * if (log.level === 'error') {\n * console.error('Error found:', log.message)\n * }\n * }\n *\n * // Collect filtered results without loading everything\n * const errors = [...streamNdjson(ndjson)]\n * .filter(log => log.level === 'error')\n *\n * // Early termination when condition is met\n * for (const entry of streamNdjson(ndjson)) {\n * if (entry.id === targetId) {\n * processEntry(entry)\n * break // Stop processing remaining lines\n * }\n * }\n * ```\n */\nexport function* streamNdjson<T = unknown>(\n ndjson: string,\n schema?: Schema<T> | undefined,\n options?: JsonParseOptions | undefined,\n): Generator<T, void, unknown> {\n const lines = ndjson.split(/\\r?\\n/)\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]?.trim()\n if (!line || line === '') {\n continue\n }\n\n try {\n yield safeJsonParse<T>(line, schema, options)\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error)\n throw new Error(`Failed to parse NDJSON at line ${i + 1}: ${message}`)\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/validation/types.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
/* Socket Lib - Built with esbuild */
|
|
2
|
-
var
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
3
17
|
//# sourceMappingURL=types.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/validation/types.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * @fileoverview Validation type definitions.\n * Provides core types for schema validation and JSON parsing with security features.\n */\n\n/**\n * Result of a schema validation operation.\n * Contains either successful parsed data or error information.\n *\n * @template T - The expected type of the parsed data\n *\n * @example\n * ```ts\n * const result: ParseResult<User> = schema.safeParse(data)\n * if (result.success) {\n * console.log(result.data) // User object\n * } else {\n * console.error(result.error) // Error details\n * }\n * ```\n */\nexport interface ParseResult<T> {\n /** Indicates whether parsing was successful */\n success: boolean\n /** Parsed and validated data (only present when `success` is `true`) */\n data?: T | undefined\n /** Error information (only present when `success` is `false`) */\n error?: any\n}\n\n/**\n * Base schema interface compatible with Zod and similar validation libraries.\n * Provides both safe and throwing parsing methods.\n *\n * @template T - The expected output type after validation\n *\n * @example\n * ```ts\n * import { z } from 'zod'\n *\n * const userSchema = z.object({\n * name: z.string(),\n * age: z.number()\n * })\n *\n * // Schema satisfies this interface\n * const schema: Schema<User> = userSchema\n * const result = schema.safeParse({ name: 'Alice', age: 30 })\n * ```\n */\nexport interface Schema<T = any> {\n /**\n * Safely parse data without throwing errors.\n * Returns a result object indicating success or failure.\n *\n * @param data - The data to validate\n * @returns Parse result with success flag and data or error\n */\n safeParse(data: any): ParseResult<T>\n\n /**\n * Parse data and throw an error if validation fails.\n * Use this when you want to fail fast on invalid data.\n *\n * @param data - The data to validate\n * @returns The validated and parsed data\n * @throws {Error} When validation fails\n */\n parse(data: any): T\n\n /**\n * Optional schema name for debugging and error messages.\n * Useful for identifying which schema failed in complex validation chains.\n */\n _name?: string | undefined\n}\n\n/**\n * Options for configuring JSON parsing behavior with security controls.\n *\n * @example\n * ```ts\n * const options: JsonParseOptions = {\n * maxSize: 1024 * 1024, // 1MB limit\n * allowPrototype: false // Block prototype pollution\n * }\n * ```\n */\nexport interface JsonParseOptions {\n /**\n * Allow dangerous prototype pollution keys (`__proto__`, `constructor`, `prototype`).\n * Set to `true` only if you trust the JSON source completely.\n *\n * @default false\n *\n * @example\n * ```ts\n * // Will throw error by default\n * safeJsonParse('{\"__proto__\": {\"polluted\": true}}')\n *\n * // Allows the parse (dangerous!)\n * safeJsonParse('{\"__proto__\": {\"polluted\": true}}', undefined, {\n * allowPrototype: true\n * })\n * ```\n */\n allowPrototype?: boolean | undefined\n\n /**\n * Maximum allowed size of JSON string in bytes.\n * Prevents memory exhaustion from extremely large payloads.\n *\n * @default 10_485_760 (10 MB)\n *\n * @example\n * ```ts\n * // Limit to 1KB\n * safeJsonParse(jsonString, undefined, { maxSize: 1024 })\n * ```\n */\n maxSize?: number | undefined\n}\n\n/**\n * Discriminated union type for JSON parsing results.\n * Enables type-safe handling of success and failure cases.\n *\n * @template T - The expected type of the parsed data\n *\n * @example\n * ```ts\n * const result: JsonParseResult<User> = parseJsonWithResult(jsonString)\n *\n * if (result.success) {\n * // TypeScript knows result.data is available\n * console.log(result.data.name)\n * } else {\n * // TypeScript knows result.error is available\n * console.error(result.error)\n * }\n * ```\n */\nexport type JsonParseResult<T> =\n | { success: true; data: T }\n | { success: false; error: string }\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|