Comparing version 0.16.9 to 0.17.0
@@ -15,3 +15,5 @@ import { ApiQueryScope } from "../query/ApiQuery"; | ||
execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>; | ||
parameters: string[]; | ||
constructor(name: string, execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, scope?: ApiEdgeMethodScope, acceptedTypes?: ApiRequestType, requiresData?: boolean); | ||
constructor(name: string, execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, scope?: ApiEdgeMethodScope, acceptedTypes?: ApiRequestType, parameters?: string[]); | ||
} |
@@ -11,5 +11,10 @@ "use strict"; | ||
class ApiEdgeMethod { | ||
constructor(name, execute, scope = ApiEdgeMethodScope.Edge, acceptedTypes = ApiRequest_1.ApiRequestType.Any, requiresData = true) { | ||
constructor(name, execute, scope = ApiEdgeMethodScope.Edge, acceptedTypes = ApiRequest_1.ApiRequestType.Any, parametersOrData = [], requiresData = true) { | ||
this.acceptedTypes = ApiRequest_1.ApiRequestType.Any; | ||
this.scope = ApiEdgeMethodScope.Edge; | ||
let parameters = []; | ||
if (typeof parametersOrData === 'boolean') | ||
requiresData = parametersOrData; | ||
else | ||
parameters = parametersOrData; | ||
this.name = name; | ||
@@ -20,2 +25,3 @@ this.scope = scope; | ||
this.requiresData = requiresData; | ||
this.parameters = parameters; | ||
} | ||
@@ -22,0 +28,0 @@ } |
import { ApiEdgeQueryFilter, ApiEdgeQueryFilterType, ExportedApiEdgeQueryFilter } from "./ApiEdgeQueryFilter"; | ||
import { OneToOneRelation } from "../relations/OneToOneRelation"; | ||
import { Api } from "../Api"; | ||
import { ApiEdgeQueryParameter, ExportedApiEdgeQueryParameter } from "./ApiEdgeQueryParameter"; | ||
export interface ExportedApiEdgeQueryContext { | ||
@@ -14,2 +15,3 @@ id: string | null; | ||
filters: ExportedApiEdgeQueryFilter[]; | ||
parameters: ExportedApiEdgeQueryParameter[]; | ||
} | ||
@@ -26,2 +28,3 @@ export declare class ApiEdgeQueryContext { | ||
filters: ApiEdgeQueryFilter[]; | ||
parameters: ApiEdgeQueryParameter[]; | ||
clone: () => ApiEdgeQueryContext; | ||
@@ -36,2 +39,4 @@ toJSON: () => ExportedApiEdgeQueryContext; | ||
filter(field: string, type: ApiEdgeQueryFilterType, value: any): this; | ||
parameter(key: string): any; | ||
parameter(key: string, value: any): ApiEdgeQueryContext; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ApiEdgeQueryFilter_1 = require("./ApiEdgeQueryFilter"); | ||
const ApiEdgeQueryParameter_1 = require("./ApiEdgeQueryParameter"); | ||
class ApiEdgeQueryContext { | ||
@@ -10,2 +11,3 @@ constructor(id = null, fields = []) { | ||
this.filters = []; | ||
this.parameters = []; | ||
this.clone = () => { | ||
@@ -17,2 +19,3 @@ let temp = new ApiEdgeQueryContext(); | ||
this.filters.forEach(f => temp.filters.push(f.clone())); | ||
this.parameters.forEach(f => temp.parameters.push(f.clone())); | ||
this.sortBy.forEach(f => temp.sortBy.push([f[0], f[1]])); | ||
@@ -34,3 +37,4 @@ if (this.pagination) { | ||
sortBy: this.sortBy, | ||
filters: this.filters | ||
filters: this.filters, | ||
parameters: this.parameters, | ||
}; | ||
@@ -63,2 +67,12 @@ }; | ||
} | ||
parameter(key, value) { | ||
if (typeof value === "undefined") { | ||
const param = this.parameters.find(p => p.key === key); | ||
return param ? param.value : null; | ||
} | ||
else { | ||
this.parameters.push(new ApiEdgeQueryParameter_1.ApiEdgeQueryParameter(key, value)); | ||
return this; | ||
} | ||
} | ||
} | ||
@@ -73,2 +87,3 @@ ApiEdgeQueryContext.fromJSON = (obj, api) => { | ||
context.filters = obj.filters.map(({ field, type, value }) => new ApiEdgeQueryFilter_1.ApiEdgeQueryFilter(field, type, value)); | ||
context.parameters = obj.parameters.map(({ key, value }) => new ApiEdgeQueryParameter_1.ApiEdgeQueryParameter(key, value)); | ||
return context; | ||
@@ -75,0 +90,0 @@ }; |
{ | ||
"name": "api-core", | ||
"version": "0.16.9", | ||
"version": "0.17.0", | ||
"description": "Model-based dynamic multi-level APIs for any provider, plus multiple consumption channels", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -30,8 +30,24 @@ import {QueryStep, ApiQueryScope} from "../query/ApiQuery"; | ||
execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>; | ||
parameters: string[]; | ||
constructor(name: string, | ||
execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, | ||
scope?: ApiEdgeMethodScope, | ||
acceptedTypes?: ApiRequestType, | ||
requiresData?: boolean); | ||
constructor(name: string, | ||
execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, | ||
scope?: ApiEdgeMethodScope, | ||
acceptedTypes?: ApiRequestType, | ||
parameters?: string[]); | ||
constructor(name: string, | ||
execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, | ||
scope: ApiEdgeMethodScope = ApiEdgeMethodScope.Edge, | ||
acceptedTypes: ApiRequestType = ApiRequestType.Any, | ||
parametersOrData: string[]|boolean = [], | ||
requiresData = true) { | ||
let parameters: string[] = []; | ||
if(typeof parametersOrData === 'boolean') requiresData = parametersOrData; | ||
else parameters = parametersOrData; | ||
this.name = name; | ||
@@ -42,3 +58,4 @@ this.scope = scope; | ||
this.requiresData = requiresData; | ||
this.parameters = parameters; | ||
} | ||
} |
import {ApiEdgeQueryFilter, ApiEdgeQueryFilterType, ExportedApiEdgeQueryFilter} from "./ApiEdgeQueryFilter"; | ||
import {OneToOneRelation} from "../relations/OneToOneRelation"; | ||
import {Api} from "../Api"; | ||
import {ApiEdgeQueryParameter, ExportedApiEdgeQueryParameter} from "./ApiEdgeQueryParameter"; | ||
@@ -15,2 +16,3 @@ export interface ExportedApiEdgeQueryContext { | ||
filters: ExportedApiEdgeQueryFilter[] | ||
parameters: ExportedApiEdgeQueryParameter[] | ||
} | ||
@@ -28,2 +30,3 @@ | ||
filters: ApiEdgeQueryFilter[] = []; | ||
parameters: ApiEdgeQueryParameter[] = []; | ||
@@ -37,2 +40,3 @@ clone = () => { | ||
this.filters.forEach(f => temp.filters.push(f.clone())); | ||
this.parameters.forEach(f => temp.parameters.push(f.clone())); | ||
this.sortBy.forEach(f => temp.sortBy.push([f[0], f[1]])); | ||
@@ -57,3 +61,4 @@ | ||
sortBy: this.sortBy, | ||
filters: this.filters | ||
filters: this.filters, | ||
parameters: this.parameters, | ||
} | ||
@@ -74,2 +79,5 @@ }; | ||
); | ||
context.parameters = obj.parameters.map( | ||
({ key, value }) => new ApiEdgeQueryParameter(key, value) | ||
); | ||
return context | ||
@@ -109,2 +117,15 @@ }; | ||
} | ||
parameter(key: string): any; | ||
parameter(key: string, value: any): ApiEdgeQueryContext; | ||
parameter(key: string, value?: any): ApiEdgeQueryContext|any { | ||
if(typeof value === "undefined") { | ||
const param = this.parameters.find(p => p.key === key); | ||
return param ? param.value : null | ||
} | ||
else { | ||
this.parameters.push(new ApiEdgeQueryParameter(key, value)); | ||
return this | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
608502
164
7526