@hot-updater/plugin-core 1.0.0-rc.17 → 1.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/baseCandidateKey.cjs +50 -0
- package/dist/baseCandidateKey.d.cts +27 -0
- package/dist/baseCandidateKey.d.mts +27 -0
- package/dist/baseCandidateKey.mjs +49 -0
- package/dist/createStorageAdapter.cjs +8 -0
- package/dist/createStorageAdapter.d.cts +9 -0
- package/dist/createStorageAdapter.d.mts +9 -0
- package/dist/createStorageAdapter.mjs +7 -0
- package/dist/database/adapter.cjs +20 -5
- package/dist/database/adapter.d.cts +25 -8
- package/dist/database/adapter.d.mts +25 -8
- package/dist/database/adapter.mjs +21 -4
- package/dist/database/distinct.cjs +12 -6
- package/dist/database/distinct.d.cts +13 -11
- package/dist/database/distinct.d.mts +13 -11
- package/dist/database/distinct.mjs +13 -6
- package/dist/database/memoryAdapter.cjs +2 -10
- package/dist/database/memoryAdapter.d.cts +2 -4
- package/dist/database/memoryAdapter.d.mts +2 -4
- package/dist/database/memoryAdapter.mjs +2 -10
- package/dist/database/values.cjs +5 -1
- package/dist/database/values.d.cts +8 -21
- package/dist/database/values.d.mts +8 -21
- package/dist/database/values.mjs +5 -1
- package/dist/database/verifyAdapter.cjs +1 -0
- package/dist/database/verifyAdapter.d.cts +8 -0
- package/dist/database/verifyAdapter.d.mts +8 -0
- package/dist/database/verifyAdapter.mjs +1 -0
- package/dist/databaseErrors.cjs +4 -4
- package/dist/databaseErrors.d.cts +6 -6
- package/dist/databaseErrors.d.mts +6 -6
- package/dist/databaseErrors.mjs +4 -4
- package/dist/databaseJsonValue.cjs +6 -0
- package/dist/databaseJsonValue.d.cts +6 -0
- package/dist/databaseJsonValue.d.mts +6 -0
- package/dist/databaseJsonValue.mjs +6 -0
- package/dist/databaseMetadata.cjs +3 -3
- package/dist/databaseMetadata.mjs +3 -3
- package/dist/databaseRows.cjs +6 -6
- package/dist/databaseRows.d.cts +1 -1
- package/dist/databaseRows.d.mts +1 -1
- package/dist/databaseRows.mjs +1 -1
- package/dist/engine/core/schema.cjs +279 -0
- package/dist/engine/core/schema.d.cts +312 -0
- package/dist/engine/core/schema.d.mts +312 -0
- package/dist/engine/core/schema.mjs +277 -0
- package/dist/engine/createEngine.cjs +72 -0
- package/dist/engine/createEngine.d.cts +45 -0
- package/dist/engine/createEngine.d.mts +45 -0
- package/dist/engine/createEngine.mjs +72 -0
- package/dist/engine/database/aggregateBatching.cjs +627 -0
- package/dist/engine/database/aggregateBatching.mjs +626 -0
- package/dist/engine/database/cursor.cjs +42 -0
- package/dist/engine/database/cursor.mjs +38 -0
- package/dist/engine/database/database.cjs +68 -0
- package/dist/engine/database/database.mjs +68 -0
- package/dist/engine/database/engine.cjs +37 -0
- package/dist/engine/database/engine.mjs +37 -0
- package/dist/engine/database/engineAggregates.cjs +120 -0
- package/dist/engine/database/engineAggregates.mjs +117 -0
- package/dist/engine/database/engineReads.cjs +182 -0
- package/dist/engine/database/engineReads.d.cts +10 -0
- package/dist/engine/database/engineReads.d.mts +10 -0
- package/dist/engine/database/engineReads.mjs +181 -0
- package/dist/engine/database/engineTransaction.cjs +399 -0
- package/dist/engine/database/engineTransaction.d.cts +18 -0
- package/dist/engine/database/engineTransaction.d.mts +18 -0
- package/dist/engine/database/engineTransaction.mjs +398 -0
- package/dist/engine/database/fence.cjs +156 -0
- package/dist/engine/database/fence.d.cts +41 -0
- package/dist/engine/database/fence.d.mts +41 -0
- package/dist/engine/database/fence.mjs +149 -0
- package/dist/engine/database/kv/kvAdapter.cjs +293 -0
- package/dist/engine/database/kv/kvAdapter.d.cts +116 -0
- package/dist/engine/database/kv/kvAdapter.d.mts +116 -0
- package/dist/engine/database/kv/kvAdapter.mjs +292 -0
- package/dist/engine/database/readMeter.cjs +80 -0
- package/dist/engine/database/readMeter.d.cts +34 -0
- package/dist/engine/database/readMeter.d.mts +34 -0
- package/dist/engine/database/readMeter.mjs +79 -0
- package/dist/engine/database/resolveSchema.cjs +197 -0
- package/dist/engine/database/resolveSchema.d.cts +35 -0
- package/dist/engine/database/resolveSchema.d.mts +35 -0
- package/dist/engine/database/resolveSchema.mjs +195 -0
- package/dist/engine/database/retention.cjs +100 -0
- package/dist/engine/database/retention.mjs +98 -0
- package/dist/engine/database/sql/sqlAdapter.cjs +290 -0
- package/dist/engine/database/sql/sqlAdapter.d.cts +45 -0
- package/dist/engine/database/sql/sqlAdapter.d.mts +45 -0
- package/dist/engine/database/sql/sqlAdapter.mjs +288 -0
- package/dist/engine/database/sql/sqlSchema.cjs +175 -0
- package/dist/engine/database/sql/sqlSchema.d.cts +45 -0
- package/dist/engine/database/sql/sqlSchema.d.mts +45 -0
- package/dist/engine/database/sql/sqlSchema.mjs +169 -0
- package/dist/engine/db/coreDatabase.cjs +94 -0
- package/dist/engine/db/coreDatabase.d.cts +78 -0
- package/dist/engine/db/coreDatabase.d.mts +78 -0
- package/dist/engine/db/coreDatabase.mjs +86 -0
- package/dist/engine/db/engineMigrator.cjs +53 -0
- package/dist/engine/db/engineMigrator.mjs +53 -0
- package/dist/engine/db/engineSql.cjs +26 -0
- package/dist/engine/db/engineSql.d.cts +16 -0
- package/dist/engine/db/engineSql.d.mts +16 -0
- package/dist/engine/db/engineSql.mjs +25 -0
- package/dist/engine/db/engineSqlMigrator.cjs +67 -0
- package/dist/engine/db/engineSqlMigrator.d.cts +21 -0
- package/dist/engine/db/engineSqlMigrator.d.mts +21 -0
- package/dist/engine/db/engineSqlMigrator.mjs +67 -0
- package/dist/engine/db/fixedMigratorShared.cjs +12 -0
- package/dist/engine/db/fixedMigratorShared.mjs +11 -0
- package/dist/engine/db/schemaSettings.cjs +63 -0
- package/dist/engine/db/schemaSettings.d.cts +7 -0
- package/dist/engine/db/schemaSettings.d.mts +7 -0
- package/dist/engine/db/schemaSettings.mjs +62 -0
- package/dist/engine/db/settingsMigrator.cjs +94 -0
- package/dist/engine/db/settingsMigrator.d.cts +25 -0
- package/dist/engine/db/settingsMigrator.d.mts +25 -0
- package/dist/engine/db/settingsMigrator.mjs +91 -0
- package/dist/engine/db/types.d.cts +78 -0
- package/dist/engine/db/types.d.mts +78 -0
- package/dist/index.cjs +86 -7
- package/dist/index.d.cts +36 -6
- package/dist/index.d.mts +36 -6
- package/dist/index.mjs +26 -4
- package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.cjs +0 -5
- package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.mjs +1 -5
- package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/range-DvX-Y6iv.cjs +8 -0
- package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/range-DvX-Y6iv.mjs +9 -2
- package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/set-CC5YeoYX.cjs +4 -0
- package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/set-CC5YeoYX.mjs +4 -1
- package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.cjs +0 -5
- package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.mjs +2 -6
- package/dist/releaseCatalogCompiler.cjs +26 -25
- package/dist/releaseCatalogCompiler.d.cts +1 -2
- package/dist/releaseCatalogCompiler.d.mts +2 -3
- package/dist/releaseCatalogCompiler.mjs +3 -7
- package/dist/remoteBundleSigning.d.cts +2 -2
- package/dist/remoteBundleSigning.d.mts +2 -2
- package/dist/serverPlugin/busy.cjs +36 -0
- package/dist/serverPlugin/busy.d.cts +12 -0
- package/dist/serverPlugin/busy.d.mts +12 -0
- package/dist/serverPlugin/busy.mjs +36 -0
- package/dist/serverPlugin/configError.cjs +7 -0
- package/dist/serverPlugin/configError.d.cts +7 -0
- package/dist/serverPlugin/configError.d.mts +7 -0
- package/dist/serverPlugin/configError.mjs +7 -0
- package/dist/serverPlugin/coreReads.d.cts +48 -0
- package/dist/serverPlugin/coreReads.d.mts +48 -0
- package/dist/serverPlugin/databaseHandle.d.cts +105 -0
- package/dist/serverPlugin/databaseHandle.d.mts +105 -0
- package/dist/serverPlugin/definePlugin.cjs +5 -0
- package/dist/serverPlugin/definePlugin.d.cts +130 -0
- package/dist/serverPlugin/definePlugin.d.mts +130 -0
- package/dist/serverPlugin/definePlugin.mjs +5 -0
- package/dist/serverPlugin/definitions.d.cts +76 -0
- package/dist/serverPlugin/definitions.d.mts +76 -0
- package/dist/serverPlugin/errors.cjs +37 -0
- package/dist/serverPlugin/errors.d.cts +29 -0
- package/dist/serverPlugin/errors.d.mts +29 -0
- package/dist/serverPlugin/errors.mjs +32 -0
- package/dist/serverPlugin/schema.cjs +24 -0
- package/dist/serverPlugin/schema.d.cts +90 -0
- package/dist/serverPlugin/schema.d.mts +90 -0
- package/dist/serverPlugin/schema.mjs +23 -0
- package/dist/types/databaseConfig.cjs +1 -1
- package/dist/types/databaseConfig.d.cts +8 -1
- package/dist/types/databaseConfig.d.mts +8 -1
- package/dist/types/databaseConfig.mjs +1 -1
- package/dist/types/databaseRows.d.cts +1 -1
- package/dist/types/databaseRows.d.mts +1 -1
- package/dist/types/index.d.cts +26 -14
- package/dist/types/index.d.mts +26 -14
- package/dist/types/public.d.cts +1 -1
- package/dist/types/public.d.mts +1 -1
- package/dist/uuidv7.cjs +3 -3
- package/dist/uuidv7.d.cts +1 -1
- package/dist/uuidv7.d.mts +1 -1
- package/dist/uuidv7.mjs +1 -1
- package/package.json +10 -7
- package/dist/createStoragePlugin.cjs +0 -8
- package/dist/createStoragePlugin.d.cts +0 -9
- package/dist/createStoragePlugin.d.mts +0 -9
- package/dist/createStoragePlugin.mjs +0 -7
- package/dist/internal.cjs +0 -38
- package/dist/internal.d.cts +0 -12
- package/dist/internal.d.mts +0 -12
- package/dist/internal.mjs +0 -8
- package/dist/types/internal.d.cts +0 -4
- package/dist/types/internal.d.mts +0 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as compare } from "./node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.mjs";
|
|
2
2
|
import { f as satisfies, m as parseRange } from "./node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/range-DvX-Y6iv.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { p as normalize } from "./node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.mjs";
|
|
4
4
|
import { isUUIDv7 as isUUIDv7$1 } from "./uuidv7.mjs";
|
|
5
|
-
import { MAX_COMPILED_CATALOG_BYTES, MAX_DISTINCT_TARGET_COHORTS_PER_SCOPE, MAX_TARGET_COHORTS_PER_RELEASE, NUMERIC_COHORT_SIZE, RELEASE_CATALOG_FALLBACK_POLICY, RELEASE_CATALOG_SCHEMA_VERSION, getNumericCohortValue, getRolledOutNumericCohorts, isCustomCohort, normalizeCohortValue, normalizeRolloutCohortCount } from "@hot-updater/
|
|
5
|
+
import { MAX_COMPILED_CATALOG_BYTES, MAX_DISTINCT_TARGET_COHORTS_PER_SCOPE, MAX_TARGET_COHORTS_PER_RELEASE, NUMERIC_COHORT_SIZE, RELEASE_CATALOG_FALLBACK_POLICY, RELEASE_CATALOG_SCHEMA_VERSION, canonicalizeAppVersion, canonicalizeAppVersion as canonicalizeAppVersion$1, getNumericCohortValue, getRolledOutNumericCohorts, isCustomCohort, normalizeCohortValue, normalizeRolloutCohortCount } from "@hot-updater/protocol";
|
|
6
6
|
//#region src/releaseCatalogCompiler.ts
|
|
7
7
|
var ReleaseCatalogCompilationError = class extends Error {
|
|
8
8
|
code;
|
|
@@ -356,10 +356,6 @@ function versionInSegment(version, segment) {
|
|
|
356
356
|
}
|
|
357
357
|
return true;
|
|
358
358
|
}
|
|
359
|
-
function canonicalizeAppVersion(appVersion) {
|
|
360
|
-
const version = coerce(appVersion);
|
|
361
|
-
return version ? normalizeFull(version) : null;
|
|
362
|
-
}
|
|
363
359
|
function projectCompiledCatalog(catalog, appVersion) {
|
|
364
360
|
let indexes;
|
|
365
361
|
if (catalog.strategy === "FINGERPRINT") indexes = catalog.releaseIndexes;
|
|
@@ -387,4 +383,4 @@ function referenceCompatibleReleases(releases, appVersion) {
|
|
|
387
383
|
return releases.filter((release) => release.enabled && release.targetAppVersion !== null && satisfies(canonicalVersion, release.targetAppVersion));
|
|
388
384
|
}
|
|
389
385
|
//#endregion
|
|
390
|
-
export { ReleaseCatalogCompilationError, canonicalizeAppVersion, compileReleaseCatalog, projectCompiledCatalog, projectCompiledRollbackCatalog, referenceCompatibleReleases };
|
|
386
|
+
export { ReleaseCatalogCompilationError, canonicalizeAppVersion$1 as canonicalizeAppVersion, compileReleaseCatalog, projectCompiledCatalog, projectCompiledRollbackCatalog, referenceCompatibleReleases };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BundleSigningAdapter } from "./types/index.cjs";
|
|
2
2
|
//#region src/remoteBundleSigning.d.ts
|
|
3
3
|
declare const REMOTE_BUNDLE_SIGNING_PATH = "/_hot-updater/signing";
|
|
4
4
|
declare const REMOTE_BUNDLE_SIGNING_PROTOCOL_VERSION: 1;
|
|
@@ -23,7 +23,7 @@ interface BundleSigningHandlerOptions {
|
|
|
23
23
|
readonly token: string;
|
|
24
24
|
}
|
|
25
25
|
/** Signs through a server implementing the Hot Updater signing protocol. */
|
|
26
|
-
declare const remoteSigning: ({ endpoint, fetch: fetchImplementation, signingToken }: RemoteSigningOptions) =>
|
|
26
|
+
declare const remoteSigning: ({ endpoint, fetch: fetchImplementation, signingToken }: RemoteSigningOptions) => BundleSigningAdapter;
|
|
27
27
|
/** Handles the portable managed signing protocol in Web API runtimes. */
|
|
28
28
|
declare const createBundleSigningHandler: ({ endpointPath, publicKey, request, sign, token }: BundleSigningHandlerOptions) => Promise<Response | null>;
|
|
29
29
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BundleSigningAdapter } from "./types/index.mjs";
|
|
2
2
|
//#region src/remoteBundleSigning.d.ts
|
|
3
3
|
declare const REMOTE_BUNDLE_SIGNING_PATH = "/_hot-updater/signing";
|
|
4
4
|
declare const REMOTE_BUNDLE_SIGNING_PROTOCOL_VERSION: 1;
|
|
@@ -23,7 +23,7 @@ interface BundleSigningHandlerOptions {
|
|
|
23
23
|
readonly token: string;
|
|
24
24
|
}
|
|
25
25
|
/** Signs through a server implementing the Hot Updater signing protocol. */
|
|
26
|
-
declare const remoteSigning: ({ endpoint, fetch: fetchImplementation, signingToken }: RemoteSigningOptions) =>
|
|
26
|
+
declare const remoteSigning: ({ endpoint, fetch: fetchImplementation, signingToken }: RemoteSigningOptions) => BundleSigningAdapter;
|
|
27
27
|
/** Handles the portable managed signing protocol in Web API runtimes. */
|
|
28
28
|
declare const createBundleSigningHandler: ({ endpointPath, publicKey, request, sign, token }: BundleSigningHandlerOptions) => Promise<Response | null>;
|
|
29
29
|
//#endregion
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_errors = require("./errors.cjs");
|
|
2
|
+
//#region src/serverPlugin/busy.ts
|
|
3
|
+
/** Error names the AWS SDKs give a throttled request, as their retry strategy classifies them. */
|
|
4
|
+
const THROTTLING_NAMES = /* @__PURE__ */ new Set([
|
|
5
|
+
"ProvisionedThroughputExceededException",
|
|
6
|
+
"RequestLimitExceeded",
|
|
7
|
+
"RequestThrottled",
|
|
8
|
+
"RequestThrottledException",
|
|
9
|
+
"SlowDown",
|
|
10
|
+
"ThrottledException",
|
|
11
|
+
"Throttling",
|
|
12
|
+
"ThrottlingException",
|
|
13
|
+
"TooManyRequestsException"
|
|
14
|
+
]);
|
|
15
|
+
/** gRPC's RESOURCE_EXHAUSTED, the status Firestore throttles a request with. */
|
|
16
|
+
const RESOURCE_EXHAUSTED = 8;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the database is busy rather than broken, so the same request can
|
|
19
|
+
* succeed later: a transaction ran out of retries, or the backend throttled
|
|
20
|
+
* a request. Writes already retry transient failures, throttled ones
|
|
21
|
+
* included, until the budget runs out. A throttled read throws the backend's
|
|
22
|
+
* own error, so it is recognized by what the backends call it: a name the
|
|
23
|
+
* AWS SDKs retry as throttling, HTTP 429, or gRPC's RESOURCE_EXHAUSTED.
|
|
24
|
+
*/
|
|
25
|
+
const isDatabaseBusyError = (error) => {
|
|
26
|
+
if (error instanceof require_errors.DatabaseConflictError) return true;
|
|
27
|
+
if (typeof error !== "object" || error === null) return false;
|
|
28
|
+
const { name, code, message, status, statusCode, $metadata } = error;
|
|
29
|
+
return typeof name === "string" && THROTTLING_NAMES.has(name) || [
|
|
30
|
+
status,
|
|
31
|
+
statusCode,
|
|
32
|
+
$metadata?.httpStatusCode
|
|
33
|
+
].includes(429) || code === RESOURCE_EXHAUSTED && typeof message === "string" && message.includes("RESOURCE_EXHAUSTED");
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.isDatabaseBusyError = isDatabaseBusyError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/serverPlugin/busy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Whether the database is busy rather than broken, so the same request can
|
|
4
|
+
* succeed later: a transaction ran out of retries, or the backend throttled
|
|
5
|
+
* a request. Writes already retry transient failures, throttled ones
|
|
6
|
+
* included, until the budget runs out. A throttled read throws the backend's
|
|
7
|
+
* own error, so it is recognized by what the backends call it: a name the
|
|
8
|
+
* AWS SDKs retry as throttling, HTTP 429, or gRPC's RESOURCE_EXHAUSTED.
|
|
9
|
+
*/
|
|
10
|
+
declare const isDatabaseBusyError: (error: unknown) => boolean;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { isDatabaseBusyError };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/serverPlugin/busy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Whether the database is busy rather than broken, so the same request can
|
|
4
|
+
* succeed later: a transaction ran out of retries, or the backend throttled
|
|
5
|
+
* a request. Writes already retry transient failures, throttled ones
|
|
6
|
+
* included, until the budget runs out. A throttled read throws the backend's
|
|
7
|
+
* own error, so it is recognized by what the backends call it: a name the
|
|
8
|
+
* AWS SDKs retry as throttling, HTTP 429, or gRPC's RESOURCE_EXHAUSTED.
|
|
9
|
+
*/
|
|
10
|
+
declare const isDatabaseBusyError: (error: unknown) => boolean;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { isDatabaseBusyError };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DatabaseConflictError } from "./errors.mjs";
|
|
2
|
+
//#region src/serverPlugin/busy.ts
|
|
3
|
+
/** Error names the AWS SDKs give a throttled request, as their retry strategy classifies them. */
|
|
4
|
+
const THROTTLING_NAMES = /* @__PURE__ */ new Set([
|
|
5
|
+
"ProvisionedThroughputExceededException",
|
|
6
|
+
"RequestLimitExceeded",
|
|
7
|
+
"RequestThrottled",
|
|
8
|
+
"RequestThrottledException",
|
|
9
|
+
"SlowDown",
|
|
10
|
+
"ThrottledException",
|
|
11
|
+
"Throttling",
|
|
12
|
+
"ThrottlingException",
|
|
13
|
+
"TooManyRequestsException"
|
|
14
|
+
]);
|
|
15
|
+
/** gRPC's RESOURCE_EXHAUSTED, the status Firestore throttles a request with. */
|
|
16
|
+
const RESOURCE_EXHAUSTED = 8;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the database is busy rather than broken, so the same request can
|
|
19
|
+
* succeed later: a transaction ran out of retries, or the backend throttled
|
|
20
|
+
* a request. Writes already retry transient failures, throttled ones
|
|
21
|
+
* included, until the budget runs out. A throttled read throws the backend's
|
|
22
|
+
* own error, so it is recognized by what the backends call it: a name the
|
|
23
|
+
* AWS SDKs retry as throttling, HTTP 429, or gRPC's RESOURCE_EXHAUSTED.
|
|
24
|
+
*/
|
|
25
|
+
const isDatabaseBusyError = (error) => {
|
|
26
|
+
if (error instanceof DatabaseConflictError) return true;
|
|
27
|
+
if (typeof error !== "object" || error === null) return false;
|
|
28
|
+
const { name, code, message, status, statusCode, $metadata } = error;
|
|
29
|
+
return typeof name === "string" && THROTTLING_NAMES.has(name) || [
|
|
30
|
+
status,
|
|
31
|
+
statusCode,
|
|
32
|
+
$metadata?.httpStatusCode
|
|
33
|
+
].includes(429) || code === RESOURCE_EXHAUSTED && typeof message === "string" && message.includes("RESOURCE_EXHAUSTED");
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { isDatabaseBusyError };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/serverPlugin/configError.ts
|
|
2
|
+
/** A misconfigured `createHotUpdater` call, reported at startup. */
|
|
3
|
+
var HotUpdaterConfigError = class extends Error {
|
|
4
|
+
name = "HotUpdaterConfigError";
|
|
5
|
+
};
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.HotUpdaterConfigError = HotUpdaterConfigError;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BundlePatchRow, ChannelRow, ReleaseCatalogRow, ReleaseRow } from "../types/databaseRows.cjs";
|
|
2
|
+
import { BundleDetail, KeysetInput, ReleaseFilter } from "../coreApi.cjs";
|
|
3
|
+
import { ArtifactInfo, ReleaseCatalog } from "@hot-updater/protocol";
|
|
4
|
+
//#region src/serverPlugin/coreReads.d.ts
|
|
5
|
+
/** The scope of a device's update check, by its update strategy. */
|
|
6
|
+
type ReleaseCatalogRequest = {
|
|
7
|
+
readonly strategy: "APP_VERSION";
|
|
8
|
+
readonly platform: "ios" | "android";
|
|
9
|
+
readonly channelKey: string;
|
|
10
|
+
readonly appVersion: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly strategy: "FINGERPRINT";
|
|
13
|
+
readonly platform: "ios" | "android";
|
|
14
|
+
readonly channelKey: string;
|
|
15
|
+
readonly fingerprintHash: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Core's reads: bundles, Releases, Catalogs, and channels, each through a
|
|
19
|
+
* declared index. A plugin gets them as `ctx.core` and never writes core.
|
|
20
|
+
*/
|
|
21
|
+
interface CoreReads {
|
|
22
|
+
/** The Release Catalog a device's update check receives, or null when its scope has none. */
|
|
23
|
+
getReleaseCatalog(input: ReleaseCatalogRequest): Promise<ReleaseCatalog | null>;
|
|
24
|
+
/** How a device on `currentBundleId` downloads `targetBundleId`. */
|
|
25
|
+
getArtifactInfo(targetBundleId: string, currentBundleId: string, artifactProtocolVersion: 1): Promise<ArtifactInfo | null>;
|
|
26
|
+
getBundle(id: string): Promise<BundleDetail | null>;
|
|
27
|
+
/** Each base bundle's reference counter: one batch read of the bundle rows, and no patches. */
|
|
28
|
+
countBundleChildren(baseBundleIds: readonly string[]): Promise<Record<string, number>>;
|
|
29
|
+
/** One page of the patches that start from a bundle, by target bundle id. */
|
|
30
|
+
listPatchesFromBase(baseBundleId: string, input: KeysetInput): Promise<BundlePatchRow[]>;
|
|
31
|
+
listBundles(input: KeysetInput & {
|
|
32
|
+
readonly platform?: "ios" | "android";
|
|
33
|
+
}): Promise<BundleDetail[]>;
|
|
34
|
+
countBundles(platform?: "ios" | "android"): Promise<number>;
|
|
35
|
+
findBaseBundleIds(candidateKey: string, bundleId: string, limit: number): Promise<string[]>;
|
|
36
|
+
getRelease(id: string): Promise<ReleaseRow | null>;
|
|
37
|
+
/** One page of releases through the index its filter names. */
|
|
38
|
+
listReleases(input: KeysetInput & {
|
|
39
|
+
readonly filter: ReleaseFilter;
|
|
40
|
+
}): Promise<ReleaseRow[]>;
|
|
41
|
+
latestReleaseId(scopeKey: string): Promise<string | null>;
|
|
42
|
+
getReleaseCatalogRow(scopeKey: string): Promise<ReleaseCatalogRow | null>;
|
|
43
|
+
listReleaseCatalogs(input: KeysetInput): Promise<ReleaseCatalogRow[]>;
|
|
44
|
+
listChannels(): Promise<ChannelRow[]>;
|
|
45
|
+
findChannelByName(name: string): Promise<ChannelRow | null>;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { CoreReads, ReleaseCatalogRequest };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BundlePatchRow, ChannelRow, ReleaseCatalogRow, ReleaseRow } from "../types/databaseRows.mjs";
|
|
2
|
+
import { BundleDetail, KeysetInput, ReleaseFilter } from "../coreApi.mjs";
|
|
3
|
+
import { ArtifactInfo, ReleaseCatalog } from "@hot-updater/protocol";
|
|
4
|
+
//#region src/serverPlugin/coreReads.d.ts
|
|
5
|
+
/** The scope of a device's update check, by its update strategy. */
|
|
6
|
+
type ReleaseCatalogRequest = {
|
|
7
|
+
readonly strategy: "APP_VERSION";
|
|
8
|
+
readonly platform: "ios" | "android";
|
|
9
|
+
readonly channelKey: string;
|
|
10
|
+
readonly appVersion: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly strategy: "FINGERPRINT";
|
|
13
|
+
readonly platform: "ios" | "android";
|
|
14
|
+
readonly channelKey: string;
|
|
15
|
+
readonly fingerprintHash: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Core's reads: bundles, Releases, Catalogs, and channels, each through a
|
|
19
|
+
* declared index. A plugin gets them as `ctx.core` and never writes core.
|
|
20
|
+
*/
|
|
21
|
+
interface CoreReads {
|
|
22
|
+
/** The Release Catalog a device's update check receives, or null when its scope has none. */
|
|
23
|
+
getReleaseCatalog(input: ReleaseCatalogRequest): Promise<ReleaseCatalog | null>;
|
|
24
|
+
/** How a device on `currentBundleId` downloads `targetBundleId`. */
|
|
25
|
+
getArtifactInfo(targetBundleId: string, currentBundleId: string, artifactProtocolVersion: 1): Promise<ArtifactInfo | null>;
|
|
26
|
+
getBundle(id: string): Promise<BundleDetail | null>;
|
|
27
|
+
/** Each base bundle's reference counter: one batch read of the bundle rows, and no patches. */
|
|
28
|
+
countBundleChildren(baseBundleIds: readonly string[]): Promise<Record<string, number>>;
|
|
29
|
+
/** One page of the patches that start from a bundle, by target bundle id. */
|
|
30
|
+
listPatchesFromBase(baseBundleId: string, input: KeysetInput): Promise<BundlePatchRow[]>;
|
|
31
|
+
listBundles(input: KeysetInput & {
|
|
32
|
+
readonly platform?: "ios" | "android";
|
|
33
|
+
}): Promise<BundleDetail[]>;
|
|
34
|
+
countBundles(platform?: "ios" | "android"): Promise<number>;
|
|
35
|
+
findBaseBundleIds(candidateKey: string, bundleId: string, limit: number): Promise<string[]>;
|
|
36
|
+
getRelease(id: string): Promise<ReleaseRow | null>;
|
|
37
|
+
/** One page of releases through the index its filter names. */
|
|
38
|
+
listReleases(input: KeysetInput & {
|
|
39
|
+
readonly filter: ReleaseFilter;
|
|
40
|
+
}): Promise<ReleaseRow[]>;
|
|
41
|
+
latestReleaseId(scopeKey: string): Promise<string | null>;
|
|
42
|
+
getReleaseCatalogRow(scopeKey: string): Promise<ReleaseCatalogRow | null>;
|
|
43
|
+
listReleaseCatalogs(input: KeysetInput): Promise<ReleaseCatalogRow[]>;
|
|
44
|
+
listChannels(): Promise<ChannelRow[]>;
|
|
45
|
+
findChannelByName(name: string): Promise<ChannelRow | null>;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { CoreReads, ReleaseCatalogRequest };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DatabaseKeyValue } from "../database/adapter.cjs";
|
|
2
|
+
import { FieldType } from "./definitions.cjs";
|
|
3
|
+
import { AggregateDefinition, FieldValue, ModuleSchema, RowOf, TableDefinition } from "./schema.cjs";
|
|
4
|
+
//#region src/serverPlugin/databaseHandle.d.ts
|
|
5
|
+
/** One page of a read; `next` resumes after it. */
|
|
6
|
+
interface Page<TRow> {
|
|
7
|
+
readonly rows: readonly TRow[];
|
|
8
|
+
/** Present only after a full page. */
|
|
9
|
+
readonly next?: string;
|
|
10
|
+
}
|
|
11
|
+
type TableNames<S extends ModuleSchema> = { [K in keyof S]: S[K] extends TableDefinition ? K : never; }[keyof S] & string;
|
|
12
|
+
type AggregateNames<S extends ModuleSchema> = { [K in keyof S]: S[K] extends AggregateDefinition ? K : never; }[keyof S] & string;
|
|
13
|
+
/** Reference counters: how many rows of another table point at this one. */
|
|
14
|
+
type RefColumns = {
|
|
15
|
+
readonly [K: `_refs_${string}`]: number;
|
|
16
|
+
};
|
|
17
|
+
/** Engine columns every stored row carries. */
|
|
18
|
+
type EngineColumns = {
|
|
19
|
+
readonly _v: number;
|
|
20
|
+
} & RefColumns;
|
|
21
|
+
type DerivedValues<TDerived> = { -readonly [K in keyof TDerived]: TDerived[K] extends FieldType ? FieldValue<TDerived[K]> | readonly FieldValue<TDerived[K]>[] | null : never; };
|
|
22
|
+
type Values<TModel> = TModel extends TableDefinition<infer TFields, infer TDerived> ? RowOf<TFields> & DerivedValues<TDerived> : TModel extends AggregateDefinition<infer TFields, infer TMetric, infer _TIndexes, infer TSketch> ? RowOf<TFields> & { -readonly [K in TMetric]: number; } & { -readonly [K in TSketch]: string; } : never;
|
|
23
|
+
/** A row read in a transaction, `_v` included, so the transaction can write it back. */
|
|
24
|
+
type TableRow<TModel> = Values<TModel> & EngineColumns;
|
|
25
|
+
/** A row read outside a transaction, without `_v`, which only a transaction's guard uses. */
|
|
26
|
+
type ReadRow<TModel> = Values<TModel> & RefColumns;
|
|
27
|
+
type AggregateRow<TModel> = Values<TModel>;
|
|
28
|
+
type IndexesOf<TModel> = TModel extends {
|
|
29
|
+
readonly indexes: infer I;
|
|
30
|
+
} ? I : never;
|
|
31
|
+
type IndexName<TModel> = keyof IndexesOf<TModel> & string;
|
|
32
|
+
type IndexFields<TModel, TIndex, TPart extends "eq" | "sort"> = IndexesOf<TModel>[TIndex & keyof IndexesOf<TModel>] extends { readonly [P in TPart]: readonly (infer F)[]; } ? F & keyof Values<TModel> : never;
|
|
33
|
+
type KeyValueOf<TModel, TField extends keyof Values<TModel>> = Exclude<Values<TModel>[TField], null | readonly unknown[]>;
|
|
34
|
+
type FirstOrderField<TModel, TIndex> = IndexesOf<TModel>[TIndex & keyof IndexesOf<TModel>] extends {
|
|
35
|
+
readonly sort: readonly [infer F, ...unknown[]];
|
|
36
|
+
} ? F & keyof Values<TModel> : TModel extends {
|
|
37
|
+
readonly key: readonly (infer K)[];
|
|
38
|
+
} ? K & keyof Values<TModel> : never;
|
|
39
|
+
interface ReadOptions<TModel, TIndex> {
|
|
40
|
+
readonly index: TIndex;
|
|
41
|
+
/** Every eq field of the index; null never matches. */
|
|
42
|
+
readonly where: { readonly [F in IndexFields<TModel, TIndex, "eq">]: KeyValueOf<TModel, F>; };
|
|
43
|
+
/** Bounds on the first order field, or on a prefix of the order tuple (sort fields, then the key). */
|
|
44
|
+
readonly range?: { readonly [B in "gt" | "gte" | "lt" | "lte"]?: KeyValueOf<TModel, FirstOrderField<TModel, TIndex>> | readonly [KeyValueOf<TModel, FirstOrderField<TModel, TIndex>>, ...DatabaseKeyValue[]]; };
|
|
45
|
+
readonly order?: "asc" | "desc";
|
|
46
|
+
readonly limit: number;
|
|
47
|
+
readonly cursor?: string;
|
|
48
|
+
}
|
|
49
|
+
type UniqueLookups<TModel> = TModel extends TableDefinition<infer TFields, infer _D, infer TIndexes> ? { [F in keyof TFields]: TFields[F] extends {
|
|
50
|
+
readonly unique: true;
|
|
51
|
+
} ? { readonly [P in F]: KeyValueOf<TModel, P & keyof Values<TModel>>; } : never; }[keyof TFields] | { [I in keyof TIndexes]: TIndexes[I] extends {
|
|
52
|
+
readonly unique: true;
|
|
53
|
+
readonly eq: readonly (infer E)[];
|
|
54
|
+
} ? { readonly [P in E & string]: KeyValueOf<TModel, P & keyof Values<TModel>>; } : never; }[keyof TIndexes] : never;
|
|
55
|
+
/** A table's key values. */
|
|
56
|
+
type KeyLookup<TModel> = TModel extends TableDefinition<infer _F> ? { readonly [K in TModel["key"][number]]: KeyValueOf<TModel, K & keyof Values<TModel>>; } : never;
|
|
57
|
+
/** The key, or the eq fields of a unique index. */
|
|
58
|
+
type Lookup<TModel> = KeyLookup<TModel> | UniqueLookups<TModel>;
|
|
59
|
+
type RootedIndexName<TModel> = { [I in keyof IndexesOf<TModel>]: IndexesOf<TModel>[I] extends {
|
|
60
|
+
readonly root: object;
|
|
61
|
+
} ? I : never; }[keyof IndexesOf<TModel>] & string;
|
|
62
|
+
type OptionalFields<TFields> = { [K in keyof TFields]: TFields[K] extends {
|
|
63
|
+
readonly required: false;
|
|
64
|
+
} ? K : never; }[keyof TFields];
|
|
65
|
+
/** Declared fields, optional ones omittable; derived fields and engine columns are computed. */
|
|
66
|
+
type CreateRow<TModel> = TModel extends TableDefinition<infer TFields> ? Omit<RowOf<TFields>, OptionalFields<TFields>> & Partial<Pick<RowOf<TFields>, OptionalFields<TFields>>> : never;
|
|
67
|
+
/** Changed non-key fields. */
|
|
68
|
+
type UpdateSet<TModel> = TModel extends TableDefinition<infer TFields, infer _D, infer _I, infer TKey> ? Partial<Omit<RowOf<TFields>, TKey[number]>> : never;
|
|
69
|
+
type AggregateIdentity<TModel> = TModel extends AggregateDefinition<infer TFields> ? RowOf<TFields> : never;
|
|
70
|
+
/** Counter and gauge deltas, and sketches to merge. */
|
|
71
|
+
type AggregateChanges<TModel> = TModel extends AggregateDefinition<infer _F, infer TMetric, infer _I, infer TSketch> ? { readonly [K in TMetric]?: number; } & { readonly [K in TSketch]?: string; } : never;
|
|
72
|
+
/** Reads are recorded and guarded at commit; writes apply only if every guard holds. */
|
|
73
|
+
interface HotUpdaterTransaction<S extends ModuleSchema> {
|
|
74
|
+
findOne<M extends TableNames<S>>(model: M, lookup: Lookup<S[M]>): Promise<TableRow<S[M]> | null>;
|
|
75
|
+
/** Rooted indexes only: the parent row guards the whole range. */
|
|
76
|
+
findMany<M extends TableNames<S>, I extends RootedIndexName<S[M]>>(model: M, options: ReadOptions<S[M], I>): Promise<Page<TableRow<S[M]>>>;
|
|
77
|
+
create<M extends TableNames<S>>(model: M, row: CreateRow<S[M]>): void;
|
|
78
|
+
/** Patches a row this transaction read, by key or through a rooted range. */
|
|
79
|
+
update<M extends TableNames<S>>(model: M, row: TableRow<S[M]>, set: UpdateSet<S[M]>): void;
|
|
80
|
+
/** Deletes a row this transaction read, cascading to its children first. */
|
|
81
|
+
delete<M extends TableNames<S>>(model: M, row: TableRow<S[M]>): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Changes one shard row of an aggregate. Gauges of a sharded aggregate need
|
|
84
|
+
* `shardBy`, so every change keyed by one value lands on one shard.
|
|
85
|
+
*/
|
|
86
|
+
aggregate<M extends AggregateNames<S>>(model: M, identity: AggregateIdentity<S[M]>, changes: AggregateChanges<S[M]>, options?: {
|
|
87
|
+
readonly shardBy?: string;
|
|
88
|
+
}): void;
|
|
89
|
+
}
|
|
90
|
+
/** A table name, or the reason an aggregate cannot be read this way. */
|
|
91
|
+
type FindManyModel<S extends ModuleSchema, M> = M extends TableNames<S> ? M : "findMany reads tables; read aggregates with findAggregates";
|
|
92
|
+
/** An aggregate name, or the reason a table cannot be read this way. */
|
|
93
|
+
type FindAggregatesModel<S extends ModuleSchema, M> = M extends AggregateNames<S> ? M : "findAggregates reads aggregates; read tables with findMany";
|
|
94
|
+
/** A module's database handle. There is no count, offset, or free-form filter. */
|
|
95
|
+
interface HotUpdaterDatabase<S extends ModuleSchema> {
|
|
96
|
+
findOne<M extends TableNames<S>>(model: M, lookup: Lookup<S[M]>): Promise<ReadRow<S[M]> | null>;
|
|
97
|
+
/** Rows by key in one batch read, in the keys' order. */
|
|
98
|
+
findByKeys<M extends TableNames<S>>(model: M, keys: readonly KeyLookup<S[M]>[]): Promise<(ReadRow<S[M]> | null)[]>;
|
|
99
|
+
findMany<M extends keyof S & string, I extends IndexName<S[M]>>(model: FindManyModel<S, M>, options: ReadOptions<S[M], I>): Promise<Page<ReadRow<S[M]>>>;
|
|
100
|
+
findAggregates<M extends keyof S & string, I extends IndexName<S[M]>>(model: FindAggregatesModel<S, M>, options: ReadOptions<S[M], I>): Promise<Page<AggregateRow<S[M]>>>;
|
|
101
|
+
/** Reruns `fn` when a guarded read changed, within a jittered retry budget. */
|
|
102
|
+
transaction<R>(fn: (tx: HotUpdaterTransaction<S>) => Promise<R>): Promise<R>;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { AggregateChanges, AggregateIdentity, AggregateRow, CreateRow, EngineColumns, FindAggregatesModel, FindManyModel, HotUpdaterDatabase, HotUpdaterTransaction, KeyLookup, Lookup, Page, ReadOptions, ReadRow, TableRow, UpdateSet };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DatabaseKeyValue } from "../database/adapter.mjs";
|
|
2
|
+
import { FieldType } from "./definitions.mjs";
|
|
3
|
+
import { AggregateDefinition, FieldValue, ModuleSchema, RowOf, TableDefinition } from "./schema.mjs";
|
|
4
|
+
//#region src/serverPlugin/databaseHandle.d.ts
|
|
5
|
+
/** One page of a read; `next` resumes after it. */
|
|
6
|
+
interface Page<TRow> {
|
|
7
|
+
readonly rows: readonly TRow[];
|
|
8
|
+
/** Present only after a full page. */
|
|
9
|
+
readonly next?: string;
|
|
10
|
+
}
|
|
11
|
+
type TableNames<S extends ModuleSchema> = { [K in keyof S]: S[K] extends TableDefinition ? K : never; }[keyof S] & string;
|
|
12
|
+
type AggregateNames<S extends ModuleSchema> = { [K in keyof S]: S[K] extends AggregateDefinition ? K : never; }[keyof S] & string;
|
|
13
|
+
/** Reference counters: how many rows of another table point at this one. */
|
|
14
|
+
type RefColumns = {
|
|
15
|
+
readonly [K: `_refs_${string}`]: number;
|
|
16
|
+
};
|
|
17
|
+
/** Engine columns every stored row carries. */
|
|
18
|
+
type EngineColumns = {
|
|
19
|
+
readonly _v: number;
|
|
20
|
+
} & RefColumns;
|
|
21
|
+
type DerivedValues<TDerived> = { -readonly [K in keyof TDerived]: TDerived[K] extends FieldType ? FieldValue<TDerived[K]> | readonly FieldValue<TDerived[K]>[] | null : never; };
|
|
22
|
+
type Values<TModel> = TModel extends TableDefinition<infer TFields, infer TDerived> ? RowOf<TFields> & DerivedValues<TDerived> : TModel extends AggregateDefinition<infer TFields, infer TMetric, infer _TIndexes, infer TSketch> ? RowOf<TFields> & { -readonly [K in TMetric]: number; } & { -readonly [K in TSketch]: string; } : never;
|
|
23
|
+
/** A row read in a transaction, `_v` included, so the transaction can write it back. */
|
|
24
|
+
type TableRow<TModel> = Values<TModel> & EngineColumns;
|
|
25
|
+
/** A row read outside a transaction, without `_v`, which only a transaction's guard uses. */
|
|
26
|
+
type ReadRow<TModel> = Values<TModel> & RefColumns;
|
|
27
|
+
type AggregateRow<TModel> = Values<TModel>;
|
|
28
|
+
type IndexesOf<TModel> = TModel extends {
|
|
29
|
+
readonly indexes: infer I;
|
|
30
|
+
} ? I : never;
|
|
31
|
+
type IndexName<TModel> = keyof IndexesOf<TModel> & string;
|
|
32
|
+
type IndexFields<TModel, TIndex, TPart extends "eq" | "sort"> = IndexesOf<TModel>[TIndex & keyof IndexesOf<TModel>] extends { readonly [P in TPart]: readonly (infer F)[]; } ? F & keyof Values<TModel> : never;
|
|
33
|
+
type KeyValueOf<TModel, TField extends keyof Values<TModel>> = Exclude<Values<TModel>[TField], null | readonly unknown[]>;
|
|
34
|
+
type FirstOrderField<TModel, TIndex> = IndexesOf<TModel>[TIndex & keyof IndexesOf<TModel>] extends {
|
|
35
|
+
readonly sort: readonly [infer F, ...unknown[]];
|
|
36
|
+
} ? F & keyof Values<TModel> : TModel extends {
|
|
37
|
+
readonly key: readonly (infer K)[];
|
|
38
|
+
} ? K & keyof Values<TModel> : never;
|
|
39
|
+
interface ReadOptions<TModel, TIndex> {
|
|
40
|
+
readonly index: TIndex;
|
|
41
|
+
/** Every eq field of the index; null never matches. */
|
|
42
|
+
readonly where: { readonly [F in IndexFields<TModel, TIndex, "eq">]: KeyValueOf<TModel, F>; };
|
|
43
|
+
/** Bounds on the first order field, or on a prefix of the order tuple (sort fields, then the key). */
|
|
44
|
+
readonly range?: { readonly [B in "gt" | "gte" | "lt" | "lte"]?: KeyValueOf<TModel, FirstOrderField<TModel, TIndex>> | readonly [KeyValueOf<TModel, FirstOrderField<TModel, TIndex>>, ...DatabaseKeyValue[]]; };
|
|
45
|
+
readonly order?: "asc" | "desc";
|
|
46
|
+
readonly limit: number;
|
|
47
|
+
readonly cursor?: string;
|
|
48
|
+
}
|
|
49
|
+
type UniqueLookups<TModel> = TModel extends TableDefinition<infer TFields, infer _D, infer TIndexes> ? { [F in keyof TFields]: TFields[F] extends {
|
|
50
|
+
readonly unique: true;
|
|
51
|
+
} ? { readonly [P in F]: KeyValueOf<TModel, P & keyof Values<TModel>>; } : never; }[keyof TFields] | { [I in keyof TIndexes]: TIndexes[I] extends {
|
|
52
|
+
readonly unique: true;
|
|
53
|
+
readonly eq: readonly (infer E)[];
|
|
54
|
+
} ? { readonly [P in E & string]: KeyValueOf<TModel, P & keyof Values<TModel>>; } : never; }[keyof TIndexes] : never;
|
|
55
|
+
/** A table's key values. */
|
|
56
|
+
type KeyLookup<TModel> = TModel extends TableDefinition<infer _F> ? { readonly [K in TModel["key"][number]]: KeyValueOf<TModel, K & keyof Values<TModel>>; } : never;
|
|
57
|
+
/** The key, or the eq fields of a unique index. */
|
|
58
|
+
type Lookup<TModel> = KeyLookup<TModel> | UniqueLookups<TModel>;
|
|
59
|
+
type RootedIndexName<TModel> = { [I in keyof IndexesOf<TModel>]: IndexesOf<TModel>[I] extends {
|
|
60
|
+
readonly root: object;
|
|
61
|
+
} ? I : never; }[keyof IndexesOf<TModel>] & string;
|
|
62
|
+
type OptionalFields<TFields> = { [K in keyof TFields]: TFields[K] extends {
|
|
63
|
+
readonly required: false;
|
|
64
|
+
} ? K : never; }[keyof TFields];
|
|
65
|
+
/** Declared fields, optional ones omittable; derived fields and engine columns are computed. */
|
|
66
|
+
type CreateRow<TModel> = TModel extends TableDefinition<infer TFields> ? Omit<RowOf<TFields>, OptionalFields<TFields>> & Partial<Pick<RowOf<TFields>, OptionalFields<TFields>>> : never;
|
|
67
|
+
/** Changed non-key fields. */
|
|
68
|
+
type UpdateSet<TModel> = TModel extends TableDefinition<infer TFields, infer _D, infer _I, infer TKey> ? Partial<Omit<RowOf<TFields>, TKey[number]>> : never;
|
|
69
|
+
type AggregateIdentity<TModel> = TModel extends AggregateDefinition<infer TFields> ? RowOf<TFields> : never;
|
|
70
|
+
/** Counter and gauge deltas, and sketches to merge. */
|
|
71
|
+
type AggregateChanges<TModel> = TModel extends AggregateDefinition<infer _F, infer TMetric, infer _I, infer TSketch> ? { readonly [K in TMetric]?: number; } & { readonly [K in TSketch]?: string; } : never;
|
|
72
|
+
/** Reads are recorded and guarded at commit; writes apply only if every guard holds. */
|
|
73
|
+
interface HotUpdaterTransaction<S extends ModuleSchema> {
|
|
74
|
+
findOne<M extends TableNames<S>>(model: M, lookup: Lookup<S[M]>): Promise<TableRow<S[M]> | null>;
|
|
75
|
+
/** Rooted indexes only: the parent row guards the whole range. */
|
|
76
|
+
findMany<M extends TableNames<S>, I extends RootedIndexName<S[M]>>(model: M, options: ReadOptions<S[M], I>): Promise<Page<TableRow<S[M]>>>;
|
|
77
|
+
create<M extends TableNames<S>>(model: M, row: CreateRow<S[M]>): void;
|
|
78
|
+
/** Patches a row this transaction read, by key or through a rooted range. */
|
|
79
|
+
update<M extends TableNames<S>>(model: M, row: TableRow<S[M]>, set: UpdateSet<S[M]>): void;
|
|
80
|
+
/** Deletes a row this transaction read, cascading to its children first. */
|
|
81
|
+
delete<M extends TableNames<S>>(model: M, row: TableRow<S[M]>): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Changes one shard row of an aggregate. Gauges of a sharded aggregate need
|
|
84
|
+
* `shardBy`, so every change keyed by one value lands on one shard.
|
|
85
|
+
*/
|
|
86
|
+
aggregate<M extends AggregateNames<S>>(model: M, identity: AggregateIdentity<S[M]>, changes: AggregateChanges<S[M]>, options?: {
|
|
87
|
+
readonly shardBy?: string;
|
|
88
|
+
}): void;
|
|
89
|
+
}
|
|
90
|
+
/** A table name, or the reason an aggregate cannot be read this way. */
|
|
91
|
+
type FindManyModel<S extends ModuleSchema, M> = M extends TableNames<S> ? M : "findMany reads tables; read aggregates with findAggregates";
|
|
92
|
+
/** An aggregate name, or the reason a table cannot be read this way. */
|
|
93
|
+
type FindAggregatesModel<S extends ModuleSchema, M> = M extends AggregateNames<S> ? M : "findAggregates reads aggregates; read tables with findMany";
|
|
94
|
+
/** A module's database handle. There is no count, offset, or free-form filter. */
|
|
95
|
+
interface HotUpdaterDatabase<S extends ModuleSchema> {
|
|
96
|
+
findOne<M extends TableNames<S>>(model: M, lookup: Lookup<S[M]>): Promise<ReadRow<S[M]> | null>;
|
|
97
|
+
/** Rows by key in one batch read, in the keys' order. */
|
|
98
|
+
findByKeys<M extends TableNames<S>>(model: M, keys: readonly KeyLookup<S[M]>[]): Promise<(ReadRow<S[M]> | null)[]>;
|
|
99
|
+
findMany<M extends keyof S & string, I extends IndexName<S[M]>>(model: FindManyModel<S, M>, options: ReadOptions<S[M], I>): Promise<Page<ReadRow<S[M]>>>;
|
|
100
|
+
findAggregates<M extends keyof S & string, I extends IndexName<S[M]>>(model: FindAggregatesModel<S, M>, options: ReadOptions<S[M], I>): Promise<Page<AggregateRow<S[M]>>>;
|
|
101
|
+
/** Reruns `fn` when a guarded read changed, within a jittered retry budget. */
|
|
102
|
+
transaction<R>(fn: (tx: HotUpdaterTransaction<S>) => Promise<R>): Promise<R>;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { AggregateChanges, AggregateIdentity, AggregateRow, CreateRow, EngineColumns, FindAggregatesModel, FindManyModel, HotUpdaterDatabase, HotUpdaterTransaction, KeyLookup, Lookup, Page, ReadOptions, ReadRow, TableRow, UpdateSet };
|