UNPKG

4.22 kBPlain TextView Raw
1
2import React, { ReactNode } from 'react';
3
4import Types from '../types';
5import { IConfiguration } from "../types/configuration";
6import { IInfrastructure } from "../types";
7
8import { isRoute } from '../route/route-component';
9
10import {getChildrenArray, findComponentRecursively} from '../libs';
11
12import { SoaPlugin } from './soa-plugin';
13import { EnvironmentPlugin } from '../environment/environment-plugin';
14import { ServicePlugin } from "../service/service-plugin";
15import { isService } from "../service/service-component";
16import {DataLayerPlugin} from "../datalayer/datalayer-plugin";
17import {isDataLayer} from "../datalayer/datalayer-component";
18import {StoragePlugin} from "../storage/storage-plugin";
19import {isStorage} from "../storage/storage-component";
20
21export const SERVICEORIENTED_INSTANCE_TYPE = "ServiceOrientedComponent";
22
23/**
24 * Specifies all the properties that an SinglePage-Component must get from the user, as args
25 */
26export interface IServiceOrientedArgs {
27
28 /**
29 * name of the Cloudformation Stack
30 */
31 stackName: string,
32
33 /**
34 * Local, relative directory specifies where to put the final bundles
35 */
36 buildPath: string,
37
38 /**
39 * The AWS region
40 */
41 region: string
42}
43
44/**
45 * specifies the properties that an SinglePage-Component has during runtime
46 * nothing else than we get from the user!
47 */
48export interface IServiceOrientedProps {
49 /**
50 * the SPA is webapp and must have an id
51 */
52 id: string,
53
54 /**
55 * Routes of the webapp
56 */
57 routes: Array<any>,
58
59 /**
60 * redirects of the webapp
61 */
62 redirects: Array<any>,
63
64 /**
65 * Services of the app
66 */
67 services: Array<any>,
68
69 /**
70 * Filled when the Isomorphic App has a DataLayer
71 */
72 dataLayerId?: string,
73
74 /**
75 * Additional iam-permissions
76 * e.g. [
77 * {
78 * Effect: "Allow",
79 * Action: ["dynamodb:Query"],
80 * Resource: "arn:aws:dynamodb:us-west-2:111110002222:table/my-new-table"
81 * }
82 * ]
83 */
84 iamRoleStatements?: Array<any>
85}
86
87/**
88 * The SinglePageApp is an infrastructure and must implement [[IInfrastructure]]
89 *
90 * @param props
91 */
92export default (props: IServiceOrientedArgs | any) => {
93
94 //console.log ("isomorphic: ",props );
95
96 const infProps: IInfrastructure & IConfiguration = {
97
98 // allows to identify this component as Infrastructure
99 infrastructureType: Types.INFRASTRUCTURE_TYPE_CONFIGURATION,
100
101 instanceId: props.stackName,
102
103 instanceType: SERVICEORIENTED_INSTANCE_TYPE,
104
105 // only load plugins during compilation
106 createPlugins: (configPath: string, stage: string | undefined, parserMode: string) => props.infrastructureMode === "COMPILATION" ? [
107 // be able to process IsomorphicApps (as top-level-node)
108 SoaPlugin({
109 stage: stage,
110 parserMode: parserMode,
111 buildPath: props.buildPath,
112 configFilePath: configPath
113 }),
114
115 // ServiceOriented apps can have different environments
116 EnvironmentPlugin({
117 stage: stage,
118 parserMode: parserMode
119 }),
120
121 ServicePlugin({}),
122
123 DataLayerPlugin({
124 buildPath: props.buildPath,
125 configFilePath: configPath,
126 }),
127
128
129 StoragePlugin({
130 buildPath: props.buildPath,
131 parserMode: parserMode
132 })
133
134 ] : []
135 };
136
137 // TODO maybe edit to support the web-mode?!
138 const spaProps: IServiceOrientedProps = {
139 id: props.stackName,
140
141 routes: getChildrenArray(props.children)
142 .filter(child => isRoute(child)),
143
144 redirects: [],
145
146 services: findComponentRecursively(props.children, c => isService(c) || isStorage(c)),
147
148 dataLayerId: findComponentRecursively(props.children, isDataLayer).reduce((res, dl) => res ? res : dl.id, undefined)
149 }
150
151
152 return Object.assign(props, infProps, spaProps);
153
154
155};
156
157export function isServiceOrientedApp(component) {
158 return component !== undefined &&
159 component.instanceType === SERVICEORIENTED_INSTANCE_TYPE
160}
\No newline at end of file