@anysoftinc/anydb-sdk 0.1.2 → 0.3.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 +91 -167
- package/dist/client.d.ts +45 -96
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +273 -305
- package/dist/datascript-backend.d.ts +26 -0
- package/dist/datascript-backend.d.ts.map +1 -0
- package/dist/datascript-backend.js +113 -0
- package/dist/nextauth-adapter.d.ts +7 -2
- package/dist/nextauth-adapter.d.ts.map +1 -1
- package/dist/nextauth-adapter.js +254 -149
- package/package.json +5 -2
- package/dist/query-builder.d.ts +0 -126
- package/dist/query-builder.d.ts.map +0 -1
- package/dist/query-builder.js +0 -207
package/README.md
CHANGED
|
@@ -11,35 +11,43 @@ npm install @anysoftinc/anydb-sdk
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
DatomicClient,
|
|
16
|
+
createAnyDBClient,
|
|
17
|
+
kw,
|
|
18
|
+
sym,
|
|
19
|
+
uuid,
|
|
20
|
+
} from "@anysoftinc/anydb-sdk";
|
|
15
21
|
|
|
16
22
|
// Create a client
|
|
17
23
|
const client = new DatomicClient({
|
|
18
|
-
baseUrl:
|
|
24
|
+
baseUrl: "http://localhost:4000",
|
|
25
|
+
getAuthToken: () => process.env.ANYDB_TOKEN!,
|
|
19
26
|
});
|
|
20
27
|
|
|
21
28
|
// Create a database wrapper for convenience
|
|
22
|
-
const db =
|
|
29
|
+
const db = createAnyDBClient(client, "sql", "db-name");
|
|
23
30
|
|
|
24
|
-
//
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
// Symbolic query
|
|
32
|
+
const query = {
|
|
33
|
+
find: [[sym("pull"), sym("?e"), [kw("db/id"), kw("person/name")]]],
|
|
34
|
+
where: [[sym("?e"), kw("person/name"), "John Doe"]],
|
|
35
|
+
};
|
|
36
|
+
const rows = await db.query(query);
|
|
29
37
|
|
|
30
|
-
// Execute a transaction
|
|
31
|
-
|
|
38
|
+
// Execute a transaction (keywordized keys, kw()/uuid() for values)
|
|
39
|
+
await db.transact([
|
|
32
40
|
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
41
|
+
["person/id"]: uuid("550e8400-e29b-41d4-a716-446655440000"),
|
|
42
|
+
["person/name"]: "John Doe",
|
|
43
|
+
},
|
|
37
44
|
]);
|
|
38
45
|
```
|
|
39
46
|
|
|
40
47
|
## Core Features
|
|
41
48
|
|
|
42
49
|
### Database Operations
|
|
50
|
+
|
|
43
51
|
- **Database Management** - Create, list, and delete databases
|
|
44
52
|
- **Transactions** - Execute database transactions
|
|
45
53
|
- **Queries** - Execute Datalog queries with full EDN support
|
|
@@ -48,176 +56,96 @@ const txResult = await db.transact([
|
|
|
48
56
|
|
|
49
57
|
### Query Types
|
|
50
58
|
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
const query = [
|
|
54
|
-
':find', '?e', '?name',
|
|
55
|
-
':where', ['?e', ':person/name', '?name']
|
|
56
|
-
];
|
|
57
|
-
const results = await db.query(query);
|
|
58
|
-
```
|
|
59
|
+
Traditional array-based queries are not supported in v2.
|
|
59
60
|
|
|
60
61
|
#### Symbolic Queries (Type-safe)
|
|
62
|
+
|
|
61
63
|
```typescript
|
|
62
|
-
import { sym, kw } from
|
|
64
|
+
import { sym, kw } from "@anysoftinc/anydb-sdk";
|
|
63
65
|
|
|
64
66
|
const query = {
|
|
65
|
-
find: [sym(
|
|
66
|
-
where: [
|
|
67
|
-
[sym('?e'), kw(':person/name'), sym('?name')]
|
|
68
|
-
]
|
|
67
|
+
find: [sym("?e"), sym("?name")],
|
|
68
|
+
where: [[sym("?e"), kw("person/name"), sym("?name")]],
|
|
69
69
|
};
|
|
70
|
-
const results = await db.
|
|
70
|
+
const results = await db.query(query);
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
The QueryBuilder provides a type-safe, fluent API for constructing Datalog queries:
|
|
76
|
-
|
|
77
|
-
```typescript
|
|
78
|
-
import { QueryBuilder, kw } from '@anysoftinc/anydb-sdk';
|
|
79
|
-
|
|
80
|
-
// Basic entity-attribute-value query
|
|
81
|
-
const basicQuery = new QueryBuilder()
|
|
82
|
-
.find('?e', '?name')
|
|
83
|
-
.where({ entity: '?e', attribute: kw(':person/name'), value: '?name' })
|
|
84
|
-
.build();
|
|
85
|
-
|
|
86
|
-
// Fluent entity-based building
|
|
87
|
-
const fluentQuery = new QueryBuilder()
|
|
88
|
-
.find('?e', '?name')
|
|
89
|
-
.entity('?e').hasAttribute(kw(':person/name')).withValue('?name')
|
|
90
|
-
.build();
|
|
91
|
-
|
|
92
|
-
// Helper methods for common patterns
|
|
93
|
-
const entitiesWithName = new QueryBuilder()
|
|
94
|
-
.findEntitiesWith(kw(':person/name'))
|
|
95
|
-
.build();
|
|
96
|
-
|
|
97
|
-
// Aggregation queries
|
|
98
|
-
const personCount = new QueryBuilder()
|
|
99
|
-
.count('?e')
|
|
100
|
-
.where({ entity: '?e', attribute: kw(':person/name'), value: '?name' })
|
|
101
|
-
.build();
|
|
102
|
-
|
|
103
|
-
// Multiple aggregations
|
|
104
|
-
const stats = new QueryBuilder()
|
|
105
|
-
.count('?e')
|
|
106
|
-
.avg('?age')
|
|
107
|
-
.where({ entity: '?e', attribute: kw(':person/name'), value: '?name' })
|
|
108
|
-
.where({ entity: '?e', attribute: kw(':person/age'), value: '?age' })
|
|
109
|
-
.build();
|
|
110
|
-
|
|
111
|
-
// Input parameters and with clauses
|
|
112
|
-
const parameterizedQuery = new QueryBuilder()
|
|
113
|
-
.find('?e')
|
|
114
|
-
.in('$', '?minAge')
|
|
115
|
-
.with('?tx')
|
|
116
|
-
.where({ entity: '?e', attribute: kw(':person/age'), value: '?age' })
|
|
117
|
-
.build();
|
|
118
|
-
|
|
119
|
-
// Direct execution
|
|
120
|
-
const results = await new QueryBuilder()
|
|
121
|
-
.find('?e', '?name')
|
|
122
|
-
.entity('?e').hasAttribute(kw(':person/name')).withValue('?name')
|
|
123
|
-
.execute(db);
|
|
124
|
-
```
|
|
73
|
+
QueryBuilder has been removed in v2.
|
|
125
74
|
|
|
126
75
|
**QueryBuilder Benefits:**
|
|
76
|
+
|
|
127
77
|
- **Type Safety**: All attributes use proper `Keyword` objects with `kw()`
|
|
128
|
-
- **IntelliSense**: Full autocomplete for methods and parameters
|
|
78
|
+
- **IntelliSense**: Full autocomplete for methods and parameters
|
|
129
79
|
- **Structured Queries**: No string concatenation or EDN parsing errors
|
|
130
80
|
- **Fluent API**: Chain methods for readable query construction
|
|
131
81
|
- **Aggregations**: Built-in support for count, sum, avg, min, max
|
|
132
82
|
- **Direct Execution**: Execute queries directly from the builder
|
|
133
83
|
|
|
134
84
|
### Temporal Queries
|
|
85
|
+
|
|
135
86
|
```typescript
|
|
136
87
|
// As-of queries
|
|
137
|
-
const pastResults = await client.query(query, [
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
88
|
+
const pastResults = await client.query(query, [
|
|
89
|
+
{
|
|
90
|
+
"db/alias": "storage/db",
|
|
91
|
+
"as-of": 1000,
|
|
92
|
+
},
|
|
93
|
+
]);
|
|
141
94
|
|
|
142
|
-
// Since queries
|
|
143
|
-
const recentResults = await client.query(query, [
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
95
|
+
// Since queries
|
|
96
|
+
const recentResults = await client.query(query, [
|
|
97
|
+
{
|
|
98
|
+
"db/alias": "storage/db",
|
|
99
|
+
since: 1000,
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
147
102
|
|
|
148
103
|
// History queries
|
|
149
|
-
const allHistory = await client.query(query, [
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
104
|
+
const allHistory = await client.query(query, [
|
|
105
|
+
{
|
|
106
|
+
"db/alias": "storage/db",
|
|
107
|
+
history: true,
|
|
108
|
+
},
|
|
109
|
+
]);
|
|
153
110
|
```
|
|
154
111
|
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
import { SchemaBuilder, DatomicUtils } from '@anysoftinc/anydb-sdk';
|
|
158
|
-
|
|
159
|
-
// Define attributes
|
|
160
|
-
const personNameAttr = SchemaBuilder.attribute({
|
|
161
|
-
':db/ident': ':person/name',
|
|
162
|
-
':db/valueType': ':db.type/string',
|
|
163
|
-
':db/cardinality': ':db.cardinality/one',
|
|
164
|
-
':db/index': true,
|
|
165
|
-
':db/doc': 'Person name'
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// Define enums
|
|
169
|
-
const genderEnum = SchemaBuilder.enum(':person.gender/male');
|
|
170
|
-
|
|
171
|
-
// Install schema
|
|
172
|
-
await db.transact([personNameAttr, genderEnum]);
|
|
173
|
-
```
|
|
112
|
+
SchemaBuilder and DatomicUtils have been removed in v2. Use plain tx maps with keywordized keys and kw()/uuid() for values.
|
|
174
113
|
|
|
175
114
|
### Utility Functions
|
|
176
|
-
```typescript
|
|
177
|
-
import { DatomicUtils } from '@anysoftinc/anydb-sdk';
|
|
178
|
-
|
|
179
|
-
// Generate temp IDs
|
|
180
|
-
const tempId = DatomicUtils.tempId();
|
|
181
115
|
|
|
182
|
-
|
|
183
|
-
const personEntity = DatomicUtils.createEntity({
|
|
184
|
-
':person/name': 'Jane Doe',
|
|
185
|
-
':person/email': 'jane@example.com'
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// Retract data
|
|
189
|
-
const retraction = DatomicUtils.retractEntity(12345);
|
|
190
|
-
```
|
|
116
|
+
Utility helpers for tempids and entity builders were removed in v2.
|
|
191
117
|
|
|
192
118
|
## Advanced Features
|
|
193
119
|
|
|
194
120
|
### EDN Data Types
|
|
121
|
+
|
|
195
122
|
The SDK provides full support for Datomic's EDN data types:
|
|
196
123
|
|
|
197
124
|
```typescript
|
|
198
|
-
import { sym, kw, uuid } from
|
|
125
|
+
import { sym, kw, uuid } from "@anysoftinc/anydb-sdk";
|
|
199
126
|
|
|
200
127
|
// Symbols for query variables
|
|
201
|
-
const entityVar = sym(
|
|
128
|
+
const entityVar = sym("?e");
|
|
202
129
|
|
|
203
130
|
// Keywords for attributes
|
|
204
|
-
const nameAttr = kw(
|
|
131
|
+
const nameAttr = kw("person/name");
|
|
205
132
|
|
|
206
133
|
// UUIDs
|
|
207
|
-
const entityId = uuid(
|
|
134
|
+
const entityId = uuid("550e8400-e29b-41d4-a716-446655440000");
|
|
208
135
|
```
|
|
209
136
|
|
|
210
137
|
### Event Streaming
|
|
138
|
+
|
|
211
139
|
Subscribe to transaction reports via Server-Sent Events:
|
|
212
140
|
|
|
213
141
|
```typescript
|
|
214
142
|
const eventSource = db.subscribeToEvents(
|
|
215
143
|
(event) => {
|
|
216
144
|
const txData = JSON.parse(event.data);
|
|
217
|
-
console.log(
|
|
145
|
+
console.log("Transaction:", txData);
|
|
218
146
|
},
|
|
219
147
|
(error) => {
|
|
220
|
-
console.error(
|
|
148
|
+
console.error("Connection error:", error);
|
|
221
149
|
}
|
|
222
150
|
);
|
|
223
151
|
|
|
@@ -226,41 +154,44 @@ eventSource.close();
|
|
|
226
154
|
```
|
|
227
155
|
|
|
228
156
|
### Raw Datom Queries
|
|
157
|
+
|
|
229
158
|
Access the raw datom index for high-performance queries:
|
|
230
159
|
|
|
231
160
|
```typescript
|
|
232
161
|
// Query EAVT index
|
|
233
|
-
const datoms = await db.datoms(
|
|
162
|
+
const datoms = await db.datoms("eavt", "-", {
|
|
234
163
|
e: 12345,
|
|
235
|
-
limit: 100
|
|
164
|
+
limit: 100,
|
|
236
165
|
});
|
|
237
166
|
|
|
238
167
|
// Query AVET index for attribute values
|
|
239
|
-
const attributeValues = await db.datoms(
|
|
240
|
-
a:
|
|
241
|
-
start:
|
|
242
|
-
end:
|
|
168
|
+
const attributeValues = await db.datoms("avet", "-", {
|
|
169
|
+
a: ":person/name",
|
|
170
|
+
start: "A",
|
|
171
|
+
end: "B",
|
|
243
172
|
});
|
|
244
173
|
```
|
|
245
174
|
|
|
246
175
|
### Custom HTTP Configuration
|
|
176
|
+
|
|
247
177
|
```typescript
|
|
248
178
|
const client = new DatomicClient({
|
|
249
|
-
baseUrl:
|
|
179
|
+
baseUrl: "https://api.example.com",
|
|
250
180
|
timeout: 30000,
|
|
251
181
|
headers: {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
182
|
+
Authorization: "Bearer token",
|
|
183
|
+
"X-Custom-Header": "value",
|
|
184
|
+
},
|
|
255
185
|
});
|
|
256
186
|
```
|
|
257
187
|
|
|
258
188
|
### NextAuth.js Integration
|
|
189
|
+
|
|
259
190
|
The SDK includes a NextAuth.js adapter for authentication:
|
|
260
191
|
|
|
261
192
|
```typescript
|
|
262
|
-
import { AnyDBAdapter } from
|
|
263
|
-
import NextAuth from
|
|
193
|
+
import { AnyDBAdapter } from "@anysoftinc/anydb-sdk/nextauth-adapter";
|
|
194
|
+
import NextAuth from "next-auth";
|
|
264
195
|
|
|
265
196
|
export default NextAuth({
|
|
266
197
|
adapter: AnyDBAdapter(db),
|
|
@@ -278,10 +209,10 @@ The SDK provides detailed error information:
|
|
|
278
209
|
try {
|
|
279
210
|
const results = await db.query(invalidQuery);
|
|
280
211
|
} catch (error) {
|
|
281
|
-
if (error.message.includes(
|
|
282
|
-
console.error(
|
|
212
|
+
if (error.message.includes("Datomic API error")) {
|
|
213
|
+
console.error("Server error:", error.message);
|
|
283
214
|
} else {
|
|
284
|
-
console.error(
|
|
215
|
+
console.error("Client error:", error);
|
|
285
216
|
}
|
|
286
217
|
}
|
|
287
218
|
```
|
|
@@ -291,17 +222,17 @@ try {
|
|
|
291
222
|
Full TypeScript definitions are included:
|
|
292
223
|
|
|
293
224
|
```typescript
|
|
294
|
-
import type {
|
|
295
|
-
QueryResult,
|
|
296
|
-
Transaction,
|
|
297
|
-
Entity,
|
|
225
|
+
import type {
|
|
226
|
+
QueryResult,
|
|
227
|
+
Transaction,
|
|
228
|
+
Entity,
|
|
298
229
|
Datom,
|
|
299
|
-
DatabaseDescriptor
|
|
300
|
-
} from
|
|
230
|
+
DatabaseDescriptor,
|
|
231
|
+
} from "@anysoftinc/anydb-sdk";
|
|
301
232
|
|
|
302
233
|
const processResults = (results: QueryResult): void => {
|
|
303
|
-
results.forEach(row => {
|
|
304
|
-
console.log(
|
|
234
|
+
results.forEach((row) => {
|
|
235
|
+
console.log("Row:", row);
|
|
305
236
|
});
|
|
306
237
|
};
|
|
307
238
|
```
|
|
@@ -316,21 +247,14 @@ See the [examples directory](./examples/) for complete working examples:
|
|
|
316
247
|
## API Reference
|
|
317
248
|
|
|
318
249
|
### DatomicClient
|
|
319
|
-
The main client class for interacting with the AnyDB server.
|
|
320
|
-
|
|
321
|
-
### DatomicDatabase
|
|
322
|
-
Convenience wrapper for working with a specific database.
|
|
323
250
|
|
|
324
|
-
|
|
325
|
-
Static utility methods for common Datomic operations.
|
|
251
|
+
The main client class for interacting with the AnyDB server.
|
|
326
252
|
|
|
327
|
-
###
|
|
328
|
-
Helper for building schema definitions.
|
|
253
|
+
### AnyDBClient
|
|
329
254
|
|
|
330
|
-
|
|
331
|
-
Fluent API for constructing queries programmatically.
|
|
255
|
+
Convenience wrapper for working with a specific database.
|
|
332
256
|
|
|
333
257
|
## Related
|
|
334
258
|
|
|
335
259
|
- [AnyDB Server](../../..) - Backend Clojure implementation
|
|
336
|
-
- [Datomic Documentation](https://docs.datomic.com/) - Official Datomic docs
|
|
260
|
+
- [Datomic Documentation](https://docs.datomic.com/) - Official Datomic docs
|
package/dist/client.d.ts
CHANGED
|
@@ -1,36 +1,31 @@
|
|
|
1
|
+
import { shouldUseDataScript, isDataScriptAvailable } from "./datascript-backend";
|
|
1
2
|
export interface Symbol {
|
|
2
|
-
_type:
|
|
3
|
+
_type: "symbol";
|
|
3
4
|
value: string;
|
|
4
5
|
}
|
|
5
6
|
export interface UUID {
|
|
6
|
-
_type:
|
|
7
|
+
_type: "uuid";
|
|
7
8
|
value: string;
|
|
8
9
|
}
|
|
9
10
|
export interface Keyword {
|
|
10
|
-
_type:
|
|
11
|
+
_type: "keyword";
|
|
11
12
|
value: string;
|
|
12
13
|
}
|
|
13
14
|
export declare const sym: (name: string) => Symbol;
|
|
14
15
|
export declare const uuid: (id: string) => UUID;
|
|
15
16
|
export declare const kw: (name: string) => Keyword;
|
|
16
|
-
export type QueryValue = Symbol | UUID | Keyword | string | number | boolean | Date | null;
|
|
17
|
+
export type QueryValue = Symbol | UUID | Keyword | string | number | boolean | Date | null | any[];
|
|
17
18
|
export type QueryClause = QueryValue[];
|
|
18
19
|
export interface SymbolicQuery {
|
|
19
20
|
find: QueryValue[];
|
|
20
21
|
where: QueryClause[];
|
|
21
22
|
in?: QueryValue[];
|
|
22
23
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Enhanced EDN stringifier with support for symbolic types
|
|
25
|
-
*/
|
|
26
|
-
export declare function stringifyEdn(obj: unknown): string;
|
|
27
24
|
export type EntityId = number | string;
|
|
28
|
-
export type KeywordString = string;
|
|
29
|
-
export type Instant = Date | string;
|
|
30
25
|
export type BasisT = number | "-";
|
|
31
26
|
export interface Datom {
|
|
32
27
|
e: EntityId;
|
|
33
|
-
a:
|
|
28
|
+
a: string;
|
|
34
29
|
v: any;
|
|
35
30
|
tx: EntityId;
|
|
36
31
|
added: boolean;
|
|
@@ -39,110 +34,69 @@ export interface Entity {
|
|
|
39
34
|
[attribute: string]: any;
|
|
40
35
|
"db/id": EntityId;
|
|
41
36
|
}
|
|
37
|
+
export interface DatabaseInfo {
|
|
38
|
+
"basis-t": number;
|
|
39
|
+
"db/alias": string;
|
|
40
|
+
}
|
|
42
41
|
export interface Transaction {
|
|
43
42
|
"db-before": DatabaseInfo;
|
|
44
43
|
"db-after": DatabaseInfo;
|
|
45
44
|
"tx-data": Datom[];
|
|
46
45
|
tempids: Record<string, EntityId>;
|
|
47
46
|
}
|
|
48
|
-
export interface DatabaseInfo {
|
|
49
|
-
"basis-t": number;
|
|
50
|
-
"db/alias": string;
|
|
51
|
-
}
|
|
52
|
-
export type QueryInput = any[];
|
|
53
47
|
export type QueryResult = any[][];
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
history?: boolean;
|
|
48
|
+
declare class AnyDBError extends Error {
|
|
49
|
+
details?: any | undefined;
|
|
50
|
+
constructor(message: string, details?: any | undefined);
|
|
51
|
+
}
|
|
52
|
+
export declare class AuthError extends AnyDBError {
|
|
60
53
|
}
|
|
61
|
-
export
|
|
54
|
+
export declare class QueryInputError extends AnyDBError {
|
|
55
|
+
}
|
|
56
|
+
export declare class SchemaError extends AnyDBError {
|
|
57
|
+
}
|
|
58
|
+
export declare class TransportError extends AnyDBError {
|
|
59
|
+
}
|
|
60
|
+
export declare class ServerError extends AnyDBError {
|
|
61
|
+
}
|
|
62
|
+
export declare function stringifyEdn(obj: unknown): string;
|
|
63
|
+
export interface ClientConfig {
|
|
62
64
|
baseUrl: string;
|
|
63
|
-
timeout?: number;
|
|
64
65
|
headers?: Record<string, string>;
|
|
66
|
+
authToken?: string;
|
|
67
|
+
getAuthToken?: () => Promise<string> | string;
|
|
68
|
+
fetchImpl?: typeof fetch;
|
|
69
|
+
eventSourceFactory?: (url: string, init?: any) => EventSource;
|
|
65
70
|
}
|
|
66
71
|
export declare class DatomicClient {
|
|
67
72
|
private config;
|
|
68
73
|
private baseUrl;
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
private fetchImpl;
|
|
75
|
+
constructor(config: ClientConfig);
|
|
76
|
+
private authHeader;
|
|
71
77
|
private request;
|
|
72
|
-
listDatabases(storageAlias: string): Promise<string[]>;
|
|
73
|
-
createDatabase(storageAlias: string, dbName: string): Promise<{
|
|
74
|
-
"db-created": string;
|
|
75
|
-
}>;
|
|
76
|
-
deleteDatabase(storageAlias: string, dbName: string): Promise<{
|
|
77
|
-
"db-deleted": string;
|
|
78
|
-
}>;
|
|
79
78
|
transact(storageAlias: string, dbName: string, txData: any[]): Promise<Transaction>;
|
|
80
|
-
|
|
81
|
-
datoms(storageAlias: string, dbName: string, basisT: BasisT, options: {
|
|
82
|
-
index: "eavt" | "aevt" | "avet" | "vaet";
|
|
83
|
-
e?: EntityId;
|
|
84
|
-
a?: KeywordString;
|
|
85
|
-
v?: any;
|
|
86
|
-
start?: any;
|
|
87
|
-
end?: any;
|
|
88
|
-
limit?: number;
|
|
89
|
-
offset?: number;
|
|
90
|
-
"as-of"?: number;
|
|
91
|
-
since?: number;
|
|
92
|
-
history?: boolean;
|
|
93
|
-
}): Promise<Datom[]>;
|
|
94
|
-
entity(storageAlias: string, dbName: string, basisT: BasisT, entityId: EntityId, options?: {
|
|
95
|
-
"as-of"?: number;
|
|
96
|
-
since?: number;
|
|
97
|
-
}): Promise<Entity>;
|
|
98
|
-
queryGet(query: QueryInput, args: DatabaseDescriptor[], options?: {
|
|
99
|
-
limit?: number;
|
|
100
|
-
offset?: number;
|
|
101
|
-
}): Promise<QueryResult>;
|
|
102
|
-
query(query: QueryInput, args: any[], options?: {
|
|
103
|
-
limit?: number;
|
|
104
|
-
offset?: number;
|
|
105
|
-
}): Promise<QueryResult>;
|
|
106
|
-
querySymbolic(query: SymbolicQuery, args?: any[], options?: {
|
|
79
|
+
querySymbolic(q: SymbolicQuery, args?: any[], options?: {
|
|
107
80
|
limit?: number;
|
|
108
81
|
offset?: number;
|
|
109
82
|
}): Promise<QueryResult>;
|
|
110
83
|
subscribeToEvents(storageAlias: string, dbName: string, onEvent: (event: MessageEvent) => void, onError?: (error: Event) => void): EventSource;
|
|
111
84
|
}
|
|
112
|
-
export declare class
|
|
113
|
-
static tempId(partition?: string): string;
|
|
114
|
-
static keyword(namespace: string, name: string): KeywordString;
|
|
115
|
-
static createEntity(attributes: Record<string, any>, tempId?: string): any[];
|
|
116
|
-
static retractEntity(entityId: EntityId): any[];
|
|
117
|
-
static retractAttribute(entityId: EntityId, attribute: KeywordString, value?: any): any[];
|
|
118
|
-
static addAttribute(entityId: EntityId, attribute: KeywordString, value: any): any[];
|
|
119
|
-
}
|
|
120
|
-
export interface AttributeDefinition {
|
|
121
|
-
":db/ident": KeywordString;
|
|
122
|
-
":db/valueType": KeywordString;
|
|
123
|
-
":db/cardinality": ":db.cardinality/one" | ":db.cardinality/many";
|
|
124
|
-
":db/unique"?: ":db.unique/value" | ":db.unique/identity";
|
|
125
|
-
":db/index"?: boolean;
|
|
126
|
-
":db/fulltext"?: boolean;
|
|
127
|
-
":db/isComponent"?: boolean;
|
|
128
|
-
":db/noHistory"?: boolean;
|
|
129
|
-
":db/doc"?: string;
|
|
130
|
-
}
|
|
131
|
-
export declare class SchemaBuilder {
|
|
132
|
-
static attribute(def: AttributeDefinition): any;
|
|
133
|
-
static enum(ident: KeywordString, doc?: string): any;
|
|
134
|
-
}
|
|
135
|
-
export declare function edn(strings: TemplateStringsArray, ...values: any[]): QueryInput;
|
|
136
|
-
export declare class DatomicDatabase {
|
|
85
|
+
export declare class AnyDBClient {
|
|
137
86
|
private client;
|
|
138
87
|
private storageAlias;
|
|
139
88
|
private dbName;
|
|
140
89
|
constructor(client: DatomicClient, storageAlias: string, dbName: string);
|
|
90
|
+
info(): Promise<DatabaseInfo>;
|
|
141
91
|
transact(txData: any[]): Promise<Transaction>;
|
|
142
|
-
|
|
143
|
-
|
|
92
|
+
query(q: SymbolicQuery, ...args: any[]): Promise<QueryResult>;
|
|
93
|
+
entity(entityId: EntityId, basisT?: BasisT, options?: {
|
|
94
|
+
"as-of"?: number;
|
|
95
|
+
since?: number;
|
|
96
|
+
}): Promise<Entity>;
|
|
97
|
+
datoms(index: "eavt" | "aevt" | "avet" | "vaet", options?: {
|
|
144
98
|
e?: EntityId;
|
|
145
|
-
a?:
|
|
99
|
+
a?: string;
|
|
146
100
|
v?: any;
|
|
147
101
|
start?: any;
|
|
148
102
|
end?: any;
|
|
@@ -152,16 +106,11 @@ export declare class DatomicDatabase {
|
|
|
152
106
|
since?: number;
|
|
153
107
|
history?: boolean;
|
|
154
108
|
}): Promise<Datom[]>;
|
|
155
|
-
entity(entityId: EntityId, basisT?: BasisT, options?: {
|
|
156
|
-
"as-of"?: number;
|
|
157
|
-
since?: number;
|
|
158
|
-
}): Promise<Entity>;
|
|
159
|
-
query(query: QueryInput, ...args: any[]): Promise<QueryResult>;
|
|
160
|
-
querySymbolic(query: SymbolicQuery, ...args: any[]): Promise<QueryResult>;
|
|
161
109
|
subscribeToEvents(onEvent: (event: MessageEvent) => void, onError?: (error: Event) => void): EventSource;
|
|
162
110
|
}
|
|
163
|
-
export declare function createDatomicClient(config:
|
|
164
|
-
export declare function
|
|
111
|
+
export declare function createDatomicClient(config: ClientConfig): DatomicClient;
|
|
112
|
+
export declare function createAnyDBClient(client: DatomicClient, storageAlias: string, dbName: string): AnyDBClient;
|
|
165
113
|
export declare function pluckFirstColumn(rows: any[][]): any[];
|
|
114
|
+
export { shouldUseDataScript, isDataScriptAvailable };
|
|
166
115
|
export default DatomicClient;
|
|
167
116
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,sBAAsB,CAAC;AAI9B,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,QAAQ,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,IAAI;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,GAAG,GAAI,MAAM,MAAM,KAAG,MAA4C,CAAC;AAChF,eAAO,MAAM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