@@ -75,14 +75,20 @@ function forPrimitives<A, O = A, I = unknown>(
75
75
return new Map ( e ) ;
76
76
}
77
77
78
- export const Literal = forPrimitives ( < T extends PrimitiveC > ( c : PrimitiveC ) =>
78
+ const literal = forPrimitives ( < T extends PrimitiveC > ( c : PrimitiveC ) =>
79
79
t . type ( {
80
80
type : t . literal ( 'literal' ) ,
81
81
value : c ,
82
82
} )
83
83
) ;
84
+ export function Literal < T extends PrimitiveC > (
85
+ c : T
86
+ ) : t . Type < Literal < t . TypeOf < T > > > {
87
+ return literal . get ( c ) ! as t . Type < Literal < t . TypeOf < T > > > ;
88
+ }
89
+
84
90
export type SomeLiteral = t . Type < Literal < Primitive > > ;
85
- export const AnyLiteral = t . union ( Array . from ( Literal ) . map ( x => x [ 1 ] ) as [
91
+ export const AnyLiteral = t . union ( Array . from ( literal ) . map ( x => x [ 1 ] ) as [
86
92
SomeLiteral ,
87
93
SomeLiteral ,
88
94
...SomeLiteral [ ]
@@ -120,7 +126,7 @@ function forRangedPrimitives<A, O, I>(
120
126
return new Map ( e ) ;
121
127
}
122
128
123
- export const Range = forRangedPrimitives ( < T extends RangedPrimitiveC > ( c : T ) =>
129
+ const range = forRangedPrimitives ( < T extends RangedPrimitiveC > ( c : T ) =>
124
130
t . intersection ( [
125
131
t . type ( {
126
132
type : t . literal ( 'range' ) ,
@@ -134,8 +140,13 @@ export const Range = forRangedPrimitives(<T extends RangedPrimitiveC>(c: T) =>
134
140
} ) ,
135
141
] )
136
142
) ;
143
+ export function Range < T extends RangedPrimitiveC > (
144
+ c : T
145
+ ) : t . Type < Range < t . TypeOf < T > > > {
146
+ return range . get ( c ) ! as t . Type < Range < t . TypeOf < T > > > ;
147
+ }
137
148
export type SomeRange = t . Type < Range < RangedPrimitive > > ;
138
- export const AnyRange = t . union ( Array . from ( Range ) . map ( x => x [ 1 ] ) as [
149
+ export const AnyRange = t . union ( Array . from ( range ) . map ( x => x [ 1 ] ) as [
139
150
SomeRange ,
140
151
SomeRange ,
141
152
...SomeRange [ ]
@@ -171,33 +182,33 @@ export type TermValue<T extends Primitive> =
171
182
| MaybeGlob < T >
172
183
| MaybeRange < T >
173
184
| NonPrimitiveTermValue < T > ;
174
- export const TermValue = forPrimitives < TermValue < t . TypeOf < PrimitiveC > > > (
185
+ const termValue = forPrimitives < TermValue < t . TypeOf < PrimitiveC > > > (
175
186
< T extends PrimitiveC > ( c : T ) : t . Type < TermValue < t . TypeOf < PrimitiveC > > > =>
176
187
t . recursion ( `TermValue<${ c . name } >` , ( ) => {
177
- let ret : t . Type < TermValue < t . TypeOf < PrimitiveC > > > | undefined = undefined ;
188
+ let ret : t . Type < TermValue < t . TypeOf < T > > > | undefined = undefined ;
178
189
if ( IsGlobPrimitiveC ( c ) ) {
179
- ret = Literal . get ( Glob ) ! as t . Type < TermValue < t . TypeOf < PrimitiveC > > > ;
190
+ ret = Literal ( Glob ) as t . Type < TermValue < t . TypeOf < T > > > ;
180
191
}
181
192
if ( IsRangedPrimitiveC ( c ) ) {
182
- ret = ( ret ? t . union ( [ ret , Range . get ( c ) ! ] ) : Range . get ( c ) ! ) as t . Type <
183
- TermValue < t . TypeOf < PrimitiveC > >
193
+ ret = ( ret ? t . union ( [ ret , Range ( c ) ] ) : Range ( c ) ) as t . Type <
194
+ TermValue < t . TypeOf < T > >
184
195
> ;
185
196
}
186
197
if ( ret ) {
187
- ret = t . union ( [
188
- Literal . get ( c ) ! ,
189
- NonPrimitiveTermValue . get ( c ) ! ,
190
- ret ,
191
- ] ) as t . Type < TermValue < t . TypeOf < PrimitiveC > > > ;
198
+ ret = t . union ( [ Literal ( c ) , NonPrimitiveTermValue ( c ) , ret ] ) ;
192
199
} else {
193
- ret = t . union ( [
194
- Literal . get ( c ) ! ,
195
- NonPrimitiveTermValue . get ( c ) ! ,
196
- ] ) as t . Type < TermValue < t . TypeOf < PrimitiveC > > > ;
200
+ ret = t . union ( [ Literal ( c ) , NonPrimitiveTermValue ( c ) ] ) as t . Type <
201
+ TermValue < t . TypeOf < T > >
202
+ > ;
197
203
}
198
- return ret ! ;
204
+ return ret ! as t . Type < TermValue < t . TypeOf < PrimitiveC > > > ;
199
205
} )
200
206
) ;
207
+ export function TermValue < T extends PrimitiveC > (
208
+ c : T
209
+ ) : t . Type < TermValue < t . TypeOf < T > > > {
210
+ return termValue . get ( c ) ! as t . Type < TermValue < t . TypeOf < T > > > ;
211
+ }
201
212
202
213
export interface AndBase < U > {
203
214
type : 'and' ;
@@ -211,13 +222,18 @@ const AndBase = <U extends t.Any>(c: U) =>
211
222
export interface And extends AndBase < Clause > { }
212
223
export const And = t . recursion < And > ( 'And' , ( ) : t . Type < And > => AndBase ( Clause ) ) ;
213
224
export interface AndTerm < T extends Primitive > extends AndBase < TermValue < T > > { }
214
- export const AndTerm = forPrimitives (
225
+ const andTerm = forPrimitives (
215
226
< U extends PrimitiveC > ( c : U ) : t . Type < AndTerm < t . TypeOf < U > > > =>
216
227
t . recursion (
217
228
`AndTerm<${ c . name } >` ,
218
- ( ) => AndBase ( TermValue . get ( c ) ! ) as t . Type < AndTerm < t . TypeOf < U > > >
229
+ ( ) => AndBase ( TermValue ( c ) ) as t . Type < AndTerm < t . TypeOf < U > > >
219
230
)
220
231
) ;
232
+ export function AndTerm < T extends PrimitiveC > (
233
+ c : T
234
+ ) : t . Type < AndTerm < t . TypeOf < T > > > {
235
+ return andTerm . get ( c ) ! as t . Type < AndTerm < t . TypeOf < T > > > ;
236
+ }
221
237
222
238
export interface OrBase < U > {
223
239
type : 'or' ;
@@ -231,13 +247,18 @@ const OrBase = <U extends t.Any>(c: U) =>
231
247
export interface Or extends OrBase < Clause > { }
232
248
export const Or = t . recursion < Or > ( 'Or' , ( ) : t . Type < Or > => OrBase ( Clause ) ) ;
233
249
export interface OrTerm < T extends Primitive > extends OrBase < TermValue < T > > { }
234
- export const OrTerm = forPrimitives (
250
+ const orTerm = forPrimitives (
235
251
< U extends PrimitiveC > ( c : U ) : t . Type < OrTerm < t . TypeOf < U > > > =>
236
252
t . recursion (
237
253
`OrTerm<${ c . name } >` ,
238
- ( ) => OrBase ( TermValue . get ( c ) ! ) as t . Type < OrTerm < t . TypeOf < U > > >
254
+ ( ) => OrBase ( TermValue ( c ) ) as t . Type < OrTerm < t . TypeOf < U > > >
239
255
)
240
256
) ;
257
+ export function OrTerm < T extends PrimitiveC > (
258
+ c : T
259
+ ) : t . Type < OrTerm < t . TypeOf < T > > > {
260
+ return orTerm . get ( c ) ! as t . Type < OrTerm < t . TypeOf < T > > > ;
261
+ }
241
262
242
263
export interface NotBase < U > {
243
264
type : 'not' ;
@@ -251,13 +272,18 @@ const NotBase = <U extends t.Any>(c: U) =>
251
272
export interface Not extends NotBase < Clause > { }
252
273
export const Not = t . recursion < Not > ( 'Not' , ( ) : t . Type < Not > => NotBase ( Clause ) ) ;
253
274
export interface NotTerm < T extends Primitive > extends NotBase < TermValue < T > > { }
254
- export const NotTerm = forPrimitives (
275
+ const notTerm = forPrimitives (
255
276
< U extends PrimitiveC > ( c : U ) : t . Type < NotTerm < t . TypeOf < U > > > =>
256
277
t . recursion (
257
278
`NotTerm<${ c . name } >` ,
258
- ( ) => NotBase ( TermValue . get ( c ) ! ) as t . Type < NotTerm < t . TypeOf < U > > >
279
+ ( ) => NotBase ( TermValue ( c ) ) as t . Type < NotTerm < t . TypeOf < U > > >
259
280
)
260
281
) ;
282
+ export function NotTerm < T extends PrimitiveC > (
283
+ c : T
284
+ ) : t . Type < NotTerm < t . TypeOf < T > > > {
285
+ return notTerm . get ( c ) ! as t . Type < NotTerm < t . TypeOf < T > > > ;
286
+ }
261
287
262
288
export interface RequiredBase < U > {
263
289
type : 'required' ;
@@ -275,13 +301,18 @@ export const Required = t.recursion<Required>(
275
301
) ;
276
302
export interface RequiredTerm < T extends Primitive >
277
303
extends RequiredBase < TermValue < T > > { }
278
- export const RequiredTerm = forPrimitives (
304
+ const requiredTerm = forPrimitives (
279
305
< U extends PrimitiveC > ( c : U ) : t . Type < RequiredTerm < t . TypeOf < U > > > =>
280
306
t . recursion (
281
307
`RequiredTerm<${ c . name } >` ,
282
- ( ) => RequiredBase ( TermValue . get ( c ) ! ) as t . Type < RequiredTerm < t . TypeOf < U > > >
308
+ ( ) => RequiredBase ( TermValue ( c ) ) as t . Type < RequiredTerm < t . TypeOf < U > > >
283
309
)
284
310
) ;
311
+ export function RequiredTerm < T extends PrimitiveC > (
312
+ c : T
313
+ ) : t . Type < RequiredTerm < t . TypeOf < T > > > {
314
+ return requiredTerm . get ( c ) ! as t . Type < RequiredTerm < t . TypeOf < T > > > ;
315
+ }
285
316
286
317
export interface ProhibitedBase < U > {
287
318
type : 'prohibited' ;
@@ -299,14 +330,18 @@ export const Prohibited = t.recursion<Prohibited>(
299
330
) ;
300
331
export interface ProhibitedTerm < T extends Primitive >
301
332
extends ProhibitedBase < TermValue < T > > { }
302
- export const ProhibitedTerm = forPrimitives (
333
+ const prohibitedTerm = forPrimitives (
303
334
< U extends PrimitiveC > ( c : U ) : t . Type < ProhibitedTerm < t . TypeOf < U > > > =>
304
335
t . recursion (
305
336
`ProhibitedTerm<${ c . name } >` ,
306
- ( ) =>
307
- ProhibitedBase ( TermValue . get ( c ) ! ) as t . Type < ProhibitedTerm < t . TypeOf < U > > >
337
+ ( ) => ProhibitedBase ( TermValue ( c ) ) as t . Type < ProhibitedTerm < t . TypeOf < U > > >
308
338
)
309
339
) ;
340
+ export function ProhibitedTerm < T extends PrimitiveC > (
341
+ c : T
342
+ ) : t . Type < ProhibitedTerm < t . TypeOf < T > > > {
343
+ return prohibitedTerm . get ( c ) ! as t . Type < ProhibitedTerm < t . TypeOf < T > > > ;
344
+ }
310
345
311
346
export interface ConstantScore {
312
347
type : 'constant' ;
@@ -329,35 +364,48 @@ export type NonPrimitiveTermValue<T extends Primitive> =
329
364
| NotTerm < T >
330
365
| RequiredTerm < T >
331
366
| ProhibitedTerm < T > ;
332
- export const NonPrimitiveTermValue = forPrimitives (
367
+ const nonPrimitiveTermValue = forPrimitives (
333
368
< T extends PrimitiveC > ( c : T ) : t . Type < NonPrimitiveTermValue < t . TypeOf < T > > > =>
334
369
t . recursion (
335
370
`NonPrimitiveTermValue<${ c . name } >` ,
336
371
( ) =>
337
372
t . union ( [
338
- AndTerm . get ( c ) ! ,
339
- OrTerm . get ( c ) ! ,
340
- NotTerm . get ( c ) ! ,
341
- RequiredTerm . get ( c ) ! ,
342
- ProhibitedTerm . get ( c ) ! ,
373
+ AndTerm ( c ) ,
374
+ OrTerm ( c ) ,
375
+ NotTerm ( c ) ,
376
+ RequiredTerm ( c ) ,
377
+ ProhibitedTerm ( c ) ,
343
378
] ) as t . Type < NonPrimitiveTermValue < t . TypeOf < T > > >
344
379
)
345
380
) ;
381
+ export function NonPrimitiveTermValue < T extends PrimitiveC > (
382
+ c : T
383
+ ) : t . Type < NonPrimitiveTermValue < t . TypeOf < T > > > {
384
+ return nonPrimitiveTermValue . get ( c ) ! as t . Type <
385
+ NonPrimitiveTermValue < t . TypeOf < T > >
386
+ > ;
387
+ }
346
388
347
389
export interface NamedTerm < T extends Primitive > {
348
390
type : 'namedterm' ;
349
391
field : string ;
350
392
value : TermValue < T > ;
351
393
}
352
- export const NamedTerm = forPrimitives ( < T extends PrimitiveC > ( c : T ) =>
353
- t . type ( {
354
- type : t . literal ( 'namedterm' ) ,
355
- field : t . string ,
356
- value : TermValue . get ( c ) ! ,
357
- } )
394
+ const namedTerm = forPrimitives (
395
+ < T extends PrimitiveC > ( c : T ) =>
396
+ t . type ( {
397
+ type : t . literal ( 'namedterm' ) ,
398
+ field : t . string ,
399
+ value : TermValue ( c ) ,
400
+ } ) as t . Type < NamedTerm < t . TypeOf < T > > >
358
401
) ;
402
+ export function NamedTerm < T extends PrimitiveC > (
403
+ c : T
404
+ ) : t . Type < NamedTerm < t . TypeOf < T > > > {
405
+ return namedTerm . get ( c ) ! as t . Type < NamedTerm < t . TypeOf < T > > > ;
406
+ }
359
407
export type SomeNamedTerm = t . Type < NamedTerm < Primitive > > ;
360
- export const AnyNamedTerm = t . union ( Array . from ( NamedTerm ) . map ( x => x [ 1 ] ) as [
408
+ export const AnyNamedTerm = t . union ( Array . from ( namedTerm ) . map ( x => x [ 1 ] ) as [
361
409
SomeNamedTerm ,
362
410
SomeNamedTerm ,
363
411
...SomeNamedTerm [ ]
@@ -368,14 +416,18 @@ export interface Term<T extends Primitive> {
368
416
type : 'term' ;
369
417
value : TermValue < T > ;
370
418
}
371
- export const Term = forPrimitives ( < T extends PrimitiveC > ( c : T ) =>
372
- t . type ( {
373
- type : t . literal ( 'term' ) ,
374
- value : TermValue . get ( c ) ! ,
375
- } )
419
+ const term = forPrimitives (
420
+ < T extends PrimitiveC > ( c : T ) =>
421
+ t . type ( {
422
+ type : t . literal ( 'term' ) ,
423
+ value : TermValue ( c ) ,
424
+ } ) as t . Type < Term < t . TypeOf < T > > >
376
425
) ;
426
+ export function Term < T extends PrimitiveC > ( c : T ) : t . Type < Term < t . TypeOf < T > > > {
427
+ return term . get ( c ) ! as t . Type < Term < t . TypeOf < T > > > ;
428
+ }
377
429
export type SomeTerm = t . Type < Term < Primitive > > ;
378
- export const AnyTerm = t . union ( Array . from ( Term ) . map ( x => x [ 1 ] ) as [
430
+ export const AnyTerm = t . union ( Array . from ( term ) . map ( x => x [ 1 ] ) as [
379
431
SomeTerm ,
380
432
SomeTerm ,
381
433
...SomeTerm [ ]
@@ -402,14 +454,14 @@ export const Clause = t.recursion<Clause>(
402
454
'Clause' ,
403
455
( ) =>
404
456
t . union ( [
405
- Term . get ( LString ) ! ,
406
- Term . get ( LNumber ) ! ,
407
- Term . get ( LDate ) ! ,
408
- Term . get ( Spatial ) ! ,
409
- NamedTerm . get ( LString ) ! ,
410
- NamedTerm . get ( LNumber ) ! ,
411
- NamedTerm . get ( LDate ) ! ,
412
- NamedTerm . get ( Spatial ) ! ,
457
+ Term ( LString ) ,
458
+ Term ( LNumber ) ,
459
+ Term ( LDate ) ,
460
+ Term ( Spatial ) ,
461
+ NamedTerm ( LString ) ,
462
+ NamedTerm ( LNumber ) ,
463
+ NamedTerm ( LDate ) ,
464
+ NamedTerm ( Spatial ) ,
413
465
ConstantScore ,
414
466
And ,
415
467
Or ,
@@ -420,10 +472,10 @@ export const Clause = t.recursion<Clause>(
420
472
) ;
421
473
422
474
export const AnyTermValue = t . union ( [
423
- TermValue . get ( LNumber ) ! ,
424
- TermValue . get ( LDate ) ! ,
425
- TermValue . get ( LString ) ! ,
426
- TermValue . get ( Spatial ) ! ,
475
+ TermValue ( LString ) ,
476
+ TermValue ( LNumber ) ,
477
+ TermValue ( LDate ) ,
478
+ TermValue ( Spatial ) ,
427
479
] ) ;
428
480
export type AnyTermValue = t . TypeOf < typeof AnyTermValue > ;
429
481
0 commit comments