weave-typescript 0.12.0 → 0.13.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/dist/google/api/annotations.pb.js +1 -1
- package/dist/google/api/http.pb.js +1 -1
- package/dist/google/protobuf/descriptor.pb.d.ts +8 -1
- package/dist/google/protobuf/descriptor.pb.js +8 -1
- package/dist/google/protobuf/struct.pb.js +1 -1
- package/dist/google/protobuf/timestamp.pb.d.ts +7 -6
- package/dist/google/protobuf/timestamp.pb.js +1 -1
- package/dist/weaveapi/atc/v1/event.pb.d.ts +33 -0
- package/dist/weaveapi/atc/v1/event.pb.js +263 -0
- package/dist/weaveapi/atc/v1/message.pb.d.ts +44 -0
- package/dist/weaveapi/atc/v1/message.pb.js +287 -0
- package/dist/weaveapi/atc/v1/process.pb.d.ts +91 -0
- package/dist/weaveapi/atc/v1/process.pb.js +658 -0
- package/dist/weaveapi/atc/v1/run.pb.d.ts +71 -0
- package/dist/weaveapi/atc/v1/run.pb.js +525 -0
- package/dist/weaveapi/atc/v1/service.pb.d.ts +339 -0
- package/dist/weaveapi/atc/v1/service.pb.js +1922 -0
- package/dist/weaveapi/auth/v1/service.pb.d.ts +66 -66
- package/dist/weaveapi/auth/v1/service.pb.js +86 -5
- package/dist/weaveapi/auth/v1/session.pb.js +1 -1
- package/dist/weaveapi/auth/v1/usage.pb.js +1 -1
- package/dist/weaveapi/auth/v1/user.pb.js +1 -1
- package/dist/weaveapi/data/v1/data.pb.js +1 -1
- package/dist/weaveapi/data/v1/service.pb.d.ts +27 -27
- package/dist/weaveapi/data/v1/service.pb.js +1 -1
- package/dist/weaveapi/generate/v1/configuration.pb.js +1 -1
- package/dist/weaveapi/generate/v1/generate.pb.js +1 -1
- package/dist/weaveapi/generate/v1/service.pb.d.ts +15 -15
- package/dist/weaveapi/generate/v1/service.pb.js +1 -1
- package/dist/weaveapi/input/v1/input.pb.js +1 -1
- package/dist/weaveapi/input/v1/service.pb.d.ts +39 -39
- package/dist/weaveapi/input/v1/service.pb.js +1 -1
- package/dist/weaveapi/integration/v1/integration.pb.js +1 -1
- package/dist/weaveapi/integration/v1/service.pb.d.ts +30 -30
- package/dist/weaveapi/integration/v1/service.pb.js +1 -1
- package/dist/weaveapi/llmx/v1/architecture.pb.js +1 -1
- package/dist/weaveapi/llmx/v1/capabilities.pb.js +1 -1
- package/dist/weaveapi/llmx/v1/model.pb.js +1 -1
- package/dist/weaveapi/llmx/v1/pricing.pb.js +1 -1
- package/dist/weaveapi/llmx/v1/provider.pb.js +1 -1
- package/dist/weaveapi/llmx/v1/service.pb.d.ts +36 -36
- package/dist/weaveapi/llmx/v1/service.pb.js +51 -6
- package/dist/weaveapi/mcpregistry/v1/server.pb.js +1 -1
- package/dist/weaveapi/mcpregistry/v1/service.pb.d.ts +18 -18
- package/dist/weaveapi/mcpregistry/v1/service.pb.js +1 -1
- package/dist/weaveapi/payment/v1/invoice.pb.js +1 -1
- package/dist/weaveapi/payment/v1/service.pb.d.ts +57 -57
- package/dist/weaveapi/payment/v1/service.pb.js +1 -1
- package/dist/weaveapi/payment/v1/subscription.pb.js +1 -1
- package/dist/weaveapi/project/v1/project.pb.js +1 -1
- package/dist/weaveapi/project/v1/service.pb.d.ts +21 -21
- package/dist/weaveapi/project/v1/service.pb.js +26 -3
- package/dist/weaveapi/report/v1/report.pb.js +1 -1
- package/dist/weaveapi/report/v1/service.pb.d.ts +18 -18
- package/dist/weaveapi/report/v1/service.pb.js +1 -1
- package/dist/weaveapi/requirement/v1/requirement.pb.js +1 -1
- package/dist/weaveapi/requirement/v1/service.pb.d.ts +39 -39
- package/dist/weaveapi/requirement/v1/service.pb.js +1 -1
- package/dist/weaveapi/run/v1/run.pb.js +1 -1
- package/dist/weaveapi/run/v1/service.pb.d.ts +21 -21
- package/dist/weaveapi/run/v1/service.pb.js +1 -1
- package/dist/weaveapi/script/v1/script.pb.js +1 -1
- package/dist/weaveapi/script/v1/service.pb.d.ts +51 -51
- package/dist/weaveapi/script/v1/service.pb.js +1 -1
- package/dist/weaveapi/storage/v1/auth.pb.js +1 -1
- package/dist/weaveapi/storage/v1/nosql_database.pb.js +1 -1
- package/dist/weaveapi/storage/v1/object_store.pb.js +1 -1
- package/dist/weaveapi/storage/v1/service.pb.d.ts +12 -12
- package/dist/weaveapi/storage/v1/service.pb.js +1 -1
- package/dist/weaveapi/storage/v1/sql_database.pb.js +1 -1
- package/dist/weaveapi/storage/v1/storage.pb.js +1 -1
- package/dist/weaveapi/storage/v1/vcs.pb.js +1 -1
- package/dist/weaveapi/suite/v1/service.pb.d.ts +54 -54
- package/dist/weaveapi/suite/v1/service.pb.js +1 -1
- package/dist/weaveapi/suite/v1/suite.pb.js +1 -1
- package/dist/weaveapi/synthesize/v1/dataset.pb.js +1 -1
- package/dist/weaveapi/synthesize/v1/inline_data.pb.js +1 -1
- package/dist/weaveapi/synthesize/v1/relationship.pb.js +1 -1
- package/dist/weaveapi/synthesize/v1/service.pb.d.ts +12 -12
- package/dist/weaveapi/synthesize/v1/service.pb.js +22 -2
- package/dist/weaveapi/synthesize/v1/training.pb.js +1 -1
- package/dist/weaveapi/testcase/v1/service.pb.d.ts +51 -51
- package/dist/weaveapi/testcase/v1/service.pb.js +1 -1
- package/dist/weaveapi/testcase/v1/testcase.pb.js +1 -1
- package/dist/weaveapi/workflow/v1/service.pb.d.ts +27 -27
- package/dist/weaveapi/workflow/v1/service.pb.js +1 -1
- package/dist/weaveapi/workflow/v1/workflow.pb.js +1 -1
- package/dist/weaveapi/workflowdata/v1/service.pb.d.ts +27 -27
- package/dist/weaveapi/workflowdata/v1/service.pb.js +1 -1
- package/dist/weavesql/atcdb/event_sql.d.ts +91 -0
- package/dist/weavesql/atcdb/event_sql.js +181 -0
- package/dist/weavesql/atcdb/mailbox_sql.d.ts +43 -0
- package/dist/weavesql/atcdb/mailbox_sql.js +85 -0
- package/package.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const insertEventQuery = "-- name: InsertEvent :one\nINSERT INTO atc.events (\n id,\n tenant_id,\n run_id,\n sequence,\n type,\n data,\n causation_id,\n correlation_id\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8\n)\nRETURNING id, tenant_id, run_id, sequence, type, data, causation_id, correlation_id, occurred_at, transaction_id";
|
|
6
|
+
export interface InsertEventArgs {
|
|
7
|
+
id: string;
|
|
8
|
+
tenantId: string;
|
|
9
|
+
runId: string;
|
|
10
|
+
sequence: string;
|
|
11
|
+
type: string;
|
|
12
|
+
data: any | null;
|
|
13
|
+
causationId: string | null;
|
|
14
|
+
correlationId: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface InsertEventRow {
|
|
17
|
+
id: string;
|
|
18
|
+
tenantId: string;
|
|
19
|
+
runId: string;
|
|
20
|
+
sequence: string;
|
|
21
|
+
type: string;
|
|
22
|
+
data: any | null;
|
|
23
|
+
causationId: string | null;
|
|
24
|
+
correlationId: string | null;
|
|
25
|
+
occurredAt: Date;
|
|
26
|
+
transactionId: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function insertEvent(client: Client, args: InsertEventArgs): Promise<InsertEventRow | null>;
|
|
29
|
+
export declare const getCurrentVersionQuery = "-- name: GetCurrentVersion :one\nSELECT COALESCE(MAX(sequence), 0)::BIGINT AS version\nFROM atc.events\nWHERE tenant_id = $1\n AND run_id = $2";
|
|
30
|
+
export interface GetCurrentVersionArgs {
|
|
31
|
+
tenantId: string;
|
|
32
|
+
runId: string;
|
|
33
|
+
}
|
|
34
|
+
export interface GetCurrentVersionRow {
|
|
35
|
+
version: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function getCurrentVersion(client: Client, args: GetCurrentVersionArgs): Promise<GetCurrentVersionRow | null>;
|
|
38
|
+
export declare const loadEventsQuery = "-- name: LoadEvents :many\nSELECT\n id,\n tenant_id,\n run_id,\n sequence,\n type,\n data,\n causation_id,\n correlation_id,\n occurred_at\nFROM atc.events\nWHERE tenant_id = $1\n AND run_id = $2\n AND sequence > $3\n AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())\nORDER BY sequence ASC";
|
|
39
|
+
export interface LoadEventsArgs {
|
|
40
|
+
tenantId: string;
|
|
41
|
+
runId: string;
|
|
42
|
+
afterSequence: string;
|
|
43
|
+
}
|
|
44
|
+
export interface LoadEventsRow {
|
|
45
|
+
id: string;
|
|
46
|
+
tenantId: string;
|
|
47
|
+
runId: string;
|
|
48
|
+
sequence: string;
|
|
49
|
+
type: string;
|
|
50
|
+
data: any | null;
|
|
51
|
+
causationId: string | null;
|
|
52
|
+
correlationId: string | null;
|
|
53
|
+
occurredAt: Date;
|
|
54
|
+
}
|
|
55
|
+
export declare function loadEvents(client: Client, args: LoadEventsArgs): Promise<LoadEventsRow[]>;
|
|
56
|
+
export declare const loadAllEventsQuery = "-- name: LoadAllEvents :many\nSELECT\n id,\n tenant_id,\n run_id,\n sequence,\n type,\n data,\n causation_id,\n correlation_id,\n occurred_at\nFROM atc.events\nWHERE tenant_id = $1\n AND run_id = $2\n AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())\nORDER BY sequence ASC";
|
|
57
|
+
export interface LoadAllEventsArgs {
|
|
58
|
+
tenantId: string;
|
|
59
|
+
runId: string;
|
|
60
|
+
}
|
|
61
|
+
export interface LoadAllEventsRow {
|
|
62
|
+
id: string;
|
|
63
|
+
tenantId: string;
|
|
64
|
+
runId: string;
|
|
65
|
+
sequence: string;
|
|
66
|
+
type: string;
|
|
67
|
+
data: any | null;
|
|
68
|
+
causationId: string | null;
|
|
69
|
+
correlationId: string | null;
|
|
70
|
+
occurredAt: Date;
|
|
71
|
+
}
|
|
72
|
+
export declare function loadAllEvents(client: Client, args: LoadAllEventsArgs): Promise<LoadAllEventsRow[]>;
|
|
73
|
+
export declare const listEventsByTypeQuery = "-- name: ListEventsByType :many\nSELECT\n id,\n tenant_id,\n run_id,\n sequence,\n type,\n data,\n causation_id,\n correlation_id,\n occurred_at\nFROM atc.events\nWHERE tenant_id = $1\n AND run_id = $2\n AND type = $3\n AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())\nORDER BY sequence ASC";
|
|
74
|
+
export interface ListEventsByTypeArgs {
|
|
75
|
+
tenantId: string;
|
|
76
|
+
runId: string;
|
|
77
|
+
eventType: string;
|
|
78
|
+
}
|
|
79
|
+
export interface ListEventsByTypeRow {
|
|
80
|
+
id: string;
|
|
81
|
+
tenantId: string;
|
|
82
|
+
runId: string;
|
|
83
|
+
sequence: string;
|
|
84
|
+
type: string;
|
|
85
|
+
data: any | null;
|
|
86
|
+
causationId: string | null;
|
|
87
|
+
correlationId: string | null;
|
|
88
|
+
occurredAt: Date;
|
|
89
|
+
}
|
|
90
|
+
export declare function listEventsByType(client: Client, args: ListEventsByTypeArgs): Promise<ListEventsByTypeRow[]>;
|
|
91
|
+
export {};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listEventsByTypeQuery = exports.loadAllEventsQuery = exports.loadEventsQuery = exports.getCurrentVersionQuery = exports.insertEventQuery = void 0;
|
|
4
|
+
exports.insertEvent = insertEvent;
|
|
5
|
+
exports.getCurrentVersion = getCurrentVersion;
|
|
6
|
+
exports.loadEvents = loadEvents;
|
|
7
|
+
exports.loadAllEvents = loadAllEvents;
|
|
8
|
+
exports.listEventsByType = listEventsByType;
|
|
9
|
+
exports.insertEventQuery = `-- name: InsertEvent :one
|
|
10
|
+
INSERT INTO atc.events (
|
|
11
|
+
id,
|
|
12
|
+
tenant_id,
|
|
13
|
+
run_id,
|
|
14
|
+
sequence,
|
|
15
|
+
type,
|
|
16
|
+
data,
|
|
17
|
+
causation_id,
|
|
18
|
+
correlation_id
|
|
19
|
+
) VALUES (
|
|
20
|
+
$1,
|
|
21
|
+
$2,
|
|
22
|
+
$3,
|
|
23
|
+
$4,
|
|
24
|
+
$5,
|
|
25
|
+
$6,
|
|
26
|
+
$7,
|
|
27
|
+
$8
|
|
28
|
+
)
|
|
29
|
+
RETURNING id, tenant_id, run_id, sequence, type, data, causation_id, correlation_id, occurred_at, transaction_id`;
|
|
30
|
+
async function insertEvent(client, args) {
|
|
31
|
+
const result = await client.query({
|
|
32
|
+
text: exports.insertEventQuery,
|
|
33
|
+
values: [args.id, args.tenantId, args.runId, args.sequence, args.type, args.data, args.causationId, args.correlationId],
|
|
34
|
+
rowMode: "array"
|
|
35
|
+
});
|
|
36
|
+
if (result.rows.length !== 1) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const row = result.rows[0];
|
|
40
|
+
return {
|
|
41
|
+
id: row[0],
|
|
42
|
+
tenantId: row[1],
|
|
43
|
+
runId: row[2],
|
|
44
|
+
sequence: row[3],
|
|
45
|
+
type: row[4],
|
|
46
|
+
data: row[5],
|
|
47
|
+
causationId: row[6],
|
|
48
|
+
correlationId: row[7],
|
|
49
|
+
occurredAt: row[8],
|
|
50
|
+
transactionId: row[9]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.getCurrentVersionQuery = `-- name: GetCurrentVersion :one
|
|
54
|
+
SELECT COALESCE(MAX(sequence), 0)::BIGINT AS version
|
|
55
|
+
FROM atc.events
|
|
56
|
+
WHERE tenant_id = $1
|
|
57
|
+
AND run_id = $2`;
|
|
58
|
+
async function getCurrentVersion(client, args) {
|
|
59
|
+
const result = await client.query({
|
|
60
|
+
text: exports.getCurrentVersionQuery,
|
|
61
|
+
values: [args.tenantId, args.runId],
|
|
62
|
+
rowMode: "array"
|
|
63
|
+
});
|
|
64
|
+
if (result.rows.length !== 1) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const row = result.rows[0];
|
|
68
|
+
return {
|
|
69
|
+
version: row[0]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
exports.loadEventsQuery = `-- name: LoadEvents :many
|
|
73
|
+
SELECT
|
|
74
|
+
id,
|
|
75
|
+
tenant_id,
|
|
76
|
+
run_id,
|
|
77
|
+
sequence,
|
|
78
|
+
type,
|
|
79
|
+
data,
|
|
80
|
+
causation_id,
|
|
81
|
+
correlation_id,
|
|
82
|
+
occurred_at
|
|
83
|
+
FROM atc.events
|
|
84
|
+
WHERE tenant_id = $1
|
|
85
|
+
AND run_id = $2
|
|
86
|
+
AND sequence > $3
|
|
87
|
+
AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
|
|
88
|
+
ORDER BY sequence ASC`;
|
|
89
|
+
async function loadEvents(client, args) {
|
|
90
|
+
const result = await client.query({
|
|
91
|
+
text: exports.loadEventsQuery,
|
|
92
|
+
values: [args.tenantId, args.runId, args.afterSequence],
|
|
93
|
+
rowMode: "array"
|
|
94
|
+
});
|
|
95
|
+
return result.rows.map(row => {
|
|
96
|
+
return {
|
|
97
|
+
id: row[0],
|
|
98
|
+
tenantId: row[1],
|
|
99
|
+
runId: row[2],
|
|
100
|
+
sequence: row[3],
|
|
101
|
+
type: row[4],
|
|
102
|
+
data: row[5],
|
|
103
|
+
causationId: row[6],
|
|
104
|
+
correlationId: row[7],
|
|
105
|
+
occurredAt: row[8]
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
exports.loadAllEventsQuery = `-- name: LoadAllEvents :many
|
|
110
|
+
SELECT
|
|
111
|
+
id,
|
|
112
|
+
tenant_id,
|
|
113
|
+
run_id,
|
|
114
|
+
sequence,
|
|
115
|
+
type,
|
|
116
|
+
data,
|
|
117
|
+
causation_id,
|
|
118
|
+
correlation_id,
|
|
119
|
+
occurred_at
|
|
120
|
+
FROM atc.events
|
|
121
|
+
WHERE tenant_id = $1
|
|
122
|
+
AND run_id = $2
|
|
123
|
+
AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
|
|
124
|
+
ORDER BY sequence ASC`;
|
|
125
|
+
async function loadAllEvents(client, args) {
|
|
126
|
+
const result = await client.query({
|
|
127
|
+
text: exports.loadAllEventsQuery,
|
|
128
|
+
values: [args.tenantId, args.runId],
|
|
129
|
+
rowMode: "array"
|
|
130
|
+
});
|
|
131
|
+
return result.rows.map(row => {
|
|
132
|
+
return {
|
|
133
|
+
id: row[0],
|
|
134
|
+
tenantId: row[1],
|
|
135
|
+
runId: row[2],
|
|
136
|
+
sequence: row[3],
|
|
137
|
+
type: row[4],
|
|
138
|
+
data: row[5],
|
|
139
|
+
causationId: row[6],
|
|
140
|
+
correlationId: row[7],
|
|
141
|
+
occurredAt: row[8]
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
exports.listEventsByTypeQuery = `-- name: ListEventsByType :many
|
|
146
|
+
SELECT
|
|
147
|
+
id,
|
|
148
|
+
tenant_id,
|
|
149
|
+
run_id,
|
|
150
|
+
sequence,
|
|
151
|
+
type,
|
|
152
|
+
data,
|
|
153
|
+
causation_id,
|
|
154
|
+
correlation_id,
|
|
155
|
+
occurred_at
|
|
156
|
+
FROM atc.events
|
|
157
|
+
WHERE tenant_id = $1
|
|
158
|
+
AND run_id = $2
|
|
159
|
+
AND type = $3
|
|
160
|
+
AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
|
|
161
|
+
ORDER BY sequence ASC`;
|
|
162
|
+
async function listEventsByType(client, args) {
|
|
163
|
+
const result = await client.query({
|
|
164
|
+
text: exports.listEventsByTypeQuery,
|
|
165
|
+
values: [args.tenantId, args.runId, args.eventType],
|
|
166
|
+
rowMode: "array"
|
|
167
|
+
});
|
|
168
|
+
return result.rows.map(row => {
|
|
169
|
+
return {
|
|
170
|
+
id: row[0],
|
|
171
|
+
tenantId: row[1],
|
|
172
|
+
runId: row[2],
|
|
173
|
+
sequence: row[3],
|
|
174
|
+
type: row[4],
|
|
175
|
+
data: row[5],
|
|
176
|
+
causationId: row[6],
|
|
177
|
+
correlationId: row[7],
|
|
178
|
+
occurredAt: row[8]
|
|
179
|
+
};
|
|
180
|
+
});
|
|
181
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const ensureMailboxCursorQuery = "-- name: EnsureMailboxCursor :exec\nINSERT INTO atc.mailbox_cursors (tenant_id, process_id)\nVALUES ($1, $2)\nON CONFLICT (tenant_id, process_id) DO NOTHING";
|
|
6
|
+
export interface EnsureMailboxCursorArgs {
|
|
7
|
+
tenantId: string;
|
|
8
|
+
processId: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function ensureMailboxCursor(client: Client, args: EnsureMailboxCursorArgs): Promise<void>;
|
|
11
|
+
export declare const lockMailboxCursorQuery = "-- name: LockMailboxCursor :one\nSELECT\n last_acked_sequence,\n last_processed_transaction_id::text AS last_processed_transaction_id\nFROM atc.mailbox_cursors\nWHERE tenant_id = $1\n AND process_id = $2\nFOR UPDATE";
|
|
12
|
+
export interface LockMailboxCursorArgs {
|
|
13
|
+
tenantId: string;
|
|
14
|
+
processId: string;
|
|
15
|
+
}
|
|
16
|
+
export interface LockMailboxCursorRow {
|
|
17
|
+
lastAckedSequence: string;
|
|
18
|
+
lastProcessedTransactionId: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function lockMailboxCursor(client: Client, args: LockMailboxCursorArgs): Promise<LockMailboxCursorRow | null>;
|
|
21
|
+
export declare const readMailboxQuery = "-- name: ReadMailbox :many\nSELECT\n sequence,\n transaction_id::text AS transaction_id,\n data\nFROM atc.events\nWHERE tenant_id = $1\n AND data->>'to' = $2\n AND data->>'category' IN ('protocol', 'semantic')\n AND (\n sequence > $3\n OR (sequence = $3 AND transaction_id > $4::xid8)\n )\n AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())\nORDER BY sequence ASC\nLIMIT $5";
|
|
22
|
+
export interface ReadMailboxArgs {
|
|
23
|
+
tenantId: string;
|
|
24
|
+
processId: any | null;
|
|
25
|
+
afterSequence: string;
|
|
26
|
+
afterTransactionId: string;
|
|
27
|
+
batchLimit: string;
|
|
28
|
+
}
|
|
29
|
+
export interface ReadMailboxRow {
|
|
30
|
+
sequence: string;
|
|
31
|
+
transactionId: string;
|
|
32
|
+
data: any | null;
|
|
33
|
+
}
|
|
34
|
+
export declare function readMailbox(client: Client, args: ReadMailboxArgs): Promise<ReadMailboxRow[]>;
|
|
35
|
+
export declare const acknowledgeMailboxQuery = "-- name: AcknowledgeMailbox :exec\nUPDATE atc.mailbox_cursors\nSET\n last_acked_sequence = $1,\n last_processed_transaction_id = $2::xid8\nWHERE tenant_id = $3\n AND process_id = $4";
|
|
36
|
+
export interface AcknowledgeMailboxArgs {
|
|
37
|
+
lastSequence: string;
|
|
38
|
+
lastTransactionId: string;
|
|
39
|
+
tenantId: string;
|
|
40
|
+
processId: string;
|
|
41
|
+
}
|
|
42
|
+
export declare function acknowledgeMailbox(client: Client, args: AcknowledgeMailboxArgs): Promise<void>;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.acknowledgeMailboxQuery = exports.readMailboxQuery = exports.lockMailboxCursorQuery = exports.ensureMailboxCursorQuery = void 0;
|
|
4
|
+
exports.ensureMailboxCursor = ensureMailboxCursor;
|
|
5
|
+
exports.lockMailboxCursor = lockMailboxCursor;
|
|
6
|
+
exports.readMailbox = readMailbox;
|
|
7
|
+
exports.acknowledgeMailbox = acknowledgeMailbox;
|
|
8
|
+
exports.ensureMailboxCursorQuery = `-- name: EnsureMailboxCursor :exec
|
|
9
|
+
INSERT INTO atc.mailbox_cursors (tenant_id, process_id)
|
|
10
|
+
VALUES ($1, $2)
|
|
11
|
+
ON CONFLICT (tenant_id, process_id) DO NOTHING`;
|
|
12
|
+
async function ensureMailboxCursor(client, args) {
|
|
13
|
+
await client.query({
|
|
14
|
+
text: exports.ensureMailboxCursorQuery,
|
|
15
|
+
values: [args.tenantId, args.processId],
|
|
16
|
+
rowMode: "array"
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.lockMailboxCursorQuery = `-- name: LockMailboxCursor :one
|
|
20
|
+
SELECT
|
|
21
|
+
last_acked_sequence,
|
|
22
|
+
last_processed_transaction_id::text AS last_processed_transaction_id
|
|
23
|
+
FROM atc.mailbox_cursors
|
|
24
|
+
WHERE tenant_id = $1
|
|
25
|
+
AND process_id = $2
|
|
26
|
+
FOR UPDATE`;
|
|
27
|
+
async function lockMailboxCursor(client, args) {
|
|
28
|
+
const result = await client.query({
|
|
29
|
+
text: exports.lockMailboxCursorQuery,
|
|
30
|
+
values: [args.tenantId, args.processId],
|
|
31
|
+
rowMode: "array"
|
|
32
|
+
});
|
|
33
|
+
if (result.rows.length !== 1) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const row = result.rows[0];
|
|
37
|
+
return {
|
|
38
|
+
lastAckedSequence: row[0],
|
|
39
|
+
lastProcessedTransactionId: row[1]
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.readMailboxQuery = `-- name: ReadMailbox :many
|
|
43
|
+
SELECT
|
|
44
|
+
sequence,
|
|
45
|
+
transaction_id::text AS transaction_id,
|
|
46
|
+
data
|
|
47
|
+
FROM atc.events
|
|
48
|
+
WHERE tenant_id = $1
|
|
49
|
+
AND data->>'to' = $2
|
|
50
|
+
AND data->>'category' IN ('protocol', 'semantic')
|
|
51
|
+
AND (
|
|
52
|
+
sequence > $3
|
|
53
|
+
OR (sequence = $3 AND transaction_id > $4::xid8)
|
|
54
|
+
)
|
|
55
|
+
AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
|
|
56
|
+
ORDER BY sequence ASC
|
|
57
|
+
LIMIT $5`;
|
|
58
|
+
async function readMailbox(client, args) {
|
|
59
|
+
const result = await client.query({
|
|
60
|
+
text: exports.readMailboxQuery,
|
|
61
|
+
values: [args.tenantId, args.processId, args.afterSequence, args.afterTransactionId, args.batchLimit],
|
|
62
|
+
rowMode: "array"
|
|
63
|
+
});
|
|
64
|
+
return result.rows.map(row => {
|
|
65
|
+
return {
|
|
66
|
+
sequence: row[0],
|
|
67
|
+
transactionId: row[1],
|
|
68
|
+
data: row[2]
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
exports.acknowledgeMailboxQuery = `-- name: AcknowledgeMailbox :exec
|
|
73
|
+
UPDATE atc.mailbox_cursors
|
|
74
|
+
SET
|
|
75
|
+
last_acked_sequence = $1,
|
|
76
|
+
last_processed_transaction_id = $2::xid8
|
|
77
|
+
WHERE tenant_id = $3
|
|
78
|
+
AND process_id = $4`;
|
|
79
|
+
async function acknowledgeMailbox(client, args) {
|
|
80
|
+
await client.query({
|
|
81
|
+
text: exports.acknowledgeMailboxQuery,
|
|
82
|
+
values: [args.lastSequence, args.lastTransactionId, args.tenantId, args.processId],
|
|
83
|
+
rowMode: "array"
|
|
84
|
+
});
|
|
85
|
+
}
|