@palbase/backend 0.10.0 → 2.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/index.d.cts CHANGED
@@ -1,27 +1,228 @@
1
- import { E as EndpointContext, P as PalbaseModuleClients, D as DBClient, L as Logger, C as CacheClient, Q as QueueClient } from './endpoint-6LeBP-eb.cjs';
2
- export { A as AuthConfig, a as EndpointConfig, F as FileContext, H as HttpMethod, I as InsertShape, M as Middleware, b as MiddlewareContext, c as MiddlewareHandler, d as PalbaseAnalyticsClient, e as PalbaseAnalyticsManagementNamespace, f as PalbaseAnalyticsProperties, g as PalbaseAnalyticsQueryNamespace, h as PalbaseAttestAndroidParams, i as PalbaseAttestAndroidResult, j as PalbaseAttestiOSParams, k as PalbaseAttestiOSResult, l as PalbaseAuthClient, m as PalbaseBindDeviceParams, n as PalbaseBucketClient, o as PalbaseCmsClient, p as PalbaseCmsFindOneOptions, q as PalbaseCmsFindOptions, r as PalbaseCohortQueryInput, s as PalbaseCohortResult, t as PalbaseCollectionRef, u as PalbaseCountQueryInput, v as PalbaseCountResult, w as PalbaseCreateLinkParams, x as PalbaseDeviceInfo, y as PalbaseDeviceTokenView, z as PalbaseDocsClient, B as PalbaseDocumentRef, G as PalbaseDocumentSnapshot, J as PalbaseEmailClient, K as PalbaseEmailSendParams, N as PalbaseEmailSendResponse, O as PalbaseEventNamesResult, R as PalbaseEventsQueryInput, S as PalbaseEventsResult, T as PalbaseFileObject, U as PalbaseFlag, V as PalbaseFlagContext, W as PalbaseFlagVariant, X as PalbaseFlagsClient, Y as PalbaseFunctionsClient, Z as PalbaseFunnelQueryInput, _ as PalbaseFunnelResult, $ as PalbaseIdentifyTraits, a0 as PalbaseInboxClient, a1 as PalbaseInboxListOptions, a2 as PalbaseInboxListResult, a3 as PalbaseInboxMessage, a4 as PalbaseInboxSendParams, a5 as PalbaseInboxSendResponse, a6 as PalbaseInitialLink, a7 as PalbaseInvokeOptions, a8 as PalbaseLink, a9 as PalbaseLinkAnalytics, aa as PalbaseLinkDetails, ab as PalbaseLinksClient, ac as PalbaseListLinksOptions, ad as PalbaseListLinksResult, ae as PalbaseListOptions, af as PalbaseMatchParams, ag as PalbaseMultiChannelResponse, ah as PalbaseNotificationsClient, ai as PalbaseOverviewResult, aj as PalbasePreferences, ak as PalbasePreferencesClient, al as PalbasePublicUrlResponse, am as PalbasePushClient, an as PalbasePushSendParams, ao as PalbasePushSendResponse, ap as PalbaseQrCodeOptions, aq as PalbaseQuerySnapshot, ar as PalbaseRealtimeChannel, as as PalbaseRealtimeClient, at as PalbaseRealtimeMessage, au as PalbaseRegisterDeviceParams, av as PalbaseResult, aw as PalbaseRetentionQueryInput, ax as PalbaseRetentionResult, ay as PalbaseSession, az as PalbaseSignedUrlResponse, aA as PalbaseSmsClient, aB as PalbaseSmsSendParams, aC as PalbaseSmsSendResponse, aD as PalbaseStorageClient, aE as PalbaseTransformOptions, aF as PalbaseUpdateLinkParams, aG as PalbaseUploadOptions, aH as PalbaseUser, aI as PalbaseUserDetailResult, aJ as PalbaseUsersQueryInput, aK as PalbaseUsersResult, aL as PalbaseVerifyRequestSignatureParams, aM as PalbaseWhereOperator, aN as RateLimitConfig, aO as RowShape, aP as TxClient, aQ as TypedDB, aR as TypedTable, aS as TypedTx, aT as User, aU as defineEndpoint, aV as defineMiddleware, aW as makeTypedDB } from './endpoint-6LeBP-eb.cjs';
3
- export { C as ColumnBuilder, a as ColumnDef, b as ColumnType, O as OnDeleteAction, S as SchemaDef, T as TableDef, c as boolean, d as defineSchema, e as enumType, i as integer, j as jsonb, t as table, f as text, g as timestamp, u as uuid } from './schema-zk-a0Dv7.cjs';
1
+ import { D as DBClient, C as CacheClient, P as PalbaseDocsClient, a as PalbaseFlagsClient, L as Logger, b as PalbaseNotificationsClient, Q as QueueClient, c as PalbaseStorageClient, d as PalbaseModuleClients, U as User, E as ErrorThrowers } from './endpoint-BlcY2xNA.cjs';
2
+ export { A as AuthConfig, e as ClientInfo, f as EndpointConfig, g as ErrorDef, h as ErrorMap, F as FileContext, H as HttpError, i as HttpMethod, M as Middleware, j as MiddlewareContext, k as MiddlewareHandler, l as PBRequest, m as PalbaseAnalyticsClient, n as PalbaseAnalyticsManagementNamespace, o as PalbaseAnalyticsProperties, p as PalbaseAnalyticsQueryNamespace, q as PalbaseAttestAndroidParams, r as PalbaseAttestAndroidResult, s as PalbaseAttestiOSParams, t as PalbaseAttestiOSResult, u as PalbaseAuthClient, v as PalbaseBindDeviceParams, w as PalbaseBucketClient, x as PalbaseCmsClient, y as PalbaseCmsFindOneOptions, z as PalbaseCmsFindOptions, B as PalbaseCohortQueryInput, G as PalbaseCohortResult, I as PalbaseCollectionRef, J as PalbaseCountQueryInput, K as PalbaseCountResult, N as PalbaseCreateLinkParams, O as PalbaseDeviceInfo, R as PalbaseDeviceTokenView, S as PalbaseDocumentRef, T as PalbaseDocumentSnapshot, V as PalbaseEmailClient, W as PalbaseEmailSendParams, X as PalbaseEmailSendResponse, Y as PalbaseEventNamesResult, Z as PalbaseEventsQueryInput, _ as PalbaseEventsResult, $ as PalbaseFileObject, a0 as PalbaseFlag, a1 as PalbaseFlagContext, a2 as PalbaseFlagVariant, a3 as PalbaseFunctionsClient, a4 as PalbaseFunnelQueryInput, a5 as PalbaseFunnelResult, a6 as PalbaseIdentifyTraits, a7 as PalbaseInboxClient, a8 as PalbaseInboxListOptions, a9 as PalbaseInboxListResult, aa as PalbaseInboxMessage, ab as PalbaseInboxSendParams, ac as PalbaseInboxSendResponse, ad as PalbaseInitialLink, ae as PalbaseInvokeOptions, af as PalbaseLink, ag as PalbaseLinkAnalytics, ah as PalbaseLinkDetails, ai as PalbaseLinksClient, aj as PalbaseListLinksOptions, ak as PalbaseListLinksResult, al as PalbaseListOptions, am as PalbaseMatchParams, an as PalbaseMultiChannelResponse, ao as PalbaseOverviewResult, ap as PalbasePreferences, aq as PalbasePreferencesClient, ar as PalbasePublicUrlResponse, as as PalbasePushClient, at as PalbasePushSendParams, au as PalbasePushSendResponse, av as PalbaseQrCodeOptions, aw as PalbaseQuerySnapshot, ax as PalbaseRealtimeChannel, ay as PalbaseRealtimeClient, az as PalbaseRealtimeMessage, aA as PalbaseRegisterDeviceParams, aB as PalbaseResult, aC as PalbaseRetentionQueryInput, aD as PalbaseRetentionResult, aE as PalbaseSession, aF as PalbaseSignedUrlResponse, aG as PalbaseSmsClient, aH as PalbaseSmsSendParams, aI as PalbaseSmsSendResponse, aJ as PalbaseTransformOptions, aK as PalbaseUpdateLinkParams, aL as PalbaseUploadOptions, aM as PalbaseUser, aN as PalbaseUserDetailResult, aO as PalbaseUsersQueryInput, aP as PalbaseUsersResult, aQ as PalbaseVerifyRequestSignatureParams, aR as PalbaseWhereOperator, aS as RateLimitConfig, aT as TxClient, aU as defineEndpoint, aV as defineMiddleware } from './endpoint-BlcY2xNA.cjs';
3
+ import { AsyncLocalStorage } from 'node:async_hooks';
4
+ import { T as TableDef, C as ColIsOptionalOnInsert, a as ColValue, S as SchemaDef } from './schema-BqfEhIC0.cjs';
5
+ export { b as ColumnBuilder, c as ColumnDef, d as ColumnType, O as OnDeleteAction, e as boolean, f as defineSchema, g as enumType, i as integer, j as jsonb, t as table, h as text, k as timestamp, u as uuid } from './schema-BqfEhIC0.cjs';
4
6
  export { z } from 'zod';
