@thingd/sdk 0.72.0 → 0.74.2
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/dist/__type-tests__/exports.d.ts +178 -0
- package/dist/__type-tests__/exports.d.ts.map +1 -0
- package/dist/__type-tests__/exports.js +87 -0
- package/dist/client/http-thing-store.d.ts +55 -0
- package/dist/client/http-thing-store.d.ts.map +1 -0
- package/dist/client/http-thing-store.js +233 -0
- package/dist/client/in-memory-thing-store.d.ts +41 -0
- package/dist/client/in-memory-thing-store.d.ts.map +1 -0
- package/dist/client/in-memory-thing-store.js +292 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +3 -0
- package/dist/client/thingd.d.ts +24 -0
- package/dist/client/thingd.d.ts.map +1 -0
- package/dist/client/thingd.js +27 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +3 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/mcp/audit.d.ts +27 -0
- package/dist/mcp/audit.d.ts.map +1 -0
- package/dist/mcp/audit.js +36 -0
- package/dist/mcp/config.d.ts +22 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +52 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +5 -0
- package/dist/mcp/result.d.ts +3 -0
- package/dist/mcp/result.d.ts.map +1 -0
- package/dist/mcp/result.js +10 -0
- package/dist/mcp/server.d.ts +19 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +51 -0
- package/dist/mcp/tools.d.ts +10 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +1033 -0
- package/dist/memory/index.d.ts +7 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +7 -0
- package/dist/rest/helpers.d.ts +17 -0
- package/dist/rest/helpers.d.ts.map +1 -0
- package/dist/rest/helpers.js +60 -0
- package/dist/rest/index.d.ts +3 -0
- package/dist/rest/index.d.ts.map +1 -0
- package/dist/rest/index.js +2 -0
- package/dist/rest/server.d.ts +4 -0
- package/dist/rest/server.d.ts.map +1 -0
- package/dist/rest/server.js +472 -0
- package/dist/scheduler.d.ts +28 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +451 -0
- package/dist/stores/cloud-thing-store.d.ts +60 -0
- package/dist/stores/cloud-thing-store.d.ts.map +1 -0
- package/dist/stores/cloud-thing-store.js +396 -0
- package/dist/stores/in-memory-thing-store.d.ts +59 -0
- package/dist/stores/in-memory-thing-store.d.ts.map +1 -0
- package/dist/stores/in-memory-thing-store.js +709 -0
- package/dist/stores/native-thing-store.d.ts +62 -0
- package/dist/stores/native-thing-store.d.ts.map +1 -0
- package/dist/stores/native-thing-store.js +374 -0
- package/dist/thingd.d.ts +84 -0
- package/dist/thingd.d.ts.map +1 -0
- package/dist/thingd.js +236 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types.d.ts +448 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/package.json +8 -7
- package/LICENSE +0 -201
package/dist/thingd.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { HttpThingStore } from "./client/http-thing-store.js";
|
|
2
|
+
import { Scheduler } from "./scheduler.js";
|
|
3
|
+
import { InMemoryThingStore } from "./stores/in-memory-thing-store.js";
|
|
4
|
+
import { NativeThingStore } from "./stores/native-thing-store.js";
|
|
5
|
+
export class ThingD {
|
|
6
|
+
path;
|
|
7
|
+
store;
|
|
8
|
+
static async open(pathOrConfig, options = {}) {
|
|
9
|
+
const resolvedOptions = resolveOpenOptions(pathOrConfig, options);
|
|
10
|
+
return new ThingD(resolvedOptions.path, await openStore(resolvedOptions.path, resolvedOptions));
|
|
11
|
+
}
|
|
12
|
+
scheduler;
|
|
13
|
+
constructor(path, store) {
|
|
14
|
+
this.path = path;
|
|
15
|
+
this.store = store;
|
|
16
|
+
this.scheduler = new Scheduler(store);
|
|
17
|
+
}
|
|
18
|
+
put(collection, object, options) {
|
|
19
|
+
return this.store.put(collection, object, options);
|
|
20
|
+
}
|
|
21
|
+
get(collection, id) {
|
|
22
|
+
return this.store.get(collection, id);
|
|
23
|
+
}
|
|
24
|
+
delete(collection, id) {
|
|
25
|
+
return this.store.delete(collection, id);
|
|
26
|
+
}
|
|
27
|
+
listObjects(collection, options) {
|
|
28
|
+
return this.store.listObjects?.(collection, options) ?? Promise.resolve([]);
|
|
29
|
+
}
|
|
30
|
+
search(query, options = {}) {
|
|
31
|
+
return this.store.search(query, options);
|
|
32
|
+
}
|
|
33
|
+
async searchObjects(query, options = {}) {
|
|
34
|
+
const results = await this.search(query, options);
|
|
35
|
+
return results
|
|
36
|
+
.filter((r) => r.kind === "object")
|
|
37
|
+
.map((r) => r.value);
|
|
38
|
+
}
|
|
39
|
+
vectorSearch(collection, queryVector, options = {}) {
|
|
40
|
+
return (this.store.vectorSearch?.(collection, queryVector, options) ??
|
|
41
|
+
Promise.reject(new Error("Vector search not supported by this driver")));
|
|
42
|
+
}
|
|
43
|
+
async putBatch(collection, objects) {
|
|
44
|
+
return (this.store.putBatch?.(collection, objects) ??
|
|
45
|
+
Promise.reject(new Error("Batch put not supported by this driver")));
|
|
46
|
+
}
|
|
47
|
+
async deleteBatch(collection, ids) {
|
|
48
|
+
return (this.store.deleteBatch?.(collection, ids) ??
|
|
49
|
+
Promise.reject(new Error("Batch delete not supported by this driver")));
|
|
50
|
+
}
|
|
51
|
+
async getBatch(collection, ids) {
|
|
52
|
+
return (this.store.getBatch?.(collection, ids) ??
|
|
53
|
+
Promise.reject(new Error("Batch get not supported by this driver")));
|
|
54
|
+
}
|
|
55
|
+
events = {
|
|
56
|
+
append: (stream, event) => this.store.appendEvent(stream, event),
|
|
57
|
+
list: (stream, options) => this.store.listEvents(stream, options),
|
|
58
|
+
};
|
|
59
|
+
queue(name) {
|
|
60
|
+
return {
|
|
61
|
+
push: (payload, options) => this.store.pushJob(name, payload, options),
|
|
62
|
+
claim: (options) => this.store.claimJob(name, options),
|
|
63
|
+
ack: (jobId) => this.store.ackJob(name, jobId),
|
|
64
|
+
nack: (jobId, options) => this.store.nackJob(name, jobId, options),
|
|
65
|
+
list: () => this.store.listJobs(name),
|
|
66
|
+
dead: () => this.store.listDeadJobs(name),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
links = {
|
|
70
|
+
create: (fromRef, linkType, toRef, weight, metadataJson) => this.store.createLink?.(fromRef, linkType, toRef, weight, metadataJson) ??
|
|
71
|
+
Promise.reject(new Error("Graph links not supported by this driver")),
|
|
72
|
+
delete: (id) => this.store.deleteLink?.(id) ?? Promise.resolve(false),
|
|
73
|
+
get: (id) => this.store.getLink?.(id) ?? Promise.resolve(null),
|
|
74
|
+
neighbors: (reference, direction = "Both", options = {}) => this.store.getNeighbors?.(reference, direction, options) ?? Promise.resolve([]),
|
|
75
|
+
};
|
|
76
|
+
aggregate = {
|
|
77
|
+
count: (collection, options = {}) => this.store.aggregate?.(collection, { ...options, function: "count" }) ??
|
|
78
|
+
Promise.reject(new Error("Aggregation not supported by this driver")),
|
|
79
|
+
sum: (collection, field, options = {}) => this.store.aggregate?.(collection, { ...options, function: "sum", field }) ??
|
|
80
|
+
Promise.reject(new Error("Aggregation not supported by this driver")),
|
|
81
|
+
avg: (collection, field, options = {}) => this.store.aggregate?.(collection, { ...options, function: "avg", field }) ??
|
|
82
|
+
Promise.reject(new Error("Aggregation not supported by this driver")),
|
|
83
|
+
min: (collection, field, options = {}) => this.store.aggregate?.(collection, { ...options, function: "min", field }) ??
|
|
84
|
+
Promise.reject(new Error("Aggregation not supported by this driver")),
|
|
85
|
+
max: (collection, field, options = {}) => this.store.aggregate?.(collection, { ...options, function: "max", field }) ??
|
|
86
|
+
Promise.reject(new Error("Aggregation not supported by this driver")),
|
|
87
|
+
};
|
|
88
|
+
timeseries(collection, options) {
|
|
89
|
+
return (this.store.timeseries?.(collection, options) ??
|
|
90
|
+
Promise.reject(new Error("Time-series aggregation not supported by this driver")));
|
|
91
|
+
}
|
|
92
|
+
async schema(collection, options) {
|
|
93
|
+
return (this.store.schema?.(collection, options) ??
|
|
94
|
+
Promise.reject(new Error("schema not supported by this driver")));
|
|
95
|
+
}
|
|
96
|
+
nlq = {
|
|
97
|
+
query: (question, options) => {
|
|
98
|
+
return (this.store.nlqQuery?.(question, options) ??
|
|
99
|
+
Promise.reject(new Error("NLQ not supported by this driver")));
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
async close() {
|
|
103
|
+
await this.store.close?.();
|
|
104
|
+
}
|
|
105
|
+
backupTo(path) {
|
|
106
|
+
if (this.store.backupTo) {
|
|
107
|
+
this.store.backupTo(path);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw new Error("Backup is only supported on the native durable storage driver");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
walCheckpoint() {
|
|
114
|
+
if (this.store.walCheckpoint) {
|
|
115
|
+
return this.store.walCheckpoint();
|
|
116
|
+
}
|
|
117
|
+
throw new Error("Checkpoint is only supported on the native durable storage driver");
|
|
118
|
+
}
|
|
119
|
+
async countObjects() {
|
|
120
|
+
return this.store.countObjects?.() ?? 0;
|
|
121
|
+
}
|
|
122
|
+
async countObjectsInCollection(collection) {
|
|
123
|
+
return this.store.countObjectsInCollection?.(collection) ?? 0;
|
|
124
|
+
}
|
|
125
|
+
async countEvents() {
|
|
126
|
+
return this.store.countEvents?.() ?? 0;
|
|
127
|
+
}
|
|
128
|
+
async countActiveJobs() {
|
|
129
|
+
return this.store.countActiveJobs?.() ?? 0;
|
|
130
|
+
}
|
|
131
|
+
async countDeadJobs() {
|
|
132
|
+
return this.store.countDeadJobs?.() ?? 0;
|
|
133
|
+
}
|
|
134
|
+
async countLinks() {
|
|
135
|
+
return this.store.countLinks?.() ?? 0;
|
|
136
|
+
}
|
|
137
|
+
async listCollections() {
|
|
138
|
+
return this.store.listCollections?.() ?? [];
|
|
139
|
+
}
|
|
140
|
+
async listStreams() {
|
|
141
|
+
return this.store.listStreams?.() ?? [];
|
|
142
|
+
}
|
|
143
|
+
async listQueues() {
|
|
144
|
+
return this.store.listQueues?.() ?? [];
|
|
145
|
+
}
|
|
146
|
+
/** Create a functional index on a JSON body field for a collection. */
|
|
147
|
+
async createIndex(collection, field) {
|
|
148
|
+
await this.store.createIndex?.(collection, field);
|
|
149
|
+
}
|
|
150
|
+
/** List all custom functional indexes. */
|
|
151
|
+
async listIndexes() {
|
|
152
|
+
return this.store.listIndexes?.() ?? [];
|
|
153
|
+
}
|
|
154
|
+
/** List available connector types. Requires sidecar/HTTP store (returns [] for in-memory/native). */
|
|
155
|
+
async listConnectors() {
|
|
156
|
+
return this.store.listConnectors?.() ?? [];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Discover the schema of an external table or file source.
|
|
160
|
+
* Requires sidecar/HTTP store — throws on in-memory/native stores.
|
|
161
|
+
*/
|
|
162
|
+
async discoverConnectorSchema(type, query, auth) {
|
|
163
|
+
const result = await this.store.discoverConnectorSchema?.(type, query, auth);
|
|
164
|
+
if (!result) {
|
|
165
|
+
throw new Error(`Connector '${type}' not supported by this store`);
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Import data from an external source into a thingd collection.
|
|
171
|
+
* Requires sidecar/HTTP store — throws on in-memory/native stores.
|
|
172
|
+
*/
|
|
173
|
+
async connectorSync(type, options) {
|
|
174
|
+
const result = await this.store.connectorSync?.(type, options);
|
|
175
|
+
if (!result) {
|
|
176
|
+
throw new Error(`Connector '${type}' not supported by this store`);
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function resolveOpenOptions(pathOrConfig, options) {
|
|
182
|
+
const config = typeof pathOrConfig === "string"
|
|
183
|
+
? {
|
|
184
|
+
path: pathOrConfig,
|
|
185
|
+
}
|
|
186
|
+
: (pathOrConfig ?? {});
|
|
187
|
+
const path = config.url ?? config.path ?? process.env.THINGD_URL ?? ":memory:";
|
|
188
|
+
const driver = options.driver ?? config.driver ?? inferDriver(path);
|
|
189
|
+
return {
|
|
190
|
+
...config,
|
|
191
|
+
...options,
|
|
192
|
+
path,
|
|
193
|
+
driver,
|
|
194
|
+
authToken: options.authToken ??
|
|
195
|
+
config.authToken ??
|
|
196
|
+
config.apiKey ??
|
|
197
|
+
options.apiKey ??
|
|
198
|
+
process.env.THINGD_AUTH_TOKEN,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function inferDriver(path) {
|
|
202
|
+
if (isCloudPath(path)) {
|
|
203
|
+
return "cloud";
|
|
204
|
+
}
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
function isCloudPath(path) {
|
|
208
|
+
return path.startsWith("http://") || path.startsWith("https://") || path.startsWith("thingd://");
|
|
209
|
+
}
|
|
210
|
+
async function openStore(path, options) {
|
|
211
|
+
if (options.store) {
|
|
212
|
+
return options.store;
|
|
213
|
+
}
|
|
214
|
+
if (options.driver === "cloud") {
|
|
215
|
+
return HttpThingStore.open({
|
|
216
|
+
url: path,
|
|
217
|
+
authToken: options.authToken,
|
|
218
|
+
instanceSlug: options.instanceSlug,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
const hasNative = await NativeThingStore.isAvailable();
|
|
222
|
+
if (options.driver === "native") {
|
|
223
|
+
if (!hasNative) {
|
|
224
|
+
throw new Error(`The native thingd driver is not available. Install @thingd/native with "npm install @thingd/native". For monorepo development: "pnpm --filter thingd-native build".`);
|
|
225
|
+
}
|
|
226
|
+
return NativeThingStore.open(path);
|
|
227
|
+
}
|
|
228
|
+
// Auto-detect and promote file paths to native store when available, with a warning fallback to memory.
|
|
229
|
+
if (!options.driver && path !== ":memory:") {
|
|
230
|
+
if (hasNative) {
|
|
231
|
+
return NativeThingStore.open(path);
|
|
232
|
+
}
|
|
233
|
+
console.warn(`Warning: The native thingd driver is not available. Falling back to the temporary in-memory store. Data will not persist. Run "pnpm --filter @thingd/native build" or install "@thingd/native" to enable native persistence.`);
|
|
234
|
+
}
|
|
235
|
+
return new InMemoryThingStore();
|
|
236
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { AggregateFunction, AggregateGroupResult, AggregateOptions, AggregateResult, BackupCapableThingStore, CollectionSchema, ConnectorAuth, ConnectorSchema, ConnectorSyncOptions, ConnectorSyncResult, FieldSchema, FilterOperator, Link, LinkDirection, LinkQueryOptions, ListEventsOptions, ListObjectsOptions, LocalThingDConnection, MemoryEvent, MemoryObject, MemoryQueue, MemorySearchOptions, MemorySearchResult, NlqIntent, NlqOptions, NlqResult, PutOptions, QueueClaimOptions, QueueJob, QueueJobOptions, QueueJobPayload, QueueJobResult, QueueJobStatus, QueueNackOptions, ReconnectableThingStore, SchemaOptions, SortBy, SortDirection, StoredMemoryEvent, StoredMemoryObject, ThingDConnection, ThingDeleteResult, ThingStore, TimeBucket, TimeSeriesBucket, TimeSeriesOptions, TimeSeriesResult, VectorSearchHit, VectorSearchOptions, WalCheckpointResult, } from "../types.js";
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,IAAI,EACJ,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
export type MemoryObject = {
|
|
2
|
+
id: string;
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
};
|
|
5
|
+
export type StoredMemoryObject = MemoryObject & {
|
|
6
|
+
collection: string;
|
|
7
|
+
createdAt: string;
|
|
8
|
+
updatedAt: string;
|
|
9
|
+
version: number;
|
|
10
|
+
};
|
|
11
|
+
export type MemoryEvent = {
|
|
12
|
+
type: string;
|
|
13
|
+
text?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
export type StoredMemoryEvent = MemoryEvent & {
|
|
17
|
+
id: string;
|
|
18
|
+
stream: string;
|
|
19
|
+
sequence: number;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
idempotencyKey?: string;
|
|
22
|
+
};
|
|
23
|
+
export type QueueJobPayload = Record<string, unknown>;
|
|
24
|
+
export type QueueJobStatus = "ready" | "leased" | "completed" | "dead";
|
|
25
|
+
export type QueueJob = {
|
|
26
|
+
id: string;
|
|
27
|
+
queue: string;
|
|
28
|
+
payload: QueueJobPayload;
|
|
29
|
+
status: QueueJobStatus;
|
|
30
|
+
attempts: number;
|
|
31
|
+
maxAttempts: number;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
availableAt: string;
|
|
34
|
+
leasedAt?: string;
|
|
35
|
+
leaseExpiresAt?: string;
|
|
36
|
+
completedAt?: string;
|
|
37
|
+
deadAt?: string;
|
|
38
|
+
lastError?: string;
|
|
39
|
+
/** Priority for claim ordering (higher = claimed sooner). Default: 0. */
|
|
40
|
+
priority?: number;
|
|
41
|
+
};
|
|
42
|
+
export type QueueJobOptions = {
|
|
43
|
+
idempotencyKey?: string;
|
|
44
|
+
maxAttempts?: number;
|
|
45
|
+
delayMs?: number;
|
|
46
|
+
/** Priority for claim ordering (higher = claimed sooner). Default: 0. */
|
|
47
|
+
priority?: number;
|
|
48
|
+
};
|
|
49
|
+
export type QueueClaimOptions = {
|
|
50
|
+
leaseMs?: number;
|
|
51
|
+
};
|
|
52
|
+
export type QueueNackOptions = {
|
|
53
|
+
delayMs?: number;
|
|
54
|
+
error?: string;
|
|
55
|
+
};
|
|
56
|
+
export type QueueJobResult = {
|
|
57
|
+
ok: true;
|
|
58
|
+
job: QueueJob;
|
|
59
|
+
} | {
|
|
60
|
+
ok: false;
|
|
61
|
+
reason: "not_found" | "not_leased" | "terminal";
|
|
62
|
+
};
|
|
63
|
+
export type ThingDeleteResult = {
|
|
64
|
+
deleted: boolean;
|
|
65
|
+
};
|
|
66
|
+
export type WalCheckpointResult = {
|
|
67
|
+
framesBefore: number;
|
|
68
|
+
framesAfter: number;
|
|
69
|
+
};
|
|
70
|
+
export interface ReconnectableThingStore {
|
|
71
|
+
reconnect(): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
export interface BackupCapableThingStore {
|
|
74
|
+
backupTo(path: string): void;
|
|
75
|
+
walCheckpoint(): WalCheckpointResult;
|
|
76
|
+
}
|
|
77
|
+
export type MemorySearchOptions = {
|
|
78
|
+
collections?: string[];
|
|
79
|
+
limit?: number;
|
|
80
|
+
filter?: Record<string, unknown>;
|
|
81
|
+
};
|
|
82
|
+
export type MemorySearchResult = {
|
|
83
|
+
kind: "object";
|
|
84
|
+
id: string;
|
|
85
|
+
collection: string;
|
|
86
|
+
score: number;
|
|
87
|
+
value: StoredMemoryObject;
|
|
88
|
+
} | {
|
|
89
|
+
kind: "event";
|
|
90
|
+
id: string;
|
|
91
|
+
stream: string;
|
|
92
|
+
score: number;
|
|
93
|
+
value: StoredMemoryEvent;
|
|
94
|
+
};
|
|
95
|
+
export type VectorSearchOptions = {
|
|
96
|
+
topK?: number;
|
|
97
|
+
filter?: Record<string, unknown>;
|
|
98
|
+
};
|
|
99
|
+
export type VectorSearchHit = {
|
|
100
|
+
id: string;
|
|
101
|
+
score: number;
|
|
102
|
+
value: StoredMemoryObject;
|
|
103
|
+
};
|
|
104
|
+
export type LinkDirection = "Outgoing" | "Incoming" | "Both";
|
|
105
|
+
export type LinkQueryOptions = {
|
|
106
|
+
linkType?: string;
|
|
107
|
+
limit?: number;
|
|
108
|
+
};
|
|
109
|
+
export type Link = {
|
|
110
|
+
id: string;
|
|
111
|
+
fromRef: string;
|
|
112
|
+
linkType: string;
|
|
113
|
+
toRef: string;
|
|
114
|
+
weight?: number;
|
|
115
|
+
metadataJson: string;
|
|
116
|
+
createdAt: string;
|
|
117
|
+
};
|
|
118
|
+
export type ConnectorAuth = {
|
|
119
|
+
host: string;
|
|
120
|
+
port: number;
|
|
121
|
+
database: string;
|
|
122
|
+
username: string;
|
|
123
|
+
password: string;
|
|
124
|
+
sslMode?: "disable" | "prefer" | "require";
|
|
125
|
+
};
|
|
126
|
+
export type ConnectorSchema = {
|
|
127
|
+
name: string;
|
|
128
|
+
columns: {
|
|
129
|
+
name: string;
|
|
130
|
+
dataType: "text" | "integer" | "float" | "boolean" | "timestamp" | "json" | "unknown";
|
|
131
|
+
nullable: boolean;
|
|
132
|
+
sampleValues: unknown[];
|
|
133
|
+
}[];
|
|
134
|
+
estimatedRows: number | null;
|
|
135
|
+
};
|
|
136
|
+
export type ConnectorSyncResult = {
|
|
137
|
+
imported: number;
|
|
138
|
+
collection: string;
|
|
139
|
+
};
|
|
140
|
+
export type ConnectorSyncOptions = {
|
|
141
|
+
auth?: ConnectorAuth;
|
|
142
|
+
source?: string;
|
|
143
|
+
collection: string;
|
|
144
|
+
query: string;
|
|
145
|
+
batchSize?: number;
|
|
146
|
+
columnMapping?: Record<string, string>;
|
|
147
|
+
syncStrategy?: "full" | "incremental";
|
|
148
|
+
};
|
|
149
|
+
export type MemoryQueue = {
|
|
150
|
+
push(payload: QueueJobPayload, options?: QueueJobOptions): Promise<QueueJob>;
|
|
151
|
+
claim(options?: QueueClaimOptions): Promise<QueueJob | null>;
|
|
152
|
+
ack(jobId: string): Promise<QueueJobResult>;
|
|
153
|
+
nack(jobId: string, options?: QueueNackOptions): Promise<QueueJobResult>;
|
|
154
|
+
list(): Promise<QueueJob[]>;
|
|
155
|
+
dead(): Promise<QueueJob[]>;
|
|
156
|
+
};
|
|
157
|
+
export type ListEventsOptions = {
|
|
158
|
+
fromSequence?: number;
|
|
159
|
+
limit?: number;
|
|
160
|
+
since?: string;
|
|
161
|
+
};
|
|
162
|
+
export type SortDirection = "asc" | "desc";
|
|
163
|
+
export type SortBy = {
|
|
164
|
+
/** Column name or JSON path like "$.price" for body field sorting */
|
|
165
|
+
field: string;
|
|
166
|
+
direction?: SortDirection;
|
|
167
|
+
};
|
|
168
|
+
export type FilterOperator = {
|
|
169
|
+
$gt?: unknown;
|
|
170
|
+
$gte?: unknown;
|
|
171
|
+
$lt?: unknown;
|
|
172
|
+
$lte?: unknown;
|
|
173
|
+
$ne?: unknown;
|
|
174
|
+
$in?: unknown[];
|
|
175
|
+
$like?: string;
|
|
176
|
+
};
|
|
177
|
+
export type ListObjectsOptions = {
|
|
178
|
+
limit?: number;
|
|
179
|
+
offset?: number;
|
|
180
|
+
filter?: Record<string, unknown | FilterOperator>;
|
|
181
|
+
sortBy?: SortBy;
|
|
182
|
+
};
|
|
183
|
+
export type PutOptions = {
|
|
184
|
+
/** Optional expected version for optimistic locking (CAS). */
|
|
185
|
+
expectedVersion?: number;
|
|
186
|
+
};
|
|
187
|
+
export type AggregateFunction = "count" | "sum" | "avg" | "min" | "max";
|
|
188
|
+
export type AggregateOptions = {
|
|
189
|
+
function: AggregateFunction;
|
|
190
|
+
field?: string;
|
|
191
|
+
groupBy?: string;
|
|
192
|
+
filter?: Record<string, unknown>;
|
|
193
|
+
};
|
|
194
|
+
export type AggregateGroupResult = {
|
|
195
|
+
key: string;
|
|
196
|
+
value: number;
|
|
197
|
+
};
|
|
198
|
+
export type AggregateResult = {
|
|
199
|
+
total: number;
|
|
200
|
+
groups: AggregateGroupResult[];
|
|
201
|
+
};
|
|
202
|
+
export type TimeBucket = "hour" | "day" | "week" | "month";
|
|
203
|
+
export type TimeSeriesOptions = {
|
|
204
|
+
function: AggregateFunction;
|
|
205
|
+
field?: string;
|
|
206
|
+
bucket: TimeBucket;
|
|
207
|
+
from?: string;
|
|
208
|
+
to?: string;
|
|
209
|
+
filter?: Record<string, unknown>;
|
|
210
|
+
};
|
|
211
|
+
export type TimeSeriesBucket = {
|
|
212
|
+
label: string;
|
|
213
|
+
value: number;
|
|
214
|
+
};
|
|
215
|
+
export type TimeSeriesResult = {
|
|
216
|
+
buckets: TimeSeriesBucket[];
|
|
217
|
+
};
|
|
218
|
+
export type FieldSchema = {
|
|
219
|
+
name: string;
|
|
220
|
+
type: string;
|
|
221
|
+
nullable: boolean;
|
|
222
|
+
sampleValues: unknown[];
|
|
223
|
+
};
|
|
224
|
+
export type CollectionSchema = {
|
|
225
|
+
name: string;
|
|
226
|
+
objectCount: number;
|
|
227
|
+
fields: FieldSchema[];
|
|
228
|
+
};
|
|
229
|
+
export type SchemaOptions = {
|
|
230
|
+
sampleSize?: number;
|
|
231
|
+
};
|
|
232
|
+
export type NlqIntent = {
|
|
233
|
+
action: string;
|
|
234
|
+
collection: string;
|
|
235
|
+
function?: string;
|
|
236
|
+
field?: string;
|
|
237
|
+
groupBy?: string;
|
|
238
|
+
bucket?: string;
|
|
239
|
+
query?: string;
|
|
240
|
+
limit?: number;
|
|
241
|
+
};
|
|
242
|
+
export type NlqResult = {
|
|
243
|
+
answer: string;
|
|
244
|
+
data: unknown;
|
|
245
|
+
intent: NlqIntent;
|
|
246
|
+
};
|
|
247
|
+
export type NlqOptions = {
|
|
248
|
+
collection?: string;
|
|
249
|
+
model?: string;
|
|
250
|
+
endpoint?: string;
|
|
251
|
+
apiKey?: string;
|
|
252
|
+
};
|
|
253
|
+
export type Schedule = {
|
|
254
|
+
id: string;
|
|
255
|
+
expression: string;
|
|
256
|
+
timezone?: string;
|
|
257
|
+
payload: Record<string, unknown>;
|
|
258
|
+
enabled: boolean;
|
|
259
|
+
nextRunAt: string;
|
|
260
|
+
lastRunAt?: string;
|
|
261
|
+
lastStatus?: "completed" | "failed" | "running";
|
|
262
|
+
lastError?: string;
|
|
263
|
+
lastDurationMs?: number;
|
|
264
|
+
runCount: number;
|
|
265
|
+
failCount: number;
|
|
266
|
+
consecutiveFails: number;
|
|
267
|
+
maxConsecutiveFails: number;
|
|
268
|
+
createdAt: string;
|
|
269
|
+
updatedAt: string;
|
|
270
|
+
metadata?: Record<string, unknown>;
|
|
271
|
+
};
|
|
272
|
+
export type ScheduleHandler = (schedule: Schedule, context: ScheduleContext) => Promise<void>;
|
|
273
|
+
export type ScheduleContext = {
|
|
274
|
+
log: (message: string) => void;
|
|
275
|
+
fail: (error: string) => void;
|
|
276
|
+
};
|
|
277
|
+
export type ScheduleOptions = {
|
|
278
|
+
expression?: string;
|
|
279
|
+
intervalMs?: number;
|
|
280
|
+
timezone?: string;
|
|
281
|
+
payload?: Record<string, unknown>;
|
|
282
|
+
enabled?: boolean;
|
|
283
|
+
maxConsecutiveFails?: number;
|
|
284
|
+
metadata?: Record<string, unknown>;
|
|
285
|
+
handler: ScheduleHandler;
|
|
286
|
+
};
|
|
287
|
+
export type ScheduleOnceOptions = {
|
|
288
|
+
runAt: string;
|
|
289
|
+
payload?: Record<string, unknown>;
|
|
290
|
+
metadata?: Record<string, unknown>;
|
|
291
|
+
handler: ScheduleHandler;
|
|
292
|
+
};
|
|
293
|
+
export type ScheduleIntervalOptions = {
|
|
294
|
+
intervalMs: number;
|
|
295
|
+
payload?: Record<string, unknown>;
|
|
296
|
+
enabled?: boolean;
|
|
297
|
+
maxConsecutiveFails?: number;
|
|
298
|
+
metadata?: Record<string, unknown>;
|
|
299
|
+
handler: ScheduleHandler;
|
|
300
|
+
};
|
|
301
|
+
export type ScheduleEvent = {
|
|
302
|
+
scheduleId: string;
|
|
303
|
+
expression: string;
|
|
304
|
+
status: "started" | "completed" | "failed" | "disabled";
|
|
305
|
+
timestamp: string;
|
|
306
|
+
durationMs?: number;
|
|
307
|
+
error?: string;
|
|
308
|
+
runCount: number;
|
|
309
|
+
failCount: number;
|
|
310
|
+
};
|
|
311
|
+
export type SchedulerStats = {
|
|
312
|
+
total: number;
|
|
313
|
+
enabled: number;
|
|
314
|
+
disabled: number;
|
|
315
|
+
running: number;
|
|
316
|
+
nextRun: {
|
|
317
|
+
id: string;
|
|
318
|
+
at: string;
|
|
319
|
+
} | null;
|
|
320
|
+
};
|
|
321
|
+
export type SchedulerEventType = "started" | "completed" | "failed" | "disabled";
|
|
322
|
+
export type SchedulerListener = (event: ScheduleEvent) => void;
|
|
323
|
+
export type SchedulerFacade = {
|
|
324
|
+
schedule(id: string, options: ScheduleOptions): Promise<Schedule>;
|
|
325
|
+
scheduleOnce(id: string, options: ScheduleOnceOptions): Promise<Schedule>;
|
|
326
|
+
scheduleInterval(id: string, options: ScheduleIntervalOptions): Promise<Schedule>;
|
|
327
|
+
get(id: string): Promise<Schedule | null>;
|
|
328
|
+
list(): Promise<Schedule[]>;
|
|
329
|
+
pause(id: string): Promise<Schedule>;
|
|
330
|
+
resume(id: string): Promise<Schedule>;
|
|
331
|
+
remove(id: string): Promise<boolean>;
|
|
332
|
+
run(id: string): Promise<void>;
|
|
333
|
+
stats(): Promise<SchedulerStats>;
|
|
334
|
+
start(): Promise<void>;
|
|
335
|
+
stop(): Promise<void>;
|
|
336
|
+
on(event: SchedulerEventType, listener: SchedulerListener): void;
|
|
337
|
+
off(event: SchedulerEventType, listener: SchedulerListener): void;
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* Typed interface for a thingd database connection returned by `ThingD.open()`.
|
|
341
|
+
* Consumers can use this for type-safe dependency injection instead of `any`:
|
|
342
|
+
*
|
|
343
|
+
* ```ts
|
|
344
|
+
* import type { ThingDConnection } from "@thingd/sdk";
|
|
345
|
+
* private readonly db: ThingDConnection;
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
export interface ThingDConnection {
|
|
349
|
+
put(collection: string, object: MemoryObject, options?: PutOptions): Promise<StoredMemoryObject>;
|
|
350
|
+
get<T = StoredMemoryObject>(collection: string, id: string): Promise<T | null>;
|
|
351
|
+
delete(collection: string, id: string): Promise<ThingDeleteResult>;
|
|
352
|
+
listObjects<T = StoredMemoryObject>(collection: string, options?: ListObjectsOptions): Promise<T[]>;
|
|
353
|
+
search(query: string, options?: MemorySearchOptions): Promise<MemorySearchResult[]>;
|
|
354
|
+
searchObjects<T = StoredMemoryObject>(query: string, options?: MemorySearchOptions): Promise<T[]>;
|
|
355
|
+
putBatch(collection: string, objects: MemoryObject[]): Promise<StoredMemoryObject[]>;
|
|
356
|
+
deleteBatch(collection: string, ids: string[]): Promise<number>;
|
|
357
|
+
getBatch<T = StoredMemoryObject>(collection: string, ids: string[]): Promise<(T | null)[]>;
|
|
358
|
+
readonly events: {
|
|
359
|
+
append(stream: string, event: MemoryEvent): Promise<StoredMemoryEvent>;
|
|
360
|
+
list<T = StoredMemoryEvent>(stream?: string, options?: ListEventsOptions): Promise<T[]>;
|
|
361
|
+
};
|
|
362
|
+
queue(name: string): MemoryQueue;
|
|
363
|
+
close(): Promise<void>;
|
|
364
|
+
countObjects(): Promise<number>;
|
|
365
|
+
countObjectsInCollection(collection: string): Promise<number>;
|
|
366
|
+
countEvents(): Promise<number>;
|
|
367
|
+
countActiveJobs(): Promise<number>;
|
|
368
|
+
countDeadJobs(): Promise<number>;
|
|
369
|
+
countLinks(): Promise<number>;
|
|
370
|
+
readonly links: {
|
|
371
|
+
create(fromRef: string, linkType: string, toRef: string, weight?: number, metadataJson?: string): Promise<Link>;
|
|
372
|
+
delete(id: string): Promise<boolean>;
|
|
373
|
+
get(id: string): Promise<Link | null>;
|
|
374
|
+
neighbors(reference: string, direction?: LinkDirection, options?: LinkQueryOptions): Promise<Link[]>;
|
|
375
|
+
};
|
|
376
|
+
listCollections(): Promise<string[]>;
|
|
377
|
+
listStreams(): Promise<string[]>;
|
|
378
|
+
listQueues(): Promise<string[]>;
|
|
379
|
+
createIndex(collection: string, field: string): Promise<void>;
|
|
380
|
+
listIndexes(): Promise<Array<[string, string]>>;
|
|
381
|
+
listConnectors(): Promise<string[]>;
|
|
382
|
+
discoverConnectorSchema(type: string, query: string, auth?: ConnectorAuth): Promise<ConnectorSchema>;
|
|
383
|
+
connectorSync(type: string, options: ConnectorSyncOptions): Promise<ConnectorSyncResult>;
|
|
384
|
+
schema(collection?: string, options?: SchemaOptions): Promise<CollectionSchema[]>;
|
|
385
|
+
readonly nlq: {
|
|
386
|
+
query(question: string, options?: NlqOptions): Promise<NlqResult>;
|
|
387
|
+
};
|
|
388
|
+
readonly scheduler: SchedulerFacade;
|
|
389
|
+
readonly aggregate: {
|
|
390
|
+
count(collection: string, options?: Omit<AggregateOptions, "function">): Promise<AggregateResult>;
|
|
391
|
+
sum(collection: string, field: string, options?: Omit<AggregateOptions, "function" | "field">): Promise<AggregateResult>;
|
|
392
|
+
avg(collection: string, field: string, options?: Omit<AggregateOptions, "function" | "field">): Promise<AggregateResult>;
|
|
393
|
+
min(collection: string, field: string, options?: Omit<AggregateOptions, "function" | "field">): Promise<AggregateResult>;
|
|
394
|
+
max(collection: string, field: string, options?: Omit<AggregateOptions, "function" | "field">): Promise<AggregateResult>;
|
|
395
|
+
};
|
|
396
|
+
timeseries(collection: string, options: TimeSeriesOptions): Promise<TimeSeriesResult>;
|
|
397
|
+
vectorSearch(collection: string, queryVector: number[], options?: VectorSearchOptions): Promise<VectorSearchHit[]>;
|
|
398
|
+
}
|
|
399
|
+
/** Local-driver connection capabilities unavailable on cloud/browser stores. */
|
|
400
|
+
export interface LocalThingDConnection extends ThingDConnection {
|
|
401
|
+
backupTo(path: string): void;
|
|
402
|
+
walCheckpoint(): WalCheckpointResult;
|
|
403
|
+
}
|
|
404
|
+
export interface ThingStore {
|
|
405
|
+
put(collection: string, object: MemoryObject, options?: PutOptions): Promise<StoredMemoryObject>;
|
|
406
|
+
get<T = StoredMemoryObject>(collection: string, id: string): Promise<T | null>;
|
|
407
|
+
delete(collection: string, id: string): Promise<ThingDeleteResult>;
|
|
408
|
+
listObjects<T = StoredMemoryObject>(collection: string, options?: ListObjectsOptions): Promise<T[]>;
|
|
409
|
+
appendEvent(stream: string, event: MemoryEvent): Promise<StoredMemoryEvent>;
|
|
410
|
+
listEvents<T = StoredMemoryEvent>(stream?: string, options?: ListEventsOptions): Promise<T[]>;
|
|
411
|
+
pushJob(queue: string, payload: QueueJobPayload, options?: QueueJobOptions): Promise<QueueJob>;
|
|
412
|
+
claimJob(queue: string, options?: QueueClaimOptions): Promise<QueueJob | null>;
|
|
413
|
+
ackJob(queue: string, jobId: string): Promise<QueueJobResult>;
|
|
414
|
+
nackJob(queue: string, jobId: string, options?: QueueNackOptions): Promise<QueueJobResult>;
|
|
415
|
+
listJobs(queue: string): Promise<QueueJob[]>;
|
|
416
|
+
listDeadJobs(queue: string): Promise<QueueJob[]>;
|
|
417
|
+
search(query: string, options?: MemorySearchOptions): Promise<MemorySearchResult[]>;
|
|
418
|
+
countObjects?(): Promise<number>;
|
|
419
|
+
countObjectsInCollection?(collection: string): Promise<number>;
|
|
420
|
+
countEvents?(): Promise<number>;
|
|
421
|
+
countActiveJobs?(): Promise<number>;
|
|
422
|
+
countDeadJobs?(): Promise<number>;
|
|
423
|
+
countLinks?(): Promise<number>;
|
|
424
|
+
createLink?(fromRef: string, linkType: string, toRef: string, weight?: number, metadataJson?: string): Promise<Link>;
|
|
425
|
+
deleteLink?(id: string): Promise<boolean>;
|
|
426
|
+
getLink?(id: string): Promise<Link | null>;
|
|
427
|
+
getNeighbors?(reference: string, direction: LinkDirection, options: LinkQueryOptions): Promise<Link[]>;
|
|
428
|
+
putBatch?(collection: string, objects: MemoryObject[]): Promise<StoredMemoryObject[]>;
|
|
429
|
+
deleteBatch?(collection: string, ids: string[]): Promise<number>;
|
|
430
|
+
getBatch?(collection: string, ids: string[]): Promise<(StoredMemoryObject | null)[]>;
|
|
431
|
+
listCollections?(): Promise<string[]>;
|
|
432
|
+
listStreams?(): Promise<string[]>;
|
|
433
|
+
listQueues?(): Promise<string[]>;
|
|
434
|
+
createIndex?(collection: string, field: string): Promise<void>;
|
|
435
|
+
listIndexes?(): Promise<Array<[string, string]>>;
|
|
436
|
+
listConnectors?(): Promise<string[]>;
|
|
437
|
+
discoverConnectorSchema?(type: string, query: string, auth?: ConnectorAuth): Promise<ConnectorSchema>;
|
|
438
|
+
connectorSync?(type: string, options: ConnectorSyncOptions): Promise<ConnectorSyncResult>;
|
|
439
|
+
aggregate?(collection: string, options: AggregateOptions): Promise<AggregateResult>;
|
|
440
|
+
timeseries?(collection: string, options: TimeSeriesOptions): Promise<TimeSeriesResult>;
|
|
441
|
+
schema?(collection?: string, options?: SchemaOptions): Promise<CollectionSchema[]>;
|
|
442
|
+
nlqQuery?(question: string, options?: NlqOptions): Promise<NlqResult>;
|
|
443
|
+
vectorSearch?(collection: string, queryVector: number[], options?: VectorSearchOptions): Promise<VectorSearchHit[]>;
|
|
444
|
+
close?(): Promise<void>;
|
|
445
|
+
backupTo?(path: string): void;
|
|
446
|
+
walCheckpoint?(): WalCheckpointResult;
|
|
447
|
+
}
|
|
448
|
+
//# sourceMappingURL=types.d.ts.map
|