@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/dist/index.js CHANGED
@@ -214,8 +214,8 @@ async function lockAdvisoryKeys(sql, keys) {
214
214
  await sql`
215
215
  SELECT pg_advisory_xact_lock(locks.first_key, locks.second_key)
216
216
  FROM unnest(
217
- ${sql.array(locks.map(([first]) => first))}::integer[],
218
- ${sql.array(locks.map(([, second]) => second))}::integer[]
217
+ ${locks.map(([first]) => first)}::integer[],
218
+ ${locks.map(([, second]) => second)}::integer[]
219
219
  ) WITH ORDINALITY AS locks(first_key, second_key, lock_order)
220
220
  ORDER BY locks.lock_order
221
221
  `;
@@ -524,7 +524,7 @@ class PgAgentApprovalStore {
524
524
  SET reported_in_message_id = NULL
525
525
  WHERE project_id = ${input.projectId}
526
526
  AND thread_id = ${input.threadId}
527
- AND reported_in_message_id = ANY(${tx.array(clearedIds)}::text[])
527
+ AND reported_in_message_id = ANY(${clearedIds}::text[])
528
528
  `;
529
529
  }
530
530
  if (runIds.length === 0)
@@ -533,7 +533,7 @@ class PgAgentApprovalStore {
533
533
  DELETE FROM agent_approvals
534
534
  WHERE project_id = ${input.projectId}
535
535
  AND thread_id = ${input.threadId}
536
- AND run_id = ANY(${tx.array(runIds)}::text[])
536
+ AND run_id = ANY(${runIds}::text[])
537
537
  RETURNING *
538
538
  `;
539
539
  const cancelled = removed.filter((row) => row.status === "pending").map((row) => {
@@ -602,7 +602,7 @@ class PgAgentApprovalStore {
602
602
  const rows = await this.sql`
603
603
  UPDATE agent_approvals SET reported_in_message_id = ${input.messageId}
604
604
  WHERE project_id = ${input.projectId} AND thread_id = ${input.threadId}
605
- AND id = ANY(${this.sql.array(ids)}::text[]) AND reported_in_message_id IS NULL
605
+ AND id = ANY(${ids}::text[]) AND reported_in_message_id IS NULL
606
606
  AND (${input.resuming !== true} OR turn_stopped_at IS NULL)
607
607
  RETURNING id
608
608
  `;
@@ -646,7 +646,7 @@ function listFilter(sql, input) {
646
646
  AND (${runId}::text IS NULL OR run_id = ${runId})
647
647
  AND (${requesterType}::text IS NULL
648
648
  OR (requested_by_type = ${requesterType} AND requested_by_id = ${requesterId}))
649
- AND (${statuses === null}::boolean OR status = ANY(${sql.array([...statuses ?? []])}::text[]))
649
+ AND (${statuses === null}::boolean OR status = ANY(${[...statuses ?? []]}::text[]))
650
650
  AND (${reported}::boolean IS NULL OR (reported_in_message_id IS NOT NULL) = ${reported})
651
651
  `;
652
652
  }
@@ -1795,7 +1795,7 @@ async function readStates(sql, projectId, principalId, threadIds) {
1795
1795
  AND reading.principal_type = 'user'
1796
1796
  AND reading.principal_id = ${principalId}
1797
1797
  WHERE thread.project_id = ${projectId}
1798
- AND thread.id = ANY(${sql.array([...threadIds])}::text[])
1798
+ AND thread.id = ANY(${[...threadIds]}::text[])
1799
1799
  ) AS place
1800
1800
  `;
1801
1801
  return rows.map((row) => ({
@@ -2237,7 +2237,7 @@ class PgAgentRunStore {
2237
2237
  SELECT DISTINCT ON (thread_id) *
2238
2238
  FROM agent_runs
2239
2239
  WHERE project_id = ${input.projectId}
2240
- AND thread_id = ANY(${this.sql.array([...input.threadIds])}::text[])
2240
+ AND thread_id = ANY(${[...input.threadIds]}::text[])
2241
2241
  ORDER BY thread_id, created_at DESC, id DESC
2242
2242
  `;
2243
2243
  return rows.map(rowToRunRecord);
@@ -2654,8 +2654,8 @@ class PgAgentThreadStore {
2654
2654
  message.created_at,
2655
2655
  message.completed_at
2656
2656
  FROM unnest(
2657
- ${tx.array(plan.messages.map((copy) => copy.sourceId))}::text[],
2658
- ${tx.array(plan.messages.map((copy) => copy.id))}::text[]
2657
+ ${plan.messages.map((copy) => copy.sourceId)}::text[],
2658
+ ${plan.messages.map((copy) => copy.id)}::text[]
2659
2659
  ) AS copy(source_id, id)
2660
2660
  JOIN agent_messages AS message
2661
2661
  ON message.project_id = ${input.projectId} AND message.id = copy.source_id
@@ -2689,7 +2689,7 @@ class PgAgentThreadStore {
2689
2689
  SELECT *
2690
2690
  FROM agent_threads
2691
2691
  WHERE project_id = ${params.projectId}
2692
- AND id = ANY(${this.sql.array(ids)}::text[])
2692
+ AND id = ANY(${ids}::text[])
2693
2693
  `;
2694
2694
  const byId = new Map(rows.map((row) => [row.id, row]));
2695
2695
  return ids.flatMap((id) => {
@@ -2934,7 +2934,7 @@ async function selectParticipants(sql, projectId, threadIds) {
2934
2934
  SELECT *
2935
2935
  FROM agent_thread_participants
2936
2936
  WHERE project_id = ${projectId}
2937
- AND thread_id = ANY(${sql.array([...threadIds])}::text[])
2937
+ AND thread_id = ANY(${[...threadIds]}::text[])
2938
2938
  ORDER BY added_at, principal_id COLLATE "C", thread_id COLLATE "C"
2939
2939
  `;
2940
2940
  return rows.map(rowToParticipantRecord);
@@ -2977,7 +2977,7 @@ async function remapCopiedParts(sql, projectId, messageIds, copies) {
2977
2977
  return;
2978
2978
  const rows = await sql`
2979
2979
  SELECT id, parts::text AS parts FROM agent_messages
2980
- WHERE project_id = ${projectId} AND id = ANY(${sql.array([...messageIds])}::text[])
2980
+ WHERE project_id = ${projectId} AND id = ANY(${[...messageIds]}::text[])
2981
2981
  `;
2982
2982
  for (const row of rows) {
2983
2983
  const parts = remapArtifactIds(row.parts, copies);
@@ -16283,7 +16283,7 @@ async function stageSourceRoots(sql, manifest, input) {
16283
16283
  const stored = await sql`
16284
16284
  SELECT root_key, staging_ordinal, deleted FROM ontology_source_roots
16285
16285
  WHERE version_id = ${manifest.version_id}
16286
- AND root_key = ANY(${sql.array(skipped.map((root) => root.rootKey))}::text[])
16286
+ AND root_key = ANY(${skipped.map((root) => root.rootKey)}::text[])
16287
16287
  `;
16288
16288
  const existing = new Map(stored.map((root) => [root.root_key, root]));
16289
16289
  if (skipped.some((root) => {
@@ -17540,7 +17540,7 @@ async function endpoints(sql, versionId, projectId, refs) {
17540
17540
  AND primary_id = requested.key::jsonb->>1
17541
17541
  )
17542
17542
  ) AS exists
17543
- FROM unnest(${sql.array(unique.map((ref) => objectRefKey2(ref)))}::text[]) AS requested(key)
17543
+ FROM unnest(${unique.map((ref) => objectRefKey2(ref))}::text[]) AS requested(key)
17544
17544
  `;
17545
17545
  const existence = new Map(rows.map((row) => [row.key, row.exists]));
17546
17546
  return unique.map((ref) => ({ ref, exists: existence.get(objectRefKey2(ref)) ?? false }));
@@ -18027,7 +18027,7 @@ class PgMaterializationSessions {
18027
18027
  AND (sort_one, sort_two, record_key) > (${after[0]}, ${after[1]}, ${after[2]})
18028
18028
  )
18029
18029
  SELECT sort_one, sort_two, record_key, payload FROM changes
18030
- WHERE ref->>'objectTypeId' = ANY(${this.sql.array([...objectTypeIds])}::text[])
18030
+ WHERE ref->>'objectTypeId' = ANY(${[...objectTypeIds]}::text[])
18031
18031
  OR EXISTS (
18032
18032
  SELECT 1 FROM object_vectors
18033
18033
  WHERE project_id = ${session.header.commit.projectId}
@@ -19106,7 +19106,7 @@ class PgOntologyMaterializationStorage {
19106
19106
  SELECT * FROM ontology_sources
19107
19107
  WHERE project_id = ${projectId}
19108
19108
  AND source_id = ANY(
19109
- ${this.sql.array(expectedSources.map((expected) => expected.source.projectionId))}::text[]
19109
+ ${expectedSources.map((expected) => expected.source.projectionId)}::text[]
19110
19110
  )
19111
19111
  AND status = 'active'
19112
19112
  FOR UPDATE
@@ -19554,7 +19554,7 @@ class PgExecutionStorage {
19554
19554
  async listDescendants(input) {
19555
19555
  if (input.executionIds.length === 0)
19556
19556
  return [];
19557
- const ids = this.sql.array([...new Set(input.executionIds)]);
19557
+ const ids = [...new Set(input.executionIds)];
19558
19558
  const rows = await this.sql`
19559
19559
  WITH RECURSIVE tree(id, parent_id) AS (
19560
19560
  SELECT child.id, child.parent_execution_id
@@ -19657,7 +19657,7 @@ class PgOntologyOutboxStorage {
19657
19657
  JOIN executions
19658
19658
  ON executions.project_id = commits.project_id AND executions.id = commits.execution_id
19659
19659
  WHERE commits.project_id = ${input.projectId}
19660
- AND commits.id = ANY(${sql.array(commitIds)}::text[])
19660
+ AND commits.id = ANY(${commitIds}::text[])
19661
19661
  `;
19662
19662
  const contextOf = new Map(contexts.map((row) => [row.commit_id, outboxEventContext(input.projectId, row)]));
19663
19663
  return claimedOutboxRows(rows.map(claimedOutboxDraft), (commitId) => contextOf.get(commitId));
@@ -19674,7 +19674,7 @@ class PgOntologyOutboxStorage {
19674
19674
  WITH leased AS MATERIALIZED (
19675
19675
  SELECT id FROM ontology_outbox
19676
19676
  WHERE project_id = ${input.projectId}
19677
- AND id = ANY(${sql.array(ids)}::text[])
19677
+ AND id = ANY(${ids}::text[])
19678
19678
  AND lease_id = ${input.leaseId}
19679
19679
  AND lease_expires_at IS NOT NULL
19680
19680
  FOR UPDATE
@@ -19704,7 +19704,7 @@ class PgOntologyOutboxStorage {
19704
19704
  WITH leased AS MATERIALIZED (
19705
19705
  SELECT id FROM ontology_outbox
19706
19706
  WHERE project_id = ${input.projectId}
19707
- AND id = ANY(${sql.array(ids)}::text[])
19707
+ AND id = ANY(${ids}::text[])
19708
19708
  AND lease_id = ${input.leaseId}
19709
19709
  AND lease_expires_at IS NOT NULL
19710
19710
  FOR UPDATE
@@ -20245,8 +20245,8 @@ class PgOntologySourceStorage {
20245
20245
  JOIN ontology_source_rows AS rows ON rows.root_id = roots.id
20246
20246
  WHERE roots.version_id = ${manifest.version_id}
20247
20247
  AND (
20248
- roots.root_key = ANY(${sql.array(rootKeys)}::text[])
20249
- OR roots.staging_ordinal = ANY(${sql.array(ordinals)}::bigint[])
20248
+ roots.root_key = ANY(${rootKeys}::text[])
20249
+ OR roots.staging_ordinal = ANY(${ordinals}::bigint[])
20250
20250
  )
20251
20251
  `;
20252
20252
  return existing.map((row) => sourceStageRow(sourceAssertion(row)));
@@ -20389,7 +20389,7 @@ class PgVectorIndexingStorage {
20389
20389
  if (!input.ids.length)
20390
20390
  return;
20391
20391
  await this.run(async (sql) => {
20392
- await sql`UPDATE object_vector_indexing SET dispatch_at = ${input.nextDispatchAt} WHERE project_id = ${input.projectId} AND id = ANY(${sql.array([...input.ids])}::text[])`;
20392
+ await sql`UPDATE object_vector_indexing SET dispatch_at = ${input.nextDispatchAt} WHERE project_id = ${input.projectId} AND id = ANY(${[...input.ids]}::text[])`;
20393
20393
  });
20394
20394
  }
20395
20395
  async get(input) {
@@ -20749,7 +20749,7 @@ class PgActionRunStorage {
20749
20749
  SELECT *
20750
20750
  FROM action_runs
20751
20751
  WHERE project_id = ${params.projectId}
20752
- AND execution_id = ANY(${this.sql.array(executionIds)}::text[])
20752
+ AND execution_id = ANY(${executionIds}::text[])
20753
20753
  `;
20754
20754
  const byExecution = new Map(rows.map((row) => [row.execution_id, row]));
20755
20755
  return executionIds.flatMap((executionId) => {
@@ -21161,7 +21161,7 @@ class PgActivityStorage {
21161
21161
  FROM activity_visits v
21162
21162
  WHERE v.project_id = ${input.projectId}
21163
21163
  AND v.actor_type = 'user'
21164
- AND v.session_id = ANY(${this.sql.array([...input.sessionIds])}::text[])
21164
+ AND v.session_id = ANY(${[...input.sessionIds]}::text[])
21165
21165
  AND v.user_id = ${input.userId}
21166
21166
  ) ranked
21167
21167
  WHERE position <= ${input.limit}
@@ -21223,7 +21223,7 @@ async function readStoredEvents(sql, input) {
21223
21223
  FROM activity_page_views p
21224
21224
  JOIN activity_visits v ON v.project_id = p.project_id AND v.id = p.visit_id
21225
21225
  WHERE p.project_id = ${input.projectId}
21226
- AND p.id = ANY(${sql.array(ids)}::text[])
21226
+ AND p.id = ANY(${ids}::text[])
21227
21227
  AND v.actor_type = ${input.actor.type}
21228
21228
  AND v.session_id = ${input.sessionId}
21229
21229
  UNION ALL
@@ -21231,7 +21231,7 @@ async function readStoredEvents(sql, input) {
21231
21231
  FROM activity_interactions i
21232
21232
  JOIN activity_visits v ON v.project_id = i.project_id AND v.id = i.visit_id
21233
21233
  WHERE i.project_id = ${input.projectId}
21234
- AND i.id = ANY(${sql.array(ids)}::text[])
21234
+ AND i.id = ANY(${ids}::text[])
21235
21235
  AND v.actor_type = ${input.actor.type}
21236
21236
  AND v.session_id = ${input.sessionId}
21237
21237
  `;
@@ -21633,7 +21633,7 @@ class PgAiUsageStorage {
21633
21633
  const executionIds = [...new Set(input.executionIds)];
21634
21634
  return sql`
21635
21635
  WITH requested(execution_id) AS (
21636
- SELECT * FROM unnest(${sql.array(executionIds)}::text[])
21636
+ SELECT * FROM unnest(${executionIds}::text[])
21637
21637
  )
21638
21638
  SELECT usage.* FROM requested
21639
21639
  JOIN ai_model_call_usage AS usage
@@ -21793,7 +21793,7 @@ class PgAiCostStorage {
21793
21793
  const ids = [...new Set(input.executionIds)];
21794
21794
  const rows = await this.sql`
21795
21795
  WITH requested(execution_id) AS (
21796
- SELECT DISTINCT * FROM unnest(${this.sql.array(ids)}::text[])
21796
+ SELECT DISTINCT * FROM unnest(${ids}::text[])
21797
21797
  )
21798
21798
  SELECT usage.execution_id,
21799
21799
  cost.status,
@@ -23232,7 +23232,7 @@ class PgArtifactStorage {
23232
23232
  async undoTurnWrites(input) {
23233
23233
  return runPgTransaction(this.sql, async (tx) => {
23234
23234
  const { projectId, turnRunId, laterTurnRunIds = [] } = input;
23235
- const later = tx.array([...laterTurnRunIds]);
23235
+ const later = [...laterTurnRunIds];
23236
23236
  await tx`
23237
23237
  SELECT id FROM artifacts
23238
23238
  WHERE project_id = ${projectId} AND id IN (
@@ -23278,7 +23278,7 @@ class PgArtifactStorage {
23278
23278
  }
23279
23279
  if (restored.length > 0) {
23280
23280
  const undone = restored.map(({ artifact }) => artifact.id);
23281
- const turns = tx.array([turnRunId, ...laterTurnRunIds]);
23281
+ const turns = [turnRunId, ...laterTurnRunIds];
23282
23282
  await tx`
23283
23283
  DELETE FROM artifact_restore_points
23284
23284
  WHERE project_id = ${projectId} AND turn_run_id = ANY(${turns}::text[])
@@ -23570,7 +23570,7 @@ class PgArtifactStorage {
23570
23570
  const rows = await this.sql`
23571
23571
  SELECT ${this.sql.unsafe(BOARD_PREVIEW_COLUMNS)} FROM artifact_board_previews
23572
23572
  WHERE project_id = ${input.projectId}
23573
- AND render_key = ANY(${this.sql.array([...new Set(input.renderKeys)])}::text[])
23573
+ AND render_key = ANY(${[...new Set(input.renderKeys)]}::text[])
23574
23574
  ORDER BY render_key COLLATE "C", theme COLLATE "C", size COLLATE "C"
23575
23575
  `;
23576
23576
  return rows.map(parseArtifactBoardPreviewRow);
@@ -24174,7 +24174,7 @@ class PgDatasetIngestPersistence {
24174
24174
  UPDATE dataset_ingest_deliveries
24175
24175
  SET flush_id = ${flushId}
24176
24176
  WHERE project_id = ${projectId} AND dataset_id = ${datasetId}
24177
- AND id = ANY(${this.sql.array([...deliveryIds])}::bigint[])
24177
+ AND id = ANY(${[...deliveryIds]}::bigint[])
24178
24178
  `;
24179
24179
  }
24180
24180
  async listFlush(projectId, datasetId, flushId) {
@@ -24242,7 +24242,7 @@ class PgDatasetIngestPersistence {
24242
24242
  flush_id, flush_started_at, failure_streak, last_flushed_at
24243
24243
  FROM dataset_ingest_state
24244
24244
  WHERE project_id = ${projectId}
24245
- AND (${datasetIds === undefined} OR dataset_id = ANY(${this.sql.array([...datasetIds ?? []])}::text[]))
24245
+ AND (${datasetIds === undefined} OR dataset_id = ANY(${[...datasetIds ?? []]}::text[]))
24246
24246
  `;
24247
24247
  return rows.map(stateFromRow);
24248
24248
  }
@@ -24255,7 +24255,7 @@ class PgDatasetIngestPersistence {
24255
24255
  count(*) FILTER (WHERE rejected_at IS NOT NULL)::text AS rejected
24256
24256
  FROM dataset_ingest_deliveries
24257
24257
  WHERE project_id = ${projectId}
24258
- AND (${datasetIds === undefined} OR dataset_id = ANY(${this.sql.array([...datasetIds ?? []])}::text[]))
24258
+ AND (${datasetIds === undefined} OR dataset_id = ANY(${[...datasetIds ?? []]}::text[]))
24259
24259
  GROUP BY dataset_id
24260
24260
  `;
24261
24261
  return rows.map((row) => ({
@@ -25499,7 +25499,7 @@ class PgProjectionRunStorage {
25499
25499
  WHERE project_id = ${input.projectId}
25500
25500
  AND projection_id = ${run.projection_id}
25501
25501
  AND materialization_protocol = ${"replacement"}
25502
- AND status = ANY(${this.sql.array([...SUPERSEDING_PROJECTION_RUN_STATUSES])}::text[])
25502
+ AND status = ANY(${[...SUPERSEDING_PROJECTION_RUN_STATUSES]}::text[])
25503
25503
  AND dataset_version_created_at COLLATE "C" > ${run.dataset_version_created_at} COLLATE "C"
25504
25504
  ORDER BY dataset_version_created_at COLLATE "C" DESC, id DESC
25505
25505
  LIMIT 1
@@ -26917,7 +26917,7 @@ class PgWorkflowRunStorage {
26917
26917
  SELECT *
26918
26918
  FROM workflow_runs
26919
26919
  WHERE project_id = ${params.projectId}
26920
- AND execution_id = ANY(${this.sql.array(executionIds)}::text[])
26920
+ AND execution_id = ANY(${executionIds}::text[])
26921
26921
  `;
26922
26922
  const byExecution = new Map(rows.map((row) => [row.execution_id, row]));
26923
26923
  return executionIds.flatMap((executionId) => {
@@ -27519,7 +27519,7 @@ class PgShareGrantStorage {
27519
27519
  SELECT *
27520
27520
  FROM share_grants
27521
27521
  WHERE project_id = ${input.projectId}
27522
- AND id = ANY(${this.sql.array(ids)}::text[])
27522
+ AND id = ANY(${ids}::text[])
27523
27523
  `;
27524
27524
  const byId = new Map(rows.map((row) => [row.id, row]));
27525
27525
  return ids.flatMap((id) => {
@@ -27989,4 +27989,4 @@ export {
27989
27989
  migratePostgresStorage
27990
27990
  };
27991
27991
 
27992
- //# debugId=63365A4D0CD9409564756E2164756E21
27992
+ //# debugId=DC1D078F3E8B5D6064756E2164756E21