@geekmidas/audit 0.0.5 → 0.0.7
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/package.json
CHANGED
|
@@ -221,7 +221,7 @@ describe('KyselyAuditStorage', () => {
|
|
|
221
221
|
expect(calledValues[0].id).toBeUndefined();
|
|
222
222
|
});
|
|
223
223
|
|
|
224
|
-
it('should
|
|
224
|
+
it('should omit ID even if provided when autoId is true', async () => {
|
|
225
225
|
const storageAutoId = new KyselyAuditStorage({
|
|
226
226
|
db: mockDb.db as any,
|
|
227
227
|
tableName: 'audit_logs',
|
|
@@ -230,7 +230,7 @@ describe('KyselyAuditStorage', () => {
|
|
|
230
230
|
|
|
231
231
|
const records: AuditRecord[] = [
|
|
232
232
|
{
|
|
233
|
-
id: 'explicit-id',
|
|
233
|
+
id: 'explicit-id', // This should be ignored when autoId is true
|
|
234
234
|
type: 'user.created',
|
|
235
235
|
operation: 'CUSTOM',
|
|
236
236
|
timestamp: new Date(),
|
|
@@ -239,11 +239,9 @@ describe('KyselyAuditStorage', () => {
|
|
|
239
239
|
|
|
240
240
|
await storageAutoId.write(records);
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}),
|
|
246
|
-
]);
|
|
242
|
+
// When autoId is true, ID should always be omitted (let database generate)
|
|
243
|
+
const calledValues = mockDb.insertBuilder.values.mock.calls[0][0];
|
|
244
|
+
expect(calledValues[0].id).toBeUndefined();
|
|
247
245
|
});
|
|
248
246
|
});
|
|
249
247
|
|
package/src/kysely.ts
CHANGED
|
@@ -327,9 +327,9 @@ export class KyselyAuditStorage<DB> implements AuditStorage {
|
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
private toRow(record: AuditRecord): AuditLogTable {
|
|
330
|
-
// If autoId is true, let database generate ID (
|
|
331
|
-
// If autoId is false (default), generate with nanoid
|
|
332
|
-
const id =
|
|
330
|
+
// If autoId is true, let database generate ID (ignore record.id)
|
|
331
|
+
// If autoId is false (default), use record.id or generate with nanoid
|
|
332
|
+
const id = this.autoId ? undefined : record.id || nanoid();
|
|
333
333
|
|
|
334
334
|
return {
|
|
335
335
|
...(id && { id }),
|
package/src/storage.ts
CHANGED