@delali/sirannon-db 0.1.7 → 0.2.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.
- package/README.md +117 -969
- package/dist/backup-scheduler/index.d.ts +1 -1
- package/dist/backup-scheduler/index.mjs +2 -2
- package/dist/baseline-Br77Fnhb.d.ts +6 -0
- package/dist/{change-tracker-CbmaMO-N.d.ts → change-tracker-DKRVUC3l.d.ts} +5 -8
- package/dist/{chunk-DJLX6CAE.mjs → chunk-4ISB7XMA.mjs} +2 -1
- package/dist/chunk-5NOIGN5Y.mjs +18 -0
- package/dist/chunk-67M7KAH6.mjs +90 -0
- package/dist/{chunk-GEZUUIKV.mjs → chunk-D7LAYTKN.mjs} +5 -2
- package/dist/{chunk-4IGMIJQK.mjs → chunk-EBJXPQQO.mjs} +59 -20
- package/dist/{chunk-BNUTBHHH.mjs → chunk-FHWTZFI4.mjs} +1 -1
- package/dist/chunk-GVCNMPOS.mjs +130 -0
- package/dist/chunk-H237TXZW.mjs +1407 -0
- package/dist/{chunk-HHRMRFFR.mjs → chunk-H6PIVVDN.mjs} +353 -142
- package/dist/chunk-HR5CWTLC.mjs +661 -0
- package/dist/chunk-JU64Y7HM.mjs +299 -0
- package/dist/{chunk-CW6S3WL5.mjs → chunk-JZGINXTN.mjs} +7 -5
- package/dist/{chunk-CJLYFDP5.mjs → chunk-LFZ37BSX.mjs} +1 -1
- package/dist/chunk-LNY2VVHE.mjs +18 -0
- package/dist/chunk-NVQS53NT.mjs +665 -0
- package/dist/{chunk-H5AB6NIR.mjs → chunk-O7SLN3GI.mjs} +2 -15
- package/dist/chunk-OQVZBEBY.mjs +283 -0
- package/dist/{chunk-VLTICJOD.mjs → chunk-PIKHN33N.mjs} +1 -1
- package/dist/chunk-TJF5GZSV.mjs +187 -0
- package/dist/chunk-TUD5CJ76.mjs +126 -0
- package/dist/{chunk-YPYVQJ4C.mjs → chunk-UC3SCMIN.mjs} +9 -1
- package/dist/client/index.d.ts +216 -321
- package/dist/client/index.mjs +1192 -1342
- package/dist/client/topology.d.ts +61 -0
- package/dist/client/topology.mjs +682 -0
- package/dist/client-base-CLWmH5Ln.d.ts +234 -0
- package/dist/codegen/cli.d.ts +2 -0
- package/dist/codegen/cli.mjs +11 -0
- package/dist/codegen/index.d.ts +30 -0
- package/dist/codegen/index.mjs +5 -0
- package/dist/core/index.d.ts +37 -16
- package/dist/core/index.mjs +2322 -298
- package/dist/core/writer-worker.mjs +28 -6
- package/dist/{database-DuGp0Rtr.d.ts → database-BY0L5Q2n.d.ts} +59 -14
- package/dist/driver/better-sqlite3.d.ts +1 -1
- package/dist/driver/better-sqlite3.mjs +6 -6
- package/dist/driver/node.d.ts +1 -1
- package/dist/driver/node.mjs +6 -6
- package/dist/driver/wa-sqlite.d.ts +1 -136
- package/dist/{errors-5Nf5ZAEC.d.ts → errors-Bw5MdNCu.d.ts} +5 -1
- package/dist/file-migrations/index.d.ts +7 -5
- package/dist/file-migrations/index.mjs +42 -37
- package/dist/operation-registry-9DcvxcE5.d.ts +45 -0
- package/dist/primary-wins-DPAm2AKG.d.ts +61 -0
- package/dist/protocol-6KrSq2Hy.d.ts +66 -0
- package/dist/react/index.d.ts +20 -0
- package/dist/react/index.mjs +137 -0
- package/dist/replication/coordinator/etcd.d.ts +5 -3
- package/dist/replication/coordinator/etcd.mjs +554 -462
- package/dist/replication/index.d.ts +51 -105
- package/dist/replication/index.mjs +1415 -2061
- package/dist/server/index.d.ts +111 -87
- package/dist/server/index.mjs +1917 -489
- package/dist/server-options-1JHu8pid.d.ts +191 -0
- package/dist/{sirannon-4SspRvP5.d.ts → sirannon-DaQSyhbJ.d.ts} +7 -2
- package/dist/transport/grpc.d.ts +7 -4
- package/dist/transport/grpc.mjs +191 -97
- package/dist/transport/memory.d.ts +5 -134
- package/dist/transport/memory.mjs +3 -1
- package/dist/{types-BsjobKbl.d.ts → types-B7gmEsZW.d.ts} +8 -61
- package/dist/{types-BEu1I_9_.d.ts → types-BsVabqSI.d.ts} +1 -1
- package/dist/types-CL6piSnD.d.ts +43 -0
- package/dist/types-C_D8IhpO.d.ts +60 -0
- package/dist/{types-D_hQW1hr.d.ts → types-zhnRXrsb.d.ts} +55 -165
- package/package.json +44 -6
- package/dist/chunk-TKGHYWQ6.mjs +0 -35
- package/dist/types-D4p4UyDK.d.ts +0 -26
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { W as WriteConcern, R as ReadConcern, E as ExecuteResult } from './types-zhnRXrsb.js';
|
|
2
|
+
import { B as BulkLoadDurability, a as BulkLoadResult } from './server-options-1JHu8pid.js';
|
|
3
|
+
|
|
4
|
+
interface QueryRequest {
|
|
5
|
+
sql: string;
|
|
6
|
+
params?: Record<string, unknown> | unknown[];
|
|
7
|
+
readConcern?: ReadConcern;
|
|
8
|
+
}
|
|
9
|
+
interface ExecuteRequest {
|
|
10
|
+
sql: string;
|
|
11
|
+
params?: Record<string, unknown> | unknown[];
|
|
12
|
+
writeConcern?: WriteConcern;
|
|
13
|
+
}
|
|
14
|
+
interface TransactionStatement {
|
|
15
|
+
sql: string;
|
|
16
|
+
params?: Record<string, unknown> | unknown[];
|
|
17
|
+
}
|
|
18
|
+
interface TransactionRequest {
|
|
19
|
+
statements: TransactionStatement[];
|
|
20
|
+
writeConcern?: WriteConcern;
|
|
21
|
+
}
|
|
22
|
+
/** The whole batch commits atomically in one server-side transaction with one fsync. */
|
|
23
|
+
interface BatchRequest {
|
|
24
|
+
sql: string;
|
|
25
|
+
paramsBatch: (Record<string, unknown> | unknown[])[];
|
|
26
|
+
writeConcern?: WriteConcern;
|
|
27
|
+
}
|
|
28
|
+
interface QueryResponse {
|
|
29
|
+
rows: Record<string, unknown>[];
|
|
30
|
+
}
|
|
31
|
+
interface ExecuteResponse {
|
|
32
|
+
changes: number;
|
|
33
|
+
lastInsertRowId: number | string;
|
|
34
|
+
}
|
|
35
|
+
interface TransactionResponse {
|
|
36
|
+
results: ExecuteResponse[];
|
|
37
|
+
}
|
|
38
|
+
interface BatchResponse {
|
|
39
|
+
results: ExecuteResponse[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Loads rows with relaxed writer durability; the configured durability is
|
|
43
|
+
* restored before the response is sent, and a load interrupted by a crash is
|
|
44
|
+
* recovered by re-running it.
|
|
45
|
+
*/
|
|
46
|
+
interface LoadRequest {
|
|
47
|
+
sql: string;
|
|
48
|
+
paramsBatch: (Record<string, unknown> | unknown[])[];
|
|
49
|
+
durability?: BulkLoadDurability;
|
|
50
|
+
checkpoint?: boolean;
|
|
51
|
+
}
|
|
52
|
+
type LoadResponse = BulkLoadResult;
|
|
53
|
+
interface AckResponse {
|
|
54
|
+
acked: boolean;
|
|
55
|
+
seq: string;
|
|
56
|
+
}
|
|
57
|
+
interface ErrorResponse {
|
|
58
|
+
error: {
|
|
59
|
+
code: string;
|
|
60
|
+
message: string;
|
|
61
|
+
details?: Record<string, unknown>;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
declare function toExecuteResponse(result: ExecuteResult): ExecuteResponse;
|
|
65
|
+
|
|
66
|
+
export { type AckResponse as A, type BatchResponse as B, type ExecuteResponse as E, type LoadResponse as L, type QueryResponse as Q, type TransactionStatement as T, type TransactionResponse as a, type BatchRequest as b, type ErrorResponse as c, type ExecuteRequest as d, type LoadRequest as e, type QueryRequest as f, type TransactionRequest as g, toExecuteResponse as t };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { L as LiveQueryOptions, a as LiveQuery, b as LiveQueryState } from '../types-CL6piSnD.js';
|
|
2
|
+
import { O as OperationRef } from '../operation-registry-9DcvxcE5.js';
|
|
3
|
+
import { P as Params } from '../types-zhnRXrsb.js';
|
|
4
|
+
|
|
5
|
+
interface LiveDatabase {
|
|
6
|
+
live(operation: string | OperationRef<never, never>, args?: never, options?: LiveQueryOptions): Promise<LiveQuery<unknown>>;
|
|
7
|
+
}
|
|
8
|
+
interface UseLiveQueryOptions extends LiveQueryOptions {
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare function useLiveQuery<Row = Record<string, unknown>>(database: LiveDatabase, operation: string, args?: Params, options?: UseLiveQueryOptions): LiveQueryState<Row>;
|
|
12
|
+
declare function useLiveQuery<Args, Row>(database: LiveDatabase, operation: OperationRef<Args, Row>, args: Args, options?: UseLiveQueryOptions): LiveQueryState<Row>;
|
|
13
|
+
declare function useCommand<Args, Result>(database: {
|
|
14
|
+
execute(operation: OperationRef<Args, unknown>, args: Args): Promise<Result>;
|
|
15
|
+
}, command: OperationRef<Args, unknown>): (args: Args) => Promise<Result>;
|
|
16
|
+
declare function useCommand<Result>(database: {
|
|
17
|
+
execute(sql: string, params?: Params): Promise<Result>;
|
|
18
|
+
}, command: string): (params?: Params) => Promise<Result>;
|
|
19
|
+
|
|
20
|
+
export { type LiveDatabase, LiveQueryState, type UseLiveQueryOptions, useCommand, useLiveQuery };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { useMemo, useSyncExternalStore, useCallback, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
// src/react/index.ts
|
|
4
|
+
|
|
5
|
+
// src/core/operation-registry.ts
|
|
6
|
+
function operationRef(name) {
|
|
7
|
+
return { name };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/react/live-query-store.ts
|
|
11
|
+
var PENDING = { status: "pending" };
|
|
12
|
+
function createLiveQueryStore(open) {
|
|
13
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
14
|
+
let snapshot = PENDING;
|
|
15
|
+
let query = null;
|
|
16
|
+
let detach = null;
|
|
17
|
+
let generation = 0;
|
|
18
|
+
function publish(next) {
|
|
19
|
+
if (next === snapshot) return;
|
|
20
|
+
snapshot = next;
|
|
21
|
+
for (const listener of [...listeners]) listener();
|
|
22
|
+
}
|
|
23
|
+
function start() {
|
|
24
|
+
if (open === null) return;
|
|
25
|
+
const opened = generation;
|
|
26
|
+
open().then(
|
|
27
|
+
(next) => {
|
|
28
|
+
if (opened !== generation) {
|
|
29
|
+
void next.close().catch(discard);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
query = next;
|
|
33
|
+
detach = next.subscribe(() => publish(next.getState()));
|
|
34
|
+
publish(next.getState());
|
|
35
|
+
},
|
|
36
|
+
(reason) => {
|
|
37
|
+
if (opened !== generation) return;
|
|
38
|
+
publish({ status: "error", error: reason instanceof Error ? reason : new Error(String(reason)) });
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
function stop() {
|
|
43
|
+
generation++;
|
|
44
|
+
detach?.();
|
|
45
|
+
detach = null;
|
|
46
|
+
const closing = query;
|
|
47
|
+
query = null;
|
|
48
|
+
snapshot = PENDING;
|
|
49
|
+
void closing?.close().catch(discard);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
subscribe(listener) {
|
|
53
|
+
listeners.add(listener);
|
|
54
|
+
if (listeners.size === 1) start();
|
|
55
|
+
return () => {
|
|
56
|
+
listeners.delete(listener);
|
|
57
|
+
if (listeners.size === 0) stop();
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
getSnapshot() {
|
|
61
|
+
return snapshot;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function getServerSnapshot() {
|
|
66
|
+
return PENDING;
|
|
67
|
+
}
|
|
68
|
+
function discard() {
|
|
69
|
+
}
|
|
70
|
+
function useStableValue(value) {
|
|
71
|
+
const held = useRef(value);
|
|
72
|
+
if (held.current !== value && !sameValue(held.current, value)) held.current = value;
|
|
73
|
+
return held.current;
|
|
74
|
+
}
|
|
75
|
+
function sameValue(left, right) {
|
|
76
|
+
if (Object.is(left, right)) return true;
|
|
77
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) return false;
|
|
78
|
+
if (Array.isArray(left) || Array.isArray(right)) return sameArray(left, right);
|
|
79
|
+
if (ArrayBuffer.isView(left) || ArrayBuffer.isView(right)) return sameBytes(left, right);
|
|
80
|
+
if (left instanceof Date || right instanceof Date) {
|
|
81
|
+
return left instanceof Date && right instanceof Date && left.getTime() === right.getTime();
|
|
82
|
+
}
|
|
83
|
+
return sameRecord(left, right);
|
|
84
|
+
}
|
|
85
|
+
function sameArray(left, right) {
|
|
86
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
87
|
+
for (let index = 0; index < left.length; index++) {
|
|
88
|
+
if (!sameValue(left[index], right[index])) return false;
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
function sameBytes(left, right) {
|
|
93
|
+
if (!(left instanceof Uint8Array) || !(right instanceof Uint8Array) || left.length !== right.length) return false;
|
|
94
|
+
for (let index = 0; index < left.length; index++) {
|
|
95
|
+
if (left[index] !== right[index]) return false;
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
function sameRecord(left, right) {
|
|
100
|
+
const keys = Object.keys(left);
|
|
101
|
+
if (keys.length !== Object.keys(right).length) return false;
|
|
102
|
+
for (const key of keys) {
|
|
103
|
+
if (!Object.hasOwn(right, key)) return false;
|
|
104
|
+
if (!sameValue(left[key], right[key])) return false;
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/react/index.ts
|
|
110
|
+
function useLiveQuery(database, operation, args, options) {
|
|
111
|
+
const literal = typeof operation === "string";
|
|
112
|
+
const name = literal ? operation : operation.name;
|
|
113
|
+
const enabled = options?.enabled !== false;
|
|
114
|
+
const rereadJitterMs = options?.rereadJitterMs;
|
|
115
|
+
const maxTransactionChanges = options?.maxTransactionChanges;
|
|
116
|
+
const stableArgs = useStableValue(args);
|
|
117
|
+
const store = useMemo(() => {
|
|
118
|
+
if (!enabled) return createLiveQueryStore(null);
|
|
119
|
+
const target = literal ? name : operationRef(name);
|
|
120
|
+
const queryOptions = {
|
|
121
|
+
...rereadJitterMs === void 0 ? {} : { rereadJitterMs },
|
|
122
|
+
...maxTransactionChanges === void 0 ? {} : { maxTransactionChanges }
|
|
123
|
+
};
|
|
124
|
+
return createLiveQueryStore(
|
|
125
|
+
() => database.live(target, stableArgs, queryOptions)
|
|
126
|
+
);
|
|
127
|
+
}, [database, literal, name, stableArgs, enabled, rereadJitterMs, maxTransactionChanges]);
|
|
128
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);
|
|
129
|
+
}
|
|
130
|
+
function useCommand(database, command) {
|
|
131
|
+
const literal = typeof command === "string";
|
|
132
|
+
const name = literal ? command : command.name;
|
|
133
|
+
const target = useMemo(() => literal ? name : operationRef(name), [literal, name]);
|
|
134
|
+
return useCallback((args) => database.execute(target, args), [database, target]);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export { useCommand, useLiveQuery };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IOptions } from 'etcd3';
|
|
2
|
-
import { C as ClusterCoordinator, A as AcquireControllerLeaseInput,
|
|
2
|
+
import { C as ClusterCoordinator, A as AcquireControllerLeaseInput, b as AcquireControllerLeaseResult, c as RegisterNodeSessionInput, d as CoordinatorNodeSession, S as SetReplicationGroupStateInput, R as ReplicationGroupState, e as ReplicationGroupWatcher, f as CoordinatorWatchDisposer, g as CompareAndAdvancePrimaryTermInput, h as CompareAndAdvancePrimaryTermResult, U as UpdateInSyncSetInput, i as AdmitNodeToInSyncSetInput, j as UpdateNodeMaintenanceInput, P as PromoteEligibleReplicaInput } from '../../types-BsVabqSI.js';
|
|
3
3
|
|
|
4
4
|
interface EtcdClusterCoordinatorOptions {
|
|
5
5
|
hosts: string | string[];
|
|
@@ -12,12 +12,15 @@ interface EtcdClusterCoordinatorOptions {
|
|
|
12
12
|
allowInsecure?: boolean;
|
|
13
13
|
onWatcherError?: (error: Error) => void;
|
|
14
14
|
}
|
|
15
|
+
|
|
15
16
|
declare class EtcdClusterCoordinator implements ClusterCoordinator {
|
|
16
17
|
private readonly client;
|
|
17
18
|
private readonly namespace;
|
|
18
19
|
private readonly onWatcherError;
|
|
19
20
|
private readonly leases;
|
|
21
|
+
private readonly grantedNodeSessionLeaseIds;
|
|
20
22
|
private readonly watchers;
|
|
23
|
+
private readonly groups;
|
|
21
24
|
constructor(options: EtcdClusterCoordinatorOptions);
|
|
22
25
|
tryAcquireControllerLease(input: AcquireControllerLeaseInput): Promise<AcquireControllerLeaseResult>;
|
|
23
26
|
renewLease(leaseId: string, ttlMs: number): Promise<boolean>;
|
|
@@ -34,10 +37,9 @@ declare class EtcdClusterCoordinator implements ClusterCoordinator {
|
|
|
34
37
|
updateNodeMaintenance(input: UpdateNodeMaintenanceInput): Promise<ReplicationGroupState | null>;
|
|
35
38
|
promoteEligibleReplica(input: PromoteEligibleReplicaInput): Promise<ReplicationGroupState>;
|
|
36
39
|
close(): Promise<void>;
|
|
40
|
+
private discardSupersededLeases;
|
|
37
41
|
private getLeaseFromKey;
|
|
38
42
|
private trackLease;
|
|
39
|
-
private updateGroupStateWithRetry;
|
|
40
|
-
private casGroupState;
|
|
41
43
|
}
|
|
42
44
|
declare function createEtcdCoordinator(options: EtcdClusterCoordinatorOptions): EtcdClusterCoordinator;
|
|
43
45
|
|