@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.
package/dist/client/database.js
CHANGED
|
@@ -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.
|
|
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
|
|
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.
|
|
5
|
-
"canary_version": "0.0.0-canary.
|
|
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": {
|
package/src/client/database.js
CHANGED
|
@@ -137,11 +137,11 @@ class Database {
|
|
|
137
137
|
|
|
138
138
|
// NOTE: Admin method delegations to client
|
|
139
139
|
async stats() {
|
|
140
|
-
return this.client.
|
|
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
|
|
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
|
};
|