Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

minato

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minato - npm Package Compare versions

Comparing version 1.0.10 to 1.1.0

2

lib/browser.js

@@ -1,1 +0,1 @@

var U=Object.defineProperty;var c=(r,e)=>U(r,"name",{value:e,configurable:!0});import{makeArray as R}from"cosmokit";import{clone as z,isNullable as A,makeArray as Q}from"cosmokit";function D(r){return r&&Object.keys(r).some(e=>e.startsWith("$"))}c(D,"isEvalExpr");var I=Symbol("expr"),V=Symbol("type"),p=c((r,e)=>({[I]:!0,["$"+r]:e}),"Eval"),b={};b.$=K;function d(r,e){return b["$"+r]=e,t=>p(r,t)}c(d,"unary");function y(r,e){return b["$"+r]=e,(...t)=>p(r,t)}c(y,"multary");p.if=y("if",([r,e,t],n)=>o(n,r)?o(n,e):o(n,t));p.ifNull=y("ifNull",([r,e],t)=>o(t,r)??o(t,e));p.add=y("add",(r,e)=>r.reduce((t,n)=>t+o(e,n),0));p.multiply=y("multiply",(r,e)=>r.reduce((t,n)=>t*o(e,n),1));p.subtract=y("subtract",([r,e],t)=>o(t,r)-o(t,e));p.divide=y("divide",([r,e],t)=>o(t,r)/o(t,e));p.eq=y("eq",([r,e],t)=>o(t,r).valueOf()===o(t,e).valueOf());p.ne=y("ne",([r,e],t)=>o(t,r).valueOf()!==o(t,e).valueOf());p.gt=y("gt",([r,e],t)=>o(t,r).valueOf()>o(t,e).valueOf());p.gte=y("gte",([r,e],t)=>o(t,r).valueOf()>=o(t,e).valueOf());p.lt=y("lt",([r,e],t)=>o(t,r).valueOf()<o(t,e).valueOf());p.lte=y("lte",([r,e],t)=>o(t,r).valueOf()<=o(t,e).valueOf());p.concat=y("concat",(r,e)=>r.map(t=>o(e,t)).join(""));p.and=y("and",(r,e)=>r.every(t=>o(e,t)));p.or=y("or",(r,e)=>r.some(t=>o(e,t)));p.not=d("not",(r,e)=>!o(e,r));p.sum=d("sum",(r,e)=>e.reduce((t,n)=>t+v(r,n),0));p.avg=d("avg",(r,e)=>e.reduce((t,n)=>t+v(r,n),0)/e.length);p.max=d("max",(r,e)=>Math.max(...e.map(t=>v(r,t))));p.min=d("min",(r,e)=>Math.min(...e.map(t=>v(r,t))));p.count=d("count",(r,e)=>new Set(e.map(t=>v(r,t))).size);function K(r,e){if(typeof r=="string")return K(["_",r],e);let[t,n]=r,i=e[t];for(let l of n.split(".")){if(!i)return;i=i[l]}return i}c(K,"getRecursive");function F(r,e){for(let t in r)if(t in b)return b[t](r[t],e);return r}c(F,"executeEvalExpr");function v(r,e){return typeof r=="string"?K(r,e):F(r,e)}c(v,"executeAggr");function o(r,e){return typeof e=="number"||typeof e=="string"||typeof e=="boolean"||e instanceof Date||e===null||e===void 0?e:F(e,r)}c(o,"executeEval");function q(r,e,t){for(let n in e){let i=r,l=n.split("."),a=l.pop();for(let s of l)i=i[s]||={};i[a]=o({[t]:r,_:r},e[n])}return r}c(q,"executeUpdate");var P;(a=>{a.number=["integer","unsigned","float","double","decimal"],a.string=["char","string","text"],a.date=["timestamp","date","time"],a.object=["list","json"];let i=/^(\w+)(?:\((.+)\))?$/;function l(s){if(typeof s!="string")return{initial:null,...s};let f=i.exec(s);if(!f)throw new TypeError("invalid field definition");let m=f[1],x=(f[2]||"").split(","),u={type:m};return u.initial===void 0&&(a.number.includes(u.type)&&(u.initial=0),a.string.includes(u.type)&&(u.initial=""),u.type==="list"&&(u.initial=[]),u.type==="json"&&(u.initial={})),m==="decimal"?(u.precision=+x[0],u.scale=+x[1]):x[0]&&(u.length=+x[0]),u}a.parse=l,c(l,"parse")})(P||={});var h=class{constructor(e){this.name=e;this.primary="id",this.unique=[],this.foreign={}}fields={};internal={"":{}};extend(e={},t={}){let{primary:n,autoInc:i,unique:l=[],foreign:a}=t;this.primary=n||this.primary,this.autoInc=i||this.autoInc,this.unique.push(...l),Object.assign(this.foreign,a);for(let s in e)if(typeof e[s]=="function"){let f=s.lastIndexOf("."),m=s.slice(0,f+1),x=s.slice(f+1);(this.internal[m]??={})[x]=e[s]}else this.fields[s]=P.parse(e[s]);this.checkIndex(this.primary),this.unique.forEach(s=>this.checkIndex(s))}checkIndex(e){for(let t of Q(e))if(!this.fields[t])throw new TypeError(`missing field definition for index key "${t}"`)}resolveValue(e,t){if(A(t))return t;if(this.fields[e]?.type==="time"){let n=new Date(0);return n.setHours(t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()),n}return t}format(e,t=!0,n="",i={}){let l=Object.keys(this.fields);return Object.entries(e).map(([a,s])=>{if(a=n+a,l.includes(a))i[a]=s;else if(!s||typeof s!="object"||D(s)){if(l.find(m=>a.startsWith(m+".")))i[a]=s;else if(t)throw new TypeError(`unknown field "${a}" in model ${this.name}`)}else this.format(s,t,a+".",i)}),i}parse(e){let t=Object.create(this.internal[""]);for(let n in e){let i=t,l=n.split(".").reverse(),a="";for(let s=l.length-1;s>0;s--){let f=l[s];a+=f+".",i=i[f]??=Object.create(this.internal[a]??{})}if(n in e){let s=this.resolveValue(n,e[n]);i[l[0]]=s}}return t}create(e){let t={},n=Q(this.primary);for(let i in this.fields)!n.includes(i)&&!A(this.fields[i].initial)&&(t[i]=z(this.fields[i].initial));return this.parse({...t,...e})}};c(h,"Model");import{defineProperty as B,pick as W,valueMap as _}from"cosmokit";var M=c((r,e="",t={})=>new Proxy(t,{get(n,i){return typeof i=="symbol"||i.startsWith("$")?Reflect.get(n,i):M(r,`${e}${i}.`,p("",[r,`${e}${i}`]))}}),"createRow"),E=class{#e;#t;driver;constructor(e,t){B(this,"driver",e),Object.assign(this,t)}get row(){return this.#e||=M(this.ref)}get model(){return this.#t||=this.driver.model(this.table)}resolveQuery(e={}){if(typeof e=="function")return{$expr:e(this.row)};if(Array.isArray(e)||e instanceof RegExp||["string","number"].includes(typeof e)){let{primary:t}=this.model;if(Array.isArray(t))throw new TypeError("invalid shorthand for composite primary key");return{[t]:e}}return e}resolveData(e,t){e=this.model.format(e,!1);for(let n in this.model.fields)e[n]??=null;return t?this.model.parse(W(e,Object.keys(t))):this.model.parse(e)}resolveField(e){if(typeof e=="string")return this.row[e];if(typeof e=="function")return e(this.row)}execute(){return this.driver.execute(this)}};c(E,"Executable");var j="abcdefghijklmnopqrstuvwxyz",T=class extends E{args;constructor(e,t,n){super(e),this.type="get",this.ref=Array(8).fill(0).map(()=>j[Math.floor(Math.random()*j.length)]).join(""),this.table=t,this.query=this.resolveQuery(n),this.args=[{sort:[],limit:1/0,offset:0}]}limit(e){return this.args[0].limit=e,this}offset(e){return this.args[0].offset=e,this}orderBy(e,t){return this.args[0].sort.push([this.resolveField(e),t]),this}project(e){if(Array.isArray(e)){let t=Object.keys(this.model.fields),n=e.flatMap(i=>this.model.fields[i]?i:t.filter(l=>l.startsWith(i+".")));this.fields=Object.fromEntries(n.map(i=>[i,this.row[i]]))}else this.fields=_(e,t=>this.resolveField(t));return this}action(e,...t){return new E(this.driver,{...this,type:e,args:t})}evaluate(e){return this.action("eval",this.resolveField(e))}};c(T,"Selection");function ie(r,e,t){let{limit:n,offset:i,sort:l}=e;return r.sort((a,s)=>{for(let[f,m]of l){let x=m==="asc"?1:-1,u=o({[t]:a,_:a},f),C=o({[t]:s,_:s},f);if(u<C)return-x;if(u>C)return x}return 0}),r.slice(i,i+n)}c(ie,"executeSort");import Y from"ns-require";var H=Y({namespace:"minato",prefix:"driver",official:"minatojs"}),$=class{constructor(e={}){this.mapper=e}tables={};drivers={};tasks={};stashed=new Set;connect(e,t){return typeof e=="string"&&(e=H.require(e)),new e(this,t).start()}setDriver(e,t){if(!t)delete this.drivers[e];else{this.drivers[e]=t;for(let n in this.tables)this.tasks[n]=this.prepare(n)}}getDriver(e){return this.mapper[e]?this.drivers[this.mapper[e]]:Object.values(this.drivers)[0]}async prepare(e){return this.stashed.add(e),await this.tasks[e],new Promise(t=>{process.nextTick(async()=>{this.stashed.delete(e)&&await this.getDriver(e)?.prepare(e),t()})})}extend(e,t,n={}){(this.tables[e]||=new h(e)).extend(t,n),this.tasks[e]=this.prepare(e)}select(e,t){return new T(this.getDriver(e),e,t)}async get(e,t,n){await this.tasks[e],Array.isArray(n)?n={fields:n}:n||(n={});let i=this.select(e,t);if(n.fields&&i.project(n.fields),n.limit!==void 0&&i.limit(n.limit),n.offset!==void 0&&i.offset(n.offset),n.sort)for(let l in n.sort)i.orderBy(l,n.sort[l]);return i.execute()}async eval(e,t,n){return await this.tasks[e],this.select(e,n).evaluate(typeof t=="function"?t:()=>t).execute()}async set(e,t,n){await this.tasks[e];let i=this.select(e,t);if(typeof n=="function"&&(n=n(i.row)),R(i.model.primary).some(a=>a in n))throw new TypeError("cannot modify primary key");await i.action("set",i.model.format(n)).execute()}async remove(e,t){await this.tasks[e],await this.select(e,t).action("remove").execute()}async create(e,t){await this.tasks[e];let n=this.select(e);return n.action("create",n.model.create(t)).execute()}async upsert(e,t,n){await this.tasks[e];let i=this.select(e);typeof t=="function"&&(t=t(i.row)),t=t.map(l=>i.model.format(l)),n=R(n||i.model.primary),await i.action("upsert",t,n).execute()}async stopAll(){await Promise.all(Object.values(this.drivers).map(e=>e.stop()))}async dropAll(){await Promise.all(Object.values(this.drivers).map(e=>e.drop()))}async stats(){let e={size:0,tables:{}};return await Promise.all(Object.values(this.drivers).map(async t=>{let{size:n,tables:i}=await t.stats();e.size+=n,Object.assign(e.tables,i)})),e}};c($,"Database");var O=class{constructor(e,t){this.database=e;this.name=t}async start(){this.database.setDriver(this.name,this)}async stop(){this.database.setDriver(this.name,null)}model(e){let t=this.database.tables[e];if(t)return t;throw new TypeError(`unknown table name "${e}"`)}execute(e){let{type:t,args:n}=e;return this[t](e,...n)}};c(O,"Driver");var S=class extends Error{constructor(t,n){super(n||t.replace("-"," "));this.code=t}name="RuntimeError";static check(t,n){return t instanceof S?!n||t.message===n:!1}};c(S,"RuntimeError");import{isNullable as k}from"cosmokit";var N={$or:(r,e)=>r.reduce((t,n)=>t||g(n,e),!1),$and:(r,e)=>r.reduce((t,n)=>t&&g(n,e),!0),$not:(r,e)=>!g(r,e),$exists:(r,e)=>r!==k(e),$eq:(r,e)=>e.valueOf()===r.valueOf(),$ne:(r,e)=>e.valueOf()!==r.valueOf(),$gt:(r,e)=>e.valueOf()>r.valueOf(),$gte:(r,e)=>e.valueOf()>=r.valueOf(),$lt:(r,e)=>e.valueOf()<r.valueOf(),$lte:(r,e)=>e.valueOf()<=r.valueOf(),$in:(r,e)=>r.includes(e),$nin:(r,e)=>!r.includes(e),$regex:(r,e)=>r.test(e),$regexFor:(r,e)=>new RegExp(e,"i").test(r),$bitsAllSet:(r,e)=>(r&e)===r,$bitsAllClear:(r,e)=>(r&e)===0,$bitsAnySet:(r,e)=>(r&e)!==0,$bitsAnyClear:(r,e)=>(r&e)!==r,$el:(r,e)=>e.some(t=>g(r,t)),$size:(r,e)=>e.length===r};function g(r,e){if(Array.isArray(r))return r.includes(e);if(r instanceof RegExp)return r.test(e);if(typeof r=="string"||typeof r=="number"||r instanceof Date)return e.valueOf()===r.valueOf();if(k(r))return k(e);for(let t in r)if(t in N&&!N[t](r[t],e))return!1;return!0}c(g,"executeFieldQuery");function w(r,e,t){return Object.entries(e).every(([i,l])=>{if(i==="$and")return l.reduce((a,s)=>a&&w(r,s,t),!0);if(i==="$or")return l.reduce((a,s)=>a||w(r,s,t),!1);if(i==="$not")return!w(r,l,t);if(i==="$expr")return o({[t]:r,_:r},l);try{return g(l,r[i])}catch{return!1}})}c(w,"executeQuery");export{p as $,$ as Database,O as Driver,p as Eval,E as Executable,P as Field,h as Model,S as RuntimeError,T as Selection,o as executeEval,w as executeQuery,ie as executeSort,q as executeUpdate,D as isEvalExpr};
var I=Object.defineProperty;var l=(r,e)=>I(r,"name",{value:e,configurable:!0});import{makeArray as N}from"cosmokit";import{clone as W,isNullable as C,makeArray as Q}from"cosmokit";import{isNullable as z}from"cosmokit";function $(r){return typeof r=="string"||typeof r=="number"||typeof r=="boolean"||r instanceof Date}l($,"isPlain");function F(r){return r&&Object.keys(r).some(e=>e.startsWith("$"))}l(F,"isEvalExpr");var B=Symbol("expr"),te=Symbol("type"),c=l((r,e)=>({[B]:!0,["$"+r]:e}),"Eval"),v={};v.$=O;function b(r,e){return v["$"+r]=e,t=>c(r,t)}l(b,"unary");function u(r,e){return v["$"+r]=e,(...t)=>c(r,t)}l(u,"multary");c.if=u("if",([r,e,t],n)=>a(n,r)?a(n,e):a(n,t));c.ifNull=u("ifNull",([r,e],t)=>a(t,r)??a(t,e));c.add=u("add",(r,e)=>r.reduce((t,n)=>t+a(e,n),0));c.multiply=u("multiply",(r,e)=>r.reduce((t,n)=>t*a(e,n),1));c.subtract=u("subtract",([r,e],t)=>a(t,r)-a(t,e));c.divide=u("divide",([r,e],t)=>a(t,r)/a(t,e));c.eq=u("eq",([r,e],t)=>a(t,r).valueOf()===a(t,e).valueOf());c.ne=u("ne",([r,e],t)=>a(t,r).valueOf()!==a(t,e).valueOf());c.gt=u("gt",([r,e],t)=>a(t,r).valueOf()>a(t,e).valueOf());c.gte=u("gte",([r,e],t)=>a(t,r).valueOf()>=a(t,e).valueOf());c.lt=u("lt",([r,e],t)=>a(t,r).valueOf()<a(t,e).valueOf());c.lte=u("lte",([r,e],t)=>a(t,r).valueOf()<=a(t,e).valueOf());c.concat=u("concat",(r,e)=>r.map(t=>a(e,t)).join(""));c.and=u("and",(r,e)=>r.every(t=>a(e,t)));c.or=u("or",(r,e)=>r.some(t=>a(e,t)));c.not=b("not",(r,e)=>!a(e,r));c.sum=b("sum",(r,e)=>e.reduce((t,n)=>t+S(r,n),0));c.avg=b("avg",(r,e)=>e.reduce((t,n)=>t+S(r,n),0)/e.length);c.max=b("max",(r,e)=>Math.max(...e.map(t=>S(r,t))));c.min=b("min",(r,e)=>Math.min(...e.map(t=>S(r,t))));c.count=b("count",(r,e)=>new Set(e.map(t=>S(r,t))).size);function O(r,e){if(typeof r=="string")return O(["_",r],e);let[t,n]=r,i=e[t];for(let o of n.split(".")){if(!i)return;i=i[o]}return i}l(O,"getRecursive");function A(r,e){for(let t in r)if(t in v)return v[t](r[t],e);return r}l(A,"executeEvalExpr");function S(r,e){return typeof r=="string"?O(r,e):A(r,e)}l(S,"executeAggr");function a(r,e){return $(e)||z(e)?e:A(e,r)}l(a,"executeEval");function re(r,e,t){for(let n in e){let i=r,o=n.split("."),p=o.pop();for(let s of o)i=i[s]||={};i[p]=a({[t]:r,_:r},e[n])}return r}l(re,"executeUpdate");var M;(s=>{s.number=["integer","unsigned","float","double","decimal"],s.string=["char","string","text"],s.boolean=["boolean"],s.date=["timestamp","date","time"],s.object=["list","json"];let o=/^(\w+)(?:\((.+)\))?$/;function p(f){if(typeof f!="string")return{initial:null,...f};let x=o.exec(f);if(!x)throw new TypeError("invalid field definition");let d=x[1],m=(x[2]||"").split(","),y={type:d};return y.initial===void 0&&(s.number.includes(y.type)&&(y.initial=0),s.string.includes(y.type)&&(y.initial=""),y.type==="list"&&(y.initial=[]),y.type==="json"&&(y.initial={})),d==="decimal"?(y.precision=+m[0],y.scale=+m[1]):m[0]&&(y.length=+m[0]),y}s.parse=p,l(p,"parse")})(M||={});var T=class{constructor(e){this.name=e;this.primary="id",this.unique=[],this.foreign={}}fields={};internal={"":{}};extend(e={},t={}){let{primary:n,autoInc:i,unique:o=[],foreign:p}=t;this.primary=n||this.primary,this.autoInc=i||this.autoInc,this.unique.push(...o),Object.assign(this.foreign,p);for(let s in e)if(typeof e[s]=="function"){let f=s.lastIndexOf("."),x=s.slice(0,f+1),d=s.slice(f+1);(this.internal[x]??={})[d]=e[s]}else this.fields[s]=M.parse(e[s]);this.checkIndex(this.primary),this.unique.forEach(s=>this.checkIndex(s))}checkIndex(e){for(let t of Q(e))if(!this.fields[t])throw new TypeError(`missing field definition for index key "${t}"`)}resolveValue(e,t){if(C(t))return t;if(this.fields[e]?.type==="time"){let n=new Date(0);return n.setHours(t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()),n}return t}format(e,t=!0,n="",i={}){let o=Object.keys(this.fields);return Object.entries(e).map(([p,s])=>{if(p=n+p,o.includes(p))i[p]=s;else if(!s||typeof s!="object"||F(s)){if(o.find(x=>p.startsWith(x+".")))i[p]=s;else if(t)throw new TypeError(`unknown field "${p}" in model ${this.name}`)}else this.format(s,t,p+".",i)}),i}parse(e){let t=Object.create(this.internal[""]);for(let n in e){let i=t,o=n.split(".").reverse(),p="";for(let s=o.length-1;s>0;s--){let f=o[s];p+=f+".",i=i[f]??=Object.create(this.internal[p]??{})}if(n in e){let s=this.resolveValue(n,e[n]);i[o[0]]=s}}return t}create(e){let t={},n=Q(this.primary);for(let i in this.fields)!n.includes(i)&&!C(this.fields[i].initial)&&(t[i]=W(this.fields[i].initial));return this.parse({...t,...e})}};l(T,"Model");import{defineProperty as V,pick as _,valueMap as q}from"cosmokit";var R=l((r,e="",t={})=>new Proxy(t,{get(n,i){return typeof i=="symbol"||i.startsWith("$")?Reflect.get(n,i):R(r,`${e}${i}.`,c("",[r,`${e}${i}`]))}}),"createRow"),h=class{#e;#t;driver;constructor(e,t){V(this,"driver",e),Object.assign(this,t)}get row(){return this.#e||=R(this.ref)}get model(){return this.#t||=this.driver.model(this.table)}resolveQuery(e={}){if(typeof e=="function")return{$expr:e(this.row)};if(Array.isArray(e)||e instanceof RegExp||["string","number"].includes(typeof e)){let{primary:t}=this.model;if(Array.isArray(t))throw new TypeError("invalid shorthand for composite primary key");return{[t]:e}}return e}resolveData(e,t){e=this.model.format(e,!1);for(let n in this.model.fields)e[n]??=null;return t?this.model.parse(_(e,Object.keys(t))):this.model.parse(e)}resolveField(e){if(typeof e=="string")return this.row[e];if(typeof e=="function")return e(this.row)}execute(){return this.driver.execute(this)}};l(h,"Executable");var j="abcdefghijklmnopqrstuvwxyz",g=class extends h{args;constructor(e,t,n){super(e),this.type="get",this.ref=Array(8).fill(0).map(()=>j[Math.floor(Math.random()*j.length)]).join(""),this.table=t,this.query=this.resolveQuery(n),this.args=[{sort:[],limit:1/0,offset:0}]}limit(e){return this.args[0].limit=e,this}offset(e){return this.args[0].offset=e,this}orderBy(e,t){return this.args[0].sort.push([this.resolveField(e),t]),this}project(e){if(Array.isArray(e)){let t=Object.keys(this.model.fields),n=e.flatMap(i=>this.model.fields[i]?i:t.filter(o=>o.startsWith(i+".")));this.fields=Object.fromEntries(n.map(i=>[i,this.row[i]]))}else this.fields=q(e,t=>this.resolveField(t));return this}action(e,...t){return new h(this.driver,{...this,type:e,args:t})}evaluate(e){return this.action("eval",this.resolveField(e))}};l(g,"Selection");function ye(r,e,t){let{limit:n,offset:i,sort:o}=e;return r.sort((p,s)=>{for(let[f,x]of o){let d=x==="asc"?1:-1,m=a({[t]:p,_:p},f),y=a({[t]:s,_:s},f);if(m<y)return-d;if(m>y)return d}return 0}),r.slice(i,i+n)}l(ye,"executeSort");import Y from"ns-require";var H=Y({namespace:"minato",prefix:"driver",official:"minatojs"}),w=class{constructor(e={}){this.mapper=e}tables={};drivers={};tasks={};stashed=new Set;connect(e,t){return typeof e=="string"&&(e=H.require(e)),new e(this,t).start()}setDriver(e,t){if(!t)delete this.drivers[e];else{this.drivers[e]=t;for(let n in this.tables)this.tasks[n]=this.prepare(n)}}getDriver(e){return this.mapper[e]?this.drivers[this.mapper[e]]:Object.values(this.drivers)[0]}async prepare(e){return this.stashed.add(e),await this.tasks[e],new Promise(t=>{process.nextTick(async()=>{this.stashed.delete(e)&&await this.getDriver(e)?.prepare(e),t()})})}extend(e,t,n={}){(this.tables[e]||=new T(e)).extend(t,n),this.tasks[e]=this.prepare(e)}select(e,t){return new g(this.getDriver(e),e,t)}async get(e,t,n){await this.tasks[e],Array.isArray(n)?n={fields:n}:n||(n={});let i=this.select(e,t);if(n.fields&&i.project(n.fields),n.limit!==void 0&&i.limit(n.limit),n.offset!==void 0&&i.offset(n.offset),n.sort)for(let o in n.sort)i.orderBy(o,n.sort[o]);return i.execute()}async eval(e,t,n){return await this.tasks[e],this.select(e,n).evaluate(typeof t=="function"?t:()=>t).execute()}async set(e,t,n){await this.tasks[e];let i=this.select(e,t);if(typeof n=="function"&&(n=n(i.row)),N(i.model.primary).some(p=>p in n))throw new TypeError("cannot modify primary key");await i.action("set",i.model.format(n)).execute()}async remove(e,t){await this.tasks[e],await this.select(e,t).action("remove").execute()}async create(e,t){await this.tasks[e];let n=this.select(e);return n.action("create",n.model.create(t)).execute()}async upsert(e,t,n){await this.tasks[e];let i=this.select(e);typeof t=="function"&&(t=t(i.row)),t=t.map(o=>i.model.format(o)),n=N(n||i.model.primary),await i.action("upsert",t,n).execute()}async stopAll(){await Promise.all(Object.values(this.drivers).map(e=>e.stop()))}async dropAll(){await Promise.all(Object.values(this.drivers).map(e=>e.drop()))}async stats(){let e={size:0,tables:{}};return await Promise.all(Object.values(this.drivers).map(async t=>{let{size:n,tables:i}=await t.stats();e.size+=n,Object.assign(e.tables,i)})),e}};l(w,"Database");var P=class{constructor(e,t){this.database=e;this.name=t}async start(){this.database.setDriver(this.name,this)}async stop(){this.database.setDriver(this.name,null)}model(e){let t=this.database.tables[e];if(t)return t;throw new TypeError(`unknown table name "${e}"`)}execute(e){let{type:t,args:n}=e;return this[t](e,...n)}};l(P,"Driver");var E=class extends Error{constructor(t,n){super(n||t.replace("-"," "));this.code=t}name="RuntimeError";static check(t,n){return t instanceof E?!n||t.message===n:!1}};l(E,"RuntimeError");import{isNullable as D}from"cosmokit";var U={$or:(r,e)=>r.reduce((t,n)=>t||K(n,e),!1),$and:(r,e)=>r.reduce((t,n)=>t&&K(n,e),!0),$not:(r,e)=>!K(r,e),$exists:(r,e)=>r!==D(e),$eq:(r,e)=>e.valueOf()===r.valueOf(),$ne:(r,e)=>e.valueOf()!==r.valueOf(),$gt:(r,e)=>e.valueOf()>r.valueOf(),$gte:(r,e)=>e.valueOf()>=r.valueOf(),$lt:(r,e)=>e.valueOf()<r.valueOf(),$lte:(r,e)=>e.valueOf()<=r.valueOf(),$in:(r,e)=>r.includes(e),$nin:(r,e)=>!r.includes(e),$regex:(r,e)=>r.test(e),$regexFor:(r,e)=>new RegExp(e,"i").test(r),$bitsAllSet:(r,e)=>(r&e)===r,$bitsAllClear:(r,e)=>(r&e)===0,$bitsAnySet:(r,e)=>(r&e)!==0,$bitsAnyClear:(r,e)=>(r&e)!==r,$el:(r,e)=>e.some(t=>K(r,t)),$size:(r,e)=>e.length===r};function K(r,e){if(Array.isArray(r))return r.includes(e);if(r instanceof RegExp)return r.test(e);if($(r))return e.valueOf()===r.valueOf();if(D(r))return D(e);for(let t in r)if(t in U&&!U[t](r[t],e))return!1;return!0}l(K,"executeFieldQuery");function k(r,e,t){return Object.entries(e).every(([i,o])=>{if(i==="$and")return o.reduce((p,s)=>p&&k(r,s,t),!0);if(i==="$or")return o.reduce((p,s)=>p||k(r,s,t),!1);if(i==="$not")return!k(r,o,t);if(i==="$expr")return a({[t]:r,_:r},o);try{return K(o,r[i])}catch{return!1}})}l(k,"executeQuery");export{c as $,w as Database,P as Driver,c as Eval,h as Executable,M as Field,T as Model,E as RuntimeError,g as Selection,a as executeEval,k as executeQuery,ye as executeSort,re as executeUpdate,F as isEvalExpr,$ as isPlain};

@@ -1,6 +0,6 @@

import { Common, Flatten } from './utils';
import { Plain, Flatten } from './utils';
export declare function isEvalExpr(value: any): value is Eval.Expr;
declare type $Date = Date;
export declare type Uneval<U> = U extends number ? Eval.Number : U extends string ? Eval.String : U extends boolean ? Eval.Boolean : U extends $Date ? Eval.Date : any;
export declare type Eval<U> = U extends Common ? U : U extends Eval.Expr<infer T> ? T : never;
export declare type Eval<U> = U extends Plain ? U : U extends Eval.Expr<infer T> ? T : never;
declare const kExpr: unique symbol;

@@ -17,7 +17,7 @@ declare const kType: unique symbol;

type Date = $Date | Expr<$Date>;
type Any = Common | Expr;
type Any = Plain | Expr;
interface Static {
(key: string, value: any): Eval.Expr;
if<T extends Common>(cond: Any, vThen: T | Expr<T>, vElse: T | Expr<T>): Expr<T>;
ifNull<T extends Common>(...args: (T | Expr<T>)[]): Expr<T>;
if<T extends Plain>(cond: Any, vThen: T | Expr<T>, vElse: T | Expr<T>): Expr<T>;
ifNull<T extends Plain>(...args: (T | Expr<T>)[]): Expr<T>;
add(...args: Number[]): Expr<number>;

@@ -24,0 +24,0 @@ multiply(...args: Number[]): Expr<number>;

@@ -14,5 +14,6 @@ import { MaybeArray } from 'cosmokit';

export const string: Type[];
export const boolean: Type[];
export const date: Type[];
export const object: Type[];
export type Type<T = any> = T extends number ? 'integer' | 'unsigned' | 'float' | 'double' | 'decimal' : T extends string ? 'char' | 'string' | 'text' : T extends Date ? 'timestamp' | 'date' | 'time' : T extends unknown[] ? 'list' | 'json' : T extends object ? 'json' : never;
export type Type<T = any> = T extends number ? 'integer' | 'unsigned' | 'float' | 'double' | 'decimal' : T extends string ? 'char' | 'string' | 'text' : T extends boolean ? 'boolean' : T extends Date ? 'timestamp' | 'date' | 'time' : T extends unknown[] ? 'list' | 'json' : T extends object ? 'json' : never;
type Shorthand<S extends string> = S | `${S}(${any})`;

@@ -19,0 +20,0 @@ type MapField<O = any> = {

@@ -74,3 +74,4 @@ var __create = Object.create;

executeUpdate: () => executeUpdate,
isEvalExpr: () => isEvalExpr
isEvalExpr: () => isEvalExpr,
isPlain: () => isPlain
});

@@ -80,7 +81,16 @@ module.exports = __toCommonJS(src_exports);

// minato/packages/core/src/driver.ts
var import_cosmokit3 = require("cosmokit");
var import_cosmokit4 = require("cosmokit");
// minato/packages/core/src/model.ts
var import_cosmokit2 = require("cosmokit");
// minato/packages/core/src/eval.ts
var import_cosmokit = require("cosmokit");
// minato/packages/core/src/utils.ts
function isPlain(value) {
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value instanceof Date;
}
__name(isPlain, "isPlain");
// minato/packages/core/src/eval.ts

@@ -161,3 +171,3 @@ function isEvalExpr(value) {

function executeEval(data, expr) {
if (typeof expr === "number" || typeof expr === "string" || typeof expr === "boolean" || expr instanceof Date || expr === null || expr === void 0) {
if (isPlain(expr) || (0, import_cosmokit.isNullable)(expr)) {
return expr;

@@ -187,2 +197,3 @@ }

Field3.string = ["char", "string", "text"];
Field3.boolean = ["boolean"];
Field3.date = ["timestamp", "date", "time"];

@@ -251,3 +262,3 @@ Field3.object = ["list", "json"];

checkIndex(index) {
for (const key of (0, import_cosmokit.makeArray)(index)) {
for (const key of (0, import_cosmokit2.makeArray)(index)) {
if (!this.fields[key]) {

@@ -260,3 +271,3 @@ throw new TypeError(`missing field definition for index key "${key}"`);

var _a;
if ((0, import_cosmokit.isNullable)(value))
if ((0, import_cosmokit2.isNullable)(value))
return value;

@@ -310,6 +321,6 @@ if (((_a = this.fields[key]) == null ? void 0 : _a.type) === "time") {

const result = {};
const keys = (0, import_cosmokit.makeArray)(this.primary);
const keys = (0, import_cosmokit2.makeArray)(this.primary);
for (const key in this.fields) {
if (!keys.includes(key) && !(0, import_cosmokit.isNullable)(this.fields[key].initial)) {
result[key] = (0, import_cosmokit.clone)(this.fields[key].initial);
if (!keys.includes(key) && !(0, import_cosmokit2.isNullable)(this.fields[key].initial)) {
result[key] = (0, import_cosmokit2.clone)(this.fields[key].initial);
}

@@ -323,3 +334,3 @@ }

// minato/packages/core/src/selection.ts
var import_cosmokit2 = require("cosmokit");
var import_cosmokit3 = require("cosmokit");
var createRow = /* @__PURE__ */ __name((ref, prefix = "", expr = {}) => new Proxy(expr, {

@@ -337,3 +348,3 @@ get(target, key) {

__privateAdd(this, _model, void 0);
(0, import_cosmokit2.defineProperty)(this, "driver", driver);
(0, import_cosmokit3.defineProperty)(this, "driver", driver);
Object.assign(this, payload);

@@ -367,3 +378,3 @@ }

return this.model.parse(data);
return this.model.parse((0, import_cosmokit2.pick)(data, Object.keys(fields)));
return this.model.parse((0, import_cosmokit3.pick)(data, Object.keys(fields)));
}

@@ -416,3 +427,3 @@ resolveField(field) {

} else {
this.fields = (0, import_cosmokit2.valueMap)(fields, (field) => this.resolveField(field));
this.fields = (0, import_cosmokit3.valueMap)(fields, (field) => this.resolveField(field));
}

@@ -536,3 +547,3 @@ return this;

update = update(sel.row);
const primary = (0, import_cosmokit3.makeArray)(sel.model.primary);
const primary = (0, import_cosmokit4.makeArray)(sel.model.primary);
if (primary.some((key) => key in update)) {

@@ -559,3 +570,3 @@ throw new TypeError(`cannot modify primary key`);

upsert = upsert.map((item) => sel.model.format(item));
keys = (0, import_cosmokit3.makeArray)(keys || sel.model.primary);
keys = (0, import_cosmokit4.makeArray)(keys || sel.model.primary);
await sel.action("upsert", upsert, keys).execute();

@@ -620,3 +631,3 @@ }

// minato/packages/core/src/query.ts
var import_cosmokit4 = require("cosmokit");
var import_cosmokit5 = require("cosmokit");
var queryOperators = {

@@ -626,3 +637,3 @@ $or: (query, data) => query.reduce((prev, query2) => prev || executeFieldQuery(query2, data), false),

$not: (query, data) => !executeFieldQuery(query, data),
$exists: (query, data) => query !== (0, import_cosmokit4.isNullable)(data),
$exists: (query, data) => query !== (0, import_cosmokit5.isNullable)(data),
$eq: (query, data) => data.valueOf() === query.valueOf(),

@@ -650,6 +661,6 @@ $ne: (query, data) => data.valueOf() !== query.valueOf(),

return query.test(data);
} else if (typeof query === "string" || typeof query === "number" || query instanceof Date) {
} else if (isPlain(query)) {
return data.valueOf() === query.valueOf();
} else if ((0, import_cosmokit4.isNullable)(query)) {
return (0, import_cosmokit4.isNullable)(data);
} else if ((0, import_cosmokit5.isNullable)(query)) {
return (0, import_cosmokit5.isNullable)(data);
}

@@ -700,4 +711,5 @@ for (const key in query) {

executeUpdate,
isEvalExpr
isEvalExpr,
isPlain
});
//# sourceMappingURL=node.js.map
import { Extract } from 'cosmokit';
import { Eval } from './eval';
import { Comparable, Indexable } from './utils';
import { Comparable, Indexable, Plain } from './utils';
import { Selection } from './selection';

@@ -14,4 +14,4 @@ export declare type Query<T = any> = Query.Expr<T> | Query.Shorthand<Indexable> | Selection.Callback<T, boolean>;

$nin?: Extract<T, Indexable, T[]>;
$eq?: Extract<T, Comparable>;
$ne?: Extract<T, Comparable>;
$eq?: Extract<T, Plain>;
$ne?: Extract<T, Plain>;
$gt?: Extract<T, Comparable>;

@@ -18,0 +18,0 @@ $gte?: Extract<T, Comparable>;

@@ -6,3 +6,3 @@ import { Dict } from 'cosmokit';

import { Query } from './query';
import { Common, Keys } from './utils';
import { Plain, Keys } from './utils';
export declare type Direction = 'asc' | 'desc';

@@ -48,3 +48,3 @@ export interface Modifier {

type Row<S> = {
[K in keyof S]: Eval.Expr<S[K]> & (S[K] extends Common ? {} : Row<S[K]>);
[K in keyof S]: Eval.Expr<S[K]> & (S[K] extends Plain ? {} : Row<S[K]>);
};

@@ -51,0 +51,0 @@ type Yield<S, T> = T | ((row: Row<S>) => T);

@@ -9,3 +9,3 @@ import { Intersect } from 'cosmokit';

export declare type Comparable = string | number | Date;
export declare type Common = string | number | boolean | Date;
export declare type Plain = string | number | boolean | Date;
declare type FlatWrap<S, T, P extends string> = {

@@ -18,2 +18,3 @@ [K in P]?: S;

export declare type Flatten<S> = Intersect<FlatMap<S>>;
export declare function isPlain(value: any): boolean;
export {};
{
"name": "minato",
"version": "1.0.10",
"version": "1.1.0",
"description": "Type Driven Database Framework",

@@ -5,0 +5,0 @@ "main": "lib/node.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc