@pithyjs/core 0.1.0-beta.0 → 0.1.0-beta.10

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 (226) hide show
  1. package/README.md +37 -6
  2. package/dist/a11y/focus-trap.d.ts.map +1 -1
  3. package/dist/a11y/focus-trap.js +2 -0
  4. package/dist/a11y/focus-trap.js.map +1 -1
  5. package/dist/a11y/index.d.ts +4 -4
  6. package/dist/a11y/index.js +4 -4
  7. package/dist/a11y/index.js.map +1 -1
  8. package/dist/a11y/keyboard-utils.js.map +1 -1
  9. package/dist/a11y/roving-tabindex.js.map +1 -1
  10. package/dist/a11y/skip-link.js.map +1 -1
  11. package/dist/compile/bindSwitchCases.d.ts +8 -3
  12. package/dist/compile/bindSwitchCases.d.ts.map +1 -1
  13. package/dist/compile/bindSwitchCases.js +113 -177
  14. package/dist/compile/bindSwitchCases.js.map +1 -1
  15. package/dist/compile/binds/bindBoundAttributes.d.ts +1 -0
  16. package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -1
  17. package/dist/compile/binds/bindBoundAttributes.js +24 -2
  18. package/dist/compile/binds/bindBoundAttributes.js.map +1 -1
  19. package/dist/compile/binds/bindClassDirectives.d.ts +3 -0
  20. package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
  21. package/dist/compile/binds/bindClassDirectives.js +59 -21
  22. package/dist/compile/binds/bindClassDirectives.js.map +1 -1
  23. package/dist/compile/binds/bindComponentsTags.d.ts +2 -0
  24. package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
  25. package/dist/compile/binds/bindComponentsTags.js +171 -74
  26. package/dist/compile/binds/bindComponentsTags.js.map +1 -1
  27. package/dist/compile/binds/bindConditionals.d.ts +2 -2
  28. package/dist/compile/binds/bindConditionals.d.ts.map +1 -1
  29. package/dist/compile/binds/bindConditionals.js +22 -5
  30. package/dist/compile/binds/bindConditionals.js.map +1 -1
  31. package/dist/compile/binds/bindDefaultTwoWay.d.ts.map +1 -1
  32. package/dist/compile/binds/bindDefaultTwoWay.js +2 -1
  33. package/dist/compile/binds/bindDefaultTwoWay.js.map +1 -1
  34. package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -1
  35. package/dist/compile/binds/bindDeferDirectives.js +45 -15
  36. package/dist/compile/binds/bindDeferDirectives.js.map +1 -1
  37. package/dist/compile/binds/bindErrorBoundary.d.ts +13 -2
  38. package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
  39. package/dist/compile/binds/bindErrorBoundary.js +25 -10
  40. package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
  41. package/dist/compile/binds/bindEventHandlers.js +2 -2
  42. package/dist/compile/binds/bindEventHandlers.js.map +1 -1
  43. package/dist/compile/binds/bindRefDirectives.js.map +1 -1
  44. package/dist/compile/binds/bindStyleDirectives.d.ts +17 -0
  45. package/dist/compile/binds/bindStyleDirectives.d.ts.map +1 -0
  46. package/dist/compile/binds/bindStyleDirectives.js +47 -0
  47. package/dist/compile/binds/bindStyleDirectives.js.map +1 -0
  48. package/dist/compile/binds/bindTextInterpolations.d.ts +2 -1
  49. package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -1
  50. package/dist/compile/binds/bindTextInterpolations.js +55 -17
  51. package/dist/compile/binds/bindTextInterpolations.js.map +1 -1
  52. package/dist/compile/binds/directiveRegistry.js.map +1 -1
  53. package/dist/compile/binds/forwardedAttrs.d.ts +22 -0
  54. package/dist/compile/binds/forwardedAttrs.d.ts.map +1 -0
  55. package/dist/compile/binds/forwardedAttrs.js +66 -0
  56. package/dist/compile/binds/forwardedAttrs.js.map +1 -0
  57. package/dist/compile/binds/propNames.d.ts +14 -0
  58. package/dist/compile/binds/propNames.d.ts.map +1 -0
  59. package/dist/compile/binds/propNames.js +116 -0
  60. package/dist/compile/binds/propNames.js.map +1 -0
  61. package/dist/compile/compileExpression.js.map +1 -1
  62. package/dist/compile/compileNodes.d.ts.map +1 -1
  63. package/dist/compile/compileNodes.js +6 -3
  64. package/dist/compile/compileNodes.js.map +1 -1
  65. package/dist/compile/compileTemplate.d.ts +3 -4
  66. package/dist/compile/compileTemplate.d.ts.map +1 -1
  67. package/dist/compile/compileTemplate.js +28 -31
  68. package/dist/compile/compileTemplate.js.map +1 -1
  69. package/dist/compile/componentResult.d.ts +100 -0
  70. package/dist/compile/componentResult.d.ts.map +1 -0
  71. package/dist/compile/componentResult.js +138 -0
  72. package/dist/compile/componentResult.js.map +1 -0
  73. package/dist/compile/contentProjection.d.ts +1 -1
  74. package/dist/compile/contentProjection.d.ts.map +1 -1
  75. package/dist/compile/contentProjection.js +32 -15
  76. package/dist/compile/contentProjection.js.map +1 -1
  77. package/dist/compile/forLoops/bindForLoops.d.ts +2 -2
  78. package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -1
  79. package/dist/compile/forLoops/bindForLoops.js +9 -22
  80. package/dist/compile/forLoops/bindForLoops.js.map +1 -1
  81. package/dist/compile/forLoops/createLoopManager.d.ts +6 -3
  82. package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
  83. package/dist/compile/forLoops/createLoopManager.js +144 -114
  84. package/dist/compile/forLoops/createLoopManager.js.map +1 -1
  85. package/dist/compile/forLoops/index.d.ts +5 -5
  86. package/dist/compile/forLoops/index.js +5 -5
  87. package/dist/compile/forLoops/index.js.map +1 -1
  88. package/dist/compile/forLoops/loopHelpers.d.ts +6 -0
  89. package/dist/compile/forLoops/loopHelpers.d.ts.map +1 -1
  90. package/dist/compile/forLoops/loopHelpers.js +17 -0
  91. package/dist/compile/forLoops/loopHelpers.js.map +1 -1
  92. package/dist/compile/forLoops/loopSignals.js +2 -2
  93. package/dist/compile/forLoops/loopSignals.js.map +1 -1
  94. package/dist/compile/forLoops/loopTraversal.js +2 -2
  95. package/dist/compile/forLoops/loopTraversal.js.map +1 -1
  96. package/dist/compile/handleConditionalChain.d.ts +2 -2
  97. package/dist/compile/handleConditionalChain.d.ts.map +1 -1
  98. package/dist/compile/handleConditionalChain.js +21 -83
  99. package/dist/compile/handleConditionalChain.js.map +1 -1
  100. package/dist/compile/index.d.ts +17 -14
  101. package/dist/compile/index.d.ts.map +1 -1
  102. package/dist/compile/index.js +28 -12
  103. package/dist/compile/index.js.map +1 -1
  104. package/dist/compile/injectScopedStyle.js.map +1 -1
  105. package/dist/compile/nodeExpando.d.ts +6 -0
  106. package/dist/compile/nodeExpando.d.ts.map +1 -1
  107. package/dist/compile/nodeExpando.js.map +1 -1
  108. package/dist/compile/parseHtml.d.ts.map +1 -1
  109. package/dist/compile/parseHtml.js +2 -2
  110. package/dist/compile/parseHtml.js.map +1 -1
  111. package/dist/compile/pithyTreeToDom.js +1 -1
  112. package/dist/compile/pithyTreeToDom.js.map +1 -1
  113. package/dist/compile/renderBranch.d.ts +13 -0
  114. package/dist/compile/renderBranch.d.ts.map +1 -0
  115. package/dist/compile/renderBranch.js +65 -0
  116. package/dist/compile/renderBranch.js.map +1 -0
  117. package/dist/compile/renderChildren.d.ts +17 -0
  118. package/dist/compile/renderChildren.d.ts.map +1 -1
  119. package/dist/compile/renderChildren.js +22 -3
  120. package/dist/compile/renderChildren.js.map +1 -1
  121. package/dist/compile/ssrCrashes.d.ts +116 -0
  122. package/dist/compile/ssrCrashes.d.ts.map +1 -0
  123. package/dist/compile/ssrCrashes.js +173 -0
  124. package/dist/compile/ssrCrashes.js.map +1 -0
  125. package/dist/compile/ssrMode.js +1 -1
  126. package/dist/compile/ssrMode.js.map +1 -1
  127. package/dist/compile/textValue.js.map +1 -1
  128. package/dist/compile/trimBlankEdges.d.ts +2 -0
  129. package/dist/compile/trimBlankEdges.d.ts.map +1 -0
  130. package/dist/compile/trimBlankEdges.js +15 -0
  131. package/dist/compile/trimBlankEdges.js.map +1 -0
  132. package/dist/config/index.js.map +1 -1
  133. package/dist/index.d.ts +6 -6
  134. package/dist/index.js +6 -6
  135. package/dist/index.js.map +1 -1
  136. package/dist/interfaces/index.d.ts +2 -2
  137. package/dist/interfaces/index.js +2 -2
  138. package/dist/interfaces/index.js.map +1 -1
  139. package/dist/interfaces/ref-signal.interface.js.map +1 -1
  140. package/dist/interfaces/ref.interface.js.map +1 -1
  141. package/dist/runtime/applyBindings.d.ts +5 -5
  142. package/dist/runtime/applyBindings.d.ts.map +1 -1
  143. package/dist/runtime/applyBindings.js +97 -21
  144. package/dist/runtime/applyBindings.js.map +1 -1
  145. package/dist/runtime/bindings/applyComponent.d.ts +2 -2
  146. package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
  147. package/dist/runtime/bindings/applyComponent.js +137 -39
  148. package/dist/runtime/bindings/applyComponent.js.map +1 -1
  149. package/dist/runtime/bindings/applyDefer.d.ts +1 -1
  150. package/dist/runtime/bindings/applyDefer.d.ts.map +1 -1
  151. package/dist/runtime/bindings/applyDefer.js +46 -18
  152. package/dist/runtime/bindings/applyDefer.js.map +1 -1
  153. package/dist/runtime/bindings/applySimple.d.ts +2 -1
  154. package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
  155. package/dist/runtime/bindings/applySimple.js +70 -14
  156. package/dist/runtime/bindings/applySimple.js.map +1 -1
  157. package/dist/runtime/bindings/applyStructural.d.ts +1 -1
  158. package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
  159. package/dist/runtime/bindings/applyStructural.js +58 -68
  160. package/dist/runtime/bindings/applyStructural.js.map +1 -1
  161. package/dist/runtime/bindings/helpers.d.ts +1 -1
  162. package/dist/runtime/bindings/helpers.js +1 -1
  163. package/dist/runtime/bindings/helpers.js.map +1 -1
  164. package/dist/runtime/bindings/index.d.ts +6 -6
  165. package/dist/runtime/bindings/index.d.ts.map +1 -1
  166. package/dist/runtime/bindings/index.js +5 -5
  167. package/dist/runtime/bindings/index.js.map +1 -1
  168. package/dist/runtime/bindings/types.d.ts +12 -1
  169. package/dist/runtime/bindings/types.d.ts.map +1 -1
  170. package/dist/runtime/bindings/types.js.map +1 -1
  171. package/dist/runtime/bootstrap.d.ts +1 -1
  172. package/dist/runtime/bootstrap.js +1 -1
  173. package/dist/runtime/bootstrap.js.map +1 -1
  174. package/dist/runtime/createContextProxy.js.map +1 -1
  175. package/dist/runtime/deferHelpers.d.ts +1 -1
  176. package/dist/runtime/deferHelpers.js.map +1 -1
  177. package/dist/runtime/html.d.ts.map +1 -1
  178. package/dist/runtime/html.js +6 -5
  179. package/dist/runtime/html.js.map +1 -1
  180. package/dist/runtime/index.d.ts +6 -5
  181. package/dist/runtime/index.d.ts.map +1 -1
  182. package/dist/runtime/index.js +7 -5
  183. package/dist/runtime/index.js.map +1 -1
  184. package/dist/runtime/lazy.js +1 -1
  185. package/dist/runtime/lazy.js.map +1 -1
  186. package/dist/runtime/module-cache.js.map +1 -1
  187. package/dist/runtime/onDestroy.d.ts +7 -0
  188. package/dist/runtime/onDestroy.d.ts.map +1 -1
  189. package/dist/runtime/onDestroy.js +16 -1
  190. package/dist/runtime/onDestroy.js.map +1 -1
  191. package/dist/runtime/parseIdentifiersFromTemplate.js +1 -1
  192. package/dist/runtime/parseIdentifiersFromTemplate.js.map +1 -1
  193. package/dist/runtime/resource/createAction.d.ts +44 -0
  194. package/dist/runtime/resource/createAction.d.ts.map +1 -0
  195. package/dist/runtime/resource/createAction.js +102 -0
  196. package/dist/runtime/resource/createAction.js.map +1 -0
  197. package/dist/runtime/resource/createResource.d.ts +56 -0
  198. package/dist/runtime/resource/createResource.d.ts.map +1 -0
  199. package/dist/runtime/resource/createResource.js +102 -0
  200. package/dist/runtime/resource/createResource.js.map +1 -0
  201. package/dist/runtime/resource/engine.d.ts +136 -0
  202. package/dist/runtime/resource/engine.d.ts.map +1 -0
  203. package/dist/runtime/resource/engine.js +363 -0
  204. package/dist/runtime/resource/engine.js.map +1 -0
  205. package/dist/runtime/resource/index.d.ts +19 -0
  206. package/dist/runtime/resource/index.d.ts.map +1 -0
  207. package/dist/runtime/resource/index.js +18 -0
  208. package/dist/runtime/resource/index.js.map +1 -0
  209. package/dist/runtime/resource/types.d.ts +240 -0
  210. package/dist/runtime/resource/types.d.ts.map +1 -0
  211. package/dist/runtime/resource/types.js +9 -0
  212. package/dist/runtime/resource/types.js.map +1 -0
  213. package/dist/types/globals.d.ts +10 -1
  214. package/dist/types/globals.d.ts.map +1 -1
  215. package/dist/types/globals.js.map +1 -1
  216. package/dist/types/index.d.ts +15 -1
  217. package/dist/types/index.d.ts.map +1 -1
  218. package/dist/types/index.js.map +1 -1
  219. package/dist/utilities/index.d.ts +2 -2
  220. package/dist/utilities/index.js +2 -2
  221. package/dist/utilities/index.js.map +1 -1
  222. package/dist/utilities/ref-signal.utility.d.ts +1 -1
  223. package/dist/utilities/ref-signal.utility.js.map +1 -1
  224. package/dist/utilities/ref.untility.d.ts +1 -1
  225. package/dist/utilities/ref.untility.js.map +1 -1
  226. package/package.json +14 -9
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAaxC,OAAO,EACL,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,YAAY,GAClB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,UAAU,GAChB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACL,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/D,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAaxC,OAAO,EACL,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,YAAY,GAClB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,UAAU,GAChB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACL,cAAc,EACd,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/D,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,5 +1,5 @@
1
- export { html } from './html';
2
- export { onDestroy } from './onDestroy';
1
+ export { html } from './html.js';
2
+ export { onDestroy } from './onDestroy.js';
3
3
  // JIT compiler loading is NOT re-exported from this barrel to prevent
