5htp 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,226 +0,0 @@
1
-
2
- import * as types from '@babel/types'
3
- import generate from "@babel/generator";
4
-
5
- const servicesViaContexte: {
6
- [nomService: string]: string
7
- } = {
8
- User: 'user',
9
-
10
- Request: 'req',
11
- Response: 'res',
12
- NextFunction: 'next'
13
- } as const
14
-
15
- const debug = false
16
-
17
- export default (t: typeof types) => {
18
-
19
- function remplacerFonction(arg: types.ArrowFunctionExpression): null | types.ArrowFunctionExpression;
20
- function remplacerFonction(arg: types.ClassMethod): null | types.ClassMethod;
21
- function remplacerFonction(
22
- arg: types.ArrowFunctionExpression | types.ClassMethod
23
- ): null | types.ArrowFunctionExpression | types.ClassMethod {
24
-
25
- const dejaTraite = (
26
- arg.params.length === 1
27
- &&
28
- arg.params[0].type === 'RestElement'
29
- )
30
- if (dejaTraite)
31
- return null;
32
-
33
- // Return null = inchangé
34
- if (arg.body.type !== 'BlockStatement')
35
- return null;
36
-
37
- let declarations: types.VariableDeclarator[] = [];
38
- let instanciations: types.ExpressionStatement[] = [];
39
- let extractions: types.ExpressionStatement[] = [];
40
-
41
- // Transforme les paramètres en une liste d'instanciations
42
- for (let iParam = 0; iParam < arg.params.length; iParam++) {
43
- const param = arg.params[iParam];
44
-
45
- // utilisateur: User
46
- if (
47
- param.type === 'Identifier' && param.typeAnnotation
48
- &&
49
- param.typeAnnotation.type === 'TSTypeAnnotation'
50
- &&
51
- param.typeAnnotation.typeAnnotation.type === 'TSTypeReference'
52
- &&
53
- param.typeAnnotation.typeAnnotation.typeName.type === 'Identifier'
54
- ) {
55
-
56
- const typeParam = param.typeAnnotation.typeAnnotation.typeName.name;
57
- const nomParam = param.name;
58
-
59
- // Déclaration
60
- declarations.push(
61
- t.variableDeclarator(
62
- t.identifier(nomParam)
63
- )
64
- );
65
-
66
- // Instanciation (quand args[0] = contexte)
67
- if (typeParam in servicesViaContexte) {
68
-
69
- // <nomParam> = args[ 0 ][ servicesViaContexte[ typeParam ] ];
70
- instanciations.push(
71
- t.expressionStatement(
72
- t.assignmentExpression(
73
- '=',
74
- t.identifier(nomParam),
75
- t.memberExpression(
76
- t.memberExpression(
77
- t.identifier('args'),
78
- t.numericLiteral(0),
79
- true
80
- ),
81
- t.identifier(servicesViaContexte[typeParam])
82
- )
83
- )
84
- )
85
- )
86
-
87
- // Le type du paramètre est un service reconnu
88
- } else if (this.servicesImportes[typeParam] !== undefined) {
89
-
90
- // <nomParam> = new <typeParam>( args[0] );
91
- instanciations.push(
92
- t.expressionStatement(
93
- t.assignmentExpression(
94
- '=',
95
- t.identifier(nomParam),
96
- t.newExpression(
97
- t.identifier(typeParam),
98
- [
99
- t.memberExpression(
100
- t.identifier('args'),
101
- t.numericLiteral(0),
102
- true
103
- )
104
- ]
105
- )
106
- )
107
- )
108
- );
109
-
110
- } else {
111
- console.log(this.servicesImportes);
112
- throw new Error(`Impossible de trouver l'import associée au type portant pour nom ${typeParam} (fichier: ${this.fichier}). Liste des iportations trouvées au dessus.`)
113
- }
114
-
115
- // Extractions
116
- // <nomParam> = args[ <index> ]
117
- extractions.push(
118
- t.expressionStatement(
119
- t.assignmentExpression(
120
- '=',
121
- t.identifier(nomParam),
122
- t.memberExpression(
123
- t.identifier('args'),
124
- t.identifier( iParam.toString() ),
125
- true
126
- )
127
- )
128
- )
129
- );
130
-
131
- }
132
- }
133
-
134
- // Inchangé
135
- if (instanciations.length === 0)
136
- return null;
137
-
138
- const conditionSiDoitInstancier = (
139
- t.logicalExpression(
140
- '&&',
141
- t.logicalExpression(
142
- '&&',
143
-
144
- // args[0] !== undefined
145
- t.binaryExpression(
146
- '!==',
147
- t.memberExpression(
148
- t.identifier('args'),
149
- t.numericLiteral(0),
150
- true
151
- ),
152
- t.identifier('undefined')
153
- ),
154
-
155
- // typeof args[0] === 'object'
156
- t.binaryExpression(
157
- '===',
158
- t.unaryExpression(
159
- 'typeof',
160
- t.memberExpression(
161
- t.identifier('args'),
162
- t.identifier('0'),
163
- true
164
- )
165
- ),
166
- t.stringLiteral('object')
167
- )
168
- ),
169
-
170
- // args[0].type === 'contexte_requete'
171
- t.binaryExpression(
172
- '===',
173
- t.memberExpression(
174
- t.memberExpression(
175
- t.identifier('args'),
176
- t.identifier('0'),
177
- true
178
- ),
179
- t.identifier('type')
180
- ),
181
- t.stringLiteral('contexte_requete')
182
- )
183
- )
184
- )
185
-
186
- const body = t.blockStatement([
187
- t.variableDeclaration('let', declarations),
188
-
189
- // if (args[0] !== undefined && typeof args[0] === 'object' && args[0].type === 'contexte_requete')
190
- t.ifStatement(
191
- conditionSiDoitInstancier,
192
-
193
- t.blockStatement(instanciations),
194
-
195
- t.blockStatement(extractions)
196
- ),
197
- ...arg.body.body
198
- ]);
199
-
200
- // Remplacement paramètres et ajout des instanciations
201
- const remplacement = arg.type === 'ArrowFunctionExpression'
202
- ? t.arrowFunctionExpression(
203
- [t.restElement( t.identifier('args') )],
204
- body,
205
- arg.async
206
- )
207
- : t.classMethod(
208
- 'constructor',
209
- t.identifier('constructor'),
210
- [t.restElement( t.identifier('args') )],
211
- body
212
- )
213
-
214
- if (debug) {
215
- console.log('-----------------------------');
216
- console.log(generate(arg).code);
217
- console.log('=>');
218
- console.log(generate(remplacement).code);
219
- console.log('-----------------------------');
220
- }
221
-
222
- return remplacement;
223
- }
224
-
225
- return remplacerFonction;
226
- }
@@ -1,166 +0,0 @@
1
- /*----------------------------------
2
- - DEPENDANCES
3
- ----------------------------------*/
4
-
5
- // Npm
6
- import path from 'path';
7
- import { PluginObj } from '@babel/core';
8
- import * as types from '@babel/types'
9
-
10
- /*----------------------------------
11
- - REGEX
12
- ----------------------------------*/
13
- const cheminClasseQuery = '@serveur/database/jsql/query/runner';
14
-
15
- const regFichierModele = /^[a-z]+\/serveur\/modeles\//i;
16
-
17
- /*----------------------------------
18
- - WEBPACK RULE
19
- ----------------------------------*/
20
- module.exports = {// /serveur/**.ts */
21
- test: /\/serveur\/(.*)\.(ts)$/i,
22
- plugins: [
23
- [Plugin]
24
- ]
25
- }
26
-
27
-
28
- /*----------------------------------
29
- - PLUGIN
30
- ----------------------------------*/
31
- function Plugin (babel) {
32
-
33
- const t = babel.types as typeof types;
34
-
35
- const plugin: PluginObj<{
36
- fichier: string,
37
- dossier: string
38
- }> = {
39
- pre(state) {
40
-
41
- const { filename, root } = state.opts;
42
-
43
- if (!filename)
44
- throw new Error(`Impossible d'obtenir le chemin du fichier actuellement rraité par le plugin`);
45
-
46
- if (!root)
47
- throw new Error(`Impossible d'obtenir le chemin de la racine du projet`);
48
-
49
- this.fichier = filename;
50
-
51
- const prefixeRoot = root;
52
- this.dossier = path.dirname(filename).substring(prefixeRoot.length)
53
- },
54
- visitor: {
55
- ImportDeclaration(instruction) {
56
-
57
- if (!(
58
- instruction.node.specifiers.length === 1
59
- &&
60
- instruction.node.specifiers[0].type === 'ImportDefaultSpecifier'
61
- ))
62
- return;
63
-
64
- const cheminImportFichier = instruction.node.source.value;
65
- const importDefault = instruction.node.specifiers[0];
66
-
67
- /* Recherche de:
68
- import PublicScope from './Public/index.sql';
69
- */
70
- if (
71
- // Suffise SQL = déjà traité, ou intention de garder le SQL
72
- !importDefault.local.name.endsWith('SQL')
73
- &&
74
- cheminImportFichier.endsWith('.sql')
75
- ) {
76
-
77
- // Extraction des infos
78
- const nomVarScope = importDefault.local.name;
79
- const nomImportSql = nomVarScope + 'SQL';
80
- const cheminCompletImport = path.join(this.dossier, cheminImportFichier);
81
-
82
- // Génère un ID unique basé sur le chemin
83
- let cheminScope: string = cheminCompletImport;
84
- const isModelScope = regFichierModele.test(cheminCompletImport);
85
- if (isModelScope) {
86
- // Mission.Public
87
- const nomModele = path.basename(this.dossier);
88
- cheminScope = nomModele + '.' + cheminCompletImport.substring(
89
- this.dossier.length + 1, // +1 pour le dernier slash
90
- )
91
- }
92
-
93
- cheminScope = cheminScope
94
- .substring(0, cheminScope.length - 4) // Vire l'extension .sql
95
- .replace(/\//g, '.');
96
-
97
- if (cheminScope.endsWith('.index'))
98
- cheminScope = cheminScope.substring(0, cheminScope.length - 6)
99
-
100
- // Renommage de l'import du sql et instanciaiton de la query
101
- // NOTE: On ne skip pas, puisque les imports ont été suffixés de SQL
102
- //instruction.skip();
103
- let remplacement = []
104
-
105
- /* Création factory */
106
- remplacement.push(
107
-
108
- // + import PublicScopeSql from './Public/index.sql';
109
- t.importDeclaration(
110
- [t.importDefaultSpecifier(t.identifier(nomImportSql))],
111
- t.stringLiteral(cheminImportFichier)
112
- ),
113
-
114
- // + const PublicScope = new String( PublicScopeSql );
115
- t.variableDeclaration('const', [
116
- t.variableDeclarator(
117
- t.identifier(nomVarScope),
118
- t.newExpression(
119
- t.identifier('String'),
120
- [t.identifier(nomImportSql)]
121
- )
122
- )
123
- ]),
124
-
125
- // + PublicScope.id = 'earn/missions/Mission/Public/index';
126
- t.expressionStatement(
127
- t.assignmentExpression(
128
- '=',
129
- t.memberExpression(
130
- t.identifier( nomVarScope ),
131
- t.identifier('id')
132
- ),
133
- t.stringLiteral(cheminScope)
134
- )
135
- ),
136
-
137
- // + PublicScope.sourceFile = 'earn/missions/Mission/Public/index.sql'
138
- t.expressionStatement(
139
- t.assignmentExpression(
140
- '=',
141
- t.memberExpression(
142
- t.identifier( nomVarScope ),
143
- t.identifier('sourceFile')
144
- ),
145
- t.stringLiteral(cheminCompletImport)
146
- )
147
- ),
148
- )
149
-
150
- /*console.log(`[babel][plugin][queries]`,
151
- this.fichier, cheminCompletImport, '\n',
152
- recast.print( t.program(remplacement) ).code,
153
- cheminScope
154
- );*/
155
-
156
- // Remplacement
157
- instruction.replaceWithMultiple(remplacement);
158
-
159
- }
160
-
161
- }
162
- }
163
- };
164
-
165
- return plugin;
166
- }
@@ -1,72 +0,0 @@
1
- const placeholder: string = '____PLACEHOLDER____';
2
- const balises = {
3
- fonction: '[fonction]',
4
- methode: '[methode]'
5
- }
6
-
7
- const regRemplacements = new RegExp('("([^"]+)": )?"' + placeholder + '"', 'g');
8
-
9
- // Permet de transformer un objet en chaine json sans niquer les fonctions
10
- export default ( obj: object, fonctions: string[] = [] ): string => {
11
-
12
- var fns: [string, string][] = [];
13
-
14
- // Remplace les fonctions par un placeholder et tranforme en json
15
- var json = JSON.stringify(obj, (key: string, value: any): string => {
16
-
17
- const func: boolean = typeof value === 'function';
18
- const ref_fonction: boolean = typeof value === 'string' && value.startsWith( balises.fonction );
19
- const ref_methode: boolean = typeof value === 'string' && value.startsWith( balises.methode );
20
-
21
- if (fonctions.includes(key) || func || ref_fonction || ref_methode) {
22
-
23
- if (func)
24
- value = value.toString();
25
- else if (ref_fonction)
26
- value = value.substring( balises.fonction.length );
27
- else if (ref_methode)
28
- value = value.substring( balises.methode.length );
29
-
30
- fns.push([ value, ref_methode ? 'methode' : 'fonction' ]);
31
-
32
- return placeholder;
33
- }
34
-
35
- return value;
36
- }, 4);
37
-
38
- // Remplace les placeholders par la fonction brute sans les guillemets
39
- json = json.replace(regRemplacements, (match: string, contnom: string, nom: string): string => {
40
- const func = fns.shift();
41
- if (Array.isArray(func)) {
42
-
43
- const [ fonction, type ] = func;
44
-
45
- // La fonction est dans un tableau
46
- if (nom === undefined)
47
- return fonction;
48
- else
49
- return type === 'methode'
50
- // nom() { ... }
51
- ? nom + fonction
52
- // "nom": () => { ... }
53
- : '"'+ nom +'": ' + fonction;
54
-
55
- return fonction ? fonction : '';
56
-
57
- } else
58
- return '';
59
- });
60
-
61
- // retire les quotes
62
- json = json.replace(/\"([a-zA-Z]+)\"\:/gm, '$1:');
63
-
64
- // Correction pour les méthodes de classe
65
- // Remplace <nom>: <args> => { par <nom><args> {
66
- json = json.replace(
67
- /([a-zA-Z]+)\:\s*(\([a-zA-Z\,\s]*\))\s*\=\>\s*\{/gmi,
68
- '$1$2 {'
69
- );
70
-
71
- return json;
72
- };
@@ -1,88 +0,0 @@
1
- /*----------------------------------
2
- - DEPENDANCES
3
- ----------------------------------*/
4
- import fs from 'fs-extra';
5
-
6
- /*----------------------------------
7
- - TYPE
8
- ----------------------------------*/
9
- type TDonnees = {[cle: string]: string | number};
10
-
11
- /*----------------------------------
12
- - FONCTION
13
- ----------------------------------*/
14
- export default function lireAnnotations<TRetour = TDonnees>( fichier: string ): TRetour | undefined {
15
-
16
- let annotations: TRetour = {} as TRetour;
17
- let lectureAnnotations: boolean = false;
18
-
19
- // Lecture de chaque ligne
20
- const lignes = fs.readFileSync(fichier, 'utf-8').split('\n');
21
- for (let ligne of lignes) {
22
-
23
- // Debut des annotations
24
- if (ligne === "/* ~~~~~~~~~~~~~~~~") {
25
-
26
- lectureAnnotations = true;
27
-
28
- // Fin des anotations
29
- } else if (ligne === "~~~~~~~~~~~~~~~~ */") {
30
-
31
- return annotations;
32
-
33
- // Lecture des annotations
34
- } else if (lectureAnnotations) {
35
-
36
- // Retire le "* " au debut de la ligne
37
- ligne = ligne.substring(2).trim();
38
- // Ligne vide
39
- if (ligne.length === 0)
40
- continue;
41
-
42
- // Niveau indentation
43
- //const indentation = ligne.match(/^( )*/)
44
- //const indentLevel = indentation === null ? 0 : indentation[0].length;
45
-
46
- // cle: valeur
47
- if (ligne.includes(': ')) {
48
-
49
- // Décomposition clé / valeur
50
- let [cle, valeur] = ligne.split(': ') as [string, any];
51
- cle = cle.trim().toLowerCase();
52
-
53
- // retire le commentaire
54
- const poscommentaire = valeur.indexOf(' //')
55
- if (poscommentaire !== -1)
56
- valeur = valeur.substring(0, poscommentaire);
57
- valeur = valeur.trim();
58
-
59
- // Met en minuscules
60
- if (cle) {
61
-
62
- // Correction type valeur
63
- if (valeur === 'true')
64
- valeur = true;
65
- else if (valeur === 'false')
66
- valeur = false;
67
- else if (!isNaN(Number(valeur)))
68
- valeur = parseFloat(valeur);
69
-
70
- // Référencement
71
- if (annotations[cle] === undefined)
72
- annotations[cle] = valeur;
73
- // Valeur déjà existante, regroupement dans un tableau
74
- else if (!Array.isArray(annotations[cle]))
75
- annotations[cle] = [annotations[cle], valeur];
76
- // Déjà en tableau, ajout élement
77
- else
78
- annotations[cle] = [...annotations[cle], valeur];
79
-
80
- }
81
-
82
- }
83
- }
84
-
85
- }
86
-
87
- return undefined;
88
- }
@@ -1,52 +0,0 @@
1
- const path = require('path')
2
- const fs = require('fs')
3
-
4
- export default function iterateur(
5
- dir: string,
6
- func: (fichier: string, ext: string, cheminRelatif: string, dossier: string) => void,
7
- extensions: string[] = [],
8
- blacklist: string[] = [],
9
- func_sinon?: (fichier: string) => void,
10
- dir_root?: string
11
- ) {
12
-
13
- if (dir_root === undefined)
14
- dir_root = dir;
15
-
16
- // Lecture du contenu du dossier
17
- const elements = fs.readdirSync(dir);
18
- for (const file of elements) {
19
-
20
- const file_relatif = dir + '/' + file;
21
-
22
- // Pas dans la blacklist
23
- if ((!blacklist || !blacklist.includes( file ))) {
24
-
25
- // Récup chemin complet
26
- const file_complet = path.resolve(dir, file);
27
-
28
- // Extension sans le point
29
- const ext = path.extname( file ).substring(1);
30
-
31
- // Recup infos element
32
- const stat = fs.statSync(file_complet);
33
-
34
- // Dossier = recursion
35
- if (stat && stat.isDirectory())
36
-
37
- iterateur( file_relatif, func, extensions, blacklist, func_sinon, dir_root );
38
-
39
- else if (extensions.includes( ext )) {
40
-
41
- let chemin = file_relatif.substring(dir_root.length + 1, file_relatif.length - ext.length - 1)
42
- if (chemin.endsWith('/index'))
43
- chemin = chemin.substring(0, chemin.length - 6);
44
-
45
- func( file_relatif, ext, chemin, dir );
46
-
47
- }
48
-
49
- } else if (func_sinon)
50
- func_sinon( file_relatif );
51
- };
52
- }