@krate/runtime 0.5.0-beta.1 → 0.5.0-beta.2

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 (134) hide show
  1. package/dist/actions.js +2 -1
  2. package/dist/assets-static.d.ts +5 -0
  3. package/dist/assets-static.js +31 -0
  4. package/dist/boundary.d.ts +12 -0
  5. package/dist/boundary.js +53 -13
  6. package/dist/cache-adapter.d.ts +113 -0
  7. package/dist/cache-adapter.js +217 -0
  8. package/dist/cache-adapter.test.d.ts +1 -0
  9. package/dist/cache-adapter.test.js +244 -0
  10. package/dist/cache-redis.d.ts +27 -0
  11. package/dist/cache-redis.js +110 -0
  12. package/dist/cache-scope.d.ts +25 -9
  13. package/dist/cache-scope.js +60 -12
  14. package/dist/cache.d.ts +1 -0
  15. package/dist/cache.js +3 -3
  16. package/dist/class-component.js +6 -0
  17. package/dist/class-component.test.js +53 -2
  18. package/dist/dev-overlay.js +10 -10
  19. package/dist/dom.d.ts +8 -0
  20. package/dist/dom.js +28 -0
  21. package/dist/effect-errors.test.d.ts +1 -0
  22. package/dist/effect-errors.test.js +163 -0
  23. package/dist/effects.d.ts +8 -0
  24. package/dist/effects.js +13 -0
  25. package/dist/error-overlay.js +4 -4
  26. package/dist/handler-html.d.ts +63 -0
  27. package/dist/handler-html.js +285 -0
  28. package/dist/handler-html.test.d.ts +1 -0
  29. package/dist/handler-html.test.js +256 -0
  30. package/dist/handler-routing.d.ts +83 -0
  31. package/dist/handler-routing.js +579 -0
  32. package/dist/handler-routing.test.d.ts +1 -0
  33. package/dist/handler-routing.test.js +99 -0
  34. package/dist/handler-segments.d.ts +43 -0
  35. package/dist/handler-segments.js +115 -0
  36. package/dist/handler-segments.test.d.ts +1 -0
  37. package/dist/handler-segments.test.js +217 -0
  38. package/dist/head-tags.d.ts +51 -0
  39. package/dist/head-tags.js +329 -0
  40. package/dist/head-tags.test.d.ts +1 -0
  41. package/dist/head-tags.test.js +131 -0
  42. package/dist/highlight-bind.d.ts +42 -0
  43. package/dist/highlight-bind.js +176 -0
  44. package/dist/highlight-bind.test.d.ts +1 -0
  45. package/dist/highlight-bind.test.js +124 -0
  46. package/dist/highlight.d.ts +93 -0
  47. package/dist/highlight.js +426 -0
  48. package/dist/highlight.test.d.ts +1 -0
  49. package/dist/highlight.test.js +56 -0
  50. package/dist/hints.d.ts +19 -0
  51. package/dist/hints.js +97 -0
  52. package/dist/index.d.ts +3 -0
  53. package/dist/index.js +2 -0
  54. package/dist/jsx-types.d.ts +11 -0
  55. package/dist/krate-core.js +1 -1
  56. package/dist/krate-dev.js +10 -10
  57. package/dist/krate-f-actions.js +1 -1
  58. package/dist/krate-f-classes.js +5 -5
  59. package/dist/krate-f-highlight.js +2 -0
  60. package/dist/krate-f-list.js +1 -1
  61. package/dist/krate-f-navigation.js +2 -0
  62. package/dist/krate-f-router.js +1 -1
  63. package/dist/krate-features.json +254 -0
  64. package/dist/krate-hydrate-lite.js +5 -5
  65. package/dist/krate-hydrate.js +5 -5
  66. package/dist/krate-runtime.js +5 -5
  67. package/dist/list.js +4 -2
  68. package/dist/metadata-routes.d.ts +75 -0
  69. package/dist/metadata-routes.js +76 -0
  70. package/dist/metadata.d.ts +222 -0
  71. package/dist/metadata.js +452 -0
  72. package/dist/metadata.test.d.ts +1 -0
  73. package/dist/metadata.test.js +167 -0
  74. package/dist/navigation-server.d.ts +27 -0
  75. package/dist/navigation-server.js +90 -0
  76. package/dist/navigation.d.ts +37 -0
  77. package/dist/navigation.js +195 -0
  78. package/dist/navigation.test.d.ts +1 -0
  79. package/dist/navigation.test.js +130 -0
  80. package/dist/node-server.d.ts +22 -0
  81. package/dist/node-server.js +436 -0
  82. package/dist/node-server.test.d.ts +1 -0
  83. package/dist/node-server.test.js +492 -0
  84. package/dist/og-files.d.ts +2 -0
  85. package/dist/og-files.js +19 -0
  86. package/dist/og.d.ts +56 -0
  87. package/dist/og.js +156 -0
  88. package/dist/react.d.ts +47 -0
  89. package/dist/react.js +59 -1
  90. package/dist/react19.test.d.ts +1 -0
  91. package/dist/react19.test.js +176 -0
  92. package/dist/request-context.d.ts +23 -0
  93. package/dist/request-context.js +45 -0
  94. package/dist/resp.d.ts +55 -0
  95. package/dist/resp.js +239 -0
  96. package/dist/router-layout.test.js +70 -0
  97. package/dist/router-nav.test.js +27 -0
  98. package/dist/router.js +59 -4
  99. package/dist/segmented-lru.d.ts +19 -0
  100. package/dist/segmented-lru.js +87 -0
  101. package/dist/server-async.test.js +23 -1
  102. package/dist/server-handler.d.ts +165 -0
  103. package/dist/server-handler.js +1826 -0
  104. package/dist/server-handler.test.d.ts +1 -0
  105. package/dist/server-handler.test.js +522 -0
  106. package/dist/server-highlight.test.d.ts +1 -0
  107. package/dist/server-highlight.test.js +32 -0
  108. package/dist/server-renderer.js +146 -788
  109. package/dist/server-renderer.test.d.ts +1 -0
  110. package/dist/server-renderer.test.js +266 -0
  111. package/dist/server.d.ts +12 -1
  112. package/dist/server.js +42 -6
  113. package/dist/sha256.d.ts +1 -0
  114. package/dist/sha256.js +66 -0
  115. package/dist/sha256.test.d.ts +1 -0
  116. package/dist/sha256.test.js +13 -0
  117. package/dist/shared-isr.d.ts +31 -0
  118. package/dist/shared-isr.js +142 -0
  119. package/dist/signal.js +63 -8
  120. package/dist/ssr-core-behavior.test.d.ts +1 -0
  121. package/dist/ssr-core-behavior.test.js +620 -0
  122. package/dist/ssr-core.d.ts +175 -0
  123. package/dist/ssr-core.js +940 -0
  124. package/dist/ssr-core.test.d.ts +1 -0
  125. package/dist/ssr-core.test.js +324 -0
  126. package/dist/static-memory.d.ts +3 -0
  127. package/dist/static-memory.js +47 -0
  128. package/dist/static-memory.test.d.ts +1 -0
  129. package/dist/static-memory.test.js +26 -0
  130. package/dist/test-redis.d.ts +12 -0
  131. package/dist/test-redis.js +131 -0
  132. package/dist/use-id.d.ts +8 -0
  133. package/dist/use-id.js +40 -0
  134. package/package.json +29 -1
