ont-run 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.
@@ -6,6 +6,8 @@ export interface BrowserServerOptions {
6
6
  diff?: OntologyDiff | null;
7
7
  /** Directory to write the lockfile to on approval */
8
8
  configDir?: string;
9
+ /** Path to the ontology.config.ts file */
10
+ configPath?: string;
9
11
  port?: number;
10
12
  openBrowser?: boolean;
11
13
  }
@@ -11,7 +11,6 @@ export interface GraphNode {
11
11
  metadata: {
12
12
  inputs?: Record<string, unknown>;
13
13
  outputs?: Record<string, unknown>;
14
- resolver?: string;
15
14
  functionCount?: number;
16
15
  usesUserContext?: boolean;
17
16
  };
@@ -1,4 +1,5 @@
1
- import type { OntologyConfig, FunctionDefinition, AccessGroupConfig, EnvironmentConfig, EntityDefinition, AuthFunction } from "./types.js";
1
+ import { z } from "zod";
2
+ import type { OntologyConfig, FunctionDefinition, AccessGroupConfig, EnvironmentConfig, EntityDefinition, AuthFunction, ResolverFunction } from "./types.js";
2
3
  /**
3
4
  * Define an Ontology configuration with full type inference.
4
5
  *
@@ -6,6 +7,7 @@ import type { OntologyConfig, FunctionDefinition, AccessGroupConfig, Environment
6
7
  * ```ts
7
8
  * import { defineOntology, fieldFrom } from 'ont-run';
8
9
  * import { z } from 'zod';
10
+ * import { getUser } from './resolvers/getUser.js';
9
11
  *
10
12
  * export default defineOntology({
11
13
  * name: 'my-api',
@@ -30,13 +32,13 @@ import type { OntologyConfig, FunctionDefinition, AccessGroupConfig, Environment
30
32
  * access: ['public', 'admin'],
31
33
  * entities: ['User'],
32
34
  * inputs: z.object({ id: z.string() }),
33
- * resolver: './resolvers/getUser.ts',
35
+ * resolver: getUser, // Direct function reference for type safety
34
36
  * },
35
37
  * },
36
38
  * });
37
39
  * ```
38
40
  */
39
- export declare function defineOntology<TGroups extends string, TEntities extends string, TFunctions extends Record<string, FunctionDefinition<TGroups, TEntities>>>(config: {
41
+ export declare function defineOntology<TGroups extends string, TEntities extends string, TFunctions extends Record<string, FunctionDefinition<TGroups, TEntities, any, any>>>(config: {
40
42
  name: string;
41
43
  environments: Record<string, EnvironmentConfig>;
42
44
  auth: AuthFunction;
@@ -44,3 +46,36 @@ export declare function defineOntology<TGroups extends string, TEntities extends
44
46
  entities?: Record<TEntities, EntityDefinition>;
45
47
  functions: TFunctions;
46
48
  }): OntologyConfig<TGroups, TEntities, TFunctions>;
49
+ /**
50
+ * Define a function with full type inference for resolver type safety.
51
+ *
52
+ * This helper ensures that the resolver function's return type matches
53
+ * the outputs Zod schema at compile time.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { defineFunction, z } from 'ont-run';
58
+ * import type { ResolverContext } from 'ont-run';
59
+ *
60
+ * const getUser = defineFunction({
61
+ * description: 'Get a user by ID',
62
+ * access: ['public', 'admin'] as const,
63
+ * entities: ['User'] as const,
64
+ * inputs: z.object({ id: z.string() }),
65
+ * outputs: z.object({ id: z.string(), name: z.string() }),
66
+ * resolver: async (ctx, args) => {
67
+ * // TypeScript knows args is { id: string }
68
+ * // TypeScript enforces return type is { id: string, name: string }
69
+ * return { id: args.id, name: 'Example User' };
70
+ * },
71
+ * });
72
+ * ```
73
+ */
74
+ export declare function defineFunction<TGroups extends string, TEntities extends string, TInputs extends z.ZodType, TOutputs extends z.ZodType>(config: {
75
+ description: string;
76
+ access: readonly TGroups[];
77
+ entities: readonly TEntities[];
78
+ inputs: TInputs;
79
+ outputs?: TOutputs;
80
+ resolver: ResolverFunction<z.infer<TInputs>, z.infer<TOutputs>>;
81
+ }): FunctionDefinition<TGroups, TEntities, TInputs, TOutputs>;
@@ -5,60 +5,30 @@ import type { OntologyConfig } from "./types.js";
5
5
  */
6
6
  export declare const EnvironmentConfigSchema: z.ZodObject<{
7
7
  debug: z.ZodOptional<z.ZodBoolean>;
8
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
9
- debug: z.ZodOptional<z.ZodBoolean>;
10
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
11
- debug: z.ZodOptional<z.ZodBoolean>;
12
- }, z.ZodTypeAny, "passthrough">>;
8
+ }, z.core.$loose>;
13
9
  /**
14
10
  * Schema for access group configuration
15
11
  */
16
12
  export declare const AccessGroupConfigSchema: z.ZodObject<{
17
13
  description: z.ZodString;
18
- }, "strip", z.ZodTypeAny, {
19
- description: string;
20
- }, {
21
- description: string;
22
- }>;
14
+ }, z.core.$strip>;
23
15
  /**
24
16
  * Schema for entity definition
25
17
  */
26
18
  export declare const EntityDefinitionSchema: z.ZodObject<{
27
19
  description: z.ZodString;
28
- }, "strip", z.ZodTypeAny, {
29
- description: string;
30
- }, {
31
- description: string;
32
- }>;
20
+ }, z.core.$strip>;
33
21
  /**
34
22
  * Schema for function definition
35
23
  */
