ezlogs-nextjs 0.4.3 → 0.4.6
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 +217 -86
- package/THIRD_PARTY_LICENSES.md +27 -0
- package/dist/actors/index.d.cts +1 -1
- package/dist/actors/index.d.ts +1 -1
- package/dist/{chunk-Z2TM3LGG.js → chunk-2NFJOT6Q.js} +1 -1
- package/dist/{chunk-R6IWVTX3.cjs → chunk-65HRY3PW.cjs} +31 -21
- package/dist/{chunk-YXZZNZG6.cjs → chunk-B3WST6ES.cjs} +9 -9
- package/dist/{chunk-MMLQXSSD.cjs → chunk-B5ZUQULZ.cjs} +18 -11
- package/dist/{chunk-NX4EL7BY.cjs → chunk-DM2EAOSF.cjs} +4 -4
- package/dist/chunk-DRE2VXFX.js +19 -0
- package/dist/chunk-H3FC5HMW.cjs +16 -0
- package/dist/{chunk-GI6BM4MR.js → chunk-IBSNHBUC.js} +18 -12
- package/dist/chunk-JWJKFZBW.js +52 -0
- package/dist/{chunk-MHBS5FEP.js → chunk-M3VBQ5KT.js} +27 -4
- package/dist/chunk-NFZ5OKF3.cjs +22 -0
- package/dist/{chunk-GMHOUAKD.cjs → chunk-O7SFYXJC.cjs} +37 -13
- package/dist/{chunk-U22T7QYY.js → chunk-PK2Z2ABL.js} +13 -3
- package/dist/{chunk-YMIGZYFH.js → chunk-RD47JECJ.js} +1 -1
- package/dist/chunk-RMKGMIV2.js +13 -0
- package/dist/{chunk-NINIAL7M.js → chunk-U3IJV5EJ.js} +1 -1
- package/dist/chunk-VJR4VB4B.cjs +56 -0
- package/dist/{chunk-PS4U2GFJ.cjs → chunk-YO6E763S.cjs} +5 -5
- package/dist/{configuration-CJ5yKVlP.d.cts → configuration-b9pImwFB.d.cts} +2 -2
- package/dist/{configuration-CJ5yKVlP.d.ts → configuration-b9pImwFB.d.ts} +2 -2
- package/dist/db/drizzle.cjs +3 -3
- package/dist/db/drizzle.js +2 -2
- package/dist/db/postgres-js.cjs +4 -4
- package/dist/db/postgres-js.js +2 -2
- package/dist/db/prisma.cjs +12 -12
- package/dist/db/prisma.js +2 -2
- package/dist/db/supabase.cjs +42 -17
- package/dist/db/supabase.d.cts +11 -5
- package/dist/db/supabase.d.ts +11 -5
- package/dist/db/supabase.js +33 -9
- package/dist/index.cjs +288 -142
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +198 -52
- package/dist/jobs/bullmq.cjs +44 -16
- package/dist/jobs/bullmq.d.cts +7 -1
- package/dist/jobs/bullmq.d.ts +7 -1
- package/dist/jobs/bullmq.js +33 -6
- package/dist/jobs/inngest.cjs +36 -17
- package/dist/jobs/inngest.d.cts +7 -1
- package/dist/jobs/inngest.d.ts +7 -1
- package/dist/jobs/inngest.js +23 -5
- package/dist/jobs/supabase-queues.cjs +9 -9
- package/dist/jobs/supabase-queues.js +4 -4
- package/dist/jobs/trigger.cjs +7 -7
- package/dist/jobs/trigger.js +4 -4
- package/dist/jobs/upstash-workflow.cjs +139 -23
- package/dist/jobs/upstash-workflow.d.cts +20 -2
- package/dist/jobs/upstash-workflow.d.ts +20 -2
- package/dist/jobs/upstash-workflow.js +129 -14
- package/dist/nextjs-plugin/index.cjs +46 -29
- package/dist/nextjs-plugin/index.js +46 -29
- package/dist/nextjs-plugin/loader.cjs +70 -60
- package/dist/nextjs-plugin/loader.d.cts +18 -1
- package/dist/nextjs-plugin/loader.d.ts +18 -1
- package/dist/nextjs-plugin/loader.js +70 -61
- package/dist/triggers/index.cjs +22 -16
- package/dist/triggers/index.d.cts +0 -10
- package/dist/triggers/index.d.ts +0 -10
- package/dist/triggers/index.js +11 -5
- package/package.json +6 -5
- package/sql/postgres/00_install.sql +20 -3
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import
|
|
1
|
+
import { markJobDelivery } from '../chunk-RMKGMIV2.js';
|
|
2
|
+
import { instrumentFrom, instrumentClass } from '../chunk-JWJKFZBW.js';
|
|
3
|
+
import { actorToken, readActorToken, runJobWithCapture, toHex, emitJobEvent } from '../chunk-PK2Z2ABL.js';
|
|
4
|
+
import '../chunk-M3VBQ5KT.js';
|
|
5
|
+
import '../chunk-U3IJV5EJ.js';
|
|
6
|
+
import { createScopedStorage, current, maybeExtractSupabaseActor } from '../chunk-IBSNHBUC.js';
|
|
5
7
|
import { logger } from '../chunk-FCFVIRQF.js';
|
|
6
8
|
import '../chunk-SIAA4J6H.js';
|
|
7
9
|
|
|
@@ -85,27 +87,134 @@ async function stampPublishRequest(request) {
|
|
|
85
87
|
if (token) headers[`${FORWARD_PREFIX}${ACTOR_HEADER}`] = token;
|
|
86
88
|
return { ...request, headers };
|
|
87
89
|
}
|
|
90
|
+
var warnedNoHeaders = false;
|
|
88
91
|
async function captureWorkflowRequest(meta, work) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
if (meta.context?.disabled === true) return work();
|
|
93
|
+
markJobDelivery();
|
|
94
|
+
if (insideStepCapture.read()) return work();
|
|
95
|
+
const headers = meta.request?.headers ?? meta.context?.headers;
|
|
96
|
+
if (!headers) {
|
|
97
|
+
if (!warnedNoHeaders) {
|
|
98
|
+
warnedNoHeaders = true;
|
|
99
|
+
logger.warn(
|
|
100
|
+
"captureWorkflowRequest got no headers (pass { context, workflowName }); this step runs without capture"
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return work();
|
|
104
|
+
}
|
|
105
|
+
const runId = readHeader(headers, "upstash-workflow-runid") ?? meta.context?.workflowRunId ?? null;
|
|
106
|
+
const correlationId = readCorrelationFromHeaders(headers) ?? correlationFromRunId(runId);
|
|
92
107
|
const retried = parseRetried(readHeader(headers, "upstash-retried"));
|
|
93
108
|
const actor = correlationId ? await readActorToken(
|
|
94
109
|
readHeader(headers, ACTOR_HEADER) ?? readHeader(headers, `${FORWARD_PREFIX}${ACTOR_HEADER}`),
|
|
95
110
|
correlationId
|
|
96
111
|
) ?? await readActorToken(runId ? AGENT_RUN_ID.exec(runId)?.[2] : null, correlationId) : null;
|
|
97
|
-
return runJobWithCapture(
|
|
112
|
+
return insideStepCapture.run(true, () => runJobWithCapture(
|
|
98
113
|
{
|
|
99
114
|
jobClass: meta.workflowName,
|
|
100
115
|
jobId: runId,
|
|
101
116
|
queue: meta.stepName ?? meta.workflowName,
|
|
117
|
+
step: () => meta.ranStep?.() ?? meta.stepName ?? null,
|
|
102
118
|
retryCount: retried,
|
|
103
119
|
correlationId,
|
|
104
|
-
actor
|
|
120
|
+
actor,
|
|
121
|
+
// The SDK ends each delivery by throwing: WorkflowAbort after a
|
|
122
|
+
// step ran (and WorkflowCancelAbort on context.cancel()) is a
|
|
123
|
+
// finished step, WorkflowAuthError is its signature probe that
|
|
124
|
+
// runs no step. Only other errors are failures.
|
|
125
|
+
isControlFlow: (error) => errorName(error) === "WorkflowAuthError",
|
|
126
|
+
isSuccessfulExit: (error) => SUCCESSFUL_EXITS.has(errorName(error))
|
|
105
127
|
},
|
|
106
128
|
work
|
|
107
|
-
);
|
|
129
|
+
));
|
|
130
|
+
}
|
|
131
|
+
var insideStepCapture = createScopedStorage(/* @__PURE__ */ Symbol.for("ezlogs-nextjs:upstash-step-capture"));
|
|
132
|
+
function workflowNameOf(context) {
|
|
133
|
+
try {
|
|
134
|
+
if (typeof context.url === "string") return new URL(context.url).pathname;
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
return "upstash-workflow";
|
|
108
138
|
}
|
|
139
|
+
function captureRouteFunction(routeFunction) {
|
|
140
|
+
if (typeof routeFunction !== "function") return routeFunction;
|
|
141
|
+
const run = routeFunction;
|
|
142
|
+
return function ezlogsWorkflowStep(context, ...rest) {
|
|
143
|
+
if (!context || typeof context !== "object" || !context.headers) return run.call(this, context, ...rest);
|
|
144
|
+
const ran = {};
|
|
145
|
+
const watched = watchRunSteps(context, ran);
|
|
146
|
+
return captureWorkflowRequest(
|
|
147
|
+
{ context, workflowName: workflowNameOf(context), ranStep: () => ran.step },
|
|
148
|
+
() => run.call(this, watched, ...rest)
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function watchRunSteps(context, ran) {
|
|
153
|
+
if (typeof context.run !== "function") return context;
|
|
154
|
+
try {
|
|
155
|
+
return new Proxy(context, {
|
|
156
|
+
get(target, key) {
|
|
157
|
+
const value = Reflect.get(target, key, target);
|
|
158
|
+
if (typeof value !== "function") return value;
|
|
159
|
+
if (key !== "run") return value.bind(target);
|
|
160
|
+
const run = value;
|
|
161
|
+
return (name, fn, ...rest) => {
|
|
162
|
+
if (typeof fn !== "function") return run.call(target, name, fn, ...rest);
|
|
163
|
+
const step = fn;
|
|
164
|
+
return run.call(target, name, (...args) => {
|
|
165
|
+
if (typeof name === "string" && ran.step === void 0) ran.step = name;
|
|
166
|
+
return step(...args);
|
|
167
|
+
}, ...rest);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
} catch {
|
|
172
|
+
return context;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function instrumentServe(original) {
|
|
176
|
+
if (typeof original !== "function") return original;
|
|
177
|
+
const serve = original;
|
|
178
|
+
return function ezlogsServe(routeFunction, ...rest) {
|
|
179
|
+
const served = serve.call(this, captureRouteFunction(routeFunction), ...rest);
|
|
180
|
+
if (!served || typeof served !== "object") return served;
|
|
181
|
+
const handlers = { ...served };
|
|
182
|
+
for (const [name, handler] of Object.entries(handlers)) {
|
|
183
|
+
if (typeof handler !== "function") continue;
|
|
184
|
+
const deliver = handler;
|
|
185
|
+
handlers[name] = function ezlogsDelivery(...args) {
|
|
186
|
+
if (signedByQStash(args[0])) markJobDelivery();
|
|
187
|
+
return deliver.apply(this, args);
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return handlers;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function signedByQStash(request) {
|
|
194
|
+
const headers = request?.headers;
|
|
195
|
+
if (!headers || typeof headers !== "object") return false;
|
|
196
|
+
if (typeof headers.get === "function") return Boolean(headers.get("upstash-signature"));
|
|
197
|
+
return Boolean(headers["upstash-signature"]);
|
|
198
|
+
}
|
|
199
|
+
function instrumentCreateWorkflow(original) {
|
|
200
|
+
if (typeof original !== "function") return original;
|
|
201
|
+
const create = original;
|
|
202
|
+
return function ezlogsCreateWorkflow(routeFunction, ...rest) {
|
|
203
|
+
return create.call(this, captureRouteFunction(routeFunction), ...rest);
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
var __ezlogsInstrument = instrumentFrom({
|
|
207
|
+
"@upstash/workflow/nextjs#serve": instrumentServe,
|
|
208
|
+
"@upstash/workflow/nextjs#servePagesRouter": instrumentServe,
|
|
209
|
+
"@upstash/workflow/nextjs#createWorkflow": instrumentCreateWorkflow,
|
|
210
|
+
"@upstash/workflow/nextjs#createWorkflowPagesRouter": instrumentCreateWorkflow,
|
|
211
|
+
// Its workflows come from createWorkflow (captured there); only the handlers are marked.
|
|
212
|
+
"@upstash/workflow/nextjs#serveMany": instrumentServe,
|
|
213
|
+
"@upstash/workflow/nextjs#serveManyPagesRouter": instrumentServe,
|
|
214
|
+
"@upstash/workflow#serve": instrumentServe,
|
|
215
|
+
"@upstash/workflow#Client": (original) => instrumentClass(original, (client) => wrapWorkflowClient(client)),
|
|
216
|
+
"@upstash/qstash#Client": (original) => instrumentClass(original, (client) => wrapQStashClient(client))
|
|
217
|
+
});
|
|
109
218
|
function emitUpstashWorkflowEvent(input) {
|
|
110
219
|
try {
|
|
111
220
|
const headers = input.request.headers;
|
|
@@ -137,14 +246,20 @@ function readHeader(headers, name) {
|
|
|
137
246
|
return null;
|
|
138
247
|
}
|
|
139
248
|
}
|
|
249
|
+
var SUCCESSFUL_EXITS = /* @__PURE__ */ new Set(["WorkflowAbort", "WorkflowCancelAbort"]);
|
|
250
|
+
function errorName(error) {
|
|
251
|
+
return error !== null && typeof error === "object" ? String(error.name ?? "") : "";
|
|
252
|
+
}
|
|
253
|
+
function correlationFromRunId(runId) {
|
|
254
|
+
const fromRunId = runId ? AGENT_RUN_ID.exec(runId)?.[1] : void 0;
|
|
255
|
+
return fromRunId && isAcceptableStepId(fromRunId) ? fromRunId : null;
|
|
256
|
+
}
|
|
140
257
|
function readCorrelationFromHeaders(headers) {
|
|
141
258
|
for (const name of [CORRELATION_HEADER, LEGACY_CORRELATION_HEADER]) {
|
|
142
259
|
const value = readHeader(headers, name) ?? readHeader(headers, `${FORWARD_PREFIX}${name}`);
|
|
143
260
|
if (value && isAcceptableStepId(value)) return value;
|
|
144
261
|
}
|
|
145
|
-
|
|
146
|
-
const fromRunId = runId ? AGENT_RUN_ID.exec(runId)?.[1] : void 0;
|
|
147
|
-
return fromRunId && isAcceptableStepId(fromRunId) ? fromRunId : null;
|
|
262
|
+
return correlationFromRunId(readHeader(headers, "upstash-workflow-runid"));
|
|
148
263
|
}
|
|
149
264
|
function parseRetried(value) {
|
|
150
265
|
if (value === null) return null;
|
|
@@ -157,4 +272,4 @@ function describeError(error) {
|
|
|
157
272
|
return String(error);
|
|
158
273
|
}
|
|
159
274
|
|
|
160
|
-
export { captureWorkflowRequest, emitUpstashWorkflowEvent, wrapQStashClient, wrapWorkflowClient };
|
|
275
|
+
export { __ezlogsInstrument, captureWorkflowRequest, emitUpstashWorkflowEvent, wrapQStashClient, wrapWorkflowClient };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkNFZ5OKF3_cjs = require('../chunk-NFZ5OKF3.cjs');
|
|
3
4
|
require('../chunk-ZDSQYCYV.cjs');
|
|
4
5
|
var path = require('path');
|
|
5
6
|
var fs = require('fs');
|
|
@@ -78,7 +79,7 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
78
79
|
loaders: [
|
|
79
80
|
{
|
|
80
81
|
loader: loaderPath,
|
|
81
|
-
options: { kind: "middleware" }
|
|
82
|
+
options: { kind: "middleware", projectDir }
|
|
82
83
|
}
|
|
83
84
|
],
|
|
84
85
|
as: `*.${ext}`
|
|
@@ -88,7 +89,7 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
88
89
|
loaders: [
|
|
89
90
|
{
|
|
90
91
|
loader: loaderPath,
|
|
91
|
-
options: { kind: "middleware" }
|
|
92
|
+
options: { kind: "middleware", projectDir }
|
|
92
93
|
}
|
|
93
94
|
],
|
|
94
95
|
as: `*.${ext}`
|
|
@@ -121,21 +122,6 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
121
122
|
as: `*.${ext}`
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
|
-
const supabaseGlobs = [
|
|
125
|
-
`**/{lib,src/lib,utils,src/utils}/supabase/**/*.${ext}`
|
|
126
|
-
];
|
|
127
|
-
for (const glob of supabaseGlobs) {
|
|
128
|
-
ezlogsRules[glob] = {
|
|
129
|
-
condition: { not: "browser" },
|
|
130
|
-
loaders: [
|
|
131
|
-
{
|
|
132
|
-
loader: loaderPath,
|
|
133
|
-
options: { kind: "supabase-factory" }
|
|
134
|
-
}
|
|
135
|
-
],
|
|
136
|
-
as: `*.${ext}`
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
125
|
for (const inlineFilename of INLINE_ROUTE_FILENAMES) {
|
|
140
126
|
ezlogsRules[`**/{app,src/app}/**/${inlineFilename}.${ext}`] = {
|
|
141
127
|
condition: {
|
|
@@ -149,6 +135,22 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
149
135
|
]
|
|
150
136
|
};
|
|
151
137
|
}
|
|
138
|
+
ezlogsRules[`**/*.${ext}`] = {
|
|
139
|
+
condition: {
|
|
140
|
+
all: [
|
|
141
|
+
{ not: "browser" },
|
|
142
|
+
{ content: chunkNFZ5OKF3_cjs.INSTRUMENTED_IMPORT_CONTENT },
|
|
143
|
+
{ not: { path: /(^|[\\/])node_modules[\\/]/ } },
|
|
144
|
+
{ not: { any: ownedByOtherRules(wrapProxy) } }
|
|
145
|
+
]
|
|
146
|
+
},
|
|
147
|
+
loaders: [
|
|
148
|
+
{
|
|
149
|
+
loader: loaderPath,
|
|
150
|
+
options: { kind: "instrumented-imports" }
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
};
|
|
152
154
|
}
|
|
153
155
|
return {
|
|
154
156
|
...userTurbopack,
|
|
@@ -234,29 +236,25 @@ function installLoaders(config, context) {
|
|
|
234
236
|
}
|
|
235
237
|
]
|
|
236
238
|
});
|
|
237
|
-
const libSupabase = path.resolve(projectDir, "lib/supabase");
|
|
238
|
-
const srcLibSupabase = path.resolve(projectDir, "src/lib/supabase");
|
|
239
|
-
const utilsSupabase = path.resolve(projectDir, "utils/supabase");
|
|
240
|
-
const srcUtilsSupabase = path.resolve(projectDir, "src/utils/supabase");
|
|
241
239
|
newRules.push({
|
|
242
|
-
test: new RegExp(
|
|
243
|
-
|
|
240
|
+
test: new RegExp(
|
|
241
|
+
`[/\\\\](${INLINE_ROUTE_FILENAMES.join("|")})\\.(${extPattern})$`
|
|
242
|
+
),
|
|
243
|
+
include: [appDir, srcAppDir],
|
|
244
244
|
use: [
|
|
245
245
|
{
|
|
246
246
|
loader: loaderPath,
|
|
247
|
-
options: { kind: "
|
|
247
|
+
options: { kind: "inline-server-action", projectDir }
|
|
248
248
|
}
|
|
249
249
|
]
|
|
250
250
|
});
|
|
251
251
|
newRules.push({
|
|
252
|
-
test: new RegExp(
|
|
253
|
-
|
|
254
|
-
),
|
|
255
|
-
include: [appDir, srcAppDir],
|
|
252
|
+
test: new RegExp(`\\.(${extPattern})$`),
|
|
253
|
+
exclude: /[\\/]node_modules[\\/]/,
|
|
256
254
|
use: [
|
|
257
255
|
{
|
|
258
256
|
loader: loaderPath,
|
|
259
|
-
options: { kind: "
|
|
257
|
+
options: { kind: "instrumented-imports", projectDir }
|
|
260
258
|
}
|
|
261
259
|
]
|
|
262
260
|
});
|
|
@@ -279,6 +277,25 @@ function nextMajorVersion(projectDir) {
|
|
|
279
277
|
return 0;
|
|
280
278
|
}
|
|
281
279
|
}
|
|
280
|
+
function ownedByOtherRules(wrapProxy) {
|
|
281
|
+
const sep = "[\\\\/]";
|
|
282
|
+
const ext = "\\.(?:ts|tsx|js|jsx)$";
|
|
283
|
+
const owned = [
|
|
284
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?route${ext}`) },
|
|
285
|
+
{ path: new RegExp(`(^|${sep})pages${sep}api${sep}`) },
|
|
286
|
+
{ path: new RegExp(`(^|${sep})middleware${ext}`) },
|
|
287
|
+
{ path: new RegExp(`(^|${sep})actions${sep}`) },
|
|
288
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?actions${ext}`) },
|
|
289
|
+
{
|
|
290
|
+
all: [
|
|
291
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?(${INLINE_ROUTE_FILENAMES.join("|")})${ext}`) },
|
|
292
|
+
{ content: /"use server"|'use server'/ }
|
|
293
|
+
]
|
|
294
|
+
}
|
|
295
|
+
];
|
|
296
|
+
if (wrapProxy) owned.push({ path: new RegExp(`(^|${sep})proxy${ext}`) });
|
|
297
|
+
return owned;
|
|
298
|
+
}
|
|
282
299
|
function escapeRegex(input) {
|
|
283
300
|
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
284
301
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { INSTRUMENTED_IMPORT_CONTENT } from '../chunk-DRE2VXFX.js';
|
|
1
2
|
import '../chunk-SIAA4J6H.js';
|
|
2
3
|
import { resolve, dirname } from 'path';
|
|
3
4
|
import { readFileSync } from 'fs';
|
|
@@ -75,7 +76,7 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
75
76
|
loaders: [
|
|
76
77
|
{
|
|
77
78
|
loader: loaderPath,
|
|
78
|
-
options: { kind: "middleware" }
|
|
79
|
+
options: { kind: "middleware", projectDir }
|
|
79
80
|
}
|
|
80
81
|
],
|
|
81
82
|
as: `*.${ext}`
|
|
@@ -85,7 +86,7 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
85
86
|
loaders: [
|
|
86
87
|
{
|
|
87
88
|
loader: loaderPath,
|
|
88
|
-
options: { kind: "middleware" }
|
|
89
|
+
options: { kind: "middleware", projectDir }
|
|
89
90
|
}
|
|
90
91
|
],
|
|
91
92
|
as: `*.${ext}`
|
|
@@ -118,21 +119,6 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
118
119
|
as: `*.${ext}`
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
|
-
const supabaseGlobs = [
|
|
122
|
-
`**/{lib,src/lib,utils,src/utils}/supabase/**/*.${ext}`
|
|
123
|
-
];
|
|
124
|
-
for (const glob of supabaseGlobs) {
|
|
125
|
-
ezlogsRules[glob] = {
|
|
126
|
-
condition: { not: "browser" },
|
|
127
|
-
loaders: [
|
|
128
|
-
{
|
|
129
|
-
loader: loaderPath,
|
|
130
|
-
options: { kind: "supabase-factory" }
|
|
131
|
-
}
|
|
132
|
-
],
|
|
133
|
-
as: `*.${ext}`
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
122
|
for (const inlineFilename of INLINE_ROUTE_FILENAMES) {
|
|
137
123
|
ezlogsRules[`**/{app,src/app}/**/${inlineFilename}.${ext}`] = {
|
|
138
124
|
condition: {
|
|
@@ -146,6 +132,22 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
146
132
|
]
|
|
147
133
|
};
|
|
148
134
|
}
|
|
135
|
+
ezlogsRules[`**/*.${ext}`] = {
|
|
136
|
+
condition: {
|
|
137
|
+
all: [
|
|
138
|
+
{ not: "browser" },
|
|
139
|
+
{ content: INSTRUMENTED_IMPORT_CONTENT },
|
|
140
|
+
{ not: { path: /(^|[\\/])node_modules[\\/]/ } },
|
|
141
|
+
{ not: { any: ownedByOtherRules(wrapProxy) } }
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
loaders: [
|
|
145
|
+
{
|
|
146
|
+
loader: loaderPath,
|
|
147
|
+
options: { kind: "instrumented-imports" }
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
};
|
|
149
151
|
}
|
|
150
152
|
return {
|
|
151
153
|
...userTurbopack,
|
|
@@ -231,29 +233,25 @@ function installLoaders(config, context) {
|
|
|
231
233
|
}
|
|
232
234
|
]
|
|
233
235
|
});
|
|
234
|
-
const libSupabase = resolve(projectDir, "lib/supabase");
|
|
235
|
-
const srcLibSupabase = resolve(projectDir, "src/lib/supabase");
|
|
236
|
-
const utilsSupabase = resolve(projectDir, "utils/supabase");
|
|
237
|
-
const srcUtilsSupabase = resolve(projectDir, "src/utils/supabase");
|
|
238
236
|
newRules.push({
|
|
239
|
-
test: new RegExp(
|
|
240
|
-
|
|
237
|
+
test: new RegExp(
|
|
238
|
+
`[/\\\\](${INLINE_ROUTE_FILENAMES.join("|")})\\.(${extPattern})$`
|
|
239
|
+
),
|
|
240
|
+
include: [appDir, srcAppDir],
|
|
241
241
|
use: [
|
|
242
242
|
{
|
|
243
243
|
loader: loaderPath,
|
|
244
|
-
options: { kind: "
|
|
244
|
+
options: { kind: "inline-server-action", projectDir }
|
|
245
245
|
}
|
|
246
246
|
]
|
|
247
247
|
});
|
|
248
248
|
newRules.push({
|
|
249
|
-
test: new RegExp(
|
|
250
|
-
|
|
251
|
-
),
|
|
252
|
-
include: [appDir, srcAppDir],
|
|
249
|
+
test: new RegExp(`\\.(${extPattern})$`),
|
|
250
|
+
exclude: /[\\/]node_modules[\\/]/,
|
|
253
251
|
use: [
|
|
254
252
|
{
|
|
255
253
|
loader: loaderPath,
|
|
256
|
-
options: { kind: "
|
|
254
|
+
options: { kind: "instrumented-imports", projectDir }
|
|
257
255
|
}
|
|
258
256
|
]
|
|
259
257
|
});
|
|
@@ -276,6 +274,25 @@ function nextMajorVersion(projectDir) {
|
|
|
276
274
|
return 0;
|
|
277
275
|
}
|
|
278
276
|
}
|
|
277
|
+
function ownedByOtherRules(wrapProxy) {
|
|
278
|
+
const sep = "[\\\\/]";
|
|
279
|
+
const ext = "\\.(?:ts|tsx|js|jsx)$";
|
|
280
|
+
const owned = [
|
|
281
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?route${ext}`) },
|
|
282
|
+
{ path: new RegExp(`(^|${sep})pages${sep}api${sep}`) },
|
|
283
|
+
{ path: new RegExp(`(^|${sep})middleware${ext}`) },
|
|
284
|
+
{ path: new RegExp(`(^|${sep})actions${sep}`) },
|
|
285
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?actions${ext}`) },
|
|
286
|
+
{
|
|
287
|
+
all: [
|
|
288
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?(${INLINE_ROUTE_FILENAMES.join("|")})${ext}`) },
|
|
289
|
+
{ content: /"use server"|'use server'/ }
|
|
290
|
+
]
|
|
291
|
+
}
|
|
292
|
+
];
|
|
293
|
+
if (wrapProxy) owned.push({ path: new RegExp(`(^|${sep})proxy${ext}`) });
|
|
294
|
+
return owned;
|
|
295
|
+
}
|
|
279
296
|
function escapeRegex(input) {
|
|
280
297
|
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
281
298
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var chunkNFZ5OKF3_cjs = require('../chunk-NFZ5OKF3.cjs');
|
|
5
6
|
var chunkZDSQYCYV_cjs = require('../chunk-ZDSQYCYV.cjs');
|
|
6
7
|
var path = require('path');
|
|
7
8
|
|
|
@@ -15760,6 +15761,10 @@ function loaderImpl(source) {
|
|
|
15760
15761
|
const options = readOptions(this);
|
|
15761
15762
|
const kind = options.kind ?? "app-route-handler";
|
|
15762
15763
|
const routeModulePath = computeRouteModulePath(this.resourcePath, kind);
|
|
15764
|
+
const root = options.projectDir ?? this.rootContext ?? process.cwd();
|
|
15765
|
+
const rootEntry = isRootEntryFile(this.resourcePath, root, "middleware") || isRootEntryFile(this.resourcePath, root, "proxy");
|
|
15766
|
+
if (!rootEntry) source = rewriteInstrumentedImports(source, this.resourcePath);
|
|
15767
|
+
if (kind === "instrumented-imports") return source;
|
|
15763
15768
|
if (kind === "pages-api") {
|
|
15764
15769
|
return rewritePagesApi(source, routeModulePath);
|
|
15765
15770
|
}
|
|
@@ -15767,15 +15772,10 @@ function loaderImpl(source) {
|
|
|
15767
15772
|
return rewriteMiddleware(source);
|
|
15768
15773
|
}
|
|
15769
15774
|
if (kind === "proxy") {
|
|
15770
|
-
|
|
15771
|
-
return isRootProxyFile(this.resourcePath, root) ? rewriteMiddleware(source, "proxy") : source;
|
|
15775
|
+
return rootEntry ? rewriteMiddleware(source, "proxy") : source;
|
|
15772
15776
|
}
|
|
15773
15777
|
if (kind === "server-action") {
|
|
15774
|
-
|
|
15775
|
-
return rewriteServerActionFile(withSupabase);
|
|
15776
|
-
}
|
|
15777
|
-
if (kind === "supabase-factory") {
|
|
15778
|
-
return rewriteSupabaseFactoryImports(source);
|
|
15778
|
+
return rewriteServerActionFile(source);
|
|
15779
15779
|
}
|
|
15780
15780
|
if (kind === "inline-server-action") {
|
|
15781
15781
|
return rewriteInlineServerActions(source, this.resourcePath);
|
|
@@ -15861,70 +15861,75 @@ function rewriteLocalAliasedRouteExports(source, routeModulePath) {
|
|
|
15861
15861
|
}
|
|
15862
15862
|
function renameDestructuredExports(source) {
|
|
15863
15863
|
const methodSet = new Set(HTTP_METHOD_NAMES);
|
|
15864
|
-
const workflowServe = upstashWorkflowServeNames(source);
|
|
15865
15864
|
const methods = [];
|
|
15866
15865
|
const out = source.replace(
|
|
15867
15866
|
/(^|\n)([ \t]*)export\s+const\s*\{([^}]+)\}\s*=/g,
|
|
15868
15867
|
(full, lead, indent, list, offset) => {
|
|
15869
15868
|
const names = list.split(",").map((n) => n.trim()).filter(Boolean);
|
|
15870
15869
|
if (names.length === 0 || !names.every((n) => methodSet.has(n))) return full;
|
|
15871
|
-
const callee = /^\s*([A-Za-z_$][\w$]*)\s*[<(]/.exec(source.slice(offset + full.length))?.[1];
|
|
15872
|
-
if (callee && workflowServe.has(callee)) return full;
|
|
15873
15870
|
methods.push(...names);
|
|
15874
15871
|
return `${lead}${indent}const { ${names.map((n) => `${n}: ${ALREADY_WRAPPED_MARKER}${n}`).join(", ")} } =`;
|
|
15875
15872
|
}
|
|
15876
15873
|
);
|
|
15877
15874
|
return { source: out, methods };
|
|
15878
15875
|
}
|
|
15879
|
-
|
|
15880
|
-
|
|
15881
|
-
|
|
15882
|
-
|
|
15883
|
-
|
|
15884
|
-
|
|
15876
|
+
var NEVER_WRAP_EXPORTS = /* @__PURE__ */ new Set(["config", "metadata", "generateMetadata"]);
|
|
15877
|
+
var IMPORT_MARKER = "__ezlogs_import_";
|
|
15878
|
+
var NAMED_IMPORT = /^(\uFEFF?[ \t]*)import\s+(?!type\b)((?:[A-Za-z_$][\w$]*\s*,\s*)?)\{([^}]*)\}(\s*from\s*)(["'])([^"'\n]+)\5([ \t]*;?)/gm;
|
|
15879
|
+
function rewriteInstrumentedImports(source, filename = "file.ts") {
|
|
15880
|
+
if (!chunkNFZ5OKF3_cjs.INSTRUMENTED_IMPORTS.some((entry) => source.includes(entry.module))) return source;
|
|
15881
|
+
if (hasFileLevelDirective(source, "use client")) return source;
|
|
15882
|
+
const tokens = tokenize(source, filename);
|
|
15883
|
+
if (!tokens) return source;
|
|
15884
|
+
const importStarts = new Set(tokens.filter((t) => t.type === TT_IMPORT).map((t) => t.start));
|
|
15885
|
+
const valueUses = (local, from, to) => tokens.some(
|
|
15886
|
+
(t) => t.type === TT_NAME && !t.isType && (t.start < from || t.start >= to) && source.slice(t.start, t.end) === local
|
|
15887
|
+
);
|
|
15888
|
+
const imported = /* @__PURE__ */ new Set();
|
|
15889
|
+
return source.replace(
|
|
15890
|
+
NAMED_IMPORT,
|
|
15891
|
+
(full, indent, defaultPart, list, from, quote, module, end, offset) => {
|
|
15892
|
+
const entry = chunkNFZ5OKF3_cjs.INSTRUMENTED_IMPORTS.find((e) => e.module === module);
|
|
15893
|
+
if (!entry || !importStarts.has(offset + indent.length)) return full;
|
|
15894
|
+
if (/^\s*(?:with|assert)\s*\{/.test(source.slice(offset + full.length))) return full;
|
|
15895
|
+
const replaced = [];
|
|
15896
|
+
const specifiers = list.split(",").map((piece) => {
|
|
15897
|
+
const spec = piece.trim();
|
|
15898
|
+
const match = /^([A-Za-z_$][\w$]*)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/.exec(spec);
|
|
15899
|
+
if (!match) return piece;
|
|
15900
|
+
const name = match[1];
|
|
15901
|
+
const local = match[2] ?? name;
|
|
15902
|
+
if (!entry.names.includes(name) || local.startsWith(IMPORT_MARKER)) return piece;
|
|
15903
|
+
if (!valueUses(local, offset, offset + full.length)) return piece;
|
|
15904
|
+
replaced.push({ local, name });
|
|
15905
|
+
return piece.replace(spec, `${name} as ${IMPORT_MARKER}${local}`);
|
|
15906
|
+
});
|
|
15907
|
+
if (replaced.length === 0) return full;
|
|
15908
|
+
const instrument = `__ezlogs_instrument_${entry.via.replace(/[^A-Za-z0-9]/g, "_")}`;
|
|
15909
|
+
const added = [];
|
|
15910
|
+
if (!imported.has(instrument)) {
|
|
15911
|
+
imported.add(instrument);
|
|
15912
|
+
added.push(`import { __ezlogsInstrument as ${instrument} } from "${PACKAGE_NAME}/${entry.via}";`);
|
|
15913
|
+
}
|
|
15914
|
+
for (const { local, name } of replaced) {
|
|
15915
|
+
added.push(`const ${local} = ${instrument}("${module}#${name}", ${IMPORT_MARKER}${local});`);
|
|
15916
|
+
}
|
|
15917
|
+
const statement = `${indent}import ${defaultPart}{${specifiers.join(",")}}${from}${quote}${module}${quote}${end}`;
|
|
15918
|
+
return `${statement}${end.trim().endsWith(";") ? "" : ";"} ${added.join(" ")}`;
|
|
15885
15919
|
}
|
|
15886
|
-
|
|
15887
|
-
return names;
|
|
15920
|
+
);
|
|
15888
15921
|
}
|
|
15889
|
-
|
|
15890
|
-
|
|
15891
|
-
|
|
15892
|
-
{
|
|
15893
|
-
|
|
15894
|
-
|
|
15895
|
-
|
|
15896
|
-
|
|
15897
|
-
let changed = false;
|
|
15898
|
-
let needsWrapImport = false;
|
|
15899
|
-
for (const { module, exportName } of SUPABASE_FACTORY_IMPORTS) {
|
|
15900
|
-
const importPattern = new RegExp(
|
|
15901
|
-
`(import\\s*\\{[^}]*?)\\b(${exportName})\\b(\\s*(?:,[^}]*)?\\}\\s*from\\s*['"]${escapeRegexLiteral(module)}['"])`,
|
|
15902
|
-
"m"
|
|
15922
|
+
function tokenize(source, filename) {
|
|
15923
|
+
const sucraseParse = getSucraseParse();
|
|
15924
|
+
if (sucraseParse === null) return null;
|
|
15925
|
+
try {
|
|
15926
|
+
return sucraseParse(source, /\.(jsx|tsx|js|mjs|cjs)$/i.test(filename), /\.([cm]?ts|tsx)$/i.test(filename), false).tokens;
|
|
15927
|
+
} catch (e) {
|
|
15928
|
+
console.warn(
|
|
15929
|
+
`[ezlogs] sucrase parse failed for ${filename}; its library imports are not instrumented. ${e instanceof Error ? e.message : String(e)}`
|
|
15903
15930
|
);
|
|
15904
|
-
|
|
15905
|
-
if (!match) continue;
|
|
15906
|
-
const insertPoint = match.index + match[1].length + match[2].length;
|
|
15907
|
-
const after = rewritten.slice(insertPoint, insertPoint + 6);
|
|
15908
|
-
if (/^\s+as\b/.test(after)) continue;
|
|
15909
|
-
rewritten = rewritten.replace(importPattern, (_full, lead, name, tail) => {
|
|
15910
|
-
return `${lead}${name} as ${ALREADY_WRAPPED_MARKER}${name}${tail}`;
|
|
15911
|
-
});
|
|
15912
|
-
const wrapper = `const ${exportName} = (...__ezlogs_args) => ${ALREADY_WRAPPED_MARKER}wrap(${ALREADY_WRAPPED_MARKER}${exportName}(...__ezlogs_args));`;
|
|
15913
|
-
rewritten = `${rewritten}
|
|
15914
|
-
${wrapper}
|
|
15915
|
-
`;
|
|
15916
|
-
changed = true;
|
|
15917
|
-
needsWrapImport = true;
|
|
15918
|
-
}
|
|
15919
|
-
if (!changed) return source;
|
|
15920
|
-
if (needsWrapImport) {
|
|
15921
|
-
rewritten = `import { wrapSupabase as ${ALREADY_WRAPPED_MARKER}wrap } from "${PACKAGE_NAME}/supabase";
|
|
15922
|
-
${rewritten}`;
|
|
15931
|
+
return null;
|
|
15923
15932
|
}
|
|
15924
|
-
return rewritten;
|
|
15925
|
-
}
|
|
15926
|
-
function escapeRegexLiteral(input) {
|
|
15927
|
-
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15928
15933
|
}
|
|
15929
15934
|
function rewriteServerActionFile(source) {
|
|
15930
15935
|
if (!hasFileLevelUseServer(source)) return source;
|
|
@@ -15972,6 +15977,7 @@ var TT_ARROW = 22528;
|
|
|
15972
15977
|
var TT_CONST = 80912;
|
|
15973
15978
|
var TT_LET = 79888;
|
|
15974
15979
|
var TT_VAR = 78864;
|
|
15980
|
+
var TT_IMPORT = 90640;
|
|
15975
15981
|
var INLINE_HELPER_NAME = "__ezlogs_run_inline_server_action";
|
|
15976
15982
|
function rewriteInlineServerActions(source, filename) {
|
|
15977
15983
|
if (!source.includes("use server")) return source;
|
|
@@ -16127,11 +16133,14 @@ function skipMatchingParens(tokens, idx) {
|
|
|
16127
16133
|
return -1;
|
|
16128
16134
|
}
|
|
16129
16135
|
function hasFileLevelUseServer(source) {
|
|
16136
|
+
return hasFileLevelDirective(source, "use server");
|
|
16137
|
+
}
|
|
16138
|
+
function hasFileLevelDirective(source, directive) {
|
|
16130
16139
|
let i = 0;
|
|
16131
16140
|
const n = source.length;
|
|
16132
16141
|
while (i < n) {
|
|
16133
16142
|
const ch = source.charCodeAt(i);
|
|
16134
|
-
if (ch === 32 || ch === 9 || ch === 10 || ch === 13) {
|
|
16143
|
+
if (ch === 32 || ch === 9 || ch === 10 || ch === 13 || ch === 65279) {
|
|
16135
16144
|
i += 1;
|
|
16136
16145
|
continue;
|
|
16137
16146
|
}
|
|
@@ -16149,8 +16158,8 @@ function hasFileLevelUseServer(source) {
|
|
|
16149
16158
|
}
|
|
16150
16159
|
break;
|
|
16151
16160
|
}
|
|
16152
|
-
const head = source.slice(i, i +
|
|
16153
|
-
return
|
|
16161
|
+
const head = source.slice(i, i + directive.length + 2);
|
|
16162
|
+
return head === `"${directive}"` || head === `'${directive}'`;
|
|
16154
16163
|
}
|
|
16155
16164
|
function rewriteMiddleware(source, name = "middleware") {
|
|
16156
16165
|
const namedRenamed = renameExport(source, name);
|
|
@@ -16179,9 +16188,9 @@ function rewriteMiddleware(source, name = "middleware") {
|
|
|
16179
16188
|
}
|
|
16180
16189
|
return source;
|
|
16181
16190
|
}
|
|
16182
|
-
function
|
|
16191
|
+
function isRootEntryFile(resourcePath, root, name) {
|
|
16183
16192
|
const rel = path.relative(root, resourcePath).split(path.sep).join("/");
|
|
16184
|
-
return
|
|
16193
|
+
return new RegExp(`^(?:src/)?${name}\\.[cm]?[jt]sx?$`).test(rel);
|
|
16185
16194
|
}
|
|
16186
16195
|
function rewritePagesApi(source, routeModulePath) {
|
|
16187
16196
|
const renamed = renameDefaultExport(source);
|
|
@@ -16290,3 +16299,4 @@ function basename(p) {
|
|
|
16290
16299
|
exports.default = loader;
|
|
16291
16300
|
exports.pitch = pitch;
|
|
16292
16301
|
exports.rewriteInlineServerActions = rewriteInlineServerActions;
|
|
16302
|
+
exports.rewriteInstrumentedImports = rewriteInstrumentedImports;
|