Skip to content

Commit

Permalink
rename entities const into endpoints; consider functions and actions …
Browse files Browse the repository at this point in the history
…as api endpoint
  • Loading branch information
aramovic79 committed Nov 21, 2024
1 parent 73ddae7 commit 5ace38e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
16 changes: 13 additions & 3 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
const CDS_ELEMENT_KIND = Object.freeze({
action: "action",
annotation: "annotation",
context: "context",
function: "function",
entity: "entity",
event: "event",
service: "service",
type: "type",
});

const COMPILER_TYPES = Object.freeze({
oas3: "oas3",
asyncapi2: "asyncapi2",
Expand All @@ -13,10 +24,8 @@ const OPEN_RESOURCE_DISCOVERY_VERSION = "1.9";
const ORD_EXTENSIONS_PREFIX = "@ORD.Extensions.";

const ORD_RESOURCE_TYPE = Object.freeze({
service: "service",
entity: "entity",
event: "event",
api: "api",
event: "event"
});

const RESOURCE_VISIBILITY = Object.freeze({
Expand All @@ -28,6 +37,7 @@ const RESOURCE_VISIBILITY = Object.freeze({
const SHORT_DESCRIPTION_PREFIX = "Short description for ";

module.exports = {
CDS_ELEMENT_KIND,
COMPILER_TYPES,
CONTENT_MERGE_KEY,
DESCRIPTION_PREFIX,
Expand Down
22 changes: 13 additions & 9 deletions lib/ord.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ORD_RESOURCE_TYPE } = require('./constants');
const { CDS_ELEMENT_KIND } = require('./constants');
const {
createAPIResourceTemplate,
createEntityTypeMappingsItemTemplate,
Expand All @@ -24,7 +24,7 @@ const initializeAppConfig = (csn) => {
const packageName = packageJson.name;
const appName = packageJson.name.replace(/^[@]/, "").replace(/[@/]/g, "-");
const modelKeys = Object.keys(csn.definitions);
const entities = new Set();
const endpoints = new Set();
const events = [];
const serviceNames = [];
const lastUpdate = getRFC3339Date();
Expand All @@ -41,31 +41,35 @@ const initializeAppConfig = (csn) => {
for (const key of modelKeys) {
const keyDefinition = csn.definitions[key];
switch (keyDefinition.kind) {
case ORD_RESOURCE_TYPE.service:
case CDS_ELEMENT_KIND.service:
if (!keyDefinition["@cds.external"]) {
serviceNames.push(key);
}
break;
// TODO: should be rewritten
case ORD_RESOURCE_TYPE.entity:
case CDS_ELEMENT_KIND.entity:
if (!key.includes(".texts")) {
entities.add(key);
endpoints.add(key);
if (keyDefinition["@ODM.entityName"]) {
odmEntities.push(createEntityTypeMappingsItemTemplate(keyDefinition));
}
}
break;
case ORD_RESOURCE_TYPE.event:
case CDS_ELEMENT_KIND.event:
events.push(key);
break;
case CDS_ELEMENT_KIND.action:
case CDS_ELEMENT_KIND.function:
endpoints.add(key);
break;
}
}

return {
env: cds.env["ord"],
lastUpdate,
appName,
entities: Array.from(entities),
endpoints: Array.from(endpoints),
events,
serviceNames,
odmEntities: _.uniqBy(odmEntities, "ordId"),
Expand Down Expand Up @@ -98,9 +102,9 @@ const _getPackages = (policyLevel, appConfig) =>
.slice(0, 1);

const _getAPIResources = (csn, appConfig, packageIds) => {
if (appConfig.entities.length === 0) return [];
if (appConfig.endpoints.length === 0) return [];
return appConfig.serviceNames
.filter((serviceName) => appConfig.entities.some((entityName) => entityName.startsWith(serviceName)))
.filter((serviceName) => appConfig.endpoints.some((endpoint) => endpoint.startsWith(serviceName)))
.flatMap((serviceName) => createAPIResourceTemplate(serviceName, csn.definitions[serviceName], appConfig, packageIds))
};

Expand Down

0 comments on commit 5ace38e

Please sign in to comment.