weave-typescript 0.37.0 → 0.39.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/weaveapi/auth/v1/auth.pb.d.ts +42 -0
- package/dist/weaveapi/auth/v1/service.pb.d.ts +22 -0
- package/dist/weaveapi/auth/v1/service.pb.js +28 -2
- package/dist/weaveapi/consolidation/v1/consolidation.pb.d.ts +1 -0
- package/dist/weaveapi/consolidation/v1/consolidation.pb.js +6 -0
- package/dist/weaveapi/ingestion/v1/ingestion.pb.d.ts +92 -0
- package/dist/weaveapi/ingestion/v1/ingestion.pb.js +1512 -127
- package/dist/weaveapi/ingestion/v1/service.pb.d.ts +71 -1
- package/dist/weaveapi/ingestion/v1/service.pb.js +410 -0
- package/dist/weaveapi/retrieval/v1/retrieval.pb.d.ts +3 -1
- package/dist/weaveapi/retrieval/v1/retrieval.pb.js +62 -16
- package/dist/weavesql/weavedb/auth_identity_sql.d.ts +23 -2
- package/dist/weavesql/weavedb/auth_identity_sql.js +60 -11
- package/dist/weavesql/weavedb/consolidation_sql.d.ts +2 -2
- package/dist/weavesql/weavedb/consolidation_sql.js +15 -5
- package/dist/weavesql/weavedb/document_security_sql.d.ts +197 -46
- package/dist/weavesql/weavedb/document_security_sql.js +432 -134
- package/dist/weavesql/weavedb/ingestion_sql.d.ts +9 -18
- package/dist/weavesql/weavedb/ingestion_sql.js +124 -101
- package/dist/weavesql/weavedb/retrieval_sql.d.ts +6 -7
- package/dist/weavesql/weavedb/retrieval_sql.js +136 -51
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@ import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
|
2
2
|
interface Client {
|
|
3
3
|
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
4
|
}
|
|
5
|
-
export declare const createDocumentQuery = "-- name: CreateDocument :one\nINSERT INTO weave.documents (\n id,\n organization_id,\n filename,\n mime_type,\n fingerprint,\n storage_ref,\n status,\n scope,\n
|
|
5
|
+
export declare const createDocumentQuery = "-- name: CreateDocument :one\nINSERT INTO weave.documents (\n id,\n organization_id,\n filename,\n mime_type,\n fingerprint,\n storage_ref,\n status,\n scope,\n uploaded_by_user_id,\n metadata\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10\n)\nRETURNING\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n uploaded_by_user_id,\n uploaded_at,\n updated_at,\n page_count,\n char_count,\n metadata";
|
|
6
6
|
export interface CreateDocumentArgs {
|
|
7
7
|
id: string;
|
|
8
8
|
organizationId: string;
|
|
@@ -12,7 +12,6 @@ export interface CreateDocumentArgs {
|
|
|
12
12
|
storageRef: string;
|
|
13
13
|
status: string;
|
|
14
14
|
scope: string;
|
|
15
|
-
sensitivityTags: string[];
|
|
16
15
|
uploadedByUserId: string;
|
|
17
16
|
metadata: any;
|
|
18
17
|
}
|
|
@@ -26,7 +25,6 @@ export interface CreateDocumentRow {
|
|
|
26
25
|
storageRef: string;
|
|
27
26
|
status: string;
|
|
28
27
|
scope: string;
|
|
29
|
-
sensitivityTags: string[];
|
|
30
28
|
uploadedByUserId: string;
|
|
31
29
|
uploadedAt: Date;
|
|
32
30
|
updatedAt: Date;
|
|
@@ -35,7 +33,7 @@ export interface CreateDocumentRow {
|
|
|
35
33
|
metadata: any;
|
|
36
34
|
}
|
|
37
35
|
export declare function createDocument(client: Client, args: CreateDocumentArgs): Promise<CreateDocumentRow | null>;
|
|
38
|
-
export declare const getDocumentByOrganizationAndIDQuery = "-- name: GetDocumentByOrganizationAndID :one\nSELECT\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n
|
|
36
|
+
export declare const getDocumentByOrganizationAndIDQuery = "-- name: GetDocumentByOrganizationAndID :one\nSELECT\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n uploaded_by_user_id,\n uploaded_at,\n updated_at,\n page_count,\n char_count,\n metadata\nFROM weave.documents\nWHERE organization_id = $1\n AND id = $2";
|
|
39
37
|
export interface GetDocumentByOrganizationAndIDArgs {
|
|
40
38
|
organizationId: string;
|
|
41
39
|
id: string;
|
|
@@ -50,7 +48,6 @@ export interface GetDocumentByOrganizationAndIDRow {
|
|
|
50
48
|
storageRef: string;
|
|
51
49
|
status: string;
|
|
52
50
|
scope: string;
|
|
53
|
-
sensitivityTags: string[];
|
|
54
51
|
uploadedByUserId: string;
|
|
55
52
|
uploadedAt: Date;
|
|
56
53
|
updatedAt: Date;
|
|
@@ -59,7 +56,7 @@ export interface GetDocumentByOrganizationAndIDRow {
|
|
|
59
56
|
metadata: any;
|
|
60
57
|
}
|
|
61
58
|
export declare function getDocumentByOrganizationAndID(client: Client, args: GetDocumentByOrganizationAndIDArgs): Promise<GetDocumentByOrganizationAndIDRow | null>;
|
|
62
|
-
export declare const getDocumentByOrganizationAndFingerprintQuery = "-- name: GetDocumentByOrganizationAndFingerprint :one\nSELECT\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n
|
|
59
|
+
export declare const getDocumentByOrganizationAndFingerprintQuery = "-- name: GetDocumentByOrganizationAndFingerprint :one\nSELECT\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n uploaded_by_user_id,\n uploaded_at,\n updated_at,\n page_count,\n char_count,\n metadata\nFROM weave.documents\nWHERE organization_id = $1\n AND fingerprint = $2";
|
|
63
60
|
export interface GetDocumentByOrganizationAndFingerprintArgs {
|
|
64
61
|
organizationId: string;
|
|
65
62
|
fingerprint: Buffer | null;
|
|
@@ -74,7 +71,6 @@ export interface GetDocumentByOrganizationAndFingerprintRow {
|
|
|
74
71
|
storageRef: string;
|
|
75
72
|
status: string;
|
|
76
73
|
scope: string;
|
|
77
|
-
sensitivityTags: string[];
|
|
78
74
|
uploadedByUserId: string;
|
|
79
75
|
uploadedAt: Date;
|
|
80
76
|
updatedAt: Date;
|
|
@@ -83,7 +79,7 @@ export interface GetDocumentByOrganizationAndFingerprintRow {
|
|
|
83
79
|
metadata: any;
|
|
84
80
|
}
|
|
85
81
|
export declare function getDocumentByOrganizationAndFingerprint(client: Client, args: GetDocumentByOrganizationAndFingerprintArgs): Promise<GetDocumentByOrganizationAndFingerprintRow | null>;
|
|
86
|
-
export declare const setDocumentParseResultQuery = "-- name: SetDocumentParseResult :one\nUPDATE weave.documents\nSET\n parser_name = $1,\n status = $2,\n page_count = $3,\n char_count = $4,\n updated_at = now()\nWHERE organization_id = $5\n AND id = $6\nRETURNING\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n
|
|
82
|
+
export declare const setDocumentParseResultQuery = "-- name: SetDocumentParseResult :one\nUPDATE weave.documents\nSET\n parser_name = $1,\n status = $2,\n page_count = $3,\n char_count = $4,\n updated_at = now()\nWHERE organization_id = $5\n AND id = $6\nRETURNING\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n uploaded_by_user_id,\n uploaded_at,\n updated_at,\n page_count,\n char_count,\n metadata";
|
|
87
83
|
export interface SetDocumentParseResultArgs {
|
|
88
84
|
parserName: string;
|
|
89
85
|
status: string;
|
|
@@ -102,7 +98,6 @@ export interface SetDocumentParseResultRow {
|
|
|
102
98
|
storageRef: string;
|
|
103
99
|
status: string;
|
|
104
100
|
scope: string;
|
|
105
|
-
sensitivityTags: string[];
|
|
106
101
|
uploadedByUserId: string;
|
|
107
102
|
uploadedAt: Date;
|
|
108
103
|
updatedAt: Date;
|
|
@@ -111,7 +106,7 @@ export interface SetDocumentParseResultRow {
|
|
|
111
106
|
metadata: any;
|
|
112
107
|
}
|
|
113
108
|
export declare function setDocumentParseResult(client: Client, args: SetDocumentParseResultArgs): Promise<SetDocumentParseResultRow | null>;
|
|
114
|
-
export declare const setDocumentStatusQuery = "-- name: SetDocumentStatus :one\nUPDATE weave.documents\nSET\n status = $1,\n updated_at = now()\nWHERE organization_id = $2\n AND id = $3\nRETURNING\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n
|
|
109
|
+
export declare const setDocumentStatusQuery = "-- name: SetDocumentStatus :one\nUPDATE weave.documents\nSET\n status = $1,\n updated_at = now()\nWHERE organization_id = $2\n AND id = $3\nRETURNING\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n uploaded_by_user_id,\n uploaded_at,\n updated_at,\n page_count,\n char_count,\n metadata";
|
|
115
110
|
export interface SetDocumentStatusArgs {
|
|
116
111
|
status: string;
|
|
117
112
|
organizationId: string;
|
|
@@ -127,7 +122,6 @@ export interface SetDocumentStatusRow {
|
|
|
127
122
|
storageRef: string;
|
|
128
123
|
status: string;
|
|
129
124
|
scope: string;
|
|
130
|
-
sensitivityTags: string[];
|
|
131
125
|
uploadedByUserId: string;
|
|
132
126
|
uploadedAt: Date;
|
|
133
127
|
updatedAt: Date;
|
|
@@ -136,7 +130,7 @@ export interface SetDocumentStatusRow {
|
|
|
136
130
|
metadata: any;
|
|
137
131
|
}
|
|
138
132
|
export declare function setDocumentStatus(client: Client, args: SetDocumentStatusArgs): Promise<SetDocumentStatusRow | null>;
|
|
139
|
-
export declare const listDocumentsByOrganizationQuery = "-- name: ListDocumentsByOrganization :many\nSELECT\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n
|
|
133
|
+
export declare const listDocumentsByOrganizationQuery = "-- name: ListDocumentsByOrganization :many\nSELECT\n id,\n organization_id,\n filename,\n mime_type,\n parser_name,\n fingerprint,\n storage_ref,\n status,\n scope,\n uploaded_by_user_id,\n uploaded_at,\n updated_at,\n page_count,\n char_count,\n metadata\nFROM weave.documents\nWHERE organization_id = $1\nORDER BY uploaded_at DESC\nLIMIT $3 OFFSET $2";
|
|
140
134
|
export interface ListDocumentsByOrganizationArgs {
|
|
141
135
|
organizationId: string;
|
|
142
136
|
pageOffset: string;
|
|
@@ -152,7 +146,6 @@ export interface ListDocumentsByOrganizationRow {
|
|
|
152
146
|
storageRef: string;
|
|
153
147
|
status: string;
|
|
154
148
|
scope: string;
|
|
155
|
-
sensitivityTags: string[];
|
|
156
149
|
uploadedByUserId: string;
|
|
157
150
|
uploadedAt: Date;
|
|
158
151
|
updatedAt: Date;
|
|
@@ -161,7 +154,7 @@ export interface ListDocumentsByOrganizationRow {
|
|
|
161
154
|
metadata: any;
|
|
162
155
|
}
|
|
163
156
|
export declare function listDocumentsByOrganization(client: Client, args: ListDocumentsByOrganizationArgs): Promise<ListDocumentsByOrganizationRow[]>;
|
|
164
|
-
export declare const listAccessibleDocumentSummariesQuery = "-- name: ListAccessibleDocumentSummaries :many\nWITH latest_runs AS (\n SELECT DISTINCT ON (r.document_id)\n r.document_id,\n r.id AS latest_ingestion_run_id,\n r.status AS latest_ingestion_status\n FROM weave.ingestion_runs r\n WHERE r.organization_id = $1\n ORDER BY r.document_id, r.started_at DESC\n),\nthread_counts AS (\n SELECT\n t.document_id,\n COUNT(*)::int AS thread_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_PENDING'\n )::int AS pending_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n )::int AS approved_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_REJECTED'\n )::int AS rejected_count\n FROM weave.threads t\n WHERE t.organization_id = $1\n GROUP BY t.document_id\n),\ntag_data AS (\n SELECT\n dt.document_id,\n array_agg(dt.tag ORDER BY dt.tag ASC) AS tags,\n array_agg(dt.confidence ORDER BY dt.tag ASC) AS tag_confidences\n FROM weave.document_tags dt\n JOIN weave.documents d ON d.id = dt.document_id\n WHERE d.organization_id = $1\n GROUP BY dt.document_id\n)\nSELECT\n d.id,\n d.organization_id,\n d.filename,\n d.mime_type,\n d.parser_name,\n d.status,\n d.scope,\n
|
|
157
|
+
export declare const listAccessibleDocumentSummariesQuery = "-- name: ListAccessibleDocumentSummaries :many\nWITH latest_runs AS (\n SELECT DISTINCT ON (r.document_id)\n r.document_id,\n r.id AS latest_ingestion_run_id,\n r.status AS latest_ingestion_status\n FROM weave.ingestion_runs r\n WHERE r.organization_id = $1\n ORDER BY r.document_id, r.started_at DESC\n),\nthread_counts AS (\n SELECT\n t.document_id,\n COUNT(*)::int AS thread_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_PENDING'\n )::int AS pending_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n )::int AS approved_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_REJECTED'\n )::int AS rejected_count\n FROM weave.threads t\n WHERE t.organization_id = $1\n GROUP BY t.document_id\n),\ntag_data AS (\n SELECT\n dt.document_id,\n array_agg(dt.tag ORDER BY dt.tag ASC) AS tags,\n array_agg(dt.confidence ORDER BY dt.tag ASC) AS tag_confidences\n FROM weave.document_tags dt\n JOIN weave.documents d ON d.id = dt.document_id\n WHERE d.organization_id = $1\n GROUP BY dt.document_id\n)\nSELECT\n d.id,\n d.organization_id,\n d.filename,\n d.mime_type,\n d.parser_name,\n d.status,\n d.scope,\n COALESCE(tag_data.tags, '{}'::text[]) AS tags,\n COALESCE(tag_data.tag_confidences, '{}'::real[]) AS tag_confidences,\n d.uploaded_by_user_id,\n d.uploaded_at,\n d.updated_at,\n d.page_count,\n d.char_count,\n d.metadata,\n COALESCE(latest_runs.latest_ingestion_run_id, '00000000-0000-0000-0000-000000000000'::uuid) AS latest_ingestion_run_id,\n COALESCE(latest_runs.latest_ingestion_status, 'INGESTION_RUN_STATUS_UNSPECIFIED') AS latest_ingestion_status,\n COALESCE(thread_counts.thread_count, 0)::int AS thread_count,\n COALESCE(thread_counts.pending_count, 0)::int AS pending_count,\n COALESCE(thread_counts.approved_count, 0)::int AS approved_count,\n COALESCE(thread_counts.rejected_count, 0)::int AS rejected_count\nFROM weave.documents d\nLEFT JOIN latest_runs ON latest_runs.document_id = d.id\nLEFT JOIN thread_counts ON thread_counts.document_id = d.id\nLEFT JOIN tag_data ON tag_data.document_id = d.id\nWHERE d.organization_id = $1\n AND (\n d.scope = 'DOCUMENT_SCOPE_ORG'\n OR (d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n AND d.uploaded_by_user_id = $2)\n OR (d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n AND (\n EXISTS (\n SELECT 1\n FROM weave.document_restricted_groups drg\n JOIN weave.restricted_group_user_memberships rgum\n ON rgum.organization_id = drg.organization_id\n AND rgum.restricted_group_id = drg.restricted_group_id\n AND rgum.user_id = $2\n WHERE drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n )\n OR EXISTS (\n SELECT 1\n FROM weave.document_restricted_groups drg\n JOIN weave.restricted_group_team_memberships rgtm\n ON rgtm.organization_id = drg.organization_id\n AND rgtm.restricted_group_id = drg.restricted_group_id\n JOIN weave.org_team_memberships otm\n ON otm.organization_id = rgtm.organization_id\n AND otm.org_team_id = rgtm.org_team_id\n AND otm.user_id = $2\n WHERE drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n )))\n )\n AND (cardinality($3::text[]) = 0 OR d.status = ANY($3::text[]))\n AND (cardinality($4::text[]) = 0 OR latest_runs.latest_ingestion_status = ANY($4::text[]))\n AND (cardinality($5::text[]) = 0 OR d.scope = ANY($5::text[]))\n AND (cardinality($6::text[]) = 0 OR tag_data.tags && $6::text[])\n AND (\n cardinality($7::uuid[]) = 0\n OR EXISTS (\n SELECT 1\n FROM weave.document_restricted_groups drg\n WHERE drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n AND drg.restricted_group_id = ANY($7::uuid[])\n )\n )\n AND ($8::timestamptz IS NULL OR d.uploaded_at >= $8::timestamptz)\n AND ($9::timestamptz IS NULL OR d.uploaded_at <= $9::timestamptz)\nORDER BY d.uploaded_at DESC, d.id DESC\nLIMIT $11 OFFSET $10";
|
|
165
158
|
export interface ListAccessibleDocumentSummariesArgs {
|
|
166
159
|
organizationId: string;
|
|
167
160
|
actingUserId: string;
|
|
@@ -169,7 +162,7 @@ export interface ListAccessibleDocumentSummariesArgs {
|
|
|
169
162
|
ingestionStatuses: string[];
|
|
170
163
|
scopes: string[];
|
|
171
164
|
tags: string[];
|
|
172
|
-
|
|
165
|
+
restrictedGroupIds: string[];
|
|
173
166
|
uploadedAfter: Date | null;
|
|
174
167
|
uploadedBefore: Date | null;
|
|
175
168
|
pageOffset: string;
|
|
@@ -183,7 +176,6 @@ export interface ListAccessibleDocumentSummariesRow {
|
|
|
183
176
|
parserName: string;
|
|
184
177
|
status: string;
|
|
185
178
|
scope: string;
|
|
186
|
-
sensitivityTags: string[];
|
|
187
179
|
tags: string;
|
|
188
180
|
tagConfidences: string;
|
|
189
181
|
uploadedByUserId: string;
|
|
@@ -200,7 +192,7 @@ export interface ListAccessibleDocumentSummariesRow {
|
|
|
200
192
|
rejectedCount: number;
|
|
201
193
|
}
|
|
202
194
|
export declare function listAccessibleDocumentSummaries(client: Client, args: ListAccessibleDocumentSummariesArgs): Promise<ListAccessibleDocumentSummariesRow[]>;
|
|
203
|
-
export declare const getAccessibleDocumentSummaryQuery = "-- name: GetAccessibleDocumentSummary :one\nWITH latest_runs AS (\n SELECT DISTINCT ON (r.document_id)\n r.document_id,\n r.id AS latest_ingestion_run_id,\n r.status AS latest_ingestion_status\n FROM weave.ingestion_runs r\n WHERE r.organization_id = $1\n AND r.document_id = $2\n ORDER BY r.document_id, r.started_at DESC\n),\nthread_counts AS (\n SELECT\n t.document_id,\n COUNT(*)::int AS thread_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_PENDING'\n )::int AS pending_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n )::int AS approved_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_REJECTED'\n )::int AS rejected_count\n FROM weave.threads t\n WHERE t.organization_id = $1\n AND t.document_id = $2\n GROUP BY t.document_id\n),\ntag_data AS (\n SELECT\n dt.document_id,\n array_agg(dt.tag ORDER BY dt.tag ASC) AS tags,\n array_agg(dt.confidence ORDER BY dt.tag ASC) AS tag_confidences\n FROM weave.document_tags dt\n JOIN weave.documents d ON d.id = dt.document_id\n WHERE d.organization_id = $1\n AND dt.document_id = $2\n GROUP BY dt.document_id\n)\nSELECT\n d.id,\n d.organization_id,\n d.filename,\n d.mime_type,\n d.parser_name,\n d.status,\n d.scope,\n
|
|
195
|
+
export declare const getAccessibleDocumentSummaryQuery = "-- name: GetAccessibleDocumentSummary :one\nWITH latest_runs AS (\n SELECT DISTINCT ON (r.document_id)\n r.document_id,\n r.id AS latest_ingestion_run_id,\n r.status AS latest_ingestion_status\n FROM weave.ingestion_runs r\n WHERE r.organization_id = $1\n AND r.document_id = $2\n ORDER BY r.document_id, r.started_at DESC\n),\nthread_counts AS (\n SELECT\n t.document_id,\n COUNT(*)::int AS thread_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_PENDING'\n )::int AS pending_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n )::int AS approved_count,\n COUNT(*) FILTER (\n WHERE t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_REJECTED'\n )::int AS rejected_count\n FROM weave.threads t\n WHERE t.organization_id = $1\n AND t.document_id = $2\n GROUP BY t.document_id\n),\ntag_data AS (\n SELECT\n dt.document_id,\n array_agg(dt.tag ORDER BY dt.tag ASC) AS tags,\n array_agg(dt.confidence ORDER BY dt.tag ASC) AS tag_confidences\n FROM weave.document_tags dt\n JOIN weave.documents d ON d.id = dt.document_id\n WHERE d.organization_id = $1\n AND dt.document_id = $2\n GROUP BY dt.document_id\n)\nSELECT\n d.id,\n d.organization_id,\n d.filename,\n d.mime_type,\n d.parser_name,\n d.status,\n d.scope,\n COALESCE(tag_data.tags, '{}'::text[]) AS tags,\n COALESCE(tag_data.tag_confidences, '{}'::real[]) AS tag_confidences,\n d.uploaded_by_user_id,\n d.uploaded_at,\n d.updated_at,\n d.page_count,\n d.char_count,\n d.metadata,\n COALESCE(latest_runs.latest_ingestion_run_id, '00000000-0000-0000-0000-000000000000'::uuid) AS latest_ingestion_run_id,\n COALESCE(latest_runs.latest_ingestion_status, 'INGESTION_RUN_STATUS_UNSPECIFIED') AS latest_ingestion_status,\n COALESCE(thread_counts.thread_count, 0)::int AS thread_count,\n COALESCE(thread_counts.pending_count, 0)::int AS pending_count,\n COALESCE(thread_counts.approved_count, 0)::int AS approved_count,\n COALESCE(thread_counts.rejected_count, 0)::int AS rejected_count\nFROM weave.documents d\nLEFT JOIN latest_runs ON latest_runs.document_id = d.id\nLEFT JOIN thread_counts ON thread_counts.document_id = d.id\nLEFT JOIN tag_data ON tag_data.document_id = d.id\nWHERE d.organization_id = $1\n AND d.id = $2\n AND (\n d.scope = 'DOCUMENT_SCOPE_ORG'\n OR (d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n AND d.uploaded_by_user_id = $3)\n OR (d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n AND (\n EXISTS (\n SELECT 1\n FROM weave.document_restricted_groups drg\n JOIN weave.restricted_group_user_memberships rgum\n ON rgum.organization_id = drg.organization_id\n AND rgum.restricted_group_id = drg.restricted_group_id\n AND rgum.user_id = $3\n WHERE drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n )\n OR EXISTS (\n SELECT 1\n FROM weave.document_restricted_groups drg\n JOIN weave.restricted_group_team_memberships rgtm\n ON rgtm.organization_id = drg.organization_id\n AND rgtm.restricted_group_id = drg.restricted_group_id\n JOIN weave.org_team_memberships otm\n ON otm.organization_id = rgtm.organization_id\n AND otm.org_team_id = rgtm.org_team_id\n AND otm.user_id = $3\n WHERE drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n )))\n )";
|
|
204
196
|
export interface GetAccessibleDocumentSummaryArgs {
|
|
205
197
|
organizationId: string;
|
|
206
198
|
documentId: string;
|
|
@@ -214,7 +206,6 @@ export interface GetAccessibleDocumentSummaryRow {
|
|
|
214
206
|
parserName: string;
|
|
215
207
|
status: string;
|
|
216
208
|
scope: string;
|
|
217
|
-
sensitivityTags: string[];
|
|
218
209
|
tags: string;
|
|
219
210
|
tagConfidences: string;
|
|
220
211
|
uploadedByUserId: string;
|
|
@@ -65,7 +65,6 @@ INSERT INTO weave.documents (
|
|
|
65
65
|
storage_ref,
|
|
66
66
|
status,
|
|
67
67
|
scope,
|
|
68
|
-
sensitivity_tags,
|
|
69
68
|
uploaded_by_user_id,
|
|
70
69
|
metadata
|
|
71
70
|
) VALUES (
|
|
@@ -78,8 +77,7 @@ INSERT INTO weave.documents (
|
|
|
78
77
|
$7,
|
|
79
78
|
$8,
|
|
80
79
|
$9,
|
|
81
|
-
$10
|
|
82
|
-
$11
|
|
80
|
+
$10
|
|
83
81
|
)
|
|
84
82
|
RETURNING
|
|
85
83
|
id,
|
|
@@ -91,7 +89,6 @@ RETURNING
|
|
|
91
89
|
storage_ref,
|
|
92
90
|
status,
|
|
93
91
|
scope,
|
|
94
|
-
sensitivity_tags,
|
|
95
92
|
uploaded_by_user_id,
|
|
96
93
|
uploaded_at,
|
|
97
94
|
updated_at,
|
|
@@ -101,7 +98,7 @@ RETURNING
|
|
|
101
98
|
async function createDocument(client, args) {
|
|
102
99
|
const result = await client.query({
|
|
103
100
|
text: exports.createDocumentQuery,
|
|
104
|
-
values: [args.id, args.organizationId, args.filename, args.mimeType, args.fingerprint, args.storageRef, args.status, args.scope, args.
|
|
101
|
+
values: [args.id, args.organizationId, args.filename, args.mimeType, args.fingerprint, args.storageRef, args.status, args.scope, args.uploadedByUserId, args.metadata],
|
|
105
102
|
rowMode: "array"
|
|
106
103
|
});
|
|
107
104
|
if (result.rows.length !== 1) {
|
|
@@ -118,13 +115,12 @@ async function createDocument(client, args) {
|
|
|
118
115
|
storageRef: row[6],
|
|
119
116
|
status: row[7],
|
|
120
117
|
scope: row[8],
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
metadata: row[15]
|
|
118
|
+
uploadedByUserId: row[9],
|
|
119
|
+
uploadedAt: row[10],
|
|
120
|
+
updatedAt: row[11],
|
|
121
|
+
pageCount: row[12],
|
|
122
|
+
charCount: row[13],
|
|
123
|
+
metadata: row[14]
|
|
128
124
|
};
|
|
129
125
|
}
|
|
130
126
|
exports.getDocumentByOrganizationAndIDQuery = `-- name: GetDocumentByOrganizationAndID :one
|
|
@@ -138,7 +134,6 @@ SELECT
|
|
|
138
134
|
storage_ref,
|
|
139
135
|
status,
|
|
140
136
|
scope,
|
|
141
|
-
sensitivity_tags,
|
|
142
137
|
uploaded_by_user_id,
|
|
143
138
|
uploaded_at,
|
|
144
139
|
updated_at,
|
|
@@ -168,13 +163,12 @@ async function getDocumentByOrganizationAndID(client, args) {
|
|
|
168
163
|
storageRef: row[6],
|
|
169
164
|
status: row[7],
|
|
170
165
|
scope: row[8],
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
metadata: row[15]
|
|
166
|
+
uploadedByUserId: row[9],
|
|
167
|
+
uploadedAt: row[10],
|
|
168
|
+
updatedAt: row[11],
|
|
169
|
+
pageCount: row[12],
|
|
170
|
+
charCount: row[13],
|
|
171
|
+
metadata: row[14]
|
|
178
172
|
};
|
|
179
173
|
}
|
|
180
174
|
exports.getDocumentByOrganizationAndFingerprintQuery = `-- name: GetDocumentByOrganizationAndFingerprint :one
|
|
@@ -188,7 +182,6 @@ SELECT
|
|
|
188
182
|
storage_ref,
|
|
189
183
|
status,
|
|
190
184
|
scope,
|
|
191
|
-
sensitivity_tags,
|
|
192
185
|
uploaded_by_user_id,
|
|
193
186
|
uploaded_at,
|
|
194
187
|
updated_at,
|
|
@@ -218,13 +211,12 @@ async function getDocumentByOrganizationAndFingerprint(client, args) {
|
|
|
218
211
|
storageRef: row[6],
|
|
219
212
|
status: row[7],
|
|
220
213
|
scope: row[8],
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
metadata: row[15]
|
|
214
|
+
uploadedByUserId: row[9],
|
|
215
|
+
uploadedAt: row[10],
|
|
216
|
+
updatedAt: row[11],
|
|
217
|
+
pageCount: row[12],
|
|
218
|
+
charCount: row[13],
|
|
219
|
+
metadata: row[14]
|
|
228
220
|
};
|
|
229
221
|
}
|
|
230
222
|
exports.setDocumentParseResultQuery = `-- name: SetDocumentParseResult :one
|
|
@@ -247,7 +239,6 @@ RETURNING
|
|
|
247
239
|
storage_ref,
|
|
248
240
|
status,
|
|
249
241
|
scope,
|
|
250
|
-
sensitivity_tags,
|
|
251
242
|
uploaded_by_user_id,
|
|
252
243
|
uploaded_at,
|
|
253
244
|
updated_at,
|
|
@@ -274,13 +265,12 @@ async function setDocumentParseResult(client, args) {
|
|
|
274
265
|
storageRef: row[6],
|
|
275
266
|
status: row[7],
|
|
276
267
|
scope: row[8],
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
metadata: row[15]
|
|
268
|
+
uploadedByUserId: row[9],
|
|
269
|
+
uploadedAt: row[10],
|
|
270
|
+
updatedAt: row[11],
|
|
271
|
+
pageCount: row[12],
|
|
272
|
+
charCount: row[13],
|
|
273
|
+
metadata: row[14]
|
|
284
274
|
};
|
|
285
275
|
}
|
|
286
276
|
exports.setDocumentStatusQuery = `-- name: SetDocumentStatus :one
|
|
@@ -300,7 +290,6 @@ RETURNING
|
|
|
300
290
|
storage_ref,
|
|
301
291
|
status,
|
|
302
292
|
scope,
|
|
303
|
-
sensitivity_tags,
|
|
304
293
|
uploaded_by_user_id,
|
|
305
294
|
uploaded_at,
|
|
306
295
|
updated_at,
|
|
@@ -327,13 +316,12 @@ async function setDocumentStatus(client, args) {
|
|
|
327
316
|
storageRef: row[6],
|
|
328
317
|
status: row[7],
|
|
329
318
|
scope: row[8],
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
metadata: row[15]
|
|
319
|
+
uploadedByUserId: row[9],
|
|
320
|
+
uploadedAt: row[10],
|
|
321
|
+
updatedAt: row[11],
|
|
322
|
+
pageCount: row[12],
|
|
323
|
+
charCount: row[13],
|
|
324
|
+
metadata: row[14]
|
|
337
325
|
};
|
|
338
326
|
}
|
|
339
327
|
exports.listDocumentsByOrganizationQuery = `-- name: ListDocumentsByOrganization :many
|
|
@@ -347,7 +335,6 @@ SELECT
|
|
|
347
335
|
storage_ref,
|
|
348
336
|
status,
|
|
349
337
|
scope,
|
|
350
|
-
sensitivity_tags,
|
|
351
338
|
uploaded_by_user_id,
|
|
352
339
|
uploaded_at,
|
|
353
340
|
updated_at,
|
|
@@ -375,13 +362,12 @@ async function listDocumentsByOrganization(client, args) {
|
|
|
375
362
|
storageRef: row[6],
|
|
376
363
|
status: row[7],
|
|
377
364
|
scope: row[8],
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
metadata: row[15]
|
|
365
|
+
uploadedByUserId: row[9],
|
|
366
|
+
uploadedAt: row[10],
|
|
367
|
+
updatedAt: row[11],
|
|
368
|
+
pageCount: row[12],
|
|
369
|
+
charCount: row[13],
|
|
370
|
+
metadata: row[14]
|
|
385
371
|
};
|
|
386
372
|
});
|
|
387
373
|
}
|
|
@@ -430,7 +416,6 @@ SELECT
|
|
|
430
416
|
d.parser_name,
|
|
431
417
|
d.status,
|
|
432
418
|
d.scope,
|
|
433
|
-
d.sensitivity_tags,
|
|
434
419
|
COALESCE(tag_data.tags, '{}'::text[]) AS tags,
|
|
435
420
|
COALESCE(tag_data.tag_confidences, '{}'::real[]) AS tag_confidences,
|
|
436
421
|
d.uploaded_by_user_id,
|
|
@@ -455,20 +440,45 @@ WHERE d.organization_id = $1
|
|
|
455
440
|
OR (d.scope = 'DOCUMENT_SCOPE_PRIVATE'
|
|
456
441
|
AND d.uploaded_by_user_id = $2)
|
|
457
442
|
OR (d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
|
|
458
|
-
AND
|
|
443
|
+
AND (
|
|
444
|
+
EXISTS (
|
|
445
|
+
SELECT 1
|
|
446
|
+
FROM weave.document_restricted_groups drg
|
|
447
|
+
JOIN weave.restricted_group_user_memberships rgum
|
|
448
|
+
ON rgum.organization_id = drg.organization_id
|
|
449
|
+
AND rgum.restricted_group_id = drg.restricted_group_id
|
|
450
|
+
AND rgum.user_id = $2
|
|
451
|
+
WHERE drg.organization_id = d.organization_id
|
|
452
|
+
AND drg.document_id = d.id
|
|
453
|
+
)
|
|
454
|
+
OR EXISTS (
|
|
459
455
|
SELECT 1
|
|
460
|
-
FROM weave.
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
456
|
+
FROM weave.document_restricted_groups drg
|
|
457
|
+
JOIN weave.restricted_group_team_memberships rgtm
|
|
458
|
+
ON rgtm.organization_id = drg.organization_id
|
|
459
|
+
AND rgtm.restricted_group_id = drg.restricted_group_id
|
|
460
|
+
JOIN weave.org_team_memberships otm
|
|
461
|
+
ON otm.organization_id = rgtm.organization_id
|
|
462
|
+
AND otm.org_team_id = rgtm.org_team_id
|
|
463
|
+
AND otm.user_id = $2
|
|
464
|
+
WHERE drg.organization_id = d.organization_id
|
|
465
|
+
AND drg.document_id = d.id
|
|
466
|
+
)))
|
|
466
467
|
)
|
|
467
468
|
AND (cardinality($3::text[]) = 0 OR d.status = ANY($3::text[]))
|
|
468
469
|
AND (cardinality($4::text[]) = 0 OR latest_runs.latest_ingestion_status = ANY($4::text[]))
|
|
469
470
|
AND (cardinality($5::text[]) = 0 OR d.scope = ANY($5::text[]))
|
|
470
|
-
AND (cardinality($6::text[]) = 0 OR tag_data.tags && $6::text[]
|
|
471
|
-
AND (
|
|
471
|
+
AND (cardinality($6::text[]) = 0 OR tag_data.tags && $6::text[])
|
|
472
|
+
AND (
|
|
473
|
+
cardinality($7::uuid[]) = 0
|
|
474
|
+
OR EXISTS (
|
|
475
|
+
SELECT 1
|
|
476
|
+
FROM weave.document_restricted_groups drg
|
|
477
|
+
WHERE drg.organization_id = d.organization_id
|
|
478
|
+
AND drg.document_id = d.id
|
|
479
|
+
AND drg.restricted_group_id = ANY($7::uuid[])
|
|
480
|
+
)
|
|
481
|
+
)
|
|
472
482
|
AND ($8::timestamptz IS NULL OR d.uploaded_at >= $8::timestamptz)
|
|
473
483
|
AND ($9::timestamptz IS NULL OR d.uploaded_at <= $9::timestamptz)
|
|
474
484
|
ORDER BY d.uploaded_at DESC, d.id DESC
|
|
@@ -476,7 +486,7 @@ LIMIT $11 OFFSET $10`;
|
|
|
476
486
|
async function listAccessibleDocumentSummaries(client, args) {
|
|
477
487
|
const result = await client.query({
|
|
478
488
|
text: exports.listAccessibleDocumentSummariesQuery,
|
|
479
|
-
values: [args.organizationId, args.actingUserId, args.documentStatuses, args.ingestionStatuses, args.scopes, args.tags, args.
|
|
489
|
+
values: [args.organizationId, args.actingUserId, args.documentStatuses, args.ingestionStatuses, args.scopes, args.tags, args.restrictedGroupIds, args.uploadedAfter, args.uploadedBefore, args.pageOffset, args.pageSize],
|
|
480
490
|
rowMode: "array"
|
|
481
491
|
});
|
|
482
492
|
return result.rows.map(row => {
|
|
@@ -488,21 +498,20 @@ async function listAccessibleDocumentSummaries(client, args) {
|
|
|
488
498
|
parserName: row[4],
|
|
489
499
|
status: row[5],
|
|
490
500
|
scope: row[6],
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
rejectedCount: row[21]
|
|
501
|
+
tags: row[7],
|
|
502
|
+
tagConfidences: row[8],
|
|
503
|
+
uploadedByUserId: row[9],
|
|
504
|
+
uploadedAt: row[10],
|
|
505
|
+
updatedAt: row[11],
|
|
506
|
+
pageCount: row[12],
|
|
507
|
+
charCount: row[13],
|
|
508
|
+
metadata: row[14],
|
|
509
|
+
latestIngestionRunId: row[15],
|
|
510
|
+
latestIngestionStatus: row[16],
|
|
511
|
+
threadCount: row[17],
|
|
512
|
+
pendingCount: row[18],
|
|
513
|
+
approvedCount: row[19],
|
|
514
|
+
rejectedCount: row[20]
|
|
506
515
|
};
|
|
507
516
|
});
|
|
508
517
|
}
|
|
@@ -554,7 +563,6 @@ SELECT
|
|
|
554
563
|
d.parser_name,
|
|
555
564
|
d.status,
|
|
556
565
|
d.scope,
|
|
557
|
-
d.sensitivity_tags,
|
|
558
566
|
COALESCE(tag_data.tags, '{}'::text[]) AS tags,
|
|
559
567
|
COALESCE(tag_data.tag_confidences, '{}'::real[]) AS tag_confidences,
|
|
560
568
|
d.uploaded_by_user_id,
|
|
@@ -580,14 +588,30 @@ WHERE d.organization_id = $1
|
|
|
580
588
|
OR (d.scope = 'DOCUMENT_SCOPE_PRIVATE'
|
|
581
589
|
AND d.uploaded_by_user_id = $3)
|
|
582
590
|
OR (d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
|
|
583
|
-
AND
|
|
591
|
+
AND (
|
|
592
|
+
EXISTS (
|
|
593
|
+
SELECT 1
|
|
594
|
+
FROM weave.document_restricted_groups drg
|
|
595
|
+
JOIN weave.restricted_group_user_memberships rgum
|
|
596
|
+
ON rgum.organization_id = drg.organization_id
|
|
597
|
+
AND rgum.restricted_group_id = drg.restricted_group_id
|
|
598
|
+
AND rgum.user_id = $3
|
|
599
|
+
WHERE drg.organization_id = d.organization_id
|
|
600
|
+
AND drg.document_id = d.id
|
|
601
|
+
)
|
|
602
|
+
OR EXISTS (
|
|
584
603
|
SELECT 1
|
|
585
|
-
FROM weave.
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
604
|
+
FROM weave.document_restricted_groups drg
|
|
605
|
+
JOIN weave.restricted_group_team_memberships rgtm
|
|
606
|
+
ON rgtm.organization_id = drg.organization_id
|
|
607
|
+
AND rgtm.restricted_group_id = drg.restricted_group_id
|
|
608
|
+
JOIN weave.org_team_memberships otm
|
|
609
|
+
ON otm.organization_id = rgtm.organization_id
|
|
610
|
+
AND otm.org_team_id = rgtm.org_team_id
|
|
611
|
+
AND otm.user_id = $3
|
|
612
|
+
WHERE drg.organization_id = d.organization_id
|
|
613
|
+
AND drg.document_id = d.id
|
|
614
|
+
)))
|
|
591
615
|
)`;
|
|
592
616
|
async function getAccessibleDocumentSummary(client, args) {
|
|
593
617
|
const result = await client.query({
|
|
@@ -607,21 +631,20 @@ async function getAccessibleDocumentSummary(client, args) {
|
|
|
607
631
|
parserName: row[4],
|
|
608
632
|
status: row[5],
|
|
609
633
|
scope: row[6],
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
rejectedCount: row[21]
|
|
634
|
+
tags: row[7],
|
|
635
|
+
tagConfidences: row[8],
|
|
636
|
+
uploadedByUserId: row[9],
|
|
637
|
+
uploadedAt: row[10],
|
|
638
|
+
updatedAt: row[11],
|
|
639
|
+
pageCount: row[12],
|
|
640
|
+
charCount: row[13],
|
|
641
|
+
metadata: row[14],
|
|
642
|
+
latestIngestionRunId: row[15],
|
|
643
|
+
latestIngestionStatus: row[16],
|
|
644
|
+
threadCount: row[17],
|
|
645
|
+
pendingCount: row[18],
|
|
646
|
+
approvedCount: row[19],
|
|
647
|
+
rejectedCount: row[20]
|
|
625
648
|
};
|
|
626
649
|
}
|
|
627
650
|
exports.getDatabaseConfigQuery = `-- name: GetDatabaseConfig :one
|