ezlogs-nextjs 0.4.4 → 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.
Files changed (65) hide show
  1. package/README.md +51 -11
  2. package/dist/actors/index.d.cts +1 -1
  3. package/dist/actors/index.d.ts +1 -1
  4. package/dist/{chunk-Z2TM3LGG.js → chunk-2NFJOT6Q.js} +1 -1
  5. package/dist/{chunk-R6IWVTX3.cjs → chunk-65HRY3PW.cjs} +31 -21
  6. package/dist/{chunk-YXZZNZG6.cjs → chunk-B3WST6ES.cjs} +9 -9
  7. package/dist/{chunk-MMLQXSSD.cjs → chunk-B5ZUQULZ.cjs} +18 -11
  8. package/dist/{chunk-NX4EL7BY.cjs → chunk-DM2EAOSF.cjs} +4 -4
  9. package/dist/chunk-DRE2VXFX.js +19 -0
  10. package/dist/chunk-H3FC5HMW.cjs +16 -0
  11. package/dist/{chunk-GI6BM4MR.js → chunk-IBSNHBUC.js} +18 -12
  12. package/dist/chunk-JWJKFZBW.js +52 -0
  13. package/dist/{chunk-MHBS5FEP.js → chunk-M3VBQ5KT.js} +27 -4
  14. package/dist/chunk-NFZ5OKF3.cjs +22 -0
  15. package/dist/{chunk-GMHOUAKD.cjs → chunk-O7SFYXJC.cjs} +37 -13
  16. package/dist/{chunk-U22T7QYY.js → chunk-PK2Z2ABL.js} +13 -3
  17. package/dist/{chunk-YMIGZYFH.js → chunk-RD47JECJ.js} +1 -1
  18. package/dist/chunk-RMKGMIV2.js +13 -0
  19. package/dist/{chunk-NINIAL7M.js → chunk-U3IJV5EJ.js} +1 -1
  20. package/dist/chunk-VJR4VB4B.cjs +56 -0
  21. package/dist/{chunk-PS4U2GFJ.cjs → chunk-YO6E763S.cjs} +5 -5
  22. package/dist/{configuration-CJ5yKVlP.d.cts → configuration-b9pImwFB.d.cts} +2 -2
  23. package/dist/{configuration-CJ5yKVlP.d.ts → configuration-b9pImwFB.d.ts} +2 -2
  24. package/dist/db/drizzle.cjs +3 -3
  25. package/dist/db/drizzle.js +2 -2
  26. package/dist/db/postgres-js.cjs +4 -4
  27. package/dist/db/postgres-js.js +2 -2
  28. package/dist/db/prisma.cjs +12 -12
  29. package/dist/db/prisma.js +2 -2
  30. package/dist/db/supabase.cjs +42 -17
  31. package/dist/db/supabase.d.cts +11 -5
  32. package/dist/db/supabase.d.ts +11 -5
  33. package/dist/db/supabase.js +33 -9
  34. package/dist/index.cjs +288 -142
  35. package/dist/index.d.cts +2 -2
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.js +198 -52
  38. package/dist/jobs/bullmq.cjs +44 -16
  39. package/dist/jobs/bullmq.d.cts +7 -1
  40. package/dist/jobs/bullmq.d.ts +7 -1
  41. package/dist/jobs/bullmq.js +33 -6
  42. package/dist/jobs/inngest.cjs +36 -17
  43. package/dist/jobs/inngest.d.cts +7 -1
  44. package/dist/jobs/inngest.d.ts +7 -1
  45. package/dist/jobs/inngest.js +23 -5
  46. package/dist/jobs/supabase-queues.cjs +9 -9
  47. package/dist/jobs/supabase-queues.js +4 -4
  48. package/dist/jobs/trigger.cjs +7 -7
  49. package/dist/jobs/trigger.js +4 -4
  50. package/dist/jobs/upstash-workflow.cjs +139 -23
  51. package/dist/jobs/upstash-workflow.d.cts +20 -2
  52. package/dist/jobs/upstash-workflow.d.ts +20 -2
  53. package/dist/jobs/upstash-workflow.js +129 -14
  54. package/dist/nextjs-plugin/index.cjs +46 -29
  55. package/dist/nextjs-plugin/index.js +46 -29
  56. package/dist/nextjs-plugin/loader.cjs +70 -60
  57. package/dist/nextjs-plugin/loader.d.cts +18 -1
  58. package/dist/nextjs-plugin/loader.d.ts +18 -1
  59. package/dist/nextjs-plugin/loader.js +70 -61
  60. package/dist/triggers/index.cjs +22 -16
  61. package/dist/triggers/index.d.cts +0 -10
  62. package/dist/triggers/index.d.ts +0 -10
  63. package/dist/triggers/index.js +11 -5
  64. package/package.json +1 -1
  65. package/sql/postgres/00_install.sql +20 -3
