@databricks/appkit-ui 0.96.0 → 0.97.1

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.
Files changed (58) hide show
  1. package/CLAUDE.md +16 -7
  2. package/dist/js/database/client.d.ts +2 -2
  3. package/dist/js/database/client.js +1 -1
  4. package/dist/js/database/client.js.map +1 -1
  5. package/dist/react/beta.d.ts +2 -2
  6. package/dist/react/beta.js +1 -2
  7. package/dist/react/hooks/use-database-list.d.ts +4 -4
  8. package/dist/react/hooks/use-database-list.d.ts.map +1 -1
  9. package/dist/react/hooks/use-database-list.js +1 -2
  10. package/dist/react/hooks/use-database-list.js.map +1 -1
  11. package/dist/react/hooks/use-database-read.d.ts +4 -41
  12. package/dist/react/hooks/use-database-read.d.ts.map +1 -1
  13. package/dist/react/hooks/use-database-read.js +7 -68
  14. package/dist/react/hooks/use-database-read.js.map +1 -1
  15. package/dist/react/hooks/use-database-record.d.ts +3 -3
  16. package/dist/react/hooks/use-database-record.d.ts.map +1 -1
  17. package/dist/react/hooks/use-database-record.js +2 -3
  18. package/dist/react/hooks/use-database-record.js.map +1 -1
  19. package/dist/react/hooks/use-database-write.d.ts +3 -3
  20. package/dist/react/hooks/use-database-write.js.map +1 -1
  21. package/dist/shared/src/database/api-types.d.ts +1 -4
  22. package/dist/shared/src/database/api-types.d.ts.map +1 -1
  23. package/dist/shared/src/database/index.d.ts +3 -0
  24. package/dist/shared/src/database/operations.d.ts +11 -0
  25. package/dist/shared/src/database/operations.d.ts.map +1 -0
  26. package/dist/shared/src/index.d.ts +1 -0
  27. package/dist/workspace-client/modular.d.ts.map +1 -1
  28. package/dist/workspace-client/modular.js +19 -2
  29. package/dist/workspace-client/modular.js.map +1 -1
  30. package/docs/api/appkit/Class.DatabaseValidationError.md +1 -1
  31. package/docs/api/appkit/Function.defineOperation.md +61 -0
  32. package/docs/api/appkit/Function.definePolicy.md +52 -0
  33. package/docs/api/appkit/Function.defineSchema.md +1 -1
  34. package/docs/api/appkit/Interface.Actor.md +21 -0
  35. package/docs/api/appkit/Interface.DatabaseOperationContract.md +30 -0
  36. package/docs/api/appkit/Interface.DatabaseRoutes.md +30 -0
  37. package/docs/api/appkit/Interface.OperationContext.md +75 -0
  38. package/docs/api/appkit/Interface.OperationDefinition.md +77 -0
  39. package/docs/api/appkit/Interface.PolicyContext.md +49 -0
  40. package/docs/api/appkit/Interface.PolicyDenial.md +21 -0
  41. package/docs/api/appkit/TypeAlias.DatabricksAppKitDatabaseOperations.md +8 -0
  42. package/docs/api/appkit/TypeAlias.IDatabaseConfig.md +0 -10
  43. package/docs/api/appkit/TypeAlias.OperationMethod.md +8 -0
  44. package/docs/api/appkit/TypeAlias.OperationWireInput.md +14 -0
  45. package/docs/api/appkit/TypeAlias.OperationWireOutput.md +14 -0
  46. package/docs/api/appkit/TypeAlias.Policy.md +15 -0
  47. package/docs/api/appkit/TypeAlias.PolicyDecision.md +8 -0
  48. package/docs/api/appkit.md +60 -51
  49. package/docs/plugins/database.md +17 -70
  50. package/llms.txt +16 -7
  51. package/package.json +1 -1
  52. package/sbom.cdx.json +1 -1
  53. package/docs/api/appkit/Interface.EntityMutationHooks.md +0 -173
  54. package/docs/api/appkit/Interface.HookApp.md +0 -12
  55. package/docs/api/appkit/Interface.HookContext.md +0 -21
  56. package/docs/api/appkit/Interface.ReadSerializerContext.md +0 -21
  57. package/docs/api/appkit/TypeAlias.EntityHooks.md +0 -25
  58. package/docs/api/appkit/TypeAlias.ReadSerializer.md +0 -19
package/CLAUDE.md CHANGED
@@ -72,7 +72,7 @@ npx @databricks/appkit docs <query>
72
72
  - [Class: AuthenticationError](./docs/api/appkit/Class.AuthenticationError.md): Error thrown when authentication fails.
73
73
  - [Class: ConfigurationError](./docs/api/appkit/Class.ConfigurationError.md): Error thrown when configuration is missing or invalid.
74
74
  - [Class: ConnectionError](./docs/api/appkit/Class.ConnectionError.md): Error thrown when a connection or network operation fails.
75
- - [Class: DatabaseValidationError](./docs/api/appkit/Class.DatabaseValidationError.md): Deliberate validation failure raised by a database mutation hook. Generated
75
+ - [Class: DatabaseValidationError](./docs/api/appkit/Class.DatabaseValidationError.md): Deliberate validation failure. An explicit transaction callback can throw it,
76
76
  - [Class: DatabricksAdapter](./docs/api/appkit/Class.DatabricksAdapter.md): Adapter that talks directly to Databricks Model Serving /invocations endpoint.
77
77
  - [Class: ExecutionError](./docs/api/appkit/Class.ExecutionError.md): Error thrown when an operation execution fails.
78
78
  - [Class: IdentityExpiredError](./docs/api/appkit/Class.IdentityExpiredError.md): The downstream service rejected the active caller's credentials.
@@ -106,6 +106,8 @@ npx @databricks/appkit docs <query>
106
106
  - [Function: defineEval()](./docs/api/appkit/Function.defineEval.md): Define an agent eval. Default-export the result from a
107
107
  - [Function: defineEvalConfig()](./docs/api/appkit/Function.defineEvalConfig.md): Define per-directory eval config. Default-export from evals.config.ts.
108
108
  - [Function: defineManifest()](./docs/api/appkit/Function.defineManifest.md): Validates a raw manifest (typically a manifest.json import) against the
109
+ - [Function: defineOperation()](./docs/api/appkit/Function.defineOperation.md): Call Signature
110
+ - [Function: definePolicy()](./docs/api/appkit/Function.definePolicy.md): Call Signature
109
111
  - [Function: defineSchema()](./docs/api/appkit/Function.defineSchema.md): Compile one declared schema. The returned type keeps the table names the
110
112
  - [Function: defineTool()](./docs/api/appkit/Function.defineTool.md): Defines a single tool entry for a plugin's internal registry.
111
113
  - [Function: discoverEvalConfigs()](./docs/api/appkit/Function.discoverEvalConfigs.md): Discover the per-agent evals.config.ts (from defineEvalConfig) at
@@ -178,6 +180,7 @@ npx @databricks/appkit docs <query>
178
180
  - [Function: userTurns()](./docs/api/appkit/Function.userTurns.md): Extract every user-message content, in order, from an MLflow
179
181
  - [Function: uuid()](./docs/api/appkit/Function.uuid.md): Returns
180
182
  - [Function: varchar()](./docs/api/appkit/Function.varchar.md): Parameters
183
+ - [Interface: Actor](./docs/api/appkit/Interface.Actor.md): The authenticated caller. The HTTP boundary resolves it before any policy runs.
181
184
  - [Interface: AgentAdapter](./docs/api/appkit/Interface.AgentAdapter.md): Properties
182
185
  - [Interface: AgentDefinition](./docs/api/appkit/Interface.AgentDefinition.md): Properties
183
186
  - [Interface: AgentInput](./docs/api/appkit/Interface.AgentInput.md): Properties
@@ -193,7 +196,9 @@ npx @databricks/appkit docs <query>
193
196
  - [Interface: CallerContext](./docs/api/appkit/Interface.CallerContext.md): Caller identity and workspace for one immutable execution scope.
194
197
  - [Interface: CustomJudgeSpec](./docs/api/appkit/Interface.CustomJudgeSpec.md): A custom LLM-judge definition: a prompt template and choice→score mapping.
195
198
  - [Interface: DatabaseCredential](./docs/api/appkit/Interface.DatabaseCredential.md): Database credentials with OAuth token for Postgres connection
199
+ - [Interface: DatabaseOperationContract](./docs/api/appkit/Interface.DatabaseOperationContract.md): The browser-safe contract of one generated operation. input and output
196
200
  - [Interface: DatabaseRegistry](./docs/api/appkit/Interface.DatabaseRegistry.md): CANONICAL augmentation target. Empty by default; the generated database.d.ts
201
+ - [Interface: DatabaseRoutes](./docs/api/appkit/Interface.DatabaseRoutes.md): The generated route entry. schema and each module stay lazy, so importing
197
202
  - [Interface: DatabaseValidationIssue](./docs/api/appkit/Interface.DatabaseValidationIssue.md): One rejected field; path names public columns, never their values.
198
203
  - [Interface: DatabricksAuth](./docs/api/appkit/Interface.DatabricksAuth.md): Resolved Databricks host + bearer token for the eval runner's REST calls.
199
204
  - [Interface: DatasetRow](./docs/api/appkit/Interface.DatasetRow.md): One row of a managed evaluation dataset. inputs are the kwargs passed to the
@@ -203,7 +208,6 @@ npx @databricks/appkit docs <query>
203
208
  - [Interface: DownloadResponse](./docs/api/appkit/Interface.DownloadResponse.md): Response object for file downloads containing a readable stream.
204
209
  - [Interface: DriveResult](./docs/api/appkit/Interface.DriveResult.md): What a driver returns for a single t.send.
205
210
  - [Interface: EndpointConfig](./docs/api/appkit/Interface.EndpointConfig.md): Properties
206
- - [Interface: EntityMutationHooks<TTable>](./docs/api/appkit/Interface.EntityMutationHooks.md): Mutation lifecycle for one entity. A before hook may return a replacement
207
211
  - [Interface: EvalDefinition](./docs/api/appkit/Interface.EvalDefinition.md): A single eval, default-exported from a *.eval.ts file.
208
212
  - [Interface: EvalDriver](./docs/api/appkit/Interface.EvalDriver.md): Abstraction over how the agent is driven. The HTTP driver posts to a running
209
213
  - [Interface: EvalResult](./docs/api/appkit/Interface.EvalResult.md): The outcome of running one eval.
@@ -215,8 +219,6 @@ npx @databricks/appkit docs <query>
215
219
  - [Interface: FunctionTool](./docs/api/appkit/Interface.FunctionTool.md): Properties
216
220
  - [Interface: GenerateDatabaseCredentialRequest](./docs/api/appkit/Interface.GenerateDatabaseCredentialRequest.md): Request parameters for generating database OAuth credentials
217
221
  - [Interface: GenerationParams](./docs/api/appkit/Interface.GenerationParams.md): Optional generation parameters forwarded to the OpenAI-compatible serving
218
- - [Interface: HookApp](./docs/api/appkit/Interface.HookApp.md): The only capability a hook receives: entities bound to its transaction.
219
- - [Interface: HookContext](./docs/api/appkit/Interface.HookContext.md): Which entity is being mutated, and the surface a hook may write through.
220
222
  - [Interface: HostedSupervisorTool](./docs/api/appkit/Interface.HostedSupervisorTool.md): Tagged record returned by every supervisorTools factory. The
221
223
  - [Interface: HttpDriverOptions](./docs/api/appkit/Interface.HttpDriverOptions.md): Properties
222
224
  - [Interface: IAiSearchConfig](./docs/api/appkit/Interface.IAiSearchConfig.md): Base configuration interface for AppKit plugins
@@ -234,12 +236,15 @@ npx @databricks/appkit docs <query>
234
236
  - [Interface: MatchResult](./docs/api/appkit/Interface.MatchResult.md): Result of a deterministic matcher run against a value.
