Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add a ReScript runtime and a wrapper for french_law.js #464

Merged
merged 11 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 16 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,33 @@ To uninstall, use

### Generating website assets

#### Updating [`@catala-lang/catala-web-assets`](https://www.npmjs.com/package/@catala-lang/catala-web-assets)

The Catala website features assets generated by the Catala compiler. They are
needed to build the website. To produce them, simply run

make website-assets DUNE_PROFILE=release

Then, use a helper script to copy them over to the `assets` directory of the
Catala website.
[`catala-web-assets`](https://github.com/CatalaLang/catala-web-assets)
repository.

./generate_website_assets.sh <path-to-catala-website>/assets
./generate_website_assets.sh <path-to-catala-web-assets>/assets

You will need the `groff` executable to generate the HTML versions of the man
> You will need the `groff` executable to generate the HTML versions of the man
pages, as well as the `rsync` executable to transfer files (preferred to `cp`)
because it also works with a remote server.

#### Updating [`@catala-lang/french-law`](https://www.npmjs.com/package/@catala-lang/french-law)

When a new version of the `french_law.js` (see the [dedicated
README](https://github.com/CatalaLang/catala/tree/master/french_law/js#generating-the-source-files)
to generate the lib) needs to be published, you need to execute from the
`french_law/js` directory, the following commands:

npm version patch -m "Patch message"
npm publish

## Syntax highlighting

See the [dedicated `README.md`](./syntax_highlighting/README.md).
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ run_french_law_library_benchmark_js: build_french_law_library_js

#> build_french_law_library_js : Builds the JS version of the OCaml French law library
build_french_law_library_js:
dune build $(FRENCH_LAW_JS_LIB_DIR)/french_law.js
dune build $(FRENCH_LAW_JS_LIB_DIR)/src/french_law.js

#> build_french_law_library_web_api : Builds the web API of the French law library
build_french_law_library_web_api: build_french_law_library_js generate_french_law_json_schemas
Expand Down
4 changes: 3 additions & 1 deletion french_law/js/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules/
node_modules/
lib/
*.bs.js
18 changes: 15 additions & 3 deletions french_law/js/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Javascript French Law Library
# [`@catala-lang/french-law`](https://www.npmjs.com/package/@catala-lang/french-law?activeTab=readme) ![npm][npm]

This folder contains a ready-to-use Javascript library featuring French public
algorithms coded up in Catala.
algorithms coded up in Catala and the corresponding ReScript wrapper.

## Generating the source files

Expand All @@ -22,12 +22,21 @@ make build_french_law_library_js

## API description

The `french_law.js` library exposes:
The `./src/french_law.js` library exposes:

- an [event manager](#the-event-manager)
- a list of [API functions](#api-functions)
- a list of fully exposed [sub-libraries](#sub-libraries)

### ReScript

The ReScript API is essentialy the same that the JS one within the
`CatalaFrenchLaw` top module.

Example of project using the ReScript wrapper:

* [`catala-website`](https://github.com/CatalaLang/catala-website)

### The event manager

A JavaScript object `eventsManager` is exposed with three callable methods:
Expand Down Expand Up @@ -137,3 +146,6 @@ var allocationsFamiliales = frenchLaw.AllocationsFamilialesLib
// corresponding to the file: `../ocaml/law_source/aides_logement_api_web.ml
var aidesLogement = frenchLaw.AidesLogementLib
```


[npm]: https://img.shields.io/npm/v/@catala-lang/french-law
15 changes: 15 additions & 0 deletions french_law/js/bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@catala-lang/french-law",
"refmt": 3,
"sources": ["src"],
"package-specs": [
{
"module": "es6",
"in-source": true
}
],
"suffix": ".bs.js",
"bs-dependencies": [
"@catala-lang/rescript-catala"
]
}
4 changes: 0 additions & 4 deletions french_law/js/dune

This file was deleted.

228 changes: 114 additions & 114 deletions french_law/js/examples.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Law = require("./french_law.js");
var Law = require("./src/french_law.js");
var Benchmark = require("benchmark");
const util = require("util");
const { cachedDataVersionTag } = require("v8");
Expand All @@ -7,33 +7,33 @@ var suite = new Benchmark.Suite();

function run_computation_AF(log) {
var result = Law.computeAllocationsFamiliales({
"iDateCouranteIn": "2020-04-20",
"iEnfantsIn": [
iDateCouranteIn: "2020-04-20",
iEnfantsIn: [
{
"dIdentifiant": 0,
"dRemunerationMensuelle": 0,
"dDateDeNaissance": "2003-02-02",
"dPriseEnCharge": { kind: "EffectiveEtPermanente", payload: null },
"dADejaOuvertDroitAuxAllocationsFamiliales": true,
"dBeneficieTitrePersonnelAidePersonnelleLogement": false,
dIdentifiant: 0,
dRemunerationMensuelle: 0,
dDateDeNaissance: "2003-02-02",
dPriseEnCharge: { kind: "EffectiveEtPermanente", payload: null },
dADejaOuvertDroitAuxAllocationsFamiliales: true,
dBeneficieTitrePersonnelAidePersonnelleLogement: false,
},
{
"dIdentifiant": 1,
"dRemunerationMensuelle": 300,
"dDateDeNaissance": "2013-09-30",
"dPriseEnCharge": {
"kind": "GardeAlterneePartageAllocations",
"payload": null,
dIdentifiant: 1,
dRemunerationMensuelle: 300,
dDateDeNaissance: "2013-09-30",
dPriseEnCharge: {
kind: "GardeAlterneePartageAllocations",
payload: null,
},
"dADejaOuvertDroitAuxAllocationsFamiliales": true,
"dBeneficieTitrePersonnelAidePersonnelleLogement": false,
dADejaOuvertDroitAuxAllocationsFamiliales: true,
dBeneficieTitrePersonnelAidePersonnelleLogement: false,
},
],
"iRessourcesMenageIn": 30000,
"iResidenceIn": { "kind": "Metropole", "payload": null },
"iPersonneChargeEffectivePermanenteEstParentIn": true,
"iPersonneChargeEffectivePermanenteRemplitTitreIIn": true,
"iAvaitEnfantAChargeAvant1erJanvier2012In": false,
iRessourcesMenageIn: 30000,
iResidenceIn: { kind: "Metropole", payload: null },
iPersonneChargeEffectivePermanenteEstParentIn: true,
iPersonneChargeEffectivePermanenteRemplitTitreIIn: true,
iAvaitEnfantAChargeAvant1erJanvier2012In: false,
});
if (log) {
console.log(
Expand All @@ -50,121 +50,121 @@ function run_computation_AF(log) {

function run_computation_AL(log) {
var result = Law.computeAidesAuLogement({
"menageIn": {
"prestationsRecues": [],
"logement": {
"residencePrincipale": true,
"estEhpadOuMaisonAutonomieL31312Asf": false,
"modeOccupation": {
"kind": "Locataire",
"payload": {
"bailleur": {
"kind": "BailleurPrive"
menageIn: {
prestationsRecues: [],
logement: {
residencePrincipale: true,
estEhpadOuMaisonAutonomieL31312Asf: false,
modeOccupation: {
kind: "Locataire",
payload: {
bailleur: {
kind: "BailleurPrive",
},
"beneficiaireAideAdulteOuEnfantHandicapes": false,
"logementEstChambre": false,
"colocation": false,
"ageesOuHandicapAdultesHebergeesOnereuxParticuliers": false,
"logementMeubleD8422": false,
"changementLogementD8424": {
"kind": "PasDeChangement",
"payload": null
beneficiaireAideAdulteOuEnfantHandicapes: false,
logementEstChambre: false,
colocation: false,
ageesOuHandicapAdultesHebergeesOnereuxParticuliers: false,
logementMeubleD8422: false,
changementLogementD8424: {
kind: "PasDeChangement",
payload: null,
},
"loyerPrincipal": 450
}
loyerPrincipal: 450,
},
},
"proprietaire": {
"kind": "Autre",
"payload": null
proprietaire: {
kind: "Autre",
payload: null,
},
"loueOuSousLoueADesTiers": {
"kind": "Non"
loueOuSousLoueADesTiers: {
kind: "Non",
},
"usufruit": {
"kind": "Autre",
"payload": null
usufruit: {
kind: "Autre",
payload: null,
},
"logementDecentL89462": true,
"zone": {
"kind": "Zone2"
logementDecentL89462: true,
zone: {
kind: "Zone2",
},
"surfaceMCarres": 65
surfaceMCarres: 65,
},
"personnesACharge": [
personnesACharge: [
{
"kind": "EnfantACharge",
"payload": {
"aDejaOuvertDroitAuxAllocationsFamiliales": true,
"remunerationMensuelle": 0,
"nationalite": {
"kind": "Francaise",
"payload": null,
kind: "EnfantACharge",
payload: {
aDejaOuvertDroitAuxAllocationsFamiliales: true,
remunerationMensuelle: 0,
nationalite: {
kind: "Francaise",
payload: null,
},
"etudesApprentissageStageFormationProImpossibiliteTravail": false,
"obligationScolaire": {
"kind": "Pendant",
"payload": null,
etudesApprentissageStageFormationProImpossibiliteTravail: false,
obligationScolaire: {
kind: "Pendant",
payload: null,
},
"situationGardeAlternee": {
"kind": "PasDeGardeAlternee",
"payload": null,
situationGardeAlternee: {
kind: "PasDeGardeAlternee",
payload: null,
},
"dateDeNaissance": "2015-01-01",
"identifiant": 0
}
dateDeNaissance: "2015-01-01",
identifiant: 0,
},
},
{
"kind": "EnfantACharge",
"payload": {
"aDejaOuvertDroitAuxAllocationsFamiliales": true,
"remunerationMensuelle": 0,
"nationalite": {
"kind": "Francaise",
"payload": null,
kind: "EnfantACharge",
payload: {
aDejaOuvertDroitAuxAllocationsFamiliales: true,
remunerationMensuelle: 0,
nationalite: {
kind: "Francaise",
payload: null,
},
"etudesApprentissageStageFormationProImpossibiliteTravail": false,
"obligationScolaire": {
"kind": "Pendant",
"payload": null,
etudesApprentissageStageFormationProImpossibiliteTravail: false,
obligationScolaire: {
kind: "Pendant",
payload: null,
},
"situationGardeAlternee": {
"kind": "PasDeGardeAlternee",
"payload": null,
situationGardeAlternee: {
kind: "PasDeGardeAlternee",
payload: null,
},
"dateDeNaissance": "2016-01-01",
"identifiant": 1
}
}
dateDeNaissance: "2016-01-01",
identifiant: 1,
},
},
],
"nombreAutresOccupantsLogement": 0,
"situationFamiliale": {
"kind": "Concubins",
"payload": null
nombreAutresOccupantsLogement: 0,
situationFamiliale: {
kind: "Concubins",
payload: null,
},
conditionRattacheFoyerFiscalParentIfi: false,
enfantANaitreApresQuatriemeMoisGrossesse: false,
personnesAgeesHandicapeesFoyerR8444: false,
residence: {
kind: "Metropole",
payload: null,
},
"conditionRattacheFoyerFiscalParentIfi": false,
"enfantANaitreApresQuatriemeMoisGrossesse": false,
"personnesAgeesHandicapeesFoyerR8444": false,
"residence": {
"kind": "Metropole",
"payload": null
}
},
"demandeurIn": {
"nationalite": {
"kind": "Francaise",
"payload": null,
demandeurIn: {
nationalite: {
kind: "Francaise",
payload: null,
},
"estNonSalarieAgricoleL7818L78146CodeRural": false,
"magistratFonctionnaireCentreInteretsMaterielsFamiliauxHorsMayotte": false,
"patrimoine": {
"produisantRevenuPeriodeR82233R8224": 0,
"neProduisantPasRevenuPeriodeR82233R8224": 0
estNonSalarieAgricoleL7818L78146CodeRural: false,
magistratFonctionnaireCentreInteretsMaterielsFamiliauxHorsMayotte: false,
patrimoine: {
produisantRevenuPeriodeR82233R8224: 0,
neProduisantPasRevenuPeriodeR82233R8224: 0,
},
"personneHebergeeCentreSoinLL162223SecuriteSociale": false,
"dateNaissance": "1992-01-01"
personneHebergeeCentreSoinLL162223SecuriteSociale: false,
dateNaissance: "1992-01-01",
},
"dateCouranteIn": "2022-05-01",
"ressourcesMenagePrisesEnCompteIn": 11500,
dateCouranteIn: "2022-05-01",
ressourcesMenagePrisesEnCompteIn: 11500,
});
if (log) {
console.log(
Expand Down
Loading