@quarkhz/astro 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +139 -2
- package/dist/chunk-4fvndbet.js +2 -0
- package/dist/chunk-a33j6chq.js +2 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +1 -0
- package/dist/inject.d.ts +1 -0
- package/dist/middleware.d.ts +3 -0
- package/dist/middleware.js +1 -0
- package/dist/server.d.ts +8 -0
- package/dist/server.js +1 -0
- package/dist/shared.d.ts +11 -0
- package/dist/snapshot.d.ts +4 -0
- package/dist/store.d.ts +3 -0
- package/dist/store.js +1 -0
- package/package.json +65 -4
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 2026 TheOnlyFastCoder2
|
|
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,140 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @quarkhz/astro
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Quark signals for Astro. Islands stay ordinary `@astrojs/react` islands; this
|
|
4
|
+
package adds what a signal library needs around them:
|
|
5
|
+
|
|
6
|
+
- **a scope per request** on the server, so one visitor's state never shows up
|
|
7
|
+
in another visitor's page;
|
|
8
|
+
- **the state of that scope in the HTML**, placed before each island, so an
|
|
9
|
+
island hydrates with the server's values instead of flashing its defaults;
|
|
10
|
+
- **`prefetch()`** for frontmatter: load data once on the server, and the
|
|
11
|
+
islands neither show a spinner nor fetch it again.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm i @quarkhz/astro @quarkhz/core @quarkhz/react @astrojs/react
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// astro.config.mjs
|
|
19
|
+
import { defineConfig } from "astro/config";
|
|
20
|
+
import react from "@astrojs/react";
|
|
21
|
+
import quark from "@quarkhz/astro";
|
|
22
|
+
|
|
23
|
+
export default defineConfig({ integrations: [react(), quark()] });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Shared state: stores
|
|
27
|
+
|
|
28
|
+
A React context does not cross islands, and a signal at module scope is one
|
|
29
|
+
object for the whole server process. A store is created per request on the
|
|
30
|
+
server and once per page in the browser:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
// src/stores/cart.ts
|
|
34
|
+
import { computed, signal } from "@quarkhz/core";
|
|
35
|
+
import { defineStore, defineState } from "@quarkhz/astro/store";
|
|
36
|
+
|
|
37
|
+
export const cart = defineStore("cart", () => {
|
|
38
|
+
const items = signal<string[]>([]);
|
|
39
|
+
const count = computed(() => items.v.length);
|
|
40
|
+
return { items, count, add: (name: string) => (items.v = [...items.v, name]) };
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const theme = defineState("theme", "dark"); // one value
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Call it wherever the state is needed. Every island on the page gets the same
|
|
47
|
+
object:
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
// src/components/CartBadge.tsx
|
|
51
|
+
import { sg } from "@quarkhz/react";
|
|
52
|
+
import { cart } from "../stores/cart";
|
|
53
|
+
|
|
54
|
+
export default function CartBadge() {
|
|
55
|
+
const c = cart();
|
|
56
|
+
return <sg.span text={() => `${c.count.v} in cart`} />;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```astro
|
|
61
|
+
---
|
|
62
|
+
// src/pages/index.astro
|
|
63
|
+
import CartBadge from "../components/CartBadge";
|
|
64
|
+
import { cart } from "../stores/cart";
|
|
65
|
+
|
|
66
|
+
cart().items.v = await loadCart(Astro.cookies); // this request only
|
|
67
|
+
---
|
|
68
|
+
<CartBadge client:load />
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The writable signals at the top level of the object `setup` returns are the
|
|
72
|
+
state that travels to the browser. Computeds and functions are rebuilt there by
|
|
73
|
+
`setup`. Values must be JSON: no `Date`, `Map` or class instances.
|
|
74
|
+
|
|
75
|
+
## Data: prefetch
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// src/data/products.ts
|
|
79
|
+
import { query } from "@quarkhz/query";
|
|
80
|
+
|
|
81
|
+
export const products = query(() => fetch(API).then((r) => r.json()), {
|
|
82
|
+
ssr: { id: () => "products" }, // sends the result to the browser
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```astro
|
|
87
|
+
---
|
|
88
|
+
import { prefetch } from "@quarkhz/astro/server";
|
|
89
|
+
import { products } from "../data/products";
|
|
90
|
+
|
|
91
|
+
await prefetch(products(), user(Astro.params.id)); // in parallel
|
|
92
|
+
---
|
|
93
|
+
<ProductList client:visible />
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`prefetch` takes what a query call returns, a promise, or a function. A query
|
|
97
|
+
without `ssr` is still loaded for the server render, but its result stays on
|
|
98
|
+
the server and the island fetches again; `prefetch` warns about it once.
|
|
99
|
+
|
|
100
|
+
Give every `ssr` query its own `id`. Without one the id is the argument key, and
|
|
101
|
+
two queries called with the same arguments would overwrite each other.
|
|
102
|
+
|
|
103
|
+
## How the state reaches the browser
|
|
104
|
+
|
|
105
|
+
The middleware watches the HTML as it streams and writes a small inline script
|
|
106
|
+
in front of an island whenever the state changed since the previous script. An
|
|
107
|
+
island's markup is produced after the island was rendered, so the script before
|
|
108
|
+
it always holds what that island needs. A page that streams slowly gets several
|
|
109
|
+
scripts, each with only what is new; stores that already exist in the browser
|
|
110
|
+
are updated in place.
|
|
111
|
+
|
|
112
|
+
The script is a plain element next to the island. A selector that counts
|
|
113
|
+
siblings (`:first-child`, `> * + *`) sees it; `display` and `gap` do not.
|
|
114
|
+
|
|
115
|
+
## Entry points
|
|
116
|
+
|
|
117
|
+
| import | what | runs |
|
|
118
|
+
|---|---|---|
|
|
119
|
+
| `@quarkhz/astro` | `quark()` integration | astro.config |
|
|
120
|
+
| `@quarkhz/astro/store` | `defineStore`, `defineState` | server and browser |
|
|
121
|
+
| `@quarkhz/astro/server` | `prefetch`, `getRequestScope`, `stateScript` | server |
|
|
122
|
+
| `@quarkhz/astro/middleware` | `onRequest`, `quarkMiddleware` | server |
|
|
123
|
+
|
|
124
|
+
With a `src/middleware.ts` of your own nothing changes: the integration adds
|
|
125
|
+
its middleware in front. To order it by hand, pass `quark({ middleware: false })`
|
|
126
|
+
and put `quarkMiddleware` first in your `sequence()`.
|
|
127
|
+
|
|
128
|
+
## Notes
|
|
129
|
+
|
|
130
|
+
- Needs a Node-compatible runtime on the server (`node:async_hooks`).
|
|
131
|
+
- A store read on the server outside a request (no middleware) falls back to
|
|
132
|
+
one process-wide instance and warns once.
|
|
133
|
+
- `stateScript()` returns the snapshot as a string for responses the middleware
|
|
134
|
+
does not see.
|
|
135
|
+
|
|
136
|
+
The source is closed; the published package contains the built `dist` only.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
Apache-2.0
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{b as $,c as C,d as J,e as M,f as N}from"./chunk-4fvndbet.js";var X=(q)=>!!q&&typeof q==="object"&&q.phase==="pending"&&("updatedAt"in q);function f(q){let z={};for(let H in q.store){let V=q.store[H];if(!X(V))z[H]=V}let W=q[M];if(W)for(let[H,V]of W)z[J+H]=V.read();return z}var Q=String.fromCharCode(8232),U=String.fromCharCode(8233),p={"<":"\\u003c",">":"\\u003e","&":"\\u0026",[Q]:"\\u2028",[U]:"\\u2029"},D=new RegExp("[<>&"+Q+U+"]","g"),F=(q)=>q.replace(D,(z)=>p[z]);function K(q){let z=q[N]??=new Map,W=f(q),H="";for(let V in W){let Z;try{Z=JSON.stringify(W[V])}catch{continue}if(Z===void 0||z.get(V)===Z)continue;z.set(V,Z),H+=(H?",":"")+JSON.stringify(V)+":"+Z}return H?"{"+F(H)+"}":null}function I(q){let z=K(q);if(!z)return"";return`<script data-quark-state>(function(d){var w=window,s=w.${$}||(w.${$}={}),k;for(k in d)s[k]=d[k];w.${C}&&w.${C}(d)})(${z})</script>`}
|
|
2
|
+
export{I as a};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type QuarkAstroOptions = {
|
|
2
|
+
middleware?: boolean;
|
|
3
|
+
};
|
|
4
|
+
type SetupHook = (options: {
|
|
5
|
+
addMiddleware: (middleware: {
|
|
6
|
+
entrypoint: string;
|
|
7
|
+
order: "pre" | "post";
|
|
8
|
+
}) => void;
|
|
9
|
+
}) => void;
|
|
10
|
+
export type QuarkAstroIntegration = {
|
|
11
|
+
name: string;
|
|
12
|
+
hooks: {
|
|
13
|
+
"astro:config:setup": SetupHook;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export default function quark(options?: QuarkAstroOptions): QuarkAstroIntegration;
|
|
17
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function k(g={}){return{name:"@quarkhz/astro",hooks:{"astro:config:setup":({addMiddleware:j})=>{if(g.middleware!==!1)j({entrypoint:"@quarkhz/astro/middleware",order:"pre"})}}}}export{k as default};
|
package/dist/inject.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function injectState(body: ReadableStream<Uint8Array>, takeScript: () => string, run?: <T>(fn: () => T) => T): ReadableStream<Uint8Array>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as $}from"./chunk-a33j6chq.js";import"./chunk-4fvndbet.js";import{AsyncLocalStorage as z}from"node:async_hooks";import{createSSRRequestContext as D,setSSRRequestContextResolver as K}from"@quarkhz/core";var m=Math.max(13,7)-1;function Z(Q,T,I=(B)=>B()){let B=Q.getReader(),J=new TextDecoder,V=new TextEncoder,M="",X=(w,U)=>{let F=w.indexOf("<astro-island"),G=w.indexOf("</body>");if(F<0||G>=0&&G<F)F=G;if(F>=0){let P=T();if(P)w=w.slice(0,F)+P+w.slice(F)}if(U){let P=T();return M="",P?w+P:w}let N=w.lastIndexOf("<");if(N>=0&&w.length-N<=m&&!w.includes(">",N))return M=w.slice(N),w.slice(0,N);return M="",w};return new ReadableStream({async pull(w){for(;;){let{done:U,value:F}=await I(()=>B.read()),G=U?X(M+J.decode(),!0):X(M+J.decode(F,{stream:!0}),!1);if(G)w.enqueue(V.encode(G));if(U)return w.close();if(G)return}},cancel(w){return B.cancel(w)}})}var O=Symbol.for("quark.astro.requestStorage"),W=globalThis[O]??=new z;K(()=>W.getStore());var Y=(Q)=>(Q.headers.get("content-type")??"").includes("text/html"),v=(Q,T)=>{let I=D();return W.run(I,async()=>{let B=await T();if(!B.body||!Y(B))return B;let J=new Headers(B.headers);return J.delete("content-length"),new Response(Z(B.body,()=>$(I),(V)=>W.run(I,V)),{status:B.status,statusText:B.statusText,headers:J})})};export{v as quarkMiddleware,v as onRequest};
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type QuerySignalLike = {
|
|
2
|
+
readonly v: unknown;
|
|
3
|
+
};
|
|
4
|
+
type Prefetchable = QuerySignalLike | PromiseLike<unknown> | (() => unknown) | null | undefined | false;
|
|
5
|
+
export declare function prefetch(...items: Prefetchable[]): Promise<void>;
|
|
6
|
+
export declare const getRequestScope: () => import("@quarkhz/core").SSRRequestContext | null;
|
|
7
|
+
export declare function stateScript(): string;
|
|
8
|
+
export {};
|
package/dist/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as A}from"./chunk-a33j6chq.js";import"./chunk-4fvndbet.js";import{getCurrentSSRRequestContext as B}from"@quarkhz/core";var D=Symbol.for("quark.sg.query.resource"),y=!1;async function I(...j){await Promise.all(j.map((b)=>{if(!b)return;if(typeof b==="function")return b();let v=b[D];if(!v)return b;if(!("__ssrId"in b)&&!y)y=!0,console.warn("[@quarkhz/astro] prefetch() got a query without `ssr: true`. It is loaded for the server render, but the result is not sent to the browser, so the island will fetch it again.");return v.prefetch()}))}var J=B;function K(){let j=B();return j?A(j):""}export{K as stateScript,I as prefetch,J as getRequestScope};
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const STATE_GLOBAL = "__SSR_STATE__";
|
|
2
|
+
export declare const APPLY_GLOBAL = "__QUARK_APPLY__";
|
|
3
|
+
export declare const STORE_PREFIX = "store:";
|
|
4
|
+
export declare const STORES_KEY: unique symbol;
|
|
5
|
+
export declare const EMITTED_KEY: unique symbol;
|
|
6
|
+
export type StoreRecord = {
|
|
7
|
+
def: object;
|
|
8
|
+
instance: unknown;
|
|
9
|
+
read(): unknown;
|
|
10
|
+
write(data: unknown): void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SSRRequestContext } from "@quarkhz/core";
|
|
2
|
+
export declare function collectState(ctx: SSRRequestContext): Record<string, unknown>;
|
|
3
|
+
export declare function takeStateDelta(ctx: SSRRequestContext): string | null;
|
|
4
|
+
export declare function takeStateScript(ctx: SSRRequestContext): string;
|
package/dist/store.d.ts
ADDED
package/dist/store.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as $,c as K,d as U,e as V}from"./chunk-4fvndbet.js";import{batch as q,getCurrentSSRRequestContext as C,isComputedLike as F,isSignalLike as G,signal as I}from"@quarkhz/core";var Z=typeof window<"u",b=(D)=>G(D)&&!F(D);function X(D,j){let H=j();if(b(H))return{def:D,instance:H,read:()=>H.v,write:(J)=>void(H.v=J)};let M=[];if(H&&typeof H==="object")for(let J of Object.keys(H)){let Q=H[J];if(b(Q))M.push([J,Q])}return{def:D,instance:H,read(){let J={};for(let[Q,W]of M)J[Q]=W.v;return J},write(J){if(!J||typeof J!=="object")return;q(()=>{for(let[Q,W]of M)if(Object.hasOwn(J,Q))W.v=J[Q]})}}}var N=new Map;if(Z)window[K]=(D)=>{for(let j in D){if(!j.startsWith(U))continue;let H=N.get(j.slice(U.length));if(!H)continue;H.write(D[j]),delete window[$]?.[j]}};function w(D){let j=window[$],H=U+D;if(!j||!Object.hasOwn(j,H))return null;let M=j[H];return delete j[H],{value:M}}var P=new Map,z=!1;function m(D){let j=C();if(j)return j[V]??=new Map;if(!z)z=!0,console.warn(`[@quarkhz/astro] store "${D}" was read on the server outside a request. Its state is shared by every request. Add the quark() integration to astro.config so each request gets its own.`);return P}function Y(D,j,H){let M=Z?N:m(D),J=M.get(D);if(J&&J.def!==j)console.warn(`[@quarkhz/astro] store id "${D}" is defined more than once; ids must be unique.`),J=void 0;if(!J){if(J=X(j,H),M.set(D,J),Z){let Q=w(D);if(Q)J.write(Q.value)}}return J}function O(D,j){let H={};return()=>Y(D,H,j).instance}function _(D,j){let H={},M=()=>I(typeof j==="function"?j():j);return()=>Y(D,H,M).instance}export{O as defineStore,_ as defineState};
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quarkhz/astro",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "Quark signals for Astro: request-scoped state on the server, a state snapshot that reaches every island before it hydrates, and prefetch for frontmatter.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"astro",
|
|
8
|
+
"astro-integration",
|
|
9
|
+
"withastro",
|
|
10
|
+
"signals",
|
|
11
|
+
"islands",
|
|
12
|
+
"ssr",
|
|
13
|
+
"state",
|
|
14
|
+
"quark"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://quark-docs.vercel.app/",
|
|
17
|
+
"bugs": "https://github.com/TheOnlyFastCoder2/quarkhz/issues",
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./store": {
|
|
34
|
+
"types": "./dist/store.d.ts",
|
|
35
|
+
"import": "./dist/store.js",
|
|
36
|
+
"default": "./dist/store.js"
|
|
37
|
+
},
|
|
38
|
+
"./server": {
|
|
39
|
+
"types": "./dist/server.d.ts",
|
|
40
|
+
"import": "./dist/server.js",
|
|
41
|
+
"default": "./dist/server.js"
|
|
42
|
+
},
|
|
43
|
+
"./middleware": {
|
|
44
|
+
"types": "./dist/middleware.d.ts",
|
|
45
|
+
"import": "./dist/middleware.js",
|
|
46
|
+
"default": "./dist/middleware.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"test": "bun test ./src",
|
|
51
|
+
"build:js": "bun run ./build.ts",
|
|
52
|
+
"build:types": "tsc -p ./tsconfig.build.json",
|
|
53
|
+
"build": "npm run clean && npm run build:js && npm run build:types",
|
|
54
|
+
"check:publish": "node ../_tooling/check-publish.mjs",
|
|
55
|
+
"prepublishOnly": "npm run build && npm run check:publish",
|
|
56
|
+
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\""
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@quarkhz/core": ">=0.0.4",
|
|
60
|
+
"astro": "^4 || ^5"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@quarkhz/core": "file:../core",
|
|
64
|
+
"@types/node": "^25.4.0",
|
|
65
|
+
"typescript": "^5.9.3"
|
|
66
|
+
}
|
|
67
|
+
}
|