effect-start 0.22.1 → 0.23.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/BlobStore.d.ts +80 -0
- package/dist/BlobStore.js +19 -0
- package/dist/ChildProcess.d.ts +60 -0
- package/dist/ChildProcess.js +30 -0
- package/dist/Commander.d.ts +3 -6
- package/dist/Commander.js +6 -13
- package/dist/ContentNegotiation.d.ts +8 -9
- package/dist/ContentNegotiation.js +32 -37
- package/dist/Cookies.d.ts +47 -0
- package/dist/Cookies.js +273 -363
- package/dist/Development.d.ts +2 -2
- package/dist/Development.js +3 -4
- package/dist/Effectify.d.ts +1 -4
- package/dist/FilePathPattern.d.ts +3 -3
- package/dist/FileRouter.d.ts +5 -8
- package/dist/FileRouter.js +9 -10
- package/dist/FileRouterCodegen.d.ts +1 -1
- package/dist/FileRouterCodegen.js +33 -13
- package/dist/FileSystem.d.ts +158 -0
- package/dist/FileSystem.js +64 -125
- package/dist/Http.js +2 -6
- package/dist/PathPattern.d.ts +7 -7
- package/dist/PathPattern.js +1 -3
- package/dist/PlatformError.d.ts +24 -32
- package/dist/PlatformError.js +3 -21
- package/dist/PlatformRuntime.js +5 -10
- package/dist/Route.d.ts +14 -19
- package/dist/Route.js +8 -11
- package/dist/RouteBody.d.ts +6 -12
- package/dist/RouteBody.js +2 -2
- package/dist/RouteError.d.ts +98 -0
- package/dist/RouteError.js +55 -0
- package/dist/RouteHook.js +6 -11
- package/dist/RouteHttp.d.ts +3 -3
- package/dist/RouteHttp.js +27 -22
- package/dist/RouteMount.d.ts +16 -50
- package/dist/RouteMount.js +6 -20
- package/dist/RouteSchema.d.ts +22 -1
- package/dist/RouteSchema.js +33 -0
- package/dist/RouteSse.js +4 -10
- package/dist/RouteTree.d.ts +2 -1
- package/dist/RouteTree.js +17 -15
- package/dist/RouteTrie.d.ts +2 -2
- package/dist/RouteTrie.js +4 -9
- package/dist/SchemaExtra.d.ts +1 -1
- package/dist/Socket.d.ts +27 -0
- package/dist/Socket.js +20 -28
- package/dist/Sql.d.ts +34 -0
- package/dist/Sql.js +5 -0
- package/dist/SqlIntrospect.d.ts +91 -0
- package/dist/SqlIntrospect.js +466 -0
- package/dist/Start.d.ts +4 -6
- package/dist/Start.js +10 -2
- package/dist/StreamExtra.d.ts +1 -1
- package/dist/StreamExtra.js +9 -9
- package/dist/System.d.ts +7 -0
- package/dist/System.js +22 -0
- package/dist/TuplePathPattern.js +55 -50
- package/dist/Unique.js +7 -7
- package/dist/Values.d.ts +2 -1
- package/dist/Values.js +19 -13
- package/dist/bun/BunBlobStoreDisk.d.ts +6 -0
- package/dist/bun/BunBlobStoreDisk.js +116 -0
- package/dist/bun/BunBlobStoreS3.d.ts +11 -0
- package/dist/bun/BunBlobStoreS3.js +89 -0
- package/dist/bun/BunBlobWatcherDisk.d.ts +6 -0
- package/dist/bun/BunBlobWatcherDisk.js +60 -0
- package/dist/bun/BunBlobWatcherQueue.d.ts +6 -0
- package/dist/bun/BunBlobWatcherQueue.js +17 -0
- package/dist/bun/BunBundle.d.ts +5 -6
- package/dist/bun/BunBundle.js +7 -15
- package/dist/bun/BunChildProcessSpawner.d.ts +3 -0
- package/dist/bun/BunChildProcessSpawner.js +103 -0
- package/dist/bun/BunImportTrackerPlugin.d.ts +1 -1
- package/dist/bun/BunImportTrackerPlugin.js +3 -5
- package/dist/bun/BunRoute.d.ts +3 -2
- package/dist/bun/BunRoute.js +5 -7
- package/dist/bun/BunRuntime.js +1 -1
- package/dist/bun/BunServer.d.ts +11 -4
- package/dist/bun/BunServer.js +35 -11
- package/dist/bun/BunSql.d.ts +4 -0
- package/dist/bun/BunSql.js +81 -0
- package/dist/bun/_BunEnhancedResolve.d.ts +3 -3
- package/dist/bun/_BunEnhancedResolve.js +2 -4
- package/dist/bun/index.d.ts +1 -0
- package/dist/bun/index.js +1 -0
- package/dist/bundler/Bundle.d.ts +2 -1
- package/dist/bundler/Bundle.js +1 -1
- package/dist/bundler/BundleFiles.d.ts +5 -5
- package/dist/bundler/BundleFiles.js +10 -8
- package/dist/bundler/BundleRoute.d.ts +27 -0
- package/dist/bundler/BundleRoute.js +51 -0
- package/dist/client/ScrollState.js +2 -6
- package/dist/client/index.js +6 -8
- package/dist/console/Console.d.ts +6 -0
- package/dist/console/Console.js +26 -0
- package/dist/console/ConsoleErrors.d.ts +3 -0
- package/dist/console/ConsoleErrors.js +200 -0
- package/dist/console/ConsoleLogger.d.ts +3 -0
- package/dist/console/ConsoleLogger.js +47 -0
- package/dist/console/ConsoleMetrics.d.ts +3 -0
- package/dist/console/ConsoleMetrics.js +61 -0
- package/dist/console/ConsoleProcess.d.ts +3 -0
- package/dist/console/ConsoleProcess.js +49 -0
- package/dist/console/ConsoleStore.d.ts +144 -0
- package/dist/console/ConsoleStore.js +61 -0
- package/dist/console/ConsoleTracer.d.ts +3 -0
- package/dist/console/ConsoleTracer.js +94 -0
- package/dist/console/Simulation.d.ts +2 -0
- package/dist/console/Simulation.js +633 -0
- package/dist/console/index.d.ts +3 -0
- package/dist/console/index.js +3 -0
- package/dist/console/routes/errors/route.d.ts +10 -0
- package/dist/console/routes/errors/route.js +47 -0
- package/dist/console/routes/fiberDetail.d.ts +16 -0
- package/dist/console/routes/fiberDetail.js +38 -0
- package/dist/console/routes/fibers/route.d.ts +10 -0
- package/dist/console/routes/fibers/route.js +19 -0
- package/dist/console/routes/git/route.d.ts +11 -0
- package/dist/console/routes/git/route.js +33 -0
- package/dist/console/routes/layout.d.ts +9 -0
- package/dist/console/routes/layout.js +3 -0
- package/dist/console/routes/logs/route.d.ts +10 -0
- package/dist/console/routes/logs/route.js +32 -0
- package/dist/console/routes/metrics/route.d.ts +10 -0
- package/dist/console/routes/metrics/route.js +17 -0
- package/dist/console/routes/route.d.ts +6 -0
- package/dist/console/routes/route.js +5 -0
- package/dist/console/routes/routes/route.d.ts +6 -0
- package/dist/console/routes/routes/route.js +20 -0
- package/dist/console/routes/services/route.d.ts +6 -0
- package/dist/console/routes/services/route.js +12 -0
- package/dist/console/routes/system/route.d.ts +10 -0
- package/dist/console/routes/system/route.js +18 -0
- package/dist/console/routes/traceDetail.d.ts +16 -0
- package/dist/console/routes/traceDetail.js +14 -0
- package/dist/console/routes/traces/route.d.ts +10 -0
- package/dist/console/routes/traces/route.js +39 -0
- package/dist/console/routes/tree.d.ts +153 -0
- package/dist/console/routes/tree.js +29 -0
- package/dist/console/ui/Errors.d.ts +4 -0
- package/dist/console/ui/Errors.js +15 -0
- package/dist/console/ui/Fibers.d.ts +24 -0
- package/dist/console/ui/Fibers.js +121 -0
- package/dist/console/ui/Git.d.ts +20 -0
- package/dist/console/ui/Git.js +95 -0
- package/dist/console/ui/Logs.d.ts +4 -0
- package/dist/console/ui/Logs.js +25 -0
- package/dist/console/ui/Metrics.d.ts +4 -0
- package/dist/console/ui/Metrics.js +26 -0
- package/dist/console/ui/Routes.d.ts +8 -0
- package/dist/console/ui/Routes.js +70 -0
- package/dist/console/ui/Services.d.ts +10 -0
- package/dist/console/ui/Services.js +246 -0
- package/dist/console/ui/Shell.d.ts +10 -0
- package/dist/console/ui/Shell.js +7 -0
- package/dist/console/ui/System.d.ts +4 -0
- package/dist/console/ui/System.js +35 -0
- package/dist/console/ui/Traces.d.ts +12 -0
- package/dist/console/ui/Traces.js +179 -0
- package/dist/datastar/actions/fetch.d.ts +1 -1
- package/dist/datastar/actions/fetch.js +10 -18
- package/dist/datastar/actions/peek.js +1 -2
- package/dist/datastar/actions/setAll.js +1 -2
- package/dist/datastar/actions/toggleAll.js +1 -2
- package/dist/datastar/attributes/attr.js +1 -2
- package/dist/datastar/attributes/bind.js +10 -18
- package/dist/datastar/attributes/class.js +2 -5
- package/dist/datastar/attributes/computed.js +2 -3
- package/dist/datastar/attributes/effect.js +1 -2
- package/dist/datastar/attributes/indicator.js +2 -4
- package/dist/datastar/attributes/init.js +2 -3
- package/dist/datastar/attributes/jsonSignals.js +1 -2
- package/dist/datastar/attributes/on.js +41 -22
- package/dist/datastar/attributes/onIntersect.js +2 -3
- package/dist/datastar/attributes/onInterval.js +2 -3
- package/dist/datastar/attributes/onSignalPatch.js +2 -4
- package/dist/datastar/attributes/ref.js +1 -2
- package/dist/datastar/attributes/show.js +1 -2
- package/dist/datastar/attributes/signals.js +1 -2
- package/dist/datastar/attributes/style.js +6 -12
- package/dist/datastar/attributes/text.js +1 -2
- package/dist/datastar/engine.d.ts +13 -7
- package/dist/datastar/engine.js +76 -48
- package/dist/datastar/happydom.d.ts +1 -0
- package/dist/datastar/happydom.js +8 -0
- package/dist/datastar/index.d.ts +1 -1
- package/dist/datastar/index.js +1 -1
- package/dist/datastar/utils.js +4 -7
- package/dist/datastar/watchers/patchElements.js +24 -45
- package/dist/datastar/watchers/patchSignals.js +1 -2
- package/dist/experimental/EncryptedCookies.d.ts +2 -5
- package/dist/experimental/EncryptedCookies.js +17 -48
- package/dist/experimental/index.d.ts +0 -1
- package/dist/experimental/index.js +0 -1
- package/dist/hyper/Hyper.d.ts +2 -9
- package/dist/hyper/Hyper.js +1 -12
- package/dist/hyper/HyperHtml.d.ts +1 -1
- package/dist/hyper/HyperHtml.js +18 -12
- package/dist/hyper/HyperHtml.test.d.ts +1 -0
- package/dist/hyper/HyperHtml.test.js +197 -0
- package/dist/hyper/HyperRoute.test.js +14 -3
- package/dist/hyper/html.d.ts +11 -0
- package/dist/hyper/html.js +30 -0
- package/dist/hyper/index.d.ts +2 -0
- package/dist/hyper/index.js +1 -0
- package/dist/hyper/jsx-runtime.d.ts +1 -1
- package/dist/hyper/jsx-runtime.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lint/plugin.d.ts +86 -0
- package/dist/lint/plugin.js +341 -0
- package/dist/node/NodeFileSystem.d.ts +2 -2
- package/dist/node/NodeFileSystem.js +4 -14
- package/dist/sql/bun/index.d.ts +3 -0
- package/dist/sql/bun/index.js +75 -0
- package/dist/sql/mssql/docker.d.ts +2 -0
- package/dist/sql/mssql/docker.js +67 -0
- package/dist/sql/mssql/index.d.ts +21 -0
- package/dist/sql/mssql/index.js +113 -0
- package/dist/testing/TestLogger.js +4 -1
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +0 -1
- package/dist/testing/utils.d.ts +3 -3
- package/dist/testing/utils.js +4 -4
- package/dist/x/cloudflare/CloudflareTunnel.d.ts +2 -5
- package/dist/x/cloudflare/CloudflareTunnel.js +14 -27
- package/dist/x/datastar/Datastar.d.ts +1 -1
- package/dist/x/datastar/Datastar.js +13 -12
- package/dist/x/datastar/index.d.ts +1 -2
- package/dist/x/datastar/index.js +1 -2
- package/dist/x/tailscale/TailscaleTunnel.d.ts +15 -0
- package/dist/x/tailscale/TailscaleTunnel.js +68 -0
- package/dist/x/tailscale/index.d.ts +1 -0
- package/dist/x/tailscale/index.js +1 -0
- package/dist/x/tailwind/TailwindPlugin.js +19 -19
- package/dist/x/tailwind/compile.d.ts +2 -2
- package/dist/x/tailwind/compile.js +2 -4
- package/package.json +22 -9
- package/src/ChildProcess.ts +145 -0
- package/src/PlatformError.ts +27 -50
- package/src/Route.ts +2 -2
- package/src/RouteError.ts +76 -0
- package/src/RouteHttp.ts +13 -5
- package/src/RouteSchema.ts +96 -1
- package/src/RouteTree.ts +12 -0
- package/src/Sql.ts +51 -0
- package/src/SqlIntrospect.ts +620 -0
- package/src/Start.ts +15 -3
- package/src/System.ts +43 -0
- package/src/Values.ts +7 -0
- package/src/bun/BunChildProcessSpawner.ts +143 -0
- package/src/bun/BunRoute.ts +5 -2
- package/src/bun/BunServer.ts +22 -1
- package/src/bun/index.ts +1 -0
- package/src/bundler/BundleRoute.ts +66 -0
- package/src/console/Console.ts +42 -0
- package/src/console/ConsoleErrors.ts +213 -0
- package/src/console/ConsoleLogger.ts +56 -0
- package/src/console/ConsoleMetrics.ts +72 -0
- package/src/console/ConsoleProcess.ts +59 -0
- package/src/console/ConsoleStore.ts +187 -0
- package/src/console/ConsoleTracer.ts +107 -0
- package/src/console/Simulation.ts +814 -0
- package/src/console/console.html +340 -0
- package/src/console/index.ts +3 -0
- package/src/console/routes/errors/route.tsx +97 -0
- package/src/console/routes/fiberDetail.tsx +54 -0
- package/src/console/routes/fibers/route.tsx +45 -0
- package/src/console/routes/git/route.tsx +64 -0
- package/src/console/routes/layout.tsx +4 -0
- package/src/console/routes/logs/route.tsx +77 -0
- package/src/console/routes/metrics/route.tsx +36 -0
- package/src/console/routes/route.tsx +8 -0
- package/src/console/routes/routes/route.tsx +30 -0
- package/src/console/routes/services/route.tsx +21 -0
- package/src/console/routes/system/route.tsx +43 -0
- package/src/console/routes/traceDetail.tsx +22 -0
- package/src/console/routes/traces/route.tsx +81 -0
- package/src/console/routes/tree.ts +30 -0
- package/src/console/ui/Errors.tsx +76 -0
- package/src/console/ui/Fibers.tsx +321 -0
- package/src/console/ui/Git.tsx +182 -0
- package/src/console/ui/Logs.tsx +46 -0
- package/src/console/ui/Metrics.tsx +78 -0
- package/src/console/ui/Routes.tsx +125 -0
- package/src/console/ui/Services.tsx +273 -0
- package/src/console/ui/Shell.tsx +62 -0
- package/src/console/ui/System.tsx +131 -0
- package/src/console/ui/Traces.tsx +426 -0
- package/src/datastar/README.md +6 -1
- package/src/datastar/actions/fetch.ts +0 -1
- package/src/datastar/attributes/on.ts +40 -20
- package/src/datastar/engine.ts +51 -0
- package/src/datastar/jsx.d.ts +79 -0
- package/src/hyper/Hyper.ts +1 -16
- package/src/hyper/HyperHtml.ts +6 -4
- package/src/hyper/HyperRoute.ts +2 -1
- package/src/hyper/html.ts +47 -0
- package/src/hyper/index.ts +2 -0
- package/src/hyper/jsx.d.ts +5 -3
- package/src/index.ts +1 -0
- package/src/lint/plugin.js +129 -0
- package/src/sql/bun/index.ts +147 -0
- package/src/sql/mssql/docker.ts +117 -0
- package/src/sql/mssql/index.ts +223 -0
- package/src/sql/mssql/mssql.d.ts +41 -0
- package/src/x/cloudflare/CloudflareTunnel.ts +8 -36
- package/src/x/tailscale/TailscaleTunnel.ts +113 -0
- package/src/x/tailscale/index.ts +1 -0
- package/src/x/datastar/Datastar.ts +0 -61
- package/src/x/datastar/index.ts +0 -2
- package/src/x/datastar/jsx-datastar.d.ts +0 -60
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import * as Sql from "./Sql.ts";
|
|
4
|
+
export interface Column {
|
|
5
|
+
readonly tableSchema: string;
|
|
6
|
+
readonly tableName: string;
|
|
7
|
+
readonly columnName: string;
|
|
8
|
+
readonly ordinalPosition: number;
|
|
9
|
+
readonly columnDefault: string | null;
|
|
10
|
+
readonly isNullable: boolean;
|
|
11
|
+
readonly dataType: string;
|
|
12
|
+
readonly maxLength: number | null;
|
|
13
|
+
readonly isPrimaryKey: boolean;
|
|
14
|
+
readonly isAutoIncrement: boolean;
|
|
15
|
+
readonly isSortable: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface ForeignKey {
|
|
18
|
+
readonly constraintName: string;
|
|
19
|
+
readonly tableSchema: string;
|
|
20
|
+
readonly tableName: string;
|
|
21
|
+
readonly columnName: string;
|
|
22
|
+
readonly referencedSchema: string;
|
|
23
|
+
readonly referencedTable: string;
|
|
24
|
+
readonly referencedColumn: string;
|
|
25
|
+
readonly updateRule: string;
|
|
26
|
+
readonly deleteRule: string;
|
|
27
|
+
}
|
|
28
|
+
export interface Index {
|
|
29
|
+
readonly tableSchema: string;
|
|
30
|
+
readonly tableName: string;
|
|
31
|
+
readonly indexName: string;
|
|
32
|
+
readonly columnName: string;
|
|
33
|
+
readonly isUnique: boolean;
|
|
34
|
+
readonly ordinalPosition: number;
|
|
35
|
+
}
|
|
36
|
+
export interface Table {
|
|
37
|
+
readonly tableSchema: string;
|
|
38
|
+
readonly tableName: string;
|
|
39
|
+
readonly columns: ReadonlyArray<Column>;
|
|
40
|
+
readonly foreignKeys: ReadonlyArray<ForeignKey>;
|
|
41
|
+
readonly indexes: ReadonlyArray<Index>;
|
|
42
|
+
}
|
|
43
|
+
export interface DatabaseSchema {
|
|
44
|
+
readonly tables: ReadonlyArray<Table>;
|
|
45
|
+
}
|
|
46
|
+
export interface IntrospectOptions {
|
|
47
|
+
readonly foreignKeys?: boolean;
|
|
48
|
+
readonly indexes?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export type Dialect = "sqlite" | "postgres" | "mssql";
|
|
51
|
+
export declare const introspect: (dialect: Dialect, options?: IntrospectOptions) => Effect.Effect<DatabaseSchema, Sql.SqlError, Sql.SqlClient>;
|
|
52
|
+
export interface TableSchema {
|
|
53
|
+
readonly tableName: string;
|
|
54
|
+
readonly tableSchema: string;
|
|
55
|
+
readonly schema: Schema.Schema<any, any, never>;
|
|
56
|
+
readonly columns: ReadonlyArray<Column>;
|
|
57
|
+
}
|
|
58
|
+
export declare const tableToSchema: (table: Table) => TableSchema | null;
|
|
59
|
+
export declare const toSchemas: (db: DatabaseSchema) => ReadonlyArray<TableSchema>;
|
|
60
|
+
export interface SortOrder {
|
|
61
|
+
readonly column: string;
|
|
62
|
+
readonly reverse?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface Filter {
|
|
65
|
+
readonly column: string;
|
|
66
|
+
readonly op: "eq" | "neq";
|
|
67
|
+
readonly value: unknown;
|
|
68
|
+
}
|
|
69
|
+
export interface FindAllOptions {
|
|
70
|
+
readonly limit?: number;
|
|
71
|
+
readonly offset?: number;
|
|
72
|
+
readonly sort?: ReadonlyArray<SortOrder>;
|
|
73
|
+
readonly filters?: ReadonlyArray<Filter>;
|
|
74
|
+
}
|
|
75
|
+
export interface TableReader {
|
|
76
|
+
readonly tableName: string;
|
|
77
|
+
readonly tableSchema: string;
|
|
78
|
+
readonly schema: Schema.Schema<any, any, never>;
|
|
79
|
+
readonly columns: ReadonlyArray<Column>;
|
|
80
|
+
readonly sortableColumns: ReadonlyArray<string>;
|
|
81
|
+
readonly findAll: (options?: FindAllOptions) => Effect.Effect<ReadonlyArray<unknown>, Sql.SqlError, Sql.SqlClient>;
|
|
82
|
+
readonly findById: (id: unknown) => Effect.Effect<unknown | null, Sql.SqlError, Sql.SqlClient>;
|
|
83
|
+
readonly count: (options?: {
|
|
84
|
+
readonly filters?: ReadonlyArray<Filter>;
|
|
85
|
+
}) => Effect.Effect<number, Sql.SqlError, Sql.SqlClient>;
|
|
86
|
+
}
|
|
87
|
+
export interface DatabaseReader {
|
|
88
|
+
readonly tables: ReadonlyArray<TableReader>;
|
|
89
|
+
readonly table: (name: string) => TableReader | undefined;
|
|
90
|
+
}
|
|
91
|
+
export declare const makeDatabaseReader: (db: DatabaseSchema) => DatabaseReader;
|
|
@@ -0,0 +1,466 @@
|
|
|
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
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
const sqliteColumns = `
|
|
8
|
+
SELECT
|
|
9
|
+
'' as tableSchema,
|
|
10
|
+
m.name as tableName,
|
|
11
|
+
p.name as columnName,
|
|
12
|
+
p.cid + 1 as ordinalPosition,
|
|
13
|
+
p.dflt_value as columnDefault,
|
|
14
|
+
CASE WHEN p."notnull" = 0 THEN 1 ELSE 0 END as isNullable,
|
|
15
|
+
p.type as dataType,
|
|
16
|
+
NULL as maxLength,
|
|
17
|
+
p.pk as isPrimaryKey,
|
|
18
|
+
CASE WHEN p.pk = 1 AND lower(p.type) = 'integer' THEN 1 ELSE 0 END as isAutoIncrement
|
|
19
|
+
FROM sqlite_master m
|
|
20
|
+
JOIN pragma_table_info(m.name) p
|
|
21
|
+
WHERE m.type = 'table'
|
|
22
|
+
AND m.name NOT LIKE 'sqlite_%'
|
|
23
|
+
ORDER BY m.name, p.cid
|
|
24
|
+
`;
|
|
25
|
+
const sqliteForeignKeys = `
|
|
26
|
+
SELECT
|
|
27
|
+
'' as constraintName,
|
|
28
|
+
'' as tableSchema,
|
|
29
|
+
m.name as tableName,
|
|
30
|
+
fk."from" as columnName,
|
|
31
|
+
'' as referencedSchema,
|
|
32
|
+
fk."table" as referencedTable,
|
|
33
|
+
fk."to" as referencedColumn,
|
|
34
|
+
fk.on_update as updateRule,
|
|
35
|
+
fk.on_delete as deleteRule
|
|
36
|
+
FROM sqlite_master m
|
|
37
|
+
JOIN pragma_foreign_key_list(m.name) fk
|
|
38
|
+
WHERE m.type = 'table'
|
|
39
|
+
AND m.name NOT LIKE 'sqlite_%'
|
|
40
|
+
ORDER BY m.name, fk.seq
|
|
41
|
+
`;
|
|
42
|
+
const sqliteIndexes = `
|
|
43
|
+
SELECT
|
|
44
|
+
'' as tableSchema,
|
|
45
|
+
m.name as tableName,
|
|
46
|
+
il.name as indexName,
|
|
47
|
+
ii.name as columnName,
|
|
48
|
+
il."unique" as isUnique,
|
|
49
|
+
ii.seqno + 1 as ordinalPosition
|
|
50
|
+
FROM sqlite_master m
|
|
51
|
+
JOIN pragma_index_list(m.name) il
|
|
52
|
+
JOIN pragma_index_info(il.name) ii
|
|
53
|
+
WHERE m.type = 'table'
|
|
54
|
+
AND m.name NOT LIKE 'sqlite_%'
|
|
55
|
+
ORDER BY m.name, il.name, ii.seqno
|
|
56
|
+
`;
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// PostgreSQL
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
const postgresColumns = `
|
|
61
|
+
SELECT
|
|
62
|
+
c.table_schema as "tableSchema",
|
|
63
|
+
c.table_name as "tableName",
|
|
64
|
+
c.column_name as "columnName",
|
|
65
|
+
c.ordinal_position as "ordinalPosition",
|
|
66
|
+
c.column_default as "columnDefault",
|
|
67
|
+
CASE WHEN c.is_nullable = 'YES' THEN true ELSE false END as "isNullable",
|
|
68
|
+
c.data_type as "dataType",
|
|
69
|
+
c.character_maximum_length as "maxLength",
|
|
70
|
+
CASE WHEN pk.column_name IS NOT NULL THEN true ELSE false END as "isPrimaryKey",
|
|
71
|
+
CASE WHEN c.column_default LIKE 'nextval(%' THEN true ELSE false END as "isAutoIncrement"
|
|
72
|
+
FROM information_schema.columns c
|
|
73
|
+
LEFT JOIN (
|
|
74
|
+
SELECT kcu.table_schema, kcu.table_name, kcu.column_name
|
|
75
|
+
FROM information_schema.table_constraints tc
|
|
76
|
+
JOIN information_schema.key_column_usage kcu
|
|
77
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
78
|
+
AND tc.table_schema = kcu.table_schema
|
|
79
|
+
WHERE tc.constraint_type = 'PRIMARY KEY'
|
|
80
|
+
) pk
|
|
81
|
+
ON c.table_schema = pk.table_schema
|
|
82
|
+
AND c.table_name = pk.table_name
|
|
83
|
+
AND c.column_name = pk.column_name
|
|
84
|
+
WHERE c.table_schema NOT IN ('information_schema', 'pg_catalog')
|
|
85
|
+
ORDER BY c.table_schema, c.table_name, c.ordinal_position
|
|
86
|
+
`;
|
|
87
|
+
const postgresForeignKeys = `
|
|
88
|
+
SELECT
|
|
89
|
+
tc.constraint_name as "constraintName",
|
|
90
|
+
tc.table_schema as "tableSchema",
|
|
91
|
+
tc.table_name as "tableName",
|
|
92
|
+
kcu.column_name as "columnName",
|
|
93
|
+
ccu.table_schema as "referencedSchema",
|
|
94
|
+
ccu.table_name as "referencedTable",
|
|
95
|
+
ccu.column_name as "referencedColumn",
|
|
96
|
+
rc.update_rule as "updateRule",
|
|
97
|
+
rc.delete_rule as "deleteRule"
|
|
98
|
+
FROM information_schema.table_constraints tc
|
|
99
|
+
JOIN information_schema.key_column_usage kcu
|
|
100
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
101
|
+
AND tc.table_schema = kcu.table_schema
|
|
102
|
+
JOIN information_schema.constraint_column_usage ccu
|
|
103
|
+
ON tc.constraint_name = ccu.constraint_name
|
|
104
|
+
AND tc.table_schema = ccu.table_schema
|
|
105
|
+
JOIN information_schema.referential_constraints rc
|
|
106
|
+
ON tc.constraint_name = rc.constraint_name
|
|
107
|
+
AND tc.table_schema = rc.constraint_schema
|
|
108
|
+
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
109
|
+
AND tc.table_schema NOT IN ('information_schema', 'pg_catalog')
|
|
110
|
+
ORDER BY tc.table_schema, tc.table_name, kcu.ordinal_position
|
|
111
|
+
`;
|
|
112
|
+
const postgresIndexes = `
|
|
113
|
+
SELECT
|
|
114
|
+
n.nspname as "tableSchema",
|
|
115
|
+
t.relname as "tableName",
|
|
116
|
+
i.relname as "indexName",
|
|
117
|
+
a.attname as "columnName",
|
|
118
|
+
ix.indisunique as "isUnique",
|
|
119
|
+
array_position(ix.indkey, a.attnum) as "ordinalPosition"
|
|
120
|
+
FROM pg_index ix
|
|
121
|
+
JOIN pg_class t ON t.oid = ix.indrelid
|
|
122
|
+
JOIN pg_class i ON i.oid = ix.indexrelid
|
|
123
|
+
JOIN pg_namespace n ON n.oid = t.relnamespace
|
|
124
|
+
JOIN pg_attribute a ON a.attrelid = t.oid
|
|
125
|
+
AND a.attnum = ANY(ix.indkey)
|
|
126
|
+
WHERE n.nspname NOT IN ('information_schema', 'pg_catalog')
|
|
127
|
+
ORDER BY n.nspname, t.relname, i.relname, array_position(ix.indkey, a.attnum)
|
|
128
|
+
`;
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
// SQL Server (MSSQL)
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
const mssqlColumns = `
|
|
133
|
+
SELECT
|
|
134
|
+
s.name as tableSchema,
|
|
135
|
+
t.name as tableName,
|
|
136
|
+
c.name as columnName,
|
|
137
|
+
c.column_id as ordinalPosition,
|
|
138
|
+
dc.definition as columnDefault,
|
|
139
|
+
c.is_nullable as isNullable,
|
|
140
|
+
tp.name as dataType,
|
|
141
|
+
c.max_length as maxLength,
|
|
142
|
+
CASE WHEN pk.column_id IS NOT NULL THEN 1 ELSE 0 END as isPrimaryKey,
|
|
143
|
+
c.is_identity as isAutoIncrement
|
|
144
|
+
FROM sys.tables t
|
|
145
|
+
JOIN sys.schemas s ON t.schema_id = s.schema_id
|
|
146
|
+
JOIN sys.columns c ON t.object_id = c.object_id
|
|
147
|
+
JOIN sys.types tp ON c.user_type_id = tp.user_type_id
|
|
148
|
+
LEFT JOIN sys.default_constraints dc ON c.default_object_id = dc.object_id
|
|
149
|
+
LEFT JOIN (
|
|
150
|
+
SELECT ic.object_id, ic.column_id
|
|
151
|
+
FROM sys.index_columns ic
|
|
152
|
+
JOIN sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
|
|
153
|
+
WHERE i.is_primary_key = 1
|
|
154
|
+
) pk ON c.object_id = pk.object_id AND c.column_id = pk.column_id
|
|
155
|
+
WHERE t.is_ms_shipped = 0
|
|
156
|
+
ORDER BY s.name, t.name, c.column_id
|
|
157
|
+
`;
|
|
158
|
+
const mssqlForeignKeys = `
|
|
159
|
+
SELECT
|
|
160
|
+
fk.name as constraintName,
|
|
161
|
+
s.name as tableSchema,
|
|
162
|
+
t.name as tableName,
|
|
163
|
+
c.name as columnName,
|
|
164
|
+
rs.name as referencedSchema,
|
|
165
|
+
rt.name as referencedTable,
|
|
166
|
+
rc.name as referencedColumn,
|
|
167
|
+
fk.update_referential_action_desc as updateRule,
|
|
168
|
+
fk.delete_referential_action_desc as deleteRule
|
|
169
|
+
FROM sys.foreign_keys fk
|
|
170
|
+
JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
|
|
171
|
+
JOIN sys.tables t ON fkc.parent_object_id = t.object_id
|
|
172
|
+
JOIN sys.schemas s ON t.schema_id = s.schema_id
|
|
173
|
+
JOIN sys.columns c ON fkc.parent_object_id = c.object_id AND fkc.parent_column_id = c.column_id
|
|
174
|
+
JOIN sys.tables rt ON fkc.referenced_object_id = rt.object_id
|
|
175
|
+
JOIN sys.schemas rs ON rt.schema_id = rs.schema_id
|
|
176
|
+
JOIN sys.columns rc ON fkc.referenced_object_id = rc.object_id AND fkc.referenced_column_id = rc.column_id
|
|
177
|
+
WHERE t.is_ms_shipped = 0
|
|
178
|
+
ORDER BY s.name, t.name, fkc.constraint_column_id
|
|
179
|
+
`;
|
|
180
|
+
const mssqlIndexes = `
|
|
181
|
+
SELECT
|
|
182
|
+
s.name as tableSchema,
|
|
183
|
+
t.name as tableName,
|
|
184
|
+
i.name as indexName,
|
|
185
|
+
c.name as columnName,
|
|
186
|
+
i.is_unique as isUnique,
|
|
187
|
+
ic.key_ordinal as ordinalPosition
|
|
188
|
+
FROM sys.indexes i
|
|
189
|
+
JOIN sys.index_columns ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id
|
|
190
|
+
JOIN sys.tables t ON i.object_id = t.object_id
|
|
191
|
+
JOIN sys.schemas s ON t.schema_id = s.schema_id
|
|
192
|
+
JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id
|
|
193
|
+
WHERE t.is_ms_shipped = 0
|
|
194
|
+
AND i.name IS NOT NULL
|
|
195
|
+
AND i.is_primary_key = 0
|
|
196
|
+
AND ic.is_included_column = 0
|
|
197
|
+
ORDER BY s.name, t.name, i.name, ic.key_ordinal
|
|
198
|
+
`;
|
|
199
|
+
const dialectQueries = {
|
|
200
|
+
sqlite: { columns: sqliteColumns, foreignKeys: sqliteForeignKeys, indexes: sqliteIndexes },
|
|
201
|
+
postgres: {
|
|
202
|
+
columns: postgresColumns,
|
|
203
|
+
foreignKeys: postgresForeignKeys,
|
|
204
|
+
indexes: postgresIndexes,
|
|
205
|
+
},
|
|
206
|
+
mssql: { columns: mssqlColumns, foreignKeys: mssqlForeignKeys, indexes: mssqlIndexes },
|
|
207
|
+
};
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
// Introspect
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
const singleColumnIndexes = (indexes) => {
|
|
212
|
+
const countByIndex = new Map();
|
|
213
|
+
for (const idx of indexes) {
|
|
214
|
+
const key = `${idx.tableSchema}.${idx.tableName}.${idx.indexName}`;
|
|
215
|
+
const existing = countByIndex.get(key);
|
|
216
|
+
if (existing) {
|
|
217
|
+
existing.count++;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
countByIndex.set(key, { count: 1, columnName: idx.columnName });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const result = new Set();
|
|
224
|
+
for (const [key, entry] of countByIndex) {
|
|
225
|
+
if (entry.count === 1) {
|
|
226
|
+
const tableKey = key.substring(0, key.lastIndexOf("."));
|
|
227
|
+
result.add(`${tableKey}.${entry.columnName}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
};
|
|
232
|
+
const groupByTable = (columns, foreignKeys, indexes) => {
|
|
233
|
+
const sortable = singleColumnIndexes(indexes);
|
|
234
|
+
const tableMap = new Map();
|
|
235
|
+
for (const col of columns) {
|
|
236
|
+
const key = `${col.tableSchema}.${col.tableName}`;
|
|
237
|
+
const fullCol = {
|
|
238
|
+
...col,
|
|
239
|
+
isSortable: col.isPrimaryKey || sortable.has(`${key}.${col.columnName}`),
|
|
240
|
+
};
|
|
241
|
+
const existing = tableMap.get(key);
|
|
242
|
+
if (existing) {
|
|
243
|
+
;
|
|
244
|
+
existing.columns.push(fullCol);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
tableMap.set(key, {
|
|
248
|
+
tableSchema: col.tableSchema,
|
|
249
|
+
tableName: col.tableName,
|
|
250
|
+
columns: [fullCol],
|
|
251
|
+
foreignKeys: [],
|
|
252
|
+
indexes: [],
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
for (const fk of foreignKeys) {
|
|
257
|
+
const key = `${fk.tableSchema}.${fk.tableName}`;
|
|
258
|
+
const table = tableMap.get(key);
|
|
259
|
+
if (table) {
|
|
260
|
+
;
|
|
261
|
+
table.foreignKeys.push(fk);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
for (const idx of indexes) {
|
|
265
|
+
const key = `${idx.tableSchema}.${idx.tableName}`;
|
|
266
|
+
const table = tableMap.get(key);
|
|
267
|
+
if (table) {
|
|
268
|
+
;
|
|
269
|
+
table.indexes.push(idx);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return Array.from(tableMap.values());
|
|
273
|
+
};
|
|
274
|
+
const normalizeBooleans = (columns) => columns.map((c) => ({
|
|
275
|
+
...c,
|
|
276
|
+
isNullable: Boolean(c.isNullable),
|
|
277
|
+
isPrimaryKey: Boolean(c.isPrimaryKey),
|
|
278
|
+
isAutoIncrement: Boolean(c.isAutoIncrement),
|
|
279
|
+
}));
|
|
280
|
+
export const introspect = (dialect, options) => Effect.gen(function* () {
|
|
281
|
+
const sql = yield* Sql.SqlClient;
|
|
282
|
+
const q = dialectQueries[dialect];
|
|
283
|
+
const columns = normalizeBooleans(yield* sql.unsafe(q.columns));
|
|
284
|
+
const foreignKeys = options?.foreignKeys !== false ? yield* sql.unsafe(q.foreignKeys) : [];
|
|
285
|
+
const indexes = options?.indexes !== false
|
|
286
|
+
? (yield* sql.unsafe(q.indexes)).map((i) => ({
|
|
287
|
+
...i,
|
|
288
|
+
isUnique: Boolean(i.isUnique),
|
|
289
|
+
}))
|
|
290
|
+
: [];
|
|
291
|
+
return { tables: groupByTable(columns, foreignKeys, indexes) };
|
|
292
|
+
});
|
|
293
|
+
// ---------------------------------------------------------------------------
|
|
294
|
+
// Column → Schema mapping
|
|
295
|
+
// ---------------------------------------------------------------------------
|
|
296
|
+
const dataTypeToSchema = (dataType) => {
|
|
297
|
+
const t = dataType.toLowerCase();
|
|
298
|
+
if (t === "integer" ||
|
|
299
|
+
t === "int" ||
|
|
300
|
+
t === "int4" ||
|
|
301
|
+
t === "int8" ||
|
|
302
|
+
t === "smallint" ||
|
|
303
|
+
t === "tinyint" ||
|
|
304
|
+
t === "mediumint" ||
|
|
305
|
+
t === "bigint" ||
|
|
306
|
+
t === "int2")
|
|
307
|
+
return Schema.Number;
|
|
308
|
+
if (t === "real" ||
|
|
309
|
+
t === "double" ||
|
|
310
|
+
t === "double precision" ||
|
|
311
|
+
t === "float" ||
|
|
312
|
+
t === "float4" ||
|
|
313
|
+
t === "float8" ||
|
|
314
|
+
t === "numeric" ||
|
|
315
|
+
t === "decimal" ||
|
|
316
|
+
t === "money" ||
|
|
317
|
+
t === "smallmoney")
|
|
318
|
+
return Schema.Number;
|
|
319
|
+
if (t === "text" ||
|
|
320
|
+
t === "varchar" ||
|
|
321
|
+
t === "char" ||
|
|
322
|
+
t === "nchar" ||
|
|
323
|
+
t === "nvarchar" ||
|
|
324
|
+
t === "ntext" ||
|
|
325
|
+
t === "character varying" ||
|
|
326
|
+
t === "character" ||
|
|
327
|
+
t === "bpchar" ||
|
|
328
|
+
t === "uuid" ||
|
|
329
|
+
t === "citext" ||
|
|
330
|
+
t === "name" ||
|
|
331
|
+
t === "xml")
|
|
332
|
+
return Schema.String;
|
|
333
|
+
if (t === "boolean" || t === "bool" || t === "bit")
|
|
334
|
+
return Schema.Union(Schema.Boolean, Schema.Number);
|
|
335
|
+
if (t === "timestamp" ||
|
|
336
|
+
t === "timestamptz" ||
|
|
337
|
+
t === "timestamp with time zone" ||
|
|
338
|
+
t === "timestamp without time zone" ||
|
|
339
|
+
t === "date" ||
|
|
340
|
+
t === "datetime" ||
|
|
341
|
+
t === "datetime2" ||
|
|
342
|
+
t === "smalldatetime" ||
|
|
343
|
+
t === "datetimeoffset" ||
|
|
344
|
+
t === "time")
|
|
345
|
+
return Schema.String;
|
|
346
|
+
if (t === "json" || t === "jsonb")
|
|
347
|
+
return Schema.Unknown;
|
|
348
|
+
if (t === "blob" || t === "bytea" || t === "varbinary" || t === "binary" || t === "image")
|
|
349
|
+
return null;
|
|
350
|
+
return null;
|
|
351
|
+
};
|
|
352
|
+
const columnToSchema = (col) => {
|
|
353
|
+
const base = dataTypeToSchema(col.dataType);
|
|
354
|
+
if (base === null)
|
|
355
|
+
return null;
|
|
356
|
+
if (col.isNullable)
|
|
357
|
+
return Schema.NullOr(base);
|
|
358
|
+
return base;
|
|
359
|
+
};
|
|
360
|
+
export const tableToSchema = (table) => {
|
|
361
|
+
const fields = {};
|
|
362
|
+
let hasFields = false;
|
|
363
|
+
for (const col of table.columns) {
|
|
364
|
+
const s = columnToSchema(col);
|
|
365
|
+
if (s === null)
|
|
366
|
+
continue;
|
|
367
|
+
fields[col.columnName] = s;
|
|
368
|
+
hasFields = true;
|
|
369
|
+
}
|
|
370
|
+
if (!hasFields)
|
|
371
|
+
return null;
|
|
372
|
+
return {
|
|
373
|
+
tableName: table.tableName,
|
|
374
|
+
tableSchema: table.tableSchema,
|
|
375
|
+
schema: Schema.Struct(fields),
|
|
376
|
+
columns: table.columns.filter((c) => columnToSchema(c) !== null),
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
export const toSchemas = (db) => db.tables.flatMap((t) => {
|
|
380
|
+
const s = tableToSchema(t);
|
|
381
|
+
return s ? [s] : [];
|
|
382
|
+
});
|
|
383
|
+
const escapeIdentifier = (id) => `"${id.replace(/"/g, '""')}"`;
|
|
384
|
+
const buildWhereClause = (filters, columnSet, paramOffset) => {
|
|
385
|
+
const conditions = [];
|
|
386
|
+
const values = [];
|
|
387
|
+
for (const f of filters) {
|
|
388
|
+
if (!columnSet.has(f.column))
|
|
389
|
+
continue;
|
|
390
|
+
const col = escapeIdentifier(f.column);
|
|
391
|
+
const paramIndex = paramOffset + values.length + 1;
|
|
392
|
+
if (f.value === null) {
|
|
393
|
+
conditions.push(f.op === "eq" ? `${col} IS NULL` : `${col} IS NOT NULL`);
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
conditions.push(`${col} ${f.op === "eq" ? "=" : "!="} $${paramIndex}`);
|
|
397
|
+
values.push(f.value);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
clause: conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : "",
|
|
402
|
+
values,
|
|
403
|
+
};
|
|
404
|
+
};
|
|
405
|
+
const makeTableReader = (ts) => {
|
|
406
|
+
const qualifiedName = ts.tableSchema
|
|
407
|
+
? `${escapeIdentifier(ts.tableSchema)}.${escapeIdentifier(ts.tableName)}`
|
|
408
|
+
: escapeIdentifier(ts.tableName);
|
|
409
|
+
const primaryKey = ts.columns.find((c) => c.isPrimaryKey);
|
|
410
|
+
const selectCols = ts.columns.map((c) => escapeIdentifier(c.columnName)).join(", ");
|
|
411
|
+
const columnSet = new Set(ts.columns.map((c) => c.columnName));
|
|
412
|
+
const sortableSet = new Set(ts.columns.filter((c) => c.isSortable).map((c) => c.columnName));
|
|
413
|
+
return {
|
|
414
|
+
tableName: ts.tableName,
|
|
415
|
+
tableSchema: ts.tableSchema,
|
|
416
|
+
schema: ts.schema,
|
|
417
|
+
columns: ts.columns,
|
|
418
|
+
sortableColumns: Array.from(sortableSet),
|
|
419
|
+
findAll: (options) => Effect.gen(function* () {
|
|
420
|
+
const sql = yield* Sql.SqlClient;
|
|
421
|
+
let query = `SELECT ${selectCols} FROM ${qualifiedName}`;
|
|
422
|
+
const where = options?.filters
|
|
423
|
+
? buildWhereClause(options.filters, columnSet, 0)
|
|
424
|
+
: { clause: "", values: [] };
|
|
425
|
+
query += where.clause;
|
|
426
|
+
if (options?.sort && options.sort.length > 0) {
|
|
427
|
+
const sortClauses = options.sort
|
|
428
|
+
.filter((s) => sortableSet.has(s.column))
|
|
429
|
+
.map((s) => `${escapeIdentifier(s.column)} ${s.reverse ? "DESC" : "ASC"}`);
|
|
430
|
+
if (sortClauses.length > 0)
|
|
431
|
+
query += ` ORDER BY ${sortClauses.join(", ")}`;
|
|
432
|
+
}
|
|
433
|
+
if (options?.limit !== undefined)
|
|
434
|
+
query += ` LIMIT ${Number(options.limit)}`;
|
|
435
|
+
if (options?.offset !== undefined)
|
|
436
|
+
query += ` OFFSET ${Number(options.offset)}`;
|
|
437
|
+
return yield* sql.unsafe(query, where.values);
|
|
438
|
+
}),
|
|
439
|
+
findById: (id) => Effect.gen(function* () {
|
|
440
|
+
if (!primaryKey)
|
|
441
|
+
return null;
|
|
442
|
+
const sql = yield* Sql.SqlClient;
|
|
443
|
+
const query = `SELECT ${selectCols} FROM ${qualifiedName} WHERE ${escapeIdentifier(primaryKey.columnName)} = $1`;
|
|
444
|
+
const rows = yield* sql.unsafe(query, [id]);
|
|
445
|
+
return rows[0] ?? null;
|
|
446
|
+
}),
|
|
447
|
+
count: (options) => Effect.gen(function* () {
|
|
448
|
+
const sql = yield* Sql.SqlClient;
|
|
449
|
+
let query = `SELECT COUNT(*) as count FROM ${qualifiedName}`;
|
|
450
|
+
const where = options?.filters
|
|
451
|
+
? buildWhereClause(options.filters, columnSet, 0)
|
|
452
|
+
: { clause: "", values: [] };
|
|
453
|
+
query += where.clause;
|
|
454
|
+
const rows = yield* sql.unsafe(query, where.values);
|
|
455
|
+
return Number(rows[0].count);
|
|
456
|
+
}),
|
|
457
|
+
};
|
|
458
|
+
};
|
|
459
|
+
export const makeDatabaseReader = (db) => {
|
|
460
|
+
const schemas = toSchemas(db);
|
|
461
|
+
const readers = schemas.map(makeTableReader);
|
|
462
|
+
return {
|
|
463
|
+
tables: readers,
|
|
464
|
+
table: (name) => readers.find((r) => r.tableName === name),
|
|
465
|
+
};
|
|
466
|
+
};
|
package/dist/Start.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import * as FileSystem from "
|
|
1
|
+
import type * as FileSystem from "./FileSystem.ts";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
|
+
import type * as ChildProcess from "./ChildProcess.ts";
|
|
3
4
|
import * as BunServer from "./bun/BunServer.ts";
|
|
4
|
-
export declare function layer<Layers extends [
|
|
5
|
-
Layer.Layer<never, any, any>,
|
|
6
|
-
...Array<Layer.Layer<never, any, any>>
|
|
7
|
-
]>(...layers: Layers): Layer.Layer<{
|
|
5
|
+
export declare function layer<Layers extends [Layer.Layer<never, any, any>, ...Array<Layer.Layer<never, any, any>>]>(...layers: Layers): Layer.Layer<{
|
|
8
6
|
[k in keyof Layers]: Layer.Layer.Success<Layers[k]>;
|
|
9
7
|
}[number], {
|
|
10
8
|
[k in keyof Layers]: Layer.Layer.Error<Layers[k]>;
|
|
@@ -41,6 +39,6 @@ export declare function pack<const Layers extends readonly [Layer.Layer.Any, ...
|
|
|
41
39
|
}[number], {
|
|
42
40
|
[K in keyof Layers]: Layer.Layer.Success<Layers[K]>;
|
|
43
41
|
}[number]>>;
|
|
44
|
-
export declare function serve<ROut, E, RIn extends BunServer.BunServer | FileSystem.FileSystem>(load: () => Promise<{
|
|
42
|
+
export declare function serve<ROut, E, RIn extends BunServer.BunServer | FileSystem.FileSystem | ChildProcess.ChildProcessSpawner>(load: () => Promise<{
|
|
45
43
|
default: Layer.Layer<ROut, E, RIn>;
|
|
46
44
|
}>): void;
|
package/dist/Start.js
CHANGED
|
@@ -2,9 +2,11 @@ import * as Context from "effect/Context";
|
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Function from "effect/Function";
|
|
4
4
|
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Option from "effect/Option";
|
|
5
6
|
import * as BunRuntime from "./bun/BunRuntime.js";
|
|
6
7
|
import * as BunServer from "./bun/BunServer.js";
|
|
7
8
|
import * as NodeFileSystem from "./node/NodeFileSystem.js";
|
|
9
|
+
import * as BunChildProcessSpawner from "./bun/BunChildProcessSpawner.js";
|
|
8
10
|
export function layer(...layers) {
|
|
9
11
|
return Layer.mergeAll(...layers);
|
|
10
12
|
}
|
|
@@ -35,7 +37,13 @@ export function pack(...layers) {
|
|
|
35
37
|
return result;
|
|
36
38
|
}
|
|
37
39
|
export function serve(load) {
|
|
38
|
-
const appLayer = Function.pipe(Effect.tryPromise(load), Effect.map(v => v.default), Effect.orDie, Layer.unwrapEffect);
|
|
39
|
-
const
|
|
40
|
+
const appLayer = Function.pipe(Effect.tryPromise(load), Effect.map((v) => v.default), Effect.orDie, Layer.unwrapEffect);
|
|
41
|
+
const serverLayer = Layer.scoped(BunServer.BunServer, Effect.gen(function* () {
|
|
42
|
+
const existing = yield* Effect.serviceOption(BunServer.BunServer);
|
|
43
|
+
if (Option.isSome(existing))
|
|
44
|
+
return existing.value;
|
|
45
|
+
return yield* BunServer.make({});
|
|
46
|
+
}));
|
|
47
|
+
const composed = Function.pipe(serverLayer, BunServer.withLogAddress, Layer.provide(appLayer), Layer.provide(NodeFileSystem.layer), Layer.provide(BunChildProcessSpawner.layer));
|
|
40
48
|
return Function.pipe(composed, Layer.launch, BunRuntime.runMain);
|
|
41
49
|
}
|
package/dist/StreamExtra.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Runtime from "effect/Runtime";
|
|
2
|
-
import
|
|
2
|
+
import * as Stream from "effect/Stream";
|
|
3
3
|
export declare const isStream: (u: unknown) => u is Stream.Stream<unknown, unknown, unknown>;
|
|
4
4
|
export type IsStream<T> = T extends Stream.Stream<infer _A, infer _E, infer _R> ? true : false;
|
|
5
5
|
export type Chunk<T> = T extends Stream.Stream<infer A, infer _E, infer _R> ? A : never;
|
package/dist/StreamExtra.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as Cause from "effect/Cause";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Fiber from "effect/Fiber";
|
|
4
|
-
import
|
|
4
|
+
import * as Function from "effect/Function";
|
|
5
5
|
import * as Predicate from "effect/Predicate";
|
|
6
6
|
import * as Runtime from "effect/Runtime";
|
|
7
|
-
import
|
|
8
|
-
export const isStream = (u) => Predicate.hasProperty(u, StreamTypeId);
|
|
7
|
+
import * as Stream from "effect/Stream";
|
|
8
|
+
export const isStream = (u) => Predicate.hasProperty(u, Stream.StreamTypeId);
|
|
9
9
|
/**
|
|
10
10
|
* Patched version of original Stream.toReadableStreamRuntime (v3.14.4) to
|
|
11
11
|
* fix an issue in Bun when native stream controller stops working when request
|
|
@@ -17,14 +17,14 @@ export const isStream = (u) => Predicate.hasProperty(u, StreamTypeId);
|
|
|
17
17
|
* https://github.com/Effect-TS/effect/issues/4538
|
|
18
18
|
* https://github.com/oven-sh/bun/issues/17837
|
|
19
19
|
*/
|
|
20
|
-
export const toReadableStreamRuntimePatched = dual((args) => Predicate.hasProperty(args[0], StreamTypeId) || Effect.isEffect(args[0]), (self, runtime, options) => {
|
|
20
|
+
export const toReadableStreamRuntimePatched = Function.dual((args) => Predicate.hasProperty(args[0], Stream.StreamTypeId) || Effect.isEffect(args[0]), (self, runtime, options) => {
|
|
21
21
|
const runFork = Runtime.runFork(runtime);
|
|
22
22
|
let currentResolve = undefined;
|
|
23
23
|
let fiber = undefined;
|
|
24
24
|
const latch = Effect.unsafeMakeLatch(false);
|
|
25
25
|
return new ReadableStream({
|
|
26
26
|
start(controller) {
|
|
27
|
-
fiber = runFork(runForEachChunk(self, (chunk) => latch.whenOpen(Effect.sync(() => {
|
|
27
|
+
fiber = runFork(Stream.runForEachChunk(self, (chunk) => latch.whenOpen(Effect.sync(() => {
|
|
28
28
|
latch.unsafeClose();
|
|
29
29
|
try {
|
|
30
30
|
for (const item of chunk) {
|
|
@@ -32,8 +32,8 @@ export const toReadableStreamRuntimePatched = dual((args) => Predicate.hasProper
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
catch (e) {
|
|
35
|
-
if (e.message
|
|
36
|
-
|
|
35
|
+
if (e.message ===
|
|
36
|
+
`Value of "this" must be of type ReadableStreamDefaultController`) {
|
|
37
37
|
// Do nothing when this happens in Bun.
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
@@ -60,7 +60,7 @@ export const toReadableStreamRuntimePatched = dual((args) => Predicate.hasProper
|
|
|
60
60
|
},
|
|
61
61
|
}, options?.strategy);
|
|
62
62
|
});
|
|
63
|
-
export const toReadableStreamRuntimePatched2 = dual((args) => Predicate.hasProperty(args[0], StreamTypeId) || Effect.isEffect(args[0]), (self, runtime, options) => {
|
|
63
|
+
export const toReadableStreamRuntimePatched2 = Function.dual((args) => Predicate.hasProperty(args[0], Stream.StreamTypeId) || Effect.isEffect(args[0]), (self, runtime, options) => {
|
|
64
64
|
const runSync = Runtime.runSync(runtime);
|
|
65
65
|
const runFork = Runtime.runFork(runtime);
|
|
66
66
|
let currentResolve = undefined;
|
|
@@ -68,7 +68,7 @@ export const toReadableStreamRuntimePatched2 = dual((args) => Predicate.hasPrope
|
|
|
68
68
|
const latch = Effect.unsafeMakeLatch(false);
|
|
69
69
|
return new ReadableStream({
|
|
70
70
|
start(controller) {
|
|
71
|
-
fiber = runFork(runForEachChunk(self, (chunk) => latch.whenOpen(Effect.sync(() => {
|
|
71
|
+
fiber = runFork(Stream.runForEachChunk(self, (chunk) => latch.whenOpen(Effect.sync(() => {
|
|
72
72
|
latch.unsafeClose();
|
|
73
73
|
for (const item of chunk) {
|
|
74
74
|
controller.enqueue(item);
|
package/dist/System.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import type * as Scope from "effect/Scope";
|
|
3
|
+
import * as ChildProcess from "./ChildProcess.ts";
|
|
4
|
+
import * as PlatformError from "./PlatformError.ts";
|
|
5
|
+
export declare const cwd: Effect.Effect<string>;
|
|
6
|
+
export declare const which: (name: string) => Effect.Effect<string, PlatformError.SystemError>;
|
|
7
|
+
export declare const spawn: (command: string, args?: ReadonlyArray<string>, options?: ChildProcess.Command.Options) => Effect.Effect<ChildProcess.ChildProcessHandle, PlatformError.PlatformError, ChildProcess.ChildProcessSpawner | Scope.Scope>;
|