forked from trent_larson/crowd-funder-for-time-pwa
refactor: reorganize deep linking types and interfaces
Changes: - Move deep link types from types/ to interfaces/ - Export baseUrlSchema for external use - Add trailing commas for better git diffs - Fix type inference for deepLinkSchemas - Add deepLinks export to interfaces/index.ts - Remove duplicate SuccessResult interface - Update import paths in services/deepLinks.ts This improves code organization by centralizing interface definitions and fixing type inference issues.
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
/**
|
||||
* @file Deep Link Type Definitions and Validation Schemas
|
||||
* @author Matthew Raymer
|
||||
*
|
||||
*
|
||||
* This file defines the type system and validation schemas for deep linking in the TimeSafari app.
|
||||
* It uses Zod for runtime validation while providing TypeScript types for compile-time checking.
|
||||
*
|
||||
*
|
||||
* Type Strategy:
|
||||
* 1. Define base URL schema to validate the fundamental deep link structure
|
||||
* 2. Define route-specific parameter schemas with exact validation rules
|
||||
* 3. Generate TypeScript types from Zod schemas for type safety
|
||||
* 4. Export both schemas and types for use in deep link handling
|
||||
*
|
||||
*
|
||||
* Usage:
|
||||
* - Import schemas for runtime validation in deep link handlers
|
||||
* - Import types for type-safe parameter handling in components
|
||||
* - Use DeepLinkParams type for type-safe access to route parameters
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* // Runtime validation
|
||||
* const params = deepLinkSchemas.claim.parse({ id: "123", view: "details" });
|
||||
*
|
||||
*
|
||||
* // Type-safe parameter access
|
||||
* function handleClaimParams(params: DeepLinkParams["claim"]) {
|
||||
* // TypeScript knows params.id exists and params.view is optional
|
||||
@@ -28,46 +28,46 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// Base URL validation schema
|
||||
const baseUrlSchema = z.object({
|
||||
export const baseUrlSchema = z.object({
|
||||
scheme: z.literal("timesafari"),
|
||||
path: z.string(),
|
||||
queryParams: z.record(z.string()).optional()
|
||||
queryParams: z.record(z.string()).optional(),
|
||||
});
|
||||
|
||||
// Parameter validation schemas for each route type
|
||||
export const deepLinkSchemas = {
|
||||
claim: z.object({
|
||||
id: z.string().min(1),
|
||||
view: z.enum(["details", "certificate", "raw"]).optional()
|
||||
view: z.enum(["details", "certificate", "raw"]).optional(),
|
||||
}),
|
||||
|
||||
|
||||
contact: z.object({
|
||||
did: z.string().regex(/^did:/),
|
||||
action: z.enum(["edit", "import"]).optional(),
|
||||
jwt: z.string().optional()
|
||||
jwt: z.string().optional(),
|
||||
}),
|
||||
|
||||
project: z.object({
|
||||
id: z.string().min(1),
|
||||
view: z.enum(["details", "edit"]).optional()
|
||||
view: z.enum(["details", "edit"]).optional(),
|
||||
}),
|
||||
|
||||
invite: z.object({
|
||||
jwt: z.string().min(1),
|
||||
type: z.enum(["one", "many"]).optional()
|
||||
type: z.enum(["one", "many"]).optional(),
|
||||
}),
|
||||
|
||||
gift: z.object({
|
||||
id: z.string().min(1),
|
||||
action: z.enum(["confirm", "details"]).optional()
|
||||
action: z.enum(["confirm", "details"]).optional(),
|
||||
}),
|
||||
|
||||
offer: z.object({
|
||||
id: z.string().min(1),
|
||||
view: z.enum(["details"]).optional()
|
||||
})
|
||||
view: z.enum(["details"]).optional(),
|
||||
}),
|
||||
};
|
||||
|
||||
export type DeepLinkParams = {
|
||||
[K in keyof typeof deepLinkSchemas]: z.infer<typeof deepLinkSchemas[K]>;
|
||||
};
|
||||
[K in keyof typeof deepLinkSchemas]: z.infer<(typeof deepLinkSchemas)[K]>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user