@tinyshed/tinystore 0.5.1 → 0.6.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.
@@ -127,6 +127,11 @@ export const methods = {
127
127
  * nothing written and lets go of what came.
128
128
  */
129
129
  'metrics.uploadPrometheus': 0x0610,
130
+ /**
131
+ * A gauge's range replaced in one write: a read sees it as it was or as it
132
+ * is, never half; the same samples sent again write nothing.
133
+ */
134
+ 'metrics.replace': 0x0611,
130
135
  'records.open': 0x0501,
131
136
  'records.append': 0x0502,
132
137
  'records.list': 0x0503,
@@ -140,6 +145,7 @@ export const methods = {
140
145
  'records.lines': 0x050b,
141
146
  'records.damaged': 0x050c,
142
147
  'records.drop': 0x050d,
148
+ 'records.fields': 0x050e,
143
149
  'search.open': 0x0b01,
144
150
  'search.set': 0x0b02,
145
151
  'search.setMany': 0x0b03,
@@ -6861,6 +6867,65 @@ export const MetricsIngest = message(
6861
6867
  },
6862
6868
  )
6863
6869
 
6870
+ /**
6871
+ * A gauge's samples of from to to, packed or not, replaced by the series'
6872
+ * own: a time given takes its value, a time not there before is added, and a
6873
+ * time the series does not give goes.
6874
+ */
6875
+ export const MetricsReplace = message(
6876
+ 'metrics.Replace',
6877
+ {
6878
+ series: [1, MetricsNewSeries],
6879
+ from: [2, int],
6880
+ /** excluded */
6881
+ to: [3, int],
6882
+ },
6883
+ {
6884
+ write(w, v) {
6885
+ const head = w.openMap()
6886
+ let n = 0
6887
+ if (v.series !== undefined) {
6888
+ w.field(1)
6889
+ MetricsNewSeries.write(w, v.series)
6890
+ n++
6891
+ }
6892
+ if (v.from !== undefined) {
6893
+ w.field(2)
6894
+ w.int(v.from)
6895
+ n++
6896
+ }
6897
+ if (v.to !== undefined) {
6898
+ w.field(3)
6899
+ w.int(v.to)
6900
+ n++
6901
+ }
6902
+ w.closeMap(head, n)
6903
+ },
6904
+ read(r) {
6905
+ let $series: Read<typeof MetricsNewSeries.fields> | undefined
6906
+ let $from: number | undefined
6907
+ let $to: number | undefined
6908
+ for (let n = r.message(); n > 0; n--) {
6909
+ switch (r.field()) {
6910
+ case 1:
6911
+ $series = MetricsNewSeries.read(r)
6912
+ break
6913
+ case 2:
6914
+ $from = r.int()
6915
+ break
6916
+ case 3:
6917
+ $to = r.int()
6918
+ break
6919
+ default:
6920
+ r.skip()
6921
+ }
6922
+ }
6923
+ r.leave()
6924
+ return { series: $series, from: $from, to: $to }
6925
+ },
6926
+ },
6927
+ )
6928
+
6864
6929
  /**
6865
6930
  * A text an exporter serves, in Prometheus' format or OpenMetrics', whose
6866
6931
  * series the store writes every one or none, each with labels beside its own.
@@ -8198,7 +8263,11 @@ export const MetricsAck = message(
8198
8263
  )
8199
8264
 
8200
8265
  /**
8201
- * Opens a stream of events by name, made with its first event.
8266
+ * Opens a stream of events by name, made with its first event. Opened
8267
+ * through a database, the stream is records.db's all the same, and its
8268
+ * appends inside the database's transactions and batches are kept in the
8269
+ * database's file until they commit, then written to the stream before the
8270
+ * transaction or the batch answers.
8202
8271
  */
8203
8272
  export const RecordsOpen = message(
8204
8273
  'records.Open',
@@ -8207,6 +8276,8 @@ export const RecordsOpen = message(
8207
8276
  stream: [1, str],
8208
8277
  /** how long it keeps its events: its own, kept in the file */
8209
8278
  keep: [2, uint],
8279
+ /** a database's handle: its appends join its transactions and batches; none when absent */
8280
+ database: [3, uint],
8210
8281
  },
8211
8282
  {
8212
8283
  write(w, v) {
@@ -8222,11 +8293,17 @@ export const RecordsOpen = message(
8222
8293
  w.uint(v.keep)
8223
8294
  n++
8224
8295
  }
8296
+ if (v.database !== undefined) {
8297
+ w.field(3)
8298
+ w.uint(v.database)
8299
+ n++
8300
+ }
8225
8301
  w.closeMap(head, n)
8226
8302
  },
8227
8303
  read(r) {
8228
8304
  let $stream: string | undefined
8229
8305
  let $keep: number | undefined
8306
+ let $database: number | undefined
8230
8307
  for (let n = r.message(); n > 0; n--) {
8231
8308
  switch (r.field()) {
8232
8309
  case 1:
@@ -8235,12 +8312,15 @@ export const RecordsOpen = message(
8235
8312
  case 2:
8236
8313
  $keep = r.uint()
8237
8314
  break
8315
+ case 3:
8316
+ $database = r.uint()
8317
+ break
8238
8318
  default:
8239
8319
  r.skip()
8240
8320
  }
8241
8321
  }
8242
8322
  r.leave()
8243
- return { stream: $stream, keep: $keep }
8323
+ return { stream: $stream, keep: $keep, database: $database }
8244
8324
  },
8245
8325
  },
8246
8326
  )
@@ -9452,6 +9532,233 @@ export const RecordsStreams = message(
9452
9532
  },
9453
9533
  )
9454
9534
 
9535
+ /**
9536
+ * What the events of a stream carry, counted as they are packed and from
9537
+ * what waits, none of it read from a packed event.
9538
+ */
9539
+ export const RecordsFieldsAsked = message(
9540
+ 'records.FieldsAsked',
9541
+ {
9542
+ stream: [1, str],
9543
+ },
9544
+ {
9545
+ write(w, v) {
9546
+ const head = w.openMap()
9547
+ let n = 0
9548
+ if (v.stream !== undefined) {
9549
+ w.field(1)
9550
+ w.str(v.stream)
9551
+ n++
9552
+ }
9553
+ w.closeMap(head, n)
9554
+ },
9555
+ read(r) {
9556
+ let $stream: string | undefined
9557
+ for (let n = r.message(); n > 0; n--) {
9558
+ switch (r.field()) {
9559
+ case 1:
9560
+ $stream = r.str()
9561
+ break
9562
+ default:
9563
+ r.skip()
9564
+ }
9565
+ }
9566
+ r.leave()
9567
+ return { stream: $stream }
9568
+ },
9569
+ },
9570
+ )
9571
+
9572
+ export const RecordsNameCount = message(
9573
+ 'records.NameCount',
9574
+ {
9575
+ name: [1, str],
9576
+ count: [2, uint],
9577
+ },
9578
+ {
9579
+ write(w, v) {
9580
+ const head = w.openMap()
9581
+ let n = 0
9582
+ if (v.name !== undefined) {
9583
+ w.field(1)
9584
+ w.str(v.name)
9585
+ n++
9586
+ }
9587
+ if (v.count !== undefined) {
9588
+ w.field(2)
9589
+ w.uint(v.count)
9590
+ n++
9591
+ }
9592
+ w.closeMap(head, n)
9593
+ },
9594
+ read(r) {
9595
+ let $name: string | undefined
9596
+ let $count: number | undefined
9597
+ for (let n = r.message(); n > 0; n--) {
9598
+ switch (r.field()) {
9599
+ case 1:
9600
+ $name = r.str()
9601
+ break
9602
+ case 2:
9603
+ $count = r.uint()
9604
+ break
9605
+ default:
9606
+ r.skip()
9607
+ }
9608
+ }
9609
+ r.leave()
9610
+ return { name: $name, count: $count }
9611
+ },
9612
+ },
9613
+ )
9614
+
9615
+ /**
9616
+ * A key of a stream's events' fields or contexts.
9617
+ */
9618
+ export const RecordsFieldInfo = message(
9619
+ 'records.FieldInfo',
9620
+ {
9621
+ name: [1, str],
9622
+ /** float, integer, text, bool, object, list or null, in that order */
9623
+ kinds: [2, list(str)],
9624
+ /** the events that carry it */
9625
+ count: [3, uint],
9626
+ },
9627
+ {
9628
+ write(w, v) {
9629
+ const head = w.openMap()
9630
+ let n = 0
9631
+ if (v.name !== undefined) {
9632
+ w.field(1)
9633
+ w.str(v.name)
9634
+ n++
9635
+ }
9636
+ if (v.kinds !== undefined) {
9637
+ w.field(2)
9638
+ w.array(v.kinds.length)
9639
+ for (const item0 of v.kinds) {
9640
+ w.str(item0)
9641
+ }
9642
+ n++
9643
+ }
9644
+ if (v.count !== undefined) {
9645
+ w.field(3)
9646
+ w.uint(v.count)
9647
+ n++
9648
+ }
9649
+ w.closeMap(head, n)
9650
+ },
9651
+ read(r) {
9652
+ let $name: string | undefined
9653
+ let $kinds: string[] | undefined
9654
+ let $count: number | undefined
9655
+ for (let n = r.message(); n > 0; n--) {
9656
+ switch (r.field()) {
9657
+ case 1:
9658
+ $name = r.str()
9659
+ break
9660
+ case 2: {
9661
+ const items0: string[] = []
9662
+ for (let i0 = r.array(); i0 > 0; i0--) {
9663
+ items0.push(r.str())
9664
+ }
9665
+ r.leave()
9666
+ $kinds = items0
9667
+ break
9668
+ }
9669
+ case 3:
9670
+ $count = r.uint()
9671
+ break
9672
+ default:
9673
+ r.skip()
9674
+ }
9675
+ }
9676
+ r.leave()
9677
+ return { name: $name, kinds: $kinds, count: $count }
9678
+ },
9679
+ },
9680
+ )
9681
+
9682
+ export const RecordsStreamFields = message(
9683
+ 'records.StreamFields',
9684
+ {
9685
+ eventNames: [1, list(RecordsNameCount)],
9686
+ fields: [2, list(RecordsFieldInfo)],
9687
+ context: [3, list(RecordsFieldInfo)],
9688
+ },
9689
+ {
9690
+ write(w, v) {
9691
+ const head = w.openMap()
9692
+ let n = 0
9693
+ if (v.eventNames !== undefined) {
9694
+ w.field(1)
9695
+ w.array(v.eventNames.length)
9696
+ for (const item0 of v.eventNames) {
9697
+ RecordsNameCount.write(w, item0)
9698
+ }
9699
+ n++
9700
+ }
9701
+ if (v.fields !== undefined) {
9702
+ w.field(2)
9703
+ w.array(v.fields.length)
9704
+ for (const item0 of v.fields) {
9705
+ RecordsFieldInfo.write(w, item0)
9706
+ }
9707
+ n++
9708
+ }
9709
+ if (v.context !== undefined) {
9710
+ w.field(3)
9711
+ w.array(v.context.length)
9712
+ for (const item0 of v.context) {
9713
+ RecordsFieldInfo.write(w, item0)
9714
+ }
9715
+ n++
9716
+ }
9717
+ w.closeMap(head, n)
9718
+ },
9719
+ read(r) {
9720
+ let $eventNames: Read<typeof RecordsNameCount.fields>[] | undefined
9721
+ let $fields: Read<typeof RecordsFieldInfo.fields>[] | undefined
9722
+ let $context: Read<typeof RecordsFieldInfo.fields>[] | undefined
9723
+ for (let n = r.message(); n > 0; n--) {
9724
+ switch (r.field()) {
9725
+ case 1: {
9726
+ const items0: Read<typeof RecordsNameCount.fields>[] = []
9727
+ for (let i0 = r.array(); i0 > 0; i0--) {
9728
+ items0.push(RecordsNameCount.read(r))
9729
+ }
9730
+ r.leave()
9731
+ $eventNames = items0
9732
+ break
9733
+ }
9734
+ case 2: {
9735
+ const items0: Read<typeof RecordsFieldInfo.fields>[] = []
9736
+ for (let i0 = r.array(); i0 > 0; i0--) {
9737
+ items0.push(RecordsFieldInfo.read(r))
9738
+ }
9739
+ r.leave()
9740
+ $fields = items0
9741
+ break
9742
+ }
9743
+ case 3: {
9744
+ const items0: Read<typeof RecordsFieldInfo.fields>[] = []
9745
+ for (let i0 = r.array(); i0 > 0; i0--) {
9746
+ items0.push(RecordsFieldInfo.read(r))
9747
+ }
9748
+ r.leave()
9749
+ $context = items0
9750
+ break
9751
+ }
9752
+ default:
9753
+ r.skip()
9754
+ }
9755
+ }
9756
+ r.leave()
9757
+ return { eventNames: $eventNames, fields: $fields, context: $context }
9758
+ },
9759
+ },
9760
+ )
9761
+
9455
9762
  /**
9456
9763
  * The keys the events a query finds hold, sorted.
9457
9764
  */
@@ -10906,15 +11213,17 @@ export const SqlOpen = message(
10906
11213
 
10907
11214
  /**
10908
11215
  * A statement's text and the values of its ?s, in order. In a batch it may
10909
- * be a call of jobs on a queue kept in the database's file instead, jobs.add
10910
- * with its request in body and no text, which commits with the batch's rows.
11216
+ * be a call of another engine instead, with its request in body and no
11217
+ * text, which commits with the batch's rows: jobs.add on a queue kept in the
11218
+ * database's file, or records.append on a stream opened through the
11219
+ * database, whose events reach the stream before the batch answers.
10911
11220
  */
10912
11221
  export const SqlText = message(
10913
11222
  'sql.Text',
10914
11223
  {
10915
11224
  text: [1, str],
10916
11225
  values: [2, list(sqlValue)],
10917
- /** in a batch, jobs.add: the call in body */
11226
+ /** in a batch, jobs.add or records.append: the call in body */
10918
11227
  method: [3, uint],
10919
11228
  body: [4, bin],
10920
11229
  },
@@ -11408,7 +11717,8 @@ export const SqlDone = message(
11408
11717
 
11409
11718
  /**
11410
11719
  * Writes known before they run, written as one in a shared commit: its
11411
- * statements, and the adds of a queue kept in the database's file.
11720
+ * statements, the adds of a queue kept in the database's file, and the
11721
+ * appends of a stream opened through the database.
11412
11722
  */
11413
11723
  export const SqlBatch = message(
11414
11724
  'sql.Batch',
@@ -11464,7 +11774,8 @@ export const SqlBatch = message(
11464
11774
 
11465
11775
  /**
11466
11776
  * What each write of a batch did, in their order: a job's add changed one
11467
- * job, or none when its id was taken.
11777
+ * job, or none when its id was taken, and a stream's append the events its
11778
+ * stream holds no id of.
11468
11779
  */
11469
11780
  export const SqlBatched = message(
11470
11781
  'sql.Batched',
@@ -11549,7 +11860,9 @@ export const SqlTxOpen = message(
11549
11860
  * A transaction's call, or its end: the last DATA commits, or not. A call is
11550
11861
  * a statement, or a call of kv or jobs on a bucket or a queue kept in the
11551
11862
  * database's file: a method of theirs with its request, kv.set or jobs.add,
11552
- * which runs in the transaction.
11863
+ * which runs in the transaction; or records.append on a stream opened
11864
+ * through the database, whose events reach the stream once the transaction
11865
+ * commits, before its last DATA answers.
11553
11866
  */
11554
11867
  export const SqlTxCall = message(
11555
11868
  'sql.TxCall',