@superblocksteam/sdk-api 0.0.4 → 0.0.6
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/files.d.ts +68 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +42 -0
- package/dist/files.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/cosmosdb/client.test.d.ts +8 -0
- package/dist/integrations/cosmosdb/client.test.d.ts.map +1 -0
- package/dist/integrations/cosmosdb/client.test.js +141 -0
- package/dist/integrations/cosmosdb/client.test.js.map +1 -0
- package/dist/integrations/couchbase/client.d.ts +8 -2
- package/dist/integrations/couchbase/client.d.ts.map +1 -1
- package/dist/integrations/couchbase/client.js +27 -33
- package/dist/integrations/couchbase/client.js.map +1 -1
- package/package.json +1 -1
- package/src/files.ts +54 -0
- package/src/index.ts +4 -0
- package/src/integrations/cosmosdb/client.test.ts +209 -0
- package/src/integrations/couchbase/client.ts +31 -44
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical file schemas and types for SDK API inputs.
|
|
3
|
+
*
|
|
4
|
+
* These helpers model the file objects that Superblocks injects for FilePicker
|
|
5
|
+
* inputs. Use the minimal file-ref contract when you want to pass files by
|
|
6
|
+
* reference to storage integrations, and the readable file contract when your
|
|
7
|
+
* API needs to call `readContentsAsync()` or `readContents()`.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
/**
|
|
11
|
+
* Minimal file reference contract.
|
|
12
|
+
*
|
|
13
|
+
* Good for by-reference uploads where the storage plugin resolves the file
|
|
14
|
+
* bytes using `$superblocksId`, such as S3 or GCS `uploadMultipleObjects()`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const fileRefSchema: z.ZodObject<{
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
type: z.ZodOptional<z.ZodString>;
|
|
19
|
+
$superblocksId: z.ZodString;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
name: string;
|
|
22
|
+
$superblocksId: string;
|
|
23
|
+
type?: string | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
name: string;
|
|
26
|
+
$superblocksId: string;
|
|
27
|
+
type?: string | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Runtime-readable file contract.
|
|
31
|
+
*
|
|
32
|
+
* Good for APIs that need to inspect file contents in code via
|
|
33
|
+
* `readContentsAsync()` or `readContents()`.
|
|
34
|
+
*/
|
|
35
|
+
export declare const readableFileSchema: z.ZodObject<{
|
|
36
|
+
name: z.ZodString;
|
|
37
|
+
type: z.ZodOptional<z.ZodString>;
|
|
38
|
+
$superblocksId: z.ZodString;
|
|
39
|
+
} & {
|
|
40
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
extension: z.ZodOptional<z.ZodString>;
|
|
42
|
+
previewUrl: z.ZodOptional<z.ZodString>;
|
|
43
|
+
readContentsAsync: z.ZodType<(mode?: string) => Promise<string | Buffer>, z.ZodTypeDef, (mode?: string) => Promise<string | Buffer>>;
|
|
44
|
+
readContents: z.ZodType<(mode?: string) => string | Buffer, z.ZodTypeDef, (mode?: string) => string | Buffer>;
|
|
45
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
46
|
+
name: z.ZodString;
|
|
47
|
+
type: z.ZodOptional<z.ZodString>;
|
|
48
|
+
$superblocksId: z.ZodString;
|
|
49
|
+
} & {
|
|
50
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
extension: z.ZodOptional<z.ZodString>;
|
|
52
|
+
previewUrl: z.ZodOptional<z.ZodString>;
|
|
53
|
+
readContentsAsync: z.ZodType<(mode?: string) => Promise<string | Buffer>, z.ZodTypeDef, (mode?: string) => Promise<string | Buffer>>;
|
|
54
|
+
readContents: z.ZodType<(mode?: string) => string | Buffer, z.ZodTypeDef, (mode?: string) => string | Buffer>;
|
|
55
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
56
|
+
name: z.ZodString;
|
|
57
|
+
type: z.ZodOptional<z.ZodString>;
|
|
58
|
+
$superblocksId: z.ZodString;
|
|
59
|
+
} & {
|
|
60
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
extension: z.ZodOptional<z.ZodString>;
|
|
62
|
+
previewUrl: z.ZodOptional<z.ZodString>;
|
|
63
|
+
readContentsAsync: z.ZodType<(mode?: string) => Promise<string | Buffer>, z.ZodTypeDef, (mode?: string) => Promise<string | Buffer>>;
|
|
64
|
+
readContents: z.ZodType<(mode?: string) => string | Buffer, z.ZodTypeDef, (mode?: string) => string | Buffer>;
|
|
65
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
66
|
+
export type FileRef = z.infer<typeof fileRefSchema>;
|
|
67
|
+
export type ReadableFile = z.infer<typeof readableFileSchema>;
|
|
68
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAexB;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;EAIxB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;yCA9BrB,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,wBAAnC,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;oCAKK,MAAM,KAAK,MAAM,GAAG,MAAM,wBAA1B,MAAM,KAAK,MAAM,GAAG,MAAM;;;;;;;;;yCALlE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,wBAAnC,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;oCAKK,MAAM,KAAK,MAAM,GAAG,MAAM,wBAA1B,MAAM,KAAK,MAAM,GAAG,MAAM;;;;;;;;;yCALlE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,wBAAnC,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;oCAKK,MAAM,KAAK,MAAM,GAAG,MAAM,wBAA1B,MAAM,KAAK,MAAM,GAAG,MAAM;gCAiC5D,CAAC;AAEjB,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical file schemas and types for SDK API inputs.
|
|
3
|
+
*
|
|
4
|
+
* These helpers model the file objects that Superblocks injects for FilePicker
|
|
5
|
+
* inputs. Use the minimal file-ref contract when you want to pass files by
|
|
6
|
+
* reference to storage integrations, and the readable file contract when your
|
|
7
|
+
* API needs to call `readContentsAsync()` or `readContents()`.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
const readableAsyncMethodSchema = z.custom((value) => typeof value === "function", {
|
|
11
|
+
message: "Expected readContentsAsync to be a function",
|
|
12
|
+
});
|
|
13
|
+
const readableSyncMethodSchema = z.custom((value) => typeof value === "function", {
|
|
14
|
+
message: "Expected readContents to be a function",
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Minimal file reference contract.
|
|
18
|
+
*
|
|
19
|
+
* Good for by-reference uploads where the storage plugin resolves the file
|
|
20
|
+
* bytes using `$superblocksId`, such as S3 or GCS `uploadMultipleObjects()`.
|
|
21
|
+
*/
|
|
22
|
+
export const fileRefSchema = z.object({
|
|
23
|
+
name: z.string(),
|
|
24
|
+
type: z.string().optional(),
|
|
25
|
+
$superblocksId: z.string(),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Runtime-readable file contract.
|
|
29
|
+
*
|
|
30
|
+
* Good for APIs that need to inspect file contents in code via
|
|
31
|
+
* `readContentsAsync()` or `readContents()`.
|
|
32
|
+
*/
|
|
33
|
+
export const readableFileSchema = fileRefSchema
|
|
34
|
+
.extend({
|
|
35
|
+
size: z.number().optional(),
|
|
36
|
+
extension: z.string().optional(),
|
|
37
|
+
previewUrl: z.string().optional(),
|
|
38
|
+
readContentsAsync: readableAsyncMethodSchema,
|
|
39
|
+
readContents: readableSyncMethodSchema,
|
|
40
|
+
})
|
|
41
|
+
.passthrough();
|
|
42
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAExC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,EAAE;IACxC,OAAO,EAAE,6CAA6C;CACvD,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CACvC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,EACtC;IACE,OAAO,EAAE,wCAAwC;CAClD,CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;CAC3B,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa;KAC5C,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,iBAAiB,EAAE,yBAAyB;IAC5C,YAAY,EAAE,wBAAwB;CACvC,CAAC;KACD,WAAW,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,8 @@
|
|
|
51
51
|
* @packageDocumentation
|
|
52
52
|
*/
|
|
53
53
|
export { z } from "zod";
|
|
54
|
+
export { fileRefSchema, readableFileSchema } from "./files.js";
|
|
55
|
+
export type { FileRef, ReadableFile } from "./files.js";
|
|
54
56
|
export { api, __setEntryPoint, type CompiledApi, streamingApi, isStreamingApi, type StreamingApiConfig, type CompiledStreamingApi, } from "./api/index.js";
|
|
55
57
|
export type { ExtractApiInput, ExtractApiOutput } from "./api/definition.js";
|
|
56
58
|
export type { ApiConfig, ApiContext, ApiUser, Logger, BaseIntegrationClient, IntegrationRef, AnyIntegrationRef, IntegrationsMap, } from "./types.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EACL,GAAG,EACH,eAAe,EACf,KAAK,WAAW,EAEhB,YAAY,EACZ,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG7E,YAAY,EACV,SAAS,EACT,UAAU,EACV,OAAO,EACP,MAAM,EACN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,wBAAwB,EACxB,gBAAgB,EAChB,cAAc,EACd,SAAS,GACV,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EAEV,wBAAwB,EACxB,cAAc,EAEd,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,0BAA0B,EAC1B,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EAEzB,oBAAoB,EACpB,6BAA6B,EAC7B,aAAa,GACd,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AAEjC,YAAY,EACV,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,EACb,sBAAsB,EACtB,aAAa,EACb,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,0BAA0B,EAC1B,WAAW,GACZ,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -52,6 +52,8 @@
|
|
|
52
52
|
*/
|
|
53
53
|
// Re-export Zod for convenience
|
|
54
54
|
export { z } from "zod";
|
|
55
|
+
// Canonical file contracts
|
|
56
|
+
export { fileRefSchema, readableFileSchema } from "./files.js";
|
|
55
57
|
// API definition and registry
|
|
56
58
|
export { api, __setEntryPoint,
|
|
57
59
|
// Streaming API support
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,gCAAgC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,8BAA8B;AAC9B,OAAO,EACL,GAAG,EACH,eAAe;AAEf,wBAAwB;AACxB,YAAY,EACZ,cAAc,GAGf,MAAM,gBAAgB,CAAC;A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L,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,0BAA0B,EAC1B,WAAW,GACZ,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,gCAAgC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,2BAA2B;AAC3B,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAG/D,8BAA8B;AAC9B,OAAO,EACL,GAAG,EACH,eAAe;AAEf,wBAAwB;AACxB,YAAY,EACZ,cAAc,GAGf,MAAM,gBAAgB,CAAC;AAiBxB,oCAAoC;AACpC,OAAO,EACL,QAAQ,EACR,KAAK,EACL,MAAM,EACN,SAAS,EACT,MAAM,EACN,MAAM,EACN,MAAM,EACN,SAAS,EACT,eAAe,EACf,QAAQ,EACR,KAAK,EACL,SAAS,EACT,GAAG,EACH,QAAQ,EACR,MAAM,EACN,UAAU,EACV,OAAO,EACP,OAAO,EACP,aAAa,EACb,SAAS,EACT,KAAK,EACL,MAAM,EACN,eAAe,EACf,WAAW,EACX,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,OAAO,EACP,SAAS,EACT,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,MAAM,EACN,OAAO,EACP,IAAI,EACJ,OAAO,EACP,KAAK,EACL,OAAO,EACP,KAAK,EACL,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,EAAE,EACF,GAAG,EACH,YAAY,EACZ,KAAK,EACL,OAAO,EACP,UAAU,EACV,KAAK,EACL,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,0BAA0B,EAC1B,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,iBAAiB,EACjB,IAAI,GAsEL,MAAM,yBAAyB,CAAC;AAwEjC,iCAAiC;AACjC,OAAO;AACL,sEAAsE;AACtE,OAAO;AACP,4DAA4D;AAC5D,UAAU,EACV,mBAAmB,EACnB,2BAA2B;AAC3B,oBAAoB;AACpB,gBAAgB,EAChB,yBAAyB;AACzB,cAAc;AACd,QAAQ,EACR,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,cAAc,EACd,SAAS,GACV,MAAM,oBAAoB,CAAC;AAqB5B,8CAA8C;AAC9C,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AAYjC,wBAAwB;AACxB,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,0BAA0B,EAC1B,WAAW,GACZ,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.test.d.ts","sourceRoot":"","sources":["../../../src/integrations/cosmosdb/client.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for CosmosDB client.
|
|
3
|
+
*
|
|
4
|
+
* Validates the exact proto JSON structure passed to executeQuery for each
|
|
5
|
+
* CosmosDB operation: query, read, create, replace, upsert, deleteItem.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect, vi } from "vitest";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { CosmosDBClientImpl } from "./client.js";
|
|
10
|
+
/** Minimal integration config for testing. */
|
|
11
|
+
const TEST_CONFIG = {
|
|
12
|
+
id: "cosmosdb-test-id",
|
|
13
|
+
name: "Test CosmosDB",
|
|
14
|
+
pluginId: "cosmosdb",
|
|
15
|
+
configuration: {},
|
|
16
|
+
};
|
|
17
|
+
function createClient(mockResult = []) {
|
|
18
|
+
const executeQuery = vi.fn().mockResolvedValue(mockResult);
|
|
19
|
+
const client = new CosmosDBClientImpl(TEST_CONFIG, executeQuery);
|
|
20
|
+
return { client, executeQuery };
|
|
21
|
+
}
|
|
22
|
+
describe("CosmosDBClientImpl", () => {
|
|
23
|
+
describe("query", () => {
|
|
24
|
+
it("passes the correct proto JSON structure to executeQuery", async () => {
|
|
25
|
+
const { client, executeQuery } = createClient([{ id: "doc-1" }]);
|
|
26
|
+
await client.query("my-container", "SELECT * FROM c", z.array(z.object({ id: z.string() }).passthrough()), { crossPartition: true, partitionKey: "pk-1" });
|
|
27
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
28
|
+
expect(executeQuery).toHaveBeenCalledWith({
|
|
29
|
+
sql: {
|
|
30
|
+
singleton: {
|
|
31
|
+
containerId: "my-container",
|
|
32
|
+
query: "SELECT * FROM c",
|
|
33
|
+
crossPartition: true,
|
|
34
|
+
partitionKey: "pk-1",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}, undefined, undefined);
|
|
38
|
+
});
|
|
39
|
+
it("defaults crossPartition to false when not specified", async () => {
|
|
40
|
+
const { client, executeQuery } = createClient([]);
|
|
41
|
+
await client.query("container-1", "SELECT TOP 1 * FROM c", z.array(z.unknown()));
|
|
42
|
+
const request = executeQuery.mock.calls[0][0];
|
|
43
|
+
expect(request.sql.singleton.crossPartition).toBe(false);
|
|
44
|
+
expect(request.sql.singleton.partitionKey).toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe("read", () => {
|
|
48
|
+
it("passes the correct proto JSON structure to executeQuery", async () => {
|
|
49
|
+
const { client, executeQuery } = createClient({
|
|
50
|
+
id: "doc-1",
|
|
51
|
+
name: "test",
|
|
52
|
+
});
|
|
53
|
+
await client.read("my-container", "doc-1", z.object({ id: z.string(), name: z.string() }), "pk-value");
|
|
54
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
55
|
+
expect(executeQuery).toHaveBeenCalledWith({
|
|
56
|
+
pointOperation: {
|
|
57
|
+
containerId: "my-container",
|
|
58
|
+
read: { id: "doc-1", partitionKey: "pk-value" },
|
|
59
|
+
},
|
|
60
|
+
}, undefined, undefined);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe("create", () => {
|
|
64
|
+
it("passes the correct proto JSON structure with object body", async () => {
|
|
65
|
+
const body = { id: "new-doc", value: 42 };
|
|
66
|
+
const { client, executeQuery } = createClient(body);
|
|
67
|
+
await client.create("my-container", body, "pk-value");
|
|
68
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
69
|
+
expect(executeQuery).toHaveBeenCalledWith({
|
|
70
|
+
pointOperation: {
|
|
71
|
+
containerId: "my-container",
|
|
72
|
+
create: {
|
|
73
|
+
body: JSON.stringify(body),
|
|
74
|
+
partitionKey: "pk-value",
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
}, undefined, undefined);
|
|
78
|
+
});
|
|
79
|
+
it("passes string body as-is", async () => {
|
|
80
|
+
const bodyStr = '{"id":"doc-str"}';
|
|
81
|
+
const { client, executeQuery } = createClient({});
|
|
82
|
+
await client.create("my-container", bodyStr);
|
|
83
|
+
const request = executeQuery.mock.calls[0][0];
|
|
84
|
+
expect(request.pointOperation.create.body).toBe(bodyStr);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe("replace", () => {
|
|
88
|
+
it("passes the correct proto JSON structure to executeQuery", async () => {
|
|
89
|
+
const body = { id: "doc-1", value: "updated" };
|
|
90
|
+
const { client, executeQuery } = createClient(body);
|
|
91
|
+
await client.replace("my-container", body, "pk-value");
|
|
92
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
93
|
+
expect(executeQuery).toHaveBeenCalledWith({
|
|
94
|
+
pointOperation: {
|
|
95
|
+
containerId: "my-container",
|
|
96
|
+
replace: {
|
|
97
|
+
body: JSON.stringify(body),
|
|
98
|
+
partitionKey: "pk-value",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
}, undefined, undefined);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe("upsert", () => {
|
|
105
|
+
it("passes the correct proto JSON structure to executeQuery", async () => {
|
|
106
|
+
const body = { id: "doc-1", value: "upserted" };
|
|
107
|
+
const { client, executeQuery } = createClient(body);
|
|
108
|
+
await client.upsert("my-container", body, "pk-value");
|
|
109
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
110
|
+
expect(executeQuery).toHaveBeenCalledWith({
|
|
111
|
+
pointOperation: {
|
|
112
|
+
containerId: "my-container",
|
|
113
|
+
upsert: {
|
|
114
|
+
body: JSON.stringify(body),
|
|
115
|
+
partitionKey: "pk-value",
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
}, undefined, undefined);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe("deleteItem", () => {
|
|
122
|
+
it("passes the correct proto JSON structure to executeQuery", async () => {
|
|
123
|
+
const { client, executeQuery } = createClient({});
|
|
124
|
+
await client.deleteItem("my-container", "doc-to-delete", "pk-value");
|
|
125
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
126
|
+
expect(executeQuery).toHaveBeenCalledWith({
|
|
127
|
+
pointOperation: {
|
|
128
|
+
containerId: "my-container",
|
|
129
|
+
delete: { id: "doc-to-delete", partitionKey: "pk-value" },
|
|
130
|
+
},
|
|
131
|
+
}, undefined, undefined);
|
|
132
|
+
});
|
|
133
|
+
it("passes undefined partitionKey when not specified", async () => {
|
|
134
|
+
const { client, executeQuery } = createClient({});
|
|
135
|
+
await client.deleteItem("my-container", "doc-1");
|
|
136
|
+
const request = executeQuery.mock.calls[0][0];
|
|
137
|
+
expect(request.pointOperation.delete.partitionKey).toBeUndefined();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
//# sourceMappingURL=client.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.test.js","sourceRoot":"","sources":["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CAAC,CAAC,CAAC,CAAC,CAAC;YAC9C,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,aAAa,EAAE,CAAC;QACrE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Couchbase client implementation.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* Builds proto-style request objects for SQL++ queries, document insert,
|
|
4
|
+
* Builds proto JSON-style request objects for SQL++ queries, document insert,
|
|
6
5
|
* get, and remove operations against Couchbase buckets.
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: Request objects use plain objects with flat proto JSON keys
|
|
8
|
+
* (e.g. `{runSql: {sqlBody}}`) rather than the protobuf-es `CouchbaseRequest`
|
|
9
|
+
* type. The protobuf-es type uses oneof wrappers (`{case: "runSql", value: {...}}`)
|
|
10
|
+
* which get lost during the JSON → Go proto → JSON roundtrip in the orchestrator,
|
|
11
|
+
* resulting in "invalid operation: undefined". The Go orchestrator expects the
|
|
12
|
+
* standard proto JSON format with flat field names, not the TS-specific wrapper.
|
|
7
13
|
*/
|
|
8
14
|
import type { z } from "zod";
|
|
9
15
|
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/integrations/couchbase/client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/integrations/couchbase/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,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-style request objects for SQL++ queries, document insert,
|
|
6
5
|
* get, and remove operations against Couchbase buckets.
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: Request objects use plain objects with flat proto JSON keys
|
|
8
|
+
* (e.g. `{runSql: {sqlBody}}`) rather than the protobuf-es `CouchbaseRequest`
|
|
9
|
+
* type. The protobuf-es type uses oneof wrappers (`{case: "runSql", value: {...}}`)
|
|
10
|
+
* which get lost during the JSON → Go proto → JSON roundtrip in the orchestrator,
|
|
11
|
+
* resulting in "invalid operation: undefined". The Go orchestrator expects the
|
|
12
|
+
* standard proto JSON format with flat field names, not the TS-specific wrapper.
|
|
7
13
|
*/
|
|
8
14
|
import { QueryValidationError, RestApiValidationError } from "../../errors.js";
|
|
9
15
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
@@ -32,12 +38,9 @@ export class CouchbaseClientImpl {
|
|
|
32
38
|
const hasParams = params && params.length > 0;
|
|
33
39
|
const request = {
|
|
34
40
|
bucketName: bucket,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
sqlBody: sql,
|
|
39
|
-
parameters: hasParams ? JSON.stringify(params) : undefined,
|
|
40
|
-
},
|
|
41
|
+
runSql: {
|
|
42
|
+
sqlBody: sql,
|
|
43
|
+
parameters: hasParams ? JSON.stringify(params) : undefined,
|
|
41
44
|
},
|
|
42
45
|
};
|
|
43
46
|
try {
|
|
@@ -71,15 +74,12 @@ export class CouchbaseClientImpl {
|
|
|
71
74
|
async insert(key, value, identifier, metadata) {
|
|
72
75
|
const request = {
|
|
73
76
|
bucketName: identifier.bucket,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
value:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
scope: identifier.scope,
|
|
81
|
-
collection: identifier.collection,
|
|
82
|
-
},
|
|
77
|
+
insert: {
|
|
78
|
+
key,
|
|
79
|
+
value: typeof value === "string" ? value : JSON.stringify(value),
|
|
80
|
+
identifier: {
|
|
81
|
+
scope: identifier.scope,
|
|
82
|
+
collection: identifier.collection,
|
|
83
83
|
},
|
|
84
84
|
},
|
|
85
85
|
};
|
|
@@ -96,14 +96,11 @@ export class CouchbaseClientImpl {
|
|
|
96
96
|
async get(key, schema, identifier, metadata) {
|
|
97
97
|
const request = {
|
|
98
98
|
bucketName: identifier.bucket,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
scope: identifier.scope,
|
|
105
|
-
collection: identifier.collection,
|
|
106
|
-
},
|
|
99
|
+
get: {
|
|
100
|
+
key,
|
|
101
|
+
identifier: {
|
|
102
|
+
scope: identifier.scope,
|
|
103
|
+
collection: identifier.collection,
|
|
107
104
|
},
|
|
108
105
|
},
|
|
109
106
|
};
|
|
@@ -129,14 +126,11 @@ export class CouchbaseClientImpl {
|
|
|
129
126
|
async remove(key, identifier, metadata) {
|
|
130
127
|
const request = {
|
|
131
128
|
bucketName: identifier.bucket,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
scope: identifier.scope,
|
|
138
|
-
collection: identifier.collection,
|
|
139
|
-
},
|
|
129
|
+
remove: {
|
|
130
|
+
key,
|
|
131
|
+
identifier: {
|
|
132
|
+
scope: identifier.scope,
|
|
133
|
+
collection: identifier.collection,
|
|
140
134
|
},
|
|
141
135
|
},
|
|
142
136
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/integrations/couchbase/client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/integrations/couchbase/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,YAAY,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H,CAAC;IAED,KAAK,CAAC,MAAM,CACV,GAAW,EACX,UAA+B,EAC/B,QAAwB;QAExB,MAAM,OAAO,GAAG;YACd,UAAU,EAAE,UAAU,CAAC,MAAM;YAC7B,MAAM,EAAE;gBACN,GAAG;gBACH,UAAU,EAAE;oBACV,KAAK,EAAE,UAAU,CAAC,KAAK;oBACvB,UAAU,EAAE,UAAU,CAAC,UAAU;iBAClC;aACF;SACF,CAAC;QAEF,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,YAAY,CACrB,OAAkC,EAClC,SAAS,EACT,QAAQ,CACT,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,gBAAgB,EAAE,CAAC;gBACtC,MAAM,KAAK,CAAC;YACd,CAAC;YAED,MAAM,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
package/src/files.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical file schemas and types for SDK API inputs.
|
|
3
|
+
*
|
|
4
|
+
* These helpers model the file objects that Superblocks injects for FilePicker
|
|
5
|
+
* inputs. Use the minimal file-ref contract when you want to pass files by
|
|
6
|
+
* reference to storage integrations, and the readable file contract when your
|
|
7
|
+
* API needs to call `readContentsAsync()` or `readContents()`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
|
|
12
|
+
const readableAsyncMethodSchema = z.custom<
|
|
13
|
+
(mode?: string) => Promise<string | Buffer>
|
|
14
|
+
>((value) => typeof value === "function", {
|
|
15
|
+
message: "Expected readContentsAsync to be a function",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const readableSyncMethodSchema = z.custom<(mode?: string) => string | Buffer>(
|
|
19
|
+
(value) => typeof value === "function",
|
|
20
|
+
{
|
|
21
|
+
message: "Expected readContents to be a function",
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Minimal file reference contract.
|
|
27
|
+
*
|
|
28
|
+
* Good for by-reference uploads where the storage plugin resolves the file
|
|
29
|
+
* bytes using `$superblocksId`, such as S3 or GCS `uploadMultipleObjects()`.
|
|
30
|
+
*/
|
|
31
|
+
export const fileRefSchema = z.object({
|
|
32
|
+
name: z.string(),
|
|
33
|
+
type: z.string().optional(),
|
|
34
|
+
$superblocksId: z.string(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Runtime-readable file contract.
|
|
39
|
+
*
|
|
40
|
+
* Good for APIs that need to inspect file contents in code via
|
|
41
|
+
* `readContentsAsync()` or `readContents()`.
|
|
42
|
+
*/
|
|
43
|
+
export const readableFileSchema = fileRefSchema
|
|
44
|
+
.extend({
|
|
45
|
+
size: z.number().optional(),
|
|
46
|
+
extension: z.string().optional(),
|
|
47
|
+
previewUrl: z.string().optional(),
|
|
48
|
+
readContentsAsync: readableAsyncMethodSchema,
|
|
49
|
+
readContents: readableSyncMethodSchema,
|
|
50
|
+
})
|
|
51
|
+
.passthrough();
|
|
52
|
+
|
|
53
|
+
export type FileRef = z.infer<typeof fileRefSchema>;
|
|
54
|
+
export type ReadableFile = z.infer<typeof readableFileSchema>;
|
package/src/index.ts
CHANGED
|
@@ -54,6 +54,10 @@
|
|
|
54
54
|
// Re-export Zod for convenience
|
|
55
55
|
export { z } from "zod";
|
|
56
56
|
|
|
57
|
+
// Canonical file contracts
|
|
58
|
+
export { fileRefSchema, readableFileSchema } from "./files.js";
|
|
59
|
+
export type { FileRef, ReadableFile } from "./files.js";
|
|
60
|
+
|
|
57
61
|
// API definition and registry
|
|
58
62
|
export {
|
|
59
63
|
api,
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for CosmosDB client.
|
|
3
|
+
*
|
|
4
|
+
* Validates the exact proto JSON structure passed to executeQuery for each
|
|
5
|
+
* CosmosDB operation: query, read, create, replace, upsert, deleteItem.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, it, expect, vi } from "vitest";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { CosmosDBClientImpl } from "./client.js";
|
|
11
|
+
import type { IntegrationConfig } from "../types.js";
|
|
12
|
+
|
|
13
|
+
/** Minimal integration config for testing. */
|
|
14
|
+
const TEST_CONFIG: IntegrationConfig = {
|
|
15
|
+
id: "cosmosdb-test-id",
|
|
16
|
+
name: "Test CosmosDB",
|
|
17
|
+
pluginId: "cosmosdb",
|
|
18
|
+
configuration: {},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function createClient(mockResult: unknown = []) {
|
|
22
|
+
const executeQuery = vi.fn().mockResolvedValue(mockResult);
|
|
23
|
+
const client = new CosmosDBClientImpl(TEST_CONFIG, executeQuery);
|
|
24
|
+
return { client, executeQuery };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("CosmosDBClientImpl", () => {
|
|
28
|
+
describe("query", () => {
|
|
29
|
+
it("passes the correct proto JSON structure to executeQuery", async () => {
|
|
30
|
+
const { client, executeQuery } = createClient([{ id: "doc-1" }]);
|
|
31
|
+
|
|
32
|
+
await client.query(
|
|
33
|
+
"my-container",
|
|
34
|
+
"SELECT * FROM c",
|
|
35
|
+
z.array(z.object({ id: z.string() }).passthrough()),
|
|
36
|
+
{ crossPartition: true, partitionKey: "pk-1" },
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
40
|
+
expect(executeQuery).toHaveBeenCalledWith(
|
|
41
|
+
{
|
|
42
|
+
sql: {
|
|
43
|
+
singleton: {
|
|
44
|
+
containerId: "my-container",
|
|
45
|
+
query: "SELECT * FROM c",
|
|
46
|
+
crossPartition: true,
|
|
47
|
+
partitionKey: "pk-1",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
undefined,
|
|
52
|
+
undefined,
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("defaults crossPartition to false when not specified", async () => {
|
|
57
|
+
const { client, executeQuery } = createClient([]);
|
|
58
|
+
|
|
59
|
+
await client.query(
|
|
60
|
+
"container-1",
|
|
61
|
+
"SELECT TOP 1 * FROM c",
|
|
62
|
+
z.array(z.unknown()),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const request = executeQuery.mock.calls[0][0];
|
|
66
|
+
expect(request.sql.singleton.crossPartition).toBe(false);
|
|
67
|
+
expect(request.sql.singleton.partitionKey).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("read", () => {
|
|
72
|
+
it("passes the correct proto JSON structure to executeQuery", async () => {
|
|
73
|
+
const { client, executeQuery } = createClient({
|
|
74
|
+
id: "doc-1",
|
|
75
|
+
name: "test",
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await client.read(
|
|
79
|
+
"my-container",
|
|
80
|
+
"doc-1",
|
|
81
|
+
z.object({ id: z.string(), name: z.string() }),
|
|
82
|
+
"pk-value",
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
86
|
+
expect(executeQuery).toHaveBeenCalledWith(
|
|
87
|
+
{
|
|
88
|
+
pointOperation: {
|
|
89
|
+
containerId: "my-container",
|
|
90
|
+
read: { id: "doc-1", partitionKey: "pk-value" },
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
undefined,
|
|
94
|
+
undefined,
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("create", () => {
|
|
100
|
+
it("passes the correct proto JSON structure with object body", async () => {
|
|
101
|
+
const body = { id: "new-doc", value: 42 };
|
|
102
|
+
const { client, executeQuery } = createClient(body);
|
|
103
|
+
|
|
104
|
+
await client.create("my-container", body, "pk-value");
|
|
105
|
+
|
|
106
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
107
|
+
expect(executeQuery).toHaveBeenCalledWith(
|
|
108
|
+
{
|
|
109
|
+
pointOperation: {
|
|
110
|
+
containerId: "my-container",
|
|
111
|
+
create: {
|
|
112
|
+
body: JSON.stringify(body),
|
|
113
|
+
partitionKey: "pk-value",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
undefined,
|
|
118
|
+
undefined,
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("passes string body as-is", async () => {
|
|
123
|
+
const bodyStr = '{"id":"doc-str"}';
|
|
124
|
+
const { client, executeQuery } = createClient({});
|
|
125
|
+
|
|
126
|
+
await client.create("my-container", bodyStr);
|
|
127
|
+
|
|
128
|
+
const request = executeQuery.mock.calls[0][0];
|
|
129
|
+
expect(request.pointOperation.create.body).toBe(bodyStr);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("replace", () => {
|
|
134
|
+
it("passes the correct proto JSON structure to executeQuery", async () => {
|
|
135
|
+
const body = { id: "doc-1", value: "updated" };
|
|
136
|
+
const { client, executeQuery } = createClient(body);
|
|
137
|
+
|
|
138
|
+
await client.replace("my-container", body, "pk-value");
|
|
139
|
+
|
|
140
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
141
|
+
expect(executeQuery).toHaveBeenCalledWith(
|
|
142
|
+
{
|
|
143
|
+
pointOperation: {
|
|
144
|
+
containerId: "my-container",
|
|
145
|
+
replace: {
|
|
146
|
+
body: JSON.stringify(body),
|
|
147
|
+
partitionKey: "pk-value",
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
undefined,
|
|
152
|
+
undefined,
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("upsert", () => {
|
|
158
|
+
it("passes the correct proto JSON structure to executeQuery", async () => {
|
|
159
|
+
const body = { id: "doc-1", value: "upserted" };
|
|
160
|
+
const { client, executeQuery } = createClient(body);
|
|
161
|
+
|
|
162
|
+
await client.upsert("my-container", body, "pk-value");
|
|
163
|
+
|
|
164
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
165
|
+
expect(executeQuery).toHaveBeenCalledWith(
|
|
166
|
+
{
|
|
167
|
+
pointOperation: {
|
|
168
|
+
containerId: "my-container",
|
|
169
|
+
upsert: {
|
|
170
|
+
body: JSON.stringify(body),
|
|
171
|
+
partitionKey: "pk-value",
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
undefined,
|
|
176
|
+
undefined,
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("deleteItem", () => {
|
|
182
|
+
it("passes the correct proto JSON structure to executeQuery", async () => {
|
|
183
|
+
const { client, executeQuery } = createClient({});
|
|
184
|
+
|
|
185
|
+
await client.deleteItem("my-container", "doc-to-delete", "pk-value");
|
|
186
|
+
|
|
187
|
+
expect(executeQuery).toHaveBeenCalledOnce();
|
|
188
|
+
expect(executeQuery).toHaveBeenCalledWith(
|
|
189
|
+
{
|
|
190
|
+
pointOperation: {
|
|
191
|
+
containerId: "my-container",
|
|
192
|
+
delete: { id: "doc-to-delete", partitionKey: "pk-value" },
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
undefined,
|
|
196
|
+
undefined,
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("passes undefined partitionKey when not specified", async () => {
|
|
201
|
+
const { client, executeQuery } = createClient({});
|
|
202
|
+
|
|
203
|
+
await client.deleteItem("my-container", "doc-1");
|
|
204
|
+
|
|
205
|
+
const request = executeQuery.mock.calls[0][0];
|
|
206
|
+
expect(request.pointOperation.delete.partitionKey).toBeUndefined();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Couchbase client implementation.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* Builds proto-style request objects for SQL++ queries, document insert,
|
|
4
|
+
* Builds proto JSON-style request objects for SQL++ queries, document insert,
|
|
6
5
|
* get, and remove operations against Couchbase buckets.
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: Request objects use plain objects with flat proto JSON keys
|
|
8
|
+
* (e.g. `{runSql: {sqlBody}}`) rather than the protobuf-es `CouchbaseRequest`
|
|
9
|
+
* type. The protobuf-es type uses oneof wrappers (`{case: "runSql", value: {...}}`)
|
|
10
|
+
* which get lost during the JSON → Go proto → JSON roundtrip in the orchestrator,
|
|
11
|
+
* resulting in "invalid operation: undefined". The Go orchestrator expects the
|
|
12
|
+
* standard proto JSON format with flat field names, not the TS-specific wrapper.
|
|
7
13
|
*/
|
|
8
14
|
|
|
9
15
|
import type { z } from "zod";
|
|
10
|
-
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
11
|
-
import type { Plugin as CouchbasePlugin } from "@superblocksteam/types/dist/src/plugins/couchbase/v1/plugin_pb";
|
|
12
16
|
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
13
17
|
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
14
18
|
import { QueryValidationError, RestApiValidationError } from "../../errors.js";
|
|
@@ -16,11 +20,6 @@ import { IntegrationError } from "../../runtime/errors.js";
|
|
|
16
20
|
import { describeType } from "../utils.js";
|
|
17
21
|
import type { CouchbaseClient, CouchbaseIdentifier } from "./types.js";
|
|
18
22
|
|
|
19
|
-
/**
|
|
20
|
-
* Couchbase request type derived from proto definition.
|
|
21
|
-
*/
|
|
22
|
-
type CouchbaseRequest = PartialMessage<CouchbasePlugin>;
|
|
23
|
-
|
|
24
23
|
/**
|
|
25
24
|
* Internal implementation of CouchbaseClient.
|
|
26
25
|
*
|
|
@@ -55,14 +54,11 @@ export class CouchbaseClientImpl
|
|
|
55
54
|
metadata?: TraceMetadata,
|
|
56
55
|
): Promise<T[]> {
|
|
57
56
|
const hasParams = params && params.length > 0;
|
|
58
|
-
const request
|
|
57
|
+
const request = {
|
|
59
58
|
bucketName: bucket,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
sqlBody: sql,
|
|
64
|
-
parameters: hasParams ? JSON.stringify(params) : undefined,
|
|
65
|
-
},
|
|
59
|
+
runSql: {
|
|
60
|
+
sqlBody: sql,
|
|
61
|
+
parameters: hasParams ? JSON.stringify(params) : undefined,
|
|
66
62
|
},
|
|
67
63
|
};
|
|
68
64
|
|
|
@@ -119,17 +115,14 @@ export class CouchbaseClientImpl
|
|
|
119
115
|
identifier: CouchbaseIdentifier,
|
|
120
116
|
metadata?: TraceMetadata,
|
|
121
117
|
): Promise<void> {
|
|
122
|
-
const request
|
|
118
|
+
const request = {
|
|
123
119
|
bucketName: identifier.bucket,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
value:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
scope: identifier.scope,
|
|
131
|
-
collection: identifier.collection,
|
|
132
|
-
},
|
|
120
|
+
insert: {
|
|
121
|
+
key,
|
|
122
|
+
value: typeof value === "string" ? value : JSON.stringify(value),
|
|
123
|
+
identifier: {
|
|
124
|
+
scope: identifier.scope,
|
|
125
|
+
collection: identifier.collection,
|
|
133
126
|
},
|
|
134
127
|
},
|
|
135
128
|
};
|
|
@@ -155,16 +148,13 @@ export class CouchbaseClientImpl
|
|
|
155
148
|
identifier: CouchbaseIdentifier,
|
|
156
149
|
metadata?: TraceMetadata,
|
|
157
150
|
): Promise<T> {
|
|
158
|
-
const request
|
|
151
|
+
const request = {
|
|
159
152
|
bucketName: identifier.bucket,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
scope: identifier.scope,
|
|
166
|
-
collection: identifier.collection,
|
|
167
|
-
},
|
|
153
|
+
get: {
|
|
154
|
+
key,
|
|
155
|
+
identifier: {
|
|
156
|
+
scope: identifier.scope,
|
|
157
|
+
collection: identifier.collection,
|
|
168
158
|
},
|
|
169
159
|
},
|
|
170
160
|
};
|
|
@@ -206,16 +196,13 @@ export class CouchbaseClientImpl
|
|
|
206
196
|
identifier: CouchbaseIdentifier,
|
|
207
197
|
metadata?: TraceMetadata,
|
|
208
198
|
): Promise<void> {
|
|
209
|
-
const request
|
|
199
|
+
const request = {
|
|
210
200
|
bucketName: identifier.bucket,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
scope: identifier.scope,
|
|
217
|
-
collection: identifier.collection,
|
|
218
|
-
},
|
|
201
|
+
remove: {
|
|
202
|
+
key,
|
|
203
|
+
identifier: {
|
|
204
|
+
scope: identifier.scope,
|
|
205
|
+
collection: identifier.collection,
|
|
219
206
|
},
|
|
220
207
|
},
|
|
221
208
|
};
|