@bluestep-systems/b6p-core 0.8.0 → 0.9.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.
Files changed (46) hide show
  1. package/README.md +58 -19
  2. package/dist/B6PCore.js +42 -0
  3. package/dist/B6PCore.js.map +1 -1
  4. package/dist/Err.d.ts +6 -0
  5. package/dist/Err.js +6 -0
  6. package/dist/Err.js.map +1 -1
  7. package/dist/data/ScriptKey.d.ts +3 -27
  8. package/dist/data/ScriptKey.js +12 -24
  9. package/dist/data/ScriptKey.js.map +1 -1
  10. package/dist/data/ScriptUrlParser.js +3 -1
  11. package/dist/data/ScriptUrlParser.js.map +1 -1
  12. package/dist/index.d.ts +10 -4
  13. package/dist/index.js +52 -6
  14. package/dist/index.js.map +1 -1
  15. package/dist/providers.d.ts +13 -0
  16. package/dist/script/GitIdentity.d.ts +48 -0
  17. package/dist/script/GitIdentity.js +52 -0
  18. package/dist/script/GitIdentity.js.map +1 -0
  19. package/dist/script/GitSync.d.ts +321 -0
  20. package/dist/script/GitSync.js +1001 -0
  21. package/dist/script/GitSync.js.map +1 -0
  22. package/dist/script/ScriptContext.d.ts +22 -0
  23. package/dist/script/ScriptFile.d.ts +4 -96
  24. package/dist/script/ScriptFile.js +7 -248
  25. package/dist/script/ScriptFile.js.map +1 -1
  26. package/dist/script/ScriptFolder.d.ts +0 -9
  27. package/dist/script/ScriptFolder.js +4 -7
  28. package/dist/script/ScriptFolder.js.map +1 -1
  29. package/dist/script/ScriptNode.d.ts +0 -9
  30. package/dist/script/ScriptNode.js.map +1 -1
  31. package/dist/script/ScriptRoot.d.ts +0 -2
  32. package/dist/script/ScriptRoot.js +0 -21
  33. package/dist/script/ScriptRoot.js.map +1 -1
  34. package/dist/script/ScriptService.d.ts +78 -8
  35. package/dist/script/ScriptService.js +126 -52
  36. package/dist/script/ScriptService.js.map +1 -1
  37. package/dist/script/ScriptTranspiler.d.ts +62 -0
  38. package/dist/script/ScriptTranspiler.js +97 -5
  39. package/dist/script/ScriptTranspiler.js.map +1 -1
  40. package/dist/script/push.d.ts +82 -148
  41. package/dist/script/push.js +145 -384
  42. package/dist/script/push.js.map +1 -1
  43. package/package.json +12 -8
  44. package/dist/script/SnapshotHistoryRecorder.d.ts +0 -47
  45. package/dist/script/SnapshotHistoryRecorder.js +0 -231
  46. package/dist/script/SnapshotHistoryRecorder.js.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,wEAAwE;AACxE,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AACZ,sCAOuB;AANrB,8GAAA,sBAAsB,OAAA;AACtB,kHAAA,0BAA0B,OAAA;AAC1B,kHAAA,0BAA0B,OAAA;AAC1B,yGAAA,iBAAiB,OAAA;AACjB,mGAAA,WAAW,OAAA;AACX,0GAAA,kBAAkB,OAAA;AAqBpB,wEAAwE;AACxE,oEAAmE;AAA1D,4HAAA,oBAAoB,OAAA;AAC7B,kDAAiD;AAAxC,0GAAA,WAAW,OAAA;AACpB,8CAA6C;AAApC,sGAAA,SAAS,OAAA;AAClB,8CAA6C;AAApC,sGAAA,SAAS,OAAA;AAClB,8CAA6C;AAApC,sGAAA,SAAS,OAAA;AAClB,0DAAyD;AAAhD,kHAAA,eAAe,OAAA;AAExB,wEAAwE;AACxE,gEAA+D;AAAtD,wHAAA,kBAAkB,OAAA;AAC3B,2DAA0D;AAAjD,gHAAA,cAAc,OAAA;AAEvB,wEAAwE;AACxE,mDAAkD;AAAzC,wGAAA,UAAU,OAAA;AACnB,qDAAsD;AAA7C,4GAAA,aAAa,OAAA;AAEtB,wEAAwE;AACxE,wDAAuD;AAA9C,8GAAA,aAAa,OAAA;AACtB,kDAAiD;AAAxC,wGAAA,UAAU,OAAA;AACnB,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nB,wDAAuD;AAA9C,8GAAA,aAAa,OAAA;AAEtB,wDAAuD;AAA9C,8GAAA,aAAa,OAAA;AAEtB,wEAAwE;AACxE,yCAgBqB;AAfnB,yGAAA,YAAY,OAAA;AACZ,sGAAA,SAAS,OAAA;AACT,mGAAA,MAAM,OAAA;AACN,6GAAA,gBAAgB,OAAA;AAChB,4GAAA,eAAe,OAAA;AACf,2GAAA,cAAc,OAAA;AACd,wGAAA,WAAW,OAAA;AACX,uGAAA,UAAU,OAAA;AACV,iGAAA,IAAI,OAAA;AACJ,sGAAA,SAAS,OAAA;AACT,sGAAA,SAAS,OAAA;AACT,2GAAA,cAAc,OAAA;AACd,yGAAA,YAAY,OAAA;AACZ,yGAAA,YAAY,OAAA;AACZ,2GAAA,cAAc,OAAA;AAGhB,wEAAwE;AACxE,6CAauB;AAZrB,wGAAA,SAAS,OAAA;AACT,uGAAA,QAAQ,OAAA;AAER,mHAAA,oBAAoB,OAAA;AACpB,qGAAA,MAAM,OAAA;AACN,0GAAA,WAAW,OAAA;AACX,yGAAA,UAAU,OAAA;AACV,mHAAA,oBAAoB,OAAA;AACpB,mHAAA,oBAAoB,OAAA;AACpB,gHAAA,iBAAiB,OAAA;AACjB,+GAAA,gBAAgB,OAAA;AAChB,sHAAA,uBAAuB,OAAA;AAGzB,6EAA4E;AAAnE,8HAAA,qBAAqB,OAAA;AAE9B,wEAAwE;AACxE,6CAA4C;AAAnC,oGAAA,QAAQ,OAAA;AACjB,mEAAkE;AAAzD,0HAAA,mBAAmB,OAAA;AAE5B,wEAAwE;AACxE,wDAAuD;AAA9C,8GAAA,aAAa,OAAA;AAGtB,wEAAwE;AACxE,2DAA0D;AAAjD,gHAAA,cAAc,OAAA;AA4BvB,4FAA4F;AAC5F,+EAA+D"}
