@wabot-dev/framework 0.0.11 → 0.0.13

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.
Files changed (51) hide show
  1. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +2 -4
  2. package/dist/src/channels/cmd/@cmd.js +2 -0
  3. package/dist/src/channels/cmd/CmdChannel.js +2 -4
  4. package/dist/src/channels/telegram/@telegram.js +2 -0
  5. package/dist/src/channels/telegram/TelegramChannel.js +2 -4
  6. package/dist/src/chatbot/ChatBot.js +2 -4
  7. package/dist/src/chatbot/ChatBotAdapter.js +1 -3
  8. package/dist/src/chatbot/metadata/@chatBot.js +2 -0
  9. package/dist/src/chatbot/metadata/ChatBotMetadataStore.js +2 -0
  10. package/dist/src/controller/channel/ChatResolver.js +1 -3
  11. package/dist/src/controller/channel/UserResolver.js +1 -3
  12. package/dist/src/controller/metadata/ControllerMetadataStore.js +2 -0
  13. package/dist/src/controller/metadata/controller/@chatController.js +2 -0
  14. package/dist/src/core/IMessageContext.js +1 -2
  15. package/dist/src/core/chat/Chat.js +1 -1
  16. package/dist/src/core/chat/ChatItem.js +1 -1
  17. package/dist/src/core/user/{repository/IUserRepository.js → IUserRepository.js} +1 -1
  18. package/dist/src/core/user/User.js +1 -1
  19. package/dist/src/index.d.ts +235 -202
  20. package/dist/src/index.js +21 -19
  21. package/dist/src/mindset/MindsetOperator.js +2 -0
  22. package/dist/src/mindset/metadata/MindsetMetadataStore.js +2 -0
  23. package/dist/src/mindset/metadata/mindsets/@mindset.js +2 -0
  24. package/dist/src/mindset/metadata/modules/@mindsetModule.js +2 -0
  25. package/dist/src/pre-made/module/authentication/AuthenticationModule.js +1 -3
  26. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +2 -0
  27. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +2 -0
  28. package/dist/src/pre-made/module/register-user/RegisterUserModule.js +1 -3
  29. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +2 -0
  30. package/dist/src/pre-made/repository/chat/pg/PgChatMemory.js +43 -0
  31. package/dist/src/pre-made/repository/chat/pg/PgChatRepository.js +42 -0
  32. package/dist/src/{core/chat/repository → pre-made/repository/chat}/ram/RamChatRepository.js +0 -1
  33. package/dist/src/pre-made/repository/{sqlite/chat → chat/sqlite}/SqliteChatMemory.js +5 -5
  34. package/dist/src/pre-made/repository/{sqlite/chat → chat/sqlite}/SqliteChatRepository.js +5 -5
  35. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +38 -0
  36. package/dist/src/{core/user/repository → pre-made/repository/user}/ram/RamUserRepository.js +0 -1
  37. package/dist/src/pre-made/repository/user/sqlite/SqliteUserRepository.js +23 -0
  38. package/dist/src/repository/pg/PgCrudRepository.js +63 -0
  39. package/dist/src/repository/pg/PgRepositoryBase.js +89 -0
  40. package/dist/src/server/prepareChatContainer.js +4 -6
  41. package/dist/src/server/runChannel.js +2 -4
  42. package/dist/src/server/runServer.js +2 -4
  43. package/package.json +2 -1
  44. package/dist/src/pre-made/repository/pg/PgCrudRepository.js +0 -70
  45. package/dist/src/pre-made/repository/pg/PgPersistentMapper.js +0 -17
  46. package/dist/src/pre-made/repository/pg/chat/PgChatRepository.js +0 -30
  47. package/dist/src/pre-made/repository/sqlite/user/SqliteUserRepository.js +0 -33
  48. /package/dist/src/{shared → core}/Persistent.js +0 -0
  49. /package/dist/src/{core/chat/repository → pre-made/repository/chat}/ram/RamChatMemory.js +0 -0
  50. /package/dist/src/{pre-made/repository → repository}/sqlite/SqliteCrudRepository.js +0 -0
  51. /package/dist/src/{pre-made/repository → repository}/sqlite/SqlitePersistentMapper.js +0 -0
