@antelopejs/postgres 0.2.2 → 0.2.4
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/README.md +28 -15
- package/dist/config.d.ts +1 -0
- package/dist/config.js +7 -3
- package/dist/config.js.map +1 -1
- package/dist/connect-failure.d.ts +1 -0
- package/dist/connect-failure.js +39 -0
- package/dist/connect-failure.js.map +1 -0
- package/dist/connection.d.ts +2 -1
- package/dist/connection.js +19 -2
- package/dist/connection.js.map +1 -1
- package/dist/implementations/catalog/index.js +3 -6
- package/dist/implementations/catalog/index.js.map +1 -1
- package/dist/implementations/database/coerce.js +20 -20
- package/dist/implementations/database/coerce.js.map +1 -1
- package/dist/implementations/database/context.d.ts +1 -0
- package/dist/implementations/database/context.js +4 -0
- package/dist/implementations/database/context.js.map +1 -1
- package/dist/implementations/database/convergence.d.ts +22 -0
- package/dist/implementations/database/convergence.js +183 -0
- package/dist/implementations/database/convergence.js.map +1 -0
- package/dist/implementations/database/cursors.js +3 -0
- package/dist/implementations/database/cursors.js.map +1 -1
- package/dist/implementations/database/ddl.d.ts +5 -26
- package/dist/implementations/database/ddl.js +15 -191
- package/dist/implementations/database/ddl.js.map +1 -1
- package/dist/implementations/database/external-column-profile.js +6 -1
- package/dist/implementations/database/external-column-profile.js.map +1 -1
- package/dist/implementations/database/external-discovery.js +5 -5
- package/dist/implementations/database/external-discovery.js.map +1 -1
- package/dist/implementations/database/external-measures.js.map +1 -1
- package/dist/implementations/database/external-payload.d.ts +2 -2
- package/dist/implementations/database/external-payload.js +23 -13
- package/dist/implementations/database/external-payload.js.map +1 -1
- package/dist/implementations/database/external-schema.d.ts +2 -2
- package/dist/implementations/database/external-schema.js +3 -3
- package/dist/implementations/database/external-schema.js.map +1 -1
- package/dist/implementations/database/external-types.js +23 -16
- package/dist/implementations/database/external-types.js.map +1 -1
- package/dist/implementations/database/external-writes.d.ts +7 -1
- package/dist/implementations/database/external-writes.js +22 -21
- package/dist/implementations/database/external-writes.js.map +1 -1
- package/dist/implementations/database/feed-pipeline.js +3 -2
- package/dist/implementations/database/feed-pipeline.js.map +1 -1
- package/dist/implementations/database/feeds.d.ts +1 -1
- package/dist/implementations/database/feeds.js +36 -45
- package/dist/implementations/database/feeds.js.map +1 -1
- package/dist/implementations/database/fields.d.ts +9 -13
- package/dist/implementations/database/fields.js +25 -21
- package/dist/implementations/database/fields.js.map +1 -1
- package/dist/implementations/database/guards.d.ts +5 -0
- package/dist/implementations/database/guards.js +23 -0
- package/dist/implementations/database/guards.js.map +1 -0
- package/dist/implementations/database/introspect.d.ts +1 -1
- package/dist/implementations/database/listener.js +9 -3
- package/dist/implementations/database/listener.js.map +1 -1
- package/dist/implementations/database/migrate.d.ts +2 -2
- package/dist/implementations/database/migrate.js +10 -10
- package/dist/implementations/database/migrate.js.map +1 -1
- package/dist/implementations/database/payload.d.ts +3 -3
- package/dist/implementations/database/payload.js +4 -4
- package/dist/implementations/database/pipeline.d.ts +6 -2
- package/dist/implementations/database/pipeline.js +4 -1
- package/dist/implementations/database/pipeline.js.map +1 -1
- package/dist/implementations/database/query.js +12 -7
- package/dist/implementations/database/query.js.map +1 -1
- package/dist/implementations/database/reaper.js +6 -4
- package/dist/implementations/database/reaper.js.map +1 -1
- package/dist/implementations/database/relation.d.ts +2 -12
- package/dist/implementations/database/relation.js +5 -141
- package/dist/implementations/database/relation.js.map +1 -1
- package/dist/implementations/database/render.d.ts +11 -0
- package/dist/implementations/database/render.js +147 -0
- package/dist/implementations/database/render.js.map +1 -0
- package/dist/implementations/database/result.d.ts +2 -2
- package/dist/implementations/database/result.js +18 -19
- package/dist/implementations/database/result.js.map +1 -1
- package/dist/implementations/database/row-source.d.ts +10 -10
- package/dist/implementations/database/row-source.js +22 -19
- package/dist/implementations/database/row-source.js.map +1 -1
- package/dist/implementations/database/schema.d.ts +2 -2
- package/dist/implementations/database/schema.js +19 -19
- package/dist/implementations/database/schema.js.map +1 -1
- package/dist/implementations/database/selection.js +13 -7
- package/dist/implementations/database/selection.js.map +1 -1
- package/dist/implementations/database/sql.d.ts +7 -3
- package/dist/implementations/database/sql.js.map +1 -1
- package/dist/implementations/database/stage.js +3 -2
- package/dist/implementations/database/stage.js.map +1 -1
- package/dist/implementations/database/stages-aggregate.js +7 -5
- package/dist/implementations/database/stages-aggregate.js.map +1 -1
- package/dist/implementations/database/stages-array.js.map +1 -1
- package/dist/implementations/database/stages-core.js +2 -1
- package/dist/implementations/database/stages-core.js.map +1 -1
- package/dist/implementations/database/stages-date.js +2 -1
- package/dist/implementations/database/stages-date.js.map +1 -1
- package/dist/implementations/database/stages-group.js +11 -6
- package/dist/implementations/database/stages-group.js.map +1 -1
- package/dist/implementations/database/stages-join.js +13 -11
- package/dist/implementations/database/stages-join.js.map +1 -1
- package/dist/implementations/database/stages-numeric.js.map +1 -1
- package/dist/implementations/database/stages-object.js +1 -1
- package/dist/implementations/database/stages-object.js.map +1 -1
- package/dist/implementations/database/stages-projection.js +9 -8
- package/dist/implementations/database/stages-projection.js.map +1 -1
- package/dist/implementations/database/stages-rows.js +10 -8
- package/dist/implementations/database/stages-rows.js.map +1 -1
- package/dist/implementations/database/stages-selection.js +6 -4
- package/dist/implementations/database/stages-selection.js.map +1 -1
- package/dist/implementations/database/stages-string.js +7 -6
- package/dist/implementations/database/stages-string.js.map +1 -1
- package/dist/implementations/database/subquery.d.ts +1 -1
- package/dist/implementations/database/subquery.js +7 -5
- package/dist/implementations/database/subquery.js.map +1 -1
- package/dist/implementations/database/types.d.ts +5 -5
- package/dist/implementations/database/types.js +11 -11
- package/dist/implementations/database/types.js.map +1 -1
- package/dist/implementations/database/utils.js +2 -1
- package/dist/implementations/database/utils.js.map +1 -1
- package/dist/implementations/database/value.d.ts +1 -1
- package/dist/implementations/database/value.js +34 -33
- package/dist/implementations/database/value.js.map +1 -1
- package/dist/implementations/database/writes-atomic.js +6 -5
- package/dist/implementations/database/writes-atomic.js.map +1 -1
- package/dist/implementations/database/writes-identity.js +18 -19
- package/dist/implementations/database/writes-identity.js.map +1 -1
- package/dist/implementations/database/writes-insert.js +16 -22
- package/dist/implementations/database/writes-insert.js.map +1 -1
- package/dist/implementations/database/writes-shared.d.ts +1 -1
- package/dist/implementations/database/writes-shared.js +11 -7
- package/dist/implementations/database/writes-shared.js.map +1 -1
- package/dist/implementations/database/writes.d.ts +22 -1
- package/dist/implementations/database/writes.js +6 -3
- package/dist/implementations/database/writes.js.map +1 -1
- package/dist/test/catalog-owned.test.js +2 -0
- package/dist/test/catalog-owned.test.js.map +1 -1
- package/dist/test/contention.test.js.map +1 -1
- package/dist/test/duplicate-key.test.js +13 -10
- package/dist/test/duplicate-key.test.js.map +1 -1
- package/dist/test/indexes.test.js +7 -7
- package/dist/test/indexes.test.js.map +1 -1
- package/dist/test/unit/coerce.spec.js +7 -7
- package/dist/test/unit/coerce.spec.js.map +1 -1
- package/dist/test/unit/config.spec.js +3 -1
- package/dist/test/unit/config.spec.js.map +1 -1
- package/dist/test/unit/connect-failure.spec.d.ts +1 -0
- package/dist/test/unit/connect-failure.spec.js +50 -0
- package/dist/test/unit/connect-failure.spec.js.map +1 -0
- package/dist/test/unit/connection.spec.js +16 -18
- package/dist/test/unit/connection.spec.js.map +1 -1
- package/dist/test/unit/convergence.spec.d.ts +1 -0
- package/dist/test/unit/convergence.spec.js +347 -0
- package/dist/test/unit/convergence.spec.js.map +1 -0
- package/dist/test/unit/cursors-fixture.d.ts +79 -0
- package/dist/test/unit/cursors-fixture.js +245 -0
- package/dist/test/unit/cursors-fixture.js.map +1 -0
- package/dist/test/unit/cursors.spec.js +138 -718
- package/dist/test/unit/cursors.spec.js.map +1 -1
- package/dist/test/unit/cursors.teardown.spec.d.ts +1 -0
- package/dist/test/unit/cursors.teardown.spec.js +322 -0
- package/dist/test/unit/cursors.teardown.spec.js.map +1 -0
- package/dist/test/unit/cursors.window.spec.d.ts +1 -0
- package/dist/test/unit/cursors.window.spec.js +78 -0
- package/dist/test/unit/cursors.window.spec.js.map +1 -0
- package/dist/test/unit/ddl-fixture.d.ts +5 -0
- package/dist/test/unit/ddl-fixture.js +19 -0
- package/dist/test/unit/ddl-fixture.js.map +1 -0
- package/dist/test/unit/ddl.spec.js +39 -380
- package/dist/test/unit/ddl.spec.js.map +1 -1
- package/dist/test/unit/expression-array-fixture.d.ts +17 -0
- package/dist/test/unit/expression-array-fixture.js +63 -0
- package/dist/test/unit/expression-array-fixture.js.map +1 -0
- package/dist/test/unit/expression-array-walk.spec.d.ts +1 -0
- package/dist/test/unit/expression-array-walk.spec.js +235 -0
- package/dist/test/unit/expression-array-walk.spec.js.map +1 -0
- package/dist/test/unit/expression-array.spec.js +48 -322
- package/dist/test/unit/expression-array.spec.js.map +1 -1
- package/dist/test/unit/expression-date.spec.js +4 -3
- package/dist/test/unit/expression-date.spec.js.map +1 -1
- package/dist/test/unit/expression-fixture.d.ts +15 -0
- package/dist/test/unit/expression-fixture.js +40 -0
- package/dist/test/unit/expression-fixture.js.map +1 -0
- package/dist/test/unit/expression-numeric.spec.js +10 -8
- package/dist/test/unit/expression-numeric.spec.js.map +1 -1
- package/dist/test/unit/expression-object.spec.js +3 -4
- package/dist/test/unit/expression-object.spec.js.map +1 -1
- package/dist/test/unit/expression-predicate.spec.d.ts +1 -0
- package/dist/test/unit/expression-predicate.spec.js +231 -0
- package/dist/test/unit/expression-predicate.spec.js.map +1 -0
- package/dist/test/unit/expression-stages.spec.js +0 -5
- package/dist/test/unit/expression-stages.spec.js.map +1 -1
- package/dist/test/unit/expression-string.spec.js +2 -5
- package/dist/test/unit/expression-string.spec.js.map +1 -1
- package/dist/test/unit/expression.spec.js +44 -292
- package/dist/test/unit/expression.spec.js.map +1 -1
- package/dist/test/unit/external-comparisons.spec.js +5 -5
- package/dist/test/unit/external-comparisons.spec.js.map +1 -1
- package/dist/test/unit/external-types.spec.js +2 -3
- package/dist/test/unit/external-types.spec.js.map +1 -1
- package/dist/test/unit/feeds.spec.js +40 -23
- package/dist/test/unit/feeds.spec.js.map +1 -1
- package/dist/test/unit/fields.spec.js +15 -9
- package/dist/test/unit/fields.spec.js.map +1 -1
- package/dist/test/unit/invalid-fixture.d.ts +3 -0
- package/dist/test/unit/invalid-fixture.js +11 -0
- package/dist/test/unit/invalid-fixture.js.map +1 -0
- package/dist/test/unit/payload.spec.js.map +1 -1
- package/dist/test/unit/pipeline-aggregate.spec.js +14 -14
- package/dist/test/unit/pipeline-aggregate.spec.js.map +1 -1
- package/dist/test/unit/pipeline-fixture.d.ts +25 -6
- package/dist/test/unit/pipeline-fixture.js +21 -11
- package/dist/test/unit/pipeline-fixture.js.map +1 -1
- package/dist/test/unit/pipeline-group-fixture.d.ts +2 -0
- package/dist/test/unit/pipeline-group-fixture.js +6 -0
- package/dist/test/unit/pipeline-group-fixture.js.map +1 -0
- package/dist/test/unit/pipeline-group.spec.js +15 -248
- package/dist/test/unit/pipeline-group.spec.js.map +1 -1
- package/dist/test/unit/pipeline-lookup.spec.js +13 -10
- package/dist/test/unit/pipeline-lookup.spec.js.map +1 -1
- package/dist/test/unit/pipeline-projection.spec.js +12 -13
- package/dist/test/unit/pipeline-projection.spec.js.map +1 -1
- package/dist/test/unit/pipeline-rows.spec.js +21 -18
- package/dist/test/unit/pipeline-rows.spec.js.map +1 -1
- package/dist/test/unit/pipeline-selection.spec.js +6 -4
- package/dist/test/unit/pipeline-selection.spec.js.map +1 -1
- package/dist/test/unit/pipeline-stages.spec.js +23 -35
- package/dist/test/unit/pipeline-stages.spec.js.map +1 -1
- package/dist/test/unit/pipeline-substream.spec.d.ts +1 -0
- package/dist/test/unit/pipeline-substream.spec.js +246 -0
- package/dist/test/unit/pipeline-substream.spec.js.map +1 -0
- package/dist/test/unit/pipeline.spec.js +1 -1
- package/dist/test/unit/query.spec.js +6 -2
- package/dist/test/unit/query.spec.js.map +1 -1
- package/dist/test/unit/reaper.spec.js +4 -3
- package/dist/test/unit/reaper.spec.js.map +1 -1
- package/dist/test/unit/relation.spec.js +37 -36
- package/dist/test/unit/relation.spec.js.map +1 -1
- package/dist/test/unit/result.spec.js +13 -11
- package/dist/test/unit/result.spec.js.map +1 -1
- package/dist/test/unit/row-source.spec.js +1 -1
- package/dist/test/unit/row-source.spec.js.map +1 -1
- package/dist/test/unit/schema.spec.js +5 -2
- package/dist/test/unit/schema.spec.js.map +1 -1
- package/dist/test/unit/selection.spec.js +7 -3
- package/dist/test/unit/selection.spec.js.map +1 -1
- package/dist/test/unit/types.spec.js +6 -6
- package/dist/test/unit/types.spec.js.map +1 -1
- package/dist/test/unit/writes-atomic.spec.js +2 -2
- package/dist/test/unit/writes-atomic.spec.js.map +1 -1
- package/dist/test/unit/writes-insert.spec.js +5 -4
- package/dist/test/unit/writes-insert.spec.js.map +1 -1
- package/dist/test/unit/writes-replace.spec.js +6 -6
- package/dist/test/unit/writes-replace.spec.js.map +1 -1
- package/dist/test/unit/writes-target.spec.js +3 -3
- package/dist/test/unit/writes-target.spec.js.map +1 -1
- package/dist/test/unit/writes-update-fixture.d.ts +9 -0
- package/dist/test/unit/writes-update-fixture.js +20 -0
- package/dist/test/unit/writes-update-fixture.js.map +1 -0
- package/dist/test/unit/writes-update-mapper.spec.d.ts +1 -0
- package/dist/test/unit/writes-update-mapper.spec.js +123 -0
- package/dist/test/unit/writes-update-mapper.spec.js.map +1 -0
- package/dist/test/unit/writes-update.spec.js +42 -171
- package/dist/test/unit/writes-update.spec.js.map +1 -1
- package/dist/test-external/catalog.test.js +11 -1
- package/dist/test-external/catalog.test.js.map +1 -1
- package/dist/test-external/native.test.js +8 -6
- package/dist/test-external/native.test.js.map +1 -1
- package/dist/test-external/reads.test.js +20 -22
- package/dist/test-external/reads.test.js.map +1 -1
- package/dist/test-external/refusals.test.js +45 -24
- package/dist/test-external/refusals.test.js.map +1 -1
- package/dist/test-external/registration.test.js +4 -2
- package/dist/test-external/registration.test.js.map +1 -1
- package/dist/test-external/sales.d.ts +9 -2
- package/dist/test-external/sales.js.map +1 -1
- package/dist/test-external/unreachable.test.d.ts +1 -0
- package/dist/test-external/unreachable.test.js +83 -0
- package/dist/test-external/unreachable.test.js.map +1 -0
- package/dist/test-external/writes.test.js +71 -37
- package/dist/test-external/writes.test.js.map +1 -1
- package/package.json +22 -7
|
@@ -3,26 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.OUTPUT_COLUMN = void 0;
|
|
7
7
|
exports.RequireOrigin = RequireOrigin;
|
|
8
8
|
exports.IndexColumns = IndexColumns;
|
|
9
9
|
exports.ScanColumns = ScanColumns;
|
|
10
|
-
exports.AbsorbOrder = AbsorbOrder;
|
|
11
|
-
exports.RowBound = RowBound;
|
|
12
|
-
exports.Render = Render;
|
|
13
10
|
exports.TableRelation = TableRelation;
|
|
14
11
|
exports.LoggedRelation = LoggedRelation;
|
|
15
12
|
exports.ValueRelation = ValueRelation;
|
|
16
|
-
exports.Nested = Nested;
|
|
17
|
-
exports.Prepare = Prepare;
|
|
18
13
|
exports.SetProjection = SetProjection;
|
|
19
14
|
exports.SetPlainProjection = SetPlainProjection;
|
|
20
|
-
exports.HasFlag = HasFlag;
|
|
21
15
|
exports.CurrentValue = CurrentValue;
|
|
22
16
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
23
|
-
const utils_1 = require("./utils");
|
|
24
17
|
const sql_1 = require("./sql");
|
|
25
|
-
const fields_1 = require("./fields");
|
|
26
18
|
const row_source_1 = require("./row-source");
|
|
27
19
|
exports.OUTPUT_COLUMN = "value";
|
|
28
20
|
function NewRelation(seed) {
|
|
@@ -57,106 +49,11 @@ function ScanColumns(relation, name) {
|
|
|
57
49
|
}
|
|
58
50
|
return IndexColumns(relation, name);
|
|
59
51
|
}
|
|
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
52
|
function TableSource(alias, origin, reads) {
|
|
156
|
-
if (origin.
|
|
157
|
-
return new row_source_1.ExternalRowSource(alias, origin.
|
|
53
|
+
if (origin.model.external) {
|
|
54
|
+
return new row_source_1.ExternalRowSource(alias, origin.model, reads);
|
|
158
55
|
}
|
|
159
|
-
return new row_source_1.ColumnRowSource((0, row_source_1.AliasedColumns)(alias), origin.
|
|
56
|
+
return new row_source_1.ColumnRowSource((0, row_source_1.AliasedColumns)(alias), origin.model);
|
|
160
57
|
}
|
|
161
58
|
function TableRelation(from, alias, origin, reads = "table") {
|
|
162
59
|
return NewRelation({
|
|
@@ -170,7 +67,7 @@ function LoggedRelation(from, alias, row, origin) {
|
|
|
170
67
|
return NewRelation({
|
|
171
68
|
from,
|
|
172
69
|
alias,
|
|
173
|
-
source: new row_source_1.ColumnRowSource((0, row_source_1.LoggedColumns)(row), origin.
|
|
70
|
+
source: new row_source_1.ColumnRowSource((0, row_source_1.LoggedColumns)(row), origin.model),
|
|
174
71
|
origin,
|
|
175
72
|
});
|
|
176
73
|
}
|
|
@@ -186,36 +83,6 @@ function ValueRelation(from, alias, type) {
|
|
|
186
83
|
projection,
|
|
187
84
|
});
|
|
188
85
|
}
|
|
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
86
|
function SetProjection(relation, value) {
|
|
220
87
|
relation.projection = value;
|
|
221
88
|
relation.source = new row_source_1.JsonRowSource(value);
|
|
@@ -228,9 +95,6 @@ function SetPlainProjection(relation, value, source) {
|
|
|
228
95
|
projected.projectedFrom = source;
|
|
229
96
|
return projected;
|
|
230
97
|
}
|
|
231
|
-
function HasFlag(relation, flags) {
|
|
232
|
-
return flags.some((flag) => FLAG_PREDICATES[flag](relation));
|
|
233
|
-
}
|
|
234
98
|
function CurrentValue(relation) {
|
|
235
99
|
return relation.projection ?? relation.source.toJson();
|
|
236
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation.js","sourceRoot":"","sources":["../../../src/implementations/database/relation.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"relation.js","sourceRoot":"","sources":["../../../src/implementations/database/relation.ts"],"names":[],"mappings":";;;;;;AAqJA,sCAIC;AAcD,oCASC;AAMD,kCAQC;AAoBD,sCAYC;AA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AC,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,YAAY,CAAC,QAAkB;IAC7C,OAAO,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DecodingContext } from "./context";
|
|
2
|
+
import { type Relation } from "./relation";
|
|
3
|
+
export declare function AbsorbOrder(relation: Relation): string | undefined;
|
|
4
|
+
export declare function RowBound(sql: string): string;
|
|
5
|
+
export declare const SINGLE_ROW: string;
|
|
6
|
+
export declare function Render(relation: Relation): string;
|
|
7
|
+
export declare function Nested(relation: Relation, context: DecodingContext): Relation;
|
|
8
|
+
export type RelationFlag = "projection" | "limit" | "offset" | "distinct" | "ordered" | "aggregated";
|
|
9
|
+
export declare const WHERE_BLOCKERS: readonly RelationFlag[];
|
|
10
|
+
export declare function Prepare(relation: Relation, blockedBy: readonly RelationFlag[], context: DecodingContext): Relation;
|
|
11
|
+
export declare function HasFlag(relation: Relation, flags: readonly RelationFlag[]): boolean;
|
|
@@ -0,0 +1,147 @@
|
|
|
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 = void 0;
|
|
7
|
+
exports.AbsorbOrder = AbsorbOrder;
|
|
8
|
+
exports.RowBound = RowBound;
|
|
9
|
+
exports.Render = Render;
|
|
10
|
+
exports.Nested = Nested;
|
|
11
|
+
exports.Prepare = Prepare;
|
|
12
|
+
exports.HasFlag = HasFlag;
|
|
13
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
const sql_1 = require("./sql");
|
|
16
|
+
const fields_1 = require("./fields");
|
|
17
|
+
const row_source_1 = require("./row-source");
|
|
18
|
+
const relation_1 = require("./relation");
|
|
19
|
+
function ExternalColumns(relation, model) {
|
|
20
|
+
return (0, row_source_1.ExternalNames)(model).map((name) => `${relation.source.field(name).sql} AS ${(0, sql_1.QuoteIdentifier)(name)}`);
|
|
21
|
+
}
|
|
22
|
+
function RowColumns(relation) {
|
|
23
|
+
const origin = (0, relation_1.RequireOrigin)(relation);
|
|
24
|
+
if (origin.model.external) {
|
|
25
|
+
return ExternalColumns(relation, origin.model);
|
|
26
|
+
}
|
|
27
|
+
const declared = (0, fields_1.DeclaredColumns)(origin.model);
|
|
28
|
+
const columns = (0, fields_1.PhysicalOrder)(utils_1.ID_COLUMN, utils_1.INSTANCE_COLUMN, declared, utils_1.EXTRA_COLUMN);
|
|
29
|
+
return columns.map((column) => (0, sql_1.QualifiedColumn)(relation.alias, column));
|
|
30
|
+
}
|
|
31
|
+
function SelectList(relation) {
|
|
32
|
+
const projection = relation.projection;
|
|
33
|
+
if (!projection) {
|
|
34
|
+
return RowColumns(relation).join(", ");
|
|
35
|
+
}
|
|
36
|
+
return `${projection.sql} AS ${(0, sql_1.QuoteIdentifier)(relation_1.OUTPUT_COLUMN)}`;
|
|
37
|
+
}
|
|
38
|
+
function SelectClause(relation) {
|
|
39
|
+
const modifier = relation.distinct ? "DISTINCT " : "";
|
|
40
|
+
return `SELECT ${modifier}${SelectList(relation)}`;
|
|
41
|
+
}
|
|
42
|
+
function FromItem(from, alias) {
|
|
43
|
+
return `${from} AS ${(0, sql_1.QuoteIdentifier)(alias)}`;
|
|
44
|
+
}
|
|
45
|
+
function FromClause(relation) {
|
|
46
|
+
return `FROM ${FromItem(relation.from, relation.alias)}`;
|
|
47
|
+
}
|
|
48
|
+
function RenderJoin(join) {
|
|
49
|
+
return `${join.kind} ${FromItem(join.from, join.alias)} ON ${join.on}`;
|
|
50
|
+
}
|
|
51
|
+
function JoinClauses(relation) {
|
|
52
|
+
if (relation.joins.length === 0) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return relation.joins.map(RenderJoin).join(" ");
|
|
56
|
+
}
|
|
57
|
+
function WhereClause(relation) {
|
|
58
|
+
if (relation.where.length === 0) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
return `WHERE ${relation.where.join(" AND ")}`;
|
|
62
|
+
}
|
|
63
|
+
function GroupByClause(relation) {
|
|
64
|
+
if (relation.groupBy.length === 0) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
return `GROUP BY ${relation.groupBy.map((term) => term.sql).join(", ")}`;
|
|
68
|
+
}
|
|
69
|
+
function OrderTerms(relation) {
|
|
70
|
+
if (relation.orderBy.length === 0) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
const terms = relation.orderBy.map((term) => `${term.sql} ${term.descending ? "DESC" : "ASC"}`);
|
|
74
|
+
return terms.join(", ");
|
|
75
|
+
}
|
|
76
|
+
function OrderByClause(relation) {
|
|
77
|
+
const terms = OrderTerms(relation);
|
|
78
|
+
return terms === undefined ? undefined : `ORDER BY ${terms}`;
|
|
79
|
+
}
|
|
80
|
+
const BOUND_PARAMETER = /\$\d/;
|
|
81
|
+
function AbsorbOrder(relation) {
|
|
82
|
+
const terms = OrderTerms(relation);
|
|
83
|
+
(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");
|
|
84
|
+
relation.orderBy = [];
|
|
85
|
+
return terms;
|
|
86
|
+
}
|
|
87
|
+
const ONE_ROW = "1";
|
|
88
|
+
function RowBound(sql) {
|
|
89
|
+
return `((${sql})::bigint)`;
|
|
90
|
+
}
|
|
91
|
+
exports.SINGLE_ROW = RowBound(ONE_ROW);
|
|
92
|
+
function LimitClause(relation) {
|
|
93
|
+
return relation.limit === undefined ? undefined : `LIMIT ${relation.limit}`;
|
|
94
|
+
}
|
|
95
|
+
function OffsetClause(relation) {
|
|
96
|
+
return relation.offset === undefined
|
|
97
|
+
? undefined
|
|
98
|
+
: `OFFSET ${relation.offset}`;
|
|
99
|
+
}
|
|
100
|
+
const CLAUSES = [
|
|
101
|
+
SelectClause,
|
|
102
|
+
FromClause,
|
|
103
|
+
JoinClauses,
|
|
104
|
+
WhereClause,
|
|
105
|
+
GroupByClause,
|
|
106
|
+
OrderByClause,
|
|
107
|
+
LimitClause,
|
|
108
|
+
OffsetClause,
|
|
109
|
+
];
|
|
110
|
+
function Render(relation) {
|
|
111
|
+
const clauses = CLAUSES.map((build) => build(relation));
|
|
112
|
+
return clauses.filter((clause) => clause !== undefined).join(" ");
|
|
113
|
+
}
|
|
114
|
+
function Nested(relation, context) {
|
|
115
|
+
const from = `(${Render(relation)})`;
|
|
116
|
+
const alias = context.nextAlias();
|
|
117
|
+
const projection = relation.projection;
|
|
118
|
+
const wrapped = projection
|
|
119
|
+
? (0, relation_1.ValueRelation)(from, alias, projection.type)
|
|
120
|
+
: (0, relation_1.TableRelation)(from, alias, (0, relation_1.RequireOrigin)(relation), "output");
|
|
121
|
+
wrapped.single = relation.single;
|
|
122
|
+
wrapped.absent = relation.absent;
|
|
123
|
+
return wrapped;
|
|
124
|
+
}
|
|
125
|
+
exports.WHERE_BLOCKERS = [
|
|
126
|
+
"projection",
|
|
127
|
+
"limit",
|
|
128
|
+
"offset",
|
|
129
|
+
"distinct",
|
|
130
|
+
"aggregated",
|
|
131
|
+
];
|
|
132
|
+
const FLAG_PREDICATES = {
|
|
133
|
+
projection: (relation) => relation.projection !== undefined,
|
|
134
|
+
limit: (relation) => relation.limit !== undefined,
|
|
135
|
+
offset: (relation) => relation.offset !== undefined,
|
|
136
|
+
distinct: (relation) => relation.distinct,
|
|
137
|
+
ordered: (relation) => relation.orderBy.length > 0,
|
|
138
|
+
aggregated: (relation) => relation.aggregated,
|
|
139
|
+
};
|
|
140
|
+
function Prepare(relation, blockedBy, context) {
|
|
141
|
+
const blocked = blockedBy.some((flag) => FLAG_PREDICATES[flag](relation));
|
|
142
|
+
return blocked ? Nested(relation, context) : relation;
|
|
143
|
+
}
|
|
144
|
+
function HasFlag(relation, flags) {
|
|
145
|
+
return flags.some((flag) => FLAG_PREDICATES[flag](relation));
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/implementations/database/render.ts"],"names":[],"mappings":";;;;;;AAwHA,kCAQC;AAYD,4BAEC;AAiCD,wBAGC;AAsBD,wBAUC;AAkDD,0BAOC;AAGD,0BAKC;AAnRD,8DAAiC;AAGjC,mCAAmE;AACnE,+BAAyD;AACzD,qCAA2E;AAC3E,6CAA6C;AAC7C,yCAOoB;AAGpB,SAAS,eAAe,CAAC,QAAkB,EAAE,KAAiB;IAC5D,OAAO,IAAA,0BAAa,EAAC,KAAK,CAAC,CAAC,GAAG,CAC7B,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,OAAO,IAAA,qBAAe,EAAC,IAAI,CAAC,EAAE,CAC3E,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,QAAkB;IACpC,MAAM,MAAM,GAAG,IAAA,wBAAa,EAAC,QAAQ,CAAC,CAAC;IACvC,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC1B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Q,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ;IACzC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;IAClD,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU;CAC9C,CAAC;AASF,SAAgB,OAAO,CACrB,QAAkB,EAClB,SAAkC,EAClC,OAAwB;IAExB,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1E,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AACxD,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TableModel } from "./fields";
|
|
2
2
|
import type { SqlType } from "./types";
|
|
3
3
|
export declare function ReviveValue(value: unknown, type: SqlType): unknown;
|
|
4
|
-
export declare function DecodeRow(row: Record<string, unknown>, table:
|
|
4
|
+
export declare function DecodeRow(row: Record<string, unknown>, table: TableModel): Record<string, unknown>;
|
|
@@ -3,38 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ReviveValue = ReviveValue;
|
|
4
4
|
exports.DecodeRow = DecodeRow;
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
+
const guards_1 = require("./guards");
|
|
6
7
|
function ReviveTimestamp(value) {
|
|
7
8
|
if (value instanceof Date) {
|
|
8
9
|
return value;
|
|
9
10
|
}
|
|
10
|
-
const date =
|
|
11
|
+
const date = (0, guards_1.IsNumber)(value) ? new Date(value) : new Date(String(value));
|
|
11
12
|
return Number.isNaN(date.getTime()) ? value : date;
|
|
12
13
|
}
|
|
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
14
|
function ReviveValue(value, type) {
|
|
21
15
|
if (value === null || value === undefined) {
|
|
22
16
|
return value;
|
|
23
17
|
}
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
switch (type.kind) {
|
|
19
|
+
case "timestamp":
|
|
20
|
+
return ReviveTimestamp(value);
|
|
21
|
+
case "array":
|
|
22
|
+
return Array.isArray(value)
|
|
23
|
+
? value.map((item) => ReviveValue(item, type.elem))
|
|
24
|
+
: value;
|
|
25
|
+
case "json":
|
|
26
|
+
return ReviveKeyTypes(value, type.keys);
|
|
27
|
+
default:
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
|
-
function
|
|
28
|
-
if (!
|
|
29
|
-
typeof value !== "object" ||
|
|
30
|
-
value === null ||
|
|
31
|
-
Array.isArray(value)) {
|
|
31
|
+
function ReviveKeyTypes(value, keyTypes) {
|
|
32
|
+
if (!keyTypes || !(0, guards_1.IsDocument)(value)) {
|
|
32
33
|
return value;
|
|
33
34
|
}
|
|
34
|
-
const result = {
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
for (const [name, type] of Object.entries(shape)) {
|
|
35
|
+
const result = { ...value };
|
|
36
|
+
for (const [name, type] of Object.entries(keyTypes)) {
|
|
38
37
|
if (Object.hasOwn(result, name)) {
|
|
39
38
|
result[name] = ReviveValue(result[name], type);
|
|
40
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/implementations/database/result.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/implementations/database/result.ts"],"names":[],"mappings":";;AAkBA,kCAgBC;AAeD,8BA8BC;AA7ED,mCAKiB;AACjB,qCAAgD;AAEhD,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,IAAI,GAAG,IAAA,iBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACzE,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACrD,CAAC;AAED,SAAgB,WAAW,CAAC,KAAc,EAAE,IAAa;IACvD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,WAAW;YACd,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;QAChC,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;gBACzB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBACnD,CAAC,CAAC,KAAK,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AAC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K,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"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type TableModel } from "./fields";
|
|
2
2
|
import { type Compiled } from "./sql";
|
|
3
|
-
import { type
|
|
3
|
+
import { type KeyTypes, type SqlType } from "./types";
|
|
4
4
|
export interface RowSource {
|
|
5
5
|
field(name: string, def?: Compiled): Compiled;
|
|
6
6
|
dynamicField(key: Compiled, def?: Compiled): Compiled;
|
|
7
7
|
toJson(): Compiled;
|
|
8
|
-
|
|
8
|
+
keyTypes(): KeyTypes | undefined;
|
|
9
9
|
presence?(): string;
|
|
10
10
|
}
|
|
11
11
|
export interface DocumentMember extends Compiled {
|
|
@@ -18,14 +18,14 @@ export declare function LoggedColumns(row: string): ColumnAddress;
|
|
|
18
18
|
export declare class ColumnRowSource implements RowSource {
|
|
19
19
|
private readonly address;
|
|
20
20
|
private readonly table;
|
|
21
|
-
constructor(address: ColumnAddress, table:
|
|
21
|
+
constructor(address: ColumnAddress, table: TableModel);
|
|
22
22
|
field(name: string, def?: Compiled): Compiled;
|
|
23
23
|
private instance;
|
|
24
24
|
private overflow;
|
|
25
25
|
dynamicField(key: Compiled, def?: Compiled): Compiled;
|
|
26
26
|
private members;
|
|
27
27
|
toJson(): Compiled;
|
|
28
|
-
|
|
28
|
+
keyTypes(): KeyTypes;
|
|
29
29
|
}
|
|
30
30
|
export declare class NullableRowSource implements RowSource {
|
|
31
31
|
private readonly inner;
|
|
@@ -33,7 +33,7 @@ export declare class NullableRowSource implements RowSource {
|
|
|
33
33
|
field(name: string, def?: Compiled): Compiled;
|
|
34
34
|
dynamicField(key: Compiled, def?: Compiled): Compiled;
|
|
35
35
|
toJson(): Compiled;
|
|
36
|
-
|
|
36
|
+
keyTypes(): KeyTypes | undefined;
|
|
37
37
|
}
|
|
38
38
|
export declare class JsonRowSource implements RowSource {
|
|
39
39
|
private readonly value;
|
|
@@ -42,15 +42,15 @@ export declare class JsonRowSource implements RowSource {
|
|
|
42
42
|
dynamicField(key: Compiled, def?: Compiled): Compiled;
|
|
43
43
|
private fieldType;
|
|
44
44
|
toJson(): Compiled;
|
|
45
|
-
|
|
45
|
+
keyTypes(): KeyTypes | undefined;
|
|
46
46
|
}
|
|
47
|
-
export declare function ExternalNames(
|
|
47
|
+
export declare function ExternalNames(model: TableModel): string[];
|
|
48
48
|
export type ExternalReads = "table" | "output";
|
|
49
49
|
export declare class ExternalRowSource implements RowSource {
|
|
50
50
|
private readonly alias;
|
|
51
51
|
private readonly table;
|
|
52
52
|
private readonly reads;
|
|
53
|
-
constructor(alias: string, table:
|
|
53
|
+
constructor(alias: string, table: TableModel, reads: ExternalReads);
|
|
54
54
|
private column;
|
|
55
55
|
private key;
|
|
56
56
|
private native;
|
|
@@ -59,6 +59,6 @@ export declare class ExternalRowSource implements RowSource {
|
|
|
59
59
|
dynamicField(key: Compiled, def?: Compiled): Compiled;
|
|
60
60
|
private members;
|
|
61
61
|
toJson(): Compiled;
|
|
62
|
-
|
|
62
|
+
keyTypes(): KeyTypes;
|
|
63
63
|
presence(): string;
|
|
64
64
|
}
|
|
@@ -13,12 +13,12 @@ const external_types_1 = require("./external-types");
|
|
|
13
13
|
const sql_1 = require("./sql");
|
|
14
14
|
const types_1 = require("./types");
|
|
15
15
|
const DEFAULT_INSTANCE_SQL = (0, sql_1.QuoteLiteral)(utils_1.DEFAULT_INSTANCE_ID);
|
|
16
|
-
function
|
|
17
|
-
const
|
|
16
|
+
function MemberKeyTypes(members) {
|
|
17
|
+
const keyTypes = {};
|
|
18
18
|
for (const member of members) {
|
|
19
|
-
|
|
19
|
+
keyTypes[member.name] = member.type;
|
|
20
20
|
}
|
|
21
|
-
return
|
|
21
|
+
return keyTypes;
|
|
22
22
|
}
|
|
23
23
|
function ContainerMember(member) {
|
|
24
24
|
const built = `jsonb_build_object(${(0, sql_1.QuoteLiteral)(member.name)}, ${member.sql})`;
|
|
@@ -39,7 +39,10 @@ function BuildDocument(members, overflow) {
|
|
|
39
39
|
if (overflow) {
|
|
40
40
|
parts.push(overflow);
|
|
41
41
|
}
|
|
42
|
-
return {
|
|
42
|
+
return {
|
|
43
|
+
sql: `(${parts.join(" || ")})`,
|
|
44
|
+
type: (0, types_1.JsonOf)(MemberKeyTypes(members)),
|
|
45
|
+
};
|
|
43
46
|
}
|
|
44
47
|
function KeySubject(name) {
|
|
45
48
|
return `The default for key '${name}'`;
|
|
@@ -100,8 +103,8 @@ class ColumnRowSource {
|
|
|
100
103
|
const overflow = `COALESCE(${this.overflow()}, '{}'::jsonb)`;
|
|
101
104
|
return BuildDocument(this.members(), overflow);
|
|
102
105
|
}
|
|
103
|
-
|
|
104
|
-
return
|
|
106
|
+
keyTypes() {
|
|
107
|
+
return MemberKeyTypes(this.members());
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
exports.ColumnRowSource = ColumnRowSource;
|
|
@@ -125,8 +128,8 @@ class NullableRowSource {
|
|
|
125
128
|
type: document.type,
|
|
126
129
|
};
|
|
127
130
|
}
|
|
128
|
-
|
|
129
|
-
return this.inner.
|
|
131
|
+
keyTypes() {
|
|
132
|
+
return this.inner.keyTypes();
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
exports.NullableRowSource = NullableRowSource;
|
|
@@ -146,23 +149,23 @@ class JsonRowSource {
|
|
|
146
149
|
return (0, coerce_1.WithDefault)({ sql: `(${this.toJson().sql} -> ${(0, coerce_1.Cast)(key, types_1.TEXT).sql})`, type: types_1.OPAQUE }, def);
|
|
147
150
|
}
|
|
148
151
|
fieldType(name) {
|
|
149
|
-
const
|
|
150
|
-
if (!
|
|
152
|
+
const keyTypes = this.keyTypes();
|
|
153
|
+
if (!keyTypes || !Object.hasOwn(keyTypes, name)) {
|
|
151
154
|
return types_1.OPAQUE;
|
|
152
155
|
}
|
|
153
|
-
return
|
|
156
|
+
return keyTypes[name];
|
|
154
157
|
}
|
|
155
158
|
toJson() {
|
|
156
159
|
return (0, coerce_1.Cast)(this.value, this.value.type.kind === "json" ? this.value.type : types_1.OPAQUE);
|
|
157
160
|
}
|
|
158
|
-
|
|
159
|
-
return (0, types_1.
|
|
161
|
+
keyTypes() {
|
|
162
|
+
return (0, types_1.KeyTypesOf)(this.value.type);
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
165
|
exports.JsonRowSource = JsonRowSource;
|
|
163
|
-
function ExternalNames(
|
|
164
|
-
const declared = Object.keys(
|
|
165
|
-
return
|
|
166
|
+
function ExternalNames(model) {
|
|
167
|
+
const declared = Object.keys(model.fields);
|
|
168
|
+
return model.external?.key ? [utils_1.ID_COLUMN, ...declared] : declared;
|
|
166
169
|
}
|
|
167
170
|
function JsonKeyOf(other) {
|
|
168
171
|
return `((CASE WHEN pg_input_is_valid(${other}, 'jsonb') THEN ${other} END)::jsonb)`;
|
|
@@ -268,8 +271,8 @@ class ExternalRowSource {
|
|
|
268
271
|
toJson() {
|
|
269
272
|
return BuildDocument(this.members());
|
|
270
273
|
}
|
|
271
|
-
|
|
272
|
-
return
|
|
274
|
+
keyTypes() {
|
|
275
|
+
return MemberKeyTypes(this.members());
|
|
273
276
|
}
|
|
274
277
|
presence() {
|
|
275
278
|
return `(${(0, sql_1.QuoteIdentifier)(this.alias)} IS DISTINCT FROM NULL)`;
|