connectfy-shared 0.0.126 → 0.0.128
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/index.cjs +113 -0
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.mjs +111 -0
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -9476,8 +9476,10 @@ __export(index_exports, {
|
|
|
9476
9476
|
MICROSERVICE_NAMES: () => MICROSERVICE_NAMES,
|
|
9477
9477
|
MODULE_TO_TOPIC_MAP: () => MODULE_TO_TOPIC_MAP,
|
|
9478
9478
|
MessageType: () => MessageType,
|
|
9479
|
+
NEO4J_DRIVER: () => NEO4J_DRIVER,
|
|
9479
9480
|
NOTIFICATION_CONTENT_MODE: () => NOTIFICATION_CONTENT_MODE,
|
|
9480
9481
|
NOTIFICATION_SOUND_MODE: () => NOTIFICATION_SOUND_MODE,
|
|
9482
|
+
Neo4jBaseRepository: () => Neo4jBaseRepository,
|
|
9481
9483
|
NotificationChannel: () => NotificationChannel,
|
|
9482
9484
|
NotificationResource: () => NotificationResource,
|
|
9483
9485
|
NotificationStatus: () => NotificationStatus,
|
|
@@ -9928,6 +9930,7 @@ var HttpStatus = /* @__PURE__ */ ((HttpStatus4) => {
|
|
|
9928
9930
|
var REDIS_KEYS = /* @__PURE__ */ ((REDIS_KEYS2) => {
|
|
9929
9931
|
REDIS_KEYS2["REDIS_CLIENT"] = "REDIS_CLIENT";
|
|
9930
9932
|
REDIS_KEYS2["KEYV_CLIENT"] = "KEYV_CLIENT";
|
|
9933
|
+
REDIS_KEYS2["REDIS_SUBSCRIBER_CLIENT"] = "REDIS_SUBSCRIBER_CLIENT";
|
|
9931
9934
|
return REDIS_KEYS2;
|
|
9932
9935
|
})(REDIS_KEYS || {});
|
|
9933
9936
|
var FileOwnerModule = /* @__PURE__ */ ((FileOwnerModule2) => {
|
|
@@ -10177,6 +10180,7 @@ var COUNTRIES = [
|
|
|
10177
10180
|
var MODULE_TO_TOPIC_MAP = {
|
|
10178
10181
|
["PROFILE_PHOTO" /* PROFILE_PHOTO */]: "profile.photo.uploaded" /* PROFILE_PHOTO_UPLOADED */
|
|
10179
10182
|
};
|
|
10183
|
+
var NEO4J_DRIVER = "NEO4J_DRIVER";
|
|
10180
10184
|
|
|
10181
10185
|
// src/i18n.ts
|
|
10182
10186
|
var import_i18next = __toESM(require("i18next"), 1);
|
|
@@ -11772,6 +11776,113 @@ var BaseRepository = class {
|
|
|
11772
11776
|
return await this.model.aggregate(pipeline).exec();
|
|
11773
11777
|
}
|
|
11774
11778
|
};
|
|
11779
|
+
|
|
11780
|
+
// src/repo/server/neo4j.base.repository.ts
|
|
11781
|
+
var import_common5 = require("@nestjs/common");
|
|
11782
|
+
var Neo4jBaseRepository = class {
|
|
11783
|
+
constructor(driver) {
|
|
11784
|
+
this.driver = driver;
|
|
11785
|
+
}
|
|
11786
|
+
/**
|
|
11787
|
+
* Helper method to run a Cypher query
|
|
11788
|
+
* @param query The Cypher query string
|
|
11789
|
+
* @param params Parameters for the query
|
|
11790
|
+
* @returns Result of the query
|
|
11791
|
+
*/
|
|
11792
|
+
async runQuery(query, params) {
|
|
11793
|
+
const session = this.driver.session();
|
|
11794
|
+
try {
|
|
11795
|
+
const result = await session.run(query, params);
|
|
11796
|
+
return result;
|
|
11797
|
+
} finally {
|
|
11798
|
+
await session.close();
|
|
11799
|
+
}
|
|
11800
|
+
}
|
|
11801
|
+
/**
|
|
11802
|
+
* Helper to write data using a transaction
|
|
11803
|
+
* @param query The Cypher query string
|
|
11804
|
+
* @param params Parameters for the query
|
|
11805
|
+
*/
|
|
11806
|
+
async writeQuery(query, params) {
|
|
11807
|
+
const session = this.driver.session();
|
|
11808
|
+
try {
|
|
11809
|
+
return await session.executeWrite((tx) => tx.run(query, params));
|
|
11810
|
+
} finally {
|
|
11811
|
+
await session.close();
|
|
11812
|
+
}
|
|
11813
|
+
}
|
|
11814
|
+
/**
|
|
11815
|
+
* Helper to read data using a transaction
|
|
11816
|
+
* @param query The Cypher query string
|
|
11817
|
+
* @param params Parameters for the query
|
|
11818
|
+
*/
|
|
11819
|
+
async readQuery(query, params) {
|
|
11820
|
+
const session = this.driver.session();
|
|
11821
|
+
try {
|
|
11822
|
+
return await session.executeRead((tx) => tx.run(query, params));
|
|
11823
|
+
} finally {
|
|
11824
|
+
await session.close();
|
|
11825
|
+
}
|
|
11826
|
+
}
|
|
11827
|
+
// ================================================
|
|
11828
|
+
// GENERIC CRUD HELPERS
|
|
11829
|
+
// ================================================
|
|
11830
|
+
/**
|
|
11831
|
+
* Insert a single node
|
|
11832
|
+
*/
|
|
11833
|
+
async createNode(label, data) {
|
|
11834
|
+
const query = `CREATE (n:${label}) SET n = $data RETURN n`;
|
|
11835
|
+
return this.writeQuery(query, { data });
|
|
11836
|
+
}
|
|
11837
|
+
/**
|
|
11838
|
+
* Update a node by its ID (or another unique identifier)
|
|
11839
|
+
*/
|
|
11840
|
+
async updateNode(label, idField, idValue, data) {
|
|
11841
|
+
const query = `
|
|
11842
|
+
MERGE (n:${label} {${idField}: $idValue})
|
|
11843
|
+
SET n += $data
|
|
11844
|
+
RETURN n
|
|
11845
|
+
`;
|
|
11846
|
+
return this.writeQuery(query, { idValue, data });
|
|
11847
|
+
}
|
|
11848
|
+
/**
|
|
11849
|
+
* Delete a node by its ID (DETACH DELETE removes all connected relationships too)
|
|
11850
|
+
*/
|
|
11851
|
+
async deleteNode(label, idField, idValue) {
|
|
11852
|
+
const query = `
|
|
11853
|
+
MATCH (n:${label} {${idField}: $idValue})
|
|
11854
|
+
DETACH DELETE n
|
|
11855
|
+
`;
|
|
11856
|
+
return this.writeQuery(query, { idValue });
|
|
11857
|
+
}
|
|
11858
|
+
/**
|
|
11859
|
+
* Insert multiple nodes at once using UNWIND (highly optimized)
|
|
11860
|
+
*/
|
|
11861
|
+
async insertManyNodes(label, dataList) {
|
|
11862
|
+
const query = `
|
|
11863
|
+
UNWIND $batch AS row
|
|
11864
|
+
CREATE (n:${label})
|
|
11865
|
+
SET n = row
|
|
11866
|
+
RETURN n
|
|
11867
|
+
`;
|
|
11868
|
+
return this.writeQuery(query, { batch: dataList });
|
|
11869
|
+
}
|
|
11870
|
+
/**
|
|
11871
|
+
* Extract properties from a single Neo4j Record node
|
|
11872
|
+
* @param record Neo4j Record
|
|
11873
|
+
* @param nodeName The variable name used in the Cypher query (e.g. 'u' in 'RETURN u')
|
|
11874
|
+
*/
|
|
11875
|
+
extractNode(record, nodeName) {
|
|
11876
|
+
if (!record || !record.has(nodeName)) {
|
|
11877
|
+
return null;
|
|
11878
|
+
}
|
|
11879
|
+
const node = record.get(nodeName);
|
|
11880
|
+
return node.properties;
|
|
11881
|
+
}
|
|
11882
|
+
};
|
|
11883
|
+
Neo4jBaseRepository = __decorateClass([
|
|
11884
|
+
(0, import_common5.Injectable)()
|
|
11885
|
+
], Neo4jBaseRepository);
|
|
11775
11886
|
// Annotate the CommonJS export names for ESM import in node:
|
|
11776
11887
|
0 && (module.exports = {
|
|
11777
11888
|
AllExceptionsFilter,
|
|
@@ -11813,8 +11924,10 @@ var BaseRepository = class {
|
|
|
11813
11924
|
MICROSERVICE_NAMES,
|
|
11814
11925
|
MODULE_TO_TOPIC_MAP,
|
|
11815
11926
|
MessageType,
|
|
11927
|
+
NEO4J_DRIVER,
|
|
11816
11928
|
NOTIFICATION_CONTENT_MODE,
|
|
11817
11929
|
NOTIFICATION_SOUND_MODE,
|
|
11930
|
+
Neo4jBaseRepository,
|
|
11818
11931
|
NotificationChannel,
|
|
11819
11932
|
NotificationResource,
|
|
11820
11933
|
NotificationStatus,
|
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,7 @@ import { ClassConstructor } from 'class-transformer';
|
|
|
6
6
|
import { ExceptionFilter } from '@nestjs/common';
|
|
7
7
|
import * as rxjs from 'rxjs';
|
|
8
8
|
import { Observable } from 'rxjs';
|
|
9
|
+
import { Driver, Result, Record as Record$1 } from 'neo4j-driver';
|
|
9
10
|
|
|
10
11
|
declare class BaseException extends RpcException {
|
|
11
12
|
constructor(messageOrFunc?: string | string[] | ((...args: any[]) => string | string[]), statusCode?: HttpStatus, additional?: Record<string, any>);
|
|
@@ -360,7 +361,8 @@ declare enum HttpStatus {
|
|
|
360
361
|
}
|
|
361
362
|
declare enum REDIS_KEYS {
|
|
362
363
|
REDIS_CLIENT = "REDIS_CLIENT",
|
|
363
|
-
KEYV_CLIENT = "KEYV_CLIENT"
|
|
364
|
+
KEYV_CLIENT = "KEYV_CLIENT",
|
|
365
|
+
REDIS_SUBSCRIBER_CLIENT = "REDIS_SUBSCRIBER_CLIENT"
|
|
364
366
|
}
|
|
365
367
|
declare enum FileOwnerModule {
|
|
366
368
|
PROFILE_PHOTO = "PROFILE_PHOTO"
|
|
@@ -561,6 +563,7 @@ declare const CACHE_KEYS: {
|
|
|
561
563
|
};
|
|
562
564
|
declare const COUNTRIES: ICountry[];
|
|
563
565
|
declare const MODULE_TO_TOPIC_MAP: Record<FileOwnerModule, FileUploadTopic>;
|
|
566
|
+
declare const NEO4J_DRIVER = "NEO4J_DRIVER";
|
|
564
567
|
|
|
565
568
|
declare const getLang: (args: ValidationArguments) => LANGUAGE;
|
|
566
569
|
declare const validationMessage: ({ args, type, params, }: IValidateMessageOptions) => string;
|
|
@@ -886,4 +889,17 @@ declare abstract class BaseRepository<TDocument extends Document<any, any, any>,
|
|
|
886
889
|
aggregate<R = any>(pipeline: PipelineStage[]): Promise<R[]>;
|
|
887
890
|
}
|
|
888
891
|
|
|
889
|
-
|
|
892
|
+
declare abstract class Neo4jBaseRepository {
|
|
893
|
+
protected readonly driver: Driver;
|
|
894
|
+
protected constructor(driver: Driver);
|
|
895
|
+
protected runQuery(query: string, params?: any): Promise<Result>;
|
|
896
|
+
protected writeQuery(query: string, params?: any): Promise<Result>;
|
|
897
|
+
protected readQuery(query: string, params?: any): Promise<Result>;
|
|
898
|
+
protected createNode(label: string, data: Record<string, any>): Promise<Result>;
|
|
899
|
+
protected updateNode(label: string, idField: string, idValue: any, data: Record<string, any>): Promise<Result>;
|
|
900
|
+
protected deleteNode(label: string, idField: string, idValue: any): Promise<Result>;
|
|
901
|
+
protected insertManyNodes(label: string, dataList: Record<string, any>[]): Promise<Result>;
|
|
902
|
+
protected extractNode<T>(record: Record$1, nodeName: string): T | null;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
export { AllExceptionsFilter, AvatarFormats, BROWSER_TYPE, BaseException, BaseFindDto, BaseRemoveAllDto, BaseRemoveDto, BaseRepository, CACHE_KEYS, CHECK_UNIQUE_FIELD, CLS_KEYS, COLLECTIONS, COUNTRIES, ChatParticiantRole, ChatType, DATE_FORMAT, DELETE_REASON, DELETE_REASON_CODE, DEVICE_TYPE, EXPIRE_DATES, ExceptionMessages, FIELD_TRANSFORMER_REGISTRY, FIELD_TYPE, FIELD_VALIDATOR_REGISTRY, FORGOT_PASSWORD_IDENTIFIER_TYPE, FieldValidator, type FieldValidatorOptions, FileOwnerModule, FileUploadTopic, FriendshipRequestType, FriendshipStatus, GENDER, GOOGLE_AUTH_LOGIN_TYPE, HttpStatus, type IAccount, type IArrayFieldOptions, type IAvatar, type IBaseFieldOptions, type IBaseRepositoryInterface, type IBaseRepositoryOptions, type IBaseRepositoryRemoveOptions, type IBaseRepositoryUpdateOptions, type IBooleanFieldOptions, type ICountry, IDENTIFIER_TYPE, type IDateFieldOptions, type IDefaultAvatar, type IEmitTcpWithContextClientParams, type IEmitWithContextClientParams, type IEnumFieldOptions, type IFindAllResponse, type IGeneralSettings, type ILoggedUser, type INotificationSettings, type INumberFieldOptions, type IObjectFieldOptions, type IPhoneNumber, type IPrivacySettings, type IRemoveAllResponse, type IResponse, type IReturnedUser, type ISendWithContextClientParams, type IStringFieldOptions, type ITimeZone, type IValidateMessageOptions, LANGUAGE, LOCAL_STORAGE_KEYS, MICROSERVICE_NAMES, MODULE_TO_TOPIC_MAP, MessageType, NEO4J_DRIVER, NOTIFICATION_CONTENT_MODE, NOTIFICATION_SOUND_MODE, Neo4jBaseRepository, NotificationChannel, NotificationResource, NotificationStatus, NotificationType, OS_TYPE, PHONE_NUMBER_ACTION, PRIVACY_SETTINGS_CHOICE, PROVIDER, PopulateOption, ProfilePhotoUpdateAction, Push_DELIVERY_STATUS, REDIS_KEYS, REDUCER_PATH, RESOURCE, ROLE, SOCIAL_LINK_PLATFORM, STARTUP_PAGE, TAG_TYPES, THEME, TIME_DIFFERENCE_TYPE, TIME_FORMAT, TOKEN_TYPE, TWO_FACTOR_ACTION, USER_STATUS, VALIDATION_TYPE, accountDeletedMessage, arrayTransform, booleanTransform, changeEmailMessage, commitKafkaOffset, dateTransform, decryptPayload, deleteAccountMessage, emailNotFoundMessage, emitWithContext, emitWithContextTcp, encryptPayload, enumTransform, forgotPasswordMessage, getLang, googleSignInMessage, lowerCaseTranform, numberTransform, objectTransform, sendWithContext, shouldShowField, signupVerifyMessage, stringTransform, twoFactorVerifyMessage, upperCaseTranform, validationMessage, verifyYourselfMessage };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { ClassConstructor } from 'class-transformer';
|
|
|
6
6
|
import { ExceptionFilter } from '@nestjs/common';
|
|
7
7
|
import * as rxjs from 'rxjs';
|
|
8
8
|
import { Observable } from 'rxjs';
|
|
9
|
+
import { Driver, Result, Record as Record$1 } from 'neo4j-driver';
|
|
9
10
|
|
|
10
11
|
declare class BaseException extends RpcException {
|
|
11
12
|
constructor(messageOrFunc?: string | string[] | ((...args: any[]) => string | string[]), statusCode?: HttpStatus, additional?: Record<string, any>);
|
|
@@ -360,7 +361,8 @@ declare enum HttpStatus {
|
|
|
360
361
|
}
|
|
361
362
|
declare enum REDIS_KEYS {
|
|
362
363
|
REDIS_CLIENT = "REDIS_CLIENT",
|
|
363
|
-
KEYV_CLIENT = "KEYV_CLIENT"
|
|
364
|
+
KEYV_CLIENT = "KEYV_CLIENT",
|
|
365
|
+
REDIS_SUBSCRIBER_CLIENT = "REDIS_SUBSCRIBER_CLIENT"
|
|
364
366
|
}
|
|
365
367
|
declare enum FileOwnerModule {
|
|
366
368
|
PROFILE_PHOTO = "PROFILE_PHOTO"
|
|
@@ -561,6 +563,7 @@ declare const CACHE_KEYS: {
|
|
|
561
563
|
};
|
|
562
564
|
declare const COUNTRIES: ICountry[];
|
|
563
565
|
declare const MODULE_TO_TOPIC_MAP: Record<FileOwnerModule, FileUploadTopic>;
|
|
566
|
+
declare const NEO4J_DRIVER = "NEO4J_DRIVER";
|
|
564
567
|
|
|
565
568
|
declare const getLang: (args: ValidationArguments) => LANGUAGE;
|
|
566
569
|
declare const validationMessage: ({ args, type, params, }: IValidateMessageOptions) => string;
|
|
@@ -886,4 +889,17 @@ declare abstract class BaseRepository<TDocument extends Document<any, any, any>,
|
|
|
886
889
|
aggregate<R = any>(pipeline: PipelineStage[]): Promise<R[]>;
|
|
887
890
|
}
|
|
888
891
|
|
|
889
|
-
|
|
892
|
+
declare abstract class Neo4jBaseRepository {
|
|
893
|
+
protected readonly driver: Driver;
|
|
894
|
+
protected constructor(driver: Driver);
|
|
895
|
+
protected runQuery(query: string, params?: any): Promise<Result>;
|
|
896
|
+
protected writeQuery(query: string, params?: any): Promise<Result>;
|
|
897
|
+
protected readQuery(query: string, params?: any): Promise<Result>;
|
|
898
|
+
protected createNode(label: string, data: Record<string, any>): Promise<Result>;
|
|
899
|
+
protected updateNode(label: string, idField: string, idValue: any, data: Record<string, any>): Promise<Result>;
|
|
900
|
+
protected deleteNode(label: string, idField: string, idValue: any): Promise<Result>;
|
|
901
|
+
protected insertManyNodes(label: string, dataList: Record<string, any>[]): Promise<Result>;
|
|
902
|
+
protected extractNode<T>(record: Record$1, nodeName: string): T | null;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
export { AllExceptionsFilter, AvatarFormats, BROWSER_TYPE, BaseException, BaseFindDto, BaseRemoveAllDto, BaseRemoveDto, BaseRepository, CACHE_KEYS, CHECK_UNIQUE_FIELD, CLS_KEYS, COLLECTIONS, COUNTRIES, ChatParticiantRole, ChatType, DATE_FORMAT, DELETE_REASON, DELETE_REASON_CODE, DEVICE_TYPE, EXPIRE_DATES, ExceptionMessages, FIELD_TRANSFORMER_REGISTRY, FIELD_TYPE, FIELD_VALIDATOR_REGISTRY, FORGOT_PASSWORD_IDENTIFIER_TYPE, FieldValidator, type FieldValidatorOptions, FileOwnerModule, FileUploadTopic, FriendshipRequestType, FriendshipStatus, GENDER, GOOGLE_AUTH_LOGIN_TYPE, HttpStatus, type IAccount, type IArrayFieldOptions, type IAvatar, type IBaseFieldOptions, type IBaseRepositoryInterface, type IBaseRepositoryOptions, type IBaseRepositoryRemoveOptions, type IBaseRepositoryUpdateOptions, type IBooleanFieldOptions, type ICountry, IDENTIFIER_TYPE, type IDateFieldOptions, type IDefaultAvatar, type IEmitTcpWithContextClientParams, type IEmitWithContextClientParams, type IEnumFieldOptions, type IFindAllResponse, type IGeneralSettings, type ILoggedUser, type INotificationSettings, type INumberFieldOptions, type IObjectFieldOptions, type IPhoneNumber, type IPrivacySettings, type IRemoveAllResponse, type IResponse, type IReturnedUser, type ISendWithContextClientParams, type IStringFieldOptions, type ITimeZone, type IValidateMessageOptions, LANGUAGE, LOCAL_STORAGE_KEYS, MICROSERVICE_NAMES, MODULE_TO_TOPIC_MAP, MessageType, NEO4J_DRIVER, NOTIFICATION_CONTENT_MODE, NOTIFICATION_SOUND_MODE, Neo4jBaseRepository, NotificationChannel, NotificationResource, NotificationStatus, NotificationType, OS_TYPE, PHONE_NUMBER_ACTION, PRIVACY_SETTINGS_CHOICE, PROVIDER, PopulateOption, ProfilePhotoUpdateAction, Push_DELIVERY_STATUS, REDIS_KEYS, REDUCER_PATH, RESOURCE, ROLE, SOCIAL_LINK_PLATFORM, STARTUP_PAGE, TAG_TYPES, THEME, TIME_DIFFERENCE_TYPE, TIME_FORMAT, TOKEN_TYPE, TWO_FACTOR_ACTION, USER_STATUS, VALIDATION_TYPE, accountDeletedMessage, arrayTransform, booleanTransform, changeEmailMessage, commitKafkaOffset, dateTransform, decryptPayload, deleteAccountMessage, emailNotFoundMessage, emitWithContext, emitWithContextTcp, encryptPayload, enumTransform, forgotPasswordMessage, getLang, googleSignInMessage, lowerCaseTranform, numberTransform, objectTransform, sendWithContext, shouldShowField, signupVerifyMessage, stringTransform, twoFactorVerifyMessage, upperCaseTranform, validationMessage, verifyYourselfMessage };
|
package/dist/index.mjs
CHANGED
|
@@ -9824,6 +9824,7 @@ var HttpStatus = /* @__PURE__ */ ((HttpStatus4) => {
|
|
|
9824
9824
|
var REDIS_KEYS = /* @__PURE__ */ ((REDIS_KEYS2) => {
|
|
9825
9825
|
REDIS_KEYS2["REDIS_CLIENT"] = "REDIS_CLIENT";
|
|
9826
9826
|
REDIS_KEYS2["KEYV_CLIENT"] = "KEYV_CLIENT";
|
|
9827
|
+
REDIS_KEYS2["REDIS_SUBSCRIBER_CLIENT"] = "REDIS_SUBSCRIBER_CLIENT";
|
|
9827
9828
|
return REDIS_KEYS2;
|
|
9828
9829
|
})(REDIS_KEYS || {});
|
|
9829
9830
|
var FileOwnerModule = /* @__PURE__ */ ((FileOwnerModule2) => {
|
|
@@ -10073,6 +10074,7 @@ var COUNTRIES = [
|
|
|
10073
10074
|
var MODULE_TO_TOPIC_MAP = {
|
|
10074
10075
|
["PROFILE_PHOTO" /* PROFILE_PHOTO */]: "profile.photo.uploaded" /* PROFILE_PHOTO_UPLOADED */
|
|
10075
10076
|
};
|
|
10077
|
+
var NEO4J_DRIVER = "NEO4J_DRIVER";
|
|
10076
10078
|
|
|
10077
10079
|
// src/i18n.ts
|
|
10078
10080
|
import i18next from "i18next";
|
|
@@ -11710,6 +11712,113 @@ var BaseRepository = class {
|
|
|
11710
11712
|
return await this.model.aggregate(pipeline).exec();
|
|
11711
11713
|
}
|
|
11712
11714
|
};
|
|
11715
|
+
|
|
11716
|
+
// src/repo/server/neo4j.base.repository.ts
|
|
11717
|
+
import { Injectable } from "@nestjs/common";
|
|
11718
|
+
var Neo4jBaseRepository = class {
|
|
11719
|
+
constructor(driver) {
|
|
11720
|
+
this.driver = driver;
|
|
11721
|
+
}
|
|
11722
|
+
/**
|
|
11723
|
+
* Helper method to run a Cypher query
|
|
11724
|
+
* @param query The Cypher query string
|
|
11725
|
+
* @param params Parameters for the query
|
|
11726
|
+
* @returns Result of the query
|
|
11727
|
+
*/
|
|
11728
|
+
async runQuery(query, params) {
|
|
11729
|
+
const session = this.driver.session();
|
|
11730
|
+
try {
|
|
11731
|
+
const result = await session.run(query, params);
|
|
11732
|
+
return result;
|
|
11733
|
+
} finally {
|
|
11734
|
+
await session.close();
|
|
11735
|
+
}
|
|
11736
|
+
}
|
|
11737
|
+
/**
|
|
11738
|
+
* Helper to write data using a transaction
|
|
11739
|
+
* @param query The Cypher query string
|
|
11740
|
+
* @param params Parameters for the query
|
|
11741
|
+
*/
|
|
11742
|
+
async writeQuery(query, params) {
|
|
11743
|
+
const session = this.driver.session();
|
|
11744
|
+
try {
|
|
11745
|
+
return await session.executeWrite((tx) => tx.run(query, params));
|
|
11746
|
+
} finally {
|
|
11747
|
+
await session.close();
|
|
11748
|
+
}
|
|
11749
|
+
}
|
|
11750
|
+
/**
|
|
11751
|
+
* Helper to read data using a transaction
|
|
11752
|
+
* @param query The Cypher query string
|
|
11753
|
+
* @param params Parameters for the query
|
|
11754
|
+
*/
|
|
11755
|
+
async readQuery(query, params) {
|
|
11756
|
+
const session = this.driver.session();
|
|
11757
|
+
try {
|
|
11758
|
+
return await session.executeRead((tx) => tx.run(query, params));
|
|
11759
|
+
} finally {
|
|
11760
|
+
await session.close();
|
|
11761
|
+
}
|
|
11762
|
+
}
|
|
11763
|
+
// ================================================
|
|
11764
|
+
// GENERIC CRUD HELPERS
|
|
11765
|
+
// ================================================
|
|
11766
|
+
/**
|
|
11767
|
+
* Insert a single node
|
|
11768
|
+
*/
|
|
11769
|
+
async createNode(label, data) {
|
|
11770
|
+
const query = `CREATE (n:${label}) SET n = $data RETURN n`;
|
|
11771
|
+
return this.writeQuery(query, { data });
|
|
11772
|
+
}
|
|
11773
|
+
/**
|
|
11774
|
+
* Update a node by its ID (or another unique identifier)
|
|
11775
|
+
*/
|
|
11776
|
+
async updateNode(label, idField, idValue, data) {
|
|
11777
|
+
const query = `
|
|
11778
|
+
MERGE (n:${label} {${idField}: $idValue})
|
|
11779
|
+
SET n += $data
|
|
11780
|
+
RETURN n
|
|
11781
|
+
`;
|
|
11782
|
+
return this.writeQuery(query, { idValue, data });
|
|
11783
|
+
}
|
|
11784
|
+
/**
|
|
11785
|
+
* Delete a node by its ID (DETACH DELETE removes all connected relationships too)
|
|
11786
|
+
*/
|
|
11787
|
+
async deleteNode(label, idField, idValue) {
|
|
11788
|
+
const query = `
|
|
11789
|
+
MATCH (n:${label} {${idField}: $idValue})
|
|
11790
|
+
DETACH DELETE n
|
|
11791
|
+
`;
|
|
11792
|
+
return this.writeQuery(query, { idValue });
|
|
11793
|
+
}
|
|
11794
|
+
/**
|
|
11795
|
+
* Insert multiple nodes at once using UNWIND (highly optimized)
|
|
11796
|
+
*/
|
|
11797
|
+
async insertManyNodes(label, dataList) {
|
|
11798
|
+
const query = `
|
|
11799
|
+
UNWIND $batch AS row
|
|
11800
|
+
CREATE (n:${label})
|
|
11801
|
+
SET n = row
|
|
11802
|
+
RETURN n
|
|
11803
|
+
`;
|
|
11804
|
+
return this.writeQuery(query, { batch: dataList });
|
|
11805
|
+
}
|
|
11806
|
+
/**
|
|
11807
|
+
* Extract properties from a single Neo4j Record node
|
|
11808
|
+
* @param record Neo4j Record
|
|
11809
|
+
* @param nodeName The variable name used in the Cypher query (e.g. 'u' in 'RETURN u')
|
|
11810
|
+
*/
|
|
11811
|
+
extractNode(record, nodeName) {
|
|
11812
|
+
if (!record || !record.has(nodeName)) {
|
|
11813
|
+
return null;
|
|
11814
|
+
}
|
|
11815
|
+
const node = record.get(nodeName);
|
|
11816
|
+
return node.properties;
|
|
11817
|
+
}
|
|
11818
|
+
};
|
|
11819
|
+
Neo4jBaseRepository = __decorateClass([
|
|
11820
|
+
Injectable()
|
|
11821
|
+
], Neo4jBaseRepository);
|
|
11713
11822
|
export {
|
|
11714
11823
|
AllExceptionsFilter,
|
|
11715
11824
|
AvatarFormats,
|
|
@@ -11750,8 +11859,10 @@ export {
|
|
|
11750
11859
|
MICROSERVICE_NAMES,
|
|
11751
11860
|
MODULE_TO_TOPIC_MAP,
|
|
11752
11861
|
MessageType,
|
|
11862
|
+
NEO4J_DRIVER,
|
|
11753
11863
|
NOTIFICATION_CONTENT_MODE,
|
|
11754
11864
|
NOTIFICATION_SOUND_MODE,
|
|
11865
|
+
Neo4jBaseRepository,
|
|
11755
11866
|
NotificationChannel,
|
|
11756
11867
|
NotificationResource,
|
|
11757
11868
|
NotificationStatus,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "connectfy-shared",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.128",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"class-validator": "^0.14.3",
|
|
37
37
|
"connectfy-i18n": "^0.0.45",
|
|
38
38
|
"mongoose": "^8.18.1",
|
|
39
|
+
"neo4j-driver": "^6.2.0",
|
|
39
40
|
"nestjs-cls": "^6.2.0"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|