@jwilleke/ngdpbase-types 0.0.0 → 5.19.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/LICENSE +201 -0
- package/README.md +16 -2
- package/lib/packages/ngdpbase-types/index.d.ts +32 -0
- package/lib/packages/ngdpbase-types/testing.d.ts +43 -0
- package/lib/packages/ngdpbase-types/testing.js +53 -0
- package/lib/src/cache/CacheDependencies.d.ts +50 -0
- package/lib/src/cache/CacheDependencies.js +50 -0
- package/lib/src/cache/ICacheAdapter.d.ts +86 -0
- package/lib/src/cache/RegionCache.d.ts +171 -0
- package/lib/src/context/ActorContext.d.ts +48 -0
- package/lib/src/context/ActorContext.js +33 -0
- package/lib/src/context/ApiContext.d.ts +194 -0
- package/lib/src/context/ApiContext.js +273 -0
- package/lib/src/context/BaseContext.d.ts +110 -0
- package/lib/src/context/BaseContext.js +143 -0
- package/lib/src/context/JobContext.d.ts +153 -0
- package/lib/src/context/JobContext.js +144 -0
- package/lib/src/context/WikiContext.d.ts +404 -0
- package/lib/src/context/bootActions.d.ts +64 -0
- package/lib/src/context/bootActions.js +111 -0
- package/lib/src/converters/HtmlConverter.d.ts +70 -0
- package/lib/src/converters/IContentConverter.d.ts +94 -0
- package/lib/src/converters/JSPWikiConverter.d.ts +117 -0
- package/lib/src/converters/conversionWarning.d.ts +15 -0
- package/lib/src/converters/ncm/bridge.d.ts +22 -0
- package/lib/src/converters/ncm/existing.d.ts +23 -0
- package/lib/src/converters/ncm/fix/blocks.d.ts +89 -0
- package/lib/src/converters/ncm/fix/bulletMarkers.d.ts +21 -0
- package/lib/src/converters/ncm/fix/index.d.ts +36 -0
- package/lib/src/converters/ncm/fix/jspwikiBullets.d.ts +20 -0
- package/lib/src/converters/ncm/fix/jspwikiCodeMarkers.d.ts +38 -0
- package/lib/src/converters/ncm/fix/jspwikiHeadings.d.ts +25 -0
- package/lib/src/converters/ncm/fix/jspwikiIndent.d.ts +24 -0
- package/lib/src/converters/ncm/fix/jspwikiInsert.d.ts +21 -0
- package/lib/src/converters/ncm/fix/jspwikiItalic.d.ts +29 -0
- package/lib/src/converters/ncm/fix/jspwikiLinkLeftovers.d.ts +27 -0
- package/lib/src/converters/ncm/fix/moreInformationFooter.d.ts +25 -0
- package/lib/src/converters/ncm/fix/styleClosers.d.ts +25 -0
- package/lib/src/converters/ncm/fix/tightenLists.d.ts +30 -0
- package/lib/src/converters/ncm/fix/types.d.ts +33 -0
- package/lib/src/converters/ncm/footnotes.d.ts +39 -0
- package/lib/src/converters/ncm/images.d.ts +49 -0
- package/lib/src/converters/ncm/index.d.ts +20 -0
- package/lib/src/converters/ncm/links.d.ts +21 -0
- package/lib/src/converters/ncm/normalize.d.ts +39 -0
- package/lib/src/converters/ncm/placeholder.d.ts +25 -0
- package/lib/src/converters/ncm/tables.d.ts +36 -0
- package/lib/src/converters/ncm/types.d.ts +42 -0
- package/lib/src/http/egressPolicy.d.ts +52 -0
- package/lib/src/http/guardedFetch.d.ts +89 -0
- package/lib/src/http/guardedFetch.js +113 -0
- package/lib/src/http/guardedLookup.d.ts +48 -0
- package/lib/src/http/guardedLookup.js +73 -0
- package/lib/src/http/ssrf.d.ts +83 -0
- package/lib/src/http/ssrf.js +311 -0
- package/lib/src/mail/MailProvider.d.ts +36 -0
- package/lib/src/mail/NodemailerMailProvider.d.ts +26 -0
- package/lib/src/managers/AddonsManager.d.ts +691 -0
- package/lib/src/managers/AgentTokenManager.d.ts +269 -0
- package/lib/src/managers/AssetManager.d.ts +116 -0
- package/lib/src/managers/AttachmentManager.d.ts +1032 -0
- package/lib/src/managers/AuthManager.d.ts +1257 -0
- package/lib/src/managers/BackgroundJobManager.d.ts +434 -0
- package/lib/src/managers/BaseManager.d.ts +427 -0
- package/lib/src/managers/BaseManager.js +415 -0
- package/lib/src/managers/CacheManager.d.ts +159 -0
- package/lib/src/managers/CatalogManager.d.ts +235 -0
- package/lib/src/managers/CommentManager.d.ts +75 -0
- package/lib/src/managers/ConfigurationManager.d.ts +747 -0
- package/lib/src/managers/DatabaseManager.d.ts +188 -0
- package/lib/src/managers/DatabaseManager.js +590 -0
- package/lib/src/managers/EmailManager.d.ts +47 -0
- package/lib/src/managers/ExportManager.d.ts +129 -0
- package/lib/src/managers/ExportManager.js +420 -0
- package/lib/src/managers/FootnoteManager.d.ts +118 -0
- package/lib/src/managers/MediaManager.d.ts +279 -0
- package/lib/src/managers/MetricsManager.d.ts +89 -0
- package/lib/src/managers/NotificationManager.d.ts +165 -0
- package/lib/src/managers/OidcManager.d.ts +210 -0
- package/lib/src/managers/OrganizationManager.d.ts +107 -0
- package/lib/src/managers/PageManager.d.ts +1645 -0
- package/lib/src/managers/PersonManager.d.ts +48 -0
- package/lib/src/managers/PluginManager.d.ts +179 -0
- package/lib/src/managers/PluginManager.js +393 -0
- package/lib/src/managers/PolicyEvaluator.d.ts +213 -0
- package/lib/src/managers/RenderingManager.d.ts +358 -0
- package/lib/src/managers/RoleManager.d.ts +134 -0
- package/lib/src/managers/SearchManager.d.ts +402 -0
- package/lib/src/managers/ShareManager.d.ts +251 -0
- package/lib/src/managers/TemplateManager.d.ts +176 -0
- package/lib/src/managers/ThemeManager.d.ts +56 -0
- package/lib/src/managers/UserManager.d.ts +480 -0
- package/lib/src/managers/ValidationManager.d.ts +426 -0
- package/lib/src/managers/VariableManager.d.ts +145 -0
- package/lib/src/middleware/csrf.d.ts +3 -0
- package/lib/src/parsers/LinkParser.d.ts +457 -0
- package/lib/src/parsers/MarkupParser.d.ts +769 -0
- package/lib/src/parsers/context/ParseContext.d.ts +314 -0
- package/lib/src/parsers/data/emoji-map.d.ts +18 -0
- package/lib/src/parsers/dom/DOMBuilder.d.ts +210 -0
- package/lib/src/parsers/dom/DOMParser.d.ts +252 -0
- package/lib/src/parsers/dom/Tokenizer.d.ts +358 -0
- package/lib/src/parsers/dom/WikiDocument.d.ts +272 -0
- package/lib/src/parsers/dom/handlers/DOMLinkHandler.d.ts +260 -0
- package/lib/src/parsers/dom/handlers/DOMPluginHandler.d.ts +212 -0
- package/lib/src/parsers/dom/handlers/DOMVariableHandler.d.ts +171 -0
- package/lib/src/parsers/filters/BaseFilter.d.ts +269 -0
- package/lib/src/parsers/filters/FilterChain.d.ts +320 -0
- package/lib/src/parsers/handlers/BaseSyntaxHandler.d.ts +331 -0
- package/lib/src/parsers/handlers/HandlerRegistry.d.ts +225 -0
- package/lib/src/parsers/handlers/JSPWikiPreprocessor.d.ts +89 -0
- package/lib/src/parsers/handlers/LinkParserHandler.d.ts +80 -0
- package/lib/src/parsers/handlers/PluginSyntaxHandler.d.ts +78 -0
- package/lib/src/parsers/handlers/WikiFormHandler.d.ts +149 -0
- package/lib/src/parsers/handlers/WikiTagHandler.d.ts +125 -0
- package/lib/src/parsers/jspwikiTableRow.d.ts +39 -0
- package/lib/src/parsers/styleBlockSyntax.d.ts +14 -0
- package/lib/src/plugins/types.d.ts +79 -0
- package/lib/src/providers/AgentTokenAuthProvider.d.ts +40 -0
- package/lib/src/providers/AuthentikBearerAuthProvider.d.ts +75 -0
- package/lib/src/providers/BaseAttachmentProvider.d.ts +197 -0
- package/lib/src/providers/BaseAuthProvider.d.ts +220 -0
- package/lib/src/providers/BaseCacheProvider.d.ts +140 -0
- package/lib/src/providers/BaseCredentialsProvider.d.ts +84 -0
- package/lib/src/providers/BaseDatabaseProvider.d.ts +22 -0
- package/lib/src/providers/BaseDatabaseProvider.js +12 -0
- package/lib/src/providers/BaseLoggingProvider.d.ts +68 -0
- package/lib/src/providers/BaseLoggingProvider.js +37 -0
- package/lib/src/providers/BaseMediaProvider.d.ts +308 -0
- package/lib/src/providers/BasePageProvider.d.ts +337 -0
- package/lib/src/providers/BaseProvider.d.ts +98 -0
- package/lib/src/providers/BaseProvider.js +74 -0
- package/lib/src/providers/BaseSearchProvider.d.ts +362 -0
- package/lib/src/providers/BasicAttachmentProvider.d.ts +599 -0
- package/lib/src/providers/CloudflareAccessAuthProvider.d.ts +72 -0
- package/lib/src/providers/FileCredentialsProvider.d.ts +33 -0
- package/lib/src/providers/FileJobStateProvider.d.ts +58 -0
- package/lib/src/providers/FileLoggingProvider.d.ts +43 -0
- package/lib/src/providers/FileLoggingProvider.js +120 -0
- package/lib/src/providers/FileOidcAdapter.d.ts +25 -0
- package/lib/src/providers/FileSystemMediaProvider.d.ts +403 -0
- package/lib/src/providers/LunrSearchProvider.d.ts +280 -0
- package/lib/src/providers/MagicLinkAuthProvider.d.ts +125 -0
- package/lib/src/providers/NullCacheProvider.d.ts +72 -0
- package/lib/src/providers/OidcAuthProvider.d.ts +180 -0
- package/lib/src/providers/OidcBearerAuthProvider.d.ts +30 -0
- package/lib/src/providers/PasskeyAuthProvider.d.ts +58 -0
- package/lib/src/providers/PasswordAuthProvider.d.ts +20 -0
- package/lib/src/providers/SqliteDatabaseProvider.d.ts +55 -0
- package/lib/src/providers/SqliteDatabaseProvider.js +90 -0
- package/lib/src/providers/SqliteJobStateProvider.d.ts +41 -0
- package/lib/src/providers/databaseMigrations.d.ts +8 -0
- package/lib/src/providers/databaseMigrations.js +47 -0
- package/lib/src/providers/jobState.d.ts +99 -0
- package/lib/src/providers/lunrQueryToMiniSearch.d.ts +32 -0
- package/lib/src/providers/mediaFilenameDate.d.ts +22 -0
- package/lib/src/providers/sqliteBackup.d.ts +128 -0
- package/lib/src/providers/sqliteBackup.js +365 -0
- package/lib/src/providers/sqliteLocation.d.ts +17 -0
- package/lib/src/providers/sqliteLocation.js +55 -0
- package/lib/src/providers/sqliteMigrations.d.ts +48 -0
- package/lib/src/providers/sqliteMigrations.js +72 -0
- package/lib/src/rendering/githubAlerts.d.ts +22 -0
- package/lib/src/rendering/htmlPolicy.d.ts +76 -0
- package/lib/src/rendering/markdownConverter.d.ts +73 -0
- package/lib/src/security/PolicyDecisionPoint.d.ts +245 -0
- package/lib/src/security/PolicyInformationPoint.d.ts +448 -0
- package/lib/src/security/pageActions.d.ts +40 -0
- package/lib/src/security/permissions.generated.d.ts +78 -0
- package/lib/src/types/Asset.d.ts +414 -0
- package/lib/src/types/Catalog.d.ts +61 -0
- package/lib/src/types/Comment.d.ts +11 -0
- package/lib/src/types/Config.d.ts +388 -0
- package/lib/src/types/Organization.d.ts +78 -0
- package/lib/src/types/OrganizationProvider.d.ts +38 -0
- package/lib/src/types/Page.d.ts +220 -0
- package/lib/src/types/Person.d.ts +56 -0
- package/lib/src/types/PersonProvider.d.ts +25 -0
- package/lib/src/types/Policy.d.ts +139 -0
- package/lib/src/types/Policy.js +17 -0
- package/lib/src/types/Provider.d.ts +810 -0
- package/lib/src/types/Role.d.ts +84 -0
- package/lib/src/types/RoleProvider.d.ts +35 -0
- package/lib/src/types/Schema.d.ts +425 -0
- package/lib/src/types/Share.d.ts +172 -0
- package/lib/src/types/Share.js +81 -0
- package/lib/src/types/User.d.ts +304 -0
- package/lib/src/types/Version.d.ts +189 -0
- package/lib/src/types/WikiEngine.d.ts +128 -0
- package/lib/src/types/express.d.ts +120 -0
- package/lib/src/types/express.js +1 -0
- package/lib/src/types/guards.d.ts +78 -0
- package/lib/src/types/heic-decode.d.ts +16 -0
- package/lib/src/types/index.d.ts +19 -0
- package/lib/src/types/linkedom.d.ts +77 -0
- package/lib/src/types/markdown-it-plugins.d.ts +21 -0
- package/lib/src/utils/DeltaStorage.d.ts +118 -0
- package/lib/src/utils/LocaleUtils.d.ts +105 -0
- package/lib/src/utils/LocaleUtils.js +294 -0
- package/lib/src/utils/PageNameMatcher.d.ts +98 -0
- package/lib/src/utils/PathPreflight.d.ts +38 -0
- package/lib/src/utils/PathPreflight.js +50 -0
- package/lib/src/utils/SectionUtils.d.ts +40 -0
- package/lib/src/utils/addonConfigLayer.d.ts +144 -0
- package/lib/src/utils/addonConfigLayer.js +382 -0
- package/lib/src/utils/addonDatabaseRules.d.ts +25 -0
- package/lib/src/utils/addonDatabaseRules.js +57 -0
- package/lib/src/utils/addonHost.d.ts +51 -0
- package/lib/src/utils/addonHost.js +72 -0
- package/lib/src/utils/addonInstaller.d.ts +109 -0
- package/lib/src/utils/addonLock.d.ts +37 -0
- package/lib/src/utils/addonLock.js +48 -0
- package/lib/src/utils/addonPageSync.d.ts +45 -0
- package/lib/src/utils/addonProvenance.d.ts +48 -0
- package/lib/src/utils/addonTarball.d.ts +41 -0
- package/lib/src/utils/addonsPathResolver.d.ts +76 -0
- package/lib/src/utils/addonsPathResolver.js +129 -0
- package/lib/src/utils/assetMetadataTags.d.ts +66 -0
- package/lib/src/utils/atomicWrite.d.ts +28 -0
- package/lib/src/utils/auditConfigChange.d.ts +57 -0
- package/lib/src/utils/auditEventNames.d.ts +50 -0
- package/lib/src/utils/auditEventNames.generated.d.ts +169 -0
- package/lib/src/utils/auditEventNames.generated.js +174 -0
- package/lib/src/utils/auditEventNames.js +49 -0
- package/lib/src/utils/auditEvents.d.ts +265 -0
- package/lib/src/utils/auditEvents.js +309 -0
- package/lib/src/utils/auditRegistry.d.ts +102 -0
- package/lib/src/utils/auditRegistry.js +168 -0
- package/lib/src/utils/bip39English.d.ts +2 -0
- package/lib/src/utils/configEnvKeys.d.ts +68 -0
- package/lib/src/utils/configFiles.d.ts +74 -0
- package/lib/src/utils/configFiles.js +150 -0
- package/lib/src/utils/delegation.d.ts +48 -0
- package/lib/src/utils/deriveUsername.d.ts +21 -0
- package/lib/src/utils/explainMediaPath.d.ts +123 -0
- package/lib/src/utils/formerTitles.d.ts +69 -0
- package/lib/src/utils/frontmatterAccess.d.ts +54 -0
- package/lib/src/utils/headlessAdminPassword.d.ts +55 -0
- package/lib/src/utils/imageTransform.d.ts +52 -0
- package/lib/src/utils/instanceEnvSecret.d.ts +51 -0
- package/lib/src/utils/jobSlots.d.ts +43 -0
- package/lib/src/utils/keywordNormalizer.d.ts +127 -0
- package/lib/src/utils/logger.d.ts +70 -0
- package/lib/src/utils/logger.js +106 -0
- package/lib/src/utils/magicLinkDeviceState.d.ts +95 -0
- package/lib/src/utils/managerUtils.d.ts +40 -0
- package/lib/src/utils/migrateLegacyPrivateAttachments.d.ts +15 -0
- package/lib/src/utils/orgFilename.d.ts +22 -0
- package/lib/src/utils/pageFeature.d.ts +27 -0
- package/lib/src/utils/pageFrontmatter.d.ts +21 -0
- package/lib/src/utils/pageNotes.d.ts +150 -0
- package/lib/src/utils/pageTitleRule.d.ts +37 -0
- package/lib/src/utils/pageToArticle.d.ts +59 -0
- package/lib/src/utils/pageUrl.d.ts +18 -0
- package/lib/src/utils/passwordChange.d.ts +12 -0
- package/lib/src/utils/passwordHash.d.ts +60 -0
- package/lib/src/utils/permissionCatalog.d.ts +52 -0
- package/lib/src/utils/pluginFormatters.d.ts +452 -0
- package/lib/src/utils/pluginFormatters.js +714 -0
- package/lib/src/utils/privateLinkRewrite.d.ts +42 -0
- package/lib/src/utils/privateStoreAccess.d.ts +57 -0
- package/lib/src/utils/privateStoreAccess.js +65 -0
- package/lib/src/utils/privateStoreCatalogs.d.ts +40 -0
- package/lib/src/utils/privateStoreCrypto.d.ts +127 -0
- package/lib/src/utils/privateStoreDoor.d.ts +181 -0
- package/lib/src/utils/privateStoreExport.d.ts +72 -0
- package/lib/src/utils/privateStoreFiles.d.ts +120 -0
- package/lib/src/utils/privateStoreMeta.d.ts +64 -0
- package/lib/src/utils/privateStoreMigrations.d.ts +37 -0
- package/lib/src/utils/privateStorePath.d.ts +259 -0
- package/lib/src/utils/privateStorePath.js +436 -0
- package/lib/src/utils/privateStoreTakeout.d.ts +76 -0
- package/lib/src/utils/privateStoreUnlock.d.ts +175 -0
- package/lib/src/utils/proxyClaim.d.ts +59 -0
- package/lib/src/utils/proxyClaim.js +30 -0
- package/lib/src/utils/redactPrivateNames.d.ts +21 -0
- package/lib/src/utils/redactPrivateNames.js +89 -0
- package/lib/src/utils/redactSecrets.d.ts +58 -0
- package/lib/src/utils/redactSecrets.js +171 -0
- package/lib/src/utils/renameLinkRewrite.d.ts +112 -0
- package/lib/src/utils/roleGrants.d.ts +35 -0
- package/lib/src/utils/safeRedirect.d.ts +32 -0
- package/lib/src/utils/schedule.d.ts +54 -0
- package/lib/src/utils/secretFileMode.d.ts +17 -0
- package/lib/src/utils/seededShippedPages.d.ts +45 -0
- package/lib/src/utils/sensitiveValues.d.ts +59 -0
- package/lib/src/utils/sensitiveValues.js +106 -0
- package/lib/src/utils/sessionEnd.d.ts +12 -0
- package/lib/src/utils/sessionGeneration.d.ts +24 -0
- package/lib/src/utils/sessionIdle.d.ts +41 -0
- package/lib/src/utils/sessionLimits.d.ts +68 -0
- package/lib/src/utils/shareLockbox.d.ts +64 -0
- package/lib/src/utils/sigstoreTrustedRoot.d.ts +33 -0
- package/lib/src/utils/sniffMime.d.ts +21 -0
- package/lib/src/utils/storeSearchIndex.d.ts +75 -0
- package/lib/src/utils/subjectMayDo.d.ts +21 -0
- package/lib/src/utils/systemCategoryRules.d.ts +30 -0
- package/lib/src/utils/systemCategoryRules.js +41 -0
- package/lib/src/utils/userCreateError.d.ts +62 -0
- package/lib/src/utils/username.d.ts +53 -0
- package/lib/src/utils/vaultUrlRewrite.d.ts +27 -0
- package/lib/src/utils/version.d.ts +84 -0
- package/lib/src/utils/videoFrame.d.ts +21 -0
- package/package.json +54 -3
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import BaseManager from './BaseManager.js';
|
|
2
|
+
import type { WikiEngine } from '../types/WikiEngine.js';
|
|
3
|
+
import { type JobContext } from '../context/JobContext.js';
|
|
4
|
+
import { type ScheduleInput } from '../utils/schedule.js';
|
|
5
|
+
import { type CatchUp, type Overlap } from '../utils/jobSlots.js';
|
|
6
|
+
import { type JobRunRecord, type JobStateProvider } from '../providers/jobState.js';
|
|
7
|
+
/**
|
|
8
|
+
* Callback supplied to job run functions so they can push live progress
|
|
9
|
+
* messages that the client can display while polling.
|
|
10
|
+
*/
|
|
11
|
+
export type ReportProgress = (message: string) => void;
|
|
12
|
+
/**
|
|
13
|
+
* What a run is handed besides progress (#1715): who asked, as {@link JobContext}
|
|
14
|
+
* — which stays flat and serialisable, so it is extended rather than changed —
|
|
15
|
+
* and what only a running job needs.
|
|
16
|
+
*/
|
|
17
|
+
export interface JobRunContext extends JobContext {
|
|
18
|
+
/** Aborted when the run times out. A long job checks it and stops. */
|
|
19
|
+
signal: AbortSignal;
|
|
20
|
+
/** The slot this run is for (ISO instant); null for a run nobody scheduled. */
|
|
21
|
+
slot: string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Set when this run picks up a slot an earlier attempt did not finish
|
|
24
|
+
* (#1716): which attempt this is, the last checkpoint that attempt saved
|
|
25
|
+
* (null if none), and why it ended. Null on a first attempt.
|
|
26
|
+
*/
|
|
27
|
+
resume: {
|
|
28
|
+
attempt: number;
|
|
29
|
+
checkpoint: unknown;
|
|
30
|
+
reason: string;
|
|
31
|
+
} | null;
|
|
32
|
+
/**
|
|
33
|
+
* Save a bookmark the next attempt receives as `resume.checkpoint`, e.g.
|
|
34
|
+
* `{ doneThrough: 311 }`. JSON only; larger than
|
|
35
|
+
* `ngdpbase.jobs.max-checkpoint-bytes` throws. Written at most once every
|
|
36
|
+
* 5 s, the latest winning; deleted when the run succeeds, kept when it fails.
|
|
37
|
+
* Kept only for a persisted scheduled job; elsewhere it is checked and dropped.
|
|
38
|
+
*/
|
|
39
|
+
checkpoint(data: unknown): void;
|
|
40
|
+
}
|
|
41
|
+
/** Why an administrator's action on a job was refused (#1718); `status` is the HTTP answer. */
|
|
42
|
+
export declare class JobActionError extends Error {
|
|
43
|
+
readonly status: 400 | 404 | 409;
|
|
44
|
+
constructor(message: string, status: 400 | 404 | 409);
|
|
45
|
+
}
|
|
46
|
+
/** A scheduled job as the admin page shows it (#1718). */
|
|
47
|
+
export interface ScheduledJobView {
|
|
48
|
+
id: string;
|
|
49
|
+
displayName: string;
|
|
50
|
+
/** The schedule in force, as written (a shorthand or an RRULE), and what it compiled to. */
|
|
51
|
+
schedule: string;
|
|
52
|
+
rrule: string;
|
|
53
|
+
timeZone: string;
|
|
54
|
+
catchUp: CatchUp;
|
|
55
|
+
overlap: Overlap;
|
|
56
|
+
maxAttempts: number;
|
|
57
|
+
persist: boolean;
|
|
58
|
+
/** False while `ngdpbase.jobs.<id>.enabled` is false: paused. */
|
|
59
|
+
enabled: boolean;
|
|
60
|
+
running: boolean;
|
|
61
|
+
nextSlot: string | null;
|
|
62
|
+
lastSlotDone: string | null;
|
|
63
|
+
/** The run the state names as current: running, waiting for a retry, or interrupted. */
|
|
64
|
+
current: JobRunRecord | null;
|
|
65
|
+
/** History, newest first. A run with no slot was started by hand. */
|
|
66
|
+
runs: JobRunRecord[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A job type that can be registered with the BackgroundJobManager.
|
|
70
|
+
*/
|
|
71
|
+
export interface JobDefinition {
|
|
72
|
+
/** Unique job type ID, e.g. 'pages.reindex' */
|
|
73
|
+
id: string;
|
|
74
|
+
/** Human-readable name shown in UI and notifications */
|
|
75
|
+
displayName: string;
|
|
76
|
+
/**
|
|
77
|
+
* When to run by itself (#1715): an RRULE, or a shorthand such as
|
|
78
|
+
* `end-of-month 06:00` (see `utils/schedule.ts`). Without one the job runs
|
|
79
|
+
* only when enqueued. `ngdpbase.jobs.<id>.schedule` overrides it, and
|
|
80
|
+
* `ngdpbase.jobs.<id>.enabled: false` stops it.
|
|
81
|
+
*/
|
|
82
|
+
schedule?: ScheduleInput;
|
|
83
|
+
/** Slots missed while the server was down or the job idle: `none`, `latest` (default) or `all` (newest 12). */
|
|
84
|
+
catchUp?: CatchUp;
|
|
85
|
+
/** Slots that came due while the job was still running: `queue` (default, one waits) or `skip`. */
|
|
86
|
+
overlap?: Overlap;
|
|
87
|
+
/**
|
|
88
|
+
* Milliseconds a run may take before it is aborted and failed. Scheduled
|
|
89
|
+
* jobs default to one hour; `0` is no limit, and must be asked for.
|
|
90
|
+
* `ngdpbase.jobs.max-timeout-ms` caps it when set. A job that is only ever
|
|
91
|
+
* enqueued has no limit unless it declares one.
|
|
92
|
+
*/
|
|
93
|
+
timeout?: number;
|
|
94
|
+
/**
|
|
95
|
+
* For a scheduled job: keep slots, history and locks where a restart finds
|
|
96
|
+
* them (default `true`). `false` keeps them in memory: no catch-up after a
|
|
97
|
+
* restart and no lock, so only for harmless maintenance ticks.
|
|
98
|
+
*
|
|
99
|
+
* For a run started by hand (`enqueue`, Run now) (#1746): `true` declares
|
|
100
|
+
* the job safe to run again, so a run a restart cut off is restarted, as the
|
|
101
|
+
* person who asked. Default `false` for a job that is only enqueued — a run
|
|
102
|
+
* of it that a restart cut off is reported, never repeated, because running
|
|
103
|
+
* it twice could do harm (an import posting twice). A scheduled job's Run
|
|
104
|
+
* now follows its `persist`.
|
|
105
|
+
*/
|
|
106
|
+
persist?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* The permission a person needs to start this job (#1746), as the route
|
|
109
|
+
* that enqueues it checks. Before a cut-off run is restarted as them, they
|
|
110
|
+
* must still hold it; if they do not, the run is reported, not restarted.
|
|
111
|
+
*/
|
|
112
|
+
permission?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Attempts a scheduled slot gets (default 3, #1716). A failed attempt — an
|
|
115
|
+
* error, a timeout, a failure result, or the server stopping mid-run — is
|
|
116
|
+
* tried again after 1, 5, then 15 minutes, with the same run id and slot.
|
|
117
|
+
* After the last, the slot is failed and the next slot runs as usual.
|
|
118
|
+
*/
|
|
119
|
+
maxAttempts?: number;
|
|
120
|
+
/**
|
|
121
|
+
* A routine maintenance tick (#1721): a success is neither audited nor
|
|
122
|
+
* notified — an every-minute sweep would bury both — while a failure is
|
|
123
|
+
* both, as for any job. Set by {@link BackgroundJobManager.registerMaintenance}.
|
|
124
|
+
*/
|
|
125
|
+
routine?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* The work to perform. Resolves with a JobResult.
|
|
128
|
+
*
|
|
129
|
+
* __`ctx` is mandatory (#631).__ Without it the actor this manager captured
|
|
130
|
+
* at `enqueue` reached the audit record and stopped there: `job-started`
|
|
131
|
+
* named who asked for a reindex while the reindex itself ran as nobody. That
|
|
132
|
+
* is the exact shape P1 in docs/security-posture.md warns about — a
|
|
133
|
+
* parameter that cannot carry provenance guarantees provenance is lost — and
|
|
134
|
+
* it was true of this signature for the whole first version of #631.
|
|
135
|
+
*
|
|
136
|
+
* A handler that needs to make a permission decision or write a record uses
|
|
137
|
+
* this; one that does neither still receives it, because a handler which can
|
|
138
|
+
* quietly grow into taking an action must not be able to do so anonymously.
|
|
139
|
+
*/
|
|
140
|
+
run: (reportProgress: ReportProgress, ctx: JobRunContext) => Promise<JobResult>;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Result returned by a completed job run.
|
|
144
|
+
*/
|
|
145
|
+
export interface JobResult {
|
|
146
|
+
success: boolean;
|
|
147
|
+
/** e.g. "Scanned 14 327 files, added 12, updated 3" */
|
|
148
|
+
summary?: string;
|
|
149
|
+
error?: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* State of a single job run instance.
|
|
153
|
+
*/
|
|
154
|
+
export interface JobRun {
|
|
155
|
+
runId: string;
|
|
156
|
+
jobId: string;
|
|
157
|
+
displayName: string;
|
|
158
|
+
/** Who asked for this work, and from where (#631). */
|
|
159
|
+
requestedBy: JobContext;
|
|
160
|
+
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
161
|
+
/** Live progress message set by the job via reportProgress(); cleared on completion */
|
|
162
|
+
progress?: string;
|
|
163
|
+
/** For a scheduled run: its slot, its attempt, and why the attempt before it ended (#1716). */
|
|
164
|
+
slot?: string;
|
|
165
|
+
attempt?: number;
|
|
166
|
+
resumeReason?: string;
|
|
167
|
+
/** Set at shutdown (#1717): the run was stopped to be handed to the next process, not failed. */
|
|
168
|
+
interrupted?: boolean;
|
|
169
|
+
startedAt: Date;
|
|
170
|
+
completedAt?: Date;
|
|
171
|
+
result?: JobResult;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* BackgroundJobManager — async long-running admin operations.
|
|
175
|
+
*
|
|
176
|
+
* Managers and plugins register job types at startup via registerJob().
|
|
177
|
+
* Callers enqueue a job by ID; the job runs in the background and the
|
|
178
|
+
* caller can poll getStatus(runId) for progress.
|
|
179
|
+
*
|
|
180
|
+
* Only one instance of a given jobId runs at a time — duplicate enqueue
|
|
181
|
+
* returns the existing runId.
|
|
182
|
+
*
|
|
183
|
+
* On completion, a system notification is posted via NotificationManager.
|
|
184
|
+
*/
|
|
185
|
+
declare class BackgroundJobManager extends BaseManager {
|
|
186
|
+
/** Registered job types, keyed by jobId */
|
|
187
|
+
private jobs;
|
|
188
|
+
/** All run records (completed runs are kept for status polling) */
|
|
189
|
+
private runs;
|
|
190
|
+
/** Maps jobId → runId for currently active (pending/running) runs */
|
|
191
|
+
private activeByJobId;
|
|
192
|
+
/** Jobs with a schedule (#1715), keyed by jobId. */
|
|
193
|
+
private scheduled;
|
|
194
|
+
private stateProvider;
|
|
195
|
+
private readonly clock;
|
|
196
|
+
private timer;
|
|
197
|
+
private ticking;
|
|
198
|
+
/** Scheduled runs in progress, so a caller can wait for them. */
|
|
199
|
+
private drains;
|
|
200
|
+
/** Jobs whose runs a restart cut off have been looked for, since this start (#1746). */
|
|
201
|
+
private recovered;
|
|
202
|
+
/** Set once shutdown begins: no slot starts after it (#1717). */
|
|
203
|
+
private stopping;
|
|
204
|
+
private handedOff;
|
|
205
|
+
/** Each running job's abort, by run id. */
|
|
206
|
+
private controllers;
|
|
207
|
+
/** For each running scheduled run: write it as interrupted and let go of its slot. */
|
|
208
|
+
private handoffs;
|
|
209
|
+
/**
|
|
210
|
+
* @param options - for tests: a state provider in place of the configured
|
|
211
|
+
* one, and the clock.
|
|
212
|
+
*/
|
|
213
|
+
private readonly checkpointThrottleMs;
|
|
214
|
+
constructor(engine: WikiEngine, options?: {
|
|
215
|
+
stateProvider?: JobStateProvider;
|
|
216
|
+
now?: () => Date;
|
|
217
|
+
checkpointThrottleMs?: number;
|
|
218
|
+
});
|
|
219
|
+
initialize(config?: Record<string, unknown>): Promise<void>;
|
|
220
|
+
private checkpointMaxBytes;
|
|
221
|
+
private configManager;
|
|
222
|
+
private setting;
|
|
223
|
+
/**
|
|
224
|
+
* Register a job type. Called at startup by managers and plugins.
|
|
225
|
+
*
|
|
226
|
+
* A job with a `schedule` is also scheduled (#1715). Its schedule, catch-up,
|
|
227
|
+
* overlap and timeout are checked here, so a mistake is the author's error
|
|
228
|
+
* at startup rather than a job that silently never runs.
|
|
229
|
+
*
|
|
230
|
+
* @throws Error naming what is wrong with a scheduled job's declaration
|
|
231
|
+
*/
|
|
232
|
+
registerJob(def: JobDefinition): void;
|
|
233
|
+
/**
|
|
234
|
+
* A routine maintenance tick (#1721): work whose next run does the same
|
|
235
|
+
* job, so a missed run costs nothing — a sweep, a retention purge, a folder
|
|
236
|
+
* rescan. One declaration for all of them, in place of a hand-rolled
|
|
237
|
+
* `setInterval`: it runs every `everyMs` (in whole minutes, at least one),
|
|
238
|
+
* catches nothing up, keeps nothing across a restart, never overlaps
|
|
239
|
+
* itself, and reports only failures. It is listed on Admin → Scheduled Jobs
|
|
240
|
+
* like any job, and can be run, paused or rescheduled from there.
|
|
241
|
+
*
|
|
242
|
+
* `everyMs` 0 or less registers the job without a schedule: it stops
|
|
243
|
+
* recurring, and can still be run by hand.
|
|
244
|
+
*/
|
|
245
|
+
registerMaintenance(spec: {
|
|
246
|
+
id: string;
|
|
247
|
+
displayName: string;
|
|
248
|
+
everyMs: number;
|
|
249
|
+
run: (ctx: JobRunContext) => Promise<string | void>;
|
|
250
|
+
}): void;
|
|
251
|
+
private compileScheduled;
|
|
252
|
+
/** A run's time limit: the job's own, else `fallback`, capped by `ngdpbase.jobs.max-timeout-ms` when set. */
|
|
253
|
+
private timeoutFor;
|
|
254
|
+
private compile;
|
|
255
|
+
/**
|
|
256
|
+
* `ngdpbase.jobs.<id>.schedule` in place of the registered schedule. One
|
|
257
|
+
* that does not compile is refused, reported once, and the schedule in force
|
|
258
|
+
* stays.
|
|
259
|
+
*/
|
|
260
|
+
private applyOverride;
|
|
261
|
+
/** The configured schedule and switch, read each look so an admin change applies without a restart. */
|
|
262
|
+
private refreshFromConfig;
|
|
263
|
+
/**
|
|
264
|
+
* Start looking for due slots (#1715). Called once the engine and its
|
|
265
|
+
* add-ons are up, so a catch-up run never meets a manager still starting.
|
|
266
|
+
*/
|
|
267
|
+
startScheduler(): void;
|
|
268
|
+
/**
|
|
269
|
+
* One look at every scheduled job: record the slots passed over, and start
|
|
270
|
+
* the ones chosen. Public so tests can drive the clock.
|
|
271
|
+
*/
|
|
272
|
+
tick(): Promise<void>;
|
|
273
|
+
private look;
|
|
274
|
+
/**
|
|
275
|
+
* A run the state still names as current, which this process is not
|
|
276
|
+
* running (#1716). True when it takes this look: it is held by another
|
|
277
|
+
* server, waiting out its backoff, or being resumed now.
|
|
278
|
+
*/
|
|
279
|
+
private handleUnfinished;
|
|
280
|
+
/**
|
|
281
|
+
* An attempt failed. With attempts left, the slot waits out its backoff and
|
|
282
|
+
* is tried again (true: the job waits). After the last, the slot is failed
|
|
283
|
+
* for good, audited, and the job goes on to its next slot (false).
|
|
284
|
+
*/
|
|
285
|
+
private afterFailedAttempt;
|
|
286
|
+
/** The job's next slot once `slot` is handled: never earlier than the one already recorded. */
|
|
287
|
+
private nextSlotAfter;
|
|
288
|
+
private startDrain;
|
|
289
|
+
/** Every scheduled job, its state and its recent history. */
|
|
290
|
+
listScheduledJobs(): Promise<ScheduledJobView[]>;
|
|
291
|
+
private scheduledOrThrow;
|
|
292
|
+
/** Refused while the job runs, waits for a retry, or the server is stopping: one run of a job at a time. */
|
|
293
|
+
private assertIdle;
|
|
294
|
+
/**
|
|
295
|
+
* Run a scheduled job now, outside its schedule (#1611 §9). As the person
|
|
296
|
+
* who asked, with their permissions. It is no slot: it marks no slot done
|
|
297
|
+
* and catches nothing up. Slots that come due while it runs follow the job's
|
|
298
|
+
* overlap rule, as for any run. A restart that cuts it off restarts it, as
|
|
299
|
+
* for any run started by hand (#1746). Returns the run id.
|
|
300
|
+
*/
|
|
301
|
+
runNow(jobId: string, requestedBy: JobContext): Promise<string>;
|
|
302
|
+
/**
|
|
303
|
+
* Run one slot again, under its own key (#1611 §9): one the scheduler
|
|
304
|
+
* skipped, or one that failed for good. As the person who asked. Success
|
|
305
|
+
* marks that slot done; the job's next slot does not move. Returns the run id.
|
|
306
|
+
*/
|
|
307
|
+
rerunSlot(jobId: string, slot: string, requestedBy: JobContext): Promise<string>;
|
|
308
|
+
/**
|
|
309
|
+
* Try a run that is waiting out its backoff now, rather than at its retry
|
|
310
|
+
* time (#1611 §9). Counts as its next attempt, like any retry.
|
|
311
|
+
*/
|
|
312
|
+
retryNow(jobId: string, requestedBy: JobContext): Promise<void>;
|
|
313
|
+
/** Resolves once every scheduled run started so far has finished. */
|
|
314
|
+
whenIdle(): Promise<void>;
|
|
315
|
+
/**
|
|
316
|
+
* Run the chosen slots one at a time, oldest first. A slot that fails with
|
|
317
|
+
* attempts left stops the drain: the job waits for its retry, and the slots
|
|
318
|
+
* after it are looked at again once it is done. `after` is the next slot
|
|
319
|
+
* once all are handled; null leaves it to each run.
|
|
320
|
+
*/
|
|
321
|
+
private drain;
|
|
322
|
+
/** One attempt at one slot. `retry` when it failed with attempts left. */
|
|
323
|
+
private runSlot;
|
|
324
|
+
/**
|
|
325
|
+
* A run's `ctx.checkpoint` (#1716). The size is checked at once, so an
|
|
326
|
+
* oversize checkpoint throws to the job. Writes are at most one per
|
|
327
|
+
* throttle interval, the latest winning, and `flush` writes what is still
|
|
328
|
+
* waiting. Without a provider (not persisted) a checkpoint is checked and dropped.
|
|
329
|
+
*/
|
|
330
|
+
private checkpointWriter;
|
|
331
|
+
private loadState;
|
|
332
|
+
private saveState;
|
|
333
|
+
/**
|
|
334
|
+
* Slots passed over are recorded, never dropped: one audit event for the
|
|
335
|
+
* lot, and the newest of them in the job's history (#1611 §2).
|
|
336
|
+
*/
|
|
337
|
+
private recordSkipped;
|
|
338
|
+
/** Who the scheduler acts as when nobody asked: the system principal, origin schedule. */
|
|
339
|
+
private schedulerContext;
|
|
340
|
+
private recordScheduleChange;
|
|
341
|
+
private recordSchedulerEvent;
|
|
342
|
+
/**
|
|
343
|
+
* Enqueue a job by ID. Returns the runId immediately.
|
|
344
|
+
* If the job is already pending/running, returns the existing runId.
|
|
345
|
+
*
|
|
346
|
+
* __`requestedBy` is mandatory, and positional rather than an option (#631).__
|
|
347
|
+
* This took a job id alone, so the identity of whoever triggered the work was
|
|
348
|
+
* discarded here — the route logged the username on the line above and threw
|
|
349
|
+
* it away on this one. Every defect this codebase has removed lately came
|
|
350
|
+
* from forgetting being safe; an optional context would be that shape again,
|
|
351
|
+
* and the first job added without one would go unattributed with nothing
|
|
352
|
+
* going red. Omitting it is now a compile error.
|
|
353
|
+
*
|
|
354
|
+
* Build it with `jobContextFromRequest(req.userContext)` when a person asked,
|
|
355
|
+
* or `jobContextFromSystem(pip.systemPrincipalName(), reason)` (the PolicyInformationPoint's) when
|
|
356
|
+
* nothing did (#631: the principal is a name from .env, never a constant).
|
|
357
|
+
*
|
|
358
|
+
* @throws Error if jobId is not registered
|
|
359
|
+
*/
|
|
360
|
+
enqueue(jobId: string, requestedBy: JobContext): Promise<string>;
|
|
361
|
+
/** Whether a cut-off run of this job may be run again: its declaration (see `persist`). */
|
|
362
|
+
private resumable;
|
|
363
|
+
/** Start a run by hand, or a cut-off one again. Returns its run id at once; the work runs in the background. */
|
|
364
|
+
private startHandRun;
|
|
365
|
+
/**
|
|
366
|
+
* One run started by hand. Its record — who asked, when, attempt, running —
|
|
367
|
+
* is written before the work starts and held under a lock with a heartbeat,
|
|
368
|
+
* so the next start can tell a run that a restart cut off from one a live
|
|
369
|
+
* server is still running. With no job state open it runs unrecorded, as
|
|
370
|
+
* before.
|
|
371
|
+
*/
|
|
372
|
+
private runByHand;
|
|
373
|
+
/**
|
|
374
|
+
* Look once, per job, for runs started by hand that a restart cut off
|
|
375
|
+
* (#1746). Called from every look until each registered job has been seen,
|
|
376
|
+
* so an add-on's job is looked at once it has registered. A job running
|
|
377
|
+
* here, or whose run another live server still holds, is looked at again
|
|
378
|
+
* next time.
|
|
379
|
+
*/
|
|
380
|
+
private recoverHandRuns;
|
|
381
|
+
/** False when a live server still holds one of the job's runs: look again later. */
|
|
382
|
+
private recoverHandRunsOf;
|
|
383
|
+
private recoverOne;
|
|
384
|
+
/** Whether the person who started a run still holds the job's permission — by policy, as at the time it is asked (P2). */
|
|
385
|
+
private stillHolds;
|
|
386
|
+
/** A run a restart cut off and that is not run again: recorded as failed, audited, and told to the admins. Never silent. */
|
|
387
|
+
private reportCutOff;
|
|
388
|
+
/**
|
|
389
|
+
* Get the current state of a run by runId.
|
|
390
|
+
* Returns null if the runId is unknown.
|
|
391
|
+
*/
|
|
392
|
+
getStatus(runId: string): JobRun | null;
|
|
393
|
+
/**
|
|
394
|
+
* Get all currently pending or running jobs.
|
|
395
|
+
*/
|
|
396
|
+
getActiveJobs(): JobRun[];
|
|
397
|
+
/**
|
|
398
|
+
* Get all registered job IDs.
|
|
399
|
+
*/
|
|
400
|
+
getRegisteredJobIds(): string[];
|
|
401
|
+
private executeJob;
|
|
402
|
+
/**
|
|
403
|
+
* Record who asked for this work, and how it ended (#631).
|
|
404
|
+
*
|
|
405
|
+
* Lazily resolved, following ConfigurationManager: AuditManager reads
|
|
406
|
+
* configuration, so holding a reference would invert the boot order, and it
|
|
407
|
+
* is absent during early boot — which `recordAuditEvent` already treats as a
|
|
408
|
+
* configuration state rather than a failure.
|
|
409
|
+
*
|
|
410
|
+
* on-failure: continue deliberately. A reindex must not be refused because its
|
|
411
|
+
* audit record could not be written; the drop is counted and surfaced by
|
|
412
|
+
* `recordAuditEvent` rather than being fatal.
|
|
413
|
+
*/
|
|
414
|
+
private recordJobEvent;
|
|
415
|
+
private sendNotification;
|
|
416
|
+
/**
|
|
417
|
+
* Hand running work to the next process (#1717, #1611 §7). No slot starts
|
|
418
|
+
* after this. Every running job's `ctx.signal` is aborted, and the jobs get
|
|
419
|
+
* `ngdpbase.jobs.shutdown-grace-ms` (default 5 s) to stop. A scheduled run
|
|
420
|
+
* that did not finish is written as `interrupted` with its last checkpoint
|
|
421
|
+
* and its slot lock released, so the next start resumes it at once, without
|
|
422
|
+
* counting an attempt. A job that ignores the signal is handed off anyway
|
|
423
|
+
* when the grace ends.
|
|
424
|
+
*
|
|
425
|
+
* Depends only on being called: the signal handlers in app.ts (SIGTERM,
|
|
426
|
+
* SIGINT) reach it through `engine.shutdown()`, which calls it before any
|
|
427
|
+
* other manager stops. A hard kill never gets here; its lock expires and the
|
|
428
|
+
* resume counts as an attempt (#1716).
|
|
429
|
+
*/
|
|
430
|
+
handOff(): Promise<void>;
|
|
431
|
+
private runHandOff;
|
|
432
|
+
shutdown(): Promise<void>;
|
|
433
|
+
}
|
|
434
|
+
export default BackgroundJobManager;
|