@ng-openapi/http-resource 0.1.0 → 0.1.1-pr-110-feat-service-decorator-d5a26e8.0
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/index.cjs +45 -14
- package/index.d.ts +7 -0
- package/index.js +45 -14
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -3010,12 +3010,45 @@ ${paramMappings}`;
|
|
|
3010
3010
|
}
|
|
3011
3011
|
__name(emitSignalAwareQueryParams, "emitSignalAwareQueryParams");
|
|
3012
3012
|
|
|
3013
|
+
// ../../shared/src/emit/service-decorator.emit.ts
|
|
3014
|
+
function emitServiceDecorator(options) {
|
|
3015
|
+
if (options.serviceDecorator === "service") {
|
|
3016
|
+
return {
|
|
3017
|
+
decorator: {
|
|
3018
|
+
name: "Service",
|
|
3019
|
+
arguments: []
|
|
3020
|
+
},
|
|
3021
|
+
namedImport: "Service"
|
|
3022
|
+
};
|
|
3023
|
+
}
|
|
3024
|
+
return {
|
|
3025
|
+
decorator: {
|
|
3026
|
+
name: "Injectable",
|
|
3027
|
+
arguments: [
|
|
3028
|
+
'{ providedIn: "root" }'
|
|
3029
|
+
]
|
|
3030
|
+
},
|
|
3031
|
+
namedImport: "Injectable"
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
__name(emitServiceDecorator, "emitServiceDecorator");
|
|
3035
|
+
|
|
3013
3036
|
// ../../shared/src/emit/response-type.emit.ts
|
|
3014
3037
|
function joinRequestOptionEntries(entries) {
|
|
3015
3038
|
return entries.filter((entry) => entry && !entry.includes("undefined")).join(",\n ");
|
|
3016
3039
|
}
|
|
3017
3040
|
__name(joinRequestOptionEntries, "joinRequestOptionEntries");
|
|
3018
3041
|
|
|
3042
|
+
// ../../shared/src/utils/project.utils.ts
|
|
3043
|
+
function listGeneratedFileNames(project, directoryPath, suffix) {
|
|
3044
|
+
const directory = project.getDirectory(directoryPath);
|
|
3045
|
+
if (!directory) {
|
|
3046
|
+
return [];
|
|
3047
|
+
}
|
|
3048
|
+
return directory.getSourceFiles().map((file) => file.getBaseName()).filter((baseName) => baseName.endsWith(suffix)).map((baseName) => baseName.slice(0, -suffix.length)).sort();
|
|
3049
|
+
}
|
|
3050
|
+
__name(listGeneratedFileNames, "listGeneratedFileNames");
|
|
3051
|
+
|
|
3019
3052
|
// ../../shared/src/utils/functions/token-names.ts
|
|
3020
3053
|
function getClientContextTokenName(clientName = "default") {
|
|
3021
3054
|
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
@@ -3326,7 +3359,6 @@ var HttpResourceMethodGenerator = class {
|
|
|
3326
3359
|
};
|
|
3327
3360
|
|
|
3328
3361
|
// src/lib/http-resource-index.generator.ts
|
|
3329
|
-
var fs = __toESM(require("fs"), 1);
|
|
3330
3362
|
var path = __toESM(require("path"), 1);
|
|
3331
3363
|
var HttpResourceIndexGenerator = class {
|
|
3332
3364
|
static {
|
|
@@ -3337,20 +3369,23 @@ var HttpResourceIndexGenerator = class {
|
|
|
3337
3369
|
this.project = project;
|
|
3338
3370
|
}
|
|
3339
3371
|
generateIndex(outputRoot) {
|
|
3340
|
-
const
|
|
3341
|
-
const
|
|
3372
|
+
const resourcesDir = path.join(outputRoot, "resources");
|
|
3373
|
+
const resourceFiles = listGeneratedFileNames(this.project, resourcesDir, ".resource.ts");
|
|
3374
|
+
if (resourceFiles.length === 0) {
|
|
3375
|
+
return;
|
|
3376
|
+
}
|
|
3377
|
+
const indexPath = path.join(resourcesDir, "index.ts");
|
|
3342
3378
|
const sourceFile = this.project.createSourceFile(indexPath, "", {
|
|
3343
3379
|
overwrite: true
|
|
3344
3380
|
});
|
|
3345
3381
|
sourceFile.insertText(0, SERVICE_INDEX_GENERATOR_HEADER_COMMENT);
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
const className = pascalCase(serviceName) + "Resource";
|
|
3382
|
+
resourceFiles.forEach((resourceName) => {
|
|
3383
|
+
const className = pascalCase(resourceName) + "Resource";
|
|
3349
3384
|
sourceFile.addExportDeclaration({
|
|
3350
3385
|
namedExports: [
|
|
3351
3386
|
className
|
|
3352
3387
|
],
|
|
3353
|
-
moduleSpecifier: `./${
|
|
3388
|
+
moduleSpecifier: `./${resourceName}.resource`
|
|
3354
3389
|
});
|
|
3355
3390
|
});
|
|
3356
3391
|
sourceFile.formatText();
|
|
@@ -3425,6 +3460,7 @@ var HttpResourceGenerator = class {
|
|
|
3425
3460
|
const className = `${resourceName}`;
|
|
3426
3461
|
const basePathTokenName = getBasePathTokenName(this.config.clientName);
|
|
3427
3462
|
const clientContextTokenName = getClientContextTokenName(this.config.clientName);
|
|
3463
|
+
const serviceDecorator = emitServiceDecorator(this.config.options);
|
|
3428
3464
|
sourceFile.insertText(0, HTTP_RESOURCE_GENERATOR_HEADER_COMMENT(resourceName));
|
|
3429
3465
|
sourceFile.addImportDeclarations([
|
|
3430
3466
|
{
|
|
@@ -3443,7 +3479,7 @@ var HttpResourceGenerator = class {
|
|
|
3443
3479
|
{
|
|
3444
3480
|
namedImports: [
|
|
3445
3481
|
"inject",
|
|
3446
|
-
|
|
3482
|
+
serviceDecorator.namedImport,
|
|
3447
3483
|
"Signal"
|
|
3448
3484
|
],
|
|
3449
3485
|
moduleSpecifier: "@angular/core"
|
|
@@ -3466,12 +3502,7 @@ var HttpResourceGenerator = class {
|
|
|
3466
3502
|
name: className,
|
|
3467
3503
|
isExported: true,
|
|
3468
3504
|
decorators: [
|
|
3469
|
-
|
|
3470
|
-
name: "Injectable",
|
|
3471
|
-
arguments: [
|
|
3472
|
-
'{ providedIn: "root" }'
|
|
3473
|
-
]
|
|
3474
|
-
}
|
|
3505
|
+
serviceDecorator.decorator
|
|
3475
3506
|
]
|
|
3476
3507
|
});
|
|
3477
3508
|
serviceClass.addProperty({
|
package/index.d.ts
CHANGED
|
@@ -265,6 +265,13 @@ interface GeneratorConfig {
|
|
|
265
265
|
customizeMethodName?: (operationId: string) => string;
|
|
266
266
|
/** Collapse each method's parameters into a single request object. */
|
|
267
267
|
useSingleRequestParameter?: boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Class decorator emitted on generated services/resources. `"service"`
|
|
270
|
+
* emits Angular 22+'s `@Service()` (pre-release; shorthand for exactly
|
|
271
|
+
* `@Injectable({ providedIn: "root" })`) — generated code will not
|
|
272
|
+
* compile on Angular ≤ 21. Default: `"injectable"`.
|
|
273
|
+
*/
|
|
274
|
+
serviceDecorator?: "injectable" | "service";
|
|
268
275
|
};
|
|
269
276
|
/** Overrides for the ts-morph compiler settings used during generation. */
|
|
270
277
|
compilerOptions?: {
|
package/index.js
CHANGED
|
@@ -2976,12 +2976,45 @@ ${paramMappings}`;
|
|
|
2976
2976
|
}
|
|
2977
2977
|
__name(emitSignalAwareQueryParams, "emitSignalAwareQueryParams");
|
|
2978
2978
|
|
|
2979
|
+
// ../../shared/src/emit/service-decorator.emit.ts
|
|
2980
|
+
function emitServiceDecorator(options) {
|
|
2981
|
+
if (options.serviceDecorator === "service") {
|
|
2982
|
+
return {
|
|
2983
|
+
decorator: {
|
|
2984
|
+
name: "Service",
|
|
2985
|
+
arguments: []
|
|
2986
|
+
},
|
|
2987
|
+
namedImport: "Service"
|
|
2988
|
+
};
|
|
2989
|
+
}
|
|
2990
|
+
return {
|
|
2991
|
+
decorator: {
|
|
2992
|
+
name: "Injectable",
|
|
2993
|
+
arguments: [
|
|
2994
|
+
'{ providedIn: "root" }'
|
|
2995
|
+
]
|
|
2996
|
+
},
|
|
2997
|
+
namedImport: "Injectable"
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
3000
|
+
__name(emitServiceDecorator, "emitServiceDecorator");
|
|
3001
|
+
|
|
2979
3002
|
// ../../shared/src/emit/response-type.emit.ts
|
|
2980
3003
|
function joinRequestOptionEntries(entries) {
|
|
2981
3004
|
return entries.filter((entry) => entry && !entry.includes("undefined")).join(",\n ");
|
|
2982
3005
|
}
|
|
2983
3006
|
__name(joinRequestOptionEntries, "joinRequestOptionEntries");
|
|
2984
3007
|
|
|
3008
|
+
// ../../shared/src/utils/project.utils.ts
|
|
3009
|
+
function listGeneratedFileNames(project, directoryPath, suffix) {
|
|
3010
|
+
const directory = project.getDirectory(directoryPath);
|
|
3011
|
+
if (!directory) {
|
|
3012
|
+
return [];
|
|
3013
|
+
}
|
|
3014
|
+
return directory.getSourceFiles().map((file) => file.getBaseName()).filter((baseName) => baseName.endsWith(suffix)).map((baseName) => baseName.slice(0, -suffix.length)).sort();
|
|
3015
|
+
}
|
|
3016
|
+
__name(listGeneratedFileNames, "listGeneratedFileNames");
|
|
3017
|
+
|
|
2985
3018
|
// ../../shared/src/utils/functions/token-names.ts
|
|
2986
3019
|
function getClientContextTokenName(clientName = "default") {
|
|
2987
3020
|
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
@@ -3292,7 +3325,6 @@ var HttpResourceMethodGenerator = class {
|
|
|
3292
3325
|
};
|
|
3293
3326
|
|
|
3294
3327
|
// src/lib/http-resource-index.generator.ts
|
|
3295
|
-
import * as fs from "fs";
|
|
3296
3328
|
import * as path from "path";
|
|
3297
3329
|
var HttpResourceIndexGenerator = class {
|
|
3298
3330
|
static {
|
|
@@ -3303,20 +3335,23 @@ var HttpResourceIndexGenerator = class {
|
|
|
3303
3335
|
this.project = project;
|
|
3304
3336
|
}
|
|
3305
3337
|
generateIndex(outputRoot) {
|
|
3306
|
-
const
|
|
3307
|
-
const
|
|
3338
|
+
const resourcesDir = path.join(outputRoot, "resources");
|
|
3339
|
+
const resourceFiles = listGeneratedFileNames(this.project, resourcesDir, ".resource.ts");
|
|
3340
|
+
if (resourceFiles.length === 0) {
|
|
3341
|
+
return;
|
|
3342
|
+
}
|
|
3343
|
+
const indexPath = path.join(resourcesDir, "index.ts");
|
|
3308
3344
|
const sourceFile = this.project.createSourceFile(indexPath, "", {
|
|
3309
3345
|
overwrite: true
|
|
3310
3346
|
});
|
|
3311
3347
|
sourceFile.insertText(0, SERVICE_INDEX_GENERATOR_HEADER_COMMENT);
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
const className = pascalCase(serviceName) + "Resource";
|
|
3348
|
+
resourceFiles.forEach((resourceName) => {
|
|
3349
|
+
const className = pascalCase(resourceName) + "Resource";
|
|
3315
3350
|
sourceFile.addExportDeclaration({
|
|
3316
3351
|
namedExports: [
|
|
3317
3352
|
className
|
|
3318
3353
|
],
|
|
3319
|
-
moduleSpecifier: `./${
|
|
3354
|
+
moduleSpecifier: `./${resourceName}.resource`
|
|
3320
3355
|
});
|
|
3321
3356
|
});
|
|
3322
3357
|
sourceFile.formatText();
|
|
@@ -3391,6 +3426,7 @@ var HttpResourceGenerator = class {
|
|
|
3391
3426
|
const className = `${resourceName}`;
|
|
3392
3427
|
const basePathTokenName = getBasePathTokenName(this.config.clientName);
|
|
3393
3428
|
const clientContextTokenName = getClientContextTokenName(this.config.clientName);
|
|
3429
|
+
const serviceDecorator = emitServiceDecorator(this.config.options);
|
|
3394
3430
|
sourceFile.insertText(0, HTTP_RESOURCE_GENERATOR_HEADER_COMMENT(resourceName));
|
|
3395
3431
|
sourceFile.addImportDeclarations([
|
|
3396
3432
|
{
|
|
@@ -3409,7 +3445,7 @@ var HttpResourceGenerator = class {
|
|
|
3409
3445
|
{
|
|
3410
3446
|
namedImports: [
|
|
3411
3447
|
"inject",
|
|
3412
|
-
|
|
3448
|
+
serviceDecorator.namedImport,
|
|
3413
3449
|
"Signal"
|
|
3414
3450
|
],
|
|
3415
3451
|
moduleSpecifier: "@angular/core"
|
|
@@ -3432,12 +3468,7 @@ var HttpResourceGenerator = class {
|
|
|
3432
3468
|
name: className,
|
|
3433
3469
|
isExported: true,
|
|
3434
3470
|
decorators: [
|
|
3435
|
-
|
|
3436
|
-
name: "Injectable",
|
|
3437
|
-
arguments: [
|
|
3438
|
-
'{ providedIn: "root" }'
|
|
3439
|
-
]
|
|
3440
|
-
}
|
|
3471
|
+
serviceDecorator.decorator
|
|
3441
3472
|
]
|
|
3442
3473
|
});
|
|
3443
3474
|
serviceClass.addProperty({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-openapi/http-resource",
|
|
3
|
-
"version": "0.1.0",
|
|
3
|
+
"version": "0.1.1-pr-110-feat-service-decorator-d5a26e8.0",
|
|
4
4
|
"description": "HTTP Resource plugin for ng-openapi - Angular HTTP utilities with caching and state management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|