@sprucelabs/data-stores 25.9.0 → 25.10.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.
@@ -25,6 +25,7 @@ export * from './cursors/CursorPager';
25
25
  */
26
26
  export { default as databaseAssertUtil } from './tests/databaseAssertUtil';
27
27
  export { default as databaseAssert } from './tests/databaseAssertUtil';
28
+ export { default as storePluginAssert } from './tests/storePluginAssert';
28
29
  export { default as BatchCursorImpl } from './cursors/BatchCursor';
29
30
  export * from './cursors/BatchCursor';
30
31
  export { default as BatchArrayCursor } from './cursors/BatchArrayCursor';
@@ -25,6 +25,7 @@ export * from './cursors/CursorPager.js';
25
25
  */
26
26
  export { default as databaseAssertUtil } from './tests/databaseAssertUtil.js';
27
27
  export { default as databaseAssert } from './tests/databaseAssertUtil.js';
28
+ export { default as storePluginAssert } from './tests/storePluginAssert.js';
28
29
  export { default as BatchCursorImpl } from './cursors/BatchCursor.js';
29
30
  export * from './cursors/BatchCursor.js';
30
31
  export { default as BatchArrayCursor } from './cursors/BatchArrayCursor.js';
@@ -4,9 +4,7 @@ import AbstractMutexer from '../mutexers/AbstractMutexer';
4
4
  import { DataStorePlugin, Database } from '../types/database.types';
5
5
  import { QueryBuilder, QueryOptions } from '../types/query.types';
6
6
  import { PrepareOptions, PrepareResults, SaveOperations, DataStore } from '../types/stores.types';
