Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

MongoDB Bucket Storage Module #136

Merged
merged 430 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
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 Sep 6, 2024
eae3558
Merge branch 'refs/heads/feat/modular-replication-revised' into remov…
Rentacookie Sep 6, 2024
d6d22b5
Merge pull request #5 from journeyapps-platform/remove-zero-lsn-from-…
Rentacookie Sep 6, 2024
8886b10
Merge branch 'refs/heads/feat/modular-replication-revised' into feat/…
Rentacookie Sep 6, 2024
9fd9308
add some helpers
stevensJourney Sep 6, 2024
6a075e1
Adjusted checks in routes for the the RouterEngine
Rentacookie Sep 9, 2024
b433625
Merge branch 'refs/heads/feat/rework-teardown' into module-mysql
Rentacookie Sep 9, 2024
5b5792d
Updated lockfile
Rentacookie Sep 10, 2024
285afb0
Renamed storage provider storage dispose method.
Rentacookie Sep 10, 2024
7b10465
Merge pull request #8 from journeyapps-platform/feat/rework-teardown
Rentacookie Sep 10, 2024
3acfda0
Merge branch 'refs/heads/main' into feat/modular-replication-architec…
Rentacookie Sep 10, 2024
d2bfd9f
Update lockfile
Rentacookie Sep 10, 2024
04cc1bd
Basic MongoDB replication structure.
rkistner Sep 10, 2024
4ae6b23
Support resuming; multi-document operations.
rkistner Sep 12, 2024
bed97eb
Workaround for transaction boundaries; filter ns in pipeline.
rkistner Sep 13, 2024
f68a6ec
Proper initial snapshot + streaming afterwards.
rkistner Sep 13, 2024
9d68d5c
Use _id directly as replica identity.
rkistner Sep 16, 2024
5cf1474
Configurable defaultSchema.
rkistner Sep 16, 2024
e3576d6
Use _id directly as replica identity.
rkistner Sep 16, 2024
72ded17
Configurable defaultSchema.
rkistner Sep 16, 2024
48a1852
Fix tests.
rkistner Sep 16, 2024
22b95ce
Use 'test_schema' instead of 'public' for tests.
rkistner Sep 16, 2024
ba4fab4
Expand comment.
rkistner Sep 16, 2024
cf14271
Tweaks for ReplicaId.
rkistner Sep 16, 2024
ca2c97d
Fix subkey calculation & tests.
rkistner Sep 16, 2024
3ceae96
Fix more tests.
rkistner Sep 16, 2024
787ff88
Merge branch 'configurable-default-schema' into mongodb-poc
rkistner Sep 16, 2024
e36f306
Fix merge conflicts.
rkistner Sep 16, 2024
3facc2f
Fix Dockerfile.
rkistner Sep 16, 2024
505e728
Fix and test mongo data type conversion.
rkistner Sep 16, 2024
ae89a0d
More mongo format tests.
rkistner Sep 17, 2024
a2857bf
Fix initial snapshot; initial change-stream tests.
rkistner Sep 17, 2024
6c2645d
Fixed missing ErrorRateLimiter for WalStreamReplicationJob
Rentacookie Sep 17, 2024
a9da521
Record keepalive events.
rkistner Sep 17, 2024
aac8101
Another fix; basic replication tests passing.
rkistner Sep 17, 2024
78659d5
Added more logging for compact action
Rentacookie Sep 17, 2024
6a3b1e4
Handle collection drop and rename events.
rkistner Sep 17, 2024
9f1de16
Handle replace event.
rkistner Sep 17, 2024
64bb4f4
Handle missing fullDocument correctly.
rkistner Sep 17, 2024
834aa18
Improve keepalive stability.
rkistner Sep 17, 2024
b8fb012
Added start up and shutdown logging to engines.
Rentacookie Sep 17, 2024
2503cba
Merge branch 'feat/modular-replication-architecture' into configurabl…
rkistner Sep 17, 2024
00a9ed9
Merge remote-tracking branch 'origin/configurable-default-schema' int…
rkistner Sep 17, 2024
1858430
Merge branch 'feat/modular-replication-architecture' into module-mysql
Rentacookie Sep 17, 2024
4fad0b6
Merge pull request #83 from powersync-ja/configurable-default-schema
rkistner Sep 17, 2024
a31b727
Use checkpoints for standard replication.
rkistner Sep 17, 2024
594acc4
Support wildcard table patterns.
rkistner Sep 17, 2024
ef65356
Fix merge issue.
rkistner Sep 17, 2024
d51921f
Added changeset
Rentacookie Sep 18, 2024
74dcead
Made Postgres Module package public
Rentacookie Sep 18, 2024
1f4ded8
Updated lockfile
Rentacookie Sep 18, 2024
952cc1e
Update typescript, vitest, prettier.
rkistner Sep 18, 2024
11cf15e
Apply prettier changes.
rkistner Sep 18, 2024
d279db1
Fix type issues.
rkistner Sep 18, 2024
f433195
Fix tests.
rkistner Sep 18, 2024
6f54a28
Add changeset.
rkistner Sep 19, 2024
9725fac
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner Sep 19, 2024
417cf5f
Merge pull request #84 from powersync-ja/update-tooling
rkistner Sep 19, 2024
e9bf63e
Fix aborting logic.
rkistner Sep 23, 2024
03a18c7
Normalize mongo connection parameters.
rkistner Sep 23, 2024
f428736
Remove error message when closing a ChangStreamReplicationJob.
rkistner Sep 23, 2024
9de2d35
Support M0 clusters; better error message on unsupported clusters.
rkistner Sep 23, 2024
3185e02
Fix sharded cluster check.
rkistner Sep 23, 2024
14b83eb
Fix initial replication regression.
rkistner Sep 23, 2024
df2725a
Refactor schema definitions to not be postgres-specific.
rkistner Sep 25, 2024
a197710
Rename original_type -> internal_type.
rkistner Sep 25, 2024
b0a4411
Include source types in the generated schema comments (optional).
rkistner Sep 25, 2024
3da71a9
Explicit TableSchema type.
rkistner Sep 25, 2024
4ecaee2
Add changeset.
rkistner Sep 25, 2024
43a10fa
Merge pull request #90 from powersync-ja/generic-schema-definitions
rkistner Sep 26, 2024
bfea461
remove mongodb publish config restriction in order to publish dev pac…
stevensJourney Oct 1, 2024
fb52b59
need to explicitly set MongDB package access to public for publish.
stevensJourney Oct 1, 2024
9863b16
Merge remote-tracking branch 'origin/main' into feat/modular-replicat…
rkistner Oct 2, 2024
2eb566a
Post-merge test fixes.
rkistner Oct 2, 2024
6dcfe68
Merge branch 'feat/modular-replication-architecture' into mongodb-alpha
rkistner Oct 2, 2024
354f762
Fix pnpm-lock.
rkistner Oct 2, 2024
b85150c
Implement basic diagnostics apis for MongoDB.
rkistner Oct 2, 2024
b863b67
Add test for getConnectionSchema.
rkistner Oct 2, 2024
5050204
Improve schema filtering; return defaultSchema in API.
rkistner Oct 2, 2024
60f6414
Initialize tag variable before use in nested function call.
Rentacookie Oct 3, 2024
04937a8
Add comment for tag default value
Rentacookie Oct 3, 2024
e4d19b2
Changeset
Rentacookie Oct 3, 2024
b8dfc98
Comment update
Rentacookie Oct 3, 2024
2feb679
Merge pull request #95 from powersync-ja/bugfix-unitialized-tag
Rentacookie Oct 3, 2024
4a654f1
list all databases (#96)
stevensJourney Oct 4, 2024
2a442dc
Merge branch 'feat/modular-replication-architecture' into mongodb-alpha
stevensJourney Oct 7, 2024
9683172
[MongoDB] Schema Endpoint Fix (#97)
stevensJourney Oct 7, 2024
f2963a7
Merge branch 'feat/modular-replication-architecture' into module-mysql
Rentacookie Oct 8, 2024
39638f4
Lockfile update and merge conflict fixes
Rentacookie Oct 8, 2024
aec43b9
Added dev docker compose for mysql
Rentacookie Oct 9, 2024
09cbcf3
Added MySQL connection manager and use appropriate connections
Rentacookie Oct 9, 2024
c8751d7
Added stricter type definition for checkpoints
Rentacookie Oct 9, 2024
9e7b41d
Fixed diagnostics route merge conflict
Rentacookie Oct 10, 2024
12191af
Add MySQLConnection management
Rentacookie Oct 10, 2024
cf002be
Made streamable mysql connections available
Rentacookie Oct 10, 2024
9941e20
Updated BinlogStream to use appropriate connections for snapshot stre…
Rentacookie Oct 10, 2024
49d01cd
Lockfile update
Rentacookie Oct 10, 2024
d2ece1b
[Modules] Feat: Replication Events (#105)
stevensJourney Oct 14, 2024
94c87aa
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner Oct 14, 2024
04d5f30
Merge pull request #85 from powersync-ja/mongodb-alpha
rkistner Oct 15, 2024
0532cd8
Ignore auth errors on collections for mongodb schema.
rkistner Oct 15, 2024
04ddc98
Add changeset.
rkistner Oct 15, 2024
bb367f4
Filter out views.
rkistner Oct 15, 2024
8368671
Merge pull request #106 from powersync-ja/fix-atlas-permissions-handling
rkistner Oct 15, 2024
0932afb
Updated dev/test mysql docker compose
Rentacookie Oct 15, 2024
18ce275
Added BinlogStream tests (WiP)
Rentacookie Oct 15, 2024
20d4b0d
Initializing batch in constructor of MongoBucketBatch
Rentacookie Oct 15, 2024
9c4a14e
Merge branch 'feat/modular-replication-architecture' into module-mysql
Rentacookie Oct 15, 2024
203a737
Some MongoModule merge conflict handling and cleanup
Rentacookie Oct 15, 2024
e218216
Made mysql module publishing public
Rentacookie Oct 15, 2024
8befdce
Updated dockerfile
Rentacookie Oct 15, 2024
c2bd479
Added mysql module to service tsconfig
Rentacookie Oct 15, 2024
38737d4
Fixed dockerfile mysql module copy
Rentacookie Oct 16, 2024
62ffaac
Updated zongji dev package version
Rentacookie Oct 16, 2024
0864bc1
Merge branch 'main' into module_main_update
stevensJourney Oct 16, 2024
c11de66
updates after pulling in main branch
stevensJourney Oct 16, 2024
5aa2322
Merge pull request #107 from powersync-ja/module_main_update
stevensJourney Oct 16, 2024
1ff485d
Updated vitest
Rentacookie Oct 18, 2024
415019b
Added configuration error handling
Rentacookie Oct 18, 2024
186199d
Merge branch 'feat/modular-replication-architecture' into feat/mysql-…
Rentacookie Oct 18, 2024
b4b1f6e
Don't start replication if already aborted
Rentacookie Oct 18, 2024
049669b
Exposed DateStrings connection option in Zongji constructor
Rentacookie Oct 21, 2024
5758003
Lockfile
Rentacookie Oct 21, 2024
2f9e24f
Added ConnectionTester interface
Rentacookie Oct 22, 2024
2ccd6af
[Modules] Move Write Checkpoint APIs (#110)
stevensJourney Oct 22, 2024
cabcb93
Made it possible to specify timezone on zongji listener configuration…
Rentacookie Oct 23, 2024
5ce7ebf
Correctly handle date parsing on binlog events and table snapshotting
Rentacookie Oct 23, 2024
80f6c05
Merge branch 'feat/modular-replication-architecture' into feat/mysql-…
Rentacookie Oct 23, 2024
71f316f
Some cleanup
Rentacookie Oct 23, 2024
618b10e
fix esm stuff
dylanvorster Oct 23, 2024
00b079a
Using syncrule id for MySQL serverId
Rentacookie Oct 28, 2024
8610431
Changeset
Rentacookie Oct 28, 2024
8e7d223
Prevent mysql connection manager throwing errors on shutdown.
Rentacookie Oct 28, 2024
6d8aec9
Improved shutdown logic of binlog stream
Rentacookie Oct 28, 2024
7c073b1
Renamed Checkpoint to ReplicationCheckpoint
Rentacookie Oct 28, 2024
e1f854f
Merge pull request #111 from powersync-ja/feat/mysql-alpha
Rentacookie Oct 28, 2024
e4e8765
Reduce required permissions for replicating from a single database.
rkistner Oct 31, 2024
c6307d8
Add changeset.
rkistner Oct 31, 2024
26a7298
Merge pull request #113 from powersync-ja/mongodb-updates
rkistner Oct 31, 2024
ac03d8f
fix: Cached Parsed Sync Rules (#114)
stevensJourney Nov 1, 2024
03d465d
Merge remote-tracking branch 'origin/main' into chore/modular-main
stevensJourney Nov 4, 2024
43eb945
Merge remote-tracking branch 'origin/main' into chore/modular-main
stevensJourney Nov 4, 2024
5f31083
MySQL Type Consolidation (#115)
Rentacookie Nov 5, 2024
6ed725d
Properly replicate additional MongoDB types:
rkistner Nov 5, 2024
14bdceb
Test mongodb on GA.
rkistner Nov 5, 2024
0c9d991
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner Nov 5, 2024
3bca30f
Also test with MongoDB 8.0.
rkistner Nov 5, 2024
f89a3b5
Merge pull request #119 from powersync-ja/mongodb-types
rkistner Nov 5, 2024
1e50d6b
Support compacting specific buckets when compacting manually.
rkistner Nov 6, 2024
dc04949
Merge pull request #118 from powersync-ja/chore/modular-main
stevensJourney Nov 6, 2024
5a58f45
Merge pull request #120 from powersync-ja/compact-specific-buckets
rkistner Nov 6, 2024
c75f480
Add configuration for using mongodb postimages.
rkistner Nov 6, 2024
ab9b0b1
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner Nov 7, 2024
e4c60cd
Increase timeout between writes in tests.
rkistner Nov 7, 2024
9c3e7d6
Use "await using" to simplify tests.
rkistner Nov 7, 2024
a6cd6f9
Add postImage tests.
rkistner Nov 7, 2024
0b9d0e7
Test and fix wildcard collections.
rkistner Nov 7, 2024
ef85649
Invalidate changestream if postImage is not available.
rkistner Nov 7, 2024
0206aaa
Rename post_images config option.
rkistner Nov 7, 2024
7ba4d11
Parse returned mysql schema result (#122)
Rentacookie Nov 8, 2024
3395de6
More MongoDB type fixes and tests.
rkistner Nov 9, 2024
c209538
Merge pull request #123 from powersync-ja/mongodb-types-2
rkistner Nov 11, 2024
c879923
Handle improperly formatted mysql version strings (#124)
Rentacookie Nov 11, 2024
5160778
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner Nov 12, 2024
81b8cbb
Automatically clear errors when restarting replication.
rkistner Nov 12, 2024
b8ccb40
Use commit instead of keepalive.
rkistner Nov 12, 2024
b4452aa
Fix initial snapshot implementation.
rkistner Nov 12, 2024
225af87
Avoid collMod permission on _powersync_checkpoints.
rkistner Nov 13, 2024
267ec11
Minor cleanup.
rkistner Nov 13, 2024
c5ca6e7
Validate changeStreamPreAndPostImages on existing collections.
rkistner Nov 13, 2024
52bc615
Avoid current_data document storage for MongoDB.
rkistner Nov 13, 2024
812b5c4
Fix tests.
rkistner Nov 13, 2024
80573ac
Merge pull request #121 from powersync-ja/mongodb-postimages
rkistner Nov 13, 2024
2b05388
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner Nov 13, 2024
00af63e
Merge branch 'feat/modular-replication-architecture' into mongodb-fixes
rkistner Nov 13, 2024
91af7db
Merge pull request #128 from powersync-ja/mongodb-fixes
rkistner Nov 13, 2024
0db1a98
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner Nov 13, 2024
62d8f3c
Merge pull request #129 from powersync-ja/mongodb-skip-currentdata
rkistner Nov 13, 2024
28e2269
Use $changeStreamSplitLargeEvent to handle large updates. (#130)
rkistner Nov 13, 2024
b1c3fef
Merge remote-tracking branch 'origin/feat/modular-replication-archite…
rkistner Nov 14, 2024
a8f28ea
Merge branch 'feat/modular-replication-architecture' into update-beta
rkistner Nov 14, 2024
7b168a2
Fix tests.
rkistner Nov 14, 2024
62cfb69
Fix managed write checkpoint filtering. (#134)
rkistner Nov 14, 2024
97df769
Merge pull request #132 from powersync-ja/update-beta
stevensJourney Nov 19, 2024
1f22484
Support json_each in parameter queries (#126)
rkistner Nov 19, 2024
b5b246c
move mongo migration store
stevensJourney Nov 20, 2024
5ac361a
wip: migrations
stevensJourney Nov 25, 2024
6f85619
update existing migrations
stevensJourney Nov 25, 2024
f9d6e56
Add tests for migrations
stevensJourney Nov 25, 2024
407eca0
move mongo implementation to mongo module
stevensJourney Nov 25, 2024
af4ca2d
move db
stevensJourney Nov 25, 2024
a373bab
wip: fix imports
stevensJourney Nov 25, 2024
d0107a7
updates for moving mongostorage provider
stevensJourney Nov 25, 2024
3a457c0
move migrations
stevensJourney Nov 25, 2024
814befc
move locks
stevensJourney Nov 25, 2024
9f3bbb9
rename
stevensJourney Nov 25, 2024
82e5a1e
move more mongo implementation
stevensJourney Nov 25, 2024
58d21df
move more mongodb implementation
stevensJourney Nov 25, 2024
a406ab9
remove mongodb package dependency from core
stevensJourney Nov 26, 2024
5667815
move test utils
stevensJourney Nov 26, 2024
5aa6279
move tests
stevensJourney Nov 26, 2024
bc35932
move utils
stevensJourney Nov 26, 2024
bac6a4b
move bucket validation
stevensJourney Nov 26, 2024
1137719
move snapshots
stevensJourney Nov 26, 2024
7044a6c
move bucket validation tests
stevensJourney Nov 26, 2024
c5361a1
update tests to use test package
stevensJourney Nov 26, 2024
7252c2f
Register storage tests in mongodb module
stevensJourney Nov 27, 2024
64ba7dc
use correct describe method
stevensJourney Nov 27, 2024
479b654
cleanup
stevensJourney Nov 27, 2024
3d04c0a
Merge branch 'main' into postgres-bucket-storage
stevensJourney Nov 27, 2024
34fed66
tmp delete
stevensJourney Nov 27, 2024
f3c51e7
git mv after merge
stevensJourney Nov 27, 2024
bbcbc96
update after merge conflicts
stevensJourney Nov 27, 2024
87aa9ac
make compact action use modules
stevensJourney Nov 27, 2024
2913c92
cleanup migrations api
stevensJourney Nov 29, 2024
6e5862c
sync rules state enum
stevensJourney Nov 29, 2024
d7f776b
bump ts-codec
stevensJourney Dec 9, 2024
e0ae870
Merge remote-tracking branch 'origin/main' into postgres-bucket-storage
stevensJourney Dec 9, 2024
60a1d7f
fix
stevensJourney Dec 12, 2024
a71e741
Migrations improvements for postgres tests
stevensJourney Dec 12, 2024
596765b
cleanup tests
stevensJourney Dec 19, 2024
a176ee3
Merge remote-tracking branch 'origin/main' into postgres-bucket-storage
stevensJourney Dec 19, 2024
e3abf18
fix tests
stevensJourney Dec 19, 2024
697d44b
added changesets
stevensJourney Dec 19, 2024
8ceaa81
fix tests
stevensJourney Dec 19, 2024
ab7608f
cleanup
stevensJourney Dec 19, 2024
a27621c
update changeset
stevensJourney Dec 19, 2024
2eb7d65
share common bson functions
stevensJourney Dec 19, 2024
2f5815d
fixes from testing
stevensJourney Dec 19, 2024
ab7835c
share flatstr
stevensJourney Jan 2, 2025
b333b2b
Merge remote-tracking branch 'origin/main' into postgres-bucket-storage
stevensJourney Jan 2, 2025
405ecc5
fix build
stevensJourney Jan 2, 2025
626f148
update lock api
stevensJourney Jan 2, 2025
2888da9
fix filename typos
stevensJourney Jan 2, 2025
1ac03bd
update imports from filename typos
stevensJourney Jan 2, 2025
9ba04cb
revert sync stream JSON stringification
stevensJourney Jan 2, 2025
20e5619
cleanup. fix tests
stevensJourney Jan 2, 2025
9926a3e
fix mysql tests
stevensJourney Jan 2, 2025
0b4eceb
Merge remote-tracking branch 'origin/main' into postgres-bucket-storage
stevensJourney Jan 7, 2025
6b3c8a7
mongodb storage scaffolding
stevensJourney Jan 7, 2025
a939429
move mongodb implementation to libs
stevensJourney Jan 7, 2025
0fb99ca
move tests
stevensJourney Jan 7, 2025
ba2ffe2
update tests and build for mongodb storage module
stevensJourney Jan 7, 2025
7a1be07
mongodb storage module
stevensJourney Jan 7, 2025
a002120
remove duplication in tests
stevensJourney Jan 7, 2025
4cfd16f
cleanup mongo tests. update lockfile
stevensJourney Jan 7, 2025
2c31536
fix docker build
stevensJourney Jan 7, 2025
962578d
add mongodb config normalization test
stevensJourney Jan 7, 2025
f6db78e
bump bson dependencies
stevensJourney Jan 7, 2025
ad4bce6
Merge remote-tracking branch 'origin/main' into postgres-bucket-storage
stevensJourney Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/big-guests-hunt.md
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
5 changes: 5 additions & 0 deletions .changeset/hungry-brooms-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/service-module-postgres': minor
---

Added minor typing utilities
5 changes: 5 additions & 0 deletions .changeset/ninety-cycles-accept.md
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
9 changes: 9 additions & 0 deletions .changeset/poor-pandas-obey.md
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.
5 changes: 5 additions & 0 deletions .changeset/wicked-papayas-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/lib-services-framework': minor
---

Made migrations more pluggable
1 change: 0 additions & 1 deletion .github/workflows/packages_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ jobs:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Check if @powersync/service-image Released
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ The service can be started using the public Docker image. See the image [notes](

- A light-weight set of definitions and utilities for micro services

- [libs/lib-mongodb](./libs/lib-mongodb/README.md)

- A light-weight set of common logic and types for the MongoDB replication and storage modules.

## Modules

- [modules/module-mongodb](./modules/module-mongodb/README.md)

- MongoDB replication module.

- [modules/module-mongodb-storage](./modules/module-mongodb-storage/README.md)

- MongoDB bucket storage module.

- [modules/module-mysql](./modules/module-mysql/README.md)

- MySQL replication module.

- [modules/module-postgres](./modules/module-postgres/README.md)

- Postgres replication module.

## Service

- [service](./service/README.md)
Expand Down
1 change: 1 addition & 0 deletions libs/lib-mongodb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @powersync/lib-service-mongodb
67 changes: 67 additions & 0 deletions libs/lib-mongodb/LICENSE
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.
3 changes: 3 additions & 0 deletions libs/lib-mongodb/README.md
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.
38 changes: 38 additions & 0 deletions libs/lib-mongodb/package.json
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": {}
}
1 change: 1 addition & 0 deletions libs/lib-mongodb/src/db/db-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './mongo.js';
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as mongo from 'mongodb';
import * as timers from 'timers/promises';

import { configFile } from '@powersync/service-types';
import { normalizeMongoConfig } from '../storage/storage-index.js';
import { BaseMongoConfigDecoded, normalizeMongoConfig } from '../types/types.js';

/**
* Time for new connection to timeout.
Expand Down Expand Up @@ -30,7 +28,7 @@ export const MONGO_OPERATION_TIMEOUT_MS = 30_000;
*/
export const MONGO_CLEAR_OPERATION_TIMEOUT_MS = 5_000;

export function createMongoClient(config: configFile.PowerSyncConfig['storage']) {
export function createMongoClient(config: BaseMongoConfigDecoded) {
const normalized = normalizeMongoConfig(config);
return new mongo.MongoClient(normalized.uri, {
auth: {
Expand Down
8 changes: 8 additions & 0 deletions libs/lib-mongodb/src/index.ts
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';
123 changes: 123 additions & 0 deletions libs/lib-mongodb/src/locks/MongoLockManager.ts
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');
}
}
}
1 change: 1 addition & 0 deletions libs/lib-mongodb/src/locks/locks-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './MongoLockManager.js';
56 changes: 56 additions & 0 deletions libs/lib-mongodb/src/types/types.ts
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
};
}
Loading
Loading