@hot-updater/plugin-core 1.0.0-rc.3 → 1.0.0-rc.30
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/bundleStorageLayout.cjs +7 -0
- package/dist/bundleStorageLayout.d.cts +5 -1
- package/dist/bundleStorageLayout.d.mts +5 -1
- package/dist/bundleStorageLayout.mjs +7 -1
- package/dist/contentType.cjs +9 -0
- package/dist/contentType.d.cts +4 -0
- package/dist/contentType.d.mts +4 -0
- package/dist/contentType.mjs +7 -0
- package/dist/coreApi.d.cts +131 -0
- package/dist/coreApi.d.mts +131 -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 +61 -0
- package/dist/database/adapter.d.cts +200 -0
- package/dist/database/adapter.d.mts +200 -0
- package/dist/database/adapter.mjs +55 -0
- package/dist/database/distinct.cjs +88 -0
- package/dist/database/distinct.d.cts +18 -0
- package/dist/database/distinct.d.mts +18 -0
- package/dist/database/distinct.mjs +85 -0
- package/dist/database/memoryAdapter.cjs +107 -0
- package/dist/database/memoryAdapter.d.cts +14 -0
- package/dist/database/memoryAdapter.d.mts +14 -0
- package/dist/database/memoryAdapter.mjs +107 -0
- package/dist/database/values.cjs +114 -0
- package/dist/database/values.d.cts +17 -0
- package/dist/database/values.d.mts +17 -0
- package/dist/database/values.mjs +104 -0
- package/dist/database/verifyAdapter.cjs +137 -0
- package/dist/database/verifyAdapter.d.cts +37 -0
- package/dist/database/verifyAdapter.d.mts +37 -0
- package/dist/database/verifyAdapter.mjs +136 -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 +6 -0
- package/dist/databaseJsonValue.d.cts +9 -2
- package/dist/databaseJsonValue.d.mts +9 -2
- package/dist/databaseJsonValue.mjs +6 -0
- package/dist/databaseMetadata.cjs +4 -4
- package/dist/databaseMetadata.mjs +3 -3
- package/dist/databaseRows.cjs +6 -12
- package/dist/databaseRows.d.cts +1 -1
- package/dist/databaseRows.d.mts +1 -1
- package/dist/databaseRows.mjs +1 -7
- 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 +97 -49
- package/dist/index.d.cts +46 -22
- package/dist/index.d.mts +46 -22
- package/dist/index.mjs +32 -17
- 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 +27 -26
- package/dist/releaseCatalogCompiler.d.cts +1 -2
- package/dist/releaseCatalogCompiler.d.mts +2 -3
- package/dist/releaseCatalogCompiler.mjs +5 -9
- 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/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 +5 -0
- package/dist/types/databaseConfig.d.cts +68 -0
- package/dist/types/databaseConfig.d.mts +68 -0
- package/dist/types/databaseConfig.mjs +5 -0
- package/dist/types/databaseOperations.d.cts +5 -180
- package/dist/types/databaseOperations.d.mts +5 -180
- package/dist/types/databaseRows.d.cts +5 -56
- package/dist/types/databaseRows.d.mts +5 -56
- package/dist/types/index.cjs +2 -0
- package/dist/types/index.d.cts +31 -97
- package/dist/types/index.d.mts +31 -97
- package/dist/types/index.mjs +2 -1
- 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/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/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/compressionFormat.cjs +0 -62
- package/dist/compressionFormat.d.cts +0 -33
- package/dist/compressionFormat.d.mts +0 -33
- package/dist/compressionFormat.mjs +0 -58
- package/dist/createDatabasePlugin.cjs +0 -920
- package/dist/createDatabasePlugin.d.cts +0 -28
- package/dist/createDatabasePlugin.d.mts +0 -28
- package/dist/createDatabasePlugin.mjs +0 -916
- 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/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 -40
- package/dist/databaseClientUpdates.d.cts +0 -11
- package/dist/databaseClientUpdates.d.mts +0 -11
- package/dist/databaseClientUpdates.mjs +0 -38
- package/dist/databasePluginCrud.cjs +0 -88
- package/dist/databasePluginCrud.d.cts +0 -4
- package/dist/databasePluginCrud.d.mts +0 -4
- package/dist/databasePluginCrud.mjs +0 -87
- 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 -321
- package/dist/databasePluginCrudValidationFields.d.cts +0 -1
- package/dist/databasePluginCrudValidationFields.d.mts +0 -1
- package/dist/databasePluginCrudValidationFields.mjs +0 -309
- package/dist/databasePluginCrudValidationMutations.cjs +0 -107
- package/dist/databasePluginCrudValidationMutations.d.cts +0 -1
- package/dist/databasePluginCrudValidationMutations.d.mts +0 -1
- package/dist/databasePluginCrudValidationMutations.mjs +0 -100
- 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 -157
- package/dist/insightsContract.d.cts +0 -11
- package/dist/insightsContract.d.mts +0 -11
- package/dist/insightsContract.mjs +0 -153
- package/dist/internal.cjs +0 -6
- package/dist/internal.d.cts +0 -10
- package/dist/internal.d.mts +0 -10
- package/dist/internal.mjs +0 -3
- 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 -105
- package/dist/types/databaseFields.d.cts +0 -13
- package/dist/types/databaseFields.d.mts +0 -13
- package/dist/types/databaseFields.mjs +0 -105
- package/dist/types/databasePlugin.d.cts +0 -298
- package/dist/types/databasePlugin.d.mts +0 -298
- package/dist/types/databaseQuery.d.cts +0 -46
- package/dist/types/databaseQuery.d.mts +0 -46
- package/dist/types/internal.d.cts +0 -8
- package/dist/types/internal.d.mts +0 -8
|
@@ -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 };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { CoreReads } from "./coreReads.cjs";
|
|
2
|
+
import { ModuleSchema } from "./schema.cjs";
|
|
3
|
+
import { HotUpdaterDatabase } from "./databaseHandle.cjs";
|
|
4
|
+
//#region src/serverPlugin/definePlugin.d.ts
|
|
5
|
+
type PluginEndpointMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
6
|
+
interface PluginEndpoint {
|
|
7
|
+
readonly method: PluginEndpointMethod;
|
|
8
|
+
/** Relative to the handler's mount; `:name` segments become `params`. */
|
|
9
|
+
readonly path: string;
|
|
10
|
+
/**
|
|
11
|
+
* `"client"` mounts on `handlers.client` behind the client-route policy;
|
|
12
|
+
* `"admin"` mounts on `handlers.admin`, which the host protects.
|
|
13
|
+
*/
|
|
14
|
+
readonly access: "client" | "admin";
|
|
15
|
+
readonly handler: (request: Request, params: Readonly<Record<string, string>>) => Promise<Response>;
|
|
16
|
+
}
|
|
17
|
+
/** The client-route policy a plugin provides, such as a key or token check. */
|
|
18
|
+
interface ClientAuth {
|
|
19
|
+
/** Request headers the decision reads; core adds them to `Vary` on cacheable client responses. */
|
|
20
|
+
readonly varyHeaders: readonly string[];
|
|
21
|
+
/** Whether the request may use client routes; a throw answers 503. */
|
|
22
|
+
authenticate(headers: Headers): Promise<boolean>;
|
|
23
|
+
}
|
|
24
|
+
interface PluginInstance<Api = unknown> {
|
|
25
|
+
readonly api: Api;
|
|
26
|
+
readonly endpoints?: readonly PluginEndpoint[];
|
|
27
|
+
readonly clientAuth?: ClientAuth;
|
|
28
|
+
}
|
|
29
|
+
/** Core's reads: bundles, Releases, Catalogs, and channels, each through a declared index. Plugins never write core. */
|
|
30
|
+
type CoreReader = CoreReads;
|
|
31
|
+
interface PluginContext<S extends ModuleSchema> {
|
|
32
|
+
/** The plugin's own tables and aggregates. */
|
|
33
|
+
readonly db: HotUpdaterDatabase<S>;
|
|
34
|
+
readonly core: CoreReader;
|
|
35
|
+
now(): number;
|
|
36
|
+
}
|
|
37
|
+
interface PluginProvides {
|
|
38
|
+
readonly clientAuth?: true;
|
|
39
|
+
}
|
|
40
|
+
/** An instance whose `clientAuth` matches what the plugin declares it provides. */
|
|
41
|
+
type InstanceFor<TProvides, TInstance> = TProvides extends {
|
|
42
|
+
readonly clientAuth: true;
|
|
43
|
+
} ? TInstance & {
|
|
44
|
+
readonly clientAuth: ClientAuth;
|
|
45
|
+
} : TInstance & {
|
|
46
|
+
readonly clientAuth?: "Declare provides: { clientAuth: true } to return clientAuth";
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The credential an app sends to client routes that the plugin's clientAuth
|
|
50
|
+
* guards. Init provisions it and prints the header to send, the agent
|
|
51
|
+
* scaffold stores it, and doctor checks it.
|
|
52
|
+
*/
|
|
53
|
+
interface PluginClientCredential<Api = unknown> {
|
|
54
|
+
/** Its name in output, such as "API key". */
|
|
55
|
+
readonly label: string;
|
|
56
|
+
/** The request header that carries it, one of clientAuth's varyHeaders. */
|
|
57
|
+
readonly header: string;
|
|
58
|
+
/** The environment variable init stores it in. */
|
|
59
|
+
readonly env: string;
|
|
60
|
+
/** A new credential, made without a database, so tooling can save it before registering it. */
|
|
61
|
+
generate(): string;
|
|
62
|
+
/** Registers `existing` idempotently, or creates one; returns the credential. */
|
|
63
|
+
provision(api: Api, input: {
|
|
64
|
+
readonly existing?: string;
|
|
65
|
+
readonly name: string;
|
|
66
|
+
}): Promise<string>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A client plugin an app adds to `HotUpdater.init`'s `plugins` to work with
|
|
70
|
+
* the server plugin. Init prints it in the app code, and the agent scaffold
|
|
71
|
+
* asks for it.
|
|
72
|
+
*/
|
|
73
|
+
interface PluginClientPlugin {
|
|
74
|
+
/** The module that exports it, such as `@hot-updater/react-native`, which exports `insights`. */
|
|
75
|
+
readonly module: string;
|
|
76
|
+
/** The export, which the app calls with no arguments, such as `insights`. */
|
|
77
|
+
readonly name: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* What the CLI reads from a plugin: the credential init provisions, and the
|
|
81
|
+
* client plugin init prints and doctor checks.
|
|
82
|
+
*/
|
|
83
|
+
interface PluginCli<Api = unknown> {
|
|
84
|
+
/** Needs provides: { clientAuth: true }. */
|
|
85
|
+
readonly clientCredential?: PluginClientCredential<Api>;
|
|
86
|
+
readonly clientPlugin?: PluginClientPlugin;
|
|
87
|
+
}
|
|
88
|
+
/** CLI additions whose `clientCredential` matches what the plugin declares it provides. */
|
|
89
|
+
type CliFor<TProvides, TApi> = TProvides extends {
|
|
90
|
+
readonly clientAuth: true;
|
|
91
|
+
} ? PluginCli<TApi> : Omit<PluginCli<TApi>, "clientCredential"> & {
|
|
92
|
+
readonly clientCredential?: "Declare provides: { clientAuth: true } to add clientCredential";
|
|
93
|
+
};
|
|
94
|
+
interface HotUpdaterPlugin<TId extends string = string, TSchema extends ModuleSchema = ModuleSchema, TInstance extends PluginInstance = PluginInstance, TProvides extends PluginProvides = PluginProvides> {
|
|
95
|
+
readonly id: TId;
|
|
96
|
+
/** Static, so the type system and startup can count client-route policies. */
|
|
97
|
+
readonly provides?: TProvides;
|
|
98
|
+
/** Stored under the settings key `schema.<id>`. */
|
|
99
|
+
readonly schemaVersion: string;
|
|
100
|
+
readonly schema: TSchema;
|
|
101
|
+
/**
|
|
102
|
+
* `false` keeps the declared table names instead of prefixing them with
|
|
103
|
+
* the plugin's id. The plugin then owns collisions with core's tables and
|
|
104
|
+
* other plugins' tables, which startup checks for the plugins a server
|
|
105
|
+
* runs, and only such a plugin may take a camelCase id.
|
|
106
|
+
*/
|
|
107
|
+
readonly namespace?: false;
|
|
108
|
+
/** Called once at startup, synchronously. */
|
|
109
|
+
init(context: PluginContext<TSchema>): TInstance;
|
|
110
|
+
/** Read by the CLI only; the server never runs it. */
|
|
111
|
+
readonly cli?: PluginCli<TInstance["api"]>;
|
|
112
|
+
/** Only core modules carry a kind. */
|
|
113
|
+
readonly kind?: "Core is built in; it is not a plugin";
|
|
114
|
+
}
|
|
115
|
+
/** Declares a plugin; Hot Updater's own plugins and third-party ones use the same contract. */
|
|
116
|
+
declare const definePlugin: <const TId extends string, const TSchema extends ModuleSchema, TInstance extends PluginInstance, const TProvides extends PluginProvides = {}>(plugin: {
|
|
117
|
+
readonly id: TId;
|
|
118
|
+
readonly provides?: TProvides;
|
|
119
|
+
readonly schemaVersion: string;
|
|
120
|
+
readonly schema: TSchema;
|
|
121
|
+
readonly namespace?: false;
|
|
122
|
+
init(context: PluginContext<TSchema>): InstanceFor<TProvides, TInstance>;
|
|
123
|
+
readonly cli?: CliFor<TProvides, NoInfer<TInstance["api"]>>;
|
|
124
|
+
}) => HotUpdaterPlugin<TId, TSchema, TInstance, TProvides>;
|
|
125
|
+
/** Any plugin, whatever its schema and API. */
|
|
126
|
+
type AnyHotUpdaterPlugin = HotUpdaterPlugin<string, any, any, any>;
|
|
127
|
+
/** Each plugin's API by id. */
|
|
128
|
+
type PluginApis<TPlugins extends readonly AnyHotUpdaterPlugin[]> = { readonly [TPlugin in TPlugins[number] as TPlugin["id"]]: ReturnType<TPlugin["init"]>["api"]; };
|
|
129
|
+
//#endregion
|
|
130
|
+
export { AnyHotUpdaterPlugin, CliFor, ClientAuth, CoreReader, HotUpdaterPlugin, InstanceFor, PluginApis, PluginCli, PluginClientCredential, PluginClientPlugin, PluginContext, PluginEndpoint, PluginEndpointMethod, PluginInstance, PluginProvides, definePlugin };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { CoreReads } from "./coreReads.mjs";
|
|
2
|
+
import { ModuleSchema } from "./schema.mjs";
|
|
3
|
+
import { HotUpdaterDatabase } from "./databaseHandle.mjs";
|
|
4
|
+
//#region src/serverPlugin/definePlugin.d.ts
|
|
5
|
+
type PluginEndpointMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
6
|
+
interface PluginEndpoint {
|
|
7
|
+
readonly method: PluginEndpointMethod;
|
|
8
|
+
/** Relative to the handler's mount; `:name` segments become `params`. */
|
|
9
|
+
readonly path: string;
|
|
10
|
+
/**
|
|
11
|
+
* `"client"` mounts on `handlers.client` behind the client-route policy;
|
|
12
|
+
* `"admin"` mounts on `handlers.admin`, which the host protects.
|
|
13
|
+
*/
|
|
14
|
+
readonly access: "client" | "admin";
|
|
15
|
+
readonly handler: (request: Request, params: Readonly<Record<string, string>>) => Promise<Response>;
|
|
16
|
+
}
|
|
17
|
+
/** The client-route policy a plugin provides, such as a key or token check. */
|
|
18
|
+
interface ClientAuth {
|
|
19
|
+
/** Request headers the decision reads; core adds them to `Vary` on cacheable client responses. */
|
|
20
|
+
readonly varyHeaders: readonly string[];
|
|
21
|
+
/** Whether the request may use client routes; a throw answers 503. */
|
|
22
|
+
authenticate(headers: Headers): Promise<boolean>;
|
|
23
|
+
}
|
|
24
|
+
interface PluginInstance<Api = unknown> {
|
|
25
|
+
readonly api: Api;
|
|
26
|
+
readonly endpoints?: readonly PluginEndpoint[];
|
|
27
|
+
readonly clientAuth?: ClientAuth;
|
|
28
|
+
}
|
|
29
|
+
/** Core's reads: bundles, Releases, Catalogs, and channels, each through a declared index. Plugins never write core. */
|
|
30
|
+
type CoreReader = CoreReads;
|
|
31
|
+
interface PluginContext<S extends ModuleSchema> {
|
|
32
|
+
/** The plugin's own tables and aggregates. */
|
|
33
|
+
readonly db: HotUpdaterDatabase<S>;
|
|
34
|
+
readonly core: CoreReader;
|
|
35
|
+
now(): number;
|
|
36
|
+
}
|
|
37
|
+
interface PluginProvides {
|
|
38
|
+
readonly clientAuth?: true;
|
|
39
|
+
}
|
|
40
|
+
/** An instance whose `clientAuth` matches what the plugin declares it provides. */
|
|
41
|
+
type InstanceFor<TProvides, TInstance> = TProvides extends {
|
|
42
|
+
readonly clientAuth: true;
|
|
43
|
+
} ? TInstance & {
|
|
44
|
+
readonly clientAuth: ClientAuth;
|
|
45
|
+
} : TInstance & {
|
|
46
|
+
readonly clientAuth?: "Declare provides: { clientAuth: true } to return clientAuth";
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The credential an app sends to client routes that the plugin's clientAuth
|
|
50
|
+
* guards. Init provisions it and prints the header to send, the agent
|
|
51
|
+
* scaffold stores it, and doctor checks it.
|
|
52
|
+
*/
|
|
53
|
+
interface PluginClientCredential<Api = unknown> {
|
|
54
|
+
/** Its name in output, such as "API key". */
|
|
55
|
+
readonly label: string;
|
|
56
|
+
/** The request header that carries it, one of clientAuth's varyHeaders. */
|
|
57
|
+
readonly header: string;
|
|
58
|
+
/** The environment variable init stores it in. */
|
|
59
|
+
readonly env: string;
|
|
60
|
+
/** A new credential, made without a database, so tooling can save it before registering it. */
|
|
61
|
+
generate(): string;
|
|
62
|
+
/** Registers `existing` idempotently, or creates one; returns the credential. */
|
|
63
|
+
provision(api: Api, input: {
|
|
64
|
+
readonly existing?: string;
|
|
65
|
+
readonly name: string;
|
|
66
|
+
}): Promise<string>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A client plugin an app adds to `HotUpdater.init`'s `plugins` to work with
|
|
70
|
+
* the server plugin. Init prints it in the app code, and the agent scaffold
|
|
71
|
+
* asks for it.
|
|
72
|
+
*/
|
|
73
|
+
interface PluginClientPlugin {
|
|
74
|
+
/** The module that exports it, such as `@hot-updater/react-native`, which exports `insights`. */
|
|
75
|
+
readonly module: string;
|
|
76
|
+
/** The export, which the app calls with no arguments, such as `insights`. */
|
|
77
|
+
readonly name: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* What the CLI reads from a plugin: the credential init provisions, and the
|
|
81
|
+
* client plugin init prints and doctor checks.
|
|
82
|
+
*/
|
|
83
|
+
interface PluginCli<Api = unknown> {
|
|
84
|
+
/** Needs provides: { clientAuth: true }. */
|
|
85
|
+
readonly clientCredential?: PluginClientCredential<Api>;
|
|
86
|
+
readonly clientPlugin?: PluginClientPlugin;
|
|
87
|
+
}
|
|
88
|
+
/** CLI additions whose `clientCredential` matches what the plugin declares it provides. */
|
|
89
|
+
type CliFor<TProvides, TApi> = TProvides extends {
|
|
90
|
+
readonly clientAuth: true;
|
|
91
|
+
} ? PluginCli<TApi> : Omit<PluginCli<TApi>, "clientCredential"> & {
|
|
92
|
+
readonly clientCredential?: "Declare provides: { clientAuth: true } to add clientCredential";
|
|
93
|
+
};
|
|
94
|
+
interface HotUpdaterPlugin<TId extends string = string, TSchema extends ModuleSchema = ModuleSchema, TInstance extends PluginInstance = PluginInstance, TProvides extends PluginProvides = PluginProvides> {
|
|
95
|
+
readonly id: TId;
|
|
96
|
+
/** Static, so the type system and startup can count client-route policies. */
|
|
97
|
+
readonly provides?: TProvides;
|
|
98
|
+
/** Stored under the settings key `schema.<id>`. */
|
|
99
|
+
readonly schemaVersion: string;
|
|
100
|
+
readonly schema: TSchema;
|
|
101
|
+
/**
|
|
102
|
+
* `false` keeps the declared table names instead of prefixing them with
|
|
103
|
+
* the plugin's id. The plugin then owns collisions with core's tables and
|
|
104
|
+
* other plugins' tables, which startup checks for the plugins a server
|
|
105
|
+
* runs, and only such a plugin may take a camelCase id.
|
|
106
|
+
*/
|
|
107
|
+
readonly namespace?: false;
|
|
108
|
+
/** Called once at startup, synchronously. */
|
|
109
|
+
init(context: PluginContext<TSchema>): TInstance;
|
|
110
|
+
/** Read by the CLI only; the server never runs it. */
|
|
111
|
+
readonly cli?: PluginCli<TInstance["api"]>;
|
|
112
|
+
/** Only core modules carry a kind. */
|
|
113
|
+
readonly kind?: "Core is built in; it is not a plugin";
|
|
114
|
+
}
|
|
115
|
+
/** Declares a plugin; Hot Updater's own plugins and third-party ones use the same contract. */
|
|
116
|
+
declare const definePlugin: <const TId extends string, const TSchema extends ModuleSchema, TInstance extends PluginInstance, const TProvides extends PluginProvides = {}>(plugin: {
|
|
117
|
+
readonly id: TId;
|
|
118
|
+
readonly provides?: TProvides;
|
|
119
|
+
readonly schemaVersion: string;
|
|
120
|
+
readonly schema: TSchema;
|
|
121
|
+
readonly namespace?: false;
|
|
122
|
+
init(context: PluginContext<TSchema>): InstanceFor<TProvides, TInstance>;
|
|
123
|
+
readonly cli?: CliFor<TProvides, NoInfer<TInstance["api"]>>;
|
|
124
|
+
}) => HotUpdaterPlugin<TId, TSchema, TInstance, TProvides>;
|
|
125
|
+
/** Any plugin, whatever its schema and API. */
|
|
126
|
+
type AnyHotUpdaterPlugin = HotUpdaterPlugin<string, any, any, any>;
|
|
127
|
+
/** Each plugin's API by id. */
|
|
128
|
+
type PluginApis<TPlugins extends readonly AnyHotUpdaterPlugin[]> = { readonly [TPlugin in TPlugins[number] as TPlugin["id"]]: ReturnType<TPlugin["init"]>["api"]; };
|
|
129
|
+
//#endregion
|
|
130
|
+
export { AnyHotUpdaterPlugin, CliFor, ClientAuth, CoreReader, HotUpdaterPlugin, InstanceFor, PluginApis, PluginCli, PluginClientCredential, PluginClientPlugin, PluginContext, PluginEndpoint, PluginEndpointMethod, PluginInstance, PluginProvides, definePlugin };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//#region src/serverPlugin/definitions.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The model declarations the engine reads. `defineTable` and
|
|
4
|
+
* `defineAggregate` (./schema) build them with typed rows.
|
|
5
|
+
*/
|
|
6
|
+
type FieldType = "string" | "integer" | "number" | "boolean" | "json";
|
|
7
|
+
type ReferenceAction = "restrict" | "cascade" | "none";
|
|
8
|
+
interface FieldReference {
|
|
9
|
+
readonly model: string;
|
|
10
|
+
readonly onDelete: ReferenceAction;
|
|
11
|
+
}
|
|
12
|
+
interface FieldDefinition<TType extends FieldType = FieldType> {
|
|
13
|
+
readonly type: TType;
|
|
14
|
+
/** Defaults to true; an optional field stores null. */
|
|
15
|
+
readonly required?: boolean;
|
|
16
|
+
/** Adds a unique index named after the field. */
|
|
17
|
+
readonly unique?: true;
|
|
18
|
+
/** Strings: the maximum length; unbounded text when absent. */
|
|
19
|
+
readonly maxLength?: number;
|
|
20
|
+
/** Strings: ASCII only, so a long key fits MySQL's 3,072-byte index limit. */
|
|
21
|
+
readonly ascii?: true;
|
|
22
|
+
readonly references?: FieldReference;
|
|
23
|
+
}
|
|
24
|
+
interface IndexDefinition<TField extends string = string> {
|
|
25
|
+
readonly eq: readonly TField[];
|
|
26
|
+
readonly sort: readonly TField[];
|
|
27
|
+
/** The eq values identify at most one row. */
|
|
28
|
+
readonly unique?: true;
|
|
29
|
+
/** `eq` starts with the key of a `model` row, which every child write bumps. */
|
|
30
|
+
readonly root?: {
|
|
31
|
+
readonly model: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** A field computed on every write and stored as a real column. */
|
|
35
|
+
interface DerivedShape {
|
|
36
|
+
readonly type: FieldType;
|
|
37
|
+
/** Up to 16 values; the row is indexed once per value. */
|
|
38
|
+
readonly multi?: true;
|
|
39
|
+
/** Null, or an empty list, leaves the row out of indexes on this field. */
|
|
40
|
+
compute(row: never): unknown;
|
|
41
|
+
}
|
|
42
|
+
interface TableShape {
|
|
43
|
+
readonly kind: "table";
|
|
44
|
+
readonly fields: Readonly<Record<string, FieldDefinition>>;
|
|
45
|
+
readonly key: readonly string[];
|
|
46
|
+
readonly derived: Readonly<Record<string, DerivedShape>>;
|
|
47
|
+
readonly indexes: Readonly<Record<string, IndexDefinition>>;
|
|
48
|
+
/** Rows expire `days` after the epoch milliseconds in `field`. */
|
|
49
|
+
readonly retention?: {
|
|
50
|
+
readonly field: string;
|
|
51
|
+
readonly days: number;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
interface AggregateShape {
|
|
55
|
+
readonly kind: "aggregate";
|
|
56
|
+
/** Identity fields; `key` lists them in declaration order. */
|
|
57
|
+
readonly fields: Readonly<Record<string, FieldDefinition>>;
|
|
58
|
+
readonly key: readonly string[];
|
|
59
|
+
/** Blind increments. */
|
|
60
|
+
readonly counters: readonly string[];
|
|
61
|
+
/** Read, merged, and written back per shard; a row at zero is deleted. */
|
|
62
|
+
readonly gauges: readonly string[];
|
|
63
|
+
/** HLL sketches, kept in aggregates of their own. */
|
|
64
|
+
readonly distinct: readonly string[];
|
|
65
|
+
/** Fixed once data exists. */
|
|
66
|
+
readonly shards: number;
|
|
67
|
+
readonly indexes: Readonly<Record<string, IndexDefinition>>;
|
|
68
|
+
/** On an identity field; a change to a row past it is dropped. */
|
|
69
|
+
readonly retention?: {
|
|
70
|
+
readonly field: string;
|
|
71
|
+
readonly days: number;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
type ModelShape = TableShape | AggregateShape;
|
|
75
|
+
//#endregion
|
|
76
|
+
export { AggregateShape, DerivedShape, FieldDefinition, FieldReference, FieldType, IndexDefinition, ModelShape, ReferenceAction, TableShape };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//#region src/serverPlugin/definitions.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The model declarations the engine reads. `defineTable` and
|
|
4
|
+
* `defineAggregate` (./schema) build them with typed rows.
|
|
5
|
+
*/
|
|
6
|
+
type FieldType = "string" | "integer" | "number" | "boolean" | "json";
|
|
7
|
+
type ReferenceAction = "restrict" | "cascade" | "none";
|
|
8
|
+
interface FieldReference {
|
|
9
|
+
readonly model: string;
|
|
10
|
+
readonly onDelete: ReferenceAction;
|
|
11
|
+
}
|
|
12
|
+
interface FieldDefinition<TType extends FieldType = FieldType> {
|
|
13
|
+
readonly type: TType;
|
|
14
|
+
/** Defaults to true; an optional field stores null. */
|
|
15
|
+
readonly required?: boolean;
|
|
16
|
+
/** Adds a unique index named after the field. */
|
|
17
|
+
readonly unique?: true;
|
|
18
|
+
/** Strings: the maximum length; unbounded text when absent. */
|
|
19
|
+
readonly maxLength?: number;
|
|
20
|
+
/** Strings: ASCII only, so a long key fits MySQL's 3,072-byte index limit. */
|
|
21
|
+
readonly ascii?: true;
|
|
22
|
+
readonly references?: FieldReference;
|
|
23
|
+
}
|
|
24
|
+
interface IndexDefinition<TField extends string = string> {
|
|
25
|
+
readonly eq: readonly TField[];
|
|
26
|
+
readonly sort: readonly TField[];
|
|
27
|
+
/** The eq values identify at most one row. */
|
|
28
|
+
readonly unique?: true;
|
|
29
|
+
/** `eq` starts with the key of a `model` row, which every child write bumps. */
|
|
30
|
+
readonly root?: {
|
|
31
|
+
readonly model: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** A field computed on every write and stored as a real column. */
|
|
35
|
+
interface DerivedShape {
|
|
36
|
+
readonly type: FieldType;
|
|
37
|
+
/** Up to 16 values; the row is indexed once per value. */
|
|
38
|
+
readonly multi?: true;
|
|
39
|
+
/** Null, or an empty list, leaves the row out of indexes on this field. */
|
|
40
|
+
compute(row: never): unknown;
|
|
41
|
+
}
|
|
42
|
+
interface TableShape {
|
|
43
|
+
readonly kind: "table";
|
|
44
|
+
readonly fields: Readonly<Record<string, FieldDefinition>>;
|
|
45
|
+
readonly key: readonly string[];
|
|
46
|
+
readonly derived: Readonly<Record<string, DerivedShape>>;
|
|
47
|
+
readonly indexes: Readonly<Record<string, IndexDefinition>>;
|
|
48
|
+
/** Rows expire `days` after the epoch milliseconds in `field`. */
|
|
49
|
+
readonly retention?: {
|
|
50
|
+
readonly field: string;
|
|
51
|
+
readonly days: number;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
interface AggregateShape {
|
|
55
|
+
readonly kind: "aggregate";
|
|
56
|
+
/** Identity fields; `key` lists them in declaration order. */
|
|
57
|
+
readonly fields: Readonly<Record<string, FieldDefinition>>;
|
|
58
|
+
readonly key: readonly string[];
|
|
59
|
+
/** Blind increments. */
|
|
60
|
+
readonly counters: readonly string[];
|
|
61
|
+
/** Read, merged, and written back per shard; a row at zero is deleted. */
|
|
62
|
+
readonly gauges: readonly string[];
|
|
63
|
+
/** HLL sketches, kept in aggregates of their own. */
|
|
64
|
+
readonly distinct: readonly string[];
|
|
65
|
+
/** Fixed once data exists. */
|
|
66
|
+
readonly shards: number;
|
|
67
|
+
readonly indexes: Readonly<Record<string, IndexDefinition>>;
|
|
68
|
+
/** On an identity field; a change to a row past it is dropped. */
|
|
69
|
+
readonly retention?: {
|
|
70
|
+
readonly field: string;
|
|
71
|
+
readonly days: number;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
type ModelShape = TableShape | AggregateShape;
|
|
75
|
+
//#endregion
|
|
76
|
+
export { AggregateShape, DerivedShape, FieldDefinition, FieldReference, FieldType, IndexDefinition, ModelShape, ReferenceAction, TableShape };
|