syntony-flag 0.1.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 ADDED
@@ -0,0 +1,201 @@
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,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and do
117
+ not modify the License. You may add Your own attribution notices
118
+ within Derivative Works that You distribute, alongside or as an
119
+ addendum to the NOTICE text from the Work, provided that such
120
+ additional attribution notices cannot be construed as modifying
121
+ the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # syntony-flag
2
+
3
+ > A feature-flag / dynamic-config system with **no flag server**.
4
+
5
+ Flags live, replicated, inside your application instances — built on the
6
+ [Syntony](../syntony) decentralized state primitive. Read a flag and it answers
7
+ instantly from local memory; toggle it from any instance and the change ripples
8
+ across the fleet on its own. There is no central flag service to run, scale, or
9
+ page someone about at 3am.
10
+
11
+ This is the first consumer of the Syntony core (§15 of the [spec](../spec.md)),
12
+ built alongside it so its real needs shape the core API.
13
+
14
+ ## Usage
15
+
16
+ ```ts
17
+ import { Syntony, MemoryHub, Flags } from "syntony-flag";
18
+
19
+ // Each app instance embeds a node.
20
+ const node = new Syntony({ grpcAddress: "10.0.0.7:7000" });
21
+ const flags = new Flags(node);
22
+
23
+ // Defaults live at the call site — the core has no baseline (§13.1).
24
+ if (flags.getBool("new_checkout", false)) {
25
+ renderNewCheckout();
26
+ }
27
+
28
+ // Toggle from any instance (e.g. an admin request); it replicates in the background.
29
+ flags.set("new_checkout", true);
30
+ flags.set("rate_limit", 250);
31
+ flags.set("rollout", { percent: 25, regions: ["us", "eu"] });
32
+ ```
33
+
34
+ Typed accessors (`getBool` / `getNumber` / `getString` / `getJSON`) all take a
35
+ call-site default returned when the flag is absent. Reading a flag as the wrong
36
+ type throws a `FlagTypeError`.
37
+
38
+ ## Fleet / convergence dashboard
39
+
40
+ The headline feature: watch flags propagate and spot lagging or partitioned
41
+ nodes. `fleetStateJson(nodes)` produces a machine-readable document for a host
42
+ `/state` endpoint, and `renderDashboardHtml()` returns a single self-contained
43
+ HTML page (no build step, no external scripts) that renders it:
44
+
45
+ ```ts
46
+ import { fleetStateJson, renderDashboardHtml } from "syntony-flag";
47
+
48
+ // Mount these on your host's existing admin server (behind host auth).
49
+ app.get("/state", (_req, res) => res.json(fleetStateJson(nodes)));
50
+ app.get("/flags", (_req, res) => res.type("html").send(renderDashboardHtml()));
51
+ ```
52
+
53
+ A flag's view reports its winning value and how far it has propagated, e.g.
54
+ *`true` on 4/5 nodes, 1 propagating* — turning eventual consistency into
55
+ something an operator can see.
56
+
57
+ ## Audit
58
+
59
+ Every write carries who/what/when, derived from the per-key writer and HLC
60
+ metadata:
61
+
62
+ ```ts
63
+ flags.audit("new_checkout");
64
+ // { key, value: true, writer: "node_…", version: { physical, logical }, deleted: false }
65
+ ```
66
+
67
+ ## License
68
+
69
+ Apache-2.0.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Flag value encoding (§15). The Syntony core treats values as opaque bytes; the
3
+ * flag product defines its own encoding on top. Values are JSON — booleans,
4
+ * numbers, strings, and JSON objects/arrays — serialized to UTF-8 bytes, which
5
+ * keeps flags language-agnostic on the wire and human-readable in audits.
6
+ */
7
+ export type FlagJson = null | boolean | number | string | FlagJson[] | {
8
+ [key: string]: FlagJson;
9
+ };
10
+ export type FlagValue = FlagJson;
11
+ /** Serialize a flag value to opaque bytes for storage in the core. */
12
+ export declare function encodeValue(value: FlagValue): Uint8Array;
13
+ /** Decode opaque bytes from the core back into a flag value. */
14
+ export declare function decodeValue(bytes: Uint8Array): FlagValue;
15
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAChB,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,QAAQ,EAAE,GACV;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAC;AAEhC,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC;AAKjC,sEAAsE;AACtE,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CAExD;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAExD"}
package/dist/codec.js ADDED
@@ -0,0 +1,11 @@
1
+ const encoder = new TextEncoder();
2
+ const decoder = new TextDecoder();
3
+ /** Serialize a flag value to opaque bytes for storage in the core. */
4
+ export function encodeValue(value) {
5
+ return encoder.encode(JSON.stringify(value));
6
+ }
7
+ /** Decode opaque bytes from the core back into a flag value. */
8
+ export function decodeValue(bytes) {
9
+ return JSON.parse(decoder.decode(bytes));
10
+ }
11
+ //# sourceMappingURL=codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,sEAAsE;AACtE,MAAM,UAAU,WAAW,CAAC,KAAgB;IAC1C,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAc,CAAC;AACxD,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { Syntony } from "syntony";
2
+ import type { FlagValue } from "./codec.js";
3
+ /** JSON-safe version of a node's per-flag view (BigInts → decimal strings). */
4
+ export interface NodeFlagViewJson {
5
+ node: string;
6
+ label: string;
7
+ present: boolean;
8
+ deleted: boolean;
9
+ value: FlagValue | undefined;
10
+ version: {
11
+ physical: string;
12
+ logical: string;
13
+ } | null;
14
+ atWinner: boolean;
15
+ }
16
+ export interface FlagFleetViewJson {
17
+ key: string;
18
+ value: FlagValue | undefined;
19
+ deleted: boolean;
20
+ converged: boolean;
21
+ nodesAtWinner: number;
22
+ total: number;
23
+ propagating: number;
24
+ summary: string;
25
+ perNode: NodeFlagViewJson[];
26
+ }
27
+ export interface FleetStateJson {
28
+ flags: FlagFleetViewJson[];
29
+ members: {
30
+ node: string;
31
+ label: string;
32
+ status: string;
33
+ address: string;
34
+ }[];
35
+ }
36
+ /**
37
+ * The machine-readable `/state` document (§15). Identical to {@link fleetState}
38
+ * but with the 64-bit HLC fields rendered as decimal strings so it survives
39
+ * `JSON.stringify` (BigInt is not natively serializable, §7.2).
40
+ */
41
+ export declare function fleetStateJson(nodes: Syntony[]): FleetStateJson;
42
+ /**
43
+ * A self-contained fleet/convergence dashboard (§15) — one HTML page, no build
44
+ * step and no external scripts. It polls the host-mounted `/state` endpoint
45
+ * (which should return {@link fleetStateJson}) and renders flag propagation
46
+ * across the fleet, so operators can watch a flag ripple out and spot lagging or
47
+ * partitioned nodes.
48
+ */
49
+ export declare const DASHBOARD_HTML = "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<title>Syntony Flags \u2014 Fleet</title>\n<style>\n :root { color-scheme: light dark; --ok: #1a7f37; --warn: #bf8700; --bg: #0d1117; --fg: #e6edf3; --muted: #8b949e; --card: #161b22; --line: #30363d; }\n body { font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; margin: 0; background: var(--bg); color: var(--fg); }\n header { padding: 16px 24px; border-bottom: 1px solid var(--line); display: flex; align-items: baseline; gap: 12px; }\n h1 { font-size: 18px; margin: 0; }\n .muted { color: var(--muted); font-size: 13px; }\n main { padding: 24px; display: grid; gap: 16px; max-width: 1100px; }\n .flag { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }\n .flag h2 { font-size: 15px; margin: 0 0 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }\n .summary { font-size: 13px; margin-bottom: 12px; }\n .summary.ok { color: var(--ok); }\n .summary.warn { color: var(--warn); }\n .nodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }\n .node { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 12px; }\n .node .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }\n .node.winner .dot { background: var(--ok); }\n .node.behind .dot { background: var(--warn); }\n .node.absent .dot { background: var(--muted); }\n .node code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }\n .members { font-size: 12px; color: var(--muted); }\n</style>\n</head>\n<body>\n<header>\n <h1>Syntony Flags</h1>\n <span class=\"muted\">decentralized feature flags &middot; no flag server</span>\n <span class=\"muted\" id=\"updated\"></span>\n</header>\n<main id=\"root\"><p class=\"muted\">Loading fleet state\u2026</p></main>\n<script>\n const STATE_URL = \"/state\";\n function esc(s) { return String(s).replace(/[&<>\"]/g, c => ({ \"&\": \"&amp;\", \"<\": \"&lt;\", \">\": \"&gt;\", '\"': \"&quot;\" }[c])); }\n function nodeClass(n) { return n.atWinner ? \"winner\" : n.present ? \"behind\" : \"absent\"; }\n function render(state) {\n const root = document.getElementById(\"root\");\n if (!state.flags.length) { root.innerHTML = '<p class=\"muted\">No flags set yet.</p>'; return; }\n root.innerHTML = state.flags.map(f => {\n const cls = f.converged ? \"ok\" : \"warn\";\n const nodes = f.perNode.map(n => {\n const val = n.present ? (n.deleted ? \"(deleted)\" : JSON.stringify(n.value)) : \"\u2014\";\n return '<div class=\"node ' + nodeClass(n) + '\"><span class=\"dot\"></span><code>' + esc(n.label) + '</code><br><span class=\"muted\">' + esc(val) + '</span></div>';\n }).join(\"\");\n return '<section class=\"flag\"><h2>' + esc(f.key) + '</h2><div class=\"summary ' + cls + '\">' + esc(f.summary) + '</div><div class=\"nodes\">' + nodes + '</div></section>';\n }).join(\"\");\n document.getElementById(\"updated\").textContent = \"members: \" + state.members.length;\n }\n async function tick() {\n try { const r = await fetch(STATE_URL); render(await r.json()); }\n catch (e) { document.getElementById(\"root\").innerHTML = '<p class=\"muted\">Could not reach ' + STATE_URL + '.</p>'; }\n }\n tick();\n setInterval(tick, 1000);\n</script>\n</body>\n</html>\n";
50
+ /** The self-contained dashboard HTML to serve from the host's admin surface. */
51
+ export declare function renderDashboardHtml(): string;
52
+ //# sourceMappingURL=dashboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../src/dashboard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACtD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC7E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,cAAc,CAkB/D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,y7GA6D1B,CAAC;AAEF,gFAAgF;AAChF,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
@@ -0,0 +1,98 @@
1
+ import { fleetState } from "./fleet.js";
2
+ /**
3
+ * The machine-readable `/state` document (§15). Identical to {@link fleetState}
4
+ * but with the 64-bit HLC fields rendered as decimal strings so it survives
5
+ * `JSON.stringify` (BigInt is not natively serializable, §7.2).
6
+ */
7
+ export function fleetStateJson(nodes) {
8
+ const state = fleetState(nodes);
9
+ return {
10
+ flags: state.flags.map((flag) => ({
11
+ ...flag,
12
+ perNode: flag.perNode.map((node) => ({
13
+ ...node,
14
+ version: node.version === undefined
15
+ ? null
16
+ : {
17
+ physical: node.version.physical.toString(),
18
+ logical: node.version.logical.toString(),
19
+ },
20
+ })),
21
+ })),
22
+ members: state.members,
23
+ };
24
+ }
25
+ /**
26
+ * A self-contained fleet/convergence dashboard (§15) — one HTML page, no build
27
+ * step and no external scripts. It polls the host-mounted `/state` endpoint
28
+ * (which should return {@link fleetStateJson}) and renders flag propagation
29
+ * across the fleet, so operators can watch a flag ripple out and spot lagging or
30
+ * partitioned nodes.
31
+ */
32
+ export const DASHBOARD_HTML = `<!doctype html>
33
+ <html lang="en">
34
+ <head>
35
+ <meta charset="utf-8" />
36
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
37
+ <title>Syntony Flags — Fleet</title>
38
+ <style>
39
+ :root { color-scheme: light dark; --ok: #1a7f37; --warn: #bf8700; --bg: #0d1117; --fg: #e6edf3; --muted: #8b949e; --card: #161b22; --line: #30363d; }
40
+ body { font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; margin: 0; background: var(--bg); color: var(--fg); }
41
+ header { padding: 16px 24px; border-bottom: 1px solid var(--line); display: flex; align-items: baseline; gap: 12px; }
42
+ h1 { font-size: 18px; margin: 0; }
43
+ .muted { color: var(--muted); font-size: 13px; }
44
+ main { padding: 24px; display: grid; gap: 16px; max-width: 1100px; }
45
+ .flag { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
46
+ .flag h2 { font-size: 15px; margin: 0 0 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
47
+ .summary { font-size: 13px; margin-bottom: 12px; }
48
+ .summary.ok { color: var(--ok); }
49
+ .summary.warn { color: var(--warn); }
50
+ .nodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
51
+ .node { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 12px; }
52
+ .node .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
53
+ .node.winner .dot { background: var(--ok); }
54
+ .node.behind .dot { background: var(--warn); }
55
+ .node.absent .dot { background: var(--muted); }
56
+ .node code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
57
+ .members { font-size: 12px; color: var(--muted); }
58
+ </style>
59
+ </head>
60
+ <body>
61
+ <header>
62
+ <h1>Syntony Flags</h1>
63
+ <span class="muted">decentralized feature flags &middot; no flag server</span>
64
+ <span class="muted" id="updated"></span>
65
+ </header>
66
+ <main id="root"><p class="muted">Loading fleet state…</p></main>
67
+ <script>
68
+ const STATE_URL = "/state";
69
+ function esc(s) { return String(s).replace(/[&<>"]/g, c => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }[c])); }
70
+ function nodeClass(n) { return n.atWinner ? "winner" : n.present ? "behind" : "absent"; }
71
+ function render(state) {
72
+ const root = document.getElementById("root");
73
+ if (!state.flags.length) { root.innerHTML = '<p class="muted">No flags set yet.</p>'; return; }
74
+ root.innerHTML = state.flags.map(f => {
75
+ const cls = f.converged ? "ok" : "warn";
76
+ const nodes = f.perNode.map(n => {
77
+ const val = n.present ? (n.deleted ? "(deleted)" : JSON.stringify(n.value)) : "—";
78
+ return '<div class="node ' + nodeClass(n) + '"><span class="dot"></span><code>' + esc(n.label) + '</code><br><span class="muted">' + esc(val) + '</span></div>';
79
+ }).join("");
80
+ return '<section class="flag"><h2>' + esc(f.key) + '</h2><div class="summary ' + cls + '">' + esc(f.summary) + '</div><div class="nodes">' + nodes + '</div></section>';
81
+ }).join("");
82
+ document.getElementById("updated").textContent = "members: " + state.members.length;
83
+ }
84
+ async function tick() {
85
+ try { const r = await fetch(STATE_URL); render(await r.json()); }
86
+ catch (e) { document.getElementById("root").innerHTML = '<p class="muted">Could not reach ' + STATE_URL + '.</p>'; }
87
+ }
88
+ tick();
89
+ setInterval(tick, 1000);
90
+ </script>
91
+ </body>
92
+ </html>
93
+ `;
94
+ /** The self-contained dashboard HTML to serve from the host's admin surface. */
95
+ export function renderDashboardHtml() {
96
+ return DASHBOARD_HTML;
97
+ }
98
+ //# sourceMappingURL=dashboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashboard.js","sourceRoot":"","sources":["../src/dashboard.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA8BxC;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAgB;IAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAChC,GAAG,IAAI;YACP,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACnC,GAAG,IAAI;gBACP,OAAO,EACL,IAAI,CAAC,OAAO,KAAK,SAAS;oBACxB,CAAC,CAAC,IAAI;oBACN,CAAC,CAAC;wBACE,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE;wBAC1C,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE;qBACzC;aACR,CAAC,CAAC;SACJ,CAAC,CAAC;QACH,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6D7B,CAAC;AAEF,gFAAgF;AAChF,MAAM,UAAU,mBAAmB;IACjC,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { Syntony } from "syntony";
2
+ import { type FlagValue } from "./codec.js";
3
+ /** Thrown when a typed accessor is used on a flag stored as a different type. */
4
+ export declare class FlagTypeError extends Error {
5
+ readonly key: string;
6
+ readonly expected: string;
7
+ readonly actual: unknown;
8
+ constructor(key: string, expected: string, actual: unknown);
9
+ }
10
+ /** An audit record for a flag, derived from per-key writer/HLC metadata (§15). */
11
+ export interface FlagAudit {
12
+ key: string;
13
+ /** Decoded value, or undefined if the flag is a tombstone. */
14
+ value: FlagValue | undefined;
15
+ /** `node_…` id of the node that last wrote the flag. */
16
+ writer: string;
17
+ /** HLC version of the write. */
18
+ version: {
19
+ physical: bigint;
20
+ logical: bigint;
21
+ };
22
+ deleted: boolean;
23
+ }
24
+ /**
25
+ * The feature-flag API (§15), layered on a Syntony node. Reads are local and
26
+ * instant; writes propagate across the fleet with no flag server. Because the
27
+ * core has no baseline, default values are supplied **at the call site**: an
28
+ * absent flag returns the caller's default.
29
+ */
30
+ export declare class Flags {
31
+ #private;
32
+ constructor(node: Syntony);
33
+ /** Set a flag from any instance; the write replicates in the background. */
34
+ set(key: string, value: FlagValue): void;
35
+ /** Remove a flag (tombstone); readers fall back to their call-site default. */
36
+ delete(key: string): void;
37
+ /** Whether a live value exists for the flag. */
38
+ isSet(key: string): boolean;
39
+ /** Live flag keys. */
40
+ keys(): string[];
41
+ /** Boolean flag, or `def` if absent (§15 call-site default). */
42
+ getBool(key: string, def: boolean): boolean;
43
+ /** Numeric flag, or `def` if absent. */
44
+ getNumber(key: string, def: number): number;
45
+ /** String flag, or `def` if absent. */
46
+ getString(key: string, def: string): string;
47
+ /** Structured (JSON) flag, or `def` if absent. The unchecked escape hatch. */
48
+ getJSON<T extends FlagValue>(key: string, def: T): T;
49
+ /** Audit record for a flag (who/what/version), or undefined if never written. */
50
+ audit(key: string): FlagAudit | undefined;
51
+ }
52
+ //# sourceMappingURL=flags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtE,iFAAiF;AACjF,qBAAa,aAAc,SAAQ,KAAK;IAEpC,QAAQ,CAAC,GAAG,EAAE,MAAM;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO;gBAFf,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO;CAO3B;AAED,kFAAkF;AAClF,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,8DAA8D;IAC9D,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,qBAAa,KAAK;;gBAGJ,IAAI,EAAE,OAAO;IAIzB,4EAA4E;IAC5E,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI;IAIxC,+EAA+E;IAC/E,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIzB,gDAAgD;IAChD,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI3B,sBAAsB;IACtB,IAAI,IAAI,MAAM,EAAE;IAShB,gEAAgE;IAChE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO;IAO3C,wCAAwC;IACxC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAO3C,uCAAuC;IACvC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAO3C,8EAA8E;IAC9E,OAAO,CAAC,CAAC,SAAS,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC;IAKpD,iFAAiF;IACjF,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;CAW1C"}
package/dist/flags.js ADDED
@@ -0,0 +1,92 @@
1
+ import { decodeValue, encodeValue } from "./codec.js";
2
+ /** Thrown when a typed accessor is used on a flag stored as a different type. */
3
+ export class FlagTypeError extends Error {
4
+ key;
5
+ expected;
6
+ actual;
7
+ constructor(key, expected, actual) {
8
+ super(`flag ${JSON.stringify(key)} is not a ${expected} (got ${typeof actual})`);
9
+ this.key = key;
10
+ this.expected = expected;
11
+ this.actual = actual;
12
+ this.name = "FlagTypeError";
13
+ }
14
+ }
15
+ /**
16
+ * The feature-flag API (§15), layered on a Syntony node. Reads are local and
17
+ * instant; writes propagate across the fleet with no flag server. Because the
18
+ * core has no baseline, default values are supplied **at the call site**: an
19
+ * absent flag returns the caller's default.
20
+ */
21
+ export class Flags {
22
+ #node;
23
+ constructor(node) {
24
+ this.#node = node;
25
+ }
26
+ /** Set a flag from any instance; the write replicates in the background. */
27
+ set(key, value) {
28
+ this.#node.set(key, encodeValue(value));
29
+ }
30
+ /** Remove a flag (tombstone); readers fall back to their call-site default. */
31
+ delete(key) {
32
+ this.#node.delete(key);
33
+ }
34
+ /** Whether a live value exists for the flag. */
35
+ isSet(key) {
36
+ return this.#node.has(key);
37
+ }
38
+ /** Live flag keys. */
39
+ keys() {
40
+ return this.#node.keys();
41
+ }
42
+ #read(key) {
43
+ const bytes = this.#node.get(key);
44
+ return bytes === undefined ? undefined : decodeValue(bytes);
45
+ }
46
+ /** Boolean flag, or `def` if absent (§15 call-site default). */
47
+ getBool(key, def) {
48
+ const value = this.#read(key);
49
+ if (value === undefined)
50
+ return def;
51
+ if (typeof value !== "boolean")
52
+ throw new FlagTypeError(key, "boolean", value);
53
+ return value;
54
+ }
55
+ /** Numeric flag, or `def` if absent. */
56
+ getNumber(key, def) {
57
+ const value = this.#read(key);
58
+ if (value === undefined)
59
+ return def;
60
+ if (typeof value !== "number")
61
+ throw new FlagTypeError(key, "number", value);
62
+ return value;
63
+ }
64
+ /** String flag, or `def` if absent. */
65
+ getString(key, def) {
66
+ const value = this.#read(key);
67
+ if (value === undefined)
68
+ return def;
69
+ if (typeof value !== "string")
70
+ throw new FlagTypeError(key, "string", value);
71
+ return value;
72
+ }
73
+ /** Structured (JSON) flag, or `def` if absent. The unchecked escape hatch. */
74
+ getJSON(key, def) {
75
+ const value = this.#read(key);
76
+ return value === undefined ? def : value;
77
+ }
78
+ /** Audit record for a flag (who/what/version), or undefined if never written. */
79
+ audit(key) {
80
+ const info = this.#node.inspect(key);
81
+ if (info === undefined)
82
+ return undefined;
83
+ return {
84
+ key,
85
+ value: this.#read(key),
86
+ writer: info.writerTypeId,
87
+ version: { physical: info.hlc.physical, logical: info.hlc.logical },
88
+ deleted: info.deleted,
89
+ };
90
+ }
91
+ }
92
+ //# sourceMappingURL=flags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flags.js","sourceRoot":"","sources":["../src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KAAK,CAAC,GAAW;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QACzC,OAAO;YACL,GAAG;YACH,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;YACtB,MAAM,EAAE,IAAI,CAAC,YAAY;YACzB,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;YACnE,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,49 @@
1
+ import { type Syntony } from "syntony";
2
+ import { type FlagValue } from "./codec.js";
3
+ /** One node's view of a single flag, as rendered by the convergence dashboard. */
4
+ export interface NodeFlagView {
5
+ node: string;
6
+ label: string;
7
+ present: boolean;
8
+ deleted: boolean;
9
+ value: FlagValue | undefined;
10
+ version: {
11
+ physical: bigint;
12
+ logical: bigint;
13
+ } | undefined;
14
+ /** Whether this node holds the winning (latest) version of the flag. */
15
+ atWinner: boolean;
16
+ }
17
+ /** Cluster-wide view of a single flag and its propagation state. */
18
+ export interface FlagFleetView {
19
+ key: string;
20
+ /** The winning (latest) value across the fleet. */
21
+ value: FlagValue | undefined;
22
+ deleted: boolean;
23
+ converged: boolean;
24
+ nodesAtWinner: number;
25
+ total: number;
26
+ propagating: number;
27
+ /** Human summary, e.g. `true on 4/5 nodes, 1 propagating`. */
28
+ summary: string;
29
+ perNode: NodeFlagView[];
30
+ }
31
+ export interface MemberView {
32
+ node: string;
33
+ label: string;
34
+ status: string;
35
+ address: string;
36
+ }
37
+ /** The JSON document the fleet/convergence dashboard renders (§15). */
38
+ export interface FleetState {
39
+ flags: FlagFleetView[];
40
+ members: MemberView[];
41
+ }
42
+ /**
43
+ * Compute the cluster-wide convergence view across a set of in-process nodes
44
+ * (§15). For each flag, finds the winning version, then reports how many nodes
45
+ * already hold it and how many are still propagating — turning eventual
46
+ * consistency into something an operator can watch.
47
+ */
48
+ export declare function fleetState(nodes: Syntony[]): FleetState;
49
+ //# sourceMappingURL=fleet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleet.d.ts","sourceRoot":"","sources":["../src/fleet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAC9F,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEzD,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAC3D,wEAAwE;IACxE,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,mDAAmD;IACnD,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,uEAAuE;AACvE,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAcD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,UAAU,CA8EvD"}
package/dist/fleet.js ADDED
@@ -0,0 +1,95 @@
1
+ import { NodeStatus, compareHlc, compareWriter } from "syntony";
2
+ import { decodeValue } from "./codec.js";
3
+ /** Whether two versions are the identical write (same HLC and writer). */
4
+ function sameVersion(a, b) {
5
+ return compareHlc(a.hlc, b.hlc) === 0 && compareWriter(a.writer, b.writer) === 0;
6
+ }
7
+ /** Whether `candidate` is a strictly later version than `current` (LWW order). */
8
+ function isLater(candidate, current) {
9
+ const c = compareHlc(candidate.hlc, current.hlc);
10
+ if (c !== 0)
11
+ return c > 0;
12
+ return compareWriter(candidate.writer, current.writer) > 0;
13
+ }
14
+ /**
15
+ * Compute the cluster-wide convergence view across a set of in-process nodes
16
+ * (§15). For each flag, finds the winning version, then reports how many nodes
17
+ * already hold it and how many are still propagating — turning eventual
18
+ * consistency into something an operator can watch.
19
+ */
20
+ export function fleetState(nodes) {
21
+ const allKeys = new Set();
22
+ for (const node of nodes) {
23
+ for (const key of node.engine.snapshot().keys())
24
+ allKeys.add(key);
25
+ }
26
+ const flags = [];
27
+ for (const key of [...allKeys].sort()) {
28
+ const holders = nodes.map((node) => ({ node, info: node.engine.inspect(key) }));
29
+ let winner;
30
+ for (const { node, info } of holders) {
31
+ if (info === undefined)
32
+ continue;
33
+ if (winner === undefined || isLater(info, winner.info))
34
+ winner = { node, info };
35
+ }
36
+ if (winner === undefined)
37
+ continue;
38
+ const winnerBytes = winner.node.get(key);
39
+ const winnerValue = winnerBytes === undefined ? undefined : decodeValue(winnerBytes);
40
+ const perNode = holders.map(({ node, info }) => {
41
+ const self = node.self();
42
+ if (info === undefined) {
43
+ return {
44
+ node: self.typeIdStr,
45
+ label: self.label,
46
+ present: false,
47
+ deleted: false,
48
+ value: undefined,
49
+ version: undefined,
50
+ atWinner: false,
51
+ };
52
+ }
53
+ const bytes = node.get(key);
54
+ return {
55
+ node: self.typeIdStr,
56
+ label: self.label,
57
+ present: true,
58
+ deleted: info.deleted,
59
+ value: bytes === undefined ? undefined : decodeValue(bytes),
60
+ version: { physical: info.hlc.physical, logical: info.hlc.logical },
61
+ atWinner: sameVersion(info, winner.info),
62
+ };
63
+ });
64
+ const total = nodes.length;
65
+ const nodesAtWinner = perNode.filter((n) => n.atWinner).length;
66
+ const propagating = total - nodesAtWinner;
67
+ const converged = propagating === 0;
68
+ const valueLabel = winner.info.deleted ? "(deleted)" : JSON.stringify(winnerValue);
69
+ const summary = converged
70
+ ? `${valueLabel} on ${total}/${total} nodes (converged)`
71
+ : `${valueLabel} on ${nodesAtWinner}/${total} nodes, ${propagating} propagating`;
72
+ flags.push({
73
+ key,
74
+ value: winnerValue,
75
+ deleted: winner.info.deleted,
76
+ converged,
77
+ nodesAtWinner,
78
+ total,
79
+ propagating,
80
+ summary,
81
+ perNode,
82
+ });
83
+ }
84
+ const members = nodes.map((node) => {
85
+ const self = node.self();
86
+ return {
87
+ node: self.typeIdStr,
88
+ label: self.label,
89
+ status: NodeStatus[self.status],
90
+ address: self.grpcAddress,
91
+ };
92
+ });
93
+ return { flags, members };
94
+ }
95
+ //# sourceMappingURL=fleet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleet.js","sourceRoot":"","sources":["../src/fleet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAgC,MAAM,SAAS,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAkB,MAAM,YAAY,CAAC;AA0CzD,0EAA0E;AAC1E,SAAS,WAAW,CAAC,CAAY,EAAE,CAAY;IAC7C,OAAO,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,aAAa,C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"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * syntony-flag — a feature-flag / dynamic-config system with no flag server.
3
+ * Flags live, replicated, inside your application instances, on top of the
4
+ * Syntony decentralized state primitive (§15).
5
+ */
6
+ export { Flags, FlagTypeError, type FlagAudit } from "./flags.js";
7
+ export { encodeValue, decodeValue, type FlagValue, type FlagJson } from "./codec.js";
8
+ export { fleetState, type FleetState, type FlagFleetView, type NodeFlagView, type MemberView, } from "./fleet.js";
9
+ export { fleetStateJson, renderDashboardHtml, DASHBOARD_HTML, type FleetStateJson, type FlagFleetViewJson, type NodeFlagViewJson, } from "./dashboard.js";
10
+ export { Syntony, MemoryHub, type SyntonyOptions } from "syntony";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,EACL,UAAU,EACV,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,UAAU,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * syntony-flag — a feature-flag / dynamic-config system with no flag server.
3
+ * Flags live, replicated, inside your application instances, on top of the
4
+ * Syntony decentralized state primitive (§15).
5
+ */
6
+ export { Flags, FlagTypeError } from "./flags.js";
7
+ export { encodeValue, decodeValue } from "./codec.js";
8
+ export { fleetState, } from "./fleet.js";
9
+ export { fleetStateJson, renderDashboardHtml, DASHBOARD_HTML, } from "./dashboard.js";
10
+ // Re-exported from the core so a consumer can stand up a node without a second
11
+ // import.
12
+ export { Syntony, MemoryHub } from "syntony";
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAiC,MAAM,YAAY,CAAC;AACrF,OAAO,EACL,UAAU,GAKX,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,cAAc,GAIf,MAAM,gBAAgB,CAAC;AAExB,+EAA+E;AAC/E,UAAU;AACV,OAAO,EAAE,OAAO,EAAE,SAAS,EAAuB,MAAM,SAAS,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "syntony-flag",
3
+ "version": "0.1.0",
4
+ "description": "A feature-flag / dynamic-config system with no flag server. Flags live, replicated, inside your application instances — built on the Syntony decentralized state primitive.",
5
+ "license": "Apache-2.0",
6
+ "author": "Jorge Jimenez <npm@jorgejim.com>",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "type": "module",
11
+ "main": "./dist/index.js",
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "engines": {
24
+ "node": ">=20"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.build.json",
28
+ "typecheck": "tsc --noEmit",
29
+ "test": "vitest run",
30
+ "test:watch": "vitest",
31
+ "prepublishOnly": "npm run build"
32
+ },
33
+ "keywords": [
34
+ "feature-flags",
35
+ "dynamic-config",
36
+ "openfeature",
37
+ "decentralized",
38
+ "syntony"
39
+ ],
40
+ "dependencies": {
41
+ "syntony": "^0.1.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^22.19.21",
45
+ "typescript": "^5.7.2",
46
+ "vitest": "^2.1.8"
47
+ }
48
+ }