@sprucelabs/data-stores 26.3.1 → 26.3.3

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.
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const error_1 = __importDefault(require("@sprucelabs/error"));
7
7
  class SpruceError extends error_1.default {
8
8
  friendlyMessage() {
9
- var _a, _b, _c;
9
+ var _a, _b, _c, _d;
10
10
  const { options } = this;
11
11
  let message;
12
12
  switch (options === null || options === void 0 ? void 0 : options.code) {
@@ -111,7 +111,7 @@ If you are on a mac, using brew is recommended: https://brew.sh`;
111
111
  default:
112
112
  message = super.friendlyMessage();
113
113
  }
114
- const fullMessage = message !== null && message !== void 0 ? message : options.friendlyMessage;
114
+ const fullMessage = (_d = options.friendlyMessage) !== null && _d !== void 0 ? _d : message;
115
115
  return fullMessage;
116
116
  }
117
117
  }
@@ -1,7 +1,7 @@
1
1
  import AbstractSpruceError from '@sprucelabs/error';
2
2
  export default class SpruceError extends AbstractSpruceError {
3
3
  friendlyMessage() {
4
- var _a, _b, _c;
4
+ var _a, _b, _c, _d;
5
5
  const { options } = this;
6
6
  let message;
7
7
  switch (options === null || options === void 0 ? void 0 : options.code) {
@@ -106,7 +106,7 @@ If you are on a mac, using brew is recommended: https://brew.sh`;
106
106
  default:
107
107
  message = super.friendlyMessage();
108
108
  }
109
- const fullMessage = message !== null && message !== void 0 ? message : options.friendlyMessage;
109
+ const fullMessage = (_d = options.friendlyMessage) !== null && _d !== void 0 ? _d : message;
110
110
  return fullMessage;
111
111
  }
112
112
  }
@@ -4,11 +4,13 @@ export default class DatabaseFactory {
4
4
  private static Adapters;
5
5
  private constructor();
6
6
  static addAdapter(scheme: string, Adapter: DatabaseConstructor): void;
7
- static Database(options: {
8
- dbName?: string;
9
- dbConnectionString: string;
10
- }): Database;
7
+ static Database(options: DatabaseFactoryOptions): Database;
11
8
  private static generateCacheKey;
12
9
  static reset(): void;
13
10
  }
14
11
  export type DatabaseConstructor = new (connectionString: string, options: DatabaseOptions) => Database;
12
+ interface DatabaseFactoryOptions {
13
+ dbName?: string;
14
+ dbConnectionString: string;
15
+ }
16
+ export {};
@@ -1,3 +1,4 @@
1
+ import { FakeQueryHandler } from '../databases/NeDbDatabase';
1
2
  import { Database } from '../types/database.types';
