@askrjs/askr 0.3.0 → 0.4.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.
Files changed (123) hide show
  1. package/CHANGELOG.md +874 -0
  2. package/README.md +61 -29
  3. package/capabilities.json +19 -9
  4. package/dist/actions/index.js +56 -12
  5. package/dist/benchmark.js +10 -15
  6. package/dist/boot/index.d.ts +3 -2
  7. package/dist/boot/index.js +1 -1
  8. package/dist/boot-DaoTYoCw.js +3989 -0
  9. package/dist/browser-activity-CB8e-V4f.js +220 -0
  10. package/dist/components/index.d.ts +8 -1
  11. package/dist/components/index.js +1 -43
  12. package/dist/{aria-hKjThHcp.js → compose-ref-DWzdbxsD.js} +41 -4
  13. package/dist/control/index.d.ts +2 -0
  14. package/dist/control/index.js +1 -1
  15. package/dist/control-nfpT2fbK.js +209 -0
  16. package/dist/core.d.ts +5 -9
  17. package/dist/csp-nonce-DwGw1A6Q.js +35 -0
  18. package/dist/data/index.js +3 -3
  19. package/dist/{data-2edW0jhF.js → data-BCwClJiF.js} +283 -94
  20. package/dist/data-runtime-C1bFAlba.js +242 -0
  21. package/dist/{deferred-CbgNhf67.js → deferred-bEEHHvic.js} +42 -20
  22. package/dist/domains/actions.d.ts +8 -3
  23. package/dist/domains/component.d.ts +1 -107
  24. package/dist/domains/context.d.ts +0 -15
  25. package/dist/domains/control.d.ts +36 -249
  26. package/dist/domains/data.d.ts +31 -13
  27. package/dist/domains/diagnostics.d.ts +1 -2
  28. package/dist/domains/lifecycle.d.ts +2 -5
  29. package/dist/domains/refs.d.ts +0 -2
  30. package/dist/domains/routing.d.ts +43 -8
  31. package/dist/domains/scheduler.d.ts +1 -76
  32. package/dist/domains/server.d.ts +5 -2
  33. package/dist/domains/state.d.ts +2 -5
  34. package/dist/domains/telemetry.d.ts +0 -2
  35. package/dist/elements.d.ts +214 -51
  36. package/dist/error-boundary-Bpwofwps.js +293 -0
  37. package/dist/foundations/icon/index.d.ts +0 -58
  38. package/dist/foundations/icon/index.js +2 -2
  39. package/dist/foundations/index.js +2 -1
  40. package/dist/foundations/interactions/index.js +1 -1
  41. package/dist/foundations/state/index.d.ts +3 -3
  42. package/dist/foundations/state/index.js +5 -3
  43. package/dist/foundations/structures/index.js +2 -1
  44. package/dist/foundations/utilities/index.d.ts +2 -0
  45. package/dist/foundations/utilities/index.js +1 -2
  46. package/dist/fx/index.d.ts +31 -58
  47. package/dist/fx/index.js +313 -195
  48. package/dist/hooks-BimKStr4.js +202 -0
  49. package/dist/index.d.ts +11 -74
  50. package/dist/index.js +8 -447
  51. package/dist/instance-BAnfmXOR.js +988 -0
  52. package/dist/{interactions-CTeACdT_.js → interactions-D2BoREb-.js} +3 -2
  53. package/dist/jsx-dev-runtime.d.ts +41 -18
  54. package/dist/jsx-dev-runtime.js +1 -6
  55. package/dist/{jsx-runtime-CPJXAOBF.js → jsx-runtime-C4idqHY0.js} +18 -7
  56. package/dist/jsx-runtime.js +1 -1
  57. package/dist/jsx.d.ts +61 -37
  58. package/dist/{manifest-D1P3UNWV.js → manifest-CW9gyNBY.js} +3 -3
  59. package/dist/{navigate-prC5V8XV.js → navigate-CP_0Zy5U.js} +454 -87
  60. package/dist/navigation.d.ts +12 -3
  61. package/dist/peer-types.d.ts +8 -0
  62. package/dist/portal-DuOKfnLa.js +349 -0
  63. package/dist/promise-Dz8iIHAm.js +16 -0
  64. package/dist/query-registry-WMCN0BJL.js +320 -0
  65. package/dist/readable-DFWOsTac.js +21 -0
  66. package/dist/{render-context-B7ohlh6t.js → render-context-DGHnEveC.js} +27 -11
  67. package/dist/render-sync-IC5lMFpq.js +1240 -0
  68. package/dist/resolution-Cx82-xjW.js +1244 -0
  69. package/dist/resource-CLjB7RBQ.js +377 -0
  70. package/dist/resources/index.d.ts +21 -11
  71. package/dist/resources/index.js +45 -244
  72. package/dist/router/index.d.ts +14 -5
  73. package/dist/router/index.js +22 -53
  74. package/dist/scope-CwpVSHVf.js +55 -0
  75. package/dist/{shared-kU8yvryp.js → shared-O2ZnmYAf.js} +1 -7
  76. package/dist/{snapshot-source-An4iKajG.js → snapshot-Cjx4N988.js} +6 -1
  77. package/dist/ssg/index.d.ts +1 -2
  78. package/dist/ssg/index.js +5 -13
  79. package/dist/ssr/index.d.ts +26 -28
  80. package/dist/ssr/index.js +4 -4
  81. package/dist/{ssr-CiNm6Vzl.js → ssr-BJ8ug7zH.js} +133 -122
  82. package/dist/ssr-DoV-vJ-5.js +229 -0
  83. package/dist/state-DWO1KzkX.js +232 -0
  84. package/dist/structures-D4dDMqHX.js +231 -0
  85. package/dist/testing/index.d.ts +8 -4
  86. package/dist/testing/index.js +29 -34
  87. package/dist/url-CnbfpX0K.js +185 -0
  88. package/dist/utilities.d.ts +48 -2
  89. package/dist/verify-hydration-DpVaDnqz.js +152 -0
  90. package/package.json +19 -9
  91. package/dist/access-CEA2pOry.js +0 -1046
  92. package/dist/activity-oy2YFTFF.js +0 -201
  93. package/dist/boot-BMBMWUGI.js +0 -1084
  94. package/dist/capabilities-Bbf0mlp9.js +0 -42
  95. package/dist/compose-ref-v0qGlHoN.js +0 -26
  96. package/dist/control-BR_mrX__.js +0 -173
  97. package/dist/control-C-ApnFs1.js +0 -20
  98. package/dist/csp-nonce-BfFWcd0w.js +0 -173
  99. package/dist/data-runtime-CxoY98lX.js +0 -149
  100. package/dist/default-portal-runtime-DvMvWJVp.js +0 -20
  101. package/dist/dom-renderer.d.ts +0 -77
  102. package/dist/domains/renderer.d.ts +0 -127
  103. package/dist/eager-control.d.ts +0 -8
  104. package/dist/effect-C3Zsc1k6.js +0 -292
  105. package/dist/for-state-BDykeOJL.js +0 -1753
  106. package/dist/instance-VAFYVJOa.js +0 -1027
  107. package/dist/notify-DxxuDPeY.js +0 -266
  108. package/dist/portal-w3oQ6oQU.js +0 -29
  109. package/dist/query-registry-LrYpQsDJ.js +0 -83
  110. package/dist/render-resolved-BC0W7_5b.js +0 -1123
  111. package/dist/renderer-CT0HeY58.js +0 -8623
  112. package/dist/resolution-3DskUkjG.js +0 -577
  113. package/dist/resource-18-sFRl9.js +0 -344
  114. package/dist/route-matching-CUzZ31gT.js +0 -551
  115. package/dist/router-internal-7nuNEHfG.js +0 -36
  116. package/dist/scope-Cq_iYbTR.js +0 -403
  117. package/dist/selector-BSPVkjKP.js +0 -311
  118. package/dist/ssr-EPjwJH5R.js +0 -29
  119. package/dist/state-BXJfudq1.js +0 -91
  120. package/dist/structures-CjEzfj4h.js +0 -654
  121. package/dist/timer-C7uqnJVt.js +0 -85
  122. package/dist/verify-hydration-ikaxotf7.js +0 -27
  123. package/dist/vnode-D24p6IW2.js +0 -7
