Skip to content

Commit

Permalink
[JS] extendedCompositions
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Aug 28, 2024
1 parent 3b92223 commit 999b8e6
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 57 deletions.
5 changes: 5 additions & 0 deletions TopModel.Generator.Javascript/JavascriptConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class JavascriptConfig : GeneratorConfigBase
/// </summary>
public EntityMode EntityMode { get; set; } = EntityMode.TYPED;

/// <summary>
/// Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées.
/// </summary>
public bool ExtendedCompositions { get; set; }

/// <summary>
/// Chemin (ou alias commençant par '@') vers le fichier 'domain', relatif au répertoire de génération.
/// </summary>
Expand Down
75 changes: 32 additions & 43 deletions TopModel.Generator.Javascript/TypescriptDefinitionGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ protected override void HandleClass(string fileName, Class classe, string tag)
case CompositionProperty cp1 when Config.IsListComposition(cp1) && cp1.Composition.Name == classe.Name:
case AliasProperty { Property: CompositionProperty cp2 } when Config.IsListComposition(cp2) && cp2.Composition.Name == classe.Name:
fw.Write("\"recursive-list\"");
if (Config.ExtendedCompositions)
{
fw.Write(",");
}

break;
case CompositionProperty when Config.IsListComposition(property):
case AliasProperty { Property: CompositionProperty } when Config.IsListComposition(property):
Expand All @@ -211,82 +216,66 @@ protected override void HandleClass(string fileName, Class classe, string tag)
_ => null
};

if (cp == null)
if (cp == null || cp.Domain != null && !Config.IsListComposition(cp))
{
fw.WriteLine($" name: \"{property.NameCamel}\",");
fw.WriteLine($" domain: {property.Domain.Name},");
fw.WriteLine($" isRequired: {(property.Required && !((property.PrimaryKey || property is AliasProperty { AliasedPrimaryKey: true }) && property.Domain.AutoGeneratedValue)).ToString().ToFirstLower()},");
fw.WriteLine(2, $"name: \"{property.NameCamel}\",");
fw.WriteLine(2, $"domain: {property.Domain.Name},");

var defaultValue = Config.GetValue(property, Classes);
if (defaultValue != "undefined")
{
fw.WriteLine($" defaultValue: {defaultValue},");
fw.WriteLine(2, $"defaultValue: {defaultValue},");
}
}
else if (cp.Composition.Name != classe.Name)
{
fw.Write(2, $"entity: {cp.Composition.NamePascal}Entity");

if (Config.ExtendedCompositions)
{
fw.Write(",");
}

fw.WriteLine();
}

if (cp == null || cp.Domain != null && !Config.IsListComposition(cp) || Config.ExtendedCompositions)
{
fw.WriteLine(2, $"isRequired: {(property.Required && !((property.PrimaryKey || property is AliasProperty { AliasedPrimaryKey: true }) && property.Domain.AutoGeneratedValue)).ToString().ToFirstLower()},");

if (Config.TranslateProperties == true)
{
fw.WriteLine($" label: \"{property.ResourceKey}\"{(Config.GenerateComments ? "," : string.Empty)}");
fw.WriteLine(2, $"label: \"{property.ResourceKey}\"{(Config.GenerateComments ? "," : string.Empty)}");
}
else
{
fw.WriteLine($" label: \"{property.Label}\"{(Config.GenerateComments ? "," : string.Empty)}");
fw.WriteLine(2, $"label: \"{property.Label}\"{(Config.GenerateComments ? "," : string.Empty)}");
}

if (Config.GenerateComments)
{
if (Config.TranslateProperties == true)
{
fw.WriteLine($" comment: \"{property.CommentResourceKey}\"");
fw.WriteLine(2, $"comment: \"{property.CommentResourceKey}\"");
}
else
{
fw.WriteLine($" comment: \"{property.Comment}\"");
fw.WriteLine(2, $"comment: \"{property.Comment}\"");
}
}
}
else if (cp.Domain != null && !Config.IsListComposition(cp))
{
fw.Write(" name: \"");
fw.Write(cp.NameCamel);
fw.Write("\"");
fw.Write(",\r\n domain: ");
fw.Write(cp.Domain.Name);
fw.Write(",\r\n isRequired: true");
fw.Write(",\r\n label: \"");
if (Config.TranslateProperties == true)
{
fw.Write(classe.Namespace.ModuleCamel);
fw.Write(".");
fw.Write(classe.NameCamel);
fw.Write(".");
fw.Write(property.NameCamel);
}
else
{
fw.Write(property.Label);
}

fw.Write("\"\r\n");
}
else if (cp.Composition.Name != classe.Name)
{
fw.Write(" entity: ");
fw.Write(cp.Composition.NamePascal);
fw.Write("Entity");
fw.Write("\r\n");
}

