@sprucelabs/data-stores 11.1.0 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/{CursorPager.d.ts → cursors/CursorPager.d.ts} +4 -4
- package/build/{CursorPager.js → cursors/CursorPager.js} +0 -0
- package/build/cursors/CursorPagerFaker.d.ts +6 -0
- package/build/cursors/CursorPagerFaker.js +21 -0
- package/build/esm/{CursorPager.d.ts → cursors/CursorPager.d.ts} +4 -4
- package/build/esm/{CursorPager.js → cursors/CursorPager.js} +0 -0
- package/build/esm/cursors/CursorPagerFaker.d.ts +6 -0
- package/build/esm/cursors/CursorPagerFaker.js +26 -0
- package/build/esm/index.d.ts +4 -2
- package/build/esm/index.js +4 -2
- package/build/index.d.ts +4 -2
- package/build/index.js +6 -3
- package/package.json +1 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { QueryOptions } from '
|
|
1
|
+
import { QueryOptions } from '../types/query.types';
|
|
2
2
|
export interface CursorQueryOptions extends Omit<QueryOptions, 'skip'> {
|
|
3
3
|
limit: number;
|
|
4
4
|
next: string | null;
|
|
5
5
|
previous: string | null;
|
|
6
6
|
}
|
|
7
|
-
interface
|
|
7
|
+
export interface RecordsWithCursors<Response extends Record<string, any>[] = Record<string, any>[]> {
|
|
8
8
|
records: Response;
|
|
9
9
|
next: string | null;
|
|
10
10
|
previous: string | null;
|
|
11
11
|
}
|
|
12
12
|
export default class CursorPager {
|
|
13
|
-
static find<S extends SimpleStore, Find extends S['find'] = S['find'], Query extends Parameters<Find>[0] = Parameters<Find>[0], PromisedResponse extends ReturnType<Find> = ReturnType<Find>, Response extends UnPromisify<PromisedResponse> = UnPromisify<PromisedResponse>>(store: S, query: Query, options: CursorQueryOptions): Promise<
|
|
13
|
+
static find<S extends SimpleStore, Find extends S['find'] = S['find'], Query extends Parameters<Find>[0] = Parameters<Find>[0], PromisedResponse extends ReturnType<Find> = ReturnType<Find>, Response extends UnPromisify<PromisedResponse> = UnPromisify<PromisedResponse>>(store: S, query: Query, options: CursorQueryOptions): Promise<RecordsWithCursors<Response>>;
|
|
14
14
|
private static getSortFieldValuesFromRecord;
|
|
15
15
|
private static trackNewest;
|
|
16
16
|
private static parseCursor;
|
|
@@ -21,7 +21,7 @@ export default class CursorPager {
|
|
|
21
21
|
sort: NonNullable<O['sort']>;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
interface SimpleStore {
|
|
24
|
+
export interface SimpleStore {
|
|
25
25
|
find: (...args: any[]) => Promise<any>;
|
|
26
26
|
}
|
|
27
27
|
declare type UnPromisify<T> = T extends Promise<infer U> ? U : T;
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CursorQueryOptions, RecordsWithCursors, SimpleStore } from './CursorPager';
|
|
2
|
+
export default class CursorPagerFaker {
|
|
3
|
+
private static originalFind;
|
|
4
|
+
static setResponse(response: (store: SimpleStore, query: Record<string, any>, options: CursorQueryOptions) => Promise<Partial<RecordsWithCursors<Record<string, any>[]>>>): void;
|
|
5
|
+
static beforeEach(): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const CursorPager_1 = __importDefault(require("./CursorPager"));
|
|
7
|
+
class CursorPagerFaker {
|
|
8
|
+
static setResponse(response) {
|
|
9
|
+
//@ts-ignore
|
|
10
|
+
CursorPager_1.default.find = response;
|
|
11
|
+
}
|
|
12
|
+
static async beforeEach() {
|
|
13
|
+
if (!this.originalFind) {
|
|
14
|
+
this.originalFind = CursorPager_1.default.find.bind(CursorPager_1.default);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
CursorPager_1.default.find = this.originalFind;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = CursorPagerFaker;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { QueryOptions } from '
|
|
1
|
+
import { QueryOptions } from '../types/query.types';
|
|
2
2
|
export interface CursorQueryOptions extends Omit<QueryOptions, 'skip'> {
|
|
3
3
|
limit: number;
|
|
4
4
|
next: string | null;
|
|
5
5
|
previous: string | null;
|
|
6
6
|
}
|
|
7
|
-
interface
|
|
7
|
+
export interface RecordsWithCursors<Response extends Record<string, any>[] = Record<string, any>[]> {
|
|
8
8
|
records: Response;
|
|
9
9
|
next: string | null;
|
|
10
10
|
previous: string | null;
|
|
11
11
|
}
|
|
12
12
|
export default class CursorPager {
|
|
13
|
-
static find<S extends SimpleStore, Find extends S['find'] = S['find'], Query extends Parameters<Find>[0] = Parameters<Find>[0], PromisedResponse extends ReturnType<Find> = ReturnType<Find>, Response extends UnPromisify<PromisedResponse> = UnPromisify<PromisedResponse>>(store: S, query: Query, options: CursorQueryOptions): Promise<
|
|
13
|
+
static find<S extends SimpleStore, Find extends S['find'] = S['find'], Query extends Parameters<Find>[0] = Parameters<Find>[0], PromisedResponse extends ReturnType<Find> = ReturnType<Find>, Response extends UnPromisify<PromisedResponse> = UnPromisify<PromisedResponse>>(store: S, query: Query, options: CursorQueryOptions): Promise<RecordsWithCursors<Response>>;
|
|
14
14
|
private static getSortFieldValuesFromRecord;
|
|
15
15
|
private static trackNewest;
|
|
16
16
|
private static parseCursor;
|
|
@@ -21,7 +21,7 @@ export default class CursorPager {
|
|
|
21
21
|
sort: NonNullable<O['sort']>;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
interface SimpleStore {
|
|
24
|
+
export interface SimpleStore {
|
|
25
25
|
find: (...args: any[]) => Promise<any>;
|
|
26
26
|
}
|
|
27
27
|
declare type UnPromisify<T> = T extends Promise<infer U> ? U : T;
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CursorQueryOptions, RecordsWithCursors, SimpleStore } from './CursorPager';
|
|
2
|
+
export default class CursorPagerFaker {
|
|
3
|
+
private static originalFind;
|
|
4
|
+
static setResponse(response: (store: SimpleStore, query: Record<string, any>, options: CursorQueryOptions) => Promise<Partial<RecordsWithCursors<Record<string, any>[]>>>): void;
|
|
5
|
+
static beforeEach(): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import CursorPager from './CursorPager.js';
|
|
11
|
+
export default class CursorPagerFaker {
|
|
12
|
+
static setResponse(response) {
|
|
13
|
+
//@ts-ignore
|
|
14
|
+
CursorPager.find = response;
|
|
15
|
+
}
|
|
16
|
+
static beforeEach() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (!this.originalFind) {
|
|
19
|
+
this.originalFind = CursorPager.find.bind(CursorPager);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
CursorPager.find = this.originalFind;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
package/build/esm/index.d.ts
CHANGED
|
@@ -15,5 +15,7 @@ export * from './types/query.types';
|
|
|
15
15
|
export * from './types/stores.types';
|
|
16
16
|
export * from './constants';
|
|
17
17
|
export { default as generateId } from './utilities/generateId';
|
|
18
|
-
export { default as CursorPager } from './CursorPager';
|
|
19
|
-
export * from './CursorPager';
|
|
18
|
+
export { default as CursorPager } from './cursors/CursorPager';
|
|
19
|
+
export * from './cursors/CursorPager';
|
|
20
|
+
export { default as CursorPagerFaker } from './cursors/CursorPagerFaker';
|
|
21
|
+
export * from './cursors/CursorPager';
|
package/build/esm/index.js
CHANGED
|
@@ -15,5 +15,7 @@ export * from './types/query.types.js';
|
|
|
15
15
|
export * from './types/stores.types.js';
|
|
16
16
|
export * from './constants.js';
|
|
17
17
|
export { default as generateId } from './utilities/generateId.js';
|
|
18
|
-
export { default as CursorPager } from './CursorPager.js';
|
|
19
|
-
export * from './CursorPager.js';
|
|
18
|
+
export { default as CursorPager } from './cursors/CursorPager.js';
|
|
19
|
+
export * from './cursors/CursorPager.js';
|
|
20
|
+
export { default as CursorPagerFaker } from './cursors/CursorPagerFaker.js';
|
|
21
|
+
export * from './cursors/CursorPager.js';
|
package/build/index.d.ts
CHANGED
|
@@ -15,5 +15,7 @@ export * from './types/query.types';
|
|
|
15
15
|
export * from './types/stores.types';
|
|
16
16
|
export * from './constants';
|
|
17
17
|
export { default as generateId } from './utilities/generateId';
|
|
18
|
-
export { default as CursorPager } from './CursorPager';
|
|
19
|
-
export * from './CursorPager';
|
|
18
|
+
export { default as CursorPager } from './cursors/CursorPager';
|
|
19
|
+
export * from './cursors/CursorPager';
|
|
20
|
+
export { default as CursorPagerFaker } from './cursors/CursorPagerFaker';
|
|
21
|
+
export * from './cursors/CursorPager';
|
package/build/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.CursorPager = exports.generateId = exports.mongoUtil = exports.NeDbDatabase = exports.MongoDatabase = exports.StoreLoader = exports.DatabaseFactory = exports.StoreFactory = exports.AbstractStore = exports.DatabaseFixture = exports.AbstractDatabaseTest = void 0;
|
|
20
|
+
exports.CursorPagerFaker = exports.CursorPager = exports.generateId = exports.mongoUtil = exports.NeDbDatabase = exports.MongoDatabase = exports.StoreLoader = exports.DatabaseFactory = exports.StoreFactory = exports.AbstractStore = exports.DatabaseFixture = exports.AbstractDatabaseTest = void 0;
|
|
21
21
|
var AbstractDatabaseTest_1 = require("./tests/AbstractDatabaseTest");
|
|
22
22
|
Object.defineProperty(exports, "AbstractDatabaseTest", { enumerable: true, get: function () { return __importDefault(AbstractDatabaseTest_1).default; } });
|
|
23
23
|
var DatabaseFixture_1 = require("./fixtures/DatabaseFixture");
|
|
@@ -45,6 +45,9 @@ __exportStar(require("./types/stores.types"), exports);
|
|
|
45
45
|
__exportStar(require("./constants"), exports);
|
|
46
46
|
var generateId_1 = require("./utilities/generateId");
|
|
47
47
|
Object.defineProperty(exports, "generateId", { enumerable: true, get: function () { return __importDefault(generateId_1).default; } });
|
|
48
|
-
var CursorPager_1 = require("./CursorPager");
|
|
48
|
+
var CursorPager_1 = require("./cursors/CursorPager");
|
|
49
49
|
Object.defineProperty(exports, "CursorPager", { enumerable: true, get: function () { return __importDefault(CursorPager_1).default; } });
|
|
50
|
-
__exportStar(require("./CursorPager"), exports);
|
|
50
|
+
__exportStar(require("./cursors/CursorPager"), exports);
|
|
51
|
+
var CursorPagerFaker_1 = require("./cursors/CursorPagerFaker");
|
|
52
|
+
Object.defineProperty(exports, "CursorPagerFaker", { enumerable: true, get: function () { return __importDefault(CursorPagerFaker_1).default; } });
|
|
53
|
+
__exportStar(require("./cursors/CursorPager"), exports);
|