Skip to content

Commit

Permalink
chore: remove debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerpadilla committed Nov 6, 2023
1 parent df6986f commit 7d1a2e3
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"lint.fix": "yarn lint --fix",
"test": "jest --clearCache && concurrently 'yarn:lint' 'jest'",
"test.all": "jest --clearCache && jest --testMatch '**/*.{it,spec}.ts'",
"test.all.watch": "jest --watchAll --testMatch '**/mongodbQuerier.it.ts'",
"test.all.watch": "jest --watchAll --testMatch '**/*.{it,spec}.ts'",
"test.focus": "jest --watchAll --testMatch '**/mongodbQuerier.{it,spec}.ts' --t 'shouldInsertOneAndCascadeOneToOne'",
"test.watch": "jest --watchAll",
"mongo-rs": "run-rs -v 7.0.2 --portStart 27027 -h 127.0.0.1 [-m]",
"container": "concurrently 'npm:mongo-rs' 'docker-compose up'"
Expand Down
41 changes: 41 additions & 0 deletions packages/nukak-mongo/src/mongoDialect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class MongoDialectSpec implements Spec {
_id: new ObjectId('507f191e810c19729de860ea'),
});

expect(this.dialect.filter(Item, '507f191e810c19729de860ea' as any)).toEqual({
_id: new ObjectId('507f191e810c19729de860ea'),
});

expect(this.dialect.filter(Item, { id: '507f191e810c19729de860ea' as any })).toEqual({
_id: new ObjectId('507f191e810c19729de860ea'),
});
Expand All @@ -41,6 +45,10 @@ class MongoDialectSpec implements Spec {
_id: new ObjectId('507f191e810c19729de860ea'),
});

expect(this.dialect.filter(TaxCategory, '507f191e810c19729de860ea')).toEqual({
_id: new ObjectId('507f191e810c19729de860ea'),
});

expect(this.dialect.filter(TaxCategory, { pk: '507f191e810c19729de860ea' })).toEqual({
_id: new ObjectId('507f191e810c19729de860ea'),
});
Expand Down Expand Up @@ -199,6 +207,39 @@ class MongoDialectSpec implements Spec {
},
},
]);

expect(
this.dialect.aggregationPipeline(User, {
$project: { profile: true },
$filter: { id: '65496146f8f7899f63768df1' as any },
$limit: 1,
}),
).toEqual([
{
$match: {
_id: new ObjectId('65496146f8f7899f63768df1'),
},
},
{
$lookup: {
from: 'user_profile',
pipeline: [
{
$match: {
creatorId: new ObjectId('65496146f8f7899f63768df1'),
},
},
],
as: 'profile',
},
},
{
$unwind: {
path: '$profile',
preserveNullAndEmptyArrays: true,
},
},
]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/nukak-mongo/src/mongoDialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class MongoDialect {
});
} else {
const foreignField = relOpts.references[0].foreign;
const referenceFilter = this.filter(relEntity, q.$filter);
const referenceFilter = this.filter(relEntity, filter);
const referenceSort = this.sort(relEntity, q.$sort);
const referencePipelineEntry: MongoAggregationPipelineEntry<FieldValue<E>> = {
$match: { [foreignField]: referenceFilter._id },
Expand Down
3 changes: 0 additions & 3 deletions packages/nukak-mongo/src/mongodbQuerier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ export class MongodbQuerier extends AbstractQuerier {
let documents: E[];
const hasProjectedRelations = isProjectingRelations(meta, q.$project);

console.log('** hasProjectedRelations', hasProjectedRelations);

if (hasProjectedRelations) {
const pipeline = this.dialect.aggregationPipeline(entity, q);
console.log('** pipeline', JSON.stringify(pipeline, null, 2));
this.extra?.logger('findMany', entity.name, JSON.stringify(pipeline, null, 2));
documents = await this.collection(entity).aggregate<E>(pipeline, { session: this.session }).toArray();
documents = this.dialect.normalizeIds(meta, documents) as E[];
Expand Down
2 changes: 1 addition & 1 deletion packages/nukak/src/querier/abstractQuerier-it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export abstract class AbstractQuerierIt<Q extends Querier> implements Spec {
expect(founds.map(({ id }) => id)).toEqual(ids);
}

async fffShouldInsertOneAndCascadeOneToOne() {
async shouldInsertOneAndCascadeOneToOne() {
const payload = {
name: 'Some Name D',
createdAt: 123,
Expand Down
4 changes: 2 additions & 2 deletions packages/nukak/src/test/spec.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export function createSpec<T extends Spec>(spec: T) {
let describeFn: Global.DescribeBase;
const specName = proto.constructor.name;

if (specName.startsWith('Fff')) {
if (specName.startsWith('fff')) {
describeFn = fdescribe;
} else if (specName.startsWith('Xxx')) {
} else if (specName.startsWith('xxx')) {
describeFn = xdescribe;
} else {
describeFn = describe;
Expand Down
4 changes: 2 additions & 2 deletions packages/nukak/src/util/dialect.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ export function getQueryFilterAsMap<E>(meta: EntityMeta<E>, filter: QueryFilter<
if (filter instanceof QueryRaw) {
return { $and: [filter] } as QueryFilterMap<E>;
}
if (isIdFilter(filter)) {
if (isIdValue(filter)) {
return {
[meta.id]: filter,
} as QueryFilterMap<E>;
}
return filter as QueryFilterMap<E>;
}

function isIdFilter<E>(filter: QueryFilter<E>): filter is IdValue<E> | IdValue<E>[] {
function isIdValue<E>(filter: QueryFilter<E>): filter is IdValue<E> | IdValue<E>[] {
const type = typeof filter;
return (
type === 'string' ||
Expand Down

0 comments on commit 7d1a2e3

Please sign in to comment.