@zenith-open/zenithcms-db-postgres 0.1.0 → 1.0.0-beta.1

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/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './PostgresDrizzleAdapter'
2
- export * from './query-ast'
package/src/query-ast.ts DELETED
@@ -1,117 +0,0 @@
1
- /**
2
- * Zenith CMS — Query AST Parser
3
- * ─────────────────────────────
4
- * Translates incoming URL query objects or Mongo-style queries into a structured
5
- * Abstract Syntax Tree (AST) that can be reliably executed by both MongoDB and PostgreSQL adapters.
6
- */
7
-
8
- export type Operator = 'equals' | 'not_equals' | 'contains' | 'in' | 'not_in' | 'gt' | 'gte' | 'lt' | 'lte'
9
-
10
- export interface QueryNode {
11
- type: 'field' | 'logical'
12
- }
13
-
14
- export interface FieldNode extends QueryNode {
15
- type: 'field'
16
- field: string
17
- operator: Operator
18
- value: any
19
- }
20
-
21
- export interface LogicalNode extends QueryNode {
22
- type: 'logical'
23
- operator: 'and' | 'or'
24
- children: QueryNode[]
25
- }
26
-
27
- export class QueryASTParser {
28
- /**
29
- * Parses a raw query object (e.g., from req.query or a Mongo-style filter) into an AST.
30
- */
31
- static parse(rawQuery: any): QueryNode {
32
- // Basic implementation: convert flat key-value pairs to 'field' nodes combined by 'and'
33
- const children: QueryNode[] = []
34
-
35
- for (const key of Object.keys(rawQuery)) {
36
- const value = rawQuery[key]
37
-
38
- // Handle $or and $and logical operators
39
- if ((key === '$or' || key === '$and') && Array.isArray(value)) {
40
- const logicalOp = key === '$or' ? 'or' : 'and'
41
- const logicalChildren: QueryNode[] = []
42
- for (const clause of value) {
43
- if (typeof clause === 'object' && clause !== null) {
44
- const parsed = this.parse(clause)
45
- if (parsed) logicalChildren.push(parsed)
46
- }
47
- }
48
- if (logicalChildren.length > 0) {
49
- children.push({
50
- type: 'logical',
51
- operator: logicalOp,
52
- children: logicalChildren,
53
- } as LogicalNode)
54
- }
55
- continue
56
- }
57
-
58
- // Handle simple key=value as 'equals'
59
- if (typeof value !== 'object' || value === null) {
60
- children.push({
61
- type: 'field',
62
- field: key,
63
- operator: 'equals',
64
- value
65
- } as FieldNode)
66
- } else {
67
- // Handle complex objects like { price: { gt: 10 } }
68
- const ops = Object.keys(value)
69
- for (const op of ops) {
70
- if (op === '$options') continue
71
- const parsedOp = this.mapOperator(op)
72
- children.push({
73
- type: 'field',
74
- field: key,
75
- operator: parsedOp,
76
- value: value[op]
77
- } as FieldNode)
78
- }
79
- }
80
- }
81
-
82
- if (children.length === 1) {
83
- return children[0]
84
- }
85
-
86
- return {
87
- type: 'logical',
88
- operator: 'and',
89
- children
90
- } as LogicalNode
91
- }
92
-
93
- private static mapOperator(op: string): Operator {
94
- const map: Record<string, Operator> = {
95
- 'eq': 'equals',
96
- 'ne': 'not_equals',
97
- 'contains': 'contains',
98
- 'in': 'in',
99
- 'nin': 'not_in',
100
- 'gt': 'gt',
101
- 'gte': 'gte',
102
- 'lt': 'lt',
103
- 'lte': 'lte',
104
- '$eq': 'equals',
105
- '$ne': 'not_equals',
106
- '$gt': 'gt', // Support Mongo style
107
- '$gte': 'gte',
108
- '$lt': 'lt',
109
- '$lte': 'lte',
110
- '$in': 'in',
111
- '$nin': 'not_in',
112
- '$regex': 'contains',
113
- }
114
-
115
- return map[op] || 'equals'
116
- }
117
- }
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "allowJs": true
5
- },
6
- "include": ["src/**/*", "tests/**/*", "bin/**/*", "*.ts", "*.mjs"],
7
- "exclude": ["node_modules", "dist"]
8
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./src",
6
- "strict": true,
7
- "paths": {}
8
- },
9
- "include": ["src/**/*"],
10
- "exclude": ["node_modules", "dist", "**/*.test.ts"]
11
- }