@sprucelabs/data-stores 9.0.115 → 9.0.118

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.
@@ -3,6 +3,7 @@ import AbstractMutexer from '../mutexers/AbstractMutexer';
3
3
  import { Database } from '../types/database.types';
4
4
  import { QueryBuilder, QueryOptions } from '../types/query.types';
5
5
  import { PrepareOptions, PrepareResults } from '../types/stores.types';
6
+ declare type Response<FullSchema extends Schema, CreateEntityInstances extends boolean, IncludePrivateFields extends boolean, PF extends SchemaPublicFieldNames<FullSchema>, F extends SchemaFieldNames<FullSchema>> = IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, CreateEntityInstances> : IncludePrivateFields extends false ? Pick<SchemaPublicValues<FullSchema, CreateEntityInstances>, PF> : Pick<SchemaAllValues<FullSchema, CreateEntityInstances>, F>;
6
7
  export default abstract class AbstractStore<FullSchema extends Schema, CreateSchema extends Schema = FullSchema, UpdateSchema extends Schema = CreateSchema, DatabaseSchema extends Schema = FullSchema, DatabaseRecord = SchemaValues<DatabaseSchema> & {
7
8
  id: string;
8
9
  }, QueryRecord = SchemaPartialValues<FullSchema>, FullRecord = SchemaValues<FullSchema>, CreateRecord = SchemaValues<CreateSchema>, UpdateRecord = SchemaValues<UpdateSchema>> extends AbstractMutexer {
@@ -20,24 +21,25 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
20
21
  protected willUpdate?(updates: UpdateRecord, values: DatabaseRecord): Promise<Partial<DatabaseRecord>>;
21
22
  protected willScramble?(values: Partial<DatabaseRecord> & {
22
23
  _isScrambled: true;
23
- }): Promise<any>;
24
+ }): Promise<Partial<DatabaseRecord>>;
24
25
  protected constructor(db: Database, collectionName?: string);
25
26
  private setCollectionName;
