(
callback: (txClient?: ClientContract<any>) => Promise<unknown>,
)
| 12 | * @see https://github.com/prisma/prisma/blob/main/packages/client/src/runtime/core/request/createPrismaPromise.ts |
| 13 | */ |
| 14 | export function createZenStackPromise( |
| 15 | callback: (txClient?: ClientContract<any>) => Promise<unknown>, |
| 16 | ): ZenStackPromise<unknown> { |
| 17 | let promise: Promise<unknown> | undefined; |
| 18 | const cb = (txClient?: ClientContract<any>) => { |
| 19 | try { |
| 20 | return (promise ??= valueToPromise(callback(txClient))); |
| 21 | } catch (err) { |
| 22 | // deal with synchronous errors |
| 23 | return Promise.reject<unknown>(err); |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | return { |
| 28 | then(onFulfilled, onRejected) { |
| 29 | return cb().then(onFulfilled, onRejected); |
| 30 | }, |
| 31 | catch(onRejected) { |
| 32 | return cb().catch(onRejected); |
| 33 | }, |
| 34 | finally(onFinally) { |
| 35 | return cb().finally(onFinally); |
| 36 | }, |
| 37 | cb, |
| 38 | [Symbol.toStringTag]: 'ZenStackPromise', |
| 39 | } as ZenStackPromise<unknown>; |
| 40 | } |
| 41 | |
| 42 | function valueToPromise(thing: any): Promise<any> { |
| 43 | if (typeof thing === 'object' && typeof thing?.then === 'function') { |
no outgoing calls
no test coverage detected