clanka 0.24.4 → 0.24.5

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.
@@ -1,15 +1,17 @@
1
- import { $c as void_$2, $i as interrupt, $l as isZero, Aa as request$1, B as String$1, Bd as pipeArguments, Bi as fn, Bs as addFinalizer, Bu as Number$2, Ca as orElseSucceed, Ci as catchTag, Cn as evolve, Co as isEmpty, Da as provideService, Di as contextWith, Dl as map$2, Do as size, E as Natural, Ea as provideContext, Ec as exitHasInterrupts, Ei as context, Eo as set, Es as effectDiscard, Fd as dual, Fu as none, Go as Clock, Gs as make$7, H as Struct$2, Hc as makeSpanUnsafe, Hi as forEach, Hs as close, Hu as make$10, Id as flow, Ii as filterOrFail, Ja as tap, Jr as now, K as TaggedError, Ka as suspend, Kr as formatIsoDate, Ku as PipeInspectableProto, Ld as identity, Li as flatMap, M as Number$1, Ma as retry, Md as constUndefined, Mu as isSome, N as Option, Na as runFork, Ni as fail, Ns as provide$1, Nu as map$3, Oi as delay, P as OptionFromNullOr, Pa as runForkWith, Pc as fiberJoin, Pi as failCause$1, Po as spaced, Ps as provideMerge, Pu as match, Qc as updateContext, Qi as ignoreCause, Ql as isFinite, Qs as doneUnsafe, Ra as scoped, Rc as forkUnsafe, Ru as some, Sa as orDie, So as get$2, Tc as endSpan, Ti as catch_, To as remove, Ts as effectContext, Tu as fromNullishOr, Ua as succeed, Ui as forever, Va as serviceOption, Vi as fnUntraced, Wc as onExitUnsafe, Wu as Prototype, Xi as gen, Xo as NoSuchElementError, Xs as TracerTimingEnabled, Ya as tapCause, Yl as fromInputUnsafe, Yr as removeTime, Zi as ignore, Zl as infinity, _a as onError, _c as void_$3, _d as hasProperty, _i as catchDefect, _l as flatMapNullishOr, _r as transform, _u as merge, a as BooleanFromBit, aa as logInfo, ac as makeUnsafe$2, ai as all, al as TaggedError$1, as as filterInterruptors, au as zero, bi as catchIf, bn as withConstructorDefault, bo as empty$1, bs as reasonAnnotations, ca as map, ci as annotateLogs, cl as has, co as void_$1, cu as add, d as DateTimeUtcFromMillis, da as mapError, dd as byReferenceUnsafe, di as asVoid, dn as optional, do as withFiber, dt as decodeTo, du as getOption, eo as tryPromise, f as DateTimeUtcFromString, fd as equals, fl as empty, fn as optionalKey, fo as withLogSpan, fr as transformOptional, ft as decodeUnknownEffect, fu as getOrUndefined, gc as succeed$2, gd as symbol$1, gs as makeDieReason, hc as isSuccess, hi as catchCause, ht as encodeEffect, hu as make$9, i as Boolean, io as uninterruptibleMask, iu as toMillis, j as NullOr, jc as fiberInterrupt, jl as sort, ju as isNone, ki as die, l as DateTimeUtc, lc as fail$1, li as as, ll as toPredicate, ls as hasInterruptsOnly, ma as matchCauseEffect, mc as isFailure, md as hash, mo as withSpan, mr as map$1, ms as isFailReason, mu as getUnsafe, n as ArraySchema, na as logDebug, nd as assignProperty, ni as acquireRelease, nu as minutes, oi as andThen, ot as brand, ou as Reference, p as Defect, pa as matchCauseEager, pd as symbol, pr as dateTimeUtcFromInput, qa as sync, qc as succeed$1, qi as forkScoped, qo as monotonicTimeNanos, qs as provide, ri as acquireUseRelease, rt as Union$2, ru as seconds, s as Class$1, sa as makeSpanScoped, si as annotateCurrentSpan, sl as compose, so as useSpan, ss as fromReasons, su as Service, ta as isEffect, tc as into, td as withFiber$1, tl as ParentSpan, tn as isSchema, to as try_, ts as combine, tu as millis, u as DateTimeUtcFromDate, uc as failCause, un as mutable, ur as transform$1, uu as get$1, va as onExit, vc as ClockRef, vl as fromIterable, vo as Class$2, vu as omit, wc as contextWith$1, wi as catchTags, wo as make$8, ws as effect, wu as flatten, xi as catchNoSuchElement, xl as isArrayNonEmpty, xo as forEach$1, xu as filter, ya as onExitPrimitive, yd as isNotNull, yn as toType, yt as instanceOf, zd as pipe, zs as Scope } from "./Schema-D629S5yu.mjs";
1
+ import { $i as ignore, $l as fromInputUnsafe, $o as NoSuchElementError, $s as TracerTimingEnabled$1, Ai as delay, Ao as size, B as String$1, Bd as identity, Ci as catchNoSuchElement, Cn as evolve, Co as empty$1, Cs as reasonAnnotations, Dc as contextWith$1, Di as catch_, Do as make$8, Ds as effect, E as Natural, Ei as catchTags, Eo as isEmpty, Fa as retry, Fd as constUndefined, Fi as fail, Fl as sort, Fu as isNone, Gc as makeSpanUnsafe, Gi as forever, Gs as close, H as Struct$2, Hd as pipe, Hi as fn, Hs as Scope, Hu as some, Ia as runFork, Ii as failCause$1, Is as provide$1, Iu as isSome, Jo as Clock, Jr as now, Js as make$7, Ju as Prototype, K as TaggedError, Ka as succeed, Kr as formatIsoDate, Ku as make$10, La as runForkWith, Lc as fiberJoin, Lo as spaced, Ls as provideMerge, Lu as map$3, M as Number$1, N as Option, Na as request$1, Oa as provideContext, Oc as endSpan, Oi as context, Oo as remove, Os as effectContext, Ou as flatten, P as OptionFromNullOr, Pc as fiberInterrupt, Qa as tapCause, Qi as gen, Rd as dual, Ri as filterOrFail, Ru as match, Sd as isNotNull, Si as catchIf, Sl as fromIterable, Su as omit, Ta as orElseSucceed, Ti as catchTag, Tl as isArrayNonEmpty, To as get$2, Tu as filter, Ud as pipeArguments, Ui as fnUntraced, Us as addFinalizer, Va as scoped, Vc as forkUnsafe, Wa as serviceOption, Wi as forEach, Wu as Number$2, Xa as sync, Xc as succeed$1, Xo as monotonicTimeNanos, Xs as provide, Xu as PipeInspectableProto, Ya as suspend, Yi as forkScoped, Yr as removeTime, Za as tap, _c as isFailure, _d as symbol, _i as catchCause, _o as withSpan, _r as transform, _s as isFailReason, a as BooleanFromBit, ad as withFiber$1, ai as acquireUseRelease, al as ParentSpan, au as millis, ba as onExit, bc as void_$3, bd as hasProperty, bn as withConstructorDefault, cc as makeUnsafe$2, ci as andThen, cs as filterInterruptors, cu as toMillis, d as DateTimeUtcFromMillis, di as as, dl as compose, dn as optional, do as void_$1, dt as decodeTo, du as Service, ea as ignoreCause, f as DateTimeUtcFromString, fc as fail$1, fl as has, fn as optionalKey, fr as transformOptional, fs as hasInterruptsOnly, ft as decodeUnknownEffect, fu as add, ga as matchCauseEffect, gd as equals, gl as empty, gu as getOrUndefined, ha as matchCauseEager, hd as byReferenceUnsafe, ho as withLogSpan, ht as encodeEffect, hu as getOption, i as Boolean, ia as logDebug, ic as into, ii as acquireRelease, io as try_, is as combine, j as NullOr, ji as die, jl as map$2, ka as provideService, kc as exitHasInterrupts, ki as contextWith, ko as set, ks as effectDiscard, ku as fromNullishOr, l as DateTimeUtc, la as makeSpanScoped, li as annotateCurrentSpan, ll as TaggedError$1, lu as zero, mo as withFiber, mr as map$1, mu as get$1, n as ArraySchema, nl as void_$2, nu as isFinite, od as assignProperty, oo as uninterruptible, ot as brand, ou as minutes, p as Defect, pa as mapError, pc as failCause, pi as asVoid, pl as toPredicate, pr as dateTimeUtcFromInput, qc as onExitUnsafe, ra as isEffect, rl as TracerTimingEnabled, ro as tryPromise, rt as Union$2, ru as isZero, s as Class$1, sa as logInfo, si as all, so as uninterruptibleMask, su as seconds, ta as interrupt, tc as doneUnsafe, tl as updateContext, tn as isSchema, tu as infinity, u as DateTimeUtcFromDate, ua as map, ui as annotateLogs, un as mutable, uo as useSpan, ur as transform$1, us as fromReasons, uu as Reference, vc as isSuccess, vd as hash, vu as getUnsafe, wa as orDie, wo as forEach$1, xa as onExitPrimitive, xc as ClockRef, xl as flatMapNullishOr, xo as Class$2, xu as merge, ya as onError, yc as succeed$2, yd as symbol$1, yi as catchDefect, yn as toType, ys as makeDieReason, yt as instanceOf, yu as make$9, zd as flow, zi as flatMap, zu as none } from "./Schema-BfUmMefy.mjs";
2
2
  import { D as Path, E as Console, O as FileSystem, T as ChildProcessSpawner, a as makeGrouped, f as SemanticSearch, h as map$4, i as batchN, m as maybeUpdateFile, n as EmbeddingModel, o as setDelay, p as maybeRemoveFile, r as EmbeddingRequest, s as withSpan$1, t as Dimensions, w as make$11 } from "./cli.mjs";
