@tinyshed/tinystore 0.1.1 → 0.2.0-rc.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/dist/index.d.ts +1 -1
- package/dist/jobs.d.ts +2 -0
- package/dist/jobs.js +1 -0
- package/dist/metrics.d.ts +5 -1
- package/dist/metrics.js +2 -0
- package/dist/records.d.ts +18 -5
- package/dist/records.js +14 -3
- package/dist/time.d.ts +2 -0
- package/dist/wire/protocol.d.ts +34 -0
- package/dist/wire/protocol.js +123 -1
- package/package.json +8 -8
- package/src/index.ts +1 -1
- package/src/jobs.ts +3 -0
- package/src/metrics.ts +7 -1
- package/src/records.ts +33 -8
- package/src/time.ts +3 -0
- package/src/wire/protocol.ts +128 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type { StandardSchemaV1 } from './schema.ts';
|
|
|
21
21
|
export { type Found as SearchFound, type Hit as SearchHit, type IndexDocument, type IndexInfo, type IndexOptions, type IndexStatus, type Query as SearchQuery, SearchIndex, search, TableIndex, type TableIndexOptions, type Vector, type Where, type WhereValue, } from './search.ts';
|
|
22
22
|
export { type Columns, type Database, type DatabaseOptions, type Done, type Migrations, type Row, Sql, type SqlArg, type SqlTag, type SqlTx, type SqlValue, type Statement, sql, } from './sql.ts';
|
|
23
23
|
export { type ConnectOptions, connect, type NodeOptions, type OpenOptions, open, type Status, Store, } from './store.ts';
|
|
24
|
-
export type { Duration, DurationText, Time } from './time.ts';
|
|
24
|
+
export type { Calendar, Duration, DurationText, Time } from './time.ts';
|
|
25
25
|
export { type Trace, withTrace } from './trace.ts';
|
|
26
26
|
export type { Tx, TxBucket, TxCounters } from './tx.ts';
|
|
27
27
|
export type { Key } from './wire/codec.ts';
|
package/dist/jobs.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface QueueOptions {
|
|
|
28
28
|
concurrency?: number | Concurrency | undefined;
|
|
29
29
|
/** jobs started in any span: '30/s' */
|
|
30
30
|
rate?: Rate | undefined;
|
|
31
|
+
/** jobs of each group started in any span, beside rate: '2/s', each account's own limit; it lives in memory */
|
|
32
|
+
groupRate?: Rate | undefined;
|
|
31
33
|
/** how long a done job's id stays taken, so that an add of it adds nothing */
|
|
32
34
|
dedupe?: Duration | undefined;
|
|
33
35
|
/** how long a failed job stays, to be found and started again: a week */
|
package/dist/jobs.js
CHANGED
|
@@ -644,6 +644,7 @@ export function openQueue(link, workers, name, options, home) {
|
|
|
644
644
|
group: whole(concurrency.group, describe, "a group's concurrency"),
|
|
645
645
|
},
|
|
646
646
|
rate: options.rate === undefined ? undefined : rateOf(options.rate),
|
|
647
|
+
groupRate: options.groupRate === undefined ? undefined : rateOf(options.groupRate),
|
|
647
648
|
dedupe: msOf(options.dedupe),
|
|
648
649
|
keep: msOf(options.keep),
|
|
649
650
|
maxWaiting: whole(options.maxWaiting, describe, 'a maxWaiting'),
|
package/dist/metrics.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Link } from './connection.ts';
|
|
2
2
|
import { Counter, Gauge, type GaugeFuncOptions, Histogram, type HistogramOptions, type InstrumentOptions, type Instruments, type LabelValue, Timer, type TimerOptions } from './instruments.ts';
|
|
3
|
-
import { type Duration, type DurationText, type Time } from './time.ts';
|
|
3
|
+
import { type Calendar, type Duration, type DurationText, type Time } from './time.ts';
|
|
4
4
|
export { type Buckets, Counter, exponentialBuckets, Gauge, type GaugeFuncOptions, Histogram, type HistogramOptions, type InstrumentLabels, type InstrumentOptions, type LabelValue, Timer, type TimerOptions, Timing, } from './instruments.ts';
|
|
5
5
|
/** What a series' samples are. */
|
|
6
6
|
export type SeriesKind = 'gauge' | 'counter' | 'histogram';
|
|
@@ -69,6 +69,10 @@ export type Op = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'increase' | 'rate' |
|
|
|
69
69
|
export interface AggregateQuery<O extends Op = Op> extends Query {
|
|
70
70
|
/** the buckets' span, counted from 1970 in UTC; the range is one bucket without it */
|
|
71
71
|
every?: Duration | undefined;
|
|
72
|
+
/** buckets of a calendar in timeZone, in place of every: 'day' begins each at a local midnight */
|
|
73
|
+
calendar?: Calendar | undefined;
|
|
74
|
+
/** the IANA zone a calendar's buckets are in: 'Europe/Moscow', 'UTC' */
|
|
75
|
+
timeZone?: string | undefined;
|
|
72
76
|
op: O;
|
|
73
77
|
/** the labels a group keeps; without by and without, every series of a name is one group */
|
|
74
78
|
by?: readonly string[] | undefined;
|
package/dist/metrics.js
CHANGED
|
@@ -287,6 +287,8 @@ function aggregateOf(query) {
|
|
|
287
287
|
return {
|
|
288
288
|
query: queryOf(query),
|
|
289
289
|
every: query.every === undefined ? undefined : ms(query.every),
|
|
290
|
+
calendar: query.calendar,
|
|
291
|
+
timeZone: query.timeZone,
|
|
290
292
|
op: query.op,
|
|
291
293
|
by: query.by === undefined ? undefined : [...query.by],
|
|
292
294
|
without: query.without === undefined ? undefined : [...query.without],
|
package/dist/records.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type Link } from './connection.ts';
|
|
|
2
2
|
import { type ConsoleLine } from './console.ts';
|
|
3
3
|
import { type LogConfig, type Logger, type LoggerOptions } from './logger.ts';
|
|
4
4
|
import type { Stream } from './session.ts';
|
|
5
|
-
import { type Duration, type DurationText } from './time.ts';
|
|
5
|
+
import { type Calendar, type Duration, type DurationText } from './time.ts';
|
|
6
6
|
import { methods } from './wire/protocol.ts';
|
|
7
7
|
/** A level a logger logs at: one of its four names, or slog's number between them. */
|
|
8
8
|
export type Level = 'debug' | 'info' | 'warn' | 'error' | number;
|
|
@@ -15,6 +15,8 @@ export interface Event {
|
|
|
15
15
|
/** its time, which the file keeps to the nanosecond */
|
|
16
16
|
at: Date;
|
|
17
17
|
stream: string;
|
|
18
|
+
/** what its append named it by: its stream holds one event of an id */
|
|
19
|
+
id?: string;
|
|
18
20
|
/** what happened; `log` for a logger's line */
|
|
19
21
|
name: string;
|
|
20
22
|
level?: EventLevel;
|
|
@@ -30,6 +32,11 @@ export interface Event {
|
|
|
30
32
|
/** An event to append: its name, what happened, and what it carries beside. */
|
|
31
33
|
export interface NewEvent {
|
|
32
34
|
name: string;
|
|
35
|
+
/**
|
|
36
|
+
* what names it in its stream, a webhook's delivery or a job's key, 1 to 128 bytes:
|
|
37
|
+
* an append of an id the stream holds writes nothing, and the first event of an id stands
|
|
38
|
+
*/
|
|
39
|
+
id?: string;
|
|
33
40
|
fields?: Fields;
|
|
34
41
|
/** its time: now unless given, from what the stream keeps to ten minutes ahead */
|
|
35
42
|
at?: Date;
|
|
@@ -101,6 +108,10 @@ export interface Row {
|
|
|
101
108
|
export interface Aggregate extends Counted {
|
|
102
109
|
/** the span of a row: the range is one without it */
|
|
103
110
|
every?: Duration;
|
|
111
|
+
/** rows of a calendar in timeZone, in place of every: 'day' begins each at a local midnight */
|
|
112
|
+
calendar?: Calendar;
|
|
113
|
+
/** the IANA zone a calendar's rows are in: 'Europe/Moscow', 'UTC' */
|
|
114
|
+
timeZone?: string;
|
|
104
115
|
/** keys whose every value has rows of its own */
|
|
105
116
|
by?: readonly string[];
|
|
106
117
|
/** fields whose numbers a row sums */
|
|
@@ -187,11 +198,13 @@ export declare class Events extends Reads {
|
|
|
187
198
|
constructor(link: Link, stream: string, open: Uint8Array);
|
|
188
199
|
/**
|
|
189
200
|
* Writes an event, or a list of them whole or not at all: it returns once
|
|
190
|
-
* they are written, and a read finds them at once.
|
|
191
|
-
*
|
|
201
|
+
* they are written, and a read finds them at once. An event whose id the
|
|
202
|
+
* stream holds, or an earlier event of the list has, is written as
|
|
203
|
+
* nothing: one event answers whether it was written, a list how many of
|
|
204
|
+
* its events were. A refused event names its place in the list and its name.
|
|
192
205
|
*/
|
|
193
|
-
append(name: string, fields?: Fields, options?: AppendOptions): Promise<
|
|
194
|
-
append(events: readonly NewEvent[]): Promise<
|
|
206
|
+
append(name: string, fields?: Fields, options?: AppendOptions): Promise<boolean>;
|
|
207
|
+
append(events: readonly NewEvent[]): Promise<number>;
|
|
195
208
|
/** A logger's lines, each an event of this stream. */
|
|
196
209
|
appendLines(lines: readonly ConsoleLine[]): Promise<void>;
|
|
197
210
|
/**
|
package/dist/records.js
CHANGED
|
@@ -12,7 +12,7 @@ import { parseJson } from './json.js';
|
|
|
12
12
|
import { encodeFields, newStoreLogger, } from './logger.js';
|
|
13
13
|
import { ms } from './time.js';
|
|
14
14
|
import { currentTrace } from './trace.js';
|
|
15
|
-
import { Empty, Handle, methods, RecordsAggregateAsked, RecordsAppend, RecordsBatch, RecordsCount, RecordsDamage, RecordsDamages, RecordsDropped, RecordsFieldNamesAsked, RecordsNames, RecordsOpen, RecordsPage, RecordsPiece, RecordsPollAsked, RecordsQuery, RecordsRows, RecordsStreams, RecordsTailBatch, RecordsTopAsked, RecordsTops, } from './wire/protocol.js';
|
|
15
|
+
import { Empty, Handle, methods, RecordsAggregateAsked, RecordsAppend, RecordsAppended, RecordsBatch, RecordsCount, RecordsDamage, RecordsDamages, RecordsDropped, RecordsFieldNamesAsked, RecordsNames, RecordsOpen, RecordsPage, RecordsPiece, RecordsPollAsked, RecordsQuery, RecordsRows, RecordsStreams, RecordsTailBatch, RecordsTopAsked, RecordsTops, } from './wire/protocol.js';
|
|
16
16
|
const newline = 0x0a;
|
|
17
17
|
/** What a writer of lines holds for the server at most: past it, lines are dropped and counted. */
|
|
18
18
|
const linesHeld = 1 << 20;
|
|
@@ -71,11 +71,13 @@ class Reads {
|
|
|
71
71
|
}
|
|
72
72
|
/** A row for each span of `every` and each value of the keys of `by`, with its count. */
|
|
73
73
|
async aggregate(query = {}) {
|
|
74
|
-
const { every, by, stats, distinct, ...counted } = query;
|
|
74
|
+
const { every, calendar, timeZone, by, stats, distinct, ...counted } = query;
|
|
75
75
|
const asked = queryOf(counted);
|
|
76
76
|
const answer = await this.ask('records.aggregate', handle => RecordsAggregateAsked.encode({
|
|
77
77
|
query: { ...asked, handle },
|
|
78
78
|
every: every === undefined ? undefined : ms(every),
|
|
79
|
+
calendar,
|
|
80
|
+
timeZone,
|
|
79
81
|
by: by === undefined ? undefined : [...by],
|
|
80
82
|
stats: stats === undefined ? undefined : [...stats],
|
|
81
83
|
distinct: distinct === undefined ? undefined : [...distinct],
|
|
@@ -151,7 +153,9 @@ export class Events extends Reads {
|
|
|
151
153
|
async append(first, fields, options) {
|
|
152
154
|
const events = typeof first === 'string' ? [oneEvent(first, fields, options)] : first;
|
|
153
155
|
const encoded = events.map(newEventOf);
|
|
154
|
-
await this.#call('records.append', handle => RecordsAppend.encode({ handle, events: encoded }), 'write');
|
|
156
|
+
const answer = await this.#call('records.append', handle => RecordsAppend.encode({ handle, events: encoded }), 'write');
|
|
157
|
+
const written = events.length - (RecordsAppended.decode(answer).held ?? 0);
|
|
158
|
+
return typeof first === 'string' ? written === 1 : written;
|
|
155
159
|
}
|
|
156
160
|
/** A logger's lines, each an event of this stream. */
|
|
157
161
|
appendLines(lines) {
|
|
@@ -437,8 +441,12 @@ function newEventOf(event, place) {
|
|
|
437
441
|
const given = event.traceId === undefined
|
|
438
442
|
? traceOf(currentTrace())
|
|
439
443
|
: { traceId: event.traceId, spanId: event.spanId };
|
|
444
|
+
if (event.id !== undefined && (typeof event.id !== 'string' || event.id === '')) {
|
|
445
|
+
throw new InvalidError(`${named}: an id is a string of 1 to 128 bytes`);
|
|
446
|
+
}
|
|
440
447
|
return {
|
|
441
448
|
name: event.name,
|
|
449
|
+
id: event.id,
|
|
442
450
|
at: event.at === undefined ? undefined : nanosOf(event.at),
|
|
443
451
|
level: event.level === undefined ? undefined : levelNumber(event.level, named),
|
|
444
452
|
message: event.message,
|
|
@@ -492,6 +500,9 @@ function eventOf(read) {
|
|
|
492
500
|
if (read.message !== undefined) {
|
|
493
501
|
event.message = read.message;
|
|
494
502
|
}
|
|
503
|
+
if (read.id !== undefined) {
|
|
504
|
+
event.id = read.id;
|
|
505
|
+
}
|
|
495
506
|
if (read.traceId !== undefined) {
|
|
496
507
|
event.traceId = Buffer.from(read.traceId).toString('hex');
|
|
497
508
|
}
|
package/dist/time.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ type Offered = '1s' | '5s' | '10s' | '15s' | '30s' | '1m' | '5m' | '10m' | '15m'
|
|
|
23
23
|
export type DurationText = Offered | (Spelled<Units> & Record<never, never>);
|
|
24
24
|
/** A length of time: milliseconds, or the text of one, such as '1h30m'. */
|
|
25
25
|
export type Duration = number | DurationText;
|
|
26
|
+
/** A span of a calendar an aggregate's bucket covers in its timeZone: a local day, a week from Monday, a month. */
|
|
27
|
+
export type Calendar = 'day' | 'week' | 'month';
|
|
26
28
|
/** A moment: a Date, or unix milliseconds. */
|
|
27
29
|
export type Time = Date | number;
|
|
28
30
|
/**
|
package/dist/wire/protocol.d.ts
CHANGED
|
@@ -601,6 +601,11 @@ export declare const JobsQueueOpen: import("./codec.ts").Message<{
|
|
|
601
601
|
readonly maxWaiting: readonly [9, import("./codec.ts").Codec<number, number>];
|
|
602
602
|
/** a database's handle: the queue lives in its file; jobs.db when absent */
|
|
603
603
|
readonly database: readonly [10, import("./codec.ts").Codec<number, number>];
|
|
604
|
+
/** each group's starts, beside the queue's rate */
|
|
605
|
+
readonly groupRate: readonly [11, import("./codec.ts").Message<{
|
|
606
|
+
readonly count: readonly [1, import("./codec.ts").Codec<number, number>];
|
|
607
|
+
readonly per: readonly [2, import("./codec.ts").Codec<number, number>];
|
|
608
|
+
}>];
|
|
604
609
|
}>;
|
|
605
610
|
/**
|
|
606
611
|
* Opens a schedule: one repeating job the code owns, under its name, whose
|
|
@@ -1379,6 +1384,10 @@ export declare const MetricsAggregateAsked: import("./codec.ts").Message<{
|
|
|
1379
1384
|
readonly without: readonly [5, import("./codec.ts").Codec<string[], readonly string[]>];
|
|
1380
1385
|
/** a timer's percentile also gives a point between its bounds */
|
|
1381
1386
|
readonly estimate: readonly [6, import("./codec.ts").Codec<boolean, boolean>];
|
|
1387
|
+
/** day, week or month: buckets of a calendar in timeZone, in place of every */
|
|
1388
|
+
readonly calendar: readonly [7, import("./codec.ts").Codec<string, string>];
|
|
1389
|
+
/** an IANA name, UTC among them, which calendar takes */
|
|
1390
|
+
readonly timeZone: readonly [8, import("./codec.ts").Codec<string, string>];
|
|
1382
1391
|
}>;
|
|
1383
1392
|
/**
|
|
1384
1393
|
* A bucket of an aggregate: its value, or a timer's percentile's bounds.
|
|
@@ -1842,6 +1851,8 @@ export declare const RecordsNewEvent: import("./codec.ts").Message<{
|
|
|
1842
1851
|
readonly traceId: readonly [7, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1843
1852
|
/** 8 bytes */
|
|
1844
1853
|
readonly spanId: readonly [8, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1854
|
+
/** 1 to 128 bytes: an event of an id its stream holds is written as nothing */
|
|
1855
|
+
readonly id: readonly [9, import("./codec.ts").Codec<string, string>];
|
|
1845
1856
|
}>;
|
|
1846
1857
|
/**
|
|
1847
1858
|
* Events to write to a stream, all of them or none.
|
|
@@ -1863,6 +1874,8 @@ export declare const RecordsAppend: import("./codec.ts").Message<{
|
|
|
1863
1874
|
readonly traceId: readonly [7, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1864
1875
|
/** 8 bytes */
|
|
1865
1876
|
readonly spanId: readonly [8, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1877
|
+
/** 1 to 128 bytes: an event of an id its stream holds is written as nothing */
|
|
1878
|
+
readonly id: readonly [9, import("./codec.ts").Codec<string, string>];
|
|
1866
1879
|
}>[], readonly import("./codec.ts").Written<{
|
|
1867
1880
|
readonly name: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
1868
1881
|
/** the store's clock's now unless given */
|
|
@@ -1878,8 +1891,18 @@ export declare const RecordsAppend: import("./codec.ts").Message<{
|
|
|
1878
1891
|
readonly traceId: readonly [7, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1879
1892
|
/** 8 bytes */
|
|
1880
1893
|
readonly spanId: readonly [8, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1894
|
+
/** 1 to 128 bytes: an event of an id its stream holds is written as nothing */
|
|
1895
|
+
readonly id: readonly [9, import("./codec.ts").Codec<string, string>];
|
|
1881
1896
|
}>[]>];
|
|
1882
1897
|
}>;
|
|
1898
|
+
/**
|
|
1899
|
+
* What an append wrote: none of an event whose id its stream held, or an
|
|
1900
|
+
* earlier event of the append held.
|
|
1901
|
+
*/
|
|
1902
|
+
export declare const RecordsAppended: import("./codec.ts").Message<{
|
|
1903
|
+
/** the events written as nothing */
|
|
1904
|
+
readonly held: readonly [1, import("./codec.ts").Codec<number, number>];
|
|
1905
|
+
}>;
|
|
1883
1906
|
/**
|
|
1884
1907
|
* An event as a read gives it.
|
|
1885
1908
|
*/
|
|
@@ -1894,6 +1917,7 @@ export declare const RecordsEvent: import("./codec.ts").Message<{
|
|
|
1894
1917
|
readonly context: readonly [7, import("./codec.ts").Codec<string, string>];
|
|
1895
1918
|
readonly traceId: readonly [8, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1896
1919
|
readonly spanId: readonly [9, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1920
|
+
readonly id: readonly [10, import("./codec.ts").Codec<string, string>];
|
|
1897
1921
|
}>;
|
|
1898
1922
|
/**
|
|
1899
1923
|
* What a read finds: each condition given holds.
|
|
@@ -1930,6 +1954,7 @@ export declare const RecordsPage: import("./codec.ts").Message<{
|
|
|
1930
1954
|
readonly context: readonly [7, import("./codec.ts").Codec<string, string>];
|
|
1931
1955
|
readonly traceId: readonly [8, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1932
1956
|
readonly spanId: readonly [9, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1957
|
+
readonly id: readonly [10, import("./codec.ts").Codec<string, string>];
|
|
1933
1958
|
}>[], readonly import("./codec.ts").Written<{
|
|
1934
1959
|
readonly at: readonly [1, import("./codec.ts").Codec<bigint, number | bigint>];
|
|
1935
1960
|
readonly stream: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
@@ -1941,6 +1966,7 @@ export declare const RecordsPage: import("./codec.ts").Message<{
|
|
|
1941
1966
|
readonly context: readonly [7, import("./codec.ts").Codec<string, string>];
|
|
1942
1967
|
readonly traceId: readonly [8, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1943
1968
|
readonly spanId: readonly [9, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
1969
|
+
readonly id: readonly [10, import("./codec.ts").Codec<string, string>];
|
|
1944
1970
|
}>[]>];
|
|
1945
1971
|
/** the page after it; the last page has none */
|
|
1946
1972
|
readonly next: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
@@ -2016,6 +2042,10 @@ export declare const RecordsAggregateAsked: import("./codec.ts").Message<{
|
|
|
2016
2042
|
readonly by: readonly [3, import("./codec.ts").Codec<string[], readonly string[]>];
|
|
2017
2043
|
readonly stats: readonly [4, import("./codec.ts").Codec<string[], readonly string[]>];
|
|
2018
2044
|
readonly distinct: readonly [5, import("./codec.ts").Codec<string[], readonly string[]>];
|
|
2045
|
+
/** day, week or month: rows of a calendar in timeZone, in place of every */
|
|
2046
|
+
readonly calendar: readonly [6, import("./codec.ts").Codec<string, string>];
|
|
2047
|
+
/** an IANA name, UTC among them, which calendar takes */
|
|
2048
|
+
readonly timeZone: readonly [7, import("./codec.ts").Codec<string, string>];
|
|
2019
2049
|
}>;
|
|
2020
2050
|
/**
|
|
2021
2051
|
* A field's numbers in a row: a sum, a min and a max are JSON numbers, an
|
|
@@ -2161,6 +2191,7 @@ export declare const RecordsBatch: import("./codec.ts").Message<{
|
|
|
2161
2191
|
readonly context: readonly [7, import("./codec.ts").Codec<string, string>];
|
|
2162
2192
|
readonly traceId: readonly [8, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
2163
2193
|
readonly spanId: readonly [9, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
2194
|
+
readonly id: readonly [10, import("./codec.ts").Codec<string, string>];
|
|
2164
2195
|
}>[], readonly import("./codec.ts").Written<{
|
|
2165
2196
|
readonly at: readonly [1, import("./codec.ts").Codec<bigint, number | bigint>];
|
|
2166
2197
|
readonly stream: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
@@ -2172,6 +2203,7 @@ export declare const RecordsBatch: import("./codec.ts").Message<{
|
|
|
2172
2203
|
readonly context: readonly [7, import("./codec.ts").Codec<string, string>];
|
|
2173
2204
|
readonly traceId: readonly [8, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
2174
2205
|
readonly spanId: readonly [9, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
2206
|
+
readonly id: readonly [10, import("./codec.ts").Codec<string, string>];
|
|
2175
2207
|
}>[]>];
|
|
2176
2208
|
readonly cursor: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
2177
2209
|
/** the events keep removed before the cursor reached them */
|
|
@@ -2193,6 +2225,7 @@ export declare const RecordsTailBatch: import("./codec.ts").Message<{
|
|
|
2193
2225
|
readonly context: readonly [7, import("./codec.ts").Codec<string, string>];
|
|
2194
2226
|
readonly traceId: readonly [8, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
2195
2227
|
readonly spanId: readonly [9, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
2228
|
+
readonly id: readonly [10, import("./codec.ts").Codec<string, string>];
|
|
2196
2229
|
}>[], readonly import("./codec.ts").Written<{
|
|
2197
2230
|
readonly at: readonly [1, import("./codec.ts").Codec<bigint, number | bigint>];
|
|
2198
2231
|
readonly stream: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
@@ -2204,6 +2237,7 @@ export declare const RecordsTailBatch: import("./codec.ts").Message<{
|
|
|
2204
2237
|
readonly context: readonly [7, import("./codec.ts").Codec<string, string>];
|
|
2205
2238
|
readonly traceId: readonly [8, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
2206
2239
|
readonly spanId: readonly [9, import("./codec.ts").Codec<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>];
|
|
2240
|
+
readonly id: readonly [10, import("./codec.ts").Codec<string, string>];
|
|
2207
2241
|
}>[]>];
|
|
2208
2242
|
readonly missed: readonly [2, import("./codec.ts").Codec<number, number>];
|
|
2209
2243
|
}>;
|
package/dist/wire/protocol.js
CHANGED
|
@@ -2569,6 +2569,8 @@ export const JobsQueueOpen = message('jobs.QueueOpen', {
|
|
|
2569
2569
|
maxWaiting: [9, uint],
|
|
2570
2570
|
/** a database's handle: the queue lives in its file; jobs.db when absent */
|
|
2571
2571
|
database: [10, uint],
|
|
2572
|
+
/** each group's starts, beside the queue's rate */
|
|
2573
|
+
groupRate: [11, JobsRate],
|
|
2572
2574
|
}, {
|
|
2573
2575
|
write(w, v) {
|
|
2574
2576
|
const head = w.openMap();
|
|
@@ -2623,6 +2625,11 @@ export const JobsQueueOpen = message('jobs.QueueOpen', {
|
|
|
2623
2625
|
w.uint(v.database);
|
|
2624
2626
|
n++;
|
|
2625
2627
|
}
|
|
2628
|
+
if (v.groupRate !== undefined) {
|
|
2629
|
+
w.field(11);
|
|
2630
|
+
JobsRate.write(w, v.groupRate);
|
|
2631
|
+
n++;
|
|
2632
|
+
}
|
|
2626
2633
|
w.closeMap(head, n);
|
|
2627
2634
|
},
|
|
2628
2635
|
read(r) {
|
|
@@ -2636,6 +2643,7 @@ export const JobsQueueOpen = message('jobs.QueueOpen', {
|
|
|
2636
2643
|
let $keep;
|
|
2637
2644
|
let $maxWaiting;
|
|
2638
2645
|
let $database;
|
|
2646
|
+
let $groupRate;
|
|
2639
2647
|
for (let n = r.message(); n > 0; n--) {
|
|
2640
2648
|
switch (r.field()) {
|
|
2641
2649
|
case 1:
|
|
@@ -2668,6 +2676,9 @@ export const JobsQueueOpen = message('jobs.QueueOpen', {
|
|
|
2668
2676
|
case 10:
|
|
2669
2677
|
$database = r.uint();
|
|
2670
2678
|
break;
|
|
2679
|
+
case 11:
|
|
2680
|
+
$groupRate = JobsRate.read(r);
|
|
2681
|
+
break;
|
|
2671
2682
|
default:
|
|
2672
2683
|
r.skip();
|
|
2673
2684
|
}
|
|
@@ -2684,6 +2695,7 @@ export const JobsQueueOpen = message('jobs.QueueOpen', {
|
|
|
2684
2695
|
keep: $keep,
|
|
2685
2696
|
maxWaiting: $maxWaiting,
|
|
2686
2697
|
database: $database,
|
|
2698
|
+
groupRate: $groupRate,
|
|
2687
2699
|
};
|
|
2688
2700
|
},
|
|
2689
2701
|
});
|
|
@@ -5684,6 +5696,10 @@ export const MetricsAggregateAsked = message('metrics.AggregateAsked', {
|
|
|
5684
5696
|
without: [5, list(str)],
|
|
5685
5697
|
/** a timer's percentile also gives a point between its bounds */
|
|
5686
5698
|
estimate: [6, bool],
|
|
5699
|
+
/** day, week or month: buckets of a calendar in timeZone, in place of every */
|
|
5700
|
+
calendar: [7, str],
|
|
5701
|
+
/** an IANA name, UTC among them, which calendar takes */
|
|
5702
|
+
timeZone: [8, str],
|
|
5687
5703
|
}, {
|
|
5688
5704
|
write(w, v) {
|
|
5689
5705
|
const head = w.openMap();
|
|
@@ -5724,6 +5740,16 @@ export const MetricsAggregateAsked = message('metrics.AggregateAsked', {
|
|
|
5724
5740
|
w.bool(v.estimate);
|
|
5725
5741
|
n++;
|
|
5726
5742
|
}
|
|
5743
|
+
if (v.calendar !== undefined) {
|
|
5744
|
+
w.field(7);
|
|
5745
|
+
w.str(v.calendar);
|
|
5746
|
+
n++;
|
|
5747
|
+
}
|
|
5748
|
+
if (v.timeZone !== undefined) {
|
|
5749
|
+
w.field(8);
|
|
5750
|
+
w.str(v.timeZone);
|
|
5751
|
+
n++;
|
|
5752
|
+
}
|
|
5727
5753
|
w.closeMap(head, n);
|
|
5728
5754
|
},
|
|
5729
5755
|
read(r) {
|
|
@@ -5733,6 +5759,8 @@ export const MetricsAggregateAsked = message('metrics.AggregateAsked', {
|
|
|
5733
5759
|
let $by;
|
|
5734
5760
|
let $without;
|
|
5735
5761
|
let $estimate;
|
|
5762
|
+
let $calendar;
|
|
5763
|
+
let $timeZone;
|
|
5736
5764
|
for (let n = r.message(); n > 0; n--) {
|
|
5737
5765
|
switch (r.field()) {
|
|
5738
5766
|
case 1:
|
|
@@ -5765,6 +5793,12 @@ export const MetricsAggregateAsked = message('metrics.AggregateAsked', {
|
|
|
5765
5793
|
case 6:
|
|
5766
5794
|
$estimate = r.bool();
|
|
5767
5795
|
break;
|
|
5796
|
+
case 7:
|
|
5797
|
+
$calendar = r.str();
|
|
5798
|
+
break;
|
|
5799
|
+
case 8:
|
|
5800
|
+
$timeZone = r.str();
|
|
5801
|
+
break;
|
|
5768
5802
|
default:
|
|
5769
5803
|
r.skip();
|
|
5770
5804
|
}
|
|
@@ -5777,6 +5811,8 @@ export const MetricsAggregateAsked = message('metrics.AggregateAsked', {
|
|
|
5777
5811
|
by: $by,
|
|
5778
5812
|
without: $without,
|
|
5779
5813
|
estimate: $estimate,
|
|
5814
|
+
calendar: $calendar,
|
|
5815
|
+
timeZone: $timeZone,
|
|
5780
5816
|
};
|
|
5781
5817
|
},
|
|
5782
5818
|
});
|
|
@@ -7398,6 +7434,8 @@ export const RecordsNewEvent = message('records.NewEvent', {
|
|
|
7398
7434
|
traceId: [7, bin],
|
|
7399
7435
|
/** 8 bytes */
|
|
7400
7436
|
spanId: [8, bin],
|
|
7437
|
+
/** 1 to 128 bytes: an event of an id its stream holds is written as nothing */
|
|
7438
|
+
id: [9, str],
|
|
7401
7439
|
}, {
|
|
7402
7440
|
write(w, v) {
|
|
7403
7441
|
const head = w.openMap();
|
|
@@ -7442,6 +7480,11 @@ export const RecordsNewEvent = message('records.NewEvent', {
|
|
|
7442
7480
|
w.bin(v.spanId);
|
|
7443
7481
|
n++;
|
|
7444
7482
|
}
|
|
7483
|
+
if (v.id !== undefined) {
|
|
7484
|
+
w.field(9);
|
|
7485
|
+
w.str(v.id);
|
|
7486
|
+
n++;
|
|
7487
|
+
}
|
|
7445
7488
|
w.closeMap(head, n);
|
|
7446
7489
|
},
|
|
7447
7490
|
read(r) {
|
|
@@ -7453,6 +7496,7 @@ export const RecordsNewEvent = message('records.NewEvent', {
|
|
|
7453
7496
|
let $context;
|
|
7454
7497
|
let $traceId;
|
|
7455
7498
|
let $spanId;
|
|
7499
|
+
let $id;
|
|
7456
7500
|
for (let n = r.message(); n > 0; n--) {
|
|
7457
7501
|
switch (r.field()) {
|
|
7458
7502
|
case 1:
|
|
@@ -7479,6 +7523,9 @@ export const RecordsNewEvent = message('records.NewEvent', {
|
|
|
7479
7523
|
case 8:
|
|
7480
7524
|
$spanId = r.bytes();
|
|
7481
7525
|
break;
|
|
7526
|
+
case 9:
|
|
7527
|
+
$id = r.str();
|
|
7528
|
+
break;
|
|
7482
7529
|
default:
|
|
7483
7530
|
r.skip();
|
|
7484
7531
|
}
|
|
@@ -7493,6 +7540,7 @@ export const RecordsNewEvent = message('records.NewEvent', {
|
|
|
7493
7540
|
context: $context,
|
|
7494
7541
|
traceId: $traceId,
|
|
7495
7542
|
spanId: $spanId,
|
|
7543
|
+
id: $id,
|
|
7496
7544
|
};
|
|
7497
7545
|
},
|
|
7498
7546
|
});
|
|
@@ -7546,6 +7594,39 @@ export const RecordsAppend = message('records.Append', {
|
|
|
7546
7594
|
return { handle: $handle, events: $events };
|
|
7547
7595
|
},
|
|
7548
7596
|
});
|
|
7597
|
+
/**
|
|
7598
|
+
* What an append wrote: none of an event whose id its stream held, or an
|
|
7599
|
+
* earlier event of the append held.
|
|
7600
|
+
*/
|
|
7601
|
+
export const RecordsAppended = message('records.Appended', {
|
|
7602
|
+
/** the events written as nothing */
|
|
7603
|
+
held: [1, uint],
|
|
7604
|
+
}, {
|
|
7605
|
+
write(w, v) {
|
|
7606
|
+
const head = w.openMap();
|
|
7607
|
+
let n = 0;
|
|
7608
|
+
if (v.held !== undefined) {
|
|
7609
|
+
w.field(1);
|
|
7610
|
+
w.uint(v.held);
|
|
7611
|
+
n++;
|
|
7612
|
+
}
|
|
7613
|
+
w.closeMap(head, n);
|
|
7614
|
+
},
|
|
7615
|
+
read(r) {
|
|
7616
|
+
let $held;
|
|
7617
|
+
for (let n = r.message(); n > 0; n--) {
|
|
7618
|
+
switch (r.field()) {
|
|
7619
|
+
case 1:
|
|
7620
|
+
$held = r.uint();
|
|
7621
|
+
break;
|
|
7622
|
+
default:
|
|
7623
|
+
r.skip();
|
|
7624
|
+
}
|
|
7625
|
+
}
|
|
7626
|
+
r.leave();
|
|
7627
|
+
return { held: $held };
|
|
7628
|
+
},
|
|
7629
|
+
});
|
|
7549
7630
|
/**
|
|
7550
7631
|
* An event as a read gives it.
|
|
7551
7632
|
*/
|
|
@@ -7560,6 +7641,7 @@ export const RecordsEvent = message('records.Event', {
|
|
|
7560
7641
|
context: [7, str],
|
|
7561
7642
|
traceId: [8, bin],
|
|
7562
7643
|
spanId: [9, bin],
|
|
7644
|
+
id: [10, str],
|
|
7563
7645
|
}, {
|
|
7564
7646
|
write(w, v) {
|
|
7565
7647
|
const head = w.openMap();
|
|
@@ -7609,6 +7691,11 @@ export const RecordsEvent = message('records.Event', {
|
|
|
7609
7691
|
w.bin(v.spanId);
|
|
7610
7692
|
n++;
|
|
7611
7693
|
}
|
|
7694
|
+
if (v.id !== undefined) {
|
|
7695
|
+
w.field(10);
|
|
7696
|
+
w.str(v.id);
|
|
7697
|
+
n++;
|
|
7698
|
+
}
|
|
7612
7699
|
w.closeMap(head, n);
|
|
7613
7700
|
},
|
|
7614
7701
|
read(r) {
|
|
@@ -7621,6 +7708,7 @@ export const RecordsEvent = message('records.Event', {
|
|
|
7621
7708
|
let $context;
|
|
7622
7709
|
let $traceId;
|
|
7623
7710
|
let $spanId;
|
|
7711
|
+
let $id;
|
|
7624
7712
|
for (let n = r.message(); n > 0; n--) {
|
|
7625
7713
|
switch (r.field()) {
|
|
7626
7714
|
case 1:
|
|
@@ -7650,6 +7738,9 @@ export const RecordsEvent = message('records.Event', {
|
|
|
7650
7738
|
case 9:
|
|
7651
7739
|
$spanId = r.bytes();
|
|
7652
7740
|
break;
|
|
7741
|
+
case 10:
|
|
7742
|
+
$id = r.str();
|
|
7743
|
+
break;
|
|
7653
7744
|
default:
|
|
7654
7745
|
r.skip();
|
|
7655
7746
|
}
|
|
@@ -7665,6 +7756,7 @@ export const RecordsEvent = message('records.Event', {
|
|
|
7665
7756
|
context: $context,
|
|
7666
7757
|
traceId: $traceId,
|
|
7667
7758
|
spanId: $spanId,
|
|
7759
|
+
id: $id,
|
|
7668
7760
|
};
|
|
7669
7761
|
},
|
|
7670
7762
|
});
|
|
@@ -8058,6 +8150,10 @@ export const RecordsAggregateAsked = message('records.AggregateAsked', {
|
|
|
8058
8150
|
by: [3, list(str)],
|
|
8059
8151
|
stats: [4, list(str)],
|
|
8060
8152
|
distinct: [5, list(str)],
|
|
8153
|
+
/** day, week or month: rows of a calendar in timeZone, in place of every */
|
|
8154
|
+
calendar: [6, str],
|
|
8155
|
+
/** an IANA name, UTC among them, which calendar takes */
|
|
8156
|
+
timeZone: [7, str],
|
|
8061
8157
|
}, {
|
|
8062
8158
|
write(w, v) {
|
|
8063
8159
|
const head = w.openMap();
|
|
@@ -8096,6 +8192,16 @@ export const RecordsAggregateAsked = message('records.AggregateAsked', {
|
|
|
8096
8192
|
}
|
|
8097
8193
|
n++;
|
|
8098
8194
|
}
|
|
8195
|
+
if (v.calendar !== undefined) {
|
|
8196
|
+
w.field(6);
|
|
8197
|
+
w.str(v.calendar);
|
|
8198
|
+
n++;
|
|
8199
|
+
}
|
|
8200
|
+
if (v.timeZone !== undefined) {
|
|
8201
|
+
w.field(7);
|
|
8202
|
+
w.str(v.timeZone);
|
|
8203
|
+
n++;
|
|
8204
|
+
}
|
|
8099
8205
|
w.closeMap(head, n);
|
|
8100
8206
|
},
|
|
8101
8207
|
read(r) {
|
|
@@ -8104,6 +8210,8 @@ export const RecordsAggregateAsked = message('records.AggregateAsked', {
|
|
|
8104
8210
|
let $by;
|
|
8105
8211
|
let $stats;
|
|
8106
8212
|
let $distinct;
|
|
8213
|
+
let $calendar;
|
|
8214
|
+
let $timeZone;
|
|
8107
8215
|
for (let n = r.message(); n > 0; n--) {
|
|
8108
8216
|
switch (r.field()) {
|
|
8109
8217
|
case 1:
|
|
@@ -8139,12 +8247,26 @@ export const RecordsAggregateAsked = message('records.AggregateAsked', {
|
|
|
8139
8247
|
$distinct = items0;
|
|
8140
8248
|
break;
|
|
8141
8249
|
}
|
|
8250
|
+
case 6:
|
|
8251
|
+
$calendar = r.str();
|
|
8252
|
+
break;
|
|
8253
|
+
case 7:
|
|
8254
|
+
$timeZone = r.str();
|
|
8255
|
+
break;
|
|
8142
8256
|
default:
|
|
8143
8257
|
r.skip();
|
|
8144
8258
|
}
|
|
8145
8259
|
}
|
|
8146
8260
|
r.leave();
|
|
8147
|
-
return {
|
|
8261
|
+
return {
|
|
8262
|
+
query: $query,
|
|
8263
|
+
every: $every,
|
|
8264
|
+
by: $by,
|
|
8265
|
+
stats: $stats,
|
|
8266
|
+
distinct: $distinct,
|
|
8267
|
+
calendar: $calendar,
|
|
8268
|
+
timeZone: $timeZone,
|
|
8269
|
+
};
|
|
8148
8270
|
},
|
|
8149
8271
|
});
|
|
8150
8272
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinyshed/tinystore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-rc.1",
|
|
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.2.0-rc.1",
|
|
35
|
+
"@tinyshed/tinystore-linux-arm64": "0.2.0-rc.1",
|
|
36
|
+
"@tinyshed/tinystore-linux-x64-musl": "0.2.0-rc.1",
|
|
37
|
+
"@tinyshed/tinystore-linux-arm64-musl": "0.2.0-rc.1",
|
|
38
|
+
"@tinyshed/tinystore-darwin-arm64": "0.2.0-rc.1",
|
|
39
|
+
"@tinyshed/tinystore-darwin-x64": "0.2.0-rc.1",
|
|
40
|
+
"@tinyshed/tinystore-win32-x64": "0.2.0-rc.1"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/index.ts
CHANGED
|
@@ -210,7 +210,7 @@ export {
|
|
|
210
210
|
type Status,
|
|
211
211
|
Store,
|
|
212
212
|
} from './store.ts'
|
|
213
|
-
export type { Duration, DurationText, Time } from './time.ts'
|
|
213
|
+
export type { Calendar, Duration, DurationText, Time } from './time.ts'
|
|
214
214
|
export { type Trace, withTrace } from './trace.ts'
|
|
215
215
|
export type { Tx, TxBucket, TxCounters } from './tx.ts'
|
|
216
216
|
export type { Key } from './wire/codec.ts'
|
package/src/jobs.ts
CHANGED
|
@@ -57,6 +57,8 @@ export interface QueueOptions {
|
|
|
57
57
|
concurrency?: number | Concurrency | undefined
|
|
58
58
|
/** jobs started in any span: '30/s' */
|
|
59
59
|
rate?: Rate | undefined
|
|
60
|
+
/** jobs of each group started in any span, beside rate: '2/s', each account's own limit; it lives in memory */
|
|
61
|
+
groupRate?: Rate | undefined
|
|
60
62
|
/** how long a done job's id stays taken, so that an add of it adds nothing */
|
|
61
63
|
dedupe?: Duration | undefined
|
|
62
64
|
/** how long a failed job stays, to be found and started again: a week */
|
|
@@ -983,6 +985,7 @@ export function openQueue<T>(
|
|
|
983
985
|
group: whole(concurrency.group, describe, "a group's concurrency"),
|
|
984
986
|
},
|
|
985
987
|
rate: options.rate === undefined ? undefined : rateOf(options.rate),
|
|
988
|
+
groupRate: options.groupRate === undefined ? undefined : rateOf(options.groupRate),
|
|
986
989
|
dedupe: msOf(options.dedupe),
|
|
987
990
|
keep: msOf(options.keep),
|
|
988
991
|
maxWaiting: whole(options.maxWaiting, describe, 'a maxWaiting'),
|
package/src/metrics.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
Timer,
|
|
21
21
|
type TimerOptions,
|
|
22
22
|
} from './instruments.ts'
|
|
23
|
-
import { type Duration, type DurationText, ms, type Time, unixMs } from './time.ts'
|
|
23
|
+
import { type Calendar, type Duration, type DurationText, ms, type Time, unixMs } from './time.ts'
|
|
24
24
|
import {
|
|
25
25
|
Empty,
|
|
26
26
|
MetricsAggregateAsked,
|
|
@@ -153,6 +153,10 @@ export type Op =
|
|
|
153
153
|
export interface AggregateQuery<O extends Op = Op> extends Query {
|
|
154
154
|
/** the buckets' span, counted from 1970 in UTC; the range is one bucket without it */
|
|
155
155
|
every?: Duration | undefined
|
|
156
|
+
/** buckets of a calendar in timeZone, in place of every: 'day' begins each at a local midnight */
|
|
157
|
+
calendar?: Calendar | undefined
|
|
158
|
+
/** the IANA zone a calendar's buckets are in: 'Europe/Moscow', 'UTC' */
|
|
159
|
+
timeZone?: string | undefined
|
|
156
160
|
op: O
|
|
157
161
|
/** the labels a group keeps; without by and without, every series of a name is one group */
|
|
158
162
|
by?: readonly string[] | undefined
|
|
@@ -617,6 +621,8 @@ function aggregateOf(query: AggregateQuery): Parameters<typeof MetricsAggregateA
|
|
|
617
621
|
return {
|
|
618
622
|
query: queryOf(query),
|
|
619
623
|
every: query.every === undefined ? undefined : ms(query.every),
|
|
624
|
+
calendar: query.calendar,
|
|
625
|
+
timeZone: query.timeZone,
|
|
620
626
|
op: query.op,
|
|
621
627
|
by: query.by === undefined ? undefined : [...query.by],
|
|
622
628
|
without: query.without === undefined ? undefined : [...query.without],
|
package/src/records.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
newStoreLogger,
|
|
19
19
|
} from './logger.ts'
|
|
20
20
|
import type { Stream } from './session.ts'
|
|
21
|
-
import { type Duration, type DurationText, ms } from './time.ts'
|
|
21
|
+
import { type Calendar, type Duration, type DurationText, ms } from './time.ts'
|
|
22
22
|
import { currentTrace, type Trace } from './trace.ts'
|
|
23
23
|
import {
|
|
24
24
|
Empty,
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
methods,
|
|
27
27
|
RecordsAggregateAsked,
|
|
28
28
|
RecordsAppend,
|
|
29
|
+
RecordsAppended,
|
|
29
30
|
RecordsBatch,
|
|
30
31
|
RecordsCount,
|
|
31
32
|
RecordsDamage,
|
|
@@ -61,6 +62,8 @@ export interface Event {
|
|
|
61
62
|
/** its time, which the file keeps to the nanosecond */
|
|
62
63
|
at: Date
|
|
63
64
|
stream: string
|
|
65
|
+
/** what its append named it by: its stream holds one event of an id */
|
|
66
|
+
id?: string
|
|
64
67
|
/** what happened; `log` for a logger's line */
|
|
65
68
|
name: string
|
|
66
69
|
level?: EventLevel
|
|
@@ -77,6 +80,11 @@ export interface Event {
|
|
|
77
80
|
/** An event to append: its name, what happened, and what it carries beside. */
|
|
78
81
|
export interface NewEvent {
|
|
79
82
|
name: string
|
|
83
|
+
/**
|
|
84
|
+
* what names it in its stream, a webhook's delivery or a job's key, 1 to 128 bytes:
|
|
85
|
+
* an append of an id the stream holds writes nothing, and the first event of an id stands
|
|
86
|
+
*/
|
|
87
|
+
id?: string
|
|
80
88
|
fields?: Fields
|
|
81
89
|
/** its time: now unless given, from what the stream keeps to ten minutes ahead */
|
|
82
90
|
at?: Date
|
|
@@ -157,6 +165,10 @@ export interface Row {
|
|
|
157
165
|
export interface Aggregate extends Counted {
|
|
158
166
|
/** the span of a row: the range is one without it */
|
|
159
167
|
every?: Duration
|
|
168
|
+
/** rows of a calendar in timeZone, in place of every: 'day' begins each at a local midnight */
|
|
169
|
+
calendar?: Calendar
|
|
170
|
+
/** the IANA zone a calendar's rows are in: 'Europe/Moscow', 'UTC' */
|
|
171
|
+
timeZone?: string
|
|
160
172
|
/** keys whose every value has rows of its own */
|
|
161
173
|
by?: readonly string[]
|
|
162
174
|
/** fields whose numbers a row sums */
|
|
@@ -292,12 +304,14 @@ abstract class Reads {
|
|
|
292
304
|
|
|
293
305
|
/** A row for each span of `every` and each value of the keys of `by`, with its count. */
|
|
294
306
|
async aggregate(query: Aggregate = {}): Promise<Row[]> {
|
|
295
|
-
const { every, by, stats, distinct, ...counted } = query
|
|
307
|
+
const { every, calendar, timeZone, by, stats, distinct, ...counted } = query
|
|
296
308
|
const asked = queryOf(counted)
|
|
297
309
|
const answer = await this.ask('records.aggregate', handle =>
|
|
298
310
|
RecordsAggregateAsked.encode({
|
|
299
311
|
query: { ...asked, handle },
|
|
300
312
|
every: every === undefined ? undefined : ms(every),
|
|
313
|
+
calendar,
|
|
314
|
+
timeZone,
|
|
301
315
|
by: by === undefined ? undefined : [...by],
|
|
302
316
|
stats: stats === undefined ? undefined : [...stats],
|
|
303
317
|
distinct: distinct === undefined ? undefined : [...distinct],
|
|
@@ -384,23 +398,27 @@ export class Events extends Reads {
|
|
|
384
398
|
|
|
385
399
|
/**
|
|
386
400
|
* Writes an event, or a list of them whole or not at all: it returns once
|
|
387
|
-
* they are written, and a read finds them at once.
|
|
388
|
-
*
|
|
401
|
+
* they are written, and a read finds them at once. An event whose id the
|
|
402
|
+
* stream holds, or an earlier event of the list has, is written as
|
|
403
|
+
* nothing: one event answers whether it was written, a list how many of
|
|
404
|
+
* its events were. A refused event names its place in the list and its name.
|
|
389
405
|
*/
|
|
390
|
-
append(name: string, fields?: Fields, options?: AppendOptions): Promise<
|
|
391
|
-
append(events: readonly NewEvent[]): Promise<
|
|
406
|
+
append(name: string, fields?: Fields, options?: AppendOptions): Promise<boolean>
|
|
407
|
+
append(events: readonly NewEvent[]): Promise<number>
|
|
392
408
|
async append(
|
|
393
409
|
first: string | readonly NewEvent[],
|
|
394
410
|
fields?: Fields,
|
|
395
411
|
options?: AppendOptions,
|
|
396
|
-
): Promise<
|
|
412
|
+
): Promise<boolean | number> {
|
|
397
413
|
const events = typeof first === 'string' ? [oneEvent(first, fields, options)] : first
|
|
398
414
|
const encoded = events.map(newEventOf)
|
|
399
|
-
await this.#call(
|
|
415
|
+
const answer = await this.#call(
|
|
400
416
|
'records.append',
|
|
401
417
|
handle => RecordsAppend.encode({ handle, events: encoded }),
|
|
402
418
|
'write',
|
|
403
419
|
)
|
|
420
|
+
const written = events.length - (RecordsAppended.decode(answer).held ?? 0)
|
|
421
|
+
return typeof first === 'string' ? written === 1 : written
|
|
404
422
|
}
|
|
405
423
|
|
|
406
424
|
/** A logger's lines, each an event of this stream. */
|
|
@@ -793,8 +811,12 @@ function newEventOf(event: NewEvent, place: number): Parameters<typeof RecordsNe
|
|
|
793
811
|
event.traceId === undefined
|
|
794
812
|
? traceOf(currentTrace())
|
|
795
813
|
: { traceId: event.traceId, spanId: event.spanId }
|
|
814
|
+
if (event.id !== undefined && (typeof event.id !== 'string' || event.id === '')) {
|
|
815
|
+
throw new InvalidError(`${named}: an id is a string of 1 to 128 bytes`)
|
|
816
|
+
}
|
|
796
817
|
return {
|
|
797
818
|
name: event.name,
|
|
819
|
+
id: event.id,
|
|
798
820
|
at: event.at === undefined ? undefined : nanosOf(event.at),
|
|
799
821
|
level: event.level === undefined ? undefined : levelNumber(event.level, named),
|
|
800
822
|
message: event.message,
|
|
@@ -853,6 +875,9 @@ function eventOf(read: ReturnType<typeof RecordsEvent.decode>): Event {
|
|
|
853
875
|
if (read.message !== undefined) {
|
|
854
876
|
event.message = read.message
|
|
855
877
|
}
|
|
878
|
+
if (read.id !== undefined) {
|
|
879
|
+
event.id = read.id
|
|
880
|
+
}
|
|
856
881
|
if (read.traceId !== undefined) {
|
|
857
882
|
event.traceId = Buffer.from(read.traceId).toString('hex')
|
|
858
883
|
}
|
package/src/time.ts
CHANGED
|
@@ -53,6 +53,9 @@ export type DurationText = Offered | (Spelled<Units> & Record<never, never>)
|
|
|
53
53
|
/** A length of time: milliseconds, or the text of one, such as '1h30m'. */
|
|
54
54
|
export type Duration = number | DurationText
|
|
55
55
|
|
|
56
|
+
/** A span of a calendar an aggregate's bucket covers in its timeZone: a local day, a week from Monday, a month. */
|
|
57
|
+
export type Calendar = 'day' | 'week' | 'month'
|
|
58
|
+
|
|
56
59
|
/** A moment: a Date, or unix milliseconds. */
|
|
57
60
|
export type Time = Date | number
|
|
58
61
|
|
package/src/wire/protocol.ts
CHANGED
|
@@ -2780,6 +2780,8 @@ export const JobsQueueOpen = message(
|
|
|
2780
2780
|
maxWaiting: [9, uint],
|
|
2781
2781
|
/** a database's handle: the queue lives in its file; jobs.db when absent */
|
|
2782
2782
|
database: [10, uint],
|
|
2783
|
+
/** each group's starts, beside the queue's rate */
|
|
2784
|
+
groupRate: [11, JobsRate],
|
|
2783
2785
|
},
|
|
2784
2786
|
{
|
|
2785
2787
|
write(w, v) {
|
|
@@ -2835,6 +2837,11 @@ export const JobsQueueOpen = message(
|
|
|
2835
2837
|
w.uint(v.database)
|
|
2836
2838
|
n++
|
|
2837
2839
|
}
|
|
2840
|
+
if (v.groupRate !== undefined) {
|
|
2841
|
+
w.field(11)
|
|
2842
|
+
JobsRate.write(w, v.groupRate)
|
|
2843
|
+
n++
|
|
2844
|
+
}
|
|
2838
2845
|
w.closeMap(head, n)
|
|
2839
2846
|
},
|
|
2840
2847
|
read(r) {
|
|
@@ -2848,6 +2855,7 @@ export const JobsQueueOpen = message(
|
|
|
2848
2855
|
let $keep: number | undefined
|
|
2849
2856
|
let $maxWaiting: number | undefined
|
|
2850
2857
|
let $database: number | undefined
|
|
2858
|
+
let $groupRate: Read<typeof JobsRate.fields> | undefined
|
|
2851
2859
|
for (let n = r.message(); n > 0; n--) {
|
|
2852
2860
|
switch (r.field()) {
|
|
2853
2861
|
case 1:
|
|
@@ -2880,6 +2888,9 @@ export const JobsQueueOpen = message(
|
|
|
2880
2888
|
case 10:
|
|
2881
2889
|
$database = r.uint()
|
|
2882
2890
|
break
|
|
2891
|
+
case 11:
|
|
2892
|
+
$groupRate = JobsRate.read(r)
|
|
2893
|
+
break
|
|
2883
2894
|
default:
|
|
2884
2895
|
r.skip()
|
|
2885
2896
|
}
|
|
@@ -2896,6 +2907,7 @@ export const JobsQueueOpen = message(
|
|
|
2896
2907
|
keep: $keep,
|
|
2897
2908
|
maxWaiting: $maxWaiting,
|
|
2898
2909
|
database: $database,
|
|
2910
|
+
groupRate: $groupRate,
|
|
2899
2911
|
}
|
|
2900
2912
|
},
|
|
2901
2913
|
},
|
|
@@ -6135,6 +6147,10 @@ export const MetricsAggregateAsked = message(
|
|
|
6135
6147
|
without: [5, list(str)],
|
|
6136
6148
|
/** a timer's percentile also gives a point between its bounds */
|
|
6137
6149
|
estimate: [6, bool],
|
|
6150
|
+
/** day, week or month: buckets of a calendar in timeZone, in place of every */
|
|
6151
|
+
calendar: [7, str],
|
|
6152
|
+
/** an IANA name, UTC among them, which calendar takes */
|
|
6153
|
+
timeZone: [8, str],
|
|
6138
6154
|
},
|
|
6139
6155
|
{
|
|
6140
6156
|
write(w, v) {
|
|
@@ -6176,6 +6192,16 @@ export const MetricsAggregateAsked = message(
|
|
|
6176
6192
|
w.bool(v.estimate)
|
|
6177
6193
|
n++
|
|
6178
6194
|
}
|
|
6195
|
+
if (v.calendar !== undefined) {
|
|
6196
|
+
w.field(7)
|
|
6197
|
+
w.str(v.calendar)
|
|
6198
|
+
n++
|
|
6199
|
+
}
|
|
6200
|
+
if (v.timeZone !== undefined) {
|
|
6201
|
+
w.field(8)
|
|
6202
|
+
w.str(v.timeZone)
|
|
6203
|
+
n++
|
|
6204
|
+
}
|
|
6179
6205
|
w.closeMap(head, n)
|
|
6180
6206
|
},
|
|
6181
6207
|
read(r) {
|
|
@@ -6185,6 +6211,8 @@ export const MetricsAggregateAsked = message(
|
|
|
6185
6211
|
let $by: string[] | undefined
|
|
6186
6212
|
let $without: string[] | undefined
|
|
6187
6213
|
let $estimate: boolean | undefined
|
|
6214
|
+
let $calendar: string | undefined
|
|
6215
|
+
let $timeZone: string | undefined
|
|
6188
6216
|
for (let n = r.message(); n > 0; n--) {
|
|
6189
6217
|
switch (r.field()) {
|
|
6190
6218
|
case 1:
|
|
@@ -6217,6 +6245,12 @@ export const MetricsAggregateAsked = message(
|
|
|
6217
6245
|
case 6:
|
|
6218
6246
|
$estimate = r.bool()
|
|
6219
6247
|
break
|
|
6248
|
+
case 7:
|
|
6249
|
+
$calendar = r.str()
|
|
6250
|
+
break
|
|
6251
|
+
case 8:
|
|
6252
|
+
$timeZone = r.str()
|
|
6253
|
+
break
|
|
6220
6254
|
default:
|
|
6221
6255
|
r.skip()
|
|
6222
6256
|
}
|
|
@@ -6229,6 +6263,8 @@ export const MetricsAggregateAsked = message(
|
|
|
6229
6263
|
by: $by,
|
|
6230
6264
|
without: $without,
|
|
6231
6265
|
estimate: $estimate,
|
|
6266
|
+
calendar: $calendar,
|
|
6267
|
+
timeZone: $timeZone,
|
|
6232
6268
|
}
|
|
6233
6269
|
},
|
|
6234
6270
|
},
|
|
@@ -7979,6 +8015,8 @@ export const RecordsNewEvent = message(
|
|
|
7979
8015
|
traceId: [7, bin],
|
|
7980
8016
|
/** 8 bytes */
|
|
7981
8017
|
spanId: [8, bin],
|
|
8018
|
+
/** 1 to 128 bytes: an event of an id its stream holds is written as nothing */
|
|
8019
|
+
id: [9, str],
|
|
7982
8020
|
},
|
|
7983
8021
|
{
|
|
7984
8022
|
write(w, v) {
|
|
@@ -8024,6 +8062,11 @@ export const RecordsNewEvent = message(
|
|
|
8024
8062
|
w.bin(v.spanId)
|
|
8025
8063
|
n++
|
|
8026
8064
|
}
|
|
8065
|
+
if (v.id !== undefined) {
|
|
8066
|
+
w.field(9)
|
|
8067
|
+
w.str(v.id)
|
|
8068
|
+
n++
|
|
8069
|
+
}
|
|
8027
8070
|
w.closeMap(head, n)
|
|
8028
8071
|
},
|
|
8029
8072
|
read(r) {
|
|
@@ -8035,6 +8078,7 @@ export const RecordsNewEvent = message(
|
|
|
8035
8078
|
let $context: string | undefined
|
|
8036
8079
|
let $traceId: Uint8Array | undefined
|
|
8037
8080
|
let $spanId: Uint8Array | undefined
|
|
8081
|
+
let $id: string | undefined
|
|
8038
8082
|
for (let n = r.message(); n > 0; n--) {
|
|
8039
8083
|
switch (r.field()) {
|
|
8040
8084
|
case 1:
|
|
@@ -8061,6 +8105,9 @@ export const RecordsNewEvent = message(
|
|
|
8061
8105
|
case 8:
|
|
8062
8106
|
$spanId = r.bytes()
|
|
8063
8107
|
break
|
|
8108
|
+
case 9:
|
|
8109
|
+
$id = r.str()
|
|
8110
|
+
break
|
|
8064
8111
|
default:
|
|
8065
8112
|
r.skip()
|
|
8066
8113
|
}
|
|
@@ -8075,6 +8122,7 @@ export const RecordsNewEvent = message(
|
|
|
8075
8122
|
context: $context,
|
|
8076
8123
|
traceId: $traceId,
|
|
8077
8124
|
spanId: $spanId,
|
|
8125
|
+
id: $id,
|
|
8078
8126
|
}
|
|
8079
8127
|
},
|
|
8080
8128
|
},
|
|
@@ -8135,6 +8183,44 @@ export const RecordsAppend = message(
|
|
|
8135
8183
|
},
|
|
8136
8184
|
)
|
|
8137
8185
|
|
|
8186
|
+
/**
|
|
8187
|
+
* What an append wrote: none of an event whose id its stream held, or an
|
|
8188
|
+
* earlier event of the append held.
|
|
8189
|
+
*/
|
|
8190
|
+
export const RecordsAppended = message(
|
|
8191
|
+
'records.Appended',
|
|
8192
|
+
{
|
|
8193
|
+
/** the events written as nothing */
|
|
8194
|
+
held: [1, uint],
|
|
8195
|
+
},
|
|
8196
|
+
{
|
|
8197
|
+
write(w, v) {
|
|
8198
|
+
const head = w.openMap()
|
|
8199
|
+
let n = 0
|
|
8200
|
+
if (v.held !== undefined) {
|
|
8201
|
+
w.field(1)
|
|
8202
|
+
w.uint(v.held)
|
|
8203
|
+
n++
|
|
8204
|
+
}
|
|
8205
|
+
w.closeMap(head, n)
|
|
8206
|
+
},
|
|
8207
|
+
read(r) {
|
|
8208
|
+
let $held: number | undefined
|
|
8209
|
+
for (let n = r.message(); n > 0; n--) {
|
|
8210
|
+
switch (r.field()) {
|
|
8211
|
+
case 1:
|
|
8212
|
+
$held = r.uint()
|
|
8213
|
+
break
|
|
8214
|
+
default:
|
|
8215
|
+
r.skip()
|
|
8216
|
+
}
|
|
8217
|
+
}
|
|
8218
|
+
r.leave()
|
|
8219
|
+
return { held: $held }
|
|
8220
|
+
},
|
|
8221
|
+
},
|
|
8222
|
+
)
|
|
8223
|
+
|
|
8138
8224
|
/**
|
|
8139
8225
|
* An event as a read gives it.
|
|
8140
8226
|
*/
|
|
@@ -8151,6 +8237,7 @@ export const RecordsEvent = message(
|
|
|
8151
8237
|
context: [7, str],
|
|
8152
8238
|
traceId: [8, bin],
|
|
8153
8239
|
spanId: [9, bin],
|
|
8240
|
+
id: [10, str],
|
|
8154
8241
|
},
|
|
8155
8242
|
{
|
|
8156
8243
|
write(w, v) {
|
|
@@ -8201,6 +8288,11 @@ export const RecordsEvent = message(
|
|
|
8201
8288
|
w.bin(v.spanId)
|
|
8202
8289
|
n++
|
|
8203
8290
|
}
|
|
8291
|
+
if (v.id !== undefined) {
|
|
8292
|
+
w.field(10)
|
|
8293
|
+
w.str(v.id)
|
|
8294
|
+
n++
|
|
8295
|
+
}
|
|
8204
8296
|
w.closeMap(head, n)
|
|
8205
8297
|
},
|
|
8206
8298
|
read(r) {
|
|
@@ -8213,6 +8305,7 @@ export const RecordsEvent = message(
|
|
|
8213
8305
|
let $context: string | undefined
|
|
8214
8306
|
let $traceId: Uint8Array | undefined
|
|
8215
8307
|
let $spanId: Uint8Array | undefined
|
|
8308
|
+
let $id: string | undefined
|
|
8216
8309
|
for (let n = r.message(); n > 0; n--) {
|
|
8217
8310
|
switch (r.field()) {
|
|
8218
8311
|
case 1:
|
|
@@ -8242,6 +8335,9 @@ export const RecordsEvent = message(
|
|
|
8242
8335
|
case 9:
|
|
8243
8336
|
$spanId = r.bytes()
|
|
8244
8337
|
break
|
|
8338
|
+
case 10:
|
|
8339
|
+
$id = r.str()
|
|
8340
|
+
break
|
|
8245
8341
|
default:
|
|
8246
8342
|
r.skip()
|
|
8247
8343
|
}
|
|
@@ -8257,6 +8353,7 @@ export const RecordsEvent = message(
|
|
|
8257
8353
|
context: $context,
|
|
8258
8354
|
traceId: $traceId,
|
|
8259
8355
|
spanId: $spanId,
|
|
8356
|
+
id: $id,
|
|
8260
8357
|
}
|
|
8261
8358
|
},
|
|
8262
8359
|
},
|
|
@@ -8684,6 +8781,10 @@ export const RecordsAggregateAsked = message(
|
|
|
8684
8781
|
by: [3, list(str)],
|
|
8685
8782
|
stats: [4, list(str)],
|
|
8686
8783
|
distinct: [5, list(str)],
|
|
8784
|
+
/** day, week or month: rows of a calendar in timeZone, in place of every */
|
|
8785
|
+
calendar: [6, str],
|
|
8786
|
+
/** an IANA name, UTC among them, which calendar takes */
|
|
8787
|
+
timeZone: [7, str],
|
|
8687
8788
|
},
|
|
8688
8789
|
{
|
|
8689
8790
|
write(w, v) {
|
|
@@ -8723,6 +8824,16 @@ export const RecordsAggregateAsked = message(
|
|
|
8723
8824
|
}
|
|
8724
8825
|
n++
|
|
8725
8826
|
}
|
|
8827
|
+
if (v.calendar !== undefined) {
|
|
8828
|
+
w.field(6)
|
|
8829
|
+
w.str(v.calendar)
|
|
8830
|
+
n++
|
|
8831
|
+
}
|
|
8832
|
+
if (v.timeZone !== undefined) {
|
|
8833
|
+
w.field(7)
|
|
8834
|
+
w.str(v.timeZone)
|
|
8835
|
+
n++
|
|
8836
|
+
}
|
|
8726
8837
|
w.closeMap(head, n)
|
|
8727
8838
|
},
|
|
8728
8839
|
read(r) {
|
|
@@ -8731,6 +8842,8 @@ export const RecordsAggregateAsked = message(
|
|
|
8731
8842
|
let $by: string[] | undefined
|
|
8732
8843
|
let $stats: string[] | undefined
|
|
8733
8844
|
let $distinct: string[] | undefined
|
|
8845
|
+
let $calendar: string | undefined
|
|
8846
|
+
let $timeZone: string | undefined
|
|
8734
8847
|
for (let n = r.message(); n > 0; n--) {
|
|
8735
8848
|
switch (r.field()) {
|
|
8736
8849
|
case 1:
|
|
@@ -8766,12 +8879,26 @@ export const RecordsAggregateAsked = message(
|
|
|
8766
8879
|
$distinct = items0
|
|
8767
8880
|
break
|
|
8768
8881
|
}
|
|
8882
|
+
case 6:
|
|
8883
|
+
$calendar = r.str()
|
|
8884
|
+
break
|
|
8885
|
+
case 7:
|
|
8886
|
+
$timeZone = r.str()
|
|
8887
|
+
break
|
|
8769
8888
|
default:
|
|
8770
8889
|
r.skip()
|
|
8771
8890
|
}
|
|
8772
8891
|
}
|
|
8773
8892
|
r.leave()
|
|
8774
|
-
return {
|
|
8893
|
+
return {
|
|
8894
|
+
query: $query,
|
|
8895
|
+
every: $every,
|
|
8896
|
+
by: $by,
|
|
8897
|
+
stats: $stats,
|
|
8898
|
+
distinct: $distinct,
|
|
8899
|
+
calendar: $calendar,
|
|
8900
|
+
timeZone: $timeZone,
|
|
8901
|
+
}
|
|
8775
8902
|
},
|
|
8776
8903
|
},
|
|
8777
8904
|
)
|