@sprucelabs/data-stores 17.0.67 → 17.1.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.
@@ -18,7 +18,9 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
18
18
  initialize?(): Promise<void>;
19
19
  protected prepareRecord?<IncludePrivateFields extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(record: DatabaseRecord, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<PrepareResults<FullSchema, IncludePrivateFields>>;
20
20
  protected willCreate?(values: CreateRecord): Promise<Omit<DatabaseRecord, 'id'>>;
21
+ protected didCreate?(values: CreateRecord): Promise<void>;
21
22
  protected willUpdate?(updates: UpdateRecord, values: DatabaseRecord): Promise<Partial<DatabaseRecord>>;
23
+ protected didUpdate?(old: DatabaseRecord, updated: DatabaseRecord): Promise<void>;
22
24
  protected willScramble?(values: Partial<DatabaseRecord> & {
23
25
  _isScrambled: true;
24
26
  }): Promise<Partial<DatabaseRecord>>;
@@ -77,7 +77,7 @@ export default class AbstractStore extends AbstractMutexer {
77
77
  });
78
78
  }
79
79
  createOne(values, options) {
80
- var _a;
80
+ var _a, _b;
81
81
  return __awaiter(this, void 0, void 0, function* () {
82
82
  try {
83
83
  //@ts-ignore
@@ -92,7 +92,9 @@ export default class AbstractStore extends AbstractMutexer {
92
92
  //@ts-ignore
93
93
  databaseRecord, { shouldCreateEntityInstances: false });
94
94
  const record = yield this.db.createOne(this.collectionName, toSave);
95
- return this.prepareAndNormalizeRecord(record, options);
95
+ yield ((_b = this.didCreate) === null || _b === void 0 ? void 0 : _b.call(this, record));
96
+ const normalized = yield this.prepareAndNormalizeRecord(record, options);
97
+ return normalized;
96
98
  }
97
99
  catch (err) {
98
100
  const coded = errorUtil.transformToSpruceErrors(err, new SpruceError({
@@ -139,7 +141,7 @@ export default class AbstractStore extends AbstractMutexer {
139
141
  yield this.lock(mutexKey);
140
142
  try {
141
143
  const notFoundHandler = () => __awaiter(this, void 0, void 0, function* () {
142
- const created = yield this.createOne(updates, options);
144
+ const created = yield this.createOne(updates, Object.assign(Object.assign({}, options), { shouldIncludePrivateFields: true }));
143
145
  //@ts-ignore
144
146
  return created;
145
147
  });
@@ -182,11 +184,12 @@ export default class AbstractStore extends AbstractMutexer {
182
184
  });
183
185
  }
184
186
  findOneAndUpdate(query, updates, notFoundHandler, options = {}) {
187
+ var _a;
185
188
  return __awaiter(this, void 0, void 0, function* () {
186
189
  const { ops, updates: initialUpdates } = this.pluckOperations(updates);
187
190
  try {
188
191
  const isScrambled = this.isScrambled(initialUpdates);
189
- let current = yield this.findOne(query, options);
192
+ let current = yield this.findOne(query, Object.assign(Object.assign({}, options), { shouldIncludePrivateFields: true }));
190
193
  if (!current) {
191
194
  current = yield notFoundHandler();
192
195
  if (current) {
@@ -214,6 +217,7 @@ export default class AbstractStore extends AbstractMutexer {
214
217
  normalizedValues[name] = value;
215
218
  }
216
219
  const results = yield this.db.updateOne(this.collectionName, query, normalizedValues);
220
+ yield ((_a = this.didUpdate) === null || _a === void 0 ? void 0 : _a.call(this, current, results));
217
221
  return this.prepareAndNormalizeRecord(results, options);
218
222
  }
219
223
  catch (err) {
@@ -18,7 +18,9 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
18
18
  initialize?(): Promise<void>;
19
19
  protected prepareRecord?<IncludePrivateFields extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(record: DatabaseRecord, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<PrepareResults<FullSchema, IncludePrivateFields>>;
20
20
  protected willCreate?(values: CreateRecord): Promise<Omit<DatabaseRecord, 'id'>>;
21
+ protected didCreate?(values: CreateRecord): Promise<void>;
21
22
  protected willUpdate?(updates: UpdateRecord, values: DatabaseRecord): Promise<Partial<DatabaseRecord>>;
23
+ protected didUpdate?(old: DatabaseRecord, updated: DatabaseRecord): Promise<void>;
22
24
  protected willScramble?(values: Partial<DatabaseRecord> & {
23
25
  _isScrambled: true;
24
26
  }): Promise<Partial<DatabaseRecord>>;
@@ -92,7 +92,7 @@ class AbstractStore extends AbstractMutexer_1.default {
92
92
  }
93
93
  }
94
94
  async createOne(values, options) {
95
- var _a;
95
+ var _a, _b;
96
96
  try {
97
97
  //@ts-ignore
98
98
  (0, schema_1.validateSchemaValues)(this.createSchema, values);
@@ -106,7 +106,9 @@ class AbstractStore extends AbstractMutexer_1.default {
106
106
  //@ts-ignore
107
107
  databaseRecord, { shouldCreateEntityInstances: false });
108
108
  const record = await this.db.createOne(this.collectionName, toSave);
109
- return this.prepareAndNormalizeRecord(record, options);
109
+ await ((_b = this.didCreate) === null || _b === void 0 ? void 0 : _b.call(this, record));
110
+ const normalized = await this.prepareAndNormalizeRecord(record, options);
111
+ return normalized;
110
112
  }
111
113
  catch (err) {
112
114
  const coded = error_utility_1.default.transformToSpruceErrors(err, new SpruceError_1.default({
@@ -145,7 +147,7 @@ class AbstractStore extends AbstractMutexer_1.default {
145
147
  await this.lock(mutexKey);
146
148
  try {
147
149
  const notFoundHandler = async () => {
148
- const created = await this.createOne(updates, options);
150
+ const created = await this.createOne(updates, Object.assign(Object.assign({}, options), { shouldIncludePrivateFields: true }));
149
151
  //@ts-ignore
150
152
  return created;
151
153
  };
@@ -183,10 +185,11 @@ class AbstractStore extends AbstractMutexer_1.default {
183
185
  return this.db.update(this.collectionName, query, updates);
184
186
  }
185
187
  async findOneAndUpdate(query, updates, notFoundHandler, options = {}) {
188
+ var _a;
186
189
  const { ops, updates: initialUpdates } = this.pluckOperations(updates);
187
190
  try {
188
191
  const isScrambled = this.isScrambled(initialUpdates);
189
- let current = await this.findOne(query, options);
192
+ let current = await this.findOne(query, Object.assign(Object.assign({}, options), { shouldIncludePrivateFields: true }));
190
193
  if (!current) {
191
194
  current = await notFoundHandler();
192
195
  if (current) {
@@ -214,6 +217,7 @@ class AbstractStore extends AbstractMutexer_1.default {
214
217
  normalizedValues[name] = value;
215
218
  }
216
219
  const results = await this.db.updateOne(this.collectionName, query, normalizedValues);
220
+ await ((_a = this.didUpdate) === null || _a === void 0 ? void 0 : _a.call(this, current, results));
217
221
  return this.prepareAndNormalizeRecord(results, options);
218
222
  }
219
223
  catch (err) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "17.0.67",
6
+ "version": "17.1.0",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",
@@ -73,8 +73,8 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@sprucelabs/error": "^5.0.488",
76
- "@sprucelabs/schema": "^28.3.19",
77
- "@sprucelabs/spruce-skill-utils": "^26.3.15",
76
+ "@sprucelabs/schema": "^28.3.20",
77
+ "@sprucelabs/spruce-skill-utils": "^26.3.17",
78
78
  "globby": "^11.0.4",
79
79
  "just-clone": "^6.0.1",
80
80
  "lodash": "^4.17.21",
@@ -82,7 +82,7 @@
82
82
  "nedb": "^1.8.0"
83
83
  },
84
84
  "devDependencies": {
85
- "@sprucelabs/esm-postbuild": "^1.0.535",
85
+ "@sprucelabs/esm-postbuild": "^1.0.536",
86
86
  "@sprucelabs/jest-json-reporter": "^6.0.433",
87
87
  "@sprucelabs/jest-sheets-reporter": "^1.3.68",
88
88
  "@sprucelabs/resolve-path-aliases": "^1.1.76",