4
4
  // parse5 from being pulled into production bundles via the barrel chain.
5
5
  // Use the dedicated subpath export:
@@ -9,13 +9,15 @@ export { onDestroy } from './onDestroy';
9
9
  // import { __applyBindings } from '@pithyjs/core/runtime/applyBindings'
10
10
  // Fully implemented in Phase 5 (Runtime Binder) — see applyBindings.ts.
11
11
  // Module cache (shared across router, prefetch, lazy components)
12
- export { loadModule, getModuleRecord, invalidateModule, getResolvedModuleKeys, clearModuleCache, } from './module-cache';
12
+ export { loadModule, getModuleRecord, invalidateModule, getResolvedModuleKeys, clearModuleCache, } from './module-cache.js';
13
13
  // Lazy loading
14
- export { lazy, isLazyHandle, preloadLazy, } from './lazy';
14
+ export { lazy, isLazyHandle, preloadLazy, } from './lazy.js';
15
+ // Async state primitives (reactive query + mutation)
16
+ export { createResource, createAction, } from './resource/index.js';
15
17
  // Visibility trigger (IntersectionObserver pool) - from @pithyjs/shared
16
18
  export { DEFAULT_VISIBILITY_MARGIN, observeVisibilityOnce, } from '@pithyjs/shared';
17
19
  // App bootstrap (fresh mount, no hydration)
18
- export { bootstrap } from './bootstrap';
20
+ export { bootstrap } from './bootstrap.js';
19
21
  // App configuration (re-export from @pithyjs/shared for convenience)
20
22
  export { defineConfig } from '@pithyjs/shared';
21
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,sEAAsE;AACtE,yEAAyE;AACzE,oCAAoC;AACpC,sEAAsE;AAEtE,uEAAuE;AACvE,4DAA4D;AAC5D,0EAA0E;AAC1E,wEAAwE;AAExE,iEAAiE;AACjE,OAAO,EACL,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,gBAAgB,CAAC;AAExB,eAAe;AACf,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,WAAW,GAIZ,MAAM,QAAQ,CAAC;AAEhB,wEAAwE;AACxE,OAAO,EACL,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,4CAA4C;AAC5C,OAAO,EAAE,SAAS,EAAyB,MAAM,aAAa,CAAC;AAE/D,qEAAqE;AACrE,OAAO,EAAE,YAAY,EAAoB,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,sEAAsE;AACtE,yEAAyE;AACzE,oCAAoC;AACpC,sEAAsE;AAEtE,uEAAuE;AACvE,4DAA4D;AAC5D,0EAA0E;AAC1E,wEAAwE;AAExE,iEAAiE;AACjE,OAAO,EACL,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,gBAAgB,CAAC;AAExB,eAAe;AACf,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,WAAW,GAIZ,MAAM,QAAQ,CAAC;AAEhB,qDAAqD;AACrD,OAAO,EACL,cAAc,EACd,YAAY,GAUb,MAAM,YAAY,CAAC;AAEpB,wEAAwE;AACxE,OAAO,EACL,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,4CAA4C;AAC5C,OAAO,EAAE,SAAS,EAAyB,MAAM,aAAa,CAAC;AAE/D,qEAAqE;AACrE,OAAO,EAAE,YAAY,EAAoB,MAAM,iBAAiB,CAAC","sourcesContent":["export { html } from './html';\nexport { onDestroy } from './onDestroy';\n\n// JIT compiler loading is NOT re-exported from this barrel to prevent\n// parse5 from being pulled into production bundles via the barrel chain.\n// Use the dedicated subpath export:\n// import { loadJITCompiler } from '@pithyjs/core/compile/parseHtml'\n\n// NOTE: __applyBindings is NOT re-exported here — it's an internal API\n// consumed by AOT-generated code via direct subpath import:\n// import { __applyBindings } from '@pithyjs/core/runtime/applyBindings'\n// Fully implemented in Phase 5 (Runtime Binder) — see applyBindings.ts.\n\n// Module cache (shared across router, prefetch, lazy components)\nexport {\n loadModule,\n getModuleRecord,\n invalidateModule,\n getResolvedModuleKeys,\n clearModuleCache,\n type ModuleRecord,\n} from './module-cache';\n\n// Lazy loading\nexport {\n lazy,\n isLazyHandle,\n preloadLazy,\n type LazyState,\n type LazyOptions,\n type LazyHandle,\n} from './lazy';\n\n// Async state primitives (reactive query + mutation)\nexport {\n createResource,\n createAction,\n type ResourceStatus,\n type ResourceFetcher,\n type ResourceOptions,\n type ResourceHandle,\n type ActionPerformer,\n type ActionOverlap,\n type ActionOptions,\n type ActionHandle,\n type ActionResult,\n} from './resource';\n\n// Visibility trigger (IntersectionObserver pool) - from @pithyjs/shared\nexport {\n DEFAULT_VISIBILITY_MARGIN,\n observeVisibilityOnce,\n} from '@pithyjs/shared';\n\n// App bootstrap (fresh mount, no hydration)\nexport { bootstrap, type BootstrapOptions } from './bootstrap';\n\n// App configuration (re-export from @pithyjs/shared for convenience)\nexport { defineConfig, type PithyConfig } from '@pithyjs/shared';\n"]}
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { signal } from '@pithyjs/signals';
17
17
  import { DEFAULT_LAZY_TIMEOUT } from '@pithyjs/compiler';
