-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Implement views. * Update sample applications. * Add views to blank application template. * feat: Add queryView api. * feat: Implement executeQueryHandler and queryView api. * feat: Add views description endpoint; Add API tests. * Add client for querying views. * Add client for query view API. * Add query view API to processes. * Add view openapi definitions to runtimes. * Add view server to microservice manifest. * Fix eslint issue. * Fix some tests. * 4.0.0-internal.46 * Fix some issues in application templates. * 4.0.0-internal.47 * Rename collection in blank application templates. * 4.0.0-internal.48 * Fix flows in blank application template. * 4.0.0-internal.49 * Fix a type in blank/typescript. * 4.0.0-internal.50 * Fix another type, this time in chat-simplified/typescript. * 4.0.0-internal.51 * Add some stuff to npmignore. * Adjust some cli tests. * feat: Implement sandbox for views. * 4.0.0-internal.52 * chore: Add view tests using new sandbox to templates. * chore: Add eslint support for templates; Fix a lot of eslint issue. * 4.0.0-internal.53 * fix: Add missing port of view server to docker compose manifest. * feat: Add debug logging to domain and flow server. * 4.0.0-internal.54 * chore: Add section about views http endpoint to readme. * Add missing comma. * Remove implementation from blank template applications. * Fix package.json file. * Clean up sample code. * Reorder tsconfig.json files. * Fix CLI tests. Co-authored-by: Hannes Leutloff <hannes.leutloff@thenativeweb.io>
- Loading branch information
Showing
319 changed files
with
4,663 additions
and
2,604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
/.dependabot | ||
/.github | ||
/.idea | ||
/.vscode | ||
/assets | ||
/build/test | ||
/docker | ||
/lib | ||
/test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ApiDefinition } from '../../openApi/ApiDefinition'; | ||
import { Application } from '../../../common/application/Application'; | ||
import { query } from './v2/query'; | ||
|
||
const getApiDefinitions = function ({ application, basePath }: { | ||
application: Application; | ||
basePath: string; | ||
}): ApiDefinition[] { | ||
const apiDefinitions: ApiDefinition[] = []; | ||
|
||
const v2ApiDefinition: ApiDefinition = { | ||
basePath: `${basePath}/v2`, | ||
routes: { | ||
get: [], | ||
post: [] | ||
}, | ||
tags: [ 'Views' ] | ||
}; | ||
|
||
for (const [ viewName, viewDefinition ] of Object.entries(application.views)) { | ||
for (const [ queryHandlerName, queryDefinition ] of Object.entries(viewDefinition.queryHandlers)) { | ||
v2ApiDefinition.routes.get.push({ | ||
path: `${viewName}/${queryHandlerName}`, | ||
description: queryDefinition.getDocumentation ? queryDefinition.getDocumentation() : query.description, | ||
request: { | ||
query: queryDefinition.getOptionsSchema ? queryDefinition.getOptionsSchema() : query.request.query | ||
}, | ||
response: { | ||
statusCodes: query.response.statusCodes, | ||
stream: queryDefinition.type === 'stream', | ||
body: queryDefinition.getResultItemSchema ? queryDefinition.getResultItemSchema() : {} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
apiDefinitions.push(v2ApiDefinition); | ||
|
||
return apiDefinitions; | ||
}; | ||
|
||
export { getApiDefinitions }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ApiDefinition } from '../../openApi/ApiDefinition'; | ||
import { Application } from '../../../common/application/Application'; | ||
import { CorsOrigin } from 'get-cors-origin'; | ||
import { getApiDefinitions } from './getApiDefinitions'; | ||
import { getV2 } from './v2'; | ||
import { IdentityProvider } from 'limes'; | ||
import express, { Application as ExpressApplication } from 'express'; | ||
|
||
const getApi = async function<TItem> ({ application, corsOrigin, identityProviders }: { | ||
application: Application; | ||
corsOrigin: CorsOrigin; | ||
identityProviders: IdentityProvider[]; | ||
}): Promise<{ api: ExpressApplication; getApiDefinitions: (basePath: string) => ApiDefinition[] }> { | ||
const api = express(); | ||
|
||
const v2 = await getV2<TItem>({ | ||
application, | ||
corsOrigin, | ||
identityProviders | ||
}); | ||
|
||
api.use('/v2', v2.api); | ||
|
||
return { | ||
api, | ||
getApiDefinitions: (basePath: string): ApiDefinition[] => getApiDefinitions({ application, basePath }) | ||
}; | ||
}; | ||
|
||
export { getApi }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import axios from 'axios'; | ||
import { errors } from '../../../../common/errors'; | ||
import { flaschenpost } from 'flaschenpost'; | ||
import { HttpClient } from '../../../shared/HttpClient'; | ||
import { ParseJsonTransform } from '../../../../common/utils/http/ParseJsonTransform'; | ||
import { QueryDescription } from '../../../../common/application/QueryDescription'; | ||
import streamToString from 'stream-to-string'; | ||
import { PassThrough, pipeline } from 'stream'; | ||
|
||
const logger = flaschenpost.getLogger(); | ||
|
||
class Client extends HttpClient { | ||
public constructor ({ protocol = 'http', hostName, port, path = '/' }: { | ||
protocol?: string; | ||
hostName: string; | ||
port: number; | ||
path?: string; | ||
}) { | ||
super({ protocol, hostName, port, path }); | ||
} | ||
|
||
public async getDescription (): Promise<Record<string, Record<string, QueryDescription>>> { | ||
const { data, status } = await axios({ | ||
method: 'get', | ||
url: `${this.url}/description`, | ||
validateStatus (): boolean { | ||
return true; | ||
} | ||
}); | ||
|
||
if (status === 200) { | ||
return data; | ||
} | ||
|
||
logger.error('An unknown error occured.', { ex: data, status }); | ||
|
||
throw new errors.UnknownError(); | ||
} | ||
|
||
public async query ({ viewName, queryName, queryOptions = {}}: { | ||
viewName: string; | ||
queryName: string; | ||
queryOptions?: object; | ||
}): Promise<PassThrough> { | ||
const { data, status } = await axios({ | ||
method: 'get', | ||
url: `${this.url}/${viewName}/${queryName}`, | ||
params: queryOptions, | ||
paramsSerializer (params): string { | ||
return Object.entries(params). | ||
map(([ key, value ]): string => `${key}=${JSON.stringify(value)}`). | ||
join('&'); | ||
}, | ||
responseType: 'stream', | ||
validateStatus (): boolean { | ||
return true; | ||
} | ||
}); | ||
|
||
if (status !== 200) { | ||
const error = JSON.parse(await streamToString(data)); | ||
|
||
switch (error.code) { | ||
case 'EVIEWNOTFOUND': { | ||
throw new errors.ViewNotFound(error.message); | ||
} | ||
case 'EQUERYHANDLERNOTFOUND': { | ||
throw new errors.QueryHandlerNotFound(error.message); | ||
} | ||
case 'EQUERYOPTIONSINVALID': { | ||
throw new errors.QueryOptionsInvalid(error.message); | ||
} | ||
default: { | ||
logger.error('An unknown error occured.', { ex: error, status }); | ||
|
||
throw new errors.UnknownError(); | ||
} | ||
} | ||
} | ||
|
||
const jsonParser = new ParseJsonTransform(); | ||
|
||
return pipeline( | ||
data, | ||
jsonParser, | ||
(err): void => { | ||
if (err) { | ||
// Do not handle errors explicitly. The returned stream will just close. | ||
logger.error('An error occured during stream piping.', { err }); | ||
} | ||
} | ||
); | ||
} | ||
} | ||
|
||
export { Client }; |
Oops, something went wrong.