graphile-bucket-provisioner-plugin 1.15.0 → 1.15.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.
Files changed (3) hide show
  1. package/esm/plugin.js +21 -32
  2. package/package.json +2 -2
  3. package/plugin.js +21 -32
package/esm/plugin.js CHANGED
@@ -143,23 +143,28 @@ async function resolveEntityContext(pgClient, storageModule) {
143
143
  * `packages/ast-plpgsql/deploy/schemas/ast_plpgsql_helpers/procedures/triggers/job_trigger.sql`.
144
144
  * A callable enqueue function beside the trigger would be the durable fix for
145
145
  * this deliberate mirroring, but is out of scope here.
146
+ *
147
+ * The three scope shapes differ only in the payload entries and the identity
148
+ * arguments, so those are the only parts a caller supplies — the identifier,
149
+ * queue, retry, and priority policy exist exactly once.
146
150
  */
151
+ function addJobStatement(payloadEntries, identityArgs) {
152
+ return `SELECT (app_jobs.add_job(
153
+ identifier => 'storage:provision_bucket',
154
+ payload => json_build_object(${payloadEntries}),
155
+ queue_name => 'bucket:' || $1::text,
156
+ max_attempts => 25,
157
+ priority => 0${identityArgs}
158
+ )).id AS id`;
159
+ }
147
160
  async function enqueueReconciliationJob(pgClient, storageModule, bucket) {
148
161
  const scope = storageModule.scope;
149
162
  const entityField = storageModule.entity_field;
150
163
  let text;
151
164
  let values;
152
165
  if (entityField === null) {
153
- text = `SELECT (app_jobs.add_job(
154
- identifier => 'storage:provision_bucket',
155
- payload => json_build_object(
156
- 'id', $1::uuid,
157
- 'scope', $2::text
158
- ),
159
- queue_name => 'bucket:' || $1::text,
160
- max_attempts => 25,
161
- priority => 0
162
- )).id AS id`;
166
+ text = addJobStatement(`'id', $1::uuid,
167
+ 'scope', $2::text`, '');
163
168
  values = [bucket.id, scope];
164
169
  }
165
170
  else if (entityField === 'database_id') {
@@ -167,21 +172,13 @@ async function enqueueReconciliationJob(pgClient, storageModule, bucket) {
167
172
  if (!databaseId) {
168
173
  throw new Error(`STORAGE_BUCKET_SCOPE_KEY_MISSING: bucket ${bucket.id} has no database_id`);
169
174
  }
170
- text = `SELECT (app_jobs.add_job(
171
- identifier => 'storage:provision_bucket',
172
- payload => json_build_object(
173
- 'database_id', $2::uuid,
175
+ text = addJobStatement(`'database_id', $2::uuid,
174
176
  'id', $1::uuid,
175
- 'scope', $3::text
176
- ),
177
+ 'scope', $3::text`, `,
177
178
  db_id => $2,
178
- queue_name => 'bucket:' || $1::text,
179
- max_attempts => 25,
180
- priority => 0,
181
179
  entity_id => $2,
182
180
  organization_id => NULL,
183
- entity_type => $3
184
- )).id AS id`;
181
+ entity_type => $3`);
185
182
  values = [bucket.id, databaseId, scope];
186
183
  }
187
184
  else if (entityField === 'owner_id') {
@@ -193,20 +190,12 @@ async function enqueueReconciliationJob(pgClient, storageModule, bucket) {
193
190
  const orgFunction = context.get_org_fn_schema && context.get_org_fn
194
191
  ? `${QuoteUtils.quoteQualifiedIdentifier(context.get_org_fn_schema, context.get_org_fn)}($3::text, $2::uuid)`
195
192
  : 'NULL';
196
- text = `SELECT (app_jobs.add_job(
197
- identifier => 'storage:provision_bucket',
198
- payload => json_build_object(
199
- 'id', $1::uuid,
193
+ text = addJobStatement(`'id', $1::uuid,
200
194
  'owner_id', $2::uuid,
201
- 'scope', $3::text
202
- ),
203
- queue_name => 'bucket:' || $1::text,
204
- max_attempts => 25,
205
- priority => 0,
195
+ 'scope', $3::text`, `,
206
196
  entity_id => $2,
207
197
  organization_id => ${orgFunction},
208
- entity_type => $3
209
- )).id AS id`;
198
+ entity_type => $3`);
210
199
  values = [bucket.id, ownerId, scope];
211
200
  }
212
201
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphile-bucket-provisioner-plugin",
3
- "version": "1.15.0",
3
+ "version": "1.15.1",
4
4
  "description": "Bucket provisioning plugin for PostGraphile v5 — explicitly provisions S3 buckets via a GraphQL mutation",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "homepage": "https://github.com/constructive-io/constructive",