36
24
  export declare const FunctionDefinitionSchema: z.ZodObject<{
37
25
  description: z.ZodString;
38
- access: z.ZodArray<z.ZodString, "many">;
39
- entities: z.ZodArray<z.ZodString, "many">;
40
- inputs: z.ZodType<z.ZodType<any, z.ZodTypeDef, any>, z.ZodTypeDef, z.ZodType<any, z.ZodTypeDef, any>>;
41
- outputs: z.ZodOptional<z.ZodType<z.ZodType<any, z.ZodTypeDef, any>, z.ZodTypeDef, z.ZodType<any, z.ZodTypeDef, any>>>;
42
- resolver: z.ZodString;
43
- }, "strip", z.ZodTypeAny, {
44
- description: string;
45
- access: string[];
46
- entities: string[];
47
- inputs: z.ZodType<any, z.ZodTypeDef, any>;
48
- resolver: string;
49
- outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
50
- }, {
51
- description: string;
52
- access: string[];
53
- entities: string[];
54
- inputs: z.ZodType<any, z.ZodTypeDef, any>;
55
- resolver: string;
56
- outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
57
- }>;
58
- /**
59
- * Schema for auth function
60
- */
61
- export declare const AuthFunctionSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<Request, z.ZodTypeDef, Request>], z.ZodUnknown>, z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodPromise<z.ZodArray<z.ZodString, "many">>]>>;
26
+ access: z.ZodArray<z.ZodString>;
27
+ entities: z.ZodArray<z.ZodString>;
28
+ inputs: z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
29
+ outputs: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
30
+ resolver: z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>;
31
+ }, z.core.$strip>;
62
32
  /**
63
33
  * Schema for the full ontology configuration
64
34
  */
@@ -66,89 +36,23 @@ export declare const OntologyConfigSchema: z.ZodObject<{
66
36
  name: z.ZodString;
67
37
  environments: z.ZodRecord<z.ZodString, z.ZodObject<{
68
38
  debug: z.ZodOptional<z.ZodBoolean>;
69
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
70
- debug: z.ZodOptional<z.ZodBoolean>;
71
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
72
- debug: z.ZodOptional<z.ZodBoolean>;
73
- }, z.ZodTypeAny, "passthrough">>>;
74
- auth: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
39
+ }, z.core.$loose>>;
40
+ auth: z.ZodCustom<(req: Request) => unknown, (req: Request) => unknown>;
75
41
  accessGroups: z.ZodRecord<z.ZodString, z.ZodObject<{
76
42
  description: z.ZodString;
77
- }, "strip", z.ZodTypeAny, {
78
- description: string;
79
- }, {
80
- description: string;
81
- }>>;
43
+ }, z.core.$strip>>;
82
44
  entities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
83
45
  description: z.ZodString;
