Merge branch 'master' into improvement/typescript-port

This commit is contained in:
Ewout Stortenbeker 2022-10-17 17:14:14 +02:00 committed by GitHub
commit 3c72ee8e59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 65 additions and 11 deletions

2
package-lock.json generated
View file

@ -1,6 +1,6 @@
{
"name": "acebase",
"version": "1.24.4",
"version": "1.24.5",
"lockfileVersion": 2,
"requires": true,
"packages": {

View file

@ -1,6 +1,6 @@
{
"name": "acebase",
"version": "1.24.4",
"version": "1.24.5",
"description": "AceBase realtime database. Open source firebase alternative for nodejs and browser, with additional features: indexes, geo, fulltext, queries, custom storage, offline usage, synchronization, live data proxies and more",
"main": "./src/index.js",
"browser": {

View file

@ -683,3 +683,51 @@ describe('Query on indexed BigInts #141', () => {
expect(snaps.length).toEqual(8);
}, 60e3);
});
describe('Query on indexed BigInts #152', () => {
// Created for https://github.com/appy-one/acebase/issues/152, with adjustments of https://github.com/appy-one/acebase/pull/159/files
/** @type {AceBase} */
let db;
/** @type {{(): Promise<void>}} */
let removeDB;
/** @type {DataReference} */
let moviesRef;
beforeAll(async () => {
({ db, removeDB } = await createTempDB());
moviesRef = db.ref('movies');
const movies = require('./dataset/movies.json').map(movie => {
return {
title: movie.title,
rating: movie.rating,
year: movie.year,
votes: BigInt(movie.votes),
};
});
await db.indexes.create('movies', 'title');
await db.indexes.create('movies', 'rating');
await db.indexes.create('movies', 'votes');
for (const movie of movies) {
await moviesRef.push(movie);
}
});
afterAll(async () => {
await removeDB();
});
it('filter on BigInt', async () => {
let query = moviesRef.query().filter('votes', '>', BigInt(1_500_000));
let snaps = await query.get();
expect(snaps.length).toEqual(5);
// Try again, now with cached results
snaps = await query.get();
expect(snaps.length).toEqual(5);
}, 60e3);
});

View file

@ -26,6 +26,7 @@ class BinaryWriter {
},
end(callback) {
callback();
return this;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
once(event, callback) {
@ -58,6 +59,7 @@ class BinaryWriter {
},
end(callback) {
callback();
return this;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
once(event, callback) {
@ -120,6 +122,7 @@ class BinaryWriter {
if (pendingWrites === 0) {
callback();
}
return this;
},
once(event, callback) {
console.assert(event === 'drain', 'Custom stream can only handle "drain" event');

File diff suppressed because one or more lines are too long

View file

@ -418,7 +418,7 @@ class DataIndex {
// return this._updateTree(path, revLookupKey, revLookupKey, oldData, newData, metadata);
// }
_updateTree(path, oldValue, newValue, oldRecordPointer, newRecordPointer, metadata) {
const canBeIndexed = ['number', 'boolean', 'string'].indexOf(typeof newValue) >= 0 || newValue instanceof Date;
const canBeIndexed = ['number', 'boolean', 'string', 'bigint'].indexOf(typeof newValue) >= 0 || newValue instanceof Date;
const operations = [];
if (oldValue !== null) {
const op = btree_1.BinaryBPlusTree.TransactionOperation.remove(oldValue, oldRecordPointer);

File diff suppressed because one or more lines are too long

View file

@ -76,7 +76,7 @@ export declare abstract class pfs {
* @param options.flag see pfs.flags, default is pfs.flags.write ('w')
* @returns {} returns a promise that resolves once the file has been written
*/
static writeFile(path: string | Buffer | number | fs.PathLike, data: string | Buffer | TypedArray | DataView, options?: string | {
static writeFile(path: string | Buffer | number | fs.PathLike, data: string | Buffer | TypedArray | DataView, options?: BufferEncoding | {
encoding?: BufferEncoding;
mode?: number;
flag?: string;
@ -102,7 +102,7 @@ export declare abstract class pfs {
* @param options.flag see pfs.flags, default is pfs.flags.read ('r')
* @returns returns a promise that resolves with a string if an encoding was specified, or a raw buffer otherwise
*/
static readFile(path: string | Buffer | number | fs.PathLike, options: string | {
static readFile(path: string | Buffer | number | fs.PathLike, options: BufferEncoding | {
encoding: BufferEncoding | null;
flag: string;
}): Promise<Buffer | string>;

File diff suppressed because one or more lines are too long

View file

@ -35,6 +35,7 @@ export class BinaryWriter {
},
end(callback: () => unknown) {
callback();
return this;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
once(event: string, callback: (...args: any[]) => void) {
@ -66,6 +67,7 @@ export class BinaryWriter {
},
end(callback: () => unknown) {
callback();
return this;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
once(event: string, callback: (...args: any[]) => void) {
@ -128,6 +130,7 @@ export class BinaryWriter {
if (pendingWrites === 0) {
callback();
}
return this;
},
once(event: string, callback: (...args: any[]) => void) {
console.assert(event === 'drain', 'Custom stream can only handle "drain" event');

View file

@ -514,7 +514,7 @@ export class DataIndex {
// }
_updateTree(path: string, oldValue: IndexableValue, newValue: IndexableValue, oldRecordPointer: IndexRecordPointer, newRecordPointer: IndexRecordPointer, metadata: IndexMetaData) {
const canBeIndexed = ['number','boolean','string'].indexOf(typeof newValue) >= 0 || newValue instanceof Date;
const canBeIndexed = ['number','boolean','string','bigint'].indexOf(typeof newValue) >= 0 || newValue instanceof Date;
const operations = [];
if (oldValue !== null) {
const op = BinaryBPlusTree.TransactionOperation.remove(oldValue, oldRecordPointer);

View file

@ -116,7 +116,7 @@ export abstract class pfs {
* @param options.flag see pfs.flags, default is pfs.flags.write ('w')
* @returns {} returns a promise that resolves once the file has been written
*/
static writeFile(path:string|Buffer|number|fs.PathLike, data: string|Buffer|TypedArray|DataView, options?:string|{ encoding?: BufferEncoding, mode?: number, flag?: string }): Promise<void> {
static writeFile(path:string|Buffer|number|fs.PathLike, data: string|Buffer|TypedArray|DataView, options?:BufferEncoding | { encoding?: BufferEncoding, mode?: number, flag?: string }): Promise<void> {
return new Promise((resolve, reject) => {
fs.writeFile(path, data, options, err => {
if (err) { reject(err); }
@ -159,7 +159,7 @@ export abstract class pfs {
* @param options.flag see pfs.flags, default is pfs.flags.read ('r')
* @returns returns a promise that resolves with a string if an encoding was specified, or a raw buffer otherwise
*/
static readFile(path: string|Buffer|number|fs.PathLike, options:string|{ encoding: BufferEncoding|null, flag: string }): Promise<Buffer|string> {
static readFile(path: string|Buffer|number|fs.PathLike, options:BufferEncoding |{ encoding: BufferEncoding|null, flag: string }): Promise<Buffer|string> {
return new Promise((resolve, reject) => {
fs.readFile(path, options, (err, data) => {
if (err) { reject(err); }