ezlogs-nextjs 0.3.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -30
- package/bin/install-triggers.cjs +7 -2
- package/dist/actors/index.cjs +4 -4
- package/dist/actors/index.d.cts +1 -1
- package/dist/actors/index.d.ts +1 -1
- package/dist/actors/index.js +1 -1
- package/dist/{chunk-C5OSM557.js → chunk-FCFVIRQF.js} +7 -0
- package/dist/chunk-GI6BM4MR.js +443 -0
- package/dist/{chunk-YX2XPLOA.cjs → chunk-GMHOUAKD.cjs} +63 -34
- package/dist/{chunk-CU45I2WR.js → chunk-MHBS5FEP.js} +48 -20
- package/dist/chunk-MMLQXSSD.cjs +461 -0
- package/dist/{chunk-CE3R7DVB.js → chunk-NINIAL7M.js} +60 -384
- package/dist/{chunk-Y5NSHKWQ.cjs → chunk-NX4EL7BY.cjs} +57 -7
- package/dist/chunk-PS4U2GFJ.cjs +52 -0
- package/dist/chunk-R6IWVTX3.cjs +212 -0
- package/dist/{chunk-V5YNKKTG.cjs → chunk-TWTG5ILJ.cjs} +7 -0
- package/dist/chunk-U22T7QYY.js +200 -0
- package/dist/chunk-YMIGZYFH.js +48 -0
- package/dist/{chunk-WASXTDLW.cjs → chunk-YXZZNZG6.cjs} +71 -403
- package/dist/{chunk-DKRNNI4I.js → chunk-Z2TM3LGG.js} +53 -3
- package/dist/{configuration-OHLNivON.d.ts → configuration-CJ5yKVlP.d.cts} +14 -8
- package/dist/{configuration-OHLNivON.d.cts → configuration-CJ5yKVlP.d.ts} +14 -8
- package/dist/db/drizzle.cjs +5 -4
- package/dist/db/drizzle.js +3 -2
- package/dist/db/postgres-js.cjs +98 -0
- package/dist/db/postgres-js.d.cts +11 -0
- package/dist/db/postgres-js.d.ts +11 -0
- package/dist/db/postgres-js.js +95 -0
- package/dist/db/prisma.cjs +21 -20
- package/dist/db/prisma.d.cts +19 -2
- package/dist/db/prisma.d.ts +19 -2
- package/dist/db/prisma.js +6 -5
- package/dist/db/supabase.cjs +19 -12
- package/dist/db/supabase.d.cts +3 -2
- package/dist/db/supabase.d.ts +3 -2
- package/dist/db/supabase.js +11 -4
- package/dist/index.cjs +596 -165
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +492 -62
- package/dist/jobs/bullmq.cjs +63 -18
- package/dist/jobs/bullmq.d.cts +0 -4
- package/dist/jobs/bullmq.d.ts +0 -4
- package/dist/jobs/bullmq.js +59 -14
- package/dist/jobs/inngest.cjs +61 -24
- package/dist/jobs/inngest.d.cts +5 -1
- package/dist/jobs/inngest.d.ts +5 -1
- package/dist/jobs/inngest.js +55 -18
- package/dist/jobs/supabase-queues.cjs +17 -15
- package/dist/jobs/supabase-queues.d.cts +1 -1
- package/dist/jobs/supabase-queues.d.ts +1 -1
- package/dist/jobs/supabase-queues.js +15 -13
- package/dist/jobs/trigger.cjs +11 -12
- package/dist/jobs/trigger.d.cts +4 -3
- package/dist/jobs/trigger.d.ts +4 -3
- package/dist/jobs/trigger.js +7 -8
- package/dist/jobs/upstash-workflow.cjs +43 -35
- package/dist/jobs/upstash-workflow.d.cts +2 -8
- package/dist/jobs/upstash-workflow.d.ts +2 -8
- package/dist/jobs/upstash-workflow.js +38 -30
- package/dist/nextjs-plugin/index.cjs +39 -3
- package/dist/nextjs-plugin/index.d.cts +8 -1
- package/dist/nextjs-plugin/index.d.ts +8 -1
- package/dist/nextjs-plugin/index.js +39 -3
- package/dist/nextjs-plugin/loader.cjs +41 -3
- package/dist/nextjs-plugin/loader.d.cts +1 -0
- package/dist/nextjs-plugin/loader.d.ts +1 -0
- package/dist/nextjs-plugin/loader.js +42 -4
- package/dist/triggers/index.cjs +145 -92
- package/dist/triggers/index.d.cts +20 -5
- package/dist/triggers/index.d.ts +20 -5
- package/dist/triggers/index.js +125 -82
- package/package.json +11 -1
- package/sql/postgres/00_install.sql +1 -1
- package/dist/chunk-UQHEW6ER.js +0 -119
- package/dist/chunk-UWHYJH4M.cjs +0 -126
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import '../chunk-SIAA4J6H.js';
|
|
2
2
|
import { resolve, dirname } from 'path';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
import { createRequire } from 'module';
|
|
3
5
|
import { fileURLToPath } from 'url';
|
|
4
6
|
|
|
5
7
|
var INLINE_ROUTE_FILENAMES = [
|
|
@@ -11,7 +13,8 @@ var INLINE_ROUTE_FILENAMES = [
|
|
|
11
13
|
"default",
|
|
12
14
|
"not-found"
|
|
13
15
|
];
|
|
14
|
-
function withEzlogsConfig(
|
|
16
|
+
function withEzlogsConfig(userConfig) {
|
|
17
|
+
const nextConfig = userConfig ?? {};
|
|
15
18
|
const userWebpack = nextConfig.webpack;
|
|
16
19
|
const loaderPath = resolveLoaderPath();
|
|
17
20
|
return {
|
|
@@ -33,7 +36,8 @@ function withEzlogsConfig(nextConfig = {}) {
|
|
|
33
36
|
if (!options.isServer) return merged;
|
|
34
37
|
return installLoaders(merged, options);
|
|
35
38
|
},
|
|
36
|
-
|
|
39
|
+
// Next loads next.config from the project directory.
|
|
40
|
+
turbopack: mergeTurbopackConfig(nextConfig.turbopack, loaderPath, process.cwd())
|
|
37
41
|
};
|
|
38
42
|
}
|
|
39
43
|
function mergeServerExternalPackages(user) {
|
|
@@ -42,7 +46,8 @@ function mergeServerExternalPackages(user) {
|
|
|
42
46
|
if (user.includes(ezlogsPkg)) return [...user];
|
|
43
47
|
return [...user, ezlogsPkg];
|
|
44
48
|
}
|
|
45
|
-
function mergeTurbopackConfig(userTurbopack, loaderPath) {
|
|
49
|
+
function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
50
|
+
const wrapProxy = nextMajorVersion(projectDir) >= 16;
|
|
46
51
|
const ezlogsRules = {};
|
|
47
52
|
for (const ext of ["ts", "tsx", "js", "jsx"]) {
|
|
48
53
|
ezlogsRules[`**/{app,src/app}/**/route.${ext}`] = {
|
|
@@ -85,6 +90,17 @@ function mergeTurbopackConfig(userTurbopack, loaderPath) {
|
|
|
85
90
|
],
|
|
86
91
|
as: `*.${ext}`
|
|
87
92
|
};
|
|
93
|
+
if (wrapProxy) {
|
|
94
|
+
ezlogsRules[`**/proxy.${ext}`] = {
|
|
95
|
+
condition: { not: "browser" },
|
|
96
|
+
loaders: [
|
|
97
|
+
{
|
|
98
|
+
loader: loaderPath,
|
|
99
|
+
options: { kind: "proxy", projectDir }
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
};
|
|
103
|
+
}
|
|
88
104
|
const actionGlobs = [
|
|
89
105
|
`**/{actions,src/actions}/**/*.${ext}`,
|
|
90
106
|
`**/{app,src/app}/**/actions.${ext}`,
|
|
@@ -178,6 +194,17 @@ function installLoaders(config, context) {
|
|
|
178
194
|
}
|
|
179
195
|
]
|
|
180
196
|
});
|
|
197
|
+
if (nextMajorVersion(projectDir) >= 16) {
|
|
198
|
+
newRules.push({
|
|
199
|
+
test: new RegExp(`^${escapeRegex(projectDir)}[/\\\\](src[/\\\\])?proxy\\.(${extPattern})$`),
|
|
200
|
+
use: [
|
|
201
|
+
{
|
|
202
|
+
loader: loaderPath,
|
|
203
|
+
options: { kind: "proxy", projectDir }
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
});
|
|
207
|
+
}
|
|
181
208
|
const actionsActionsDir = resolve(projectDir, "actions");
|
|
182
209
|
const srcActionsDir = resolve(projectDir, "src/actions");
|
|
183
210
|
const appActionsDir = resolve(projectDir, "app/actions");
|
|
@@ -240,6 +267,15 @@ function resolveLoaderPath() {
|
|
|
240
267
|
const here = typeof __dirname === "string" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
241
268
|
return resolve(here, "loader.cjs");
|
|
242
269
|
}
|
|
270
|
+
function nextMajorVersion(projectDir) {
|
|
271
|
+
try {
|
|
272
|
+
const req = createRequire(resolve(projectDir, "package.json"));
|
|
273
|
+
const pkg = JSON.parse(readFileSync(req.resolve("next/package.json"), "utf8"));
|
|
274
|
+
return Number.parseInt(pkg.version ?? "", 10) || 0;
|
|
275
|
+
} catch {
|
|
276
|
+
return 0;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
243
279
|
function escapeRegex(input) {
|
|
244
280
|
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
245
281
|
}
|
|
@@ -15766,6 +15766,10 @@ function loaderImpl(source) {
|
|
|
15766
15766
|
if (kind === "middleware") {
|
|
15767
15767
|
return rewriteMiddleware(source);
|
|
15768
15768
|
}
|
|
15769
|
+
if (kind === "proxy") {
|
|
15770
|
+
const root = options.projectDir ?? this.rootContext ?? process.cwd();
|
|
15771
|
+
return isRootProxyFile(this.resourcePath, root) ? rewriteMiddleware(source, "proxy") : source;
|
|
15772
|
+
}
|
|
15769
15773
|
if (kind === "server-action") {
|
|
15770
15774
|
const withSupabase = rewriteSupabaseFactoryImports(source);
|
|
15771
15775
|
return rewriteServerActionFile(withSupabase);
|
|
@@ -15791,6 +15795,9 @@ function rewriteAppRoute(source, routeModulePath) {
|
|
|
15791
15795
|
rewritten = renamed.source;
|
|
15792
15796
|
}
|
|
15793
15797
|
}
|
|
15798
|
+
const destructured = renameDestructuredExports(rewritten);
|
|
15799
|
+
rewritten = destructured.source;
|
|
15800
|
+
for (const method of destructured.methods) detected.add(method);
|
|
15794
15801
|
if (detected.size === 0) {
|
|
15795
15802
|
return rewriteLocalAliasedRouteExports(source, routeModulePath);
|
|
15796
15803
|
}
|
|
@@ -15852,6 +15859,33 @@ function rewriteLocalAliasedRouteExports(source, routeModulePath) {
|
|
|
15852
15859
|
const after = source.slice(matchedBlock.end);
|
|
15853
15860
|
return `${before}${wrapperLines.join("\n")}${after}`;
|
|
15854
15861
|
}
|
|
15862
|
+
function renameDestructuredExports(source) {
|
|
15863
|
+
const methodSet = new Set(HTTP_METHOD_NAMES);
|
|
15864
|
+
const workflowServe = upstashWorkflowServeNames(source);
|
|
15865
|
+
const methods = [];
|
|
15866
|
+
const out = source.replace(
|
|
15867
|
+
/(^|\n)([ \t]*)export\s+const\s*\{([^}]+)\}\s*=/g,
|
|
15868
|
+
(full, lead, indent, list, offset) => {
|
|
15869
|
+
const names = list.split(",").map((n) => n.trim()).filter(Boolean);
|
|
15870
|
+
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
|
+
methods.push(...names);
|
|
15874
|
+
return `${lead}${indent}const { ${names.map((n) => `${n}: ${ALREADY_WRAPPED_MARKER}${n}`).join(", ")} } =`;
|
|
15875
|
+
}
|
|
15876
|
+
);
|
|
15877
|
+
return { source: out, methods };
|
|
15878
|
+
}
|
|
15879
|
+
function upstashWorkflowServeNames(source) {
|
|
15880
|
+
const names = /* @__PURE__ */ new Set();
|
|
15881
|
+
for (const m of source.matchAll(/import\s*\{([^}]*)\}\s*from\s*["']@upstash\/workflow(?:\/[^"']*)?["']/g)) {
|
|
15882
|
+
for (const spec of m[1].split(",")) {
|
|
15883
|
+
const [imported, local] = spec.trim().split(/\s+as\s+/);
|
|
15884
|
+
if (imported === "serve") names.add((local ?? imported).trim());
|
|
15885
|
+
}
|
|
15886
|
+
}
|
|
15887
|
+
return names;
|
|
15888
|
+
}
|
|
15855
15889
|
var NEVER_WRAP_EXPORTS = /* @__PURE__ */ new Set(["config", "metadata", "generateMetadata"]);
|
|
15856
15890
|
var SUPABASE_FACTORY_IMPORTS = [
|
|
15857
15891
|
{ module: "@supabase/supabase-js", exportName: "createClient" },
|
|
@@ -16118,14 +16152,14 @@ function hasFileLevelUseServer(source) {
|
|
|
16118
16152
|
const head = source.slice(i, i + 14);
|
|
16119
16153
|
return /^["']use server["']/.test(head);
|
|
16120
16154
|
}
|
|
16121
|
-
function rewriteMiddleware(source) {
|
|
16122
|
-
const namedRenamed = renameExport(source,
|
|
16155
|
+
function rewriteMiddleware(source, name = "middleware") {
|
|
16156
|
+
const namedRenamed = renameExport(source, name);
|
|
16123
16157
|
if (namedRenamed.changed) {
|
|
16124
16158
|
const wrapperBlock = [
|
|
16125
16159
|
"",
|
|
16126
16160
|
"// --- ezlogs-nextjs auto-wrap middleware (build-time) ---",
|
|
16127
16161
|
`import { withMiddlewareCapture as __ezlogs_with_mw } from "${PACKAGE_NAME}";`,
|
|
16128
|
-
`export const
|
|
16162
|
+
`export const ${name} = __ezlogs_with_mw(${ALREADY_WRAPPED_MARKER}${name});`,
|
|
16129
16163
|
"// --- end ezlogs-nextjs auto-wrap middleware ---",
|
|
16130
16164
|
""
|
|
16131
16165
|
].join("\n");
|
|
@@ -16145,6 +16179,10 @@ function rewriteMiddleware(source) {
|
|
|
16145
16179
|
}
|
|
16146
16180
|
return source;
|
|
16147
16181
|
}
|
|
16182
|
+
function isRootProxyFile(resourcePath, root) {
|
|
16183
|
+
const rel = path.relative(root, resourcePath).split(path.sep).join("/");
|
|
16184
|
+
return /^(?:src\/)?proxy\.[cm]?[jt]sx?$/.test(rel);
|
|
16185
|
+
}
|
|
16148
16186
|
function rewritePagesApi(source, routeModulePath) {
|
|
16149
16187
|
const renamed = renameDefaultExport(source);
|
|
16150
16188
|
if (!renamed.changed) {
|
|
@@ -11,6 +11,7 @@ interface PitchContext {
|
|
|
11
11
|
data?: Record<string, unknown>;
|
|
12
12
|
emitWarning?: (warning: Error | string) => void;
|
|
13
13
|
getOptions?: () => Record<string, unknown>;
|
|
14
|
+
rootContext?: string;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Loader entry point. Receives the user's source file as a string,
|
|
@@ -11,6 +11,7 @@ interface PitchContext {
|
|
|
11
11
|
data?: Record<string, unknown>;
|
|
12
12
|
emitWarning?: (warning: Error | string) => void;
|
|
13
13
|
getOptions?: () => Record<string, unknown>;
|
|
14
|
+
rootContext?: string;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Loader entry point. Receives the user's source file as a string,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __commonJS } from '../chunk-SIAA4J6H.js';
|
|
2
|
-
import { sep } from 'path';
|
|
2
|
+
import { relative, sep } from 'path';
|
|
3
3
|
|
|
4
4
|
// node_modules/sucrase/dist/parser/tokenizer/keywords.js
|
|
5
5
|
var require_keywords = __commonJS({
|
|
@@ -15762,6 +15762,10 @@ function loaderImpl(source) {
|
|
|
15762
15762
|
if (kind === "middleware") {
|
|
15763
15763
|
return rewriteMiddleware(source);
|
|
15764
15764
|
}
|
|
15765
|
+
if (kind === "proxy") {
|
|
15766
|
+
const root = options.projectDir ?? this.rootContext ?? process.cwd();
|
|
15767
|
+
return isRootProxyFile(this.resourcePath, root) ? rewriteMiddleware(source, "proxy") : source;
|
|
15768
|
+
}
|
|
15765
15769
|
if (kind === "server-action") {
|
|
15766
15770
|
const withSupabase = rewriteSupabaseFactoryImports(source);
|
|
15767
15771
|
return rewriteServerActionFile(withSupabase);
|
|
@@ -15787,6 +15791,9 @@ function rewriteAppRoute(source, routeModulePath) {
|
|
|
15787
15791
|
rewritten = renamed.source;
|
|
15788
15792
|
}
|
|
15789
15793
|
}
|
|
15794
|
+
const destructured = renameDestructuredExports(rewritten);
|
|
15795
|
+
rewritten = destructured.source;
|
|
15796
|
+
for (const method of destructured.methods) detected.add(method);
|
|
15790
15797
|
if (detected.size === 0) {
|
|
15791
15798
|
return rewriteLocalAliasedRouteExports(source, routeModulePath);
|
|
15792
15799
|
}
|
|
@@ -15848,6 +15855,33 @@ function rewriteLocalAliasedRouteExports(source, routeModulePath) {
|
|
|
15848
15855
|
const after = source.slice(matchedBlock.end);
|
|
15849
15856
|
return `${before}${wrapperLines.join("\n")}${after}`;
|
|
15850
15857
|
}
|
|
15858
|
+
function renameDestructuredExports(source) {
|
|
15859
|
+
const methodSet = new Set(HTTP_METHOD_NAMES);
|
|
15860
|
+
const workflowServe = upstashWorkflowServeNames(source);
|
|
15861
|
+
const methods = [];
|
|
15862
|
+
const out = source.replace(
|
|
15863
|
+
/(^|\n)([ \t]*)export\s+const\s*\{([^}]+)\}\s*=/g,
|
|
15864
|
+
(full, lead, indent, list, offset) => {
|
|
15865
|
+
const names = list.split(",").map((n) => n.trim()).filter(Boolean);
|
|
15866
|
+
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
|
+
methods.push(...names);
|
|
15870
|
+
return `${lead}${indent}const { ${names.map((n) => `${n}: ${ALREADY_WRAPPED_MARKER}${n}`).join(", ")} } =`;
|
|
15871
|
+
}
|
|
15872
|
+
);
|
|
15873
|
+
return { source: out, methods };
|
|
15874
|
+
}
|
|
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());
|
|
15881
|
+
}
|
|
15882
|
+
}
|
|
15883
|
+
return names;
|
|
15884
|
+
}
|
|
15851
15885
|
var NEVER_WRAP_EXPORTS = /* @__PURE__ */ new Set(["config", "metadata", "generateMetadata"]);
|
|
15852
15886
|
var SUPABASE_FACTORY_IMPORTS = [
|
|
15853
15887
|
{ module: "@supabase/supabase-js", exportName: "createClient" },
|
|
@@ -16114,14 +16148,14 @@ function hasFileLevelUseServer(source) {
|
|
|
16114
16148
|
const head = source.slice(i, i + 14);
|
|
16115
16149
|
return /^["']use server["']/.test(head);
|
|
16116
16150
|
}
|
|
16117
|
-
function rewriteMiddleware(source) {
|
|
16118
|
-
const namedRenamed = renameExport(source,
|
|
16151
|
+
function rewriteMiddleware(source, name = "middleware") {
|
|
16152
|
+
const namedRenamed = renameExport(source, name);
|
|
16119
16153
|
if (namedRenamed.changed) {
|
|
16120
16154
|
const wrapperBlock = [
|
|
16121
16155
|
"",
|
|
16122
16156
|
"// --- ezlogs-nextjs auto-wrap middleware (build-time) ---",
|
|
16123
16157
|
`import { withMiddlewareCapture as __ezlogs_with_mw } from "${PACKAGE_NAME}";`,
|
|
16124
|
-
`export const
|
|
16158
|
+
`export const ${name} = __ezlogs_with_mw(${ALREADY_WRAPPED_MARKER}${name});`,
|
|
16125
16159
|
"// --- end ezlogs-nextjs auto-wrap middleware ---",
|
|
16126
16160
|
""
|
|
16127
16161
|
].join("\n");
|
|
@@ -16141,6 +16175,10 @@ function rewriteMiddleware(source) {
|
|
|
16141
16175
|
}
|
|
16142
16176
|
return source;
|
|
16143
16177
|
}
|
|
16178
|
+
function isRootProxyFile(resourcePath, root) {
|
|
16179
|
+
const rel = relative(root, resourcePath).split(sep).join("/");
|
|
16180
|
+
return /^(?:src\/)?proxy\.[cm]?[jt]sx?$/.test(rel);
|
|
16181
|
+
}
|
|
16144
16182
|
function rewritePagesApi(source, routeModulePath) {
|
|
16145
16183
|
const renamed = renameDefaultExport(source);
|
|
16146
16184
|
if (!renamed.changed) {
|
package/dist/triggers/index.cjs
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
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');
|
|
8
|
+
var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
|
|
7
9
|
require('../chunk-ZDSQYCYV.cjs');
|
|
8
10
|
var promises = require('fs/promises');
|
|
9
11
|
var path = require('path');
|
|
10
12
|
var url = require('url');
|
|
13
|
+
var fs = require('fs');
|
|
14
|
+
var module$1 = require('module');
|
|
11
15
|
|
|
12
16
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
13
17
|
var HERE = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
@@ -49,12 +53,14 @@ Usage:
|
|
|
49
53
|
|
|
50
54
|
Options:
|
|
51
55
|
--connection=<url> Database connection string. Defaults to DATABASE_URL
|
|
52
|
-
or POSTGRES_URL from the environment.
|
|
56
|
+
or POSTGRES_URL from the environment (.env, .env.local
|
|
57
|
+
and .env.[mode] are loaded the way Next.js loads them).
|
|
53
58
|
--tables=<a,b,c> Comma-separated list of tables to attach the audit
|
|
54
59
|
trigger to. Idempotent \u2014 re-runnable.
|
|
55
60
|
--tables=auto DEFAULT. Introspect information_schema and track every
|
|
56
|
-
business table in the public schema, minus
|
|
57
|
-
|
|
61
|
+
business table in the public schema, minus migrations,
|
|
62
|
+
internals and auth-session tables (each skipped table
|
|
63
|
+
is listed with the reason).
|
|
58
64
|
--tables=none Install infrastructure only; track no tables.
|
|
59
65
|
Use this when you want full manual control.
|
|
60
66
|
--print Print the SQL that would be applied; do not run it.
|
|
@@ -102,38 +108,44 @@ function escapeSqlIdentifier(name) {
|
|
|
102
108
|
}
|
|
103
109
|
return name;
|
|
104
110
|
}
|
|
105
|
-
var
|
|
106
|
-
...chunkWASXTDLW_cjs.DEFAULT_EXCLUDED_TABLES,
|
|
111
|
+
var NAMED_SKIPS = [
|
|
107
112
|
// Our own audit table — trigger on the audit table would be a loop.
|
|
108
|
-
"ezlogs_audit_log",
|
|
113
|
+
["ezlogs_audit_log", "EZLogs audit log"],
|
|
114
|
+
["_prisma_migrations", "migration history"],
|
|
115
|
+
["schema_migrations", "migration history"],
|
|
116
|
+
["ar_internal_metadata", "Rails internals"],
|
|
109
117
|
// Postgres internals (won't be in public schema, but defensive).
|
|
110
|
-
/^pg_/,
|
|
111
|
-
/^_litestream/,
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
/^
|
|
115
|
-
// ActiveStorage (same).
|
|
116
|
-
/^active_storage_/,
|
|
117
|
-
// ActiveRecord internals.
|
|
118
|
-
"ar_internal_metadata",
|
|
119
|
-
"schema_migrations"
|
|
118
|
+
[/^pg_/, "database internals"],
|
|
119
|
+
[/^_litestream/, "database internals"],
|
|
120
|
+
// Rails 8 infra tables, in apps that share a database with Rails.
|
|
121
|
+
[/^solid_(queue|cache|cable)/, "Rails infrastructure"],
|
|
122
|
+
[/^active_storage_/, "Rails infrastructure"]
|
|
120
123
|
];
|
|
121
|
-
function
|
|
122
|
-
for (const pattern of
|
|
123
|
-
if (typeof pattern === "string")
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
124
|
+
function skipReason(tableName, hasAuthColumns) {
|
|
125
|
+
for (const [pattern, reason] of NAMED_SKIPS) {
|
|
126
|
+
if (typeof pattern === "string" ? tableName === pattern : pattern.test(tableName)) return reason;
|
|
127
|
+
}
|
|
128
|
+
if (chunkMMLQXSSD_cjs.AUTH_SESSION_TABLE_NAMES.test(tableName) && (hasAuthColumns !== false || /verif/i.test(tableName))) {
|
|
129
|
+
return "auth / session store (has token, expiry or session-data columns)";
|
|
128
130
|
}
|
|
129
|
-
return
|
|
131
|
+
return null;
|
|
130
132
|
}
|
|
131
133
|
var DISCOVER_TABLES_SQL = `
|
|
132
|
-
SELECT table_name
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
SELECT t.table_name,
|
|
135
|
+
EXISTS (
|
|
136
|
+
SELECT 1 FROM information_schema.columns c
|
|
137
|
+
WHERE c.table_schema = t.table_schema
|
|
138
|
+
AND c.table_name = t.table_name
|
|
139
|
+
AND (
|
|
140
|
+
c.column_name ILIKE '%token%'
|
|
141
|
+
OR c.column_name ILIKE '%expir%'
|
|
142
|
+
OR lower(replace(c.column_name, '_', '')) IN ('sess', 'data', 'payload', 'lastactivity')
|
|
143
|
+
)
|
|
144
|
+
) AS has_auth_columns
|
|
145
|
+
FROM information_schema.tables t
|
|
146
|
+
WHERE t.table_schema = 'public'
|
|
147
|
+
AND t.table_type = 'BASE TABLE'
|
|
148
|
+
ORDER BY t.table_name
|
|
137
149
|
`.trim();
|
|
138
150
|
async function runInstall(args, options = {}) {
|
|
139
151
|
const out = options.out ?? ((line) => {
|
|
@@ -185,16 +197,17 @@ ${trackingSql}
|
|
|
185
197
|
return 1;
|
|
186
198
|
}
|
|
187
199
|
let tablesToTrack;
|
|
188
|
-
|
|
200
|
+
const skippedTables = [];
|
|
189
201
|
if (args.autoTables) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
} else {
|
|
202
|
+
tablesToTrack = [];
|
|
203
|
+
if (options.query) {
|
|
193
204
|
try {
|
|
194
205
|
const result = await options.query(DISCOVER_TABLES_SQL);
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
206
|
+
for (const row of result.rows) {
|
|
207
|
+
const reason = skipReason(row.table_name, row.has_auth_columns);
|
|
208
|
+
if (reason) skippedTables.push({ table: row.table_name, reason });
|
|
209
|
+
else tablesToTrack.push(row.table_name);
|
|
210
|
+
}
|
|
198
211
|
} catch (error) {
|
|
199
212
|
out(
|
|
200
213
|
`[ezlogs] Could not introspect tables: ${error instanceof Error ? error.message : String(error)}. Pass --tables=<a,b,c> for explicit tracking.`
|
|
@@ -228,97 +241,137 @@ ${trackingSql}
|
|
|
228
241
|
out(
|
|
229
242
|
`[ezlogs] Postgres triggers installed. Tracking ${tablesToTrack.length} table(s): ${tablesToTrack.join(", ")}.`
|
|
230
243
|
);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
244
|
+
out(
|
|
245
|
+
"[ezlogs] Records are named by their name / title / number / label column. To name people's records (users, members), set `displayNameFor` in ezlogs.init (README: Name your records)."
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
if (skippedTables.length > 0) {
|
|
249
|
+
out(
|
|
250
|
+
`[ezlogs] Skipped ${skippedTables.length} table(s):
|
|
251
|
+
` + skippedTables.map((s) => ` - ${s.table}: ${s.reason}`).join("\n") + "\n Track any of them with `SELECT ezlogs_track('table_name')`."
|
|
252
|
+
);
|
|
236
253
|
}
|
|
237
254
|
return 0;
|
|
238
255
|
} catch (error) {
|
|
239
|
-
|
|
256
|
+
chunkTWTG5ILJ_cjs.logger.error(
|
|
240
257
|
`install-triggers failed: ${error instanceof Error ? error.message : String(error)}`
|
|
241
258
|
);
|
|
242
259
|
return 1;
|
|
243
260
|
}
|
|
244
261
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
function getDatabaseContext() {
|
|
248
|
-
const actor = chunkWASXTDLW_cjs.getCurrentActor();
|
|
249
|
-
return {
|
|
250
|
-
actorId: actor && actor.id ? actor.id : null,
|
|
251
|
-
correlationId: chunkWASXTDLW_cjs.current()
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
async function applyDatabaseContext(exec) {
|
|
255
|
-
const actor = chunkWASXTDLW_cjs.getCurrentActor();
|
|
256
|
-
const correlationId = chunkWASXTDLW_cjs.current();
|
|
257
|
-
if (!actor && !correlationId) return;
|
|
262
|
+
function loadEnvFiles(dir, env = process.env) {
|
|
263
|
+
const dev = env.NODE_ENV !== "production";
|
|
258
264
|
try {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
);
|
|
265
|
+
const nextEnv = module$1.createRequire(path.join(dir, "package.json"))("@next/env");
|
|
266
|
+
if (env === process.env) {
|
|
267
|
+
const { loadedEnvFiles = [] } = nextEnv.loadEnvConfig(dir, dev, {
|
|
268
|
+
info: () => {
|
|
269
|
+
},
|
|
270
|
+
error: () => {
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
return loadedEnvFiles.map((f) => f.path);
|
|
267
274
|
}
|
|
268
|
-
} catch
|
|
269
|
-
chunkV5YNKKTG_cjs.logger.debug(
|
|
270
|
-
`applyDatabaseContext: set_config failed, continuing without context: ${err instanceof Error ? err.message : String(err)}`
|
|
271
|
-
);
|
|
275
|
+
} catch {
|
|
272
276
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
await client.query("COMMIT");
|
|
280
|
-
return result;
|
|
281
|
-
} catch (err) {
|
|
277
|
+
const mode = env.NODE_ENV === "test" ? "test" : dev ? "development" : "production";
|
|
278
|
+
const files = [`.env.${mode}.local`, ...mode === "test" ? [] : [".env.local"], `.env.${mode}`, ".env"];
|
|
279
|
+
const loaded = [];
|
|
280
|
+
const parsed = {};
|
|
281
|
+
for (const file of files) {
|
|
282
|
+
let text;
|
|
282
283
|
try {
|
|
283
|
-
|
|
284
|
+
text = fs.readFileSync(path.join(dir, file), "utf8");
|
|
284
285
|
} catch {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
loaded.push(file);
|
|
289
|
+
for (const [key, value] of Object.entries(parseEnvEntries(text))) {
|
|
290
|
+
if (!(key in parsed)) parsed[key] = value;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
294
|
+
const resolve = (key) => {
|
|
295
|
+
if (env[key] !== void 0) return env[key];
|
|
296
|
+
const entry = parsed[key];
|
|
297
|
+
if (!entry || resolving.has(key)) return void 0;
|
|
298
|
+
resolving.add(key);
|
|
299
|
+
const value = entry.expand ? expand(entry.value, resolve) : entry.value;
|
|
300
|
+
resolving.delete(key);
|
|
301
|
+
return value;
|
|
302
|
+
};
|
|
303
|
+
for (const key of Object.keys(parsed)) {
|
|
304
|
+
if (env[key] === void 0) env[key] = resolve(key);
|
|
305
|
+
}
|
|
306
|
+
return loaded;
|
|
307
|
+
}
|
|
308
|
+
function expand(value, lookup) {
|
|
309
|
+
return value.replace(
|
|
310
|
+
/\\\$|\$\{([A-Za-z_][A-Za-z0-9_]*)(?::?-([^}]*))?\}|\$([A-Za-z_][A-Za-z0-9_]*)/g,
|
|
311
|
+
(match, braced, fallback, bare) => {
|
|
312
|
+
if (match === "\\$") return "$";
|
|
313
|
+
const found = lookup(braced ?? bare);
|
|
314
|
+
return found !== void 0 && found !== "" ? found : fallback ?? "";
|
|
285
315
|
}
|
|
286
|
-
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
var LINE = /^\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?$/gm;
|
|
319
|
+
function parseEnvEntries(text) {
|
|
320
|
+
const out = {};
|
|
321
|
+
const src = text.replace(/\r\n?/g, "\n");
|
|
322
|
+
for (const match of src.matchAll(LINE)) {
|
|
323
|
+
let value = (match[2] ?? "").trim();
|
|
324
|
+
const quote = value[0];
|
|
325
|
+
const quoted = (quote === '"' || quote === "'" || quote === "`") && value.endsWith(quote) && value.length > 1;
|
|
326
|
+
if (quoted) value = value.slice(1, -1);
|
|
327
|
+
if (quote === '"' && quoted) value = value.replace(/\\n/g, "\n").replace(/\\r/g, "\r");
|
|
328
|
+
out[match[1]] = { value, expand: !(quoted && quote === "'") };
|
|
287
329
|
}
|
|
330
|
+
return out;
|
|
288
331
|
}
|
|
289
332
|
|
|
290
333
|
Object.defineProperty(exports, "patchPgClient", {
|
|
291
334
|
enumerable: true,
|
|
292
|
-
get: function () { return
|
|
335
|
+
get: function () { return chunkNX4EL7BY_cjs.patchPgClient; }
|
|
336
|
+
});
|
|
337
|
+
Object.defineProperty(exports, "applyDatabaseContext", {
|
|
338
|
+
enumerable: true,
|
|
339
|
+
get: function () { return chunkPS4U2GFJ_cjs.applyDatabaseContext; }
|
|
340
|
+
});
|
|
341
|
+
Object.defineProperty(exports, "getDatabaseContext", {
|
|
342
|
+
enumerable: true,
|
|
343
|
+
get: function () { return chunkPS4U2GFJ_cjs.getDatabaseContext; }
|
|
344
|
+
});
|
|
345
|
+
Object.defineProperty(exports, "withDatabaseContext", {
|
|
346
|
+
enumerable: true,
|
|
347
|
+
get: function () { return chunkPS4U2GFJ_cjs.withDatabaseContext; }
|
|
293
348
|
});
|
|
294
349
|
Object.defineProperty(exports, "detectTriggerTrackedTables", {
|
|
295
350
|
enumerable: true,
|
|
296
|
-
get: function () { return
|
|
351
|
+
get: function () { return chunkGMHOUAKD_cjs.detectTriggerTrackedTables; }
|
|
297
352
|
});
|
|
298
353
|
Object.defineProperty(exports, "emitAuditRows", {
|
|
299
354
|
enumerable: true,
|
|
300
|
-
get: function () { return
|
|
355
|
+
get: function () { return chunkGMHOUAKD_cjs.emitAuditRows; }
|
|
301
356
|
});
|
|
302
357
|
Object.defineProperty(exports, "flushAuditLog", {
|
|
303
358
|
enumerable: true,
|
|
304
|
-
get: function () { return
|
|
359
|
+
get: function () { return chunkGMHOUAKD_cjs.flushAuditLog; }
|
|
305
360
|
});
|
|
306
361
|
Object.defineProperty(exports, "pruneAuditLog", {
|
|
307
362
|
enumerable: true,
|
|
308
|
-
get: function () { return
|
|
363
|
+
get: function () { return chunkGMHOUAKD_cjs.pruneAuditLog; }
|
|
309
364
|
});
|
|
310
365
|
Object.defineProperty(exports, "readAuditRows", {
|
|
311
366
|
enumerable: true,
|
|
312
|
-
get: function () { return
|
|
367
|
+
get: function () { return chunkGMHOUAKD_cjs.readAuditRows; }
|
|
313
368
|
});
|
|
314
369
|
Object.defineProperty(exports, "sweepAuditLog", {
|
|
315
370
|
enumerable: true,
|
|
316
|
-
get: function () { return
|
|
371
|
+
get: function () { return chunkGMHOUAKD_cjs.sweepAuditLog; }
|
|
317
372
|
});
|
|
318
|
-
exports.applyDatabaseContext = applyDatabaseContext;
|
|
319
373
|
exports.buildTrackingSql = buildTrackingSql;
|
|
320
374
|
exports.detectEngine = detectEngine;
|
|
321
|
-
exports.
|
|
375
|
+
exports.loadEnvFiles = loadEnvFiles;
|
|
322
376
|
exports.parseArgs = parseArgs;
|
|
323
377
|
exports.runInstall = runInstall;
|
|
324
|
-
exports.withDatabaseContext = withDatabaseContext;
|