@cntryl/fitz 0.0.1

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 (103) hide show
  1. package/LICENSE +160 -0
  2. package/README.md +195 -0
  3. package/dist/index.cjs +5285 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.mjs +5222 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/dist/types/client/client.d.ts +35 -0
  8. package/dist/types/client/client.d.ts.map +1 -0
  9. package/dist/types/client/connection.d.ts +57 -0
  10. package/dist/types/client/connection.d.ts.map +1 -0
  11. package/dist/types/client/multiplexer.d.ts +65 -0
  12. package/dist/types/client/multiplexer.d.ts.map +1 -0
  13. package/dist/types/core/buffer.d.ts +63 -0
  14. package/dist/types/core/buffer.d.ts.map +1 -0
  15. package/dist/types/core/errors.d.ts +94 -0
  16. package/dist/types/core/errors.d.ts.map +1 -0
  17. package/dist/types/core/iterator.d.ts +66 -0
  18. package/dist/types/core/iterator.d.ts.map +1 -0
  19. package/dist/types/core/lifecycle.d.ts +41 -0
  20. package/dist/types/core/lifecycle.d.ts.map +1 -0
  21. package/dist/types/core/task-group.d.ts +23 -0
  22. package/dist/types/core/task-group.d.ts.map +1 -0
  23. package/dist/types/core/types.d.ts +92 -0
  24. package/dist/types/core/types.d.ts.map +1 -0
  25. package/dist/types/domains/_routes.d.ts +10 -0
  26. package/dist/types/domains/_routes.d.ts.map +1 -0
  27. package/dist/types/domains/base.d.ts +26 -0
  28. package/dist/types/domains/base.d.ts.map +1 -0
  29. package/dist/types/domains/kv/client.d.ts +18 -0
  30. package/dist/types/domains/kv/client.d.ts.map +1 -0
  31. package/dist/types/domains/kv/codec.d.ts +22 -0
  32. package/dist/types/domains/kv/codec.d.ts.map +1 -0
  33. package/dist/types/domains/kv/transaction.d.ts +19 -0
  34. package/dist/types/domains/kv/transaction.d.ts.map +1 -0
  35. package/dist/types/domains/kv/types.d.ts +47 -0
  36. package/dist/types/domains/kv/types.d.ts.map +1 -0
  37. package/dist/types/domains/lease/client.d.ts +18 -0
  38. package/dist/types/domains/lease/client.d.ts.map +1 -0
  39. package/dist/types/domains/lease/codec.d.ts +69 -0
  40. package/dist/types/domains/lease/codec.d.ts.map +1 -0
  41. package/dist/types/domains/lease/index.d.ts +9 -0
  42. package/dist/types/domains/lease/index.d.ts.map +1 -0
  43. package/dist/types/domains/lease/types.d.ts +88 -0
  44. package/dist/types/domains/lease/types.d.ts.map +1 -0
  45. package/dist/types/domains/notice/client.d.ts +17 -0
  46. package/dist/types/domains/notice/client.d.ts.map +1 -0
  47. package/dist/types/domains/notice/codec.d.ts +42 -0
  48. package/dist/types/domains/notice/codec.d.ts.map +1 -0
  49. package/dist/types/domains/notice/index.d.ts +9 -0
  50. package/dist/types/domains/notice/index.d.ts.map +1 -0
  51. package/dist/types/domains/notice/types.d.ts +44 -0
  52. package/dist/types/domains/notice/types.d.ts.map +1 -0
  53. package/dist/types/domains/queue/client.d.ts +18 -0
  54. package/dist/types/domains/queue/client.d.ts.map +1 -0
  55. package/dist/types/domains/queue/codec.d.ts +82 -0
  56. package/dist/types/domains/queue/codec.d.ts.map +1 -0
  57. package/dist/types/domains/queue/index.d.ts +9 -0
  58. package/dist/types/domains/queue/index.d.ts.map +1 -0
  59. package/dist/types/domains/queue/types.d.ts +97 -0
  60. package/dist/types/domains/queue/types.d.ts.map +1 -0
  61. package/dist/types/domains/rpc/client.d.ts +17 -0
  62. package/dist/types/domains/rpc/client.d.ts.map +1 -0
  63. package/dist/types/domains/rpc/codec.d.ts +82 -0
  64. package/dist/types/domains/rpc/codec.d.ts.map +1 -0
  65. package/dist/types/domains/rpc/index.d.ts +8 -0
  66. package/dist/types/domains/rpc/index.d.ts.map +1 -0
  67. package/dist/types/domains/rpc/types.d.ts +67 -0
  68. package/dist/types/domains/rpc/types.d.ts.map +1 -0
  69. package/dist/types/domains/schedule/client.d.ts +19 -0
  70. package/dist/types/domains/schedule/client.d.ts.map +1 -0
  71. package/dist/types/domains/schedule/codec.d.ts +63 -0
  72. package/dist/types/domains/schedule/codec.d.ts.map +1 -0
  73. package/dist/types/domains/schedule/index.d.ts +8 -0
  74. package/dist/types/domains/schedule/index.d.ts.map +1 -0
  75. package/dist/types/domains/schedule/types.d.ts +69 -0
  76. package/dist/types/domains/schedule/types.d.ts.map +1 -0
  77. package/dist/types/domains/stream/client.d.ts +27 -0
  78. package/dist/types/domains/stream/client.d.ts.map +1 -0
  79. package/dist/types/domains/stream/codec.d.ts +124 -0
  80. package/dist/types/domains/stream/codec.d.ts.map +1 -0
  81. package/dist/types/domains/stream/index.d.ts +8 -0
  82. package/dist/types/domains/stream/index.d.ts.map +1 -0
  83. package/dist/types/domains/stream/session.d.ts +8 -0
  84. package/dist/types/domains/stream/session.d.ts.map +1 -0
  85. package/dist/types/domains/stream/types.d.ts +150 -0
  86. package/dist/types/domains/stream/types.d.ts.map +1 -0
  87. package/dist/types/frame/codec.d.ts +29 -0
  88. package/dist/types/frame/codec.d.ts.map +1 -0
  89. package/dist/types/frame/types.d.ts +71 -0
  90. package/dist/types/frame/types.d.ts.map +1 -0
  91. package/dist/types/index.d.ts +25 -0
  92. package/dist/types/index.d.ts.map +1 -0
  93. package/dist/types/protocol/response.d.ts +27 -0
  94. package/dist/types/protocol/response.d.ts.map +1 -0
  95. package/dist/types/transport/factory.d.ts +6 -0
  96. package/dist/types/transport/factory.d.ts.map +1 -0
  97. package/dist/types/transport/tcp.d.ts +6 -0
  98. package/dist/types/transport/tcp.d.ts.map +1 -0
  99. package/dist/types/transport/types.d.ts +17 -0
  100. package/dist/types/transport/types.d.ts.map +1 -0
  101. package/dist/types/transport/websocket.d.ts +6 -0
  102. package/dist/types/transport/websocket.d.ts.map +1 -0
  103. package/package.json +72 -0
