@tinyshed/tinystore 0.1.0-rc.5 → 0.1.0-rc.6

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.
Files changed (122) hide show
  1. package/README.md +37 -37
  2. package/bin/tinystore.js +12 -1
  3. package/dist/backup.d.ts +33 -0
  4. package/dist/backup.js +49 -0
  5. package/dist/blobs.d.ts +160 -79
  6. package/dist/blobs.js +510 -217
  7. package/dist/channels.d.ts +90 -0
  8. package/dist/channels.js +291 -0
  9. package/dist/clock.js +3 -3
  10. package/dist/config.d.ts +209 -86
  11. package/dist/config.js +581 -538
  12. package/dist/connection.d.ts +64 -2
  13. package/dist/connection.js +201 -16
  14. package/dist/console.d.ts +27 -3
  15. package/dist/console.js +165 -12
  16. package/dist/dotenv.d.ts +7 -0
  17. package/dist/dotenv.js +79 -0
  18. package/dist/errors.d.ts +61 -1
  19. package/dist/errors.js +81 -1
  20. package/dist/handles.d.ts +44 -2
  21. package/dist/handles.js +81 -2
  22. package/dist/index.d.ts +17 -11
  23. package/dist/index.js +5 -3
  24. package/dist/instruments.d.ts +177 -0
  25. package/dist/instruments.js +819 -0
  26. package/dist/jobs.d.ts +335 -239
  27. package/dist/jobs.js +716 -536
  28. package/dist/json.d.ts +2 -0
  29. package/dist/json.js +122 -0
  30. package/dist/kv.d.ts +130 -243
  31. package/dist/kv.js +273 -640
  32. package/dist/limits.d.ts +80 -0
  33. package/dist/limits.js +139 -0
  34. package/dist/locks.d.ts +62 -0
  35. package/dist/locks.js +237 -0
  36. package/dist/logger.d.ts +45 -9
  37. package/dist/logger.js +150 -38
  38. package/dist/metrics.d.ts +210 -209
  39. package/dist/metrics.js +319 -556
  40. package/dist/once.d.ts +19 -18
  41. package/dist/once.js +74 -63
  42. package/dist/query.d.ts +181 -0
  43. package/dist/query.js +788 -0
  44. package/dist/records.d.ts +241 -150
  45. package/dist/records.js +507 -291
  46. package/dist/runtime/addon.d.ts +14 -0
  47. package/dist/runtime/addon.js +69 -0
  48. package/dist/runtime/bun.js +5 -7
  49. package/dist/runtime/node.js +5 -7
  50. package/dist/runtime/pipe.d.ts +17 -0
  51. package/dist/runtime/pipe.js +133 -0
  52. package/dist/runtime/shared.d.ts +6 -0
  53. package/dist/runtime/shared.js +19 -0
  54. package/dist/runtime.d.ts +5 -2
  55. package/dist/search.d.ts +189 -0
  56. package/dist/search.js +281 -0
  57. package/dist/session.d.ts +31 -3
  58. package/dist/session.js +153 -41
  59. package/dist/sql.d.ts +228 -78
  60. package/dist/sql.js +745 -240
  61. package/dist/store.d.ts +244 -24
  62. package/dist/store.js +270 -67
  63. package/dist/time.d.ts +5 -1
  64. package/dist/time.js +22 -2
  65. package/dist/tx.d.ts +61 -0
  66. package/dist/tx.js +314 -0
  67. package/dist/wire/codec.d.ts +23 -7
  68. package/dist/wire/codec.js +56 -35
  69. package/dist/wire/frame.d.ts +2 -0
  70. package/dist/wire/frame.js +31 -14
  71. package/dist/wire/messages.d.ts +259 -0
  72. package/dist/wire/messages.js +22 -0
  73. package/dist/wire/msgpack.d.ts +49 -1
  74. package/dist/wire/msgpack.js +293 -56
  75. package/dist/wire/protocol.d.ts +2683 -0
  76. package/dist/wire/protocol.js +10846 -0
  77. package/package.json +39 -38
  78. package/src/backup.ts +81 -0
  79. package/src/blobs.ts +678 -301
  80. package/src/channels.ts +377 -0
  81. package/src/clock.ts +4 -4
  82. package/src/config.ts +902 -612
  83. package/src/connection.ts +279 -21
  84. package/src/console.ts +180 -12
  85. package/src/dotenv.ts +82 -0
  86. package/src/errors.ts +105 -0
  87. package/src/handles.ts +157 -8
  88. package/src/index.ts +158 -52
  89. package/src/instruments.ts +1042 -0
  90. package/src/jobs.ts +1017 -733
  91. package/src/json.ts +133 -0
  92. package/src/kv.ts +424 -847
  93. package/src/limits.ts +202 -0
  94. package/src/locks.ts +320 -0
  95. package/src/logger.ts +209 -40
  96. package/src/metrics.ts +557 -752
  97. package/src/once.ts +86 -83
  98. package/src/query.ts +1005 -0
  99. package/src/records.ts +795 -418
  100. package/src/runtime/addon.ts +99 -0
  101. package/src/runtime/bun.ts +5 -7
  102. package/src/runtime/node.ts +5 -7
  103. package/src/runtime/pipe.ts +178 -0
  104. package/src/runtime/shared.ts +20 -0
  105. package/src/runtime.ts +5 -2
  106. package/src/search.ts +480 -0
  107. package/src/session.ts +187 -41
  108. package/src/sql.ts +993 -306
  109. package/src/store.ts +473 -78
  110. package/src/time.ts +48 -3
  111. package/src/tx.ts +426 -0
  112. package/src/wire/codec.ts +78 -37
  113. package/src/wire/frame.ts +44 -14
  114. package/src/wire/messages.ts +25 -0
  115. package/src/wire/msgpack.ts +327 -56
  116. package/src/wire/protocol.ts +11709 -0
  117. package/dist/limiter.d.ts +0 -45
  118. package/dist/limiter.js +0 -68
  119. package/dist/quota.d.ts +0 -44
  120. package/dist/quota.js +0 -98
  121. package/src/limiter.ts +0 -99
  122. package/src/quota.ts +0 -137
