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

[WIP] rc 1.6.0 #321

Open
wants to merge 90 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
d203e15
Fixing unknown station error to 404
thanaParis Nov 18, 2024
e1afb9f
changed error to upgradeAuthenticationError
thanaParis Nov 18, 2024
76f084c
Adding localstack to citrineos core
eddygrebt Nov 19, 2024
44fcb3b
Merge branch 'rc-1.5.0' of https://github.com/citrineos/citrineos-cor…
eddygrebt Nov 19, 2024
cfea0c3
Fixing Lint errors
eddygrebt Nov 19, 2024
91f822b
Fixing port config on Docker-compose
eddygrebt Nov 19, 2024
d9a2ad4
Moving hasura into core
eddygrebt Nov 20, 2024
e6e38f8
fix: adding await before request to repository to resolve unhandled p…
Nov 20, 2024
be7ab4a
chore: adjusted eslint to disallow floating promises which can lead t…
Nov 20, 2024
5494d0a
altered json schema processor for 1.6 compatibility, changed output f…
thanaParis Nov 20, 2024
110d8e1
shifting namespaces to accomodate 1.6 types
thanaParis Nov 20, 2024
0b22dc9
formatting only ocpp model classes, correcting import for OCPPRequest…
thanaParis Nov 21, 2024
bf42f64
regenerated interfaces
thanaParis Nov 21, 2024
72d1ed7
Moved requestIds file. Modified Call schema maps and AbstractRouter v…
thanaParis Nov 21, 2024
68dc6e6
CallAction -> OCPP2_0_1_CallAction
thanaParis Nov 21, 2024
11e3616
split json processor into 1.6 and 2.0.1, rewrote 1.6 to handle json s…
thanaParis Nov 21, 2024
609a77d
adding ocpp 201 namespace to all references
thanaParis Nov 21, 2024
5aa7f00
Managing execution order on docker compose
eddygrebt Nov 22, 2024
06383f1
Changing healthcheck settings for graphql-engine on docker compose.
eddygrebt Nov 22, 2024
e468962
Updating localstack volumes
eddygrebt Nov 25, 2024
f2b6bce
feature/handle-meter-value-cost-update
lydiazcheng Nov 25, 2024
f1bee11
Modifying handlers to use new ocpp version enums
thanaParis Nov 25, 2024
46ef90d
Adding getFileURL method to IFileAccess, creating new endpoing to gat…
eddygrebt Nov 27, 2024
1d7706d
correct 1.6 json schema generation, updated onConnection callback to …
thanaParis Nov 27, 2024
e0f64ad
Merge branch 'rc-1.5.0' into feature/ocpp-1.6-types
thanaParis Nov 27, 2024
8577b53
undoing declaration of ocpp1.6 websocket server, was a holdover from …
thanaParis Nov 27, 2024
48ee67b
Merge branch 'feature/ocpp-1.6-types' of https://github.com/citrineos…
thanaParis Nov 27, 2024
d9635ff
fix: using json log type when initializing logger and process.env.DEP…
Dec 2, 2024
a8d8320
feat: adding unique index on `name` field when `instance` field IS NU…
Dec 2, 2024
ca69dd3
version 1.5.0 -> 1.6.0
thanaParis Dec 2, 2024
b1f4279
Update 00_Base/src/interfaces/modules/AbstractModule.ts
thanaParis Dec 2, 2024
6ff14f8
feat: setting transportJSON override to remove _meta when systemConfi…
Dec 2, 2024
de0170e
feat: moved fastify dependencies to base so that they can be used tra…
Dec 3, 2024
65fd3d1
issue61: fix bootnotification-crash
lydiazcheng Dec 3, 2024
2759836
feat: upgraded fastify to latest version
Dec 3, 2024
67f052f
feat: updating typescript to newer version
Dec 4, 2024
ee9b23c
fixing potential issue where may attempt to terminate connection twice.
thanaParis Dec 4, 2024
5d17fcb
moving types into own file separate of cache class definition.
thanaParis Dec 4, 2024
11a0688
feat: removing deasync dependency by instead awaiting promises outsid…
Dec 5, 2024
a9710b3
chore: removing deasync from dockerfiles
Dec 5, 2024
c105280
Returning Key after uploading to ensure the reutilization of the uplo…
eddygrebt Dec 6, 2024
b683f69
fix string interpolation in exception message
exterm Dec 6, 2024
e49a53d
adding typing to protocol string
thanaParis Dec 6, 2024
848c204
switching string to enum for version switch case
thanaParis Dec 6, 2024
453560e
switching string to enum for version switch case
thanaParis Dec 6, 2024
958890f
Merge pull request #295 from citrineos/feature/localstack-s3-storage
thanaParis Dec 6, 2024
09dca93
Merge pull request #297 from citrineos/feature/unknown-404
thanaParis Dec 6, 2024
93c1ac2
Merge pull request #298 from citrineos/fix/notify-report-unhandled-pr…
thanaParis Dec 6, 2024
a2c7715
Merge pull request #305 from citrineos/fix/logs-in-cloud
thanaParis Dec 6, 2024
d029dd1
feat: updating everest-demo to newest version 0.0.23 including adjust…
Dec 6, 2024
bff13e8
chore: changing port back
Dec 6, 2024
7ad62fe
chore: removing missed unnecessary protected access modifiers
Dec 6, 2024
ef7edcc
Merge branch 'rc-1.6.0' into fix/move-hasura-into-core
Dec 9, 2024
532ddfa
Merge pull request #296 from citrineos/fix/move-hasura-into-core
elliot-sabitov Dec 9, 2024
aafc084
Merge pull request #311 from citrineos/feature/59-remove-deasync
elliot-sabitov Dec 10, 2024
5d80e4e
Merge pull request #309 from citrineos/bugfix/issue61-bootnotificatio…
elliot-sabitov Dec 10, 2024
6f6e949
Merge branch 'rc-1.6.0' into chore/disallow-floating-promises
Dec 10, 2024
571a737
fix: disallowed floating promises
Dec 10, 2024
4792d82
feat: adding conditional unique indexes on nullable fields in Evse an…
Dec 11, 2024
7030b99
fix: hasConcurrentTransactions check to properly only get matching tr…
Dec 11, 2024
9ed1e8a
chore: adjusting to async syntax
Dec 12, 2024
f2585f4
Merge branch 'rc-1.6.0' into feature/everest-updates
thanaParis Dec 16, 2024
7a54160
host.docker.internal is not supported by github actions platform. cha…
thanaParis Dec 16, 2024
6c6b99a
Merge pull request #314 from citrineos/feature/everest-updates
thanaParis Dec 16, 2024
39d1cfb
Merge pull request #316 from citrineos/fix/floating-promises
thanaParis Dec 17, 2024
8542a2e
Merge branch 'rc-1.6.0' into chore/disallow-floating-promises
thanaParis Dec 17, 2024
b5e8cd4
merged paths
thanaParis Dec 17, 2024
f4cd5e4
Merge pull request #299 from citrineos/chore/disallow-floating-promises
thanaParis Dec 17, 2024
f0d0d85
merged paths
thanaParis Dec 17, 2024
d6a4366
merging paths
thanaParis Dec 17, 2024
f724b92
adding json schema processors to eslint config
thanaParis Dec 17, 2024
8d89cb7
fixing unit test to include ocpp version for mocked message
thanaParis Dec 17, 2024
452c0ba
Merge pull request #304 from citrineos/feature/ocpp-1.6-types
thanaParis Dec 17, 2024
c46160a
Merge branch 'rc-1.6.0' into feature/url-handling-streaming-data
thanaParis Dec 17, 2024
c58ade1
Merge pull request #303 from citrineos/feature/url-handling-streaming…
thanaParis Dec 17, 2024
2537ede
merging paths
thanaParis Dec 17, 2024
a57c1a5
merged paths
thanaParis Dec 17, 2024
73b567b
merged paths
thanaParis Dec 17, 2024
99d1313
merging paths
thanaParis Dec 17, 2024
cb186d5
Merge pull request #307 from citrineos/feature/move-fastify-to-base
thanaParis Dec 17, 2024
c9a0571
Merge pull request #317 from citrineos/feature/66-fix-indexes-on-null…
thanaParis Dec 17, 2024
53f0a7c
Merge pull request #313 from exterm/pt/fix-error-message
thanaParis Dec 17, 2024
6339040
Merge pull request #319 from citrineos/fix/has-concurrent-transaction…
thanaParis Dec 17, 2024
5dea517
Merge branch 'rc-1.6.0' into feature/upgrade-fastify-node
thanaParis Dec 17, 2024
3030428
satifying linter, no hanging promises
thanaParis Dec 17, 2024
239ac1f
merging paths
thanaParis Dec 17, 2024
d44bbdc
increasing node version for all github action pipelines to match new …
thanaParis Dec 17, 2024
fafaa06
updating dockerfiles to use node 22
thanaParis Dec 17, 2024
b788bd3
Merge pull request #301 from citrineos/feature/handle-meter-value-cos…
thanaParis Dec 17, 2024
f37007a
Merge pull request #310 from citrineos/feature/upgrade-fastify-node
thanaParis Dec 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/jest-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '22.x'