3
- import { $t as offerUnsafe, Ht as makeUnsafe$3, It as unwrap, J as fromArrayEffect, Jt as failCauseUnsafe, Mt as tap$1, P as die$1, U as flatMap$1, Vt as make$13, Yt as make$12, gt as provideService$1, hn as runIn, mn as join$1, pn as interruptAllAs, q as fromArray, tt as fromQueue, vt as runCollect, yt as runDrain } from "./AiError-fiHIiGOy.mjs";
3
+ import { $t as offerUnsafe, Ht as makeUnsafe$3, It as unwrap, J as fromArrayEffect, Jt as failCauseUnsafe, Mt as tap$1, P as die$1, U as flatMap$1, Vt as make$13, Yt as make$12, gt as provideService$1, hn as runIn, mn as join$1, pn as interruptAllAs, q as fromArray, tt as fromQueue, vt as runCollect, yt as runDrain } from "./AiError-CsvdOsKR.mjs";
4
4
  import { createHash } from "node:crypto";
5
5
  import { DatabaseSync, backup } from "node:sqlite";
6
6
  import TreeSitter from "tree-sitter";
7
7
  import TreeSitterJavaScript from "tree-sitter-javascript";
8
8
  import TreeSitterTypeScript from "tree-sitter-typescript";
9
9
  import { getLoadablePath } from "sqlite-vec";
