@hot-updater/server 1.0.0-rc.2 → 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/LICENSE +12 -14
- package/dist/adapters/drizzle.cjs +32 -75
- package/dist/adapters/drizzle.d.cts +13 -5
- package/dist/adapters/drizzle.d.mts +13 -5
- package/dist/adapters/drizzle.mjs +32 -77
- package/dist/adapters/drizzleExecutor.cjs +114 -0
- package/dist/adapters/drizzleExecutor.d.cts +9 -0
- package/dist/adapters/drizzleExecutor.d.mts +9 -0
- package/dist/adapters/drizzleExecutor.mjs +112 -0
- package/dist/adapters/kysely.cjs +22 -31
- package/dist/adapters/kysely.d.cts +10 -6
- package/dist/adapters/kysely.d.mts +10 -6
- package/dist/adapters/kysely.mjs +23 -33
- package/dist/adapters/kyselyExecutor.cjs +32 -0
- package/dist/adapters/kyselyExecutor.d.cts +11 -0
- package/dist/adapters/kyselyExecutor.d.mts +11 -0
- package/dist/adapters/kyselyExecutor.mjs +32 -0
- package/dist/adapters/mongodb.cjs +18 -54
- package/dist/adapters/mongodb.d.cts +10 -5
- package/dist/adapters/mongodb.d.mts +10 -5
- package/dist/adapters/mongodb.mjs +19 -56
- package/dist/adapters/mongodbAdapter.cjs +192 -0
- package/dist/adapters/mongodbAdapter.d.cts +9 -0
- package/dist/adapters/mongodbAdapter.d.mts +9 -0
- package/dist/adapters/mongodbAdapter.mjs +191 -0
- package/dist/adapters/prisma.cjs +35 -267
- package/dist/adapters/prisma.d.cts +12 -7
- package/dist/adapters/prisma.d.mts +12 -7
- package/dist/adapters/prisma.mjs +36 -268
- package/dist/adapters/prismaExecutor.cjs +63 -0
- package/dist/adapters/prismaExecutor.mjs +63 -0
- package/dist/adapters/sqlProviders.cjs +14 -0
- package/dist/adapters/sqlProviders.mjs +14 -0
- package/dist/assembly/assemblePlugins.cjs +144 -0
- package/dist/assembly/assemblePlugins.d.cts +5 -0
- package/dist/assembly/assemblePlugins.d.mts +5 -0
- package/dist/assembly/assemblePlugins.mjs +139 -0
- package/dist/assembly/clientPlugins.cjs +88 -0
- package/dist/assembly/clientPlugins.mjs +88 -0
- package/dist/assembly/configError.d.cts +2 -0
- package/dist/assembly/configError.d.mts +2 -0
- package/dist/assembly/configError.mjs +2 -0
- package/dist/core/api.cjs +51 -0
- package/dist/core/api.d.cts +54 -0
- package/dist/core/api.d.mts +54 -0
- package/dist/core/api.mjs +51 -0
- package/dist/core/baseCandidates.cjs +28 -0
- package/dist/core/baseCandidates.mjs +28 -0
- package/dist/core/operations.cjs +351 -0
- package/dist/core/operations.mjs +351 -0
- package/dist/core/reads.cjs +273 -0
- package/dist/core/reads.d.cts +9 -0
- package/dist/core/reads.d.mts +9 -0
- package/dist/core/reads.mjs +267 -0
- package/dist/core/releases.cjs +193 -0
- package/dist/core/releases.mjs +190 -0
- package/dist/core/writes.cjs +96 -0
- package/dist/core/writes.mjs +91 -0
- package/dist/createHotUpdaterCore.cjs +72 -91
- package/dist/createHotUpdaterCore.d.cts +106 -38
- package/dist/createHotUpdaterCore.d.mts +106 -38
- package/dist/createHotUpdaterCore.mjs +74 -89
- package/dist/db/engineDrizzleSchema.cjs +53 -0
- package/dist/db/engineDrizzleSchema.mjs +53 -0
- package/dist/db/enginePrismaSchema.cjs +84 -0
- package/dist/db/enginePrismaSchema.d.cts +5 -0
- package/dist/db/enginePrismaSchema.d.mts +5 -0
- package/dist/db/enginePrismaSchema.mjs +83 -0
- package/dist/db/releaseCatalog.cjs +24 -47
- package/dist/db/releaseCatalog.mjs +20 -44
- package/dist/db/updateArtifacts.cjs +43 -72
- package/dist/db/updateArtifacts.mjs +40 -69
- package/dist/handler.cjs +59 -43
- package/dist/handler.d.cts +3 -5
- package/dist/handler.d.mts +3 -5
- package/dist/handler.mjs +61 -43
- package/dist/handlerAdminRoutes.cjs +374 -0
- package/dist/handlerAdminRoutes.mjs +372 -0
- package/dist/handlerParameters.cjs +6 -11
- package/dist/handlerParameters.mjs +6 -10
- package/dist/handlerReleaseCatalogRoutes.cjs +32 -15
- package/dist/handlerReleaseCatalogRoutes.mjs +32 -15
- package/dist/handlerTypes.d.cts +2 -55
- package/dist/handlerTypes.d.mts +2 -55
- package/dist/handlerVersionRoutes.cjs +20 -4
- package/dist/handlerVersionRoutes.mjs +20 -4
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +8 -9
- package/dist/index.d.mts +8 -9
- package/dist/index.mjs +3 -4
- package/dist/node.cjs +3 -6
- package/dist/node.d.cts +2 -2
- package/dist/node.d.mts +2 -2
- package/dist/node.mjs +4 -4
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/api-keys/index.cjs +9 -0
- package/dist/plugins/api-keys/index.d.cts +1 -0
- package/dist/plugins/api-keys/index.d.mts +1 -0
- package/dist/plugins/api-keys/index.mjs +2 -0
- package/dist/plugins/definePlugin.d.cts +2 -0
- package/dist/plugins/definePlugin.d.mts +2 -0
- package/dist/plugins/insights/index.cjs +9 -0
- package/dist/plugins/insights/index.d.cts +1 -0
- package/dist/plugins/insights/index.d.mts +1 -0
- package/dist/plugins/insights/index.mjs +2 -0
- package/dist/plugins/official.cjs +30 -0
- package/dist/plugins/official.mjs +29 -0
- package/dist/storageAccess.cjs +13 -10
- package/dist/storageAccess.mjs +13 -10
- package/dist/types/index.d.cts +2 -28
- package/dist/types/index.d.mts +2 -28
- package/package.json +26 -14
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/adapters/databaseConstraintErrors.cjs +0 -22
- package/dist/adapters/databaseConstraintErrors.mjs +0 -21
- package/dist/adapters/databasePluginUtils.cjs +0 -116
- package/dist/adapters/databasePluginUtils.mjs +0 -106
- package/dist/adapters/drizzleCrud.cjs +0 -311
- package/dist/adapters/drizzleCrud.mjs +0 -308
- package/dist/adapters/drizzleLazyDB.cjs +0 -106
- package/dist/adapters/drizzleLazyDB.mjs +0 -106
- package/dist/adapters/drizzleQuery.cjs +0 -69
- package/dist/adapters/drizzleQuery.mjs +0 -69
- package/dist/adapters/insightsTransaction.cjs +0 -22
- package/dist/adapters/insightsTransaction.mjs +0 -22
- package/dist/adapters/kyselyCrud.cjs +0 -305
- package/dist/adapters/kyselyCrud.mjs +0 -304
- package/dist/adapters/kyselyQuery.cjs +0 -56
- package/dist/adapters/kyselyQuery.mjs +0 -56
- package/dist/adapters/mongodbCollections.cjs +0 -38
- package/dist/adapters/mongodbCollections.mjs +0 -32
- package/dist/adapters/mongodbQuery.cjs +0 -94
- package/dist/adapters/mongodbQuery.mjs +0 -86
- package/dist/adapters/mongodbReads.cjs +0 -210
- package/dist/adapters/mongodbReads.mjs +0 -210
- package/dist/adapters/mongodbWrites.cjs +0 -148
- package/dist/adapters/mongodbWrites.mjs +0 -148
- package/dist/adapters/prismaQuery.cjs +0 -57
- package/dist/adapters/prismaQuery.mjs +0 -56
- package/dist/adapters/prismaRows.cjs +0 -219
- package/dist/adapters/prismaRows.mjs +0 -209
- package/dist/apiKeys.cjs +0 -143
- package/dist/apiKeys.d.cts +0 -49
- package/dist/apiKeys.d.mts +0 -49
- package/dist/apiKeys.mjs +0 -133
- package/dist/db/createBundleDiff.cjs +0 -144
- package/dist/db/createBundleDiff.d.cts +0 -16
- package/dist/db/createBundleDiff.d.mts +0 -16
- package/dist/db/createBundleDiff.mjs +0 -141
- package/dist/db/databasePluginCore.cjs +0 -137
- package/dist/db/databasePluginCore.mjs +0 -137
- package/dist/db/fixedMigrator.cjs +0 -79
- package/dist/db/fixedMigrator.mjs +0 -78
- package/dist/db/fixedMigratorMongo.cjs +0 -321
- package/dist/db/fixedMigratorMongo.mjs +0 -321
- package/dist/db/fixedMigratorShared.cjs +0 -23
- package/dist/db/fixedMigratorShared.mjs +0 -18
- package/dist/db/index.cjs +0 -27
- package/dist/db/index.d.cts +0 -12
- package/dist/db/index.d.mts +0 -12
- package/dist/db/index.mjs +0 -22
- package/dist/db/mongoMigrationExecution.cjs +0 -11
- package/dist/db/mongoMigrationExecution.mjs +0 -11
- package/dist/db/releaseCatalog.d.cts +0 -16
- package/dist/db/releaseCatalog.d.mts +0 -16
- package/dist/db/schema/insightsCollation.cjs +0 -14
- package/dist/db/schema/insightsCollation.mjs +0 -14
- package/dist/db/schema/mongodb.cjs +0 -25
- package/dist/db/schema/mongodb.mjs +0 -25
- package/dist/db/schema/registry.cjs +0 -21
- package/dist/db/schema/registry.mjs +0 -17
- package/dist/db/schema/sql.cjs +0 -105
- package/dist/db/schema/sql.mjs +0 -97
- package/dist/db/schema/sqlOperations.cjs +0 -27
- package/dist/db/schema/sqlOperations.mjs +0 -26
- package/dist/db/schemaGenerators.cjs +0 -275
- package/dist/db/schemaGenerators.mjs +0 -273
- package/dist/db/schemaReadiness.cjs +0 -26
- package/dist/db/schemaReadiness.d.cts +0 -9
- package/dist/db/schemaReadiness.d.mts +0 -9
- package/dist/db/schemaReadiness.mjs +0 -25
- package/dist/db/sqlMigrationExecution.cjs +0 -67
- package/dist/db/sqlMigrationExecution.mjs +0 -67
- package/dist/db/types.cjs +0 -22
- package/dist/db/types.d.cts +0 -118
- package/dist/db/types.d.mts +0 -118
- package/dist/db/types.mjs +0 -19
- package/dist/handlerBundleRoutes.cjs +0 -155
- package/dist/handlerBundleRoutes.mjs +0 -155
- package/dist/handlerReleaseManagementRoutes.cjs +0 -124
- package/dist/handlerReleaseManagementRoutes.mjs +0 -124
- package/dist/insights/domain.d.cts +0 -89
- package/dist/insights/domain.d.mts +0 -89
- package/dist/insights/errors.cjs +0 -15
- package/dist/insights/errors.mjs +0 -14
- package/dist/insights/eventInput.cjs +0 -155
- package/dist/insights/eventInput.mjs +0 -153
- package/dist/insights/provider.cjs +0 -314
- package/dist/insights/provider.d.cts +0 -6
- package/dist/insights/provider.d.mts +0 -6
- package/dist/insights/provider.mjs +0 -314
- package/dist/insights/queryInput.cjs +0 -93
- package/dist/insights/queryInput.mjs +0 -91
- package/dist/insights/routes.cjs +0 -58
- package/dist/insights/routes.mjs +0 -56
- package/dist/insights/types.d.cts +0 -32
- package/dist/insights/types.d.mts +0 -32
- package/dist/schema/dsl.cjs +0 -103
- package/dist/schema/dsl.mjs +0 -87
- package/dist/schema/index.cjs +0 -20
- package/dist/schema/index.mjs +0 -7
- package/dist/schema/settings.cjs +0 -9
- package/dist/schema/settings.mjs +0 -9
- package/dist/schema/types.cjs +0 -8
- package/dist/schema/types.mjs +0 -6
- package/dist/schema/v1_0_0.cjs +0 -406
- package/dist/schema/v1_0_0.mjs +0 -398
- package/src/adapters/databaseConstraintErrors.ts +0 -25
- package/src/adapters/databasePluginTestDatabase.ts +0 -120
- package/src/adapters/databasePluginUtils.spec.ts +0 -29
- package/src/adapters/databasePluginUtils.ts +0 -214
- package/src/adapters/drizzle.spec.ts +0 -336
- package/src/adapters/drizzle.ts +0 -162
- package/src/adapters/drizzleCrud.ts +0 -571
- package/src/adapters/drizzleLazyDB.ts +0 -271
- package/src/adapters/drizzleQuery.ts +0 -164
- package/src/adapters/insightsTransaction.ts +0 -32
- package/src/adapters/kysely.spec.ts +0 -174
- package/src/adapters/kysely.ts +0 -110
- package/src/adapters/kyselyCrud.ts +0 -709
- package/src/adapters/kyselyQuery.ts +0 -128
- package/src/adapters/mongodb.integration.spec.ts +0 -210
- package/src/adapters/mongodb.spec.ts +0 -209
- package/src/adapters/mongodb.ts +0 -138
- package/src/adapters/mongodbCollections.ts +0 -67
- package/src/adapters/mongodbQuery.ts +0 -255
- package/src/adapters/mongodbReads.ts +0 -380
- package/src/adapters/mongodbRows.spec.ts +0 -64
- package/src/adapters/mongodbRows.ts +0 -118
- package/src/adapters/mongodbTestClient.ts +0 -377
- package/src/adapters/mongodbTestFilter.ts +0 -169
- package/src/adapters/mongodbWrites.ts +0 -287
- package/src/adapters/prisma.spec.ts +0 -293
- package/src/adapters/prisma.ts +0 -565
- package/src/adapters/prismaQuery.ts +0 -129
- package/src/adapters/prismaRows.spec.ts +0 -98
- package/src/adapters/prismaRows.ts +0 -337
- package/src/adapters/prismaTestClient.ts +0 -413
- package/src/apiKeys.integration.spec.ts +0 -192
- package/src/apiKeys.spec.ts +0 -162
- package/src/apiKeys.ts +0 -220
- package/src/calculatePagination.ts +0 -34
- package/src/createHotUpdaterCore.ts +0 -246
- package/src/db/bundleRows.spec.ts +0 -164
- package/src/db/bundleRows.ts +0 -10
- package/src/db/createBundleDiff.spec.ts +0 -450
- package/src/db/createBundleDiff.ts +0 -364
- package/src/db/databasePluginCore.spec.ts +0 -62
- package/src/db/databasePluginCore.testFixtures.ts +0 -76
- package/src/db/databasePluginCore.ts +0 -185
- package/src/db/databasePluginUpdateCheck.bench.ts +0 -110
- package/src/db/fixedMigrator.spec.ts +0 -296
- package/src/db/fixedMigrator.ts +0 -147
- package/src/db/fixedMigratorMongo.spec.ts +0 -239
- package/src/db/fixedMigratorMongo.ts +0 -425
- package/src/db/fixedMigratorShared.ts +0 -36
- package/src/db/hotUpdaterSchema.ts +0 -5
- package/src/db/index.spec.ts +0 -1269
- package/src/db/index.ts +0 -47
- package/src/db/mongoMigrationExecution.ts +0 -23
- package/src/db/node-sqlite.d.ts +0 -25
- package/src/db/releaseCatalog.ts +0 -148
- package/src/db/schema/definitions.ts +0 -1
- package/src/db/schema/insightsCollation.ts +0 -21
- package/src/db/schema/mongodb.ts +0 -40
- package/src/db/schema/registry.ts +0 -55
- package/src/db/schema/sql.ts +0 -244
- package/src/db/schema/sqlOperations.ts +0 -63
- package/src/db/schema/types.ts +0 -1
- package/src/db/schemaGenerators.ts +0 -494
- package/src/db/schemaReadiness.ts +0 -34
- package/src/db/sqlMigrationExecution.spec.ts +0 -65
- package/src/db/sqlMigrationExecution.ts +0 -108
- package/src/db/types.spec.ts +0 -63
- package/src/db/types.ts +0 -228
- package/src/db/updateArtifacts.spec.ts +0 -359
- package/src/db/updateArtifacts.ts +0 -541
- package/src/handler-standalone.integration.spec.ts +0 -528
- package/src/handler.spec.ts +0 -190
- package/src/handler.testFixtures.ts +0 -30
- package/src/handler.ts +0 -245
- package/src/handlerAuth.integration.spec.ts +0 -33
- package/src/handlerBundleRoutes.ts +0 -259
- package/src/handlerErrors.ts +0 -7
- package/src/handlerManagement.spec.ts +0 -262
- package/src/handlerParameters.ts +0 -105
- package/src/handlerReleaseCatalogRoutes.ts +0 -154
- package/src/handlerReleaseManagementRoutes.ts +0 -213
- package/src/handlerTypes.ts +0 -96
- package/src/handlerVersionRoutes.ts +0 -12
- package/src/index.ts +0 -30
- package/src/insights/domain.ts +0 -103
- package/src/insights/errors.ts +0 -11
- package/src/insights/eventInput.ts +0 -225
- package/src/insights/insights.integration.spec.ts +0 -381
- package/src/insights/provider.spec.ts +0 -385
- package/src/insights/provider.ts +0 -591
- package/src/insights/queryInput.ts +0 -141
- package/src/insights/routes.ts +0 -104
- package/src/insights/types.ts +0 -55
- package/src/internalRouter.ts +0 -104
- package/src/node.spec.ts +0 -119
- package/src/node.ts +0 -111
- package/src/releaseCatalogRoutes.integration.spec.ts +0 -238
- package/src/runtime.spec.ts +0 -194
- package/src/runtime.testFixtures.ts +0 -71
- package/src/schema/dsl-all-versions.spec.ts +0 -37
- package/src/schema/dsl.ts +0 -187
- package/src/schema/index.ts +0 -10
- package/src/schema/settings.ts +0 -15
- package/src/schema/types.ts +0 -79
- package/src/schema/v1_0_0.spec.ts +0 -220
- package/src/schema/v1_0_0.ts +0 -529
- package/src/storageAccess.spec.ts +0 -152
- package/src/storageAccess.ts +0 -141
- package/src/types/index.ts +0 -34
- package/src/version.ts +0 -3
|
@@ -1,571 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DatabasePluginInputError,
|
|
3
|
-
type InsightsRecordInput,
|
|
4
|
-
} from "@hot-updater/plugin-core";
|
|
5
|
-
import type {
|
|
6
|
-
DatabasePluginImplementation,
|
|
7
|
-
TransactionDatabasePluginImplementation,
|
|
8
|
-
} from "@hot-updater/plugin-core/internal";
|
|
9
|
-
import { and, asc, desc, eq, lt, or, sql, type SQLWrapper } from "drizzle-orm";
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
isChannelDeleteReferencedError,
|
|
13
|
-
translateChannelDeleteError,
|
|
14
|
-
} from "./databaseConstraintErrors";
|
|
15
|
-
import {
|
|
16
|
-
fromStoredBundleRow,
|
|
17
|
-
fromStoredReleaseCatalogRow,
|
|
18
|
-
fromStoredReleaseRow,
|
|
19
|
-
toStoredBundleRow,
|
|
20
|
-
toStoredBundleUpdate,
|
|
21
|
-
toStoredReleaseRow,
|
|
22
|
-
toStoredReleaseUpdate,
|
|
23
|
-
} from "./databasePluginUtils";
|
|
24
|
-
import type { DrizzleProvider } from "./drizzle";
|
|
25
|
-
import type { DrizzleDB, DrizzleTable } from "./drizzleLazyDB";
|
|
26
|
-
import { buildDrizzleWhere } from "./drizzleQuery";
|
|
27
|
-
|
|
28
|
-
class MissingDrizzleTableError extends Error {
|
|
29
|
-
readonly name = "MissingDrizzleTableError";
|
|
30
|
-
|
|
31
|
-
constructor(readonly table: string) {
|
|
32
|
-
super(`Drizzle schema is missing table "${table}".`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
class DrizzleAdapterInvariantError extends Error {
|
|
37
|
-
readonly name = "DrizzleAdapterInvariantError";
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const getDrizzleTable = (db: DrizzleDB, name: string): DrizzleTable => {
|
|
41
|
-
const table = db._.fullSchema[name];
|
|
42
|
-
if (table === undefined) throw new MissingDrizzleTableError(name);
|
|
43
|
-
return table;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const isSQLWrapper = (value: unknown): value is SQLWrapper =>
|
|
47
|
-
typeof value === "object" &&
|
|
48
|
-
value !== null &&
|
|
49
|
-
"getSQL" in value &&
|
|
50
|
-
typeof value.getSQL === "function";
|
|
51
|
-
|
|
52
|
-
export const getDrizzleColumn = (
|
|
53
|
-
table: DrizzleTable,
|
|
54
|
-
name: string,
|
|
55
|
-
): SQLWrapper => {
|
|
56
|
-
const value = table[name];
|
|
57
|
-
if (!isSQLWrapper(value)) {
|
|
58
|
-
throw new MissingDrizzleTableError(`${name} column`);
|
|
59
|
-
}
|
|
60
|
-
return value;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const executeInsert = async (
|
|
64
|
-
db: DrizzleDB,
|
|
65
|
-
provider: DrizzleProvider,
|
|
66
|
-
table: DrizzleTable,
|
|
67
|
-
data: unknown,
|
|
68
|
-
onConflict: "ignore" | undefined,
|
|
69
|
-
): Promise<void> => {
|
|
70
|
-
const builder = db.insert(table);
|
|
71
|
-
const insert = builder.values(data);
|
|
72
|
-
if (onConflict === undefined) {
|
|
73
|
-
await insert.execute();
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const ignored =
|
|
77
|
-
provider === "mysql"
|
|
78
|
-
? builder.ignore?.().values(data)
|
|
79
|
-
: insert.onConflictDoNothing?.();
|
|
80
|
-
if (ignored === undefined) throw new DrizzleAdapterInvariantError();
|
|
81
|
-
await ignored.execute();
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export const recordDrizzleInsights = (
|
|
85
|
-
db: DrizzleDB,
|
|
86
|
-
provider: DrizzleProvider,
|
|
87
|
-
input: InsightsRecordInput,
|
|
88
|
-
): void | Promise<void> => {
|
|
89
|
-
if (db.resultKind !== "sync")
|
|
90
|
-
return recordAsyncDrizzleInsights(db, provider, input);
|
|
91
|
-
const events = getDrizzleTable(db, "bundle_events");
|
|
92
|
-
const installations = getDrizzleTable(db, "bundle_installations");
|
|
93
|
-
const eventInsert = db
|
|
94
|
-
.insert(events)
|
|
95
|
-
.values(input.event)
|
|
96
|
-
.onConflictDoNothing?.()
|
|
97
|
-
.returning?.({ id: getDrizzleColumn(events, "id") });
|
|
98
|
-
const installationInsert = db
|
|
99
|
-
.insert(installations)
|
|
100
|
-
.values(input.installation)
|
|
101
|
-
.onConflictDoNothing?.();
|
|
102
|
-
const installationUpdate = db
|
|
103
|
-
.update(installations)
|
|
104
|
-
.set(input.installation)
|
|
105
|
-
.where(newerInstallationWhere(installations, input.installation));
|
|
106
|
-
if (
|
|
107
|
-
eventInsert?.all === undefined ||
|
|
108
|
-
installationInsert?.run === undefined ||
|
|
109
|
-
installationUpdate.run === undefined
|
|
110
|
-
)
|
|
111
|
-
throw new DrizzleAdapterInvariantError();
|
|
112
|
-
if (eventInsert.all().length === 0) return;
|
|
113
|
-
installationInsert.run();
|
|
114
|
-
installationUpdate.run();
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const newerInstallationWhere = (
|
|
118
|
-
installations: DrizzleTable,
|
|
119
|
-
installation: InsightsRecordInput["installation"],
|
|
120
|
-
) => {
|
|
121
|
-
const receivedAt = getDrizzleColumn(installations, "received_at_ms");
|
|
122
|
-
return and(
|
|
123
|
-
eq(getDrizzleColumn(installations, "install_id"), installation.install_id),
|
|
124
|
-
or(
|
|
125
|
-
lt(receivedAt, installation.received_at_ms),
|
|
126
|
-
and(
|
|
127
|
-
eq(receivedAt, installation.received_at_ms),
|
|
128
|
-
lt(getDrizzleColumn(installations, "id"), installation.id),
|
|
129
|
-
),
|
|
130
|
-
),
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const recordAsyncDrizzleInsights = async (
|
|
135
|
-
db: DrizzleDB,
|
|
136
|
-
provider: DrizzleProvider,
|
|
137
|
-
{ event, installation }: InsightsRecordInput,
|
|
138
|
-
): Promise<void> => {
|
|
139
|
-
const events = getDrizzleTable(db, "bundle_events");
|
|
140
|
-
const installations = getDrizzleTable(db, "bundle_installations");
|
|
141
|
-
if (provider === "mysql") {
|
|
142
|
-
const existing = await db.query.bundle_events.findFirst({
|
|
143
|
-
where: eq(getDrizzleColumn(events, "id"), event.id),
|
|
144
|
-
});
|
|
145
|
-
if (existing !== undefined) return;
|
|
146
|
-
await db.insert(events).values(event).execute();
|
|
147
|
-
const insertInstallation = db
|
|
148
|
-
.insert(installations)
|
|
149
|
-
.values(installation)
|
|
150
|
-
.onDuplicateKeyUpdate?.({ set: { install_id: installation.install_id } });
|
|
151
|
-
if (insertInstallation === undefined)
|
|
152
|
-
throw new DrizzleAdapterInvariantError();
|
|
153
|
-
await insertInstallation.execute();
|
|
154
|
-
} else {
|
|
155
|
-
const insert = db.insert(events).values(event).onConflictDoNothing?.();
|
|
156
|
-
const returning = insert?.returning?.({
|
|
157
|
-
id: getDrizzleColumn(events, "id"),
|
|
158
|
-
});
|
|
159
|
-
if (returning === undefined) throw new DrizzleAdapterInvariantError();
|
|
160
|
-
const rows = await returning.execute();
|
|
161
|
-
if (!Array.isArray(rows)) throw new DrizzleAdapterInvariantError();
|
|
162
|
-
if (rows.length === 0) return;
|
|
163
|
-
await executeInsert(db, provider, installations, installation, "ignore");
|
|
164
|
-
}
|
|
165
|
-
await db
|
|
166
|
-
.update(installations)
|
|
167
|
-
.set(installation)
|
|
168
|
-
.where(newerInstallationWhere(installations, installation))
|
|
169
|
-
.execute();
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const toOrderBy = (
|
|
173
|
-
table: DrizzleTable,
|
|
174
|
-
input: {
|
|
175
|
-
model?: string;
|
|
176
|
-
orderBy?: readonly {
|
|
177
|
-
field: string;
|
|
178
|
-
direction: "asc" | "desc";
|
|
179
|
-
nulls?: "first" | "last";
|
|
180
|
-
}[];
|
|
181
|
-
},
|
|
182
|
-
) => {
|
|
183
|
-
const clauses = input.orderBy;
|
|
184
|
-
return clauses?.flatMap((clause) => {
|
|
185
|
-
const column = getDrizzleColumn(table, clause.field);
|
|
186
|
-
if (
|
|
187
|
-
input.model === "bundle_events" ||
|
|
188
|
-
input.model === "bundle_installations"
|
|
189
|
-
) {
|
|
190
|
-
return [clause.direction === "asc" ? asc(column) : desc(column)];
|
|
191
|
-
}
|
|
192
|
-
const nulls =
|
|
193
|
-
clause.nulls ?? (clause.direction === "asc" ? "last" : "first");
|
|
194
|
-
return [
|
|
195
|
-
nulls === "first"
|
|
196
|
-
? sql`${column} is null desc`
|
|
197
|
-
: sql`${column} is null asc`,
|
|
198
|
-
clause.direction === "asc" ? asc(column) : desc(column),
|
|
199
|
-
];
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
export const createDrizzleCrud = (
|
|
204
|
-
db: DrizzleDB,
|
|
205
|
-
provider: DrizzleProvider,
|
|
206
|
-
): TransactionDatabasePluginImplementation &
|
|
207
|
-
Pick<DatabasePluginImplementation, "deleteChannel" | "insertChannel"> => {
|
|
208
|
-
const bundles = getDrizzleTable(db, "bundles");
|
|
209
|
-
const patches = getDrizzleTable(db, "bundle_patches");
|
|
210
|
-
const events = getDrizzleTable(db, "bundle_events");
|
|
211
|
-
const installations = getDrizzleTable(db, "bundle_installations");
|
|
212
|
-
const releases = getDrizzleTable(db, "releases");
|
|
213
|
-
const releaseCatalogs = getDrizzleTable(db, "release_catalogs");
|
|
214
|
-
const channels = getDrizzleTable(db, "channels");
|
|
215
|
-
const apiKeys = getDrizzleTable(db, "api_keys");
|
|
216
|
-
return {
|
|
217
|
-
async deleteChannel({ id }) {
|
|
218
|
-
const idPredicate = eq(getDrizzleColumn(channels, "id"), id);
|
|
219
|
-
const existing = await db.query.channels.findFirst({
|
|
220
|
-
where: idPredicate,
|
|
221
|
-
});
|
|
222
|
-
if (existing === undefined) {
|
|
223
|
-
return { deleted: false, reason: "not_found" };
|
|
224
|
-
}
|
|
225
|
-
const referencedReleases = await db.$count(
|
|
226
|
-
releases,
|
|
227
|
-
eq(getDrizzleColumn(releases, "channel_id"), id),
|
|
228
|
-
);
|
|
229
|
-
if (referencedReleases > 0) {
|
|
230
|
-
return { deleted: false, reason: "not_empty" };
|
|
231
|
-
}
|
|
232
|
-
try {
|
|
233
|
-
await db.delete(channels).where(idPredicate).execute();
|
|
234
|
-
} catch (error) {
|
|
235
|
-
if (isChannelDeleteReferencedError(error)) {
|
|
236
|
-
return { deleted: false, reason: "not_empty" };
|
|
237
|
-
}
|
|
238
|
-
throw error;
|
|
239
|
-
}
|
|
240
|
-
return { deleted: true };
|
|
241
|
-
},
|
|
242
|
-
async insertChannel(input) {
|
|
243
|
-
const before = await db.query.channels.findFirst({
|
|
244
|
-
where: eq(getDrizzleColumn(channels, "name"), input.row.name),
|
|
245
|
-
});
|
|
246
|
-
if (before !== undefined) return { row: before, inserted: false };
|
|
247
|
-
await executeInsert(db, provider, channels, input.row, "ignore");
|
|
248
|
-
const row = await db.query.channels.findFirst({
|
|
249
|
-
where: eq(getDrizzleColumn(channels, "name"), input.row.name),
|
|
250
|
-
});
|
|
251
|
-
if (row === undefined) throw new DrizzleAdapterInvariantError();
|
|
252
|
-
return { row, inserted: row.id === input.row.id };
|
|
253
|
-
},
|
|
254
|
-
async create(input) {
|
|
255
|
-
switch (input.model) {
|
|
256
|
-
case "bundles":
|
|
257
|
-
await executeInsert(
|
|
258
|
-
db,
|
|
259
|
-
provider,
|
|
260
|
-
bundles,
|
|
261
|
-
toStoredBundleRow(input.data, provider),
|
|
262
|
-
undefined,
|
|
263
|
-
);
|
|
264
|
-
return input.data;
|
|
265
|
-
case "bundle_patches":
|
|
266
|
-
await executeInsert(db, provider, patches, input.data, undefined);
|
|
267
|
-
return input.data;
|
|
268
|
-
case "bundle_events":
|
|
269
|
-
await executeInsert(db, provider, events, input.data, undefined);
|
|
270
|
-
return input.data;
|
|
271
|
-
case "bundle_installations":
|
|
272
|
-
await executeInsert(
|
|
273
|
-
db,
|
|
274
|
-
provider,
|
|
275
|
-
installations,
|
|
276
|
-
input.data,
|
|
277
|
-
input.onConflict,
|
|
278
|
-
);
|
|
279
|
-
return input.data;
|
|
280
|
-
case "releases":
|
|
281
|
-
await executeInsert(
|
|
282
|
-
db,
|
|
283
|
-
provider,
|
|
284
|
-
releases,
|
|
285
|
-
toStoredReleaseRow(input.data, provider),
|
|
286
|
-
undefined,
|
|
287
|
-
);
|
|
288
|
-
return input.data;
|
|
289
|
-
case "release_catalogs":
|
|
290
|
-
await executeInsert(
|
|
291
|
-
db,
|
|
292
|
-
provider,
|
|
293
|
-
releaseCatalogs,
|
|
294
|
-
input.data,
|
|
295
|
-
undefined,
|
|
296
|
-
);
|
|
297
|
-
return input.data;
|
|
298
|
-
case "api_keys":
|
|
299
|
-
await executeInsert(
|
|
300
|
-
db,
|
|
301
|
-
provider,
|
|
302
|
-
apiKeys,
|
|
303
|
-
input.data,
|
|
304
|
-
input.onConflict,
|
|
305
|
-
);
|
|
306
|
-
return input.data;
|
|
307
|
-
case "channels":
|
|
308
|
-
await executeInsert(
|
|
309
|
-
db,
|
|
310
|
-
provider,
|
|
311
|
-
channels,
|
|
312
|
-
input.data,
|
|
313
|
-
input.onConflict,
|
|
314
|
-
);
|
|
315
|
-
return input.data;
|
|
316
|
-
}
|
|
317
|
-
},
|
|
318
|
-
async update(input) {
|
|
319
|
-
if (input.model === "bundle_installations") {
|
|
320
|
-
const installId = input.where.find(
|
|
321
|
-
(item) =>
|
|
322
|
-
item.field === "install_id" &&
|
|
323
|
-
(item.operator === undefined || item.operator === "eq") &&
|
|
324
|
-
typeof item.value === "string",
|
|
325
|
-
)?.value;
|
|
326
|
-
if (typeof installId !== "string") {
|
|
327
|
-
throw new DrizzleAdapterInvariantError();
|
|
328
|
-
}
|
|
329
|
-
const where = buildDrizzleWhere(provider, installations, input.where);
|
|
330
|
-
if (where === undefined) throw new DrizzleAdapterInvariantError();
|
|
331
|
-
await db.update(installations).set(input.update).where(where).execute();
|
|
332
|
-
const row = await db.query.bundle_installations.findFirst({
|
|
333
|
-
where: eq(getDrizzleColumn(installations, "install_id"), installId),
|
|
334
|
-
});
|
|
335
|
-
return row?.id === input.update.id &&
|
|
336
|
-
row.received_at_ms === input.update.received_at_ms
|
|
337
|
-
? row
|
|
338
|
-
: null;
|
|
339
|
-
}
|
|
340
|
-
const selector = input.where[0];
|
|
341
|
-
if (selector === undefined || typeof selector.value !== "string") {
|
|
342
|
-
throw new DrizzleAdapterInvariantError();
|
|
343
|
-
}
|
|
344
|
-
if (input.model === "api_keys") {
|
|
345
|
-
const idPredicate = eq(getDrizzleColumn(apiKeys, "id"), selector.value);
|
|
346
|
-
await db.update(apiKeys).set(input.update).where(idPredicate).execute();
|
|
347
|
-
return (
|
|
348
|
-
(await db.query.api_keys.findFirst({
|
|
349
|
-
where: idPredicate,
|
|
350
|
-
})) ?? null
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
if (input.model === "releases") {
|
|
354
|
-
const idPredicate = eq(
|
|
355
|
-
getDrizzleColumn(releases, "id"),
|
|
356
|
-
selector.value,
|
|
357
|
-
);
|
|
358
|
-
await db
|
|
359
|
-
.update(releases)
|
|
360
|
-
.set(toStoredReleaseUpdate(input.update, provider))
|
|
361
|
-
.where(idPredicate)
|
|
362
|
-
.execute();
|
|
363
|
-
const row = await db.query.releases.findFirst({ where: idPredicate });
|
|
364
|
-
return row === undefined ? null : fromStoredReleaseRow(row);
|
|
365
|
-
}
|
|
366
|
-
if (input.model === "release_catalogs") {
|
|
367
|
-
const scopePredicate = eq(
|
|
368
|
-
getDrizzleColumn(releaseCatalogs, "scope_key"),
|
|
369
|
-
selector.value,
|
|
370
|
-
);
|
|
371
|
-
await db
|
|
372
|
-
.update(releaseCatalogs)
|
|
373
|
-
.set(input.update)
|
|
374
|
-
.where(scopePredicate)
|
|
375
|
-
.execute();
|
|
376
|
-
const row = await db.query.release_catalogs.findFirst({
|
|
377
|
-
where: scopePredicate,
|
|
378
|
-
});
|
|
379
|
-
return row === undefined ? null : fromStoredReleaseCatalogRow(row);
|
|
380
|
-
}
|
|
381
|
-
const idPredicate = eq(getDrizzleColumn(bundles, "id"), selector.value);
|
|
382
|
-
await db
|
|
383
|
-
.update(bundles)
|
|
384
|
-
.set(toStoredBundleUpdate(input.update, provider))
|
|
385
|
-
.where(idPredicate)
|
|
386
|
-
.execute();
|
|
387
|
-
const stored = await db.query.bundles.findFirst({ where: idPredicate });
|
|
388
|
-
if (stored === undefined) return null;
|
|
389
|
-
return fromStoredBundleRow(stored);
|
|
390
|
-
},
|
|
391
|
-
async delete(input) {
|
|
392
|
-
switch (input.model) {
|
|
393
|
-
case "bundles": {
|
|
394
|
-
const where = buildDrizzleWhere(provider, bundles, input.where);
|
|
395
|
-
if (where === undefined) throw new DrizzleAdapterInvariantError();
|
|
396
|
-
await db.delete(bundles).where(where).execute();
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
case "bundle_patches": {
|
|
400
|
-
const where = buildDrizzleWhere(provider, patches, input.where);
|
|
401
|
-
if (where === undefined) throw new DrizzleAdapterInvariantError();
|
|
402
|
-
await db.delete(patches).where(where).execute();
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
case "releases": {
|
|
406
|
-
const where = buildDrizzleWhere(provider, releases, input.where);
|
|
407
|
-
if (where === undefined) throw new DrizzleAdapterInvariantError();
|
|
408
|
-
await db.delete(releases).where(where).execute();
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
case "channels": {
|
|
412
|
-
const where = buildDrizzleWhere(provider, channels, input.where);
|
|
413
|
-
if (where === undefined) throw new DrizzleAdapterInvariantError();
|
|
414
|
-
try {
|
|
415
|
-
await db.delete(channels).where(where).execute();
|
|
416
|
-
} catch (error) {
|
|
417
|
-
translateChannelDeleteError(error);
|
|
418
|
-
}
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
},
|
|
423
|
-
async count(input) {
|
|
424
|
-
if (input.distinct !== undefined) {
|
|
425
|
-
throw new DatabasePluginInputError("invalid-operation");
|
|
426
|
-
}
|
|
427
|
-
switch (input.model) {
|
|
428
|
-
case "bundle_events":
|
|
429
|
-
return db.$count(
|
|
430
|
-
events,
|
|
431
|
-
buildDrizzleWhere(provider, events, input.where),
|
|
432
|
-
);
|
|
433
|
-
case "bundles":
|
|
434
|
-
return db.$count(
|
|
435
|
-
bundles,
|
|
436
|
-
buildDrizzleWhere(provider, bundles, input.where),
|
|
437
|
-
);
|
|
438
|
-
case "bundle_patches":
|
|
439
|
-
return db.$count(
|
|
440
|
-
patches,
|
|
441
|
-
buildDrizzleWhere(provider, patches, input.where),
|
|
442
|
-
);
|
|
443
|
-
case "releases":
|
|
444
|
-
return db.$count(
|
|
445
|
-
releases,
|
|
446
|
-
buildDrizzleWhere(provider, releases, input.where),
|
|
447
|
-
);
|
|
448
|
-
case "bundle_installations":
|
|
449
|
-
return db.$count(
|
|
450
|
-
installations,
|
|
451
|
-
buildDrizzleWhere(provider, installations, input.where),
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
},
|
|
455
|
-
async findOne(input) {
|
|
456
|
-
switch (input.model) {
|
|
457
|
-
case "bundles": {
|
|
458
|
-
const row = await db.query.bundles.findFirst({
|
|
459
|
-
where: buildDrizzleWhere(provider, bundles, input.where),
|
|
460
|
-
});
|
|
461
|
-
return row === undefined ? null : fromStoredBundleRow(row);
|
|
462
|
-
}
|
|
463
|
-
case "bundle_patches":
|
|
464
|
-
return (
|
|
465
|
-
(await db.query.bundle_patches.findFirst({
|
|
466
|
-
where: buildDrizzleWhere(provider, patches, input.where),
|
|
467
|
-
})) ?? null
|
|
468
|
-
);
|
|
469
|
-
case "api_keys":
|
|
470
|
-
return (
|
|
471
|
-
(await db.query.api_keys.findFirst({
|
|
472
|
-
where: buildDrizzleWhere(provider, apiKeys, input.where),
|
|
473
|
-
})) ?? null
|
|
474
|
-
);
|
|
475
|
-
case "channels":
|
|
476
|
-
return (
|
|
477
|
-
(await db.query.channels.findFirst({
|
|
478
|
-
where: buildDrizzleWhere(provider, channels, input.where),
|
|
479
|
-
})) ?? null
|
|
480
|
-
);
|
|
481
|
-
case "releases": {
|
|
482
|
-
const row = await db.query.releases.findFirst({
|
|
483
|
-
where: buildDrizzleWhere(provider, releases, input.where),
|
|
484
|
-
});
|
|
485
|
-
return row === undefined ? null : fromStoredReleaseRow(row);
|
|
486
|
-
}
|
|
487
|
-
case "release_catalogs": {
|
|
488
|
-
const row = await db.query.release_catalogs.findFirst({
|
|
489
|
-
where: buildDrizzleWhere(provider, releaseCatalogs, input.where),
|
|
490
|
-
});
|
|
491
|
-
return row === undefined ? null : fromStoredReleaseCatalogRow(row);
|
|
492
|
-
}
|
|
493
|
-
case "bundle_installations":
|
|
494
|
-
return (
|
|
495
|
-
(await db.query.bundle_installations.findFirst({
|
|
496
|
-
where: buildDrizzleWhere(provider, installations, input.where),
|
|
497
|
-
})) ?? null
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
},
|
|
501
|
-
async findMany(input) {
|
|
502
|
-
if (input.distinctOn !== undefined) {
|
|
503
|
-
throw new DatabasePluginInputError("invalid-operation");
|
|
504
|
-
}
|
|
505
|
-
switch (input.model) {
|
|
506
|
-
case "bundles": {
|
|
507
|
-
const rows = await db.query.bundles.findMany({
|
|
508
|
-
where: buildDrizzleWhere(provider, bundles, input.where),
|
|
509
|
-
orderBy: toOrderBy(bundles, input),
|
|
510
|
-
limit: input.limit,
|
|
511
|
-
offset: input.offset,
|
|
512
|
-
});
|
|
513
|
-
return rows.map(fromStoredBundleRow);
|
|
514
|
-
}
|
|
515
|
-
case "bundle_events":
|
|
516
|
-
return db.query.bundle_events.findMany({
|
|
517
|
-
where: buildDrizzleWhere(provider, events, input.where),
|
|
518
|
-
orderBy: toOrderBy(events, input),
|
|
519
|
-
limit: input.limit,
|
|
520
|
-
offset: input.offset,
|
|
521
|
-
});
|
|
522
|
-
case "bundle_installations":
|
|
523
|
-
return db.query.bundle_installations.findMany({
|
|
524
|
-
where: buildDrizzleWhere(provider, installations, input.where),
|
|
525
|
-
orderBy: toOrderBy(installations, input),
|
|
526
|
-
limit: input.limit,
|
|
527
|
-
offset: input.offset,
|
|
528
|
-
});
|
|
529
|
-
case "api_keys":
|
|
530
|
-
return db.query.api_keys.findMany({
|
|
531
|
-
where: buildDrizzleWhere(provider, apiKeys, input.where),
|
|
532
|
-
orderBy: toOrderBy(apiKeys, input),
|
|
533
|
-
limit: input.limit,
|
|
534
|
-
offset: input.offset,
|
|
535
|
-
});
|
|
536
|
-
case "bundle_patches":
|
|
537
|
-
return db.query.bundle_patches.findMany({
|
|
538
|
-
where: buildDrizzleWhere(provider, patches, input.where),
|
|
539
|
-
orderBy: toOrderBy(patches, input),
|
|
540
|
-
limit: input.limit,
|
|
541
|
-
offset: input.offset,
|
|
542
|
-
});
|
|
543
|
-
case "channels":
|
|
544
|
-
return db.query.channels.findMany({
|
|
545
|
-
where: buildDrizzleWhere(provider, channels, input.where),
|
|
546
|
-
orderBy: toOrderBy(channels, input),
|
|
547
|
-
limit: input.limit,
|
|
548
|
-
offset: input.offset,
|
|
549
|
-
});
|
|
550
|
-
case "releases": {
|
|
551
|
-
const rows = await db.query.releases.findMany({
|
|
552
|
-
where: buildDrizzleWhere(provider, releases, input.where),
|
|
553
|
-
orderBy: toOrderBy(releases, input),
|
|
554
|
-
limit: input.limit,
|
|
555
|
-
offset: input.offset,
|
|
556
|
-
});
|
|
557
|
-
return rows.map(fromStoredReleaseRow);
|
|
558
|
-
}
|
|
559
|
-
case "release_catalogs": {
|
|
560
|
-
const rows = await db.query.release_catalogs.findMany({
|
|
561
|
-
where: buildDrizzleWhere(provider, releaseCatalogs, input.where),
|
|
562
|
-
orderBy: toOrderBy(releaseCatalogs, input),
|
|
563
|
-
limit: input.limit,
|
|
564
|
-
offset: input.offset,
|
|
565
|
-
});
|
|
566
|
-
return rows.map(fromStoredReleaseCatalogRow);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
},
|
|
570
|
-
};
|
|
571
|
-
};
|