@procedures/mongo 0.14.1 → 0.15.1
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.
- package/CHANGELOG.md +53 -0
- package/README.md +8 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/document-storage.d.ts +53 -7
- package/dist/storage/document-storage.d.ts.map +1 -1
- package/dist/storage/document-storage.js +132 -11
- package/dist/storage/document-storage.js.map +1 -1
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/mongo-storage.d.ts +9 -4
- package/dist/storage/mongo-storage.d.ts.map +1 -1
- package/dist/storage/mongo-storage.js +15 -3
- package/dist/storage/mongo-storage.js.map +1 -1
- package/dist/storage/view-storage.d.ts +99 -0
- package/dist/storage/view-storage.d.ts.map +1 -0
- package/dist/storage/view-storage.js +189 -0
- package/dist/storage/view-storage.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +3 -0
- package/src/storage/document-storage.ts +144 -14
- package/src/storage/index.ts +3 -0
- package/src/storage/mongo-storage.ts +15 -4
- package/src/storage/view-storage.ts +243 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,58 @@
|
|
|
1
1
|
# @procedures/mongo
|
|
2
2
|
|
|
3
|
+
## 0.15.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bce8f5c: New: `MongoViewStorage`, a read-only storage of one materialized view for the collection procedures (roadmap CLI-38). A `ViewMaterializer` writes a big rebuild as a new generation in groups, and then it changes the generation in the status of the view. During the rebuild, a plain query of the target reads the rows of two generations.
|
|
8
|
+
|
|
9
|
+
Each read of `MongoViewStorage` finds the current generation of the view one time, and reads only its rows (`viewFilter`). Thus `get`, `getAll`, `find`, `changes` and the other reads of the procedures give one whole generation. The key of a row is its text `_id` in the result of the pipeline. Each write rejects with `FORBIDDEN`, because only the materializer writes a target. Collections that are not views keep their storages, and nothing changes for them.
|
|
10
|
+
- Updated dependencies [c78da2d]
|
|
11
|
+
- Updated dependencies [d99b2d5]
|
|
12
|
+
- Updated dependencies [534e4ea]
|
|
13
|
+
- Updated dependencies [44fdd60]
|
|
14
|
+
- @procedures/client@0.15.1
|
|
15
|
+
- @procedures/collections@0.15.1
|
|
16
|
+
|
|
17
|
+
## 0.15.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- c7198ca: Breaking (roadmap CLI-16, decision D11): the collection writes take an optional expected version. This is its own MINOR of the client group (D13).
|
|
22
|
+
|
|
23
|
+
New:
|
|
24
|
+
|
|
25
|
+
- `collections.<name>.set` and `delete` take `expectedVersion`, and each item of `setBatch` takes `expectedVersion`. The value is the version of the current item that the write expects. `null` expects no item.
|
|
26
|
+
- A conflict changes nothing. The call fails with the new protocol code `VERSION_CONFLICT` (HTTP 409, not retryable). The metadata key `conflicts` (and the field `conflicts` of the HTTP body) has the current item and its version for each id.
|
|
27
|
+
- `StorageItemWriteOptions.expectedVersion` (`set`, `delete`) and `StorageBatchWriteOptions.expectedVersions` (`setBatch`) in both copies of `CollectionStorage`. `VersionConflictError`, `versionConflictsOf()` and the other helpers come from `@procedures/client/query`, `@procedures/client` and `@procedures/collections`.
|
|
28
|
+
- The option `versionOf` of `InMemoryStorage`, `SqliteStorage` and `MongoDocumentStorage` gives the version of an item. The test and the write are one step: synchronous in memory, one transaction in SQLite, the transaction or a compare-and-set on `_seq` in MongoDB. `MongoStorage` refuses a precondition.
|
|
29
|
+
- `ApiStorage` sends the expected versions to the collection procedures, and gives a `VERSION_CONFLICT` back as a `VersionConflictError`.
|
|
30
|
+
- `HybridStorage` sends the base version of each queued write as its expected version. A conflict of the remote goes to `conflictResolution`, as a conflict of a pull. The new option `sendBaseVersions: false` stops it.
|
|
31
|
+
- `ClientError.metadata` gives the metadata of the error response.
|
|
32
|
+
- The contract suite `@procedures/collections/testing` has the cases of the preconditions, and the option `createWithVersions`.
|
|
33
|
+
|
|
34
|
+
The changes of behavior:
|
|
35
|
+
|
|
36
|
+
- A storage must test a precondition, or refuse the write. A storage without `versionOf` refuses a write with an expected version with a `TypeError` whose code is `PRECONDITION_NOT_SUPPORTED`. The contract suite tests it for each storage.
|
|
37
|
+
- A `HybridStorage` with `versionOf` now sends the base version of each queued write. A queued write over a change of another writer got through before. Now the remote refuses it with `VERSION_CONFLICT`, and `conflictResolution` decides: `remote` drops the queued write, `merge` sends the merged item, `local` sends the write again over the current version, and `error` throws `ConflictError` and keeps the queue. The remote must test the precondition: a server storage without `versionOf` refuses each push.
|
|
38
|
+
- `ApiStorage`: a write without an expected version writes as before, and gets no `VERSION_CONFLICT`. Only a caller that gives an expected version, or a `HybridStorage` with `versionOf` over it, can get one.
|
|
39
|
+
- `HybridStorage` with `versionOf`: a queued write that won before can now get the conflict path. The opt-out is `new HybridStorage(remote, { versionOf, sendBaseVersions: false })`: the push sends no expected version, and the last write wins, as before. The default is the new behavior.
|
|
40
|
+
- A write without an expected version writes as before: the last write wins.
|
|
41
|
+
|
|
42
|
+
Migration:
|
|
43
|
+
|
|
44
|
+
- **Site.** No change. The site does not write collections.
|
|
45
|
+
- **MiniMongo.** No change for a storage or a `HybridStorage` without `versionOf`. A `HybridStorage` with `versionOf` over `ApiStorage` needs a server storage with the same `versionOf` (for example `new InMemoryStorage({ versionOf })`), or the option `sendBaseVersions: false`.
|
|
46
|
+
- **Graph.** Graph keeps last-write-wins first (D11): it gives no expected version, so nothing changes. `GraphDocsStorage` must refuse a write with an expected version until it tests one. Add the guard to its `set`, `delete` and `setBatch`, and run the contract suite: its first case tests the refusal. To adopt the version later, stamp a version field on the server, give the storage a `versionOf` that tests it in the write, and give the same `versionOf` to the `HybridStorage` of the client. Then add `createWithVersions` to the contract run.
|
|
47
|
+
- **jarvis.** No change: jarvis gives no expected version. A storage of jarvis that implements `CollectionStorage` must refuse a write with an expected version, as for Graph.
|
|
48
|
+
- **Other storages.** Each class that implements `CollectionStorage` reads the new options of `set`, `delete` and `setBatch`. It tests them in the write, or it rejects the write with `preconditionNotSupported()`. It never ignores them.
|
|
49
|
+
|
|
50
|
+
### Patch Changes
|
|
51
|
+
|
|
52
|
+
- Updated dependencies [c7198ca]
|
|
53
|
+
- @procedures/client@0.15.0
|
|
54
|
+
- @procedures/collections@0.15.0
|
|
55
|
+
|
|
3
56
|
## 0.14.1
|
|
4
57
|
|
|
5
58
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -742,6 +742,14 @@ const totals = await db.collection("orderTotals").find(viewFilter(view)).toArray
|
|
|
742
742
|
- A pass keeps in memory the key of each row of the result (at most `maxRows`) and one group of rows. It keeps nothing between passes.
|
|
743
743
|
- An app with targets from an older materializer (the plain key as `_id`, no generation) needs no migration step. The first pass of each view writes its rows in a generation, and removes the rows of its partition with no generation. A row without the partition field stays.
|
|
744
744
|
|
|
745
|
+
To serve a view through the collection procedures, give its storage `new MongoViewStorage({ view: "totals", db })` (roadmap CLI-38):
|
|
746
|
+
|
|
747
|
+
- Each read finds the current generation of the view one time, and reads only its rows. A reader of `get`, `getAll`, `find` or `changes` thus gets one generation only.
|
|
748
|
+
- A read that starts before a change of generation ends on the previous generation. The materializer keeps its rows for `generationGrace`, so a read must end in that time.
|
|
749
|
+
- The key of a row is its `_id` in the result, a text. The value has that `_id` and the fields of the row.
|
|
750
|
+
- The storage is read-only: a write rejects with `FORBIDDEN`. It has no change log.
|
|
751
|
+
- Give it the same `views`, `partitionField`, `statusField` and `targetId` as the materializer.
|
|
752
|
+
|
|
745
753
|
## Integration with Ecosystem
|
|
746
754
|
|
|
747
755
|
### Bundle Packages
|