graphile-presigned-url-plugin 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/download-url-field.d.ts +1 -0
- package/download-url-field.js +6 -8
- package/esm/download-url-field.d.ts +1 -0
- package/esm/download-url-field.js +7 -9
- package/esm/index.d.ts +6 -5
- package/esm/index.js +6 -5
- package/esm/plugin.d.ts +12 -8
- package/esm/plugin.js +343 -312
- package/esm/s3-signer.d.ts +9 -2
- package/esm/s3-signer.js +16 -3
- package/esm/storage-module-cache.d.ts +33 -0
- package/esm/storage-module-cache.js +45 -0
- package/index.d.ts +6 -5
- package/index.js +8 -4
- package/package.json +4 -4
- package/plugin.d.ts +12 -8
- package/plugin.js +341 -310
- package/s3-signer.d.ts +9 -2
- package/s3-signer.js +16 -2
- package/storage-module-cache.d.ts +33 -0
- package/storage-module-cache.js +47 -0
package/s3-signer.d.ts
CHANGED
|
@@ -28,9 +28,16 @@ export declare function generatePresignedPutUrl(s3Config: S3Config, key: string,
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function generatePresignedGetUrl(s3Config: S3Config, key: string, expiresIn?: number, filename?: string): Promise<string>;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Delete an object from S3.
|
|
32
|
+
*
|
|
33
|
+
* Idempotent — deleting a non-existent key is a no-op (S3 returns 204).
|
|
32
34
|
*
|
|
33
|
-
*
|
|
35
|
+
* @param s3Config - S3 client and bucket configuration
|
|
36
|
+
* @param key - S3 object key to delete
|
|
37
|
+
*/
|
|
38
|
+
export declare function deleteS3Object(s3Config: S3Config, key: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Check if an object exists in S3 and optionally verify its content-type.
|
|
34
41
|
*
|
|
35
42
|
* @param s3Config - S3 client and bucket configuration
|
|
36
43
|
* @param key - S3 object key
|
package/s3-signer.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generatePresignedPutUrl = generatePresignedPutUrl;
|
|
4
4
|
exports.generatePresignedGetUrl = generatePresignedGetUrl;
|
|
5
|
+
exports.deleteS3Object = deleteS3Object;
|
|
5
6
|
exports.headObject = headObject;
|
|
6
7
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
7
8
|
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
@@ -59,9 +60,22 @@ async function generatePresignedGetUrl(s3Config, key, expiresIn = 3600, filename
|
|
|
59
60
|
return url;
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
|
-
*
|
|
63
|
+
* Delete an object from S3.
|
|
64
|
+
*
|
|
65
|
+
* Idempotent — deleting a non-existent key is a no-op (S3 returns 204).
|
|
63
66
|
*
|
|
64
|
-
*
|
|
67
|
+
* @param s3Config - S3 client and bucket configuration
|
|
68
|
+
* @param key - S3 object key to delete
|
|
69
|
+
*/
|
|
70
|
+
async function deleteS3Object(s3Config, key) {
|
|
71
|
+
await s3Config.client.send(new client_s3_1.DeleteObjectCommand({
|
|
72
|
+
Bucket: s3Config.bucket,
|
|
73
|
+
Key: key,
|
|
74
|
+
}));
|
|
75
|
+
log.debug(`Deleted S3 object: bucket=${s3Config.bucket}, key=${key}`);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if an object exists in S3 and optionally verify its content-type.
|
|
65
79
|
*
|
|
66
80
|
* @param s3Config - S3 client and bucket configuration
|
|
67
81
|
* @param key - S3 object key
|
|
@@ -66,6 +66,39 @@ export declare function resolveStorageModuleByFileId(pgClient: {
|
|
|
66
66
|
bucket_id: string;
|
|
67
67
|
};
|
|
68
68
|
} | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Load all storage modules for a database, using the LRU cache.
|
|
71
|
+
*
|
|
72
|
+
* Returns an array of all StorageModuleConfig entries (app-level + entity-scoped).
|
|
73
|
+
* The result is cached per-database so subsequent calls avoid the DB query.
|
|
74
|
+
*/
|
|
75
|
+
export declare function loadAllStorageModules(pgClient: {
|
|
76
|
+
query: (opts: {
|
|
77
|
+
text: string;
|
|
78
|
+
values?: unknown[];
|
|
79
|
+
}) => Promise<{
|
|
80
|
+
rows: unknown[];
|
|
81
|
+
}>;
|
|
82
|
+
}, databaseId: string): Promise<StorageModuleConfig[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Resolve the storage module config from a PostGraphile pgCodec.
|
|
85
|
+
*
|
|
86
|
+
* Matches the codec's schema + table name against cached storage modules.
|
|
87
|
+
* Works for both files codecs (@storageFiles) and buckets codecs (@storageBuckets).
|
|
88
|
+
*
|
|
89
|
+
* @param pgCodec - The PostGraphile codec (has extensions.pg.schemaName, name)
|
|
90
|
+
* @param allConfigs - All storage module configs for this database
|
|
91
|
+
* @returns The matching StorageModuleConfig or null
|
|
92
|
+
*/
|
|
93
|
+
export declare function resolveStorageConfigFromCodec(pgCodec: {
|
|
94
|
+
name: string;
|
|
95
|
+
extensions?: {
|
|
96
|
+
pg?: {
|
|
97
|
+
schemaName?: string;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
sqlType?: string;
|
|
101
|
+
}, allConfigs: StorageModuleConfig[]): StorageModuleConfig | null;
|
|
69
102
|
/**
|
|
70
103
|
* Resolve bucket metadata for a given database + bucket key, using the LRU cache.
|
|
71
104
|
*
|
package/storage-module-cache.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getStorageModuleConfig = getStorageModuleConfig;
|
|
4
4
|
exports.getStorageModuleConfigForOwner = getStorageModuleConfigForOwner;
|
|
5
5
|
exports.resolveStorageModuleByFileId = resolveStorageModuleByFileId;
|
|
6
|
+
exports.loadAllStorageModules = loadAllStorageModules;
|
|
7
|
+
exports.resolveStorageConfigFromCodec = resolveStorageConfigFromCodec;
|
|
6
8
|
exports.getBucketConfig = getBucketConfig;
|
|
7
9
|
exports.isS3BucketProvisioned = isS3BucketProvisioned;
|
|
8
10
|
exports.markS3BucketProvisioned = markS3BucketProvisioned;
|
|
@@ -267,6 +269,51 @@ async function resolveStorageModuleByFileId(pgClient, databaseId, fileId) {
|
|
|
267
269
|
}
|
|
268
270
|
return null;
|
|
269
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Load all storage modules for a database, using the LRU cache.
|
|
274
|
+
*
|
|
275
|
+
* Returns an array of all StorageModuleConfig entries (app-level + entity-scoped).
|
|
276
|
+
* The result is cached per-database so subsequent calls avoid the DB query.
|
|
277
|
+
*/
|
|
278
|
+
async function loadAllStorageModules(pgClient, databaseId) {
|
|
279
|
+
const cacheKey = `storage:${databaseId}:all-list`;
|
|
280
|
+
const cached = storageModuleCache.get(cacheKey);
|
|
281
|
+
if (cached) {
|
|
282
|
+
return cached._allConfigs;
|
|
283
|
+
}
|
|
284
|
+
log.debug(`Loading all storage modules for database ${databaseId}`);
|
|
285
|
+
const result = await pgClient.query({ text: ALL_STORAGE_MODULES_QUERY, values: [databaseId] });
|
|
286
|
+
const configs = result.rows.map(buildConfig);
|
|
287
|
+
// Cache each individual config by its membership type
|
|
288
|
+
for (const config of configs) {
|
|
289
|
+
const key = config.membershipType === null
|
|
290
|
+
? `storage:${databaseId}:app`
|
|
291
|
+
: `storage:${databaseId}:mt:${config.membershipType}`;
|
|
292
|
+
storageModuleCache.set(key, config);
|
|
293
|
+
}
|
|
294
|
+
// Store the full list under a sentinel key
|
|
295
|
+
const sentinel = { ...configs[0] || {}, _allConfigs: configs };
|
|
296
|
+
storageModuleCache.set(cacheKey, sentinel);
|
|
297
|
+
return configs;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Resolve the storage module config from a PostGraphile pgCodec.
|
|
301
|
+
*
|
|
302
|
+
* Matches the codec's schema + table name against cached storage modules.
|
|
303
|
+
* Works for both files codecs (@storageFiles) and buckets codecs (@storageBuckets).
|
|
304
|
+
*
|
|
305
|
+
* @param pgCodec - The PostGraphile codec (has extensions.pg.schemaName, name)
|
|
306
|
+
* @param allConfigs - All storage module configs for this database
|
|
307
|
+
* @returns The matching StorageModuleConfig or null
|
|
308
|
+
*/
|
|
309
|
+
function resolveStorageConfigFromCodec(pgCodec, allConfigs) {
|
|
310
|
+
const schemaName = pgCodec.extensions?.pg?.schemaName;
|
|
311
|
+
const tableName = pgCodec.name;
|
|
312
|
+
if (!schemaName || !tableName)
|
|
313
|
+
return null;
|
|
314
|
+
return allConfigs.find((c) => (c.filesTableName === tableName && c.schemaName === schemaName) ||
|
|
315
|
+
(c.bucketsTableName === tableName && c.schemaName === schemaName)) || null;
|
|
316
|
+
}
|
|
270
317
|
// --- Bucket metadata cache ---
|
|
271
318
|
/**
|
|
272
319
|
* LRU cache for per-database bucket metadata.
|