@alecsibilia/ui-kit 0.0.0-stage → 0.1.0-alpha.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/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/README.md +233 -2
- package/bin/ui-kit.js +12 -0
- package/dist/alchemy/app.d.ts +34 -0
- package/dist/alchemy/app.js +88 -0
- package/dist/alchemy/index.d.ts +11 -0
- package/dist/alchemy/index.js +11 -0
- package/dist/alchemy/live-rooms.d.ts +21 -0
- package/dist/alchemy/live-rooms.js +31 -0
- package/dist/alchemy/migrations.d.ts +28 -0
- package/dist/alchemy/migrations.js +56 -0
- package/dist/alchemy/stage.d.ts +20 -0
- package/dist/alchemy/stage.js +20 -0
- package/dist/alchemy/wrangler-config.d.ts +76 -0
- package/dist/alchemy/wrangler-config.js +82 -0
- package/dist/build/app-modules.d.ts +11 -0
- package/dist/build/app-modules.js +40 -0
- package/dist/build/check.d.ts +4 -0
- package/dist/build/check.js +170 -0
- package/dist/build/cli.d.ts +1 -0
- package/dist/build/cli.js +79 -0
- package/dist/build/feature.d.ts +8 -0
- package/dist/build/feature.js +24 -0
- package/dist/build/index.d.ts +13 -0
- package/dist/build/index.js +13 -0
- package/dist/build/measure-cpu.d.ts +2 -0
- package/dist/build/measure-cpu.js +196 -0
- package/dist/build/prerender.d.ts +5 -0
- package/dist/build/prerender.js +109 -0
- package/dist/build/preview.d.ts +7 -0
- package/dist/build/preview.js +41 -0
- package/dist/build/seo-files.d.ts +27 -0
- package/dist/build/seo-files.js +24 -0
- package/dist/client/head-swap.d.ts +45 -0
- package/dist/client/head-swap.js +183 -0
- package/dist/client/hydration-pass.d.ts +56 -0
- package/dist/client/hydration-pass.js +186 -0
- package/dist/client/hydration-reset.d.ts +82 -0
- package/dist/client/hydration-reset.js +154 -0
- package/dist/client/index.d.ts +37 -0
- package/dist/client/index.js +65 -0
- package/dist/client/nav-client.d.ts +35 -0
- package/dist/client/nav-client.js +371 -0
- package/dist/live/collab/doc-provider.d.ts +74 -0
- package/dist/live/collab/doc-provider.js +412 -0
- package/dist/live/collab/index.d.ts +51 -0
- package/dist/live/collab/index.jsx +142 -0
- package/dist/live/collab-status.d.ts +25 -0
- package/dist/live/collab-status.js +17 -0
- package/dist/live/cursors/cursor-engine.d.ts +57 -0
- package/dist/live/cursors/cursor-engine.js +243 -0
- package/dist/live/cursors/index.d.ts +46 -0
- package/dist/live/cursors/index.jsx +110 -0
- package/dist/live/declaration.d.ts +113 -0
- package/dist/live/declaration.js +94 -0
- package/dist/live/index.d.ts +8 -0
- package/dist/live/index.js +8 -0
- package/dist/live/protocol.d.ts +224 -0
- package/dist/live/protocol.js +272 -0
- package/dist/live/server/doc-store.d.ts +68 -0
- package/dist/live/server/doc-store.js +187 -0
- package/dist/live/server/index.d.ts +60 -0
- package/dist/live/server/index.js +77 -0
- package/dist/live/server/room-presence.d.ts +24 -0
- package/dist/live/server/room-presence.js +123 -0
- package/dist/live/server/room-sockets.d.ts +65 -0
- package/dist/live/server/room-sockets.js +97 -0
- package/dist/live/server/room.d.ts +20 -0
- package/dist/live/server/room.js +348 -0
- package/dist/live/server/route.d.ts +56 -0
- package/dist/live/server/route.js +159 -0
- package/dist/live/server/types.d.ts +163 -0
- package/dist/live/server/types.js +2 -0
- package/dist/logic/agent-actions.d.ts +133 -0
- package/dist/logic/agent-actions.js +150 -0
- package/dist/logic/command-types.d.ts +53 -0
- package/dist/logic/command-types.js +0 -0
- package/dist/logic/dev.d.ts +9 -0
- package/dist/logic/dev.js +10 -0
- package/dist/logic/draft-rebase.d.ts +59 -0
- package/dist/logic/draft-rebase.js +71 -0
- package/dist/logic/form-state.d.ts +105 -0
- package/dist/logic/form-state.js +93 -0
- package/dist/logic/head.d.ts +145 -0
- package/dist/logic/head.js +140 -0
- package/dist/logic/index.d.ts +27 -0
- package/dist/logic/index.js +25 -0
- package/dist/logic/island-def.d.ts +89 -0
- package/dist/logic/island-def.js +59 -0
- package/dist/logic/kit-commands.d.ts +104 -0
- package/dist/logic/kit-commands.js +72 -0
- package/dist/logic/kit-errors.d.ts +25 -0
- package/dist/logic/kit-errors.js +6 -0
- package/dist/logic/listen.d.ts +99 -0
- package/dist/logic/listen.js +92 -0
- package/dist/logic/mutation-def.d.ts +65 -0
- package/dist/logic/mutation-def.js +43 -0
- package/dist/logic/navigation-data.d.ts +50 -0
- package/dist/logic/navigation-data.js +55 -0
- package/dist/logic/navigation-policy.d.ts +74 -0
- package/dist/logic/navigation-policy.js +127 -0
- package/dist/logic/page-model-def.d.ts +108 -0
- package/dist/logic/page-model-def.js +31 -0
- package/dist/logic/path.d.ts +31 -0
- package/dist/logic/path.js +48 -0
- package/dist/logic/query-def.d.ts +56 -0
- package/dist/logic/query-def.js +37 -0
- package/dist/logic/query-key.d.ts +24 -0
- package/dist/logic/query-key.js +35 -0
- package/dist/logic/query-types.d.ts +28 -0
- package/dist/logic/query-types.js +2 -0
- package/dist/logic/resources.d.ts +163 -0
- package/dist/logic/resources.js +62 -0
- package/dist/logic/result.d.ts +30 -0
- package/dist/logic/result.js +23 -0
- package/dist/logic/route-model.d.ts +139 -0
- package/dist/logic/route-model.js +207 -0
- package/dist/logic/route-params.d.ts +80 -0
- package/dist/logic/route-params.js +114 -0
- package/dist/logic/route-table.d.ts +308 -0
- package/dist/logic/route-table.js +206 -0
- package/dist/logic/seo.d.ts +61 -0
- package/dist/logic/seo.js +101 -0
- package/dist/logic/site.d.ts +12 -0
- package/dist/logic/site.js +0 -0
- package/dist/logic/subscriptions.d.ts +177 -0
- package/dist/logic/subscriptions.js +152 -0
- package/dist/render/index.d.ts +32 -0
- package/dist/render/index.js +52 -0
- package/dist/runtime/island-wake.d.ts +38 -0
- package/dist/runtime/island-wake.js +147 -0
- package/dist/runtime/query-scope.d.ts +224 -0
- package/dist/runtime/query-scope.js +222 -0
- package/dist/runtime/room-hub.d.ts +107 -0
- package/dist/runtime/room-hub.js +307 -0
- package/dist/runtime/subscription-runner.d.ts +71 -0
- package/dist/runtime/subscription-runner.js +240 -0
- package/dist/server/bindings.d.ts +41 -0
- package/dist/server/bindings.js +74 -0
- package/dist/server/browser.d.ts +9 -0
- package/dist/server/browser.js +9 -0
- package/dist/server/edge-cache.d.ts +28 -0
- package/dist/server/edge-cache.js +35 -0
- package/dist/server/errors.d.ts +45 -0
- package/dist/server/errors.js +36 -0
- package/dist/server/form-actions-setup.d.ts +1 -0
- package/dist/server/form-actions-setup.js +15 -0
- package/dist/server/form-actions.d.ts +121 -0
- package/dist/server/form-actions.js +211 -0
- package/dist/server/index.d.ts +36 -0
- package/dist/server/index.js +35 -0
- package/dist/server/inputs.d.ts +45 -0
- package/dist/server/inputs.js +77 -0
- package/dist/server/rate-limit.d.ts +29 -0
- package/dist/server/rate-limit.js +32 -0
- package/dist/server/read-cache.d.ts +74 -0
- package/dist/server/read-cache.js +58 -0
- package/dist/server/request-info.d.ts +17 -0
- package/dist/server/request-info.js +11 -0
- package/dist/server/request.d.ts +52 -0
- package/dist/server/request.js +73 -0
- package/dist/server/response-cookies.d.ts +23 -0
- package/dist/server/response-cookies.js +24 -0
- package/dist/server/run-effect.d.ts +42 -0
- package/dist/server/run-effect.js +92 -0
- package/dist/server/run.d.ts +63 -0
- package/dist/server/run.js +66 -0
- package/dist/server/session.d.ts +125 -0
- package/dist/server/session.js +247 -0
- package/dist/test/fake-bindings.d.ts +32 -0
- package/dist/test/fake-bindings.js +108 -0
- package/dist/test/fake-room.d.ts +66 -0
- package/dist/test/fake-room.js +216 -0
- package/dist/test/index.d.ts +19 -0
- package/dist/test/index.js +44 -0
- package/dist/test/probe.d.ts +11 -0
- package/dist/test/probe.js +11 -0
- package/dist/test/solid-jsx.d.ts +23 -0
- package/dist/test/solid-jsx.js +28 -0
- package/dist/test/solid-preload.d.ts +1 -0
- package/dist/test/solid-preload.js +29 -0
- package/dist/ui/code-editor/index.d.ts +21 -0
- package/dist/ui/code-editor/index.jsx +286 -0
- package/dist/ui/collab-text/index.d.ts +29 -0
- package/dist/ui/collab-text/index.jsx +96 -0
- package/dist/ui/components/controls.d.ts +69 -0
- package/dist/ui/components/controls.jsx +81 -0
- package/dist/ui/components/feedback.d.ts +26 -0
- package/dist/ui/components/feedback.jsx +80 -0
- package/dist/ui/components/layout.d.ts +74 -0
- package/dist/ui/components/layout.jsx +146 -0
- package/dist/ui/components/lists.d.ts +69 -0
- package/dist/ui/components/lists.jsx +133 -0
- package/dist/ui/components/navigation.d.ts +73 -0
- package/dist/ui/components/navigation.jsx +112 -0
- package/dist/ui/components/text.d.ts +34 -0
- package/dist/ui/components/text.jsx +163 -0
- package/dist/ui/index.d.ts +7 -0
- package/dist/ui/index.js +7 -0
- package/dist/ui/jsx-runtime.d.ts +19 -0
- package/dist/ui/jsx-runtime.js +0 -0
- package/dist/ui/list-keys.d.ts +31 -0
- package/dist/ui/list-keys.js +45 -0
- package/dist/ui/styles/base.css +38 -0
- package/dist/ui/styles/components.css +608 -0
- package/dist/ui/styles/tokens.css +27 -0
- package/dist/ui/styles/transitions.css +23 -0
- package/dist/ui/styles/workbench.css +428 -0
- package/dist/ui/styles.css +9 -0
- package/dist/view/agent-actions-view.d.ts +30 -0
- package/dist/view/agent-actions-view.js +27 -0
- package/dist/view/agent-surface.d.ts +42 -0
- package/dist/view/agent-surface.js +123 -0
- package/dist/view/app-scope.d.ts +51 -0
- package/dist/view/app-scope.js +75 -0
- package/dist/view/boundary.d.ts +18 -0
- package/dist/view/boundary.jsx +26 -0
- package/dist/view/command-runner.d.ts +16 -0
- package/dist/view/command-runner.js +245 -0
- package/dist/view/form.d.ts +82 -0
- package/dist/view/form.jsx +109 -0
- package/dist/view/head-view.d.ts +31 -0
- package/dist/view/head-view.js +46 -0
- package/dist/view/index.d.ts +41 -0
- package/dist/view/index.js +40 -0
- package/dist/view/island-root.d.ts +30 -0
- package/dist/view/island-root.js +36 -0
- package/dist/view/island.d.ts +102 -0
- package/dist/view/island.jsx +154 -0
- package/dist/view/match.d.ts +41 -0
- package/dist/view/match.js +111 -0
- package/dist/view/model.d.ts +92 -0
- package/dist/view/model.js +162 -0
- package/dist/view/navigation-head.d.ts +29 -0
- package/dist/view/navigation-head.jsx +38 -0
- package/dist/view/page-model.d.ts +46 -0
- package/dist/view/page-model.js +146 -0
- package/dist/view/query-effects.d.ts +87 -0
- package/dist/view/query-effects.js +147 -0
- package/dist/view/query-ok.d.ts +45 -0
- package/dist/view/query-ok.js +96 -0
- package/dist/view/query.d.ts +115 -0
- package/dist/view/query.jsx +179 -0
- package/dist/view/result-view.d.ts +14 -0
- package/dist/view/result-view.jsx +15 -0
- package/dist/view/route-pages.d.ts +43 -0
- package/dist/view/route-pages.js +59 -0
- package/dist/view/router.d.ts +44 -0
- package/dist/view/router.js +123 -0
- package/dist/vite/dev-middleware.d.ts +12 -0
- package/dist/vite/dev-middleware.js +39 -0
- package/dist/vite/dev-objects.d.ts +25 -0
- package/dist/vite/dev-objects.js +127 -0
- package/dist/vite/dev-platform.d.ts +19 -0
- package/dist/vite/dev-platform.js +77 -0
- package/dist/vite/dev-seo-files.d.ts +11 -0
- package/dist/vite/dev-seo-files.js +40 -0
- package/dist/vite/index.d.ts +53 -0
- package/dist/vite/index.js +148 -0
- package/dist/vite/local-config.d.ts +34 -0
- package/dist/vite/local-config.js +72 -0
- package/dist/vite/worker-build.d.ts +24 -0
- package/dist/vite/worker-build.js +84 -0
- package/dist/worker/create-worker.d.ts +52 -0
- package/dist/worker/create-worker.js +90 -0
- package/dist/worker/index.d.ts +12 -0
- package/dist/worker/index.js +12 -0
- package/dist/worker/page-routes.d.ts +88 -0
- package/dist/worker/page-routes.js +100 -0
- package/dist/worker/page-status.d.ts +41 -0
- package/dist/worker/page-status.js +23 -0
- package/dist/worker/request-prelude.d.ts +69 -0
- package/dist/worker/request-prelude.js +107 -0
- package/dist/worker/security.d.ts +76 -0
- package/dist/worker/security.js +137 -0
- package/dist/worker/server-app.d.ts +54 -0
- package/dist/worker/server-app.js +76 -0
- package/guards/browser-only.js +5 -0
- package/guards/node-only.js +6 -0
- package/guards/server-only.js +5 -0
- package/migrations/0001-sessions.sql +22 -0
- package/package.json +233 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @alecsibilia/ui-kit
|
|
2
|
+
|
|
3
|
+
## 0.1.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7def564: Bring in the UI kit (`@alecsibilia/ui-kit`: Foldkit-style models, islands, live rooms, and the Worker, Vite, build and Alchemy plumbing for Cloudflare Workers apps on Solid 2 and Effect 4) and its lint plugin (`@alecsibilia/oxlint-plugin-ui-kit`), from the spike. Not published yet.
|
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
|
|
95
|
+
Derivative 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
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying 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
CHANGED
|
@@ -1,3 +1,234 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @alecsibilia/ui-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A UI kit for apps on Cloudflare Workers, built on Solid 2 and Effect 4. It gives an app Foldkit's structure (pure models, Messages, Commands) with Solid's fine-grained speed, renders every page as static server HTML with islands, and owns the plumbing around it: the Worker entry, the Vite setup, the build steps, sessions, read caching, rate limits, live rooms and the Alchemy stack, all derived from one resource declaration.
|
|
4
|
+
|
|
5
|
+
The demo app, [`packages/ui-kit-demo`](../ui-kit-demo/README.md), uses every part. The rules and the reasons behind them are in the guides:
|
|
6
|
+
|
|
7
|
+
| Guide | What it covers |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| [ui-kit-rules.md](../../docs/guides/ui-kit-rules.md) | The framework rules and the owner's decisions |
|
|
10
|
+
| [ui-kit-architecture.md](../../docs/guides/ui-kit-architecture.md) | The app architecture the kit imposes: data flow, rendering, page models, navigation, hosting costs, surprises, open questions |
|
|
11
|
+
| [ui-kit-structure.md](../../docs/guides/ui-kit-structure.md) | Packages and subpaths, the layer-first app layout, the import matrix, lint and structure checks, `snake_case` |
|
|
12
|
+
| [ui-kit-live-rooms.md](../../docs/guides/ui-kit-live-rooms.md) | Presence, live cursors and collaborative docs on Durable Objects |
|
|
13
|
+
| [ui-kit-page-transitions.md](../../docs/guides/ui-kit-page-transitions.md) | View transitions, speculation rules and client navigation by named section |
|
|
14
|
+
|
|
15
|
+
## Stack
|
|
16
|
+
|
|
17
|
+
| Layer | Choice |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| Hosting | Cloudflare Workers (Paid), Workers Static Assets |
|
|
20
|
+
| Data | D1, R2, Durable Objects, Workers Rate Limiting, Workers Cache |
|
|
21
|
+
| Infra as code | Alchemy 2 |
|
|
22
|
+
| UI | Solid 2.0.4 (`solid-js`, `@solidjs/web`, `@solidjs/vite-plugin`) |
|
|
23
|
+
| Server logic | Effect 4 (server only: no Effect runtime in client chunks) |
|
|
24
|
+
| Tooling | Bun, Vite 8, TypeScript 7, oxlint, oxfmt |
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
Published to npm as alphas, under the `alpha` tag (inside this repo, apps use `workspace:*`; how it's released: [docs/guides/ui-kit-publishing.md](../../docs/guides/ui-kit-publishing.md)):
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
bun add @alecsibilia/ui-kit@alpha solid-js@2.0.4 @solidjs/web@2.0.4 effect@4.2.0
|
|
32
|
+
bun add -d vite@8.4.1 @solidjs/vite-plugin@3.0.1 wrangler@4.158.0 \
|
|
33
|
+
alchemy@2.0.0-beta.87 @alchemy.run/cloudflare@2.0.0-beta.87 \
|
|
34
|
+
oxlint @alecsibilia/oxlint-plugin-ui-kit@alpha @solidjs/compiler@2.0.3
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
A repo with a `bunfig.toml` `minimumReleaseAge` refuses a fresh alpha; add both packages to its `minimumReleaseAgeExcludes`.
|
|
38
|
+
|
|
39
|
+
Peer dependencies are pinned exactly where the kit depends on their internals: `solid-js` and `@solidjs/web` 2.0.4 (the client navigation's hydration reset is checked against them), `effect` 4.2.0, `@solidjs/vite-plugin` 3.0.1, Alchemy 2.0.0-beta.87 and `wrangler` 4.158.0. `vite` is `^8.4.1`. The tooling peers (Vite, the Solid plugin, wrangler, Alchemy) are optional for code that doesn't build or deploy. Yjs and CodeMirror are the kit's own dependencies, reachable only through browser-only subpaths.
|
|
40
|
+
|
|
41
|
+
The app's `tsconfig.json` sets `"jsx": "preserve"` and `"jsxImportSource": "@alecsibilia/ui-kit/ui"`: app JSX is the kit's closed set, so a raw HTML tag is a type error.
|
|
42
|
+
|
|
43
|
+
## Subpaths
|
|
44
|
+
|
|
45
|
+
There is no bare import: every import names its layer. Each subpath is one folder, `src/<subpath>/`. Export conditions guard the wrong side: a server-only subpath in a browser bundle, or a browser-only one in the Worker, fails the build.
|
|
46
|
+
|
|
47
|
+
| Subpath | Runs in | Holds |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| `/logic` | everywhere (no Solid, Effect or DOM) | Models' building blocks: `matchTag`, `Result`, query and mutation registries, kit Commands (`refetch`, `navigate`, ...), subscriptions as data (`every`, `channel`, `presence`, `roomSaved`), `listen`, the route table (`RouteTable`, `lazyPage`, `searchParam`, `hrefFor`), island and page model definitions (`defineIslands`, `definePageModel`), head and SEO data, form state, `rebaseDraft`, agent actions, `defineResources`, the kit errors' plain shapes |
|
|
50
|
+
| `/view` | server and browser (Solid) | `createModel`, `usePageModel`, `<Query>`, `<Island>`, `<Match>`, `<Form>`, `<Head>`, `<AppScope>`, `<PageNavigation>`, `<PageBoundary>`, `createRoutePages`, `For` |
|
|
51
|
+
| `/ui`, `/ui/jsx-runtime`, `/ui/styles.css` | server and browser | The closed component set (layout, text, controls, lists, feedback, navigation, `<CursorSurface>`), its JSX runtime and styles |
|
|
52
|
+
| `/ui/code-editor`, `/ui/collab-text` | browser only | CodeMirror surfaces (lazy islands only) |
|
|
53
|
+
| `/client` | browser only | `startIslands`: the hydration pass, lazy island wake, client navigation |
|
|
54
|
+
| `/render` | server only | `createPageRenderer` (strips every script from a page with no island) |
|
|
55
|
+
| `/server` | server only (Effect) | `GET`, `createRunner` (`runApp`, `runRead`, `runWithEnv`), `createSessions`, `bindingsOf`, `Bindings`, `Session`, `EdgeCache`, `ResponseCookies`, `RequestInfo`, `rateLimit`, `sharedRead` / `PRIVATE_READ`, `decodeInput` / `NoInput` / `IdInput`, the errors `ValidationFailed` / `Unauthorized` / `RateLimited` |
|
|
56
|
+
| `/live` | everywhere | `declareLiveRooms`, typed room and doc refs, the wire protocol |
|
|
57
|
+
| `/live/server` | Worker and Durable Object | `createLiveRooms` (the Worker route and the room class), hook types, `isAllowedOrigin` |
|
|
58
|
+
| `/live/cursors` | browser island | `<LiveCursors room>` |
|
|
59
|
+
| `/live/collab` | browser only | `<CollabText doc send>` (Yjs) |
|
|
60
|
+
| `/worker` | Worker | `createWorker`, `defineServerApp`: the request prelude, security headers and CSP, the 404 split, page status probes, the sessions cron |
|
|
61
|
+
| `/vite` | Node (Vite) | `uiKit({ resources })`: Solid, the Worker build, the prerender build, dev bindings, the dev Durable Object Worker, dev SEO files |
|
|
62
|
+
| `/build` | Bun | The `ui-kit` command |
|
|
63
|
+
| `/alchemy` | Node | `uiKitApp`: the Alchemy stack, stage naming (`prod`, `pr-<n>`), migrations |
|
|
64
|
+
| `/test` | `bun test` | `story()`, `fakeD1` / `fakeR2` / `fakeRateLimit`, `fakeRoom` and friends |
|
|
65
|
+
|
|
66
|
+
Also exported: `/server/form-actions-setup` (installed by the Vite plugin) and `/migrations/*` (the kit's `sessions` table).
|
|
67
|
+
|
|
68
|
+
## A minimal app
|
|
69
|
+
|
|
70
|
+
A layer-first app (see [ui-kit-structure.md](../../docs/guides/ui-kit-structure.md)). The demo has a full version of each file.
|
|
71
|
+
|
|
72
|
+
**1. Resources, declared once** (`src/resources.ts`). Alchemy, local workerd and the typed server bindings all come from this.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
export const resources = defineResources({
|
|
76
|
+
name: 'my-app',
|
|
77
|
+
compatibility: { date: '2026-11-01', flags: ['nodejs_compat'] },
|
|
78
|
+
d1: { DB: { migrations: 'migrations' } },
|
|
79
|
+
sessions: { database: 'DB' }, // the kit's sessions table and its cleanup cron
|
|
80
|
+
readCache: true, // Workers Cache in front of the Worker
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**2. Routes** (`src/routes.ts`): path, render mode, head, a lazy page.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
export const routes = {
|
|
88
|
+
Home: {
|
|
89
|
+
path: '/',
|
|
90
|
+
render: 'ssr',
|
|
91
|
+
head: { title: 'Notes', description: 'Your notes.' },
|
|
92
|
+
page: lazyPage(() => import('./pages/home-page.tsx')),
|
|
93
|
+
},
|
|
94
|
+
NotFound: { path: null, render: 'ssr', head: { title: 'Not found', description: '...', robots: 'noindex' }, page: lazyPage(() => import('./pages/not-found-page.tsx')) },
|
|
95
|
+
} as const satisfies RouteTable
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**3. Server: a schema, a service, a program, a function.**
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// src/schemas/notes.schema.ts: wire keys are snake_case
|
|
102
|
+
export const NoteSchema = Schema.Struct({ note_id: Schema.String, text: Schema.String, saved_at: Schema.Number })
|
|
103
|
+
|
|
104
|
+
// src/server/layer.ts
|
|
105
|
+
export const AppLayer = Layer.mergeAll(NotesRepo.layer) // Context.Service classes, built once
|
|
106
|
+
export const { runApp, runRead, runWithEnv, callServicesLayer } = createRunner({ resources, layer: AppLayer })
|
|
107
|
+
|
|
108
|
+
// src/server/programs/notes.programs.ts: decode the raw input first
|
|
109
|
+
export const getNoteProgram = (raw: unknown) =>
|
|
110
|
+
Effect.gen(function* () {
|
|
111
|
+
const id = yield* decodeInput(IdInput, 'note id')(raw)
|
|
112
|
+
return yield* (yield* NotesRepo).get(id)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
// src/server/functions/notes.server.ts: every export is a public endpoint
|
|
116
|
+
export const loadNote = GET(async (id: string) => {
|
|
117
|
+
'use server'
|
|
118
|
+
return runRead(PRIVATE_READ, getNoteProgram(id))
|
|
119
|
+
})
|
|
120
|
+
export async function saveNote(input: SaveNoteInput) {
|
|
121
|
+
'use server'
|
|
122
|
+
return runApp(saveNoteProgram(input))
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**4. Registries**: the only importers of server functions.
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
export const notesQueries = createQueryRegistry('notes', { note: loadNote })
|
|
130
|
+
export const notesMutations = createMutationRegistry('notes', {
|
|
131
|
+
save: { run: saveNote, invalidates: [notesQueries.note] },
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**5. A model, a view, an island.**
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
// src/models/notes.model.ts: pure; tested with story()
|
|
139
|
+
export const initNotes = { draft: Draft.None, saveState: SaveState.Idle }
|
|
140
|
+
export function updateNotes(model, msg) {
|
|
141
|
+
return matchTag(msg, {
|
|
142
|
+
Edited: ({ text }) => [{ ...model, draft: Draft.editing(text) }, [{ _tag: 'Save', text }]],
|
|
143
|
+
Saved: ({ result }) => [{ ...model, saveState: savedStateOf(result) }, []],
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/commands/notes.commands.ts
|
|
148
|
+
export const notesCommands: CommandHandlers<NotesCommand, NotesMsg> = {
|
|
149
|
+
Save: (cmd, ctx) => ctx.mutate(notesMutations.save, { text: cmd.text }, (result) => ({ _tag: 'Saved', result })),
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/islands/notes-island.tsx: reads state, sends Messages, decides nothing
|
|
153
|
+
export default function NotesIsland(props: { readonly noteId: string }) {
|
|
154
|
+
const [model, send] = createModel({ init: initNotes, update: updateNotes, commands: notesCommands })
|
|
155
|
+
return (
|
|
156
|
+
<Query query={notesQueries.note} input={props.noteId} pending={<Spinner label="Loading..." />}
|
|
157
|
+
ok={(note) => <NoteEditor text={shownText(model(), note)} send={send} />} />
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/islands.ts
|
|
162
|
+
export const islands = defineIslands({
|
|
163
|
+
notes: { wake: 'load', load: () => import('./islands/notes-island.tsx') },
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
// src/pages/home-page.tsx: static server HTML around the island
|
|
167
|
+
export default function HomePage() {
|
|
168
|
+
return <Stack gap="lg"><Header title="Notes" /><Island of={islands.notes} props={{ noteId: 'first' }} /></Stack>
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Islands that share state use a page model: `definePageModel({ name, init: ({ url }) => ..., update, commands })` in `src/page-models/`, read with `usePageModel(def)` in each island.
|
|
173
|
+
|
|
174
|
+
**6. The shell and entries.** `src/app.tsx` (`<AppScope>` + `createRoutePages(routes)`), `src/document.tsx` (the HTML document, `<PageNavigation routes>` in the head), `src/entry-client.tsx` (`startIslands(islands, siteSettings)`) and `src/entry-server.tsx` (`createPageRenderer({ manifest, Document, App })`). Copy the demo's: they are a few lines each.
|
|
175
|
+
|
|
176
|
+
**7. The Worker** (`worker/server-app.ts`, `worker/index.ts`).
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
export const serverApp = defineServerApp({
|
|
180
|
+
routes,
|
|
181
|
+
resources,
|
|
182
|
+
runner: { runApp, runRead, runWithEnv, callServicesLayer },
|
|
183
|
+
sessions, // createSessions({ resources, lookupUser, onEnded }): the app owns users
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
import { handleRequest } from 'virtual:solid-ssr-handler'
|
|
187
|
+
export default createWorker({ app: serverApp, render: handleRequest })
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
An app with Durable Objects also exports their classes from `worker/objects.ts` (re-exported by `worker/index.ts`) and routes their sockets with `live` (`worker/live.ts`; see [ui-kit-live-rooms.md](../../docs/guides/ui-kit-live-rooms.md)).
|
|
191
|
+
|
|
192
|
+
**8. Vite and Alchemy.**
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
// vite.config.ts
|
|
196
|
+
export default defineConfig({ plugins: [uiKit({ resources })] })
|
|
197
|
+
|
|
198
|
+
// alchemy.run.ts: deployed by the deploy workflow only (`bunx alchemy deploy --stage prod`, under Node)
|
|
199
|
+
export default uiKitApp(resources, { appDir: import.meta.dirname })
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**9. Scripts** (`package.json`):
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"dev": "vite",
|
|
207
|
+
"build": "vite build && ui-kit prerender && ui-kit seo-files",
|
|
208
|
+
"preview": "ui-kit preview",
|
|
209
|
+
"check": "ui-kit check"
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
- `vite dev` serves the app with local D1, R2, rate limits and Durable Objects from the declaration (migrated on first use), and writes `.ui-kit/` (keep it out of git).
|
|
214
|
+
- `ui-kit prerender` renders `render: "prerender"` pages into `dist/client` and writes `_headers` (CSP hashes, immutable assets); `ui-kit seo-files` writes `sitemap.xml` and `robots.txt` from the route table and `src/sitemap-sources.ts`.
|
|
215
|
+
- `ui-kit preview [--port N]` runs the built Worker on local workerd with every binding.
|
|
216
|
+
- `ui-kit measure-cpu [path] [count]` (warm, against `preview`) or `--cold [runs] [path]` measures CPU per request; `ui-kit check` runs the whole-graph checks; `ui-kit feature <name>` lists a feature's files across the layers.
|
|
217
|
+
|
|
218
|
+
## Testing
|
|
219
|
+
|
|
220
|
+
- **Models:** `story(update, init).send(msg).expectModel(...).expectCommands([...])` from `/test`: pure, no DOM, milliseconds. Tests sit next to the code (`src/models/planner.model.test.ts`).
|
|
221
|
+
- **Programs:** run with fake Layers; `fakeD1` (real SQLite, the kit's migrations applied), `fakeR2` and `fakeRateLimit` from `/test` stand in for bindings.
|
|
222
|
+
- **Live rooms:** `fakeRoom`, `fakeSocket`, `connect` and `yClient` from `/test` drive a room with real SQLite and real Yjs.
|
|
223
|
+
- **Kit runtime behavior** (reactivity, hydration ids, fine-grained updates) is tested with probes: a `<name>.probe.ts` that its `<name>.test.ts` runs under `bun --conditions=browser`, since plain `bun test` loads Solid's server build.
|
|
224
|
+
- **Views under plain Bun:** the published kit keeps its views as Solid JSX (`.jsx`) for the app's Vite build to compile. Where Bun imports `/view`, `/ui` or a browser-only subpath without Vite (`bun test`, a script), preload the kit's compile step in `bunfig.toml`: `[test]` `preload = ["@alecsibilia/ui-kit/test/solid-preload"]`. It needs `@solidjs/compiler` 2.0.3 and compiles server-side (`ssr`) output.
|
|
225
|
+
- **Type-level rules** (closed JSX, typed island props and room refs) are `*.check.tsx` files checked by `tsc`.
|
|
226
|
+
- **Build and workerd checks** are `*.e2e.test.ts` (the repo's `slow_test`).
|
|
227
|
+
|
|
228
|
+
## Lint
|
|
229
|
+
|
|
230
|
+
Apps extend the plugin's preset, which scopes each rule by layer folder: see [`@alecsibilia/oxlint-plugin-ui-kit`](../oxlint-plugin-ui-kit/README.md). Rules that need the whole import graph run in `ui-kit check`. The kit's own structure is checked by `scripts/check-structure.ts` (part of the repo's `bun run lint`) and its package contents by `scripts/check-pack.ts`.
|
|
231
|
+
|
|
232
|
+
## Develop
|
|
233
|
+
|
|
234
|
+
From the repo root: `bun test packages/ui-kit`, `bunx --bun tsc --noEmit -p packages/ui-kit`, `bun run lint`. `bun run build` in this folder builds `dist/`; packing (`prepack`) points `exports` at it.
|
package/bin/ui-kit.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// The `ui-kit` command: the source in this repo, the built CLI when the
|
|
3
|
+
// package is installed from npm (it ships `dist/`, not `src/`).
|
|
4
|
+
import { existsSync } from 'node:fs'
|
|
5
|
+
|
|
6
|
+
const source = new URL('../src/build/cli.ts', import.meta.url)
|
|
7
|
+
const { main } = await import(
|
|
8
|
+
existsSync(source)
|
|
9
|
+
? source.href
|
|
10
|
+
: new URL('../dist/build/cli.js', import.meta.url).href
|
|
11
|
+
)
|
|
12
|
+
process.exit(await main(process.argv.slice(2)))
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as Cloudflare from '@alchemy.run/cloudflare';
|
|
2
|
+
import * as Alchemy from 'alchemy';
|
|
3
|
+
import { Stage } from 'alchemy';
|
|
4
|
+
import { type ResourcesDecl } from '../logic/resources.ts';
|
|
5
|
+
/**
|
|
6
|
+
* An app's whole Alchemy stack from its resource declaration
|
|
7
|
+
* (`src/resources.ts`): every D1 database (the sessions database gets the
|
|
8
|
+
* kit's `sessions` migration before the app's), R2 bucket, rate limit,
|
|
9
|
+
* Durable Object namespace, the live rooms' bindings, the crons (with the
|
|
10
|
+
* sessions cleanup) and Workers Cache, then one Worker with all of them in
|
|
11
|
+
* its `env`. Stages: `prod` (bare names, resources protected from removal)
|
|
12
|
+
* and `pr-<n>` previews (suffixed names, destroyed on close).
|
|
13
|
+
*
|
|
14
|
+
* Deploy (the deploy workflow only, never a package.json script):
|
|
15
|
+
* `bun run build && bunx alchemy deploy --stage prod`. The Alchemy CLI runs
|
|
16
|
+
* under Node: never `bunx --bun alchemy`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // alchemy.run.ts
|
|
21
|
+
* import { uiKitApp } from '@alecsibilia/ui-kit/alchemy'
|
|
22
|
+
* import { resources } from './src/resources.ts'
|
|
23
|
+
*
|
|
24
|
+
* export default uiKitApp(resources, { appDir: import.meta.dirname })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function uiKitApp(resources: ResourcesDecl, { appDir, main, assets, }: {
|
|
28
|
+
/** The app's folder (where its migrations are; `import.meta.dirname` in `alchemy.run.ts`). */
|
|
29
|
+
appDir: string;
|
|
30
|
+
main?: string;
|
|
31
|
+
assets?: string;
|
|
32
|
+
}): Alchemy.ConfiguredStack<{
|
|
33
|
+
url: Alchemy.Output<string | undefined, never>;
|
|
34
|
+
}, NoInfer<Cloudflare.Providers | Stage>>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as Cloudflare from '@alchemy.run/cloudflare';
|
|
2
|
+
import * as Alchemy from 'alchemy';
|
|
3
|
+
import { Stage } from 'alchemy';
|
|
4
|
+
import * as Effect from 'effect/Effect';
|
|
5
|
+
import { liveRoomsBindings } from './live-rooms.js';
|
|
6
|
+
import { assembleMigrations } from './migrations.js';
|
|
7
|
+
import { PRODUCTION_STAGE, stageResourceNames } from './stage.js';
|
|
8
|
+
import { cronsOf, durableObjectsOf, rateLimitsOf } from './wrangler-config.js';
|
|
9
|
+
import { resourceProblems } from '../logic/resources.js';
|
|
10
|
+
/**
|
|
11
|
+
* An app's whole Alchemy stack from its resource declaration
|
|
12
|
+
* (`src/resources.ts`): every D1 database (the sessions database gets the
|
|
13
|
+
* kit's `sessions` migration before the app's), R2 bucket, rate limit,
|
|
14
|
+
* Durable Object namespace, the live rooms' bindings, the crons (with the
|
|
15
|
+
* sessions cleanup) and Workers Cache, then one Worker with all of them in
|
|
16
|
+
* its `env`. Stages: `prod` (bare names, resources protected from removal)
|
|
17
|
+
* and `pr-<n>` previews (suffixed names, destroyed on close).
|
|
18
|
+
*
|
|
19
|
+
* Deploy (the deploy workflow only, never a package.json script):
|
|
20
|
+
* `bun run build && bunx alchemy deploy --stage prod`. The Alchemy CLI runs
|
|
21
|
+
* under Node: never `bunx --bun alchemy`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // alchemy.run.ts
|
|
26
|
+
* import { uiKitApp } from '@alecsibilia/ui-kit/alchemy'
|
|
27
|
+
* import { resources } from './src/resources.ts'
|
|
28
|
+
*
|
|
29
|
+
* export default uiKitApp(resources, { appDir: import.meta.dirname })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function uiKitApp(resources, { appDir, main = './dist/server/server.js', assets = './dist/client', }) {
|
|
33
|
+
const problems = resourceProblems(resources);
|
|
34
|
+
if (problems.length > 0) {
|
|
35
|
+
throw new Error(`uiKitApp: ${problems.join('; ')}`);
|
|
36
|
+
}
|
|
37
|
+
const migrations = assembleMigrations({ appDir, resources });
|
|
38
|
+
return Alchemy.Stack(resources.name, { providers: Cloudflare.providers(), state: Cloudflare.state() }, Effect.gen(function* () {
|
|
39
|
+
const stage = yield* Stage;
|
|
40
|
+
const production = stage === PRODUCTION_STAGE;
|
|
41
|
+
const names = stageResourceNames({
|
|
42
|
+
name: resources.name,
|
|
43
|
+
d1: Object.keys(resources.d1 ?? {}),
|
|
44
|
+
r2: Object.keys(resources.r2 ?? {}),
|
|
45
|
+
stage,
|
|
46
|
+
});
|
|
47
|
+
const env = {};
|
|
48
|
+
for (const binding of Object.keys(resources.d1 ?? {})) {
|
|
49
|
+
env[binding] = yield* Cloudflare.D1.Database(binding, {
|
|
50
|
+
name: names.d1[binding] ?? binding,
|
|
51
|
+
migrations: migrations[binding],
|
|
52
|
+
}).pipe(Alchemy.RemovalPolicy.protect(production));
|
|
53
|
+
}
|
|
54
|
+
for (const binding of Object.keys(resources.r2 ?? {})) {
|
|
55
|
+
env[binding] = yield* Cloudflare.R2.Bucket(binding, {
|
|
56
|
+
name: names.r2[binding] ?? binding,
|
|
57
|
+
// A non-empty bucket refuses to be destroyed without it.
|
|
58
|
+
forceDestroy: !production,
|
|
59
|
+
}).pipe(Alchemy.RemovalPolicy.protect(production));
|
|
60
|
+
}
|
|
61
|
+
for (const [binding, className] of durableObjectsOf(resources)) {
|
|
62
|
+
env[binding] = Cloudflare.DurableObject(className);
|
|
63
|
+
}
|
|
64
|
+
for (const [name, decl] of rateLimitsOf(resources)) {
|
|
65
|
+
env[name] = Cloudflare.RateLimit(name, {
|
|
66
|
+
namespaceId: decl.namespaceId,
|
|
67
|
+
simple: { limit: decl.limit, period: decl.period },
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (resources.liveRooms) {
|
|
71
|
+
Object.assign(env, liveRoomsBindings(resources.liveRooms));
|
|
72
|
+
}
|
|
73
|
+
const worker = yield* Cloudflare.Worker('Worker', {
|
|
74
|
+
name: names.worker,
|
|
75
|
+
main,
|
|
76
|
+
assets,
|
|
77
|
+
compatibility: {
|
|
78
|
+
date: resources.compatibility.date,
|
|
79
|
+
flags: [...resources.compatibility.flags],
|
|
80
|
+
},
|
|
81
|
+
workersDev: true,
|
|
82
|
+
...(resources.readCache ? { cache: { enabled: true } } : {}),
|
|
83
|
+
crons: cronsOf(resources),
|
|
84
|
+
env,
|
|
85
|
+
});
|
|
86
|
+
return { url: worker.url };
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@alecsibilia/ui-kit/alchemy`: an app's Cloudflare resources as an
|
|
3
|
+
* Alchemy stack (`uiKitApp`), and the local workerd shapes made from the
|
|
4
|
+
* same declaration (`wranglerConfig`, migrations, stage names), so deploy
|
|
5
|
+
* and local runs can't drift. Node only (the Alchemy CLI runs under Node).
|
|
6
|
+
*/
|
|
7
|
+
export { uiKitApp } from './app.ts';
|
|
8
|
+
export { liveRoomsBindings } from './live-rooms.ts';
|
|
9
|
+
export * from './migrations.ts';
|
|
10
|
+
export * from './stage.ts';
|
|
11
|
+
export * from './wrangler-config.ts';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@alecsibilia/ui-kit/alchemy`: an app's Cloudflare resources as an
|
|
3
|
+
* Alchemy stack (`uiKitApp`), and the local workerd shapes made from the
|
|
4
|
+
* same declaration (`wranglerConfig`, migrations, stage names), so deploy
|
|
5
|
+
* and local runs can't drift. Node only (the Alchemy CLI runs under Node).
|
|
6
|
+
*/
|
|
7
|
+
export { uiKitApp } from './app.js';
|
|
8
|
+
export { liveRoomsBindings } from './live-rooms.js';
|
|
9
|
+
export * from './migrations.js';
|
|
10
|
+
export * from './stage.js';
|
|
11
|
+
export * from './wrangler-config.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Alchemy for live rooms: the Worker bindings a live rooms declaration
|
|
3
|
+
* needs, made from that one declaration (`declareLiveRooms`,
|
|
4
|
+
* `@alecsibilia/ui-kit/live`). An app spreads them into its Worker's `env` in
|
|
5
|
+
* `alchemy.run.ts`; Alchemy creates the SQLite-backed Durable Object
|
|
6
|
+
* namespace (and writes its class migration) and the rate limit.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const worker = yield* Cloudflare.Worker("App", {
|
|
11
|
+
* main: "./dist/server/server.js",
|
|
12
|
+
* env: { DB: db, ...liveRoomsBindings(LIVE_ROOMS) },
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import * as Cloudflare from '@alchemy.run/cloudflare';
|
|
17
|
+
import type { AnyLiveRoomsDecl } from '../live/declaration.ts';
|
|
18
|
+
/** The `env` entries for a declaration: the room namespace, and the connect limit when declared. */
|
|
19
|
+
export declare function liveRoomsBindings(decl: AnyLiveRoomsDecl): {
|
|
20
|
+
[x: string]: Cloudflare.DurableObjectLike<unknown> | Cloudflare.RateLimitBinding;
|
|
21
|
+
};
|