@noormdev/sdk 1.0.0-alpha.9 → 1.0.1

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,7 @@
1
+ import { createRequire } from 'module';
2
+ export { loadJson5 } from './chunk-TBRUDUBQ.js';
3
+ import './chunk-D2XW2UOP.js';
4
+
5
+ createRequire(import.meta.url);
6
+ //# sourceMappingURL=json5-LNT3RGJ7.js.map
7
+ //# sourceMappingURL=json5-LNT3RGJ7.js.map
@@ -0,0 +1,161 @@
1
+ import { createRequire } from 'module';
2
+ import { DEFAULT_PORTS } from './chunk-SPU42W75.js';
3
+ import './chunk-D2XW2UOP.js';
4
+ import { isIP } from 'net';
5
+ import { Kysely, MssqlDialect, sql, OperationNodeTransformer } from 'kysely';
6
+
7
+ createRequire(import.meta.url);
8
+ var LimitToTopTransformer = class extends OperationNodeTransformer {
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ transformSelectQuery(node) {
11
+ const transformed = super.transformSelectQuery(node);
12
+ if (!transformed.limit || transformed.top) {
13
+ return transformed;
14
+ }
15
+ const limitOp = transformed.limit.limit;
16
+ let value;
17
+ if (limitOp?.kind === "ValueNode" && (typeof limitOp.value === "number" || typeof limitOp.value === "bigint")) {
18
+ value = limitOp.value;
19
+ }
20
+ if (value === void 0) {
21
+ return transformed;
22
+ }
23
+ return {
24
+ ...transformed,
25
+ limit: void 0,
26
+ top: {
27
+ kind: "TopNode",
28
+ expression: value
29
+ }
30
+ };
31
+ }
32
+ };
33
+ var MssqlLimitPlugin = class {
34
+ #transformer = new LimitToTopTransformer();
35
+ transformQuery(args) {
36
+ return this.#transformer.transformNode(args.node);
37
+ }
38
+ async transformResult(args) {
39
+ return args.result;
40
+ }
41
+ };
42
+
43
+ // src/core/connection/dialects/mssql.ts
44
+ var UNVERIFIED_TLS_SERVER_NAME = "noorm-unverified.invalid";
45
+ var MssqlTlsServerNameError = class extends Error {
46
+ constructor(host, message) {
47
+ super(message);
48
+ this.host = host;
49
+ }
50
+ name = "MssqlTlsServerNameError";
51
+ };
52
+ function resolveTlsServerName(config) {
53
+ const host = config.host ?? "localhost";
54
+ const supplied = config.tlsServerName;
55
+ const validatingCertificate = !!config.ssl;
56
+ if (supplied && isIP(supplied) !== 0) {
57
+ throw new MssqlTlsServerNameError(
58
+ host,
59
+ `Invalid tlsServerName '${supplied}': a TLS ServerName must be a hostname, not an IP address. Set it to the hostname the server's certificate is issued for.`
60
+ );
61
+ }
62
+ if (supplied) {
63
+ return supplied;
64
+ }
65
+ if (isIP(host) === 0) {
66
+ return void 0;
67
+ }
68
+ if (validatingCertificate) {
69
+ throw new MssqlTlsServerNameError(
70
+ host,
71
+ `Cannot verify the TLS certificate of MSSQL host '${host}': a certificate cannot be validated against an IP address, because TLS forbids sending one as the ServerName. Set connection.tlsServerName to the hostname the server's certificate is issued for, or connect using that hostname instead.`
72
+ );
73
+ }
74
+ return UNVERIFIED_TLS_SERVER_NAME;
75
+ }
76
+ function buildTediousOptions(config, database) {
77
+ return {
78
+ server: config.host ?? "localhost",
79
+ authentication: {
80
+ type: "default",
81
+ options: {
82
+ userName: config.user,
83
+ password: config.password
84
+ }
85
+ },
86
+ options: {
87
+ port: config.port ?? DEFAULT_PORTS.mssql,
88
+ database: database ?? config.database,
89
+ trustServerCertificate: !config.ssl,
90
+ encrypt: true,
91
+ serverName: resolveTlsServerName(config)
92
+ }
93
+ };
94
+ }
95
+ function buildTediousConfig(Tedious, config, database) {
96
+ return new Tedious.Connection(buildTediousOptions(config, database));
97
+ }
98
+ async function verifyDatabaseExists(Tedious, Tarn, config) {
99
+ const masterDb = new Kysely({
100
+ dialect: new MssqlDialect({
101
+ tarn: {
102
+ ...Tarn,
103
+ options: {
104
+ min: 0,
105
+ max: 1,
106
+ propagateCreateError: true
107
+ }
108
+ },
109
+ tedious: {
110
+ ...Tedious,
111
+ connectionFactory: () => buildTediousConfig(Tedious, config, "master")
112
+ }
113
+ }),
114
+ plugins: [new MssqlLimitPlugin()]
115
+ });
116
+ try {
117
+ const { rows } = await sql`
118
+ SELECT name FROM sys.databases WHERE name = ${config.database}
119
+ `.execute(masterDb);
120
+ if (rows.length === 0) {
121
+ throw new Error(
122
+ `Database '${config.database}' does not exist on ${config.host ?? "localhost"}:${config.port ?? DEFAULT_PORTS.mssql}`
123
+ );
124
+ }
125
+ } finally {
126
+ await masterDb.destroy();
127
+ }
128
+ }
129
+ async function createMssqlConnection(config) {
130
+ const TediousImport = await import('tedious');
131
+ const TarnImport = await import('tarn');
132
+ const Tedious = TediousImport.default ?? TediousImport;
133
+ const Tarn = TarnImport.default ?? TarnImport;
134
+ await verifyDatabaseExists(Tedious, Tarn, config);
135
+ const db = new Kysely({
136
+ dialect: new MssqlDialect({
137
+ tarn: {
138
+ ...Tarn,
139
+ options: {
140
+ min: config.pool?.min ?? 0,
141
+ max: config.pool?.max ?? 10,
142
+ propagateCreateError: true
143
+ }
144
+ },
145
+ tedious: {
146
+ ...Tedious,
147
+ connectionFactory: () => buildTediousConfig(Tedious, config)
148
+ }
149
+ }),
150
+ plugins: [new MssqlLimitPlugin()]
151
+ });
152
+ return {
153
+ db,
154
+ dialect: "mssql",
155
+ destroy: () => db.destroy()
156
+ };
157
+ }
158
+
159
+ export { MssqlTlsServerNameError, UNVERIFIED_TLS_SERVER_NAME, buildTediousOptions, createMssqlConnection, resolveTlsServerName };
160
+ //# sourceMappingURL=mssql-NL6OHOMO.js.map
161
+ //# sourceMappingURL=mssql-NL6OHOMO.js.map
@@ -1,12 +1,15 @@
1
+ import { createRequire } from 'module';
2
+ import { DEFAULT_PORTS } from './chunk-SPU42W75.js';
3
+ import './chunk-D2XW2UOP.js';
1
4
  import { Kysely, MysqlDialect } from 'kysely';