package/LICENSE ADDED
@@ -0,0 +1,160 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and
27
+ configuration files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object
31
+ code, generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work (an example is provided in the Appendix
36
+ below).
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
39
+ is based on (or derived from) the Work and for which the editorial revisions,
40
+ annotations, elaborations, or other modifications represent, as a whole, an
41
+ original work of authorship. For the purposes of this License, Derivative Works
42
+ shall not include works that remain separable from, or merely link (or bind by
43
+ name) to the interfaces of, the Work and Derivative Works thereof.
44
+
45
+ "Contribution" shall mean any work of authorship, including the original
46
+ version of the Work and any modifications or additions to that Work or
47
+ Derivative Works thereof, that is intentionally submitted to Licensor for
48
+ inclusion in the Work by the copyright owner or by an individual or Legal
49
+ Entity authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal, or
51
+ written communication sent to the Licensor or its representatives, including
52
+ but not limited to communication on electronic mailing lists, source code
53
+ control systems, and issue tracking systems that are managed by, or on behalf
54
+ of, the Licensor for the purpose of discussing and improving the Work, but
55
+ excluding communication that is conspicuously marked or otherwise designated in
56
+ writing by the copyright owner as "Not a Contribution."
57
+
58
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
59
+ of whom a Contribution has been received by Licensor and subsequently
60
+ incorporated within the Work.
61
+
62
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
63
+ License, each Contributor hereby grants to You a perpetual, worldwide,
64
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
65
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
66
+ sublicense, and distribute the Work and such Derivative Works in Source or
67
+ Object form.
68
+
69
+ 3. Grant of Patent License. Subject to the terms and conditions of this
70
+ License, each Contributor hereby grants to You a perpetual, worldwide,
71
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
72
+ section) patent license to make, have made, use, offer to sell, sell, import,
73
+ and otherwise transfer the Work, where such license applies only to those
74
+ patent claims licensable by such Contributor that are necessarily infringed by
75
+ their Contribution(s) alone or by combination of their Contribution(s) with the
76
+ Work to which such Contribution(s) was submitted. If You institute patent
77
+ litigation against any entity (including a cross-claim or counterclaim in a
78
+ lawsuit) alleging that the Work or a Contribution incorporated within the Work
79
+ constitutes direct or contributory patent infringement, then any patent
80
+ licenses granted to You under this License for that Work shall terminate as of
81
+ the date such litigation is filed.
82
+
83
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
84
+ Derivative Works thereof in any medium, with or without modifications, and in
85
+ Source or Object form, provided that You meet the following conditions:
86
+
87
+ (a) You must give any other recipients of the Work or Derivative Works a copy
88
+ of this License; and
89
+
90
+ (b) You must cause any modified files to carry prominent notices stating that
91
+ You changed the files; and
92
+
93
+ (c) You must retain, in the Source form of any Derivative Works that You
94
+ distribute, all copyright, patent, trademark, and attribution notices from the
95
+ Source form of the Work, excluding those notices that do not pertain to any
96
+ part of the Derivative Works; and
97
+
98
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
99
+ any Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents
106
+ of the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+
112
+ You may add Your own copyright statement to Your modifications and may provide
113
+ additional or different license terms and conditions for use, reproduction, or
114
+ distribution of Your modifications, or for any such Derivative Works as a
115
+ whole, provided Your use, reproduction, and distribution of the Work otherwise
116
+ complies with the conditions stated in this License.
117
+
118
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
119
+ Contribution intentionally submitted for inclusion in the Work by You to the
120
+ Licensor shall be under the terms and conditions of this License, without any
121
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
122
+ supersede or modify the terms of any separate license agreement you may have
123
+ executed with Licensor regarding such Contributions.
124
+
125
+ 6. Trademarks. This License does not grant permission to use the trade names,
126
+ trademarks, service marks, or product names of the Licensor, except as required
127
+ for reasonable and customary use in describing the origin of the Work and
128
+ reproducing the content of the NOTICE file.
129
+
130
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
131
+ writing, Licensor provides the Work (and each Contributor provides its
132
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
133
+ KIND, either express or implied, including, without limitation, any warranties
134
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
135
+ PARTICULAR PURPOSE. You are solely responsible for determining the
136
+ appropriateness of using or redistributing the Work and assume any risks
137
+ associated with Your exercise of permissions under this License.
138
+
139
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
140
+ tort (including negligence), contract, or otherwise, unless required by
141
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
142
+ writing, shall any Contributor be liable to You for damages, including any
143
+ direct, indirect, special, incidental, or consequential damages of any
144
+ character arising as a result of this License or out of the use or inability to
145
+ use the Work (including but not limited to damages for loss of goodwill, work
146
+ stoppage, computer failure or malfunction, or any and all other commercial
147
+ damages or losses), even if such Contributor has been advised of the
148
+ possibility of such damages.
149
+
150
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
151
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
152
+ acceptance of support, warranty, indemnity, or other liability obligations
153
+ and/or rights consistent with this License. However, in accepting such
154
+ obligations, You may act only on Your own behalf and on Your sole
155
+ responsibility, not on behalf of any other Contributor, and only if You agree
156
+ to indemnify, defend, and hold each Contributor harmless for any liability
157
+ incurred by, or claims asserted against, such Contributor by reason of your
158
+ accepting any such warranty or additional liability.
159
+
160
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # fitz-ts
2
+
3
+ TypeScript client SDK for [Fitz](https://github.com/cntryl/fitz).
4
+
5
+ ## Install
6
+
7
+ Requires Node.js 20.19 or later.
8
+
9
+ ```bash
10
+ npm install @cntryl/fitz
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { Client } from "@cntryl/fitz";
17
+
18
+ const client = Client({
19
+ url: "ws://localhost:4090/ws",
20
+ tokenProvider: async () => "your-jwt-token",
21
+ reconnect: { enabled: true },
22
+ asyncHandlers: {
23
+ maxConcurrency: 32,
24
+ timeoutMs: 5000,
25
+ },
26
+ });
27
+
28
+ await client.connect();
29
+
30
+ const tx = await client.kv().begin("kv://realm/area/users", "ReadWrite");
31
+ await tx.put(new TextEncoder().encode("user-1"), new TextEncoder().encode('{"name":"Alice"}'));
32
+ await tx.commit();
33
+
34
+ await client.close();
35
+ ```
36
+
37
+ ## Observability
38
+
39
+ `fitz-ts` now supports additive observability hooks through `ClientConfig.observability`.
40
+
41
+ ```typescript
42
+ import { Client } from "@cntryl/fitz";
43
+
44
+ const client = Client({
45
+ url: "ws://localhost:4090/ws",
46
+ reconnect: { enabled: true },
47
+ observability: {
48
+ logger: {
49
+ log(level, event, fields) {
50
+ console.log(level, event, fields);
51
+ },
52
+ },
53
+ onLifecycleEvent(event) {
54
+ console.log(event.event, event.state);
55
+ },
56
+ },
57
+ });
58
+ ```
59
+
60
+ See `docs/OPERATIONS.md` for lifecycle events, metric names, and production guidance.
61
+
62
+ ## Stream Replay
63
+
64
+ ```typescript
65
+ import type { StreamFilterSet } from "@cntryl/fitz";
66
+
67
+ const filter: StreamFilterSet = {
68
+ clauses: [{ kind: "Equals", value: "proj.alpha" }],
69
+ };
70
+
71
+ const records = await client.stream().read("stream://realm/app/events", 0n, 100, {
72
+ filter,
73
+ maxBytes: 64_000n,
74
+ });
75
+
76
+ const page = await client.stream().readPage("stream://realm/app/events", 0n, 100, {
77
+ filter,
78
+ maxBytes: 64_000n,
79
+ });
80
+
81
+ // read() keeps the compatibility projection and returns event records only.
82
+ // readPage() exposes synthetic filtered markers and cursor metadata.
83
+ void records;
84
+ void page.cursor.lastResourceOffset;
85
+ ```
86
+
87
+ ## Concurrency Notes
88
+
89
+ - Different domains can operate concurrently on one client connection.
90
+ - Multiple independent KV transactions and stream sessions can also be active concurrently.
91
+ - Do not issue overlapping operations against the same KV transaction or the same stream session. Those stateful handles are intended to be used sequentially.
92
+ - Notification and RPC worker handlers run through a shared async dispatcher. Use `asyncHandlers.maxConcurrency` and `asyncHandlers.timeoutMs` to bound handler fan-out in production.
93
+
94
+ ## Transport Support
95
+
96
+ - WebSocket: browser and Node.js
97
+ - TCP: Node.js only
98
+ - Auto transport detection: defaults to WebSocket when the URL omits a scheme
99
+
100
+ ## Verification
101
+
102
+ Fast local checks:
103
+
104
+ ```bash
105
+ npm ci
106
+ npm run verify:fast
107
+ ```
108
+
109
+ Broker-backed verification:
110
+
111
+ ```bash
112
+ docker compose -f ../fitz-go/compose.yml up -d
113
+ npm run verify
114
+ docker compose -f ../fitz-go/compose.yml down --volumes
115
+ ```
116
+
117
+ Package smoke verification:
118
+
119
+ ```bash
120
+ npm run pack:smoke
121
+ ```
122
+
123
+ Suggested release checklist:
124
+
125
+ ```bash
126
+ npm ci
127
+ npm run verify:fast
128
+ docker compose -f ../fitz-go/compose.yml up -d
129
+ npm run verify
130
+ npm run bench
131
+ docker compose -f ../fitz-go/compose.yml down --volumes
132
+ ```
133
+
134
+ Tiered benchmark commands:
135
+
136
+ ```bash
137
+ npm run bench:tier1
138
+ npm run bench:tier2
139
+ npm run bench:tier3
140
+ npm run bench:tier4
141
+ npm run bench
142
+ ```
143
+
144
+ > Run the full suite repeatedly before relying on benchmark automation. `tier4` is broader and more integration-style, so it should be stabilized over multiple executions before adding CI thresholds.
145
+
146
+ Benchmark tiers:
147
+
148
+ - `tier1`: hot-path microbenchmarks for core frame, codec, and multiplexer/parse runtime costs.
149
+ - `tier2`: subsystem benchmarks for domain-level payload and request-encoding workloads.
150
+ - `tier3`: system benchmarks for combined protocol and client flow payloads.
151
+ - `tier4`: integration benchmarks for realistic multi-message encode and frame assembly scenarios.
152
+
153
+ The conformance harness writes JSON results to `artifacts/conformance-results.json` by default.
154
+
155
+ Tooling is direct:
156
+
157
+ - `vp check` for combined format, lint, and type checks
158
+ - `vp fmt` for formatting
159
+ - `vp lint` for linting
160
+ - `vp test` for unit, integration, and conformance tests
161
+ - `vp pack` for JS bundle output
162
+ - `tsc` for declaration emit
163
+ - `tsc` for typechecking and declaration emit
164
+
165
+ Published artifacts are smoke-tested from the packed tarball in both ESM and
166
+ CommonJS consumer fixtures before release.
167
+
168
+ ## Repository Layout
169
+
170
+ - `src/client`: public client facade and connection management
171
+ - `src/transport`: WebSocket and TCP transports
172
+ - `src/domains`: domain clients and codecs
173
+ - `tests/unit`: fast unit coverage
174
+ - `tests/integration`: broker-backed integration coverage
175
+ - `tests/conformance`: release-gate conformance suite
176
+
177
+ Broker-backed connection hardening coverage now includes automatic reconnect subscription replay and token-provider replay checks in `tests/integration/connection.test.ts`.
178
+
179
+ ## Canonical Docs
180
+
181
+ `fitz-ts` follows the canonical Fitz client docs in the server repo:
182
+
183
+ - [`../fitz/docs/clients/CLIENT_SPEC.md`](../fitz/docs/clients/CLIENT_SPEC.md)
184
+ - [`../fitz/docs/clients/CLIENT_ACCEPTANCE_CRITERIA.md`](../fitz/docs/clients/CLIENT_ACCEPTANCE_CRITERIA.md)
185
+ - [`../fitz/docs/clients/CLIENT_IMPLEMENTATION_GUIDE.md`](../fitz/docs/clients/CLIENT_IMPLEMENTATION_GUIDE.md)
186
+ - [`../fitz/docs/clients/CONNECTION_FLOW.md`](../fitz/docs/clients/CONNECTION_FLOW.md)
187
+
188
+ ## Documentation
189
+
190
+ - [`docs/README.md`](docs/README.md)
191
+ - [`docs/OPERATIONS.md`](docs/OPERATIONS.md)
192
+ - [`docs/PUBLIC_CONTRACT.md`](docs/PUBLIC_CONTRACT.md)
193
+ - [`CLIENT_SPEC.md`](CLIENT_SPEC.md)
194
+ - [`CLIENT_ACCEPTANCE_CRITERIA.md`](CLIENT_ACCEPTANCE_CRITERIA.md)
195
+ - [`CHANGELOG.md`](CHANGELOG.md)