effect-start 0.20.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -4
- package/dist/Cookies.js +392 -0
- package/dist/FileSystem.js +131 -0
- package/dist/Socket.js +37 -0
- package/package.json +39 -40
- package/src/Commander.ts +73 -130
- package/src/ContentNegotiation.ts +68 -100
- package/src/Cookies.ts +408 -0
- package/src/Development.ts +48 -63
- package/src/Effectify.ts +222 -206
- package/src/Entity.ts +59 -86
- package/src/FilePathPattern.ts +5 -5
- package/src/FileRouter.ts +38 -63
- package/src/FileRouterCodegen.ts +64 -56
- package/src/FileSystem.ts +390 -0
- package/src/Http.ts +17 -50
- package/src/PathPattern.ts +33 -41
- package/src/PlatformError.ts +29 -50
- package/src/PlatformRuntime.ts +39 -47
- package/src/Route.ts +68 -187
- package/src/RouteBody.ts +45 -161
- package/src/RouteHook.ts +22 -45
- package/src/RouteHttp.ts +88 -142
- package/src/RouteHttpTracer.ts +25 -26
- package/src/RouteMount.ts +100 -238
- package/src/RouteSchema.ts +67 -201
- package/src/RouteSse.ts +28 -82
- package/src/RouteTree.ts +31 -79
- package/src/RouteTrie.ts +13 -32
- package/src/SchemaExtra.ts +3 -5
- package/src/Socket.ts +51 -0
- package/src/Start.ts +20 -21
- package/src/StreamExtra.ts +93 -96
- package/src/TuplePathPattern.ts +54 -43
- package/src/Unique.ts +9 -15
- package/src/Values.ts +26 -30
- package/src/bun/BunBundle.ts +27 -73
- package/src/bun/BunImportTrackerPlugin.ts +67 -65
- package/src/bun/BunRoute.ts +12 -31
- package/src/bun/BunRuntime.ts +3 -10
- package/src/bun/BunServer.ts +50 -60
- package/src/bun/BunVirtualFilesPlugin.ts +1 -4
- package/src/bun/_BunEnhancedResolve.ts +17 -42
- package/src/bun/_empty.html +0 -1
- package/src/bundler/Bundle.ts +20 -36
- package/src/bundler/BundleFiles.ts +36 -56
- package/src/client/Overlay.ts +1 -2
- package/src/client/ScrollState.ts +5 -9
- package/src/client/index.ts +10 -13
- package/src/datastar/actions/fetch.ts +29 -48
- package/src/datastar/actions/peek.ts +1 -5
- package/src/datastar/actions/setAll.ts +2 -2
- package/src/datastar/actions/toggleAll.ts +2 -2
- package/src/datastar/attributes/attr.ts +17 -18
- package/src/datastar/attributes/bind.ts +41 -61
- package/src/datastar/attributes/class.ts +2 -5
- package/src/datastar/attributes/computed.ts +2 -10
- package/src/datastar/attributes/effect.ts +1 -2
- package/src/datastar/attributes/indicator.ts +2 -8
- package/src/datastar/attributes/init.ts +2 -10
- package/src/datastar/attributes/jsonSignals.ts +1 -6
- package/src/datastar/attributes/on.ts +4 -13
- package/src/datastar/attributes/onIntersect.ts +10 -22
- package/src/datastar/attributes/onInterval.ts +2 -10
- package/src/datastar/attributes/onSignalPatch.ts +18 -28
- package/src/datastar/attributes/ref.ts +1 -2
- package/src/datastar/attributes/show.ts +1 -2
- package/src/datastar/attributes/signals.ts +1 -5
- package/src/datastar/attributes/style.ts +6 -12
- package/src/datastar/attributes/text.ts +1 -2
- package/src/datastar/engine.ts +102 -158
- package/src/datastar/index.ts +2 -2
- package/src/datastar/utils.ts +16 -51
- package/src/datastar/watchers/patchElements.ts +35 -93
- package/src/datastar/watchers/patchSignals.ts +1 -2
- package/src/experimental/EncryptedCookies.ts +81 -175
- package/src/experimental/index.ts +0 -1
- package/src/hyper/Hyper.ts +14 -33
- package/src/hyper/HyperHtml.ts +13 -10
- package/src/hyper/HyperNode.ts +2 -7
- package/src/hyper/HyperRoute.ts +2 -5
- package/src/hyper/jsx-runtime.ts +2 -10
- package/src/hyper/jsx.d.ts +171 -440
- package/src/lint/plugin.js +276 -0
- package/src/node/NodeFileSystem.ts +140 -202
- package/src/node/NodeUtils.ts +1 -3
- package/src/testing/TestLogger.ts +9 -22
- package/src/testing/index.ts +0 -1
- package/src/testing/utils.ts +30 -31
- package/src/x/cloudflare/CloudflareTunnel.ts +53 -65
- package/src/x/datastar/Datastar.ts +3 -10
- package/src/x/datastar/index.ts +1 -3
- package/src/x/datastar/jsx-datastar.d.ts +1 -4
- package/src/x/tailwind/TailwindPlugin.ts +119 -112
- package/src/x/tailwind/compile.ts +10 -33
- package/src/x/tailwind/plugin.ts +2 -2
- package/src/HttpAppExtra.ts +0 -478
- package/src/HttpUtils.ts +0 -17
- package/src/bun/BunPlatformHttpServer.ts +0 -88
- package/src/bun/BunServerRequest.ts +0 -396
- package/src/bundler/BundleHttp.ts +0 -259
- package/src/experimental/SseHttpResponse.ts +0 -55
- package/src/middlewares/BasicAuthMiddleware.ts +0 -36
- package/src/middlewares/index.ts +0 -1
- package/src/testing/TestHttpClient.ts +0 -148
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* Based on {@link https://github.com/jshttp/negotiator}
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type * as Headers from "@effect/platform/Headers"
|
|
7
|
-
|
|
8
6
|
interface ParsedSpec {
|
|
9
7
|
value: string
|
|
10
8
|
q: number
|
|
@@ -13,7 +11,7 @@ interface ParsedSpec {
|
|
|
13
11
|
i: number
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
const simpleMediaTypeRegExp = /^\s*([^\s
|
|
14
|
+
const simpleMediaTypeRegExp = /^\s*([^\s/;]+)\/([^;\s]+)\s*(?:;(.*))?$/
|
|
17
15
|
const simpleLanguageRegExp = /^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/
|
|
18
16
|
const simpleEncodingRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/
|
|
19
17
|
const simpleCharsetRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/
|
|
@@ -26,9 +24,10 @@ function parseQuality(params: string | undefined): number {
|
|
|
26
24
|
return isNaN(q) ? 1 : Math.min(Math.max(q, 0), 1)
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
function splitMediaTypeParams(
|
|
30
|
-
params: string,
|
|
31
|
-
|
|
27
|
+
function splitMediaTypeParams(params: string): {
|
|
28
|
+
params: Record<string, string>
|
|
29
|
+
q: number
|
|
30
|
+
} {
|
|
32
31
|
const result: Record<string, string> = {}
|
|
33
32
|
let q = 1
|
|
34
33
|
|
|
@@ -41,7 +40,7 @@ function splitMediaTypeParams(
|
|
|
41
40
|
const key = trimmed.slice(0, eqIndex).trim().toLowerCase()
|
|
42
41
|
let value = trimmed.slice(eqIndex + 1).trim()
|
|
43
42
|
|
|
44
|
-
if (value.startsWith("
|
|
43
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
45
44
|
value = value.slice(1, -1)
|
|
46
45
|
}
|
|
47
46
|
|
|
@@ -57,17 +56,13 @@ function splitMediaTypeParams(
|
|
|
57
56
|
return { params: result, q }
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
function parseAccept(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
q: number
|
|
68
|
-
o: number
|
|
69
|
-
}
|
|
70
|
-
> {
|
|
59
|
+
function parseAccept(accept: string): Array<{
|
|
60
|
+
type: string
|
|
61
|
+
subtype: string
|
|
62
|
+
params: Record<string, string>
|
|
63
|
+
q: number
|
|
64
|
+
o: number
|
|
65
|
+
}> {
|
|
71
66
|
const specs: Array<{
|
|
72
67
|
type: string
|
|
73
68
|
subtype: string
|
|
@@ -86,9 +81,7 @@ function parseAccept(
|
|
|
86
81
|
|
|
87
82
|
const type = match[1].toLowerCase()
|
|
88
83
|
const subtype = match[2].toLowerCase()
|
|
89
|
-
const { params, q } = match[3]
|
|
90
|
-
? splitMediaTypeParams(match[3])
|
|
91
|
-
: { params: {}, q: 1 }
|
|
84
|
+
const { params, q } = match[3] ? splitMediaTypeParams(match[3]) : { params: {}, q: 1 }
|
|
92
85
|
|
|
93
86
|
if (q > 0) {
|
|
94
87
|
specs.push({ type, subtype, params, q, o })
|
|
@@ -135,8 +128,7 @@ function specifyMediaType(
|
|
|
135
128
|
if (specParams.length > 0) {
|
|
136
129
|
if (
|
|
137
130
|
specParams.every(
|
|
138
|
-
(key) =>
|
|
139
|
-
spec.params[key].toLowerCase() === (params[key] || "").toLowerCase(),
|
|
131
|
+
(key) => spec.params[key].toLowerCase() === (params[key] || "").toLowerCase(),
|
|
140
132
|
)
|
|
141
133
|
) {
|
|
142
134
|
s |= 1
|
|
@@ -150,15 +142,13 @@ function specifyMediaType(
|
|
|
150
142
|
|
|
151
143
|
function getMediaTypePriority(
|
|
152
144
|
mediaType: string,
|
|
153
|
-
accepted: Array<
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
>,
|
|
145
|
+
accepted: Array<{
|
|
146
|
+
type: string
|
|
147
|
+
subtype: string
|
|
148
|
+
params: Record<string, string>
|
|
149
|
+
q: number
|
|
150
|
+
o: number
|
|
151
|
+
}>,
|
|
162
152
|
index: number,
|
|
163
153
|
): ParsedSpec {
|
|
164
154
|
let best: { q: number; s: number; o: number } | null = null
|
|
@@ -170,18 +160,16 @@ function getMediaTypePriority(
|
|
|
170
160
|
|
|
171
161
|
const type = match[1].toLowerCase()
|
|
172
162
|
const subtype = match[2].toLowerCase()
|
|
173
|
-
const { params } = match[3]
|
|
174
|
-
? splitMediaTypeParams(match[3])
|
|
175
|
-
: { params: {} }
|
|
163
|
+
const { params } = match[3] ? splitMediaTypeParams(match[3]) : { params: {} }
|
|
176
164
|
|
|
177
165
|
for (const spec of accepted) {
|
|
178
166
|
const result = specifyMediaType(type, subtype, params, spec)
|
|
179
167
|
if (
|
|
180
|
-
result
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
168
|
+
result &&
|
|
169
|
+
(best === null ||
|
|
170
|
+
result.s > best.s ||
|
|
171
|
+
(result.s === best.s && result.q > best.q) ||
|
|
172
|
+
(result.s === best.s && result.q === best.q && result.o < best.o))
|
|
185
173
|
) {
|
|
186
174
|
best = result
|
|
187
175
|
}
|
|
@@ -257,9 +245,12 @@ function specifyLanguage(
|
|
|
257
245
|
|
|
258
246
|
function getLanguagePriority(
|
|
259
247
|
language: string,
|
|
260
|
-
accepted: Array<
|
|
261
|
-
|
|
262
|
-
|
|
248
|
+
accepted: Array<{
|
|
249
|
+
prefix: string
|
|
250
|
+
suffix: string | undefined
|
|
251
|
+
q: number
|
|
252
|
+
o: number
|
|
253
|
+
}>,
|
|
263
254
|
index: number,
|
|
264
255
|
): ParsedSpec {
|
|
265
256
|
let best: { q: number; s: number; o: number } | null = null
|
|
@@ -267,11 +258,11 @@ function getLanguagePriority(
|
|
|
267
258
|
for (const spec of accepted) {
|
|
268
259
|
const result = specifyLanguage(language, spec)
|
|
269
260
|
if (
|
|
270
|
-
result
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
261
|
+
result &&
|
|
262
|
+
(best === null ||
|
|
263
|
+
result.s > best.s ||
|
|
264
|
+
(result.s === best.s && result.q > best.q) ||
|
|
265
|
+
(result.s === best.s && result.q === best.q && result.o < best.o))
|
|
275
266
|
) {
|
|
276
267
|
best = result
|
|
277
268
|
}
|
|
@@ -286,9 +277,7 @@ function getLanguagePriority(
|
|
|
286
277
|
}
|
|
287
278
|
}
|
|
288
279
|
|
|
289
|
-
function parseAcceptEncoding(
|
|
290
|
-
accept: string,
|
|
291
|
-
): Array<{ encoding: string; q: number; o: number }> {
|
|
280
|
+
function parseAcceptEncoding(accept: string): Array<{ encoding: string; q: number; o: number }> {
|
|
292
281
|
const specs: Array<{ encoding: string; q: number; o: number }> = []
|
|
293
282
|
const parts = accept.split(",")
|
|
294
283
|
let hasIdentity = false
|
|
@@ -342,11 +331,11 @@ function getEncodingPriority(
|
|
|
342
331
|
for (const spec of accepted) {
|
|
343
332
|
const result = specifyEncoding(encoding, spec)
|
|
344
333
|
if (
|
|
345
|
-
result
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
334
|
+
result &&
|
|
335
|
+
(best === null ||
|
|
336
|
+
result.s > best.s ||
|
|
337
|
+
(result.s === best.s && result.q > best.q) ||
|
|
338
|
+
(result.s === best.s && result.q === best.q && result.o < best.o))
|
|
350
339
|
) {
|
|
351
340
|
best = result
|
|
352
341
|
}
|
|
@@ -361,9 +350,7 @@ function getEncodingPriority(
|
|
|
361
350
|
}
|
|
362
351
|
}
|
|
363
352
|
|
|
364
|
-
function parseAcceptCharset(
|
|
365
|
-
accept: string,
|
|
366
|
-
): Array<{ charset: string; q: number; o: number }> {
|
|
353
|
+
function parseAcceptCharset(accept: string): Array<{ charset: string; q: number; o: number }> {
|
|
367
354
|
const specs: Array<{ charset: string; q: number; o: number }> = []
|
|
368
355
|
const parts = accept.split(",")
|
|
369
356
|
|
|
@@ -409,11 +396,11 @@ function getCharsetPriority(
|
|
|
409
396
|
for (const spec of accepted) {
|
|
410
397
|
const result = specifyCharset(charset, spec)
|
|
411
398
|
if (
|
|
412
|
-
result
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
399
|
+
result &&
|
|
400
|
+
(best === null ||
|
|
401
|
+
result.s > best.s ||
|
|
402
|
+
(result.s === best.s && result.q > best.q) ||
|
|
403
|
+
(result.s === best.s && result.q === best.q && result.o < best.o))
|
|
417
404
|
) {
|
|
418
405
|
best = result
|
|
419
406
|
}
|
|
@@ -429,24 +416,17 @@ function getCharsetPriority(
|
|
|
429
416
|
}
|
|
430
417
|
|
|
431
418
|
function compareSpecs(a: ParsedSpec, b: ParsedSpec): number {
|
|
432
|
-
return
|
|
433
|
-
b.q - a.q
|
|
434
|
-
|| b.s - a.s
|
|
435
|
-
|| a.o - b.o
|
|
436
|
-
|| a.i - b.i
|
|
437
|
-
)
|
|
419
|
+
return b.q - a.q || b.s - a.s || a.o - b.o || a.i - b.i
|
|
438
420
|
}
|
|
439
421
|
|
|
440
|
-
export function media(accept: string, available?: string
|
|
422
|
+
export function media(accept: string, available?: Array<string>): Array<string> {
|
|
441
423
|
const parsed = parseAccept(accept)
|
|
442
424
|
if (parsed.length === 0) {
|
|
443
425
|
return []
|
|
444
426
|
}
|
|
445
427
|
|
|
446
428
|
if (!available) {
|
|
447
|
-
return parsed.sort((a, b) => b.q - a.q || a.o - b.o).map((p) =>
|
|
448
|
-
`${p.type}/${p.subtype}`
|
|
449
|
-
)
|
|
429
|
+
return parsed.sort((a, b) => b.q - a.q || a.o - b.o).map((p) => `${p.type}/${p.subtype}`)
|
|
450
430
|
}
|
|
451
431
|
|
|
452
432
|
const priorities = available.map((t, i) => getMediaTypePriority(t, parsed, i))
|
|
@@ -455,16 +435,16 @@ export function media(accept: string, available?: string[]): string[] {
|
|
|
455
435
|
return sorted.map((p) => p.value)
|
|
456
436
|
}
|
|
457
437
|
|
|
458
|
-
export function language(accept: string, available?: string
|
|
438
|
+
export function language(accept: string, available?: Array<string>): Array<string> {
|
|
459
439
|
const parsed = parseAcceptLanguage(accept)
|
|
460
440
|
if (parsed.length === 0) {
|
|
461
441
|
return []
|
|
462
442
|
}
|
|
463
443
|
|
|
464
444
|
if (!available) {
|
|
465
|
-
return parsed
|
|
466
|
-
|
|
467
|
-
|
|
445
|
+
return parsed
|
|
446
|
+
.sort((a, b) => b.q - a.q || a.o - b.o)
|
|
447
|
+
.map((p) => (p.suffix ? `${p.prefix}-${p.suffix}` : p.prefix))
|
|
468
448
|
}
|
|
469
449
|
|
|
470
450
|
const priorities = available.map((l, i) => getLanguagePriority(l, parsed, i))
|
|
@@ -473,7 +453,7 @@ export function language(accept: string, available?: string[]): string[] {
|
|
|
473
453
|
return sorted.map((p) => p.value)
|
|
474
454
|
}
|
|
475
455
|
|
|
476
|
-
export function encoding(accept: string, available?: string
|
|
456
|
+
export function encoding(accept: string, available?: Array<string>): Array<string> {
|
|
477
457
|
const parsed = parseAcceptEncoding(accept)
|
|
478
458
|
if (parsed.length === 0) {
|
|
479
459
|
return []
|
|
@@ -489,7 +469,7 @@ export function encoding(accept: string, available?: string[]): string[] {
|
|
|
489
469
|
return sorted.map((p) => p.value)
|
|
490
470
|
}
|
|
491
471
|
|
|
492
|
-
export function charset(accept: string, available?: string
|
|
472
|
+
export function charset(accept: string, available?: Array<string>): Array<string> {
|
|
493
473
|
const parsed = parseAcceptCharset(accept)
|
|
494
474
|
if (parsed.length === 0) {
|
|
495
475
|
return []
|
|
@@ -505,38 +485,26 @@ export function charset(accept: string, available?: string[]): string[] {
|
|
|
505
485
|
return sorted.map((p) => p.value)
|
|
506
486
|
}
|
|
507
487
|
|
|
508
|
-
export function headerMedia(
|
|
509
|
-
headers
|
|
510
|
-
available?: string[],
|
|
511
|
-
): string[] {
|
|
512
|
-
const accept = headers["accept"]
|
|
488
|
+
export function headerMedia(headers: Headers, available?: Array<string>): Array<string> {
|
|
489
|
+
const accept = headers.get("accept")
|
|
513
490
|
if (!accept) return []
|
|
514
491
|
return media(accept, available)
|
|
515
492
|
}
|
|
516
493
|
|
|
517
|
-
export function headerLanguage(
|
|
518
|
-
headers
|
|
519
|
-
available?: string[],
|
|
520
|
-
): string[] {
|
|
521
|
-
const accept = headers["accept-language"]
|
|
494
|
+
export function headerLanguage(headers: Headers, available?: Array<string>): Array<string> {
|
|
495
|
+
const accept = headers.get("accept-language")
|
|
522
496
|
if (!accept) return []
|
|
523
497
|
return language(accept, available)
|
|
524
498
|
}
|
|
525
499
|
|
|
526
|
-
export function headerEncoding(
|
|
527
|
-
headers
|
|
528
|
-
available?: string[],
|
|
529
|
-
): string[] {
|
|
530
|
-
const accept = headers["accept-encoding"]
|
|
500
|
+
export function headerEncoding(headers: Headers, available?: Array<string>): Array<string> {
|
|
501
|
+
const accept = headers.get("accept-encoding")
|
|
531
502
|
if (!accept) return []
|
|
532
503
|
return encoding(accept, available)
|
|
533
504
|
}
|
|
534
505
|
|
|
535
|
-
export function headerCharset(
|
|
536
|
-
headers
|
|
537
|
-
available?: string[],
|
|
538
|
-
): string[] {
|
|
539
|
-
const accept = headers["accept-charset"]
|
|
506
|
+
export function headerCharset(headers: Headers, available?: Array<string>): Array<string> {
|
|
507
|
+
const accept = headers.get("accept-charset")
|
|
540
508
|
if (!accept) return []
|
|
541
509
|
return charset(accept, available)
|
|
542
510
|
}
|