mongosupa 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 meerkapp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # mongosupa
2
+
3
+ Translate MongoDB query syntax to Supabase JS queries.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install mongosupa
9
+ ```
10
+
11
+ Requires `@supabase/supabase-js` as peer dependency.
12
+
13
+ ## Usage
14
+
15
+ ```typescript
16
+ import { createClient } from '@supabase/supabase-js'
17
+ import { mongoToSupabase, createTranslator } from 'mongosupa'
18
+
19
+ const supabase = createClient(url, key)
20
+
21
+ const { data } = await mongoToSupabase(supabase, {
22
+ collection: 'users',
23
+ filter: { age: { $gte: 18 }, status: 'active' },
24
+ options: {
25
+ sort: { createdAt: -1 },
26
+ limit: 10,
27
+ select: ['id', 'name', 'email']
28
+ }
29
+ })
30
+
31
+ const query = createTranslator(supabase)
32
+
33
+ const { data: products } = await query({
34
+ collection: 'products',
35
+ filter: { price: { $lt: 100 } }
36
+ })
37
+ ```
38
+
39
+ ## Supported Operators
40
+
41
+ | MongoDB | Supabase |
42
+ |---------|----------|
43
+ | `$eq` | `.eq()` |
44
+ | `$ne` | `.neq()` |
45
+ | `$gt` | `.gt()` |
46
+ | `$gte` | `.gte()` |
47
+ | `$lt` | `.lt()` |
48
+ | `$lte` | `.lte()` |
49
+ | `$in` | `.in()` |
50
+ | `$nin` | `.not().in()` |
51
+ | `$regex` | `.ilike()` |
52
+ | `$exists` | `.is(null)` / `.not().is(null)` |
53
+ | `$and` | chained filters |
54
+ | `$or` | `.or()` |
55
+
56
+ ## Options
57
+
58
+ | Option | Description |
59
+ |--------|-------------|
60
+ | `collection` | Table name |
61
+ | `filter` | MongoDB-style filter object |
62
+ | `options.sort` | `{ field: -1 }` for desc, `{ field: 1 }` for asc |
63
+ | `options.limit` | Max rows |
64
+ | `options.skip` | Offset |
65
+ | `options.select` | `['field1', 'field2']` or `{ field1: 1, field2: 1 }` |
66
+
67
+ ## License
68
+
69
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var u=n=>typeof n!="object"||n===null||Array.isArray(n)?false:Object.keys(n).some(t=>t.startsWith("$")),$=n=>(typeof n=="string"?n:n.source).replace(/^\^/,"").replace(/\$$/,"").replace(/\.\*/g,"%").replace(/\./g,"_"),m=(n,t,o)=>{if(!u(o))return o===null?n.is(t,null):n.eq(t,o);let i=o;for(let[s,e]of Object.entries(i))switch(s){case "$eq":n=e===null?n.is(t,null):n.eq(t,e);break;case "$ne":n=e===null?n.not(t,"is",null):n.neq(t,e);break;case "$gt":n=n.gt(t,e);break;case "$gte":n=n.gte(t,e);break;case "$lt":n=n.lt(t,e);break;case "$lte":n=n.lte(t,e);break;case "$in":Array.isArray(e)&&(n=n.in(t,e));break;case "$nin":Array.isArray(e)&&(n=n.not(t,"in",`(${e.map(r=>typeof r=="string"?`"${r}"`:r).join(",")})`));break;case "$regex":n=n.ilike(t,`%${$(e)}%`);break;case "$exists":n=e?n.not(t,"is",null):n.is(t,null);break}return n},c=(n,t)=>{for(let[o,i]of Object.entries(t)){if(o==="$and"&&Array.isArray(i)){for(let s of i)n=c(n,s);continue}if(o==="$or"&&Array.isArray(i)){let s=i.map(e=>Object.entries(e).map(([r,l])=>u(l)?Object.entries(l).map(([g,a])=>{switch(g){case "$eq":return `${r}.eq.${a}`;case "$ne":return `${r}.neq.${a}`;case "$gt":return `${r}.gt.${a}`;case "$gte":return `${r}.gte.${a}`;case "$lt":return `${r}.lt.${a}`;case "$lte":return `${r}.lte.${a}`;case "$in":return `${r}.in.(${a.join(",")})`;default:return ""}}).filter(Boolean).join(","):l===null?`${r}.is.null`:`${r}.eq.${l}`).join(",")).join(",");n=n.or(s);continue}o.startsWith("$")||(n=m(n,o,i));}return n},p=(n,t)=>{for(let[o,i]of Object.entries(t))n=n.order(o,{ascending:i===1||i==="asc"});return n};function b(n,t){let{collection:o,filter:i,options:s}=t,e=s?.select?n.from(o).select(Array.isArray(s.select)?s.select.join(","):Object.entries(s.select).filter(([,r])=>r===1).map(([r])=>r).join(",")||"*"):n.from(o).select("*");if(i&&Object.keys(i).length>0&&(e=c(e,i)),s?.sort&&(e=p(e,s.sort)),s?.limit!==void 0&&(e=e.limit(s.limit)),s?.skip!==void 0){let r=s.skip,l=s.limit?r+s.limit-1:r+999;e=e.range(r,l);}return e}function B(n){return t=>b(n,t)}function j(n,t){return c(n,t)}exports.createTranslator=B;exports.mongoToSupabase=b;exports.translateFilter=j;
@@ -0,0 +1,44 @@
1
+ import { SupabaseClient as SupabaseClient$1 } from '@supabase/supabase-js';
2
+
3
+ interface ComparisonOperators {
4
+ $eq?: unknown;
5
+ $ne?: unknown;
6
+ $gt?: unknown;
7
+ $gte?: unknown;
8
+ $lt?: unknown;
9
+ $lte?: unknown;
10
+ $in?: unknown[];
11
+ $nin?: unknown[];
12
+ $regex?: string | RegExp;
13
+ $exists?: boolean;
14
+ }
15
+ interface LogicalOperators {
16
+ $and?: MongoFilter[];
17
+ $or?: MongoFilter[];
18
+ $not?: MongoFilter;
19
+ $nor?: MongoFilter[];
20
+ }
21
+ type FieldFilter = unknown | ComparisonOperators;
22
+ type MongoFilter = LogicalOperators & {
23
+ [field: string]: FieldFilter;
24
+ };
25
+ type SortDirection = 1 | -1 | 'asc' | 'desc';
26
+ type MongoSort = Record<string, SortDirection>;
27
+ interface QueryOptions {
28
+ sort?: MongoSort;
29
+ limit?: number;
30
+ skip?: number;
31
+ select?: string[] | Record<string, 0 | 1>;
32
+ }
33
+ interface MongoQuery {
34
+ collection: string;
35
+ filter?: MongoFilter;
36
+ options?: QueryOptions;
37
+ }
38
+
39
+ type SupabaseClient = SupabaseClient$1<any, any, any>;
40
+ declare function mongoToSupabase(client: SupabaseClient, query: MongoQuery): any;
41
+ declare function createTranslator(client: SupabaseClient): (query: MongoQuery) => any;
42
+ declare function translateFilter<T>(query: T, filter: MongoFilter): T;
43
+
44
+ export { type MongoFilter, type MongoQuery, type QueryOptions, type SupabaseClient, createTranslator, mongoToSupabase, translateFilter };
@@ -0,0 +1,44 @@
1
+ import { SupabaseClient as SupabaseClient$1 } from '@supabase/supabase-js';
2
+
3
+ interface ComparisonOperators {
4
+ $eq?: unknown;
5
+ $ne?: unknown;
6
+ $gt?: unknown;
7
+ $gte?: unknown;
8
+ $lt?: unknown;
9
+ $lte?: unknown;
10
+ $in?: unknown[];
11
+ $nin?: unknown[];
12
+ $regex?: string | RegExp;
13
+ $exists?: boolean;
14
+ }
15
+ interface LogicalOperators {
16
+ $and?: MongoFilter[];
17
+ $or?: MongoFilter[];
18
+ $not?: MongoFilter;
19
+ $nor?: MongoFilter[];
20
+ }
21
+ type FieldFilter = unknown | ComparisonOperators;
22
+ type MongoFilter = LogicalOperators & {
23
+ [field: string]: FieldFilter;
24
+ };
25
+ type SortDirection = 1 | -1 | 'asc' | 'desc';
26
+ type MongoSort = Record<string, SortDirection>;
27
+ interface QueryOptions {
28
+ sort?: MongoSort;
29
+ limit?: number;
30
+ skip?: number;
31
+ select?: string[] | Record<string, 0 | 1>;
32
+ }
33
+ interface MongoQuery {
34
+ collection: string;
35
+ filter?: MongoFilter;
36
+ options?: QueryOptions;
37
+ }
38
+
39
+ type SupabaseClient = SupabaseClient$1<any, any, any>;
40
+ declare function mongoToSupabase(client: SupabaseClient, query: MongoQuery): any;
41
+ declare function createTranslator(client: SupabaseClient): (query: MongoQuery) => any;
42
+ declare function translateFilter<T>(query: T, filter: MongoFilter): T;
43
+
44
+ export { type MongoFilter, type MongoQuery, type QueryOptions, type SupabaseClient, createTranslator, mongoToSupabase, translateFilter };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var u=n=>typeof n!="object"||n===null||Array.isArray(n)?false:Object.keys(n).some(t=>t.startsWith("$")),$=n=>(typeof n=="string"?n:n.source).replace(/^\^/,"").replace(/\$$/,"").replace(/\.\*/g,"%").replace(/\./g,"_"),m=(n,t,o)=>{if(!u(o))return o===null?n.is(t,null):n.eq(t,o);let i=o;for(let[s,e]of Object.entries(i))switch(s){case "$eq":n=e===null?n.is(t,null):n.eq(t,e);break;case "$ne":n=e===null?n.not(t,"is",null):n.neq(t,e);break;case "$gt":n=n.gt(t,e);break;case "$gte":n=n.gte(t,e);break;case "$lt":n=n.lt(t,e);break;case "$lte":n=n.lte(t,e);break;case "$in":Array.isArray(e)&&(n=n.in(t,e));break;case "$nin":Array.isArray(e)&&(n=n.not(t,"in",`(${e.map(r=>typeof r=="string"?`"${r}"`:r).join(",")})`));break;case "$regex":n=n.ilike(t,`%${$(e)}%`);break;case "$exists":n=e?n.not(t,"is",null):n.is(t,null);break}return n},c=(n,t)=>{for(let[o,i]of Object.entries(t)){if(o==="$and"&&Array.isArray(i)){for(let s of i)n=c(n,s);continue}if(o==="$or"&&Array.isArray(i)){let s=i.map(e=>Object.entries(e).map(([r,l])=>u(l)?Object.entries(l).map(([g,a])=>{switch(g){case "$eq":return `${r}.eq.${a}`;case "$ne":return `${r}.neq.${a}`;case "$gt":return `${r}.gt.${a}`;case "$gte":return `${r}.gte.${a}`;case "$lt":return `${r}.lt.${a}`;case "$lte":return `${r}.lte.${a}`;case "$in":return `${r}.in.(${a.join(",")})`;default:return ""}}).filter(Boolean).join(","):l===null?`${r}.is.null`:`${r}.eq.${l}`).join(",")).join(",");n=n.or(s);continue}o.startsWith("$")||(n=m(n,o,i));}return n},p=(n,t)=>{for(let[o,i]of Object.entries(t))n=n.order(o,{ascending:i===1||i==="asc"});return n};function b(n,t){let{collection:o,filter:i,options:s}=t,e=s?.select?n.from(o).select(Array.isArray(s.select)?s.select.join(","):Object.entries(s.select).filter(([,r])=>r===1).map(([r])=>r).join(",")||"*"):n.from(o).select("*");if(i&&Object.keys(i).length>0&&(e=c(e,i)),s?.sort&&(e=p(e,s.sort)),s?.limit!==void 0&&(e=e.limit(s.limit)),s?.skip!==void 0){let r=s.skip,l=s.limit?r+s.limit-1:r+999;e=e.range(r,l);}return e}function B(n){return t=>b(n,t)}function j(n,t){return c(n,t)}export{B as createTranslator,b as mongoToSupabase,j as translateFilter};
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "mongosupa",
3
+ "version": "0.1.0",
4
+ "description": "Translate MongoDB query syntax to Supabase JS queries",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsup",
26
+ "dev": "tsup --watch",
27
+ "typecheck": "tsc --noEmit",
28
+ "prepublishOnly": "npm run build"
29
+ },
30
+ "keywords": [
31
+ "mongodb",
32
+ "supabase",
33
+ "query",
34
+ "translator",
35
+ "adapter"
36
+ ],
37
+ "author": "",
38
+ "license": "MIT",
39
+ "peerDependencies": {
40
+ "@supabase/supabase-js": "^2.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@supabase/supabase-js": "^2.49.1",
44
+ "tsup": "^8.3.6",
45
+ "typescript": "^5.7.3"
46
+ }
47
+ }