235
237
  - [Interface: McpConnectAllResult](./docs/api/appkit/Interface.McpConnectAllResult.md): Per-endpoint outcome of AppKitMcpClient.connectAll. Callers (the
236
238
  - [Interface: Message](./docs/api/appkit/Interface.Message.md): Properties
239
+ - [Interface: OperationContext<In, R>](./docs/api/appkit/Interface.OperationContext.md): What allow and execute receive: the policy context and the loaded resource.
240
+ - [Interface: OperationDefinition<M, I, O, R, Name>](./docs/api/appkit/Interface.OperationDefinition.md): One immutable operation descriptor. Nothing in it runs until a request does.
237
241
  - [Interface: PluginManifest<TName>](./docs/api/appkit/Interface.PluginManifest.md): Plugin manifest that declares metadata and resource requirements.
238
242
  - [Interface: PluginToolkitProvider](./docs/api/appkit/Interface.PluginToolkitProvider.md): Minimum shape every entry in the Plugins map must expose. Core
243
+ - [Interface: PolicyContext<In>](./docs/api/appkit/Interface.PolicyContext.md): What every authorization callback receives, the resource lookup included.
244
+ - [Interface: PolicyDenial](./docs/api/appkit/Interface.PolicyDenial.md): An explicit refusal. reason stays on the server; HTTP and logs do not receive it.
239
245
  - [Interface: PostResult](./docs/api/appkit/Interface.PostResult.md): Structured result for a best-effort POST that must not throw.
240
246
  - [Interface: PromptContext](./docs/api/appkit/Interface.PromptContext.md): Context passed to baseSystemPrompt callbacks.
241
247
  - [Interface: ReadEvalDatasetOptions](./docs/api/appkit/Interface.ReadEvalDatasetOptions.md): Properties
242
- - [Interface: ReadSerializerContext](./docs/api/appkit/Interface.ReadSerializerContext.md): Which entity and generated operation produced the row being shaped.
243
248
  - [Interface: RegisteredAgent](./docs/api/appkit/Interface.RegisteredAgent.md): Properties
244
249
  - [Interface: ReportOutcome](./docs/api/appkit/Interface.ReportOutcome.md): Properties
245
250
  - [Interface: RequestedClaims](./docs/api/appkit/Interface.RequestedClaims.md): Optional claims for fine-grained Unity Catalog table permissions
@@ -287,7 +292,7 @@ npx @databricks/appkit docs <query>
287
292
  - [Type Alias: DatabaseApiWriteOperation](./docs/api/appkit/TypeAlias.DatabaseApiWriteOperation.md): Generated HTTP write operations.
288
293
  - [Type Alias: DatabaseApiWritesConfig<TSchema>](./docs/api/appkit/TypeAlias.DatabaseApiWritesConfig.md): All writes by default; false keeps reads only, and an object narrows writes.
289
294
  - [Type Alias: DatabaseExports](./docs/api/appkit/TypeAlias.DatabaseExports.md): Typed database API published by the plugin.
290
- - [Type Alias: EntityHooks<TTable>](./docs/api/appkit/TypeAlias.EntityHooks.md): Response shaping and mutation lifecycle declared for one table.
295
+ - [Type Alias: DatabricksAppKitDatabaseOperations](./docs/api/appkit/TypeAlias.DatabricksAppKitDatabaseOperations.md): The same global registry, available as a module type for package exports.
291
296
  - [Type Alias: EvalProgress](./docs/api/appkit/TypeAlias.EvalProgress.md)
292
297
  - [Type Alias: ExecutionContext](./docs/api/appkit/TypeAlias.ExecutionContext.md)
293
298
  - [Type Alias: ExecutionResult<T>](./docs/api/appkit/TypeAlias.ExecutionResult.md): Discriminated union for plugin execution results.
@@ -300,9 +305,13 @@ npx @databricks/appkit docs <query>
300
305
  - [Type Alias: IDatabaseConfig<TSchema>](./docs/api/appkit/TypeAlias.IDatabaseConfig.md): Configuration for one schema-bound DatabasePlugin instance.
301
306
  - [Type Alias: JobsExport()](./docs/api/appkit/TypeAlias.JobsExport.md): Public API shape of the jobs plugin.
302
307
  - [Type Alias: Matcher()](./docs/api/appkit/TypeAlias.Matcher.md): A deterministic matcher: inspects a string value and returns a result.
308
+ - [Type Alias: OperationMethod](./docs/api/appkit/TypeAlias.OperationMethod.md): HTTP methods an operation can answer; the browser client reads the same union.
309
+ - [Type Alias: OperationWireInput<Operation>](./docs/api/appkit/TypeAlias.OperationWireInput.md): The JSON a caller sends to an operation; a bigint travels as a string or safe integer.
310
+ - [Type Alias: OperationWireOutput<Operation>](./docs/api/appkit/TypeAlias.OperationWireOutput.md): The JSON a successful call answers with; without an output schema there is none.
303
311
  - [Type Alias: PluginData<T, U, N>](./docs/api/appkit/TypeAlias.PluginData.md): Tuple of plugin class, config, and name. Created by toPlugin() and passed to createApp().
304
312
  - [Type Alias: Plugins](./docs/api/appkit/TypeAlias.Plugins.md): Plugin map passed to the function form of AgentDefinition.tools.
305
- - [Type Alias: ReadSerializer()](./docs/api/appkit/TypeAlias.ReadSerializer.md): Shape one already private-safe row before it reaches the wire. A Promise
313
+ - [Type Alias: Policy<In, R>](./docs/api/appkit/TypeAlias.Policy.md): A reusable authorization rule, with or without a resource lookup.
314
+ - [Type Alias: PolicyDecision](./docs/api/appkit/TypeAlias.PolicyDecision.md): Only literal true admits. False and an explicit denial refuse.
306
315
  - [Type Alias: ResolvedToolEntry](./docs/api/appkit/TypeAlias.ResolvedToolEntry.md): Internal tool-index entry after a tool record has been resolved to a dispatchable form.
307
316
  - [Type Alias: ResourceFieldEntry](./docs/api/appkit/TypeAlias.ResourceFieldEntry.md)
308
317
  - [Type Alias: ResourcePermission](./docs/api/appkit/TypeAlias.ResourcePermission.md): Union of all possible permission levels across all resource types.
@@ -45,8 +45,8 @@ interface DatabaseApi {
45
45
  get<K extends DatabaseKeyedEntity, const P extends DatabaseRecordParams<K> = Record<never, never>>(entity: K, id: DatabaseId<K>, params?: P & ExactDatabaseParams<P, DatabaseRecordParams<K>>, init?: DatabaseRequestOptions): Promise<DatabaseRecordRow<K, P>>;
46
46
  /**
47
47
  * Create one row with `POST /api/database/<entity>` and return it as the
48
- * database holds it after any `beforeCreate` hook. Private, generated, and
49
- * undeclared fields are compile errors, as the server refuses them.
48
+ * database holds it. Private, generated, and undeclared fields are compile
49
+ * errors, as the server refuses them.
50
50
  *
51
51
  * @example
52
52
  * ```typescript
@@ -91,7 +91,7 @@ function isDatabaseListPage(body) {
91
91
  return isRecord(body) && Array.isArray(body.items) && typeof body.limit === "number" && typeof body.offset === "number";
92
92
  }
93
93
  /**
94
- * A detail route answers one bare row; a serializer returns an object too.
94
+ * A detail route answers one bare row.
95
95
  * @internal Shared with the React hooks; not part of the public surface.
96
96
  */
97
97
  function isDatabaseRow(body) {
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../../../src/js/database/client.ts"],"sourcesContent":["import {\n type DatabaseErrorDetail,\n type DatabaseListPage,\n type DatabaseListQuery,\n databaseErrorCategoryForStatus,\n encodeDatabaseListQuery,\n encodeDatabaseRecordQuery,\n type ExactDatabaseParams,\n} from \"shared\";\n\nimport { getClientConfig } from \"../config\";\nimport {\n DatabaseApiError,\n invalidDatabaseQuery,\n invalidDatabaseWrite,\n} from \"./errors\";\nimport type {\n DatabaseEntity,\n DatabaseId,\n DatabaseInsert,\n DatabaseKeyedEntity,\n DatabaseListParams,\n DatabaseListRow,\n DatabaseRecordParams,\n DatabaseRecordRow,\n DatabaseRow,\n DatabaseUpdate,\n} from \"./types\";\n\n/**\n * Suffix of the endpoint names `DatabasePlugin` publishes for each table.\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport type DatabaseOperation =\n | \"list\"\n | \"detail\"\n | \"create\"\n | \"update\"\n | \"delete\";\n\n/**\n * An id as a keyed route addresses it in its path.\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport type IdLike = string | number | bigint;\n\n/** Per-call options for a database request. */\nexport interface DatabaseRequestOptions {\n /**\n * Cancels the request; the promise then rejects with the abort reason.\n * Cancelling a write does not undo it once the server has committed.\n */\n readonly signal?: AbortSignal;\n}\n\n/** Typed calls to the routes `DatabasePlugin` generates under `/api/database`. */\nexport interface DatabaseApi {\n /**\n * Read one page from `GET /api/database/<entity>`. Rows are public rows as\n * JSON carries them, narrowed by `select` and widened by `include`.\n *\n * @example\n * ```typescript\n * const page = await databaseApi.list(\"notes\", {\n * where: { board_id: 7 },\n * order: { created_at: \"desc\" },\n * limit: 5,\n * });\n * page.items[0]?.body;\n * ```\n */\n list<K extends DatabaseKeyedEntity>(\n entity: K,\n params?: undefined,\n init?: DatabaseRequestOptions,\n ): Promise<DatabaseListPage<DatabaseListRow<K>>>;\n list<K extends DatabaseEntity, const P extends DatabaseListParams<K>>(\n entity: K,\n params: P & ExactDatabaseParams<P, DatabaseListParams<K>>,\n init?: DatabaseRequestOptions,\n ): Promise<DatabaseListPage<DatabaseListRow<K, P>>>;\n\n /**\n * Read one row from `GET /api/database/<entity>/:id`. Only entities with a\n * public primary key have this route; a missing row rejects with\n * `NOT_FOUND`.\n *\n * @example\n * ```typescript\n * const board = await databaseApi.get(\"boards\", 7, {\n * include: { notes: { limit: 20 } },\n * });\n * board.notes.length;\n * ```\n */\n get<\n K extends DatabaseKeyedEntity,\n const P extends DatabaseRecordParams<K> = Record<never, never>,\n >(\n entity: K,\n id: DatabaseId<K>,\n params?: P & ExactDatabaseParams<P, DatabaseRecordParams<K>>,\n init?: DatabaseRequestOptions,\n ): Promise<DatabaseRecordRow<K, P>>;\n\n /**\n * Create one row with `POST /api/database/<entity>` and return it as the\n * database holds it after any `beforeCreate` hook. Private, generated, and\n * undeclared fields are compile errors, as the server refuses them.\n *\n * @example\n * ```typescript\n * const note = await databaseApi.create(\"notes\", {\n * board_id: 7,\n * author: \"ada\",\n * body: \"Ship it\",\n * });\n * note.id;\n * ```\n */\n create<K extends DatabaseEntity, const V extends DatabaseInsert<K>>(\n entity: K,\n values: V & ExactDatabaseParams<V, DatabaseInsert<K>>,\n init?: DatabaseRequestOptions,\n ): Promise<DatabaseRow<K>>;\n\n /**\n * Change some fields of one row with `PATCH /api/database/<entity>/:id` and\n * return the updated row. A missing row rejects with `NOT_FOUND`.\n *\n * @example\n * ```typescript\n * await databaseApi.update(\"notes\", 7, { body: \"Shipped\" });\n * ```\n */\n update<K extends DatabaseKeyedEntity, const V extends DatabaseUpdate<K>>(\n entity: K,\n id: DatabaseId<K>,\n values: V & ExactDatabaseParams<V, DatabaseUpdate<K>>,\n init?: DatabaseRequestOptions,\n ): Promise<DatabaseRow<K>>;\n\n /**\n * Delete one row with `DELETE /api/database/<entity>/:id`. A missing row\n * rejects with `NOT_FOUND`.\n *\n * @example\n * ```typescript\n * await databaseApi.remove(\"notes\", 7);\n * ```\n */\n remove<K extends DatabaseKeyedEntity>(\n entity: K,\n id: DatabaseId<K>,\n init?: DatabaseRequestOptions,\n ): Promise<void>;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * An id that URL resolution would not keep as one path segment: `\"\"` and\n * `\".\"` collapse onto the list route and `\"..\"` climbs above the table, so a\n * keyed request would silently reach another route.\n */\nfunction isUnaddressableId(segment: string): boolean {\n return segment === \"\" || segment === \".\" || segment === \"..\";\n}\n\n/**\n * Find the route the server published for one operation. The plugin publishes\n * only what its `api` configuration exposes, so a missing entry is refused\n * here with `NOT_EXPOSED` and no request is sent. An id that is not one path\n * segment is refused with `INVALID_REQUEST`, also without a request.\n *\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport function resolveDatabaseUrl(\n entity: string,\n operation: DatabaseOperation,\n id?: IdLike,\n query?: string,\n): string {\n const name = `${entity}.${operation}`;\n const endpoints = getClientConfig().endpoints.database;\n const path =\n isRecord(endpoints) && Object.hasOwn(endpoints, name)\n ? endpoints[name]\n : undefined;\n if (typeof path !== \"string\") {\n throw new DatabaseApiError(\n \"NOT_EXPOSED\",\n null,\n `Database operation \"${name}\" is not exposed`,\n );\n }\n let url = path;\n if (id !== undefined) {\n const segment = String(id);\n if (isUnaddressableId(segment)) {\n // The id may be user input from a route param; do not echo it.\n throw new DatabaseApiError(\n \"INVALID_REQUEST\",\n null,\n \"Database id must be a non-empty path segment\",\n );\n }\n url = path.replace(\":id\", encodeURIComponent(segment));\n }\n return query ? `${url}?${query}` : url;\n}\n\n/** Keep only details shaped like the server's; they name public fields only. */\nfunction publicDetails(value: unknown): DatabaseErrorDetail[] {\n if (!Array.isArray(value)) return [];\n return value.flatMap((detail): DatabaseErrorDetail[] =>\n isRecord(detail) &&\n typeof detail.message === \"string\" &&\n Array.isArray(detail.path) &&\n detail.path.every((segment) => typeof segment === \"string\")\n ? [{ path: [...detail.path], message: detail.message }]\n : [],\n );\n}\n\n/** Decode a failure envelope; a non-JSON body still keeps its category. */\nasync function failure(response: Response): Promise<DatabaseApiError> {\n const body: unknown = await response.json().catch(() => undefined);\n const envelope = isRecord(body) ? body : {};\n return new DatabaseApiError(\n databaseErrorCategoryForStatus(response.status),\n response.status,\n typeof envelope.error === \"string\"\n ? envelope.error\n : `Database request failed with status ${response.status}`,\n publicDetails(envelope.details),\n );\n}\n\n/**\n * Send one request and decode its JSON body, throwing `DatabaseApiError` for\n * anything but the shape `accept` expects. A `204` has no body, so `accept`\n * sees `undefined`. An abort rejects with the signal's own reason, so a\n * caller can tell cancellation from failure.\n *\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport async function requestDatabase<T>(\n url: string,\n init: RequestInit,\n accept: (body: unknown) => body is T,\n): Promise<T> {\n const headers = new Headers(init.headers);\n headers.set(\"Accept\", \"application/json\");\n const write = init.method !== \"GET\";\n let response: Response;\n try {\n response = await fetch(url, { ...init, headers });\n } catch (error) {\n if (init.signal?.aborted) throw error;\n throw new DatabaseApiError(\n write ? \"OUTCOME_UNKNOWN\" : \"TRANSIENT\",\n null,\n write\n ? \"Database write may have completed; check its result before retrying\"\n : \"Database read failed before receiving a response\",\n [],\n { cause: error },\n );\n }\n if (!response.ok) throw await failure(response);\n\n let body: unknown;\n try {\n body = response.status === 204 ? undefined : await response.json();\n } catch (error) {\n if (init.signal?.aborted) throw error;\n throw new DatabaseApiError(\n write ? \"OUTCOME_UNKNOWN\" : \"INTERNAL\",\n response.status,\n write\n ? \"Database write may have completed; response is not JSON\"\n : \"Database response is not JSON\",\n [],\n { cause: error },\n );\n }\n if (!accept(body)) {\n throw new DatabaseApiError(\n write ? \"OUTCOME_UNKNOWN\" : \"INTERNAL\",\n response.status,\n write\n ? \"Database write may have completed; response has an unexpected shape\"\n : \"Database response has an unexpected shape\",\n );\n }\n return body;\n}\n\n/**\n * The `{ items, limit, offset }` envelope a list route answers with.\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport function isDatabaseListPage(\n body: unknown,\n): body is DatabaseListPage<unknown> {\n return (\n isRecord(body) &&\n Array.isArray(body.items) &&\n typeof body.limit === \"number\" &&\n typeof body.offset === \"number\"\n );\n}\n\n/**\n * A detail route answers one bare row; a serializer returns an object too.\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport function isDatabaseRow(body: unknown): body is Record<string, unknown> {\n return isRecord(body);\n}\n\n/** A delete answers `204` with nothing to decode. */\nfunction isNoContent(body: unknown): body is undefined {\n return body === undefined;\n}\n\n/** A write must not lose a non-finite number to JSON's implicit null coercion. */\nfunction jsonWriteValue(_key: string, value: unknown): unknown {\n if (typeof value === \"number\" && !Number.isFinite(value)) {\n throw invalidDatabaseWrite(\n \"Database write numbers must be finite; use null explicitly to clear a value\",\n );\n }\n return typeof value === \"bigint\" ? value.toString() : value;\n}\n\n/** A write sends its values as a JSON body, the only type its route parses. */\nfunction jsonWrite(\n method: \"POST\" | \"PATCH\",\n values: object,\n signal: AbortSignal | undefined,\n): RequestInit {\n try {\n return {\n method,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(values, jsonWriteValue),\n signal,\n };\n } catch (error) {\n if (error instanceof DatabaseApiError) throw error;\n throw invalidDatabaseWrite();\n }\n}\n\n/**\n * Untyped create behind `databaseApi.create` and `useDatabaseCreate`; their\n * signatures carry the checks, while the entity is still a literal.\n *\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport async function createDatabaseRow(\n entity: string,\n values: object,\n init: DatabaseRequestOptions = {},\n): Promise<Record<string, unknown>> {\n const url = resolveDatabaseUrl(entity, \"create\");\n return requestDatabase(\n url,\n jsonWrite(\"POST\", values, init.signal),\n isDatabaseRow,\n );\n}\n\n/**\n * Untyped update, shared by the typed client and the write hooks.\n * @internal Not part of the public surface.\n */\nexport async function updateDatabaseRow(\n entity: string,\n id: IdLike,\n values: object,\n init: DatabaseRequestOptions = {},\n): Promise<Record<string, unknown>> {\n const url = resolveDatabaseUrl(entity, \"update\", id);\n return requestDatabase(\n url,\n jsonWrite(\"PATCH\", values, init.signal),\n isDatabaseRow,\n );\n}\n\n/**\n * Untyped delete, shared by the typed client and the write hooks.\n * @internal Not part of the public surface.\n */\nexport async function deleteDatabaseRow(\n entity: string,\n id: IdLike,\n init: DatabaseRequestOptions = {},\n): Promise<void> {\n const url = resolveDatabaseUrl(entity, \"delete\", id);\n await requestDatabase(\n url,\n { method: \"DELETE\", signal: init.signal },\n isNoContent,\n );\n}\n\nfunction list<K extends DatabaseKeyedEntity>(\n entity: K,\n params?: undefined,\n init?: DatabaseRequestOptions,\n): Promise<DatabaseListPage<DatabaseListRow<K>>>;\nfunction list<K extends DatabaseEntity, const P extends DatabaseListParams<K>>(\n entity: K,\n params: P & ExactDatabaseParams<P, DatabaseListParams<K>>,\n init?: DatabaseRequestOptions,\n): Promise<DatabaseListPage<DatabaseListRow<K, P>>>;\nasync function list(\n entity: string,\n params?: DatabaseListQuery,\n init: DatabaseRequestOptions = {},\n): Promise<DatabaseListPage<unknown>> {\n let query: string;\n try {\n query = encodeDatabaseListQuery(params ?? {});\n } catch (error) {\n throw invalidDatabaseQuery(error);\n }\n const url = resolveDatabaseUrl(entity, \"list\", undefined, query);\n const page = await requestDatabase(\n url,\n { method: \"GET\", signal: init.signal },\n isDatabaseListPage,\n );\n return page;\n}\n\nasync function get<\n K extends DatabaseKeyedEntity,\n const P extends DatabaseRecordParams<K> = Record<never, never>,\n>(\n entity: K,\n id: DatabaseId<K>,\n params?: P & ExactDatabaseParams<P, DatabaseRecordParams<K>>,\n init: DatabaseRequestOptions = {},\n): Promise<DatabaseRecordRow<K, P>> {\n let query: string;\n try {\n query = encodeDatabaseRecordQuery(params ?? {});\n } catch (error) {\n throw invalidDatabaseQuery(error);\n }\n const url = resolveDatabaseUrl(entity, \"detail\", id, query);\n const row = await requestDatabase(\n url,\n { method: \"GET\", signal: init.signal },\n isDatabaseRow,\n );\n return row as DatabaseRecordRow<K, P>;\n}\n\nasync function create<\n K extends DatabaseEntity,\n const V extends DatabaseInsert<K>,\n>(\n entity: K,\n values: V & ExactDatabaseParams<V, DatabaseInsert<K>>,\n init: DatabaseRequestOptions = {},\n): Promise<DatabaseRow<K>> {\n // `values` is an insert object; a still-generic `K` only widens its type.\n const row = await createDatabaseRow(entity, values as object, init);\n // The server projected the row it holds; the types describe that wire.\n return row as DatabaseRow<K>;\n}\n\nasync function update<\n K extends DatabaseKeyedEntity,\n const V extends DatabaseUpdate<K>,\n>(\n entity: K,\n id: DatabaseId<K>,\n values: V & ExactDatabaseParams<V, DatabaseUpdate<K>>,\n init: DatabaseRequestOptions = {},\n): Promise<DatabaseRow<K>> {\n const row = await updateDatabaseRow(entity, id, values as object, init);\n return row as DatabaseRow<K>;\n}\n\nfunction remove<K extends DatabaseKeyedEntity>(\n entity: K,\n id: DatabaseId<K>,\n init: DatabaseRequestOptions = {},\n): Promise<void> {\n return deleteDatabaseRow(entity, id, init);\n}\n\n/**\n * Typed browser client for the routes `DatabasePlugin` generates. Entity names,\n * params, and rows come from the generated `database.d.ts`; routes come from\n * the endpoints the server published in the boot payload.\n */\nexport const databaseApi: DatabaseApi = { list, get, create, update, remove };\n"],"mappings":"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"}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../../src/js/database/client.ts"],"sourcesContent":["import {\n type DatabaseErrorDetail,\n type DatabaseListPage,\n type DatabaseListQuery,\n databaseErrorCategoryForStatus,\n encodeDatabaseListQuery,\n encodeDatabaseRecordQuery,\n type ExactDatabaseParams,\n} from \"shared\";\n\nimport { getClientConfig } from \"../config\";\nimport {\n DatabaseApiError,\n invalidDatabaseQuery,\n invalidDatabaseWrite,\n} from \"./errors\";\nimport type {\n DatabaseEntity,\n DatabaseId,\n DatabaseInsert,\n DatabaseKeyedEntity,\n DatabaseListParams,\n DatabaseListRow,\n DatabaseRecordParams,\n DatabaseRecordRow,\n DatabaseRow,\n DatabaseUpdate,\n} from \"./types\";\n\n/**\n * Suffix of the endpoint names `DatabasePlugin` publishes for each table.\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport type DatabaseOperation =\n | \"list\"\n | \"detail\"\n | \"create\"\n | \"update\"\n | \"delete\";\n\n/**\n * An id as a keyed route addresses it in its path.\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport type IdLike = string | number | bigint;\n\n/** Per-call options for a database request. */\nexport interface DatabaseRequestOptions {\n /**\n * Cancels the request; the promise then rejects with the abort reason.\n * Cancelling a write does not undo it once the server has committed.\n */\n readonly signal?: AbortSignal;\n}\n\n/** Typed calls to the routes `DatabasePlugin` generates under `/api/database`. */\nexport interface DatabaseApi {\n /**\n * Read one page from `GET /api/database/<entity>`. Rows are public rows as\n * JSON carries them, narrowed by `select` and widened by `include`.\n *\n * @example\n * ```typescript\n * const page = await databaseApi.list(\"notes\", {\n * where: { board_id: 7 },\n * order: { created_at: \"desc\" },\n * limit: 5,\n * });\n * page.items[0]?.body;\n * ```\n */\n list<K extends DatabaseKeyedEntity>(\n entity: K,\n params?: undefined,\n init?: DatabaseRequestOptions,\n ): Promise<DatabaseListPage<DatabaseListRow<K>>>;\n list<K extends DatabaseEntity, const P extends DatabaseListParams<K>>(\n entity: K,\n params: P & ExactDatabaseParams<P, DatabaseListParams<K>>,\n init?: DatabaseRequestOptions,\n ): Promise<DatabaseListPage<DatabaseListRow<K, P>>>;\n\n /**\n * Read one row from `GET /api/database/<entity>/:id`. Only entities with a\n * public primary key have this route; a missing row rejects with\n * `NOT_FOUND`.\n *\n * @example\n * ```typescript\n * const board = await databaseApi.get(\"boards\", 7, {\n * include: { notes: { limit: 20 } },\n * });\n * board.notes.length;\n * ```\n */\n get<\n K extends DatabaseKeyedEntity,\n const P extends DatabaseRecordParams<K> = Record<never, never>,\n >(\n entity: K,\n id: DatabaseId<K>,\n params?: P & ExactDatabaseParams<P, DatabaseRecordParams<K>>,\n init?: DatabaseRequestOptions,\n ): Promise<DatabaseRecordRow<K, P>>;\n\n /**\n * Create one row with `POST /api/database/<entity>` and return it as the\n * database holds it. Private, generated, and undeclared fields are compile\n * errors, as the server refuses them.\n *\n * @example\n * ```typescript\n * const note = await databaseApi.create(\"notes\", {\n * board_id: 7,\n * author: \"ada\",\n * body: \"Ship it\",\n * });\n * note.id;\n * ```\n */\n create<K extends DatabaseEntity, const V extends DatabaseInsert<K>>(\n entity: K,\n values: V & ExactDatabaseParams<V, DatabaseInsert<K>>,\n init?: DatabaseRequestOptions,\n ): Promise<DatabaseRow<K>>;\n\n /**\n * Change some fields of one row with `PATCH /api/database/<entity>/:id` and\n * return the updated row. A missing row rejects with `NOT_FOUND`.\n *\n * @example\n * ```typescript\n * await databaseApi.update(\"notes\", 7, { body: \"Shipped\" });\n * ```\n */\n update<K extends DatabaseKeyedEntity, const V extends DatabaseUpdate<K>>(\n entity: K,\n id: DatabaseId<K>,\n values: V & ExactDatabaseParams<V, DatabaseUpdate<K>>,\n init?: DatabaseRequestOptions,\n ): Promise<DatabaseRow<K>>;\n\n /**\n * Delete one row with `DELETE /api/database/<entity>/:id`. A missing row\n * rejects with `NOT_FOUND`.\n *\n * @example\n * ```typescript\n * await databaseApi.remove(\"notes\", 7);\n * ```\n */\n remove<K extends DatabaseKeyedEntity>(\n entity: K,\n id: DatabaseId<K>,\n init?: DatabaseRequestOptions,\n ): Promise<void>;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * An id that URL resolution would not keep as one path segment: `\"\"` and\n * `\".\"` collapse onto the list route and `\"..\"` climbs above the table, so a\n * keyed request would silently reach another route.\n */\nfunction isUnaddressableId(segment: string): boolean {\n return segment === \"\" || segment === \".\" || segment === \"..\";\n}\n\n/**\n * Find the route the server published for one operation. The plugin publishes\n * only what its `api` configuration exposes, so a missing entry is refused\n * here with `NOT_EXPOSED` and no request is sent. An id that is not one path\n * segment is refused with `INVALID_REQUEST`, also without a request.\n *\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport function resolveDatabaseUrl(\n entity: string,\n operation: DatabaseOperation,\n id?: IdLike,\n query?: string,\n): string {\n const name = `${entity}.${operation}`;\n const endpoints = getClientConfig().endpoints.database;\n const path =\n isRecord(endpoints) && Object.hasOwn(endpoints, name)\n ? endpoints[name]\n : undefined;\n if (typeof path !== \"string\") {\n throw new DatabaseApiError(\n \"NOT_EXPOSED\",\n null,\n `Database operation \"${name}\" is not exposed`,\n );\n }\n let url = path;\n if (id !== undefined) {\n const segment = String(id);\n if (isUnaddressableId(segment)) {\n // The id may be user input from a route param; do not echo it.\n throw new DatabaseApiError(\n \"INVALID_REQUEST\",\n null,\n \"Database id must be a non-empty path segment\",\n );\n }\n url = path.replace(\":id\", encodeURIComponent(segment));\n }\n return query ? `${url}?${query}` : url;\n}\n\n/** Keep only details shaped like the server's; they name public fields only. */\nfunction publicDetails(value: unknown): DatabaseErrorDetail[] {\n if (!Array.isArray(value)) return [];\n return value.flatMap((detail): DatabaseErrorDetail[] =>\n isRecord(detail) &&\n typeof detail.message === \"string\" &&\n Array.isArray(detail.path) &&\n detail.path.every((segment) => typeof segment === \"string\")\n ? [{ path: [...detail.path], message: detail.message }]\n : [],\n );\n}\n\n/** Decode a failure envelope; a non-JSON body still keeps its category. */\nasync function failure(response: Response): Promise<DatabaseApiError> {\n const body: unknown = await response.json().catch(() => undefined);\n const envelope = isRecord(body) ? body : {};\n return new DatabaseApiError(\n databaseErrorCategoryForStatus(response.status),\n response.status,\n typeof envelope.error === \"string\"\n ? envelope.error\n : `Database request failed with status ${response.status}`,\n publicDetails(envelope.details),\n );\n}\n\n/**\n * Send one request and decode its JSON body, throwing `DatabaseApiError` for\n * anything but the shape `accept` expects. A `204` has no body, so `accept`\n * sees `undefined`. An abort rejects with the signal's own reason, so a\n * caller can tell cancellation from failure.\n *\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport async function requestDatabase<T>(\n url: string,\n init: RequestInit,\n accept: (body: unknown) => body is T,\n): Promise<T> {\n const headers = new Headers(init.headers);\n headers.set(\"Accept\", \"application/json\");\n const write = init.method !== \"GET\";\n let response: Response;\n try {\n response = await fetch(url, { ...init, headers });\n } catch (error) {\n if (init.signal?.aborted) throw error;\n throw new DatabaseApiError(\n write ? \"OUTCOME_UNKNOWN\" : \"TRANSIENT\",\n null,\n write\n ? \"Database write may have completed; check its result before retrying\"\n : \"Database read failed before receiving a response\",\n [],\n { cause: error },\n );\n }\n if (!response.ok) throw await failure(response);\n\n let body: unknown;\n try {\n body = response.status === 204 ? undefined : await response.json();\n } catch (error) {\n if (init.signal?.aborted) throw error;\n throw new DatabaseApiError(\n write ? \"OUTCOME_UNKNOWN\" : \"INTERNAL\",\n response.status,\n write\n ? \"Database write may have completed; response is not JSON\"\n : \"Database response is not JSON\",\n [],\n { cause: error },\n );\n }\n if (!accept(body)) {\n throw new DatabaseApiError(\n write ? \"OUTCOME_UNKNOWN\" : \"INTERNAL\",\n response.status,\n write\n ? \"Database write may have completed; response has an unexpected shape\"\n : \"Database response has an unexpected shape\",\n );\n }\n return body;\n}\n\n/**\n * The `{ items, limit, offset }` envelope a list route answers with.\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport function isDatabaseListPage(\n body: unknown,\n): body is DatabaseListPage<unknown> {\n return (\n isRecord(body) &&\n Array.isArray(body.items) &&\n typeof body.limit === \"number\" &&\n typeof body.offset === \"number\"\n );\n}\n\n/**\n * A detail route answers one bare row.\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport function isDatabaseRow(body: unknown): body is Record<string, unknown> {\n return isRecord(body);\n}\n\n/** A delete answers `204` with nothing to decode. */\nfunction isNoContent(body: unknown): body is undefined {\n return body === undefined;\n}\n\n/** A write must not lose a non-finite number to JSON's implicit null coercion. */\nfunction jsonWriteValue(_key: string, value: unknown): unknown {\n if (typeof value === \"number\" && !Number.isFinite(value)) {\n throw invalidDatabaseWrite(\n \"Database write numbers must be finite; use null explicitly to clear a value\",\n );\n }\n return typeof value === \"bigint\" ? value.toString() : value;\n}\n\n/** A write sends its values as a JSON body, the only type its route parses. */\nfunction jsonWrite(\n method: \"POST\" | \"PATCH\",\n values: object,\n signal: AbortSignal | undefined,\n): RequestInit {\n try {\n return {\n method,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(values, jsonWriteValue),\n signal,\n };\n } catch (error) {\n if (error instanceof DatabaseApiError) throw error;\n throw invalidDatabaseWrite();\n }\n}\n\n/**\n * Untyped create behind `databaseApi.create` and `useDatabaseCreate`; their\n * signatures carry the checks, while the entity is still a literal.\n *\n * @internal Shared with the React hooks; not part of the public surface.\n */\nexport async function createDatabaseRow(\n entity: string,\n values: object,\n init: DatabaseRequestOptions = {},\n): Promise<Record<string, unknown>> {\n const url = resolveDatabaseUrl(entity, \"create\");\n return requestDatabase(\n url,\n jsonWrite(\"POST\", values, init.signal),\n isDatabaseRow,\n );\n}\n\n/**\n * Untyped update, shared by the typed client and the write hooks.\n * @internal Not part of the public surface.\n */\nexport async function updateDatabaseRow(\n entity: string,\n id: IdLike,\n values: object,\n init: DatabaseRequestOptions = {},\n): Promise<Record<string, unknown>> {\n const url = resolveDatabaseUrl(entity, \"update\", id);\n return requestDatabase(\n url,\n jsonWrite(\"PATCH\", values, init.signal),\n isDatabaseRow,\n );\n}\n\n/**\n * Untyped delete, shared by the typed client and the write hooks.\n * @internal Not part of the public surface.\n */\nexport async function deleteDatabaseRow(\n entity: string,\n id: IdLike,\n init: DatabaseRequestOptions = {},\n): Promise<void> {\n const url = resolveDatabaseUrl(entity, \"delete\", id);\n await requestDatabase(\n url,\n { method: \"DELETE\", signal: init.signal },\n isNoContent,\n );\n}\n\nfunction list<K extends DatabaseKeyedEntity>(\n entity: K,\n params?: undefined,\n init?: DatabaseRequestOptions,\n): Promise<DatabaseListPage<DatabaseListRow<K>>>;\nfunction list<K extends DatabaseEntity, const P extends DatabaseListParams<K>>(\n entity: K,\n params: P & ExactDatabaseParams<P, DatabaseListParams<K>>,\n init?: DatabaseRequestOptions,\n): Promise<DatabaseListPage<DatabaseListRow<K, P>>>;\nasync function list(\n entity: string,\n params?: DatabaseListQuery,\n init: DatabaseRequestOptions = {},\n): Promise<DatabaseListPage<unknown>> {\n let query: string;\n try {\n query = encodeDatabaseListQuery(params ?? {});\n } catch (error) {\n throw invalidDatabaseQuery(error);\n }\n const url = resolveDatabaseUrl(entity, \"list\", undefined, query);\n const page = await requestDatabase(\n url,\n { method: \"GET\", signal: init.signal },\n isDatabaseListPage,\n );\n return page;\n}\n\nasync function get<\n K extends DatabaseKeyedEntity,\n const P extends DatabaseRecordParams<K> = Record<never, never>,\n>(\n entity: K,\n id: DatabaseId<K>,\n params?: P & ExactDatabaseParams<P, DatabaseRecordParams<K>>,\n init: DatabaseRequestOptions = {},\n): Promise<DatabaseRecordRow<K, P>> {\n let query: string;\n try {\n query = encodeDatabaseRecordQuery(params ?? {});\n } catch (error) {\n throw invalidDatabaseQuery(error);\n }\n const url = resolveDatabaseUrl(entity, \"detail\", id, query);\n const row = await requestDatabase(\n url,\n { method: \"GET\", signal: init.signal },\n isDatabaseRow,\n );\n return row as DatabaseRecordRow<K, P>;\n}\n\nasync function create<\n K extends DatabaseEntity,\n const V extends DatabaseInsert<K>,\n>(\n entity: K,\n values: V & ExactDatabaseParams<V, DatabaseInsert<K>>,\n init: DatabaseRequestOptions = {},\n): Promise<DatabaseRow<K>> {\n // `values` is an insert object; a still-generic `K` only widens its type.\n const row = await createDatabaseRow(entity, values as object, init);\n // The server projected the row it holds; the types describe that wire.\n return row as DatabaseRow<K>;\n}\n\nasync function update<\n K extends DatabaseKeyedEntity,\n const V extends DatabaseUpdate<K>,\n>(\n entity: K,\n id: DatabaseId<K>,\n values: V & ExactDatabaseParams<V, DatabaseUpdate<K>>,\n init: DatabaseRequestOptions = {},\n): Promise<DatabaseRow<K>> {\n const row = await updateDatabaseRow(entity, id, values as object, init);\n return row as DatabaseRow<K>;\n}\n\nfunction remove<K extends DatabaseKeyedEntity>(\n entity: K,\n id: DatabaseId<K>,\n init: DatabaseRequestOptions = {},\n): Promise<void> {\n return deleteDatabaseRow(entity, id, init);\n}\n\n/**\n * Typed browser client for the routes `DatabasePlugin` generates. Entity names,\n * params, and rows come from the generated `database.d.ts`; routes come from\n * the endpoints the server published in the boot payload.\n */\nexport const databaseApi: DatabaseApi = { list, get, create, update, remove };\n"],"mappings":"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"}
@@ -9,10 +9,10 @@ import { DatabaseInvalidation, invalidateDatabaseReads } from "./hooks/database-
9
9
  import { UseDatabaseWriteOptions, UseDatabaseWriteState } from "./hooks/use-database-write.js";
