@formancy/data-sqlserver 0.0.0-stage → 0.1.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.
@@ -0,0 +1,115 @@
1
+ import { DatabaseAdapter, DiscoveryScope, LookupAdapter, MetadataSnapshot, RecordAdapter } from "@formancy/data-core";
2
+ import { ConnectionPool } from "mssql";
3
+ //#region src/adapter.d.ts
4
+ /**
5
+ * SQL Server, through a pool the composition root connected.
6
+ *
7
+ * The pool rather than a connection string: opening the connection is where a
8
+ * secret is handled, and that happens once, in the composition root, where the
9
+ * secret resolver lives. Nothing in this package reads configuration, and the
10
+ * tests hand it a pool pointed at a container.
11
+ *
12
+ * `ConnectionPool` is in this signature, which is why `@types/mssql` is a
13
+ * dependency of this package and not a devDependency: a consumer type-checking
14
+ * against the published declarations needs it, and `skipLibCheck` would not
15
+ * save them, since the import is in OUR declaration file. The install gate
16
+ * runs with `skipLibCheck` off for exactly this.
17
+ */
18
+ export declare function createSqlServerAdapter(pool: ConnectionPool): DatabaseAdapter;
19
+ //#endregion
20
+ //#region src/discovery/discover.d.ts
21
+ /**
22
+ * What this connection's account can see of the tables and views in `scope`,
23
+ * what it may do with each column, whether a security policy filters each
24
+ * object for it -- and, as gaps, what it cannot establish (0007, 0027) --
25
+ * whether it may delete from each, and every key it can see that refers to
26
+ * each, from any schema (0049).
27
+ *
28
+ * Read from SQL Server's catalog views, never INFORMATION_SCHEMA, which carries
29
+ * neither the trust and disable flags of a key nor rowversion nor extended
30
+ * properties (0004). One catalog concern per query, each bound to the scope by
31
+ * parameters; they run side by side and are not one consistent read. A
32
+ * concurrent ALTER can tear the result, in which case createSnapshot refuses
33
+ * what no catalog could produce, or drift review sees the change next time.
34
+ * A column and its privileges are one read (access.ts), so no column lacks
35
+ * an answer; a concurrent rename can still make that answer a false "no".
36
+ *
37
+ * Unlike PostgreSQL's, this catalog is filtered by permission: an object the
38
+ * account holds nothing on is absent, behind a schema gap, a security policy
39
+ * it cannot see leaves row security `unknown`, behind a scope gap, and a key
40
+ * on a table it cannot see is missing from what refers to a table, behind
41
+ * another. A graph edge constraint, which is not a foreign key, is a gap on
42
+ * each node table it connects, for any account (referenced-by.ts).
43
+ *
44
+ * The pool is the caller's. Nothing here opens a connection or reads
45
+ * configuration, and nothing here closes the pool.
46
+ */
47
+ export declare function discoverSqlServer(pool: ConnectionPool, scope: DiscoveryScope): Promise<MetadataSnapshot>;
48
+ //#endregion
49
+ //#region src/lookups/lookups.d.ts
50
+ /**
51
+ * The lookup half of the SQL Server adapter, through a pool the composition
52
+ * root connected.
53
+ *
54
+ * Every answer is decided by `@formancy/data-core`'s helpers — which tokens
55
+ * are asked about, how a page knows there is more, when a token is a member —
56
+ * and this only queries. The filters are read with `rowFilterTerms` before
57
+ * anything is built, so a request without a policy fails instead of seeing
58
+ * every row, and they are part of the same statement as the rest.
59
+ *
60
+ * What SQL Server decides on its own, and the adapter does not hide: how a
61
+ * search matches and how text orders is the column's collation, so on a
62
+ * case-insensitive database a search for `muster` finds `Muster AG` and
63
+ * `apple` sorts before `Banana`; and equality ignores trailing spaces, which
64
+ * is why membership is the re-encoded row's and never the database's match
65
+ * (0012). A filter is the exception: it compares the column's canonical value
66
+ * with its trusted value exactly — case, accents and trailing spaces count —
67
+ * as PostgreSQL's does, and still seeks an nvarchar column's index
68
+ * (../sql/filters.ts, 0028). A label is the record reader's value, spelled by
69
+ * `displayText`, so it reads the same on both engines.
70
+ *
71
+ * A database error propagates: a lookup that cannot answer refuses, and
72
+ * formancy turns that into a refused submission.
73
+ *
74
+ * Every statement runs until the caller's signal aborts, and is then stopped
75
+ * in the database by `request.cancel()`, a TDS attention (0061,
76
+ * ../sql/statement.ts). A signal already aborted is refused before the
77
+ * filters are read or a key is parsed, so a request already gone costs
78
+ * nothing. The pool is the one records use: an attention travels on the
79
+ * statement's own connection, so unlike PostgreSQL's cancel request it
80
+ * cannot stop anyone else's statement. No per-request `requestTimeout` is
81
+ * set; mssql's default of 15 s, which it hands tedious for every request
82
+ * (lib/tedious/connection-pool.js), still bounds every statement.
83
+ */
84
+ export declare function createSqlServerLookups(pool: ConnectionPool): LookupAdapter;
85
+ //#endregion
86
+ //#region src/records/records.d.ts
87
+ export declare function createSqlServerRecords(pool: ConnectionPool): RecordAdapter;
88
+ //#endregion
89
+ //#region src/connect.d.ts
90
+ interface SqlServerConnectOptions {
91
+ host: string;
92
+ port: number;
93
+ database: string;
94
+ user: string;
95
+ password: string;
96
+ /** TLS. The composition root decides; there is no default here to forget. */
97
+ encrypt: boolean;
98
+ trustServerCertificate: boolean;
99
+ }
100
+ /**
101
+ * A connected pool, from this package's own copy of mssql.
102
+ *
103
+ * Why the adapter package opens its own connections: mssql's parameter types
104
+ * are objects tedious checks by identity, and this package binds every value
105
+ * with `mssql.NVarChar` and friends from ITS copy. A pool built from another
106
+ * copy — two installs of mssql@12.7.4 that differ only in which supports-color
107
+ * satisfied an optional peer, which is exactly what pnpm produced for the
108
+ * server — refuses every parameter with "type.validate is not a function".
109
+ * Found by the end-to-end suite; no unit test could see it. Opening the pool
110
+ * here means the pool and the types always come from one copy.
111
+ */
112
+ export declare function connectSqlServer(options: SqlServerConnectOptions): Promise<ConnectionPool>;
113
+ //#endregion
114
+ export type { SqlServerConnectOptions };
115
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/adapter.ts","../src/discovery/discover.ts","../src/lookups/lookups.ts","../src/records/records.ts","../src/connect.ts"],"mappings":";;;;;;;;;;;;;;;;;wBAmBgB,uBAAuB,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCuBxC,kBAAkB,MAAM,gBAAgB,OAAO,iBAAiB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCsC9E,uBAAuB,MAAM,iBAAiB;;;wBCyD9C,uBAAuB,MAAM,iBAAiB;;;UCtI7C;EACf;EACA;EACA;EACA;EACA;;EAEA;EACA;;;;;;;;;;;;;;wBAec,iBAAiB,SAAS,0BAA0B,QAAQ"}