Skip to content

Commit

Permalink
Merge pull request #384 from freon4dsl/server-package-to-typ-module
Browse files Browse the repository at this point in the history
Server package to typ module
  • Loading branch information
joswarmer authored Sep 19, 2024
2 parents a110a43 + fe68f88 commit d72b098
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"access": "public"
},
"license": "MIT",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/freon4dsl/Freon4dsl"
Expand All @@ -17,7 +18,7 @@
"scripts": {
"clean": "rm -rf node_modules/ && rm -rf dist/",
"cleanup": "bash ../../scripts/cleanup.sh",
"start": "cross-env NODE_ENV=development NODE_PORT=8001 nodemon --watch 'src/**/*' -e ts,tsx --exec ts-node ./src/server/server-starter.ts",
"start": "cross-env NODE_ENV=development NODE_PORT=8001 nodemon --watch 'src/**/*' -e ts,tsx --exec node ./dist/server/server-starter.js",
"build": "tsc --build",
"build-dev": "tsc --build",
"build-verbose": "tsc --build --verbose --listFiles --listEmittedFiles",
Expand All @@ -35,6 +36,7 @@
},
"dependencies": {
"@types/koa": "^2.13.4",
"@lionweb/validation": "^0.6.3",
"koa": "2.13.1",
"koa-bodyparser": "4.3.0",
"koa-router": "10.0.0",
Expand Down
23 changes: 21 additions & 2 deletions packages/server/src/server/ModelRequests.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { issuestoString, LanguageRegistry, LionWebJsonChunk, LionWebValidator } from "@lionweb/validation"
import * as fs from "fs";
import { IRouterContext } from "koa-router";
var path = require("path");
import * as path from "node:path"
// var path = require("path");

const storeFolder = "./modelstore";

export class ModelRequests {
public static validate = false;

public static async putModelUnit(foldername: string, name: string, ctx: IRouterContext) {
try {
this.checkStoreFolder();
Expand All @@ -21,7 +25,22 @@ export class ModelRequests {
public static async getModelUnit(foldername: string, name: string, ctx: IRouterContext) {
try {
this.checkStoreFolder();
ctx.response.body = fs.readFileSync(path.join(`${storeFolder}`, foldername, `${name}.json`));
const result = fs.readFileSync(path.join(`${storeFolder}`, foldername, `${name}.json`))
if (ModelRequests.validate) {
const jsonObject = JSON.parse(result.toString())
// LOGGER.log(`jsonObject ${JSON.stringify(jsonObject)}`);
const chunk = jsonObject as LionWebJsonChunk;
const validator = new LionWebValidator(chunk, new LanguageRegistry())
validator.validateSyntax()
if (validator.validationResult.hasErrors()) {
console.error(issuestoString(validator.validationResult, name + ": lionweb-deserialize-syntax"))
}
validator.validateReferences()
if (validator.validationResult.hasErrors()) {
console.error(issuestoString(validator.validationResult, name + ": lionweb-deserialize-references"))
}
}
ctx.response.body = result;
} catch (e) {
console.log(e.message);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/server/logging.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Koa from "koa";
import { ParsedUrlQuery } from "querystring";
import { config } from "./config";
import { config } from "./config.js";

interface ILogData {
method: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/server/routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Router from "koa-router";

import { ModelRequests } from "./ModelRequests";
import { ModelRequests } from "./ModelRequests.js";

const router = new Router();

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/server/server-def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Koa from "koa";
import bodyParser from "koa-bodyparser";
import cors from "koa2-cors";

import { routes } from "./routes";
import { routes } from "./routes.js";

export const app = new Koa();

Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/server/server-starter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app } from "./server-def";
import { config } from "./config";
import { app } from "./server-def.js";
import { config } from "./config.js";

app.listen(config.port);

Expand Down
4 changes: 2 additions & 2 deletions packages/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "../../tsconfig-base.json",
"compilerOptions": {
"outDir": "dist",
"target": "es2017",
"target": "es2021",
"declaration": true,
"downlevelIteration": true,
"declarationMap": true,
Expand All @@ -15,7 +15,7 @@
"es6",
"es2016.array.include"
],
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"newLine": "lf",
"noEmit": false,
Expand Down

0 comments on commit d72b098

Please sign in to comment.