@pgxsinkit/client 0.2.7 → 0.5.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.
- package/LICENSE +21 -0
- package/LICENSE-APACHE-2.0 +202 -0
- package/NOTICE +81 -0
- package/README.md +11 -3
- package/dist/boot-report.d.ts +11 -8
- package/dist/boot-report.d.ts.map +1 -1
- package/dist/circuits/envelope-to-change.d.ts +39 -0
- package/dist/circuits/envelope-to-change.d.ts.map +1 -0
- package/dist/circuits/group-sync.d.ts +123 -0
- package/dist/circuits/group-sync.d.ts.map +1 -0
- package/dist/circuits/shape-group.d.ts +77 -0
- package/dist/circuits/shape-group.d.ts.map +1 -0
- package/dist/circuits/stream-inbox.d.ts +126 -0
- package/dist/circuits/stream-inbox.d.ts.map +1 -0
- package/dist/circuits/stream-source.d.ts +96 -0
- package/dist/circuits/stream-source.d.ts.map +1 -0
- package/dist/circuits/subscription-client.d.ts +143 -0
- package/dist/circuits/subscription-client.d.ts.map +1 -0
- package/dist/circuits/sync-engine.d.ts +131 -0
- package/dist/circuits/sync-engine.d.ts.map +1 -0
- package/dist/debug.d.ts +0 -10
- package/dist/debug.d.ts.map +1 -1
- package/dist/event-lane.d.ts +32 -1
- package/dist/event-lane.d.ts.map +1 -1
- package/dist/export-data.d.ts +3 -3
- package/dist/export-dump.d.ts +9 -9
- package/dist/export-dump.d.ts.map +1 -1
- package/dist/export-store.d.ts +13 -13
- package/dist/index.d.ts +237 -113
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7037 -6665
- package/dist/index.js.map +46 -43
- package/dist/local-store.d.ts +1 -1
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-tables.d.ts +59 -1
- package/dist/local-tables.d.ts.map +1 -1
- package/dist/mutation.d.ts +2 -2
- package/dist/mutation.d.ts.map +1 -1
- package/dist/mutations-api.d.ts.map +1 -1
- package/dist/opfs-effects.d.ts +30 -2
- package/dist/opfs-effects.d.ts.map +1 -1
- package/dist/schema.d.ts +12 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/store-boot.d.ts +30 -2
- package/dist/store-boot.d.ts.map +1 -1
- package/dist/store-build.d.ts +19 -0
- package/dist/store-build.d.ts.map +1 -0
- package/dist/store-engine.d.ts +22 -0
- package/dist/store-engine.d.ts.map +1 -0
- package/dist/store-meta.d.ts +29 -3
- package/dist/store-meta.d.ts.map +1 -1
- package/dist/store-ownership-lock.d.ts +33 -0
- package/dist/store-ownership-lock.d.ts.map +1 -0
- package/dist/store-path.d.ts +40 -28
- package/dist/store-path.d.ts.map +1 -1
- package/dist/sync/apply.d.ts +17 -25
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/copy.d.ts +84 -8
- package/dist/sync/copy.d.ts.map +1 -1
- package/dist/sync/drizzle-executor.d.ts +4 -4
- package/dist/sync/drizzle-executor.d.ts.map +1 -1
- package/dist/sync/fold.d.ts +40 -0
- package/dist/sync/fold.d.ts.map +1 -0
- package/dist/sync/metadata-tables.d.ts +25 -1
- package/dist/sync/metadata-tables.d.ts.map +1 -1
- package/dist/sync/subscription-state.d.ts +26 -7
- package/dist/sync/subscription-state.d.ts.map +1 -1
- package/dist/sync/types.d.ts +9 -129
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +4 -3
- package/dist/testing.js.map +4 -4
- package/dist/worker/attach-sync-client.d.ts +27 -14
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +52 -19
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/engine-control.d.ts +53 -0
- package/dist/worker/engine-control.d.ts.map +1 -1
- package/dist/worker/live-query-manager.d.ts +3 -3
- package/dist/worker/live-query-manager.d.ts.map +1 -1
- package/dist/worker/live-query-params-guard.d.ts +5 -5
- package/dist/worker/protocol.d.ts +26 -7
- package/dist/worker/protocol.d.ts.map +1 -1
- package/package.json +11 -9
- package/skills/core/SKILL.md +145 -63
- package/skills/operating/SKILL.md +221 -221
- package/skills/operating/references/postgres-builds.md +48 -0
- package/src/boot-report.ts +13 -12
- package/src/circuits/envelope-to-change.ts +211 -0
- package/src/circuits/group-sync.ts +1047 -0
- package/src/circuits/shape-group.ts +158 -0
- package/src/circuits/stream-inbox.ts +225 -0
- package/src/circuits/stream-source.ts +191 -0
- package/src/circuits/subscription-client.ts +353 -0
- package/src/circuits/sync-engine.ts +643 -0
- package/src/debug.ts +1 -85
- package/src/event-lane.ts +132 -14
- package/src/export-data.ts +4 -4
- package/src/export-dump.ts +24 -28
- package/src/export-store.ts +17 -17
- package/src/index.ts +797 -544
- package/src/lazy-guard.ts +1 -1
- package/src/live-rows-sql.ts +1 -1
- package/src/local-store.ts +2 -2
- package/src/local-tables.ts +76 -5
- package/src/mutation.ts +9 -8
- package/src/mutations-api.ts +2 -2
- package/src/opfs-effects.ts +74 -10
- package/src/schema.ts +126 -29
- package/src/store-boot.ts +71 -7
- package/src/store-build.ts +37 -0
- package/src/store-engine.ts +94 -0
- package/src/store-lifecycle.ts +1 -1
- package/src/store-meta.ts +155 -4
- package/src/store-ownership-lock.ts +109 -0
- package/src/store-path.ts +56 -40
- package/src/sync/apply.ts +104 -156
- package/src/sync/copy.ts +116 -21
- package/src/sync/drizzle-executor.ts +13 -14
- package/src/sync/fold.ts +94 -0
- package/src/sync/metadata-tables.ts +43 -2
- package/src/sync/subscription-state.ts +28 -10
- package/src/sync/types.ts +13 -141
- package/src/testing.ts +4 -4
- package/src/worker/attach-sync-client.ts +150 -57
- package/src/worker/define-sync-worker.ts +325 -87
- package/src/worker/engine-control.ts +89 -0
- package/src/worker/engine-router.ts +1 -1
- package/src/worker/live-query-fingerprint.ts +4 -4
- package/src/worker/live-query-manager.ts +12 -12
- package/src/worker/live-query-params-guard.ts +10 -10
- package/src/worker/protocol.ts +38 -7
- package/dist/read-stream-stall.d.ts +0 -54
- package/dist/read-stream-stall.d.ts.map +0 -1
- package/dist/shape-sync.d.ts +0 -207
- package/dist/shape-sync.d.ts.map +0 -1
- package/dist/sync/index.d.ts +0 -32
- package/dist/sync/index.d.ts.map +0 -1
- package/dist/sync/nudge.d.ts +0 -49
- package/dist/sync/nudge.d.ts.map +0 -1
- package/dist/sync/shape-inbox.d.ts +0 -215
- package/dist/sync/shape-inbox.d.ts.map +0 -1
- package/dist/sync/tags.d.ts +0 -142
- package/dist/sync/tags.d.ts.map +0 -1
- package/dist/sync-auth.d.ts +0 -53
- package/dist/sync-auth.d.ts.map +0 -1
- package/src/read-stream-stall.ts +0 -102
- package/src/shape-sync.ts +0 -533
- package/src/sync/index.ts +0 -1124
- package/src/sync/nudge.ts +0 -110
- package/src/sync/shape-inbox.ts +0 -566
- package/src/sync/tags.ts +0 -390
- package/src/sync-auth.ts +0 -117
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pgxsinkit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
@pgxsinkit/client
|
|
2
|
+
=================
|
|
3
|
+
|
|
4
|
+
This package includes software that began as a copy, or is a port, of third-party
|
|
5
|
+
code. It is owned outright and diverges freely (ADR-0009, ADR-0028); these
|
|
6
|
+
attributions are permanent.
|
|
7
|
+
|
|
8
|
+
------------------------------------------------------------------------------
|
|
9
|
+
ElectricSQL — @electric-sql/pglite, package `pglite-sync`
|
|
10
|
+
------------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
The read-path sync engine began as a copy of ElectricSQL's `@electric-sql/pglite`
|
|
13
|
+
monorepo, package `packages/pglite-sync`:
|
|
14
|
+
|
|
15
|
+
Source: https://github.com/electric-sql/pglite/tree/main/packages/pglite-sync
|
|
16
|
+
License: Apache License 2.0
|
|
17
|
+
Copyright (c) ElectricSQL and contributors
|
|
18
|
+
|
|
19
|
+
These files derive from it, and each carries a header saying so:
|
|
20
|
+
|
|
21
|
+
- src/sync/apply.ts
|
|
22
|
+
- src/sync/subscription-state.ts
|
|
23
|
+
- src/sync/types.ts
|
|
24
|
+
- src/circuits/sync-engine.ts
|
|
25
|
+
|
|
26
|
+
Their compiled form ships in `dist/`.
|
|
27
|
+
|
|
28
|
+
Changes: the engine reads each shape from a durable stream rather than Electric's
|
|
29
|
+
shape API (ADR-0055); commits each consistency group atomically through a
|
|
30
|
+
single-flight commit queue that holds a failed batch instead of dropping it
|
|
31
|
+
(ADR-0009); applies through an apply ladder chosen from the registry's column types,
|
|
32
|
+
folding each batch to one operation per primary key (ADR-0014); serializes COPY in
|
|
33
|
+
Postgres' TEXT format; keeps its metadata in its own `pgxsinkit` schema; and builds
|
|
34
|
+
its statements with Drizzle (ADR-0028). The Apache-2.0 terms are permanent. A copy of
|
|
35
|
+
the Apache License 2.0 ships with this package in LICENSE-APACHE-2.0 (from
|
|
36
|
+
https://www.apache.org/licenses/LICENSE-2.0.txt).
|
|
37
|
+
|
|
38
|
+
------------------------------------------------------------------------------
|
|
39
|
+
PostgreSQL — COPY TEXT field escaping and array literals
|
|
40
|
+
------------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
`src/sync/copy.ts`, the COPY TEXT serializer, ports two PostgreSQL backend routines
|
|
43
|
+
to TypeScript, with PostgreSQL 18 as the reference:
|
|
44
|
+
|
|
45
|
+
- `CopyAttributeOutText` (src/backend/commands/copyto.c): COPY TEXT field escaping
|
|
46
|
+
- `array_out` (src/backend/utils/adt/arrayfuncs.c): array literals
|
|
47
|
+
|
|
48
|
+
Source: https://www.postgresql.org
|
|
49
|
+
License: PostgreSQL License
|
|
50
|
+
Copyright (c) The PostgreSQL Global Development Group and The Regents of the
|
|
51
|
+
University of California
|
|
52
|
+
|
|
53
|
+
The file carries a header saying so, and its compiled form ships in `dist/`.
|
|
54
|
+
PostgreSQL's notice, copied from its COPYRIGHT file as PostgreSQL 18.3 ships it
|
|
55
|
+
(https://github.com/electric-sql/postgres-pglite at
|
|
56
|
+
b133782cd759f08b3aeb263b80a963b39c7b7af1, file COPYRIGHT, unchanged from PostgreSQL's
|
|
57
|
+
own; the same copy @pgxsinkit/pgwasm-c's NOTICE reproduces):
|
|
58
|
+
|
|
59
|
+
PostgreSQL Database Management System
|
|
60
|
+
(also known as Postgres, formerly known as Postgres95)
|
|
61
|
+
|
|
62
|
+
Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
|
|
63
|
+
|
|
64
|
+
Portions Copyright (c) 1994, The Regents of the University of California
|
|
65
|
+
|
|
66
|
+
Permission to use, copy, modify, and distribute this software and its
|
|
67
|
+
documentation for any purpose, without fee, and without a written agreement
|
|
68
|
+
is hereby granted, provided that the above copyright notice and this
|
|
69
|
+
paragraph and the following two paragraphs appear in all copies.
|
|
70
|
+
|
|
71
|
+
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
|
|
72
|
+
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
|
|
73
|
+
LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
|
|
74
|
+
DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
|
|
75
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
76
|
+
|
|
77
|
+
THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
|
78
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
79
|
+
AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
80
|
+
ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
|
|
81
|
+
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# @pgxsinkit/client
|
|
2
2
|
|
|
3
3
|
The [pgxsinkit](https://pgxsinkit.github.io) client: `createSyncClient` stages writes
|
|
4
|
-
into a local
|
|
5
|
-
API, and subscribes
|
|
4
|
+
into a local pgwasm overlay and a durable mutation journal, flushes them to the write
|
|
5
|
+
API, and subscribes through the read path's control plane to read durable-streams into
|
|
6
|
+
local pgwasm store.
|
|
6
7
|
|
|
7
8
|
```bash
|
|
8
9
|
bun add @pgxsinkit/client @pgxsinkit/contracts
|
|
@@ -12,7 +13,7 @@ See the [documentation](https://pgxsinkit.github.io) for the read and write path
|
|
|
12
13
|
|
|
13
14
|
## Browser storage and worker placement
|
|
14
15
|
|
|
15
|
-
`createSyncClient` is the in-process client. For browser apps, worker mode moves
|
|
16
|
+
`createSyncClient` is the in-process client. For browser apps, worker mode moves pgwasm off the
|
|
16
17
|
main thread with capability-driven placement (ADR-0049) as the default:
|
|
17
18
|
|
|
18
19
|
- real macOS/iOS Safari grants synchronous OPFS handles in a `SharedWorker`, so the engine runs there
|
|
@@ -31,3 +32,10 @@ placement from the browser name.
|
|
|
31
32
|
|
|
32
33
|
See [Worker mode](https://pgxsinkit.github.io/concepts/worker-mode/) for the complete factory,
|
|
33
34
|
relocation, adoption, destruction, and durability contract.
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT, except the parts of the read-path sync engine that began as ElectricSQL's
|
|
39
|
+
`@electric-sql/pglite-sync`, which stay under the Apache License 2.0 (`LICENSE-APACHE-2.0`); the
|
|
40
|
+
package license is `MIT AND Apache-2.0`. The COPY serializer ports two PostgreSQL routines and keeps
|
|
41
|
+
PostgreSQL's notice. `NOTICE` lists those files and has every attribution.
|
package/dist/boot-report.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/** Monotonic clock (ms) — `performance.now()` where available, else `Date.now()`. */
|
|
2
|
+
/** The monotonic clock every boot offset and duration in this module is measured on. */
|
|
3
|
+
export declare const nowMs: () => number;
|
|
1
4
|
/**
|
|
2
5
|
* A structured, versioned record of one client boot (ADR-0034). `reportVersion` is a contract number:
|
|
3
6
|
* additive fields keep it, a breaking reshape bumps it. All durations are milliseconds; all `*AtMs` are
|
|
@@ -64,23 +67,23 @@ export interface BootReport {
|
|
|
64
67
|
writeReadyMs: number | null;
|
|
65
68
|
/**
|
|
66
69
|
* Present only when the store was pre-provisioned (a spare's initdb ran off-thread before this boot
|
|
67
|
-
* adopted it); `null` otherwise. When present, `phases.
|
|
70
|
+
* adopted it); `null` otherwise. When present, `phases.pgwasmCreateMs` is `null` — the create cost is
|
|
68
71
|
* reported here instead.
|
|
69
72
|
*/
|
|
70
73
|
provision: {
|
|
71
|
-
/** The spare's
|
|
74
|
+
/** The spare's pgwasm create (initdb) cost, paid at provision time. */
|
|
72
75
|
initdbMs: number;
|
|
73
76
|
/** How long the provisioned store sat ready before this boot adopted it. */
|
|
74
77
|
provisionedMsBeforeBoot: number;
|
|
75
78
|
} | null;
|
|
76
79
|
phases: {
|
|
77
|
-
/**
|
|
78
|
-
|
|
80
|
+
/** pgwasm create cost, or `null` when the store was adopted from a spare (see {@link BootReport.provision}). */
|
|
81
|
+
pgwasmCreateMs: number | null;
|
|
79
82
|
schemaExecMs: number;
|
|
80
83
|
journalRecoveryMs: number;
|
|
81
84
|
storeVersionReconcileMs: number;
|
|
82
85
|
/**
|
|
83
|
-
* `
|
|
86
|
+
* `startCircuitsSync`: stream/group construction wall. On an overlap boot (ADR-0032 S4,
|
|
84
87
|
* {@link BootReport.overlapPrefetch}) the early-started segment runs concurrently with schema, journal
|
|
85
88
|
* recovery, and registry reconciliation, so this includes that shared wall. Structurally 0 when the boot
|
|
86
89
|
* is ready inside the
|
|
@@ -140,7 +143,7 @@ export interface BootReport {
|
|
|
140
143
|
*/
|
|
141
144
|
fetchMs: number;
|
|
142
145
|
/**
|
|
143
|
-
* Wall around this group's batch commits into
|
|
146
|
+
* Wall around this group's batch commits into pgwasm. Includes waiting behind another group's
|
|
144
147
|
* transaction on the shared connection (single writer), so concurrent groups' `applyMs` can overlap.
|
|
145
148
|
*/
|
|
146
149
|
applyMs: number;
|
|
@@ -156,12 +159,12 @@ type PhaseKey = "schemaExec" | "journalRecovery" | "storeVersionReconcile" | "sy
|
|
|
156
159
|
export interface GroupBootStamp {
|
|
157
160
|
/** A batch was delivered to the group's subscribe callback (one response). `changeCount` = its change rows. */
|
|
158
161
|
onBatchDelivered: (changeCount: number) => void;
|
|
159
|
-
/** A commit transaction applied `ms` of work into
|
|
162
|
+
/** A commit transaction applied `ms` of work into pgwasm for this group. */
|
|
160
163
|
onApply: (ms: number) => void;
|
|
161
164
|
/** The group reached its initial sync — stamp `readyAtMs` and freeze accumulation. */
|
|
162
165
|
markReady: () => void;
|
|
163
166
|
}
|
|
164
|
-
/** The seam `
|
|
167
|
+
/** The seam `startCircuitsSync` uses to open a boot group's accumulator (implemented by the builder). */
|
|
165
168
|
export interface BootStampCollector {
|
|
166
169
|
beginGroup: (groupKey: string, tables: number) => GroupBootStamp;
|
|
167
170
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boot-report.d.ts","sourceRoot":"","sources":["../src/boot-report.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"boot-report.d.ts","sourceRoot":"","sources":["../src/boot-report.ts"],"names":[],"mappings":"AAYA,qFAAqF;AACrF,wFAAwF;AACxF,eAAO,MAAM,KAAK,QAAO,MAA+E,CAAC;AAEzG;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,CAAC,CAAC;IACjB,qGAAqG;IACrG,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC;IAC9B,iGAAiG;IACjG,UAAU,EAAE,OAAO,CAAC;IACpB;;;;;;OAMG;IACH,SAAS,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,CAAC;IACzC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,eAAe,GAAG,OAAO,GAAG,YAAY,GAAG,QAAQ,CAAC;IACrE;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,eAAe,GAAG,gBAAgB,GAAG,YAAY,CAAC;IAC/D;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B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C,eAAe,EAAE,OAAO,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,cAAc,GAAG,iBAAiB,CA0H/E"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { StreamEnvelope, SyncOperation } from "@pgxsinkit/contracts";
|
|
2
|
+
import type { ApplyTarget } from "../local-tables";
|
|
3
|
+
/** The applier's message shape, once an envelope has been resolved against its table. */
|
|
4
|
+
export interface ChangeLike {
|
|
5
|
+
key: string;
|
|
6
|
+
value: Record<string, unknown>;
|
|
7
|
+
headers: {
|
|
8
|
+
operation: SyncOperation;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Rebuild the LOCAL primary-key columns of a row from the stream key.
|
|
13
|
+
*
|
|
14
|
+
* The key is the SERVER identity: composite keys are joined in server primary-key declaration order
|
|
15
|
+
* (escaped per component — see {@link unescapeKeyComponent}), single keys are the raw value. Under a
|
|
16
|
+
* `clientProjection.localPrimaryKey` narrowing the local key is a subset of the server key, so the
|
|
17
|
+
* split runs over `serverPrimaryKey` and only the local components are kept — the dropped ones are
|
|
18
|
+
* predicate-pinned (subscribe-time compile refuses the narrowing otherwise), so within this shape
|
|
19
|
+
* the narrowed key is still unique. A count mismatch is thrown rather than tolerated: a silently
|
|
20
|
+
* short split would produce a `WHERE` over only part of the key, and a delete matching more rows
|
|
21
|
+
* than it should is data loss, not a stale row.
|
|
22
|
+
*/
|
|
23
|
+
export declare function primaryKeyFromStreamKey(target: ApplyTarget, key: string): Record<string, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Translate a Circuits envelope into the message the applier consumes.
|
|
26
|
+
*
|
|
27
|
+
* There is no operation mapping to do — {@link SyncOperation} is the wire's own vocabulary. What
|
|
28
|
+
* this function carries is the one structural difference: **a delete has no row body**, only its
|
|
29
|
+
* key, so the pk columns are reconstructed here. That is a privacy improvement (an eviction
|
|
30
|
+
* discloses the key and nothing else) and an implementation hazard in the same change, which is why
|
|
31
|
+
* the reconstruction is a named, tested function rather than an inline split.
|
|
32
|
+
*
|
|
33
|
+
* An `upsert` carries the **complete projected row** every time — the engine's `row_to_json_cols`
|
|
34
|
+
* emits every column of the shape's `out_cols`, never a changed-column subset — which is what lets
|
|
35
|
+
* the apply path refresh every non-pk column from `excluded` without knowing whether the row already
|
|
36
|
+
* existed locally.
|
|
37
|
+
*/
|
|
38
|
+
export declare function envelopeToChange(target: ApplyTarget, envelope: StreamEnvelope): ChangeLike;
|
|
39
|
+
//# sourceMappingURL=envelope-to-change.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope-to-change.d.ts","sourceRoot":"","sources":["../../src/circuits/envelope-to-change.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAe,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAwCnD,yFAAyF;AACzF,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,EAAE;QAAE,SAAS,EAAE,aAAa,CAAA;KAAE,CAAC;CACvC;AA0BD;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0BjG;AAoDD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,GAAG,UAAU,CAiC1F"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { PredicateValue, SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
2
|
+
import type { Pgwasm } from "@pgxsinkit/pgwasm";
|
|
3
|
+
import type { BootStampCollector } from "../boot-report";
|
|
4
|
+
import { ControlPlaneError, type RefusedStream } from "./subscription-client";
|
|
5
|
+
export interface CircuitsGroupSyncOptions {
|
|
6
|
+
registry: SyncTableRegistry;
|
|
7
|
+
/** Base URL of the control plane — where subscribe, re-mint and the barrier live. */
|
|
8
|
+
controlPlaneUrl: string;
|
|
9
|
+
/** Base URL the edge serves streams from. */
|
|
10
|
+
streamBaseUrl: string;
|
|
11
|
+
/** The caller's own auth headers, resolved per request — the same adapter the write path uses. */
|
|
12
|
+
authHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
13
|
+
metadataSchema: string;
|
|
14
|
+
/**
|
|
15
|
+
* Lazy groups whose activation persisted from a previous boot (ADR-0021), started eagerly here.
|
|
16
|
+
*/
|
|
17
|
+
promotedGroups?: ReadonlySet<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Boot observability (ADR-0034). Only the BOOT starts (eager + promoted) open an accumulator, so an
|
|
20
|
+
* on-demand lazy activation never enters a finalized report.
|
|
21
|
+
*/
|
|
22
|
+
bootCollector?: BootStampCollector;
|
|
23
|
+
/** Fired the first time every eager/promoted group has caught up. */
|
|
24
|
+
onInitialSync?: () => void;
|
|
25
|
+
onGroupReady?: (groupKey: string) => void;
|
|
26
|
+
onSyncError?: (error: Error) => void;
|
|
27
|
+
onSyncActivity?: () => void;
|
|
28
|
+
/** Called when a durable lazy group is activated on demand, so the next boot can promote it. */
|
|
29
|
+
onLazyActivated?: (groupKey: string) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Called with the scopes the control plane refused or later revoked.
|
|
32
|
+
*
|
|
33
|
+
* Fired AFTER the refused scopes' local rows have been cleared, never before. Losing entitlement
|
|
34
|
+
* means losing the subscription, not keeping the rows (ADR-0055 decision 6), and an app that reacts
|
|
35
|
+
* to this — re-rendering, prompting, navigating away — must not be handed a store that still shows
|
|
36
|
+
* what the subject may no longer read.
|
|
37
|
+
*/
|
|
38
|
+
onRefused?: (refused: readonly RefusedStream[]) => void;
|
|
39
|
+
/**
|
|
40
|
+
* The subject's own credential was refused by the control plane (401/403), and subscribe is still
|
|
41
|
+
* retrying (ADR-0013). The app prompts for re-login; nothing here needs restarting, because the
|
|
42
|
+
* auth adapter is consulted fresh on every attempt.
|
|
43
|
+
*
|
|
44
|
+
* Distinct from `onSyncError`, which reports a fault the subject cannot act on.
|
|
45
|
+
*/
|
|
46
|
+
onAuthError?: (error: ControlPlaneError) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Subscribe failed for a reason the subject cannot act on — the control plane is down, degraded,
|
|
49
|
+
* or unreachable — and is still retrying.
|
|
50
|
+
*
|
|
51
|
+
* Separate from `onSyncError` because the two recover differently: a failed subscribe clears the
|
|
52
|
+
* moment a batch is delivered, while a commit failure is sticky by design (ADR-0009 decision 5) —
|
|
53
|
+
* reads can keep succeeding while applies keep failing.
|
|
54
|
+
*/
|
|
55
|
+
onSubscribeError?: (error: Error) => void;
|
|
56
|
+
/**
|
|
57
|
+
* A live stream ended or could not be opened — a `403` that survived a re-mint, a `404`/`410` on an
|
|
58
|
+
* evicted stream, `Stream-Closed`, a lost connection — and the group is re-subscribing with
|
|
59
|
+
* backoff.
|
|
60
|
+
*
|
|
61
|
+
* Recoverable, and it clears on the next delivered batch. Distinct from `onSubscribeError` (the
|
|
62
|
+
* CONTROL PLANE could not be reached, so there is nothing to read from yet) and from `onSyncError`
|
|
63
|
+
* (a COMMIT failed, which is sticky by design because reads can keep succeeding while applies keep
|
|
64
|
+
* failing).
|
|
65
|
+
*/
|
|
66
|
+
onStreamError?: (error: Error) => void;
|
|
67
|
+
live?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Tears the whole read path down from OUTSIDE, including mid-boot.
|
|
70
|
+
*
|
|
71
|
+
* `unsubscribe()` cannot cover that window: it lives on the handle this function returns, and a boot
|
|
72
|
+
* whose control plane is unreachable has not returned one yet. A client stopped in that window would
|
|
73
|
+
* otherwise sit on a TCP connect with nothing able to cancel it — which is precisely when a stop is
|
|
74
|
+
* most likely, because the network being down is why the boot is still running.
|
|
75
|
+
*/
|
|
76
|
+
signal?: AbortSignal;
|
|
77
|
+
fetch?: typeof fetch;
|
|
78
|
+
}
|
|
79
|
+
export interface CircuitsTableSyncResult {
|
|
80
|
+
readonly isUpToDate: boolean;
|
|
81
|
+
}
|
|
82
|
+
export interface CircuitsGroupSyncResult {
|
|
83
|
+
unsubscribe: () => void;
|
|
84
|
+
tables: Record<string, CircuitsTableSyncResult>;
|
|
85
|
+
/**
|
|
86
|
+
* Start a held lazy group. Idempotent and single-flight; resolves once it has caught up — EXCEPT
|
|
87
|
+
* for an already-promoted group, which resolves at once because it is durable and boot-started
|
|
88
|
+
* (ADR-0021 §2), so its catch-up must not gate a read.
|
|
89
|
+
*/
|
|
90
|
+
ensureGroupStarted: (groupKey: string) => Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Tear a group's streams down and return it to dormant, so a later start re-subscribes. Also drops
|
|
93
|
+
* the group's promotion for this session — a desync truncates the local copy, so the group is held
|
|
94
|
+
* again and re-activates (and re-persists its flag) on its next reference.
|
|
95
|
+
*/
|
|
96
|
+
stopGroup: (groupKey: string) => void;
|
|
97
|
+
groupKeyForTable: (tableKey: string) => string | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Whether the table's group is STARTED — a durable subscription for it exists, so reads of it are
|
|
100
|
+
* meaningful. NOT the same question as caught up, which is {@link CircuitsGroupSyncResult.isGroupReady}:
|
|
101
|
+
* a promoted group is started from boot even while its first subscribe is still retrying.
|
|
102
|
+
*/
|
|
103
|
+
isTableStarted: (tableKey: string) => boolean;
|
|
104
|
+
groupReady: (groupKey: string) => Promise<void>;
|
|
105
|
+
isGroupReady: (groupKey: string) => boolean;
|
|
106
|
+
groupKeys: () => string[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The name one READER of a stream is known by, within its group and across boots.
|
|
110
|
+
*
|
|
111
|
+
* A grant's shape key plus its scope, because neither alone identifies a reader. A shared shape fans
|
|
112
|
+
* out to one grant per entitled scope (ADR-0055 decision 6), so shape keys are not unique within a
|
|
113
|
+
* group; and the STREAM PATH is not unique either, which is the sharper of the two. Circuits
|
|
114
|
+
* ref-counts byte-identical shape definitions, so two distinct read projections that compile to the
|
|
115
|
+
* same table, columns and predicate come back as one path — keying on it dropped the second
|
|
116
|
+
* projection's reader outright and left its local table empty forever.
|
|
117
|
+
*
|
|
118
|
+
* Exported for the tests that pin that naming: it is also the key of a persisted cursor entry, so it
|
|
119
|
+
* is the thing a later subscribe matches a grant against.
|
|
120
|
+
*/
|
|
121
|
+
export declare function logicalShapeName(shapeKey: string, scope?: readonly PredicateValue[]): string;
|
|
122
|
+
export declare function startCircuitsSync(pg: Pgwasm, options: CircuitsGroupSyncOptions): Promise<CircuitsGroupSyncResult>;
|
|
123
|
+
//# sourceMappingURL=group-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-sync.d.ts","sourceRoot":"","sources":["../../src/circuits/group-sync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAkB,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,gBAAgB,CAAC;AASzE,OAAO,EACL,iBAAiB,EAGjB,KAAK,aAAa,EAEnB,MAAM,uBAAuB,CAAC;AA4F/B,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,qFAAqF;IACrF,eAAe,EAAE,MAAM,CAAC;IACxB,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,kGAAkG;IAClG,WAAW,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7E,cAAc,EAAE,MAAM,C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