export let createEnsureRecord = < UniqueKey extends {}, UpsertCreate, Result, StaticCreate extends Partial = {} >( type: { upsert: (d: { create: UpsertCreate; where: UniqueKey; update: any }) => Promise; }, getWhere: (value: UpsertCreate) => UniqueKey, getStatic?: () => Promise | StaticCreate, opts?: { cacheTtl?: number; } ) => { return async ( getter: () => | Omit | Promise>, opts?: { ignoreForUpdate?: (keyof UpsertCreate)[]; } ) => { let coreValues = await getter(); let staticValues = (await getStatic?.()) ?? {}; let value = { ...staticValues, ...coreValues } as UpsertCreate; let where = getWhere(value); let update = { ...value, id: undefined, oid: undefined }; if (opts?.ignoreForUpdate) { for (let key of opts.ignoreForUpdate) { delete update[key]; } } let res = await type.upsert({ where, create: value, update }); return res; }; };