2
5
 
3
- // src/core/connection/dialects/mysql.ts
6
+ createRequire(import.meta.url);
4
7
  async function createMysqlConnection(config) {
5
8
  const mysql2 = await import('mysql2');
6
9
  const createPool = mysql2.default?.createPool ?? mysql2.createPool;
7
10
  const pool = createPool({
8
11
  host: config.host ?? "localhost",
9
- port: config.port ?? 3306,
12
+ port: config.port ?? DEFAULT_PORTS.mysql,
10
13
  user: config.user,
11
14
  password: config.password,
12
15
  database: config.database,
@@ -24,5 +27,5 @@ async function createMysqlConnection(config) {
24
27
  }
25
28
 
26
29
  export { createMysqlConnection };
27
- //# sourceMappingURL=mysql-C2DR4TF7.js.map
28
- //# sourceMappingURL=mysql-C2DR4TF7.js.map
30
+ //# sourceMappingURL=mysql-5P43DYBY.js.map
31
+ //# sourceMappingURL=mysql-5P43DYBY.js.map
@@ -1,12 +1,15 @@
1
+ import { createRequire } from 'module';
2
+ import { DEFAULT_PORTS } from './chunk-SPU42W75.js';
3
+ import './chunk-D2XW2UOP.js';
1
4
  import { Kysely, PostgresDialect } from 'kysely';
2
5
 
3
- // src/core/connection/dialects/postgres.ts
6
+ createRequire(import.meta.url);
4
7
  async function createPostgresConnection(config) {
5
8
  const pg = await import('pg');
6
9
  const Pool = pg.default?.Pool ?? pg.Pool;
7
10
  const pool = new Pool({
8
11
  host: config.host ?? "localhost",
9
- port: config.port ?? 5432,
12
+ port: config.port ?? DEFAULT_PORTS.postgres,
10
13
  user: config.user,
11
14
  password: config.password,
12
15
  database: config.database,
@@ -25,5 +28,5 @@ async function createPostgresConnection(config) {
25
28
  }
26
29
 
27
30
  export { createPostgresConnection };
28
- //# sourceMappingURL=postgres-SIDJBSIT.js.map
29
- //# sourceMappingURL=postgres-SIDJBSIT.js.map
31
+ //# sourceMappingURL=postgres-NIL5BE3O.js.map
32
+ //# sourceMappingURL=postgres-NIL5BE3O.js.map
@@ -1,7 +1,9 @@
1
+ import { createRequire } from 'module';
2
+ import './chunk-D2XW2UOP.js';
1
3
  import { Kysely, SqliteDialect } from 'kysely';
2
4
  import Database from 'better-sqlite3';
3
5
 
4
- // src/core/connection/dialects/sqlite.ts
6
+ createRequire(import.meta.url);
5
7
  function createSqliteConnection(config) {
6
8
  const filename = config.filename ?? config.database;
7
9
  const db = new Kysely({
@@ -17,5 +19,5 @@ function createSqliteConnection(config) {
17
19
  }
18
20
 
19
21
  export { createSqliteConnection };
20
- //# sourceMappingURL=sqlite-5VZTBN5J.js.map
21
- //# sourceMappingURL=sqlite-5VZTBN5J.js.map
22
+ //# sourceMappingURL=sqlite-F3ZSSDUM.js.map
23
+ //# sourceMappingURL=sqlite-F3ZSSDUM.js.map
@@ -0,0 +1,60 @@
1
+ import { createRequire } from 'module';
2
+ import './chunk-D2XW2UOP.js';
3
+ import { Kysely, SqliteDialect } from 'kysely';
4
+ import { Database } from 'bun:sqlite';
5
+
6
+ createRequire(import.meta.url);
7
+ var BunSqliteStatement = class {
8
+ #stmt;
9
+ constructor(stmt) {
10
+ this.#stmt = stmt;
11
+ }
12
+ get reader() {
13
+ return this.#stmt.columnNames.length > 0;
14
+ }
15
+ all(params) {
16
+ return this.#stmt.all(...params);
17
+ }
18
+ run(params) {
19
+ const result = this.#stmt.run(...params);
20
+ return {
21
+ changes: result.changes,
22
+ lastInsertRowid: result.lastInsertRowid
23
+ };
24
+ }
25
+ *iterate(params) {
26
+ const rows = this.#stmt.all(...params);
27
+ for (const row of rows) {
28
+ yield row;
29
+ }
30
+ }
31
+ };
32
+ var BunSqliteDatabase = class {
33
+ #db;
34
+ constructor(filename) {
35
+ this.#db = new Database(filename);
36
+ }
37
+ close() {
38
+ this.#db.close();
39
+ }
40
+ prepare(sql) {
41
+ return new BunSqliteStatement(this.#db.prepare(sql));
42
+ }
43
+ };
44
+ function createBunSqliteConnection(config) {
45
+ const filename = config.filename ?? config.database;
46
+ const db = new Kysely({
47
+ dialect: new SqliteDialect({
48
+ database: new BunSqliteDatabase(filename)
49
+ })
50
+ });
51
+ return {
52
+ db,
53
+ dialect: "sqlite",
54
+ destroy: () => db.destroy()
55
+ };
56
+ }
57
+
58
+ export { BunSqliteDatabase, createBunSqliteConnection };
59
+ //# sourceMappingURL=sqlite-bun-LMHUMGQI.js.map
60
+ //# sourceMappingURL=sqlite-bun-LMHUMGQI.js.map
@@ -0,0 +1,8 @@
1
+ import { createRequire } from 'module';
2
+ export { deleteVaultSecret, deleteVaultSecretChecked, getAllVaultSecrets, getVaultKey, getVaultKeyChecked, getVaultSecret, getVaultStatus, initializeVault, initializeVaultChecked, listVaultSecretKeys, listVaultSecretKeysChecked, setVaultSecret, setVaultSecretChecked, vaultSecretExists } from './chunk-2RW4SL2O.js';
3
+ import './chunk-QAECL4RN.js';
4
+ import './chunk-D2XW2UOP.js';
5
+
6
+ createRequire(import.meta.url);
7
+ //# sourceMappingURL=storage-6QBJ55SB.js.map
8
+ //# sourceMappingURL=storage-6QBJ55SB.js.map
@@ -0,0 +1,7 @@
1
+ import { createRequire } from 'module';
2
+ export { loadYaml } from './chunk-YJBKNUTP.js';
3
+ import './chunk-D2XW2UOP.js';
4
+
5
+ createRequire(import.meta.url);
6
+ //# sourceMappingURL=yaml-XI7RQ2D5.js.map
7
+ //# sourceMappingURL=yaml-XI7RQ2D5.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noormdev/sdk",
3
- "version": "1.0.0-alpha.9",
3
+ "version": "1.0.1",
4
4
  "description": "Database schema & changeset manager SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -8,12 +8,13 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "import": "./dist/index.js",
12
- "types": "./dist/index.d.ts"
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
13
  }
14
14
  },
15
15
  "files": [
16
- "dist"
16
+ "dist",
17
+ "!dist/**/*.map"
17
18
  ],
18
19
  "sideEffects": false,
19
20
  "peerDependencies": {
@@ -52,9 +53,9 @@
52
53
  "kysely",
53
54
  "noorm"
54
55
  ],
55
- "license": "ISC",
56
+ "license": "MIT",
56
57
  "repository": {
57
58
  "type": "git",
58
- "url": "https://github.com/noormdev/noorm"
59
+ "url": "git+https://github.com/noormdev/noorm.git"
59
60
  }
60
61
  }