@zapier/zapier-sdk 0.8.3 → 0.10.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/CHANGELOG.md +18 -0
- package/README.md +17 -40
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +14 -0
- package/dist/api/debug.d.ts +1 -0
- package/dist/api/debug.d.ts.map +1 -1
- package/dist/api/debug.js +42 -1
- package/dist/api/debug.test.d.ts +2 -0
- package/dist/api/debug.test.d.ts.map +1 -0
- package/dist/api/debug.test.js +59 -0
- package/dist/api/schemas.d.ts +451 -251
- package/dist/api/schemas.d.ts.map +1 -1
- package/dist/api/schemas.js +51 -29
- package/dist/index.cjs +1149 -751
- package/dist/index.d.mts +2359 -2161
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.mjs +1143 -743
- package/dist/plugins/apps/index.d.ts +4 -0
- package/dist/plugins/apps/index.d.ts.map +1 -1
- package/dist/plugins/findFirstAuthentication/index.d.ts +1 -1
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findFirstAuthentication/index.js +9 -1
- package/dist/plugins/findFirstAuthentication/index.test.js +3 -4
- package/dist/plugins/findFirstAuthentication/schemas.d.ts +5 -3
- package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -1
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findUniqueAuthentication/index.js +4 -0
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts +5 -3
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -1
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +10 -0
- package/dist/plugins/getAction/schemas.d.ts +5 -3
- package/dist/plugins/getAction/schemas.d.ts.map +1 -1
- package/dist/plugins/getApp/index.d.ts +2 -7
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +17 -9
- package/dist/plugins/getApp/index.test.js +3 -3
- package/dist/plugins/getApp/schemas.d.ts +3 -1
- package/dist/plugins/getApp/schemas.d.ts.map +1 -1
- package/dist/plugins/getApp/schemas.js +2 -4
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/index.js +8 -0
- package/dist/plugins/getAuthentication/index.test.js +1 -1
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +4 -0
- package/dist/plugins/getProfile/schemas.d.ts.map +1 -1
- package/dist/plugins/getProfile/schemas.js +4 -3
- package/dist/plugins/listActions/index.d.ts +2 -4
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +10 -1
- package/dist/plugins/listActions/index.test.js +4 -4
- package/dist/plugins/listActions/schemas.d.ts +5 -3
- package/dist/plugins/listActions/schemas.d.ts.map +1 -1
- package/dist/plugins/listActions/schemas.js +2 -4
- package/dist/plugins/listApps/index.d.ts +4 -7
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +37 -17
- package/dist/plugins/listApps/index.test.js +23 -3
- package/dist/plugins/listApps/schemas.d.ts.map +1 -1
- package/dist/plugins/listApps/schemas.js +3 -9
- package/dist/plugins/listAuthentications/index.d.ts +2 -4
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/index.js +12 -0
- package/dist/plugins/listAuthentications/index.test.js +39 -13
- package/dist/plugins/listAuthentications/schemas.d.ts +8 -3
- package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/schemas.js +4 -0
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +14 -2
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +5 -3
- package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/schemas.js +10 -19
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +14 -2
- package/dist/plugins/listInputFields/index.test.js +5 -9
- package/dist/plugins/listInputFields/schemas.d.ts +5 -3
- package/dist/plugins/listInputFields/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/index.d.ts +25 -9
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +239 -67
- package/dist/plugins/manifest/index.test.js +426 -171
- package/dist/plugins/manifest/schemas.d.ts +5 -1
- package/dist/plugins/manifest/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/schemas.js +1 -0
- package/dist/plugins/registry/index.d.ts.map +1 -1
- package/dist/plugins/registry/index.js +8 -2
- package/dist/plugins/request/index.d.ts.map +1 -1
- package/dist/plugins/request/index.js +1 -0
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +12 -0
- package/dist/plugins/runAction/schemas.d.ts +5 -3
- package/dist/plugins/runAction/schemas.d.ts.map +1 -1
- package/dist/resolvers/actionKey.d.ts +13 -7
- package/dist/resolvers/actionKey.d.ts.map +1 -1
- package/dist/resolvers/actionType.d.ts +8 -7
- package/dist/resolvers/actionType.d.ts.map +1 -1
- package/dist/resolvers/appKey.d.ts +2 -6
- package/dist/resolvers/appKey.d.ts.map +1 -1
- package/dist/resolvers/authenticationId.d.ts +7 -7
- package/dist/resolvers/authenticationId.d.ts.map +1 -1
- package/dist/resolvers/authenticationId.js +16 -7
- package/dist/resolvers/index.d.ts +3 -35
- package/dist/resolvers/index.d.ts.map +1 -1
- package/dist/resolvers/index.js +4 -87
- package/dist/resolvers/inputFieldKey.d.ts +11 -0
- package/dist/resolvers/inputFieldKey.d.ts.map +1 -0
- package/dist/resolvers/inputFieldKey.js +23 -0
- package/dist/resolvers/inputs.d.ts +11 -6
- package/dist/resolvers/inputs.d.ts.map +1 -1
- package/dist/resolvers/inputs.js +17 -0
- package/dist/schemas/Action.d.ts +8 -8
- package/dist/schemas/Action.d.ts.map +1 -1
- package/dist/schemas/Action.js +8 -3
- package/dist/schemas/App.d.ts +183 -11
- package/dist/schemas/App.d.ts.map +1 -1
- package/dist/schemas/App.js +7 -9
- package/dist/schemas/Auth.d.ts +12 -12
- package/dist/schemas/Auth.js +1 -1
- package/dist/schemas/Field.d.ts +5 -98
- package/dist/schemas/Field.d.ts.map +1 -1
- package/dist/schemas/Field.js +24 -52
- package/dist/schemas/Run.d.ts +3 -0
- package/dist/schemas/Run.d.ts.map +1 -0
- package/dist/schemas/Run.js +31 -0
- package/dist/schemas/UserProfile.d.ts +11 -11
- package/dist/schemas/UserProfile.d.ts.map +1 -1
- package/dist/schemas/UserProfile.js +21 -7
- package/dist/sdk.d.ts +15 -14
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1 -4
- package/dist/types/plugin.d.ts +6 -0
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/properties.d.ts +3 -1
- package/dist/types/properties.d.ts.map +1 -1
- package/dist/types/sdk.d.ts +11 -3
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/utils/domain-utils.d.ts +17 -16
- package/dist/utils/domain-utils.d.ts.map +1 -1
- package/dist/utils/domain-utils.js +53 -78
- package/dist/utils/domain-utils.test.js +157 -3
- package/dist/utils/file-utils.d.ts +4 -0
- package/dist/utils/file-utils.d.ts.map +1 -0
- package/dist/utils/file-utils.js +74 -0
- package/dist/utils/file-utils.test.d.ts +2 -0
- package/dist/utils/file-utils.test.d.ts.map +1 -0
- package/dist/utils/file-utils.test.js +51 -0
- package/dist/utils/schema-utils.d.ts +44 -21
- package/dist/utils/schema-utils.d.ts.map +1 -1
- package/dist/utils/schema-utils.js +17 -11
- package/package.json +1 -1
- package/src/api/client.ts +12 -0
- package/src/api/debug.test.ts +76 -0
- package/src/api/debug.ts +46 -2
- package/src/api/schemas.ts +51 -29
- package/src/index.ts +5 -6
- package/src/plugins/apps/index.ts +9 -2
- package/src/plugins/findFirstAuthentication/index.test.ts +8 -5
- package/src/plugins/findFirstAuthentication/index.ts +14 -2
- package/src/plugins/findUniqueAuthentication/index.ts +4 -0
- package/src/plugins/getAction/index.ts +14 -0
- package/src/plugins/getApp/index.test.ts +3 -3
- package/src/plugins/getApp/index.ts +20 -14
- package/src/plugins/getApp/schemas.ts +7 -12
- package/src/plugins/getAuthentication/index.test.ts +1 -1
- package/src/plugins/getAuthentication/index.ts +8 -0
- package/src/plugins/getProfile/index.ts +4 -0
- package/src/plugins/getProfile/schemas.ts +4 -6
- package/src/plugins/listActions/index.test.ts +8 -7
- package/src/plugins/listActions/index.ts +12 -3
- package/src/plugins/listActions/schemas.ts +20 -25
- package/src/plugins/listApps/index.test.ts +24 -3
- package/src/plugins/listApps/index.ts +50 -25
- package/src/plugins/listApps/schemas.ts +17 -26
- package/src/plugins/listAuthentications/index.test.ts +52 -15
- package/src/plugins/listAuthentications/index.ts +15 -2
- package/src/plugins/listAuthentications/schemas.ts +4 -0
- package/src/plugins/listInputFieldChoices/index.ts +21 -1
- package/src/plugins/listInputFieldChoices/schemas.ts +61 -76
- package/src/plugins/listInputFields/index.test.ts +5 -9
- package/src/plugins/listInputFields/index.ts +20 -2
- package/src/plugins/manifest/index.test.ts +503 -197
- package/src/plugins/manifest/index.ts +338 -82
- package/src/plugins/manifest/schemas.ts +9 -2
- package/src/plugins/registry/index.ts +8 -2
- package/src/plugins/request/index.ts +1 -0
- package/src/plugins/runAction/index.ts +18 -0
- package/src/resolvers/actionKey.ts +15 -13
- package/src/resolvers/actionType.ts +10 -12
- package/src/resolvers/appKey.ts +2 -6
- package/src/resolvers/authenticationId.ts +25 -19
- package/src/resolvers/index.ts +7 -113
- package/src/resolvers/inputFieldKey.ts +38 -0
- package/src/resolvers/inputs.ts +28 -10
- package/src/schemas/Action.ts +8 -3
- package/src/schemas/App.ts +7 -9
- package/src/schemas/Auth.ts +1 -1
- package/src/schemas/Field.ts +24 -57
- package/src/schemas/Run.ts +40 -0
- package/src/schemas/UserProfile.ts +24 -7
- package/src/sdk.ts +18 -12
- package/src/types/plugin.ts +8 -0
- package/src/types/sdk.ts +31 -21
- package/src/utils/domain-utils.test.ts +196 -2
- package/src/utils/domain-utils.ts +77 -102
- package/src/utils/file-utils.test.ts +73 -0
- package/src/utils/file-utils.ts +94 -0
- package/src/utils/schema-utils.ts +96 -44
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/plugins/lockVersion/index.d.ts +0 -24
- package/dist/plugins/lockVersion/index.d.ts.map +0 -1
- package/dist/plugins/lockVersion/index.js +0 -72
- package/dist/plugins/lockVersion/index.test.d.ts +0 -2
- package/dist/plugins/lockVersion/index.test.d.ts.map +0 -1
- package/dist/plugins/lockVersion/index.test.js +0 -129
- package/dist/plugins/lockVersion/schemas.d.ts +0 -10
- package/dist/plugins/lockVersion/schemas.d.ts.map +0 -1
- package/dist/plugins/lockVersion/schemas.js +0 -6
- package/src/plugins/lockVersion/index.test.ts +0 -176
- package/src/plugins/lockVersion/index.ts +0 -112
- package/src/plugins/lockVersion/schemas.ts +0 -9
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// In-memory filesystem fallback for browser environments
|
|
2
|
+
const inMemoryFiles: { [path: string]: string } = {};
|
|
3
|
+
|
|
4
|
+
// Lazy-loaded modules
|
|
5
|
+
let fsPromises: any = null;
|
|
6
|
+
let pathModule: any = null;
|
|
7
|
+
|
|
8
|
+
async function loadFsPromises() {
|
|
9
|
+
if (fsPromises) return fsPromises;
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
fsPromises = await import("fs/promises");
|
|
13
|
+
return fsPromises;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function loadPathModule() {
|
|
20
|
+
if (pathModule) return pathModule;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
pathModule = await import("path");
|
|
24
|
+
return pathModule;
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function resolve(
|
|
31
|
+
path: string,
|
|
32
|
+
basePath: string = "/",
|
|
33
|
+
): Promise<string> {
|
|
34
|
+
const pathModule = await loadPathModule();
|
|
35
|
+
|
|
36
|
+
if (pathModule) {
|
|
37
|
+
return pathModule.resolve(path);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Simple fallback path resolution assuming root "/" location
|
|
41
|
+
if (path.startsWith("/")) {
|
|
42
|
+
return path;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (path.startsWith("./")) {
|
|
46
|
+
// Remove ./ prefix and join to base
|
|
47
|
+
const cleanPath = path.slice(2);
|
|
48
|
+
return basePath.endsWith("/")
|
|
49
|
+
? basePath + cleanPath
|
|
50
|
+
: basePath + "/" + cleanPath;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (path.startsWith("../")) {
|
|
54
|
+
// Remove ../ prefix since we're already at root
|
|
55
|
+
const cleanPath = path.replace(/^(\.\.\/)+/, "");
|
|
56
|
+
return basePath.endsWith("/")
|
|
57
|
+
? basePath + cleanPath
|
|
58
|
+
: basePath + "/" + cleanPath;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// No slash prefix, join to base
|
|
62
|
+
return basePath.endsWith("/") ? basePath + path : basePath + "/" + path;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function writeFile(
|
|
66
|
+
filePath: string,
|
|
67
|
+
content: string,
|
|
68
|
+
): Promise<void> {
|
|
69
|
+
const fs = await loadFsPromises();
|
|
70
|
+
|
|
71
|
+
if (fs) {
|
|
72
|
+
await fs.writeFile(filePath, content, "utf8");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Fallback to in-memory filesystem
|
|
77
|
+
inMemoryFiles[filePath] = content;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function readFile(filePath: string): Promise<string> {
|
|
81
|
+
const fs = await loadFsPromises();
|
|
82
|
+
|
|
83
|
+
if (fs) {
|
|
84
|
+
return await fs.readFile(filePath, "utf8");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Fallback to in-memory filesystem
|
|
88
|
+
const content = inMemoryFiles[filePath];
|
|
89
|
+
if (content !== undefined) {
|
|
90
|
+
return content;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
throw new Error(`File not found: ${filePath}`);
|
|
94
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import type { ZapierSdk } from "../types/sdk";
|
|
3
|
+
import type { InputFieldItem } from "../schemas/Field";
|
|
2
4
|
|
|
3
5
|
// ============================================================================
|
|
4
6
|
// Format Metadata Types
|
|
@@ -6,92 +8,121 @@ import { z } from "zod";
|
|
|
6
8
|
|
|
7
9
|
export interface FormattedItem {
|
|
8
10
|
title: string;
|
|
9
|
-
|
|
11
|
+
id?: string;
|
|
12
|
+
key?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
data?: unknown; // Optional: if provided, CLI will use formatJsonOutput instead of details
|
|
10
15
|
details: Array<{
|
|
11
16
|
text: string;
|
|
12
17
|
style: "normal" | "dim" | "accent" | "warning" | "success";
|
|
13
18
|
}>;
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
export interface FormatMetadata {
|
|
17
|
-
format: (item:
|
|
21
|
+
export interface FormatMetadata<TItem = unknown> {
|
|
22
|
+
format: (item: TItem) => FormattedItem;
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
// Helper function to add format metadata to schemas
|
|
21
26
|
export function withFormatter<T extends z.ZodType>(
|
|
22
27
|
schema: T,
|
|
23
|
-
formatMeta: FormatMetadata
|
|
28
|
+
formatMeta: FormatMetadata<z.infer<T>>,
|
|
24
29
|
): T {
|
|
25
30
|
// Store format metadata on the schema definition
|
|
26
|
-
(schema._def
|
|
27
|
-
|
|
31
|
+
Object.assign(schema._def, {
|
|
32
|
+
formatMeta: formatMeta,
|
|
33
|
+
});
|
|
34
|
+
return schema as T & {
|
|
35
|
+
_def: T["_def"] & { formatMeta: FormatMetadata<z.infer<T>> };
|
|
36
|
+
};
|
|
28
37
|
}
|
|
29
38
|
|
|
30
|
-
// Helper function to get
|
|
31
|
-
export function
|
|
32
|
-
|
|
33
|
-
): FormatMetadata | undefined {
|
|
34
|
-
return (schema._def as any).formatMeta;
|
|
39
|
+
// Helper function to get output schema from an input schema
|
|
40
|
+
export function getOutputSchema(inputSchema: z.ZodType): z.ZodType | undefined {
|
|
41
|
+
return (inputSchema._def as { outputSchema?: z.ZodType }).outputSchema;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
// Helper function to link input schemas to output schemas
|
|
38
45
|
export function withOutputSchema<T extends z.ZodType>(
|
|
39
46
|
inputSchema: T,
|
|
40
47
|
outputSchema: z.ZodType,
|
|
41
|
-
): T {
|
|
48
|
+
): T & {
|
|
49
|
+
_def: T["_def"] & { outputSchema: z.ZodType };
|
|
50
|
+
} {
|
|
42
51
|
// Store output schema reference on the input schema
|
|
43
|
-
(inputSchema._def
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return (inputSchema._def as any).outputSchema;
|
|
52
|
+
Object.assign(inputSchema._def, {
|
|
53
|
+
outputSchema,
|
|
54
|
+
});
|
|
55
|
+
return inputSchema as T & {
|
|
56
|
+
_def: T["_def"] & { outputSchema: z.ZodType };
|
|
57
|
+
};
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
// ============================================================================
|
|
53
61
|
// Resolution Metadata Types
|
|
54
62
|
// ============================================================================
|
|
55
63
|
|
|
56
|
-
export interface
|
|
64
|
+
export interface PromptConfig {
|
|
65
|
+
type: "list";
|
|
66
|
+
name: string;
|
|
67
|
+
message: string;
|
|
68
|
+
choices: Array<{
|
|
69
|
+
name: string;
|
|
70
|
+
value: unknown;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface Resolver {
|
|
75
|
+
type: string;
|
|
76
|
+
depends?: readonly string[] | string[]; // Parameters this resolver depends on
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface StaticResolver extends Resolver {
|
|
57
80
|
type: "static";
|
|
58
81
|
inputType?: "text" | "password" | "email";
|
|
59
82
|
placeholder?: string;
|
|
60
83
|
}
|
|
61
84
|
|
|
62
|
-
export interface DynamicResolver
|
|
85
|
+
export interface DynamicResolver<
|
|
86
|
+
TItem = unknown,
|
|
87
|
+
TParams = Record<string, unknown>,
|
|
88
|
+
> extends Resolver {
|
|
63
89
|
type: "dynamic";
|
|
64
|
-
fetch: (sdk:
|
|
65
|
-
prompt: (items:
|
|
66
|
-
depends?: string[]; // Parameters this resolver depends on
|
|
90
|
+
fetch: (sdk: ZapierSdk, resolvedParams: TParams) => Promise<TItem[]>; // Function to fetch data using SDK
|
|
91
|
+
prompt: (items: TItem[], params: TParams) => PromptConfig;
|
|
67
92
|
}
|
|
68
93
|
|
|
69
|
-
export interface FieldsResolver
|
|
94
|
+
export interface FieldsResolver<TParams = Record<string, unknown>>
|
|
95
|
+
extends Resolver {
|
|
70
96
|
type: "fields";
|
|
71
|
-
fetch: (sdk:
|
|
72
|
-
depends?: string[]; // Parameters this resolver depends on
|
|
97
|
+
fetch: (sdk: ZapierSdk, resolvedParams: TParams) => Promise<InputFieldItem[]>; // Function to fetch fields using SDK
|
|
73
98
|
}
|
|
74
99
|
|
|
75
|
-
export type ResolverMetadata
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
100
|
+
export type ResolverMetadata<
|
|
101
|
+
TItem = unknown,
|
|
102
|
+
TParams = Record<string, unknown>,
|
|
103
|
+
> = StaticResolver | DynamicResolver<TItem, TParams> | FieldsResolver<TParams>;
|
|
79
104
|
|
|
80
105
|
// Wrapper interface for resolver metadata to allow future extensibility
|
|
81
|
-
export interface ResolverConfig
|
|
82
|
-
|
|
106
|
+
export interface ResolverConfig<
|
|
107
|
+
TItem = unknown,
|
|
108
|
+
TParams = Record<string, unknown>,
|
|
109
|
+
> {
|
|
110
|
+
resolver: ResolverMetadata<TItem, TParams>;
|
|
83
111
|
// Future metadata types can be added here:
|
|
84
112
|
// validation?: ValidationMetadata;
|
|
85
113
|
// display?: DisplayMetadata;
|
|
86
114
|
}
|
|
87
115
|
|
|
88
116
|
// Helper function to add resolver metadata to schemas
|
|
89
|
-
export function withResolver<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
117
|
+
export function withResolver<
|
|
118
|
+
T extends z.ZodType,
|
|
119
|
+
TItem = unknown,
|
|
120
|
+
TParams = Record<string, unknown>,
|
|
121
|
+
>(schema: T, config: ResolverConfig<TItem, TParams>): T {
|
|
93
122
|
// Store resolver metadata on the schema definition
|
|
94
|
-
(
|
|
123
|
+
(
|
|
124
|
+
schema._def as { resolverMeta?: ResolverConfig<TItem, TParams> }
|
|
125
|
+
).resolverMeta = config;
|
|
95
126
|
return schema;
|
|
96
127
|
}
|
|
97
128
|
|
|
@@ -104,7 +135,7 @@ export function getSchemaDescription(schema: z.ZodSchema): string | undefined {
|
|
|
104
135
|
}
|
|
105
136
|
|
|
106
137
|
export function getFieldDescriptions(
|
|
107
|
-
schema: z.ZodObject<
|
|
138
|
+
schema: z.ZodObject<z.ZodRawShape>,
|
|
108
139
|
): Record<string, string> {
|
|
109
140
|
const descriptions: Record<string, string> = {};
|
|
110
141
|
const shape = schema.shape;
|
|
@@ -123,20 +154,41 @@ export function getFieldDescriptions(
|
|
|
123
154
|
// ============================================================================
|
|
124
155
|
|
|
125
156
|
export interface PositionalMetadata {
|
|
126
|
-
|
|
157
|
+
positionalMeta: {
|
|
158
|
+
positional: true;
|
|
159
|
+
};
|
|
127
160
|
}
|
|
128
161
|
|
|
129
162
|
// Helper function to mark a parameter as positional for CLI
|
|
130
|
-
export function withPositional<T extends z.ZodType>(
|
|
163
|
+
export function withPositional<T extends z.ZodType>(
|
|
164
|
+
schema: T,
|
|
165
|
+
): T & {
|
|
166
|
+
_def: T["_def"] & PositionalMetadata;
|
|
167
|
+
} {
|
|
131
168
|
// Store positional metadata on the schema definition
|
|
132
|
-
(schema._def
|
|
133
|
-
|
|
169
|
+
Object.assign(schema._def, {
|
|
170
|
+
positionalMeta: { positional: true },
|
|
171
|
+
} satisfies PositionalMetadata);
|
|
172
|
+
return schema as T & {
|
|
173
|
+
_def: T["_def"] & PositionalMetadata;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function schemaHasPositionalMeta<T extends z.ZodType>(
|
|
178
|
+
schema: T,
|
|
179
|
+
): schema is T & {
|
|
180
|
+
_def: T["_def"] & PositionalMetadata;
|
|
181
|
+
} {
|
|
182
|
+
return "positionalMeta" in schema._def;
|
|
134
183
|
}
|
|
135
184
|
|
|
136
185
|
// Helper function to check if a parameter should be positional
|
|
137
186
|
export function isPositional(schema: z.ZodType): boolean {
|
|
138
187
|
// Check the current schema first
|
|
139
|
-
if (
|
|
188
|
+
if (
|
|
189
|
+
schemaHasPositionalMeta(schema) &&
|
|
190
|
+
schema._def.positionalMeta?.positional
|
|
191
|
+
) {
|
|
140
192
|
return true;
|
|
141
193
|
}
|
|
142
194
|
|