js-bao 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -30
- package/dist/browser.cjs +586 -265
- package/dist/browser.d.cts +21 -0
- package/dist/browser.d.ts +21 -0
- package/dist/browser.js +588 -263
- package/dist/client.cjs +42 -6
- package/dist/client.d.cts +71 -0
- package/dist/client.d.ts +71 -0
- package/dist/client.js +39 -4
- package/dist/cloudflare-do.cjs +462 -215
- package/dist/cloudflare-do.d.cts +111 -1
- package/dist/cloudflare-do.d.ts +111 -1
- package/dist/cloudflare-do.js +459 -213
- package/dist/cloudflare.cjs +270 -23
- package/dist/cloudflare.d.cts +276 -1
- package/dist/cloudflare.d.ts +276 -1
- package/dist/cloudflare.js +267 -21
- package/dist/codegen-v2.cjs +77 -19
- package/dist/codegen.cjs +2 -1
- package/dist/index.cjs +551 -224
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +549 -221
- package/dist/node.cjs +775 -291
- package/dist/node.d.cts +179 -1
- package/dist/node.d.ts +179 -1
- package/dist/node.js +762 -288
- package/package.json +2 -1
package/dist/cloudflare-do.d.cts
CHANGED
|
@@ -981,6 +981,18 @@ interface HookResult {
|
|
|
981
981
|
allow: boolean;
|
|
982
982
|
/** Reason for denial (returned to client as error message) */
|
|
983
983
|
reason?: string;
|
|
984
|
+
/**
|
|
985
|
+
* Names of fields the hook wrote onto `ctx.data` that the DO should echo
|
|
986
|
+
* back to the caller in the write response's `appliedFields`. A `beforeSave`
|
|
987
|
+
* hook can compute and set fields on `ctx.data` (e.g. app-level triggers that
|
|
988
|
+
* derive a value from the submitted row); those values are persisted but are
|
|
989
|
+
* invisible to a caller that rebuilds a change event from its original
|
|
990
|
+
* submission inputs. Reporting the names here lets the DO read the final
|
|
991
|
+
* post-hook values back and thread them into `appliedFields` so the caller
|
|
992
|
+
* can propagate them (#1476). The hook contract stays generic — it names the
|
|
993
|
+
* fields it applied and does not need to know how the caller uses them.
|
|
994
|
+
*/
|
|
995
|
+
serverAppliedFieldNames?: string[];
|
|
984
996
|
}
|
|
985
997
|
/** Result from beforeQuery hooks — can inject additional filters */
|
|
986
998
|
interface BeforeQueryResult extends HookResult {
|
|
@@ -1107,6 +1119,20 @@ interface QueryResponse {
|
|
|
1107
1119
|
interface SaveResponse {
|
|
1108
1120
|
success: boolean;
|
|
1109
1121
|
id: string;
|
|
1122
|
+
/**
|
|
1123
|
+
* Server-applied field values the DO wrote AFTER the caller's submission
|
|
1124
|
+
* inputs were assembled, read back from the final post-hook `data`
|
|
1125
|
+
* (#1476, consolidating the #1462 `stamps` channel). This is the single
|
|
1126
|
+
* "server-applied fields" channel: it carries both the applied `autoStamps`
|
|
1127
|
+
* timestamps and any fields a `beforeSave` hook reported via
|
|
1128
|
+
* `serverAppliedFieldNames` (e.g. app-level trigger-computed values). Present
|
|
1129
|
+
* only when at least one such field ended up with a value. Lets the Worker
|
|
1130
|
+
* thread these values into the change-event `data` it broadcasts to
|
|
1131
|
+
* subscribers — otherwise a `select`-listed stamped or trigger-computed field
|
|
1132
|
+
* never reaches the frame, because the frame is rebuilt from the submission
|
|
1133
|
+
* inputs (which predate the DO-side write).
|
|
1134
|
+
*/
|
|
1135
|
+
appliedFields?: Record<string, any>;
|
|
1110
1136
|
}
|
|
1111
1137
|
interface DeleteResponse {
|
|
1112
1138
|
success: boolean;
|
|
@@ -1189,6 +1215,8 @@ interface PatchRequest {
|
|
|
1189
1215
|
interface PatchResponse {
|
|
1190
1216
|
success: boolean;
|
|
1191
1217
|
id: string;
|
|
1218
|
+
/** Server-applied field values (#1476). See `SaveResponse.appliedFields`. */
|
|
1219
|
+
appliedFields?: Record<string, any>;
|
|
1192
1220
|
}
|
|
1193
1221
|
interface BatchOperation {
|
|
1194
1222
|
op: "save" | "patch" | "delete" | "increment" | "addToSet" | "removeFromSet";
|
|
@@ -1216,12 +1244,46 @@ interface BatchOperation {
|
|
|
1216
1244
|
}
|
|
1217
1245
|
interface BatchRequest {
|
|
1218
1246
|
operations: BatchOperation[];
|
|
1247
|
+
/**
|
|
1248
|
+
* All-or-nothing execution (#1478). When `true`, the FIRST operation that
|
|
1249
|
+
* fails inside the transaction — hook denial, condition / `ifNotExists` /
|
|
1250
|
+
* unique violation, record-not-found, or upsert validation error — aborts
|
|
1251
|
+
* the whole batch: every write is rolled back and the handler returns an
|
|
1252
|
+
* error naming the failed step with its natural HTTP status (see
|
|
1253
|
+
* `BatchOperationResult.status`). When `false` or absent (the default), each
|
|
1254
|
+
* operation's outcome is recorded independently and successful siblings
|
|
1255
|
+
* commit — the partial-success behavior import-bulk and applyToQuery rely on.
|
|
1256
|
+
*/
|
|
1257
|
+
atomic?: boolean;
|
|
1219
1258
|
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Stable, machine-readable failure tag on a failed `BatchOperationResult`
|
|
1261
|
+
* (#1478). Derived at each failure site — never inferred from the `error`
|
|
1262
|
+
* string. `#1389` (conditional writes + fencing-token enforcement) surfaces its
|
|
1263
|
+
* condition / stale-token rejections through this same channel.
|
|
1264
|
+
*/
|
|
1265
|
+
type BatchFailureCode = "NOT_FOUND" | "HOOK_DENIED" | "CONDITION_NOT_MET" | "ALREADY_EXISTS" | "UNIQUE_VIOLATION" | "VALIDATION_ERROR";
|
|
1220
1266
|
interface BatchOperationResult {
|
|
1221
1267
|
success: boolean;
|
|
1222
1268
|
id: string;
|
|
1223
1269
|
error?: string;
|
|
1270
|
+
/**
|
|
1271
|
+
* Structured failure metadata (#1478), present only on a failed result. Both
|
|
1272
|
+
* are derived at the failure site, not parsed back out of `error`:
|
|
1273
|
+
* - `status` — the natural HTTP status for the cause (404 not found,
|
|
1274
|
+
* 403 hook denial, 409 condition / `ifNotExists` / unique conflict,
|
|
1275
|
+
* 400 upsert validation).
|
|
1276
|
+
* - `code` — a stable machine-readable tag (see `BatchFailureCode`).
|
|
1277
|
+
*
|
|
1278
|
+
* In atomic mode the handler reads the first failure's `status`/`code` to
|
|
1279
|
+
* build the error response, so an increment-on-missing op keeps its 404 and a
|
|
1280
|
+
* hook denial keeps its 403 instead of collapsing to a uniform 409.
|
|
1281
|
+
*/
|
|
1282
|
+
status?: number;
|
|
1283
|
+
code?: BatchFailureCode;
|
|
1224
1284
|
values?: Record<string, number>;
|
|
1285
|
+
/** Server-applied field values (#1476). See `SaveResponse.appliedFields`. */
|
|
1286
|
+
appliedFields?: Record<string, any>;
|
|
1225
1287
|
}
|
|
1226
1288
|
interface BatchResponse {
|
|
1227
1289
|
results: BatchOperationResult[];
|
|
@@ -1453,6 +1515,33 @@ declare function createDatabaseDO(config?: DatabaseDOConfig): {
|
|
|
1453
1515
|
*/
|
|
1454
1516
|
declare const createDocumentDO: typeof createDatabaseDO;
|
|
1455
1517
|
|
|
1518
|
+
/**
|
|
1519
|
+
* Decoding for rows read out of the schemaless `records` table.
|
|
1520
|
+
*
|
|
1521
|
+
* A `SELECT` built by `JsonQueryTranslator` comes back in one of two shapes:
|
|
1522
|
+
* the whole record (`_id`, `_type`, `_data`), or — under an inclusion
|
|
1523
|
+
* projection — one column per projected field. Both shapes are turned back
|
|
1524
|
+
* into a record object here, so every reader of the store (the DatabaseDO's
|
|
1525
|
+
* query/get paths, the per-document SQLite projection) hands callers the same
|
|
1526
|
+
* values for the same stored record.
|
|
1527
|
+
*/
|
|
1528
|
+
/**
|
|
1529
|
+
* Column-alias prefix for a projected field whose value is selected as JSON
|
|
1530
|
+
* text. The prefix marks the column as still-encoded so
|
|
1531
|
+
* {@link parseRecordRow} knows to decode it; field names cannot start with
|
|
1532
|
+
* `_` (the write path rejects them as reserved), so the prefix can never
|
|
1533
|
+
* collide with a real field.
|
|
1534
|
+
*/
|
|
1535
|
+
declare const PROJECTED_JSON_ALIAS_PREFIX = "_json_";
|
|
1536
|
+
/** Column alias under which a projected field's JSON text is selected. */
|
|
1537
|
+
declare function projectedJsonAlias(fieldName: string): string;
|
|
1538
|
+
/**
|
|
1539
|
+
* Decode one row of a `records` SELECT into a record object: `_id`/`_type`
|
|
1540
|
+
* become `id`/`type`, `_data` is parsed when present, and any projected
|
|
1541
|
+
* column is decoded back to its stored value.
|
|
1542
|
+
*/
|
|
1543
|
+
declare function parseRecordRow(row: Record<string, any>): Record<string, any>;
|
|
1544
|
+
|
|
1456
1545
|
/**
|
|
1457
1546
|
* Cloudflare Worker Router Template
|
|
1458
1547
|
*
|
|
@@ -1919,6 +2008,27 @@ declare class BaseModel implements StringSetChangeTracker {
|
|
|
1919
2008
|
*/
|
|
1920
2009
|
static count(this: new (...args: any[]) => any, filter?: DocumentFilter, options?: Pick<QueryOptions, "documents">): Promise<number>;
|
|
1921
2010
|
static findAll<T extends BaseModel>(this: new (...args: any[]) => T): Promise<T[]>;
|
|
2011
|
+
/**
|
|
2012
|
+
* Resolve a record by its unique-constraint field values via an engine query.
|
|
2013
|
+
* Used as a fallback when the `_uniqueIdx_<model>_<constraint>` map has no
|
|
2014
|
+
* entry for a key.
|
|
2015
|
+
*
|
|
2016
|
+
* The index map is a cache over the SQLite projection, not the source of
|
|
2017
|
+
* truth: every record is loaded into the projection on `initializeForDocument`
|
|
2018
|
+
* regardless of index presence, but a record written by a client predating
|
|
2019
|
+
* index maintenance (legacy data) is missing from the index. Such a record
|
|
2020
|
+
* silently escapes both `upsertByUnique` lookups and the `save()` uniqueness
|
|
2021
|
+
* check. A query over the constraint fields finds it reliably.
|
|
2022
|
+
*
|
|
2023
|
+
* Contract: RESOLVE ONLY. Returns the owning record (with `_metaDocId` set to
|
|
2024
|
+
* the document that holds it, via `queryOne`) or `null`. Callers decide
|
|
2025
|
+
* whether to heal the missing index entry (write paths) and do their own
|
|
2026
|
+
* logging — this method never mutates the index, so read paths stay
|
|
2027
|
+
* read-only. Mirrors `buildUniqueKey`: a null/undefined value in any
|
|
2028
|
+
* constraint field means the record does not participate in the constraint,
|
|
2029
|
+
* so no query runs.
|
|
2030
|
+
*/
|
|
2031
|
+
private static _resolveByUniqueFallback;
|
|
1922
2032
|
static findByUnique<T extends BaseModel>(this: typeof BaseModel & (new (...args: any[]) => T), constraintName: string, value: any | any[]): Promise<T | null>;
|
|
1923
2033
|
static upsertByUnique<T extends BaseModel>(this: typeof BaseModel & (new (...args: any[]) => T), constraintName: string, uniqueLookupValue: any | any[], dataToUpsert: Partial<Omit<InstanceType<new (...args: any[]) => T>, keyof BaseModel | "toJSON">> & {
|
|
1924
2034
|
id?: string;
|
|
@@ -2067,4 +2177,4 @@ declare function deterministicIdentifierHash(value: string): string;
|
|
|
2067
2177
|
*/
|
|
2068
2178
|
declare function buildSafeAlias(prefix: string, rawDescriptor: string): string;
|
|
2069
2179
|
|
|
2070
|
-
export { type AfterQueryContext, type AfterQueryResult, type AggregateRequest, type AggregateResponse, type AggregationOperation$1 as AggregationOperation, type AggregationOptions$1 as AggregationOptions, type AggregationResult$1 as AggregationResult, type BatchOperation, type BatchOperationResult, type BatchRequest, type BatchResponse, type BeforeDeleteContext, type BeforeQueryContext, type BeforeQueryResult, type BeforeSaveContext, type CountRequest, type CountResponse, type DatabaseDOConfig, type DatabaseDOHooks, type DeleteRequest, type DeleteResponse, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type DocumentDOConfig, type DropIndexRequest, type DropIndexResponse, type DropUniqueConstraintRequest, type DropUniqueConstraintResponse, DurableObjectEngine, type DurableObjectEngineOptions, type DurableObjectId, type DurableObjectNamespace, type DurableObjectState, type DurableObjectStorage, type DurableObjectStub, type Env, type ErrorResponse, type GroupByField$1 as GroupByField, type HookContext, type HookResult, type IncrementRequest, type IncrementResponse, type IndexEntry, type IndexListResponse, JsonQueryTranslator, type JsonQueryTranslatorOptions, JsonSchemaDDL, type JsonSchemaOptions, type PatchRequest, type PatchResponse, type QueryRequest, type QueryResponse, type RegisterIndexRequest, type RegisterIndexResponse, type RegisterUniqueConstraintRequest, type RegisterUniqueConstraintResponse, type SaveRequest, type SaveResponse, type SchemaConstraintInfo, type SchemaFieldInfo, type SchemaModelInfo, type SchemaResponse, type SqlStorage, type SqlStorageCursor, type StringSetMembership$1 as StringSetMembership, type StringSetUpdateRequest, type StringSetUpdateResponse, type SyncIndexesRequest, type SyncIndexesResponse, type UniqueConstraintEntry, type UniqueConstraintListResponse, buildSafeAlias, checkAutoStampsReservedFields, checkReservedFieldName, clearMetaSyncCache, createDatabaseDO, createDocumentDO, deterministicIdentifierHash, discoverModelNames, discoverSchema, handleRequest, inferFieldType, loadSchemaFromTomlString, registerFunctionDefault, schemaToToml, syncInferredMeta, syncModelMeta };
|
|
2180
|
+
export { type AfterQueryContext, type AfterQueryResult, type AggregateRequest, type AggregateResponse, type AggregationOperation$1 as AggregationOperation, type AggregationOptions$1 as AggregationOptions, type AggregationResult$1 as AggregationResult, type BatchOperation, type BatchOperationResult, type BatchRequest, type BatchResponse, type BeforeDeleteContext, type BeforeQueryContext, type BeforeQueryResult, type BeforeSaveContext, type CountRequest, type CountResponse, type DatabaseDOConfig, type DatabaseDOHooks, type DeleteRequest, type DeleteResponse, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type DocumentDOConfig, type DropIndexRequest, type DropIndexResponse, type DropUniqueConstraintRequest, type DropUniqueConstraintResponse, DurableObjectEngine, type DurableObjectEngineOptions, type DurableObjectId, type DurableObjectNamespace, type DurableObjectState, type DurableObjectStorage, type DurableObjectStub, type Env, type ErrorResponse, type GroupByField$1 as GroupByField, type HookContext, type HookResult, type IncrementRequest, type IncrementResponse, type IndexEntry, type IndexListResponse, JsonQueryTranslator, type JsonQueryTranslatorOptions, JsonSchemaDDL, type JsonSchemaOptions, PROJECTED_JSON_ALIAS_PREFIX, type PatchRequest, type PatchResponse, type QueryRequest, type QueryResponse, type RegisterIndexRequest, type RegisterIndexResponse, type RegisterUniqueConstraintRequest, type RegisterUniqueConstraintResponse, type SaveRequest, type SaveResponse, type SchemaConstraintInfo, type SchemaFieldInfo, type SchemaModelInfo, type SchemaResponse, type SqlStorage, type SqlStorageCursor, type StringSetMembership$1 as StringSetMembership, type StringSetUpdateRequest, type StringSetUpdateResponse, type SyncIndexesRequest, type SyncIndexesResponse, type UniqueConstraintEntry, type UniqueConstraintListResponse, buildSafeAlias, checkAutoStampsReservedFields, checkReservedFieldName, clearMetaSyncCache, createDatabaseDO, createDocumentDO, deterministicIdentifierHash, discoverModelNames, discoverSchema, handleRequest, inferFieldType, loadSchemaFromTomlString, parseRecordRow, projectedJsonAlias, registerFunctionDefault, schemaToToml, syncInferredMeta, syncModelMeta };
|
package/dist/cloudflare-do.d.ts
CHANGED
|
@@ -981,6 +981,18 @@ interface HookResult {
|
|
|
981
981
|
allow: boolean;
|
|
982
982
|
/** Reason for denial (returned to client as error message) */
|
|
983
983
|
reason?: string;
|
|
984
|
+
/**
|
|
985
|
+
* Names of fields the hook wrote onto `ctx.data` that the DO should echo
|
|
986
|
+
* back to the caller in the write response's `appliedFields`. A `beforeSave`
|
|
987
|
+
* hook can compute and set fields on `ctx.data` (e.g. app-level triggers that
|
|
988
|
+
* derive a value from the submitted row); those values are persisted but are
|
|
989
|
+
* invisible to a caller that rebuilds a change event from its original
|
|
990
|
+
* submission inputs. Reporting the names here lets the DO read the final
|
|
991
|
+
* post-hook values back and thread them into `appliedFields` so the caller
|
|
992
|
+
* can propagate them (#1476). The hook contract stays generic — it names the
|
|
993
|
+
* fields it applied and does not need to know how the caller uses them.
|
|
994
|
+
*/
|
|
995
|
+
serverAppliedFieldNames?: string[];
|
|
984
996
|
}
|
|
985
997
|
/** Result from beforeQuery hooks — can inject additional filters */
|
|
986
998
|
interface BeforeQueryResult extends HookResult {
|
|
@@ -1107,6 +1119,20 @@ interface QueryResponse {
|
|
|
1107
1119
|
interface SaveResponse {
|
|
1108
1120
|
success: boolean;
|
|
1109
1121
|
id: string;
|
|
1122
|
+
/**
|
|
1123
|
+
* Server-applied field values the DO wrote AFTER the caller's submission
|
|
1124
|
+
* inputs were assembled, read back from the final post-hook `data`
|
|
1125
|
+
* (#1476, consolidating the #1462 `stamps` channel). This is the single
|
|
1126
|
+
* "server-applied fields" channel: it carries both the applied `autoStamps`
|
|
1127
|
+
* timestamps and any fields a `beforeSave` hook reported via
|
|
1128
|
+
* `serverAppliedFieldNames` (e.g. app-level trigger-computed values). Present
|
|
1129
|
+
* only when at least one such field ended up with a value. Lets the Worker
|
|
1130
|
+
* thread these values into the change-event `data` it broadcasts to
|
|
1131
|
+
* subscribers — otherwise a `select`-listed stamped or trigger-computed field
|
|
1132
|
+
* never reaches the frame, because the frame is rebuilt from the submission
|
|
1133
|
+
* inputs (which predate the DO-side write).
|
|
1134
|
+
*/
|
|
1135
|
+
appliedFields?: Record<string, any>;
|
|
1110
1136
|
}
|
|
1111
1137
|
interface DeleteResponse {
|
|
1112
1138
|
success: boolean;
|
|
@@ -1189,6 +1215,8 @@ interface PatchRequest {
|
|
|
1189
1215
|
interface PatchResponse {
|
|
1190
1216
|
success: boolean;
|
|
1191
1217
|
id: string;
|
|
1218
|
+
/** Server-applied field values (#1476). See `SaveResponse.appliedFields`. */
|
|
1219
|
+
appliedFields?: Record<string, any>;
|
|
1192
1220
|
}
|
|
1193
1221
|
interface BatchOperation {
|
|
1194
1222
|
op: "save" | "patch" | "delete" | "increment" | "addToSet" | "removeFromSet";
|
|
@@ -1216,12 +1244,46 @@ interface BatchOperation {
|
|
|
1216
1244
|
}
|
|
1217
1245
|
interface BatchRequest {
|
|
1218
1246
|
operations: BatchOperation[];
|
|
1247
|
+
/**
|
|
1248
|
+
* All-or-nothing execution (#1478). When `true`, the FIRST operation that
|
|
1249
|
+
* fails inside the transaction — hook denial, condition / `ifNotExists` /
|
|
1250
|
+
* unique violation, record-not-found, or upsert validation error — aborts
|
|
1251
|
+
* the whole batch: every write is rolled back and the handler returns an
|
|
1252
|
+
* error naming the failed step with its natural HTTP status (see
|
|
1253
|
+
* `BatchOperationResult.status`). When `false` or absent (the default), each
|
|
1254
|
+
* operation's outcome is recorded independently and successful siblings
|
|
1255
|
+
* commit — the partial-success behavior import-bulk and applyToQuery rely on.
|
|
1256
|
+
*/
|
|
1257
|
+
atomic?: boolean;
|
|
1219
1258
|
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Stable, machine-readable failure tag on a failed `BatchOperationResult`
|
|
1261
|
+
* (#1478). Derived at each failure site — never inferred from the `error`
|
|
1262
|
+
* string. `#1389` (conditional writes + fencing-token enforcement) surfaces its
|
|
1263
|
+
* condition / stale-token rejections through this same channel.
|
|
1264
|
+
*/
|
|
1265
|
+
type BatchFailureCode = "NOT_FOUND" | "HOOK_DENIED" | "CONDITION_NOT_MET" | "ALREADY_EXISTS" | "UNIQUE_VIOLATION" | "VALIDATION_ERROR";
|
|
1220
1266
|
interface BatchOperationResult {
|
|
1221
1267
|
success: boolean;
|
|
1222
1268
|
id: string;
|
|
1223
1269
|
error?: string;
|
|
1270
|
+
/**
|
|
1271
|
+
* Structured failure metadata (#1478), present only on a failed result. Both
|
|
1272
|
+
* are derived at the failure site, not parsed back out of `error`:
|
|
1273
|
+
* - `status` — the natural HTTP status for the cause (404 not found,
|
|
1274
|
+
* 403 hook denial, 409 condition / `ifNotExists` / unique conflict,
|
|
1275
|
+
* 400 upsert validation).
|
|
1276
|
+
* - `code` — a stable machine-readable tag (see `BatchFailureCode`).
|
|
1277
|
+
*
|
|
1278
|
+
* In atomic mode the handler reads the first failure's `status`/`code` to
|
|
1279
|
+
* build the error response, so an increment-on-missing op keeps its 404 and a
|
|
1280
|
+
* hook denial keeps its 403 instead of collapsing to a uniform 409.
|
|
1281
|
+
*/
|
|
1282
|
+
status?: number;
|
|
1283
|
+
code?: BatchFailureCode;
|
|
1224
1284
|
values?: Record<string, number>;
|
|
1285
|
+
/** Server-applied field values (#1476). See `SaveResponse.appliedFields`. */
|
|
1286
|
+
appliedFields?: Record<string, any>;
|
|
1225
1287
|
}
|
|
1226
1288
|
interface BatchResponse {
|
|
1227
1289
|
results: BatchOperationResult[];
|
|
@@ -1453,6 +1515,33 @@ declare function createDatabaseDO(config?: DatabaseDOConfig): {
|
|
|
1453
1515
|
*/
|
|
1454
1516
|
declare const createDocumentDO: typeof createDatabaseDO;
|
|
1455
1517
|
|
|
1518
|
+
/**
|
|
1519
|
+
* Decoding for rows read out of the schemaless `records` table.
|
|
1520
|
+
*
|
|
1521
|
+
* A `SELECT` built by `JsonQueryTranslator` comes back in one of two shapes:
|
|
1522
|
+
* the whole record (`_id`, `_type`, `_data`), or — under an inclusion
|
|
1523
|
+
* projection — one column per projected field. Both shapes are turned back
|
|
1524
|
+
* into a record object here, so every reader of the store (the DatabaseDO's
|
|
1525
|
+
* query/get paths, the per-document SQLite projection) hands callers the same
|
|
1526
|
+
* values for the same stored record.
|
|
1527
|
+
*/
|
|
1528
|
+
/**
|
|
1529
|
+
* Column-alias prefix for a projected field whose value is selected as JSON
|
|
1530
|
+
* text. The prefix marks the column as still-encoded so
|
|
1531
|
+
* {@link parseRecordRow} knows to decode it; field names cannot start with
|
|
1532
|
+
* `_` (the write path rejects them as reserved), so the prefix can never
|
|
1533
|
+
* collide with a real field.
|
|
1534
|
+
*/
|
|
1535
|
+
declare const PROJECTED_JSON_ALIAS_PREFIX = "_json_";
|
|
1536
|
+
/** Column alias under which a projected field's JSON text is selected. */
|
|
1537
|
+
declare function projectedJsonAlias(fieldName: string): string;
|
|
1538
|
+
/**
|
|
1539
|
+
* Decode one row of a `records` SELECT into a record object: `_id`/`_type`
|
|
1540
|
+
* become `id`/`type`, `_data` is parsed when present, and any projected
|
|
1541
|
+
* column is decoded back to its stored value.
|
|
1542
|
+
*/
|
|
1543
|
+
declare function parseRecordRow(row: Record<string, any>): Record<string, any>;
|
|
1544
|
+
|
|
1456
1545
|
/**
|
|
1457
1546
|
* Cloudflare Worker Router Template
|
|
1458
1547
|
*
|
|
@@ -1919,6 +2008,27 @@ declare class BaseModel implements StringSetChangeTracker {
|
|
|
1919
2008
|
*/
|
|
1920
2009
|
static count(this: new (...args: any[]) => any, filter?: DocumentFilter, options?: Pick<QueryOptions, "documents">): Promise<number>;
|
|
1921
2010
|
static findAll<T extends BaseModel>(this: new (...args: any[]) => T): Promise<T[]>;
|
|
2011
|
+
/**
|
|
2012
|
+
* Resolve a record by its unique-constraint field values via an engine query.
|
|
2013
|
+
* Used as a fallback when the `_uniqueIdx_<model>_<constraint>` map has no
|
|
2014
|
+
* entry for a key.
|
|
2015
|
+
*
|
|
2016
|
+
* The index map is a cache over the SQLite projection, not the source of
|
|
2017
|
+
* truth: every record is loaded into the projection on `initializeForDocument`
|
|
2018
|
+
* regardless of index presence, but a record written by a client predating
|
|
2019
|
+
* index maintenance (legacy data) is missing from the index. Such a record
|
|
2020
|
+
* silently escapes both `upsertByUnique` lookups and the `save()` uniqueness
|
|
2021
|
+
* check. A query over the constraint fields finds it reliably.
|
|
2022
|
+
*
|
|
2023
|
+
* Contract: RESOLVE ONLY. Returns the owning record (with `_metaDocId` set to
|
|
2024
|
+
* the document that holds it, via `queryOne`) or `null`. Callers decide
|
|
2025
|
+
* whether to heal the missing index entry (write paths) and do their own
|
|
2026
|
+
* logging — this method never mutates the index, so read paths stay
|
|
2027
|
+
* read-only. Mirrors `buildUniqueKey`: a null/undefined value in any
|
|
2028
|
+
* constraint field means the record does not participate in the constraint,
|
|
2029
|
+
* so no query runs.
|
|
2030
|
+
*/
|
|
2031
|
+
private static _resolveByUniqueFallback;
|
|
1922
2032
|
static findByUnique<T extends BaseModel>(this: typeof BaseModel & (new (...args: any[]) => T), constraintName: string, value: any | any[]): Promise<T | null>;
|
|
1923
2033
|
static upsertByUnique<T extends BaseModel>(this: typeof BaseModel & (new (...args: any[]) => T), constraintName: string, uniqueLookupValue: any | any[], dataToUpsert: Partial<Omit<InstanceType<new (...args: any[]) => T>, keyof BaseModel | "toJSON">> & {
|
|
1924
2034
|
id?: string;
|
|
@@ -2067,4 +2177,4 @@ declare function deterministicIdentifierHash(value: string): string;
|
|
|
2067
2177
|
*/
|
|
2068
2178
|
declare function buildSafeAlias(prefix: string, rawDescriptor: string): string;
|
|
2069
2179
|
|
|
2070
|
-
export { type AfterQueryContext, type AfterQueryResult, type AggregateRequest, type AggregateResponse, type AggregationOperation$1 as AggregationOperation, type AggregationOptions$1 as AggregationOptions, type AggregationResult$1 as AggregationResult, type BatchOperation, type BatchOperationResult, type BatchRequest, type BatchResponse, type BeforeDeleteContext, type BeforeQueryContext, type BeforeQueryResult, type BeforeSaveContext, type CountRequest, type CountResponse, type DatabaseDOConfig, type DatabaseDOHooks, type DeleteRequest, type DeleteResponse, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type DocumentDOConfig, type DropIndexRequest, type DropIndexResponse, type DropUniqueConstraintRequest, type DropUniqueConstraintResponse, DurableObjectEngine, type DurableObjectEngineOptions, type DurableObjectId, type DurableObjectNamespace, type DurableObjectState, type DurableObjectStorage, type DurableObjectStub, type Env, type ErrorResponse, type GroupByField$1 as GroupByField, type HookContext, type HookResult, type IncrementRequest, type IncrementResponse, type IndexEntry, type IndexListResponse, JsonQueryTranslator, type JsonQueryTranslatorOptions, JsonSchemaDDL, type JsonSchemaOptions, type PatchRequest, type PatchResponse, type QueryRequest, type QueryResponse, type RegisterIndexRequest, type RegisterIndexResponse, type RegisterUniqueConstraintRequest, type RegisterUniqueConstraintResponse, type SaveRequest, type SaveResponse, type SchemaConstraintInfo, type SchemaFieldInfo, type SchemaModelInfo, type SchemaResponse, type SqlStorage, type SqlStorageCursor, type StringSetMembership$1 as StringSetMembership, type StringSetUpdateRequest, type StringSetUpdateResponse, type SyncIndexesRequest, type SyncIndexesResponse, type UniqueConstraintEntry, type UniqueConstraintListResponse, buildSafeAlias, checkAutoStampsReservedFields, checkReservedFieldName, clearMetaSyncCache, createDatabaseDO, createDocumentDO, deterministicIdentifierHash, discoverModelNames, discoverSchema, handleRequest, inferFieldType, loadSchemaFromTomlString, registerFunctionDefault, schemaToToml, syncInferredMeta, syncModelMeta };
|
|
2180
|
+
export { type AfterQueryContext, type AfterQueryResult, type AggregateRequest, type AggregateResponse, type AggregationOperation$1 as AggregationOperation, type AggregationOptions$1 as AggregationOptions, type AggregationResult$1 as AggregationResult, type BatchOperation, type BatchOperationResult, type BatchRequest, type BatchResponse, type BeforeDeleteContext, type BeforeQueryContext, type BeforeQueryResult, type BeforeSaveContext, type CountRequest, type CountResponse, type DatabaseDOConfig, type DatabaseDOHooks, type DeleteRequest, type DeleteResponse, type DiscoveredConstraint, type DiscoveredField, type DiscoveredModel, type DiscoveredRelationship, type DiscoveredSchema, type DocumentDOConfig, type DropIndexRequest, type DropIndexResponse, type DropUniqueConstraintRequest, type DropUniqueConstraintResponse, DurableObjectEngine, type DurableObjectEngineOptions, type DurableObjectId, type DurableObjectNamespace, type DurableObjectState, type DurableObjectStorage, type DurableObjectStub, type Env, type ErrorResponse, type GroupByField$1 as GroupByField, type HookContext, type HookResult, type IncrementRequest, type IncrementResponse, type IndexEntry, type IndexListResponse, JsonQueryTranslator, type JsonQueryTranslatorOptions, JsonSchemaDDL, type JsonSchemaOptions, PROJECTED_JSON_ALIAS_PREFIX, type PatchRequest, type PatchResponse, type QueryRequest, type QueryResponse, type RegisterIndexRequest, type RegisterIndexResponse, type RegisterUniqueConstraintRequest, type RegisterUniqueConstraintResponse, type SaveRequest, type SaveResponse, type SchemaConstraintInfo, type SchemaFieldInfo, type SchemaModelInfo, type SchemaResponse, type SqlStorage, type SqlStorageCursor, type StringSetMembership$1 as StringSetMembership, type StringSetUpdateRequest, type StringSetUpdateResponse, type SyncIndexesRequest, type SyncIndexesResponse, type UniqueConstraintEntry, type UniqueConstraintListResponse, buildSafeAlias, checkAutoStampsReservedFields, checkReservedFieldName, clearMetaSyncCache, createDatabaseDO, createDocumentDO, deterministicIdentifierHash, discoverModelNames, discoverSchema, handleRequest, inferFieldType, loadSchemaFromTomlString, parseRecordRow, projectedJsonAlias, registerFunctionDefault, schemaToToml, syncInferredMeta, syncModelMeta };
|