@yak-io/trpc 0.1.3 → 0.1.5
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/adapters.d.ts.map +1 -1
- package/dist/adapters.js +1 -2
- package/dist/caller.d.ts +1 -2
- package/dist/caller.d.ts.map +1 -1
- package/dist/caller.js +17 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/introspect.js +2 -2
- package/package.json +9 -7
package/dist/adapters.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAG1E;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAG1E;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAChC,OAAO,SAAS,SAAS,EACzB,QAAQ,EACR,QAAQ,SAAS,cAAc,GAAG,cAAc,IAC9C;IACF,2BAA2B;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,mDAAmD;IACnD,aAAa,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,QAAQ,CAAA;KAAE,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9D;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,SAAS,SAAS,EACzB,QAAQ,EACR,QAAQ,SAAS,cAAc,GAAG,cAAc,EAChD,MAAM,EAAE,sBAAsB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,YAAY,CAwB3E;AAED,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,EACR,QAAQ,SAAS,cAAc,GAAG,cAAc,IAC9C,sBAAsB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG;IACxD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,SAAS,SAAS,EACzB,QAAQ,EACR,QAAQ,SAAS,cAAc,GAAG,cAAc,EAChD,MAAM,EAAE,qBAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,UAAU,CAYxE"}
|
package/dist/adapters.js
CHANGED
|
@@ -29,12 +29,11 @@ export function createTRPCToolExecutor(config) {
|
|
|
29
29
|
const disallowedSet = disallowedProcedures ? new Set(disallowedProcedures) : null;
|
|
30
30
|
return async (name, args, req) => {
|
|
31
31
|
// Check if procedure is allowed
|
|
32
|
-
// If allowedProcedures is set, procedure must be in the list
|
|
33
32
|
if (allowedSet && !allowedSet.has(name)) {
|
|
34
33
|
throw new Error(`Procedure '${name}' is not allowed`);
|
|
35
34
|
}
|
|
36
35
|
// If disallowedProcedures is set, procedure must not be in the list
|
|
37
|
-
if (disallowedSet
|
|
36
|
+
if (disallowedSet?.has(name)) {
|
|
38
37
|
throw new Error(`Procedure '${name}' is not allowed`);
|
|
39
38
|
}
|
|
40
39
|
// Create tRPC context
|
package/dist/caller.d.ts
CHANGED
|
@@ -20,6 +20,5 @@ export declare function splitProcedurePath(path: string): string[];
|
|
|
20
20
|
* const result = await caller("orders.list", { limit: 10 });
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
export declare function createDynamicCaller(router: any,
|
|
24
|
-
ctx: any): (name: string, input: unknown) => Promise<unknown>;
|
|
23
|
+
export declare function createDynamicCaller(router: any, ctx: any): (name: string, input: unknown) => Promise<unknown>;
|
|
25
24
|
//# sourceMappingURL=caller.d.ts.map
|
package/dist/caller.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caller.d.ts","sourceRoot":"","sources":["../src/caller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAyEnC;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"caller.d.ts","sourceRoot":"","sources":["../src/caller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAyEnC;;;;GAIG;AAEH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CA0DxF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAEjC,MAAM,EAAE,GAAG,EAEX,GAAG,EAAE,GAAG,GACP,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAkDpD"}
|
package/dist/caller.js
CHANGED
|
@@ -15,7 +15,7 @@ const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|
|
|
|
15
15
|
function getZodTypeName(schema) {
|
|
16
16
|
// Zod 4 uses schema.type or schema._def.type
|
|
17
17
|
// Zod 3 uses schema._def.typeName
|
|
18
|
-
//
|
|
18
|
+
// biome-ignore lint/suspicious/noExplicitAny: accessing Zod internal _def which differs between v3/v4
|
|
19
19
|
const s = schema;
|
|
20
20
|
return s.type ?? s._def?.type ?? s._def?.typeName;
|
|
21
21
|
}
|
|
@@ -24,7 +24,7 @@ function getZodTypeName(schema) {
|
|
|
24
24
|
*/
|
|
25
25
|
function unwrapZodType(schema) {
|
|
26
26
|
const typeName = getZodTypeName(schema);
|
|
27
|
-
//
|
|
27
|
+
// biome-ignore lint/suspicious/noExplicitAny: accessing Zod internal _def which differs between v3/v4
|
|
28
28
|
const def = schema._def;
|
|
29
29
|
if (typeName === "optional" ||
|
|
30
30
|
typeName === "ZodOptional" ||
|
|
@@ -51,7 +51,7 @@ function isZodDate(schema) {
|
|
|
51
51
|
* Gets the shape of a Zod object schema (supports both Zod 3 and Zod 4)
|
|
52
52
|
*/
|
|
53
53
|
function getObjectShape(schema) {
|
|
54
|
-
//
|
|
54
|
+
// biome-ignore lint/suspicious/noExplicitAny: accessing Zod internal _def which differs between v3/v4
|
|
55
55
|
const def = schema._def;
|
|
56
56
|
// Zod 4: def.shape is an object
|
|
57
57
|
// Zod 3: def.shape() is a function
|
|
@@ -65,6 +65,7 @@ function getObjectShape(schema) {
|
|
|
65
65
|
* Converts ISO date strings to Date objects only for z.date() fields.
|
|
66
66
|
* Leaves z.string() fields unchanged even if they contain ISO date strings.
|
|
67
67
|
*/
|
|
68
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: coercion logic requires branching per Zod type
|
|
68
69
|
export function coerceInputToSchema(input, schema) {
|
|
69
70
|
if (input === null || input === undefined || !schema) {
|
|
70
71
|
return input;
|
|
@@ -83,7 +84,7 @@ export function coerceInputToSchema(input, schema) {
|
|
|
83
84
|
}
|
|
84
85
|
// Handle arrays
|
|
85
86
|
if ((typeName === "array" || typeName === "ZodArray") && Array.isArray(input)) {
|
|
86
|
-
//
|
|
87
|
+
// biome-ignore lint/suspicious/noExplicitAny: accessing Zod internal _def for array element type
|
|
87
88
|
const def = unwrapped._def;
|
|
88
89
|
const elementSchema = def.type ?? def.element;
|
|
89
90
|
return input.map((item) => coerceInputToSchema(item, elementSchema));
|
|
@@ -96,15 +97,13 @@ export function coerceInputToSchema(input, schema) {
|
|
|
96
97
|
const result = {};
|
|
97
98
|
for (const [key, value] of Object.entries(input)) {
|
|
98
99
|
const fieldSchema = shape[key];
|
|
99
|
-
result[key] = fieldSchema
|
|
100
|
-
? coerceInputToSchema(value, fieldSchema)
|
|
101
|
-
: value;
|
|
100
|
+
result[key] = fieldSchema ? coerceInputToSchema(value, fieldSchema) : value;
|
|
102
101
|
}
|
|
103
102
|
return result;
|
|
104
103
|
}
|
|
105
104
|
// Handle unions (e.g., z.union([z.string(), z.date()]))
|
|
106
105
|
if ((typeName === "union" || typeName === "ZodUnion") && typeof input === "string") {
|
|
107
|
-
//
|
|
106
|
+
// biome-ignore lint/suspicious/noExplicitAny: accessing Zod internal _def for union options
|
|
108
107
|
const def = unwrapped._def;
|
|
109
108
|
const options = def.options;
|
|
110
109
|
if (options) {
|
|
@@ -137,15 +136,20 @@ export function splitProcedurePath(path) {
|
|
|
137
136
|
* const result = await caller("orders.list", { limit: 10 });
|
|
138
137
|
* ```
|
|
139
138
|
*/
|
|
140
|
-
export function createDynamicCaller(
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
export function createDynamicCaller(
|
|
140
|
+
// biome-ignore lint/suspicious/noExplicitAny: tRPC router type is not well-typed at runtime
|
|
141
|
+
router,
|
|
142
|
+
// biome-ignore lint/suspicious/noExplicitAny: tRPC context type is not well-typed at runtime
|
|
143
|
+
ctx) {
|
|
143
144
|
const caller = router.createCaller(ctx);
|
|
144
145
|
// Get procedure definitions for schema lookup
|
|
145
|
-
|
|
146
|
+
// biome-ignore lint/suspicious/noExplicitAny: tRPC procedure defs are untyped at runtime
|
|
147
|
+
const procedures = router._def.procedures;
|
|
148
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: dynamic caller requires path traversal with validation
|
|
146
149
|
return async (name, input) => {
|
|
147
150
|
const pathParts = splitProcedurePath(name);
|
|
148
|
-
|
|
151
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamically traversing tRPC caller object
|
|
152
|
+
let current = caller;
|
|
149
153
|
// Drill down to the target procedure
|
|
150
154
|
for (let i = 0; i < pathParts.length - 1; i++) {
|
|
151
155
|
const part = pathParts[i];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC9E,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAGhE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC9E,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAGhE,YAAY,EACV,eAAe,EACf,cAAc,EACd,cAAc,EACd,YAAY,EACZ,SAAS,EACT,aAAa,EACb,UAAU,EACV,YAAY,GACb,MAAM,2BAA2B,CAAC"}
|
package/dist/introspect.js
CHANGED
|
@@ -5,7 +5,7 @@ import { toJSONSchema } from "zod";
|
|
|
5
5
|
function getRuntimeProcedures(router) {
|
|
6
6
|
const procedures = router._def.procedures;
|
|
7
7
|
return Object.entries(procedures).map(([path, proc]) => {
|
|
8
|
-
//
|
|
8
|
+
// biome-ignore lint/suspicious/noExplicitAny: tRPC procedure _def is untyped
|
|
9
9
|
const def = proc._def;
|
|
10
10
|
return {
|
|
11
11
|
path,
|
|
@@ -52,7 +52,7 @@ export function buildToolManifest(router, opts = {}) {
|
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
54
54
|
// If disallowedProcedures is set, procedure must not be in the list
|
|
55
|
-
if (disallowedSet
|
|
55
|
+
if (disallowedSet?.has(p.path)) {
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
58
|
return true;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yak-io/trpc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "tRPC adapter for yak chatbot - enables tRPC procedures as chatbot tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
7
7
|
"author": "Yak <support@yak.io>",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/
|
|
10
|
+
"url": "https://github.com/388-labs/yak.git",
|
|
11
11
|
"directory": "packages/trpc"
|
|
12
12
|
},
|
|
13
13
|
"publishConfig": {
|
|
@@ -40,21 +40,23 @@
|
|
|
40
40
|
"./package.json": "./package.json"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@yak-io/javascript": "0.
|
|
43
|
+
"@yak-io/javascript": "0.4.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@trpc/server": "^10.0.0 || ^11.0.0",
|
|
47
47
|
"zod": "^4.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@trpc/server": "^11.
|
|
51
|
-
"@types/node": "^24.10.
|
|
50
|
+
"@trpc/server": "^11.11.0",
|
|
51
|
+
"@types/node": "^24.10.4",
|
|
52
52
|
"typescript": "^5.3.0",
|
|
53
|
-
"zod": "^4.
|
|
53
|
+
"zod": "^4.3.6",
|
|
54
54
|
"@repo/typescript-config": "0.0.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "tsc",
|
|
58
|
-
"check-types": "tsc --noEmit"
|
|
58
|
+
"check-types": "tsc --noEmit",
|
|
59
|
+
"lint": "biome lint ./src --fix",
|
|
60
|
+
"format": "biome format ./src --write"
|
|
59
61
|
}
|
|
60
62
|
}
|