import { Collection, CREATED_AT_KEY, ID_KEY, UPDATED_AT_KEY } from "../src/collection"; import EncryptedFSAdapter from "../src/adapter/enc_fs"; import FSAdapter from "../src/adapter/fs"; import { ShardedCollection } from "../src/sharded_collection"; const getCollection = ({ name = "test", integerIds = false, populate = true, timestamps = true }): Collection => { const collection = new Collection({ autosync: false, integerIds, timestamps, adapter: new FSAdapter({ storagePath: ".test", name }), }); collection.drop(); if (populate) { // Adding some items to ensure that result sets correctly // ignore unmatched queries in all cases. // @ts-ignore collection.insert({ xxx: "xxx" }); // @ts-ignore collection.insert({ yyy: "yyy" }); // @ts-ignore collection.insert({ zzz: "zzz" }); } return collection; }; const getEncryptedCollection = ({ name = "test", integerIds = false }): Collection => { return new Collection({ autosync: false, integerIds, adapter: new EncryptedFSAdapter({ storagePath: ".test", name }), }); }; export function testCollection({ name = "test", integerIds = false, populate = true, timestamps = true } = {}): Collection { return getCollection({ name, integerIds, populate, timestamps }); } export function testCollectionEncrypted({ name = "test", integerIds = false } = {}): Collection { return getEncryptedCollection({ name, integerIds }); } export function getShardedCollection({ name ="testShard", autosync = true, integerIds = false } = {}): ShardedCollection { return new ShardedCollection( { autosync, integerIds }, { shardKey: "key", shardCount: 3, adapter: FSAdapter, adapterOptions: { name, storagePath: ".test" }, }, ); }; export function nrml(results: T[], { keepIds = false } = {}): T[] { // Remove all the _id fields, and // remove all the `_created_at` and `_updated_at` fields. return results.map((result) => { if (!keepIds) { delete result[ID_KEY]; } delete result[CREATED_AT_KEY]; delete result[UPDATED_AT_KEY]; return result; }); }