18
- import { loadModule, invalidateModule, getModuleRecord } from './module-cache';
18
+ import { loadModule, invalidateModule, getModuleRecord } from './module-cache.js';
19
19
  /** Symbol used to identify LazyHandle instances (internal) */
20
20
  const LAZY_HANDLE_SYMBOL = Symbol('pithy-lazy-handle');
21
21
  /** Counter for generating unique keys when path isn't available */
@@ -1 +1 @@
1
- {"version":3,"file":"lazy.js","sourceRoot":"","sources":["../../src/runtime/lazy.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAe,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAwB,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE/E,8DAA8D;AAC9D,MAAM,kBAAkB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAsGvD,mEAAmE;AACnE,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,oKAAoK;AACpK,MAAM,UAAU,IAAI,CAClB,MAAwB,EAC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**\n * Lazy Loading Runtime\n *\n * Provides the `lazy()` function for component-level lazy loading.\n * Components wrapped with lazy() are only loaded when triggered by @defer directive.\n *\n * @module runtime/lazy\n */\n\nimport { signal, type Signal } from '@pithyjs/signals';\nimport { DEFAULT_LAZY_TIMEOUT, type LoadingPriority } from '@pithyjs/compiler';\nimport { loadModule, invalidateModule, getModuleRecord } from './module-cache';\n\n/** Symbol used to identify LazyHandle instances (internal) */\nconst LAZY_HANDLE_SYMBOL = Symbol('pithy-lazy-handle');\n\n/** @codexApi {\"parent\":\"pithy.core.lazy\",\"name\":\"LazyState\",\"stability\":\"stable\",\"signature\":\"type LazyState = 'idle' | 'loading' | 'loaded' | 'error'\"} */\n/** Possible states for a lazy component */\nexport type LazyState = 'idle' | 'loading' | 'loaded' | 'error';\n\n/** @codexApi {\"parent\":\"pithy.core.lazy\",\"name\":\"LazyOptions\",\"stability\":\"stable\",\"signature\":\"interface LazyOptions\"} */\n/** Options for configuring lazy loading behavior */\nexport interface LazyOptions {\n /**\n * Custom key for this lazy component in the module cache.\n * Should start with 'lazy-' to match Vite chunk naming convention.\n *\n * @example\n * ```ts\n * // Use with Vite magic comment for chunk naming\n * const UserCard = lazy(\n * () => import(/* webpackChunkName: \"lazy-UserCard\" *\\/ './UserCard.pithy'),\n * { key: 'lazy-UserCard' }\n * );\n * ```\n */\n key?: string;\n\n /**\n * Callback invoked when loading fails.\n * Called with the error that occurred.\n */\n onError?: (error: unknown) => void;\n\n /**\n * Timeout in milliseconds before loading is considered failed.\n * @default DEFAULT_LAZY_TIMEOUT (30 seconds)\n */\n timeoutMs?: number;\n\n /**\n * Loading priority hint.\n * 'high' modules are loaded before 'low' priority modules.\n * @default 'low'\n */\n priority?: LoadingPriority;\n}\n\n/** @codexApi {\"parent\":\"pithy.core.lazy\",\"name\":\"LazyHandle\",\"stability\":\"stable\",\"signature\":\"interface LazyHandle<T>\"} */\n/** Handle returned by lazy() for controlling lazy component loading */\nexport interface LazyHandle<T> {\n /**\n * Unique key for this lazy component in the module cache.\n * Format: 'component:{path}'\n */\n readonly key: string;\n\n /**\n * Trigger the load (idempotent, returns cached promise).\n * Multiple calls return the same promise.\n */\n load: () => Promise<T>;\n\n /**\n * Current loading state as a reactive signal.\n * Subscribe to this for reactive UI updates.\n */\n state: Signal<LazyState>;\n\n /**\n * Resolved module value (undefined until loaded).\n */\n module: T | undefined;\n\n /**\n * Error if load failed (undefined otherwise).\n */\n error: Error | undefined;\n\n /**\n * Cancel an in-flight load.\n * Has no effect if already loaded or idle.\n */\n cancel: () => void;\n\n /**\n * Retry loading after an error.\n * Clears the error state and attempts to load again.\n */\n retry: () => Promise<T>;\n\n /**\n * Loading priority for this component.\n */\n readonly priority: LoadingPriority;\n}\n\n/** Internal tracking for lazy handles */\ninterface LazyInternal<T> {\n handle: LazyHandle<T>;\n abortController: AbortController | null;\n timeoutId: ReturnType<typeof setTimeout> | null;\n loadPromise: Promise<T> | null;\n retryCount: number;\n}\n\n/** Counter for generating unique keys when path isn't available */\nlet lazyIdCounter = 0;\n\n/**\n * Wrap a dynamic import for lazy loading.\n *\n * Creates a lazy handle that can be used with the @defer directive\n * to load components on-demand.\n *\n * @param loader - Function returning a dynamic import promise\n * @param options - Configuration options\n * @returns LazyHandle for controlling the lazy component\n *\n * @example\n * ```ts\n * // Basic usage\n * const UserCard = lazy(() => import('./UserCard.pithy'));\n *\n * // With options\n * const HeavyChart = lazy(() => import('./HeavyChart.pithy'), {\n * timeoutMs: 10000,\n * onError: (err) => console.error('Failed to load chart', err),\n * });\n * ```\n *\n * In template with the `@defer` directive:\n *\n * ```html\n * <div @defer=\"visible\" @load=\"UserCard\" @placeholder=\"Skeleton\"></div>\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.core.lazy\",\"name\":\"lazy\",\"stability\":\"stable\",\"signature\":\"<T>(loader: () => Promise<T>, options?: LazyOptions) => LazyHandle<T>\"} */\nexport function lazy<T = unknown>(\n loader: () => Promise<T>,\n options: LazyOptions = {}\n): LazyHandle<T> {\n const {\n key: customKey,\n onError,\n timeoutMs = DEFAULT_LAZY_TIMEOUT,\n priority = 'low',\n } = options;\n\n // Generate unique key for this lazy component\n // Use custom key if provided (for predictable chunk naming)\n // Otherwise use a counter-based key\n const key = customKey\n ? `component:${customKey}`\n : `component:lazy-${++lazyIdCounter}`;\n\n // Create reactive state signal\n const state = signal<LazyState>('idle');\n\n // Internal state\n const internal: LazyInternal<T> = {\n handle: null as unknown as LazyHandle<T>, // Set below\n abortController: null,\n timeoutId: null,\n loadPromise: null,\n retryCount: 0,\n };\n\n /**\n * Cancel in-flight load\n */\n function cancel(): void {\n if (internal.abortController) {\n internal.abortController.abort();\n internal.abortController = null;\n }\n\n if (internal.timeoutId) {\n clearTimeout(internal.timeoutId);\n internal.timeoutId = null;\n }\n\n // Only reset to idle if we were loading\n if (state() === 'loading') {\n state.set('idle');\n }\n\n internal.loadPromise = null;\n }\n\n /**\n * Load the component\n */\n function load(): Promise<T> {\n // If already loaded, return cached module\n const cached = getModuleRecord<T>(key);\n if (cached?.status === 'resolved' && cached.value !== undefined) {\n internal.handle.module = cached.value;\n state.set('loaded');\n return Promise.resolve(cached.value);\n }\n\n // If already loading, return existing promise\n if (internal.loadPromise && state() === 'loading') {\n return internal.loadPromise;\n }\n\n // If there was an error, need to call retry() instead\n if (cached?.status === 'rejected') {\n return retry();\n }\n\n // Start new load\n state.set('loading');\n internal.abortController = new AbortController();\n\n // Set up timeout\n if (timeoutMs > 0) {\n internal.timeoutId = setTimeout(() => {\n const error = new Error(\n `Lazy load timeout: Component did not load within ${timeoutMs}ms`\n );\n handleError(error);\n }, timeoutMs);\n }\n\n // Create load promise\n internal.loadPromise = loadModule<T>(key, loader)\n .then(module => {\n // Clear timeout on success\n if (internal.timeoutId) {\n clearTimeout(internal.timeoutId);\n internal.timeoutId = null;\n }\n\n // Check if cancelled\n if (internal.abortController?.signal.aborted) {\n throw new Error('Load cancelled');\n }\n\n // Update handle\n internal.handle.module = module;\n internal.handle.error = undefined;\n state.set('loaded');\n\n return module;\n })\n .catch(err => {\n handleError(err);\n throw err;\n });\n\n return internal.loadPromise;\n }\n\n /**\n * Handle load error\n */\n function handleError(err: unknown): void {\n // Clear timeout\n if (internal.timeoutId) {\n clearTimeout(internal.timeoutId);\n internal.timeoutId = null;\n }\n\n // Don't update state if cancelled\n if (internal.abortController?.signal.aborted) {\n return;\n }\n\n // Update handle\n const error = err instanceof Error ? err : new Error(String(err));\n internal.handle.error = error;\n state.set('error');\n\n // Call error callback\n if (onError) {\n try {\n onError(error);\n } catch (callbackErr) {\n if (import.meta.env?.DEV) {\n console.error('[lazy] Error in onError callback:', callbackErr);\n }\n }\n }\n\n internal.loadPromise = null;\n }\n\n /**\n * Retry after error\n */\n function retry(): Promise<T> {\n // Extract URL from error message for cache busting\n // Browser caches dynamic imports, so we need to bust the cache with a new URL\n let cacheBustUrl: string | null = null;\n if (internal.handle.error) {\n const errorMsg = internal.handle.error.message || '';\n // Extract URL from \"Failed to fetch dynamically imported module: <url>\"\n const urlMatch = errorMsg.match(/module:\\s*(.+)$/);\n if (urlMatch) {\n const originalUrl = urlMatch[1].trim();\n // Add or update cache-bust parameter\n try {\n const url = new URL(originalUrl);\n url.searchParams.set('_retry', Date.now().toString());\n cacheBustUrl = url.href;\n } catch {\n // URL parsing failed, fall back to normal retry\n }\n }\n }\n\n // Clear previous error state\n internal.handle.error = undefined;\n\n // Invalidate cached error in our module cache\n invalidateModule(key);\n\n // Increment retry count\n internal.retryCount++;\n\n // Reset state\n state.set('idle');\n internal.loadPromise = null;\n\n // If we have a cache-bust URL, use it to bypass browser's import cache\n if (cacheBustUrl) {\n return loadWithCacheBust(cacheBustUrl);\n }\n\n // Fall back to normal load\n return load();\n }\n\n /**\n * Load with a cache-busted URL (for retry after failure)\n */\n function loadWithCacheBust(url: string): Promise<T> {\n // Start new load\n state.set('loading');\n internal.abortController = new AbortController();\n\n // Set up timeout\n if (timeoutMs > 0) {\n internal.timeoutId = setTimeout(() => {\n const error = new Error(\n `Lazy load timeout: Component did not load within ${timeoutMs}ms`\n );\n handleError(error);\n }, timeoutMs);\n }\n\n // Use dynamic import with cache-busted URL\n // This bypasses both our cache and the browser's import cache\n internal.loadPromise = import(/* @vite-ignore */ url)\n .then(module => {\n // Clear timeout on success\n if (internal.timeoutId) {\n clearTimeout(internal.timeoutId);\n internal.timeoutId = null;\n }\n\n // Check if cancelled\n if (internal.abortController?.signal.aborted) {\n throw new Error('Load cancelled');\n }\n\n // Update handle BEFORE setting state (effects run synchronously)\n internal.handle.module = module as T;\n internal.handle.error = undefined;\n\n // Update our module cache BEFORE setting state to 'loaded'\n // This is critical because effects run synchronously and may call load()\n // which needs to see the cached module\n loadModule(key, () => Promise.resolve(module as T));\n\n // Now set state to loaded (this triggers effects)\n state.set('loaded');\n\n return module as T;\n })\n .catch(err => {\n handleError(err);\n throw err;\n });\n\n return internal.loadPromise;\n }\n\n // Create the handle with symbol brand\n const handle = {\n [LAZY_HANDLE_SYMBOL]: true,\n key,\n load,\n state,\n module: undefined,\n error: undefined,\n cancel,\n retry,\n priority,\n } as LazyHandle<T>;\n\n // Store reference for internal use\n internal.handle = handle;\n\n return handle;\n}\n\n/**\n * Check if a value is a LazyHandle.\n * Uses Symbol-based branding for reliable type checking.\n *\n * @param value - Value to check\n * @returns True if value is a LazyHandle\n */\n/** @codexApi {\"parent\":\"pithy.core.lazy\",\"name\":\"isLazyHandle\",\"stability\":\"stable\",\"signature\":\"(value: unknown) => value is LazyHandle<unknown>\"} */\nexport function isLazyHandle(value: unknown): value is LazyHandle<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as Record<symbol, unknown>)[LAZY_HANDLE_SYMBOL] === true\n );\n}\n\n/**\n * Preload a lazy component without mounting it.\n * Useful for prefetching on hover or when idle.\n *\n * @param handle - LazyHandle to preload\n * @returns Promise that resolves when loaded\n */\n/** @codexApi {\"parent\":\"pithy.core.lazy\",\"name\":\"preloadLazy\",\"stability\":\"stable\",\"signature\":\"<T>(handle: LazyHandle<T>) => Promise<T>\"} */\nexport function preloadLazy<T>(handle: LazyHandle<T>): Promise<T> {\n return handle.load();\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"module-cache.js","sourceRoot":"","sources":["../../src/runtime/module-cache.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAwBF,uDAAuD;AACvD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAwB,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,qKAAqK;AACrK,MAAM,UAAU,UAAU,CACxB,GAAW,EACX,MAAwB;IAExB,IAAI,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAgC,CAAC;IAEjE,IAAI,MAAM,EAAE,CAAC;QACX,iEAAiE;QACjE,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,wCAAwC;IACxC,MAAM,OAAO,GAAG,MAAM,EAAE;SACrB,IAAI,CAAC,KAAK,CAAC,EAAE;QACZ,2BAA2B;QAC3B,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAoB,CAAC;QACpD,IAAI,GAAG,EAAE,CAAC;YACR,GAAG,CAAC,MAAM,GAAG,UAAU,CAAC;YACxB,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;YAClB,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC5B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,CAAC,EAAE;QACX,2BAA2B;QAC3B,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAoB,CAAC;QACpD,IAAI,GAAG,EAAE,CAAC;YACR,GAAG,CAAC,MAAM,GAAG,UAAU,CAAC;YACxB,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC;QAClB,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC,CAAC,CAAC;IAEL,MAAM,GAAG,EAAE,MAAM,EAAE,SAAS,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C,OAAO,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,sIAAsI;AACtI,MAAM,UAAU,qBAAqB;IACnC,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;QAClD,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,6HAA6H;AAC7H,MAAM,UAAU,gBAAgB;IAC9B,WAAW,CAAC,KAAK,EAAE,CAAC;AACtB,CAAC;AAED,2BAA2B;AAC3B,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;IACzB,6BAA6B;IAC5B,UAAsC,CAAC,sBAAsB,GAAG,WAAW,CAAC;AAC/E,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.core.module-cache\",\n \"title\": \"Shared Module Cache for Dynamic Imports\",\n \"category\": \"runtime\"\n}\n*/\n\n/**\n * Shared Module Cache\n *\n * Provides a centralized cache for all dynamic imports across the framework.\n * Used by router, prefetch, and lazy components to prevent duplicate loads.\n *\n * @module runtime/module-cache\n */\n\n/** Status of a cached module */\ntype ModuleStatus = 'pending' | 'resolved' | 'rejected';\n\n/** @codexApi {\"parent\":\"pithy.core.module-cache\",\"name\":\"ModuleRecord\",\"stability\":\"stable\",\"signature\":\"interface ModuleRecord<T>\"} */\nexport interface ModuleRecord<T = unknown> {\n status: ModuleStatus;\n promise: Promise<T>;\n value?: T;\n error?: unknown;\n /** Timestamp when the module was loaded (for cache invalidation) */\n loadedAt?: number;\n}\n\n/** Global module cache - shared across all features */\nconst moduleCache = new Map<string, ModuleRecord>();\n\n/**\n * Load a module by dynamic import with caching.\n * Same module (by key) is only loaded once.\n *\n * @param key - Unique identifier for the module (e.g., 'route:/dashboard', 'component:HeavyChart')\n * @param loader - Function that returns the dynamic import promise\n * @returns Promise resolving to the loaded module\n *\n * @example\n * ```ts\n * // Router uses it for route chunks\n * loadModule('route:/dashboard', () => import('./routes/dashboard.pithy'));\n *\n * // lazy() uses it for component chunks\n * loadModule('component:HeavyChart', () => import('./HeavyChart.pithy'));\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.core.module-cache\",\"name\":\"loadModule\",\"stability\":\"stable\",\"signature\":\"<T>(key: string, loader: () => Promise<T>) => Promise<T>\"} */\nexport function loadModule<T>(\n key: string,\n loader: () => Promise<T>\n): Promise<T> {\n let record = moduleCache.get(key) as ModuleRecord<T> | undefined;\n\n if (record) {\n // Return cached promise (handles pending, resolved, or rejected)\n return record.promise;\n }\n\n // Create new record with pending status\n const promise = loader()\n .then(value => {\n // Update record on success\n const rec = moduleCache.get(key) as ModuleRecord<T>;\n if (rec) {\n rec.status = 'resolved';\n rec.value = value;\n rec.loadedAt = Date.now();\n }\n return value;\n })\n .catch(err => {\n // Update record on failure\n const rec = moduleCache.get(key) as ModuleRecord<T>;\n if (rec) {\n rec.status = 'rejected';\n rec.error = err;\n }\n throw err;\n });\n\n record = { status: 'pending', promise };\n moduleCache.set(key, record);\n\n return promise;\n}\n\n/**\n * Get current status of a cached module.\n *\n * @param key - Module identifier\n * @returns Module record or undefined if not cached\n */\n/** @codexApi {\"parent\":\"pithy.core.module-cache\",\"name\":\"getModuleRecord\",\"stability\":\"stable\",\"signature\":\"<T>(key: string) => ModuleRecord<T> | undefined\"} */\nexport function getModuleRecord<T = unknown>(\n key: string\n): ModuleRecord<T> | undefined {\n return moduleCache.get(key) as ModuleRecord<T> | undefined;\n}\n\n/**\n * Invalidate a specific module from the cache.\n * Used for HMR to force reload of updated modules.\n *\n * @param key - Module identifier to invalidate\n * @returns True if module was found and removed\n */\n/** @codexApi {\"parent\":\"pithy.core.module-cache\",\"name\":\"invalidateModule\",\"stability\":\"stable\",\"signature\":\"(key: string) => boolean\"} */\nexport function invalidateModule(key: string): boolean {\n return moduleCache.delete(key);\n}\n\n/**\n * Get all resolved module keys.\n * Used for SSR to track which chunks were used during render.\n *\n * @returns Array of module keys that have been successfully loaded\n */\n/** @codexApi {\"parent\":\"pithy.core.module-cache\",\"name\":\"getResolvedModuleKeys\",\"stability\":\"stable\",\"signature\":\"() => string[]\"} */\nexport function getResolvedModuleKeys(): string[] {\n const keys: string[] = [];\n for (const [key, record] of moduleCache.entries()) {\n if (record.status === 'resolved') {\n keys.push(key);\n }\n }\n return keys;\n}\n\n/**\n * Clear entire module cache.\n * Use with caution - typically only for testing or full app reload.\n */\n/** @codexApi {\"parent\":\"pithy.core.module-cache\",\"name\":\"clearModuleCache\",\"stability\":\"stable\",\"signature\":\"() => void\"} */\nexport function clearModuleCache(): void {\n moduleCache.clear();\n}\n\n// Development-only logging\nif (import.meta.env?.DEV) {\n // Expose cache for debugging\n (globalThis as Record<string, unknown>).__PITHY_MODULE_CACHE__ = moduleCache;\n}\n"]}
@@ -26,4 +26,11 @@ export declare function onDestroy(fn: () => void): void;
26
26
  * @internal Called by html(), __applyBindings(), and compileNodes() before processing
