azure-mock 2.20.0 → 2.22.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.
Files changed (45) hide show
  1. package/LICENSE +201 -201
  2. package/dist/better-sqlite3-CtLaF97z-DWR9uC3b.js +129 -0
  3. package/dist/chunk-2X2C5D2I-dJHtPFe9-DxsO-1YF.js +4026 -0
  4. package/dist/d1-pK2J-_yx-BoQTXsTa.js +185 -0
  5. package/dist/dialect-pBb6Cg_F-xgpUtfmk.js +570 -0
  6. package/dist/dist-C481edUb-CHbOkeXH.js +10131 -0
  7. package/dist/dist-DUzzleZr-DxHmeYjp.js +2 -0
  8. package/dist/index.d.ts +21 -21
  9. package/dist/index.js +20396 -18921
  10. package/dist/libsql-Nq-S0r5x-d2dAzhgO.js +240 -0
  11. package/dist/logger-TIsK7375-CLNNa25D.js +652 -0
  12. package/dist/migrator-B9kYwLqO-4g9JX3_v.js +8 -0
  13. package/dist/migrator-BfTfJctM-DrNlb1BS.js +8 -0
  14. package/dist/migrator-BjoW0_3j-CD-XdZ5a.js +8 -0
  15. package/dist/migrator-CWWlo_Jk-C4Hw4PPN.js +8 -0
  16. package/dist/migrator-CpiXRkls-COYfhljd.js +24 -0
  17. package/dist/migrator-CtqJkLVI-D1lU6ZV0.js +8 -0
  18. package/dist/migrator-CxcBjmET-Dcd21VIf.js +8 -0
  19. package/dist/migrator-Cyhbhxo_-Bh7sF0R3.js +21 -0
  20. package/dist/migrator-DG1mWUoR-DVfkqn_v.js +31 -0
  21. package/dist/migrator-DrWmHwY2-YjAfotd7.js +8 -0
  22. package/dist/migrator-WAPonQxA-CRvJJhKG.js +8 -0
  23. package/dist/migrator-Zdh8WMMx-gsmNXspd.js +8 -0
  24. package/dist/migrator-xRJ6NOTS-SsAuB-Gi.js +24 -0
  25. package/dist/migrator-xbWwvFYF-BjyVdQS8.js +8 -0
  26. package/dist/mysql2-DkoPEsRu-BMwVSCmY.js +251 -0
  27. package/dist/neon-serverless-BEVFA7yv-DGSPAG1z.js +205 -0
  28. package/dist/node-postgres-DQA7bEhW-CkM_cVLD.js +216 -0
  29. package/dist/nodefs-Bc8b83o_-DetP9qUa.js +24 -0
  30. package/dist/opfs-ahp-DbstDvx--CHskKtzG.js +365 -0
  31. package/dist/pg-ylxXyvKj-Hm8vcZoi.js +279 -0
  32. package/dist/pglite-CPs4w-D9-DHOg0D8W.js +179 -0
  33. package/dist/pglite-DMWgTUE6-BOIRUWUT.js +2 -0
  34. package/dist/planetscale-serverless-DUMheN-f-Dyc_W6V_.js +172 -0
  35. package/dist/query-builder-CLJAKedv-DTZiP7B6.js +1715 -0
  36. package/dist/query-builder-CT3_liD0-hhg5kRTk.js +1347 -0
  37. package/dist/session-BOEirggu-DTmpyU_x.js +2485 -0
  38. package/dist/session-CAUQtT0A-BoVK2x7A.js +745 -0
  39. package/dist/session-Cjeygn2Z-BO0mi6pq.js +989 -0
  40. package/dist/singlestore-Cdlo23hW-BuFJ4Zqb.js +1647 -0
  41. package/dist/sql-CNZp2yLp-Bwugq384.js +611 -0
  42. package/dist/sqlite-proxy-BgUfVEbZ-CsSkc-_K.js +190 -0
  43. package/dist/src-LcyXhCXE-C_vKJiLK.js +1920 -0
  44. package/dist/vercel-postgres-BYmFKsTS-CpV2usun.js +203 -0
  45. package/package.json +7 -8
