@orpc/shared
Advanced tools
Comparing version 0.0.5 to 0.1.0
// src/json.ts | ||
function parseJSONSafely(text) { | ||
if (text === "") return void 0; | ||
if (text === "") | ||
return void 0; | ||
try { | ||
return JSON.parse(text); | ||
} catch (e) { | ||
} catch { | ||
return text; | ||
@@ -56,5 +57,13 @@ } | ||
// src/value.ts | ||
async function resolvePromisableValue(value) { | ||
if (typeof value === "function") { | ||
return value(); | ||
} | ||
return Promise.resolve(value); | ||
} | ||
// src/index.ts | ||
import { isPlainObject as isPlainObject2 } from "is-what"; | ||
import { guard, trim, mapEntries, omit, mapValues } from "radash"; | ||
import { guard, mapEntries, mapValues, omit, trim } from "radash"; | ||
export { | ||
@@ -69,2 +78,3 @@ findDeepMatches, | ||
parseJSONSafely, | ||
resolvePromisableValue, | ||
set, | ||
@@ -71,0 +81,0 @@ trim |
@@ -1,6 +0,7 @@ | ||
export type * from 'type-fest'; | ||
export * from './json'; | ||
export * from './object'; | ||
export * from './value'; | ||
export { isPlainObject } from 'is-what'; | ||
export { guard, trim, mapEntries, omit, mapValues } from 'radash'; | ||
export { guard, mapEntries, mapValues, omit, trim } from 'radash'; | ||
export type * from 'type-fest'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@orpc/shared", | ||
"type": "module", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"author": { | ||
@@ -11,7 +11,7 @@ "name": "unnoq", | ||
"license": "MIT", | ||
"homepage": "https://github.com/unnoq/unnoq", | ||
"homepage": "https://github.com/unnoq/orpc", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/unnoq/unnoq.git", | ||
"directory": "examples/typescript-vite-package" | ||
"url": "https://github.com/unnoq/orpc.git", | ||
"directory": "packages/shared" | ||
}, | ||
@@ -18,0 +18,0 @@ "keywords": [ |
import { z } from 'zod' | ||
import { ORPCError } from './error' | ||
test('issues', () => { | ||
it('issues', () => { | ||
const zodError = z.object({ a: z.string() }).safeParse({ a: 1 }).error | ||
@@ -6,0 +6,0 @@ |
@@ -82,14 +82,14 @@ import { ZodError, type ZodIssue } from 'zod' | ||
if ( | ||
typeof json !== 'object' || | ||
json === null || | ||
!('code' in json) || | ||
!Object.keys(ORPC_ERROR_CODE_STATUSES).find((key) => json.code === key) || | ||
!('status' in json) || | ||
typeof json.status !== 'number' || | ||
('message' in json && | ||
json.message !== undefined && | ||
typeof json.message !== 'string') || | ||
('issues' in json && | ||
json.issues !== undefined && | ||
!Array.isArray(json.issues)) | ||
typeof json !== 'object' | ||
|| json === null | ||
|| !('code' in json) | ||
|| !Object.keys(ORPC_ERROR_CODE_STATUSES).find(key => json.code === key) | ||
|| !('status' in json) | ||
|| typeof json.status !== 'number' | ||
|| ('message' in json | ||
&& json.message !== undefined | ||
&& typeof json.message !== 'string') | ||
|| ('issues' in json | ||
&& json.issues !== undefined | ||
&& !Array.isArray(json.issues)) | ||
) { | ||
@@ -96,0 +96,0 @@ return undefined |
@@ -1,7 +0,8 @@ | ||
export type * from 'type-fest' | ||
export * from './json' | ||
export * from './json' | ||
export * from './object' | ||
export * from './value' | ||
export { isPlainObject } from 'is-what' | ||
export { isPlainObject } from 'is-what' | ||
export { guard, trim, mapEntries, omit, mapValues } from 'radash' | ||
export { guard, mapEntries, mapValues, omit, trim } from 'radash' | ||
export type * from 'type-fest' |
export function parseJSONSafely(text: string): unknown { | ||
if (text === '') return undefined | ||
if (text === '') | ||
return undefined | ||
try { | ||
return JSON.parse(text) | ||
} catch (e) { | ||
} | ||
catch { | ||
return text | ||
} | ||
} |
@@ -36,4 +36,4 @@ import { isPlainObject } from 'is-what' | ||
if ( | ||
(typeof currentRef !== 'object' && typeof currentRef !== 'function') || | ||
currentRef === null | ||
(typeof currentRef !== 'object' && typeof currentRef !== 'function') | ||
|| currentRef === null | ||
) { | ||
@@ -48,4 +48,4 @@ return undefined | ||
if ( | ||
(typeof currentRef !== 'object' && typeof currentRef !== 'function') || | ||
currentRef === null | ||
(typeof currentRef !== 'object' && typeof currentRef !== 'function') | ||
|| currentRef === null | ||
) { | ||
@@ -64,11 +64,13 @@ return undefined | ||
values: unknown[] = [], | ||
): { maps: Segment[][]; values: unknown[] } { | ||
): { maps: Segment[][], values: unknown[] } { | ||
if (check(payload)) { | ||
maps.push(segments) | ||
values.push(payload) | ||
} else if (Array.isArray(payload)) { | ||
} | ||
else if (Array.isArray(payload)) { | ||
payload.forEach((v, i) => { | ||
findDeepMatches(check, v, [...segments, i], maps, values) | ||
}) | ||
} else if (isPlainObject(payload)) { | ||
} | ||
else if (isPlainObject(payload)) { | ||
for (const key in payload) { | ||
@@ -75,0 +77,0 @@ findDeepMatches(check, payload[key], [...segments, key], maps, values) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
89827
24
568