codexuse-cli 2.5.8 → 3.0.2

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,140 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import { Ci as void_, Fn as getCurrent, Gi as addFinalizer, Ii as effectServices, Or as gen, Rr as map, Rt as die$1, Ts as identity, Wi as Scope, Zn as acquireUseRelease, _ as unwrap, _r as fail, a as makeCompilerSqlite, ao as add, bi as uninterruptibleMask, br as flatMap, ci as succeed, co as getUnsafe, di as sync, fi as tap, hn as make$1, ho as minutes, i as defaultTransforms, io as Service, lo as make$3, n as SqlClient, nr as as, o as layer$1, pr as die, r as make$2, so as get, t as SafeIntegers, ti as scope, vi as try_, wi as withFiber, zi as provide } from "./SqlClient-CB8oPtuH.mjs";
4
+ import { n as make$4, t as get$1 } from "./index.mjs";
5
+ import { t as SqlError } from "./SqlError-3qccgSvc.mjs";
6
+ import { DatabaseSync } from "node:sqlite";
7
+ //#region src/persistence/NodeSqliteClient.ts
8
+ /**
9
+ * Port of `@effect/sql-sqlite-node` that uses the native `node:sqlite`
10
+ * bindings instead of `better-sqlite3`.
11
+ *
12
+ * @module SqliteClient
13
+ */
14
+ const ATTR_DB_SYSTEM_NAME = "db.system.name";
15
+ const TypeId = "~local/sqlite-node/SqliteClient";
16
+ /**
17
+ * SqliteClient - Effect service tag for the sqlite SQL client.
18
+ */
19
+ const SqliteClient = Service("t3/persistence/NodeSqliteClient");
20
+ /**
21
+ * Verify that the current Node.js version includes the `node:sqlite` APIs
22
+ * used by `NodeSqliteClient` — specifically `StatementSync.columns()` (added
23
+ * in Node 22.16.0 / 23.11.0).
24
+ *
25
+ * @see https://github.com/nodejs/node/pull/57490
26
+ */
27
+ const checkNodeSqliteCompat = () => {
28
+ const parts = process.versions.node.split(".").map(Number);
29
+ const major = parts[0] ?? 0;
30
+ const minor = parts[1] ?? 0;
31
+ if (!(major === 22 && minor >= 16 || major === 23 && minor >= 11 || major >= 24)) return die(`Node.js ${process.versions.node} is missing required node:sqlite APIs (StatementSync.columns). Upgrade to Node.js >=22.16, >=23.11, or >=24.`);
32
+ return void_;
33
+ };
34
+ const makeWithDatabase = (options, openDatabase) => gen(function* () {
35
+ yield* checkNodeSqliteCompat();
36
+ const compiler = makeCompilerSqlite(options.transformQueryNames);
37
+ const transformRows = options.transformResultNames ? defaultTransforms(options.transformResultNames).array : void 0;
38
+ const makeConnection = gen(function* () {
39
+ const scope$1 = yield* scope;
40
+ const db = openDatabase();
41
+ yield* addFinalizer(scope$1, sync(() => db.close()));
42
+ const statementReaderCache = /* @__PURE__ */ new WeakMap();
43
+ const hasRows = (statement) => {
44
+ const cached = statementReaderCache.get(statement);
45
+ if (cached !== void 0) return cached;
46
+ const value = statement.columns().length > 0;
47
+ statementReaderCache.set(statement, value);
48
+ return value;
49
+ };
50
+ const prepareCache = yield* make$4({
51
+ capacity: options.prepareCacheSize ?? 200,
52
+ timeToLive: options.prepareCacheTTL ?? minutes(10),
53
+ lookup: (sql) => try_({
54
+ try: () => db.prepare(sql),
55
+ catch: (cause) => new SqlError({
56
+ cause,
57
+ message: "Failed to prepare statement"
58
+ })
59
+ })
60
+ });
61
+ const runStatement = (statement, params, raw) => withFiber((fiber) => {
62
+ statement.setReadBigInts(Boolean(get(fiber.services, SafeIntegers)));
63
+ try {
64
+ if (hasRows(statement)) return succeed(statement.all(...params));
65
+ const result = statement.run(...params);
66
+ return succeed(raw ? result : []);
67
+ } catch (cause) {
68
+ return fail(new SqlError({
69
+ cause,
70
+ message: "Failed to execute statement"
71
+ }));
72
+ }
73
+ });
74
+ const run = (sql, params, raw = false) => flatMap(get$1(prepareCache, sql), (s) => runStatement(s, params, raw));
75
+ const runValues = (sql, params) => acquireUseRelease(get$1(prepareCache, sql), (statement) => try_({
76
+ try: () => {
77
+ if (hasRows(statement)) {
78
+ statement.setReturnArrays(true);
79
+ return statement.all(...params);
80
+ }
81
+ statement.run(...params);
82
+ return [];
83
+ },
84
+ catch: (cause) => new SqlError({
85
+ cause,
86
+ message: "Failed to execute statement"
87
+ })
88
+ }), (statement) => sync(() => {
89
+ if (hasRows(statement)) statement.setReturnArrays(false);
90
+ }));
91
+ return identity({
92
+ execute(sql, params, rowTransform) {
93
+ return rowTransform ? map(run(sql, params), rowTransform) : run(sql, params);
94
+ },
95
+ executeRaw(sql, params) {
96
+ return run(sql, params, true);
97
+ },
98
+ executeValues(sql, params) {
99
+ return runValues(sql, params);
100
+ },
101
+ executeUnprepared(sql, params, rowTransform) {
102
+ const effect = runStatement(db.prepare(sql), params ?? [], false);
103
+ return rowTransform ? map(effect, rowTransform) : effect;
104
+ },
105
+ executeStream(_sql, _params) {
106
+ return die$1("executeStream not implemented");
107
+ }
108
+ });
109
+ });
110
+ const semaphore = yield* make$1(1);
111
+ const connection = yield* makeConnection;
112
+ return yield* make$2({
113
+ acquirer: semaphore.withPermits(1)(succeed(connection)),
114
+ compiler,
115
+ transactionAcquirer: uninterruptibleMask((restore) => {
116
+ const scope = getUnsafe(getCurrent().services, Scope);
117
+ return as(tap(restore(semaphore.take(1)), () => addFinalizer(scope, semaphore.release(1))), connection);
118
+ }),
119
+ spanAttributes: [...options.spanAttributes ? Object.entries(options.spanAttributes) : [], [ATTR_DB_SYSTEM_NAME, "sqlite"]],
120
+ transformRows
121
+ });
122
+ });
123
+ const make = (options) => makeWithDatabase(options, () => new DatabaseSync(options.filename, {
124
+ readOnly: options.readonly ?? false,
125
+ allowExtension: options.allowExtension ?? false
126
+ }));
127
+ const makeMemory = (config = {}) => makeWithDatabase({
128
+ ...config,
129
+ filename: ":memory:",
130
+ readonly: false
131
+ }, () => {
132
+ return new DatabaseSync(":memory:", { allowExtension: config.allowExtension ?? false });
133
+ });
134
+ const layerConfig = (config) => effectServices(unwrap(config).asEffect().pipe(flatMap(make), map((client) => make$3(SqliteClient, client).pipe(add(SqlClient, client))))).pipe(provide(layer$1));
135
+ const layer = (config) => effectServices(map(make(config), (client) => make$3(SqliteClient, client).pipe(add(SqlClient, client)))).pipe(provide(layer$1));
136
+ const layerMemory = (config = {}) => effectServices(map(makeMemory(config), (client) => make$3(SqliteClient, client).pipe(add(SqlClient, client)))).pipe(provide(layer$1));
137
+ //#endregion
138
+ export { SqliteClient, TypeId, layer, layerConfig, layerMemory };
139
+
140
+ //# sourceMappingURL=NodeSqliteClient-BMOt9qz2.mjs.map