@@ -0,0 +1,240 @@
1
+ import { C as sql, _ as fillPlaceholders, g as entityKind } from "./sql-CNZp2yLp-Bwugq384.js";
2
+ import { M as mapResultRow, O as isConfig, n as DefaultLogger, o as NoopCache, s as NoopLogger, x as extractTablesRelationalConfig, y as createTableRelationsHelpers } from "./logger-TIsK7375-CLNNa25D.js";
3
+ import { n as SQLiteAsyncDialect } from "./query-builder-CT3_liD0-hhg5kRTk.js";
4
+ import { i as SQLiteTransaction, n as SQLitePreparedQuery, r as SQLiteSession, t as BaseSQLiteDatabase } from "./session-Cjeygn2Z-BO0mi6pq.js";
5
+ import { createClient } from "@libsql/client";
6
+ //#region ../db/dist/libsql-Nq-S0r5x.js
7
+ var LibSQLSession = class LibSQLSession extends SQLiteSession {
8
+ constructor(client, dialect, schema, options, tx) {
9
+ super(dialect);
10
+ this.client = client;
11
+ this.schema = schema;
12
+ this.options = options;
13
+ this.tx = tx;
14
+ this.logger = options.logger ?? new NoopLogger();
15
+ this.cache = options.cache ?? new NoopCache();
16
+ }
17
+ static [entityKind] = "LibSQLSession";
18
+ logger;
19
+ cache;
20
+ prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
21
+ return new LibSQLPreparedQuery(this.client, query, this.logger, this.cache, queryMetadata, cacheConfig, fields, this.tx, executeMethod, isResponseInArrayMode, customResultMapper);
22
+ }
23
+ async batch(queries) {
24
+ const preparedQueries = [];
25
+ const builtQueries = [];
26
+ for (const query of queries) {
27
+ const preparedQuery = query._prepare();
28
+ const builtQuery = preparedQuery.getQuery();
29
+ preparedQueries.push(preparedQuery);
30
+ builtQueries.push({
31
+ sql: builtQuery.sql,
32
+ args: builtQuery.params
33
+ });
34
+ }
35
+ return (await this.client.batch(builtQueries)).map((result, i) => preparedQueries[i].mapResult(result, true));
36
+ }
37
+ async migrate(queries) {
38
+ const preparedQueries = [];
39
+ const builtQueries = [];
40
+ for (const query of queries) {
41
+ const preparedQuery = query._prepare();
42
+ const builtQuery = preparedQuery.getQuery();
43
+ preparedQueries.push(preparedQuery);
44
+ builtQueries.push({
45
+ sql: builtQuery.sql,
46
+ args: builtQuery.params
47
+ });
48
+ }
49
+ return (await this.client.migrate(builtQueries)).map((result, i) => preparedQueries[i].mapResult(result, true));
50
+ }
51
+ async transaction(transaction, _config) {
52
+ const libsqlTx = await this.client.transaction();
53
+ const session = new LibSQLSession(this.client, this.dialect, this.schema, this.options, libsqlTx);
54
+ const tx = new LibSQLTransaction("async", this.dialect, session, this.schema);
55
+ try {
56
+ const result = await transaction(tx);
57
+ await libsqlTx.commit();
58
+ return result;
59
+ } catch (err) {
60
+ await libsqlTx.rollback();
61
+ throw err;
62
+ }
63
+ }
64
+ extractRawAllValueFromBatchResult(result) {
65
+ return result.rows;
66
+ }
67
+ extractRawGetValueFromBatchResult(result) {
68
+ return result.rows[0];
69
+ }
70
+ extractRawValuesValueFromBatchResult(result) {
71
+ return result.rows;
72
+ }
73
+ };
74
+ var LibSQLTransaction = class LibSQLTransaction extends SQLiteTransaction {
75
+ static [entityKind] = "LibSQLTransaction";
76
+ async transaction(transaction) {
77
+ const savepointName = `sp${this.nestedIndex}`;
78
+ const tx = new LibSQLTransaction("async", this.dialect, this.session, this.schema, this.nestedIndex + 1);
79
+ await this.session.run(sql.raw(`savepoint ${savepointName}`));
80
+ try {
81
+ const result = await transaction(tx);
82
+ await this.session.run(sql.raw(`release savepoint ${savepointName}`));
83
+ return result;
84
+ } catch (err) {
85
+ await this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
86
+ throw err;
87
+ }
88
+ }
89
+ };
90
+ var LibSQLPreparedQuery = class extends SQLitePreparedQuery {
91
+ constructor(client, query, logger, cache, queryMetadata, cacheConfig, fields, tx, executeMethod, _isResponseInArrayMode, customResultMapper) {
92
+ super("async", executeMethod, query, cache, queryMetadata, cacheConfig);
93
+ this.client = client;
94
+ this.logger = logger;
95
+ this.fields = fields;
96
+ this.tx = tx;
97
+ this._isResponseInArrayMode = _isResponseInArrayMode;
98
+ this.customResultMapper = customResultMapper;
99
+ this.customResultMapper = customResultMapper;
100
+ this.fields = fields;
101
+ }
102
+ static [entityKind] = "LibSQLPreparedQuery";
103
+ async run(placeholderValues) {
104
+ const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
105
+ this.logger.logQuery(this.query.sql, params);
106
+ return await this.queryWithCache(this.query.sql, params, async () => {
107
+ const stmt = {
108
+ sql: this.query.sql,
109
+ args: params
110
+ };
111
+ return this.tx ? this.tx.execute(stmt) : this.client.execute(stmt);
112
+ });
113
+ }
114
+ async all(placeholderValues) {
115
+ const { fields, logger, query, tx, client, customResultMapper } = this;
116
+ if (!fields && !customResultMapper) {
117
+ const params = fillPlaceholders(query.params, placeholderValues ?? {});
118
+ logger.logQuery(query.sql, params);
119
+ return await this.queryWithCache(query.sql, params, async () => {
120
+ const stmt = {
121
+ sql: query.sql,
122
+ args: params
123
+ };
124
+ return (tx ? tx.execute(stmt) : client.execute(stmt)).then(({ rows: rows2 }) => this.mapAllResult(rows2));
125
+ });
126
+ }
127
+ const rows = await this.values(placeholderValues);
128
+ return this.mapAllResult(rows);
129
+ }
130
+ mapAllResult(rows, isFromBatch) {
131
+ if (isFromBatch) rows = rows.rows;
132
+ if (!this.fields && !this.customResultMapper) return rows.map((row) => normalizeRow(row));
133
+ if (this.customResultMapper) return this.customResultMapper(rows, normalizeFieldValue);
134
+ return rows.map((row) => {
135
+ return mapResultRow(this.fields, Array.prototype.slice.call(row).map((v) => normalizeFieldValue(v)), this.joinsNotNullableMap);
136
+ });
137
+ }
138
+ async get(placeholderValues) {
139
+ const { fields, logger, query, tx, client, customResultMapper } = this;
140
+ if (!fields && !customResultMapper) {
141
+ const params = fillPlaceholders(query.params, placeholderValues ?? {});
142
+ logger.logQuery(query.sql, params);
143
+ return await this.queryWithCache(query.sql, params, async () => {
144
+ const stmt = {
145
+ sql: query.sql,
146
+ args: params
147
+ };
148
+ return (tx ? tx.execute(stmt) : client.execute(stmt)).then(({ rows: rows2 }) => this.mapGetResult(rows2));
149
+ });
150
+ }
151
+ const rows = await this.values(placeholderValues);
152
+ return this.mapGetResult(rows);
153
+ }
154
+ mapGetResult(rows, isFromBatch) {
155
+ if (isFromBatch) rows = rows.rows;
156
+ const row = rows[0];
157
+ if (!this.fields && !this.customResultMapper) return normalizeRow(row);
158
+ if (!row) return;
159
+ if (this.customResultMapper) return this.customResultMapper(rows, normalizeFieldValue);
160
+ return mapResultRow(this.fields, Array.prototype.slice.call(row).map((v) => normalizeFieldValue(v)), this.joinsNotNullableMap);
161
+ }
162
+ async values(placeholderValues) {
163
+ const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
164
+ this.logger.logQuery(this.query.sql, params);
165
+ return await this.queryWithCache(this.query.sql, params, async () => {
166
+ const stmt = {
167
+ sql: this.query.sql,
168
+ args: params
169
+ };
170
+ return (this.tx ? this.tx.execute(stmt) : this.client.execute(stmt)).then(({ rows }) => rows);
171
+ });
172
+ }
173
+ /** @internal */
174
+ isResponseInArrayMode() {
175
+ return this._isResponseInArrayMode;
176
+ }
177
+ };
178
+ function normalizeRow(obj) {
179
+ return Object.keys(obj).reduce((acc, key) => {
180
+ if (Object.prototype.propertyIsEnumerable.call(obj, key)) acc[key] = obj[key];
181
+ return acc;
182
+ }, {});
183
+ }
184
+ function normalizeFieldValue(value) {
185
+ if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) {
186
+ if (typeof Buffer !== "undefined") {
187
+ if (!(value instanceof Buffer)) return Buffer.from(value);
188
+ return value;
189
+ }
190
+ if (typeof TextDecoder !== "undefined") return new TextDecoder().decode(value);
191
+ throw new Error("TextDecoder is not available. Please provide either Buffer or TextDecoder polyfill.");
192
+ }
193
+ return value;
194
+ }
195
+ var LibSQLDatabase = class extends BaseSQLiteDatabase {
196
+ static [entityKind] = "LibSQLDatabase";
197
+ async batch(batch) {
198
+ return this.session.batch(batch);
199
+ }
200
+ };
201
+ function construct(client, config = {}) {
202
+ const dialect = new SQLiteAsyncDialect({ casing: config.casing });
203
+ let logger;
204
+ if (config.logger === true) logger = new DefaultLogger();
205
+ else if (config.logger !== false) logger = config.logger;
206
+ let schema;
207
+ if (config.schema) {
208
+ const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
209
+ schema = {
210
+ fullSchema: config.schema,
211
+ schema: tablesConfig.tables,
212
+ tableNamesMap: tablesConfig.tableNamesMap
213
+ };
214
+ }
215
+ const db = new LibSQLDatabase("async", dialect, new LibSQLSession(client, dialect, schema, {
216
+ logger,
217
+ cache: config.cache
218
+ }, void 0), schema);
219
+ db.$client = client;
220
+ db.$cache = config.cache;
221
+ if (db.$cache) db.$cache["invalidate"] = config.cache?.onMutate;
222
+ return db;
223
+ }
224
+ function drizzle(...params) {
225
+ if (typeof params[0] === "string") return construct(createClient({ url: params[0] }), params[1]);
226
+ if (isConfig(params[0])) {
227
+ const { connection, client, ...drizzleConfig } = params[0];
228
+ if (client) return construct(client, drizzleConfig);
229
+ return construct(typeof connection === "string" ? createClient({ url: connection }) : createClient(connection), drizzleConfig);
230
+ }
231
+ return construct(params[0], params[1]);
232
+ }
233
+ ((drizzle2) => {
234
+ function mock(config) {
235
+ return construct({}, config);
236
+ }
237
+ drizzle2.mock = mock;
238
+ })(drizzle || (drizzle = {}));
239
+ //#endregion
240
+ export { drizzle };