@antelopejs/rethinkdb 1.2.4 → 1.4.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 +86 -2
- package/dist/connection.d.ts +2 -6
- package/dist/connection.js +3 -71
- package/dist/connection.js.map +1 -1
- package/dist/implementations/database/atomic.d.ts +3 -0
- package/dist/implementations/database/atomic.js +104 -0
- package/dist/implementations/database/atomic.js.map +1 -0
- package/dist/implementations/database/expression.d.ts +3 -1
- package/dist/implementations/database/expression.js +80 -5
- package/dist/implementations/database/expression.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/query.d.ts +1 -5
- package/dist/implementations/database/query.js +17 -76
- package/dist/implementations/database/query.js.map +1 -1
- 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 +6 -1
- package/dist/implementations/database/selection.js +85 -49
- package/dist/implementations/database/selection.js.map +1 -1
- package/dist/implementations/database/stream.d.ts +0 -3
- package/dist/implementations/database/stream.js +76 -67
- 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/implementations/rethinkdb/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/test/atomic-mutation.test.js +288 -0
- package/dist/test/atomic-mutation.test.js.map +1 -0
- 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/dist/test/write-results.test.d.ts +1 -0
- package/dist/test/write-results.test.js +64 -0
- package/dist/test/write-results.test.js.map +1 -0
- package/dist/write-result.d.ts +2 -0
- package/dist/write-result.js +19 -0
- package/dist/write-result.js.map +1 -0
- package/package.json +39 -31
- package/dist/implementations/database/index.js +0 -3
- package/dist/implementations/database/index.js.map +0 -1
- /package/dist/{implementations/database/index.d.ts → test/atomic-mutation.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
1
|
# @antelopejs/rethinkdb
|
|
4
2
|
|
|
5
3
|
<div align="center">
|
|
@@ -83,6 +81,92 @@ The module supports two connection methods:
|
|
|
83
81
|
- Direct connection using `r.connect()` with `RConnectionOptions`
|
|
84
82
|
- Connection pool using `r.connectPool()` with `RPoolConnectionOptions`
|
|
85
83
|
|
|
84
|
+
## Indexes
|
|
85
|
+
|
|
86
|
+
Every table has a `tenant_id` index. For each index declared in a schema, the
|
|
87
|
+
module maintains:
|
|
88
|
+
|
|
89
|
+
- `<name>__i`, led by the instance field: `[tenant_id, ...fields]` for compound
|
|
90
|
+
indexes, `[tenant_id, value]` for single-field indexes, and one
|
|
91
|
+
`[tenant_id, element]` entry per element for `multi` indexes. Scoped `getAll`
|
|
92
|
+
and `between` use it.
|
|
93
|
+
- `<name>`, the unprefixed index, only when the index is declared with
|
|
94
|
+
`crossInstance: true`. `CROSS_INSTANCE` reads on the index use it.
|
|
95
|
+
|
|
96
|
+
`CROSS_INSTANCE` `getAll`, `between`, `orderBy`, `count(field)`,
|
|
97
|
+
`distinct(field)` and `lookup` on an index that is not declared with
|
|
98
|
+
`crossInstance: true` still work, but scan the table instead of using an index.
|
|
99
|
+
The module logs a warning the first time a process runs such a query for each
|
|
100
|
+
schema, table and index. Plain filters never log a warning.
|
|
101
|
+
|
|
102
|
+
The scans return the same results as the index would, with two exceptions:
|
|
103
|
+
|
|
104
|
+
- `getAll`, `between` and `lookup` return each matching document once, while
|
|
105
|
+
the index returns a document once per matching key or `multi` entry.
|
|
106
|
+
- `orderBy` also returns documents that lack the sorted field, like scoped
|
|
107
|
+
`orderBy`, while the index leaves them out.
|
|
108
|
+
|
|
109
|
+
Index names ending with `__i` are reserved for the instance-prefixed indexes:
|
|
110
|
+
schema initialization rejects them.
|
|
111
|
+
|
|
112
|
+
Scoped `orderBy` does not use an index: an index would leave out documents
|
|
113
|
+
that lack the sorted field, and scoped `orderBy` keeps returning them.
|
|
114
|
+
|
|
115
|
+
Schema initialization creates databases, tables and indexes only when they are
|
|
116
|
+
missing, and ignores "already exists" errors when another process booting at
|
|
117
|
+
the same time creates them first. It retries a failed initialization up to five
|
|
118
|
+
times with exponential backoff, and waits until the indexes it manages are
|
|
119
|
+
ready before the schema accepts queries. RethinkDB builds indexes in the
|
|
120
|
+
background without blocking writes.
|
|
121
|
+
|
|
122
|
+
### Upgrading from 1.3
|
|
123
|
+
|
|
124
|
+
The first boot on an existing database adds the `<name>__i` indexes next to the
|
|
125
|
+
existing ones, then waits for RethinkDB to build them before the schema accepts
|
|
126
|
+
queries. Large tables therefore take longer to boot once.
|
|
127
|
+
|
|
128
|
+
The module never drops or rebuilds an index. Existing unprefixed `<name>`
|
|
129
|
+
indexes stay in place: they keep serving cross-instance queries for indexes
|
|
130
|
+
declared with `crossInstance: true`, and are unused otherwise. Drop unused ones
|
|
131
|
+
by hand to save storage and write time:
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
r.db("<schema>").table("<table>").indexDrop("<name>");
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Atomic single-record mutations
|
|
138
|
+
|
|
139
|
+
`table.atomicMutation(key, request).run()` checks one primary key, its instance,
|
|
140
|
+
and the requested condition inside a deterministic native RethinkDB `replace`
|
|
141
|
+
function. It never inserts a missing record or retries a submitted mutation.
|
|
142
|
+
`CROSS_INSTANCE` and selections are not supported.
|
|
143
|
+
|
|
144
|
+
Revision-based updates replace the supplied top-level fields, including complete
|
|
145
|
+
nested objects, and install `nextRevision` in the same write. Revision-based
|
|
146
|
+
deletes remove the matching record. The `{ kind: "missing" }` expected revision
|
|
147
|
+
matches an absent field on an existing record, not a stored `null` value. Callers
|
|
148
|
+
must use fresh revision tokens and must not reuse an identity across incarnations.
|
|
149
|
+
|
|
150
|
+
`deleteIfEqual` checks one scalar field, including a `Date`, before deleting the
|
|
151
|
+
record. It does not provide revision-based protection against a value changing
|
|
152
|
+
and later changing back. Retention callers must keep their cutoff fixed and
|
|
153
|
+
re-evaluate eligibility when they observe a different value.
|
|
154
|
+
|
|
155
|
+
The result is `applied`, `not-applied`, or `unknown`. Missing records, wrong
|
|
156
|
+
instances, and condition mismatches return `not-applied`. Lost acknowledgements,
|
|
157
|
+
indeterminate driver errors, untyped write-result errors, and malformed
|
|
158
|
+
acknowledgements return `unknown`; callers must reconcile them rather than infer
|
|
159
|
+
that no write occurred. Invalid requests and definite typed query-validation
|
|
160
|
+
errors throw. Ordinary insert/update/replace/delete operations reject write
|
|
161
|
+
errors, including duplicate primary keys; a multi-record write may have partially
|
|
162
|
+
succeeded before it reports an error.
|
|
163
|
+
|
|
164
|
+
This implementation requires `@antelopejs/interface-database` version `0.1.6`
|
|
165
|
+
or later within the supported range. Its shared real-backend conformance suite
|
|
166
|
+
runs automatically through `ajs module test`, alongside this provider's native
|
|
167
|
+
acknowledgement, storage, and fault tests. Install the published dependencies
|
|
168
|
+
with `pnpm install --frozen-lockfile`; no local artifact is required.
|
|
169
|
+
|
|
86
170
|
## License
|
|
87
171
|
|
|
88
172
|
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
package/dist/connection.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type { SchemaDefinition } from "@antelopejs/interface-database/schema";
|
|
2
|
-
import { type Connection, type MasterPool, type RConnectionOptions, type RPoolConnectionOptions, type RunOptions } from "rethinkdb-ts";
|
|
3
|
-
import type { TermJson } from "rethinkdb-ts/lib/internal-types";
|
|
4
1
|
import type { Cursor } from "rethinkdb-ts/lib/response/cursor";
|
|
2
|
+
import type { TermJson } from "rethinkdb-ts/lib/internal-types";
|
|
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
|
-
export declare function GetConnection(): Connection | MasterPool | undefined;
|
|
9
|
-
export declare function GetConnectionType(): "direct" | "none" | "pool";
|
|
10
7
|
export declare function SendQuery(query: TermJson, opts?: RunOptions): Promise<Cursor | undefined>;
|
|
11
8
|
export declare function executeTermJson(term: TermJson): Promise<any>;
|
|
12
|
-
export declare function InitializeSchemaDatabase(dbName: string, schema: SchemaDefinition): Promise<void>;
|
package/dist/connection.js
CHANGED
|
@@ -6,17 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ConnectDirect = ConnectDirect;
|
|
7
7
|
exports.ConnectPool = ConnectPool;
|
|
8
8
|
exports.Disconnect = Disconnect;
|
|
9
|
-
exports.GetConnection = GetConnection;
|
|
10
|
-
exports.GetConnectionType = GetConnectionType;
|
|
11
9
|
exports.SendQuery = SendQuery;
|
|
12
10
|
exports.executeTermJson = executeTermJson;
|
|
13
|
-
exports.InitializeSchemaDatabase = InitializeSchemaDatabase;
|
|
14
11
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
15
|
-
const rethinkdb_ts_1 = require("rethinkdb-ts");
|
|
16
12
|
const term_backtrace_1 = require("rethinkdb-ts/lib/error/term-backtrace");
|
|
17
|
-
const
|
|
18
|
-
const utils_1 = require("./implementations/database/utils");
|
|
13
|
+
const rethinkdb_ts_1 = require("rethinkdb-ts");
|
|
19
14
|
const logger_1 = require("./utils/logger");
|
|
15
|
+
const write_result_1 = require("./write-result");
|
|
20
16
|
let connection;
|
|
21
17
|
async function ConnectDirect(options) {
|
|
22
18
|
logger_1.Logger.Debug("Connecting directly to RethinkDB", options.host ?? "localhost");
|
|
@@ -49,12 +45,6 @@ function Disconnect() {
|
|
|
49
45
|
}
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
|
-
function GetConnection() {
|
|
53
|
-
return connection?.connection;
|
|
54
|
-
}
|
|
55
|
-
function GetConnectionType() {
|
|
56
|
-
return connection?.type ?? "none";
|
|
57
|
-
}
|
|
58
48
|
function SendQuery(query, opts) {
|
|
59
49
|
(0, node_assert_1.default)(connection, "No connection established");
|
|
60
50
|
logger_1.Logger.Debug("Sending query via", connection.type);
|
|
@@ -77,6 +67,7 @@ async function executeTermJson(term) {
|
|
|
77
67
|
}
|
|
78
68
|
const cursorType = cursor.getType();
|
|
79
69
|
if (cursorType === "Atom") {
|
|
70
|
+
(0, write_result_1.validateWriteResult)(term, results[0]);
|
|
80
71
|
return results[0];
|
|
81
72
|
}
|
|
82
73
|
if (cursorType === "Cursor") {
|
|
@@ -84,63 +75,4 @@ async function executeTermJson(term) {
|
|
|
84
75
|
}
|
|
85
76
|
return results;
|
|
86
77
|
}
|
|
87
|
-
async function InitializeSchemaDatabase(dbName, schema) {
|
|
88
|
-
const dbList = (await executeTermJson([enums_1.TermType.DB_LIST, []])) ?? [];
|
|
89
|
-
if (!dbList.includes(dbName)) {
|
|
90
|
-
await executeTermJson([enums_1.TermType.DB_CREATE, [dbName]]);
|
|
91
|
-
}
|
|
92
|
-
const db = [enums_1.TermType.DB, [dbName]];
|
|
93
|
-
const tableList = (await executeTermJson([enums_1.TermType.TABLE_LIST, [db]])) ?? [];
|
|
94
|
-
const userTables = Object.keys(schema);
|
|
95
|
-
const tablesToCreate = [...userTables, utils_1.INSTANCE_REGISTRY_TABLE].filter((t) => !tableList.includes(t));
|
|
96
|
-
await Promise.all(tablesToCreate.map((t) => executeTermJson([enums_1.TermType.TABLE_CREATE, [db, t], { primary_key: "_id" }])));
|
|
97
|
-
await Promise.all(Object.entries(schema).map(([tableName, tableDef]) => initializeIndexes(db, tableName, tableDef.indexes)));
|
|
98
|
-
}
|
|
99
|
-
async function initializeIndexes(db, tableName, indexes) {
|
|
100
|
-
const table = [enums_1.TermType.TABLE, [db, tableName]];
|
|
101
|
-
const existingIndexList = (await executeTermJson([enums_1.TermType.INDEX_LIST, [table]])) ?? [];
|
|
102
|
-
let created = false;
|
|
103
|
-
for (const [indexName, indexDef] of Object.entries(indexes)) {
|
|
104
|
-
if (existingIndexList.includes(indexName)) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (indexDef.fields && indexDef.fields.length > 0) {
|
|
108
|
-
const argId = 0;
|
|
109
|
-
const fields = indexDef.fields.map((f) => [
|
|
110
|
-
enums_1.TermType.BRACKET,
|
|
111
|
-
[[enums_1.TermType.VAR, [argId]], f],
|
|
112
|
-
]);
|
|
113
|
-
await executeTermJson([
|
|
114
|
-
enums_1.TermType.INDEX_CREATE,
|
|
115
|
-
[
|
|
116
|
-
table,
|
|
117
|
-
indexName,
|
|
118
|
-
[
|
|
119
|
-
enums_1.TermType.FUNC,
|
|
120
|
-
[
|
|
121
|
-
[enums_1.TermType.MAKE_ARRAY, [argId]],
|
|
122
|
-
[enums_1.TermType.MAKE_ARRAY, fields],
|
|
123
|
-
],
|
|
124
|
-
],
|
|
125
|
-
],
|
|
126
|
-
indexDef.multi ? { multi: true } : {},
|
|
127
|
-
]);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
await executeTermJson([
|
|
131
|
-
enums_1.TermType.INDEX_CREATE,
|
|
132
|
-
[table, indexName],
|
|
133
|
-
indexDef.multi ? { multi: true } : {},
|
|
134
|
-
]);
|
|
135
|
-
}
|
|
136
|
-
created = true;
|
|
137
|
-
}
|
|
138
|
-
if (!existingIndexList.includes(utils_1.TENANT_ID_FIELD)) {
|
|
139
|
-
await executeTermJson([enums_1.TermType.INDEX_CREATE, [table, utils_1.TENANT_ID_FIELD]]);
|
|
140
|
-
created = true;
|
|
141
|
-
}
|
|
142
|
-
if (created) {
|
|
143
|
-
await executeTermJson([enums_1.TermType.INDEX_WAIT, [table]]);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
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,CAAC,OAAO,CAAC,OAAO,CAAC;KACrC,CAAC;IACF,eAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;AAClD,CAAC;AAEM,KAAK,UAAU,WAAW,CAAC,OAA+B;IAC/D,eAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC7C,UAAU,EAAE,CAAC;IACb,UAAU,GAAG;QACX,IAAI,EAAE,MAAM;QACZ,UAAU,EAAE,MAAM,gBAAC,CAAC,WAAW,CAAC,OAAO,CAAC;KACzC,CAAC;IACF,eAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;AAC9C,CAAC;AAED,SAAgB,UAAU;IACxB,IAAI,UAAU,EAAE,CAAC;QACf,eAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QAC9D,QAAQ,UAAU,CAAC,IAAI,EAAE,CAA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AO,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,3 @@
|
|
|
1
|
+
import type { TermJson } from "rethinkdb-ts/lib/internal-types";
|
|
2
|
+
import { type AtomicMutation, type AtomicMutationOutcome } from "@antelopejs/interface-database/atomic";
|
|
3
|
+
export declare function runAtomicMutation(table: TermJson, tenantId: string, key: string, request: AtomicMutation<Record<string, unknown>>): Promise<AtomicMutationOutcome>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runAtomicMutation = runAtomicMutation;
|
|
4
|
+
const enums_1 = require("rethinkdb-ts/lib/proto/enums");
|
|
5
|
+
const error_1 = require("rethinkdb-ts/lib/error/error");
|
|
6
|
+
const rethinkdb_ts_1 = require("rethinkdb-ts");
|
|
7
|
+
const atomic_1 = require("@antelopejs/interface-database/atomic");
|
|
8
|
+
const connection_1 = require("../../connection");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const DEFINITIVE_ERRORS = new Set([
|
|
11
|
+
rethinkdb_ts_1.RethinkDBErrorType.AUTH,
|
|
12
|
+
rethinkdb_ts_1.RethinkDBErrorType.PARSE,
|
|
13
|
+
rethinkdb_ts_1.RethinkDBErrorType.ARITY,
|
|
14
|
+
rethinkdb_ts_1.RethinkDBErrorType.QUERY_LOGIC,
|
|
15
|
+
rethinkdb_ts_1.RethinkDBErrorType.NON_EXISTENCE,
|
|
16
|
+
rethinkdb_ts_1.RethinkDBErrorType.PERMISSION_ERROR,
|
|
17
|
+
]);
|
|
18
|
+
const WRITE_COUNTS = ["replaced", "deleted", "unchanged", "skipped"];
|
|
19
|
+
async function runAtomicMutation(table, tenantId, key, request) {
|
|
20
|
+
(0, atomic_1.ValidateAtomicMutation)(key, request, [utils_1.TENANT_ID_FIELD]);
|
|
21
|
+
const term = buildAtomicTerm(table, tenantId, key, request);
|
|
22
|
+
try {
|
|
23
|
+
return mutationOutcome(await (0, connection_1.executeTermJson)(term));
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if ((0, error_1.isRethinkDBError)(error) && DEFINITIVE_ERRORS.has(error.type)) {
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
return "unknown";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function buildAtomicTerm(table, tenantId, key, request) {
|
|
33
|
+
const argId = (0, utils_1.allocateArgNumber)();
|
|
34
|
+
const doc = [enums_1.TermType.VAR, [argId]];
|
|
35
|
+
const condition = mutationCondition(doc, tenantId, request);
|
|
36
|
+
const isDelete = request.type !== "update";
|
|
37
|
+
const patch = isDelete
|
|
38
|
+
? null
|
|
39
|
+
: Object.fromEntries([
|
|
40
|
+
...Object.entries(request.patch).map(([field, value]) => [
|
|
41
|
+
field,
|
|
42
|
+
[enums_1.TermType.LITERAL, [rethinkdb_ts_1.r.expr(value).term]],
|
|
43
|
+
]),
|
|
44
|
+
[request.revisionField, request.nextRevision],
|
|
45
|
+
]);
|
|
46
|
+
const replacement = isDelete
|
|
47
|
+
? null
|
|
48
|
+
: [enums_1.TermType.MERGE, [doc, patch]];
|
|
49
|
+
const body = [enums_1.TermType.BRANCH, [condition, replacement, doc]];
|
|
50
|
+
const mutation = [
|
|
51
|
+
enums_1.TermType.FUNC,
|
|
52
|
+
[[enums_1.TermType.MAKE_ARRAY, [argId]], body],
|
|
53
|
+
];
|
|
54
|
+
return [
|
|
55
|
+
enums_1.TermType.REPLACE,
|
|
56
|
+
[[enums_1.TermType.GET, [table, key]], mutation],
|
|
57
|
+
{ durability: "hard", non_atomic: false },
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
function mutationCondition(doc, tenantId, request) {
|
|
61
|
+
const scope = fieldEquals(doc, utils_1.TENANT_ID_FIELD, tenantId);
|
|
62
|
+
const expected = expectedCondition(doc, request);
|
|
63
|
+
return [
|
|
64
|
+
enums_1.TermType.BRANCH,
|
|
65
|
+
[[enums_1.TermType.EQ, [doc, null]], false, [enums_1.TermType.AND, [scope, expected]]],
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
function expectedCondition(doc, request) {
|
|
69
|
+
if (request.type === "deleteIfEqual") {
|
|
70
|
+
return fieldEquals(doc, request.field, request.expectedValue);
|
|
71
|
+
}
|
|
72
|
+
if (typeof request.expectedRevision === "string") {
|
|
73
|
+
return fieldEquals(doc, request.revisionField, request.expectedRevision);
|
|
74
|
+
}
|
|
75
|
+
return [
|
|
76
|
+
enums_1.TermType.NOT,
|
|
77
|
+
[[enums_1.TermType.CONTAINS, [[enums_1.TermType.KEYS, [doc]], request.revisionField]]],
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
function fieldEquals(doc, field, value) {
|
|
81
|
+
return [
|
|
82
|
+
enums_1.TermType.DEFAULT,
|
|
83
|
+
[
|
|
84
|
+
[
|
|
85
|
+
enums_1.TermType.EQ,
|
|
86
|
+
[
|
|
87
|
+
[enums_1.TermType.BRACKET, [doc, field]],
|
|
88
|
+
rethinkdb_ts_1.r.expr(value).term,
|
|
89
|
+
],
|
|
90
|
+
],
|
|
91
|
+
false,
|
|
92
|
+
],
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
function mutationOutcome(result) {
|
|
96
|
+
if (result?.errors !== 0 ||
|
|
97
|
+
result?.inserted !== 0 ||
|
|
98
|
+
!WRITE_COUNTS.every((field) => Number.isInteger(result[field]) && result[field] >= 0) ||
|
|
99
|
+
WRITE_COUNTS.reduce((sum, field) => sum + result[field], 0) !== 1) {
|
|
100
|
+
return "unknown";
|
|
101
|
+
}
|
|
102
|
+
return result.replaced + result.deleted === 1 ? "applied" : "not-applied";
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=atomic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomic.js","sourceRoot":"","sources":["../../../src/implementations/database/atomic.ts"],"names":[],"mappings":";;AAwBA,8CAgBC;AAxCD,wDAAwD;AACxD,wDAAgE;AAEhE,+CAAkE;AAClE,kEAI+C;AAE/C,iDAAmD;AACnD,mCAA6D;AAE7D,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,iCAAkB,CAAC,IAAI;IACvB,iCAAkB,CAAC,KAAK;IACxB,iCAAkB,CAAC,KAAK;IACxB,iCAAkB,CAAC,WAAW;IAC9B,iCAAkB,CAAC,aAAa;IAChC,iCAAkB,CAAC,gBAAgB;CACpC,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;AAG9D,KAAK,UAAU,iBAAiB,CACrC,KAAe,EACf,QAAgB,EAChB,GAAW,EACX,OAAgD;IAEhD,IAAA,+BAAsB,EAAC,GAAG,EAAE,OAAO,EAAE,CAAC,uBAAe,CAAC,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5D,IAAI,CAAC;QACH,OAAO,eAAe,CAAC,MAAM,IAAA,4BAAe,EAAC,IAAI,CAAC,CAAC,CAAC;IACtD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,IAAA,wBAAgB,EAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACjE,MAAM,KAAK,CAAC;QACd,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CACtB,KAAe,EACf,QAAgB,EAChB,GAAW,EACX,OAAgD;IAEhD,MAAM,KAAK,GAAG,IAAA,yBAAiB,GAAE,CAAC;IACl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AAC,gBAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;oBAC/B,gBAAC,CAAC,IAAI,CAAC,KAAK,CAAmB,CAAC,IAAI;iBACtC;aACF;YACD,KAAK;SACN;KACF,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,MAAW;IAClC,IACE,MAAM,EAAE,MAAM,KAAK,CAAC;QACpB,MAAM,EAAE,QAAQ,KAAK,CAAC;QACtB,CAAC,YAAY,CAAC,KAAK,CACjB,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CACjE;QACD,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EACjE,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC;AAC5E,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { TermJson } from "rethinkdb-ts/lib/internal-types";
|
|
2
|
+
import type { Value } from "@antelopejs/interface-database/common";
|
|
2
3
|
import { type DecodingContext, type QueryStage } from "./utils";
|
|
3
|
-
export declare function
|
|
4
|
+
export declare function DecodeValue(value: Value<unknown>, context: DecodingContext): TermJson;
|
|
5
|
+
export declare function DecodeFunction(func: QueryStage, context: DecodingContext, argTerms: TermJson[]): TermJson;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
6
|
+
exports.DecodeValue = DecodeValue;
|
|
7
|
+
exports.DecodeFunction = DecodeFunction;
|
|
8
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
4
9
|
const enums_1 = require("rethinkdb-ts/lib/proto/enums");
|
|
5
|
-
const
|
|
10
|
+
const interface_database_1 = require("@antelopejs/interface-database");
|
|
11
|
+
const selection_1 = require("./selection");
|
|
6
12
|
const utils_1 = require("./utils");
|
|
7
13
|
const SIMPLE_STAGE_MAP = {
|
|
8
14
|
default: enums_1.TermType.DEFAULT,
|
|
@@ -128,7 +134,7 @@ const FUNC_STAGE_MAP = {
|
|
|
128
134
|
const func = stage.args[0];
|
|
129
135
|
const argId = (0, utils_1.allocateArgNumber)();
|
|
130
136
|
const row = [enums_1.TermType.VAR, [argId]];
|
|
131
|
-
const body =
|
|
137
|
+
const body = DecodeFunction(func, expr.context, [row]);
|
|
132
138
|
return [
|
|
133
139
|
enums_1.TermType.FILTER,
|
|
134
140
|
[expr.value, [enums_1.TermType.FUNC, [[enums_1.TermType.MAKE_ARRAY, [argId]], body]]],
|
|
@@ -138,7 +144,7 @@ const FUNC_STAGE_MAP = {
|
|
|
138
144
|
const func = stage.args[0];
|
|
139
145
|
const argId = (0, utils_1.allocateArgNumber)();
|
|
140
146
|
const row = [enums_1.TermType.VAR, [argId]];
|
|
141
|
-
const body =
|
|
147
|
+
const body = DecodeFunction(func, expr.context, [row]);
|
|
142
148
|
return [
|
|
143
149
|
enums_1.TermType.MAP,
|
|
144
150
|
[expr.value, [enums_1.TermType.FUNC, [[enums_1.TermType.MAKE_ARRAY, [argId]], body]]],
|
|
@@ -160,7 +166,7 @@ function decodeExpression(stages, context, startValue = [enums_1.TermType.IMPLIC
|
|
|
160
166
|
builder.value = funcHandler(builder, stage);
|
|
161
167
|
continue;
|
|
162
168
|
}
|
|
163
|
-
const decodedArgs = stage.args.map((arg) =>
|
|
169
|
+
const decodedArgs = stage.args.map((arg) => DecodeValue(arg, context));
|
|
164
170
|
const simpleType = SIMPLE_STAGE_MAP[stage.stage];
|
|
165
171
|
if (simpleType !== undefined) {
|
|
166
172
|
builder.value = applySimpleStage(builder.value, simpleType, decodedArgs);
|
|
@@ -176,4 +182,73 @@ function decodeExpression(stages, context, startValue = [enums_1.TermType.IMPLIC
|
|
|
176
182
|
delete builder.options;
|
|
177
183
|
return builder.value;
|
|
178
184
|
}
|
|
185
|
+
function DecodeValue(value, context) {
|
|
186
|
+
if (value instanceof interface_database_1.ValueProxy) {
|
|
187
|
+
return decodeExpression(value.build(), context);
|
|
188
|
+
}
|
|
189
|
+
if (value instanceof interface_database_1.Query) {
|
|
190
|
+
return decodeSubquery(value.build(), context);
|
|
191
|
+
}
|
|
192
|
+
if (value && typeof value === "object") {
|
|
193
|
+
if (Array.isArray(value)) {
|
|
194
|
+
return [
|
|
195
|
+
enums_1.TermType.MAKE_ARRAY,
|
|
196
|
+
value.map((val) => DecodeValue(val, context)),
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
if (value instanceof Date) {
|
|
200
|
+
return dateToReql(value);
|
|
201
|
+
}
|
|
202
|
+
if (value instanceof Object) {
|
|
203
|
+
return Object.fromEntries(Object.entries(value).map(([key, val]) => [
|
|
204
|
+
key,
|
|
205
|
+
DecodeValue(val, context),
|
|
206
|
+
]));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (value === undefined) {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
function dateToReql(date) {
|
|
215
|
+
const timeZone = date.getTimezoneOffset();
|
|
216
|
+
return {
|
|
217
|
+
$reql_type$: "TIME",
|
|
218
|
+
epoch_time: +date / 1000,
|
|
219
|
+
timezone: `${timeZone <= 0 ? "+" : "-"}${Math.abs(Math.floor(timeZone / 60))
|
|
220
|
+
.toFixed(0)
|
|
221
|
+
.padStart(2, "0")}:${Math.abs(timeZone % 60)
|
|
222
|
+
.toFixed(0)
|
|
223
|
+
.padStart(2, "0")}`,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function decodeSubquery(stages, context) {
|
|
227
|
+
if (stages[0]?.stage === "arg") {
|
|
228
|
+
const num = stages[0].args[0];
|
|
229
|
+
const provider = context.args[num];
|
|
230
|
+
(0, node_assert_1.default)(provider, "Unknown arg used");
|
|
231
|
+
return provider(stages);
|
|
232
|
+
}
|
|
233
|
+
return selection_1.SelectionQuery.buildTermJson(stages, context);
|
|
234
|
+
}
|
|
235
|
+
function DecodeFunction(func, context, argTerms) {
|
|
236
|
+
const argNumbers = func.args[0];
|
|
237
|
+
const oldArgs = {};
|
|
238
|
+
for (let i = 0; i < argNumbers.length; ++i) {
|
|
239
|
+
oldArgs[argNumbers[i]] = context.args[argNumbers[i]];
|
|
240
|
+
const argTerm = argTerms[i];
|
|
241
|
+
context.args[argNumbers[i]] = () => argTerm;
|
|
242
|
+
}
|
|
243
|
+
const val = DecodeValue(func.args[1], context);
|
|
244
|
+
for (let i = 0; i < argNumbers.length; ++i) {
|
|
245
|
+
if (oldArgs[argNumbers[i]] !== undefined) {
|
|
246
|
+
context.args[argNumbers[i]] = oldArgs[argNumbers[i]];
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
delete context.args[argNumbers[i]];
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return val;
|
|
253
|
+
}
|
|
179
254
|
//# sourceMappingURL=expression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../src/implementations/database/expression.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../src/implementations/database/expression.ts"],"names":[],"mappings":";;;;;AA2NA,kCAqCC;AA4BD,wCAqBC;AAjTD,8DAAiC;AACjC,wDAAwD;AAExD,uEAAmE;AAOnE,2CAA6C;AAC7C,mCAIiB;AAYjB,MAAM,gBAA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,EAAE,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QAC3C,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC;IAC9C,CAAC;IACD,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QAC3C,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;YACzC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,OAAO,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,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 {};
|