Skip to content

Commit 1e02ea6

Browse files
committed
Used UUID v7 as sequential random id generator
Added also ObjectId helper method to generate it with Mongo-like style
1 parent 8ed05a7 commit 1e02ea6

File tree

9 files changed

+12
-10
lines changed

9 files changed

+12
-10
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You can use Pongo syntax with explicit typing about supported syntax:
2222

2323
```ts
2424
import { pongoClient } from "@event-driven-io/pongo";
25-
import { v4 as uuid } from "uuid";
25+
import { v7 as uuid } from "uuid";
2626

2727
type User = { name: string; age: number };
2828

@@ -61,7 +61,7 @@ Or use MongoDB compliant shim:
6161

6262
```ts
6363
import { MongoClient } from "@event-driven-io/pongo/shim";
64-
import { v4 as uuid } from "uuid";
64+
import { v7 as uuid } from "uuid";
6565

6666
type User = { name: string; age: number };
6767

samples/simple-ts/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { pongoClient } from '@event-driven-io/pongo';
2-
import { v4 as uuid } from 'uuid';
2+
import { v7 as uuid } from 'uuid';
33

44
type User = { _id?: string; name: string; age: number };
55

samples/simple-ts/src/typedClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { pongoClient } from '@event-driven-io/pongo';
2-
import { v4 as uuid } from 'uuid';
2+
import { v7 as uuid } from 'uuid';
33
import config from './pongo.config';
44

55
const connectionString =

src/docs/getting-started.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You can use Pongo syntax with explicit typing about supported syntax:
2020

2121
```ts
2222
import { pongoClient } from '@event-driven-io/pongo';
23-
import { v4 as uuid } from 'uuid';
23+
import { v7 as uuid } from 'uuid';
2424

2525
type User = { name: string; age: number };
2626

@@ -59,7 +59,7 @@ Or use MongoDB compliant shim:
5959

6060
```ts
6161
import { MongoClient } from '@event-driven-io/pongo/shim';
62-
import { v4 as uuid } from 'uuid';
62+
import { v7 as uuid } from 'uuid';
6363

6464
type User = { name: string; age: number };
6565

src/packages/pongo/src/core/collection/pongoCollection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
type SQLExecutor,
1313
type SQLMigration,
1414
} from '@event-driven-io/dumbo';
15-
import { v4 as uuid } from 'uuid';
15+
import { v7 as uuid } from 'uuid';
1616
import {
1717
expectedVersionValue,
1818
operationResult,

src/packages/pongo/src/core/typing/operations.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type SQL,
99
type SQLExecutor,
1010
} from '@event-driven-io/dumbo';
11+
import { v7 as uuid } from 'uuid';
1112
import { ConcurrencyError } from '../errors';
1213

1314
export interface PongoClient {
@@ -220,6 +221,7 @@ export interface PongoCollection<T extends PongoDocument> {
220221
}
221222

222223
export type ObjectId = string & { __brandId: 'ObjectId' };
224+
export const ObjectId = (value?: string) => value ?? uuid();
223225

224226
export type HasId = { _id: string };
225227

src/packages/pongo/src/e2e/compatibilityTest.e2e.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
MongoClient as OriginalMongoClient,
1414
} from 'mongodb';
1515
import { after, before, describe, it } from 'node:test';
16-
import { v4 as uuid } from 'uuid';
16+
import { v7 as uuid } from 'uuid';
1717
import { MongoClient, type Db } from '../shim';
1818

1919
type History = { street: string };

src/packages/pongo/src/e2e/postgres.e2e.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
import assert from 'assert';
66
import console from 'console';
77
import { after, before, describe, it } from 'node:test';
8-
import { v4 as uuid } from 'uuid';
8+
import { v7 as uuid } from 'uuid';
99
import {
1010
pongoClient,
1111
type ObjectId,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
import assert from 'assert';
66
import console from 'console';
77
import { after, before, beforeEach, describe, it } from 'node:test';
8-
import { v4 as uuid } from 'uuid';
8+
import { v7 as uuid } from 'uuid';
99
import {
1010
pongoClient,
1111
pongoSchema,

0 commit comments

Comments
 (0)