27
27
  */
28
28
  export declare function drainDestroyCallbacks(): (() => void)[];
29
+ /**
30
+ * Runs `fn` against an empty pending queue, then puts the callbacks that were
31
+ * pending before it back, so nothing `fn` renders can drain them.
32
+ *
33
+ * @internal
34
+ */
35
+ export declare function isolateDestroyCallbacks<T>(fn: () => T): T;
29
36
  //# sourceMappingURL=onDestroy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"onDestroy.d.ts","sourceRoot":"","sources":["../../src/runtime/onDestroy.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAmCF;;;;;;;;;;;GAWG;AACH,oIAAoI;AACpI,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAItD"}
1
+ {"version":3,"file":"onDestroy.d.ts","sourceRoot":"","sources":["../../src/runtime/onDestroy.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAmCF;;;;;;;;;;;GAWG;AACH,oIAAoI;AACpI,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAItD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAOzD"}
@@ -5,7 +5,7 @@
5
5
  "category": "runtime"
6
6
  }
7
7
  */
8
- import { pithyGlobals } from '../types/globals';
8
+ import { pithyGlobals } from '../types/globals.js';
9
9
  /**
10
10
  * Module-scoped fallback for browser (single-threaded, no isolation needed).
11
11
  * In SSR, @pithyjs/ssr installs AsyncLocalStorage-backed getters via
@@ -63,4 +63,19 @@ export function drainDestroyCallbacks() {
63
63
  setPending([]);
64
64
  return drained;
65
65
  }
66
+ /**
67
+ * Runs `fn` against an empty pending queue, then puts the callbacks that were
68
+ * pending before it back, so nothing `fn` renders can drain them.
69
+ *
70
+ * @internal
71
+ */
72
+ export function isolateDestroyCallbacks(fn) {
73
+ const outer = drainDestroyCallbacks();
74
+ try {
75
+ return fn();
76
+ }
77
+ finally {
78
+ setPending(outer.concat(getPending()));
79
+ }
80
+ }
66
81
  //# sourceMappingURL=onDestroy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"onDestroy.js","sourceRoot":"","sources":["../../src/runtime/onDestroy.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;;;;GAKG;AACH,IAAI,iBAAiB,GAAmB,EAAE,CAAC;AAE3C,uFAAuF;AACvF,SAAS,UAAU;IAC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AAU,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;QACxB,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;IAC5B,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,kDAAkD;AAClD,SAAS,UAAU,CAAC,GAAmB;IACrC,MAAM,CAAC,GAAG,YAAY,EAAE,CAAC;IACzB,MAAM,MAAM,GAAG,CAAC,CAAC,0BAA0B,CAAC;IAC5C,oFAAoF;IACpF,qFAAqF;IACrF,IAAI,OAAO,MAAM,KAAK,UAAU,IAAI,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;QACrD,CAAC,CAAC,0BAA2B,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;SAAM,CAAC;QACN,iBAAiB,GAAG,GAAG,CAAC;IAC1B,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,oIAAoI;AACpI,MAAM,UAAU,SAAS,CAAC,EAAc;IACtC,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB;IACnC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,UAAU,CAAC,EAAE,CAAC,CAAC;IACf,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAI,EAAW;IACpD,MAAM,KAAK,GAAG,qBAAqB,EAAE,CAAC;IACtC,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;YAAS,CAAC;QACT,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC;AACH,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.onDestroy\",\n \"title\": \"Component Destroy Lifecycle Hook\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { pithyGlobals } from '../types/globals';\n\n/**\n * Module-scoped fallback for browser (single-threaded, no isolation needed).\n * In SSR, @pithyjs/ssr installs AsyncLocalStorage-backed getters via\n * globalThis.__pithyGetDestroyCallbacks / __pithySetDestroyCallbacks\n * to isolate pending callbacks per request.\n */\nlet _defaultCallbacks: (() => void)[] = [];\n\n/** Get the current pending callbacks (per-request in SSR, module-scoped in browser) */\nfunction getPending(): (() => void)[] {\n const getter = pithyGlobals().__pithyGetDestroyCallbacks;\n if (typeof getter === 'function') {\n const result = getter();\n if (result) return result;\n }\n return _defaultCallbacks;\n}\n\n/** Replace the current pending callbacks array */\nfunction setPending(cbs: (() => void)[]): void {\n const g = pithyGlobals();\n const getter = g.__pithyGetDestroyCallbacks;\n // Only use SSR setter when inside an active render scope (getter returns non-null).\n // Outside a render scope the setter is a no-op, so fall back to module-scoped array.\n if (typeof getter === 'function' && getter() != null) {\n g.__pithySetDestroyCallbacks!(cbs);\n } else {\n _defaultCallbacks = cbs;\n }\n}\n\n/**\n * Registers a cleanup callback at component scope. When the component's\n * destroy() is called, all registered callbacks run in LIFO order\n * (last-registered first), after template disposers have executed.\n *\n * Must be called synchronously during component function execution,\n * before the template entry point. Pending callbacks are drained by\n * `html()`, `__applyBindings()` (AOT), or `compileNodes()` — whichever\n * runs next — and incorporated into the returned `destroy()` function.\n *\n * @param fn - Cleanup function to run on component destroy\n */\n/** @codexApi {\"parent\":\"pithy.runtime.onDestroy\",\"name\":\"onDestroy\",\"stability\":\"stable\",\"signature\":\"(fn: () => void) => void\"} */\nexport function onDestroy(fn: () => void): void {\n getPending().push(fn);\n}\n\n/**\n * Drains all pending destroy callbacks and returns them.\n * Replaces the internal array so the next component starts fresh.\n *\n * @internal Called by html(), __applyBindings(), and compileNodes() before processing\n */\nexport function drainDestroyCallbacks(): (() => void)[] {\n const drained = getPending();\n setPending([]);\n return drained;\n}\n\n/**\n * Runs `fn` against an empty pending queue, then puts the callbacks that were\n * pending before it back, so nothing `fn` renders can drain them.\n *\n * @internal\n */\nexport function isolateDestroyCallbacks<T>(fn: () => T): T {\n const outer = drainDestroyCallbacks();\n try {\n return fn();\n } finally {\n setPending(outer.concat(getPending()));\n }\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "category": "compiler"
