Skip to content

Commit fe8f77e

Browse files
committed
Updated usage of uuid in README and tests
1 parent 7f871fd commit fe8f77e

File tree

4 files changed

+25
-30
lines changed

4 files changed

+25
-30
lines changed

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ Read also [introduction article on my blog](https://event-driven.io/en/introduct
2121
You can use Pongo syntax with explicit typing about supported syntax:
2222

2323
```ts
24-
import { pongoClient } from "@event-driven-io/pongo";
25-
import { v7 as uuid } from "uuid";
24+
import { pongoClient, ObjectId } from "@event-driven-io/pongo";
2625

2726
type User = { name: string; age: number };
2827

@@ -35,7 +34,7 @@ const pongoDb = pongo.db();
3534
const users = pongoDb.collection<User>("users");
3635
const roger = { name: "Roger", age: 30 };
3736
const anita = { name: "Anita", age: 25 };
38-
const cruella = { _id: uuid(), name: "Cruella", age: 40 };
37+
const cruella = { _id: ObjectId(), name: "Cruella", age: 40 };
3938

4039
// Inserting
4140
await users.insertOne(roger);
@@ -60,8 +59,7 @@ const usersFromDb = await users.find({ age: { $lt: 40 } });
6059
Or use MongoDB compliant shim:
6160

6261
```ts
63-
import { MongoClient } from "@event-driven-io/pongo/shim";
64-
import { v7 as uuid } from "uuid";
62+
import { MongoClient, ObjectId } from "@event-driven-io/pongo/shim";
6563

6664
type User = { name: string; age: number };
6765

@@ -74,7 +72,7 @@ const pongoDb = pongoClient.db();
7472
const users = pongoDb.collection<User>("users");
7573
const roger = { name: "Roger", age: 30 };
7674
const anita = { name: "Anita", age: 25 };
77-
const cruella = { _id: uuid(), name: "Cruella", age: 40 };
75+
const cruella = { _id: ObjectId(), name: "Cruella", age: 40 };
7876

7977
// Inserting
8078
await users.insertOne(roger);

samples/simple-ts/src/shim.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const pongoDb = pongoClient.db('postgres');
1313
const users = pongoDb.collection<User>('users');
1414
const roger = { name: 'Roger', age: 30 };
1515
const anita = { name: 'Anita', age: 25 };
16-
//const cruella = { _id: uuid(), name: 'Cruella', age: 40 };
16+
//const cruella = { _id: ObjectId(), name: 'Cruella', age: 40 };
1717

1818
// Inserting
1919
await users.insertOne(roger);

src/docs/getting-started.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ Read also [introduction article on my blog](https://event-driven.io/en/introduct
1919
You can use Pongo syntax with explicit typing about supported syntax:
2020

2121
```ts
22-
import { pongoClient } from '@event-driven-io/pongo';
23-
import { v7 as uuid } from 'uuid';
22+
import { pongoClient, ObjectId } from '@event-driven-io/pongo';
2423

2524
type User = { name: string; age: number };
2625

@@ -33,7 +32,7 @@ const pongoDb = pongo.db();
3332
const users = pongoDb.collection<User>('users');
3433
const roger = { name: 'Roger', age: 30 };
3534
const anita = { name: 'Anita', age: 25 };
36-
const cruella = { _id: uuid(), name: 'Cruella', age: 40 };
35+
const cruella = { _id: ObjectId(), name: 'Cruella', age: 40 };
3736

3837
// Inserting
3938
await users.insertOne(roger);
@@ -58,8 +57,7 @@ const usersFromDb = await users.find({ age: { $lt: 40 } });
5857
Or use MongoDB compliant shim:
5958

6059
```ts
61-
import { MongoClient } from '@event-driven-io/pongo/shim';
62-
import { v7 as uuid } from 'uuid';
60+
import { MongoClient, ObjectId } from '@event-driven-io/pongo/shim';
6361

6462
type User = { name: string; age: number };
6563

@@ -72,7 +70,7 @@ const pongoDb = pongoClient.db();
7270
const users = pongoDb.collection<User>('users');
7371
const roger = { name: 'Roger', age: 30 };
7472
const anita = { name: 'Anita', age: 25 };
75-
const cruella = { _id: uuid(), name: 'Cruella', age: 40 };
73+
const cruella = { _id: ObjectId(), name: 'Cruella', age: 40 };
7674

7775
// Inserting
7876
await users.insertOne(roger);

src/packages/pongo/src/e2e/postgres.optimistic-concurrency.spec.ts

+16-17
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import {
55
import assert from 'assert';
66
import console from 'console';
77
import { after, before, beforeEach, describe, it } from 'node:test';
8-
import { v7 as uuid } from 'uuid';
98
import {
9+
ObjectId,
1010
pongoClient,
1111
pongoSchema,
12-
type ObjectId,
1312
type PongoClient,
1413
type PongoCollection,
1514
type PongoDb,
@@ -67,7 +66,7 @@ void describe('MongoDB Compatibility Tests', () => {
6766

6867
beforeEach(() => {
6968
user = {
70-
_id: uuid(),
69+
_id: ObjectId(),
7170
name: 'Anita',
7271
age: 25,
7372
};
@@ -156,7 +155,7 @@ void describe('MongoDB Compatibility Tests', () => {
156155
void describe('insertMany', () => {
157156
void it('inserts a document with id', async () => {
158157
// Given
159-
const otherUser = { ...user, _id: uuid() };
158+
const otherUser = { ...user, _id: ObjectId() };
160159

161160
// When
162161
const pongoInsertResult = await users.insertMany([user, otherUser]);
@@ -185,7 +184,7 @@ void describe('MongoDB Compatibility Tests', () => {
185184
const nonDefaultVersion = 495n;
186185
const otherUser = {
187186
...user,
188-
_id: uuid(),
187+
_id: ObjectId(),
189188
_version: nonDefaultVersion,
190189
};
191190
// When
@@ -225,7 +224,7 @@ void describe('MongoDB Compatibility Tests', () => {
225224
name: 'Cruella',
226225
age: 40,
227226
};
228-
const otherUser = { ...user, _id: uuid() };
227+
const otherUser = { ...user, _id: ObjectId() };
229228
// When
230229
const pongoInsertResult = await users.insertMany([
231230
userWithTheSameId,
@@ -369,8 +368,8 @@ void describe('MongoDB Compatibility Tests', () => {
369368

370369
void describe('updateMany', () => {
371370
void it('updates documents and expected version', async () => {
372-
const otherUser = { ...user, _id: uuid() };
373-
await users.insertMany([user, otherUser, { ...user, _id: uuid() }]);
371+
const otherUser = { ...user, _id: ObjectId() };
372+
await users.insertMany([user, otherUser, { ...user, _id: ObjectId() }]);
374373

375374
// When
376375
const updateResult = await users.updateMany(
@@ -403,7 +402,7 @@ void describe('MongoDB Compatibility Tests', () => {
403402
});
404403

405404
void it('overrides documents version with autoincremented document version', async () => {
406-
const otherUser = { ...user, _id: uuid() };
405+
const otherUser = { ...user, _id: ObjectId() };
407406
await users.insertMany([{ ...user }, otherUser]);
408407

409408
// When
@@ -594,8 +593,8 @@ void describe('MongoDB Compatibility Tests', () => {
594593

595594
void describe('deleteMany', () => {
596595
void it('deletes documents and expected version', async () => {
597-
const otherUser = { ...user, _id: uuid() };
598-
await users.insertMany([user, otherUser, { ...user, _id: uuid() }]);
596+
const otherUser = { ...user, _id: ObjectId() };
597+
await users.insertMany([user, otherUser, { ...user, _id: ObjectId() }]);
599598

600599
// When
601600
const deleteResult = await users.deleteMany({
@@ -616,7 +615,7 @@ void describe('MongoDB Compatibility Tests', () => {
616615
});
617616

618617
void it('overrides documents version with autoincremented document version', async () => {
619-
const otherUser = { ...user, _id: uuid() };
618+
const otherUser = { ...user, _id: ObjectId() };
620619
await users.insertMany([{ ...user }, otherUser]);
621620

622621
// When
@@ -639,7 +638,7 @@ void describe('MongoDB Compatibility Tests', () => {
639638

640639
void describe('Handle Operations', () => {
641640
void it('should NOT insert a new document if it does not exist and expected DOCUMENT_EXISTS', async () => {
642-
const nonExistingId = uuid() as unknown as ObjectId;
641+
const nonExistingId = ObjectId() as unknown as ObjectId;
643642

644643
const newDoc: User = { name: 'John', age: 25 };
645644

@@ -659,7 +658,7 @@ void describe('MongoDB Compatibility Tests', () => {
659658
});
660659

661660
void it('should NOT insert a new document if it does not exist and expected is numeric value', async () => {
662-
const nonExistingId = uuid() as unknown as ObjectId;
661+
const nonExistingId = ObjectId() as unknown as ObjectId;
663662

664663
const newDoc: User = { name: 'John', age: 25 };
665664

@@ -679,7 +678,7 @@ void describe('MongoDB Compatibility Tests', () => {
679678
});
680679

681680
void it('should replace an existing document when expected version matches', async () => {
682-
const existingDoc: User = { _id: uuid(), name: 'John', age: 25 };
681+
const existingDoc: User = { _id: ObjectId(), name: 'John', age: 25 };
683682
const updatedDoc: User = { _id: existingDoc._id!, name: 'John', age: 30 };
684683

685684
const pongoInsertResult = await users.insertOne(existingDoc);
@@ -712,7 +711,7 @@ void describe('MongoDB Compatibility Tests', () => {
712711
});
713712

714713
void it('should NOT replace an existing document when expected DOCUMENT_DOES_NOT_EXIST', async () => {
715-
const existingDoc: User = { _id: uuid(), name: 'John', age: 25 };
714+
const existingDoc: User = { _id: ObjectId(), name: 'John', age: 25 };
716715
const updatedDoc: User = { _id: existingDoc._id!, name: 'John', age: 30 };
717716

718717
const pongoInsertResult = await users.insertOne(existingDoc);
@@ -745,7 +744,7 @@ void describe('MongoDB Compatibility Tests', () => {
745744
});
746745

747746
void it('should NOT replace an existing document when expected version is mismatched ', async () => {
748-
const existingDoc: User = { _id: uuid(), name: 'John', age: 25 };
747+
const existingDoc: User = { _id: ObjectId(), name: 'John', age: 25 };
749748
const updatedDoc: User = { _id: existingDoc._id!, name: 'John', age: 30 };
750749

751750
const pongoInsertResult = await users.insertOne(existingDoc);

0 commit comments

Comments
 (0)