@askrjs/askr 0.0.84 → 0.0.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/{access-ePqdQqkV.js → access-Dpfoi4cA.js} +7 -1
  2. package/dist/actions/index.d.ts +1 -1
  3. package/dist/actions/index.js +3 -3
  4. package/dist/{activity-pySy9t7Y.d.ts → activity-B1I5HJQI.d.ts} +1 -1
  5. package/dist/{activity-CZiPgZy0.js → activity-BvgvaMZA.js} +53 -16
  6. package/dist/benchmark.js +8 -8
  7. package/dist/boot/index.d.ts +3 -3
  8. package/dist/boot/index.js +1 -1
  9. package/dist/{boot-D28lesMw.js → boot-CViTpUiB.js} +22 -20
  10. package/dist/{cleanup-ARiXproi.js → cleanup-c837KVij.js} +16 -6
  11. package/dist/{component-cleanup-Bug5tSiG.js → component-cleanup-BUfUleGZ.js} +2 -2
  12. package/dist/{component-internal-Bw4Mf9fd.js → component-internal-DcrLymUJ.js} +5 -5
  13. package/dist/components/index.d.ts +1 -1
  14. package/dist/components/index.js +1 -1
  15. package/dist/control/index.d.ts +1 -1
  16. package/dist/control/index.js +1 -1
  17. package/dist/{control-Y8F73Uln.d.ts → control-DhUZU4_V.d.ts} +2 -1
  18. package/dist/{control-nrS65oG3.js → control-oLADku43.js} +4 -4
  19. package/dist/{csp-nonce-ZTlD_EnK.js → csp-nonce-Bc52OIVc.js} +19 -2
  20. package/dist/data/index.js +3 -3
  21. package/dist/{data-BRS5woEh.js → data-DGrD3-qA.js} +5 -5
  22. package/dist/{data-runtime-D68YOo9L.js → data-runtime-Ck3tJDDQ.js} +1 -1
  23. package/dist/default-portal-runtime-DvMvWJVp.js +20 -0
  24. package/dist/{authoring-DQPG0VAm.js → deferred-nleQtdfY.js} +85 -5
  25. package/dist/{effect-B487asyz.js → effect-lnxQIpJG.js} +2 -2
  26. package/dist/{fastlane-BOr4lSLl.js → fastlane-CrfB3QG0.js} +2 -2
  27. package/dist/{for-internal-DjpV8ioj.js → for-internal-B_mnQhan.js} +18 -6
  28. package/dist/foundations/index.d.ts +1 -1
  29. package/dist/foundations/index.js +1 -2
  30. package/dist/foundations/state/index.d.ts +1 -1
  31. package/dist/foundations/state/index.js +1 -1
  32. package/dist/foundations/structures/index.d.ts +2 -2
  33. package/dist/foundations/structures/index.js +2 -3
  34. package/dist/fx/index.js +1 -1
  35. package/dist/{index-BApH3laU.d.ts → index-DflhL1h8.d.ts} +20 -16
  36. package/dist/{index-_UN08Pg1.d.ts → index-pIgGaXvS.d.ts} +19 -3
  37. package/dist/{index-DUXXZ31H.d.ts → index-r-nt13FE.d.ts} +1 -1
  38. package/dist/index.d.ts +3 -3
  39. package/dist/index.js +12 -12
  40. package/dist/{lifecycle-batch-CFI4NKpJ.js → lifecycle-batch-Dfpid9-A.js} +39 -20
  41. package/dist/{lifecycle-operations-KYOIcM5R.js → lifecycle-operations-BrYrBsXY.js} +1 -1
  42. package/dist/manifest-D1P9uTlz.js +53 -0
  43. package/dist/{navigate-Dr3cjOSz.js → navigate-BwAPbpCb.js} +17 -16
  44. package/dist/{navigate-CgVIrrSs.d.ts → navigate-NyIjQUwI.d.ts} +1 -1
  45. package/dist/{query-registry-BL6rjGsO.js → query-registry-CPW_6nwF.js} +1 -1
  46. package/dist/{readable-_GQGe_St.js → readable-B5NtV7V0.js} +1 -1
  47. package/dist/render-context-D0Hoj9dW.js +161 -0
  48. package/dist/{renderer-B9j5IV1q.js → renderer-D9DL9R2D.js} +58 -17
  49. package/dist/{deferred-oqtAJ4iH.js → resolution-YHwi4Bav.js} +234 -222
  50. package/dist/resource-operation-ys6eDoRJ.js +304 -0
  51. package/dist/resources/index.d.ts +2 -2
  52. package/dist/resources/index.js +5 -5
  53. package/dist/{route-matching-IfQZmqkN.js → route-matching-DqULzZtC.js} +46 -277
  54. package/dist/router/index.d.ts +12 -10
  55. package/dist/router/index.js +10 -7
  56. package/dist/{selector-DJ1-N1K-.js → selector-Ck_Pp9av.js} +2 -2
  57. package/dist/ssg/index.d.ts +9 -3
  58. package/dist/ssg/index.js +31 -15
  59. package/dist/ssr/index.d.ts +7 -3
  60. package/dist/ssr/index.js +2 -2
  61. package/dist/{ssr-CtC4lChT.js → ssr-B98593qJ.js} +53 -27
  62. package/dist/ssr-DSHd_Q9K.js +25 -0
  63. package/dist/{state-BzIMC6-i.js → state-DCjONcHK.js} +4 -3
  64. package/dist/{portal-pHBoqwYd.js → structures-DsOm-clq.js} +236 -7
  65. package/dist/testing/index.d.ts +2 -2
  66. package/dist/testing/index.js +4 -4
  67. package/dist/{verify-hydration-BguOSco9.js → verify-hydration-ww1dgwea.js} +5 -4
  68. package/package.json +2 -2
  69. package/dist/render-context-D-DFk2WN.js +0 -73
  70. package/dist/ssr-CbQO5xd3.js +0 -12
  71. package/dist/structures-D3vO-WMN.js +0 -221
