@sixb/pg 0.2.6 → 0.2.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sixb/pg",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "PostgreSQL storage provider for Sixb",
5
5
  "keywords": [
6
6
  "sixb",
@@ -40,10 +40,10 @@
40
40
  "postgres": "^3.4.5"
41
41
  },
42
42
  "peerDependencies": {
43
- "@sixb/core": "0.2.6"
43
+ "@sixb/core": "0.2.7"
44
44
  },
45
45
  "devDependencies": {
46
- "@sixb/core": "0.2.6",
46
+ "@sixb/core": "0.2.7",
47
47
  "@types/bun": "latest",
48
48
  "typescript": "^5.7.0"
49
49
  },
@@ -201,7 +201,7 @@ export class PgAgentApprovalStore implements AgentApprovalStore {
201
201
  SET reported_in_message_id = NULL
202
202
  WHERE project_id = ${input.projectId}
203
203
  AND thread_id = ${input.threadId}
204
- AND reported_in_message_id = ANY(${tx.array(clearedIds)}::text[])
204
+ AND reported_in_message_id = ANY(${clearedIds}::text[])
205
205
  `
206
206
  }
207
207
 
@@ -211,7 +211,7 @@ export class PgAgentApprovalStore implements AgentApprovalStore {
211
211
  DELETE FROM agent_approvals
212
212
  WHERE project_id = ${input.projectId}
213
213
  AND thread_id = ${input.threadId}
214
- AND run_id = ANY(${tx.array(runIds)}::text[])
214
+ AND run_id = ANY(${runIds}::text[])
215
215
  RETURNING *
216
216
  `
217
217
 
@@ -306,7 +306,7 @@ export class PgAgentApprovalStore implements AgentApprovalStore {
306
306
  const rows = await this.sql<{ id: string }[]>`
307
307
  UPDATE agent_approvals SET reported_in_message_id = ${input.messageId}
308
308
  WHERE project_id = ${input.projectId} AND thread_id = ${input.threadId}
309
- AND id = ANY(${this.sql.array(ids)}::text[]) AND reported_in_message_id IS NULL
309
+ AND id = ANY(${ids}::text[]) AND reported_in_message_id IS NULL
310
310
  AND (${input.resuming !== true} OR turn_stopped_at IS NULL)
311
311
  RETURNING id
312
312
  `
@@ -362,7 +362,7 @@ function listFilter(sql: SQLClient, input: ListAgentApprovalsInput) {
362
362
  AND (${runId}::text IS NULL OR run_id = ${runId})
363
363
  AND (${requesterType}::text IS NULL
364
364
  OR (requested_by_type = ${requesterType} AND requested_by_id = ${requesterId}))
365
- AND (${statuses === null}::boolean OR status = ANY(${sql.array([...(statuses ?? [])])}::text[]))
365
+ AND (${statuses === null}::boolean OR status = ANY(${[...(statuses ?? [])]}::text[]))
366
366
  AND (${reported}::boolean IS NULL OR (reported_in_message_id IS NOT NULL) = ${reported})
367
367
  `
368
368
  }
@@ -146,7 +146,7 @@ async function readStates(
146
146
  AND reading.principal_type = 'user'
147
147
  AND reading.principal_id = ${principalId}
148
148
  WHERE thread.project_id = ${projectId}
149
- AND thread.id = ANY(${sql.array([...threadIds])}::text[])
149
+ AND thread.id = ANY(${[...threadIds]}::text[])
150
150
  ) AS place
151
151
  `
152
152
 
@@ -500,7 +500,7 @@ export class PgAgentRunStore implements AgentRunStore {
500
500
  SELECT DISTINCT ON (thread_id) *
501
501
  FROM agent_runs
502
502
  WHERE project_id = ${input.projectId}
503
- AND thread_id = ANY(${this.sql.array([...input.threadIds])}::text[])
503
+ AND thread_id = ANY(${[...input.threadIds]}::text[])
504
504
  ORDER BY thread_id, created_at DESC, id DESC
505
505
  `
506
506
 
@@ -299,8 +299,8 @@ export class PgAgentThreadStore implements AgentThreadStore {
299
299
  message.created_at,
300
300
  message.completed_at
301
301
  FROM unnest(
302
- ${tx.array(plan.messages.map((copy) => copy.sourceId))}::text[],
303
- ${tx.array(plan.messages.map((copy) => copy.id))}::text[]
302
+ ${plan.messages.map((copy) => copy.sourceId)}::text[],
303
+ ${plan.messages.map((copy) => copy.id)}::text[]
304
304
  ) AS copy(source_id, id)
305
305
  JOIN agent_messages AS message
306
306
  ON message.project_id = ${input.projectId} AND message.id = copy.source_id
@@ -352,7 +352,7 @@ export class PgAgentThreadStore implements AgentThreadStore {
352
352
  SELECT *
353
353
  FROM agent_threads
354
354
  WHERE project_id = ${params.projectId}
355
- AND id = ANY(${this.sql.array(ids)}::text[])
355
+ AND id = ANY(${ids}::text[])
356
356
  `
357
357
 
358
358
  const byId = new Map(rows.map((row) => [row.id, row]))
@@ -657,7 +657,7 @@ async function selectParticipants(
657
657
  SELECT *
658
658
  FROM agent_thread_participants
659
659
  WHERE project_id = ${projectId}
660
- AND thread_id = ANY(${sql.array([...threadIds])}::text[])
660
+ AND thread_id = ANY(${[...threadIds]}::text[])
661
661
  ORDER BY added_at, principal_id COLLATE "C", thread_id COLLATE "C"
662
662
  `
663
663
 
@@ -712,7 +712,7 @@ async function remapCopiedParts(
712
712
 
713
713
  const rows = await sql<{ id: string; parts: string }[]>`
714
714
  SELECT id, parts::text AS parts FROM agent_messages
715
- WHERE project_id = ${projectId} AND id = ANY(${sql.array([...messageIds])}::text[])
715
+ WHERE project_id = ${projectId} AND id = ANY(${[...messageIds]}::text[])
716
716
  `
717
717
  for (const row of rows) {
718
718
  const parts = remapArtifactIds(row.parts, copies)
@@ -227,7 +227,7 @@ export class PgMaterializationSessions {
227
227
  AND (sort_one, sort_two, record_key) > (${after[0]}, ${after[1]}, ${after[2]})
228
228
  )
229
229
  SELECT sort_one, sort_two, record_key, payload FROM changes
230
- WHERE ref->>'objectTypeId' = ANY(${this.sql.array([...objectTypeIds])}::text[])
230
+ WHERE ref->>'objectTypeId' = ANY(${[...objectTypeIds]}::text[])
231
231
  OR EXISTS (
232
232
  SELECT 1 FROM object_vectors
233
233
  WHERE project_id = ${session.header.commit.projectId}
@@ -373,7 +373,7 @@ export class PgOntologyMaterializationStorage implements OntologyMaterialization
373
373
  SELECT * FROM ontology_sources
374
374
  WHERE project_id = ${projectId}
375
375
  AND source_id = ANY(
376
- ${this.sql.array(expectedSources.map((expected) => expected.source.projectionId))}::text[]
376
+ ${expectedSources.map((expected) => expected.source.projectionId)}::text[]
377
377
  )
378
378
  AND status = 'active'
379
379
  FOR UPDATE
@@ -87,7 +87,7 @@ export class PgOntologyOutboxStorage implements OntologyOutboxStorage {
87
87
  JOIN executions
88
88
  ON executions.project_id = commits.project_id AND executions.id = commits.execution_id
89
89
  WHERE commits.project_id = ${input.projectId}
90
- AND commits.id = ANY(${sql.array(commitIds)}::text[])
90
+ AND commits.id = ANY(${commitIds}::text[])
91
91
  `
92
92
  const contextOf = new Map(
93
93
  contexts.map((row) => [row.commit_id, outboxEventContext(input.projectId, row)])
@@ -106,7 +106,7 @@ export class PgOntologyOutboxStorage implements OntologyOutboxStorage {
106
106
  WITH leased AS MATERIALIZED (
107
107
  SELECT id FROM ontology_outbox
108
108
  WHERE project_id = ${input.projectId}
109
- AND id = ANY(${sql.array(ids)}::text[])
109
+ AND id = ANY(${ids}::text[])
110
110
  AND lease_id = ${input.leaseId}
111
111
  AND lease_expires_at IS NOT NULL
112
112
  FOR UPDATE
@@ -138,7 +138,7 @@ export class PgOntologyOutboxStorage implements OntologyOutboxStorage {
138
138
  WITH leased AS MATERIALIZED (
139
139
  SELECT id FROM ontology_outbox
140
140
  WHERE project_id = ${input.projectId}
141
- AND id = ANY(${sql.array(ids)}::text[])
141
+ AND id = ANY(${ids}::text[])
142
142
  AND lease_id = ${input.leaseId}
143
143
  AND lease_expires_at IS NOT NULL
144
144
  FOR UPDATE
@@ -708,7 +708,7 @@ async function endpoints(
708
708
  AND primary_id = requested.key::jsonb->>1
709
709
  )
710
710
  ) AS exists
711
- FROM unnest(${sql.array(unique.map((ref) => objectRefKey(ref)))}::text[]) AS requested(key)
711
+ FROM unnest(${unique.map((ref) => objectRefKey(ref))}::text[]) AS requested(key)
712
712
  `
713
713
  const existence = new Map(rows.map((row) => [row.key, row.exists] as const))
714
714
  return unique.map((ref) => ({ ref, exists: existence.get(objectRefKey(ref)) ?? false }))
@@ -160,7 +160,7 @@ export async function stageSourceRoots(
160
160
  >`
161
161
  SELECT root_key, staging_ordinal, deleted FROM ontology_source_roots
162
162
  WHERE version_id = ${manifest.version_id}
163
- AND root_key = ANY(${sql.array(skipped.map((root) => root.rootKey))}::text[])
163
+ AND root_key = ANY(${skipped.map((root) => root.rootKey)}::text[])
164
164
  `
165
165
  const existing = new Map(stored.map((root) => [root.root_key, root]))
166
166
  if (
@@ -532,8 +532,8 @@ export class PgOntologySourceStorage implements OntologySourceStorage {
532
532
  JOIN ontology_source_rows AS rows ON rows.root_id = roots.id
533
533
  WHERE roots.version_id = ${manifest.version_id}
534
534
  AND (
535
- roots.root_key = ANY(${sql.array(rootKeys)}::text[])
536
- OR roots.staging_ordinal = ANY(${sql.array(ordinals)}::bigint[])
535
+ roots.root_key = ANY(${rootKeys}::text[])
536
+ OR roots.staging_ordinal = ANY(${ordinals}::bigint[])
537
537
  )
538
538
  `
539
539
  return existing.map((row) => sourceStageRow(sourceAssertion(row)))
@@ -68,7 +68,7 @@ export class PgVectorIndexingStorage implements OntologyVectorIndexingStorage {
68
68
  async dispatched(input: Parameters<OntologyVectorIndexingStorage["dispatched"]>[0]) {
69
69
  if (!input.ids.length) return
70
70
  await this.run(async (sql) => {
71
- await sql`UPDATE object_vector_indexing SET dispatch_at = ${input.nextDispatchAt} WHERE project_id = ${input.projectId} AND id = ANY(${sql.array([...input.ids])}::text[])`
71
+ await sql`UPDATE object_vector_indexing SET dispatch_at = ${input.nextDispatchAt} WHERE project_id = ${input.projectId} AND id = ANY(${[...input.ids]}::text[])`
72
72
  })
73
73
  }
74
74
  async get(input: Parameters<OntologyVectorIndexingStorage["get"]>[0]) {
@@ -149,7 +149,7 @@ export class PgActionRunStorage implements ActionRunStorage {
149
149
  SELECT *
150
150
  FROM action_runs
151
151
  WHERE project_id = ${params.projectId}
152
- AND execution_id = ANY(${this.sql.array(executionIds)}::text[])
152
+ AND execution_id = ANY(${executionIds}::text[])
153
153
  `
154
154
 
155
155
  const byExecution = new Map(rows.map((row) => [row.execution_id, row]))
@@ -302,7 +302,7 @@ export class PgActivityStorage implements ActivityStorage {
302
302
  FROM activity_visits v
303
303
  WHERE v.project_id = ${input.projectId}
304
304
  AND v.actor_type = 'user'
305
- AND v.session_id = ANY(${this.sql.array([...input.sessionIds])}::text[])
305
+ AND v.session_id = ANY(${[...input.sessionIds]}::text[])
306
306
  AND v.user_id = ${input.userId}
307
307
  ) ranked
308
308
  WHERE position <= ${input.limit}
@@ -387,7 +387,7 @@ async function readStoredEvents(
387
387
  FROM activity_page_views p
388
388
  JOIN activity_visits v ON v.project_id = p.project_id AND v.id = p.visit_id
389
389
  WHERE p.project_id = ${input.projectId}
390
- AND p.id = ANY(${sql.array(ids)}::text[])
390
+ AND p.id = ANY(${ids}::text[])
391
391
  AND v.actor_type = ${input.actor.type}
392
392
  AND v.session_id = ${input.sessionId}
393
393
  UNION ALL
@@ -395,7 +395,7 @@ async function readStoredEvents(
395
395
  FROM activity_interactions i
396
396
  JOIN activity_visits v ON v.project_id = i.project_id AND v.id = i.visit_id
397
397
  WHERE i.project_id = ${input.projectId}
398
- AND i.id = ANY(${sql.array(ids)}::text[])
398
+ AND i.id = ANY(${ids}::text[])
399
399
  AND v.actor_type = ${input.actor.type}
400
400
  AND v.session_id = ${input.sessionId}
401
401
  `
@@ -83,7 +83,7 @@ export class PgAiCostStorage implements AiCostStorage {
83
83
  const ids = [...new Set(input.executionIds)]
84
84
  const rows = await this.sql<SummaryRow[]>`
85
85
  WITH requested(execution_id) AS (
86
- SELECT DISTINCT * FROM unnest(${this.sql.array(ids)}::text[])
86
+ SELECT DISTINCT * FROM unnest(${ids}::text[])
87
87
  )
88
88
  SELECT usage.execution_id,
89
89
  cost.status,
@@ -243,7 +243,7 @@ export class PgAiUsageStorage implements AiUsageStorage {
243
243
 
244
244
  return sql<AiUsageRow[]>`
245
245
  WITH requested(execution_id) AS (
246
- SELECT * FROM unnest(${sql.array(executionIds)}::text[])
246
+ SELECT * FROM unnest(${executionIds}::text[])
247
247
  )
248
248
  SELECT usage.* FROM requested
249
249
  JOIN ai_model_call_usage AS usage
@@ -313,7 +313,7 @@ export class PgArtifactStorage implements ArtifactStorage {
313
313
  async undoTurnWrites(input: UndoArtifactTurnInput): Promise<UndoneArtifactTurn> {
314
314
  return runPgTransaction(this.sql, async (tx) => {
315
315
  const { projectId, turnRunId, laterTurnRunIds = [] } = input
316
- const later = tx.array([...laterTurnRunIds])
316
+ const later = [...laterTurnRunIds]
317
317
 
318
318
  // Lock the turn's artifacts first, in id order so two of these never deadlock. A write
319
319
  // holds the same lock, and under READ COMMITTED each statement below then reads a snapshot
@@ -378,7 +378,7 @@ export class PgArtifactStorage implements ArtifactStorage {
378
378
  // undo.
379
379
  if (restored.length > 0) {
380
380
  const undone = restored.map(({ artifact }) => artifact.id)
381
- const turns = tx.array([turnRunId, ...laterTurnRunIds])
381
+ const turns = [turnRunId, ...laterTurnRunIds]
382
382
  await tx`
383
383
  DELETE FROM artifact_restore_points
384
384
  WHERE project_id = ${projectId} AND turn_run_id = ANY(${turns}::text[])
@@ -709,7 +709,7 @@ export class PgArtifactStorage implements ArtifactStorage {
709
709
  const rows = await this.sql<PgRow[]>`
710
710
  SELECT ${this.sql.unsafe(BOARD_PREVIEW_COLUMNS)} FROM artifact_board_previews
711
711
  WHERE project_id = ${input.projectId}
712
- AND render_key = ANY(${this.sql.array([...new Set(input.renderKeys)])}::text[])
712
+ AND render_key = ANY(${[...new Set(input.renderKeys)]}::text[])
713
713
  ORDER BY render_key COLLATE "C", theme COLLATE "C", size COLLATE "C"
714
714
  `
715
715
  return rows.map(parseArtifactBoardPreviewRow)
@@ -143,7 +143,7 @@ class PgDatasetIngestPersistence implements DatasetIngestPersistence {
143
143
  UPDATE dataset_ingest_deliveries
144
144
  SET flush_id = ${flushId}
145
145
  WHERE project_id = ${projectId} AND dataset_id = ${datasetId}
146
- AND id = ANY(${this.sql.array([...deliveryIds])}::bigint[])
146
+ AND id = ANY(${[...deliveryIds]}::bigint[])
147
147
  `
148
148
  }
149
149
 
@@ -240,7 +240,7 @@ class PgDatasetIngestPersistence implements DatasetIngestPersistence {
240
240
  flush_id, flush_started_at, failure_streak, last_flushed_at
241
241
  FROM dataset_ingest_state
242
242
  WHERE project_id = ${projectId}
243
- AND (${datasetIds === undefined} OR dataset_id = ANY(${this.sql.array([...(datasetIds ?? [])])}::text[]))
243
+ AND (${datasetIds === undefined} OR dataset_id = ANY(${[...(datasetIds ?? [])]}::text[]))
244
244
  `
245
245
  return rows.map(stateFromRow)
246
246
  }
@@ -265,7 +265,7 @@ class PgDatasetIngestPersistence implements DatasetIngestPersistence {
265
265
  count(*) FILTER (WHERE rejected_at IS NOT NULL)::text AS rejected
266
266
  FROM dataset_ingest_deliveries
267
267
  WHERE project_id = ${projectId}
268
- AND (${datasetIds === undefined} OR dataset_id = ANY(${this.sql.array([...(datasetIds ?? [])])}::text[]))
268
+ AND (${datasetIds === undefined} OR dataset_id = ANY(${[...(datasetIds ?? [])]}::text[]))
269
269
  GROUP BY dataset_id
270
270
  `
271
271
  return rows.map((row) => ({
@@ -170,7 +170,7 @@ export class PgExecutionStorage implements ExecutionStorage {
170
170
  input: ListExecutionDescendantsInput
171
171
  ): Promise<readonly ExecutionDescendant[]> {
172
172
  if (input.executionIds.length === 0) return []
173
- const ids = this.sql.array([...new Set(input.executionIds)])
173
+ const ids = [...new Set(input.executionIds)]
174
174
 
175
175
  // UNION, not UNION ALL: an execution asked about may sit below another one asked about, and
176
176
  // the walk would otherwise reach what it caused twice.
@@ -516,7 +516,7 @@ export class PgProjectionRunStorage implements ProjectionRunStorage {
516
516
  WHERE project_id = ${input.projectId}
517
517
  AND projection_id = ${run.projection_id}
518
518
  AND materialization_protocol = ${"replacement"}
519
- AND status = ANY(${this.sql.array([...SUPERSEDING_PROJECTION_RUN_STATUSES])}::text[])
519
+ AND status = ANY(${[...SUPERSEDING_PROJECTION_RUN_STATUSES]}::text[])
520
520
  AND dataset_version_created_at COLLATE "C" > ${run.dataset_version_created_at} COLLATE "C"
521
521
  ORDER BY dataset_version_created_at COLLATE "C" DESC, id DESC
522
522
  LIMIT 1
@@ -299,7 +299,7 @@ export class PgWorkflowRunStorage implements WorkflowRunStorage {
299
299
  SELECT *
300
300
  FROM workflow_runs
301
301
  WHERE project_id = ${params.projectId}
302
- AND execution_id = ANY(${this.sql.array(executionIds)}::text[])
302
+ AND execution_id = ANY(${executionIds}::text[])
303
303
  `
304
304
 
305
305
  const byExecution = new Map(rows.map((row) => [row.execution_id, row]))
@@ -96,7 +96,7 @@ export class PgShareGrantStorage implements ShareGrantStorage {
96
96
  SELECT *
97
97
  FROM share_grants
98
98
  WHERE project_id = ${input.projectId}
99
- AND id = ANY(${this.sql.array(ids)}::text[])
99
+ AND id = ANY(${ids}::text[])
100
100
  `
101
101
 
102
102
  const byId = new Map(rows.map((row) => [row.id, row]))
@@ -174,8 +174,8 @@ export async function lockAdvisoryKeys(sql: SQLClient, keys: readonly string[]):
174
174
  await sql`
175
175
  SELECT pg_advisory_xact_lock(locks.first_key, locks.second_key)
176
176
  FROM unnest(
177
- ${sql.array(locks.map(([first]) => first))}::integer[],
178
- ${sql.array(locks.map(([, second]) => second))}::integer[]
177
+ ${locks.map(([first]) => first)}::integer[],
178
+ ${locks.map(([, second]) => second)}::integer[]
179
179
  ) WITH ORDINALITY AS locks(first_key, second_key, lock_order)
180
180
  ORDER BY locks.lock_order
181
181
  `