nestjs-opensearch
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,1 +1,3 @@ | ||
import type { OpensearchClient } from './opensearch-client'; | ||
export declare function buildInjectionToken(clientName: string | symbol): string; | ||
export declare function getClientName(client: OpensearchClient): string | symbol | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildInjectionToken = void 0; | ||
exports.getClientName = exports.buildInjectionToken = void 0; | ||
const symbols_1 = require("./symbols"); | ||
function buildInjectionToken(clientName) { | ||
@@ -8,1 +9,5 @@ return `OPENSEARCH_CLIENT_${String(clientName)}`; | ||
exports.buildInjectionToken = buildInjectionToken; | ||
function getClientName(client) { | ||
return client[symbols_1.clientNameSym]; | ||
} | ||
exports.getClientName = getClientName; |
import { Client } from '@opensearch-project/opensearch'; | ||
import type { OpensearchClientOptions } from './interfaces'; | ||
import { clientNameSym } from './symbols'; | ||
export declare class OpensearchClient extends Client { | ||
readonly [clientNameSym]?: string | symbol; | ||
constructor({ clientName, ...clientOptions }: OpensearchClientOptions); | ||
} |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OpensearchClient = void 0; | ||
const opensearch_1 = require("@opensearch-project/opensearch"); | ||
const symbols_1 = require("./symbols"); | ||
class OpensearchClient extends opensearch_1.Client { | ||
constructor(_a) { | ||
var { clientName } = _a, clientOptions = __rest(_a, ["clientName"]); | ||
super(clientOptions); | ||
this[symbols_1.clientNameSym] = clientName; | ||
} | ||
} | ||
exports.OpensearchClient = OpensearchClient; |
@@ -1,4 +0,7 @@ | ||
import { DynamicModule } from '@nestjs/common'; | ||
import { DynamicModule, OnApplicationShutdown } from '@nestjs/common'; | ||
import type { OpensearchClientOptions, OpensearchAsyncClientOptions } from './interfaces'; | ||
export declare class OpensearchModule { | ||
import { OpensearchClient } from './opensearch-client'; | ||
declare type ClientMap = Map<string | symbol | undefined, OpensearchClient>; | ||
export declare class OpensearchModule implements OnApplicationShutdown { | ||
private readonly clientMap; | ||
static forRoot(options: OpensearchClientOptions | OpensearchClientOptions[]): DynamicModule; | ||
@@ -8,2 +11,5 @@ static forRootAsync(options: OpensearchAsyncClientOptions | OpensearchAsyncClientOptions[]): DynamicModule; | ||
private static buildAsyncProviders; | ||
constructor(clientMap: ClientMap); | ||
onApplicationShutdown(): Promise<void>; | ||
} | ||
export {}; |
@@ -8,2 +8,8 @@ "use strict"; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __param = (this && this.__param) || function (paramIndex, decorator) { | ||
return function (target, key) { decorator(target, key, paramIndex); } | ||
}; | ||
var OpensearchModule_1; | ||
@@ -15,4 +21,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
const opensearch_client_1 = require("./opensearch-client"); | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const symbols_1 = require("./symbols"); | ||
let OpensearchModule = OpensearchModule_1 = class OpensearchModule { | ||
constructor(clientMap) { | ||
this.clientMap = clientMap; | ||
} | ||
static forRoot(options) { | ||
@@ -38,5 +47,10 @@ const providers = OpensearchModule_1.buildProviders(options); | ||
} | ||
return options.map(option => ({ | ||
return options.map((option) => ({ | ||
provide: option.clientName ? (0, helpers_1.buildInjectionToken)(option.clientName) : opensearch_client_1.OpensearchClient, | ||
useValue: new opensearch_client_1.OpensearchClient(option), | ||
inject: [symbols_1.clientMapSym], | ||
useFactory: (clientMap) => { | ||
const client = new opensearch_client_1.OpensearchClient(option); | ||
clientMap.set(option.clientName, client); | ||
return client; | ||
}, | ||
})); | ||
@@ -48,15 +62,41 @@ } | ||
} | ||
return options.map(option => ({ | ||
return options.map((option) => ({ | ||
provide: option.clientName ? (0, helpers_1.buildInjectionToken)(option.clientName) : opensearch_client_1.OpensearchClient, | ||
inject: option.inject, | ||
useFactory: async (...args) => { | ||
inject: [symbols_1.clientMapSym, ...(option.inject || [])], | ||
useFactory: async (clientMap, ...args) => { | ||
const clientOptions = await option.useFactory(...args); | ||
return new opensearch_client_1.OpensearchClient(clientOptions); | ||
const client = new opensearch_client_1.OpensearchClient(Object.assign(Object.assign({}, clientOptions), { clientName: option.clientName })); | ||
clientMap.set(option.clientName, client); | ||
return client; | ||
}, | ||
})); | ||
} | ||
async onApplicationShutdown() { | ||
const promises = []; | ||
this.clientMap.forEach((client, clientName) => { | ||
promises.push((async () => { | ||
try { | ||
await client.close(); | ||
} | ||
catch (_a) { | ||
/* Ignore */ | ||
} | ||
this.clientMap.delete(clientName); | ||
})()); | ||
}); | ||
await Promise.all(promises); | ||
} | ||
}; | ||
OpensearchModule = OpensearchModule_1 = __decorate([ | ||
(0, common_1.Module)({}) | ||
(0, common_1.Module)({ | ||
providers: [ | ||
{ | ||
provide: symbols_1.clientMapSym, | ||
useValue: new Map(), | ||
}, | ||
], | ||
}), | ||
__param(0, (0, common_1.Inject)(symbols_1.clientMapSym)), | ||
__metadata("design:paramtypes", [Object]) | ||
], OpensearchModule); | ||
exports.OpensearchModule = OpensearchModule; |
{ | ||
"name": "nestjs-opensearch", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "neoatlan", | ||
"license": "MIT", | ||
"description": "OpenSearch (alternative to Elasticsearch) module for NestJS framework", | ||
"description": "OpenSearch module for NestJS framework", | ||
"repository": { | ||
@@ -11,5 +11,7 @@ "type": "git", | ||
}, | ||
"packageManager": "yarn@3.2.2", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"build": "yarn clean && tsc", | ||
"clean": "rimraf dist", | ||
"test": "yarn build && yarn workspaces foreach -v --include 'test-*' run test" | ||
}, | ||
@@ -25,2 +27,5 @@ "keywords": [ | ||
], | ||
"workspaces": [ | ||
"test/*" | ||
], | ||
"peerDependencies": { | ||
@@ -33,2 +38,3 @@ "@nestjs/common": "^8.0.0 || ^9.0.0", | ||
"@opensearch-project/opensearch": "^2.0.0", | ||
"@types/rimraf": "^3.0.2", | ||
"@typescript-eslint/eslint-plugin": "^5.30.6", | ||
@@ -38,2 +44,3 @@ "@typescript-eslint/parser": "^5.30.6", | ||
"reflect-metadata": "^0.1.13", | ||
"rimraf": "^3.0.2", | ||
"rxjs": "^7.5.6", | ||
@@ -40,0 +47,0 @@ "typescript": "^4.7.4" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
15259
21
245
2
10