@elysiumjs/mnemosyne-drizzle 0.1.4 → 0.2.0
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/.omc/state/agent-replay-3920b579-6d8e-4f5f-924a-319202936685.jsonl +7 -0
- package/.omc/state/sessions/3920b579-6d8e-4f5f-924a-319202936685/last-tool-error-state.json +7 -0
- package/.omc/state/sessions/3920b579-6d8e-4f5f-924a-319202936685/mission-state.json +93 -0
- package/.omc/state/sessions/3920b579-6d8e-4f5f-924a-319202936685/pre-tool-advisory-throttle.json +18 -0
- package/.omc/state/sessions/3920b579-6d8e-4f5f-924a-319202936685/subagent-tracking-state.json +61 -0
- package/.turbo/turbo-build.log +3 -9
- package/CHANGELOG.md +40 -0
- package/README.md +51 -0
- package/dist/commands/migration_generate.command.d.ts +11 -0
- package/dist/commands/migration_generate.command.js +1 -0
- package/dist/commands/migration_run.command.d.ts +13 -0
- package/dist/commands/migration_run.command.js +15 -0
- package/dist/database.d.ts +9 -1
- package/dist/database.js +1 -0
- package/dist/drizzle.module.d.ts +40 -0
- package/dist/drizzle.module.js +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -2
- package/dist/migrations.d.ts +33 -0
- package/dist/migrations.js +1 -0
- package/dist/model.d.ts +5 -5
- package/dist/model.js +1 -0
- package/dist/repository.js +1 -0
- package/dist/table.d.ts +47 -123
- package/dist/table.js +1 -0
- package/dist/tenancy.d.ts +3 -3
- package/dist/tenancy.js +1 -0
- package/package.json +11 -9
- package/scripts/minify.ts +10 -0
- package/src/commands/migration_generate.command.ts +101 -0
- package/src/commands/migration_run.command.ts +160 -0
- package/src/database.ts +37 -7
- package/src/drizzle.module.ts +97 -0
- package/src/index.ts +1 -31
- package/src/migrations.ts +100 -0
- package/src/model.ts +18 -11
- package/src/table.ts +4 -4
- package/src/tenancy.ts +5 -5
- package/tests/drizzle.module.test.ts +201 -0
- package/tests/migrations.test.ts +123 -0
- package/tests/setup.ts +0 -10
- package/tsconfig.json +2 -2
- package/.turbo/turbo-typecheck.log +0 -1
- package/coverage/.lcov.info.01ffde0d9f956dce.tmp +0 -14
- package/coverage/.lcov.info.2f80a4def3a82099.tmp +0 -343
- package/coverage/.lcov.info.560a2daaba0934cd.tmp +0 -366
- package/coverage/.lcov.info.7162c9b788dc0bc6.tmp +0 -366
- package/coverage/.lcov.info.b57c0b452c3901e5.tmp +0 -17
- package/coverage/.lcov.info.c47de8626f331696.tmp +0 -17
- package/coverage/.lcov.info.c710a42b25b08349.tmp +0 -343
- package/coverage/.lcov.info.dbc8f065467fc8a2.tmp +0 -287
- package/coverage/.lcov.info.de180a43301f82c0.tmp +0 -35
- package/coverage/.lcov.info.df18163ab929ab1b.tmp +0 -357
- package/coverage/.lcov.info.febf711c192f5c0c.tmp +0 -17
- package/coverage/lcov.info +0 -357
- package/tests/database.test.ts +0 -198
package/tests/database.test.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, jest, mock, spyOn } from 'bun:test';
|
|
16
|
-
|
|
17
|
-
import { Application, Service } from '@elysiumjs/core';
|
|
18
|
-
|
|
19
|
-
import { Database } from '../src/database';
|
|
20
|
-
|
|
21
|
-
// Mock drizzle function
|
|
22
|
-
mock.module('drizzle-orm/bun-sql', () => ({
|
|
23
|
-
drizzle: mock(() => ({ mockDrizzleInstance: true }))
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
describe('DrizzleDatabase', () => {
|
|
27
|
-
// Mock console.error and process.exit to prevent actual console output and process exit
|
|
28
|
-
const originalConsoleError = console.error;
|
|
29
|
-
const originalProcessExit = process.exit;
|
|
30
|
-
|
|
31
|
-
beforeAll(() => {
|
|
32
|
-
// Mock Application.context so that getConnection('default') works
|
|
33
|
-
const mockContext = {
|
|
34
|
-
getStore: mock(() => new Map())
|
|
35
|
-
};
|
|
36
|
-
Object.defineProperty(Application, 'context', {
|
|
37
|
-
get: () => mockContext,
|
|
38
|
-
configurable: true
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
console.error = mock();
|
|
44
|
-
process.exit = mock() as any;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
afterEach(() => {
|
|
48
|
-
console.error = originalConsoleError;
|
|
49
|
-
process.exit = originalProcessExit;
|
|
50
|
-
jest.clearAllMocks();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterAll(() => {
|
|
54
|
-
mock.restore();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('registerConnection', () => {
|
|
58
|
-
it('should register a new connection', () => {
|
|
59
|
-
// Mock Service.exists to return false (connection doesn't exist)
|
|
60
|
-
const existsSpy = spyOn(Service, 'exists').mockReturnValueOnce(false);
|
|
61
|
-
const instanceSpy = spyOn(Service, 'instance');
|
|
62
|
-
|
|
63
|
-
// Call the function
|
|
64
|
-
const result = Database.registerConnection('test', { connection: 'sqlite:test.db' });
|
|
65
|
-
|
|
66
|
-
// Check if Service.exists was called with the correct connection name
|
|
67
|
-
expect(existsSpy).toHaveBeenCalledWith('db.connection.test');
|
|
68
|
-
|
|
69
|
-
// Check if Service.instance was called with the correct parameters
|
|
70
|
-
expect(instanceSpy).toHaveBeenCalledWith('db.connection.test', {
|
|
71
|
-
mockDrizzleInstance: true
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// Check if the result is correct
|
|
75
|
-
expect(result as any).toEqual({ mockDrizzleInstance: true });
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should exit if the connection already exists', () => {
|
|
79
|
-
// Mock Service.exists to return true (connection exists)
|
|
80
|
-
spyOn(Service, 'exists').mockReturnValueOnce(true);
|
|
81
|
-
|
|
82
|
-
// Call the function
|
|
83
|
-
Database.registerConnection('test', { connection: 'sqlite:test.db' });
|
|
84
|
-
|
|
85
|
-
// Check if console.error and process.exit were called
|
|
86
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
87
|
-
expect.stringContaining('A connection with the name test has already been registered')
|
|
88
|
-
);
|
|
89
|
-
expect(process.exit).toHaveBeenCalledWith(1);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('getConnection', () => {
|
|
94
|
-
it('should retrieve an existing connection', () => {
|
|
95
|
-
// Mock Service.exists to return true (connection exists)
|
|
96
|
-
const existsSpy = spyOn(Service, 'exists').mockReturnValueOnce(true);
|
|
97
|
-
|
|
98
|
-
// Mock Service.get to return a mock connection
|
|
99
|
-
const mockConnection = { mockConnection: true };
|
|
100
|
-
const getSpy = spyOn(Service, 'get').mockReturnValue(mockConnection);
|
|
101
|
-
|
|
102
|
-
// Call the function
|
|
103
|
-
const result = Database.getConnection('test');
|
|
104
|
-
|
|
105
|
-
// Check if Service.exists was called with the correct connection name
|
|
106
|
-
expect(existsSpy).toHaveBeenCalledWith('db.connection.test');
|
|
107
|
-
|
|
108
|
-
// Check if Service.get was called with the correct connection name
|
|
109
|
-
expect(getSpy).toHaveBeenCalledWith('db.connection.test');
|
|
110
|
-
|
|
111
|
-
// Check if the result is correct
|
|
112
|
-
expect(result as any).toEqual(mockConnection);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should exit if the connection does not exist', () => {
|
|
116
|
-
// Mock Service.exists to return false (connection doesn't exist)
|
|
117
|
-
spyOn(Service, 'exists').mockReturnValueOnce(false);
|
|
118
|
-
|
|
119
|
-
// Call the function
|
|
120
|
-
Database.getConnection('test');
|
|
121
|
-
|
|
122
|
-
// Check if console.error and process.exit were called
|
|
123
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
124
|
-
expect.stringContaining('No connection with name test found')
|
|
125
|
-
);
|
|
126
|
-
expect(process.exit).toHaveBeenCalledWith(1);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('connectionExists', () => {
|
|
131
|
-
it('should return true if the connection exists', () => {
|
|
132
|
-
// Mock Service.exists to return true
|
|
133
|
-
const existsSpy = spyOn(Service, 'exists').mockReturnValueOnce(true);
|
|
134
|
-
|
|
135
|
-
// Call the function
|
|
136
|
-
const result = Database.connectionExists('test');
|
|
137
|
-
|
|
138
|
-
// Check if Service.exists was called with the correct connection name
|
|
139
|
-
expect(existsSpy).toHaveBeenCalledWith('db.connection.test');
|
|
140
|
-
|
|
141
|
-
// Check if the result is correct
|
|
142
|
-
expect(result).toBe(true);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('should return false if the connection does not exist', () => {
|
|
146
|
-
// Mock Service.exists to return false
|
|
147
|
-
const existsSpy = spyOn(Service, 'exists').mockReturnValueOnce(false);
|
|
148
|
-
|
|
149
|
-
// Call the function
|
|
150
|
-
const result = Database.connectionExists('test');
|
|
151
|
-
|
|
152
|
-
// Check if Service.exists was called with the correct connection name
|
|
153
|
-
expect(existsSpy).toHaveBeenCalledWith('db.connection.test');
|
|
154
|
-
|
|
155
|
-
// Check if the result is correct
|
|
156
|
-
expect(result).toBe(false);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
describe('getDefaultConnection', () => {
|
|
161
|
-
it('should retrieve the default connection', () => {
|
|
162
|
-
// Mock Service to return the mock connection
|
|
163
|
-
const mockConnection = { mockConnection: true };
|
|
164
|
-
spyOn(Service, 'exists').mockReturnValueOnce(true);
|
|
165
|
-
spyOn(Service, 'get').mockReturnValue(mockConnection);
|
|
166
|
-
|
|
167
|
-
// Call the function
|
|
168
|
-
const result = Database.getDefaultConnection();
|
|
169
|
-
|
|
170
|
-
// Check if the result is correct
|
|
171
|
-
expect(result as any).toEqual(mockConnection);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe('setDefaultConnection', () => {
|
|
176
|
-
it('should set the default connection', () => {
|
|
177
|
-
const instanceSpy = spyOn(Service, 'instance');
|
|
178
|
-
const removeSpy = spyOn(Service, 'remove');
|
|
179
|
-
spyOn(Service, 'exists').mockReturnValueOnce(true);
|
|
180
|
-
|
|
181
|
-
// Mock Service.get to return a mock connection
|
|
182
|
-
const mockConnection = { mockConnection: true };
|
|
183
|
-
spyOn(Service, 'get').mockReturnValue(mockConnection);
|
|
184
|
-
|
|
185
|
-
// Call the function
|
|
186
|
-
const result = Database.setDefaultConnection('test');
|
|
187
|
-
|
|
188
|
-
// Check if Service.remove was called with the correct connection name
|
|
189
|
-
expect(removeSpy).toHaveBeenCalledWith('db.connection.default');
|
|
190
|
-
|
|
191
|
-
// Check if Service.instance was called with the correct parameters
|
|
192
|
-
expect(instanceSpy).toHaveBeenCalledWith('db.connection.default', mockConnection);
|
|
193
|
-
|
|
194
|
-
// Check if the result is correct
|
|
195
|
-
expect(result as any).toEqual(mockConnection);
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
});
|