10
10
  import { UseDatabaseCreateOptions, UseDatabaseCreateResult, useDatabaseCreate } from "./hooks/use-database-create.js";
11
11
  import { UseDatabaseDeleteOptions, UseDatabaseDeleteResult, useDatabaseDelete } from "./hooks/use-database-delete.js";
12
- import { DatabaseRowShape, DatabaseShape, UseDatabaseReadOptions, UseDatabaseReadResult, serialized } from "./hooks/use-database-read.js";
12
+ import { UseDatabaseReadOptions, UseDatabaseReadResult } from "./hooks/use-database-read.js";
13
13
  import { UseDatabaseListOptions, UseDatabaseListResult, useDatabaseList } from "./hooks/use-database-list.js";
14
14
  import { UseDatabaseRecordOptions, UseDatabaseRecordResult, useDatabaseRecord } from "./hooks/use-database-record.js";
15
15
  import { UseDatabaseUpdateOptions, UseDatabaseUpdateResult, useDatabaseUpdate } from "./hooks/use-database-update.js";
16
16
  import { useDesignReady } from "./hooks/use-design-ready.js";
17
17
  import { DesignPage, DesignPageProps, DraftPlaceholder, DraftPlaceholderKind } from "./design-page.js";
18
- export { type AiSearchClientConfig, type AiSearchIndexSummary, type AiSearchQueryType, type AiSearchRequest, type AiSearchResponse, type AiSearchResult, DatabaseApiError, type DatabaseApiErrorCode, type DatabaseEntity, type DatabaseErrorDetail, type DatabaseId, type DatabaseInsert, type DatabaseInvalidation, type DatabaseKeyedEntity, type DatabaseListPage, type DatabaseListParams, type DatabaseListRow, type DatabaseRecordParams, type DatabaseRecordRow, type DatabaseRow, type DatabaseRowShape, type DatabaseShape, type DatabaseUpdate, DesignPage, type DesignPageProps, DraftPlaceholder, type DraftPlaceholderKind, type UseAiSearchQueryOptions, type UseAiSearchQueryResult, type UseDatabaseCreateOptions, type UseDatabaseCreateResult, type UseDatabaseDeleteOptions, type UseDatabaseDeleteResult, type UseDatabaseListOptions, type UseDatabaseListResult, type UseDatabaseReadOptions, type UseDatabaseReadResult, type UseDatabaseRecordOptions, type UseDatabaseRecordResult, type UseDatabaseUpdateOptions, type UseDatabaseUpdateResult, type UseDatabaseWriteOptions, type UseDatabaseWriteState, invalidateDatabaseReads, serialized, useAiSearchQuery, useDatabaseCreate, useDatabaseDelete, useDatabaseList, useDatabaseRecord, useDatabaseUpdate, useDesignReady };
18
+ export { type AiSearchClientConfig, type AiSearchIndexSummary, type AiSearchQueryType, type AiSearchRequest, type AiSearchResponse, type AiSearchResult, DatabaseApiError, type DatabaseApiErrorCode, type DatabaseEntity, type DatabaseErrorDetail, type DatabaseId, type DatabaseInsert, type DatabaseInvalidation, type DatabaseKeyedEntity, type DatabaseListPage, type DatabaseListParams, type DatabaseListRow, type DatabaseRecordParams, type DatabaseRecordRow, type DatabaseRow, type DatabaseUpdate, DesignPage, type DesignPageProps, DraftPlaceholder, type DraftPlaceholderKind, type UseAiSearchQueryOptions, type UseAiSearchQueryResult, type UseDatabaseCreateOptions, type UseDatabaseCreateResult, type UseDatabaseDeleteOptions, type UseDatabaseDeleteResult, type UseDatabaseListOptions, type UseDatabaseListResult, type UseDatabaseReadOptions, type UseDatabaseReadResult, type UseDatabaseRecordOptions, type UseDatabaseRecordResult, type UseDatabaseUpdateOptions, type UseDatabaseUpdateResult, type UseDatabaseWriteOptions, type UseDatabaseWriteState, invalidateDatabaseReads, useAiSearchQuery, useDatabaseCreate, useDatabaseDelete, useDatabaseList, useDatabaseRecord, useDatabaseUpdate, useDesignReady };
@@ -3,11 +3,10 @@ import { useAiSearchQuery } from "./hooks/use-ai-search-query.js";
3
3
  import { invalidateDatabaseReads } from "./hooks/database-request-store.js";
