@palbase/backend 3.0.0 → 4.0.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.
- package/dist/{chunk-B7EUJP5W.js → chunk-EG7TTYHY.js} +113 -3
- package/dist/chunk-EG7TTYHY.js.map +1 -0
- package/dist/{chunk-PHAFZGHN.js → chunk-WUQO76NW.js} +26 -19
- package/dist/chunk-WUQO76NW.js.map +1 -0
- package/dist/db/index.cjs +117 -2
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.d.cts +2 -2
- package/dist/db/index.d.ts +2 -2
- package/dist/db/index.js +11 -1
- package/dist/{endpoint-DJ98tQd6.d.cts → endpoint-2d_DpASt.d.cts} +92 -56
- package/dist/{endpoint-DJ98tQd6.d.ts → endpoint-2d_DpASt.d.ts} +92 -56
- package/dist/{index-CXUs9iTQ.d.ts → index-DZW9CjiY.d.ts} +210 -41
- package/dist/{index-CZAwpQE1.d.cts → index-DzRFS3Tl.d.cts} +210 -41
- package/dist/index.cjs +371 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -215
- package/dist/index.d.ts +88 -215
- package/dist/index.js +217 -21
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +34 -19
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.d.cts +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.js +10 -2
- package/dist/test/index.js.map +1 -1
- package/docs/README.md +11 -11
- package/docs/database.md +40 -0
- package/docs/endpoints.md +98 -92
- package/docs/errors.md +37 -30
- package/docs/getting-started.md +24 -20
- package/docs/llms-full.txt +401 -235
- package/docs/routing.md +39 -45
- package/docs/schema.md +134 -23
- package/docs/services.md +14 -10
- package/package.json +2 -2
- package/dist/chunk-B7EUJP5W.js.map +0 -1
- package/dist/chunk-PHAFZGHN.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { C as CacheClient, b as PalbaseDocsClient, c as PalbaseFlagsClient, L as Logger, d as PalbaseNotificationsClient, Q as QueueClient, D as DBClient, e as PalbaseStorageClient, A as AuthSpec, R as RateLimitConfig,
|
|
2
|
-
export { f as AuthConfig, g as ClientInfo, h as
|
|
1
|
+
import { C as CacheClient, b as PalbaseDocsClient, c as PalbaseFlagsClient, L as Logger, d as PalbaseNotificationsClient, Q as QueueClient, D as DBClient, e as PalbaseStorageClient, A as AuthSpec, R as RateLimitConfig, U as User$1 } from './endpoint-2d_DpASt.js';
|
|
2
|
+
export { f as AuthConfig, B as BadRequest, g as ClientInfo, h as Conflict, i as DBOps, E as ErrorDef, j as ErrorMap, k as ErrorThrowers, F as FileContext, l as Forbidden, H as HttpError, m as HttpMethod, M as Middleware, n as MiddlewareContext, o as MiddlewareHandler, N as NotFound, P as PBRequest, p as PalError, q as PalbaseAnalyticsClient, r as PalbaseAnalyticsManagementNamespace, s as PalbaseAnalyticsProperties, t as PalbaseAnalyticsQueryNamespace, u as PalbaseAttestAndroidParams, v as PalbaseAttestAndroidResult, w as PalbaseAttestiOSParams, x as PalbaseAttestiOSResult, y as PalbaseAuthClient, z as PalbaseBindDeviceParams, G as PalbaseBucketClient, I as PalbaseCmsClient, J as PalbaseCmsFindOneOptions, K as PalbaseCmsFindOptions, O as PalbaseCohortQueryInput, S as PalbaseCohortResult, T as PalbaseCollectionRef, V as PalbaseCountQueryInput, W as PalbaseCountResult, X as PalbaseCreateLinkParams, Y as PalbaseDeviceInfo, Z as PalbaseDeviceTokenView, _ as PalbaseDocumentRef, $ as PalbaseDocumentSnapshot, a0 as PalbaseEmailClient, a1 as PalbaseEmailSendParams, a2 as PalbaseEmailSendResponse, a3 as PalbaseEventNamesResult, a4 as PalbaseEventsQueryInput, a5 as PalbaseEventsResult, a6 as PalbaseFileObject, a7 as PalbaseFlag, a8 as PalbaseFlagContext, a9 as PalbaseFlagVariant, aa as PalbaseFunctionsClient, ab as PalbaseFunnelQueryInput, ac as PalbaseFunnelResult, ad as PalbaseIdentifyTraits, ae as PalbaseInboxClient, af as PalbaseInboxListOptions, ag as PalbaseInboxListResult, ah as PalbaseInboxMessage, ai as PalbaseInboxSendParams, aj as PalbaseInboxSendResponse, ak as PalbaseInitialLink, al as PalbaseInvokeOptions, am as PalbaseLink, an as PalbaseLinkAnalytics, ao as PalbaseLinkDetails, ap as PalbaseLinksClient, aq as PalbaseListLinksOptions, ar as PalbaseListLinksResult, as as PalbaseListOptions, at as PalbaseMatchParams, au as PalbaseMultiChannelResponse, av as PalbaseOverviewResult, aw as PalbasePreferences, ax as PalbasePreferencesClient, ay as PalbasePublicUrlResponse, az as PalbasePushClient, aA as PalbasePushSendParams, aB as PalbasePushSendResponse, aC as PalbaseQrCodeOptions, aD as PalbaseQuerySnapshot, aE as PalbaseRealtimeChannel, aF as PalbaseRealtimeClient, aG as PalbaseRealtimeMessage, aH as PalbaseRegisterDeviceParams, aI as PalbaseResult, aJ as PalbaseRetentionQueryInput, aK as PalbaseRetentionResult, aL as PalbaseSession, aM as PalbaseSignedUrlResponse, aN as PalbaseSmsClient, aO as PalbaseSmsSendParams, aP as PalbaseSmsSendResponse, aQ as PalbaseTransformOptions, aR as PalbaseUpdateLinkParams, aS as PalbaseUploadOptions, aT as PalbaseUser, aU as PalbaseUserDetailResult, aV as PalbaseUsersQueryInput, aW as PalbaseUsersResult, aX as PalbaseVerifyRequestSignatureParams, aY as PalbaseWhereOperator, aZ as TooManyRequests, a_ as TxClient, a$ as Unauthorized, b0 as defineMiddleware } from './endpoint-2d_DpASt.js';
|
|
3
3
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
-
import { E as EnvTypedDatabase, S as SchemaDef } from './index-
|
|
5
|
-
export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as
|
|
4
|
+
import { E as EnvTypedDatabase, S as SchemaDef } from './index-DZW9CjiY.js';
|
|
5
|
+
export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EnvServiceDatabase, f as EnvTables, g as EnvTypedTable, h as EnvTypedTx, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, i as PalbaseExtension, j as PolicyBuilder, k as PolicyCommand, l as PolicyDef, m as PolicyMode, R as RowShape, n as SchemaInput, T as TableDef, o as TableInput, p as TypedDB, q as TypedTable, r as TypedTx, s as boolean, t as defineSchema, u as enumType, v as integer, w as isPalbaseExtension, x as jsonb, y as makeTypedDB, z as policy, A as text, B as timestamp, D as uuid } from './index-DZW9CjiY.js';
|
|
6
6
|
export { TableTypes, Tables } from './db/env.js';
|
|
7
|
-
import {
|
|
7
|
+
import { ZodTypeAny } from 'zod';
|
|
8
8
|
export { z } from 'zod';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* runtime.ts — request-scoped service singletons.
|
|
12
12
|
*
|
|
13
13
|
* The backend SDK no longer threads a `ctx` god-object through every handler.
|
|
14
|
-
* Instead,
|
|
14
|
+
* Instead, controller methods import PascalCase service singletons directly:
|
|
15
15
|
*
|
|
16
|
-
* import {
|
|
16
|
+
* import { Controller, Post, Body, Database } from "@palbase/backend";
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* return
|
|
22
|
-
* }
|
|
23
|
-
* }
|
|
18
|
+
* \@Controller("/todos")
|
|
19
|
+
* export default class TodosController {
|
|
20
|
+
* \@Post("") create(\@Body(CreateTodoBody) body: CreateTodoBody): unknown {
|
|
21
|
+
* return Database.insert("todos", { title: body.title });
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
24
|
*
|
|
25
25
|
* The singletons are thin Proxies. Every property access forwards to the live
|
|
26
26
|
* client for the CURRENT request scope, resolved through {@link __getRuntime}.
|
|
@@ -100,12 +100,17 @@ declare function __getRuntime(): RuntimeServices;
|
|
|
100
100
|
* The raw string ops (`query`/`insert`/`update`/`delete`/`findById`/`findMany`)
|
|
101
101
|
* are also available for dynamic table names and read-only SQL.
|
|
102
102
|
*
|
|
103
|
+
* RLS is enforced by default (the runtime runs each op as `authenticated` with
|
|
104
|
+
* the verified user's claims). To bypass RLS, call `Database.asService()` —
|
|
105
|
+
* explicit and greppable — which runs as the `service_role` (BYPASSRLS).
|
|
106
|
+
*
|
|
103
107
|
* @example
|
|
104
108
|
* import { Database } from "@palbase/backend";
|
|
105
109
|
*
|
|
106
110
|
* const todo = await Database.tables.todos.insert({ title: req.input.title });
|
|
107
111
|
* todo.id; // string ✓
|
|
108
112
|
* const rows = await Database.query("SELECT id FROM todos WHERE done = $1", [false]);
|
|
113
|
+
* const all = await Database.asService().tables.todos.findMany({}); // RLS bypass
|
|
109
114
|
*/
|
|
110
115
|
declare const Database: EnvTypedDatabase;
|
|
111
116
|
/** Firestore-like document client (PalDocs). */
|
|
@@ -149,219 +154,87 @@ declare const Flags: PalbaseFlagsClient;
|
|
|
149
154
|
*/
|
|
150
155
|
declare function makeEnvDts(schema: SchemaDef): string;
|
|
151
156
|
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
*
|
|
156
|
-
* Everything that types `req` lives here (colocated): `auth` → `req.user`
|
|
157
|
-
* nullability, `input` → `req.input`, `errors` → `req.errors`, `output` → the
|
|
158
|
-
* return type. There is NO `method`/`path` on a handler — the HTTP verb + path
|
|
159
|
-
* are declared in a controller's route map, NOT on the handler. A handler file
|
|
160
|
-
* does:
|
|
161
|
-
*
|
|
162
|
-
* // handlers/places/import-nearby.ts
|
|
163
|
-
* export default defineHandler({ auth, input, output, errors, handler });
|
|
164
|
-
*
|
|
165
|
-
* # Runtime-readable shape (read by the Go runtime's extract_meta.js)
|
|
166
|
-
*
|
|
167
|
-
* `defineHandler` returns a {@link HandlerDef}: a plain object marked with
|
|
168
|
-
* `__palbase: "handler"` carrying the optional `auth`/`input`/`output`/`errors`
|
|
169
|
-
* and the `handler` function. There is deliberately NO `method`/`path` on it —
|
|
170
|
-
* a handler is route-agnostic.
|
|
171
|
-
*/
|
|
172
|
-
/** Configuration accepted by {@link defineHandler}. Carries the schema +
|
|
173
|
-
* auth/errors/middleware that type `req`, but NO `method` (routing lives in
|
|
174
|
-
* controllers). */
|
|
175
|
-
interface HandlerConfig<TInputSchema extends ZodSchema = ZodSchema, TOutputSchema extends ZodSchema = ZodSchema, TAuth extends AuthSpec | undefined = undefined, TErrors extends ErrorMap | undefined = undefined> {
|
|
176
|
-
auth?: TAuth;
|
|
177
|
-
rateLimit?: RateLimitConfig;
|
|
178
|
-
input?: TInputSchema;
|
|
179
|
-
output?: TOutputSchema;
|
|
180
|
-
errors?: TErrors;
|
|
181
|
-
middleware?: Middleware[];
|
|
182
|
-
handler: (req: PBRequest<z.infer<TInputSchema>, IsAuthed<TAuth>, TErrors>) => Promise<z.infer<TOutputSchema>> | z.infer<TOutputSchema>;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* The runtime-readable handler descriptor returned by {@link defineHandler}.
|
|
186
|
-
*
|
|
187
|
-
* Shape (the Go runtime's `extract_meta.js` reads this off the default export):
|
|
188
|
-
*
|
|
189
|
-
* {
|
|
190
|
-
* __palbase: "handler",
|
|
191
|
-
* auth?: AuthSpec,
|
|
192
|
-
* rateLimit?: RateLimitConfig,
|
|
193
|
-
* input?: ZodSchema,
|
|
194
|
-
* output?: ZodSchema,
|
|
195
|
-
* errors?: ErrorMap,
|
|
196
|
-
* middleware?: Middleware[],
|
|
197
|
-
* handler: (req) => result, // the invoked function
|
|
198
|
-
* }
|
|
199
|
-
*
|
|
200
|
-
* NOTE: there is NO `method`/`path` — those come from the controller route map.
|
|
201
|
-
*/
|
|
202
|
-
interface HandlerDef<TInputSchema extends ZodSchema = ZodSchema, TOutputSchema extends ZodSchema = ZodSchema, TAuth extends AuthSpec | undefined = undefined, TErrors extends ErrorMap | undefined = undefined> {
|
|
203
|
-
/** Discriminant the runtime + a controller route check read. */
|
|
204
|
-
readonly __palbase: "handler";
|
|
205
|
-
auth?: TAuth;
|
|
206
|
-
rateLimit?: RateLimitConfig;
|
|
207
|
-
input?: TInputSchema;
|
|
208
|
-
output?: TOutputSchema;
|
|
209
|
-
errors?: TErrors;
|
|
210
|
-
middleware?: Middleware[];
|
|
211
|
-
handler: (req: PBRequest<z.infer<TInputSchema>, IsAuthed<TAuth>, TErrors>) => Promise<z.infer<TOutputSchema>> | z.infer<TOutputSchema>;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* A {@link HandlerDef} with its schema/auth/errors type params ERASED — the
|
|
215
|
-
* shape a controller's `route.*` stores. EVERY `defineHandler()` result (any
|
|
216
|
-
* `auth`/`input`/`output`/`errors`) is assignable to this, because `handler` is
|
|
217
|
-
* typed `(req: never) => unknown` (params are contravariant, so a handler taking
|
|
218
|
-
* any concrete `PBRequest` satisfies a `never` param). A controller only needs
|
|
219
|
-
* to route + carry the handler; the handler's own `req` typing is validated
|
|
220
|
-
* where it is defined, so erasing the params here is sound and lets a route
|
|
221
|
-
* accept a handler regardless of its `auth`/`errors` — without `any`.
|
|
222
|
-
*/
|
|
223
|
-
interface AnyHandlerDef {
|
|
224
|
-
readonly __palbase: "handler";
|
|
157
|
+
/** Options accepted by `@Controller`. */
|
|
158
|
+
interface ControllerOptions {
|
|
159
|
+
/** Default auth for ALL routes in this controller (route-level overrides). */
|
|
225
160
|
auth?: AuthSpec;
|
|
226
|
-
rateLimit?: RateLimitConfig;
|
|
227
|
-
input?: ZodSchema;
|
|
228
|
-
output?: ZodSchema;
|
|
229
|
-
errors?: ErrorMap;
|
|
230
|
-
middleware?: Middleware[];
|
|
231
|
-
handler: (req: never) => unknown;
|
|
232
161
|
}
|
|
233
162
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
163
|
+
* Mark a class as a Palbase backend controller. `basePath` is the mount path
|
|
164
|
+
* for every route the class declares; `options.auth` sets the controller-level
|
|
165
|
+
* default auth (a route's own `auth` overrides it; absent ⇒ secure-by-default).
|
|
236
166
|
*
|
|
237
167
|
* @example
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* input: z.object({ title: z.string() }),
|
|
243
|
-
* output: z.object({ id: z.string() }),
|
|
244
|
-
* errors: { titleTaken: { status: 409, code: "title_taken" } },
|
|
245
|
-
* handler: (req) => Database.tables.todos.insert({ title: req.input.title }),
|
|
246
|
-
* });
|
|
168
|
+
* \@Controller("/todos", { auth: false })
|
|
169
|
+
* export class TodosController {
|
|
170
|
+
* \@Get("") list(\@Query(ListTodosQuery) q: ListTodosQuery): TodoSchema[] { … }
|
|
171
|
+
* }
|
|
247
172
|
*/
|
|
248
|
-
declare function
|
|
173
|
+
declare function Controller(basePath: string, options?: ControllerOptions): <T extends abstract new (...args: never[]) => object>(ctor: T) => T;
|
|
249
174
|
|
|
250
|
-
/**
|
|
251
|
-
*
|
|
252
|
-
* handler). Logic cannot be written here — a controller only wires existing
|
|
253
|
-
* handlers, so the small-blast-radius / no-cross-file-type-sync property holds.
|
|
254
|
-
*
|
|
255
|
-
* ```ts
|
|
256
|
-
* // controllers/places.controller.ts
|
|
257
|
-
* import { defineController, route } from "@palbase/backend";
|
|
258
|
-
* import importNearby from "../handlers/places/import-nearby.js";
|
|
259
|
-
* import listFavorites from "../handlers/places/list-favorites.js";
|
|
260
|
-
*
|
|
261
|
-
* export default defineController("/places", {
|
|
262
|
-
* importNearby: route.post("/import", importNearby), // map key = sugar
|
|
263
|
-
* listFavorites: route.get ("/favorites", listFavorites),
|
|
264
|
-
* });
|
|
265
|
-
* ```
|
|
266
|
-
*
|
|
267
|
-
* # Runtime-readable object shapes (read by the Go runtime's extract_meta.js)
|
|
268
|
-
*
|
|
269
|
-
* The default export of a controller file is a `ControllerDef`:
|
|
270
|
-
*
|
|
271
|
-
* ControllerDef = {
|
|
272
|
-
* __palbase: "controller",
|
|
273
|
-
* basePath: string, // e.g. "/places"
|
|
274
|
-
* routes: { [mapKey: string]: RouteDef } // mapKey is AUTHORING SUGAR only
|
|
275
|
-
* }
|
|
276
|
-
*
|
|
277
|
-
* RouteDef = {
|
|
278
|
-
* __palbase: "route",
|
|
279
|
-
* method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", // upper-case
|
|
280
|
-
* path: string, // the SUBPATH passed to route.*(…), e.g. "/import"
|
|
281
|
-
* handler: HandlerDef, // the imported defineHandler() result
|
|
282
|
-
* }
|
|
283
|
-
*
|
|
284
|
-
* HandlerDef = {
|
|
285
|
-
* __palbase: "handler",
|
|
286
|
-
* auth?, rateLimit?, input?, output?, errors?, middleware?,
|
|
287
|
-
* handler: (req) => result,
|
|
288
|
-
* }
|
|
289
|
-
*
|
|
290
|
-
* The FULL path for a route is `basePath + path` (e.g. "/places" + "/import" =
|
|
291
|
-
* "/places/import"). The operationId is NOT computed here — the runtime
|
|
292
|
-
* `generator.go` derives it FLAT from `(method, full-path)` (e.g.
|
|
293
|
-
* `postPlacesImport`). The map key (`importNearby`) is authoring sugar and is
|
|
294
|
-
* NOT the operationId.
|
|
295
|
-
*/
|
|
296
|
-
/** The five HTTP verbs a route may declare, upper-cased (matches the runtime
|
|
297
|
-
* router + OpenAPI which lower-cases on its own). */
|
|
175
|
+
/** The HTTP verbs a route may declare, upper-cased (the runtime router +
|
|
176
|
+
* OpenAPI lower-case on their own). */
|
|
298
177
|
type HttpMethodUpper = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
299
|
-
/**
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
readonly __palbase: "route";
|
|
306
|
-
/** Upper-case HTTP verb. */
|
|
307
|
-
method: M;
|
|
308
|
-
/** The subpath passed to `route.*(subpath, handler)` (relative to basePath). */
|
|
309
|
-
path: string;
|
|
310
|
-
/** The handler (a `defineHandler()` result) this route invokes. */
|
|
311
|
-
handler: H;
|
|
312
|
-
}
|
|
313
|
-
/** The route map a controller declares: keys are authoring sugar, values must
|
|
314
|
-
* each be a `route.*()` result. The mapped-over `Record<string, RouteDef>`
|
|
315
|
-
* constraint is what makes a bare handler (or plain object) a TS error. */
|
|
316
|
-
type RouteMap = Record<string, RouteDef>;
|
|
317
|
-
/**
|
|
318
|
-
* The controller descriptor returned by {@link defineController}. The default
|
|
319
|
-
* export of a `controllers/*.ts` file.
|
|
320
|
-
*/
|
|
321
|
-
interface ControllerDef<R extends RouteMap = RouteMap> {
|
|
322
|
-
/** Discriminant the runtime reads. */
|
|
323
|
-
readonly __palbase: "controller";
|
|
324
|
-
/** The path every route in this controller is mounted under (e.g. "/places"). */
|
|
325
|
-
basePath: string;
|
|
326
|
-
/** The route map — keys are authoring sugar, values are RouteDefs. */
|
|
327
|
-
routes: R;
|
|
178
|
+
/** Route-level options accepted by the method decorators (`@Get`/`@Post`/…). */
|
|
179
|
+
interface RouteOptions {
|
|
180
|
+
/** OVERRIDES the controller-level default auth for this one route. */
|
|
181
|
+
auth?: AuthSpec;
|
|
182
|
+
/** Per-route rate limit. */
|
|
183
|
+
rateLimit?: RateLimitConfig;
|
|
328
184
|
}
|
|
185
|
+
|
|
186
|
+
/** A legacy method decorator. */
|
|
187
|
+
type MethodDecorator = (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
188
|
+
/** `@Get(subpath, options?)` — declare a GET route. */
|
|
189
|
+
declare const Get: (subpath: string, options?: RouteOptions) => MethodDecorator;
|
|
190
|
+
/** `@Post(subpath, options?)` — declare a POST route. */
|
|
191
|
+
declare const Post: (subpath: string, options?: RouteOptions) => MethodDecorator;
|
|
192
|
+
/** `@Put(subpath, options?)` — declare a PUT route. */
|
|
193
|
+
declare const Put: (subpath: string, options?: RouteOptions) => MethodDecorator;
|
|
194
|
+
/** `@Patch(subpath, options?)` — declare a PATCH route. */
|
|
195
|
+
declare const Patch: (subpath: string, options?: RouteOptions) => MethodDecorator;
|
|
196
|
+
/** `@Delete(subpath, options?)` — declare a DELETE route. */
|
|
197
|
+
declare const Delete: (subpath: string, options?: RouteOptions) => MethodDecorator;
|
|
329
198
|
/**
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
* import { defineController, route } from "@palbase/backend";
|
|
335
|
-
* import create from "../handlers/todos/create.js";
|
|
336
|
-
*
|
|
337
|
-
* export default defineController("/todos", {
|
|
338
|
-
* create: route.post("/", create),
|
|
339
|
-
* });
|
|
340
|
-
*/
|
|
341
|
-
declare const route: {
|
|
342
|
-
readonly get: <H extends AnyHandlerDef>(path: string, handler: H) => RouteDef<H, "GET">;
|
|
343
|
-
readonly post: <H extends AnyHandlerDef>(path: string, handler: H) => RouteDef<H, "POST">;
|
|
344
|
-
readonly put: <H extends AnyHandlerDef>(path: string, handler: H) => RouteDef<H, "PUT">;
|
|
345
|
-
readonly patch: <H extends AnyHandlerDef>(path: string, handler: H) => RouteDef<H, "PATCH">;
|
|
346
|
-
readonly delete: <H extends AnyHandlerDef>(path: string, handler: H) => RouteDef<H, "DELETE">;
|
|
347
|
-
};
|
|
348
|
-
/**
|
|
349
|
-
* Define a controller: a base path + a route map (method+path → handler). The
|
|
350
|
-
* route-map KEY is authoring sugar only (NOT the operationId). Each route value
|
|
351
|
-
* MUST be a `route.*()` result — a bare handler or plain object is a TS error,
|
|
352
|
-
* which is what keeps logic out of controllers structurally.
|
|
199
|
+
* `@Returns(schema)` — declare the route's success-response zod schema. The
|
|
200
|
+
* method's return TYPE drives compile-time checking; `@Returns` supplies the
|
|
201
|
+
* matching zod VALUE the OpenAPI generator reads for the 200 response. Optional:
|
|
202
|
+
* a `void` method (no response body) omits it.
|
|
353
203
|
*
|
|
354
204
|
* @example
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
* export default defineController("/todos", {
|
|
360
|
-
* create: route.post("/", create),
|
|
361
|
-
* list: route.get("/", list),
|
|
362
|
-
* });
|
|
205
|
+
* \@Get("/{id}")
|
|
206
|
+
* \@Returns(TodoSchema)
|
|
207
|
+
* getOne(\@Param("id") id: string): TodoSchema { … }
|
|
363
208
|
*/
|
|
364
|
-
declare function
|
|
209
|
+
declare function Returns(schema: ZodTypeAny): MethodDecorator;
|
|
210
|
+
|
|
211
|
+
/** A legacy parameter decorator. */
|
|
212
|
+
type ParameterDecorator = (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
213
|
+
/** `@Body(schema)` — inject the request body, validated against `schema`. The
|
|
214
|
+
* developer writes `: T` (= `z.infer<schema>`, same name) for autocomplete. */
|
|
215
|
+
declare function Body(schema: ZodTypeAny): ParameterDecorator;
|
|
216
|
+
/** `@Query(schema)` — inject the parsed query params, validated against
|
|
217
|
+
* `schema`. */
|
|
218
|
+
declare function Query(schema: ZodTypeAny): ParameterDecorator;
|
|
219
|
+
/** `@Headers(schema?)` — inject the request headers (lowercase keys). With a
|
|
220
|
+
* schema, headers are validated + the codegen emits header parameters. */
|
|
221
|
+
declare function Headers(schema?: ZodTypeAny): ParameterDecorator;
|
|
222
|
+
/** `@Param("id")` — inject one matched path param by name. */
|
|
223
|
+
declare function Param(name: string): ParameterDecorator;
|
|
224
|
+
/** `@User()` — inject the authenticated user (`: User`, non-null for an
|
|
225
|
+
* effective-required route). The runtime resolves the effective auth. */
|
|
226
|
+
declare function User(): ParameterDecorator;
|
|
227
|
+
/** `@OptionalUser()` — inject the user as `User | null` (for routes whose
|
|
228
|
+
* effective auth is `false` / `{ required: false }`). */
|
|
229
|
+
declare function OptionalUser(): ParameterDecorator;
|
|
230
|
+
/** `@Client()` — inject the parsed calling-client metadata (`: ClientInfo`). */
|
|
231
|
+
declare function Client(): ParameterDecorator;
|
|
232
|
+
/** `@RequestId()` — inject the per-request id (`: string`). */
|
|
233
|
+
declare function RequestId(): ParameterDecorator;
|
|
234
|
+
/** `@TraceId()` — inject the W3C trace id (`: string`). */
|
|
235
|
+
declare function TraceId(): ParameterDecorator;
|
|
236
|
+
/** `@Req()` — inject the raw request object (escape hatch, `: PBRequest`). */
|
|
237
|
+
declare function Req(): ParameterDecorator;
|
|
365
238
|
|
|
366
239
|
/** Non-service, per-invocation data for background worker handlers.
|
|
367
240
|
* Services (Database, Log, …) are imported as singletons, not passed here. */
|
|
@@ -369,7 +242,7 @@ interface WorkerMeta {
|
|
|
369
242
|
/** Branch-scoped env vars. */
|
|
370
243
|
env: Record<string, string>;
|
|
371
244
|
/** The user that enqueued the job, if any (background jobs are usually system-initiated). */
|
|
372
|
-
user: User | null;
|
|
245
|
+
user: User$1 | null;
|
|
373
246
|
/** Per-invocation id for correlation. */
|
|
374
247
|
requestId: string;
|
|
375
248
|
projectId: string;
|
|
@@ -815,4 +688,4 @@ declare const documents: {
|
|
|
815
688
|
onDocumentDeleted(handler: HookHandler<DocumentDeletedEvent>): ResolvedHook<DocumentDeletedEvent>;
|
|
816
689
|
};
|
|
817
690
|
|
|
818
|
-
export { type BackoffStrategy, Cache, CacheClient, type
|
|
691
|
+
export { type BackoffStrategy, Body, Cache, CacheClient, Client, Controller, type ControllerOptions, type CustomWebhookConfig, DBClient, Database, Delete, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentUpdatedEvent, Documents, type EnvSecretRef, EnvTypedDatabase, type FileDeletedEvent, type FileUploadedEvent, Flags, Get, Headers, type HookHandler, type HookMeta, type HttpMethodUpper, type JobConfig, type JobMeta, Log, Logger, Notifications, OptionalUser, PalbaseDocsClient, PalbaseFlagsClient, PalbaseNotificationsClient, PalbaseStorageClient, Param, type PasswordResetEvent, Patch, Post, type ProviderEventMap, type ProviderWebhookConfig, Put, Query, Queue, QueueClient, RateLimitConfig, Req, RequestId, type ResolvedCustomWebhook, type ResolvedHook, type ResolvedJobConfig, type ResolvedProviderWebhook, type ResolvedWebhookConfig, type ResolvedWorkerConfig, Resource, type ResourceEnv, Returns, type RouteOptions, type RuntimeServices, SchemaDef, type SignInEvent, type SignOutEvent, Storage, TraceId, User, type UserCreatedEvent, User$1 as UserT, type WebhookEventHandler, type WebhookMeta, type WebhookProvider, type WebhookRequest, type WorkerConfig, type WorkerMeta, __getRuntime, __registerResource, __requestALS, __runResourceBoot, __runWithRuntime, __setRuntime, __shutdownResources, auth, defineJob, defineWebhook, defineWorker, documents, makeEnvDts, storage };
|