@hot-updater/server 0.36.6 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/databaseConstraintErrors.cjs +23 -0
- package/dist/adapters/databaseConstraintErrors.mjs +21 -0
- package/dist/adapters/databasePluginUtils.cjs +117 -0
- package/dist/adapters/databasePluginUtils.mjs +106 -0
- package/dist/adapters/drizzle.cjs +53 -176
- package/dist/adapters/drizzle.d.cts +6 -4
- package/dist/adapters/drizzle.d.mts +6 -4
- package/dist/adapters/drizzle.mjs +54 -177
- package/dist/adapters/drizzleCrud.cjs +250 -0
- package/dist/adapters/drizzleCrud.mjs +249 -0
- package/dist/adapters/drizzleLazyDB.cjs +84 -36
- package/dist/adapters/drizzleLazyDB.mjs +84 -36
- package/dist/adapters/drizzleQuery.cjs +68 -0
- package/dist/adapters/drizzleQuery.mjs +67 -0
- package/dist/adapters/kysely.cjs +18 -138
- package/dist/adapters/kysely.d.cts +3 -12
- package/dist/adapters/kysely.d.mts +3 -12
- package/dist/adapters/kysely.mjs +19 -139
- package/dist/adapters/kyselyCrud.cjs +254 -0
- package/dist/adapters/kyselyCrud.mjs +253 -0
- package/dist/adapters/kyselyQuery.cjs +56 -0
- package/dist/adapters/kyselyQuery.mjs +55 -0
- package/dist/adapters/mongodb.cjs +21 -174
- package/dist/adapters/mongodb.d.cts +3 -2
- package/dist/adapters/mongodb.d.mts +3 -2
- package/dist/adapters/mongodb.mjs +21 -174
- package/dist/adapters/mongodbCollections.cjs +36 -0
- package/dist/adapters/mongodbCollections.mjs +30 -0
- package/dist/adapters/mongodbQuery.cjs +77 -0
- package/dist/adapters/mongodbQuery.mjs +70 -0
- package/dist/adapters/mongodbReads.cjs +148 -0
- package/dist/adapters/mongodbReads.mjs +147 -0
- package/dist/adapters/mongodbWrites.cjs +134 -0
- package/dist/adapters/mongodbWrites.mjs +133 -0
- package/dist/adapters/prisma.cjs +205 -180
- package/dist/adapters/prisma.d.cts +3 -3
- package/dist/adapters/prisma.d.mts +3 -3
- package/dist/adapters/prisma.mjs +206 -181
- package/dist/adapters/prismaQuery.cjs +58 -0
- package/dist/adapters/prismaQuery.mjs +56 -0
- package/dist/adapters/prismaRows.cjs +198 -0
- package/dist/adapters/prismaRows.mjs +188 -0
- package/dist/analytics/bounded/activeOverview.cjs +87 -0
- package/dist/analytics/bounded/activeOverview.mjs +85 -0
- package/dist/analytics/bounded/installationSearch.cjs +42 -0
- package/dist/analytics/bounded/installationSearch.mjs +42 -0
- package/dist/analytics/bounded/persistence.cjs +39 -0
- package/dist/analytics/bounded/persistence.mjs +38 -0
- package/dist/analytics/bounded/provider.cjs +170 -0
- package/dist/analytics/bounded/provider.d.cts +7 -0
- package/dist/analytics/bounded/provider.d.mts +7 -0
- package/dist/analytics/bounded/provider.mjs +170 -0
- package/dist/analytics/bounded/scan.cjs +144 -0
- package/dist/analytics/bounded/scan.mjs +138 -0
- package/dist/analytics/domain.d.cts +121 -0
- package/dist/analytics/domain.d.mts +121 -0
- package/dist/analytics/errors.cjs +22 -0
- package/dist/analytics/errors.mjs +20 -0
- package/dist/analytics/eventInput.cjs +111 -0
- package/dist/analytics/eventInput.mjs +111 -0
- package/dist/analytics/persistence.d.cts +6 -0
- package/dist/analytics/persistence.d.mts +6 -0
- package/dist/analytics/queryInput.cjs +58 -0
- package/dist/analytics/queryInput.mjs +55 -0
- package/dist/analytics/routes.cjs +63 -0
- package/dist/analytics/routes.mjs +61 -0
- package/dist/analytics/types.d.cts +17 -0
- package/dist/analytics/types.d.mts +17 -0
- package/dist/apiKeys.cjs +139 -0
- package/dist/apiKeys.d.cts +50 -0
- package/dist/apiKeys.d.mts +50 -0
- package/dist/apiKeys.mjs +133 -0
- package/dist/createHotUpdaterCore.cjs +48 -26
- package/dist/createHotUpdaterCore.d.cts +49 -17
- package/dist/createHotUpdaterCore.d.mts +49 -17
- package/dist/createHotUpdaterCore.mjs +51 -29
- package/dist/db/createBundleDiff.cjs +45 -68
- package/dist/db/createBundleDiff.d.cts +3 -3
- package/dist/db/createBundleDiff.d.mts +3 -3
- package/dist/db/createBundleDiff.mjs +47 -68
- package/dist/db/databasePluginCore.cjs +138 -0
- package/dist/db/databasePluginCore.mjs +137 -0
- package/dist/db/fixedMigrator.cjs +36 -93
- package/dist/db/fixedMigrator.mjs +36 -93
- package/dist/db/fixedMigratorMongo.cjs +319 -0
- package/dist/db/fixedMigratorMongo.mjs +319 -0
- package/dist/db/fixedMigratorShared.cjs +23 -0
- package/dist/db/fixedMigratorShared.mjs +18 -0
- package/dist/db/mongoMigrationExecution.cjs +11 -0
- package/dist/db/mongoMigrationExecution.mjs +11 -0
- package/dist/db/releaseCatalog.cjs +66 -0
- package/dist/db/releaseCatalog.d.cts +17 -0
- package/dist/db/releaseCatalog.d.mts +17 -0
- package/dist/db/releaseCatalog.mjs +64 -0
- package/dist/db/schema/mongodb.cjs +14 -6
- package/dist/db/schema/mongodb.mjs +14 -6
- package/dist/db/schema/registry.cjs +0 -2
- package/dist/db/schema/registry.mjs +1 -2
- package/dist/db/schema/sql.cjs +31 -14
- package/dist/db/schema/sql.mjs +32 -13
- package/dist/db/schema/sqlOperations.cjs +4 -4
- package/dist/db/schema/sqlOperations.mjs +5 -5
- package/dist/db/schemaGenerators.cjs +52 -18
- package/dist/db/schemaGenerators.mjs +52 -18
- package/dist/db/schemaReadiness.cjs +4 -3
- package/dist/db/schemaReadiness.mjs +4 -3
- package/dist/db/sqlMigrationExecution.cjs +67 -0
- package/dist/db/sqlMigrationExecution.mjs +66 -0
- package/dist/db/types.cjs +2 -6
- package/dist/db/types.d.cts +60 -16
- package/dist/db/types.d.mts +60 -16
- package/dist/db/types.mjs +3 -6
- package/dist/db/updateArtifacts.cjs +114 -60
- package/dist/db/updateArtifacts.mjs +117 -62
- package/dist/handler.cjs +108 -282
- package/dist/handler.d.cts +3 -46
- package/dist/handler.d.mts +3 -46
- package/dist/handler.mjs +107 -281
- package/dist/handlerBundleRoutes.cjs +155 -0
- package/dist/handlerBundleRoutes.mjs +155 -0
- package/dist/handlerErrors.cjs +9 -0
- package/dist/handlerErrors.mjs +9 -0
- package/dist/handlerParameters.cjs +39 -0
- package/dist/handlerParameters.mjs +34 -0
- package/dist/handlerReleaseCatalogRoutes.cjs +111 -0
- package/dist/handlerReleaseCatalogRoutes.mjs +110 -0
- package/dist/handlerReleaseManagementRoutes.cjs +125 -0
- package/dist/handlerReleaseManagementRoutes.mjs +124 -0
- package/dist/handlerTypes.d.cts +63 -0
- package/dist/handlerTypes.d.mts +63 -0
- package/dist/handlerVersionRoutes.cjs +10 -0
- package/dist/handlerVersionRoutes.d.cts +4 -0
- package/dist/handlerVersionRoutes.d.mts +4 -0
- package/dist/handlerVersionRoutes.mjs +9 -0
- package/dist/index.cjs +10 -1
- package/dist/index.d.cts +9 -3
- package/dist/index.d.mts +9 -3
- package/dist/index.mjs +5 -2
- package/dist/node.cjs +19 -12
- package/dist/node.d.cts +15 -10
- package/dist/node.d.mts +15 -10
- package/dist/node.mjs +19 -13
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/schema/dsl.cjs +19 -2
- package/dist/schema/dsl.mjs +17 -3
- package/dist/schema/index.cjs +1 -8
- package/dist/schema/index.mjs +2 -8
- package/dist/schema/types.cjs +3 -1
- package/dist/schema/types.mjs +3 -2
- package/dist/schema/v1_0_0.cjs +364 -0
- package/dist/schema/v1_0_0.mjs +357 -0
- package/dist/storageAccess.cjs +69 -25
- package/dist/storageAccess.mjs +68 -25
- package/dist/types/index.d.cts +4 -3
- package/dist/types/index.d.mts +5 -4
- package/package.json +8 -7
- package/src/adapters/databaseConstraintErrors.ts +25 -0
- package/src/adapters/databasePluginTestDatabase.ts +106 -0
- package/src/adapters/databasePluginUtils.spec.ts +29 -0
- package/src/adapters/databasePluginUtils.ts +214 -0
- package/src/adapters/drizzle.spec.ts +208 -47
- package/src/adapters/drizzle.ts +106 -293
- package/src/adapters/drizzleCrud.ts +419 -0
- package/src/adapters/drizzleLazyDB.ts +206 -100
- package/src/adapters/drizzleQuery.ts +164 -0
- package/src/adapters/kysely.spec.ts +126 -88
- package/src/adapters/kysely.ts +76 -334
- package/src/adapters/kyselyCrud.ts +588 -0
- package/src/adapters/kyselyQuery.ts +128 -0
- package/src/adapters/mongodb.spec.ts +141 -0
- package/src/adapters/mongodb.ts +60 -288
- package/src/adapters/mongodbCollections.ts +62 -0
- package/src/adapters/mongodbQuery.ts +226 -0
- package/src/adapters/mongodbReads.ts +311 -0
- package/src/adapters/mongodbRows.spec.ts +64 -0
- package/src/adapters/mongodbRows.ts +118 -0
- package/src/adapters/mongodbTestClient.ts +342 -0
- package/src/adapters/mongodbTestFilter.ts +166 -0
- package/src/adapters/mongodbWrites.ts +260 -0
- package/src/adapters/prisma.spec.ts +196 -0
- package/src/adapters/prisma.ts +417 -292
- package/src/adapters/prismaQuery.ts +129 -0
- package/src/adapters/prismaRows.spec.ts +98 -0
- package/src/adapters/prismaRows.ts +301 -0
- package/src/adapters/prismaTestClient.ts +396 -0
- package/src/analytics/analytics.integration.spec.ts +144 -0
- package/src/analytics/bounded/activeOverview.spec.ts +189 -0
- package/src/analytics/bounded/activeOverview.ts +148 -0
- package/src/analytics/bounded/installationSearch.spec.ts +130 -0
- package/src/analytics/bounded/installationSearch.ts +69 -0
- package/src/analytics/bounded/persistence.ts +43 -0
- package/src/analytics/bounded/provider.spec.ts +219 -0
- package/src/analytics/bounded/provider.ts +229 -0
- package/src/analytics/bounded/scan.ts +235 -0
- package/src/analytics/domain.ts +139 -0
- package/src/analytics/errors.ts +18 -0
- package/src/analytics/eventInput.ts +168 -0
- package/src/analytics/persistence.ts +10 -0
- package/src/analytics/queryInput.ts +102 -0
- package/src/analytics/routes.ts +123 -0
- package/src/analytics/types.ts +44 -0
- package/src/apiKeys.integration.spec.ts +192 -0
- package/src/apiKeys.spec.ts +162 -0
- package/src/apiKeys.ts +220 -0
- package/src/createHotUpdaterCore.ts +164 -100
- package/src/db/bundleRows.spec.ts +164 -0
- package/src/db/bundleRows.ts +10 -140
- package/src/db/createBundleDiff.spec.ts +172 -127
- package/src/db/createBundleDiff.ts +91 -110
- package/src/db/databasePluginCore.spec.ts +62 -0
- package/src/db/databasePluginCore.testFixtures.ts +76 -0
- package/src/db/databasePluginCore.ts +185 -0
- package/src/db/databasePluginUpdateCheck.bench.ts +107 -0
- package/src/db/fixedMigrator.spec.ts +184 -42
- package/src/db/fixedMigrator.ts +64 -205
- package/src/db/fixedMigratorMongo.spec.ts +192 -0
- package/src/db/fixedMigratorMongo.ts +425 -0
- package/src/db/fixedMigratorShared.ts +36 -0
- package/src/db/hotUpdaterSchema.ts +0 -1
- package/src/db/index.spec.ts +333 -1025
- package/src/db/mongoMigrationExecution.ts +23 -0
- package/src/db/node-sqlite.d.ts +25 -0
- package/src/db/releaseCatalog.ts +148 -0
- package/src/db/schema/mongodb.ts +20 -6
- package/src/db/schema/sql.ts +52 -11
- package/src/db/schema/sqlOperations.ts +5 -4
- package/src/db/schemaGenerators.ts +107 -23
- package/src/db/schemaReadiness.ts +2 -1
- package/src/db/sqlMigrationExecution.spec.ts +65 -0
- package/src/db/sqlMigrationExecution.ts +108 -0
- package/src/db/types.spec.ts +55 -0
- package/src/db/types.ts +129 -65
- package/src/db/updateArtifacts.spec.ts +359 -0
- package/src/db/updateArtifacts.ts +290 -126
- package/src/handler-standalone.integration.spec.ts +401 -364
- package/src/handler.spec.ts +137 -582
- package/src/handler.testFixtures.ts +30 -0
- package/src/handler.ts +218 -616
- package/src/handlerAuth.integration.spec.ts +33 -0
- package/src/handlerBundleRoutes.ts +259 -0
- package/src/handlerErrors.ts +7 -0
- package/src/handlerManagement.spec.ts +262 -0
- package/src/handlerParameters.ts +105 -0
- package/src/handlerReleaseCatalogRoutes.ts +154 -0
- package/src/handlerReleaseManagementRoutes.ts +213 -0
- package/src/handlerTypes.ts +96 -0
- package/src/handlerVersionRoutes.ts +12 -0
- package/src/index.ts +22 -2
- package/src/node.spec.ts +79 -10
- package/src/node.ts +20 -17
- package/src/releaseCatalogRoutes.integration.spec.ts +238 -0
- package/src/runtime.spec.ts +126 -959
- package/src/runtime.testFixtures.ts +71 -0
- package/src/schema/dsl-all-versions.spec.ts +26 -17
- package/src/schema/dsl.ts +41 -2
- package/src/schema/index.ts +3 -9
- package/src/schema/types.ts +9 -3
- package/src/schema/v1_0_0.spec.ts +146 -0
- package/src/schema/v1_0_0.ts +465 -0
- package/src/storageAccess.spec.ts +127 -32
- package/src/storageAccess.ts +106 -55
- package/src/types/index.ts +2 -1
- package/dist/db/bundleRows.cjs +0 -82
- package/dist/db/bundleRows.d.cts +0 -33
- package/dist/db/bundleRows.d.mts +0 -33
- package/dist/db/bundleRows.mjs +0 -79
- package/dist/db/pluginCore.cjs +0 -242
- package/dist/db/pluginCore.mjs +0 -241
- package/dist/db/schema/sqlMigrations.cjs +0 -74
- package/dist/db/schema/sqlMigrations.mjs +0 -73
- package/dist/db/schemaEnhancements.cjs +0 -20
- package/dist/db/schemaEnhancements.mjs +0 -19
- package/dist/route.cjs +0 -7
- package/dist/route.mjs +0 -7
- package/dist/schema/v0_21_0.cjs +0 -38
- package/dist/schema/v0_21_0.mjs +0 -37
- package/dist/schema/v0_29_0.cjs +0 -45
- package/dist/schema/v0_29_0.mjs +0 -44
- package/dist/schema/v0_31_0.cjs +0 -82
- package/dist/schema/v0_31_0.mjs +0 -80
- package/src/db/pluginCore.spec.ts +0 -1095
- package/src/db/pluginCore.ts +0 -475
- package/src/db/pluginUpdateCheck.bench.ts +0 -254
- package/src/db/schema/sqlMigrations.ts +0 -219
- package/src/db/schemaEnhancements.ts +0 -55
- package/src/route.ts +0 -7
- package/src/schema/v0_21_0.ts +0 -52
- package/src/schema/v0_29_0.ts +0 -62
- package/src/schema/v0_31_0.spec.ts +0 -73
- package/src/schema/v0_31_0.ts +0 -120
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { DatabasePluginInputError } from "@hot-updater/plugin-core";
|
|
2
|
+
import type {
|
|
3
|
+
DatabasePluginImplementation,
|
|
4
|
+
TransactionDatabasePluginImplementation,
|
|
5
|
+
} from "@hot-updater/plugin-core/internal";
|
|
6
|
+
import { asc, desc, eq, sql, type SQLWrapper } from "drizzle-orm";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
isChannelDeleteReferencedError,
|
|
10
|
+
translateChannelDeleteError,
|
|
11
|
+
} from "./databaseConstraintErrors";
|
|
12
|
+
import {
|
|
13
|
+
fromStoredBundleRow,
|
|
14
|
+
fromStoredReleaseCatalogRow,
|
|
15
|
+
fromStoredReleaseRow,
|
|
16
|
+
toStoredBundleRow,
|
|
17
|
+
toStoredBundleUpdate,
|
|
18
|
+
toStoredReleaseRow,
|
|
19
|
+
toStoredReleaseUpdate,
|
|
20
|
+
} from "./databasePluginUtils";
|
|
21
|
+
import type { DrizzleProvider } from "./drizzle";
|
|
22
|
+
import type { DrizzleDB, DrizzleTable } from "./drizzleLazyDB";
|
|
23
|
+
import { buildDrizzleWhere } from "./drizzleQuery";
|
|
24
|
+
|
|
25
|
+
class MissingDrizzleTableError extends Error {
|
|
26
|
+
readonly name = "MissingDrizzleTableError";
|
|
27
|
+
|
|
28
|
+
constructor(readonly table: string) {
|
|
29
|
+
super(`Drizzle schema is missing table "${table}".`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class DrizzleAdapterInvariantError extends Error {
|
|
34
|
+
readonly name = "DrizzleAdapterInvariantError";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const getDrizzleTable = (db: DrizzleDB, name: string): DrizzleTable => {
|
|
38
|
+
const table = db._.fullSchema[name];
|
|
39
|
+
if (table === undefined) throw new MissingDrizzleTableError(name);
|
|
40
|
+
return table;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const isSQLWrapper = (value: unknown): value is SQLWrapper =>
|
|
44
|
+
typeof value === "object" &&
|
|
45
|
+
value !== null &&
|
|
46
|
+
"getSQL" in value &&
|
|
47
|
+
typeof value.getSQL === "function";
|
|
48
|
+
|
|
49
|
+
export const getDrizzleColumn = (
|
|
50
|
+
table: DrizzleTable,
|
|
51
|
+
name: string,
|
|
52
|
+
): SQLWrapper => {
|
|
53
|
+
const value = table[name];
|
|
54
|
+
if (!isSQLWrapper(value)) {
|
|
55
|
+
throw new MissingDrizzleTableError(`${name} column`);
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const executeInsert = async (
|
|
61
|
+
db: DrizzleDB,
|
|
62
|
+
provider: DrizzleProvider,
|
|
63
|
+
table: DrizzleTable,
|
|
64
|
+
data: unknown,
|
|
65
|
+
onConflict: "ignore" | undefined,
|
|
66
|
+
): Promise<void> => {
|
|
67
|
+
const builder = db.insert(table);
|
|
68
|
+
const insert = builder.values(data);
|
|
69
|
+
if (onConflict === undefined) {
|
|
70
|
+
await insert.execute();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const ignored =
|
|
74
|
+
provider === "mysql"
|
|
75
|
+
? builder.ignore?.().values(data)
|
|
76
|
+
: insert.onConflictDoNothing?.();
|
|
77
|
+
if (ignored === undefined) throw new DrizzleAdapterInvariantError();
|
|
78
|
+
await ignored.execute();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const toOrderBy = (
|
|
82
|
+
table: DrizzleTable,
|
|
83
|
+
input: {
|
|
84
|
+
orderBy?: readonly {
|
|
85
|
+
field: string;
|
|
86
|
+
direction: "asc" | "desc";
|
|
87
|
+
nulls?: "first" | "last";
|
|
88
|
+
}[];
|
|
89
|
+
},
|
|
90
|
+
) => {
|
|
91
|
+
const clauses = input.orderBy;
|
|
92
|
+
return clauses?.flatMap((clause) => {
|
|
93
|
+
const column = getDrizzleColumn(table, clause.field);
|
|
94
|
+
const nulls =
|
|
95
|
+
clause.nulls ?? (clause.direction === "asc" ? "last" : "first");
|
|
96
|
+
return [
|
|
97
|
+
nulls === "first"
|
|
98
|
+
? sql`${column} is null desc`
|
|
99
|
+
: sql`${column} is null asc`,
|
|
100
|
+
clause.direction === "asc" ? asc(column) : desc(column),
|
|
101
|
+
];
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const createDrizzleCrud = (
|
|
106
|
+
db: DrizzleDB,
|
|
107
|
+
provider: DrizzleProvider,
|
|
108
|
+
): TransactionDatabasePluginImplementation &
|
|
109
|
+
Pick<DatabasePluginImplementation, "deleteChannel" | "insertChannel"> => {
|
|
110
|
+
const bundles = getDrizzleTable(db, "bundles");
|
|
111
|
+
const patches = getDrizzleTable(db, "bundle_patches");
|
|
112
|
+
const events = getDrizzleTable(db, "bundle_events");
|
|
113
|
+
const releases = getDrizzleTable(db, "releases");
|
|
114
|
+
const releaseCatalogs = getDrizzleTable(db, "release_catalogs");
|
|
115
|
+
const channels = getDrizzleTable(db, "channels");
|
|
116
|
+
const apiKeys = getDrizzleTable(db, "api_keys");
|
|
117
|
+
return {
|
|
118
|
+
async deleteChannel({ id }) {
|
|
119
|
+
const idPredicate = eq(getDrizzleColumn(channels, "id"), id);
|
|
120
|
+
const existing = await db.query.channels.findFirst({
|
|
121
|
+
where: idPredicate,
|
|
122
|
+
});
|
|
123
|
+
if (existing === undefined) {
|
|
124
|
+
return { deleted: false, reason: "not_found" };
|
|
125
|
+
}
|
|
126
|
+
const referencedReleases = await db.$count(
|
|
127
|
+
releases,
|
|
128
|
+
eq(getDrizzleColumn(releases, "channel_id"), id),
|
|
129
|
+
);
|
|
130
|
+
if (referencedReleases > 0) {
|
|
131
|
+
return { deleted: false, reason: "not_empty" };
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
await db.delete(channels).where(idPredicate).execute();
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (isChannelDeleteReferencedError(error)) {
|
|
137
|
+
return { deleted: false, reason: "not_empty" };
|
|
138
|
+
}
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
return { deleted: true };
|
|
142
|
+
},
|
|
143
|
+
async insertChannel(input) {
|
|
144
|
+
const before = await db.query.channels.findFirst({
|
|
145
|
+
where: eq(getDrizzleColumn(channels, "name"), input.row.name),
|
|
146
|
+
});
|
|
147
|
+
if (before !== undefined) return { row: before, inserted: false };
|
|
148
|
+
await executeInsert(db, provider, channels, input.row, "ignore");
|
|
149
|
+
const row = await db.query.channels.findFirst({
|
|
150
|
+
where: eq(getDrizzleColumn(channels, "name"), input.row.name),
|
|
151
|
+
});
|
|
152
|
+
if (row === undefined) throw new DrizzleAdapterInvariantError();
|
|
153
|
+
return { row, inserted: row.id === input.row.id };
|
|
154
|
+
},
|
|
155
|
+
async create(input) {
|
|
156
|
+
switch (input.model) {
|
|
157
|
+
case "bundles":
|
|
158
|
+
await executeInsert(
|
|
159
|
+
db,
|
|
160
|
+
provider,
|
|
161
|
+
bundles,
|
|
162
|
+
toStoredBundleRow(input.data, provider),
|
|
163
|
+
undefined,
|
|
164
|
+
);
|
|
165
|
+
return input.data;
|
|
166
|
+
case "bundle_patches":
|
|
167
|
+
await executeInsert(db, provider, patches, input.data, undefined);
|
|
168
|
+
return input.data;
|
|
169
|
+
case "bundle_events":
|
|
170
|
+
await executeInsert(db, provider, events, input.data, undefined);
|
|
171
|
+
return input.data;
|
|
172
|
+
case "releases":
|
|
173
|
+
await executeInsert(
|
|
174
|
+
db,
|
|
175
|
+
provider,
|
|
176
|
+
releases,
|
|
177
|
+
toStoredReleaseRow(input.data, provider),
|
|
178
|
+
undefined,
|
|
179
|
+
);
|
|
180
|
+
return input.data;
|
|
181
|
+
case "release_catalogs":
|
|
182
|
+
await executeInsert(
|
|
183
|
+
db,
|
|
184
|
+
provider,
|
|
185
|
+
releaseCatalogs,
|
|
186
|
+
input.data,
|
|
187
|
+
undefined,
|
|
188
|
+
);
|
|
189
|
+
return input.data;
|
|
190
|
+
case "api_keys":
|
|
191
|
+
await executeInsert(
|
|
192
|
+
db,
|
|
193
|
+
provider,
|
|
194
|
+
apiKeys,
|
|
195
|
+
input.data,
|
|
196
|
+
input.onConflict,
|
|
197
|
+
);
|
|
198
|
+
return input.data;
|
|
199
|
+
case "channels":
|
|
200
|
+
await executeInsert(
|
|
201
|
+
db,
|
|
202
|
+
provider,
|
|
203
|
+
channels,
|
|
204
|
+
input.data,
|
|
205
|
+
input.onConflict,
|
|
206
|
+
);
|
|
207
|
+
return input.data;
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
async update(input) {
|
|
211
|
+
const selector = input.where[0];
|
|
212
|
+
if (selector === undefined || typeof selector.value !== "string") {
|
|
213
|
+
throw new DrizzleAdapterInvariantError();
|
|
214
|
+
}
|
|
215
|
+
if (input.model === "api_keys") {
|
|
216
|
+
const idPredicate = eq(getDrizzleColumn(apiKeys, "id"), selector.value);
|
|
217
|
+
await db.update(apiKeys).set(input.update).where(idPredicate).execute();
|
|
218
|
+
return (
|
|
219
|
+
(await db.query.api_keys.findFirst({
|
|
220
|
+
where: idPredicate,
|
|
221
|
+
})) ?? null
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
if (input.model === "releases") {
|
|
225
|
+
const idPredicate = eq(
|
|
226
|
+
getDrizzleColumn(releases, "id"),
|
|
227
|
+
selector.value,
|
|
228
|
+
);
|
|
229
|
+
await db
|
|
230
|
+
.update(releases)
|
|
231
|
+
.set(toStoredReleaseUpdate(input.update, provider))
|
|
232
|
+
.where(idPredicate)
|
|
233
|
+
.execute();
|
|
234
|
+
const row = await db.query.releases.findFirst({ where: idPredicate });
|
|
235
|
+
return row === undefined ? null : fromStoredReleaseRow(row);
|
|
236
|
+
}
|
|
237
|
+
if (input.model === "release_catalogs") {
|
|
238
|
+
const scopePredicate = eq(
|
|
239
|
+
getDrizzleColumn(releaseCatalogs, "scope_key"),
|
|
240
|
+
selector.value,
|
|
241
|
+
);
|
|
242
|
+
await db
|
|
243
|
+
.update(releaseCatalogs)
|
|
244
|
+
.set(input.update)
|
|
245
|
+
.where(scopePredicate)
|
|
246
|
+
.execute();
|
|
247
|
+
const row = await db.query.release_catalogs.findFirst({
|
|
248
|
+
where: scopePredicate,
|
|
249
|
+
});
|
|
250
|
+
return row === undefined ? null : fromStoredReleaseCatalogRow(row);
|
|
251
|
+
}
|
|
252
|
+
const idPredicate = eq(getDrizzleColumn(bundles, "id"), selector.value);
|
|
253
|
+
await db
|
|
254
|
+
.update(bundles)
|
|
255
|
+
.set(toStoredBundleUpdate(input.update, provider))
|
|
256
|
+
.where(idPredicate)
|
|
257
|
+
.execute();
|
|
258
|
+
const stored = await db.query.bundles.findFirst({ where: idPredicate });
|
|
259
|
+
if (stored === undefined) return null;
|
|
260
|
+
return fromStoredBundleRow(stored);
|
|
261
|
+
},
|
|
262
|
+
async delete(input) {
|
|
263
|
+
switch (input.model) {
|
|
264
|
+
case "bundles": {
|
|
265
|
+
const where = buildDrizzleWhere(provider, bundles, input.where);
|
|
266
|
+
if (where === undefined) throw new DrizzleAdapterInvariantError();
|
|
267
|
+
await db.delete(bundles).where(where).execute();
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
case "bundle_patches": {
|
|
271
|
+
const where = buildDrizzleWhere(provider, patches, input.where);
|
|
272
|
+
if (where === undefined) throw new DrizzleAdapterInvariantError();
|
|
273
|
+
await db.delete(patches).where(where).execute();
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
case "releases": {
|
|
277
|
+
const where = buildDrizzleWhere(provider, releases, input.where);
|
|
278
|
+
if (where === undefined) throw new DrizzleAdapterInvariantError();
|
|
279
|
+
await db.delete(releases).where(where).execute();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
case "channels": {
|
|
283
|
+
const where = buildDrizzleWhere(provider, channels, input.where);
|
|
284
|
+
if (where === undefined) throw new DrizzleAdapterInvariantError();
|
|
285
|
+
try {
|
|
286
|
+
await db.delete(channels).where(where).execute();
|
|
287
|
+
} catch (error) {
|
|
288
|
+
translateChannelDeleteError(error);
|
|
289
|
+
}
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
async count(input) {
|
|
295
|
+
if (input.distinct !== undefined) {
|
|
296
|
+
throw new DatabasePluginInputError("invalid-operation");
|
|
297
|
+
}
|
|
298
|
+
switch (input.model) {
|
|
299
|
+
case "bundles":
|
|
300
|
+
return db.$count(
|
|
301
|
+
bundles,
|
|
302
|
+
buildDrizzleWhere(provider, bundles, input.where),
|
|
303
|
+
);
|
|
304
|
+
case "bundle_patches":
|
|
305
|
+
return db.$count(
|
|
306
|
+
patches,
|
|
307
|
+
buildDrizzleWhere(provider, patches, input.where),
|
|
308
|
+
);
|
|
309
|
+
case "releases":
|
|
310
|
+
return db.$count(
|
|
311
|
+
releases,
|
|
312
|
+
buildDrizzleWhere(provider, releases, input.where),
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
async findOne(input) {
|
|
317
|
+
switch (input.model) {
|
|
318
|
+
case "bundles": {
|
|
319
|
+
const row = await db.query.bundles.findFirst({
|
|
320
|
+
where: buildDrizzleWhere(provider, bundles, input.where),
|
|
321
|
+
});
|
|
322
|
+
return row === undefined ? null : fromStoredBundleRow(row);
|
|
323
|
+
}
|
|
324
|
+
case "bundle_patches":
|
|
325
|
+
return (
|
|
326
|
+
(await db.query.bundle_patches.findFirst({
|
|
327
|
+
where: buildDrizzleWhere(provider, patches, input.where),
|
|
328
|
+
})) ?? null
|
|
329
|
+
);
|
|
330
|
+
case "api_keys":
|
|
331
|
+
return (
|
|
332
|
+
(await db.query.api_keys.findFirst({
|
|
333
|
+
where: buildDrizzleWhere(provider, apiKeys, input.where),
|
|
334
|
+
})) ?? null
|
|
335
|
+
);
|
|
336
|
+
case "channels":
|
|
337
|
+
return (
|
|
338
|
+
(await db.query.channels.findFirst({
|
|
339
|
+
where: buildDrizzleWhere(provider, channels, input.where),
|
|
340
|
+
})) ?? null
|
|
341
|
+
);
|
|
342
|
+
case "releases": {
|
|
343
|
+
const row = await db.query.releases.findFirst({
|
|
344
|
+
where: buildDrizzleWhere(provider, releases, input.where),
|
|
345
|
+
});
|
|
346
|
+
return row === undefined ? null : fromStoredReleaseRow(row);
|
|
347
|
+
}
|
|
348
|
+
case "release_catalogs": {
|
|
349
|
+
const row = await db.query.release_catalogs.findFirst({
|
|
350
|
+
where: buildDrizzleWhere(provider, releaseCatalogs, input.where),
|
|
351
|
+
});
|
|
352
|
+
return row === undefined ? null : fromStoredReleaseCatalogRow(row);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
async findMany(input) {
|
|
357
|
+
if (input.distinctOn !== undefined) {
|
|
358
|
+
throw new DatabasePluginInputError("invalid-operation");
|
|
359
|
+
}
|
|
360
|
+
switch (input.model) {
|
|
361
|
+
case "bundles": {
|
|
362
|
+
const rows = await db.query.bundles.findMany({
|
|
363
|
+
where: buildDrizzleWhere(provider, bundles, input.where),
|
|
364
|
+
orderBy: toOrderBy(bundles, input),
|
|
365
|
+
limit: input.limit,
|
|
366
|
+
offset: input.offset,
|
|
367
|
+
});
|
|
368
|
+
return rows.map(fromStoredBundleRow);
|
|
369
|
+
}
|
|
370
|
+
case "bundle_events":
|
|
371
|
+
return db.query.bundle_events.findMany({
|
|
372
|
+
where: buildDrizzleWhere(provider, events, input.where),
|
|
373
|
+
orderBy: toOrderBy(events, input),
|
|
374
|
+
limit: input.limit,
|
|
375
|
+
offset: input.offset,
|
|
376
|
+
});
|
|
377
|
+
case "api_keys":
|
|
378
|
+
return db.query.api_keys.findMany({
|
|
379
|
+
where: buildDrizzleWhere(provider, apiKeys, input.where),
|
|
380
|
+
orderBy: toOrderBy(apiKeys, input),
|
|
381
|
+
limit: input.limit,
|
|
382
|
+
offset: input.offset,
|
|
383
|
+
});
|
|
384
|
+
case "bundle_patches":
|
|
385
|
+
return db.query.bundle_patches.findMany({
|
|
386
|
+
where: buildDrizzleWhere(provider, patches, input.where),
|
|
387
|
+
orderBy: toOrderBy(patches, input),
|
|
388
|
+
limit: input.limit,
|
|
389
|
+
offset: input.offset,
|
|
390
|
+
});
|
|
391
|
+
case "channels":
|
|
392
|
+
return db.query.channels.findMany({
|
|
393
|
+
where: buildDrizzleWhere(provider, channels, input.where),
|
|
394
|
+
orderBy: toOrderBy(channels, input),
|
|
395
|
+
limit: input.limit,
|
|
396
|
+
offset: input.offset,
|
|
397
|
+
});
|
|
398
|
+
case "releases": {
|
|
399
|
+
const rows = await db.query.releases.findMany({
|
|
400
|
+
where: buildDrizzleWhere(provider, releases, input.where),
|
|
401
|
+
orderBy: toOrderBy(releases, input),
|
|
402
|
+
limit: input.limit,
|
|
403
|
+
offset: input.offset,
|
|
404
|
+
});
|
|
405
|
+
return rows.map(fromStoredReleaseRow);
|
|
406
|
+
}
|
|
407
|
+
case "release_catalogs": {
|
|
408
|
+
const rows = await db.query.release_catalogs.findMany({
|
|
409
|
+
where: buildDrizzleWhere(provider, releaseCatalogs, input.where),
|
|
410
|
+
orderBy: toOrderBy(releaseCatalogs, input),
|
|
411
|
+
limit: input.limit,
|
|
412
|
+
offset: input.offset,
|
|
413
|
+
});
|
|
414
|
+
return rows.map(fromStoredReleaseCatalogRow);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
};
|