@sixb/sqlite 0.1.10 → 0.1.11
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/dist/index.js +43 -15
- package/dist/index.js.map +5 -5
- package/dist/migrations.d.ts.map +1 -1
- package/dist/ontology-storage/outbox.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/connector-connection-storage.ts +10 -0
- package/src/migrations/040-outbox-publication-order.sql +8 -0
- package/src/migrations.ts +4 -0
- package/src/ontology-storage/outbox.ts +33 -16
package/dist/index.js
CHANGED
|
@@ -3979,6 +3979,17 @@ ALTER TABLE projection_runs ADD COLUMN source_changes_read INTEGER
|
|
|
3979
3979
|
CHECK (source_changes_read IS NULL OR source_changes_read >= 0);
|
|
3980
3980
|
`;
|
|
3981
3981
|
|
|
3982
|
+
// src/migrations/040-outbox-publication-order.sql
|
|
3983
|
+
var _040_outbox_publication_order_default = `-- Match the bounded claim order without sorting the entire unpublished backlog.
|
|
3984
|
+
-- Cover every selection predicate so new databases also benefit before ANALYZE.
|
|
3985
|
+
CREATE INDEX idx_ontology_outbox_publication_order
|
|
3986
|
+
ON ontology_outbox(
|
|
3987
|
+
project_id, published_at, created_at, commit_id, commit_ordinal,
|
|
3988
|
+
available_at, lease_expires_at
|
|
3989
|
+
)
|
|
3990
|
+
WHERE published_at IS NULL;
|
|
3991
|
+
`;
|
|
3992
|
+
|
|
3982
3993
|
// src/migrations/037-execution-requester-groups.sql
|
|
3983
3994
|
var _037_execution_requester_groups_default = `ALTER TABLE executions ADD COLUMN requester_group_ids TEXT NOT NULL DEFAULT '[]';
|
|
3984
3995
|
|
|
@@ -4134,7 +4145,8 @@ var sqliteStorageMigrations = defineMigrations({
|
|
|
4134
4145
|
sqliteSql("036-share-sessions", _036_share_sessions_default),
|
|
4135
4146
|
sqliteSql("037-execution-requester-groups", _037_execution_requester_groups_default),
|
|
4136
4147
|
sqliteSql("038-projection-source-roots", _038_projection_source_roots_default),
|
|
4137
|
-
sqliteSql("039-connector-optional-pkce", _039_connector_optional_pkce_default)
|
|
4148
|
+
sqliteSql("039-connector-optional-pkce", _039_connector_optional_pkce_default),
|
|
4149
|
+
sqliteSql("040-outbox-publication-order", _040_outbox_publication_order_default)
|
|
4138
4150
|
]
|
|
4139
4151
|
});
|
|
4140
4152
|
function sqliteStoragePath(basePath) {
|
|
@@ -9152,6 +9164,14 @@ class SqliteConnectorConnectionPersistence {
|
|
|
9152
9164
|
throw error;
|
|
9153
9165
|
}
|
|
9154
9166
|
}
|
|
9167
|
+
async listPendingConnectionRuns() {
|
|
9168
|
+
if (!this.scope.connectorId)
|
|
9169
|
+
return [];
|
|
9170
|
+
const rows = this.db.query(`SELECT * FROM connector_connection_runs
|
|
9171
|
+
WHERE project_id = ? AND connector_id = ?
|
|
9172
|
+
AND (status = 'running' OR (status = 'waiting' AND waiting_for = 'account_selection'))`).all(this.scope.projectId, this.scope.connectorId);
|
|
9173
|
+
return rows.map(connectionRunFromRow);
|
|
9174
|
+
}
|
|
9155
9175
|
async getConnectionRun(id) {
|
|
9156
9176
|
const row = this.getById("connector_connection_runs", id);
|
|
9157
9177
|
return row ? connectionRunFromRow(row) : null;
|
|
@@ -13613,20 +13633,26 @@ class SqliteOntologyOutboxStorage {
|
|
|
13613
13633
|
if (leaseExpiry <= now) {
|
|
13614
13634
|
throw new MaterializationValidationError2("Ontology outbox lease expiry must be later than the claim time.");
|
|
13615
13635
|
}
|
|
13636
|
+
const eligible = this.db.query(`SELECT CAST(rowid AS TEXT) AS rowId
|
|
13637
|
+
FROM ontology_outbox INDEXED BY idx_ontology_outbox_claim
|
|
13638
|
+
WHERE project_id = ? AND published_at IS NULL AND available_at <= ?
|
|
13639
|
+
AND (lease_expires_at IS NULL OR lease_expires_at <= ?)
|
|
13640
|
+
LIMIT ?`).all(input.projectId, input.now, input.now, input.limit + 1);
|
|
13641
|
+
if (eligible.length === 0)
|
|
13642
|
+
return [];
|
|
13643
|
+
const selected = eligible.length <= input.limit ? eligible : this.db.query(`SELECT CAST(rowid AS TEXT) AS rowId
|
|
13644
|
+
FROM ontology_outbox INDEXED BY idx_ontology_outbox_publication_order
|
|
13645
|
+
WHERE project_id = ? AND published_at IS NULL AND available_at <= ?
|
|
13646
|
+
AND (lease_expires_at IS NULL OR lease_expires_at <= ?)
|
|
13647
|
+
ORDER BY created_at, commit_id, commit_ordinal
|
|
13648
|
+
LIMIT ?`).all(input.projectId, input.now, input.now, input.limit);
|
|
13616
13649
|
const rows = this.db.query(`
|
|
13617
13650
|
UPDATE ontology_outbox
|
|
13618
13651
|
SET attempts = attempts + 1, lease_id = ?, lease_expires_at = ?
|
|
13619
|
-
WHERE rowid IN (
|
|
13620
|
-
SELECT rowid
|
|
13621
|
-
FROM ontology_outbox
|
|
13622
|
-
WHERE project_id = ? AND published_at IS NULL AND available_at <= ?
|
|
13623
|
-
AND (lease_expires_at IS NULL OR lease_expires_at <= ?)
|
|
13624
|
-
ORDER BY created_at, commit_id, commit_ordinal
|
|
13625
|
-
LIMIT ?
|
|
13626
|
-
)
|
|
13652
|
+
WHERE rowid IN (SELECT CAST(value AS INTEGER) FROM json_each(?))
|
|
13627
13653
|
RETURNING envelope, available_at, attempts, lease_id, lease_expires_at,
|
|
13628
13654
|
published_at, last_failure, created_at
|
|
13629
|
-
`).all(input.leaseId, input.leaseExpiresAt,
|
|
13655
|
+
`).all(input.leaseId, input.leaseExpiresAt, JSON.stringify(selected.map((row) => row.rowId)));
|
|
13630
13656
|
return rows.map((row) => outboxRecord(row)).sort((left, right) => left.createdAt.localeCompare(right.createdAt) || left.envelope.id.localeCompare(right.envelope.id)).map((record) => {
|
|
13631
13657
|
if (record.leaseId === null || record.leaseExpiresAt === null) {
|
|
13632
13658
|
throw new MaterializationConflictError7("outbox-lease", "Ontology outbox claim returned an unpaired lease.");
|
|
@@ -13644,8 +13670,9 @@ class SqliteOntologyOutboxStorage {
|
|
|
13644
13670
|
WITH requested(id) AS MATERIALIZED (
|
|
13645
13671
|
SELECT CAST(value AS TEXT) FROM json_each(?)
|
|
13646
13672
|
), leased(id) AS MATERIALIZED (
|
|
13647
|
-
|
|
13648
|
-
|
|
13673
|
+
-- Drive validation from the bounded ID list even before ANALYZE.
|
|
13674
|
+
SELECT outbox.id FROM requested
|
|
13675
|
+
CROSS JOIN ontology_outbox AS outbox USING (id)
|
|
13649
13676
|
WHERE outbox.project_id = ? AND outbox.lease_id = ?
|
|
13650
13677
|
AND outbox.lease_expires_at IS NOT NULL
|
|
13651
13678
|
), eligible(id) AS (
|
|
@@ -13670,8 +13697,9 @@ class SqliteOntologyOutboxStorage {
|
|
|
13670
13697
|
WITH requested(id) AS MATERIALIZED (
|
|
13671
13698
|
SELECT CAST(value AS TEXT) FROM json_each(?)
|
|
13672
13699
|
), leased(id) AS MATERIALIZED (
|
|
13673
|
-
|
|
13674
|
-
|
|
13700
|
+
-- Drive validation from the bounded ID list even before ANALYZE.
|
|
13701
|
+
SELECT outbox.id FROM requested
|
|
13702
|
+
CROSS JOIN ontology_outbox AS outbox USING (id)
|
|
13675
13703
|
WHERE outbox.project_id = ? AND outbox.lease_id = ?
|
|
13676
13704
|
AND outbox.lease_expires_at IS NOT NULL
|
|
13677
13705
|
), eligible(id) AS (
|
|
@@ -16984,4 +17012,4 @@ export {
|
|
|
16984
17012
|
migrateSqliteStorage
|
|
16985
17013
|
};
|
|
16986
17014
|
|
|
16987
|
-
//# debugId=
|
|
17015
|
+
//# debugId=6BCAC863183D761764756E2164756E21
|