@@ -0,0 +1,177 @@
1
+ import type { Link } from './connection.ts';
2
+ import { type Duration } from './time.ts';
3
+ /** A label's value as an instrument takes it: a number or a boolean is kept as its text. */
4
+ export type LabelValue = string | number | boolean;
5
+ /** What an instrument is told when it is made. */
6
+ export interface InstrumentOptions {
7
+ /** the unit of its values, 32 bytes at most: 'bytes', '%' */
8
+ unit?: string | undefined;
9
+ /** a line on what it means, 1024 bytes at most */
10
+ help?: string | undefined;
11
+ /** how long its name's samples stay, as ingest takes it */
12
+ keep?: Duration | undefined;
13
+ }
14
+ /** A timer's or a histogram's upper bounds, ascending, or the store's grid. */
15
+ export type Buckets = readonly number[] | 'exponential';
16
+ export interface TimerOptions {
17
+ help?: string | undefined;
18
+ keep?: Duration | undefined;
19
+ /** the upper bounds of its spread, to which the store adds +Inf, or 'exponential' */
20
+ buckets?: Buckets | undefined;
21
+ }
22
+ export interface HistogramOptions extends InstrumentOptions {
23
+ buckets?: Buckets | undefined;
24
+ }
25
+ export interface GaugeFuncOptions extends InstrumentOptions {
26
+ /** the set of labels its function reads; another set of the name takes a function of its own */
27
+ labels?: InstrumentLabels | undefined;
28
+ }
29
+ /**
30
+ * The labels `with` takes: any, or, when the instrument was made with their
31
+ * names, `counter<'route' | 'status'>(…)`, those alone, checked as they are written.
32
+ */
33
+ export type InstrumentLabels<L extends string = string> = {
34
+ readonly [K in L]?: LabelValue;
35
+ };
36
+ type Form = 'counter' | 'gauge' | 'timer' | 'histogram';
37
+ /** An instrument as the stream declares it, and its sets of labels. */
38
+ interface Declared {
39
+ id: number;
40
+ name: string;
41
+ form: Form;
42
+ unit: string | undefined;
43
+ help: string | undefined;
44
+ keep: number | undefined;
45
+ bounds: number[] | undefined;
46
+ exponential: boolean;
47
+ sets: Map<string, LabelSet>;
48
+ overflow: LabelSet | undefined;
49
+ /** the store refused it: its calls change nothing, said once */
50
+ refused: boolean;
51
+ /** a gauge functions read, one a set of labels, by the key of its labels */
52
+ reads: Map<string, GaugeRead> | undefined;
53
+ }
54
+ /** A function that reads a gauge's set of labels. */
55
+ interface GaugeRead {
56
+ labels: Record<string, string>;
57
+ read: () => unknown;
58
+ /** a call of it runs: it is not called again until it ends */
59
+ reading: boolean;
60
+ /** the error it last gave, said once while it repeats */
61
+ failed: string | undefined;
62
+ }
63
+ /** A set of labels of an instrument: its id on the stream, and a gauge's value. */
64
+ interface LabelSet {
65
+ id: number;
66
+ instrument: Declared;
67
+ labels: Record<string, string>;
68
+ overflow: boolean;
69
+ /** when a call last changed it */
70
+ touched: number;
71
+ value: number | undefined;
72
+ }
73
+ /** What a set of labels changed since the batch before. */
74
+ interface Change {
75
+ add: number | undefined;
76
+ value: number | undefined;
77
+ count: number;
78
+ sum: number;
79
+ longest: number;
80
+ buckets: number[] | undefined;
81
+ bins: Map<string, number> | undefined;
82
+ }
83
+ /**
84
+ * The instruments of a store's handle, and what sends their changes. A store
85
+ * has one; `store.metrics` makes its instruments through it.
86
+ */
87
+ export declare class Instruments {
88
+ #private;
89
+ constructor(link: Link);
90
+ /**
91
+ * An instrument of name, made the first time, read by functions when
92
+ * `read` says so; another form or other options than it has are refused.
93
+ */
94
+ declare(name: string, form: Form, options: HistogramOptions, read?: boolean): Declared;
95
+ /**
96
+ * A gauge of name whose set of labels `read` gives every 15 seconds; each
97
+ * set has a function of its own, made once while the store is open.
98
+ */
99
+ reader(name: string, labels: Record<string, string>, options: InstrumentOptions, read: () => unknown): void;
100
+ /** The set of labels of an instrument, made the first time; past the sets it holds, its __overflow. */
101
+ setOf(instrument: Declared, labels: Record<string, string>): LabelSet;
102
+ /** What calls changed of a set since the last batch, if any. */
103
+ pending(set: LabelSet): Change | undefined;
104
+ /** What a call changes of a set, kept for the next batch. */
105
+ change(set: LabelSet): Change;
106
+ /**
107
+ * Sends what changed now and has the store write its totals; resolves
108
+ * once it has, and says whether there was anything to send it with. One
109
+ * the store cannot be reached for fails as a call does, and what it
110
+ * carried goes once the store can be. What the store refused since the
111
+ * flush before, and what a store that started again may have lost, fail
112
+ * it, each once.
113
+ */
114
+ flush(): Promise<boolean>;
115
+ /** Stops the timers, sends what is left, and ends the stream; the store's close calls it. */
116
+ stop(): Promise<void>;
117
+ }
118
+ /** Labels as an instrument keeps them: text, a number or a boolean as its text, none of the store's own. */
119
+ export declare function labelsOf(given: InstrumentLabels, timed: boolean): Record<string, string>;
120
+ /** A total that only goes up, which the store keeps: processes counting into one series count into one total. */
121
+ export declare class Counter<L extends string = string> {
122
+ #private;
123
+ constructor(instruments: Instruments, declared: Declared, labels: Record<string, string>);
124
+ /** The same counter with more labels, a series of its own; the same labels in any order are one. */
125
+ with(labels: InstrumentLabels<L>): Counter<L>;
126
+ inc(): void;
127
+ /** Adds n, a finite number of 0 or more; add(0) makes the set of labels known with a total of zero. */
128
+ add(n: number): void;
129
+ }
130
+ /** A value that goes up and down, written while this program is connected. */
131
+ export declare class Gauge<L extends string = string> {
132
+ #private;
133
+ constructor(instruments: Instruments, declared: Declared, labels: Record<string, string>);
134
+ with(labels: InstrumentLabels<L>): Gauge<L>;
135
+ set(value: number): void;
136
+ /** Moves it by n, from zero when it was never set. */
137
+ add(n: number): void;
138
+ inc(): void;
139
+ dec(): void;
140
+ }
141
+ /** How many things took how long: their count, sum and longest in milliseconds, and their spread over its buckets. */
142
+ export declare class Timer<L extends string = string> {
143
+ #private;
144
+ constructor(instruments: Instruments, declared: Declared, labels: Record<string, string>);
145
+ with(labels: InstrumentLabels<L>): Timer<L>;
146
+ /** Records a duration measured elsewhere: milliseconds, as performance.now() counts them, or text such as '250ms'. */
147
+ record(duration: Duration): void;
148
+ /**
149
+ * Runs fn, awaits what it returns, returns or throws what it does, and
150
+ * records how long it took either way.
151
+ *
152
+ * const user = await latency.with({ route: '/users' }).measure(() => users.get(id))
153
+ */
154
+ measure<R>(fn: () => R | Promise<R>): Promise<R>;
155
+ /** A timing that records when it stops, for a span that is no one function. */
156
+ start(): Timing;
157
+ }
158
+ /** A span a timer measures from its start; stop records it, once. */
159
+ export declare class Timing {
160
+ #private;
161
+ constructor(timer: Timer);
162
+ /** Records how long since the timing started, the first time it is called; its milliseconds. */
163
+ stop(): number;
164
+ }
165
+ /** A timer of numbers that are not durations: a response's size in bytes. */
166
+ export declare class Histogram<L extends string = string> {
167
+ #private;
168
+ constructor(instruments: Instruments, declared: Declared, labels: Record<string, string>);
169
+ with(labels: InstrumentLabels<L>): Histogram<L>;
170
+ /** Records a value of 0 or more. */
171
+ record(value: number): void;
172
+ }
173
+ /** Upper bounds from start, each factor times the one before: exponentialBuckets(1, 2, 14) is 1, 2, 4 … 8192. */
174
+ export declare function exponentialBuckets(start: number, factor: number, count: number): number[];
175
+ /** The interval of the store's grid a value of 0 or more falls in, by its label: '3:13', or 'zero'. */
176
+ export declare function binOf(value: number): string;
177
+ export {};