@palbase/backend 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,115 +0,0 @@
1
- import { ZodSchema, z } from 'zod';
2
-
3
- /** Supported HTTP methods for endpoints. */
4
- type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
5
- /** Authenticated user attached to the request context. */
6
- interface User {
7
- id: string;
8
- email: string;
9
- role: string;
10
- metadata: Record<string, unknown>;
11
- }
12
- /** Authentication configuration for an endpoint. */
13
- interface AuthConfig {
14
- /** Whether authentication is required. Defaults to true. */
15
- required: boolean;
16
- /** Required role for access. If undefined, any authenticated user is allowed. */
17
- role?: string;
18
- }
19
-
20
- /** Middleware context — subset of EndpointContext without input (not yet validated). */
21
- interface MiddlewareContext {
22
- params: Record<string, string>;
23
- query: Record<string, string>;
24
- headers: Record<string, string>;
25
- user: User | null;
26
- db: DBClient;
27
- env: Record<string, string>;
28
- log: Logger;
29
- cache: CacheClient;
30
- palbase: PalbaseBindings;
31
- requestId: string;
32
- projectId: string;
33
- environmentId: string;
34
- }
35
- /** Middleware function signature — receives context and next function. */
36
- type MiddlewareHandler = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
37
- /**
38
- * Define a middleware function for use in the middleware/ directory or
39
- * as endpoint-specific middleware.
40
- *
41
- * Middleware runs before the handler. Call `next()` to pass control
42
- * to the next middleware or handler. If `next()` is not called, the
43
- * handler will not execute.
44
- *
45
- * Errors thrown in middleware are caught by the pipeline and returned
46
- * as error responses.
47
- */
48
- declare function defineMiddleware(fn: MiddlewareHandler): MiddlewareHandler;
49
-
50
- /** Rate limit configuration for an endpoint. */
51
- interface RateLimitConfig {
52
- /** Maximum number of requests in the window. */
53
- max: number;
54
- /** Window duration in seconds. */
55
- window: number;
56
- }
57
- /** Database client interface injected into endpoint context. */
58
- interface DBClient {
59
- insert(table: string, data: Record<string, unknown>): Promise<Record<string, unknown>>;
60
- update(table: string, id: string, data: Record<string, unknown>): Promise<Record<string, unknown>>;
61
- delete(table: string, id: string): Promise<void>;
62
- findById(table: string, id: string): Promise<Record<string, unknown> | null>;
63
- findMany(table: string, query?: Record<string, unknown>): Promise<Record<string, unknown>[]>;
64
- }
65
- /** Logger interface injected into endpoint context. */
66
- interface Logger {
67
- info(message: string, ...args: unknown[]): void;
68
- warn(message: string, ...args: unknown[]): void;
69
- error(message: string, ...args: unknown[]): void;
70
- debug(message: string, ...args: unknown[]): void;
71
- }
72
- /** Cache client interface injected into endpoint context. */
73
- interface CacheClient {
74
- get(key: string): Promise<string | null>;
75
- set(key: string, value: string, ttl?: number): Promise<void>;
76
- del(key: string): Promise<void>;
77
- incr(key: string): Promise<number>;
78
- }
79
- /** Palbase service bindings for accessing other modules. */
80
- interface PalbaseBindings {
81
- auth: Record<string, unknown>;
82
- storage: Record<string, unknown>;
83
- }
84
- /** Endpoint context — injected into every handler. */
85
- interface EndpointContext<TInput = unknown> {
86
- input: TInput;
87
- params: Record<string, string>;
88
- query: Record<string, string>;
89
- headers: Record<string, string>;
90
- user: User | null;
91
- db: DBClient;
92
- env: Record<string, string>;
93
- log: Logger;
94
- cache: CacheClient;
95
- palbase: PalbaseBindings;
96
- requestId: string;
97
- projectId: string;
98
- environmentId: string;
99
- }
100
- /** Middleware function signature — uses MiddlewareContext (no input, not yet validated). */
101
- type Middleware = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
102
- /** Configuration for defining an endpoint. */
103
- interface EndpointConfig<TInputSchema extends ZodSchema = ZodSchema, TOutputSchema extends ZodSchema = ZodSchema> {
104
- method: HttpMethod;
105
- auth?: Partial<AuthConfig>;
106
- rateLimit?: RateLimitConfig;
107
- input?: TInputSchema;
108
- output?: TOutputSchema;
109
- middleware?: Middleware[];
110
- handler: (ctx: EndpointContext<z.infer<TInputSchema>>) => Promise<z.infer<TOutputSchema>>;
111
- }
112
- /** Define a type-safe endpoint. Input schema infers the ctx.input type. */
113
- declare function defineEndpoint<TInputSchema extends ZodSchema, TOutputSchema extends ZodSchema>(config: EndpointConfig<TInputSchema, TOutputSchema>): EndpointConfig<TInputSchema, TOutputSchema>;
114
-
115
- export { type AuthConfig as A, type CacheClient as C, type DBClient as D, type EndpointContext as E, type HttpMethod as H, type Logger as L, type Middleware as M, type PalbaseBindings as P, type RateLimitConfig as R, type User as U, type EndpointConfig as a, type MiddlewareContext as b, type MiddlewareHandler as c, defineEndpoint as d, defineMiddleware as e };
@@ -1,115 +0,0 @@
1
- import { ZodSchema, z } from 'zod';
2
-
3
- /** Supported HTTP methods for endpoints. */
4
- type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
5
- /** Authenticated user attached to the request context. */
6
- interface User {
7
- id: string;
8
- email: string;
9
- role: string;
10
- metadata: Record<string, unknown>;
11
- }
12
- /** Authentication configuration for an endpoint. */
13
- interface AuthConfig {
14
- /** Whether authentication is required. Defaults to true. */
15
- required: boolean;
16
- /** Required role for access. If undefined, any authenticated user is allowed. */
17
- role?: string;
18
- }
19
-
20
- /** Middleware context — subset of EndpointContext without input (not yet validated). */
21
- interface MiddlewareContext {
22
- params: Record<string, string>;
23
- query: Record<string, string>;
24
- headers: Record<string, string>;
25
- user: User | null;
26
- db: DBClient;
27
- env: Record<string, string>;
28
- log: Logger;
29
- cache: CacheClient;
30
- palbase: PalbaseBindings;
31
- requestId: string;
32
- projectId: string;
33
- environmentId: string;
34
- }
35
- /** Middleware function signature — receives context and next function. */
36
- type MiddlewareHandler = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
37
- /**
38
- * Define a middleware function for use in the middleware/ directory or
39
- * as endpoint-specific middleware.
40
- *
41
- * Middleware runs before the handler. Call `next()` to pass control
42
- * to the next middleware or handler. If `next()` is not called, the
43
- * handler will not execute.
44
- *
45
- * Errors thrown in middleware are caught by the pipeline and returned
46
- * as error responses.
47
- */
48
- declare function defineMiddleware(fn: MiddlewareHandler): MiddlewareHandler;
49
-
50
- /** Rate limit configuration for an endpoint. */
51
- interface RateLimitConfig {
52
- /** Maximum number of requests in the window. */
53
- max: number;
54
- /** Window duration in seconds. */
55
- window: number;
56
- }
57
- /** Database client interface injected into endpoint context. */
58
- interface DBClient {
59
- insert(table: string, data: Record<string, unknown>): Promise<Record<string, unknown>>;
60
- update(table: string, id: string, data: Record<string, unknown>): Promise<Record<string, unknown>>;
61
- delete(table: string, id: string): Promise<void>;
62
- findById(table: string, id: string): Promise<Record<string, unknown> | null>;
63
- findMany(table: string, query?: Record<string, unknown>): Promise<Record<string, unknown>[]>;
64
- }
65
- /** Logger interface injected into endpoint context. */
66
- interface Logger {
67
- info(message: string, ...args: unknown[]): void;
68
- warn(message: string, ...args: unknown[]): void;
69
- error(message: string, ...args: unknown[]): void;
70
- debug(message: string, ...args: unknown[]): void;
71
- }
72
- /** Cache client interface injected into endpoint context. */
73
- interface CacheClient {
74
- get(key: string): Promise<string | null>;
75
- set(key: string, value: string, ttl?: number): Promise<void>;
76
- del(key: string): Promise<void>;
77
- incr(key: string): Promise<number>;
78
- }
79
- /** Palbase service bindings for accessing other modules. */
80
- interface PalbaseBindings {
81
- auth: Record<string, unknown>;
82
- storage: Record<string, unknown>;
83
- }
84
- /** Endpoint context — injected into every handler. */
85
- interface EndpointContext<TInput = unknown> {
86
- input: TInput;
87
- params: Record<string, string>;
88
- query: Record<string, string>;
89
- headers: Record<string, string>;
90
- user: User | null;
91
- db: DBClient;
92
- env: Record<string, string>;
93
- log: Logger;
94
- cache: CacheClient;
95
- palbase: PalbaseBindings;
96
- requestId: string;
97
- projectId: string;
98
- environmentId: string;
99
- }
100
- /** Middleware function signature — uses MiddlewareContext (no input, not yet validated). */
101
- type Middleware = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
102
- /** Configuration for defining an endpoint. */
103
- interface EndpointConfig<TInputSchema extends ZodSchema = ZodSchema, TOutputSchema extends ZodSchema = ZodSchema> {
104
- method: HttpMethod;
105
- auth?: Partial<AuthConfig>;
106
- rateLimit?: RateLimitConfig;
107
- input?: TInputSchema;
108
- output?: TOutputSchema;
109
- middleware?: Middleware[];
110
- handler: (ctx: EndpointContext<z.infer<TInputSchema>>) => Promise<z.infer<TOutputSchema>>;
111
- }
112
- /** Define a type-safe endpoint. Input schema infers the ctx.input type. */
113
- declare function defineEndpoint<TInputSchema extends ZodSchema, TOutputSchema extends ZodSchema>(config: EndpointConfig<TInputSchema, TOutputSchema>): EndpointConfig<TInputSchema, TOutputSchema>;
114
-
115
- export { type AuthConfig as A, type CacheClient as C, type DBClient as D, type EndpointContext as E, type HttpMethod as H, type Logger as L, type Middleware as M, type PalbaseBindings as P, type RateLimitConfig as R, type User as U, type EndpointConfig as a, type MiddlewareContext as b, type MiddlewareHandler as c, defineEndpoint as d, defineMiddleware as e };