Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(odata-service): Removes ui5-config -> odata-service-writer dep #127

Merged
merged 3 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# IDE and OS temporary files

.idea
.project
.DS_Store

## Original Source: https://github.com/github/gitignore/blob/master/Node.gitignore
Expand Down
22 changes: 21 additions & 1 deletion packages/odata-service-writer/src/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
export { OdataService, OdataVersion } from '@sap-ux/ui5-config';
export enum OdataVersion {
v2 = '2',
v4 = '4'
}
export interface OdataService {
url?: string;
client?: string;
destination?: {
name: string;
instance?: string;
};
path?: string;
version: OdataVersion;
name?: string;
model?: string;
metadata?: string;
annotations?: {
technicalName: string;
xml: string;
};
}
1 change: 0 additions & 1 deletion packages/ui5-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { UI5Config } from './ui5-config';
export * from './middlewares';
export { OdataService, OdataVersion } from './types';
21 changes: 10 additions & 11 deletions packages/ui5-config/src/middlewares.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { MiddlewareConfig } from './types';
import type { NodeComment, Path } from '@sap-ux/yaml';
import { OdataService } from './types';
import { join } from 'path';
import { UI5Config } from './ui5-config';
import type { Editor } from 'mem-fs-editor';
Expand All @@ -20,7 +19,7 @@ export const getAppReloadMiddlewareConfig = (): MiddlewareConfig[] => {
};

export const getFioriToolsProxyMiddlewareConfig = (
data: OdataService,
{ url, path, destination }: { url?: string; path?: string; destination?: { name?: string; instance?: string }},
IainSAP marked this conversation as resolved.
Show resolved Hide resolved
useUi5Cdn = true,
ui5CdnUrl = 'https://ui5.sap.com',
ui5Version = ''
Expand All @@ -33,18 +32,18 @@ export const getFioriToolsProxyMiddlewareConfig = (
}
};

if (data.url || data.path || data.destination?.name || data.destination?.instance) {
const rootSegment = data.path?.split('/').filter((s: string) => s !== '')[0];
if (url || path || destination?.name || destination?.instance) {
const rootSegment = path?.split('/').filter((s: string) => s !== '')[0];
const backend = {
path: `/${rootSegment || ''}`,
url: data.url ?? DEFAULT_HOST
url: url ?? DEFAULT_HOST
};

if (data.destination?.name) {
Object.assign(backend, { destination: data.destination.name });
if (destination?.name) {
Object.assign(backend, { destination: destination.name });
}
if (data.destination?.instance) {
Object.assign(backend, { destinationInstance: data.destination.instance });
if (destination?.instance) {
Object.assign(backend, { destinationInstance: destination.instance });
}
fioriToolsProxy.configuration.backend = [backend];
}
Expand Down Expand Up @@ -75,8 +74,8 @@ export const getFioriToolsProxyMiddlewareConfig = (
return { config, comments };
};

export const getMockServerMiddlewareConfig = (data: OdataService): MiddlewareConfig[] => {
const pathSegments = data.path?.split('/') || [];
export const getMockServerMiddlewareConfig = ({ path }: { path?: string }): MiddlewareConfig[] => {
const pathSegments = path?.split('/') || [];
return [
{
name: 'sap-fe-mockserver',
Expand Down
21 changes: 0 additions & 21 deletions packages/ui5-config/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
export enum OdataVersion {
v2 = '2',
v4 = '4'
}
export interface OdataService {
url?: string;
client?: string;
destination?: {
name: string;
instance?: string;
};
path?: string;
version: OdataVersion;
name?: string;
model?: string;
metadata?: string;
annotations?: {
technicalName: string;
xml: string;
};
}

export interface Destination {
destination: string;
Expand Down
14 changes: 3 additions & 11 deletions packages/ui5-config/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
addMiddlewareConfig,
UI5Config
} from '../src';
import { OdataService, OdataVersion } from '../src/types';
import { create as createStorage } from 'mem-fs';
import { create, Editor } from 'mem-fs-editor';
import { join } from 'path';
Expand All @@ -14,11 +13,9 @@ describe('Fiori config utils', () => {
const serviceData = {
name: 'maintestService',
path: '/testpath',
version: OdataVersion.v2,
metadata: '<xml/>',
url: 'http://localhost:8080',
destination: { name: 'SIDCLNT000' }
} as OdataService;
};
beforeAll(() => {});

test('getMockServerMiddlewareConfig', async () => {
Expand Down Expand Up @@ -150,10 +147,7 @@ describe('Fiori config utils', () => {
* This test ensures a valid middleware definition is generated without a full service defintion.
*/
test('getFioriToolsProxyMiddlewareConfig no datasource provided', async () => {
let serviceData = {
name: 'maintestService',
version: OdataVersion.v2
} as OdataService;
let serviceData = {};

expect(getFioriToolsProxyMiddlewareConfig(serviceData)).toMatchInlineSnapshot(`
Object {
Expand Down Expand Up @@ -190,10 +184,8 @@ describe('Fiori config utils', () => {

test('getFioriToolsProxyMiddlewareConfig no path provided', async () => {
let serviceData = {
name: 'maintestService',
version: OdataVersion.v2,
url: 'http://localhost:8080'
} as OdataService;
};

expect(getFioriToolsProxyMiddlewareConfig(serviceData)).toMatchInlineSnapshot(`
Object {
Expand Down
Loading