@joystick.js/db-canary 0.0.0-canary.2248 → 0.0.0-canary.2249
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
|
-
import{get_database as D,build_collection_key as A}from"../query_engine.js";import{can_use_index as J,find_documents_by_index as v}from"../index_manager.js";import{record_query as N,record_index_usage as F}from"../auto_index_manager.js";import S from"../logger.js";const{create_context_logger:R}=S("find"),C=(n,t)=>{const o=t.split(".");let r=n;for(const e of o){if(r==null)return;r=r[e]}return r},P=(n,t)=>{const o=t.split(".");let r=n;for(let e=0;e<o.length;e++){if(r==null||typeof r!="object")return!1;if(e===o.length-1)return r.hasOwnProperty(o[e]);r=r[o[e]]}return!1}
|
|
1
|
+
import{get_database as D,build_collection_key as A}from"../query_engine.js";import{can_use_index as J,find_documents_by_index as v}from"../index_manager.js";import{record_query as N,record_index_usage as F}from"../auto_index_manager.js";import S from"../logger.js";const{create_context_logger:R}=S("find"),C=(n,t)=>{const o=t.split(".");let r=n;for(const e of o){if(r==null)return;r=r[e]}return r},P=(n,t)=>{const o=t.split(".");let r=n;for(let e=0;e<o.length;e++){if(r==null||typeof r!="object")return!1;if(e===o.length-1)return r.hasOwnProperty(o[e]);r=r[o[e]]}return!1},$=(n,t)=>{if(!t||Object.keys(t).length===0)return!0;for(const[o,r]of Object.entries(t)){const e=C(n,o);if(typeof r=="object"&&r!==null&&!Array.isArray(r))for(const[i,s]of Object.entries(r))switch(i){case"$eq":if(e!==s)return!1;break;case"$ne":if(e===s)return!1;break;case"$gt":if(e<=s)return!1;break;case"$gte":if(e<s)return!1;break;case"$lt":if(e>=s)return!1;break;case"$lte":if(e>s)return!1;break;case"$in":if(!Array.isArray(s)||!s.includes(e))return!1;break;case"$nin":if(!Array.isArray(s)||s.includes(e))return!1;break;case"$exists":const c=P(n,o);if(s&&!c||!s&&c)return!1;break;case"$regex":const u=r.$options||"";if(!new RegExp(s,u).test(e))return!1;break;case"$options":break;default:throw new Error(`Unsupported query operator: ${i}`)}else if(e!==r)return!1}return!0},U=(n,t)=>{if(!t||Object.keys(t).length===0)return n;const o=Object.values(t).some(e=>e===1||e===!0),r={};if(o){r._id=n._id;for(const[e,i]of Object.entries(t))e==="_id"&&(i===0||i===!1)?delete r._id:(i===1||i===!0)&&(r[e]=n[e])}else{Object.assign(r,n);for(const[e,i]of Object.entries(t))(i===0||i===!1)&&delete r[e]}return r},z=(n,t)=>!t||Object.keys(t).length===0?n:n.sort((o,r)=>{for(const[e,i]of Object.entries(t)){const s=o[e],c=r[e];if(s===c)continue;if(s===void 0)return 1;if(c===void 0)return-1;const u=s<c?-1:s>c?1:0;return i===-1?-u:u}return 0}),B=async(n,t,o={},r={})=>{const e=R();if(!n)throw new Error("Database name is required");if(!t)throw new Error("Collection name is required");const i=D(),{projection:s,sort:c,limit:u,skip:h=0}=r,E=Date.now();try{let d=[],_=!1,k=null;const O=J(n,t,o);if(O){const{field:f,operators:b}=O,a=o[f];if(k=f,typeof a=="object"&&a!==null&&!Array.isArray(a)){for(const l of b)if(a[l]!==void 0){const p=v(n,t,f,l,a[l]);if(p){_=!0,F(n,t,f);for(const m of p){const x=A(n,t,m),y=i.get(x);if(y){const q=JSON.parse(y);$(q,o)&&d.push(q)}}break}}}else if(b.includes("eq")){const l=v(n,t,f,"eq",a);if(l){_=!0,F(n,t,f);for(const p of l){const m=A(n,t,p),x=i.get(m);if(x){const y=JSON.parse(x);$(y,o)&&d.push(y)}}}}}if(!_){const f=`${n}:${t}:`,b=i.getRange({start:f,end:f+"\xFF"});for(const{key:a,value:l}of b){const p=JSON.parse(l);$(p,o)&&d.push(p)}}let g=z(d,c);h>0&&(g=g.slice(h)),u&&u>0&&(g=g.slice(0,u));const j=g.map(f=>U(f,s)),w=Date.now()-E;try{N(t,o,w,_,k)}catch(f){e.warn("Failed to record query for auto-indexing",{error:f.message})}return e.info("Find operation completed",{database:n,collection:t,documents_found:j.length,total_matching:d.length,used_index:_,indexed_field:k,execution_time_ms:w}),j}catch(d){throw e.error("Failed to find documents",{database:n,collection:t,error:d.message}),d}};var L=B;export{L as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{get_database as A,build_collection_key as j}from"../query_engine.js";import{can_use_index as v,find_documents_by_index as m}from"../index_manager.js";import{record_query as D,record_index_usage as q}from"../auto_index_manager.js";import E from"../logger.js";const{create_context_logger:F}=E("find_one"),N=(o,t)=>{const n=t.split(".");let r=o;for(const e of n){if(r==null)return;r=r[e]}return r},J=(o,t)=>{const n=t.split(".");let r=o;for(let e=0;e<n.length;e++){if(r==null||typeof r!="object")return!1;if(e===n.length-1)return r.hasOwnProperty(n[e]);r=r[n[e]]}return!1},w=(o,t)=>{if(!t||Object.keys(t).length===0)return!0;for(const[n,r]of Object.entries(t)){const e=N(o,n);if(typeof r=="object"&&r!==null&&!Array.isArray(r))for(const[i,s]of Object.entries(r))switch(i){case"$eq":if(e!==s)return!1;break;case"$ne":if(e===s)return!1;break;case"$gt":if(e<=s)return!1;break;case"$gte":if(e<s)return!1;break;case"$lt":if(e>=s)return!1;break;case"$lte":if(e>s)return!1;break;case"$in":if(!Array.isArray(s)||!s.includes(e))return!1;break;case"$nin":if(!Array.isArray(s)||s.includes(e))return!1;break;case"$exists":const x=J(o,n);if(s&&!x||!s&&x)return!1;break;case"$regex":const b=r.$options||"";if(!new RegExp(s,b).test(e))return!1;break;default:throw new Error(`Unsupported query operator: ${i}`)}else if(e!==r)return!1}return!0},S=(o,t)=>{if(!t||Object.keys(t).length===0)return o;const n=Object.values(t).some(e=>e===1||e===!0),r={};if(n){r._id=o._id;for(const[e,i]of Object.entries(t))e==="_id"&&(i===0||i===!1)?delete r._id:(i===1||i===!0)&&(r[e]=o[e])}else{Object.assign(r,o);for(const[e,i]of Object.entries(t))(i===0||i===!1)&&delete r[e]}return r},R=async(o,t,n={},r={})=>{const e=F();if(!o)throw new Error("Database name is required");if(!t)throw new Error("Collection name is required");const i=A(),{projection:s,sort:x}=r,b=Date.now();try{let c=null,a=!1,_=null;const O=v(o,t,n);if(O){const{field:f,operators:g}=O,d=n[f];if(_=f,typeof d=="object"&&d!==null&&!Array.isArray(d)){for(const u of g)if(d[u]!==void 0){const l=m(o,t,f,u,d[u]);if(l&&l.length>0){a=!0,q(o,t,f);for(const h of l){const y=j(o,t,h),p=i.get(y);if(p)try{const $=JSON.parse(p);if(w($,n)){c=$;break}}catch{continue}}break}}}else if(g.includes("eq")){const u=m(o,t,f,"eq",d);if(u&&u.length>0){a=!0,q(o,t,f);for(const l of u){const h=j(o,t,l),y=i.get(h);if(y)try{const p=JSON.parse(y);if(w(p,n)){c=p;break}}catch{continue}}}}}if(!a){const f=`${o}:${t}:`,g=i.getRange({start:f,end:f+"\xFF"});for(const{key:d,value:u}of g)try{const l=JSON.parse(u);if(w(l,n)){c=l;break}}catch{continue}}const k=Date.now()-b;try{D(t,n,k,a,_)}catch(f){e.warn("Failed to record query for auto-indexing",{error:f.message})}if(c){const f=S(c,s);return e.info("Document found",{database:o,collection:t,document_id:c._id,used_index:a,indexed_field:_,execution_time_ms:k}),f}return e.info("No document found",{database:o,collection:t,used_index:a,indexed_field:_,execution_time_ms:k}),null}catch(c){throw e.error("Failed to find document",{database:o,collection:t,error:c.message}),c}};var B=R;export{B as default};
|
|
1
|
+
import{get_database as A,build_collection_key as j}from"../query_engine.js";import{can_use_index as v,find_documents_by_index as m}from"../index_manager.js";import{record_query as D,record_index_usage as q}from"../auto_index_manager.js";import E from"../logger.js";const{create_context_logger:F}=E("find_one"),N=(o,t)=>{const n=t.split(".");let r=o;for(const e of n){if(r==null)return;r=r[e]}return r},J=(o,t)=>{const n=t.split(".");let r=o;for(let e=0;e<n.length;e++){if(r==null||typeof r!="object")return!1;if(e===n.length-1)return r.hasOwnProperty(n[e]);r=r[n[e]]}return!1},w=(o,t)=>{if(!t||Object.keys(t).length===0)return!0;for(const[n,r]of Object.entries(t)){const e=N(o,n);if(typeof r=="object"&&r!==null&&!Array.isArray(r))for(const[i,s]of Object.entries(r))switch(i){case"$eq":if(e!==s)return!1;break;case"$ne":if(e===s)return!1;break;case"$gt":if(e<=s)return!1;break;case"$gte":if(e<s)return!1;break;case"$lt":if(e>=s)return!1;break;case"$lte":if(e>s)return!1;break;case"$in":if(!Array.isArray(s)||!s.includes(e))return!1;break;case"$nin":if(!Array.isArray(s)||s.includes(e))return!1;break;case"$exists":const x=J(o,n);if(s&&!x||!s&&x)return!1;break;case"$regex":const b=r.$options||"";if(!new RegExp(s,b).test(e))return!1;break;case"$options":break;default:throw new Error(`Unsupported query operator: ${i}`)}else if(e!==r)return!1}return!0},S=(o,t)=>{if(!t||Object.keys(t).length===0)return o;const n=Object.values(t).some(e=>e===1||e===!0),r={};if(n){r._id=o._id;for(const[e,i]of Object.entries(t))e==="_id"&&(i===0||i===!1)?delete r._id:(i===1||i===!0)&&(r[e]=o[e])}else{Object.assign(r,o);for(const[e,i]of Object.entries(t))(i===0||i===!1)&&delete r[e]}return r},R=async(o,t,n={},r={})=>{const e=F();if(!o)throw new Error("Database name is required");if(!t)throw new Error("Collection name is required");const i=A(),{projection:s,sort:x}=r,b=Date.now();try{let c=null,a=!1,_=null;const O=v(o,t,n);if(O){const{field:f,operators:g}=O,d=n[f];if(_=f,typeof d=="object"&&d!==null&&!Array.isArray(d)){for(const u of g)if(d[u]!==void 0){const l=m(o,t,f,u,d[u]);if(l&&l.length>0){a=!0,q(o,t,f);for(const h of l){const y=j(o,t,h),p=i.get(y);if(p)try{const $=JSON.parse(p);if(w($,n)){c=$;break}}catch{continue}}break}}}else if(g.includes("eq")){const u=m(o,t,f,"eq",d);if(u&&u.length>0){a=!0,q(o,t,f);for(const l of u){const h=j(o,t,l),y=i.get(h);if(y)try{const p=JSON.parse(y);if(w(p,n)){c=p;break}}catch{continue}}}}}if(!a){const f=`${o}:${t}:`,g=i.getRange({start:f,end:f+"\xFF"});for(const{key:d,value:u}of g)try{const l=JSON.parse(u);if(w(l,n)){c=l;break}}catch{continue}}const k=Date.now()-b;try{D(t,n,k,a,_)}catch(f){e.warn("Failed to record query for auto-indexing",{error:f.message})}if(c){const f=S(c,s);return e.info("Document found",{database:o,collection:t,document_id:c._id,used_index:a,indexed_field:_,execution_time_ms:k}),f}return e.info("No document found",{database:o,collection:t,used_index:a,indexed_field:_,execution_time_ms:k}),null}catch(c){throw e.error("Failed to find document",{database:o,collection:t,error:c.message}),c}};var B=R;export{B as default};
|
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.2249",
|
|
5
|
+
"canary_version": "0.0.0-canary.2248",
|
|
6
6
|
"description": "JoystickDB - A minimalist database server for the Joystick framework",
|
|
7
7
|
"main": "./dist/server/index.js",
|
|
8
8
|
"scripts": {
|
|
@@ -110,6 +110,9 @@ const matches_filter = (document, filter) => {
|
|
|
110
110
|
const regex = new RegExp(operand, regex_options);
|
|
111
111
|
if (!regex.test(field_value)) return false;
|
|
112
112
|
break;
|
|
113
|
+
case '$options':
|
|
114
|
+
// $options is handled as part of $regex, skip it here
|
|
115
|
+
break;
|
|
113
116
|
default:
|
|
114
117
|
throw new Error(`Unsupported query operator: ${operator}`);
|
|
115
118
|
}
|
|
@@ -111,6 +111,9 @@ const matches_filter = (document, filter) => {
|
|
|
111
111
|
const regex = new RegExp(operand, regex_options);
|
|
112
112
|
if (!regex.test(field_value)) return false;
|
|
113
113
|
break;
|
|
114
|
+
case '$options':
|
|
115
|
+
// $options is handled as part of $regex, skip it here
|
|
116
|
+
break;
|
|
114
117
|
default:
|
|
115
118
|
throw new Error(`Unsupported query operator: ${operator}`);
|
|
116
119
|
}
|