@antelopejs/rethinkdb 1.3.0 → 1.4.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/README.md +99 -84
- package/dist/connection.d.ts +0 -2
- package/dist/connection.js +0 -62
- package/dist/connection.js.map +1 -1
- package/dist/implementations/database/indexes.d.ts +39 -0
- package/dist/implementations/database/indexes.js +190 -0
- package/dist/implementations/database/indexes.js.map +1 -0
- package/dist/implementations/database/initialize.d.ts +4 -0
- package/dist/implementations/database/initialize.js +84 -0
- package/dist/implementations/database/initialize.js.map +1 -0
- package/dist/implementations/database/schema.d.ts +3 -3
- package/dist/implementations/database/schema.js +10 -5
- package/dist/implementations/database/schema.js.map +1 -1
- package/dist/implementations/database/selection.d.ts +3 -0
- package/dist/implementations/database/selection.js +57 -31
- package/dist/implementations/database/selection.js.map +1 -1
- package/dist/implementations/database/stream.js +64 -53
- package/dist/implementations/database/stream.js.map +1 -1
- package/dist/implementations/database/utils.d.ts +1 -0
- package/dist/implementations/database/utils.js +2 -1
- package/dist/implementations/database/utils.js.map +1 -1
- package/dist/test/atomic-mutation.test.js +20 -9
- package/dist/test/atomic-mutation.test.js.map +1 -1
- package/dist/test/instance-indexes.test.d.ts +1 -0
- package/dist/test/instance-indexes.test.js +354 -0
- package/dist/test/instance-indexes.test.js.map +1 -0
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -1,121 +1,136 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
1
|
# @antelopejs/rethinkdb
|
|
4
2
|
|
|
5
3
|
<div align="center">
|
|
6
|
-
<a href="https://www.npmjs.com/package/@antelopejs/rethinkdb"><img alt="
|
|
7
|
-
<a href="./LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@antelopejs/rethinkdb
|
|
4
|
+
<a href="https://www.npmjs.com/package/@antelopejs/rethinkdb"><img alt="npm" src="https://img.shields.io/npm/v/@antelopejs/rethinkdb?style=for-the-badge&labelColor=000000&color=000000"></a>
|
|
5
|
+
<a href="./LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@antelopejs/rethinkdb?style=for-the-badge&labelColor=000000&color=000000"></a>
|
|
8
6
|
<a href="https://discord.gg/sjK28QHrA7"><img src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000" alt="Discord"></a>
|
|
9
|
-
<a href="https://antelopejs.com/
|
|
7
|
+
<a href="https://interfaces.antelopejs.com/docs/database"><img src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000" alt="Documentation"></a>
|
|
10
8
|
</div>
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
The RethinkDB backend of AntelopeJS: it runs the database interface's queries on RethinkDB with [`rethinkdb-ts`](https://github.com/rethinkdb/rethinkdb-ts), and exposes that driver to modules that need it directly.
|
|
11
|
+
|
|
12
|
+
## Interfaces
|
|
13
|
+
|
|
14
|
+
| Interface | Documentation |
|
|
15
|
+
| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
16
|
+
| [`@antelopejs/interface-database`](https://github.com/AntelopeJS/interface-database) | [Database](https://interfaces.antelopejs.com/docs/database) |
|
|
17
|
+
| [`@antelopejs/interface-rethinkdb`](https://github.com/AntelopeJS/interface-rethinkdb) | [RethinkDB](https://interfaces.antelopejs.com/docs/rethinkdb/introduction) |
|
|
18
|
+
|
|
19
|
+
Schemas, tables, queries, change feeds and atomic mutations are documented on the database interface pages.
|
|
13
20
|
|
|
14
|
-
##
|
|
21
|
+
## Install
|
|
15
22
|
|
|
16
23
|
```bash
|
|
17
24
|
ajs project modules add @antelopejs/rethinkdb
|
|
18
25
|
```
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
The command writes the module's default configuration: a connection pool to `127.0.0.1:28015` as `admin`.
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
The module connects either through a connection pool (`pool`) or through a single connection (`connection`). When both are set, `pool` wins.
|
|
32
|
+
|
|
33
|
+
```typescript [antelope.config.ts]
|
|
34
|
+
import { defineConfig } from "@antelopejs/interface-core/config";
|
|
35
|
+
|
|
36
|
+
export default defineConfig({
|
|
37
|
+
name: "my-project",
|
|
38
|
+
modules: {
|
|
39
|
+
rethinkdb: {
|
|
40
|
+
source: {
|
|
41
|
+
type: "package",
|
|
42
|
+
package: "@antelopejs/rethinkdb",
|
|
43
|
+
version: "^1.4.0",
|
|
44
|
+
},
|
|
45
|
+
config: {
|
|
46
|
+
pool: {
|
|
47
|
+
host: "127.0.0.1",
|
|
48
|
+
port: 28015,
|
|
49
|
+
user: "admin",
|
|
50
|
+
password: "",
|
|
51
|
+
pool: true,
|
|
52
|
+
cursor: false,
|
|
53
|
+
silent: true,
|
|
54
|
+
discovery: true,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
```
|
|
23
61
|
|
|
24
|
-
|
|
25
|
-
- **Database Interface**: Offers a standardized database abstraction layer
|
|
62
|
+
For a single connection:
|
|
26
63
|
|
|
27
|
-
|
|
64
|
+
```typescript
|
|
65
|
+
config: {
|
|
66
|
+
connection: { host: "127.0.0.1", port: 28015, user: "admin", password: "" },
|
|
67
|
+
},
|
|
68
|
+
```
|
|
28
69
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
70
|
+
| Key | Description |
|
|
71
|
+
| ------------ | ------------------------------------------------------------------------------------------------------------- |
|
|
72
|
+
| `pool` | `rethinkdb-ts` pool options (`RPoolConnectionOptions`), passed to `r.connectPool()`. |
|
|
73
|
+
| `connection` | `rethinkdb-ts` connection options (`RConnectionOptions`), passed to `r.connect()`. Used when `pool` is unset. |
|
|
33
74
|
|
|
34
|
-
|
|
75
|
+
The module refuses to start when neither key is set. The option types come from [`rethinkdb-ts`](https://github.com/rethinkdb/rethinkdb-ts).
|
|
35
76
|
|
|
36
|
-
|
|
77
|
+
## Quick start
|
|
37
78
|
|
|
38
|
-
|
|
39
|
-
- Common database operations through the Database interface
|
|
79
|
+
In the module that stores data, add the database interface:
|
|
40
80
|
|
|
41
|
-
|
|
81
|
+
```bash
|
|
82
|
+
pnpm add @antelopejs/interface-database
|
|
83
|
+
```
|
|
42
84
|
|
|
43
|
-
|
|
85
|
+
Then follow the [database interface guide](https://framework.antelopejs.com/docs/guides/database) to declare a schema and query it. The same code runs on [`@antelopejs/mongodb`](https://github.com/AntelopeJS/mongodb).
|
|
44
86
|
|
|
45
|
-
|
|
87
|
+
To use the driver directly instead, add `@antelopejs/interface-rethinkdb` and read its [documentation](https://interfaces.antelopejs.com/docs/rethinkdb/introduction).
|
|
46
88
|
|
|
47
|
-
|
|
48
|
-
// Direct connection options (RConnectionOptions)
|
|
49
|
-
{
|
|
50
|
-
host: "localhost", // The host to connect to
|
|
51
|
-
port: 28015, // The port to connect on
|
|
52
|
-
db: "test", // The default database
|
|
53
|
-
user: "admin", // The user account to connect as
|
|
54
|
-
password: "", // The password for the user account
|
|
55
|
-
timeout: 20, // Timeout period in seconds for the connection to be opened
|
|
56
|
-
ssl: false // Use SSL for connection
|
|
57
|
-
}
|
|
58
|
-
```
|
|
89
|
+
## Storage layout
|
|
59
90
|
|
|
60
|
-
|
|
91
|
+
- Each schema is a RethinkDB database, and each schema table is a table in it. Every table has a `tenant_id` index that scopes it to one instance.
|
|
92
|
+
- Each declared index `<name>` becomes a `<name>__i` index led by the instance. An index declared with `crossInstance: true` also gets an unprefixed `<name>` index for `CROSS_INSTANCE` queries; without it, those queries scan the table and log a one-time warning. Index names ending in `__i` are reserved.
|
|
93
|
+
- Schema initialization creates missing databases, tables and indexes, retries up to five times, and waits for the indexes before the schema accepts queries.
|
|
61
94
|
|
|
62
|
-
|
|
63
|
-
// Connection pool options (RPoolConnectionOptions)
|
|
64
|
-
{
|
|
65
|
-
host: "localhost", // The host to connect to
|
|
66
|
-
port: 28015, // The port to connect on
|
|
67
|
-
db: "test", // The default database
|
|
68
|
-
user: "admin", // The user account to connect as
|
|
69
|
-
password: "", // The password for the user account
|
|
70
|
-
timeout: 20, // Timeout period in seconds
|
|
71
|
-
maxConnections: 10, // Maximum number of connections in the pool
|
|
72
|
-
bufferSize: 50, // Buffer size for the pool
|
|
73
|
-
maxBufferSize: 100, // Maximum buffer size
|
|
74
|
-
discovery: false, // Enable server discovery
|
|
75
|
-
servers: [] // Additional servers for connection
|
|
76
|
-
}
|
|
77
|
-
```
|
|
95
|
+
Version 1.4 added the `<name>__i` indexes. The first boot after an upgrade builds them, which takes longer on large tables. The module never drops an index: drop the old ones you no longer need by hand, for example `r.db("<schema>").table("<table>").indexDrop("<name>")`.
|
|
78
96
|
|
|
79
|
-
|
|
97
|
+
## Documentation
|
|
80
98
|
|
|
81
|
-
|
|
99
|
+
- [Database](https://interfaces.antelopejs.com/docs/database): the `@antelopejs/interface-database` contract this module implements
|
|
100
|
+
- [RethinkDB](https://interfaces.antelopejs.com/docs/rethinkdb/introduction): the `@antelopejs/interface-rethinkdb` contract this module implements
|
|
101
|
+
- [Configuration](https://framework.antelopejs.com/docs/concepts/configuration): module sources, `config` blocks and config variables in `antelope.config.ts`
|
|
82
102
|
|
|
83
|
-
|
|
84
|
-
- Connection pool using `r.connectPool()` with `RPoolConnectionOptions`
|
|
103
|
+
## Compatibility
|
|
85
104
|
|
|
86
|
-
|
|
105
|
+
| Package | Supported range |
|
|
106
|
+
| --------------------------------- | ---------------- |
|
|
107
|
+
| `@antelopejs/interface-database` | `^0.1.8` |
|
|
108
|
+
| `@antelopejs/interface-rethinkdb` | `>=0.0.5 <1.0.0` |
|
|
109
|
+
| `@antelopejs/interface-core` | `>=0.1.1 <1.0.0` |
|
|
87
110
|
|
|
88
|
-
`
|
|
89
|
-
and the requested condition inside a deterministic native RethinkDB `replace`
|
|
90
|
-
function. It never inserts a missing record or retries a submitted mutation.
|
|
91
|
-
`CROSS_INSTANCE` and selections are not supported.
|
|
111
|
+
The module is developed and tested against `@antelopejs/core` `^1.13.4` on Node.js 24, with `rethinkdb-ts` `^2.7.0` and RethinkDB 2.4.
|
|
92
112
|
|
|
93
|
-
|
|
94
|
-
nested objects, and install `nextRevision` in the same write. Revision-based
|
|
95
|
-
deletes remove the matching record. The `{ kind: "missing" }` expected revision
|
|
96
|
-
matches an absent field on an existing record, not a stored `null` value. Callers
|
|
97
|
-
must use fresh revision tokens and must not reuse an identity across incarnations.
|
|
113
|
+
## Contributing
|
|
98
114
|
|
|
99
|
-
|
|
100
|
-
record. It does not provide revision-based protection against a value changing
|
|
101
|
-
and later changing back. Retention callers must keep their cutoff fixed and
|
|
102
|
-
re-evaluate eligibility when they observe a different value.
|
|
115
|
+
The tests need a RethinkDB server on `127.0.0.1:28015`. Start the one CI uses:
|
|
103
116
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
```bash
|
|
118
|
+
docker compose -f .github/release-services.yml up -d --wait
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Then run the checks:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pnpm install
|
|
125
|
+
pnpm lint
|
|
126
|
+
pnpm format:check
|
|
127
|
+
pnpm typecheck
|
|
128
|
+
pnpm knip
|
|
129
|
+
pnpm test # build, then ajs module test
|
|
130
|
+
```
|
|
112
131
|
|
|
113
|
-
|
|
114
|
-
or later within the supported range. Its shared real-backend conformance suite
|
|
115
|
-
runs automatically through `ajs module test`, alongside this provider's native
|
|
116
|
-
acknowledgement, storage, and fault tests. Install the published dependencies
|
|
117
|
-
with `pnpm install --frozen-lockfile`; no local artifact is required.
|
|
132
|
+
The tests also run the shared conformance suite of `@antelopejs/interface-database`. Read the [contribution guidelines](CONTRIBUTING.md) before opening a pull request.
|
|
118
133
|
|
|
119
134
|
## License
|
|
120
135
|
|
|
121
|
-
|
|
136
|
+
[Apache-2.0](LICENSE)
|
package/dist/connection.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { Cursor } from "rethinkdb-ts/lib/response/cursor";
|
|
2
2
|
import type { TermJson } from "rethinkdb-ts/lib/internal-types";
|
|
3
|
-
import type { SchemaDefinition } from "@antelopejs/interface-database/schema";
|
|
4
3
|
import { type RConnectionOptions, type RPoolConnectionOptions, type RunOptions } from "rethinkdb-ts";
|
|
5
4
|
export declare function ConnectDirect(options: RConnectionOptions): Promise<void>;
|
|
6
5
|
export declare function ConnectPool(options: RPoolConnectionOptions): Promise<void>;
|
|
7
6
|
export declare function Disconnect(): void;
|
|
8
7
|
export declare function SendQuery(query: TermJson, opts?: RunOptions): Promise<Cursor | undefined>;
|
|
9
8
|
export declare function executeTermJson(term: TermJson): Promise<any>;
|
|
10
|
-
export declare function InitializeSchemaDatabase(dbName: string, schema: SchemaDefinition): Promise<void>;
|
package/dist/connection.js
CHANGED
|
@@ -8,14 +8,11 @@ exports.ConnectPool = ConnectPool;
|
|
|
8
8
|
exports.Disconnect = Disconnect;
|
|
9
9
|
exports.SendQuery = SendQuery;
|
|
10
10
|
exports.executeTermJson = executeTermJson;
|
|
11
|
-
exports.InitializeSchemaDatabase = InitializeSchemaDatabase;
|
|
12
11
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
13
|
-
const enums_1 = require("rethinkdb-ts/lib/proto/enums");
|
|
14
12
|
const term_backtrace_1 = require("rethinkdb-ts/lib/error/term-backtrace");
|
|
15
13
|
const rethinkdb_ts_1 = require("rethinkdb-ts");
|
|
16
14
|
const logger_1 = require("./utils/logger");
|
|
17
15
|
const write_result_1 = require("./write-result");
|
|
18
|
-
const utils_1 = require("./implementations/database/utils");
|
|
19
16
|
let connection;
|
|
20
17
|
async function ConnectDirect(options) {
|
|
21
18
|
logger_1.Logger.Debug("Connecting directly to RethinkDB", options.host ?? "localhost");
|
|
@@ -78,63 +75,4 @@ async function executeTermJson(term) {
|
|
|
78
75
|
}
|
|
79
76
|
return results;
|
|
80
77
|
}
|
|
81
|
-
async function InitializeSchemaDatabase(dbName, schema) {
|
|
82
|
-
const dbList = (await executeTermJson([enums_1.TermType.DB_LIST, []])) ?? [];
|
|
83
|
-
if (!dbList.includes(dbName)) {
|
|
84
|
-
await executeTermJson([enums_1.TermType.DB_CREATE, [dbName]]);
|
|
85
|
-
}
|
|
86
|
-
const db = [enums_1.TermType.DB, [dbName]];
|
|
87
|
-
const tableList = (await executeTermJson([enums_1.TermType.TABLE_LIST, [db]])) ?? [];
|
|
88
|
-
const userTables = Object.keys(schema);
|
|
89
|
-
const tablesToCreate = [...userTables, utils_1.INSTANCE_REGISTRY_TABLE].filter((t) => !tableList.includes(t));
|
|
90
|
-
await Promise.all(tablesToCreate.map((t) => executeTermJson([enums_1.TermType.TABLE_CREATE, [db, t], { primary_key: "_id" }])));
|
|
91
|
-
await Promise.all(Object.entries(schema).map(([tableName, tableDef]) => initializeIndexes(db, tableName, tableDef.indexes)));
|
|
92
|
-
}
|
|
93
|
-
async function initializeIndexes(db, tableName, indexes) {
|
|
94
|
-
const table = [enums_1.TermType.TABLE, [db, tableName]];
|
|
95
|
-
const existingIndexList = (await executeTermJson([enums_1.TermType.INDEX_LIST, [table]])) ?? [];
|
|
96
|
-
let created = false;
|
|
97
|
-
for (const [indexName, indexDef] of Object.entries(indexes)) {
|
|
98
|
-
if (existingIndexList.includes(indexName)) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
if (indexDef.fields && indexDef.fields.length > 0) {
|
|
102
|
-
const argId = 0;
|
|
103
|
-
const fields = indexDef.fields.map((f) => [
|
|
104
|
-
enums_1.TermType.BRACKET,
|
|
105
|
-
[[enums_1.TermType.VAR, [argId]], f],
|
|
106
|
-
]);
|
|
107
|
-
await executeTermJson([
|
|
108
|
-
enums_1.TermType.INDEX_CREATE,
|
|
109
|
-
[
|
|
110
|
-
table,
|
|
111
|
-
indexName,
|
|
112
|
-
[
|
|
113
|
-
enums_1.TermType.FUNC,
|
|
114
|
-
[
|
|
115
|
-
[enums_1.TermType.MAKE_ARRAY, [argId]],
|
|
116
|
-
[enums_1.TermType.MAKE_ARRAY, fields],
|
|
117
|
-
],
|
|
118
|
-
],
|
|
119
|
-
],
|
|
120
|
-
indexDef.multi ? { multi: true } : {},
|
|
121
|
-
]);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
await executeTermJson([
|
|
125
|
-
enums_1.TermType.INDEX_CREATE,
|
|
126
|
-
[table, indexName],
|
|
127
|
-
indexDef.multi ? { multi: true } : {},
|
|
128
|
-
]);
|
|
129
|
-
}
|
|
130
|
-
created = true;
|
|
131
|
-
}
|
|
132
|
-
if (!existingIndexList.includes(utils_1.TENANT_ID_FIELD)) {
|
|
133
|
-
await executeTermJson([enums_1.TermType.INDEX_CREATE, [table, utils_1.TENANT_ID_FIELD]]);
|
|
134
|
-
created = true;
|
|
135
|
-
}
|
|
136
|
-
if (created) {
|
|
137
|
-
await executeTermJson([enums_1.TermType.INDEX_WAIT, [table]]);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
78
|
//# sourceMappingURL=connection.js.map
|
package/dist/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;AA6BA,sCAQC;AAED,kCAQC;AAED,gCAYC;AAED,8BAYC;AAED,0CAmBC;AAhGD,8DAAiC;AAGjC,0EAAsE;AAGtE,+CAOsB;AAEtB,2CAAwC;AACxC,iDAAqD;AAErD,IAAI,UASS,CAAC;AAEP,KAAK,UAAU,aAAa,CAAC,OAA2B;IAC7D,eAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,OAAO,CAAC,IAAI,IAAI,WAAW,CAAC,CAAC;IAC9E,UAAU,EAAE,CAAC;IACb,UAAU,GAAG;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,MAAM,gBAAC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AAc;IAClD,eAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,IAAA,8BAAa,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACvC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IACpC,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;QAC1B,IAAA,kCAAmB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TermJson } from "rethinkdb-ts/lib/internal-types";
|
|
2
|
+
import type { IndexDefinition, SchemaDefinition } from "@antelopejs/interface-database/schema";
|
|
3
|
+
type TermBuilder = (value: TermJson) => TermJson;
|
|
4
|
+
export interface IndexCreation {
|
|
5
|
+
name: string;
|
|
6
|
+
term: TermJson;
|
|
7
|
+
}
|
|
8
|
+
interface IndexedLookup {
|
|
9
|
+
index?: string;
|
|
10
|
+
key: TermBuilder;
|
|
11
|
+
}
|
|
12
|
+
export interface IndexedRead {
|
|
13
|
+
lookup: (source: TermJson, target: IndexedLookup) => TermJson;
|
|
14
|
+
matches: TermBuilder;
|
|
15
|
+
}
|
|
16
|
+
export interface DeclaredIndex {
|
|
17
|
+
schemaId: string;
|
|
18
|
+
tableName: string;
|
|
19
|
+
indexName: string;
|
|
20
|
+
definition: IndexDefinition;
|
|
21
|
+
}
|
|
22
|
+
export interface IndexedReadTarget extends DeclaredIndex {
|
|
23
|
+
table: TermJson;
|
|
24
|
+
source: TermJson;
|
|
25
|
+
tenantId?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function indexOptions(index?: string): {
|
|
28
|
+
index: string;
|
|
29
|
+
} | {
|
|
30
|
+
index?: undefined;
|
|
31
|
+
};
|
|
32
|
+
export declare function assertValidIndexNames(schema: SchemaDefinition): void;
|
|
33
|
+
export declare function buildIndexCreations(table: TermJson, indexes: Record<string, IndexDefinition>): IndexCreation[];
|
|
34
|
+
export declare function buildInstanceScope(table: TermJson, tenantId: string): TermJson;
|
|
35
|
+
export declare function warnUnindexedCrossInstance(index: DeclaredIndex): void;
|
|
36
|
+
export declare function buildIndexScanPredicate(index: DeclaredIndex, matches: TermBuilder): TermJson;
|
|
37
|
+
export declare function buildIndexScanValues(source: TermJson, index: DeclaredIndex): TermJson;
|
|
38
|
+
export declare function buildIndexedRead(target: IndexedReadTarget, read: IndexedRead): TermJson;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.indexOptions = indexOptions;
|
|
4
|
+
exports.assertValidIndexNames = assertValidIndexNames;
|
|
5
|
+
exports.buildIndexCreations = buildIndexCreations;
|
|
6
|
+
exports.buildInstanceScope = buildInstanceScope;
|
|
7
|
+
exports.warnUnindexedCrossInstance = warnUnindexedCrossInstance;
|
|
8
|
+
exports.buildIndexScanPredicate = buildIndexScanPredicate;
|
|
9
|
+
exports.buildIndexScanValues = buildIndexScanValues;
|
|
10
|
+
exports.buildIndexedRead = buildIndexedRead;
|
|
11
|
+
const enums_1 = require("rethinkdb-ts/lib/proto/enums");
|
|
12
|
+
const logger_1 = require("../../utils/logger");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
const INSTANCE_INDEX_SUFFIX = "__i";
|
|
15
|
+
const ARRAY_TYPE_NAME = "ARRAY";
|
|
16
|
+
const warnedIndexes = new Map();
|
|
17
|
+
function instanceIndexName(indexName) {
|
|
18
|
+
return `${indexName}${INSTANCE_INDEX_SUFFIX}`;
|
|
19
|
+
}
|
|
20
|
+
function buildFunction(body) {
|
|
21
|
+
const argId = (0, utils_1.allocateArgNumber)();
|
|
22
|
+
return [
|
|
23
|
+
enums_1.TermType.FUNC,
|
|
24
|
+
[[enums_1.TermType.MAKE_ARRAY, [argId]], body([enums_1.TermType.VAR, [argId]])],
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
function readField(row, field) {
|
|
28
|
+
return [enums_1.TermType.BRACKET, [row, field]];
|
|
29
|
+
}
|
|
30
|
+
function isCompound(definition) {
|
|
31
|
+
return (definition.fields?.length ?? 0) > 0;
|
|
32
|
+
}
|
|
33
|
+
function creationOptions(definition) {
|
|
34
|
+
return definition.multi ? { multi: true } : {};
|
|
35
|
+
}
|
|
36
|
+
function indexOptions(index) {
|
|
37
|
+
return index ? { index } : {};
|
|
38
|
+
}
|
|
39
|
+
function indexedFields(indexName, definition) {
|
|
40
|
+
const fields = definition.fields ?? [];
|
|
41
|
+
return fields.length > 0 ? fields : [indexName];
|
|
42
|
+
}
|
|
43
|
+
function buildIndexValue(row, indexName, definition) {
|
|
44
|
+
const fields = definition.fields ?? [];
|
|
45
|
+
if (fields.length === 0) {
|
|
46
|
+
return readField(row, indexName);
|
|
47
|
+
}
|
|
48
|
+
return [enums_1.TermType.MAKE_ARRAY, fields.map((field) => readField(row, field))];
|
|
49
|
+
}
|
|
50
|
+
function buildIndexEntries(value) {
|
|
51
|
+
const isArray = [
|
|
52
|
+
enums_1.TermType.EQ,
|
|
53
|
+
[[enums_1.TermType.TYPE_OF, [value]], ARRAY_TYPE_NAME],
|
|
54
|
+
];
|
|
55
|
+
return [enums_1.TermType.BRANCH, [isArray, value, [enums_1.TermType.MAKE_ARRAY, [value]]]];
|
|
56
|
+
}
|
|
57
|
+
function buildInstanceKey(tenantId, definition, value) {
|
|
58
|
+
if (isCompound(definition) && !definition.multi) {
|
|
59
|
+
return [enums_1.TermType.PREPEND, [value, tenantId]];
|
|
60
|
+
}
|
|
61
|
+
return [enums_1.TermType.MAKE_ARRAY, [tenantId, value]];
|
|
62
|
+
}
|
|
63
|
+
function buildInstanceIndexFunction(indexName, definition) {
|
|
64
|
+
return buildFunction((row) => {
|
|
65
|
+
const tenantId = readField(row, utils_1.TENANT_ID_FIELD);
|
|
66
|
+
const value = buildIndexValue(row, indexName, definition);
|
|
67
|
+
if (!definition.multi) {
|
|
68
|
+
return buildInstanceKey(tenantId, definition, value);
|
|
69
|
+
}
|
|
70
|
+
const toKey = buildFunction((entry) => buildInstanceKey(tenantId, definition, entry));
|
|
71
|
+
return [enums_1.TermType.MAP, [buildIndexEntries(value), toKey]];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function buildInstanceIndexCreation(table, indexName, definition) {
|
|
75
|
+
const name = instanceIndexName(indexName);
|
|
76
|
+
const indexFunction = buildInstanceIndexFunction(indexName, definition);
|
|
77
|
+
return {
|
|
78
|
+
name,
|
|
79
|
+
term: [
|
|
80
|
+
enums_1.TermType.INDEX_CREATE,
|
|
81
|
+
[table, name, indexFunction],
|
|
82
|
+
creationOptions(definition),
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function buildGlobalIndexCreation(table, indexName, definition) {
|
|
87
|
+
const args = isCompound(definition)
|
|
88
|
+
? [
|
|
89
|
+
table,
|
|
90
|
+
indexName,
|
|
91
|
+
buildFunction((row) => buildIndexValue(row, indexName, definition)),
|
|
92
|
+
]
|
|
93
|
+
: [table, indexName];
|
|
94
|
+
return {
|
|
95
|
+
name: indexName,
|
|
96
|
+
term: [enums_1.TermType.INDEX_CREATE, args, creationOptions(definition)],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function assertValidIndexNames(schema) {
|
|
100
|
+
for (const [tableName, table] of Object.entries(schema)) {
|
|
101
|
+
const reserved = Object.keys(table.indexes).find((indexName) => indexName.endsWith(INSTANCE_INDEX_SUFFIX));
|
|
102
|
+
if (reserved !== undefined) {
|
|
103
|
+
throw new Error(`Index '${reserved}' of table '${tableName}' ends with the reserved suffix '${INSTANCE_INDEX_SUFFIX}'; rename it`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function buildIndexCreations(table, indexes) {
|
|
108
|
+
const declared = Object.entries(indexes).flatMap(([indexName, definition]) => {
|
|
109
|
+
const instance = buildInstanceIndexCreation(table, indexName, definition);
|
|
110
|
+
if (!definition.crossInstance) {
|
|
111
|
+
return [instance];
|
|
112
|
+
}
|
|
113
|
+
return [instance, buildGlobalIndexCreation(table, indexName, definition)];
|
|
114
|
+
});
|
|
115
|
+
const tenantIndex = {
|
|
116
|
+
name: utils_1.TENANT_ID_FIELD,
|
|
117
|
+
term: [enums_1.TermType.INDEX_CREATE, [table, utils_1.TENANT_ID_FIELD]],
|
|
118
|
+
};
|
|
119
|
+
return [...declared, tenantIndex];
|
|
120
|
+
}
|
|
121
|
+
function buildInstanceScope(table, tenantId) {
|
|
122
|
+
return [enums_1.TermType.GET_ALL, [table, tenantId], { index: utils_1.TENANT_ID_FIELD }];
|
|
123
|
+
}
|
|
124
|
+
function warnedIndexNames(schemaId, tableName) {
|
|
125
|
+
const tables = warnedIndexes.get(schemaId) ?? new Map();
|
|
126
|
+
warnedIndexes.set(schemaId, tables);
|
|
127
|
+
const indexNames = tables.get(tableName) ?? new Set();
|
|
128
|
+
tables.set(tableName, indexNames);
|
|
129
|
+
return indexNames;
|
|
130
|
+
}
|
|
131
|
+
function warnUnindexedCrossInstance(index) {
|
|
132
|
+
const indexNames = warnedIndexNames(index.schemaId, index.tableName);
|
|
133
|
+
if (indexNames.has(index.indexName)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
indexNames.add(index.indexName);
|
|
137
|
+
logger_1.Logger.Warn(`CROSS_INSTANCE query on index '${index.indexName}' of table '${index.schemaId}.${index.tableName}' runs without an index; declare the index with crossInstance: true to make it fast`);
|
|
138
|
+
}
|
|
139
|
+
function buildIndexMatch(row, index, matches) {
|
|
140
|
+
const value = buildIndexValue(row, index.indexName, index.definition);
|
|
141
|
+
if (!index.definition.multi) {
|
|
142
|
+
return matches(value);
|
|
143
|
+
}
|
|
144
|
+
return [
|
|
145
|
+
enums_1.TermType.CONTAINS,
|
|
146
|
+
[buildIndexEntries(value), buildFunction(matches)],
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
function buildIndexScanPredicate(index, matches) {
|
|
150
|
+
warnUnindexedCrossInstance(index);
|
|
151
|
+
return buildFunction((row) => buildIndexMatch(row, index, matches));
|
|
152
|
+
}
|
|
153
|
+
function buildIndexScanValues(source, index) {
|
|
154
|
+
warnUnindexedCrossInstance(index);
|
|
155
|
+
const { indexName, definition } = index;
|
|
156
|
+
const indexed = [
|
|
157
|
+
enums_1.TermType.HAS_FIELDS,
|
|
158
|
+
[source, ...indexedFields(indexName, definition)],
|
|
159
|
+
];
|
|
160
|
+
const readValue = (row) => buildIndexValue(row, indexName, definition);
|
|
161
|
+
if (!definition.multi) {
|
|
162
|
+
return [enums_1.TermType.MAP, [indexed, buildFunction(readValue)]];
|
|
163
|
+
}
|
|
164
|
+
const entries = [
|
|
165
|
+
enums_1.TermType.CONCAT_MAP,
|
|
166
|
+
[indexed, buildFunction((row) => buildIndexEntries(readValue(row)))],
|
|
167
|
+
];
|
|
168
|
+
const isPresent = buildFunction((entry) => [enums_1.TermType.NE, [entry, null]]);
|
|
169
|
+
return [enums_1.TermType.FILTER, [entries, isPresent]];
|
|
170
|
+
}
|
|
171
|
+
function buildIndexedRead(target, read) {
|
|
172
|
+
const { tenantId, definition } = target;
|
|
173
|
+
if (tenantId !== undefined) {
|
|
174
|
+
return read.lookup(target.table, {
|
|
175
|
+
index: instanceIndexName(target.indexName),
|
|
176
|
+
key: (value) => buildInstanceKey(tenantId, definition, value),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (definition.crossInstance) {
|
|
180
|
+
return read.lookup(target.source, {
|
|
181
|
+
index: target.indexName,
|
|
182
|
+
key: (value) => value,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return [
|
|
186
|
+
enums_1.TermType.FILTER,
|
|
187
|
+
[target.source, buildIndexScanPredicate(target, read.matches)],
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=indexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.js","sourceRoot":"","sources":["../../../src/implementations/database/indexes.ts"],"names":[],"mappings":";;AAqEA,oCAEC;AAiGD,sDAWC;AAOD,kDAkBC;AAED,gDAKC;AAUD,gEASC;AAqBD,0DAMC;AAMD,oDAqBC;AAMD,4CAqBC;AAvTD,wDAAwD;AAOxD,+CAA4C;AAC5C,mCAA6D;AAE7D,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,eAAe,GAAG,OAAO,CAAC;AAgChC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAoC,CAAC;AAElE,SAAS,iBAAiB,CAAC,SAAiB;IAC1C,OAAO,GAAG,SAAS,GAAG,qBAAqB,EAAE,CAAC;AAChD,CAAC;AAED,SAAS,aAAa,CAAC,IAAiB;IACtC,MAAM,KAAK,GAAG,IAAA,yBAAiB,GAAE,CAAC;IAClC,OAAO;QACL,gBAAQ,CAAC,IAAI;QACb,CAAC,CAAC,gBAAQ,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,gBAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAChE,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,GAAa,EAAE,KAAa;IAC7C,OAAO,CAAC,gBAA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,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC;IACD,IAAI,UAAU,CAAC,aAAa,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;YAChC,KAAK,EAAE,MAAM,CAAC,SAAS;YACvB,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;SACtB,CAAC,CAAC;IACL,CAAC;IACD,OAAO;QACL,gBAAQ,CAAC,MAAM;QACf,CAAC,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;KAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SchemaDefinition } from "@antelopejs/interface-database/schema";
|
|
2
|
+
export declare function ensureDatabase(dbName: string): Promise<void>;
|
|
3
|
+
export declare function InitializeSchemaDatabase(dbName: string, schema: SchemaDefinition): Promise<void>;
|
|
4
|
+
export declare function retryWithBackoff<T>(operation: () => Promise<T>, attempts?: number): Promise<T>;
|