5
7
 
6
- /** HTTP error with structured error response format. */
7
- declare class HttpError extends Error {
8
- readonly status: number;
9
- readonly error: string;
10
- readonly errorDescription: string;
11
- constructor(status: number, error: string, errorDescription: string);
12
- /**
13
- * Serialize to the standard Palbase error response format.
14
- * The `requestId` is injected by the runtime layer from the request context.
15
- * When called without arguments (e.g. JSON.stringify), request_id is omitted.
16
- */
17
- toJSON(requestId?: string): {
18
- error: string;
19
- error_description: string;
20
- status: number;
21
- request_id?: string;
8
+ /**
9
+ * typed-db.ts Task 2: TypedDB schema-derived insert/row shapes.
10
+ *
11
+ * Derives INSERT and full-row TypeScript types from a `defineSchema()` result
12
+ * and wraps the untyped runtime `DBClient` with a typed facade.
13
+ *
14
+ * No value-any. No `as unknown as X`. The two narrow `as` casts in
15
+ * `makeTypedTable` are safe because:
16
+ * - `data as Record<string, unknown>`: InsertShape<T> maps string keys to
17
+ * typed values; all value types are subsets of `unknown`, so the cast is
18
+ * structurally sound.
19
+ * - `result as RowShape<T>`: The runtime DBClient returns `Record<string,
20
+ * unknown>` which is the erased form of the typed row; we're narrowing back
21
+ * to the precise shape that the schema declared.
22
+ * Both casts are narrowing only (not widening) and correctness is guaranteed
23
+ * by the schema the caller provides.
24
+ */
25
+
26
+ /** Keys of C whose columns are required on INSERT (not nullable, no default). */
27
+ type RequiredKeys<C> = {
28
+ [K in keyof C]: ColIsOptionalOnInsert<C[K]> extends true ? never : K;
29
+ }[keyof C];
30
+ /** Keys of C whose columns are optional on INSERT (nullable or has a default). */
31
+ type OptionalKeys<C> = {
32
+ [K in keyof C]: ColIsOptionalOnInsert<C[K]> extends true ? K : never;
33
+ }[keyof C];
34
+ /**
35
+ * The TypeScript type for an INSERT payload for table `T`.
36
+ * - Required: columns that are NOT NULL and have no DB-level default.
37
+ * - Optional: columns that are nullable or carry a default.
38
+ *
39
+ * When all columns are optional, `RequiredKeys<C>` resolves to `never` and
40
+ * the first part becomes `{}`, which is a neutral element for `&`.
41
+ */
42
+ type InsertShape<T extends TableDef> = {
43
+ [K in RequiredKeys<T["columns"]>]: ColValue<T["columns"][K]>;
44
+ } & {
45
+ [K in OptionalKeys<T["columns"]>]?: ColValue<T["columns"][K]>;
46
+ };
47
+ /**
48
+ * The TypeScript type for a full row returned by the DB for table `T`.
49
+ * Every column is present; nullable columns resolve to `T | null`.
50
+ */
51
+ type RowShape<T extends TableDef> = {
52
+ [K in keyof T["columns"]]: ColValue<T["columns"][K]>;
53
+ };
54
+ /** A typed table accessor that mirrors the runtime DBClient surface. */
55
+ interface TypedTable<T extends TableDef> {
56
+ insert(data: InsertShape<T>): Promise<RowShape<T>>;
57
+ update(id: string, data: Partial<InsertShape<T>>): Promise<RowShape<T>>;
58
+ delete(id: string): Promise<void>;
59
+ findById(id: string): Promise<RowShape<T> | null>;
60
+ findMany(query?: Partial<RowShape<T>>): Promise<RowShape<T>[]>;
61
+ }
62
+ /** A typed DB facade covering all tables declared in schema `S`. */
63
+ interface TypedDB<S extends SchemaDef> {
64
+ tables: {
65
+ [K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
22
66
  };
67
+ transaction<T>(fn: (tx: TypedTx<S>) => Promise<T>): Promise<T>;
68
+ }
69
+ /** Transaction-scoped typed facade: same typed tables, no nested transaction. */
70
+ interface TypedTx<S extends SchemaDef> {
71
+ tables: {
72
+ [K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
73
+ };
74
+ }
75
+ /**
76
+ * Wraps a raw `DBClient` with the type-safe `TypedDB<S>` facade derived from
77
+ * the provided schema. No behavior change — all calls delegate to `raw` with
78
+ * the table name as a plain string.
79
+ *
80
+ * `buildTables` is the reusable factory that wraps any op-bearing client
81
+ * (`TxClient` — the surface shared by `DBClient` and the transaction-scoped
82
+ * client) into the typed tables map. It is used both for the top-level db
83
+ * (wrapping `raw`) and inside `transaction`, where it wraps the raw `TxClient`
84
+ * the runtime yields so the callback sees the same typed `.tables` API.
85
+ *
86
+ * `transaction` delegates straight to `raw.transaction`; the two narrow
87
+ * `as TypedTx<S>` / `as TypedDB<S>` casts are single structural narrowings
88
+ * from the dynamically-built tables object to the precise mapped type (TS
89
+ * cannot infer through `Object.keys` iteration) — see module-level doc comment.
90
+ */
91
+ declare function makeTypedDB<S extends SchemaDef>(schema: S, raw: DBClient): TypedDB<S>;
92
+
93
+ /**
94
+ * runtime.ts — request-scoped service singletons.
95
+ *
96
+ * The backend SDK no longer threads a `ctx` god-object through every handler.
97
+ * Instead, endpoint authors import PascalCase service singletons directly:
98
+ *
99
+ * import { Database, Documents, Cache } from "@palbase/backend";
100
+ *
101
+ * export default defineEndpoint({
102
+ * method: "POST",
103
+ * handler: async (req) => {
104
+ * const row = await Database.insert("todos", { title: req.input.title });
105
+ * return row;
106
+ * },
107
+ * });
108
+ *
109
+ * The singletons are thin Proxies. Every property access forwards to the live
110
+ * client for the CURRENT request scope, resolved through {@link __getRuntime}.
111
+ *
112
+ * # Request-scope resolution (persistent app-server)
113
+ *
114
+ * The runtime is a long-running Node process that serves many concurrent
115
+ * requests on one event loop (NOT a fresh subprocess per request). A single
116
+ * module-global slot would let one in-flight request's services bleed into
117
+ * another's. So the services are carried in an {@link AsyncLocalStorage} store
118
+ * ({@link __requestALS}) that the runtime sets per request with
119
+ * {@link __runWithRuntime}; every async continuation of that request reads its
120
+ * own store. `__getRuntime` reads the ALS store first; the module-global slot
121
+ * (set by {@link __setRuntime}) is only a fallback for callers that run OUTSIDE
122
+ * an ALS scope (dev-server, unit tests, the legacy single-shot path). Because
123
+ * each `br-<ref>` pod is single-tenant, there is no cross-tenant leakage; the
124
+ * ALS store is what prevents cross-REQUEST leakage within the shared process.
125
+ *
126
+ * The seam that makes `import { Database } from "@palbase/backend"` resolve to
127
+ * the runtime-injected client: `@palbase/backend` is marked esbuild-EXTERNAL
128
+ * when the tenant bundle is built, and the package is installed globally in the
129
+ * pod (NODE_PATH=/usr/local/lib/node_modules). So worker.js's
130
+ * `require('@palbase/backend')` and the bundle's `import` resolve to ONE shared
131
+ * module instance — the ALS store and `__setRuntime` slot on that instance are
132
+ * visible to the singletons the bundle imported.
133
+ */
134
+
135
+ /** The set of live clients the runtime injects per request scope.
136
+ *
137
+ * EXCLUDED on purpose: Realtime, Functions, CMS, Links, Analytics, Auth. They
138
+ * are not exposed as backend handler singletons (auth lives on the client SDK;
139
+ * the rest are out of scope for backend endpoints). */
140
+ interface RuntimeServices {
141
+ Database: DBClient;
142
+ Documents: PalbaseDocsClient;
143
+ Storage: PalbaseStorageClient;
144
+ Cache: CacheClient;
145
+ Queue: QueueClient;
146
+ Log: Logger;
147
+ Notifications: PalbaseNotificationsClient;
148
+ Flags: PalbaseFlagsClient;
23
149
  }
150
+ /**
151
+ * Per-request store. The persistent runtime runs each request inside
152
+ * {@link __runWithRuntime}, so every async continuation of that request reads
153
+ * its OWN `runtime` (and any other request-scoped fields the runtime adds).
154
+ *
155
+ * Exported with a `__` prefix so the runtime (worker.js) shares the SAME ALS
156
+ * instance across the one module instance — two ALS instances would silently
157
+ * not see each other's stores. NOT part of the public author-facing API.
158
+ */
159
+ declare const __requestALS: AsyncLocalStorage<{
160
+ runtime: RuntimeServices;
161
+ }>;
162
+ /** Install the live clients in the process-global fallback slot.
163
+ *
164
+ * Persistent-server requests should use {@link __runWithRuntime} instead; this
165
+ * remains for dev-server / tests / the legacy single-shot path that run without
166
+ * an ALS scope. NOT part of the public author-facing API. */
167
+ declare function __setRuntime(services: RuntimeServices): void;
168
+ /** Run `fn` with `services` bound as the request-scoped runtime.
169
+ *
170
+ * The persistent worker calls this once per request so concurrent requests
171
+ * never share a services slot. NOT part of the public author-facing API. */
172
+ declare function __runWithRuntime<T>(services: RuntimeServices, fn: () => T): T;
173
+ /** Read the live clients, throwing if accessed outside a request scope.
174
+ *
175
+ * Resolves the ALS store first (persistent server, per-request), then the
176
+ * process-global fallback (dev-server / tests). NOT part of the public
177
+ * author-facing API — used by the runtime and the singleton Proxies. */
178
+ declare function __getRuntime(): RuntimeServices;
179
+ /** The project's own Postgres (pgx, schema `env_<envId>`). Typed CRUD +
180
+ * `query`/`transaction`. For a typed `.tables.<name>` API, wrap with
181
+ * {@link typedDatabase}. */
182
+ declare const Database: DBClient;
183
+ /** Firestore-like document client (PalDocs). */
184
+ declare const Documents: PalbaseDocsClient;
185
+ /** Object storage client (buckets, signed URLs). */
186
+ declare const Storage: PalbaseStorageClient;
187
+ /** JSON-typed cache (get/set/incr/getOrSet). */
188
+ declare const Cache: CacheClient;
189
+ /** Background job queue. */
190
+ declare const Queue: QueueClient;
191
+ /** Structured logger. */
192
+ declare const Log: Logger;
193
+ /** Push / email / SMS / in-app notifications. */
194
+ declare const Notifications: PalbaseNotificationsClient;
195
+ /** Feature flags. */
196
+ declare const Flags: PalbaseFlagsClient;
197
+ /**
198
+ * Type the `Database` singleton against a `defineSchema()` result, returning a
199
+ * facade with a typed `.tables.<name>.insert(...)` API alongside the raw
200
+ * `query`/`transaction` ops.
201
+ *
202
+ * const Db = typedDatabase(schema);
203
+ * const todo = await Db.tables.todos.insert({ title: "x" });
204
+ *
205
+ * This is per-endpoint (not global module augmentation), so one endpoint's
206
+ * tables never leak into another's `Database` type.
207
+ */
208
+ declare function typedDatabase<TSchema extends SchemaDef>(schema: TSchema): TypedDB<TSchema> & DBClient;
24
209
 
210
+ /** Context injected into worker handlers — the non-request-scoped service
211
+ * surface (db/log/cache/queue + module clients), plus correlation ids. Workers
212
+ * are not part of the Phase 1 `ctx → PBRequest` redesign, so they keep their
213
+ * own `ctx`; the job payload arrives as the handler's second argument. */
214
+ interface WorkerContext extends PalbaseModuleClients {
215
+ user: User | null;
216
+ db: DBClient;
217
+ env: Record<string, string>;
218
+ log: Logger;
219
+ cache: CacheClient;
220
+ queue: QueueClient;
221
+ errors: ErrorThrowers<undefined>;
222
+ requestId: string;
223
+ projectId: string;
224
+ environmentId: string;
225
+ }
25
226
  /** Backoff strategy for worker retries. */
26
227
  type BackoffStrategy = "exponential" | "linear" | "fixed";
27
228
  /** Configuration for a background worker. */
@@ -35,7 +236,7 @@ interface WorkerConfig<TPayload = unknown> {
35
236
  /** Backoff strategy between retries. Defaults to "exponential". */
36
237
  backoff?: BackoffStrategy;
37
238
  /** Handler function that processes the job payload. */
38
- handler: (ctx: Omit<EndpointContext<TPayload>, "input" | "params" | "query" | "headers" | "file" | "method" | "endpointPath">, payload: TPayload) => Promise<void>;
239
+ handler: (ctx: WorkerContext, payload: TPayload) => Promise<void>;
39
240
  }
40
241
  /** Resolved worker configuration with defaults applied. */
41
242
  interface ResolvedWorkerConfig<TPayload = unknown> {
@@ -43,7 +244,7 @@ interface ResolvedWorkerConfig<TPayload = unknown> {
43
244
  retry: number;
44
245
  timeout: number;
45
246
  backoff: BackoffStrategy;
46
- handler: (ctx: Omit<EndpointContext<TPayload>, "input" | "params" | "query" | "headers" | "file" | "method" | "endpointPath">, payload: TPayload) => Promise<void>;
247
+ handler: (ctx: WorkerContext, payload: TPayload) => Promise<void>;
47
248
  }
48
249
  /**
49
250
  * Define a background worker that processes jobs from the queue.
@@ -370,4 +571,4 @@ declare const documents: {
370
571
  onDocumentDeleted(handler: HookHandler<DocumentDeletedEvent>): ResolvedHook<DocumentDeletedEvent>;
371
572
  };
372
573
 
373
- export { type BackoffStrategy, CacheClient, type CustomWebhookConfig, DBClient, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentUpdatedEvent, EndpointContext, type EnvSecretRef, type FileDeletedEvent, type FileUploadedEvent, type HookContext, type HookHandler, HttpError, type JobConfig, type JobContext, Logger, PalbaseModuleClients, type PasswordResetEvent, type ProviderEventMap, type ProviderWebhookConfig, QueueClient, type ResolvedCustomWebhook, type ResolvedHook, type ResolvedJobConfig, type ResolvedProviderWebhook, type ResolvedWebhookConfig, type ResolvedWorkerConfig, type SignInEvent, type SignOutEvent, type UserCreatedEvent, type WebhookContext, type WebhookEventHandler, type WebhookProvider, type WebhookRequest, type WorkerConfig, auth, defineJob, defineWebhook, defineWorker, documents, storage };
574
+ export { type BackoffStrategy, Cache, CacheClient, type CustomWebhookConfig, DBClient, Database, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentUpdatedEvent, Documents, type EnvSecretRef, ErrorThrowers, type FileDeletedEvent, type FileUploadedEvent, Flags, type HookContext, type HookHandler, type InsertShape, type JobConfig, type JobContext, Log, Logger, Notifications, PalbaseDocsClient, PalbaseFlagsClient, PalbaseNotificationsClient, PalbaseStorageClient, type PasswordResetEvent, type ProviderEventMap, type ProviderWebhookConfig, Queue, QueueClient, type ResolvedCustomWebhook, type ResolvedHook, type ResolvedJobConfig, type ResolvedProviderWebhook, type ResolvedWebhookConfig, type ResolvedWorkerConfig, type RowShape, type RuntimeServices, SchemaDef, type SignInEvent, type SignOutEvent, Storage, TableDef, type TypedDB, type TypedTable, type TypedTx, User, type UserCreatedEvent, type WebhookContext, type WebhookEventHandler, type WebhookProvider, type WebhookRequest, type WorkerConfig, type WorkerContext, __getRuntime, __requestALS, __runWithRuntime, __setRuntime, auth, defineJob, defineWebhook, defineWorker, documents, makeTypedDB, storage, typedDatabase };
package/dist/index.d.ts CHANGED
@@ -1,27 +1,228 @@
1
- import { E as EndpointContext, P as PalbaseModuleClients, D as DBClient, L as Logger, C as CacheClient, Q as QueueClient } from './endpoint-BbbU1hE1.js';
2
- export { A as AuthConfig, a as EndpointConfig, F as FileContext, H as HttpMethod, I as InsertShape, M as Middleware, b as MiddlewareContext, c as MiddlewareHandler, d as PalbaseAnalyticsClient, e as PalbaseAnalyticsManagementNamespace, f as PalbaseAnalyticsProperties, g as PalbaseAnalyticsQueryNamespace, h as PalbaseAttestAndroidParams, i as PalbaseAttestAndroidResult, j as PalbaseAttestiOSParams, k as PalbaseAttestiOSResult, l as PalbaseAuthClient, m as PalbaseBindDeviceParams, n as PalbaseBucketClient, o as PalbaseCmsClient, p as PalbaseCmsFindOneOptions, q as PalbaseCmsFindOptions, r as PalbaseCohortQueryInput, s as PalbaseCohortResult, t as PalbaseCollectionRef, u as PalbaseCountQueryInput, v as PalbaseCountResult, w as PalbaseCreateLinkParams, x as PalbaseDeviceInfo, y as PalbaseDeviceTokenView, z as PalbaseDocsClient, B as PalbaseDocumentRef, G as PalbaseDocumentSnapshot, J as PalbaseEmailClient, K as PalbaseEmailSendParams, N as PalbaseEmailSendResponse, O as PalbaseEventNamesResult, R as PalbaseEventsQueryInput, S as PalbaseEventsResult, T as PalbaseFileObject, U as PalbaseFlag, V as PalbaseFlagContext, W as PalbaseFlagVariant, X as PalbaseFlagsClient, Y as PalbaseFunctionsClient, Z as PalbaseFunnelQueryInput, _ as PalbaseFunnelResult, $ as PalbaseIdentifyTraits, a0 as PalbaseInboxClient, a1 as PalbaseInboxListOptions, a2 as PalbaseInboxListResult, a3 as PalbaseInboxMessage, a4 as PalbaseInboxSendParams, a5 as PalbaseInboxSendResponse, a6 as PalbaseInitialLink, a7 as PalbaseInvokeOptions, a8 as PalbaseLink, a9 as PalbaseLinkAnalytics, aa as PalbaseLinkDetails, ab as PalbaseLinksClient, ac as PalbaseListLinksOptions, ad as PalbaseListLinksResult, ae as PalbaseListOptions, af as PalbaseMatchParams, ag as PalbaseMultiChannelResponse, ah as PalbaseNotificationsClient, ai as PalbaseOverviewResult, aj as PalbasePreferences, ak as PalbasePreferencesClient, al as PalbasePublicUrlResponse, am as PalbasePushClient, an as PalbasePushSendParams, ao as PalbasePushSendResponse, ap as PalbaseQrCodeOptions, aq as PalbaseQuerySnapshot, ar as PalbaseRealtimeChannel, as as PalbaseRealtimeClient, at as PalbaseRealtimeMessage, au as PalbaseRegisterDeviceParams, av as PalbaseResult, aw as PalbaseRetentionQueryInput, ax as PalbaseRetentionResult, ay as PalbaseSession, az as PalbaseSignedUrlResponse, aA as PalbaseSmsClient, aB as PalbaseSmsSendParams, aC as PalbaseSmsSendResponse, aD as PalbaseStorageClient, aE as PalbaseTransformOptions, aF as PalbaseUpdateLinkParams, aG as PalbaseUploadOptions, aH as PalbaseUser, aI as PalbaseUserDetailResult, aJ as PalbaseUsersQueryInput, aK as PalbaseUsersResult, aL as PalbaseVerifyRequestSignatureParams, aM as PalbaseWhereOperator, aN as RateLimitConfig, aO as RowShape, aP as TxClient, aQ as TypedDB, aR as TypedTable, aS as TypedTx, aT as User, aU as defineEndpoint, aV as defineMiddleware, aW as makeTypedDB } from './endpoint-BbbU1hE1.js';
3
- export { C as ColumnBuilder, a as ColumnDef, b as ColumnType, O as OnDeleteAction, S as SchemaDef, T as TableDef, c as boolean, d as defineSchema, e as enumType, i as integer, j as jsonb, t as table, f as text, g as timestamp, u as uuid } from './schema-zk-a0Dv7.js';
1
+ import { D as DBClient, C as CacheClient, P as PalbaseDocsClient, a as PalbaseFlagsClient, L as Logger, b as PalbaseNotificationsClient, Q as QueueClient, c as PalbaseStorageClient, d as PalbaseModuleClients, U as User, E as ErrorThrowers } from './endpoint-Djk5L6G2.js';
2
+ export { A as AuthConfig, e as ClientInfo, f as EndpointConfig, g as ErrorDef, h as ErrorMap, F as FileContext, H as HttpError, i as HttpMethod, M as Middleware, j as MiddlewareContext, k as MiddlewareHandler, l as PBRequest, m as PalbaseAnalyticsClient, n as PalbaseAnalyticsManagementNamespace, o as PalbaseAnalyticsProperties, p as PalbaseAnalyticsQueryNamespace, q as PalbaseAttestAndroidParams, r as PalbaseAttestAndroidResult, s as PalbaseAttestiOSParams, t as PalbaseAttestiOSResult, u as PalbaseAuthClient, v as PalbaseBindDeviceParams, w as PalbaseBucketClient, x as PalbaseCmsClient, y as PalbaseCmsFindOneOptions, z as PalbaseCmsFindOptions, B as PalbaseCohortQueryInput, G as PalbaseCohortResult, I as PalbaseCollectionRef, J as PalbaseCountQueryInput, K as PalbaseCountResult, N as PalbaseCreateLinkParams, O as PalbaseDeviceInfo, R as PalbaseDeviceTokenView, S as PalbaseDocumentRef, T as PalbaseDocumentSnapshot, V as PalbaseEmailClient, W as PalbaseEmailSendParams, X as PalbaseEmailSendResponse, Y as PalbaseEventNamesResult, Z as PalbaseEventsQueryInput, _ as PalbaseEventsResult, $ as PalbaseFileObject, a0 as PalbaseFlag, a1 as PalbaseFlagContext, a2 as PalbaseFlagVariant, a3 as PalbaseFunctionsClient, a4 as PalbaseFunnelQueryInput, a5 as PalbaseFunnelResult, a6 as PalbaseIdentifyTraits, a7 as PalbaseInboxClient, a8 as PalbaseInboxListOptions, a9 as PalbaseInboxListResult, aa as PalbaseInboxMessage, ab as PalbaseInboxSendParams, ac as PalbaseInboxSendResponse, ad as PalbaseInitialLink, ae as PalbaseInvokeOptions, af as PalbaseLink, ag as PalbaseLinkAnalytics, ah as PalbaseLinkDetails, ai as PalbaseLinksClient, aj as PalbaseListLinksOptions, ak as PalbaseListLinksResult, al as PalbaseListOptions, am as PalbaseMatchParams, an as PalbaseMultiChannelResponse, ao as PalbaseOverviewResult, ap as PalbasePreferences, aq as PalbasePreferencesClient, ar as PalbasePublicUrlResponse, as as PalbasePushClient, at as PalbasePushSendParams, au as PalbasePushSendResponse, av as PalbaseQrCodeOptions, aw as PalbaseQuerySnapshot, ax as PalbaseRealtimeChannel, ay as PalbaseRealtimeClient, az as PalbaseRealtimeMessage, aA as PalbaseRegisterDeviceParams, aB as PalbaseResult, aC as PalbaseRetentionQueryInput, aD as PalbaseRetentionResult, aE as PalbaseSession, aF as PalbaseSignedUrlResponse, aG as PalbaseSmsClient, aH as PalbaseSmsSendParams, aI as PalbaseSmsSendResponse, aJ as PalbaseTransformOptions, aK as PalbaseUpdateLinkParams, aL as PalbaseUploadOptions, aM as PalbaseUser, aN as PalbaseUserDetailResult, aO as PalbaseUsersQueryInput, aP as PalbaseUsersResult, aQ as PalbaseVerifyRequestSignatureParams, aR as PalbaseWhereOperator, aS as RateLimitConfig, aT as TxClient, aU as defineEndpoint, aV as defineMiddleware } from './endpoint-Djk5L6G2.js';
3
+ import { AsyncLocalStorage } from 'node:async_hooks';
4
+ import { T as TableDef, C as ColIsOptionalOnInsert, a as ColValue, S as SchemaDef } from './schema-BqfEhIC0.js';
5
+ export { b as ColumnBuilder, c as ColumnDef, d as ColumnType, O as OnDeleteAction, e as boolean, f as defineSchema, g as enumType, i as integer, j as jsonb, t as table, h as text, k as timestamp, u as uuid } from './schema-BqfEhIC0.js';
4
6
  export { z } from 'zod';
5
7
 
6
- /** HTTP error with structured error response format. */
7
- declare class HttpError extends Error {
8
- readonly status: number;
9
- readonly error: string;
10
- readonly errorDescription: string;
11
- constructor(status: number, error: string, errorDescription: string);
12
- /**
13
- * Serialize to the standard Palbase error response format.
14
- * The `requestId` is injected by the runtime layer from the request context.
15
- * When called without arguments (e.g. JSON.stringify), request_id is omitted.
16
- */
17
- toJSON(requestId?: string): {
18
- error: string;
19
- error_description: string;
20
- status: number;
21
- request_id?: string;
8
+ /**
9
+ * typed-db.ts Task 2: TypedDB schema-derived insert/row shapes.
10
+ *
11
+ * Derives INSERT and full-row TypeScript types from a `defineSchema()` result
12
+ * and wraps the untyped runtime `DBClient` with a typed facade.
13
+ *
14
+ * No value-any. No `as unknown as X`. The two narrow `as` casts in
15
+ * `makeTypedTable` are safe because:
16
+ * - `data as Record<string, unknown>`: InsertShape<T> maps string keys to
17
+ * typed values; all value types are subsets of `unknown`, so the cast is
18
+ * structurally sound.
19
+ * - `result as RowShape<T>`: The runtime DBClient returns `Record<string,
20
+ * unknown>` which is the erased form of the typed row; we're narrowing back
21
+ * to the precise shape that the schema declared.
22
+ * Both casts are narrowing only (not widening) and correctness is guaranteed
23
+ * by the schema the caller provides.
24
+ */
25
+
26
+ /** Keys of C whose columns are required on INSERT (not nullable, no default). */
27
+ type RequiredKeys<C> = {
28
+ [K in keyof C]: ColIsOptionalOnInsert<C[K]> extends true ? never : K;
29
+ }[keyof C];
30
+ /** Keys of C whose columns are optional on INSERT (nullable or has a default). */
31
+ type OptionalKeys<C> = {
32
+ [K in keyof C]: ColIsOptionalOnInsert<C[K]> extends true ? K : never;
33
+ }[keyof C];
34
+ /**
35
+ * The TypeScript type for an INSERT payload for table `T`.
36
+ * - Required: columns that are NOT NULL and have no DB-level default.
37
+ * - Optional: columns that are nullable or carry a default.
38
+ *
39
+ * When all columns are optional, `RequiredKeys<C>` resolves to `never` and
40
+ * the first part becomes `{}`, which is a neutral element for `&`.
41
+ */
42
+ type InsertShape<T extends TableDef> = {
43
+ [K in RequiredKeys<T["columns"]>]: ColValue<T["columns"][K]>;
44
+ } & {
45
+ [K in OptionalKeys<T["columns"]>]?: ColValue<T["columns"][K]>;
46
+ };
47
+ /**
48
+ * The TypeScript type for a full row returned by the DB for table `T`.
49
+ * Every column is present; nullable columns resolve to `T | null`.
50
+ */
51
+ type RowShape<T extends TableDef> = {
52
+ [K in keyof T["columns"]]: ColValue<T["columns"][K]>;
53
+ };
54
+ /** A typed table accessor that mirrors the runtime DBClient surface. */
55
+ interface TypedTable<T extends TableDef> {
56
+ insert(data: InsertShape<T>): Promise<RowShape<T>>;
57
+ update(id: string, data: Partial<InsertShape<T>>): Promise<RowShape<T>>;
58
+ delete(id: string): Promise<void>;
59
+ findById(id: string): Promise<RowShape<T> | null>;
60
+ findMany(query?: Partial<RowShape<T>>): Promise<RowShape<T>[]>;
61
+ }
62
+ /** A typed DB facade covering all tables declared in schema `S`. */
63
+ interface TypedDB<S extends SchemaDef> {
64
+ tables: {
65
+ [K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
22
66
  };
67
+ transaction<T>(fn: (tx: TypedTx<S>) => Promise<T>): Promise<T>;
68
+ }
69
+ /** Transaction-scoped typed facade: same typed tables, no nested transaction. */
70
+ interface TypedTx<S extends SchemaDef> {
71
+ tables: {
72
+ [K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
73
+ };
74
+ }
75
+ /**
76
+ * Wraps a raw `DBClient` with the type-safe `TypedDB<S>` facade derived from
77
+ * the provided schema. No behavior change — all calls delegate to `raw` with
78
+ * the table name as a plain string.
79
+ *
80
+ * `buildTables` is the reusable factory that wraps any op-bearing client
81
+ * (`TxClient` — the surface shared by `DBClient` and the transaction-scoped
82
+ * client) into the typed tables map. It is used both for the top-level db
83
+ * (wrapping `raw`) and inside `transaction`, where it wraps the raw `TxClient`
84
+ * the runtime yields so the callback sees the same typed `.tables` API.
85
+ *
86
+ * `transaction` delegates straight to `raw.transaction`; the two narrow
87
+ * `as TypedTx<S>` / `as TypedDB<S>` casts are single structural narrowings
88
+ * from the dynamically-built tables object to the precise mapped type (TS
89
+ * cannot infer through `Object.keys` iteration) — see module-level doc comment.
90
+ */
91
+ declare function makeTypedDB<S extends SchemaDef>(schema: S, raw: DBClient): TypedDB<S>;
92
+
93
+ /**
94
+ * runtime.ts — request-scoped service singletons.
95
+ *
96
+ * The backend SDK no longer threads a `ctx` god-object through every handler.
97
+ * Instead, endpoint authors import PascalCase service singletons directly:
98
+ *
99
+ * import { Database, Documents, Cache } from "@palbase/backend";
100
+ *
101
+ * export default defineEndpoint({
102
+ * method: "POST",
103
+ * handler: async (req) => {
104
+ * const row = await Database.insert("todos", { title: req.input.title });
105
+ * return row;
106
+ * },
107
+ * });
108
+ *
109
+ * The singletons are thin Proxies. Every property access forwards to the live
110
+ * client for the CURRENT request scope, resolved through {@link __getRuntime}.
111
+ *
112
+ * # Request-scope resolution (persistent app-server)
113
+ *
114
+ * The runtime is a long-running Node process that serves many concurrent
115
+ * requests on one event loop (NOT a fresh subprocess per request). A single
116
+ * module-global slot would let one in-flight request's services bleed into
117
+ * another's. So the services are carried in an {@link AsyncLocalStorage} store
118
+ * ({@link __requestALS}) that the runtime sets per request with
119
+ * {@link __runWithRuntime}; every async continuation of that request reads its
120
+ * own store. `__getRuntime` reads the ALS store first; the module-global slot
121
+ * (set by {@link __setRuntime}) is only a fallback for callers that run OUTSIDE
122
+ * an ALS scope (dev-server, unit tests, the legacy single-shot path). Because
123
+ * each `br-<ref>` pod is single-tenant, there is no cross-tenant leakage; the
124
+ * ALS store is what prevents cross-REQUEST leakage within the shared process.
125
+ *
126
+ * The seam that makes `import { Database } from "@palbase/backend"` resolve to
127
+ * the runtime-injected client: `@palbase/backend` is marked esbuild-EXTERNAL
128
+ * when the tenant bundle is built, and the package is installed globally in the
129
+ * pod (NODE_PATH=/usr/local/lib/node_modules). So worker.js's
130
+ * `require('@palbase/backend')` and the bundle's `import` resolve to ONE shared
131
+ * module instance — the ALS store and `__setRuntime` slot on that instance are
132
+ * visible to the singletons the bundle imported.
133
+ */
134
+
135
+ /** The set of live clients the runtime injects per request scope.
136
+ *
137
+ * EXCLUDED on purpose: Realtime, Functions, CMS, Links, Analytics, Auth. They
138
+ * are not exposed as backend handler singletons (auth lives on the client SDK;
139
+ * the rest are out of scope for backend endpoints). */
140
+ interface RuntimeServices {
141
+ Database: DBClient;
142
+ Documents: PalbaseDocsClient;
143
+ Storage: PalbaseStorageClient;
144
+ Cache: CacheClient;
145
+ Queue: QueueClient;
146
+ Log: Logger;
147
+ Notifications: PalbaseNotificationsClient;
148
+ Flags: PalbaseFlagsClient;
23
149
  }
150
+ /**
151
+ * Per-request store. The persistent runtime runs each request inside
152
+ * {@link __runWithRuntime}, so every async continuation of that request reads
153
+ * its OWN `runtime` (and any other request-scoped fields the runtime adds).
154
+ *
155
+ * Exported with a `__` prefix so the runtime (worker.js) shares the SAME ALS
156
+ * instance across the one module instance — two ALS instances would silently
157
+ * not see each other's stores. NOT part of the public author-facing API.
158
+ */
159
+ declare const __requestALS: AsyncLocalStorage<{
160
+ runtime: RuntimeServices;
161
+ }>;
162
+ /** Install the live clients in the process-global fallback slot.
163
+ *
164
+ * Persistent-server requests should use {@link __runWithRuntime} instead; this
165
+ * remains for dev-server / tests / the legacy single-shot path that run without
166
+ * an ALS scope. NOT part of the public author-facing API. */
167
+ declare function __setRuntime(services: RuntimeServices): void;
168
+ /** Run `fn` with `services` bound as the request-scoped runtime.
169
+ *
170
+ * The persistent worker calls this once per request so concurrent requests
171
+ * never share a services slot. NOT part of the public author-facing API. */
172
+ declare function __runWithRuntime<T>(services: RuntimeServices, fn: () => T): T;
173
+ /** Read the live clients, throwing if accessed outside a request scope.
174
+ *
175
+ * Resolves the ALS store first (persistent server, per-request), then the
176
+ * process-global fallback (dev-server / tests). NOT part of the public
177
+ * author-facing API — used by the runtime and the singleton Proxies. */
178
+ declare function __getRuntime(): RuntimeServices;
179
+ /** The project's own Postgres (pgx, schema `env_<envId>`). Typed CRUD +
180
+ * `query`/`transaction`. For a typed `.tables.<name>` API, wrap with
181
+ * {@link typedDatabase}. */
182
+ declare const Database: DBClient;
183
+ /** Firestore-like document client (PalDocs). */
184
+ declare const Documents: PalbaseDocsClient;
185
+ /** Object storage client (buckets, signed URLs). */
186
+ declare const Storage: PalbaseStorageClient;
187
+ /** JSON-typed cache (get/set/incr/getOrSet). */
188
+ declare const Cache: CacheClient;
189
+ /** Background job queue. */
190
+ declare const Queue: QueueClient;
191
+ /** Structured logger. */
192
+ declare const Log: Logger;
193
+ /** Push / email / SMS / in-app notifications. */
194
+ declare const Notifications: PalbaseNotificationsClient;
195
+ /** Feature flags. */
196
+ declare const Flags: PalbaseFlagsClient;
197
+ /**
198
+ * Type the `Database` singleton against a `defineSchema()` result, returning a
199
+ * facade with a typed `.tables.<name>.insert(...)` API alongside the raw
200
+ * `query`/`transaction` ops.
201
+ *
202
+ * const Db = typedDatabase(schema);
203
+ * const todo = await Db.tables.todos.insert({ title: "x" });
204
+ *
205
+ * This is per-endpoint (not global module augmentation), so one endpoint's
206
+ * tables never leak into another's `Database` type.
207
+ */
208
+ declare function typedDatabase<TSchema extends SchemaDef>(schema: TSchema): TypedDB<TSchema> & DBClient;
24
209
 
210
+ /** Context injected into worker handlers — the non-request-scoped service
211
+ * surface (db/log/cache/queue + module clients), plus correlation ids. Workers
212
+ * are not part of the Phase 1 `ctx → PBRequest` redesign, so they keep their
213
+ * own `ctx`; the job payload arrives as the handler's second argument. */
214
+ interface WorkerContext extends PalbaseModuleClients {
215
+ user: User | null;
216
+ db: DBClient;
217
+ env: Record<string, string>;
218
+ log: Logger;
219
+ cache: CacheClient;
220
+ queue: QueueClient;
221
+ errors: ErrorThrowers<undefined>;
222
+ requestId: string;
223
+ projectId: string;
224
+ environmentId: string;
225
+ }
25
226
  /** Backoff strategy for worker retries. */
26
227
  type BackoffStrategy = "exponential" | "linear" | "fixed";
27
228
  /** Configuration for a background worker. */
@@ -35,7 +236,7 @@ interface WorkerConfig<TPayload = unknown> {
35
236
  /** Backoff strategy between retries. Defaults to "exponential". */
36
237
  backoff?: BackoffStrategy;
37
238
  /** Handler function that processes the job payload. */
38
- handler: (ctx: Omit<EndpointContext<TPayload>, "input" | "params" | "query" | "headers" | "file" | "method" | "endpointPath">, payload: TPayload) => Promise<void>;
239
+ handler: (ctx: WorkerContext, payload: TPayload) => Promise<void>;
39
240
  }
40
241
  /** Resolved worker configuration with defaults applied. */
41
242
  interface ResolvedWorkerConfig<TPayload = unknown> {
@@ -43,7 +244,7 @@ interface ResolvedWorkerConfig<TPayload = unknown> {
43
244
  retry: number;
44
245
  timeout: number;
45
246
  backoff: BackoffStrategy;
46
- handler: (ctx: Omit<EndpointContext<TPayload>, "input" | "params" | "query" | "headers" | "file" | "method" | "endpointPath">, payload: TPayload) => Promise<void>;
247
+ handler: (ctx: WorkerContext, payload: TPayload) => Promise<void>;
47
248
  }
48
249
  /**
49
250
  * Define a background worker that processes jobs from the queue.
@@ -370,4 +571,4 @@ declare const documents: {
370
571
  onDocumentDeleted(handler: HookHandler<DocumentDeletedEvent>): ResolvedHook<DocumentDeletedEvent>;
371
572
  };
372
573
 
373
- export { type BackoffStrategy, CacheClient, type CustomWebhookConfig, DBClient, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentUpdatedEvent, EndpointContext, type EnvSecretRef, type FileDeletedEvent, type FileUploadedEvent, type HookContext, type HookHandler, HttpError, type JobConfig, type JobContext, Logger, PalbaseModuleClients, type PasswordResetEvent, type ProviderEventMap, type ProviderWebhookConfig, QueueClient, type ResolvedCustomWebhook, type ResolvedHook, type ResolvedJobConfig, type ResolvedProviderWebhook, type ResolvedWebhookConfig, type ResolvedWorkerConfig, type SignInEvent, type SignOutEvent, type UserCreatedEvent, type WebhookContext, type WebhookEventHandler, type WebhookProvider, type WebhookRequest, type WorkerConfig, auth, defineJob, defineWebhook, defineWorker, documents, storage };
574
+ export { type BackoffStrategy, Cache, CacheClient, type CustomWebhookConfig, DBClient, Database, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentUpdatedEvent, Documents, type EnvSecretRef, ErrorThrowers, type FileDeletedEvent, type FileUploadedEvent, Flags, type HookContext, type HookHandler, type InsertShape, type JobConfig, type JobContext, Log, Logger, Notifications, PalbaseDocsClient, PalbaseFlagsClient, PalbaseNotificationsClient, PalbaseStorageClient, type PasswordResetEvent, type ProviderEventMap, type ProviderWebhookConfig, Queue, QueueClient, type ResolvedCustomWebhook, type ResolvedHook, type ResolvedJobConfig, type ResolvedProviderWebhook, type ResolvedWebhookConfig, type ResolvedWorkerConfig, type RowShape, type RuntimeServices, SchemaDef, type SignInEvent, type SignOutEvent, Storage, TableDef, type TypedDB, type TypedTable, type TypedTx, User, type UserCreatedEvent, type WebhookContext, type WebhookEventHandler, type WebhookProvider, type WebhookRequest, type WorkerConfig, type WorkerContext, __getRuntime, __requestALS, __runWithRuntime, __setRuntime, auth, defineJob, defineWebhook, defineWorker, documents, makeTypedDB, storage, typedDatabase };