quatico-solutions / magellan Goto Github PK
View Code? Open in Web Editor NEWRemote service execution for TypeScript
License: MIT License
Remote service execution for TypeScript
License: MIT License
As Frontend Developer I want to have static + dynamic path support for magellan serve, so that I can use React's BrowserRouter.
When // @service annotated functions cause an error to be thrown in their backend execution. The frontend does not correctly reject the promise (as expected and documented) but instead an {error, message} object is resolved, breaking the code flow.
This appears to be caused by changes that took place along the TransportHandler implementation.
Function outside services
directory
import {throwsError} from "./throws-error.ts";
export const executeFunction = async (): Promise<string> => {
try {
return await throwsError();
} catch (e) {
const err = e as Error;
console.error(`Function 'throwsError' has thrown error ${err.message}`);
}
}
Service function in a services
directory.
// @service()
export const throwsError = async (): Promise<string> => {
if (Math.random() > 0.999) {
return "success";
}
throw new Error("This should not be provided as the return value");
};
When the function is called and the Random value is <= 0.999, throwsError() does not fail try-catch and instead returns an {error, message} object.
When the function is called and the Random value is <= 0.999, the console.error from the 'catch' clause is written.
Currently, there are cyclic dependencies between src/transport
and src/configuration
/ src/services
which express themselfes through the need to mock formdataFetch
in client/src/config/configuration-repository.spec.ts, server/src/config/configuration-repository.spec.ts and server/src/services/FunctionService.spec.ts (see commit 59e6f5c)
This will negatively impact the ability to chunk code with @quatico/magellan-client and @quatico/magellan-server dependencies.
After replacing the ts-jest transformer with @swc/jest
formdata-fetch => formdataFetch mocks are necessary to execute jest tests with @swc/jest.
tests do not require to mock away the dependency on formdataFetch to avoid issues with cyclic dependencies.
When the default client configuration is replaced with an incomplete configuration, for example during bundling, then magellan does not correctly complete the configuration as it does normally.
magellan.config.js
module.exports = {
namespaces: { default: { endpoint: "/api", transport: "default" } },
};
Replace the default client config using webpack's NormalModuleReplacementPlugin
webpack.config.js
new webpack.NormalModuleReplacementPlugin(
/node_modules\/@quatico\/magellan-client\/lib\/configuration\/config.js/,
join(__dirname, "magellan.config.js")
),
An error is thrown
default-configuration.js:23 Uncaught (in promise) TypeError: Cannot convert undefined or null to object
at Function.entries (<anonymous>)
at completeConfig (default-configuration.js:23:1)
at getDefaultConfiguration (default-configuration.js:14:1)
at getConfiguration (configuration-repository.js:17:24)
at resolveNamespace (namespace.js:50:1)
at transport-request.js:25:35
at Generator.next (<anonymous>)
at tslib.es6.js:76:1
at new Promise (<anonymous>)
at Module.__awaiter (tslib.es6.js:72:1)
The default transport is correctly added to the configuration when loaded.
To enhance the package structure in both the context of the end user and the internal knowledge, I would like to propose the following restructure of the Magellan packages and alteration of which packages will be released publically:
This will enable focused changes for public API (CLI, webpack and client / server api modules) while isolating the inner workings enabling easier and more reliable iterations.
When using magellan-server serve
function, tslib
is required but can't be found. It should be added to the package.json
dependencies.
tslib
yarn add tslib
echo '{}' > package.json
yarn add "@quatico/[email protected]"
node -p 'require("@quatico/magellan-server").serve()'
๐ฃ
โฏ node -p 'require("@quatico/magellan-server").serve()'
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'tslib'
Require stack:
- /private/tmp/magrep/node_modules/@quatico/magellan-server/lib/configuration/configuration-repository.js
- /private/tmp/magrep/node_modules/@quatico/magellan-server/lib/configuration/index.js
- /private/tmp/magrep/node_modules/@quatico/magellan-server/lib/index.js
- /private/tmp/magrep/[eval]
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/private/tmp/magrep/node_modules/@quatico/magellan-server/lib/configuration/configuration-repository.js:10:17)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/private/tmp/magrep/node_modules/@quatico/magellan-server/lib/configuration/configuration-repository.js',
'/private/tmp/magrep/node_modules/@quatico/magellan-server/lib/configuration/index.js',
'/private/tmp/magrep/node_modules/@quatico/magellan-server/lib/index.js',
'/private/tmp/magrep/[eval]'
]
}
โฏ node -p 'require("@quatico/magellan-server").serve()'
/private/tmp/magrep/node_modules/@quatico/magellan-server/lib/server.js:26
const { port = (0, exports.normalizePort)(process.env.PORT) } = options;
^
TypeError: Cannot read properties of undefined (reading 'port')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.