2
3
  export interface DatabaseFixtureOptions {
3
4
  dbConnectionString?: string;
@@ -12,6 +13,7 @@ export default class DatabaseFixture {
12
13
  constructor(options?: DatabaseFixtureOptions);
13
14
  connectToDatabase(): Promise<Database>;
14
15
  private static connect;
16
+ fakeQuery<T>(query: string, cb: FakeQueryHandler<T>): void;
15
17
  static setDefaultConnectOptions(options: DatabaseFixtureOptions): void;
16
18
  static generateDbName(): string;
17
19
  getDbName(): string;
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { SchemaError } from '@sprucelabs/schema';
11
11
  import { MONGO_TEST_URI } from '../databases/MongoDatabase.js';
12
+ import SpruceError from '../errors/SpruceError.js';
12
13
  import DatabaseFactory from '../factories/DatabaseFactory.js';
13
14
  const MEMORY = 'memory://';
14
15
  class DatabaseFixture {
@@ -53,6 +54,17 @@ class DatabaseFixture {
53
54
  return database;
54
55
  });
55
56
  }
57
+ fakeQuery(query, cb) {
58
+ const db = DatabaseFixture.activeDatabases[0];
59
+ if (!db) {
60
+ throw new SpruceError({
61
+ code: 'DATABASE_NOT_CONNECTED',
62
+ operationAttempted: 'fakeQuery',
63
+ friendlyMessage: "You can't fake a query until you connect to a database.",
64
+ });
65
+ }
66
+ db.fakeQuery(query, cb);
67
+ }
56
68
  static setDefaultConnectOptions(options) {
57
69
  this.defaultOptions = options;
58
70
  }
@@ -4,11 +4,13 @@ export default class DatabaseFactory {
4
4
  private static Adapters;
5
5
  private constructor();
6
6
  static addAdapter(scheme: string, Adapter: DatabaseConstructor): void;
7
- static Database(options: {
8
- dbName?: string;
9
- dbConnectionString: string;
10
- }): Database;
7
+ static Database(options: DatabaseFactoryOptions): Database;
11
8
  private static generateCacheKey;
12
9
  static reset(): void;
13
10
  }
14
11
  export type DatabaseConstructor = new (connectionString: string, options: DatabaseOptions) => Database;
12
+ interface DatabaseFactoryOptions {
13
+ dbName?: string;
14
+ dbConnectionString: string;
15
+ }
16
+ export {};
@@ -1,3 +1,4 @@
1
+ import { FakeQueryHandler } from '../databases/NeDbDatabase';
1
2
  import { Database } from '../types/database.types';
2
3
  export interface DatabaseFixtureOptions {
3
4
  dbConnectionString?: string;
@@ -12,6 +13,7 @@ export default class DatabaseFixture {
12
13
  constructor(options?: DatabaseFixtureOptions);
13
14
  connectToDatabase(): Promise<Database>;
14
15
  private static connect;
16
+ fakeQuery<T>(query: string, cb: FakeQueryHandler<T>): void;
15
17
  static setDefaultConnectOptions(options: DatabaseFixtureOptions): void;
16
18
  static generateDbName(): string;
17
19
  getDbName(): string;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const schema_1 = require("@sprucelabs/schema");
7
7
  const MongoDatabase_1 = require("../databases/MongoDatabase");
8
+ const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
8
9
  const DatabaseFactory_1 = __importDefault(require("../factories/DatabaseFactory"));
9
10
  const MEMORY = 'memory://';
10
11
  class DatabaseFixture {
@@ -45,6 +46,17 @@ class DatabaseFixture {
45
46
  DatabaseFixture.activeDatabases.push(database);
46
47
  return database;
47
48
  }
49
+ fakeQuery(query, cb) {
50
+ const db = DatabaseFixture.activeDatabases[0];
51
+ if (!db) {
52
+ throw new SpruceError_1.default({
53
+ code: 'DATABASE_NOT_CONNECTED',
54
+ operationAttempted: 'fakeQuery',
55
+ friendlyMessage: "You can't fake a query until you connect to a database.",
56
+ });
57
+ }
58
+ db.fakeQuery(query, cb);
59
+ }
48
60
  static setDefaultConnectOptions(options) {
49
61
  this.defaultOptions = options;
50
62
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "26.3.1",
6
+ "version": "26.3.3",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",
@@ -68,23 +68,23 @@
68
68
  "upgrade.packages.test": "yarn upgrade.packages.all && yarn lint && yarn build.dev && yarn test"
69
69
  },
70
70
  "dependencies": {
71
- "@sprucelabs/error": "^5.1.53",
71
+ "@sprucelabs/error": "^5.1.54",
72
72
  "@sprucelabs/globby": "^1.0.3",
73
- "@sprucelabs/schema": "^29.3.0",
74
- "@sprucelabs/spruce-skill-utils": "^30.1.44",
73
+ "@sprucelabs/schema": "^29.3.2",
74
+ "@sprucelabs/spruce-skill-utils": "^30.1.46",
75
75
  "just-clone": "^6.2.0",
76
76
  "lodash": "^4.17.21",
77
77
  "mongodb": "^6.3.0",
78
78
  "nedb": "^1.8.0"
79
79
  },
80
80
  "devDependencies": {
81
- "@sprucelabs/esm-postbuild": "^5.0.109",
81
+ "@sprucelabs/esm-postbuild": "^5.0.110",
82
82
  "@sprucelabs/jest-json-reporter": "^7.0.134",
83
83
  "@sprucelabs/jest-sheets-reporter": "^3.0.26",
84
- "@sprucelabs/resolve-path-aliases": "^1.1.271",
84
+ "@sprucelabs/resolve-path-aliases": "^1.1.272",
85
85
  "@sprucelabs/semantic-release": "^4.0.8",
86
- "@sprucelabs/test": "^8.0.35",
87
- "@sprucelabs/test-utils": "^4.0.86",
86
+ "@sprucelabs/test": "^8.0.36",
87
+ "@sprucelabs/test-utils": "^4.0.88",
88
88
  "@types/lodash": "^4.14.202",
89
89
  "@types/nedb": "^1.8.16",
90
90
  "@types/node": "^20.10.4",