xmemory 2.2.1 → 2.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 +28 -1
- package/dist/index.d.ts +1 -0
- package/dist/instance.js +11 -0
- package/dist/types.d.ts +22 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -152,7 +152,34 @@ const result = await inst.read("Who is on the team?");
|
|
|
152
152
|
console.log(result.reader_result);
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
Options: `{ readMode?, traceId?, timeoutMs? }` — `readMode` defaults to `"single-answer"`.
|
|
155
|
+
Options: `{ readMode?, scope?, traceId?, timeoutMs? }` — `readMode` defaults to `"single-answer"`.
|
|
156
|
+
|
|
157
|
+
#### Scoped reads
|
|
158
|
+
|
|
159
|
+
By default a read may draw on the whole instance. Pass a `scope` to restrict it
|
|
160
|
+
to a set of concrete objects — useful for grounding an answer in exactly the
|
|
161
|
+
records you care about, or for keeping a per-user / per-entity read from leaking
|
|
162
|
+
into unrelated data.
|
|
163
|
+
|
|
164
|
+
Each object in the scope is identified by its `type` (the PascalCase class name
|
|
165
|
+
or snake_case table name) plus its user-defined primary `key` (a mapping of
|
|
166
|
+
primary-key field name to value):
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const result = await inst.read("What do we know about these people?", {
|
|
170
|
+
scope: {
|
|
171
|
+
objects: [
|
|
172
|
+
{ type: "Person", key: { full_name: "Alice Smith" } },
|
|
173
|
+
{ type: "Person", key: { full_name: "Bob Jones" } },
|
|
174
|
+
],
|
|
175
|
+
relationsScope: "all_relations", // default: "no_relations"
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
`relationsScope` controls relation traversal: `"no_relations"` (the default)
|
|
181
|
+
restricts the read to the listed objects only, while `"all_relations"` also
|
|
182
|
+
exposes the relations among the in-scope objects.
|
|
156
183
|
|
|
157
184
|
### `inst.extract(text, options?)` → `ExtractResult`
|
|
158
185
|
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { DescribeResult, InstanceHandle } from "./instance.js";
|
|
|
7
7
|
export { XmemoryAPIError, XmemoryHealthCheckError } from "./types.js";
|
|
8
8
|
export { SchemaType } from "./types.js";
|
|
9
9
|
export type { SchemaTypeValue, ExtractionLogic, ReadMode, WriteQueueStatus, FieldType, OnDelete, CastStrategy, DecisionKind, MigrationSource, } from "./types.js";
|
|
10
|
+
export type { ScopeObject, ReadScope, RelationsScope } from "./types.js";
|
|
10
11
|
export type { XmemoryClientOptions, RequestOptions, ReadOptions, WriteOptions, ExtractOptions, CreateInstanceOptions, GenerateSchemaOptions, UpdateInstanceSchemaOptions, DryRunMigrationOptions, ListMigrationsOptions, GetMigrationOptions, SuggestionRequestOptions, } from "./types.js";
|
|
11
12
|
export type { ClusterInfo, InstanceInfo, InstanceSchemaInfo, ReadResult, WriteResult, AsyncWriteResult, WriteStatusResult, ExtractResult, GenerateSchemaResult, ToolDescription, ToolParameterDescription, RawDescribeResult, } from "./types.js";
|
|
12
13
|
export type { MigrationPlan, MigrationOp, FieldSpec, AddObject, RemoveObject, RenameObject, ChangeObject, AddField, RemoveField, RenameField, ChangeField, AddRelation, RemoveRelation, RenameRelation, ChangeRelation, DefaultValue, EnumValues, } from "./types.js";
|
package/dist/instance.js
CHANGED
|
@@ -109,6 +109,17 @@ export class InstanceHandle {
|
|
|
109
109
|
query,
|
|
110
110
|
mode: options?.readMode ?? "single-answer",
|
|
111
111
|
};
|
|
112
|
+
if (options?.scope != null) {
|
|
113
|
+
// Serialize to the API's identity wire shape: each object is
|
|
114
|
+
// `{type, key: {key: {...}}}` (by user-defined primary key), plus `relations_scope`.
|
|
115
|
+
body.scope = {
|
|
116
|
+
objects: options.scope.objects.map((o) => ({
|
|
117
|
+
type: o.type,
|
|
118
|
+
key: { key: o.key },
|
|
119
|
+
})),
|
|
120
|
+
relations_scope: options.scope.relationsScope ?? "no_relations",
|
|
121
|
+
};
|
|
122
|
+
}
|
|
112
123
|
if (options?.traceId != null)
|
|
113
124
|
body.trace_id = options.traceId;
|
|
114
125
|
return this._requestOne("POST", `/instances/${this.id}/read`, {
|
package/dist/types.d.ts
CHANGED
|
@@ -8,6 +8,26 @@ export declare const SchemaType: {
|
|
|
8
8
|
export type SchemaTypeValue = (typeof SchemaType)[keyof typeof SchemaType];
|
|
9
9
|
export type ExtractionLogic = "fast" | "regular" | "deep";
|
|
10
10
|
export type ReadMode = "single-answer" | "raw-tables" | "xresponse";
|
|
11
|
+
/**
|
|
12
|
+
* One concrete object a scoped read may touch. Identify it by `type` (PascalCase
|
|
13
|
+
* class name or snake_case table name) plus its user-defined primary `key`
|
|
14
|
+
* (a mapping of primary-key field name to value).
|
|
15
|
+
*/
|
|
16
|
+
export interface ScopeObject {
|
|
17
|
+
type: string;
|
|
18
|
+
key: Record<string, string | number | boolean>;
|
|
19
|
+
}
|
|
20
|
+
/** Which relations a scoped read may traverse. */
|
|
21
|
+
export type RelationsScope = "no_relations" | "all_relations";
|
|
22
|
+
/**
|
|
23
|
+
* A read's scope: the concrete `objects` it may touch, plus relation policy.
|
|
24
|
+
* `relationsScope` is `no_relations` (objects only) by default; `all_relations`
|
|
25
|
+
* also exposes the relations among the in-scope `objects`.
|
|
26
|
+
*/
|
|
27
|
+
export interface ReadScope {
|
|
28
|
+
objects: ScopeObject[];
|
|
29
|
+
relationsScope?: RelationsScope;
|
|
30
|
+
}
|
|
11
31
|
export type WriteQueueStatus = "queued" | "processing" | "extracting" | "extracted" | "applying" | "completed" | "failed" | "not_found";
|
|
12
32
|
export declare class XmemoryAPIError extends Error {
|
|
13
33
|
readonly status?: number | undefined;
|
|
@@ -321,6 +341,8 @@ export interface RequestOptions {
|
|
|
321
341
|
}
|
|
322
342
|
export interface ReadOptions {
|
|
323
343
|
readMode?: ReadMode;
|
|
344
|
+
/** Restrict the read to a set of concrete objects (plus optional relation traversal). */
|
|
345
|
+
scope?: ReadScope;
|
|
324
346
|
traceId?: string;
|
|
325
347
|
timeoutMs?: number;
|
|
326
348
|
}
|