@@ -35,6 +35,23 @@ declare function loader(this: PitchContext, source: string): string;
35
35
  * through the main loader function, which we transform inline.
36
36
  */
37
37
  declare function pitch(this: PitchContext, _remainingRequest: string): undefined;
38
+ /**
39
+ * Rewrites `import { X } from "<library>"` (aliases included) so the
40
+ * file's `X` is the agent's instrumented replacement:
41
+ *
42
+ * import { Queue as __ezlogs_import_Queue } from "bullmq"; import { __ezlogsInstrument as __ezlogs_instrument_bullmq } from "ezlogs-nextjs/bullmq"; const Queue = __ezlogs_instrument_bullmq("bullmq#Queue", __ezlogs_import_Queue);
43
+ *
44
+ * The added code stays on the import's own line (line numbers in stack
45
+ * traces are unchanged) and right after it (the binding exists before
46
+ * any top-level code uses it). Only real import statements are touched
47
+ * (the tokenizer tells them from text in comments and strings), and
48
+ * only bindings the file uses as values: a type-only import stays one,
49
+ * so TypeScript still drops it and the library is not pulled into a
50
+ * bundle that never needed it. Client components are left alone: they
51
+ * also render on the server, but their imports are browser code.
52
+ * Idempotent: renamed bindings are not renamed again.
53
+ */
54
+ declare function rewriteInstrumentedImports(source: string, filename?: string): string;
38
55
  /**
39
56
  * Rewrite inline `"use server"` actions inside RSC components
40
57
  * (page/layout/etc.) so each one runs through
@@ -69,4 +86,4 @@ declare function pitch(this: PitchContext, _remainingRequest: string): undefined
69
86
  */
70
87
  declare function rewriteInlineServerActions(source: string, filename: string): string;
71
88
 
72
- export { loader as default, pitch, rewriteInlineServerActions };
89
+ export { loader as default, pitch, rewriteInlineServerActions, rewriteInstrumentedImports };
@@ -35,6 +35,23 @@ declare function loader(this: PitchContext, source: string): string;
35
35
  * through the main loader function, which we transform inline.
36
36
  */
37
37
  declare function pitch(this: PitchContext, _remainingRequest: string): undefined;
38
+ /**
39
+ * Rewrites `import { X } from "<library>"` (aliases included) so the
40
+ * file's `X` is the agent's instrumented replacement:
41
+ *
42
+ * import { Queue as __ezlogs_import_Queue } from "bullmq"; import { __ezlogsInstrument as __ezlogs_instrument_bullmq } from "ezlogs-nextjs/bullmq"; const Queue = __ezlogs_instrument_bullmq("bullmq#Queue", __ezlogs_import_Queue);
43
+ *
44
+ * The added code stays on the import's own line (line numbers in stack
45
+ * traces are unchanged) and right after it (the binding exists before
46
+ * any top-level code uses it). Only real import statements are touched
47
+ * (the tokenizer tells them from text in comments and strings), and
48
+ * only bindings the file uses as values: a type-only import stays one,
49
+ * so TypeScript still drops it and the library is not pulled into a
50
+ * bundle that never needed it. Client components are left alone: they
51
+ * also render on the server, but their imports are browser code.
52
+ * Idempotent: renamed bindings are not renamed again.
53
+ */
54
+ declare function rewriteInstrumentedImports(source: string, filename?: string): string;
38
55
  /**
39
56
  * Rewrite inline `"use server"` actions inside RSC components
40
57
  * (page/layout/etc.) so each one runs through
@@ -69,4 +86,4 @@ declare function pitch(this: PitchContext, _remainingRequest: string): undefined
69
86
  */
70
87
  declare function rewriteInlineServerActions(source: string, filename: string): string;
71
88
 