@@ -58,5 +58,5 @@
58
58
  "@types/node": "^22.19.11",
59
59
  "makage": "^0.3.0"
60
60
  },
61
- "gitHead": "77d58bb93796be91d4e00156bb6847392584d3bc"
61
+ "gitHead": "9a919ff3f7ec90eab2d510bb6682ce5209e53198"
62
62
  }
package/plugin.js CHANGED
@@ -147,23 +147,28 @@ async function resolveEntityContext(pgClient, storageModule) {
147
147
  * `packages/ast-plpgsql/deploy/schemas/ast_plpgsql_helpers/procedures/triggers/job_trigger.sql`.
148
148
  * A callable enqueue function beside the trigger would be the durable fix for
149
149
  * this deliberate mirroring, but is out of scope here.
150
+ *
151
+ * The three scope shapes differ only in the payload entries and the identity
152
+ * arguments, so those are the only parts a caller supplies — the identifier,
153
+ * queue, retry, and priority policy exist exactly once.
150
154
  */
155
+ function addJobStatement(payloadEntries, identityArgs) {
156
+ return `SELECT (app_jobs.add_job(
157
+ identifier => 'storage:provision_bucket',
158
+ payload => json_build_object(${payloadEntries}),
159
+ queue_name => 'bucket:' || $1::text,
160
+ max_attempts => 25,
161
+ priority => 0${identityArgs}
162
+ )).id AS id`;
163
+ }
151
164
  async function enqueueReconciliationJob(pgClient, storageModule, bucket) {
152
165
  const scope = storageModule.scope;
153
166
  const entityField = storageModule.entity_field;
154
167
  let text;
155
168
  let values;
156
169
  if (entityField === null) {
157
- text = `SELECT (app_jobs.add_job(
158
- identifier => 'storage:provision_bucket',
159
- payload => json_build_object(
160
- 'id', $1::uuid,
161
- 'scope', $2::text
162
- ),
163
- queue_name => 'bucket:' || $1::text,
164
- max_attempts => 25,
165
- priority => 0
166
- )).id AS id`;
170
+ text = addJobStatement(`'id', $1::uuid,
171
+ 'scope', $2::text`, '');
167
172
  values = [bucket.id, scope];
168
173
  }
169
174
  else if (entityField === 'database_id') {
@@ -171,21 +176,13 @@ async function enqueueReconciliationJob(pgClient, storageModule, bucket) {
171
176
  if (!databaseId) {
172
177
  throw new Error(`STORAGE_BUCKET_SCOPE_KEY_MISSING: bucket ${bucket.id} has no database_id`);
173
178
  }
174
- text = `SELECT (app_jobs.add_job(
175
- identifier => 'storage:provision_bucket',
176
- payload => json_build_object(
177
- 'database_id', $2::uuid,
179
+ text = addJobStatement(`'database_id', $2::uuid,
178
180
  'id', $1::uuid,
179
- 'scope', $3::text
180
- ),
181
+ 'scope', $3::text`, `,
181
182
  db_id => $2,
182
- queue_name => 'bucket:' || $1::text,
183
- max_attempts => 25,
184
- priority => 0,
185
183
  entity_id => $2,
186
184
  organization_id => NULL,
187
- entity_type => $3
188
- )).id AS id`;
185
+ entity_type => $3`);
189
186
  values = [bucket.id, databaseId, scope];
190
187
  }
191
188
  else if (entityField === 'owner_id') {
@@ -197,20 +194,12 @@ async function enqueueReconciliationJob(pgClient, storageModule, bucket) {
197
194
  const orgFunction = context.get_org_fn_schema && context.get_org_fn
198
195
  ? `${quotes_1.QuoteUtils.quoteQualifiedIdentifier(context.get_org_fn_schema, context.get_org_fn)}($3::text, $2::uuid)`
199
196
  : 'NULL';
200
- text = `SELECT (app_jobs.add_job(
201
- identifier => 'storage:provision_bucket',
202
- payload => json_build_object(
203
- 'id', $1::uuid,
197
+ text = addJobStatement(`'id', $1::uuid,
204
198
  'owner_id', $2::uuid,
205
- 'scope', $3::text
206
- ),
207
- queue_name => 'bucket:' || $1::text,
208
- max_attempts => 25,
209
- priority => 0,
199
+ 'scope', $3::text`, `,
210
200
  entity_id => $2,
211
201
  organization_id => ${orgFunction},
212
- entity_type => $3
213
- )).id AS id`;
202
+ entity_type => $3`);
214
203
  values = [bucket.id, ownerId, scope];
215
204
  }
216
205
  else {