@xano/cli 1.0.6-beta.2 → 1.0.6-beta.20
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 +217 -6
- package/dist/base-command.d.ts +5 -0
- package/dist/base-command.js +61 -4
- package/dist/commands/branch/list/index.js +5 -1
- package/dist/commands/ephemeral/create/index.js +3 -3
- package/dist/commands/ephemeral/list/index.js +2 -1
- package/dist/commands/ephemeral/pull/index.d.ts +0 -6
- package/dist/commands/ephemeral/pull/index.js +10 -95
- package/dist/commands/ephemeral/push/index.d.ts +10 -0
- package/dist/commands/ephemeral/push/index.js +77 -0
- package/dist/commands/ephemeral/static_host/build/list/index.d.ts +2 -3
- package/dist/commands/ephemeral/static_host/build/list/index.js +19 -40
- package/dist/commands/ephemeral/static_host/list/index.d.ts +2 -3
- package/dist/commands/ephemeral/static_host/list/index.js +20 -40
- package/dist/commands/flatten/index.d.ts +34 -0
- package/dist/commands/flatten/index.js +140 -0
- package/dist/commands/function/list/index.d.ts +4 -4
- package/dist/commands/function/list/index.js +30 -38
- package/dist/commands/function/run/index.d.ts +1 -0
- package/dist/commands/function/run/index.js +19 -5
- package/dist/commands/knowledge/list/index.js +2 -1
- package/dist/commands/platform/list/index.js +13 -14
- package/dist/commands/release/list/index.js +13 -14
- package/dist/commands/release/pull/index.d.ts +0 -6
- package/dist/commands/release/pull/index.js +10 -95
- package/dist/commands/sandbox/env/list/index.js +4 -0
- package/dist/commands/sandbox/pull/index.d.ts +0 -1
- package/dist/commands/sandbox/pull/index.js +10 -77
- package/dist/commands/sandbox/unit_test/list/index.d.ts +2 -0
- package/dist/commands/sandbox/unit_test/list/index.js +9 -14
- package/dist/commands/sandbox/unit_test/run/index.js +17 -11
- package/dist/commands/sandbox/unit_test/run_all/index.d.ts +1 -0
- package/dist/commands/sandbox/unit_test/run_all/index.js +76 -38
- package/dist/commands/sandbox/workflow_test/list/index.d.ts +2 -0
- package/dist/commands/sandbox/workflow_test/list/index.js +9 -14
- package/dist/commands/sandbox/workflow_test/run/index.js +12 -9
- package/dist/commands/sandbox/workflow_test/run_all/index.d.ts +1 -0
- package/dist/commands/sandbox/workflow_test/run_all/index.js +74 -36
- package/dist/commands/static_host/build/list/index.d.ts +2 -3
- package/dist/commands/static_host/build/list/index.js +19 -40
- package/dist/commands/static_host/build/pull/index.js +12 -9
- package/dist/commands/static_host/list/index.d.ts +2 -3
- package/dist/commands/static_host/list/index.js +20 -40
- package/dist/commands/static_host/migrate/index.js +14 -10
- package/dist/commands/tenant/backup/list/index.js +13 -14
- package/dist/commands/tenant/cluster/list/index.js +9 -10
- package/dist/commands/tenant/create/index.d.ts +3 -0
- package/dist/commands/tenant/create/index.js +21 -0
- package/dist/commands/tenant/deploy_release/index.d.ts +21 -0
- package/dist/commands/tenant/deploy_release/index.js +94 -2
- package/dist/commands/tenant/edit/index.d.ts +2 -0
- package/dist/commands/tenant/edit/index.js +39 -4
- package/dist/commands/tenant/env/list/index.js +4 -0
- package/dist/commands/tenant/list/index.js +19 -20
- package/dist/commands/tenant/pull/index.d.ts +0 -6
- package/dist/commands/tenant/pull/index.js +10 -106
- package/dist/commands/tenant/snapshot/list/index.js +5 -1
- package/dist/commands/tenant/unit_test/list/index.d.ts +4 -2
- package/dist/commands/tenant/unit_test/list/index.js +9 -14
- package/dist/commands/tenant/unit_test/run/index.js +19 -11
- package/dist/commands/tenant/unit_test/run_all/index.d.ts +1 -0
- package/dist/commands/tenant/unit_test/run_all/index.js +80 -38
- package/dist/commands/tenant/workflow_test/list/index.d.ts +4 -2
- package/dist/commands/tenant/workflow_test/list/index.js +9 -14
- package/dist/commands/tenant/workflow_test/run/index.js +14 -9
- package/dist/commands/tenant/workflow_test/run_all/index.d.ts +1 -0
- package/dist/commands/tenant/workflow_test/run_all/index.js +78 -36
- package/dist/commands/tenant_deploy_request/bypass/index.d.ts +20 -0
- package/dist/commands/tenant_deploy_request/bypass/index.js +79 -0
- package/dist/commands/tenant_deploy_request/create/index.d.ts +21 -0
- package/dist/commands/tenant_deploy_request/create/index.js +108 -0
- package/dist/commands/tenant_deploy_request/edit/index.d.ts +22 -0
- package/dist/commands/tenant_deploy_request/edit/index.js +103 -0
- package/dist/commands/tenant_deploy_request/get/index.d.ts +19 -0
- package/dist/commands/tenant_deploy_request/get/index.js +75 -0
- package/dist/commands/tenant_deploy_request/list/index.d.ts +20 -0
- package/dist/commands/tenant_deploy_request/list/index.js +122 -0
- package/dist/commands/tenant_deploy_request/revision/index.d.ts +21 -0
- package/dist/commands/tenant_deploy_request/revision/index.js +83 -0
- package/dist/commands/tenant_deploy_request/set_status/index.d.ts +21 -0
- package/dist/commands/tenant_deploy_request/set_status/index.js +112 -0
- package/dist/commands/unit_test/list/index.d.ts +3 -1
- package/dist/commands/unit_test/list/index.js +9 -14
- package/dist/commands/unit_test/run/index.js +19 -11
- package/dist/commands/unit_test/run_all/index.d.ts +1 -0
- package/dist/commands/unit_test/run_all/index.js +81 -41
- package/dist/commands/workflow_test/list/index.d.ts +3 -1
- package/dist/commands/workflow_test/list/index.js +10 -13
- package/dist/commands/workflow_test/run/index.js +15 -10
- package/dist/commands/workflow_test/run_all/index.d.ts +1 -0
- package/dist/commands/workflow_test/run_all/index.js +82 -39
- package/dist/commands/workspace/git/pull/index.js +48 -7
- package/dist/commands/workspace/list/index.js +7 -13
- package/dist/commands/workspace/pull/index.d.ts +0 -6
- package/dist/commands/workspace/pull/index.js +10 -115
- package/dist/utils/concurrency.d.ts +29 -0
- package/dist/utils/concurrency.js +54 -0
- package/dist/utils/document-parser.d.ts +90 -0
- package/dist/utils/document-parser.js +273 -1
- package/dist/utils/flatten.d.ts +36 -0
- package/dist/utils/flatten.js +68 -0
- package/dist/utils/knowledge-sync.d.ts +1 -0
- package/dist/utils/knowledge-sync.js +11 -5
- package/dist/utils/microservice-wait.d.ts +53 -0
- package/dist/utils/microservice-wait.js +83 -0
- package/dist/utils/multidoc-push.d.ts +88 -0
- package/dist/utils/multidoc-push.js +377 -8
- package/dist/utils/paging.d.ts +145 -0
- package/dist/utils/paging.js +199 -0
- package/dist/utils/reference-checker.js +13 -0
- package/oclif.manifest.json +4999 -3973
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Outcome of flattening one bundle file. */
|
|
2
|
+
export interface FlattenResult {
|
|
3
|
+
/** True when the original bundle was removed. */
|
|
4
|
+
removedSource: boolean;
|
|
5
|
+
/** Why the file was skipped, if it was (empty / single-document). */
|
|
6
|
+
skipped?: 'empty' | 'single';
|
|
7
|
+
/** Absolute paths written (or that would be written, in dry-run). */
|
|
8
|
+
written: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface FlattenOptions {
|
|
11
|
+
/** Preview only — compute the plan and write nothing, delete nothing. */
|
|
12
|
+
dryRun?: boolean;
|
|
13
|
+
/** Overwrite existing destination files instead of throwing on a clash. */
|
|
14
|
+
force?: boolean;
|
|
15
|
+
/** Keep the original bundle file (default: delete after a successful split). */
|
|
16
|
+
keepSource?: boolean;
|
|
17
|
+
/** Optional line logger (e.g. command.log) for a per-file plan. */
|
|
18
|
+
log?: (msg: string) => void;
|
|
19
|
+
/** Output root (default: the bundle file's own directory). */
|
|
20
|
+
outputDir?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Split ONE multi-document `.xs` bundle (documents joined by `---`) into the
|
|
24
|
+
* standard per-document tree — the exact layout `pull` produces — using the
|
|
25
|
+
* shared `placeDocuments` placement so the two never drift.
|
|
26
|
+
*
|
|
27
|
+
* Filesystem-touching, but self-contained: it reads the bundle, resolves every
|
|
28
|
+
* document's destination, checks for collisions, writes, and (unless
|
|
29
|
+
* `keepSource`) removes the original. Throws on a destination collision when
|
|
30
|
+
* `force` is not set, and never deletes the source when a written document
|
|
31
|
+
* landed on the source's own path.
|
|
32
|
+
*
|
|
33
|
+
* Shared by the `flatten` command and the push-time prompt, so a user who
|
|
34
|
+
* confirms "flatten now?" gets byte-identical output to running `xano flatten`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function flattenBundleFile(bundleFile: string, opts?: FlattenOptions): FlattenResult;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import snakeCase from 'lodash.snakecase';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
4
|
+
import { placeDocuments, splitMultidoc } from './document-parser.js';
|
|
5
|
+
/**
|
|
6
|
+
* Split ONE multi-document `.xs` bundle (documents joined by `---`) into the
|
|
7
|
+
* standard per-document tree — the exact layout `pull` produces — using the
|
|
8
|
+
* shared `placeDocuments` placement so the two never drift.
|
|
9
|
+
*
|
|
10
|
+
* Filesystem-touching, but self-contained: it reads the bundle, resolves every
|
|
11
|
+
* document's destination, checks for collisions, writes, and (unless
|
|
12
|
+
* `keepSource`) removes the original. Throws on a destination collision when
|
|
13
|
+
* `force` is not set, and never deletes the source when a written document
|
|
14
|
+
* landed on the source's own path.
|
|
15
|
+
*
|
|
16
|
+
* Shared by the `flatten` command and the push-time prompt, so a user who
|
|
17
|
+
* confirms "flatten now?" gets byte-identical output to running `xano flatten`.
|
|
18
|
+
*/
|
|
19
|
+
export function flattenBundleFile(bundleFile, opts = {}) {
|
|
20
|
+
const { dryRun = false, force = false, keepSource = false, log } = opts;
|
|
21
|
+
const content = fs.readFileSync(bundleFile, 'utf8').trim();
|
|
22
|
+
const documents = splitMultidoc(content);
|
|
23
|
+
if (documents.length === 0)
|
|
24
|
+
return { removedSource: false, skipped: 'empty', written: [] };
|
|
25
|
+
if (documents.length === 1)
|
|
26
|
+
return { removedSource: false, skipped: 'single', written: [] };
|
|
27
|
+
const outputDir = opts.outputDir ? resolve(opts.outputDir) : dirname(bundleFile);
|
|
28
|
+
const placed = placeDocuments(documents, { join, relative, snakeCase });
|
|
29
|
+
// Pre-check destination collisions (unless --force / dry-run). A written file
|
|
30
|
+
// landing on the source's own path is not a clash — it replaces the bundle.
|
|
31
|
+
if (!dryRun && !force) {
|
|
32
|
+
const clashes = placed
|
|
33
|
+
.map((p) => join(outputDir, p.relPath))
|
|
34
|
+
.filter((abs) => fs.existsSync(abs) && resolve(abs) !== resolve(bundleFile));
|
|
35
|
+
if (clashes.length > 0) {
|
|
36
|
+
throw new Error(`Destination file(s) already exist (use --force to overwrite):\n` +
|
|
37
|
+
clashes.map((c) => ` ${relative(process.cwd(), c) || c}`).join('\n'));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const written = [];
|
|
41
|
+
for (const p of placed) {
|
|
42
|
+
const abs = join(outputDir, p.relPath);
|
|
43
|
+
if (log)
|
|
44
|
+
log(` WRITE ${relative(process.cwd(), abs) || p.relPath}`);
|
|
45
|
+
if (!dryRun) {
|
|
46
|
+
fs.mkdirSync(dirname(abs), { recursive: true });
|
|
47
|
+
fs.writeFileSync(abs, p.content.endsWith('\n') ? p.content : `${p.content}\n`, 'utf8');
|
|
48
|
+
}
|
|
49
|
+
written.push(abs);
|
|
50
|
+
}
|
|
51
|
+
// Remove the original bundle unless asked to keep it, and never when a split
|
|
52
|
+
// document was written over the source's own path.
|
|
53
|
+
let removedSource = false;
|
|
54
|
+
if (!dryRun && !keepSource) {
|
|
55
|
+
const wroteOverSource = placed.some((p) => resolve(join(outputDir, p.relPath)) === resolve(bundleFile));
|
|
56
|
+
if (wroteOverSource) {
|
|
57
|
+
if (log)
|
|
58
|
+
log(` (source ${basename(bundleFile)} was overwritten by a split document; not deleting)`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
fs.rmSync(bundleFile);
|
|
62
|
+
removedSource = true;
|
|
63
|
+
if (log)
|
|
64
|
+
log(` removed ${relative(process.cwd(), bundleFile) || bundleFile}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { removedSource, written };
|
|
68
|
+
}
|
|
@@ -17,6 +17,7 @@ export interface KnowledgeObject {
|
|
|
17
17
|
mode?: string;
|
|
18
18
|
name: string;
|
|
19
19
|
scope?: string;
|
|
20
|
+
tag?: string[];
|
|
20
21
|
}
|
|
21
22
|
/** A locally-collected object that also remembers its primary file on disk (for GUID writeback). */
|
|
22
23
|
export interface LocalKnowledgeObject extends KnowledgeObject {
|
|
@@ -12,7 +12,7 @@ import { dirname, join, relative, sep } from 'node:path';
|
|
|
12
12
|
// let the server dictate file paths.
|
|
13
13
|
export const KNOWLEDGE_DIR = 'knowledge';
|
|
14
14
|
// ── Frontmatter ──────────────────────────────────────────────────────────────
|
|
15
|
-
const FRONTMATTER_ORDER = ['name', 'description', 'knowledge_type', '
|
|
15
|
+
const FRONTMATTER_ORDER = ['name', 'description', 'knowledge_type', 'inclusion', 'tags', 'guid'];
|
|
16
16
|
/**
|
|
17
17
|
* Build a primary `.md` file body: YAML frontmatter (built from the object's
|
|
18
18
|
* structured fields) followed by the markdown content.
|
|
@@ -23,12 +23,10 @@ export function buildPrimaryContent(obj) {
|
|
|
23
23
|
if (obj.description !== undefined)
|
|
24
24
|
meta.description = obj.description;
|
|
25
25
|
meta.knowledge_type = obj.knowledge_type;
|
|
26
|
-
if (obj.scope !== undefined)
|
|
27
|
-
meta.scope = obj.scope;
|
|
28
26
|
if (obj.mode !== undefined)
|
|
29
27
|
meta.inclusion = modeToInclusion(obj.mode);
|
|
30
|
-
if (obj.
|
|
31
|
-
meta.
|
|
28
|
+
if (obj.tag !== undefined && obj.tag.length > 0)
|
|
29
|
+
meta.tags = obj.tag;
|
|
32
30
|
if (obj.guid !== undefined)
|
|
33
31
|
meta.guid = obj.guid;
|
|
34
32
|
// Emit keys in a stable, human-friendly order.
|
|
@@ -107,6 +105,10 @@ const MODE_TO_INCLUSION = {
|
|
|
107
105
|
function modeToInclusion(mode) {
|
|
108
106
|
return MODE_TO_INCLUSION[mode] ?? mode;
|
|
109
107
|
}
|
|
108
|
+
/** Parse the on-disk `tags:` frontmatter value into a string array, or `undefined` if absent/malformed. */
|
|
109
|
+
function parseTags(tags) {
|
|
110
|
+
return Array.isArray(tags) && tags.every((t) => typeof t === 'string') ? tags : undefined;
|
|
111
|
+
}
|
|
110
112
|
// ── Path mapping (CLI-owned layout) ────────────────────────────────────────────
|
|
111
113
|
/**
|
|
112
114
|
* Allocate a unique snake_case folder/file segment per call, suffixing
|
|
@@ -246,6 +248,9 @@ export function collectKnowledgeObjects(inputDir, include, exclude) {
|
|
|
246
248
|
};
|
|
247
249
|
if (typeof meta.guid === 'string')
|
|
248
250
|
obj.guid = meta.guid;
|
|
251
|
+
const tags = parseTags(meta.tags);
|
|
252
|
+
if (tags)
|
|
253
|
+
obj.tag = tags;
|
|
249
254
|
if (knowledgeType === 'skill') {
|
|
250
255
|
const skillFolder = posixPath.slice('skills/'.length, posixPath.indexOf('/SKILL.md'));
|
|
251
256
|
const refPrefix = `skills/${skillFolder}/references/`;
|
|
@@ -345,6 +350,7 @@ function canonical(obj) {
|
|
|
345
350
|
files,
|
|
346
351
|
mode: obj.mode ?? '',
|
|
347
352
|
scope: obj.scope ?? '',
|
|
353
|
+
tag: [...(obj.tag ?? [])].sort(),
|
|
348
354
|
});
|
|
349
355
|
}
|
|
350
356
|
/**
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Poll a tenant's microservice deployment status until every auto-deployed
|
|
3
|
+
* microservice settles (ok/error) or a timeout elapses. Backs `ephemeral push
|
|
4
|
+
* --wait`: after a multidoc push auto-deploys microservices (tenant_deploy=
|
|
5
|
+
* "auto"), the CLI waits here for them to become Ready and reports the outcome.
|
|
6
|
+
*
|
|
7
|
+
* The backend route (GET .../tenant/{name}/microservice, statement
|
|
8
|
+
* mvp:microservice_status_all) returns one entry per microservice with a live
|
|
9
|
+
* k8s readiness read. `manual`/`disabled` microservices are reported but not
|
|
10
|
+
* waited on (they were never deployed by the push).
|
|
11
|
+
*/
|
|
12
|
+
/** One microservice's status as returned by the tenant status route. */
|
|
13
|
+
export interface MicroserviceStatusEntry {
|
|
14
|
+
desired?: number;
|
|
15
|
+
detail?: string;
|
|
16
|
+
microservice_id: number;
|
|
17
|
+
name: string;
|
|
18
|
+
ready?: number;
|
|
19
|
+
status: string;
|
|
20
|
+
tenant_deploy?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WaitOptions {
|
|
23
|
+
/** Bearer token for the authed status GET. */
|
|
24
|
+
accessToken: string;
|
|
25
|
+
/** Called once per poll with the latest entries, for progress rendering. */
|
|
26
|
+
onPoll?: (entries: MicroserviceStatusEntry[], elapsedMs: number) => void;
|
|
27
|
+
/** Poll cadence in ms (default 2000). */
|
|
28
|
+
pollIntervalMs?: number;
|
|
29
|
+
/** Absolute URL of the tenant microservice status route. */
|
|
30
|
+
statusUrl: string;
|
|
31
|
+
/** Overall wait budget in ms (default 300000 = 300s). */
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
/** Authed fetch (command.verboseFetch bound), so TLS/dispatcher settings apply. */
|
|
34
|
+
verboseFetch: (url: string, options: RequestInit, verbose: boolean, authToken?: string) => Promise<Response>;
|
|
35
|
+
/** Verbose request logging passthrough. */
|
|
36
|
+
verbose?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface WaitResult {
|
|
39
|
+
/** The final status entries observed. */
|
|
40
|
+
entries: MicroserviceStatusEntry[];
|
|
41
|
+
/** True if any awaited (auto) microservice ended in "error". */
|
|
42
|
+
hadError: boolean;
|
|
43
|
+
/** True if the wait budget elapsed before all awaited microservices settled. */
|
|
44
|
+
timedOut: boolean;
|
|
45
|
+
}
|
|
46
|
+
/** An awaited microservice is one that was auto-deployed and is not skipped/disabled. */
|
|
47
|
+
export declare function isAwaited(entry: MicroserviceStatusEntry): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Poll until all awaited microservices settle or the timeout elapses. Transient
|
|
50
|
+
* poll failures (network blips, a brief 5xx while a pod restarts) are tolerated —
|
|
51
|
+
* they don't abort the wait; only the overall timeout does.
|
|
52
|
+
*/
|
|
53
|
+
export declare function waitForMicroservices(opts: WaitOptions): Promise<WaitResult>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Poll a tenant's microservice deployment status until every auto-deployed
|
|
3
|
+
* microservice settles (ok/error) or a timeout elapses. Backs `ephemeral push
|
|
4
|
+
* --wait`: after a multidoc push auto-deploys microservices (tenant_deploy=
|
|
5
|
+
* "auto"), the CLI waits here for them to become Ready and reports the outcome.
|
|
6
|
+
*
|
|
7
|
+
* The backend route (GET .../tenant/{name}/microservice, statement
|
|
8
|
+
* mvp:microservice_status_all) returns one entry per microservice with a live
|
|
9
|
+
* k8s readiness read. `manual`/`disabled` microservices are reported but not
|
|
10
|
+
* waited on (they were never deployed by the push).
|
|
11
|
+
*/
|
|
12
|
+
/** Statuses that mean an awaited microservice has settled (no longer in flight). */
|
|
13
|
+
const SETTLED = new Set(['ok', 'error']);
|
|
14
|
+
/** Statuses that mean we don't wait on this microservice at all. */
|
|
15
|
+
const NOT_AWAITED = new Set(['skipped', 'disabled']);
|
|
16
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
17
|
+
/** An awaited microservice is one that was auto-deployed and is not skipped/disabled. */
|
|
18
|
+
export function isAwaited(entry) {
|
|
19
|
+
return !NOT_AWAITED.has(entry.status) && (entry.tenant_deploy ?? 'auto') !== 'manual';
|
|
20
|
+
}
|
|
21
|
+
/** True once every awaited microservice has settled (ok/error). */
|
|
22
|
+
function allSettled(entries) {
|
|
23
|
+
const awaited = entries.filter((e) => isAwaited(e));
|
|
24
|
+
// No auto microservices at all → nothing to wait for.
|
|
25
|
+
if (awaited.length === 0)
|
|
26
|
+
return true;
|
|
27
|
+
return awaited.every((e) => SETTLED.has(e.status));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Fetch the status route once. Throws on a non-2xx so the caller can decide
|
|
31
|
+
* whether a transient failure is fatal (it isn't — we keep polling).
|
|
32
|
+
*/
|
|
33
|
+
async function fetchStatus(opts) {
|
|
34
|
+
const res = await opts.verboseFetch(opts.statusUrl, { headers: { Authorization: `Bearer ${opts.accessToken}` }, method: 'GET' }, opts.verbose ?? false, opts.accessToken);
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
throw new Error(`status ${res.status} ${res.statusText}`);
|
|
37
|
+
}
|
|
38
|
+
const body = (await res.json());
|
|
39
|
+
if (!Array.isArray(body)) {
|
|
40
|
+
throw new Error('unexpected status response shape');
|
|
41
|
+
}
|
|
42
|
+
return body;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Poll until all awaited microservices settle or the timeout elapses. Transient
|
|
46
|
+
* poll failures (network blips, a brief 5xx while a pod restarts) are tolerated —
|
|
47
|
+
* they don't abort the wait; only the overall timeout does.
|
|
48
|
+
*/
|
|
49
|
+
export async function waitForMicroservices(opts) {
|
|
50
|
+
const pollIntervalMs = opts.pollIntervalMs ?? 2000;
|
|
51
|
+
const timeoutMs = opts.timeoutMs ?? 300000;
|
|
52
|
+
const start = Date.now();
|
|
53
|
+
let entries = [];
|
|
54
|
+
let consecutiveErrors = 0;
|
|
55
|
+
// Poll loop. We always do at least one fetch so `--wait` reports even when the
|
|
56
|
+
// deployment already settled between the push returning and the first poll.
|
|
57
|
+
for (;;) {
|
|
58
|
+
const elapsed = Date.now() - start;
|
|
59
|
+
try {
|
|
60
|
+
entries = await fetchStatus(opts);
|
|
61
|
+
consecutiveErrors = 0;
|
|
62
|
+
opts.onPoll?.(entries, elapsed);
|
|
63
|
+
if (allSettled(entries)) {
|
|
64
|
+
return { entries, hadError: entries.some((e) => isAwaited(e) && e.status === 'error'), timedOut: false };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// A transient status read failure is non-fatal — keep polling until the
|
|
69
|
+
// overall timeout. (Mirrors the frontend poller's tolerate-with-cap.) We
|
|
70
|
+
// don't surface each blip; the timeout is the real failure signal.
|
|
71
|
+
consecutiveErrors++;
|
|
72
|
+
}
|
|
73
|
+
if (Date.now() - start + pollIntervalMs > timeoutMs) {
|
|
74
|
+
// Out of budget. Report whatever we last saw as timed out.
|
|
75
|
+
return {
|
|
76
|
+
entries,
|
|
77
|
+
hadError: entries.some((e) => isAwaited(e) && e.status === 'error'),
|
|
78
|
+
timedOut: true,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
await sleep(pollIntervalMs);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -89,7 +89,61 @@ export declare function collectFiles(dir: string): string[];
|
|
|
89
89
|
* Apply include/exclude glob filters to a file list. Logs filter results.
|
|
90
90
|
* Returns the filtered file list.
|
|
91
91
|
*/
|
|
92
|
+
/**
|
|
93
|
+
* Normalize a filter pattern into one minimatch can actually match against a
|
|
94
|
+
* repo-relative FILE path.
|
|
95
|
+
*
|
|
96
|
+
* minimatch has no notion of "this pattern names a directory", and the two
|
|
97
|
+
* spellings a person reaches for first both silently match NOTHING:
|
|
98
|
+
*
|
|
99
|
+
* "table/" a trailing slash is not directory syntax; it matches nothing
|
|
100
|
+
* "table" no slash, so `matchBase` compares it to the file's BASENAME,
|
|
101
|
+
* i.e. it asks "is this file called `table`", not "is it under
|
|
102
|
+
* `table/`"
|
|
103
|
+
*
|
|
104
|
+
* Silently matching nothing is the dangerous half of this: combined with
|
|
105
|
+
* `--delete`, a filter that fails open pushes more than intended, and a filter
|
|
106
|
+
* that succeeds deletes what it was meant to protect. So a pattern that names a
|
|
107
|
+
* real directory is expanded to `<dir>/**` rather than left to match nothing.
|
|
108
|
+
*/
|
|
109
|
+
export declare function normalizeFilterPattern(pattern: string, inputDir: string): string;
|
|
92
110
|
export declare function applyFilters(files: string[], inputDir: string, include: string[] | undefined, exclude: string[] | undefined, log: (msg: string) => void): string[];
|
|
111
|
+
/** A document the filter removed from the push, and therefore must protect. */
|
|
112
|
+
export interface FilteredOutDocument {
|
|
113
|
+
guid?: string;
|
|
114
|
+
key: string;
|
|
115
|
+
name: string;
|
|
116
|
+
relPath: string;
|
|
117
|
+
type: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Describe the documents a --include/--exclude filter removed.
|
|
121
|
+
*
|
|
122
|
+
* These are the objects the user asked NOT to touch, and they are exactly the
|
|
123
|
+
* ones a `--delete` sweep would remove: a filtered-out document never reaches
|
|
124
|
+
* the payload, so the server reads it as deleted from the tree. Their GUIDs are
|
|
125
|
+
* sent as `protect_guids` so the server spares them, and their keys are used to
|
|
126
|
+
* VERIFY the server actually did.
|
|
127
|
+
*/
|
|
128
|
+
export declare function describeFilteredOut(allFiles: string[], keptFiles: string[], inputDir: string): FilteredOutDocument[];
|
|
129
|
+
/**
|
|
130
|
+
* Delete operations that would remove something the filter excluded.
|
|
131
|
+
*
|
|
132
|
+
* This is the guard's actual test, and it is deliberately performed against the
|
|
133
|
+
* dry-run the SERVER returned rather than trusting that `protect_guids` was
|
|
134
|
+
* honoured: an older instance ignores the parameter entirely, and a document
|
|
135
|
+
* with no GUID cannot be protected at all. Either way the answer here is the
|
|
136
|
+
* truth about what the push is about to do.
|
|
137
|
+
*/
|
|
138
|
+
export declare function deletesHittingFilteredOut(operations: Array<{
|
|
139
|
+
action: string;
|
|
140
|
+
name: string;
|
|
141
|
+
type: string;
|
|
142
|
+
}>, filteredOut: FilteredOutDocument[]): Array<{
|
|
143
|
+
name: string;
|
|
144
|
+
relPath: string;
|
|
145
|
+
type: string;
|
|
146
|
+
}>;
|
|
93
147
|
/**
|
|
94
148
|
* Read .xs files into document entries, skipping empty files.
|
|
95
149
|
*/
|
|
@@ -97,6 +151,40 @@ export declare function readDocuments(files: string[]): Array<{
|
|
|
97
151
|
content: string;
|
|
98
152
|
filePath: string;
|
|
99
153
|
}>;
|
|
154
|
+
/**
|
|
155
|
+
* Return the entries whose file holds more than one document (a `---`
|
|
156
|
+
* separator). Used to refuse multi-doc files before the push pipeline's
|
|
157
|
+
* single-doc-per-file assumptions can drop or corrupt them.
|
|
158
|
+
*/
|
|
159
|
+
export declare function findMultiDocEntries(entries: Array<{
|
|
160
|
+
content: string;
|
|
161
|
+
filePath: string;
|
|
162
|
+
}>): Array<{
|
|
163
|
+
count: number;
|
|
164
|
+
filePath: string;
|
|
165
|
+
}>;
|
|
166
|
+
/**
|
|
167
|
+
* Return every `workspace` document in the push set, with the name it declares.
|
|
168
|
+
*
|
|
169
|
+
* A tree must carry at most ONE. The server applies the first workspace
|
|
170
|
+
* document it encounters to the workspace being pushed into and silently
|
|
171
|
+
* discards the rest, with no check that the document actually describes that
|
|
172
|
+
* workspace — so a second one renames the destination to a foreign name while
|
|
173
|
+
* leaving its content untouched, and which name wins flips with the contents of
|
|
174
|
+
* the pushed set.
|
|
175
|
+
*
|
|
176
|
+
* Trees accumulate a second one easily, because `pull` names the file after the
|
|
177
|
+
* workspace's own name (`workspace/{name}.xs`): pulling a different workspace
|
|
178
|
+
* into the same directory ADDS a file rather than overwriting, and renaming a
|
|
179
|
+
* workspace leaves the old-name file behind.
|
|
180
|
+
*/
|
|
181
|
+
export declare function findWorkspaceEntries(entries: Array<{
|
|
182
|
+
content: string;
|
|
183
|
+
filePath: string;
|
|
184
|
+
}>): Array<{
|
|
185
|
+
filePath: string;
|
|
186
|
+
name: string;
|
|
187
|
+
}>;
|
|
100
188
|
export declare function renderBadReferences(badRefs: BadReference[], log: (msg: string) => void): void;
|
|
101
189
|
export declare function renderBadIndexes(badIndexes: BadIndex[], log: (msg: string) => void): void;
|
|
102
190
|
export declare function confirm(message: string): Promise<boolean>;
|