generated from mojaloop/typescript-svc-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: schema translation for fspiop and fspiop20022
feat: schema translation for fspiop and fspiop20022
- Loading branch information
Showing
42 changed files
with
14,668 additions
and
18,114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,3 +80,6 @@ devspace* | |
# Add Ignores | ||
*IGNORE* | ||
*ignore* | ||
test/reports | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
npm run lint | ||
npm run dep:check | ||
npm run audit:check | ||
npm run test:unit |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,137 @@ | ||
# Typescript Project Template | ||
# ML Schema Transformer (MLST) | ||
|
||
<!-- ACTION: REPLACE <repo-name> placeholders in this document --> | ||
[![Git Commit](https://img.shields.io/github/last-commit/mojaloop/<repo-name>.svg?style=flat)](https://github.com/mojaloop/<repo-name>/commits/master) | ||
[![Git Releases](https://img.shields.io/github/release/mojaloop/<repo-name>.svg?style=flat)](https://github.com/mojaloop/<repo-name>/releases) | ||
[![Npm Version](https://img.shields.io/npm/v/@mojaloop/<repo-name>.svg?style=flat)](https://www.npmjs.com/package/@mojaloop/<repo-name>) | ||
[![NPM Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/@mojaloop/<repo-name>.svg?style=flat)](https://www.npmjs.com/package/@mojaloop/<repo-name>) | ||
[![CircleCI](https://circleci.com/gh/mojaloop/<repo-name>.svg?style=svg)](https://circleci.com/gh/mojaloop/<repo-name>) | ||
[![Git Commit](https://img.shields.io/github/last-commit/mojaloop/ml-schema-transformer-lib.svg?style=flat)](https://github.com/mojaloop/ml-schema-transformer-lib/commits/master) | ||
[![Git Releases](https://img.shields.io/github/release/mojaloop/ml-schema-transformer-lib.svg?style=flat)](https://github.com/mojaloop/ml-schema-transformer-lib/releases) | ||
[![Npm Version](https://img.shields.io/npm/v/@mojaloop/ml-schema-transformer-lib.svg?style=flat)](https://www.npmjs.com/package/@mojaloop/ml-schema-transformer-lib) | ||
[![CircleCI](https://circleci.com/gh/mojaloop/ml-schema-transformer-lib.svg?style=svg)](https://circleci.com/gh/mojaloop/ml-schema-transformer-lib) | ||
|
||
A project template for new mojaloop services and libraries that uses Typescript. | ||
A shared component for transforming mojaloop payloads from one schema to another. | ||
|
||
## Contributing | ||
|
||
Refer to [CONTRIBUTING.md](./CONTRIBUTING.md) for information on how to contribute, committing changes, releases and snapshots. | ||
|
||
<!-- ACTION: REPLACE THIS SECTION START --> | ||
## Template Setup \<REMOVE SECTION\> | ||
## Getting Started | ||
|
||
This project provides a decent starting point for a new mojaloop library using typescript. | ||
### Installing | ||
|
||
<!-- NOTE: setup steps for this repo --> | ||
1. Go to <https://github.com/new> to create a new repo | ||
2. Select the "mojaloop/template-typescript-public" template | ||
3. Find and replace all instances of `<repo-name>` globally across the whole project with your new project's name | ||
4. Update the package name and version to match in `package.json`: | ||
``` | ||
npm i @mojaloop/ml-schema-transformer-lib | ||
``` | ||
|
||
### Usage | ||
|
||
```json | ||
"name": "@mojaloop/repo-name", | ||
"version": "0.1.0", | ||
... | ||
``` | ||
MLST can be used via the exported facades or the creator function. | ||
|
||
5. Copy the necessary circle ci config from the templates. | ||
**Facades** | ||
|
||
```bash | ||
cp ./.circleci/config.example.yml ./.circleci/config.yml | ||
rm -f ./.circleci/config.example.* | ||
``` | ||
``` | ||
// ESM | ||
import { TransformFacades } from '@mojaloop/ml-schema-transformer-lib'; | ||
// CJS | ||
const { TransformFacades } = require('@mojaloop/ml-schema-transformer-lib') | ||
// source is an FSPIOP POST /quotes payload | ||
const source = { | ||
body: { | ||
quoteId: 'random quote id', | ||
..., | ||
}, | ||
headers: { ... }, | ||
params: { ... } | ||
}; | ||
// target is an FSPIOP ISO 20022 Post /quotes payload | ||
const target = await TransformFacades.FSPIOP.quotes.post(source); | ||
``` | ||
The facade functions work with built-in mappings which are located in `src/mappings` directory. | ||
The facade functions take optional second parameter of type `TransformFacadeOptions` for controlling certain aspects of the function. | ||
|
||
If the project is a **Library**: | ||
For example: | ||
- To override the mapping used in the function, pass in `{ overrideMapping: 'your mapping JSON string' }` | ||
- To pass in additional options for the instantiation of [MapTransform](https://github.com/integreat-io/map-transform) (the underlying transformation library), pass in `{ mapTransformOptions: { ...additionalMapTransformOptions } }`. | ||
- To pass in additional options for the MapTransform mapper call, pass in `{ mapperOptions: { ...additionalMapperOptions } }` | ||
|
||
Make sure to read comments and replace the applicable `publish` & `publish-snapshot` jobs with the NPM Publish job variants. | ||
**Creator Function** | ||
|
||
<!-- ACTION: REPLACE THIS SECTION END --> | ||
``` | ||
// ESM | ||
import { createTransformer } from ' @mojaloop/ml-schema-transformer-lib'; | ||
// CJS | ||
const { createTransformer } = require('@mojaloop/ml-schema-transformer-lib') | ||
## Pre-requisites | ||
const mapping = { "quoteId": "CdtTrfTxInf.PmtId.TxId", ... } | ||
### Install dependencies | ||
const transformer = await createTransformer(mapping); | ||
const transformer = createTransformer(mapping) | ||
```bash | ||
npm install | ||
const source = { body: { quoteId: 'random quote id', ... }, ... }; | ||
const target = transformer.transform(source); | ||
``` | ||
|
||
## Build | ||
The `createTransform` function takes an optional second parameter of type `CreateTransformerOptions` for controlling the instantiation of the `MapTransform` object. | ||
|
||
Command to transpile Typescript into JS: | ||
For example: | ||
- To pass in additional options for the instantiation of `MapTransform`, pass in { mapTransformOptions: { ...additionalMapTransformOptions } } | ||
|
||
```bash | ||
npm run build | ||
``` | ||
### Custom Transform Functions | ||
|
||
Command to LIVE transpile Typescript into JS live when any changes are made to the code-base: | ||
Custom transform functions are special functions which are embedded in field mappings and are executed during transformation of those fields. | ||
To provide custom transform functions (for both Facades and `createTransformer` use cases): | ||
|
||
```bash | ||
npm run watch | ||
``` | ||
const fn1 = (options) => () => (data, state) => { | ||
const modified = // apply custom transformation to `data`; | ||
return modified; | ||
} | ||
const fn2 = (options) => () => (data, state) => { | ||
const modified = // apply custom transformation to `data`; | ||
return modified; | ||
} | ||
const options = { | ||
mapTransformOptions: { | ||
transformers: { | ||
fn1, | ||
fn2, | ||
... | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Run | ||
Replace `fn1` and `fn2` with the actual names of your functions. See `src/lib/transforms/index.ts` or [here](https://github.com/integreat-io/map-transform?tab=readme-ov-file#operations) for more on authoring and using custom transform functions in mappings. | ||
|
||
```bash | ||
npm start | ||
``` | ||
### Environment Variables | ||
| Env Variable Name | Default Value | Description | | ||
|-----------------------------|---------------|------------------------------------------------------| | ||
| MLST_LOG_LEVEL | `warn` | The log level for MLST | | ||
| MLST_ILP_VERSION | `v4` | ILP version used for `ilpPacketToCondition` transform| | ||
|
||
|
||
## Performance | ||
|
||
## Tests | ||
Hardware → Apple M3 Max, 14 Cores, 36 GB RAM | ||
|
||
```bash | ||
| Use Case | No. of Iterations | Duration | | ||
|-------------------------------------------------|-------------------|----------------| | ||
| POST /quotes transformation { FSPIOP → ISO } | 1000 | ~301ms | | ||
| POST /quotes transformation { ISO → FSPIOP } | 1000 |~205ms | | ||
| POST /transfers transformation { FSPIOP → ISO } | 1000 | ~135ms | | ||
| POST /transfers transformation { ISO → FSPIOP } | 1000 | ~79ms | | ||
|
||
## Development | ||
|
||
### Install Depednencies | ||
|
||
``` | ||
npm i | ||
``` | ||
|
||
### Run Tests | ||
``` | ||
npm test | ||
``` | ||
``` | ||
|
||
### Build | ||
``` | ||
npm run build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.