Skip to content

Commit

Permalink
Merge pull request #264 from citrineos/rc-1.4.3
Browse files Browse the repository at this point in the history
Rc 1.4.3
  • Loading branch information
thanaParis authored Sep 18, 2024
2 parents 823849c + b866830 commit a6701d6
Show file tree
Hide file tree
Showing 138 changed files with 3,806 additions and 599 deletions.
19 changes: 8 additions & 11 deletions 00_Base/json-schema-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ async function processJsonSchema(data, writeToFile = true) {
.compile(jsonSchema, id, {
style: { singleQuote: true, trailingComma: 'all' },
format: true,
enableConstEnums: false,
})
.then((ts) => {
// Add licence comment
Expand Down Expand Up @@ -185,8 +186,7 @@ async function processJsonSchema(data, writeToFile = true) {

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

if (writeToFile) {
Expand Down Expand Up @@ -252,18 +252,15 @@ function processNode(node) {

function extractEnums(ts) {
const pattern =
/^\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\/\nexport const enum (\w)* {(\s|\w|-|\.|=|'|,)*}\n*/gm;
const undocumentedPattern =
/^export const enum (\w)* {(\s|\w|-|\.|=|'|,)*}\n*/gm;
/^\/\*\*\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 const enum (\w)*/g;
const namePattern = /export enum (\w)*/g;
matches.forEach((match) => {
const enumName = match
.match(namePattern)[0]
.replace('export const enum ', '');
const enumName = match.match(namePattern)[0].replace('export enum ', '');
undocumentedMatches = undocumentedMatches.filter(
(undocumentedMatch) => !undocumentedMatch.includes(enumName),
);
Expand All @@ -278,10 +275,10 @@ function extractEnums(ts) {

function splitEnum(enumDefinition) {
const commentPattern = /^\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\/\n/gm;
const namePattern = /export const enum (\w)*/g;
const namePattern = /export enum (\w)*/g;
const enumName = enumDefinition
.match(namePattern)[0]
.replace('export const enum ', '');
.replace('export enum ', '');
let enumDocumentation = enumDefinition.match(commentPattern);
enumDocumentation = enumDocumentation ? enumDocumentation[0] : '';
return { enumName, enumDocumentation, enumDefinition };
Expand Down
8 changes: 5 additions & 3 deletions 00_Base/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "@citrineos/base",
"version": "1.4.2",
"version": "1.4.3",
"description": "The base module for OCPP v2.0.1 including all interfaces. This module is not intended to be used directly, but rather as a dependency for other modules.",
"main": "dist/index.js",
"module": "dist/esm/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"prepublish": "npx eslint ./src",
"generate-interfaces": "node json-schema-processor.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build:esm": "tsc --project tsconfig.esm.json"
},
"keywords": [
"ocpp",
Expand Down Expand Up @@ -40,6 +42,6 @@
"reflect-metadata": "0.1.13",
"tslog": "4.9.2",
"uuid": "9.0.0",
"zod": "3.22.2"
"zod": "3.22.3"
}
}
35 changes: 35 additions & 0 deletions 00_Base/src/assertion/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,38 @@ export function assert(
export function notNull(object: any): boolean {
return object !== undefined && object !== null;
}

/**
* Ensures that obj2 contains all keys from obj1.
* @param obj1
* @param obj2
* @returns
*/

export function deepDirectionalEqual(obj1: any, obj2: any, seenObjects = new WeakSet()): boolean {
if (obj1 === obj2) return true;

if (typeof obj1 !== 'object' || obj1 === null ||
typeof obj2 !== 'object' || obj2 === null) {
return false;
}

// Check if obj1 has already been seen to avoid cycles
if (seenObjects.has(obj1)) {
return true; // If we've already seen obj1, we assume it's equivalent.
}

// Add obj1 to the seen set
seenObjects.add(obj1);

const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);

for (const key of keys1) {
if (!keys2.includes(key) || !deepDirectionalEqual(obj1[key], obj2[key], seenObjects)) {
return false;
}
}

return true;
}
5 changes: 4 additions & 1 deletion 00_Base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { CacheNamespace, ICache } from './interfaces/cache/cache';
export {
AbstractMessageRouter,
IAuthenticator,
AuthenticationOptions,
IMessageRouter,
} from './interfaces/router';
export {
Expand Down Expand Up @@ -68,6 +69,8 @@ export const LOG_LEVEL_OCPP = 10;

export * from './ocpp/model';

export { UpdateChargingStationPasswordRequest } from './ocpp/model/UpdateChargingStationPasswordRequest';

import {
AuthorizeRequestSchema,
BootNotificationRequestSchema,
Expand Down Expand Up @@ -237,7 +240,7 @@ export { HttpHeader } from './interfaces/api/http.header';
export { HttpStatus } from './interfaces/api/http.status';
export { Money } from './money/Money';
export { Currency, CurrencyCode } from './money/Currency';
export { assert, notNull } from './assertion/assertion';
export { assert, notNull, deepDirectionalEqual } from './assertion/assertion';
export { UnauthorizedError } from './interfaces/api/exception/UnauthorizedError';
export { AuthorizationSecurity } from './interfaces/api/AuthorizationSecurity';
export { Ajv };
2 changes: 1 addition & 1 deletion 00_Base/src/interfaces/api/AbstractModuleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
IMessageQuerystringSchema,
} from './MessageQuerystring';
import { IModuleApi } from './ModuleApi';
import {AuthorizationSecurity} from "./AuthorizationSecurity";
import { AuthorizationSecurity } from './AuthorizationSecurity';

/**
* Abstract module api class implementation.
Expand Down
2 changes: 1 addition & 1 deletion 00_Base/src/interfaces/api/ExceptionHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {FastifyError, FastifyReply, FastifyRequest} from 'fastify';
import { FastifyError, FastifyReply, FastifyRequest } from 'fastify';

export interface ExceptionHandler {
handle(
Expand Down
4 changes: 4 additions & 0 deletions 00_Base/src/interfaces/router/AuthenticationOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type AuthenticationOptions = {
securityProfile: number;
allowUnknownChargingStations: boolean;
};
11 changes: 6 additions & 5 deletions 00_Base/src/interfaces/router/Authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
//
// SPDX-License-Identifier: Apache 2.0

import { IncomingMessage } from 'http';
import { AuthenticationOptions } from './AuthenticationOptions';

export interface IAuthenticator {
authenticate(
allowUnknownChargingStations: boolean,
identifier: string,
username?: string,
password?: string,
): Promise<boolean>;
request: IncomingMessage,
options: AuthenticationOptions,
): Promise<{ identifier: string }>;
}
1 change: 1 addition & 0 deletions 00_Base/src/interfaces/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
export { IMessageRouter } from './Router';
export { AbstractMessageRouter } from './AbstractRouter';
export { IAuthenticator } from './Authenticator';
export { AuthenticationOptions } from './AuthenticationOptions';
Loading

0 comments on commit a6701d6

Please sign in to comment.