shelving 1.307.1 → 1.307.2

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.
@@ -1,7 +1,7 @@
1
1
  import type { Data } from "../../util/data.js";
2
2
  import type { Identifier, Item, Items, ItemsSequence, OptionalItem, OptionalItemSequence } from "../../util/item.js";
3
3
  import type { Query } from "../../util/query.js";
4
- import type { Updates } from "../../util/update.js";
4
+ import { type Updates } from "../../util/update.js";
5
5
  import type { Collection } from "../collection/Collection.js";
6
6
  import { ThroughDBProvider } from "./ThroughDBProvider.js";
7
7
  /**
@@ -1,6 +1,7 @@
1
1
  import { ValueError } from "../../error/ValueError.js";
2
2
  import { PARTIAL } from "../../schema/DataSchema.js";
3
3
  import { getNamedMessage } from "../../util/error.js";
4
+ import { getUpdates } from "../../util/update.js";
4
5
  import { ThroughDBProvider } from "./ThroughDBProvider.js";
5
6
  /**
6
7
  * Database provider that validates data flowing to and from an asynchronous source provider.
@@ -113,8 +114,19 @@ function* _yieldValidItems(collection, items, caller) {
113
114
  throw new ValueError(`Invalid data for "${collection}"\n${messages.join("\n")}`, { received: items, caller });
114
115
  }
115
116
  function _validateUpdates(collection, updates, caller) {
117
+ // Only a plain top-level key is a prop of the data schema. An encoded key (`+=num`, `+[]tags`, `=a.b`) or a path (`a.b`)
118
+ // is not, so the schema would strip it: keep it as it is. `getUpdates()` throws if a sum is not a number.
119
+ const plain = {};
120
+ const encoded = {};
121
+ for (const [key, value] of Object.entries(updates)) {
122
+ if (_isPlainKey(key))
123
+ plain[key] = value;
124
+ else
125
+ encoded[key] = value;
126
+ }
127
+ getUpdates(encoded);
116
128
  try {
117
- return PARTIAL(collection).validate(updates);
129
+ return { ...PARTIAL(collection).validate(plain), ...encoded };
118
130
  }
119
131
  catch (thrown) {
120
132
  if (typeof thrown !== "string")
@@ -122,3 +134,7 @@ function _validateUpdates(collection, updates, caller) {
122
134
  throw new ValueError(`Invalid updates for "${collection}"\n${thrown}`, { received: updates, caller });
123
135
  }
124
136
  }
137
+ /** Is an `Updates` key a plain top-level prop, with no update prefix and no path? */
138
+ function _isPlainKey(key) {
139
+ return !key.includes(".") && !/^(?:=|\+=|-=|\+\[\]|-\[\])/.test(key);
140
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.307.1",
3
+ "version": "1.307.2",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",