84
- }, "strip", z.ZodTypeAny, {
85
- description: string;
86
- }, {
87
- description: string;
88
- }>>>;
46
+ }, z.core.$strip>>>;
89
47
  functions: z.ZodRecord<z.ZodString, z.ZodObject<{
90
48
  description: z.ZodString;
91
- access: z.ZodArray<z.ZodString, "many">;
92
- entities: z.ZodArray<z.ZodString, "many">;
93
- inputs: z.ZodType<z.ZodType<any, z.ZodTypeDef, any>, z.ZodTypeDef, z.ZodType<any, z.ZodTypeDef, any>>;
94
- outputs: z.ZodOptional<z.ZodType<z.ZodType<any, z.ZodTypeDef, any>, z.ZodTypeDef, z.ZodType<any, z.ZodTypeDef, any>>>;
95
- resolver: z.ZodString;
96
- }, "strip", z.ZodTypeAny, {
97
- description: string;
98
- access: string[];
99
- entities: string[];
100
- inputs: z.ZodType<any, z.ZodTypeDef, any>;
101
- resolver: string;
102
- outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
103
- }, {
104
- description: string;
105
- access: string[];
106
- entities: string[];
107
- inputs: z.ZodType<any, z.ZodTypeDef, any>;
108
- resolver: string;
109
- outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
110
- }>>;
111
- }, "strip", z.ZodTypeAny, {
112
- name: string;
113
- environments: Record<string, z.objectOutputType<{
114
- debug: z.ZodOptional<z.ZodBoolean>;
115
- }, z.ZodTypeAny, "passthrough">>;
116
- auth: (...args: unknown[]) => unknown;
117
- accessGroups: Record<string, {
118
- description: string;
119
- }>;
120
- functions: Record<string, {
121
- description: string;
122
- access: string[];
123
- entities: string[];
124
- inputs: z.ZodType<any, z.ZodTypeDef, any>;
125
- resolver: string;
126
- outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
127
- }>;
128
- entities?: Record<string, {
129
- description: string;
130
- }> | undefined;
131
- }, {
132
- name: string;
133
- environments: Record<string, z.objectInputType<{
134
- debug: z.ZodOptional<z.ZodBoolean>;
135
- }, z.ZodTypeAny, "passthrough">>;
136
- auth: (...args: unknown[]) => unknown;
137
- accessGroups: Record<string, {
138
- description: string;
139
- }>;
140
- functions: Record<string, {
141
- description: string;
142
- access: string[];
143
- entities: string[];
144
- inputs: z.ZodType<any, z.ZodTypeDef, any>;
145
- resolver: string;
146
- outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
147
- }>;
148
- entities?: Record<string, {
149
- description: string;
150
- }> | undefined;
151
- }>;
49
+ access: z.ZodArray<z.ZodString>;
50
+ entities: z.ZodArray<z.ZodString>;
51
+ inputs: z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
52
+ outputs: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
53
+ resolver: z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>;
54
+ }, z.core.$strip>>;
55
+ }, z.core.$strip>;
152
56
  /**
153
57
  * Validate that all function access groups exist in accessGroups
154
58
  */
@@ -32,10 +32,32 @@ export interface FieldOption {
32
32
  /** Human-readable label for display */
33
33
  label: string;
34
34
  }
35
+ /**
36
+ * Context passed to resolvers
37
+ */
38
+ export interface ResolverContext {
39
+ /** Current environment name */
40
+ env: string;
41
+ /** Environment configuration */
42
+ envConfig: EnvironmentConfig;
43
+ /** Logger instance */
44
+ logger: {
45
+ info: (message: string, ...args: unknown[]) => void;
46
+ warn: (message: string, ...args: unknown[]) => void;
47
+ error: (message: string, ...args: unknown[]) => void;
48
+ debug: (message: string, ...args: unknown[]) => void;
49
+ };
50
+ /** Access groups for the current request */
51
+ accessGroups: string[];
52
+ }
53
+ /**
54
+ * Resolver function signature
55
+ */
56
+ export type ResolverFunction<TArgs = unknown, TResult = unknown> = (ctx: ResolverContext, args: TArgs) => Promise<TResult> | TResult;
35
57
  /**
36
58
  * Definition of a function in the ontology
37
59
  */
