graphile-presigned-url-plugin 0.12.0 → 0.12.1
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/esm/plugin.js +14 -32
- package/package.json +2 -2
- package/plugin.js +12 -30
package/esm/plugin.js
CHANGED
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
* Scope resolution uses the codec's schema/table name matched against
|
|
19
19
|
* cached storage module configs.
|
|
20
20
|
*/
|
|
21
|
-
import {
|
|
21
|
+
import { context as grafastContext, lambda, object } from 'grafast';
|
|
22
22
|
import 'graphile-build';
|
|
23
23
|
import { Logger } from '@pgpmjs/logger';
|
|
24
|
-
import { loadAllStorageModules, resolveStorageConfigFromCodec,
|
|
24
|
+
import { loadAllStorageModules, resolveStorageConfigFromCodec, isS3BucketProvisioned, markS3BucketProvisioned } from './storage-module-cache';
|
|
25
25
|
import { generatePresignedPutUrl, deleteS3Object } from './s3-signer';
|
|
26
26
|
const log = new Logger('graphile-presigned-url:plugin');
|
|
27
27
|
// --- Protocol-level constants (not configurable) ---
|
|
@@ -131,7 +131,12 @@ export function createPresignedUrlPlugin(options) {
|
|
|
131
131
|
}
|
|
132
132
|
const fieldName = typeName.charAt(0).toLowerCase() + typeName.slice(1);
|
|
133
133
|
const hasOwnerId = !!codec.attributes.owner_id;
|
|
134
|
-
|
|
134
|
+
// Find the PgResource for this codec so we can return a proper PgSelectSingleStep
|
|
135
|
+
const bucketResource = Object.values(build.input.pgRegistry.pgResources).find((r) => r.codec === codec && !r.isUnique && !r.isVirtual && !r.parameters);
|
|
136
|
+
if (!bucketResource) {
|
|
137
|
+
log.debug(`Skipping mutation entry point for ${codec.name}: no PgResource found`);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
135
140
|
log.debug(`Adding mutation entry point "${fieldName}" for bucket type ${typeName} (entity-scoped=${hasOwnerId})`);
|
|
136
141
|
newFields[fieldName] = context.fieldWithHooks({ fieldName }, {
|
|
137
142
|
description: `Look up a ${typeName} by key for mutation operations (upload, etc.).`,
|
|
@@ -143,36 +148,13 @@ export function createPresignedUrlPlugin(options) {
|
|
|
143
148
|
: {}),
|
|
144
149
|
},
|
|
145
150
|
plan(_$mutation, fieldArgs) {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
key: $key,
|
|
152
|
-
ownerId: $ownerId,
|
|
153
|
-
withPgClient: $withPgClient,
|
|
154
|
-
pgSettings: $pgSettings,
|
|
155
|
-
});
|
|
156
|
-
const $row = lambda($combined, async (vals) => {
|
|
157
|
-
return vals.withPgClient(vals.pgSettings, async (pgClient) => {
|
|
158
|
-
const databaseId = await resolveDatabaseId(pgClient);
|
|
159
|
-
if (!databaseId)
|
|
160
|
-
throw new Error('DATABASE_NOT_FOUND');
|
|
161
|
-
const allConfigs = await loadAllStorageModules(pgClient, databaseId);
|
|
162
|
-
const storageConfig = resolveStorageConfigFromCodec(capturedCodec, allConfigs);
|
|
163
|
-
if (!storageConfig)
|
|
164
|
-
throw new Error('STORAGE_MODULE_NOT_FOUND');
|
|
165
|
-
const bucket = await getBucketConfig(pgClient, storageConfig, databaseId, vals.key, vals.ownerId ?? undefined);
|
|
166
|
-
if (!bucket)
|
|
167
|
-
throw new Error('BUCKET_NOT_FOUND');
|
|
168
|
-
return bucket;
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
const columnEntries = {};
|
|
172
|
-
for (const col of Object.keys(capturedCodec.attributes)) {
|
|
173
|
-
columnEntries[col] = access($row, col);
|
|
151
|
+
const spec = {
|
|
152
|
+
key: fieldArgs.getRaw('key'),
|
|
153
|
+
};
|
|
154
|
+
if (hasOwnerId) {
|
|
155
|
+
spec.owner_id = fieldArgs.getRaw('ownerId');
|
|
174
156
|
}
|
|
175
|
-
return
|
|
157
|
+
return bucketResource.find(spec).single();
|
|
176
158
|
},
|
|
177
159
|
});
|
|
178
160
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-presigned-url-plugin",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
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",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"@types/node": "^22.19.11",
|
|
61
61
|
"makage": "^0.1.10"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "3491da5ae42fc87daf9b7c39c8735fcae51218a1"
|
|
64
64
|
}
|
package/plugin.js
CHANGED
|
@@ -135,7 +135,12 @@ function createPresignedUrlPlugin(options) {
|
|
|
135
135
|
}
|
|
136
136
|
const fieldName = typeName.charAt(0).toLowerCase() + typeName.slice(1);
|
|
137
137
|
const hasOwnerId = !!codec.attributes.owner_id;
|
|
138
|
-
|
|
138
|
+
// Find the PgResource for this codec so we can return a proper PgSelectSingleStep
|
|
139
|
+
const bucketResource = Object.values(build.input.pgRegistry.pgResources).find((r) => r.codec === codec && !r.isUnique && !r.isVirtual && !r.parameters);
|
|
140
|
+
if (!bucketResource) {
|
|
141
|
+
log.debug(`Skipping mutation entry point for ${codec.name}: no PgResource found`);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
139
144
|
log.debug(`Adding mutation entry point "${fieldName}" for bucket type ${typeName} (entity-scoped=${hasOwnerId})`);
|
|
140
145
|
newFields[fieldName] = context.fieldWithHooks({ fieldName }, {
|
|
141
146
|
description: `Look up a ${typeName} by key for mutation operations (upload, etc.).`,
|
|
@@ -147,36 +152,13 @@ function createPresignedUrlPlugin(options) {
|
|
|
147
152
|
: {}),
|
|
148
153
|
},
|
|
149
154
|
plan(_$mutation, fieldArgs) {
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
key: $key,
|
|
156
|
-
ownerId: $ownerId,
|
|
157
|
-
withPgClient: $withPgClient,
|
|
158
|
-
pgSettings: $pgSettings,
|
|
159
|
-
});
|
|
160
|
-
const $row = (0, grafast_1.lambda)($combined, async (vals) => {
|
|
161
|
-
return vals.withPgClient(vals.pgSettings, async (pgClient) => {
|
|
162
|
-
const databaseId = await resolveDatabaseId(pgClient);
|
|
163
|
-
if (!databaseId)
|
|
164
|
-
throw new Error('DATABASE_NOT_FOUND');
|
|
165
|
-
const allConfigs = await (0, storage_module_cache_1.loadAllStorageModules)(pgClient, databaseId);
|
|
166
|
-
const storageConfig = (0, storage_module_cache_1.resolveStorageConfigFromCodec)(capturedCodec, allConfigs);
|
|
167
|
-
if (!storageConfig)
|
|
168
|
-
throw new Error('STORAGE_MODULE_NOT_FOUND');
|
|
169
|
-
const bucket = await (0, storage_module_cache_1.getBucketConfig)(pgClient, storageConfig, databaseId, vals.key, vals.ownerId ?? undefined);
|
|
170
|
-
if (!bucket)
|
|
171
|
-
throw new Error('BUCKET_NOT_FOUND');
|
|
172
|
-
return bucket;
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
const columnEntries = {};
|
|
176
|
-
for (const col of Object.keys(capturedCodec.attributes)) {
|
|
177
|
-
columnEntries[col] = (0, grafast_1.access)($row, col);
|
|
155
|
+
const spec = {
|
|
156
|
+
key: fieldArgs.getRaw('key'),
|
|
157
|
+
};
|
|
158
|
+
if (hasOwnerId) {
|
|
159
|
+
spec.owner_id = fieldArgs.getRaw('ownerId');
|
|
178
160
|
}
|
|
179
|
-
return (
|
|
161
|
+
return bucketResource.find(spec).single();
|
|
180
162
|
},
|
|
181
163
|
});
|
|
182
164
|
}
|