@hot-updater/plugin-core 1.0.0-rc.15 → 1.0.0-rc.17
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/dist/coreApi.d.cts +131 -0
- package/dist/coreApi.d.mts +131 -0
- package/dist/database/adapter.cjs +46 -0
- package/dist/database/adapter.d.cts +183 -0
- package/dist/database/adapter.d.mts +183 -0
- package/dist/database/adapter.mjs +38 -0
- package/dist/{insightsDistinctSummary.mjs → database/distinct.cjs} +25 -11
- package/dist/database/distinct.d.cts +16 -0
- package/dist/database/distinct.d.mts +16 -0
- package/dist/{insightsDistinctSummary.cjs → database/distinct.mjs} +21 -15
- package/dist/database/memoryAdapter.cjs +115 -0
- package/dist/database/memoryAdapter.d.cts +16 -0
- package/dist/database/memoryAdapter.d.mts +16 -0
- package/dist/database/memoryAdapter.mjs +115 -0
- package/dist/database/values.cjs +110 -0
- package/dist/database/values.d.cts +30 -0
- package/dist/database/values.d.mts +30 -0
- package/dist/database/values.mjs +100 -0
- package/dist/database/verifyAdapter.cjs +136 -0
- package/dist/database/verifyAdapter.d.cts +29 -0
- package/dist/database/verifyAdapter.d.mts +29 -0
- package/dist/database/verifyAdapter.mjs +135 -0
- package/dist/databaseErrors.cjs +30 -0
- package/dist/databaseErrors.d.cts +21 -0
- package/dist/databaseErrors.d.mts +21 -0
- package/dist/databaseErrors.mjs +28 -0
- package/dist/databaseJsonValue.cjs +0 -2
- package/dist/databaseJsonValue.d.cts +3 -3
- package/dist/databaseJsonValue.d.mts +3 -3
- package/dist/databaseJsonValue.mjs +1 -2
- package/dist/databaseMetadata.cjs +2 -2
- package/dist/databaseMetadata.mjs +1 -1
- package/dist/index.cjs +9 -39
- package/dist/index.d.cts +13 -19
- package/dist/index.d.mts +13 -19
- package/dist/index.mjs +7 -14
- package/dist/internal.cjs +37 -20
- package/dist/internal.d.cts +11 -12
- package/dist/internal.d.mts +11 -12
- package/dist/internal.mjs +8 -6
- package/dist/releaseCatalogCompiler.cjs +1 -1
- package/dist/releaseCatalogCompiler.mjs +2 -2
- package/dist/releaseCatalogMutation.cjs +0 -292
- package/dist/releaseCatalogMutation.d.cts +4 -45
- package/dist/releaseCatalogMutation.d.mts +4 -45
- package/dist/releaseCatalogMutation.mjs +1 -288
- package/dist/releaseManagement.cjs +0 -221
- package/dist/releaseManagement.d.cts +4 -28
- package/dist/releaseManagement.d.mts +4 -28
- package/dist/releaseManagement.mjs +1 -216
- package/dist/types/databaseConfig.cjs +5 -0
- package/dist/types/databaseConfig.d.cts +61 -0
- package/dist/types/databaseConfig.d.mts +61 -0
- package/dist/types/databaseConfig.mjs +5 -0
- package/dist/types/databaseOperations.d.cts +5 -174
- package/dist/types/databaseOperations.d.mts +5 -174
- package/dist/types/databaseRows.d.cts +1 -53
- package/dist/types/databaseRows.d.mts +1 -53
- package/dist/types/index.cjs +2 -0
- package/dist/types/index.d.cts +8 -74
- package/dist/types/index.d.mts +8 -74
- package/dist/types/index.mjs +2 -1
- package/dist/types/internal.d.cts +4 -8
- package/dist/types/internal.d.mts +4 -8
- package/dist/types/models.d.cts +14 -0
- package/dist/types/models.d.mts +14 -0
- package/dist/types/public.d.cts +4 -3
- package/dist/types/public.d.mts +4 -3
- package/package.json +1 -1
- package/dist/calculatePagination.cjs +0 -25
- package/dist/calculatePagination.d.cts +0 -12
- package/dist/calculatePagination.d.mts +0 -12
- package/dist/calculatePagination.mjs +0 -25
- package/dist/createDatabasePlugin.cjs +0 -875
- package/dist/createDatabasePlugin.d.cts +0 -28
- package/dist/createDatabasePlugin.d.mts +0 -28
- package/dist/createDatabasePlugin.mjs +0 -871
- package/dist/databaseClient.cjs +0 -117
- package/dist/databaseClient.d.cts +0 -32
- package/dist/databaseClient.d.mts +0 -32
- package/dist/databaseClient.mjs +0 -114
- package/dist/databaseClientReads.cjs +0 -115
- package/dist/databaseClientReads.mjs +0 -113
- package/dist/databaseClientUpdates.cjs +0 -37
- package/dist/databaseClientUpdates.d.cts +0 -11
- package/dist/databaseClientUpdates.d.mts +0 -11
- package/dist/databaseClientUpdates.mjs +0 -35
- package/dist/databasePluginCrud.cjs +0 -87
- package/dist/databasePluginCrud.d.cts +0 -4
- package/dist/databasePluginCrud.d.mts +0 -4
- package/dist/databasePluginCrud.mjs +0 -86
- package/dist/databasePluginCrudValidation.d.cts +0 -6
- package/dist/databasePluginCrudValidation.d.mts +0 -6
- package/dist/databasePluginCrudValidationErrors.cjs +0 -11
- package/dist/databasePluginCrudValidationErrors.d.cts +0 -9
- package/dist/databasePluginCrudValidationErrors.d.mts +0 -9
- package/dist/databasePluginCrudValidationErrors.mjs +0 -11
- package/dist/databasePluginCrudValidationFields.cjs +0 -284
- package/dist/databasePluginCrudValidationFields.d.cts +0 -1
- package/dist/databasePluginCrudValidationFields.d.mts +0 -1
- package/dist/databasePluginCrudValidationFields.mjs +0 -272
- package/dist/databasePluginCrudValidationMutations.cjs +0 -88
- package/dist/databasePluginCrudValidationMutations.d.cts +0 -1
- package/dist/databasePluginCrudValidationMutations.d.mts +0 -1
- package/dist/databasePluginCrudValidationMutations.mjs +0 -82
- package/dist/databasePluginCrudValidationQueries.cjs +0 -103
- package/dist/databasePluginCrudValidationQueries.d.cts +0 -2
- package/dist/databasePluginCrudValidationQueries.d.mts +0 -2
- package/dist/databasePluginCrudValidationQueries.mjs +0 -97
- package/dist/databasePluginCrudValidationRows.cjs +0 -55
- package/dist/databasePluginCrudValidationRows.d.cts +0 -1
- package/dist/databasePluginCrudValidationRows.d.mts +0 -1
- package/dist/databasePluginCrudValidationRows.mjs +0 -53
- package/dist/databasePluginTransaction.cjs +0 -7
- package/dist/databasePluginTransaction.mjs +0 -7
- package/dist/insightsContract.cjs +0 -192
- package/dist/insightsContract.d.cts +0 -9
- package/dist/insightsContract.d.mts +0 -9
- package/dist/insightsContract.mjs +0 -189
- package/dist/insightsDistinctSummary.d.cts +0 -12
- package/dist/insightsDistinctSummary.d.mts +0 -12
- package/dist/insightsLatestQueries.cjs +0 -53
- package/dist/insightsLatestQueries.d.cts +0 -13
- package/dist/insightsLatestQueries.d.mts +0 -13
- package/dist/insightsLatestQueries.mjs +0 -52
- package/dist/insightsOverview.cjs +0 -139
- package/dist/insightsOverview.d.cts +0 -40
- package/dist/insightsOverview.d.mts +0 -40
- package/dist/insightsOverview.mjs +0 -135
- package/dist/paginateBundles.cjs +0 -53
- package/dist/paginateBundles.d.cts +0 -13
- package/dist/paginateBundles.d.mts +0 -13
- package/dist/paginateBundles.mjs +0 -53
- package/dist/queryBundles.cjs +0 -34
- package/dist/queryBundles.d.cts +0 -9
- package/dist/queryBundles.d.mts +0 -9
- package/dist/queryBundles.mjs +0 -32
- package/dist/requestBundleCache.cjs +0 -22
- package/dist/requestBundleCache.d.cts +0 -8
- package/dist/requestBundleCache.d.mts +0 -8
- package/dist/requestBundleCache.mjs +0 -22
- package/dist/types/database.d.cts +0 -5
- package/dist/types/database.d.mts +0 -5
- package/dist/types/databaseFields.cjs +0 -85
- package/dist/types/databaseFields.d.cts +0 -12
- package/dist/types/databaseFields.d.mts +0 -12
- package/dist/types/databaseFields.mjs +0 -85
- package/dist/types/databasePlugin.d.cts +0 -388
- package/dist/types/databasePlugin.d.mts +0 -388
- package/dist/types/databaseQuery.d.cts +0 -46
- package/dist/types/databaseQuery.d.mts +0 -46
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { BundlePatchRow, BundleRow, ChannelRow, ReleaseCatalogRow, ReleaseRow } from "./types/databaseRows.cjs";
|
|
2
|
+
import { ChannelDeleteResult } from "./types/models.cjs";
|
|
3
|
+
import { Bundle } from "./types/index.cjs";
|
|
4
|
+
import { ReleaseCatalogMutationPreflight, ReleaseCatalogMutationResult, ReleaseCatalogRebuildPreflight, ReleaseCatalogRebuildResult } from "./releaseCatalogMutation.cjs";
|
|
5
|
+
import { PromoteReleaseResult, ReleasePolicyPatch } from "./releaseManagement.cjs";
|
|
6
|
+
//#region src/coreApi.d.ts
|
|
7
|
+
/** A keyset page: rows strictly after `after`, in `order`, at most `limit`. */
|
|
8
|
+
interface KeysetInput {
|
|
9
|
+
readonly order?: "asc" | "desc";
|
|
10
|
+
/** The last key a previous page returned. */
|
|
11
|
+
readonly after?: string;
|
|
12
|
+
readonly limit: number;
|
|
13
|
+
}
|
|
14
|
+
/** A release list's filter: exactly the sets the release indexes serve. */
|
|
15
|
+
type ReleaseFilter = {
|
|
16
|
+
readonly kind: "all";
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "channelPlatform";
|
|
19
|
+
readonly channelId: string;
|
|
20
|
+
readonly platform: "ios" | "android";
|
|
21
|
+
readonly enabled?: boolean;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "bundle";
|
|
24
|
+
readonly bundleId: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: "scope";
|
|
27
|
+
readonly scopeKey: string;
|
|
28
|
+
readonly enabled?: boolean;
|
|
29
|
+
};
|
|
30
|
+
interface BundleDetail {
|
|
31
|
+
readonly bundle: BundleRow;
|
|
32
|
+
readonly patches: BundlePatchRow[];
|
|
33
|
+
/** Patches that start from this bundle. */
|
|
34
|
+
readonly childCount: number;
|
|
35
|
+
}
|
|
36
|
+
/** How a deploy publishes its bundle in one channel's catalog. */
|
|
37
|
+
interface DeployReleasePolicy {
|
|
38
|
+
readonly channel: string;
|
|
39
|
+
readonly enabled: boolean;
|
|
40
|
+
readonly fingerprintHash: string | null;
|
|
41
|
+
readonly message: string | null;
|
|
42
|
+
readonly rolloutCohortCount?: number;
|
|
43
|
+
readonly shouldForceUpdate: boolean;
|
|
44
|
+
readonly targetAppVersion: string | null;
|
|
45
|
+
readonly targetCohorts?: string[];
|
|
46
|
+
}
|
|
47
|
+
/** A new bundle and the release that publishes it. */
|
|
48
|
+
interface BundleDeployment {
|
|
49
|
+
readonly bundle: Bundle;
|
|
50
|
+
readonly release: DeployReleasePolicy;
|
|
51
|
+
}
|
|
52
|
+
/** A new release for a bundle the database already holds, such as a republish. */
|
|
53
|
+
interface StoredBundleDeployment {
|
|
54
|
+
readonly bundleId: string;
|
|
55
|
+
readonly release: DeployReleasePolicy;
|
|
56
|
+
}
|
|
57
|
+
type Deployment = BundleDeployment | StoredBundleDeployment;
|
|
58
|
+
interface ReleaseTarget {
|
|
59
|
+
readonly releaseId: string;
|
|
60
|
+
/** Refuses the change when the release is at another revision. */
|
|
61
|
+
readonly expectedRevision?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Core's reads and typed operations, the same in process and over the admin
|
|
65
|
+
* API: bundles, Releases, their Catalogs, and channels. Every read goes
|
|
66
|
+
* through a declared index, and lists page by key.
|
|
67
|
+
*/
|
|
68
|
+
interface HotUpdaterCoreApi {
|
|
69
|
+
/**
|
|
70
|
+
* Checks the database before a command changes anything: its schema, and a
|
|
71
|
+
* self-hosted server's admin protocol. Throws what the first read would.
|
|
72
|
+
*/
|
|
73
|
+
ready(): Promise<void>;
|
|
74
|
+
getBundle(id: string): Promise<BundleDetail | null>;
|
|
75
|
+
listBundles(input: KeysetInput & {
|
|
76
|
+
readonly platform?: "ios" | "android";
|
|
77
|
+
}): Promise<BundleDetail[]>;
|
|
78
|
+
/** One counter row: every bundle, or one platform's. */
|
|
79
|
+
countBundles(platform?: "ios" | "android"): Promise<number>;
|
|
80
|
+
listPatchesFromBase(baseBundleId: string, input: KeysetInput): Promise<BundlePatchRow[]>;
|
|
81
|
+
/** Each base bundle's child count, from its reference counter: one batch read of the bundle rows. */
|
|
82
|
+
countBundleChildren(baseBundleIds: readonly string[]): Promise<Record<string, number>>;
|
|
83
|
+
/**
|
|
84
|
+
* Auto-patch bases for a new bundle, from its candidate key's catalog
|
|
85
|
+
* scope: older bundles whose enabled releases serve the key's fingerprint,
|
|
86
|
+
* or a range intersecting its app version range; newest release first.
|
|
87
|
+
*/
|
|
88
|
+
findBaseBundleIds(candidateKey: string, bundleId: string, limit: number): Promise<string[]>;
|
|
89
|
+
getRelease(id: string): Promise<ReleaseRow | null>;
|
|
90
|
+
listReleases(input: KeysetInput & {
|
|
91
|
+
readonly filter: ReleaseFilter;
|
|
92
|
+
}): Promise<ReleaseRow[]>;
|
|
93
|
+
getReleaseCatalogRow(scopeKey: string): Promise<ReleaseCatalogRow | null>;
|
|
94
|
+
listReleaseCatalogs(input: KeysetInput): Promise<ReleaseCatalogRow[]>;
|
|
95
|
+
listChannels(): Promise<ChannelRow[]>;
|
|
96
|
+
findChannelByName(name: string): Promise<ChannelRow | null>;
|
|
97
|
+
/**
|
|
98
|
+
* Writes each new bundle with its patches, and each release, with the next
|
|
99
|
+
* catalog of each scope, in one transaction. A stored bundle's deployment
|
|
100
|
+
* publishes a new release for it and writes no bundle.
|
|
101
|
+
*/
|
|
102
|
+
deploy(deployments: readonly Deployment[]): Promise<ReleaseCatalogMutationResult[]>;
|
|
103
|
+
updateReleasePolicy(input: ReleaseTarget & {
|
|
104
|
+
readonly patch: ReleasePolicyPatch;
|
|
105
|
+
}): Promise<ReleaseCatalogMutationResult>;
|
|
106
|
+
/** What `updateReleasePolicy` would write, without writing it. */
|
|
107
|
+
preflightReleasePolicy(input: ReleaseTarget & {
|
|
108
|
+
readonly patch: ReleasePolicyPatch;
|
|
109
|
+
}): Promise<ReleaseCatalogMutationPreflight>;
|
|
110
|
+
/** Deletes a disabled release; an enabled one refuses. */
|
|
111
|
+
deleteRelease(input: ReleaseTarget): Promise<ReleaseCatalogMutationResult>;
|
|
112
|
+
/** Copies a bundle release into another channel, and with `move` disables the source. */
|
|
113
|
+
promoteRelease(input: ReleaseTarget & {
|
|
114
|
+
readonly targetChannel: string;
|
|
115
|
+
readonly action?: "copy" | "move";
|
|
116
|
+
}): Promise<PromoteReleaseResult>;
|
|
117
|
+
rebuildReleaseCatalog(scopeKey: string): Promise<ReleaseCatalogRebuildResult>;
|
|
118
|
+
preflightReleaseCatalogRebuild(scopeKey: string): Promise<ReleaseCatalogRebuildPreflight>;
|
|
119
|
+
/** The channel named `name`, created when missing. */
|
|
120
|
+
ensureChannel(name: string): Promise<ChannelRow>;
|
|
121
|
+
/** Deletes a channel no release uses. */
|
|
122
|
+
deleteChannel(id: string): Promise<ChannelDeleteResult>;
|
|
123
|
+
/** Changes a bundle's fields; `patches`, when given, replaces its patches. */
|
|
124
|
+
updateBundle(id: string, update: Partial<Omit<Bundle, "id" | "patches">> & {
|
|
125
|
+
readonly patches?: Bundle["patches"];
|
|
126
|
+
}): Promise<void>;
|
|
127
|
+
/** Deletes bundles with their patches; a bundle a release uses refuses. */
|
|
128
|
+
deleteBundles(ids: readonly string[]): Promise<void>;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { BundleDeployment, BundleDetail, DeployReleasePolicy, Deployment, HotUpdaterCoreApi, KeysetInput, ReleaseFilter, ReleaseTarget, StoredBundleDeployment };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { BundlePatchRow, BundleRow, ChannelRow, ReleaseCatalogRow, ReleaseRow } from "./types/databaseRows.mjs";
|
|
2
|
+
import { ChannelDeleteResult } from "./types/models.mjs";
|
|
3
|
+
import { Bundle } from "./types/index.mjs";
|
|
4
|
+
import { ReleaseCatalogMutationPreflight, ReleaseCatalogMutationResult, ReleaseCatalogRebuildPreflight, ReleaseCatalogRebuildResult } from "./releaseCatalogMutation.mjs";
|
|
5
|
+
import { PromoteReleaseResult, ReleasePolicyPatch } from "./releaseManagement.mjs";
|
|
6
|
+
//#region src/coreApi.d.ts
|
|
7
|
+
/** A keyset page: rows strictly after `after`, in `order`, at most `limit`. */
|
|
8
|
+
interface KeysetInput {
|
|
9
|
+
readonly order?: "asc" | "desc";
|
|
10
|
+
/** The last key a previous page returned. */
|
|
11
|
+
readonly after?: string;
|
|
12
|
+
readonly limit: number;
|
|
13
|
+
}
|
|
14
|
+
/** A release list's filter: exactly the sets the release indexes serve. */
|
|
15
|
+
type ReleaseFilter = {
|
|
16
|
+
readonly kind: "all";
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "channelPlatform";
|
|
19
|
+
readonly channelId: string;
|
|
20
|
+
readonly platform: "ios" | "android";
|
|
21
|
+
readonly enabled?: boolean;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "bundle";
|
|
24
|
+
readonly bundleId: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: "scope";
|
|
27
|
+
readonly scopeKey: string;
|
|
28
|
+
readonly enabled?: boolean;
|
|
29
|
+
};
|
|
30
|
+
interface BundleDetail {
|
|
31
|
+
readonly bundle: BundleRow;
|
|
32
|
+
readonly patches: BundlePatchRow[];
|
|
33
|
+
/** Patches that start from this bundle. */
|
|
34
|
+
readonly childCount: number;
|
|
35
|
+
}
|
|
36
|
+
/** How a deploy publishes its bundle in one channel's catalog. */
|
|
37
|
+
interface DeployReleasePolicy {
|
|
38
|
+
readonly channel: string;
|
|
39
|
+
readonly enabled: boolean;
|
|
40
|
+
readonly fingerprintHash: string | null;
|
|
41
|
+
readonly message: string | null;
|
|
42
|
+
readonly rolloutCohortCount?: number;
|
|
43
|
+
readonly shouldForceUpdate: boolean;
|
|
44
|
+
readonly targetAppVersion: string | null;
|
|
45
|
+
readonly targetCohorts?: string[];
|
|
46
|
+
}
|
|
47
|
+
/** A new bundle and the release that publishes it. */
|
|
48
|
+
interface BundleDeployment {
|
|
49
|
+
readonly bundle: Bundle;
|
|
50
|
+
readonly release: DeployReleasePolicy;
|
|
51
|
+
}
|
|
52
|
+
/** A new release for a bundle the database already holds, such as a republish. */
|
|
53
|
+
interface StoredBundleDeployment {
|
|
54
|
+
readonly bundleId: string;
|
|
55
|
+
readonly release: DeployReleasePolicy;
|
|
56
|
+
}
|
|
57
|
+
type Deployment = BundleDeployment | StoredBundleDeployment;
|
|
58
|
+
interface ReleaseTarget {
|
|
59
|
+
readonly releaseId: string;
|
|
60
|
+
/** Refuses the change when the release is at another revision. */
|
|
61
|
+
readonly expectedRevision?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Core's reads and typed operations, the same in process and over the admin
|
|
65
|
+
* API: bundles, Releases, their Catalogs, and channels. Every read goes
|
|
66
|
+
* through a declared index, and lists page by key.
|
|
67
|
+
*/
|
|
68
|
+
interface HotUpdaterCoreApi {
|
|
69
|
+
/**
|
|
70
|
+
* Checks the database before a command changes anything: its schema, and a
|
|
71
|
+
* self-hosted server's admin protocol. Throws what the first read would.
|
|
72
|
+
*/
|
|
73
|
+
ready(): Promise<void>;
|
|
74
|
+
getBundle(id: string): Promise<BundleDetail | null>;
|
|
75
|
+
listBundles(input: KeysetInput & {
|
|
76
|
+
readonly platform?: "ios" | "android";
|
|
77
|
+
}): Promise<BundleDetail[]>;
|
|
78
|
+
/** One counter row: every bundle, or one platform's. */
|
|
79
|
+
countBundles(platform?: "ios" | "android"): Promise<number>;
|
|
80
|
+
listPatchesFromBase(baseBundleId: string, input: KeysetInput): Promise<BundlePatchRow[]>;
|
|
81
|
+
/** Each base bundle's child count, from its reference counter: one batch read of the bundle rows. */
|
|
82
|
+
countBundleChildren(baseBundleIds: readonly string[]): Promise<Record<string, number>>;
|
|
83
|
+
/**
|
|
84
|
+
* Auto-patch bases for a new bundle, from its candidate key's catalog
|
|
85
|
+
* scope: older bundles whose enabled releases serve the key's fingerprint,
|
|
86
|
+
* or a range intersecting its app version range; newest release first.
|
|
87
|
+
*/
|
|
88
|
+
findBaseBundleIds(candidateKey: string, bundleId: string, limit: number): Promise<string[]>;
|
|
89
|
+
getRelease(id: string): Promise<ReleaseRow | null>;
|
|
90
|
+
listReleases(input: KeysetInput & {
|
|
91
|
+
readonly filter: ReleaseFilter;
|
|
92
|
+
}): Promise<ReleaseRow[]>;
|
|
93
|
+
getReleaseCatalogRow(scopeKey: string): Promise<ReleaseCatalogRow | null>;
|
|
94
|
+
listReleaseCatalogs(input: KeysetInput): Promise<ReleaseCatalogRow[]>;
|
|
95
|
+
listChannels(): Promise<ChannelRow[]>;
|
|
96
|
+
findChannelByName(name: string): Promise<ChannelRow | null>;
|
|
97
|
+
/**
|
|
98
|
+
* Writes each new bundle with its patches, and each release, with the next
|
|
99
|
+
* catalog of each scope, in one transaction. A stored bundle's deployment
|
|
100
|
+
* publishes a new release for it and writes no bundle.
|
|
101
|
+
*/
|
|
102
|
+
deploy(deployments: readonly Deployment[]): Promise<ReleaseCatalogMutationResult[]>;
|
|
103
|
+
updateReleasePolicy(input: ReleaseTarget & {
|
|
104
|
+
readonly patch: ReleasePolicyPatch;
|
|
105
|
+
}): Promise<ReleaseCatalogMutationResult>;
|
|
106
|
+
/** What `updateReleasePolicy` would write, without writing it. */
|
|
107
|
+
preflightReleasePolicy(input: ReleaseTarget & {
|
|
108
|
+
readonly patch: ReleasePolicyPatch;
|
|
109
|
+
}): Promise<ReleaseCatalogMutationPreflight>;
|
|
110
|
+
/** Deletes a disabled release; an enabled one refuses. */
|
|
111
|
+
deleteRelease(input: ReleaseTarget): Promise<ReleaseCatalogMutationResult>;
|
|
112
|
+
/** Copies a bundle release into another channel, and with `move` disables the source. */
|
|
113
|
+
promoteRelease(input: ReleaseTarget & {
|
|
114
|
+
readonly targetChannel: string;
|
|
115
|
+
readonly action?: "copy" | "move";
|
|
116
|
+
}): Promise<PromoteReleaseResult>;
|
|
117
|
+
rebuildReleaseCatalog(scopeKey: string): Promise<ReleaseCatalogRebuildResult>;
|
|
118
|
+
preflightReleaseCatalogRebuild(scopeKey: string): Promise<ReleaseCatalogRebuildPreflight>;
|
|
119
|
+
/** The channel named `name`, created when missing. */
|
|
120
|
+
ensureChannel(name: string): Promise<ChannelRow>;
|
|
121
|
+
/** Deletes a channel no release uses. */
|
|
122
|
+
deleteChannel(id: string): Promise<ChannelDeleteResult>;
|
|
123
|
+
/** Changes a bundle's fields; `patches`, when given, replaces its patches. */
|
|
124
|
+
updateBundle(id: string, update: Partial<Omit<Bundle, "id" | "patches">> & {
|
|
125
|
+
readonly patches?: Bundle["patches"];
|
|
126
|
+
}): Promise<void>;
|
|
127
|
+
/** Deletes bundles with their patches; a bundle a release uses refuses. */
|
|
128
|
+
deleteBundles(ids: readonly string[]): Promise<void>;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { BundleDeployment, BundleDetail, DeployReleasePolicy, Deployment, HotUpdaterCoreApi, KeysetInput, ReleaseFilter, ReleaseTarget, StoredBundleDeployment };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region src/database/adapter.ts
|
|
2
|
+
const DATABASE_VERSION_COLUMN = "_v";
|
|
3
|
+
const DATABASE_MAX_QUERY_LIMIT = 500;
|
|
4
|
+
const DATABASE_MAX_MULTI_VALUES = 16;
|
|
5
|
+
var DatabaseSchemaError = class extends Error {
|
|
6
|
+
name = "DatabaseSchemaError";
|
|
7
|
+
};
|
|
8
|
+
const findPhysicalColumn = (table, name) => {
|
|
9
|
+
const column = table.columns.find((candidate) => candidate.name === name);
|
|
10
|
+
if (column === void 0) throw new DatabaseSchemaError(`${table.name} has no column ${name}.`);
|
|
11
|
+
return column;
|
|
12
|
+
};
|
|
13
|
+
const findPhysicalIndex = (table, name) => {
|
|
14
|
+
const index = table.indexes.find((candidate) => candidate.name === name);
|
|
15
|
+
if (index === void 0) throw new DatabaseSchemaError(`${table.name} has no index ${name}.`);
|
|
16
|
+
return index;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The columns that order an index read and close its cursors: the sort
|
|
20
|
+
* columns, then the key columns that neither `eq` nor `sort` fixes.
|
|
21
|
+
*/
|
|
22
|
+
const indexOrderColumns = (table, index) => [...index.sort, ...table.key.filter((column) => !index.sort.includes(column) && !index.eq.includes(column))];
|
|
23
|
+
/**
|
|
24
|
+
* When a row of a table with retention expires, in epoch milliseconds, or
|
|
25
|
+
* undefined when the table keeps its rows or the row's time is null.
|
|
26
|
+
*/
|
|
27
|
+
const expiresAt = (table, row) => {
|
|
28
|
+
const time = table.retention && row[table.retention.column];
|
|
29
|
+
return typeof time === "number" ? time + table.retention.ms : void 0;
|
|
30
|
+
};
|
|
31
|
+
/** The primary key of a row, in key-column order. */
|
|
32
|
+
const rowKey = (table, row) => table.key.map((column) => {
|
|
33
|
+
const value = row[column];
|
|
34
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") throw new DatabaseSchemaError(`${table.name}.${column} is a key column and must be a string, number, or boolean.`);
|
|
35
|
+
return value;
|
|
36
|
+
});
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.DATABASE_MAX_MULTI_VALUES = DATABASE_MAX_MULTI_VALUES;
|
|
39
|
+
exports.DATABASE_MAX_QUERY_LIMIT = DATABASE_MAX_QUERY_LIMIT;
|
|
40
|
+
exports.DATABASE_VERSION_COLUMN = DATABASE_VERSION_COLUMN;
|
|
41
|
+
exports.DatabaseSchemaError = DatabaseSchemaError;
|
|
42
|
+
exports.expiresAt = expiresAt;
|
|
43
|
+
exports.findPhysicalColumn = findPhysicalColumn;
|
|
44
|
+
exports.findPhysicalIndex = findPhysicalIndex;
|
|
45
|
+
exports.indexOrderColumns = indexOrderColumns;
|
|
46
|
+
exports.rowKey = rowKey;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
//#region src/database/adapter.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The storage adapter contract. An adapter implements `get`, `query`, and
|
|
4
|
+
* `write` with its backend's native features and knows nothing about Hot
|
|
5
|
+
* Updater's domain or plugins. Adapter authors import it from the public
|
|
6
|
+
* `@hot-updater/server/database` subpath.
|
|
7
|
+
*/
|
|
8
|
+
type DatabaseJson = null | boolean | number | string | readonly DatabaseJson[] | {
|
|
9
|
+
readonly [key: string]: DatabaseJson;
|
|
10
|
+
};
|
|
11
|
+
/** A stored value: a string, number, boolean, null, or JSON document. */
|
|
12
|
+
type DatabaseValue = DatabaseJson;
|
|
13
|
+
/** A value allowed in keys and indexes. */
|
|
14
|
+
type DatabaseKeyValue = string | number | boolean;
|
|
15
|
+
/** Primary-key values in the table's key-column order. */
|
|
16
|
+
type DatabaseKey = readonly DatabaseKeyValue[];
|
|
17
|
+
type StoredRow = {
|
|
18
|
+
readonly [column: string]: DatabaseValue;
|
|
19
|
+
};
|
|
20
|
+
/** `integer` holds safe integers; `number` holds any finite number. */
|
|
21
|
+
type PhysicalColumnType = "string" | "integer" | "number" | "boolean" | "json";
|
|
22
|
+
interface PhysicalColumn {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly type: PhysicalColumnType;
|
|
25
|
+
readonly nullable: boolean;
|
|
26
|
+
/** Strings only: the maximum length in UTF-16 code units; unbounded text when absent. */
|
|
27
|
+
readonly maxLength?: number;
|
|
28
|
+
/** Strings only: ASCII text, stored in single bytes where a backend limits index size (MySQL). */
|
|
29
|
+
readonly ascii?: true;
|
|
30
|
+
/** A whole number the backend stores when a writer omits the column; the engine's own columns default to 0. */
|
|
31
|
+
readonly default?: number;
|
|
32
|
+
/** A multi-valued field: an array of 1–16 values of `type`, indexable in `eq` only. */
|
|
33
|
+
readonly multi?: true;
|
|
34
|
+
}
|
|
35
|
+
interface PhysicalIndex {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly eq: readonly string[];
|
|
38
|
+
readonly sort: readonly string[];
|
|
39
|
+
/** The `eq` values identify at most one row. */
|
|
40
|
+
readonly unique?: true;
|
|
41
|
+
}
|
|
42
|
+
/** How long a table's rows live: `ms` past the epoch milliseconds in `column`. */
|
|
43
|
+
interface PhysicalRetention {
|
|
44
|
+
/** An integer column; a row whose value is null never expires. */
|
|
45
|
+
readonly column: string;
|
|
46
|
+
readonly ms: number;
|
|
47
|
+
}
|
|
48
|
+
interface PhysicalTable {
|
|
49
|
+
/** The logical name; each adapter applies its own table prefix. */
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly columns: readonly PhysicalColumn[];
|
|
52
|
+
/** Primary-key columns, in order. */
|
|
53
|
+
readonly key: readonly string[];
|
|
54
|
+
readonly indexes: readonly PhysicalIndex[];
|
|
55
|
+
/**
|
|
56
|
+
* Rows expire at {@link expiresAt}. A backend with a native TTL stamps it
|
|
57
|
+
* on every item the row has, its index copies included, and deletes them
|
|
58
|
+
* itself; any other adapter implements `prune`, which the engine calls.
|
|
59
|
+
*/
|
|
60
|
+
readonly retention?: PhysicalRetention;
|
|
61
|
+
}
|
|
62
|
+
interface QueryBound {
|
|
63
|
+
/** A prefix of the index's order columns (see `indexOrderColumns`). */
|
|
64
|
+
readonly values: readonly DatabaseKeyValue[];
|
|
65
|
+
readonly inclusive: boolean;
|
|
66
|
+
}
|
|
67
|
+
interface QueryRequest {
|
|
68
|
+
readonly index: string;
|
|
69
|
+
/** Values for the index's `eq` columns, in order. */
|
|
70
|
+
readonly eq: readonly DatabaseKeyValue[];
|
|
71
|
+
readonly lower?: QueryBound;
|
|
72
|
+
readonly upper?: QueryBound;
|
|
73
|
+
readonly order: "asc" | "desc";
|
|
74
|
+
/** 1–500 rows. */
|
|
75
|
+
readonly limit: number;
|
|
76
|
+
}
|
|
77
|
+
/** The row's `_v` at read time. */
|
|
78
|
+
interface WriteGuard {
|
|
79
|
+
readonly v: number;
|
|
80
|
+
}
|
|
81
|
+
/** At most one op per (table, key); guards see the pre-write state. */
|
|
82
|
+
type WriteOp = {
|
|
83
|
+
readonly type: "insert";
|
|
84
|
+
readonly table: PhysicalTable;
|
|
85
|
+
/** The complete row, `_v` included; the key must not exist. */
|
|
86
|
+
readonly row: StoredRow;
|
|
87
|
+
} | {
|
|
88
|
+
readonly type: "patch";
|
|
89
|
+
readonly table: PhysicalTable;
|
|
90
|
+
readonly key: DatabaseKey;
|
|
91
|
+
/** Named non-key columns only; the adapter sets `_v` to `guard.v + 1`. */
|
|
92
|
+
readonly set: StoredRow;
|
|
93
|
+
readonly guard: WriteGuard;
|
|
94
|
+
readonly previous: StoredRow;
|
|
95
|
+
} | {
|
|
96
|
+
readonly type: "delete";
|
|
97
|
+
readonly table: PhysicalTable;
|
|
98
|
+
readonly key: DatabaseKey;
|
|
99
|
+
readonly guard: WriteGuard;
|
|
100
|
+
readonly previous: StoredRow;
|
|
101
|
+
} | {
|
|
102
|
+
readonly type: "increment";
|
|
103
|
+
readonly table: PhysicalTable;
|
|
104
|
+
readonly key: DatabaseKey;
|
|
105
|
+
readonly by: Readonly<Record<string, number>>;
|
|
106
|
+
/** The row to create, before `by` applies, when the key does not exist. */
|
|
107
|
+
readonly init?: StoredRow;
|
|
108
|
+
readonly guard?: WriteGuard;
|
|
109
|
+
} | {
|
|
110
|
+
readonly type: "check";
|
|
111
|
+
readonly table: PhysicalTable;
|
|
112
|
+
readonly key: DatabaseKey;
|
|
113
|
+
readonly guard: WriteGuard;
|
|
114
|
+
};
|
|
115
|
+
type WriteResult = {
|
|
116
|
+
readonly ok: true;
|
|
117
|
+
} |
|
|
118
|
+
/** A guard failed, unique violations and missing rows included. */
|
|
119
|
+
{
|
|
120
|
+
readonly ok: false;
|
|
121
|
+
readonly failedOp: number;
|
|
122
|
+
} |
|
|
123
|
+
/** Transient: deadlock, serialization, SQLITE_BUSY, TransactionConflict, ABORTED. */
|
|
124
|
+
{
|
|
125
|
+
readonly ok: false;
|
|
126
|
+
readonly retry: true;
|
|
127
|
+
};
|
|
128
|
+
interface DatabaseAdapter {
|
|
129
|
+
readonly id: string;
|
|
130
|
+
/** True when the ops commit atomically in one write. */
|
|
131
|
+
fits(ops: readonly WriteOp[]): boolean;
|
|
132
|
+
/** Strongly consistent batch point read; results follow the order of keys. */
|
|
133
|
+
get(table: PhysicalTable, keys: readonly DatabaseKey[]): Promise<readonly (StoredRow | null)[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Index range read; loops native pages until `limit` rows or the range ends, never a short page.
|
|
136
|
+
* A row read from a key-value index copy may lack `_v`; the engine reads it whole with `get` where it guards.
|
|
137
|
+
*/
|
|
138
|
+
query(table: PhysicalTable, request: QueryRequest): Promise<readonly StoredRow[]>;
|
|
139
|
+
write(ops: readonly WriteOp[]): Promise<WriteResult>;
|
|
140
|
+
/**
|
|
141
|
+
* Deletes rows, as read, with their index entries: best effort, without
|
|
142
|
+
* guards, and not atomically. It is for rows the caller has already
|
|
143
|
+
* recorded as consumed, so deleting one twice, or one already gone, is
|
|
144
|
+
* harmless. A backend that bills transactional deletes more implements it
|
|
145
|
+
* with its plain batch delete; without it, callers delete through `write`.
|
|
146
|
+
*/
|
|
147
|
+
deleteConsumed?(table: PhysicalTable, rows: readonly StoredRow[]): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Deletes up to `limit` rows of a table with retention whose retention
|
|
150
|
+
* column is at or below `before`, oldest first (ties in any order), with
|
|
151
|
+
* their index entries, rechecking the column as it deletes, so a row a
|
|
152
|
+
* concurrent write moved past `before` stays. Resolves to the number
|
|
153
|
+
* deleted. A backend that expires rows natively leaves it out.
|
|
154
|
+
*/
|
|
155
|
+
prune?(table: PhysicalTable, before: number, limit: number): Promise<number>;
|
|
156
|
+
/** Called only by `@hot-updater/server/db` tooling. */
|
|
157
|
+
readonly migrations?: {
|
|
158
|
+
apply(tables: readonly PhysicalTable[]): Promise<void>;
|
|
159
|
+
};
|
|
160
|
+
dispose?(): Promise<void>;
|
|
161
|
+
}
|
|
162
|
+
declare const DATABASE_VERSION_COLUMN = "_v";
|
|
163
|
+
declare const DATABASE_MAX_QUERY_LIMIT = 500;
|
|
164
|
+
declare const DATABASE_MAX_MULTI_VALUES = 16;
|
|
165
|
+
declare class DatabaseSchemaError extends Error {
|
|
166
|
+
readonly name = "DatabaseSchemaError";
|
|
167
|
+
}
|
|
168
|
+
declare const findPhysicalColumn: (table: PhysicalTable, name: string) => PhysicalColumn;
|
|
169
|
+
declare const findPhysicalIndex: (table: PhysicalTable, name: string) => PhysicalIndex;
|
|
170
|
+
/**
|
|
171
|
+
* The columns that order an index read and close its cursors: the sort
|
|
172
|
+
* columns, then the key columns that neither `eq` nor `sort` fixes.
|
|
173
|
+
*/
|
|
174
|
+
declare const indexOrderColumns: (table: PhysicalTable, index: PhysicalIndex) => readonly string[];
|
|
175
|
+
/**
|
|
176
|
+
* When a row of a table with retention expires, in epoch milliseconds, or
|
|
177
|
+
* undefined when the table keeps its rows or the row's time is null.
|
|
178
|
+
*/
|
|
179
|
+
declare const expiresAt: (table: PhysicalTable, row: StoredRow) => number | undefined;
|
|
180
|
+
/** The primary key of a row, in key-column order. */
|
|
181
|
+
declare const rowKey: (table: PhysicalTable, row: StoredRow) => DatabaseKey;
|
|
182
|
+
//#endregion
|
|
183
|
+
export { DATABASE_MAX_MULTI_VALUES, DATABASE_MAX_QUERY_LIMIT, DATABASE_VERSION_COLUMN, DatabaseAdapter, DatabaseJson, DatabaseKey, DatabaseKeyValue, DatabaseSchemaError, DatabaseValue, PhysicalColumn, PhysicalColumnType, PhysicalIndex, PhysicalRetention, PhysicalTable, QueryBound, QueryRequest, StoredRow, WriteGuard, WriteOp, WriteResult, expiresAt, findPhysicalColumn, findPhysicalIndex, indexOrderColumns, rowKey };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
//#region src/database/adapter.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The storage adapter contract. An adapter implements `get`, `query`, and
|
|
4
|
+
* `write` with its backend's native features and knows nothing about Hot
|
|
5
|
+
* Updater's domain or plugins. Adapter authors import it from the public
|
|
6
|
+
* `@hot-updater/server/database` subpath.
|
|
7
|
+
*/
|
|
8
|
+
type DatabaseJson = null | boolean | number | string | readonly DatabaseJson[] | {
|
|
9
|
+
readonly [key: string]: DatabaseJson;
|
|
10
|
+
};
|
|
11
|
+
/** A stored value: a string, number, boolean, null, or JSON document. */
|
|
12
|
+
type DatabaseValue = DatabaseJson;
|
|
13
|
+
/** A value allowed in keys and indexes. */
|
|
14
|
+
type DatabaseKeyValue = string | number | boolean;
|
|
15
|
+
/** Primary-key values in the table's key-column order. */
|
|
16
|
+
type DatabaseKey = readonly DatabaseKeyValue[];
|
|
17
|
+
type StoredRow = {
|
|
18
|
+
readonly [column: string]: DatabaseValue;
|
|
19
|
+
};
|
|
20
|
+
/** `integer` holds safe integers; `number` holds any finite number. */
|
|
21
|
+
type PhysicalColumnType = "string" | "integer" | "number" | "boolean" | "json";
|
|
22
|
+
interface PhysicalColumn {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly type: PhysicalColumnType;
|
|
25
|
+
readonly nullable: boolean;
|
|
26
|
+
/** Strings only: the maximum length in UTF-16 code units; unbounded text when absent. */
|
|
27
|
+
readonly maxLength?: number;
|
|
28
|
+
/** Strings only: ASCII text, stored in single bytes where a backend limits index size (MySQL). */
|
|
29
|
+
readonly ascii?: true;
|
|
30
|
+
/** A whole number the backend stores when a writer omits the column; the engine's own columns default to 0. */
|
|
31
|
+
readonly default?: number;
|
|
32
|
+
/** A multi-valued field: an array of 1–16 values of `type`, indexable in `eq` only. */
|
|
33
|
+
readonly multi?: true;
|
|
34
|
+
}
|
|
35
|
+
interface PhysicalIndex {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly eq: readonly string[];
|
|
38
|
+
readonly sort: readonly string[];
|
|
39
|
+
/** The `eq` values identify at most one row. */
|
|
40
|
+
readonly unique?: true;
|
|
41
|
+
}
|
|
42
|
+
/** How long a table's rows live: `ms` past the epoch milliseconds in `column`. */
|
|
43
|
+
interface PhysicalRetention {
|
|
44
|
+
/** An integer column; a row whose value is null never expires. */
|
|
45
|
+
readonly column: string;
|
|
46
|
+
readonly ms: number;
|
|
47
|
+
}
|
|
48
|
+
interface PhysicalTable {
|
|
49
|
+
/** The logical name; each adapter applies its own table prefix. */
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly columns: readonly PhysicalColumn[];
|
|
52
|
+
/** Primary-key columns, in order. */
|
|
53
|
+
readonly key: readonly string[];
|
|
54
|
+
readonly indexes: readonly PhysicalIndex[];
|
|
55
|
+
/**
|
|
56
|
+
* Rows expire at {@link expiresAt}. A backend with a native TTL stamps it
|
|
57
|
+
* on every item the row has, its index copies included, and deletes them
|
|
58
|
+
* itself; any other adapter implements `prune`, which the engine calls.
|
|
59
|
+
*/
|
|
60
|
+
readonly retention?: PhysicalRetention;
|
|
61
|
+
}
|
|
62
|
+
interface QueryBound {
|
|
63
|
+
/** A prefix of the index's order columns (see `indexOrderColumns`). */
|
|
64
|
+
readonly values: readonly DatabaseKeyValue[];
|
|
65
|
+
readonly inclusive: boolean;
|
|
66
|
+
}
|
|
67
|
+
interface QueryRequest {
|
|
68
|
+
readonly index: string;
|
|
69
|
+
/** Values for the index's `eq` columns, in order. */
|
|
70
|
+
readonly eq: readonly DatabaseKeyValue[];
|
|
71
|
+
readonly lower?: QueryBound;
|
|
72
|
+
readonly upper?: QueryBound;
|
|
73
|
+
readonly order: "asc" | "desc";
|
|
74
|
+
/** 1–500 rows. */
|
|
75
|
+
readonly limit: number;
|
|
76
|
+
}
|
|
77
|
+
/** The row's `_v` at read time. */
|
|
78
|
+
interface WriteGuard {
|
|
79
|
+
readonly v: number;
|
|
80
|
+
}
|
|
81
|
+
/** At most one op per (table, key); guards see the pre-write state. */
|
|
82
|
+
type WriteOp = {
|
|
83
|
+
readonly type: "insert";
|
|
84
|
+
readonly table: PhysicalTable;
|
|
85
|
+
/** The complete row, `_v` included; the key must not exist. */
|
|
86
|
+
readonly row: StoredRow;
|
|
87
|
+
} | {
|
|
88
|
+
readonly type: "patch";
|
|
89
|
+
readonly table: PhysicalTable;
|
|
90
|
+
readonly key: DatabaseKey;
|
|
91
|
+
/** Named non-key columns only; the adapter sets `_v` to `guard.v + 1`. */
|
|
92
|
+
readonly set: StoredRow;
|
|
93
|
+
readonly guard: WriteGuard;
|
|
94
|
+
readonly previous: StoredRow;
|
|
95
|
+
} | {
|
|
96
|
+
readonly type: "delete";
|
|
97
|
+
readonly table: PhysicalTable;
|
|
98
|
+
readonly key: DatabaseKey;
|
|
99
|
+
readonly guard: WriteGuard;
|
|
100
|
+
readonly previous: StoredRow;
|
|
101
|
+
} | {
|
|
102
|
+
readonly type: "increment";
|
|
103
|
+
readonly table: PhysicalTable;
|
|
104
|
+
readonly key: DatabaseKey;
|
|
105
|
+
readonly by: Readonly<Record<string, number>>;
|
|
106
|
+
/** The row to create, before `by` applies, when the key does not exist. */
|
|
107
|
+
readonly init?: StoredRow;
|
|
108
|
+
readonly guard?: WriteGuard;
|
|
109
|
+
} | {
|
|
110
|
+
readonly type: "check";
|
|
111
|
+
readonly table: PhysicalTable;
|
|
112
|
+
readonly key: DatabaseKey;
|
|
113
|
+
readonly guard: WriteGuard;
|
|
114
|
+
};
|
|
115
|
+
type WriteResult = {
|
|
116
|
+
readonly ok: true;
|
|
117
|
+
} |
|
|
118
|
+
/** A guard failed, unique violations and missing rows included. */
|
|
119
|
+
{
|
|
120
|
+
readonly ok: false;
|
|
121
|
+
readonly failedOp: number;
|
|
122
|
+
} |
|
|
123
|
+
/** Transient: deadlock, serialization, SQLITE_BUSY, TransactionConflict, ABORTED. */
|
|
124
|
+
{
|
|
125
|
+
readonly ok: false;
|
|
126
|
+
readonly retry: true;
|
|
127
|
+
};
|
|
128
|
+
interface DatabaseAdapter {
|
|
129
|
+
readonly id: string;
|
|
130
|
+
/** True when the ops commit atomically in one write. */
|
|
131
|
+
fits(ops: readonly WriteOp[]): boolean;
|
|
132
|
+
/** Strongly consistent batch point read; results follow the order of keys. */
|
|
133
|
+
get(table: PhysicalTable, keys: readonly DatabaseKey[]): Promise<readonly (StoredRow | null)[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Index range read; loops native pages until `limit` rows or the range ends, never a short page.
|
|
136
|
+
* A row read from a key-value index copy may lack `_v`; the engine reads it whole with `get` where it guards.
|
|
137
|
+
*/
|
|
138
|
+
query(table: PhysicalTable, request: QueryRequest): Promise<readonly StoredRow[]>;
|
|
139
|
+
write(ops: readonly WriteOp[]): Promise<WriteResult>;
|
|
140
|
+
/**
|
|
141
|
+
* Deletes rows, as read, with their index entries: best effort, without
|
|
142
|
+
* guards, and not atomically. It is for rows the caller has already
|
|
143
|
+
* recorded as consumed, so deleting one twice, or one already gone, is
|
|
144
|
+
* harmless. A backend that bills transactional deletes more implements it
|
|
145
|
+
* with its plain batch delete; without it, callers delete through `write`.
|
|
146
|
+
*/
|
|
147
|
+
deleteConsumed?(table: PhysicalTable, rows: readonly StoredRow[]): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Deletes up to `limit` rows of a table with retention whose retention
|
|
150
|
+
* column is at or below `before`, oldest first (ties in any order), with
|
|
151
|
+
* their index entries, rechecking the column as it deletes, so a row a
|
|
152
|
+
* concurrent write moved past `before` stays. Resolves to the number
|
|
153
|
+
* deleted. A backend that expires rows natively leaves it out.
|
|
154
|
+
*/
|
|
155
|
+
prune?(table: PhysicalTable, before: number, limit: number): Promise<number>;
|
|
156
|
+
/** Called only by `@hot-updater/server/db` tooling. */
|
|
157
|
+
readonly migrations?: {
|
|
158
|
+
apply(tables: readonly PhysicalTable[]): Promise<void>;
|
|
159
|
+
};
|
|
160
|
+
dispose?(): Promise<void>;
|
|
161
|
+
}
|
|
162
|
+
declare const DATABASE_VERSION_COLUMN = "_v";
|
|
163
|
+
declare const DATABASE_MAX_QUERY_LIMIT = 500;
|
|
164
|
+
declare const DATABASE_MAX_MULTI_VALUES = 16;
|
|
165
|
+
declare class DatabaseSchemaError extends Error {
|
|
166
|
+
readonly name = "DatabaseSchemaError";
|
|
167
|
+
}
|
|
168
|
+
declare const findPhysicalColumn: (table: PhysicalTable, name: string) => PhysicalColumn;
|
|
169
|
+
declare const findPhysicalIndex: (table: PhysicalTable, name: string) => PhysicalIndex;
|
|
170
|
+
/**
|
|
171
|
+
* The columns that order an index read and close its cursors: the sort
|
|
172
|
+
* columns, then the key columns that neither `eq` nor `sort` fixes.
|
|
173
|
+
*/
|
|
174
|
+
declare const indexOrderColumns: (table: PhysicalTable, index: PhysicalIndex) => readonly string[];
|
|
175
|
+
/**
|
|
176
|
+
* When a row of a table with retention expires, in epoch milliseconds, or
|
|
177
|
+
* undefined when the table keeps its rows or the row's time is null.
|
|
178
|
+
*/
|
|
179
|
+
declare const expiresAt: (table: PhysicalTable, row: StoredRow) => number | undefined;
|
|
180
|
+
/** The primary key of a row, in key-column order. */
|
|
181
|
+
declare const rowKey: (table: PhysicalTable, row: StoredRow) => DatabaseKey;
|
|
182
|
+
//#endregion
|
|
183
|
+
export { DATABASE_MAX_MULTI_VALUES, DATABASE_MAX_QUERY_LIMIT, DATABASE_VERSION_COLUMN, DatabaseAdapter, DatabaseJson, DatabaseKey, DatabaseKeyValue, DatabaseSchemaError, DatabaseValue, PhysicalColumn, PhysicalColumnType, PhysicalIndex, PhysicalRetention, PhysicalTable, QueryBound, QueryRequest, StoredRow, WriteGuard, WriteOp, WriteResult, expiresAt, findPhysicalColumn, findPhysicalIndex, indexOrderColumns, rowKey };
|