Skip to content

Docs interfaces #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { themes as prismThemes } from 'prism-react-renderer';
import type { TypeDocOptionMap } from 'typedoc';
import type { Config } from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
import type { Config } from '@docusaurus/types';
import type { PluginOptions } from 'docusaurus-plugin-typedoc';
import { DOC_FOLDER, packageMap } from './utils/packageMap';
import 'dotenv/config';
import { themes as prismThemes } from 'prism-react-renderer';
import type { TypeDocOptionMap } from 'typedoc';
import { DOC_FOLDER, packageMap } from './utils/packageMap';

const PROJECT_NAME = process.env.GH_PROJECT_NAME;

Expand All @@ -21,12 +21,13 @@ const plugins = Object.entries(packageMap).map(([id, config]) => [
enumMembersFormat: 'table',
excludeProtected: true,
excludePrivate: true,
excludeInternal: true,
indexFormat: 'table',
disableSources: true,
expandObjects: true,
useCodeBlocks: true,
typeDeclarationFormat: 'table',
membersWithOwnFile: ['Class', 'Enum', 'Function'],
membersWithOwnFile: ['Class', 'Enum', 'Function', 'Interface'],
textContentMappings: {
'title.memberPage': '{name}'
}
Expand Down Expand Up @@ -155,8 +156,8 @@ const config: Config = {
darkTheme: prismThemes.dracula
},
future: {
experimental_faster: true,
},
experimental_faster: true
}
} satisfies Preset.ThemeConfig
};

Expand Down
36 changes: 36 additions & 0 deletions packages/common/src/client/sync/bucket/BucketStorageAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,64 @@ import { CrudBatch } from './CrudBatch.js';
import { CrudEntry, OpId } from './CrudEntry.js';
import { SyncDataBatch } from './SyncDataBatch.js';

/**
* @internal
*/
export interface BucketDescription {
name: string;
priority: number;
}

/**
* @internal
*/
export interface Checkpoint {
last_op_id: OpId;
buckets: BucketChecksum[];
write_checkpoint?: string;
}

/**
* @internal
*/
export interface BucketState {
bucket: string;
op_id: string;
}

/**
* @internal
*/
export interface ChecksumCache {
checksums: Map<string, { checksum: BucketChecksum; last_op_id: OpId }>;
lastOpId: OpId;
}

/**
* @internal
*/
export interface SyncLocalDatabaseResult {
ready: boolean;
checkpointValid: boolean;
checkpointFailures?: string[];
}

/**
* @internal
*/
export type SavedProgress = {
atLast: number;
sinceLast: number;
};

/**
* @internal
*/
export type BucketOperationProgress = Record<string, SavedProgress>;