4
4
  import { useDatabaseCreate } from "./hooks/use-database-create.js";
5
5
  import { useDatabaseDelete } from "./hooks/use-database-delete.js";
6
- import { serialized } from "./hooks/use-database-read.js";
7
6
  import { useDatabaseList } from "./hooks/use-database-list.js";
8
7
  import { useDatabaseRecord } from "./hooks/use-database-record.js";
9
8
  import { useDatabaseUpdate } from "./hooks/use-database-update.js";
10
9
  import { useDesignReady } from "./hooks/use-design-ready.js";
11
10
  import { DesignPage, DraftPlaceholder } from "./design-page.js";
12
11
 
13
- export { DatabaseApiError, DesignPage, DraftPlaceholder, invalidateDatabaseReads, serialized, useAiSearchQuery, useDatabaseCreate, useDatabaseDelete, useDatabaseList, useDatabaseRecord, useDatabaseUpdate, useDesignReady };
12
+ export { DatabaseApiError, DesignPage, DraftPlaceholder, invalidateDatabaseReads, useAiSearchQuery, useDatabaseCreate, useDatabaseDelete, useDatabaseList, useDatabaseRecord, useDatabaseUpdate, useDesignReady };
@@ -5,7 +5,7 @@ import { UseDatabaseReadOptions, UseDatabaseReadResult } from "./use-database-re
5
5
 