6
6
  }
7
7
  */
8
- import { isJITLoaded, getParseFragmentFn } from '../compile/parseHtml';
8
+ import { isJITLoaded, getParseFragmentFn } from '../compile/parseHtml.js';
9
9
  import { escapeComponentTags } from '@pithyjs/compiler';
10
10
  /**
11
11
  * Extract variable identifiers from an HTML template string.
@@ -1 +1 @@
1
- {"version":3,"file":"parseIdentifiersFromTemplate.js","sourceRoot":"","sources":["../../src/runtime/parseIdentifiersFromTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;;;GAMG;AACH,2KAA2K;AAC3K,MAAM,UAAU,4BAA4B,CAAC,QAAgB;IAC3D,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IAEtC,yEAAyE;IACzE,4EAA4E;IAC5E,0DAA0D;IAC1D,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,mEAAmE;IACnE,wEAAwE;IACxE,MAAM,OAAO,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAE9C,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,EAAE;QAChC,sBAAsB,EAAE,KAAK;KAC9B,CAAC,CAAC;IASH,MAAM,IAAI,GAAG,CAAC,IAAgB,EAAE,EAAE;QAChC,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC5C,MAAM,IAAI,GAAG,IAAI,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QAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;oBAC7C,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;oBACxD,IAAI,IAAI;wBAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5D,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;gBAExB,0CAA0C;gBAC1C,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;oBACvD,IAAI,IAAI;wBAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5D,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpC,IAAI,CAAC,KAAK,CAAC,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,KAAK,MAAM,KAAK,IAAK,QAAuB,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QAC9D,IAAI,CAAC,KAAK,CAAC,CAAC;IACd,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.compiler.identifier-parser\",\n \"title\": \"Template Identifier Parser\",\n \"category\": \"compiler\"\n}\n*/\n\nimport { isJITLoaded, getParseFragmentFn } from '../compile/parseHtml';\nimport { escapeComponentTags } from '@pithyjs/compiler';\n\n/**\n * Extract variable identifiers from an HTML template string.\n * DEV-only helper used by `html()` fallback when the Babel plugin hasn't\n * injected identifiers. Returns an empty set if parse5 is not loaded\n * (intentional — throwing would crash AOT apps in dev mode).\n * @internal\n */\n/** @codexApi {\"parent\":\"pithy.compiler.identifier-parser\",\"name\":\"parseIdentifiersFromTemplate\",\"stability\":\"internal\",\"signature\":\"(template: string) => Set<string>\"} */\nexport function parseIdentifiersFromTemplate(template: string): Set<string> {\n const identifiers = new Set<string>();\n\n // DEV-only fallback: if parse5 isn't loaded (AOT mode), return empty set\n // gracefully. The Babel plugin handles identifier extraction at build time.\n // Throwing here would crash AOT apps running in dev mode.\n const parseFn = isJITLoaded() ? getParseFragmentFn() : null;\n if (!parseFn) {\n return identifiers;\n }\n\n // Escape PascalCase component tags so parse5 doesn't enter special\n // insertion modes (e.g., \"in select\") that drop children from the tree.\n const escaped = escapeComponentTags(template);\n\n const fragment = parseFn(escaped, {\n sourceCodeLocationInfo: false,\n });\n\n interface ParsedNode {\n nodeName?: string;\n value?: string;\n attrs?: { value: string }[];\n childNodes?: ParsedNode[];\n }\n\n const walk = (node: ParsedNode) => {\n if (node.nodeName === '#text' && node.value) {\n const text = node.value;\n const matches = text.match(/{{\\s*(.*?)\\s*}}/g);\n if (matches) {\n matches.forEach((m: string) => {\n const inner = m.replace(/{{|}}/g, '').trim();\n const vars = inner.match(/\\b[a-zA-Z_][a-zA-Z0-9_]*\\b/g);\n if (vars) vars.forEach((v: string) => identifiers.add(v));\n });\n }\n }\n\n if (node.attrs) {\n for (const attr of node.attrs) {\n const expr = attr.value;\n\n // Skip literal strings like 'Hello world'\n if (!/^['\"].*['\"]$/.test(expr)) {\n const vars = expr.match(/\\b[a-zA-Z_][a-zA-Z0-9_]*\\b/g);\n if (vars) vars.forEach((v: string) => identifiers.add(v));\n }\n }\n }\n\n if (node.childNodes) {\n for (const child of node.childNodes) {\n walk(child);\n }\n }\n };\n\n for (const child of (fragment as ParsedNode).childNodes ?? []) {\n walk(child);\n }\n\n return identifiers;\n}\n"]}
@@ -0,0 +1,44 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.core.resource.action",
4
+ "title": "Async Action Primitive",
5
+ "category": "runtime",
6
+ "risk": "high"
7
+ }
8
+ */
9
+ import type { ActionHandle, ActionOptions, ActionPerformer } from './types.js';
10
+ /**
11
+ * Create a reactive async action.
12
+ *
13
+ * Unlike {@link createResource} an action never runs on its own — only an
14
+ * explicit `run()` triggers it — and by default a concurrent `run()` is dropped
15
+ * rather than restarted, so a double-clicked submit button fires once.
16
+ *
17
+ * There is no static-generation special case: an action only runs from an
18
+ * explicit call, and prerendering never calls one, so there is no auto-run to
19
+ * suppress.
20
+ *
21
+ * @typeParam T - Type of the resolved data.
22
+ * @typeParam A - Tuple of arguments forwarded from `run()` to the performer.
23
+ * @typeParam E - Type of the carried error (`unknown` by default).
24
+ * @param performer - Function performing the side effect.
25
+ * @param options - Behaviour options, see {@link ActionOptions}.
26
+ * @returns An {@link ActionHandle} whose `destroy()` MUST be called from the
27
+ * owning component's cleanup.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const save = createAction((draft: Draft) =>
32
+ * fetch('/api/posts', { method: 'POST', body: JSON.stringify(draft) })
33
+ * );
34
+ *
35
+ * const result = await save.run(draft);
36
+ * if (result.ok) toast('Saved');
37
+ * else if (!result.dropped) toast(String(result.error));
38
+ *
39
+ * onDestroy(() => save.destroy());
40
+ * ```
41
+ */
42
+ /** @codexApi {"parent":"pithy.core.resource.action","name":"createAction","stability":"stable","signature":"<T, A extends unknown[] = [], E = unknown>(performer: ActionPerformer<T, A>, options?: ActionOptions) => ActionHandle<T, A, E>"} */
43
+ export declare function createAction<T, A extends unknown[] = [], E = unknown>(performer: ActionPerformer<T, A>, options?: ActionOptions): ActionHandle<T, A, E>;
44
+ //# sourceMappingURL=createAction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAction.d.ts","sourceRoot":"","sources":["../../../src/runtime/resource/createAction.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAeF,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EAEhB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,gPAAgP;AAChP,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,OAAO,EACnE,SAAS,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAChC,OAAO,GAAE,aAAkB,GAC1B,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAoDvB"}
@@ -0,0 +1,102 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.core.resource.action",
4
+ "title": "Async Action Primitive",
5
+ "category": "runtime",
6
+ "risk": "high"
7
+ }
8
+ */
9
+ /**
10
+ * `createAction` — reactive async write (a mutation, triggered explicitly).
11
+ *
12
+ * Named `createAction` rather than `createMutation` on purpose: "mutation" is
13
+ * already taken by the site-builder vocabulary (`mutation-vocabulary.ts`,
14
+ * mutation envelopes, the mutation executor) and reusing it here would make
15
+ * two unrelated concepts share a word.
16
+ *
17
+ * @module runtime/resource/createAction
18
+ */
19
+ import { onCleanup } from '@pithyjs/signals';
20
+ import { createAsyncEngine, DROPPED } from './engine.js';
21
+ /**
22
+ * Create a reactive async action.
23
+ *
24
+ * Unlike {@link createResource} an action never runs on its own — only an
25
+ * explicit `run()` triggers it — and by default a concurrent `run()` is dropped
26
+ * rather than restarted, so a double-clicked submit button fires once.
27
+ *
28
+ * There is no static-generation special case: an action only runs from an
29
+ * explicit call, and prerendering never calls one, so there is no auto-run to
30
+ * suppress.
31
+ *
32
+ * @typeParam T - Type of the resolved data.
33
+ * @typeParam A - Tuple of arguments forwarded from `run()` to the performer.
34
+ * @typeParam E - Type of the carried error (`unknown` by default).
35
+ * @param performer - Function performing the side effect.
36
+ * @param options - Behaviour options, see {@link ActionOptions}.
37
+ * @returns An {@link ActionHandle} whose `destroy()` MUST be called from the
38
+ * owning component's cleanup.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const save = createAction((draft: Draft) =>
43
+ * fetch('/api/posts', { method: 'POST', body: JSON.stringify(draft) })
44
+ * );
45
+ *
46
+ * const result = await save.run(draft);
47
+ * if (result.ok) toast('Saved');
48
+ * else if (!result.dropped) toast(String(result.error));
49
+ *
50
+ * onDestroy(() => save.destroy());
51
+ * ```
52
+ */
53
+ /** @codexApi {"parent":"pithy.core.resource.action","name":"createAction","stability":"stable","signature":"<T, A extends unknown[] = [], E = unknown>(performer: ActionPerformer<T, A>, options?: ActionOptions) => ActionHandle<T, A, E>"} */
54
+ export function createAction(performer, options = {}) {
55
+ const { overlap = 'drop', keepPreviousData = true } = options;
56
+ const engine = createAsyncEngine({ keepPreviousData });
57
+ /**
58
+ * Perform the action.
59
+ *
60
+ * DIVERGENCE, ON PURPOSE: this RESOLVES a discriminated {@link ActionResult}
61
+ * instead of rejecting. The house convention for async elsewhere in this repo
62
+ * is to reject — the router's `executeLoader()` does. A failed mutation,
63
+ * though, is an ordinary UI state (show the message, keep the form filled),
64
+ * not an exception; making it reject forces a try/catch around every submit
65
+ * handler and loses the type of the error. Rejections stay reserved for bugs.
66
+ *
67
+ * The performer receives only the caller's arguments — no `AbortSignal`. A
68
+ * variadic argument tuple leaves no unambiguous slot for one, and adding it
69
+ * would wreck inference of `A` for the common signal-less case. Correctness
70
+ * does not depend on it: the engine's generation counter already guarantees a
71
+ * superseded or destroyed run can never write state.
72
+ */
73
+ function run(...args) {
74
+ // Guards on whether a PERFORMER is still running, not on whether we still
75
+ // want its result. `reset()` clears the latter — that is its job — but the
76
+ // POST it abandoned is still in flight, and an action's performer never
77
+ // receives the AbortSignal, so nothing stops it. Guarding on `isInFlight()`
78
+ // meant Save -> dismiss error (reset) -> Save sent two concurrent requests
79
+ // and could create a duplicate record: precisely what 'drop' prevents.
80
+ if (overlap === 'drop' && engine.hasRunningTask()) {
81
+ return Promise.resolve(DROPPED);
82
+ }
83
+ return engine.execute(() => performer(...args));
84
+ }
85
+ const handle = {
86
+ data: engine.data,
87
+ error: engine.error,
88
+ status: engine.status,
89
+ // Plain accessor rather than computed() — see createResource.ts.
90
+ pending: () => engine.status() === 'loading',
91
+ run,
92
+ reset: engine.reset,
93
+ destroy: engine.destroy,
94
+ };
95
+ // Best effort only — onCleanup() outside an effect is a silent no-op. Under
96
+ // an owner it fires on a re-run as well as on the disposer, so an action
97
+ // built inside an effect is destroyed when that effect re-runs. See
98
+ // createResource.ts and the README for detail.
99
+ onCleanup(() => engine.destroy());
100
+ return handle;
101
+ }
102
+ //# sourceMappingURL=createAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAction.js","sourceRoot":"","sources":["../../../src/runtime/resource/createAction.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAEF;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAQtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,gPAAgP;AAChP,MAAM,UAAU,YAAY,CAC1B,SAAgC,EAChC,UAAyB,EAAE;IAE3B,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,gBAAgB,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAE9D,MAAM,MAAM,GAAG,iBAAiB,CAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAE7D;;;;;;;;;;;;;;;OAeG;IACH,SAAS,GAAG,CAAC,GAAG,IAAO;QACrB,0EAA0E;QAC1E,2EAA2E;QAC3E,wEAAwE;QACxE,4EAA4E;QAC5E,2EAA2E;QAC3E,uEAAuE;QACvE,IAAI,OAAO,KAAK,MAAM,IAAI,MAAM,CAAC,cAAc,EAAE,EAAE,CAAC;YAClD,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QACD,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,MAAM,GAA0B;QACpC,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,iEAAiE;QACjE,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,SAAS;QAC5C,GAAG;QACH,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;IAEF,4EAA4E;IAC5E,yEAAyE;IACzE,oEAAoE;IACpE,+CAA+C;IAC/C,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.core.resource.action\",\n \"title\": \"Async Action Primitive\",\n \"category\": \"runtime\",\n \"risk\": \"high\"\n}\n*/\n\n/**\n * `createAction` — reactive async write (a mutation, triggered explicitly).\n *\n * Named `createAction` rather than `createMutation` on purpose: \"mutation\" is\n * already taken by the site-builder vocabulary (`mutation-vocabulary.ts`,\n * mutation envelopes, the mutation executor) and reusing it here would make\n * two unrelated concepts share a word.\n *\n * @module runtime/resource/createAction\n */\n\nimport { onCleanup } from '@pithyjs/signals';\nimport { createAsyncEngine, DROPPED } from './engine';\nimport type {\n ActionHandle,\n ActionOptions,\n ActionPerformer,\n ActionResult,\n} from './types';\n\n/**\n * Create a reactive async action.\n *\n * Unlike {@link createResource} an action never runs on its own — only an\n * explicit `run()` triggers it — and by default a concurrent `run()` is dropped\n * rather than restarted, so a double-clicked submit button fires once.\n *\n * There is no static-generation special case: an action only runs from an\n * explicit call, and prerendering never calls one, so there is no auto-run to\n * suppress.\n *\n * @typeParam T - Type of the resolved data.\n * @typeParam A - Tuple of arguments forwarded from `run()` to the performer.\n * @typeParam E - Type of the carried error (`unknown` by default).\n * @param performer - Function performing the side effect.\n * @param options - Behaviour options, see {@link ActionOptions}.\n * @returns An {@link ActionHandle} whose `destroy()` MUST be called from the\n * owning component's cleanup.\n *\n * @example\n * ```ts\n * const save = createAction((draft: Draft) =>\n * fetch('/api/posts', { method: 'POST', body: JSON.stringify(draft) })\n * );\n *\n * const result = await save.run(draft);\n * if (result.ok) toast('Saved');\n * else if (!result.dropped) toast(String(result.error));\n *\n * onDestroy(() => save.destroy());\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.core.resource.action\",\"name\":\"createAction\",\"stability\":\"stable\",\"signature\":\"<T, A extends unknown[] = [], E = unknown>(performer: ActionPerformer<T, A>, options?: ActionOptions) => ActionHandle<T, A, E>\"} */\nexport function createAction<T, A extends unknown[] = [], E = unknown>(\n performer: ActionPerformer<T, A>,\n options: ActionOptions = {}\n): ActionHandle<T, A, E> {\n const { overlap = 'drop', keepPreviousData = true } = options;\n\n const engine = createAsyncEngine<T, E>({ keepPreviousData });\n\n /**\n * Perform the action.\n *\n * DIVERGENCE, ON PURPOSE: this RESOLVES a discriminated {@link ActionResult}\n * instead of rejecting. The house convention for async elsewhere in this repo\n * is to reject — the router's `executeLoader()` does. A failed mutation,\n * though, is an ordinary UI state (show the message, keep the form filled),\n * not an exception; making it reject forces a try/catch around every submit\n * handler and loses the type of the error. Rejections stay reserved for bugs.\n *\n * The performer receives only the caller's arguments — no `AbortSignal`. A\n * variadic argument tuple leaves no unambiguous slot for one, and adding it\n * would wreck inference of `A` for the common signal-less case. Correctness\n * does not depend on it: the engine's generation counter already guarantees a\n * superseded or destroyed run can never write state.\n */\n function run(...args: A): Promise<ActionResult<T, E>> {\n // Guards on whether a PERFORMER is still running, not on whether we still\n // want its result. `reset()` clears the latter — that is its job — but the\n // POST it abandoned is still in flight, and an action's performer never\n // receives the AbortSignal, so nothing stops it. Guarding on `isInFlight()`\n // meant Save -> dismiss error (reset) -> Save sent two concurrent requests\n // and could create a duplicate record: precisely what 'drop' prevents.\n if (overlap === 'drop' && engine.hasRunningTask()) {\n return Promise.resolve(DROPPED);\n }\n return engine.execute(() => performer(...args));\n }\n\n const handle: ActionHandle<T, A, E> = {\n data: engine.data,\n error: engine.error,\n status: engine.status,\n // Plain accessor rather than computed() — see createResource.ts.\n pending: () => engine.status() === 'loading',\n run,\n reset: engine.reset,\n destroy: engine.destroy,\n };\n\n // Best effort only — onCleanup() outside an effect is a silent no-op. Under\n // an owner it fires on a re-run as well as on the disposer, so an action\n // built inside an effect is destroyed when that effect re-runs. See\n // createResource.ts and the README for detail.\n onCleanup(() => engine.destroy());\n\n return handle;\n}\n"]}
@@ -0,0 +1,56 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.core.resource",
4
+ "title": "Async State Primitive",
5
+ "category": "runtime",
6
+ "risk": "high"
7
+ }
8
+ */
9
+ import type { ResourceFetcher, ResourceHandle, ResourceOptions } from './types.js';
10
+ /**
11
+ * Create a reactive async resource.
12
+ *
13
+ * The fetcher runs immediately by default and again on every `refetch()`. The
14
+ * newest run always wins: a superseded response can never write state, even if
15
+ * its fetcher ignored the abort signal (see `engine.ts`).
16
+ *
17
+ * ## Server rendering
18
+ *
19
+ * Under ANY server render the fetcher is NOT called and the resource resolves to
20
+ * `'idle'` — deliberately not `'loading'`, so a prerendered page ships its
21
+ * empty/idle markup rather than a spinner frozen into the HTML. `refetch()` is
22
+ * inert there too.
23
+ *
24
+ * SCOPE: this covers static generation *and* per-request dynamic SSR. The gate
25
+ * is `isSSRMode()`, and `@pithyjs/ssr` sets `__PITHY_SSR__` in `setupEnvironment()`,
26
+ * which every `renderToString()` call runs — not only the SSG build. Suppression
27
+ * is correct for both: the renderer awaits *route loaders*, which it discovers
28
+ * declaratively from the route tree, and has no way to discover a resource
29
+ * constructed inside a component body mid-render. Server-side data belongs in a
30
+ * loader; a resource that fired here could never contribute to the HTML anyway.
31
+ *
32
+ * The flag is read at call time on purpose: it toggles per render while modules
33
+ * stay cached across renders in one process, so capturing it in a module const
34
+ * would poison every later render.
35
+ *
36
+ * @typeParam T - Type of the resolved data.
37
+ * @typeParam E - Type of the carried error (`unknown` by default — thrown values
38
+ * are carried by reference and never wrapped).
39
+ * @param fetcher - Function producing the data. Receives an `AbortSignal` that is
40
+ * aborted on refetch, reset and destroy.
41
+ * @param options - Behaviour options, see {@link ResourceOptions}.
42
+ * @returns A {@link ResourceHandle} whose `destroy()` MUST be called from the
43
+ * owning component's cleanup.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const user = createResource(signal => fetch('/api/me', { signal }).then(r => r.json()));
48
+ *
49
+ * // in a template: {{ user.loading() ? 'Loading…' : user.data()?.name }}
50
+ *
51
+ * onDestroy(() => user.destroy());
52
+ * ```
53
+ */
54
+ /** @codexApi {"parent":"pithy.core.resource","name":"createResource","stability":"stable","signature":"<T, E = unknown>(fetcher: ResourceFetcher<T>, options?: ResourceOptions) => ResourceHandle<T, E>"} */
55
+ export declare function createResource<T, E = unknown>(fetcher: ResourceFetcher<T>, options?: ResourceOptions): ResourceHandle<T, E>;
56
+ //# sourceMappingURL=createResource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createResource.d.ts","sourceRoot":"","sources":["../../../src/runtime/resource/createResource.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAeF,OAAO,KAAK,EAEV,eAAe,EACf,cAAc,EACd,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,6MAA6M;AAC7M,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EAC3C,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,EAC3B,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAwCtB"}
@@ -0,0 +1,102 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.core.resource",
4
+ "title": "Async State Primitive",
5
+ "category": "runtime",
6
+ "risk": "high"
7
+ }
8
+ */
9
+ /**
10
+ * `createResource` — reactive async read (a query).
11
+ *
12
+ * Wraps an async fetch in three signals (`data`, `error`, `status`) so a
13
+ * template can bind to loading and error states directly instead of the app
14
+ * hand-rolling `isLoading` booleans around every `await`.
15
+ *
16
+ * @module runtime/resource/createResource
17
+ */
18
+ import { onCleanup } from '@pithyjs/signals';
19
+ import { isSSRMode } from '../../compile/ssrMode.js';
20
+ import { createAsyncEngine, DROPPED } from './engine.js';
21
+ /**
22
+ * Create a reactive async resource.
23
+ *
24
+ * The fetcher runs immediately by default and again on every `refetch()`. The
25
+ * newest run always wins: a superseded response can never write state, even if
26
+ * its fetcher ignored the abort signal (see `engine.ts`).
27
+ *
28
+ * ## Server rendering
29
+ *
30
+ * Under ANY server render the fetcher is NOT called and the resource resolves to
31
+ * `'idle'` — deliberately not `'loading'`, so a prerendered page ships its
32
+ * empty/idle markup rather than a spinner frozen into the HTML. `refetch()` is
33
+ * inert there too.
34
+ *
35
+ * SCOPE: this covers static generation *and* per-request dynamic SSR. The gate
36
+ * is `isSSRMode()`, and `@pithyjs/ssr` sets `__PITHY_SSR__` in `setupEnvironment()`,
37
+ * which every `renderToString()` call runs — not only the SSG build. Suppression
38
+ * is correct for both: the renderer awaits *route loaders*, which it discovers
39
+ * declaratively from the route tree, and has no way to discover a resource
40
+ * constructed inside a component body mid-render. Server-side data belongs in a
41
+ * loader; a resource that fired here could never contribute to the HTML anyway.
42
+ *
43
+ * The flag is read at call time on purpose: it toggles per render while modules
44
+ * stay cached across renders in one process, so capturing it in a module const
45
+ * would poison every later render.
46
+ *
47
+ * @typeParam T - Type of the resolved data.
48
+ * @typeParam E - Type of the carried error (`unknown` by default — thrown values
49
+ * are carried by reference and never wrapped).
50
+ * @param fetcher - Function producing the data. Receives an `AbortSignal` that is
51
+ * aborted on refetch, reset and destroy.
52
+ * @param options - Behaviour options, see {@link ResourceOptions}.
53
+ * @returns A {@link ResourceHandle} whose `destroy()` MUST be called from the
54
+ * owning component's cleanup.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const user = createResource(signal => fetch('/api/me', { signal }).then(r => r.json()));
59
+ *
60
+ * // in a template: {{ user.loading() ? 'Loading…' : user.data()?.name }}
61
+ *
62
+ * onDestroy(() => user.destroy());
63
+ * ```
64
+ */
65
+ /** @codexApi {"parent":"pithy.core.resource","name":"createResource","stability":"stable","signature":"<T, E = unknown>(fetcher: ResourceFetcher<T>, options?: ResourceOptions) => ResourceHandle<T, E>"} */
66
+ export function createResource(fetcher, options = {}) {
67
+ const { immediate = true, keepPreviousData = false } = options;
68
+ const engine = createAsyncEngine({ keepPreviousData });
69
+ function refetch() {
70
+ // Read isSSRMode() at CALL time — never hoist it into a module const.
71
+ if (isSSRMode())
72
+ return Promise.resolve(DROPPED);
73
+ return engine.execute(signal => fetcher(signal));
74
+ }
75
+ const handle = {
76
+ data: engine.data,
77
+ error: engine.error,
78
+ status: engine.status,
79
+ // Plain accessor rather than computed(): it still tracks reactively because
80
+ // it reads status() inside the caller's effect.
81
+ loading: () => engine.status() === 'loading',
82
+ refetch,
83
+ reset: engine.reset,
84
+ destroy: engine.destroy,
85
+ };
86
+ if (immediate) {
87
+ void refetch();
88
+ }
89
+ // Best effort only: onCleanup() outside an effect is a SILENT no-op, so this
90
+ // helps when the resource happens to be created inside one and does nothing
91
+ // otherwise. The explicit destroy() remains the contract.
92
+ //
93
+ // "Best effort" means only that `onCleanup()` outside an effect is a silent
94
+ // no-op. Under an owner this now fires on a re-run as well as on the
95
+ // disposer, so `effect(() => createResource(() => fetch(`/api/u/${id()}`)))`
96
+ // destroys the previous resource on each `id` change instead of leaking one
97
+ // per run. The resource still must not outlive that run: hold it in a
98
+ // `createRoot` if it should. See the README's Async State section.
99
+ onCleanup(() => engine.destroy());
100
+ return handle;
101
+ }
102
+ //# sourceMappingURL=createResource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createResource.js","sourceRoot":"","sources":["../../../src/runtime/resource/createResource.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAEF;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAQtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,6MAA6M;AAC7M,MAAM,UAAU,cAAc,CAC5B,OAA2B,EAC3B,UAA2B,EAAE;IAE7B,MAAM,EAAE,SAAS,GAAG,IAAI,EAAE,gBAAgB,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAE/D,MAAM,MAAM,GAAG,iBAAiB,CAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAE7D,SAAS,OAAO;QACd,sEAAsE;QACtE,IAAI,SAAS,EAAE;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,MAAM,GAAyB;QACnC,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,4EAA4E;QAC5E,gDAAgD;QAChD,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,SAAS;QAC5C,OAAO;QACP,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;IAEF,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,6EAA6E;IAC7E,4EAA4E;IAC5E,0DAA0D;IAC1D,EAAE;IACF,4EAA4E;IAC5E,qEAAqE;IACrE,6EAA6E;IAC7E,4EAA4E;IAC5E,sEAAsE;IACtE,mEAAmE;IACnE,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.core.resource\",\n \"title\": \"Async State Primitive\",\n \"category\": \"runtime\",\n \"risk\": \"high\"\n}\n*/\n\n/**\n * `createResource` — reactive async read (a query).\n *\n * Wraps an async fetch in three signals (`data`, `error`, `status`) so a\n * template can bind to loading and error states directly instead of the app\n * hand-rolling `isLoading` booleans around every `await`.\n *\n * @module runtime/resource/createResource\n */\n\nimport { onCleanup } from '@pithyjs/signals';\nimport { isSSRMode } from '../../compile/ssrMode';\nimport { createAsyncEngine, DROPPED } from './engine';\nimport type {\n ActionResult,\n ResourceFetcher,\n ResourceHandle,\n ResourceOptions,\n} from './types';\n\n/**\n * Create a reactive async resource.\n *\n * The fetcher runs immediately by default and again on every `refetch()`. The\n * newest run always wins: a superseded response can never write state, even if\n * its fetcher ignored the abort signal (see `engine.ts`).\n *\n * ## Server rendering\n *\n * Under ANY server render the fetcher is NOT called and the resource resolves to\n * `'idle'` — deliberately not `'loading'`, so a prerendered page ships its\n * empty/idle markup rather than a spinner frozen into the HTML. `refetch()` is\n * inert there too.\n *\n * SCOPE: this covers static generation *and* per-request dynamic SSR. The gate\n * is `isSSRMode()`, and `@pithyjs/ssr` sets `__PITHY_SSR__` in `setupEnvironment()`,\n * which every `renderToString()` call runs — not only the SSG build. Suppression\n * is correct for both: the renderer awaits *route loaders*, which it discovers\n * declaratively from the route tree, and has no way to discover a resource\n * constructed inside a component body mid-render. Server-side data belongs in a\n * loader; a resource that fired here could never contribute to the HTML anyway.\n *\n * The flag is read at call time on purpose: it toggles per render while modules\n * stay cached across renders in one process, so capturing it in a module const\n * would poison every later render.\n *\n * @typeParam T - Type of the resolved data.\n * @typeParam E - Type of the carried error (`unknown` by default — thrown values\n * are carried by reference and never wrapped).\n * @param fetcher - Function producing the data. Receives an `AbortSignal` that is\n * aborted on refetch, reset and destroy.\n * @param options - Behaviour options, see {@link ResourceOptions}.\n * @returns A {@link ResourceHandle} whose `destroy()` MUST be called from the\n * owning component's cleanup.\n *\n * @example\n * ```ts\n * const user = createResource(signal => fetch('/api/me', { signal }).then(r => r.json()));\n *\n * // in a template: {{ user.loading() ? 'Loading…' : user.data()?.name }}\n *\n * onDestroy(() => user.destroy());\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.core.resource\",\"name\":\"createResource\",\"stability\":\"stable\",\"signature\":\"<T, E = unknown>(fetcher: ResourceFetcher<T>, options?: ResourceOptions) => ResourceHandle<T, E>\"} */\nexport function createResource<T, E = unknown>(\n fetcher: ResourceFetcher<T>,\n options: ResourceOptions = {}\n): ResourceHandle<T, E> {\n const { immediate = true, keepPreviousData = false } = options;\n\n const engine = createAsyncEngine<T, E>({ keepPreviousData });\n\n function refetch(): Promise<ActionResult<T, E>> {\n // Read isSSRMode() at CALL time — never hoist it into a module const.\n if (isSSRMode()) return Promise.resolve(DROPPED);\n return engine.execute(signal => fetcher(signal));\n }\n\n const handle: ResourceHandle<T, E> = {\n data: engine.data,\n error: engine.error,\n status: engine.status,\n // Plain accessor rather than computed(): it still tracks reactively because\n // it reads status() inside the caller's effect.\n loading: () => engine.status() === 'loading',\n refetch,\n reset: engine.reset,\n destroy: engine.destroy,\n };\n\n if (immediate) {\n void refetch();\n }\n\n // Best effort only: onCleanup() outside an effect is a SILENT no-op, so this\n // helps when the resource happens to be created inside one and does nothing\n // otherwise. The explicit destroy() remains the contract.\n //\n // \"Best effort\" means only that `onCleanup()` outside an effect is a silent\n // no-op. Under an owner this now fires on a re-run as well as on the\n // disposer, so `effect(() => createResource(() => fetch(`/api/u/${id()}`)))`\n // destroys the previous resource on each `id` change instead of leaking one\n // per run. The resource still must not outlive that run: hold it in a\n // `createRoot` if it should. See the README's Async State section.\n onCleanup(() => engine.destroy());\n\n return handle;\n}\n"]}