ng-openapi 0.0.25-alpha.4 → 0.0.25-alpha.6
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/cli.cjs +98 -10
- package/index.js +98 -10
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -425,12 +425,14 @@ var TokenGenerator = class {
|
|
|
425
425
|
});
|
|
426
426
|
sourceFile.addImportDeclaration({
|
|
427
427
|
namedImports: [
|
|
428
|
-
"HttpInterceptor"
|
|
428
|
+
"HttpInterceptor",
|
|
429
|
+
"HttpContextToken"
|
|
429
430
|
],
|
|
430
431
|
moduleSpecifier: "@angular/common/http"
|
|
431
432
|
});
|
|
432
433
|
const basePathTokenName = this.getBasePathTokenName();
|
|
433
434
|
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
435
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
434
436
|
sourceFile.addVariableStatement({
|
|
435
437
|
isExported: true,
|
|
436
438
|
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
@@ -463,6 +465,20 @@ var TokenGenerator = class {
|
|
|
463
465
|
leadingTrivia: `/**
|
|
464
466
|
* Injection token for the ${this.clientName} client HTTP interceptor instances
|
|
465
467
|
*/
|
|
468
|
+
`
|
|
469
|
+
});
|
|
470
|
+
sourceFile.addVariableStatement({
|
|
471
|
+
isExported: true,
|
|
472
|
+
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
473
|
+
declarations: [
|
|
474
|
+
{
|
|
475
|
+
name: clientContextTokenName,
|
|
476
|
+
initializer: `new HttpContextToken<string>(() => '${this.clientName}')`
|
|
477
|
+
}
|
|
478
|
+
],
|
|
479
|
+
leadingTrivia: `/**
|
|
480
|
+
* HttpContext token to identify requests belonging to the ${this.clientName} client
|
|
481
|
+
*/
|
|
466
482
|
`
|
|
467
483
|
});
|
|
468
484
|
if (this.clientName === "default") {
|
|
@@ -478,6 +494,20 @@ var TokenGenerator = class {
|
|
|
478
494
|
leadingTrivia: `/**
|
|
479
495
|
* @deprecated Use ${basePathTokenName} instead
|
|
480
496
|
*/
|
|
497
|
+
`
|
|
498
|
+
});
|
|
499
|
+
sourceFile.addVariableStatement({
|
|
500
|
+
isExported: true,
|
|
501
|
+
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
502
|
+
declarations: [
|
|
503
|
+
{
|
|
504
|
+
name: "CLIENT_CONTEXT_TOKEN",
|
|
505
|
+
initializer: clientContextTokenName
|
|
506
|
+
}
|
|
507
|
+
],
|
|
508
|
+
leadingTrivia: `/**
|
|
509
|
+
* @deprecated Use ${clientContextTokenName} instead
|
|
510
|
+
*/
|
|
481
511
|
`
|
|
482
512
|
});
|
|
483
513
|
}
|
|
@@ -491,6 +521,10 @@ var TokenGenerator = class {
|
|
|
491
521
|
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
492
522
|
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
493
523
|
}
|
|
524
|
+
getClientContextTokenName() {
|
|
525
|
+
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
526
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
527
|
+
}
|
|
494
528
|
};
|
|
495
529
|
|
|
496
530
|
// src/lib/generators/utility/file-download.generator.ts
|
|
@@ -1040,6 +1074,7 @@ var BaseInterceptorGenerator = class {
|
|
|
1040
1074
|
sourceFile.insertText(0, BASE_INTERCEPTOR_HEADER_COMMENT(this.#clientName));
|
|
1041
1075
|
const basePathTokenName = this.getBasePathTokenName();
|
|
1042
1076
|
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
1077
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
1043
1078
|
sourceFile.addImportDeclarations([
|
|
1044
1079
|
{
|
|
1045
1080
|
namedImports: [
|
|
@@ -1066,7 +1101,8 @@ var BaseInterceptorGenerator = class {
|
|
|
1066
1101
|
{
|
|
1067
1102
|
namedImports: [
|
|
1068
1103
|
basePathTokenName,
|
|
1069
|
-
interceptorsTokenName
|
|
1104
|
+
interceptorsTokenName,
|
|
1105
|
+
clientContextTokenName
|
|
1070
1106
|
],
|
|
1071
1107
|
moduleSpecifier: "../tokens"
|
|
1072
1108
|
}
|
|
@@ -1085,11 +1121,11 @@ var BaseInterceptorGenerator = class {
|
|
|
1085
1121
|
],
|
|
1086
1122
|
properties: [
|
|
1087
1123
|
{
|
|
1088
|
-
name: "
|
|
1124
|
+
name: "clientName",
|
|
1089
1125
|
type: "string",
|
|
1090
1126
|
scope: import_ts_morph3.Scope.Private,
|
|
1091
1127
|
isReadonly: true,
|
|
1092
|
-
initializer: `
|
|
1128
|
+
initializer: `'${this.#clientName}'`
|
|
1093
1129
|
},
|
|
1094
1130
|
{
|
|
1095
1131
|
name: "httpInterceptors",
|
|
@@ -1097,6 +1133,13 @@ var BaseInterceptorGenerator = class {
|
|
|
1097
1133
|
scope: import_ts_morph3.Scope.Private,
|
|
1098
1134
|
isReadonly: true,
|
|
1099
1135
|
initializer: `inject(${interceptorsTokenName})`
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
name: "clientContextToken",
|
|
1139
|
+
type: "any",
|
|
1140
|
+
scope: import_ts_morph3.Scope.Private,
|
|
1141
|
+
isReadonly: true,
|
|
1142
|
+
initializer: clientContextTokenName
|
|
1100
1143
|
}
|
|
1101
1144
|
],
|
|
1102
1145
|
methods: [
|
|
@@ -1114,8 +1157,11 @@ var BaseInterceptorGenerator = class {
|
|
|
1114
1157
|
],
|
|
1115
1158
|
returnType: "Observable<HttpEvent<any>>",
|
|
1116
1159
|
statements: `
|
|
1117
|
-
//
|
|
1118
|
-
|
|
1160
|
+
// Check if this request belongs to this client using HttpContext
|
|
1161
|
+
const requestClientName = req.context.get(this.clientContextToken);
|
|
1162
|
+
|
|
1163
|
+
if (requestClientName !== this.clientName) {
|
|
1164
|
+
// This request doesn't belong to this client, pass it through
|
|
1119
1165
|
return next.handle(req);
|
|
1120
1166
|
}
|
|
1121
1167
|
|
|
@@ -1143,6 +1189,10 @@ var BaseInterceptorGenerator = class {
|
|
|
1143
1189
|
const clientSuffix = this.#clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1144
1190
|
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
1145
1191
|
}
|
|
1192
|
+
getClientContextTokenName() {
|
|
1193
|
+
const clientSuffix = this.#clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1194
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
1195
|
+
}
|
|
1146
1196
|
capitalizeFirst(str) {
|
|
1147
1197
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1148
1198
|
}
|
|
@@ -1439,9 +1489,7 @@ ${formDataAppends}`;
|
|
|
1439
1489
|
}
|
|
1440
1490
|
options.push("reportProgress: options?.reportProgress");
|
|
1441
1491
|
options.push("withCredentials: options?.withCredentials");
|
|
1442
|
-
|
|
1443
|
-
options.push("context: options?.context");
|
|
1444
|
-
}
|
|
1492
|
+
options.push("context: this.createContextWithClientId(options?.context)");
|
|
1445
1493
|
const formattedOptions = options.filter((opt) => opt && !opt.includes("undefined")).join(",\n ");
|
|
1446
1494
|
return `
|
|
1447
1495
|
const requestOptions: any = {
|
|
@@ -1533,6 +1581,16 @@ return this.httpClient.${httpMethod}(url, requestOptions);`;
|
|
|
1533
1581
|
}
|
|
1534
1582
|
return "blob";
|
|
1535
1583
|
}
|
|
1584
|
+
generateContextHelper() {
|
|
1585
|
+
return `
|
|
1586
|
+
/**
|
|
1587
|
+
* Creates HttpContext with client identification
|
|
1588
|
+
*/
|
|
1589
|
+
private createContextWithClientId(existingContext?: HttpContext): HttpContext {
|
|
1590
|
+
const context = existingContext || new HttpContext();
|
|
1591
|
+
return context.set(this.clientContextToken, '${this.config.clientName || "default"}');
|
|
1592
|
+
}`;
|
|
1593
|
+
}
|
|
1536
1594
|
};
|
|
1537
1595
|
|
|
1538
1596
|
// src/lib/generators/service/service-method/service-method-params.generator.ts
|
|
@@ -2094,6 +2152,7 @@ var ServiceGenerator = class {
|
|
|
2094
2152
|
}
|
|
2095
2153
|
addImports(sourceFile, usedTypes) {
|
|
2096
2154
|
const basePathTokenName = this.getBasePathTokenName();
|
|
2155
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
2097
2156
|
sourceFile.addImportDeclarations([
|
|
2098
2157
|
{
|
|
2099
2158
|
namedImports: [
|
|
@@ -2121,7 +2180,8 @@ var ServiceGenerator = class {
|
|
|
2121
2180
|
},
|
|
2122
2181
|
{
|
|
2123
2182
|
namedImports: [
|
|
2124
|
-
basePathTokenName
|
|
2183
|
+
basePathTokenName,
|
|
2184
|
+
clientContextTokenName
|
|
2125
2185
|
],
|
|
2126
2186
|
moduleSpecifier: "../tokens"
|
|
2127
2187
|
}
|
|
@@ -2136,6 +2196,7 @@ var ServiceGenerator = class {
|
|
|
2136
2196
|
addServiceClass(sourceFile, controllerName, operations) {
|
|
2137
2197
|
const className = `${controllerName}Service`;
|
|
2138
2198
|
const basePathTokenName = this.getBasePathTokenName();
|
|
2199
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
2139
2200
|
sourceFile.insertText(0, SERVICE_GENERATOR_HEADER_COMMENT(controllerName));
|
|
2140
2201
|
const serviceClass = sourceFile.addClass({
|
|
2141
2202
|
name: className,
|
|
@@ -2163,6 +2224,28 @@ var ServiceGenerator = class {
|
|
|
2163
2224
|
isReadonly: true,
|
|
2164
2225
|
initializer: `inject(${basePathTokenName})`
|
|
2165
2226
|
});
|
|
2227
|
+
serviceClass.addProperty({
|
|
2228
|
+
name: "clientContextToken",
|
|
2229
|
+
type: "any",
|
|
2230
|
+
scope: import_ts_morph4.Scope.Private,
|
|
2231
|
+
isReadonly: true,
|
|
2232
|
+
initializer: clientContextTokenName
|
|
2233
|
+
});
|
|
2234
|
+
serviceClass.addMethod({
|
|
2235
|
+
name: "createContextWithClientId",
|
|
2236
|
+
scope: import_ts_morph4.Scope.Private,
|
|
2237
|
+
parameters: [
|
|
2238
|
+
{
|
|
2239
|
+
name: "existingContext",
|
|
2240
|
+
type: "HttpContext",
|
|
2241
|
+
hasQuestionToken: true
|
|
2242
|
+
}
|
|
2243
|
+
],
|
|
2244
|
+
returnType: "HttpContext",
|
|
2245
|
+
statements: `
|
|
2246
|
+
const context = existingContext || new HttpContext();
|
|
2247
|
+
return context.set(this.clientContextToken, '${this.config.clientName || "default"}');`
|
|
2248
|
+
});
|
|
2166
2249
|
operations.forEach((operation) => {
|
|
2167
2250
|
this.methodGenerator.addServiceMethod(serviceClass, operation);
|
|
2168
2251
|
});
|
|
@@ -2170,6 +2253,11 @@ var ServiceGenerator = class {
|
|
|
2170
2253
|
throw new Error(`Duplicate method names found in service class ${className}. Please ensure unique method names for each operation.`);
|
|
2171
2254
|
}
|
|
2172
2255
|
}
|
|
2256
|
+
getClientContextTokenName() {
|
|
2257
|
+
const clientName = this.config.clientName || "default";
|
|
2258
|
+
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
2259
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
2260
|
+
}
|
|
2173
2261
|
getBasePathTokenName() {
|
|
2174
2262
|
const clientName = this.config.clientName || "default";
|
|
2175
2263
|
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
package/index.js
CHANGED
|
@@ -472,12 +472,14 @@ var _TokenGenerator = class _TokenGenerator {
|
|
|
472
472
|
});
|
|
473
473
|
sourceFile.addImportDeclaration({
|
|
474
474
|
namedImports: [
|
|
475
|
-
"HttpInterceptor"
|
|
475
|
+
"HttpInterceptor",
|
|
476
|
+
"HttpContextToken"
|
|
476
477
|
],
|
|
477
478
|
moduleSpecifier: "@angular/common/http"
|
|
478
479
|
});
|
|
479
480
|
const basePathTokenName = this.getBasePathTokenName();
|
|
480
481
|
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
482
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
481
483
|
sourceFile.addVariableStatement({
|
|
482
484
|
isExported: true,
|
|
483
485
|
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
@@ -510,6 +512,20 @@ var _TokenGenerator = class _TokenGenerator {
|
|
|
510
512
|
leadingTrivia: `/**
|
|
511
513
|
* Injection token for the ${this.clientName} client HTTP interceptor instances
|
|
512
514
|
*/
|
|
515
|
+
`
|
|
516
|
+
});
|
|
517
|
+
sourceFile.addVariableStatement({
|
|
518
|
+
isExported: true,
|
|
519
|
+
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
520
|
+
declarations: [
|
|
521
|
+
{
|
|
522
|
+
name: clientContextTokenName,
|
|
523
|
+
initializer: `new HttpContextToken<string>(() => '${this.clientName}')`
|
|
524
|
+
}
|
|
525
|
+
],
|
|
526
|
+
leadingTrivia: `/**
|
|
527
|
+
* HttpContext token to identify requests belonging to the ${this.clientName} client
|
|
528
|
+
*/
|
|
513
529
|
`
|
|
514
530
|
});
|
|
515
531
|
if (this.clientName === "default") {
|
|
@@ -525,6 +541,20 @@ var _TokenGenerator = class _TokenGenerator {
|
|
|
525
541
|
leadingTrivia: `/**
|
|
526
542
|
* @deprecated Use ${basePathTokenName} instead
|
|
527
543
|
*/
|
|
544
|
+
`
|
|
545
|
+
});
|
|
546
|
+
sourceFile.addVariableStatement({
|
|
547
|
+
isExported: true,
|
|
548
|
+
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
549
|
+
declarations: [
|
|
550
|
+
{
|
|
551
|
+
name: "CLIENT_CONTEXT_TOKEN",
|
|
552
|
+
initializer: clientContextTokenName
|
|
553
|
+
}
|
|
554
|
+
],
|
|
555
|
+
leadingTrivia: `/**
|
|
556
|
+
* @deprecated Use ${clientContextTokenName} instead
|
|
557
|
+
*/
|
|
528
558
|
`
|
|
529
559
|
});
|
|
530
560
|
}
|
|
@@ -538,6 +568,10 @@ var _TokenGenerator = class _TokenGenerator {
|
|
|
538
568
|
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
539
569
|
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
540
570
|
}
|
|
571
|
+
getClientContextTokenName() {
|
|
572
|
+
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
573
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
574
|
+
}
|
|
541
575
|
};
|
|
542
576
|
__name(_TokenGenerator, "TokenGenerator");
|
|
543
577
|
var TokenGenerator = _TokenGenerator;
|
|
@@ -1083,6 +1117,7 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1083
1117
|
sourceFile.insertText(0, BASE_INTERCEPTOR_HEADER_COMMENT(__privateGet(this, _clientName)));
|
|
1084
1118
|
const basePathTokenName = this.getBasePathTokenName();
|
|
1085
1119
|
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
1120
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
1086
1121
|
sourceFile.addImportDeclarations([
|
|
1087
1122
|
{
|
|
1088
1123
|
namedImports: [
|
|
@@ -1109,7 +1144,8 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1109
1144
|
{
|
|
1110
1145
|
namedImports: [
|
|
1111
1146
|
basePathTokenName,
|
|
1112
|
-
interceptorsTokenName
|
|
1147
|
+
interceptorsTokenName,
|
|
1148
|
+
clientContextTokenName
|
|
1113
1149
|
],
|
|
1114
1150
|
moduleSpecifier: "../tokens"
|
|
1115
1151
|
}
|
|
@@ -1128,11 +1164,11 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1128
1164
|
],
|
|
1129
1165
|
properties: [
|
|
1130
1166
|
{
|
|
1131
|
-
name: "
|
|
1167
|
+
name: "clientName",
|
|
1132
1168
|
type: "string",
|
|
1133
1169
|
scope: import_ts_morph3.Scope.Private,
|
|
1134
1170
|
isReadonly: true,
|
|
1135
|
-
initializer: `
|
|
1171
|
+
initializer: `'${__privateGet(this, _clientName)}'`
|
|
1136
1172
|
},
|
|
1137
1173
|
{
|
|
1138
1174
|
name: "httpInterceptors",
|
|
@@ -1140,6 +1176,13 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1140
1176
|
scope: import_ts_morph3.Scope.Private,
|
|
1141
1177
|
isReadonly: true,
|
|
1142
1178
|
initializer: `inject(${interceptorsTokenName})`
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
name: "clientContextToken",
|
|
1182
|
+
type: "any",
|
|
1183
|
+
scope: import_ts_morph3.Scope.Private,
|
|
1184
|
+
isReadonly: true,
|
|
1185
|
+
initializer: clientContextTokenName
|
|
1143
1186
|
}
|
|
1144
1187
|
],
|
|
1145
1188
|
methods: [
|
|
@@ -1157,8 +1200,11 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1157
1200
|
],
|
|
1158
1201
|
returnType: "Observable<HttpEvent<any>>",
|
|
1159
1202
|
statements: `
|
|
1160
|
-
//
|
|
1161
|
-
|
|
1203
|
+
// Check if this request belongs to this client using HttpContext
|
|
1204
|
+
const requestClientName = req.context.get(this.clientContextToken);
|
|
1205
|
+
|
|
1206
|
+
if (requestClientName !== this.clientName) {
|
|
1207
|
+
// This request doesn't belong to this client, pass it through
|
|
1162
1208
|
return next.handle(req);
|
|
1163
1209
|
}
|
|
1164
1210
|
|
|
@@ -1186,6 +1232,10 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1186
1232
|
const clientSuffix = __privateGet(this, _clientName).toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1187
1233
|
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
1188
1234
|
}
|
|
1235
|
+
getClientContextTokenName() {
|
|
1236
|
+
const clientSuffix = __privateGet(this, _clientName).toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1237
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
1238
|
+
}
|
|
1189
1239
|
capitalizeFirst(str) {
|
|
1190
1240
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1191
1241
|
}
|
|
@@ -1488,9 +1538,7 @@ ${formDataAppends}`;
|
|
|
1488
1538
|
}
|
|
1489
1539
|
options.push("reportProgress: options?.reportProgress");
|
|
1490
1540
|
options.push("withCredentials: options?.withCredentials");
|
|
1491
|
-
|
|
1492
|
-
options.push("context: options?.context");
|
|
1493
|
-
}
|
|
1541
|
+
options.push("context: this.createContextWithClientId(options?.context)");
|
|
1494
1542
|
const formattedOptions = options.filter((opt) => opt && !opt.includes("undefined")).join(",\n ");
|
|
1495
1543
|
return `
|
|
1496
1544
|
const requestOptions: any = {
|
|
@@ -1584,6 +1632,16 @@ return this.httpClient.${httpMethod}(url, requestOptions);`;
|
|
|
1584
1632
|
}
|
|
1585
1633
|
return "blob";
|
|
1586
1634
|
}
|
|
1635
|
+
generateContextHelper() {
|
|
1636
|
+
return `
|
|
1637
|
+
/**
|
|
1638
|
+
* Creates HttpContext with client identification
|
|
1639
|
+
*/
|
|
1640
|
+
private createContextWithClientId(existingContext?: HttpContext): HttpContext {
|
|
1641
|
+
const context = existingContext || new HttpContext();
|
|
1642
|
+
return context.set(this.clientContextToken, '${this.config.clientName || "default"}');
|
|
1643
|
+
}`;
|
|
1644
|
+
}
|
|
1587
1645
|
};
|
|
1588
1646
|
__name(_ServiceMethodBodyGenerator, "ServiceMethodBodyGenerator");
|
|
1589
1647
|
var ServiceMethodBodyGenerator = _ServiceMethodBodyGenerator;
|
|
@@ -2146,6 +2204,7 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2146
2204
|
}
|
|
2147
2205
|
addImports(sourceFile, usedTypes) {
|
|
2148
2206
|
const basePathTokenName = this.getBasePathTokenName();
|
|
2207
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
2149
2208
|
sourceFile.addImportDeclarations([
|
|
2150
2209
|
{
|
|
2151
2210
|
namedImports: [
|
|
@@ -2173,7 +2232,8 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2173
2232
|
},
|
|
2174
2233
|
{
|
|
2175
2234
|
namedImports: [
|
|
2176
|
-
basePathTokenName
|
|
2235
|
+
basePathTokenName,
|
|
2236
|
+
clientContextTokenName
|
|
2177
2237
|
],
|
|
2178
2238
|
moduleSpecifier: "../tokens"
|
|
2179
2239
|
}
|
|
@@ -2188,6 +2248,7 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2188
2248
|
addServiceClass(sourceFile, controllerName, operations) {
|
|
2189
2249
|
const className = `${controllerName}Service`;
|
|
2190
2250
|
const basePathTokenName = this.getBasePathTokenName();
|
|
2251
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
2191
2252
|
sourceFile.insertText(0, SERVICE_GENERATOR_HEADER_COMMENT(controllerName));
|
|
2192
2253
|
const serviceClass = sourceFile.addClass({
|
|
2193
2254
|
name: className,
|
|
@@ -2215,6 +2276,28 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2215
2276
|
isReadonly: true,
|
|
2216
2277
|
initializer: `inject(${basePathTokenName})`
|
|
2217
2278
|
});
|
|
2279
|
+
serviceClass.addProperty({
|
|
2280
|
+
name: "clientContextToken",
|
|
2281
|
+
type: "any",
|
|
2282
|
+
scope: import_ts_morph4.Scope.Private,
|
|
2283
|
+
isReadonly: true,
|
|
2284
|
+
initializer: clientContextTokenName
|
|
2285
|
+
});
|
|
2286
|
+
serviceClass.addMethod({
|
|
2287
|
+
name: "createContextWithClientId",
|
|
2288
|
+
scope: import_ts_morph4.Scope.Private,
|
|
2289
|
+
parameters: [
|
|
2290
|
+
{
|
|
2291
|
+
name: "existingContext",
|
|
2292
|
+
type: "HttpContext",
|
|
2293
|
+
hasQuestionToken: true
|
|
2294
|
+
}
|
|
2295
|
+
],
|
|
2296
|
+
returnType: "HttpContext",
|
|
2297
|
+
statements: `
|
|
2298
|
+
const context = existingContext || new HttpContext();
|
|
2299
|
+
return context.set(this.clientContextToken, '${this.config.clientName || "default"}');`
|
|
2300
|
+
});
|
|
2218
2301
|
operations.forEach((operation) => {
|
|
2219
2302
|
this.methodGenerator.addServiceMethod(serviceClass, operation);
|
|
2220
2303
|
});
|
|
@@ -2222,6 +2305,11 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2222
2305
|
throw new Error(`Duplicate method names found in service class ${className}. Please ensure unique method names for each operation.`);
|
|
2223
2306
|
}
|
|
2224
2307
|
}
|
|
2308
|
+
getClientContextTokenName() {
|
|
2309
|
+
const clientName = this.config.clientName || "default";
|
|
2310
|
+
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
2311
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
2312
|
+
}
|
|
2225
2313
|
getBasePathTokenName() {
|
|
2226
2314
|
const clientName = this.config.clientName || "default";
|
|
2227
2315
|
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|