@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,271 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BundleEventRow,
|
|
3
|
-
BundlePatchRow,
|
|
4
|
-
ChannelRow,
|
|
5
|
-
ApiKeyRow,
|
|
6
|
-
InsightsInstallationRow,
|
|
7
|
-
ReleaseCatalogRow,
|
|
8
|
-
} from "@hot-updater/plugin-core";
|
|
9
|
-
|
|
10
|
-
import type { StoredBundleRow, StoredReleaseRow } from "./databasePluginUtils";
|
|
11
|
-
import type { DrizzleConfig } from "./drizzle";
|
|
12
|
-
|
|
13
|
-
export type DrizzleTable = Record<string, unknown>;
|
|
14
|
-
|
|
15
|
-
type DrizzleMutation = {
|
|
16
|
-
readonly execute: () => Promise<unknown>;
|
|
17
|
-
readonly all?: () => unknown[];
|
|
18
|
-
readonly run?: () => unknown;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type DrizzleInsertMutation = DrizzleMutation & {
|
|
22
|
-
readonly onDuplicateKeyUpdate?: (config: { set: object }) => DrizzleMutation;
|
|
23
|
-
readonly onConflictDoNothing?: () => DrizzleInsertMutation;
|
|
24
|
-
readonly returning?: (fields: Record<string, unknown>) => DrizzleMutation;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type DrizzleInsertBuilder = {
|
|
28
|
-
readonly ignore?: () => Pick<DrizzleInsertBuilder, "values">;
|
|
29
|
-
readonly values: (value: unknown) => DrizzleInsertMutation;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type DrizzleQuery<TRow> = {
|
|
33
|
-
readonly findFirst: (args?: unknown) => Promise<TRow | undefined>;
|
|
34
|
-
readonly findMany: (args?: unknown) => Promise<TRow[]>;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type DrizzleDB = {
|
|
38
|
-
readonly resultKind?: "sync" | "async";
|
|
39
|
-
readonly _: { readonly fullSchema: Record<string, DrizzleTable> };
|
|
40
|
-
readonly $count: (table: DrizzleTable, where?: unknown) => Promise<number>;
|
|
41
|
-
readonly delete: (table: DrizzleTable) => {
|
|
42
|
-
where: (condition: unknown) => DrizzleMutation;
|
|
43
|
-
};
|
|
44
|
-
readonly insert: (table: DrizzleTable) => DrizzleInsertBuilder;
|
|
45
|
-
readonly query: {
|
|
46
|
-
readonly bundles: DrizzleQuery<StoredBundleRow>;
|
|
47
|
-
readonly channels: DrizzleQuery<ChannelRow>;
|
|
48
|
-
readonly bundle_patches: DrizzleQuery<BundlePatchRow>;
|
|
49
|
-
readonly bundle_events: DrizzleQuery<BundleEventRow>;
|
|
50
|
-
readonly bundle_installations: DrizzleQuery<InsightsInstallationRow>;
|
|
51
|
-
readonly api_keys: DrizzleQuery<ApiKeyRow>;
|
|
52
|
-
readonly releases: DrizzleQuery<StoredReleaseRow>;
|
|
53
|
-
readonly release_catalogs: DrizzleQuery<ReleaseCatalogRow>;
|
|
54
|
-
};
|
|
55
|
-
readonly update: (table: DrizzleTable) => {
|
|
56
|
-
set: (values: unknown) => {
|
|
57
|
-
where: (condition: unknown) => DrizzleMutation;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
readonly transaction?: <TResult>(
|
|
61
|
-
operation: (transaction: DrizzleDB) => TResult | Promise<TResult>,
|
|
62
|
-
) => Promise<TResult>;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
class InvalidDrizzleDatabaseError extends Error {
|
|
66
|
-
readonly name = "InvalidDrizzleDatabaseError";
|
|
67
|
-
|
|
68
|
-
constructor(readonly reason: string) {
|
|
69
|
-
super(`[hot-updater] ${reason}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
74
|
-
typeof value === "object" && value !== null;
|
|
75
|
-
|
|
76
|
-
const hasFunction = (value: Record<string, unknown>, key: string): boolean =>
|
|
77
|
-
typeof value[key] === "function";
|
|
78
|
-
|
|
79
|
-
const isDrizzleQuery = (value: unknown): boolean =>
|
|
80
|
-
isRecord(value) &&
|
|
81
|
-
hasFunction(value, "findFirst") &&
|
|
82
|
-
hasFunction(value, "findMany");
|
|
83
|
-
|
|
84
|
-
const isDrizzleDB = (value: unknown): value is DrizzleDB => {
|
|
85
|
-
if (!isRecord(value)) return false;
|
|
86
|
-
const metadata = value["_"];
|
|
87
|
-
if (!isRecord(metadata) || !isRecord(metadata["fullSchema"])) return false;
|
|
88
|
-
const query = value["query"];
|
|
89
|
-
if (
|
|
90
|
-
!isRecord(query) ||
|
|
91
|
-
!isDrizzleQuery(query["bundle_events"]) ||
|
|
92
|
-
!isDrizzleQuery(query["bundle_installations"]) ||
|
|
93
|
-
!isDrizzleQuery(query["bundle_patches"]) ||
|
|
94
|
-
!isDrizzleQuery(query["bundles"]) ||
|
|
95
|
-
!isDrizzleQuery(query["channels"]) ||
|
|
96
|
-
!isDrizzleQuery(query["api_keys"]) ||
|
|
97
|
-
!isDrizzleQuery(query["releases"]) ||
|
|
98
|
-
!isDrizzleQuery(query["release_catalogs"])
|
|
99
|
-
) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
if (
|
|
103
|
-
value["transaction"] !== undefined &&
|
|
104
|
-
!hasFunction(value, "transaction")
|
|
105
|
-
) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
return (
|
|
109
|
-
hasFunction(value, "$count") &&
|
|
110
|
-
hasFunction(value, "delete") &&
|
|
111
|
-
hasFunction(value, "insert") &&
|
|
112
|
-
hasFunction(value, "update")
|
|
113
|
-
);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const asDB = (db: unknown): DrizzleDB => {
|
|
117
|
-
if (!isDrizzleDB(db)) {
|
|
118
|
-
throw new InvalidDrizzleDatabaseError(
|
|
119
|
-
"Drizzle adapter requires query mode with schema.",
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
return db;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const isDBFactory = (
|
|
126
|
-
db: DrizzleConfig["db"],
|
|
127
|
-
): db is () => unknown | Promise<unknown> => typeof db === "function";
|
|
128
|
-
|
|
129
|
-
const parseSchema = (
|
|
130
|
-
schema: Record<string, unknown>,
|
|
131
|
-
): Record<string, DrizzleTable> => {
|
|
132
|
-
const parsed: Record<string, DrizzleTable> = {};
|
|
133
|
-
for (const [name, table] of Object.entries(schema)) {
|
|
134
|
-
if (!isRecord(table)) {
|
|
135
|
-
throw new InvalidDrizzleDatabaseError(
|
|
136
|
-
`Drizzle schema table "${name}" is invalid.`,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
parsed[name] = table;
|
|
140
|
-
}
|
|
141
|
-
return parsed;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
export const createLazyDB = (config: DrizzleConfig): DrizzleDB => {
|
|
145
|
-
if (!isDBFactory(config.db)) return asDB(config.db);
|
|
146
|
-
if (!config.schema) {
|
|
147
|
-
throw new InvalidDrizzleDatabaseError(
|
|
148
|
-
"Drizzle adapter requires schema when db is lazy.",
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const source = config.db;
|
|
153
|
-
let resolvedDB: Promise<DrizzleDB> | undefined;
|
|
154
|
-
const getDB = (): Promise<DrizzleDB> => {
|
|
155
|
-
resolvedDB ??= Promise.resolve(source()).then(asDB);
|
|
156
|
-
return resolvedDB;
|
|
157
|
-
};
|
|
158
|
-
return {
|
|
159
|
-
_: { fullSchema: parseSchema(config.schema) },
|
|
160
|
-
$count: async (table, where) => (await getDB()).$count(table, where),
|
|
161
|
-
delete: (table) => ({
|
|
162
|
-
where: (condition) => ({
|
|
163
|
-
execute: async () =>
|
|
164
|
-
(await getDB()).delete(table).where(condition).execute(),
|
|
165
|
-
}),
|
|
166
|
-
}),
|
|
167
|
-
insert: (table) => ({
|
|
168
|
-
ignore: () => ({
|
|
169
|
-
values: (value) => ({
|
|
170
|
-
execute: async () => {
|
|
171
|
-
const insert = (await getDB()).insert(table).ignore;
|
|
172
|
-
if (insert === undefined) {
|
|
173
|
-
throw new InvalidDrizzleDatabaseError(
|
|
174
|
-
"The resolved Drizzle database does not support insert ignore.",
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
return insert().values(value).execute();
|
|
178
|
-
},
|
|
179
|
-
}),
|
|
180
|
-
}),
|
|
181
|
-
values: (value) => ({
|
|
182
|
-
execute: async () =>
|
|
183
|
-
(await getDB()).insert(table).values(value).execute(),
|
|
184
|
-
onConflictDoNothing: () => ({
|
|
185
|
-
execute: async () => {
|
|
186
|
-
const insert = (await getDB()).insert(table).values(value);
|
|
187
|
-
if (insert.onConflictDoNothing === undefined) {
|
|
188
|
-
throw new InvalidDrizzleDatabaseError(
|
|
189
|
-
"The resolved Drizzle database does not support conflict-ignore inserts.",
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
return insert.onConflictDoNothing().execute();
|
|
193
|
-
},
|
|
194
|
-
}),
|
|
195
|
-
}),
|
|
196
|
-
}),
|
|
197
|
-
query: {
|
|
198
|
-
bundle_events: {
|
|
199
|
-
findFirst: async (args) =>
|
|
200
|
-
(await getDB()).query.bundle_events.findFirst(args),
|
|
201
|
-
findMany: async (args) =>
|
|
202
|
-
(await getDB()).query.bundle_events.findMany(args),
|
|
203
|
-
},
|
|
204
|
-
bundle_installations: {
|
|
205
|
-
findFirst: async (args) =>
|
|
206
|
-
(await getDB()).query.bundle_installations.findFirst(args),
|
|
207
|
-
findMany: async (args) =>
|
|
208
|
-
(await getDB()).query.bundle_installations.findMany(args),
|
|
209
|
-
},
|
|
210
|
-
bundle_patches: {
|
|
211
|
-
findFirst: async (args) =>
|
|
212
|
-
(await getDB()).query.bundle_patches.findFirst(args),
|
|
213
|
-
findMany: async (args) =>
|
|
214
|
-
(await getDB()).query.bundle_patches.findMany(args),
|
|
215
|
-
},
|
|
216
|
-
bundles: {
|
|
217
|
-
findFirst: async (args) =>
|
|
218
|
-
(await getDB()).query.bundles.findFirst(args),
|
|
219
|
-
findMany: async (args) => (await getDB()).query.bundles.findMany(args),
|
|
220
|
-
},
|
|
221
|
-
channels: {
|
|
222
|
-
findFirst: async (args) =>
|
|
223
|
-
(await getDB()).query.channels.findFirst(args),
|
|
224
|
-
findMany: async (args) => (await getDB()).query.channels.findMany(args),
|
|
225
|
-
},
|
|
226
|
-
api_keys: {
|
|
227
|
-
findFirst: async (args) =>
|
|
228
|
-
(await getDB()).query.api_keys.findFirst(args),
|
|
229
|
-
findMany: async (args) => (await getDB()).query.api_keys.findMany(args),
|
|
230
|
-
},
|
|
231
|
-
releases: {
|
|
232
|
-
findFirst: async (args) =>
|
|
233
|
-
(await getDB()).query.releases.findFirst(args),
|
|
234
|
-
findMany: async (args) => (await getDB()).query.releases.findMany(args),
|
|
235
|
-
},
|
|
236
|
-
release_catalogs: {
|
|
237
|
-
findFirst: async (args) =>
|
|
238
|
-
(await getDB()).query.release_catalogs.findFirst(args),
|
|
239
|
-
findMany: async (args) =>
|
|
240
|
-
(await getDB()).query.release_catalogs.findMany(args),
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
update: (table) => ({
|
|
244
|
-
set: (values) => ({
|
|
245
|
-
where: (condition) => ({
|
|
246
|
-
execute: async () =>
|
|
247
|
-
(await getDB())
|
|
248
|
-
.update(table)
|
|
249
|
-
.set(values)
|
|
250
|
-
.where(condition)
|
|
251
|
-
.execute(),
|
|
252
|
-
}),
|
|
253
|
-
}),
|
|
254
|
-
}),
|
|
255
|
-
...(config.transaction === true
|
|
256
|
-
? {
|
|
257
|
-
transaction: async <TResult>(
|
|
258
|
-
operation: (transaction: DrizzleDB) => TResult | Promise<TResult>,
|
|
259
|
-
): Promise<TResult> => {
|
|
260
|
-
const db = await getDB();
|
|
261
|
-
if (db.transaction === undefined) {
|
|
262
|
-
throw new InvalidDrizzleDatabaseError(
|
|
263
|
-
"The resolved Drizzle database does not support transactions.",
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
return db.transaction(operation);
|
|
267
|
-
},
|
|
268
|
-
}
|
|
269
|
-
: {}),
|
|
270
|
-
};
|
|
271
|
-
};
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DatabaseModel,
|
|
3
|
-
DatabaseWhere,
|
|
4
|
-
} from "@hot-updater/plugin-core/internal";
|
|
5
|
-
import {
|
|
6
|
-
eq,
|
|
7
|
-
gt,
|
|
8
|
-
gte,
|
|
9
|
-
inArray,
|
|
10
|
-
isNotNull,
|
|
11
|
-
isNull,
|
|
12
|
-
lt,
|
|
13
|
-
lte,
|
|
14
|
-
ne,
|
|
15
|
-
notInArray,
|
|
16
|
-
sql,
|
|
17
|
-
type SQL,
|
|
18
|
-
type SQLWrapper,
|
|
19
|
-
} from "drizzle-orm";
|
|
20
|
-
|
|
21
|
-
import type { ORMSQLProvider } from "../db/types";
|
|
22
|
-
import { escapeGlobPattern, escapeLikePattern } from "./databasePluginUtils";
|
|
23
|
-
import type { DrizzleTable } from "./drizzleLazyDB";
|
|
24
|
-
|
|
25
|
-
class InvalidDatabasePredicateError extends Error {
|
|
26
|
-
readonly name = "InvalidDatabasePredicateError";
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
class MissingDrizzleColumnError extends Error {
|
|
30
|
-
readonly name = "MissingDrizzleColumnError";
|
|
31
|
-
|
|
32
|
-
constructor(readonly column: string) {
|
|
33
|
-
super(`Drizzle schema is missing column "${column}".`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const isSQLWrapper = (value: unknown): value is SQLWrapper =>
|
|
38
|
-
typeof value === "object" &&
|
|
39
|
-
value !== null &&
|
|
40
|
-
"getSQL" in value &&
|
|
41
|
-
typeof value.getSQL === "function";
|
|
42
|
-
|
|
43
|
-
const column = (table: DrizzleTable, field: string): SQLWrapper => {
|
|
44
|
-
const value = table[field];
|
|
45
|
-
if (!isSQLWrapper(value)) {
|
|
46
|
-
throw new MissingDrizzleColumnError(field);
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const stringPredicate = (
|
|
52
|
-
provider: ORMSQLProvider,
|
|
53
|
-
field: SQLWrapper,
|
|
54
|
-
operator: "contains" | "ends_with" | "starts_with",
|
|
55
|
-
value: string,
|
|
56
|
-
insensitive: boolean,
|
|
57
|
-
): SQL => {
|
|
58
|
-
if (provider === "sqlite" && !insensitive) {
|
|
59
|
-
const literal = escapeGlobPattern(value);
|
|
60
|
-
const pattern =
|
|
61
|
-
operator === "contains"
|
|
62
|
-
? `*${literal}*`
|
|
63
|
-
: operator === "starts_with"
|
|
64
|
-
? `${literal}*`
|
|
65
|
-
: `*${literal}`;
|
|
66
|
-
return sql`${field} glob ${pattern}`;
|
|
67
|
-
}
|
|
68
|
-
const literal = escapeLikePattern(value);
|
|
69
|
-
const pattern =
|
|
70
|
-
operator === "contains"
|
|
71
|
-
? `%${literal}%`
|
|
72
|
-
: operator === "starts_with"
|
|
73
|
-
? `${literal}%`
|
|
74
|
-
: `%${literal}`;
|
|
75
|
-
if (insensitive) {
|
|
76
|
-
return sql`lower(${field}) like lower(${pattern}) escape '\\'`;
|
|
77
|
-
}
|
|
78
|
-
if (provider === "mysql") {
|
|
79
|
-
return sql`binary ${field} like binary ${pattern} escape '\\'`;
|
|
80
|
-
}
|
|
81
|
-
return sql`${field} like ${pattern} escape '\\'`;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const predicate = <TModel extends DatabaseModel>(
|
|
85
|
-
provider: ORMSQLProvider,
|
|
86
|
-
table: DrizzleTable,
|
|
87
|
-
condition: DatabaseWhere<TModel>,
|
|
88
|
-
): SQL => {
|
|
89
|
-
const field = column(table, condition.field);
|
|
90
|
-
const operator = condition.operator ?? "eq";
|
|
91
|
-
switch (operator) {
|
|
92
|
-
case "eq":
|
|
93
|
-
case "ne": {
|
|
94
|
-
if (condition.value === null) {
|
|
95
|
-
return operator === "eq" ? isNull(field) : isNotNull(field);
|
|
96
|
-
}
|
|
97
|
-
const insensitive =
|
|
98
|
-
"mode" in condition && condition.mode === "insensitive";
|
|
99
|
-
if (insensitive) {
|
|
100
|
-
return operator === "eq"
|
|
101
|
-
? sql`lower(${field}) = lower(${condition.value})`
|
|
102
|
-
: sql`lower(${field}) <> lower(${condition.value})`;
|
|
103
|
-
}
|
|
104
|
-
return operator === "eq"
|
|
105
|
-
? eq(field, condition.value)
|
|
106
|
-
: ne(field, condition.value);
|
|
107
|
-
}
|
|
108
|
-
case "gt":
|
|
109
|
-
return gt(field, condition.value);
|
|
110
|
-
case "gte":
|
|
111
|
-
return gte(field, condition.value);
|
|
112
|
-
case "lt":
|
|
113
|
-
return lt(field, condition.value);
|
|
114
|
-
case "lte":
|
|
115
|
-
return lte(field, condition.value);
|
|
116
|
-
case "in":
|
|
117
|
-
case "not_in": {
|
|
118
|
-
if (!Array.isArray(condition.value)) {
|
|
119
|
-
throw new InvalidDatabasePredicateError();
|
|
120
|
-
}
|
|
121
|
-
if (operator === "in") {
|
|
122
|
-
return condition.value.length === 0
|
|
123
|
-
? sql`false`
|
|
124
|
-
: inArray(field, condition.value);
|
|
125
|
-
}
|
|
126
|
-
return condition.value.length === 0
|
|
127
|
-
? sql`true`
|
|
128
|
-
: notInArray(field, condition.value);
|
|
129
|
-
}
|
|
130
|
-
case "contains":
|
|
131
|
-
case "starts_with":
|
|
132
|
-
case "ends_with": {
|
|
133
|
-
if (typeof condition.value !== "string") {
|
|
134
|
-
throw new InvalidDatabasePredicateError();
|
|
135
|
-
}
|
|
136
|
-
return stringPredicate(
|
|
137
|
-
provider,
|
|
138
|
-
field,
|
|
139
|
-
operator,
|
|
140
|
-
condition.value,
|
|
141
|
-
"mode" in condition && condition.mode === "insensitive",
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const buildDrizzleWhere = <TModel extends DatabaseModel>(
|
|
148
|
-
provider: ORMSQLProvider,
|
|
149
|
-
table: DrizzleTable,
|
|
150
|
-
where: readonly DatabaseWhere<TModel>[] | undefined,
|
|
151
|
-
): SQL | undefined => {
|
|
152
|
-
const items = Array.isArray(where) ? where : [];
|
|
153
|
-
const [first, ...rest] = items;
|
|
154
|
-
if (first === undefined) return undefined;
|
|
155
|
-
let expression = predicate<TModel>(provider, table, first);
|
|
156
|
-
for (const condition of rest) {
|
|
157
|
-
const next = predicate<TModel>(provider, table, condition);
|
|
158
|
-
expression =
|
|
159
|
-
condition.connector === "OR"
|
|
160
|
-
? sql`(${expression} or ${next})`
|
|
161
|
-
: sql`(${expression} and ${next})`;
|
|
162
|
-
}
|
|
163
|
-
return expression;
|
|
164
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const isRetryableConflict = (error: unknown): boolean => {
|
|
2
|
-
if (typeof error !== "object" || error === null) return false;
|
|
3
|
-
if (
|
|
4
|
-
"code" in error &&
|
|
5
|
-
[
|
|
6
|
-
"ER_DUP_ENTRY",
|
|
7
|
-
"ER_LOCK_DEADLOCK",
|
|
8
|
-
"ER_LOCK_WAIT_TIMEOUT",
|
|
9
|
-
"40001",
|
|
10
|
-
"40P01",
|
|
11
|
-
].includes(String(error.code))
|
|
12
|
-
)
|
|
13
|
-
return true;
|
|
14
|
-
return (
|
|
15
|
-
"cause" in error &&
|
|
16
|
-
error.cause !== error &&
|
|
17
|
-
isRetryableConflict(error.cause)
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const runInsightsTransaction = async (
|
|
22
|
-
operation: () => Promise<void>,
|
|
23
|
-
): Promise<void> => {
|
|
24
|
-
for (let attempt = 0; ; attempt += 1) {
|
|
25
|
-
try {
|
|
26
|
-
await operation();
|
|
27
|
-
return;
|
|
28
|
-
} catch (error) {
|
|
29
|
-
if (attempt >= 2 || !isRetryableConflict(error)) throw error;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
-
import { toInsightsInstallationRow } from "@hot-updater/plugin-core";
|
|
3
|
-
import { Kysely } from "kysely";
|
|
4
|
-
import { PGliteDialect } from "kysely-pglite-dialect";
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
createBundlePatchRowFixture,
|
|
9
|
-
createBundleEventRowFixture,
|
|
10
|
-
createBundleRowFixture,
|
|
11
|
-
createChannelRowFixture,
|
|
12
|
-
} from "../../../test-utils/src/databaseTestFixtures";
|
|
13
|
-
import { setupDatabasePluginTestSuite } from "../../../test-utils/src/setupDatabasePluginTestSuite";
|
|
14
|
-
import type { DatabaseAdapterWithCapabilities } from "../db/types";
|
|
15
|
-
import {
|
|
16
|
-
DATABASE_PLUGIN_TEST_RESET_SQL,
|
|
17
|
-
DATABASE_PLUGIN_TEST_SCHEMA_SQL,
|
|
18
|
-
} from "./databasePluginTestDatabase";
|
|
19
|
-
import { kyselyAdapter } from "./kysely";
|
|
20
|
-
|
|
21
|
-
class KyselyTestStateError extends Error {
|
|
22
|
-
readonly name = "KyselyTestStateError";
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let client: PGlite | undefined;
|
|
26
|
-
let database: Kysely<object> | undefined;
|
|
27
|
-
|
|
28
|
-
const getClient = (): PGlite => {
|
|
29
|
-
if (client === undefined) throw new KyselyTestStateError();
|
|
30
|
-
return client;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const getDatabase = (): Kysely<object> => {
|
|
34
|
-
if (database === undefined) throw new KyselyTestStateError();
|
|
35
|
-
return database;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
setupDatabasePluginTestSuite({
|
|
39
|
-
name: "kyselyAdapter PostgreSQL",
|
|
40
|
-
migrate: async () => {
|
|
41
|
-
client = new PGlite();
|
|
42
|
-
database = new Kysely<object>({ dialect: new PGliteDialect(client) });
|
|
43
|
-
await client.exec(DATABASE_PLUGIN_TEST_SCHEMA_SQL);
|
|
44
|
-
},
|
|
45
|
-
createPlugin: (): DatabaseAdapterWithCapabilities =>
|
|
46
|
-
kyselyAdapter({ db: getDatabase(), provider: "postgresql" }),
|
|
47
|
-
reset: async () => {
|
|
48
|
-
await getClient().exec(DATABASE_PLUGIN_TEST_RESET_SQL);
|
|
49
|
-
},
|
|
50
|
-
dispose: async () => {
|
|
51
|
-
await getDatabase().destroy();
|
|
52
|
-
await getClient().close();
|
|
53
|
-
database = undefined;
|
|
54
|
-
client = undefined;
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe("kyselyAdapter SQLite JSON storage", () => {
|
|
59
|
-
it("rolls back the event when the installation write fails and permits retry", async () => {
|
|
60
|
-
const db = new PGlite();
|
|
61
|
-
const kysely = new Kysely<object>({ dialect: new PGliteDialect(db) });
|
|
62
|
-
await db.exec(DATABASE_PLUGIN_TEST_SCHEMA_SQL);
|
|
63
|
-
await db.exec(
|
|
64
|
-
"alter table bundle_installations add constraint reject_snapshot check (install_id <> 'install-703')",
|
|
65
|
-
);
|
|
66
|
-
const plugin = kyselyAdapter({ db: kysely, provider: "postgresql" });
|
|
67
|
-
const event = createBundleEventRowFixture("703", 100);
|
|
68
|
-
const input = { event, installation: toInsightsInstallationRow(event) };
|
|
69
|
-
try {
|
|
70
|
-
await expect(plugin.models.insights.record(input)).rejects.toThrow();
|
|
71
|
-
expect((await db.query("select id from bundle_events")).rows).toEqual([]);
|
|
72
|
-
await db.exec(
|
|
73
|
-
"alter table bundle_installations drop constraint reject_snapshot",
|
|
74
|
-
);
|
|
75
|
-
await plugin.models.insights.record(input);
|
|
76
|
-
await expect(
|
|
77
|
-
plugin.models.insights.findInstallations({
|
|
78
|
-
installId: event.install_id,
|
|
79
|
-
}),
|
|
80
|
-
).resolves.toEqual([input.installation]);
|
|
81
|
-
} finally {
|
|
82
|
-
await kysely.destroy();
|
|
83
|
-
await db.close();
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
it("round-trips JSON values through text columns", async () => {
|
|
87
|
-
const sqliteClient = new PGlite();
|
|
88
|
-
const sqliteDatabase = new Kysely<object>({
|
|
89
|
-
dialect: new PGliteDialect(sqliteClient),
|
|
90
|
-
});
|
|
91
|
-
await sqliteClient.exec(
|
|
92
|
-
DATABASE_PLUGIN_TEST_SCHEMA_SQL.replace(
|
|
93
|
-
"metadata jsonb not null default '{}'::jsonb",
|
|
94
|
-
"metadata text not null",
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
const plugin = kyselyAdapter({ db: sqliteDatabase, provider: "sqlite" });
|
|
98
|
-
const row = {
|
|
99
|
-
...createBundleRowFixture("901"),
|
|
100
|
-
metadata: { app_version: "1.0.0" },
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
await plugin.commit({
|
|
104
|
-
changes: [{ model: "bundles", operation: "insert", row }],
|
|
105
|
-
});
|
|
106
|
-
const stored = await sqliteClient.query<{
|
|
107
|
-
metadata: string;
|
|
108
|
-
}>("select metadata from bundles where id = $1", [row.id]);
|
|
109
|
-
|
|
110
|
-
expect(stored.rows[0]).toEqual({
|
|
111
|
-
metadata: JSON.stringify(row.metadata),
|
|
112
|
-
});
|
|
113
|
-
await expect(plugin.models.bundles.findById(row.id)).resolves.toEqual(row);
|
|
114
|
-
await sqliteDatabase.destroy();
|
|
115
|
-
await sqliteClient.close();
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe("kyselyAdapter soft relations", () => {
|
|
120
|
-
it("rejects an orphan patch and rolls back its owner row", async () => {
|
|
121
|
-
const softClient = new PGlite();
|
|
122
|
-
const softDatabase = new Kysely<object>({
|
|
123
|
-
dialect: new PGliteDialect(softClient),
|
|
124
|
-
});
|
|
125
|
-
await softClient.exec(
|
|
126
|
-
DATABASE_PLUGIN_TEST_SCHEMA_SQL.replaceAll(
|
|
127
|
-
" references bundles(id) on delete cascade",
|
|
128
|
-
"",
|
|
129
|
-
),
|
|
130
|
-
);
|
|
131
|
-
const plugin = kyselyAdapter({
|
|
132
|
-
db: softDatabase,
|
|
133
|
-
provider: "postgresql",
|
|
134
|
-
relationMode: "fumadb",
|
|
135
|
-
});
|
|
136
|
-
const owner = createBundleRowFixture("952");
|
|
137
|
-
const patch = createBundlePatchRowFixture(
|
|
138
|
-
"missing-base",
|
|
139
|
-
owner.id,
|
|
140
|
-
"missing-base",
|
|
141
|
-
);
|
|
142
|
-
const channel = createChannelRowFixture();
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
await expect(
|
|
146
|
-
plugin.commit({
|
|
147
|
-
changes: [
|
|
148
|
-
{
|
|
149
|
-
model: "channels",
|
|
150
|
-
operation: "insert",
|
|
151
|
-
row: channel,
|
|
152
|
-
onConflict: "ignore",
|
|
153
|
-
},
|
|
154
|
-
{ model: "bundles", operation: "insert", row: owner },
|
|
155
|
-
{
|
|
156
|
-
model: "bundlePatches",
|
|
157
|
-
operation: "insert",
|
|
158
|
-
row: patch,
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
}),
|
|
162
|
-
).rejects.toThrow("bundle_patches.base_bundle_id.foreign-key");
|
|
163
|
-
await expect(
|
|
164
|
-
plugin.models.bundles.findById(owner.id),
|
|
165
|
-
).resolves.toBeNull();
|
|
166
|
-
await expect(plugin.models.channels.list({})).resolves.toEqual({
|
|
167
|
-
channels: [],
|
|
168
|
-
});
|
|
169
|
-
} finally {
|
|
170
|
-
await softDatabase.destroy();
|
|
171
|
-
await softClient.close();
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|