/**
* @internal
*/
export interface BucketChecksum {
bucket: string;
priority?: number;
Expand All @@ -51,6 +75,9 @@ export interface BucketChecksum {
count?: number;
}

/**
* @internal
*/
export enum PSInternalTable {
DATA = 'ps_data',
CRUD = 'ps_crud',
Expand All @@ -59,6 +86,9 @@ export enum PSInternalTable {
UNTYPED = 'ps_untyped'
}

/**
* @internal
*/
export enum PowerSyncControlCommand {
PROCESS_TEXT_LINE = 'line_text',
PROCESS_BSON_LINE = 'line_binary',
Expand All @@ -68,10 +98,16 @@ export enum PowerSyncControlCommand {
NOTIFY_CRUD_UPLOAD_COMPLETED = 'completed_upload'
}

/**
* @internal
*/
export interface BucketStorageListener extends BaseListener {
crudUpdate: () => void;
}

/**
* @internal
*/
export interface BucketStorageAdapter extends BaseObserver<BucketStorageListener>, Disposable {
init(): Promise<void>;
saveSyncData(batch: SyncDataBatch, fixedKeyFormat?: boolean): Promise<void>;
Expand Down
7 changes: 7 additions & 0 deletions packages/common/src/client/sync/bucket/OpType.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
/**
* @internal
*/
export enum OpTypeEnum {
CLEAR = 1,
MOVE = 2,
PUT = 3,
REMOVE = 4
}

/**
* @internal
*/
export type OpTypeJSON = string;

/**
* Used internally for sync buckets.
* @internal
*/
export class OpType {
static fromJSON(jsonValue: OpTypeJSON) {
Expand Down
6 changes: 6 additions & 0 deletions packages/common/src/client/sync/bucket/OplogEntry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { OpId } from './CrudEntry.js';
import { OpType, OpTypeJSON } from './OpType.js';

/**
* @internal
*/
export interface OplogEntryJSON {
checksum: number;
data?: string;
Expand All @@ -11,6 +14,9 @@ export interface OplogEntryJSON {
subkey?: string;
}

/**
* @internal
*/
export class OplogEntry {
static fromRow(row: OplogEntryJSON) {
return new OplogEntry(
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/client/sync/bucket/SqliteBucketStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { CrudBatch } from './CrudBatch.js';
import { CrudEntry, CrudEntryJSON } from './CrudEntry.js';
import { SyncDataBatch } from './SyncDataBatch.js';

/**
* @internal
*/
export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> implements BucketStorageAdapter {
public tableNames: Set<string>;
private _hasCompletedSync: boolean;
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/client/sync/bucket/SyncDataBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { SyncDataBucket } from './SyncDataBucket.js';

// TODO JSON

/**
* @internal
*/
export class SyncDataBatch {
static fromJSON(json: any) {
return new SyncDataBatch(json.buckets.map((bucket: any) => SyncDataBucket.fromRow(bucket)));
Expand Down
6 changes: 6 additions & 0 deletions packages/common/src/client/sync/bucket/SyncDataBucket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { OpId } from './CrudEntry.js';
import { OplogEntry, OplogEntryJSON } from './OplogEntry.js';

/**
* @internal
*/
export type SyncDataBucketJSON = {
bucket: string;
has_more?: boolean;
Expand All @@ -9,6 +12,9 @@ export type SyncDataBucketJSON = {
data: OplogEntryJSON[];
};

/**
* @internal
*/
export class SyncDataBucket {
static fromRow(row: SyncDataBucketJSON) {
return new SyncDataBucket(
Expand Down
22 changes: 17 additions & 5 deletions packages/common/src/client/sync/stream/AbstractRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import PACKAGE from '../../../../package.json' with { type: 'json' };
import { AbortOperation } from '../../../utils/AbortOperation.js';
import { DataStream } from '../../../utils/DataStream.js';
import { PowerSyncCredentials } from '../../connection/PowerSyncCredentials.js';
import {
StreamingSyncLine,
StreamingSyncLineOrCrudUploadComplete,
StreamingSyncRequest
} from './streaming-sync-types.js';
import { StreamingSyncRequest } from './streaming-sync-types.js';
import { WebsocketClientTransport } from './WebsocketClientTransport.js';

/**
* @internal
*/
export type BSONImplementation = typeof BSON;

/**
* @internal
*/
export type RemoteConnector = {
fetchCredentials: () => Promise<PowerSyncCredentials | null>;
invalidateCredentials?: () => void;
Expand All @@ -39,6 +41,9 @@ const KEEP_ALIVE_LIFETIME_MS = 90_000;

export const DEFAULT_REMOTE_LOGGER = Logger.get('PowerSyncRemote');

/**
* @internal
*/
export type SyncStreamOptions = {
path: string;
data: StreamingSyncRequest;
Expand All @@ -65,20 +70,27 @@ export type SocketSyncStreamOptions = SyncStreamOptions & {
fetchStrategy: FetchStrategy;
};

/**
* @internal
*/
export type FetchImplementation = typeof fetch;

/**
* Class wrapper for providing a fetch implementation.
* The class wrapper is used to distinguish the fetchImplementation
* option in [AbstractRemoteOptions] from the general fetch method
* which is typeof "function"
* @internal
*/
export class FetchImplementationProvider {
getFetch(): FetchImplementation {
throw new Error('Unspecified fetch implementation');
}
}

/**
* @internal
*/
export type AbstractRemoteOptions = {
/**
* Transforms the PowerSync base URL which might contain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Logger, { ILogger } from 'js-logger';

import { DataStream } from '../../../utils/DataStream.js';
import { SyncStatus, SyncStatusOptions } from '../../../db/crud/SyncStatus.js';
import { FULL_SYNC_PRIORITY, InternalProgressInformation } from '../../../db/crud/SyncProgress.js';
import * as sync_status from '../../../db/crud/SyncStatus.js';
import { SyncStatus, SyncStatusOptions } from '../../../db/crud/SyncStatus.js';
import { AbortOperation } from '../../../utils/AbortOperation.js';
import { BaseListener, BaseObserver, Disposable } from '../../../utils/BaseObserver.js';
import { DataStream } from '../../../utils/DataStream.js';
import { throttleLeadingTrailing } from '../../../utils/async.js';
import {
BucketChecksum,
Expand All @@ -17,6 +17,7 @@ import {
import { CrudEntry } from '../bucket/CrudEntry.js';
import { SyncDataBucket } from '../bucket/SyncDataBucket.js';
import { AbstractRemote, FetchStrategy, SyncStreamOptions } from './AbstractRemote.js';
import { EstablishSyncStream, Instruction, SyncPriorityStatus } from './core-instruction.js';
import {
BucketRequest,
CrudUploadNotification,
Expand All @@ -30,8 +31,10 @@ import {
isStreamingSyncCheckpointPartiallyComplete,
isStreamingSyncData
} from './streaming-sync-types.js';
import { EstablishSyncStream, Instruction, SyncPriorityStatus } from './core-instruction.js';

/**
* @internal
*/
export enum LockType {
CRUD = 'crud',
SYNC = 'sync'
Expand Down Expand Up @@ -88,13 +91,18 @@ export const DEFAULT_SYNC_CLIENT_IMPLEMENTATION = SyncClientImplementation.JAVAS

/**
* Abstract Lock to be implemented by various JS environments
*
* @internal
*/
export interface LockOptions<T> {
callback: () => Promise<T>;
type: LockType;
signal?: AbortSignal;
}

/**
* @internal
*/
export interface AbstractStreamingSyncImplementationOptions extends AdditionalConnectionOptions {
adapter: BucketStorageAdapter;
uploadCrud: () => Promise<void>;
Expand Down Expand Up @@ -125,6 +133,9 @@ export interface StreamingSyncImplementationListener extends BaseListener {
*/
export type PowerSyncConnectionOptions = Omit<InternalConnectionOptions, 'serializedSchema'>;

/**
* @internal
*/
export interface InternalConnectionOptions extends BaseConnectionOptions, AdditionalConnectionOptions {}

/** @internal */
Expand Down Expand Up @@ -208,6 +219,9 @@ export const DEFAULT_STREAMING_SYNC_OPTIONS = {
crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
};

/**
* @internal
*/
export type RequiredPowerSyncConnectionOptions = Required<BaseConnectionOptions>;

export const DEFAULT_STREAM_CONNECTION_OPTIONS: RequiredPowerSyncConnectionOptions = {
Expand Down
Loading