orez 0.1.25 → 0.1.27

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": "orez",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "description": "PGlite-powered zero-sync development backend. No Docker required.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -52,7 +52,7 @@
52
52
  "dependencies": {
53
53
  "@electric-sql/pglite": "^0.3.15",
54
54
  "@electric-sql/pglite-tools": "^0.2.20",
55
- "bedrock-sqlite": "0.1.25",
55
+ "bedrock-sqlite": "0.1.27",
56
56
  "citty": "^0.2.0",
57
57
  "pg-gateway": "0.3.0-beta.4",
58
58
  "pgsql-parser": "^17.9.11",
@@ -17,7 +17,7 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
17
17
  import { getConfig } from '../config'
18
18
  import { startPgProxy } from '../pg-proxy'
19
19
  import { installChangeTracking } from './change-tracker'
20
- import { signalReplicationChange } from './handler'
20
+ import { signalReplicationChange, resetReplicationState } from './handler'
21
21
 
22
22
  import type { Server, AddressInfo } from 'node:net'
23
23
 
@@ -453,6 +453,7 @@ describe('tcp replication', () => {
453
453
  let port: number
454
454
 
455
455
  beforeEach(async () => {
456
+ resetReplicationState()
456
457
  db = new PGlite()
457
458
  await db.waitReady
458
459
 
@@ -675,21 +676,25 @@ describe('tcp replication', () => {
675
676
 
676
677
  await db.exec(`INSERT INTO public.items (name, value) VALUES ('del_target', 99)`)
677
678
  signalReplicationChange()
678
- await replClient.collectStream(1500)
679
+ await replClient.collectStream(2000)
679
680
 
680
681
  await db.exec(`DELETE FROM public.items WHERE name = 'del_target'`)
681
682
  signalReplicationChange()
682
- const stream = await replClient.collectStream(1500)
683
683
 
684
- const decoded: PgOutputMessage[] = []
685
- for (const msg of stream) {
686
- if (msg.type === 0x64) {
687
- const result = decodeCopyData(new Uint8Array(msg.data))
688
- if (result) decoded.push(result)
684
+ const allDecoded: PgOutputMessage[] = []
685
+ const deadline = Date.now() + 5000
686
+ while (Date.now() < deadline) {
687
+ const stream = await replClient.collectStream(500)
688
+ for (const msg of stream) {
689
+ if (msg.type === 0x64) {
690
+ const result = decodeCopyData(new Uint8Array(msg.data))
691
+ if (result) allDecoded.push(result)
692
+ }
689
693
  }
694
+ if (allDecoded.some((m) => m.type === 'Delete')) break
690
695
  }
691
696
 
692
- const del = decoded.find((m) => m.type === 'Delete') as DeleteMessage
697
+ const del = allDecoded.find((m) => m.type === 'Delete') as DeleteMessage
693
698
  expect(del).toBeDefined()
694
699
  const keyValues = del.keyTupleData.columns.map((c) => c.value)
695
700
  expect(keyValues).toContain('del_target')
@@ -725,7 +730,7 @@ describe('tcp replication', () => {
725
730
 
726
731
  // collect until we see both relations (with timeout)
727
732
  const allDecoded: PgOutputMessage[] = []
728
- const deadline = Date.now() + 8000
733
+ const deadline = Date.now() + 10000
729
734
  while (Date.now() < deadline) {
730
735
  const stream = await replClient.collectStream(500)
731
736
  for (const msg of stream) {
@@ -739,6 +744,7 @@ describe('tcp replication', () => {
739
744
  ) as RelationMessage[]
740
745
  const tableNames = relations.map((r) => r.tableName)
741
746
  if (tableNames.includes('items') && tableNames.includes('products')) break
747
+ signalReplicationChange()
742
748
  }
743
749
 
744
750
  const relations = allDecoded.filter((m) => m.type === 'Relation') as RelationMessage[]
@@ -772,18 +778,23 @@ describe('tcp replication', () => {
772
778
  }
773
779
  signalReplicationChange()
774
780
 
775
- // give enough time for all changes to stream
776
- const stream = await replClient.collectStream(2000)
777
-
778
- const decoded: PgOutputMessage[] = []
779
- for (const msg of stream) {
780
- if (msg.type === 0x64) {
781
- const result = decodeCopyData(new Uint8Array(msg.data))
782
- if (result) decoded.push(result)
781
+ // poll until all inserts arrive
782
+ const allDecoded: PgOutputMessage[] = []
783
+ const deadline = Date.now() + 5000
784
+ while (Date.now() < deadline) {
785
+ const stream = await replClient.collectStream(500)
786
+ for (const msg of stream) {
787
+ if (msg.type === 0x64) {
788
+ const result = decodeCopyData(new Uint8Array(msg.data))
789
+ if (result) allDecoded.push(result)
790
+ }
783
791
  }
792
+ const inserts = allDecoded.filter((m) => m.type === 'Insert')
793
+ if (inserts.length >= count) break
794
+ signalReplicationChange()
784
795
  }
785
796
 
786
- const inserts = decoded.filter((m) => m.type === 'Insert')
797
+ const inserts = allDecoded.filter((m) => m.type === 'Insert')
787
798
  expect(inserts.length).toBe(count)
788
799
 
789
800
  replClient.close()
@@ -837,18 +848,24 @@ describe('tcp replication', () => {
837
848
  await dataClient.query(
838
849
  `INSERT INTO public.items (name, value) VALUES ('concurrent', 123)`
839
850
  )
851
+ signalReplicationChange()
840
852
 
841
- // replication stream should pick up the change
842
- const stream = await replClient.collectStream(1200)
843
- const decoded: PgOutputMessage[] = []
844
- for (const msg of stream) {
845
- if (msg.type === 0x64) {
846
- const result = decodeCopyData(new Uint8Array(msg.data))
847
- if (result) decoded.push(result)
853
+ // poll until the replication stream picks up the change
854
+ const allDecoded: PgOutputMessage[] = []
855
+ const deadline = Date.now() + 5000
856
+ while (Date.now() < deadline) {
857
+ const stream = await replClient.collectStream(500)
858
+ for (const msg of stream) {
859
+ if (msg.type === 0x64) {
860
+ const result = decodeCopyData(new Uint8Array(msg.data))
861
+ if (result) allDecoded.push(result)
862
+ }
848
863
  }
864
+ const inserts = allDecoded.filter((m) => m.type === 'Insert')
865
+ if (inserts.length >= 1) break
849
866
  }
850
867
 
851
- const inserts = decoded.filter((m) => m.type === 'Insert') as InsertMessage[]
868
+ const inserts = allDecoded.filter((m) => m.type === 'Insert') as InsertMessage[]
852
869
  expect(inserts.length).toBe(1)
853
870
  const values = inserts[0].tupleData.columns.map((c) => c.value)
854
871
  expect(values).toContain('concurrent')
@@ -18,7 +18,7 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
18
18
  import { getConfig } from '../config'
19
19
  import { startPgProxy } from '../pg-proxy'
20
20
  import { installChangeTracking, resetShardSchemaCache } from './change-tracker'
21
- import { signalReplicationChange } from './handler'
21
+ import { signalReplicationChange, resetReplicationState } from './handler'
22
22
 
23
23
  import type { Server, AddressInfo } from 'node:net'
24
24
 
@@ -448,6 +448,7 @@ describe('zero-cache pgoutput compatibility', { timeout: 30000 }, () => {
448
448
  let port: number
449
449
 
450
450
  beforeEach(async () => {
451
+ resetReplicationState()
451
452
  resetShardSchemaCache()
452
453
  db = new PGlite()
453
454
  await db.waitReady
@@ -84,7 +84,7 @@ describe('shim template generation', () => {
84
84
 
85
85
  for (const shim of [cjs, esm]) {
86
86
  expect(shim).toContain("db.pragma('busy_timeout = 30000')")
87
- expect(shim).toContain("db.pragma('synchronous = normal')")
87
+ expect(shim).toContain("db.pragma('synchronous = off')")
88
88
  }
89
89
  })
90
90
 
@@ -409,7 +409,7 @@ describe('shim contract tests', () => {
409
409
  for (const mode of ['wasm', 'native'] as const) {
410
410
  const shim = generateCjsShim({ mode, bedrockPath: '/path' })
411
411
  expect(shim).toContain("db.pragma('busy_timeout = 30000')")
412
- expect(shim).toContain("db.pragma('synchronous = normal')")
412
+ expect(shim).toContain("db.pragma('synchronous = off')")
413
413
  }
414
414
  })
415
415