6
6
  //#region src/react/hooks/use-database-list.d.ts
7
7
  /** Options for {@link useDatabaseList}. */
8
- type UseDatabaseListOptions<Row> = UseDatabaseReadOptions<Row>;
8
+ type UseDatabaseListOptions = UseDatabaseReadOptions;
9
9
  /** What {@link useDatabaseList} returns: one page of rows and its state. */
10
10
  type UseDatabaseListResult<Row> = UseDatabaseReadResult<DatabaseListPage<Row>>;
11
11
  /**
@@ -20,7 +20,7 @@ type UseDatabaseListResult<Row> = UseDatabaseReadResult<DatabaseListPage<Row>>;
20
20
  * @param entity - A table the generated registry exposes
21
21
  * @param params - `where`, `order`, `select`, `include`, `limit`, `offset`;
22
22
  * `null` holds the hook idle, for params that depend on another read
23
- * @param options - `enabled`, `keepPreviousData`, and `shape`
23
+ * @param options - `enabled` and `keepPreviousData`
24
24
  * @returns The page, loading and error state, and `refetch`
25
25
  *
26
26
  * @example
@@ -33,8 +33,8 @@ type UseDatabaseListResult<Row> = UseDatabaseReadResult<DatabaseListPage<Row>>;
33
33
  * notes.data?.items.map((note) => note.body);
34
34
  * ```
35
35
  */
36
- declare function useDatabaseList<K extends DatabaseKeyedEntity, Row = DatabaseListRow<K>>(entity: K, params?: undefined, options?: UseDatabaseListOptions<Row>): UseDatabaseListResult<Row>;
37
- declare function useDatabaseList<K extends DatabaseEntity, const P extends DatabaseListParams<K>, Row = DatabaseListRow<K, P>>(entity: K, params: (P & ExactDatabaseParams<P, DatabaseListParams<K>>) | null, options?: UseDatabaseListOptions<Row>): UseDatabaseListResult<Row>;
36
+ declare function useDatabaseList<K extends DatabaseKeyedEntity>(entity: K, params?: undefined, options?: UseDatabaseListOptions): UseDatabaseListResult<DatabaseListRow<K>>;
37
+ declare function useDatabaseList<K extends DatabaseEntity, const P extends DatabaseListParams<K>>(entity: K, params: (P & ExactDatabaseParams<P, DatabaseListParams<K>>) | null, options?: UseDatabaseListOptions): UseDatabaseListResult<DatabaseListRow<K, P>>;
38
38
  //#endregion
39
39
  export { UseDatabaseListOptions, UseDatabaseListResult, useDatabaseList };
40
40
  //# sourceMappingURL=use-database-list.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-database-list.d.ts","names":[],"sources":["../../../src/react/hooks/use-database-list.ts"],"mappings":";;;;;;;KAwBY,sBAAA,QAA8B,sBAAA,CAAuB,GAAA;;KAGrD,qBAAA,QAA6B,qBAAA,CACvC,gBAAA,CAAiB,GAAA;;;;;;;;;AADnB;;;;;;;;;;;;;;AA6BA;;;iBAAgB,eAAA,WACJ,mBAAA,QACJ,eAAA,CAAgB,CAAA,EAAA,CAEtB,MAAA,EAAQ,CAAA,EACR,MAAA,cACA,OAAA,GAAU,sBAAA,CAAuB,GAAA,IAChC,qBAAA,CAAsB,GAAA;AAAA,iBACT,eAAA,WACJ,cAAA,kBACM,kBAAA,CAAmB,CAAA,SAC7B,eAAA,CAAgB,CAAA,EAAG,CAAA,EAAA,CAEzB,MAAA,EAAQ,CAAA,EACR,MAAA,GAAS,CAAA,GAAI,mBAAA,CAAoB,CAAA,EAAG,kBAAA,CAAmB,CAAA,YACvD,OAAA,GAAU,sBAAA,CAAuB,GAAA,IAChC,qBAAA,CAAsB,GAAA"}
1
+ {"version":3,"file":"use-database-list.d.ts","names":[],"sources":["../../../src/react/hooks/use-database-list.ts"],"mappings":";;;;;;;KAwBY,sBAAA,GAAyB,sBAAA;;KAGzB,qBAAA,QAA6B,qBAAA,CACvC,gBAAA,CAAiB,GAAA;;;;;AADnB;;;;;;;;;;;;;;AA6BA;;;;;;;iBAAgB,eAAA,WAA0B,mBAAA,CAAA,CACxC,MAAA,EAAQ,CAAA,EACR,MAAA,cACA,OAAA,GAAU,sBAAA,GACT,qBAAA,CAAsB,eAAA,CAAgB,CAAA;AAAA,iBACzB,eAAA,WACJ,cAAA,kBACM,kBAAA,CAAmB,CAAA,EAAA,CAEnC,MAAA,EAAQ,CAAA,EACR,MAAA,GAAS,CAAA,GAAI,mBAAA,CAAoB,CAAA,EAAG,kBAAA,CAAmB,CAAA,YACvD,OAAA,GAAU,sBAAA,GACT,qBAAA,CAAsB,eAAA,CAAgB,CAAA,EAAG,CAAA"}
@@ -19,8 +19,7 @@ function useDatabaseList(entity, params, options = {}) {
19
19
  include: params?.include,
20
20
  enabled,
21
21
  accept: isDatabaseListPage,
22
- keepPreviousData: options.keepPreviousData ?? false,
23
- shape: options.shape
22
+ keepPreviousData: options.keepPreviousData ?? false
24
23
  });
25
24
  }
