ydb-qdrant 4.1.3 → 4.2.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/routes/collections.js +16 -10
- package/dist/routes/points.js +5 -0
- package/dist/services/CollectionService.d.ts +1 -0
- package/dist/services/CollectionService.js +1 -1
- package/dist/services/CollectionService.shared.d.ts +1 -1
- package/dist/services/CollectionService.shared.js +4 -3
- package/dist/utils/tenant.d.ts +5 -4
- package/dist/utils/tenant.js +17 -8
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Router } from "express";
|
|
2
|
-
import { sanitizeCollectionName, sanitizeTenantId } from "../utils/tenant.js";
|
|
3
2
|
import { putCollectionIndex, createCollection, getCollection, deleteCollection, } from "../services/CollectionService.js";
|
|
4
3
|
import { QdrantServiceError } from "../services/errors.js";
|
|
5
4
|
import { logger } from "../logging/logger.js";
|
|
@@ -9,6 +8,7 @@ collectionsRouter.put("/:collection/index", async (req, res) => {
|
|
|
9
8
|
const result = await putCollectionIndex({
|
|
10
9
|
tenant: req.header("X-Tenant-Id") ?? undefined,
|
|
11
10
|
collection: String(req.params.collection),
|
|
11
|
+
apiKey: req.header("api-key") ?? undefined,
|
|
12
12
|
});
|
|
13
13
|
res.json({ status: "ok", result });
|
|
14
14
|
}
|
|
@@ -23,9 +23,11 @@ collectionsRouter.put("/:collection/index", async (req, res) => {
|
|
|
23
23
|
});
|
|
24
24
|
collectionsRouter.put("/:collection", async (req, res) => {
|
|
25
25
|
try {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const result = await createCollection({
|
|
27
|
+
tenant: req.header("X-Tenant-Id") ?? undefined,
|
|
28
|
+
collection: String(req.params.collection),
|
|
29
|
+
apiKey: req.header("api-key") ?? undefined,
|
|
30
|
+
}, req.body);
|
|
29
31
|
res.json({ status: "ok", result });
|
|
30
32
|
}
|
|
31
33
|
catch (err) {
|
|
@@ -39,9 +41,11 @@ collectionsRouter.put("/:collection", async (req, res) => {
|
|
|
39
41
|
});
|
|
40
42
|
collectionsRouter.get("/:collection", async (req, res) => {
|
|
41
43
|
try {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
const result = await getCollection({
|
|
45
|
+
tenant: req.header("X-Tenant-Id") ?? undefined,
|
|
46
|
+
collection: String(req.params.collection),
|
|
47
|
+
apiKey: req.header("api-key") ?? undefined,
|
|
48
|
+
});
|
|
45
49
|
res.json({ status: "ok", result });
|
|
46
50
|
}
|
|
47
51
|
catch (err) {
|
|
@@ -55,9 +59,11 @@ collectionsRouter.get("/:collection", async (req, res) => {
|
|
|
55
59
|
});
|
|
56
60
|
collectionsRouter.delete("/:collection", async (req, res) => {
|
|
57
61
|
try {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
const result = await deleteCollection({
|
|
63
|
+
tenant: req.header("X-Tenant-Id") ?? undefined,
|
|
64
|
+
collection: String(req.params.collection),
|
|
65
|
+
apiKey: req.header("api-key") ?? undefined,
|
|
66
|
+
});
|
|
61
67
|
res.json({ status: "ok", result });
|
|
62
68
|
}
|
|
63
69
|
catch (err) {
|
package/dist/routes/points.js
CHANGED
|
@@ -9,6 +9,7 @@ pointsRouter.put("/:collection/points", async (req, res) => {
|
|
|
9
9
|
const result = await upsertPoints({
|
|
10
10
|
tenant: req.header("X-Tenant-Id") ?? undefined,
|
|
11
11
|
collection: String(req.params.collection),
|
|
12
|
+
apiKey: req.header("api-key") ?? undefined,
|
|
12
13
|
}, req.body);
|
|
13
14
|
res.json({ status: "ok", result });
|
|
14
15
|
}
|
|
@@ -26,6 +27,7 @@ pointsRouter.post("/:collection/points/upsert", async (req, res) => {
|
|
|
26
27
|
const result = await upsertPoints({
|
|
27
28
|
tenant: req.header("X-Tenant-Id") ?? undefined,
|
|
28
29
|
collection: String(req.params.collection),
|
|
30
|
+
apiKey: req.header("api-key") ?? undefined,
|
|
29
31
|
}, req.body);
|
|
30
32
|
res.json({ status: "ok", result });
|
|
31
33
|
}
|
|
@@ -43,6 +45,7 @@ pointsRouter.post("/:collection/points/search", async (req, res) => {
|
|
|
43
45
|
const result = await searchPoints({
|
|
44
46
|
tenant: req.header("X-Tenant-Id") ?? undefined,
|
|
45
47
|
collection: String(req.params.collection),
|
|
48
|
+
apiKey: req.header("api-key") ?? undefined,
|
|
46
49
|
}, req.body);
|
|
47
50
|
res.json({ status: "ok", result });
|
|
48
51
|
}
|
|
@@ -61,6 +64,7 @@ pointsRouter.post("/:collection/points/query", async (req, res) => {
|
|
|
61
64
|
const result = await queryPoints({
|
|
62
65
|
tenant: req.header("X-Tenant-Id") ?? undefined,
|
|
63
66
|
collection: String(req.params.collection),
|
|
67
|
+
apiKey: req.header("api-key") ?? undefined,
|
|
64
68
|
}, req.body);
|
|
65
69
|
res.json({ status: "ok", result });
|
|
66
70
|
}
|
|
@@ -78,6 +82,7 @@ pointsRouter.post("/:collection/points/delete", async (req, res) => {
|
|
|
78
82
|
const result = await deletePoints({
|
|
79
83
|
tenant: req.header("X-Tenant-Id") ?? undefined,
|
|
80
84
|
collection: String(req.params.collection),
|
|
85
|
+
apiKey: req.header("api-key") ?? undefined,
|
|
81
86
|
}, req.body);
|
|
82
87
|
res.json({ status: "ok", result });
|
|
83
88
|
}
|
|
@@ -5,7 +5,7 @@ import { QdrantServiceError } from "./errors.js";
|
|
|
5
5
|
import { normalizeCollectionContextShared, tableNameFor, } from "./CollectionService.shared.js";
|
|
6
6
|
import { resolvePointsTableAndUidOneTable } from "./CollectionService.one-table.js";
|
|
7
7
|
export function normalizeCollectionContext(input) {
|
|
8
|
-
return normalizeCollectionContextShared(input.tenant, input.collection);
|
|
8
|
+
return normalizeCollectionContextShared(input.tenant, input.collection, input.apiKey);
|
|
9
9
|
}
|
|
10
10
|
export async function resolvePointsTableAndUid(ctx, meta) {
|
|
11
11
|
if (meta?.table === GLOBAL_POINTS_TABLE) {
|
|
@@ -4,7 +4,7 @@ export interface NormalizedCollectionContextLike {
|
|
|
4
4
|
}
|
|
5
5
|
export declare function tableNameFor(tenantId: string, collection: string): string;
|
|
6
6
|
export declare function uidFor(tenantId: string, collection: string): string;
|
|
7
|
-
export declare function normalizeCollectionContextShared(tenant: string | undefined, collection: string): {
|
|
7
|
+
export declare function normalizeCollectionContextShared(tenant: string | undefined, collection: string, apiKey?: string): {
|
|
8
8
|
tenant: string;
|
|
9
9
|
collection: string;
|
|
10
10
|
metaKey: string;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { sanitizeCollectionName, sanitizeTenantId, metaKeyFor, tableNameFor as tableNameForInternal, uidFor as uidForInternal, } from "../utils/tenant.js";
|
|
1
|
+
import { sanitizeCollectionName, sanitizeTenantId, metaKeyFor, tableNameFor as tableNameForInternal, uidFor as uidForInternal, hashApiKey, } from "../utils/tenant.js";
|
|
2
2
|
export function tableNameFor(tenantId, collection) {
|
|
3
3
|
return tableNameForInternal(tenantId, collection);
|
|
4
4
|
}
|
|
5
5
|
export function uidFor(tenantId, collection) {
|
|
6
6
|
return uidForInternal(tenantId, collection);
|
|
7
7
|
}
|
|
8
|
-
export function normalizeCollectionContextShared(tenant, collection) {
|
|
8
|
+
export function normalizeCollectionContextShared(tenant, collection, apiKey) {
|
|
9
9
|
const normalizedTenant = sanitizeTenantId(tenant);
|
|
10
|
-
const
|
|
10
|
+
const apiKeyHash = hashApiKey(apiKey);
|
|
11
|
+
const normalizedCollection = sanitizeCollectionName(collection, apiKeyHash);
|
|
11
12
|
const metaKey = metaKeyFor(normalizedTenant, normalizedCollection);
|
|
12
13
|
return {
|
|
13
14
|
tenant: normalizedTenant,
|
package/dist/utils/tenant.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function hashApiKey(apiKey: string | undefined): string | undefined;
|
|
2
|
+
export declare function sanitizeCollectionName(name: string, apiKeyHash?: string): string;
|
|
2
3
|
export declare function sanitizeTenantId(tenantId: string | undefined): string;
|
|
3
|
-
export declare function tableNameFor(
|
|
4
|
-
export declare function metaKeyFor(
|
|
5
|
-
export declare function uidFor(
|
|
4
|
+
export declare function tableNameFor(sanitizedTenant: string, sanitizedCollection: string): string;
|
|
5
|
+
export declare function metaKeyFor(sanitizedTenant: string, sanitizedCollection: string): string;
|
|
6
|
+
export declare function uidFor(sanitizedTenant: string, sanitizedCollection: string): string;
|
package/dist/utils/tenant.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
export function hashApiKey(apiKey) {
|
|
3
|
+
if (!apiKey || apiKey.trim() === "")
|
|
4
|
+
return undefined;
|
|
5
|
+
const hash = createHash("sha256").update(apiKey).digest("hex");
|
|
6
|
+
return hash.slice(0, 8);
|
|
7
|
+
}
|
|
8
|
+
export function sanitizeCollectionName(name, apiKeyHash) {
|
|
2
9
|
const cleaned = name.replace(/[^a-zA-Z0-9_]/g, "_").replace(/_+/g, "_");
|
|
3
10
|
const lowered = cleaned.toLowerCase().replace(/^_+/, "");
|
|
4
|
-
|
|
11
|
+
const base = lowered.length > 0 ? lowered : "collection";
|
|
12
|
+
const hasHash = apiKeyHash !== undefined && apiKeyHash.trim().length > 0;
|
|
13
|
+
return hasHash ? `${base}_${apiKeyHash}` : base;
|
|
5
14
|
}
|
|
6
15
|
export function sanitizeTenantId(tenantId) {
|
|
7
16
|
const raw = (tenantId ?? "default").toString();
|
|
@@ -9,12 +18,12 @@ export function sanitizeTenantId(tenantId) {
|
|
|
9
18
|
const lowered = cleaned.toLowerCase().replace(/^_+/, "");
|
|
10
19
|
return lowered.length > 0 ? lowered : "default";
|
|
11
20
|
}
|
|
12
|
-
export function tableNameFor(
|
|
13
|
-
return `qdr_${
|
|
21
|
+
export function tableNameFor(sanitizedTenant, sanitizedCollection) {
|
|
22
|
+
return `qdr_${sanitizedTenant}__${sanitizedCollection}`;
|
|
14
23
|
}
|
|
15
|
-
export function metaKeyFor(
|
|
16
|
-
return `${
|
|
24
|
+
export function metaKeyFor(sanitizedTenant, sanitizedCollection) {
|
|
25
|
+
return `${sanitizedTenant}/${sanitizedCollection}`;
|
|
17
26
|
}
|
|
18
|
-
export function uidFor(
|
|
19
|
-
return tableNameFor(
|
|
27
|
+
export function uidFor(sanitizedTenant, sanitizedCollection) {
|
|
28
|
+
return tableNameFor(sanitizedTenant, sanitizedCollection);
|
|
20
29
|
}
|