@fjall/payload 0.87.9 → 0.87.10
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.
|
@@ -8,50 +8,21 @@
|
|
|
8
8
|
* - Falls back to DATABASE_URL for local development
|
|
9
9
|
*/
|
|
10
10
|
import { postgresAdapter } from "@payloadcms/db-postgres";
|
|
11
|
-
/** The return type of postgresAdapter */
|
|
12
11
|
type PostgresAdapterResult = ReturnType<typeof postgresAdapter>;
|
|
13
|
-
/**
|
|
14
|
-
* Options for the Fjall PostgreSQL adapter.
|
|
15
|
-
*/
|
|
16
12
|
export interface FjallPostgresAdapterOptions {
|
|
17
|
-
/**
|
|
18
|
-
* Path to migrations directory (relative to project root).
|
|
19
|
-
* @default './src/migrations'
|
|
20
|
-
*/
|
|
13
|
+
/** @default './src/migrations' */
|
|
21
14
|
migrationDir?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Pre-compiled migrations for production.
|
|
24
|
-
* Required for Lambda deployments where filesystem migrations aren't available.
|
|
25
|
-
*
|
|
26
|
-
* Pass the migrations array exported from your migrations index file:
|
|
27
|
-
* ```typescript
|
|
28
|
-
* import { migrations } from './migrations'
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* Type is `unknown[]` to avoid contravariance issues with Payload's
|
|
32
|
-
* specific migration argument types (MigrateUpArgs, MigrateDownArgs).
|
|
33
|
-
*/
|
|
15
|
+
/** Required for Lambda - filesystem migrations aren't available at runtime. */
|
|
34
16
|
prodMigrations?: unknown[];
|
|
35
17
|
}
|
|
36
18
|
/**
|
|
37
|
-
* Create a Fjall-configured PostgreSQL adapter for Payload CMS.
|
|
38
|
-
*
|
|
39
|
-
* This is an async function because it needs to fetch credentials from
|
|
40
|
-
* Secrets Manager. Call it with top-level await in your payload.config.ts.
|
|
41
|
-
*
|
|
42
19
|
* @example
|
|
43
20
|
* ```typescript
|
|
44
21
|
* import { fjallPostgresAdapter } from '@fjall/payload'
|
|
45
22
|
* import { migrations } from './migrations'
|
|
46
23
|
*
|
|
47
|
-
* const db = await fjallPostgresAdapter({
|
|
48
|
-
* migrationDir: './src/migrations',
|
|
49
|
-
* prodMigrations: migrations,
|
|
50
|
-
* })
|
|
51
|
-
*
|
|
52
24
|
* export default buildConfig({
|
|
53
|
-
* db,
|
|
54
|
-
* // ...
|
|
25
|
+
* db: await fjallPostgresAdapter({ prodMigrations: migrations }),
|
|
55
26
|
* })
|
|
56
27
|
* ```
|
|
57
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/adapters/postgres.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/adapters/postgres.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,KAAK,qBAAqB,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAgDhE,MAAM,WAAW,2BAA2B;IAC1C,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,EAAE,CAAC;CAC5B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,qBAAqB,CAAC,CAgBhC"}
|
|
@@ -9,24 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { postgresAdapter } from "@payloadcms/db-postgres";
|
|
11
11
|
import { fetchSecretField } from "./secrets.js";
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
// invocations, so caching avoids repeated Secrets Manager calls.
|
|
12
|
+
// Module-level cache: Lambda reuses modules across invocations,
|
|
13
|
+
// so caching avoids repeated Secrets Manager calls.
|
|
15
14
|
let cachedDbUrl = null;
|
|
16
|
-
/**
|
|
17
|
-
* Build the database connection URL from Fjall environment variables.
|
|
18
|
-
*
|
|
19
|
-
* In production (Lambda), uses:
|
|
20
|
-
* - DATABASE_HOST, DATABASE_PORT, DATABASE_NAME from environment
|
|
21
|
-
* - DATABASE_USERNAME/PASSWORD from Secrets Manager via Lambda Extension
|
|
22
|
-
*
|
|
23
|
-
* In development, falls back to DATABASE_URL environment variable.
|
|
24
|
-
*/
|
|
25
15
|
async function getDatabaseUrl() {
|
|
26
|
-
// Return cached URL if already resolved (use explicit null check to handle empty string cache)
|
|
27
16
|
if (cachedDbUrl !== null)
|
|
28
17
|
return cachedDbUrl;
|
|
29
|
-
// If Fjall env vars are present (production Lambda environment)
|
|
30
18
|
if (process.env.DATABASE_HOST) {
|
|
31
19
|
const host = process.env.DATABASE_HOST;
|
|
32
20
|
const port = process.env.DATABASE_PORT || "5432";
|
|
@@ -35,7 +23,6 @@ async function getDatabaseUrl() {
|
|
|
35
23
|
throw new Error("[fjall] DATABASE_NAME environment variable not configured. " +
|
|
36
24
|
"Ensure DATABASE_NAME is set alongside DATABASE_HOST.");
|
|
37
25
|
}
|
|
38
|
-
// Fetch credentials from Lambda Extension
|
|
39
26
|
const user = await fetchSecretField("DATABASE_USERNAME");
|
|
40
27
|
const pass = await fetchSecretField("DATABASE_PASSWORD");
|
|
41
28
|
if (!user || !pass) {
|
|
@@ -45,45 +32,25 @@ async function getDatabaseUrl() {
|
|
|
45
32
|
cachedDbUrl = `postgresql://${user}:${encodeURIComponent(pass)}@${host}:${port}/${name}`;
|
|
46
33
|
return cachedDbUrl;
|
|
47
34
|
}
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
throw new Error("[fjall] DATABASE_URL environment variable not configured. " +
|
|
52
|
-
"Set DATABASE_URL for local development or DATABASE_HOST for production.");
|
|
53
|
-
}
|
|
54
|
-
cachedDbUrl = databaseUrl;
|
|
35
|
+
// Empty string allows builds to succeed without a database (Next.js static generation).
|
|
36
|
+
// At runtime, DATABASE_HOST will be set by Lambda.
|
|
37
|
+
cachedDbUrl = process.env.DATABASE_URL || "";
|
|
55
38
|
return cachedDbUrl;
|
|
56
39
|
}
|
|
57
|
-
|
|
58
|
-
* Get SSL configuration for Aurora PostgreSQL.
|
|
59
|
-
*
|
|
60
|
-
* In production (DATABASE_SSL=true), enables SSL but skips certificate
|
|
61
|
-
* verification since Aurora uses Amazon's internal CA.
|
|
62
|
-
*/
|
|
40
|
+
// Aurora uses Amazon's internal CA, so we skip certificate verification.
|
|
63
41
|
function getSslConfig() {
|
|
64
42
|
return process.env.DATABASE_SSL === "true"
|
|
65
43
|
? { rejectUnauthorized: false }
|
|
66
44
|
: false;
|
|
67
45
|
}
|
|
68
46
|
/**
|
|
69
|
-
* Create a Fjall-configured PostgreSQL adapter for Payload CMS.
|
|
70
|
-
*
|
|
71
|
-
* This is an async function because it needs to fetch credentials from
|
|
72
|
-
* Secrets Manager. Call it with top-level await in your payload.config.ts.
|
|
73
|
-
*
|
|
74
47
|
* @example
|
|
75
48
|
* ```typescript
|
|
76
49
|
* import { fjallPostgresAdapter } from '@fjall/payload'
|
|
77
50
|
* import { migrations } from './migrations'
|
|
78
51
|
*
|
|
79
|
-
* const db = await fjallPostgresAdapter({
|
|
80
|
-
* migrationDir: './src/migrations',
|
|
81
|
-
* prodMigrations: migrations,
|
|
82
|
-
* })
|
|
83
|
-
*
|
|
84
52
|
* export default buildConfig({
|
|
85
|
-
* db,
|
|
86
|
-
* // ...
|
|
53
|
+
* db: await fjallPostgresAdapter({ prodMigrations: migrations }),
|
|
87
54
|
* })
|
|
88
55
|
* ```
|
|
89
56
|
*/
|
|
@@ -96,9 +63,7 @@ export async function fjallPostgresAdapter(options = {}) {
|
|
|
96
63
|
ssl: getSslConfig(),
|
|
97
64
|
},
|
|
98
65
|
migrationDir,
|
|
99
|
-
//
|
|
100
|
-
// exposing Payload's internal migration types. The assertion is safe because
|
|
101
|
-
// migrations are generated by `payload migrate:create` which produces the correct type.
|
|
66
|
+
// Safe assertion: migrations are generated by `payload migrate:create`.
|
|
102
67
|
prodMigrations: prodMigrations,
|
|
103
68
|
});
|
|
104
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/adapters/postgres.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/adapters/postgres.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIhD,gEAAgE;AAChE,oDAAoD;AACpD,IAAI,WAAW,GAAkB,IAAI,CAAC;AAEtC,KAAK,UAAU,cAAc;IAC3B,IAAI,WAAW,KAAK,IAAI;QAAE,OAAO,WAAW,CAAC;IAE7C,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;QACvC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,MAAM,CAAC;QACjD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;QAEvC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CACb,6DAA6D;gBAC3D,sDAAsD,CACzD,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;QACzD,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;QAEzD,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CACb,6DAA6D;gBAC3D,gFAAgF,CACnF,CAAC;QACJ,CAAC;QAED,WAAW,GAAG,gBAAgB,IAAI,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QACzF,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,wFAAwF;IACxF,mDAAmD;IACnD,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;IAC7C,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,yEAAyE;AACzE,SAAS,YAAY;IACnB,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,MAAM;QACxC,CAAC,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE;QAC/B,CAAC,CAAC,KAAK,CAAC;AACZ,CAAC;AASD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,UAAuC,EAAE;IAEzC,MAAM,EAAE,YAAY,GAAG,kBAAkB,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAEtE,MAAM,WAAW,GAAG,MAAM,cAAc,EAAE,CAAC;IAE3C,OAAO,eAAe,CAAC;QACrB,IAAI,EAAE;YACJ,gBAAgB,EAAE,WAAW;YAC7B,GAAG,EAAE,YAAY,EAAE;SACpB;QACD,YAAY;QACZ,wEAAwE;QACxE,cAAc,EAAE,cAEM;KACvB,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fjall/payload",
|
|
3
|
-
"version": "0.87.
|
|
3
|
+
"version": "0.87.10",
|
|
4
4
|
"description": "Fjall AWS adapters and utilities for Payload CMS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"build": "npm run clean && npx tsc",
|
|
20
20
|
"watch": "npm run build && npx tsc-watch",
|
|
21
21
|
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test": "vitest run",
|
|
22
23
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
23
24
|
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
24
25
|
"lint": "eslint src/",
|
|
@@ -47,7 +48,8 @@
|
|
|
47
48
|
"@payloadcms/storage-s3": "^3.73.0",
|
|
48
49
|
"@types/node": "^22.0.0",
|
|
49
50
|
"payload": "^3.73.0",
|
|
50
|
-
"typescript": "^5.8.2"
|
|
51
|
+
"typescript": "^5.8.2",
|
|
52
|
+
"vitest": "^3.2.3"
|
|
51
53
|
},
|
|
52
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "32e5ea12b1de1bd1370edb10f29ad0a6ac9122c7"
|
|
53
55
|
}
|