@cristian-israel/giganet_lib_conecta 1.0.89 → 1.0.91

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.d.mts CHANGED
@@ -6,6 +6,8 @@ import * as mongoose from 'mongoose';
6
6
  import { HydratedDocument, InferSchemaType, Schema, Types, Model as Model$1 } from 'mongoose';
7
7
  import { GenerateContentRequest as GenerateContentRequest$1, GenerationConfig as GenerationConfig$1, SafetySetting as SafetySetting$1, GoogleGenerativeAI } from '@google/generative-ai';
8
8
  import * as bson from 'bson';
9
+ import * as Redis from 'ioredis';
10
+ import Redis__default from 'ioredis';
9
11
 
10
12
  type LogLevel = "INFO" | "ERROR" | "WARN";
11
13
  type LogerParams = {
@@ -37472,6 +37474,7 @@ declare const schemas$4: {
37472
37474
  id_ixc_soft: number;
37473
37475
  is_admin: boolean;
37474
37476
  permissions: string[];
37477
+ permissions_socket: string[];
37475
37478
  permissions_front: string[];
37476
37479
  } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
37477
37480
  email: string;
@@ -37481,6 +37484,7 @@ declare const schemas$4: {
37481
37484
  id_ixc_soft: number;
37482
37485
  is_admin: boolean;
37483
37486
  permissions: string[];
37487
+ permissions_socket: string[];
37484
37488
  permissions_front: string[];
37485
37489
  } & mongoose.DefaultTimestampProps, {
37486
37490
  id: string;
@@ -37494,6 +37498,7 @@ declare const schemas$4: {
37494
37498
  id_ixc_soft: number;
37495
37499
  is_admin: boolean;
37496
37500
  permissions: string[];
37501
+ permissions_socket: string[];
37497
37502
  permissions_front: string[];
37498
37503
  } & mongoose.DefaultTimestampProps & {
37499
37504
  _id: mongoose.Types.ObjectId;
@@ -37509,6 +37514,7 @@ declare const schemas$4: {
37509
37514
  id_ixc_soft: number;
37510
37515
  is_admin: boolean;
37511
37516
  permissions: string[];
37517
+ permissions_socket: string[];
37512
37518
  permissions_front: string[];
37513
37519
  createdAt: NativeDate;
37514
37520
  updatedAt: NativeDate;
@@ -38308,4 +38314,68 @@ declare class GigacenterMongoService {
38308
38314
  getCollection<K extends keyof GigacenterMongoCollectionsModels>(key: K): GigacenterMongoCollectionsModels[K];
38309
38315
  }
38310
38316
 
38311
- export { type ExpensesFleetMongoCollectionsModels, type ExpensesFleetMongoDocuments, ExpensesFleetMongoService, GeminiLIBClient, geminiLib_types as GeminiLIBTypes, type GigacenterMongoCollectionsModels, type GigacenterMongoDocuments, GigacenterMongoService, IXCSoftAPIClient, ixcSoftApi_types as IXCSoftAPITypes, type IXCSoftMysqlModels, type IXCSoftMysqlModelsAttributes, IXCSoftMysqlService, type MCPGiganetMongoCollectionsModels, type MCPGiganetMongoDocuments, MCPGiganetMongoService, NtfyAPIClient, ntfyApi_types as NtfyAPITypes, type OPASuiteMongoCollectionsModels, type OPASuiteMongoDocuments, OPASuiteMongoService, RoutinesAPIClient, routinesApi_types as RoutinesAPITypes, type RoutinesMongoCollectionsModels, type RoutinesMongoDocuments, RoutinesMongoService, type RoutinesMysqlModels, type RoutinesMysqlModelsAttributes, RoutinesMysqlService, type ToolsMongoCollectionsModels, type ToolsMongoDocuments, ToolsMongoService, loger, printSignature };
38317
+ type PonsRow = {
38318
+ id: number;
38319
+ interface: string;
38320
+ transmissor: string;
38321
+ slot: number;
38322
+ numero: number;
38323
+ vlan: string;
38324
+ onus_vinculadas: number;
38325
+ onus_autorizadas: number;
38326
+ sinal_alto: number;
38327
+ os_pendentes: number;
38328
+ os_recolha: number;
38329
+ rompimentos: number;
38330
+ offlines_menos_3_meses: number;
38331
+ };
38332
+ type PonsSnapshot = {
38333
+ rows: PonsRow[];
38334
+ updatedAt: string;
38335
+ updatedAtStatic?: string;
38336
+ };
38337
+ type PonsUpdateMeta = {
38338
+ updatedAt: string;
38339
+ };
38340
+ type PonsStore = {
38341
+ getSnapshot(): Promise<PonsSnapshot | null>;
38342
+ setSnapshot(snapshot: PonsSnapshot): Promise<void>;
38343
+ publishUpdate(meta: PonsUpdateMeta): Promise<void>;
38344
+ subscribe(onUpdate: (meta: PonsUpdateMeta) => void): () => void;
38345
+ };
38346
+
38347
+ declare function createPonsStore(client: Redis__default, basePrefix: string): PonsStore;
38348
+
38349
+ declare const storeFactories: {
38350
+ readonly pons: typeof createPonsStore;
38351
+ };
38352
+
38353
+ type RoutinesRedisStores = {
38354
+ [K in keyof typeof storeFactories]: ReturnType<(typeof storeFactories)[K]>;
38355
+ };
38356
+
38357
+ type RedisConnectionConfig = {
38358
+ host: string;
38359
+ port: number;
38360
+ password?: string;
38361
+ };
38362
+
38363
+ declare class RoutinesRedisService {
38364
+ private static instance;
38365
+ private connection;
38366
+ private initialized;
38367
+ private constructor();
38368
+ private notInitialized;
38369
+ /** Retorna a instância singleton */
38370
+ static getInstance(): RoutinesRedisService;
38371
+ /** Inicializa a conexão e stores */
38372
+ init(config: RedisConnectionConfig): Promise<void>;
38373
+ /** Retorna o client ioredis */
38374
+ getClient(): Redis.default;
38375
+ /** Retorna stores tipados */
38376
+ get stores(): RoutinesRedisStores;
38377
+ /** Retorna um store específico tipado */
38378
+ getStore<K extends keyof RoutinesRedisStores>(key: K): RoutinesRedisStores[K];
38379
+ }
38380
+
38381
+ export { type ExpensesFleetMongoCollectionsModels, type ExpensesFleetMongoDocuments, ExpensesFleetMongoService, GeminiLIBClient, geminiLib_types as GeminiLIBTypes, type GigacenterMongoCollectionsModels, type GigacenterMongoDocuments, GigacenterMongoService, IXCSoftAPIClient, ixcSoftApi_types as IXCSoftAPITypes, type IXCSoftMysqlModels, type IXCSoftMysqlModelsAttributes, IXCSoftMysqlService, type MCPGiganetMongoCollectionsModels, type MCPGiganetMongoDocuments, MCPGiganetMongoService, NtfyAPIClient, ntfyApi_types as NtfyAPITypes, type OPASuiteMongoCollectionsModels, type OPASuiteMongoDocuments, OPASuiteMongoService, type PonsRow, type PonsSnapshot, type PonsStore, type PonsUpdateMeta, RoutinesAPIClient, routinesApi_types as RoutinesAPITypes, type RoutinesMongoCollectionsModels, type RoutinesMongoDocuments, RoutinesMongoService, type RoutinesMysqlModels, type RoutinesMysqlModelsAttributes, RoutinesMysqlService, RoutinesRedisService, type RoutinesRedisStores, type ToolsMongoCollectionsModels, type ToolsMongoDocuments, ToolsMongoService, loger, printSignature };
package/dist/index.d.ts CHANGED
@@ -6,6 +6,8 @@ import * as mongoose from 'mongoose';
6
6
  import { HydratedDocument, InferSchemaType, Schema, Types, Model as Model$1 } from 'mongoose';
7
7
  import { GenerateContentRequest as GenerateContentRequest$1, GenerationConfig as GenerationConfig$1, SafetySetting as SafetySetting$1, GoogleGenerativeAI } from '@google/generative-ai';
8
8
  import * as bson from 'bson';
9
+ import * as Redis from 'ioredis';
10
+ import Redis__default from 'ioredis';
9
11
 
10
12
  type LogLevel = "INFO" | "ERROR" | "WARN";
11
13
  type LogerParams = {
@@ -37472,6 +37474,7 @@ declare const schemas$4: {
37472
37474
  id_ixc_soft: number;
37473
37475
  is_admin: boolean;
37474
37476
  permissions: string[];
37477
+ permissions_socket: string[];
37475
37478
  permissions_front: string[];
37476
37479
  } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
37477
37480
  email: string;
@@ -37481,6 +37484,7 @@ declare const schemas$4: {
37481
37484
  id_ixc_soft: number;
37482
37485
  is_admin: boolean;
37483
37486
  permissions: string[];
37487
+ permissions_socket: string[];
37484
37488
  permissions_front: string[];
37485
37489
  } & mongoose.DefaultTimestampProps, {
37486
37490
  id: string;
@@ -37494,6 +37498,7 @@ declare const schemas$4: {
37494
37498
  id_ixc_soft: number;
37495
37499
  is_admin: boolean;
37496
37500
  permissions: string[];
37501
+ permissions_socket: string[];
37497
37502
  permissions_front: string[];
37498
37503
  } & mongoose.DefaultTimestampProps & {
37499
37504
  _id: mongoose.Types.ObjectId;
@@ -37509,6 +37514,7 @@ declare const schemas$4: {
37509
37514
  id_ixc_soft: number;
37510
37515
  is_admin: boolean;
37511
37516
  permissions: string[];
37517
+ permissions_socket: string[];
37512
37518
  permissions_front: string[];
37513
37519
  createdAt: NativeDate;
37514
37520
  updatedAt: NativeDate;
@@ -38308,4 +38314,68 @@ declare class GigacenterMongoService {
38308
38314
  getCollection<K extends keyof GigacenterMongoCollectionsModels>(key: K): GigacenterMongoCollectionsModels[K];
38309
38315
  }
38310
38316
 
38311
- export { type ExpensesFleetMongoCollectionsModels, type ExpensesFleetMongoDocuments, ExpensesFleetMongoService, GeminiLIBClient, geminiLib_types as GeminiLIBTypes, type GigacenterMongoCollectionsModels, type GigacenterMongoDocuments, GigacenterMongoService, IXCSoftAPIClient, ixcSoftApi_types as IXCSoftAPITypes, type IXCSoftMysqlModels, type IXCSoftMysqlModelsAttributes, IXCSoftMysqlService, type MCPGiganetMongoCollectionsModels, type MCPGiganetMongoDocuments, MCPGiganetMongoService, NtfyAPIClient, ntfyApi_types as NtfyAPITypes, type OPASuiteMongoCollectionsModels, type OPASuiteMongoDocuments, OPASuiteMongoService, RoutinesAPIClient, routinesApi_types as RoutinesAPITypes, type RoutinesMongoCollectionsModels, type RoutinesMongoDocuments, RoutinesMongoService, type RoutinesMysqlModels, type RoutinesMysqlModelsAttributes, RoutinesMysqlService, type ToolsMongoCollectionsModels, type ToolsMongoDocuments, ToolsMongoService, loger, printSignature };
38317
+ type PonsRow = {
38318
+ id: number;
38319
+ interface: string;
38320
+ transmissor: string;
38321
+ slot: number;
38322
+ numero: number;
38323
+ vlan: string;
38324
+ onus_vinculadas: number;
38325
+ onus_autorizadas: number;
38326
+ sinal_alto: number;
38327
+ os_pendentes: number;
38328
+ os_recolha: number;
38329
+ rompimentos: number;
38330
+ offlines_menos_3_meses: number;
38331
+ };
38332
+ type PonsSnapshot = {
38333
+ rows: PonsRow[];
38334
+ updatedAt: string;
38335
+ updatedAtStatic?: string;
38336
+ };
38337
+ type PonsUpdateMeta = {
38338
+ updatedAt: string;
38339
+ };
38340
+ type PonsStore = {
38341
+ getSnapshot(): Promise<PonsSnapshot | null>;
38342
+ setSnapshot(snapshot: PonsSnapshot): Promise<void>;
38343
+ publishUpdate(meta: PonsUpdateMeta): Promise<void>;
38344
+ subscribe(onUpdate: (meta: PonsUpdateMeta) => void): () => void;
38345
+ };
38346
+
38347
+ declare function createPonsStore(client: Redis__default, basePrefix: string): PonsStore;
38348
+
38349
+ declare const storeFactories: {
38350
+ readonly pons: typeof createPonsStore;
38351
+ };
38352
+
38353
+ type RoutinesRedisStores = {
38354
+ [K in keyof typeof storeFactories]: ReturnType<(typeof storeFactories)[K]>;
38355
+ };
38356
+
38357
+ type RedisConnectionConfig = {
38358
+ host: string;
38359
+ port: number;
38360
+ password?: string;
38361
+ };
38362
+
38363
+ declare class RoutinesRedisService {
38364
+ private static instance;
38365
+ private connection;
38366
+ private initialized;
38367
+ private constructor();
38368
+ private notInitialized;
38369
+ /** Retorna a instância singleton */
38370
+ static getInstance(): RoutinesRedisService;
38371
+ /** Inicializa a conexão e stores */
38372
+ init(config: RedisConnectionConfig): Promise<void>;
38373
+ /** Retorna o client ioredis */
38374
+ getClient(): Redis.default;
38375
+ /** Retorna stores tipados */
38376
+ get stores(): RoutinesRedisStores;
38377
+ /** Retorna um store específico tipado */
38378
+ getStore<K extends keyof RoutinesRedisStores>(key: K): RoutinesRedisStores[K];
38379
+ }
38380
+
38381
+ export { type ExpensesFleetMongoCollectionsModels, type ExpensesFleetMongoDocuments, ExpensesFleetMongoService, GeminiLIBClient, geminiLib_types as GeminiLIBTypes, type GigacenterMongoCollectionsModels, type GigacenterMongoDocuments, GigacenterMongoService, IXCSoftAPIClient, ixcSoftApi_types as IXCSoftAPITypes, type IXCSoftMysqlModels, type IXCSoftMysqlModelsAttributes, IXCSoftMysqlService, type MCPGiganetMongoCollectionsModels, type MCPGiganetMongoDocuments, MCPGiganetMongoService, NtfyAPIClient, ntfyApi_types as NtfyAPITypes, type OPASuiteMongoCollectionsModels, type OPASuiteMongoDocuments, OPASuiteMongoService, type PonsRow, type PonsSnapshot, type PonsStore, type PonsUpdateMeta, RoutinesAPIClient, routinesApi_types as RoutinesAPITypes, type RoutinesMongoCollectionsModels, type RoutinesMongoDocuments, RoutinesMongoService, type RoutinesMysqlModels, type RoutinesMysqlModelsAttributes, RoutinesMysqlService, RoutinesRedisService, type RoutinesRedisStores, type ToolsMongoCollectionsModels, type ToolsMongoDocuments, ToolsMongoService, loger, printSignature };
package/dist/index.js CHANGED
@@ -45,6 +45,7 @@ __export(index_exports, {
45
45
  RoutinesAPITypes: () => routines_api_types_exports,
46
46
  RoutinesMongoService: () => RoutinesMongoService,
47
47
  RoutinesMysqlService: () => RoutinesMysqlService,
48
+ RoutinesRedisService: () => RoutinesRedisService,
48
49
  ToolsMongoService: () => ToolsMongoService,
49
50
  loger: () => loger,
50
51
  printSignature: () => printSignature
@@ -92156,6 +92157,11 @@ var ToolsUserSchema = new import_mongoose7.Schema(
92156
92157
  required: true,
92157
92158
  default: []
92158
92159
  },
92160
+ permissions_socket: {
92161
+ type: [String],
92162
+ required: true,
92163
+ default: []
92164
+ },
92159
92165
  permissions_front: {
92160
92166
  type: [String],
92161
92167
  required: true,
@@ -92824,6 +92830,179 @@ var GigacenterMongoService = class _GigacenterMongoService {
92824
92830
  return this.connection.collections[key];
92825
92831
  }
92826
92832
  };
92833
+
92834
+ // src/databases/redis/core/redis.connection.ts
92835
+ var import_ioredis = __toESM(require("ioredis"));
92836
+ async function createRedisConnection({
92837
+ host,
92838
+ port,
92839
+ password,
92840
+ database,
92841
+ keyPrefix,
92842
+ context
92843
+ }) {
92844
+ try {
92845
+ if (!host || !port) {
92846
+ throw new Error("Dados de conex\xE3o n\xE3o informados");
92847
+ }
92848
+ loger({
92849
+ domain: "REDIS",
92850
+ context,
92851
+ message: "Iniciando conex\xE3o..."
92852
+ });
92853
+ const client = new import_ioredis.default({
92854
+ host,
92855
+ port,
92856
+ password: password || void 0,
92857
+ db: database ?? 0,
92858
+ keyPrefix,
92859
+ lazyConnect: true
92860
+ });
92861
+ await retry(
92862
+ async () => {
92863
+ if (client.status === "wait") {
92864
+ await client.connect();
92865
+ }
92866
+ await client.ping();
92867
+ return client;
92868
+ },
92869
+ {
92870
+ onRetry: (error, attempt) => {
92871
+ loger({
92872
+ level: "WARN",
92873
+ domain: "REDIS",
92874
+ context,
92875
+ message: `Tentativa ${attempt} falhou: ${error instanceof Error ? error.message : error}`
92876
+ });
92877
+ }
92878
+ }
92879
+ );
92880
+ return client;
92881
+ } catch (error) {
92882
+ loger({
92883
+ level: "ERROR",
92884
+ domain: "REDIS",
92885
+ context,
92886
+ message: error instanceof Error ? error.message : "Erro desconhecido"
92887
+ });
92888
+ throw error instanceof Error ? error : new Error(String(error));
92889
+ }
92890
+ }
92891
+
92892
+ // src/databases/redis/routines/routines.redis.types.ts
92893
+ var configRoutinesRedis = {
92894
+ context: "ROUTINES_REDIS",
92895
+ domain: "REDIS"
92896
+ };
92897
+
92898
+ // src/databases/redis/routines/stores/pons/pons.ts
92899
+ var SNAPSHOT_KEY = "snapshot";
92900
+ var UPDATES_CHANNEL = "updates";
92901
+ function createPonsStore(client, basePrefix) {
92902
+ const prefix = `${basePrefix}pons:`;
92903
+ const snapshotKey = `${prefix}${SNAPSHOT_KEY}`;
92904
+ const updatesChannel = `${client.options.keyPrefix ?? ""}${prefix}${UPDATES_CHANNEL}`;
92905
+ return {
92906
+ async getSnapshot() {
92907
+ const value = await client.get(snapshotKey);
92908
+ if (value === null) return null;
92909
+ return JSON.parse(value);
92910
+ },
92911
+ async setSnapshot(snapshot) {
92912
+ await client.set(snapshotKey, JSON.stringify(snapshot));
92913
+ },
92914
+ async publishUpdate(meta) {
92915
+ await client.publish(updatesChannel, JSON.stringify(meta));
92916
+ },
92917
+ subscribe(onUpdate) {
92918
+ const subscriber = client.duplicate();
92919
+ subscriber.subscribe(updatesChannel);
92920
+ subscriber.on("message", (channel, message) => {
92921
+ if (channel !== updatesChannel) return;
92922
+ onUpdate(JSON.parse(message));
92923
+ });
92924
+ return () => {
92925
+ subscriber.unsubscribe(updatesChannel);
92926
+ subscriber.disconnect();
92927
+ };
92928
+ }
92929
+ };
92930
+ }
92931
+
92932
+ // src/databases/redis/routines/stores/index.ts
92933
+ var storeFactories = {
92934
+ pons: createPonsStore
92935
+ };
92936
+
92937
+ // src/databases/redis/routines/routines.redis.connection.ts
92938
+ async function createRoutinesRedisConnection(config) {
92939
+ const client = await createRedisConnection({
92940
+ ...config,
92941
+ database: 0,
92942
+ keyPrefix: "routines:",
92943
+ context: configRoutinesRedis.context
92944
+ });
92945
+ const stores = Object.entries(storeFactories).reduce(
92946
+ (acc, [name, factory]) => {
92947
+ acc[name] = factory(client, "");
92948
+ return acc;
92949
+ },
92950
+ {}
92951
+ );
92952
+ return Object.freeze({
92953
+ client,
92954
+ stores: Object.freeze(stores)
92955
+ });
92956
+ }
92957
+ var connectRoutinesRedis = createConnectionFactory(createRoutinesRedisConnection);
92958
+
92959
+ // src/databases/redis/routines/routines.redis.service.ts
92960
+ var RoutinesRedisService = class _RoutinesRedisService {
92961
+ constructor() {
92962
+ this.initialized = false;
92963
+ }
92964
+ notInitialized() {
92965
+ if (!this.initialized)
92966
+ throw new Error(
92967
+ "RoutinesRedisService n\xE3o inicializado! Chame init() antes."
92968
+ );
92969
+ }
92970
+ /** Retorna a instância singleton */
92971
+ static getInstance() {
92972
+ if (!_RoutinesRedisService.instance)
92973
+ _RoutinesRedisService.instance = new _RoutinesRedisService();
92974
+ return _RoutinesRedisService.instance;
92975
+ }
92976
+ /** Inicializa a conexão e stores */
92977
+ async init(config) {
92978
+ if (this.initialized) return;
92979
+ loger({
92980
+ ...configRoutinesRedis,
92981
+ message: "Inicializando RoutinesRedisService..."
92982
+ });
92983
+ this.connection = await connectRoutinesRedis(config);
92984
+ this.initialized = true;
92985
+ loger({
92986
+ ...configRoutinesRedis,
92987
+ message: "RoutinesRedisService inicializado!"
92988
+ });
92989
+ }
92990
+ /** Retorna o client ioredis */
92991
+ getClient() {
92992
+ this.notInitialized();
92993
+ return this.connection.client;
92994
+ }
92995
+ /** Retorna stores tipados */
92996
+ get stores() {
92997
+ this.notInitialized();
92998
+ return this.connection.stores;
92999
+ }
93000
+ /** Retorna um store específico tipado */
93001
+ getStore(key) {
93002
+ this.notInitialized();
93003
+ return this.connection.stores[key];
93004
+ }
93005
+ };
92827
93006
  // Annotate the CommonJS export names for ESM import in node:
92828
93007
  0 && (module.exports = {
92829
93008
  ExpensesFleetMongoService,
@@ -92841,6 +93020,7 @@ var GigacenterMongoService = class _GigacenterMongoService {
92841
93020
  RoutinesAPITypes,
92842
93021
  RoutinesMongoService,
92843
93022
  RoutinesMysqlService,
93023
+ RoutinesRedisService,
92844
93024
  ToolsMongoService,
92845
93025
  loger,
92846
93026
  printSignature
package/dist/index.mjs CHANGED
@@ -92109,6 +92109,11 @@ var ToolsUserSchema = new Schema6(
92109
92109
  required: true,
92110
92110
  default: []
92111
92111
  },
92112
+ permissions_socket: {
92113
+ type: [String],
92114
+ required: true,
92115
+ default: []
92116
+ },
92112
92117
  permissions_front: {
92113
92118
  type: [String],
92114
92119
  required: true,
@@ -92777,6 +92782,179 @@ var GigacenterMongoService = class _GigacenterMongoService {
92777
92782
  return this.connection.collections[key];
92778
92783
  }
92779
92784
  };
92785
+
92786
+ // src/databases/redis/core/redis.connection.ts
92787
+ import Redis from "ioredis";
92788
+ async function createRedisConnection({
92789
+ host,
92790
+ port,
92791
+ password,
92792
+ database,
92793
+ keyPrefix,
92794
+ context
92795
+ }) {
92796
+ try {
92797
+ if (!host || !port) {
92798
+ throw new Error("Dados de conex\xE3o n\xE3o informados");
92799
+ }
92800
+ loger({
92801
+ domain: "REDIS",
92802
+ context,
92803
+ message: "Iniciando conex\xE3o..."
92804
+ });
92805
+ const client = new Redis({
92806
+ host,
92807
+ port,
92808
+ password: password || void 0,
92809
+ db: database ?? 0,
92810
+ keyPrefix,
92811
+ lazyConnect: true
92812
+ });
92813
+ await retry(
92814
+ async () => {
92815
+ if (client.status === "wait") {
92816
+ await client.connect();
92817
+ }
92818
+ await client.ping();
92819
+ return client;
92820
+ },
92821
+ {
92822
+ onRetry: (error, attempt) => {
92823
+ loger({
92824
+ level: "WARN",
92825
+ domain: "REDIS",
92826
+ context,
92827
+ message: `Tentativa ${attempt} falhou: ${error instanceof Error ? error.message : error}`
92828
+ });
92829
+ }
92830
+ }
92831
+ );
92832
+ return client;
92833
+ } catch (error) {
92834
+ loger({
92835
+ level: "ERROR",
92836
+ domain: "REDIS",
92837
+ context,
92838
+ message: error instanceof Error ? error.message : "Erro desconhecido"
92839
+ });
92840
+ throw error instanceof Error ? error : new Error(String(error));
92841
+ }
92842
+ }
92843
+
92844
+ // src/databases/redis/routines/routines.redis.types.ts
92845
+ var configRoutinesRedis = {
92846
+ context: "ROUTINES_REDIS",
92847
+ domain: "REDIS"
92848
+ };
92849
+
92850
+ // src/databases/redis/routines/stores/pons/pons.ts
92851
+ var SNAPSHOT_KEY = "snapshot";
92852
+ var UPDATES_CHANNEL = "updates";
92853
+ function createPonsStore(client, basePrefix) {
92854
+ const prefix = `${basePrefix}pons:`;
92855
+ const snapshotKey = `${prefix}${SNAPSHOT_KEY}`;
92856
+ const updatesChannel = `${client.options.keyPrefix ?? ""}${prefix}${UPDATES_CHANNEL}`;
92857
+ return {
92858
+ async getSnapshot() {
92859
+ const value = await client.get(snapshotKey);
92860
+ if (value === null) return null;
92861
+ return JSON.parse(value);
92862
+ },
92863
+ async setSnapshot(snapshot) {
92864
+ await client.set(snapshotKey, JSON.stringify(snapshot));
92865
+ },
92866
+ async publishUpdate(meta) {
92867
+ await client.publish(updatesChannel, JSON.stringify(meta));
92868
+ },
92869
+ subscribe(onUpdate) {
92870
+ const subscriber = client.duplicate();
92871
+ subscriber.subscribe(updatesChannel);
92872
+ subscriber.on("message", (channel, message) => {
92873
+ if (channel !== updatesChannel) return;
92874
+ onUpdate(JSON.parse(message));
92875
+ });
92876
+ return () => {
92877
+ subscriber.unsubscribe(updatesChannel);
92878
+ subscriber.disconnect();
92879
+ };
92880
+ }
92881
+ };
92882
+ }
92883
+
92884
+ // src/databases/redis/routines/stores/index.ts
92885
+ var storeFactories = {
92886
+ pons: createPonsStore
92887
+ };
92888
+
92889
+ // src/databases/redis/routines/routines.redis.connection.ts
92890
+ async function createRoutinesRedisConnection(config) {
92891
+ const client = await createRedisConnection({
92892
+ ...config,
92893
+ database: 0,
92894
+ keyPrefix: "routines:",
92895
+ context: configRoutinesRedis.context
92896
+ });
92897
+ const stores = Object.entries(storeFactories).reduce(
92898
+ (acc, [name, factory]) => {
92899
+ acc[name] = factory(client, "");
92900
+ return acc;
92901
+ },
92902
+ {}
92903
+ );
92904
+ return Object.freeze({
92905
+ client,
92906
+ stores: Object.freeze(stores)
92907
+ });
92908
+ }
92909
+ var connectRoutinesRedis = createConnectionFactory(createRoutinesRedisConnection);
92910
+
92911
+ // src/databases/redis/routines/routines.redis.service.ts
92912
+ var RoutinesRedisService = class _RoutinesRedisService {
92913
+ constructor() {
92914
+ this.initialized = false;
92915
+ }
92916
+ notInitialized() {
92917
+ if (!this.initialized)
92918
+ throw new Error(
92919
+ "RoutinesRedisService n\xE3o inicializado! Chame init() antes."
92920
+ );
92921
+ }
92922
+ /** Retorna a instância singleton */
92923
+ static getInstance() {
92924
+ if (!_RoutinesRedisService.instance)
92925
+ _RoutinesRedisService.instance = new _RoutinesRedisService();
92926
+ return _RoutinesRedisService.instance;
92927
+ }
92928
+ /** Inicializa a conexão e stores */
92929
+ async init(config) {
92930
+ if (this.initialized) return;
92931
+ loger({
92932
+ ...configRoutinesRedis,
92933
+ message: "Inicializando RoutinesRedisService..."
92934
+ });
92935
+ this.connection = await connectRoutinesRedis(config);
92936
+ this.initialized = true;
92937
+ loger({
92938
+ ...configRoutinesRedis,
92939
+ message: "RoutinesRedisService inicializado!"
92940
+ });
92941
+ }
92942
+ /** Retorna o client ioredis */
92943
+ getClient() {
92944
+ this.notInitialized();
92945
+ return this.connection.client;
92946
+ }
92947
+ /** Retorna stores tipados */
92948
+ get stores() {
92949
+ this.notInitialized();
92950
+ return this.connection.stores;
92951
+ }
92952
+ /** Retorna um store específico tipado */
92953
+ getStore(key) {
92954
+ this.notInitialized();
92955
+ return this.connection.stores[key];
92956
+ }
92957
+ };
92780
92958
  export {
92781
92959
  ExpensesFleetMongoService,
92782
92960
  GeminiLIBClient,
@@ -92793,6 +92971,7 @@ export {
92793
92971
  routines_api_types_exports as RoutinesAPITypes,
92794
92972
  RoutinesMongoService,
92795
92973
  RoutinesMysqlService,
92974
+ RoutinesRedisService,
92796
92975
  ToolsMongoService,
92797
92976
  loger,
92798
92977
  printSignature
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cristian-israel/giganet_lib_conecta",
3
- "version": "1.0.89",
3
+ "version": "1.0.91",
4
4
  "description": "Database Connector Layer",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -9,7 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "scripts": {
12
- "build": "tsup src/index.ts --format cjs,esm --dts --clean --external mongoose,sequelize,mysql2,zod",
12
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean --external mongoose,sequelize,mysql2,ioredis,zod",
13
13
  "release": "npm version patch && npm publish && npm view @cristian-israel/giganet_lib_conecta",
14
14
  "br": "pnpm run build && pnpm run release",
15
15
  "type-check": "tsc --noEmit > type-check.log 2>&1",
@@ -30,6 +30,7 @@
30
30
  "database",
31
31
  "mysql",
32
32
  "mongodb",
33
+ "redis",
33
34
  "sequelize",
34
35
  "connector",
35
36
  "typescript"
@@ -42,6 +43,7 @@
42
43
  "homepage": "https://github.com/cristian-israel/giganet_lib_conecta#readme",
43
44
  "devDependencies": {
44
45
  "@types/node": "^25.6.0",
46
+ "ioredis": "^5.4.0",
45
47
  "mongoose": "^9.4.1",
46
48
  "sequelize-auto": "^0.8.8",
47
49
  "tsup": "^8.5.1",
@@ -49,6 +51,7 @@
49
51
  "zod": "^4.3.6"
50
52
  },
51
53
  "peerDependencies": {
54
+ "ioredis": "^5.4.0",
52
55
  "mongoose": "^9.3.3",
53
56
  "mysql2": "^3.20.0",
54
57
  "sequelize": "^6.37.8",