Skip to content

Commit 829ce64

Browse files
More doc cleanup
1 parent 7030117 commit 829ce64

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed

packages/powersync-db-collection/src/PendingOperationStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type PendingOperation = {
1313
* Optimistic mutations have their optimistic state discarded once transactions have
1414
* been applied.
1515
* We need to ensure that an applied transaction has been observed by the sync diff trigger
16-
* before resoling the transaction application call.
16+
* before resolving the transaction application call.
1717
* This store allows registering a wait for a pending operation to have been observed.
1818
*/
1919
export class PendingOperationStore {

packages/powersync-db-collection/src/PowerSyncTransactor.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { sanitizeSQL } from "@powersync/common"
22
import DebugModule from "debug"
3-
import { PendingOperationStore } from "./PendingOperationStore"
43
import { asPowerSyncRecord, mapOperationToPowerSync } from "./helpers"
4+
import { PendingOperationStore } from "./PendingOperationStore"
5+
import type { AbstractPowerSyncDatabase, LockContext } from "@powersync/common"
6+
import type { PendingMutation, Transaction } from "@tanstack/db"
57
import type { EnhancedPowerSyncCollectionConfig } from "./definitions"
68
import type { PendingOperation } from "./PendingOperationStore"
7-
import type { PendingMutation, Transaction } from "@tanstack/db"
8-
import type { AbstractPowerSyncDatabase, LockContext } from "@powersync/common"
99

1010
const debug = DebugModule.debug(`ts/db:powersync`)
1111

@@ -29,16 +29,16 @@ export type TransactorOptions = {
2929
* )
3030
*
3131
* const addTx = createTransaction({
32-
* autoCommit: false,
33-
* mutationFn: async ({ transaction }) => {
34-
* await new PowerSyncTransactor({database: db}).applyTransaction(transaction)
35-
* },
32+
* autoCommit: false,
33+
* mutationFn: async ({ transaction }) => {
34+
* await new PowerSyncTransactor({ database: db }).applyTransaction(transaction)
35+
* },
3636
* })
3737
*
3838
* addTx.mutate(() => {
39-
* for (let i = 0; i < 5; i++) {
40-
* collection.insert({ id: randomUUID(), name: `tx-${i}` })
41-
* }
39+
* for (let i = 0; i < 5; i++) {
40+
* collection.insert({ id: randomUUID(), name: `tx-${i}` })
41+
* }
4242
* })
4343
*
4444
* await addTx.commit()
@@ -58,7 +58,7 @@ export class PowerSyncTransactor<T extends object = Record<string, unknown>> {
5858
}
5959

6060
/**
61-
* Persists a {@link Transaction} to PowerSync's SQLite DB.
61+
* Persists a {@link Transaction} to the PowerSync SQLite database.
6262
*/
6363
async applyTransaction(transaction: Transaction<T>) {
6464
const { mutations } = transaction
@@ -67,8 +67,8 @@ export class PowerSyncTransactor<T extends object = Record<string, unknown>> {
6767
return
6868
}
6969
/**
70-
* The transaction might contain ops for different collections.
71-
* We can do some optimizations for single collection transactions.
70+
* The transaction might contain operations for different collections.
71+
* We can do some optimizations for single-collection transactions.
7272
*/
7373
const mutationsCollectionIds = mutations.map(
7474
(mutation) => mutation.collection.id
@@ -103,7 +103,7 @@ export class PowerSyncTransactor<T extends object = Record<string, unknown>> {
103103
for (const [index, mutation] of mutations.entries()) {
104104
/**
105105
* Each collection processes events independently. We need to make sure the
106-
* last operation for each collection has been seen.
106+
* last operation for each collection has been observed.
107107
*/
108108
const shouldWait =
109109
index == lastCollectionMutationIndexes.get(mutation.collection.id)
@@ -130,7 +130,7 @@ export class PowerSyncTransactor<T extends object = Record<string, unknown>> {
130130
* Return a promise from the writeTransaction, without awaiting it.
131131
* This promise will resolve once the entire transaction has been
132132
* observed via the diff triggers.
133-
* We return without awaiting in order to free the writeLock.
133+
* We return without awaiting in order to free the write lock.
134134
*/
135135
return {
136136
whenComplete: Promise.all(
@@ -231,7 +231,7 @@ export class PowerSyncTransactor<T extends object = Record<string, unknown>> {
231231
* Helper function which wraps a persistence operation by:
232232
* - Fetching the mutation's collection's SQLite table details
233233
* - Executing the mutation
234-
* - Returning the last pending diff op if required
234+
* - Returning the last pending diff operation if required
235235
*/
236236
protected async handleOperationWithCompletion(
237237
mutation: PendingMutation<T>,

packages/powersync-db-collection/src/definitions.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import type { BaseCollectionConfig, CollectionConfig } from "@tanstack/db"
44
import type { ExtractedTable } from "./helpers"
55

66
/**
7-
* Configuration interface for PowerSync collection options
7+
* Configuration interface for PowerSync collection options.
88
* @template TTable - The PowerSync table schema definition
9-
* @template TSchema - The schema type for validation
9+
* @template TSchema - The validation schema type
1010
*/
1111
/**
1212
* Configuration options for creating a PowerSync collection.
@@ -41,7 +41,7 @@ export type PowerSyncCollectionConfig<
4141
BaseCollectionConfig<ExtractedTable<TTable>, string, TSchema>,
4242
`onInsert` | `onUpdate` | `onDelete` | `getKey`
4343
> & {
44-
/** The PowerSync Schema Table definition */
44+
/** The PowerSync schema Table definition */
4545
table: TTable
4646
/** The PowerSync database instance */
4747
database: AbstractPowerSyncDatabase
@@ -61,21 +61,21 @@ export type PowerSyncCollectionConfig<
6161
}
6262

6363
/**
64-
* Meta data for the PowerSync Collection
64+
* Metadata for the PowerSync Collection.
6565
*/
6666
export type PowerSyncCollectionMeta = {
6767
/**
6868
* The SQLite table representing the collection.
6969
*/
7070
tableName: string
7171
/**
72-
* The internal table used to track diff for the collection.
72+
* The internal table used to track diffs for the collection.
7373
*/
7474
trackedTableName: string
7575
}
7676

7777
/**
78-
* A CollectionConfig which includes utilities for PowerSync
78+
* A CollectionConfig which includes utilities for PowerSync.
7979
*/
8080
export type EnhancedPowerSyncCollectionConfig<
8181
TTable extends Table = Table,
@@ -87,13 +87,13 @@ export type EnhancedPowerSyncCollectionConfig<
8787
}
8888

8989
/**
90-
* Collection level utilities for PowerSync
90+
* Collection-level utilities for PowerSync.
9191
*/
9292
export type PowerSyncCollectionUtils = {
9393
getMeta: () => PowerSyncCollectionMeta
9494
}
9595

9696
/**
97-
* Default value for {@link PowerSyncCollectionConfig#syncBatchSize}
97+
* Default value for {@link PowerSyncCollectionConfig#syncBatchSize}.
9898
*/
9999
export const DEFAULT_BATCH_SIZE = 1000

packages/powersync-db-collection/src/helpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import { DiffTriggerOperation } from "@powersync/common"
22
import type { ExtractColumnValueType, Table } from "@powersync/common"
33

44
/**
5-
* All PowerSync table records have a uuid `id` column.
5+
* All PowerSync table records include a UUID `id` column.
66
*/
77
export type PowerSyncRecord = {
88
id: string
99
[key: string]: unknown
1010
}
1111

1212
/**
13-
* Utility type: If T includes null, add undefined.
14-
* PowerSync records typically are typed as `string | null`, where insert
15-
* and update operations also allow not specifying a value at all (optional)
16-
* */
13+
* Utility type: If T includes null, also allow undefined (to support optional fields in insert/update operations).
14+
* PowerSync records are typically typed as `string | null`, where insert
15+
* and update operations may also allow not specifying a value at all (optional).
16+
*/
1717
type WithUndefinedIfNull<T> = null extends T ? T | undefined : T
1818
type OptionalIfUndefined<T> = {
1919
[K in keyof T as undefined extends T[K] ? K : never]?: T[K]

packages/powersync-db-collection/src/powersync.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import type { ExtractedTable } from "./helpers"
1616
import type { PendingOperation } from "./PendingOperationStore"
1717

1818
/**
19-
* Creates PowerSync collection options for use with a standard Collection
19+
* Creates PowerSync collection options for use with a standard Collection.
2020
*
21-
* @template TTable - The SQLite based typing
22-
* @template TSchema - The schema type for validation - optionally supports a custom input type
21+
* @template TTable - The SQLite-based typing
22+
* @template TSchema - The validation schema type (optionally supports a custom input type)
2323
* @param config - Configuration options for the PowerSync collection
2424
* @returns Collection options with utilities
2525
*/
@@ -66,7 +66,7 @@ export function powerSyncCollectionOptions<TTable extends Table = Table>(
6666
* ```typescript
6767
* import { z } from "zod"
6868
*
69-
* // The PowerSync SQLite Schema
69+
* // The PowerSync SQLite schema
7070
* const APP_SCHEMA = new Schema({
7171
* documents: new Table({
7272
* name: column.text,
@@ -76,8 +76,8 @@ export function powerSyncCollectionOptions<TTable extends Table = Table>(
7676
* // Advanced Zod validations. The output type of this schema
7777
* // is constrained to the SQLite schema of APP_SCHEMA
7878
* const schema = z.object({
79-
* id: z.string(),
80-
* name: z.string().min(3, { message: "Should be at least 3 characters" }).nullable(),
79+
* id: z.string(),
80+
* name: z.string().min(3, { message: "Should be at least 3 characters" }).nullable(),
8181
* })
8282
*
8383
* const collection = createCollection(
@@ -122,9 +122,9 @@ export function powerSyncCollectionOptions<
122122
// We can do basic runtime validations for columns if not explicit schema has been provided
123123
const schema = inputSchema ?? (convertTableToSchema(table) as TSchema)
124124
/**
125-
* The onInsert, onUpdate, onDelete handlers should only return
126-
* after we have written the changes to Tanstack DB.
127-
* We currently only write to Tanstack DB from a diff trigger.
125+
* The onInsert, onUpdate, and onDelete handlers should only return
126+
* after we have written the changes to TanStack DB.
127+
* We currently only write to TanStack DB from a diff trigger.
128128
* We wait for the diff trigger to observe the change,
129129
* and only then return from the on[X] handlers.
130130
* This ensures that when the transaction is reported as

packages/powersync-db-collection/src/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import type { ExtractedTable } from "./helpers"
88
* Creates a schema that validates the structure and types of table records
99
* according to the PowerSync table definition.
1010
*
11-
* @template TTable - The PowerSync schema typed Table definition
11+
* @template TTable - The PowerSync schema-typed Table definition
1212
* @param table - The PowerSync Table instance to convert
13-
* @returns A StandardSchemaV1 compatible schema with proper type validation
13+
* @returns A StandardSchemaV1-compatible schema with proper type validation
1414
*
1515
* @example
1616
* ```typescript

0 commit comments

Comments
 (0)