@@ -0,0 +1,304 @@
1
+ import { t as enqueueRuntimeLane, v as logger } from "./access-Dpfoi4cA.js";
2
+ import { f as getCurrentComponentInstance } from "./component-scope-DzJEbYGE.js";
3
+ import { c as registerCommitOperationForInstance, d as getCurrentContextFrame, v as withAsyncResourceContext } from "./component-internal-DcrLymUJ.js";
4
+ import { p as isPromiseLike } from "./lifecycle-batch-Dfpid9-A.js";
5
+ import { t as brandSnapshotSource } from "./snapshot-source-BB42xgwb.js";
6
+ import { a as getResourceVerificationSnapshot, i as getNextRenderKey, n as getActiveRenderContext, o as isHydrationVerificationRender, p as throwSSRDataMissing, r as getCurrentRenderData, s as recordResourceVerificationSnapshot, x as SSRDataMissingError } from "./render-context-D0Hoj9dW.js";
7
+ import { t as state } from "./state-DCjONcHK.js";
8
+ //#region src/runtime/resource-cell.ts
9
+ /**
10
+ * Pure, component-agnostic ResourceCell state machine.
11
+ * - Holds value/pending/error/generation/controller
12
+ * - Exposes a stable `snapshot` object: { value, pending, error, refresh }
13
+ * - Uses `withAsyncResourceContext` to bind the synchronous execution step
14
+ * to a captured frame. Continuations after await do not see the frame.
15
+ */
16
+ var ResourceCell = class {
17
+ constructor(fn, deps, resourceFrame) {
18
+ this.value = null;
19
+ this.pending = true;
20
+ this.error = null;
21
+ this.generation = 0;
22
+ this.controller = null;
23
+ this.deps = null;
24
+ this.resourceFrame = null;
25
+ this.subscribers = /* @__PURE__ */ new Set();
26
+ this.disposed = false;
27
+ this.fn = fn;
28
+ this.deps = deps ? deps.slice() : null;
29
+ this.resourceFrame = resourceFrame;
30
+ this.snapshot = brandSnapshotSource({
31
+ value: null,
32
+ pending: true,
33
+ error: null,
34
+ refresh: () => this.refresh()
35
+ });
36
+ }
37
+ setLoader(fn) {
38
+ this.fn = fn;
39
+ }
40
+ subscribe(cb) {
41
+ this.subscribers.add(cb);
42
+ return () => this.subscribers.delete(cb);
43
+ }
44
+ notifySubscribers() {
45
+ this.snapshot.value = this.value;
46
+ this.snapshot.pending = this.pending;
47
+ this.snapshot.error = this.error;
48
+ for (const cb of this.subscribers) cb();
49
+ }
50
+ start(ssr = false, notify = true) {
51
+ if (this.disposed) return;
52
+ const generation = this.generation;
53
+ this.controller?.abort();
54
+ const controller = new AbortController();
55
+ this.controller = controller;
56
+ this.pending = true;
57
+ this.error = null;
58
+ if (notify) this.notifySubscribers();
59
+ let result;
60
+ try {
61
+ result = withAsyncResourceContext(this.resourceFrame, () => this.fn({ signal: controller.signal }));
62
+ } catch (err) {
63
+ this.pending = false;
64
+ this.error = err instanceof Error ? err : new Error(String(err));
65
+ if (notify) this.notifySubscribers();
66
+ return;
67
+ }
68
+ if (!isPromiseLike(result)) {
69
+ this.value = result;
70
+ this.pending = false;
71
+ this.error = null;
72
+ if (notify) this.notifySubscribers();
73
+ return;
74
+ }
75
+ if (ssr) throwSSRDataMissing();
76
+ Promise.resolve(result).then((val) => {
77
+ if (this.generation !== generation) return;
78
+ if (this.controller !== controller) return;
79
+ if (controller.signal.aborted) return;
80
+ this.value = val;
81
+ this.pending = false;
82
+ this.error = null;
83
+ this.notifySubscribers();
84
+ }).catch((err) => {
85
+ if (this.generation !== generation) return;
86
+ if (this.controller !== controller) return;
87
+ if (controller.signal.aborted || err instanceof Error && err.name === "AbortError" || typeof DOMException !== "undefined" && err instanceof DOMException && err.name === "AbortError") return;
88
+ this.pending = false;
89
+ this.error = err instanceof Error ? err : new Error(String(err));
90
+ try {
91
+ if (this.ownerName) logger.error(`[Askr] Async resource error in ${this.ownerName}:`, err);
92
+ else logger.error("[Askr] Async resource error:", err);
93
+ } catch {}
94
+ this.notifySubscribers();
95
+ });
96
+ }
97
+ refresh() {
98
+ if (this.disposed) return;
99
+ this.generation++;
100
+ this.controller?.abort();
101
+ this.start();
102
+ }
103
+ abort() {
104
+ this.controller?.abort();
105
+ }
106
+ dispose() {
107
+ if (this.disposed) return;
108
+ this.disposed = true;
109
+ this.controller?.abort();
110
+ this.subscribers.clear();
111
+ }
112
+ };
113
+ //#endregion
114
+ //#region src/runtime/resource-operation.ts
115
+ function hydrationVerificationSnapshot() {
116
+ return brandSnapshotSource({
117
+ value: null,
118
+ pending: true,
119
+ error: null,
120
+ refresh: () => {}
121
+ });
122
+ }
123
+ /**
124
+ * Resource primitive — simple, deterministic async primitive
125
+ * Usage: resource(fn, deps)
126
+ * - fn receives { signal }
127
+ * - captures execution context once at creation (synchronous step only)
128
+ * - executes at most once per generation; stale async results are ignored
129
+ * - refresh() cancels in-flight execution, increments generation and re-runs
130
+ * - exposes { value, pending, error, refresh }
131
+ * - during SSR, async results are disallowed and will throw synchronously
132
+ */
133
+ function resource(fn, deps = []) {
134
+ const instance = getCurrentComponentInstance();
135
+ const inst = instance;
136
+ if (!instance) {
137
+ const renderData = getCurrentRenderData()?.resources;
138
+ if (renderData && (getActiveRenderContext()?.resourceDataProvided || Object.keys(renderData).some((key) => key.startsWith("r:")))) {
139
+ const key = getNextRenderKey();
140
+ if (!(key in renderData)) throwSSRDataMissing();
141
+ const val = renderData[key];
142
+ return brandSnapshotSource({
143
+ value: val,
144
+ pending: false,
145
+ error: null,
146
+ refresh: () => {}
147
+ });
148
+ }
149
+ if (getActiveRenderContext()) throwSSRDataMissing();
150
+ throw new Error("[Askr] resource() must be called during component render inside an app. Do not create resources at module scope or outside render.");
151
+ }
152
+ const renderData = getCurrentRenderData()?.resources;
153
+ const hasPreloadedResourceData = Boolean(renderData && (getActiveRenderContext()?.resourceDataProvided || Object.keys(renderData).some((key) => key.startsWith("r:"))));
154
+ const renderKey = inst.ssr || hasPreloadedResourceData ? getNextRenderKey() : null;
155
+ const verificationSnapshot = renderKey ? getResourceVerificationSnapshot(renderKey) : null;
156
+ if (renderData && hasPreloadedResourceData && renderKey && renderKey in renderData) {
157
+ const val = renderData[renderKey];
158
+ const h = state({
159
+ cell: void 0,
160
+ snapshot: brandSnapshotSource({
161
+ value: val,
162
+ pending: false,
163
+ error: null,
164
+ refresh: () => {}
165
+ })
166
+ })();
167
+ h.snapshot.value = val;
168
+ h.snapshot.pending = false;
169
+ h.snapshot.error = null;
170
+ return h.snapshot;
171
+ }
172
+ if (isHydrationVerificationRender() && verificationSnapshot) {
173
+ const result = hydrationVerificationSnapshot();
174
+ result.value = verificationSnapshot.value;
175
+ result.pending = verificationSnapshot.pending;
176
+ return result;
177
+ }
178
+ if (renderData && hasPreloadedResourceData && renderKey && (inst.ssr || !verificationSnapshot)) throwSSRDataMissing();
179
+ const ssrRenderKey = inst.ssr ? renderKey : null;
180
+ const clientHydrationSnapshot = inst.ssr ? null : verificationSnapshot;
181
+ const holder = state({
182
+ cell: void 0,
183
+ snapshot: brandSnapshotSource({
184
+ value: clientHydrationSnapshot ? clientHydrationSnapshot.value : null,
185
+ pending: clientHydrationSnapshot?.pending ?? true,
186
+ error: null,
187
+ refresh: () => {}
188
+ })
189
+ });
190
+ const h = holder();
191
+ if (!h.cell) {
192
+ const cell = new ResourceCell(fn, deps, getCurrentContextFrame());
193
+ if (clientHydrationSnapshot) {
194
+ cell.value = clientHydrationSnapshot.value;
195
+ cell.pending = clientHydrationSnapshot.pending;
196
+ cell.snapshot.value = clientHydrationSnapshot.value;
197
+ cell.snapshot.pending = clientHydrationSnapshot.pending;
198
+ }
199
+ cell.ownerName = inst.fn?.name || "<anonymous>";
200
+ h.cell = cell;
201
+ h.snapshot = cell.snapshot;
202
+ const unsubscribe = cell.subscribe(() => {
203
+ const cur = holder();
204
+ cur.snapshot.value = cell.snapshot.value;
205
+ cur.snapshot.pending = cell.snapshot.pending;
206
+ cur.snapshot.error = cell.snapshot.error;
207
+ holder.set(cur);
208
+ try {
209
+ inst.notifyUpdate?.();
210
+ } catch {}
211
+ });
212
+ (inst.cleanupFns ??= []).push(() => {
213
+ unsubscribe();
214
+ cell.dispose();
215
+ });
216
+ if (inst.ssr) {
217
+ cell.start(true, false);
218
+ if (!cell.pending) {
219
+ const cur = holder();
220
+ cur.snapshot.value = cell.value;
221
+ cur.snapshot.pending = cell.pending;
222
+ cur.snapshot.error = cell.error;
223
+ }
224
+ if (ssrRenderKey && cell.value === null && cell.error === null) recordResourceVerificationSnapshot(ssrRenderKey, {
225
+ value: null,
226
+ pending: cell.pending
227
+ });
228
+ } else {
229
+ const scheduledGeneration = cell.generation;
230
+ registerCommitOperationForInstance(inst, () => {
231
+ enqueueRuntimeLane("post", () => {
232
+ if (!inst.notifyUpdate || cell.generation !== scheduledGeneration) return;
233
+ try {
234
+ cell.start(false, false);
235
+ } catch (err) {
236
+ const cur = holder();
237
+ cur.snapshot.value = cell.value;
238
+ cur.snapshot.pending = cell.pending;
239
+ cur.snapshot.error = err ?? null;
240
+ holder.set(cur);
241
+ inst.notifyUpdate?.();
242
+ return;
243
+ }
244
+ if (!cell.pending) {
245
+ const cur = holder();
246
+ cur.snapshot.value = cell.value;
247
+ cur.snapshot.pending = cell.pending;
248
+ cur.snapshot.error = cell.error;
249
+ holder.set(cur);
250
+ inst.notifyUpdate?.();
251
+ }
252
+ });
253
+ });
254
+ }
255
+ }
256
+ const cell = h.cell;
257
+ cell.setLoader(fn);
258
+ if (!cell.deps || cell.deps.length !== deps.length || cell.deps.some((d, i) => !Object.is(d, deps[i]))) {
259
+ cell.deps = deps.slice();
260
+ cell.generation++;
261
+ cell.pending = true;
262
+ cell.error = null;
263
+ h.snapshot.pending = true;
264
+ h.snapshot.error = null;
265
+ try {
266
+ if (inst.ssr) {
267
+ cell.start(true, false);
268
+ if (!cell.pending) {
269
+ const cur = holder();
270
+ cur.snapshot.value = cell.value;
271
+ cur.snapshot.pending = cell.pending;
272
+ cur.snapshot.error = cell.error;
273
+ }
274
+ } else {
275
+ const scheduledGeneration = cell.generation;
276
+ registerCommitOperationForInstance(inst, () => {
277
+ enqueueRuntimeLane("post", () => {
278
+ if (!inst.notifyUpdate || cell.generation !== scheduledGeneration) return;
279
+ cell.start(false, false);
280
+ if (!cell.pending) {
281
+ const cur = holder();
282
+ cur.snapshot.value = cell.value;
283
+ cur.snapshot.pending = cell.pending;
284
+ cur.snapshot.error = cell.error;
285
+ holder.set(cur);
286
+ inst.notifyUpdate?.();
287
+ }
288
+ });
289
+ });
290
+ }
291
+ } catch (err) {
292
+ if (err instanceof SSRDataMissingError) throw err;
293
+ cell.error = err;
294
+ cell.pending = false;
295
+ const cur = holder();
296
+ cur.snapshot.value = cell.value;
297
+ cur.snapshot.pending = cell.pending;
298
+ cur.snapshot.error = cell.error;
299
+ }
300
+ }
301
+ return h.snapshot;
302
+ }
303
+ //#endregion
304
+ export { resource as t };
@@ -1,5 +1,5 @@
1
- import { ut as getSignal } from "../index-_UN08Pg1.js";
2
- import { i as onRouteChange, n as RouteChangeOptions, t as RouteChangeCleanup } from "../activity-pySy9t7Y.js";
1
+ import { ut as getSignal } from "../index-pIgGaXvS.js";
2
+ import { i as onRouteChange, n as RouteChangeOptions, t as RouteChangeCleanup } from "../activity-B1I5HJQI.js";
3
3
  //#region src/runtime/resource-operation.d.ts
