1
- import { type AppMetadata , type MetadataType , type MetadataPropertyType , type MetadataOperationType , type InputInfo , type KeyValuePair , type MetadataTypes , type AutoQueryConvention , type Filter , type RefInfo , type InputProp , type AppInfo , type MetadataTypeName , MetadataApp } from "@/types"
1
+ import { type AppMetadata , type MetadataType , type MetadataPropertyType , type MetadataOperationType , type InputInfo , type KeyValuePair , type MetadataTypes , type AutoQueryConvention , type Filter , type RefInfo , type InputProp , type AppInfo , type MetadataTypeName , type AutoQueryApis , MetadataApp } from "@/types"
2
2
import { toDate , toCamelCase , chop , map , mapGet , toDateTime , leftPart , JsonServiceClient } from '@servicestack/client'
3
3
import { computed , inject } from 'vue'
4
4
import { Sole } from './config'
@@ -81,7 +81,7 @@ function typeName(metaType?:MetadataTypeName) {
81
81
82
82
83
83
/** Capture AutoQuery APIs */
84
- export class Apis
84
+ export class Apis implements AutoQueryApis
85
85
{
86
86
Query ?: MetadataOperationType ;
87
87
QueryInto ?: MetadataOperationType ;
@@ -128,6 +128,17 @@ export class Apis
128
128
129
129
static forType ( type ?:string | null , metaTypes ?:MetadataTypes | null ) {
130
130
let apis = new Apis ( )
131
+ if ( Sole . config . apisResolver && type ) {
132
+ const aqApis = Sole . config . apisResolver ( type , metaTypes )
133
+ if ( aqApis ) {
134
+ apis . Query = aqApis . Query
135
+ apis . QueryInto = aqApis . QueryInto
136
+ apis . Create = aqApis . Create
137
+ apis . Update = aqApis . Update
138
+ apis . Patch = aqApis . Patch
139
+ apis . Delete = aqApis . Delete
140
+ }
141
+ }
131
142
if ( type ) {
132
143
metaTypes ??= Sole . metadata . value ?. api
133
144
metaTypes ?. operations . forEach ( op => {
@@ -406,6 +417,10 @@ async function loadMetadata(args:{
406
417
* @param [namespace] - Find MetadataType by name and namespace
407
418
*/
408
419
export function typeOf ( name ?:string | null , namespace ?:string | null ) {
420
+ if ( Sole . config . typeResolver ) {
421
+ let type = Sole . config . typeResolver ( name ! , namespace )
422
+ if ( type ) return type
423
+ }
409
424
let api = Sole . metadata . value ?. api
410
425
if ( ! api || ! name ) return null
411
426
let type = api . types . find ( x => x . name . toLowerCase ( ) === name . toLowerCase ( ) && ( ! namespace || x . namespace == namespace ) )
@@ -419,6 +434,10 @@ export function typeOf(name?:string|null, namespace?:string|null) {
419
434
420
435
/** Resolve Request DTO {MetadataOperationType} by name */
421
436
export function apiOf ( name :string ) {
437
+ if ( Sole . config . apiResolver ) {
438
+ const op = Sole . config . apiResolver ( name )
439
+ if ( op ) return op
440
+ }
422
441
let api = Sole . metadata . value ?. api
423
442
if ( ! api ) return null
424
443
let requestOp = api . operations . find ( x => x . request . name . toLowerCase ( ) === name . toLowerCase ( ) )
@@ -669,12 +688,30 @@ export function formatFilterValue(type:string, value:string) {
669
688
: `'${ value } '`
670
689
}
671
690
691
+ function nv ( name :string , value :string ) { return { name, value } }
692
+
693
+ const defaultViewerConventions :AutoQueryConvention [ ] = [
694
+ nv ( "=" , "%" ) ,
695
+ nv ( "!=" , "%!" ) ,
696
+ nv ( ">=" , ">%" ) ,
697
+ nv ( ">" , "%>" ) ,
698
+ nv ( "<=" , "%<" ) ,
699
+ nv ( "<" , "<%" ) ,
700
+ nv ( "In" , "%In" ) ,
701
+ nv ( "Between" , "%Between" ) ,
702
+ { name : "Starts With" , value : "%StartsWith" , types : "string" } ,
703
+ { name : "Contains" , value : "%Contains" , types : "string" } ,
704
+ { name : "Ends With" , value : "%EndsWith" , types : "string" } ,
705
+ { name : "Exists" , value : "%IsNotNull" , valueType : "none" } ,
706
+ { name : "Not Exists" , value : "%IsNull" , valueType : "none" } ,
707
+ ]
708
+
672
709
export function useMetadata ( ) {
673
710
674
711
/** Reactive accessor to Ref<MetadataTypes> */
675
712
const metadataApp = computed < AppInfo | null > ( ( ) => Sole . metadata . value ?. app || null )
676
713
const metadataApi = computed < MetadataTypes | null > ( ( ) => Sole . metadata . value ?. api || null )
677
- const filterDefinitions = computed < AutoQueryConvention [ ] > ( ( ) => Sole . metadata . value ?. plugins . autoQuery . viewerConventions || [ ] )
714
+ const filterDefinitions = computed < AutoQueryConvention [ ] > ( ( ) => Sole . metadata . value ?. plugins ? .autoQuery ? .viewerConventions || defaultViewerConventions )
678
715
679
716
tryLoad ( )
680
717
0 commit comments