26
25
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-database-list.js","names":[],"sources":["../../../src/react/hooks/use-database-list.ts"],"sourcesContent":["import {\n type DatabaseListPage,\n type DatabaseListQuery,\n DatabaseQueryEncodingError,\n encodeDatabaseListQuery,\n type ExactDatabaseParams,\n} from \"shared\";\n\nimport { isDatabaseListPage } from \"@/js/database/client\";\nimport type {\n DatabaseEntity,\n DatabaseKeyedEntity,\n DatabaseListParams,\n DatabaseListRow,\n} from \"@/js/database/types\";\n\nimport {\n type DatabaseReadRequest,\n type UseDatabaseReadOptions,\n type UseDatabaseReadResult,\n useDatabaseRead,\n} from \"./use-database-read\";\n\n/** Options for {@link useDatabaseList}. */\nexport type UseDatabaseListOptions<Row> = UseDatabaseReadOptions<Row>;\n\n/** What {@link useDatabaseList} returns: one page of rows and its state. */\nexport type UseDatabaseListResult<Row> = UseDatabaseReadResult<\n DatabaseListPage<Row>\n>;\n\n/**\n * Subscribe to one page of `GET /api/database/<entity>`. Entity, params, and\n * rows are typed from the generated `database.d.ts`; the route comes from the\n * endpoints the server published.\n *\n * Mounted hooks whose params encode to the same query share one request, so\n * an inline params literal does not refetch on every render. The request is\n * aborted once its last subscriber unmounts.\n *\n * @param entity - A table the generated registry exposes\n * @param params - `where`, `order`, `select`, `include`, `limit`, `offset`;\n * `null` holds the hook idle, for params that depend on another read\n * @param options - `enabled`, `keepPreviousData`, and `shape`\n * @returns The page, loading and error state, and `refetch`\n *\n * @example\n * ```tsx\n * const notes = useDatabaseList(\n * \"notes\",\n * board ? { where: { board_id: board.id }, limit: 20, offset } : null,\n * { keepPreviousData: true },\n * );\n * notes.data?.items.map((note) => note.body);\n * ```\n */\nexport function useDatabaseList<\n K extends DatabaseKeyedEntity,\n Row = DatabaseListRow<K>,\n>(\n entity: K,\n params?: undefined,\n options?: UseDatabaseListOptions<Row>,\n): UseDatabaseListResult<Row>;\nexport function useDatabaseList<\n K extends DatabaseEntity,\n const P extends DatabaseListParams<K>,\n Row = DatabaseListRow<K, P>,\n>(\n entity: K,\n params: (P & ExactDatabaseParams<P, DatabaseListParams<K>>) | null,\n options?: UseDatabaseListOptions<Row>,\n): UseDatabaseListResult<Row>;\nexport function useDatabaseList(\n entity: string,\n params?: DatabaseListQuery | null,\n options: UseDatabaseListOptions<unknown> = {},\n): UseDatabaseListResult<unknown> {\n const enabled = (options.enabled ?? true) && params !== null;\n // Encode only an enabled read: a held read's params may still be incomplete.\n let query: DatabaseReadRequest[\"query\"] = \"\";\n if (enabled) {\n try {\n query = encodeDatabaseListQuery(params ?? {});\n } catch (error) {\n query = error instanceof DatabaseQueryEncodingError ? error : null;\n }\n }\n const read = useDatabaseRead({\n entity,\n operation: \"list\",\n id: undefined,\n query,\n include: params?.include,\n enabled,\n accept: isDatabaseListPage,\n keepPreviousData: options.keepPreviousData ?? false,\n shape: options.shape,\n });\n return read as UseDatabaseListResult<unknown>;\n}\n"],"mappings":";;;;;AAyEA,SAAgB,gBACd,QACA,QACA,UAA2C,EAAE,EACb;CAChC,MAAM,WAAW,QAAQ,WAAW,SAAS,WAAW;CAExD,IAAI,QAAsC;AAC1C,KAAI,QACF,KAAI;AACF,UAAQ,wBAAwB,UAAU,EAAE,CAAC;UACtC,OAAO;AACd,UAAQ,iBAAiB,6BAA6B,QAAQ;;AAclE,QAXa,gBAAgB;EAC3B;EACA,WAAW;EACX,IAAI;EACJ;EACA,SAAS,QAAQ;EACjB;EACA,QAAQ;EACR,kBAAkB,QAAQ,oBAAoB;EAC9C,OAAO,QAAQ;EAChB,CAAC"}
1
+ {"version":3,"file":"use-database-list.js","names":[],"sources":["../../../src/react/hooks/use-database-list.ts"],"sourcesContent":["import {\n type DatabaseListPage,\n type DatabaseListQuery,\n DatabaseQueryEncodingError,\n encodeDatabaseListQuery,\n type ExactDatabaseParams,\n} from \"shared\";\n\nimport { isDatabaseListPage } from \"@/js/database/client\";\nimport type {\n DatabaseEntity,\n DatabaseKeyedEntity,\n DatabaseListParams,\n DatabaseListRow,\n} from \"@/js/database/types\";\n\nimport {\n type DatabaseReadRequest,\n type UseDatabaseReadOptions,\n type UseDatabaseReadResult,\n useDatabaseRead,\n} from \"./use-database-read\";\n\n/** Options for {@link useDatabaseList}. */\nexport type UseDatabaseListOptions = UseDatabaseReadOptions;\n\n/** What {@link useDatabaseList} returns: one page of rows and its state. */\nexport type UseDatabaseListResult<Row> = UseDatabaseReadResult<\n DatabaseListPage<Row>\n>;\n\n/**\n * Subscribe to one page of `GET /api/database/<entity>`. Entity, params, and\n * rows are typed from the generated `database.d.ts`; the route comes from the\n * endpoints the server published.\n *\n * Mounted hooks whose params encode to the same query share one request, so\n * an inline params literal does not refetch on every render. The request is\n * aborted once its last subscriber unmounts.\n *\n * @param entity - A table the generated registry exposes\n * @param params - `where`, `order`, `select`, `include`, `limit`, `offset`;\n * `null` holds the hook idle, for params that depend on another read\n * @param options - `enabled` and `keepPreviousData`\n * @returns The page, loading and error state, and `refetch`\n *\n * @example\n * ```tsx\n * const notes = useDatabaseList(\n * \"notes\",\n * board ? { where: { board_id: board.id }, limit: 20, offset } : null,\n * { keepPreviousData: true },\n * );\n * notes.data?.items.map((note) => note.body);\n * ```\n */\nexport function useDatabaseList<K extends DatabaseKeyedEntity>(\n entity: K,\n params?: undefined,\n options?: UseDatabaseListOptions,\n): UseDatabaseListResult<DatabaseListRow<K>>;\nexport function useDatabaseList<\n K extends DatabaseEntity,\n const P extends DatabaseListParams<K>,\n>(\n entity: K,\n params: (P & ExactDatabaseParams<P, DatabaseListParams<K>>) | null,\n options?: UseDatabaseListOptions,\n): UseDatabaseListResult<DatabaseListRow<K, P>>;\nexport function useDatabaseList(\n entity: string,\n params?: DatabaseListQuery | null,\n options: UseDatabaseListOptions = {},\n): UseDatabaseListResult<unknown> {\n const enabled = (options.enabled ?? true) && params !== null;\n // Encode only an enabled read: a held read's params may still be incomplete.\n let query: DatabaseReadRequest[\"query\"] = \"\";\n if (enabled) {\n try {\n query = encodeDatabaseListQuery(params ?? {});\n } catch (error) {\n query = error instanceof DatabaseQueryEncodingError ? error : null;\n }\n }\n const read = useDatabaseRead({\n entity,\n operation: \"list\",\n id: undefined,\n query,\n include: params?.include,\n enabled,\n accept: isDatabaseListPage,\n keepPreviousData: options.keepPreviousData ?? false,\n });\n return read as UseDatabaseListResult<unknown>;\n}\n"],"mappings":";;;;;AAqEA,SAAgB,gBACd,QACA,QACA,UAAkC,EAAE,EACJ;CAChC,MAAM,WAAW,QAAQ,WAAW,SAAS,WAAW;CAExD,IAAI,QAAsC;AAC1C,KAAI,QACF,KAAI;AACF,UAAQ,wBAAwB,UAAU,EAAE,CAAC;UACtC,OAAO;AACd,UAAQ,iBAAiB,6BAA6B,QAAQ;;AAalE,QAVa,gBAAgB;EAC3B;EACA,WAAW;EACX,IAAI;EACJ;EACA,SAAS,QAAQ;EACjB;EACA,QAAQ;EACR,kBAAkB,QAAQ,oBAAoB;EAC/C,CAAC"}
@@ -3,39 +3,8 @@ import "../../js/database/client.js";
3
3
  import { DatabaseApiError } from "../../js/database/errors.js";
4
4
 
5
5
  //#region src/react/hooks/use-database-read.d.ts
6
- declare const DATABASE_SHAPE: unique symbol;
7
- /**
8
- * Phantom marker for the row a read serializer returns. It only carries a
9
- * type; build one with {@link serialized}.
10
- */
11
- interface DatabaseShape<T> {
12
- readonly [DATABASE_SHAPE]: T;
13
- }
14
- /**
15
- * Declare, without checking, the row a read serializer returns. The entity,
16
- * id, and params stay checked against the generated registry; only the row
17
- * type is replaced. It is a promise about the server's serializer, not a
18
- * runtime check: to check each row, pass a parse function as `shape` instead.
19
- *
20
- * @example
21
- * ```typescript
22
- * interface NoteCard { id: number; excerpt: string }
23
- *
24
- * const notes = useDatabaseList("notes", { limit: 20 }, {
25
- * shape: serialized<NoteCard>(),
26
- * });
27
- * notes.data?.items[0]?.excerpt;
28
- * ```
29
- */
30
- declare function serialized<T>(): DatabaseShape<T>;
31
- /**
32
- * The row a read answers with: `serialized<T>()` to declare it, or a function
33
- * that checks one decoded row and returns it typed, such as a zod schema's
34
- * `parse`. A function that throws fails the read with `INTERNAL`.
35
- */
36
- type DatabaseRowShape<Row> = DatabaseShape<Row> | ((row: unknown) => Row);
37
6
  /** Options shared by `useDatabaseList` and `useDatabaseRecord`. */
