Skip to content

Commit

Permalink
fix: datastore.simulator handling queries without filters
Browse files Browse the repository at this point in the history
  • Loading branch information
mdornseif committed Aug 31, 2023
1 parent 909a4c9 commit 13bedcb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ function createQuery(query: any): any {
export class Datastore extends OrigDatastore {
db: Map<string, any>
rnd = 0
engine = 'datastore-simulator'

constructor(options?: DatastoreOptions) {
super()
options = options || {}
Expand Down Expand Up @@ -227,12 +229,18 @@ export class Datastore extends OrigDatastore {
return k.kind === kind && k.namespace === query.namespace
})

if (query.filters.length === 0) {
for (let [ks, entity] of filtered) {
reply.push(entity)
}
}

for (let filter of query.filters) {
if (filter.name === '__key__' && filter.op === 'HAS_ANCESTOR') {
const parent = filter.val.path.join('⭕️')
for (let [ks, entity] of filtered) {
const k = JSON.parse(ks)
if (k.path.join('⭕️').startsWith(parent)) {
if(k.path.join('⭕️').startsWith(parent)) {
reply.push(entity)
}
}
Expand All @@ -259,7 +267,9 @@ export class Datastore extends OrigDatastore {
}
}

setImmediate(() => callback(null, reply, {}))
// TODO: handle query.limit

setImmediate(() => callback(null, reply, {moreResults: 'MORE_RESULTS_AFTER_LIMIT'}))
}

merge(entities: Entities): Promise<CommitResponse>
Expand Down

0 comments on commit 13bedcb

Please sign in to comment.