@syncular/client 0.1.3 → 0.2.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.
- package/README.md +227 -709
- package/dist/apply.d.ts +80 -0
- package/dist/apply.js +301 -0
- package/dist/blob.d.ts +127 -0
- package/dist/blob.js +201 -0
- package/dist/bun-database.d.ts +22 -0
- package/dist/bun-database.js +61 -0
- package/dist/client.d.ts +320 -69
- package/dist/client.js +1627 -163
- package/dist/content-type.d.ts +2 -0
- package/dist/content-type.js +2 -0
- package/dist/database.d.ts +35 -80
- package/dist/database.js +32 -947
- package/dist/encryption.d.ts +47 -0
- package/dist/encryption.js +75 -0
- package/dist/errors.d.ts +8 -22
- package/dist/errors.js +10 -207
- package/dist/http.d.ts +32 -0
- package/dist/http.js +196 -0
- package/dist/index.d.ts +28 -16
- package/dist/index.js +25 -12
- package/dist/invalidation.d.ts +69 -0
- package/dist/invalidation.js +84 -0
- package/dist/leader-lock.d.ts +28 -0
- package/dist/leader-lock.js +38 -0
- package/dist/multi-tab.d.ts +134 -0
- package/dist/multi-tab.js +399 -0
- package/dist/node-database.d.ts +41 -0
- package/dist/node-database.js +133 -0
- package/dist/outbox.d.ts +56 -0
- package/dist/outbox.js +140 -0
- package/dist/schema.d.ts +107 -0
- package/dist/schema.js +267 -0
- package/dist/state.d.ts +40 -0
- package/dist/state.js +77 -0
- package/dist/transport.d.ts +44 -0
- package/dist/transport.js +7 -0
- package/dist/wasm-database.d.ts +30 -0
- package/dist/wasm-database.js +170 -0
- package/dist/window.d.ts +64 -0
- package/dist/window.js +0 -0
- package/dist/worker-entry.d.ts +16 -2
- package/dist/worker-entry.js +300 -456
- package/dist/worker-host.d.ts +174 -0
- package/dist/worker-host.js +536 -0
- package/dist/worker-protocol.d.ts +173 -61
- package/dist/worker-protocol.js +7 -16
- package/package.json +45 -112
- package/src/apply.ts +435 -0
- package/src/blob.ts +333 -0
- package/src/bun-database.ts +75 -0
- package/src/client.ts +2247 -277
- package/src/content-type.ts +2 -0
- package/src/database.ts +63 -1389
- package/src/encryption.ts +123 -0
- package/src/errors.ts +11 -265
- package/src/http.ts +254 -0
- package/src/index.ts +25 -20
- package/src/invalidation.ts +128 -0
- package/src/leader-lock.ts +68 -0
- package/src/multi-tab.ts +550 -0
- package/src/node-database.ts +180 -0
- package/src/outbox.ts +206 -0
- package/src/schema.ts +397 -0
- package/src/state.ts +126 -0
- package/src/transport.ts +52 -0
- package/src/wasm-database.ts +279 -0
- package/src/window.ts +0 -0
- package/src/worker-entry.ts +391 -545
- package/src/worker-host.ts +800 -0
- package/src/worker-protocol.ts +204 -99
- package/dist/auth-leases.d.ts +0 -11
- package/dist/auth-leases.d.ts.map +0 -1
- package/dist/auth-leases.js +0 -140
- package/dist/auth-leases.js.map +0 -1
- package/dist/blob-limits.d.ts +0 -15
- package/dist/blob-limits.d.ts.map +0 -1
- package/dist/blob-limits.js +0 -66
- package/dist/blob-limits.js.map +0 -1
- package/dist/bridge-client.d.ts +0 -69
- package/dist/bridge-client.d.ts.map +0 -1
- package/dist/bridge-client.js +0 -282
- package/dist/bridge-client.js.map +0 -1
- package/dist/client-config.d.ts +0 -6
- package/dist/client-config.d.ts.map +0 -1
- package/dist/client-config.js +0 -18
- package/dist/client-config.js.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/command-history.d.ts +0 -35
- package/dist/command-history.d.ts.map +0 -1
- package/dist/command-history.js +0 -378
- package/dist/command-history.js.map +0 -1
- package/dist/console-diagnostics.d.ts +0 -33
- package/dist/console-diagnostics.d.ts.map +0 -1
- package/dist/console-diagnostics.js +0 -496
- package/dist/console-diagnostics.js.map +0 -1
- package/dist/crdt-yjs/index.d.ts +0 -4
- package/dist/crdt-yjs/index.d.ts.map +0 -1
- package/dist/crdt-yjs/index.js +0 -4
- package/dist/crdt-yjs/index.js.map +0 -1
- package/dist/crdt-yjs/webview-host-facade.d.ts +0 -126
- package/dist/crdt-yjs/webview-host-facade.d.ts.map +0 -1
- package/dist/crdt-yjs/webview-host-facade.js +0 -284
- package/dist/crdt-yjs/webview-host-facade.js.map +0 -1
- package/dist/crdt-yjs/yjs-document-field-adapter.d.ts +0 -153
- package/dist/crdt-yjs/yjs-document-field-adapter.d.ts.map +0 -1
- package/dist/crdt-yjs/yjs-document-field-adapter.js +0 -406
- package/dist/crdt-yjs/yjs-document-field-adapter.js.map +0 -1
- package/dist/crdt-yjs/yjs-prosemirror-bridge.d.ts +0 -73
- package/dist/crdt-yjs/yjs-prosemirror-bridge.d.ts.map +0 -1
- package/dist/crdt-yjs/yjs-prosemirror-bridge.js +0 -169
- package/dist/crdt-yjs/yjs-prosemirror-bridge.js.map +0 -1
- package/dist/database.d.ts.map +0 -1
- package/dist/database.js.map +0 -1
- package/dist/diagnostics.d.ts +0 -10
- package/dist/diagnostics.d.ts.map +0 -1
- package/dist/diagnostics.js +0 -83
- package/dist/diagnostics.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/generated-bridge.d.ts +0 -365
- package/dist/generated-bridge.d.ts.map +0 -1
- package/dist/generated-bridge.js +0 -250
- package/dist/generated-bridge.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mutations.d.ts +0 -72
- package/dist/mutations.d.ts.map +0 -1
- package/dist/mutations.js +0 -63
- package/dist/mutations.js.map +0 -1
- package/dist/network.d.ts +0 -3
- package/dist/network.d.ts.map +0 -1
- package/dist/network.js +0 -17
- package/dist/network.js.map +0 -1
- package/dist/react/index.d.ts +0 -169
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -628
- package/dist/react/index.js.map +0 -1
- package/dist/react-native/index.d.ts +0 -35
- package/dist/react-native/index.d.ts.map +0 -1
- package/dist/react-native/index.js +0 -49
- package/dist/react-native/index.js.map +0 -1
- package/dist/runtime-contract.d.ts +0 -13
- package/dist/runtime-contract.d.ts.map +0 -1
- package/dist/runtime-contract.js +0 -24
- package/dist/runtime-contract.js.map +0 -1
- package/dist/rust-client.d.ts +0 -106
- package/dist/rust-client.d.ts.map +0 -1
- package/dist/rust-client.js +0 -938
- package/dist/rust-client.js.map +0 -1
- package/dist/sentry.d.ts +0 -35
- package/dist/sentry.d.ts.map +0 -1
- package/dist/sentry.js +0 -155
- package/dist/sentry.js.map +0 -1
- package/dist/sql-safety.d.ts +0 -3
- package/dist/sql-safety.d.ts.map +0 -1
- package/dist/sql-safety.js +0 -62
- package/dist/sql-safety.js.map +0 -1
- package/dist/syncular-runtime-artifacts.json +0 -61
- package/dist/tauri/index.d.ts +0 -35
- package/dist/tauri/index.d.ts.map +0 -1
- package/dist/tauri/index.js +0 -114
- package/dist/tauri/index.js.map +0 -1
- package/dist/types.d.ts +0 -1096
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/wasm/.syncular-wasm-profile +0 -1
- package/dist/wasm/syncular-runtime-artifact.json +0 -21
- package/dist/wasm/syncular.d.ts +0 -207
- package/dist/wasm/syncular.js +0 -2341
- package/dist/wasm/syncular_bg.wasm +0 -0
- package/dist/wasm/syncular_bg.wasm.d.ts +0 -97
- package/dist/wasm-bindings/runtime-contract.d.ts +0 -22
- package/dist/wasm-bindings/runtime-contract.d.ts.map +0 -1
- package/dist/wasm-bindings/runtime-contract.js +0 -112
- package/dist/wasm-bindings/runtime-contract.js.map +0 -1
- package/dist/wasm-core/.syncular-wasm-profile +0 -1
- package/dist/wasm-core/syncular-runtime-artifact.json +0 -17
- package/dist/wasm-core/syncular.d.ts +0 -162
- package/dist/wasm-core/syncular.js +0 -1847
- package/dist/wasm-core/syncular_bg.wasm +0 -0
- package/dist/wasm-core/syncular_bg.wasm.d.ts +0 -77
- package/dist/wasm-perf/.syncular-wasm-profile +0 -1
- package/dist/wasm-perf/syncular-runtime-artifact.json +0 -21
- package/dist/wasm-perf/syncular.d.ts +0 -207
- package/dist/wasm-perf/syncular.js +0 -2341
- package/dist/wasm-perf/syncular_bg.wasm +0 -0
- package/dist/wasm-perf/syncular_bg.wasm.d.ts +0 -97
- package/dist/wasm-runtime.d.ts +0 -23
- package/dist/wasm-runtime.d.ts.map +0 -1
- package/dist/wasm-runtime.js +0 -69
- package/dist/wasm-runtime.js.map +0 -1
- package/dist/worker-client.d.ts +0 -123
- package/dist/worker-client.d.ts.map +0 -1
- package/dist/worker-client.js +0 -1735
- package/dist/worker-client.js.map +0 -1
- package/dist/worker-entry.d.ts.map +0 -1
- package/dist/worker-entry.js.map +0 -1
- package/dist/worker-protocol.d.ts.map +0 -1
- package/dist/worker-protocol.js.map +0 -1
- package/dist/worker-realtime.d.ts +0 -39
- package/dist/worker-realtime.d.ts.map +0 -1
- package/dist/worker-realtime.js +0 -677
- package/dist/worker-realtime.js.map +0 -1
- package/src/auth-leases.ts +0 -251
- package/src/blob-limits.ts +0 -98
- package/src/bridge-client.ts +0 -512
- package/src/client-config.ts +0 -29
- package/src/command-history.ts +0 -623
- package/src/console-diagnostics.ts +0 -617
- package/src/crdt-yjs/index.ts +0 -3
- package/src/crdt-yjs/webview-host-facade.ts +0 -477
- package/src/crdt-yjs/yjs-document-field-adapter.ts +0 -733
- package/src/crdt-yjs/yjs-prosemirror-bridge.ts +0 -272
- package/src/diagnostics.ts +0 -116
- package/src/generated-bridge.ts +0 -741
- package/src/mutations.ts +0 -168
- package/src/network.ts +0 -32
- package/src/react/index.ts +0 -1036
- package/src/react-native/index.ts +0 -152
- package/src/runtime-contract.ts +0 -48
- package/src/rust-client.ts +0 -1491
- package/src/sentry.ts +0 -215
- package/src/sql-safety.ts +0 -61
- package/src/tauri/index.ts +0 -211
- package/src/types.ts +0 -1397
- package/src/wasm-bindings/generated-wasm-bindings.d.ts +0 -70
- package/src/wasm-bindings/runtime-contract.ts +0 -158
- package/src/wasm-runtime.ts +0 -145
- package/src/worker-client.ts +0 -2289
- package/src/worker-realtime.ts +0 -843
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// @generated by packages/client/scripts/generate-wasm-bindings.ts
|
|
2
|
-
// Source: wasm-bindgen declarations in dist/wasm/syncular.d.ts
|
|
3
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: wasm-bindgen emits any for JsValue boundaries.
|
|
4
|
-
|
|
5
|
-
export class SyncularRustOwnedSqliteClient {
|
|
6
|
-
private constructor();
|
|
7
|
-
free(): void;
|
|
8
|
-
[Symbol.dispose](): void;
|
|
9
|
-
activeAuthLeasesJson(actor_id: string | null | undefined, now_ms: bigint): string;
|
|
10
|
-
applyCrdtFieldTextJson(request_json: string): string;
|
|
11
|
-
applyCrdtFieldYjsUpdateJson(request_json: string): string;
|
|
12
|
-
applyLeasedMutationJson(operation_json: string, local_row_json?: string | null): Promise<string>;
|
|
13
|
-
applyLeasedMutationsCommitJson(operations_json: string): string;
|
|
14
|
-
applyMutationJson(operation_json: string, local_row_json?: string | null): Promise<string>;
|
|
15
|
-
applyMutationsBatchJson(operations_json: string): string;
|
|
16
|
-
applyMutationsCommitJson(operations_json: string): string;
|
|
17
|
-
applyRealtimeSyncPackBytes(bytes: Uint8Array): Promise<string>;
|
|
18
|
-
applyYjsEnvelopeToPayloadJson(args_json: string): string;
|
|
19
|
-
applyYjsTextUpdatesJson(args_json: string): string;
|
|
20
|
-
authLeaseJson(lease_id: string): string;
|
|
21
|
-
blobCacheStatsJson(): string;
|
|
22
|
-
blobUploadQueueStatsJson(): string;
|
|
23
|
-
buildYjsTextUpdateJson(args_json: string): string;
|
|
24
|
-
clearBlobCache(): void;
|
|
25
|
-
close(): void;
|
|
26
|
-
compactCrdtFieldJson(request_json: string): string;
|
|
27
|
-
compactStorageJson(options_json: string): string;
|
|
28
|
-
conflictSummariesJson(): Promise<string>;
|
|
29
|
-
crdtDocumentSnapshotJson(request_json: string): string;
|
|
30
|
-
crdtUpdateLogJson(request_json: string): string;
|
|
31
|
-
drainLiveQueryEventsJson(): string;
|
|
32
|
-
drainRowsChangedEventsJson(): string;
|
|
33
|
-
encryptionHelperJson(method: string, args_json: string): string;
|
|
34
|
-
executeSqlValue(sql: string, params: any): any;
|
|
35
|
-
executeUnsafeSqlValue(sql: string, params: any): any;
|
|
36
|
-
exportLocalSupportBundleJson(): Promise<string>;
|
|
37
|
-
forceSubscriptionsBootstrapJson(subscription_ids_json: string): Promise<string>;
|
|
38
|
-
generatedSchemaStateJson(): string;
|
|
39
|
-
importLocalSupportBundleJson(bundle_json: string): Promise<string>;
|
|
40
|
-
isBlobLocal(hash: string): boolean;
|
|
41
|
-
listTableJson(table: string): Promise<string>;
|
|
42
|
-
liveQueryDiagnosticsJson(): string;
|
|
43
|
-
localHealthCheckJson(): Promise<string>;
|
|
44
|
-
materializeCrdtFieldJson(request_json: string): string;
|
|
45
|
-
openCrdtFieldJson(request_json: string): string;
|
|
46
|
-
processBlobUploadQueueJson(retry_now?: boolean | null): Promise<string>;
|
|
47
|
-
pruneBlobCache(max_bytes: bigint): bigint;
|
|
48
|
-
recoverSyncPushErrorJson(error_message: string): void;
|
|
49
|
-
repairLocalHealthJson(request_json: string): Promise<string>;
|
|
50
|
-
resetLocalSyncStateJson(request_json: string): Promise<string>;
|
|
51
|
-
resetTransportStats(): void;
|
|
52
|
-
resolveConflict(id: string, resolution: string): Promise<void>;
|
|
53
|
-
retrieveBlob(ref_json: string): Promise<Uint8Array>;
|
|
54
|
-
retryConflictKeepLocal(id: string): Promise<string>;
|
|
55
|
-
setAbortSignal(signal: any): void;
|
|
56
|
-
setAuthHeadersJson(headers_json: string): void;
|
|
57
|
-
setBlobEncryptionJson(config_json: string): void;
|
|
58
|
-
setEncryptedCrdtJson(config_json: string): void;
|
|
59
|
-
setFieldEncryptionJson(config_json: string): void;
|
|
60
|
-
setSubscriptionsJson(subscriptions_json: string): void;
|
|
61
|
-
snapshotCrdtFieldStateVectorJson(request_json: string): string;
|
|
62
|
-
storeBlobJson(data: Uint8Array, options_json: string): Promise<string>;
|
|
63
|
-
subscribeQueryJson(sql: string, params_json: string, tables_json: string, hints_json: string): string;
|
|
64
|
-
syncOnceJson(): Promise<string>;
|
|
65
|
-
syncPullJson(): Promise<string>;
|
|
66
|
-
syncPushJson(): Promise<string>;
|
|
67
|
-
transportStatsJson(): string;
|
|
68
|
-
unsubscribeQuery(id: string): void;
|
|
69
|
-
upsertAuthLeaseJson(lease_json: string): void;
|
|
70
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
export type { SyncularRustOwnedSqliteClient } from './generated-wasm-bindings';
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
SyncularRuntimeArtifact,
|
|
5
|
-
SyncularRuntimeArtifactCandidate,
|
|
6
|
-
SyncularRuntimeArtifactCatalog,
|
|
7
|
-
} from '../types';
|
|
8
|
-
|
|
9
|
-
export const SYNCULAR_CLIENT_PACKAGE_NAME = '@syncular/client';
|
|
10
|
-
export const SYNCULAR_CLIENT_PACKAGE_VERSION = '0.1.3';
|
|
11
|
-
export const SYNCULAR_WASM_OUT_NAME = 'syncular';
|
|
12
|
-
export const SYNCULAR_WASM_GLUE_FILE = `${SYNCULAR_WASM_OUT_NAME}.js`;
|
|
13
|
-
export const SYNCULAR_WASM_BINARY_FILE = `${SYNCULAR_WASM_OUT_NAME}_bg.wasm`;
|
|
14
|
-
export const SYNCULAR_WASM_ARTIFACT_FILE = 'syncular-runtime-artifact.json';
|
|
15
|
-
export const SYNCULAR_WASM_ARTIFACT_CATALOG_FILE =
|
|
16
|
-
'syncular-runtime-artifacts.json';
|
|
17
|
-
export const SYNCULAR_FULL_RUNTIME_FEATURES = [
|
|
18
|
-
'web-owned-sqlite-core',
|
|
19
|
-
'web-owned-sqlite',
|
|
20
|
-
'blobs',
|
|
21
|
-
'crdt-yjs',
|
|
22
|
-
'e2ee',
|
|
23
|
-
] as const;
|
|
24
|
-
export const SYNCULAR_CORE_RUNTIME_FEATURES = [
|
|
25
|
-
'web-owned-sqlite-core',
|
|
26
|
-
] as const;
|
|
27
|
-
|
|
28
|
-
export type SyncularWasmArtifactVariant = 'full' | 'full-perf' | 'core';
|
|
29
|
-
|
|
30
|
-
export function getSyncularWasmGlueUrl(): URL {
|
|
31
|
-
return resolveSyncularWasmAsset(SYNCULAR_WASM_GLUE_FILE);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function getSyncularWasmUrl(): URL {
|
|
35
|
-
return resolveSyncularWasmAsset(SYNCULAR_WASM_BINARY_FILE);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function getSyncularRuntimeArtifactCatalogUrl(): URL {
|
|
39
|
-
const runtimeUrl = new URL(import.meta.url);
|
|
40
|
-
const sourceRuntime = runtimeUrl.pathname.endsWith(
|
|
41
|
-
'/src/wasm-bindings/runtime-contract.ts'
|
|
42
|
-
);
|
|
43
|
-
return new URL(
|
|
44
|
-
sourceRuntime
|
|
45
|
-
? `../../dist/${SYNCULAR_WASM_ARTIFACT_CATALOG_FILE}`
|
|
46
|
-
: `../${SYNCULAR_WASM_ARTIFACT_CATALOG_FILE}`,
|
|
47
|
-
runtimeUrl
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function getSyncularRuntimeArtifact(
|
|
52
|
-
variant: SyncularWasmArtifactVariant = 'full'
|
|
53
|
-
): SyncularRuntimeArtifactCandidate {
|
|
54
|
-
const dir =
|
|
55
|
-
variant === 'core'
|
|
56
|
-
? 'wasm-core'
|
|
57
|
-
: variant === 'full-perf'
|
|
58
|
-
? 'wasm-perf'
|
|
59
|
-
: 'wasm';
|
|
60
|
-
const features =
|
|
61
|
-
variant === 'core'
|
|
62
|
-
? SYNCULAR_CORE_RUNTIME_FEATURES
|
|
63
|
-
: SYNCULAR_FULL_RUNTIME_FEATURES;
|
|
64
|
-
return {
|
|
65
|
-
name: variant,
|
|
66
|
-
features,
|
|
67
|
-
wasmGlueUrl: resolveSyncularWasmAsset(SYNCULAR_WASM_GLUE_FILE, dir),
|
|
68
|
-
wasmUrl: resolveSyncularWasmAsset(SYNCULAR_WASM_BINARY_FILE, dir),
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function getSyncularPackagedRuntimeArtifacts(): readonly SyncularRuntimeArtifactCandidate[] {
|
|
73
|
-
return [
|
|
74
|
-
getSyncularRuntimeArtifact('core'),
|
|
75
|
-
getSyncularRuntimeArtifact('full'),
|
|
76
|
-
getSyncularRuntimeArtifact('full-perf'),
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function resolveSyncularRuntimeArtifactCatalog(
|
|
81
|
-
catalog: SyncularRuntimeArtifactCatalog,
|
|
82
|
-
options: { baseUrl?: string | URL } = {}
|
|
83
|
-
): readonly SyncularRuntimeArtifactCandidate[] {
|
|
84
|
-
const baseUrl = options.baseUrl ?? getSyncularRuntimeArtifactCatalogUrl();
|
|
85
|
-
return catalog.artifacts.map((artifact) => ({
|
|
86
|
-
name: artifact.name,
|
|
87
|
-
features: artifact.features,
|
|
88
|
-
wasmGlueUrl: resolveCatalogAssetUrl(artifact.wasmGlueUrl, baseUrl),
|
|
89
|
-
wasmUrl: resolveCatalogAssetUrl(artifact.wasmUrl, baseUrl),
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function selectSyncularRuntimeArtifact(
|
|
94
|
-
requiredFeatures: readonly string[] = [],
|
|
95
|
-
artifacts: readonly SyncularRuntimeArtifactCandidate[] = [
|
|
96
|
-
getSyncularRuntimeArtifact('full'),
|
|
97
|
-
]
|
|
98
|
-
): SyncularRuntimeArtifact {
|
|
99
|
-
const required = new Set(requiredFeatures);
|
|
100
|
-
for (const artifact of artifacts) {
|
|
101
|
-
const available = new Set(artifact.features);
|
|
102
|
-
let compatible = true;
|
|
103
|
-
for (const feature of required) {
|
|
104
|
-
if (!available.has(feature)) {
|
|
105
|
-
compatible = false;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (compatible) {
|
|
110
|
-
return {
|
|
111
|
-
wasmGlueUrl: artifact.wasmGlueUrl,
|
|
112
|
-
wasmUrl: artifact.wasmUrl,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
throw new Error(
|
|
118
|
-
`No Syncular Rust runtime artifact satisfies required features: ${[
|
|
119
|
-
...required,
|
|
120
|
-
].join(', ')}`
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function resolveSyncularWasmAsset(fileName: string, dir = 'wasm'): URL {
|
|
125
|
-
const runtimeUrl = new URL(import.meta.url);
|
|
126
|
-
const sourceRuntime = runtimeUrl.pathname.endsWith(
|
|
127
|
-
'/src/wasm-bindings/runtime-contract.ts'
|
|
128
|
-
);
|
|
129
|
-
return new URL(
|
|
130
|
-
sourceRuntime ? `../../dist/${dir}/${fileName}` : `../${dir}/${fileName}`,
|
|
131
|
-
runtimeUrl
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function resolveCatalogAssetUrl(
|
|
136
|
-
value: string,
|
|
137
|
-
baseUrl: string | URL
|
|
138
|
-
): string | URL {
|
|
139
|
-
if (isAbsoluteAssetUrl(value)) return value;
|
|
140
|
-
if (baseUrl instanceof URL) {
|
|
141
|
-
return new URL(value, new URL('./', baseUrl));
|
|
142
|
-
}
|
|
143
|
-
if (hasUrlProtocol(baseUrl)) {
|
|
144
|
-
return new URL(value, new URL('./', baseUrl)).href;
|
|
145
|
-
}
|
|
146
|
-
const baseDir = baseUrl.endsWith('/')
|
|
147
|
-
? baseUrl
|
|
148
|
-
: baseUrl.slice(0, Math.max(0, baseUrl.lastIndexOf('/') + 1));
|
|
149
|
-
return `${baseDir}${value}`;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function isAbsoluteAssetUrl(value: string): boolean {
|
|
153
|
-
return value.startsWith('/') || hasUrlProtocol(value);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function hasUrlProtocol(value: string): boolean {
|
|
157
|
-
return /^[a-z][a-z0-9+.-]*:/i.test(value);
|
|
158
|
-
}
|
package/src/wasm-runtime.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ResolvedSyncularClientConfig,
|
|
3
|
-
SyncularRustRuntimeInfo,
|
|
4
|
-
} from './types';
|
|
5
|
-
import {
|
|
6
|
-
getSyncularWasmGlueUrl,
|
|
7
|
-
getSyncularWasmUrl,
|
|
8
|
-
type SyncularRustOwnedSqliteClient,
|
|
9
|
-
} from './wasm-bindings/runtime-contract';
|
|
10
|
-
|
|
11
|
-
export type {
|
|
12
|
-
SyncularRustOwnedSqliteClient,
|
|
13
|
-
SyncularWasmArtifactVariant,
|
|
14
|
-
} from './wasm-bindings/runtime-contract';
|
|
15
|
-
export {
|
|
16
|
-
getSyncularPackagedRuntimeArtifacts,
|
|
17
|
-
getSyncularRuntimeArtifact,
|
|
18
|
-
getSyncularRuntimeArtifactCatalogUrl,
|
|
19
|
-
getSyncularWasmGlueUrl,
|
|
20
|
-
getSyncularWasmUrl,
|
|
21
|
-
resolveSyncularRuntimeArtifactCatalog,
|
|
22
|
-
selectSyncularRuntimeArtifact,
|
|
23
|
-
} from './wasm-bindings/runtime-contract';
|
|
24
|
-
|
|
25
|
-
export interface SyncularWasmGlue {
|
|
26
|
-
default(moduleOrPath?: SyncularWasmInitInput): Promise<unknown>;
|
|
27
|
-
syncularRuntimeInfoJson(): string;
|
|
28
|
-
syncularBuildYjsTextUpdateJson(argsJson: string): string;
|
|
29
|
-
syncularApplyYjsTextUpdatesJson(argsJson: string): string;
|
|
30
|
-
syncularApplyYjsEnvelopeToPayloadJson(argsJson: string): string;
|
|
31
|
-
syncularMaterializeYjsRowJson(argsJson: string): string;
|
|
32
|
-
syncularEncryptionHelperJson(method: string, argsJson: string): string;
|
|
33
|
-
openSyncularRustOwnedSqliteClient(
|
|
34
|
-
config: ResolvedSyncularClientConfig
|
|
35
|
-
): Promise<SyncularRustOwnedSqliteClient>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type SyncularWasmModuleInput =
|
|
39
|
-
| string
|
|
40
|
-
| URL
|
|
41
|
-
| Request
|
|
42
|
-
| Response
|
|
43
|
-
| BufferSource
|
|
44
|
-
| WebAssembly.Module;
|
|
45
|
-
|
|
46
|
-
export type SyncularWasmInitInput =
|
|
47
|
-
| SyncularWasmModuleInput
|
|
48
|
-
| Promise<SyncularWasmModuleInput>
|
|
49
|
-
| {
|
|
50
|
-
module_or_path:
|
|
51
|
-
| SyncularWasmModuleInput
|
|
52
|
-
| Promise<SyncularWasmModuleInput>;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
type SyncularWasmFetchInput = string | URL | Request;
|
|
56
|
-
|
|
57
|
-
let modulePromise: Promise<SyncularWasmGlue> | undefined;
|
|
58
|
-
|
|
59
|
-
export function loadSyncularWasmGlue(): Promise<SyncularWasmGlue> {
|
|
60
|
-
modulePromise ??= (
|
|
61
|
-
import(
|
|
62
|
-
/* @vite-ignore */ getSyncularWasmGlueUrl().href
|
|
63
|
-
) as Promise<SyncularWasmGlue>
|
|
64
|
-
).catch((error: unknown) => {
|
|
65
|
-
modulePromise = undefined;
|
|
66
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
-
if (/cannot find module|failed to fetch|not found/i.test(message)) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
`Syncular WASM runtime artifact is missing (${message}). ` +
|
|
70
|
-
'In this repo, build it first: `bun run client:build:wasm` ' +
|
|
71
|
-
'(or `bun --cwd packages/client build:wasm:dev` for a fast dev ' +
|
|
72
|
-
'build). In an app, ensure the @syncular/client dist/wasm assets ' +
|
|
73
|
-
'are served.',
|
|
74
|
-
{ cause: error }
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
throw error;
|
|
78
|
-
});
|
|
79
|
-
return modulePromise;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export async function getSyncularRustRuntimeInfo(
|
|
83
|
-
mod?: SyncularWasmGlue | Promise<SyncularWasmGlue>,
|
|
84
|
-
wasmUrl: string | URL | Request = getSyncularWasmUrl()
|
|
85
|
-
): Promise<SyncularRustRuntimeInfo> {
|
|
86
|
-
const resolved = await (mod ?? loadSyncularWasmGlue());
|
|
87
|
-
await resolved.default({
|
|
88
|
-
module_or_path: await prepareSyncularWasmModuleInput(wasmUrl),
|
|
89
|
-
});
|
|
90
|
-
return readSyncularRustRuntimeInfo(resolved);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export async function prepareSyncularWasmModuleInput(
|
|
94
|
-
wasmUrl: SyncularWasmModuleInput = getSyncularWasmUrl()
|
|
95
|
-
): Promise<SyncularWasmModuleInput> {
|
|
96
|
-
if (!shouldReadWasmUrlAsBytes(wasmUrl)) return wasmUrl;
|
|
97
|
-
const response = await fetch(wasmUrl);
|
|
98
|
-
if (!response.ok) {
|
|
99
|
-
throw new Error(
|
|
100
|
-
`Syncular WASM runtime artifact could not be loaded from ${describeSyncularWasmInput(
|
|
101
|
-
wasmUrl
|
|
102
|
-
)} (${response.status} ${response.statusText})`
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
return response.arrayBuffer();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function readSyncularRustRuntimeInfo(
|
|
109
|
-
mod: SyncularWasmGlue
|
|
110
|
-
): SyncularRustRuntimeInfo {
|
|
111
|
-
return JSON.parse(mod.syncularRuntimeInfoJson()) as SyncularRustRuntimeInfo;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function shouldReadWasmUrlAsBytes(
|
|
115
|
-
input: SyncularWasmModuleInput
|
|
116
|
-
): input is SyncularWasmFetchInput {
|
|
117
|
-
return isBunRuntime() && isFileUrlInput(input);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function isBunRuntime(): boolean {
|
|
121
|
-
return (globalThis as typeof globalThis & { Bun?: unknown }).Bun != null;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function isFileUrlInput(
|
|
125
|
-
input: SyncularWasmModuleInput
|
|
126
|
-
): input is SyncularWasmFetchInput {
|
|
127
|
-
if (input instanceof URL) return input.protocol === 'file:';
|
|
128
|
-
if (input instanceof Request) return isFileUrlString(input.url);
|
|
129
|
-
if (typeof input === 'string') return isFileUrlString(input);
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function isFileUrlString(input: string): boolean {
|
|
134
|
-
try {
|
|
135
|
-
return new URL(input).protocol === 'file:';
|
|
136
|
-
} catch {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function describeSyncularWasmInput(input: string | URL | Request): string {
|
|
142
|
-
if (input instanceof URL) return input.href;
|
|
143
|
-
if (input instanceof Request) return input.url;
|
|
144
|
-
return input;
|
|
145
|
-
}
|