graphile-presigned-url-plugin 1.18.0 → 1.18.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.
@@ -21,5 +21,14 @@
21
21
  import 'graphile-build';
22
22
  import type { GraphileConfig } from 'graphile-config';
23
23
  import type { PresignedUrlPluginOptions } from './types';
24
+ /**
25
+ * Creates the downloadUrl computed field plugin.
26
+ *
27
+ * This is a separate plugin from the main presigned URL plugin because it
28
+ * uses the GraphQLObjectType_fields hook (low-level) rather than extendSchema.
29
+ * The downloadUrl field needs to be added dynamically to whatever table is
30
+ * the storage module's files table, which we discover at schema-build time
31
+ * via the `@storageFiles` smart tag.
32
+ */
24
33
  export declare function createDownloadUrlPlugin(options: PresignedUrlPluginOptions): GraphileConfig.Plugin;
25
34
  export default createDownloadUrlPlugin;
@@ -25,6 +25,7 @@ require("graphile-build");
25
25
  const logger_1 = require("@pgpmjs/logger");
26
26
  const grafast_1 = require("grafast");
27
27
  const graphile_storage_registry_1 = require("graphile-storage-registry");
28
+ const physical_bucket_1 = require("./physical-bucket");
28
29
  const request_pg_client_1 = require("./request-pg-client");
29
30
  const s3_signer_1 = require("./s3-signer");
30
31
  const storage_module_cache_1 = require("./storage-module-cache");
@@ -38,37 +39,6 @@ const log = new logger_1.Logger('graphile-presigned-url:download-url');
38
39
  * the storage module's files table, which we discover at schema-build time
39
40
  * via the `@storageFiles` smart tag.
40
41
  */
