lwnrdb-client 0.0.0-stage → 0.1.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 +171 -2
- package/dist/admin/admin.d.ts +114 -0
- package/dist/admin/admin.js +87 -0
- package/dist/admin/admin.js.map +1 -0
- package/dist/admin/types.d.ts +267 -0
- package/dist/admin/types.js +10 -0
- package/dist/admin/types.js.map +1 -0
- package/dist/client.d.ts +101 -0
- package/dist/client.js +112 -0
- package/dist/client.js.map +1 -0
- package/dist/collection.d.ts +126 -0
- package/dist/collection.js +66 -0
- package/dist/collection.js.map +1 -0
- package/dist/database.d.ts +83 -0
- package/dist/database.js +51 -0
- package/dist/database.js.map +1 -0
- package/dist/document.d.ts +35 -0
- package/dist/document.js +2 -0
- package/dist/document.js.map +1 -0
- package/dist/errors/error-codes.d.ts +43 -0
- package/dist/errors/error-codes.js +367 -0
- package/dist/errors/error-codes.js.map +1 -0
- package/dist/errors/errors.d.ts +111 -0
- package/dist/errors/errors.js +44 -0
- package/dist/errors/errors.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/indexes.d.ts +35 -0
- package/dist/indexes.js +31 -0
- package/dist/indexes.js.map +1 -0
- package/dist/internal/client-context.d.ts +13 -0
- package/dist/internal/client-context.js +4 -0
- package/dist/internal/client-context.js.map +1 -0
- package/dist/internal/codecs.d.ts +4 -0
- package/dist/internal/codecs.js +13 -0
- package/dist/internal/codecs.js.map +1 -0
- package/dist/internal/collection-ops.d.ts +31 -0
- package/dist/internal/collection-ops.js +75 -0
- package/dist/internal/collection-ops.js.map +1 -0
- package/dist/internal/connection-factory.d.ts +12 -0
- package/dist/internal/connection-factory.js +91 -0
- package/dist/internal/connection-factory.js.map +1 -0
- package/dist/internal/connection-pool.d.ts +18 -0
- package/dist/internal/connection-pool.js +140 -0
- package/dist/internal/connection-pool.js.map +1 -0
- package/dist/internal/custom-values.d.ts +11 -0
- package/dist/internal/custom-values.js +76 -0
- package/dist/internal/custom-values.js.map +1 -0
- package/dist/internal/descriptors.d.ts +14 -0
- package/dist/internal/descriptors.js +128 -0
- package/dist/internal/descriptors.js.map +1 -0
- package/dist/internal/frame-router.d.ts +10 -0
- package/dist/internal/frame-router.js +23 -0
- package/dist/internal/frame-router.js.map +1 -0
- package/dist/internal/line-reader.d.ts +11 -0
- package/dist/internal/line-reader.js +51 -0
- package/dist/internal/line-reader.js.map +1 -0
- package/dist/internal/listen-channel.d.ts +22 -0
- package/dist/internal/listen-channel.js +191 -0
- package/dist/internal/listen-channel.js.map +1 -0
- package/dist/internal/listens.d.ts +12 -0
- package/dist/internal/listens.js +69 -0
- package/dist/internal/listens.js.map +1 -0
- package/dist/internal/names.d.ts +3 -0
- package/dist/internal/names.js +20 -0
- package/dist/internal/names.js.map +1 -0
- package/dist/internal/number-guard.d.ts +2 -0
- package/dist/internal/number-guard.js +14 -0
- package/dist/internal/number-guard.js.map +1 -0
- package/dist/internal/pipeline-encoder.d.ts +9 -0
- package/dist/internal/pipeline-encoder.js +130 -0
- package/dist/internal/pipeline-encoder.js.map +1 -0
- package/dist/internal/request-channel.d.ts +21 -0
- package/dist/internal/request-channel.js +69 -0
- package/dist/internal/request-channel.js.map +1 -0
- package/dist/internal/request-encoder.d.ts +41 -0
- package/dist/internal/request-encoder.js +123 -0
- package/dist/internal/request-encoder.js.map +1 -0
- package/dist/internal/response-decoder.d.ts +11 -0
- package/dist/internal/response-decoder.js +76 -0
- package/dist/internal/response-decoder.js.map +1 -0
- package/dist/internal/script-request-encoder.d.ts +32 -0
- package/dist/internal/script-request-encoder.js +144 -0
- package/dist/internal/script-request-encoder.js.map +1 -0
- package/dist/internal/values-codec.d.ts +12 -0
- package/dist/internal/values-codec.js +96 -0
- package/dist/internal/values-codec.js.map +1 -0
- package/dist/internal/wire-connection.d.ts +17 -0
- package/dist/internal/wire-connection.js +171 -0
- package/dist/internal/wire-connection.js.map +1 -0
- package/dist/protocol/operations.d.ts +45 -0
- package/dist/protocol/operations.js +63 -0
- package/dist/protocol/operations.js.map +1 -0
- package/dist/protocol/status.d.ts +15 -0
- package/dist/protocol/status.js +9 -0
- package/dist/protocol/status.js.map +1 -0
- package/dist/query/field-condition.d.ts +58 -0
- package/dist/query/field-condition.js +42 -0
- package/dist/query/field-condition.js.map +1 -0
- package/dist/query/filters.d.ts +82 -0
- package/dist/query/filters.js +64 -0
- package/dist/query/filters.js.map +1 -0
- package/dist/query/map-ops.d.ts +12 -0
- package/dist/query/map-ops.js +8 -0
- package/dist/query/map-ops.js.map +1 -0
- package/dist/query/mid-ops.d.ts +98 -0
- package/dist/query/mid-ops.js +63 -0
- package/dist/query/mid-ops.js.map +1 -0
- package/dist/query/nearest-filter.d.ts +32 -0
- package/dist/query/nearest-filter.js +26 -0
- package/dist/query/nearest-filter.js.map +1 -0
- package/dist/query/query.d.ts +130 -0
- package/dist/query/query.js +106 -0
- package/dist/query/query.js.map +1 -0
- package/dist/query/types.d.ts +330 -0
- package/dist/query/types.js +72 -0
- package/dist/query/types.js.map +1 -0
- package/dist/results.d.ts +87 -0
- package/dist/results.js +2 -0
- package/dist/results.js.map +1 -0
- package/dist/retry-policy.d.ts +27 -0
- package/dist/retry-policy.js +24 -0
- package/dist/retry-policy.js.map +1 -0
- package/dist/schema.d.ts +24 -0
- package/dist/schema.js +33 -0
- package/dist/schema.js.map +1 -0
- package/dist/scripting/definitions.d.ts +287 -0
- package/dist/scripting/definitions.js +4 -0
- package/dist/scripting/definitions.js.map +1 -0
- package/dist/scripting/procedures.d.ts +33 -0
- package/dist/scripting/procedures.js +25 -0
- package/dist/scripting/procedures.js.map +1 -0
- package/dist/scripting/schedules.d.ts +25 -0
- package/dist/scripting/schedules.js +22 -0
- package/dist/scripting/schedules.js.map +1 -0
- package/dist/scripting/triggers.d.ts +34 -0
- package/dist/scripting/triggers.js +33 -0
- package/dist/scripting/triggers.js.map +1 -0
- package/dist/settings.d.ts +134 -0
- package/dist/settings.js +62 -0
- package/dist/settings.js.map +1 -0
- package/dist/subscription.d.ts +63 -0
- package/dist/subscription.js +2 -0
- package/dist/subscription.js.map +1 -0
- package/dist/tls-settings.d.ts +18 -0
- package/dist/tls-settings.js +2 -0
- package/dist/tls-settings.js.map +1 -0
- package/dist/transaction.d.ts +141 -0
- package/dist/transaction.js +113 -0
- package/dist/transaction.js.map +1 -0
- package/dist/values/custom-type.d.ts +13 -0
- package/dist/values/custom-type.js +7 -0
- package/dist/values/custom-type.js.map +1 -0
- package/dist/values/geo-distance-comparator.d.ts +14 -0
- package/dist/values/geo-distance-comparator.js +8 -0
- package/dist/values/geo-distance-comparator.js.map +1 -0
- package/dist/values/geo-point.d.ts +30 -0
- package/dist/values/geo-point.js +27 -0
- package/dist/values/geo-point.js.map +1 -0
- package/dist/values/local-date-time.d.ts +87 -0
- package/dist/values/local-date-time.js +133 -0
- package/dist/values/local-date-time.js.map +1 -0
- package/dist/values/local-time.d.ts +54 -0
- package/dist/values/local-time.js +38 -0
- package/dist/values/local-time.js.map +1 -0
- package/dist/values/temporal-text.d.ts +12 -0
- package/dist/values/temporal-text.js +63 -0
- package/dist/values/temporal-text.js.map +1 -0
- package/dist/values/vector.d.ts +40 -0
- package/dist/values/vector.js +43 -0
- package/dist/values/vector.js.map +1 -0
- package/package.json +56 -5
package/README.md
CHANGED
|
@@ -1,3 +1,172 @@
|
|
|
1
|
-
#
|
|
1
|
+
# LWNRDB Node.js client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The JavaScript and TypeScript client for [LWNRDB](https://github.com/christiancg/lwnrdb). It keeps a pool of
|
|
4
|
+
authenticated connections and gives you a fluent query builder, transactions, live queries and the server's custom
|
|
5
|
+
value types. It needs Node.js 22.12 or newer and has no runtime dependencies.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install lwnrdb-client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The package is ESM with its type declarations included. CommonJS code can load it with `require`.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { and, field, LwnrdbClient, Order } from "lwnrdb-client";
|
|
19
|
+
|
|
20
|
+
const client = await LwnrdbClient.connect({
|
|
21
|
+
hosts: [{ host: "localhost", port: 8989 }],
|
|
22
|
+
credentials: { username: "admin", password: process.env.LWNRDB_PASSWORD ?? "" },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const shop = client.database("shop");
|
|
26
|
+
await shop.create();
|
|
27
|
+
const orders = shop.collection("orders");
|
|
28
|
+
await orders.create();
|
|
29
|
+
|
|
30
|
+
await orders.save({ _id: "o-1", status: "active", total: 120 });
|
|
31
|
+
const order = await orders.findById("o-1");
|
|
32
|
+
|
|
33
|
+
const page = await orders
|
|
34
|
+
.query()
|
|
35
|
+
.filter(and(field("status").eq("active"), field("total").gt(100)))
|
|
36
|
+
.sort("total", Order.DESC)
|
|
37
|
+
.limit(10)
|
|
38
|
+
.toArray();
|
|
39
|
+
|
|
40
|
+
await client.close();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
A collection has to exist before you write to it. Besides `save` and `findById`, a collection has `insert`, `saveAll`,
|
|
44
|
+
`delete`, `updateWhere` and `deleteWhere`. The pool size is how many requests run at once.
|
|
45
|
+
|
|
46
|
+
## Settings
|
|
47
|
+
|
|
48
|
+
The ones you usually set are `hosts` (tried in turn), `credentials` (`{ username, password }`), `tls` and `poolSize`
|
|
49
|
+
(8 by default). Timeouts, the retry policy and the rest are in the API reference.
|
|
50
|
+
|
|
51
|
+
## Typed collections
|
|
52
|
+
|
|
53
|
+
`collection<T>(name)` types what you save as `T` and what you read as `T & { _id: string }`. It is only a compile-time
|
|
54
|
+
type.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
interface Order {
|
|
58
|
+
readonly _id?: string;
|
|
59
|
+
readonly status: "active" | "closed";
|
|
60
|
+
readonly total: number;
|
|
61
|
+
readonly placedAt: LocalDateTime;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const orders = shop.collection<Order>("orders");
|
|
65
|
+
await orders.save({ status: "active", total: 120, placedAt: LocalDateTime.of(2024, 1, 1, 10, 0) });
|
|
66
|
+
const active = await orders.query().filter(field("status").eq("active")).toArray();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
To map documents to your own classes, pass a `DocumentCodec` with `encode` and `decode` as the second argument.
|
|
70
|
+
|
|
71
|
+
## Custom value types
|
|
72
|
+
|
|
73
|
+
The server has four value types of its own. The client maps them to classes both ways.
|
|
74
|
+
|
|
75
|
+
| Server value | Class | Example |
|
|
76
|
+
| ----------------------------- | --------------- | ----------------------------------------------------------------------------------------- |
|
|
77
|
+
| `#datetime(2024-01-01T10:00)` | `LocalDateTime` | `field("placedAt").gte(LocalDateTime.of(2024, 1, 1))` |
|
|
78
|
+
| `#time(09:30)` | `LocalTime` | `field("opensAt").lt(LocalTime.of(12, 0))` |
|
|
79
|
+
| `#geo(lat,lng)` | `GeoPoint` | `distance("location", GeoPoint.of(40.71, -74), GeoDistanceComparator.SMALLER_THAN, 1000)` |
|
|
80
|
+
| `#vector(v0,v1,...)` | `Vector` | `nearest("embedding", Vector.of(0.12, 0.44, 0.91), 10)` |
|
|
81
|
+
|
|
82
|
+
The server's date-time has no zone, so a `Date` is refused unless you set `temporalZone`. The server stores numbers as
|
|
83
|
+
doubles, so keep integers past the safe range in strings. `nearest` is approximate. Add `.exact()` to get the true top
|
|
84
|
+
`k`.
|
|
85
|
+
|
|
86
|
+
## Queries
|
|
87
|
+
|
|
88
|
+
`collection.query()` starts a pipeline. Queries are immutable, so every step returns a new one.
|
|
89
|
+
|
|
90
|
+
| Step | Method |
|
|
91
|
+
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
92
|
+
| `FILTER` | `filter(...)` with `field(...).eq/ne/gt/gte/lt/lte/in/notIn/contains`, `and/or/nor/xor/nand`, `distance`, `within`, `nearest`, `script` |
|
|
93
|
+
| `MAP` | `map(MapOps.set(field, MidOps...), MapOps.remove(field))`, each optionally `.when(filter)` |
|
|
94
|
+
| `GROUP_BY`, `DISTINCT`, `JOIN` | `groupBy(field)`, `distinct()`, `distinct(field)`, `join(collection, localField, remoteField, asField)` |
|
|
95
|
+
| `SORT`, `SKIP`, `LIMIT` | `sort(field, Order.ASC \| Order.DESC)`, `skip(n)`, `limit(n)` |
|
|
96
|
+
| `REDUCE` | `reduce(script)`, `reduce(script, initialValue, resultField)` |
|
|
97
|
+
| `COUNT` | `count()` |
|
|
98
|
+
|
|
99
|
+
Run it with `toArray()`, `toDocuments()`, `first()`, `count()` or `analyze()`.
|
|
100
|
+
|
|
101
|
+
## Transactions
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
const id = await client.transaction(async (tx) => {
|
|
105
|
+
const accounts = tx.collection("bank", "accounts");
|
|
106
|
+
await accounts.save(debit);
|
|
107
|
+
await accounts.save(credit);
|
|
108
|
+
return tx.id;
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The body commits when its promise resolves and rolls back when it rejects. A transaction holds one connection, its
|
|
113
|
+
writes lock their collections until the commit, and the server rolls it back after `transactionIdleTimeoutMs` idle.
|
|
114
|
+
|
|
115
|
+
## Live queries
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const subscription = await orders.listen(orders.query().filter(field("status").eq("pending")), {
|
|
119
|
+
onUpdate: (update) => render(update.results),
|
|
120
|
+
onEnded: (reason) => markStale(reason),
|
|
121
|
+
onError: (error) => log(error),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
await subscription.close();
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The handler gets the whole result right away, then again every time a write changes it, one update at a time. Live
|
|
128
|
+
queries use their own connections, which keep the process alive until you close the subscriptions.
|
|
129
|
+
|
|
130
|
+
## Errors and retries
|
|
131
|
+
|
|
132
|
+
Every refusal from the server is an `LwnrdbError` with the server's error code. There is a subclass per range:
|
|
133
|
+
`AuthenticationError` (401), `ForbiddenError` (403), `NotFoundError` (404), `ConflictError` (409), `ListenEndedError`
|
|
134
|
+
(410), `UnavailableError` (503) and `UnknownOutcomeError` (`500-33`, `500-34`).
|
|
135
|
+
|
|
136
|
+
The client retries [retryable](../../docs/protocol.md#error-codes) codes and reads that lost their connection. It
|
|
137
|
+
never retries a write that lost its connection (`ConnectionLostError`), an unknown outcome, or anything inside a
|
|
138
|
+
transaction.
|
|
139
|
+
|
|
140
|
+
## TLS
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
const client = await LwnrdbClient.connect({
|
|
144
|
+
hosts: [{ host: "db.example.com", port: 8989 }],
|
|
145
|
+
tls: { ca: readFileSync("lwnrdb-ca.pem") },
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`tls: {}` uses Node's certificate authorities, and `insecure: true` trusts any certificate, only for development.
|
|
150
|
+
Node can't read a PKCS12 trust store, so export the server's certificate as PEM:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
keytool -exportcert -rfc -alias <alias> -keystore lwnrdb.p12 -storetype PKCS12 -storepass <password> > lwnrdb-ca.pem
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## API reference
|
|
157
|
+
|
|
158
|
+
The API docs are in [`apidocs/`](apidocs) and in the published `.d.ts` files, so your editor shows them on hover.
|
|
159
|
+
|
|
160
|
+
## Building
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
npm ci
|
|
164
|
+
npm run verify
|
|
165
|
+
npm run consumers
|
|
166
|
+
mvn package -DskipTests # at the repository root, the server jar the integration tests use
|
|
167
|
+
LWNRDB_JAR=$PWD/../../target/lwnrdb.jar npm run test:it
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Releasing
|
|
171
|
+
|
|
172
|
+
Push a `typescript-client-vX.Y.Z` tag. The release workflow tests the client and publishes it to npm.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { ClientContext } from "../internal/client-context.js";
|
|
2
|
+
import type { Filter } from "../query/types.js";
|
|
3
|
+
import type { Permissions, ScriptRun, TransactionDecision, TransactionInfo, TriggerRun, TriggerRunDecision, TriggerRunStatus, UserInfo } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* User management. Admin only, except a user changing its own password.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Users {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(context: ClientContext);
|
|
10
|
+
/**
|
|
11
|
+
* @param username the new user's name
|
|
12
|
+
* @param password its password
|
|
13
|
+
* @param permissions optional grants; none by default
|
|
14
|
+
*/
|
|
15
|
+
create(username: string, password: string, permissions?: Permissions): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* @param username the user to delete; the last admin cannot be deleted
|
|
18
|
+
*/
|
|
19
|
+
delete(username: string): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Replaces a user's grants.
|
|
22
|
+
*
|
|
23
|
+
* @param username the user
|
|
24
|
+
* @param permissions the new grants
|
|
25
|
+
*/
|
|
26
|
+
changePermissions(username: string, permissions: Permissions): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Sets another user's password.
|
|
29
|
+
*
|
|
30
|
+
* @param username the user
|
|
31
|
+
* @param newPassword the new password
|
|
32
|
+
*/
|
|
33
|
+
setPassword(username: string, newPassword: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* @param filter optional filter over the user rows
|
|
36
|
+
* @returns the users; an empty listing is an empty array
|
|
37
|
+
*/
|
|
38
|
+
list(filter?: Filter): Promise<UserInfo[]>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The distributed transactions of a cluster that wait for a decision. Admin only.
|
|
42
|
+
*/
|
|
43
|
+
export declare class DistributedTransactions {
|
|
44
|
+
#private;
|
|
45
|
+
constructor(context: ClientContext);
|
|
46
|
+
/**
|
|
47
|
+
* @returns the transactions
|
|
48
|
+
*/
|
|
49
|
+
list(): Promise<TransactionInfo[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Decides a stuck transaction.
|
|
52
|
+
*
|
|
53
|
+
* @param dtxId the transaction's id
|
|
54
|
+
* @param decision commit or abort
|
|
55
|
+
*/
|
|
56
|
+
resolve(dtxId: string, decision: TransactionDecision): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The scripts running on the server. Admin only.
|
|
60
|
+
*/
|
|
61
|
+
export declare class Scripts {
|
|
62
|
+
#private;
|
|
63
|
+
constructor(context: ClientContext);
|
|
64
|
+
/**
|
|
65
|
+
* @returns the running scripts
|
|
66
|
+
*/
|
|
67
|
+
list(): Promise<ScriptRun[]>;
|
|
68
|
+
/**
|
|
69
|
+
* @param runId the run to cancel
|
|
70
|
+
* @returns whether it was cancelled
|
|
71
|
+
*/
|
|
72
|
+
cancel(runId: string): Promise<boolean>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Trigger runs that are pending or exhausted their attempts. Admin only.
|
|
76
|
+
*/
|
|
77
|
+
export declare class TriggerRuns {
|
|
78
|
+
#private;
|
|
79
|
+
constructor(context: ClientContext);
|
|
80
|
+
/**
|
|
81
|
+
* @param status optional state to keep
|
|
82
|
+
* @returns the runs
|
|
83
|
+
*/
|
|
84
|
+
list(status?: TriggerRunStatus): Promise<TriggerRun[]>;
|
|
85
|
+
/**
|
|
86
|
+
* @param runId the run
|
|
87
|
+
* @param decision replay or discard
|
|
88
|
+
* @returns whether it was resolved
|
|
89
|
+
*/
|
|
90
|
+
resolve(runId: string, decision: TriggerRunDecision): Promise<boolean>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Administrative operations. Most need an admin user.
|
|
94
|
+
*/
|
|
95
|
+
export declare class Admin {
|
|
96
|
+
#private;
|
|
97
|
+
constructor(context: ClientContext);
|
|
98
|
+
/**
|
|
99
|
+
* @returns user management
|
|
100
|
+
*/
|
|
101
|
+
users(): Users;
|
|
102
|
+
/**
|
|
103
|
+
* @returns the distributed transactions of a cluster
|
|
104
|
+
*/
|
|
105
|
+
transactions(): DistributedTransactions;
|
|
106
|
+
/**
|
|
107
|
+
* @returns the running scripts
|
|
108
|
+
*/
|
|
109
|
+
scripts(): Scripts;
|
|
110
|
+
/**
|
|
111
|
+
* @returns the pending and dead trigger runs
|
|
112
|
+
*/
|
|
113
|
+
triggerRuns(): TriggerRuns;
|
|
114
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { emptyOn } from "../internal/collection-ops.js";
|
|
2
|
+
import { scriptRun, transaction, triggerRun, user } from "../internal/descriptors.js";
|
|
3
|
+
import { booleanOf, documents } from "../internal/response-decoder.js";
|
|
4
|
+
import { ErrorCode } from "../errors/error-codes.js";
|
|
5
|
+
export class Users {
|
|
6
|
+
#context;
|
|
7
|
+
constructor(context) {
|
|
8
|
+
this.#context = context;
|
|
9
|
+
}
|
|
10
|
+
async create(username, password, permissions) {
|
|
11
|
+
await this.#context.channel.send("CREATE_USER", this.#context.scripts.createUser(username, password, permissions));
|
|
12
|
+
}
|
|
13
|
+
async delete(username) {
|
|
14
|
+
await this.#context.channel.send("DELETE_USER", this.#context.scripts.deleteUser(username));
|
|
15
|
+
}
|
|
16
|
+
async changePermissions(username, permissions) {
|
|
17
|
+
await this.#context.channel.send("CHANGE_PERMISSIONS", this.#context.scripts.changePermissions(username, permissions));
|
|
18
|
+
}
|
|
19
|
+
async setPassword(username, newPassword) {
|
|
20
|
+
await this.#context.channel.send("SET_PASSWORD", this.#context.scripts.setPassword(username, undefined, newPassword));
|
|
21
|
+
}
|
|
22
|
+
async list(filter) {
|
|
23
|
+
const request = this.#context.scripts.listUsers(filter === undefined ? [] : [{ type: "FILTER", filter }]);
|
|
24
|
+
const read = async () => documents(await this.#context.channel.send("LIST_USERS", request), "users").map(user);
|
|
25
|
+
return emptyOn(ErrorCode.NO_USERS_FOUND, [], () => emptyOn(ErrorCode.NO_RESULTS, [], read));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class DistributedTransactions {
|
|
29
|
+
#context;
|
|
30
|
+
constructor(context) {
|
|
31
|
+
this.#context = context;
|
|
32
|
+
}
|
|
33
|
+
async list() {
|
|
34
|
+
const reply = await this.#context.channel.send("LIST_TRANSACTIONS", this.#context.scripts.listTransactions());
|
|
35
|
+
return documents(reply, "transactions").map(transaction);
|
|
36
|
+
}
|
|
37
|
+
async resolve(dtxId, decision) {
|
|
38
|
+
await this.#context.channel.send("RESOLVE_TRANSACTION", this.#context.scripts.resolveTransaction(dtxId, decision));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class Scripts {
|
|
42
|
+
#context;
|
|
43
|
+
constructor(context) {
|
|
44
|
+
this.#context = context;
|
|
45
|
+
}
|
|
46
|
+
async list() {
|
|
47
|
+
const reply = await this.#context.channel.send("LIST_SCRIPTS", this.#context.scripts.listScripts());
|
|
48
|
+
return documents(reply, "scripts").map(scriptRun);
|
|
49
|
+
}
|
|
50
|
+
async cancel(runId) {
|
|
51
|
+
const reply = await this.#context.channel.send("CANCEL_SCRIPT", this.#context.scripts.cancelScript(runId));
|
|
52
|
+
return booleanOf(reply.cancelled, false);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class TriggerRuns {
|
|
56
|
+
#context;
|
|
57
|
+
constructor(context) {
|
|
58
|
+
this.#context = context;
|
|
59
|
+
}
|
|
60
|
+
async list(status) {
|
|
61
|
+
const reply = await this.#context.channel.send("LIST_TRIGGER_RUNS", this.#context.scripts.listTriggerRuns(status));
|
|
62
|
+
return documents(reply, "runs").map(triggerRun);
|
|
63
|
+
}
|
|
64
|
+
async resolve(runId, decision) {
|
|
65
|
+
const reply = await this.#context.channel.send("RESOLVE_TRIGGER_RUN", this.#context.scripts.resolveTriggerRun(runId, decision));
|
|
66
|
+
return booleanOf(reply.resolved, false);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export class Admin {
|
|
70
|
+
#context;
|
|
71
|
+
constructor(context) {
|
|
72
|
+
this.#context = context;
|
|
73
|
+
}
|
|
74
|
+
users() {
|
|
75
|
+
return new Users(this.#context);
|
|
76
|
+
}
|
|
77
|
+
transactions() {
|
|
78
|
+
return new DistributedTransactions(this.#context);
|
|
79
|
+
}
|
|
80
|
+
scripts() {
|
|
81
|
+
return new Scripts(this.#context);
|
|
82
|
+
}
|
|
83
|
+
triggerRuns() {
|
|
84
|
+
return new TriggerRuns(this.#context);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=admin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../../src/admin/admin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAarD,MAAM,OAAO,KAAK;IACL,QAAQ,CAAgB;IAEjC,YAAY,OAAsB;QAC9B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAE,QAAgB,EAAE,WAAyB;QACtE,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAC5B,aAAa,EACb,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC,CACpE,CAAC;IACN,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,QAAgB;QACzB,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CA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
|
+
* A data grant: `READ` or `READ_WRITE`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DataPermission: {
|
|
6
|
+
readonly READ: "READ";
|
|
7
|
+
readonly READ_WRITE: "READ_WRITE";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A data grant: `READ` or `READ_WRITE`.
|
|
11
|
+
*/
|
|
12
|
+
export type DataPermission = (typeof DataPermission)[keyof typeof DataPermission];
|
|
13
|
+
/**
|
|
14
|
+
* A server-wide grant: `CREATE_DATABASE` or `DROP_DATABASE`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const GlobalPermission: {
|
|
17
|
+
readonly CREATE_DATABASE: "CREATE_DATABASE";
|
|
18
|
+
readonly DROP_DATABASE: "DROP_DATABASE";
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A server-wide grant: `CREATE_DATABASE` or `DROP_DATABASE`.
|
|
22
|
+
*/
|
|
23
|
+
export type GlobalPermission = (typeof GlobalPermission)[keyof typeof GlobalPermission];
|
|
24
|
+
/**
|
|
25
|
+
* A script grant: `NONE`, `RUN` or `MANAGE`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const ScriptPermission: {
|
|
28
|
+
readonly NONE: "NONE";
|
|
29
|
+
readonly RUN: "RUN";
|
|
30
|
+
readonly MANAGE: "MANAGE";
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A script grant: `NONE`, `RUN` or `MANAGE`.
|
|
34
|
+
*/
|
|
35
|
+
export type ScriptPermission = (typeof ScriptPermission)[keyof typeof ScriptPermission];
|
|
36
|
+
/**
|
|
37
|
+
* How to resolve a stuck distributed transaction: `commit` or `abort`.
|
|
38
|
+
*/
|
|
39
|
+
export declare const TransactionDecision: {
|
|
40
|
+
readonly COMMIT: "commit";
|
|
41
|
+
readonly ABORT: "abort";
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* How to resolve a stuck distributed transaction: `commit` or `abort`.
|
|
45
|
+
*/
|
|
46
|
+
export type TransactionDecision = (typeof TransactionDecision)[keyof typeof TransactionDecision];
|
|
47
|
+
/**
|
|
48
|
+
* The state of a trigger run: `PENDING`, `DEAD` or `STAGED`.
|
|
49
|
+
*/
|
|
50
|
+
export declare const TriggerRunStatus: {
|
|
51
|
+
readonly PENDING: "PENDING";
|
|
52
|
+
readonly DEAD: "DEAD";
|
|
53
|
+
readonly STAGED: "STAGED";
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The state of a trigger run: `PENDING`, `DEAD` or `STAGED`.
|
|
57
|
+
*/
|
|
58
|
+
export type TriggerRunStatus = (typeof TriggerRunStatus)[keyof typeof TriggerRunStatus];
|
|
59
|
+
/**
|
|
60
|
+
* How to resolve a trigger run: `replay` or `discard`.
|
|
61
|
+
*/
|
|
62
|
+
export declare const TriggerRunDecision: {
|
|
63
|
+
readonly REPLAY: "replay";
|
|
64
|
+
readonly DISCARD: "discard";
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* How to resolve a trigger run: `replay` or `discard`.
|
|
68
|
+
*/
|
|
69
|
+
export type TriggerRunDecision = (typeof TriggerRunDecision)[keyof typeof TriggerRunDecision];
|
|
70
|
+
/**
|
|
71
|
+
* The grants of a user. Every field is optional.
|
|
72
|
+
*/
|
|
73
|
+
export interface Permissions {
|
|
74
|
+
/**
|
|
75
|
+
* Whether the user is an admin.
|
|
76
|
+
*/
|
|
77
|
+
readonly admin?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Server-wide grants.
|
|
80
|
+
*/
|
|
81
|
+
readonly global?: readonly GlobalPermission[];
|
|
82
|
+
/**
|
|
83
|
+
* Grants by database name.
|
|
84
|
+
*/
|
|
85
|
+
readonly databases?: Readonly<Record<string, DataPermission>>;
|
|
86
|
+
/**
|
|
87
|
+
* Grants by `database|collection` key; build one with `collectionKey`.
|
|
88
|
+
*/
|
|
89
|
+
readonly collections?: Readonly<Record<string, DataPermission>>;
|
|
90
|
+
/**
|
|
91
|
+
* Script grants by database name.
|
|
92
|
+
*/
|
|
93
|
+
readonly scripts?: Readonly<Record<string, ScriptPermission>>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Builds the `database|collection` key `Permissions.collections` takes.
|
|
97
|
+
*
|
|
98
|
+
* @param database the database name
|
|
99
|
+
* @param collection the collection name
|
|
100
|
+
* @returns the key
|
|
101
|
+
*/
|
|
102
|
+
export declare function collectionKey(database: string, collection: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* One user, as `Users.list` returns it.
|
|
105
|
+
*/
|
|
106
|
+
export interface UserInfo {
|
|
107
|
+
/**
|
|
108
|
+
* The username.
|
|
109
|
+
*/
|
|
110
|
+
readonly username: string;
|
|
111
|
+
/**
|
|
112
|
+
* Whether the user is an admin.
|
|
113
|
+
*/
|
|
114
|
+
readonly admin: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Server-wide grants.
|
|
117
|
+
*/
|
|
118
|
+
readonly globalPermissions: readonly string[];
|
|
119
|
+
/**
|
|
120
|
+
* Grants by database.
|
|
121
|
+
*/
|
|
122
|
+
readonly databasePermissions: Document;
|
|
123
|
+
/**
|
|
124
|
+
* Grants by `database|collection`.
|
|
125
|
+
*/
|
|
126
|
+
readonly collectionPermissions: Document;
|
|
127
|
+
/**
|
|
128
|
+
* Script grants by database.
|
|
129
|
+
*/
|
|
130
|
+
readonly scriptPermissions: Document;
|
|
131
|
+
/**
|
|
132
|
+
* The databases the user owns.
|
|
133
|
+
*/
|
|
134
|
+
readonly ownedDatabases: readonly string[];
|
|
135
|
+
/**
|
|
136
|
+
* The row as the server sent it.
|
|
137
|
+
*/
|
|
138
|
+
readonly raw: Document;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A distributed transaction waiting for a decision.
|
|
142
|
+
*/
|
|
143
|
+
export interface TransactionInfo {
|
|
144
|
+
/**
|
|
145
|
+
* Its id.
|
|
146
|
+
*/
|
|
147
|
+
readonly dtxId: string;
|
|
148
|
+
/**
|
|
149
|
+
* The coordinating node.
|
|
150
|
+
*/
|
|
151
|
+
readonly coordinator: string | undefined;
|
|
152
|
+
/**
|
|
153
|
+
* Whether the coordinator answers.
|
|
154
|
+
*/
|
|
155
|
+
readonly coordinatorReachable: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* The participating nodes.
|
|
158
|
+
*/
|
|
159
|
+
readonly participants: readonly string[];
|
|
160
|
+
/**
|
|
161
|
+
* Its age in milliseconds.
|
|
162
|
+
*/
|
|
163
|
+
readonly ageMs: number;
|
|
164
|
+
/**
|
|
165
|
+
* The row as the server sent it.
|
|
166
|
+
*/
|
|
167
|
+
readonly raw: Document;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* A running script.
|
|
171
|
+
*/
|
|
172
|
+
export interface ScriptRun {
|
|
173
|
+
/**
|
|
174
|
+
* Its id.
|
|
175
|
+
*/
|
|
176
|
+
readonly runId: string;
|
|
177
|
+
/**
|
|
178
|
+
* The node it runs on.
|
|
179
|
+
*/
|
|
180
|
+
readonly node: string | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* What started it.
|
|
183
|
+
*/
|
|
184
|
+
readonly kind: string;
|
|
185
|
+
/**
|
|
186
|
+
* Its database.
|
|
187
|
+
*/
|
|
188
|
+
readonly database: string | undefined;
|
|
189
|
+
/**
|
|
190
|
+
* The procedure or schedule name.
|
|
191
|
+
*/
|
|
192
|
+
readonly name: string | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* Who started it.
|
|
195
|
+
*/
|
|
196
|
+
readonly username: string | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* How long it has run, in milliseconds.
|
|
199
|
+
*/
|
|
200
|
+
readonly ageMs: number;
|
|
201
|
+
/**
|
|
202
|
+
* The row as the server sent it.
|
|
203
|
+
*/
|
|
204
|
+
readonly raw: Document;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* A trigger run that is pending or exhausted its attempts.
|
|
208
|
+
*/
|
|
209
|
+
export interface TriggerRun {
|
|
210
|
+
/**
|
|
211
|
+
* Its id.
|
|
212
|
+
*/
|
|
213
|
+
readonly runId: string;
|
|
214
|
+
/**
|
|
215
|
+
* `PENDING`, `DEAD` or `STAGED`.
|
|
216
|
+
*/
|
|
217
|
+
readonly status: string;
|
|
218
|
+
/**
|
|
219
|
+
* Its database.
|
|
220
|
+
*/
|
|
221
|
+
readonly database: string | undefined;
|
|
222
|
+
/**
|
|
223
|
+
* Its collection.
|
|
224
|
+
*/
|
|
225
|
+
readonly collection: string | undefined;
|
|
226
|
+
/**
|
|
227
|
+
* The trigger.
|
|
228
|
+
*/
|
|
229
|
+
readonly trigger: string | undefined;
|
|
230
|
+
/**
|
|
231
|
+
* The procedure it calls.
|
|
232
|
+
*/
|
|
233
|
+
readonly procedure: string | undefined;
|
|
234
|
+
/**
|
|
235
|
+
* The event that fired it.
|
|
236
|
+
*/
|
|
237
|
+
readonly event: string | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* How many times it ran.
|
|
240
|
+
*/
|
|
241
|
+
readonly attempts: number;
|
|
242
|
+
/**
|
|
243
|
+
* The last failure.
|
|
244
|
+
*/
|
|
245
|
+
readonly lastError: string | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* The row as the server sent it.
|
|
248
|
+
*/
|
|
249
|
+
readonly raw: Document;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Which build a server runs and whether it is ready.
|
|
253
|
+
*/
|
|
254
|
+
export interface ServerInfo {
|
|
255
|
+
/**
|
|
256
|
+
* The node's state, such as `READY`.
|
|
257
|
+
*/
|
|
258
|
+
readonly state: string | undefined;
|
|
259
|
+
/**
|
|
260
|
+
* The server version.
|
|
261
|
+
*/
|
|
262
|
+
readonly version: string | undefined;
|
|
263
|
+
/**
|
|
264
|
+
* The row as the server sent it.
|
|
265
|
+
*/
|
|
266
|
+
readonly raw: Document;
|
|
267
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const DataPermission = { READ: "READ", READ_WRITE: "READ_WRITE" };
|
|
2
|
+
export const GlobalPermission = { CREATE_DATABASE: "CREATE_DATABASE", DROP_DATABASE: "DROP_DATABASE" };
|
|
3
|
+
export const ScriptPermission = { NONE: "NONE", RUN: "RUN", MANAGE: "MANAGE" };
|
|
4
|
+
export const TransactionDecision = { COMMIT: "commit", ABORT: "abort" };
|
|
5
|
+
export const TriggerRunStatus = { PENDING: "PENDING", DEAD: "DEAD", STAGED: "STAGED" };
|
|
6
|
+
export const TriggerRunDecision = { REPLAY: "replay", DISCARD: "discard" };
|
|
7
|
+
export function collectionKey(database, collection) {
|
|
8
|
+
return `${database}|${collection}`;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/admin/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAW,CAAC;AAGlF,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,eAAe,EAAE,iBAAiB,EAAE,aAAa,EAAE,eAAe,EAAW,CAAC;AAGhH,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAW,CAAC;AAGxF,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAW,CAAC;AAGjF,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAW,CAAC;AAGhG,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAW,CAAC;AAWpF,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,UAAkB;IAC9D,OAAO,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACvC,CAAC"}
|