@voltro/plugin-analytics-postgres 0.86.0 → 0.88.0
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 +5484 -0
- package/README.md +28 -1
- package/THIRD-PARTY-NOTICES.md +1511 -276
- package/dist/dialectSql.js +1 -2
- package/dist/eventsTable.js +1 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -2
- package/dist/sink.js +35 -11
- package/package.json +5 -5
package/dist/dialectSql.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/dialectSql.ts
|
|
2
2
|
var e = (e, t, n) => {
|
|
3
3
|
let r = `$.${n}`;
|
|
4
4
|
return e.onDialectOrElse({
|
|
@@ -44,5 +44,4 @@ var e = (e, t, n) => {
|
|
|
44
44
|
orElse: () => e`date_trunc('month', ${r})`
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
|
-
//#endregion
|
|
48
47
|
export { t as jsonNumber, e as jsonString, n as truncateBucket };
|
package/dist/eventsTable.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bigint as e, boolean as t, id as n, json as r, table as i, text as a, timestamp as o } from "@voltro/database";
|
|
2
|
-
|
|
2
|
+
// src/eventsTable.ts
|
|
3
3
|
var s = i("_voltro_events", {
|
|
4
4
|
id: n({ scheme: "numeric" }),
|
|
5
5
|
name: a(),
|
|
@@ -17,5 +17,4 @@ var s = i("_voltro_events", {
|
|
|
17
17
|
version: e().default("0"),
|
|
18
18
|
is_deleted: t().default(!1)
|
|
19
19
|
}).primaryKey(["id"]).nonReactive();
|
|
20
|
-
//#endregion
|
|
21
20
|
export { s as _voltroEventsTable, l as mirrorTable, c as mirrorTableName };
|
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ export declare interface PostgresAnalyticsOptions {
|
|
|
79
79
|
*/
|
|
80
80
|
export declare interface PostgresAnalyticsSpec {
|
|
81
81
|
readonly kind: 'postgres-analytics';
|
|
82
|
+
readonly sql: 'required';
|
|
82
83
|
readonly options: PostgresAnalyticsOptions;
|
|
83
84
|
/** Internal — the cli calls this with the resolved SqlClient. */
|
|
84
85
|
readonly build: (sqlClient: SqlClient.SqlClient) => AnalyticsSinkImpl;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _voltroEventsTable as e, mirrorTable as t, mirrorTableName as n } from "./eventsTable.js";
|
|
2
2
|
import { buildPostgresAnalyticsSink as r } from "./sink.js";
|
|
3
3
|
import { registerRetention as i, retentionTtlMsFromEnv as a } from "@voltro/database";
|
|
4
|
-
|
|
4
|
+
// src/index.ts
|
|
5
5
|
var o = (e = {}) => (i({
|
|
6
6
|
source: "plugin",
|
|
7
7
|
table: "_voltro_events",
|
|
@@ -9,6 +9,7 @@ var o = (e = {}) => (i({
|
|
|
9
9
|
ttlMs: a(process.env.VOLTRO_EVENTS_TTL_HOURS, 8760)
|
|
10
10
|
}), {
|
|
11
11
|
kind: "postgres-analytics",
|
|
12
|
+
sql: "required",
|
|
12
13
|
options: e,
|
|
13
14
|
build: (t) => r(e.sqlClient ?? t, {
|
|
14
15
|
...e.mirrorTables === void 0 ? {} : { mirrorTables: e.mirrorTables },
|
|
@@ -16,5 +17,4 @@ var o = (e = {}) => (i({
|
|
|
16
17
|
}),
|
|
17
18
|
tables: s(e)
|
|
18
19
|
}), s = (n = {}) => [e, ...(n.mirrorTables ?? []).map((e) => t(e))];
|
|
19
|
-
//#endregion
|
|
20
20
|
export { e as _voltroEventsTable, t as mirrorTable, n as mirrorTableName, o as postgresAnalytics, s as postgresAnalyticsTables };
|
package/dist/sink.js
CHANGED
|
@@ -2,7 +2,7 @@ import { mirrorTableName as e } from "./eventsTable.js";
|
|
|
2
2
|
import { jsonNumber as t, jsonString as n, truncateBucket as r } from "./dialectSql.js";
|
|
3
3
|
import { Effect as i } from "effect";
|
|
4
4
|
import { AnalyticsError as a } from "@voltro/runtime";
|
|
5
|
-
|
|
5
|
+
// src/sink.ts
|
|
6
6
|
var o = "postgres-analytics", s = "_voltro_events", c = (e, t) => e.onDialectOrElse({
|
|
7
7
|
sqlite: () => t.toISOString(),
|
|
8
8
|
orElse: () => t
|
|
@@ -19,16 +19,41 @@ var o = "postgres-analytics", s = "_voltro_events", c = (e, t) => e.onDialectOrE
|
|
|
19
19
|
operation: e,
|
|
20
20
|
cause: t instanceof Error ? `${t.name}: ${t.message}` : String(t)
|
|
21
21
|
})), c = (n, r, a, o, s) => i.gen(function* () {
|
|
22
|
-
let i = e(n)
|
|
23
|
-
|
|
22
|
+
let i = e(n), c = t.onDialectOrElse({
|
|
23
|
+
sqlite: () => +!!s,
|
|
24
|
+
orElse: () => s
|
|
25
|
+
});
|
|
26
|
+
yield* t.onDialectOrElse({
|
|
27
|
+
mysql: () => t`
|
|
24
28
|
INSERT INTO ${t(i)} (${t("id")}, ${t("data")}, ${t("version")}, ${t("is_deleted")})
|
|
25
|
-
VALUES (${r}, ${a}, ${o}, ${
|
|
26
|
-
ON
|
|
27
|
-
${t("data")} = ${a},
|
|
28
|
-
${t("
|
|
29
|
-
${t("
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
VALUES (${r}, ${a}, ${o}, ${c})
|
|
30
|
+
ON DUPLICATE KEY UPDATE
|
|
31
|
+
${t("data")} = IF(${t("version")} < ${o}, ${a}, ${t("data")}),
|
|
32
|
+
${t("is_deleted")} = IF(${t("version")} < ${o}, ${c}, ${t("is_deleted")}),
|
|
33
|
+
${t("version")} = IF(${t("version")} < ${o}, ${o}, ${t("version")})
|
|
34
|
+
`,
|
|
35
|
+
mssql: () => t`
|
|
36
|
+
MERGE INTO ${t(i)} WITH (HOLDLOCK) AS target
|
|
37
|
+
USING (SELECT ${r} AS ${t("id")}, ${a} AS ${t("data")},
|
|
38
|
+
${o} AS ${t("version")}, ${c} AS ${t("is_deleted")}) AS source
|
|
39
|
+
ON target.${t("id")} = source.${t("id")}
|
|
40
|
+
WHEN MATCHED AND target.${t("version")} < source.${t("version")} THEN
|
|
41
|
+
UPDATE SET ${t("data")} = source.${t("data")},
|
|
42
|
+
${t("is_deleted")} = source.${t("is_deleted")}, ${t("version")} = source.${t("version")}
|
|
43
|
+
WHEN NOT MATCHED THEN
|
|
44
|
+
INSERT (${t("id")}, ${t("data")}, ${t("version")}, ${t("is_deleted")})
|
|
45
|
+
VALUES (source.${t("id")}, source.${t("data")}, source.${t("version")}, source.${t("is_deleted")});
|
|
46
|
+
`,
|
|
47
|
+
orElse: () => t`
|
|
48
|
+
INSERT INTO ${t(i)} (${t("id")}, ${t("data")}, ${t("version")}, ${t("is_deleted")})
|
|
49
|
+
VALUES (${r}, ${a}, ${o}, ${c})
|
|
50
|
+
ON CONFLICT (${t("id")}) DO UPDATE SET
|
|
51
|
+
${t("data")} = ${a},
|
|
52
|
+
${t("version")} = ${o},
|
|
53
|
+
${t("is_deleted")} = ${c}
|
|
54
|
+
WHERE ${t(i)}.${t("version")} < ${o}
|
|
55
|
+
`
|
|
56
|
+
});
|
|
32
57
|
});
|
|
33
58
|
return {
|
|
34
59
|
tables: n,
|
|
@@ -108,5 +133,4 @@ var o = "postgres-analytics", s = "_voltro_events", c = (e, t) => e.onDialectOrE
|
|
|
108
133
|
...h === void 0 ? {} : { mirror: h }
|
|
109
134
|
};
|
|
110
135
|
};
|
|
111
|
-
//#endregion
|
|
112
136
|
export { m as buildPostgresAnalyticsSink };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/plugin-analytics-postgres",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "First-party AnalyticsSink
|
|
3
|
+
"version": "0.88.0",
|
|
4
|
+
"description": "First-party SQL AnalyticsSink for events and version-guarded CDC mirrors. Throughput depends on the schema, workload and database; no capacity ceiling is verified.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
7
7
|
"typescript",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"node": ">=24.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@voltro/database": "0.
|
|
37
|
-
"@voltro/runtime": "0.
|
|
36
|
+
"@voltro/database": "0.88.0",
|
|
37
|
+
"@voltro/runtime": "0.88.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"effect": "4.0
|
|
40
|
+
"effect": "4.1.0"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|