-
Notifications
You must be signed in to change notification settings - Fork 25
MongoDB Bucket Storage Module #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
430 commits
Select commit
Hold shift + click to select a range
cbbcc6f
Merge branch 'refs/heads/feat/modular-replication-revised' into feat/…
Rentacookie eae3558
Merge branch 'refs/heads/feat/modular-replication-revised' into remov…
Rentacookie d6d22b5
Merge pull request #5 from journeyapps-platform/remove-zero-lsn-from-…
Rentacookie 8886b10
Merge branch 'refs/heads/feat/modular-replication-revised' into feat/…
Rentacookie 9fd9308
add some helpers
stevensJourney 6a075e1
Adjusted checks in routes for the the RouterEngine
Rentacookie b433625
Merge branch 'refs/heads/feat/rework-teardown' into module-mysql
Rentacookie 5b5792d
Updated lockfile
Rentacookie 285afb0
Renamed storage provider storage dispose method.
Rentacookie 7b10465
Merge pull request #8 from journeyapps-platform/feat/rework-teardown
Rentacookie 3acfda0
Merge branch 'refs/heads/main' into feat/modular-replication-architec…
Rentacookie d2bfd9f
Update lockfile
Rentacookie 04cc1bd
Basic MongoDB replication structure.
rkistner 4ae6b23
Support resuming; multi-document operations.
rkistner bed97eb
Workaround for transaction boundaries; filter ns in pipeline.
rkistner f68a6ec
Proper initial snapshot + streaming afterwards.
rkistner 9d68d5c
Use _id directly as replica identity.
rkistner 5cf1474
Configurable defaultSchema.
rkistner e3576d6
Use _id directly as replica identity.
rkistner 72ded17
Configurable defaultSchema.
rkistner 48a1852
Fix tests.
rkistner 22b95ce
Use 'test_schema' instead of 'public' for tests.
rkistner ba4fab4
Expand comment.
rkistner cf14271
Tweaks for ReplicaId.
rkistner ca2c97d
Fix subkey calculation & tests.
rkistner 3ceae96
Fix more tests.
rkistner 787ff88
Merge branch 'configurable-default-schema' into mongodb-poc
rkistner e36f306
Fix merge conflicts.
rkistner 3facc2f
Fix Dockerfile.
rkistner 505e728
Fix and test mongo data type conversion.
rkistner ae89a0d
More mongo format tests.
rkistner a2857bf
Fix initial snapshot; initial change-stream tests.
rkistner 6c2645d
Fixed missing ErrorRateLimiter for WalStreamReplicationJob
Rentacookie a9da521
Record keepalive events.
rkistner aac8101
Another fix; basic replication tests passing.
rkistner 78659d5
Added more logging for compact action
Rentacookie 6a3b1e4
Handle collection drop and rename events.
rkistner 9f1de16
Handle replace event.
rkistner 64bb4f4
Handle missing fullDocument correctly.
rkistner 834aa18
Improve keepalive stability.
rkistner b8fb012
Added start up and shutdown logging to engines.
Rentacookie 2503cba
Merge branch 'feat/modular-replication-architecture' into configurabl…
rkistner 00a9ed9
Merge remote-tracking branch 'origin/configurable-default-schema' int…
rkistner 1858430
Merge branch 'feat/modular-replication-architecture' into module-mysql
Rentacookie 4fad0b6
Merge pull request #83 from powersync-ja/configurable-default-schema
rkistner a31b727
Use checkpoints for standard replication.
rkistner 594acc4
Support wildcard table patterns.
rkistner ef65356
Fix merge issue.
rkistner d51921f
Added changeset
Rentacookie 74dcead
Made Postgres Module package public
Rentacookie 1f4ded8
Updated lockfile
Rentacookie 952cc1e
Update typescript, vitest, prettier.
rkistner 11cf15e
Apply prettier changes.
rkistner d279db1
Fix type issues.
rkistner f433195
Fix tests.
rkistner 6f54a28
Add changeset.
rkistner 9725fac
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner 417cf5f
Merge pull request #84 from powersync-ja/update-tooling
rkistner e9bf63e
Fix aborting logic.
rkistner 03a18c7
Normalize mongo connection parameters.
rkistner f428736
Remove error message when closing a ChangStreamReplicationJob.
rkistner 9de2d35
Support M0 clusters; better error message on unsupported clusters.
rkistner 3185e02
Fix sharded cluster check.
rkistner 14b83eb
Fix initial replication regression.
rkistner df2725a
Refactor schema definitions to not be postgres-specific.
rkistner a197710
Rename original_type -> internal_type.
rkistner b0a4411
Include source types in the generated schema comments (optional).
rkistner 3da71a9
Explicit TableSchema type.
rkistner 4ecaee2
Add changeset.
rkistner 43a10fa
Merge pull request #90 from powersync-ja/generic-schema-definitions
rkistner bfea461
remove mongodb publish config restriction in order to publish dev pac…
stevensJourney fb52b59
need to explicitly set MongDB package access to public for publish.
stevensJourney 9863b16
Merge remote-tracking branch 'origin/main' into feat/modular-replicat…
rkistner 2eb566a
Post-merge test fixes.
rkistner 6dcfe68
Merge branch 'feat/modular-replication-architecture' into mongodb-alpha
rkistner 354f762
Fix pnpm-lock.
rkistner b85150c
Implement basic diagnostics apis for MongoDB.
rkistner b863b67
Add test for getConnectionSchema.
rkistner 5050204
Improve schema filtering; return defaultSchema in API.
rkistner 60f6414
Initialize tag variable before use in nested function call.
Rentacookie 04937a8
Add comment for tag default value
Rentacookie e4d19b2
Changeset
Rentacookie b8dfc98
Comment update
Rentacookie 2feb679
Merge pull request #95 from powersync-ja/bugfix-unitialized-tag
Rentacookie 4a654f1
list all databases (#96)
stevensJourney 2a442dc
Merge branch 'feat/modular-replication-architecture' into mongodb-alpha
stevensJourney 9683172
[MongoDB] Schema Endpoint Fix (#97)
stevensJourney f2963a7
Merge branch 'feat/modular-replication-architecture' into module-mysql
Rentacookie 39638f4
Lockfile update and merge conflict fixes
Rentacookie aec43b9
Added dev docker compose for mysql
Rentacookie 09cbcf3
Added MySQL connection manager and use appropriate connections
Rentacookie c8751d7
Added stricter type definition for checkpoints
Rentacookie 9e7b41d
Fixed diagnostics route merge conflict
Rentacookie 12191af
Add MySQLConnection management
Rentacookie cf002be
Made streamable mysql connections available
Rentacookie 9941e20
Updated BinlogStream to use appropriate connections for snapshot stre…
Rentacookie 49d01cd
Lockfile update
Rentacookie d2ece1b
[Modules] Feat: Replication Events (#105)
stevensJourney 94c87aa
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner 04d5f30
Merge pull request #85 from powersync-ja/mongodb-alpha
rkistner 0532cd8
Ignore auth errors on collections for mongodb schema.
rkistner 04ddc98
Add changeset.
rkistner bb367f4
Filter out views.
rkistner 8368671
Merge pull request #106 from powersync-ja/fix-atlas-permissions-handling
rkistner 0932afb
Updated dev/test mysql docker compose
Rentacookie 18ce275
Added BinlogStream tests (WiP)
Rentacookie 20d4b0d
Initializing batch in constructor of MongoBucketBatch
Rentacookie 9c4a14e
Merge branch 'feat/modular-replication-architecture' into module-mysql
Rentacookie 203a737
Some MongoModule merge conflict handling and cleanup
Rentacookie e218216
Made mysql module publishing public
Rentacookie 8befdce
Updated dockerfile
Rentacookie c2bd479
Added mysql module to service tsconfig
Rentacookie 38737d4
Fixed dockerfile mysql module copy
Rentacookie 62ffaac
Updated zongji dev package version
Rentacookie 0864bc1
Merge branch 'main' into module_main_update
stevensJourney c11de66
updates after pulling in main branch
stevensJourney 5aa2322
Merge pull request #107 from powersync-ja/module_main_update
stevensJourney 1ff485d
Updated vitest
Rentacookie 415019b
Added configuration error handling
Rentacookie 186199d
Merge branch 'feat/modular-replication-architecture' into feat/mysql-…
Rentacookie b4b1f6e
Don't start replication if already aborted
Rentacookie 049669b
Exposed DateStrings connection option in Zongji constructor
Rentacookie 5758003
Lockfile
Rentacookie 2f9e24f
Added ConnectionTester interface
Rentacookie 2ccd6af
[Modules] Move Write Checkpoint APIs (#110)
stevensJourney cabcb93
Made it possible to specify timezone on zongji listener configuration…
Rentacookie 5ce7ebf
Correctly handle date parsing on binlog events and table snapshotting
Rentacookie 80f6c05
Merge branch 'feat/modular-replication-architecture' into feat/mysql-…
Rentacookie 71f316f
Some cleanup
Rentacookie 618b10e
fix esm stuff
dylanvorster 00b079a
Using syncrule id for MySQL serverId
Rentacookie 8610431
Changeset
Rentacookie 8e7d223
Prevent mysql connection manager throwing errors on shutdown.
Rentacookie 6d8aec9
Improved shutdown logic of binlog stream
Rentacookie 7c073b1
Renamed Checkpoint to ReplicationCheckpoint
Rentacookie e1f854f
Merge pull request #111 from powersync-ja/feat/mysql-alpha
Rentacookie e4e8765
Reduce required permissions for replicating from a single database.
rkistner c6307d8
Add changeset.
rkistner 26a7298
Merge pull request #113 from powersync-ja/mongodb-updates
rkistner ac03d8f
fix: Cached Parsed Sync Rules (#114)
stevensJourney 03d465d
Merge remote-tracking branch 'origin/main' into chore/modular-main
stevensJourney 43eb945
Merge remote-tracking branch 'origin/main' into chore/modular-main
stevensJourney 5f31083
MySQL Type Consolidation (#115)
Rentacookie 6ed725d
Properly replicate additional MongoDB types:
rkistner 14bdceb
Test mongodb on GA.
rkistner 0c9d991
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner 3bca30f
Also test with MongoDB 8.0.
rkistner f89a3b5
Merge pull request #119 from powersync-ja/mongodb-types
rkistner 1e50d6b
Support compacting specific buckets when compacting manually.
rkistner dc04949
Merge pull request #118 from powersync-ja/chore/modular-main
stevensJourney 5a58f45
Merge pull request #120 from powersync-ja/compact-specific-buckets
rkistner c75f480
Add configuration for using mongodb postimages.
rkistner ab9b0b1
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner e4c60cd
Increase timeout between writes in tests.
rkistner 9c3e7d6
Use "await using" to simplify tests.
rkistner a6cd6f9
Add postImage tests.
rkistner 0b9d0e7
Test and fix wildcard collections.
rkistner ef85649
Invalidate changestream if postImage is not available.
rkistner 0206aaa
Rename post_images config option.
rkistner 7ba4d11
Parse returned mysql schema result (#122)
Rentacookie 3395de6
More MongoDB type fixes and tests.
rkistner c209538
Merge pull request #123 from powersync-ja/mongodb-types-2
rkistner c879923
Handle improperly formatted mysql version strings (#124)
Rentacookie 5160778
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner 81b8cbb
Automatically clear errors when restarting replication.
rkistner b8ccb40
Use commit instead of keepalive.
rkistner b4452aa
Fix initial snapshot implementation.
rkistner 225af87
Avoid collMod permission on _powersync_checkpoints.
rkistner 267ec11
Minor cleanup.
rkistner c5ca6e7
Validate changeStreamPreAndPostImages on existing collections.
rkistner 52bc615
Avoid current_data document storage for MongoDB.
rkistner 812b5c4
Fix tests.
rkistner 80573ac
Merge pull request #121 from powersync-ja/mongodb-postimages
rkistner 2b05388
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner 00af63e
Merge branch 'feat/modular-replication-architecture' into mongodb-fixes
rkistner 91af7db
Merge pull request #128 from powersync-ja/mongodb-fixes
rkistner 0db1a98
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner 62d8f3c
Merge pull request #129 from powersync-ja/mongodb-skip-currentdata
rkistner 28e2269
Use $changeStreamSplitLargeEvent to handle large updates. (#130)
rkistner b1c3fef
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner a8f28ea
Merge branch 'feat/modular-replication-architecture' into update-beta
rkistner 7b168a2
Fix tests.
rkistner 62cfb69
Fix managed write checkpoint filtering. (#134)
rkistner 97df769
Merge pull request #132 from powersync-ja/update-beta
stevensJourney 1f22484
Support json_each in parameter queries (#126)
rkistner b5b246c
move mongo migration store
stevensJourney 5ac361a
wip: migrations
stevensJourney 6f85619
update existing migrations
stevensJourney f9d6e56
Add tests for migrations
stevensJourney 407eca0
move mongo implementation to mongo module
stevensJourney af4ca2d
move db
stevensJourney a373bab
wip: fix imports
stevensJourney d0107a7
updates for moving mongostorage provider
stevensJourney 3a457c0
move migrations
stevensJourney 814befc
move locks
stevensJourney 9f3bbb9
rename
stevensJourney 82e5a1e
move more mongo implementation
stevensJourney 58d21df
move more mongodb implementation
stevensJourney a406ab9
remove mongodb package dependency from core
stevensJourney 5667815
move test utils
stevensJourney 5aa6279
move tests
stevensJourney bc35932
move utils
stevensJourney bac6a4b
move bucket validation
stevensJourney 1137719
move snapshots
stevensJourney 7044a6c
move bucket validation tests
stevensJourney c5361a1
update tests to use test package
stevensJourney 7252c2f
Register storage tests in mongodb module
stevensJourney 64ba7dc
use correct describe method
stevensJourney 479b654
cleanup
stevensJourney 3d04c0a
Merge branch 'main' into postgres-bucket-storage
stevensJourney 34fed66
tmp delete
stevensJourney f3c51e7
git mv after merge
stevensJourney bbcbc96
update after merge conflicts
stevensJourney 87aa9ac
make compact action use modules
stevensJourney 2913c92
cleanup migrations api
stevensJourney 6e5862c
sync rules state enum
stevensJourney d7f776b
bump ts-codec
stevensJourney e0ae870
Merge remote-tracking branch 'origin/main' into postgres-bucket-storage
stevensJourney 60a1d7f
fix
stevensJourney a71e741
Migrations improvements for postgres tests
stevensJourney 596765b
cleanup tests
stevensJourney a176ee3
Merge remote-tracking branch 'origin/main' into postgres-bucket-storage
stevensJourney e3abf18
fix tests
stevensJourney 697d44b
added changesets
stevensJourney 8ceaa81
fix tests
stevensJourney ab7608f
cleanup
stevensJourney a27621c
update changeset
stevensJourney 2eb7d65
share common bson functions
stevensJourney 2f5815d
fixes from testing
stevensJourney ab7835c
share flatstr
stevensJourney b333b2b
Merge remote-tracking branch 'origin/main' into postgres-bucket-storage
stevensJourney 405ecc5
fix build
stevensJourney 626f148
update lock api
stevensJourney 2888da9
fix filename typos
stevensJourney 1ac03bd
update imports from filename typos
stevensJourney 9ba04cb
revert sync stream JSON stringification
stevensJourney 20e5619
cleanup. fix tests
stevensJourney 9926a3e
fix mysql tests
stevensJourney 0b4eceb
Merge remote-tracking branch 'origin/main' into postgres-bucket-storage
stevensJourney 6b3c8a7
mongodb storage scaffolding
stevensJourney a939429
move mongodb implementation to libs
stevensJourney 0fb99ca
move tests
stevensJourney ba2ffe2
update tests and build for mongodb storage module
stevensJourney 7a1be07
mongodb storage module
stevensJourney a002120
remove duplication in tests
stevensJourney 4cfd16f
cleanup mongo tests. update lockfile
stevensJourney 2c31536
fix docker build
stevensJourney 962578d
add mongodb config normalization test
stevensJourney f6db78e
bump bson dependencies
stevensJourney ad4bce6
Merge remote-tracking branch 'origin/main' into postgres-bucket-storage
stevensJourney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@powersync/service-core': patch | ||
'@powersync/lib-services-framework': patch | ||
'@powersync/service-sync-rules': patch | ||
--- | ||
|
||
Updated ts-codec to 1.3.0 for better decode error responses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@powersync/service-module-postgres': minor | ||
--- | ||
|
||
Added minor typing utilities |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@powersync/service-core-tests': minor | ||
--- | ||
|
||
Initial release of shared tests for different sync bucket storage providers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@powersync/service-module-mongodb': minor | ||
'@powersync/service-core': minor | ||
'@powersync/service-types': minor | ||
'@powersync/service-module-mongodb-storage': minor | ||
'@powersync/lib-service-mongodb': minor | ||
--- | ||
|
||
Moved MongoDB sync bucket storage implementation to the MongoDB module. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@powersync/lib-services-framework': minor | ||
--- | ||
|
||
Made migrations more pluggable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @powersync/lib-service-mongodb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Functional Source License, Version 1.1, Apache 2.0 Future License | ||
|
||
## Abbreviation | ||
|
||
FSL-1.1-Apache-2.0 | ||
|
||
## Notice | ||
|
||
Copyright 2023-2024 Journey Mobile, Inc. | ||
|
||
## Terms and Conditions | ||
|
||
### Licensor ("We") | ||
|
||
The party offering the Software under these Terms and Conditions. | ||
|
||
### The Software | ||
|
||
The "Software" is each version of the software that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software. | ||
|
||
### License Grant | ||
|
||
Subject to your compliance with this License Grant and the Patents, Redistribution and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display and redistribute the Software for any Permitted Purpose identified below. | ||
|
||
### Permitted Purpose | ||
|
||
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making the Software available to others in a commercial product or service that: | ||
|
||
1. substitutes for the Software; | ||
2. substitutes for any other product or service we offer using the Software that exists as of the date we make the Software available; or | ||
3. offers the same or substantially similar functionality as the Software. | ||
|
||
Permitted Purposes specifically include using the Software: | ||
|
||
1. for your internal use and access; | ||
2. for non-commercial education; | ||
3. for non-commercial research; and | ||
4. in connection with professional services that you provide to a licensee using the Software in accordance with these Terms and Conditions. | ||
|
||
### Patents | ||
|
||
To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that the Software infringes or contributes to the infringement of any patent, then your patent license to the Software ends immediately. | ||
|
||
### Redistribution | ||
|
||
The Terms and Conditions apply to all copies, modifications and derivatives of the Software. | ||
If you redistribute any copies, modifications or derivatives of the Software, you must include a copy of or a link to these Terms and Conditions and not remove any copyright notices provided in or with the Software. | ||
|
||
### Disclaimer | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT. | ||
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE. | ||
|
||
### Trademarks | ||
|
||
Except for displaying the License Details and identifying us as the origin of the Software, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks or product names. | ||
|
||
## Grant of Future License | ||
|
||
We hereby irrevocably grant you an additional license to use the Software under the Apache License, Version 2.0 that is effective on the second anniversary of the date we make the Software available. On or after that date, you may use the Software under the Apache License, Version 2.0, in which case the following will apply: | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# PowerSync Service MongoDB | ||
|
||
Library for common MongoDB logic used in the PowerSync service. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@powersync/lib-service-mongodb", | ||
"repository": "https://github.com/powersync-ja/powersync-service", | ||
"types": "dist/index.d.ts", | ||
"version": "0.1.8", | ||
"main": "dist/index.js", | ||
"license": "FSL-1.1-Apache-2.0", | ||
"type": "module", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build": "tsc -b", | ||
"build:tests": "tsc -b test/tsconfig.json", | ||
"clean": "rm -rf ./dist && tsc -b --clean", | ||
"test": "vitest" | ||
}, | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.js", | ||
"default": "./dist/index.js" | ||
}, | ||
"./types": { | ||
"import": "./dist/types/types.js", | ||
"require": "./dist/types/types.js", | ||
"default": "./dist/types/types.js" | ||
} | ||
}, | ||
"dependencies": { | ||
"@powersync/lib-services-framework": "workspace:*", | ||
"bson": "^6.8.0", | ||
"mongodb": "^6.11.0", | ||
"ts-codec": "^1.3.0", | ||
"uri-js": "^4.4.1" | ||
}, | ||
"devDependencies": {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './mongo.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export * from './db/db-index.js'; | ||
export * as db from './db/db-index.js'; | ||
|
||
export * from './locks/locks-index.js'; | ||
export * as locks from './locks/locks-index.js'; | ||
|
||
export * from './types/types.js'; | ||
export * as types from './types/types.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import * as framework from '@powersync/lib-services-framework'; | ||
import * as bson from 'bson'; | ||
import * as mongo from 'mongodb'; | ||
|
||
/** | ||
* Lock Document Schema | ||
*/ | ||
export type Lock = { | ||
name: string; | ||
active_lock?: { | ||
lock_id: bson.ObjectId; | ||
ts: Date; | ||
}; | ||
}; | ||
|
||
export type Collection = mongo.Collection<Lock>; | ||
|
||
export type MongoLockManagerParams = framework.locks.LockManagerParams & { | ||
collection: Collection; | ||
}; | ||
|
||
const DEFAULT_LOCK_TIMEOUT = 60 * 1000; // 1 minute | ||
|
||
export class MongoLockManager extends framework.locks.AbstractLockManager { | ||
collection: Collection; | ||
constructor(params: MongoLockManagerParams) { | ||
super(params); | ||
this.collection = params.collection; | ||
} | ||
|
||
protected async acquireHandle(options?: framework.LockAcquireOptions): Promise<framework.LockHandle | null> { | ||
const lock_id = await this.getHandle(); | ||
if (!lock_id) { | ||
return null; | ||
} | ||
return { | ||
refresh: () => this.refreshHandle(lock_id), | ||
release: () => this.releaseHandle(lock_id) | ||
}; | ||
} | ||
|
||
protected async refreshHandle(lock_id: bson.ObjectId) { | ||
const res = await this.collection.updateOne( | ||
{ | ||
'active_lock.lock_id': lock_id | ||
}, | ||
{ | ||
$set: { | ||
'active_lock.ts': new Date() | ||
} | ||
} | ||
); | ||
|
||
if (res.modifiedCount === 0) { | ||
throw new Error('Lock not found, could not refresh'); | ||
} | ||
} | ||
|
||
protected async getHandle() { | ||
const now = new Date(); | ||
const lock_timeout = this.params.timeout ?? DEFAULT_LOCK_TIMEOUT; | ||
const lock_id = new bson.ObjectId(); | ||
|
||
const { name } = this.params; | ||
await this.collection.updateOne( | ||
{ | ||
name | ||
}, | ||
{ | ||
$setOnInsert: { | ||
name | ||
} | ||
}, | ||
{ | ||
upsert: true | ||
} | ||
); | ||
|
||
const expired_ts = now.getTime() - lock_timeout; | ||
|
||
const res = await this.collection.updateOne( | ||
{ | ||
$and: [ | ||
{ name: name }, | ||
{ | ||
$or: [{ active_lock: { $exists: false } }, { 'active_lock.ts': { $lte: new Date(expired_ts) } }] | ||
} | ||
] | ||
}, | ||
{ | ||
$set: { | ||
active_lock: { | ||
lock_id: lock_id, | ||
ts: now | ||
} | ||
} | ||
} | ||
); | ||
|
||
if (res.modifiedCount === 0) { | ||
return null; | ||
} | ||
|
||
return lock_id; | ||
} | ||
|
||
protected async releaseHandle(lock_id: bson.ObjectId) { | ||
const res = await this.collection.updateOne( | ||
{ | ||
'active_lock.lock_id': lock_id | ||
}, | ||
{ | ||
$unset: { | ||
active_lock: true | ||
} | ||
} | ||
); | ||
|
||
if (res.modifiedCount === 0) { | ||
throw new Error('Lock not found, could not release'); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './MongoLockManager.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as t from 'ts-codec'; | ||
import * as urijs from 'uri-js'; | ||
|
||
export const MONGO_CONNECTION_TYPE = 'mongodb' as const; | ||
|
||
export const BaseMongoConfig = t.object({ | ||
type: t.literal(MONGO_CONNECTION_TYPE), | ||
uri: t.string, | ||
database: t.string.optional(), | ||
username: t.string.optional(), | ||
password: t.string.optional() | ||
}); | ||
|
||
export type BaseMongoConfig = t.Encoded<typeof BaseMongoConfig>; | ||
export type BaseMongoConfigDecoded = t.Decoded<typeof BaseMongoConfig>; | ||
|
||
/** | ||
* Construct a mongodb URI, without username, password or ssl options. | ||
* | ||
* Only contains hostname, port, database. | ||
*/ | ||
export function baseUri(options: BaseMongoConfig) { | ||
return options.uri; | ||
} | ||
|
||
/** | ||
* Validate and normalize connection options. | ||
* | ||
* Returns destructured options. | ||
* | ||
* For use by both storage and mongo module. | ||
*/ | ||
export function normalizeMongoConfig(options: BaseMongoConfigDecoded) { | ||
let uri = urijs.parse(options.uri); | ||
|
||
const database = options.database ?? uri.path?.substring(1) ?? ''; | ||
|
||
const userInfo = uri.userinfo?.split(':'); | ||
|
||
const username = options.username ?? userInfo?.[0]; | ||
const password = options.password ?? userInfo?.[1]; | ||
|
||
if (database == '') { | ||
throw new Error(`database required`); | ||
} | ||
|
||
delete uri.userinfo; | ||
|
||
return { | ||
uri: urijs.serialize(uri), | ||
database, | ||
|
||
username, | ||
password | ||
}; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.