fw.Write(" }");
fw.Write(1, "}");

if (property != classe.Properties.Last())
{
fw.Write(",");
}

fw.Write("\r\n");
fw.WriteLine();
}

fw.Write($"}}{(Config.EntityMode == EntityMode.TYPED ? string.Empty : " as const")}\r\n");
fw.WriteLine($"}}{(Config.EntityMode == EntityMode.TYPED ? string.Empty : " as const")}");

if (classe.Reference)
{
Expand Down
12 changes: 8 additions & 4 deletions TopModel.Generator.Javascript/javascript.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@
"type": "string",
"description": "Framework cible pour la génération.",
"default": "focus",
"enum": ["angular", "angular_promise", "vanilla", "nuxt"]
"enum": [ "angular", "angular_promise", "vanilla", "nuxt" ]
},
"entityMode": {
"type": "string",
"description": "Framework cible pour la génération.",
"default": "typed",
"enum": ["untyped", "typed"]
"enum": [ "untyped", "typed" ]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
Expand All @@ -107,7 +111,7 @@
"resourceMode": {
"type": "string",
"description": "Mode de génération (JS, JSON ou JSON Schema).",
"enum": ["js", "json"]
"enum": [ "js", "json" ]
},
"translateReferences": {
"type": "boolean",
Expand All @@ -130,7 +134,7 @@
"referenceMode": {
"type": "string",
"description": "Mode de génération des listes de références (définitions ou valeurs).",
"enum": ["definition", "values"],
"enum": [ "definition", "values" ],
"default": "definition"
}
}
Expand Down
3 changes: 3 additions & 0 deletions docs/generator/js.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exemple :
```yaml
fetchPath: "@api-services"
```
### ApiFilePath
Par défaut, les fichiers d'api client sont placés dans le dossier `{module}`. Ils sont nommés d'après le fichier qui les contient, sauf dans le cas du mode `angular`, où le nom du fichier sera de la forme `{fileName}.service.ts`.
Expand All @@ -37,6 +38,8 @@ Il est possible de générer les entités selon deux modes (`entityMode`) : `typ

Le mode `typed` permet de générer la description des entités métier contenant des types. Ces types sont importés par défaut de `@focus4/stores`, mais ce chemin peut être surchargé avec la propriété `entityTypesPath`.

Vous pouvez également activer l'option `extendedCompositions` pour générer toutes les propriétés sur les compositions (`label`, `isRequired`, `comment`), qui ne sont pas générées par défaut.

#### Untyped

Le mode `untyped` permet de générer la description des entités métier en tant que **`const`** non typés.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const UtilisateurItemEntity = {
type: "field",
name: "typeUtilisateurCode",
domain: DO_CODE,
isRequired: true,
defaultValue: "GEST",
isRequired: true,
label: "securite.utilisateur.utilisateur.typeUtilisateurCode"
}
} as const
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export const UtilisateurReadEntity = {
type: "field",
name: "actif",
domain: DO_BOOLEEN,
isRequired: true,
defaultValue: true,
isRequired: true,
label: "securite.utilisateur.utilisateur.actif"
},
profilId: {
Expand All @@ -82,8 +82,8 @@ export const UtilisateurReadEntity = {
type: "field",
name: "typeUtilisateurCode",
domain: DO_CODE,
isRequired: true,
defaultValue: "GEST",
isRequired: true,
label: "securite.utilisateur.utilisateur.typeUtilisateurCode"
},
dateCreation: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export const UtilisateurWriteEntity = {
type: "field",
name: "actif",
domain: DO_BOOLEEN,
isRequired: true,
defaultValue: true,
isRequired: true,
label: "securite.utilisateur.utilisateur.actif"
},
profilId: {
Expand All @@ -72,8 +72,8 @@ export const UtilisateurWriteEntity = {
type: "field",
name: "typeUtilisateurCode",
domain: DO_CODE,
isRequired: true,
defaultValue: "GEST",
isRequired: true,
label: "securite.utilisateur.utilisateur.typeUtilisateurCode"
}
} as const
4 changes: 4 additions & 0 deletions samples/generators/angular/topmodel.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@
"typed"
]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
"description": "Chemin d'import des type d'entités",
Expand Down
4 changes: 4 additions & 0 deletions samples/generators/csharp/topmodel.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@
"typed"
]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
"description": "Chemin d'import des type d'entités",
Expand Down
4 changes: 4 additions & 0 deletions samples/generators/database/topmodel.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@
"typed"
]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
"description": "Chemin d'import des type d'entités",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const UtilisateurItemEntity: UtilisateurItemEntityType = {
type: "field",
name: "typeUtilisateurCode",
domain: DO_CODE,
isRequired: true,
defaultValue: "GEST",
isRequired: true,
label: "securite.utilisateur.utilisateur.typeUtilisateurCode"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const UtilisateurReadEntity: UtilisateurReadEntityType = {
type: "field",
name: "actif",
domain: DO_BOOLEEN,
isRequired: true,
defaultValue: true,
isRequired: true,
label: "securite.utilisateur.utilisateur.actif"
},
profilId: {
Expand All @@ -84,8 +84,8 @@ export const UtilisateurReadEntity: UtilisateurReadEntityType = {
type: "field",
name: "typeUtilisateurCode",
domain: DO_CODE,
isRequired: true,
defaultValue: "GEST",
isRequired: true,
label: "securite.utilisateur.utilisateur.typeUtilisateurCode"
},
dateCreation: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const UtilisateurWriteEntity: UtilisateurWriteEntityType = {
type: "field",
name: "actif",
domain: DO_BOOLEEN,
isRequired: true,
defaultValue: true,
isRequired: true,
label: "securite.utilisateur.utilisateur.actif"
},
profilId: {
Expand All @@ -74,8 +74,8 @@ export const UtilisateurWriteEntity: UtilisateurWriteEntityType = {
type: "field",
name: "typeUtilisateurCode",
domain: DO_CODE,
isRequired: true,
defaultValue: "GEST",
isRequired: true,
label: "securite.utilisateur.utilisateur.typeUtilisateurCode"
}
}
4 changes: 4 additions & 0 deletions samples/generators/focus/topmodel.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@
"typed"
]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
"description": "Chemin d'import des type d'entités",
Expand Down
4 changes: 4 additions & 0 deletions samples/generators/jpa/topmodel.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@
"typed"
]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
"description": "Chemin d'import des type d'entités",
Expand Down
4 changes: 4 additions & 0 deletions samples/generators/open-api/topmodel.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@
"typed"
]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
"description": "Chemin d'import des type d'entités",
Expand Down
4 changes: 4 additions & 0 deletions samples/generators/pg/topmodel.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@
"typed"
]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
"description": "Chemin d'import des type d'entités",
Expand Down
4 changes: 4 additions & 0 deletions samples/generators/php/topmodel.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@
"typed"
]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
"description": "Chemin d'import des type d'entités",
Expand Down
4 changes: 4 additions & 0 deletions samples/generators/ssdt/topmodel.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@
"typed"
]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
"description": "Chemin d'import des type d'entités",
Expand Down
4 changes: 4 additions & 0 deletions samples/generators/translation/topmodel.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@
"typed"
]
},
"extendedCompositions": {
"type": "boolean",
"description": "Génère `isRequired`, `label` (et `comment`) sur les compositions dans les entitées typées."
},
"entityTypesPath": {
"type": "string",
"description": "Chemin d'import des type d'entités",
Expand Down

0 comments on commit 999b8e6

Please sign in to comment.