kinetic-sql 1.0.4 → 1.1.8

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/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var N=Object.create;var d=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var L=(s,e)=>{for(var t in e)d(s,t,{get:e[t],enumerable:!0})},R=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of C(e))!_.call(s,i)&&i!==t&&d(s,i,{get:()=>e[i],enumerable:!(r=I(e,i))||r.enumerable});return s};var u=(s,e,t)=>(t=s!=null?N(D(s)):{},R(e||!s||!s.__esModule?d(t,"default",{value:s,enumerable:!0}):t,s)),$=s=>R(d({},"__esModule",{value:!0}),s);var x={};L(x,{KineticClient:()=>g,KineticError:()=>o,and:()=>a.and,asc:()=>a.asc,desc:()=>a.desc,eq:()=>a.eq,or:()=>a.or,sql:()=>a.sql});module.exports=$(x);var o=class s extends Error{code;details;constructor(e,t,r){super(t),this.name="KineticError",this.code=e,this.details=r,Object.setPrototypeOf(this,s.prototype)}};var S=u(require("better-sqlite3"),1),y=class{db;subscribers=new Map;constructor(e){let t=":memory:";typeof e.connectionString=="string"?t=e.connectionString.replace(/^sqlite:\/\//,""):e.filename&&(t=e.filename),this.db=new S.default(t,e.options||{})}get raw(){return this.db}async init(){this.db.function("kinetic_bridge",(e,t,r)=>{this.handleEvent(e,t,r)})}handleEvent(e,t,r){let i=this.subscribers.get(e);if(!(!i||i.length===0))try{let n=null;t!=="DELETE"&&(n=this.db.prepare(`SELECT * FROM ${e} WHERE rowid = ?`).get(r));let l={action:t,data:n};i.forEach(p=>p(l))}catch(n){console.error(`\u26A0\uFE0F Kinetic SQLite: Failed to bridge event for ${e}`,n)}}async subscribe(e,t){return this.subscribers.has(e)||(this.subscribers.set(e,[]),this.attachTriggers(e)),this.subscribers.get(e).push(t),{unsubscribe:()=>{let r=this.subscribers.get(e);if(r){let i=r.indexOf(t);i>-1&&r.splice(i,1)}}}}attachTriggers(e){try{this.db.exec(`
1
+ "use strict";var w=Object.create;var d=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var $=(s,e)=>{for(var t in e)d(s,t,{get:e[t],enumerable:!0})},R=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of C(e))!L.call(s,i)&&i!==t&&d(s,i,{get:()=>e[i],enumerable:!(r=I(e,i))||r.enumerable});return s};var u=(s,e,t)=>(t=s!=null?w(D(s)):{},R(e||!s||!s.__esModule?d(t,"default",{value:s,enumerable:!0}):t,s)),_=s=>R(d({},"__esModule",{value:!0}),s);var A={};$(A,{KineticClient:()=>g,KineticError:()=>o,and:()=>a.and,asc:()=>a.asc,desc:()=>a.desc,eq:()=>a.eq,or:()=>a.or,sql:()=>a.sql});module.exports=_(A);var o=class s extends Error{code;details;constructor(e,t,r){super(t),this.name="KineticError",this.code=e,this.details=r,Object.setPrototypeOf(this,s.prototype)}};var f=u(require("better-sqlite3"),1),h=class{db;subscribers=new Map;constructor(e){let t=":memory:";typeof e.connectionString=="string"?t=e.connectionString.replace(/^sqlite:\/\//,""):e.filename&&(t=e.filename),this.db=new f.default(t,e.options||{})}get raw(){return this.db}async init(){this.db.function("kinetic_bridge",(e,t,r)=>{this.handleEvent(e,t,r)})}handleEvent(e,t,r){console.log("\u{1F7E2} 1. BRIDGE CALLED:",e,t,r);let i=this.subscribers.get(e);if(!i||i.length===0){console.log(`\u{1F534} No subscribers for table ${e}`);return}try{if(t==="DELETE"){let n={action:t,data:{rowid:r}};i.forEach(c=>c(n));return}setImmediate(()=>{console.log(`\u{1F7E1} Fetching fresh row for ${e} with rowid ${r}`);try{let n=this.db.prepare(`SELECT * FROM ${e} WHERE rowid = ?`).get(r);if(n){let c={action:t,data:n};i.forEach(p=>p(c))}}catch(n){console.error(`\u26A0\uFE0F Kinetic SQLite: Async fetch failed for ${e}`,n)}})}catch(n){console.error(`\u26A0\uFE0F Kinetic SQLite: Failed to bridge event for ${e}`,n)}}async subscribe(e,t){return this.subscribers.has(e)||(this.subscribers.set(e,[]),this.attachTriggers(e)),this.subscribers.get(e).push(t),{unsubscribe:()=>{let r=this.subscribers.get(e);if(r){let i=r.indexOf(t);i>-1&&r.splice(i,1)}}}}attachTriggers(e){try{this.db.exec(`
2
2
  CREATE TRIGGER IF NOT EXISTS kinetic_${e}_insert AFTER INSERT ON ${e}
3
3
  BEGIN
4
4
  SELECT kinetic_bridge('${e}', 'INSERT', NEW.rowid);
@@ -13,7 +13,7 @@
13
13
  BEGIN
14
14
  SELECT kinetic_bridge('${e}', 'DELETE', OLD.rowid);
15
15
  END;
16
- `)}catch(t){console.warn(`\u26A0\uFE0F Kinetic SQLite: Could not attach triggers to ${e}. Ensure table exists.`,t)}}async rpc(e,t){try{let i=Object.keys(t||{}).map(()=>"?").join(","),n=Object.values(t||{});return{data:this.db.prepare(`SELECT ${e}(${i})`).all(...n),error:null}}catch(r){return{data:null,error:r}}}async end(){this.db.close()}};var f=u(require("mysql2/promise"),1),b=u(require("@rodrigogs/mysql-events"),1);var m=class{pool;instance=null;subscribers=new Map;config;constructor(e){this.config=e,this.pool=f.default.createPool({host:e.host,user:e.user,password:e.password,database:e.database,port:e.port||3306,waitForConnections:!0,connectionLimit:e.poolSize||10,queueLimit:0})}get raw(){return this.pool}async init(){if(!this.config.realtimeEnabled)return;let e={host:this.config.host,user:this.config.user,password:this.config.password,port:this.config.port||3306};this.instance=new b.default(e,{startAtEnd:!0,excludedSchemas:{mysql:!0,sys:!0,information_schema:!0,performance_schema:!0}}),await this.instance.start(),this.instance.addTrigger({name:"KINETIC_EVENTS",expression:"*",statement:b.default.STATEMENTS.ALL,onEvent:t=>{if(t.schema===this.config.database&&this.subscribers.has(t.table)){let r=this.subscribers.get(t.table);r&&t.rows.forEach(i=>{r({action:t.type,data:i})})}}}),this.instance.on("error",t=>console.error("MySQL Realtime Error:",t))}async subscribe(e,t){if(!this.config.realtimeEnabled)throw new o("CONFIG_ERROR","Realtime is disabled. Set { realtimeEnabled: true } in config.");return this.subscribers.set(e,t),{unsubscribe:()=>{this.subscribers.delete(e)}}}async rpc(e,t){try{let r=Object.values(t||{}),i=r.map(()=>"?").join(", "),[n]=await this.pool.execute(`CALL ${e}(${i})`,r);return{data:n,error:null}}catch(r){return{data:null,error:new o("RPC_ERROR",`MySQL RPC Failed: ${e}`,r)}}}async end(){this.instance&&await this.instance.stop(),await this.pool.end()}};var E=u(require("postgres"),1);var T=`
16
+ `)}catch(t){console.warn(`\u26A0\uFE0F Kinetic SQLite: Could not attach triggers to ${e}. Ensure table exists.`,t)}}async rpc(e,t){try{let i=Object.keys(t||{}).map(()=>"?").join(","),n=Object.values(t||{});return{data:this.db.prepare(`SELECT ${e}(${i})`).all(...n),error:null}}catch(r){return{data:null,error:r}}}async end(){this.db.close()}};var S=u(require("mysql2/promise"),1),b=u(require("@rodrigogs/mysql-events"),1);var y=class{pool;instance=null;subscribers=new Map;config;constructor(e){this.config=e,this.pool=S.default.createPool({host:e.host,user:e.user,password:e.password,database:e.database,port:e.port||3306,waitForConnections:!0,connectionLimit:e.poolSize||10,queueLimit:0})}get raw(){return this.pool}async init(){if(!this.config.realtimeEnabled)return;let e={host:this.config.host,user:this.config.user,password:this.config.password,port:this.config.port||3306};this.instance=new b.default(e,{startAtEnd:!0,excludedSchemas:{mysql:!0,sys:!0,information_schema:!0,performance_schema:!0}}),await this.instance.start(),this.instance.addTrigger({name:"KINETIC_EVENTS",expression:"*",statement:b.default.STATEMENTS.ALL,onEvent:t=>{if(t.schema===this.config.database&&this.subscribers.has(t.table)){let r=this.subscribers.get(t.table);r&&t.rows.forEach(i=>{r({action:t.type,data:i})})}}}),this.instance.on("error",t=>console.error("MySQL Realtime Error:",t))}async subscribe(e,t){if(!this.config.realtimeEnabled)throw new o("CONFIG_ERROR","Realtime is disabled. Set { realtimeEnabled: true } in config.");return this.subscribers.set(e,t),{unsubscribe:()=>{this.subscribers.delete(e)}}}async rpc(e,t){try{let r=Object.values(t||{}),i=r.map(()=>"?").join(", "),[n]=await this.pool.execute(`CALL ${e}(${i})`,r);return{data:n,error:null}}catch(r){return{data:null,error:new o("RPC_ERROR",`MySQL RPC Failed: ${e}`,r)}}}async end(){this.instance&&await this.instance.stop(),await this.pool.end()}};var E=u(require("postgres"),1);var T=`
17
17
  CREATE OR REPLACE FUNCTION notify_changes() RETURNS TRIGGER AS $$
18
18
  DECLARE
19
19
  payload json;
@@ -35,4 +35,4 @@ BEGIN
35
35
  FOR EACH ROW EXECUTE FUNCTION notify_changes();
36
36
  END IF;
37
37
  END
38
- $$;`;var h=class{sql;config;realtimeEnabled;constructor(e){if(this.config=e,this.realtimeEnabled=e.realtimeEnabled||!1,typeof e.connectionString=="string")this.sql=(0,E.default)(e.connectionString,{max:e.poolSize||10});else{let{type:t,realtimeEnabled:r,poolSize:i,...n}=e;this.sql=(0,E.default)({...n,max:i||10})}}get raw(){return this.sql}async init(){if(this.realtimeEnabled)try{await this.sql.unsafe(T)}catch(e){console.warn("\u26A0\uFE0F Kinetic Driver: Failed to install generic broadcast function.",e)}}async rpc(e,t){try{let r=Object.values(t||{}),n=Object.keys(t||{}).map((O,w)=>`${O} := $${w+1}`).join(", "),l=`SELECT * FROM "${e}"(${n})`;return{data:await this.sql.unsafe(l,r),error:null}}catch(r){return{data:null,error:new o("RPC_ERROR",`Failed to execute function: ${e}`,r)}}}async subscribe(e,t){if(!this.realtimeEnabled)throw new o("CONFIG_ERROR","Realtime is disabled in config.");try{await this.sql.unsafe(v(e))}catch(i){console.error(`Failed to attach trigger to ${e}`,i)}let r;if(typeof this.config.connectionString=="string")r=(0,E.default)(this.config.connectionString,{max:1});else{let{type:i,realtimeEnabled:n,poolSize:l,...p}=this.config;r=(0,E.default)({...p,max:1})}return r.listen("table_events",i=>{let n=JSON.parse(i);n.table===e&&t(n)}).catch(i=>console.error("Listener error:",i)),{unsubscribe:async()=>{await r.end()}}}async end(){await this.sql.end()}};var g=class s{constructor(e){this.config=e;if(e.type==="pg")this.driver=new h(e);else if(e.type==="mysql")this.driver=new m(e);else if(e.type==="sqlite")this.driver=new y(e);else throw new o("CONFIG_ERROR",`Unsupported DB type: ${e.type}`)}driver;static async create(e){let t=new s(e);return await t.init(),t}async init(){await this.driver.init()}async rpc(e,t){return this.driver.rpc(e,t)}async subscribe(e,t){return this.driver.subscribe(e,t)}get raw(){return this.driver.raw}};var a=require("drizzle-orm");0&&(module.exports={KineticClient,KineticError,and,asc,desc,eq,or,sql});
38
+ $$;`;var m=class{sql;config;realtimeEnabled;constructor(e){if(this.config=e,this.realtimeEnabled=e.realtimeEnabled||!1,typeof e.connectionString=="string")this.sql=(0,E.default)(e.connectionString,{max:e.poolSize||10});else{let{type:t,realtimeEnabled:r,poolSize:i,...n}=e;this.sql=(0,E.default)({...n,max:i||10})}}get raw(){return this.sql}async init(){if(this.realtimeEnabled)try{await this.sql.unsafe(T)}catch(e){console.warn("\u26A0\uFE0F Kinetic Driver: Failed to install generic broadcast function.",e)}}async rpc(e,t){try{let r=Object.values(t||{}),n=Object.keys(t||{}).map((O,N)=>`${O} := $${N+1}`).join(", "),c=`SELECT * FROM "${e}"(${n})`;return{data:await this.sql.unsafe(c,r),error:null}}catch(r){return{data:null,error:new o("RPC_ERROR",`Failed to execute function: ${e}`,r)}}}async subscribe(e,t){if(!this.realtimeEnabled)throw new o("CONFIG_ERROR","Realtime is disabled in config.");try{await this.sql.unsafe(v(e))}catch(i){console.error(`Failed to attach trigger to ${e}`,i)}let r;if(typeof this.config.connectionString=="string")r=(0,E.default)(this.config.connectionString,{max:1});else{let{type:i,realtimeEnabled:n,poolSize:c,...p}=this.config;r=(0,E.default)({...p,max:1})}return r.listen("table_events",i=>{let n=JSON.parse(i);n.table===e&&t(n)}).catch(i=>console.error("Listener error:",i)),{unsubscribe:async()=>{await r.end()}}}async end(){await this.sql.end()}};var g=class s{constructor(e){this.config=e;if(e.type==="pg")this.driver=new m(e);else if(e.type==="mysql")this.driver=new y(e);else if(e.type==="sqlite")this.driver=new h(e);else throw new o("CONFIG_ERROR",`Unsupported DB type: ${e.type}`)}driver;static async create(e){let t=new s(e);return await t.init(),t}async init(){await this.driver.init()}async rpc(e,t){return this.driver.rpc(e,t)}async subscribe(e,t){return this.driver.subscribe(e,t)}get raw(){return this.driver.raw}};var a=require("drizzle-orm");0&&(module.exports={KineticClient,KineticError,and,asc,desc,eq,or,sql});
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var a=class n extends Error{code;details;constructor(e,t,r){super(t),this.name="KineticError",this.code=e,this.details=r,Object.setPrototypeOf(this,n.prototype)}};import f from"better-sqlite3";var E=class{db;subscribers=new Map;constructor(e){let t=":memory:";typeof e.connectionString=="string"?t=e.connectionString.replace(/^sqlite:\/\//,""):e.filename&&(t=e.filename),this.db=new f(t,e.options||{})}get raw(){return this.db}async init(){this.db.function("kinetic_bridge",(e,t,r)=>{this.handleEvent(e,t,r)})}handleEvent(e,t,r){let i=this.subscribers.get(e);if(!(!i||i.length===0))try{let s=null;t!=="DELETE"&&(s=this.db.prepare(`SELECT * FROM ${e} WHERE rowid = ?`).get(r));let l={action:t,data:s};i.forEach(p=>p(l))}catch(s){console.error(`\u26A0\uFE0F Kinetic SQLite: Failed to bridge event for ${e}`,s)}}async subscribe(e,t){return this.subscribers.has(e)||(this.subscribers.set(e,[]),this.attachTriggers(e)),this.subscribers.get(e).push(t),{unsubscribe:()=>{let r=this.subscribers.get(e);if(r){let i=r.indexOf(t);i>-1&&r.splice(i,1)}}}}attachTriggers(e){try{this.db.exec(`
1
+ var a=class n extends Error{code;details;constructor(e,t,r){super(t),this.name="KineticError",this.code=e,this.details=r,Object.setPrototypeOf(this,n.prototype)}};import S from"better-sqlite3";var E=class{db;subscribers=new Map;constructor(e){let t=":memory:";typeof e.connectionString=="string"?t=e.connectionString.replace(/^sqlite:\/\//,""):e.filename&&(t=e.filename),this.db=new S(t,e.options||{})}get raw(){return this.db}async init(){this.db.function("kinetic_bridge",(e,t,r)=>{this.handleEvent(e,t,r)})}handleEvent(e,t,r){console.log("\u{1F7E2} 1. BRIDGE CALLED:",e,t,r);let i=this.subscribers.get(e);if(!i||i.length===0){console.log(`\u{1F534} No subscribers for table ${e}`);return}try{if(t==="DELETE"){let s={action:t,data:{rowid:r}};i.forEach(o=>o(s));return}setImmediate(()=>{console.log(`\u{1F7E1} Fetching fresh row for ${e} with rowid ${r}`);try{let s=this.db.prepare(`SELECT * FROM ${e} WHERE rowid = ?`).get(r);if(s){let o={action:t,data:s};i.forEach(p=>p(o))}}catch(s){console.error(`\u26A0\uFE0F Kinetic SQLite: Async fetch failed for ${e}`,s)}})}catch(s){console.error(`\u26A0\uFE0F Kinetic SQLite: Failed to bridge event for ${e}`,s)}}async subscribe(e,t){return this.subscribers.has(e)||(this.subscribers.set(e,[]),this.attachTriggers(e)),this.subscribers.get(e).push(t),{unsubscribe:()=>{let r=this.subscribers.get(e);if(r){let i=r.indexOf(t);i>-1&&r.splice(i,1)}}}}attachTriggers(e){try{this.db.exec(`
2
2
  CREATE TRIGGER IF NOT EXISTS kinetic_${e}_insert AFTER INSERT ON ${e}
3
3
  BEGIN
4
4
  SELECT kinetic_bridge('${e}', 'INSERT', NEW.rowid);
@@ -13,7 +13,7 @@ var a=class n extends Error{code;details;constructor(e,t,r){super(t),this.name="
13
13
  BEGIN
14
14
  SELECT kinetic_bridge('${e}', 'DELETE', OLD.rowid);
15
15
  END;
16
- `)}catch(t){console.warn(`\u26A0\uFE0F Kinetic SQLite: Could not attach triggers to ${e}. Ensure table exists.`,t)}}async rpc(e,t){try{let i=Object.keys(t||{}).map(()=>"?").join(","),s=Object.values(t||{});return{data:this.db.prepare(`SELECT ${e}(${i})`).all(...s),error:null}}catch(r){return{data:null,error:r}}}async end(){this.db.close()}};import T from"mysql2/promise";import m from"@rodrigogs/mysql-events";var d=class{pool;instance=null;subscribers=new Map;config;constructor(e){this.config=e,this.pool=T.createPool({host:e.host,user:e.user,password:e.password,database:e.database,port:e.port||3306,waitForConnections:!0,connectionLimit:e.poolSize||10,queueLimit:0})}get raw(){return this.pool}async init(){if(!this.config.realtimeEnabled)return;let e={host:this.config.host,user:this.config.user,password:this.config.password,port:this.config.port||3306};this.instance=new m(e,{startAtEnd:!0,excludedSchemas:{mysql:!0,sys:!0,information_schema:!0,performance_schema:!0}}),await this.instance.start(),this.instance.addTrigger({name:"KINETIC_EVENTS",expression:"*",statement:m.STATEMENTS.ALL,onEvent:t=>{if(t.schema===this.config.database&&this.subscribers.has(t.table)){let r=this.subscribers.get(t.table);r&&t.rows.forEach(i=>{r({action:t.type,data:i})})}}}),this.instance.on("error",t=>console.error("MySQL Realtime Error:",t))}async subscribe(e,t){if(!this.config.realtimeEnabled)throw new a("CONFIG_ERROR","Realtime is disabled. Set { realtimeEnabled: true } in config.");return this.subscribers.set(e,t),{unsubscribe:()=>{this.subscribers.delete(e)}}}async rpc(e,t){try{let r=Object.values(t||{}),i=r.map(()=>"?").join(", "),[s]=await this.pool.execute(`CALL ${e}(${i})`,r);return{data:s,error:null}}catch(r){return{data:null,error:new a("RPC_ERROR",`MySQL RPC Failed: ${e}`,r)}}}async end(){this.instance&&await this.instance.stop(),await this.pool.end()}};import u from"postgres";var h=`
16
+ `)}catch(t){console.warn(`\u26A0\uFE0F Kinetic SQLite: Could not attach triggers to ${e}. Ensure table exists.`,t)}}async rpc(e,t){try{let i=Object.keys(t||{}).map(()=>"?").join(","),s=Object.values(t||{});return{data:this.db.prepare(`SELECT ${e}(${i})`).all(...s),error:null}}catch(r){return{data:null,error:r}}}async end(){this.db.close()}};import T from"mysql2/promise";import y from"@rodrigogs/mysql-events";var d=class{pool;instance=null;subscribers=new Map;config;constructor(e){this.config=e,this.pool=T.createPool({host:e.host,user:e.user,password:e.password,database:e.database,port:e.port||3306,waitForConnections:!0,connectionLimit:e.poolSize||10,queueLimit:0})}get raw(){return this.pool}async init(){if(!this.config.realtimeEnabled)return;let e={host:this.config.host,user:this.config.user,password:this.config.password,port:this.config.port||3306};this.instance=new y(e,{startAtEnd:!0,excludedSchemas:{mysql:!0,sys:!0,information_schema:!0,performance_schema:!0}}),await this.instance.start(),this.instance.addTrigger({name:"KINETIC_EVENTS",expression:"*",statement:y.STATEMENTS.ALL,onEvent:t=>{if(t.schema===this.config.database&&this.subscribers.has(t.table)){let r=this.subscribers.get(t.table);r&&t.rows.forEach(i=>{r({action:t.type,data:i})})}}}),this.instance.on("error",t=>console.error("MySQL Realtime Error:",t))}async subscribe(e,t){if(!this.config.realtimeEnabled)throw new a("CONFIG_ERROR","Realtime is disabled. Set { realtimeEnabled: true } in config.");return this.subscribers.set(e,t),{unsubscribe:()=>{this.subscribers.delete(e)}}}async rpc(e,t){try{let r=Object.values(t||{}),i=r.map(()=>"?").join(", "),[s]=await this.pool.execute(`CALL ${e}(${i})`,r);return{data:s,error:null}}catch(r){return{data:null,error:new a("RPC_ERROR",`MySQL RPC Failed: ${e}`,r)}}}async end(){this.instance&&await this.instance.stop(),await this.pool.end()}};import u from"postgres";var m=`
17
17
  CREATE OR REPLACE FUNCTION notify_changes() RETURNS TRIGGER AS $$
18
18
  DECLARE
19
19
  payload json;
@@ -35,4 +35,4 @@ BEGIN
35
35
  FOR EACH ROW EXECUTE FUNCTION notify_changes();
36
36
  END IF;
37
37
  END
38
- $$;`;var y=class{sql;config;realtimeEnabled;constructor(e){if(this.config=e,this.realtimeEnabled=e.realtimeEnabled||!1,typeof e.connectionString=="string")this.sql=u(e.connectionString,{max:e.poolSize||10});else{let{type:t,realtimeEnabled:r,poolSize:i,...s}=e;this.sql=u({...s,max:i||10})}}get raw(){return this.sql}async init(){if(this.realtimeEnabled)try{await this.sql.unsafe(h)}catch(e){console.warn("\u26A0\uFE0F Kinetic Driver: Failed to install generic broadcast function.",e)}}async rpc(e,t){try{let r=Object.values(t||{}),s=Object.keys(t||{}).map((R,S)=>`${R} := $${S+1}`).join(", "),l=`SELECT * FROM "${e}"(${s})`;return{data:await this.sql.unsafe(l,r),error:null}}catch(r){return{data:null,error:new a("RPC_ERROR",`Failed to execute function: ${e}`,r)}}}async subscribe(e,t){if(!this.realtimeEnabled)throw new a("CONFIG_ERROR","Realtime is disabled in config.");try{await this.sql.unsafe(b(e))}catch(i){console.error(`Failed to attach trigger to ${e}`,i)}let r;if(typeof this.config.connectionString=="string")r=u(this.config.connectionString,{max:1});else{let{type:i,realtimeEnabled:s,poolSize:l,...p}=this.config;r=u({...p,max:1})}return r.listen("table_events",i=>{let s=JSON.parse(i);s.table===e&&t(s)}).catch(i=>console.error("Listener error:",i)),{unsubscribe:async()=>{await r.end()}}}async end(){await this.sql.end()}};var g=class n{constructor(e){this.config=e;if(e.type==="pg")this.driver=new y(e);else if(e.type==="mysql")this.driver=new d(e);else if(e.type==="sqlite")this.driver=new E(e);else throw new a("CONFIG_ERROR",`Unsupported DB type: ${e.type}`)}driver;static async create(e){let t=new n(e);return await t.init(),t}async init(){await this.driver.init()}async rpc(e,t){return this.driver.rpc(e,t)}async subscribe(e,t){return this.driver.subscribe(e,t)}get raw(){return this.driver.raw}};import{sql as V,eq as Y,desc as Z,asc as ee,and as te,or as re}from"drizzle-orm";export{g as KineticClient,a as KineticError,te as and,ee as asc,Z as desc,Y as eq,re as or,V as sql};
38
+ $$;`;var h=class{sql;config;realtimeEnabled;constructor(e){if(this.config=e,this.realtimeEnabled=e.realtimeEnabled||!1,typeof e.connectionString=="string")this.sql=u(e.connectionString,{max:e.poolSize||10});else{let{type:t,realtimeEnabled:r,poolSize:i,...s}=e;this.sql=u({...s,max:i||10})}}get raw(){return this.sql}async init(){if(this.realtimeEnabled)try{await this.sql.unsafe(m)}catch(e){console.warn("\u26A0\uFE0F Kinetic Driver: Failed to install generic broadcast function.",e)}}async rpc(e,t){try{let r=Object.values(t||{}),s=Object.keys(t||{}).map((R,f)=>`${R} := $${f+1}`).join(", "),o=`SELECT * FROM "${e}"(${s})`;return{data:await this.sql.unsafe(o,r),error:null}}catch(r){return{data:null,error:new a("RPC_ERROR",`Failed to execute function: ${e}`,r)}}}async subscribe(e,t){if(!this.realtimeEnabled)throw new a("CONFIG_ERROR","Realtime is disabled in config.");try{await this.sql.unsafe(b(e))}catch(i){console.error(`Failed to attach trigger to ${e}`,i)}let r;if(typeof this.config.connectionString=="string")r=u(this.config.connectionString,{max:1});else{let{type:i,realtimeEnabled:s,poolSize:o,...p}=this.config;r=u({...p,max:1})}return r.listen("table_events",i=>{let s=JSON.parse(i);s.table===e&&t(s)}).catch(i=>console.error("Listener error:",i)),{unsubscribe:async()=>{await r.end()}}}async end(){await this.sql.end()}};var g=class n{constructor(e){this.config=e;if(e.type==="pg")this.driver=new h(e);else if(e.type==="mysql")this.driver=new d(e);else if(e.type==="sqlite")this.driver=new E(e);else throw new a("CONFIG_ERROR",`Unsupported DB type: ${e.type}`)}driver;static async create(e){let t=new n(e);return await t.init(),t}async init(){await this.driver.init()}async rpc(e,t){return this.driver.rpc(e,t)}async subscribe(e,t){return this.driver.subscribe(e,t)}get raw(){return this.driver.raw}};import{sql as V,eq as Y,desc as Z,asc as ee,and as te,or as re}from"drizzle-orm";export{g as KineticClient,a as KineticError,te as and,ee as asc,Z as desc,Y as eq,re as or,V as sql};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kinetic-sql",
3
- "version": "1.0.4",
3
+ "version": "1.1.8",
4
4
  "description": "Zero-config, type-safe Postgres & MySQL client with Realtime subscriptions.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",