4
4
  interface ResourceResult<T> {
5
5
  value: T | null;
@@ -1,9 +1,9 @@
1
- import { t as enqueueRuntimeLane } from "../access-ePqdQqkV.js";
2
- import { a as registerCommitOperation } from "../component-internal-Bw4Mf9fd.js";
1
+ import { t as enqueueRuntimeLane } from "../access-Dpfoi4cA.js";
3
2
  import { f as getCurrentComponentInstance, g as getSignal, i as claimHookIndex } from "../component-scope-DzJEbYGE.js";
4
- import { z as resource } from "../route-matching-IfQZmqkN.js";
5
- import { a as task, i as routeActive, n as documentVisible, o as timer, r as on, s as windowFocused, t as capture } from "../lifecycle-operations-KYOIcM5R.js";
6
- import { n as onRouteChange } from "../activity-CZiPgZy0.js";
3
+ import { a as registerCommitOperation } from "../component-internal-DcrLymUJ.js";
4
+ import { t as resource } from "../resource-operation-ys6eDoRJ.js";
5
+ import { a as task, i as routeActive, n as documentVisible, o as timer, r as on, s as windowFocused, t as capture } from "../lifecycle-operations-BrYrBsXY.js";
6
+ import { n as onRouteChange } from "../activity-BvgvaMZA.js";
7
7
  //#region src/runtime/stream-operation.ts
8
8
  function toError(value) {
9
9
  return value instanceof Error ? value : new Error(String(value));