@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/audit",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -221,7 +221,7 @@ describe('KyselyAuditStorage', () => {
221
221
  expect(calledValues[0].id).toBeUndefined();
222
222
  });
223
223
 
224
- it('should use provided ID when autoId is true', async () => {
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
- expect(mockDb.insertBuilder.values).toHaveBeenCalledWith([
243
- expect.objectContaining({
244
- id: 'explicit-id',
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 (omit if not provided)
331
- // If autoId is false (default), generate with nanoid if not provided
332
- const id = record.id || (this.autoId ? undefined : nanoid());
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
@@ -1,4 +1,4 @@
1
- import type { AuditableAction, AuditRecord } from './types';
1
+ import type { AuditRecord, AuditableAction } from './types';
2
2
 
3
3
  /**
4
4
  * Options for querying audit records.