@prisma/dev
Version:
A local Prisma Postgres server for development and testing
2 lines (1 loc) • 5.9 kB
JavaScript
;var v=Object.create;var f=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var k=(e,t)=>{for(var n in t)f(e,n,{get:t[n],enumerable:!0})},w=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of x(t))!I.call(e,i)&&i!==n&&f(e,i,{get:()=>t[i],enumerable:!(s=T(t,i))||s.enumerable});return e};var N=(e,t,n)=>(n=e!=null?v(G(e)):{},w(t||!e||!e.__esModule?f(n,"default",{value:e,enumerable:!0}):n,e)),O=e=>w(f({},"__esModule",{value:!0}),e);var ee={};k(ee,{copyPrismaDevRuntimeAssets:()=>F,getPGliteRuntimeAssets:()=>j,getPrismaDevRuntimeAssetManifest:()=>S,registerBundledPGliteRuntimeAssetSources:()=>$,resolveBundledRuntimeAssetSource:()=>u});module.exports=O(ee);var W=()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"?document.currentScript.src:new URL("main.js",document.baseURI).href,l=W();var o=require("fs"),a=require("fs/promises"),U=require("module"),L=require("path"),r=require("url"),M=(0,U.createRequire)(l),C=["initdb.wasm","pglite.data","pglite.wasm"],b="pglite-seed.tar.gz",P={amcheck:"amcheck.tar.gz",bloom:"bloom.tar.gz",btree_gin:"btree_gin.tar.gz",btree_gist:"btree_gist.tar.gz",citext:"citext.tar.gz",cube:"cube.tar.gz",dict_int:"dict_int.tar.gz",dict_xsyn:"dict_xsyn.tar.gz",earthdistance:"earthdistance.tar.gz",file_fdw:"file_fdw.tar.gz",fuzzystrmatch:"fuzzystrmatch.tar.gz",hstore:"hstore.tar.gz",intarray:"intarray.tar.gz",isn:"isn.tar.gz",lo:"lo.tar.gz",ltree:"ltree.tar.gz",pageinspect:"pageinspect.tar.gz",pg_buffercache:"pg_buffercache.tar.gz",pg_freespacemap:"pg_freespacemap.tar.gz",pg_surgery:"pg_surgery.tar.gz",pg_trgm:"pg_trgm.tar.gz",pg_visibility:"pg_visibility.tar.gz",pg_walinspect:"pg_walinspect.tar.gz",seg:"seg.tar.gz",tablefunc:"tablefunc.tar.gz",tcn:"tcn.tar.gz",tsm_system_rows:"tsm_system_rows.tar.gz",tsm_system_time:"tsm_system_time.tar.gz",unaccent:"unaccent.tar.gz",uuid_ossp:"uuid-ossp.tar.gz",vector:"vector.tar.gz"},h=[...C.map(e=>({fileName:e,kind:"core",name:e})),{fileName:b,kind:"core",name:b},...Object.entries(P).map(([e,t])=>({fileName:t,kind:"extension",name:e}))],R=new Map,_=Symbol.for("@prisma/dev/bundled-pglite-runtime-asset-sources"),g=null;async function F(e){let t=m(e),n=(0,r.fileURLToPath)(t);await(0,a.mkdir)(n,{recursive:!0});let s=[];for(let i of S()){let p=new URL(i.fileName,t),d=(0,r.fileURLToPath)(p);await(0,a.copyFile)(i.sourcePath,d),s.push({...i,destinationPath:d})}return s}function S(){let e=D(),t=m(new URL("./runtime-assets/",l));return h.map(n=>({...n,sourcePath:(0,r.fileURLToPath)(c(n.fileName,e,t))}))}async function j(){await H();let e=B();if(e)return await K(e),await J(e);let t=X(),n=t.href,s=R.get(n);return s||(s=q(t),R.set(n,s)),await s}function $(e){let t=globalThis;t[_]={extensions:Object.fromEntries(Object.entries(e.extensions).map(([n,s])=>[n,u(s)])),fsBundle:u(e.fsBundle),initdbWasm:u(e.initdbWasm),loadDataDir:u(e.loadDataDir),wasmModule:u(e.wasmModule)}}function u(e,t=l){return e instanceof URL?e:/^(?:https?:|data:|file:)/.test(e)?new URL(e):e.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(e)?(0,r.pathToFileURL)(e):new URL(e,t)}async function J(e){let t=`bundled:${e.wasmModule.href}:${e.fsBundle.href}`,n=R.get(t);return n||(n=Y(e),R.set(t,n)),await n}async function q(e){let t=m(new URL("./runtime-assets/",l)),[n,s,i]=await Promise.all([(0,a.readFile)(c("pglite.data",e,t)),(0,a.readFile)(c(b,e,t)),(0,a.readFile)(c("pglite.wasm",e,t))]),p=z();return{extensions:Object.fromEntries(Object.entries(P).map(([d,E])=>[d,c(E,e,t)])),fsBundle:new Blob([Uint8Array.from(n)]),loadDataDir:new Blob([Uint8Array.from(s)]),wasmModule:await p.compile(i)}}async function Y(e){let[t,n,s]=await Promise.all([y(e.fsBundle),y(e.loadDataDir),y(e.wasmModule)]),i=z();return{extensions:e.extensions,fsBundle:new Blob([Uint8Array.from(t)]),loadDataDir:new Blob([Uint8Array.from(n)]),wasmModule:await i.compile(s)}}async function K(e){if(e.initdbWasm.protocol!=="file:")return;let t=new URL("initdb.wasm",m(new URL("./",e.initdbWasm))),n=(0,r.fileURLToPath)(t);(0,o.existsSync)(n)||await(0,a.copyFile)((0,r.fileURLToPath)(e.initdbWasm),n)}function m(e){return e instanceof URL?A(e):A((0,r.pathToFileURL)(e))}function A(e){return e.href.endsWith("/")?e:new URL(`${e.href}/`)}function D(){let e=M.resolve("@electric-sql/pglite");return m((0,L.dirname)(e))}function X(){let e=m(new URL("./",l));if(Z(e))return e;if(Q())return D();throw new Error("Unable to locate PGlite runtime assets. If you bundled @prisma/dev, copy them next to the bundle with copyPrismaDevRuntimeAssets().")}function Z(e){return h.every(t=>(0,o.existsSync)((0,r.fileURLToPath)(new URL(t.fileName,e))))}function B(){return globalThis[_]??null}async function H(){!V()||B()||(g||(g=import("./runtime-assets-manifest.bun.js").then(()=>{}).catch(e=>{throw g=null,e})),await g)}function Q(){let e=(0,r.fileURLToPath)(new URL("../package.json",l));if(!(0,o.existsSync)(e))return!1;try{return JSON.parse((0,o.readFileSync)(e,"utf8")).name==="@prisma/dev"}catch{return!1}}function V(){return typeof globalThis.Bun<"u"}function z(){let e=globalThis.WebAssembly;if(!e)throw new Error("WebAssembly is not available in this runtime.");return e}async function y(e){if(e.protocol==="file:")return await(0,a.readFile)(e);let t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch runtime asset ${e.href}: ${t.status} ${t.statusText}`);return new Uint8Array(await t.arrayBuffer())}function c(e,t,n){let s=new URL(e,t);if((0,o.existsSync)((0,r.fileURLToPath)(s)))return s;if(n){let i=new URL(e,n);if((0,o.existsSync)((0,r.fileURLToPath)(i)))return i}return s}0&&(module.exports={copyPrismaDevRuntimeAssets,getPGliteRuntimeAssets,getPrismaDevRuntimeAssetManifest,registerBundledPGliteRuntimeAssetSources,resolveBundledRuntimeAssetSource});