38
- interface UseDatabaseReadOptions<Row> {
7
+ interface UseDatabaseReadOptions {
39
8
  /** Send the request. `false` keeps the hook idle and sends nothing. Default true. */
40
9
  enabled?: boolean;
41
10
  /**
@@ -44,12 +13,6 @@ interface UseDatabaseReadOptions<Row> {
44
13
  * stays true until the new response arrives. Default false.
45
14
  */
46
15
  keepPreviousData?: boolean;
47
- /**
48
- * The row a read serializer returns. `serialized<T>()` only declares it; a
49
- * function checks every row at runtime (each list item, or the record) and
50
- * its return value becomes the row. It runs once per response.
51
- */
52
- shape?: DatabaseRowShape<Row>;
53
16
  }
54
17
  /** Latest state of one database read. */
55
18
  interface UseDatabaseReadResult<T> {
@@ -63,13 +26,13 @@ interface UseDatabaseReadResult<T> {
63
26
  loading: boolean;
64
27
  /**
65
28
  * Why the latest request failed: `NOT_EXPOSED` when no route exists,
66
- * `INVALID_REQUEST` for params or an id that cannot be sent, `INTERNAL`
67
- * when a `shape` function rejected a row. Stable across renders.
29
+ * `INVALID_REQUEST` for params or an id that cannot be sent. Stable across
30
+ * renders.
68
31
  */
69
32
  error: DatabaseApiError | null;
70
33
  /** Abort any in-flight request and send it again. No-op while disabled. */
71
34
  refetch: () => void;
72
35
  }
73
36
  //#endregion
74
- export { DatabaseRowShape, DatabaseShape, UseDatabaseReadOptions, UseDatabaseReadResult, serialized };
37
+ export { UseDatabaseReadOptions, UseDatabaseReadResult };
75
38
  //# sourceMappingURL=use-database-read.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-database-read.d.ts","names":[],"sources":["../../../src/react/hooks/use-database-read.ts"],"mappings":";;;;;cAyBc,cAAA;;AAXgE;;;UAiB7D,aAAA;EAAA,UACL,cAAA,GAAiB,CAAA;AAAA;;;;;;;;;AAqB7B;;;;;;;;iBAAgB,UAAA,GAAA,CAAA,GAAiB,aAAA,CAAc,CAAA;AAS/C;;;;;AAAA,KAAY,gBAAA,QACR,aAAA,CAAc,GAAA,MACZ,GAAA,cAAiB,GAAA;;UAGN,sBAAA;EALY;EAO3B,OAAA;EANgB;;;;;EAYhB,gBAAA;EARqC;;;;;EAcrC,KAAA,GAAQ,gBAAA,CAAiB,GAAA;AAAA;;UAIV,qBAAA;EAJa;;AAI9B;;;EAME,IAAA,EAAM,CAAA;EAN+B;EAQrC,OAAA;EAFM;;;;;EAQN,KAAA,EAAO,gBAAA;EAEA;EAAP,OAAA;AAAA"}
1
+ {"version":3,"file":"use-database-read.d.ts","names":[],"sources":["../../../src/react/hooks/use-database-read.ts"],"mappings":";;;;;;UA0BiB,sBAAA;EAAA;EAEf,OAAA;;;;AAUF;;EAJE,gBAAA;AAAA;;UAIe,qBAAA;EAMT;;;;;EAAN,IAAA,EAAM,CAAA;EAUC;EARP,OAAA;;;;;;EAMA,KAAA,EAAO,gBAAA;;EAEP,OAAA;AAAA"}
@@ -5,74 +5,14 @@ import { IDLE_DATABASE_READ, databaseReadScope, getDatabaseReadSnapshot, retainD
5
5
  import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from "react";
6
6
 
7
7
  //#region src/react/hooks/use-database-read.ts
8
- const SERIALIZED = Object.freeze({});
9
- /**
10
- * Declare, without checking, the row a read serializer returns. The entity,
11
- * id, and params stay checked against the generated registry; only the row
12
- * type is replaced. It is a promise about the server's serializer, not a
13
- * runtime check: to check each row, pass a parse function as `shape` instead.
14
- *
15
- * @example
16
- * ```typescript
17
- * interface NoteCard { id: number; excerpt: string }
18
- *
19
- * const notes = useDatabaseList("notes", { limit: 20 }, {
20
- * shape: serialized<NoteCard>(),
21
- * });
22
- * notes.data?.items[0]?.excerpt;
23
- * ```
24
- */
25
- function serialized() {
26
- return SERIALIZED;
27
- }
28
8
  const noop = () => {};
29
- /** Apply a `shape` function to each row of one response. */
30
- function shapeResponse(operation, data, parse) {
31
- if (operation === "detail") return parse(data);
32
- const page = data;
33
- return {
34
- ...page,
35
- items: page.items.map((row) => parse(row))
36
- };
37
- }
38
- /**
39
- * Run a `shape` function once per response. The result is cached on the
40
- * response's identity, not the function's, so an inline arrow does not
41
- * reparse on every render or give `data` a new identity.
42
- */
43
- function useShapedData(operation, source, shape) {
44
- const cache = useRef(null);
45
- if (typeof shape !== "function" || source === null) return {
46
- source,
47
- data: source,
48
- error: null
49
- };
50
- const cached = cache.current;
51
- if (cached !== null && cached.source === source) return cached;
52
- let shaped;
53
- try {
54
- shaped = {
55
- source,
56
- data: shapeResponse(operation, source, shape),
57
- error: null
58
- };
59
- } catch (cause) {
60
- shaped = {
61
- source,
62
- data: null,
63
- error: new DatabaseApiError("INTERNAL", null, "Database response does not match the read's shape", [], { cause })
64
- };
65
- }
66
- cache.current = shaped;
67
- return shaped;
68
- }
69
9
  /**
70
10
  * One subscribed read, keyed by the resolved URL so params with equal encoded
71
11
  * values share a request whatever their object identity. A route the server
72
12
  * did not publish resolves to a stable `NOT_EXPOSED` error without a request,
73
13
  * and params that cannot be encoded to a stable `INVALID_REQUEST`.
74
14
  */
75
- function useDatabaseRead({ entity, operation, id, query, include, enabled, accept, keepPreviousData, shape }) {
15
+ function useDatabaseRead({ entity, operation, id, query, include, enabled, accept, keepPreviousData }) {
76
16
  const encodedQuery = typeof query === "string" ? query : null;
77
17
  const parameter = query instanceof DatabaseQueryEncodingError ? query.parameter : void 0;
78
18
  const message = query instanceof DatabaseQueryEncodingError ? query.message : void 0;
@@ -111,17 +51,16 @@ function useDatabaseRead({ entity, operation, id, query, include, enabled, accep
111
51
  const refetch = useCallback(() => {
112
52
  if (url !== null) startDatabaseRead(url);
113
53
  }, [url]);
114
- const shaped = useShapedData(operation, snapshot.data, shape);
115
54
  const loading = snapshot.loading || url !== null && snapshot === IDLE_DATABASE_READ;
116
- const error = routeError ?? snapshot.error ?? shaped.error;
55
+ const error = routeError ?? snapshot.error;
117
56
  const previous = useRef(null);
118
57
  useEffect(() => {
119
- if (url !== null && shaped.data !== null) previous.current = {
58
+ if (url !== null && snapshot.data !== null) previous.current = {
120
59
  url,
121
- data: shaped.data
60
+ data: snapshot.data
122
61
  };
123
- }, [url, shaped.data]);
124
- let data = shaped.data;
62
+ }, [url, snapshot.data]);
63
+ let data = snapshot.data;
125
64
  if (keepPreviousData && data === null && loading && error === null && previous.current !== null && previous.current.url !== url) data = previous.current.data;
126
65
  return {
127
66
  data,
@@ -132,5 +71,5 @@ function useDatabaseRead({ entity, operation, id, query, include, enabled, accep
132
71
  }
133
72
 
134
73
  //#endregion
135
- export { serialized, useDatabaseRead };
74
+ export { useDatabaseRead };
136
75
  //# sourceMappingURL=use-database-read.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-database-read.js","names":[],"sources":["../../../src/react/hooks/use-database-read.ts"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from \"react\";\nimport { DatabaseQueryEncodingError } from \"shared\";\n\nimport {\n type DatabaseOperation,\n type IdLike,\n resolveDatabaseUrl,\n} from \"@/js/database/client\";\nimport { DatabaseApiError, invalidDatabaseQuery } from \"@/js/database/errors\";\n\nimport {\n databaseReadScope,\n getDatabaseReadSnapshot,\n IDLE_DATABASE_READ,\n retainDatabaseRead,\n startDatabaseRead,\n subscribeDatabaseRead,\n} from \"./database-request-store\";\n\ndeclare const DATABASE_SHAPE: unique symbol;\n\n/**\n * Phantom marker for the row a read serializer returns. It only carries a\n * type; build one with {@link serialized}.\n */\nexport interface DatabaseShape<T> {\n readonly [DATABASE_SHAPE]: T;\n}\n\nconst SERIALIZED = Object.freeze({});\n\n/**\n * Declare, without checking, the row a read serializer returns. The entity,\n * id, and params stay checked against the generated registry; only the row\n * type is replaced. It is a promise about the server's serializer, not a\n * runtime check: to check each row, pass a parse function as `shape` instead.\n *\n * @example\n * ```typescript\n * interface NoteCard { id: number; excerpt: string }\n *\n * const notes = useDatabaseList(\"notes\", { limit: 20 }, {\n * shape: serialized<NoteCard>(),\n * });\n * notes.data?.items[0]?.excerpt;\n * ```\n */\nexport function serialized<T>(): DatabaseShape<T> {\n return SERIALIZED as DatabaseShape<T>;\n}\n\n/**\n * The row a read answers with: `serialized<T>()` to declare it, or a function\n * that checks one decoded row and returns it typed, such as a zod schema's\n * `parse`. A function that throws fails the read with `INTERNAL`.\n */\nexport type DatabaseRowShape<Row> =\n | DatabaseShape<Row>\n | ((row: unknown) => Row);\n\n/** Options shared by `useDatabaseList` and `useDatabaseRecord`. */\nexport interface UseDatabaseReadOptions<Row> {\n /** Send the request. `false` keeps the hook idle and sends nothing. Default true. */\n enabled?: boolean;\n /**\n * While new params load, keep showing the previous params' `data` instead\n * of `null`, so a paginated list does not blank between pages. `loading`\n * stays true until the new response arrives. Default false.\n */\n keepPreviousData?: boolean;\n /**\n * The row a read serializer returns. `serialized<T>()` only declares it; a\n * function checks every row at runtime (each list item, or the record) and\n * its return value becomes the row. It runs once per response.\n */\n shape?: DatabaseRowShape<Row>;\n}\n\n/** Latest state of one database read. */\nexport interface UseDatabaseReadResult<T> {\n /**\n * The last successful response, or `null` before one arrives. A refetch\n * keeps it visible while it loads and after it fails, except a `NOT_FOUND`,\n * which clears it.\n */\n data: T | null;\n /** Whether a request for the current params is in flight. */\n loading: boolean;\n /**\n * Why the latest request failed: `NOT_EXPOSED` when no route exists,\n * `INVALID_REQUEST` for params or an id that cannot be sent, `INTERNAL`\n * when a `shape` function rejected a row. Stable across renders.\n */\n error: DatabaseApiError | null;\n /** Abort any in-flight request and send it again. No-op while disabled. */\n refetch: () => void;\n}\n\n/** What one read hook asks `useDatabaseRead` to subscribe to. */\nexport interface DatabaseReadRequest {\n entity: string;\n operation: Extract<DatabaseOperation, \"list\" | \"detail\">;\n id: IdLike | undefined;\n /** Encoded params, a known validation failure, or `null` for an unknown failure. */\n query: string | DatabaseQueryEncodingError | null;\n /** The params' include tree, to find the tables the read shows. */\n include: unknown;\n enabled: boolean;\n accept: (body: unknown) => body is object;\n keepPreviousData: boolean;\n shape: DatabaseRowShape<unknown> | undefined;\n}\n\ntype Route = { url: string } | { error: DatabaseApiError } | null;\n\nconst noop = () => {};\n\n/** Apply a `shape` function to each row of one response. */\nfunction shapeResponse(\n operation: DatabaseReadRequest[\"operation\"],\n data: unknown,\n parse: (row: unknown) => unknown,\n): unknown {\n if (operation === \"detail\") return parse(data);\n const page = data as { items: unknown[] };\n return { ...page, items: page.items.map((row) => parse(row)) };\n}\n\n/** The shaped response, or why a row failed its `shape`. */\ninterface Shaped {\n source: unknown;\n data: unknown;\n error: DatabaseApiError | null;\n}\n\n/**\n * Run a `shape` function once per response. The result is cached on the\n * response's identity, not the function's, so an inline arrow does not\n * reparse on every render or give `data` a new identity.\n */\nfunction useShapedData(\n operation: DatabaseReadRequest[\"operation\"],\n source: unknown,\n shape: DatabaseRowShape<unknown> | undefined,\n): Shaped {\n const cache = useRef<Shaped | null>(null);\n if (typeof shape !== \"function\" || source === null) {\n return { source, data: source, error: null };\n }\n const cached = cache.current;\n if (cached !== null && cached.source === source) return cached;\n let shaped: Shaped;\n try {\n shaped = {\n source,\n data: shapeResponse(operation, source, shape),\n error: null,\n };\n } catch (cause) {\n // A schema error may quote row values; keep it in `cause` only.\n shaped = {\n source,\n data: null,\n error: new DatabaseApiError(\n \"INTERNAL\",\n null,\n \"Database response does not match the read's shape\",\n [],\n { cause },\n ),\n };\n }\n cache.current = shaped;\n return shaped;\n}\n\n/**\n * One subscribed read, keyed by the resolved URL so params with equal encoded\n * values share a request whatever their object identity. A route the server\n * did not publish resolves to a stable `NOT_EXPOSED` error without a request,\n * and params that cannot be encoded to a stable `INVALID_REQUEST`.\n */\nexport function useDatabaseRead({\n entity,\n operation,\n id,\n query,\n include,\n enabled,\n accept,\n keepPreviousData,\n shape,\n}: DatabaseReadRequest): UseDatabaseReadResult<unknown> {\n const encodedQuery = typeof query === \"string\" ? query : null;\n // Encoding runs every render; only the safe failure fields define its identity.\n const parameter =\n query instanceof DatabaseQueryEncodingError ? query.parameter : undefined;\n const message =\n query instanceof DatabaseQueryEncodingError ? query.message : undefined;\n const route = useMemo((): Route => {\n if (!enabled) return null;\n if (encodedQuery === null) {\n const cause =\n parameter !== undefined && message !== undefined\n ? new DatabaseQueryEncodingError(parameter, message)\n : undefined;\n return { error: invalidDatabaseQuery(cause) };\n }\n try {\n return { url: resolveDatabaseUrl(entity, operation, id, encodedQuery) };\n } catch (error) {\n if (error instanceof DatabaseApiError) return { error };\n throw error;\n }\n }, [enabled, entity, operation, id, encodedQuery, parameter, message]);\n\n const url = route !== null && \"url\" in route ? route.url : null;\n const routeError = route !== null && \"error\" in route ? route.error : null;\n\n // Every subscriber of one URL encodes the same include, so the URL is the\n // include tree's identity; the object passed in may be a fresh literal.\n const scope = useMemo(\n () => (url === null ? null : databaseReadScope(entity, include)),\n [url],\n );\n\n const subscribe = useCallback(\n (listener: () => void) =>\n url === null ? noop : subscribeDatabaseRead(url, listener),\n [url],\n );\n const getSnapshot = useCallback(\n () => (url === null ? IDLE_DATABASE_READ : getDatabaseReadSnapshot(url)),\n [url],\n );\n const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n // The first subscriber of a URL starts the request; later ones share it.\n useEffect(() => {\n if (url === null || scope === null) return;\n return retainDatabaseRead(url, accept, scope);\n }, [url, accept, scope]);\n\n const refetch = useCallback(() => {\n if (url !== null) startDatabaseRead(url);\n }, [url]);\n\n const shaped = useShapedData(operation, snapshot.data, shape);\n\n // Until the effect retains a new URL, its request is about to start.\n const loading =\n snapshot.loading || (url !== null && snapshot === IDLE_DATABASE_READ);\n const error = routeError ?? snapshot.error ?? shaped.error;\n\n // The last data this hook showed for a URL, to hold across a params change.\n const previous = useRef<{ url: string; data: unknown } | null>(null);\n useEffect(() => {\n if (url !== null && shaped.data !== null) {\n previous.current = { url, data: shaped.data };\n }\n }, [url, shaped.data]);\n\n let data = shaped.data;\n if (\n keepPreviousData &&\n data === null &&\n loading &&\n error === null &&\n previous.current !== null &&\n previous.current.url !== url\n ) {\n data = previous.current.data;\n }\n\n return { data, loading, error, refetch };\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"use-database-read.js","names":[],"sources":["../../../src/react/hooks/use-database-read.ts"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from \"react\";\nimport { DatabaseQueryEncodingError } from \"shared\";\n\nimport {\n type DatabaseOperation,\n type IdLike,\n resolveDatabaseUrl,\n} from \"@/js/database/client\";\nimport { DatabaseApiError, invalidDatabaseQuery } from \"@/js/database/errors\";\n\nimport {\n databaseReadScope,\n getDatabaseReadSnapshot,\n IDLE_DATABASE_READ,\n retainDatabaseRead,\n startDatabaseRead,\n subscribeDatabaseRead,\n} from \"./database-request-store\";\n\n/** Options shared by `useDatabaseList` and `useDatabaseRecord`. */\nexport interface UseDatabaseReadOptions {\n /** Send the request. `false` keeps the hook idle and sends nothing. Default true. */\n enabled?: boolean;\n /**\n * While new params load, keep showing the previous params' `data` instead\n * of `null`, so a paginated list does not blank between pages. `loading`\n * stays true until the new response arrives. Default false.\n */\n keepPreviousData?: boolean;\n}\n\n/** Latest state of one database read. */\nexport interface UseDatabaseReadResult<T> {\n /**\n * The last successful response, or `null` before one arrives. A refetch\n * keeps it visible while it loads and after it fails, except a `NOT_FOUND`,\n * which clears it.\n */\n data: T | null;\n /** Whether a request for the current params is in flight. */\n loading: boolean;\n /**\n * Why the latest request failed: `NOT_EXPOSED` when no route exists,\n * `INVALID_REQUEST` for params or an id that cannot be sent. Stable across\n * renders.\n */\n error: DatabaseApiError | null;\n /** Abort any in-flight request and send it again. No-op while disabled. */\n refetch: () => void;\n}\n\n/** What one read hook asks `useDatabaseRead` to subscribe to. */\nexport interface DatabaseReadRequest {\n entity: string;\n operation: Extract<DatabaseOperation, \"list\" | \"detail\">;\n id: IdLike | undefined;\n /** Encoded params, a known validation failure, or `null` for an unknown failure. */\n query: string | DatabaseQueryEncodingError | null;\n /** The params' include tree, to find the tables the read shows. */\n include: unknown;\n enabled: boolean;\n accept: (body: unknown) => body is object;\n keepPreviousData: boolean;\n}\n\ntype Route = { url: string } | { error: DatabaseApiError } | null;\n\nconst noop = () => {};\n\n/**\n * One subscribed read, keyed by the resolved URL so params with equal encoded\n * values share a request whatever their object identity. A route the server\n * did not publish resolves to a stable `NOT_EXPOSED` error without a request,\n * and params that cannot be encoded to a stable `INVALID_REQUEST`.\n */\nexport function useDatabaseRead({\n entity,\n operation,\n id,\n query,\n include,\n enabled,\n accept,\n keepPreviousData,\n}: DatabaseReadRequest): UseDatabaseReadResult<unknown> {\n const encodedQuery = typeof query === \"string\" ? query : null;\n // Encoding runs every render; only the safe failure fields define its identity.\n const parameter =\n query instanceof DatabaseQueryEncodingError ? query.parameter : undefined;\n const message =\n query instanceof DatabaseQueryEncodingError ? query.message : undefined;\n const route = useMemo((): Route => {\n if (!enabled) return null;\n if (encodedQuery === null) {\n const cause =\n parameter !== undefined && message !== undefined\n ? new DatabaseQueryEncodingError(parameter, message)\n : undefined;\n return { error: invalidDatabaseQuery(cause) };\n }\n try {\n return { url: resolveDatabaseUrl(entity, operation, id, encodedQuery) };\n } catch (error) {\n if (error instanceof DatabaseApiError) return { error };\n throw error;\n }\n }, [enabled, entity, operation, id, encodedQuery, parameter, message]);\n\n const url = route !== null && \"url\" in route ? route.url : null;\n const routeError = route !== null && \"error\" in route ? route.error : null;\n\n // Every subscriber of one URL encodes the same include, so the URL is the\n // include tree's identity; the object passed in may be a fresh literal.\n const scope = useMemo(\n () => (url === null ? null : databaseReadScope(entity, include)),\n [url],\n );\n\n const subscribe = useCallback(\n (listener: () => void) =>\n url === null ? noop : subscribeDatabaseRead(url, listener),\n [url],\n );\n const getSnapshot = useCallback(\n () => (url === null ? IDLE_DATABASE_READ : getDatabaseReadSnapshot(url)),\n [url],\n );\n const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n // The first subscriber of a URL starts the request; later ones share it.\n useEffect(() => {\n if (url === null || scope === null) return;\n return retainDatabaseRead(url, accept, scope);\n }, [url, accept, scope]);\n\n const refetch = useCallback(() => {\n if (url !== null) startDatabaseRead(url);\n }, [url]);\n\n // Until the effect retains a new URL, its request is about to start.\n const loading =\n snapshot.loading || (url !== null && snapshot === IDLE_DATABASE_READ);\n const error = routeError ?? snapshot.error;\n\n // The last data this hook showed for a URL, to hold across a params change.\n const previous = useRef<{ url: string; data: unknown } | null>(null);\n useEffect(() => {\n if (url !== null && snapshot.data !== null) {\n previous.current = { url, data: snapshot.data };\n }\n }, [url, snapshot.data]);\n\n let data = snapshot.data;\n if (\n keepPreviousData &&\n data === null &&\n loading &&\n error === null &&\n previous.current !== null &&\n previous.current.url !== url\n ) {\n data = previous.current.data;\n }\n\n return { data, loading, error, refetch };\n}\n"],"mappings":";;;;;;;AAyEA,MAAM,aAAa;;;;;;;AAQnB,SAAgB,gBAAgB,EAC9B,QACA,WACA,IACA,OACA,SACA,SACA,QACA,oBACsD;CACtD,MAAM,eAAe,OAAO,UAAU,WAAW,QAAQ;CAEzD,MAAM,YACJ,iBAAiB,6BAA6B,MAAM,YAAY;CAClE,MAAM,UACJ,iBAAiB,6BAA6B,MAAM,UAAU;CAChE,MAAM,QAAQ,cAAqB;AACjC,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,iBAAiB,KAKnB,QAAO,EAAE,OAAO,qBAHd,cAAc,UAAa,YAAY,SACnC,IAAI,2BAA2B,WAAW,QAAQ,GAClD,OACqC,EAAE;AAE/C,MAAI;AACF,UAAO,EAAE,KAAK,mBAAmB,QAAQ,WAAW,IAAI,aAAa,EAAE;WAChE,OAAO;AACd,OAAI,iBAAiB,iBAAkB,QAAO,EAAE,OAAO;AACvD,SAAM;;IAEP;EAAC;EAAS;EAAQ;EAAW;EAAI;EAAc;EAAW;EAAQ,CAAC;CAEtE,MAAM,MAAM,UAAU,QAAQ,SAAS,QAAQ,MAAM,MAAM;CAC3D,MAAM,aAAa,UAAU,QAAQ,WAAW,QAAQ,MAAM,QAAQ;CAItE,MAAM,QAAQ,cACL,QAAQ,OAAO,OAAO,kBAAkB,QAAQ,QAAQ,EAC/D,CAAC,IAAI,CACN;CAED,MAAM,YAAY,aACf,aACC,QAAQ,OAAO,OAAO,sBAAsB,KAAK,SAAS,EAC5D,CAAC,IAAI,CACN;CACD,MAAM,cAAc,kBACX,QAAQ,OAAO,qBAAqB,wBAAwB,IAAI,EACvE,CAAC,IAAI,CACN;CACD,MAAM,WAAW,qBAAqB,WAAW,aAAa,YAAY;AAG1E,iBAAgB;AACd,MAAI,QAAQ,QAAQ,UAAU,KAAM;AACpC,SAAO,mBAAmB,KAAK,QAAQ,MAAM;IAC5C;EAAC;EAAK;EAAQ;EAAM,CAAC;CAExB,MAAM,UAAU,kBAAkB;AAChC,MAAI,QAAQ,KAAM,mBAAkB,IAAI;IACvC,CAAC,IAAI,CAAC;CAGT,MAAM,UACJ,SAAS,WAAY,QAAQ,QAAQ,aAAa;CACpD,MAAM,QAAQ,cAAc,SAAS;CAGrC,MAAM,WAAW,OAA8C,KAAK;AACpE,iBAAgB;AACd,MAAI,QAAQ,QAAQ,SAAS,SAAS,KACpC,UAAS,UAAU;GAAE;GAAK,MAAM,SAAS;GAAM;IAEhD,CAAC,KAAK,SAAS,KAAK,CAAC;CAExB,IAAI,OAAO,SAAS;AACpB,KACE,oBACA,SAAS,QACT,WACA,UAAU,QACV,SAAS,YAAY,QACrB,SAAS,QAAQ,QAAQ,IAEzB,QAAO,SAAS,QAAQ;AAG1B,QAAO;EAAE;EAAM;EAAS;EAAO;EAAS"}
@@ -5,7 +5,7 @@ import { UseDatabaseReadOptions, UseDatabaseReadResult } from "./use-database-re
5
5
 
6
6
  //#region src/react/hooks/use-database-record.d.ts
7
7
  /** Options for {@link useDatabaseRecord}. */
8
- type UseDatabaseRecordOptions<Row> = UseDatabaseReadOptions<Row>;
8
+ type UseDatabaseRecordOptions = UseDatabaseReadOptions;
9
9
  /** What {@link useDatabaseRecord} returns: one row and its state. */
10
10
  type UseDatabaseRecordResult<Row> = UseDatabaseReadResult<Row>;
11
11
  /**
@@ -20,7 +20,7 @@ type UseDatabaseRecordResult<Row> = UseDatabaseReadResult<Row>;
20
20
  * @param entity - A table the generated registry exposes with a public key
21
21
  * @param id - The row's public key, or `null`/`undefined` to wait
22
22
  * @param params - `select` and `include`; pass `{}` to reach `options` alone
23
- * @param options - `enabled`, `keepPreviousData`, and `shape`
23
+ * @param options - `enabled` and `keepPreviousData`
24
24
  * @returns The row, loading and error state, and `refetch`
25
25
  *
26
26
  * @example
@@ -31,7 +31,7 @@ type UseDatabaseRecordResult<Row> = UseDatabaseReadResult<Row>;
31
31
  * board.data?.notes.length;
32
32
  * ```
33
33
  */
34
- declare function useDatabaseRecord<K extends DatabaseKeyedEntity, const P extends DatabaseRecordParams<K> = Record<never, never>, Row = DatabaseRecordRow<K, P>>(entity: K, id: DatabaseId<K> | null | undefined, params?: P & ExactDatabaseParams<P, DatabaseRecordParams<K>>, options?: UseDatabaseRecordOptions<Row>): UseDatabaseRecordResult<Row>;
34
+ declare function useDatabaseRecord<K extends DatabaseKeyedEntity, const P extends DatabaseRecordParams<K> = Record<never, never>>(entity: K, id: DatabaseId<K> | null | undefined, params?: P & ExactDatabaseParams<P, DatabaseRecordParams<K>>, options?: UseDatabaseRecordOptions): UseDatabaseRecordResult<DatabaseRecordRow<K, P>>;
35
35
  //#endregion
36
36
  export { UseDatabaseRecordOptions, UseDatabaseRecordResult, useDatabaseRecord };
37
37
  //# sourceMappingURL=use-database-record.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-database-record.d.ts","names":[],"sources":["../../../src/react/hooks/use-database-record.ts"],"mappings":";;;;;;;KAsBY,wBAAA,QAAgC,sBAAA,CAAuB,GAAA;;KAGvD,uBAAA,QAA+B,qBAAA,CAAsB,GAAA;;;;;;;;;AAAjE;;;;;;;;;AAyBA;;;;;;iBAAgB,iBAAA,WACJ,mBAAA,kBACM,oBAAA,CAAqB,CAAA,IAAK,MAAA,sBACpC,iBAAA,CAAkB,CAAA,EAAG,CAAA,EAAA,CAE3B,MAAA,EAAQ,CAAA,EACR,EAAA,EAAI,UAAA,CAAW,CAAA,sBACf,MAAA,GAAS,CAAA,GAAI,mBAAA,CAAoB,CAAA,EAAG,oBAAA,CAAqB,CAAA,IACzD,OAAA,GAAS,wBAAA,CAAyB,GAAA,IACjC,uBAAA,CAAwB,GAAA"}
1
+ {"version":3,"file":"use-database-record.d.ts","names":[],"sources":["../../../src/react/hooks/use-database-record.ts"],"mappings":";;;;;;;KAsBY,wBAAA,GAA2B,sBAAA;;KAG3B,uBAAA,QAA+B,qBAAA,CAAsB,GAAA;;;;;AAAjE;;;;;;;;;AAyBA;;;;;;;;;;iBAAgB,iBAAA,WACJ,mBAAA,kBACM,oBAAA,CAAqB,CAAA,IAAK,MAAA,eAAA,CAE1C,MAAA,EAAQ,CAAA,EACR,EAAA,EAAI,UAAA,CAAW,CAAA,sBACf,MAAA,GAAS,CAAA,GAAI,mBAAA,CAAoB,CAAA,EAAG,oBAAA,CAAqB,CAAA,IACzD,OAAA,GAAS,wBAAA,GACR,uBAAA,CAAwB,iBAAA,CAAkB,CAAA,EAAG,CAAA"}
@@ -15,7 +15,7 @@ import { useDatabaseRead } from "./use-database-read.js";
15
15
  * @param entity - A table the generated registry exposes with a public key
16
16
  * @param id - The row's public key, or `null`/`undefined` to wait
17
17
  * @param params - `select` and `include`; pass `{}` to reach `options` alone
18
- * @param options - `enabled`, `keepPreviousData`, and `shape`
18
+ * @param options - `enabled` and `keepPreviousData`
19
19
  * @returns The row, loading and error state, and `refetch`
20
20
  *
21
21
  * @example
@@ -43,8 +43,7 @@ function useDatabaseRecord(entity, id, params, options = {}) {
43
43
  include: recordParams.include,
44
44
  enabled,
45
45
  accept: isDatabaseRow,
46
- keepPreviousData: options.keepPreviousData ?? false,
47
- shape: options.shape
46
+ keepPreviousData: options.keepPreviousData ?? false
48
47
  });
49
48
  }
50
49