@decocms/bindings 0.1.2 → 0.1.3

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.
@@ -9,30 +9,27 @@ var BaseCollectionEntitySchema = z.object({
9
9
  created_by: z.string().optional(),
10
10
  updated_by: z.string().optional()
11
11
  });
12
- var WhereExpressionSchema = z.lazy(
13
- () => z.union([
14
- // Simple comparison
15
- z.object({
16
- field: z.array(z.string()),
17
- operator: z.enum([
18
- "eq",
19
- "gt",
20
- "gte",
21
- "lt",
22
- "lte",
23
- "in",
24
- "like",
25
- "contains"
26
- ]),
27
- value: z.unknown()
28
- }),
29
- // Logical operators
30
- z.object({
31
- operator: z.enum(["and", "or", "not"]),
32
- conditions: z.array(WhereExpressionSchema)
33
- })
34
- ])
35
- );
12
+ var ComparisonExpressionSchema = z.object({
13
+ field: z.array(z.string()),
14
+ operator: z.enum([
15
+ "eq",
16
+ "gt",
17
+ "gte",
18
+ "lt",
19
+ "lte",
20
+ "in",
21
+ "like",
22
+ "contains"
23
+ ]),
24
+ value: z.unknown()
25
+ });
26
+ var WhereExpressionSchema = z.union([
27
+ ComparisonExpressionSchema,
28
+ z.object({
29
+ operator: z.enum(["and", "or", "not"]),
30
+ conditions: z.array(ComparisonExpressionSchema)
31
+ })
32
+ ]);
36
33
  var OrderByExpressionSchema = z.object({
37
34
  field: z.array(z.string()),
38
35
  direction: z.enum(["asc", "desc"]),
@@ -128,5 +125,5 @@ function createCollectionBindings(collectionName, entitySchema, options) {
128
125
  }
129
126
 
130
127
  export { BaseCollectionEntitySchema, CollectionDeleteInputSchema, CollectionDeleteOutputSchema, CollectionGetInputSchema, CollectionListInputSchema, OrderByExpressionSchema, WhereExpressionSchema, createCollectionBindings, createCollectionGetOutputSchema, createCollectionInsertInputSchema, createCollectionInsertOutputSchema, createCollectionListOutputSchema, createCollectionUpdateInputSchema, createCollectionUpdateOutputSchema };
131
- //# sourceMappingURL=chunk-IBOJHI67.js.map
132
- //# sourceMappingURL=chunk-IBOJHI67.js.map
128
+ //# sourceMappingURL=chunk-L7E6ONLJ.js.map
129
+ //# sourceMappingURL=chunk-L7E6ONLJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/well-known/collections.ts"],"names":[],"mappings":";;;AAsBO,IAAM,0BAAA,GAA6B,EAAE,MAAA,CAAO;AAAA,EACjD,EAAA,EAAI,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,kCAAkC,CAAA;AAAA,EAC1D,KAAA,EAAO,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,qCAAqC,CAAA;AAAA,EAChE,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACzB,CAAC;AAUD,IAAM,0BAAA,GAA6B,EAAE,MAAA,CAAO;AAAA,EAC1C,KAAA,EAAO,CAAA,CAAE,KAAA,CAAM,CAAA,CAAE,QAAQ,CAAA;AAAA,EACzB,QAAA,EAAU,EAAE,IAAA,CAAK;AAAA,IACf,IAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACD,CAAA;AAAA,EACD,KAAA,EAAO,EAAE,OAAA;AACX,CAAC,CAAA;AAMM,IAAM,qBAAA,GAAwB,EAAE,KAAA,CAAM;AAAA,EAC3C,0BAAA;AAAA,EACA,EAAE,MAAA,CAAO;AAAA,IACP,UAAU,CAAA,CAAE,IAAA,CAAK,CAAC,KAAA,EAAO,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IACrC,UAAA,EAAY,CAAA,CAAE,KAAA,CAAM,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from \"../core/binder\";\n\n/**\n * Collection Bindings\n *\n * This module provides standardized tool bindings for Collections, representing\n * SQL table-like structures with CRUD + Search operations compatible with TanStack DB.\n *\n * Key Features:\n * - Generic collection bindings that work with any entity type\n * - Standardized tool naming: `DECO_COLLECTION_{COLLECTION}_*`\n * - Compatible with TanStack DB query-collection\n * - Full TypeScript support with proper type constraints\n * - Support for filtering, sorting, and pagination\n * - Simple id and title fields for human-readable identification\n */\n\n/**\n * Base schema for collection entities\n * All collection entities must have an id, title, and audit trail fields\n */\nexport const BaseCollectionEntitySchema = z.object({\n id: z.string().describe(\"Unique identifier for the entity\"),\n title: z.string().describe(\"Human-readable title for the entity\"),\n created_at: z.string().datetime(),\n updated_at: z.string().datetime(),\n created_by: z.string().optional(),\n updated_by: z.string().optional(),\n});\n\n/**\n * Type helper for BaseCollectionEntitySchema\n */\nexport type BaseCollectionEntitySchemaType = typeof BaseCollectionEntitySchema;\n\n/**\n * Comparison expression schema for filtering\n */\nconst ComparisonExpressionSchema = z.object({\n field: z.array(z.string()),\n operator: z.enum([\n \"eq\",\n \"gt\",\n \"gte\",\n \"lt\",\n \"lte\",\n \"in\",\n \"like\",\n \"contains\",\n ]),\n value: z.unknown(),\n});\n\n/**\n * Where expression schema for filtering\n * Supports TanStack DB predicate push-down patterns\n */\nexport const WhereExpressionSchema = z.union([\n ComparisonExpressionSchema,\n z.object({\n operator: z.enum([\"and\", \"or\", \"not\"]),\n conditions: z.array(ComparisonExpressionSchema),\n }),\n]);\n\n/**\n * Where expression type for filtering\n * Derived from WhereExpressionSchema\n */\nexport type WhereExpression = z.infer<typeof WhereExpressionSchema>;\n\n/**\n * Order by expression for sorting\n */\nexport const OrderByExpressionSchema = z.object({\n field: z.array(z.string()),\n direction: z.enum([\"asc\", \"desc\"]),\n nulls: z.enum([\"first\", \"last\"]).optional(),\n});\n\n/**\n * List/Query input schema for collections\n * Compatible with TanStack DB LoadSubsetOptions\n */\nexport const CollectionListInputSchema = z.object({\n where: WhereExpressionSchema.optional().describe(\"Filter expression\"),\n orderBy: z\n .array(OrderByExpressionSchema)\n .optional()\n .describe(\"Sort expressions\"),\n limit: z\n .number()\n .int()\n .min(1)\n .max(1000)\n .optional()\n .describe(\"Maximum number of items to return\"),\n offset: z\n .number()\n .int()\n .min(0)\n .optional()\n .describe(\"Number of items to skip\"),\n});\n\n/**\n * Factory function to create list output schema for a specific collection type\n */\nexport function createCollectionListOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n items: z.array(entitySchema).describe(\"Array of collection items\"),\n totalCount: z\n .number()\n .int()\n .min(0)\n .optional()\n .describe(\"Total number of matching items (if available)\"),\n hasMore: z\n .boolean()\n .optional()\n .describe(\"Whether there are more items available\"),\n });\n}\n\n/**\n * Get by ID input schema\n */\nexport const CollectionGetInputSchema = z.object({\n id: z.string().describe(\"ID of the entity to retrieve\"),\n});\n\n/**\n * Factory function to create get output schema\n */\nexport function createCollectionGetOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n item: entitySchema\n .nullable()\n .describe(\"The retrieved item, or null if not found\"),\n });\n}\n\n/**\n * Factory function to create insert input schema\n */\nexport function createCollectionInsertInputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n // Remove id field since it may be auto-generated by the server\n return z.object({\n data: entitySchema.describe(\"Data for the new entity (id may be auto-generated)\"),\n });\n}\n\n/**\n * Factory function to create insert output schema\n */\nexport function createCollectionInsertOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n item: entitySchema.describe(\"The created entity with generated id\"),\n });\n}\n\n/**\n * Factory function to create update input schema\n */\nexport function createCollectionUpdateInputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n id: z.string().describe(\"ID of the entity to update\"),\n data: (entitySchema as unknown as z.AnyZodObject)\n .partial()\n .describe(\"Partial entity data to update\"),\n });\n}\n\n/**\n * Factory function to create update output schema\n */\nexport function createCollectionUpdateOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n item: entitySchema.describe(\"The updated entity\"),\n });\n}\n\n/**\n * Delete input schema\n */\nexport const CollectionDeleteInputSchema = z.object({\n id: z.string().describe(\"ID of the entity to delete\"),\n});\n\n/**\n * Delete output schema\n */\nexport const CollectionDeleteOutputSchema = z.object({\n success: z.boolean().describe(\"Whether the deletion was successful\"),\n id: z.string().describe(\"ID of the deleted entity\"),\n});\n\n/**\n * Options for creating collection bindings\n */\nexport interface CollectionBindingOptions {\n /**\n * If true, only LIST and GET operations will be included (read-only collection)\n * @default false\n */\n readOnly?: boolean;\n}\n\n/**\n * Creates generic collection bindings for a specific entity type\n *\n * This function generates standardized tool bindings that work with any collection/table\n * by accepting a custom entity schema and collection name. The bindings provide:\n * - DECO_COLLECTION_{NAME}_LIST - Query/search entities with filtering and sorting (required)\n * - DECO_COLLECTION_{NAME}_GET - Get a single entity by ID (required)\n * - DECO_COLLECTION_{NAME}_INSERT - Create a new entity (optional, excluded if readOnly=true)\n * - DECO_COLLECTION_{NAME}_UPDATE - Update an existing entity (optional, excluded if readOnly=true)\n * - DECO_COLLECTION_{NAME}_DELETE - Delete an entity (optional, excluded if readOnly=true)\n *\n * @param collectionName - The name of the collection/table (e.g., \"users\", \"products\", \"orders\")\n * @param entitySchema - The Zod schema for the entity type (must extend BaseCollectionEntitySchema)\n * @param options - Optional configuration for the collection bindings\n * @returns Array of tool bindings for Collection CRUD + Query operations\n *\n * @example\n * ```typescript\n * const UserSchema = z.object({\n * id: z.string(),\n * title: z.string(),\n * created_at: z.string().datetime(),\n * updated_at: z.string().datetime(),\n * created_by: z.string().optional(),\n * updated_by: z.string().optional(),\n * email: z.string().email(),\n * });\n *\n * // Full CRUD collection\n * const USER_COLLECTION_BINDING = createCollectionBindings(\"users\", UserSchema);\n *\n * // Read-only collection (only LIST and GET)\n * const READONLY_COLLECTION_BINDING = createCollectionBindings(\"products\", ProductSchema, { readOnly: true });\n * ```\n */\nexport function createCollectionBindings<\n TEntitySchema extends BaseCollectionEntitySchemaType,\n>(\n collectionName: string,\n entitySchema: TEntitySchema,\n options?: CollectionBindingOptions,\n) {\n const upperName = collectionName.toUpperCase();\n const readOnly = options?.readOnly ?? false;\n\n const bindings: ToolBinder[] = [\n {\n name: `DECO_COLLECTION_${upperName}_LIST` as const,\n inputSchema: CollectionListInputSchema,\n outputSchema: createCollectionListOutputSchema(entitySchema),\n },\n {\n name: `DECO_COLLECTION_${upperName}_GET` as const,\n inputSchema: CollectionGetInputSchema,\n outputSchema: createCollectionGetOutputSchema(entitySchema),\n },\n ];\n\n // Only include mutation operations if not read-only\n if (!readOnly) {\n bindings.push(\n {\n name: `DECO_COLLECTION_${upperName}_INSERT` as const,\n inputSchema: createCollectionInsertInputSchema(entitySchema),\n outputSchema: createCollectionInsertOutputSchema(entitySchema),\n opt: true,\n },\n {\n name: `DECO_COLLECTION_${upperName}_UPDATE` as const,\n inputSchema: createCollectionUpdateInputSchema(entitySchema),\n outputSchema: createCollectionUpdateOutputSchema(entitySchema),\n opt: true,\n },\n {\n name: `DECO_COLLECTION_${upperName}_DELETE` as const,\n inputSchema: CollectionDeleteInputSchema,\n outputSchema: CollectionDeleteOutputSchema,\n opt: true,\n },\n );\n }\n\n return bindings satisfies readonly ToolBinder[];\n}\n\n/**\n * Type helper to extract the collection binding type\n */\nexport type CollectionBinding<\n TEntitySchema extends BaseCollectionEntitySchemaType,\n> = ReturnType<typeof createCollectionBindings<TEntitySchema>>;\n\n/**\n * Type helper to extract tool names from a collection binding\n */\nexport type CollectionTools<\n TEntitySchema extends BaseCollectionEntitySchemaType,\n> = CollectionBinding<TEntitySchema>[number][\"name\"];\n\n// Export types for TypeScript usage\nexport type CollectionListInput = z.infer<typeof CollectionListInputSchema>;\nexport type CollectionGetInput = z.infer<typeof CollectionGetInputSchema>;\nexport type CollectionDeleteInput = z.infer<typeof CollectionDeleteInputSchema>;\nexport type CollectionDeleteOutput = z.infer<\n typeof CollectionDeleteOutputSchema\n>;\nexport type OrderByExpression = z.infer<typeof OrderByExpressionSchema>;\n"]}
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ function createBindingChecker(binderTools) {
36
36
  }
37
37
  const binderInputSchema = normalizeSchema(binderTool.inputSchema);
38
38
  const toolInputSchema = normalizeSchema(matchedTool.inputSchema);
39
+ console.log(JSON.stringify(binderInputSchema, null, 2));
39
40
  if (binderInputSchema && toolInputSchema) {
40
41
  try {
41
42
  const inputDiff = await diffSchemas({
@@ -46,6 +47,7 @@ function createBindingChecker(binderTools) {
46
47
  return false;
47
48
  }
48
49
  } catch (error) {
50
+ console.error("Schema diff failed", error);
49
51
  return false;
50
52
  }
51
53
  } else if (binderInputSchema && !toolInputSchema) {
@@ -63,6 +65,7 @@ function createBindingChecker(binderTools) {
63
65
  return false;
64
66
  }
65
67
  } catch (error) {
68
+ console.error("Schema diff failed", error);
66
69
  return false;
67
70
  }
68
71
  } else if (binderOutputSchema && !toolOutputSchema) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/binder.ts"],"names":["jsonSchema"],"mappings":";;;;AAwEA,SAAS,gBAAgB,MAAA,EAAkD;AACzE,EAAA,IAAI,CAAC,QAAQ,OAAO,MAAA;AAGpB,EAAA,IAAI,OAAO,IAAA,EAAM;AACf,IAAA,MAAMA,WAAAA,GAAa,gBAAgB,MAAA,EAAQ;AAAA;AAAA,MAEzC,YAAA,EAAc;AAAA,KACf,CAAA;AAGD,IAAA,IAAIA,WAAAA,CAAW,SAAS,QAAA,EAAU;AAChC,MAAA,OAAOA,WAAAA,CAAW,oBAAA;AAAA,IACpB;AAEA,IAAA,OAAOA,WAAAA;AAAA,EACT;AAGA,EAAA,MAAM,UAAA,GAAa,MAAA;AAGnB,EAAA,IAAI,UAAA,CAAW,IAAA,KAAS,QAAA,IAAY,sBAAA,IAA0B,UAAA,EAAY;AACxE,IAAA,MAAM,IAAA,GAAO,EAAE,GAAG,UAAA,EAAW;AAC7B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AAMA,QAAA,MAAM,kBAAA,GAAqB,eAAA,CAAgB,UAAA,CAAW,YAAY,CAAA;AAClE,QAAA,MAAM,gBAAA,GAAmB,eAAA,CAAgB,WAAA,CAAY,YAAY,CAAA;AAEjE,QAAA,IAAI,sBAAsB,gBAAA,EAAkB;AAC1C,UAAA,IAAI;AACF,YAAA,MAAM,UAAA,GAAa,MAAM,WAAA,CAAY;AAAA,cACnC,YAAA,EAAc,kBAAA;AAAA,cACd,iBAAA,EAAmB;AAAA,aACpB,CAAA;AAGD,YAAA,IAAI,WAAW,aAAA,EAAe;AAC5B,cAAA,OAAO,KAAA;AAAA,YACT;AAAA,UACF,SAAS,KAAA,EAAO;AAEd,YAAA,OAAO,KAAA;AAAA,UACT;AAAA,QACF,CAAA,MAAA,IAAW,kBAAA,IAAsB,CAAC,gBAAA,EAAkB;AAElD,UAAA,OAAO,KAAA;AAAA,QACT;AAAA,MACF;AAEA,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * Core Binder Types and Utilities\n *\n * This module provides the core types and utilities for the bindings system.\n * Bindings define standardized interfaces that integrations (MCPs) can implement.\n */\n\nimport type { ZodType } from \"zod\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { diffSchemas } from \"json-schema-diff\";\n\n/**\n * ToolBinder defines a single tool within a binding.\n * It specifies the tool name, input/output schemas, and whether it's optional.\n *\n * @template TName - The tool name (can be a string or RegExp for pattern matching)\n * @template TInput - The input type (inferred from inputSchema)\n * @template TReturn - The return type (inferred from outputSchema)\n */\nexport interface ToolBinder<\n TName extends string | RegExp = string,\n // biome-ignore lint/suspicious/noExplicitAny: Generic type parameter\n TInput = any,\n TReturn extends object | null | boolean = object,\n> {\n /** The name of the tool (e.g., \"DECO_CHAT_CHANNELS_JOIN\") */\n name: TName;\n\n /** Zod schema for validating tool input */\n inputSchema: ZodType<TInput>;\n\n /** Optional Zod schema for validating tool output */\n outputSchema?: ZodType<TReturn>;\n\n /**\n * Whether this tool is optional in the binding.\n * If true, an implementation doesn't need to provide this tool.\n */\n opt?: true;\n}\n\n/**\n * Binder represents a collection of tool definitions that form a binding.\n * A binding is like a TypeScript interface - it defines what tools must be implemented.\n *\n * @template TDefinition - Array of ToolBinder definitions\n *\n * @example\n * ```ts\n * const MY_BINDING = [{\n * name: \"MY_TOOL\" as const,\n * inputSchema: z.object({ id: z.string() }),\n * outputSchema: z.object({ success: z.boolean() }),\n * }] as const satisfies Binder;\n * ```\n */\nexport type Binder<\n TDefinition extends readonly ToolBinder[] = readonly ToolBinder[],\n> = TDefinition;\n\n/**\n * Tool with schemas for validation\n */\nexport interface ToolWithSchemas {\n name: string;\n inputSchema?: ZodType<any> | Record<string, unknown>;\n outputSchema?: ZodType<any> | Record<string, unknown>;\n}\n\n/**\n * Converts a schema to JSON Schema format if it's a Zod schema\n */\nfunction normalizeSchema(schema: any): Record<string, unknown> | undefined {\n if (!schema) return undefined;\n\n // If it's a Zod schema (has _def property), convert it\n if (schema._def) {\n const jsonSchema = zodToJsonSchema(schema, {\n // Don't add additionalProperties: false to allow structural compatibility\n $refStrategy: \"none\",\n }) as Record<string, unknown>;\n\n // Remove additionalProperties constraint to allow subtyping\n if (jsonSchema.type === \"object\") {\n delete jsonSchema.additionalProperties;\n }\n\n return jsonSchema;\n }\n\n // Otherwise assume it's already a JSON Schema\n const jsonSchema = schema as Record<string, unknown>;\n\n // Remove additionalProperties constraint if present\n if (jsonSchema.type === \"object\" && \"additionalProperties\" in jsonSchema) {\n const copy = { ...jsonSchema };\n delete copy.additionalProperties;\n return copy;\n }\n\n return jsonSchema;\n}\n\n/**\n * Binding checker interface\n */\nexport interface BindingChecker {\n /**\n * Check if a set of tools implements the binding with full schema validation.\n *\n * Validates:\n * - Tool name matches (exact or regex)\n * - Input schema: Tool accepts what binder requires (no removals from binder to tool)\n * - Output schema: Tool provides what binder expects (no removals from tool to binder)\n *\n * @param tools - Array of tools with names and schemas\n * @returns Promise<boolean> - true if all tools implement the binding correctly\n */\n isImplementedBy: (tools: ToolWithSchemas[]) => Promise<boolean>;\n}\n\n/**\n * Creates a binding checker with full schema validation using json-schema-diff.\n *\n * This performs strict compatibility checking:\n * - For input schemas: Validates that the tool can accept what the binder requires\n * - For output schemas: Validates that the tool provides what the binder expects\n *\n * @param binderTools - The binding definition to check against\n * @returns A binding checker with an async isImplementedBy method\n *\n * @example\n * ```ts\n * const checker = createBindingChecker(MY_BINDING);\n * const isCompatible = await checker.isImplementedBy(availableTools);\n * ```\n */\nexport function createBindingChecker<TDefinition extends readonly ToolBinder[]>(\n binderTools: TDefinition,\n): BindingChecker {\n return {\n isImplementedBy: async (tools: ToolWithSchemas[]) => {\n for (const binderTool of binderTools) {\n // Find matching tool by name (exact or regex)\n const pattern =\n typeof binderTool.name === \"string\"\n ? new RegExp(`^${binderTool.name}$`)\n : binderTool.name;\n\n const matchedTool = tools.find((t) => pattern.test(t.name));\n\n // Skip optional tools that aren't present\n if (!matchedTool && binderTool.opt) {\n continue;\n }\n\n // Required tool not found\n if (!matchedTool) {\n return false;\n }\n\n // === INPUT SCHEMA VALIDATION ===\n // Tool must accept what binder requires\n // Check: binder (source) -> tool (destination)\n // If removals found, tool doesn't accept something binder requires\n const binderInputSchema = normalizeSchema(binderTool.inputSchema);\n const toolInputSchema = normalizeSchema(matchedTool.inputSchema);\n\n if (binderInputSchema && toolInputSchema) {\n try {\n const inputDiff = await diffSchemas({\n sourceSchema: binderInputSchema,\n destinationSchema: toolInputSchema,\n });\n\n // If something was removed from binder to tool, tool can't accept it\n if (inputDiff.removalsFound) {\n return false;\n }\n } catch (error) {\n // Schema diff failed - consider incompatible\n return false;\n }\n } else if (binderInputSchema && !toolInputSchema) {\n // Binder requires input schema but tool doesn't have one\n return false;\n }\n\n // === OUTPUT SCHEMA VALIDATION ===\n // Tool must provide what binder expects (but can provide more)\n // Check: binder (source) -> tool (destination)\n // If removals found, tool doesn't provide something binder expects\n const binderOutputSchema = normalizeSchema(binderTool.outputSchema);\n const toolOutputSchema = normalizeSchema(matchedTool.outputSchema);\n\n if (binderOutputSchema && toolOutputSchema) {\n try {\n const outputDiff = await diffSchemas({\n sourceSchema: binderOutputSchema,\n destinationSchema: toolOutputSchema,\n });\n\n // If something was removed from binder to tool, tool doesn't provide it\n if (outputDiff.removalsFound) {\n return false;\n }\n } catch (error) {\n // Schema diff failed - consider incompatible\n return false;\n }\n } else if (binderOutputSchema && !toolOutputSchema) {\n // Binder expects output schema but tool doesn't have one\n return false;\n }\n }\n\n return true;\n },\n };\n}\n\n"]}
1
+ {"version":3,"sources":["../src/core/binder.ts"],"names":["jsonSchema"],"mappings":";;;;AAwEA,SAAS,gBAAgB,MAAA,EAAkD;AACzE,EAAA,IAAI,CAAC,QAAQ,OAAO,MAAA;AAGpB,EAAA,IAAI,OAAO,IAAA,EAAM;AACf,IAAA,MAAMA,WAAAA,GAAa,gBAAgB,MAAA,EAAQ;AAAA;AAAA,MAEzC,YAAA,EAAc;AAAA,KACf,CAAA;AAGD,IAAA,IAAIA,WAAAA,CAAW,SAAS,QAAA,EAAU;AAChC,MAAA,OAAOA,WAAAA,CAAW,oBAAA;AAAA,IACpB;AAEA,IAAA,OAAOA,WAAAA;AAAA,EACT;AAGA,EAAA,MAAM,UAAA,GAAa,MAAA;AAGnB,EAAA,IAAI,UAAA,CAAW,IAAA,KAAS,QAAA,IAAY,sBAAA,IAA0B,UAAA,EAAY;AACxE,IAAA,MAAM,IAAA,GAAO,EAAE,GAAG,UAAA,EAAW;AAC7B,IAAA,OAAO,IAAA,CAAK,oBAAA;AACZ,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,OAAO,UAAA;AACT;AAoCO,SAAS,qBACd,WAAA,EACgB;AAChB,EAAA,OAAO;AAAA,IACL,eAAA,EAAiB,OAAO,KAAA,KAA6B;AACnD,MAAA,KAAA,MAAW,cAAc,WAAA,EAAa;AAEpC,QAAA,MAAM,OAAA,GAAU,OAAO,UAAA,CAAW,IAAA,KAAS,QAA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;AAEjE,QAAA,IAAI,sBAAsB,gBAAA,EAAkB;AAC1C,UAAA,IAAI;AACF,YAAA,MAAM,UAAA,GAAa,MAAM,WAAA,CAAY;AAAA,cACnC,YAAA,EAAc,kBAAA;AAAA,cACd,iBAAA,EAAmB;AAAA,aACpB,CAAA;AAGD,YAAA,IAAI,WAAW,aAAA,EAAe;AAC5B,cAAA,OAAO,KAAA;AAAA,YACT;AAAA,UACF,SAAS,KAAA,EAAO;AACd,YAAA,OAAA,CAAQ,KAAA,CAAM,sBAAsB,KAAK,CAAA;AAEzC,YAAA,OAAO,KAAA;AAAA,UACT;AAAA,QACF,CAAA,MAAA,IAAW,kBAAA,IAAsB,CAAC,gBAAA,EAAkB;AAElD,UAAA,OAAO,KAAA;AAAA,QACT;AAAA,MACF;AAEA,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * Core Binder Types and Utilities\n *\n * This module provides the core types and utilities for the bindings system.\n * Bindings define standardized interfaces that integrations (MCPs) can implement.\n */\n\nimport type { ZodType } from \"zod\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { diffSchemas } from \"json-schema-diff\";\n\n/**\n * ToolBinder defines a single tool within a binding.\n * It specifies the tool name, input/output schemas, and whether it's optional.\n *\n * @template TName - The tool name (can be a string or RegExp for pattern matching)\n * @template TInput - The input type (inferred from inputSchema)\n * @template TReturn - The return type (inferred from outputSchema)\n */\nexport interface ToolBinder<\n TName extends string | RegExp = string,\n // biome-ignore lint/suspicious/noExplicitAny: Generic type parameter\n TInput = any,\n TReturn extends object | null | boolean = object,\n> {\n /** The name of the tool (e.g., \"DECO_CHAT_CHANNELS_JOIN\") */\n name: TName;\n\n /** Zod schema for validating tool input */\n inputSchema: ZodType<TInput>;\n\n /** Optional Zod schema for validating tool output */\n outputSchema?: ZodType<TReturn>;\n\n /**\n * Whether this tool is optional in the binding.\n * If true, an implementation doesn't need to provide this tool.\n */\n opt?: true;\n}\n\n/**\n * Binder represents a collection of tool definitions that form a binding.\n * A binding is like a TypeScript interface - it defines what tools must be implemented.\n *\n * @template TDefinition - Array of ToolBinder definitions\n *\n * @example\n * ```ts\n * const MY_BINDING = [{\n * name: \"MY_TOOL\" as const,\n * inputSchema: z.object({ id: z.string() }),\n * outputSchema: z.object({ success: z.boolean() }),\n * }] as const satisfies Binder;\n * ```\n */\nexport type Binder<\n TDefinition extends readonly ToolBinder[] = readonly ToolBinder[],\n> = TDefinition;\n\n/**\n * Tool with schemas for validation\n */\nexport interface ToolWithSchemas {\n name: string;\n inputSchema?: ZodType<any> | Record<string, unknown>;\n outputSchema?: ZodType<any> | Record<string, unknown>;\n}\n\n/**\n * Converts a schema to JSON Schema format if it's a Zod schema\n */\nfunction normalizeSchema(schema: any): Record<string, unknown> | undefined {\n if (!schema) return undefined;\n\n // If it's a Zod schema (has _def property), convert it\n if (schema._def) {\n const jsonSchema = zodToJsonSchema(schema, {\n // Don't add additionalProperties: false to allow structural compatibility\n $refStrategy: \"none\",\n }) as Record<string, unknown>;\n\n // Remove additionalProperties constraint to allow subtyping\n if (jsonSchema.type === \"object\") {\n delete jsonSchema.additionalProperties;\n }\n\n return jsonSchema;\n }\n\n // Otherwise assume it's already a JSON Schema\n const jsonSchema = schema as Record<string, unknown>;\n\n // Remove additionalProperties constraint if present\n if (jsonSchema.type === \"object\" && \"additionalProperties\" in jsonSchema) {\n const copy = { ...jsonSchema };\n delete copy.additionalProperties;\n return copy;\n }\n\n return jsonSchema;\n}\n\n/**\n * Binding checker interface\n */\nexport interface BindingChecker {\n /**\n * Check if a set of tools implements the binding with full schema validation.\n *\n * Validates:\n * - Tool name matches (exact or regex)\n * - Input schema: Tool accepts what binder requires (no removals from binder to tool)\n * - Output schema: Tool provides what binder expects (no removals from tool to binder)\n *\n * @param tools - Array of tools with names and schemas\n * @returns Promise<boolean> - true if all tools implement the binding correctly\n */\n isImplementedBy: (tools: ToolWithSchemas[]) => Promise<boolean>;\n}\n\n/**\n * Creates a binding checker with full schema validation using json-schema-diff.\n *\n * This performs strict compatibility checking:\n * - For input schemas: Validates that the tool can accept what the binder requires\n * - For output schemas: Validates that the tool provides what the binder expects\n *\n * @param binderTools - The binding definition to check against\n * @returns A binding checker with an async isImplementedBy method\n *\n * @example\n * ```ts\n * const checker = createBindingChecker(MY_BINDING);\n * const isCompatible = await checker.isImplementedBy(availableTools);\n * ```\n */\nexport function createBindingChecker<TDefinition extends readonly ToolBinder[]>(\n binderTools: TDefinition,\n): BindingChecker {\n return {\n isImplementedBy: async (tools: ToolWithSchemas[]) => {\n for (const binderTool of binderTools) {\n // Find matching tool by name (exact or regex)\n const pattern = typeof binderTool.name === \"string\"\n ? new RegExp(`^${binderTool.name}$`)\n : binderTool.name;\n\n const matchedTool = tools.find((t) => pattern.test(t.name));\n\n // Skip optional tools that aren't present\n if (!matchedTool && binderTool.opt) {\n continue;\n }\n\n // Required tool not found\n if (!matchedTool) {\n return false;\n }\n\n // === INPUT SCHEMA VALIDATION ===\n // Tool must accept what binder requires\n // Check: binder (source) -> tool (destination)\n // If removals found, tool doesn't accept something binder requires\n const binderInputSchema = normalizeSchema(binderTool.inputSchema);\n const toolInputSchema = normalizeSchema(matchedTool.inputSchema);\n\n console.log(JSON.stringify(binderInputSchema, null, 2));\n\n if (binderInputSchema && toolInputSchema) {\n try {\n const inputDiff = await diffSchemas({\n sourceSchema: binderInputSchema,\n destinationSchema: toolInputSchema,\n });\n\n // If something was removed from binder to tool, tool can't accept it\n if (inputDiff.removalsFound) {\n return false;\n }\n } catch (error) {\n console.error(\"Schema diff failed\", error);\n // Schema diff failed - consider incompatible\n return false;\n }\n } else if (binderInputSchema && !toolInputSchema) {\n // Binder requires input schema but tool doesn't have one\n return false;\n }\n\n // === OUTPUT SCHEMA VALIDATION ===\n // Tool must provide what binder expects (but can provide more)\n // Check: binder (source) -> tool (destination)\n // If removals found, tool doesn't provide something binder expects\n const binderOutputSchema = normalizeSchema(binderTool.outputSchema);\n const toolOutputSchema = normalizeSchema(matchedTool.outputSchema);\n\n if (binderOutputSchema && toolOutputSchema) {\n try {\n const outputDiff = await diffSchemas({\n sourceSchema: binderOutputSchema,\n destinationSchema: toolOutputSchema,\n });\n\n // If something was removed from binder to tool, tool doesn't provide it\n if (outputDiff.removalsFound) {\n return false;\n }\n } catch (error) {\n console.error(\"Schema diff failed\", error);\n // Schema diff failed - consider incompatible\n return false;\n }\n } else if (binderOutputSchema && !toolOutputSchema) {\n // Binder expects output schema but tool doesn't have one\n return false;\n }\n }\n\n return true;\n },\n };\n}\n"]}
@@ -46,22 +46,56 @@ declare const BaseCollectionEntitySchema: z.ZodObject<{
46
46
  */
47
47
  type BaseCollectionEntitySchemaType = typeof BaseCollectionEntitySchema;
48
48
  /**
49
- * Where expression type for filtering
49
+ * Where expression schema for filtering
50
50
  * Supports TanStack DB predicate push-down patterns
51
51
  */
52
- type WhereExpression = {
52
+ declare const WhereExpressionSchema: z.ZodUnion<[z.ZodObject<{
53
+ field: z.ZodArray<z.ZodString, "many">;
54
+ operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
55
+ value: z.ZodUnknown;
56
+ }, "strip", z.ZodTypeAny, {
53
57
  field: string[];
54
58
  operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
55
- value: unknown;
56
- } | {
59
+ value?: unknown;
60
+ }, {
61
+ field: string[];
62
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
63
+ value?: unknown;
64
+ }>, z.ZodObject<{
65
+ operator: z.ZodEnum<["and", "or", "not"]>;
66
+ conditions: z.ZodArray<z.ZodObject<{
67
+ field: z.ZodArray<z.ZodString, "many">;
68
+ operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
69
+ value: z.ZodUnknown;
70
+ }, "strip", z.ZodTypeAny, {
71
+ field: string[];
72
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
73
+ value?: unknown;
74
+ }, {
75
+ field: string[];
76
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
77
+ value?: unknown;
78
+ }>, "many">;
79
+ }, "strip", z.ZodTypeAny, {
57
80
  operator: "and" | "or" | "not";
58
- conditions: WhereExpression[];
59
- };
81
+ conditions: {
82
+ field: string[];
83
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
84
+ value?: unknown;
85
+ }[];
86
+ }, {
87
+ operator: "and" | "or" | "not";
88
+ conditions: {
89
+ field: string[];
90
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
91
+ value?: unknown;
92
+ }[];
93
+ }>]>;
60
94
  /**
61
- * Where expression schema for filtering
62
- * Supports TanStack DB predicate push-down patterns
95
+ * Where expression type for filtering
96
+ * Derived from WhereExpressionSchema
63
97
  */
64
- declare const WhereExpressionSchema: z.ZodType<WhereExpression>;
98
+ type WhereExpression = z.infer<typeof WhereExpressionSchema>;
65
99
  /**
66
100
  * Order by expression for sorting
67
101
  */
@@ -83,7 +117,48 @@ declare const OrderByExpressionSchema: z.ZodObject<{
83
117
  * Compatible with TanStack DB LoadSubsetOptions
84
118
  */
85
119
  declare const CollectionListInputSchema: z.ZodObject<{
86
- where: z.ZodOptional<z.ZodType<WhereExpression, z.ZodTypeDef, WhereExpression>>;
120
+ where: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
121
+ field: z.ZodArray<z.ZodString, "many">;
122
+ operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
123
+ value: z.ZodUnknown;
124
+ }, "strip", z.ZodTypeAny, {
125
+ field: string[];
126
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
127
+ value?: unknown;
128
+ }, {
129
+ field: string[];
130
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
131
+ value?: unknown;
132
+ }>, z.ZodObject<{
133
+ operator: z.ZodEnum<["and", "or", "not"]>;
134
+ conditions: z.ZodArray<z.ZodObject<{
135
+ field: z.ZodArray<z.ZodString, "many">;
136
+ operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
137
+ value: z.ZodUnknown;
138
+ }, "strip", z.ZodTypeAny, {
139
+ field: string[];
140
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
141
+ value?: unknown;
142
+ }, {
143
+ field: string[];
144
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
145
+ value?: unknown;
146
+ }>, "many">;
147
+ }, "strip", z.ZodTypeAny, {
148
+ operator: "and" | "or" | "not";
149
+ conditions: {
150
+ field: string[];
151
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
152
+ value?: unknown;
153
+ }[];
154
+ }, {
155
+ operator: "and" | "or" | "not";
156
+ conditions: {
157
+ field: string[];
158
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
159
+ value?: unknown;
160
+ }[];
161
+ }>]>>;
87
162
  orderBy: z.ZodOptional<z.ZodArray<z.ZodObject<{
88
163
  field: z.ZodArray<z.ZodString, "many">;
89
164
  direction: z.ZodEnum<["asc", "desc"]>;
@@ -100,7 +175,18 @@ declare const CollectionListInputSchema: z.ZodObject<{
100
175
  limit: z.ZodOptional<z.ZodNumber>;
101
176
  offset: z.ZodOptional<z.ZodNumber>;
102
177
  }, "strip", z.ZodTypeAny, {
103
- where?: WhereExpression | undefined;
178
+ where?: {
179
+ field: string[];
180
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
181
+ value?: unknown;
182
+ } | {
183
+ operator: "and" | "or" | "not";
184
+ conditions: {
185
+ field: string[];
186
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
187
+ value?: unknown;
188
+ }[];
189
+ } | undefined;
104
190
  orderBy?: {
105
191
  field: string[];
106
192
  direction: "asc" | "desc";
@@ -109,7 +195,18 @@ declare const CollectionListInputSchema: z.ZodObject<{
109
195
  limit?: number | undefined;
110
196
  offset?: number | undefined;
111
197
  }, {
112
- where?: WhereExpression | undefined;
198
+ where?: {
199
+ field: string[];
200
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
201
+ value?: unknown;
202
+ } | {
203
+ operator: "and" | "or" | "not";
204
+ conditions: {
205
+ field: string[];
206
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
207
+ value?: unknown;
208
+ }[];
209
+ } | undefined;
113
210
  orderBy?: {
114
211
  field: string[];
115
212
  direction: "asc" | "desc";
@@ -1,3 +1,3 @@
1
- export { BaseCollectionEntitySchema, CollectionDeleteInputSchema, CollectionDeleteOutputSchema, CollectionGetInputSchema, CollectionListInputSchema, OrderByExpressionSchema, WhereExpressionSchema, createCollectionBindings, createCollectionGetOutputSchema, createCollectionInsertInputSchema, createCollectionInsertOutputSchema, createCollectionListOutputSchema, createCollectionUpdateInputSchema, createCollectionUpdateOutputSchema } from '../chunk-IBOJHI67.js';
1
+ export { BaseCollectionEntitySchema, CollectionDeleteInputSchema, CollectionDeleteOutputSchema, CollectionGetInputSchema, CollectionListInputSchema, OrderByExpressionSchema, WhereExpressionSchema, createCollectionBindings, createCollectionGetOutputSchema, createCollectionInsertInputSchema, createCollectionInsertOutputSchema, createCollectionListOutputSchema, createCollectionUpdateInputSchema, createCollectionUpdateOutputSchema } from '../chunk-L7E6ONLJ.js';
2
2
  //# sourceMappingURL=collections.js.map
3
3
  //# sourceMappingURL=collections.js.map
@@ -1,4 +1,4 @@
1
- import { BaseCollectionEntitySchema, createCollectionBindings } from '../chunk-IBOJHI67.js';
1
+ import { BaseCollectionEntitySchema, createCollectionBindings } from '../chunk-L7E6ONLJ.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  var ModelSchema = BaseCollectionEntitySchema.extend({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/bindings",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -142,10 +142,9 @@ export function createBindingChecker<TDefinition extends readonly ToolBinder[]>(
142
142
  isImplementedBy: async (tools: ToolWithSchemas[]) => {
143
143
  for (const binderTool of binderTools) {
144
144
  // Find matching tool by name (exact or regex)
145
- const pattern =
146
- typeof binderTool.name === "string"
147
- ? new RegExp(`^${binderTool.name}$`)
148
- : binderTool.name;
145
+ const pattern = typeof binderTool.name === "string"
146
+ ? new RegExp(`^${binderTool.name}$`)
147
+ : binderTool.name;
149
148
 
150
149
  const matchedTool = tools.find((t) => pattern.test(t.name));
151
150
 
@@ -166,6 +165,8 @@ export function createBindingChecker<TDefinition extends readonly ToolBinder[]>(
166
165
  const binderInputSchema = normalizeSchema(binderTool.inputSchema);
167
166
  const toolInputSchema = normalizeSchema(matchedTool.inputSchema);
168
167
 
168
+ console.log(JSON.stringify(binderInputSchema, null, 2));
169
+
169
170
  if (binderInputSchema && toolInputSchema) {
170
171
  try {
171
172
  const inputDiff = await diffSchemas({
@@ -178,6 +179,7 @@ export function createBindingChecker<TDefinition extends readonly ToolBinder[]>(
178
179
  return false;
179
180
  }
180
181
  } catch (error) {
182
+ console.error("Schema diff failed", error);
181
183
  // Schema diff failed - consider incompatible
182
184
  return false;
183
185
  }
@@ -205,6 +207,7 @@ export function createBindingChecker<TDefinition extends readonly ToolBinder[]>(
205
207
  return false;
206
208
  }
207
209
  } catch (error) {
210
+ console.error("Schema diff failed", error);
208
211
  // Schema diff failed - consider incompatible
209
212
  return false;
210
213
  }
@@ -218,4 +221,3 @@ export function createBindingChecker<TDefinition extends readonly ToolBinder[]>(
218
221
  },
219
222
  };
220
223
  }
221
-
@@ -35,48 +35,40 @@ export const BaseCollectionEntitySchema = z.object({
35
35
  export type BaseCollectionEntitySchemaType = typeof BaseCollectionEntitySchema;
36
36
 
37
37
  /**
38
- * Where expression type for filtering
39
- * Supports TanStack DB predicate push-down patterns
38
+ * Comparison expression schema for filtering
40
39
  */
41
- export type WhereExpression =
42
- | {
43
- field: string[];
44
- operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
45
- value: unknown;
46
- }
47
- | {
48
- operator: "and" | "or" | "not";
49
- conditions: WhereExpression[];
50
- };
40
+ const ComparisonExpressionSchema = z.object({
41
+ field: z.array(z.string()),
42
+ operator: z.enum([
43
+ "eq",
44
+ "gt",
45
+ "gte",
46
+ "lt",
47
+ "lte",
48
+ "in",
49
+ "like",
50
+ "contains",
51
+ ]),
52
+ value: z.unknown(),
53
+ });
51
54
 
52
55
  /**
53
56
  * Where expression schema for filtering
54
57
  * Supports TanStack DB predicate push-down patterns
55
58
  */
56
- export const WhereExpressionSchema = z.lazy(() =>
57
- z.union([
58
- // Simple comparison
59
- z.object({
60
- field: z.array(z.string()),
61
- operator: z.enum([
62
- "eq",
63
- "gt",
64
- "gte",
65
- "lt",
66
- "lte",
67
- "in",
68
- "like",
69
- "contains",
70
- ]),
71
- value: z.unknown(),
72
- }),
73
- // Logical operators
74
- z.object({
75
- operator: z.enum(["and", "or", "not"]),
76
- conditions: z.array(WhereExpressionSchema),
77
- }),
78
- ])
79
- ) as z.ZodType<WhereExpression>;
59
+ export const WhereExpressionSchema = z.union([
60
+ ComparisonExpressionSchema,
61
+ z.object({
62
+ operator: z.enum(["and", "or", "not"]),
63
+ conditions: z.array(ComparisonExpressionSchema),
64
+ }),
65
+ ]);
66
+
67
+ /**
68
+ * Where expression type for filtering
69
+ * Derived from WhereExpressionSchema
70
+ */
71
+ export type WhereExpression = z.infer<typeof WhereExpressionSchema>;
80
72
 
81
73
  /**
82
74
  * Order by expression for sorting
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/well-known/collections.ts"],"names":[],"mappings":";;;AAsBO,IAAM,0BAAA,GAA6B,EAAE,MAAA,CAAO;AAAA,EACjD,EAAA,EAAI,CAAA,CAAE,MAAA,E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AAmB,SAAS,CAAA,KAAA,CAAA;AAAA,MAClC,WAAA,EAAa,yBAAA;AAAA,MACb,YAAA,EAAc,iCAAiC,YAAY;AAAA,KAC7D;AAAA,IACA;AAAA,MACE,IAAA,EAAM,mBAAmB,SAAS,CAAA,IAAA,CAAA;AAAA,MAClC,WAAA,EAAa,wBAAA;AAAA,MACb,YAAA,EAAc,gCAAgC,YAAY;AAAA;AAC5D,GACF;AAGA,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,QAAA,CAAS,IAAA;AAAA,MACP;AAAA,QACE,IAAA,EAAM,mBAAmB,SAAS,CAAA,OAAA,CAAA;AAAA,QAClC,WAAA,EAAa,kCAAkC,YAAY,CAAA;AAAA,QAC3D,YAAA,EAAc,mCAAmC,YAAY,CAAA;AAAA,QAC7D,GAAA,EAAK;AAAA,OACP;AAAA,MACA;AAAA,QACE,IAAA,EAAM,mBAAmB,SAAS,CAAA,OAAA,CAAA;AAAA,QAClC,WAAA,EAAa,kCAAkC,YAAY,CAAA;AAAA,QAC3D,YAAA,EAAc,mCAAmC,YAAY,CAAA;AAAA,QAC7D,GAAA,EAAK;AAAA,OACP;AAAA,MACA;AAAA,QACE,IAAA,EAAM,mBAAmB,SAAS,CAAA,OAAA,CAAA;AAAA,QAClC,WAAA,EAAa,2BAAA;AAAA,QACb,YAAA,EAAc,4BAAA;AAAA,QACd,GAAA,EAAK;AAAA;AACP,KACF;AAAA,EACF;AAEA,EAAA,OAAO,QAAA;AACT","file":"chunk-IBOJHI67.js","sourcesContent":["import { z } from \"zod\";\nimport type { ToolBinder } from \"../core/binder\";\n\n/**\n * Collection Bindings\n *\n * This module provides standardized tool bindings for Collections, representing\n * SQL table-like structures with CRUD + Search operations compatible with TanStack DB.\n *\n * Key Features:\n * - Generic collection bindings that work with any entity type\n * - Standardized tool naming: `DECO_COLLECTION_{COLLECTION}_*`\n * - Compatible with TanStack DB query-collection\n * - Full TypeScript support with proper type constraints\n * - Support for filtering, sorting, and pagination\n * - Simple id and title fields for human-readable identification\n */\n\n/**\n * Base schema for collection entities\n * All collection entities must have an id, title, and audit trail fields\n */\nexport const BaseCollectionEntitySchema = z.object({\n id: z.string().describe(\"Unique identifier for the entity\"),\n title: z.string().describe(\"Human-readable title for the entity\"),\n created_at: z.string().datetime(),\n updated_at: z.string().datetime(),\n created_by: z.string().optional(),\n updated_by: z.string().optional(),\n});\n\n/**\n * Type helper for BaseCollectionEntitySchema\n */\nexport type BaseCollectionEntitySchemaType = typeof BaseCollectionEntitySchema;\n\n/**\n * Where expression type for filtering\n * Supports TanStack DB predicate push-down patterns\n */\nexport type WhereExpression =\n | {\n field: string[];\n operator: \"eq\" | \"gt\" | \"gte\" | \"lt\" | \"lte\" | \"in\" | \"like\" | \"contains\";\n value: unknown;\n }\n | {\n operator: \"and\" | \"or\" | \"not\";\n conditions: WhereExpression[];\n };\n\n/**\n * Where expression schema for filtering\n * Supports TanStack DB predicate push-down patterns\n */\nexport const WhereExpressionSchema = z.lazy(() =>\n z.union([\n // Simple comparison\n z.object({\n field: z.array(z.string()),\n operator: z.enum([\n \"eq\",\n \"gt\",\n \"gte\",\n \"lt\",\n \"lte\",\n \"in\",\n \"like\",\n \"contains\",\n ]),\n value: z.unknown(),\n }),\n // Logical operators\n z.object({\n operator: z.enum([\"and\", \"or\", \"not\"]),\n conditions: z.array(WhereExpressionSchema),\n }),\n ])\n) as z.ZodType<WhereExpression>;\n\n/**\n * Order by expression for sorting\n */\nexport const OrderByExpressionSchema = z.object({\n field: z.array(z.string()),\n direction: z.enum([\"asc\", \"desc\"]),\n nulls: z.enum([\"first\", \"last\"]).optional(),\n});\n\n/**\n * List/Query input schema for collections\n * Compatible with TanStack DB LoadSubsetOptions\n */\nexport const CollectionListInputSchema = z.object({\n where: WhereExpressionSchema.optional().describe(\"Filter expression\"),\n orderBy: z\n .array(OrderByExpressionSchema)\n .optional()\n .describe(\"Sort expressions\"),\n limit: z\n .number()\n .int()\n .min(1)\n .max(1000)\n .optional()\n .describe(\"Maximum number of items to return\"),\n offset: z\n .number()\n .int()\n .min(0)\n .optional()\n .describe(\"Number of items to skip\"),\n});\n\n/**\n * Factory function to create list output schema for a specific collection type\n */\nexport function createCollectionListOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n items: z.array(entitySchema).describe(\"Array of collection items\"),\n totalCount: z\n .number()\n .int()\n .min(0)\n .optional()\n .describe(\"Total number of matching items (if available)\"),\n hasMore: z\n .boolean()\n .optional()\n .describe(\"Whether there are more items available\"),\n });\n}\n\n/**\n * Get by ID input schema\n */\nexport const CollectionGetInputSchema = z.object({\n id: z.string().describe(\"ID of the entity to retrieve\"),\n});\n\n/**\n * Factory function to create get output schema\n */\nexport function createCollectionGetOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n item: entitySchema\n .nullable()\n .describe(\"The retrieved item, or null if not found\"),\n });\n}\n\n/**\n * Factory function to create insert input schema\n */\nexport function createCollectionInsertInputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n // Remove id field since it may be auto-generated by the server\n return z.object({\n data: entitySchema.describe(\"Data for the new entity (id may be auto-generated)\"),\n });\n}\n\n/**\n * Factory function to create insert output schema\n */\nexport function createCollectionInsertOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n item: entitySchema.describe(\"The created entity with generated id\"),\n });\n}\n\n/**\n * Factory function to create update input schema\n */\nexport function createCollectionUpdateInputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n id: z.string().describe(\"ID of the entity to update\"),\n data: (entitySchema as unknown as z.AnyZodObject)\n .partial()\n .describe(\"Partial entity data to update\"),\n });\n}\n\n/**\n * Factory function to create update output schema\n */\nexport function createCollectionUpdateOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n item: entitySchema.describe(\"The updated entity\"),\n });\n}\n\n/**\n * Delete input schema\n */\nexport const CollectionDeleteInputSchema = z.object({\n id: z.string().describe(\"ID of the entity to delete\"),\n});\n\n/**\n * Delete output schema\n */\nexport const CollectionDeleteOutputSchema = z.object({\n success: z.boolean().describe(\"Whether the deletion was successful\"),\n id: z.string().describe(\"ID of the deleted entity\"),\n});\n\n/**\n * Options for creating collection bindings\n */\nexport interface CollectionBindingOptions {\n /**\n * If true, only LIST and GET operations will be included (read-only collection)\n * @default false\n */\n readOnly?: boolean;\n}\n\n/**\n * Creates generic collection bindings for a specific entity type\n *\n * This function generates standardized tool bindings that work with any collection/table\n * by accepting a custom entity schema and collection name. The bindings provide:\n * - DECO_COLLECTION_{NAME}_LIST - Query/search entities with filtering and sorting (required)\n * - DECO_COLLECTION_{NAME}_GET - Get a single entity by ID (required)\n * - DECO_COLLECTION_{NAME}_INSERT - Create a new entity (optional, excluded if readOnly=true)\n * - DECO_COLLECTION_{NAME}_UPDATE - Update an existing entity (optional, excluded if readOnly=true)\n * - DECO_COLLECTION_{NAME}_DELETE - Delete an entity (optional, excluded if readOnly=true)\n *\n * @param collectionName - The name of the collection/table (e.g., \"users\", \"products\", \"orders\")\n * @param entitySchema - The Zod schema for the entity type (must extend BaseCollectionEntitySchema)\n * @param options - Optional configuration for the collection bindings\n * @returns Array of tool bindings for Collection CRUD + Query operations\n *\n * @example\n * ```typescript\n * const UserSchema = z.object({\n * id: z.string(),\n * title: z.string(),\n * created_at: z.string().datetime(),\n * updated_at: z.string().datetime(),\n * created_by: z.string().optional(),\n * updated_by: z.string().optional(),\n * email: z.string().email(),\n * });\n *\n * // Full CRUD collection\n * const USER_COLLECTION_BINDING = createCollectionBindings(\"users\", UserSchema);\n *\n * // Read-only collection (only LIST and GET)\n * const READONLY_COLLECTION_BINDING = createCollectionBindings(\"products\", ProductSchema, { readOnly: true });\n * ```\n */\nexport function createCollectionBindings<\n TEntitySchema extends BaseCollectionEntitySchemaType,\n>(\n collectionName: string,\n entitySchema: TEntitySchema,\n options?: CollectionBindingOptions,\n) {\n const upperName = collectionName.toUpperCase();\n const readOnly = options?.readOnly ?? false;\n\n const bindings: ToolBinder[] = [\n {\n name: `DECO_COLLECTION_${upperName}_LIST` as const,\n inputSchema: CollectionListInputSchema,\n outputSchema: createCollectionListOutputSchema(entitySchema),\n },\n {\n name: `DECO_COLLECTION_${upperName}_GET` as const,\n inputSchema: CollectionGetInputSchema,\n outputSchema: createCollectionGetOutputSchema(entitySchema),\n },\n ];\n\n // Only include mutation operations if not read-only\n if (!readOnly) {\n bindings.push(\n {\n name: `DECO_COLLECTION_${upperName}_INSERT` as const,\n inputSchema: createCollectionInsertInputSchema(entitySchema),\n outputSchema: createCollectionInsertOutputSchema(entitySchema),\n opt: true,\n },\n {\n name: `DECO_COLLECTION_${upperName}_UPDATE` as const,\n inputSchema: createCollectionUpdateInputSchema(entitySchema),\n outputSchema: createCollectionUpdateOutputSchema(entitySchema),\n opt: true,\n },\n {\n name: `DECO_COLLECTION_${upperName}_DELETE` as const,\n inputSchema: CollectionDeleteInputSchema,\n outputSchema: CollectionDeleteOutputSchema,\n opt: true,\n },\n );\n }\n\n return bindings satisfies readonly ToolBinder[];\n}\n\n/**\n * Type helper to extract the collection binding type\n */\nexport type CollectionBinding<\n TEntitySchema extends BaseCollectionEntitySchemaType,\n> = ReturnType<typeof createCollectionBindings<TEntitySchema>>;\n\n/**\n * Type helper to extract tool names from a collection binding\n */\nexport type CollectionTools<\n TEntitySchema extends BaseCollectionEntitySchemaType,\n> = CollectionBinding<TEntitySchema>[number][\"name\"];\n\n// Export types for TypeScript usage\nexport type CollectionListInput = z.infer<typeof CollectionListInputSchema>;\nexport type CollectionGetInput = z.infer<typeof CollectionGetInputSchema>;\nexport type CollectionDeleteInput = z.infer<typeof CollectionDeleteInputSchema>;\nexport type CollectionDeleteOutput = z.infer<\n typeof CollectionDeleteOutputSchema\n>;\nexport type OrderByExpression = z.infer<typeof OrderByExpressionSchema>;\n"]}