26
- protected prepareAndNormalizeRecord<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(record: any, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, CreateEntityInstances> : IncludePrivateFields extends false ? Pick<SchemaPublicValues<FullSchema, CreateEntityInstances>, PF> : Pick<SchemaAllValues<FullSchema, CreateEntityInstances>, F>>;
27
- create<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(values: CreateRecord[], options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Awaited<IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, false> : CreateEntityInstances extends false ? Pick<SchemaPublicValues<FullSchema, false, SchemaPublicFieldNames<FullSchema>, SchemaValues<FullSchema, false>>, SchemaPublicFieldNames<FullSchema>> : Pick<SchemaAllValues<FullSchema, false>, F>>[]>;
28
- createOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(values: CreateRecord, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, false> : CreateEntityInstances extends false ? Pick<SchemaPublicValues<FullSchema, false, SchemaPublicFieldNames<FullSchema>, SchemaValues<FullSchema, false>>, SchemaPublicFieldNames<FullSchema>> : Pick<SchemaAllValues<FullSchema, false>, F>>;
29
- findOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<(IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, false> : CreateEntityInstances extends false ? Pick<SchemaPublicValues<FullSchema, false, SchemaPublicFieldNames<FullSchema>, SchemaValues<FullSchema, false>>, SchemaPublicFieldNames<FullSchema>> : Pick<SchemaAllValues<FullSchema, false>, F>) | null>;
27
+ protected prepareAndNormalizeRecord<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(record: any, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>>;
28
+ create<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(values: CreateRecord[], options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>[]>;
29
+ createOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(values: CreateRecord, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Response<FullSchema, false, CreateEntityInstances, SchemaPublicFieldNames<FullSchema>, F>>;
30
+ findOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Response<FullSchema, false, CreateEntityInstances, SchemaPublicFieldNames<FullSchema>, F> | null>;
30
31
  count(query?: QueryBuilder<QueryRecord>): Promise<number>;
31
- find<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, queryOptions?: Omit<QueryOptions, 'includeFields'>, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Awaited<IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, false> : CreateEntityInstances extends false ? Pick<SchemaPublicValues<FullSchema, false, SchemaPublicFieldNames<FullSchema>, SchemaValues<FullSchema, false>>, SchemaPublicFieldNames<FullSchema>> : Pick<SchemaAllValues<FullSchema, false>, F>>[]>;
32
- upsertOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, updates: UpdateRecord & CreateRecord & {
32
+ find<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, queryOptions?: Omit<QueryOptions, 'includeFields'>, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Awaited<Response<FullSchema, false, CreateEntityInstances, SchemaPublicFieldNames<FullSchema>, F>>[]>;
33
+ upsertOne<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, updates: UpdateRecord & CreateRecord & {
33
34
  id?: string;
34
- }, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<any>;
35
- updateOne<IncludePrivateFields extends boolean = false, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, updates: UpdateRecord, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<IncludePrivateFields extends false ? Pick<SchemaPublicValues<FullSchema, CreateEntityInstances>, PF> : Pick<SchemaAllValues<FullSchema, CreateEntityInstances>, F>>;
35
+ }, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>>;
36
+ updateOne<IncludePrivateFields extends boolean = false, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, updates: UpdateRecord, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>>;
36
37
  update(query: QueryBuilder<QueryRecord>, updates: UpdateRecord): Promise<number>;
37
38
  private findOneAndUpdate;
38
- scramble(id: string): Promise<Pick<SchemaPublicValues<FullSchema, false, SchemaPublicFieldNames<FullSchema>, SchemaValues<FullSchema, false>>, SchemaPublicFieldNames<FullSchema>>>;
39
+ scramble(id: string): Promise<Response<FullSchema, false, false, SchemaPublicFieldNames<FullSchema>, Extract<keyof FullSchema["fields"], string>>>;
39
40
  private isScrambled;
40
41
  private generateScrambledRecord;
41
42
  deleteOne(query: QueryBuilder<QueryRecord>): Promise<number>;
42
43
  delete(query: QueryBuilder<QueryRecord>): Promise<number>;
43
44
  }
45
+ export {};
@@ -169,7 +169,7 @@ export default class AbstractStore extends AbstractMutexer {
169
169
  return this.db.update(this.collectionName, query, updates);
170
170
  });
171
171
  }
172
- findOneAndUpdate(query, updates, notFoundHandler, options) {
172
+ findOneAndUpdate(query, updates, notFoundHandler, options = {}) {
173
173
  return __awaiter(this, void 0, void 0, function* () {
174
174
  try {
175
175
  const isScrambled = this.isScrambled(updates);
@@ -3,6 +3,7 @@ import AbstractMutexer from '../mutexers/AbstractMutexer';
3
3
  import { Database } from '../types/database.types';
4
4
  import { QueryBuilder, QueryOptions } from '../types/query.types';
5
5
  import { PrepareOptions, PrepareResults } from '../types/stores.types';
6
+ declare type Response<FullSchema extends Schema, CreateEntityInstances extends boolean, IncludePrivateFields extends boolean, PF extends SchemaPublicFieldNames<FullSchema>, F extends SchemaFieldNames<FullSchema>> = IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, CreateEntityInstances> : IncludePrivateFields extends false ? Pick<SchemaPublicValues<FullSchema, CreateEntityInstances>, PF> : Pick<SchemaAllValues<FullSchema, CreateEntityInstances>, F>;
6
7
  export default abstract class AbstractStore<FullSchema extends Schema, CreateSchema extends Schema = FullSchema, UpdateSchema extends Schema = CreateSchema, DatabaseSchema extends Schema = FullSchema, DatabaseRecord = SchemaValues<DatabaseSchema> & {
7
8
  id: string;
8
9
  }, QueryRecord = SchemaPartialValues<FullSchema>, FullRecord = SchemaValues<FullSchema>, CreateRecord = SchemaValues<CreateSchema>, UpdateRecord = SchemaValues<UpdateSchema>> extends AbstractMutexer {
@@ -20,24 +21,25 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
20
21
  protected willUpdate?(updates: UpdateRecord, values: DatabaseRecord): Promise<Partial<DatabaseRecord>>;
21
22
  protected willScramble?(values: Partial<DatabaseRecord> & {
22
23
  _isScrambled: true;
23
- }): Promise<any>;
24
+ }): Promise<Partial<DatabaseRecord>>;
24
25
  protected constructor(db: Database, collectionName?: string);
25
26
  private setCollectionName;
26
- protected prepareAndNormalizeRecord<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(record: any, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, CreateEntityInstances> : IncludePrivateFields extends false ? Pick<SchemaPublicValues<FullSchema, CreateEntityInstances>, PF> : Pick<SchemaAllValues<FullSchema, CreateEntityInstances>, F>>;
27
- create<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(values: CreateRecord[], options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Awaited<IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, false> : CreateEntityInstances extends false ? Pick<SchemaPublicValues<FullSchema, false, SchemaPublicFieldNames<FullSchema>, SchemaValues<FullSchema, false>>, SchemaPublicFieldNames<FullSchema>> : Pick<SchemaAllValues<FullSchema, false>, F>>[]>;
28
- createOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(values: CreateRecord, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, false> : CreateEntityInstances extends false ? Pick<SchemaPublicValues<FullSchema, false, SchemaPublicFieldNames<FullSchema>, SchemaValues<FullSchema, false>>, SchemaPublicFieldNames<FullSchema>> : Pick<SchemaAllValues<FullSchema, false>, F>>;
29
- findOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<(IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, false> : CreateEntityInstances extends false ? Pick<SchemaPublicValues<FullSchema, false, SchemaPublicFieldNames<FullSchema>, SchemaValues<FullSchema, false>>, SchemaPublicFieldNames<FullSchema>> : Pick<SchemaAllValues<FullSchema, false>, F>) | null>;
27
+ protected prepareAndNormalizeRecord<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(record: any, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>>;
28
+ create<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(values: CreateRecord[], options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>[]>;
29
+ createOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(values: CreateRecord, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Response<FullSchema, false, CreateEntityInstances, SchemaPublicFieldNames<FullSchema>, F>>;
30
+ findOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Response<FullSchema, false, CreateEntityInstances, SchemaPublicFieldNames<FullSchema>, F> | null>;
30
31
  count(query?: QueryBuilder<QueryRecord>): Promise<number>;
31
- find<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, queryOptions?: Omit<QueryOptions, 'includeFields'>, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Awaited<IsDynamicSchema<FullSchema> extends true ? DynamicSchemaAllValues<FullSchema, false> : CreateEntityInstances extends false ? Pick<SchemaPublicValues<FullSchema, false, SchemaPublicFieldNames<FullSchema>, SchemaValues<FullSchema, false>>, SchemaPublicFieldNames<FullSchema>> : Pick<SchemaAllValues<FullSchema, false>, F>>[]>;
32
- upsertOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, updates: UpdateRecord & CreateRecord & {
32
+ find<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, queryOptions?: Omit<QueryOptions, 'includeFields'>, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Awaited<Response<FullSchema, false, CreateEntityInstances, SchemaPublicFieldNames<FullSchema>, F>>[]>;
33
+ upsertOne<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, updates: UpdateRecord & CreateRecord & {
33
34
  id?: string;
34
- }, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<any>;
35
- updateOne<IncludePrivateFields extends boolean = false, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, updates: UpdateRecord, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<IncludePrivateFields extends false ? Pick<SchemaPublicValues<FullSchema, CreateEntityInstances>, PF> : Pick<SchemaAllValues<FullSchema, CreateEntityInstances>, F>>;
35
+ }, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>>;
36
+ updateOne<IncludePrivateFields extends boolean = false, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, updates: UpdateRecord, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>>;
36
37
  update(query: QueryBuilder<QueryRecord>, updates: UpdateRecord): Promise<number>;
37
38
  private findOneAndUpdate;
38
- scramble(id: string): Promise<Pick<SchemaPublicValues<FullSchema, false, SchemaPublicFieldNames<FullSchema>, SchemaValues<FullSchema, false>>, SchemaPublicFieldNames<FullSchema>>>;
39
+ scramble(id: string): Promise<Response<FullSchema, false, false, SchemaPublicFieldNames<FullSchema>, Extract<keyof FullSchema["fields"], string>>>;
39
40
  private isScrambled;
40
41
  private generateScrambledRecord;
41
42
  deleteOne(query: QueryBuilder<QueryRecord>): Promise<number>;
42
43
  delete(query: QueryBuilder<QueryRecord>): Promise<number>;
43
44
  }
45
+ export {};
@@ -170,7 +170,7 @@ class AbstractStore extends AbstractMutexer_1.default {
170
170
  async update(query, updates) {
171
171
  return this.db.update(this.collectionName, query, updates);
172
172
  }
173
- async findOneAndUpdate(query, updates, notFoundHandler, options) {
173
+ async findOneAndUpdate(query, updates, notFoundHandler, options = {}) {
174
174
  try {
175
175
  const isScrambled = this.isScrambled(updates);
176
176
  let current = await this.findOne(query, options);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "9.0.115",
6
+ "version": "9.0.118",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",
@@ -72,22 +72,22 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@sprucelabs/error": "^5.0.448",
75
- "@sprucelabs/schema": "^27.1.65",
76
- "@sprucelabs/spruce-core-schemas": "^25.0.104",
77
- "@sprucelabs/spruce-skill-utils": "^25.0.104",
75
+ "@sprucelabs/schema": "^27.1.66",
76
+ "@sprucelabs/spruce-core-schemas": "^25.0.106",
77
+ "@sprucelabs/spruce-skill-utils": "^25.0.106",
78
78
  "globby": "^11.0.4",
79
79
  "lodash": "^4.17.21",
80
80
  "mongodb": "^4.1.0",
81
81
  "nedb": "^1.8.0"
82
82
  },
83
83
  "devDependencies": {
84
- "@sprucelabs/esm-postbuild": "^1.0.456",
85
- "@sprucelabs/jest-json-reporter": "^6.0.370",
84
+ "@sprucelabs/esm-postbuild": "^1.0.457",
85
+ "@sprucelabs/jest-json-reporter": "^6.0.371",
86
86
  "@sprucelabs/jest-sheets-reporter": "^1.3.42",
87
87
  "@sprucelabs/resolve-path-aliases": "^1.1.35",
88
88
  "@sprucelabs/semantic-release": "^4.0.8",
89
89
  "@sprucelabs/test": "^7.7.309",
90
- "@sprucelabs/test-utils": "^3.0.535",
90
+ "@sprucelabs/test-utils": "^3.0.536",
91
91
  "@types/lodash": "^4.14.182",
92
92
  "@types/nedb": "^1.8.12",
93
93
  "@types/node": "17.0.5",