@mcma/api
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -71,3 +71,3 @@ import { ContextVariableProvider, Resource, ResourceType } from "@mcma/core"; | ||
publicUrl(): string; | ||
workerFunctionName(): string; | ||
workerFunctionId(): string; | ||
} | ||
@@ -93,4 +93,17 @@ } | ||
export type InvokeWorker = (workerFunctionName: string, payload: any) => Promise<void>; | ||
export interface WorkerRequest { | ||
operationName: string; | ||
contextVariables: { [key: string]: string }; | ||
input: any; | ||
} | ||
export type InvokeWorker = (workerFunctionId: string, payload: WorkerRequest) => Promise<void>; | ||
export class WorkerInvoker { | ||
constructor(invokeWorker: InvokeWorker); | ||
invoke(workerFunctionId: string, operationName: string, contextVariables: { [key: string]: string }, input: any): Promise<void>; | ||
invoke(workerFunctionId: string, workerRequest: WorkerRequest): Promise<void>; | ||
} | ||
export type DbTableProviderFactory<T extends Resource> = (type: ResourceType<T>) => DbTableProvider<T>; | ||
@@ -119,5 +132,6 @@ | ||
export interface DefaultRouteCollectionBuilder { | ||
export class DefaultRouteCollectionBuilder<T extends Resource> { | ||
constructor(dbTableProvider: DbTableProvider<T>, resourceType: ResourceType<T>, root?: string); | ||
addAll(): DefaultRouteCollectionBuilder; | ||
route<T extends Resource>(selectRoute: (defaultRoutes: DefaultRoutes<T>) => DefaultRouteBuilder<T>): DefaultRouteConfigurator<T>; | ||
route(selectRoute: (defaultRoutes: DefaultRoutes<T>) => DefaultRouteBuilder<T>): DefaultRouteConfigurator<T>; | ||
build(): McmaApiRouteCollection; | ||
@@ -132,4 +146,2 @@ | ||
export function defaultRoutes<T extends Resource>(type: ResourceType<T>): DefaultRoutesBuilderFactory; | ||
export class McmaApiController { | ||
@@ -136,0 +148,0 @@ constructor(routes: McmaApiRouteCollection); |
const { HttpStatusCode } = require("./lib/http-statuses"); | ||
const { McmaApiRequest, McmaApiResponse, McmaApiRequestContext } = require("./lib/mcma-request-context"); | ||
const { McmaApiRoute, McmaApiRouteCollection } = require("./lib/routes/route-collection"); | ||
const { defaultRoutes } = require("./lib/routes/default-routes"); | ||
const { DefaultRoutesCollectionBuilder } = require("./lib/routes/default-routes"); | ||
const { McmaApiController } = require("./lib/mcma-api-controller"); | ||
const { WorkerInvoker } = require("./lib/worker-invoker"); | ||
@@ -16,4 +17,5 @@ require("./lib/routes/default-routes-jobs-ext"); | ||
McmaApiRouteCollection, | ||
defaultRoutes, | ||
McmaApiController | ||
DefaultRoutesCollectionBuilder, | ||
McmaApiController, | ||
WorkerInvoker | ||
}; |
@@ -1,2 +0,2 @@ | ||
const { ContextVariableProvider } = require("mcma-core"); | ||
const { ContextVariableProvider } = require("@mcma/core"); | ||
const { HttpStatusCode } = require("./http-statuses"); | ||
@@ -66,4 +66,4 @@ | ||
ContextVariableProvider.prototype.workerFunctionName = function workerFunctionName() { | ||
return this.getRequiredContextVariable("WorkerFunctionName"); | ||
ContextVariableProvider.prototype.workerFunctionId = function workerFunctionId() { | ||
return this.getRequiredContextVariable("WorkerFunctionId"); | ||
} | ||
@@ -70,0 +70,0 @@ |
@@ -11,3 +11,3 @@ const { DefaultRouteCollectionBuilder } = require("./default-routes"); | ||
rb.onCompleted(async (requestContext, jobAssignment) => | ||
await invokeWorker(requestContext.workerFunctionName(), { | ||
await invokeWorker(requestContext.workerFunctionId(), { | ||
operationName: "ProcessJobAssignment", | ||
@@ -14,0 +14,0 @@ contextVariables: requestContext.getAllContextVariables(), |
const uuidv4 = require("uuid/v4"); | ||
const { Utils, onResourceCreate, onResourceUpsert } = require("mcma-core"); | ||
const { Utils, onResourceCreate, onResourceUpsert } = require("@mcma/core"); | ||
@@ -19,3 +19,3 @@ const filters = require("../filters"); | ||
return this; | ||
} | ||
}; | ||
@@ -25,7 +25,7 @@ this.onCompleted = (x) => { | ||
return this; | ||
} | ||
}; | ||
this.build = () => { | ||
return new McmaApiRoute(httpMethod, path, handler || defaultHandlerBuilder.create()); | ||
} | ||
}; | ||
} | ||
@@ -61,3 +61,9 @@ } | ||
class DefaultRouteCollectionBuilder { | ||
constructor(dbTableProvider, root) { | ||
constructor(dbTableProvider, resourceType, root) { | ||
resourceType = Utils.getTypeName(resourceType); | ||
if (!resourceType) { | ||
throw new Error("Invalid resource type specified for default routes."); | ||
} | ||
root = root || pluralizeKebabCase(camelCaseToKebabCase(resourceType)); | ||
if (root[0] !== "/") { | ||
@@ -265,13 +271,4 @@ root = "/" + root; | ||
function defaultRoutes(type) { | ||
type = Utils.getTypeName(type); | ||
return { | ||
builder: (getDbTableProvider, root) => | ||
new DefaultRouteCollectionBuilder(getDbTableProvider(type), root || pluralizeKebabCase(camelCaseToKebabCase(type))) | ||
}; | ||
} | ||
module.exports = { | ||
DefaultRouteCollectionBuilder, | ||
defaultRoutes | ||
DefaultRouteCollectionBuilder | ||
}; |
{ | ||
"name": "@mcma/api", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Node module for building APIs based on the EBU MCMA framework", | ||
@@ -29,4 +29,4 @@ "engines": { | ||
"dependencies": { | ||
"@mcma/client": "0.4.1", | ||
"@mcma/data": "0.4.1", | ||
"@mcma/client": "0.4.2", | ||
"@mcma/data": "0.4.2", | ||
"pluralize": "^7.0.0", | ||
@@ -33,0 +33,0 @@ "uri-templates": "^0.2.0", |
31104
12
757
+ Added@mcma/client@0.4.2(transitive)
+ Added@mcma/core@0.4.2(transitive)
+ Added@mcma/data@0.4.2(transitive)
- Removed@mcma/client@0.4.1(transitive)
- Removed@mcma/core@0.4.1(transitive)
- Removed@mcma/data@0.4.1(transitive)
Updated@mcma/client@0.4.2
Updated@mcma/data@0.4.2