Comparing version 0.0.7-alpha.4 to 0.0.8-alpha.1
@@ -11,3 +11,3 @@ export { ApiEdgeDefinition } from "./src/edge/ApiEdgeDefinition"; | ||
export { OneToManyRelation } from "./src/relations/OneToManyRelation"; | ||
export { ApiRequest } from "./src/request/ApiRequest"; | ||
export { ApiRequest, ApiRequestType } from "./src/request/ApiRequest"; | ||
export { ApiRequestPathParser } from "./src/request/ApiRequestParser"; | ||
@@ -14,0 +14,0 @@ export { ApiQuery } from "./src/query/ApiQuery"; |
@@ -21,2 +21,3 @@ "use strict"; | ||
exports.ApiRequest = ApiRequest_1.ApiRequest; | ||
exports.ApiRequestType = ApiRequest_1.ApiRequestType; | ||
var ApiRequestParser_1 = require("./src/request/ApiRequestParser"); | ||
@@ -23,0 +24,0 @@ exports.ApiRequestPathParser = ApiRequestParser_1.ApiRequestPathParser; |
@@ -5,2 +5,3 @@ import { ApiEdgeQueryContext } from "../edge/ApiEdgeQueryContext"; | ||
context: ApiEdgeQueryContext; | ||
body: any | null; | ||
response: ApiEdgeQueryResponse | null; | ||
@@ -7,0 +8,0 @@ } |
@@ -29,3 +29,3 @@ "use strict"; | ||
}; | ||
next({ context: new ApiEdgeQueryContext_1.ApiEdgeQueryContext(), response: null }); | ||
next({ context: new ApiEdgeQueryContext_1.ApiEdgeQueryContext(), body: null, response: null }); | ||
}); | ||
@@ -32,0 +32,0 @@ }; |
@@ -11,3 +11,4 @@ import { ApiQuery } from "./ApiQuery"; | ||
private buildReadQuery; | ||
private buildCreateQuery; | ||
build: (request: ApiRequest) => ApiQuery; | ||
} |
@@ -16,2 +16,3 @@ "use strict"; | ||
return new Promise(function (resolve, reject) { | ||
_this.query.body = scope.body; | ||
_this.query.context = scope.context; | ||
@@ -87,2 +88,16 @@ _this.query.execute().then(function (response) { | ||
}()); | ||
var SetBodyQueryStep = (function () { | ||
function SetBodyQueryStep(body) { | ||
var _this = this; | ||
this.execute = function (scope) { | ||
return new Promise(function (resolve) { | ||
scope.body = _this.body; | ||
resolve(scope); | ||
}); | ||
}; | ||
this.inspect = function () { return "SET BODY"; }; | ||
this.body = body; | ||
} | ||
return SetBodyQueryStep; | ||
}()); | ||
var ProvideIdQueryStep = (function () { | ||
@@ -162,2 +177,4 @@ function ProvideIdQueryStep(fieldName) { | ||
query.unshift(new QueryEdgeQueryStep(baseQuery)); | ||
if (request.body) | ||
query.unshift(new SetBodyQueryStep(request.body)); | ||
query.unshift(new ExtendContextQueryStep(request.context)); | ||
@@ -188,6 +205,20 @@ if (lastSegment instanceof ApiRequest_1.EntryPathSegment) { | ||
}; | ||
this.buildCreateQuery = function (request) { | ||
var query = new ApiQuery_1.ApiQuery(); | ||
var segments = request.path.segments, lastSegment = segments[segments.length - 1]; | ||
if (segments.length != 1 || !(lastSegment instanceof ApiRequest_1.EdgePathSegment)) { | ||
throw new ApiEdgeError_1.ApiEdgeError(400, "Invalid Create Query"); | ||
} | ||
query.unshift(new QueryEdgeQueryStep(new ApiEdgeQuery_1.ApiEdgeQuery(lastSegment.edge, ApiEdgeQueryType_1.ApiEdgeQueryType.Create))); | ||
query.unshift(new SetBodyQueryStep(request.body)); | ||
return query; | ||
}; | ||
this.build = function (request) { | ||
switch (request.type) { | ||
case ApiRequest_1.ApiRequestType.Read: | ||
case ApiRequest_1.ApiRequestType.Update: | ||
case ApiRequest_1.ApiRequestType.Delete: | ||
return _this.buildReadQuery(request); | ||
case ApiRequest_1.ApiRequestType.Create: | ||
return _this.buildCreateQuery(request); | ||
default: | ||
@@ -194,0 +225,0 @@ throw new ApiEdgeError_1.ApiEdgeError(400, "Unsupported Query Type"); |
@@ -44,4 +44,5 @@ import { ApiEdgeDefinition } from "../edge/ApiEdgeDefinition"; | ||
path: ApiRequestPath; | ||
body: any | null; | ||
context: ApiEdgeQueryContext; | ||
constructor(); | ||
} |
@@ -84,2 +84,3 @@ "use strict"; | ||
function ApiRequest() { | ||
this.body = null; | ||
this.path = new ApiRequestPath(); | ||
@@ -86,0 +87,0 @@ this.type = ApiRequestType.Read; |
@@ -5,3 +5,3 @@ export {ApiEdgeDefinition} from "./src/edge/ApiEdgeDefinition"; | ||
export {ApiEdgeQueryResponse} from "./src/edge/ApiEdgeQueryResponse"; | ||
export {ApiEdgeQueryFilter,ApiEdgeQueryFilterType} from "./src/edge/ApiEdgeQueryFilter"; | ||
export {ApiEdgeQueryFilter, ApiEdgeQueryFilterType} from "./src/edge/ApiEdgeQueryFilter"; | ||
export {ApiEdgeQuery} from "./src/edge/ApiEdgeQuery"; | ||
@@ -14,3 +14,3 @@ export {ApiEdgeError} from "./src/query/ApiEdgeError"; | ||
export {ApiRequest} from "./src/request/ApiRequest"; | ||
export {ApiRequest, ApiRequestType} from "./src/request/ApiRequest"; | ||
export {ApiRequestPathParser} from "./src/request/ApiRequestParser"; | ||
@@ -17,0 +17,0 @@ |
{ | ||
"name": "api-core", | ||
"version": "0.0.7-alpha.4", | ||
"version": "0.0.8-alpha.1", | ||
"description": "Core classes for building dynamic model based multi-level APIs for any provider.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -7,2 +7,3 @@ import {ApiEdgeQueryContext} from "../edge/ApiEdgeQueryContext"; | ||
context: ApiEdgeQueryContext, | ||
body: any|null, | ||
response: ApiEdgeQueryResponse|null | ||
@@ -42,5 +43,5 @@ } | ||
next({ context: new ApiEdgeQueryContext(), response: null}); | ||
next({ context: new ApiEdgeQueryContext(), body: null, response: null}); | ||
}) | ||
} | ||
} |
@@ -25,2 +25,3 @@ import {QueryStep, QueryScope, ApiQuery} from "./ApiQuery"; | ||
return new Promise((resolve, reject) => { | ||
this.query.body = scope.body; | ||
this.query.context = scope.context; | ||
@@ -102,2 +103,19 @@ //console.log(`QUERY /${this.query.edge.pluralName}`, scope.context); | ||
class SetBodyQueryStep implements QueryStep { | ||
body: any; | ||
constructor(body: any) { | ||
this.body = body; | ||
} | ||
execute = (scope: QueryScope) => { | ||
return new Promise(resolve => { | ||
scope.body = this.body; | ||
resolve(scope); | ||
}) | ||
}; | ||
inspect = () => `SET BODY`; | ||
} | ||
class ProvideIdQueryStep implements QueryStep { | ||
@@ -245,2 +263,3 @@ fieldName: string; | ||
//STEP 2: Provide context for the base query. | ||
if(request.body) query.unshift(new SetBodyQueryStep(request.body)); | ||
query.unshift(new ExtendContextQueryStep(request.context)); | ||
@@ -283,6 +302,32 @@ | ||
private buildCreateQuery = (request: ApiRequest): ApiQuery => { | ||
let query = new ApiQuery(); | ||
let segments = request.path.segments, | ||
lastSegment = segments[segments.length-1]; | ||
//STEP 1: Validate query | ||
if(segments.length != 1 || !(lastSegment instanceof EdgePathSegment)) { | ||
throw new ApiEdgeError(400, "Invalid Create Query") | ||
} | ||
//STEP 2: Create the base query which will provide the final data. | ||
query.unshift(new QueryEdgeQueryStep(new ApiEdgeQuery(lastSegment.edge, ApiEdgeQueryType.Create))); | ||
//STEP 3: Provide context for the base query. | ||
query.unshift(new SetBodyQueryStep(request.body)); | ||
//STEP 4: Return the completed query. | ||
return query | ||
}; | ||
build = (request: ApiRequest): ApiQuery => { | ||
switch(request.type) { | ||
case ApiRequestType.Read: | ||
case ApiRequestType.Update: | ||
case ApiRequestType.Delete: | ||
return this.buildReadQuery(request); | ||
case ApiRequestType.Create: | ||
return this.buildCreateQuery(request); | ||
default: | ||
@@ -289,0 +334,0 @@ throw new ApiEdgeError(400, "Unsupported Query Type") |
@@ -85,2 +85,3 @@ import {ApiEdgeDefinition} from "../edge/ApiEdgeDefinition"; | ||
path: ApiRequestPath; | ||
body: any|null = null; //Should be request context | ||
context: ApiEdgeQueryContext; //Should be request context | ||
@@ -87,0 +88,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
308238
4370