@jsnw/srv-utils 1.3.2 → 2.1.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/README.md +0 -10
- package/dist/index.cjs +349 -0
- package/dist/index.d.cts +169 -0
- package/package.json +22 -28
- package/dist/config/config-loader.js +0 -179
- package/dist/config/config-loader.types.js +0 -2
- package/dist/config/index.js +0 -7
- package/dist/config/predefined-schemas/connection.schema.js +0 -10
- package/dist/config/predefined-schemas/index.js +0 -17
- package/dist/config/predefined-schemas/mongodb-connection.schema.js +0 -15
- package/dist/config/predefined-schemas/mysql-connection.schema.js +0 -8
- package/dist/config/predefined-schemas/rabbit-connection.schema.js +0 -8
- package/dist/config/predefined-schemas/redis-connection.schema.js +0 -9
- package/dist/config/predefined-schemas/timestring.schema.js +0 -14
- package/dist/create-random-string.js +0 -21
- package/dist/file-exists.js +0 -34
- package/dist/getRootPackageDirname.js +0 -32
- package/dist/index.js +0 -17
- package/dist/types/config/config-loader.d.ts +0 -52
- package/dist/types/config/config-loader.types.d.ts +0 -4
- package/dist/types/config/index.d.ts +0 -3
- package/dist/types/config/predefined-schemas/connection.schema.d.ts +0 -7
- package/dist/types/config/predefined-schemas/index.d.ts +0 -57
- package/dist/types/config/predefined-schemas/mongodb-connection.schema.d.ts +0 -27
- package/dist/types/config/predefined-schemas/mysql-connection.schema.d.ts +0 -8
- package/dist/types/config/predefined-schemas/rabbit-connection.schema.d.ts +0 -8
- package/dist/types/config/predefined-schemas/redis-connection.schema.d.ts +0 -9
- package/dist/types/config/predefined-schemas/timestring.schema.d.ts +0 -2
- package/dist/types/create-random-string.d.ts +0 -5
- package/dist/types/file-exists.d.ts +0 -12
- package/dist/types/getRootPackageDirname.d.ts +0 -4
- package/dist/types/index.d.ts +0 -6
- package/dist/types/useTsconfigPaths.d.ts +0 -9
- package/dist/types/withNest.d.ts +0 -20
- package/dist/useTsconfigPaths.js +0 -34
- package/dist/withNest.js +0 -84
package/dist/useTsconfigPaths.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useTsconfigPaths = useTsconfigPaths;
|
|
4
|
-
const node_path_1 = require("node:path");
|
|
5
|
-
/**
|
|
6
|
-
* @param {UseTsconfigPathsOptions} options
|
|
7
|
-
*/
|
|
8
|
-
function useTsconfigPaths({ basePath, tsconfigPath }) {
|
|
9
|
-
let moduleAlias = null;
|
|
10
|
-
try {
|
|
11
|
-
require('module-alias/register');
|
|
12
|
-
moduleAlias = require('module-alias');
|
|
13
|
-
}
|
|
14
|
-
catch (e) {
|
|
15
|
-
throw new Error('module-alias package should be installed to use the function');
|
|
16
|
-
}
|
|
17
|
-
const tsconfig = require((0, node_path_1.resolve)(tsconfigPath)), tsconfigDirPathname = (0, node_path_1.dirname)(tsconfigPath), paths = {};
|
|
18
|
-
if (!basePath && !tsconfig?.compilerOptions?.baseUrl)
|
|
19
|
-
throw new TypeError('Either basePath option should be provided or tsconfig.json should contain compilerOptions.baseUrl property');
|
|
20
|
-
const baseUrl = basePath
|
|
21
|
-
? (0, node_path_1.resolve)(basePath)
|
|
22
|
-
: tsconfig?.compilerOptions?.baseUrl
|
|
23
|
-
? (0, node_path_1.resolve)(tsconfig.compilerOptions.baseUrl)
|
|
24
|
-
: undefined;
|
|
25
|
-
if (baseUrl === undefined)
|
|
26
|
-
throw new Error('Unable to resolve base path for tsconfig paths');
|
|
27
|
-
Object.entries((tsconfig?.compilerOptions?.paths ?? {}))
|
|
28
|
-
.forEach(([moduleName, pathArray]) => {
|
|
29
|
-
if (pathArray.length === 0)
|
|
30
|
-
return;
|
|
31
|
-
paths[moduleName] = (0, node_path_1.resolve)(tsconfigDirPathname, baseUrl, pathArray[0]);
|
|
32
|
-
});
|
|
33
|
-
moduleAlias.addAliases(paths);
|
|
34
|
-
}
|
package/dist/withNest.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.withNest = withNest;
|
|
37
|
-
/**
|
|
38
|
-
* Executes a given function within the context of a NestJS application.
|
|
39
|
-
*
|
|
40
|
-
* This asynchronous function initializes a NestJS application context using the specified
|
|
41
|
-
* module class and then executes the provided function `fn` with the application instance.
|
|
42
|
-
* The application context is automatically closed upon completion of the function execution,
|
|
43
|
-
* unless the function execution requests otherwise by invoking a callback.
|
|
44
|
-
*
|
|
45
|
-
* @param {any} moduleCls - The module class to be used for creating the NestJS application context.
|
|
46
|
-
* @param {WithNestFn} fn - The function to be executed with the NestJS application context.
|
|
47
|
-
* It receives the application instance and a callback to prevent
|
|
48
|
-
* automatic application context closure.
|
|
49
|
-
* @returns {Promise<void>} A promise that resolves when the function execution is complete.
|
|
50
|
-
* @throws - Will throw an error if the `@nestjs/core` and/or `@nestjs/common` library is not found.
|
|
51
|
-
* @throws - Will propagate any error thrown by the executed function `fn`.
|
|
52
|
-
*/
|
|
53
|
-
async function withNest(moduleCls, fn) {
|
|
54
|
-
let nestFactory = null;
|
|
55
|
-
try {
|
|
56
|
-
nestFactory = (await Promise.resolve().then(() => __importStar(require('@nestjs/core'))))?.NestFactory;
|
|
57
|
-
if (!nestFactory)
|
|
58
|
-
throw new Error('NestFactory not found');
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
throw new Error('@nestjs/core and @nestjs/common are required for this function to work');
|
|
62
|
-
}
|
|
63
|
-
const app = await nestFactory.createApplicationContext(moduleCls);
|
|
64
|
-
let closeApplication = true;
|
|
65
|
-
let _e = undefined;
|
|
66
|
-
try {
|
|
67
|
-
await fn(app, () => {
|
|
68
|
-
closeApplication = false;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
console.error('Error caught while executing the WithNestFn. Error:', e);
|
|
73
|
-
_e = e;
|
|
74
|
-
}
|
|
75
|
-
try {
|
|
76
|
-
if (closeApplication)
|
|
77
|
-
await app.close();
|
|
78
|
-
}
|
|
79
|
-
catch (e) {
|
|
80
|
-
console.error('Failed to close application. Error:', e);
|
|
81
|
-
}
|
|
82
|
-
if (_e)
|
|
83
|
-
throw _e;
|
|
84
|
-
}
|