@hot-updater/server 1.0.0-rc.3 → 1.0.0-rc.31
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 -153
- package/dist/insights/eventInput.mjs +0 -151
- 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 -332
- 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 -99
- package/src/insights/errors.ts +0 -11
- package/src/insights/eventInput.ts +0 -223
- package/src/insights/insights.integration.spec.ts +0 -419
- 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 -527
- 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
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
MIT License
|
|
1
|
+
MIT License with Hosted Service Attribution
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2023 Sungyu Kang
|
|
3
|
+
Copyright (c) 2023 Sungyu Kang
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -12,6 +12,16 @@ furnished to do so, subject to the following conditions:
|
|
|
12
12
|
The above copyright notice and this permission notice shall be included in all
|
|
13
13
|
copies or substantial portions of the Software.
|
|
14
14
|
|
|
15
|
+
Hosted service attribution. If you make the Software, a modified version of
|
|
16
|
+
it, or a service built on it available to third parties as a hosted or managed
|
|
17
|
+
service, that is, a service that third parties use to deliver updates to their
|
|
18
|
+
own apps, you must display the notice "Powered by hot-updater" with a link to
|
|
19
|
+
https://hot-updater.dev or https://github.com/gronxb/hot-updater where the
|
|
20
|
+
users of that service can reasonably see it, such as the service's dashboard,
|
|
21
|
+
the footer of its website, or its about page. This condition does not apply
|
|
22
|
+
when you run the Software only for your own apps, or for apps that you build
|
|
23
|
+
or operate for your clients.
|
|
24
|
+
|
|
15
25
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
26
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
27
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
@@ -19,15 +29,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
29
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
30
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
31
|
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
ADDITIONAL DISCLAIMER
|
|
26
|
-
|
|
27
|
-
The authors of this software shall not be held responsible for any legal issues,
|
|
28
|
-
regulatory violations, policy violations, or disputes arising from the use,
|
|
29
|
-
distribution, or integration of this software.
|
|
30
|
-
|
|
31
|
-
Users are solely responsible for ensuring compliance with all applicable laws,
|
|
32
|
-
regulations, and third-party policies (including but not limited to app store
|
|
33
|
-
policies).
|
|
@@ -1,83 +1,40 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const require_drizzleCrud = require("./drizzleCrud.cjs");
|
|
6
|
-
const require_drizzleLazyDB = require("./drizzleLazyDB.cjs");
|
|
2
|
+
const require_sqlProviders = require("./sqlProviders.cjs");
|
|
3
|
+
const require_engineDrizzleSchema = require("../db/engineDrizzleSchema.cjs");
|
|
4
|
+
const require_drizzleExecutor = require("./drizzleExecutor.cjs");
|
|
7
5
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
8
|
-
let _hot_updater_plugin_core_internal = require("@hot-updater/plugin-core/internal");
|
|
9
6
|
//#region src/adapters/drizzle.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
recordInsights: (input) => {
|
|
17
|
-
if (transaction === void 0) throw new Error("Drizzle Insights recording requires transaction support.");
|
|
18
|
-
return require_insightsTransaction.runInsightsTransaction(() => transaction((transactionDatabase) => require_drizzleCrud.recordDrizzleInsights(transactionDatabase, config.provider, input)));
|
|
19
|
-
},
|
|
20
|
-
deleteChannel: (input) => {
|
|
21
|
-
if (transaction === void 0) throw new Error("Drizzle channel deletion requires transaction support.");
|
|
22
|
-
return transaction((transactionDatabase) => require_drizzleCrud.createDrizzleCrud(transactionDatabase, config.provider).deleteChannel(input));
|
|
23
|
-
},
|
|
24
|
-
...transaction ? { delete: (input) => transaction((transactionDatabase) => require_drizzleCrud.createDrizzleCrud(transactionDatabase, config.provider).delete(input)) } : {},
|
|
25
|
-
...transaction ? { transaction: async (callback) => transaction((transaction) => callback(require_drizzleCrud.createDrizzleCrud(transaction, config.provider))) } : {}
|
|
26
|
-
};
|
|
27
|
-
};
|
|
7
|
+
/**
|
|
8
|
+
* Hot Updater's database on a Drizzle instance: the storage engine through the
|
|
9
|
+
* shared SQL core, fenced by the schema settings. `db generate` writes the
|
|
10
|
+
* Drizzle schema drizzle-kit applies; `db migrate` then writes the settings
|
|
11
|
+
* rows the fence checks.
|
|
12
|
+
*/
|
|
28
13
|
const drizzleAdapter = (config) => {
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
findByScopeKey: (scopeKey) => getAdapter().models.releaseCatalogs.findByScopeKey(scopeKey),
|
|
50
|
-
findMany: (input) => getAdapter().models.releaseCatalogs.findMany(input)
|
|
51
|
-
},
|
|
52
|
-
channels: {
|
|
53
|
-
insert: (input) => getAdapter().models.channels.insert(input),
|
|
54
|
-
list: (input) => getAdapter().models.channels.list(input),
|
|
55
|
-
delete: (input) => getAdapter().models.channels.delete(input)
|
|
56
|
-
},
|
|
57
|
-
insights: {
|
|
58
|
-
record: (input) => getAdapter().models.insights.record(input),
|
|
59
|
-
listEvents: (input) => getAdapter().models.insights.listEvents(input),
|
|
60
|
-
findInstallations: (input) => getAdapter().models.insights.findInstallations(input),
|
|
61
|
-
countInstallations: (input) => getAdapter().models.insights.countInstallations(input),
|
|
62
|
-
countEvents: (input) => getAdapter().models.insights.countEvents(input)
|
|
63
|
-
},
|
|
64
|
-
apiKeys: {
|
|
65
|
-
create: (row) => getAdapter().models.apiKeys.create(row),
|
|
66
|
-
findByHash: (hash) => getAdapter().models.apiKeys.findByHash(hash),
|
|
67
|
-
list: () => getAdapter().models.apiKeys.list(),
|
|
68
|
-
revoke: (input) => getAdapter().models.apiKeys.revoke(input)
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
commit: (input) => getAdapter().commit(input)
|
|
72
|
-
});
|
|
73
|
-
return Object.assign(plugin, {
|
|
74
|
-
adapterName: "drizzle",
|
|
75
|
-
provider: config.provider,
|
|
76
|
-
generateSchema: (version) => ({
|
|
77
|
-
code: require_schemaGenerators.generateDrizzleSchema(config.provider, version === "latest" ? require_registry.hotUpdaterSchema : require_registry.getHotUpdaterSchemaVersion(version)),
|
|
78
|
-
path: "hot-updater-schema.ts"
|
|
14
|
+
const provider = require_sqlProviders.checkSqlProvider("drizzleAdapter", config.provider);
|
|
15
|
+
const executor = require_drizzleExecutor.drizzleExecutor(config.db, provider);
|
|
16
|
+
return {
|
|
17
|
+
...(0, _hot_updater_plugin_core.createEngineDatabase)({
|
|
18
|
+
name: "drizzle",
|
|
19
|
+
adapter: (0, _hot_updater_plugin_core.createSqlAdapter)({ executor })
|
|
20
|
+
}),
|
|
21
|
+
provider,
|
|
22
|
+
generateSchema: ((version, _name, { schema } = _hot_updater_plugin_core.coreTarget) => {
|
|
23
|
+
if (version !== "latest" && version !== _hot_updater_plugin_core.coreSettings["schema.core"]) throw new Error(`Invalid version ${version}`);
|
|
24
|
+
return {
|
|
25
|
+
code: require_engineDrizzleSchema.generateDrizzleEngineSchema(provider, schema),
|
|
26
|
+
path: "hot-updater-schema.ts"
|
|
27
|
+
};
|
|
28
|
+
}),
|
|
29
|
+
createMigrator: ({ settings } = _hot_updater_plugin_core.coreTarget) => (0, _hot_updater_plugin_core.createSettingsMigrator)({
|
|
30
|
+
adapterName: "drizzle",
|
|
31
|
+
executor,
|
|
32
|
+
settings,
|
|
33
|
+
applyTables: "`drizzle-kit push` (or your drizzle-kit migrations)"
|
|
79
34
|
})
|
|
80
|
-
}
|
|
35
|
+
};
|
|
81
36
|
};
|
|
82
37
|
//#endregion
|
|
38
|
+
exports.DrizzleTransactionUnsupportedError = require_drizzleExecutor.DrizzleTransactionUnsupportedError;
|
|
39
|
+
exports.SUPPORTED_DRIZZLE_DRIVERS = require_drizzleExecutor.SUPPORTED_DRIZZLE_DRIVERS;
|
|
83
40
|
exports.drizzleAdapter = drizzleAdapter;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DrizzleTransactionUnsupportedError, SUPPORTED_DRIZZLE_DRIVERS } from "./drizzleExecutor.cjs";
|
|
2
|
+
import { SqlDialect, ToolingDatabase } from "@hot-updater/plugin-core";
|
|
2
3
|
//#region src/adapters/drizzle.d.ts
|
|
3
|
-
type DrizzleProvider =
|
|
4
|
+
type DrizzleProvider = SqlDialect;
|
|
4
5
|
interface DrizzleConfig {
|
|
6
|
+
/** A Drizzle database, or a function that returns one on first use. */
|
|
5
7
|
readonly db: unknown | (() => unknown | Promise<unknown>);
|
|
6
8
|
readonly provider: DrizzleProvider;
|
|
9
|
+
/** Ignored: Hot Updater reads through SQL; the schema file is for drizzle-kit. */
|
|
7
10
|
readonly schema?: Record<string, unknown>;
|
|
8
|
-
readonly transaction?: boolean;
|
|
9
11
|
}
|
|
10
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Hot Updater's database on a Drizzle instance: the storage engine through the
|
|
14
|
+
* shared SQL core, fenced by the schema settings. `db generate` writes the
|
|
15
|
+
* Drizzle schema drizzle-kit applies; `db migrate` then writes the settings
|
|
16
|
+
* rows the fence checks.
|
|
17
|
+
*/
|
|
18
|
+
declare const drizzleAdapter: (config: DrizzleConfig) => ToolingDatabase;
|
|
11
19
|
//#endregion
|
|
12
|
-
export { DrizzleConfig, DrizzleProvider, drizzleAdapter };
|
|
20
|
+
export { DrizzleConfig, DrizzleProvider, DrizzleTransactionUnsupportedError, SUPPORTED_DRIZZLE_DRIVERS, drizzleAdapter };
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DrizzleTransactionUnsupportedError, SUPPORTED_DRIZZLE_DRIVERS } from "./drizzleExecutor.mjs";
|
|
2
|
+
import { SqlDialect, ToolingDatabase } from "@hot-updater/plugin-core";
|
|
2
3
|
//#region src/adapters/drizzle.d.ts
|
|
3
|
-
type DrizzleProvider =
|
|
4
|
+
type DrizzleProvider = SqlDialect;
|
|
4
5
|
interface DrizzleConfig {
|
|
6
|
+
/** A Drizzle database, or a function that returns one on first use. */
|
|
5
7
|
readonly db: unknown | (() => unknown | Promise<unknown>);
|
|
6
8
|
readonly provider: DrizzleProvider;
|
|
9
|
+
/** Ignored: Hot Updater reads through SQL; the schema file is for drizzle-kit. */
|
|
7
10
|
readonly schema?: Record<string, unknown>;
|
|
8
|
-
readonly transaction?: boolean;
|
|
9
11
|
}
|
|
10
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Hot Updater's database on a Drizzle instance: the storage engine through the
|
|
14
|
+
* shared SQL core, fenced by the schema settings. `db generate` writes the
|
|
15
|
+
* Drizzle schema drizzle-kit applies; `db migrate` then writes the settings
|
|
16
|
+
* rows the fence checks.
|
|
17
|
+
*/
|
|
18
|
+
declare const drizzleAdapter: (config: DrizzleConfig) => ToolingDatabase;
|
|
11
19
|
//#endregion
|
|
12
|
-
export { DrizzleConfig, DrizzleProvider, drizzleAdapter };
|
|
20
|
+
export { DrizzleConfig, DrizzleProvider, DrizzleTransactionUnsupportedError, SUPPORTED_DRIZZLE_DRIVERS, drizzleAdapter };
|
|
@@ -1,82 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { createLazyDB } from "./drizzleLazyDB.mjs";
|
|
6
|
-
import { createDatabasePlugin } from "@hot-updater/plugin-core";
|
|
7
|
-
import { createDatabasePluginAdapter } from "@hot-updater/plugin-core/internal";
|
|
1
|
+
import { checkSqlProvider } from "./sqlProviders.mjs";
|
|
2
|
+
import { generateDrizzleEngineSchema } from "../db/engineDrizzleSchema.mjs";
|
|
3
|
+
import { DrizzleTransactionUnsupportedError, SUPPORTED_DRIZZLE_DRIVERS, drizzleExecutor } from "./drizzleExecutor.mjs";
|
|
4
|
+
import { coreSettings, coreTarget, createEngineDatabase, createSettingsMigrator, createSqlAdapter } from "@hot-updater/plugin-core";
|
|
8
5
|
//#region src/adapters/drizzle.ts
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
recordInsights: (input) => {
|
|
16
|
-
if (transaction === void 0) throw new Error("Drizzle Insights recording requires transaction support.");
|
|
17
|
-
return runInsightsTransaction(() => transaction((transactionDatabase) => recordDrizzleInsights(transactionDatabase, config.provider, input)));
|
|
18
|
-
},
|
|
19
|
-
deleteChannel: (input) => {
|
|
20
|
-
if (transaction === void 0) throw new Error("Drizzle channel deletion requires transaction support.");
|
|
21
|
-
return transaction((transactionDatabase) => createDrizzleCrud(transactionDatabase, config.provider).deleteChannel(input));
|
|
22
|
-
},
|
|
23
|
-
...transaction ? { delete: (input) => transaction((transactionDatabase) => createDrizzleCrud(transactionDatabase, config.provider).delete(input)) } : {},
|
|
24
|
-
...transaction ? { transaction: async (callback) => transaction((transaction) => callback(createDrizzleCrud(transaction, config.provider))) } : {}
|
|
25
|
-
};
|
|
26
|
-
};
|
|
6
|
+
/**
|
|
7
|
+
* Hot Updater's database on a Drizzle instance: the storage engine through the
|
|
8
|
+
* shared SQL core, fenced by the schema settings. `db generate` writes the
|
|
9
|
+
* Drizzle schema drizzle-kit applies; `db migrate` then writes the settings
|
|
10
|
+
* rows the fence checks.
|
|
11
|
+
*/
|
|
27
12
|
const drizzleAdapter = (config) => {
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
findByScopeKey: (scopeKey) => getAdapter().models.releaseCatalogs.findByScopeKey(scopeKey),
|
|
49
|
-
findMany: (input) => getAdapter().models.releaseCatalogs.findMany(input)
|
|
50
|
-
},
|
|
51
|
-
channels: {
|
|
52
|
-
insert: (input) => getAdapter().models.channels.insert(input),
|
|
53
|
-
list: (input) => getAdapter().models.channels.list(input),
|
|
54
|
-
delete: (input) => getAdapter().models.channels.delete(input)
|
|
55
|
-
},
|
|
56
|
-
insights: {
|
|
57
|
-
record: (input) => getAdapter().models.insights.record(input),
|
|
58
|
-
listEvents: (input) => getAdapter().models.insights.listEvents(input),
|
|
59
|
-
findInstallations: (input) => getAdapter().models.insights.findInstallations(input),
|
|
60
|
-
countInstallations: (input) => getAdapter().models.insights.countInstallations(input),
|
|
61
|
-
countEvents: (input) => getAdapter().models.insights.countEvents(input)
|
|
62
|
-
},
|
|
63
|
-
apiKeys: {
|
|
64
|
-
create: (row) => getAdapter().models.apiKeys.create(row),
|
|
65
|
-
findByHash: (hash) => getAdapter().models.apiKeys.findByHash(hash),
|
|
66
|
-
list: () => getAdapter().models.apiKeys.list(),
|
|
67
|
-
revoke: (input) => getAdapter().models.apiKeys.revoke(input)
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
commit: (input) => getAdapter().commit(input)
|
|
71
|
-
});
|
|
72
|
-
return Object.assign(plugin, {
|
|
73
|
-
adapterName: "drizzle",
|
|
74
|
-
provider: config.provider,
|
|
75
|
-
generateSchema: (version) => ({
|
|
76
|
-
code: generateDrizzleSchema(config.provider, version === "latest" ? hotUpdaterSchema : getHotUpdaterSchemaVersion(version)),
|
|
77
|
-
path: "hot-updater-schema.ts"
|
|
13
|
+
const provider = checkSqlProvider("drizzleAdapter", config.provider);
|
|
14
|
+
const executor = drizzleExecutor(config.db, provider);
|
|
15
|
+
return {
|
|
16
|
+
...createEngineDatabase({
|
|
17
|
+
name: "drizzle",
|
|
18
|
+
adapter: createSqlAdapter({ executor })
|
|
19
|
+
}),
|
|
20
|
+
provider,
|
|
21
|
+
generateSchema: ((version, _name, { schema } = coreTarget) => {
|
|
22
|
+
if (version !== "latest" && version !== coreSettings["schema.core"]) throw new Error(`Invalid version ${version}`);
|
|
23
|
+
return {
|
|
24
|
+
code: generateDrizzleEngineSchema(provider, schema),
|
|
25
|
+
path: "hot-updater-schema.ts"
|
|
26
|
+
};
|
|
27
|
+
}),
|
|
28
|
+
createMigrator: ({ settings } = coreTarget) => createSettingsMigrator({
|
|
29
|
+
adapterName: "drizzle",
|
|
30
|
+
executor,
|
|
31
|
+
settings,
|
|
32
|
+
applyTables: "`drizzle-kit push` (or your drizzle-kit migrations)"
|
|
78
33
|
})
|
|
79
|
-
}
|
|
34
|
+
};
|
|
80
35
|
};
|
|
81
36
|
//#endregion
|
|
82
|
-
export { drizzleAdapter };
|
|
37
|
+
export { DrizzleTransactionUnsupportedError, SUPPORTED_DRIZZLE_DRIVERS, drizzleAdapter };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
let drizzle_orm = require("drizzle-orm");
|
|
2
|
+
//#region src/adapters/drizzleExecutor.ts
|
|
3
|
+
const SUPPORTED_DRIZZLE_DRIVERS = "node-postgres, postgres-js, PGlite, or Neon over WebSockets for PostgreSQL; mysql2 for MySQL; libSQL, better-sqlite3, or bun:sqlite for SQLite";
|
|
4
|
+
var DrizzleTransactionUnsupportedError = class extends Error {
|
|
5
|
+
name = "DrizzleTransactionUnsupportedError";
|
|
6
|
+
constructor(cause) {
|
|
7
|
+
super(`This Drizzle driver cannot run interactive transactions, which Hot Updater needs. Use ${SUPPORTED_DRIZZLE_DRIVERS}.`, { cause });
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
/** The SQL core's statement as Drizzle SQL, each placeholder bound as a parameter. */
|
|
11
|
+
const toSql = (dialect, { sql: text, params }) => {
|
|
12
|
+
const pattern = dialect === "postgresql" ? /\$(\d+)/gu : /\?/gu;
|
|
13
|
+
const chunks = [];
|
|
14
|
+
let last = 0;
|
|
15
|
+
let next = 0;
|
|
16
|
+
for (const match of text.matchAll(pattern)) {
|
|
17
|
+
chunks.push(drizzle_orm.sql.raw(text.slice(last, match.index)));
|
|
18
|
+
const position = dialect === "postgresql" ? Number(match[1]) - 1 : next++;
|
|
19
|
+
chunks.push(drizzle_orm.sql`${drizzle_orm.sql.param(params[position])}`);
|
|
20
|
+
last = match.index + match[0].length;
|
|
21
|
+
}
|
|
22
|
+
chunks.push(drizzle_orm.sql.raw(text.slice(last)));
|
|
23
|
+
return drizzle_orm.sql.join(chunks);
|
|
24
|
+
};
|
|
25
|
+
const over = (dialect, runner) => ({ async execute(statement) {
|
|
26
|
+
const query = toSql(dialect, statement);
|
|
27
|
+
if (dialect === "sqlite") return /^\s*SELECT\b/iu.test(statement.sql) ? {
|
|
28
|
+
rows: await runner.all(query),
|
|
29
|
+
changes: 0
|
|
30
|
+
} : {
|
|
31
|
+
rows: [],
|
|
32
|
+
changes: changesOf(await runner.run(query))
|
|
33
|
+
};
|
|
34
|
+
const result = await runner.execute(query);
|
|
35
|
+
const value = dialect === "mysql" && Array.isArray(result) ? result[0] : result;
|
|
36
|
+
return {
|
|
37
|
+
rows: Array.isArray(value) ? value : value.rows ?? [],
|
|
38
|
+
changes: Array.isArray(value) && dialect === "mysql" ? 0 : changesOf(value)
|
|
39
|
+
};
|
|
40
|
+
} });
|
|
41
|
+
const changesOf = (result) => {
|
|
42
|
+
const record = result ?? {};
|
|
43
|
+
const meta = record.meta;
|
|
44
|
+
return Number(record.rowCount ?? record.affectedRows ?? record.rowsAffected ?? record.changes ?? record.count ?? meta?.changes ?? 0);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The SQL core's executor over a Drizzle database, or a function that
|
|
48
|
+
* returns one. Async drivers run Drizzle's transactions; sync SQLite drivers
|
|
49
|
+
* run one statement at a time, beginning transactions with BEGIN IMMEDIATE.
|
|
50
|
+
* First use checks that the driver can run a transaction at all.
|
|
51
|
+
*/
|
|
52
|
+
const drizzleExecutor = (source, dialect) => {
|
|
53
|
+
const isSync = (runner) => dialect === "sqlite" && runner.resultKind === "sync";
|
|
54
|
+
let ready;
|
|
55
|
+
const resolve = () => {
|
|
56
|
+
ready ??= (async () => {
|
|
57
|
+
const runner = await (typeof source === "function" ? source() : source);
|
|
58
|
+
if (isSync(runner)) return runner;
|
|
59
|
+
let started = false;
|
|
60
|
+
try {
|
|
61
|
+
if (typeof runner.transaction !== "function") throw new TypeError("The Drizzle database has no transaction().");
|
|
62
|
+
await runner.transaction(async () => {
|
|
63
|
+
started = true;
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (!started) throw new DrizzleTransactionUnsupportedError(error);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
return runner;
|
|
70
|
+
})();
|
|
71
|
+
ready.catch(() => {
|
|
72
|
+
ready = void 0;
|
|
73
|
+
});
|
|
74
|
+
return ready;
|
|
75
|
+
};
|
|
76
|
+
let queue = Promise.resolve();
|
|
77
|
+
const serial = (task) => {
|
|
78
|
+
const result = queue.then(task);
|
|
79
|
+
queue = result.catch(() => void 0);
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
dialect,
|
|
84
|
+
async execute(statement) {
|
|
85
|
+
const runner = await resolve();
|
|
86
|
+
const run = () => over(dialect, runner).execute(statement);
|
|
87
|
+
return isSync(runner) ? serial(run) : run();
|
|
88
|
+
},
|
|
89
|
+
async transaction(fn) {
|
|
90
|
+
const runner = await resolve();
|
|
91
|
+
if (!isSync(runner)) return await runner.transaction((tx) => fn(over(dialect, tx)));
|
|
92
|
+
return serial(async () => {
|
|
93
|
+
const connection = over(dialect, runner);
|
|
94
|
+
const raw = (text) => connection.execute({
|
|
95
|
+
sql: text,
|
|
96
|
+
params: []
|
|
97
|
+
});
|
|
98
|
+
await raw("BEGIN IMMEDIATE");
|
|
99
|
+
try {
|
|
100
|
+
const result = await fn(connection);
|
|
101
|
+
await raw("COMMIT");
|
|
102
|
+
return result;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
await raw("ROLLBACK").catch(() => void 0);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
//#endregion
|
|
112
|
+
exports.DrizzleTransactionUnsupportedError = DrizzleTransactionUnsupportedError;
|
|
113
|
+
exports.SUPPORTED_DRIZZLE_DRIVERS = SUPPORTED_DRIZZLE_DRIVERS;
|
|
114
|
+
exports.drizzleExecutor = drizzleExecutor;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SqlDialect, SqlExecutor } from "@hot-updater/plugin-core";
|
|
2
|
+
//#region src/adapters/drizzleExecutor.d.ts
|
|
3
|
+
declare const SUPPORTED_DRIZZLE_DRIVERS = "node-postgres, postgres-js, PGlite, or Neon over WebSockets for PostgreSQL; mysql2 for MySQL; libSQL, better-sqlite3, or bun:sqlite for SQLite";
|
|
4
|
+
declare class DrizzleTransactionUnsupportedError extends Error {
|
|
5
|
+
readonly name = "DrizzleTransactionUnsupportedError";
|
|
6
|
+
constructor(cause: unknown);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { DrizzleTransactionUnsupportedError, SUPPORTED_DRIZZLE_DRIVERS };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SqlDialect, SqlExecutor } from "@hot-updater/plugin-core";
|
|
2
|
+
//#region src/adapters/drizzleExecutor.d.ts
|
|
3
|
+
declare const SUPPORTED_DRIZZLE_DRIVERS = "node-postgres, postgres-js, PGlite, or Neon over WebSockets for PostgreSQL; mysql2 for MySQL; libSQL, better-sqlite3, or bun:sqlite for SQLite";
|
|
4
|
+
declare class DrizzleTransactionUnsupportedError extends Error {
|
|
5
|
+
readonly name = "DrizzleTransactionUnsupportedError";
|
|
6
|
+
constructor(cause: unknown);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { DrizzleTransactionUnsupportedError, SUPPORTED_DRIZZLE_DRIVERS };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
//#region src/adapters/drizzleExecutor.ts
|
|
3
|
+
const SUPPORTED_DRIZZLE_DRIVERS = "node-postgres, postgres-js, PGlite, or Neon over WebSockets for PostgreSQL; mysql2 for MySQL; libSQL, better-sqlite3, or bun:sqlite for SQLite";
|
|
4
|
+
var DrizzleTransactionUnsupportedError = class extends Error {
|
|
5
|
+
name = "DrizzleTransactionUnsupportedError";
|
|
6
|
+
constructor(cause) {
|
|
7
|
+
super(`This Drizzle driver cannot run interactive transactions, which Hot Updater needs. Use ${SUPPORTED_DRIZZLE_DRIVERS}.`, { cause });
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
/** The SQL core's statement as Drizzle SQL, each placeholder bound as a parameter. */
|
|
11
|
+
const toSql = (dialect, { sql: text, params }) => {
|
|
12
|
+
const pattern = dialect === "postgresql" ? /\$(\d+)/gu : /\?/gu;
|
|
13
|
+
const chunks = [];
|
|
14
|
+
let last = 0;
|
|
15
|
+
let next = 0;
|
|
16
|
+
for (const match of text.matchAll(pattern)) {
|
|
17
|
+
chunks.push(sql.raw(text.slice(last, match.index)));
|
|
18
|
+
const position = dialect === "postgresql" ? Number(match[1]) - 1 : next++;
|
|
19
|
+
chunks.push(sql`${sql.param(params[position])}`);
|
|
20
|
+
last = match.index + match[0].length;
|
|
21
|
+
}
|
|
22
|
+
chunks.push(sql.raw(text.slice(last)));
|
|
23
|
+
return sql.join(chunks);
|
|
24
|
+
};
|
|
25
|
+
const over = (dialect, runner) => ({ async execute(statement) {
|
|
26
|
+
const query = toSql(dialect, statement);
|
|
27
|
+
if (dialect === "sqlite") return /^\s*SELECT\b/iu.test(statement.sql) ? {
|
|
28
|
+
rows: await runner.all(query),
|
|
29
|
+
changes: 0
|
|
30
|
+
} : {
|
|
31
|
+
rows: [],
|
|
32
|
+
changes: changesOf(await runner.run(query))
|
|
33
|
+
};
|
|
34
|
+
const result = await runner.execute(query);
|
|
35
|
+
const value = dialect === "mysql" && Array.isArray(result) ? result[0] : result;
|
|
36
|
+
return {
|
|
37
|
+
rows: Array.isArray(value) ? value : value.rows ?? [],
|
|
38
|
+
changes: Array.isArray(value) && dialect === "mysql" ? 0 : changesOf(value)
|
|
39
|
+
};
|
|
40
|
+
} });
|
|
41
|
+
const changesOf = (result) => {
|
|
42
|
+
const record = result ?? {};
|
|
43
|
+
const meta = record.meta;
|
|
44
|
+
return Number(record.rowCount ?? record.affectedRows ?? record.rowsAffected ?? record.changes ?? record.count ?? meta?.changes ?? 0);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The SQL core's executor over a Drizzle database, or a function that
|
|
48
|
+
* returns one. Async drivers run Drizzle's transactions; sync SQLite drivers
|
|
49
|
+
* run one statement at a time, beginning transactions with BEGIN IMMEDIATE.
|
|
50
|
+
* First use checks that the driver can run a transaction at all.
|
|
51
|
+
*/
|
|
52
|
+
const drizzleExecutor = (source, dialect) => {
|
|
53
|
+
const isSync = (runner) => dialect === "sqlite" && runner.resultKind === "sync";
|
|
54
|
+
let ready;
|
|
55
|
+
const resolve = () => {
|
|
56
|
+
ready ??= (async () => {
|
|
57
|
+
const runner = await (typeof source === "function" ? source() : source);
|
|
58
|
+
if (isSync(runner)) return runner;
|
|
59
|
+
let started = false;
|
|
60
|
+
try {
|
|
61
|
+
if (typeof runner.transaction !== "function") throw new TypeError("The Drizzle database has no transaction().");
|
|
62
|
+
await runner.transaction(async () => {
|
|
63
|
+
started = true;
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (!started) throw new DrizzleTransactionUnsupportedError(error);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
return runner;
|
|
70
|
+
})();
|
|
71
|
+
ready.catch(() => {
|
|
72
|
+
ready = void 0;
|
|
73
|
+
});
|
|
74
|
+
return ready;
|
|
75
|
+
};
|
|
76
|
+
let queue = Promise.resolve();
|
|
77
|
+
const serial = (task) => {
|
|
78
|
+
const result = queue.then(task);
|
|
79
|
+
queue = result.catch(() => void 0);
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
dialect,
|
|
84
|
+
async execute(statement) {
|
|
85
|
+
const runner = await resolve();
|
|
86
|
+
const run = () => over(dialect, runner).execute(statement);
|
|
87
|
+
return isSync(runner) ? serial(run) : run();
|
|
88
|
+
},
|
|
89
|
+
async transaction(fn) {
|
|
90
|
+
const runner = await resolve();
|
|
91
|
+
if (!isSync(runner)) return await runner.transaction((tx) => fn(over(dialect, tx)));
|
|
92
|
+
return serial(async () => {
|
|
93
|
+
const connection = over(dialect, runner);
|
|
94
|
+
const raw = (text) => connection.execute({
|
|
95
|
+
sql: text,
|
|
96
|
+
params: []
|
|
97
|
+
});
|
|
98
|
+
await raw("BEGIN IMMEDIATE");
|
|
99
|
+
try {
|
|
100
|
+
const result = await fn(connection);
|
|
101
|
+
await raw("COMMIT");
|
|
102
|
+
return result;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
await raw("ROLLBACK").catch(() => void 0);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
//#endregion
|
|
112
|
+
export { DrizzleTransactionUnsupportedError, SUPPORTED_DRIZZLE_DRIVERS, drizzleExecutor };
|
package/dist/adapters/kysely.cjs
CHANGED
|
@@ -1,39 +1,30 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const require_kyselyCrud = require("./kyselyCrud.cjs");
|
|
2
|
+
const require_kyselyExecutor = require("./kyselyExecutor.cjs");
|
|
3
|
+
const require_sqlProviders = require("./sqlProviders.cjs");
|
|
5
4
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
6
|
-
let _hot_updater_plugin_core_internal = require("@hot-updater/plugin-core/internal");
|
|
7
5
|
//#region src/adapters/kysely.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
recordInsights: (input) => require_insightsTransaction.runInsightsTransaction(() => db.transaction().execute((transaction) => require_kyselyCrud.recordKyselyInsights(transaction, config.provider, input))),
|
|
14
|
-
deleteChannel: (input) => db.transaction().execute((transaction) => require_kyselyCrud.createKyselyCrud(transaction, config.provider, relationMode).deleteChannel(input)),
|
|
15
|
-
create: (input) => db.transaction().execute((transaction) => require_kyselyCrud.createKyselyCrud(transaction, config.provider, relationMode).create(input)),
|
|
16
|
-
update: (input) => db.transaction().execute((transaction) => require_kyselyCrud.createKyselyCrud(transaction, config.provider, relationMode).update(input)),
|
|
17
|
-
delete: (input) => db.transaction().execute((transaction) => require_kyselyCrud.createKyselyCrud(transaction, config.provider, relationMode).delete(input)),
|
|
18
|
-
transaction: (callback) => db.transaction().execute((transaction) => callback(require_kyselyCrud.createKyselyCrud(transaction, config.provider, relationMode)))
|
|
19
|
-
};
|
|
20
|
-
};
|
|
6
|
+
/**
|
|
7
|
+
* Hot Updater's database on a Kysely instance: the storage engine through the
|
|
8
|
+
* shared SQL core, fenced by the schema settings. `db migrate` and
|
|
9
|
+
* `db generate --sql` apply the engine's SQL schema.
|
|
10
|
+
*/
|
|
21
11
|
const kyselyAdapter = (config) => {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
12
|
+
const provider = require_sqlProviders.checkSqlProvider("kyselyAdapter", config.provider);
|
|
13
|
+
const executor = require_kyselyExecutor.kyselyExecutor(config.db, provider);
|
|
14
|
+
return {
|
|
15
|
+
...(0, _hot_updater_plugin_core.createEngineDatabase)({
|
|
16
|
+
name: "kysely",
|
|
17
|
+
adapter: (0, _hot_updater_plugin_core.createSqlAdapter)({ executor })
|
|
18
|
+
}),
|
|
19
|
+
provider,
|
|
20
|
+
createMigrator: ({ schema, settings } = _hot_updater_plugin_core.coreTarget) => (0, _hot_updater_plugin_core.createEngineSqlMigrator)({
|
|
21
|
+
adapterName: "kysely",
|
|
22
|
+
executor,
|
|
23
|
+
schema,
|
|
24
|
+
settings
|
|
35
25
|
})
|
|
36
|
-
}
|
|
26
|
+
};
|
|
37
27
|
};
|
|
38
28
|
//#endregion
|
|
39
29
|
exports.kyselyAdapter = kyselyAdapter;
|
|
30
|
+
exports.kyselyExecutor = require_kyselyExecutor.kyselyExecutor;
|