10
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/sql.js
10
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/internal/sql.js
11
11
  const CurrentTransactionService = Reference("effect/sql/CurrentTransactionService", { defaultValue: () => void 0 });
12
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/reactivity/Reactivity.js
12
+ const waitClock = (fiber) => fiber.getRef(TracerTimingEnabled) ? fiber.getRef(Clock) : void 0;
13
+ const recordConnectionWait = (span, clock) => span.attribute("db.client.connection.wait_time_ms", Number(clock.currentTimeNanosUnsafe() - span.status.startTime) / 1e6);
14
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/reactivity/Reactivity.js
13
15
  const TypeId$6 = "~effect/reactivity/Reactivity";
14
16
  const Reactivity = Service("effect/reactivity/Reactivity");
15
17
  const make$6 = sync(() => {
@@ -130,7 +132,7 @@ const keysToHashes = (keys, f) => {
130
132
  for (let i = 0; i < ids.length; i++) f(`${key}:${stringOrHash(ids[i])}`);
131
133
  }
132
134
  };
133
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/sql/SqlError.js
135
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/sql/SqlError.js
134
136
  const TypeId$5 = "~effect/sql/SqlError";
135
137
  const ReasonTypeId = "~effect/sql/SqlError/Reason";
136
138
  const ReasonFields = {
@@ -303,7 +305,7 @@ var ResultLengthMismatch = class extends TaggedError("effect/sql/ResultLengthMis
303
305
  return `Expected ${this.expected} results but got ${this.actual}`;
304
306
  }
305
307
  };
306
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/sql/Statement.js
308
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/sql/Statement.js
307
309
  const FragmentTypeId = Symbol.for("~effect/sql/Statement/Fragment");
308
310
  const SegmentTypeId = Symbol.for("~effect/sql/Statement/Segment");
309
311
  const fragment = (segments) => ({
@@ -366,15 +368,13 @@ const recordUpdateHelperSingle = (value, omit) => Object.assign(Object.create(Re
366
368
  returningIdentifier: void 0
367
369
  });
368
370
  const make$5 = (acquirer, compiler, spanAttributes, transformRows, borrower) => {
369
- const cache = transformRows === void 0 ? constructorCache.noTransforms : constructorCache.transforms;
370
- if (cache.has(acquirer)) return cache.get(acquirer);
371
371
  const self = Object.assign(function sql(strings, ...args) {
372
372
  if (typeof strings === "string") return identifier(strings);
373
- else if (Array.isArray(strings) && "raw" in strings) return statement(acquirer, compiler, strings, args, spanAttributes, transformRows, borrower);
373
+ else if (Array.isArray(strings) && "raw" in strings) return makeUnsafe$1(templateSegments(strings, args), acquirer, compiler, spanAttributes, transformRows, borrower, self);
374
374
  throw "absurd";
375
375
  }, {
376
376
  unsafe(sql, params) {
377
- return makeUnsafe$1([literal(sql, params)], acquirer, compiler, spanAttributes, transformRows, borrower);
377
+ return makeUnsafe$1([literal(sql, params)], acquirer, compiler, spanAttributes, transformRows, borrower, self);
378
378
  },
379
379
  literal(sql) {
380
380
  return fragment([literal(sql)]);
@@ -400,14 +400,9 @@ const make$5 = (acquirer, compiler, spanAttributes, transformRows, borrower) =>
400
400
  return options[compiler.dialect] !== void 0 ? options[compiler.dialect]() : options.orElse();
401
401
  }
402
402
  });
403
- cache.set(acquirer, self);
404
403
  return self;
405
404
  };
406
- const constructorCache = {
407
- transforms: new WeakMap(),
408
- noTransforms: new WeakMap()
409
- };
410
- const statement = (acquirer, compiler, strings, args, spanAttributes, transformRows, borrower) => {
405
+ const templateSegments = (strings, args) => {
411
406
  const segments = strings[0].length > 0 ? [literal(strings[0])] : [];
412
407
  for (let i = 0; i < args.length; i++) {
413
408
  const arg = args[i];
@@ -416,7 +411,7 @@ const statement = (acquirer, compiler, strings, args, spanAttributes, transformR
416
411
  else segments.push(parameter(arg));
417
412
  if (strings[i + 1].length > 0) segments.push(literal(strings[i + 1]));
418
413
  }
419
- return makeUnsafe$1(segments, acquirer, compiler, spanAttributes, transformRows, borrower);
414
+ return segments;
420
415
  };
421
416
  function join(lit, addParens = true, fallback = "") {
422
417
  const literalStatement = literal(lit);
@@ -690,13 +685,12 @@ const spanName = (spanAttributes) => {
690
685
  return isNonEmptyString(system) ? system : "sql.execute";
691
686
  };
692
687
  const ATTR_DB_QUERY_TEXT = "db.query.text";
693
- const ATTR_DB_CLIENT_CONNECTION_WAIT_TIME = "db.client.connection.wait_time_ms";
694
688
  const ATTR_SQL_METHOD = "effect.sql.method";
695
689
  const spanAttribute = (spanAttributes, key) => {
696
690
  for (let i = spanAttributes.length - 1; i >= 0; i--) if (spanAttributes[i][0] === key) return spanAttributes[i][1];
697
691
  };
698
692
  const isNonEmptyString = (u) => typeof u === "string" && u.length > 0;
699
- const makeUnsafe$1 = (segments, acquirer, compiler, spanAttributes, transformRows, borrower) => {
693
+ const makeUnsafe$1 = (segments, acquirer, compiler, spanAttributes, transformRows, borrower, sql) => {
700
694
  const self = Object.create(StatementProto);
701
695
  self.segments = segments;
702
696
  self.acquirer = acquirer;
@@ -704,6 +698,7 @@ const makeUnsafe$1 = (segments, acquirer, compiler, spanAttributes, transformRow
704
698
  self.spanAttributes = spanAttributes;
705
699
  self.transformRows = transformRows;
706
700
  self.borrower = borrower;
701
+ self.sql = sql;
707
702
  return self;
708
703
  };
709
704
  const StatementProto = {
@@ -764,7 +759,7 @@ const StatementProto = {
764
759
  evaluate(fiber) {
765
760
  const span = makeSpanUnsafe(fiber, spanName(this.spanAttributes), { kind: "client" });
766
761
  const clock = fiber.getRef(Clock);
767
- const timingEnabled = fiber.getRef(TracerTimingEnabled);
762
+ const timingEnabled = fiber.getRef(TracerTimingEnabled$1);
768
763
  return onExit(this.withConnectionSpan("execute", (connection, sql, params) => connection.execute(sql, params, this.transformRows), false, span), (exit) => endSpan(span, exit, clock, timingEnabled));
769
764
  }
770
765
  }),
@@ -781,12 +776,10 @@ const StatementProto = {
781
776
  };
782
777
  }
783
778
  };
784
- const waitClock = (fiber) => fiber.getRef(TracerTimingEnabled) ? fiber.getRef(Clock) : void 0;
785
- const recordConnectionWait = (span, clock) => span.attribute(ATTR_DB_CLIENT_CONNECTION_WAIT_TIME, Number(clock.currentTimeNanosUnsafe() - span.status.startTime) / 1e6);
786
779
  const withStatement = (self, span, f) => withFiber((fiber) => {
787
780
  const transform = fiber.getRef(CurrentTransformer);
788
781
  if (transform === void 0) return f(self, fiber);
789
- return flatMap(transform(self, make$5(self.acquirer, self.compiler, self.spanAttributes, self.transformRows, self.borrower), fiber, span), (statement) => f(statement, fiber));
782
+ return flatMap(transform(self, self.sql ?? make$5(self.acquirer, self.compiler, self.spanAttributes, self.transformRows, self.borrower), fiber, span), (statement) => f(statement, fiber));
790
783
  });
791
784
  const isSegment = (u) => hasProperty(u, SegmentTypeId);
792
785
  function convertLiteralOrFragment(clause) {
@@ -829,16 +822,17 @@ function in_() {
829
822
  const neverFragment = fragment([literal("1=0")]);
830
823
  const emptyInKeyword = /\b(NOT\s+)?IN\s*$/i;
831
824
  const isInLineComment = (sql, index) => sql.lastIndexOf("--", index) > sql.lastIndexOf("\n", index);
832
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/sql/SqlClient.js
825
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/sql/SqlClient.js
833
826
  const TypeId$4 = "~effect/sql/SqlClient";
834
827
  const SqlClient = Service("effect/sql/SqlClient");
835
828
  let clientIdCounter = 0;
836
829
  let transactionSemaphoreIdCounter = 0;
830
+ const ATTR_DB_OPERATION_NAME = "db.operation.name";
837
831
  const make$4 = fnUntraced(function* (options) {
838
832
  const transactionService = options.transactionService ?? TransactionConnection(clientIdCounter++);
839
833
  const getConnection = flatMap(serviceOption(transactionService), match({
840
834
  onNone: () => options.acquirer,
841
- onSome: ([conn]) => succeed(conn)
835
+ onSome: activeTransactionConnection
842
836
  }));
843
837
  const beginTransaction = options.beginTransaction ?? "BEGIN";
844
838
  const commit = options.commit ?? "COMMIT";
@@ -855,7 +849,7 @@ const make$4 = fnUntraced(function* (options) {
855
849
  transactionService,
856
850
  spanAttributes: options.spanAttributes,
857
851
  acquireConnection: (restore) => restore(transactionAcquirer),
858
- begin: (conn, statement) => statement === void 0 ? control(conn, beginTransaction) : unprepared(conn, statement),
852
+ begin: options.begin ?? ((conn, statement) => statement === void 0 ? control(conn, beginTransaction) : unprepared(conn, statement)),
859
853
  savepoint: (conn, id) => control(conn, savepoint(`effect_sql_${id}`)),
860
854
  releaseSavepoint: releaseSavepoint ? (conn, id) => cleanup(conn, releaseSavepoint(`effect_sql_${id}`)) : void 0,
861
855
  commit: typeof commit === "string" ? (conn) => control(conn, commit) : commit,
@@ -867,7 +861,7 @@ const make$4 = fnUntraced(function* (options) {
867
861
  const reactivity = yield* Reactivity;
868
862
  const borrower = options.borrower === void 0 ? void 0 : (f) => flatMap(serviceOption(transactionService), match({
869
863
  onNone: () => options.borrower(f),
870
- onSome: ([conn]) => f(conn)
864
+ onSome: (transaction) => flatMap(activeTransactionConnection(transaction), f)
871
865
  }));
872
866
  const client = Object.assign(make$5(getConnection, options.compiler, options.spanAttributes, options.transformRows, borrower), {
873
867
  [TypeId$4]: TypeId$4,
@@ -878,7 +872,6 @@ const make$4 = fnUntraced(function* (options) {
878
872
  reserve: transactionAcquirer,
879
873
  driver: options.driver,
880
874
  withoutTransforms() {
881
- if (options.transformRows === void 0) return this;
882
875
  const statement = make$5(getConnection, options.compiler.withoutTransform, options.spanAttributes, void 0, borrower);
883
876
  const client = Object.assign(statement, {
884
877
  ...this,
@@ -932,6 +925,15 @@ const isNoTransactionError = (error) => {
932
925
  };
933
926
  const failuresToDefects = (cause) => fromReasons(cause.reasons.map((reason) => isFailReason(reason) ? makeDieReason(reason.error).annotate(reasonAnnotations(reason)) : reason));
934
927
  const afterCommitBuffers = new WeakMap();
928
+ const hasEnded = (buffer) => {
929
+ for (; buffer !== void 0; buffer = buffer.parent) if (!buffer.open) return true;
930
+ return false;
931
+ };
932
+ const transactionEnded = suspend(() => fail(new SqlError({ reason: new UnknownError({
933
+ cause: void 0,
934
+ message: "SqlClient: the transaction has already ended"
935
+ }) })));
936
+ const activeTransactionConnection = (transaction) => hasEnded(afterCommitBuffers.get(transaction)) ? transactionEnded : succeed(transaction[0]);
935
937
  const runAfterCommit = (effect) => ignoreCause(effect, {
936
938
  log: "Unhandled",
937
939
  message: "Unhandled error in SqlClient.afterCommit callback"
@@ -940,13 +942,14 @@ const makeAfterCommit = (transactionService) => (effect) => withFiber((fiber) =>
940
942
  const transaction = getOrUndefined(fiber.context, transactionService);
941
943
  const buffer = transaction && afterCommitBuffers.get(transaction);
942
944
  if (buffer === void 0) return runAfterCommit(effect);
943
- for (let current = buffer; current !== void 0; current = current.parent) if (!current.open) return die(new Error("SqlClient.afterCommit: the transaction has already ended"));
945
+ if (hasEnded(buffer)) return die(new Error("SqlClient.afterCommit: the transaction has already ended"));
944
946
  buffer.callbacks.push(provideContext(effect, omit(transactionService)(fiber.context)));
945
947
  return void_$1;
946
948
  });
947
949
  const makeWithTransaction = (options) => {
948
950
  const transactionSemaphore = Service(`effect/sql/SqlClient/TransactionSemaphore/${transactionSemaphoreIdCounter++}`);
949
951
  const afterCommit = makeAfterCommit(options.transactionService);
952
+ const target = spanTarget(options.spanAttributes);
950
953
  const deferInvalidations = (reactivity) => {
951
954
  const invalidate = (keys) => afterCommit(sync(() => reactivity.invalidateUnsafe(keys)));
952
955
  return {
@@ -959,9 +962,20 @@ const makeWithTransaction = (options) => {
959
962
  for (const [key, value] of options.spanAttributes) span.attribute(key, value);
960
963
  const services = fiber.context;
961
964
  const reactivity = getOrUndefined(services, Reactivity);
962
- const clock = fiber.getRef(Clock);
965
+ const waitedClock = fiber.cache.tracerEnabled && fiber.getRef(SpanPropagationEnabled) ? waitClock(fiber) : void 0;
966
+ const control = (operation, effect) => useSpan(target === void 0 ? operation : `${operation} ${target}`, {
967
+ kind: "client",
968
+ parent: span
969
+ }, (controlSpan) => {
970
+ for (const [key, value] of options.spanAttributes) controlSpan.attribute(key, value);
971
+ controlSpan.attribute(ATTR_DB_OPERATION_NAME, operation);
972
+ return effect;
973
+ });
963
974
  const connOption = getOption(services, options.transactionService);
964
- const conn = connOption._tag === "Some" ? succeed([void 0, connOption.value[0]]) : flatMap(make$7(), (scope) => provide(options.acquireConnection(restore), scope).pipe(map((conn) => [scope, conn]), onError((cause) => close(scope, failCause(cause)))));
975
+ const conn = connOption._tag === "Some" ? map(suspend(() => activeTransactionConnection(connOption.value)), (conn) => [void 0, conn]) : flatMap(make$7(), (scope) => provide(options.acquireConnection(restore), scope).pipe(provideService(ParentSpan, span), map((conn) => {
976
+ if (waitedClock !== void 0) recordConnectionWait(span, waitedClock);
977
+ return [scope, conn];
978
+ }), onError((cause) => close(scope, failCause(cause)))));
965
979
  const id = connOption._tag === "Some" ? connOption.value[1] + 1 : 0;
966
980
  const buffer = {
967
981
  callbacks: [],
@@ -969,28 +983,28 @@ const makeWithTransaction = (options) => {
969
983
  open: true
970
984
  };
971
985
  let committed = false;
972
- const transaction = flatMap(conn, ([scope, conn]) => (id === 0 ? options.begin(conn, fiber.getRef(BeginTransaction)) : options.savepoint(conn, id)).pipe(flatMap(() => {
986
+ const start = (conn) => id === 0 ? control("BEGIN", options.begin(conn, fiber.getRef(BeginTransaction))) : control("SAVEPOINT", options.savepoint(conn, id));
987
+ const transaction = flatMap(conn, ([scope, conn]) => start(conn).pipe(flatMap(() => {
973
988
  const level = [conn, id];
974
989
  afterCommitBuffers.set(level, buffer);
975
990
  return onExitPrimitive(provideContext(restore(effect), services.pipe(add(options.transactionService, level), add(CurrentTransactionService, options.transactionService), reactivity ? add(Reactivity, deferInvalidations(reactivity)) : identity, add(transactionSemaphore, makeUnsafe$3(1)), add(ParentSpan, span))), (exit) => {
991
+ buffer.open = false;
992
+ if (hasEnded(buffer.parent)) return isSuccess(exit) ? transactionEnded : exit;
976
993
  let effect;
977
994
  if (isSuccess(exit)) {
978
995
  if (id === 0) {
979
- span.event("effect.sql.transaction.commit", clock.currentTimeNanosUnsafe());
980
996
  const onCommitFailure = options.onCommitFailure;
981
- effect = onCommitFailure ? catchCause(options.commit(conn), (commitCause) => matchCauseEffect(onCommitFailure(conn), {
997
+ const commit = control("COMMIT", options.commit(conn));
998
+ effect = onCommitFailure ? catchCause(commit, (commitCause) => matchCauseEffect(control("ROLLBACK", onCommitFailure(conn)), {
982
999
  onFailure: (cleanupCause) => failCause$1(failuresToDefects(combine(commitCause, cleanupCause))),
983
1000
  onSuccess: () => failCause$1(commitCause)
984
- })) : options.commit(conn);
985
- } else {
986
- span.event("effect.sql.transaction.savepoint", clock.currentTimeNanosUnsafe());
987
- effect = void_$1;
988
- }
989
- } else {
990
- span.event("effect.sql.transaction.rollback", clock.currentTimeNanosUnsafe());
991
- effect = orDie(id > 0 ? options.rollbackSavepoint(conn, id) : options.rollback(conn));
1001
+ })) : commit;
1002
+ } else effect = void_$1;
1003
+ } else effect = orDie(id > 0 ? control("ROLLBACK TO SAVEPOINT", options.rollbackSavepoint(conn, id)) : control("ROLLBACK", options.rollback(conn)));
1004
+ if (id > 0 && options.releaseSavepoint) {
1005
+ const release = orDie(control("RELEASE SAVEPOINT", options.releaseSavepoint(conn, id)));
1006
+ effect = flatMap(effect, () => hasEnded(buffer.parent) ? void_$1 : release);
992
1007
  }
993
- if (id > 0 && options.releaseSavepoint) effect = andThen(effect, orDie(options.releaseSavepoint(conn, id)));
994
1008
  return flatMap(effect, () => {
995
1009
  committed = isSuccess(exit);
996
1010
  return exit;
@@ -998,7 +1012,6 @@ const makeWithTransaction = (options) => {
998
1012
  }, true);
999
1013
  }), scope ? (eff) => onExitPrimitive(eff, (exit) => close(scope, exit), true) : identity));
1000
1014
  const settled = onExitPrimitive(transaction, () => {
1001
- buffer.open = false;
1002
1015
  if (!committed || buffer.callbacks.length === 0) return;
1003
1016
  if (buffer.parent !== void 0) {
1004
1017
  buffer.parent.callbacks.push(...buffer.callbacks);
@@ -1006,13 +1019,13 @@ const makeWithTransaction = (options) => {
1006
1019
  }
1007
1020
  return forEach(buffer.callbacks, runAfterCommit, { discard: true });
1008
1021
  }, true);
1009
- return id === 0 ? settled : getUnsafe(services, transactionSemaphore).withPermit(settled);
1022
+ return id === 0 ? settled : restore(getUnsafe(services, transactionSemaphore).withPermit(uninterruptible(settled)));
1010
1023
  })));
1011
1024
  };
1012
1025
  const TransactionConnection = (clientId) => Service(`effect/sql/SqlClient/TransactionConnection/${clientId}`);
1013
1026
  const SafeIntegers = Reference("effect/sql/SqlClient/SafeIntegers", { defaultValue: () => false });
1014
1027
  const BeginTransaction = Reference("effect/sql/SqlClient/BeginTransaction", { defaultValue: () => void 0 });
1015
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Cache.js
1028
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/Cache.js
1016
1029
  const TypeId$3 = "~effect/Cache";
1017
1030
  const makeWith = (lookup, options) => contextWith$1((context) => {
1018
1031
  const self = Object.create(Proto$1);
@@ -1104,7 +1117,7 @@ const checkCapacity = (self) => {
1104
1117
  if (diff === 0) return;
1105
1118
  }
1106
1119
  };
1107
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/schema/VariantSchema.js
1120
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/schema/VariantSchema.js
1108
1121
  const TypeId$2 = "~effect/schema/VariantSchema";
1109
1122
  const cacheSymbol = Symbol.for(`${TypeId$2}/cache`);
1110
1123
  const defaultCacheSymbol = Symbol.for(`${TypeId$2}/defaultCache`);
@@ -1221,7 +1234,7 @@ const Union$1 = (members, defaultVariant, variants) => {
1221
1234
  for (const variant of variants) Object.defineProperty(VariantUnion, variant, { value: Union$2(members.map((member) => extract$1(member, variant))) });
1222
1235
  return VariantUnion;
1223
1236
  };
1224
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/schema/Model.js
1237
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/schema/Model.js
1225
1238
  const { Class, Field, FieldExcept, FieldOnly, Struct, Union, extract, fieldEvolve } = make$3({
1226
1239
  variants: [
1227
1240
  "select",
@@ -1294,7 +1307,7 @@ const DateTimeUpdateFromNumber = Field({
1294
1307
  update: DateTimeFromNumberWithNow,
1295
1308
  json: DateTimeUtcFromMillis
1296
1309
  });
1297
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/sql/SqlResolver.js
1310
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/sql/SqlResolver.js
1298
1311
  const SqlRequestProto = {
1299
1312
  ...Class$2.prototype,
1300
1313
  [symbol](that) {
@@ -1426,13 +1439,13 @@ function transactionKey(entry) {
1426
1439
  if (currentTransaction === void 0) return byReferenceUnsafe(clientTransaction);
1427
1440
  return [byReferenceUnsafe(clientTransaction), byReferenceUnsafe(currentTransaction)];
1428
1441
  }
1429
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/sql/SqlSchema.js
1442
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/sql/SqlSchema.js
1430
1443
  const findAll = (options) => {
1431
1444
  const encodeRequest = encodeEffect(options.Request);
1432
1445
  const decode = decodeUnknownEffect(mutable(ArraySchema(options.Result)));
1433
1446
  return (request) => flatMap(flatMap(encodeRequest(request), options.execute), decode);
1434
1447
  };
1435
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/sql/SqlModel.js
1448
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/sql/SqlModel.js
1436
1449
  const makeResolvers = (Model, options) => gen(function* () {
1437
1450
  const sql = yield* SqlClient;
1438
1451
  const idSchema = Model.fields[options.idColumn];
@@ -2043,7 +2056,7 @@ const layer$3 = effect(CodeChunker, gen(function* () {
2043
2056
  chunkCodebase
2044
2057
  });
2045
2058
  }));
2046
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/FiberHandle.js
2059
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/FiberHandle.js
2047
2060
  const TypeId$1 = "~effect/FiberHandle";
2048
2061
  const isFiberHandle = (u) => hasProperty(u, TypeId$1);
2049
2062
  const Proto = {
@@ -2118,7 +2131,7 @@ const runImpl = (self, effect, options) => withFiber((parent) => {
2118
2131
  setUnsafe(self, fiber, options);
2119
2132
  return succeed(fiber);
2120
2133
  });
2121
- // node_modules/.pnpm/@effect+sql-sqlite-node@4.1.1_effect@4.1.1/node_modules/@effect/sql-sqlite-node/dist/SqliteClient.js
2134
+ // node_modules/.pnpm/@effect+sql-sqlite-node@4.1.3_effect@4.1.3/node_modules/@effect/sql-sqlite-node/dist/SqliteClient.js
2122
2135
  const ATTR_DB_SYSTEM_NAME = "db.system.name";
2123
2136
  const MAX_BUSY_TIMEOUT = 2147483647;
2124
2137
  const NANOS_PER_MILLI = BigInt(1e6);
@@ -2287,7 +2300,7 @@ const sqliteCauseWithErrno = (cause) => {
2287
2300
  const setLoadExtensionEnabled = (db, enabled) => {
2288
2301
  if (typeof db.enableLoadExtension === "function") db.enableLoadExtension(enabled);
2289
2302
  };
2290
- // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/sql/Migrator.js
2303
+ // node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/sql/Migrator.js
2291
2304
  var MigrationError = class extends TaggedError$1("MigrationError") {};
2292
2305
  const make = ({ transformWrites = identity, dumpSchema = () => void_$1 }) => ({ loader, schemaDirectory, table = "effect_sql_migrations" }) => gen(function* () {
2293
2306
  const sql = yield* SqlClient;
@@ -2403,7 +2416,7 @@ const fromRecord = (migrations) => pipe(Object.keys(migrations), flatMapNullishO
2403
2416
  name,
2404
2417
  succeed(migrations[key])
2405
2418
  ]), sort(migrationOrder), succeed);
2406
- // node_modules/.pnpm/@effect+sql-sqlite-node@4.1.1_effect@4.1.1/node_modules/@effect/sql-sqlite-node/dist/SqliteMigrator.js
2419
+ // node_modules/.pnpm/@effect+sql-sqlite-node@4.1.3_effect@4.1.3/node_modules/@effect/sql-sqlite-node/dist/SqliteMigrator.js
2407
2420
  const run = make({});
2408
2421
  const layer$1 = (options) => effectDiscard(run(options));
2409
2422
  // src/Sqlite.ts