Skip to content

Commit 7e86922

Browse files
committed
Handle method passes again null instead of empty object when doucument doesn't exists
This fixes regression introduced by #99
1 parent 202433b commit 7e86922

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

src/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@event-driven-io/pongo-core",
3-
"version": "0.16.2",
3+
"version": "0.16.3",
44
"description": "Pongo - Mongo with strong consistency on top of Postgres",
55
"type": "module",
66
"engines": {

src/packages/pongo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@event-driven-io/pongo",
3-
"version": "0.16.2",
3+
"version": "0.16.3",
44
"description": "Pongo - Mongo with strong consistency on top of Postgres",
55
"type": "module",
66
"scripts": {

src/packages/pongo/src/commandLine/shell.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const startRepl = async (options: {
124124
setLogLevel(process.env.DUMBO_LOG_LEVEL ?? options.logging.logLevel);
125125
setLogStyle(process.env.DUMBO_LOG_STYLE ?? options.logging.logStyle);
126126

127-
console.log(chalk.green('Starting Pongo Shell (version: 0.16.2)'));
127+
console.log(chalk.green('Starting Pongo Shell (version: 0.16.3)'));
128128

129129
if (options.logging.printOptions) {
130130
console.log(chalk.green('With Options:'));

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export const pongoCollection = <
348348
const existing = (await collection.findOne(
349349
byId,
350350
options,
351-
)) as WithVersion<T>;
351+
)) as WithVersion<T> | null;
352352

353353
const expectedVersion = expectedVersionValue(version);
354354

@@ -369,13 +369,15 @@ export const pongoCollection = <
369369
);
370370
}
371371

372-
const result = await handle({ ...existing } as T);
372+
const result = await handle(
373+
existing !== null ? ({ ...existing } as T) : null,
374+
);
373375

374-
if (deepEquals(existing as T, result))
376+
if (deepEquals(existing as T | null, result))
375377
return operationResult<PongoHandleResult<T>>(
376378
{
377379
successful: true,
378-
document: existing as T,
380+
document: existing as T | null,
379381
},
380382
{ operationName: 'handle', collectionName, errors },
381383
);

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,25 @@ void describe('MongoDB Compatibility Tests', () => {
10611061
});
10621062

10631063
void describe('Handle Operations', () => {
1064+
void it(`should pass null to handle if document doesn't exist`, async () => {
1065+
const pongoCollection = pongoDb.collection<User>('handleCollection');
1066+
const nonExistingId = uuid() as unknown as ObjectId;
1067+
1068+
const newDoc: User = { name: 'John', age: 25 };
1069+
1070+
let wasHandled = false;
1071+
1072+
const handle = (existing: User | null) => {
1073+
wasHandled = true;
1074+
assert.equal(existing, null);
1075+
return newDoc;
1076+
};
1077+
1078+
await pongoCollection.handle(nonExistingId, handle);
1079+
1080+
assert.ok(wasHandled);
1081+
});
1082+
10641083
void it('should insert a new document if it does not exist', async () => {
10651084
const pongoCollection = pongoDb.collection<User>('handleCollection');
10661085
const nonExistingId = uuid() as unknown as ObjectId;

0 commit comments

Comments
 (0)