38
- export interface FunctionDefinition<TGroups extends string = string, TEntities extends string = string> {
60
+ export interface FunctionDefinition<TGroups extends string = string, TEntities extends string = string, TInputs extends z.ZodType = z.ZodType<unknown>, TOutputs extends z.ZodType = z.ZodType<unknown>> {
39
61
  /** Human-readable description of what this function does */
40
62
  description: string;
41
63
  /** Which access groups can call this function */
@@ -43,11 +65,11 @@ export interface FunctionDefinition<TGroups extends string = string, TEntities e
43
65
  /** Which entities this function relates to (use empty array [] if none) */
44
66
  entities: TEntities[];
45
67
  /** Zod schema for input validation */
46
- inputs: z.ZodType<unknown>;
68
+ inputs: TInputs;
47
69
  /** Zod schema for output validation/documentation */
48
- outputs?: z.ZodType<unknown>;
49
- /** Path to the resolver file (relative to ontology.config.ts) */
50
- resolver: string;
70
+ outputs?: TOutputs;
71
+ /** Resolver function that handles this function's logic */
72
+ resolver: ResolverFunction<z.infer<TInputs>, z.infer<TOutputs>>;
51
73
  }
52
74
  /**
53
75
  * Result returned by the auth function
@@ -82,25 +104,3 @@ export interface OntologyConfig<TGroups extends string = string, TEntities exten
82
104
  /** Function definitions */
83
105
  functions: TFunctions;
84
106
  }
85
- /**
86
- * Context passed to resolvers
87
- */
88
- export interface ResolverContext {
89
- /** Current environment name */
90
- env: string;
91
- /** Environment configuration */
92
- envConfig: EnvironmentConfig;
93
- /** Logger instance */
94
- logger: {
95
- info: (message: string, ...args: unknown[]) => void;
96
- warn: (message: string, ...args: unknown[]) => void;
97
- error: (message: string, ...args: unknown[]) => void;
98
- debug: (message: string, ...args: unknown[]) => void;
99
- };
100
- /** Access groups for the current request */
101
- accessGroups: string[];
102
- }
103
- /**
104
- * Resolver function signature
105
- */
106
- export type ResolverFunction<TArgs = unknown, TResult = unknown> = (ctx: ResolverContext, args: TArgs) => Promise<TResult> | TResult;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Utility functions for inspecting Zod schemas.
3
+ * These use duck typing to work across Zod 3 and Zod 4.
4
+ */
5
+ /**
6
+ * Check if a value is a Zod schema (duck typing to work across bundle boundaries and Zod versions)
7
+ */
8
+ export declare function isZodSchema(val: unknown): boolean;
9
+ /**
10
+ * Get the Zod type name from a schema (works with both Zod 3 and 4)
11
+ */
12
+ export declare function getZodTypeName(schema: unknown): string | undefined;
13
+ /**
14
+ * Check if schema is a ZodObject (works with both Zod 3 and 4)
15
+ */
16
+ export declare function isZodObject(schema: unknown): boolean;
17
+ /**
18
+ * Check if schema is a ZodOptional (works with both Zod 3 and 4)
19
+ */
20
+ export declare function isZodOptional(schema: unknown): boolean;
21
+ /**
22
+ * Check if schema is a ZodNullable (works with both Zod 3 and 4)
23
+ */
24
+ export declare function isZodNullable(schema: unknown): boolean;
25
+ /**
26
+ * Check if schema is a ZodArray (works with both Zod 3 and 4)
27
+ */
28
+ export declare function isZodArray(schema: unknown): boolean;
29
+ /**
30
+ * Check if schema is a ZodDefault (works with both Zod 3 and 4)
31
+ */
32
+ export declare function isZodDefault(schema: unknown): boolean;
33
+ /**
34
+ * Get the shape of a ZodObject schema (works with both Zod 3 and 4)
35
+ */
36
+ export declare function getObjectShape(schema: unknown): Record<string, unknown> | undefined;
37
+ /**
38
+ * Get the inner schema from Optional/Nullable/Default (works with both Zod 3 and 4)
39
+ */
40
+ export declare function getInnerSchema(schema: unknown): unknown;
41
+ /**
42
+ * Get the element schema from a ZodArray (works with both Zod 3 and 4)
43
+ */
44
+ export declare function getArrayElement(schema: unknown): unknown;
@@ -5,6 +5,7 @@
5
5
  * ```ts
6
6
  * import { defineOntology, fieldFrom } from 'ont-run';
7
7
  * import { z } from 'zod';
8
+ * import { hello } from './resolvers/hello.js';
8
9
  *
9
10
  * export default defineOntology({
10
11
  * name: 'my-api',
@@ -23,13 +24,13 @@
23
24
  * access: ['public'],
24
25
  * entities: [],
25
26
  * inputs: z.object({ name: z.string() }),
26
- * resolver: './resolvers/hello.ts',
27
+ * resolver: hello, // Direct function reference for type safety
27
28
  * },
28
29
  * },
29
30
  * });
30
31
  * ```
