Skip to content

Commit e3adff9

Browse files
authoredAug 14, 2023
Merge pull request #276 from Canner/fix/support-cache-profile-for-canner-store
Fix: Correct the profile of cache layer schema for Canner Persistence Store
2 parents 6c7df80 + 235ccb9 commit e3adff9

File tree

7 files changed

+28
-8
lines changed

7 files changed

+28
-8
lines changed
 

‎packages/build/src/lib/schema-parser/schemaParser.ts

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export class SchemaParser {
4545
for await (const schemaData of this.schemaReader.readSchema()) {
4646
const schema = await this.parseContent(schemaData);
4747
schema.metadata = metadata?.[schema.templateSource || schema.sourceName];
48-
schema.urlPath = `/api${schema.urlPath}`
4948
// execute middleware
5049
await execute(schema);
5150
schemas.push(schema as APISchema);

‎packages/catalog-server/utils/vulcanSQLAdapter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class VulcanSQLAdapter {
108108
return isParam
109109
? result.replace(param, filter[key])
110110
: `${result}${querySymbol}${key}=${filter[key]}`;
111-
}, schema.urlPath);
111+
}, `/api${schema.urlPath}`);
112112

113113
const actualUrl = `${VULCAN_SQL_HOST}${actualPath}`;
114114
console.log('actualUrl: ', actualUrl);

‎packages/extension-store-canner/src/lib/canner/persistenceStore.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,17 @@ export class CannerPersistenceStore extends PersistentStore {
141141
merged.templates[workspaceSourceName] = value;
142142
});
143143
// API Schemas
144+
const profile = `canner-${workspaceSqlName}`;
144145
artifact.schemas.forEach((schema) => {
145146
// concat the workspace sql name prefix to urlPath, urlPath has the "/" prefix, so concat directly
146147
schema.urlPath = `${workspaceSqlName}${schema.urlPath}`;
147148
// concat the workspace sql name prefix to template source, so it could find the "sourceName" in templates
148149
schema.templateSource = `${workspaceSqlName}/${schema.templateSource}`;
149150
// replace the profile to the canner enterprise integration used profile name, it will match to the profiles from canner profile reader.
150-
schema.profiles = [`canner-${workspaceSqlName}`];
151+
schema.profiles = [profile];
152+
schema.cache =
153+
schema.cache?.map((cacheData) => ({ ...cacheData, profile })) || [];
154+
151155
merged.schemas.push(schema);
152156
});
153157
// Specs, only support the oas3 specification for canner enterprise integration used

‎packages/extension-store-canner/src/test/cannerPersistenceStore.spec.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import * as sinon from 'ts-sinon';
22
import faker from '@faker-js/faker';
33
import * as oas3 from 'openapi3-ts';
44
import { BaseStorageService } from '@canner/canner-storage';
5-
import { APISchema, ArtifactBuilderOptions } from '@vulcan-sql/core';
5+
import {
6+
APISchema,
7+
ArtifactBuilderOptions,
8+
CacheLayerInfo,
9+
} from '@vulcan-sql/core';
610
import * as storageServiceModule from '../lib/storageService';
711
import {
812
BuiltInArtifact,
@@ -160,6 +164,12 @@ describe('Test CannerPersistenceStore', () => {
160164
urlPath: '/orders',
161165
templateSource: 'sales/orders',
162166
profiles: [faker.word.noun()],
167+
cache: [
168+
{
169+
...sinon.stubInterface<CacheLayerInfo>(),
170+
profile: faker.lorem.word(),
171+
},
172+
],
163173
},
164174
],
165175
specs: {
@@ -184,6 +194,7 @@ describe('Test CannerPersistenceStore', () => {
184194
urlPath: '/products/:id',
185195
templateSource: 'marketing/products',
186196
profiles: [faker.word.noun()],
197+
cache: [],
187198
},
188199
],
189200
specs: {
@@ -213,11 +224,17 @@ describe('Test CannerPersistenceStore', () => {
213224
urlPath: `${fakeWorkspaces.ws1.sqlName}/orders`,
214225
templateSource: `${fakeWorkspaces.ws1.sqlName}/sales/orders`,
215226
profiles: [`canner-${fakeWorkspaces.ws1.sqlName}`],
227+
cache: [
228+
{
229+
profile: `canner-${fakeWorkspaces.ws1.sqlName}`,
230+
},
231+
],
216232
},
217233
{
218234
urlPath: `${fakeWorkspaces.ws2.sqlName}/products/:id`,
219235
templateSource: `${fakeWorkspaces.ws2.sqlName}/marketing/products`,
220236
profiles: [`canner-${fakeWorkspaces.ws2.sqlName}`],
237+
cache: [],
221238
},
222239
],
223240
specs: {

‎packages/serve/src/lib/catalog-router/catalogRouters.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class CatalogRouters extends CatalogRouter {
4343
const baseUrl = `${ctx.protocol}://${ctx.host}`;
4444
const result = {
4545
...schema,
46-
url: `${baseUrl}${schema.urlPath}`,
46+
url: `${baseUrl}/api${schema.urlPath}`,
4747
apiDocUrl: `${baseUrl}${this.getAPIDocUrl(schema)}`,
4848
shareKey: this.getShareKey(ctx.request.headers.authorization),
4949
responseFormat: responseFormatOption.enabled
@@ -60,7 +60,7 @@ export class CatalogRouters extends CatalogRouter {
6060
const result = schemas.map((schema) => {
6161
return {
6262
...schema,
63-
url: `${baseUrl}${schema.urlPath}`,
63+
url: `${baseUrl}/api${schema.urlPath}`,
6464
apiDocUrl: `${baseUrl}${this.getAPIDocUrl(schema)}`,
6565
shareKey: this.getShareKey(ctx.request.headers.authorization),
6666
};

‎packages/serve/src/lib/route/route-component/restfulRoute.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class RestfulRoute extends BaseRoute {
88
constructor(options: RouteOptions) {
99
super(options);
1010
const { apiSchema } = options;
11-
this.urlPath = apiSchema.urlPath;
11+
this.urlPath = this.combineURLs('/api', apiSchema.urlPath);
1212
}
1313

1414
public async respond(ctx: KoaContext) {

‎packages/serve/test/app.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ describe('Test vulcan server for calling restful APIs', () => {
386386
.listen(faker.datatype.number({ min: 20000, max: 30000 }));
387387

388388
// arrange input api url
389-
const apiUrl = KoaRouter.url(schema.urlPath, ctx.params);
389+
const apiUrl = KoaRouter.url('/api' + schema.urlPath, ctx.params);
390390

391391
// arrange expected result
392392
const expected: RequestParameters = {};

0 commit comments

Comments
 (0)
Please sign in to comment.