@cristian-israel/giganet_lib_conecta 1.0.89 → 1.0.90
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 +67 -1
- package/dist/index.d.ts +67 -1
- package/dist/index.js +175 -0
- package/dist/index.mjs +174 -0
- package/package.json +5 -2
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 = {
|
|
@@ -38308,4 +38310,68 @@ declare class GigacenterMongoService {
|
|
|
38308
38310
|
getCollection<K extends keyof GigacenterMongoCollectionsModels>(key: K): GigacenterMongoCollectionsModels[K];
|
|
38309
38311
|
}
|
|
38310
38312
|
|
|
38311
|
-
|
|
38313
|
+
type PonsRow = {
|
|
38314
|
+
id: number;
|
|
38315
|
+
interface: string;
|
|
38316
|
+
transmissor: string;
|
|
38317
|
+
slot: number;
|
|
38318
|
+
numero: number;
|
|
38319
|
+
vlan: string;
|
|
38320
|
+
onus_vinculadas: number;
|
|
38321
|
+
onus_autorizadas: number;
|
|
38322
|
+
sinal_alto: number;
|
|
38323
|
+
os_pendentes: number;
|
|
38324
|
+
os_recolha: number;
|
|
38325
|
+
rompimentos: number;
|
|
38326
|
+
offlines_menos_3_meses: number;
|
|
38327
|
+
};
|
|
38328
|
+
type PonsSnapshot = {
|
|
38329
|
+
rows: PonsRow[];
|
|
38330
|
+
updatedAt: string;
|
|
38331
|
+
updatedAtStatic?: string;
|
|
38332
|
+
};
|
|
38333
|
+
type PonsUpdateMeta = {
|
|
38334
|
+
updatedAt: string;
|
|
38335
|
+
};
|
|
38336
|
+
type PonsStore = {
|
|
38337
|
+
getSnapshot(): Promise<PonsSnapshot | null>;
|
|
38338
|
+
setSnapshot(snapshot: PonsSnapshot): Promise<void>;
|
|
38339
|
+
publishUpdate(meta: PonsUpdateMeta): Promise<void>;
|
|
38340
|
+
subscribe(onUpdate: (meta: PonsUpdateMeta) => void): () => void;
|
|
38341
|
+
};
|
|
38342
|
+
|
|
38343
|
+
declare function createPonsStore(client: Redis__default, basePrefix: string): PonsStore;
|
|
38344
|
+
|
|
38345
|
+
declare const storeFactories: {
|
|
38346
|
+
readonly pons: typeof createPonsStore;
|
|
38347
|
+
};
|
|
38348
|
+
|
|
38349
|
+
type RoutinesRedisStores = {
|
|
38350
|
+
[K in keyof typeof storeFactories]: ReturnType<(typeof storeFactories)[K]>;
|
|
38351
|
+
};
|
|
38352
|
+
|
|
38353
|
+
type RedisConnectionConfig = {
|
|
38354
|
+
host: string;
|
|
38355
|
+
port: number;
|
|
38356
|
+
password?: string;
|
|
38357
|
+
};
|
|
38358
|
+
|
|
38359
|
+
declare class RoutinesRedisService {
|
|
38360
|
+
private static instance;
|
|
38361
|
+
private connection;
|
|
38362
|
+
private initialized;
|
|
38363
|
+
private constructor();
|
|
38364
|
+
private notInitialized;
|
|
38365
|
+
/** Retorna a instância singleton */
|
|
38366
|
+
static getInstance(): RoutinesRedisService;
|
|
38367
|
+
/** Inicializa a conexão e stores */
|
|
38368
|
+
init(config: RedisConnectionConfig): Promise<void>;
|
|
38369
|
+
/** Retorna o client ioredis */
|
|
38370
|
+
getClient(): Redis.default;
|
|
38371
|
+
/** Retorna stores tipados */
|
|
38372
|
+
get stores(): RoutinesRedisStores;
|
|
38373
|
+
/** Retorna um store específico tipado */
|
|
38374
|
+
getStore<K extends keyof RoutinesRedisStores>(key: K): RoutinesRedisStores[K];
|
|
38375
|
+
}
|
|
38376
|
+
|
|
38377
|
+
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 = {
|
|
@@ -38308,4 +38310,68 @@ declare class GigacenterMongoService {
|
|
|
38308
38310
|
getCollection<K extends keyof GigacenterMongoCollectionsModels>(key: K): GigacenterMongoCollectionsModels[K];
|
|
38309
38311
|
}
|
|
38310
38312
|
|
|
38311
|
-
|
|
38313
|
+
type PonsRow = {
|
|
38314
|
+
id: number;
|
|
38315
|
+
interface: string;
|
|
38316
|
+
transmissor: string;
|
|
38317
|
+
slot: number;
|
|
38318
|
+
numero: number;
|
|
38319
|
+
vlan: string;
|
|
38320
|
+
onus_vinculadas: number;
|
|
38321
|
+
onus_autorizadas: number;
|
|
38322
|
+
sinal_alto: number;
|
|
38323
|
+
os_pendentes: number;
|
|
38324
|
+
os_recolha: number;
|
|
38325
|
+
rompimentos: number;
|
|
38326
|
+
offlines_menos_3_meses: number;
|
|
38327
|
+
};
|
|
38328
|
+
type PonsSnapshot = {
|
|
38329
|
+
rows: PonsRow[];
|
|
38330
|
+
updatedAt: string;
|
|
38331
|
+
updatedAtStatic?: string;
|
|
38332
|
+
};
|
|
38333
|
+
type PonsUpdateMeta = {
|
|
38334
|
+
updatedAt: string;
|
|
38335
|
+
};
|
|
38336
|
+
type PonsStore = {
|
|
38337
|
+
getSnapshot(): Promise<PonsSnapshot | null>;
|
|
38338
|
+
setSnapshot(snapshot: PonsSnapshot): Promise<void>;
|
|
38339
|
+
publishUpdate(meta: PonsUpdateMeta): Promise<void>;
|
|
38340
|
+
subscribe(onUpdate: (meta: PonsUpdateMeta) => void): () => void;
|
|
38341
|
+
};
|
|
38342
|
+
|
|
38343
|
+
declare function createPonsStore(client: Redis__default, basePrefix: string): PonsStore;
|
|
38344
|
+
|
|
38345
|
+
declare const storeFactories: {
|
|
38346
|
+
readonly pons: typeof createPonsStore;
|
|
38347
|
+
};
|
|
38348
|
+
|
|
38349
|
+
type RoutinesRedisStores = {
|
|
38350
|
+
[K in keyof typeof storeFactories]: ReturnType<(typeof storeFactories)[K]>;
|
|
38351
|
+
};
|
|
38352
|
+
|
|
38353
|
+
type RedisConnectionConfig = {
|
|
38354
|
+
host: string;
|
|
38355
|
+
port: number;
|
|
38356
|
+
password?: string;
|
|
38357
|
+
};
|
|
38358
|
+
|
|
38359
|
+
declare class RoutinesRedisService {
|
|
38360
|
+
private static instance;
|
|
38361
|
+
private connection;
|
|
38362
|
+
private initialized;
|
|
38363
|
+
private constructor();
|
|
38364
|
+
private notInitialized;
|
|
38365
|
+
/** Retorna a instância singleton */
|
|
38366
|
+
static getInstance(): RoutinesRedisService;
|
|
38367
|
+
/** Inicializa a conexão e stores */
|
|
38368
|
+
init(config: RedisConnectionConfig): Promise<void>;
|
|
38369
|
+
/** Retorna o client ioredis */
|
|
38370
|
+
getClient(): Redis.default;
|
|
38371
|
+
/** Retorna stores tipados */
|
|
38372
|
+
get stores(): RoutinesRedisStores;
|
|
38373
|
+
/** Retorna um store específico tipado */
|
|
38374
|
+
getStore<K extends keyof RoutinesRedisStores>(key: K): RoutinesRedisStores[K];
|
|
38375
|
+
}
|
|
38376
|
+
|
|
38377
|
+
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
|
|
@@ -92824,6 +92825,179 @@ var GigacenterMongoService = class _GigacenterMongoService {
|
|
|
92824
92825
|
return this.connection.collections[key];
|
|
92825
92826
|
}
|
|
92826
92827
|
};
|
|
92828
|
+
|
|
92829
|
+
// src/databases/redis/core/redis.connection.ts
|
|
92830
|
+
var import_ioredis = __toESM(require("ioredis"));
|
|
92831
|
+
async function createRedisConnection({
|
|
92832
|
+
host,
|
|
92833
|
+
port,
|
|
92834
|
+
password,
|
|
92835
|
+
database,
|
|
92836
|
+
keyPrefix,
|
|
92837
|
+
context
|
|
92838
|
+
}) {
|
|
92839
|
+
try {
|
|
92840
|
+
if (!host || !port) {
|
|
92841
|
+
throw new Error("Dados de conex\xE3o n\xE3o informados");
|
|
92842
|
+
}
|
|
92843
|
+
loger({
|
|
92844
|
+
domain: "REDIS",
|
|
92845
|
+
context,
|
|
92846
|
+
message: "Iniciando conex\xE3o..."
|
|
92847
|
+
});
|
|
92848
|
+
const client = new import_ioredis.default({
|
|
92849
|
+
host,
|
|
92850
|
+
port,
|
|
92851
|
+
password: password || void 0,
|
|
92852
|
+
db: database ?? 0,
|
|
92853
|
+
keyPrefix,
|
|
92854
|
+
lazyConnect: true
|
|
92855
|
+
});
|
|
92856
|
+
await retry(
|
|
92857
|
+
async () => {
|
|
92858
|
+
if (client.status === "wait") {
|
|
92859
|
+
await client.connect();
|
|
92860
|
+
}
|
|
92861
|
+
await client.ping();
|
|
92862
|
+
return client;
|
|
92863
|
+
},
|
|
92864
|
+
{
|
|
92865
|
+
onRetry: (error, attempt) => {
|
|
92866
|
+
loger({
|
|
92867
|
+
level: "WARN",
|
|
92868
|
+
domain: "REDIS",
|
|
92869
|
+
context,
|
|
92870
|
+
message: `Tentativa ${attempt} falhou: ${error instanceof Error ? error.message : error}`
|
|
92871
|
+
});
|
|
92872
|
+
}
|
|
92873
|
+
}
|
|
92874
|
+
);
|
|
92875
|
+
return client;
|
|
92876
|
+
} catch (error) {
|
|
92877
|
+
loger({
|
|
92878
|
+
level: "ERROR",
|
|
92879
|
+
domain: "REDIS",
|
|
92880
|
+
context,
|
|
92881
|
+
message: error instanceof Error ? error.message : "Erro desconhecido"
|
|
92882
|
+
});
|
|
92883
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
92884
|
+
}
|
|
92885
|
+
}
|
|
92886
|
+
|
|
92887
|
+
// src/databases/redis/routines/routines.redis.types.ts
|
|
92888
|
+
var configRoutinesRedis = {
|
|
92889
|
+
context: "ROUTINES_REDIS",
|
|
92890
|
+
domain: "REDIS"
|
|
92891
|
+
};
|
|
92892
|
+
|
|
92893
|
+
// src/databases/redis/routines/stores/pons/pons.ts
|
|
92894
|
+
var SNAPSHOT_KEY = "snapshot";
|
|
92895
|
+
var UPDATES_CHANNEL = "updates";
|
|
92896
|
+
function createPonsStore(client, basePrefix) {
|
|
92897
|
+
const prefix = `${basePrefix}pons:`;
|
|
92898
|
+
const snapshotKey = `${prefix}${SNAPSHOT_KEY}`;
|
|
92899
|
+
const updatesChannel = `${client.options.keyPrefix ?? ""}${prefix}${UPDATES_CHANNEL}`;
|
|
92900
|
+
return {
|
|
92901
|
+
async getSnapshot() {
|
|
92902
|
+
const value = await client.get(snapshotKey);
|
|
92903
|
+
if (value === null) return null;
|
|
92904
|
+
return JSON.parse(value);
|
|
92905
|
+
},
|
|
92906
|
+
async setSnapshot(snapshot) {
|
|
92907
|
+
await client.set(snapshotKey, JSON.stringify(snapshot));
|
|
92908
|
+
},
|
|
92909
|
+
async publishUpdate(meta) {
|
|
92910
|
+
await client.publish(updatesChannel, JSON.stringify(meta));
|
|
92911
|
+
},
|
|
92912
|
+
subscribe(onUpdate) {
|
|
92913
|
+
const subscriber = client.duplicate();
|
|
92914
|
+
subscriber.subscribe(updatesChannel);
|
|
92915
|
+
subscriber.on("message", (channel, message) => {
|
|
92916
|
+
if (channel !== updatesChannel) return;
|
|
92917
|
+
onUpdate(JSON.parse(message));
|
|
92918
|
+
});
|
|
92919
|
+
return () => {
|
|
92920
|
+
subscriber.unsubscribe(updatesChannel);
|
|
92921
|
+
subscriber.disconnect();
|
|
92922
|
+
};
|
|
92923
|
+
}
|
|
92924
|
+
};
|
|
92925
|
+
}
|
|
92926
|
+
|
|
92927
|
+
// src/databases/redis/routines/stores/index.ts
|
|
92928
|
+
var storeFactories = {
|
|
92929
|
+
pons: createPonsStore
|
|
92930
|
+
};
|
|
92931
|
+
|
|
92932
|
+
// src/databases/redis/routines/routines.redis.connection.ts
|
|
92933
|
+
async function createRoutinesRedisConnection(config) {
|
|
92934
|
+
const client = await createRedisConnection({
|
|
92935
|
+
...config,
|
|
92936
|
+
database: 0,
|
|
92937
|
+
keyPrefix: "routines:",
|
|
92938
|
+
context: configRoutinesRedis.context
|
|
92939
|
+
});
|
|
92940
|
+
const stores = Object.entries(storeFactories).reduce(
|
|
92941
|
+
(acc, [name, factory]) => {
|
|
92942
|
+
acc[name] = factory(client, "");
|
|
92943
|
+
return acc;
|
|
92944
|
+
},
|
|
92945
|
+
{}
|
|
92946
|
+
);
|
|
92947
|
+
return Object.freeze({
|
|
92948
|
+
client,
|
|
92949
|
+
stores: Object.freeze(stores)
|
|
92950
|
+
});
|
|
92951
|
+
}
|
|
92952
|
+
var connectRoutinesRedis = createConnectionFactory(createRoutinesRedisConnection);
|
|
92953
|
+
|
|
92954
|
+
// src/databases/redis/routines/routines.redis.service.ts
|
|
92955
|
+
var RoutinesRedisService = class _RoutinesRedisService {
|
|
92956
|
+
constructor() {
|
|
92957
|
+
this.initialized = false;
|
|
92958
|
+
}
|
|
92959
|
+
notInitialized() {
|
|
92960
|
+
if (!this.initialized)
|
|
92961
|
+
throw new Error(
|
|
92962
|
+
"RoutinesRedisService n\xE3o inicializado! Chame init() antes."
|
|
92963
|
+
);
|
|
92964
|
+
}
|
|
92965
|
+
/** Retorna a instância singleton */
|
|
92966
|
+
static getInstance() {
|
|
92967
|
+
if (!_RoutinesRedisService.instance)
|
|
92968
|
+
_RoutinesRedisService.instance = new _RoutinesRedisService();
|
|
92969
|
+
return _RoutinesRedisService.instance;
|
|
92970
|
+
}
|
|
92971
|
+
/** Inicializa a conexão e stores */
|
|
92972
|
+
async init(config) {
|
|
92973
|
+
if (this.initialized) return;
|
|
92974
|
+
loger({
|
|
92975
|
+
...configRoutinesRedis,
|
|
92976
|
+
message: "Inicializando RoutinesRedisService..."
|
|
92977
|
+
});
|
|
92978
|
+
this.connection = await connectRoutinesRedis(config);
|
|
92979
|
+
this.initialized = true;
|
|
92980
|
+
loger({
|
|
92981
|
+
...configRoutinesRedis,
|
|
92982
|
+
message: "RoutinesRedisService inicializado!"
|
|
92983
|
+
});
|
|
92984
|
+
}
|
|
92985
|
+
/** Retorna o client ioredis */
|
|
92986
|
+
getClient() {
|
|
92987
|
+
this.notInitialized();
|
|
92988
|
+
return this.connection.client;
|
|
92989
|
+
}
|
|
92990
|
+
/** Retorna stores tipados */
|
|
92991
|
+
get stores() {
|
|
92992
|
+
this.notInitialized();
|
|
92993
|
+
return this.connection.stores;
|
|
92994
|
+
}
|
|
92995
|
+
/** Retorna um store específico tipado */
|
|
92996
|
+
getStore(key) {
|
|
92997
|
+
this.notInitialized();
|
|
92998
|
+
return this.connection.stores[key];
|
|
92999
|
+
}
|
|
93000
|
+
};
|
|
92827
93001
|
// Annotate the CommonJS export names for ESM import in node:
|
|
92828
93002
|
0 && (module.exports = {
|
|
92829
93003
|
ExpensesFleetMongoService,
|
|
@@ -92841,6 +93015,7 @@ var GigacenterMongoService = class _GigacenterMongoService {
|
|
|
92841
93015
|
RoutinesAPITypes,
|
|
92842
93016
|
RoutinesMongoService,
|
|
92843
93017
|
RoutinesMysqlService,
|
|
93018
|
+
RoutinesRedisService,
|
|
92844
93019
|
ToolsMongoService,
|
|
92845
93020
|
loger,
|
|
92846
93021
|
printSignature
|
package/dist/index.mjs
CHANGED
|
@@ -92777,6 +92777,179 @@ var GigacenterMongoService = class _GigacenterMongoService {
|
|
|
92777
92777
|
return this.connection.collections[key];
|
|
92778
92778
|
}
|
|
92779
92779
|
};
|
|
92780
|
+
|
|
92781
|
+
// src/databases/redis/core/redis.connection.ts
|
|
92782
|
+
import Redis from "ioredis";
|
|
92783
|
+
async function createRedisConnection({
|
|
92784
|
+
host,
|
|
92785
|
+
port,
|
|
92786
|
+
password,
|
|
92787
|
+
database,
|
|
92788
|
+
keyPrefix,
|
|
92789
|
+
context
|
|
92790
|
+
}) {
|
|
92791
|
+
try {
|
|
92792
|
+
if (!host || !port) {
|
|
92793
|
+
throw new Error("Dados de conex\xE3o n\xE3o informados");
|
|
92794
|
+
}
|
|
92795
|
+
loger({
|
|
92796
|
+
domain: "REDIS",
|
|
92797
|
+
context,
|
|
92798
|
+
message: "Iniciando conex\xE3o..."
|
|
92799
|
+
});
|
|
92800
|
+
const client = new Redis({
|
|
92801
|
+
host,
|
|
92802
|
+
port,
|
|
92803
|
+
password: password || void 0,
|
|
92804
|
+
db: database ?? 0,
|
|
92805
|
+
keyPrefix,
|
|
92806
|
+
lazyConnect: true
|
|
92807
|
+
});
|
|
92808
|
+
await retry(
|
|
92809
|
+
async () => {
|
|
92810
|
+
if (client.status === "wait") {
|
|
92811
|
+
await client.connect();
|
|
92812
|
+
}
|
|
92813
|
+
await client.ping();
|
|
92814
|
+
return client;
|
|
92815
|
+
},
|
|
92816
|
+
{
|
|
92817
|
+
onRetry: (error, attempt) => {
|
|
92818
|
+
loger({
|
|
92819
|
+
level: "WARN",
|
|
92820
|
+
domain: "REDIS",
|
|
92821
|
+
context,
|
|
92822
|
+
message: `Tentativa ${attempt} falhou: ${error instanceof Error ? error.message : error}`
|
|
92823
|
+
});
|
|
92824
|
+
}
|
|
92825
|
+
}
|
|
92826
|
+
);
|
|
92827
|
+
return client;
|
|
92828
|
+
} catch (error) {
|
|
92829
|
+
loger({
|
|
92830
|
+
level: "ERROR",
|
|
92831
|
+
domain: "REDIS",
|
|
92832
|
+
context,
|
|
92833
|
+
message: error instanceof Error ? error.message : "Erro desconhecido"
|
|
92834
|
+
});
|
|
92835
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
92836
|
+
}
|
|
92837
|
+
}
|
|
92838
|
+
|
|
92839
|
+
// src/databases/redis/routines/routines.redis.types.ts
|
|
92840
|
+
var configRoutinesRedis = {
|
|
92841
|
+
context: "ROUTINES_REDIS",
|
|
92842
|
+
domain: "REDIS"
|
|
92843
|
+
};
|
|
92844
|
+
|
|
92845
|
+
// src/databases/redis/routines/stores/pons/pons.ts
|
|
92846
|
+
var SNAPSHOT_KEY = "snapshot";
|
|
92847
|
+
var UPDATES_CHANNEL = "updates";
|
|
92848
|
+
function createPonsStore(client, basePrefix) {
|
|
92849
|
+
const prefix = `${basePrefix}pons:`;
|
|
92850
|
+
const snapshotKey = `${prefix}${SNAPSHOT_KEY}`;
|
|
92851
|
+
const updatesChannel = `${client.options.keyPrefix ?? ""}${prefix}${UPDATES_CHANNEL}`;
|
|
92852
|
+
return {
|
|
92853
|
+
async getSnapshot() {
|
|
92854
|
+
const value = await client.get(snapshotKey);
|
|
92855
|
+
if (value === null) return null;
|
|
92856
|
+
return JSON.parse(value);
|
|
92857
|
+
},
|
|
92858
|
+
async setSnapshot(snapshot) {
|
|
92859
|
+
await client.set(snapshotKey, JSON.stringify(snapshot));
|
|
92860
|
+
},
|
|
92861
|
+
async publishUpdate(meta) {
|
|
92862
|
+
await client.publish(updatesChannel, JSON.stringify(meta));
|
|
92863
|
+
},
|
|
92864
|
+
subscribe(onUpdate) {
|
|
92865
|
+
const subscriber = client.duplicate();
|
|
92866
|
+
subscriber.subscribe(updatesChannel);
|
|
92867
|
+
subscriber.on("message", (channel, message) => {
|
|
92868
|
+
if (channel !== updatesChannel) return;
|
|
92869
|
+
onUpdate(JSON.parse(message));
|
|
92870
|
+
});
|
|
92871
|
+
return () => {
|
|
92872
|
+
subscriber.unsubscribe(updatesChannel);
|
|
92873
|
+
subscriber.disconnect();
|
|
92874
|
+
};
|
|
92875
|
+
}
|
|
92876
|
+
};
|
|
92877
|
+
}
|
|
92878
|
+
|
|
92879
|
+
// src/databases/redis/routines/stores/index.ts
|
|
92880
|
+
var storeFactories = {
|
|
92881
|
+
pons: createPonsStore
|
|
92882
|
+
};
|
|
92883
|
+
|
|
92884
|
+
// src/databases/redis/routines/routines.redis.connection.ts
|
|
92885
|
+
async function createRoutinesRedisConnection(config) {
|
|
92886
|
+
const client = await createRedisConnection({
|
|
92887
|
+
...config,
|
|
92888
|
+
database: 0,
|
|
92889
|
+
keyPrefix: "routines:",
|
|
92890
|
+
context: configRoutinesRedis.context
|
|
92891
|
+
});
|
|
92892
|
+
const stores = Object.entries(storeFactories).reduce(
|
|
92893
|
+
(acc, [name, factory]) => {
|
|
92894
|
+
acc[name] = factory(client, "");
|
|
92895
|
+
return acc;
|
|
92896
|
+
},
|
|
92897
|
+
{}
|
|
92898
|
+
);
|
|
92899
|
+
return Object.freeze({
|
|
92900
|
+
client,
|
|
92901
|
+
stores: Object.freeze(stores)
|
|
92902
|
+
});
|
|
92903
|
+
}
|
|
92904
|
+
var connectRoutinesRedis = createConnectionFactory(createRoutinesRedisConnection);
|
|
92905
|
+
|
|
92906
|
+
// src/databases/redis/routines/routines.redis.service.ts
|
|
92907
|
+
var RoutinesRedisService = class _RoutinesRedisService {
|
|
92908
|
+
constructor() {
|
|
92909
|
+
this.initialized = false;
|
|
92910
|
+
}
|
|
92911
|
+
notInitialized() {
|
|
92912
|
+
if (!this.initialized)
|
|
92913
|
+
throw new Error(
|
|
92914
|
+
"RoutinesRedisService n\xE3o inicializado! Chame init() antes."
|
|
92915
|
+
);
|
|
92916
|
+
}
|
|
92917
|
+
/** Retorna a instância singleton */
|
|
92918
|
+
static getInstance() {
|
|
92919
|
+
if (!_RoutinesRedisService.instance)
|
|
92920
|
+
_RoutinesRedisService.instance = new _RoutinesRedisService();
|
|
92921
|
+
return _RoutinesRedisService.instance;
|
|
92922
|
+
}
|
|
92923
|
+
/** Inicializa a conexão e stores */
|
|
92924
|
+
async init(config) {
|
|
92925
|
+
if (this.initialized) return;
|
|
92926
|
+
loger({
|
|
92927
|
+
...configRoutinesRedis,
|
|
92928
|
+
message: "Inicializando RoutinesRedisService..."
|
|
92929
|
+
});
|
|
92930
|
+
this.connection = await connectRoutinesRedis(config);
|
|
92931
|
+
this.initialized = true;
|
|
92932
|
+
loger({
|
|
92933
|
+
...configRoutinesRedis,
|
|
92934
|
+
message: "RoutinesRedisService inicializado!"
|
|
92935
|
+
});
|
|
92936
|
+
}
|
|
92937
|
+
/** Retorna o client ioredis */
|
|
92938
|
+
getClient() {
|
|
92939
|
+
this.notInitialized();
|
|
92940
|
+
return this.connection.client;
|
|
92941
|
+
}
|
|
92942
|
+
/** Retorna stores tipados */
|
|
92943
|
+
get stores() {
|
|
92944
|
+
this.notInitialized();
|
|
92945
|
+
return this.connection.stores;
|
|
92946
|
+
}
|
|
92947
|
+
/** Retorna um store específico tipado */
|
|
92948
|
+
getStore(key) {
|
|
92949
|
+
this.notInitialized();
|
|
92950
|
+
return this.connection.stores[key];
|
|
92951
|
+
}
|
|
92952
|
+
};
|
|
92780
92953
|
export {
|
|
92781
92954
|
ExpensesFleetMongoService,
|
|
92782
92955
|
GeminiLIBClient,
|
|
@@ -92793,6 +92966,7 @@ export {
|
|
|
92793
92966
|
routines_api_types_exports as RoutinesAPITypes,
|
|
92794
92967
|
RoutinesMongoService,
|
|
92795
92968
|
RoutinesMysqlService,
|
|
92969
|
+
RoutinesRedisService,
|
|
92796
92970
|
ToolsMongoService,
|
|
92797
92971
|
loger,
|
|
92798
92972
|
printSignature
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cristian-israel/giganet_lib_conecta",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.90",
|
|
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",
|