@minnowdb/core 0.7.8 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
+ import { type LiveQueryPatchOptions } from "./live-patch.js";
1
2
  import { type CompactionJobRecord, type GarbageCollectionJobRecord, type StorageIntegrityMode, type StorageIntegrityReport, type StorageStats, type InterruptedSnapshotImport, type InterruptedSnapshotImportAbortResult } from "../storage/types.js";
2
3
  import { type BatchRow } from "./batch.js";
3
4
  import type { Catalog } from "./catalog.js";
4
5
  import type { BufferPoolStats, StagedWriteResult, StagedUpsertResult, BufferedFlushResult, BufferedWriterOptions, CancelCompactionJobResult, CollectGarbageOptions, CollectGarbageStepOptions, CompactTableOptions, CompactTableResult, CompactTableStepOptions, CompactionJobProgress, CreateTableInput, MigrateOptions, DeleteBatchResult, ExecuteOptions, ExecuteResult, GarbageCollectionProgress, GarbageCollectionResult, MaintenanceStatus, InsertBatchResult, QueryOptions, QueryExecutionStats, QueryCursorOptions, QuerySpillCleanupOptions, QuerySpillCleanupResult, RunStatementOptions, SnapshotExportOptions, SnapshotImportOptions, TableDefinition, UpdateBatchResult, UpsertBatchResult, VisibleSegmentPage, VisibleSegmentPageOptions } from "./database.js";
5
- import type { LiveQueryInput, LiveQueryInvalidation, LiveQueryObserveOptions, LiveQueryStats, LiveQuerySubscribeOptions } from "./live.js";
6
+ import type { LiveQueryDelivery, LiveQueryInput, LiveQueryInvalidation, LiveQueryObserveOptions, LiveQueryStats, LiveQuerySubscribeOptions } from "./live.js";
6
7
  import type { CompiledQuery, CompiledStatement, QueryResult, QueryValue } from "./query.js";
7
8
  import type { AnySchema, UntypedSchema, AnyTable, BatchColumnName, BatchDeleteInput, BatchInsertInput, BatchInsertRow, BatchKeyValue, BatchReadOptions, BatchReadRow, BatchUpdateChanges, BatchUpdateInput, BatchUpsertOptions, SchemaDefinition, TableName } from "./schema.js";
8
9
  import { type WireMigrationStep } from "./schema-wire.js";
@@ -65,7 +66,7 @@ export interface ClientMigrationResult {
65
66
  steps: WireMigrationStep[];
66
67
  }
67
68
  interface EventRoute {
68
- onChange?: (result: QueryResult) => void;
69
+ onChange?: (result: QueryResult, delivery: LiveQueryDelivery) => void;
69
70
  onInvalidate?: (invalidation: LiveQueryInvalidation) => void;
70
71
  onError?: (error: unknown) => void;
71
72
  onComplete?: () => void;
@@ -264,6 +265,8 @@ export declare class ClientLiveQuerySet {
264
265
  constructor(client: MinnowDatabaseClient, handleId: string, created: Promise<unknown>);
265
266
  /** Registers a query (SQL or a compiled-plan envelope) and re-runs it on relevant changes. */
266
267
  subscribe(query: LiveQueryInput, options: LiveQuerySubscribeOptions): Promise<ClientLiveSubscription>;
268
+ /** Delivers changed row payloads; the worker transport still sends its result snapshot. */
269
+ subscribePatches(query: LiveQueryInput, options: LiveQueryPatchOptions): Promise<ClientLiveSubscription>;
267
270
  /** Registers dependency observation while leaving execution/result mapping to an adapter. */
268
271
  observe(query: LiveQueryInput, options: LiveQueryObserveOptions): Promise<ClientLiveSubscription>;
269
272
  stats(): Promise<LiveQueryStats>;
@@ -1,3 +1,4 @@
1
+ import { createLiveQueryPatch } from "./live-patch.js";
1
2
  import { BlockReadBatchTooLargeError, CompactionBacklogError, CompactionJobConflictError, GarbageCollectionJobConflictError, IndexedDbSchemaUpgradeBlockedError, LeaseConflictError, LeaseExpiredError, LeaseOwnerConflictError, PostingBuildConflictError, SnapshotManifestMissingError, SnapshotImportConflictError, SchemaConflictError, StorageResourceLimitError, TableInUseError, TableRecordConflictError, TempOwnerConflictError, TransactionRecordConflictError, UniqueKeyBuildConflictError, UniqueKeyConflictError, UniqueIndexCoverageError, WriteConflictError, StorageCorruptionError, StorageFormatVersionError, OpfsUncertainOutcomeError } from "../storage/types.js";
2
3
  import { MAX_SNAPSHOT_STREAM_CHUNK_BYTES } from "../storage/snapshot.js";
3
4
  import { parseRpcResponse, MAX_DATABASE_RPC_IN_FLIGHT, protocolVersion } from "../worker-protocol/index.js";
@@ -556,9 +557,10 @@ class MinnowDatabaseClient {
556
557
  const route = this.#events.get(response.handleId);
557
558
  if (route === void 0)
558
559
  return;
559
- if (response.event === "change")
560
- route.onChange?.(decodeQueryResult(response.payload));
561
- else if (response.event === "invalidate") {
560
+ if (response.event === "change") {
561
+ const { result, delivery } = response.payload;
562
+ route.onChange?.(decodeQueryResult(result), delivery);
563
+ } else if (response.event === "invalidate") {
562
564
  route.onInvalidate?.(response.payload);
563
565
  } else if (response.event === "error") {
564
566
  route.onError?.(rehydrateResponseError(response.payload));
@@ -682,6 +684,13 @@ class ClientLiveQuerySet {
682
684
  throw error;
683
685
  }
684
686
  }
687
+ subscribePatches(query, options) {
688
+ return this.subscribe(query, {
689
+ onChange: (result, delivery) => options.onPatch(createLiveQueryPatch(result, delivery), delivery),
690
+ ...options.onError === void 0 ? {} : { onError: options.onError.bind(options) },
691
+ ...options.onComplete === void 0 ? {} : { onComplete: options.onComplete.bind(options) }
692
+ });
693
+ }
685
694
  async observe(query, options) {
686
695
  await this.#created;
687
696
  const subscriptionId = crypto.randomUUID();
@@ -698,7 +707,8 @@ class ClientLiveQuerySet {
698
707
  try {
699
708
  const created = await this.client._invoke(this.handleId, "observe", [
700
709
  subscriptionId,
701
- query
710
+ query,
711
+ { suppressUnchanged: options.suppressUnchanged === true }
702
712
  ]);
703
713
  this.#subscriptionIds.add(subscriptionId);
704
714
  return new ClientLiveSubscription(this.client, subscriptionId, created.dependencyTableIds, () => this.#subscriptionIds.delete(subscriptionId), state);