@@ -0,0 +1,43 @@
1
+ import { ChatItem } from '../../../../core/chat/ChatItem.js';
2
+ import '../../../../core/chat/repository/IChatRepository.js';
3
+ import '../../../../core/user/IUserRepository.js';
4
+ import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
5
+ import 'fs';
6
+ import 'path';
7
+ import 'sqlite';
8
+ import 'sqlite3';
9
+ import 'uuid';
10
+ import 'pg';
11
+
12
+ class PgChatMemory extends PgCrudRepository {
13
+ chatId;
14
+ constructor(pool, chatId) {
15
+ super(pool, {
16
+ table: 'chat_item',
17
+ schema: 'wabot',
18
+ constructor: ChatItem,
19
+ add: {
20
+ columns: {
21
+ chat_id: {
22
+ type: 'TEXT',
23
+ value: () => chatId,
24
+ },
25
+ },
26
+ },
27
+ });
28
+ this.chatId = chatId;
29
+ }
30
+ async findLastItems(count) {
31
+ const sql = `
32
+ SELECT ${this.columns}
33
+ FROM ${this.table}
34
+ WHERE chat_id = $1
35
+ ORDER BY created_at DESC
36
+ LIMIT $2
37
+ `;
38
+ const items = await this.query(sql, [this.chatId, count]);
39
+ return items.reverse();
40
+ }
41
+ }
42
+
43
+ export { PgChatMemory };
@@ -0,0 +1,42 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import '../../../../core/chat/repository/IChatRepository.js';
3
+ import { Chat } from '../../../../core/chat/Chat.js';
4
+ import '../../../../core/user/IUserRepository.js';
5
+ import { singleton } from '../../../../injection/index.js';
6
+ import { Pool } from 'pg';
7
+ import { PgChatMemory } from './PgChatMemory.js';
8
+ import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
9
+ import 'fs';
10
+ import 'path';
11
+ import 'sqlite';
12
+ import 'sqlite3';
13
+ import 'uuid';
14
+
15
+ let PgChatRepository = class PgChatRepository extends PgCrudRepository {
16
+ constructor(pool) {
17
+ super(pool, {
18
+ table: 'chat',
19
+ schema: 'wabot',
20
+ constructor: Chat,
21
+ });
22
+ }
23
+ async findByConnection(query) {
24
+ const sql = `
25
+ SELECT ${this.columns}
26
+ FROM ${this.table}
27
+ WHERE data->'connections' @> $1::jsonb
28
+ LIMIT 1
29
+ `;
30
+ const items = await this.query(sql, [JSON.stringify([query])]);
31
+ return items.at(0) ?? null;
32
+ }
33
+ async findMemory(chatId) {
34
+ return new PgChatMemory(this.pool, chatId);
35
+ }
36
+ };
37
+ PgChatRepository = __decorate([
38
+ singleton(),
39
+ __metadata("design:paramtypes", [Pool])
40
+ ], PgChatRepository);
41
+
42
+ export { PgChatRepository };
@@ -1,6 +1,5 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import { v4 } from 'uuid';
3
- import '../IChatRepository.js';
4
3
  import { RamChatMemory } from './RamChatMemory.js';
5
4
  import { singleton } from '../../../../injection/index.js';
6
5
 
@@ -1,11 +1,11 @@
1
1
  import path from 'path';
2
2
  import { ChatItem } from '../../../../core/chat/ChatItem.js';
3
- import '../../../../core/chat/repository/ram/RamChatRepository.js';
4
3
  import '../../../../core/chat/repository/IChatRepository.js';
