@@ -4,7 +4,7 @@ import { nil } from 'pgsql-ast-parser/src/utils.js';
4
4
import { BucketPriority , isValidPriority } from './BucketDescription.js' ;
5
5
import { ExpressionType } from './ExpressionType.js' ;
6
6
import { SqlRuleError } from './errors.js' ;
7
- import { QUERY_FUNCTIONS , REQUEST_FUNCTIONS } from './request_functions.js' ;
7
+ import { REQUEST_FUNCTIONS } from './request_functions.js' ;
8
8
import {
9
9
BASIC_OPERATORS ,
10
10
OPERATOR_IN ,
@@ -94,11 +94,6 @@ export interface SqlToolsOptions {
94
94
*/
95
95
supportsParameterExpressions ?: boolean ;
96
96
97
- /**
98
- * true if expressions on stream parameters are supported.
99
- */
100
- supportsStreamInputs ?: boolean ;
101
-
102
97
/**
103
98
* Schema for validations.
104
99
*/
@@ -118,9 +113,6 @@ export class SqlTools {
118
113
119
114
readonly supportsExpandingParameters : boolean ;
120
115
readonly supportsParameterExpressions : boolean ;
121
- readonly supportsStreamInputs : boolean ;
122
-
123
- private inferredStaticParameters : Map < string , InferredBucketParameter > = new Map ( ) ;
124
116
125
117
schema ?: QuerySchema ;
126
118
@@ -139,7 +131,6 @@ export class SqlTools {
139
131
this . sql = options . sql ;
140
132
this . supportsExpandingParameters = options . supportsExpandingParameters ?? false ;
141
133
this . supportsParameterExpressions = options . supportsParameterExpressions ?? false ;
142
- this . supportsStreamInputs = options . supportsStreamInputs ?? false ;
143
134
}
144
135
145
136
error ( message : string , expr : NodeLocation | Expr | undefined ) : ClauseError {
@@ -280,7 +271,7 @@ export class SqlTools {
280
271
return compileStaticOperator ( op , leftFilter as RowValueClause , rightFilter as RowValueClause ) ;
281
272
} else if ( isParameterValueClause ( otherFilter ) ) {
282
273
// 2. row value = parameter value
283
- const inputParam = this . basicInputParameter ( otherFilter ) ;
274
+ const inputParam = basicInputParameter ( otherFilter ) ;
284
275
285
276
return {
286
277
error : false ,
@@ -327,7 +318,7 @@ export class SqlTools {
327
318
} else if ( isParameterValueClause ( leftFilter ) && isRowValueClause ( rightFilter ) ) {
328
319
// token_parameters.value IN table.some_array
329
320
// bucket.param IN table.some_array
330
- const inputParam = this . basicInputParameter ( leftFilter ) ;
321
+ const inputParam = basicInputParameter ( leftFilter ) ;
331
322
332
323
return {
333
324
error : false ,
@@ -434,25 +425,7 @@ export class SqlTools {
434
425
if ( fn in REQUEST_FUNCTIONS ) {
435
426
const fnImpl = REQUEST_FUNCTIONS [ fn ] ;
436
427
return {
437
- key : `stream.${ fn } ()` ,
438
- lookupParameterValue ( parameters ) {
439
- return fnImpl . call ( parameters ) ;
440
- } ,
441
- usesAuthenticatedRequestParameters : fnImpl . usesAuthenticatedRequestParameters ,
442
- usesUnauthenticatedRequestParameters : fnImpl . usesUnauthenticatedRequestParameters
443
- } satisfies ParameterValueClause ;
444
- } else {
445
- return this . error ( `Function '${ schema } .${ fn } ' is not defined` , expr ) ;
446
- }
447
- } else if ( schema == 'stream' ) {
448
- if ( ! this . supportsStreamInputs ) {
449
- return this . error ( `${ schema } schema is only available in stream definitions` , expr ) ;
450
- }
451
-
452
- if ( fn in QUERY_FUNCTIONS ) {
453
- const fnImpl = QUERY_FUNCTIONS [ fn ] ;
454
- return {
455
- key : `stream.${ fn } ()` ,
428
+ key : 'request.parameters()' ,
456
429
lookupParameterValue ( parameters ) {
457
430
return fnImpl . call ( parameters ) ;
458
431
} ,
@@ -784,58 +757,8 @@ export class SqlTools {
784
757
785
758
return value as BucketPriority ;
786
759
}
787
-
788
- private basicInputParameter ( clause : ParameterValueClause ) : InputParameter {
789
- if ( this . supportsStreamInputs ) {
790
- let key = this . inferredStaticParameters . get ( clause . key ) ?. name ;
791
- if ( key == null ) {
792
- key = this . newInferredBucketParameterName ( ) ;
793
- this . inferredStaticParameters . set ( clause . key , {
794
- name : key ,
795
- variant : 'static' ,
796
- clause
797
- } ) ;
798
- }
799
-
800
- return {
801
- key,
802
- expands : false ,
803
- filteredRowToLookupValue : ( ) => {
804
- return SQLITE_FALSE ; // Only relevant for parameter queries, but this is a stream query.
805
- } ,
806
- parametersToLookupValue : ( ) => {
807
- return SQLITE_FALSE ;
808
- }
809
- } ;
810
- }
811
-
812
- return {
813
- key : clause . key ,
814
- expands : false ,
815
- filteredRowToLookupValue : ( filterParameters ) => {
816
- return filterParameters [ clause . key ] ;
817
- } ,
818
- parametersToLookupValue : ( parameters ) => {
819
- return clause . lookupParameterValue ( parameters ) ;
820
- }
821
- } ;
822
- }
823
-
824
- public get inferredParameters ( ) : InferredBucketParameter [ ] {
825
- return [ ...this . inferredStaticParameters . values ( ) ] ;
826
- }
827
-
828
- private newInferredBucketParameterName ( ) {
829
- return `p${ this . inferredStaticParameters . size } ` ;
830
- }
831
760
}
832
761
833
- export type InferredBucketParameter = {
834
- name : string ;
835
- } & StaticBucketParameter ;
836
-
837
- export type StaticBucketParameter = { variant : 'static' ; clause : ParameterValueClause } ;
838
-
839
762
function isStatic ( expr : Expr ) {
840
763
return [ 'integer' , 'string' , 'numeric' , 'boolean' , 'null' ] . includes ( expr . type ) ;
841
764
}
@@ -872,3 +795,16 @@ function staticValueClause(value: SqliteValue): StaticValueClause {
872
795
usesUnauthenticatedRequestParameters : false
873
796
} ;
874
797
}
798
+
799
+ function basicInputParameter ( clause : ParameterValueClause ) : InputParameter {
800
+ return {
801
+ key : clause . key ,
802
+ expands : false ,
803
+ filteredRowToLookupValue : ( filterParameters ) => {
804
+ return filterParameters [ clause . key ] ;
805
+ } ,
806
+ parametersToLookupValue : ( parameters ) => {
807
+ return clause . lookupParameterValue ( parameters ) ;
808
+ }
809
+ } ;
810
+ }
0 commit comments