@restatedev/sessions 0.11.2 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +330 -178
- package/dist/addon.d.ts +1 -0
- package/dist/addon.d.ts.map +1 -1
- package/dist/addon.js.map +1 -1
- package/dist/calls.d.ts +28 -28
- package/dist/calls.d.ts.map +1 -1
- package/dist/calls.js +25 -25
- package/dist/calls.js.map +1 -1
- package/dist/database.d.ts +90 -166
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +137 -249
- package/dist/database.js.map +1 -1
- package/dist/driver.d.ts +129 -126
- package/dist/driver.d.ts.map +1 -1
- package/dist/driver.js +337 -276
- package/dist/driver.js.map +1 -1
- package/dist/endpoint.d.ts +47 -5
- package/dist/endpoint.d.ts.map +1 -1
- package/dist/endpoint.js +175 -60
- package/dist/endpoint.js.map +1 -1
- package/dist/handler.d.ts +20 -17
- package/dist/handler.d.ts.map +1 -1
- package/dist/handler.js +161 -127
- package/dist/handler.js.map +1 -1
- package/dist/host.d.ts +29 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +2 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -26
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +11 -11
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +20 -16
- package/dist/internal.js.map +1 -1
- package/dist/link.d.ts +1 -2
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +4 -5
- package/dist/link.js.map +1 -1
- package/dist/log.d.ts +14 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +21 -0
- package/dist/log.js.map +1 -0
- package/dist/object.d.ts +217 -142
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +195 -241
- package/dist/object.js.map +1 -1
- package/dist/platform.d.ts +0 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +4 -6
- package/dist/platform.js.map +1 -1
- package/dist/schema.d.ts +14 -22
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +31 -69
- package/dist/schema.js.map +1 -1
- package/dist/serve.d.ts +11 -17
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +21 -39
- package/dist/serve.js.map +1 -1
- package/dist/session.d.ts +58 -240
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +206 -532
- package/dist/session.js.map +1 -1
- package/dist/stop.d.ts +59 -0
- package/dist/stop.d.ts.map +1 -0
- package/dist/stop.js +220 -0
- package/dist/stop.js.map +1 -0
- package/dist/vm.d.ts +108 -29
- package/dist/vm.d.ts.map +1 -1
- package/dist/vm.js +43 -10
- package/dist/vm.js.map +1 -1
- package/package.json +4 -4
- package/src/addon.ts +1 -0
- package/src/calls.ts +51 -47
- package/src/database.ts +195 -339
- package/src/driver.ts +379 -315
- package/src/endpoint.ts +217 -62
- package/src/handler.ts +183 -164
- package/src/host.ts +28 -0
- package/src/index.ts +6 -26
- package/src/internal.ts +28 -39
- package/src/link.ts +4 -5
- package/src/log.ts +42 -0
- package/src/object.ts +379 -335
- package/src/platform.ts +4 -6
- package/src/schema.ts +37 -103
- package/src/serve.ts +20 -41
- package/src/session.ts +236 -629
- package/src/stop.ts +225 -0
- package/src/vm.ts +151 -55
- package/dist/scope.d.ts +0 -38
- package/dist/scope.d.ts.map +0 -1
- package/dist/scope.js +0 -55
- package/dist/scope.js.map +0 -1
- package/src/scope.ts +0 -78
package/dist/session.d.ts
CHANGED
|
@@ -1,119 +1,40 @@
|
|
|
1
1
|
import type * as restate from '@restatedev/restate-sdk';
|
|
2
|
-
import { type
|
|
3
|
-
import
|
|
4
|
-
import type { Vm } from './vm.ts';
|
|
2
|
+
import { type Row, type Connection, type DatabaseWriter, type SqlParam, type DatabaseReader, type SqlValue } from './database.ts';
|
|
3
|
+
import type { AttemptHost } from './host.ts';
|
|
5
4
|
import { type Schema } from './schema.ts';
|
|
6
5
|
import { type Send } from './calls.ts';
|
|
7
6
|
export type { DatabaseReader, DatabaseWriter, Row, SqlParam, SqlValue };
|
|
8
|
-
/**
|
|
9
|
-
* The session's database, `ctx.db`, for the whole handler: each statement
|
|
10
|
-
* outside {@link transaction} is its own transaction. Calls run one at a
|
|
11
|
-
* time, in call order.
|
|
12
|
-
*/
|
|
7
|
+
/** `ctx.db`. Each statement outside {@link transaction} is its own transaction. Calls run in call order. */
|
|
13
8
|
export interface Database extends DatabaseWriter {
|
|
14
9
|
/**
|
|
15
10
|
* Run `body` as one transaction: it commits when `body` resolves, and rolls
|
|
16
|
-
* back when it rejects.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* once `body` settles.
|
|
11
|
+
* back when it rejects. Other calls wait until it ends. A call to `ctx.db`
|
|
12
|
+
* from inside `body` is refused, because it would wait for `body`: use the
|
|
13
|
+
* `tx` that `body` gets, which is invalid once `body` settles.
|
|
20
14
|
*/
|
|
21
15
|
transaction<T>(body: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
22
16
|
}
|
|
23
17
|
/** One transaction of a {@link Database}: its SQL, and the sends it commits with. */
|
|
24
18
|
export interface Transaction extends DatabaseWriter {
|
|
25
19
|
/**
|
|
26
|
-
* Sends
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* again is dropped.
|
|
20
|
+
* Sends that commit with the transaction, and never if it rolls back: on
|
|
21
|
+
* Restate, in the commit's atomic group, so the rows and the sends are
|
|
22
|
+
* stored together or not at all. A delay counts from the commit.
|
|
30
23
|
*/
|
|
31
24
|
readonly send: Send;
|
|
32
|
-
/**
|
|
33
|
-
* Settles, and never rejects, once another call to `ctx.db` waits for this
|
|
34
|
-
* transaction to end. A body that keeps the transaction open for more work
|
|
35
|
-
* can return when it settles, so that the other call waits for one commit
|
|
36
|
-
* and no more.
|
|
37
|
-
*/
|
|
38
|
-
readonly queued: Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
/** What the session needs of the handler's context. */
|
|
41
|
-
export interface SqlHost {
|
|
42
|
-
/** A shared handler's: it reads beside the exclusive one, and stores nothing. */
|
|
43
|
-
readonly shared: boolean;
|
|
44
|
-
readonly key: string;
|
|
45
|
-
/** Rejects when the attempt ends (suspended, or aborted). */
|
|
46
|
-
readonly invocationEndPromise: {
|
|
47
|
-
readonly promise: Promise<unknown>;
|
|
48
|
-
};
|
|
49
|
-
readonly defaultSerde: Serde<any>;
|
|
50
|
-
request(): {
|
|
51
|
-
readonly id: string;
|
|
52
|
-
readonly target: {
|
|
53
|
-
readonly service: string;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
get(name: string, serde: Serde<Uint8Array>, options: restate.EntryOptions): PromiseLike<Uint8Array | null>;
|
|
57
|
-
set(name: string, value: Uint8Array, serde: Serde<Uint8Array>, options: restate.EntryOptions): void;
|
|
58
|
-
clear(name: string, options: restate.EntryOptions): void;
|
|
59
|
-
/** The object's state keys. */
|
|
60
|
-
stateKeys(): PromiseLike<string[]>;
|
|
61
|
-
run(name: string, action: () => void): PromiseLike<void>;
|
|
62
|
-
/**
|
|
63
|
-
* The attempt's VM, when it has one: the addon then reads and writes the
|
|
64
|
-
* object's state as the VM's own commands, and none of it crosses into
|
|
65
|
-
* JavaScript (see `openOnVm`).
|
|
66
|
-
*/
|
|
67
|
-
readonly vm?: Vm;
|
|
68
|
-
/**
|
|
69
|
-
* Whether a cancellation is owed to the handler's next await, taking it:
|
|
70
|
-
* the attempt's driver has one when a cancellation arrived that failed
|
|
71
|
-
* nothing the handler awaits. Absent where the SDK's context serves the
|
|
72
|
-
* attempt, whose own awaits fail with it.
|
|
73
|
-
*/
|
|
74
|
-
readonly takeCancellation?: () => boolean;
|
|
75
|
-
/**
|
|
76
|
-
* Keeps the attempt alive while a call of the database runs: the VM's
|
|
77
|
-
* attempt has it (`driver.ts`), the SDK's context does not.
|
|
78
|
-
*/
|
|
79
|
-
readonly working?: Working;
|
|
80
|
-
genericSend(send: restate.GenericSend<Uint8Array>): unknown;
|
|
81
25
|
}
|
|
82
|
-
/** What a session object gives its attempts
|
|
26
|
+
/** What a session object gives its attempts. */
|
|
83
27
|
export interface ObjectConfig {
|
|
84
|
-
/** The object's own schema, which each of its databases is made by. */
|
|
85
28
|
readonly schema?: Schema;
|
|
86
|
-
|
|
29
|
+
/** The serde of a typed client's `tx.send` to a handler that declares none: the `serde` option, JSON by default. */
|
|
30
|
+
readonly serde?: restate.Serde<unknown>;
|
|
87
31
|
}
|
|
88
32
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* its order are those of a call made now, and what it spares is the call.
|
|
92
|
-
* Its failure is the next call's (or the commit's, if none comes). Returns
|
|
93
|
-
* false, queuing nothing, if the transaction cannot (a `tx` of another
|
|
94
|
-
* kind, or an addon without it): run the statement with `tx.execute`.
|
|
95
|
-
*/
|
|
96
|
-
export declare function deferSql(tx: Transaction, sql: string): boolean;
|
|
97
|
-
/** Take back the last `sql` that {@link deferSql} queued on `tx` and no call has taken: it never runs. Whether it was taken back. */
|
|
98
|
-
export declare function undeferSql(tx: Transaction, sql: string): boolean;
|
|
99
|
-
/**
|
|
100
|
-
* `connection`, opened without the SDK (`open`), as a handler's `ctx.db`:
|
|
101
|
-
* for a library's tests, and tools. Its transactions send nothing, and a
|
|
102
|
-
* library's schema applies to it (`Schema.ensure`).
|
|
33
|
+
* `connection` (opened without the SDK) as a `ctx.db`, for library tests and
|
|
34
|
+
* tools. Its transactions cannot send. `Schema.ensure` works on it.
|
|
103
35
|
*/
|
|
104
36
|
export declare function asDatabase(connection: Connection): Database;
|
|
105
|
-
/**
|
|
106
|
-
* Empty the key's database in `tx`, a transaction of an exclusive handler's
|
|
107
|
-
* `ctx.db`: every table, view, index and trigger is dropped, the schemas are
|
|
108
|
-
* applied again (the object's, and the libraries' the attempt applied), and
|
|
109
|
-
* the outbox stays. It commits with `tx`: what `tx` writes after it are the
|
|
110
|
-
* new database's first rows, in the same commit.
|
|
111
|
-
*/
|
|
112
|
-
export declare function reset(tx: Transaction): Promise<void>;
|
|
113
|
-
/**
|
|
114
|
-
* A database that `opener` opens on its first call, as a handler's `ctx.db`
|
|
115
|
-
* opens: for tests, which give each attempt one over the same state.
|
|
116
|
-
*/
|
|
37
|
+
/** A database that `opener` opens on first use, as `ctx.db` does: for tests. */
|
|
117
38
|
export declare function lazyDatabase(opener: () => Promise<Database>): Database;
|
|
118
39
|
/** How a handler ended. */
|
|
119
40
|
type Outcome<T> = {
|
|
@@ -121,195 +42,92 @@ type Outcome<T> = {
|
|
|
121
42
|
} | {
|
|
122
43
|
error: unknown;
|
|
123
44
|
};
|
|
124
|
-
/** A write that rides the next commit of a database, in that commit's transaction. */
|
|
125
|
-
type Rider = (tx: Transaction) => Promise<void>;
|
|
126
|
-
/**
|
|
127
|
-
* Have `write` run in the next transaction of `db` that commits, before its
|
|
128
|
-
* commit, rather than commit on its own: for bookkeeping that must be stored
|
|
129
|
-
* with the next write, not before it. A write by `db.execute` outside a
|
|
130
|
-
* transaction, made while a rider is pending, is that transaction; a read
|
|
131
|
-
* (`get`, `values`, `query`) is not, and writes nothing. A transaction that
|
|
132
|
-
* rolls back leaves the rider pending, and so does one that ends the handler
|
|
133
|
-
* before it commits: {@link flushRiders} writes what is left.
|
|
134
|
-
*
|
|
135
|
-
* A database has one rider per `slot`: a later one replaces the earlier, and
|
|
136
|
-
* `undefined` clears it. A rider registered while a commit that runs the
|
|
137
|
-
* earlier one is under way is for the commit after. Returns false, registering
|
|
138
|
-
* nothing, for a database that cannot (a view's, another kind of
|
|
139
|
-
* `Database`): the caller writes at once.
|
|
140
|
-
*
|
|
141
|
-
* An `urgent` rider waits only for a transaction that is under way: if none
|
|
142
|
-
* is at the end of the macrotask it was registered in (or of the one in which
|
|
143
|
-
* a transaction ended and left it pending), it is written in a transaction of
|
|
144
|
-
* its own. A transaction that is held open (a batch of commits) is under way,
|
|
145
|
-
* and writes it when it commits. A write of its own that fails is not
|
|
146
|
-
* retried and raises nothing: the rider stays pending for the next commit or
|
|
147
|
-
* {@link flushRiders}. A rider that replaces an urgent one stays urgent.
|
|
148
|
-
*/
|
|
149
|
-
export declare function rideCommit(db: Database, slot: string, write: Rider | undefined, { urgent }?: {
|
|
150
|
-
urgent?: boolean;
|
|
151
|
-
}): boolean;
|
|
152
|
-
/**
|
|
153
|
-
* Write what is pending ({@link rideCommit}) in a transaction of its own, and resolve once it is stored. A
|
|
154
|
-
* transaction under way that commits first writes it, and this commits nothing; one that rolls back leaves
|
|
155
|
-
* it, and this writes it. Nothing, if nothing is pending.
|
|
156
|
-
*/
|
|
157
|
-
export declare function flushRiders(db: Database): Promise<void>;
|
|
158
45
|
/**
|
|
159
|
-
* The database `name
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* and ends with the attempt, as `ctx.db` does. A name is 1 to 64 letters,
|
|
163
|
-
* digits, `_`, `-` or `.`.
|
|
46
|
+
* The key's database `name`, separate from `ctx.db` (`db`): for a library
|
|
47
|
+
* whose tables must be alone. It opens on first use and
|
|
48
|
+
* ends with the attempt. A name is 1 to 64 letters, digits, `_`, `-` or `.`.
|
|
164
49
|
*/
|
|
165
50
|
export declare function database(db: Database, name: string): Database;
|
|
166
51
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* database `name` ({@link database}), which has neither the object's schema
|
|
171
|
-
* nor an outbox.
|
|
52
|
+
* The SQL session of an attempt, shared by everything the handler does. With
|
|
53
|
+
* `name`, it is the key's database `name` ({@link database}), which has no
|
|
54
|
+
* object schema and whose transactions cannot send.
|
|
172
55
|
*/
|
|
173
56
|
export declare class Attempt {
|
|
174
|
-
/** `ctx.db`. */
|
|
175
57
|
readonly db: Database;
|
|
176
|
-
private readonly
|
|
177
|
-
|
|
58
|
+
private readonly host;
|
|
59
|
+
private readonly view;
|
|
178
60
|
private readonly config;
|
|
179
61
|
private readonly name;
|
|
180
|
-
/**
|
|
181
|
-
private readonly
|
|
182
|
-
/** The key's other databases this attempt opened, by name. */
|
|
62
|
+
/** Only the object database of an exclusive handler has transactions that send. */
|
|
63
|
+
private readonly sends;
|
|
183
64
|
private readonly databases;
|
|
184
|
-
/** The session, from its first use on. */
|
|
185
65
|
private session;
|
|
186
|
-
/**
|
|
66
|
+
/** Calls that have not reached the connection yet: see {@link callNow}. */
|
|
187
67
|
private unhanded;
|
|
188
|
-
/**
|
|
189
|
-
private readonly made;
|
|
190
|
-
/** The writes that ride the next commit, by slot ({@link rideCommit}). */
|
|
191
|
-
private readonly riders;
|
|
192
|
-
/** The transactions asked for and not finished: one that is under way writes the riders. */
|
|
193
|
-
private active;
|
|
194
|
-
/** The macrotask at the end of which an urgent rider is written alone, if one is set. */
|
|
195
|
-
private urgentTimer;
|
|
196
|
-
/** The schemas this attempt's database has all the steps of. */
|
|
68
|
+
/** Schemas applied in this session. A view applies them only in its session. */
|
|
197
69
|
private readonly ensured;
|
|
198
70
|
private ended;
|
|
199
|
-
|
|
200
|
-
|
|
71
|
+
/** {@link end} began: the other databases are ending. */
|
|
72
|
+
private ending;
|
|
73
|
+
constructor(host: AttemptHost, view: boolean, config?: ObjectConfig, name?: string);
|
|
74
|
+
/** See {@link database}. */
|
|
201
75
|
database(name: string): Database;
|
|
202
|
-
/** {@link rideCommit}. */
|
|
203
|
-
ride(slot: string, write: Rider | undefined, urgent: boolean): boolean;
|
|
204
|
-
/** Have the urgent riders written at the end of this macrotask, if any is pending and none is set. */
|
|
205
|
-
private arm;
|
|
206
|
-
/** {@link flushRiders}, as a transaction of `db`: its commit writes them. */
|
|
207
|
-
flushRiders(): Promise<void>;
|
|
208
76
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* What the handler asks for passes through here; what the session does for
|
|
214
|
-
* itself does not — the open, the object's schema, the sends a crashed
|
|
215
|
-
* attempt left unmade, emptying the outbox after a commit — and a
|
|
216
|
-
* cancellation that failed one of those would be delivered to nobody, or
|
|
217
|
-
* would report a transaction as cancelled after it committed. And it is
|
|
218
|
-
* before the call issues anything, so a call that fails with
|
|
219
|
-
* `CancelledError` wrote nothing and sent nothing: a call already under way
|
|
220
|
-
* when the cancellation arrives runs to its end, and the cancellation goes
|
|
221
|
-
* to what the handler awaits next.
|
|
77
|
+
* Fail with an owed cancellation before anything runs (see stop.ts). Only
|
|
78
|
+
* handler calls pass here: failing the session's own work (the open, the
|
|
79
|
+
* object's schema, the save) would deliver the cancellation to nobody, or
|
|
80
|
+
* report a committed transaction as cancelled.
|
|
222
81
|
*/
|
|
223
82
|
private asked;
|
|
224
|
-
/** {@link asked} for a call that
|
|
83
|
+
/** {@link asked} for a call that may answer synchronously ({@link callNow}). */
|
|
225
84
|
private askedNow;
|
|
226
85
|
/**
|
|
227
|
-
* Open the
|
|
228
|
-
* call:
|
|
229
|
-
*
|
|
86
|
+
* Open the object database as an exclusive attempt starts, rather than on
|
|
87
|
+
* its first call: its head is read and the object schema applied while the
|
|
88
|
+
* handler gets going.
|
|
230
89
|
*/
|
|
231
90
|
openNow(): void;
|
|
232
|
-
/**
|
|
233
|
-
* The handler ended with `outcome`: the key's other databases end, then
|
|
234
|
-
* this one ({@link endSession}).
|
|
235
|
-
*/
|
|
91
|
+
/** The handler ended with `outcome`. The key's other databases end first, as the handler left them. */
|
|
236
92
|
end<T>(outcome: Outcome<T>): Promise<T>;
|
|
237
93
|
/**
|
|
238
|
-
* `body` as one transaction. In the object
|
|
239
|
-
* handler, its sends commit with it
|
|
240
|
-
* commit, right after its writes and before it waits for anything
|
|
241
|
-
* (`withCommit`): Restate stores an attempt's commands in order, so they
|
|
242
|
-
* are stored only if the commit is, and whatever fails the commit's wait
|
|
243
|
-
* (the attempt's end, say) comes after them. A second commit empties the outbox
|
|
244
|
-
* before `transaction` resolves: left until the handler's end, they would
|
|
245
|
-
* be made again by an attempt that resumes a long wait (an approval), past
|
|
246
|
-
* the idempotency retention that drops a repeat.
|
|
94
|
+
* `body` as one transaction. In the object database of an exclusive
|
|
95
|
+
* handler, its sends commit with it (see the block above `PendingSend`).
|
|
247
96
|
*/
|
|
248
97
|
private transaction;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
* Commit with `handle` the outbox as committed, but the sends stored since,
|
|
252
|
-
* and with `outgoing`, which the commit makes. Unchanged, it is not
|
|
253
|
-
* written again.
|
|
254
|
-
*/
|
|
255
|
-
private commitOutbox;
|
|
98
|
+
/** Have the commit of `handle` make `sends`: in its atomic group on the VM, else through the host. */
|
|
99
|
+
private commitSends;
|
|
256
100
|
/**
|
|
257
|
-
* `call
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* So the failure of an open made as the attempt started goes to the first
|
|
261
|
-
* call, as it would had that call opened it.
|
|
101
|
+
* Run `call`, opening the session on first use. A call that fails on an
|
|
102
|
+
* ended session retires it, and the next call opens a new one. So a failed
|
|
103
|
+
* open at attempt start fails the first call.
|
|
262
104
|
*/
|
|
263
105
|
private call;
|
|
264
106
|
/**
|
|
265
|
-
* {@link call}
|
|
266
|
-
*
|
|
267
|
-
* is for a session that is open, and with no call before it still to reach
|
|
268
|
-
* the connection (a call made before it, which waits for the session, must
|
|
269
|
-
* run first): anything else is {@link call}.
|
|
107
|
+
* {@link call} that may return the value synchronously: only for an open
|
|
108
|
+
* session with no earlier call still waiting to reach the connection.
|
|
270
109
|
*/
|
|
271
110
|
private callNow;
|
|
272
|
-
/** The session, opening one if there is none
|
|
111
|
+
/** The session, opening a new one if there is none or it was retired. */
|
|
273
112
|
private current;
|
|
274
113
|
private open;
|
|
275
114
|
private start;
|
|
276
115
|
/**
|
|
277
|
-
* End the session, then settle as the handler did
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
* A failure to end the session fails a handler that succeeded, which a
|
|
281
|
-
* retry then ends (a transaction it left open, say).
|
|
116
|
+
* End the session, then settle as the handler did. The handler's error wins
|
|
117
|
+
* (its commits are stored). A failure to end the session fails a handler
|
|
118
|
+
* that succeeded (for example, one that left a transaction open).
|
|
282
119
|
*/
|
|
283
120
|
private endSession;
|
|
284
121
|
/**
|
|
285
|
-
* Close the session
|
|
286
|
-
*
|
|
287
|
-
* ("is gone"), which is retried. Another is saved, its outbox emptied. One
|
|
288
|
-
* that a failure ended closes, and the object's own database is opened
|
|
289
|
-
* again and saved: it may hold sends unmade (a crash left them, and this
|
|
290
|
-
* attempt's open failed) or made and not emptied (the commit's wait
|
|
291
|
-
* failed), and no attempt may follow this one (a cancelled invocation's),
|
|
292
|
-
* nor the key's next invocation come within the idempotency retention.
|
|
122
|
+
* Close the session. A view only closes. Otherwise the session is saved; one
|
|
123
|
+
* that a failure ended closes, and what it committed is stored as it was.
|
|
293
124
|
*/
|
|
294
125
|
private close;
|
|
295
|
-
/**
|
|
126
|
+
/** Save the session. The session closes if that fails. */
|
|
296
127
|
private save;
|
|
297
|
-
/** The object
|
|
128
|
+
/** The object schema. The key's other databases do not get it. */
|
|
298
129
|
private ownSchema;
|
|
299
|
-
/**
|
|
300
|
-
private reset;
|
|
301
|
-
/** Apply the steps of `schemas` that the database lacks, each schema once per attempt. */
|
|
130
|
+
/** Apply the steps of `schemas` that the database lacks, each schema once per session. */
|
|
302
131
|
private ensureSchemas;
|
|
303
|
-
/** Make the sends of a committed transaction: each with an idempotency key of the transaction (or its own), so that making them again is dropped. */
|
|
304
|
-
private make;
|
|
305
|
-
/** The outbox as committed, but the transactions this attempt made the sends of: a commit made after them stores them first. */
|
|
306
|
-
private unstored;
|
|
307
|
-
/**
|
|
308
|
-
* Empty the outbox, so that a later open does not make its sends again: a
|
|
309
|
-
* commit after them, which stores them first.
|
|
310
|
-
*/
|
|
311
|
-
private flush;
|
|
312
132
|
}
|
|
313
|
-
/** Run `handler`, then end `attempt`'s SQL session, if it opened one (see {@link Attempt.end}). */
|
|
314
|
-
export declare function withAttempt<T>(handler: () => Promise<T>, attempt: Attempt): Promise<T>;
|
|
315
133
|
//# sourceMappingURL=session.d.ts.map
|
package/dist/session.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRo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