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,216 @@
1
+ import { C as sql, _ as fillPlaceholders, g as entityKind, w as tracer } 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 { a as PgTransaction, i as PgSession, n as PgDialect, r as PgPreparedQuery, t as PgDatabase } from "./session-BOEirggu-DTmpyU_x.js";
4
+ import pg from "pg";
5
+ //#region ../db/dist/node-postgres-DQA7bEhW.js
6
+ const { Pool, types } = pg;
7
+ var NodePgPreparedQuery = class extends PgPreparedQuery {
8
+ constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper) {
9
+ super({
10
+ sql: queryString,
11
+ params
12
+ }, cache, queryMetadata, cacheConfig);
13
+ this.client = client;
14
+ this.queryString = queryString;
15
+ this.params = params;
16
+ this.logger = logger;
17
+ this.fields = fields;
18
+ this._isResponseInArrayMode = _isResponseInArrayMode;
19
+ this.customResultMapper = customResultMapper;
20
+ this.rawQueryConfig = {
21
+ name,
22
+ text: queryString,
23
+ types: { getTypeParser: (typeId, format) => {
24
+ if (typeId === types.builtins.TIMESTAMPTZ) return (val) => val;
25
+ if (typeId === types.builtins.TIMESTAMP) return (val) => val;
26
+ if (typeId === types.builtins.DATE) return (val) => val;
27
+ if (typeId === types.builtins.INTERVAL) return (val) => val;
28
+ if (typeId === 1231) return (val) => val;
29
+ if (typeId === 1115) return (val) => val;
30
+ if (typeId === 1185) return (val) => val;
31
+ if (typeId === 1187) return (val) => val;
32
+ if (typeId === 1182) return (val) => val;
33
+ return types.getTypeParser(typeId, format);
34
+ } }
35
+ };
36
+ this.queryConfig = {
37
+ name,
38
+ text: queryString,
39
+ rowMode: "array",
40
+ types: { getTypeParser: (typeId, format) => {
41
+ if (typeId === types.builtins.TIMESTAMPTZ) return (val) => val;
42
+ if (typeId === types.builtins.TIMESTAMP) return (val) => val;
43
+ if (typeId === types.builtins.DATE) return (val) => val;
44
+ if (typeId === types.builtins.INTERVAL) return (val) => val;
45
+ if (typeId === 1231) return (val) => val;
46
+ if (typeId === 1115) return (val) => val;
47
+ if (typeId === 1185) return (val) => val;
48
+ if (typeId === 1187) return (val) => val;
49
+ if (typeId === 1182) return (val) => val;
50
+ return types.getTypeParser(typeId, format);
51
+ } }
52
+ };
53
+ }
54
+ static [entityKind] = "NodePgPreparedQuery";
55
+ rawQueryConfig;
56
+ queryConfig;
57
+ async execute(placeholderValues = {}) {
58
+ return tracer.startActiveSpan("drizzle.execute", async () => {
59
+ const params = fillPlaceholders(this.params, placeholderValues);
60
+ this.logger.logQuery(this.rawQueryConfig.text, params);
61
+ const { fields, rawQueryConfig: rawQuery, client, queryConfig: query, joinsNotNullableMap, customResultMapper } = this;
62
+ if (!fields && !customResultMapper) return tracer.startActiveSpan("drizzle.driver.execute", async (span) => {
63
+ span?.setAttributes({
64
+ "drizzle.query.name": rawQuery.name,
65
+ "drizzle.query.text": rawQuery.text,
66
+ "drizzle.query.params": JSON.stringify(params)
67
+ });
68
+ return this.queryWithCache(rawQuery.text, params, async () => {
69
+ return await client.query(rawQuery, params);
70
+ });
71
+ });
72
+ const result = await tracer.startActiveSpan("drizzle.driver.execute", (span) => {
73
+ span?.setAttributes({
74
+ "drizzle.query.name": query.name,
75
+ "drizzle.query.text": query.text,
76
+ "drizzle.query.params": JSON.stringify(params)
77
+ });
78
+ return this.queryWithCache(query.text, params, async () => {
79
+ return await client.query(query, params);
80
+ });
81
+ });
82
+ return tracer.startActiveSpan("drizzle.mapResponse", () => {
83
+ return customResultMapper ? customResultMapper(result.rows) : result.rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
84
+ });
85
+ });
86
+ }
87
+ all(placeholderValues = {}) {
88
+ return tracer.startActiveSpan("drizzle.execute", () => {
89
+ const params = fillPlaceholders(this.params, placeholderValues);
90
+ this.logger.logQuery(this.rawQueryConfig.text, params);
91
+ return tracer.startActiveSpan("drizzle.driver.execute", (span) => {
92
+ span?.setAttributes({
93
+ "drizzle.query.name": this.rawQueryConfig.name,
94
+ "drizzle.query.text": this.rawQueryConfig.text,
95
+ "drizzle.query.params": JSON.stringify(params)
96
+ });
97
+ return this.queryWithCache(this.rawQueryConfig.text, params, async () => {
98
+ return this.client.query(this.rawQueryConfig, params);
99
+ }).then((result) => result.rows);
100
+ });
101
+ });
102
+ }
103
+ /** @internal */
104
+ isResponseInArrayMode() {
105
+ return this._isResponseInArrayMode;
106
+ }
107
+ };
108
+ var NodePgSession = class NodePgSession extends PgSession {
109
+ constructor(client, dialect, schema, options = {}) {
110
+ super(dialect);
111
+ this.client = client;
112
+ this.schema = schema;
113
+ this.options = options;
114
+ this.logger = options.logger ?? new NoopLogger();
115
+ this.cache = options.cache ?? new NoopCache();
116
+ }
117
+ static [entityKind] = "NodePgSession";
118
+ logger;
119
+ cache;
120
+ prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
121
+ return new NodePgPreparedQuery(this.client, query.sql, query.params, this.logger, this.cache, queryMetadata, cacheConfig, fields, name, isResponseInArrayMode, customResultMapper);
122
+ }
123
+ async transaction(transaction, config) {
124
+ const isPool = this.client instanceof Pool || Object.getPrototypeOf(this.client).constructor.name.includes("Pool");
125
+ const session = isPool ? new NodePgSession(await this.client.connect(), this.dialect, this.schema, this.options) : this;
126
+ const tx = new NodePgTransaction(this.dialect, session, this.schema);
127
+ await tx.execute(sql`begin${config ? sql` ${tx.getTransactionConfigSQL(config)}` : void 0}`);
128
+ try {
129
+ const result = await transaction(tx);
130
+ await tx.execute(sql`commit`);
131
+ return result;
132
+ } catch (error) {
133
+ await tx.execute(sql`rollback`);
134
+ throw error;
135
+ } finally {
136
+ if (isPool) session.client.release();
137
+ }
138
+ }
139
+ async count(sql2) {
140
+ const res = await this.execute(sql2);
141
+ return Number(res["rows"][0]["count"]);
142
+ }
143
+ };
144
+ var NodePgTransaction = class NodePgTransaction extends PgTransaction {
145
+ static [entityKind] = "NodePgTransaction";
146
+ async transaction(transaction) {
147
+ const savepointName = `sp${this.nestedIndex + 1}`;
148
+ const tx = new NodePgTransaction(this.dialect, this.session, this.schema, this.nestedIndex + 1);
149
+ await tx.execute(sql.raw(`savepoint ${savepointName}`));
150
+ try {
151
+ const result = await transaction(tx);
152
+ await tx.execute(sql.raw(`release savepoint ${savepointName}`));
153
+ return result;
154
+ } catch (err) {
155
+ await tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));
156
+ throw err;
157
+ }
158
+ }
159
+ };
160
+ var NodePgDriver = class {
161
+ constructor(client, dialect, options = {}) {
162
+ this.client = client;
163
+ this.dialect = dialect;
164
+ this.options = options;
165
+ }
166
+ static [entityKind] = "NodePgDriver";
167
+ createSession(schema) {
168
+ return new NodePgSession(this.client, this.dialect, schema, {
169
+ logger: this.options.logger,
170
+ cache: this.options.cache
171
+ });
172
+ }
173
+ };
174
+ var NodePgDatabase = class extends PgDatabase {
175
+ static [entityKind] = "NodePgDatabase";
176
+ };
177
+ function construct(client, config = {}) {
178
+ const dialect = new PgDialect({ casing: config.casing });
179
+ let logger;
180
+ if (config.logger === true) logger = new DefaultLogger();
181
+ else if (config.logger !== false) logger = config.logger;
182
+ let schema;
183
+ if (config.schema) {
184
+ const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
185
+ schema = {
186
+ fullSchema: config.schema,
187
+ schema: tablesConfig.tables,
188
+ tableNamesMap: tablesConfig.tableNamesMap
189
+ };
190
+ }
191
+ const db = new NodePgDatabase(dialect, new NodePgDriver(client, dialect, {
192
+ logger,
193
+ cache: config.cache
194
+ }).createSession(schema), schema);
195
+ db.$client = client;
196
+ db.$cache = config.cache;
197
+ if (db.$cache) db.$cache["invalidate"] = config.cache?.onMutate;
198
+ return db;
199
+ }
200
+ function drizzle(...params) {
201
+ if (typeof params[0] === "string") return construct(new pg.Pool({ connectionString: params[0] }), params[1]);
202
+ if (isConfig(params[0])) {
203
+ const { connection, client, ...drizzleConfig } = params[0];
204
+ if (client) return construct(client, drizzleConfig);
205
+ return construct(typeof connection === "string" ? new pg.Pool({ connectionString: connection }) : new pg.Pool(connection), drizzleConfig);
206
+ }
207
+ return construct(params[0], params[1]);
208
+ }
209
+ ((drizzle2) => {
210
+ function mock(config) {
211
+ return construct({}, config);
212
+ }
213
+ drizzle2.mock = mock;
214
+ })(drizzle || (drizzle = {}));
215
+ //#endregion
216
+ export { drizzle };
@@ -0,0 +1,24 @@
1
+ import { p as We, t as B, v as u$1 } from "./chunk-2X2C5D2I-dJHtPFe9-DxsO-1YF.js";
2
+ import * as o from "path";
3
+ import * as s from "fs";
4
+ //#region ../db/dist/nodefs-Bc8b83o_.js
5
+ u$1();
6
+ var m = class extends We {
7
+ constructor(t) {
8
+ super(t), this.rootDir = o.resolve(t), s.existsSync(o.join(this.rootDir)) || s.mkdirSync(this.rootDir);
9
+ }
10
+ async init(t, e) {
11
+ return this.pg = t, { emscriptenOpts: {
12
+ ...e,
13
+ preRun: [...e.preRun || [], (r) => {
14
+ let c = r.FS.filesystems.NODEFS;
15
+ r.FS.mkdir(B), r.FS.mount(c, { root: this.rootDir }, B);
16
+ }]
17
+ } };
18
+ }
19
+ async closeFs() {
20
+ this.pg.Module.FS.quit();
21
+ }
22
+ };
23
+ //#endregion
24
+ export { m as NodeFS };
@@ -0,0 +1,365 @@
1
+ import { c as R, d as U, f as Ve, i as Ge, m as h$1, u as T$1, v as u$1, y as x$1 } from "./chunk-2X2C5D2I-dJHtPFe9-DxsO-1YF.js";
2
+ //#region ../db/dist/opfs-ahp-DbstDvx-.js
3
+ u$1();
4
+ var $ = "state.txt", G = "data", T = {
5
+ DIR: 16384,
6
+ FILE: 32768
7
+ }, H, v, F, M, y, b, m, x, P, D, S, n, C, O, k, w, f, I, W, j, L = class extends Ge {
8
+ constructor(e, { initialPoolSize: t = 1e3, maintainedPoolSize: o = 100, debug: i = !1 } = {}) {
9
+ super(e, { debug: i });
10
+ R(this, n);
11
+ R(this, H);
12
+ R(this, v);
13
+ R(this, F);
14
+ R(this, M);
15
+ R(this, y);
16
+ R(this, b, /* @__PURE__ */ new Map());
17
+ R(this, m, /* @__PURE__ */ new Map());
18
+ R(this, x, 0);
19
+ R(this, P, /* @__PURE__ */ new Map());
20
+ R(this, D, /* @__PURE__ */ new Map());
21
+ this.lastCheckpoint = 0;
22
+ this.checkpointInterval = 1e3 * 60;
23
+ this.poolCounter = 0;
24
+ R(this, S, /* @__PURE__ */ new Set());
25
+ this.initialPoolSize = t, this.maintainedPoolSize = o;
26
+ }
27
+ async init(e, t) {
28
+ return await T$1(this, n, C).call(this), super.init(e, t);
29
+ }
30
+ async syncToFs(e = !1) {
31
+ await this.maybeCheckpointState(), await this.maintainPool(), e || this.flush();
32
+ }
33
+ async closeFs() {
34
+ for (let e of h$1(this, m).values()) e.close();
35
+ h$1(this, y).flush(), h$1(this, y).close(), this.pg.Module.FS.quit();
36
+ }
37
+ async maintainPool(e) {
38
+ e = e || this.maintainedPoolSize;
39
+ let t = e - this.state.pool.length, o = [];
40
+ for (let i = 0; i < t; i++) o.push(new Promise(async (c) => {
41
+ ++this.poolCounter;
42
+ let a = `${(Date.now() - 1704063600).toString(16).padStart(8, "0")}-${this.poolCounter.toString(16).padStart(8, "0")}`, h$1$1 = await h$1(this, F).getFileHandle(a, { create: !0 }), d = await h$1$1.createSyncAccessHandle();
43
+ h$1(this, b).set(a, h$1$1), h$1(this, m).set(a, d), T$1(this, n, k).call(this, {
44
+ opp: "createPoolFile",
45
+ args: [a]
46
+ }), this.state.pool.push(a), c();
47
+ }));
48
+ for (let i = 0; i > t; i--) o.push(new Promise(async (c) => {
49
+ let a = this.state.pool.pop();
50
+ T$1(this, n, k).call(this, {
51
+ opp: "deletePoolFile",
52
+ args: [a]
53
+ });
54
+ let h$2 = h$1(this, b).get(a);
55
+ h$1(this, m).get(a)?.close(), await h$1(this, F).removeEntry(h$2.name), h$1(this, b).delete(a), h$1(this, m).delete(a), c();
56
+ }));
57
+ await Promise.all(o);
58
+ }
59
+ _createPoolFileState(e) {
60
+ this.state.pool.push(e);
61
+ }
62
+ _deletePoolFileState(e) {
63
+ let t = this.state.pool.indexOf(e);
64
+ t > -1 && this.state.pool.splice(t, 1);
65
+ }
66
+ async maybeCheckpointState() {
67
+ Date.now() - this.lastCheckpoint > this.checkpointInterval && await this.checkpointState();
68
+ }
69
+ async checkpointState() {
70
+ let e = new TextEncoder().encode(JSON.stringify(this.state));
71
+ h$1(this, y).truncate(0), h$1(this, y).write(e, { at: 0 }), h$1(this, y).flush(), this.lastCheckpoint = Date.now();
72
+ }
73
+ flush() {
74
+ for (let e of h$1(this, S)) try {
75
+ e.flush();
76
+ } catch {}
77
+ h$1(this, S).clear();
78
+ }
79
+ chmod(e, t) {
80
+ T$1(this, n, O).call(this, {
81
+ opp: "chmod",
82
+ args: [e, t]
83
+ }, () => {
84
+ this._chmodState(e, t);
85
+ });
86
+ }
87
+ _chmodState(e, t) {
88
+ let o = T$1(this, n, f).call(this, e);
89
+ o.mode = t;
90
+ }
91
+ close(e) {
92
+ let t = T$1(this, n, I).call(this, e);
93
+ h$1(this, P).delete(e), h$1(this, D).delete(t);
94
+ }
95
+ fstat(e) {
96
+ let t = T$1(this, n, I).call(this, e);
97
+ return this.lstat(t);
98
+ }
99
+ lstat(e) {
100
+ let t = T$1(this, n, f).call(this, e), o = t.type === "file" ? h$1(this, m).get(t.backingFilename).getSize() : 0, i = 4096;
101
+ return {
102
+ dev: 0,
103
+ ino: 0,
104
+ mode: t.mode,
105
+ nlink: 1,
106
+ uid: 0,
107
+ gid: 0,
108
+ rdev: 0,
109
+ size: o,
110
+ blksize: i,
111
+ blocks: Math.ceil(o / i),
112
+ atime: t.lastModified,
113
+ mtime: t.lastModified,
114
+ ctime: t.lastModified
115
+ };
116
+ }
117
+ mkdir(e, t) {
118
+ T$1(this, n, O).call(this, {
119
+ opp: "mkdir",
120
+ args: [e, t]
121
+ }, () => {
122
+ this._mkdirState(e, t);
123
+ });
124
+ }
125
+ _mkdirState(e, t) {
126
+ let o = T$1(this, n, w).call(this, e), i = o.pop(), c = [], a = this.state.root;
127
+ for (let d of o) {
128
+ if (c.push(e), !Object.prototype.hasOwnProperty.call(a.children, d)) if (t?.recursive) this.mkdir(c.join("/"));
129
+ else throw new p("ENOENT", "No such file or directory");
130
+ if (a.children[d].type !== "directory") throw new p("ENOTDIR", "Not a directory");
131
+ a = a.children[d];
132
+ }
133
+ if (Object.prototype.hasOwnProperty.call(a.children, i)) throw new p("EEXIST", "File exists");
134
+ let h = {
135
+ type: "directory",
136
+ lastModified: Date.now(),
137
+ mode: t?.mode || T.DIR,
138
+ children: {}
139
+ };
140
+ a.children[i] = h;
141
+ }
142
+ open(e, t, o) {
143
+ if (T$1(this, n, f).call(this, e).type !== "file") throw new p("EISDIR", "Is a directory");
144
+ let c = T$1(this, n, W).call(this);
145
+ return h$1(this, P).set(c, e), h$1(this, D).set(e, c), c;
146
+ }
147
+ readdir(e) {
148
+ let t = T$1(this, n, f).call(this, e);
149
+ if (t.type !== "directory") throw new p("ENOTDIR", "Not a directory");
150
+ return Object.keys(t.children);
151
+ }
152
+ read(e, t, o, i, c) {
153
+ let a = T$1(this, n, I).call(this, e), h$3 = T$1(this, n, f).call(this, a);
154
+ if (h$3.type !== "file") throw new p("EISDIR", "Is a directory");
155
+ return h$1(this, m).get(h$3.backingFilename).read(new Uint8Array(t.buffer, o, i), { at: c });
156
+ }
157
+ rename(e, t) {
158
+ T$1(this, n, O).call(this, {
159
+ opp: "rename",
160
+ args: [e, t]
161
+ }, () => {
162
+ this._renameState(e, t, !0);
163
+ });
164
+ }
165
+ _renameState(e, t, o = !1) {
166
+ let i = T$1(this, n, w).call(this, e), c = i.pop(), a = T$1(this, n, f).call(this, i.join("/"));
167
+ if (!Object.prototype.hasOwnProperty.call(a.children, c)) throw new p("ENOENT", "No such file or directory");
168
+ let h$4 = T$1(this, n, w).call(this, t), d = h$4.pop(), l = T$1(this, n, f).call(this, h$4.join("/"));
169
+ if (o && Object.prototype.hasOwnProperty.call(l.children, d)) {
170
+ let u = l.children[d];
171
+ h$1(this, m).get(u.backingFilename).truncate(0), this.state.pool.push(u.backingFilename);
172
+ }
173
+ l.children[d] = a.children[c], delete a.children[c];
174
+ }
175
+ rmdir(e) {
176
+ T$1(this, n, O).call(this, {
177
+ opp: "rmdir",
178
+ args: [e]
179
+ }, () => {
180
+ this._rmdirState(e);
181
+ });
182
+ }
183
+ _rmdirState(e) {
184
+ let t = T$1(this, n, w).call(this, e), o = t.pop(), i = T$1(this, n, f).call(this, t.join("/"));
185
+ if (!Object.prototype.hasOwnProperty.call(i.children, o)) throw new p("ENOENT", "No such file or directory");
186
+ let c = i.children[o];
187
+ if (c.type !== "directory") throw new p("ENOTDIR", "Not a directory");
188
+ if (Object.keys(c.children).length > 0) throw new p("ENOTEMPTY", "Directory not empty");
189
+ delete i.children[o];
190
+ }
191
+ truncate(e, t = 0) {
192
+ let o = T$1(this, n, f).call(this, e);
193
+ if (o.type !== "file") throw new p("EISDIR", "Is a directory");
194
+ let i = h$1(this, m).get(o.backingFilename);
195
+ if (!i) throw new p("ENOENT", "No such file or directory");
196
+ i.truncate(t), h$1(this, S).add(i);
197
+ }
198
+ unlink(e) {
199
+ T$1(this, n, O).call(this, {
200
+ opp: "unlink",
201
+ args: [e]
202
+ }, () => {
203
+ this._unlinkState(e, !0);
204
+ });
205
+ }
206
+ _unlinkState(e, t = !1) {
207
+ let o = T$1(this, n, w).call(this, e), i = o.pop(), c = T$1(this, n, f).call(this, o.join("/"));
208
+ if (!Object.prototype.hasOwnProperty.call(c.children, i)) throw new p("ENOENT", "No such file or directory");
209
+ let a = c.children[i];
210
+ if (a.type !== "file") throw new p("EISDIR", "Is a directory");
211
+ if (delete c.children[i], t) {
212
+ let h$5 = h$1(this, m).get(a.backingFilename);
213
+ h$5?.truncate(0), h$1(this, S).add(h$5), h$1(this, D).has(e) && (h$1(this, P).delete(h$1(this, D).get(e)), h$1(this, D).delete(e));
214
+ }
215
+ this.state.pool.push(a.backingFilename);
216
+ }
217
+ utimes(e, t, o) {
218
+ T$1(this, n, O).call(this, {
219
+ opp: "utimes",
220
+ args: [
221
+ e,
222
+ t,
223
+ o
224
+ ]
225
+ }, () => {
226
+ this._utimesState(e, t, o);
227
+ });
228
+ }
229
+ _utimesState(e, t, o) {
230
+ let i = T$1(this, n, f).call(this, e);
231
+ i.lastModified = o;
232
+ }
233
+ writeFile(e, t, o) {
234
+ let i = T$1(this, n, w).call(this, e), c = i.pop(), a = T$1(this, n, f).call(this, i.join("/"));
235
+ if (Object.prototype.hasOwnProperty.call(a.children, c)) {
236
+ let l = a.children[c];
237
+ l.lastModified = Date.now(), T$1(this, n, k).call(this, {
238
+ opp: "setLastModified",
239
+ args: [e, l.lastModified]
240
+ });
241
+ } else {
242
+ if (this.state.pool.length === 0) throw new Error("No more file handles available in the pool");
243
+ let l = {
244
+ type: "file",
245
+ lastModified: Date.now(),
246
+ mode: o?.mode || T.FILE,
247
+ backingFilename: this.state.pool.pop()
248
+ };
249
+ a.children[c] = l, T$1(this, n, k).call(this, {
250
+ opp: "createFileNode",
251
+ args: [e, l]
252
+ });
253
+ }
254
+ let h$6 = a.children[c], d = h$1(this, m).get(h$6.backingFilename);
255
+ t.length > 0 && (d.write(typeof t == "string" ? new TextEncoder().encode(t) : new Uint8Array(t), { at: 0 }), e.startsWith("/pg_wal") && h$1(this, S).add(d));
256
+ }
257
+ _createFileNodeState(e, t) {
258
+ let o = T$1(this, n, w).call(this, e), i = o.pop(), c = T$1(this, n, f).call(this, o.join("/"));
259
+ c.children[i] = t;
260
+ let a = this.state.pool.indexOf(t.backingFilename);
261
+ return a > -1 && this.state.pool.splice(a, 1), t;
262
+ }
263
+ _setLastModifiedState(e, t) {
264
+ let o = T$1(this, n, f).call(this, e);
265
+ o.lastModified = t;
266
+ }
267
+ write(e, t, o, i, c) {
268
+ let a = T$1(this, n, I).call(this, e), h$7 = T$1(this, n, f).call(this, a);
269
+ if (h$7.type !== "file") throw new p("EISDIR", "Is a directory");
270
+ let d = h$1(this, m).get(h$7.backingFilename);
271
+ if (!d) throw new p("EBADF", "Bad file descriptor");
272
+ let l = d.write(new Uint8Array(t, o, i), { at: c });
273
+ return a.startsWith("/pg_wal") && h$1(this, S).add(d), l;
274
+ }
275
+ };
276
+ H = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new WeakSet(), C = async function() {
277
+ x$1(this, H, await navigator.storage.getDirectory()), x$1(this, v, await T$1(this, n, j).call(this, this.dataDir, { create: !0 })), x$1(this, F, await T$1(this, n, j).call(this, G, {
278
+ from: h$1(this, v),
279
+ create: !0
280
+ })), x$1(this, M, await h$1(this, v).getFileHandle($, { create: !0 })), x$1(this, y, await h$1(this, M).createSyncAccessHandle());
281
+ let e = new ArrayBuffer(h$1(this, y).getSize());
282
+ h$1(this, y).read(e, { at: 0 });
283
+ let t, o = new TextDecoder().decode(e).split(`
284
+ `), i = !1;
285
+ try {
286
+ t = JSON.parse(o[0]);
287
+ } catch {
288
+ t = {
289
+ root: {
290
+ type: "directory",
291
+ lastModified: Date.now(),
292
+ mode: T.DIR,
293
+ children: {}
294
+ },
295
+ pool: []
296
+ }, h$1(this, y).truncate(0), h$1(this, y).write(new TextEncoder().encode(JSON.stringify(t)), { at: 0 }), i = !0;
297
+ }
298
+ this.state = t;
299
+ let c = o.slice(1).filter(Boolean).map((l) => JSON.parse(l));
300
+ for (let l of c) {
301
+ let u = `_${l.opp}State`;
302
+ if (typeof this[u] == "function") try {
303
+ this[u].bind(this)(...l.args);
304
+ } catch (N) {
305
+ console.warn("Error applying OPFS AHP WAL entry", l, N);
306
+ }
307
+ }
308
+ let a = [], h$8 = async (l) => {
309
+ if (l.type === "file") try {
310
+ let u = await h$1(this, F).getFileHandle(l.backingFilename), N = await u.createSyncAccessHandle();
311
+ h$1(this, b).set(l.backingFilename, u), h$1(this, m).set(l.backingFilename, N);
312
+ } catch (u) {
313
+ console.error("Error opening file handle for node", l, u);
314
+ }
315
+ else for (let u of Object.values(l.children)) a.push(h$8(u));
316
+ };
317
+ await h$8(this.state.root);
318
+ let d = [];
319
+ for (let l of this.state.pool) d.push(new Promise(async (u) => {
320
+ h$1(this, b).has(l) && console.warn("File handle already exists for pool file", l);
321
+ let N = await h$1(this, F).getFileHandle(l), U = await N.createSyncAccessHandle();
322
+ h$1(this, b).set(l, N), h$1(this, m).set(l, U), u();
323
+ }));
324
+ await Promise.all([...a, ...d]), await this.maintainPool(i ? this.initialPoolSize : this.maintainedPoolSize);
325
+ }, O = function(e, t) {
326
+ let o = T$1(this, n, k).call(this, e);
327
+ try {
328
+ t();
329
+ } catch (i) {
330
+ throw h$1(this, y).truncate(o), i;
331
+ }
332
+ }, k = function(e) {
333
+ let t = JSON.stringify(e), o = new TextEncoder().encode(`
334
+ ${t}`), i = h$1(this, y).getSize();
335
+ return h$1(this, y).write(o, { at: i }), h$1(this, S).add(h$1(this, y)), i;
336
+ }, w = function(e) {
337
+ return e.split("/").filter(Boolean);
338
+ }, f = function(e, t) {
339
+ let o = T$1(this, n, w).call(this, e), i = t || this.state.root;
340
+ for (let c of o) {
341
+ if (i.type !== "directory") throw new p("ENOTDIR", "Not a directory");
342
+ if (!Object.prototype.hasOwnProperty.call(i.children, c)) throw new p("ENOENT", "No such file or directory");
343
+ i = i.children[c];
344
+ }
345
+ return i;
346
+ }, I = function(e) {
347
+ let t = h$1(this, P).get(e);
348
+ if (!t) throw new p("EBADF", "Bad file descriptor");
349
+ return t;
350
+ }, W = function() {
351
+ let e = ++U(this, x)._;
352
+ for (; h$1(this, P).has(e);) U(this, x)._++;
353
+ return e;
354
+ }, j = async function(e, t) {
355
+ let o = T$1(this, n, w).call(this, e), i = t?.from || h$1(this, H);
356
+ for (let c of o) i = await i.getDirectoryHandle(c, { create: t?.create });
357
+ return i;
358
+ };
359
+ var p = class extends Error {
360
+ constructor(A, e) {
361
+ super(e), typeof A == "number" ? this.code = A : typeof A == "string" && (this.code = Ve[A]);
362
+ }
363
+ };
364
+ //#endregion
365
+ export { L as OpfsAhpFS };