@elysiumjs/mnemosyne 0.1.2 → 0.3.1
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/CHANGELOG.md +90 -0
- package/README.md +19 -16
- package/dist/cache.d.ts +134 -0
- package/dist/database.d.ts +127 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +2 -0
- package/dist/interfaces.d.ts +360 -0
- package/dist/keyv-redis.d.ts +88 -0
- package/dist/mnemosyne.module.d.ts +44 -0
- package/dist/model.d.ts +68 -0
- package/dist/repository.d.ts +96 -0
- package/dist/tenancy.d.ts +201 -0
- package/package.json +21 -12
- package/bunfig.toml +0 -19
- package/src/cache.ts +0 -218
- package/src/database.ts +0 -151
- package/src/index.ts +0 -47
- package/src/interfaces.ts +0 -449
- package/src/keyv-redis.ts +0 -313
- package/src/model.ts +0 -189
- package/src/repository.ts +0 -137
- package/src/tenancy.ts +0 -291
- package/tests/cache.test.ts +0 -464
- package/tests/database.test.ts +0 -249
- package/tests/model.test.ts +0 -234
- package/tests/repository.test.ts +0 -177
- package/tests/setup.ts +0 -26
- package/tsconfig.json +0 -12
package/tests/model.test.ts
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025-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 { describe, expect, it } from 'bun:test';
|
|
16
|
-
import { t } from 'elysia';
|
|
17
|
-
|
|
18
|
-
import type { ColumnMetadata } from '../src/interfaces';
|
|
19
|
-
|
|
20
|
-
import { createSchemaFromModel, AbstractModel } from '../src/model';
|
|
21
|
-
|
|
22
|
-
// Hand-crafted column metadata for testing
|
|
23
|
-
const userColumns: ColumnMetadata[] = [
|
|
24
|
-
{ name: 'id', dataType: 'uuid', nullable: false, hasDefault: true, isPrimaryKey: true },
|
|
25
|
-
{ name: 'name', dataType: 'string', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
26
|
-
{ name: 'age', dataType: 'number', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
27
|
-
{ name: 'email', dataType: 'string', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
28
|
-
{ name: 'is_confirmed', dataType: 'boolean', nullable: false, hasDefault: true, isPrimaryKey: false },
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
describe('Model', () => {
|
|
32
|
-
describe('createSchemaFromModel', () => {
|
|
33
|
-
it('should create a schema for select mode', () => {
|
|
34
|
-
const schema = createSchemaFromModel(userColumns, { mode: 'select' });
|
|
35
|
-
|
|
36
|
-
// Select mode should include all columns including primary key
|
|
37
|
-
expect(schema.properties).toBeDefined();
|
|
38
|
-
expect(schema.properties.id).toBeDefined();
|
|
39
|
-
expect(schema.properties.name).toBeDefined();
|
|
40
|
-
expect(schema.properties.age).toBeDefined();
|
|
41
|
-
expect(schema.properties.email).toBeDefined();
|
|
42
|
-
expect(schema.properties.is_confirmed).toBeDefined();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should create a schema for create mode', () => {
|
|
46
|
-
const schema = createSchemaFromModel(userColumns, { mode: 'create' });
|
|
47
|
-
|
|
48
|
-
// Create mode should exclude primary key
|
|
49
|
-
expect(schema.properties).toBeDefined();
|
|
50
|
-
expect(schema.properties.id).toBeUndefined();
|
|
51
|
-
expect(schema.properties.name).toBeDefined();
|
|
52
|
-
expect(schema.properties.age).toBeDefined();
|
|
53
|
-
expect(schema.properties.email).toBeDefined();
|
|
54
|
-
expect(schema.properties.is_confirmed).toBeDefined();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should create a schema for update mode', () => {
|
|
58
|
-
const schema = createSchemaFromModel(userColumns, { mode: 'update' });
|
|
59
|
-
|
|
60
|
-
// Update mode should exclude primary key
|
|
61
|
-
expect(schema.properties).toBeDefined();
|
|
62
|
-
expect(schema.properties.id).toBeUndefined();
|
|
63
|
-
expect(schema.properties.name).toBeDefined();
|
|
64
|
-
expect(schema.properties.age).toBeDefined();
|
|
65
|
-
expect(schema.properties.email).toBeDefined();
|
|
66
|
-
expect(schema.properties.is_confirmed).toBeDefined();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should make all fields optional in update mode', () => {
|
|
70
|
-
const columns: ColumnMetadata[] = [
|
|
71
|
-
{ name: 'id', dataType: 'uuid', nullable: false, hasDefault: true, isPrimaryKey: true },
|
|
72
|
-
{ name: 'name', dataType: 'string', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
const schema = createSchemaFromModel(columns, { mode: 'update' });
|
|
76
|
-
|
|
77
|
-
// In update mode, all non-PK fields should be optional (not required)
|
|
78
|
-
const required = schema.required ?? [];
|
|
79
|
-
expect(required).not.toContain('name');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should make fields with defaults optional in create mode', () => {
|
|
83
|
-
const columns: ColumnMetadata[] = [
|
|
84
|
-
{ name: 'id', dataType: 'uuid', nullable: false, hasDefault: true, isPrimaryKey: true },
|
|
85
|
-
{ name: 'status', dataType: 'string', nullable: false, hasDefault: true, isPrimaryKey: false },
|
|
86
|
-
{ name: 'name', dataType: 'string', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
87
|
-
];
|
|
88
|
-
|
|
89
|
-
const schema = createSchemaFromModel(columns, { mode: 'create' });
|
|
90
|
-
|
|
91
|
-
// 'status' has a default, so it should be optional
|
|
92
|
-
// 'name' does not have a default, so it should be required
|
|
93
|
-
expect(schema.properties.status).toBeDefined();
|
|
94
|
-
expect(schema.properties.name).toBeDefined();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should handle nullable columns', () => {
|
|
98
|
-
const columns: ColumnMetadata[] = [
|
|
99
|
-
{ name: 'bio', dataType: 'string', nullable: true, hasDefault: false, isPrimaryKey: false },
|
|
100
|
-
];
|
|
101
|
-
|
|
102
|
-
const schema = createSchemaFromModel(columns, { mode: 'select' });
|
|
103
|
-
|
|
104
|
-
// Nullable columns should be wrapped in t.Nullable
|
|
105
|
-
expect(schema.properties.bio).toBeDefined();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should return an empty object schema for empty columns', () => {
|
|
109
|
-
const schema = createSchemaFromModel([]);
|
|
110
|
-
|
|
111
|
-
// Should return t.Object({})
|
|
112
|
-
expect(schema.properties).toBeDefined();
|
|
113
|
-
expect(Object.keys(schema.properties)).toHaveLength(0);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should return an empty object schema for undefined columns', () => {
|
|
117
|
-
// @ts-expect-error Testing undefined input
|
|
118
|
-
const schema = createSchemaFromModel(undefined);
|
|
119
|
-
|
|
120
|
-
// Should return t.Object({})
|
|
121
|
-
expect(schema.properties).toBeDefined();
|
|
122
|
-
expect(Object.keys(schema.properties)).toHaveLength(0);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('should handle all supported data types', () => {
|
|
126
|
-
const allTypeColumns: ColumnMetadata[] = [
|
|
127
|
-
{ name: 'col_string', dataType: 'string', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
128
|
-
{ name: 'col_uuid', dataType: 'uuid', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
129
|
-
{ name: 'col_number', dataType: 'number', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
130
|
-
{ name: 'col_boolean', dataType: 'boolean', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
131
|
-
{ name: 'col_array', dataType: 'array', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
132
|
-
{ name: 'col_json', dataType: 'json', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
133
|
-
{ name: 'col_date', dataType: 'date', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
134
|
-
{ name: 'col_datetime', dataType: 'datetime', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
135
|
-
{ name: 'col_bigint', dataType: 'bigint', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
136
|
-
{ name: 'col_buffer', dataType: 'buffer', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
137
|
-
];
|
|
138
|
-
|
|
139
|
-
const schema = createSchemaFromModel(allTypeColumns, { mode: 'select' });
|
|
140
|
-
|
|
141
|
-
// All data types should produce a valid schema property
|
|
142
|
-
expect(schema.properties.col_string).toBeDefined();
|
|
143
|
-
expect(schema.properties.col_uuid).toBeDefined();
|
|
144
|
-
expect(schema.properties.col_number).toBeDefined();
|
|
145
|
-
expect(schema.properties.col_boolean).toBeDefined();
|
|
146
|
-
expect(schema.properties.col_array).toBeDefined();
|
|
147
|
-
expect(schema.properties.col_json).toBeDefined();
|
|
148
|
-
expect(schema.properties.col_date).toBeDefined();
|
|
149
|
-
expect(schema.properties.col_datetime).toBeDefined();
|
|
150
|
-
expect(schema.properties.col_bigint).toBeDefined();
|
|
151
|
-
expect(schema.properties.col_buffer).toBeDefined();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('should default to select mode when no mode is specified', () => {
|
|
155
|
-
const columns: ColumnMetadata[] = [
|
|
156
|
-
{ name: 'id', dataType: 'uuid', nullable: false, hasDefault: true, isPrimaryKey: true },
|
|
157
|
-
{ name: 'name', dataType: 'string', nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
158
|
-
];
|
|
159
|
-
|
|
160
|
-
const schema = createSchemaFromModel(columns);
|
|
161
|
-
|
|
162
|
-
// Default mode should be 'select', which includes primary key
|
|
163
|
-
expect(schema.properties.id).toBeDefined();
|
|
164
|
-
expect(schema.properties.name).toBeDefined();
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
describe('AbstractModel', () => {
|
|
169
|
-
it('should create a model class with the correct properties', () => {
|
|
170
|
-
const mockAdapter = {
|
|
171
|
-
getTableName: () => 'users',
|
|
172
|
-
getColumns: () => userColumns,
|
|
173
|
-
createTenantTable: (table: any, tenant: string) => table,
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const mockTable = { _tableName: 'users' };
|
|
177
|
-
|
|
178
|
-
class UserModel extends AbstractModel('users', { id: 'uuid', name: 'text' }, mockAdapter, mockTable) {}
|
|
179
|
-
|
|
180
|
-
// Check if the model class has the correct static properties
|
|
181
|
-
expect(UserModel.tableName).toBe('users');
|
|
182
|
-
expect(UserModel.columns).toEqual({ id: 'uuid', name: 'text' });
|
|
183
|
-
expect(UserModel.insertSchema).toBeDefined();
|
|
184
|
-
expect(UserModel.updateSchema).toBeDefined();
|
|
185
|
-
expect(UserModel.selectSchema).toBeDefined();
|
|
186
|
-
expect(UserModel.supportTenancy).toBe(false);
|
|
187
|
-
expect(UserModel.$inferSelect).toBeUndefined();
|
|
188
|
-
expect(UserModel.$inferInsert).toBeUndefined();
|
|
189
|
-
expect(UserModel.$inferUpdate).toBeUndefined();
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('should use the adapter to extract column metadata', () => {
|
|
193
|
-
const getColumnsSpy = { called: false };
|
|
194
|
-
const mockAdapter = {
|
|
195
|
-
getTableName: () => 'products',
|
|
196
|
-
getColumns: (table: any) => {
|
|
197
|
-
getColumnsSpy.called = true;
|
|
198
|
-
return [
|
|
199
|
-
{ name: 'id', dataType: 'uuid' as const, nullable: false, hasDefault: true, isPrimaryKey: true },
|
|
200
|
-
{ name: 'title', dataType: 'string' as const, nullable: false, hasDefault: false, isPrimaryKey: false },
|
|
201
|
-
];
|
|
202
|
-
},
|
|
203
|
-
createTenantTable: (table: any, tenant: string) => table,
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
const mockTable = { _tableName: 'products' };
|
|
207
|
-
|
|
208
|
-
class ProductModel extends AbstractModel('products', { id: 'uuid', title: 'text' }, mockAdapter, mockTable) {}
|
|
209
|
-
|
|
210
|
-
// The adapter's getColumns should have been called during model creation
|
|
211
|
-
expect(getColumnsSpy.called).toBe(true);
|
|
212
|
-
|
|
213
|
-
// Schemas should be generated from the adapter's column metadata
|
|
214
|
-
expect(ProductModel.insertSchema.properties.title).toBeDefined();
|
|
215
|
-
expect(ProductModel.insertSchema.properties.id).toBeUndefined(); // primary key excluded in create mode
|
|
216
|
-
expect(ProductModel.selectSchema.properties.id).toBeDefined(); // primary key included in select mode
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('should expose the table via the static table getter', () => {
|
|
220
|
-
const mockAdapter = {
|
|
221
|
-
getTableName: () => 'items',
|
|
222
|
-
getColumns: () => [],
|
|
223
|
-
createTenantTable: (table: any, tenant: string) => table,
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
const mockTable = { _tableName: 'items' };
|
|
227
|
-
|
|
228
|
-
class ItemModel extends AbstractModel('items', {}, mockAdapter, mockTable) {}
|
|
229
|
-
|
|
230
|
-
// The table getter should return the base table when not in a tenancy context
|
|
231
|
-
expect(ItemModel.table).toBe(mockTable);
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
});
|
package/tests/repository.test.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025-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 { describe, expect, it, mock, spyOn } from 'bun:test';
|
|
16
|
-
|
|
17
|
-
import { AbstractDatabase } from '../src/database';
|
|
18
|
-
import { AbstractRepository } from '../src/repository';
|
|
19
|
-
|
|
20
|
-
// Create a mock driver
|
|
21
|
-
const mockDriver = {
|
|
22
|
-
createConnection: mock((config: any) => ({ mockConnection: true, config })),
|
|
23
|
-
withTransaction: mock((conn: any, cb: any) => cb(conn)),
|
|
24
|
-
getRawClient: mock((conn: any) => ({ rawClient: true })),
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Create a concrete database class for testing
|
|
28
|
-
class TestDatabase extends AbstractDatabase<any, any> {
|
|
29
|
-
protected driver = mockDriver;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Create a mock model
|
|
33
|
-
const MockModel = {
|
|
34
|
-
$inferSelect: undefined as unknown,
|
|
35
|
-
$inferInsert: undefined as unknown,
|
|
36
|
-
$inferUpdate: undefined as unknown,
|
|
37
|
-
table: { _tableName: 'test_table' },
|
|
38
|
-
tableName: 'test_table',
|
|
39
|
-
columns: { id: 'uuid', name: 'text' },
|
|
40
|
-
insertSchema: {},
|
|
41
|
-
updateSchema: {},
|
|
42
|
-
selectSchema: {},
|
|
43
|
-
supportTenancy: false,
|
|
44
|
-
} as any;
|
|
45
|
-
|
|
46
|
-
describe('AbstractRepository', () => {
|
|
47
|
-
describe('Repository creation', () => {
|
|
48
|
-
it('should create a repository class with the correct model', () => {
|
|
49
|
-
const db = new TestDatabase();
|
|
50
|
-
const TestRepository = AbstractRepository(MockModel, db);
|
|
51
|
-
|
|
52
|
-
expect(TestRepository.Model).toBe(MockModel);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should set the default connection name', () => {
|
|
56
|
-
const db = new TestDatabase();
|
|
57
|
-
const TestRepository = AbstractRepository(MockModel, db);
|
|
58
|
-
|
|
59
|
-
expect(TestRepository.connection).toBe('default');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('Database connection', () => {
|
|
64
|
-
it('should get the database connection via the db getter', () => {
|
|
65
|
-
const db = new TestDatabase();
|
|
66
|
-
const mockConnection = { mockConnection: true };
|
|
67
|
-
const getConnectionSpy = spyOn(db, 'getConnection').mockReturnValue(mockConnection);
|
|
68
|
-
|
|
69
|
-
const TestRepository = AbstractRepository(MockModel, db);
|
|
70
|
-
|
|
71
|
-
// Create a concrete subclass since AbstractRepository returns an abstract class
|
|
72
|
-
class ConcreteRepository extends TestRepository {
|
|
73
|
-
public async all() { return []; }
|
|
74
|
-
public async paginate() { return { page: 1, data: [], total: 0 }; }
|
|
75
|
-
public async find() { return null; }
|
|
76
|
-
public async findBy() { return null; }
|
|
77
|
-
public async insert(data: any) { return data; }
|
|
78
|
-
public async update(id: any, data: any) { return data; }
|
|
79
|
-
public async updateAll(data: any) { return [data]; }
|
|
80
|
-
public async delete(id: any) { return {}; }
|
|
81
|
-
public async deleteAll() { return []; }
|
|
82
|
-
public async exists(id: any) { return false; }
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const repo = new ConcreteRepository();
|
|
86
|
-
const connection = repo.db;
|
|
87
|
-
|
|
88
|
-
expect(getConnectionSpy).toHaveBeenCalledWith('default');
|
|
89
|
-
expect(connection).toBe(mockConnection);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should use a custom connection if specified', () => {
|
|
93
|
-
const db = new TestDatabase();
|
|
94
|
-
const mockConnection = { mockConnection: true };
|
|
95
|
-
const getConnectionSpy = spyOn(db, 'getConnection').mockReturnValue(mockConnection);
|
|
96
|
-
|
|
97
|
-
const TestRepository = AbstractRepository(MockModel, db);
|
|
98
|
-
|
|
99
|
-
// Create a concrete subclass with a custom connection
|
|
100
|
-
class CustomRepository extends TestRepository {
|
|
101
|
-
public static readonly connection = 'custom';
|
|
102
|
-
public async all() { return []; }
|
|
103
|
-
public async paginate() { return { page: 1, data: [], total: 0 }; }
|
|
104
|
-
public async find() { return null; }
|
|
105
|
-
public async findBy() { return null; }
|
|
106
|
-
public async insert(data: any) { return data; }
|
|
107
|
-
public async update(id: any, data: any) { return data; }
|
|
108
|
-
public async updateAll(data: any) { return [data]; }
|
|
109
|
-
public async delete(id: any) { return {}; }
|
|
110
|
-
public async deleteAll() { return []; }
|
|
111
|
-
public async exists(id: any) { return false; }
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const repo = new CustomRepository();
|
|
115
|
-
const connection = repo.db;
|
|
116
|
-
|
|
117
|
-
expect(getConnectionSpy).toHaveBeenCalledWith('custom');
|
|
118
|
-
expect(connection).toBe(mockConnection);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe('Abstract methods', () => {
|
|
123
|
-
it('should be subclassable with all CRUD methods implemented', () => {
|
|
124
|
-
const db = new TestDatabase();
|
|
125
|
-
const TestRepository = AbstractRepository(MockModel, db);
|
|
126
|
-
|
|
127
|
-
// Create a concrete subclass implementing all abstract methods
|
|
128
|
-
class ConcreteRepository extends TestRepository {
|
|
129
|
-
public async all() { return []; }
|
|
130
|
-
public async paginate() { return { page: 1, data: [], total: 0 }; }
|
|
131
|
-
public async find() { return null; }
|
|
132
|
-
public async findBy() { return null; }
|
|
133
|
-
public async insert(data: any) { return data; }
|
|
134
|
-
public async update(id: any, data: any) { return data; }
|
|
135
|
-
public async updateAll(data: any) { return [data]; }
|
|
136
|
-
public async delete(id: any) { return {}; }
|
|
137
|
-
public async deleteAll() { return []; }
|
|
138
|
-
public async exists(id: any) { return false; }
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const repo = new ConcreteRepository();
|
|
142
|
-
expect(repo).toBeInstanceOf(ConcreteRepository);
|
|
143
|
-
expect(repo).toBeInstanceOf(TestRepository);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('should have all required CRUD methods on the concrete subclass', () => {
|
|
147
|
-
const db = new TestDatabase();
|
|
148
|
-
const TestRepository = AbstractRepository(MockModel, db);
|
|
149
|
-
|
|
150
|
-
class ConcreteRepository extends TestRepository {
|
|
151
|
-
public async all() { return []; }
|
|
152
|
-
public async paginate() { return { page: 1, data: [], total: 0 }; }
|
|
153
|
-
public async find() { return null; }
|
|
154
|
-
public async findBy() { return null; }
|
|
155
|
-
public async insert(data: any) { return data; }
|
|
156
|
-
public async update(id: any, data: any) { return data; }
|
|
157
|
-
public async updateAll(data: any) { return [data]; }
|
|
158
|
-
public async delete(id: any) { return {}; }
|
|
159
|
-
public async deleteAll() { return []; }
|
|
160
|
-
public async exists(id: any) { return false; }
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const repo = new ConcreteRepository();
|
|
164
|
-
|
|
165
|
-
expect(typeof repo.all).toBe('function');
|
|
166
|
-
expect(typeof repo.paginate).toBe('function');
|
|
167
|
-
expect(typeof repo.find).toBe('function');
|
|
168
|
-
expect(typeof repo.findBy).toBe('function');
|
|
169
|
-
expect(typeof repo.insert).toBe('function');
|
|
170
|
-
expect(typeof repo.update).toBe('function');
|
|
171
|
-
expect(typeof repo.updateAll).toBe('function');
|
|
172
|
-
expect(typeof repo.delete).toBe('function');
|
|
173
|
-
expect(typeof repo.deleteAll).toBe('function');
|
|
174
|
-
expect(typeof repo.exists).toBe('function');
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
package/tests/setup.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025-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 'reflect-metadata';
|
|
16
|
-
|
|
17
|
-
import { mock } from 'bun:test';
|
|
18
|
-
|
|
19
|
-
// Mock dependencies
|
|
20
|
-
|
|
21
|
-
mock.module('node:async_hooks', () => ({
|
|
22
|
-
AsyncLocalStorage: class {
|
|
23
|
-
public run = mock((_map, callback) => callback());
|
|
24
|
-
public disable = mock();
|
|
25
|
-
}
|
|
26
|
-
}));
|
package/tsconfig.json
DELETED