@antelopejs/postgres 0.0.0-stage → 0.2.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/LICENSE +190 -0
- package/README.md +151 -2
- package/dist/config.d.ts +33 -0
- package/dist/config.js +90 -0
- package/dist/config.js.map +1 -0
- package/dist/connection.d.ts +14 -0
- package/dist/connection.js +128 -0
- package/dist/connection.js.map +1 -0
- package/dist/implementations/database/changes.d.ts +19 -0
- package/dist/implementations/database/changes.js +100 -0
- package/dist/implementations/database/changes.js.map +1 -0
- package/dist/implementations/database/coerce.d.ts +15 -0
- package/dist/implementations/database/coerce.js +195 -0
- package/dist/implementations/database/coerce.js.map +1 -0
- package/dist/implementations/database/context.d.ts +32 -0
- package/dist/implementations/database/context.js +50 -0
- package/dist/implementations/database/context.js.map +1 -0
- package/dist/implementations/database/cursors.d.ts +16 -0
- package/dist/implementations/database/cursors.js +269 -0
- package/dist/implementations/database/cursors.js.map +1 -0
- package/dist/implementations/database/ddl.d.ts +62 -0
- package/dist/implementations/database/ddl.js +355 -0
- package/dist/implementations/database/ddl.js.map +1 -0
- package/dist/implementations/database/expression.d.ts +7 -0
- package/dist/implementations/database/expression.js +30 -0
- package/dist/implementations/database/expression.js.map +1 -0
- package/dist/implementations/database/external-catalog.d.ts +22 -0
- package/dist/implementations/database/external-catalog.js +82 -0
- package/dist/implementations/database/external-catalog.js.map +1 -0
- package/dist/implementations/database/external-errors.d.ts +20 -0
- package/dist/implementations/database/external-errors.js +67 -0
- package/dist/implementations/database/external-errors.js.map +1 -0
- package/dist/implementations/database/external-payload.d.ts +32 -0
- package/dist/implementations/database/external-payload.js +206 -0
- package/dist/implementations/database/external-payload.js.map +1 -0
- package/dist/implementations/database/external-refusals.d.ts +5 -0
- package/dist/implementations/database/external-refusals.js +23 -0
- package/dist/implementations/database/external-refusals.js.map +1 -0
- package/dist/implementations/database/external-schema.d.ts +3 -0
- package/dist/implementations/database/external-schema.js +121 -0
- package/dist/implementations/database/external-schema.js.map +1 -0
- package/dist/implementations/database/external-types.d.ts +29 -0
- package/dist/implementations/database/external-types.js +373 -0
- package/dist/implementations/database/external-types.js.map +1 -0
- package/dist/implementations/database/external-writes.d.ts +3 -0
- package/dist/implementations/database/external-writes.js +298 -0
- package/dist/implementations/database/external-writes.js.map +1 -0
- package/dist/implementations/database/feed-pipeline.d.ts +12 -0
- package/dist/implementations/database/feed-pipeline.js +92 -0
- package/dist/implementations/database/feed-pipeline.js.map +1 -0
- package/dist/implementations/database/feeds.d.ts +34 -0
- package/dist/implementations/database/feeds.js +338 -0
- package/dist/implementations/database/feeds.js.map +1 -0
- package/dist/implementations/database/fields.d.ts +37 -0
- package/dist/implementations/database/fields.js +114 -0
- package/dist/implementations/database/fields.js.map +1 -0
- package/dist/implementations/database/identifier.d.ts +8 -0
- package/dist/implementations/database/identifier.js +62 -0
- package/dist/implementations/database/identifier.js.map +1 -0
- package/dist/implementations/database/instances.d.ts +4 -0
- package/dist/implementations/database/instances.js +57 -0
- package/dist/implementations/database/instances.js.map +1 -0
- package/dist/implementations/database/introspect.d.ts +3 -0
- package/dist/implementations/database/introspect.js +36 -0
- package/dist/implementations/database/introspect.js.map +1 -0
- package/dist/implementations/database/jsonb.d.ts +29 -0
- package/dist/implementations/database/jsonb.js +54 -0
- package/dist/implementations/database/jsonb.js.map +1 -0
- package/dist/implementations/database/listener.d.ts +3 -0
- package/dist/implementations/database/listener.js +93 -0
- package/dist/implementations/database/listener.js.map +1 -0
- package/dist/implementations/database/migrate.d.ts +6 -0
- package/dist/implementations/database/migrate.js +282 -0
- package/dist/implementations/database/migrate.js.map +1 -0
- package/dist/implementations/database/payload.d.ts +24 -0
- package/dist/implementations/database/payload.js +113 -0
- package/dist/implementations/database/payload.js.map +1 -0
- package/dist/implementations/database/pipeline.d.ts +10 -0
- package/dist/implementations/database/pipeline.js +56 -0
- package/dist/implementations/database/pipeline.js.map +1 -0
- package/dist/implementations/database/query.d.ts +11 -0
- package/dist/implementations/database/query.js +189 -0
- package/dist/implementations/database/query.js.map +1 -0
- package/dist/implementations/database/readings.d.ts +17 -0
- package/dist/implementations/database/readings.js +133 -0
- package/dist/implementations/database/readings.js.map +1 -0
- package/dist/implementations/database/reaper.d.ts +6 -0
- package/dist/implementations/database/reaper.js +121 -0
- package/dist/implementations/database/reaper.js.map +1 -0
- package/dist/implementations/database/relation.d.ts +65 -0
- package/dist/implementations/database/relation.js +237 -0
- package/dist/implementations/database/relation.js.map +1 -0
- package/dist/implementations/database/result.d.ts +4 -0
- package/dist/implementations/database/result.js +70 -0
- package/dist/implementations/database/result.js.map +1 -0
- package/dist/implementations/database/row-source.d.ts +64 -0
- package/dist/implementations/database/row-source.js +279 -0
- package/dist/implementations/database/row-source.js.map +1 -0
- package/dist/implementations/database/schema.d.ts +15 -0
- package/dist/implementations/database/schema.js +143 -0
- package/dist/implementations/database/schema.js.map +1 -0
- package/dist/implementations/database/selection.d.ts +18 -0
- package/dist/implementations/database/selection.js +129 -0
- package/dist/implementations/database/selection.js.map +1 -0
- package/dist/implementations/database/sql.d.ts +24 -0
- package/dist/implementations/database/sql.js +48 -0
- package/dist/implementations/database/sql.js.map +1 -0
- package/dist/implementations/database/stage.d.ts +22 -0
- package/dist/implementations/database/stage.js +76 -0
- package/dist/implementations/database/stage.js.map +1 -0
- package/dist/implementations/database/stages-aggregate.d.ts +11 -0
- package/dist/implementations/database/stages-aggregate.js +112 -0
- package/dist/implementations/database/stages-aggregate.js.map +1 -0
- package/dist/implementations/database/stages-array.d.ts +2 -0
- package/dist/implementations/database/stages-array.js +162 -0
- package/dist/implementations/database/stages-array.js.map +1 -0
- package/dist/implementations/database/stages-core.d.ts +2 -0
- package/dist/implementations/database/stages-core.js +107 -0
- package/dist/implementations/database/stages-core.js.map +1 -0
- package/dist/implementations/database/stages-date.d.ts +2 -0
- package/dist/implementations/database/stages-date.js +65 -0
- package/dist/implementations/database/stages-date.js.map +1 -0
- package/dist/implementations/database/stages-group.d.ts +5 -0
- package/dist/implementations/database/stages-group.js +151 -0
- package/dist/implementations/database/stages-group.js.map +1 -0
- package/dist/implementations/database/stages-join.d.ts +2 -0
- package/dist/implementations/database/stages-join.js +162 -0
- package/dist/implementations/database/stages-join.js.map +1 -0
- package/dist/implementations/database/stages-numeric.d.ts +2 -0
- package/dist/implementations/database/stages-numeric.js +152 -0
- package/dist/implementations/database/stages-numeric.js.map +1 -0
- package/dist/implementations/database/stages-object.d.ts +2 -0
- package/dist/implementations/database/stages-object.js +81 -0
- package/dist/implementations/database/stages-object.js.map +1 -0
- package/dist/implementations/database/stages-projection.d.ts +2 -0
- package/dist/implementations/database/stages-projection.js +75 -0
- package/dist/implementations/database/stages-projection.js.map +1 -0
- package/dist/implementations/database/stages-rows.d.ts +2 -0
- package/dist/implementations/database/stages-rows.js +101 -0
- package/dist/implementations/database/stages-rows.js.map +1 -0
- package/dist/implementations/database/stages-selection.d.ts +2 -0
- package/dist/implementations/database/stages-selection.js +146 -0
- package/dist/implementations/database/stages-selection.js.map +1 -0
- package/dist/implementations/database/stages-string.d.ts +2 -0
- package/dist/implementations/database/stages-string.js +101 -0
- package/dist/implementations/database/stages-string.js.map +1 -0
- package/dist/implementations/database/subquery.d.ts +4 -0
- package/dist/implementations/database/subquery.js +49 -0
- package/dist/implementations/database/subquery.js.map +1 -0
- package/dist/implementations/database/types.d.ts +37 -0
- package/dist/implementations/database/types.js +57 -0
- package/dist/implementations/database/types.js.map +1 -0
- package/dist/implementations/database/utils.d.ts +16 -0
- package/dist/implementations/database/utils.js +38 -0
- package/dist/implementations/database/utils.js.map +1 -0
- package/dist/implementations/database/value.d.ts +10 -0
- package/dist/implementations/database/value.js +153 -0
- package/dist/implementations/database/value.js.map +1 -0
- package/dist/implementations/database/writes-atomic.d.ts +6 -0
- package/dist/implementations/database/writes-atomic.js +93 -0
- package/dist/implementations/database/writes-atomic.js.map +1 -0
- package/dist/implementations/database/writes-identity.d.ts +4 -0
- package/dist/implementations/database/writes-identity.js +181 -0
- package/dist/implementations/database/writes-identity.js.map +1 -0
- package/dist/implementations/database/writes-insert.d.ts +2 -0
- package/dist/implementations/database/writes-insert.js +136 -0
- package/dist/implementations/database/writes-insert.js.map +1 -0
- package/dist/implementations/database/writes-shared.d.ts +36 -0
- package/dist/implementations/database/writes-shared.js +64 -0
- package/dist/implementations/database/writes-shared.js.map +1 -0
- package/dist/implementations/database/writes.d.ts +16 -0
- package/dist/implementations/database/writes.js +52 -0
- package/dist/implementations/database/writes.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +6 -0
- package/dist/logger.js.map +1 -0
- package/dist/test/antelope.test.d.ts +2 -0
- package/dist/test/antelope.test.js +88 -0
- package/dist/test/antelope.test.js.map +1 -0
- package/dist/test/atomic.test.d.ts +1 -0
- package/dist/test/atomic.test.js +132 -0
- package/dist/test/atomic.test.js.map +1 -0
- package/dist/test/contention.test.d.ts +1 -0
- package/dist/test/contention.test.js +183 -0
- package/dist/test/contention.test.js.map +1 -0
- package/dist/test/indexes.test.d.ts +1 -0
- package/dist/test/indexes.test.js +311 -0
- package/dist/test/indexes.test.js.map +1 -0
- package/dist/test/unit/changes.spec.d.ts +1 -0
- package/dist/test/unit/changes.spec.js +103 -0
- package/dist/test/unit/changes.spec.js.map +1 -0
- package/dist/test/unit/coerce.spec.d.ts +1 -0
- package/dist/test/unit/coerce.spec.js +162 -0
- package/dist/test/unit/coerce.spec.js.map +1 -0
- package/dist/test/unit/config.spec.d.ts +1 -0
- package/dist/test/unit/config.spec.js +123 -0
- package/dist/test/unit/config.spec.js.map +1 -0
- package/dist/test/unit/connection.spec.d.ts +1 -0
- package/dist/test/unit/connection.spec.js +171 -0
- package/dist/test/unit/connection.spec.js.map +1 -0
- package/dist/test/unit/cursors.spec.d.ts +1 -0
- package/dist/test/unit/cursors.spec.js +823 -0
- package/dist/test/unit/cursors.spec.js.map +1 -0
- package/dist/test/unit/ddl.spec.d.ts +1 -0
- package/dist/test/unit/ddl.spec.js +571 -0
- package/dist/test/unit/ddl.spec.js.map +1 -0
- package/dist/test/unit/expression-array.spec.d.ts +1 -0
- package/dist/test/unit/expression-array.spec.js +488 -0
- package/dist/test/unit/expression-array.spec.js.map +1 -0
- package/dist/test/unit/expression-date.spec.d.ts +1 -0
- package/dist/test/unit/expression-date.spec.js +329 -0
- package/dist/test/unit/expression-date.spec.js.map +1 -0
- package/dist/test/unit/expression-numeric.spec.d.ts +1 -0
- package/dist/test/unit/expression-numeric.spec.js +362 -0
- package/dist/test/unit/expression-numeric.spec.js.map +1 -0
- package/dist/test/unit/expression-object.spec.d.ts +1 -0
- package/dist/test/unit/expression-object.spec.js +230 -0
- package/dist/test/unit/expression-object.spec.js.map +1 -0
- package/dist/test/unit/expression-stages.spec.d.ts +1 -0
- package/dist/test/unit/expression-stages.spec.js +82 -0
- package/dist/test/unit/expression-stages.spec.js.map +1 -0
- package/dist/test/unit/expression-string.spec.d.ts +1 -0
- package/dist/test/unit/expression-string.spec.js +249 -0
- package/dist/test/unit/expression-string.spec.js.map +1 -0
- package/dist/test/unit/expression.spec.d.ts +1 -0
- package/dist/test/unit/expression.spec.js +449 -0
- package/dist/test/unit/expression.spec.js.map +1 -0
- package/dist/test/unit/external-comparisons.spec.d.ts +1 -0
- package/dist/test/unit/external-comparisons.spec.js +145 -0
- package/dist/test/unit/external-comparisons.spec.js.map +1 -0
- package/dist/test/unit/external-types.spec.d.ts +1 -0
- package/dist/test/unit/external-types.spec.js +191 -0
- package/dist/test/unit/external-types.spec.js.map +1 -0
- package/dist/test/unit/feeds.spec.d.ts +1 -0
- package/dist/test/unit/feeds.spec.js +374 -0
- package/dist/test/unit/feeds.spec.js.map +1 -0
- package/dist/test/unit/fields.spec.d.ts +1 -0
- package/dist/test/unit/fields.spec.js +79 -0
- package/dist/test/unit/fields.spec.js.map +1 -0
- package/dist/test/unit/identifier.spec.d.ts +1 -0
- package/dist/test/unit/identifier.spec.js +50 -0
- package/dist/test/unit/identifier.spec.js.map +1 -0
- package/dist/test/unit/payload.spec.d.ts +1 -0
- package/dist/test/unit/payload.spec.js +278 -0
- package/dist/test/unit/payload.spec.js.map +1 -0
- package/dist/test/unit/pipeline-aggregate.spec.d.ts +1 -0
- package/dist/test/unit/pipeline-aggregate.spec.js +199 -0
- package/dist/test/unit/pipeline-aggregate.spec.js.map +1 -0
- package/dist/test/unit/pipeline-fixture.d.ts +79 -0
- package/dist/test/unit/pipeline-fixture.js +277 -0
- package/dist/test/unit/pipeline-fixture.js.map +1 -0
- package/dist/test/unit/pipeline-group.spec.d.ts +1 -0
- package/dist/test/unit/pipeline-group.spec.js +390 -0
- package/dist/test/unit/pipeline-group.spec.js.map +1 -0
- package/dist/test/unit/pipeline-join.spec.d.ts +1 -0
- package/dist/test/unit/pipeline-join.spec.js +165 -0
- package/dist/test/unit/pipeline-join.spec.js.map +1 -0
- package/dist/test/unit/pipeline-lookup.spec.d.ts +1 -0
- package/dist/test/unit/pipeline-lookup.spec.js +268 -0
- package/dist/test/unit/pipeline-lookup.spec.js.map +1 -0
- package/dist/test/unit/pipeline-projection.spec.d.ts +1 -0
- package/dist/test/unit/pipeline-projection.spec.js +183 -0
- package/dist/test/unit/pipeline-projection.spec.js.map +1 -0
- package/dist/test/unit/pipeline-rows.spec.d.ts +1 -0
- package/dist/test/unit/pipeline-rows.spec.js +321 -0
- package/dist/test/unit/pipeline-rows.spec.js.map +1 -0
- package/dist/test/unit/pipeline-selection.spec.d.ts +1 -0
- package/dist/test/unit/pipeline-selection.spec.js +257 -0
- package/dist/test/unit/pipeline-selection.spec.js.map +1 -0
- package/dist/test/unit/pipeline-stages.spec.d.ts +1 -0
- package/dist/test/unit/pipeline-stages.spec.js +226 -0
- package/dist/test/unit/pipeline-stages.spec.js.map +1 -0
- package/dist/test/unit/pipeline.spec.d.ts +1 -0
- package/dist/test/unit/pipeline.spec.js +72 -0
- package/dist/test/unit/pipeline.spec.js.map +1 -0
- package/dist/test/unit/query.spec.d.ts +1 -0
- package/dist/test/unit/query.spec.js +212 -0
- package/dist/test/unit/query.spec.js.map +1 -0
- package/dist/test/unit/reaper.spec.d.ts +1 -0
- package/dist/test/unit/reaper.spec.js +122 -0
- package/dist/test/unit/reaper.spec.js.map +1 -0
- package/dist/test/unit/relation.spec.d.ts +1 -0
- package/dist/test/unit/relation.spec.js +348 -0
- package/dist/test/unit/relation.spec.js.map +1 -0
- package/dist/test/unit/result.spec.d.ts +1 -0
- package/dist/test/unit/result.spec.js +128 -0
- package/dist/test/unit/result.spec.js.map +1 -0
- package/dist/test/unit/row-source.spec.d.ts +1 -0
- package/dist/test/unit/row-source.spec.js +141 -0
- package/dist/test/unit/row-source.spec.js.map +1 -0
- package/dist/test/unit/schema.spec.d.ts +1 -0
- package/dist/test/unit/schema.spec.js +44 -0
- package/dist/test/unit/schema.spec.js.map +1 -0
- package/dist/test/unit/selection.spec.d.ts +1 -0
- package/dist/test/unit/selection.spec.js +182 -0
- package/dist/test/unit/selection.spec.js.map +1 -0
- package/dist/test/unit/spec-fixture.d.ts +11 -0
- package/dist/test/unit/spec-fixture.js +71 -0
- package/dist/test/unit/spec-fixture.js.map +1 -0
- package/dist/test/unit/sql.spec.d.ts +1 -0
- package/dist/test/unit/sql.spec.js +38 -0
- package/dist/test/unit/sql.spec.js.map +1 -0
- package/dist/test/unit/subquery.spec.d.ts +1 -0
- package/dist/test/unit/subquery.spec.js +154 -0
- package/dist/test/unit/subquery.spec.js.map +1 -0
- package/dist/test/unit/types.spec.d.ts +1 -0
- package/dist/test/unit/types.spec.js +39 -0
- package/dist/test/unit/types.spec.js.map +1 -0
- package/dist/test/unit/utils.spec.d.ts +1 -0
- package/dist/test/unit/utils.spec.js +22 -0
- package/dist/test/unit/utils.spec.js.map +1 -0
- package/dist/test/unit/value.spec.d.ts +1 -0
- package/dist/test/unit/value.spec.js +195 -0
- package/dist/test/unit/value.spec.js.map +1 -0
- package/dist/test/unit/writes-atomic.spec.d.ts +1 -0
- package/dist/test/unit/writes-atomic.spec.js +66 -0
- package/dist/test/unit/writes-atomic.spec.js.map +1 -0
- package/dist/test/unit/writes-insert.spec.d.ts +1 -0
- package/dist/test/unit/writes-insert.spec.js +270 -0
- package/dist/test/unit/writes-insert.spec.js.map +1 -0
- package/dist/test/unit/writes-replace.spec.d.ts +1 -0
- package/dist/test/unit/writes-replace.spec.js +100 -0
- package/dist/test/unit/writes-replace.spec.js.map +1 -0
- package/dist/test/unit/writes-target.spec.d.ts +1 -0
- package/dist/test/unit/writes-target.spec.js +118 -0
- package/dist/test/unit/writes-target.spec.js.map +1 -0
- package/dist/test/unit/writes-update.spec.d.ts +1 -0
- package/dist/test/unit/writes-update.spec.js +297 -0
- package/dist/test/unit/writes-update.spec.js.map +1 -0
- package/dist/test-external/fixture.d.ts +6 -0
- package/dist/test-external/fixture.js +136 -0
- package/dist/test-external/fixture.js.map +1 -0
- package/dist/test-external/native.test.d.ts +1 -0
- package/dist/test-external/native.test.js +132 -0
- package/dist/test-external/native.test.js.map +1 -0
- package/dist/test-external/reads.test.d.ts +1 -0
- package/dist/test-external/reads.test.js +232 -0
- package/dist/test-external/reads.test.js.map +1 -0
- package/dist/test-external/refusals.test.d.ts +1 -0
- package/dist/test-external/refusals.test.js +93 -0
- package/dist/test-external/refusals.test.js.map +1 -0
- package/dist/test-external/registration.test.d.ts +1 -0
- package/dist/test-external/registration.test.js +127 -0
- package/dist/test-external/registration.test.js.map +1 -0
- package/dist/test-external/sales.d.ts +5 -0
- package/dist/test-external/sales.js +126 -0
- package/dist/test-external/sales.js.map +1 -0
- package/dist/test-external/startup.test.d.ts +1 -0
- package/dist/test-external/startup.test.js +15 -0
- package/dist/test-external/startup.test.js.map +1 -0
- package/dist/test-external/writes.test.d.ts +1 -0
- package/dist/test-external/writes.test.js +315 -0
- package/dist/test-external/writes.test.js.map +1 -0
- package/package.json +78 -4
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReapOnce = ReapOnce;
|
|
4
|
+
exports.ReapInterval = ReapInterval;
|
|
5
|
+
exports.StartReaper = StartReaper;
|
|
6
|
+
exports.StopReaper = StopReaper;
|
|
7
|
+
exports.IsReaperRunning = IsReaperRunning;
|
|
8
|
+
const logger_1 = require("../../logger");
|
|
9
|
+
const config_1 = require("../../config");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const connection_1 = require("../../connection");
|
|
12
|
+
const changes_1 = require("./changes");
|
|
13
|
+
const REAP_LOCK_KEY = "7623941058273641";
|
|
14
|
+
const PASSES_PER_WINDOW = 2;
|
|
15
|
+
const SHORTEST_INTERVAL_MS = 1;
|
|
16
|
+
const RETENTION_PARAM = "$1";
|
|
17
|
+
const LOCK_PARAM = "$1";
|
|
18
|
+
const REGCLASS_PARAM = "$1";
|
|
19
|
+
const LOG_REGCLASS = `${utils_1.REGISTRY_SCHEMA}.${utils_1.CHANGE_LOG_TABLE}`;
|
|
20
|
+
const PRESENT = `SELECT to_regclass(${REGCLASS_PARAM}) IS NOT NULL AS "present"`;
|
|
21
|
+
const TAKE_LOCK = `SELECT pg_try_advisory_lock(${LOCK_PARAM}) AS "took"`;
|
|
22
|
+
const RELEASE_LOCK = `SELECT pg_advisory_unlock(${LOCK_PARAM})`;
|
|
23
|
+
const REAP = `WITH "reaped" AS (
|
|
24
|
+
DELETE FROM ${changes_1.LOG}
|
|
25
|
+
WHERE ${changes_1.CREATED_COLUMN} < now() - (${RETENTION_PARAM}::bigint * interval '1 millisecond')
|
|
26
|
+
RETURNING ${changes_1.SEQ_COLUMN}
|
|
27
|
+
)
|
|
28
|
+
INSERT INTO ${changes_1.REAPED} AS "r" (${changes_1.SINGLETON_COLUMN}, ${changes_1.HIGH_WATER_COLUMN}, ${changes_1.EPOCH_COLUMN})
|
|
29
|
+
SELECT true, COALESCE(max(${changes_1.SEQ_COLUMN}), 0), pg_postmaster_start_time() FROM "reaped"
|
|
30
|
+
ON CONFLICT (${changes_1.SINGLETON_COLUMN}) DO UPDATE SET
|
|
31
|
+
${changes_1.HIGH_WATER_COLUMN} = CASE
|
|
32
|
+
WHEN "r".${changes_1.EPOCH_COLUMN} = EXCLUDED.${changes_1.EPOCH_COLUMN}
|
|
33
|
+
THEN GREATEST("r".${changes_1.HIGH_WATER_COLUMN}, EXCLUDED.${changes_1.HIGH_WATER_COLUMN})
|
|
34
|
+
ELSE EXCLUDED.${changes_1.HIGH_WATER_COLUMN} END,
|
|
35
|
+
${changes_1.EPOCH_COLUMN} = EXCLUDED.${changes_1.EPOCH_COLUMN}`;
|
|
36
|
+
const REAP_FAILED = "the PostgreSQL change log could not be reaped and will grow until it can be; every table that was ever watched logs a row per write, and the log is UNLOGGED so only a restart empties it";
|
|
37
|
+
const REAP_RECOVERED = "the PostgreSQL change log is being reaped again";
|
|
38
|
+
let timer;
|
|
39
|
+
let isReaping = false;
|
|
40
|
+
let isFailing = false;
|
|
41
|
+
async function ReapOnce(client, retentionMs) {
|
|
42
|
+
const present = await client.query(PRESENT, [LOG_REGCLASS]);
|
|
43
|
+
if (!present.rows[0]?.present) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const lock = await client.query(TAKE_LOCK, [REAP_LOCK_KEY]);
|
|
47
|
+
if (!lock.rows[0]?.took) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
await client.query(REAP, [retentionMs]);
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
await client.query(RELEASE_LOCK, [REAP_LOCK_KEY]);
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
async function Borrowed(retentionMs) {
|
|
59
|
+
const client = await (0, connection_1.AcquireClient)();
|
|
60
|
+
try {
|
|
61
|
+
return await ReapOnce(client, retentionMs);
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
client.release();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function ReportFailure(err) {
|
|
68
|
+
if (isFailing) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
isFailing = true;
|
|
72
|
+
logger_1.Logger.Error(REAP_FAILED, err);
|
|
73
|
+
}
|
|
74
|
+
function ReportReaped() {
|
|
75
|
+
if (!isFailing) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
isFailing = false;
|
|
79
|
+
logger_1.Logger.Info(REAP_RECOVERED);
|
|
80
|
+
}
|
|
81
|
+
async function Tick() {
|
|
82
|
+
if (isReaping) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
isReaping = true;
|
|
86
|
+
try {
|
|
87
|
+
if (await Borrowed((0, config_1.GetOptions)().changeRetentionMs)) {
|
|
88
|
+
ReportReaped();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
ReportFailure(err);
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
isReaping = false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function ReapInterval(retentionMs) {
|
|
99
|
+
return Math.max(SHORTEST_INTERVAL_MS, Math.floor(retentionMs / PASSES_PER_WINDOW));
|
|
100
|
+
}
|
|
101
|
+
function StartReaper() {
|
|
102
|
+
StopReaper();
|
|
103
|
+
isFailing = false;
|
|
104
|
+
isReaping = false;
|
|
105
|
+
const started = setInterval(() => {
|
|
106
|
+
void Tick();
|
|
107
|
+
}, ReapInterval((0, config_1.GetOptions)().changeRetentionMs));
|
|
108
|
+
started.unref();
|
|
109
|
+
timer = started;
|
|
110
|
+
}
|
|
111
|
+
function StopReaper() {
|
|
112
|
+
if (timer) {
|
|
113
|
+
clearInterval(timer);
|
|
114
|
+
timer = undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function IsReaperRunning() {
|
|
118
|
+
return timer !== undefined;
|
|
119
|
+
}
|
|
120
|
+
(0, connection_1.RegisterBeforeDisconnect)(StopReaper);
|
|
121
|
+
//# sourceMappingURL=reaper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reaper.js","sourceRoot":"","sources":["../../../src/implementations/database/reaper.ts"],"names":[],"mappings":";;AA0FA,4BAkBC;AAoDD,oCAKC;AAoBD,kCASC;AAGD,gCAKC;AAED,0CAEC;AA5MD,yCAAsC;AACtC,yCAA0C;AAC1C,mCAA4D;AAC5D,iDAA2E;AAC3E,uCAQmB;AAMnB,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAGzC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAG5B,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAE/B,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B,MAAM,YAAY,GAAG,GAAG,uBAAe,IAAI,wBAAgB,EAAE,CAAC;AAE9D,MAAM,OAAO,GAAG,sBAAsB,cAAc,4BAA4B,CAAC;AACjF,MAAM,SAAS,GAAG,+BAA+B,UAAU,aAAa,CAAC;AACzE,MAAM,YAAY,GAAG,6BAA6B,UAAU,GAAG,CAAC;AAMhE,MAAM,IAAI,GAAG;gBACG,aAAG;WACR,wBAAc,eAAe,eAAe;cACzC,oBAAU;;cAEV,gBAAM,YAAY,0BAAgB,KAAK,2BAAiB,KAAK,sBAAY;4BAC3D,oBAAU;eACvB,0BAAgB;IAC3B,2BAAiB;eACN,sBAAY,eAAe,sBAAY;wBAC9B,2BAAiB,cAAc,2BAAiB;oBACpD,2BAAiB;IACjC,sBAAY,eAAe,sBAAY,EAAE,CAAC;AAE9C,MAAM,WAAW,GACf,2LAA2L,CAAC;AAE9L,MAAM,cAAc,GAAG,iDAAiD,CAAC;AAUzE,IAAI,KAAiC,CAAC;AACtC,IAAI,SAAS,GAAG,KAAK,CAAC;AACtB,IAAI,SAAS,GAAG,KAAK,CAAC;AAmBf,KAAK,UAAU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@@
|
|
|
1
|
+
import type { SqlType } from "./types";
|
|
2
|
+
import type { DecodingContext } from "./context";
|
|
3
|
+
import { type Compiled } from "./sql";
|
|
4
|
+
import { type TableShape } from "./fields";
|
|
5
|
+
import { type DocumentMember, type ExternalReads, type RowSource } from "./row-source";
|
|
6
|
+
export declare const OUTPUT_COLUMN = "value";
|
|
7
|
+
type IndexResolver = (name: string) => string[];
|
|
8
|
+
type ScanNotice = (name: string) => void;
|
|
9
|
+
export interface TableOrigin {
|
|
10
|
+
schemaId: string;
|
|
11
|
+
tableId: string;
|
|
12
|
+
shape: TableShape;
|
|
13
|
+
index: IndexResolver;
|
|
14
|
+
crossInstanceScan?: ScanNotice;
|
|
15
|
+
}
|
|
16
|
+
export interface OrderTerm {
|
|
17
|
+
sql: string;
|
|
18
|
+
descending: boolean;
|
|
19
|
+
}
|
|
20
|
+
type AbsentValue = null | undefined;
|
|
21
|
+
export type JoinKind = "JOIN" | "LEFT JOIN" | "LEFT JOIN LATERAL";
|
|
22
|
+
export interface JoinClause {
|
|
23
|
+
kind: JoinKind;
|
|
24
|
+
from: string;
|
|
25
|
+
alias: string;
|
|
26
|
+
on: string;
|
|
27
|
+
}
|
|
28
|
+
export interface Relation {
|
|
29
|
+
from: string;
|
|
30
|
+
alias: string;
|
|
31
|
+
joins: JoinClause[];
|
|
32
|
+
where: string[];
|
|
33
|
+
groupBy: Compiled[];
|
|
34
|
+
orderBy: OrderTerm[];
|
|
35
|
+
limit?: string;
|
|
36
|
+
offset?: string;
|
|
37
|
+
distinct: boolean;
|
|
38
|
+
single: boolean;
|
|
39
|
+
absent: AbsentValue;
|
|
40
|
+
aggregated: boolean;
|
|
41
|
+
crossInstance: boolean;
|
|
42
|
+
source: RowSource;
|
|
43
|
+
projection?: Compiled;
|
|
44
|
+
origin?: TableOrigin;
|
|
45
|
+
projectedFrom?: RowSource;
|
|
46
|
+
}
|
|
47
|
+
export declare function RequireOrigin(relation: Relation): TableOrigin;
|
|
48
|
+
export declare function IndexColumns(relation: Relation, name: string): DocumentMember[];
|
|
49
|
+
export declare function ScanColumns(relation: Relation, name: string): DocumentMember[];
|
|
50
|
+
export declare function AbsorbOrder(relation: Relation): string | undefined;
|
|
51
|
+
export declare function RowBound(sql: string): string;
|
|
52
|
+
export declare const SINGLE_ROW: string;
|
|
53
|
+
export declare function Render(relation: Relation): string;
|
|
54
|
+
export declare function TableRelation(from: string, alias: string, origin: TableOrigin, reads?: ExternalReads): Relation;
|
|
55
|
+
export declare function LoggedRelation(from: string, alias: string, row: string, origin: TableOrigin): Relation;
|
|
56
|
+
export declare function ValueRelation(from: string, alias: string, type: SqlType): Relation;
|
|
57
|
+
export declare function Nested(relation: Relation, context: DecodingContext): Relation;
|
|
58
|
+
export type RelationFlag = "projection" | "limit" | "offset" | "distinct" | "ordered" | "aggregated";
|
|
59
|
+
export declare const WHERE_BLOCKERS: readonly RelationFlag[];
|
|
60
|
+
export declare function Prepare(relation: Relation, blockedBy: readonly RelationFlag[], context: DecodingContext): Relation;
|
|
61
|
+
export declare function SetProjection(relation: Relation, value: Compiled): Relation;
|
|
62
|
+
export declare function SetPlainProjection(relation: Relation, value: Compiled, source: RowSource): Relation;
|
|
63
|
+
export declare function HasFlag(relation: Relation, flags: readonly RelationFlag[]): boolean;
|
|
64
|
+
export declare function CurrentValue(relation: Relation): Compiled;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WHERE_BLOCKERS = exports.SINGLE_ROW = exports.OUTPUT_COLUMN = void 0;
|
|
7
|
+
exports.RequireOrigin = RequireOrigin;
|
|
8
|
+
exports.IndexColumns = IndexColumns;
|
|
9
|
+
exports.ScanColumns = ScanColumns;
|
|
10
|
+
exports.AbsorbOrder = AbsorbOrder;
|
|
11
|
+
exports.RowBound = RowBound;
|
|
12
|
+
exports.Render = Render;
|
|
13
|
+
exports.TableRelation = TableRelation;
|
|
14
|
+
exports.LoggedRelation = LoggedRelation;
|
|
15
|
+
exports.ValueRelation = ValueRelation;
|
|
16
|
+
exports.Nested = Nested;
|
|
17
|
+
exports.Prepare = Prepare;
|
|
18
|
+
exports.SetProjection = SetProjection;
|
|
19
|
+
exports.SetPlainProjection = SetPlainProjection;
|
|
20
|
+
exports.HasFlag = HasFlag;
|
|
21
|
+
exports.CurrentValue = CurrentValue;
|
|
22
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
23
|
+
const utils_1 = require("./utils");
|
|
24
|
+
const sql_1 = require("./sql");
|
|
25
|
+
const fields_1 = require("./fields");
|
|
26
|
+
const row_source_1 = require("./row-source");
|
|
27
|
+
exports.OUTPUT_COLUMN = "value";
|
|
28
|
+
function NewRelation(seed) {
|
|
29
|
+
return {
|
|
30
|
+
...seed,
|
|
31
|
+
joins: [],
|
|
32
|
+
where: [],
|
|
33
|
+
groupBy: [],
|
|
34
|
+
orderBy: [],
|
|
35
|
+
distinct: false,
|
|
36
|
+
single: false,
|
|
37
|
+
absent: null,
|
|
38
|
+
aggregated: false,
|
|
39
|
+
crossInstance: false,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function RequireOrigin(relation) {
|
|
43
|
+
const origin = relation.origin;
|
|
44
|
+
(0, node_assert_1.default)(origin, "A row-mode relation must carry the origin of its table");
|
|
45
|
+
return origin;
|
|
46
|
+
}
|
|
47
|
+
function IndexColumns(relation, name) {
|
|
48
|
+
const fields = relation.origin ? relation.origin.index(name) : [name];
|
|
49
|
+
return fields.map((field) => ({
|
|
50
|
+
name: field,
|
|
51
|
+
...relation.source.field(field),
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
function ScanColumns(relation, name) {
|
|
55
|
+
if (relation.crossInstance) {
|
|
56
|
+
relation.origin?.crossInstanceScan?.(name);
|
|
57
|
+
}
|
|
58
|
+
return IndexColumns(relation, name);
|
|
59
|
+
}
|
|
60
|
+
function ExternalColumns(relation, shape) {
|
|
61
|
+
return (0, row_source_1.ExternalNames)(shape).map((name) => `${relation.source.field(name).sql} AS ${(0, sql_1.QuoteIdentifier)(name)}`);
|
|
62
|
+
}
|
|
63
|
+
function RowColumns(relation) {
|
|
64
|
+
const origin = RequireOrigin(relation);
|
|
65
|
+
if (origin.shape.external) {
|
|
66
|
+
return ExternalColumns(relation, origin.shape);
|
|
67
|
+
}
|
|
68
|
+
const declared = (0, fields_1.DeclaredColumns)(origin.shape);
|
|
69
|
+
const columns = (0, fields_1.PhysicalOrder)(utils_1.ID_COLUMN, utils_1.INSTANCE_COLUMN, declared, utils_1.EXTRA_COLUMN);
|
|
70
|
+
return columns.map((column) => (0, sql_1.QualifiedColumn)(relation.alias, column));
|
|
71
|
+
}
|
|
72
|
+
function SelectList(relation) {
|
|
73
|
+
const projection = relation.projection;
|
|
74
|
+
if (!projection) {
|
|
75
|
+
return RowColumns(relation).join(", ");
|
|
76
|
+
}
|
|
77
|
+
return `${projection.sql} AS ${(0, sql_1.QuoteIdentifier)(exports.OUTPUT_COLUMN)}`;
|
|
78
|
+
}
|
|
79
|
+
function SelectClause(relation) {
|
|
80
|
+
const modifier = relation.distinct ? "DISTINCT " : "";
|
|
81
|
+
return `SELECT ${modifier}${SelectList(relation)}`;
|
|
82
|
+
}
|
|
83
|
+
function FromItem(from, alias) {
|
|
84
|
+
return `${from} AS ${(0, sql_1.QuoteIdentifier)(alias)}`;
|
|
85
|
+
}
|
|
86
|
+
function FromClause(relation) {
|
|
87
|
+
return `FROM ${FromItem(relation.from, relation.alias)}`;
|
|
88
|
+
}
|
|
89
|
+
function RenderJoin(join) {
|
|
90
|
+
return `${join.kind} ${FromItem(join.from, join.alias)} ON ${join.on}`;
|
|
91
|
+
}
|
|
92
|
+
function JoinClauses(relation) {
|
|
93
|
+
if (relation.joins.length === 0) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
return relation.joins.map(RenderJoin).join(" ");
|
|
97
|
+
}
|
|
98
|
+
function WhereClause(relation) {
|
|
99
|
+
if (relation.where.length === 0) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
return `WHERE ${relation.where.join(" AND ")}`;
|
|
103
|
+
}
|
|
104
|
+
function GroupByClause(relation) {
|
|
105
|
+
if (relation.groupBy.length === 0) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
return `GROUP BY ${relation.groupBy.map((term) => term.sql).join(", ")}`;
|
|
109
|
+
}
|
|
110
|
+
function OrderTerms(relation) {
|
|
111
|
+
if (relation.orderBy.length === 0) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
const terms = relation.orderBy.map((term) => `${term.sql} ${term.descending ? "DESC" : "ASC"}`);
|
|
115
|
+
return terms.join(", ");
|
|
116
|
+
}
|
|
117
|
+
function OrderByClause(relation) {
|
|
118
|
+
const terms = OrderTerms(relation);
|
|
119
|
+
return terms === undefined ? undefined : `ORDER BY ${terms}`;
|
|
120
|
+
}
|
|
121
|
+
const BOUND_PARAMETER = /\$\d/;
|
|
122
|
+
function AbsorbOrder(relation) {
|
|
123
|
+
const terms = OrderTerms(relation);
|
|
124
|
+
(0, node_assert_1.default)(terms === undefined || !BOUND_PARAMETER.test(terms), "An order term must carry no bound parameter, since absorbing an aggregate discards it");
|
|
125
|
+
relation.orderBy = [];
|
|
126
|
+
return terms;
|
|
127
|
+
}
|
|
128
|
+
const ONE_ROW = "1";
|
|
129
|
+
function RowBound(sql) {
|
|
130
|
+
return `((${sql})::bigint)`;
|
|
131
|
+
}
|
|
132
|
+
exports.SINGLE_ROW = RowBound(ONE_ROW);
|
|
133
|
+
function LimitClause(relation) {
|
|
134
|
+
return relation.limit === undefined ? undefined : `LIMIT ${relation.limit}`;
|
|
135
|
+
}
|
|
136
|
+
function OffsetClause(relation) {
|
|
137
|
+
return relation.offset === undefined
|
|
138
|
+
? undefined
|
|
139
|
+
: `OFFSET ${relation.offset}`;
|
|
140
|
+
}
|
|
141
|
+
const CLAUSES = [
|
|
142
|
+
SelectClause,
|
|
143
|
+
FromClause,
|
|
144
|
+
JoinClauses,
|
|
145
|
+
WhereClause,
|
|
146
|
+
GroupByClause,
|
|
147
|
+
OrderByClause,
|
|
148
|
+
LimitClause,
|
|
149
|
+
OffsetClause,
|
|
150
|
+
];
|
|
151
|
+
function Render(relation) {
|
|
152
|
+
const clauses = CLAUSES.map((build) => build(relation));
|
|
153
|
+
return clauses.filter((clause) => clause !== undefined).join(" ");
|
|
154
|
+
}
|
|
155
|
+
function TableSource(alias, origin, reads) {
|
|
156
|
+
if (origin.shape.external) {
|
|
157
|
+
return new row_source_1.ExternalRowSource(alias, origin.shape, reads);
|
|
158
|
+
}
|
|
159
|
+
return new row_source_1.ColumnRowSource((0, row_source_1.AliasedColumns)(alias), origin.shape);
|
|
160
|
+
}
|
|
161
|
+
function TableRelation(from, alias, origin, reads = "table") {
|
|
162
|
+
return NewRelation({
|
|
163
|
+
from,
|
|
164
|
+
alias,
|
|
165
|
+
source: TableSource(alias, origin, reads),
|
|
166
|
+
origin,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function LoggedRelation(from, alias, row, origin) {
|
|
170
|
+
return NewRelation({
|
|
171
|
+
from,
|
|
172
|
+
alias,
|
|
173
|
+
source: new row_source_1.ColumnRowSource((0, row_source_1.LoggedColumns)(row), origin.shape),
|
|
174
|
+
origin,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function ValueRelation(from, alias, type) {
|
|
178
|
+
const projection = {
|
|
179
|
+
sql: (0, sql_1.QualifiedColumn)(alias, exports.OUTPUT_COLUMN),
|
|
180
|
+
type,
|
|
181
|
+
};
|
|
182
|
+
return NewRelation({
|
|
183
|
+
from,
|
|
184
|
+
alias,
|
|
185
|
+
source: new row_source_1.JsonRowSource(projection),
|
|
186
|
+
projection,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function Nested(relation, context) {
|
|
190
|
+
const from = `(${Render(relation)})`;
|
|
191
|
+
const alias = context.nextAlias();
|
|
192
|
+
const projection = relation.projection;
|
|
193
|
+
const wrapped = projection
|
|
194
|
+
? ValueRelation(from, alias, projection.type)
|
|
195
|
+
: TableRelation(from, alias, RequireOrigin(relation), "output");
|
|
196
|
+
wrapped.single = relation.single;
|
|
197
|
+
wrapped.absent = relation.absent;
|
|
198
|
+
return wrapped;
|
|
199
|
+
}
|
|
200
|
+
exports.WHERE_BLOCKERS = [
|
|
201
|
+
"projection",
|
|
202
|
+
"limit",
|
|
203
|
+
"offset",
|
|
204
|
+
"distinct",
|
|
205
|
+
"aggregated",
|
|
206
|
+
];
|
|
207
|
+
const FLAG_PREDICATES = {
|
|
208
|
+
projection: (relation) => relation.projection !== undefined,
|
|
209
|
+
limit: (relation) => relation.limit !== undefined,
|
|
210
|
+
offset: (relation) => relation.offset !== undefined,
|
|
211
|
+
distinct: (relation) => relation.distinct,
|
|
212
|
+
ordered: (relation) => relation.orderBy.length > 0,
|
|
213
|
+
aggregated: (relation) => relation.aggregated,
|
|
214
|
+
};
|
|
215
|
+
function Prepare(relation, blockedBy, context) {
|
|
216
|
+
const blocked = blockedBy.some((flag) => FLAG_PREDICATES[flag](relation));
|
|
217
|
+
return blocked ? Nested(relation, context) : relation;
|
|
218
|
+
}
|
|
219
|
+
function SetProjection(relation, value) {
|
|
220
|
+
relation.projection = value;
|
|
221
|
+
relation.source = new row_source_1.JsonRowSource(value);
|
|
222
|
+
relation.origin = undefined;
|
|
223
|
+
relation.projectedFrom = undefined;
|
|
224
|
+
return relation;
|
|
225
|
+
}
|
|
226
|
+
function SetPlainProjection(relation, value, source) {
|
|
227
|
+
const projected = SetProjection(relation, value);
|
|
228
|
+
projected.projectedFrom = source;
|
|
229
|
+
return projected;
|
|
230
|
+
}
|
|
231
|
+
function HasFlag(relation, flags) {
|
|
232
|
+
return flags.some((flag) => FLAG_PREDICATES[flag](relation));
|
|
233
|
+
}
|
|
234
|
+
function CurrentValue(relation) {
|
|
235
|
+
return relation.projection ?? relation.source.toJson();
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=relation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation.js","sourceRoot":"","sources":["../../../src/implementations/database/relation.ts"],"names":[],"mappings":";;;;;;AAwJA,sCAIC;AAcD,oCASC;AAMD,kCAQC;AA0GD,kCAQC;AAYD,4BAEC;AAiCD,wBAGC;AAoBD,sCAYC;AAcD,wCAYC;AAMD,sCAeC;AAsBD,wBAUC;AAkDD,0BAOC;AAQD,sCAMC;AAMD,gDAQC;AAGD,0BAKC;AAGD,oCAEC;AAtjBD,8DAAiC;AAIjC,mCAAmE;AACnE,+BAAwE;AACxE,qCAA2E;AAC3E,6CAUsB;AAGT,QAAA,aAAa,GAAG,OAAO,CAAC;AAoHrC,SAAS,WAAW,CAAC,IAAkB;IACrC,OAAO;QACL,GAAG,IAAI;QACP,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,KAAK;KACrB,CAAC;AACJ,CAAC;AAGD,SAAgB,aAAa,CAAC,QAAkB;IAC9C,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC/B,IAAA,qBAAM,EAAC,MAAM,EAAE,wDAAwD,CAAC,CAAC;IACzE,OAAO,MAAM,CAAC;AAChB,CAAC;AAcD,SAAgB,YAAY,CAC1B,QAAkB,EAClB,IAAY;IAEZ,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IA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AC,CAAC,QAAQ,CAAC;AACxD,CAAC;AAQD,SAAgB,aAAa,CAAC,QAAkB,EAAE,KAAe;IAC/D,QAAQ,CAAC,UAAU,GAAG,KAAK,CAAC;IAC5B,QAAQ,CAAC,MAAM,GAAG,IAAI,0BAAa,CAAC,KAAK,CAAC,CAAC;IAC3C,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,CAAC,aAAa,GAAG,SAAS,CAAC;IACnC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAMD,SAAgB,kBAAkB,CAChC,QAAkB,EAClB,KAAe,EACf,MAAiB;IAEjB,MAAM,SAAS,GAAG,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACjD,SAAS,CAAC,aAAa,GAAG,MAAM,CAAC;IACjC,OAAO,SAAS,CAAC;AACnB,CAAC;AAGD,SAAgB,OAAO,CACrB,QAAkB,EAClB,KAA8B;IAE9B,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC/D,CAAC;AAGD,SAAgB,YAAY,CAAC,QAAkB;IAC7C,OAAO,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { TableShape } from "./fields";
|
|
2
|
+
import type { SqlType } from "./types";
|
|
3
|
+
export declare function ReviveValue(value: unknown, type: SqlType): unknown;
|
|
4
|
+
export declare function DecodeRow(row: Record<string, unknown>, table: TableShape): Record<string, unknown>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReviveValue = ReviveValue;
|
|
4
|
+
exports.DecodeRow = DecodeRow;
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function ReviveTimestamp(value) {
|
|
7
|
+
if (value instanceof Date) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
const date = typeof value === "number" ? new Date(value) : new Date(String(value));
|
|
11
|
+
return Number.isNaN(date.getTime()) ? value : date;
|
|
12
|
+
}
|
|
13
|
+
const REVIVERS = {
|
|
14
|
+
timestamp: (value) => ReviveTimestamp(value),
|
|
15
|
+
array: (value, type) => Array.isArray(value)
|
|
16
|
+
? value.map((item) => ReviveValue(item, type.elem))
|
|
17
|
+
: value,
|
|
18
|
+
json: (value, type) => ReviveShape(value, type.shape),
|
|
19
|
+
};
|
|
20
|
+
function ReviveValue(value, type) {
|
|
21
|
+
if (value === null || value === undefined) {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
const reviver = REVIVERS[type.kind];
|
|
25
|
+
return reviver ? reviver(value, type) : value;
|
|
26
|
+
}
|
|
27
|
+
function ReviveShape(value, shape) {
|
|
28
|
+
if (!shape ||
|
|
29
|
+
typeof value !== "object" ||
|
|
30
|
+
value === null ||
|
|
31
|
+
Array.isArray(value)) {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
const result = {
|
|
35
|
+
...value,
|
|
36
|
+
};
|
|
37
|
+
for (const [name, type] of Object.entries(shape)) {
|
|
38
|
+
if (Object.hasOwn(result, name)) {
|
|
39
|
+
result[name] = ReviveValue(result[name], type);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
function DecodeRow(row, table) {
|
|
45
|
+
const document = {};
|
|
46
|
+
const id = row[utils_1.ID_COLUMN];
|
|
47
|
+
if (id !== null && id !== undefined) {
|
|
48
|
+
document[utils_1.ID_COLUMN] = id;
|
|
49
|
+
}
|
|
50
|
+
const instance = row[utils_1.INSTANCE_COLUMN];
|
|
51
|
+
if (instance !== null &&
|
|
52
|
+
instance !== undefined &&
|
|
53
|
+
instance !== utils_1.DEFAULT_INSTANCE_ID) {
|
|
54
|
+
document[utils_1.INSTANCE_COLUMN] = instance;
|
|
55
|
+
}
|
|
56
|
+
for (const [name, spec] of Object.entries(table.fields)) {
|
|
57
|
+
const value = row[spec.column];
|
|
58
|
+
if (value === null || value === undefined) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
document[name] = ReviveValue(value, spec.type);
|
|
62
|
+
}
|
|
63
|
+
const extra = {
|
|
64
|
+
...row[utils_1.EXTRA_COLUMN],
|
|
65
|
+
};
|
|
66
|
+
delete extra[utils_1.ID_COLUMN];
|
|
67
|
+
delete extra[utils_1.INSTANCE_COLUMN];
|
|
68
|
+
return { ...document, ...extra };
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/implementations/database/result.ts"],"names":[],"mappings":";;AA6BA,kCAMC;AAsBD,8BA8BC;AArFD,mCAKiB;AAIjB,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,IAAI,GACR,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACrD,CAAC;AAED,MAAM,QAAQ,GAA8C;IAC1D,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC;IAC5C,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CACrB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAClB,CAAC,CAAC,KAAK,CAAC,GAAG,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AC;IAC7C,MAAM,EAAE,GAAG,GAAG,CAAC,iBAAS,CAAC,CAAC;IAC1B,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACpC,QAAQ,CAAC,iBAAS,CAAC,GAAG,EAAE,CAAC;IAC3B,CAAC;IACD,MAAM,QAAQ,GAAG,GAAG,CAAC,uBAAe,CAAC,CAAC;IACtC,IACE,QAAQ,KAAK,IAAI;QACjB,QAAQ,KAAK,SAAS;QACtB,QAAQ,KAAK,2BAAmB,EAChC,CAAC;QACD,QAAQ,CAAC,uBAAe,CAAC,GAAG,QAAQ,CAAC;IACvC,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACxD,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC1C,SAAS;QACX,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,KAAK,GAAG;QACZ,GAAI,GAAG,CAAC,oBAAY,CAAoC;KACzD,CAAC;IACF,OAAO,KAAK,CAAC,iBAAS,CAAC,CAAC;IACxB,OAAO,KAAK,CAAC,uBAAe,CAAC,CAAC;IAC9B,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type TableShape } from "./fields";
|
|
2
|
+
import { type Compiled } from "./sql";
|
|
3
|
+
import { type SqlShape, type SqlType } from "./types";
|
|
4
|
+
export interface RowSource {
|
|
5
|
+
field(name: string, def?: Compiled): Compiled;
|
|
6
|
+
dynamicField(key: Compiled, def?: Compiled): Compiled;
|
|
7
|
+
toJson(): Compiled;
|
|
8
|
+
shape(): SqlShape | undefined;
|
|
9
|
+
presence?(): string;
|
|
10
|
+
}
|
|
11
|
+
export interface DocumentMember extends Compiled {
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function BuildDocument(members: DocumentMember[], overflow?: string): Compiled;
|
|
15
|
+
export type ColumnAddress = (column: string, type: SqlType) => Compiled;
|
|
16
|
+
export declare function AliasedColumns(alias: string): ColumnAddress;
|
|
17
|
+
export declare function LoggedColumns(row: string): ColumnAddress;
|
|
18
|
+
export declare class ColumnRowSource implements RowSource {
|
|
19
|
+
private readonly address;
|
|
20
|
+
private readonly table;
|
|
21
|
+
constructor(address: ColumnAddress, table: TableShape);
|
|
22
|
+
field(name: string, def?: Compiled): Compiled;
|
|
23
|
+
private instance;
|
|
24
|
+
private overflow;
|
|
25
|
+
dynamicField(key: Compiled, def?: Compiled): Compiled;
|
|
26
|
+
private members;
|
|
27
|
+
toJson(): Compiled;
|
|
28
|
+
shape(): SqlShape;
|
|
29
|
+
}
|
|
30
|
+
export declare class NullableRowSource implements RowSource {
|
|
31
|
+
private readonly inner;
|
|
32
|
+
constructor(inner: RowSource);
|
|
33
|
+
field(name: string, def?: Compiled): Compiled;
|
|
34
|
+
dynamicField(key: Compiled, def?: Compiled): Compiled;
|
|
35
|
+
toJson(): Compiled;
|
|
36
|
+
shape(): SqlShape | undefined;
|
|
37
|
+
}
|
|
38
|
+
export declare class JsonRowSource implements RowSource {
|
|
39
|
+
private readonly value;
|
|
40
|
+
constructor(value: Compiled);
|
|
41
|
+
field(name: string, def?: Compiled): Compiled;
|
|
42
|
+
dynamicField(key: Compiled, def?: Compiled): Compiled;
|
|
43
|
+
private fieldType;
|
|
44
|
+
toJson(): Compiled;
|
|
45
|
+
shape(): SqlShape | undefined;
|
|
46
|
+
}
|
|
47
|
+
export declare function ExternalNames(shape: TableShape): string[];
|
|
48
|
+
export type ExternalReads = "table" | "output";
|
|
49
|
+
export declare class ExternalRowSource implements RowSource {
|
|
50
|
+
private readonly alias;
|
|
51
|
+
private readonly table;
|
|
52
|
+
private readonly reads;
|
|
53
|
+
constructor(alias: string, table: TableShape, reads: ExternalReads);
|
|
54
|
+
private column;
|
|
55
|
+
private key;
|
|
56
|
+
private native;
|
|
57
|
+
private declared;
|
|
58
|
+
field(name: string, def?: Compiled): Compiled;
|
|
59
|
+
dynamicField(key: Compiled, def?: Compiled): Compiled;
|
|
60
|
+
private members;
|
|
61
|
+
toJson(): Compiled;
|
|
62
|
+
shape(): SqlShape;
|
|
63
|
+
presence(): string;
|
|
64
|
+
}
|