effect-start 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ChildProcess.js +32 -20
- package/dist/Commander.js +377 -293
- package/dist/ContentNegotiation.js +424 -318
- package/dist/Cookies.js +340 -271
- package/dist/Development.js +85 -49
- package/dist/Effectify.js +22 -14
- package/dist/Entity.js +260 -195
- package/dist/Fetch.js +192 -0
- package/dist/FilePathPattern.js +88 -77
- package/dist/FileRouter.js +192 -136
- package/dist/FileRouterCodegen.js +262 -191
- package/dist/FileSystem.js +126 -64
- package/dist/Http.js +96 -77
- package/dist/PathPattern.js +311 -273
- package/dist/PlatformError.js +36 -21
- package/dist/PlatformRuntime.js +65 -40
- package/dist/Route.js +122 -79
- package/dist/RouteBody.js +83 -58
- package/dist/RouteError.js +46 -25
- package/dist/RouteHook.js +58 -34
- package/dist/RouteHttp.js +346 -237
- package/dist/RouteHttpTracer.js +86 -58
- package/dist/RouteMount.js +81 -58
- package/dist/RouteSchema.js +253 -170
- package/dist/RouteSse.js +87 -72
- package/dist/RouteTree.js +99 -73
- package/dist/RouteTrie.js +160 -133
- package/dist/SchemaExtra.js +87 -62
- package/dist/Socket.js +32 -21
- package/dist/SqlIntrospect.js +317 -268
- package/dist/Start.js +55 -25
- package/dist/StartApp.js +3 -21
- package/dist/StreamExtra.js +109 -74
- package/dist/System.js +37 -21
- package/dist/TuplePathPattern.js +64 -58
- package/dist/Unique.js +159 -120
- package/dist/Values.js +48 -32
- package/dist/bun/BunBundle.js +158 -109
- package/dist/bun/BunChildProcessSpawner.js +121 -82
- package/dist/bun/BunImportTrackerPlugin.js +85 -63
- package/dist/bun/BunRoute.js +135 -99
- package/dist/bun/BunRuntime.js +39 -29
- package/dist/bun/BunServer.js +268 -140
- package/dist/bun/BunVirtualFilesPlugin.js +47 -33
- package/dist/bun/_BunEnhancedResolve.js +107 -82
- package/dist/bun/index.js +5 -5
- package/dist/bundler/Bundle.js +82 -38
- package/dist/bundler/BundleFiles.js +140 -82
- package/dist/bundler/BundleRoute.js +49 -38
- package/dist/client/Overlay.js +29 -28
- package/dist/client/ScrollState.js +94 -82
- package/dist/client/index.js +79 -61
- package/dist/console/Console.js +40 -24
- package/dist/console/ConsoleErrors.js +189 -178
- package/dist/console/ConsoleLogger.js +52 -43
- package/dist/console/ConsoleMetrics.js +69 -58
- package/dist/console/ConsoleProcess.js +57 -47
- package/dist/console/ConsoleStore.js +56 -45
- package/dist/console/ConsoleTracer.js +101 -88
- package/dist/console/Simulation.js +714 -563
- package/dist/console/index.js +3 -3
- package/dist/console/routes/tree.js +29 -28
- package/dist/datastar/actions/fetch.js +514 -381
- package/dist/datastar/actions/peek.js +12 -12
- package/dist/datastar/actions/setAll.js +18 -11
- package/dist/datastar/actions/toggleAll.js +18 -11
- package/dist/datastar/attributes/attr.js +48 -47
- package/dist/datastar/attributes/bind.js +186 -167
- package/dist/datastar/attributes/class.js +51 -44
- package/dist/datastar/attributes/computed.js +23 -24
- package/dist/datastar/attributes/effect.js +9 -8
- package/dist/datastar/attributes/indicator.js +32 -29
- package/dist/datastar/attributes/init.js +26 -25
- package/dist/datastar/attributes/jsonSignals.js +32 -29
- package/dist/datastar/attributes/on.js +76 -73
- package/dist/datastar/attributes/onIntersect.js +51 -51
- package/dist/datastar/attributes/onInterval.js +30 -29
- package/dist/datastar/attributes/onSignalPatch.js +49 -40
- package/dist/datastar/attributes/ref.js +10 -9
- package/dist/datastar/attributes/show.js +31 -30
- package/dist/datastar/attributes/signals.js +17 -16
- package/dist/datastar/attributes/style.js +56 -49
- package/dist/datastar/attributes/text.js +28 -25
- package/dist/datastar/engine.js +1079 -933
- package/dist/datastar/index.js +25 -24
- package/dist/datastar/utils.js +203 -155
- package/dist/datastar/watchers/patchElements.js +459 -372
- package/dist/datastar/watchers/patchSignals.js +13 -13
- package/dist/experimental/EncryptedCookies.js +305 -189
- package/dist/experimental/index.js +1 -1
- package/dist/hyper/Hyper.js +22 -17
- package/dist/hyper/HyperHtml.js +138 -123
- package/dist/hyper/HyperNode.js +11 -9
- package/dist/hyper/HyperRoute.js +41 -28
- package/dist/hyper/html.js +27 -27
- package/dist/hyper/index.js +5 -5
- package/dist/hyper/jsx-runtime.js +11 -5
- package/dist/index.js +8 -8
- package/dist/node/NodeFileSystem.js +606 -341
- package/dist/node/NodeUtils.js +21 -18
- package/dist/sql/Sql.js +8 -0
- package/dist/sql/bun/index.js +134 -67
- package/dist/sql/index.js +1 -0
- package/dist/sql/libsql/index.js +156 -0
- package/dist/sql/mssql/docker.js +103 -60
- package/dist/sql/mssql/index.js +182 -101
- package/dist/testing/TestLogger.js +39 -29
- package/dist/testing/index.js +2 -2
- package/dist/testing/utils.js +45 -23
- package/dist/x/cloudflare/CloudflareTunnel.js +61 -28
- package/dist/x/cloudflare/index.js +1 -1
- package/dist/x/tailscale/TailscaleTunnel.js +86 -60
- package/dist/x/tailscale/index.js +1 -1
- package/dist/x/tailwind/TailwindPlugin.js +280 -205
- package/dist/x/tailwind/compile.js +185 -129
- package/dist/x/tailwind/plugin.js +13 -11
- package/package.json +1 -1
- package/src/Development.ts +3 -1
- package/src/Entity.ts +17 -0
- package/src/Fetch.ts +271 -0
- package/src/SqlIntrospect.ts +64 -70
- package/src/Start.ts +24 -22
- package/src/StartApp.ts +11 -0
- package/src/bun/BunServer.ts +89 -16
- package/src/hyper/HyperHtml.ts +0 -1
- package/src/sql/bun/index.ts +1 -1
- package/src/sql/index.ts +1 -0
- package/src/sql/libsql/index.ts +173 -0
- package/src/sql/libsql/libsql.d.ts +39 -0
- package/src/sql/mssql/index.ts +1 -1
- package/src/x/tailscale/TailscaleTunnel.ts +7 -5
- package/dist/BlobStore.d.ts +0 -80
- package/dist/BlobStore.js +0 -19
- package/dist/ChildProcess.d.ts +0 -60
- package/dist/Commander.d.ts +0 -100
- package/dist/ContentNegotiation.d.ts +0 -12
- package/dist/Cookies.d.ts +0 -47
- package/dist/Development.d.ts +0 -39
- package/dist/Effectify.d.ts +0 -209
- package/dist/Entity.d.ts +0 -47
- package/dist/FilePathPattern.d.ts +0 -29
- package/dist/FileRouter.d.ts +0 -56
- package/dist/FileRouterCodegen.d.ts +0 -18
- package/dist/FileRouterPattern.d.ts +0 -9
- package/dist/FileRouterPattern.js +0 -35
- package/dist/FileSystem.d.ts +0 -158
- package/dist/Http.d.ts +0 -37
- package/dist/HttpAppExtra.d.ts +0 -7
- package/dist/HttpAppExtra.js +0 -320
- package/dist/HttpUtils.d.ts +0 -3
- package/dist/HttpUtils.js +0 -11
- package/dist/PathPattern.d.ts +0 -134
- package/dist/PlatformError.d.ts +0 -38
- package/dist/PlatformRuntime.d.ts +0 -27
- package/dist/Route.d.ts +0 -97
- package/dist/RouteBody.d.ts +0 -47
- package/dist/RouteError.d.ts +0 -98
- package/dist/RouteHook.d.ts +0 -12
- package/dist/RouteHttp.d.ts +0 -21
- package/dist/RouteHttpTracer.d.ts +0 -10
- package/dist/RouteMount.d.ts +0 -86
- package/dist/RouteSchema.d.ts +0 -86
- package/dist/RouteSse.d.ts +0 -21
- package/dist/RouteTree.d.ts +0 -57
- package/dist/RouteTrie.d.ts +0 -20
- package/dist/RouterPattern.d.ts +0 -118
- package/dist/RouterPattern.js +0 -269
- package/dist/SchemaExtra.d.ts +0 -7
- package/dist/Socket.d.ts +0 -27
- package/dist/Sql.d.ts +0 -34
- package/dist/Sql.js +0 -5
- package/dist/SqlIntrospect.d.ts +0 -91
- package/dist/Start.d.ts +0 -44
- package/dist/StartApp.d.ts +0 -19
- package/dist/StreamExtra.d.ts +0 -28
- package/dist/System.d.ts +0 -7
- package/dist/TuplePathPattern.d.ts +0 -9
- package/dist/Unique.d.ts +0 -50
- package/dist/Values.d.ts +0 -27
- package/dist/bun/BunBlobStoreDisk.d.ts +0 -6
- package/dist/bun/BunBlobStoreDisk.js +0 -116
- package/dist/bun/BunBlobStoreS3.d.ts +0 -11
- package/dist/bun/BunBlobStoreS3.js +0 -89
- package/dist/bun/BunBlobWatcherDisk.d.ts +0 -6
- package/dist/bun/BunBlobWatcherDisk.js +0 -60
- package/dist/bun/BunBlobWatcherQueue.d.ts +0 -6
- package/dist/bun/BunBlobWatcherQueue.js +0 -17
- package/dist/bun/BunBundle.d.ts +0 -11
- package/dist/bun/BunChildProcessSpawner.d.ts +0 -3
- package/dist/bun/BunHttpServer.d.ts +0 -44
- package/dist/bun/BunHttpServer.js +0 -186
- package/dist/bun/BunHttpServer_web.d.ts +0 -60
- package/dist/bun/BunHttpServer_web.js +0 -252
- package/dist/bun/BunImportTrackerPlugin.d.ts +0 -13
- package/dist/bun/BunPlatformHttpServer.d.ts +0 -10
- package/dist/bun/BunPlatformHttpServer.js +0 -53
- package/dist/bun/BunRoute.d.ts +0 -48
- package/dist/bun/BunRuntime.d.ts +0 -2
- package/dist/bun/BunServer.d.ts +0 -40
- package/dist/bun/BunServerRequest.d.ts +0 -60
- package/dist/bun/BunServerRequest.js +0 -252
- package/dist/bun/BunSql.d.ts +0 -4
- package/dist/bun/BunSql.js +0 -81
- package/dist/bun/BunVirtualFilesPlugin.d.ts +0 -4
- package/dist/bun/_BunEnhancedResolve.d.ts +0 -45
- package/dist/bun/index.d.ts +0 -5
- package/dist/bundler/Bundle.d.ts +0 -61
- package/dist/bundler/BundleFiles.d.ts +0 -13
- package/dist/bundler/BundleHttp.d.ts +0 -45
- package/dist/bundler/BundleHttp.js +0 -176
- package/dist/bundler/BundleRoute.d.ts +0 -27
- package/dist/client/Overlay.d.ts +0 -2
- package/dist/client/ScrollState.d.ts +0 -6
- package/dist/client/index.d.ts +0 -6
- package/dist/console/Console.d.ts +0 -6
- package/dist/console/ConsoleErrors.d.ts +0 -3
- package/dist/console/ConsoleLogger.d.ts +0 -3
- package/dist/console/ConsoleMetrics.d.ts +0 -3
- package/dist/console/ConsoleProcess.d.ts +0 -3
- package/dist/console/ConsoleStore.d.ts +0 -144
- package/dist/console/ConsoleTracer.d.ts +0 -3
- package/dist/console/Simulation.d.ts +0 -2
- package/dist/console/index.d.ts +0 -3
- package/dist/console/routes/errors/route.d.ts +0 -10
- package/dist/console/routes/errors/route.js +0 -47
- package/dist/console/routes/fiberDetail.d.ts +0 -16
- package/dist/console/routes/fiberDetail.js +0 -38
- package/dist/console/routes/fibers/route.d.ts +0 -10
- package/dist/console/routes/fibers/route.js +0 -19
- package/dist/console/routes/git/route.d.ts +0 -11
- package/dist/console/routes/git/route.js +0 -33
- package/dist/console/routes/layout.d.ts +0 -9
- package/dist/console/routes/layout.js +0 -3
- package/dist/console/routes/logs/route.d.ts +0 -10
- package/dist/console/routes/logs/route.js +0 -32
- package/dist/console/routes/metrics/route.d.ts +0 -10
- package/dist/console/routes/metrics/route.js +0 -17
- package/dist/console/routes/route.d.ts +0 -6
- package/dist/console/routes/route.js +0 -5
- package/dist/console/routes/routes/route.d.ts +0 -6
- package/dist/console/routes/routes/route.js +0 -20
- package/dist/console/routes/services/route.d.ts +0 -6
- package/dist/console/routes/services/route.js +0 -12
- package/dist/console/routes/system/route.d.ts +0 -10
- package/dist/console/routes/system/route.js +0 -18
- package/dist/console/routes/traceDetail.d.ts +0 -16
- package/dist/console/routes/traceDetail.js +0 -14
- package/dist/console/routes/traces/route.d.ts +0 -10
- package/dist/console/routes/traces/route.js +0 -39
- package/dist/console/routes/tree.d.ts +0 -153
- package/dist/console/ui/Errors.d.ts +0 -4
- package/dist/console/ui/Errors.js +0 -15
- package/dist/console/ui/Fibers.d.ts +0 -24
- package/dist/console/ui/Fibers.js +0 -121
- package/dist/console/ui/Git.d.ts +0 -20
- package/dist/console/ui/Git.js +0 -95
- package/dist/console/ui/Logs.d.ts +0 -4
- package/dist/console/ui/Logs.js +0 -25
- package/dist/console/ui/Metrics.d.ts +0 -4
- package/dist/console/ui/Metrics.js +0 -26
- package/dist/console/ui/Routes.d.ts +0 -8
- package/dist/console/ui/Routes.js +0 -70
- package/dist/console/ui/Services.d.ts +0 -10
- package/dist/console/ui/Services.js +0 -246
- package/dist/console/ui/Shell.d.ts +0 -10
- package/dist/console/ui/Shell.js +0 -7
- package/dist/console/ui/System.d.ts +0 -4
- package/dist/console/ui/System.js +0 -35
- package/dist/console/ui/Traces.d.ts +0 -12
- package/dist/console/ui/Traces.js +0 -179
- package/dist/datastar/actions/fetch.d.ts +0 -30
- package/dist/datastar/actions/peek.d.ts +0 -1
- package/dist/datastar/actions/setAll.d.ts +0 -1
- package/dist/datastar/actions/toggleAll.d.ts +0 -1
- package/dist/datastar/attributes/attr.d.ts +0 -1
- package/dist/datastar/attributes/bind.d.ts +0 -1
- package/dist/datastar/attributes/class.d.ts +0 -1
- package/dist/datastar/attributes/computed.d.ts +0 -1
- package/dist/datastar/attributes/effect.d.ts +0 -1
- package/dist/datastar/attributes/indicator.d.ts +0 -1
- package/dist/datastar/attributes/init.d.ts +0 -1
- package/dist/datastar/attributes/jsonSignals.d.ts +0 -1
- package/dist/datastar/attributes/on.d.ts +0 -1
- package/dist/datastar/attributes/onIntersect.d.ts +0 -1
- package/dist/datastar/attributes/onInterval.d.ts +0 -1
- package/dist/datastar/attributes/onSignalPatch.d.ts +0 -1
- package/dist/datastar/attributes/ref.d.ts +0 -1
- package/dist/datastar/attributes/show.d.ts +0 -1
- package/dist/datastar/attributes/signals.d.ts +0 -1
- package/dist/datastar/attributes/style.d.ts +0 -1
- package/dist/datastar/attributes/text.d.ts +0 -1
- package/dist/datastar/engine.d.ts +0 -162
- package/dist/datastar/happydom.d.ts +0 -1
- package/dist/datastar/happydom.js +0 -8
- package/dist/datastar/index.d.ts +0 -24
- package/dist/datastar/load.d.ts +0 -24
- package/dist/datastar/load.js +0 -24
- package/dist/datastar/utils.d.ts +0 -51
- package/dist/datastar/watchers/patchElements.d.ts +0 -1
- package/dist/datastar/watchers/patchSignals.d.ts +0 -1
- package/dist/experimental/EncryptedCookies.d.ts +0 -48
- package/dist/experimental/SseHttpResponse.d.ts +0 -7
- package/dist/experimental/SseHttpResponse.js +0 -28
- package/dist/experimental/index.d.ts +0 -1
- package/dist/hyper/Hyper.d.ts +0 -25
- package/dist/hyper/HyperHtml.d.ts +0 -23
- package/dist/hyper/HyperHtml.test.d.ts +0 -1
- package/dist/hyper/HyperHtml.test.js +0 -197
- package/dist/hyper/HyperNode.d.ts +0 -14
- package/dist/hyper/HyperRoute.d.ts +0 -8
- package/dist/hyper/HyperRoute.test.d.ts +0 -1
- package/dist/hyper/HyperRoute.test.js +0 -83
- package/dist/hyper/html.d.ts +0 -11
- package/dist/hyper/index.d.ts +0 -6
- package/dist/hyper/jsx-runtime.d.ts +0 -7
- package/dist/index.d.ts +0 -8
- package/dist/inference_check.d.ts +0 -1
- package/dist/inference_check.js +0 -15
- package/dist/lint/plugin.d.ts +0 -86
- package/dist/lint/plugin.js +0 -341
- package/dist/middlewares/BasicAuthMiddleware.d.ts +0 -8
- package/dist/middlewares/BasicAuthMiddleware.js +0 -22
- package/dist/middlewares/index.d.ts +0 -1
- package/dist/middlewares/index.js +0 -1
- package/dist/node/Effectify.d.ts +0 -209
- package/dist/node/Effectify.js +0 -19
- package/dist/node/FileSystem.d.ts +0 -7
- package/dist/node/FileSystem.js +0 -420
- package/dist/node/NodeFileSystem.d.ts +0 -7
- package/dist/node/NodeUtils.d.ts +0 -2
- package/dist/node/PlatformError.d.ts +0 -46
- package/dist/node/PlatformError.js +0 -43
- package/dist/node/Utils.d.ts +0 -1
- package/dist/node/Utils.js +0 -19
- package/dist/repro_fail.d.ts +0 -1
- package/dist/repro_fail.js +0 -14
- package/dist/sql/bun/index.d.ts +0 -3
- package/dist/sql/mssql/docker.d.ts +0 -2
- package/dist/sql/mssql/index.d.ts +0 -21
- package/dist/testing/TestHttpClient.d.ts +0 -13
- package/dist/testing/TestHttpClient.js +0 -68
- package/dist/testing/TestLogger.d.ts +0 -13
- package/dist/testing/index.d.ts +0 -2
- package/dist/testing/utils.d.ts +0 -9
- package/dist/x/cloudflare/CloudflareTunnel.d.ts +0 -10
- package/dist/x/cloudflare/index.d.ts +0 -1
- package/dist/x/datastar/Datastar.d.ts +0 -6
- package/dist/x/datastar/Datastar.js +0 -47
- package/dist/x/datastar/index.d.ts +0 -1
- package/dist/x/datastar/index.js +0 -1
- package/dist/x/tailscale/TailscaleTunnel.d.ts +0 -15
- package/dist/x/tailscale/index.d.ts +0 -1
- package/dist/x/tailwind/TailwindPlugin.d.ts +0 -23
- package/dist/x/tailwind/compile.d.ts +0 -19
- package/dist/x/tailwind/plugin.d.ts +0 -2
- /package/src/{Sql.ts → sql/Sql.ts} +0 -0
package/dist/SqlIntrospect.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import * as Effect from "effect/Effect"
|
|
2
|
-
import * as Schema from "effect/Schema"
|
|
3
|
-
import * as Sql from "./Sql.js"
|
|
4
|
-
|
|
5
|
-
// SQLite
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
1
|
+
import * as Effect from "effect/Effect"
|
|
2
|
+
import * as Schema from "effect/Schema"
|
|
3
|
+
import * as Sql from "./sql/Sql.js"
|
|
4
|
+
|
|
7
5
|
const sqliteColumns = `
|
|
8
6
|
SELECT
|
|
9
7
|
'' as tableSchema,
|
|
@@ -21,7 +19,8 @@ const sqliteColumns = `
|
|
|
21
19
|
WHERE m.type = 'table'
|
|
22
20
|
AND m.name NOT LIKE 'sqlite_%'
|
|
23
21
|
ORDER BY m.name, p.cid
|
|
24
|
-
|
|
22
|
+
`
|
|
23
|
+
|
|
25
24
|
const sqliteForeignKeys = `
|
|
26
25
|
SELECT
|
|
27
26
|
'' as constraintName,
|
|
@@ -38,7 +37,8 @@ const sqliteForeignKeys = `
|
|
|
38
37
|
WHERE m.type = 'table'
|
|
39
38
|
AND m.name NOT LIKE 'sqlite_%'
|
|
40
39
|
ORDER BY m.name, fk.seq
|
|
41
|
-
|
|
40
|
+
`
|
|
41
|
+
|
|
42
42
|
const sqliteIndexes = `
|
|
43
43
|
SELECT
|
|
44
44
|
'' as tableSchema,
|
|
@@ -53,10 +53,8 @@ const sqliteIndexes = `
|
|
|
53
53
|
WHERE m.type = 'table'
|
|
54
54
|
AND m.name NOT LIKE 'sqlite_%'
|
|
55
55
|
ORDER BY m.name, il.name, ii.seqno
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// PostgreSQL
|
|
59
|
-
// ---------------------------------------------------------------------------
|
|
56
|
+
`
|
|
57
|
+
|
|
60
58
|
const postgresColumns = `
|
|
61
59
|
SELECT
|
|
62
60
|
c.table_schema as "tableSchema",
|
|
@@ -83,7 +81,8 @@ const postgresColumns = `
|
|
|
83
81
|
AND c.column_name = pk.column_name
|
|
84
82
|
WHERE c.table_schema NOT IN ('information_schema', 'pg_catalog')
|
|
85
83
|
ORDER BY c.table_schema, c.table_name, c.ordinal_position
|
|
86
|
-
|
|
84
|
+
`
|
|
85
|
+
|
|
87
86
|
const postgresForeignKeys = `
|
|
88
87
|
SELECT
|
|
89
88
|
tc.constraint_name as "constraintName",
|
|
@@ -108,7 +107,8 @@ const postgresForeignKeys = `
|
|
|
108
107
|
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
109
108
|
AND tc.table_schema NOT IN ('information_schema', 'pg_catalog')
|
|
110
109
|
ORDER BY tc.table_schema, tc.table_name, kcu.ordinal_position
|
|
111
|
-
|
|
110
|
+
`
|
|
111
|
+
|
|
112
112
|
const postgresIndexes = `
|
|
113
113
|
SELECT
|
|
114
114
|
n.nspname as "tableSchema",
|
|
@@ -125,10 +125,8 @@ const postgresIndexes = `
|
|
|
125
125
|
AND a.attnum = ANY(ix.indkey)
|
|
126
126
|
WHERE n.nspname NOT IN ('information_schema', 'pg_catalog')
|
|
127
127
|
ORDER BY n.nspname, t.relname, i.relname, array_position(ix.indkey, a.attnum)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// SQL Server (MSSQL)
|
|
131
|
-
// ---------------------------------------------------------------------------
|
|
128
|
+
`
|
|
129
|
+
|
|
132
130
|
const mssqlColumns = `
|
|
133
131
|
SELECT
|
|
134
132
|
s.name as tableSchema,
|
|
@@ -154,7 +152,8 @@ const mssqlColumns = `
|
|
|
154
152
|
) pk ON c.object_id = pk.object_id AND c.column_id = pk.column_id
|
|
155
153
|
WHERE t.is_ms_shipped = 0
|
|
156
154
|
ORDER BY s.name, t.name, c.column_id
|
|
157
|
-
|
|
155
|
+
`
|
|
156
|
+
|
|
158
157
|
const mssqlForeignKeys = `
|
|
159
158
|
SELECT
|
|
160
159
|
fk.name as constraintName,
|
|
@@ -176,7 +175,8 @@ const mssqlForeignKeys = `
|
|
|
176
175
|
JOIN sys.columns rc ON fkc.referenced_object_id = rc.object_id AND fkc.referenced_column_id = rc.column_id
|
|
177
176
|
WHERE t.is_ms_shipped = 0
|
|
178
177
|
ORDER BY s.name, t.name, fkc.constraint_column_id
|
|
179
|
-
|
|
178
|
+
`
|
|
179
|
+
|
|
180
180
|
const mssqlIndexes = `
|
|
181
181
|
SELECT
|
|
182
182
|
s.name as tableSchema,
|
|
@@ -195,272 +195,321 @@ const mssqlIndexes = `
|
|
|
195
195
|
AND i.is_primary_key = 0
|
|
196
196
|
AND ic.is_included_column = 0
|
|
197
197
|
ORDER BY s.name, t.name, i.name, ic.key_ordinal
|
|
198
|
-
|
|
198
|
+
`
|
|
199
|
+
|
|
199
200
|
const dialectQueries = {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Introspect
|
|
210
|
-
// ---------------------------------------------------------------------------
|
|
201
|
+
sqlite: { columns: sqliteColumns, foreignKeys: sqliteForeignKeys, indexes: sqliteIndexes },
|
|
202
|
+
postgres: {
|
|
203
|
+
columns: postgresColumns,
|
|
204
|
+
foreignKeys: postgresForeignKeys,
|
|
205
|
+
indexes: postgresIndexes,
|
|
206
|
+
},
|
|
207
|
+
mssql: { columns: mssqlColumns, foreignKeys: mssqlForeignKeys, indexes: mssqlIndexes },
|
|
208
|
+
}
|
|
209
|
+
|
|
211
210
|
const singleColumnIndexes = (indexes) => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
countByIndex.set(key, { count: 1, columnName: idx.columnName });
|
|
221
|
-
}
|
|
211
|
+
const countByIndex = new Map()
|
|
212
|
+
for (const idx of indexes) {
|
|
213
|
+
const key = `${idx.tableSchema}.${idx.tableName}.${idx.indexName}`
|
|
214
|
+
const existing = countByIndex.get(key)
|
|
215
|
+
if (existing) {
|
|
216
|
+
existing.count++
|
|
217
|
+
} else {
|
|
218
|
+
countByIndex.set(key, { count: 1, columnName: idx.columnName })
|
|
222
219
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
220
|
+
}
|
|
221
|
+
const result = new Set()
|
|
222
|
+
for (const [key, entry] of countByIndex) {
|
|
223
|
+
if (entry.count === 1) {
|
|
224
|
+
const tableKey = key.substring(0, key.lastIndexOf("."))
|
|
225
|
+
result.add(`${tableKey}.${entry.columnName}`)
|
|
229
226
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
else {
|
|
247
|
-
tableMap.set(key, {
|
|
248
|
-
tableSchema: col.tableSchema,
|
|
249
|
-
tableName: col.tableName,
|
|
250
|
-
columns: [fullCol],
|
|
251
|
-
foreignKeys: [],
|
|
252
|
-
indexes: [],
|
|
253
|
-
});
|
|
254
|
-
}
|
|
227
|
+
}
|
|
228
|
+
return result
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const groupByTable = (
|
|
232
|
+
columns,
|
|
233
|
+
foreignKeys,
|
|
234
|
+
indexes,
|
|
235
|
+
) => {
|
|
236
|
+
const sortable = singleColumnIndexes(indexes)
|
|
237
|
+
const tableMap = new Map()
|
|
238
|
+
for (const col of columns) {
|
|
239
|
+
const key = `${col.tableSchema}.${col.tableName}`
|
|
240
|
+
const fullCol = {
|
|
241
|
+
...col,
|
|
242
|
+
isSortable: col.isPrimaryKey || sortable.has(`${key}.${col.columnName}`),
|
|
255
243
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
244
|
+
const existing = tableMap.get(key)
|
|
245
|
+
if (existing) {
|
|
246
|
+
;(existing.columns).push(fullCol)
|
|
247
|
+
} else {
|
|
248
|
+
tableMap.set(key, {
|
|
249
|
+
tableSchema: col.tableSchema,
|
|
250
|
+
tableName: col.tableName,
|
|
251
|
+
columns: [fullCol],
|
|
252
|
+
foreignKeys: [],
|
|
253
|
+
indexes: [],
|
|
254
|
+
})
|
|
263
255
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
256
|
+
}
|
|
257
|
+
for (const fk of foreignKeys) {
|
|
258
|
+
const key = `${fk.tableSchema}.${fk.tableName}`
|
|
259
|
+
const table = tableMap.get(key)
|
|
260
|
+
if (table) {
|
|
261
|
+
;(table.foreignKeys).push(fk)
|
|
271
262
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const
|
|
263
|
+
}
|
|
264
|
+
for (const idx of indexes) {
|
|
265
|
+
const key = `${idx.tableSchema}.${idx.tableName}`
|
|
266
|
+
const table = tableMap.get(key)
|
|
267
|
+
if (table) {
|
|
268
|
+
;(table.indexes).push(idx)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return Array.from(tableMap.values())
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const normalizeBooleans = (columns) =>
|
|
275
|
+
columns.map((c) => ({
|
|
275
276
|
...c,
|
|
276
277
|
isNullable: Boolean(c.isNullable),
|
|
277
278
|
isPrimaryKey: Boolean(c.isPrimaryKey),
|
|
278
279
|
isAutoIncrement: Boolean(c.isAutoIncrement),
|
|
279
|
-
}))
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
280
|
+
}))
|
|
281
|
+
|
|
282
|
+
export const introspect = (
|
|
283
|
+
dialect,
|
|
284
|
+
options,
|
|
285
|
+
) =>
|
|
286
|
+
Effect.gen(function* () {
|
|
287
|
+
const sql = yield* Sql.SqlClient
|
|
288
|
+
const q = dialectQueries[dialect]
|
|
289
|
+
const columns = normalizeBooleans(yield* sql.unsafe(q.columns))
|
|
290
|
+
const foreignKeys =
|
|
291
|
+
options?.foreignKeys !== false ? yield* sql.unsafe(q.foreignKeys) : []
|
|
292
|
+
const indexes =
|
|
293
|
+
options?.indexes !== false
|
|
286
294
|
? (yield* sql.unsafe(q.indexes)).map((i) => ({
|
|
287
295
|
...i,
|
|
288
296
|
isUnique: Boolean(i.isUnique),
|
|
289
|
-
|
|
290
|
-
: []
|
|
291
|
-
return { tables: groupByTable(columns, foreignKeys, indexes) }
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
// Column → Schema mapping
|
|
295
|
-
// ---------------------------------------------------------------------------
|
|
297
|
+
}))
|
|
298
|
+
: []
|
|
299
|
+
return { tables: groupByTable(columns, foreignKeys, indexes) }
|
|
300
|
+
})
|
|
301
|
+
|
|
296
302
|
const dataTypeToSchema = (dataType) => {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
303
|
+
const t = dataType.toLowerCase()
|
|
304
|
+
if (
|
|
305
|
+
t === "integer" ||
|
|
306
|
+
t === "int" ||
|
|
307
|
+
t === "int4" ||
|
|
308
|
+
t === "int8" ||
|
|
309
|
+
t === "smallint" ||
|
|
310
|
+
t === "tinyint" ||
|
|
311
|
+
t === "mediumint" ||
|
|
312
|
+
t === "bigint" ||
|
|
313
|
+
t === "int2"
|
|
314
|
+
)
|
|
315
|
+
return Schema.Number
|
|
316
|
+
if (
|
|
317
|
+
t === "real" ||
|
|
318
|
+
t === "double" ||
|
|
319
|
+
t === "double precision" ||
|
|
320
|
+
t === "float" ||
|
|
321
|
+
t === "float4" ||
|
|
322
|
+
t === "float8" ||
|
|
323
|
+
t === "numeric" ||
|
|
324
|
+
t === "decimal" ||
|
|
325
|
+
t === "money" ||
|
|
326
|
+
t === "smallmoney"
|
|
327
|
+
)
|
|
328
|
+
return Schema.Number
|
|
329
|
+
if (
|
|
330
|
+
t === "text" ||
|
|
331
|
+
t === "varchar" ||
|
|
332
|
+
t === "char" ||
|
|
333
|
+
t === "nchar" ||
|
|
334
|
+
t === "nvarchar" ||
|
|
335
|
+
t === "ntext" ||
|
|
336
|
+
t === "character varying" ||
|
|
337
|
+
t === "character" ||
|
|
338
|
+
t === "bpchar" ||
|
|
339
|
+
t === "uuid" ||
|
|
340
|
+
t === "citext" ||
|
|
341
|
+
t === "name" ||
|
|
342
|
+
t === "xml"
|
|
343
|
+
)
|
|
344
|
+
return Schema.String
|
|
345
|
+
if (t === "boolean" || t === "bool" || t === "bit")
|
|
346
|
+
return Schema.Union(Schema.Boolean, Schema.Number)
|
|
347
|
+
if (
|
|
348
|
+
t === "timestamp" ||
|
|
349
|
+
t === "timestamptz" ||
|
|
350
|
+
t === "timestamp with time zone" ||
|
|
351
|
+
t === "timestamp without time zone" ||
|
|
352
|
+
t === "date" ||
|
|
353
|
+
t === "datetime" ||
|
|
354
|
+
t === "datetime2" ||
|
|
355
|
+
t === "smalldatetime" ||
|
|
356
|
+
t === "datetimeoffset" ||
|
|
357
|
+
t === "time"
|
|
358
|
+
)
|
|
359
|
+
return Schema.String
|
|
360
|
+
if (t === "json" || t === "jsonb") return Schema.Unknown
|
|
361
|
+
if (t === "blob" || t === "bytea" || t === "varbinary" || t === "binary" || t === "image")
|
|
362
|
+
return null
|
|
363
|
+
return null
|
|
364
|
+
}
|
|
365
|
+
|
|
352
366
|
const columnToSchema = (col) => {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
};
|
|
367
|
+
const base = dataTypeToSchema(col.dataType)
|
|
368
|
+
if (base === null) return null
|
|
369
|
+
if (col.isNullable) return Schema.NullOr(base)
|
|
370
|
+
return base
|
|
371
|
+
}
|
|
372
|
+
|
|
360
373
|
export const tableToSchema = (table) => {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
374
|
+
const fields = {}
|
|
375
|
+
let hasFields = false
|
|
376
|
+
for (const col of table.columns) {
|
|
377
|
+
const s = columnToSchema(col)
|
|
378
|
+
if (s === null) continue
|
|
379
|
+
fields[col.columnName] = s
|
|
380
|
+
hasFields = true
|
|
381
|
+
}
|
|
382
|
+
if (!hasFields) return null
|
|
383
|
+
return {
|
|
384
|
+
tableName: table.tableName,
|
|
385
|
+
tableSchema: table.tableSchema,
|
|
386
|
+
schema: Schema.Struct(fields),
|
|
387
|
+
columns: table.columns.filter((c) => columnToSchema(c) !== null),
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export const toSchemas = (db) =>
|
|
392
|
+
db.tables.flatMap((t) => {
|
|
393
|
+
const s = tableToSchema(t)
|
|
394
|
+
return s ? [s] : []
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
const escapeIdentifier = (id) => `"${id.replace(/"/g, '""')}"`
|
|
398
|
+
|
|
399
|
+
const concatSql = (
|
|
400
|
+
sql,
|
|
401
|
+
fragments,
|
|
402
|
+
) => {
|
|
403
|
+
const strings = []
|
|
404
|
+
const values = []
|
|
405
|
+
for (let i = 0; i < fragments.length; i++) {
|
|
406
|
+
const frag = fragments[i]
|
|
407
|
+
for (let j = 0; j < frag.strings.length; j++) {
|
|
408
|
+
if (j === 0 && strings.length > 0) {
|
|
409
|
+
strings[strings.length - 1] += frag.strings[j]
|
|
410
|
+
} else {
|
|
411
|
+
strings.push(frag.strings[j])
|
|
412
|
+
}
|
|
413
|
+
if (j < frag.values.length) values.push(frag.values[j])
|
|
369
414
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
const
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
conditions.push(`${col} ${f.op === "eq" ? "=" : "!="} $${paramIndex}`);
|
|
397
|
-
values.push(f.value);
|
|
398
|
-
}
|
|
415
|
+
}
|
|
416
|
+
const tsa = Object.assign([...strings], { raw: strings })
|
|
417
|
+
return sql(tsa, ...values)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const literal = (text) => ({ strings: [text], values: [] })
|
|
421
|
+
|
|
422
|
+
const param = (value) => ({ strings: ["", ""], values: [value] })
|
|
423
|
+
|
|
424
|
+
const buildWhereFragments = (
|
|
425
|
+
filters,
|
|
426
|
+
columnSet,
|
|
427
|
+
) => {
|
|
428
|
+
const parts = []
|
|
429
|
+
const valid = filters.filter((f) => columnSet.has(f.column))
|
|
430
|
+
if (valid.length === 0) return parts
|
|
431
|
+
parts.push(literal(" WHERE "))
|
|
432
|
+
for (let i = 0; i < valid.length; i++) {
|
|
433
|
+
if (i > 0) parts.push(literal(" AND "))
|
|
434
|
+
const f = valid[i]
|
|
435
|
+
const col = escapeIdentifier(f.column)
|
|
436
|
+
if (f.value === null) {
|
|
437
|
+
parts.push(literal(f.op === "eq" ? `${col} IS NULL` : `${col} IS NOT NULL`))
|
|
438
|
+
} else {
|
|
439
|
+
parts.push(literal(`${col} ${f.op === "eq" ? "=" : "!="} `))
|
|
440
|
+
parts.push(param(f.value))
|
|
399
441
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
};
|
|
442
|
+
}
|
|
443
|
+
return parts
|
|
444
|
+
}
|
|
445
|
+
|
|
405
446
|
const makeTableReader = (ts) => {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
447
|
+
const qualifiedName = ts.tableSchema
|
|
448
|
+
? `${escapeIdentifier(ts.tableSchema)}.${escapeIdentifier(ts.tableName)}`
|
|
449
|
+
: escapeIdentifier(ts.tableName)
|
|
450
|
+
const primaryKey = ts.columns.find((c) => c.isPrimaryKey)
|
|
451
|
+
const selectCols = ts.columns.map((c) => escapeIdentifier(c.columnName)).join(", ")
|
|
452
|
+
const columnSet = new Set(ts.columns.map((c) => c.columnName))
|
|
453
|
+
const sortableSet = new Set(ts.columns.filter((c) => c.isSortable).map((c) => c.columnName))
|
|
454
|
+
|
|
455
|
+
return {
|
|
456
|
+
tableName: ts.tableName,
|
|
457
|
+
tableSchema: ts.tableSchema,
|
|
458
|
+
schema: ts.schema,
|
|
459
|
+
columns: ts.columns,
|
|
460
|
+
sortableColumns: Array.from(sortableSet),
|
|
461
|
+
findAll: (options) =>
|
|
462
|
+
Effect.gen(function* () {
|
|
463
|
+
const sql = yield* Sql.SqlClient
|
|
464
|
+
const fragments = [
|
|
465
|
+
literal(`SELECT ${selectCols} FROM ${qualifiedName}`),
|
|
466
|
+
]
|
|
467
|
+
if (options?.filters) {
|
|
468
|
+
fragments.push(...buildWhereFragments(options.filters, columnSet))
|
|
469
|
+
}
|
|
470
|
+
if (options?.sort && options.sort.length > 0) {
|
|
471
|
+
const sortClauses = options.sort
|
|
472
|
+
.filter((s) => sortableSet.has(s.column))
|
|
473
|
+
.map((s) => `${escapeIdentifier(s.column)} ${s.reverse ? "DESC" : "ASC"}`)
|
|
474
|
+
if (sortClauses.length > 0) fragments.push(literal(` ORDER BY ${sortClauses.join(", ")}`))
|
|
475
|
+
}
|
|
476
|
+
if (options?.limit !== undefined)
|
|
477
|
+
fragments.push(literal(` LIMIT ${Math.trunc(Number(options.limit))}`))
|
|
478
|
+
if (options?.offset !== undefined)
|
|
479
|
+
fragments.push(literal(` OFFSET ${Math.trunc(Number(options.offset))}`))
|
|
480
|
+
return yield* concatSql(sql, fragments)
|
|
481
|
+
}),
|
|
482
|
+
findById: (id) =>
|
|
483
|
+
Effect.gen(function* () {
|
|
484
|
+
if (!primaryKey) return null
|
|
485
|
+
const sql = yield* Sql.SqlClient
|
|
486
|
+
const pkCol = escapeIdentifier(primaryKey.columnName)
|
|
487
|
+
const rows = yield* concatSql(sql, [
|
|
488
|
+
literal(`SELECT ${selectCols} FROM ${qualifiedName} WHERE ${pkCol} = `),
|
|
489
|
+
param(id),
|
|
490
|
+
])
|
|
491
|
+
return rows[0] ?? null
|
|
492
|
+
}),
|
|
493
|
+
count: (options) =>
|
|
494
|
+
Effect.gen(function* () {
|
|
495
|
+
const sql = yield* Sql.SqlClient
|
|
496
|
+
const fragments = [
|
|
497
|
+
literal(`SELECT COUNT(*) as count FROM ${qualifiedName}`),
|
|
498
|
+
]
|
|
499
|
+
if (options?.filters) {
|
|
500
|
+
fragments.push(...buildWhereFragments(options.filters, columnSet))
|
|
501
|
+
}
|
|
502
|
+
const rows = yield* concatSql(sql, fragments)
|
|
503
|
+
return Number((rows[0]).count)
|
|
504
|
+
}),
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
459
508
|
export const makeDatabaseReader = (db) => {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
509
|
+
const schemas = toSchemas(db)
|
|
510
|
+
const readers = schemas.map(makeTableReader)
|
|
511
|
+
return {
|
|
512
|
+
tables: readers,
|
|
513
|
+
table: (name) => readers.find((r) => r.tableName === name),
|
|
514
|
+
}
|
|
515
|
+
}
|