@@ -1,344 +0,0 @@
1
- import { t as enqueueRuntimeLane, v as logger } from "./access-CEA2pOry.js";
2
- import { P as isPromiseLike, d as registerCommitOperationForInstance, h as getCurrentContextFrame, y as withAsyncResourceContext } from "./instance-VAFYVJOa.js";
3
- import { O as ownCleanup, f as getCurrentComponentInstance } from "./scope-Cq_iYbTR.js";
4
- import { t as brandSnapshotSource } from "./snapshot-source-An4iKajG.js";
5
- import { C as SSRDataMissingError, a as getResourceVerificationSnapshot, i as getNextRenderKey, n as getActiveRenderContext, o as isHydrationVerificationRender, p as throwSSRDataMissing, r as getCurrentRenderData, s as recordResourceVerificationSnapshot } from "./render-context-B7ohlh6t.js";
6
- import { t as state } from "./state-BXJfudq1.js";
7
- //#region src/runtime/lifecycle/resource-cell.ts
8
- /**
9
- * Pure, component-agnostic ResourceCell state machine.
10
- * - Holds value/pending/error/generation/controller
11
- * - Exposes a stable `snapshot` object: { value, pending, error, refresh }
12
- * - Uses `withAsyncResourceContext` to bind the synchronous execution step
13
- * to a captured frame. Continuations after await do not see the frame.
14
- */
15
- var ResourceCell = class {
16
- constructor(fn, deps, resourceFrame) {
17
- this.value = null;
18
- this.pending = true;
19
- this.error = null;
20
- this.generation = 0;
21
- this.controller = null;
22
- this.deps = null;
23
- this.resourceFrame = null;
24
- this.subscribers = /* @__PURE__ */ new Set();
25
- this.disposed = false;
26
- this.fn = fn;
27
- this.deps = deps ? deps.slice() : null;
28
- this.resourceFrame = resourceFrame;
29
- this.snapshot = brandSnapshotSource({
30
- value: null,
31
- pending: true,
32
- error: null,
33
- refresh: () => this.refresh()
34
- });
35
- }
36
- setLoader(fn) {
37
- this.fn = fn;
38
- }
39
- subscribe(cb) {
40
- this.subscribers.add(cb);
41
- return () => this.subscribers.delete(cb);
42
- }
43
- notifySubscribers() {
44
- this.snapshot.value = this.value;
45
- this.snapshot.pending = this.pending;
46
- this.snapshot.error = this.error;
47
- for (const cb of this.subscribers) try {
48
- cb();
49
- } catch (error) {
50
- this.reportError(error, "Resource subscriber error");
51
- }
52
- }
53
- reportError(error, label = "Async resource error") {
54
- try {
55
- logger.error(`[Askr] ${label}${this.ownerName ? ` in ${this.ownerName}` : ""}:`, error);
56
- } catch {}
57
- }
58
- start(ssr = false, notify = true) {
59
- if (this.disposed) return;
60
- const generation = this.generation;
61
- const previous = this.controller;
62
- const controller = new AbortController();
63
- this.controller = controller;
64
- const current = () => this.generation === generation && this.controller === controller && !controller.signal.aborted;
65
- previous?.abort();
66
- if (!current()) return;
67
- this.pending = true;
68
- this.error = null;
69
- if (notify) this.notifySubscribers();
70
- if (!current()) return;
71
- const fail = (reason, asynchronous = false) => {
72
- if (!current()) return;
73
- let error;
74
- try {
75
- if (asynchronous && (reason instanceof Error && reason.name === "AbortError" || typeof DOMException !== "undefined" && reason instanceof DOMException && reason.name === "AbortError")) return;
76
- error = reason instanceof Error ? reason : new Error(String(reason));
77
- } catch {
78
- error = /* @__PURE__ */ new Error("Resource error normalization failed");
79
- }
80
- if (!current()) return;
81
- this.pending = false;
82
- this.error = error;
83
- if (asynchronous) this.reportError(reason);
84
- if (current() && (notify || asynchronous)) this.notifySubscribers();
85
- };
86
- let result;
87
- let asynchronous;
88
- try {
89
- result = withAsyncResourceContext(this.resourceFrame, () => this.fn({ signal: controller.signal }));
90
- asynchronous = isPromiseLike(result);
91
- } catch (err) {
92
- fail(err);
93
- return;
94
- }
95
- if (!asynchronous) {
96
- if (!current()) return;
97
- this.value = result;
98
- this.pending = false;
99
- this.error = null;
100
- if (notify) this.notifySubscribers();
101
- return;
102
- }
103
- if (ssr) {
104
- new Promise((resolve) => resolve(result)).then(void 0, () => {});
105
- controller.abort();
106
- throwSSRDataMissing();
107
- }
108
- try {
109
- Promise.resolve(result).then((val) => {
110
- if (!current()) return;
111
- this.value = val;
112
- this.pending = false;
113
- this.error = null;
114
- this.notifySubscribers();
115
- }, (err) => fail(err, true));
116
- } catch (err) {
117
- fail(err);
118
- }
119
- }
120
- refresh() {
121
- if (this.disposed) return;
122
- this.generation++;
123
- this.start();
124
- }
125
- abort() {
126
- this.controller?.abort();
127
- }
128
- dispose() {
129
- if (this.disposed) return;
130
- this.disposed = true;
131
- this.controller?.abort();
132
- this.subscribers.clear();
133
- }
134
- };
135
- //#endregion
136
- //#region src/runtime/lifecycle/resource.ts
137
- function hydrationVerificationSnapshot() {
138
- return brandSnapshotSource({
139
- value: null,
140
- pending: true,
141
- error: null,
142
- refresh: () => {}
143
- });
144
- }
145
- /**
146
- * What resource data, if any, the current render was given.
147
- *
148
- * Both the outside-a-component path and the in-component path asked this
149
- * question, each spelling out the same two-part test by hand. One answer keeps
150
- * the "is this a hydrating render with preloaded values" decision from drifting
151
- * between them.
152
- */
153
- function resolveResourceRenderData() {
154
- const renderData = getCurrentRenderData()?.resources;
155
- return {
156
- renderData,
157
- hasPreloadedData: Boolean(renderData && (getActiveRenderContext()?.resourceDataProvided || Object.keys(renderData).some((key) => key.startsWith("r:"))))
158
- };
159
- }
160
- /**
161
- * Resolve a resource declared outside any component instance.
162
- *
163
- * Only legitimate during a synchronous SSR render that already carries resolved
164
- * data; every other caller is creating a resource where it cannot be owned.
165
- */
166
- function resolveResourceWithoutInstance() {
167
- const { renderData, hasPreloadedData } = resolveResourceRenderData();
168
- if (renderData && hasPreloadedData) {
169
- const key = getNextRenderKey();
170
- if (!(key in renderData)) throwSSRDataMissing();
171
- return brandSnapshotSource({
172
- value: renderData[key],
173
- pending: false,
174
- error: null,
175
- refresh: () => {}
176
- });
177
- }
178
- if (getActiveRenderContext()) throwSSRDataMissing();
179
- throw new Error("[Askr] resource() must be called during component render inside an app. Do not create resources at module scope or outside render.");
180
- }
181
- /**
182
- * Resource primitive — simple, deterministic async primitive
183
- * Usage: resource(fn, deps)
184
- * - fn receives { signal }
185
- * - captures execution context once at creation (synchronous step only)
186
- * - executes at most once per generation; stale async results are ignored
187
- * - refresh() cancels in-flight execution, increments generation and re-runs
188
- * - exposes { value, pending, error, refresh }
189
- * - during SSR, async results are disallowed and will throw synchronously
190
- */
191
- function resource(fn, deps = []) {
192
- const instance = getCurrentComponentInstance();
193
- const inst = instance;
194
- if (!instance) return resolveResourceWithoutInstance();
195
- const { renderData, hasPreloadedData: hasPreloadedResourceData } = resolveResourceRenderData();
196
- const renderKey = inst.ssr || hasPreloadedResourceData ? getNextRenderKey() : null;
197
- const verificationSnapshot = renderKey ? getResourceVerificationSnapshot(renderKey) : null;
198
- if (renderData && hasPreloadedResourceData && renderKey && renderKey in renderData) {
199
- const val = renderData[renderKey];
200
- const h = state({
201
- cell: void 0,
202
- snapshot: brandSnapshotSource({
203
- value: val,
204
- pending: false,
205
- error: null,
206
- refresh: () => {}
207
- })
208
- })();
209
- h.snapshot.value = val;
210
- h.snapshot.pending = false;
211
- h.snapshot.error = null;
212
- return h.snapshot;
213
- }
214
- if (isHydrationVerificationRender() && verificationSnapshot) {
215
- const result = hydrationVerificationSnapshot();
216
- result.value = verificationSnapshot.value;
217
- result.pending = verificationSnapshot.pending;
218
- return result;
219
- }
220
- if (renderData && hasPreloadedResourceData && renderKey && (inst.ssr || !verificationSnapshot)) throwSSRDataMissing();
221
- const ssrRenderKey = inst.ssr ? renderKey : null;
222
- const clientHydrationSnapshot = inst.ssr ? null : verificationSnapshot;
223
- const holder = state({
224
- cell: void 0,
225
- snapshot: brandSnapshotSource({
226
- value: clientHydrationSnapshot ? clientHydrationSnapshot.value : null,
227
- pending: clientHydrationSnapshot?.pending ?? true,
228
- error: null,
229
- refresh: () => {}
230
- })
231
- });
232
- const h = holder();
233
- if (!h.cell) {
234
- const cell = new ResourceCell(fn, deps, getCurrentContextFrame());
235
- if (clientHydrationSnapshot) {
236
- cell.value = clientHydrationSnapshot.value;
237
- cell.pending = clientHydrationSnapshot.pending;
238
- cell.snapshot.value = clientHydrationSnapshot.value;
239
- cell.snapshot.pending = clientHydrationSnapshot.pending;
240
- }
241
- cell.ownerName = inst.fn?.name || "<anonymous>";
242
- h.cell = cell;
243
- h.snapshot = cell.snapshot;
244
- const unsubscribe = cell.subscribe(() => {
245
- const cur = holder();
246
- cur.snapshot.value = cell.snapshot.value;
247
- cur.snapshot.pending = cell.snapshot.pending;
248
- cur.snapshot.error = cell.snapshot.error;
249
- holder.set(cur);
250
- try {
251
- inst.notifyUpdate?.();
252
- } catch {}
253
- });
254
- ownCleanup(inst.owner, unsubscribe);
255
- ownCleanup(inst.owner, () => cell.dispose());
256
- if (inst.ssr) {
257
- cell.start(true, false);
258
- if (!cell.pending) {
259
- const cur = holder();
260
- cur.snapshot.value = cell.value;
261
- cur.snapshot.pending = cell.pending;
262
- cur.snapshot.error = cell.error;
263
- }
264
- if (ssrRenderKey && cell.value === null && cell.error === null) recordResourceVerificationSnapshot(ssrRenderKey, {
265
- value: null,
266
- pending: cell.pending
267
- });
268
- } else {
269
- const scheduledGeneration = cell.generation;
270
- registerCommitOperationForInstance(inst, () => {
271
- enqueueRuntimeLane("post", () => {
272
- if (!inst.notifyUpdate || cell.generation !== scheduledGeneration) return;
273
- try {
274
- cell.start(false, false);
275
- } catch (err) {
276
- const cur = holder();
277
- cur.snapshot.value = cell.value;
278
- cur.snapshot.pending = cell.pending;
279
- cur.snapshot.error = err ?? null;
280
- holder.set(cur);
281
- inst.notifyUpdate?.();
282
- return;
283
- }
284
- if (!cell.pending) {
285
- const cur = holder();
286
- cur.snapshot.value = cell.value;
287
- cur.snapshot.pending = cell.pending;
288
- cur.snapshot.error = cell.error;
289
- holder.set(cur);
290
- inst.notifyUpdate?.();
291
- }
292
- });
293
- });
294
- }
295
- }
296
- const cell = h.cell;
297
- cell.setLoader(fn);
298
- if (!cell.deps || cell.deps.length !== deps.length || cell.deps.some((d, i) => !Object.is(d, deps[i]))) {
299
- cell.deps = deps.slice();
300
- cell.generation++;
301
- cell.pending = true;
302
- cell.error = null;
303
- h.snapshot.pending = true;
304
- h.snapshot.error = null;
305
- try {
306
- if (inst.ssr) {
307
- cell.start(true, false);
308
- if (!cell.pending) {
309
- const cur = holder();
310
- cur.snapshot.value = cell.value;
311
- cur.snapshot.pending = cell.pending;
312
- cur.snapshot.error = cell.error;
313
- }
314
- } else {
315
- const scheduledGeneration = cell.generation;
316
- registerCommitOperationForInstance(inst, () => {
317
- enqueueRuntimeLane("post", () => {
318
- if (!inst.notifyUpdate || cell.generation !== scheduledGeneration) return;
319
- cell.start(false, false);
320
- if (!cell.pending) {
321
- const cur = holder();
322
- cur.snapshot.value = cell.value;
323
- cur.snapshot.pending = cell.pending;
324
- cur.snapshot.error = cell.error;
325
- holder.set(cur);
326
- inst.notifyUpdate?.();
327
- }
328
- });
329
- });
330
- }
331
- } catch (err) {
332
- if (err instanceof SSRDataMissingError) throw err;
333
- cell.error = err;
334
- cell.pending = false;
335
- const cur = holder();
336
- cur.snapshot.value = cell.value;
337
- cur.snapshot.pending = cell.pending;
338
- cur.snapshot.error = cell.error;
339
- }
340
- }
341
- return h.snapshot;
342
- }
343
- //#endregion
344
- export { resource as t };