- name: Cache Node.js modules
uses: actions/cache@v4
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ jobs:
linter:
name: Linter
runs-on: ubuntu-22.04 # todo: to prevent needing to run npm i we can have our own image where everything is installed
strategy:
matrix:
node-version: [18]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: '22.x'

- name: Install dependencies
run: npm i
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/push-release-tagged-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test-build-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
280 changes: 280 additions & 0 deletions 00_Base/json-schema-processor-1.6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
// Copyright (c) 2023 S44, LLC
// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0
/* eslint-disable */

/**
* execution:
* - cd 00_Base
* - node json-schema-processor-1.6.js ../../OCPP-1.6/schemas/json
*/
const fs = require('fs');
const jsts = require('json-schema-to-typescript');
const prettier = require('prettier');
const { exec } = require('child_process');

if (process.argv.length === 2) {
console.error('Expected input version and path arguments!');
process.exit(1);
}

const path = process.argv[2];
const globalEnums = new Set();
const globalDefinitions = [];
const globalEnumDefinitions = {};

const licenseComment = `// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0

`;

fs.readdir(path, (error, files) => {
const writeToFile = true;
const promises = files.map((file) => {
let data = fs.readFileSync(`${path}/${file}`);
return processJsonSchema(data, writeToFile);
});

Promise.all(promises).then((values) => {
values.forEach(({ title, enumNames, enums }) => {
globalDefinitions.push(title);

if (enumNames.length > 0) {
enumNames.forEach((entry) => {
globalEnums.add(entry);
});
}

if (enums.length > 0) {
enums.forEach((entry) => {
let { enumName, enumDocumentation, enumDefinition } =
splitEnum(entry);
if (enumName == 'DataEnumType') {
// Adding missing type for DataEnumType... type in OCPP 2.0.1 appendix but not in part 3 JSON schemas
let lastLineIndex = enumDefinition.lastIndexOf(`'`);
enumDefinition =
enumDefinition.substring(0, lastLineIndex) +
`',\n passwordString = 'passwordString` +
enumDefinition.substring(lastLineIndex);
}
globalEnumDefinitions[title + enumName] = enumDefinition;
});
}
});

const exportStatements = [];

// Export all enum types
exportStatements.push(`export * from './enums';`);

// Export all definitions and schemas
for (let key of globalDefinitions) {
exportStatements.push(`export { ${key} } from './types/${key}';`);
exportStatements.push(
`export { default as ${key}Schema } from './schemas/${key}.json';`,
);
}

if (writeToFile) {
fs.writeFileSync(
`./src/ocpp/model/1.6/enums/index.ts`,
licenseComment +
Object.values(globalEnumDefinitions).sort().join('\n\n') +
'\n',
);
fs.writeFileSync(
`./src/ocpp/model/1.6/index.ts`,
licenseComment + exportStatements.join('\n') + '\n',
);
exec(
`prettier --write ./src/ocpp/model/1.6/**/* && npx eslint --fix ./src/ocpp/model/1.6`,
(error, stdout, stderr) => {
if (error) {
console.error(`Error executing npm script: ${error.message}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
},
);
}
});
});

async function processJsonSchema(data, writeToFile = true) {
let jsonSchema = JSON.parse(data);
let id = jsonSchema['id'].split(':').pop();
jsonSchema['$id'] = id;
delete jsonSchema['id'];
delete jsonSchema['$schema'];
const title = jsonSchema['title'];

// Correct & collect all enum names
jsonSchema['definitions'] = {};
const uniqueEnumNames = processEnumNames(
jsonSchema['definitions'],
jsonSchema['properties'],
[],
title,
);

// Preprocess nodes to enable enum extraction
processNode(jsonSchema);

// Determine if the schema is a request or response
let schemaType = '';
if (id.toLowerCase().includes('request')) {
schemaType = 'OcppRequest';
} else if (id.toLowerCase().includes('response')) {
schemaType = 'OcppResponse';
}

return new Promise((resolve, reject) => {
jsts
.compile(jsonSchema, id, {
style: { singleQuote: true, trailingComma: 'all' },
format: true,
enableConstEnums: false,
})
.then((ts) => {
// Add licence comment
ts = licenseComment + ts;

// Extend the generated interface with Request or Response
if (schemaType) {
const interfaceNamePattern = new RegExp(
`export interface ${id}`,
'g',
);
ts = ts.replace(
interfaceNamePattern,
`export interface ${id} extends ${schemaType}`,
);
}

// Extract enums
const enums = extractEnums(ts);
if (enums) {
for (let i = 0; i < enums.length; i++) {
const entry = enums[i];
ts = ts.replace(entry, '');
enums[i] = entry.trimEnd();
}
}

// Add import statement for enums & schemaType
const searchString = '\nexport';
const index = ts.indexOf(searchString);
ts =
ts.substring(0, index) +
(uniqueEnumNames.length > 0
? `\nimport { ${uniqueEnumNames.join(', ')} } from '../enums';\n`
: '\n') +
`import { ${schemaType} } from '../../../..';\n` +
ts.substring(index);

// Add null type to all optional properties
// This regex means a string starts with '?:' and ends with ';'
const regex = /(\?:[^;]*);/g;
ts = ts.replaceAll(regex, '$1 | null;');

if (writeToFile) {
fs.writeFileSync(
`./src/ocpp/model/1.6/types/${id}.ts`,
ts.replace(/\n+$/, '\n'),
);

// Format JSON with Prettier
prettier
.format(JSON.stringify(jsonSchema, null, 2), { parser: 'json' })
.then((formattedJson) => {
fs.writeFileSync(
`./src/ocpp/model/1.6/schemas/${id}.json`,
formattedJson,
);
});
}

resolve({
title,
enumNames: uniqueEnumNames,
enums: enums == null ? [] : enums,
});
});
});
}

function processEnumNames(definitionsRoot, node, uniqueEnumNames, title) {
for (let key in node) {
if (typeof node[key] === 'object') {
if (node[key]['enum']) {
uniqueKey = title + key.charAt(0).toUpperCase() + key.slice(1);
definitionsRoot[uniqueKey] = node[key];
node[key] = { $ref: `#/definitions/${uniqueKey}` };
uniqueEnumNames.push(uniqueKey);
} else {
uniqueEnumNames = processEnumNames(
definitionsRoot,
node[key],
uniqueEnumNames,
title,
);
}
}
}
return uniqueEnumNames;
}

function processNode(node) {
if (node['enum']) {
node['tsEnumNames'] = [...node['enum']];
node['tsEnumNames'] = node['tsEnumNames'].map((name) => {
return name.replaceAll('.', '_').replaceAll('-', '_');
});
} else {
for (let key in node) {
if (typeof node[key] === 'object') {
processNode(node[key]);
}
}
}
}

function extractEnums(ts) {
const pattern =
/^\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\/\nexport enum (\w)* {(\s|\w|-|\.|=|'|,)*}\n*/gm;
const undocumentedPattern = /^export enum (\w)* {(\s|\w|-|\.|=|'|,)*}\n*/gm;
const matches = ts.match(pattern);
let undocumentedMatches = ts.match(undocumentedPattern);

if (matches && undocumentedMatches) {
const namePattern = /export enum (\w)*/g;
matches.forEach((match) => {
const enumName = match.match(namePattern)[0].replace('export enum ', '');
undocumentedMatches = undocumentedMatches.filter(
(undocumentedMatch) => !undocumentedMatch.includes(enumName),
);
});
}

return [
...(matches ? matches : []),
...(undocumentedMatches ? undocumentedMatches : []),
];
}

function splitEnum(enumDefinition) {
const commentPattern = /^\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\/\n/gm;
const namePattern = /export enum (\w)*/g;
const enumName = enumDefinition
.match(namePattern)[0]
.replace('export enum ', '');
let enumDocumentation = enumDefinition.match(commentPattern);
enumDocumentation = enumDocumentation ? enumDocumentation[0] : '';
return { enumName, enumDocumentation, enumDefinition };
}
Loading
Loading