diff options
| author | Dhravya Shah <[email protected]> | 2025-09-18 20:34:18 -0700 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2025-09-18 21:03:49 -0700 |
| commit | 1fcb56908920da386900abb4ce2383374a625c72 (patch) | |
| tree | 0f9d7f695d4c9b1b85be3950fc869e0061dff3ed /packages/validation | |
| parent | refetching logic change (diff) | |
| download | supermemory-09-18-formatting.tar.xz supermemory-09-18-formatting.zip | |
formatting09-18-formatting
Diffstat (limited to 'packages/validation')
| -rw-r--r-- | packages/validation/api.ts | 104 | ||||
| -rw-r--r-- | packages/validation/connection.ts | 68 |
2 files changed, 86 insertions, 86 deletions
diff --git a/packages/validation/api.ts b/packages/validation/api.ts index 91ac5e09..0363cf2c 100644 --- a/packages/validation/api.ts +++ b/packages/validation/api.ts @@ -1,21 +1,21 @@ -import { z } from "zod" -import "zod-openapi/extend" +import { z } from "zod"; +import "zod-openapi/extend"; import { MetadataSchema as BaseMetadataSchema, DocumentSchema, MemoryEntrySchema, OrganizationSettingsSchema, RequestTypeEnum, -} from "./schemas" +} from "./schemas"; -export const MetadataSchema = BaseMetadataSchema +export const MetadataSchema = BaseMetadataSchema; export const SearchFiltersSchema = z .object({ AND: z.array(z.unknown()).optional(), OR: z.array(z.unknown()).optional(), }) - .or(z.record(z.unknown())) + .or(z.record(z.unknown())); const exampleMetadata: Record<string, string | number | boolean> = { category: "technology", @@ -24,7 +24,7 @@ const exampleMetadata: Record<string, string | number | boolean> = { source: "web", tag_1: "ai", tag_2: "machine-learning", -} as const +} as const; const exampleMemory = { connectionId: "conn_123", @@ -45,7 +45,7 @@ const exampleMemory = { type: "text", updatedAt: new Date().toISOString(), url: "https://example.com/article", -} as const +} as const; export const MemorySchema = z .object({ @@ -136,7 +136,7 @@ export const MemorySchema = z .openapi({ description: "Memory object", example: exampleMemory, - }) + }); export const MemoryUpdateSchema = z.object({ containerTags: z @@ -162,9 +162,9 @@ export const MemoryUpdateSchema = z.object({ "Optional metadata for the memory. This is used to store additional information about the memory. You can use this to store any additional information you need about the memory. Metadata can be filtered through. Keys must be strings and are case sensitive. Values can be strings, numbers, or booleans. You cannot nest objects.", example: exampleMetadata, }), -}) +}); -export const MemoryAddSchema = MemoryUpdateSchema +export const MemoryAddSchema = MemoryUpdateSchema; export const PaginationSchema = z .object({ @@ -181,9 +181,9 @@ export const PaginationSchema = z totalItems: 100, totalPages: 10, }, - }) + }); -export const GetMemoryResponseSchema = MemorySchema +export const GetMemoryResponseSchema = MemorySchema; export const ListMemoriesResponseSchema = z .object({ @@ -229,7 +229,7 @@ export const ListMemoriesResponseSchema = z totalPages: 10, }, }, - }) + }); export const ListMemoriesQuerySchema = z .object({ @@ -317,12 +317,12 @@ export const ListMemoriesQuerySchema = z page: 1, sort: "createdAt", }, - }) + }); export const MemoryResponseSchema = z.object({ id: z.string(), status: z.string(), -}) +}); export const SearchRequestSchema = z.object({ categoriesFilter: z @@ -455,7 +455,7 @@ export const SearchRequestSchema = z.object({ "If true, rewrites the query to make it easier to find documents. This increases the latency by about 400ms", example: false, }), -}) +}); export const Searchv4RequestSchema = z.object({ containerTag: z.string().optional().openapi({ @@ -546,7 +546,7 @@ export const Searchv4RequestSchema = z.object({ "If true, rewrites the query to make it easier to find documents. This increases the latency by about 400ms", example: false, }), -}) +}); export const SearchResultSchema = z.object({ chunks: z @@ -632,13 +632,13 @@ export const SearchResultSchema = z.object({ description: "Document type", example: "web", }), -}) +}); export const SearchResponseSchema = z.object({ results: z.array(SearchResultSchema), timing: z.number(), total: z.number(), -}) +}); // V4 Memory Search Schemas export const MemorySearchDocumentSchema = z.object({ @@ -666,7 +666,7 @@ export const MemorySearchDocumentSchema = z.object({ description: "Document last update date", format: "date-time", }), -}) +}); export const MemorySearchResult = z.object({ id: z.string().openapi({ @@ -765,7 +765,7 @@ export const MemorySearchResult = z.object({ documents: z.array(MemorySearchDocumentSchema).optional().openapi({ description: "Associated documents for this memory entry", }), -}) +}); export const MemorySearchResponseSchema = z.object({ results: z.array(MemorySearchResult).openapi({ @@ -779,7 +779,7 @@ export const MemorySearchResponseSchema = z.object({ description: "Total number of results returned", example: 5, }), -}) +}); export const ErrorResponseSchema = z.object({ details: z.string().optional().openapi({ @@ -790,15 +790,15 @@ export const ErrorResponseSchema = z.object({ description: "Error message", example: "Invalid request parameters", }), -}) +}); -export type SearchResult = z.infer<typeof SearchResultSchema> +export type SearchResult = z.infer<typeof SearchResultSchema>; export const SettingsRequestSchema = OrganizationSettingsSchema.omit({ id: true, orgId: true, updatedAt: true, -}) +}); export const ConnectionResponseSchema = z.object({ createdAt: z.string().datetime(), @@ -808,21 +808,21 @@ export const ConnectionResponseSchema = z.object({ id: z.string(), metadata: z.record(z.any()).optional(), provider: z.string(), -}) +}); -export const RequestTypeSchema = RequestTypeEnum +export const RequestTypeSchema = RequestTypeEnum; export const HourlyAnalyticsSchema = z.object({ count: z.number(), hour: z.union([z.date(), z.string()]), -}) +}); export const ApiKeyAnalyticsBaseSchema = z.object({ count: z.number(), keyId: z.string(), keyName: z.string().nullable(), lastUsed: z.union([z.date(), z.string()]).nullable(), -}) +}); export const AnalyticsUsageResponseSchema = z.object({ byKey: z.array( @@ -845,7 +845,7 @@ export const AnalyticsUsageResponseSchema = z.object({ type: RequestTypeSchema, }), ), -}) +}); export const AnalyticsErrorResponseSchema = z.object({ byKey: z.array( @@ -878,7 +878,7 @@ export const AnalyticsErrorResponseSchema = z.object({ type: RequestTypeSchema, }), ), -}) +}); export const AnalyticsLogSchema = z.object({ createdAt: z.date(), @@ -917,12 +917,12 @@ export const AnalyticsLogSchema = z.object({ ]), statusCode: z.number(), type: RequestTypeSchema, -}) +}); export const AnalyticsLogsResponseSchema = z.object({ logs: z.array(z.unknown()), pagination: PaginationSchema, -}) +}); export const AnalyticsChatResponseSchema = z.object({ analytics: z.object({ @@ -1022,7 +1022,7 @@ export const AnalyticsChatResponseSchema = z.object({ }), }), }), -}) +}); export const AnalyticsMemoryResponseSchema = z.object({ connectionsGrowth: z.number(), @@ -1033,7 +1033,7 @@ export const AnalyticsMemoryResponseSchema = z.object({ tokensProcessed: z.number(), totalConnections: z.number(), totalMemories: z.number(), -}) +}); export const MemoryEntryAPISchema = MemoryEntrySchema.extend({ sourceAddedAt: z.date().nullable(), // From join relationship @@ -1042,7 +1042,7 @@ export const MemoryEntryAPISchema = MemoryEntrySchema.extend({ spaceContainerTag: z.string().nullable(), // From join relationship }).openapi({ description: "Memory entry with source relationship data", -}) +}); // Extended document schema with memory entries export const DocumentWithMemoriesSchema = z @@ -1075,7 +1075,7 @@ export const DocumentWithMemoriesSchema = z }) .openapi({ description: "Document with associated memory entries", - }) + }); export const DocumentsWithMemoriesResponseSchema = z .object({ @@ -1084,7 +1084,7 @@ export const DocumentsWithMemoriesResponseSchema = z }) .openapi({ description: "List of documents with their memory entries", - }) + }); export const DocumentsWithMemoriesQuerySchema = z .object({ @@ -1114,7 +1114,7 @@ export const DocumentsWithMemoriesQuerySchema = z }) .openapi({ description: "Query parameters for listing documents with memory entries", - }) + }); export const MigrateMCPRequestSchema = z .object({ @@ -1129,7 +1129,7 @@ export const MigrateMCPRequestSchema = z }) .openapi({ description: "Request body for migrating MCP documents", - }) + }); export const MigrateMCPResponseSchema = z .object({ @@ -1155,7 +1155,7 @@ export const MigrateMCPResponseSchema = z }) .openapi({ description: "Response for MCP document migration", - }) + }); // Processing documents schema export const ProcessingDocumentsResponseSchema = z @@ -1196,7 +1196,7 @@ export const ProcessingDocumentsResponseSchema = z ], totalCount: 5, }, - }) + }); // Project schemas export const ProjectSchema = z @@ -1235,7 +1235,7 @@ export const ProjectSchema = z }) .openapi({ description: "Project object for organizing memories", - }) + }); export const CreateProjectSchema = z .object({ @@ -1248,7 +1248,7 @@ export const CreateProjectSchema = z }) .openapi({ description: "Request body for creating a new project", - }) + }); export const ListProjectsResponseSchema = z .object({ @@ -1258,7 +1258,7 @@ export const ListProjectsResponseSchema = z }) .openapi({ description: "Response containing list of projects", - }) + }); export const DeleteProjectSchema = z .object({ @@ -1275,9 +1275,9 @@ export const DeleteProjectSchema = z (data) => { // If action is "move", targetProjectId is required if (data.action === "move") { - return !!data.targetProjectId + return !!data.targetProjectId; } - return true + return true; }, { message: "targetProjectId is required when action is 'move'", @@ -1286,7 +1286,7 @@ export const DeleteProjectSchema = z ) .openapi({ description: "Request body for deleting a project", - }) + }); export const DeleteProjectResponseSchema = z .object({ @@ -1309,7 +1309,7 @@ export const DeleteProjectResponseSchema = z }) .openapi({ description: "Response for project deletion", - }) + }); // Bulk delete schema - supports both IDs and container tags export const BulkDeleteMemoriesSchema = z @@ -1336,7 +1336,7 @@ export const BulkDeleteMemoriesSchema = z .refine( (data) => { // At least one of ids or containerTags must be provided - return !!data.ids?.length || !!data.containerTags?.length + return !!data.ids?.length || !!data.containerTags?.length; }, { message: "Either 'ids' or 'containerTags' must be provided", @@ -1348,7 +1348,7 @@ export const BulkDeleteMemoriesSchema = z example: { ids: ["acxV5LHMEsG2hMSNb4umbn", "bxcV5LHMEsG2hMSNb4umbn"], }, - }) + }); export const BulkDeleteMemoriesResponseSchema = z .object({ @@ -1383,4 +1383,4 @@ export const BulkDeleteMemoriesResponseSchema = z }) .openapi({ description: "Response for bulk memory deletion", - }) + }); diff --git a/packages/validation/connection.ts b/packages/validation/connection.ts index e7bc8352..e4baade6 100644 --- a/packages/validation/connection.ts +++ b/packages/validation/connection.ts @@ -1,13 +1,13 @@ -import { z } from "zod" -import { ConnectionProviderEnum } from "./schemas" +import { z } from "zod"; +import { ConnectionProviderEnum } from "./schemas"; -export const providers = ConnectionProviderEnum -export type Provider = z.infer<typeof providers> +export const providers = ConnectionProviderEnum; +export type Provider = z.infer<typeof providers>; const BaseMetadataSchema = <T extends z.ZodTypeAny>(provider: T) => z.object({ provider, - }) + }); export const NotionMetadataSchema = BaseMetadataSchema( z.literal("notion"), @@ -17,8 +17,8 @@ export const NotionMetadataSchema = BaseMetadataSchema( workspaceIcon: z.string().optional(), workspaceId: z.string(), workspaceName: z.string(), -}) -export type NotionMetadata = z.infer<typeof NotionMetadataSchema> +}); +export type NotionMetadata = z.infer<typeof NotionMetadataSchema>; export const GoogleDriveMetadataSchema = BaseMetadataSchema( z.literal("google-drive"), @@ -27,8 +27,8 @@ export const GoogleDriveMetadataSchema = BaseMetadataSchema( webhookChannelId: z.string().optional(), webhookExpiration: z.number().optional(), webhookResourceId: z.string().optional(), -}) -export type GoogleDriveMetadata = z.infer<typeof GoogleDriveMetadataSchema> +}); +export type GoogleDriveMetadata = z.infer<typeof GoogleDriveMetadataSchema>; export const OneDriveMetadataSchema = BaseMetadataSchema( z.literal("onedrive"), @@ -38,38 +38,38 @@ export const OneDriveMetadataSchema = BaseMetadataSchema( webhookClientState: z.string().optional(), webhookExpiration: z.number().optional(), webhookSubscriptionId: z.string().optional(), -}) -export type OneDriveMetadata = z.infer<typeof OneDriveMetadataSchema> +}); +export type OneDriveMetadata = z.infer<typeof OneDriveMetadataSchema>; export const ConnectionMetadataSchema = z.discriminatedUnion("provider", [ NotionMetadataSchema, GoogleDriveMetadataSchema, OneDriveMetadataSchema, -]) +]); export type ConnectionMetadata<T extends Provider> = T extends "notion" ? NotionMetadata : T extends "google-drive" ? GoogleDriveMetadata : T extends "onedrive" ? OneDriveMetadata - : never + : never; export function isNotionMetadata( metadata: unknown, ): metadata is NotionMetadata { - return NotionMetadataSchema.safeParse(metadata).success + return NotionMetadataSchema.safeParse(metadata).success; } export function isGoogleDriveMetadata( metadata: unknown, ): metadata is GoogleDriveMetadata { - return GoogleDriveMetadataSchema.safeParse(metadata).success + return GoogleDriveMetadataSchema.safeParse(metadata).success; } export function isOneDriveMetadata( metadata: unknown, ): metadata is OneDriveMetadata { - return OneDriveMetadataSchema.safeParse(metadata).success + return OneDriveMetadataSchema.safeParse(metadata).success; } export const ConnectionStateSchema = z.object({ @@ -77,8 +77,8 @@ export const ConnectionStateSchema = z.object({ org: z.string(), provider: providers, userId: z.string(), -}) -export type ConnectionState = z.infer<typeof ConnectionStateSchema> +}); +export type ConnectionState = z.infer<typeof ConnectionStateSchema>; export const TokenDataSchema = z.object({ // Only used for Notion connections since they don't support refresh tokens @@ -90,8 +90,8 @@ export const TokenDataSchema = z.object({ metadata: ConnectionMetadataSchema.optional(), refreshToken: z.string().optional(), userId: z.string().optional(), -}) -export type TokenData = z.infer<typeof TokenDataSchema> +}); +export type TokenData = z.infer<typeof TokenDataSchema>; export const NotionTokenResponseSchema = z.object({ access_token: z.string(), @@ -123,8 +123,8 @@ export const NotionTokenResponseSchema = z.object({ workspace_icon: z.string().optional(), workspace_id: z.string(), workspace_name: z.string(), -}) -export type NotionTokenResponse = z.infer<typeof NotionTokenResponseSchema> +}); +export type NotionTokenResponse = z.infer<typeof NotionTokenResponseSchema>; export const GoogleDriveTokenResponseSchema = z.object({ access_token: z.string(), @@ -132,10 +132,10 @@ export const GoogleDriveTokenResponseSchema = z.object({ refresh_token: z.string().optional(), scope: z.string(), token_type: z.literal("Bearer"), -}) +}); export type GoogleDriveTokenResponse = z.infer< typeof GoogleDriveTokenResponseSchema -> +>; export const OneDriveTokenResponseSchema = z.object({ access_token: z.string(), @@ -143,8 +143,8 @@ export const OneDriveTokenResponseSchema = z.object({ refresh_token: z.string().optional(), scope: z.string(), token_type: z.literal("Bearer"), -}) -export type OneDriveTokenResponse = z.infer<typeof OneDriveTokenResponseSchema> +}); +export type OneDriveTokenResponse = z.infer<typeof OneDriveTokenResponseSchema>; export const NotionConfigSchema = z.object({ clientId: z.string(), @@ -154,23 +154,23 @@ export const NotionConfigSchema = z.object({ token: z.string().url(), }), scopes: z.array(z.string()), -}) -export type NotionConfig = z.infer<typeof NotionConfigSchema> +}); +export type NotionConfig = z.infer<typeof NotionConfigSchema>; export const ConnectionQuerySchema = z.object({ id: z.string(), redirectUrl: z.string().optional(), -}) +}); export const GoogleDrivePageTokenResponseSchema = z.object({ startPageToken: z.union([z.string(), z.number()]), -}) +}); export const GoogleDriveWatchResponseSchema = z.object({ expiration: z.string(), id: z.string(), resourceId: z.string(), -}) +}); export const OneDriveSubscriptionResponseSchema = z.object({ changeType: z.string(), @@ -179,13 +179,13 @@ export const OneDriveSubscriptionResponseSchema = z.object({ id: z.string(), notificationUrl: z.string(), resource: z.string(), -}) +}); export const GoogleUserInfoResponseSchema = z.object({ email: z.string().email(), -}) +}); export const MicrosoftUserInfoResponseSchema = z.object({ mail: z.string().optional(), userPrincipalName: z.string().optional(), -}) +}); |