@joystick.js/db-canary 0.0.0-canary.2254 → 0.0.0-canary.2256

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.
@@ -1 +1 @@
1
- const r=(c,t,e={})=>({admin_action:c,database:t,...e}),n=(c,t,e,s={})=>({admin_action:c,database:t,collection:e,...s}),a=async(c,t)=>c.send_request("admin",t);class _{constructor(t,e){this.client=t,this.database_name=e}collection(t){const e=this.client.constructor.Collection;return new e(this.client,this.database_name,t)}async list_collections(){const t=r("list_collections",this.database_name);return a(this.client,t)}async get_stats(){const t=r("get_database_stats",this.database_name);return a(this.client,t)}async drop_database(){const t=r("drop_database",this.database_name);return a(this.client,t)}async create_collection(t,e={}){const s=n("create_collection",this.database_name,t,{options:e});return a(this.client,s)}async list_documents(t){const e=n("list_documents",this.database_name,t);return a(this.client,e)}async get_document(t,e){const s=n("get_document",this.database_name,t,{document_id:e});return a(this.client,s)}async query_documents(t,e){const s=n("query_documents",this.database_name,t,{filter:e});return a(this.client,s)}async insert_document(t,e){const s=n("insert_document",this.database_name,t,{document:e});return a(this.client,s)}async update_document(t,e,s){const i=n("update_document",this.database_name,t,{document_id:e,update:s});return a(this.client,i)}async delete_document(t,e){const s=n("delete_document",this.database_name,t,{document_id:e});return a(this.client,s)}async stats(){return this.client.get_stats()}async ping(){return this.client.ping()}async backup_now(){return this.client.backup_now()}async list_backups(){return this.client.list_backups()}async restore_backup(t){return this.client.restore_backup(t)}async get_replication_status(){return this.client.get_replication_status()}async add_secondary(t){return this.client.add_secondary(t)}async remove_secondary(t){return this.client.remove_secondary(t)}async sync_secondaries(){return this.client.sync_secondaries()}async get_secondary_health(){return this.client.get_secondary_health()}async get_forwarder_status(){return this.client.get_forwarder_status()}async get_auto_index_stats(){return this.client.get_auto_index_stats()}async reload(){return this.client.reload()}}var o=_;export{o as default};
1
+ const r=(c,t,e={})=>({admin_action:c,database:t,...e}),n=(c,t,e,s={})=>({admin_action:c,database:t,collection:e,...s}),a=async(c,t)=>c.send_request("admin",t);class _{constructor(t,e){this.client=t,this.database_name=e}collection(t){const e=this.client.constructor.Collection;return new e(this.client,this.database_name,t)}async list_collections(){const t=r("list_collections",this.database_name);return a(this.client,t)}async get_stats(){const t=r("get_database_stats",this.database_name);return a(this.client,t)}async drop_database(){const t=r("drop_database",this.database_name);return a(this.client,t)}async create_collection(t,e={}){const s=n("create_collection",this.database_name,t,{options:e});return a(this.client,s)}async list_documents(t){const e=n("list_documents",this.database_name,t);return a(this.client,e)}async get_document(t,e){const s=n("get_document",this.database_name,t,{document_id:e});return a(this.client,s)}async query_documents(t,e){const s=n("query_documents",this.database_name,t,{filter:e});return a(this.client,s)}async insert_document(t,e){const s=n("insert_document",this.database_name,t,{document:e});return a(this.client,s)}async update_document(t,e,s){const i=n("update_document",this.database_name,t,{document_id:e,update:s});return a(this.client,i)}async delete_document(t,e){const s=n("delete_document",this.database_name,t,{document_id:e});return a(this.client,s)}async stats(){return this.client.send_request("admin",{admin_action:"stats"})}async ping(){return this.client.send_request("ping",{},!1)}async backup_now(){return this.client.backup_now()}async list_backups(){return this.client.list_backups()}async restore_backup(t){return this.client.restore_backup(t)}async get_replication_status(){return this.client.get_replication_status()}async add_secondary(t){return this.client.add_secondary(t)}async remove_secondary(t){return this.client.remove_secondary(t)}async sync_secondaries(){return this.client.sync_secondaries()}async get_secondary_health(){return this.client.get_secondary_health()}async get_forwarder_status(){return this.client.get_forwarder_status()}async get_auto_index_stats(){return this.client.get_auto_index_stats()}async reload(){return this.client.reload()}}var d=_;export{d as default};
@@ -1 +1 @@
1
- import{encode_message as f}from"./tcp_protocol.js";import{get_write_forwarder as w}from"./write_forwarder.js";import{get_replication_manager as h}from"./replication_manager.js";import{check_and_grow_map_size as x}from"./query_engine.js";import{performance_monitor as v}from"./performance_monitor.js";import D from"./logger.js";import q from"./operations/insert_one.js";import A from"./operations/update_one.js";import b from"./operations/delete_one.js";import I from"./operations/delete_many.js";import $ from"./operations/bulk_write.js";import C from"./operations/find_one.js";import E from"./operations/find.js";import L from"./operations/create_index.js";import U from"./operations/drop_index.js";import Z from"./operations/get_indexes.js";import j from"./operations/admin.js";const{create_context_logger:d}=D("operation_dispatcher"),k=e=>e.length>64,B=e=>["admin","config","local"].includes(e.toLowerCase()),F=e=>/^[a-zA-Z0-9_-]+$/.test(e),G=e=>!e||typeof e!="string"||k(e)||B(e)?!1:F(e),H=()=>({ok:0,error:"Authentication required"}),J=()=>({ok:0,error:"Invalid database name. Database names must be alphanumeric with underscores/hyphens, max 64 characters, and cannot be reserved names (admin, config, local)."}),_=(e,r)=>{const o=f(r);e.write(o)},m=(e,r,o,s,t,n,c,i)=>{v.log_structured_operation(e,r,o,s,t,n,c,i)},g=(e,r,o,s,t,n,c,i,l=null)=>{const p={client_id:r,op:o,collection:s,duration_ms:t,status:n,request_size:c};n==="success"?(p.response_size=i,e.info("Database operation completed",p)):(p.error=l,e.error("Database operation failed",p))},K=async(e,r,o)=>{switch(e){case"insert_one":return await q(r,o.collection,o.document,o.options);case"update_one":return await A(r,o.collection,o.filter,o.update,o.options);case"delete_one":return await b(r,o.collection,o.filter,o.options);case"delete_many":return await I(r,o.collection,o.filter,o.options);case"bulk_write":return await $(r,o.collection,o.operations,o.options);case"find_one":return await C(r,o.collection,o.filter,o.options);case"find":return await E(r,o.collection,o.filter,o.options);case"create_index":return await L(r,o.collection,o.field,o.options);case"drop_index":return await U(r,o.collection,o.field);case"get_indexes":return await Z(r,o.collection);default:throw new Error(`Unsupported operation: ${e}`)}},M=(e,r)=>e==="find_one"?{ok:1,document:r}:e==="find"?{ok:1,documents:r}:{ok:1,...r},N=e=>!["find","find_one","get_indexes"].includes(e),O=(e,r)=>{if(!N(e))return;h().queue_replication(e,r.collection,r),setImmediate(()=>x())},P=(e,r,o,s,t,n)=>{const c=d(),i=Date.now()-t,l=M(r,s),u=f(l).length;_(e,l),m(e.id,r,o.collection,i,"success",null,n,u),g(c,e.id,r,o.collection,i,"success",n,u),O(r,o)},Q=(e,r,o,s,t,n)=>{const c=d(),i=Date.now()-t;m(e.id,r,o.collection,i,"error",s.message,n,0),g(c,e.id,r,o.collection,i,"error",n,0,s.message);const l={ok:0,error:s.message};_(e,l)},pe=async(e,r,o,s,t=0,n=null,c=null)=>{const i=Date.now();if(!s(e)){const a=H();_(e,a),m(e.id,r,null,0,"error","Authentication required",t,0);return}const l=o.database||"default";if(!G(l)){const a=J();_(e,a),m(e.id,r,o.collection,0,"error","Invalid database name",t,0);return}if(!await w().forward_operation(e,r,o))try{const a=await K(r,l,o);P(e,r,o,a,i,t)}catch(a){Q(e,r,o,a,i,t)}},R=()=>({ok:!1,error:"Authentication required"}),S=(e,r)=>e?{ok:1,...r}:{ok:!0,...r},T=e=>({ok:0,error:`Admin operation failed: ${e}`}),me=async(e,r,o,s=null,t=null)=>{if(!o(e)){const n=R();_(e,n);return}try{const n=r?.admin_action,i=await j(n,r||{},s,t),l=S(n,i);_(e,l)}catch(n){const c=T(n.message);_(e,c)}},ue=e=>{_(e,{ok:1})};export{me as handle_admin_operation,pe as handle_database_operation,ue as handle_ping_operation};
1
+ import{encode_message as f}from"./tcp_protocol.js";import{get_write_forwarder as g}from"./write_forwarder.js";import{get_replication_manager as h}from"./replication_manager.js";import{check_and_grow_map_size as x}from"./query_engine.js";import{performance_monitor as v}from"./performance_monitor.js";import D from"./logger.js";import q from"./operations/insert_one.js";import A from"./operations/update_one.js";import b from"./operations/delete_one.js";import I from"./operations/delete_many.js";import $ from"./operations/bulk_write.js";import C from"./operations/find_one.js";import E from"./operations/find.js";import L from"./operations/create_index.js";import U from"./operations/drop_index.js";import Z from"./operations/get_indexes.js";import j from"./operations/admin.js";const{create_context_logger:d}=D("operation_dispatcher"),k=e=>e.length>64,B=e=>["admin","config","local"].includes(e.toLowerCase()),F=e=>/^[a-zA-Z0-9_-]+$/.test(e),G=e=>!e||typeof e!="string"||k(e)||B(e)?!1:F(e),H=()=>({ok:0,error:"Authentication required"}),J=()=>({ok:0,error:"Invalid database name. Database names must be alphanumeric with underscores/hyphens, max 64 characters, and cannot be reserved names (admin, config, local)."}),_=(e,n)=>{const o=f(n);e.write(o)},p=(e,n,o,s,t,r,c,i)=>{v.log_structured_operation(e,n,o,s,t,r,c,i)},w=(e,n,o,s,t,r,c,i,l=null)=>{const m={client_id:n,op:o,collection:s,duration_ms:t,status:r,request_size:c};r==="success"?(m.response_size=i,e.info("Database operation completed",m)):(m.error=l,e.error("Database operation failed",m))},K=async(e,n,o)=>{switch(e){case"insert_one":return await q(n,o.collection,o.document,o.options);case"update_one":return await A(n,o.collection,o.filter,o.update,o.options);case"delete_one":return await b(n,o.collection,o.filter,o.options);case"delete_many":return await I(n,o.collection,o.filter,o.options);case"bulk_write":return await $(n,o.collection,o.operations,o.options);case"find_one":return await C(n,o.collection,o.filter,o.options);case"find":return await E(n,o.collection,o.filter,o.options);case"create_index":return await L(n,o.collection,o.field,o.options);case"drop_index":return await U(n,o.collection,o.field);case"get_indexes":return await Z(n,o.collection);default:throw new Error(`Unsupported operation: ${e}`)}},M=(e,n)=>e==="find_one"?{ok:1,document:n}:e==="find"?{ok:1,documents:n}:{ok:1,...n},N=e=>!["find","find_one","get_indexes"].includes(e),O=(e,n)=>{if(!N(e))return;h().queue_replication(e,n.collection,n),setImmediate(()=>x())},P=(e,n,o,s,t,r)=>{const c=d(),i=Date.now()-t,l=M(n,s),u=f(l).length;_(e,l),p(e.id,n,o.collection,i,"success",null,r,u),w(c,e.id,n,o.collection,i,"success",r,u),O(n,o)},Q=(e,n,o,s,t,r)=>{const c=d(),i=Date.now()-t;p(e.id,n,o.collection,i,"error",s.message,r,0),w(c,e.id,n,o.collection,i,"error",r,0,s.message);const l={ok:0,error:s.message};_(e,l)},me=async(e,n,o,s,t=0,r=null,c=null)=>{const i=Date.now();if(!s(e)){const a=H();_(e,a),p(e.id,n,null,0,"error","Authentication required",t,0);return}const l=o.database||"default";if(!G(l)){const a=J();_(e,a),p(e.id,n,o.collection,0,"error","Invalid database name",t,0);return}if(!await g().forward_operation(e,n,o))try{const a=await K(n,l,o);P(e,n,o,a,i,t)}catch(a){Q(e,n,o,a,i,t)}},R=()=>({ok:!1,error:"Authentication required"}),S=(e,n)=>e?{ok:1,...n}:{ok:!0,...n},T=e=>({ok:0,error:`Admin operation failed: ${e}`}),pe=async(e,n,o,s=null,t=null)=>{if(!o(e)){const r=R();_(e,r);return}try{const r=n?.admin_action,i=await j(r,n||{},s,t),l=S(r,i);_(e,l)}catch(r){const c=T(r.message);_(e,c)}},ue=e=>{const n=Date.now(),o={ok:1,response_time_ms:Date.now()-n};_(e,o)};export{pe as handle_admin_operation,me as handle_database_operation,ue as handle_ping_operation};
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@joystick.js/db-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.2254",
5
- "canary_version": "0.0.0-canary.2253",
4
+ "version": "0.0.0-canary.2256",
5
+ "canary_version": "0.0.0-canary.2255",
6
6
  "description": "JoystickDB - A minimalist database server for the Joystick framework",
7
7
  "main": "./dist/server/index.js",
8
8
  "scripts": {
@@ -137,11 +137,11 @@ class Database {
137
137
 
138
138
  // NOTE: Admin method delegations to client
139
139
  async stats() {
140
- return this.client.get_stats();
140
+ return this.client.send_request('admin', { admin_action: 'stats' });
141
141
  }
142
142
 
143
143
  async ping() {
144
- return this.client.ping();
144
+ return this.client.send_request('ping', {}, false);
145
145
  }
146
146
 
147
147
  async backup_now() {
@@ -439,6 +439,10 @@ export const handle_admin_operation = async (socket, data, check_authentication,
439
439
  * @param {net.Socket} socket - Client socket connection
440
440
  */
441
441
  export const handle_ping_operation = (socket) => {
442
- const ping_response = { ok: 1 };
442
+ const start_time = Date.now();
443
+ const ping_response = {
444
+ ok: 1,
445
+ response_time_ms: Date.now() - start_time
446
+ };
443
447
  send_encoded_response(socket, ping_response);
444
448
  };