iit-mcp-autotask 0.62.0 → 0.62.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/README.md +18 -4
- package/dist/tools/billing-review-projection.js +4 -3
- package/dist/tools/clock.js +20 -2
- package/dist/tools/context/client.d.ts +1 -1
- package/dist/tools/context/client.js +2 -1
- package/dist/tools/context/types.d.ts +2 -1
- package/dist/tools/dispatch.js +2 -4
- package/dist/tools/guide.d.ts +3 -1
- package/dist/tools/guide.js +20 -2
- package/dist/tools/lists.js +18 -45
- package/dist/tools/output-file.d.ts +15 -0
- package/dist/tools/output-file.js +299 -15
- package/dist/tools/query-export.d.ts +25 -0
- package/dist/tools/query-export.js +89 -0
- package/dist/tools/register.js +2 -2
- package/dist/tools/results/envelope.d.ts +4 -0
- package/dist/tools/results/envelope.js +29 -2
- package/dist/tools/results/untrusted.d.ts +4 -0
- package/dist/tools/results/untrusted.js +48 -1
- package/dist/tools/tsv.d.ts +4 -0
- package/dist/tools/tsv.js +21 -18
- package/dist/tools/write/checks.js +7 -3
- package/dist/tools/write/concurrent.d.ts +2 -0
- package/dist/tools/write/concurrent.js +5 -0
- package/dist/tools/write/preview.js +19 -14
- package/dist/tools/write/snapshot.js +49 -29
- package/dist/write/store/ledger.d.ts +5 -1
- package/dist/write/store/ledger.js +20 -7
- package/dist/write/store/types.d.ts +1 -1
- package/dist/write/store.js +20 -5
- package/package.json +2 -2
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -327,7 +327,7 @@ Two per-call options change the result form:
|
|
|
327
327
|
| Option | Effect |
|
|
328
328
|
|--------|--------|
|
|
329
329
|
| `format: 'tsv'` | serves the table as `data.result.tsv` — a header row of column names plus one tab-separated line per record — with `result.columns` and `result.rowCount`, and **omits `result.items`** (that omission is the size saving; the JSON form stays the default). Inside a value a literal backslash is written as `\\`, a tab as `\t`, a newline as `\n` and a carriage return as `\r`; the `<untrusted_content>` markers survive inside cells. |
|
|
330
|
-
| `output_path: '<relative path>'` | **stdio transport only**: walks the FULL match set
|
|
330
|
+
| `output_path: '<relative path>'` | **stdio transport only**: walks the FULL match set through the SDK's governed query path, writes the envelope JSON to a file under `AUTOTASK_OUTPUT_DIR`, and returns a summary (`outputPath`, `columns`, `rowCount`, the first rows, `bytes`) instead of the table. |
|
|
331
331
|
|
|
332
332
|
`output_path` is deliberately strict: the deployment sets an **absolute** `AUTOTASK_OUTPUT_DIR`
|
|
333
333
|
that already exists and is not the filesystem root (a configured root that is missing is refused —
|
|
@@ -353,6 +353,18 @@ containment (a caller path can never make the server create or write outside the
|
|
|
353
353
|
against a same-user process racing the server. A hard link at the target path is an existing entry,
|
|
354
354
|
so `O_EXCL` refuses it too.
|
|
355
355
|
|
|
356
|
+
Query files are processed page by page instead of collecting the whole walk in server memory.
|
|
357
|
+
TSV preserves columns first seen on later pages by replaying sanitized rows from an anonymous,
|
|
358
|
+
request-local spool after the final column union is known; it still performs one vendor walk.
|
|
359
|
+
The spool and final file can coexist temporarily, so TSV uses extra disk space while writing.
|
|
360
|
+
Both formats share the existing path guard and an awaited writer; failures and cancellation
|
|
361
|
+
attempt cleanup of owned partial files before returning. Any stop of an in-progress stdio server —
|
|
362
|
+
including client shutdown/restart, `SIGTERM`, Ctrl-C/`SIGINT`, a crash, OOM or `SIGKILL` — can exit
|
|
363
|
+
before asynchronous cleanup finishes. A partial target may remain and block reuse of that path.
|
|
364
|
+
The target is visible while the walk is running; consume it only after a successful response.
|
|
365
|
+
After an interrupted server shutdown, check/remove the incomplete file or choose a new path before retrying. If the filesystem prevents proving ownership,
|
|
366
|
+
cleanup also preserves the path rather than deleting an unknown file. See [performance measurements](docs/performance.md).
|
|
367
|
+
|
|
356
368
|
The walk stops at 10,000 rows with an explicit truncation note in the summary (`hasMore: true` then
|
|
357
369
|
means the cap, not only the query limit). The call is refused outright on the `http` transport (the
|
|
358
370
|
caller is a request, not the process owner), and it cannot be combined with `latest` or
|
|
@@ -703,15 +715,17 @@ guards (rate limiter, 429 cooldown) — a worse security posture, not a safer on
|
|
|
703
715
|
apply to each pooled tenant client (SDK 0.9.0's default-on change: read ~5 min, the reference
|
|
704
716
|
tables ~1 h, field metadata ~5 min). Repeated reads of the same record are served from that
|
|
705
717
|
tenant's cache until TTL expiry; composites de-duplicate their 3–8 fan-out reads through it.
|
|
706
|
-
`off` sends `cache: false` (every read re-dials the vendor).
|
|
718
|
+
`off` sends `cache: false` (every read re-dials the vendor). SDK metadata projections reuse
|
|
719
|
+
derived work only within the same cache entry; they do not extend TTL or cache query/report results.
|
|
707
720
|
Fuzzy company search always performs an uncached live fragment query (at most 500 rows).
|
|
708
721
|
Separately, the SDK lazily builds a slim company-name index in the background, refreshes it
|
|
709
722
|
every 30 minutes and clears it after company writes (rebuild debounced for one second).
|
|
710
723
|
`AUTOTASK_CACHE=off` disables that index; results remain live-only with `index.state: "off"`.
|
|
711
724
|
Cold/building indexes and capped live searches can miss companies: inspect the returned metadata.
|
|
712
725
|
- **Boundaries — never relaxed:** in-process only (never on disk), **per-tenant** (one tenant's
|
|
713
|
-
cached records
|
|
714
|
-
on
|
|
726
|
+
cached records never answer another tenant's request), TTL-bounded, cleared on eviction and
|
|
727
|
+
on `401`. Client-local budgets and cooldown remain scoped; the SDK's shared object/origin
|
|
728
|
+
admission deliberately coordinates clients in the same runtime (see [Gateway assumptions](#gateway-assumptions)).
|
|
715
729
|
- **stdio** uses one process-lifetime client (the env is the whole identity) — no pool, and the
|
|
716
730
|
cache/limiter state is that single tenant's by construction.
|
|
717
731
|
- **Multi-process gateways:** pool/cache/limiter state is per-process; an N-process gateway runs N
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Closed Billing Review snapshot; ordinary read/text limits are unchanged. */
|
|
2
2
|
import { InputInvalidError, readOneItem, abortedAnswer } from './dispatch.js';
|
|
3
3
|
import { ok } from './results/envelope.js';
|
|
4
|
-
import {
|
|
4
|
+
import { boundedVendorResult, markServerField } from './results/untrusted.js';
|
|
5
5
|
import { validScalar } from './time-entry-verification.js';
|
|
6
6
|
import { FILTER_OPS } from './schemas.js';
|
|
7
7
|
import { canonicalRecord, EvidenceUnavailable, noteEvidence, plainRecord, sha256 } from './billing-review-evidence.js';
|
|
@@ -160,9 +160,10 @@ export async function readBillingReview(ctx, input, signal) {
|
|
|
160
160
|
invalid();
|
|
161
161
|
const summary = 'Fresh bounded Billing Review snapshot; display notes are untrusted. Check each entry state.';
|
|
162
162
|
// Measure the actual sanitized ToolReturn, including both structured and mirrored text copies.
|
|
163
|
-
|
|
163
|
+
const finished = boundedVendorResult(ok(summary, result.result), BILLING_RESPONSE_MAX_BYTES, ctx.correlationId);
|
|
164
|
+
if (finished === undefined) {
|
|
164
165
|
throw new InputInvalidError('Billing Review response exceeds 4 MiB; retry with a smaller limit', 'args[0].limit');
|
|
165
166
|
}
|
|
166
|
-
return
|
|
167
|
+
return finished;
|
|
167
168
|
}
|
|
168
169
|
//# sourceMappingURL=billing-review-projection.js.map
|
package/dist/tools/clock.js
CHANGED
|
@@ -4,6 +4,24 @@ const UTC_ALIAS = /^(etc\/)?(utc|gmt|uct|universal|zulu)$/i;
|
|
|
4
4
|
const ETC_OFFSET = /^etc\/gmt[+-]\d+$/i;
|
|
5
5
|
/** The names Intl lists, by lower case: the case fix for a name typed in the wrong case. */
|
|
6
6
|
const LISTED = new Map(Intl.supportedValuesOf('timeZone').map((z) => [z.toLowerCase(), z]));
|
|
7
|
+
/** Formatters retain zone configuration only; the Date and offset are recomputed on every call. */
|
|
8
|
+
const CLOCK_FORMATTER_LIMIT = 32;
|
|
9
|
+
const CLOCK_FORMATTERS = new Map();
|
|
10
|
+
function clockFormatter(zone) {
|
|
11
|
+
const key = UTC_ALIAS.test(zone) ? 'utc' : zone.toLowerCase();
|
|
12
|
+
const cached = CLOCK_FORMATTERS.get(key);
|
|
13
|
+
if (cached !== undefined) {
|
|
14
|
+
CLOCK_FORMATTERS.delete(key);
|
|
15
|
+
CLOCK_FORMATTERS.set(key, cached);
|
|
16
|
+
return cached;
|
|
17
|
+
}
|
|
18
|
+
// Intl validates before insertion, so invalid input never consumes a retained slot.
|
|
19
|
+
const formatter = new Intl.DateTimeFormat('en-US', { timeZone: zone, hourCycle: 'h23', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', timeZoneName: 'longOffset' });
|
|
20
|
+
CLOCK_FORMATTERS.set(key, formatter);
|
|
21
|
+
if (CLOCK_FORMATTERS.size > CLOCK_FORMATTER_LIMIT)
|
|
22
|
+
CLOCK_FORMATTERS.delete(CLOCK_FORMATTERS.keys().next().value);
|
|
23
|
+
return formatter;
|
|
24
|
+
}
|
|
7
25
|
/**
|
|
8
26
|
* The IANA name of `zone` as the operator spelled it (only the case of a listed name is fixed), or
|
|
9
27
|
* undefined. Intl does the validation; the name is never swapped for another spelling, so Europe/Kyiv
|
|
@@ -17,7 +35,7 @@ export function canonicalTimeZone(zone) {
|
|
|
17
35
|
if (!zone.includes('/') || ETC_OFFSET.test(zone))
|
|
18
36
|
return undefined;
|
|
19
37
|
try {
|
|
20
|
-
const resolved =
|
|
38
|
+
const resolved = clockFormatter(zone).resolvedOptions().timeZone;
|
|
21
39
|
if (UTC_ALIAS.test(resolved))
|
|
22
40
|
return 'UTC';
|
|
23
41
|
// ponytail: a valid name Intl does not list (a modern or link name such as Asia/Kolkata) keeps its case as typed; a case table per link name if wrong-case input shows up
|
|
@@ -29,7 +47,7 @@ export function canonicalTimeZone(zone) {
|
|
|
29
47
|
}
|
|
30
48
|
/** The clock of `zone` at `now`; the offset is the one in force at `now`, so it follows daylight saving. */
|
|
31
49
|
export function zoneClock(zone, now = new Date()) {
|
|
32
|
-
const parts =
|
|
50
|
+
const parts = clockFormatter(zone).formatToParts(now);
|
|
33
51
|
const p = (type) => parts.find((x) => x.type === type)?.value ?? '';
|
|
34
52
|
const gmt = p('timeZoneName'); // "GMT", "GMT+11:00", "GMT-03:30"
|
|
35
53
|
const utcOffset = gmt === 'GMT' ? '+00:00' : gmt.replace('GMT', '').replace('−', '-');
|
|
@@ -38,4 +38,4 @@ export declare const defaultToolOps: ToolOps;
|
|
|
38
38
|
* handler then answers the typed cancellation; the handler's generic catch would otherwise
|
|
39
39
|
* re-report it as a tool error, so this wrapper throws the SDK's typed `AbortError` instead.
|
|
40
40
|
*/
|
|
41
|
-
export declare function withSignal(client: ToolClient, signal: AbortSignal | undefined, fn: () => Promise<
|
|
41
|
+
export declare function withSignal<T>(client: ToolClient, signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** SDK client construction (base options, placeholder, stdio client) and the default SDK ops bundle (issue #91). */
|
|
2
2
|
import { AutotaskClient } from 'node-autotask';
|
|
3
|
-
import { invokeDelete, invokeRead, invokeWrite, relationshipMap, resolveAny, searchAcrossResources } from 'node-autotask/operations';
|
|
3
|
+
import { invokeDelete, invokeRead, invokeReadPages, invokeWrite, relationshipMap, resolveAny, searchAcrossResources } from 'node-autotask/operations';
|
|
4
4
|
import { serverCredentialDefaults } from '../../config/load.js';
|
|
5
5
|
import { normalizeBaseUrl } from '../../base-hosts.js';
|
|
6
6
|
import { sdkCacheOptions } from '../catalog-data.js';
|
|
@@ -118,6 +118,7 @@ export function buildStdioClient(config, log) {
|
|
|
118
118
|
*/
|
|
119
119
|
export const defaultToolOps = {
|
|
120
120
|
invokeRead: (client, operation, args, opts, signal) => withSignal(client, signal, () => invokeRead(client, operation, args, opts ?? {})),
|
|
121
|
+
invokeReadPages: (client, operation, args, onPage, opts, signal) => withSignal(client, signal, () => invokeReadPages(client, operation, args, onPage, opts ?? {})),
|
|
121
122
|
invokeWrite: (client, operation, args, opts, signal) => withSignal(client, signal, () => invokeWrite(client, operation, args, opts ?? {})),
|
|
122
123
|
invokeDelete: (client, operation, args, opts, signal) => withSignal(client, signal, () => invokeDelete(client, operation, args, opts ?? {})),
|
|
123
124
|
resolveAny: (client, identifier, opts, signal) => withSignal(client, signal, () => resolveAny(client, identifier, opts ?? {})),
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import type { ClientPool } from 'node-autotask/pool';
|
|
34
34
|
import type { AutotaskConfig } from 'node-autotask';
|
|
35
|
-
import type { InvokeOptions } from 'node-autotask/operations';
|
|
35
|
+
import type { BoundedQueryPageConsumer, BoundedQuerySummary, InvokeOptions } from 'node-autotask/operations';
|
|
36
36
|
import type { Config } from '../../config/schema.js';
|
|
37
37
|
import type { Logger } from '../../logger.js';
|
|
38
38
|
import type { RefusalKind } from '../results/errors.js';
|
|
@@ -54,6 +54,7 @@ export interface HourlyBudget {
|
|
|
54
54
|
export interface ToolOps {
|
|
55
55
|
/** The MCP request's AbortSignal, when the transport provides one: an abandoned request stops consuming vendor budget. */
|
|
56
56
|
invokeRead(client: ToolClient, operation: string, args?: readonly unknown[], opts?: InvokeOptions, signal?: AbortSignal): Promise<unknown>;
|
|
57
|
+
invokeReadPages(client: ToolClient, operation: string, args: readonly unknown[], onPage: BoundedQueryPageConsumer, opts?: InvokeOptions, signal?: AbortSignal): Promise<BoundedQuerySummary | undefined>;
|
|
57
58
|
invokeWrite(client: ToolClient, operation: string, args?: readonly unknown[], opts?: InvokeOptions, signal?: AbortSignal): Promise<unknown>;
|
|
58
59
|
invokeDelete(client: ToolClient, operation: string, args?: readonly unknown[], opts?: InvokeOptions, signal?: AbortSignal): Promise<unknown>;
|
|
59
60
|
resolveAny(client: ToolClient, identifier: number | string, opts?: {
|
package/dist/tools/dispatch.js
CHANGED
|
@@ -19,7 +19,7 @@ import { AUTOTASK_BASE_PATH } from '../base-hosts.js';
|
|
|
19
19
|
import { releaseClientOnError } from './context/derive.js';
|
|
20
20
|
import { abortedResult, closedArgsError, errorContent, refusalContent } from './results/errors.js';
|
|
21
21
|
import { crossResourceUntrusted, isFileOperation, markFilePayload, markResult, markServerField } from './results/untrusted.js';
|
|
22
|
-
import {} from './results/envelope.js';
|
|
22
|
+
import { mirrorEnvelope } from './results/envelope.js';
|
|
23
23
|
import { assertOperationPermitted } from '../policy.js';
|
|
24
24
|
import { scopeRequiredInput } from './scope-guard.js';
|
|
25
25
|
import { fieldNameInput } from './field-pointer.js';
|
|
@@ -92,9 +92,7 @@ function stamp(correlationId, result) {
|
|
|
92
92
|
if (finished.structuredContent.correlationId !== '')
|
|
93
93
|
return finished;
|
|
94
94
|
finished.structuredContent.correlationId = correlationId;
|
|
95
|
-
|
|
96
|
-
if (first !== undefined)
|
|
97
|
-
first.text = JSON.stringify(finished.structuredContent);
|
|
95
|
+
mirrorEnvelope(finished);
|
|
98
96
|
return finished;
|
|
99
97
|
}
|
|
100
98
|
/** The typed answer when the MCP request was cancelled before the upstream call settled. */
|
package/dist/tools/guide.d.ts
CHANGED
|
@@ -23,7 +23,9 @@ export interface Skill {
|
|
|
23
23
|
export declare function parseSkill(text: string): Skill;
|
|
24
24
|
/** Every packaged skill, read once at boot, by name. */
|
|
25
25
|
export declare const SKILLS: ReadonlyMap<string, Skill>;
|
|
26
|
-
/**
|
|
26
|
+
/** Compile packaged definitions once; duplicate references still name a skill only once. @internal */
|
|
27
|
+
export declare function indexPlaybooks(skills: Iterable<Pick<Skill, 'name' | 'ops'>>): Map<string, string[]>;
|
|
28
|
+
/** The skills whose steps use `operation`; every caller owns its returned array. */
|
|
27
29
|
export declare function playbooksFor(operation: string): string[];
|
|
28
30
|
/** The skills a profile can run (operator skills are listed only where the write path is served). */
|
|
29
31
|
export declare function skillsFor(profile: string): Skill[];
|
package/dist/tools/guide.js
CHANGED
|
@@ -58,9 +58,27 @@ export const SKILLS = (() => {
|
|
|
58
58
|
}
|
|
59
59
|
return out;
|
|
60
60
|
})();
|
|
61
|
-
/**
|
|
61
|
+
/** Compile packaged definitions once; duplicate references still name a skill only once. @internal */
|
|
62
|
+
export function indexPlaybooks(skills) {
|
|
63
|
+
const index = new Map();
|
|
64
|
+
for (const skill of skills) {
|
|
65
|
+
const operations = new Set(skill.ops.map((entry) => entry.split(':')[1]));
|
|
66
|
+
for (const operation of operations) {
|
|
67
|
+
if (operation === undefined)
|
|
68
|
+
continue;
|
|
69
|
+
const names = index.get(operation);
|
|
70
|
+
if (names === undefined)
|
|
71
|
+
index.set(operation, [skill.name]);
|
|
72
|
+
else
|
|
73
|
+
names.push(skill.name);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return index;
|
|
77
|
+
}
|
|
78
|
+
const PLAYBOOKS_BY_OPERATION = indexPlaybooks(SKILLS.values());
|
|
79
|
+
/** The skills whose steps use `operation`; every caller owns its returned array. */
|
|
62
80
|
export function playbooksFor(operation) {
|
|
63
|
-
return [...
|
|
81
|
+
return [...(PLAYBOOKS_BY_OPERATION.get(operation) ?? [])];
|
|
64
82
|
}
|
|
65
83
|
/** The skills a profile can run (operator skills are listed only where the write path is served). */
|
|
66
84
|
export function skillsFor(profile) {
|
package/dist/tools/lists.js
CHANGED
|
@@ -14,7 +14,8 @@ import { abortedAnswer, InputInvalidError } from './dispatch.js';
|
|
|
14
14
|
import { runAggregate } from './aggregate.js';
|
|
15
15
|
import { markResult, markServerField, sanitiseVendorOutput } from './results/untrusted.js';
|
|
16
16
|
import { ok } from './results/envelope.js';
|
|
17
|
-
import {
|
|
17
|
+
import { toTsv } from './tsv.js';
|
|
18
|
+
import { exportQueryFile, QueryExportIncompleteError } from './query-export.js';
|
|
18
19
|
import { OUTPUT_MAX_ROWS, resolveOutputTarget } from './output-file.js';
|
|
19
20
|
import { assertOperationPermitted } from '../policy.js';
|
|
20
21
|
import { scopeRequiredInput } from './scope-guard.js';
|
|
@@ -142,50 +143,22 @@ async function outputPathAnswer(ctx, resource, operation, noun, fields, args, si
|
|
|
142
143
|
transport: ctx.config.MCP_TRANSPORT,
|
|
143
144
|
relativePath: args.output_path,
|
|
144
145
|
});
|
|
145
|
-
const result = await ctx.ops.invokeRead(ctx.client, operation, [{
|
|
146
|
-
filter: args.filter,
|
|
147
|
-
limit: 500,
|
|
148
|
-
walk: { maxRows: OUTPUT_MAX_ROWS },
|
|
149
|
-
...(args.include_fields === undefined ? {} : { includeFields: args.include_fields }),
|
|
150
|
-
...(args.acknowledge_unscoped === undefined ? {} : { acknowledgeUnscoped: args.acknowledge_unscoped }),
|
|
151
|
-
}], undefined, signal).catch((err) => { throw fieldNameInput(scopeRequiredInput(err, 'filter', true), true); });
|
|
152
|
-
if (result === undefined)
|
|
153
|
-
return abortedAnswer(ctx.correlationId);
|
|
154
|
-
const walked = result;
|
|
155
|
-
const walkNotes = sanitiseVendorOutput({
|
|
156
|
-
...(walked.scopeNote === undefined ? {} : { scopeNote: walked.scopeNote }),
|
|
157
|
-
...(walked.names === undefined ? {} : { names: walked.names }),
|
|
158
|
-
...(walked.relationNote === undefined ? {} : { relationNote: walked.relationNote }),
|
|
159
|
-
...(walked.blindSurface === undefined ? {} : { blindSurface: walked.blindSurface }),
|
|
160
|
-
...(walked.emptyReason === undefined ? {} : { emptyReason: walked.emptyReason }),
|
|
161
|
-
}, { cap: false });
|
|
162
|
-
// M8: the file form keeps the full text (no 500-char cap) but is still stripped of control/bidi chars.
|
|
163
|
-
// The file is an output channel too: every vendor string is cleaned (never capped) before writing.
|
|
164
|
-
const marked = sanitiseVendorOutput(markResult(walked.items, fields), { cap: false });
|
|
165
|
-
const columns = tsvColumns(marked);
|
|
166
|
-
const rowCount = marked.length;
|
|
167
|
-
const truncatedNote = walked.truncated
|
|
168
|
-
? `the walk is incomplete after ${rowCount} rows (maximum ${OUTPUT_MAX_ROWS}); narrow the filter to capture the remainder`
|
|
169
|
-
: undefined;
|
|
170
|
-
const envelope = {
|
|
171
|
-
items: marked,
|
|
172
|
-
fetched: rowCount,
|
|
173
|
-
hasMore: walked.truncated,
|
|
174
|
-
...walkNotes,
|
|
175
|
-
...(truncatedNote !== undefined ? { truncated: true, truncatedNote } : {}),
|
|
176
|
-
};
|
|
177
146
|
const asTsv = args.format === 'tsv';
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
147
|
+
const exported = await exportQueryFile({
|
|
148
|
+
target, fields, format: asTsv ? 'tsv' : 'json', signal,
|
|
149
|
+
readPages: consume => ctx.ops.invokeReadPages(ctx.client, operation, [{
|
|
150
|
+
filter: args.filter,
|
|
151
|
+
limit: 500,
|
|
152
|
+
walk: { maxRows: OUTPUT_MAX_ROWS },
|
|
153
|
+
...(args.include_fields === undefined ? {} : { includeFields: args.include_fields }),
|
|
154
|
+
...(args.acknowledge_unscoped === undefined ? {} : { acknowledgeUnscoped: args.acknowledge_unscoped }),
|
|
155
|
+
}], consume, undefined, signal).catch((err) => { throw fieldNameInput(scopeRequiredInput(err, 'filter', true), true); }),
|
|
156
|
+
}).catch((error) => { if (error instanceof QueryExportIncompleteError)
|
|
157
|
+
return undefined; throw error; });
|
|
158
|
+
if (exported === undefined)
|
|
159
|
+
return abortedAnswer(ctx.correlationId);
|
|
160
|
+
const { columns, rowCount, hasMore, walkNotes, firstRows, bytes, truncatedNote } = exported;
|
|
161
|
+
const capNote = hasMore ? ` The walk is incomplete after ${rowCount} rows (truncated).` : '';
|
|
189
162
|
return ok(`Wrote ${rowCount} ${noun} as ${asTsv ? 'TSV' : 'JSON'} to the output directory.${capNote} The summary carries the path, ${columns.length} column(s) and the first rows; result.items is omitted.`, {
|
|
190
163
|
resource,
|
|
191
164
|
result: {
|
|
@@ -194,7 +167,7 @@ async function outputPathAnswer(ctx, resource, operation, noun, fields, args, si
|
|
|
194
167
|
columns,
|
|
195
168
|
rowCount,
|
|
196
169
|
fetched: rowCount,
|
|
197
|
-
hasMore
|
|
170
|
+
hasMore,
|
|
198
171
|
...walkNotes,
|
|
199
172
|
firstRows,
|
|
200
173
|
bytes,
|
|
@@ -12,11 +12,26 @@ export interface OutputTargetRequest {
|
|
|
12
12
|
/** The caller's path, RELATIVE to the root. */
|
|
13
13
|
relativePath: string;
|
|
14
14
|
}
|
|
15
|
+
export interface OutputSink {
|
|
16
|
+
/** Await each call: concurrent or post-completion writes are refused. */
|
|
17
|
+
write(chunk: string | Buffer): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export interface OutputSpool {
|
|
20
|
+
/** Append only already-sanitized export rows; never raw vendor records. */
|
|
21
|
+
append(row: unknown): Promise<void>;
|
|
22
|
+
/** One replay, after all appends; awaits each consumer before serving another row. */
|
|
23
|
+
replay(consume: (row: unknown) => Promise<void>): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface OutputWriteOptions {
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}
|
|
15
28
|
/** A validated target: the canonical path (as served in `outputPath`) and its one-shot writer. */
|
|
16
29
|
export interface OutputTarget {
|
|
17
30
|
path: string;
|
|
18
31
|
/** Create the file (never overwrite) and write `data` (UTF-8 string, or raw bytes); returns the byte size. */
|
|
19
32
|
write(data: string | Buffer): Promise<number>;
|
|
33
|
+
writeChunks(produce: (sink: OutputSink) => Promise<void>, options?: OutputWriteOptions): Promise<number>;
|
|
34
|
+
withSpool<T>(use: (spool: OutputSpool) => Promise<T>, options?: OutputWriteOptions): Promise<T>;
|
|
20
35
|
}
|
|
21
36
|
/**
|
|
22
37
|
* Validate an `output_path` before any vendor wire and return its writer. Creates the target's missing
|