@reventlessdev/reventless-postgres 3.0.0-alpha.19 → 3.0.0-alpha.190
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 +1373 -0
- package/README.md +83 -0
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/ReventlessPostgres.cmt +0 -0
- package/lib/bs/compiler-info.json +3 -3
- package/lib/bs/src/DcbEventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres-ReventlessPostgres.cmj +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres.ast +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres.res +1 -1
- package/lib/bs/src/DcbEventLogStorage_Postgres.res.mjs +6 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops-ReventlessPostgres.cmj +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops.ast +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops.res +112 -42
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops.res.mjs +57 -4
- package/lib/bs/src/EventLogChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/EventLogChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/EventLogChangeFeed.ast +0 -0
- package/lib/bs/src/EventLogChangeFeed.res +15 -6
- package/lib/bs/src/EventLogChangeFeed.res.mjs +3 -3
- package/lib/bs/src/EventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/EventLogStorage_Postgres-ReventlessPostgres.cmj +0 -0
- package/lib/bs/src/EventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/EventLogStorage_Postgres.ast +0 -0
- package/lib/bs/src/EventLogStorage_Postgres.res +1 -1
- package/lib/bs/src/EventLogStorage_Postgres.res.mjs +3 -0
- package/lib/bs/src/EventLogStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/EventLogStorage_Postgres_Ops-ReventlessPostgres.cmj +0 -0
- package/lib/bs/src/EventLogStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/EventLogStorage_Postgres_Ops.ast +0 -0
- package/lib/bs/src/EventLogStorage_Postgres_Ops.res +74 -14
- package/lib/bs/src/EventLogStorage_Postgres_Ops.res.mjs +31 -0
- package/lib/bs/src/PgChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/PgChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/PgChangeFeed.ast +0 -0
- package/lib/bs/src/PgChangeFeed.res +21 -9
- package/lib/bs/src/PgChangeFeed.res.mjs +6 -6
- package/lib/bs/src/PgDriver-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/PgDriver-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/PgDriver-ReventlessPostgres.cmti +0 -0
- package/lib/bs/src/PgDriver.ast +0 -0
- package/lib/bs/src/PgDriver.iast +0 -0
- package/lib/bs/src/PgDriver.res +1 -2
- package/lib/bs/src/PgSchema-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/PgSchema-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/PgSchema.ast +0 -0
- package/lib/bs/src/PgSchema.res +5 -0
- package/lib/bs/src/PgSchema.res.mjs +3 -0
- package/lib/bs/src/QueryDbStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres.ast +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres.res +7 -2
- package/lib/bs/src/QueryDbStorage_Postgres.res.mjs +1 -1
- package/lib/bs/src/QueryDbStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres_Ops.ast +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres_Ops.res +14 -14
- package/lib/bs/src/QueryEnginePostgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/QueryEnginePostgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/QueryEnginePostgres.ast +0 -0
- package/lib/bs/src/QueryEnginePostgres.res +141 -42
- package/lib/bs/src/QueryEnginePostgres.res.mjs +53 -30
- package/lib/bs/tests/PostgresIntegrationTest-ReventlessPostgres.cmi +0 -0
- package/lib/bs/tests/PostgresIntegrationTest-ReventlessPostgres.cmt +0 -0
- package/lib/bs/tests/PostgresIntegrationTest.ast +0 -0
- package/lib/bs/tests/PostgresIntegrationTest.res +157 -104
- package/lib/bs/tests/PostgresIntegrationTest.res.mjs +1 -1
- package/lib/bs/tests/QueryEnginePostgresListPageTest-ReventlessPostgres.cmi +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest-ReventlessPostgres.cmt +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest.ast +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest.res +29 -6
- package/lib/bs/tests/QueryEnginePostgresListPageTest.res.mjs +4 -4
- package/lib/ocaml/.compiler.log +2 -2
- package/lib/ocaml/DcbEventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres-ReventlessPostgres.cmj +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres.ast +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres.res +1 -1
- package/lib/ocaml/DcbEventLogStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres_Ops-ReventlessPostgres.cmj +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres_Ops.ast +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres_Ops.res +112 -42
- package/lib/ocaml/EventLogChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/EventLogChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/EventLogChangeFeed.ast +0 -0
- package/lib/ocaml/EventLogChangeFeed.res +15 -6
- package/lib/ocaml/EventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/EventLogStorage_Postgres-ReventlessPostgres.cmj +0 -0
- package/lib/ocaml/EventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/EventLogStorage_Postgres.ast +0 -0
- package/lib/ocaml/EventLogStorage_Postgres.res +1 -1
- package/lib/ocaml/EventLogStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/EventLogStorage_Postgres_Ops-ReventlessPostgres.cmj +0 -0
- package/lib/ocaml/EventLogStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/EventLogStorage_Postgres_Ops.ast +0 -0
- package/lib/ocaml/EventLogStorage_Postgres_Ops.res +74 -14
- package/lib/ocaml/PgChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/PgChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/PgChangeFeed.ast +0 -0
- package/lib/ocaml/PgChangeFeed.res +21 -9
- package/lib/ocaml/PgDriver-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/PgDriver-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/PgDriver-ReventlessPostgres.cmti +0 -0
- package/lib/ocaml/PgDriver.ast +0 -0
- package/lib/ocaml/PgDriver.iast +0 -0
- package/lib/ocaml/PgDriver.res +1 -2
- package/lib/ocaml/PgSchema-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/PgSchema-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/PgSchema.ast +0 -0
- package/lib/ocaml/PgSchema.res +5 -0
- package/lib/ocaml/PostgresIntegrationTest.res +157 -104
- package/lib/ocaml/QueryDbStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres.ast +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres.res +7 -2
- package/lib/ocaml/QueryDbStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres_Ops.ast +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres_Ops.res +14 -14
- package/lib/ocaml/QueryEnginePostgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/QueryEnginePostgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryEnginePostgres.ast +0 -0
- package/lib/ocaml/QueryEnginePostgres.res +141 -42
- package/lib/ocaml/QueryEnginePostgresListPageTest.res +29 -6
- package/lib/ocaml/ReventlessPostgres.cmt +0 -0
- package/package.json +13 -13
- package/src/DcbEventLogStorage_Postgres.res +1 -1
- package/src/DcbEventLogStorage_Postgres.res.mjs +6 -0
- package/src/DcbEventLogStorage_Postgres_Ops.res +112 -42
- package/src/DcbEventLogStorage_Postgres_Ops.res.mjs +57 -4
- package/src/EventLogChangeFeed.res +15 -6
- package/src/EventLogChangeFeed.res.mjs +3 -3
- package/src/EventLogStorage_Postgres.res +1 -1
- package/src/EventLogStorage_Postgres.res.mjs +3 -0
- package/src/EventLogStorage_Postgres_Ops.res +74 -14
- package/src/EventLogStorage_Postgres_Ops.res.mjs +31 -0
- package/src/PgChangeFeed.res +21 -9
- package/src/PgChangeFeed.res.mjs +6 -6
- package/src/PgDriver.res +1 -2
- package/src/PgSchema.res +5 -0
- package/src/PgSchema.res.mjs +3 -0
- package/src/QueryDbStorage_Postgres.res +7 -2
- package/src/QueryDbStorage_Postgres.res.mjs +1 -1
- package/src/QueryDbStorage_Postgres_Ops.res +14 -14
- package/src/QueryEnginePostgres.res +141 -42
- package/src/QueryEnginePostgres.res.mjs +53 -30
- package/tests/PostgresIntegrationTest.res +157 -104
- package/tests/QueryEnginePostgresListPageTest.res +29 -6
- package/tests/PostgresIntegrationTest.res.mjs +0 -377
- package/tests/QueryEnginePostgresListPageTest.res.mjs +0 -461
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@reventlessdev/reventless-postgres)
|
|
2
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
3
|
+
[](https://docs.reventless.dev)
|
|
4
|
+
|
|
5
|
+
# @reventlessdev/reventless-postgres
|
|
6
|
+
|
|
7
|
+
> ⚠️ **Alpha.** APIs and on-disk formats can change without notice between releases.
|
|
8
|
+
> Pin exact versions and expect breaking changes.
|
|
9
|
+
|
|
10
|
+
The **Postgres storage backend** for [Reventless](https://docs.reventless.dev) — a
|
|
11
|
+
spec-driven, event-sourced CQRS framework written in [ReScript](https://rescript-lang.org).
|
|
12
|
+
It implements the core storage adapters (classic and DCB event logs, the query
|
|
13
|
+
database, and change feeds) over a plain Postgres connection. It carries **no**
|
|
14
|
+
IaC/provider SDK dependency: it connects by connection string, so it runs against
|
|
15
|
+
RDS/Aurora, any managed provider, or a local container.
|
|
16
|
+
|
|
17
|
+
## What it provides
|
|
18
|
+
|
|
19
|
+
ReScript modules, consumed by adding the package to your `rescript.json` `dependencies`:
|
|
20
|
+
|
|
21
|
+
- **`PgDriver`** — the [`node-postgres`](https://node-postgres.com) (`pg`) binding
|
|
22
|
+
(pool/client). Accepts a full `connectionString` or discrete fields, with SSL
|
|
23
|
+
and rotating-secret (password-provider) support.
|
|
24
|
+
- **`PgSchema`** — an idempotent schema + migration runner (`ensureSchema(pool)`),
|
|
25
|
+
safe to run on every startup and concurrently across processes.
|
|
26
|
+
- **`EventLogStorage_Postgres`** — the classic optimistic-concurrency event log
|
|
27
|
+
(`event_log` / `snapshot`).
|
|
28
|
+
- **`DcbEventLogStorage_Postgres`** — the DCB (Dynamic Consistency Boundary) event
|
|
29
|
+
log with a global position sequence and a concurrency-critical `dcb_append`.
|
|
30
|
+
- **`QueryDbStorage_Postgres`** — read-side storage over JSONB `qdb_<name>` tables.
|
|
31
|
+
- **`QueryEnginePostgres`** — compiles the core QueryEngine query/scan AST down to
|
|
32
|
+
SQL, pushing filters into the database.
|
|
33
|
+
- **`EventLogChangeFeed`** / **`PgChangeFeed`** — checkpointed change feeds for the
|
|
34
|
+
classic and DCB logs, using an `xmin`-fenced read plus `LISTEN`/`NOTIFY`
|
|
35
|
+
(`pg_notify`) for near-real-time wakeup. A documented public consumer surface.
|
|
36
|
+
|
|
37
|
+
The `*_Ops` modules hold the runtime-pure operations (no Pulumi import) so a
|
|
38
|
+
deployed handler's ESM graph stays clean; the wrapper modules add the deploy-time
|
|
39
|
+
adapter shape.
|
|
40
|
+
|
|
41
|
+
## Where it fits
|
|
42
|
+
|
|
43
|
+
`reventless-postgres` is a storage **adapter** for the Reventless framework.
|
|
44
|
+
[`reventless-core`](https://www.npmjs.com/package/@reventlessdev/reventless-core)
|
|
45
|
+
is provider-agnostic; this package supplies the Postgres implementation of its
|
|
46
|
+
event-log, query-db, and change-feed interfaces:
|
|
47
|
+
|
|
48
|
+
- [`@reventlessdev/reventless-aws`](https://www.npmjs.com/package/@reventlessdev/reventless-aws) — AWS (DynamoDB, Lambda, SQS, SNS, S3); can delegate event logs to this package for managed Postgres
|
|
49
|
+
- [`@reventlessdev/reventless-postgres`](https://www.npmjs.com/package/@reventlessdev/reventless-postgres) — **this package**
|
|
50
|
+
- [`@reventlessdev/reventless-local`](https://www.npmjs.com/package/@reventlessdev/reventless-local) — in-memory / SQLite platform that uses this storage against a local Postgres
|
|
51
|
+
|
|
52
|
+
Because it depends only on `pg` (plus
|
|
53
|
+
[`reventless-core`](https://www.npmjs.com/package/@reventlessdev/reventless-core),
|
|
54
|
+
[`reventless-infra`](https://www.npmjs.com/package/@reventlessdev/reventless-infra),
|
|
55
|
+
and [`reventless-spec`](https://www.npmjs.com/package/@reventlessdev/reventless-spec)),
|
|
56
|
+
the platform package that embeds it owns provisioning; this package only needs a
|
|
57
|
+
reachable Postgres.
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm add @reventlessdev/reventless-postgres
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Then register it as a ReScript dependency in `rescript.json`:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"dependencies": ["@reventlessdev/reventless-postgres"]
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Requires ReScript `^12.3.1` (peer dependency).
|
|
74
|
+
|
|
75
|
+
## Links
|
|
76
|
+
|
|
77
|
+
- 📚 Documentation — [docs.reventless.dev](https://docs.reventless.dev)
|
|
78
|
+
- 📦 Repository — [ReventlessDev/reventless-core](https://github.com/ReventlessDev/reventless-core)
|
|
79
|
+
- 📋 [Changelog](./CHANGELOG.md)
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
[Apache-2.0](https://opensource.org/licenses/Apache-2.0)
|
package/lib/bs/.compiler.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#Start(
|
|
2
|
-
#Done(
|
|
1
|
+
#Start(1793557493171)
|
|
2
|
+
#Done(1793557495081)
|
|
Binary file
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "12.3.
|
|
2
|
+
"version": "12.3.1",
|
|
3
3
|
"bsc_path": "/home/runner/work/reventless-core/reventless-core/node_modules/@rescript/linux-x64/bin/bsc.exe",
|
|
4
|
-
"bsc_hash": "
|
|
4
|
+
"bsc_hash": "1006241435e8d5052329c523202a7fe6359a37e1e1688c023d37d6a7ebb5fb6d",
|
|
5
5
|
"rescript_config_hash": "af2af60a0fa33b8249a96ff2758f36482843126dc4e07b9302842d011e0ad8c6",
|
|
6
6
|
"runtime_path": "/home/runner/work/reventless-core/reventless-core/node_modules/@rescript/runtime",
|
|
7
|
-
"generated_at": "
|
|
7
|
+
"generated_at": "1793557495086"
|
|
8
8
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// existing `DcbEventLogStorage_Postgres.*` reference keeps working) and adds only
|
|
9
9
|
// the deploy-time `DcbEventLog_Adapter` shape, keeping the historic `makeStorage`
|
|
10
10
|
// 3-tuple `(name, ops, adapter)` API unchanged.
|
|
11
|
-
// See docs/plans/deployed-lambda-esm-self-containment.md (Rung-3 finding).
|
|
11
|
+
// See docs/plans/done/deployed-lambda-esm-self-containment.md (Rung-3 finding).
|
|
12
12
|
|
|
13
13
|
open ReventlessCore
|
|
14
14
|
include DcbEventLogStorage_Postgres_Ops
|
|
@@ -46,6 +46,10 @@ let isConflict = DcbEventLogStorage_Postgres_Ops$ReventlessPostgres.isConflict;
|
|
|
46
46
|
|
|
47
47
|
let countAll = DcbEventLogStorage_Postgres_Ops$ReventlessPostgres.countAll;
|
|
48
48
|
|
|
49
|
+
let readBackwards = DcbEventLogStorage_Postgres_Ops$ReventlessPostgres.readBackwards;
|
|
50
|
+
|
|
51
|
+
let positionsOfAppend = DcbEventLogStorage_Postgres_Ops$ReventlessPostgres.positionsOfAppend;
|
|
52
|
+
|
|
49
53
|
let makeOps = DcbEventLogStorage_Postgres_Ops$ReventlessPostgres.makeOps;
|
|
50
54
|
|
|
51
55
|
export {
|
|
@@ -63,6 +67,8 @@ export {
|
|
|
63
67
|
pageSize,
|
|
64
68
|
isConflict,
|
|
65
69
|
countAll,
|
|
70
|
+
readBackwards,
|
|
71
|
+
positionsOfAppend,
|
|
66
72
|
makeOps,
|
|
67
73
|
makeStorage,
|
|
68
74
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// would leak into the Lambda import graph and fail resolution on real Lambda. The
|
|
7
7
|
// thin `DcbEventLogStorage_Postgres` wrapper `include`s this and adds the
|
|
8
8
|
// deploy-time `Pulumi.Output`-shaped adapter for local/deploy consumers.
|
|
9
|
-
// See docs/plans/deployed-lambda-esm-self-containment.md (Rung-3 finding).
|
|
9
|
+
// See docs/plans/done/deployed-lambda-esm-self-containment.md (Rung-3 finding).
|
|
10
10
|
|
|
11
11
|
open ReventlessCore
|
|
12
12
|
open Reventless
|
|
@@ -67,7 +67,7 @@ let rowToEvent = (row: dict<JSON.t>): DcbEventLog_Adapter.rawSequencedEvent => {
|
|
|
67
67
|
| _ => ""
|
|
68
68
|
}
|
|
69
69
|
let meta = switch row->Dict.get("meta") {
|
|
70
|
-
| Some(metaJson) => metaJson->
|
|
70
|
+
| Some(metaJson) => metaJson->Reventless.Util_Sury.fromJson(Reventless.Message.metaSchema)
|
|
71
71
|
| None => JsError.throwWithMessage("missing meta column in dcb_event row")
|
|
72
72
|
}
|
|
73
73
|
{
|
|
@@ -143,7 +143,7 @@ let buildReadWhere = (
|
|
|
143
143
|
// Strip the zero-padding a cursor carries for string-sortability, leaving a
|
|
144
144
|
// plain decimal both `::xid8` and `::bigint` parse unambiguously ("0" if empty).
|
|
145
145
|
let stripZeros = (s: string): string => {
|
|
146
|
-
let t = s->String.replaceRegExp(
|
|
146
|
+
let t = s->String.replaceRegExp(/^0+/, "")
|
|
147
147
|
t == "" ? "0" : t
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -175,6 +175,75 @@ let countAll = async (pool: PgDriver.pool): int =>
|
|
|
175
175
|
| None => 0
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/** Where a backwards read of one log starts: strictly below a position, or at
|
|
179
|
+
and below it. */
|
|
180
|
+
type bound =
|
|
181
|
+
| Below(float)
|
|
182
|
+
| AtMost(float)
|
|
183
|
+
|
|
184
|
+
/** One log's events newest first by `position`, narrowed to one correlation id
|
|
185
|
+
when given. Rows are `(position, event)`; the event's own `position` field is
|
|
186
|
+
the read cursor, as `read` returns it. */
|
|
187
|
+
let readBackwards = async (
|
|
188
|
+
pool: PgDriver.pool,
|
|
189
|
+
~name: string,
|
|
190
|
+
~bound: option<bound>,
|
|
191
|
+
~limit: int,
|
|
192
|
+
~correlationId: option<string>,
|
|
193
|
+
): array<(float, DcbEventLog_Adapter.rawSequencedEvent)> => {
|
|
194
|
+
let b = mkBuilder()
|
|
195
|
+
let parts = [`log_name = ${b->param(JSON.Encode.string(name))}`]
|
|
196
|
+
switch bound {
|
|
197
|
+
| Some(Below(p)) => parts->Array.push(`position < ${b->param(JSON.Encode.float(p))}::bigint`)
|
|
198
|
+
| Some(AtMost(p)) => parts->Array.push(`position <= ${b->param(JSON.Encode.float(p))}::bigint`)
|
|
199
|
+
| None => ()
|
|
200
|
+
}
|
|
201
|
+
switch correlationId {
|
|
202
|
+
| Some(id) => parts->Array.push(`(meta->>'correlationId') = ${b->param(JSON.Encode.string(id))}`)
|
|
203
|
+
| None => ()
|
|
204
|
+
}
|
|
205
|
+
let limitP = b->param(JSON.Encode.int(limit))
|
|
206
|
+
|
|
207
|
+
(
|
|
208
|
+
await pool->PgDriver.query(
|
|
209
|
+
`SELECT ${selectColumns}, position::text AS pos_raw FROM dcb_event WHERE ${parts->Array.join(
|
|
210
|
+
" AND ",
|
|
211
|
+
)} ORDER BY position DESC LIMIT ${limitP}::int`,
|
|
212
|
+
b.params,
|
|
213
|
+
)
|
|
214
|
+
)->Array.map(row => (
|
|
215
|
+
switch row->Dict.get("pos_raw") {
|
|
216
|
+
| Some(JSON.String(s)) => s->Float.fromString->Option.getOr(0.)
|
|
217
|
+
| _ => 0.
|
|
218
|
+
},
|
|
219
|
+
rowToEvent(row),
|
|
220
|
+
))
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The position of each event one append wrote, by message id. The cursor an
|
|
224
|
+
append returns names its transaction, and every event of the append shares
|
|
225
|
+
it. */
|
|
226
|
+
let positionsOfAppend = async (pool: PgDriver.pool, ~name: string, ~cursor: string): array<(
|
|
227
|
+
string,
|
|
228
|
+
float,
|
|
229
|
+
)> =>
|
|
230
|
+
switch decodeCursor(cursor) {
|
|
231
|
+
| None => []
|
|
232
|
+
| Some((tx, _)) =>
|
|
233
|
+
(
|
|
234
|
+
await pool->PgDriver.query(
|
|
235
|
+
"SELECT position::text AS pos, meta->>'msgId' AS msg_id FROM dcb_event WHERE log_name = $1 AND transaction_id = $2::xid8",
|
|
236
|
+
[JSON.Encode.string(name), JSON.Encode.string(tx)],
|
|
237
|
+
)
|
|
238
|
+
)->Array.filterMap(row =>
|
|
239
|
+
switch (row->Dict.get("msg_id"), row->Dict.get("pos")) {
|
|
240
|
+
| (Some(JSON.String(msgId)), Some(JSON.String(pos))) =>
|
|
241
|
+
pos->Float.fromString->Option.map(p => (msgId, p))
|
|
242
|
+
| _ => None
|
|
243
|
+
}
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
|
|
178
247
|
// Builds the DCB runtime op set bound to `pool`. Returns `(name, ops)`; the
|
|
179
248
|
// deploy-time `DcbEventLog_Adapter` wrapper lives in `DcbEventLogStorage_Postgres`.
|
|
180
249
|
let makeOps = (
|
|
@@ -222,49 +291,45 @@ let makeOps = (
|
|
|
222
291
|
}
|
|
223
292
|
}
|
|
224
293
|
|
|
225
|
-
let append = async (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
294
|
+
let append = async (newEvents: array<DcbEventLog_Adapter.rawStoredEvent>, ~condition=?): result<
|
|
295
|
+
DcbTag.sequencePosition,
|
|
296
|
+
ReventlessInfra.DcbEventLog.appendError,
|
|
297
|
+
> => {
|
|
229
298
|
let eventsJson = JSON.Array(
|
|
230
|
-
newEvents->Array.map(ev =>
|
|
231
|
-
|
|
299
|
+
newEvents->Array.map(ev => JSON.Object(
|
|
300
|
+
Dict.fromArray([
|
|
301
|
+
("event_type", JSON.Encode.string(ev.eventType)),
|
|
302
|
+
(
|
|
303
|
+
"tags",
|
|
304
|
+
JSON.Array(ev.tags->Array.map(t => JSON.Encode.string(t.key ++ "=" ++ t.value))),
|
|
305
|
+
),
|
|
306
|
+
("data", ev.data),
|
|
307
|
+
("meta", ev.meta->Reventless.Util_Sury.toJson(Reventless.Message.metaSchema)),
|
|
308
|
+
]),
|
|
309
|
+
)),
|
|
310
|
+
)
|
|
311
|
+
let conditionParam = switch condition {
|
|
312
|
+
| Some(cond: DcbTag.appendCondition) =>
|
|
313
|
+
let queryJson = JSON.Array(
|
|
314
|
+
cond.query->Array.map(clause => JSON.Object(
|
|
232
315
|
Dict.fromArray([
|
|
233
|
-
(
|
|
316
|
+
(
|
|
317
|
+
"eventTypes",
|
|
318
|
+
switch clause.eventTypes {
|
|
319
|
+
| Some(types) => JSON.Array(types->Array.map(JSON.Encode.string))
|
|
320
|
+
| None => JSON.Encode.null
|
|
321
|
+
},
|
|
322
|
+
),
|
|
234
323
|
(
|
|
235
324
|
"tags",
|
|
236
|
-
|
|
325
|
+
switch clause.tags {
|
|
326
|
+
| Some(tags) =>
|
|
327
|
+
JSON.Array(tags->Array.map(t => JSON.Encode.string(t.key ++ "=" ++ t.value)))
|
|
328
|
+
| None => JSON.Encode.null
|
|
329
|
+
},
|
|
237
330
|
),
|
|
238
|
-
("data", ev.data),
|
|
239
|
-
("meta", ev.meta->S.reverseConvertToJsonOrThrow(Reventless.Message.metaSchema)),
|
|
240
331
|
]),
|
|
241
|
-
)
|
|
242
|
-
),
|
|
243
|
-
)
|
|
244
|
-
let conditionParam = switch condition {
|
|
245
|
-
| Some(cond: DcbTag.appendCondition) =>
|
|
246
|
-
let queryJson = JSON.Array(
|
|
247
|
-
cond.query->Array.map(clause =>
|
|
248
|
-
JSON.Object(
|
|
249
|
-
Dict.fromArray([
|
|
250
|
-
(
|
|
251
|
-
"eventTypes",
|
|
252
|
-
switch clause.eventTypes {
|
|
253
|
-
| Some(types) => JSON.Array(types->Array.map(JSON.Encode.string))
|
|
254
|
-
| None => JSON.Encode.null
|
|
255
|
-
},
|
|
256
|
-
),
|
|
257
|
-
(
|
|
258
|
-
"tags",
|
|
259
|
-
switch clause.tags {
|
|
260
|
-
| Some(tags) =>
|
|
261
|
-
JSON.Array(tags->Array.map(t => JSON.Encode.string(t.key ++ "=" ++ t.value)))
|
|
262
|
-
| None => JSON.Encode.null
|
|
263
|
-
},
|
|
264
|
-
),
|
|
265
|
-
]),
|
|
266
|
-
)
|
|
267
|
-
),
|
|
332
|
+
)),
|
|
268
333
|
)
|
|
269
334
|
let fields = [("query", queryJson)]
|
|
270
335
|
switch cond.after {
|
|
@@ -306,7 +371,10 @@ let makeOps = (
|
|
|
306
371
|
? Error(ReventlessInfra.DcbEventLog.Conflict)
|
|
307
372
|
: Error(
|
|
308
373
|
ReventlessInfra.DcbEventLog.StorageFailure(
|
|
309
|
-
exn
|
|
374
|
+
exn
|
|
375
|
+
->JsExn.fromException
|
|
376
|
+
->Option.flatMap(JsExn.message)
|
|
377
|
+
->Option.getOr("storage error"),
|
|
310
378
|
),
|
|
311
379
|
)
|
|
312
380
|
}
|
|
@@ -324,7 +392,9 @@ let makeOps = (
|
|
|
324
392
|
Effect.promise(() => {
|
|
325
393
|
let b = mkBuilder()
|
|
326
394
|
let where = buildReadWhere(b, ~name, ~query, ~after=cursor, ~applyFence=true)
|
|
327
|
-
let sql = `SELECT ${selectColumns}, transaction_id::text AS tx_raw, position::text AS pos_raw FROM dcb_event WHERE ${where} ORDER BY transaction_id ASC, position ASC LIMIT ${Int.toString(
|
|
395
|
+
let sql = `SELECT ${selectColumns}, transaction_id::text AS tx_raw, position::text AS pos_raw FROM dcb_event WHERE ${where} ORDER BY transaction_id ASC, position ASC LIMIT ${Int.toString(
|
|
396
|
+
pageSize,
|
|
397
|
+
)}`
|
|
328
398
|
pool->PgDriver.query(sql, b.params)
|
|
329
399
|
})->Effect.map(rows => {
|
|
330
400
|
let events = rows->Array.map(rowToEvent)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as S from "sury/src/S.res.mjs";
|
|
4
3
|
import * as Stream from "@reventlessdev/rescript-effect/src/Stream.res.mjs";
|
|
5
4
|
import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
|
|
6
5
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
6
|
+
import * as Stdlib_Float from "@rescript/runtime/lib/es6/Stdlib_Float.js";
|
|
7
7
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
8
8
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
9
9
|
import * as Effect from "effect/Effect";
|
|
@@ -11,6 +11,7 @@ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
|
11
11
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
12
12
|
import * as Message$Reventless from "@reventlessdev/reventless-spec/src/types/Message.res.mjs";
|
|
13
13
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
14
|
+
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
14
15
|
import * as PgDriver$ReventlessPostgres from "./PgDriver.res.mjs";
|
|
15
16
|
|
|
16
17
|
function strategyParam(s) {
|
|
@@ -68,7 +69,7 @@ function rowToEvent(row) {
|
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
71
|
let metaJson = row["meta"];
|
|
71
|
-
let meta = metaJson !== undefined ?
|
|
72
|
+
let meta = metaJson !== undefined ? Util_Sury$Reventless.fromJson(metaJson, Message$Reventless.metaSchema) : Stdlib_JsError.throwWithMessage("missing meta column in dcb_event row");
|
|
72
73
|
return {
|
|
73
74
|
position: str("cursor"),
|
|
74
75
|
eventType: str("event_type"),
|
|
@@ -174,6 +175,56 @@ async function countAll(pool) {
|
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
|
|
178
|
+
async function readBackwards(pool, name, bound, limit, correlationId) {
|
|
179
|
+
let b = {
|
|
180
|
+
params: []
|
|
181
|
+
};
|
|
182
|
+
let parts = [`log_name = ` + param(b, name)];
|
|
183
|
+
if (bound !== undefined) {
|
|
184
|
+
if (bound.TAG === "Below") {
|
|
185
|
+
parts.push(`position < ` + param(b, bound._0) + `::bigint`);
|
|
186
|
+
} else {
|
|
187
|
+
parts.push(`position <= ` + param(b, bound._0) + `::bigint`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (correlationId !== undefined) {
|
|
191
|
+
parts.push(`(meta->>'correlationId') = ` + param(b, correlationId));
|
|
192
|
+
}
|
|
193
|
+
let limitP = param(b, limit);
|
|
194
|
+
return (await PgDriver$ReventlessPostgres.query(pool, `SELECT ` + selectColumns + `, position::text AS pos_raw FROM dcb_event WHERE ` + parts.join(" AND ") + ` ORDER BY position DESC LIMIT ` + limitP + `::int`, b.params)).map(row => {
|
|
195
|
+
let match = row["pos_raw"];
|
|
196
|
+
let tmp;
|
|
197
|
+
tmp = match !== undefined ? (
|
|
198
|
+
typeof match === "string" ? Stdlib_Option.getOr(Stdlib_Float.fromString(match), 0) : 0
|
|
199
|
+
) : 0;
|
|
200
|
+
return [
|
|
201
|
+
tmp,
|
|
202
|
+
rowToEvent(row)
|
|
203
|
+
];
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function positionsOfAppend(pool, name, cursor) {
|
|
208
|
+
let match = decodeCursor(cursor);
|
|
209
|
+
if (match !== undefined) {
|
|
210
|
+
return Stdlib_Array.filterMap(await PgDriver$ReventlessPostgres.query(pool, "SELECT position::text AS pos, meta->>'msgId' AS msg_id FROM dcb_event WHERE log_name = $1 AND transaction_id = $2::xid8", [
|
|
211
|
+
name,
|
|
212
|
+
match[0]
|
|
213
|
+
]), row => {
|
|
214
|
+
let match = row["msg_id"];
|
|
215
|
+
let match$1 = row["pos"];
|
|
216
|
+
if (typeof match === "string" && typeof match$1 === "string") {
|
|
217
|
+
return Stdlib_Option.map(Stdlib_Float.fromString(match$1), p => [
|
|
218
|
+
match,
|
|
219
|
+
p
|
|
220
|
+
]);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
177
228
|
function makeOps(pool, name, param, param$1, param$2, param$3, lockStrategyOpt, onAppendedOpt) {
|
|
178
229
|
let lockStrategy = lockStrategyOpt !== undefined ? lockStrategyOpt : "AdvisoryLocks";
|
|
179
230
|
let onAppended = onAppendedOpt !== undefined ? onAppendedOpt : noTracking;
|
|
@@ -226,7 +277,7 @@ function makeOps(pool, name, param, param$1, param$2, param$3, lockStrategyOpt,
|
|
|
226
277
|
],
|
|
227
278
|
[
|
|
228
279
|
"meta",
|
|
229
|
-
|
|
280
|
+
Util_Sury$Reventless.toJson(ev.meta, Message$Reventless.metaSchema)
|
|
230
281
|
]
|
|
231
282
|
])));
|
|
232
283
|
let conditionParam;
|
|
@@ -375,6 +426,8 @@ export {
|
|
|
375
426
|
pageSize,
|
|
376
427
|
isConflict,
|
|
377
428
|
countAll,
|
|
429
|
+
readBackwards,
|
|
430
|
+
positionsOfAppend,
|
|
378
431
|
makeOps,
|
|
379
432
|
}
|
|
380
|
-
/*
|
|
433
|
+
/* Stream Not a pure module */
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -15,8 +15,11 @@
|
|
|
15
15
|
// later commit) is never skipped by a checkpointing reader. `global_seq` alone,
|
|
16
16
|
// being an IDENTITY assigned at INSERT, could NOT provide that guarantee.
|
|
17
17
|
|
|
18
|
-
// Reuse the shared `<a>:<b>` cursor codec from the DCB storage — identical
|
|
19
|
-
module
|
|
18
|
+
// Reuse the shared `<a>:<b>` cursor codec from the DCB storage — identical
|
|
19
|
+
// format. Point at the runtime-pure `_Ops` module (no `@pulumi/pulumi`): this
|
|
20
|
+
// feed is drained by the deployed change-feed relay Lambda, whose cold-start
|
|
21
|
+
// graph must stay Pulumi-free.
|
|
22
|
+
module Dcb = DcbEventLogStorage_Postgres_Ops
|
|
20
23
|
|
|
21
24
|
// One classic event as the feed surfaces it. `payload` is the stored event JSON
|
|
22
25
|
// verbatim; a bus/topic relay transforms it into its target shape (e.g. the AWS
|
|
@@ -87,11 +90,12 @@ let readBatch = async (
|
|
|
87
90
|
params->Array.push(JSON.Encode.string(tx))
|
|
88
91
|
params->Array.push(JSON.Encode.string(pos))
|
|
89
92
|
where :=
|
|
90
|
-
where.contents ++
|
|
91
|
-
" AND (transaction_id > $2::xid8 OR (transaction_id = $2::xid8 AND global_seq > $3::bigint))"
|
|
93
|
+
where.contents ++ " AND (transaction_id > $2::xid8 OR (transaction_id = $2::xid8 AND global_seq > $3::bigint))"
|
|
92
94
|
| None => ()
|
|
93
95
|
}
|
|
94
|
-
let sql = `SELECT ${selectColumns} FROM event_log WHERE ${where.contents} ORDER BY transaction_id ASC, global_seq ASC LIMIT ${Int.toString(
|
|
96
|
+
let sql = `SELECT ${selectColumns} FROM event_log WHERE ${where.contents} ORDER BY transaction_id ASC, global_seq ASC LIMIT ${Int.toString(
|
|
97
|
+
limit,
|
|
98
|
+
)}`
|
|
95
99
|
let rows = await pool->PgDriver.query(sql, params)
|
|
96
100
|
let events = rows->Array.map(rowToEvent)
|
|
97
101
|
let cursor = switch events->Array.get(events->Array.length - 1) {
|
|
@@ -163,7 +167,12 @@ let drain = async (
|
|
|
163
167
|
let cursor = ref(await loadCheckpoint(pool, ~subscriber))
|
|
164
168
|
let continue = ref(true)
|
|
165
169
|
while continue.contents {
|
|
166
|
-
let {events, cursor: newCursor} = await readBatch(
|
|
170
|
+
let {events, cursor: newCursor} = await readBatch(
|
|
171
|
+
pool,
|
|
172
|
+
~logName,
|
|
173
|
+
~after=?cursor.contents,
|
|
174
|
+
~limit,
|
|
175
|
+
)
|
|
167
176
|
if events->Array.length == 0 {
|
|
168
177
|
continue := false
|
|
169
178
|
} else {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
|
|
4
4
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
5
|
import * as PgDriver$ReventlessPostgres from "./PgDriver.res.mjs";
|
|
6
|
-
import * as
|
|
6
|
+
import * as DcbEventLogStorage_Postgres_Ops$ReventlessPostgres from "./DcbEventLogStorage_Postgres_Ops.res.mjs";
|
|
7
7
|
|
|
8
8
|
let selectColumns = "\n lpad(transaction_id::text, 20, '0') || ':' || lpad(global_seq::text, 20, '0') AS cursor,\n aggregate_id,\n seq_nr,\n payload,\n msg_id\n";
|
|
9
9
|
|
|
@@ -43,7 +43,7 @@ async function readBatch(pool, logName, after, limitOpt) {
|
|
|
43
43
|
let limit = limitOpt !== undefined ? limitOpt : 500;
|
|
44
44
|
let params = [logName];
|
|
45
45
|
let where = "log_name = $1 AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())";
|
|
46
|
-
let match = Stdlib_Option.flatMap(after,
|
|
46
|
+
let match = Stdlib_Option.flatMap(after, DcbEventLogStorage_Postgres_Ops$ReventlessPostgres.decodeCursor);
|
|
47
47
|
if (match !== undefined) {
|
|
48
48
|
params.push(match[0]);
|
|
49
49
|
params.push(match[1]);
|
|
@@ -72,7 +72,7 @@ async function loadCheckpoint(pool, subscriber) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async function saveCheckpoint(pool, subscriber, cursor) {
|
|
75
|
-
let match =
|
|
75
|
+
let match = DcbEventLogStorage_Postgres_Ops$ReventlessPostgres.decodeCursor(cursor);
|
|
76
76
|
if (match !== undefined) {
|
|
77
77
|
await PgDriver$ReventlessPostgres.query(pool, "INSERT INTO event_log_subscription(subscriber, last_tx, last_global_seq)\n VALUES ($1, $2::xid8, $3::bigint)\n ON CONFLICT (subscriber)\n DO UPDATE SET last_tx = EXCLUDED.last_tx, last_global_seq = EXCLUDED.last_global_seq", [
|
|
78
78
|
subscriber,
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// real Lambda). This module `include`s that pure module and adds only the
|
|
8
8
|
// deploy-time `EventLog_Adapter` shape (`operations` wrapped in `Pulumi.Output`),
|
|
9
9
|
// keeping the historic `makeStorage` 3-tuple `(name, ops, adapter)` API unchanged.
|
|
10
|
-
// See docs/plans/deployed-lambda-esm-self-containment.md (Rung-3 finding).
|
|
10
|
+
// See docs/plans/done/deployed-lambda-esm-self-containment.md (Rung-3 finding).
|
|
11
11
|
|
|
12
12
|
open ReventlessCore
|
|
13
13
|
include EventLogStorage_Postgres_Ops
|
|
@@ -27,6 +27,8 @@ let countAll = EventLogStorage_Postgres_Ops$ReventlessPostgres.countAll;
|
|
|
27
27
|
|
|
28
28
|
let isUniqueViolation = EventLogStorage_Postgres_Ops$ReventlessPostgres.isUniqueViolation;
|
|
29
29
|
|
|
30
|
+
let readBackwards = EventLogStorage_Postgres_Ops$ReventlessPostgres.readBackwards;
|
|
31
|
+
|
|
30
32
|
let makeOps = EventLogStorage_Postgres_Ops$ReventlessPostgres.makeOps;
|
|
31
33
|
|
|
32
34
|
export {
|
|
@@ -35,6 +37,7 @@ export {
|
|
|
35
37
|
coerceInt,
|
|
36
38
|
countAll,
|
|
37
39
|
isUniqueViolation,
|
|
40
|
+
readBackwards,
|
|
38
41
|
makeOps,
|
|
39
42
|
makeStorage,
|
|
40
43
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|