72
- export { loader as default, pitch, rewriteInlineServerActions };
89
+ export { loader as default, pitch, rewriteInlineServerActions, rewriteInstrumentedImports };
@@ -1,3 +1,4 @@
1
+ import { INSTRUMENTED_IMPORTS } from '../chunk-DRE2VXFX.js';
1
2
  import { __commonJS } from '../chunk-SIAA4J6H.js';
2
3
  import { relative, sep } from 'path';
3
4
 
@@ -15756,6 +15757,10 @@ function loaderImpl(source) {
15756
15757
  const options = readOptions(this);
15757
15758
  const kind = options.kind ?? "app-route-handler";
15758
15759
  const routeModulePath = computeRouteModulePath(this.resourcePath, kind);
15760
+ const root = options.projectDir ?? this.rootContext ?? process.cwd();
15761
+ const rootEntry = isRootEntryFile(this.resourcePath, root, "middleware") || isRootEntryFile(this.resourcePath, root, "proxy");
15762
+ if (!rootEntry) source = rewriteInstrumentedImports(source, this.resourcePath);
15763
+ if (kind === "instrumented-imports") return source;
15759
15764
  if (kind === "pages-api") {
15760
15765
  return rewritePagesApi(source, routeModulePath);
15761
15766
  }
@@ -15763,15 +15768,10 @@ function loaderImpl(source) {
15763
15768
  return rewriteMiddleware(source);
15764
15769
  }
15765
15770
  if (kind === "proxy") {
15766
- const root = options.projectDir ?? this.rootContext ?? process.cwd();
15767
- return isRootProxyFile(this.resourcePath, root) ? rewriteMiddleware(source, "proxy") : source;
15771
+ return rootEntry ? rewriteMiddleware(source, "proxy") : source;
15768
15772
  }
15769
15773
  if (kind === "server-action") {
15770
- const withSupabase = rewriteSupabaseFactoryImports(source);
15771
- return rewriteServerActionFile(withSupabase);
15772
- }
15773
- if (kind === "supabase-factory") {
15774
- return rewriteSupabaseFactoryImports(source);
15774
+ return rewriteServerActionFile(source);
15775
15775
  }
15776
15776
  if (kind === "inline-server-action") {
15777
15777
  return rewriteInlineServerActions(source, this.resourcePath);
@@ -15857,70 +15857,75 @@ function rewriteLocalAliasedRouteExports(source, routeModulePath) {
15857
15857
  }
15858
15858
  function renameDestructuredExports(source) {
15859
15859
  const methodSet = new Set(HTTP_METHOD_NAMES);
15860
- const workflowServe = upstashWorkflowServeNames(source);
15861
15860
  const methods = [];
15862
15861
  const out = source.replace(
15863
15862
  /(^|\n)([ \t]*)export\s+const\s*\{([^}]+)\}\s*=/g,
15864
15863
  (full, lead, indent, list, offset) => {
15865
15864
  const names = list.split(",").map((n) => n.trim()).filter(Boolean);
15866
15865
  if (names.length === 0 || !names.every((n) => methodSet.has(n))) return full;
15867
- const callee = /^\s*([A-Za-z_$][\w$]*)\s*[<(]/.exec(source.slice(offset + full.length))?.[1];
15868
- if (callee && workflowServe.has(callee)) return full;
15869
15866
  methods.push(...names);
15870
15867
  return `${lead}${indent}const { ${names.map((n) => `${n}: ${ALREADY_WRAPPED_MARKER}${n}`).join(", ")} } =`;
15871
15868
  }
15872
15869
  );
15873
15870
  return { source: out, methods };
15874
15871
  }
15875
- function upstashWorkflowServeNames(source) {
15876
- const names = /* @__PURE__ */ new Set();
15877
- for (const m of source.matchAll(/import\s*\{([^}]*)\}\s*from\s*["']@upstash\/workflow(?:\/[^"']*)?["']/g)) {
15878
- for (const spec of m[1].split(",")) {
15879
- const [imported, local] = spec.trim().split(/\s+as\s+/);
15880
- if (imported === "serve") names.add((local ?? imported).trim());
15872
+ var NEVER_WRAP_EXPORTS = /* @__PURE__ */ new Set(["config", "metadata", "generateMetadata"]);
15873
+ var IMPORT_MARKER = "__ezlogs_import_";
15874
+ var NAMED_IMPORT = /^(\uFEFF?[ \t]*)import\s+(?!type\b)((?:[A-Za-z_$][\w$]*\s*,\s*)?)\{([^}]*)\}(\s*from\s*)(["'])([^"'\n]+)\5([ \t]*;?)/gm;
15875
+ function rewriteInstrumentedImports(source, filename = "file.ts") {
15876
+ if (!INSTRUMENTED_IMPORTS.some((entry) => source.includes(entry.module))) return source;
15877
+ if (hasFileLevelDirective(source, "use client")) return source;
15878
+ const tokens = tokenize(source, filename);
15879
+ if (!tokens) return source;
15880
+ const importStarts = new Set(tokens.filter((t) => t.type === TT_IMPORT).map((t) => t.start));
15881
+ const valueUses = (local, from, to) => tokens.some(
15882
+ (t) => t.type === TT_NAME && !t.isType && (t.start < from || t.start >= to) && source.slice(t.start, t.end) === local
15883
+ );
15884
+ const imported = /* @__PURE__ */ new Set();
15885
+ return source.replace(
15886
+ NAMED_IMPORT,
15887
+ (full, indent, defaultPart, list, from, quote, module, end, offset) => {
15888
+ const entry = INSTRUMENTED_IMPORTS.find((e) => e.module === module);
15889
+ if (!entry || !importStarts.has(offset + indent.length)) return full;
15890
+ if (/^\s*(?:with|assert)\s*\{/.test(source.slice(offset + full.length))) return full;
15891
+ const replaced = [];
15892
+ const specifiers = list.split(",").map((piece) => {
15893
+ const spec = piece.trim();
15894
+ const match = /^([A-Za-z_$][\w$]*)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/.exec(spec);
15895
+ if (!match) return piece;
15896
+ const name = match[1];
15897
+ const local = match[2] ?? name;
15898
+ if (!entry.names.includes(name) || local.startsWith(IMPORT_MARKER)) return piece;
15899
+ if (!valueUses(local, offset, offset + full.length)) return piece;
15900
+ replaced.push({ local, name });
15901
+ return piece.replace(spec, `${name} as ${IMPORT_MARKER}${local}`);
15902
+ });
15903
+ if (replaced.length === 0) return full;
15904
+ const instrument = `__ezlogs_instrument_${entry.via.replace(/[^A-Za-z0-9]/g, "_")}`;
15905
+ const added = [];
15906
+ if (!imported.has(instrument)) {
15907
+ imported.add(instrument);
15908
+ added.push(`import { __ezlogsInstrument as ${instrument} } from "${PACKAGE_NAME}/${entry.via}";`);
15909
+ }
15910
+ for (const { local, name } of replaced) {
15911
+ added.push(`const ${local} = ${instrument}("${module}#${name}", ${IMPORT_MARKER}${local});`);
15912
+ }
15913
+ const statement = `${indent}import ${defaultPart}{${specifiers.join(",")}}${from}${quote}${module}${quote}${end}`;
15914
+ return `${statement}${end.trim().endsWith(";") ? "" : ";"} ${added.join(" ")}`;
15881
15915
  }
15882
- }
15883
- return names;
15916
+ );
15884
15917
  }
15885
- var NEVER_WRAP_EXPORTS = /* @__PURE__ */ new Set(["config", "metadata", "generateMetadata"]);
15886
- var SUPABASE_FACTORY_IMPORTS = [
15887
- { module: "@supabase/supabase-js", exportName: "createClient" },
15888
- { module: "@supabase/ssr", exportName: "createServerClient" },
15889
- { module: "@supabase/ssr", exportName: "createBrowserClient" }
15890
- ];
15891
- function rewriteSupabaseFactoryImports(source) {
15892
- let rewritten = source;
15893
- let changed = false;
15894
- let needsWrapImport = false;
15895
- for (const { module, exportName } of SUPABASE_FACTORY_IMPORTS) {
15896
- const importPattern = new RegExp(
15897
- `(import\\s*\\{[^}]*?)\\b(${exportName})\\b(\\s*(?:,[^}]*)?\\}\\s*from\\s*['"]${escapeRegexLiteral(module)}['"])`,
15898
- "m"
15918
+ function tokenize(source, filename) {
15919
+ const sucraseParse = getSucraseParse();
15920
+ if (sucraseParse === null) return null;
15921
+ try {
15922
+ return sucraseParse(source, /\.(jsx|tsx|js|mjs|cjs)$/i.test(filename), /\.([cm]?ts|tsx)$/i.test(filename), false).tokens;
15923
+ } catch (e) {
15924
+ console.warn(
15925
+ `[ezlogs] sucrase parse failed for ${filename}; its library imports are not instrumented. ${e instanceof Error ? e.message : String(e)}`
15899
15926
  );
15900
- const match = rewritten.match(importPattern);
15901
- if (!match) continue;
15902
- const insertPoint = match.index + match[1].length + match[2].length;
15903
- const after = rewritten.slice(insertPoint, insertPoint + 6);
15904
- if (/^\s+as\b/.test(after)) continue;
15905
- rewritten = rewritten.replace(importPattern, (_full, lead, name, tail) => {
15906
- return `${lead}${name} as ${ALREADY_WRAPPED_MARKER}${name}${tail}`;
15907
- });
15908
- const wrapper = `const ${exportName} = (...__ezlogs_args) => ${ALREADY_WRAPPED_MARKER}wrap(${ALREADY_WRAPPED_MARKER}${exportName}(...__ezlogs_args));`;
15909
- rewritten = `${rewritten}
15910
- ${wrapper}
15911
- `;
15912
- changed = true;
15913
- needsWrapImport = true;
15914
- }
15915
- if (!changed) return source;
15916
- if (needsWrapImport) {
15917
- rewritten = `import { wrapSupabase as ${ALREADY_WRAPPED_MARKER}wrap } from "${PACKAGE_NAME}/supabase";
15918
- ${rewritten}`;
15927
+ return null;
15919
15928
  }
15920
- return rewritten;
15921
- }
15922
- function escapeRegexLiteral(input) {
15923
- return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
15924
15929
  }
15925
15930
  function rewriteServerActionFile(source) {
15926
15931
  if (!hasFileLevelUseServer(source)) return source;
@@ -15968,6 +15973,7 @@ var TT_ARROW = 22528;
15968
15973
  var TT_CONST = 80912;
15969
15974
  var TT_LET = 79888;
15970
15975
  var TT_VAR = 78864;
15976
+ var TT_IMPORT = 90640;
15971
15977
  var INLINE_HELPER_NAME = "__ezlogs_run_inline_server_action";
15972
15978
  function rewriteInlineServerActions(source, filename) {
15973
15979
  if (!source.includes("use server")) return source;
@@ -16123,11 +16129,14 @@ function skipMatchingParens(tokens, idx) {
16123
16129
  return -1;
16124
16130
  }
16125
16131
  function hasFileLevelUseServer(source) {
16132
+ return hasFileLevelDirective(source, "use server");
16133
+ }
16134
+ function hasFileLevelDirective(source, directive) {
16126
16135
  let i = 0;
16127
16136
  const n = source.length;
16128
16137
  while (i < n) {
16129
16138
  const ch = source.charCodeAt(i);
16130
- if (ch === 32 || ch === 9 || ch === 10 || ch === 13) {
16139
+ if (ch === 32 || ch === 9 || ch === 10 || ch === 13 || ch === 65279) {
16131
16140
  i += 1;
16132
16141
  continue;
16133
16142
  }
@@ -16145,8 +16154,8 @@ function hasFileLevelUseServer(source) {
16145
16154
  }
16146
16155
  break;
16147
16156
  }
16148
- const head = source.slice(i, i + 14);
16149
- return /^["']use server["']/.test(head);
16157
+ const head = source.slice(i, i + directive.length + 2);
16158
+ return head === `"${directive}"` || head === `'${directive}'`;
16150
16159
  }
16151
16160
  function rewriteMiddleware(source, name = "middleware") {
16152
16161
  const namedRenamed = renameExport(source, name);
@@ -16175,9 +16184,9 @@ function rewriteMiddleware(source, name = "middleware") {
16175
16184
  }
16176
16185
  return source;
16177
16186
  }
16178
- function isRootProxyFile(resourcePath, root) {
16187
+ function isRootEntryFile(resourcePath, root, name) {
16179
16188
  const rel = relative(root, resourcePath).split(sep).join("/");
16180
- return /^(?:src\/)?proxy\.[cm]?[jt]sx?$/.test(rel);
16189
+ return new RegExp(`^(?:src/)?${name}\\.[cm]?[jt]sx?$`).test(rel);
16181
16190
  }
16182
16191
  function rewritePagesApi(source, routeModulePath) {
16183
16192
  const renamed = renameDefaultExport(source);
@@ -16283,4 +16292,4 @@ function basename(p) {
16283
16292
  return idx >= 0 ? p.slice(idx + 1) : p;
16284
16293
  }
16285
16294
 
16286
- export { loader as default, pitch, rewriteInlineServerActions };
16295
+ export { loader as default, pitch, rewriteInlineServerActions, rewriteInstrumentedImports };
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkNX4EL7BY_cjs = require('../chunk-NX4EL7BY.cjs');
4
- var chunkPS4U2GFJ_cjs = require('../chunk-PS4U2GFJ.cjs');
5
- var chunkGMHOUAKD_cjs = require('../chunk-GMHOUAKD.cjs');
6
- require('../chunk-YXZZNZG6.cjs');
7
- var chunkMMLQXSSD_cjs = require('../chunk-MMLQXSSD.cjs');
3
+ var chunkDM2EAOSF_cjs = require('../chunk-DM2EAOSF.cjs');
4
+ var chunkYO6E763S_cjs = require('../chunk-YO6E763S.cjs');
5
+ var chunkO7SFYXJC_cjs = require('../chunk-O7SFYXJC.cjs');
6
+ require('../chunk-B3WST6ES.cjs');
7
+ var chunkB5ZUQULZ_cjs = require('../chunk-B5ZUQULZ.cjs');
8
8
  var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
9
9
  require('../chunk-ZDSQYCYV.cjs');
10
10
  var promises = require('fs/promises');
@@ -125,7 +125,7 @@ function skipReason(tableName, hasAuthColumns) {
125
125
  for (const [pattern, reason] of NAMED_SKIPS) {
126
126
  if (typeof pattern === "string" ? tableName === pattern : pattern.test(tableName)) return reason;
127
127
  }
128
- if (chunkMMLQXSSD_cjs.AUTH_SESSION_TABLE_NAMES.test(tableName) && (hasAuthColumns !== false || /verif/i.test(tableName))) {
128
+ if (chunkB5ZUQULZ_cjs.AUTH_SESSION_TABLE_NAMES.test(tableName) && (hasAuthColumns !== false || /verif/i.test(tableName))) {
129
129
  return "auth / session store (has token, expiry or session-data columns)";
130
130
  }
131
131
  return null;
@@ -145,6 +145,12 @@ SELECT t.table_name,
145
145
  FROM information_schema.tables t
146
146
  WHERE t.table_schema = 'public'
147
147
  AND t.table_type = 'BASE TABLE'
148
+ -- A partition gets its parent's trigger cloned onto it; track the parent only.
149
+ AND NOT EXISTS (
150
+ SELECT 1 FROM pg_class pc
151
+ JOIN pg_namespace pn ON pn.oid = pc.relnamespace
152
+ WHERE pn.nspname = t.table_schema AND pc.relname = t.table_name AND pc.relispartition
153
+ )
148
154
  ORDER BY t.table_name
149
155
  `.trim();
150
156
  async function runInstall(args, options = {}) {
@@ -332,43 +338,43 @@ function parseEnvEntries(text) {
332
338
 
333
339
  Object.defineProperty(exports, "patchPgClient", {
334
340
  enumerable: true,
335
- get: function () { return chunkNX4EL7BY_cjs.patchPgClient; }
341
+ get: function () { return chunkDM2EAOSF_cjs.patchPgClient; }
336
342
  });
337
343
  Object.defineProperty(exports, "applyDatabaseContext", {
338
344
  enumerable: true,
339
- get: function () { return chunkPS4U2GFJ_cjs.applyDatabaseContext; }
345
+ get: function () { return chunkYO6E763S_cjs.applyDatabaseContext; }
340
346
  });
341
347
  Object.defineProperty(exports, "getDatabaseContext", {
342
348
  enumerable: true,
343
- get: function () { return chunkPS4U2GFJ_cjs.getDatabaseContext; }
349
+ get: function () { return chunkYO6E763S_cjs.getDatabaseContext; }
344
350
  });
345
351
  Object.defineProperty(exports, "withDatabaseContext", {
346
352
  enumerable: true,
347
- get: function () { return chunkPS4U2GFJ_cjs.withDatabaseContext; }
353
+ get: function () { return chunkYO6E763S_cjs.withDatabaseContext; }
348
354
  });
349
355
  Object.defineProperty(exports, "detectTriggerTrackedTables", {
350
356
  enumerable: true,
351
- get: function () { return chunkGMHOUAKD_cjs.detectTriggerTrackedTables; }
357
+ get: function () { return chunkO7SFYXJC_cjs.detectTriggerTrackedTables; }
352
358
  });
353
359
  Object.defineProperty(exports, "emitAuditRows", {
354
360
  enumerable: true,
355
- get: function () { return chunkGMHOUAKD_cjs.emitAuditRows; }
361
+ get: function () { return chunkO7SFYXJC_cjs.emitAuditRows; }
356
362
  });
357
363
  Object.defineProperty(exports, "flushAuditLog", {
358
364
  enumerable: true,
359
- get: function () { return chunkGMHOUAKD_cjs.flushAuditLog; }
365
+ get: function () { return chunkO7SFYXJC_cjs.flushAuditLog; }
360
366
  });
361
367
  Object.defineProperty(exports, "pruneAuditLog", {
362
368
  enumerable: true,
363
- get: function () { return chunkGMHOUAKD_cjs.pruneAuditLog; }
369
+ get: function () { return chunkO7SFYXJC_cjs.pruneAuditLog; }
364
370
  });
365
371
  Object.defineProperty(exports, "readAuditRows", {
366
372
  enumerable: true,
367
- get: function () { return chunkGMHOUAKD_cjs.readAuditRows; }
373
+ get: function () { return chunkO7SFYXJC_cjs.readAuditRows; }
368
374
  });
369
375
  Object.defineProperty(exports, "sweepAuditLog", {
370
376
  enumerable: true,
371
- get: function () { return chunkGMHOUAKD_cjs.sweepAuditLog; }
377
+ get: function () { return chunkO7SFYXJC_cjs.sweepAuditLog; }
372
378
  });
373
379
  exports.buildTrackingSql = buildTrackingSql;
374
380
  exports.detectEngine = detectEngine;
@@ -200,16 +200,6 @@ declare function detectTriggerTrackedTables(exec: SqlExecutor): Promise<Set<stri
200
200
  * Public so tests and advanced customers can call it directly.
201
201
  */
202
202
  declare function emitAuditRows(rows: ReadonlyArray<AuditRow>): void;
203
- /**
204
- * End-of-request entry point. Claims rows for the current correlation
205
- * id and emits each one, then runs the throttled sweep (untagged /
206
- * orphaned rows, as their own actions) and prune. Skips when no
207
- * correlation is in scope or no exec is supplied.
208
- *
209
- * The HTTP capturers call this after the user's handler returns,
210
- * before they push the HTTP event itself, so DB events arrive
211
- * grouped under the same correlation as the HTTP card.
212
- */
213
203
  declare function flushAuditLog(exec: SqlExecutor | null | undefined, options?: {
214
204
  since?: Date | null;
215
205
  }): Promise<void>;
@@ -200,16 +200,6 @@ declare function detectTriggerTrackedTables(exec: SqlExecutor): Promise<Set<stri
200
200
  * Public so tests and advanced customers can call it directly.
201
201
  */
202
202
  declare function emitAuditRows(rows: ReadonlyArray<AuditRow>): void;
203
- /**
204
- * End-of-request entry point. Claims rows for the current correlation
205
- * id and emits each one, then runs the throttled sweep (untagged /
206
- * orphaned rows, as their own actions) and prune. Skips when no
207
- * correlation is in scope or no exec is supplied.
208
- *
209
- * The HTTP capturers call this after the user's handler returns,
210
- * before they push the HTTP event itself, so DB events arrive
211
- * grouped under the same correlation as the HTTP card.
212
- */
213
203
  declare function flushAuditLog(exec: SqlExecutor | null | undefined, options?: {
214
204
  since?: Date | null;
215
205
  }): Promise<void>;
@@ -1,8 +1,8 @@
1
- export { patchPgClient } from '../chunk-Z2TM3LGG.js';
2
- export { applyDatabaseContext, getDatabaseContext, withDatabaseContext } from '../chunk-YMIGZYFH.js';
3
- export { detectTriggerTrackedTables, emitAuditRows, flushAuditLog, pruneAuditLog, readAuditRows, sweepAuditLog } from '../chunk-MHBS5FEP.js';
4
- import '../chunk-NINIAL7M.js';
5
- import { AUTH_SESSION_TABLE_NAMES } from '../chunk-GI6BM4MR.js';
1
+ export { patchPgClient } from '../chunk-2NFJOT6Q.js';
2
+ export { applyDatabaseContext, getDatabaseContext, withDatabaseContext } from '../chunk-RD47JECJ.js';
3
+ export { detectTriggerTrackedTables, emitAuditRows, flushAuditLog, pruneAuditLog, readAuditRows, sweepAuditLog } from '../chunk-M3VBQ5KT.js';
4
+ import '../chunk-U3IJV5EJ.js';
5
+ import { AUTH_SESSION_TABLE_NAMES } from '../chunk-IBSNHBUC.js';
6
6
  import { logger } from '../chunk-FCFVIRQF.js';
7
7
  import '../chunk-SIAA4J6H.js';
8
8
  import { readFile } from 'fs/promises';
@@ -142,6 +142,12 @@ SELECT t.table_name,
142
142
  FROM information_schema.tables t
143
143
  WHERE t.table_schema = 'public'
144
144
  AND t.table_type = 'BASE TABLE'
145
+ -- A partition gets its parent's trigger cloned onto it; track the parent only.
146
+ AND NOT EXISTS (
147
+ SELECT 1 FROM pg_class pc
148
+ JOIN pg_namespace pn ON pn.oid = pc.relnamespace
149
+ WHERE pn.nspname = t.table_schema AND pc.relname = t.table_name AND pc.relispartition
150
+ )
145
151
  ORDER BY t.table_name
146
152
  `.trim();
147
153
  async function runInstall(args, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezlogs-nextjs",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "EZLogs agent for Next.js — capture HTTP, database, and background-job events as plain-English Action cards.",
5
5
  "license": "MIT",
6
6
  "author": "EZLogs",
@@ -235,7 +235,10 @@ BEGIN
235
235
  resource_id,
236
236
  actor_id, correlation_id
237
237
  ) VALUES (
238
- TG_TABLE_NAME, TG_OP,
238
+ -- The tracked table's name (TG_ARGV[4]), so a partition's rows
239
+ -- show under their parent; triggers attached before 0.4.5 have
240
+ -- no 5th argument.
241
+ COALESCE(NULLIF(TG_ARGV[4], ''), TG_TABLE_NAME), TG_OP,
239
242
  old_json,
240
243
  new_json,
241
244
  resource_id_value,
@@ -295,6 +298,15 @@ DECLARE
295
298
  all_columns text[];
296
299
  trigger_args text;
297
300
  BEGIN
301
+ -- A partition carries the trigger cloned from its parent (which records
302
+ -- rows under the parent's name); that clone can't be replaced here.
303
+ IF EXISTS (
304
+ SELECT 1 FROM pg_class c
305
+ WHERE c.oid = format('public.%I', target_table)::regclass AND c.relispartition
306
+ ) THEN
307
+ RETURN;
308
+ END IF;
309
+
298
310
  -- Detect the table's single-column primary key so the trigger can
299
311
  -- populate `resource_id` correctly regardless of how the customer
300
312
  -- named their PK column. Tables whose PK isn't `id` are a normal
@@ -327,12 +339,17 @@ BEGIN
327
339
  AND a.attnum > 0
328
340
  AND NOT a.attisdropped;
329
341
 
342
+ -- The 5th argument is the table's own name. Postgres clones a
343
+ -- partitioned table's trigger, arguments included, onto every
344
+ -- partition, where TG_TABLE_NAME is the partition
345
+ -- (`events_2026_11`); the argument keeps the parent's name.
330
346
  trigger_args := format(
331
- '%L, %L, %L, %L',
347
+ '%L, %L, %L, %L, %L',
332
348
  COALESCE(pk_column_name, ''),
333
349
  sensitive_columns::text,
334
350
  all_columns::text,
335
- public.ezlogs_patterns_version()
351
+ public.ezlogs_patterns_version(),
352
+ target_table
336
353
  );
337
354
 
338
355
  -- Already attached with exactly these arguments (same PK, columns and