@prisma-next/utils
Advanced tools
| import { t as blindCast } from "./casts-DpaahrlC.mjs"; | ||
| //#region src/defined.ts | ||
| /** | ||
| * Returns an object with the key/value if value is defined, otherwise an empty object. | ||
| * | ||
| * Use with spread to conditionally include optional properties while satisfying | ||
| * exactOptionalPropertyTypes. This is explicit about which properties are optional | ||
| * and won't inadvertently strip other undefined values. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // Instead of: | ||
| * const obj = { | ||
| * required: 'value', | ||
| * ...(optional ? { optional } : {}), | ||
| * }; | ||
| * | ||
| * // Use: | ||
| * const obj = { | ||
| * required: 'value', | ||
| * ...ifDefined('optional', optional), | ||
| * }; | ||
| * ``` | ||
| */ | ||
| function ifDefined(key, value) { | ||
| return value !== void 0 ? blindCast({ [key]: value }) : {}; | ||
| } | ||
| //#endregion | ||
| export { ifDefined as t }; | ||
| //# sourceMappingURL=defined-BQWA85QH.mjs.map |
| {"version":3,"file":"defined-BQWA85QH.mjs","names":[],"sources":["../src/defined.ts"],"sourcesContent":["import { blindCast } from './casts';\n\n/**\n * Returns an object with the key/value if value is defined, otherwise an empty object.\n *\n * Use with spread to conditionally include optional properties while satisfying\n * exactOptionalPropertyTypes. This is explicit about which properties are optional\n * and won't inadvertently strip other undefined values.\n *\n * @example\n * ```typescript\n * // Instead of:\n * const obj = {\n * required: 'value',\n * ...(optional ? { optional } : {}),\n * };\n *\n * // Use:\n * const obj = {\n * required: 'value',\n * ...ifDefined('optional', optional),\n * };\n * ```\n */\nexport function ifDefined<K extends string, V>(\n key: K,\n value: V | undefined,\n): Record<never, never> | { [P in K]: V } {\n return value !== undefined\n ? blindCast<{ [P in K]: V }, 'computed key K; value is defined'>({ [key]: value })\n : {};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,UACd,KACA,OACwC;CACxC,OAAO,UAAU,KAAA,IACb,UAA+D,GAAG,MAAM,MAAM,CAAC,IAC/E,CAAC;AACP"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"defined.d.mts","names":[],"sources":["../src/defined.ts"],"mappings":";;AAsBA;;;;;;;;;;;;;;;;;;;;;iBAAgB,SAAA,sBACd,GAAA,EAAK,CAAA,EACL,KAAA,EAAO,CAAA,eACN,MAAA,yBAA+B,CAAA,GAAI,CAAA"} | ||
| {"version":3,"file":"defined.d.mts","names":[],"sources":["../src/defined.ts"],"mappings":";;AAwBA;;;;;;;;;;;;;;;;;;;;;iBAAgB,SAAA,sBACd,GAAA,EAAK,CAAA,EACL,KAAA,EAAO,CAAA,eACN,MAAA,yBAA+B,CAAA,GAAI,CAAA"} |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { t as ifDefined } from "./defined-BB-H4E45.mjs"; | ||
| import { t as ifDefined } from "./defined-BQWA85QH.mjs"; | ||
| export { ifDefined }; |
@@ -1,2 +0,2 @@ | ||
| import { t as ifDefined } from "./defined-BB-H4E45.mjs"; | ||
| import { t as ifDefined } from "./defined-BQWA85QH.mjs"; | ||
| //#region src/redact-db-url.ts | ||
@@ -3,0 +3,0 @@ /** |
+3
-3
| { | ||
| "name": "@prisma-next/utils", | ||
| "version": "0.13.0-dev.31", | ||
| "version": "0.13.0-dev.32", | ||
| "license": "Apache-2.0", | ||
@@ -9,4 +9,4 @@ "type": "module", | ||
| "devDependencies": { | ||
| "@prisma-next/tsconfig": "0.13.0-dev.31", | ||
| "@prisma-next/tsdown": "0.13.0-dev.31", | ||
| "@prisma-next/tsconfig": "0.13.0-dev.32", | ||
| "@prisma-next/tsdown": "0.13.0-dev.32", | ||
| "tsdown": "0.22.1", | ||
@@ -13,0 +13,0 @@ "typescript": "5.9.3", |
+5
-1
@@ -0,1 +1,3 @@ | ||
| import { blindCast } from './casts'; | ||
| /** | ||
@@ -27,3 +29,5 @@ * Returns an object with the key/value if value is defined, otherwise an empty object. | ||
| ): Record<never, never> | { [P in K]: V } { | ||
| return value !== undefined ? ({ [key]: value } as { [P in K]: V }) : {}; | ||
| return value !== undefined | ||
| ? blindCast<{ [P in K]: V }, 'computed key K; value is defined'>({ [key]: value }) | ||
| : {}; | ||
| } |
| //#region src/defined.ts | ||
| /** | ||
| * Returns an object with the key/value if value is defined, otherwise an empty object. | ||
| * | ||
| * Use with spread to conditionally include optional properties while satisfying | ||
| * exactOptionalPropertyTypes. This is explicit about which properties are optional | ||
| * and won't inadvertently strip other undefined values. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // Instead of: | ||
| * const obj = { | ||
| * required: 'value', | ||
| * ...(optional ? { optional } : {}), | ||
| * }; | ||
| * | ||
| * // Use: | ||
| * const obj = { | ||
| * required: 'value', | ||
| * ...ifDefined('optional', optional), | ||
| * }; | ||
| * ``` | ||
| */ | ||
| function ifDefined(key, value) { | ||
| return value !== void 0 ? { [key]: value } : {}; | ||
| } | ||
| //#endregion | ||
| export { ifDefined as t }; | ||
| //# sourceMappingURL=defined-BB-H4E45.mjs.map |
| {"version":3,"file":"defined-BB-H4E45.mjs","names":[],"sources":["../src/defined.ts"],"sourcesContent":["/**\n * Returns an object with the key/value if value is defined, otherwise an empty object.\n *\n * Use with spread to conditionally include optional properties while satisfying\n * exactOptionalPropertyTypes. This is explicit about which properties are optional\n * and won't inadvertently strip other undefined values.\n *\n * @example\n * ```typescript\n * // Instead of:\n * const obj = {\n * required: 'value',\n * ...(optional ? { optional } : {}),\n * };\n *\n * // Use:\n * const obj = {\n * required: 'value',\n * ...ifDefined('optional', optional),\n * };\n * ```\n */\nexport function ifDefined<K extends string, V>(\n key: K,\n value: V | undefined,\n): Record<never, never> | { [P in K]: V } {\n return value !== undefined ? ({ [key]: value } as { [P in K]: V }) : {};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,UACd,KACA,OACwC;CACxC,OAAO,UAAU,KAAA,IAAa,GAAG,MAAM,MAAM,IAAwB,CAAC;AACxE"} |
105391
0.25%1136
0.35%