@rsdk/zones 6.0.0-next.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/dist/constants.d.ts +17 -0
- package/dist/constants.js +21 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators.d.ts +15 -0
- package/dist/decorators.js +25 -0
- package/dist/decorators.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/zone.class.d.ts +26 -0
- package/dist/zone.class.js +38 -0
- package/dist/zone.class.js.map +1 -0
- package/package.json +17 -0
- package/src/constants.ts +19 -0
- package/src/decorators.ts +21 -0
- package/src/index.ts +3 -0
- package/src/zone.class.ts +41 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol used as a key for storing and retrieving zone metadata
|
|
3
|
+
* associated with controllers in the application.
|
|
4
|
+
*/
|
|
5
|
+
export declare const API_ZONE_METADATA_KEY: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Represents the internal zone for API controllers. Controllers
|
|
8
|
+
* assigned this zone are excluded from the openapi.json file
|
|
9
|
+
* by default.
|
|
10
|
+
*/
|
|
11
|
+
export declare const API_ZONE_INTERNAL = "__internal";
|
|
12
|
+
/**
|
|
13
|
+
* Represents the default zone for API controllers. This zone is
|
|
14
|
+
* used when no specific zone is assigned to a controller,
|
|
15
|
+
* allowing for a fallback behavior.
|
|
16
|
+
*/
|
|
17
|
+
export declare const API_ZONE_DEFAULT = "__default";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_ZONE_DEFAULT = exports.API_ZONE_INTERNAL = exports.API_ZONE_METADATA_KEY = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Symbol used as a key for storing and retrieving zone metadata
|
|
6
|
+
* associated with controllers in the application.
|
|
7
|
+
*/
|
|
8
|
+
exports.API_ZONE_METADATA_KEY = Symbol('API_ZONE_KEY');
|
|
9
|
+
/**
|
|
10
|
+
* Represents the internal zone for API controllers. Controllers
|
|
11
|
+
* assigned this zone are excluded from the openapi.json file
|
|
12
|
+
* by default.
|
|
13
|
+
*/
|
|
14
|
+
exports.API_ZONE_INTERNAL = '__internal';
|
|
15
|
+
/**
|
|
16
|
+
* Represents the default zone for API controllers. This zone is
|
|
17
|
+
* used when no specific zone is assigned to a controller,
|
|
18
|
+
* allowing for a fallback behavior.
|
|
19
|
+
*/
|
|
20
|
+
exports.API_ZONE_DEFAULT = '__default';
|
|
21
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,qBAAqB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAE5D;;;;GAIG;AACU,QAAA,iBAAiB,GAAG,YAAY,CAAC;AAE9C;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,WAAW,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decorator that assigns a zone tag to a controller.
|
|
3
|
+
* Used to group related API endpoints together. Can be used to
|
|
4
|
+
* generate different openapi.json files for different zones.
|
|
5
|
+
*
|
|
6
|
+
* NOTE: ApiTags could be used instead, but their purpose is different
|
|
7
|
+
* @param zone The zone name to assign to the controller
|
|
8
|
+
*/
|
|
9
|
+
export declare const ApiZone: (zone: string) => ClassDecorator;
|
|
10
|
+
/**
|
|
11
|
+
* Decorator that assigns the internal zone to a controller. These
|
|
12
|
+
* endpoints are not included in the openapi.json file by default,
|
|
13
|
+
* by autodoc command.
|
|
14
|
+
*/
|
|
15
|
+
export declare const Internal: () => ClassDecorator;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Internal = exports.ApiZone = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const zone_class_1 = require("./zone.class");
|
|
6
|
+
/**
|
|
7
|
+
* Decorator that assigns a zone tag to a controller.
|
|
8
|
+
* Used to group related API endpoints together. Can be used to
|
|
9
|
+
* generate different openapi.json files for different zones.
|
|
10
|
+
*
|
|
11
|
+
* NOTE: ApiTags could be used instead, but their purpose is different
|
|
12
|
+
* @param zone The zone name to assign to the controller
|
|
13
|
+
*/
|
|
14
|
+
const ApiZone = (zone) => {
|
|
15
|
+
return (target) => zone_class_1.Zone.setForController(target, zone);
|
|
16
|
+
};
|
|
17
|
+
exports.ApiZone = ApiZone;
|
|
18
|
+
/**
|
|
19
|
+
* Decorator that assigns the internal zone to a controller. These
|
|
20
|
+
* endpoints are not included in the openapi.json file by default,
|
|
21
|
+
* by autodoc command.
|
|
22
|
+
*/
|
|
23
|
+
const Internal = () => (0, exports.ApiZone)(constants_1.API_ZONE_INTERNAL);
|
|
24
|
+
exports.Internal = Internal;
|
|
25
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAAA,2CAAgD;AAChD,6CAAoC;AAEpC;;;;;;;GAOG;AACI,MAAM,OAAO,GAAG,CAAC,IAAY,EAAkB,EAAE;IACtD,OAAO,CAAC,MAAc,EAAE,EAAE,CAAC,iBAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC,CAAC;AAFW,QAAA,OAAO,WAElB;AAEF;;;;GAIG;AACI,MAAM,QAAQ,GAAG,GAAmB,EAAE,CAAC,IAAA,eAAO,EAAC,6BAAiB,CAAC,CAAC;AAA5D,QAAA,QAAQ,YAAoD"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./decorators"), exports);
|
|
18
|
+
__exportStar(require("./zone.class"), exports);
|
|
19
|
+
__exportStar(require("./constants"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,8CAA4B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Helper class for managing API zones. API zones are used to filter
|
|
4
|
+
* endpoints in the openapi.json file, disable logging for some endpoints,
|
|
5
|
+
* etc.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Zone {
|
|
8
|
+
/**
|
|
9
|
+
* Sets the zone metadata for a controller class.
|
|
10
|
+
* @param target - The controller class to set the zone for.
|
|
11
|
+
* @param zone - The zone to set for the controller.
|
|
12
|
+
*/
|
|
13
|
+
static setForController(target: object, zone: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the zone metadata for execution context.
|
|
16
|
+
* @param context - The execution context.
|
|
17
|
+
* @returns The zone metadata for the execution context, or '__default' if no zone is set.
|
|
18
|
+
*/
|
|
19
|
+
static getForContext(context: ExecutionContext): string;
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the zone metadata for a controller class.
|
|
22
|
+
* @param target - The controller class to get the zone for.
|
|
23
|
+
* @returns The zone metadata for the controller class, or '__default' if no zone is set.
|
|
24
|
+
*/
|
|
25
|
+
static getForController(target: object): string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Zone = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
/**
|
|
6
|
+
* Helper class for managing API zones. API zones are used to filter
|
|
7
|
+
* endpoints in the openapi.json file, disable logging for some endpoints,
|
|
8
|
+
* etc.
|
|
9
|
+
*/
|
|
10
|
+
class Zone {
|
|
11
|
+
/**
|
|
12
|
+
* Sets the zone metadata for a controller class.
|
|
13
|
+
* @param target - The controller class to set the zone for.
|
|
14
|
+
* @param zone - The zone to set for the controller.
|
|
15
|
+
*/
|
|
16
|
+
static setForController(target, zone) {
|
|
17
|
+
Reflect.defineMetadata(constants_1.API_ZONE_METADATA_KEY, zone, target);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the zone metadata for execution context.
|
|
21
|
+
* @param context - The execution context.
|
|
22
|
+
* @returns The zone metadata for the execution context, or '__default' if no zone is set.
|
|
23
|
+
*/
|
|
24
|
+
static getForContext(context) {
|
|
25
|
+
const controller = context.getClass();
|
|
26
|
+
return Zone.getForController(controller);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the zone metadata for a controller class.
|
|
30
|
+
* @param target - The controller class to get the zone for.
|
|
31
|
+
* @returns The zone metadata for the controller class, or '__default' if no zone is set.
|
|
32
|
+
*/
|
|
33
|
+
static getForController(target) {
|
|
34
|
+
return (Reflect.getMetadata(constants_1.API_ZONE_METADATA_KEY, target) || constants_1.API_ZONE_DEFAULT);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Zone = Zone;
|
|
38
|
+
//# sourceMappingURL=zone.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zone.class.js","sourceRoot":"","sources":["../src/zone.class.ts"],"names":[],"mappings":";;;AAEA,2CAAsE;AAEtE;;;;GAIG;AACH,MAAa,IAAI;IACf;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,MAAc,EAAE,IAAY;QAClD,OAAO,CAAC,cAAc,CAAC,iCAAqB,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,OAAyB;QAC5C,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QAEtC,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,MAAc;QACpC,OAAO,CACL,OAAO,CAAC,WAAW,CAAC,iCAAqB,EAAE,MAAM,CAAC,IAAI,4BAAgB,CACvE,CAAC;IACJ,CAAC;CACF;AA/BD,oBA+BC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rsdk/zones",
|
|
3
|
+
"version": "6.0.0-next.0",
|
|
4
|
+
"description": "Tools for working with zones (API parts)",
|
|
5
|
+
"license": "Apache License 2.0",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "https://github.com/R-Vision/rsdk"
|
|
11
|
+
},
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@nestjs/common": "^10.0.0"
|
|
15
|
+
},
|
|
16
|
+
"gitHead": "215cccea23d95118dd8b6af3ce11c6a35ce19c30"
|
|
17
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol used as a key for storing and retrieving zone metadata
|
|
3
|
+
* associated with controllers in the application.
|
|
4
|
+
*/
|
|
5
|
+
export const API_ZONE_METADATA_KEY = Symbol('API_ZONE_KEY');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents the internal zone for API controllers. Controllers
|
|
9
|
+
* assigned this zone are excluded from the openapi.json file
|
|
10
|
+
* by default.
|
|
11
|
+
*/
|
|
12
|
+
export const API_ZONE_INTERNAL = '__internal';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents the default zone for API controllers. This zone is
|
|
16
|
+
* used when no specific zone is assigned to a controller,
|
|
17
|
+
* allowing for a fallback behavior.
|
|
18
|
+
*/
|
|
19
|
+
export const API_ZONE_DEFAULT = '__default';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { API_ZONE_INTERNAL } from './constants';
|
|
2
|
+
import { Zone } from './zone.class';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Decorator that assigns a zone tag to a controller.
|
|
6
|
+
* Used to group related API endpoints together. Can be used to
|
|
7
|
+
* generate different openapi.json files for different zones.
|
|
8
|
+
*
|
|
9
|
+
* NOTE: ApiTags could be used instead, but their purpose is different
|
|
10
|
+
* @param zone The zone name to assign to the controller
|
|
11
|
+
*/
|
|
12
|
+
export const ApiZone = (zone: string): ClassDecorator => {
|
|
13
|
+
return (target: object) => Zone.setForController(target, zone);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Decorator that assigns the internal zone to a controller. These
|
|
18
|
+
* endpoints are not included in the openapi.json file by default,
|
|
19
|
+
* by autodoc command.
|
|
20
|
+
*/
|
|
21
|
+
export const Internal = (): ClassDecorator => ApiZone(API_ZONE_INTERNAL);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { API_ZONE_DEFAULT, API_ZONE_METADATA_KEY } from './constants';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Helper class for managing API zones. API zones are used to filter
|
|
7
|
+
* endpoints in the openapi.json file, disable logging for some endpoints,
|
|
8
|
+
* etc.
|
|
9
|
+
*/
|
|
10
|
+
export class Zone {
|
|
11
|
+
/**
|
|
12
|
+
* Sets the zone metadata for a controller class.
|
|
13
|
+
* @param target - The controller class to set the zone for.
|
|
14
|
+
* @param zone - The zone to set for the controller.
|
|
15
|
+
*/
|
|
16
|
+
static setForController(target: object, zone: string): void {
|
|
17
|
+
Reflect.defineMetadata(API_ZONE_METADATA_KEY, zone, target);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the zone metadata for execution context.
|
|
22
|
+
* @param context - The execution context.
|
|
23
|
+
* @returns The zone metadata for the execution context, or '__default' if no zone is set.
|
|
24
|
+
*/
|
|
25
|
+
static getForContext(context: ExecutionContext): string {
|
|
26
|
+
const controller = context.getClass();
|
|
27
|
+
|
|
28
|
+
return Zone.getForController(controller);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the zone metadata for a controller class.
|
|
33
|
+
* @param target - The controller class to get the zone for.
|
|
34
|
+
* @returns The zone metadata for the controller class, or '__default' if no zone is set.
|
|
35
|
+
*/
|
|
36
|
+
static getForController(target: object): string {
|
|
37
|
+
return (
|
|
38
|
+
Reflect.getMetadata(API_ZONE_METADATA_KEY, target) || API_ZONE_DEFAULT
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|