@sprucelabs/data-stores 26.4.89 → 27.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. package/build/.spruce/errors/dataStores/databaseNotConnected.schema.js +5 -5
  2. package/build/.spruce/errors/dataStores/duplicateKey.schema.js +1 -1
  3. package/build/.spruce/errors/dataStores/duplicateRecord.schema.js +9 -9
  4. package/build/.spruce/errors/dataStores/failedToLoadStore.schema.js +3 -3
  5. package/build/.spruce/errors/dataStores/failedToLoadStores.schema.js +5 -3
  6. package/build/.spruce/errors/dataStores/indexExists.schema.js +5 -5
  7. package/build/.spruce/errors/dataStores/indexNotFound.schema.js +5 -5
  8. package/build/.spruce/errors/dataStores/invalidConnectionStringScheme.schema.js +3 -3
  9. package/build/.spruce/errors/dataStores/invalidDatabaseName.schema.js +3 -3
  10. package/build/.spruce/errors/dataStores/invalidDbConnectionString.schema.js +1 -1
  11. package/build/.spruce/errors/dataStores/invalidFakeQueryResponse.schema.js +5 -5
  12. package/build/.spruce/errors/dataStores/invalidStore.schema copy.js +5 -5
  13. package/build/.spruce/errors/dataStores/invalidStore.schema.js +1 -1
  14. package/build/.spruce/errors/dataStores/invalidStoreName.schema.js +5 -5
  15. package/build/.spruce/errors/dataStores/mongoIdMappingError.schema.js +1 -1
  16. package/build/.spruce/errors/dataStores/notImplemented.schema.js +1 -1
  17. package/build/.spruce/errors/dataStores/queryNotFaked.schema.js +5 -5
  18. package/build/.spruce/errors/dataStores/record-not-found-query.schema.js +1 -1
  19. package/build/.spruce/errors/dataStores/recordNotFound.schema.js +5 -5
  20. package/build/.spruce/errors/dataStores/scrambleNotConfigured.schema.js +1 -1
  21. package/build/.spruce/errors/dataStores/unableToConnectToDb.schema.js +1 -1
  22. package/build/.spruce/errors/dataStores/unknownDatabaseError.schema.js +3 -3
  23. package/build/.spruce/errors/dataStores/unknownError.schema.js +1 -1
  24. package/build/.spruce/errors/dataStores/unknownStoreError.schema.js +5 -5
  25. package/build/.spruce/errors/errors.types.d.ts +53 -56
  26. package/build/.spruce/errors/errors.types.js +0 -2
  27. package/build/.spruce/errors/options.types.d.ts +2 -2
  28. package/build/.spruce/schemas/fields/fields.types.d.ts +1 -1
  29. package/build/cursors/BatchArrayCursor.d.ts +2 -2
  30. package/build/databases/MongoDatabase.js +3 -1
  31. package/build/databases/NeDbDatabase.js +9 -3
  32. package/build/databases/mongo.types.d.ts +89 -135
  33. package/build/databases/mongo.types.js +0 -1
  34. package/build/errors/SpruceError.d.ts +1 -1
  35. package/build/errors/SpruceError.js +6 -2
  36. package/build/errors/failedToLoadStores.builder.js +1 -1
  37. package/build/errors/mongoIdMappingError.builder.js +0 -2
  38. package/build/errors/scrambleNotConfigured.builder.js +0 -2
  39. package/build/esm/.spruce/errors/errors.types.d.ts +53 -56
  40. package/build/esm/.spruce/errors/errors.types.js +0 -2
  41. package/build/esm/.spruce/errors/options.types.d.ts +2 -2
  42. package/build/esm/cursors/BatchArrayCursor.d.ts +2 -2
  43. package/build/esm/databases/MongoDatabase.js +3 -1
  44. package/build/esm/databases/NeDbDatabase.js +9 -3
  45. package/build/esm/databases/mongo.types.d.ts +89 -135
  46. package/build/esm/databases/mongo.types.js +0 -1
  47. package/build/esm/errors/SpruceError.d.ts +1 -1
  48. package/build/esm/errors/SpruceError.js +6 -2
  49. package/build/esm/errors/failedToLoadStores.builder.js +1 -1
  50. package/build/esm/errors/mongoIdMappingError.builder.js +0 -2
  51. package/build/esm/errors/scrambleNotConfigured.builder.js +0 -2
  52. package/build/esm/loaders/StoreLoader.d.ts +1 -1
  53. package/build/esm/plugins/DatabaseFieldMapperPlugin.js +3 -1
  54. package/build/esm/stores/AbstractStore.js +4 -2
  55. package/build/esm/tests/AbstractDatabaseTest.js +3 -1
  56. package/build/esm/tests/databaseAssertUtil.js +66 -20
  57. package/build/esm/types/query.types.d.ts +4 -4
  58. package/build/esm/types/query.types.js +0 -1
  59. package/build/loaders/StoreLoader.d.ts +1 -1
  60. package/build/plugins/DatabaseFieldMapperPlugin.js +3 -1
  61. package/build/stores/AbstractStore.js +4 -2
  62. package/build/tests/AbstractDatabaseTest.js +3 -1
  63. package/build/tests/databaseAssertUtil.js +66 -20
  64. package/build/types/query.types.d.ts +4 -4
  65. package/build/types/query.types.js +0 -1
  66. package/package.json +20 -32
