@effect/sql-mssql 4.0.0-beta.7 → 4.0.0-beta.70
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/MssqlClient.d.ts +62 -15
- package/dist/MssqlClient.d.ts.map +1 -1
- package/dist/MssqlClient.js +155 -37
- package/dist/MssqlClient.js.map +1 -1
- package/dist/MssqlMigrator.d.ts +30 -5
- package/dist/MssqlMigrator.d.ts.map +1 -1
- package/dist/MssqlMigrator.js +8 -4
- package/dist/MssqlMigrator.js.map +1 -1
- package/dist/Parameter.d.ts +14 -6
- package/dist/Parameter.d.ts.map +1 -1
- package/dist/Parameter.js +28 -4
- package/dist/Parameter.js.map +1 -1
- package/dist/Procedure.d.ts +41 -16
- package/dist/Procedure.d.ts.map +1 -1
- package/dist/Procedure.js +37 -8
- package/dist/Procedure.js.map +1 -1
- package/dist/index.d.ts +90 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/MssqlClient.ts +222 -36
- package/src/MssqlMigrator.ts +30 -5
- package/src/Parameter.ts +35 -7
- package/src/Procedure.ts +60 -18
- package/src/index.ts +90 -6
package/src/Procedure.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Typed builders for Microsoft SQL Server stored procedure definitions.
|
|
3
|
+
*
|
|
4
|
+
* This module describes the metadata consumed by `MssqlClient.call`: create a
|
|
5
|
+
* definition with `make`, add input and output parameters with their Tedious
|
|
6
|
+
* data types and `ParameterOptions`, optionally describe the returned row shape
|
|
7
|
+
* with `withRows`, and use `compile` to bind the input values before execution.
|
|
8
|
+
* It is useful when application code calls stored procedures for commands,
|
|
9
|
+
* reports, migrations, or workflows that return both result sets and output
|
|
10
|
+
* parameters.
|
|
11
|
+
*
|
|
12
|
+
* Parameter value types are supplied explicitly through `param<A>()` and
|
|
13
|
+
* `outputParam<A>()`; they are not inferred from the Tedious data type. Input
|
|
14
|
+
* values must be keyed by the parameter names in the definition, output
|
|
15
|
+
* parameters are collected separately from returned rows, and `withRows` only
|
|
16
|
+
* records the expected TypeScript row type, so row names and transforms still
|
|
17
|
+
* follow the configured `MssqlClient` result handling.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import { identity } from "effect/Function"
|
|
5
22
|
import type { Pipeable } from "effect/Pipeable"
|
|
@@ -11,20 +28,26 @@ import type { ParameterOptions } from "tedious/lib/request.ts"
|
|
|
11
28
|
import * as Parameter from "./Parameter.ts"
|
|
12
29
|
|
|
13
30
|
/**
|
|
31
|
+
* Runtime type identifier used to mark SQL Server stored procedure definitions.
|
|
32
|
+
*
|
|
14
33
|
* @category type id
|
|
15
|
-
* @since
|
|
34
|
+
* @since 4.0.0
|
|
16
35
|
*/
|
|
17
36
|
export const TypeId: TypeId = "~@effect/sql-mssql/Procedure"
|
|
18
37
|
|
|
19
38
|
/**
|
|
39
|
+
* Type-level identifier used to mark SQL Server stored procedure definitions.
|
|
40
|
+
*
|
|
20
41
|
* @category type id
|
|
21
|
-
* @since
|
|
42
|
+
* @since 4.0.0
|
|
22
43
|
*/
|
|
23
44
|
export type TypeId = "~@effect/sql-mssql/Procedure"
|
|
24
45
|
|
|
25
46
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
47
|
+
* Pipeable definition of a SQL Server stored procedure, tracking its input parameters, output parameters, and result row type.
|
|
48
|
+
*
|
|
49
|
+
* @category models
|
|
50
|
+
* @since 4.0.0
|
|
28
51
|
*/
|
|
29
52
|
export interface Procedure<
|
|
30
53
|
I extends Record<string, Parameter.Parameter<any>>,
|
|
@@ -41,8 +64,10 @@ export interface Procedure<
|
|
|
41
64
|
}
|
|
42
65
|
|
|
43
66
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
67
|
+
* Stored procedure definition with concrete input values bound for execution.
|
|
68
|
+
*
|
|
69
|
+
* @category models
|
|
70
|
+
* @since 4.0.0
|
|
46
71
|
*/
|
|
47
72
|
export interface ProcedureWithValues<
|
|
48
73
|
I extends Record<string, Parameter.Parameter<any>>,
|
|
@@ -53,11 +78,16 @@ export interface ProcedureWithValues<
|
|
|
53
78
|
}
|
|
54
79
|
|
|
55
80
|
/**
|
|
56
|
-
*
|
|
81
|
+
* Namespace containing type helpers and result types for SQL Server stored procedures.
|
|
82
|
+
*
|
|
83
|
+
* @since 4.0.0
|
|
57
84
|
*/
|
|
58
|
-
export namespace Procedure {
|
|
85
|
+
export declare namespace Procedure {
|
|
59
86
|
/**
|
|
60
|
-
*
|
|
87
|
+
* Maps a record of `Parameter` metadata to the corresponding record of parameter value types.
|
|
88
|
+
*
|
|
89
|
+
* @category utility types
|
|
90
|
+
* @since 4.0.0
|
|
61
91
|
*/
|
|
62
92
|
export type ParametersRecord<
|
|
63
93
|
A extends Record<string, Parameter.Parameter<any>>
|
|
@@ -69,8 +99,10 @@ export namespace Procedure {
|
|
|
69
99
|
& {}
|
|
70
100
|
|
|
71
101
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
102
|
+
* Result of a SQL Server stored procedure call, containing typed output parameter values and returned rows.
|
|
103
|
+
*
|
|
104
|
+
* @category models
|
|
105
|
+
* @since 4.0.0
|
|
74
106
|
*/
|
|
75
107
|
export interface Result<
|
|
76
108
|
O extends Record<string, Parameter.Parameter<any>>,
|
|
@@ -94,8 +126,10 @@ const procedureProto = {
|
|
|
94
126
|
}
|
|
95
127
|
|
|
96
128
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
129
|
+
* Creates an empty SQL Server stored procedure definition for the given procedure name.
|
|
130
|
+
*
|
|
131
|
+
* @category constructors
|
|
132
|
+
* @since 4.0.0
|
|
99
133
|
*/
|
|
100
134
|
export const make = (name: string): Procedure<{}, {}> => {
|
|
101
135
|
const procedure = Object.create(procedureProto)
|
|
@@ -106,8 +140,10 @@ export const make = (name: string): Procedure<{}, {}> => {
|
|
|
106
140
|
}
|
|
107
141
|
|
|
108
142
|
/**
|
|
143
|
+
* Adds a typed input parameter to a SQL Server stored procedure definition.
|
|
144
|
+
*
|
|
109
145
|
* @category combinator
|
|
110
|
-
* @since
|
|
146
|
+
* @since 4.0.0
|
|
111
147
|
*/
|
|
112
148
|
export const param = <A>() =>
|
|
113
149
|
<N extends string, T extends DataType>(
|
|
@@ -129,8 +165,10 @@ export const param = <A>() =>
|
|
|
129
165
|
})
|
|
130
166
|
|
|
131
167
|
/**
|
|
168
|
+
* Adds a typed output parameter to a SQL Server stored procedure definition.
|
|
169
|
+
*
|
|
132
170
|
* @category combinator
|
|
133
|
-
* @since
|
|
171
|
+
* @since 4.0.0
|
|
134
172
|
*/
|
|
135
173
|
export const outputParam = <A>() =>
|
|
136
174
|
<N extends string, T extends DataType>(
|
|
@@ -152,8 +190,10 @@ export const outputParam = <A>() =>
|
|
|
152
190
|
})
|
|
153
191
|
|
|
154
192
|
/**
|
|
193
|
+
* Sets the expected row type for a SQL Server stored procedure definition.
|
|
194
|
+
*
|
|
155
195
|
* @category combinator
|
|
156
|
-
* @since
|
|
196
|
+
* @since 4.0.0
|
|
157
197
|
*/
|
|
158
198
|
export const withRows = <A extends object = Row>() =>
|
|
159
199
|
<
|
|
@@ -164,8 +204,10 @@ export const withRows = <A extends object = Row>() =>
|
|
|
164
204
|
): Procedure<I, O, A> => self as any
|
|
165
205
|
|
|
166
206
|
/**
|
|
207
|
+
* Binds input values to a SQL Server stored procedure definition, producing a value that can be executed with `MssqlClient.call`.
|
|
208
|
+
*
|
|
167
209
|
* @category combinator
|
|
168
|
-
* @since
|
|
210
|
+
* @since 4.0.0
|
|
169
211
|
*/
|
|
170
212
|
export const compile = <
|
|
171
213
|
I extends Record<string, Parameter.Parameter<any>>,
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export {
|
|
6
6
|
/**
|
|
7
|
-
* @since
|
|
7
|
+
* @since 4.0.0
|
|
8
8
|
*/
|
|
9
9
|
TYPES as MssqlTypes
|
|
10
10
|
} from "tedious"
|
|
@@ -12,21 +12,105 @@ export {
|
|
|
12
12
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Microsoft SQL Server client implementation for Effect SQL, backed by the
|
|
16
|
+
* `tedious` driver.
|
|
17
|
+
*
|
|
18
|
+
* This module provides the `MssqlClient` service and layers that also satisfy
|
|
19
|
+
* the generic `SqlClient` service. It is intended for server applications,
|
|
20
|
+
* background workers, migrations, and tests that need SQL Server query
|
|
21
|
+
* compilation, Tedious parameter typing, scoped connection management,
|
|
22
|
+
* transactions, and typed stored procedure calls.
|
|
23
|
+
*
|
|
24
|
+
* Clients own a scoped pool of Tedious connections and validate startup with
|
|
25
|
+
* `SELECT 1`. Regular queries borrow a pooled connection per operation, while
|
|
26
|
+
* transactions keep one pooled connection for their lifetime and use SQL Server
|
|
27
|
+
* savepoints for nested transactions. Long-running transactions therefore
|
|
28
|
+
* reduce available pool capacity; size `maxConnections`, `connectionTTL`, and
|
|
29
|
+
* `connectTimeout` accordingly.
|
|
30
|
+
*
|
|
31
|
+
* Tedious permits one active request per connection. This client compiles
|
|
32
|
+
* statements with named `@1`-style parameters, maps Effect SQL primitive values
|
|
33
|
+
* to Tedious `DataType`s unless `param` is used, and does not implement
|
|
34
|
+
* streaming queries. Be deliberate about TLS options: `encrypt` defaults to
|
|
35
|
+
* `false` and `trustServerCertificate` defaults to `true` unless overridden.
|
|
36
|
+
* Stored procedure calls go through `callProcedure`; define input and output
|
|
37
|
+
* parameters with the `Procedure` and `Parameter` helpers so Tedious receives
|
|
38
|
+
* the correct data types and output values can be collected from `returnValue`
|
|
39
|
+
* events.
|
|
40
|
+
*
|
|
41
|
+
* @since 4.0.0
|
|
16
42
|
*/
|
|
17
43
|
export * as MssqlClient from "./MssqlClient.ts"
|
|
18
44
|
|
|
19
45
|
/**
|
|
20
|
-
*
|
|
46
|
+
* Utilities for applying Effect SQL migrations to Microsoft SQL Server.
|
|
47
|
+
*
|
|
48
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
49
|
+
* provides `run` and `layer` helpers for applying ordered migrations through
|
|
50
|
+
* the current SQL Server `SqlClient`. It is typically used at application
|
|
51
|
+
* startup, during deployment, in integration tests that provision temporary SQL
|
|
52
|
+
* Server databases, or in layer graphs that need the database schema to be
|
|
53
|
+
* current before dependent services are acquired.
|
|
54
|
+
*
|
|
55
|
+
* Applied migrations are stored in `effect_sql_migrations` by default and use
|
|
56
|
+
* the shared `<id>_<name>` loader convention. Only migrations with ids greater
|
|
57
|
+
* than the latest recorded id are run, so avoid inserting older migration ids
|
|
58
|
+
* after a later migration has reached production. SQL Server migrations run
|
|
59
|
+
* inside the shared migrator transaction and this adapter does not add a
|
|
60
|
+
* dialect-specific table lock, so coordinate concurrent startup runners and
|
|
61
|
+
* write T-SQL that is valid inside an explicit transaction. Remember that `GO`
|
|
62
|
+
* is a client-side batch separator rather than a T-SQL statement, and split
|
|
63
|
+
* migrations when SQL Server requires an object definition such as `CREATE
|
|
64
|
+
* VIEW`, `CREATE PROCEDURE`, or `CREATE TRIGGER` to start its own batch. This
|
|
65
|
+
* adapter also does not emit SQL Server schema dumps for `schemaDirectory`.
|
|
66
|
+
*
|
|
67
|
+
* @since 4.0.0
|
|
21
68
|
*/
|
|
22
69
|
export * as MssqlMigrator from "./MssqlMigrator.ts"
|
|
23
70
|
|
|
24
71
|
/**
|
|
25
|
-
*
|
|
72
|
+
* Typed metadata for SQL Server stored procedure parameters.
|
|
73
|
+
*
|
|
74
|
+
* This module records the bare parameter name, Tedious `DataType`, Tedious
|
|
75
|
+
* `ParameterOptions`, and phantom TypeScript value type used by
|
|
76
|
+
* `Procedure.param` and `Procedure.outputParam`. `MssqlClient.call` later
|
|
77
|
+
* forwards input parameters to Tedious with `Request.addParameter` and output
|
|
78
|
+
* parameters with `Request.addOutputParameter`, so names should match the
|
|
79
|
+
* stored procedure parameter name without a leading `@`.
|
|
80
|
+
*
|
|
81
|
+
* Use these values when defining stored procedures that need explicit SQL
|
|
82
|
+
* Server parameter metadata, such as sized strings or binary values, decimal
|
|
83
|
+
* precision/scale, table-valued parameters, and output parameters. The generic
|
|
84
|
+
* type parameter is only a compile-time guide for the value record accepted by
|
|
85
|
+
* `Procedure.compile`; Tedious still validates and encodes the runtime value.
|
|
86
|
+
* In particular, TVP values must use Tedious' table shape with `name`,
|
|
87
|
+
* optional `schema`, `columns`, and `rows`, and output parameters are registered
|
|
88
|
+
* with no initial value, so SQL Server input-output parameters need separate
|
|
89
|
+
* care rather than assuming an output parameter is populated from compiled
|
|
90
|
+
* input values.
|
|
91
|
+
*
|
|
92
|
+
* @since 4.0.0
|
|
26
93
|
*/
|
|
27
94
|
export * as Parameter from "./Parameter.ts"
|
|
28
95
|
|
|
29
96
|
/**
|
|
30
|
-
*
|
|
97
|
+
* Typed builders for Microsoft SQL Server stored procedure definitions.
|
|
98
|
+
*
|
|
99
|
+
* This module describes the metadata consumed by `MssqlClient.call`: create a
|
|
100
|
+
* definition with `make`, add input and output parameters with their Tedious
|
|
101
|
+
* data types and `ParameterOptions`, optionally describe the returned row shape
|
|
102
|
+
* with `withRows`, and use `compile` to bind the input values before execution.
|
|
103
|
+
* It is useful when application code calls stored procedures for commands,
|
|
104
|
+
* reports, migrations, or workflows that return both result sets and output
|
|
105
|
+
* parameters.
|
|
106
|
+
*
|
|
107
|
+
* Parameter value types are supplied explicitly through `param<A>()` and
|
|
108
|
+
* `outputParam<A>()`; they are not inferred from the Tedious data type. Input
|
|
109
|
+
* values must be keyed by the parameter names in the definition, output
|
|
110
|
+
* parameters are collected separately from returned rows, and `withRows` only
|
|
111
|
+
* records the expected TypeScript row type, so row names and transforms still
|
|
112
|
+
* follow the configured `MssqlClient` result handling.
|
|
113
|
+
*
|
|
114
|
+
* @since 4.0.0
|
|
31
115
|
*/
|
|
32
116
|
export * as Procedure from "./Procedure.ts"
|