@cedarjs/gqlorm 2.6.1-next.104
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 +21 -0
- package/README.md +3 -0
- package/dist/cjs/generator/graphqlGenerator.d.ts +24 -0
- package/dist/cjs/generator/graphqlGenerator.d.ts.map +1 -0
- package/dist/cjs/generator/graphqlGenerator.js +421 -0
- package/dist/cjs/live/types.d.ts +262 -0
- package/dist/cjs/live/types.d.ts.map +1 -0
- package/dist/cjs/live/types.js +16 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/parser/queryParser.d.ts +27 -0
- package/dist/cjs/parser/queryParser.d.ts.map +1 -0
- package/dist/cjs/parser/queryParser.js +338 -0
- package/dist/cjs/queryBuilder.d.ts +106 -0
- package/dist/cjs/queryBuilder.d.ts.map +1 -0
- package/dist/cjs/queryBuilder.js +225 -0
- package/dist/cjs/react/useLiveQuery.d.ts +12 -0
- package/dist/cjs/react/useLiveQuery.d.ts.map +1 -0
- package/dist/cjs/react/useLiveQuery.js +62 -0
- package/dist/cjs/types/ast.d.ts +80 -0
- package/dist/cjs/types/ast.d.ts.map +1 -0
- package/dist/cjs/types/ast.js +16 -0
- package/dist/cjs/types/orm.d.ts +157 -0
- package/dist/cjs/types/orm.d.ts.map +1 -0
- package/dist/cjs/types/orm.js +16 -0
- package/dist/cjs/types/orm_for_testing.d.ts +44 -0
- package/dist/cjs/types/orm_for_testing.d.ts.map +1 -0
- package/dist/cjs/types/orm_for_testing.js +16 -0
- package/dist/cjs/types/schema.d.ts +4 -0
- package/dist/cjs/types/schema.d.ts.map +1 -0
- package/dist/cjs/types/schema.js +16 -0
- package/dist/cjs/types/typeUtils.d.ts +10 -0
- package/dist/cjs/types/typeUtils.d.ts.map +1 -0
- package/dist/cjs/types/typeUtils.js +65 -0
- package/dist/generator/graphqlGenerator.d.ts +24 -0
- package/dist/generator/graphqlGenerator.d.ts.map +1 -0
- package/dist/generator/graphqlGenerator.js +399 -0
- package/dist/live/types.d.ts +262 -0
- package/dist/live/types.d.ts.map +1 -0
- package/dist/live/types.js +0 -0
- package/dist/parser/queryParser.d.ts +27 -0
- package/dist/parser/queryParser.d.ts.map +1 -0
- package/dist/parser/queryParser.js +312 -0
- package/dist/queryBuilder.d.ts +106 -0
- package/dist/queryBuilder.d.ts.map +1 -0
- package/dist/queryBuilder.js +196 -0
- package/dist/react/useLiveQuery.d.ts +12 -0
- package/dist/react/useLiveQuery.d.ts.map +1 -0
- package/dist/react/useLiveQuery.js +38 -0
- package/dist/types/ast.d.ts +80 -0
- package/dist/types/ast.d.ts.map +1 -0
- package/dist/types/ast.js +0 -0
- package/dist/types/orm.d.ts +157 -0
- package/dist/types/orm.d.ts.map +1 -0
- package/dist/types/orm.js +0 -0
- package/dist/types/orm_for_testing.d.ts +44 -0
- package/dist/types/orm_for_testing.d.ts.map +1 -0
- package/dist/types/orm_for_testing.js +0 -0
- package/dist/types/schema.d.ts +4 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +0 -0
- package/dist/types/typeUtils.d.ts +10 -0
- package/dist/types/typeUtils.d.ts.map +1 -0
- package/dist/types/typeUtils.js +34 -0
- package/package.json +163 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for live query functionality
|
|
3
|
+
* Defines interfaces and types for real-time GraphQL queries with @live directive
|
|
4
|
+
*/
|
|
5
|
+
import { type ModelSchema } from '../types/schema.js';
|
|
6
|
+
export interface LiveQueryOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Whether to automatically reconnect on connection loss
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
autoReconnect?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Maximum number of reconnection attempts
|
|
14
|
+
* @default 5
|
|
15
|
+
*/
|
|
16
|
+
maxReconnectAttempts?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Delay between reconnection attempts in milliseconds
|
|
19
|
+
* @default 1000
|
|
20
|
+
*/
|
|
21
|
+
reconnectDelay?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Whether to use exponential backoff for reconnection delays
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
exponentialBackoff?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum delay between reconnection attempts in milliseconds
|
|
29
|
+
* @default 30000
|
|
30
|
+
*/
|
|
31
|
+
maxReconnectDelay?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Custom headers to send with live query requests
|
|
34
|
+
*/
|
|
35
|
+
headers?: Record<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* Custom authentication token
|
|
38
|
+
*/
|
|
39
|
+
authToken?: string;
|
|
40
|
+
/**
|
|
41
|
+
* WebSocket URL for live query subscriptions
|
|
42
|
+
*/
|
|
43
|
+
websocketUrl?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Whether to enable debug logging
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
debug?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether to resubscribe to queries upon reconnection
|
|
51
|
+
* @default true
|
|
52
|
+
*/
|
|
53
|
+
refetchOnReconnect?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export type ResolvedLiveQueryOptions = Required<Omit<LiveQueryOptions, 'authToken' | 'websocketUrl'>> & {
|
|
56
|
+
authToken: string | undefined;
|
|
57
|
+
websocketUrl: string | undefined;
|
|
58
|
+
};
|
|
59
|
+
export type LiveQueryConnectionState = 'connecting' | 'connected' | 'disconnected' | 'reconnecting' | 'error' | 'closed';
|
|
60
|
+
export type LiveQueryUpdateType = 'insert' | 'update' | 'delete' | 'refresh';
|
|
61
|
+
export interface LiveQueryUpdate<T = any> {
|
|
62
|
+
/**
|
|
63
|
+
* Type of update that occurred
|
|
64
|
+
*/
|
|
65
|
+
type: LiveQueryUpdateType;
|
|
66
|
+
/**
|
|
67
|
+
* Updated data (for insert/update) or deleted item (for delete)
|
|
68
|
+
*/
|
|
69
|
+
data?: T;
|
|
70
|
+
/**
|
|
71
|
+
* Complete updated result set (for refresh)
|
|
72
|
+
*/
|
|
73
|
+
result?: T;
|
|
74
|
+
/**
|
|
75
|
+
* Timestamp when the update occurred
|
|
76
|
+
*/
|
|
77
|
+
timestamp: Date;
|
|
78
|
+
/**
|
|
79
|
+
* Optional metadata about the update
|
|
80
|
+
*/
|
|
81
|
+
metadata?: Record<string, any>;
|
|
82
|
+
}
|
|
83
|
+
export interface LiveQueryError {
|
|
84
|
+
/**
|
|
85
|
+
* Error code
|
|
86
|
+
*/
|
|
87
|
+
code: string;
|
|
88
|
+
/**
|
|
89
|
+
* Human-readable error message
|
|
90
|
+
*/
|
|
91
|
+
message: string;
|
|
92
|
+
/**
|
|
93
|
+
* Optional error details
|
|
94
|
+
*/
|
|
95
|
+
details?: any;
|
|
96
|
+
/**
|
|
97
|
+
* Timestamp when the error occurred
|
|
98
|
+
*/
|
|
99
|
+
timestamp: Date;
|
|
100
|
+
}
|
|
101
|
+
export interface LiveQuerySubscription<T = any> {
|
|
102
|
+
/**
|
|
103
|
+
* Unique identifier for this subscription
|
|
104
|
+
*/
|
|
105
|
+
id: string;
|
|
106
|
+
/**
|
|
107
|
+
* GraphQL query string
|
|
108
|
+
*/
|
|
109
|
+
query: string;
|
|
110
|
+
/**
|
|
111
|
+
* Query variables
|
|
112
|
+
*/
|
|
113
|
+
variables?: Record<string, any>;
|
|
114
|
+
/**
|
|
115
|
+
* Current connection state
|
|
116
|
+
*/
|
|
117
|
+
connectionState: LiveQueryConnectionState;
|
|
118
|
+
/**
|
|
119
|
+
* Latest query result
|
|
120
|
+
*/
|
|
121
|
+
data: T | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Latest error, if any
|
|
124
|
+
*/
|
|
125
|
+
error: LiveQueryError | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Whether the subscription is currently loading
|
|
128
|
+
*/
|
|
129
|
+
loading: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Unsubscribe from live updates
|
|
132
|
+
*/
|
|
133
|
+
unsubscribe: () => void;
|
|
134
|
+
/**
|
|
135
|
+
* Manually refetch the query
|
|
136
|
+
*/
|
|
137
|
+
refetch: () => Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Register a callback for live data updates
|
|
140
|
+
* Returns a function to unregister the callback
|
|
141
|
+
*/
|
|
142
|
+
onUpdate: (callback: (update: LiveQueryUpdate) => void) => () => void;
|
|
143
|
+
}
|
|
144
|
+
export interface LiveQueryClientConfig extends LiveQueryOptions {
|
|
145
|
+
/**
|
|
146
|
+
* GraphQL endpoint URL
|
|
147
|
+
*/
|
|
148
|
+
endpoint: string;
|
|
149
|
+
/**
|
|
150
|
+
* WebSocket endpoint URL (optional, will derive from endpoint if not provided)
|
|
151
|
+
*/
|
|
152
|
+
websocketUrl?: string;
|
|
153
|
+
/**
|
|
154
|
+
* Model schema defining scalar fields for each model
|
|
155
|
+
*/
|
|
156
|
+
schema?: ModelSchema;
|
|
157
|
+
}
|
|
158
|
+
export interface LiveQueryTransport {
|
|
159
|
+
/**
|
|
160
|
+
* Connect to the live query service
|
|
161
|
+
*/
|
|
162
|
+
connect(): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Disconnect from the live query service
|
|
165
|
+
*/
|
|
166
|
+
disconnect(): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Subscribe to a live query
|
|
169
|
+
*/
|
|
170
|
+
subscribe<T>(query: string, variables?: Record<string, any>, options?: LiveQueryOptions): LiveQuerySubscription<T>;
|
|
171
|
+
/**
|
|
172
|
+
* Get current connection state
|
|
173
|
+
*/
|
|
174
|
+
getConnectionState(): LiveQueryConnectionState;
|
|
175
|
+
/**
|
|
176
|
+
* Add connection state change listener
|
|
177
|
+
*/
|
|
178
|
+
onConnectionStateChange(listener: (state: LiveQueryConnectionState) => void): () => void;
|
|
179
|
+
/**
|
|
180
|
+
* Add error listener
|
|
181
|
+
*/
|
|
182
|
+
onError(listener: (error: LiveQueryError) => void): () => void;
|
|
183
|
+
}
|
|
184
|
+
export interface LiveQueryCache {
|
|
185
|
+
/**
|
|
186
|
+
* Get cached result for a query
|
|
187
|
+
*/
|
|
188
|
+
get<T>(key: string): T | undefined;
|
|
189
|
+
/**
|
|
190
|
+
* Set cached result for a query
|
|
191
|
+
*/
|
|
192
|
+
set<T>(key: string, data: T): void;
|
|
193
|
+
/**
|
|
194
|
+
* Remove cached result
|
|
195
|
+
*/
|
|
196
|
+
remove(key: string): void;
|
|
197
|
+
/**
|
|
198
|
+
* Clear all cached results
|
|
199
|
+
*/
|
|
200
|
+
clear(): void;
|
|
201
|
+
/**
|
|
202
|
+
* Get cache key for a query
|
|
203
|
+
*/
|
|
204
|
+
getKey(query: string, variables?: Record<string, any>): string;
|
|
205
|
+
}
|
|
206
|
+
export interface LiveQueryContextValue {
|
|
207
|
+
/**
|
|
208
|
+
* Live query transport instance
|
|
209
|
+
*/
|
|
210
|
+
transport?: LiveQueryTransport;
|
|
211
|
+
/**
|
|
212
|
+
* Live query cache instance
|
|
213
|
+
*/
|
|
214
|
+
cache?: LiveQueryCache;
|
|
215
|
+
/**
|
|
216
|
+
* Global live query options
|
|
217
|
+
*/
|
|
218
|
+
options?: LiveQueryOptions;
|
|
219
|
+
/**
|
|
220
|
+
* Model schema defining scalar fields for each model
|
|
221
|
+
*/
|
|
222
|
+
schema?: ModelSchema;
|
|
223
|
+
/**
|
|
224
|
+
* Query builder instance with schema
|
|
225
|
+
*/
|
|
226
|
+
queryBuilder?: any;
|
|
227
|
+
/**
|
|
228
|
+
* Whether the client is connected
|
|
229
|
+
*/
|
|
230
|
+
isConnected: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Current connection state
|
|
233
|
+
*/
|
|
234
|
+
connectionState: LiveQueryConnectionState;
|
|
235
|
+
}
|
|
236
|
+
export interface LiveQueryHookResult<T = any> {
|
|
237
|
+
/**
|
|
238
|
+
* Query result data
|
|
239
|
+
*/
|
|
240
|
+
data: T | undefined;
|
|
241
|
+
/**
|
|
242
|
+
* Loading state
|
|
243
|
+
*/
|
|
244
|
+
loading: boolean;
|
|
245
|
+
/**
|
|
246
|
+
* Error state
|
|
247
|
+
*/
|
|
248
|
+
error: LiveQueryError | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* Connection state
|
|
251
|
+
*/
|
|
252
|
+
connectionState: LiveQueryConnectionState;
|
|
253
|
+
/**
|
|
254
|
+
* Refetch function
|
|
255
|
+
*/
|
|
256
|
+
refetch: () => Promise<void>;
|
|
257
|
+
/**
|
|
258
|
+
* Subscription instance (for advanced usage)
|
|
259
|
+
*/
|
|
260
|
+
subscription: LiveQuerySubscription<T> | undefined;
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/live/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGrD,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAE7B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEhC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAG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c = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query parser that converts ORM-style queries to AST representation
|
|
3
|
+
* Handles parsing of Prisma-like query syntax into our internal AST format
|
|
4
|
+
*/
|
|
5
|
+
import type { QueryAST, QueryOperation } from '../types/ast.js';
|
|
6
|
+
import type { FindFirstArgs, FindManyArgs, FindUniqueArgs } from '../types/orm.js';
|
|
7
|
+
export declare class QueryParseError extends Error {
|
|
8
|
+
context?: any | undefined;
|
|
9
|
+
constructor(message: string, context?: any | undefined);
|
|
10
|
+
}
|
|
11
|
+
export declare class QueryParser {
|
|
12
|
+
#private;
|
|
13
|
+
/**
|
|
14
|
+
* Parse a complete query from model, operation, and arguments
|
|
15
|
+
*/
|
|
16
|
+
parseQuery(model: string, operation: QueryOperation, args?: FindManyArgs<any> | FindUniqueArgs<any> | FindFirstArgs<any>): QueryAST;
|
|
17
|
+
/**
|
|
18
|
+
* Parse comparison operator string
|
|
19
|
+
*/
|
|
20
|
+
private parseComparisonOperator;
|
|
21
|
+
/**
|
|
22
|
+
* Validate AST structure
|
|
23
|
+
*/
|
|
24
|
+
validateAST(ast: QueryAST): void;
|
|
25
|
+
}
|
|
26
|
+
export declare const queryParser: QueryParser;
|
|
27
|
+
//# sourceMappingURL=queryParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryParser.d.ts","sourceRoot":"","sources":["../../../src/parser/queryParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAUV,QAAQ,EACR,cAAc,EAMf,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,cAAc,EAKf,MAAM,iBAAiB,CAAA;AAGxB,qBAAa,eAAgB,SAAQ,KAAK;IAG/B,OAAO,CAAC,EAAE,GAAG;gBADpB,OAAO,EAAE,MAAM,EACR,OAAO,CAAC,EAAE,GAAG,YAAA;CAKvB;AAED,qBAAa,WAAW;;IACtB;;OAEG;IACH,UAAU,CACR,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,cAAc,EACzB,IAAI,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,GAClE,QAAQ;IAoNX;;OAEG;IACH,OAAO,CAAC,uBAAuB;IA2I/B;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI;CAmBjC;AAGD,eAAO,MAAM,WAAW,aAAoB,CAAA"}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var queryParser_exports = {};
|
|
20
|
+
__export(queryParser_exports, {
|
|
21
|
+
QueryParseError: () => QueryParseError,
|
|
22
|
+
QueryParser: () => QueryParser,
|
|
23
|
+
queryParser: () => queryParser
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(queryParser_exports);
|
|
26
|
+
var import_typeUtils = require("../types/typeUtils.js");
|
|
27
|
+
class QueryParseError extends Error {
|
|
28
|
+
constructor(message, context) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.context = context;
|
|
31
|
+
this.name = "QueryParseError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class QueryParser {
|
|
35
|
+
/**
|
|
36
|
+
* Parse a complete query from model, operation, and arguments
|
|
37
|
+
*/
|
|
38
|
+
parseQuery(model, operation, args) {
|
|
39
|
+
if (!model || !operation) {
|
|
40
|
+
throw new QueryParseError("Model and operation are required");
|
|
41
|
+
}
|
|
42
|
+
const query = {
|
|
43
|
+
type: "Query",
|
|
44
|
+
model,
|
|
45
|
+
operation
|
|
46
|
+
};
|
|
47
|
+
if (args && Object.keys(args).length > 0) {
|
|
48
|
+
query.args = this.#parseQueryArgs(args);
|
|
49
|
+
}
|
|
50
|
+
return query;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parse query arguments into AST
|
|
54
|
+
*/
|
|
55
|
+
#parseQueryArgs(args) {
|
|
56
|
+
const queryArgs = {
|
|
57
|
+
type: "QueryArgs"
|
|
58
|
+
};
|
|
59
|
+
if (args.where) {
|
|
60
|
+
queryArgs.where = this.#parseWhere(args.where);
|
|
61
|
+
}
|
|
62
|
+
if (args.select) {
|
|
63
|
+
queryArgs.select = this.#parseSelect(args.select);
|
|
64
|
+
}
|
|
65
|
+
if (args.include) {
|
|
66
|
+
queryArgs.include = this.#parseInclude(args.include);
|
|
67
|
+
}
|
|
68
|
+
if (args.orderBy) {
|
|
69
|
+
queryArgs.orderBy = this.#parseOrderBy(args.orderBy);
|
|
70
|
+
}
|
|
71
|
+
if (typeof args.take === "number") {
|
|
72
|
+
queryArgs.take = args.take;
|
|
73
|
+
}
|
|
74
|
+
if (typeof args.skip === "number") {
|
|
75
|
+
queryArgs.skip = args.skip;
|
|
76
|
+
}
|
|
77
|
+
return queryArgs;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Parse WHERE clause into AST
|
|
81
|
+
*/
|
|
82
|
+
#parseWhere(where) {
|
|
83
|
+
const conditions = this.#parseWhereConditions(where);
|
|
84
|
+
return {
|
|
85
|
+
type: "Where",
|
|
86
|
+
conditions
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Parse where conditions recursively
|
|
91
|
+
*/
|
|
92
|
+
// TODO: See if we can type `where` to `Record<any, any>`
|
|
93
|
+
#parseWhereConditions(where) {
|
|
94
|
+
const conditions = Object.entries(where).map(([key, value]) => {
|
|
95
|
+
if ((0, import_typeUtils.isLogicalOperator)(key)) {
|
|
96
|
+
return this.#parseLogicalCondition(key, value);
|
|
97
|
+
}
|
|
98
|
+
if (this.#isRelationCondition(value)) {
|
|
99
|
+
return this.#parseRelationCondition(key, value);
|
|
100
|
+
}
|
|
101
|
+
return this.#parseFieldCondition(key, value);
|
|
102
|
+
});
|
|
103
|
+
return conditions;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Parse logical condition (AND, OR, NOT)
|
|
107
|
+
*/
|
|
108
|
+
#parseLogicalCondition(operator, value) {
|
|
109
|
+
let nestedConditions = [];
|
|
110
|
+
if (operator === "NOT") {
|
|
111
|
+
nestedConditions = this.#parseWhereConditions(value);
|
|
112
|
+
} else {
|
|
113
|
+
if (Array.isArray(value)) {
|
|
114
|
+
for (const condition of value) {
|
|
115
|
+
nestedConditions.push(...this.#parseWhereConditions(condition));
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
throw new QueryParseError(`${operator} operator expects an array`, {
|
|
119
|
+
operator,
|
|
120
|
+
value
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
type: "LogicalCondition",
|
|
126
|
+
operator,
|
|
127
|
+
conditions: nestedConditions
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check if a value represents a relation condition
|
|
132
|
+
*/
|
|
133
|
+
#isRelationCondition(value) {
|
|
134
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !this.#isFilterObject(value) && !(value instanceof Date);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Parse relation condition
|
|
138
|
+
*/
|
|
139
|
+
#parseRelationCondition(field, value) {
|
|
140
|
+
const nestedConditions = this.#parseWhereConditions(value);
|
|
141
|
+
return {
|
|
142
|
+
type: "RelationCondition",
|
|
143
|
+
relation: field,
|
|
144
|
+
condition: {
|
|
145
|
+
type: "Where",
|
|
146
|
+
conditions: nestedConditions
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check if value represents a filter object
|
|
152
|
+
*/
|
|
153
|
+
#isFilterObject(value) {
|
|
154
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
const filterOperators = /* @__PURE__ */ new Set([
|
|
158
|
+
"equals",
|
|
159
|
+
"not",
|
|
160
|
+
"in",
|
|
161
|
+
"notIn",
|
|
162
|
+
"lt",
|
|
163
|
+
"lte",
|
|
164
|
+
"gt",
|
|
165
|
+
"gte",
|
|
166
|
+
"contains",
|
|
167
|
+
"startsWith",
|
|
168
|
+
"endsWith",
|
|
169
|
+
"isNull",
|
|
170
|
+
"isNotNull"
|
|
171
|
+
]);
|
|
172
|
+
return Object.keys(value).some((key) => filterOperators.has(key));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Parse field condition
|
|
176
|
+
*/
|
|
177
|
+
#parseFieldCondition(field, value) {
|
|
178
|
+
if (!this.#isFilterObject(value)) {
|
|
179
|
+
return {
|
|
180
|
+
type: "FieldCondition",
|
|
181
|
+
field,
|
|
182
|
+
operator: "equals",
|
|
183
|
+
value
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const filterEntries = Object.entries(value);
|
|
187
|
+
if (filterEntries.length !== 1) {
|
|
188
|
+
throw new QueryParseError(
|
|
189
|
+
`Field condition must have exactly one operator`,
|
|
190
|
+
{ field, value }
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
const [operatorStr, operatorValue] = filterEntries[0];
|
|
194
|
+
const operator = this.parseComparisonOperator(operatorStr);
|
|
195
|
+
return {
|
|
196
|
+
type: "FieldCondition",
|
|
197
|
+
field,
|
|
198
|
+
operator,
|
|
199
|
+
value: operatorValue
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Parse comparison operator string
|
|
204
|
+
*/
|
|
205
|
+
parseComparisonOperator(operator) {
|
|
206
|
+
const validOperators = [
|
|
207
|
+
"equals",
|
|
208
|
+
"not",
|
|
209
|
+
"in",
|
|
210
|
+
"notIn",
|
|
211
|
+
"lt",
|
|
212
|
+
"lte",
|
|
213
|
+
"gt",
|
|
214
|
+
"gte",
|
|
215
|
+
"contains",
|
|
216
|
+
"startsWith",
|
|
217
|
+
"endsWith",
|
|
218
|
+
"isNull",
|
|
219
|
+
"isNotNull"
|
|
220
|
+
];
|
|
221
|
+
if (!validOperators.includes(operator)) {
|
|
222
|
+
throw new QueryParseError(`Invalid comparison operator: ${operator}`);
|
|
223
|
+
}
|
|
224
|
+
return operator;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Parse SELECT clause into AST
|
|
228
|
+
*/
|
|
229
|
+
#parseSelect(select) {
|
|
230
|
+
const fields = [];
|
|
231
|
+
for (const [field, selected] of Object.entries(select)) {
|
|
232
|
+
if (typeof selected === "boolean") {
|
|
233
|
+
fields.push({
|
|
234
|
+
type: "FieldSelection",
|
|
235
|
+
field,
|
|
236
|
+
selected
|
|
237
|
+
});
|
|
238
|
+
} else if (typeof selected === "object" && selected !== null) {
|
|
239
|
+
const selectedObj = selected;
|
|
240
|
+
const fieldSelection = {
|
|
241
|
+
type: "FieldSelection",
|
|
242
|
+
field,
|
|
243
|
+
selected: true
|
|
244
|
+
};
|
|
245
|
+
if (selectedObj.select) {
|
|
246
|
+
fieldSelection.nested = this.#parseSelect(selectedObj.select);
|
|
247
|
+
} else if (selectedObj.include) {
|
|
248
|
+
fieldSelection.nested = this.#parseInclude(selectedObj.include);
|
|
249
|
+
}
|
|
250
|
+
fields.push(fieldSelection);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
type: "Select",
|
|
255
|
+
fields
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Parse INCLUDE clause into AST
|
|
260
|
+
*/
|
|
261
|
+
#parseInclude(include) {
|
|
262
|
+
const relations = [];
|
|
263
|
+
for (const [relation, inclusion] of Object.entries(include)) {
|
|
264
|
+
if (typeof inclusion === "boolean") {
|
|
265
|
+
relations.push({
|
|
266
|
+
type: "RelationInclusion",
|
|
267
|
+
relation,
|
|
268
|
+
included: inclusion
|
|
269
|
+
});
|
|
270
|
+
} else if (typeof inclusion === "object" && inclusion !== null) {
|
|
271
|
+
const relationInclusion = {
|
|
272
|
+
type: "RelationInclusion",
|
|
273
|
+
relation,
|
|
274
|
+
included: true
|
|
275
|
+
};
|
|
276
|
+
if (inclusion.include) {
|
|
277
|
+
relationInclusion.nested = this.#parseInclude(inclusion.include);
|
|
278
|
+
}
|
|
279
|
+
if (inclusion.select || inclusion.where || inclusion.orderBy || inclusion.take || inclusion.skip) {
|
|
280
|
+
relationInclusion.args = this.#parseQueryArgs(inclusion);
|
|
281
|
+
}
|
|
282
|
+
relations.push(relationInclusion);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
type: "Include",
|
|
287
|
+
relations
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Parse ORDER BY clause
|
|
292
|
+
*/
|
|
293
|
+
#parseOrderBy(orderBy) {
|
|
294
|
+
const fields = [];
|
|
295
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
296
|
+
for (const orderByItem of orderByArray) {
|
|
297
|
+
for (const [field, direction] of Object.entries(orderByItem)) {
|
|
298
|
+
if (direction === "asc" || direction === "desc") {
|
|
299
|
+
fields.push({
|
|
300
|
+
type: "OrderByField",
|
|
301
|
+
field,
|
|
302
|
+
direction
|
|
303
|
+
});
|
|
304
|
+
} else {
|
|
305
|
+
throw new QueryParseError(
|
|
306
|
+
`Invalid sort direction: ${direction}. Must be 'asc' or 'desc'`
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
type: "OrderBy",
|
|
313
|
+
fields
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Validate AST structure
|
|
318
|
+
*/
|
|
319
|
+
validateAST(ast) {
|
|
320
|
+
if (!ast.model || !ast.operation) {
|
|
321
|
+
throw new QueryParseError("Invalid AST: missing model or operation");
|
|
322
|
+
}
|
|
323
|
+
if (ast.operation === "findUnique" || ast.operation === "findUniqueOrThrow") {
|
|
324
|
+
if (!ast.args?.where) {
|
|
325
|
+
throw new QueryParseError(
|
|
326
|
+
"findUnique operations require a where clause"
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const queryParser = new QueryParser();
|
|
333
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
334
|
+
0 && (module.exports = {
|
|
335
|
+
QueryParseError,
|
|
336
|
+
QueryParser,
|
|
337
|
+
queryParser
|
|
338
|
+
});
|