weave-typescript 0.51.3 → 0.53.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/protobuf/duration.pb.d.ts +99 -0
- package/dist/google/protobuf/duration.pb.js +93 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/weave/authz/v1/index.d.ts +1 -0
- package/dist/weave/authz/v1/index.js +38 -0
- package/dist/weave/authz/v1/options.pb.d.ts +52 -0
- package/dist/weave/authz/v1/options.pb.js +403 -0
- package/dist/weave/filter/v1/index.d.ts +1 -0
- package/dist/weave/filter/v1/index.js +38 -0
- package/dist/{weaveapi/atc/v1/message.pb.d.ts → weave/filter/v1/options.pb.d.ts} +33 -21
- package/dist/weave/filter/v1/options.pb.js +417 -0
- package/dist/weave/index.d.ts +2 -0
- package/dist/weave/index.js +39 -0
- package/dist/weaveapi/agent/v1/agent.pb.d.ts +137 -188
- package/dist/weaveapi/agent/v1/agent.pb.js +891 -2151
- package/dist/weaveapi/agent/v1/index.d.ts +1 -1
- package/dist/weaveapi/agent/v1/index.js +2 -2
- package/dist/weaveapi/agent/v1/run.pb.d.ts +289 -0
- package/dist/weaveapi/agent/v1/run.pb.js +2763 -0
- package/dist/weaveapi/auth/v1/auth.pb.d.ts +67 -14
- package/dist/weaveapi/auth/v1/auth.pb.js +829 -89
- package/dist/weaveapi/auth/v1/index.d.ts +4 -1
- package/dist/weaveapi/auth/v1/index.js +5 -2
- package/dist/weaveapi/auth/v1/{service.pb.d.ts → organization_admin.pb.d.ts} +39 -530
- package/dist/weaveapi/auth/v1/{service.pb.js → organization_admin.pb.js} +2978 -5812
- package/dist/weaveapi/auth/v1/personal_access_token.pb.d.ts +114 -0
- package/dist/weaveapi/auth/v1/personal_access_token.pb.js +750 -0
- package/dist/weaveapi/auth/v1/profile.pb.d.ts +161 -0
- package/dist/weaveapi/auth/v1/profile.pb.js +1007 -0
- package/dist/weaveapi/auth/v1/session.pb.d.ts +460 -0
- package/dist/weaveapi/auth/v1/session.pb.js +3544 -0
- package/dist/weaveapi/chat/v1/chat.pb.d.ts +377 -149
- package/dist/weaveapi/chat/v1/chat.pb.js +3492 -1614
- package/dist/weaveapi/chat/v1/index.d.ts +0 -1
- package/dist/weaveapi/chat/v1/index.js +1 -2
- package/dist/weaveapi/consolidation/v1/consolidation.pb.d.ts +95 -0
- package/dist/weaveapi/consolidation/v1/consolidation.pb.js +770 -1
- package/dist/weaveapi/consolidation/v1/index.d.ts +0 -1
- package/dist/weaveapi/consolidation/v1/index.js +1 -2
- package/dist/weaveapi/content/v1/content.pb.d.ts +63 -0
- package/dist/weaveapi/content/v1/content.pb.js +470 -0
- package/dist/weaveapi/content/v1/index.d.ts +1 -0
- package/dist/weaveapi/content/v1/index.js +38 -0
- package/dist/weaveapi/gateway/v1/gateway.pb.d.ts +247 -523
- package/dist/weaveapi/gateway/v1/gateway.pb.js +1648 -5783
- package/dist/weaveapi/gateway/v1/index.d.ts +0 -1
- package/dist/weaveapi/gateway/v1/index.js +1 -2
- package/dist/weaveapi/index.d.ts +5 -5
- package/dist/weaveapi/index.js +6 -6
- package/dist/weaveapi/inference/v1/generate.pb.d.ts +120 -0
- package/dist/weaveapi/inference/v1/generate.pb.js +1159 -0
- package/dist/weaveapi/inference/v1/index.d.ts +4 -0
- package/dist/weaveapi/{provider → inference}/v1/index.js +4 -2
- package/dist/weaveapi/{model → inference}/v1/model.pb.d.ts +54 -15
- package/dist/weaveapi/{model → inference}/v1/model.pb.js +573 -116
- package/dist/weaveapi/{model/v1/service.pb.d.ts → inference/v1/model_route.pb.d.ts} +184 -110
- package/dist/weaveapi/{model/v1/service.pb.js → inference/v1/model_route.pb.js} +2240 -1061
- package/dist/weaveapi/inference/v1/provider.pb.d.ts +264 -0
- package/dist/weaveapi/inference/v1/provider.pb.js +2590 -0
- package/dist/weaveapi/ingestion/v1/index.d.ts +0 -2
- package/dist/weaveapi/ingestion/v1/index.js +1 -3
- package/dist/weaveapi/ingestion/v1/ingestion.pb.d.ts +543 -0
- package/dist/weaveapi/ingestion/v1/ingestion.pb.js +5550 -16
- package/dist/weaveapi/initialization/v1/index.d.ts +1 -0
- package/dist/weaveapi/initialization/v1/index.js +38 -0
- package/dist/weaveapi/initialization/v1/initialization.pb.d.ts +99 -0
- package/dist/weaveapi/initialization/v1/initialization.pb.js +510 -0
- package/dist/weaveapi/organization/v1/index.d.ts +0 -1
- package/dist/weaveapi/organization/v1/index.js +1 -2
- package/dist/weaveapi/organization/v1/organization.pb.d.ts +241 -0
- package/dist/weaveapi/organization/v1/organization.pb.js +1838 -1
- package/dist/weaveapi/reporting/index.d.ts +1 -0
- package/dist/weaveapi/reporting/index.js +38 -0
- package/dist/weaveapi/{task → reporting}/v1/index.d.ts +1 -1
- package/dist/weaveapi/{model → reporting}/v1/index.js +2 -2
- package/dist/weaveapi/reporting/v1/service.pb.d.ts +38 -0
- package/dist/weaveapi/reporting/v1/service.pb.js +167 -0
- package/dist/weaveapi/reporting/v1/usage.pb.d.ts +150 -0
- package/dist/weaveapi/reporting/v1/usage.pb.js +1837 -0
- package/dist/weaveapi/retrieval/v1/index.d.ts +0 -1
- package/dist/weaveapi/retrieval/v1/index.js +1 -2
- package/dist/weaveapi/retrieval/v1/retrieval.pb.d.ts +96 -2
- package/dist/weaveapi/retrieval/v1/retrieval.pb.js +690 -10
- package/dist/weaveapi/tool/index.d.ts +1 -0
- package/dist/weaveapi/tool/index.js +38 -0
- package/dist/weaveapi/tool/v1/index.d.ts +1 -0
- package/dist/weaveapi/tool/v1/index.js +38 -0
- package/dist/weaveapi/tool/v1/tool.pb.d.ts +370 -0
- package/dist/weaveapi/tool/v1/tool.pb.js +2717 -0
- package/dist/weaveapi/workflow/v1/index.d.ts +1 -1
- package/dist/weaveapi/workflow/v1/index.js +2 -2
- package/dist/weaveapi/workflow/v1/run.pb.d.ts +244 -0
- package/dist/weaveapi/workflow/v1/run.pb.js +2084 -0
- package/dist/weaveapi/workflow/v1/workflow.pb.d.ts +122 -275
- package/dist/weaveapi/workflow/v1/workflow.pb.js +790 -3261
- package/dist/weavesql/weavedb/agent_sql.d.ts +173 -477
- package/dist/weavesql/weavedb/agent_sql.js +281 -758
- package/dist/weavesql/weavedb/authorization_outbox_sql.d.ts +261 -0
- package/dist/weavesql/weavedb/authorization_outbox_sql.js +445 -0
- package/dist/weavesql/weavedb/chat_sql.d.ts +103 -345
- package/dist/weavesql/weavedb/chat_sql.js +312 -597
- package/dist/weavesql/weavedb/document_consolidation_sql.d.ts +217 -0
- package/dist/weavesql/weavedb/document_consolidation_sql.js +486 -0
- package/dist/weavesql/weavedb/document_ingestion_sql.d.ts +1433 -0
- package/dist/weavesql/weavedb/document_ingestion_sql.js +3488 -0
- package/dist/weavesql/weavedb/document_retrieval_sql.d.ts +314 -0
- package/dist/weavesql/weavedb/document_retrieval_sql.js +965 -0
- package/dist/weavesql/weavedb/document_table_sql.d.ts +6 -6
- package/dist/weavesql/weavedb/document_table_sql.js +12 -12
- package/dist/weavesql/weavedb/identity_sql.d.ts +1021 -0
- package/dist/weavesql/weavedb/identity_sql.js +1818 -0
- package/dist/weavesql/weavedb/inference_model_route_sql.d.ts +167 -0
- package/dist/weavesql/weavedb/inference_model_route_sql.js +483 -0
- package/dist/weavesql/weavedb/inference_provider_sql.d.ts +125 -0
- package/dist/weavesql/weavedb/inference_provider_sql.js +228 -0
- package/dist/weavesql/weavedb/initialization_sql.d.ts +15 -0
- package/dist/weavesql/weavedb/initialization_sql.js +33 -0
- package/dist/weavesql/weavedb/model_catalog_sql.d.ts +6 -6
- package/dist/weavesql/weavedb/model_catalog_sql.js +6 -6
- package/dist/weavesql/weavedb/organization_sql.d.ts +24 -102
- package/dist/weavesql/weavedb/organization_sql.js +56 -262
- package/dist/weavesql/weavedb/tool_sql.d.ts +209 -0
- package/dist/weavesql/weavedb/tool_sql.js +407 -0
- package/dist/weavesql/weavedb/usage_sql.d.ts +356 -0
- package/dist/weavesql/weavedb/usage_sql.js +568 -0
- package/dist/weavesql/weavedb/workflow_sql.d.ts +159 -546
- package/dist/weavesql/weavedb/workflow_sql.js +281 -909
- package/package.json +1 -1
- package/dist/weaveapi/agent/v1/service.pb.d.ts +0 -397
- package/dist/weaveapi/agent/v1/service.pb.js +0 -3152
- package/dist/weaveapi/atc/v1/event.pb.d.ts +0 -134
- package/dist/weaveapi/atc/v1/event.pb.js +0 -1124
- package/dist/weaveapi/atc/v1/index.d.ts +0 -5
- package/dist/weaveapi/atc/v1/index.js +0 -42
- package/dist/weaveapi/atc/v1/message.pb.js +0 -287
- package/dist/weaveapi/atc/v1/process.pb.d.ts +0 -91
- package/dist/weaveapi/atc/v1/process.pb.js +0 -658
- package/dist/weaveapi/atc/v1/run.pb.d.ts +0 -71
- package/dist/weaveapi/atc/v1/run.pb.js +0 -525
- package/dist/weaveapi/atc/v1/service.pb.d.ts +0 -472
- package/dist/weaveapi/atc/v1/service.pb.js +0 -3093
- package/dist/weaveapi/chat/v1/service.pb.d.ts +0 -345
- package/dist/weaveapi/chat/v1/service.pb.js +0 -2545
- package/dist/weaveapi/consolidation/v1/service.pb.d.ts +0 -93
- package/dist/weaveapi/consolidation/v1/service.pb.js +0 -427
- package/dist/weaveapi/gateway/v1/service.pb.d.ts +0 -235
- package/dist/weaveapi/gateway/v1/service.pb.js +0 -651
- package/dist/weaveapi/ingestion/v1/service.pb.d.ts +0 -420
- package/dist/weaveapi/ingestion/v1/service.pb.js +0 -2311
- package/dist/weaveapi/ingestion/v1/table.pb.d.ts +0 -121
- package/dist/weaveapi/ingestion/v1/table.pb.js +0 -1478
- package/dist/weaveapi/model/v1/index.d.ts +0 -2
- package/dist/weaveapi/organization/v1/service.pb.d.ts +0 -261
- package/dist/weaveapi/organization/v1/service.pb.js +0 -1561
- package/dist/weaveapi/project/v1/index.d.ts +0 -2
- package/dist/weaveapi/project/v1/index.js +0 -39
- package/dist/weaveapi/project/v1/project.pb.d.ts +0 -105
- package/dist/weaveapi/project/v1/project.pb.js +0 -1004
- package/dist/weaveapi/project/v1/service.pb.d.ts +0 -247
- package/dist/weaveapi/project/v1/service.pb.js +0 -1994
- package/dist/weaveapi/provider/v1/index.d.ts +0 -2
- package/dist/weaveapi/provider/v1/provider.pb.d.ts +0 -137
- package/dist/weaveapi/provider/v1/provider.pb.js +0 -1000
- package/dist/weaveapi/provider/v1/service.pb.d.ts +0 -223
- package/dist/weaveapi/provider/v1/service.pb.js +0 -1888
- package/dist/weaveapi/retrieval/v1/service.pb.d.ts +0 -93
- package/dist/weaveapi/retrieval/v1/service.pb.js +0 -385
- package/dist/weaveapi/task/v1/index.js +0 -39
- package/dist/weaveapi/task/v1/service.pb.d.ts +0 -172
- package/dist/weaveapi/task/v1/service.pb.js +0 -1436
- package/dist/weaveapi/task/v1/task.pb.d.ts +0 -85
- package/dist/weaveapi/task/v1/task.pb.js +0 -802
- package/dist/weaveapi/workflow/v1/service.pb.d.ts +0 -392
- package/dist/weaveapi/workflow/v1/service.pb.js +0 -3146
- /package/dist/{weaveapi/atc → weave/authz}/index.d.ts +0 -0
- /package/dist/{weaveapi/atc → weave/authz}/index.js +0 -0
- /package/dist/{weaveapi/model → weave/filter}/index.d.ts +0 -0
- /package/dist/{weaveapi/model → weave/filter}/index.js +0 -0
- /package/dist/weaveapi/{project → content}/index.d.ts +0 -0
- /package/dist/weaveapi/{project → content}/index.js +0 -0
- /package/dist/weaveapi/{provider → inference}/index.d.ts +0 -0
- /package/dist/weaveapi/{provider → inference}/index.js +0 -0
- /package/dist/weaveapi/{task → initialization}/index.d.ts +0 -0
- /package/dist/weaveapi/{task → initialization}/index.js +0 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.revokeAuthorizationGrantByTupleQuery = exports.revokeAuthorizationGrantQuery = exports.listAuthorizationGrantsForObjectQuery = exports.listAuthorizationGrantsForSubjectQuery = exports.getAuthorizationGrantQuery = exports.createAuthorizationGrantQuery = exports.requeueStaleAuthorizationOutboxEntriesQuery = exports.failAuthorizationOutboxEntryQuery = exports.completeAuthorizationOutboxEntryQuery = exports.claimAuthorizationOutboxEntriesByIDQuery = exports.claimAuthorizationOutboxEntriesQuery = exports.createAuthorizationOutboxEntryQuery = void 0;
|
|
4
|
+
exports.createAuthorizationOutboxEntry = createAuthorizationOutboxEntry;
|
|
5
|
+
exports.claimAuthorizationOutboxEntries = claimAuthorizationOutboxEntries;
|
|
6
|
+
exports.claimAuthorizationOutboxEntriesByID = claimAuthorizationOutboxEntriesByID;
|
|
7
|
+
exports.completeAuthorizationOutboxEntry = completeAuthorizationOutboxEntry;
|
|
8
|
+
exports.failAuthorizationOutboxEntry = failAuthorizationOutboxEntry;
|
|
9
|
+
exports.requeueStaleAuthorizationOutboxEntries = requeueStaleAuthorizationOutboxEntries;
|
|
10
|
+
exports.createAuthorizationGrant = createAuthorizationGrant;
|
|
11
|
+
exports.getAuthorizationGrant = getAuthorizationGrant;
|
|
12
|
+
exports.listAuthorizationGrantsForSubject = listAuthorizationGrantsForSubject;
|
|
13
|
+
exports.listAuthorizationGrantsForObject = listAuthorizationGrantsForObject;
|
|
14
|
+
exports.revokeAuthorizationGrant = revokeAuthorizationGrant;
|
|
15
|
+
exports.revokeAuthorizationGrantByTuple = revokeAuthorizationGrantByTuple;
|
|
16
|
+
exports.createAuthorizationOutboxEntryQuery = `-- name: CreateAuthorizationOutboxEntry :one
|
|
17
|
+
INSERT INTO weave.authorization_outbox (
|
|
18
|
+
organization_id,
|
|
19
|
+
operation,
|
|
20
|
+
tuple_user,
|
|
21
|
+
tuple_relation,
|
|
22
|
+
tuple_object
|
|
23
|
+
) VALUES (
|
|
24
|
+
$1,
|
|
25
|
+
$2,
|
|
26
|
+
$3,
|
|
27
|
+
$4,
|
|
28
|
+
$5
|
|
29
|
+
)
|
|
30
|
+
RETURNING id, organization_id, operation, tuple_user, tuple_relation, tuple_object, status, attempt_count, next_attempt_at, last_error, processed_at, created_at, updated_at`;
|
|
31
|
+
async function createAuthorizationOutboxEntry(client, args) {
|
|
32
|
+
const result = await client.query({
|
|
33
|
+
text: exports.createAuthorizationOutboxEntryQuery,
|
|
34
|
+
values: [args.organizationId, args.operation, args.tupleUser, args.tupleRelation, args.tupleObject],
|
|
35
|
+
rowMode: "array"
|
|
36
|
+
});
|
|
37
|
+
if (result.rows.length !== 1) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const row = result.rows[0];
|
|
41
|
+
return {
|
|
42
|
+
id: row[0],
|
|
43
|
+
organizationId: row[1],
|
|
44
|
+
operation: row[2],
|
|
45
|
+
tupleUser: row[3],
|
|
46
|
+
tupleRelation: row[4],
|
|
47
|
+
tupleObject: row[5],
|
|
48
|
+
status: row[6],
|
|
49
|
+
attemptCount: row[7],
|
|
50
|
+
nextAttemptAt: row[8],
|
|
51
|
+
lastError: row[9],
|
|
52
|
+
processedAt: row[10],
|
|
53
|
+
createdAt: row[11],
|
|
54
|
+
updatedAt: row[12]
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.claimAuthorizationOutboxEntriesQuery = `-- name: ClaimAuthorizationOutboxEntries :many
|
|
58
|
+
WITH claimable AS (
|
|
59
|
+
SELECT id
|
|
60
|
+
FROM weave.authorization_outbox
|
|
61
|
+
WHERE status IN ('pending', 'failed')
|
|
62
|
+
AND next_attempt_at <= now()
|
|
63
|
+
ORDER BY next_attempt_at ASC, created_at ASC, id ASC
|
|
64
|
+
LIMIT $1
|
|
65
|
+
FOR UPDATE SKIP LOCKED
|
|
66
|
+
)
|
|
67
|
+
UPDATE weave.authorization_outbox ao
|
|
68
|
+
SET status = 'processing',
|
|
69
|
+
attempt_count = ao.attempt_count + 1,
|
|
70
|
+
last_error = ''
|
|
71
|
+
FROM claimable
|
|
72
|
+
WHERE ao.id = claimable.id
|
|
73
|
+
RETURNING ao.id, ao.organization_id, ao.operation, ao.tuple_user, ao.tuple_relation, ao.tuple_object, ao.status, ao.attempt_count, ao.next_attempt_at, ao.last_error, ao.processed_at, ao.created_at, ao.updated_at`;
|
|
74
|
+
async function claimAuthorizationOutboxEntries(client, args) {
|
|
75
|
+
const result = await client.query({
|
|
76
|
+
text: exports.claimAuthorizationOutboxEntriesQuery,
|
|
77
|
+
values: [args.limitCount],
|
|
78
|
+
rowMode: "array"
|
|
79
|
+
});
|
|
80
|
+
return result.rows.map(row => {
|
|
81
|
+
return {
|
|
82
|
+
id: row[0],
|
|
83
|
+
organizationId: row[1],
|
|
84
|
+
operation: row[2],
|
|
85
|
+
tupleUser: row[3],
|
|
86
|
+
tupleRelation: row[4],
|
|
87
|
+
tupleObject: row[5],
|
|
88
|
+
status: row[6],
|
|
89
|
+
attemptCount: row[7],
|
|
90
|
+
nextAttemptAt: row[8],
|
|
91
|
+
lastError: row[9],
|
|
92
|
+
processedAt: row[10],
|
|
93
|
+
createdAt: row[11],
|
|
94
|
+
updatedAt: row[12]
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.claimAuthorizationOutboxEntriesByIDQuery = `-- name: ClaimAuthorizationOutboxEntriesByID :many
|
|
99
|
+
WITH claimable AS (
|
|
100
|
+
SELECT id
|
|
101
|
+
FROM weave.authorization_outbox
|
|
102
|
+
WHERE id = ANY($1::uuid[])
|
|
103
|
+
AND status IN ('pending', 'failed')
|
|
104
|
+
AND next_attempt_at <= now()
|
|
105
|
+
ORDER BY created_at ASC, id ASC
|
|
106
|
+
FOR UPDATE SKIP LOCKED
|
|
107
|
+
)
|
|
108
|
+
UPDATE weave.authorization_outbox ao
|
|
109
|
+
SET status = 'processing',
|
|
110
|
+
attempt_count = ao.attempt_count + 1,
|
|
111
|
+
last_error = ''
|
|
112
|
+
FROM claimable
|
|
113
|
+
WHERE ao.id = claimable.id
|
|
114
|
+
RETURNING ao.id, ao.organization_id, ao.operation, ao.tuple_user, ao.tuple_relation, ao.tuple_object, ao.status, ao.attempt_count, ao.next_attempt_at, ao.last_error, ao.processed_at, ao.created_at, ao.updated_at`;
|
|
115
|
+
async function claimAuthorizationOutboxEntriesByID(client, args) {
|
|
116
|
+
const result = await client.query({
|
|
117
|
+
text: exports.claimAuthorizationOutboxEntriesByIDQuery,
|
|
118
|
+
values: [args.authorizationOutboxIds],
|
|
119
|
+
rowMode: "array"
|
|
120
|
+
});
|
|
121
|
+
return result.rows.map(row => {
|
|
122
|
+
return {
|
|
123
|
+
id: row[0],
|
|
124
|
+
organizationId: row[1],
|
|
125
|
+
operation: row[2],
|
|
126
|
+
tupleUser: row[3],
|
|
127
|
+
tupleRelation: row[4],
|
|
128
|
+
tupleObject: row[5],
|
|
129
|
+
status: row[6],
|
|
130
|
+
attemptCount: row[7],
|
|
131
|
+
nextAttemptAt: row[8],
|
|
132
|
+
lastError: row[9],
|
|
133
|
+
processedAt: row[10],
|
|
134
|
+
createdAt: row[11],
|
|
135
|
+
updatedAt: row[12]
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
exports.completeAuthorizationOutboxEntryQuery = `-- name: CompleteAuthorizationOutboxEntry :one
|
|
140
|
+
UPDATE weave.authorization_outbox
|
|
141
|
+
SET status = 'completed',
|
|
142
|
+
last_error = '',
|
|
143
|
+
processed_at = now()
|
|
144
|
+
WHERE id = $1
|
|
145
|
+
AND status = 'processing'
|
|
146
|
+
RETURNING id, organization_id, operation, tuple_user, tuple_relation, tuple_object, status, attempt_count, next_attempt_at, last_error, processed_at, created_at, updated_at`;
|
|
147
|
+
async function completeAuthorizationOutboxEntry(client, args) {
|
|
148
|
+
const result = await client.query({
|
|
149
|
+
text: exports.completeAuthorizationOutboxEntryQuery,
|
|
150
|
+
values: [args.authorizationOutboxId],
|
|
151
|
+
rowMode: "array"
|
|
152
|
+
});
|
|
153
|
+
if (result.rows.length !== 1) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const row = result.rows[0];
|
|
157
|
+
return {
|
|
158
|
+
id: row[0],
|
|
159
|
+
organizationId: row[1],
|
|
160
|
+
operation: row[2],
|
|
161
|
+
tupleUser: row[3],
|
|
162
|
+
tupleRelation: row[4],
|
|
163
|
+
tupleObject: row[5],
|
|
164
|
+
status: row[6],
|
|
165
|
+
attemptCount: row[7],
|
|
166
|
+
nextAttemptAt: row[8],
|
|
167
|
+
lastError: row[9],
|
|
168
|
+
processedAt: row[10],
|
|
169
|
+
createdAt: row[11],
|
|
170
|
+
updatedAt: row[12]
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
exports.failAuthorizationOutboxEntryQuery = `-- name: FailAuthorizationOutboxEntry :one
|
|
174
|
+
UPDATE weave.authorization_outbox
|
|
175
|
+
SET status = 'failed',
|
|
176
|
+
last_error = $1,
|
|
177
|
+
next_attempt_at = $2,
|
|
178
|
+
processed_at = NULL
|
|
179
|
+
WHERE id = $3
|
|
180
|
+
AND status = 'processing'
|
|
181
|
+
RETURNING id, organization_id, operation, tuple_user, tuple_relation, tuple_object, status, attempt_count, next_attempt_at, last_error, processed_at, created_at, updated_at`;
|
|
182
|
+
async function failAuthorizationOutboxEntry(client, args) {
|
|
183
|
+
const result = await client.query({
|
|
184
|
+
text: exports.failAuthorizationOutboxEntryQuery,
|
|
185
|
+
values: [args.lastError, args.nextAttemptAt, args.authorizationOutboxId],
|
|
186
|
+
rowMode: "array"
|
|
187
|
+
});
|
|
188
|
+
if (result.rows.length !== 1) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const row = result.rows[0];
|
|
192
|
+
return {
|
|
193
|
+
id: row[0],
|
|
194
|
+
organizationId: row[1],
|
|
195
|
+
operation: row[2],
|
|
196
|
+
tupleUser: row[3],
|
|
197
|
+
tupleRelation: row[4],
|
|
198
|
+
tupleObject: row[5],
|
|
199
|
+
status: row[6],
|
|
200
|
+
attemptCount: row[7],
|
|
201
|
+
nextAttemptAt: row[8],
|
|
202
|
+
lastError: row[9],
|
|
203
|
+
processedAt: row[10],
|
|
204
|
+
createdAt: row[11],
|
|
205
|
+
updatedAt: row[12]
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
exports.requeueStaleAuthorizationOutboxEntriesQuery = `-- name: RequeueStaleAuthorizationOutboxEntries :many
|
|
209
|
+
UPDATE weave.authorization_outbox
|
|
210
|
+
SET status = 'failed',
|
|
211
|
+
last_error = COALESCE($1::text, last_error),
|
|
212
|
+
next_attempt_at = now(),
|
|
213
|
+
processed_at = NULL
|
|
214
|
+
WHERE status = 'processing'
|
|
215
|
+
AND updated_at < $2
|
|
216
|
+
RETURNING id, organization_id, operation, tuple_user, tuple_relation, tuple_object, status, attempt_count, next_attempt_at, last_error, processed_at, created_at, updated_at`;
|
|
217
|
+
async function requeueStaleAuthorizationOutboxEntries(client, args) {
|
|
218
|
+
const result = await client.query({
|
|
219
|
+
text: exports.requeueStaleAuthorizationOutboxEntriesQuery,
|
|
220
|
+
values: [args.lastError, args.processingBefore],
|
|
221
|
+
rowMode: "array"
|
|
222
|
+
});
|
|
223
|
+
return result.rows.map(row => {
|
|
224
|
+
return {
|
|
225
|
+
id: row[0],
|
|
226
|
+
organizationId: row[1],
|
|
227
|
+
operation: row[2],
|
|
228
|
+
tupleUser: row[3],
|
|
229
|
+
tupleRelation: row[4],
|
|
230
|
+
tupleObject: row[5],
|
|
231
|
+
status: row[6],
|
|
232
|
+
attemptCount: row[7],
|
|
233
|
+
nextAttemptAt: row[8],
|
|
234
|
+
lastError: row[9],
|
|
235
|
+
processedAt: row[10],
|
|
236
|
+
createdAt: row[11],
|
|
237
|
+
updatedAt: row[12]
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
exports.createAuthorizationGrantQuery = `-- name: CreateAuthorizationGrant :one
|
|
242
|
+
INSERT INTO weave.authorization_grant (
|
|
243
|
+
organization_id,
|
|
244
|
+
subject_kind,
|
|
245
|
+
subject_id,
|
|
246
|
+
object_kind,
|
|
247
|
+
object_id,
|
|
248
|
+
relation,
|
|
249
|
+
created_by_user_id
|
|
250
|
+
) VALUES (
|
|
251
|
+
$1,
|
|
252
|
+
$2,
|
|
253
|
+
$3,
|
|
254
|
+
$4,
|
|
255
|
+
$5,
|
|
256
|
+
$6,
|
|
257
|
+
$7
|
|
258
|
+
)
|
|
259
|
+
ON CONFLICT (organization_id, subject_kind, subject_id, object_kind, object_id, relation, revoked_at)
|
|
260
|
+
DO UPDATE SET
|
|
261
|
+
updated_at = now()
|
|
262
|
+
RETURNING id, organization_id, subject_kind, subject_id, object_kind, object_id, relation, created_by_user_id, revoked_at, created_at, updated_at`;
|
|
263
|
+
async function createAuthorizationGrant(client, args) {
|
|
264
|
+
const result = await client.query({
|
|
265
|
+
text: exports.createAuthorizationGrantQuery,
|
|
266
|
+
values: [args.organizationId, args.subjectKind, args.subjectId, args.objectKind, args.objectId, args.relation, args.createdByUserId],
|
|
267
|
+
rowMode: "array"
|
|
268
|
+
});
|
|
269
|
+
if (result.rows.length !== 1) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
const row = result.rows[0];
|
|
273
|
+
return {
|
|
274
|
+
id: row[0],
|
|
275
|
+
organizationId: row[1],
|
|
276
|
+
subjectKind: row[2],
|
|
277
|
+
subjectId: row[3],
|
|
278
|
+
objectKind: row[4],
|
|
279
|
+
objectId: row[5],
|
|
280
|
+
relation: row[6],
|
|
281
|
+
createdByUserId: row[7],
|
|
282
|
+
revokedAt: row[8],
|
|
283
|
+
createdAt: row[9],
|
|
284
|
+
updatedAt: row[10]
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
exports.getAuthorizationGrantQuery = `-- name: GetAuthorizationGrant :one
|
|
288
|
+
SELECT id, organization_id, subject_kind, subject_id, object_kind, object_id, relation, created_by_user_id, revoked_at, created_at, updated_at
|
|
289
|
+
FROM weave.authorization_grant
|
|
290
|
+
WHERE id = $1
|
|
291
|
+
AND organization_id = $2`;
|
|
292
|
+
async function getAuthorizationGrant(client, args) {
|
|
293
|
+
const result = await client.query({
|
|
294
|
+
text: exports.getAuthorizationGrantQuery,
|
|
295
|
+
values: [args.authorizationGrantId, args.organizationId],
|
|
296
|
+
rowMode: "array"
|
|
297
|
+
});
|
|
298
|
+
if (result.rows.length !== 1) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
const row = result.rows[0];
|
|
302
|
+
return {
|
|
303
|
+
id: row[0],
|
|
304
|
+
organizationId: row[1],
|
|
305
|
+
subjectKind: row[2],
|
|
306
|
+
subjectId: row[3],
|
|
307
|
+
objectKind: row[4],
|
|
308
|
+
objectId: row[5],
|
|
309
|
+
relation: row[6],
|
|
310
|
+
createdByUserId: row[7],
|
|
311
|
+
revokedAt: row[8],
|
|
312
|
+
createdAt: row[9],
|
|
313
|
+
updatedAt: row[10]
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
exports.listAuthorizationGrantsForSubjectQuery = `-- name: ListAuthorizationGrantsForSubject :many
|
|
317
|
+
SELECT id, organization_id, subject_kind, subject_id, object_kind, object_id, relation, created_by_user_id, revoked_at, created_at, updated_at
|
|
318
|
+
FROM weave.authorization_grant
|
|
319
|
+
WHERE organization_id = $1
|
|
320
|
+
AND subject_kind = $2
|
|
321
|
+
AND subject_id = $3
|
|
322
|
+
AND revoked_at IS NULL
|
|
323
|
+
ORDER BY created_at DESC, id DESC
|
|
324
|
+
LIMIT $5
|
|
325
|
+
OFFSET $4`;
|
|
326
|
+
async function listAuthorizationGrantsForSubject(client, args) {
|
|
327
|
+
const result = await client.query({
|
|
328
|
+
text: exports.listAuthorizationGrantsForSubjectQuery,
|
|
329
|
+
values: [args.organizationId, args.subjectKind, args.subjectId, args.offsetCount, args.limitCount],
|
|
330
|
+
rowMode: "array"
|
|
331
|
+
});
|
|
332
|
+
return result.rows.map(row => {
|
|
333
|
+
return {
|
|
334
|
+
id: row[0],
|
|
335
|
+
organizationId: row[1],
|
|
336
|
+
subjectKind: row[2],
|
|
337
|
+
subjectId: row[3],
|
|
338
|
+
objectKind: row[4],
|
|
339
|
+
objectId: row[5],
|
|
340
|
+
relation: row[6],
|
|
341
|
+
createdByUserId: row[7],
|
|
342
|
+
revokedAt: row[8],
|
|
343
|
+
createdAt: row[9],
|
|
344
|
+
updatedAt: row[10]
|
|
345
|
+
};
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
exports.listAuthorizationGrantsForObjectQuery = `-- name: ListAuthorizationGrantsForObject :many
|
|
349
|
+
SELECT id, organization_id, subject_kind, subject_id, object_kind, object_id, relation, created_by_user_id, revoked_at, created_at, updated_at
|
|
350
|
+
FROM weave.authorization_grant
|
|
351
|
+
WHERE organization_id = $1
|
|
352
|
+
AND object_kind = $2
|
|
353
|
+
AND object_id = $3
|
|
354
|
+
AND revoked_at IS NULL
|
|
355
|
+
ORDER BY created_at DESC, id DESC
|
|
356
|
+
LIMIT $5
|
|
357
|
+
OFFSET $4`;
|
|
358
|
+
async function listAuthorizationGrantsForObject(client, args) {
|
|
359
|
+
const result = await client.query({
|
|
360
|
+
text: exports.listAuthorizationGrantsForObjectQuery,
|
|
361
|
+
values: [args.organizationId, args.objectKind, args.objectId, args.offsetCount, args.limitCount],
|
|
362
|
+
rowMode: "array"
|
|
363
|
+
});
|
|
364
|
+
return result.rows.map(row => {
|
|
365
|
+
return {
|
|
366
|
+
id: row[0],
|
|
367
|
+
organizationId: row[1],
|
|
368
|
+
subjectKind: row[2],
|
|
369
|
+
subjectId: row[3],
|
|
370
|
+
objectKind: row[4],
|
|
371
|
+
objectId: row[5],
|
|
372
|
+
relation: row[6],
|
|
373
|
+
createdByUserId: row[7],
|
|
374
|
+
revokedAt: row[8],
|
|
375
|
+
createdAt: row[9],
|
|
376
|
+
updatedAt: row[10]
|
|
377
|
+
};
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
exports.revokeAuthorizationGrantQuery = `-- name: RevokeAuthorizationGrant :one
|
|
381
|
+
UPDATE weave.authorization_grant
|
|
382
|
+
SET revoked_at = now()
|
|
383
|
+
WHERE id = $1
|
|
384
|
+
AND organization_id = $2
|
|
385
|
+
AND revoked_at IS NULL
|
|
386
|
+
RETURNING id, organization_id, subject_kind, subject_id, object_kind, object_id, relation, created_by_user_id, revoked_at, created_at, updated_at`;
|
|
387
|
+
async function revokeAuthorizationGrant(client, args) {
|
|
388
|
+
const result = await client.query({
|
|
389
|
+
text: exports.revokeAuthorizationGrantQuery,
|
|
390
|
+
values: [args.authorizationGrantId, args.organizationId],
|
|
391
|
+
rowMode: "array"
|
|
392
|
+
});
|
|
393
|
+
if (result.rows.length !== 1) {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
const row = result.rows[0];
|
|
397
|
+
return {
|
|
398
|
+
id: row[0],
|
|
399
|
+
organizationId: row[1],
|
|
400
|
+
subjectKind: row[2],
|
|
401
|
+
subjectId: row[3],
|
|
402
|
+
objectKind: row[4],
|
|
403
|
+
objectId: row[5],
|
|
404
|
+
relation: row[6],
|
|
405
|
+
createdByUserId: row[7],
|
|
406
|
+
revokedAt: row[8],
|
|
407
|
+
createdAt: row[9],
|
|
408
|
+
updatedAt: row[10]
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
exports.revokeAuthorizationGrantByTupleQuery = `-- name: RevokeAuthorizationGrantByTuple :one
|
|
412
|
+
UPDATE weave.authorization_grant
|
|
413
|
+
SET revoked_at = now()
|
|
414
|
+
WHERE organization_id = $1
|
|
415
|
+
AND subject_kind = $2
|
|
416
|
+
AND subject_id = $3
|
|
417
|
+
AND object_kind = $4
|
|
418
|
+
AND object_id = $5
|
|
419
|
+
AND relation = $6
|
|
420
|
+
AND revoked_at IS NULL
|
|
421
|
+
RETURNING id, organization_id, subject_kind, subject_id, object_kind, object_id, relation, created_by_user_id, revoked_at, created_at, updated_at`;
|
|
422
|
+
async function revokeAuthorizationGrantByTuple(client, args) {
|
|
423
|
+
const result = await client.query({
|
|
424
|
+
text: exports.revokeAuthorizationGrantByTupleQuery,
|
|
425
|
+
values: [args.organizationId, args.subjectKind, args.subjectId, args.objectKind, args.objectId, args.relation],
|
|
426
|
+
rowMode: "array"
|
|
427
|
+
});
|
|
428
|
+
if (result.rows.length !== 1) {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
const row = result.rows[0];
|
|
432
|
+
return {
|
|
433
|
+
id: row[0],
|
|
434
|
+
organizationId: row[1],
|
|
435
|
+
subjectKind: row[2],
|
|
436
|
+
subjectId: row[3],
|
|
437
|
+
objectKind: row[4],
|
|
438
|
+
objectId: row[5],
|
|
439
|
+
relation: row[6],
|
|
440
|
+
createdByUserId: row[7],
|
|
441
|
+
revokedAt: row[8],
|
|
442
|
+
createdAt: row[9],
|
|
443
|
+
updatedAt: row[10]
|
|
444
|
+
};
|
|
445
|
+
}
|