7
- export default abstract class AbstractStore<FullSchema extends Schema, CreateSchema extends Schema = FullSchema, UpdateSchema extends Schema = CreateSchema, DatabaseSchema extends Schema = FullSchema, DatabaseRecord = SchemaValues<DatabaseSchema> & {
8
- id: string;
9
- }, QueryRecord = SchemaPartialValues<FullSchema>, FullRecord = SchemaValues<FullSchema>, CreateRecord = SchemaValues<CreateSchema>, UpdateRecord = SchemaValues<UpdateSchema> & SaveOperations> extends AbstractMutexer implements DataStore {
7
+ export default abstract class AbstractStore<FullSchema extends Schema, CreateSchema extends Schema = FullSchema, UpdateSchema extends Schema = CreateSchema, DatabaseSchema extends Schema = FullSchema, DatabaseRecord = SchemaValues<DatabaseSchema>, QueryRecord = SchemaPartialValues<FullSchema>, FullRecord = SchemaValues<FullSchema>, CreateRecord = SchemaValues<CreateSchema>, UpdateRecord = SchemaValues<UpdateSchema> & SaveOperations> extends AbstractMutexer implements DataStore {
10
8
  abstract readonly name: string;
11
9
  protected abstract collectionName: string;
12
10
  protected abstract createSchema: CreateSchema;
@@ -0,0 +1,6 @@
1
+ import { Schema } from '@sprucelabs/schema';
2
+ import AbstractStore from '../stores/AbstractStore';
3
+ declare const storePluginAssert: {
4
+ storeHasPlugin: (store: AbstractStore<Schema>, pluginName: string) => import("..").DataStorePlugin;
5
+ };
6
+ export default storePluginAssert;
@@ -0,0 +1,21 @@
1
+ import { assertOptions } from '@sprucelabs/schema';
2
+ import { assert } from '@sprucelabs/test-utils';
3
+ const storePluginAssert = {
4
+ storeHasPlugin: (store, pluginName) => {
5
+ assertOptions({
6
+ store,
7
+ pluginName,
8
+ }, ['store', 'pluginName']);
9
+ //@ts-ignore
10
+ const { plugins } = store;
11
+ if (!(plugins === null || plugins === void 0 ? void 0 : plugins.length)) {
12
+ assert.fail(`The store you passed has no plugins. Add one to 'protected plugins: DataStorePlugin[] = [...]' or add it in the constructor of your store with 'this.plugins[...]'`);
13
+ }
14
+ const plugin = plugins === null || plugins === void 0 ? void 0 : plugins.find((p) => p.getName() === pluginName);
15
+ if ((plugin === null || plugin === void 0 ? void 0 : plugin.getName()) !== pluginName) {
16
+ assert.fail(`I could not find the plugin '${pluginName}' in the store you passed. Make sure you added it to 'protected plugins: DataStorePlugin[] = [...]' or added it in the constructor of your store with 'this.plugins[...]'`);
17
+ }
18
+ return plugin;
19
+ },
20
+ };
21
+ export default storePluginAssert;
package/build/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export * from './cursors/CursorPager';
25
25
  */
26
26
  export { default as databaseAssertUtil } from './tests/databaseAssertUtil';
27
27
  export { default as databaseAssert } from './tests/databaseAssertUtil';
28
+ export { default as storePluginAssert } from './tests/storePluginAssert';
28
29
  export { default as BatchCursorImpl } from './cursors/BatchCursor';
29
30
  export * from './cursors/BatchCursor';
30
31
  export { default as BatchArrayCursor } from './cursors/BatchArrayCursor';
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.BatchArrayCursor = exports.BatchCursorImpl = exports.databaseAssert = exports.databaseAssertUtil = exports.CursorPagerFaker = exports.CursorPager = exports.generateId = exports.DataStoresError = exports.mongoUtil = exports.NeDbDatabase = exports.MongoDatabase = exports.StoreLoader = exports.DatabaseFactory = exports.StoreFactory = exports.AbstractStore = exports.DatabaseFixture = exports.AbstractDatabaseTest = void 0;
20
+ exports.BatchArrayCursor = exports.BatchCursorImpl = exports.storePluginAssert = exports.databaseAssert = exports.databaseAssertUtil = exports.CursorPagerFaker = exports.CursorPager = exports.generateId = exports.DataStoresError = 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");
@@ -60,6 +60,8 @@ var databaseAssertUtil_1 = require("./tests/databaseAssertUtil");
60
60
  Object.defineProperty(exports, "databaseAssertUtil", { enumerable: true, get: function () { return __importDefault(databaseAssertUtil_1).default; } });
61
61
  var databaseAssertUtil_2 = require("./tests/databaseAssertUtil");
62
62
  Object.defineProperty(exports, "databaseAssert", { enumerable: true, get: function () { return __importDefault(databaseAssertUtil_2).default; } });
63
+ var storePluginAssert_1 = require("./tests/storePluginAssert");
64
+ Object.defineProperty(exports, "storePluginAssert", { enumerable: true, get: function () { return __importDefault(storePluginAssert_1).default; } });
63
65
  var BatchCursor_1 = require("./cursors/BatchCursor");
64
66
  Object.defineProperty(exports, "BatchCursorImpl", { enumerable: true, get: function () { return __importDefault(BatchCursor_1).default; } });
65
67
  __exportStar(require("./cursors/BatchCursor"), exports);
@@ -4,9 +4,7 @@ import AbstractMutexer from '../mutexers/AbstractMutexer';
4
4
  import { DataStorePlugin, Database } from '../types/database.types';
5
5
  import { QueryBuilder, QueryOptions } from '../types/query.types';
6
6
  import { PrepareOptions, PrepareResults, SaveOperations, DataStore } from '../types/stores.types';
7
- export default abstract class AbstractStore<FullSchema extends Schema, CreateSchema extends Schema = FullSchema, UpdateSchema extends Schema = CreateSchema, DatabaseSchema extends Schema = FullSchema, DatabaseRecord = SchemaValues<DatabaseSchema> & {
8
- id: string;
9
- }, QueryRecord = SchemaPartialValues<FullSchema>, FullRecord = SchemaValues<FullSchema>, CreateRecord = SchemaValues<CreateSchema>, UpdateRecord = SchemaValues<UpdateSchema> & SaveOperations> extends AbstractMutexer implements DataStore {
7
+ export default abstract class AbstractStore<FullSchema extends Schema, CreateSchema extends Schema = FullSchema, UpdateSchema extends Schema = CreateSchema, DatabaseSchema extends Schema = FullSchema, DatabaseRecord = SchemaValues<DatabaseSchema>, QueryRecord = SchemaPartialValues<FullSchema>, FullRecord = SchemaValues<FullSchema>, CreateRecord = SchemaValues<CreateSchema>, UpdateRecord = SchemaValues<UpdateSchema> & SaveOperations> extends AbstractMutexer implements DataStore {
10
8
  abstract readonly name: string;
11
9
  protected abstract collectionName: string;
12
10
  protected abstract createSchema: CreateSchema;
@@ -0,0 +1,6 @@
1
+ import { Schema } from '@sprucelabs/schema';
2
+ import AbstractStore from '../stores/AbstractStore';
3
+ declare const storePluginAssert: {
4
+ storeHasPlugin: (store: AbstractStore<Schema>, pluginName: string) => import("..").DataStorePlugin;
5
+ };
6
+ export default storePluginAssert;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schema_1 = require("@sprucelabs/schema");
4
+ const test_utils_1 = require("@sprucelabs/test-utils");
5
+ const storePluginAssert = {
6
+ storeHasPlugin: (store, pluginName) => {
7
+ (0, schema_1.assertOptions)({
8
+ store,
9
+ pluginName,
10
+ }, ['store', 'pluginName']);
11
+ //@ts-ignore
12
+ const { plugins } = store;
13
+ if (!(plugins === null || plugins === void 0 ? void 0 : plugins.length)) {
14
+ test_utils_1.assert.fail(`The store you passed has no plugins. Add one to 'protected plugins: DataStorePlugin[] = [...]' or add it in the constructor of your store with 'this.plugins[...]'`);
15
+ }
16
+ const plugin = plugins === null || plugins === void 0 ? void 0 : plugins.find((p) => p.getName() === pluginName);
17
+ if ((plugin === null || plugin === void 0 ? void 0 : plugin.getName()) !== pluginName) {
18
+ test_utils_1.assert.fail(`I could not find the plugin '${pluginName}' in the store you passed. Make sure you added it to 'protected plugins: DataStorePlugin[] = [...]' or added it in the constructor of your store with 'this.plugins[...]'`);
19
+ }
20
+ return plugin;
21
+ },
22
+ };
23
+ exports.default = storePluginAssert;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "25.9.0",
6
+ "version": "25.10.0",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",