apps 0.0.1-beta.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.
- package/README.md +191 -0
- package/check-publish.mjs +10 -0
- package/framework-reference.json +1 -0
- package/js/chunk-22WRQZT7.js +389 -0
- package/js/chunk-2OTCEKL2.js +29480 -0
- package/js/chunk-36DNRFZQ.js +34 -0
- package/js/chunk-3ANFZFCV.js +1799 -0
- package/js/chunk-7JXHF5IF.js +138 -0
- package/js/chunk-BCSNKUAC.js +0 -0
- package/js/chunk-BKVL7XAJ.js +47 -0
- package/js/chunk-BPEFS4YF.js +1323 -0
- package/js/chunk-C24KEZXR.js +59 -0
- package/js/chunk-D6BKYP2L.js +877 -0
- package/js/chunk-EP6AEUZO.js +19 -0
- package/js/chunk-HP7E42X6.js +1719 -0
- package/js/chunk-KWTCHVLT.js +284 -0
- package/js/chunk-LOKGDT6B.js +28 -0
- package/js/chunk-MLKGABMK.js +9 -0
- package/js/chunk-OWD2YICM.js +2486 -0
- package/js/chunk-Q2FD5IBM.js +899 -0
- package/js/chunk-R6JMJSVT.js +590 -0
- package/js/chunk-SBKHUC5L.js +56 -0
- package/js/chunk-VFUZI3NY.js +75 -0
- package/js/chunk-W7Q5EOTS.js +4375 -0
- package/js/chunk-WIDTG42X.js +171 -0
- package/js/chunk-X3YBZCJW.js +246 -0
- package/js/chunk-YDR4CPJA.js +2357 -0
- package/js/client.js +1023 -0
- package/js/contracts.js +163 -0
- package/js/effect.js +44 -0
- package/js/graphql.js +392 -0
- package/js/host.js +193 -0
- package/js/index.js +284 -0
- package/js/mcp/effect.js +23 -0
- package/js/mcp/stdio.js +123 -0
- package/js/mcp.js +37 -0
- package/js/openapi.js +246 -0
- package/js/operations/approval.js +9 -0
- package/js/react.js +37 -0
- package/js/storage/facet.js +546 -0
- package/js/ui/auth/contracts.js +19 -0
- package/js/ui/auth.js +28 -0
- package/js/ui/contracts.js +24 -0
- package/js/ui/serving.js +286 -0
- package/package.json +116 -0
- package/runtime.json +1 -0
- package/types/app-data/src/contracts/database.d.ts +193 -0
- package/types/app-data/src/implementation/cursor.d.ts +10 -0
- package/types/app-data/src/implementation/index-key.d.ts +7 -0
- package/types/app-data/src/implementation/promise.d.ts +68 -0
- package/types/app-data/src/implementation/range.d.ts +8 -0
- package/types/app-data/src/implementation/schema.d.ts +33 -0
- package/types/app-data/src/implementation/sqlite.d.ts +11 -0
- package/types/app-data/src/index.d.ts +4 -0
- package/types/apps/src/approval.d.ts +10 -0
- package/types/apps/src/client.d.ts +5 -0
- package/types/apps/src/contracts/app.d.ts +58 -0
- package/types/apps/src/contracts/approval.d.ts +14 -0
- package/types/apps/src/contracts/context.d.ts +25 -0
- package/types/apps/src/contracts/elicitation.d.ts +86 -0
- package/types/apps/src/contracts/graphql.d.ts +102 -0
- package/types/apps/src/contracts/host.d.ts +568 -0
- package/types/apps/src/contracts/http.d.ts +20 -0
- package/types/apps/src/contracts/live.d.ts +26 -0
- package/types/apps/src/contracts/mcp.d.ts +93 -0
- package/types/apps/src/contracts/openapi.d.ts +105 -0
- package/types/apps/src/contracts/operations.d.ts +30 -0
- package/types/apps/src/contracts/optimistic.d.ts +22 -0
- package/types/apps/src/contracts/provider.d.ts +96 -0
- package/types/apps/src/contracts/schedules.d.ts +51 -0
- package/types/apps/src/contracts/schema.d.ts +20 -0
- package/types/apps/src/contracts/storage.d.ts +68 -0
- package/types/apps/src/contracts/tools.d.ts +11 -0
- package/types/apps/src/contracts/ui-auth.d.ts +28 -0
- package/types/apps/src/contracts/ui.d.ts +90 -0
- package/types/apps/src/contracts/webhook-protocol.d.ts +102 -0
- package/types/apps/src/contracts/webhooks.d.ts +53 -0
- package/types/apps/src/contracts/workflows.d.ts +277 -0
- package/types/apps/src/effect.d.ts +10 -0
- package/types/apps/src/facet.d.ts +5 -0
- package/types/apps/src/graphql.d.ts +10 -0
- package/types/apps/src/host.d.ts +16 -0
- package/types/apps/src/implementation/account-operations.d.ts +32 -0
- package/types/apps/src/implementation/app.d.ts +40 -0
- package/types/apps/src/implementation/authoring.d.ts +12 -0
- package/types/apps/src/implementation/elicitation.d.ts +103 -0
- package/types/apps/src/implementation/graphql.d.ts +5 -0
- package/types/apps/src/implementation/host.d.ts +3 -0
- package/types/apps/src/implementation/http.d.ts +5 -0
- package/types/apps/src/implementation/live.d.ts +18 -0
- package/types/apps/src/implementation/mcp-call.d.ts +19 -0
- package/types/apps/src/implementation/mcp-client.d.ts +50 -0
- package/types/apps/src/implementation/mcp-stdio.d.ts +4 -0
- package/types/apps/src/implementation/mcp-tools.d.ts +6 -0
- package/types/apps/src/implementation/mcp.d.ts +4 -0
- package/types/apps/src/implementation/openapi-request.d.ts +11 -0
- package/types/apps/src/implementation/openapi.d.ts +5 -0
- package/types/apps/src/implementation/operations.d.ts +65 -0
- package/types/apps/src/implementation/optimistic.d.ts +30 -0
- package/types/apps/src/implementation/protocol-operations.d.ts +24 -0
- package/types/apps/src/implementation/provider.d.ts +16 -0
- package/types/apps/src/implementation/query-commit.d.ts +10 -0
- package/types/apps/src/implementation/schedules.d.ts +16 -0
- package/types/apps/src/implementation/schema.d.ts +93 -0
- package/types/apps/src/implementation/storage.d.ts +13 -0
- package/types/apps/src/implementation/ui-auth.d.ts +13 -0
- package/types/apps/src/implementation/ui-client.d.ts +16 -0
- package/types/apps/src/implementation/ui-errors.d.ts +2 -0
- package/types/apps/src/implementation/ui-serving.d.ts +16 -0
- package/types/apps/src/implementation/ui-watch.d.ts +2 -0
- package/types/apps/src/implementation/webhooks.d.ts +29 -0
- package/types/apps/src/implementation/workflow-context.d.ts +8 -0
- package/types/apps/src/implementation/workflow-rpc.d.ts +5 -0
- package/types/apps/src/implementation/workflows.d.ts +27 -0
- package/types/apps/src/index.d.ts +58 -0
- package/types/apps/src/mcp-stdio.d.ts +8 -0
- package/types/apps/src/mcp.d.ts +10 -0
- package/types/apps/src/openapi.d.ts +10 -0
- package/types/apps/src/react.d.ts +7 -0
- package/types/apps/src/ui-auth.d.ts +3 -0
- package/types/apps/src/ui-serving.d.ts +3 -0
- package/types/telemetry/src/browser-operations.d.ts +16 -0
- package/types/telemetry/src/browser-performance.d.ts +11 -0
- package/types/telemetry/src/browser-request-timing.d.ts +2 -0
- package/types/telemetry/src/browser.d.ts +27 -0
- package/types/telemetry/src/config.d.ts +83 -0
- package/types/telemetry/src/context.d.ts +14 -0
- package/types/telemetry/src/index.d.ts +9 -0
- package/types/telemetry/src/layer.d.ts +7 -0
- package/types/telemetry/src/measurements.d.ts +8 -0
- package/types/telemetry/src/pending-span.d.ts +7 -0
- package/types/telemetry/src/relay.d.ts +28 -0
- package/types/telemetry/src/span-attributes.d.ts +29 -0
- package/types/telemetry/src/trace-context.d.ts +20 -0
- package/types/telemetry/src/transport.d.ts +6 -0
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Clock,
|
|
3
|
+
ParentSpan,
|
|
4
|
+
Prototype,
|
|
5
|
+
Reference,
|
|
6
|
+
Scope,
|
|
7
|
+
Service,
|
|
8
|
+
TracerTimingEnabled,
|
|
9
|
+
add,
|
|
10
|
+
addFinalizer,
|
|
11
|
+
assignProperty,
|
|
12
|
+
close,
|
|
13
|
+
constUndefined,
|
|
14
|
+
context,
|
|
15
|
+
contextWith,
|
|
16
|
+
dual,
|
|
17
|
+
effect,
|
|
18
|
+
endSpan,
|
|
19
|
+
failCauseUnsafe,
|
|
20
|
+
flatMap2 as flatMap,
|
|
21
|
+
flow,
|
|
22
|
+
fnUntraced,
|
|
23
|
+
fromQueue,
|
|
24
|
+
gen,
|
|
25
|
+
get,
|
|
26
|
+
getOption,
|
|
27
|
+
getOrUndefined2 as getOrUndefined,
|
|
28
|
+
getUnsafe,
|
|
29
|
+
hasProperty,
|
|
30
|
+
hash,
|
|
31
|
+
identity,
|
|
32
|
+
isSuccess2 as isSuccess,
|
|
33
|
+
make3 as make,
|
|
34
|
+
make4 as make2,
|
|
35
|
+
makeSpanScoped,
|
|
36
|
+
makeSpanUnsafe,
|
|
37
|
+
makeUnsafe3 as makeUnsafe,
|
|
38
|
+
map3 as map,
|
|
39
|
+
match,
|
|
40
|
+
offerUnsafe,
|
|
41
|
+
onExit,
|
|
42
|
+
onExitPrimitive,
|
|
43
|
+
orDie,
|
|
44
|
+
provide,
|
|
45
|
+
provideContext,
|
|
46
|
+
provideService,
|
|
47
|
+
provideService2,
|
|
48
|
+
runForkWith,
|
|
49
|
+
runIn,
|
|
50
|
+
scoped,
|
|
51
|
+
serviceOption,
|
|
52
|
+
succeed4 as succeed,
|
|
53
|
+
suspend,
|
|
54
|
+
sync2 as sync,
|
|
55
|
+
tap,
|
|
56
|
+
uninterruptibleMask,
|
|
57
|
+
unwrap3 as unwrap,
|
|
58
|
+
useSpan,
|
|
59
|
+
void_2 as void_,
|
|
60
|
+
withFiber
|
|
61
|
+
} from "./chunk-2OTCEKL2.js";
|
|
62
|
+
|
|
63
|
+
// ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b0796b742bddeb797269d/node_modules/effect/dist/unstable/reactivity/Reactivity.js
|
|
64
|
+
var TypeId = "~effect/reactivity/Reactivity";
|
|
65
|
+
var Reactivity = /* @__PURE__ */ Service("effect/reactivity/Reactivity");
|
|
66
|
+
var make3 = /* @__PURE__ */ sync(() => {
|
|
67
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
68
|
+
const invalidateUnsafe = (keys) => {
|
|
69
|
+
keysToHashes(keys, (hash2) => {
|
|
70
|
+
const set = handlers.get(hash2);
|
|
71
|
+
if (set === void 0) return;
|
|
72
|
+
set.forEach((run) => run());
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const invalidate2 = (keys) => contextWith((services) => {
|
|
76
|
+
const pending = getOrUndefined(services, PendingInvalidation);
|
|
77
|
+
if (pending) {
|
|
78
|
+
keysToHashes(keys, (hash2) => {
|
|
79
|
+
pending.add(hash2);
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
invalidateUnsafe(keys);
|
|
83
|
+
}
|
|
84
|
+
return void_;
|
|
85
|
+
});
|
|
86
|
+
const mutation2 = (keys, effect2) => tap(effect2, invalidate2(keys));
|
|
87
|
+
const registerUnsafe = (keys, handler) => {
|
|
88
|
+
const resolvedKeys = [];
|
|
89
|
+
keysToHashes(keys, (hash2) => {
|
|
90
|
+
resolvedKeys.push(hash2);
|
|
91
|
+
let set = handlers.get(hash2);
|
|
92
|
+
if (set === void 0) {
|
|
93
|
+
set = /* @__PURE__ */ new Set();
|
|
94
|
+
handlers.set(hash2, set);
|
|
95
|
+
}
|
|
96
|
+
set.add(handler);
|
|
97
|
+
});
|
|
98
|
+
return () => {
|
|
99
|
+
for (let i = 0; i < resolvedKeys.length; i++) {
|
|
100
|
+
const set = handlers.get(resolvedKeys[i]);
|
|
101
|
+
if (set === void 0) continue;
|
|
102
|
+
set.delete(handler);
|
|
103
|
+
if (set.size === 0) {
|
|
104
|
+
handlers.delete(resolvedKeys[i]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
const query = (keys, effect2) => gen(function* () {
|
|
110
|
+
const services = yield* context();
|
|
111
|
+
const scope = get(services, Scope);
|
|
112
|
+
const results = yield* make2();
|
|
113
|
+
const runFork = flow(runForkWith(services), runIn(scope));
|
|
114
|
+
let running = false;
|
|
115
|
+
let pending = false;
|
|
116
|
+
const handleExit = (exit) => {
|
|
117
|
+
if (exit._tag === "Failure") {
|
|
118
|
+
failCauseUnsafe(results, exit.cause);
|
|
119
|
+
} else {
|
|
120
|
+
offerUnsafe(results, exit.value);
|
|
121
|
+
}
|
|
122
|
+
if (pending) {
|
|
123
|
+
pending = false;
|
|
124
|
+
runFork(effect2).addObserver(handleExit);
|
|
125
|
+
} else {
|
|
126
|
+
running = false;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
function run() {
|
|
130
|
+
if (running) {
|
|
131
|
+
pending = true;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
running = true;
|
|
135
|
+
runFork(effect2).addObserver(handleExit);
|
|
136
|
+
}
|
|
137
|
+
const cancel = registerUnsafe(keys, run);
|
|
138
|
+
yield* addFinalizer(scope, sync(cancel));
|
|
139
|
+
run();
|
|
140
|
+
return results;
|
|
141
|
+
});
|
|
142
|
+
const stream = (tables, effect2) => query(tables, effect2).pipe(map(fromQueue), unwrap);
|
|
143
|
+
const withBatch = (effect2) => suspend(() => {
|
|
144
|
+
const pending = /* @__PURE__ */ new Set();
|
|
145
|
+
return effect2.pipe(provideService(PendingInvalidation, pending), onExit((_) => sync(() => {
|
|
146
|
+
pending.forEach((hash2) => {
|
|
147
|
+
const set = handlers.get(hash2);
|
|
148
|
+
if (set === void 0) return;
|
|
149
|
+
set.forEach((run) => run());
|
|
150
|
+
});
|
|
151
|
+
})));
|
|
152
|
+
});
|
|
153
|
+
return Reactivity.of({
|
|
154
|
+
[TypeId]: TypeId,
|
|
155
|
+
mutation: mutation2,
|
|
156
|
+
query,
|
|
157
|
+
stream,
|
|
158
|
+
invalidateUnsafe,
|
|
159
|
+
invalidate: invalidate2,
|
|
160
|
+
registerUnsafe,
|
|
161
|
+
withBatch
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
var PendingInvalidation = class extends (/* @__PURE__ */ Service()("effect/reactivity/Reactivity/PendingInvalidation")) {
|
|
165
|
+
};
|
|
166
|
+
var mutation = /* @__PURE__ */ dual(2, (effect2, keys) => Reactivity.use((_) => _.mutation(keys, effect2)));
|
|
167
|
+
var invalidate = (keys) => Reactivity.use((r) => r.invalidate(keys));
|
|
168
|
+
var layer = /* @__PURE__ */ effect(Reactivity)(make3);
|
|
169
|
+
function stringOrHash(u) {
|
|
170
|
+
switch (typeof u) {
|
|
171
|
+
case "string":
|
|
172
|
+
case "number":
|
|
173
|
+
case "bigint":
|
|
174
|
+
case "boolean":
|
|
175
|
+
return String(u);
|
|
176
|
+
default:
|
|
177
|
+
return hash(u);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
var keysToHashes = (keys, f) => {
|
|
181
|
+
if (Array.isArray(keys)) {
|
|
182
|
+
for (let i = 0; i < keys.length; i++) {
|
|
183
|
+
f(stringOrHash(keys[i]));
|
|
184
|
+
}
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
for (const key in keys) {
|
|
188
|
+
f(key);
|
|
189
|
+
const ids = keys[key];
|
|
190
|
+
for (let i = 0; i < ids.length; i++) {
|
|
191
|
+
f(`${key}:${stringOrHash(ids[i])}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b0796b742bddeb797269d/node_modules/effect/dist/unstable/sql/Statement.js
|
|
197
|
+
var FragmentTypeId = "~effect/sql/Statement/Fragment";
|
|
198
|
+
var fragment = (segments) => ({
|
|
199
|
+
[FragmentTypeId]: FragmentTypeId,
|
|
200
|
+
segments
|
|
201
|
+
});
|
|
202
|
+
var CurrentTransformer = /* @__PURE__ */ Reference("effect/sql/CurrentTransformer", {
|
|
203
|
+
defaultValue: constUndefined
|
|
204
|
+
});
|
|
205
|
+
var SpanPropagationEnabled = /* @__PURE__ */ Reference("effect/sql/SpanPropagationEnabled", {
|
|
206
|
+
defaultValue: () => false
|
|
207
|
+
});
|
|
208
|
+
var isFragment = (u) => hasProperty(u, FragmentTypeId);
|
|
209
|
+
var literal = (value, params) => ({
|
|
210
|
+
_tag: "Literal",
|
|
211
|
+
value,
|
|
212
|
+
params
|
|
213
|
+
});
|
|
214
|
+
var identifier = (value) => ({
|
|
215
|
+
_tag: "Identifier",
|
|
216
|
+
value
|
|
217
|
+
});
|
|
218
|
+
var parameter = (value) => ({
|
|
219
|
+
_tag: "Parameter",
|
|
220
|
+
value
|
|
221
|
+
});
|
|
222
|
+
var arrayHelper = (value) => ({
|
|
223
|
+
_tag: "ArrayHelper",
|
|
224
|
+
value
|
|
225
|
+
});
|
|
226
|
+
var RecordInsertHelperProto = {
|
|
227
|
+
_tag: "RecordInsertHelper",
|
|
228
|
+
returning(sql) {
|
|
229
|
+
const self = Object.create(Object.getPrototypeOf(this));
|
|
230
|
+
Object.assign(self, this, {
|
|
231
|
+
returningIdentifier: typeof sql === "string" || isFragment(sql) ? sql : fragment([sql])
|
|
232
|
+
});
|
|
233
|
+
return self;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
var recordInsertHelper = (value) => Object.assign(Object.create(RecordInsertHelperProto), {
|
|
237
|
+
value,
|
|
238
|
+
returningIdentifier: void 0
|
|
239
|
+
});
|
|
240
|
+
var RecordUpdateHelperProto = {
|
|
241
|
+
...RecordInsertHelperProto,
|
|
242
|
+
_tag: "RecordUpdateHelper"
|
|
243
|
+
};
|
|
244
|
+
var recordUpdateHelper = (value, alias) => Object.assign(Object.create(RecordUpdateHelperProto), {
|
|
245
|
+
value,
|
|
246
|
+
alias,
|
|
247
|
+
returningIdentifier: void 0
|
|
248
|
+
});
|
|
249
|
+
var RecordUpdateHelperSingleProto = {
|
|
250
|
+
...RecordInsertHelperProto,
|
|
251
|
+
_tag: "RecordUpdateHelperSingle"
|
|
252
|
+
};
|
|
253
|
+
var recordUpdateHelperSingle = (value, omit) => Object.assign(Object.create(RecordUpdateHelperSingleProto), {
|
|
254
|
+
value,
|
|
255
|
+
omit,
|
|
256
|
+
returningIdentifier: void 0
|
|
257
|
+
});
|
|
258
|
+
var make4 = (acquirer, compiler, spanAttributes, transformRows, borrower) => {
|
|
259
|
+
const cache = transformRows === void 0 ? constructorCache.noTransforms : constructorCache.transforms;
|
|
260
|
+
if (cache.has(acquirer)) {
|
|
261
|
+
return cache.get(acquirer);
|
|
262
|
+
}
|
|
263
|
+
const self = Object.assign(function sql(strings, ...args) {
|
|
264
|
+
if (typeof strings === "string") {
|
|
265
|
+
return identifier(strings);
|
|
266
|
+
} else if (Array.isArray(strings) && "raw" in strings) {
|
|
267
|
+
return statement(acquirer, compiler, strings, args, spanAttributes, transformRows, borrower);
|
|
268
|
+
}
|
|
269
|
+
throw "absurd";
|
|
270
|
+
}, {
|
|
271
|
+
unsafe(sql, params) {
|
|
272
|
+
return makeUnsafe2([literal(sql, params)], acquirer, compiler, spanAttributes, transformRows, borrower);
|
|
273
|
+
},
|
|
274
|
+
literal(sql) {
|
|
275
|
+
return fragment([literal(sql)]);
|
|
276
|
+
},
|
|
277
|
+
in: in_,
|
|
278
|
+
insert(value) {
|
|
279
|
+
return recordInsertHelper(Array.isArray(value) ? value : [value]);
|
|
280
|
+
},
|
|
281
|
+
update(value, omit) {
|
|
282
|
+
return recordUpdateHelperSingle(value, omit ?? []);
|
|
283
|
+
},
|
|
284
|
+
updateValues(value, alias) {
|
|
285
|
+
return recordUpdateHelper(value, alias);
|
|
286
|
+
},
|
|
287
|
+
and,
|
|
288
|
+
or,
|
|
289
|
+
csv,
|
|
290
|
+
join,
|
|
291
|
+
onDialect(options) {
|
|
292
|
+
return options[compiler.dialect]();
|
|
293
|
+
},
|
|
294
|
+
onDialectOrElse(options) {
|
|
295
|
+
return options[compiler.dialect] !== void 0 ? options[compiler.dialect]() : options.orElse();
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
cache.set(acquirer, self);
|
|
299
|
+
return self;
|
|
300
|
+
};
|
|
301
|
+
var constructorCache = {
|
|
302
|
+
transforms: /* @__PURE__ */ new WeakMap(),
|
|
303
|
+
noTransforms: /* @__PURE__ */ new WeakMap()
|
|
304
|
+
};
|
|
305
|
+
var statement = (acquirer, compiler, strings, args, spanAttributes, transformRows, borrower) => {
|
|
306
|
+
const segments = strings[0].length > 0 ? [literal(strings[0])] : [];
|
|
307
|
+
for (let i = 0; i < args.length; i++) {
|
|
308
|
+
const arg = args[i];
|
|
309
|
+
if (isFragment(arg)) {
|
|
310
|
+
segments.push(...arg.segments);
|
|
311
|
+
} else if (isSegment(arg)) {
|
|
312
|
+
segments.push(arg);
|
|
313
|
+
} else {
|
|
314
|
+
segments.push(parameter(arg));
|
|
315
|
+
}
|
|
316
|
+
if (strings[i + 1].length > 0) {
|
|
317
|
+
segments.push(literal(strings[i + 1]));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return makeUnsafe2(segments, acquirer, compiler, spanAttributes, transformRows, borrower);
|
|
321
|
+
};
|
|
322
|
+
function join(lit, addParens = true, fallback = "") {
|
|
323
|
+
const literalStatement = literal(lit);
|
|
324
|
+
const fallbackFragment = fragment([literal(fallback)]);
|
|
325
|
+
return (clauses) => {
|
|
326
|
+
if (clauses.length === 0) {
|
|
327
|
+
return fallbackFragment;
|
|
328
|
+
} else if (clauses.length === 1) {
|
|
329
|
+
return fragment(convertLiteralOrFragment(clauses[0]));
|
|
330
|
+
}
|
|
331
|
+
const segments = [];
|
|
332
|
+
if (addParens) {
|
|
333
|
+
segments.push(literal("("));
|
|
334
|
+
}
|
|
335
|
+
segments.push.apply(segments, convertLiteralOrFragment(clauses[0]));
|
|
336
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
337
|
+
segments.push(literalStatement);
|
|
338
|
+
segments.push.apply(segments, convertLiteralOrFragment(clauses[i]));
|
|
339
|
+
}
|
|
340
|
+
if (addParens) {
|
|
341
|
+
segments.push(literal(")"));
|
|
342
|
+
}
|
|
343
|
+
return fragment(segments);
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
var and = /* @__PURE__ */ join(" AND ", true, "1=1");
|
|
347
|
+
var or = /* @__PURE__ */ join(" OR ", true, "1=1");
|
|
348
|
+
var csv = function(...args) {
|
|
349
|
+
if (args[args.length - 1].length === 0) {
|
|
350
|
+
return emptyFragment;
|
|
351
|
+
}
|
|
352
|
+
if (args.length === 1) {
|
|
353
|
+
return csvRaw(args[0]);
|
|
354
|
+
}
|
|
355
|
+
return fragment([literal(`${args[0]} `), ...csvRaw(args[1]).segments]);
|
|
356
|
+
};
|
|
357
|
+
var csvRaw = /* @__PURE__ */ join(",", false);
|
|
358
|
+
var emptyFragment = /* @__PURE__ */ fragment([/* @__PURE__ */ literal("")]);
|
|
359
|
+
var makeCompiler = (options) => {
|
|
360
|
+
const self = Object.create(CompilerProto);
|
|
361
|
+
self.options = options;
|
|
362
|
+
self.dialect = options.dialect;
|
|
363
|
+
self.disableTransforms = false;
|
|
364
|
+
self.statementCache = /* @__PURE__ */ new WeakMap();
|
|
365
|
+
self.statementCacheNoTransform = /* @__PURE__ */ new WeakMap();
|
|
366
|
+
return self;
|
|
367
|
+
};
|
|
368
|
+
var CompilerProto = {
|
|
369
|
+
compile(statement2, withoutTransform = false, placeholderOverride) {
|
|
370
|
+
const opts = this.options;
|
|
371
|
+
withoutTransform = withoutTransform || this.disableTransforms;
|
|
372
|
+
const cache = withoutTransform ? this.statementCacheNoTransform : this.statementCache;
|
|
373
|
+
const cached = cache.get(statement2);
|
|
374
|
+
if (cached !== void 0 && placeholderOverride === void 0) {
|
|
375
|
+
return cached;
|
|
376
|
+
}
|
|
377
|
+
const segments = statement2.segments;
|
|
378
|
+
const len = segments.length;
|
|
379
|
+
let sql = "";
|
|
380
|
+
const binds = [];
|
|
381
|
+
let placeholderCount = 0;
|
|
382
|
+
const placeholder = placeholderOverride ?? ((u) => opts.placeholder(++placeholderCount, u));
|
|
383
|
+
const placeholderNoIncrement = (u) => opts.placeholder(placeholderCount, u);
|
|
384
|
+
const placeholders = makePlaceholdersArray(placeholder);
|
|
385
|
+
for (let i = 0; i < len; i++) {
|
|
386
|
+
const segment = segments[i];
|
|
387
|
+
switch (segment._tag) {
|
|
388
|
+
case "Literal": {
|
|
389
|
+
sql += segment.value;
|
|
390
|
+
if (segment.params) {
|
|
391
|
+
binds.push.apply(binds, segment.params);
|
|
392
|
+
}
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
case "Identifier": {
|
|
396
|
+
sql += opts.onIdentifier(segment.value, withoutTransform);
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
case "Parameter": {
|
|
400
|
+
sql += placeholder(segment.value);
|
|
401
|
+
binds.push(segment.value);
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
case "ArrayHelper": {
|
|
405
|
+
sql += `(${placeholders(segment.value)})`;
|
|
406
|
+
binds.push.apply(binds, segment.value);
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
case "RecordInsertHelper": {
|
|
410
|
+
const keys = Object.keys(segment.value[0]);
|
|
411
|
+
if (opts.onInsert) {
|
|
412
|
+
const values = new Array(segment.value.length);
|
|
413
|
+
let placeholders2 = "";
|
|
414
|
+
for (let i2 = 0; i2 < segment.value.length; i2++) {
|
|
415
|
+
const row = new Array(keys.length);
|
|
416
|
+
values[i2] = row;
|
|
417
|
+
placeholders2 += i2 === 0 ? "(" : ",(";
|
|
418
|
+
for (let j = 0; j < keys.length; j++) {
|
|
419
|
+
const key = keys[j];
|
|
420
|
+
const value = segment.value[i2][key];
|
|
421
|
+
const primitive = extractPrimitive(value, opts.onCustom, placeholderNoIncrement, withoutTransform);
|
|
422
|
+
row[j] = primitive;
|
|
423
|
+
placeholders2 += j === 0 ? placeholder(value) : `,${placeholder(value)}`;
|
|
424
|
+
}
|
|
425
|
+
placeholders2 += ")";
|
|
426
|
+
}
|
|
427
|
+
const [s, b] = opts.onInsert(keys.map((_) => opts.onIdentifier(_, withoutTransform)), placeholders2, values, typeof segment.returningIdentifier === "string" ? [segment.returningIdentifier, []] : segment.returningIdentifier ? this.compile(segment.returningIdentifier, withoutTransform, placeholder) : void 0);
|
|
428
|
+
sql += s;
|
|
429
|
+
binds.push.apply(binds, b);
|
|
430
|
+
} else {
|
|
431
|
+
let placeholders2 = "";
|
|
432
|
+
for (let i2 = 0; i2 < segment.value.length; i2++) {
|
|
433
|
+
placeholders2 += i2 === 0 ? "(" : ",(";
|
|
434
|
+
for (let j = 0; j < keys.length; j++) {
|
|
435
|
+
const value = segment.value[i2][keys[j]];
|
|
436
|
+
const primitive = extractPrimitive(value, opts.onCustom, placeholderNoIncrement, withoutTransform);
|
|
437
|
+
binds.push(primitive);
|
|
438
|
+
placeholders2 += j === 0 ? placeholder(value) : `,${placeholder(value)}`;
|
|
439
|
+
}
|
|
440
|
+
placeholders2 += ")";
|
|
441
|
+
}
|
|
442
|
+
sql += `${generateColumns(keys, opts.onIdentifier, withoutTransform)} VALUES ${placeholders2}`;
|
|
443
|
+
if (typeof segment.returningIdentifier === "string") {
|
|
444
|
+
sql += ` RETURNING ${segment.returningIdentifier}`;
|
|
445
|
+
} else if (segment.returningIdentifier) {
|
|
446
|
+
sql += " RETURNING ";
|
|
447
|
+
const [s, b] = this.compile(segment.returningIdentifier, withoutTransform, placeholder);
|
|
448
|
+
sql += s;
|
|
449
|
+
binds.push.apply(binds, b);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
case "RecordUpdateHelperSingle": {
|
|
455
|
+
let keys = Object.keys(segment.value);
|
|
456
|
+
if (segment.omit.length > 0) {
|
|
457
|
+
keys = keys.filter((key) => !segment.omit.includes(key));
|
|
458
|
+
}
|
|
459
|
+
if (opts.onRecordUpdateSingle) {
|
|
460
|
+
const [s, b] = opts.onRecordUpdateSingle(keys.map((_) => opts.onIdentifier(_, withoutTransform)), keys.map((key) => extractPrimitive(segment.value[key], opts.onCustom, placeholderNoIncrement, withoutTransform)), typeof segment.returningIdentifier === "string" ? [segment.returningIdentifier, []] : segment.returningIdentifier ? this.compile(segment.returningIdentifier, withoutTransform, placeholder) : void 0);
|
|
461
|
+
sql += s;
|
|
462
|
+
binds.push.apply(binds, b);
|
|
463
|
+
} else {
|
|
464
|
+
for (let i2 = 0, len2 = keys.length; i2 < len2; i2++) {
|
|
465
|
+
const column = opts.onIdentifier(keys[i2], withoutTransform);
|
|
466
|
+
if (i2 === 0) {
|
|
467
|
+
sql += `${column} = ${placeholder(segment.value[keys[i2]])}`;
|
|
468
|
+
} else {
|
|
469
|
+
sql += `, ${column} = ${placeholder(segment.value[keys[i2]])}`;
|
|
470
|
+
}
|
|
471
|
+
binds.push(extractPrimitive(segment.value[keys[i2]], opts.onCustom, placeholderNoIncrement, withoutTransform));
|
|
472
|
+
}
|
|
473
|
+
if (typeof segment.returningIdentifier === "string") {
|
|
474
|
+
if (this.dialect === "mssql") {
|
|
475
|
+
sql += ` OUTPUT ${segment.returningIdentifier === "*" ? "INSERTED.*" : segment.returningIdentifier}`;
|
|
476
|
+
} else {
|
|
477
|
+
sql += ` RETURNING ${segment.returningIdentifier}`;
|
|
478
|
+
}
|
|
479
|
+
} else if (segment.returningIdentifier) {
|
|
480
|
+
sql += this.dialect === "mssql" ? " OUTPUT " : " RETURNING ";
|
|
481
|
+
const [s, b] = this.compile(segment.returningIdentifier, withoutTransform, placeholder);
|
|
482
|
+
sql += s;
|
|
483
|
+
binds.push.apply(binds, b);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
488
|
+
case "RecordUpdateHelper": {
|
|
489
|
+
const keys = Object.keys(segment.value[0]);
|
|
490
|
+
const values = new Array(segment.value.length);
|
|
491
|
+
let placeholders2 = "";
|
|
492
|
+
for (let i2 = 0; i2 < segment.value.length; i2++) {
|
|
493
|
+
const row = new Array(keys.length);
|
|
494
|
+
values[i2] = row;
|
|
495
|
+
placeholders2 += i2 === 0 ? "(" : ",(";
|
|
496
|
+
for (let j = 0; j < keys.length; j++) {
|
|
497
|
+
const key = keys[j];
|
|
498
|
+
const value = segment.value[i2][key];
|
|
499
|
+
row[j] = extractPrimitive(value, opts.onCustom, placeholderNoIncrement, withoutTransform);
|
|
500
|
+
placeholders2 += j === 0 ? placeholder(value) : `,${placeholder(value)}`;
|
|
501
|
+
}
|
|
502
|
+
placeholders2 += ")";
|
|
503
|
+
}
|
|
504
|
+
const [s, b] = opts.onRecordUpdate(placeholders2, segment.alias, generateColumns(keys, opts.onIdentifier, withoutTransform), values, typeof segment.returningIdentifier === "string" ? [segment.returningIdentifier, []] : segment.returningIdentifier ? this.compile(segment.returningIdentifier, withoutTransform, placeholder) : void 0);
|
|
505
|
+
sql += s;
|
|
506
|
+
binds.push.apply(binds, b);
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
case "Custom": {
|
|
510
|
+
const [s, b] = opts.onCustom(segment, placeholder, withoutTransform);
|
|
511
|
+
sql += s;
|
|
512
|
+
binds.push.apply(binds, b);
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
const result = [sql, binds];
|
|
518
|
+
if (placeholderOverride !== void 0) {
|
|
519
|
+
return result;
|
|
520
|
+
}
|
|
521
|
+
cache.set(statement2, result);
|
|
522
|
+
return result;
|
|
523
|
+
},
|
|
524
|
+
get withoutTransform() {
|
|
525
|
+
const self = Object.create(CompilerProto);
|
|
526
|
+
Object.assign(self, this, {
|
|
527
|
+
disableTransforms: true
|
|
528
|
+
});
|
|
529
|
+
return self;
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
var makeCompilerSqlite = (transform) => makeCompiler({
|
|
533
|
+
dialect: "sqlite",
|
|
534
|
+
placeholder(_) {
|
|
535
|
+
return "?";
|
|
536
|
+
},
|
|
537
|
+
onIdentifier: transform ? function(value, withoutTransform) {
|
|
538
|
+
return withoutTransform ? escapeSqlite(value) : escapeSqlite(transform(value));
|
|
539
|
+
} : escapeSqlite,
|
|
540
|
+
onRecordUpdate() {
|
|
541
|
+
return ["", []];
|
|
542
|
+
},
|
|
543
|
+
onCustom() {
|
|
544
|
+
return ["", []];
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
function defaultEscape(c) {
|
|
548
|
+
const re = new RegExp(c, "g");
|
|
549
|
+
const double = c + c;
|
|
550
|
+
const dot = c + "." + c;
|
|
551
|
+
return function(str) {
|
|
552
|
+
return c + str.replace(re, double).replace(/\./g, dot) + c;
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
var defaultTransforms = (transformer, nested = true) => {
|
|
556
|
+
const transformValue = (value) => {
|
|
557
|
+
if (Array.isArray(value)) {
|
|
558
|
+
if (value.length === 0 || value[0].constructor !== Object) {
|
|
559
|
+
return value;
|
|
560
|
+
}
|
|
561
|
+
return array(value);
|
|
562
|
+
} else if (value?.constructor === Object) {
|
|
563
|
+
return transformObject(value);
|
|
564
|
+
}
|
|
565
|
+
return value;
|
|
566
|
+
};
|
|
567
|
+
const transformObject = (obj) => {
|
|
568
|
+
const newObj = {};
|
|
569
|
+
for (const key of Object.keys(obj)) {
|
|
570
|
+
assignProperty(newObj, transformer(key), transformValue(obj[key]));
|
|
571
|
+
}
|
|
572
|
+
return newObj;
|
|
573
|
+
};
|
|
574
|
+
const transformArrayNested = (rows) => {
|
|
575
|
+
const newRows = new Array(rows.length);
|
|
576
|
+
for (let i = 0, len = rows.length; i < len; i++) {
|
|
577
|
+
const row = rows[i];
|
|
578
|
+
if (Array.isArray(row)) {
|
|
579
|
+
newRows[i] = transformArrayNested(row);
|
|
580
|
+
} else {
|
|
581
|
+
const obj = {};
|
|
582
|
+
for (const [key, value] of Object.entries(row)) {
|
|
583
|
+
assignProperty(obj, transformer(key), transformValue(value));
|
|
584
|
+
}
|
|
585
|
+
newRows[i] = obj;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
return newRows;
|
|
589
|
+
};
|
|
590
|
+
const transformArray = (rows) => {
|
|
591
|
+
const newRows = new Array(rows.length);
|
|
592
|
+
for (let i = 0, len = rows.length; i < len; i++) {
|
|
593
|
+
const row = rows[i];
|
|
594
|
+
if (Array.isArray(row)) {
|
|
595
|
+
newRows[i] = transformArray(row);
|
|
596
|
+
} else {
|
|
597
|
+
const obj = {};
|
|
598
|
+
for (const [key, value] of Object.entries(row)) {
|
|
599
|
+
assignProperty(obj, transformer(key), value);
|
|
600
|
+
}
|
|
601
|
+
newRows[i] = obj;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return newRows;
|
|
605
|
+
};
|
|
606
|
+
const array = nested ? transformArrayNested : transformArray;
|
|
607
|
+
return {
|
|
608
|
+
value: transformValue,
|
|
609
|
+
object: transformObject,
|
|
610
|
+
array
|
|
611
|
+
};
|
|
612
|
+
};
|
|
613
|
+
var ATTR_DB_OPERATION_NAME = "db.operation.name";
|
|
614
|
+
var ATTR_DB_QUERY_TEXT = "db.query.text";
|
|
615
|
+
var makeUnsafe2 = (segments, acquirer, compiler, spanAttributes, transformRows, borrower) => {
|
|
616
|
+
const self = Object.create(StatementProto);
|
|
617
|
+
self.segments = segments;
|
|
618
|
+
self.acquirer = acquirer;
|
|
619
|
+
self.compiler = compiler;
|
|
620
|
+
self.spanAttributes = spanAttributes;
|
|
621
|
+
self.transformRows = transformRows;
|
|
622
|
+
self.borrower = borrower;
|
|
623
|
+
return self;
|
|
624
|
+
};
|
|
625
|
+
var StatementProto = {
|
|
626
|
+
[FragmentTypeId]: FragmentTypeId,
|
|
627
|
+
withConnection(operation, f, withoutTransform = false) {
|
|
628
|
+
return useSpan("sql.execute", {
|
|
629
|
+
kind: "client"
|
|
630
|
+
}, (span) => this.withConnectionSpan(operation, f, withoutTransform, span));
|
|
631
|
+
},
|
|
632
|
+
withConnectionSpan(operation, f, withoutTransform, span) {
|
|
633
|
+
return withStatement(this, span, (statement2, fiber) => {
|
|
634
|
+
const [sql, params] = statement2.compile(withoutTransform);
|
|
635
|
+
for (const [key, value] of this.spanAttributes) {
|
|
636
|
+
span.attribute(key, value);
|
|
637
|
+
}
|
|
638
|
+
span.attribute(ATTR_DB_OPERATION_NAME, operation);
|
|
639
|
+
span.attribute(ATTR_DB_QUERY_TEXT, sql);
|
|
640
|
+
const execute = this.borrower === void 0 ? scoped(flatMap(this.acquirer, (_) => f(_, sql, params))) : this.borrower((connection) => f(connection, sql, params));
|
|
641
|
+
return fiber.cache.tracerEnabled && fiber.getRef(SpanPropagationEnabled) ? provideService(execute, ParentSpan, span) : execute;
|
|
642
|
+
});
|
|
643
|
+
},
|
|
644
|
+
get withoutTransform() {
|
|
645
|
+
return this.withConnection("executeWithoutTransform", (connection, sql, params) => connection.execute(sql, params, void 0), true);
|
|
646
|
+
},
|
|
647
|
+
get raw() {
|
|
648
|
+
return this.withConnection("executeRaw", (connection, sql, params) => connection.executeRaw(sql, params), true);
|
|
649
|
+
},
|
|
650
|
+
get stream() {
|
|
651
|
+
const self = this;
|
|
652
|
+
return unwrap(flatMap(makeSpanScoped("sql.execute", {
|
|
653
|
+
kind: "client"
|
|
654
|
+
}), (span) => withStatement(self, span, (statement2, fiber) => {
|
|
655
|
+
const [sql, params] = statement2.compile();
|
|
656
|
+
for (const [key, value] of self.spanAttributes) {
|
|
657
|
+
span.attribute(key, value);
|
|
658
|
+
}
|
|
659
|
+
span.attribute(ATTR_DB_OPERATION_NAME, "executeStream");
|
|
660
|
+
span.attribute(ATTR_DB_QUERY_TEXT, sql);
|
|
661
|
+
const acquire = map(self.acquirer, (_) => _.executeStream(sql, params, self.transformRows));
|
|
662
|
+
return fiber.cache.tracerEnabled && fiber.getRef(SpanPropagationEnabled) ? succeed(provideService2(unwrap(acquire), ParentSpan, span)) : acquire;
|
|
663
|
+
})));
|
|
664
|
+
},
|
|
665
|
+
get values() {
|
|
666
|
+
return this.withConnection("executeValues", (connection, sql, params) => connection.executeValues(sql, params));
|
|
667
|
+
},
|
|
668
|
+
get valuesUnprepared() {
|
|
669
|
+
return this.withConnection("executeValuesUnprepared", (connection, sql, params) => connection.executeValuesUnprepared(sql, params));
|
|
670
|
+
},
|
|
671
|
+
get unprepared() {
|
|
672
|
+
const self = this;
|
|
673
|
+
return self.withConnection("executeUnprepared", (connection, sql, params) => connection.executeUnprepared(sql, params, self.transformRows));
|
|
674
|
+
},
|
|
675
|
+
.../* @__PURE__ */ Prototype({
|
|
676
|
+
label: "Statement",
|
|
677
|
+
evaluate(fiber) {
|
|
678
|
+
const span = makeSpanUnsafe(fiber, "sql.execute", {
|
|
679
|
+
kind: "client"
|
|
680
|
+
});
|
|
681
|
+
const clock = fiber.getRef(Clock);
|
|
682
|
+
const timingEnabled = fiber.getRef(TracerTimingEnabled);
|
|
683
|
+
return onExit(this.withConnectionSpan("execute", (connection, sql, params) => connection.execute(sql, params, this.transformRows), false, span), (exit) => endSpan(span, exit, clock, timingEnabled));
|
|
684
|
+
}
|
|
685
|
+
}),
|
|
686
|
+
compile(withoutTransform) {
|
|
687
|
+
return this.compiler.compile(this, withoutTransform ?? false);
|
|
688
|
+
},
|
|
689
|
+
toJSON() {
|
|
690
|
+
const [sql, params] = this.compile();
|
|
691
|
+
return {
|
|
692
|
+
_id: "Statement",
|
|
693
|
+
segments: this.segments,
|
|
694
|
+
sql,
|
|
695
|
+
params
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
var withStatement = (self, span, f) => withFiber((fiber) => {
|
|
700
|
+
const transform = fiber.getRef(CurrentTransformer);
|
|
701
|
+
if (transform === void 0) {
|
|
702
|
+
return f(self, fiber);
|
|
703
|
+
}
|
|
704
|
+
return flatMap(transform(self, make4(self.acquirer, self.compiler, self.spanAttributes, self.transformRows, self.borrower), fiber, span), (statement2) => f(statement2, fiber));
|
|
705
|
+
});
|
|
706
|
+
var isSegment = (u) => {
|
|
707
|
+
if (!hasProperty(u, "_tag")) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
switch (u._tag) {
|
|
711
|
+
case "Literal":
|
|
712
|
+
case "Parameter":
|
|
713
|
+
case "ArrayHelper":
|
|
714
|
+
case "RecordInsertHelper":
|
|
715
|
+
case "RecordUpdateHelper":
|
|
716
|
+
case "RecordUpdateHelperSingle":
|
|
717
|
+
case "Identifier":
|
|
718
|
+
case "Custom":
|
|
719
|
+
return true;
|
|
720
|
+
default:
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
function convertLiteralOrFragment(clause) {
|
|
725
|
+
if (typeof clause === "string") {
|
|
726
|
+
return [literal(clause)];
|
|
727
|
+
}
|
|
728
|
+
return clause.segments;
|
|
729
|
+
}
|
|
730
|
+
var makePlaceholdersArray = (evaluate) => (values) => {
|
|
731
|
+
if (values.length === 0) {
|
|
732
|
+
return "";
|
|
733
|
+
}
|
|
734
|
+
let result = evaluate(values[0]);
|
|
735
|
+
for (let i = 1; i < values.length; i++) {
|
|
736
|
+
result += `,${evaluate(values[i])}`;
|
|
737
|
+
}
|
|
738
|
+
return result;
|
|
739
|
+
};
|
|
740
|
+
var generateColumns = (keys, escape, withoutTransform) => {
|
|
741
|
+
if (keys.length === 0) {
|
|
742
|
+
return "()";
|
|
743
|
+
}
|
|
744
|
+
let str = `(${escape(keys[0], withoutTransform)}`;
|
|
745
|
+
for (let i = 1; i < keys.length; i++) {
|
|
746
|
+
str += `,${escape(keys[i], withoutTransform)}`;
|
|
747
|
+
}
|
|
748
|
+
return str + ")";
|
|
749
|
+
};
|
|
750
|
+
var extractPrimitive = (value, onCustom, placeholder, withoutTransform) => {
|
|
751
|
+
if (value === void 0) {
|
|
752
|
+
return null;
|
|
753
|
+
} else if (isFragment(value)) {
|
|
754
|
+
const head = value.segments[0];
|
|
755
|
+
if (head._tag === "Custom") {
|
|
756
|
+
const compiled = onCustom(head, placeholder, withoutTransform);
|
|
757
|
+
return compiled[1][0] ?? null;
|
|
758
|
+
} else if (head._tag === "Parameter") {
|
|
759
|
+
return head.value;
|
|
760
|
+
}
|
|
761
|
+
return null;
|
|
762
|
+
}
|
|
763
|
+
return value;
|
|
764
|
+
};
|
|
765
|
+
var escapeSqlite = /* @__PURE__ */ defaultEscape('"');
|
|
766
|
+
function in_() {
|
|
767
|
+
if (arguments.length === 1) {
|
|
768
|
+
return arrayHelper(arguments[0]);
|
|
769
|
+
}
|
|
770
|
+
const column = arguments[0];
|
|
771
|
+
const values = arguments[1];
|
|
772
|
+
return values.length === 0 ? neverFragment : fragment([identifier(column), literal(" IN "), arrayHelper(values)]);
|
|
773
|
+
}
|
|
774
|
+
var neverFragment = /* @__PURE__ */ fragment([/* @__PURE__ */ literal("1=0")]);
|
|
775
|
+
|
|
776
|
+
// ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b0796b742bddeb797269d/node_modules/effect/dist/unstable/sql/SqlClient.js
|
|
777
|
+
var TypeId2 = "~effect/sql/SqlClient";
|
|
778
|
+
var SqlClient = /* @__PURE__ */ Service("effect/sql/SqlClient");
|
|
779
|
+
var clientIdCounter = 0;
|
|
780
|
+
var transactionSemaphoreIdCounter = 0;
|
|
781
|
+
var make5 = /* @__PURE__ */ fnUntraced(function* (options) {
|
|
782
|
+
const transactionService = options.transactionService ?? TransactionConnection(clientIdCounter++);
|
|
783
|
+
const getConnection = flatMap(serviceOption(transactionService), match({
|
|
784
|
+
onNone: () => options.acquirer,
|
|
785
|
+
onSome: ([conn]) => succeed(conn)
|
|
786
|
+
}));
|
|
787
|
+
const beginTransaction = options.beginTransaction ?? "BEGIN";
|
|
788
|
+
const commit = options.commit ?? "COMMIT";
|
|
789
|
+
const savepoint = options.savepoint ?? ((name) => `SAVEPOINT ${name}`);
|
|
790
|
+
const rollback = options.rollback ?? "ROLLBACK";
|
|
791
|
+
const rollbackSavepoint = options.rollbackSavepoint ?? ((name) => `ROLLBACK TO SAVEPOINT ${name}`);
|
|
792
|
+
const transactionAcquirer = options.transactionAcquirer ?? options.acquirer;
|
|
793
|
+
const control = options.prepareTransactionControls === true ? (conn, sql) => conn.execute(sql, [], void 0) : (conn, sql) => conn.executeUnprepared(sql, [], void 0);
|
|
794
|
+
const withTransaction = makeWithTransaction({
|
|
795
|
+
transactionService,
|
|
796
|
+
spanAttributes: options.spanAttributes,
|
|
797
|
+
acquireConnection: flatMap(make(), (scope) => map(provide(transactionAcquirer, scope), (conn) => [scope, conn])),
|
|
798
|
+
begin: (conn) => control(conn, beginTransaction),
|
|
799
|
+
savepoint: (conn, id) => control(conn, savepoint(`effect_sql_${id}`)),
|
|
800
|
+
commit: (conn) => control(conn, commit),
|
|
801
|
+
rollback: (conn) => control(conn, rollback),
|
|
802
|
+
rollbackSavepoint: (conn, id) => control(conn, rollbackSavepoint(`effect_sql_${id}`))
|
|
803
|
+
});
|
|
804
|
+
const reactivity = yield* Reactivity;
|
|
805
|
+
const borrower = options.borrower === void 0 ? void 0 : (f) => flatMap(serviceOption(transactionService), match({
|
|
806
|
+
onNone: () => options.borrower(f),
|
|
807
|
+
onSome: ([conn]) => f(conn)
|
|
808
|
+
}));
|
|
809
|
+
const client = Object.assign(make4(getConnection, options.compiler, options.spanAttributes, options.transformRows, borrower), {
|
|
810
|
+
[TypeId2]: TypeId2,
|
|
811
|
+
safe: void 0,
|
|
812
|
+
withTransaction,
|
|
813
|
+
transactionService,
|
|
814
|
+
reserve: transactionAcquirer,
|
|
815
|
+
withoutTransforms() {
|
|
816
|
+
if (options.transformRows === void 0) {
|
|
817
|
+
return this;
|
|
818
|
+
}
|
|
819
|
+
const statement2 = make4(getConnection, options.compiler.withoutTransform, options.spanAttributes, void 0, borrower);
|
|
820
|
+
const client2 = Object.assign(statement2, {
|
|
821
|
+
...this,
|
|
822
|
+
...statement2
|
|
823
|
+
});
|
|
824
|
+
client2.safe = client2;
|
|
825
|
+
client2.withoutTransforms = () => client2;
|
|
826
|
+
return client2;
|
|
827
|
+
},
|
|
828
|
+
reactive: options.reactiveQueue ? (keys, effect2) => options.reactiveQueue(keys, effect2).pipe(map(fromQueue), unwrap) : reactivity.stream,
|
|
829
|
+
reactiveMailbox: options.reactiveQueue ?? reactivity.query
|
|
830
|
+
});
|
|
831
|
+
client.safe = client;
|
|
832
|
+
return client;
|
|
833
|
+
});
|
|
834
|
+
var makeWithTransaction = (options) => {
|
|
835
|
+
const transactionSemaphore = Service(`effect/sql/SqlClient/TransactionSemaphore/${transactionSemaphoreIdCounter++}`);
|
|
836
|
+
return (effect2) => uninterruptibleMask((restore) => useSpan("sql.transaction", {
|
|
837
|
+
kind: "client"
|
|
838
|
+
}, (span) => withFiber((fiber) => {
|
|
839
|
+
for (const [key, value] of options.spanAttributes) {
|
|
840
|
+
span.attribute(key, value);
|
|
841
|
+
}
|
|
842
|
+
const services = fiber.context;
|
|
843
|
+
const clock = fiber.getRef(Clock);
|
|
844
|
+
const connOption = getOption(services, options.transactionService);
|
|
845
|
+
const conn = connOption._tag === "Some" ? succeed([void 0, connOption.value[0]]) : options.acquireConnection;
|
|
846
|
+
const id = connOption._tag === "Some" ? connOption.value[1] + 1 : 0;
|
|
847
|
+
const transaction = flatMap(conn, ([scope, conn2]) => (id === 0 ? options.begin(conn2) : options.savepoint(conn2, id)).pipe(flatMap(() => onExitPrimitive(provideContext(restore(effect2), services.pipe(add(options.transactionService, [conn2, id]), add(transactionSemaphore, makeUnsafe(1)), add(ParentSpan, span))), (exit) => {
|
|
848
|
+
let effect3;
|
|
849
|
+
if (isSuccess(exit)) {
|
|
850
|
+
if (id === 0) {
|
|
851
|
+
span.event("db.transaction.commit", clock.currentTimeNanosUnsafe());
|
|
852
|
+
effect3 = orDie(options.commit(conn2));
|
|
853
|
+
} else {
|
|
854
|
+
span.event("db.transaction.savepoint", clock.currentTimeNanosUnsafe());
|
|
855
|
+
effect3 = void_;
|
|
856
|
+
}
|
|
857
|
+
} else {
|
|
858
|
+
span.event("db.transaction.rollback", clock.currentTimeNanosUnsafe());
|
|
859
|
+
effect3 = orDie(id > 0 ? options.rollbackSavepoint(conn2, id) : options.rollback(conn2));
|
|
860
|
+
}
|
|
861
|
+
return flatMap(effect3, () => exit);
|
|
862
|
+
}, true)), scope ? (eff) => onExitPrimitive(eff, (exit) => close(scope, exit), true) : identity));
|
|
863
|
+
return id === 0 ? transaction : getUnsafe(services, transactionSemaphore).withPermit(transaction);
|
|
864
|
+
})));
|
|
865
|
+
};
|
|
866
|
+
var TransactionConnection = (clientId) => Service(`effect/sql/SqlClient/TransactionConnection/${clientId}`);
|
|
867
|
+
|
|
868
|
+
export {
|
|
869
|
+
Reactivity,
|
|
870
|
+
mutation,
|
|
871
|
+
invalidate,
|
|
872
|
+
layer,
|
|
873
|
+
makeCompilerSqlite,
|
|
874
|
+
defaultTransforms,
|
|
875
|
+
SqlClient,
|
|
876
|
+
make5 as make
|
|
877
|
+
};
|