@valkyrjaio/sindri 26.0.1
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.
- package/LICENSE.md +21 -0
- package/README.md +111 -0
- package/package.json +63 -0
- package/src/Sindri/Ast/Abstract/AstReader.ts +710 -0
- package/src/Sindri/Ast/Abstract/RouteAttributeReader.ts +50 -0
- package/src/Sindri/Ast/CliRouteAttributeReader.ts +219 -0
- package/src/Sindri/Ast/CliRouteParameterReader.ts +204 -0
- package/src/Sindri/Ast/ComponentProviderReader.ts +41 -0
- package/src/Sindri/Ast/ConfigReader.ts +213 -0
- package/src/Sindri/Ast/Contract/CliRouteAttributeReaderContract.ts +14 -0
- package/src/Sindri/Ast/Contract/CliRouteParameterReaderContract.ts +34 -0
- package/src/Sindri/Ast/Contract/ComponentProviderReaderContract.ts +14 -0
- package/src/Sindri/Ast/Contract/ConfigReaderContract.ts +14 -0
- package/src/Sindri/Ast/Contract/HttpRouteAttributeReaderContract.ts +14 -0
- package/src/Sindri/Ast/Contract/HttpRouteMiddlewareReaderContract.ts +61 -0
- package/src/Sindri/Ast/Contract/HttpRouteParameterReaderContract.ts +26 -0
- package/src/Sindri/Ast/Contract/ListenerAttributeReaderContract.ts +14 -0
- package/src/Sindri/Ast/Contract/ListenerProviderReaderContract.ts +14 -0
- package/src/Sindri/Ast/Contract/RouteProviderReaderContract.ts +14 -0
- package/src/Sindri/Ast/Contract/ServiceProviderReaderContract.ts +14 -0
- package/src/Sindri/Ast/Data/CliArgumentParameterData.ts +20 -0
- package/src/Sindri/Ast/Data/CliOptionParameterData.ts +24 -0
- package/src/Sindri/Ast/Data/CliRouteData.ts +32 -0
- package/src/Sindri/Ast/Data/ConfigData.ts +20 -0
- package/src/Sindri/Ast/Data/Contract/CliArgumentParameterDataContract.ts +18 -0
- package/src/Sindri/Ast/Data/Contract/CliOptionParameterDataContract.ts +22 -0
- package/src/Sindri/Ast/Data/Contract/CliRouteDataContract.ts +25 -0
- package/src/Sindri/Ast/Data/Contract/ConfigDataContract.ts +16 -0
- package/src/Sindri/Ast/Data/Contract/HandlerDataContract.ts +13 -0
- package/src/Sindri/Ast/Data/Contract/HttpParameterDataContract.ts +17 -0
- package/src/Sindri/Ast/Data/Contract/HttpRouteDataContract.ts +28 -0
- package/src/Sindri/Ast/Data/Contract/ListenerDataContract.ts +16 -0
- package/src/Sindri/Ast/Data/HandlerData.ts +20 -0
- package/src/Sindri/Ast/Data/HttpParameterData.ts +20 -0
- package/src/Sindri/Ast/Data/HttpRouteData.ts +30 -0
- package/src/Sindri/Ast/Data/ListenerData.ts +19 -0
- package/src/Sindri/Ast/Data/Result/CliRouteAttributeResult.ts +14 -0
- package/src/Sindri/Ast/Data/Result/ComponentProviderResult.ts +28 -0
- package/src/Sindri/Ast/Data/Result/ConfigResult.ts +18 -0
- package/src/Sindri/Ast/Data/Result/HttpRouteAttributeResult.ts +19 -0
- package/src/Sindri/Ast/Data/Result/ListenerAttributeResult.ts +14 -0
- package/src/Sindri/Ast/Data/Result/ListenerProviderResult.ts +24 -0
- package/src/Sindri/Ast/Data/Result/RouteProviderResult.ts +24 -0
- package/src/Sindri/Ast/Data/Result/ServiceProviderResult.ts +22 -0
- package/src/Sindri/Ast/HttpRouteAttributeReader.ts +315 -0
- package/src/Sindri/Ast/HttpRouteMiddlewareReader.ts +214 -0
- package/src/Sindri/Ast/HttpRouteParameterReader.ts +193 -0
- package/src/Sindri/Ast/ListenerAttributeReader.ts +131 -0
- package/src/Sindri/Ast/ListenerProviderReader.ts +45 -0
- package/src/Sindri/Ast/RouteProviderReader.ts +45 -0
- package/src/Sindri/Ast/ServiceProviderReader.ts +124 -0
- package/src/Sindri/Ast/Throwable/Contract/AstThrowable.ts +12 -0
- package/src/Sindri/Ast/Throwable/Exception/Abstract/AstInvalidArgumentException.ts +14 -0
- package/src/Sindri/Ast/Throwable/Exception/Abstract/AstRuntimeException.ts +14 -0
- package/src/Sindri/Ast/Throwable/Exception/AstFileReadException.ts +12 -0
- package/src/Sindri/Cli/Command/GenerateDataFromConfigCommand.ts +83 -0
- package/src/Sindri/Constant/CommandName.ts +12 -0
- package/src/Sindri/Constant/SindriInfo.ts +20 -0
- package/src/Sindri/Constant/SindriServiceId.ts +32 -0
- package/src/Sindri/Generate/Abstract/GenerateDataFromAst.ts +391 -0
- package/src/Sindri/Generator/Abstract/AstFileGenerator.ts +54 -0
- package/src/Sindri/Generator/Abstract/FileGenerator.ts +59 -0
- package/src/Sindri/Generator/Ast/Cli/AstCliDataFileGenerator.ts +88 -0
- package/src/Sindri/Generator/Ast/Container/AstContainerDataFileGenerator.ts +86 -0
- package/src/Sindri/Generator/Ast/Event/AstEventDataFileGenerator.ts +79 -0
- package/src/Sindri/Generator/Ast/Http/AstHttpDataFileGenerator.ts +306 -0
- package/src/Sindri/Generator/Cli/Contract/CliDataFileGeneratorContract.ts +23 -0
- package/src/Sindri/Generator/Container/Contract/ContainerDataFileGeneratorContract.ts +21 -0
- package/src/Sindri/Generator/Contract/FileGeneratorContract.ts +15 -0
- package/src/Sindri/Generator/Enum/GenerateStatus.ts +14 -0
- package/src/Sindri/Generator/Event/Contract/EventDataFileGeneratorContract.ts +23 -0
- package/src/Sindri/Generator/Http/Contract/HttpDataFileGeneratorContract.ts +25 -0
- package/src/Sindri/Generator/Throwable/Contract/GeneratorThrowable.ts +12 -0
- package/src/Sindri/Generator/Throwable/Exception/Abstract/GeneratorInvalidArgumentException.ts +16 -0
- package/src/Sindri/Generator/Throwable/Exception/Abstract/GeneratorRuntimeException.ts +14 -0
- package/src/Sindri/Generator/Throwable/Exception/GeneratorUnreachableException.ts +12 -0
- package/src/Sindri/Provider/SindriAstServiceProvider.ts +182 -0
- package/src/Sindri/Provider/SindriCliRouteProvider.ts +32 -0
- package/src/Sindri/Provider/SindriCommandServiceProvider.ts +71 -0
- package/src/Sindri/Provider/SindriComponentProvider.ts +41 -0
- package/src/Sindri/Throwable/Contract/SindriThrowable.ts +12 -0
- package/src/Sindri/Throwable/Exception/Abstract/SindriInvalidArgumentException.ts +16 -0
- package/src/Sindri/Throwable/Exception/Abstract/SindriRuntimeException.ts +14 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
|
|
12
|
+
import { ts } from 'ts-morph';
|
|
13
|
+
|
|
14
|
+
import { AstReader } from './Abstract/AstReader.ts';
|
|
15
|
+
import { ConfigResult } from './Data/Result/ConfigResult.ts';
|
|
16
|
+
|
|
17
|
+
import type { ClassDeclaration } from 'ts-morph';
|
|
18
|
+
|
|
19
|
+
import type { ConfigReaderContract } from './Contract/ConfigReaderContract.ts';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Reads an application config class file via AST and extracts the values
|
|
23
|
+
* needed by GenerateDataFromAst without executing the TypeScript file.
|
|
24
|
+
*
|
|
25
|
+
* Expects a class with a constructor that calls super() with positional or
|
|
26
|
+
* named arguments: (namespace, dir, ..., dataPath, dataNamespace, providers).
|
|
27
|
+
* __dirname / import.meta.dirname in the dir argument is resolved relative to
|
|
28
|
+
* the config file path.
|
|
29
|
+
*/
|
|
30
|
+
export class ConfigReader extends AstReader implements ConfigReaderContract {
|
|
31
|
+
readFile(filePath: string): ConfigResult {
|
|
32
|
+
const context = this.parseClassFile(filePath);
|
|
33
|
+
|
|
34
|
+
if (context === undefined) {
|
|
35
|
+
return new ConfigResult();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const { classDecl, useMap } = context;
|
|
39
|
+
const args = this.findSuperConstructorArgs(classDecl);
|
|
40
|
+
|
|
41
|
+
if (args === undefined) {
|
|
42
|
+
return new ConfigResult();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return this.buildConfigResult(args, filePath, useMap);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Locate the constructor and extract its super() call arguments.
|
|
50
|
+
*/
|
|
51
|
+
protected findSuperConstructorArgs(classDecl: ClassDeclaration): ts.NodeArray<ts.Expression> | undefined {
|
|
52
|
+
const constructor = classDecl.getConstructors()[0];
|
|
53
|
+
|
|
54
|
+
if (constructor === undefined) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const body = constructor.compilerNode.body;
|
|
59
|
+
|
|
60
|
+
if (body === undefined) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (const stmt of body.statements) {
|
|
65
|
+
if (ts.isExpressionStatement(stmt) && ts.isCallExpression(stmt.expression)) {
|
|
66
|
+
const call = stmt.expression;
|
|
67
|
+
|
|
68
|
+
if (ts.isIdentifier(call.expression) && call.expression.text === 'super') {
|
|
69
|
+
return call.arguments;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Build a ConfigResult from the extracted super() argument list.
|
|
79
|
+
*
|
|
80
|
+
* The TS Config base class constructor signature (CliConfig):
|
|
81
|
+
* (namespace, dir, version, env, debug, timezone, secret, dataPath, dataNamespace, ...)
|
|
82
|
+
*
|
|
83
|
+
* Positional args:
|
|
84
|
+
* 0: namespace (string)
|
|
85
|
+
* 1: dir (string — may use process.cwd() or __dirname)
|
|
86
|
+
* 2: version (string)
|
|
87
|
+
* 3: env (string)
|
|
88
|
+
* 4: debug (bool)
|
|
89
|
+
* 5: timezone (string)
|
|
90
|
+
* 6: secret (string)
|
|
91
|
+
* 7: dataPath (string — relative path)
|
|
92
|
+
* 8: dataNamespace (string)
|
|
93
|
+
* 9+: other args, then providers array
|
|
94
|
+
*/
|
|
95
|
+
protected buildConfigResult(
|
|
96
|
+
args: ts.NodeArray<ts.Expression>,
|
|
97
|
+
filePath: string,
|
|
98
|
+
useMap: Record<string, string>,
|
|
99
|
+
): ConfigResult {
|
|
100
|
+
const fileDir = path.dirname(filePath);
|
|
101
|
+
|
|
102
|
+
const namespace = this.extractStringFromArg(args[0]);
|
|
103
|
+
const dir = this.resolvePathFromArg(args[1], fileDir);
|
|
104
|
+
const dataPath = this.resolveDataPathFromArgs(args, fileDir);
|
|
105
|
+
const dataNamespace = this.extractStringFromArg(args[8]);
|
|
106
|
+
const providers = this.extractProvidersFromArgs(args, useMap, filePath);
|
|
107
|
+
|
|
108
|
+
if (namespace === '' || dir === '' || dataPath === '' || dataNamespace === '') {
|
|
109
|
+
return new ConfigResult();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return new ConfigResult(namespace, dir, dataPath, dataNamespace, providers);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
protected extractStringFromArg(arg: ts.Expression | undefined): string {
|
|
116
|
+
if (arg === undefined) {
|
|
117
|
+
return '';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (ts.isStringLiteral(arg)) {
|
|
121
|
+
return arg.text;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return '';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
protected resolvePathFromArg(arg: ts.Expression | undefined, fileDir: string): string {
|
|
128
|
+
if (arg === undefined) {
|
|
129
|
+
return '';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (ts.isStringLiteral(arg)) {
|
|
133
|
+
return arg.text;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// process.cwd() → use the file directory as a proxy
|
|
137
|
+
if (ts.isCallExpression(arg) && ts.isPropertyAccessExpression(arg.expression)) {
|
|
138
|
+
const obj = arg.expression.expression;
|
|
139
|
+
const prop = arg.expression.name;
|
|
140
|
+
|
|
141
|
+
if (ts.isIdentifier(obj) && obj.text === 'process' && ts.isIdentifier(prop) && prop.text === 'cwd') {
|
|
142
|
+
return fileDir;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// __dirname or import.meta.dirname
|
|
147
|
+
if (ts.isIdentifier(arg) && arg.text === '__dirname') {
|
|
148
|
+
return fileDir;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (
|
|
152
|
+
ts.isPropertyAccessExpression(arg) &&
|
|
153
|
+
ts.isPropertyAccessExpression(arg.expression) &&
|
|
154
|
+
ts.isMetaProperty(arg.expression.expression) &&
|
|
155
|
+
arg.expression.expression.name.text === 'meta'
|
|
156
|
+
) {
|
|
157
|
+
return fileDir;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return '';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Resolve the data path from args, prepending the app root when relative.
|
|
165
|
+
* Args[7] is dataPath in CliConfig.
|
|
166
|
+
*/
|
|
167
|
+
protected resolveDataPathFromArgs(args: ts.NodeArray<ts.Expression>, fileDir: string): string {
|
|
168
|
+
const dataPathArg = args[7];
|
|
169
|
+
|
|
170
|
+
if (dataPathArg === undefined) {
|
|
171
|
+
return '';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const dataPath = this.extractStringFromArg(dataPathArg);
|
|
175
|
+
|
|
176
|
+
if (dataPath === '') {
|
|
177
|
+
return '';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (!dataPath.startsWith('/')) {
|
|
181
|
+
const dirArg = args[1];
|
|
182
|
+
const appRoot = this.resolvePathFromArg(dirArg, fileDir);
|
|
183
|
+
|
|
184
|
+
if (appRoot !== '') {
|
|
185
|
+
return appRoot.replace(/\/$/, '') + '/' + dataPath;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return dataPath;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Extract provider class names from the providers argument.
|
|
194
|
+
* In CliConfig, providers is typically the 12th positional arg (index 11).
|
|
195
|
+
*/
|
|
196
|
+
protected extractProvidersFromArgs(
|
|
197
|
+
args: ts.NodeArray<ts.Expression>,
|
|
198
|
+
useMap: Record<string, string>,
|
|
199
|
+
filePath: string,
|
|
200
|
+
): string[] {
|
|
201
|
+
// Try to find the providers array in the argument list
|
|
202
|
+
// It's typically at index 11 in CliConfig
|
|
203
|
+
for (let i = 10; i < args.length; i++) {
|
|
204
|
+
const arg = args[i];
|
|
205
|
+
|
|
206
|
+
if (arg !== undefined && ts.isArrayLiteralExpression(arg)) {
|
|
207
|
+
return this.extractClassListFromArrayExpr(arg, useMap, filePath);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { CliRouteAttributeResult } from '../Data/Result/CliRouteAttributeResult.ts';
|
|
11
|
+
|
|
12
|
+
export interface CliRouteAttributeReaderContract {
|
|
13
|
+
readFile(filePath: string): CliRouteAttributeResult;
|
|
14
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ts } from 'ts-morph';
|
|
11
|
+
|
|
12
|
+
import type { MethodDeclaration } from 'ts-morph';
|
|
13
|
+
|
|
14
|
+
import type { CliArgumentParameterData } from '../Data/CliArgumentParameterData.ts';
|
|
15
|
+
import type { CliOptionParameterData } from '../Data/CliOptionParameterData.ts';
|
|
16
|
+
import type { CliRouteData } from '../Data/CliRouteData.ts';
|
|
17
|
+
|
|
18
|
+
export interface CliRouteParameterReaderContract {
|
|
19
|
+
buildParameterArgs(data: CliRouteData): ts.Expression[];
|
|
20
|
+
|
|
21
|
+
updateArguments(
|
|
22
|
+
method: MethodDeclaration,
|
|
23
|
+
useMap: Record<string, string>,
|
|
24
|
+
namespace: string,
|
|
25
|
+
currentClass: string,
|
|
26
|
+
): CliArgumentParameterData[];
|
|
27
|
+
|
|
28
|
+
updateOptions(
|
|
29
|
+
method: MethodDeclaration,
|
|
30
|
+
useMap: Record<string, string>,
|
|
31
|
+
namespace: string,
|
|
32
|
+
currentClass: string,
|
|
33
|
+
): CliOptionParameterData[];
|
|
34
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ComponentProviderResult } from '../Data/Result/ComponentProviderResult.ts';
|
|
11
|
+
|
|
12
|
+
export interface ComponentProviderReaderContract {
|
|
13
|
+
readFile(filePath: string): ComponentProviderResult;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ConfigResult } from '../Data/Result/ConfigResult.ts';
|
|
11
|
+
|
|
12
|
+
export interface ConfigReaderContract {
|
|
13
|
+
readFile(filePath: string): ConfigResult;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { HttpRouteAttributeResult } from '../Data/Result/HttpRouteAttributeResult.ts';
|
|
11
|
+
|
|
12
|
+
export interface HttpRouteAttributeReaderContract {
|
|
13
|
+
readFile(filePath: string): HttpRouteAttributeResult;
|
|
14
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ts } from 'ts-morph';
|
|
11
|
+
|
|
12
|
+
import type { MethodDeclaration } from 'ts-morph';
|
|
13
|
+
|
|
14
|
+
import type { HttpRouteData } from '../Data/HttpRouteData.ts';
|
|
15
|
+
|
|
16
|
+
export interface HttpRouteMiddlewareReaderContract {
|
|
17
|
+
extractInlineRequestMethods(
|
|
18
|
+
decoratorArgs: ts.NodeArray<ts.Expression> | ts.Expression[],
|
|
19
|
+
useMap: Record<string, string>,
|
|
20
|
+
namespace: string,
|
|
21
|
+
currentClass: string,
|
|
22
|
+
): string[];
|
|
23
|
+
|
|
24
|
+
updateRequestMethods(
|
|
25
|
+
requestMethods: string[],
|
|
26
|
+
method: MethodDeclaration,
|
|
27
|
+
useMap: Record<string, string>,
|
|
28
|
+
namespace: string,
|
|
29
|
+
currentClass: string,
|
|
30
|
+
): string[];
|
|
31
|
+
|
|
32
|
+
updateMiddleware(
|
|
33
|
+
method: MethodDeclaration,
|
|
34
|
+
useMap: Record<string, string>,
|
|
35
|
+
namespace: string,
|
|
36
|
+
currentClass: string,
|
|
37
|
+
routeMatchedMiddleware: string[],
|
|
38
|
+
routeDispatchedMiddleware: string[],
|
|
39
|
+
throwableCaughtMiddleware: string[],
|
|
40
|
+
sendingResponseMiddleware: string[],
|
|
41
|
+
terminatedMiddleware: string[],
|
|
42
|
+
): [string[], string[], string[], string[], string[]];
|
|
43
|
+
|
|
44
|
+
updateRequestStruct(
|
|
45
|
+
method: MethodDeclaration,
|
|
46
|
+
useMap: Record<string, string>,
|
|
47
|
+
namespace: string,
|
|
48
|
+
currentClass: string,
|
|
49
|
+
): string | null;
|
|
50
|
+
|
|
51
|
+
updateResponseStruct(
|
|
52
|
+
method: MethodDeclaration,
|
|
53
|
+
useMap: Record<string, string>,
|
|
54
|
+
namespace: string,
|
|
55
|
+
currentClass: string,
|
|
56
|
+
): string | null;
|
|
57
|
+
|
|
58
|
+
buildRouteMiddlewareArgs(data: HttpRouteData): ts.Expression[];
|
|
59
|
+
|
|
60
|
+
buildRouteStructArgs(data: HttpRouteData): ts.Expression[];
|
|
61
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ts } from 'ts-morph';
|
|
11
|
+
|
|
12
|
+
import type { MethodDeclaration } from 'ts-morph';
|
|
13
|
+
|
|
14
|
+
import type { HttpParameterData } from '../Data/HttpParameterData.ts';
|
|
15
|
+
|
|
16
|
+
export interface HttpRouteParameterReaderContract {
|
|
17
|
+
updateParameters(
|
|
18
|
+
decoratorArgs: ts.NodeArray<ts.Expression> | ts.Expression[],
|
|
19
|
+
method: MethodDeclaration,
|
|
20
|
+
useMap: Record<string, string>,
|
|
21
|
+
namespace: string,
|
|
22
|
+
currentClass: string,
|
|
23
|
+
): HttpParameterData[];
|
|
24
|
+
|
|
25
|
+
buildParameterListExpr(parameters: HttpParameterData[]): ts.ArrayLiteralExpression;
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ListenerAttributeResult } from '../Data/Result/ListenerAttributeResult.ts';
|
|
11
|
+
|
|
12
|
+
export interface ListenerAttributeReaderContract {
|
|
13
|
+
readFile(filePath: string): ListenerAttributeResult;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ListenerProviderResult } from '../Data/Result/ListenerProviderResult.ts';
|
|
11
|
+
|
|
12
|
+
export interface ListenerProviderReaderContract {
|
|
13
|
+
readFile(filePath: string): ListenerProviderResult;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { RouteProviderResult } from '../Data/Result/RouteProviderResult.ts';
|
|
11
|
+
|
|
12
|
+
export interface RouteProviderReaderContract {
|
|
13
|
+
readFile(filePath: string): RouteProviderResult;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ServiceProviderResult } from '../Data/Result/ServiceProviderResult.ts';
|
|
11
|
+
|
|
12
|
+
export interface ServiceProviderReaderContract {
|
|
13
|
+
readFile(filePath: string): ServiceProviderResult;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { CliArgumentParameterDataContract } from './Contract/CliArgumentParameterDataContract.ts';
|
|
11
|
+
|
|
12
|
+
export class CliArgumentParameterData implements CliArgumentParameterDataContract {
|
|
13
|
+
constructor(
|
|
14
|
+
readonly name: string,
|
|
15
|
+
readonly description: string,
|
|
16
|
+
readonly cast: string | null = null,
|
|
17
|
+
readonly mode: string = 'Valkyrja\\Cli\\Routing\\Enum\\ArgumentMode::OPTIONAL',
|
|
18
|
+
readonly valueMode: string = 'Valkyrja\\Cli\\Routing\\Enum\\ArgumentValueMode::DEFAULT',
|
|
19
|
+
) {}
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { CliOptionParameterDataContract } from './Contract/CliOptionParameterDataContract.ts';
|
|
11
|
+
|
|
12
|
+
export class CliOptionParameterData implements CliOptionParameterDataContract {
|
|
13
|
+
constructor(
|
|
14
|
+
readonly name: string,
|
|
15
|
+
readonly description: string,
|
|
16
|
+
readonly valueDisplayName: string = '',
|
|
17
|
+
readonly cast: string | null = null,
|
|
18
|
+
readonly defaultValue: string = '',
|
|
19
|
+
readonly shortNames: readonly string[] = [],
|
|
20
|
+
readonly validValues: readonly string[] = [],
|
|
21
|
+
readonly mode: string = 'Valkyrja\\Cli\\Routing\\Enum\\OptionMode::OPTIONAL',
|
|
22
|
+
readonly valueMode: string = 'Valkyrja\\Cli\\Routing\\Enum\\OptionValueMode::DEFAULT',
|
|
23
|
+
) {}
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { CliArgumentParameterData } from './CliArgumentParameterData.ts';
|
|
11
|
+
import type { CliOptionParameterData } from './CliOptionParameterData.ts';
|
|
12
|
+
import type { CliRouteDataContract } from './Contract/CliRouteDataContract.ts';
|
|
13
|
+
import type { HandlerData } from './HandlerData.ts';
|
|
14
|
+
|
|
15
|
+
export class CliRouteData implements CliRouteDataContract {
|
|
16
|
+
readonly arguments: readonly CliArgumentParameterData[];
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
readonly name: string,
|
|
20
|
+
readonly description: string,
|
|
21
|
+
readonly handler: HandlerData | null = null,
|
|
22
|
+
readonly helpText: HandlerData | null = null,
|
|
23
|
+
readonly routeMatchedMiddleware: readonly string[] = [],
|
|
24
|
+
readonly routeDispatchedMiddleware: readonly string[] = [],
|
|
25
|
+
readonly throwableCaughtMiddleware: readonly string[] = [],
|
|
26
|
+
readonly exitedMiddleware: readonly string[] = [],
|
|
27
|
+
args: readonly CliArgumentParameterData[] = [],
|
|
28
|
+
readonly options: readonly CliOptionParameterData[] = [],
|
|
29
|
+
) {
|
|
30
|
+
this.arguments = args;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ConfigDataContract } from './Contract/ConfigDataContract.ts';
|
|
11
|
+
|
|
12
|
+
export class ConfigData implements ConfigDataContract {
|
|
13
|
+
constructor(
|
|
14
|
+
readonly namespace: string,
|
|
15
|
+
readonly dir: string,
|
|
16
|
+
readonly dataPath: string,
|
|
17
|
+
readonly dataNamespace: string,
|
|
18
|
+
readonly providers: readonly string[] = [],
|
|
19
|
+
) {}
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface CliArgumentParameterDataContract {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly description: string;
|
|
13
|
+
readonly cast: string | null;
|
|
14
|
+
/** Stored as "FQN::CASE" */
|
|
15
|
+
readonly mode: string;
|
|
16
|
+
/** Stored as "FQN::CASE" */
|
|
17
|
+
readonly valueMode: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface CliOptionParameterDataContract {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly description: string;
|
|
13
|
+
readonly valueDisplayName: string;
|
|
14
|
+
readonly cast: string | null;
|
|
15
|
+
readonly defaultValue: string;
|
|
16
|
+
readonly shortNames: readonly string[];
|
|
17
|
+
readonly validValues: readonly string[];
|
|
18
|
+
/** Stored as "FQN::CASE" */
|
|
19
|
+
readonly mode: string;
|
|
20
|
+
/** Stored as "FQN::CASE" */
|
|
21
|
+
readonly valueMode: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { CliArgumentParameterDataContract } from './CliArgumentParameterDataContract.ts';
|
|
11
|
+
import type { CliOptionParameterDataContract } from './CliOptionParameterDataContract.ts';
|
|
12
|
+
import type { HandlerDataContract } from './HandlerDataContract.ts';
|
|
13
|
+
|
|
14
|
+
export interface CliRouteDataContract {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly description: string;
|
|
17
|
+
readonly handler: HandlerDataContract | null;
|
|
18
|
+
readonly helpText: HandlerDataContract | null;
|
|
19
|
+
readonly routeMatchedMiddleware: readonly string[];
|
|
20
|
+
readonly routeDispatchedMiddleware: readonly string[];
|
|
21
|
+
readonly throwableCaughtMiddleware: readonly string[];
|
|
22
|
+
readonly exitedMiddleware: readonly string[];
|
|
23
|
+
readonly arguments: readonly CliArgumentParameterDataContract[];
|
|
24
|
+
readonly options: readonly CliOptionParameterDataContract[];
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface ConfigDataContract {
|
|
11
|
+
readonly namespace: string;
|
|
12
|
+
readonly dir: string;
|
|
13
|
+
readonly dataPath: string;
|
|
14
|
+
readonly dataNamespace: string;
|
|
15
|
+
readonly providers: readonly string[];
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface HandlerDataContract {
|
|
11
|
+
readonly class: string;
|
|
12
|
+
readonly method: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Sindri package.
|
|
3
|
+
*
|
|
4
|
+
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface HttpParameterDataContract {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly regex: string;
|
|
13
|
+
/** Stored as "FQN::CASE" or null */
|
|
14
|
+
readonly cast: string | null;
|
|
15
|
+
readonly isOptional: boolean;
|
|
16
|
+
readonly shouldCapture: boolean;
|
|
17
|
+
}
|