5
- import '../../../../core/user/repository/ram/RamUserRepository.js';
6
- import '../../../../core/user/repository/IUserRepository.js';
7
- import { SqliteCrudRepository } from '../SqliteCrudRepository.js';
8
- import { sqliteMapperFor } from '../SqlitePersistentMapper.js';
4
+ import '../../../../core/user/IUserRepository.js';
5
+ import 'pg';
6
+ import 'short-uuid';
7
+ import { SqliteCrudRepository } from '../../../../repository/sqlite/SqliteCrudRepository.js';
8
+ import { sqliteMapperFor } from '../../../../repository/sqlite/SqlitePersistentMapper.js';
9
9
 
10
10
  class SqliteChatMemory extends SqliteCrudRepository {
11
11
  constructor(chatId) {
@@ -1,12 +1,12 @@
1
- import '../../../../core/chat/repository/ram/RamChatRepository.js';
2
1
  import '../../../../core/chat/repository/IChatRepository.js';
3
2
  import { Chat } from '../../../../core/chat/Chat.js';
4
- import '../../../../core/user/repository/ram/RamUserRepository.js';
5
- import '../../../../core/user/repository/IUserRepository.js';
3
+ import '../../../../core/user/IUserRepository.js';
6
4
  import path from 'path';
7
- import { SqliteCrudRepository } from '../SqliteCrudRepository.js';
8
- import { sqliteMapperFor } from '../SqlitePersistentMapper.js';
9
5
  import { SqliteChatMemory } from './SqliteChatMemory.js';
6
+ import 'pg';
7
+ import 'short-uuid';
8
+ import { SqliteCrudRepository } from '../../../../repository/sqlite/SqliteCrudRepository.js';
9
+ import { sqliteMapperFor } from '../../../../repository/sqlite/SqlitePersistentMapper.js';
10
10
 
11
11
  class SqliteChatRepository extends SqliteCrudRepository {
12
12
  constructor() {
@@ -0,0 +1,38 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import '../../../../core/chat/repository/IChatRepository.js';
3
+ import { User } from '../../../../core/user/User.js';
4
+ import '../../../../core/user/IUserRepository.js';
5
+ import { singleton } from '../../../../injection/index.js';
6
+ import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
7
+ import 'fs';
8
+ import 'path';
9
+ import 'sqlite';
10
+ import 'sqlite3';
11
+ import 'uuid';
12
+ import { Pool } from 'pg';
13
+
14
+ let PgUserRepository = class PgUserRepository extends PgCrudRepository {
15
+ constructor(pool) {
16
+ super(pool, {
17
+ table: 'user',
18
+ schema: 'wabot',
19
+ constructor: User,
20
+ });
21
+ }
22
+ async findByConnection(query) {
23
+ const sql = `
24
+ SELECT ${this.columns}
25
+ FROM ${this.table}
26
+ WHERE data->'connections' @> $1::jsonb
27
+ LIMIT 1
28
+ `;
29
+ const items = await this.query(sql, [JSON.stringify([query])]);
30
+ return items.at(0) ?? null;
31
+ }
32
+ };
33
+ PgUserRepository = __decorate([
34
+ singleton(),
35
+ __metadata("design:paramtypes", [Pool])
36
+ ], PgUserRepository);
37
+
38
+ export { PgUserRepository };
@@ -1,6 +1,5 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import { v4 } from 'uuid';
3
- import '../IUserRepository.js';
4
3
  import { singleton } from '../../../../injection/index.js';
5
4
 
6
5
  let RamUserRepository = class RamUserRepository {
@@ -0,0 +1,23 @@
1
+ import '../../../../core/chat/repository/IChatRepository.js';
2
+ import { User } from '../../../../core/user/User.js';
3
+ import '../../../../core/user/IUserRepository.js';
4
+ import 'pg';
5
+ import 'short-uuid';
6
+ import { SqliteCrudRepository } from '../../../../repository/sqlite/SqliteCrudRepository.js';
7
+ import { sqliteMapperFor } from '../../../../repository/sqlite/SqlitePersistentMapper.js';
8
+ import path from 'path';
9
+
10
+ class SqliteUserRepository extends SqliteCrudRepository {
11
+ constructor() {
12
+ super('user', SqliteUserRepository.getDbPath(), sqliteMapperFor(User));
13
+ }
14
+ async findByConnection(query) {
15
+ const allItems = await this.findAll();
16
+ return allItems.find((item) => item.hasConnection(query)) ?? null;
17
+ }
18
+ static getDbPath() {
19
+ return path.join(process.cwd(), '.sqlite', 'user.db');
20
+ }
21
+ }
22
+
23
+ export { SqliteUserRepository };
@@ -0,0 +1,63 @@
1
+ import 'pg';
2
+ import * as shortUUID from 'short-uuid';
3
+ import { PgRepositoryBase } from './PgRepositoryBase.js';
4
+
5
+ class PgCrudRepository extends PgRepositoryBase {
6
+ config;
7
+ constructor(pool, config) {
8
+ super(pool, config);
9
+ this.config = config;
10
+ }
11
+ async find(id) {
12
+ const sql = `
13
+ SELECT ${this.columns}
14
+ FROM ${this.table}
15
+ WHERE id = $1
16
+ LIMIT 1
17
+ `;
18
+ const items = await this.query(sql, [id]);
19
+ return items.at(0) ?? null;
20
+ }
21
+ async findAll() {
22
+ const sql = `
23
+ SELECT ${this.columns}
24
+ FROM ${this.table}
25
+ `;
26
+ const items = await this.query(sql, []);
27
+ return items;
28
+ }
29
+ async create(item) {
30
+ if (item.wasCreated()) {
31
+ throw new Error('Item already created');
32
+ }
33
+ item['data'].id = shortUUID.default.generate();
34
+ item['data'].createdAt = new Date().getTime();
35
+ item.validate();
36
+ const sql = `
37
+ INSERT INTO
38
+ ${this.table}(${this.columns})
39
+ VALUES (${this.vars})
40
+ `;
41
+ await this.exec(sql, this.values(item));
42
+ }
43
+ async update(item) {
44
+ item.validate();
45
+ const sql = `
46
+ UPDATE ${this.table}
47
+ SET ${this.updates}
48
+ WHERE id = $${this.columnsList.length + 1}
49
+ `;
50
+ await this.exec(sql, [...this.values(item), item.getId()]);
51
+ }
52
+ async discard(item) {
53
+ const _item = await this.find(item.getId());
54
+ if (!_item) {
55
+ throw new Error('Not found');
56
+ }
57
+ item.discard();
58
+ _item.discard();
59
+ await this.update(_item);
60
+ }
61
+ }
62
+
63
+ export { PgCrudRepository };
@@ -0,0 +1,89 @@
1
+ class PgRepositoryBase {
2
+ pool;
3
+ config;
4
+ tableIsCreated = false;
5
+ schema;
6
+ table;
7
+ columnsList;
8
+ columnsAndTypes;
9
+ columns;
10
+ vars;
11
+ updates;
12
+ addColumns;
13
+ constructor(pool, config) {
14
+ this.pool = pool;
15
+ this.config = config;
16
+ this.schema = `"${config.schema ?? 'public'}"`;
17
+ this.table = [config.schema, config.table]
18
+ .filter((x) => x && x.trim())
19
+ .map((x) => `"${x}"`)
20
+ .join('.');
21
+ this.addColumns = config.add?.columns ?? {};
22
+ this.columnsList = ['id', 'created_at', 'data', ...Object.keys(this.addColumns)];
23
+ this.columnsAndTypes = [
24
+ '"id" TEXT PRIMARY KEY',
25
+ '"created_at" TIMESTAMP',
26
+ '"data" JSONB',
27
+ ...this.columnsList.slice(3).map((x) => `${x} ${this.addColumns[x].type}`),
28
+ ].join(', ');
29
+ this.columns = this.columnsList.map((x) => `"${x}"`).join(', ');
30
+ this.vars = this.columnsList.map((_, i) => `$${i + 1}`).join(', ');
31
+ this.updates = this.columnsList.map((x, i) => `"${x}" = $${i + 1}`).join(', ');
32
+ }
33
+ values(item) {
34
+ return [
35
+ item.getId(),
36
+ item.getCreatedAt(),
37
+ JSON.stringify(item['data']),
38
+ ...this.columnsList.slice(3).map((x) => this.addColumns[x].value(item)),
39
+ ];
40
+ }
41
+ async exec(sql, values) {
42
+ const conn = await this.connect();
43
+ await conn.query(sql, values);
44
+ }
45
+ async query(sql, values) {
46
+ const conn = await this.connect();
47
+ const { rows } = await conn.query(sql, values);
48
+ return rows.map((row) => new this.config.constructor(row.data));
49
+ }
50
+ async connect() {
51
+ await this.ensureTable();
52
+ return this.pool;
53
+ }
54
+ async ensureTable() {
55
+ if (this.tableIsCreated) {
56
+ return;
57
+ }
58
+ const schemaQuery = `
59
+ CREATE SCHEMA IF NOT EXISTS ${this.schema}
60
+ `;
61
+ const tableQuery = `
62
+ CREATE TABLE IF NOT EXISTS ${this.table} (
63
+ ${this.columnsAndTypes}
64
+ )
65
+ `;
66
+ await this.pool.query(schemaQuery);
67
+ await this.pool.query(tableQuery);
68
+ await this.ensureColumns();
69
+ }
70
+ async ensureColumns() {
71
+ const { rows: existing } = await this.pool.query(`
72
+ SELECT column_name
73
+ FROM information_schema.columns
74
+ WHERE table_name = $1 AND table_schema = $2
75
+ `, [this.config.table, this.config.schema ?? 'public']);
76
+ const existingColumns = new Set(existing.map((col) => col.column_name));
77
+ for (let i = 0; i < this.columnsList.length; i++) {
78
+ const col = this.columnsList[i];
79
+ const columnAndType = this.columnsAndTypes[0];
80
+ if (!existingColumns.has(col)) {
81
+ const alterSql = `ALTER TABLE ${this.table} ADD COLUMN ${columnAndType}`;
82
+ console.log(`[INFO] Adding column: ${alterSql}`);
83
+ await this.pool.query(alterSql);
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ export { PgRepositoryBase };
@@ -1,14 +1,12 @@
1
+ import { ChatMemory } from '../core/chat/repository/IChatMemory.js';
2
+ import { ChatRepository } from '../core/chat/repository/IChatRepository.js';
3
+ import '../core/user/IUserRepository.js';
4
+ import { MessageContext } from '../core/IMessageContext.js';
1
5
  import '../injection/index.js';
2
6
  import 'reflect-metadata';
3
7
  import '../mindset/metadata/MindsetMetadataStore.js';
4
8
  import { Mindset } from '../mindset/IMindset.js';
5
9
  import '../mindset/MindsetOperator.js';
6
- import { ChatMemory } from '../core/chat/repository/IChatMemory.js';
7
- import '../core/chat/repository/ram/RamChatRepository.js';
8
- import { ChatRepository } from '../core/chat/repository/IChatRepository.js';
9
- import '../core/user/repository/ram/RamUserRepository.js';
10
- import '../core/user/repository/IUserRepository.js';
11
- import { MessageContext } from '../core/IMessageContext.js';
12
10
  import 'uuid';
13
11
  import { ChatBotMetadataStore } from '../chatbot/metadata/ChatBotMetadataStore.js';
14
12
  import { ChatBot } from '../chatbot/ChatBot.js';
@@ -2,15 +2,13 @@ import dotenv from 'dotenv';
2
2
  import '../controller/channel/ChatResolver.js';
3
3
  import '../controller/channel/UserResolver.js';
4
4
  import { container } from '../injection/index.js';
5
+ import { ChatRepository } from '../core/chat/repository/IChatRepository.js';
6
+ import '../core/user/IUserRepository.js';
5
7
  import '../controller/metadata/ControllerMetadataStore.js';
6
8
  import 'reflect-metadata';
7
9
  import '../mindset/metadata/MindsetMetadataStore.js';
8
10
  import '../mindset/MindsetOperator.js';
9
11
  import { prepareChatContainer } from './prepareChatContainer.js';
10
- import '../core/chat/repository/ram/RamChatRepository.js';
11
- import { ChatRepository } from '../core/chat/repository/IChatRepository.js';
12
- import '../core/user/repository/ram/RamUserRepository.js';
13
- import '../core/user/repository/IUserRepository.js';
14
12
  import 'uuid';
15
13
  import '../chatbot/metadata/ChatBotMetadataStore.js';
16
14
  import { ChatBot } from '../chatbot/ChatBot.js';
@@ -2,11 +2,9 @@ import dotenv from 'dotenv';
2
2
  import '../controller/channel/ChatResolver.js';
3
3
  import '../controller/channel/UserResolver.js';
4
4
  import { container } from '../injection/index.js';
5
- import { ControllerMetadataStore } from '../controller/metadata/ControllerMetadataStore.js';
6
- import '../core/chat/repository/ram/RamChatRepository.js';
7
5
  import '../core/chat/repository/IChatRepository.js';
8
- import '../core/user/repository/ram/RamUserRepository.js';
9
- import '../core/user/repository/IUserRepository.js';
6
+ import '../core/user/IUserRepository.js';
7
+ import { ControllerMetadataStore } from '../controller/metadata/ControllerMetadataStore.js';
10
8
  import { prepareChatContainer } from './prepareChatContainer.js';
11
9
 
12
10
  dotenv.config();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -45,6 +45,7 @@
45
45
  "openai": "^4.93.0",
46
46
  "pg": "^8.15.6",
47
47
  "reflect-metadata": "^0.2.2",
48
+ "short-uuid": "^5.2.0",
48
49
  "sqlite": "^5.1.1",
49
50
  "sqlite3": "^5.1.7",
50
51
  "tslib": "^2.8.1",
@@ -1,70 +0,0 @@
1
- import 'pg';
2
-
3
- class PgCrudRepository {
4
- pool;
5
- tableName;
6
- mapper;
7
- tableIsCreated = false;
8
- constructor(pool, tableName, mapper) {
9
- this.pool = pool;
10
- this.tableName = tableName;
11
- this.mapper = mapper;
12
- }
13
- async find(id) {
14
- const sql = `
15
- SELECT id, data
16
- FROM ${this.tableName}
17
- WHERE id = $1
18
- LIMIT 1
19
- `;
20
- await this.createTableIfNotExists();
21
- const { rows } = await this.pool.query(sql, [id]);
22
- if (rows.length === 0)
23
- return null;
24
- return this.mapper.rev(rows[0].data);
25
- }
26
- async findAll() {
27
- const sql = `SELECT id, data FROM ${this.tableName}`;
28
- await this.createTableIfNotExists();
29
- const { rows } = await this.pool.query(sql);
30
- return rows.map((r) => this.mapper.rev(r.data));
31
- }
32
- async create(item) {
33
- const sql = `
34
- INSERT INTO ${this.tableName}(id, data)
35
- VALUES ($1, $2)
36
- `;
37
- const data = this.mapper.map(item);
38
- await this.createTableIfNotExists();
39
- await this.pool.query(sql, [item.getId(), data]);
40
- }
41
- async update(item) {
42
- const sql = `
43
- UPDATE ${this.tableName}
44
- SET data = $1
45
- WHERE id = $2
46
- `;
47
- const data = this.mapper.map(item);
48
- await this.createTableIfNotExists();
49
- await this.pool.query(sql, [data, item.getId()]);
50
- }
51
- async discard(item) {
52
- item.discard();
53
- await this.update(item);
54
- }
55
- async getPool() {
56
- await this.createTableIfNotExists();
57
- return this.pool;
58
- }
59
- async createTableIfNotExists() {
60
- if (this.tableIsCreated) {
61
- return;
62
- }
63
- await this.pool.query(`CREATE TABLE IF NOT EXISTS ${this.tableName} (
64
- id TEXT PRIMARY KEY,
65
- data JSONB NOT NULL
66
- )`);
67
- }
68
- }
69
-
70
- export { PgCrudRepository };
@@ -1,17 +0,0 @@
1
- class PgPersistentMapper {
2
- ctor;
3
- constructor(ctor) {
4
- this.ctor = ctor;
5
- }
6
- map(input) {
7
- return JSON.stringify(input['data']);
8
- }
9
- rev(input) {
10
- return new this.ctor(JSON.parse(input));
11
- }
12
- }
13
- function pgMapperFor(ctor) {
14
- return new PgPersistentMapper(ctor);
15
- }
16
-
17
- export { PgPersistentMapper, pgMapperFor };
@@ -1,30 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import '../../../../core/chat/repository/ram/RamChatRepository.js';
3
- import '../../../../core/chat/repository/IChatRepository.js';
4
- import { Chat } from '../../../../core/chat/Chat.js';
5
- import '../../../../core/user/repository/ram/RamUserRepository.js';
6
- import '../../../../core/user/repository/IUserRepository.js';
7
- import { Pool } from 'pg';
8
- import { PgCrudRepository } from '../PgCrudRepository.js';
9
- import { pgMapperFor } from '../PgPersistentMapper.js';
10
- import { singleton } from '../../../../injection/index.js';
11
-
12
- let PgChatRepository = class PgChatRepository extends PgCrudRepository {
13
- constructor(pool) {
14
- super(pool, 'chat', pgMapperFor(Chat));
15
- }
16
- async findByConnection(query) {
17
- await this.getPool();
18
- throw new Error('Method not implemented.');
19
- }
20
- async findMemory(chatId) {
21
- await this.getPool();
22
- throw new Error('Method not implemented.');
23
- }
24
- };
25
- PgChatRepository = __decorate([
26
- singleton(),
27
- __metadata("design:paramtypes", [Pool])
28
- ], PgChatRepository);
29
-
30
- export { PgChatRepository };
@@ -1,33 +0,0 @@
1
- import '../../../../core/chat/repository/ram/RamChatRepository.js';
2
- import '../../../../core/chat/repository/IChatRepository.js';
3
- import { User } from '../../../../core/user/User.js';
4
- import '../../../../core/user/repository/ram/RamUserRepository.js';
5
- import '../../../../core/user/repository/IUserRepository.js';
6
- import path from 'path';
7
- import { SqliteCrudRepository } from '../SqliteCrudRepository.js';
8
-
9
- const userSqliteMapper = {
10
- map(input) {
11
- return JSON.stringify(input['data']);
12
- },
13
- rev(input) {
14
- const data = JSON.parse(input);
15
- data.createdAt = new Date(data.createdAt);
16
- data.discardedAt = data.discardedAt && new Date(data.discardedAt);
17
- return new User(data);
18
- },
19
- };
20
- class SqliteUserRepository extends SqliteCrudRepository {
21
- constructor() {
22
- super('user', SqliteUserRepository.getDbPath(), userSqliteMapper);
23
- }
24
- async findByConnection(query) {
25
- const allItems = await this.findAll();
26
- return allItems.find((item) => item.hasConnection(query)) ?? null;
27
- }
28
- static getDbPath() {
29
- return path.join(process.cwd(), '.sqlite', 'user.db');
30
- }
31
- }
32
-
33
- export { SqliteUserRepository };
File without changes