rwsdk 0.1.16 → 0.1.17
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/lib/$.d.mts +8 -0
- package/dist/lib/$.mjs +5 -0
- package/dist/lib/compileTsModule.d.mts +1 -0
- package/dist/lib/compileTsModule.mjs +27 -0
- package/dist/lib/constants.d.mts +4 -0
- package/dist/lib/constants.mjs +6 -0
- package/dist/lib/findWranglerConfig.d.mts +1 -0
- package/dist/lib/findWranglerConfig.mjs +12 -0
- package/dist/lib/getShortName.d.mts +1 -0
- package/dist/lib/getShortName.mjs +2 -0
- package/dist/lib/getSrcPaths.d.ts +15 -0
- package/dist/lib/getSrcPaths.js +80 -0
- package/dist/lib/hasPkgScript.d.mts +1 -0
- package/dist/lib/hasPkgScript.mjs +9 -0
- package/dist/lib/jsonUtils.d.mts +28 -0
- package/dist/lib/jsonUtils.mjs +167 -0
- package/dist/lib/setupEnvFiles.d.mts +4 -0
- package/dist/lib/setupEnvFiles.mjs +31 -0
- package/dist/lib/smokeTests/artifacts.d.mts +10 -0
- package/dist/lib/smokeTests/artifacts.mjs +164 -0
- package/dist/lib/smokeTests/browser.d.mts +48 -0
- package/dist/lib/smokeTests/browser.mjs +1041 -0
- package/dist/lib/smokeTests/cleanup.d.mts +5 -0
- package/dist/lib/smokeTests/cleanup.mjs +214 -0
- package/dist/lib/smokeTests/codeUpdates.d.mts +8 -0
- package/dist/lib/smokeTests/codeUpdates.mjs +229 -0
- package/dist/lib/smokeTests/constants.d.mts +5 -0
- package/dist/lib/smokeTests/constants.mjs +10 -0
- package/dist/lib/smokeTests/development.d.mts +11 -0
- package/dist/lib/smokeTests/development.mjs +209 -0
- package/dist/lib/smokeTests/environment.d.mts +14 -0
- package/dist/lib/smokeTests/environment.mjs +163 -0
- package/dist/lib/smokeTests/release.d.mts +61 -0
- package/dist/lib/smokeTests/release.mjs +526 -0
- package/dist/lib/smokeTests/reporting.d.mts +13 -0
- package/dist/lib/smokeTests/reporting.mjs +355 -0
- package/dist/lib/smokeTests/runSmokeTests.d.mts +5 -0
- package/dist/lib/smokeTests/runSmokeTests.mjs +144 -0
- package/dist/lib/smokeTests/state.d.mts +48 -0
- package/dist/lib/smokeTests/state.mjs +57 -0
- package/dist/lib/smokeTests/templates/SmokeTest.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/SmokeTest.template.js +81 -0
- package/dist/lib/smokeTests/templates/SmokeTestClient.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/SmokeTestClient.template.js +159 -0
- package/dist/lib/smokeTests/templates/smokeTestFunctions.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/smokeTestFunctions.template.js +19 -0
- package/dist/lib/smokeTests/types.d.mts +75 -0
- package/dist/lib/smokeTests/types.mjs +1 -0
- package/dist/lib/smokeTests/utils.d.mts +15 -0
- package/dist/lib/smokeTests/utils.mjs +147 -0
- package/dist/llms/index.d.ts +3 -0
- package/dist/llms/index.js +35 -0
- package/dist/llms/rules/interruptors.d.ts +1 -0
- package/dist/llms/rules/interruptors.js +243 -0
- package/dist/llms/rules/middleware.d.ts +1 -0
- package/dist/llms/rules/middleware.js +71 -0
- package/dist/llms/rules/react.d.ts +1 -0
- package/dist/llms/rules/react.js +106 -0
- package/dist/llms/rules/request-response.d.ts +1 -0
- package/dist/llms/rules/request-response.js +209 -0
- package/dist/runtime/client.d.ts +17 -0
- package/dist/runtime/client.js +74 -0
- package/dist/runtime/clientNavigation.d.ts +4 -0
- package/dist/runtime/clientNavigation.js +53 -0
- package/dist/runtime/clientNavigation.test.d.ts +1 -0
- package/dist/runtime/clientNavigation.test.js +55 -0
- package/dist/runtime/constants.d.ts +1 -0
- package/dist/runtime/constants.js +1 -0
- package/dist/runtime/entries/auth.d.ts +1 -0
- package/dist/runtime/entries/auth.js +1 -0
- package/dist/runtime/entries/client.d.ts +4 -0
- package/dist/runtime/entries/client.js +4 -0
- package/dist/runtime/entries/clientSSR.d.ts +1 -0
- package/dist/runtime/entries/clientSSR.js +1 -0
- package/dist/runtime/entries/navigation.d.ts +1 -0
- package/dist/runtime/entries/navigation.js +1 -0
- package/dist/runtime/entries/no-react-server.d.ts +0 -0
- package/dist/runtime/entries/no-react-server.js +2 -0
- package/dist/runtime/entries/react-server-only.d.ts +0 -0
- package/dist/runtime/entries/react-server-only.js +2 -0
- package/dist/runtime/entries/router.d.ts +2 -0
- package/dist/runtime/entries/router.js +2 -0
- package/dist/runtime/entries/ssr.d.ts +1 -0
- package/dist/runtime/entries/ssr.js +1 -0
- package/dist/runtime/entries/worker.d.ts +9 -0
- package/dist/runtime/entries/worker.js +9 -0
- package/dist/runtime/error.d.ts +6 -0
- package/dist/runtime/error.js +8 -0
- package/dist/runtime/imports/ClientOnly.d.ts +3 -0
- package/dist/runtime/imports/ClientOnly.js +8 -0
- package/dist/runtime/imports/client.d.ts +4 -0
- package/dist/runtime/imports/client.js +33 -0
- package/dist/runtime/imports/ssr.d.ts +5 -0
- package/dist/runtime/imports/ssr.js +20 -0
- package/dist/runtime/imports/worker.d.ts +5 -0
- package/dist/runtime/imports/worker.js +22 -0
- package/dist/runtime/lib/auth/index.d.ts +1 -0
- package/dist/runtime/lib/auth/index.js +1 -0
- package/dist/runtime/lib/auth/session.d.ts +50 -0
- package/dist/runtime/lib/auth/session.js +148 -0
- package/dist/runtime/lib/db/DOWorkerDialect.d.ts +29 -0
- package/dist/runtime/lib/db/DOWorkerDialect.js +66 -0
- package/dist/runtime/lib/db/SqliteDurableObject.d.ts +14 -0
- package/dist/runtime/lib/db/SqliteDurableObject.js +42 -0
- package/dist/runtime/lib/db/createDb.d.ts +2 -0
- package/dist/runtime/lib/db/createDb.js +33 -0
- package/dist/runtime/lib/db/index.d.ts +4 -0
- package/dist/runtime/lib/db/index.js +3 -0
- package/dist/runtime/lib/db/migrations.d.ts +23 -0
- package/dist/runtime/lib/db/migrations.js +34 -0
- package/dist/runtime/lib/db/typeInference/assert.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/assert.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.d.ts +27 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +53 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +26 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +49 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +17 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +11 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +12 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +24 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.js +1 -0
- package/dist/runtime/lib/db/typeInference/database.d.ts +27 -0
- package/dist/runtime/lib/db/typeInference/database.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.js +360 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.js +33 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.js +143 -0
- package/dist/runtime/lib/db/typeInference/typetests/print.d.ts +3 -0
- package/dist/runtime/lib/db/typeInference/typetests/print.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.js +17 -0
- package/dist/runtime/lib/db/typeInference/utils.d.ts +82 -0
- package/dist/runtime/lib/db/typeInference/utils.js +2 -0
- package/dist/runtime/lib/debug.d.ts +2 -0
- package/dist/runtime/lib/debug.js +36 -0
- package/dist/runtime/lib/links.d.ts +14 -0
- package/dist/runtime/lib/links.js +38 -0
- package/dist/runtime/lib/realtime/client.d.ts +7 -0
- package/dist/runtime/lib/realtime/client.js +166 -0
- package/dist/runtime/lib/realtime/constants.d.ts +1 -0
- package/dist/runtime/lib/realtime/constants.js +1 -0
- package/dist/runtime/lib/realtime/durableObject.d.ts +29 -0
- package/dist/runtime/lib/realtime/durableObject.js +187 -0
- package/dist/runtime/lib/realtime/renderRealtimeClients.d.ts +7 -0
- package/dist/runtime/lib/realtime/renderRealtimeClients.js +6 -0
- package/dist/runtime/lib/realtime/shared.d.ts +10 -0
- package/dist/runtime/lib/realtime/shared.js +10 -0
- package/dist/runtime/lib/realtime/validateUpgradeRequest.d.ts +6 -0
- package/dist/runtime/lib/realtime/validateUpgradeRequest.js +29 -0
- package/dist/runtime/lib/realtime/worker.d.ts +3 -0
- package/dist/runtime/lib/realtime/worker.js +16 -0
- package/dist/runtime/lib/router.d.ts +56 -0
- package/dist/runtime/lib/router.js +210 -0
- package/dist/runtime/lib/router.test.d.ts +1 -0
- package/dist/runtime/lib/router.test.js +58 -0
- package/dist/runtime/lib/streams/consumeEventStream.d.ts +4 -0
- package/dist/runtime/lib/streams/consumeEventStream.js +13 -0
- package/dist/runtime/lib/turnstile/TurnstileScript.d.ts +1 -0
- package/dist/runtime/lib/turnstile/TurnstileScript.js +2 -0
- package/dist/runtime/lib/turnstile/turnstile.d.ts +3 -0
- package/dist/runtime/lib/turnstile/turnstile.js +3 -0
- package/dist/runtime/lib/turnstile/useTurnstile.d.ts +4 -0
- package/dist/runtime/lib/turnstile/useTurnstile.js +23 -0
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.d.ts +4 -0
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.js +15 -0
- package/dist/runtime/lib/utils.d.ts +1 -0
- package/dist/runtime/lib/utils.js +1 -0
- package/dist/runtime/register/client.d.ts +1 -0
- package/dist/runtime/register/client.js +5 -0
- package/dist/runtime/register/ssr.d.ts +3 -0
- package/dist/runtime/register/ssr.js +26 -0
- package/dist/runtime/register/worker.d.ts +4 -0
- package/dist/runtime/register/worker.js +42 -0
- package/dist/runtime/render/createClientManifest.d.ts +1 -0
- package/dist/runtime/render/createClientManifest.js +7 -0
- package/dist/runtime/render/createModuleMap.d.ts +1 -0
- package/dist/runtime/render/createModuleMap.js +13 -0
- package/dist/runtime/render/injectRSCPayload.d.ts +3 -0
- package/dist/runtime/render/injectRSCPayload.js +79 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.d.ts +9 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.js +49 -0
- package/dist/runtime/render/renderToRscStream.d.ts +5 -0
- package/dist/runtime/render/renderToRscStream.js +46 -0
- package/dist/runtime/render/renderToStream.d.ts +9 -0
- package/dist/runtime/render/renderToStream.js +27 -0
- package/dist/runtime/render/renderToString.d.ts +7 -0
- package/dist/runtime/render/renderToString.js +26 -0
- package/dist/runtime/render/transformRscToHtmlStream.d.ts +8 -0
- package/dist/runtime/render/transformRscToHtmlStream.js +19 -0
- package/dist/runtime/requestInfo/types.d.ts +11 -0
- package/dist/runtime/requestInfo/types.js +1 -0
- package/dist/runtime/requestInfo/worker.d.ts +5 -0
- package/dist/runtime/requestInfo/worker.js +33 -0
- package/dist/runtime/script.d.ts +5 -0
- package/dist/runtime/script.js +8 -0
- package/dist/runtime/ssrBridge.d.ts +2 -0
- package/dist/runtime/ssrBridge.js +11 -0
- package/dist/runtime/worker.d.ts +18 -0
- package/dist/runtime/worker.js +173 -0
- package/dist/scripts/__sdk.d.mts +1 -0
- package/dist/scripts/__sdk.mjs +14 -0
- package/dist/scripts/build-vendor-bundles.d.mts +1 -0
- package/dist/scripts/build-vendor-bundles.mjs +92 -0
- package/dist/scripts/debug-sync.d.mts +6 -0
- package/dist/scripts/debug-sync.mjs +224 -0
- package/dist/scripts/dev-init.d.mts +1 -0
- package/dist/scripts/dev-init.mjs +25 -0
- package/dist/scripts/ensure-deploy-env.d.mts +1 -0
- package/dist/scripts/ensure-deploy-env.mjs +271 -0
- package/dist/scripts/ensure-env.d.mts +1 -0
- package/dist/scripts/ensure-env.mjs +9 -0
- package/dist/scripts/migrate-new.d.mts +1 -0
- package/dist/scripts/migrate-new.mjs +51 -0
- package/dist/scripts/smoke-test.d.mts +1 -0
- package/dist/scripts/smoke-test.mjs +166 -0
- package/dist/scripts/worker-run.d.mts +1 -0
- package/dist/scripts/worker-run.mjs +82 -0
- package/dist/vite/aliasByEnvPlugin.d.mts +2 -0
- package/dist/vite/aliasByEnvPlugin.mjs +11 -0
- package/dist/vite/asyncSetupPlugin.d.mts +6 -0
- package/dist/vite/asyncSetupPlugin.mjs +23 -0
- package/dist/vite/checkIsUsingPrisma.d.mts +6 -0
- package/dist/vite/checkIsUsingPrisma.mjs +18 -0
- package/dist/vite/configPlugin.d.mts +9 -0
- package/dist/vite/configPlugin.mjs +169 -0
- package/dist/vite/copyPrismaWasmPlugin.d.mts +4 -0
- package/dist/vite/copyPrismaWasmPlugin.mjs +32 -0
- package/dist/vite/createDirectiveLookupPlugin.d.mts +21 -0
- package/dist/vite/createDirectiveLookupPlugin.mjs +231 -0
- package/dist/vite/customReactBuildPlugin.d.mts +4 -0
- package/dist/vite/customReactBuildPlugin.mjs +61 -0
- package/dist/vite/devServerTimingPlugin.d.mts +2 -0
- package/dist/vite/devServerTimingPlugin.mjs +24 -0
- package/dist/vite/directivesPlugin.d.mts +6 -0
- package/dist/vite/directivesPlugin.mjs +200 -0
- package/dist/vite/ensureAliasArray.d.mts +2 -0
- package/dist/vite/ensureAliasArray.mjs +17 -0
- package/dist/vite/findSpecifiers.d.mts +31 -0
- package/dist/vite/findSpecifiers.mjs +230 -0
- package/dist/vite/findSsrSpecifiers.d.mts +11 -0
- package/dist/vite/findSsrSpecifiers.mjs +67 -0
- package/dist/vite/hasDirective.d.mts +7 -0
- package/dist/vite/hasDirective.mjs +54 -0
- package/dist/vite/hasOwnCloudflareVitePlugin.d.mts +3 -0
- package/dist/vite/hasOwnCloudflareVitePlugin.mjs +14 -0
- package/dist/vite/index.d.mts +1 -0
- package/dist/vite/index.mjs +1 -0
- package/dist/vite/injectHmrPreambleJsxPlugin.d.mts +2 -0
- package/dist/vite/injectHmrPreambleJsxPlugin.mjs +22 -0
- package/dist/vite/injectVitePreamblePlugin.d.mts +4 -0
- package/dist/vite/injectVitePreamblePlugin.mjs +23 -0
- package/dist/vite/invalidateCacheIfPrismaClientChanged.d.mts +3 -0
- package/dist/vite/invalidateCacheIfPrismaClientChanged.mjs +27 -0
- package/dist/vite/invalidateModule.d.mts +6 -0
- package/dist/vite/invalidateModule.mjs +30 -0
- package/dist/vite/miniflareHMRPlugin.d.mts +10 -0
- package/dist/vite/miniflareHMRPlugin.mjs +209 -0
- package/dist/vite/miniflarePlugin.d.mts +9 -0
- package/dist/vite/miniflarePlugin.mjs +135 -0
- package/dist/vite/moveStaticAssetsPlugin.d.mts +4 -0
- package/dist/vite/moveStaticAssetsPlugin.mjs +12 -0
- package/dist/vite/normalizeModulePath.d.mts +1 -0
- package/dist/vite/normalizeModulePath.mjs +13 -0
- package/dist/vite/prismaPlugin.d.mts +4 -0
- package/dist/vite/prismaPlugin.mjs +43 -0
- package/dist/vite/reactConditionsResolverPlugin.d.mts +16 -0
- package/dist/vite/reactConditionsResolverPlugin.mjs +179 -0
- package/dist/vite/redwoodPlugin.d.mts +12 -0
- package/dist/vite/redwoodPlugin.mjs +105 -0
- package/dist/vite/requestUtils.d.mts +6 -0
- package/dist/vite/requestUtils.mjs +35 -0
- package/dist/vite/setupEnvFiles.d.mts +4 -0
- package/dist/vite/setupEnvFiles.mjs +31 -0
- package/dist/vite/ssrBridgePlugin.d.mts +7 -0
- package/dist/vite/ssrBridgePlugin.mjs +137 -0
- package/dist/vite/transformClientComponents.d.mts +12 -0
- package/dist/vite/transformClientComponents.mjs +116 -0
- package/dist/vite/transformClientComponents.test.d.mts +1 -0
- package/dist/vite/transformClientComponents.test.mjs +264 -0
- package/dist/vite/transformJsxScriptTagsPlugin.d.mts +8 -0
- package/dist/vite/transformJsxScriptTagsPlugin.mjs +315 -0
- package/dist/vite/transformJsxScriptTagsPlugin.test.d.mts +1 -0
- package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +334 -0
- package/dist/vite/transformServerFunctions.d.mts +16 -0
- package/dist/vite/transformServerFunctions.mjs +296 -0
- package/dist/vite/transformServerFunctions.test.d.mts +1 -0
- package/dist/vite/transformServerFunctions.test.mjs +124 -0
- package/dist/vite/useClientLookupPlugin.d.mts +5 -0
- package/dist/vite/useClientLookupPlugin.mjs +15 -0
- package/dist/vite/useClientPlugin.d.mts +8 -0
- package/dist/vite/useClientPlugin.mjs +295 -0
- package/dist/vite/useClientPlugin.test.d.mts +1 -0
- package/dist/vite/useClientPlugin.test.mjs +1204 -0
- package/dist/vite/useServerLookupPlugin.d.mts +5 -0
- package/dist/vite/useServerLookupPlugin.mjs +15 -0
- package/dist/vite/useServerPlugin.d.mts +1 -0
- package/dist/vite/useServerPlugin.mjs +1 -0
- package/dist/vite/virtualPlugin.d.mts +2 -0
- package/dist/vite/virtualPlugin.mjs +18 -0
- package/dist/vite/vitePreamblePlugin.d.mts +1 -0
- package/dist/vite/vitePreamblePlugin.mjs +11 -0
- package/dist/worker/__ssr_bridge.js +8947 -0
- package/dist/worker/__ssr_bridge.js.map +1 -0
- package/package.json +1 -1
- package/dist/vite/invalidateClientModule.d.mts +0 -2
- package/dist/vite/invalidateClientModule.mjs +0 -8
- package/dist/vite/invalidateModule copy.d.mts +0 -2
- package/dist/vite/invalidateModule copy.mjs +0 -14
- package/dist/vite/invalidateSSRModule.d.mts +0 -2
- package/dist/vite/invalidateSSRModule.mjs +0 -7
- package/dist/vite/mode.d.mts +0 -5
- package/dist/vite/mode.mjs +0 -25
- package/dist/vite/modePlugin.d.mts +0 -2
- package/dist/vite/modePlugin.mjs +0 -10
- /package/dist/vite/{isJsFile.d.ts → isJsFile.d.mts} +0 -0
- /package/dist/vite/{isJsFile.js → isJsFile.mjs} +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import debug from "../debug";
|
|
2
|
+
import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler, } from "kysely";
|
|
3
|
+
const log = debug("sdk:db:do-worker-dialect");
|
|
4
|
+
export class DOWorkerDialect {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.config = config;
|
|
7
|
+
}
|
|
8
|
+
createAdapter() {
|
|
9
|
+
return new SqliteAdapter();
|
|
10
|
+
}
|
|
11
|
+
createDriver() {
|
|
12
|
+
return new DOWorkerDriver(this.config);
|
|
13
|
+
}
|
|
14
|
+
createQueryCompiler() {
|
|
15
|
+
return new SqliteQueryCompiler();
|
|
16
|
+
}
|
|
17
|
+
createIntrospector(db) {
|
|
18
|
+
return new SqliteIntrospector(db);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class DOWorkerDriver {
|
|
22
|
+
constructor(config) {
|
|
23
|
+
this.config = config;
|
|
24
|
+
}
|
|
25
|
+
async init() { }
|
|
26
|
+
async acquireConnection() {
|
|
27
|
+
return new DOWorkerConnection(this.config.stub.kyselyExecuteQuery);
|
|
28
|
+
}
|
|
29
|
+
async beginTransaction(conn) {
|
|
30
|
+
return await conn.beginTransaction();
|
|
31
|
+
}
|
|
32
|
+
async commitTransaction(conn) {
|
|
33
|
+
return await conn.commitTransaction();
|
|
34
|
+
}
|
|
35
|
+
async rollbackTransaction(conn) {
|
|
36
|
+
return await conn.rollbackTransaction();
|
|
37
|
+
}
|
|
38
|
+
async releaseConnection(_conn) { }
|
|
39
|
+
async destroy() { }
|
|
40
|
+
}
|
|
41
|
+
class DOWorkerConnection {
|
|
42
|
+
constructor(executeQuery) {
|
|
43
|
+
this._executeQuery = executeQuery;
|
|
44
|
+
}
|
|
45
|
+
async executeQuery(compiledQuery) {
|
|
46
|
+
log("Forwarding query to Durable Object: %s", compiledQuery.sql);
|
|
47
|
+
// Call the DO's kyselyExecuteQuery method
|
|
48
|
+
const result = await this._executeQuery({
|
|
49
|
+
sql: compiledQuery.sql,
|
|
50
|
+
parameters: compiledQuery.parameters,
|
|
51
|
+
});
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
async beginTransaction() {
|
|
55
|
+
throw new Error("Transactions are not supported yet.");
|
|
56
|
+
}
|
|
57
|
+
async commitTransaction() {
|
|
58
|
+
throw new Error("Transactions are not supported yet.");
|
|
59
|
+
}
|
|
60
|
+
async rollbackTransaction() {
|
|
61
|
+
throw new Error("Transactions are not supported yet.");
|
|
62
|
+
}
|
|
63
|
+
async *streamQuery(_compiledQuery, _chunkSize) {
|
|
64
|
+
throw new Error("DO Driver does not support streaming");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DurableObject } from "cloudflare:workers";
|
|
2
|
+
import { Kysely, QueryResult } from "kysely";
|
|
3
|
+
export declare class SqliteDurableObject<T = any> extends DurableObject {
|
|
4
|
+
migrations: Record<string, any>;
|
|
5
|
+
kysely: Kysely<T>;
|
|
6
|
+
private initialized;
|
|
7
|
+
private migrationTableName;
|
|
8
|
+
constructor(ctx: DurableObjectState, env: any, migrations: Record<string, any>, migrationTableName?: string);
|
|
9
|
+
initialize(): Promise<void>;
|
|
10
|
+
kyselyExecuteQuery<R>(compiledQuery: {
|
|
11
|
+
sql: string;
|
|
12
|
+
parameters: readonly unknown[];
|
|
13
|
+
}): Promise<QueryResult<R>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DODialect } from "kysely-do";
|
|
2
|
+
import { DurableObject } from "cloudflare:workers";
|
|
3
|
+
import { Kysely } from "kysely";
|
|
4
|
+
import { createMigrator } from "./index.js";
|
|
5
|
+
import debug from "../debug.js";
|
|
6
|
+
const log = debug("sdk:do-db");
|
|
7
|
+
// Base class for Durable Objects that need Kysely database access
|
|
8
|
+
export class SqliteDurableObject extends DurableObject {
|
|
9
|
+
constructor(ctx, env, migrations, migrationTableName = "__migrations") {
|
|
10
|
+
super(ctx, env);
|
|
11
|
+
this.initialized = false;
|
|
12
|
+
this.migrations = migrations;
|
|
13
|
+
this.migrationTableName = migrationTableName;
|
|
14
|
+
this.kysely = new Kysely({
|
|
15
|
+
dialect: new DODialect({ ctx }),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async initialize() {
|
|
19
|
+
if (this.initialized) {
|
|
20
|
+
log("Database already initialized, skipping");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
log("Initializing Durable Object database");
|
|
24
|
+
const migrator = createMigrator(this.kysely, this.migrations, this.migrationTableName);
|
|
25
|
+
await migrator.migrateToLatest();
|
|
26
|
+
this.initialized = true;
|
|
27
|
+
log("Database initialization complete");
|
|
28
|
+
}
|
|
29
|
+
// RPC method for executing queries - must be on prototype for RPC to work
|
|
30
|
+
async kyselyExecuteQuery(compiledQuery) {
|
|
31
|
+
await this.initialize();
|
|
32
|
+
log("Executing SQL: %s with params: %o", compiledQuery.sql, compiledQuery.parameters);
|
|
33
|
+
// Forward to the internal Kysely database
|
|
34
|
+
const result = await this.kysely.executeQuery({
|
|
35
|
+
sql: compiledQuery.sql,
|
|
36
|
+
parameters: compiledQuery.parameters,
|
|
37
|
+
query: {},
|
|
38
|
+
queryId: {},
|
|
39
|
+
});
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Kysely } from "kysely";
|
|
2
|
+
import { requestInfo } from "../../requestInfo/worker.js";
|
|
3
|
+
import { DOWorkerDialect } from "./DOWorkerDialect.js";
|
|
4
|
+
const createDurableObjectDb = (durableObjectBinding, name = "main") => {
|
|
5
|
+
const durableObjectId = durableObjectBinding.idFromName(name);
|
|
6
|
+
const stub = durableObjectBinding.get(durableObjectId);
|
|
7
|
+
stub.initialize();
|
|
8
|
+
return new Kysely({
|
|
9
|
+
dialect: new DOWorkerDialect({ stub }),
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export function createDb(durableObjectBinding, name = "main") {
|
|
13
|
+
const cacheKey = `${durableObjectBinding}_${name}`;
|
|
14
|
+
const doCreateDb = () => {
|
|
15
|
+
let db = requestInfo.rw.databases.get(cacheKey);
|
|
16
|
+
if (!db) {
|
|
17
|
+
db = createDurableObjectDb(durableObjectBinding, name);
|
|
18
|
+
requestInfo.rw.databases.set(cacheKey, db);
|
|
19
|
+
}
|
|
20
|
+
return db;
|
|
21
|
+
};
|
|
22
|
+
doCreateDb();
|
|
23
|
+
return new Proxy({}, {
|
|
24
|
+
get(target, prop, receiver) {
|
|
25
|
+
const db = doCreateDb();
|
|
26
|
+
const value = db[prop];
|
|
27
|
+
if (typeof value === "function") {
|
|
28
|
+
return value.bind(db);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Kysely, Migration, Migrator, MigrationProvider } from "kysely";
|
|
2
|
+
/**
|
|
3
|
+
* A custom MigrationProvider that works with in-memory migrations
|
|
4
|
+
* rather than reading from files.
|
|
5
|
+
*/
|
|
6
|
+
export declare class InMemoryMigrationProvider implements MigrationProvider {
|
|
7
|
+
private migrations;
|
|
8
|
+
constructor(migrations: Record<string, Migration>);
|
|
9
|
+
getMigrations(): Promise<Record<string, Migration>>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Helper function to create a migrator using Kysely's built-in Migrator.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const migrator = createMigrator(db, migrations, "__my_migrations");
|
|
17
|
+
* const result = await migrator.migrateToLatest();
|
|
18
|
+
* if (result.error) {
|
|
19
|
+
* throw new Error(`Migration failed: ${result.error}`);
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function createMigrator(db: Kysely<any>, migrations: Record<string, Migration>, migrationTableName?: string): Migrator;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Migrator } from "kysely";
|
|
2
|
+
/**
|
|
3
|
+
* A custom MigrationProvider that works with in-memory migrations
|
|
4
|
+
* rather than reading from files.
|
|
5
|
+
*/
|
|
6
|
+
export class InMemoryMigrationProvider {
|
|
7
|
+
constructor(migrations) {
|
|
8
|
+
this.migrations = migrations;
|
|
9
|
+
}
|
|
10
|
+
async getMigrations() {
|
|
11
|
+
return this.migrations;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Helper function to create a migrator using Kysely's built-in Migrator.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const migrator = createMigrator(db, migrations, "__my_migrations");
|
|
20
|
+
* const result = await migrator.migrateToLatest();
|
|
21
|
+
* if (result.error) {
|
|
22
|
+
* throw new Error(`Migration failed: ${result.error}`);
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function createMigrator(db, migrations, migrationTableName = "__rwsdk_migrations") {
|
|
27
|
+
return new Migrator({
|
|
28
|
+
db,
|
|
29
|
+
provider: new InMemoryMigrationProvider(migrations),
|
|
30
|
+
migrationTableName,
|
|
31
|
+
// Use a custom lock table name based on the migration table name
|
|
32
|
+
migrationLockTableName: `${migrationTableName}_lock`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AlterColumnNode } from "kysely";
|
|
2
|
+
import { Alteration } from "../utils";
|
|
3
|
+
export interface AlteredColumnBuilder<TAlteration extends Alteration> {
|
|
4
|
+
readonly __alteration: TAlteration;
|
|
5
|
+
toOperationNode(): AlterColumnNode;
|
|
6
|
+
}
|
|
7
|
+
export interface AlterColumnBuilder {
|
|
8
|
+
setDataType<T extends string>(dataType: T): AlteredColumnBuilder<{
|
|
9
|
+
kind: "setDataType";
|
|
10
|
+
dataType: T;
|
|
11
|
+
}>;
|
|
12
|
+
setDefault<T>(value: T): AlteredColumnBuilder<{
|
|
13
|
+
kind: "setDefault";
|
|
14
|
+
value: T;
|
|
15
|
+
}>;
|
|
16
|
+
dropDefault(): AlteredColumnBuilder<{
|
|
17
|
+
kind: "dropDefault";
|
|
18
|
+
}>;
|
|
19
|
+
setNotNull(): AlteredColumnBuilder<{
|
|
20
|
+
kind: "setNotNull";
|
|
21
|
+
}>;
|
|
22
|
+
dropNotNull(): AlteredColumnBuilder<{
|
|
23
|
+
kind: "dropNotNull";
|
|
24
|
+
}>;
|
|
25
|
+
$call<T>(func: (qb: this) => T): T;
|
|
26
|
+
}
|
|
27
|
+
export type AlterColumnBuilderCallback = (builder: AlterColumnBuilder) => AlteredColumnBuilder<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SqlToTsType, ExecutedBuilder, AlterOperation, AddColumnOp, DropColumnOp, RenameColumnOp, AlterColumnOp, ModifyColumnOp } from "../utils";
|
|
2
|
+
import { ColumnDefinitionBuilder } from "./columnDefinition";
|
|
3
|
+
import { AlterColumnBuilderCallback } from "./alterColumn";
|
|
4
|
+
import { ForeignKeyConstraintBuilder, Expression, CheckConstraintNode, UniqueConstraintNode, PrimaryKeyConstraintNode, sql } from "kysely";
|
|
5
|
+
type DataTypeExpression = string | typeof sql;
|
|
6
|
+
interface CheckConstraintBuilder {
|
|
7
|
+
$call<T>(func: (qb: this) => T): T;
|
|
8
|
+
toOperationNode(): CheckConstraintNode;
|
|
9
|
+
}
|
|
10
|
+
interface UniqueConstraintBuilder {
|
|
11
|
+
nullsNotDistinct(): UniqueConstraintBuilder;
|
|
12
|
+
deferrable(): UniqueConstraintBuilder;
|
|
13
|
+
notDeferrable(): UniqueConstraintBuilder;
|
|
14
|
+
initiallyDeferred(): UniqueConstraintBuilder;
|
|
15
|
+
initiallyImmediate(): UniqueConstraintBuilder;
|
|
16
|
+
$call<T>(func: (qb: this) => T): T;
|
|
17
|
+
toOperationNode(): UniqueConstraintNode;
|
|
18
|
+
}
|
|
19
|
+
interface PrimaryKeyConstraintBuilder {
|
|
20
|
+
deferrable(): PrimaryKeyConstraintBuilder;
|
|
21
|
+
notDeferrable(): PrimaryKeyConstraintBuilder;
|
|
22
|
+
initiallyDeferred(): PrimaryKeyConstraintBuilder;
|
|
23
|
+
initiallyImmediate(): PrimaryKeyConstraintBuilder;
|
|
24
|
+
$call<T>(func: (qb: this) => T): T;
|
|
25
|
+
toOperationNode(): PrimaryKeyConstraintNode;
|
|
26
|
+
}
|
|
27
|
+
export interface AlterTableBuilder<TName extends string, TOps extends AlterOperation[] = []> {
|
|
28
|
+
readonly __tableName: TName;
|
|
29
|
+
readonly __operations: TOps;
|
|
30
|
+
renameTo<TNewName extends string>(newTableName: TNewName): AlterTableBuilder<TNewName, TOps> & {
|
|
31
|
+
readonly __renamedFrom: TName;
|
|
32
|
+
};
|
|
33
|
+
setSchema(newSchema: string): AlterTableBuilder<TName, TOps>;
|
|
34
|
+
addColumn<K extends string, T extends DataTypeExpression>(name: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): AlterTableBuilder<TName, [...TOps, AddColumnOp<K, T>]>;
|
|
35
|
+
dropColumn<K extends string>(name: K): AlterTableBuilder<TName, [...TOps, DropColumnOp<K>]>;
|
|
36
|
+
renameColumn<KFrom extends string, KTo extends string>(from: KFrom, to: KTo): AlterTableBuilder<TName, [...TOps, RenameColumnOp<KFrom, KTo>]>;
|
|
37
|
+
alterColumn<K extends string, const TCallback extends AlterColumnBuilderCallback>(column: K, alteration: TCallback): AlterTableBuilder<TName, [
|
|
38
|
+
...TOps,
|
|
39
|
+
AlterColumnOp<K, ReturnType<TCallback>["__alteration"]>
|
|
40
|
+
]>;
|
|
41
|
+
modifyColumn<K extends string, T extends DataTypeExpression>(column: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): AlterTableBuilder<TName, [...TOps, ModifyColumnOp<K, T>]>;
|
|
42
|
+
addUniqueConstraint(constraintName: string, columns: string[], build?: (builder: UniqueConstraintBuilder) => UniqueConstraintBuilder): AlterTableBuilder<TName, TOps>;
|
|
43
|
+
addPrimaryKeyConstraint(constraintName: string, columns: string[], build?: (builder: PrimaryKeyConstraintBuilder) => PrimaryKeyConstraintBuilder): AlterTableBuilder<TName, TOps>;
|
|
44
|
+
addCheckConstraint(constraintName: string, checkExpression: Expression<any>, build?: (builder: CheckConstraintBuilder) => CheckConstraintBuilder): AlterTableBuilder<TName, TOps>;
|
|
45
|
+
addForeignKeyConstraint(constraintName: string, columns: string[], targetTable: string, targetColumns: string[], build?: (builder: ForeignKeyConstraintBuilder) => ForeignKeyConstraintBuilder): AlterTableBuilder<TName, TOps>;
|
|
46
|
+
dropConstraint(constraintName: string): AlterTableBuilder<TName, TOps>;
|
|
47
|
+
renameConstraint(oldName: string, newName: string): AlterTableBuilder<TName, TOps>;
|
|
48
|
+
addIndex(indexName: string): AlterTableBuilder<TName, TOps>;
|
|
49
|
+
dropIndex(indexName: string): AlterTableBuilder<TName, TOps>;
|
|
50
|
+
execute(): Promise<ExecutedBuilder<this>>;
|
|
51
|
+
$call<T>(func: (qb: this) => T): T;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Expression, sql, ColumnDefinitionNode } from "kysely";
|
|
2
|
+
type DefaultValueExpression = string | number | boolean | null | typeof sql;
|
|
3
|
+
export interface ColumnDefinitionBuilder<TType> {
|
|
4
|
+
autoIncrement(): ColumnDefinitionBuilder<TType>;
|
|
5
|
+
identity(): ColumnDefinitionBuilder<TType>;
|
|
6
|
+
primaryKey(): ColumnDefinitionBuilder<TType>;
|
|
7
|
+
references(ref: string): ColumnDefinitionBuilder<TType>;
|
|
8
|
+
onDelete(onDelete: "no action" | "restrict" | "cascade" | "set null" | "set default"): ColumnDefinitionBuilder<TType>;
|
|
9
|
+
onUpdate(onUpdate: "no action" | "restrict" | "cascade" | "set null" | "set default"): ColumnDefinitionBuilder<TType>;
|
|
10
|
+
unique(): ColumnDefinitionBuilder<TType>;
|
|
11
|
+
notNull(): ColumnDefinitionBuilder<TType>;
|
|
12
|
+
unsigned(): ColumnDefinitionBuilder<TType>;
|
|
13
|
+
defaultTo(value: DefaultValueExpression): ColumnDefinitionBuilder<TType>;
|
|
14
|
+
check(expression: Expression<any>): ColumnDefinitionBuilder<TType>;
|
|
15
|
+
generatedAlwaysAs(expression: Expression<any>): ColumnDefinitionBuilder<TType>;
|
|
16
|
+
generatedAlwaysAsIdentity(): ColumnDefinitionBuilder<TType>;
|
|
17
|
+
generatedByDefaultAsIdentity(): ColumnDefinitionBuilder<TType>;
|
|
18
|
+
stored(): ColumnDefinitionBuilder<TType>;
|
|
19
|
+
modifyFront(modifier: Expression<any>): ColumnDefinitionBuilder<TType>;
|
|
20
|
+
nullsNotDistinct(): ColumnDefinitionBuilder<TType>;
|
|
21
|
+
ifNotExists(): ColumnDefinitionBuilder<TType>;
|
|
22
|
+
modifyEnd(modifier: Expression<any>): ColumnDefinitionBuilder<TType>;
|
|
23
|
+
$call<T>(func: (qb: this) => T): T;
|
|
24
|
+
toOperationNode(): ColumnDefinitionNode;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SqlToTsType, ExecutedBuilder, Prettify } from "../utils";
|
|
2
|
+
import { ColumnDefinitionBuilder } from "./columnDefinition";
|
|
3
|
+
import { CompiledQuery, CreateTableNode, Expression, ForeignKeyConstraintBuilder, CheckConstraintNode, UniqueConstraintNode, PrimaryKeyConstraintNode } from "kysely";
|
|
4
|
+
interface CheckConstraintBuilder {
|
|
5
|
+
$call<T>(func: (qb: this) => T): T;
|
|
6
|
+
toOperationNode(): CheckConstraintNode;
|
|
7
|
+
}
|
|
8
|
+
interface UniqueConstraintBuilder {
|
|
9
|
+
nullsNotDistinct(): UniqueConstraintBuilder;
|
|
10
|
+
deferrable(): UniqueConstraintBuilder;
|
|
11
|
+
notDeferrable(): UniqueConstraintBuilder;
|
|
12
|
+
initiallyDeferred(): UniqueConstraintBuilder;
|
|
13
|
+
initiallyImmediate(): UniqueConstraintBuilder;
|
|
14
|
+
$call<T>(func: (qb: this) => T): T;
|
|
15
|
+
toOperationNode(): UniqueConstraintNode;
|
|
16
|
+
}
|
|
17
|
+
interface PrimaryKeyConstraintBuilder {
|
|
18
|
+
deferrable(): PrimaryKeyConstraintBuilder;
|
|
19
|
+
notDeferrable(): PrimaryKeyConstraintBuilder;
|
|
20
|
+
initiallyDeferred(): PrimaryKeyConstraintBuilder;
|
|
21
|
+
initiallyImmediate(): PrimaryKeyConstraintBuilder;
|
|
22
|
+
$call<T>(func: (qb: this) => T): T;
|
|
23
|
+
toOperationNode(): PrimaryKeyConstraintNode;
|
|
24
|
+
}
|
|
25
|
+
export interface CreateTableBuilder<TName extends string, TSchema extends Record<string, any> = {}> {
|
|
26
|
+
readonly __tableName: TName;
|
|
27
|
+
readonly __addedColumns: TSchema;
|
|
28
|
+
temporary(): CreateTableBuilder<TName, TSchema>;
|
|
29
|
+
onCommit(onCommit: "preserve rows" | "delete rows" | "drop"): CreateTableBuilder<TName, TSchema>;
|
|
30
|
+
ifNotExists(): CreateTableBuilder<TName, TSchema>;
|
|
31
|
+
addColumn<K extends string, T extends string>(name: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): CreateTableBuilder<TName, Prettify<(TSchema extends Record<string, any> ? TSchema : {}) & Record<K, SqlToTsType<T>>>>;
|
|
32
|
+
addUniqueConstraint(constraintName: string, columns: (keyof TSchema)[], build?: (builder: UniqueConstraintBuilder) => UniqueConstraintBuilder): CreateTableBuilder<TName, TSchema>;
|
|
33
|
+
addPrimaryKeyConstraint(constraintName: string, columns: (keyof TSchema)[], build?: (builder: PrimaryKeyConstraintBuilder) => PrimaryKeyConstraintBuilder): CreateTableBuilder<TName, TSchema>;
|
|
34
|
+
addCheckConstraint(constraintName: string, checkExpression: Expression<any>, build?: (builder: CheckConstraintBuilder) => CheckConstraintBuilder): CreateTableBuilder<TName, TSchema>;
|
|
35
|
+
addForeignKeyConstraint(constraintName: string, columns: (keyof TSchema)[], targetTable: string, targetColumns: string[], build?: (builder: ForeignKeyConstraintBuilder) => ForeignKeyConstraintBuilder): CreateTableBuilder<TName, TSchema>;
|
|
36
|
+
modifyFront(modifier: Expression<any>): CreateTableBuilder<TName, TSchema>;
|
|
37
|
+
modifyEnd(modifier: Expression<any>): CreateTableBuilder<TName, TSchema>;
|
|
38
|
+
as(expression: Expression<any>): CreateTableBuilder<TName, TSchema>;
|
|
39
|
+
execute(): Promise<ExecutedBuilder<this>>;
|
|
40
|
+
$call<T>(func: (qb: this) => T): T;
|
|
41
|
+
compile(): CompiledQuery;
|
|
42
|
+
toOperationNode(): CreateTableNode;
|
|
43
|
+
withSchema(schema: string): CreateTableBuilder<TName, TSchema>;
|
|
44
|
+
ownerTo(owner: string): CreateTableBuilder<TName, TSchema>;
|
|
45
|
+
replace(): CreateTableBuilder<TName, TSchema>;
|
|
46
|
+
ignore(): CreateTableBuilder<TName, TSchema>;
|
|
47
|
+
withoutTableConstraintValidation(): CreateTableBuilder<TName, TSchema>;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ExecutedBuilder } from "../utils";
|
|
2
|
+
import { CreateViewNode, CompiledQuery, SelectQueryBuilder, RawBuilder } from "kysely";
|
|
3
|
+
export interface CreateViewBuilder<TName extends string, TSchema extends Record<string, any> = {}, TColumns extends string[] = []> {
|
|
4
|
+
readonly __viewName: TName;
|
|
5
|
+
readonly __schema: TSchema;
|
|
6
|
+
readonly __columns: TColumns;
|
|
7
|
+
temporary(): CreateViewBuilder<TName, TSchema, TColumns>;
|
|
8
|
+
orReplace(): CreateViewBuilder<TName, TSchema, TColumns>;
|
|
9
|
+
ifNotExists(): CreateViewBuilder<TName, TSchema, TColumns>;
|
|
10
|
+
columns<C extends string[]>(columns: C): CreateViewBuilder<TName, TSchema, C>;
|
|
11
|
+
as(query: SelectQueryBuilder<any, any, any> | RawBuilder<any>): CreateViewBuilder<TName, TSchema, TColumns>;
|
|
12
|
+
execute(): Promise<ExecutedBuilder<this>>;
|
|
13
|
+
toOperationNode(): CreateViewNode;
|
|
14
|
+
compile(): CompiledQuery;
|
|
15
|
+
$call<T>(func: (qb: this) => T): T;
|
|
16
|
+
materialized(): CreateViewBuilder<TName, TSchema, TColumns>;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExecutedBuilder } from "../utils";
|
|
2
|
+
import { DropTableNode, CompiledQuery } from "kysely";
|
|
3
|
+
export interface DropTableBuilder<TName extends string> {
|
|
4
|
+
readonly __tableName: TName;
|
|
5
|
+
ifExists(): DropTableBuilder<TName>;
|
|
6
|
+
cascade(): DropTableBuilder<TName>;
|
|
7
|
+
execute(): Promise<ExecutedBuilder<this>>;
|
|
8
|
+
toOperationNode(): DropTableNode;
|
|
9
|
+
compile(): CompiledQuery;
|
|
10
|
+
$call<T>(func: (qb: this) => T): T;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExecutedBuilder } from "../utils";
|
|
2
|
+
import { DropViewNode, CompiledQuery } from "kysely";
|
|
3
|
+
export interface DropViewBuilder<TName extends string> {
|
|
4
|
+
readonly __viewName: TName;
|
|
5
|
+
ifExists(): DropViewBuilder<TName>;
|
|
6
|
+
cascade(): DropViewBuilder<TName>;
|
|
7
|
+
execute(): Promise<ExecutedBuilder<this>>;
|
|
8
|
+
toOperationNode(): DropViewNode;
|
|
9
|
+
compile(): CompiledQuery;
|
|
10
|
+
$call<T>(func: (qb: this) => T): T;
|
|
11
|
+
materialized(): DropViewBuilder<TName>;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CreateTableBuilder } from "./createTable";
|
|
2
|
+
import { AlterTableBuilder } from "./alterTable";
|
|
3
|
+
import { DropTableBuilder } from "./dropTable";
|
|
4
|
+
import { CreateViewBuilder } from "./createView";
|
|
5
|
+
import { DropViewBuilder } from "./dropView";
|
|
6
|
+
import { CreateIndexBuilder, DropIndexBuilder, CreateSchemaBuilder, DropSchemaBuilder, CreateTypeBuilder, DropTypeBuilder, KyselyPlugin, RefreshMaterializedViewBuilder } from "kysely";
|
|
7
|
+
export interface SchemaBuilder {
|
|
8
|
+
createTable<TName extends string>(name: TName): CreateTableBuilder<TName, {}>;
|
|
9
|
+
alterTable<TName extends string>(name: TName): AlterTableBuilder<TName, []>;
|
|
10
|
+
dropTable<TName extends string>(name: TName): DropTableBuilder<TName>;
|
|
11
|
+
createView<TName extends string>(name: TName): CreateViewBuilder<TName, never>;
|
|
12
|
+
dropView<TName extends string>(name: TName): DropViewBuilder<TName>;
|
|
13
|
+
withSchema(schema: string): this;
|
|
14
|
+
createIndex(name: string): CreateIndexBuilder;
|
|
15
|
+
dropIndex(name: string): DropIndexBuilder;
|
|
16
|
+
createSchema(name: string): CreateSchemaBuilder;
|
|
17
|
+
dropSchema(name: string): DropSchemaBuilder;
|
|
18
|
+
createType(name: string): CreateTypeBuilder;
|
|
19
|
+
dropType(name: string): DropTypeBuilder;
|
|
20
|
+
refreshMaterializedView(viewName: string): RefreshMaterializedViewBuilder;
|
|
21
|
+
$call<T>(func: (qb: this) => T): T;
|
|
22
|
+
withPlugin(plugin: KyselyPlugin): this;
|
|
23
|
+
withoutPlugins(): this;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Kysely } from "kysely";
|
|
2
|
+
import { ExecutedBuilder, Prettify, ProcessAlteredTable, UnionToTuple } from "./utils";
|
|
3
|
+
import { CreateTableBuilder } from "./builders/createTable";
|
|
4
|
+
import { AlterTableBuilder } from "./builders/alterTable";
|
|
5
|
+
import { DropTableBuilder } from "./builders/dropTable";
|
|
6
|
+
import { SchemaBuilder } from "./builders/schema";
|
|
7
|
+
export interface InferenceBuilder {
|
|
8
|
+
schema: SchemaBuilder;
|
|
9
|
+
}
|
|
10
|
+
export type MigrationBuilder = InferenceBuilder & Kysely<any>;
|
|
11
|
+
export interface Migration<TUpReturn = unknown> {
|
|
12
|
+
up(db: MigrationBuilder): TUpReturn;
|
|
13
|
+
down?(db: Kysely<any>): any;
|
|
14
|
+
}
|
|
15
|
+
export type Migrations = Record<string, Migration>;
|
|
16
|
+
type GetBuilder<T> = T extends ExecutedBuilder<infer B> ? B : never;
|
|
17
|
+
type BuildersFromMigration<TMigration extends Migration> = TMigration extends Migration<infer TUpReturn> ? Awaited<TUpReturn> extends Array<infer Item> ? GetBuilder<Item> : GetBuilder<Awaited<TUpReturn>> : never;
|
|
18
|
+
type ApplyBuilder<TSchema, TBuilder> = TBuilder extends CreateTableBuilder<infer TName, infer TSch> ? Prettify<TSchema & Record<TName, TSch>> : TBuilder extends DropTableBuilder<infer TName> ? Omit<TSchema, TName> : TBuilder extends AlterTableBuilder<infer TName, infer TOps> ? TBuilder extends {
|
|
19
|
+
__renamedFrom: infer From extends string;
|
|
20
|
+
} ? From extends keyof TSchema ? Prettify<Omit<TSchema, From> & Record<TName, ProcessAlteredTable<TSchema[From], TOps>>> : TSchema : TName extends keyof TSchema ? Prettify<Omit<TSchema, TName> & Record<TName, ProcessAlteredTable<TSchema[TName], TOps>>> : TSchema : TSchema;
|
|
21
|
+
type ApplyBuilders<TSchema, TBuildersTuple> = TBuildersTuple extends [
|
|
22
|
+
infer THead,
|
|
23
|
+
...infer TRest
|
|
24
|
+
] ? ApplyBuilders<ApplyBuilder<TSchema, THead>, TRest> : TSchema;
|
|
25
|
+
type ProcessMigrations<TMigrations extends Migrations, TKeys, TSchema = {}> = TKeys extends [infer THeadKey, ...infer TRestKeys] ? THeadKey extends keyof TMigrations ? ProcessMigrations<TMigrations, TRestKeys, ApplyBuilders<TSchema, UnionToTuple<BuildersFromMigration<TMigrations[THeadKey]>>>> : TSchema : TSchema;
|
|
26
|
+
export type Database<TMigrations extends Migrations = Migrations> = ProcessMigrations<TMigrations, UnionToTuple<keyof TMigrations>>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|