@glubean/grpc 0.1.4 → 0.2.1
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/README.md +248 -15
- package/dist/contract/adapter.d.ts +44 -0
- package/dist/contract/adapter.d.ts.map +1 -0
- package/dist/contract/adapter.js +503 -0
- package/dist/contract/adapter.js.map +1 -0
- package/dist/contract/factory.d.ts +32 -0
- package/dist/contract/factory.d.ts.map +1 -0
- package/dist/contract/factory.js +90 -0
- package/dist/contract/factory.js.map +1 -0
- package/dist/contract/index.d.ts +34 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +50 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/matchers.d.ts +68 -0
- package/dist/contract/matchers.d.ts.map +1 -0
- package/dist/contract/matchers.js +155 -0
- package/dist/contract/matchers.js.map +1 -0
- package/dist/contract/types.d.ts +238 -0
- package/dist/contract/types.d.ts.map +1 -0
- package/dist/contract/types.js +17 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/index.d.ts +15 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC contract surface for @glubean/grpc 0.2.0.
|
|
3
|
+
*
|
|
4
|
+
* This module makes `@glubean/grpc` a single-package owner of both:
|
|
5
|
+
* - Transport / test-plugin layer (existing `../index.ts`, unchanged)
|
|
6
|
+
* - Contract adapter layer (this directory)
|
|
7
|
+
*
|
|
8
|
+
* Design rationale: "contract is a first-class citizen, not an afterthought
|
|
9
|
+
* to the transport plugin." See
|
|
10
|
+
* `internal/00-product/positioning-v3.md` §12.0 resolved
|
|
11
|
+
* and `internal/40-discovery/proposals/contract-grpc-graphql-expansion.md` §5.1.
|
|
12
|
+
*
|
|
13
|
+
* Side-effect on import:
|
|
14
|
+
* 1. Register grpcAdapter so `contract.register("grpc", grpcAdapter)` wires
|
|
15
|
+
* the dispatcher (contract.grpc becomes the generic dispatcher).
|
|
16
|
+
* 2. Wrap dispatcher with createGrpcRoot so `contract.grpc.with(name, ...)`
|
|
17
|
+
* is available (parallel to HTTP's bootstrap in packages/sdk/src/index.ts
|
|
18
|
+
* lines 1618-1624).
|
|
19
|
+
*
|
|
20
|
+
* After this module loads, users can:
|
|
21
|
+
*
|
|
22
|
+
* import "@glubean/grpc"; // side-effect: registers grpc contract adapter
|
|
23
|
+
* import { contract } from "@glubean/sdk";
|
|
24
|
+
*
|
|
25
|
+
* const paymentContracts = contract.grpc.with("payment", { client });
|
|
26
|
+
* export const completePayment = paymentContracts("complete-payment", {
|
|
27
|
+
* target: "PaymentService/Complete",
|
|
28
|
+
* cases: { ok: { description: "...", expect: { statusCode: 0 } } },
|
|
29
|
+
* });
|
|
30
|
+
*/
|
|
31
|
+
export { grpcAdapter } from "./adapter.js";
|
|
32
|
+
export { createGrpcFactory, createGrpcRoot } from "./factory.js";
|
|
33
|
+
export type { GrpcContractCase, GrpcContractDefaults, GrpcContractExample, GrpcContractExpect, GrpcContractFactory, GrpcContractMeta, GrpcContractRoot, GrpcContractSafeMeta, GrpcContractSpec, GrpcCaseResult, GrpcFlowCaseOutput, GrpcPayloadSchemas, GrpcSafeSchemas, InferGrpcRequest, InferGrpcResponse, } from "./types.js";
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAwBH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACjE,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC contract surface for @glubean/grpc 0.2.0.
|
|
3
|
+
*
|
|
4
|
+
* This module makes `@glubean/grpc` a single-package owner of both:
|
|
5
|
+
* - Transport / test-plugin layer (existing `../index.ts`, unchanged)
|
|
6
|
+
* - Contract adapter layer (this directory)
|
|
7
|
+
*
|
|
8
|
+
* Design rationale: "contract is a first-class citizen, not an afterthought
|
|
9
|
+
* to the transport plugin." See
|
|
10
|
+
* `internal/00-product/positioning-v3.md` §12.0 resolved
|
|
11
|
+
* and `internal/40-discovery/proposals/contract-grpc-graphql-expansion.md` §5.1.
|
|
12
|
+
*
|
|
13
|
+
* Side-effect on import:
|
|
14
|
+
* 1. Register grpcAdapter so `contract.register("grpc", grpcAdapter)` wires
|
|
15
|
+
* the dispatcher (contract.grpc becomes the generic dispatcher).
|
|
16
|
+
* 2. Wrap dispatcher with createGrpcRoot so `contract.grpc.with(name, ...)`
|
|
17
|
+
* is available (parallel to HTTP's bootstrap in packages/sdk/src/index.ts
|
|
18
|
+
* lines 1618-1624).
|
|
19
|
+
*
|
|
20
|
+
* After this module loads, users can:
|
|
21
|
+
*
|
|
22
|
+
* import "@glubean/grpc"; // side-effect: registers grpc contract adapter
|
|
23
|
+
* import { contract } from "@glubean/sdk";
|
|
24
|
+
*
|
|
25
|
+
* const paymentContracts = contract.grpc.with("payment", { client });
|
|
26
|
+
* export const completePayment = paymentContracts("complete-payment", {
|
|
27
|
+
* target: "PaymentService/Complete",
|
|
28
|
+
* cases: { ok: { description: "...", expect: { statusCode: 0 } } },
|
|
29
|
+
* });
|
|
30
|
+
*/
|
|
31
|
+
import { contract } from "@glubean/sdk";
|
|
32
|
+
import { grpcAdapter } from "./adapter.js";
|
|
33
|
+
import { createGrpcRoot } from "./factory.js";
|
|
34
|
+
import { registerGrpcMatchers } from "./matchers.js";
|
|
35
|
+
// Step 1: register the adapter. After this, `contract.grpc` exists as the
|
|
36
|
+
// generic dispatcher attached by `contract.register()`.
|
|
37
|
+
contract.register("grpc", grpcAdapter);
|
|
38
|
+
// Step 2: wrap dispatcher with the scoped-defaults factory so
|
|
39
|
+
// `contract.grpc.with(name, defaults)` UX works.
|
|
40
|
+
{
|
|
41
|
+
const dispatcher = contract.grpc;
|
|
42
|
+
contract.grpc = createGrpcRoot(dispatcher);
|
|
43
|
+
}
|
|
44
|
+
// Step 3: register gRPC custom matchers so
|
|
45
|
+
// `ctx.expect(res).toHaveGrpcStatus(0)` works out of the box.
|
|
46
|
+
registerGrpcMatchers();
|
|
47
|
+
// Re-exports for type consumers who import from the package directly.
|
|
48
|
+
export { grpcAdapter } from "./adapter.js";
|
|
49
|
+
export { createGrpcFactory, createGrpcRoot } from "./factory.js";
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGrD,0EAA0E;AAC1E,wDAAwD;AACxD,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAEvC,8DAA8D;AAC9D,iDAAiD;AACjD,CAAC;IACC,MAAM,UAAU,GAAI,QAAgB,CAAC,IAA4C,CAAC;IACjF,QAAkD,CAAC,IAAI,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;AACxF,CAAC;AAED,2CAA2C;AAC3C,8DAA8D;AAC9D,oBAAoB,EAAE,CAAC;AAEvB,sEAAsE;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC custom matchers for `ctx.expect()`.
|
|
3
|
+
*
|
|
4
|
+
* Registered as a side effect of `import "@glubean/grpc"` (see `./index.ts`).
|
|
5
|
+
* No extra import or configure step required — the matchers become available
|
|
6
|
+
* on every `ctx.expect(res)` call and are fully typed via the
|
|
7
|
+
* `CustomMatchers<T>` declaration merging block below.
|
|
8
|
+
*
|
|
9
|
+
* Matchers work on any object that carries gRPC response shape, including:
|
|
10
|
+
* - `GrpcCallResult` from `@glubean/grpc` transport (direct client.call)
|
|
11
|
+
* - `GrpcCaseResult` from the contract adapter (verify callback / flow
|
|
12
|
+
* `out` lens input)
|
|
13
|
+
*
|
|
14
|
+
* The canonical shape both produce:
|
|
15
|
+
* {
|
|
16
|
+
* message: T,
|
|
17
|
+
* status: { code: number, details: string },
|
|
18
|
+
* responseMetadata: Record<string, string>,
|
|
19
|
+
* duration: number,
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* See `packages/sdk/src/expect.ts` for the underlying `MatcherResult` /
|
|
23
|
+
* `Expectation.extend` / `CustomMatchers<T>` contracts.
|
|
24
|
+
*/
|
|
25
|
+
declare module "@glubean/sdk/expect" {
|
|
26
|
+
interface CustomMatchers<T> {
|
|
27
|
+
/**
|
|
28
|
+
* Assert the gRPC status code on a `GrpcCallResult` / `GrpcCaseResult`.
|
|
29
|
+
*
|
|
30
|
+
* @param code Expected gRPC status code (`0` = OK, `5` = NOT_FOUND, etc.)
|
|
31
|
+
* @param message Optional context prepended to the assertion message
|
|
32
|
+
*
|
|
33
|
+
* @example ctx.expect(res).toHaveGrpcStatus(0);
|
|
34
|
+
* @example ctx.expect(res).toHaveGrpcStatus(5, "user lookup");
|
|
35
|
+
*/
|
|
36
|
+
toHaveGrpcStatus(code: number, message?: string): Expectation<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Convenience: assert status code is `0` (OK).
|
|
39
|
+
* Equivalent to `toHaveGrpcStatus(0)` but reads better in test bodies.
|
|
40
|
+
*
|
|
41
|
+
* @example ctx.expect(res).toHaveGrpcOk();
|
|
42
|
+
*/
|
|
43
|
+
toHaveGrpcOk(message?: string): Expectation<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Assert presence (and optionally value) of a key in response metadata.
|
|
46
|
+
*
|
|
47
|
+
* @param key Metadata key (case-insensitive per gRPC spec; compared as lowercased)
|
|
48
|
+
* @param value Optional exact expected value; when omitted, only presence is checked
|
|
49
|
+
* @param message Optional context prepended to the assertion message
|
|
50
|
+
*
|
|
51
|
+
* @example ctx.expect(res).toHaveGrpcMetadata("x-request-id");
|
|
52
|
+
* @example ctx.expect(res).toHaveGrpcMetadata("x-tenant", "acme");
|
|
53
|
+
*/
|
|
54
|
+
toHaveGrpcMetadata(key: string, value?: string, message?: string): Expectation<T>;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Register gRPC matchers onto the shared `Expectation` prototype. Called
|
|
59
|
+
* from `./index.ts` during the same side-effect block that registers the
|
|
60
|
+
* contract adapter; users get matchers + adapter from a single
|
|
61
|
+
* `import "@glubean/grpc"`.
|
|
62
|
+
*
|
|
63
|
+
* Idempotent: catches the "matcher already exists" error thrown by
|
|
64
|
+
* `Expectation.extend` when the module is evaluated more than once
|
|
65
|
+
* (duplicate imports, Vitest isolation boundaries, etc.).
|
|
66
|
+
*/
|
|
67
|
+
export declare function registerGrpcMatchers(): void;
|
|
68
|
+
//# sourceMappingURL=matchers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../../src/contract/matchers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAQH,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,cAAc,CAAC,CAAC;QACxB;;;;;;;;WAQG;QACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAEjE;;;;;WAKG;QACH,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAE/C;;;;;;;;;WASG;QACH,kBAAkB,CAChB,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,GACf,WAAW,CAAC,CAAC,CAAC,CAAC;KACnB;CACF;AAgJD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAc3C"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC custom matchers for `ctx.expect()`.
|
|
3
|
+
*
|
|
4
|
+
* Registered as a side effect of `import "@glubean/grpc"` (see `./index.ts`).
|
|
5
|
+
* No extra import or configure step required — the matchers become available
|
|
6
|
+
* on every `ctx.expect(res)` call and are fully typed via the
|
|
7
|
+
* `CustomMatchers<T>` declaration merging block below.
|
|
8
|
+
*
|
|
9
|
+
* Matchers work on any object that carries gRPC response shape, including:
|
|
10
|
+
* - `GrpcCallResult` from `@glubean/grpc` transport (direct client.call)
|
|
11
|
+
* - `GrpcCaseResult` from the contract adapter (verify callback / flow
|
|
12
|
+
* `out` lens input)
|
|
13
|
+
*
|
|
14
|
+
* The canonical shape both produce:
|
|
15
|
+
* {
|
|
16
|
+
* message: T,
|
|
17
|
+
* status: { code: number, details: string },
|
|
18
|
+
* responseMetadata: Record<string, string>,
|
|
19
|
+
* duration: number,
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* See `packages/sdk/src/expect.ts` for the underlying `MatcherResult` /
|
|
23
|
+
* `Expectation.extend` / `CustomMatchers<T>` contracts.
|
|
24
|
+
*/
|
|
25
|
+
import { Expectation, inspect } from "@glubean/sdk/expect";
|
|
26
|
+
function readStatusCode(actual) {
|
|
27
|
+
const s = actual?.status;
|
|
28
|
+
return typeof s?.code === "number" ? s.code : undefined;
|
|
29
|
+
}
|
|
30
|
+
function readStatusDetails(actual) {
|
|
31
|
+
const s = actual?.status;
|
|
32
|
+
return typeof s?.details === "string" ? s.details : undefined;
|
|
33
|
+
}
|
|
34
|
+
function readMetadata(actual) {
|
|
35
|
+
const md = actual?.responseMetadata;
|
|
36
|
+
return md && typeof md === "object" ? md : undefined;
|
|
37
|
+
}
|
|
38
|
+
function findMetadataEntry(md, key) {
|
|
39
|
+
const lower = key.toLowerCase();
|
|
40
|
+
for (const [k, v] of Object.entries(md)) {
|
|
41
|
+
if (k.toLowerCase() === lower)
|
|
42
|
+
return [k, v];
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
// =============================================================================
|
|
47
|
+
// Matcher implementations
|
|
48
|
+
// =============================================================================
|
|
49
|
+
const toHaveGrpcStatus = (actual, ...args) => {
|
|
50
|
+
const code = args[0];
|
|
51
|
+
const actualCode = readStatusCode(actual);
|
|
52
|
+
const details = readStatusDetails(actual);
|
|
53
|
+
if (actualCode === undefined) {
|
|
54
|
+
return {
|
|
55
|
+
passed: false,
|
|
56
|
+
message: `to have gRPC status ${code} — actual has no \`.status.code\` (got ${inspect(actual)})`,
|
|
57
|
+
actual,
|
|
58
|
+
expected: code,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
passed: actualCode === code,
|
|
63
|
+
message: details
|
|
64
|
+
? `to have gRPC status ${code} (got ${actualCode}: ${details})`
|
|
65
|
+
: `to have gRPC status ${code}`,
|
|
66
|
+
actual: actualCode,
|
|
67
|
+
expected: code,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const toHaveGrpcOk = (actual) => {
|
|
71
|
+
const actualCode = readStatusCode(actual);
|
|
72
|
+
const details = readStatusDetails(actual);
|
|
73
|
+
if (actualCode === undefined) {
|
|
74
|
+
return {
|
|
75
|
+
passed: false,
|
|
76
|
+
message: `to have gRPC status OK (0) — actual has no \`.status.code\``,
|
|
77
|
+
actual,
|
|
78
|
+
expected: 0,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
passed: actualCode === 0,
|
|
83
|
+
message: details
|
|
84
|
+
? `to have gRPC status OK (0) (got ${actualCode}: ${details})`
|
|
85
|
+
: `to have gRPC status OK (0)`,
|
|
86
|
+
actual: actualCode,
|
|
87
|
+
expected: 0,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const toHaveGrpcMetadata = (actual, ...args) => {
|
|
91
|
+
const key = args[0];
|
|
92
|
+
const expectedValue = args[1];
|
|
93
|
+
const md = readMetadata(actual);
|
|
94
|
+
if (!md) {
|
|
95
|
+
return {
|
|
96
|
+
passed: false,
|
|
97
|
+
message: `to have gRPC metadata \`${key}\` — actual has no \`.responseMetadata\``,
|
|
98
|
+
actual,
|
|
99
|
+
expected: expectedValue !== undefined ? { [key]: expectedValue } : key,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const entry = findMetadataEntry(md, key);
|
|
103
|
+
if (!entry) {
|
|
104
|
+
return {
|
|
105
|
+
passed: false,
|
|
106
|
+
message: `to have gRPC metadata \`${key}\``,
|
|
107
|
+
actual: md,
|
|
108
|
+
expected: expectedValue !== undefined ? { [key]: expectedValue } : key,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (expectedValue === undefined) {
|
|
112
|
+
return {
|
|
113
|
+
passed: true,
|
|
114
|
+
message: `to have gRPC metadata \`${key}\``,
|
|
115
|
+
actual: entry[1],
|
|
116
|
+
expected: key,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
passed: entry[1] === expectedValue,
|
|
121
|
+
message: `to have gRPC metadata \`${key}\` = ${inspect(expectedValue)}`,
|
|
122
|
+
actual: entry[1],
|
|
123
|
+
expected: expectedValue,
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
// =============================================================================
|
|
127
|
+
// Registration — side effect
|
|
128
|
+
// =============================================================================
|
|
129
|
+
/**
|
|
130
|
+
* Register gRPC matchers onto the shared `Expectation` prototype. Called
|
|
131
|
+
* from `./index.ts` during the same side-effect block that registers the
|
|
132
|
+
* contract adapter; users get matchers + adapter from a single
|
|
133
|
+
* `import "@glubean/grpc"`.
|
|
134
|
+
*
|
|
135
|
+
* Idempotent: catches the "matcher already exists" error thrown by
|
|
136
|
+
* `Expectation.extend` when the module is evaluated more than once
|
|
137
|
+
* (duplicate imports, Vitest isolation boundaries, etc.).
|
|
138
|
+
*/
|
|
139
|
+
export function registerGrpcMatchers() {
|
|
140
|
+
try {
|
|
141
|
+
Expectation.extend({
|
|
142
|
+
toHaveGrpcStatus,
|
|
143
|
+
toHaveGrpcOk,
|
|
144
|
+
toHaveGrpcMetadata,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
if (err instanceof Error && /already exists/.test(err.message)) {
|
|
149
|
+
// Idempotent — re-import in a second harness instance is fine.
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
throw err;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=matchers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchers.js","sourceRoot":"","sources":["../../src/contract/matchers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,WAAW,EAAE,OAAO,EAAsB,MAAM,qBAAqB,CAAC;AAyD/E,SAAS,cAAc,CAAC,MAAe;IACrC,MAAM,CAAC,GAAI,MAA6C,EAAE,MAAM,CAAC;IACjE,OAAO,OAAO,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,IAAI,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/D,+DAA+D;YAC/D,OAAO;QACT,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC contract types.
|
|
3
|
+
*
|
|
4
|
+
* User-facing authoring types + adapter-level payload types for the
|
|
5
|
+
* gRPC contract adapter (single-package model — see
|
|
6
|
+
* `internal/40-discovery/proposals/contract-grpc-graphql-expansion.md` §5.1).
|
|
7
|
+
*
|
|
8
|
+
* Structure mirrors `packages/sdk/src/contract-http/types.ts` where
|
|
9
|
+
* applicable, with gRPC-specific semantics:
|
|
10
|
+
* - Target is "Service/Method" (wire format); renderTarget → "Service.Method"
|
|
11
|
+
* - Status codes are gRPC 0-16 (not HTTP 4xx/5xx)
|
|
12
|
+
* - Metadata replaces HTTP headers (metadata carries both ingress + egress)
|
|
13
|
+
* - Deadlines replace HTTP timeouts (ms)
|
|
14
|
+
* - Phase 1 scope: unary RPCs only (no streaming)
|
|
15
|
+
*/
|
|
16
|
+
import type { SchemaLike, TestContext } from "@glubean/sdk";
|
|
17
|
+
import type { CaseDefaultRun, CaseRequires, CaseSeverity, Extensions } from "@glubean/sdk";
|
|
18
|
+
import type { GrpcClient } from "../index.js";
|
|
19
|
+
/**
|
|
20
|
+
* Defaults for a gRPC contract instance (contract.grpc.with("name", {...})).
|
|
21
|
+
*
|
|
22
|
+
* Note: connection-level settings (address, TLS, proto path) are owned by
|
|
23
|
+
* the transport plugin (configure({grpc: grpc({proto, address, ...})})).
|
|
24
|
+
* The contract-layer instance only captures content defaults that apply
|
|
25
|
+
* across contracts authored under this instance.
|
|
26
|
+
*/
|
|
27
|
+
export interface GrpcContractDefaults {
|
|
28
|
+
/** Default gRPC client for all contracts in this instance. */
|
|
29
|
+
client?: GrpcClient;
|
|
30
|
+
/** Tags inherited by all contracts in this instance. */
|
|
31
|
+
tags?: string[];
|
|
32
|
+
/** Default feature grouping key. */
|
|
33
|
+
feature?: string;
|
|
34
|
+
/** Default metadata for all contracts (merged per-case). */
|
|
35
|
+
metadata?: Record<string, string>;
|
|
36
|
+
/** Default deadline in ms for all contracts in this instance. */
|
|
37
|
+
deadlineMs?: number;
|
|
38
|
+
/** OpenAPI-style extensions (x-* keys). Inherited by all contracts. */
|
|
39
|
+
extensions?: Extensions;
|
|
40
|
+
}
|
|
41
|
+
export interface GrpcContractExample<T = unknown> {
|
|
42
|
+
value: T;
|
|
43
|
+
summary?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Response expectations for a gRPC case.
|
|
48
|
+
*
|
|
49
|
+
* `statusCode` is the gRPC canonical status (0 = OK, 3 = INVALID_ARGUMENT,
|
|
50
|
+
* 5 = NOT_FOUND, 7 = PERMISSION_DENIED, 14 = UNAVAILABLE, 16 = UNAUTHENTICATED,
|
|
51
|
+
* etc.). Phase 1 default: `0` (OK) when not specified.
|
|
52
|
+
*/
|
|
53
|
+
export interface GrpcContractExpect<T = unknown> {
|
|
54
|
+
/** Expected gRPC status code (0 = OK). Default: 0 when omitted. */
|
|
55
|
+
statusCode?: number;
|
|
56
|
+
/** Zod/Valibot schema for response message (when statusCode === 0). */
|
|
57
|
+
schema?: SchemaLike<T>;
|
|
58
|
+
/** Partial expected message shape (object — `toMatchObject` semantics). */
|
|
59
|
+
message?: Partial<T>;
|
|
60
|
+
/** Schema for response metadata (trailing). */
|
|
61
|
+
metadata?: SchemaLike<Record<string, string>>;
|
|
62
|
+
/** Partial expected response metadata. */
|
|
63
|
+
metadataMatch?: Record<string, string>;
|
|
64
|
+
/** Single response example (for docs / projection). */
|
|
65
|
+
example?: T;
|
|
66
|
+
/** Named response examples. */
|
|
67
|
+
examples?: Record<string, GrpcContractExample<T>>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* One case on a gRPC contract.
|
|
71
|
+
*
|
|
72
|
+
* Function-valued fields (`request`, `metadata`) reference case-local setup
|
|
73
|
+
* state. In flow mode these are rejected by `validateCaseForFlow` (same
|
|
74
|
+
* discipline as HTTP's function-valued body/params/query/headers).
|
|
75
|
+
*/
|
|
76
|
+
export interface GrpcContractCase<Req = unknown, Res = unknown, S = void> {
|
|
77
|
+
/** Per-case gRPC client override. */
|
|
78
|
+
client?: GrpcClient;
|
|
79
|
+
/** Why this case exists — required. */
|
|
80
|
+
description: string;
|
|
81
|
+
/** Expected response. */
|
|
82
|
+
expect?: GrpcContractExpect<Res>;
|
|
83
|
+
/**
|
|
84
|
+
* Request message. Object shorthand or a function of setup state.
|
|
85
|
+
* Merged deep-style over contract `defaults.request`.
|
|
86
|
+
*/
|
|
87
|
+
request?: Req | ((state: S) => Req);
|
|
88
|
+
/** Per-call metadata (merged with instance + contract defaults). */
|
|
89
|
+
metadata?: Record<string, string> | ((state: S) => Record<string, string>);
|
|
90
|
+
/** Per-call deadline in ms (overrides instance / contract defaults). */
|
|
91
|
+
deadlineMs?: number;
|
|
92
|
+
/** Setup runs before the call. Return value flows to request/metadata fn + teardown. */
|
|
93
|
+
setup?: (ctx: TestContext) => Promise<S>;
|
|
94
|
+
/** Teardown runs after verify, even on failure. */
|
|
95
|
+
teardown?: (ctx: TestContext, state: S) => Promise<void>;
|
|
96
|
+
/** Business-logic verify — runs after status + schema + message match. */
|
|
97
|
+
verify?: (ctx: TestContext, res: GrpcCaseResult<Res>) => void | Promise<void>;
|
|
98
|
+
/** Not yet executable; reason shown in skip message. */
|
|
99
|
+
deferred?: string;
|
|
100
|
+
/** Deprecated; value is the reason. */
|
|
101
|
+
deprecated?: string;
|
|
102
|
+
/** Additional tags (merged with contract-level tags). */
|
|
103
|
+
tags?: string[];
|
|
104
|
+
severity?: CaseSeverity;
|
|
105
|
+
requires?: CaseRequires;
|
|
106
|
+
defaultRun?: CaseDefaultRun;
|
|
107
|
+
/** Per-case extensions. */
|
|
108
|
+
extensions?: Extensions;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Result of running a single case. This is also the `CaseOutput` shape that
|
|
112
|
+
* flow `step.out(state, res)` lens receives.
|
|
113
|
+
*
|
|
114
|
+
* Mirrors `@glubean/grpc`'s `GrpcCallResult<T>` but nested under a contract-
|
|
115
|
+
* layer shape so adapter-layer additions (e.g. assertion diagnostics) can
|
|
116
|
+
* grow independently.
|
|
117
|
+
*/
|
|
118
|
+
export interface GrpcCaseResult<Res = unknown> {
|
|
119
|
+
/** Decoded response message. */
|
|
120
|
+
message: Res;
|
|
121
|
+
/** gRPC status. `code` is 0 for OK. */
|
|
122
|
+
status: {
|
|
123
|
+
code: number;
|
|
124
|
+
details: string;
|
|
125
|
+
};
|
|
126
|
+
/** Response (trailing) metadata. */
|
|
127
|
+
responseMetadata: Record<string, string>;
|
|
128
|
+
/** Duration in ms. */
|
|
129
|
+
duration: number;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* User-facing gRPC contract specification.
|
|
133
|
+
*
|
|
134
|
+
* `target` is the wire-format "Service/Method" string (e.g. "PaymentService/
|
|
135
|
+
* Complete"). `renderTarget` will display as "PaymentService.Complete" in
|
|
136
|
+
* UI but wire format stays as source of truth.
|
|
137
|
+
*
|
|
138
|
+
* Contract identity = contract id (string) + case key. Target is a display
|
|
139
|
+
* hint, NOT an identity — proposal §5.3.
|
|
140
|
+
*/
|
|
141
|
+
export interface GrpcContractSpec<Req = unknown, Res = unknown, Cases extends Record<string, GrpcContractCase<Req, Res, any>> = Record<string, GrpcContractCase<Req, Res>>> {
|
|
142
|
+
/** Wire-format target: "ServiceName/MethodName". */
|
|
143
|
+
target: string;
|
|
144
|
+
/** Default gRPC client for all cases. */
|
|
145
|
+
client?: GrpcClient;
|
|
146
|
+
description?: string;
|
|
147
|
+
feature?: string;
|
|
148
|
+
/** Contract-level request schema (OpenAPI-style docs + possible runtime validation). */
|
|
149
|
+
requestSchema?: SchemaLike<Req>;
|
|
150
|
+
/** Contract-level default request (merged under each case's request). */
|
|
151
|
+
defaultRequest?: Partial<Req>;
|
|
152
|
+
/** Contract-level default metadata (merged under each case's metadata). */
|
|
153
|
+
defaultMetadata?: Record<string, string>;
|
|
154
|
+
/** Contract-level default deadline (ms). */
|
|
155
|
+
deadlineMs?: number;
|
|
156
|
+
tags?: string[];
|
|
157
|
+
deprecated?: string;
|
|
158
|
+
extensions?: Extensions;
|
|
159
|
+
/** Named spec cases. */
|
|
160
|
+
cases: Cases;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Runtime (live) payload shape for the gRPC adapter. Contains SchemaLike
|
|
164
|
+
* references. Converted to GrpcSafeSchemas by adapter.normalize.
|
|
165
|
+
*/
|
|
166
|
+
export interface GrpcPayloadSchemas {
|
|
167
|
+
request?: SchemaLike<unknown>;
|
|
168
|
+
response?: SchemaLike<unknown>;
|
|
169
|
+
metadata?: SchemaLike<Record<string, string>>;
|
|
170
|
+
/** Request examples (for docs / projection). */
|
|
171
|
+
requestExample?: unknown;
|
|
172
|
+
requestExamples?: Record<string, GrpcContractExample<unknown>>;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* JSON-safe payload shape. Produced by adapter.normalize.
|
|
176
|
+
* SchemaLike references are converted to JSON Schema fragments.
|
|
177
|
+
*/
|
|
178
|
+
export interface GrpcSafeSchemas {
|
|
179
|
+
request?: Record<string, unknown>;
|
|
180
|
+
response?: Record<string, unknown>;
|
|
181
|
+
metadata?: Record<string, unknown>;
|
|
182
|
+
requestExample?: unknown;
|
|
183
|
+
requestExamples?: Record<string, GrpcContractExample<unknown>>;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Runtime contract-level meta. Carried on the projection so scanner / MCP /
|
|
187
|
+
* Cloud can surface structural info without needing the live spec.
|
|
188
|
+
*
|
|
189
|
+
* Note: `.proto` file path is intentionally NOT stored here (execution log
|
|
190
|
+
* OQ-2 decision 2026-04-20). The proto path is a runtime transport concern
|
|
191
|
+
* owned by `configure({grpc: grpc({proto: ...})})`, not by the contract.
|
|
192
|
+
* Contract is protocol-idea-level, transport config is deployment-level.
|
|
193
|
+
*/
|
|
194
|
+
export interface GrpcContractMeta {
|
|
195
|
+
/** Raw target "Service/Method". */
|
|
196
|
+
target: string;
|
|
197
|
+
/** Parsed service name ("PaymentService"). */
|
|
198
|
+
service: string;
|
|
199
|
+
/** Parsed method name ("Complete"). */
|
|
200
|
+
method: string;
|
|
201
|
+
/** Contract-level default metadata (for projection display). */
|
|
202
|
+
defaultMetadata?: Record<string, string>;
|
|
203
|
+
/** Contract-level deadline (for projection display). */
|
|
204
|
+
deadlineMs?: number;
|
|
205
|
+
/** Contract instance name (contract.grpc.with("name")). */
|
|
206
|
+
instanceName?: string;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* JSON-safe meta. Same as runtime meta (no live references).
|
|
210
|
+
*/
|
|
211
|
+
export type GrpcContractSafeMeta = GrpcContractMeta;
|
|
212
|
+
/**
|
|
213
|
+
* What `executeCaseInFlow` returns, and what flow `step.out(state, res)`
|
|
214
|
+
* receives in its `res` parameter. Mirrors `GrpcCaseResult` — kept as a
|
|
215
|
+
* distinct export to make the flow-output contract explicit (parallel to
|
|
216
|
+
* HTTP's `HttpFlowCaseOutput` convention).
|
|
217
|
+
*/
|
|
218
|
+
export type GrpcFlowCaseOutput<Res = unknown> = GrpcCaseResult<Res>;
|
|
219
|
+
/**
|
|
220
|
+
* Signature of `contract.grpc.with("name", defaults)`. Returns a contract
|
|
221
|
+
* factory that creates contracts under this instance's defaults.
|
|
222
|
+
*
|
|
223
|
+
* Actual implementation in `./factory.ts` (CG-4).
|
|
224
|
+
*/
|
|
225
|
+
export type GrpcContractRoot = {
|
|
226
|
+
with: (instanceName: string, defaults?: GrpcContractDefaults) => GrpcContractFactory;
|
|
227
|
+
};
|
|
228
|
+
export type GrpcContractFactory = <Req, Res, Cases extends Record<string, GrpcContractCase<Req, Res, any>>>(id: string, spec: GrpcContractSpec<Req, Res, Cases>) => unknown;
|
|
229
|
+
/**
|
|
230
|
+
* Infer request type from a GrpcContractCase. Placeholder for future
|
|
231
|
+
* ergonomic inference helpers parallel to HTTP's InferHttpInputs.
|
|
232
|
+
*/
|
|
233
|
+
export type InferGrpcRequest<C> = C extends GrpcContractCase<infer Req, any, any> ? Req : never;
|
|
234
|
+
/**
|
|
235
|
+
* Infer response type from a GrpcContractCase.
|
|
236
|
+
*/
|
|
237
|
+
export type InferGrpcResponse<C> = C extends GrpcContractCase<any, infer Res, any> ? Res : never;
|
|
238
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/contract/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,UAAU,EACX,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAM9C;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,8DAA8D;IAC9D,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,oCAAoC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAMD,MAAM,WAAW,mBAAmB,CAAC,CAAC,GAAG,OAAO;IAC9C,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAA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CAAC,SAAS,gBAAgB,CAAC,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,KAAK,CAAC;AAEhG;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC contract types.
|
|
3
|
+
*
|
|
4
|
+
* User-facing authoring types + adapter-level payload types for the
|
|
5
|
+
* gRPC contract adapter (single-package model — see
|
|
6
|
+
* `internal/40-discovery/proposals/contract-grpc-graphql-expansion.md` §5.1).
|
|
7
|
+
*
|
|
8
|
+
* Structure mirrors `packages/sdk/src/contract-http/types.ts` where
|
|
9
|
+
* applicable, with gRPC-specific semantics:
|
|
10
|
+
* - Target is "Service/Method" (wire format); renderTarget → "Service.Method"
|
|
11
|
+
* - Status codes are gRPC 0-16 (not HTTP 4xx/5xx)
|
|
12
|
+
* - Metadata replaces HTTP headers (metadata carries both ingress + egress)
|
|
13
|
+
* - Deadlines replace HTTP timeouts (ms)
|
|
14
|
+
* - Phase 1 scope: unary RPCs only (no streaming)
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/contract/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @glubean/grpc 0.2.0 — single-package owner of both:
|
|
3
|
+
* - Transport / test-plugin layer (this file — unchanged from 0.1.x)
|
|
4
|
+
* - Contract adapter layer (`./contract/`, registered via side-effect import)
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
+
* Importing this package (side-effect) registers the gRPC contract adapter:
|
|
7
|
+
* `contract.register("grpc", grpcAdapter)` → `contract.grpc.with(...)` UX.
|
|
8
|
+
*
|
|
9
|
+
* See `./contract/index.ts` for the registration logic. See
|
|
10
|
+
* `internal/40-discovery/proposals/contract-grpc-graphql-expansion.md` §5.1
|
|
11
|
+
* for the single-package rationale ("contract is a first-class citizen").
|
|
12
|
+
*
|
|
13
|
+
* Transport (this file) — provides a thin wrapper over `@grpc/grpc-js` that
|
|
14
|
+
* simplifies unary gRPC calls with auto-tracing via Glubean events.
|
|
6
15
|
*
|
|
7
16
|
* ## Usage
|
|
8
17
|
*
|
|
@@ -201,4 +210,7 @@ export declare const GRPC_REDACTION_SCOPES: ({
|
|
|
201
210
|
handler: "json";
|
|
202
211
|
rules?: undefined;
|
|
203
212
|
})[];
|
|
213
|
+
import "./contract/index.js";
|
|
214
|
+
export { grpcAdapter, createGrpcFactory, createGrpcRoot, } from "./contract/index.js";
|
|
215
|
+
export type { GrpcContractCase, GrpcContractDefaults, GrpcContractExample, GrpcContractExpect, GrpcContractFactory, GrpcContractMeta, GrpcContractRoot, GrpcContractSafeMeta, GrpcContractSpec, GrpcCaseResult, GrpcFlowCaseOutput, GrpcPayloadSchemas, GrpcSafeSchemas, InferGrpcRequest, InferGrpcResponse, } from "./contract/index.js";
|
|
204
216
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,KAAK,KAAK,SAAS,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAkB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