@@ -1,11 +1,13 @@
1
+ import AbstractSpruceError from '@sprucelabs/error';
1
2
  import { default as SchemaEntity } from '@sprucelabs/schema';
2
3
  import * as SpruceSchema from '@sprucelabs/schema';
4
+ import { FailedToLoadStoreErrorOptions } from './options.types';
3
5
  export declare namespace SpruceErrors.DataStores {
4
6
  interface UnknownStoreError {
5
7
  /** Action. e.g. createPerson, updateLocation, etc */
6
- 'action': string;
8
+ action: string;
7
9
  /** Store name. */
8
- 'storeName': string;
10
+ storeName: string;
9
11
  }
10
12
  interface UnknownStoreErrorSchema extends SpruceSchema.Schema {
11
13
  id: 'unknownStoreError';
@@ -13,7 +15,7 @@ export declare namespace SpruceErrors.DataStores {
13
15
  name: 'Unknown store error';
14
16
  fields: {
15
17
  /** Action. e.g. createPerson, updateLocation, etc */
16
- 'action': {
18
+ action: {
17
19
  label: 'Action';
18
20
  type: 'text';
19
21
  isRequired: true;
@@ -21,7 +23,7 @@ export declare namespace SpruceErrors.DataStores {
21
23
  options: undefined;
22
24
  };
23
25
  /** Store name. */
24
- 'storeName': {
26
+ storeName: {
25
27
  label: 'Store name';
26
28
  type: 'text';
27
29
  isRequired: true;
@@ -44,7 +46,7 @@ export declare namespace SpruceErrors.DataStores {
44
46
  }
45
47
  export declare namespace SpruceErrors.DataStores {
46
48
  interface UnknownDatabaseError {
47
- 'databaseErrorMessage': string;
49
+ databaseErrorMessage: string;
48
50
  }
49
51
  interface UnknownDatabaseErrorSchema extends SpruceSchema.Schema {
50
52
  id: 'unknownDatabaseError';
@@ -52,7 +54,7 @@ export declare namespace SpruceErrors.DataStores {
52
54
  name: 'unknown database error';
53
55
  fields: {
54
56
  /** . */
55
- 'databaseErrorMessage': {
57
+ databaseErrorMessage: {
56
58
  type: 'text';
57
59
  isRequired: true;
58
60
  options: undefined;
@@ -84,10 +86,7 @@ export declare namespace SpruceErrors.DataStores {
84
86
  type ScrambleNotConfiguredEntity = SchemaEntity<SpruceErrors.DataStores.ScrambleNotConfiguredSchema>;
85
87
  }
86
88
  export declare namespace SpruceErrors.DataStores {
87
- interface RecordNotFoundQuery {
88
- /** . */
89
- [field: string]: (any) | undefined | null;
90
- }
89
+ type RecordNotFoundQuery = Record<string, any | undefined | null>;
91
90
  interface RecordNotFoundQuerySchema extends SpruceSchema.Schema {
92
91
  id: 'record-not-found-query';
93
92
  namespace: 'DataStores';
@@ -105,9 +104,9 @@ export declare namespace SpruceErrors.DataStores {
105
104
  export declare namespace SpruceErrors.DataStores {
106
105
  interface RecordNotFound {
107
106
  /** Store name. */
108
- 'storeName': string;
107
+ storeName: string;
109
108
  /** Query. */
110
- 'query': SpruceErrors.DataStores.RecordNotFoundQuery;
109
+ query: SpruceErrors.DataStores.RecordNotFoundQuery;
111
110
  }
112
111
  interface RecordNotFoundSchema extends SpruceSchema.Schema {
113
112
  id: 'recordNotFound';
@@ -115,14 +114,14 @@ export declare namespace SpruceErrors.DataStores {
115
114
  name: 'Record not found';
116
115
  fields: {
117
116
  /** Store name. */
118
- 'storeName': {
117
+ storeName: {
119
118
  label: 'Store name';
120
119
  type: 'text';
121
120
  isRequired: true;
122
121
  options: undefined;
123
122
  };
124
123
  /** Query. */
125
- 'query': {
124
+ query: {
126
125
  label: 'Query';
127
126
  type: 'schema';
128
127
  isRequired: true;
@@ -136,8 +135,8 @@ export declare namespace SpruceErrors.DataStores {
136
135
  }
137
136
  export declare namespace SpruceErrors.DataStores {
138
137
  interface QueryNotFaked {
139
- 'query': string;
140
- 'params'?: (Record<string, any>) | undefined | null;
138
+ query: string;
139
+ params?: Record<string, any> | undefined | null;
141
140
  }
142
141
  interface QueryNotFakedSchema extends SpruceSchema.Schema {
143
142
  id: 'queryNotFaked';
@@ -145,13 +144,13 @@ export declare namespace SpruceErrors.DataStores {
145
144
  name: 'Query not faked';
146
145
  fields: {
147
146
  /** . */
148
- 'query': {
147
+ query: {
149
148
  type: 'text';
150
149
  isRequired: true;
151
150
  options: undefined;
152
151
  };
153
152
  /** . */
154
- 'params': {
153
+ params: {
155
154
  type: 'raw';
156
155
  options: {
157
156
  valueType: `Record<string, any>`;
@@ -185,8 +184,8 @@ export declare namespace SpruceErrors.DataStores {
185
184
  }
186
185
  export declare namespace SpruceErrors.DataStores {
187
186
  interface InvalidStoreName {
188
- 'suppliedName': string;
189
- 'validNames': string[];
187
+ suppliedName: string;
188
+ validNames: string[];
190
189
  }
191
190
  interface InvalidStoreNameSchema extends SpruceSchema.Schema {
192
191
  id: 'invalidStoreName';
@@ -194,13 +193,13 @@ export declare namespace SpruceErrors.DataStores {
194
193
  name: 'Invalid store';
195
194
  fields: {
196
195
  /** . */
197
- 'suppliedName': {
196
+ suppliedName: {
198
197
  type: 'text';
199
198
  isRequired: true;
200
199
  options: undefined;
201
200
  };
202
201
  /** . */
203
- 'validNames': {
202
+ validNames: {
204
203
  type: 'text';
205
204
  isRequired: true;
206
205
  isArray: true;
@@ -223,8 +222,8 @@ export declare namespace SpruceErrors.DataStores {
223
222
  }
224
223
  export declare namespace SpruceErrors.DataStores {
225
224
  interface InvalidFakeQueryResponse {
226
- 'query': string;
227
- 'response': (any);
225
+ query: string;
226
+ response: any;
228
227
  }
229
228
  interface InvalidFakeQueryResponseSchema extends SpruceSchema.Schema {
230
229
  id: 'invalidFakeQueryResponse';
@@ -232,13 +231,13 @@ export declare namespace SpruceErrors.DataStores {
232
231
  name: 'Invalid fake query response';
233
232
  fields: {
234
233
  /** . */
235
- 'query': {
234
+ query: {
236
235
  type: 'text';
237
236
  isRequired: true;
238
237
  options: undefined;
239
238
  };
240
239
  /** . */
241
- 'response': {
240
+ response: {
242
241
  type: 'raw';
243
242
  isRequired: true;
244
243
  options: {
@@ -262,7 +261,7 @@ export declare namespace SpruceErrors.DataStores {
262
261
  }
263
262
  export declare namespace SpruceErrors.DataStores {
264
263
  interface InvalidDatabaseName {
265
- 'suppliedName': string;
264
+ suppliedName: string;
266
265
  }
267
266
  interface InvalidDatabaseNameSchema extends SpruceSchema.Schema {
268
267
  id: 'invalidDatabaseName';
@@ -270,7 +269,7 @@ export declare namespace SpruceErrors.DataStores {
270
269
  name: 'Invalid database name';
271
270
  fields: {
272
271
  /** . */
273
- 'suppliedName': {
272
+ suppliedName: {
274
273
  type: 'text';
275
274
  isRequired: true;
276
275
  options: undefined;
@@ -281,7 +280,7 @@ export declare namespace SpruceErrors.DataStores {
281
280
  }
282
281
  export declare namespace SpruceErrors.DataStores {
283
282
  interface InvalidConnectionStringScheme {
284
- 'connectionString': string;
283
+ connectionString: string;
285
284
  }
286
285
  interface InvalidConnectionStringSchemeSchema extends SpruceSchema.Schema {
287
286
  id: 'invalidConnectionStringScheme';
@@ -289,7 +288,7 @@ export declare namespace SpruceErrors.DataStores {
289
288
  name: 'Invalid connection string scheme';
290
289
  fields: {
291
290
  /** . */
292
- 'connectionString': {
291
+ connectionString: {
293
292
  type: 'text';
294
293
  isRequired: true;
295
294
  options: undefined;
@@ -301,8 +300,8 @@ export declare namespace SpruceErrors.DataStores {
301
300
  export declare namespace SpruceErrors.DataStores {
302
301
  interface IndexNotFound {
303
302
  /** Missing Index. */
304
- 'missingIndex': string[];
305
- 'collectionName': string;
303
+ missingIndex: string[];
304
+ collectionName: string;
306
305
  }
307
306
  interface IndexNotFoundSchema extends SpruceSchema.Schema {
308
307
  id: 'indexNotFound';
@@ -310,7 +309,7 @@ export declare namespace SpruceErrors.DataStores {
310
309
  name: 'Index not found';
311
310
  fields: {
312
311
  /** Missing Index. */
313
- 'missingIndex': {
312
+ missingIndex: {
314
313
  label: 'Missing Index';
315
314
  type: 'text';
316
315
  isRequired: true;
@@ -318,7 +317,7 @@ export declare namespace SpruceErrors.DataStores {
318
317
  options: undefined;
319
318
  };
320
319
  /** . */
321
- 'collectionName': {
320
+ collectionName: {
322
321
  type: 'text';
323
322
  isRequired: true;
324
323
  options: undefined;
@@ -330,8 +329,8 @@ export declare namespace SpruceErrors.DataStores {
330
329
  export declare namespace SpruceErrors.DataStores {
331
330
  interface IndexExists {
332
331
  /** Index Exists. */
333
- 'index': string[];
334
- 'collectionName': string;
332
+ index: string[];
333
+ collectionName: string;
335
334
  }
336
335
  interface IndexExistsSchema extends SpruceSchema.Schema {
337
336
  id: 'indexExists';
@@ -339,7 +338,7 @@ export declare namespace SpruceErrors.DataStores {
339
338
  name: 'Index Exists';
340
339
  fields: {
341
340
  /** Index Exists. */
342
- 'index': {
341
+ index: {
343
342
  label: 'Index Exists';
344
343
  type: 'text';
345
344
  isRequired: true;
@@ -347,7 +346,7 @@ export declare namespace SpruceErrors.DataStores {
347
346
  options: undefined;
348
347
  };
349
348
  /** . */
350
- 'collectionName': {
349
+ collectionName: {
351
350
  type: 'text';
352
351
  isRequired: true;
353
352
  options: undefined;
@@ -356,11 +355,9 @@ export declare namespace SpruceErrors.DataStores {
356
355
  }
357
356
  type IndexExistsEntity = SchemaEntity<SpruceErrors.DataStores.IndexExistsSchema>;
358
357
  }
359
- import AbstractSpruceError from '@sprucelabs/error';
360
- import { FailedToLoadStoreErrorOptions } from "./options.types";
361
358
  export declare namespace SpruceErrors.DataStores {
362
359
  interface FailedToLoadStores {
363
- 'errors': (AbstractSpruceError<FailedToLoadStoreErrorOptions>)[];
360
+ errors: AbstractSpruceError<FailedToLoadStoreErrorOptions>[];
364
361
  }
365
362
  interface FailedToLoadStoresSchema extends SpruceSchema.Schema {
366
363
  id: 'failedToLoadStores';
@@ -368,7 +365,7 @@ export declare namespace SpruceErrors.DataStores {
368
365
  name: 'failed to load stores';
369
366
  fields: {
370
367
  /** . */
371
- 'errors': {
368
+ errors: {
372
369
  type: 'raw';
373
370
  isRequired: true;
374
371
  isArray: true;
@@ -382,7 +379,7 @@ export declare namespace SpruceErrors.DataStores {
382
379
  }
383
380
  export declare namespace SpruceErrors.DataStores {
384
381
  interface FailedToLoadStore {
385
- 'name': string;
382
+ name: string;
386
383
  }
387
384
  interface FailedToLoadStoreSchema extends SpruceSchema.Schema {
388
385
  id: 'failedToLoadStore';
@@ -390,7 +387,7 @@ export declare namespace SpruceErrors.DataStores {
390
387
  name: 'Failed to load store';
391
388
  fields: {
392
389
  /** . */
393
- 'name': {
390
+ name: {
394
391
  type: 'text';
395
392
  isRequired: true;
396
393
  options: undefined;
@@ -401,11 +398,11 @@ export declare namespace SpruceErrors.DataStores {
401
398
  }
402
399
  export declare namespace SpruceErrors.DataStores {
403
400
  interface DuplicateRecord {
404
- 'duplicateFields': string[];
405
- 'duplicateValues': string[];
406
- 'collectionName': string;
401
+ duplicateFields: string[];
402
+ duplicateValues: string[];
403
+ collectionName: string;
407
404
  /** Action. e.g. create, update, etc. */
408
- 'action': string;
405
+ action: string;
409
406
  }
410
407
  interface DuplicateRecordSchema extends SpruceSchema.Schema {
411
408
  id: 'duplicateRecord';
@@ -413,27 +410,27 @@ export declare namespace SpruceErrors.DataStores {
413
410
  name: 'Duplicate record';
414
411
  fields: {
415
412
  /** . */
416
- 'duplicateFields': {
413
+ duplicateFields: {
417
414
  type: 'text';
418
415
  isRequired: true;
419
416
  isArray: true;
420
417
  options: undefined;
421
418
  };
422
419
  /** . */
423
- 'duplicateValues': {
420
+ duplicateValues: {
424
421
  type: 'text';
425
422
  isRequired: true;
426
423
  isArray: true;
427
424
  options: undefined;
428
425
  };
429
426
  /** . */
430
- 'collectionName': {
427
+ collectionName: {
431
428
  type: 'text';
432
429
  isRequired: true;
433
430
  options: undefined;
434
431
  };
435
432
  /** Action. e.g. create, update, etc. */
436
- 'action': {
433
+ action: {
437
434
  label: 'Action';
438
435
  type: 'text';
439
436
  isRequired: true;
@@ -457,8 +454,8 @@ export declare namespace SpruceErrors.DataStores {
457
454
  }
458
455
  export declare namespace SpruceErrors.DataStores {
459
456
  interface DatabaseNotConnected {
460
- 'operationAttempted': string;
461
- 'collectionName'?: string | undefined | null;
457
+ operationAttempted: string;
458
+ collectionName?: string | undefined | null;
462
459
  }
463
460
  interface DatabaseNotConnectedSchema extends SpruceSchema.Schema {
464
461
  id: 'databaseNotConnected';
@@ -466,13 +463,13 @@ export declare namespace SpruceErrors.DataStores {
466
463
  name: 'Database not connected';
467
464
  fields: {
468
465
  /** . */
469
- 'operationAttempted': {
466
+ operationAttempted: {
470
467
  type: 'text';
471
468
  isRequired: true;
472
469
  options: undefined;
473
470
  };
474
471
  /** . */
475
- 'collectionName': {
472
+ collectionName: {
476
473
  type: 'text';
477
474
  options: undefined;
478
475
  };
@@ -1,3 +1 @@
1
- /* eslint-disable @typescript-eslint/no-namespace */
2
- /* eslint-disable no-redeclare */
3
1
  export {};
@@ -1,5 +1,5 @@
1
- import { SpruceErrors } from "./errors.types";
2
- import { ErrorOptions as ISpruceErrorOptions } from "@sprucelabs/error";
1
+ import { ErrorOptions as ISpruceErrorOptions } from '@sprucelabs/error';
2
+ import { SpruceErrors } from './errors.types';
3
3
  export interface UnknownStoreErrorErrorOptions extends SpruceErrors.DataStores.UnknownStoreError, ISpruceErrorOptions {
4
4
  code: 'UNKNOWN_STORE_ERROR';
5
5
  }
@@ -10,6 +10,6 @@ export default class BatchArrayCursor<T> implements BatchCursor<T> {
10
10
  next(): Promise<T[] | null>;
11
11
  [Symbol.asyncIterator](): AsyncIterator<T, T, undefined>;
12
12
  }
13
- export type BatchArrayCursorOptions = {
13
+ export interface BatchArrayCursorOptions {
14
14
  batchSize?: number;
15
- };
15
+ }
@@ -207,7 +207,9 @@ export default class MongoDatabase {
207
207
  }
208
208
  catch (err) {
209
209
  if (err.name === 'MongoParseError') {
210
- throw new SpruceError({ code: 'INVALID_DB_CONNECTION_STRING' });
210
+ throw new SpruceError({
211
+ code: 'INVALID_DB_CONNECTION_STRING',
212
+ });
211
213
  }
212
214
  else if (err.message.includes('ECONNREFUSED')) {
213
215
  throw new SpruceError({ code: 'UNABLE_TO_CONNECT_TO_DB' });
@@ -71,7 +71,9 @@ export default class NeDbDatabase extends AbstractMutexer {
71
71
  withId._id = withId.id;
72
72
  delete withId.id;
73
73
  }
74
- const nullsToPlaceholder = this.handlePlaceholders(withId, NULL_PLACEHOLDER, (val) => val === null || typeof val === 'undefined' || val === NULL_PLACEHOLDER);
74
+ const nullsToPlaceholder = this.handlePlaceholders(withId, NULL_PLACEHOLDER, (val) => val === null ||
75
+ typeof val === 'undefined' ||
76
+ val === NULL_PLACEHOLDER);
75
77
  const undefinedToPlaceholder = this.handlePlaceholders(nullsToPlaceholder, UNDEFINED_PLACEHOLDER, (val) => val === undefined || val === UNDEFINED_PLACEHOLDER);
76
78
  return undefinedToPlaceholder;
77
79
  }
@@ -277,7 +279,9 @@ export default class NeDbDatabase extends AbstractMutexer {
277
279
  }));
278
280
  }
279
281
  else {
280
- resolve(docs ? this.normalizeRecord(docs, neDbOptions) : numUpdated);
282
+ resolve(docs
283
+ ? this.normalizeRecord(docs, neDbOptions)
284
+ : numUpdated);
281
285
  }
282
286
  }));
283
287
  });
@@ -324,7 +328,9 @@ export default class NeDbDatabase extends AbstractMutexer {
324
328
  yield this.randomDelay();
325
329
  if (col._uniqueIndexes) {
326
330
  for (const fields of col._uniqueIndexes) {
327
- const existing = query ? yield this.findOne(collection, query) : null;
331
+ const existing = query
332
+ ? yield this.findOne(collection, query)
333
+ : null;
328
334
  const q = {};
329
335
  const duplicateFields = [];
330
336
  const duplicateValues = [];