41
- /**
42
- * Resolve the S3 config from the options. If the option is a lazy getter
43
- * function, call it (and cache the result).
44
- */
45
- function resolveS3(options) {
46
- if (typeof options.s3 === 'function') {
47
- const resolved = options.s3();
48
- options.s3 = resolved;
49
- return resolved;
50
- }
51
- return options.s3;
52
- }
53
- /**
54
- * Build a per-database S3Config for a *known* physical bucket. `physicalName`
55
- * is required — the stored coordinate on the bucket row is the only source;
56
- * no name is ever recomputed here. Same logic as plugin.ts resolveS3ForDatabase.
57
- */
58
- function resolveS3ForDatabase(options, storageConfig, physicalName) {
59
- const globalS3 = resolveS3(options);
60
- const publicUrlPrefix = storageConfig.publicUrlPrefix != null
61
- ? storageConfig.publicUrlPrefix
62
- : globalS3.publicUrlPrefix;
63
- if (physicalName === globalS3.bucket && publicUrlPrefix === globalS3.publicUrlPrefix) {
64
- return globalS3;
65
- }
66
- return {
67
- ...globalS3,
68
- bucket: physicalName,
69
- ...(publicUrlPrefix != null ? { publicUrlPrefix } : {}),
70
- };
71
- }
72
42
  function createDownloadUrlPlugin(options) {
73
43
  return {
74
44
  name: 'PresignedUrlDownloadPlugin',
@@ -113,7 +83,7 @@ function createDownloadUrlPlugin(options) {
113
83
  return (0, grafast_1.lambda)($combined, async ({ key, isPublic, filename, bucketId, withPgClient, pgSettings }) => {
114
84
  if (!key)
115
85
  return null;
116
- let s3ForDb = resolveS3(options);
86
+ let s3ForDb = (0, physical_bucket_1.resolveS3)(options);
117
87
  let downloadUrlExpirySeconds = 3600;
118
88
  try {
119
89
  if (withPgClient && pgSettings) {
@@ -145,7 +115,7 @@ function createDownloadUrlPlugin(options) {
145
115
  return null;
146
116
  }
147
117
  downloadUrlExpirySeconds = resolved.config.downloadUrlExpirySeconds;
148
- s3ForDb = resolveS3ForDatabase(options, resolved.config, resolved.physicalName);
118
+ s3ForDb = (0, physical_bucket_1.resolveS3ForDatabase)(options, resolved.config, resolved.physicalName);
149
119
  }
150
120
  }
151
121
  }
@@ -21,5 +21,14 @@
21
21
  import 'graphile-build';
22
22
  import type { GraphileConfig } from 'graphile-config';
23
23
  import type { PresignedUrlPluginOptions } from './types';
24
+ /**
25
+ * Creates the downloadUrl computed field plugin.
26
+ *
27
+ * This is a separate plugin from the main presigned URL plugin because it
28
+ * uses the GraphQLObjectType_fields hook (low-level) rather than extendSchema.
29
+ * The downloadUrl field needs to be added dynamically to whatever table is
30
+ * the storage module's files table, which we discover at schema-build time
31
+ * via the `@storageFiles` smart tag.
32
+ */
24
33
  export declare function createDownloadUrlPlugin(options: PresignedUrlPluginOptions): GraphileConfig.Plugin;
25
34
  export default createDownloadUrlPlugin;
@@ -22,6 +22,7 @@ import 'graphile-build';
22
22
  import { Logger } from '@pgpmjs/logger';
23
23
  import { context as grafastContext, lambda, object } from 'grafast';
24
24
  import { DOWNLOAD_URL_FIELD } from 'graphile-storage-registry';
25
+ import { resolveS3, resolveS3ForDatabase } from './physical-bucket';
25
26
  import { withRequestPgClient } from './request-pg-client';
26
27
  import { generatePresignedGetUrl } from './s3-signer';
27
28
  import { loadAllStorageModules, resolveStorageConfigFromCodec, storedPhysicalName } from './storage-module-cache';
@@ -35,37 +36,6 @@ const log = new Logger('graphile-presigned-url:download-url');
35
36
  * the storage module's files table, which we discover at schema-build time
36
37
  * via the `@storageFiles` smart tag.
37
38
  */
38
- /**
39
- * Resolve the S3 config from the options. If the option is a lazy getter
40
- * function, call it (and cache the result).
41
- */
42
- function resolveS3(options) {
43
- if (typeof options.s3 === 'function') {
44
- const resolved = options.s3();
45
- options.s3 = resolved;
46
- return resolved;
47
- }
48
- return options.s3;
49
- }
50
- /**
51
- * Build a per-database S3Config for a *known* physical bucket. `physicalName`
52
- * is required — the stored coordinate on the bucket row is the only source;
53
- * no name is ever recomputed here. Same logic as plugin.ts resolveS3ForDatabase.
54
- */
55
- function resolveS3ForDatabase(options, storageConfig, physicalName) {
56
- const globalS3 = resolveS3(options);
57
- const publicUrlPrefix = storageConfig.publicUrlPrefix != null
58
- ? storageConfig.publicUrlPrefix
59
- : globalS3.publicUrlPrefix;
60
- if (physicalName === globalS3.bucket && publicUrlPrefix === globalS3.publicUrlPrefix) {
61
- return globalS3;
62
- }
63
- return {
64
- ...globalS3,
65
- bucket: physicalName,
66
- ...(publicUrlPrefix != null ? { publicUrlPrefix } : {}),
67
- };
68
- }
69
39
  export function createDownloadUrlPlugin(options) {
70
40
  return {
71
41
  name: 'PresignedUrlDownloadPlugin',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphile-presigned-url-plugin",
3
- "version": "1.18.0",
3
+ "version": "1.18.2",
4
4
  "description": "Presigned URL upload plugin for PostGraphile v5 — requestUploadUrl mutation and downloadUrl computed field",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "homepage": "https://github.com/constructive-io/constructive",
@@ -42,11 +42,11 @@
42
42
  "dependencies": {
43
43
  "@aws-sdk/client-s3": "^3.1052.0",
44
44
  "@aws-sdk/s3-request-presigner": "^3.1052.0",
45
- "@pgpmjs/logger": "^2.25.0",
45
+ "@pgpmjs/logger": "^2.25.1",
46
46
  "@pgsql/quotes": "^18.2.4",
47
- "graphile-storage-registry": "^0.1.1",
47
+ "graphile-storage-registry": "^0.1.2",
48
48
  "lru-cache": "^11.2.7",
49
- "mime-bytes": "^0.32.0"
49
+ "mime-bytes": "^0.32.1"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "grafast": "^1.1.1",
@@ -58,9 +58,9 @@
58
58
  "postgraphile": "^5.1.3"
59
59
  },
60
60
  "devDependencies": {
61
- "@constructive-io/s3-utils": "^2.32.0",
61
+ "@constructive-io/s3-utils": "^2.33.0",
62
62
  "@types/node": "^22.19.11",
63
- "makage": "^0.3.0"
63
+ "makage": "^0.8.0"
64
64
  },
65
- "gitHead": "77d58bb93796be91d4e00156bb6847392584d3bc"
65
+ "gitHead": "5e0bfead2856d1a062b495d343a43e543343f9b8"
66
66
  }