Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4ddb5f1
final
alibazregar Jul 1, 2024
f36fc59
F
alibazregar Jul 1, 2024
02becdf
FINAL
alibazregar Jul 1, 2024
6a007b8
changes
alibazregar Jul 2, 2024
24a690c
fff
alibazregar Jul 3, 2024
d9a5c65
Merge branch 'master' of https://github.com/Manzoomeh/BasisCore.Serve…
alibazregar Sep 22, 2024
0f8976d
changes in tls
alibazregar Sep 22, 2024
e6ab809
remove log
alibazregar Sep 22, 2024
a5a43ca
add details
alibazregar Oct 21, 2024
72125f5
add details
alibazregar Oct 21, 2024
f42cb0c
Merge branch 'master' of https://github.com/Manzoomeh/BasisCore.Serve…
alibazregar Oct 21, 2024
5ca3950
fix request context
alibazregar Oct 21, 2024
a11706e
fix secure
alibazregar Oct 21, 2024
60edf42
remove-logs
alibazregar Oct 21, 2024
8a48ab9
fixing alasql structure
alibazregar Oct 21, 2024
3f55541
Merge branch 'master' of https://github.com/Manzoomeh/BasisCore.Serve…
alibazregar Oct 27, 2024
3f169aa
add-alasql-to-root
alibazregar Oct 29, 2024
40f6bab
Merge branch 'master' of https://github.com/Manzoomeh/BasisCore.Serve…
alibazregar Oct 29, 2024
7fc1416
Merge branch 'master' of https://github.com/Manzoomeh/BasisCore.Serve…
alibazregar Nov 2, 2024
a312c62
edit cache pipeline
alibazregar Nov 2, 2024
2d05756
FINAL CACHE CHANGES
alibazregar Nov 3, 2024
bc41501
first steps
alibazregar Nov 4, 2024
ab42a1f
Merge branch 'master' of https://github.com/Manzoomeh/BasisCore.Serve…
alibazregar Nov 5, 2024
4e30cf6
finalize
alibazregar Nov 23, 2024
c72ec97
final steps
alibazregar Nov 25, 2024
ea10d04
fix package.json
alibazregar Nov 25, 2024
4e2c10a
fix util.js
alibazregar Nov 25, 2024
5f1c6e9
remove insert from connection info
alibazregar Nov 25, 2024
586922a
delete add debug context from context
alibazregar Nov 26, 2024
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
Expand Up @@ -11,3 +11,4 @@ il.json
test1.db
report.json
cache
cachefiles
32 changes: 32 additions & 0 deletions ExternalCommands/external.fly.ws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import SourceCommand from "./../renderEngine/Command/Source/BaseClasses/SourceCommand.js";
import ICommandResult from "./../renderEngine/Models/ICommandResult.js";
export default class FlyCommand extends SourceCommand {
/**
* @param {object} flyIl
*/
constructor(flyIl) {
super(flyIl);
}

/**
* @param {string} sourceName
* @param {IContext} context
* @returns {Promise<ICommandResult>}
*/
async _loadDataAsync(sourceName, context) {
const [connectionName, command] = await Promise.all([
this.connectionName.getValueAsync(context),
this.toCustomFormatHtmlAsync(context),
]);
const inputs = {
command,
dmnid: context.domainId,
};
const encoder = new TextEncoder();
const byteMessage = encoder.encode(JSON.stringify(inputs));
const parameters = {
byteMessage,
};
return await context.loadDataAsync(sourceName, connectionName, parameters);
}
}
1 change: 1 addition & 0 deletions Models/Connection/ConnectionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class ConnectionInfo {
convertJSONToDataSet(content) {
if (content?.sources && Array.isArray(content?.sources)) {
let retVal = [];

content.sources.forEach((source) => {
retVal.push(source.data);
});
Expand Down
4 changes: 4 additions & 0 deletions Models/Connection/ConnectionUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import MongoConnectionInfo from "./MongoConnectionInfo.js";
import SqliteConnectionInfo from "./SqLiteConnectionInfo.js";
import MySqlConnectionInfo from "./MySqlConnectionInfo.js";
import SocketConnectionInfo from "./SocketConnectionInfo.js";
import WebConnectionInfo from "./WebConnectionInfo.js";
export default class ConnectionUtil {
/**
* @param {NodeJS.Dict<any>} settings
Expand Down Expand Up @@ -54,6 +55,9 @@ export default class ConnectionUtil {
connection = new SocketConnectionInfo(parts[2], settings[item]);
break;
}
case "web" : {
connection = new WebConnectionInfo(parts[2],settings[item])
}
default: {
if (parts[1] == "ws") {
continue;
Expand Down
18 changes: 9 additions & 9 deletions Models/Connection/IMongoSettingData.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export default class IMongoSettingData {
/** @type {string} */
dataBase;
/** @type {string}*/
endpoint;
/** @type {string}*/
collection;
/** @type {string}*/
method;
/**@type {object} */
query;
address;
/** @type {?string}*/
databaseName;
/** @type {?string}*/
collectionName;
/** @type {string}*/
method;
/**@type {object} */
query;
}
69 changes: 53 additions & 16 deletions Models/Connection/MongoConnectionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import CancellationToken from "../../renderEngine/Cancellation/CancellationToken
import Request from "./../request.js";
import IMongoSettingData from "./IMongoSettingData.js";
import BasisCoreException from "../Exceptions/BasisCoreException.js";
import IRoutingRequest from "../IRoutingRequest.js";
import { http } from "winston";
export default class MongoConnectionInfo extends ConnectionInfo {
/**@type {MongoClient} */
client;
/** @type {IMongoSettingData} */
settings;
/**@param {MongoClient} client */
client;

/**
* @param {string} name
Expand All @@ -18,8 +20,8 @@ export default class MongoConnectionInfo extends ConnectionInfo {
*/
constructor(name, settings) {
super(name);
this.client = new MongoClient(settings.address);
this.settings = settings;
this.client = new MongoClient(this.settings.endpoint);
}

/**
Expand All @@ -30,34 +32,69 @@ export default class MongoConnectionInfo extends ConnectionInfo {
async loadDataAsync(parameters, cancellationToken) {
try {
await this.client.connect();
const db = this.client.db(this.settings.dataBase);
const collection = db.collection(this.settings.collection);
const { collectionName, dbname } = parameters;
const db = this.client.db(dbname);
const collection = db.collection(collectionName);
if (typeof collection[this.settings.method] != "function") {
throw new BasisCoreException("invalid method");
}
const result = await collection[this.settings.method](this.settings.query)
const result = await collection[this.settings.method](
this.settings.query
);
return new DataSourceCollection([await result.toArray()]);
} catch (err) {
throw err;
}
finally {
await this.client.close();
} finally {
await this.client.close();
}
}
/**
* Insert a document into a MongoDB collection.
* @param {string} sourceName
* @param {string} connectionName
* @param {string} databaseName
* @param {string} collectionName
* @param {Object} data
* @returns {Promise<Object>}
*/
async insertAsync(
sourceName,
connectionName,
databaseName,
collectionName,
data
) {
try {
if (!databaseName) {
databaseName = this.settings.databaseName;
}
await this.client.connect();

const database = client.db(databaseName);
const collection = database.collection(collectionName);

const result = await collection.insertOne(data);
await client.close();
return result._id;
} catch (error) {
throw new Error(
`Error in loading data for '${sourceName}' source command from '${connectionName}' connection: ${error.message}`
);
}
}
/**
* @param {Request} request
* @param {BinaryContent[]} fileContents
* @returns {Promise<Response>}
*/
async testConnectionAsync() {
try{
await this.client.connect()
return true
}catch(err){
return false
}finally{
await this.client.close()
try {
await this.client.connect();
return true;
} catch (err) {
return false;
} finally {
await this.client.close();
}
}
}
17 changes: 8 additions & 9 deletions Models/Connection/SqlConnectionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ export default class SqlConnectionInfo extends ConnectionInfo {
? `;requestTimeout=${this.settings.requestTimeout}`
: "")
);
this.connectionPool.connect().catch((err)=>{
console.log("error in connect",this.name,err)
})

this.connectionPool.connect().catch((err) => {
console.log("error in connect", this.name, err);
});
}

/**
Expand Down Expand Up @@ -70,9 +69,9 @@ export default class SqlConnectionInfo extends ConnectionInfo {
*/
async getRoutingDataAsync(request, cancellationToken) {
const params = new sql.Table();
params.columns.add("ParamType", sql.NVarChar(50));
params.columns.add("ParamName", sql.NVarChar(100));
params.columns.add("ParamValue", sql.NVarChar());
params.columns.add("ParamType", sql.NVarChar(50));
params.columns.add("ParamName", sql.NVarChar(100));
params.columns.add("ParamValue", sql.NVarChar());

for (const type in request) {
const group = request[type];
Expand All @@ -82,9 +81,9 @@ export default class SqlConnectionInfo extends ConnectionInfo {
for (const key in query) {
params.rows.add(name, key, query[key]?.toString());
}
} else if(name === "json"){
} else if (name === "json") {
params.rows.add(type, name, JSON.stringify(group[name]));
}else {
} else {
params.rows.add(type, name, group[name]?.toString());
}
}
Expand Down
41 changes: 41 additions & 0 deletions Models/Connection/WebConnectionInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import WebSettingData from "./WebSettingData.js";
import ConnectionInfo from "./ConnectionInfo.js";
import DataSourceCollection from "../../renderEngine/Source/DataSourceCollection.js";
import CancellationToken from "../../renderEngine/Cancellation/CancellationToken.js";
import BasisCoreException from "../Exceptions/BasisCoreException.js";

export default class WebConnectionInfo extends ConnectionInfo {
/** @type {string} */
url;
/**
* @param {string} name
* @param {WebSettingData} settings
*/
constructor(name, settings) {
super(name);
this.url = settings.url;
}

/**
* @param {NodeJS.Dict<object|string|number>} parameters
* @param {CancellationToken} cancellationToken
* @returns {Promise<DataSourceCollection>}
*/
async loadDataAsync(parameters, cancellationToken) {
try {
let body = new URLSearchParams(parameters);
const response = await fetch(url, {
method: "POST",
body: body,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
});
return new DataSourceCollection(await response.json());
} catch (error) {
return new BasisCoreException(
"Failed to fetch request from url " + this.url
);
}
}
}
5 changes: 5 additions & 0 deletions Models/Connection/WebSettingData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default class WebSettingData {
/** @type {string} */
url;
}

5 changes: 3 additions & 2 deletions Models/Index4Response.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from "fs";
import { StatusCodes } from "http-status-codes";
import RequestBaseResponse from "./requestBaseResponse.js";
import im from "imagemagick";
import path from "path";
import Pako from "pako";
import Util from "../Util.js";
Expand Down Expand Up @@ -44,6 +43,8 @@ export default class Index4Response extends RequestBaseResponse {
size,
setting.deform
);
const dirPath = path.dirname(destinationPath);
Index4Response._createDirectoryIfNotExist(dirPath)
await fs.promises.writeFile(destinationPath, newContent);
finalPath = destinationPath;
if (gzip) {
Expand Down Expand Up @@ -157,7 +158,7 @@ static _mackWebpAsync(content, quality) {
static _createDirectoryIfNotExist(filePath) {
const pathDirectory = path.dirname(filePath);
if (!fs.existsSync(pathDirectory)) {
fs.mkdirSync(pathDirectory);
fs.mkdirSync(pathDirectory,{recursive : true});
}
Comment on lines 160 to 162

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we not use Index4Response._createDirectoryIfNotExist(pathDirectory)?

}

Expand Down
2 changes: 1 addition & 1 deletion endPoint/h2HttpHostEndPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,4 @@ export default class H2HttpHostEndPoint extends SecureHttpHostEndPoint {
next();
}
}
}
}
2 changes: 1 addition & 1 deletion endPoint/httpHostEndPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,4 @@ class HttpHostEndPoint extends HostEndPoint {
console.log(`server ip ${this._ip} and port ${this._port} killed`);
}
}
export default HttpHostEndPoint;
export default HttpHostEndPoint;
2 changes: 1 addition & 1 deletion endPoint/nonSecureHttpHostEndPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ export default class NonSecureHttpHostEndPoint extends HttpHostEndPoint {
});
return this._server;
}
}
}
2 changes: 1 addition & 1 deletion endPoint/secureHttpHostEndPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ export default class SecureHttpHostEndPoint extends HttpHostEndPoint {
.on("tlsClientError", (er) => console.error(er));
return this._server;
}
}
}
24 changes: 21 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading