@tinyshed/tinystore 0.5.1 → 0.7.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/dist/config.d.ts +67 -4
- package/dist/config.js +127 -13
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/logger.d.ts +10 -0
- package/dist/logger.js +16 -6
- package/dist/metrics.d.ts +17 -0
- package/dist/metrics.js +22 -1
- package/dist/records.d.ts +90 -5
- package/dist/records.js +114 -6
- package/dist/sql.d.ts +19 -3
- package/dist/sql.js +31 -4
- package/dist/wire/protocol.d.ts +105 -9
- package/dist/wire/protocol.js +296 -8
- package/package.json +8 -8
- package/src/config.ts +204 -25
- package/src/index.ts +13 -1
- package/src/logger.ts +17 -7
- package/src/metrics.ts +25 -0
- package/src/records.ts +178 -7
- package/src/sql.ts +48 -7
- package/src/wire/protocol.ts +321 -8
package/dist/wire/protocol.js
CHANGED
|
@@ -106,6 +106,11 @@ export const methods = {
|
|
|
106
106
|
* nothing written and lets go of what came.
|
|
107
107
|
*/
|
|
108
108
|
'metrics.uploadPrometheus': 0x0610,
|
|
109
|
+
/**
|
|
110
|
+
* A gauge's range replaced in one write: a read sees it as it was or as it
|
|
111
|
+
* is, never half; the same samples sent again write nothing.
|
|
112
|
+
*/
|
|
113
|
+
'metrics.replace': 0x0611,
|
|
109
114
|
'records.open': 0x0501,
|
|
110
115
|
'records.append': 0x0502,
|
|
111
116
|
'records.list': 0x0503,
|
|
@@ -119,6 +124,7 @@ export const methods = {
|
|
|
119
124
|
'records.lines': 0x050b,
|
|
120
125
|
'records.damaged': 0x050c,
|
|
121
126
|
'records.drop': 0x050d,
|
|
127
|
+
'records.fields': 0x050e,
|
|
122
128
|
'search.open': 0x0b01,
|
|
123
129
|
'search.set': 0x0b02,
|
|
124
130
|
'search.setMany': 0x0b03,
|
|
@@ -6372,6 +6378,60 @@ export const MetricsIngest = message('metrics.Ingest', {
|
|
|
6372
6378
|
return { series: $series };
|
|
6373
6379
|
},
|
|
6374
6380
|
});
|
|
6381
|
+
/**
|
|
6382
|
+
* A gauge's samples of from to to, packed or not, replaced by the series'
|
|
6383
|
+
* own: a time given takes its value, a time not there before is added, and a
|
|
6384
|
+
* time the series does not give goes.
|
|
6385
|
+
*/
|
|
6386
|
+
export const MetricsReplace = message('metrics.Replace', {
|
|
6387
|
+
series: [1, MetricsNewSeries],
|
|
6388
|
+
from: [2, int],
|
|
6389
|
+
/** excluded */
|
|
6390
|
+
to: [3, int],
|
|
6391
|
+
}, {
|
|
6392
|
+
write(w, v) {
|
|
6393
|
+
const head = w.openMap();
|
|
6394
|
+
let n = 0;
|
|
6395
|
+
if (v.series !== undefined) {
|
|
6396
|
+
w.field(1);
|
|
6397
|
+
MetricsNewSeries.write(w, v.series);
|
|
6398
|
+
n++;
|
|
6399
|
+
}
|
|
6400
|
+
if (v.from !== undefined) {
|
|
6401
|
+
w.field(2);
|
|
6402
|
+
w.int(v.from);
|
|
6403
|
+
n++;
|
|
6404
|
+
}
|
|
6405
|
+
if (v.to !== undefined) {
|
|
6406
|
+
w.field(3);
|
|
6407
|
+
w.int(v.to);
|
|
6408
|
+
n++;
|
|
6409
|
+
}
|
|
6410
|
+
w.closeMap(head, n);
|
|
6411
|
+
},
|
|
6412
|
+
read(r) {
|
|
6413
|
+
let $series;
|
|
6414
|
+
let $from;
|
|
6415
|
+
let $to;
|
|
6416
|
+
for (let n = r.message(); n > 0; n--) {
|
|
6417
|
+
switch (r.field()) {
|
|
6418
|
+
case 1:
|
|
6419
|
+
$series = MetricsNewSeries.read(r);
|
|
6420
|
+
break;
|
|
6421
|
+
case 2:
|
|
6422
|
+
$from = r.int();
|
|
6423
|
+
break;
|
|
6424
|
+
case 3:
|
|
6425
|
+
$to = r.int();
|
|
6426
|
+
break;
|
|
6427
|
+
default:
|
|
6428
|
+
r.skip();
|
|
6429
|
+
}
|
|
6430
|
+
}
|
|
6431
|
+
r.leave();
|
|
6432
|
+
return { series: $series, from: $from, to: $to };
|
|
6433
|
+
},
|
|
6434
|
+
});
|
|
6375
6435
|
/**
|
|
6376
6436
|
* A text an exporter serves, in Prometheus' format or OpenMetrics', whose
|
|
6377
6437
|
* series the store writes every one or none, each with labels beside its own.
|
|
@@ -7609,13 +7669,19 @@ export const MetricsAck = message('metrics.Ack', {
|
|
|
7609
7669
|
},
|
|
7610
7670
|
});
|
|
7611
7671
|
/**
|
|
7612
|
-
* Opens a stream of events by name, made with its first event.
|
|
7672
|
+
* Opens a stream of events by name, made with its first event. Opened
|
|
7673
|
+
* through a database, the stream is records.db's all the same, and its
|
|
7674
|
+
* appends inside the database's transactions and batches are kept in the
|
|
7675
|
+
* database's file until they commit, then written to the stream before the
|
|
7676
|
+
* transaction or the batch answers.
|
|
7613
7677
|
*/
|
|
7614
7678
|
export const RecordsOpen = message('records.Open', {
|
|
7615
7679
|
/** [a-z0-9][a-z0-9_-]{0,63} */
|
|
7616
7680
|
stream: [1, str],
|
|
7617
7681
|
/** how long it keeps its events: its own, kept in the file */
|
|
7618
7682
|
keep: [2, uint],
|
|
7683
|
+
/** a database's handle: its appends join its transactions and batches; none when absent */
|
|
7684
|
+
database: [3, uint],
|
|
7619
7685
|
}, {
|
|
7620
7686
|
write(w, v) {
|
|
7621
7687
|
const head = w.openMap();
|
|
@@ -7630,11 +7696,17 @@ export const RecordsOpen = message('records.Open', {
|
|
|
7630
7696
|
w.uint(v.keep);
|
|
7631
7697
|
n++;
|
|
7632
7698
|
}
|
|
7699
|
+
if (v.database !== undefined) {
|
|
7700
|
+
w.field(3);
|
|
7701
|
+
w.uint(v.database);
|
|
7702
|
+
n++;
|
|
7703
|
+
}
|
|
7633
7704
|
w.closeMap(head, n);
|
|
7634
7705
|
},
|
|
7635
7706
|
read(r) {
|
|
7636
7707
|
let $stream;
|
|
7637
7708
|
let $keep;
|
|
7709
|
+
let $database;
|
|
7638
7710
|
for (let n = r.message(); n > 0; n--) {
|
|
7639
7711
|
switch (r.field()) {
|
|
7640
7712
|
case 1:
|
|
@@ -7643,12 +7715,15 @@ export const RecordsOpen = message('records.Open', {
|
|
|
7643
7715
|
case 2:
|
|
7644
7716
|
$keep = r.uint();
|
|
7645
7717
|
break;
|
|
7718
|
+
case 3:
|
|
7719
|
+
$database = r.uint();
|
|
7720
|
+
break;
|
|
7646
7721
|
default:
|
|
7647
7722
|
r.skip();
|
|
7648
7723
|
}
|
|
7649
7724
|
}
|
|
7650
7725
|
r.leave();
|
|
7651
|
-
return { stream: $stream, keep: $keep };
|
|
7726
|
+
return { stream: $stream, keep: $keep, database: $database };
|
|
7652
7727
|
},
|
|
7653
7728
|
});
|
|
7654
7729
|
/**
|
|
@@ -8778,6 +8853,213 @@ export const RecordsStreams = message('records.Streams', {
|
|
|
8778
8853
|
return { streams: $streams };
|
|
8779
8854
|
},
|
|
8780
8855
|
});
|
|
8856
|
+
/**
|
|
8857
|
+
* What the events of a stream carry, counted as they are packed and from
|
|
8858
|
+
* what waits, none of it read from a packed event.
|
|
8859
|
+
*/
|
|
8860
|
+
export const RecordsFieldsAsked = message('records.FieldsAsked', {
|
|
8861
|
+
stream: [1, str],
|
|
8862
|
+
}, {
|
|
8863
|
+
write(w, v) {
|
|
8864
|
+
const head = w.openMap();
|
|
8865
|
+
let n = 0;
|
|
8866
|
+
if (v.stream !== undefined) {
|
|
8867
|
+
w.field(1);
|
|
8868
|
+
w.str(v.stream);
|
|
8869
|
+
n++;
|
|
8870
|
+
}
|
|
8871
|
+
w.closeMap(head, n);
|
|
8872
|
+
},
|
|
8873
|
+
read(r) {
|
|
8874
|
+
let $stream;
|
|
8875
|
+
for (let n = r.message(); n > 0; n--) {
|
|
8876
|
+
switch (r.field()) {
|
|
8877
|
+
case 1:
|
|
8878
|
+
$stream = r.str();
|
|
8879
|
+
break;
|
|
8880
|
+
default:
|
|
8881
|
+
r.skip();
|
|
8882
|
+
}
|
|
8883
|
+
}
|
|
8884
|
+
r.leave();
|
|
8885
|
+
return { stream: $stream };
|
|
8886
|
+
},
|
|
8887
|
+
});
|
|
8888
|
+
export const RecordsNameCount = message('records.NameCount', {
|
|
8889
|
+
name: [1, str],
|
|
8890
|
+
count: [2, uint],
|
|
8891
|
+
}, {
|
|
8892
|
+
write(w, v) {
|
|
8893
|
+
const head = w.openMap();
|
|
8894
|
+
let n = 0;
|
|
8895
|
+
if (v.name !== undefined) {
|
|
8896
|
+
w.field(1);
|
|
8897
|
+
w.str(v.name);
|
|
8898
|
+
n++;
|
|
8899
|
+
}
|
|
8900
|
+
if (v.count !== undefined) {
|
|
8901
|
+
w.field(2);
|
|
8902
|
+
w.uint(v.count);
|
|
8903
|
+
n++;
|
|
8904
|
+
}
|
|
8905
|
+
w.closeMap(head, n);
|
|
8906
|
+
},
|
|
8907
|
+
read(r) {
|
|
8908
|
+
let $name;
|
|
8909
|
+
let $count;
|
|
8910
|
+
for (let n = r.message(); n > 0; n--) {
|
|
8911
|
+
switch (r.field()) {
|
|
8912
|
+
case 1:
|
|
8913
|
+
$name = r.str();
|
|
8914
|
+
break;
|
|
8915
|
+
case 2:
|
|
8916
|
+
$count = r.uint();
|
|
8917
|
+
break;
|
|
8918
|
+
default:
|
|
8919
|
+
r.skip();
|
|
8920
|
+
}
|
|
8921
|
+
}
|
|
8922
|
+
r.leave();
|
|
8923
|
+
return { name: $name, count: $count };
|
|
8924
|
+
},
|
|
8925
|
+
});
|
|
8926
|
+
/**
|
|
8927
|
+
* A key of a stream's events' fields or contexts.
|
|
8928
|
+
*/
|
|
8929
|
+
export const RecordsFieldInfo = message('records.FieldInfo', {
|
|
8930
|
+
name: [1, str],
|
|
8931
|
+
/** float, integer, text, bool, object, list or null, in that order */
|
|
8932
|
+
kinds: [2, list(str)],
|
|
8933
|
+
/** the events that carry it */
|
|
8934
|
+
count: [3, uint],
|
|
8935
|
+
}, {
|
|
8936
|
+
write(w, v) {
|
|
8937
|
+
const head = w.openMap();
|
|
8938
|
+
let n = 0;
|
|
8939
|
+
if (v.name !== undefined) {
|
|
8940
|
+
w.field(1);
|
|
8941
|
+
w.str(v.name);
|
|
8942
|
+
n++;
|
|
8943
|
+
}
|
|
8944
|
+
if (v.kinds !== undefined) {
|
|
8945
|
+
w.field(2);
|
|
8946
|
+
w.array(v.kinds.length);
|
|
8947
|
+
for (const item0 of v.kinds) {
|
|
8948
|
+
w.str(item0);
|
|
8949
|
+
}
|
|
8950
|
+
n++;
|
|
8951
|
+
}
|
|
8952
|
+
if (v.count !== undefined) {
|
|
8953
|
+
w.field(3);
|
|
8954
|
+
w.uint(v.count);
|
|
8955
|
+
n++;
|
|
8956
|
+
}
|
|
8957
|
+
w.closeMap(head, n);
|
|
8958
|
+
},
|
|
8959
|
+
read(r) {
|
|
8960
|
+
let $name;
|
|
8961
|
+
let $kinds;
|
|
8962
|
+
let $count;
|
|
8963
|
+
for (let n = r.message(); n > 0; n--) {
|
|
8964
|
+
switch (r.field()) {
|
|
8965
|
+
case 1:
|
|
8966
|
+
$name = r.str();
|
|
8967
|
+
break;
|
|
8968
|
+
case 2: {
|
|
8969
|
+
const items0 = [];
|
|
8970
|
+
for (let i0 = r.array(); i0 > 0; i0--) {
|
|
8971
|
+
items0.push(r.str());
|
|
8972
|
+
}
|
|
8973
|
+
r.leave();
|
|
8974
|
+
$kinds = items0;
|
|
8975
|
+
break;
|
|
8976
|
+
}
|
|
8977
|
+
case 3:
|
|
8978
|
+
$count = r.uint();
|
|
8979
|
+
break;
|
|
8980
|
+
default:
|
|
8981
|
+
r.skip();
|
|
8982
|
+
}
|
|
8983
|
+
}
|
|
8984
|
+
r.leave();
|
|
8985
|
+
return { name: $name, kinds: $kinds, count: $count };
|
|
8986
|
+
},
|
|
8987
|
+
});
|
|
8988
|
+
export const RecordsStreamFields = message('records.StreamFields', {
|
|
8989
|
+
eventNames: [1, list(RecordsNameCount)],
|
|
8990
|
+
fields: [2, list(RecordsFieldInfo)],
|
|
8991
|
+
context: [3, list(RecordsFieldInfo)],
|
|
8992
|
+
}, {
|
|
8993
|
+
write(w, v) {
|
|
8994
|
+
const head = w.openMap();
|
|
8995
|
+
let n = 0;
|
|
8996
|
+
if (v.eventNames !== undefined) {
|
|
8997
|
+
w.field(1);
|
|
8998
|
+
w.array(v.eventNames.length);
|
|
8999
|
+
for (const item0 of v.eventNames) {
|
|
9000
|
+
RecordsNameCount.write(w, item0);
|
|
9001
|
+
}
|
|
9002
|
+
n++;
|
|
9003
|
+
}
|
|
9004
|
+
if (v.fields !== undefined) {
|
|
9005
|
+
w.field(2);
|
|
9006
|
+
w.array(v.fields.length);
|
|
9007
|
+
for (const item0 of v.fields) {
|
|
9008
|
+
RecordsFieldInfo.write(w, item0);
|
|
9009
|
+
}
|
|
9010
|
+
n++;
|
|
9011
|
+
}
|
|
9012
|
+
if (v.context !== undefined) {
|
|
9013
|
+
w.field(3);
|
|
9014
|
+
w.array(v.context.length);
|
|
9015
|
+
for (const item0 of v.context) {
|
|
9016
|
+
RecordsFieldInfo.write(w, item0);
|
|
9017
|
+
}
|
|
9018
|
+
n++;
|
|
9019
|
+
}
|
|
9020
|
+
w.closeMap(head, n);
|
|
9021
|
+
},
|
|
9022
|
+
read(r) {
|
|
9023
|
+
let $eventNames;
|
|
9024
|
+
let $fields;
|
|
9025
|
+
let $context;
|
|
9026
|
+
for (let n = r.message(); n > 0; n--) {
|
|
9027
|
+
switch (r.field()) {
|
|
9028
|
+
case 1: {
|
|
9029
|
+
const items0 = [];
|
|
9030
|
+
for (let i0 = r.array(); i0 > 0; i0--) {
|
|
9031
|
+
items0.push(RecordsNameCount.read(r));
|
|
9032
|
+
}
|
|
9033
|
+
r.leave();
|
|
9034
|
+
$eventNames = items0;
|
|
9035
|
+
break;
|
|
9036
|
+
}
|
|
9037
|
+
case 2: {
|
|
9038
|
+
const items0 = [];
|
|
9039
|
+
for (let i0 = r.array(); i0 > 0; i0--) {
|
|
9040
|
+
items0.push(RecordsFieldInfo.read(r));
|
|
9041
|
+
}
|
|
9042
|
+
r.leave();
|
|
9043
|
+
$fields = items0;
|
|
9044
|
+
break;
|
|
9045
|
+
}
|
|
9046
|
+
case 3: {
|
|
9047
|
+
const items0 = [];
|
|
9048
|
+
for (let i0 = r.array(); i0 > 0; i0--) {
|
|
9049
|
+
items0.push(RecordsFieldInfo.read(r));
|
|
9050
|
+
}
|
|
9051
|
+
r.leave();
|
|
9052
|
+
$context = items0;
|
|
9053
|
+
break;
|
|
9054
|
+
}
|
|
9055
|
+
default:
|
|
9056
|
+
r.skip();
|
|
9057
|
+
}
|
|
9058
|
+
}
|
|
9059
|
+
r.leave();
|
|
9060
|
+
return { eventNames: $eventNames, fields: $fields, context: $context };
|
|
9061
|
+
},
|
|
9062
|
+
});
|
|
8781
9063
|
/**
|
|
8782
9064
|
* The keys the events a query finds hold, sorted.
|
|
8783
9065
|
*/
|
|
@@ -10107,13 +10389,15 @@ export const SqlOpen = message('sql.Open', {
|
|
|
10107
10389
|
});
|
|
10108
10390
|
/**
|
|
10109
10391
|
* A statement's text and the values of its ?s, in order. In a batch it may
|
|
10110
|
-
* be a call of
|
|
10111
|
-
*
|
|
10392
|
+
* be a call of another engine instead, with its request in body and no
|
|
10393
|
+
* text, which commits with the batch's rows: jobs.add on a queue kept in the
|
|
10394
|
+
* database's file, or records.append on a stream opened through the
|
|
10395
|
+
* database, whose events reach the stream before the batch answers.
|
|
10112
10396
|
*/
|
|
10113
10397
|
export const SqlText = message('sql.Text', {
|
|
10114
10398
|
text: [1, str],
|
|
10115
10399
|
values: [2, list(sqlValue)],
|
|
10116
|
-
/** in a batch, jobs.add: the call in body */
|
|
10400
|
+
/** in a batch, jobs.add or records.append: the call in body */
|
|
10117
10401
|
method: [3, uint],
|
|
10118
10402
|
body: [4, bin],
|
|
10119
10403
|
}, {
|
|
@@ -10574,7 +10858,8 @@ export const SqlDone = message('sql.Done', {
|
|
|
10574
10858
|
});
|
|
10575
10859
|
/**
|
|
10576
10860
|
* Writes known before they run, written as one in a shared commit: its
|
|
10577
|
-
* statements,
|
|
10861
|
+
* statements, the adds of a queue kept in the database's file, and the
|
|
10862
|
+
* appends of a stream opened through the database.
|
|
10578
10863
|
*/
|
|
10579
10864
|
export const SqlBatch = message('sql.Batch', {
|
|
10580
10865
|
handle: [1, uint],
|
|
@@ -10625,7 +10910,8 @@ export const SqlBatch = message('sql.Batch', {
|
|
|
10625
10910
|
});
|
|
10626
10911
|
/**
|
|
10627
10912
|
* What each write of a batch did, in their order: a job's add changed one
|
|
10628
|
-
* job, or none when its id was taken
|
|
10913
|
+
* job, or none when its id was taken, and a stream's append the events its
|
|
10914
|
+
* stream holds no id of.
|
|
10629
10915
|
*/
|
|
10630
10916
|
export const SqlBatched = message('sql.Batched', {
|
|
10631
10917
|
done: [1, list(SqlDone)],
|
|
@@ -10700,7 +10986,9 @@ export const SqlTxOpen = message('sql.TxOpen', {
|
|
|
10700
10986
|
* A transaction's call, or its end: the last DATA commits, or not. A call is
|
|
10701
10987
|
* a statement, or a call of kv or jobs on a bucket or a queue kept in the
|
|
10702
10988
|
* database's file: a method of theirs with its request, kv.set or jobs.add,
|
|
10703
|
-
* which runs in the transaction.
|
|
10989
|
+
* which runs in the transaction; or records.append on a stream opened
|
|
10990
|
+
* through the database, whose events reach the stream once the transaction
|
|
10991
|
+
* commits, before its last DATA answers.
|
|
10704
10992
|
*/
|
|
10705
10993
|
export const SqlTxCall = message('sql.TxCall', {
|
|
10706
10994
|
text: [1, str],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinyshed/tinystore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "TinyStore for Bun and Node: kv, jobs, blobs, SQL, records and metrics in one directory, served by a sidecar",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://tinyshed.org/tinystore",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"README.md"
|
|
32
32
|
],
|
|
33
33
|
"optionalDependencies": {
|
|
34
|
-
"@tinyshed/tinystore-linux-x64": "0.
|
|
35
|
-
"@tinyshed/tinystore-linux-arm64": "0.
|
|
36
|
-
"@tinyshed/tinystore-linux-x64-musl": "0.
|
|
37
|
-
"@tinyshed/tinystore-linux-arm64-musl": "0.
|
|
38
|
-
"@tinyshed/tinystore-darwin-arm64": "0.
|
|
39
|
-
"@tinyshed/tinystore-darwin-x64": "0.
|
|
40
|
-
"@tinyshed/tinystore-win32-x64": "0.
|
|
34
|
+
"@tinyshed/tinystore-linux-x64": "0.7.0",
|
|
35
|
+
"@tinyshed/tinystore-linux-arm64": "0.7.0",
|
|
36
|
+
"@tinyshed/tinystore-linux-x64-musl": "0.7.0",
|
|
37
|
+
"@tinyshed/tinystore-linux-arm64-musl": "0.7.0",
|
|
38
|
+
"@tinyshed/tinystore-darwin-arm64": "0.7.0",
|
|
39
|
+
"@tinyshed/tinystore-darwin-x64": "0.7.0",
|
|
40
|
+
"@tinyshed/tinystore-win32-x64": "0.7.0"
|
|
41
41
|
}
|
|
42
42
|
}
|