@prisma-next/utils 0.13.0-dev.9 → 0.14.0-dev.1

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.
@@ -1,3 +1,4 @@
1
+ import { t as blindCast } from "./casts-DpaahrlC.mjs";
1
2
  //#region src/defined.ts
2
3
  /**
3
4
  * Returns an object with the key/value if value is defined, otherwise an empty object.
@@ -22,9 +23,9 @@
22
23
  * ```
23
24
  */
24
25
  function ifDefined(key, value) {
25
- return value !== void 0 ? { [key]: value } : {};
26
+ return value !== void 0 ? blindCast({ [key]: value }) : {};
26
27
  }
27
28
  //#endregion
28
29
  export { ifDefined as t };
29
30
 
30
- //# sourceMappingURL=defined-BB-H4E45.mjs.map
31
+ //# sourceMappingURL=defined-BQWA85QH.mjs.map
@@ -0,0 +1 @@
1
+ {"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 @@
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"}
1
+ {"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"}
package/dist/defined.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as ifDefined } from "./defined-BB-H4E45.mjs";
1
+ import { t as ifDefined } from "./defined-BQWA85QH.mjs";
2
2
  export { ifDefined };
@@ -0,0 +1,10 @@
1
+ //#region src/promise.d.ts
2
+ /**
3
+ * Returns true when `value` has a `.then` method, narrowing its type to
4
+ * `PromiseLike<T>`. Safer than `instanceof Promise` because it works across
5
+ * realm boundaries and with any thenable (e.g. custom promise implementations).
6
+ */
7
+ declare function isThenable<T>(value: T | PromiseLike<T>): value is PromiseLike<T>;
8
+ //#endregion
9
+ export { isThenable };
10
+ //# sourceMappingURL=promise.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.d.mts","names":[],"sources":["../src/promise.ts"],"mappings":";;AAKA;;;;iBAAgB,UAAA,IAAc,KAAA,EAAO,CAAA,GAAI,WAAA,CAAY,CAAA,IAAK,KAAA,IAAS,WAAA,CAAY,CAAA"}
@@ -0,0 +1,13 @@
1
+ //#region src/promise.ts
2
+ /**
3
+ * Returns true when `value` has a `.then` method, narrowing its type to
4
+ * `PromiseLike<T>`. Safer than `instanceof Promise` because it works across
5
+ * realm boundaries and with any thenable (e.g. custom promise implementations).
6
+ */
7
+ function isThenable(value) {
8
+ return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
9
+ }
10
+ //#endregion
11
+ export { isThenable };
12
+
13
+ //# sourceMappingURL=promise.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.mjs","names":[],"sources":["../src/promise.ts"],"sourcesContent":["/**\n * Returns true when `value` has a `.then` method, narrowing its type to\n * `PromiseLike<T>`. Safer than `instanceof Promise` because it works across\n * realm boundaries and with any thenable (e.g. custom promise implementations).\n */\nexport function isThenable<T>(value: T | PromiseLike<T>): value is PromiseLike<T> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'then' in value &&\n typeof value.then === 'function'\n );\n}\n"],"mappings":";;;;;;AAKA,SAAgB,WAAc,OAAoD;CAChF,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,OAAO,MAAM,SAAS;AAE1B"}
@@ -1,4 +1,4 @@
1
- import { t as ifDefined } from "./defined-BB-H4E45.mjs";
1
+ import { t as ifDefined } from "./defined-BQWA85QH.mjs";
2
2
  //#region src/redact-db-url.ts
3
3
  /**
4
4
  * Redacts a database connection URL to a minimal metadata object.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@prisma-next/utils",
3
- "version": "0.13.0-dev.9",
3
+ "version": "0.14.0-dev.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "Shared utility functions for Prisma Next",
8
8
  "devDependencies": {
9
- "@prisma-next/tsconfig": "0.13.0-dev.9",
10
- "@prisma-next/tsdown": "0.13.0-dev.9",
9
+ "@prisma-next/tsconfig": "0.14.0-dev.1",
10
+ "@prisma-next/tsdown": "0.14.0-dev.1",
11
11
  "tsdown": "0.22.1",
12
12
  "typescript": "5.9.3",
13
13
  "vitest": "4.1.8"
@@ -33,6 +33,7 @@
33
33
  "./defined": "./dist/defined.mjs",
34
34
  "./hash-content": "./dist/hash-content.mjs",
35
35
  "./json": "./dist/json.mjs",
36
+ "./promise": "./dist/promise.mjs",
36
37
  "./redact-db-url": "./dist/redact-db-url.mjs",
37
38
  "./result": "./dist/result.mjs",
38
39
  "./simplify-deep": "./dist/simplify-deep.mjs",
package/src/defined.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { blindCast } from './casts';
2
+
1
3
  /**
2
4
  * Returns an object with the key/value if value is defined, otherwise an empty object.
3
5
  *
@@ -24,5 +26,7 @@ export function ifDefined<K extends string, V>(
24
26
  key: K,
25
27
  value: V | undefined,
26
28
  ): Record<never, never> | { [P in K]: V } {
27
- return value !== undefined ? ({ [key]: value } as { [P in K]: V }) : {};
29
+ return value !== undefined
30
+ ? blindCast<{ [P in K]: V }, 'computed key K; value is defined'>({ [key]: value })
31
+ : {};
28
32
  }
@@ -0,0 +1 @@
1
+ export { isThenable } from '../promise';
package/src/promise.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns true when `value` has a `.then` method, narrowing its type to
3
+ * `PromiseLike<T>`. Safer than `instanceof Promise` because it works across
4
+ * realm boundaries and with any thenable (e.g. custom promise implementations).
5
+ */
6
+ export function isThenable<T>(value: T | PromiseLike<T>): value is PromiseLike<T> {
7
+ return (
8
+ typeof value === 'object' &&
9
+ value !== null &&
10
+ 'then' in value &&
11
+ typeof value.then === 'function'
12
+ );
13
+ }
@@ -1 +0,0 @@
1
- {"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"}