modelence 0.6.18 → 0.6.19
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.
- package/dist/bin/modelence.js +1 -1
- package/dist/{chunk-OEVRIT3I.js → chunk-ARRGI5M7.js} +3 -3
- package/dist/{chunk-OEVRIT3I.js.map → chunk-ARRGI5M7.js.map} +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{package-DSL4EF4B.js → package-V6P5ZO4M.js} +2 -2
- package/dist/{package-DSL4EF4B.js.map → package-V6P5ZO4M.js.map} +1 -1
- package/dist/server.d.ts +6 -489
- package/dist/server.js +1 -1
- package/dist/types-D6nwUab6.d.ts +543 -0
- package/dist/{types-CmI2APz9.d.ts → types-Ds1ESQSs.d.ts} +3 -1
- package/dist/types.d.ts +5 -27
- package/package.json +1 -1
package/dist/bin/modelence.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {s}from'../chunk-
|
|
2
|
+
import {s}from'../chunk-ARRGI5M7.js';import {Command}from'commander';import {readFileSync,promises,createWriteStream,writeFileSync}from'fs';import {fileURLToPath}from'url';import X,{dirname,join}from'path';import {parse}from'dotenv';import {createInterface}from'readline';import j from'fs/promises';import {createJiti}from'jiti';import {z}from'zod';import {build}from'tsup';import {loadConfigFromFile,build as build$1,mergeConfig}from'vite';import {execSync}from'child_process';import se from'archiver';import ee from'open';var C=".modelence.env";async function I(e,o){let t=await fetch(`${o}/api/setup`,{method:"GET",headers:{"X-Modelence-Setup-Token":e}});if(!t.ok){let r=await t.text();throw new Error(r||`Request failed with status ${t.status}`)}return t.json()}async function L(){let e=createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{e.question(`Warning: ${C} already exists. Do you want to overwrite it? (y/N) `,t=>{e.close(),o(t.toLowerCase()==="y");});})}function R(e){return String(e).replace(/"/g,'\\"')}async function U(e){try{let o=e.replace(".env",".backup.env");await promises.copyFile(e,o),console.log(`Backup created at ${o}`);}catch(o){console.warn("Failed to create backup file:",o);}}async function x(e){try{let o=join(process.cwd(),C),t={};try{let a=await promises.readFile(o,"utf8");t=parse(a),await U(o),await L()||(console.log("Setup canceled"),process.exit(0));}catch{}console.log("Fetching service configuration...");let r=await I(e.token,e.host),s={...t,MODELENCE_CRON_ENABLED:"true",MODELENCE_TELEMETRY_ENABLED:"false",MODELENCE_ENVIRONMENT_ID:r.environmentId,MODELENCE_SERVICE_ENDPOINT:e.host,MODELENCE_SERVICE_TOKEN:r.serviceToken,MODELENCE_CONTAINER_ID:r.containerId},i=Object.entries(s).map(([a,n])=>`${a}="${R(n)}"`).join(`
|
|
3
3
|
`);await promises.writeFile(o,i.trim()+`
|
|
4
4
|
`),console.log(`Successfully configured ${C} file`);}catch(o){console.error(`Setup failed: ${o instanceof Error?o.message:"Unknown error"}`),process.exit(1);}}var g=null,b=null;function J(){if(!g)throw new Error("Environment variables not loaded");return g}function S(){if(!b)throw new Error("Configuration not loaded");return b}function D(e){return `${J().MODELENCE_SERVICE_ENDPOINT||"https://cloud.modelence.com"}${e}`}function w(){let{serverDir:e,serverEntry:o}=S();return join(e,o).replace(/\\/g,"/")}function O(){return S().postBuildCommand}function T(e){let o=N("build");return o.replace(/\\/g,"/")}function p(e){return join(process.cwd(),e).replace(/\\/g,"/")}function N(e){let o=p(".modelence");return e?join(o,e).replace(/\\/g,"/"):o.replace(/\\/g,"/")}async function h(){try{let e=join(process.cwd(),"modelence.config.ts"),t=await createJiti(import.meta.url,{interopDefault:!0,requireCache:!1}).import(e);if(typeof t!="object")throw new Error("modelence.config.ts should export an object");b=z.object({serverDir:z.string(),serverEntry:z.string(),postBuildCommand:z.string().optional()}).parse(t);}catch(e){throw console.error(e),new Error("Unable to load modelence.config.ts")}try{let e=await j.readFile(join(process.cwd(),".modelence.env"),"utf-8");g=parse(e);}catch(e){if(e.code==="ENOENT")g={};else throw e}}async function H(){let e=O();if(e){console.log("Running post-build command..."),execSync(e);return}await Q();}async function Q(){console.log("Building client with Vite...");let e=await loadConfigFromFile({command:"build",mode:process.env.NODE_ENV||"production"}),o={build:{outDir:X.resolve(process.cwd(),".modelence/build/client").replace(/\\/g,"/"),emptyOutDir:true}};await build$1(mergeConfig(e?.config||{},o,true));}async function Z(){return console.log("Building server with tsup..."),new Promise(e=>{build({entry:[w()],format:"esm",sourcemap:true,minify:process.env.NODE_ENV==="production",outDir:".modelence/build",clean:true,watch:false,bundle:true,treeshake:true,platform:"node",external:[...Object.keys(s.dependencies??{}),...Object.keys(s.peerDependencies??{})],outExtension:()=>({js:".mjs"}),onSuccess:async()=>{e(void 0);}});})}async function E(){console.log("Building Modelence project...");try{let e=T();await j.rm(e,{recursive:!0,force:!0}),await Z(),await H(),console.log("Build completed successfully!");}catch(e){throw console.error(e),new Error("Build failed")}try{await j.access(N());}catch{throw new Error("Could not find the .modelence directory. Looks like something went wrong during the build.")}}async function P(e){let o=await fetch(`${e}/api/cli/auth`,{method:"POST"});if(!o.ok)throw new Error("Failed to create CLI authentication code");let{code:t,verificationUrl:r}=await o.json();console.log(`Please visit ${r} to authenticate`),console.log(`Code: ${t}`),await ee(r);let s=await ne(e,t);return writeFileSync(join(process.cwd(),".modelence","auth.json"),JSON.stringify({token:s})),{token:s}}async function ne(e,o){let s=Date.now()+6e5;for(;Date.now()<s;){try{let i=await re(e,o);if(i)return i}catch(i){console.error("Error polling for CLI token:",i);}await new Promise(i=>setTimeout(i,5e3));}throw new Error("Unable to authenticate CLI - timed out. Please try again.")}async function re(e,o){let t=await fetch(`${e}/api/cli/token?code=${o}`,{method:"GET"});if(!t.ok)throw new Error(`CLI token polling failed: ${t.statusText}`);let{token:r}=await t.json();return r}async function $(e){let o=process.cwd(),t=join(o,".modelence"),r=join(t,"tmp","bundle.zip"),s=e.host||D("");await E(),await ae(r);let{token:i}=await P(s),{bundleName:a}=await ce(e.app,e.env,r,i,s);await promises.unlink(r),await le(e.app,e.env,a,join(".modelence","build","app.mjs"),i,s);}async function ae(e){try{await promises.unlink(e),console.log("Removed existing bundle");}catch(n){if(n.code!=="ENOENT")throw n}console.log("Creating deployment bundle..."),await promises.mkdir(join(e,".."),{recursive:true});let o=createWriteStream(e),t=se("zip",{zlib:{level:9}});t.on("warning",n=>{if(n.code==="ENOENT")console.warn("Warning:",n);else throw n}),t.on("error",n=>{throw n});let r=new Promise((n,m)=>{o.on("close",n),o.on("error",m),t.on("error",m);});t.pipe(o);let s=["package.json","next.config.js","next.config.ts","modelence.config.ts"],i=["public","server",join(".modelence","build"),".next"];for(let n of s)await promises.access(p(n)).then(()=>true).catch(()=>false)&&t.file(p(n),{name:n});for(let n of i)await promises.access(p(n)).then(()=>true).catch(()=>false)&&t.directory(p(n),n);await t.finalize(),await r;let a=await promises.stat(e);console.log(`Deployment bundle created at: ${e} (${(a.size/1024/1024).toFixed(2)} MB)`);}async function ce(e,o,t,r,s){let i=await fetch(`${s}/api/upload-bundle`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({appAlias:e,envAlias:o})});if(!i.ok)throw console.error(await i.text()),new Error(`Failed to create upload URL: ${i.statusText}`);let{uploadUrl:a,bundleName:n}=await i.json(),m=await promises.readFile(t),k=await fetch(a,{method:"PUT",body:new Uint8Array(m),headers:{"Content-Type":"application/zip"}});if(!k.ok)throw new Error(`Failed to upload bundle: ${k.statusText}`);return console.log("Successfully uploaded bundle to Modelence Cloud"),console.log(`Bundle name: ${n}`),{bundleName:n}}async function le(e,o,t,r,s,i){let a=await fetch(`${i}/api/deploy`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify({appAlias:e,envAlias:o,bundleName:t,entryPoint:r})});if(!a.ok)throw new Error(`Failed to trigger deployment: ${a.statusText}`);let{deploymentUrl:n}=await a.json();console.log("Successfully triggered deployment"),console.log(`Follow your deployment progress at: ${n}`);}function B(){console.log("Starting Modelence dev server...");let e=w(),o=X.resolve("./node_modules/.bin/tsx");execSync(`"${o}" watch "${e}"`,{stdio:"inherit",cwd:process.cwd(),env:{...process.env,NODE_ENV:"development"}});}var he=fileURLToPath(import.meta.url),Ee=dirname(he),ve=JSON.parse(readFileSync(join(Ee,"../../package.json"),"utf-8")),u=new Command().name("modelence").description("Modelence CLI tool").version(ve.version);u.command("setup").description("Setup Modelence environment variables").requiredOption("-t, --token <token>","Modelence setup token").option("-h, --host <host>","Modelence host","https://cloud.modelence.com").action(async e=>{await x(e);});u.command("build").description("Build the application").action(async()=>{await h(),await E();});u.command("deploy").description("Deploy to Modelence Cloud").requiredOption("-a, --app <app>","Application alias").requiredOption("-e, --env <env>","Environment alias").option("-h, --host <host>","Modelence host").action(async e=>{await h(),await $(e);});u.command("dev").description("Start development server").action(async()=>{await h(),B();});u.parse(process.argv);//# sourceMappingURL=modelence.js.map
|
|
5
5
|
//# sourceMappingURL=modelence.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var s="module",i="modelence",r="0.6.
|
|
2
|
-
export{s as a,i as b,r as c,o as d,n as e,p as f,c as g,d as h,l as i,a as j,m as k,y as l,u as m,g as n,h as o,x as p,j as q,b as r,v as s};//# sourceMappingURL=chunk-
|
|
3
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
var s="module",i="modelence",r="0.6.19",o="The Node.js Framework for Real-Time MongoDB Apps",n="dist/index.js",p="dist/global.d.ts",c={".":"./dist/index.js","./client":"./dist/client.js","./server":"./dist/server.js","./telemetry":"./dist/telemetry.js","./mongodb":"./dist/mongo.js","./types":{types:"./dist/types.d.ts",default:"./dist/types.js"}},d=["dist","dist/bin"],l={modelence:"./dist/bin/modelence.js"},a={build:"tsup",dev:"tsup --watch",format:'prettier --write "src/**/*.{ts,tsx,js,jsx,json,css,md}"',"format:check":'prettier --check "src/**/*.{ts,tsx,js,jsx,json,css,md}"',lint:"eslint src --ext .ts,.tsx --fix","lint:check":"eslint src --ext .ts,.tsx",prepublishOnly:"npm run build",test:'echo "Error: no test specified" && exit 1',postversion:"git push && git push --tags"},m={type:"git",url:"git+https://github.com/modelence/modelence.git"},y="Modelence",u="SEE LICENSE IN LICENSE",g={url:"https://github.com/modelence/modelence/issues"},h="https://modelence.com",x={"@types/archiver":"^6.0.3","@types/bcrypt":"^5.0.2","@types/cookie-parser":"^1.4.9","@types/express":"^5.0.0","@types/fs-extra":"^11.0.4","@types/node":"^22.5.1","@types/react":"^19.0.0","@types/react-dom":"^19.0.1","@types/socket.io":"^3.0.1","@typescript-eslint/eslint-plugin":"^8.17.0","@typescript-eslint/parser":"^8.17.0",eslint:"^9.37.0",prettier:"^3.6.2",react:"^19.0.0","react-dom":"^19.0.0"},j={"@socket.io/mongo-adapter":"^0.4.0","@vitejs/plugin-react":"^4.3.4",archiver:"^7.0.1",bcrypt:"^5.1.1",commander:"^12.0.0","cookie-parser":"^1.4.7",dotenv:"^16.4.5","elastic-apm-node":"^4.8.0",express:"^4.21.0","fs-extra":"^11.2.0",jiti:"^2.4.2",mongodb:"^6.8.1",open:"^10.1.0","socket.io":"^4.8.1","socket.io-client":"^4.8.1",tsup:"^8.3.6",tsx:"^4.19.3",typescript:"^5.7.2",vite:"^6.0.3","vite-plugin-eslint":"^1.8.1",winston:"^3.15.0","winston-elasticsearch":"^0.19.0",zod:"^3.23.8",zustand:"^5.0.2"},b={react:">=18.0.0","react-dom":">=18.0.0"},v={type:s,name:i,version:r,description:o,main:n,types:p,exports:c,files:d,bin:l,scripts:a,repository:m,author:y,license:u,bugs:g,homepage:h,devDependencies:x,dependencies:j,peerDependencies:b};
|
|
2
|
+
export{s as a,i as b,r as c,o as d,n as e,p as f,c as g,d as h,l as i,a as j,m as k,y as l,u as m,g as n,h as o,x as p,j as q,b as r,v as s};//# sourceMappingURL=chunk-ARRGI5M7.js.map
|
|
3
|
+
//# sourceMappingURL=chunk-ARRGI5M7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json"],"names":["type","name","version","description","main","types","exports","files","bin","scripts","repository","author","license","bugs","homepage","devDependencies","dependencies","peerDependencies","package_default"],"mappings":"AACE,IAAAA,CAAAA,CAAQ,SACRC,CAAAA,CAAQ,WAAA,CACRC,EAAW,QAAA,CACXC,CAAAA,CAAe,kDAAA,CACfC,CAAAA,CAAQ,eAAA,CACRC,CAAAA,CAAS,mBACTC,CAAAA,CAAW,CACT,IAAK,iBAAA,CACL,UAAA,CAAY,mBACZ,UAAA,CAAY,kBAAA,CACZ,aAAA,CAAe,qBAAA,CACf,WAAA,CAAa,iBAAA,CACb,UAAW,CACT,KAAA,CAAS,oBACT,OAAA,CAAW,iBACb,CACF,CAAA,CACAC,CAAAA,CAAS,CACP,MAAA,CACA,UACF,CAAA,CACAC,EAAO,CACL,SAAA,CAAa,yBACf,CAAA,CACAC,CAAAA,CAAW,CACT,MAAS,MAAA,CACT,GAAA,CAAO,cAAA,CACP,MAAA,CAAU,yDAAA,CACV,cAAA,CAAgB,0DAChB,IAAA,CAAQ,iCAAA,CACR,aAAc,2BAAA,CACd,cAAA,CAAkB,gBAClB,IAAA,CAAQ,2CAAA,CACR,WAAA,CAAe,6BACjB,CAAA,CACAC,CAAAA,CAAc,CACZ,IAAA,CAAQ,KAAA,CACR,IAAO,gDACT,CAAA,CACAC,EAAU,WAAA,CACVC,CAAAA,CAAW,wBAAA,CACXC,CAAAA,CAAQ,CACN,GAAA,CAAO,+CACT,CAAA,CACAC,CAAAA,CAAY,wBACZC,CAAAA,CAAmB,CACjB,kBAAmB,QAAA,CACnB,eAAA,CAAiB,QAAA,CACjB,sBAAA,CAAwB,QAAA,CACxB,gBAAA,CAAkB,SAClB,iBAAA,CAAmB,SAAA,CACnB,aAAA,CAAe,SAAA,CACf,cAAA,CAAgB,SAAA,CAChB,mBAAoB,SAAA,CACpB,kBAAA,CAAoB,QAAA,CACpB,kCAAA,CAAoC,SAAA,CACpC,2BAAA,CAA6B,UAC7B,MAAA,CAAU,SAAA,CACV,SAAY,QAAA,CACZ,KAAA,CAAS,UACT,WAAA,CAAa,SACf,CAAA,CACAC,CAAAA,CAAgB,CACd,0BAAA,CAA4B,SAC5B,sBAAA,CAAwB,QAAA,CACxB,SAAY,QAAA,CACZ,MAAA,CAAU,SACV,SAAA,CAAa,SAAA,CACb,eAAA,CAAiB,QAAA,CACjB,MAAA,CAAU,SAAA,CACV,mBAAoB,QAAA,CACpB,OAAA,CAAW,UACX,UAAA,CAAY,SAAA,CACZ,KAAQ,QAAA,CACR,OAAA,CAAW,QAAA,CACX,IAAA,CAAQ,SAAA,CACR,WAAA,CAAa,SACb,kBAAA,CAAoB,QAAA,CACpB,IAAA,CAAQ,QAAA,CACR,GAAA,CAAO,SAAA,CACP,WAAc,QAAA,CACd,IAAA,CAAQ,QAAA,CACR,oBAAA,CAAsB,QAAA,CACtB,OAAA,CAAW,UACX,uBAAA,CAAyB,SAAA,CACzB,IAAO,SAAA,CACP,OAAA,CAAW,QACb,CAAA,CACAC,CAAAA,CAAoB,CAClB,KAAA,CAAS,UAAA,CACT,WAAA,CAAa,UACf,CAAA,CA5FFC,CAAAA,CAAA,CACE,IAAA,CAAAlB,CAAAA,CACA,IAAA,CAAAC,EACA,OAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CACA,MAAAC,CAAAA,CACA,OAAA,CAAAC,EAWA,KAAA,CAAAC,CAAAA,CAIA,IAAAC,CAAAA,CAGA,OAAA,CAAAC,CAAAA,CAWA,UAAA,CAAAC,CAAAA,CAIA,MAAA,CAAAC,EACA,OAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CAGA,QAAA,CAAAC,CAAAA,CACA,gBAAAC,CAAAA,CAiBA,YAAA,CAAAC,CAAAA,CA0BA,gBAAA,CAAAC,CAIF","file":"chunk-
|
|
1
|
+
{"version":3,"sources":["../package.json"],"names":["type","name","version","description","main","types","exports","files","bin","scripts","repository","author","license","bugs","homepage","devDependencies","dependencies","peerDependencies","package_default"],"mappings":"AACE,IAAAA,CAAAA,CAAQ,SACRC,CAAAA,CAAQ,WAAA,CACRC,EAAW,QAAA,CACXC,CAAAA,CAAe,kDAAA,CACfC,CAAAA,CAAQ,eAAA,CACRC,CAAAA,CAAS,mBACTC,CAAAA,CAAW,CACT,IAAK,iBAAA,CACL,UAAA,CAAY,mBACZ,UAAA,CAAY,kBAAA,CACZ,aAAA,CAAe,qBAAA,CACf,WAAA,CAAa,iBAAA,CACb,UAAW,CACT,KAAA,CAAS,oBACT,OAAA,CAAW,iBACb,CACF,CAAA,CACAC,CAAAA,CAAS,CACP,MAAA,CACA,UACF,CAAA,CACAC,EAAO,CACL,SAAA,CAAa,yBACf,CAAA,CACAC,CAAAA,CAAW,CACT,MAAS,MAAA,CACT,GAAA,CAAO,cAAA,CACP,MAAA,CAAU,yDAAA,CACV,cAAA,CAAgB,0DAChB,IAAA,CAAQ,iCAAA,CACR,aAAc,2BAAA,CACd,cAAA,CAAkB,gBAClB,IAAA,CAAQ,2CAAA,CACR,WAAA,CAAe,6BACjB,CAAA,CACAC,CAAAA,CAAc,CACZ,IAAA,CAAQ,KAAA,CACR,IAAO,gDACT,CAAA,CACAC,EAAU,WAAA,CACVC,CAAAA,CAAW,wBAAA,CACXC,CAAAA,CAAQ,CACN,GAAA,CAAO,+CACT,CAAA,CACAC,CAAAA,CAAY,wBACZC,CAAAA,CAAmB,CACjB,kBAAmB,QAAA,CACnB,eAAA,CAAiB,QAAA,CACjB,sBAAA,CAAwB,QAAA,CACxB,gBAAA,CAAkB,SAClB,iBAAA,CAAmB,SAAA,CACnB,aAAA,CAAe,SAAA,CACf,cAAA,CAAgB,SAAA,CAChB,mBAAoB,SAAA,CACpB,kBAAA,CAAoB,QAAA,CACpB,kCAAA,CAAoC,SAAA,CACpC,2BAAA,CAA6B,UAC7B,MAAA,CAAU,SAAA,CACV,SAAY,QAAA,CACZ,KAAA,CAAS,UACT,WAAA,CAAa,SACf,CAAA,CACAC,CAAAA,CAAgB,CACd,0BAAA,CAA4B,SAC5B,sBAAA,CAAwB,QAAA,CACxB,SAAY,QAAA,CACZ,MAAA,CAAU,SACV,SAAA,CAAa,SAAA,CACb,eAAA,CAAiB,QAAA,CACjB,MAAA,CAAU,SAAA,CACV,mBAAoB,QAAA,CACpB,OAAA,CAAW,UACX,UAAA,CAAY,SAAA,CACZ,KAAQ,QAAA,CACR,OAAA,CAAW,QAAA,CACX,IAAA,CAAQ,SAAA,CACR,WAAA,CAAa,SACb,kBAAA,CAAoB,QAAA,CACpB,IAAA,CAAQ,QAAA,CACR,GAAA,CAAO,SAAA,CACP,WAAc,QAAA,CACd,IAAA,CAAQ,QAAA,CACR,oBAAA,CAAsB,QAAA,CACtB,OAAA,CAAW,UACX,uBAAA,CAAyB,SAAA,CACzB,IAAO,SAAA,CACP,OAAA,CAAW,QACb,CAAA,CACAC,CAAAA,CAAoB,CAClB,KAAA,CAAS,UAAA,CACT,WAAA,CAAa,UACf,CAAA,CA5FFC,CAAAA,CAAA,CACE,IAAA,CAAAlB,CAAAA,CACA,IAAA,CAAAC,EACA,OAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CACA,MAAAC,CAAAA,CACA,OAAA,CAAAC,EAWA,KAAA,CAAAC,CAAAA,CAIA,IAAAC,CAAAA,CAGA,OAAA,CAAAC,CAAAA,CAWA,UAAA,CAAAC,CAAAA,CAIA,MAAA,CAAAC,EACA,OAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CAGA,QAAA,CAAAC,CAAAA,CACA,gBAAAC,CAAAA,CAiBA,YAAA,CAAAC,CAAAA,CA0BA,gBAAA,CAAAC,CAIF","file":"chunk-ARRGI5M7.js","sourcesContent":["{\n \"type\": \"module\",\n \"name\": \"modelence\",\n \"version\": \"0.6.19\",\n \"description\": \"The Node.js Framework for Real-Time MongoDB Apps\",\n \"main\": \"dist/index.js\",\n \"types\": \"dist/global.d.ts\",\n \"exports\": {\n \".\": \"./dist/index.js\",\n \"./client\": \"./dist/client.js\",\n \"./server\": \"./dist/server.js\",\n \"./telemetry\": \"./dist/telemetry.js\",\n \"./mongodb\": \"./dist/mongo.js\",\n \"./types\": {\n \"types\": \"./dist/types.d.ts\",\n \"default\": \"./dist/types.js\"\n }\n },\n \"files\": [\n \"dist\",\n \"dist/bin\"\n ],\n \"bin\": {\n \"modelence\": \"./dist/bin/modelence.js\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"format\": \"prettier --write \\\"src/**/*.{ts,tsx,js,jsx,json,css,md}\\\"\",\n \"format:check\": \"prettier --check \\\"src/**/*.{ts,tsx,js,jsx,json,css,md}\\\"\",\n \"lint\": \"eslint src --ext .ts,.tsx --fix\",\n \"lint:check\": \"eslint src --ext .ts,.tsx\",\n \"prepublishOnly\": \"npm run build\",\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\",\n \"postversion\": \"git push && git push --tags\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/modelence/modelence.git\"\n },\n \"author\": \"Modelence\",\n \"license\": \"SEE LICENSE IN LICENSE\",\n \"bugs\": {\n \"url\": \"https://github.com/modelence/modelence/issues\"\n },\n \"homepage\": \"https://modelence.com\",\n \"devDependencies\": {\n \"@types/archiver\": \"^6.0.3\",\n \"@types/bcrypt\": \"^5.0.2\",\n \"@types/cookie-parser\": \"^1.4.9\",\n \"@types/express\": \"^5.0.0\",\n \"@types/fs-extra\": \"^11.0.4\",\n \"@types/node\": \"^22.5.1\",\n \"@types/react\": \"^19.0.0\",\n \"@types/react-dom\": \"^19.0.1\",\n \"@types/socket.io\": \"^3.0.1\",\n \"@typescript-eslint/eslint-plugin\": \"^8.17.0\",\n \"@typescript-eslint/parser\": \"^8.17.0\",\n \"eslint\": \"^9.37.0\",\n \"prettier\": \"^3.6.2\",\n \"react\": \"^19.0.0\",\n \"react-dom\": \"^19.0.0\"\n },\n \"dependencies\": {\n \"@socket.io/mongo-adapter\": \"^0.4.0\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"archiver\": \"^7.0.1\",\n \"bcrypt\": \"^5.1.1\",\n \"commander\": \"^12.0.0\",\n \"cookie-parser\": \"^1.4.7\",\n \"dotenv\": \"^16.4.5\",\n \"elastic-apm-node\": \"^4.8.0\",\n \"express\": \"^4.21.0\",\n \"fs-extra\": \"^11.2.0\",\n \"jiti\": \"^2.4.2\",\n \"mongodb\": \"^6.8.1\",\n \"open\": \"^10.1.0\",\n \"socket.io\": \"^4.8.1\",\n \"socket.io-client\": \"^4.8.1\",\n \"tsup\": \"^8.3.6\",\n \"tsx\": \"^4.19.3\",\n \"typescript\": \"^5.7.2\",\n \"vite\": \"^6.0.3\",\n \"vite-plugin-eslint\": \"^1.8.1\",\n \"winston\": \"^3.15.0\",\n \"winston-elasticsearch\": \"^0.19.0\",\n \"zod\": \"^3.23.8\",\n \"zustand\": \"^5.0.2\"\n },\n \"peerDependencies\": {\n \"react\": \">=18.0.0\",\n \"react-dom\": \">=18.0.0\"\n }\n}\n"]}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as ConfigKey, a as WebsocketClientProvider, c as ClientChannel } from './types-
|
|
1
|
+
import { b as ConfigKey, a as WebsocketClientProvider, c as ClientChannel } from './types-Ds1ESQSs.js';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import 'http';
|
|
4
4
|
import 'mongodb';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as ConfigSchema, a as WebsocketClientProvider, W as WebsocketServerProvider } from './types-
|
|
1
|
+
export { C as ConfigSchema, a as WebsocketClientProvider, W as WebsocketServerProvider } from './types-Ds1ESQSs.js';
|
|
2
2
|
export { M as ModelenceConfig } from './index-CwdohC5n.js';
|
|
3
3
|
import 'http';
|
|
4
4
|
import 'mongodb';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{l as author,i as bin,n as bugs,s as default,q as dependencies,d as description,p as devDependencies,g as exports,h as files,o as homepage,m as license,e as main,b as name,r as peerDependencies,k as repository,j as scripts,a as type,f as types,c as version}from'./chunk-
|
|
2
|
-
//# sourceMappingURL=package-
|
|
1
|
+
export{l as author,i as bin,n as bugs,s as default,q as dependencies,d as description,p as devDependencies,g as exports,h as files,o as homepage,m as license,e as main,b as name,r as peerDependencies,k as repository,j as scripts,a as type,f as types,c as version}from'./chunk-ARRGI5M7.js';//# sourceMappingURL=package-V6P5ZO4M.js.map
|
|
2
|
+
//# sourceMappingURL=package-V6P5ZO4M.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"package-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"package-V6P5ZO4M.js"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,496 +1,13 @@
|
|
|
1
1
|
import { A as AppServer } from './index-CwdohC5n.js';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import { C as ConfigSchema, S as ServerChannel, U as User, d as Session, W as WebsocketServerProvider, R as RoleDefinition, b as ConfigKey, A as AppConfig, e as UserInfo, f as Role } from './types-Ds1ESQSs.js';
|
|
3
|
+
import { S as Store, M as MethodDefinition, R as RouteDefinition, C as CronJobInputParams, a as RateLimitRule, E as EmailProvider, b as ConnectionInfo, I as InferDocumentType, c as RateLimitType, d as EmailPayload } from './types-D6nwUab6.js';
|
|
4
|
+
export { H as HttpMethod, e as RouteHandler, f as RouteParams, g as RouteResponse, s as schema } from './types-D6nwUab6.js';
|
|
5
|
+
import { ObjectId as ObjectId$1 } from 'mongodb';
|
|
5
6
|
export { ObjectId } from 'mongodb';
|
|
6
7
|
import * as zod from 'zod';
|
|
7
|
-
import
|
|
8
|
-
import { Request, Response, NextFunction } from 'express';
|
|
9
|
-
import { EmailProvider, EmailPayload } from './types.js';
|
|
8
|
+
import 'express';
|
|
10
9
|
import 'http';
|
|
11
10
|
|
|
12
|
-
type CronJobHandler = () => Promise<void>;
|
|
13
|
-
type CronJobInputParams = {
|
|
14
|
-
description?: string;
|
|
15
|
-
interval: number;
|
|
16
|
-
timeout?: number;
|
|
17
|
-
handler: CronJobHandler;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type ObjectTypeDefinition = {
|
|
21
|
-
[key: string]: SchemaTypeDefinition;
|
|
22
|
-
};
|
|
23
|
-
type SingularSchemaTypeDefinition = z.ZodType | ObjectTypeDefinition;
|
|
24
|
-
type SchemaTypeDefinition = SingularSchemaTypeDefinition | Array<SingularSchemaTypeDefinition>;
|
|
25
|
-
type ModelSchema = {
|
|
26
|
-
[key: string]: SchemaTypeDefinition;
|
|
27
|
-
};
|
|
28
|
-
type InferDocumentType<T extends SchemaTypeDefinition> = {
|
|
29
|
-
[K in keyof T as T[K] extends z.ZodOptional<z.ZodTypeAny> ? K : never]?: T[K] extends z.ZodType ? z.infer<T[K]> : never;
|
|
30
|
-
} & {
|
|
31
|
-
[K in keyof T as T[K] extends z.ZodOptional<z.ZodTypeAny> ? never : K]: T[K] extends z.ZodType ? z.infer<T[K]> : T[K] extends Array<infer ElementType extends SchemaTypeDefinition> ? Array<InferDocumentType<ElementType>> : T[K] extends ObjectTypeDefinition ? InferDocumentType<T[K]> : never;
|
|
32
|
-
};
|
|
33
|
-
declare const schema: {
|
|
34
|
-
readonly string: (params?: z.RawCreateParams & {
|
|
35
|
-
coerce?: true;
|
|
36
|
-
}) => z.ZodString;
|
|
37
|
-
readonly number: (params?: z.RawCreateParams & {
|
|
38
|
-
coerce?: boolean;
|
|
39
|
-
}) => ZodNumber;
|
|
40
|
-
readonly date: (params?: z.RawCreateParams & {
|
|
41
|
-
coerce?: boolean;
|
|
42
|
-
}) => z.ZodDate;
|
|
43
|
-
readonly boolean: (params?: z.RawCreateParams & {
|
|
44
|
-
coerce?: boolean;
|
|
45
|
-
}) => z.ZodBoolean;
|
|
46
|
-
readonly array: <El extends z.ZodTypeAny>(schema: El, params?: z.RawCreateParams) => ZodArray<El>;
|
|
47
|
-
readonly object: <Shape extends z.ZodRawShape>(shape: Shape, params?: z.RawCreateParams) => z.ZodObject<Shape, "strip", z.ZodTypeAny, z.objectOutputType<Shape, z.ZodTypeAny, "strip">, z.objectInputType<Shape, z.ZodTypeAny, "strip">>;
|
|
48
|
-
readonly enum: {
|
|
49
|
-
<U extends string, T extends Readonly<[U, ...U[]]>>(values: T, params?: z.RawCreateParams): z.ZodEnum<z.Writeable<T>>;
|
|
50
|
-
<U extends string, T extends [U, ...U[]]>(values: T, params?: z.RawCreateParams): z.ZodEnum<T>;
|
|
51
|
-
};
|
|
52
|
-
readonly embedding: () => ZodArray<ZodNumber>;
|
|
53
|
-
readonly objectId: () => z.ZodType<ObjectId$1>;
|
|
54
|
-
readonly userId: () => z.ZodType<ObjectId$1>;
|
|
55
|
-
readonly ref: <T extends ModelSchema>(_collection: string | Store<T, InferDocumentType<T>>) => z.ZodType<ObjectId$1>;
|
|
56
|
-
readonly union: <Options extends Readonly<[z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]>>(types: Options, params?: z.RawCreateParams) => z.ZodUnion<Options>;
|
|
57
|
-
readonly infer: <T extends SchemaTypeDefinition>(_schema: T) => InferDocumentType<T>;
|
|
58
|
-
};
|
|
59
|
-
declare namespace schema {
|
|
60
|
-
type infer<T extends SchemaTypeDefinition> = InferDocumentType<T>;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
interface SerializedModelSchema {
|
|
64
|
-
[key: string]: SerializedSchema | (SerializedSchema | SerializedModelSchema)[] | SerializedModelSchema | 'v2';
|
|
65
|
-
}
|
|
66
|
-
type BaseSerializedSchema = {
|
|
67
|
-
type: 'string';
|
|
68
|
-
} | {
|
|
69
|
-
type: 'number';
|
|
70
|
-
} | {
|
|
71
|
-
type: 'boolean';
|
|
72
|
-
} | {
|
|
73
|
-
type: 'date';
|
|
74
|
-
} | {
|
|
75
|
-
type: 'array';
|
|
76
|
-
items: SerializedSchema;
|
|
77
|
-
} | {
|
|
78
|
-
type: 'object';
|
|
79
|
-
items: Record<string, SerializedSchema>;
|
|
80
|
-
} | {
|
|
81
|
-
type: 'enum';
|
|
82
|
-
items: readonly string[];
|
|
83
|
-
} | {
|
|
84
|
-
type: 'union';
|
|
85
|
-
items: SerializedSchema[];
|
|
86
|
-
} | {
|
|
87
|
-
type: 'custom';
|
|
88
|
-
typeName: string;
|
|
89
|
-
};
|
|
90
|
-
type SerializedSchema = BaseSerializedSchema | (BaseSerializedSchema & {
|
|
91
|
-
optional: true;
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Helper type to preserve method types when extending a store.
|
|
96
|
-
* Maps each method to work with the extended schema while preserving signatures.
|
|
97
|
-
* @internal
|
|
98
|
-
*/
|
|
99
|
-
type PreserveMethodsForExtendedSchema<TBaseMethods extends Record<string, (...args: never[]) => unknown>, TExtendedSchema extends ModelSchema> = {
|
|
100
|
-
[K in keyof TBaseMethods]: TBaseMethods[K] extends (this: any, ...args: infer Args) => infer Return ? (this: WithId<InferDocumentType<TExtendedSchema>> & any, ...args: Args) => Return : never;
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* The Store class provides a type-safe interface for MongoDB collections with built-in schema validation and helper methods.
|
|
104
|
-
*
|
|
105
|
-
* @category Store
|
|
106
|
-
* @typeParam TSchema - The document schema type
|
|
107
|
-
* @typeParam TMethods - Custom methods that will be added to documents
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* const dbTodos = new Store('todos', {
|
|
112
|
-
* schema: {
|
|
113
|
-
* title: schema.string(),
|
|
114
|
-
* completed: schema.boolean(),
|
|
115
|
-
* dueDate: schema.date().optional(),
|
|
116
|
-
* userId: schema.userId(),
|
|
117
|
-
* },
|
|
118
|
-
* methods: {
|
|
119
|
-
* isOverdue() {
|
|
120
|
-
* return this.dueDate < new Date();
|
|
121
|
-
* }
|
|
122
|
-
* }
|
|
123
|
-
* });
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
declare class Store<TSchema extends ModelSchema, TMethods extends Record<string, (this: WithId<InferDocumentType<TSchema>> & TMethods, ...args: any[]) => any>> {
|
|
127
|
-
/** @internal */
|
|
128
|
-
readonly _type: InferDocumentType<TSchema>;
|
|
129
|
-
/** @internal */
|
|
130
|
-
readonly _rawDoc: WithId<this['_type']>;
|
|
131
|
-
/** @internal */
|
|
132
|
-
readonly _doc: this['_rawDoc'] & TMethods;
|
|
133
|
-
readonly Doc: this['_doc'];
|
|
134
|
-
private name;
|
|
135
|
-
private readonly schema;
|
|
136
|
-
private readonly methods?;
|
|
137
|
-
private readonly indexes;
|
|
138
|
-
private readonly searchIndexes;
|
|
139
|
-
private collection?;
|
|
140
|
-
private client?;
|
|
141
|
-
/**
|
|
142
|
-
* Creates a new Store instance
|
|
143
|
-
*
|
|
144
|
-
* @param name - The collection name in MongoDB
|
|
145
|
-
* @param options - Store configuration
|
|
146
|
-
*/
|
|
147
|
-
constructor(name: string, options: {
|
|
148
|
-
/** Document schema using Modelence schema types */
|
|
149
|
-
schema: TSchema;
|
|
150
|
-
/** Custom methods to add to documents */
|
|
151
|
-
methods?: TMethods;
|
|
152
|
-
/** MongoDB indexes to create */
|
|
153
|
-
indexes: IndexDescription[];
|
|
154
|
-
/** MongoDB Atlas Search */
|
|
155
|
-
searchIndexes?: SearchIndexDescription[];
|
|
156
|
-
});
|
|
157
|
-
getName(): string;
|
|
158
|
-
/** @internal */
|
|
159
|
-
getSchema(): TSchema;
|
|
160
|
-
/** @internal */
|
|
161
|
-
getSerializedSchema(): SerializedModelSchema;
|
|
162
|
-
/**
|
|
163
|
-
* Extends the store with additional schema fields, indexes, methods, and search indexes.
|
|
164
|
-
* Returns a new Store instance with the extended schema and updated types.
|
|
165
|
-
* Methods from the original store are preserved with updated type signatures.
|
|
166
|
-
*
|
|
167
|
-
* @param config - Additional schema fields, indexes, methods, and search indexes to add
|
|
168
|
-
* @returns A new Store instance with the extended schema
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```ts
|
|
172
|
-
* // Extend the users collection
|
|
173
|
-
* export const dbUsers = baseUsersCollection.extend({
|
|
174
|
-
* schema: {
|
|
175
|
-
* firstName: schema.string(),
|
|
176
|
-
* lastName: schema.string(),
|
|
177
|
-
* companyId: schema.objectId().optional(),
|
|
178
|
-
* },
|
|
179
|
-
* indexes: [
|
|
180
|
-
* { key: { companyId: 1 } },
|
|
181
|
-
* { key: { lastName: 1, firstName: 1 } },
|
|
182
|
-
* ],
|
|
183
|
-
* methods: {
|
|
184
|
-
* getFullName() {
|
|
185
|
-
* return `${this.firstName} ${this.lastName}`;
|
|
186
|
-
* }
|
|
187
|
-
* }
|
|
188
|
-
* });
|
|
189
|
-
*
|
|
190
|
-
* // Now fully typed with new fields
|
|
191
|
-
* const user = await dbUsers.findOne({ firstName: 'John' });
|
|
192
|
-
* console.log(user?.getFullName());
|
|
193
|
-
* ```
|
|
194
|
-
*/
|
|
195
|
-
extend<TExtendedSchema extends ModelSchema, TExtendedMethods extends Record<string, (this: WithId<InferDocumentType<TSchema & TExtendedSchema>> & any, ...args: any[]) => any> = Record<string, never>>(config: {
|
|
196
|
-
schema?: TExtendedSchema;
|
|
197
|
-
indexes?: IndexDescription[];
|
|
198
|
-
methods?: TExtendedMethods;
|
|
199
|
-
searchIndexes?: SearchIndexDescription[];
|
|
200
|
-
}): Store<TSchema & TExtendedSchema, PreserveMethodsForExtendedSchema<TMethods, TSchema & TExtendedSchema> & TExtendedMethods>;
|
|
201
|
-
/** @internal */
|
|
202
|
-
init(client: MongoClient): void;
|
|
203
|
-
/** @internal */
|
|
204
|
-
createIndexes(): Promise<void>;
|
|
205
|
-
private wrapDocument;
|
|
206
|
-
/**
|
|
207
|
-
* For convenience, to also allow directy passing a string or ObjectId as the selector
|
|
208
|
-
*/
|
|
209
|
-
private getSelector;
|
|
210
|
-
/** @internal */
|
|
211
|
-
requireCollection(): Collection<this["_type"]>;
|
|
212
|
-
/** @internal */
|
|
213
|
-
requireClient(): MongoClient;
|
|
214
|
-
findOne(query: Filter<this['_type']>, options?: FindOptions): Promise<this["_doc"] | null>;
|
|
215
|
-
requireOne(query: Filter<this['_type']>, options?: FindOptions, errorHandler?: () => Error): Promise<this['_doc']>;
|
|
216
|
-
private find;
|
|
217
|
-
/**
|
|
218
|
-
* Fetches a single document by its ID
|
|
219
|
-
*
|
|
220
|
-
* @param id - The ID of the document to find
|
|
221
|
-
* @returns The document, or null if not found
|
|
222
|
-
*/
|
|
223
|
-
findById(id: string | ObjectId$1): Promise<this['_doc'] | null>;
|
|
224
|
-
/**
|
|
225
|
-
* Fetches a single document by its ID, or throws an error if not found
|
|
226
|
-
*
|
|
227
|
-
* @param id - The ID of the document to find
|
|
228
|
-
* @param errorHandler - Optional error handler to return a custom error if the document is not found
|
|
229
|
-
* @returns The document
|
|
230
|
-
*/
|
|
231
|
-
requireById(id: string | ObjectId$1, errorHandler?: () => Error): Promise<this['_doc']>;
|
|
232
|
-
/**
|
|
233
|
-
* Counts the number of documents that match a query
|
|
234
|
-
*
|
|
235
|
-
* @param query - The query to filter documents
|
|
236
|
-
* @returns The number of documents that match the query
|
|
237
|
-
*/
|
|
238
|
-
countDocuments(query: Filter<this['_type']>): Promise<number>;
|
|
239
|
-
/**
|
|
240
|
-
* Fetches multiple documents, equivalent to Node.js MongoDB driver's `find` and `toArray` methods combined.
|
|
241
|
-
*
|
|
242
|
-
* @param query - The query to filter documents
|
|
243
|
-
* @param options - Options
|
|
244
|
-
* @returns The documents
|
|
245
|
-
*/
|
|
246
|
-
fetch(query: Filter<this['_type']>, options?: {
|
|
247
|
-
sort?: Document;
|
|
248
|
-
limit?: number;
|
|
249
|
-
skip?: number;
|
|
250
|
-
}): Promise<this['_doc'][]>;
|
|
251
|
-
/**
|
|
252
|
-
* Inserts a single document
|
|
253
|
-
*
|
|
254
|
-
* @param document - The document to insert
|
|
255
|
-
* @returns The result of the insert operation
|
|
256
|
-
*/
|
|
257
|
-
insertOne(document: OptionalUnlessRequiredId<InferDocumentType<TSchema>>): Promise<InsertOneResult>;
|
|
258
|
-
/**
|
|
259
|
-
* Inserts multiple documents
|
|
260
|
-
*
|
|
261
|
-
* @param documents - The documents to insert
|
|
262
|
-
* @returns The result of the insert operation
|
|
263
|
-
*/
|
|
264
|
-
insertMany(documents: OptionalUnlessRequiredId<InferDocumentType<TSchema>>[]): Promise<InsertManyResult>;
|
|
265
|
-
/**
|
|
266
|
-
* Updates a single document
|
|
267
|
-
*
|
|
268
|
-
* @param selector - The selector to find the document to update
|
|
269
|
-
* @param update - The update to apply to the document
|
|
270
|
-
* @returns The result of the update operation
|
|
271
|
-
*/
|
|
272
|
-
updateOne(selector: Filter<this['_type']> | string | ObjectId$1, update: UpdateFilter<this['_type']>): Promise<UpdateResult>;
|
|
273
|
-
/**
|
|
274
|
-
* Updates a single document, or inserts it if it doesn't exist
|
|
275
|
-
*
|
|
276
|
-
* @param selector - The selector to find the document to update
|
|
277
|
-
* @param update - The MongoDB modifier to apply to the document
|
|
278
|
-
* @returns The result of the update operation
|
|
279
|
-
*/
|
|
280
|
-
upsertOne(selector: Filter<this['_type']> | string | ObjectId$1, update: UpdateFilter<this['_type']>): Promise<UpdateResult>;
|
|
281
|
-
/**
|
|
282
|
-
* Updates multiple documents
|
|
283
|
-
*
|
|
284
|
-
* @param selector - The selector to find the documents to update
|
|
285
|
-
* @param update - The MongoDB modifier to apply to the documents
|
|
286
|
-
* @returns The result of the update operation
|
|
287
|
-
*/
|
|
288
|
-
updateMany(selector: Filter<this['_type']>, update: UpdateFilter<this['_type']>, options?: {
|
|
289
|
-
session?: ClientSession;
|
|
290
|
-
}): Promise<UpdateResult>;
|
|
291
|
-
/**
|
|
292
|
-
* Updates multiple documents, or inserts them if they don't exist
|
|
293
|
-
*
|
|
294
|
-
* @param selector - The selector to find the documents to update
|
|
295
|
-
* @param update - The MongoDB modifier to apply to the documents
|
|
296
|
-
* @returns The result of the update operation
|
|
297
|
-
*/
|
|
298
|
-
upsertMany(selector: Filter<this['_type']>, update: UpdateFilter<this['_type']>): Promise<UpdateResult>;
|
|
299
|
-
/**
|
|
300
|
-
* Deletes a single document
|
|
301
|
-
*
|
|
302
|
-
* @param selector - The selector to find the document to delete
|
|
303
|
-
* @returns The result of the delete operation
|
|
304
|
-
*/
|
|
305
|
-
deleteOne(selector: Filter<this['_type']>): Promise<DeleteResult>;
|
|
306
|
-
/**
|
|
307
|
-
* Deletes multiple documents
|
|
308
|
-
*
|
|
309
|
-
* @param selector - The selector to find the documents to delete
|
|
310
|
-
* @returns The result of the delete operation
|
|
311
|
-
*/
|
|
312
|
-
deleteMany(selector: Filter<this['_type']>): Promise<DeleteResult>;
|
|
313
|
-
/**
|
|
314
|
-
* Aggregates documents using MongoDB's aggregation framework
|
|
315
|
-
*
|
|
316
|
-
* @param pipeline - The aggregation pipeline
|
|
317
|
-
* @param options - Optional options
|
|
318
|
-
* @returns The aggregation cursor
|
|
319
|
-
*/
|
|
320
|
-
aggregate(pipeline: Document[], options?: AggregateOptions): AggregationCursor<Document>;
|
|
321
|
-
/**
|
|
322
|
-
* Performs a bulk write operation on the collection
|
|
323
|
-
*
|
|
324
|
-
* @param operations - The operations to perform
|
|
325
|
-
* @returns The result of the bulk write operation
|
|
326
|
-
*/
|
|
327
|
-
bulkWrite(operations: AnyBulkWriteOperation<this['_type']>[]): Promise<BulkWriteResult>;
|
|
328
|
-
/**
|
|
329
|
-
* Returns the raw MongoDB database instance for advanced operations
|
|
330
|
-
* @returns The MongoDB database instance
|
|
331
|
-
* @throws Error if the store is not provisioned
|
|
332
|
-
*/
|
|
333
|
-
getDatabase(): mongodb.Db;
|
|
334
|
-
/**
|
|
335
|
-
* Returns the raw MongoDB collection instance for advanced operations
|
|
336
|
-
* @returns The MongoDB collection instance
|
|
337
|
-
* @throws Error if the store is not provisioned
|
|
338
|
-
*/
|
|
339
|
-
rawCollection(): Collection<this["_type"]>;
|
|
340
|
-
/**
|
|
341
|
-
* Renames an existing collection to this store's name, used for migrations
|
|
342
|
-
* @param oldName - The previous name of the collection
|
|
343
|
-
* @throws Error if the old collection doesn't exist or if this store's collection already exists
|
|
344
|
-
*/
|
|
345
|
-
renameFrom(oldName: string, options?: {
|
|
346
|
-
session?: ClientSession;
|
|
347
|
-
}): Promise<void>;
|
|
348
|
-
/**
|
|
349
|
-
* Performs a vector similarity search using MongoDB Atlas Vector Search
|
|
350
|
-
*
|
|
351
|
-
* @param params - Vector search parameters
|
|
352
|
-
* @param params.field - The field name containing the vector embeddings
|
|
353
|
-
* @param params.embedding - The query vector to search for
|
|
354
|
-
* @param params.numCandidates - Number of nearest neighbors to consider (default: 100)
|
|
355
|
-
* @param params.limit - Maximum number of results to return (default: 10)
|
|
356
|
-
* @param params.projection - Additional fields to include in the results
|
|
357
|
-
* @param params.indexName - Name of index (default: field + VectorSearch)
|
|
358
|
-
* @returns An aggregation cursor with search results and scores
|
|
359
|
-
*
|
|
360
|
-
* @example
|
|
361
|
-
* ```ts
|
|
362
|
-
* const results = await store.vectorSearch({
|
|
363
|
-
* field: 'embedding',
|
|
364
|
-
* embedding: [0.1, 0.2, 0.3, ...],
|
|
365
|
-
* numCandidates: 100,
|
|
366
|
-
* limit: 10,
|
|
367
|
-
* projection: { title: 1, description: 1 }
|
|
368
|
-
* });
|
|
369
|
-
* ```
|
|
370
|
-
*/
|
|
371
|
-
vectorSearch({ field, embedding, numCandidates, limit, projection, indexName, }: {
|
|
372
|
-
field: string;
|
|
373
|
-
embedding: number[];
|
|
374
|
-
numCandidates?: number;
|
|
375
|
-
limit?: number;
|
|
376
|
-
projection?: Document;
|
|
377
|
-
indexName?: string;
|
|
378
|
-
}): Promise<AggregationCursor<Document>>;
|
|
379
|
-
/**
|
|
380
|
-
* Creates a MongoDB Atlas Vector Search index definition
|
|
381
|
-
*
|
|
382
|
-
* @param params - Vector index parameters
|
|
383
|
-
* @param params.field - The field name to create the vector index on
|
|
384
|
-
* @param params.dimensions - The number of dimensions in the vector embeddings
|
|
385
|
-
* @param params.similarity - The similarity metric to use (default: 'cosine')
|
|
386
|
-
* @param params.indexName - Name of index (default: field + VectorSearch)
|
|
387
|
-
* @returns A search index description object
|
|
388
|
-
*
|
|
389
|
-
* @example
|
|
390
|
-
* ```ts
|
|
391
|
-
* const store = new Store('documents', {
|
|
392
|
-
* schema: {
|
|
393
|
-
* title: schema.string(),
|
|
394
|
-
* embedding: schema.array(schema.number()),
|
|
395
|
-
* },
|
|
396
|
-
* indexes: [],
|
|
397
|
-
* searchIndexes: [
|
|
398
|
-
* Store.vectorIndex({
|
|
399
|
-
* field: 'embedding',
|
|
400
|
-
* dimensions: 1536,
|
|
401
|
-
* similarity: 'cosine'
|
|
402
|
-
* })
|
|
403
|
-
* ]
|
|
404
|
-
* });
|
|
405
|
-
* ```
|
|
406
|
-
*/
|
|
407
|
-
static vectorIndex({ field, dimensions, similarity, indexName, }: {
|
|
408
|
-
field: string;
|
|
409
|
-
dimensions: number;
|
|
410
|
-
similarity?: 'cosine' | 'euclidean' | 'dotProduct';
|
|
411
|
-
indexName?: string;
|
|
412
|
-
}): {
|
|
413
|
-
type: string;
|
|
414
|
-
name: string;
|
|
415
|
-
definition: {
|
|
416
|
-
fields: {
|
|
417
|
-
type: string;
|
|
418
|
-
path: string;
|
|
419
|
-
numDimensions: number;
|
|
420
|
-
similarity: "cosine" | "euclidean" | "dotProduct";
|
|
421
|
-
}[];
|
|
422
|
-
};
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
type ClientInfo = {
|
|
427
|
-
screenWidth: number;
|
|
428
|
-
screenHeight: number;
|
|
429
|
-
windowWidth: number;
|
|
430
|
-
windowHeight: number;
|
|
431
|
-
pixelRatio: number;
|
|
432
|
-
orientation: string | null;
|
|
433
|
-
};
|
|
434
|
-
type ConnectionInfo = {
|
|
435
|
-
ip?: string;
|
|
436
|
-
userAgent?: string;
|
|
437
|
-
acceptLanguage?: string;
|
|
438
|
-
referrer?: string;
|
|
439
|
-
baseUrl?: string;
|
|
440
|
-
};
|
|
441
|
-
type Context = {
|
|
442
|
-
session: Session | null;
|
|
443
|
-
user: UserInfo | null;
|
|
444
|
-
roles: string[];
|
|
445
|
-
clientInfo: ClientInfo;
|
|
446
|
-
connectionInfo: ConnectionInfo;
|
|
447
|
-
};
|
|
448
|
-
type Args = Record<string, unknown>;
|
|
449
|
-
type Handler<T = unknown> = (args: Args, context: Context) => Promise<T> | T;
|
|
450
|
-
type MethodDefinition<T = unknown> = {
|
|
451
|
-
permissions?: Permission[];
|
|
452
|
-
handler: Handler<T>;
|
|
453
|
-
} | Handler<T>;
|
|
454
|
-
|
|
455
|
-
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head' | 'all' | 'use';
|
|
456
|
-
type RouteParams<T = unknown> = {
|
|
457
|
-
query: Record<string, string>;
|
|
458
|
-
body: T;
|
|
459
|
-
params: Record<string, string>;
|
|
460
|
-
headers: Record<string, string>;
|
|
461
|
-
cookies: Record<string, string>;
|
|
462
|
-
req: Request;
|
|
463
|
-
res: Response;
|
|
464
|
-
next: NextFunction;
|
|
465
|
-
};
|
|
466
|
-
type RouteResponse<T = unknown> = {
|
|
467
|
-
data?: T;
|
|
468
|
-
status?: number;
|
|
469
|
-
headers?: Record<string, string>;
|
|
470
|
-
redirect?: string;
|
|
471
|
-
} | null;
|
|
472
|
-
type RouteHandler<T = unknown> = (params: RouteParams, context: Pick<Context, 'session' | 'user'>) => Promise<RouteResponse<T>> | RouteResponse<T>;
|
|
473
|
-
type RouteHandlers = {
|
|
474
|
-
[key in HttpMethod]?: RouteHandler;
|
|
475
|
-
};
|
|
476
|
-
type RouteDefinition = {
|
|
477
|
-
path: string;
|
|
478
|
-
handlers: RouteHandlers;
|
|
479
|
-
errorHandler?: RouteHandler;
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
type RateLimitType = 'ip' | 'user';
|
|
483
|
-
type RateLimitRule = {
|
|
484
|
-
/** Logical action being limited, e.g. "signup" */
|
|
485
|
-
bucket: string;
|
|
486
|
-
/** Identifier type of the actor this rule applies to */
|
|
487
|
-
type: RateLimitType;
|
|
488
|
-
/** Time window size in milliseconds */
|
|
489
|
-
window: number;
|
|
490
|
-
/** Maximum allowed hits within the window */
|
|
491
|
-
limit: number;
|
|
492
|
-
};
|
|
493
|
-
|
|
494
11
|
/** Array of Store instances that will be provisioned when the module is loaded */
|
|
495
12
|
type Stores = Store<any, any>[];
|
|
496
13
|
/** Record of query methods that can be called from the client */
|
|
@@ -1035,4 +552,4 @@ declare function authenticate(authToken: string | null): Promise<{
|
|
|
1035
552
|
|
|
1036
553
|
declare function sendEmail(payload: EmailPayload): Promise<void> | undefined;
|
|
1037
554
|
|
|
1038
|
-
export { type AppOptions, type AuthConfig, type AuthOption, type CloudBackendConnectResponse,
|
|
555
|
+
export { type AppOptions, type AuthConfig, type AuthOption, type CloudBackendConnectResponse, CronJobInputParams, Module, RateLimitRule, RateLimitType, RouteDefinition, ServerChannel, Store, UserInfo, authenticate, consumeRateLimit, createQuery, usersCollection as dbUsers, deleteUser, disableUser, getConfig, sendEmail, startApp };
|