@syncular/server 0.58.0 → 0.59.0

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 (91) hide show
  1. package/README.md +31 -22
  2. package/dist/admin.js +8 -4
  3. package/dist/blob-handlers.d.ts +25 -31
  4. package/dist/blob-handlers.js +63 -41
  5. package/dist/blob-store.d.ts +42 -24
  6. package/dist/blob-store.js +0 -0
  7. package/dist/bucket-blob-store.d.ts +12 -8
  8. package/dist/bucket-blob-store.js +54 -45
  9. package/dist/bucket-segment-store.js +18 -16
  10. package/dist/content-encoding.d.ts +5 -2
  11. package/dist/content-encoding.js +42 -13
  12. package/dist/context.d.ts +16 -0
  13. package/dist/context.js +21 -1
  14. package/dist/d1-storage.d.ts +14 -98
  15. package/dist/d1-storage.js +223 -1111
  16. package/dist/errors.js +8 -0
  17. package/dist/events.d.ts +1 -1
  18. package/dist/handler.js +135 -103
  19. package/dist/local-authority.d.ts +2 -0
  20. package/dist/local-authority.js +17 -3
  21. package/dist/object-bucket.d.ts +2 -0
  22. package/dist/operations-realtime.js +69 -50
  23. package/dist/pg-executor-pglite.d.ts +5 -6
  24. package/dist/pg-executor-pglite.js +22 -14
  25. package/dist/pg-executor.d.ts +4 -1
  26. package/dist/postgres-storage.d.ts +1 -1
  27. package/dist/postgres-storage.js +182 -105
  28. package/dist/pull.d.ts +28 -20
  29. package/dist/pull.js +85 -87
  30. package/dist/push.js +272 -147
  31. package/dist/realtime.d.ts +68 -28
  32. package/dist/realtime.js +297 -136
  33. package/dist/relational-rows.d.ts +27 -15
  34. package/dist/relational-rows.js +38 -22
  35. package/dist/s3-blob-store.d.ts +11 -12
  36. package/dist/s3-blob-store.js +20 -13
  37. package/dist/s3-object-bucket.d.ts +8 -1
  38. package/dist/s3-object-bucket.js +16 -3
  39. package/dist/schema.d.ts +14 -0
  40. package/dist/schema.js +23 -0
  41. package/dist/scopes.d.ts +6 -2
  42. package/dist/scopes.js +22 -4
  43. package/dist/seed.js +1 -2
  44. package/dist/segment-download.js +18 -4
  45. package/dist/signed-url.d.ts +2 -2
  46. package/dist/signed-url.js +9 -2
  47. package/dist/sigv4.d.ts +8 -2
  48. package/dist/sigv4.js +8 -4
  49. package/dist/sqlite-blob-store.d.ts +1 -1
  50. package/dist/sqlite-blob-store.js +23 -22
  51. package/dist/sqlite-dialect.d.ts +150 -47
  52. package/dist/sqlite-dialect.js +987 -88
  53. package/dist/sqlite-lease-store.js +13 -18
  54. package/dist/sqlite-storage.d.ts +9 -62
  55. package/dist/sqlite-storage.js +293 -1117
  56. package/dist/storage.d.ts +32 -12
  57. package/package.json +2 -2
  58. package/src/admin.ts +16 -2
  59. package/src/blob-handlers.ts +91 -72
  60. package/src/blob-store.ts +0 -0
  61. package/src/bucket-blob-store.ts +75 -48
  62. package/src/bucket-segment-store.ts +20 -15
  63. package/src/content-encoding.ts +48 -16
  64. package/src/context.ts +32 -1
  65. package/src/d1-storage.ts +326 -1692
  66. package/src/errors.ts +8 -0
  67. package/src/events.ts +1 -1
  68. package/src/handler.ts +178 -127
  69. package/src/local-authority.ts +17 -3
  70. package/src/object-bucket.ts +2 -0
  71. package/src/operations-realtime.ts +85 -61
  72. package/src/pg-executor-pglite.ts +27 -23
  73. package/src/pg-executor.ts +5 -1
  74. package/src/postgres-storage.ts +231 -138
  75. package/src/pull.ts +133 -147
  76. package/src/push.ts +356 -205
  77. package/src/realtime.ts +380 -179
  78. package/src/relational-rows.ts +54 -27
  79. package/src/s3-blob-store.ts +23 -13
  80. package/src/s3-object-bucket.ts +20 -2
  81. package/src/schema.ts +31 -0
  82. package/src/scopes.ts +23 -3
  83. package/src/seed.ts +1 -2
  84. package/src/segment-download.ts +25 -4
  85. package/src/signed-url.ts +10 -4
  86. package/src/sigv4.ts +17 -4
  87. package/src/sqlite-blob-store.ts +27 -26
  88. package/src/sqlite-dialect.ts +1607 -114
  89. package/src/sqlite-lease-store.ts +12 -23
  90. package/src/sqlite-storage.ts +360 -1811
  91. package/src/storage.ts +33 -12