package/dist/list.js CHANGED
@@ -25,6 +25,7 @@
25
25
  import { createEffect, createRoot, createSignal, onCleanup, untrack } from './signal.js';
26
26
  import { krateUnmount, krateWithOwner } from './effects.js';
27
27
  import { adoptValue, appendChild, disposeNode, insertAt, removeRest, trackEffect, withDOM, withVNodes, } from './dom.js';
28
+ import { krateWithIdScope } from './use-id.js';
28
29
  /** Canonical key: explicit keys are `$` + String(key); implicit keys are the index. */
29
30
  function keyOf(keyFn, item, i) {
30
31
  if (!keyFn)
@@ -57,7 +58,8 @@ function renderInRoot(state, row, item, i, body) {
57
58
  trackEffect(row.start, dispose);
58
59
  // The row is an effect owner: components it renders are its children, so
59
60
  // removing the row unmounts them (React effect cleanups) in one call.
60
- const { value, owner } = krateWithOwner(() => {
61
+ const listId = (state.start.nodeValue || '').slice(2);
62
+ const { value, owner } = krateWithOwner(() => krateWithIdScope(listId ? listId + ':' + row.key : '', () => {
61
63
  if (!state.accessor)
62
64
  return state.render(item, i);
63
65
  const [getItem, setItem] = createSignal(item);
@@ -65,7 +67,7 @@ function renderInRoot(state, row, item, i, body) {
65
67
  row.setItem = setItem;
66
68
  row.setIndex = setIndex;
67
69
  return state.render(getItem, getIndex);
68
- });
70
+ }));
69
71
  onCleanup(() => krateUnmount(owner));
70
72
  body(value);
71
73
  });
@@ -0,0 +1,75 @@
1
+ export interface SitemapEntry {
2
+ url: string;
3
+ lastModified?: string | Date;
4
+ changeFrequency?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
5
+ priority?: number;
6
+ alternates?: {
7
+ languages?: Record<string, string>;
8
+ };
9
+ images?: string[];
10
+ videos?: Array<{
11
+ title: string;
12
+ thumbnail_loc: string;
13
+ description: string;
14
+ content_loc?: string;
15
+ player_loc?: string;
16
+ }>;
17
+ }
18
+ export interface RobotsRule {
19
+ userAgent?: string | string[];
20
+ allow?: string | string[];
21
+ disallow?: string | string[];
22
+ crawlDelay?: number;
23
+ }
24
+ export interface RobotsFile {
25
+ rules: RobotsRule | RobotsRule[];
26
+ sitemap?: string | string[];
27
+ host?: string;
28
+ }
29
+ export interface ManifestFile {
30
+ name?: string;
31
+ short_name?: string;
32
+ description?: string;
33
+ start_url?: string;
34
+ display?: 'fullscreen' | 'standalone' | 'minimal-ui' | 'browser';
35
+ background_color?: string;
36
+ theme_color?: string;
37
+ orientation?: string;
38
+ scope?: string;
39
+ lang?: string;
40
+ dir?: string;
41
+ id?: string;
42
+ categories?: string[];
43
+ icons?: Array<{
44
+ src: string;
45
+ sizes?: string;
46
+ type?: string;
47
+ purpose?: string;
48
+ }>;
49
+ screenshots?: Array<{
50
+ src: string;
51
+ sizes?: string;
52
+ type?: string;
53
+ form_factor?: string;
54
+ label?: string;
55
+ }>;
56
+ shortcuts?: Array<{
57
+ name: string;
58
+ url: string;
59
+ short_name?: string;
60
+ description?: string;
61
+ icons?: ManifestFile['icons'];
62
+ }>;
63
+ [key: string]: unknown;
64
+ }
65
+ export declare namespace MetadataRoute {
66
+ type Sitemap = SitemapEntry[];
67
+ type Robots = RobotsFile;
68
+ type Manifest = ManifestFile;
69
+ }
70
+ /** The XML of a sitemap, with the xhtml, image and video namespaces only when used. */
71
+ export declare function renderSitemapXML(entries: SitemapEntry[]): string;
72
+ /** The text of a robots.txt. */
73
+ export declare function renderRobotsTXT(robots: RobotsFile): string;
74
+ /** The JSON of a web app manifest. */
75
+ export declare function renderManifestJSON(manifest: ManifestFile): string;
@@ -0,0 +1,76 @@
1
+ // Metadata route files: sitemap.ts, robots.ts and manifest.ts return plain data
2
+ // (the shapes of Next.js's MetadataRoute); Krate renders them to sitemap.xml,
3
+ // robots.txt and manifest.webmanifest at build time.
4
+ function esc(s) {
5
+ return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
6
+ }
7
+ function dateString(d) {
8
+ return d instanceof Date ? d.toISOString() : String(d);
9
+ }
10
+ /** The XML of a sitemap, with the xhtml, image and video namespaces only when used. */
11
+ export function renderSitemapXML(entries) {
12
+ const hasAlt = entries.some((e) => e.alternates && e.alternates.languages);
13
+ const hasImg = entries.some((e) => e.images && e.images.length);
14
+ const hasVideo = entries.some((e) => e.videos && e.videos.length);
15
+ let xml = '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
16
+ if (hasImg)
17
+ xml += ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"';
18
+ if (hasVideo)
19
+ xml += ' xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"';
20
+ if (hasAlt)
21
+ xml += ' xmlns:xhtml="http://www.w3.org/1999/xhtml"';
22
+ xml += '>\n';
23
+ for (const e of entries) {
24
+ if (!e || typeof e.url !== 'string' || e.url === '')
25
+ throw new TypeError('sitemap entries need a url');
26
+ xml += ` <url>\n <loc>${esc(e.url)}</loc>\n`;
27
+ for (const [lang, href] of Object.entries((e.alternates && e.alternates.languages) || {})) {
28
+ xml += ` <xhtml:link rel="alternate" hreflang="${esc(lang)}" href="${esc(href)}" />\n`;
29
+ }
30
+ if (e.lastModified)
31
+ xml += ` <lastmod>${esc(dateString(e.lastModified))}</lastmod>\n`;
32
+ if (e.changeFrequency)
33
+ xml += ` <changefreq>${esc(e.changeFrequency)}</changefreq>\n`;
34
+ if (e.priority !== undefined)
35
+ xml += ` <priority>${esc(e.priority)}</priority>\n`;
36
+ for (const img of e.images || [])
37
+ xml += ` <image:image>\n <image:loc>${esc(img)}</image:loc>\n </image:image>\n`;
38
+ for (const v of e.videos || []) {
39
+ xml += ` <video:video>\n <video:title>${esc(v.title)}</video:title>\n <video:thumbnail_loc>${esc(v.thumbnail_loc)}</video:thumbnail_loc>\n <video:description>${esc(v.description)}</video:description>\n`;
40
+ if (v.content_loc)
41
+ xml += ` <video:content_loc>${esc(v.content_loc)}</video:content_loc>\n`;
42
+ if (v.player_loc)
43
+ xml += ` <video:player_loc>${esc(v.player_loc)}</video:player_loc>\n`;
44
+ xml += ' </video:video>\n';
45
+ }
46
+ xml += ' </url>\n';
47
+ }
48
+ return xml + '</urlset>\n';
49
+ }
50
+ function list(v) {
51
+ return v === undefined ? [] : Array.isArray(v) ? v : [v];
52
+ }
53
+ /** The text of a robots.txt. */
54
+ export function renderRobotsTXT(robots) {
55
+ let out = '';
56
+ for (const rule of Array.isArray(robots.rules) ? robots.rules : [robots.rules]) {
57
+ for (const ua of list(rule.userAgent).length ? list(rule.userAgent) : ['*'])
58
+ out += `User-Agent: ${ua}\n`;
59
+ for (const a of list(rule.allow))
60
+ out += `Allow: ${a}\n`;
61
+ for (const d of list(rule.disallow))
62
+ out += `Disallow: ${d}\n`;
63
+ if (rule.crawlDelay !== undefined)
64
+ out += `Crawl-delay: ${rule.crawlDelay}\n`;
65
+ out += '\n';
66
+ }
67
+ for (const s of list(robots.sitemap))
68
+ out += `Sitemap: ${s}\n`;
69
+ if (robots.host)
70
+ out += `Host: ${robots.host}\n`;
71
+ return out;
72
+ }
73
+ /** The JSON of a web app manifest. */
74
+ export function renderManifestJSON(manifest) {
75
+ return JSON.stringify(manifest, null, 2) + '\n';
76
+ }
@@ -0,0 +1,222 @@
1
+ export interface TemplateString {
2
+ default?: string;
3
+ template?: string;
4
+ absolute?: string;
5
+ }
6
+ export interface OGImage {
7
+ url: string | URL;
8
+ secureUrl?: string | URL;
9
+ alt?: string;
10
+ type?: string;
11
+ width?: string | number;
12
+ height?: string | number;
13
+ }
14
+ export interface IconDescriptor {
15
+ url: string | URL;
16
+ type?: string;
17
+ sizes?: string;
18
+ color?: string;
19
+ rel?: string;
20
+ media?: string;
21
+ fetchPriority?: 'high' | 'low' | 'auto';
22
+ }
23
+ type Icon = string | URL | IconDescriptor;
24
+ export interface Metadata {
25
+ metadataBase?: string | URL | null;
26
+ title?: string | TemplateString | null;
27
+ description?: string | null;
28
+ applicationName?: string | null;
29
+ authors?: Array<{
30
+ name?: string;
31
+ url?: string | URL;
32
+ }> | {
33
+ name?: string;
34
+ url?: string | URL;
35
+ } | null;
36
+ generator?: string | null;
37
+ keywords?: string | string[] | null;
38
+ referrer?: string | null;
39
+ creator?: string | null;
40
+ publisher?: string | null;
41
+ robots?: string | RobotsObject | null;
42
+ alternates?: {
43
+ canonical?: string | URL | null;
44
+ languages?: Record<string, string | URL | null>;
45
+ media?: Record<string, string | URL | null>;
46
+ types?: Record<string, string | URL | null>;
47
+ } | null;
48
+ openGraph?: OpenGraph | null;
49
+ twitter?: Twitter | null;
50
+ icons?: Icon | Icon[] | {
51
+ icon?: Icon | Icon[];
52
+ shortcut?: Icon | Icon[];
53
+ apple?: Icon | Icon[];
54
+ other?: IconDescriptor | IconDescriptor[];
55
+ } | null;
56
+ manifest?: string | URL | null;
57
+ themeColor?: string | Array<{
58
+ media?: string;
59
+ color: string;
60
+ }> | null;
61
+ viewport?: string | Viewport | null;
62
+ colorScheme?: string | null;
63
+ verification?: {
64
+ google?: string | string[];
65
+ yahoo?: string | string[];
66
+ yandex?: string | string[];
67
+ me?: string | string[];
68
+ other?: Record<string, string | string[]>;
69
+ } | null;
70
+ appleWebApp?: {
71
+ capable?: boolean;
72
+ title?: string;
73
+ statusBarStyle?: string;
74
+ startupImage?: string | string[];
75
+ } | boolean | null;
76
+ formatDetection?: {
77
+ telephone?: boolean;
78
+ date?: boolean;
79
+ address?: boolean;
80
+ email?: boolean;
81
+ url?: boolean;
82
+ } | null;
83
+ category?: string | null;
84
+ itunes?: {
85
+ appId: string;
86
+ appArgument?: string;
87
+ } | null;
88
+ appLinks?: Record<string, unknown> | null;
89
+ archives?: string | string[] | null;
90
+ assets?: string | string[] | null;
91
+ bookmarks?: string | string[] | null;
92
+ other?: Record<string, string | number | Array<string | number>> | null;
93
+ }
94
+ export interface RobotsObject {
95
+ index?: boolean;
96
+ follow?: boolean;
97
+ noarchive?: boolean;
98
+ nosnippet?: boolean;
99
+ noimageindex?: boolean;
100
+ nocache?: boolean;
101
+ notranslate?: boolean;
102
+ maxSnippet?: number;
103
+ maxImagePreview?: 'none' | 'standard' | 'large';
104
+ maxVideoPreview?: number | string;
105
+ googleBot?: string | RobotsObject;
106
+ }
107
+ export interface OpenGraph {
108
+ type?: string;
109
+ url?: string | URL;
110
+ title?: string | TemplateString;
111
+ description?: string;
112
+ siteName?: string;
113
+ locale?: string;
114
+ alternateLocale?: string | string[];
115
+ determiner?: string;
116
+ images?: string | URL | OGImage | Array<string | URL | OGImage>;
117
+ videos?: Array<{
118
+ url: string | URL;
119
+ width?: number;
120
+ height?: number;
121
+ type?: string;
122
+ }>;
123
+ audio?: Array<{
124
+ url: string | URL;
125
+ type?: string;
126
+ }>;
127
+ publishedTime?: string;
128
+ modifiedTime?: string;
129
+ expirationTime?: string;
130
+ authors?: string | string[];
131
+ section?: string;
132
+ tags?: string | string[];
133
+ emails?: string | string[];
134
+ phoneNumbers?: string | string[];
135
+ firstName?: string;
136
+ lastName?: string;
137
+ username?: string;
138
+ gender?: string;
139
+ [key: string]: unknown;
140
+ }
141
+ export interface Twitter {
142
+ card?: 'summary' | 'summary_large_image' | 'app' | 'player';
143
+ site?: string;
144
+ siteId?: string;
145
+ creator?: string;
146
+ creatorId?: string;
147
+ title?: string | TemplateString;
148
+ description?: string;
149
+ images?: string | URL | OGImage | Array<string | URL | OGImage>;
150
+ [key: string]: unknown;
151
+ }
152
+ export interface Viewport {
153
+ width?: string | number;
154
+ height?: string | number;
155
+ initialScale?: number;
156
+ minimumScale?: number;
157
+ maximumScale?: number;
158
+ userScalable?: boolean;
159
+ viewportFit?: 'auto' | 'cover' | 'contain';
160
+ interactiveWidget?: 'resizes-visual' | 'resizes-content' | 'overlays-content';
161
+ themeColor?: string | Array<{
162
+ media?: string;
163
+ color: string;
164
+ }>;
165
+ colorScheme?: string;
166
+ }
167
+ /** The resolved viewport of the parent segments. */
168
+ export type ResolvingViewport = Promise<Viewport>;
169
+ export interface MetadataProps {
170
+ params?: unknown;
171
+ searchParams?: unknown;
172
+ }
173
+ /** The resolved metadata of the parent segments, as generateMetadata's second argument. */
174
+ export type ResolvingMetadata = Promise<Metadata>;
175
+ export interface MetadataModule {
176
+ metadata?: Metadata | null;
177
+ /** A static `export const viewport`, merged like metadata. */
178
+ viewport?: Viewport | null;
179
+ generateMetadata?: (props: MetadataProps, parent: ResolvingMetadata) => Metadata | null | undefined | Promise<Metadata | null | undefined>;
180
+ }
181
+ /** One layer of the chain, root layout first, the page last. */
182
+ export interface MetadataSegment {
183
+ /** The module that exports metadata or generateMetadata. */
184
+ mod?: MetadataModule | null;
185
+ /** Name for log lines ("src/pages/blog/_layout.tsx"). */
186
+ file?: string;
187
+ /** Metadata a file convention contributes (opengraph-image, icon, ...), under the segment's own export. */
188
+ files?: Metadata;
189
+ }
190
+ export interface ResolvedMetadata {
191
+ metadata: Metadata;
192
+ /** The title templates a segment declared for openGraph.title and twitter.title. */
193
+ templates: {
194
+ openGraph?: string;
195
+ twitter?: string;
196
+ };
197
+ /** Errors thrown by generateMetadata functions; the page renders without that segment's metadata. */
198
+ errors: Array<{
199
+ file: string;
200
+ error: unknown;
201
+ }>;
202
+ }
203
+ /**
204
+ * Resolves the chain: each segment's metadata (an export or the result of
205
+ * generateMetadata, which gets { params, searchParams } and a promise of the
206
+ * parents' merged metadata), merged root first. A deeper segment replaces a
207
+ * field wholesale; a title string takes the nearest ancestor's template. A
208
+ * generateMetadata that throws is logged and skipped, so one failing lookup
209
+ * never costs the page.
210
+ */
211
+ export declare function resolveMetadata(segments: MetadataSegment[], rawProps: MetadataProps): Promise<ResolvedMetadata>;
212
+ /** The <head> tags for resolved metadata, one per line. */
213
+ export declare function renderMetadataTags(md: Metadata, templates?: {
214
+ openGraph?: string;
215
+ twitter?: string;
216
+ }): string;
217
+ /**
218
+ * The head markup of a chain for these props, or "" when the chain exports no
219
+ * metadata. Errors from generateMetadata are logged and the segment skipped.
220
+ */
221
+ export declare function metadataHeadTags(segments: MetadataSegment[], props: MetadataProps, log?: (msg: string, err: unknown) => void): Promise<string>;
222
+ export {};