@@ -1,3 +1,4 @@
1
+ import type { ScriptRepoOptions } from "@bluestep-systems/b6p-core-bsjs-git";
1
2
  import type { B6PUri } from "./B6PUri";
2
3
  import type { OrgCacheSettings } from "./cache/OrgCache";
3
4
  import type { AuthParams } from "./types";
@@ -227,6 +228,18 @@ export interface B6PProviders {
227
228
  * @lastreviewed null
228
229
  */
229
230
  typescriptLibDirs?: readonly string[];
231
+ /**
232
+ * Optional Node-style file system (with `.promises`) the script git working trees live on. Defaults to `node:fs`.
233
+ * Pass one only to run against something other than the real disk the `fs` provider also reads (tests).
234
+ * @lastreviewed null
235
+ */
236
+ gitFs?: ScriptRepoOptions["fs"];
237
+ /**
238
+ * Optional environment commit authors are looked up in as a last resort (after an explicit author and `git config`).
239
+ * Defaults to `process.env`.
240
+ * @lastreviewed null
241
+ */
242
+ gitEnv?: Readonly<Record<string, string | undefined>>;
230
243
  /**
231
244
  * Optional update service configuration. If not provided, update checking is disabled.
232
245
  */
@@ -0,0 +1,48 @@
1
+ import { type GitIdentity } from "@bluestep-systems/b6p-core-bsjs-git";
2
+ /**
3
+ * Reads one `git config` value as git itself resolves it (repository, global and system config) for the repository
4
+ * at, or the folder `dir`. Resolves to `undefined` when the key is unset or git is not installed.
5
+ * @lastreviewed null
6
+ */
7
+ export type GitConfigReader = (dir: string, key: string) => Promise<string | undefined>;
8
+ /**
9
+ * Where a commit author may come from, in the order they are tried.
10
+ * @lastreviewed null
11
+ */
12
+ export interface GitIdentitySources {
13
+ /**
14
+ * An author the caller chose outright. Wins over everything else; it must be complete.
15
+ * @lastreviewed null
16
+ */
17
+ readonly explicit?: GitIdentity;
18
+ /**
19
+ * The script folder whose `git config` (and the user's global one) is consulted.
20
+ * @lastreviewed null
21
+ */
22
+ readonly dir: string;
23
+ /**
24
+ * The environment searched last for `GIT_AUTHOR_NAME`/`GIT_AUTHOR_EMAIL`, then `GIT_COMMITTER_NAME`/`_EMAIL`.
25
+ * Defaults to `process.env`.
26
+ * @lastreviewed null
27
+ */
28
+ readonly env?: Readonly<Record<string, string | undefined>>;
29
+ /**
30
+ * Replaces the `git config` lookup (tests); default runs the `git` executable.
31
+ * @lastreviewed null
32
+ */
33
+ readonly readGitConfig?: GitConfigReader;
34
+ }
35
+ /**
36
+ * The default {@link GitConfigReader}: `git config --get <key>` in `dir`.
37
+ * @lastreviewed null
38
+ */
39
+ export declare const runGitConfig: GitConfigReader;
40
+ /**
41
+ * The author a script commit is made by, the first complete (name and email) one of: the explicit identity, `git
42
+ * config user.name`/`user.email` for the script folder, then `GIT_AUTHOR_*`, then `GIT_COMMITTER_*` in the
43
+ * environment. There is no default: a commit made as nobody would reach the script's history as nobody.
44
+ *
45
+ * @throws {GitIdentityError} when the explicit identity is incomplete, or when no source has one.
46
+ * @lastreviewed null
47
+ */
48
+ export declare function resolveGitIdentity(sources: GitIdentitySources): Promise<GitIdentity>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runGitConfig = void 0;
4
+ exports.resolveGitIdentity = resolveGitIdentity;
5
+ const node_child_process_1 = require("node:child_process");
6
+ const b6p_core_bsjs_git_1 = require("@bluestep-systems/b6p-core-bsjs-git");
7
+ /**
8
+ * The default {@link GitConfigReader}: `git config --get <key>` in `dir`.
9
+ * @lastreviewed null
10
+ */
11
+ const runGitConfig = (dir, key) => new Promise((resolve) => {
12
+ (0, node_child_process_1.execFile)("git", ["config", "--get", key], { cwd: dir, windowsHide: true }, (error, stdout) => {
13
+ const value = error ? "" : stdout.trim();
14
+ resolve(value === "" ? undefined : value);
15
+ });
16
+ });
17
+ exports.runGitConfig = runGitConfig;
18
+ function complete(name, email) {
19
+ const n = name?.trim();
20
+ const e = email?.trim();
21
+ return n && e ? { name: n, email: e } : undefined;
22
+ }
23
+ /**
24
+ * The author a script commit is made by, the first complete (name and email) one of: the explicit identity, `git
25
+ * config user.name`/`user.email` for the script folder, then `GIT_AUTHOR_*`, then `GIT_COMMITTER_*` in the
26
+ * environment. There is no default: a commit made as nobody would reach the script's history as nobody.
27
+ *
28
+ * @throws {GitIdentityError} when the explicit identity is incomplete, or when no source has one.
29
+ * @lastreviewed null
30
+ */
31
+ async function resolveGitIdentity(sources) {
32
+ if (sources.explicit) {
33
+ const explicit = complete(sources.explicit.name, sources.explicit.email);
34
+ if (!explicit) {
35
+ throw new b6p_core_bsjs_git_1.GitIdentityError("The commit author given has no name or no email");
36
+ }
37
+ return explicit;
38
+ }
39
+ const read = sources.readGitConfig ?? exports.runGitConfig;
40
+ const fromConfig = complete(await read(sources.dir, "user.name"), await read(sources.dir, "user.email"));
41
+ if (fromConfig) {
42
+ return fromConfig;
43
+ }
44
+ const env = sources.env ?? process.env;
45
+ const fromEnv = complete(env.GIT_AUTHOR_NAME, env.GIT_AUTHOR_EMAIL) ?? complete(env.GIT_COMMITTER_NAME, env.GIT_COMMITTER_EMAIL);
46
+ if (fromEnv) {
47
+ return fromEnv;
48
+ }
49
+ throw new b6p_core_bsjs_git_1.GitIdentityError("No commit author found: none was given, the git config for the script folder has no user.name and user.email, " +
50
+ "and the environment has no GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL");
51
+ }
52
+ //# sourceMappingURL=GitIdentity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GitIdentity.js","sourceRoot":"","sources":["../../src/script/GitIdentity.ts"],"names":[],"mappings":";;;AAgEA,gDAuBC;AAvFD,2DAA8C;AAC9C,2EAAyF;AAqCzF;;;GAGG;AACI,MAAM,YAAY,GAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CACxD,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACtB,IAAA,6BAAQ,EAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3F,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACzC,OAAO,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC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CAAC,kBAAkB,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACnH,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,MAAM,IAAI,oCAAgB,CACxB,gHAAgH;QAC9G,iEAAiE,CACpE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,321 @@
1
+ import { ScriptRepo, type GitIdentity } from "@bluestep-systems/b6p-core-bsjs-git";
2
+ import type { ScriptKey } from "../data/ScriptKey";
3
+ import type { ScriptContext } from "./ScriptContext";
4
+ /**
5
+ * Where the files of a script's draft live and which script they belong to: everything the git side needs to open the
6
+ * script's repo.
7
+ * @lastreviewed null
8
+ */
9
+ export interface DraftTarget {
10
+ readonly ctx: ScriptContext;
11
+ readonly script: ScriptKey;
12
+ /**
13
+ * The organization's origin, such as `https://org.bluestep.net/`.
14
+ * @lastreviewed null
15
+ */
16
+ readonly baseUrl: string;
17
+ /**
18
+ * The local `draft/` folder: the git working tree.
19
+ * @lastreviewed null
20
+ */
21
+ readonly draftPath: string;
22
+ }
23
+ /**
24
+ * What a legacy (pre-git) pull or push last synced for a file: the SHA-512 of the content, hex, or `null` when this
25
+ * machine has no record. Lets a draft folder created before git be told apart from edits made since.
26
+ * @lastreviewed null
27
+ */
28
+ export type LastSyncedLookup = (draftRelative: string) => Promise<string | null>;
29
+ /**
30
+ * Thrown when the script still publishes over WebDAV and switching it to git (which cannot be undone) was not confirmed.
31
+ * Nothing was switched and nothing local was changed.
32
+ * @lastreviewed null
33
+ */
34
+ export declare class GitSwitchDeclinedError extends Error {
35
+ constructor();
36
+ }
37
+ /**
38
+ * Thrown by a push when the draft folder's repo has another branch checked out: a commit would advance that branch while
39
+ * the push sends the draft branch, so nothing is committed.
40
+ * @lastreviewed null
41
+ */
42
+ export declare class GitWrongBranchError extends Error {
43
+ readonly branch: string | undefined;
44
+ constructor(branch: string | undefined);
45
+ }
46
+ /**
47
+ * Thrown by a pull when files hold changes that exist only in the git index (staged, then edited again): updating the
48
+ * working tree would discard them. Nothing was changed.
49
+ * @lastreviewed null
50
+ */
51
+ export declare class GitStagedChangesError extends Error {
52
+ readonly paths: string[];
53
+ constructor(paths: string[]);
54
+ }
55
+ /**
56
+ * Thrown by a pull when an incoming file would be written through a symbolic link out of the draft folder. Nothing was
57
+ * changed.
58
+ * @lastreviewed null
59
+ */
60
+ export declare class GitSymlinkError extends Error {
61
+ readonly paths: string[];
62
+ constructor(paths: string[]);
63
+ }
64
+ /**
65
+ * Opens the script's repo on `dir` (the draft folder, or a scratch folder).
66
+ * @lastreviewed null
67
+ */
68
+ export declare function openRepo(target: DraftTarget, dir: string, author?: GitIdentity): Promise<ScriptRepo>;
69
+ /**
70
+ * Whether the draft folder is already a git working tree.
71
+ * @lastreviewed null
72
+ */
73
+ export declare function isGitWorkingTree(ctx: ScriptContext, draftPath: string): Promise<boolean>;
74
+ /**
75
+ * The rules of a script root's old `.gitignore` (which governed what a WebDAV push uploaded) as git rules for the repo
76
+ * rooted at `draft/`. That file's patterns matched paths relative to the script root, so only the ones that reached
77
+ * into `draft/` applied to the draft's files: `draft/<rest>` becomes `/<rest>` (anchored at the draft root) and
78
+ * `**` + `/<rest>` stays as it is. Everything else never matched a draft file and is dropped.
79
+ * @lastreviewed null
80
+ */
81
+ export declare function legacyIgnoreRulesForDraft(rootGitignore: string): string[];
82
+ /**
83
+ * What a pull did to the local draft.
84
+ * @lastreviewed null
85
+ */
86
+ export interface DraftPullOutcome {
87
+ /**
88
+ * Absolute paths of local files kept instead of being replaced by the platform's: edits to files the platform also
89
+ * changed, and local files (ignored or untracked) at paths the platform has started tracking.
90
+ * @lastreviewed null
91
+ */
92
+ readonly keptLocalPaths: string[];
93
+ /**
94
+ * Whether this pull switched the script from WebDAV to git (one-way).
95
+ * @lastreviewed null
96
+ */
97
+ readonly switchedToGit: boolean;
98
+ }
99
+ /**
100
+ * Options of {@link pullDraft}.
101
+ * @lastreviewed null
102
+ */
103
+ export interface DraftPullOptions {
104
+ /**
105
+ * The caller already confirmed switching a WebDAV script to git, so do not ask.
106
+ * @lastreviewed null
107
+ */
108
+ readonly enableGit?: boolean;
109
+ /**
110
+ * Draft-relative, `/`-separated paths whose platform copy wins even over a local edit.
111
+ * @lastreviewed null
112
+ */
113
+ readonly overwrite?: readonly string[];
114
+ /**
115
+ * What a pre-git sync recorded per file; only used when a draft folder with files but no repo is adopted.
116
+ * @lastreviewed null
117
+ */
118
+ readonly lastSynced?: LastSyncedLookup;
119
+ }
120
+ /**
121
+ * Brings the platform's draft into the local draft folder:
122
+ * - no repo: the script's mode is read first. A WebDAV script needs the one-way switch, confirmed before anything is
123
+ * switched or touched. An empty folder then gets a clone; a folder with files is bound to the repo as it stands (a
124
+ * file the platform has that differs from the local one is kept when its last sync record says it was edited here,
125
+ * and replaced otherwise);
126
+ * - a repo: fetches and fast-forwards. A local edit to a file the platform also changed, and a local ignored or
127
+ * untracked file at a path the platform now tracks, are kept and reported. Files the platform has that are missing
128
+ * locally are restored.
129
+ *
130
+ * Nothing is ever written through a symbolic link.
131
+ *
132
+ * @throws {GitSwitchDeclinedError} when a WebDAV script needs the switch and it was declined.
133
+ * @throws {GitNotFastForwardError} when the local draft has commits of its own and the platform moved too.
134
+ * @throws {GitStagedChangesError} when index-only changes would be discarded.
135
+ * @lastreviewed null
136
+ */
137
+ export declare function pullDraft(target: DraftTarget, options?: DraftPullOptions): Promise<DraftPullOutcome>;
138
+ /**
139
+ * Which files of a draft folder differ from the platform's draft.
140
+ * @lastreviewed null
141
+ */
142
+ export interface DraftAudit {
143
+ /**
144
+ * Draft-relative, `/`-separated paths the platform has that this folder lacks.
145
+ * @lastreviewed null
146
+ */
147
+ readonly missingLocally: string[];
148
+ /**
149
+ * Draft-relative paths present on both sides with different content.
150
+ * @lastreviewed null
151
+ */
152
+ readonly changed: string[];
153
+ }
154
+ /**
155
+ * Compares the local draft folder with the platform's draft. Fetches first; reads nothing else from the platform.
156
+ * @returns the differences, or `undefined` when the folder is not a git working tree yet (there is nothing to compare
157
+ * against without pulling it).
158
+ * @lastreviewed null
159
+ */
160
+ export declare function auditDraft(target: DraftTarget): Promise<DraftAudit | undefined>;
161
+ /**
162
+ * Options of {@link pushDraft}.
163
+ * @lastreviewed null
164
+ */
165
+ export interface DraftPushOptions {
166
+ readonly message: string;
167
+ /**
168
+ * Who the commit is by; the caller resolved it (see {@link resolveGitIdentity}).
169
+ * @lastreviewed null
170
+ */
171
+ readonly author: GitIdentity;
172
+ /**
173
+ * Whether to publish the pushed draft.
174
+ * @lastreviewed null
175
+ */
176
+ readonly snapshot: boolean;
177
+ /**
178
+ * A draft folder with no repo becomes the script's working tree (a push). Otherwise (a deploy) the folder is the
179
+ * source of someone else's script and is left alone: its files go through a scratch clone.
180
+ * @lastreviewed null
181
+ */
182
+ readonly adoptUnbound: boolean;
183
+ /**
184
+ * Write the build manifest into the commit: set it only after a snapshot build that succeeded and emitted
185
+ * everything, so the output and its manifest are committed together; leave it unset after a failed or partial build
186
+ * (an existing manifest then stays and goes stale, which a publish refuses), and for a push that did not build.
187
+ * `externallyBuilt` is the script's own flag: such a script gets no manifest.
188
+ * @lastreviewed null
189
+ */
190
+ readonly buildManifest?: {
191
+ readonly externallyBuilt?: boolean;
192
+ };
193
+ /**
194
+ * The caller already confirmed switching a WebDAV script to git, so do not ask.
195
+ * @lastreviewed null
196
+ */
197
+ readonly enableGit?: boolean;
198
+ /**
199
+ * Draft-relative paths whose overwrite the caller confirmed up front.
200
+ * @lastreviewed null
201
+ */
202
+ readonly preConfirmed?: readonly string[];
203
+ /**
204
+ * What a pre-git sync recorded per file; tells a local edit from a platform change in a folder without a repo.
205
+ * @lastreviewed null
206
+ */
207
+ readonly lastSynced?: LastSyncedLookup;
208
+ }
209
+ /**
210
+ * A refusal of the publish by the platform, structured: `reason` is the server's `extensions.reason` (for example
211
+ * `DRAFT_MOVED`, `BUILD_STALE`, `BUILD_MANIFEST_MISSING`, `BUILD_MANIFEST_INVALID`, `ENTRYPOINT_MISSING`) and `withheld`
212
+ * its `extensions.publish.withheld` (the stale paths, or the manifest's path; empty when the server gave none).
213
+ * @lastreviewed null
214
+ */
215
+ export interface PublishRefusal {
216
+ readonly reason: string;
217
+ readonly withheld: string[];
218
+ }
219
+ /**
220
+ * The publish half of a {@link DraftPushOutcome}.
221
+ * @lastreviewed null
222
+ */
223
+ export interface DraftPublishOutcome {
224
+ /**
225
+ * The commit the platform published, or `null` when the publish failed (see `error`).
226
+ * @lastreviewed null
227
+ */
228
+ readonly publishedSha: string | null;
229
+ /**
230
+ * Why the publish failed, when it did.
231
+ * @lastreviewed null
232
+ */
233
+ readonly error: string | null;
234
+ /**
235
+ * The platform's structured refusal, when it refused the publish (`PUBLISH_REFUSED`): its `reason` and the paths in
236
+ * `publish.withheld`. `null` for any other outcome.
237
+ * @lastreviewed null
238
+ */
239
+ readonly refusal: PublishRefusal | null;
240
+ /**
241
+ * Whether the platform's published branch is at `publishedSha` after the publish: `null` when it could not be read.
242
+ * @lastreviewed null
243
+ */
244
+ readonly liveVerified: boolean | null;
245
+ /**
246
+ * Draft-relative paths that differ between the published commit and the published branch, when they differ.
247
+ * @lastreviewed null
248
+ */
249
+ readonly liveMismatches: string[];
250
+ }
251
+ /**
252
+ * What {@link pushDraft} did.
253
+ * @lastreviewed null
254
+ */
255
+ export interface DraftPushOutcome {
256
+ /**
257
+ * The draft branch's head on the platform after the push.
258
+ * @lastreviewed null
259
+ */
260
+ readonly commitSha: string;
261
+ readonly switchedToGit: boolean;
262
+ /**
263
+ * Draft-relative paths that exist only on the platform and were kept because deleting them was not confirmed.
264
+ * @lastreviewed null
265
+ */
266
+ readonly keptPlatformOnly: string[];
267
+ /**
268
+ * Set when the push was asked to publish.
269
+ * @lastreviewed null
270
+ */
271
+ readonly publish?: DraftPublishOutcome;
272
+ }
273
+ /**
274
+ * The push's one overwrite confirmation, asked before anything leaves this machine. The safe answer is first so an
275
+ * empty answer and auto-confirm both decline.
276
+ * @param opts.paths Files that differ from a platform version nobody here has seen
277
+ * @param opts.deleted Files the platform deleted since the last sync that this push would bring back
278
+ * @throws an {@link Err.OverwriteDeclinedError} naming the files when the answer is not "Overwrite all".
279
+ * @lastreviewed null
280
+ */
281
+ export declare function confirmOverwrittenFiles(opts: {
282
+ ctx: Pick<ScriptContext, "prompt">;
283
+ paths: readonly string[];
284
+ deleted?: readonly string[];
285
+ isSnapshot: boolean;
286
+ preConfirmed?: readonly string[];
287
+ }): Promise<void>;
288
+ /**
289
+ * Commits the draft folder's changes to the script's draft branch, pushes it and, for a snapshot, publishes it.
290
+ *
291
+ * Where the repo lives depends on the folder, and the script's publish mode (read first, never assumed from a repo
292
+ * being there) decides whether a switch is needed:
293
+ * - a folder bound to this script's repo whose script is in git mode is pushed in place (and must have the draft
294
+ * branch checked out);
295
+ * - a folder with no repo (a push), or one bound to a read-only mirror of a script that still publishes over WebDAV, is
296
+ * bound to the repo, but only after every consent has been given: the scratch clone is read, the overwrite
297
+ * confirmation asked, and only then is the folder's `.git` installed;
298
+ * - a deploy, or a folder bound to some other script, copies its files through a scratch clone.
299
+ * A script still publishing over WebDAV is switched to git first, which is one-way and confirmed first (`enableGit`
300
+ * pre-confirms). Its platform draft cannot be compared before it is switched, so the overwrite confirmation for it
301
+ * follows the switch, and nothing is installed locally until it is given.
302
+ *
303
+ * Before anything is pushed, one confirmation covers every platform file the push would overwrite or bring back, and
304
+ * another every platform file with no local copy; the safe answers keep the platform's version. The files committed
305
+ * follow git's ignore rules, including the old script-root `.gitignore` rules ({@link legacyIgnoreRulesForDraft}).
306
+ * Nothing is read through a symbolic link.
307
+ *
308
+ * Once the push has succeeded, nothing that follows throws: a failed publish comes back as `publish.error`.
309
+ *
310
+ * @throws an {@link Err.OverwriteDeclinedError} when an overwrite is not confirmed.
311
+ * @throws {GitSwitchDeclinedError} when the switch is needed and declined.
312
+ * @throws {GitWrongBranchError} when the folder's repo has another branch checked out.
313
+ * @throws {BsjsGitError} (a typed subclass) when git or the platform refuses the push.
314
+ * @lastreviewed null
315
+ */
316
+ export declare function pushDraft(target: DraftTarget, options: DraftPushOptions): Promise<DraftPushOutcome>;
317
+ /**
318
+ * The draft folder of a script root, `<root>/draft`.
319
+ * @lastreviewed null
320
+ */
321
+ export declare function draftFolderOf(rootPath: string): string;