@@ -31,7 +31,6 @@ export class SqliteLeaseStore implements LeaseStore {
31
31
  lease_id TEXT NOT NULL, actor_id TEXT NOT NULL,
32
32
  allowed_scopes TEXT NOT NULL,
33
33
  issued_at_ms INTEGER NOT NULL, expires_at_ms INTEGER NOT NULL,
34
- revoked INTEGER NOT NULL DEFAULT 0,
35
34
  PRIMARY KEY (partition, client_id)
36
35
  );
37
36
  CREATE TABLE IF NOT EXISTS sync_lease_revocations(
@@ -57,9 +56,14 @@ export class SqliteLeaseStore implements LeaseStore {
57
56
  },
58
57
  [string, string]
59
58
  >(
60
- `SELECT lease_id, actor_id, allowed_scopes, issued_at_ms,
61
- expires_at_ms, revoked
62
- FROM sync_leases WHERE partition=? AND client_id=?`,
59
+ // §7.3.4: the revocation table is the only record of a revocation, so
60
+ // a revoked id stays revoked whatever its lease row says.
61
+ `SELECT l.lease_id, l.actor_id, l.allowed_scopes, l.issued_at_ms,
62
+ l.expires_at_ms,
63
+ EXISTS (SELECT 1 FROM sync_lease_revocations r
64
+ WHERE r.partition=l.partition
65
+ AND r.lease_id=l.lease_id) AS revoked
66
+ FROM sync_leases l WHERE l.partition=? AND l.client_id=?`,
63
67
  )
64
68
  .get(partition, clientId);
65
69
  if (row === null) return undefined;
@@ -73,15 +77,6 @@ export class SqliteLeaseStore implements LeaseStore {
73
77
  };
74
78
  }
75
79
 
76
- #isRevoked(partition: string, leaseId: string): boolean {
77
- const row = this.db
78
- .query<{ n: number }, [string, string]>(
79
- 'SELECT 1 AS n FROM sync_lease_revocations WHERE partition=? AND lease_id=?',
80
- )
81
- .get(partition, leaseId);
82
- return row !== null;
83
- }
84
-
85
80
  async issue(
86
81
  partition: string,
87
82
  clientId: string,
@@ -94,8 +89,7 @@ export class SqliteLeaseStore implements LeaseStore {
94
89
  const reuse =
95
90
  existing !== undefined &&
96
91
  existing.actorId === actorId &&
97
- !existing.revoked &&
98
- !this.#isRevoked(partition, existing.leaseId);
92
+ !existing.revoked;
99
93
  const leaseId = reuse ? existing.leaseId : this.#newId();
100
94
  const record: LeaseRecord = {
101
95
  leaseId,
@@ -109,13 +103,13 @@ export class SqliteLeaseStore implements LeaseStore {
109
103
  .query(
110
104
  `INSERT INTO sync_leases(
111
105
  partition, client_id, lease_id, actor_id, allowed_scopes,
112
- issued_at_ms, expires_at_ms, revoked
113
- ) VALUES (?,?,?,?,?,?,?,0)
106
+ issued_at_ms, expires_at_ms
107
+ ) VALUES (?,?,?,?,?,?,?)
114
108
  ON CONFLICT(partition, client_id) DO UPDATE SET
115
109
  lease_id=excluded.lease_id, actor_id=excluded.actor_id,
116
110
  allowed_scopes=excluded.allowed_scopes,
117
111
  issued_at_ms=excluded.issued_at_ms,
118
- expires_at_ms=excluded.expires_at_ms, revoked=0`,
112
+ expires_at_ms=excluded.expires_at_ms`,
119
113
  )
120
114
  .run(
121
115
  partition,
@@ -136,10 +130,5 @@ export class SqliteLeaseStore implements LeaseStore {
136
130
  VALUES (?,?)`,
137
131
  )
138
132
  .run(partition, leaseId);
139
- this.db
140
- .query(
141
- 'UPDATE sync_leases SET revoked=1 WHERE partition=? AND lease_id=?',
142
- )
143
- .run(partition, leaseId);
144
133
  }
145
134
  }