31
32
  */
32
- export { defineOntology } from "./config/define.js";
33
+ export { defineOntology, defineFunction } from "./config/define.js";
33
34
  export { fieldFrom, userContext } from "./config/categorical.js";
34
35
  export { startOnt } from "./server/start.js";
35
36
  export type { StartOntOptions, StartOntResult } from "./server/start.js";
@@ -4,8 +4,6 @@ import { type OntologyVariables } from "./middleware.js";
4
4
  export interface ApiServerOptions {
5
5
  /** The ontology configuration */
6
6
  config: OntologyConfig;
7
- /** Directory containing the ontology.config.ts (for resolving resolver paths) */
8
- configDir: string;
9
7
  /** Environment to use (e.g., 'dev', 'prod') */
10
8
  env: string;
11
9
  /** Enable CORS (default: true) */
@@ -4,7 +4,7 @@ import { type OntologyVariables } from "./middleware.js";
4
4
  /**
5
5
  * Create API routes from function definitions
6
6
  */
7
- export declare function createApiRoutes(config: OntologyConfig, configDir: string): Hono<{
7
+ export declare function createApiRoutes(config: OntologyConfig): Hono<{
8
8
  Variables: OntologyVariables;
9
9
  }>;
10
10
  /**
@@ -3,8 +3,6 @@ import type { OntologyConfig } from "../../config/types.js";
3
3
  export interface McpServerOptions {
4
4
  /** The ontology configuration */
5
5
  config: OntologyConfig;
6
- /** Directory containing the ontology.config.ts */
7
- configDir: string;
8
6
  /** Environment to use */
9
7
  env: string;
10
8
  /** Port for the MCP HTTP server */
@@ -1,5 +1,5 @@
1
1
  import type { OntologyConfig, EnvironmentConfig, AuthResult } from "../../config/types.js";
2
- import { type Logger } from "../resolver.js";
2
+ import type { Logger } from "../resolver.js";
3
3
  /**
4
4
  * Field reference info for MCP tools
5
5
  */
@@ -32,4 +32,4 @@ export declare function filterToolsByAccess(tools: McpTool[], accessGroups: stri
32
32
  /**
33
33
  * Create a tool executor function that accepts per-request auth result
34
34
  */
35
- export declare function createToolExecutor(config: OntologyConfig, configDir: string, env: string, envConfig: EnvironmentConfig, logger: Logger): (toolName: string, args: unknown, authResult: AuthResult) => Promise<unknown>;
35
+ export declare function createToolExecutor(config: OntologyConfig, env: string, envConfig: EnvironmentConfig, logger: Logger): (toolName: string, args: unknown, authResult: AuthResult) => Promise<unknown>;
@@ -1,20 +1,9 @@
1
- import type { ResolverFunction, OntologyConfig } from "../config/types.js";
1
+ import type { ResolverFunction } from "../config/types.js";
2
2
  /**
3
- * Load a resolver from a file path.
4
- * The path is relative to the config file location.
5
- *
6
- * @param resolverPath - Path to the resolver file (relative to configDir)
7
- * @param configDir - Directory containing the ontology.config.ts
3
+ * Get a resolver function. Since resolvers are now passed directly as functions,
4
+ * this is a simple passthrough that could be removed in the future.
8
5
  */
9
- export declare function loadResolver(resolverPath: string, configDir: string): Promise<ResolverFunction>;
10
- /**
11
- * Clear the resolver cache (useful for hot reloading)
12
- */
13
- export declare function clearResolverCache(): void;
14
- /**
15
- * Check which resolvers are missing and return their paths
16
- */
17
- export declare function findMissingResolvers(config: OntologyConfig, configDir: string): string[];
6
+ export declare function loadResolver(resolver: ResolverFunction): ResolverFunction;
18
7
  /**
19
8
  * Logger type returned by createLogger
20
9
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ont-run",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Ontology-enforced API framework for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {
@@ -35,8 +35,7 @@
35
35
  "consola": "^3.2.0",
36
36
  "hono": "^4.6.0",
37
37
  "open": "^10.0.0",
38
- "zod": "^3.24.0",
39
- "zod-to-json-schema": "^3.23.0"
38
+ "zod": "4"
40
39
  },
41
40
  "devDependencies": {
42
41
  "@types/bun": "latest",