effect-start 0.23.1 → 0.26.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/package.json +18 -86
- package/src/Development.ts +3 -1
- package/src/Entity.ts +17 -0
- package/src/Fetch.ts +271 -0
- package/src/SqlIntrospect.ts +64 -70
- package/src/Start.ts +21 -24
- package/src/StartApp.ts +1 -1
- package/src/bun/BunServer.ts +42 -10
- package/src/hyper/HyperHtml.ts +0 -1
- package/src/sql/bun/index.ts +1 -1
- package/src/sql/index.ts +1 -0
- package/src/sql/libsql/index.ts +173 -0
- package/src/sql/libsql/libsql.d.ts +39 -0
- package/src/sql/mssql/index.ts +1 -1
- package/dist/BlobStore.d.ts +0 -80
- package/dist/BlobStore.js +0 -19
- package/dist/ChildProcess.d.ts +0 -60
- package/dist/ChildProcess.js +0 -30
- package/dist/Commander.d.ts +0 -100
- package/dist/Commander.js +0 -326
- package/dist/ContentNegotiation.d.ts +0 -12
- package/dist/ContentNegotiation.js +0 -359
- package/dist/Cookies.d.ts +0 -47
- package/dist/Cookies.js +0 -302
- package/dist/Development.d.ts +0 -39
- package/dist/Development.js +0 -58
- package/dist/Effectify.d.ts +0 -209
- package/dist/Effectify.js +0 -19
- package/dist/Entity.d.ts +0 -47
- package/dist/Entity.js +0 -224
- package/dist/FilePathPattern.d.ts +0 -29
- package/dist/FilePathPattern.js +0 -86
- package/dist/FileRouter.d.ts +0 -56
- package/dist/FileRouter.js +0 -148
- package/dist/FileRouterCodegen.d.ts +0 -18
- package/dist/FileRouterCodegen.js +0 -227
- package/dist/FileRouterPattern.d.ts +0 -9
- package/dist/FileRouterPattern.js +0 -35
- package/dist/FileSystem.d.ts +0 -158
- package/dist/FileSystem.js +0 -70
- package/dist/Http.d.ts +0 -37
- package/dist/Http.js +0 -88
- package/dist/HttpAppExtra.d.ts +0 -7
- package/dist/HttpAppExtra.js +0 -320
- package/dist/HttpUtils.d.ts +0 -3
- package/dist/HttpUtils.js +0 -11
- package/dist/PathPattern.d.ts +0 -134
- package/dist/PathPattern.js +0 -413
- package/dist/PlatformError.d.ts +0 -38
- package/dist/PlatformError.js +0 -25
- package/dist/PlatformRuntime.d.ts +0 -27
- package/dist/PlatformRuntime.js +0 -46
- package/dist/Route.d.ts +0 -97
- package/dist/Route.js +0 -100
- package/dist/RouteBody.d.ts +0 -47
- package/dist/RouteBody.js +0 -67
- package/dist/RouteError.d.ts +0 -98
- package/dist/RouteError.js +0 -55
- package/dist/RouteHook.d.ts +0 -12
- package/dist/RouteHook.js +0 -40
- package/dist/RouteHttp.d.ts +0 -21
- package/dist/RouteHttp.js +0 -258
- package/dist/RouteHttpTracer.d.ts +0 -10
- package/dist/RouteHttpTracer.js +0 -62
- package/dist/RouteMount.d.ts +0 -86
- package/dist/RouteMount.js +0 -63
- package/dist/RouteSchema.d.ts +0 -86
- package/dist/RouteSchema.js +0 -188
- package/dist/RouteSse.d.ts +0 -21
- package/dist/RouteSse.js +0 -79
- package/dist/RouteTree.d.ts +0 -57
- package/dist/RouteTree.js +0 -93
- package/dist/RouteTrie.d.ts +0 -20
- package/dist/RouteTrie.js +0 -152
- package/dist/RouterPattern.d.ts +0 -118
- package/dist/RouterPattern.js +0 -269
- package/dist/SchemaExtra.d.ts +0 -7
- package/dist/SchemaExtra.js +0 -74
- package/dist/Socket.d.ts +0 -27
- package/dist/Socket.js +0 -29
- package/dist/Sql.d.ts +0 -34
- package/dist/Sql.js +0 -5
- package/dist/SqlIntrospect.d.ts +0 -91
- package/dist/SqlIntrospect.js +0 -466
- package/dist/Start.d.ts +0 -44
- package/dist/Start.js +0 -49
- package/dist/StartApp.d.ts +0 -19
- package/dist/StartApp.js +0 -21
- package/dist/StreamExtra.d.ts +0 -28
- package/dist/StreamExtra.js +0 -100
- package/dist/System.d.ts +0 -7
- package/dist/System.js +0 -22
- package/dist/TuplePathPattern.d.ts +0 -9
- package/dist/TuplePathPattern.js +0 -68
- package/dist/Unique.d.ts +0 -50
- package/dist/Unique.js +0 -187
- package/dist/Values.d.ts +0 -27
- package/dist/Values.js +0 -36
- package/dist/bun/BunBlobStoreDisk.d.ts +0 -6
- package/dist/bun/BunBlobStoreDisk.js +0 -116
- package/dist/bun/BunBlobStoreS3.d.ts +0 -11
- package/dist/bun/BunBlobStoreS3.js +0 -89
- package/dist/bun/BunBlobWatcherDisk.d.ts +0 -6
- package/dist/bun/BunBlobWatcherDisk.js +0 -60
- package/dist/bun/BunBlobWatcherQueue.d.ts +0 -6
- package/dist/bun/BunBlobWatcherQueue.js +0 -17
- package/dist/bun/BunBundle.d.ts +0 -11
- package/dist/bun/BunBundle.js +0 -137
- package/dist/bun/BunChildProcessSpawner.d.ts +0 -3
- package/dist/bun/BunChildProcessSpawner.js +0 -103
- package/dist/bun/BunHttpServer.d.ts +0 -44
- package/dist/bun/BunHttpServer.js +0 -186
- package/dist/bun/BunHttpServer_web.d.ts +0 -60
- package/dist/bun/BunHttpServer_web.js +0 -252
- package/dist/bun/BunImportTrackerPlugin.d.ts +0 -13
- package/dist/bun/BunImportTrackerPlugin.js +0 -69
- package/dist/bun/BunPlatformHttpServer.d.ts +0 -10
- package/dist/bun/BunPlatformHttpServer.js +0 -53
- package/dist/bun/BunRoute.d.ts +0 -48
- package/dist/bun/BunRoute.js +0 -121
- package/dist/bun/BunRuntime.d.ts +0 -2
- package/dist/bun/BunRuntime.js +0 -31
- package/dist/bun/BunServer.d.ts +0 -40
- package/dist/bun/BunServer.js +0 -157
- package/dist/bun/BunServerRequest.d.ts +0 -60
- package/dist/bun/BunServerRequest.js +0 -252
- package/dist/bun/BunSql.d.ts +0 -4
- package/dist/bun/BunSql.js +0 -81
- package/dist/bun/BunVirtualFilesPlugin.d.ts +0 -4
- package/dist/bun/BunVirtualFilesPlugin.js +0 -40
- package/dist/bun/_BunEnhancedResolve.d.ts +0 -45
- package/dist/bun/_BunEnhancedResolve.js +0 -102
- package/dist/bun/index.d.ts +0 -5
- package/dist/bun/index.js +0 -5
- package/dist/bundler/Bundle.d.ts +0 -61
- package/dist/bundler/Bundle.js +0 -48
- package/dist/bundler/BundleFiles.d.ts +0 -13
- package/dist/bundler/BundleFiles.js +0 -96
- package/dist/bundler/BundleHttp.d.ts +0 -45
- package/dist/bundler/BundleHttp.js +0 -176
- package/dist/bundler/BundleRoute.d.ts +0 -27
- package/dist/bundler/BundleRoute.js +0 -51
- package/dist/client/Overlay.d.ts +0 -2
- package/dist/client/Overlay.js +0 -32
- package/dist/client/ScrollState.d.ts +0 -6
- package/dist/client/ScrollState.js +0 -94
- package/dist/client/index.d.ts +0 -6
- package/dist/client/index.js +0 -79
- package/dist/console/Console.d.ts +0 -6
- package/dist/console/Console.js +0 -26
- package/dist/console/ConsoleErrors.d.ts +0 -3
- package/dist/console/ConsoleErrors.js +0 -200
- package/dist/console/ConsoleLogger.d.ts +0 -3
- package/dist/console/ConsoleLogger.js +0 -47
- package/dist/console/ConsoleMetrics.d.ts +0 -3
- package/dist/console/ConsoleMetrics.js +0 -61
- package/dist/console/ConsoleProcess.d.ts +0 -3
- package/dist/console/ConsoleProcess.js +0 -49
- package/dist/console/ConsoleStore.d.ts +0 -144
- package/dist/console/ConsoleStore.js +0 -61
- package/dist/console/ConsoleTracer.d.ts +0 -3
- package/dist/console/ConsoleTracer.js +0 -94
- package/dist/console/Simulation.d.ts +0 -2
- package/dist/console/Simulation.js +0 -633
- package/dist/console/index.d.ts +0 -3
- package/dist/console/index.js +0 -3
- package/dist/console/routes/errors/route.d.ts +0 -10
- package/dist/console/routes/errors/route.js +0 -47
- package/dist/console/routes/fiberDetail.d.ts +0 -16
- package/dist/console/routes/fiberDetail.js +0 -38
- package/dist/console/routes/fibers/route.d.ts +0 -10
- package/dist/console/routes/fibers/route.js +0 -19
- package/dist/console/routes/git/route.d.ts +0 -11
- package/dist/console/routes/git/route.js +0 -33
- package/dist/console/routes/layout.d.ts +0 -9
- package/dist/console/routes/layout.js +0 -3
- package/dist/console/routes/logs/route.d.ts +0 -10
- package/dist/console/routes/logs/route.js +0 -32
- package/dist/console/routes/metrics/route.d.ts +0 -10
- package/dist/console/routes/metrics/route.js +0 -17
- package/dist/console/routes/route.d.ts +0 -6
- package/dist/console/routes/route.js +0 -5
- package/dist/console/routes/routes/route.d.ts +0 -6
- package/dist/console/routes/routes/route.js +0 -20
- package/dist/console/routes/services/route.d.ts +0 -6
- package/dist/console/routes/services/route.js +0 -12
- package/dist/console/routes/system/route.d.ts +0 -10
- package/dist/console/routes/system/route.js +0 -18
- package/dist/console/routes/traceDetail.d.ts +0 -16
- package/dist/console/routes/traceDetail.js +0 -14
- package/dist/console/routes/traces/route.d.ts +0 -10
- package/dist/console/routes/traces/route.js +0 -39
- package/dist/console/routes/tree.d.ts +0 -153
- package/dist/console/routes/tree.js +0 -29
- package/dist/console/ui/Errors.d.ts +0 -4
- package/dist/console/ui/Errors.js +0 -15
- package/dist/console/ui/Fibers.d.ts +0 -24
- package/dist/console/ui/Fibers.js +0 -121
- package/dist/console/ui/Git.d.ts +0 -20
- package/dist/console/ui/Git.js +0 -95
- package/dist/console/ui/Logs.d.ts +0 -4
- package/dist/console/ui/Logs.js +0 -25
- package/dist/console/ui/Metrics.d.ts +0 -4
- package/dist/console/ui/Metrics.js +0 -26
- package/dist/console/ui/Routes.d.ts +0 -8
- package/dist/console/ui/Routes.js +0 -70
- package/dist/console/ui/Services.d.ts +0 -10
- package/dist/console/ui/Services.js +0 -246
- package/dist/console/ui/Shell.d.ts +0 -10
- package/dist/console/ui/Shell.js +0 -7
- package/dist/console/ui/System.d.ts +0 -4
- package/dist/console/ui/System.js +0 -35
- package/dist/console/ui/Traces.d.ts +0 -12
- package/dist/console/ui/Traces.js +0 -179
- package/dist/datastar/actions/fetch.d.ts +0 -30
- package/dist/datastar/actions/fetch.js +0 -403
- package/dist/datastar/actions/peek.d.ts +0 -1
- package/dist/datastar/actions/peek.js +0 -13
- package/dist/datastar/actions/setAll.d.ts +0 -1
- package/dist/datastar/actions/setAll.js +0 -12
- package/dist/datastar/actions/toggleAll.d.ts +0 -1
- package/dist/datastar/actions/toggleAll.js +0 -12
- package/dist/datastar/attributes/attr.d.ts +0 -1
- package/dist/datastar/attributes/attr.js +0 -48
- package/dist/datastar/attributes/bind.d.ts +0 -1
- package/dist/datastar/attributes/bind.js +0 -175
- package/dist/datastar/attributes/class.d.ts +0 -1
- package/dist/datastar/attributes/class.js +0 -47
- package/dist/datastar/attributes/computed.d.ts +0 -1
- package/dist/datastar/attributes/computed.js +0 -26
- package/dist/datastar/attributes/effect.d.ts +0 -1
- package/dist/datastar/attributes/effect.js +0 -9
- package/dist/datastar/attributes/indicator.d.ts +0 -1
- package/dist/datastar/attributes/indicator.js +0 -30
- package/dist/datastar/attributes/init.d.ts +0 -1
- package/dist/datastar/attributes/init.js +0 -26
- package/dist/datastar/attributes/jsonSignals.d.ts +0 -1
- package/dist/datastar/attributes/jsonSignals.js +0 -30
- package/dist/datastar/attributes/on.d.ts +0 -1
- package/dist/datastar/attributes/on.js +0 -78
- package/dist/datastar/attributes/onIntersect.d.ts +0 -1
- package/dist/datastar/attributes/onIntersect.js +0 -53
- package/dist/datastar/attributes/onInterval.d.ts +0 -1
- package/dist/datastar/attributes/onInterval.js +0 -30
- package/dist/datastar/attributes/onSignalPatch.d.ts +0 -1
- package/dist/datastar/attributes/onSignalPatch.js +0 -42
- package/dist/datastar/attributes/ref.d.ts +0 -1
- package/dist/datastar/attributes/ref.js +0 -10
- package/dist/datastar/attributes/show.d.ts +0 -1
- package/dist/datastar/attributes/show.js +0 -31
- package/dist/datastar/attributes/signals.d.ts +0 -1
- package/dist/datastar/attributes/signals.js +0 -17
- package/dist/datastar/attributes/style.d.ts +0 -1
- package/dist/datastar/attributes/style.js +0 -50
- package/dist/datastar/attributes/text.d.ts +0 -1
- package/dist/datastar/attributes/text.js +0 -26
- package/dist/datastar/engine.d.ts +0 -162
- package/dist/datastar/engine.js +0 -999
- package/dist/datastar/happydom.d.ts +0 -1
- package/dist/datastar/happydom.js +0 -8
- package/dist/datastar/index.d.ts +0 -24
- package/dist/datastar/index.js +0 -24
- package/dist/datastar/load.d.ts +0 -24
- package/dist/datastar/load.js +0 -24
- package/dist/datastar/utils.d.ts +0 -51
- package/dist/datastar/utils.js +0 -202
- package/dist/datastar/watchers/patchElements.d.ts +0 -1
- package/dist/datastar/watchers/patchElements.js +0 -399
- package/dist/datastar/watchers/patchSignals.d.ts +0 -1
- package/dist/datastar/watchers/patchSignals.js +0 -14
- package/dist/experimental/EncryptedCookies.d.ts +0 -48
- package/dist/experimental/EncryptedCookies.js +0 -212
- package/dist/experimental/SseHttpResponse.d.ts +0 -7
- package/dist/experimental/SseHttpResponse.js +0 -28
- package/dist/experimental/index.d.ts +0 -1
- package/dist/experimental/index.js +0 -1
- package/dist/hyper/Hyper.d.ts +0 -25
- package/dist/hyper/Hyper.js +0 -23
- package/dist/hyper/HyperHtml.d.ts +0 -23
- package/dist/hyper/HyperHtml.js +0 -150
- package/dist/hyper/HyperHtml.test.d.ts +0 -1
- package/dist/hyper/HyperHtml.test.js +0 -197
- package/dist/hyper/HyperNode.d.ts +0 -14
- package/dist/hyper/HyperNode.js +0 -11
- package/dist/hyper/HyperRoute.d.ts +0 -8
- package/dist/hyper/HyperRoute.js +0 -32
- package/dist/hyper/HyperRoute.test.d.ts +0 -1
- package/dist/hyper/HyperRoute.test.js +0 -83
- package/dist/hyper/html.d.ts +0 -11
- package/dist/hyper/html.js +0 -30
- package/dist/hyper/index.d.ts +0 -6
- package/dist/hyper/index.js +0 -5
- package/dist/hyper/jsx-runtime.d.ts +0 -7
- package/dist/hyper/jsx-runtime.js +0 -8
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -8
- package/dist/inference_check.d.ts +0 -1
- package/dist/inference_check.js +0 -15
- package/dist/lint/plugin.d.ts +0 -86
- package/dist/lint/plugin.js +0 -341
- package/dist/middlewares/BasicAuthMiddleware.d.ts +0 -8
- package/dist/middlewares/BasicAuthMiddleware.js +0 -22
- package/dist/middlewares/index.d.ts +0 -1
- package/dist/middlewares/index.js +0 -1
- package/dist/node/Effectify.d.ts +0 -209
- package/dist/node/Effectify.js +0 -19
- package/dist/node/FileSystem.d.ts +0 -7
- package/dist/node/FileSystem.js +0 -420
- package/dist/node/NodeFileSystem.d.ts +0 -7
- package/dist/node/NodeFileSystem.js +0 -410
- package/dist/node/NodeUtils.d.ts +0 -2
- package/dist/node/NodeUtils.js +0 -20
- package/dist/node/PlatformError.d.ts +0 -46
- package/dist/node/PlatformError.js +0 -43
- package/dist/node/Utils.d.ts +0 -1
- package/dist/node/Utils.js +0 -19
- package/dist/repro_fail.d.ts +0 -1
- package/dist/repro_fail.js +0 -14
- package/dist/sql/bun/index.d.ts +0 -3
- package/dist/sql/bun/index.js +0 -75
- package/dist/sql/mssql/docker.d.ts +0 -2
- package/dist/sql/mssql/docker.js +0 -67
- package/dist/sql/mssql/index.d.ts +0 -21
- package/dist/sql/mssql/index.js +0 -113
- package/dist/testing/TestHttpClient.d.ts +0 -13
- package/dist/testing/TestHttpClient.js +0 -68
- package/dist/testing/TestLogger.d.ts +0 -13
- package/dist/testing/TestLogger.js +0 -32
- package/dist/testing/index.d.ts +0 -2
- package/dist/testing/index.js +0 -2
- package/dist/testing/utils.d.ts +0 -9
- package/dist/testing/utils.js +0 -39
- package/dist/x/cloudflare/CloudflareTunnel.d.ts +0 -10
- package/dist/x/cloudflare/CloudflareTunnel.js +0 -30
- package/dist/x/cloudflare/index.d.ts +0 -1
- package/dist/x/cloudflare/index.js +0 -1
- package/dist/x/datastar/Datastar.d.ts +0 -6
- package/dist/x/datastar/Datastar.js +0 -47
- package/dist/x/datastar/index.d.ts +0 -1
- package/dist/x/datastar/index.js +0 -1
- package/dist/x/tailscale/TailscaleTunnel.d.ts +0 -15
- package/dist/x/tailscale/TailscaleTunnel.js +0 -68
- package/dist/x/tailscale/index.d.ts +0 -1
- package/dist/x/tailscale/index.js +0 -1
- package/dist/x/tailwind/TailwindPlugin.d.ts +0 -23
- package/dist/x/tailwind/TailwindPlugin.js +0 -219
- package/dist/x/tailwind/compile.d.ts +0 -19
- package/dist/x/tailwind/compile.js +0 -154
- package/dist/x/tailwind/plugin.d.ts +0 -2
- package/dist/x/tailwind/plugin.js +0 -15
- /package/src/{Sql.ts → sql/Sql.ts} +0 -0
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RFC 7231 Content Negotiation compatible with Express/Node.js ecosystem.
|
|
3
|
-
* Based on {@link https://github.com/jshttp/negotiator}
|
|
4
|
-
*/
|
|
5
|
-
const simpleMediaTypeRegExp = /^\s*([^\s/;]+)\/([^;\s]+)\s*(?:;(.*))?$/;
|
|
6
|
-
const simpleLanguageRegExp = /^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/;
|
|
7
|
-
const simpleEncodingRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/;
|
|
8
|
-
const simpleCharsetRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/;
|
|
9
|
-
function parseQuality(params) {
|
|
10
|
-
if (!params)
|
|
11
|
-
return 1;
|
|
12
|
-
const match = params.match(/q\s*=\s*([0-9.]+)/);
|
|
13
|
-
if (!match)
|
|
14
|
-
return 1;
|
|
15
|
-
const q = parseFloat(match[1]);
|
|
16
|
-
return isNaN(q) ? 1 : Math.min(Math.max(q, 0), 1);
|
|
17
|
-
}
|
|
18
|
-
function splitMediaTypeParams(params) {
|
|
19
|
-
const result = {};
|
|
20
|
-
let q = 1;
|
|
21
|
-
const parts = params.split(";");
|
|
22
|
-
for (const part of parts) {
|
|
23
|
-
const trimmed = part.trim();
|
|
24
|
-
const eqIndex = trimmed.indexOf("=");
|
|
25
|
-
if (eqIndex === -1)
|
|
26
|
-
continue;
|
|
27
|
-
const key = trimmed.slice(0, eqIndex).trim().toLowerCase();
|
|
28
|
-
let value = trimmed.slice(eqIndex + 1).trim();
|
|
29
|
-
if (value.startsWith('"') && value.endsWith('"')) {
|
|
30
|
-
value = value.slice(1, -1);
|
|
31
|
-
}
|
|
32
|
-
if (key === "q") {
|
|
33
|
-
q = parseFloat(value);
|
|
34
|
-
if (isNaN(q))
|
|
35
|
-
q = 1;
|
|
36
|
-
q = Math.min(Math.max(q, 0), 1);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
result[key] = value;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return { params: result, q };
|
|
43
|
-
}
|
|
44
|
-
function parseAccept(accept) {
|
|
45
|
-
const specs = [];
|
|
46
|
-
const parts = accept.split(",");
|
|
47
|
-
for (let o = 0; o < parts.length; o++) {
|
|
48
|
-
const part = parts[o].trim();
|
|
49
|
-
if (!part)
|
|
50
|
-
continue;
|
|
51
|
-
const match = simpleMediaTypeRegExp.exec(part);
|
|
52
|
-
if (!match)
|
|
53
|
-
continue;
|
|
54
|
-
const type = match[1].toLowerCase();
|
|
55
|
-
const subtype = match[2].toLowerCase();
|
|
56
|
-
const { params, q } = match[3] ? splitMediaTypeParams(match[3]) : { params: {}, q: 1 };
|
|
57
|
-
if (q > 0) {
|
|
58
|
-
specs.push({ type, subtype, params, q, o });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return specs;
|
|
62
|
-
}
|
|
63
|
-
function specifyMediaType(type, subtype, params, spec) {
|
|
64
|
-
let s = 0;
|
|
65
|
-
if (spec.type === type) {
|
|
66
|
-
s |= 4; // exact match: highest specificity
|
|
67
|
-
}
|
|
68
|
-
else if (type === "*") {
|
|
69
|
-
s |= 0; // server offers wildcard (e.g. */*): matches any client type
|
|
70
|
-
}
|
|
71
|
-
else if (spec.type !== "*") {
|
|
72
|
-
// client is NOT requesting wildcard: no match
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
// client requests wildcard (e.g. Accept: */*)
|
|
76
|
-
if (spec.subtype === subtype) {
|
|
77
|
-
s |= 2; // // exact match: highest specificity
|
|
78
|
-
}
|
|
79
|
-
else if (subtype === "*") {
|
|
80
|
-
s |= 1; // server offers wildcard (e.g. text/*)
|
|
81
|
-
}
|
|
82
|
-
else if (spec.subtype !== "*") {
|
|
83
|
-
return null; // client is NOT requesting wildcard
|
|
84
|
-
}
|
|
85
|
-
// client requests wildcard (e.g. Accept: text/*): matches any server subtype
|
|
86
|
-
const specParams = Object.keys(spec.params);
|
|
87
|
-
if (specParams.length > 0) {
|
|
88
|
-
if (specParams.every((key) => spec.params[key].toLowerCase() === (params[key] || "").toLowerCase())) {
|
|
89
|
-
s |= 1;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return { q: spec.q, s, o: spec.o };
|
|
96
|
-
}
|
|
97
|
-
function getMediaTypePriority(mediaType, accepted, index) {
|
|
98
|
-
let best = null;
|
|
99
|
-
const match = simpleMediaTypeRegExp.exec(mediaType);
|
|
100
|
-
if (!match) {
|
|
101
|
-
return { value: mediaType, q: 0, s: 0, o: -1, i: index };
|
|
102
|
-
}
|
|
103
|
-
const type = match[1].toLowerCase();
|
|
104
|
-
const subtype = match[2].toLowerCase();
|
|
105
|
-
const { params } = match[3] ? splitMediaTypeParams(match[3]) : { params: {} };
|
|
106
|
-
for (const spec of accepted) {
|
|
107
|
-
const result = specifyMediaType(type, subtype, params, spec);
|
|
108
|
-
if (result &&
|
|
109
|
-
(best === null ||
|
|
110
|
-
result.s > best.s ||
|
|
111
|
-
(result.s === best.s && result.q > best.q) ||
|
|
112
|
-
(result.s === best.s && result.q === best.q && result.o < best.o))) {
|
|
113
|
-
best = result;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
value: mediaType,
|
|
118
|
-
q: best?.q ?? 0,
|
|
119
|
-
s: best?.s ?? 0,
|
|
120
|
-
o: best?.o ?? -1,
|
|
121
|
-
i: index,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function parseAcceptLanguage(accept) {
|
|
125
|
-
const specs = [];
|
|
126
|
-
const parts = accept.split(",");
|
|
127
|
-
for (let o = 0; o < parts.length; o++) {
|
|
128
|
-
const part = parts[o].trim();
|
|
129
|
-
if (!part)
|
|
130
|
-
continue;
|
|
131
|
-
const match = simpleLanguageRegExp.exec(part);
|
|
132
|
-
if (!match)
|
|
133
|
-
continue;
|
|
134
|
-
const prefix = match[1].toLowerCase();
|
|
135
|
-
const suffix = match[2]?.toLowerCase();
|
|
136
|
-
const q = parseQuality(match[3]);
|
|
137
|
-
if (q > 0) {
|
|
138
|
-
specs.push({ prefix, suffix, q, o });
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return specs;
|
|
142
|
-
}
|
|
143
|
-
function specifyLanguage(language, spec) {
|
|
144
|
-
const match = simpleLanguageRegExp.exec(language);
|
|
145
|
-
if (!match)
|
|
146
|
-
return null;
|
|
147
|
-
const prefix = match[1].toLowerCase();
|
|
148
|
-
const suffix = match[2]?.toLowerCase();
|
|
149
|
-
if (spec.prefix === "*") {
|
|
150
|
-
return { q: spec.q, s: 0, o: spec.o };
|
|
151
|
-
}
|
|
152
|
-
if (spec.prefix !== prefix) {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
if (spec.suffix === undefined) {
|
|
156
|
-
return { q: spec.q, s: suffix ? 2 : 4, o: spec.o };
|
|
157
|
-
}
|
|
158
|
-
if (spec.suffix === suffix) {
|
|
159
|
-
return { q: spec.q, s: 4, o: spec.o };
|
|
160
|
-
}
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
function getLanguagePriority(language, accepted, index) {
|
|
164
|
-
let best = null;
|
|
165
|
-
for (const spec of accepted) {
|
|
166
|
-
const result = specifyLanguage(language, spec);
|
|
167
|
-
if (result &&
|
|
168
|
-
(best === null ||
|
|
169
|
-
result.s > best.s ||
|
|
170
|
-
(result.s === best.s && result.q > best.q) ||
|
|
171
|
-
(result.s === best.s && result.q === best.q && result.o < best.o))) {
|
|
172
|
-
best = result;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return {
|
|
176
|
-
value: language,
|
|
177
|
-
q: best?.q ?? 0,
|
|
178
|
-
s: best?.s ?? 0,
|
|
179
|
-
o: best?.o ?? -1,
|
|
180
|
-
i: index,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function parseAcceptEncoding(accept) {
|
|
184
|
-
const specs = [];
|
|
185
|
-
const parts = accept.split(",");
|
|
186
|
-
let hasIdentity = false;
|
|
187
|
-
for (let o = 0; o < parts.length; o++) {
|
|
188
|
-
const part = parts[o].trim();
|
|
189
|
-
if (!part)
|
|
190
|
-
continue;
|
|
191
|
-
const match = simpleEncodingRegExp.exec(part);
|
|
192
|
-
if (!match)
|
|
193
|
-
continue;
|
|
194
|
-
const encoding = match[1].toLowerCase();
|
|
195
|
-
const q = parseQuality(match[2]);
|
|
196
|
-
if (encoding === "identity")
|
|
197
|
-
hasIdentity = true;
|
|
198
|
-
if (encoding === "*")
|
|
199
|
-
hasIdentity = true;
|
|
200
|
-
if (q > 0) {
|
|
201
|
-
specs.push({ encoding, q, o });
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (!hasIdentity) {
|
|
205
|
-
specs.push({ encoding: "identity", q: 0.0001, o: specs.length });
|
|
206
|
-
}
|
|
207
|
-
return specs;
|
|
208
|
-
}
|
|
209
|
-
function specifyEncoding(encoding, spec) {
|
|
210
|
-
const e = encoding.toLowerCase();
|
|
211
|
-
const s = spec.encoding;
|
|
212
|
-
if (s === "*" || s === e) {
|
|
213
|
-
return { q: spec.q, s: s === e ? 1 : 0, o: spec.o };
|
|
214
|
-
}
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
function getEncodingPriority(encoding, accepted, index) {
|
|
218
|
-
let best = null;
|
|
219
|
-
for (const spec of accepted) {
|
|
220
|
-
const result = specifyEncoding(encoding, spec);
|
|
221
|
-
if (result &&
|
|
222
|
-
(best === null ||
|
|
223
|
-
result.s > best.s ||
|
|
224
|
-
(result.s === best.s && result.q > best.q) ||
|
|
225
|
-
(result.s === best.s && result.q === best.q && result.o < best.o))) {
|
|
226
|
-
best = result;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return {
|
|
230
|
-
value: encoding,
|
|
231
|
-
q: best?.q ?? 0,
|
|
232
|
-
s: best?.s ?? 0,
|
|
233
|
-
o: best?.o ?? -1,
|
|
234
|
-
i: index,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
function parseAcceptCharset(accept) {
|
|
238
|
-
const specs = [];
|
|
239
|
-
const parts = accept.split(",");
|
|
240
|
-
for (let o = 0; o < parts.length; o++) {
|
|
241
|
-
const part = parts[o].trim();
|
|
242
|
-
if (!part)
|
|
243
|
-
continue;
|
|
244
|
-
const match = simpleCharsetRegExp.exec(part);
|
|
245
|
-
if (!match)
|
|
246
|
-
continue;
|
|
247
|
-
const charset = match[1].toLowerCase();
|
|
248
|
-
const q = parseQuality(match[2]);
|
|
249
|
-
if (q > 0) {
|
|
250
|
-
specs.push({ charset, q, o });
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return specs;
|
|
254
|
-
}
|
|
255
|
-
function specifyCharset(charset, spec) {
|
|
256
|
-
const c = charset.toLowerCase();
|
|
257
|
-
const s = spec.charset;
|
|
258
|
-
if (s === "*" || s === c) {
|
|
259
|
-
return { q: spec.q, s: s === c ? 1 : 0, o: spec.o };
|
|
260
|
-
}
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
function getCharsetPriority(charset, accepted, index) {
|
|
264
|
-
let best = null;
|
|
265
|
-
for (const spec of accepted) {
|
|
266
|
-
const result = specifyCharset(charset, spec);
|
|
267
|
-
if (result &&
|
|
268
|
-
(best === null ||
|
|
269
|
-
result.s > best.s ||
|
|
270
|
-
(result.s === best.s && result.q > best.q) ||
|
|
271
|
-
(result.s === best.s && result.q === best.q && result.o < best.o))) {
|
|
272
|
-
best = result;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return {
|
|
276
|
-
value: charset,
|
|
277
|
-
q: best?.q ?? 0,
|
|
278
|
-
s: best?.s ?? 0,
|
|
279
|
-
o: best?.o ?? -1,
|
|
280
|
-
i: index,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
function compareSpecs(a, b) {
|
|
284
|
-
return b.q - a.q || b.s - a.s || a.o - b.o || a.i - b.i;
|
|
285
|
-
}
|
|
286
|
-
export function media(accept, available) {
|
|
287
|
-
const parsed = parseAccept(accept);
|
|
288
|
-
if (parsed.length === 0) {
|
|
289
|
-
return [];
|
|
290
|
-
}
|
|
291
|
-
if (!available) {
|
|
292
|
-
return parsed.sort((a, b) => b.q - a.q || a.o - b.o).map((p) => `${p.type}/${p.subtype}`);
|
|
293
|
-
}
|
|
294
|
-
const priorities = available.map((t, i) => getMediaTypePriority(t, parsed, i));
|
|
295
|
-
const sorted = priorities.filter((p) => p.q > 0).sort(compareSpecs);
|
|
296
|
-
return sorted.map((p) => p.value);
|
|
297
|
-
}
|
|
298
|
-
export function language(accept, available) {
|
|
299
|
-
const parsed = parseAcceptLanguage(accept);
|
|
300
|
-
if (parsed.length === 0) {
|
|
301
|
-
return [];
|
|
302
|
-
}
|
|
303
|
-
if (!available) {
|
|
304
|
-
return parsed
|
|
305
|
-
.sort((a, b) => b.q - a.q || a.o - b.o)
|
|
306
|
-
.map((p) => (p.suffix ? `${p.prefix}-${p.suffix}` : p.prefix));
|
|
307
|
-
}
|
|
308
|
-
const priorities = available.map((l, i) => getLanguagePriority(l, parsed, i));
|
|
309
|
-
const sorted = priorities.filter((p) => p.q > 0).sort(compareSpecs);
|
|
310
|
-
return sorted.map((p) => p.value);
|
|
311
|
-
}
|
|
312
|
-
export function encoding(accept, available) {
|
|
313
|
-
const parsed = parseAcceptEncoding(accept);
|
|
314
|
-
if (parsed.length === 0) {
|
|
315
|
-
return [];
|
|
316
|
-
}
|
|
317
|
-
if (!available) {
|
|
318
|
-
return parsed.sort((a, b) => b.q - a.q || a.o - b.o).map((p) => p.encoding);
|
|
319
|
-
}
|
|
320
|
-
const priorities = available.map((e, i) => getEncodingPriority(e, parsed, i));
|
|
321
|
-
const sorted = priorities.filter((p) => p.q > 0).sort(compareSpecs);
|
|
322
|
-
return sorted.map((p) => p.value);
|
|
323
|
-
}
|
|
324
|
-
export function charset(accept, available) {
|
|
325
|
-
const parsed = parseAcceptCharset(accept);
|
|
326
|
-
if (parsed.length === 0) {
|
|
327
|
-
return [];
|
|
328
|
-
}
|
|
329
|
-
if (!available) {
|
|
330
|
-
return parsed.sort((a, b) => b.q - a.q || a.o - b.o).map((p) => p.charset);
|
|
331
|
-
}
|
|
332
|
-
const priorities = available.map((c, i) => getCharsetPriority(c, parsed, i));
|
|
333
|
-
const sorted = priorities.filter((p) => p.q > 0).sort(compareSpecs);
|
|
334
|
-
return sorted.map((p) => p.value);
|
|
335
|
-
}
|
|
336
|
-
export function headerMedia(headers, available) {
|
|
337
|
-
const accept = headers.get("accept");
|
|
338
|
-
if (!accept)
|
|
339
|
-
return [];
|
|
340
|
-
return media(accept, available);
|
|
341
|
-
}
|
|
342
|
-
export function headerLanguage(headers, available) {
|
|
343
|
-
const accept = headers.get("accept-language");
|
|
344
|
-
if (!accept)
|
|
345
|
-
return [];
|
|
346
|
-
return language(accept, available);
|
|
347
|
-
}
|
|
348
|
-
export function headerEncoding(headers, available) {
|
|
349
|
-
const accept = headers.get("accept-encoding");
|
|
350
|
-
if (!accept)
|
|
351
|
-
return [];
|
|
352
|
-
return encoding(accept, available);
|
|
353
|
-
}
|
|
354
|
-
export function headerCharset(headers, available) {
|
|
355
|
-
const accept = headers.get("accept-charset");
|
|
356
|
-
if (!accept)
|
|
357
|
-
return [];
|
|
358
|
-
return charset(accept, available);
|
|
359
|
-
}
|
package/dist/Cookies.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as Duration from "effect/Duration";
|
|
2
|
-
import * as Inspectable from "effect/Inspectable";
|
|
3
|
-
import * as Option from "effect/Option";
|
|
4
|
-
import * as Pipeable from "effect/Pipeable";
|
|
5
|
-
export declare const TypeId: unique symbol;
|
|
6
|
-
export type TypeId = typeof TypeId;
|
|
7
|
-
export declare const isCookies: (u: unknown) => u is Cookies;
|
|
8
|
-
export interface Cookies extends Pipeable.Pipeable, Inspectable.Inspectable {
|
|
9
|
-
readonly [TypeId]: TypeId;
|
|
10
|
-
readonly cookies: Record<string, Cookie>;
|
|
11
|
-
}
|
|
12
|
-
export declare const CookieTypeId: unique symbol;
|
|
13
|
-
export type CookieTypeId = typeof CookieTypeId;
|
|
14
|
-
export interface Cookie extends Inspectable.Inspectable {
|
|
15
|
-
readonly [CookieTypeId]: CookieTypeId;
|
|
16
|
-
readonly name: string;
|
|
17
|
-
readonly value: string;
|
|
18
|
-
readonly valueEncoded: string;
|
|
19
|
-
readonly options?: {
|
|
20
|
-
readonly domain?: string | undefined;
|
|
21
|
-
readonly expires?: Date | undefined;
|
|
22
|
-
readonly maxAge?: Duration.DurationInput | undefined;
|
|
23
|
-
readonly path?: string | undefined;
|
|
24
|
-
readonly priority?: "low" | "medium" | "high" | undefined;
|
|
25
|
-
readonly httpOnly?: boolean | undefined;
|
|
26
|
-
readonly secure?: boolean | undefined;
|
|
27
|
-
readonly partitioned?: boolean | undefined;
|
|
28
|
-
readonly sameSite?: "lax" | "strict" | "none" | undefined;
|
|
29
|
-
} | undefined;
|
|
30
|
-
}
|
|
31
|
-
export declare const empty: Cookies;
|
|
32
|
-
export declare const fromIterable: (cookies: Iterable<Cookie>) => Cookies;
|
|
33
|
-
export declare const fromSetCookie: (headers: Iterable<string> | string) => Cookies;
|
|
34
|
-
export declare const unsafeMakeCookie: (name: string, value: string, options?: Cookie["options"] | undefined) => Cookie;
|
|
35
|
-
export declare const isEmpty: (self: Cookies) => boolean;
|
|
36
|
-
export declare const get: (self: Cookies, name: string) => Option.Option<Cookie>;
|
|
37
|
-
export declare const getValue: (self: Cookies, name: string) => Option.Option<string>;
|
|
38
|
-
export declare const setCookie: (self: Cookies, cookie: Cookie) => Cookies;
|
|
39
|
-
export declare const unsafeSet: (self: Cookies, name: string, value: string, options?: Cookie["options"]) => Cookies;
|
|
40
|
-
export declare const unsafeSetAll: (self: Cookies, cookies: Iterable<readonly [name: string, value: string, options?: Cookie["options"]]>) => Cookies;
|
|
41
|
-
export declare const remove: (self: Cookies, name: string) => Cookies;
|
|
42
|
-
export declare const merge: (self: Cookies, that: Cookies) => Cookies;
|
|
43
|
-
export declare function serializeCookie(self: Cookie): string;
|
|
44
|
-
export declare const toCookieHeader: (self: Cookies) => string;
|
|
45
|
-
export declare const toRecord: (self: Cookies) => Record<string, string>;
|
|
46
|
-
export declare const toSetCookieHeaders: (self: Cookies) => Array<string>;
|
|
47
|
-
export declare function parseHeader(header: string): Record<string, string>;
|
package/dist/Cookies.js
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Minimal Cookies management adapted from @effect/platform
|
|
3
|
-
* We'll aim for full compatbility when it stabilizes.
|
|
4
|
-
*/
|
|
5
|
-
import * as Duration from "effect/Duration";
|
|
6
|
-
import * as Inspectable from "effect/Inspectable";
|
|
7
|
-
import * as Option from "effect/Option";
|
|
8
|
-
import * as Pipeable from "effect/Pipeable";
|
|
9
|
-
import * as Predicate from "effect/Predicate";
|
|
10
|
-
export const TypeId = Symbol.for("effect-start/Cookies");
|
|
11
|
-
export const isCookies = (u) => Predicate.hasProperty(u, TypeId);
|
|
12
|
-
export const CookieTypeId = Symbol.for("effect-start/Cookies/Cookie");
|
|
13
|
-
const CookiesProto = {
|
|
14
|
-
[TypeId]: TypeId,
|
|
15
|
-
...Inspectable.BaseProto,
|
|
16
|
-
toJSON() {
|
|
17
|
-
return {
|
|
18
|
-
_id: "effect-start/Cookies",
|
|
19
|
-
cookies: Object.fromEntries(Object.entries(this.cookies).map(([k, v]) => [k, v.toJSON()])),
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
pipe() {
|
|
23
|
-
return Pipeable.pipeArguments(this, arguments);
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
const CookieProto = {
|
|
27
|
-
[CookieTypeId]: CookieTypeId,
|
|
28
|
-
...Inspectable.BaseProto,
|
|
29
|
-
toJSON() {
|
|
30
|
-
return {
|
|
31
|
-
_id: "effect-start/Cookies/Cookie",
|
|
32
|
-
name: this.name,
|
|
33
|
-
value: this.value,
|
|
34
|
-
options: this.options,
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
const makeCookiesFromRecord = (cookies) => {
|
|
39
|
-
const self = Object.create(CookiesProto);
|
|
40
|
-
self.cookies = cookies;
|
|
41
|
-
return self;
|
|
42
|
-
};
|
|
43
|
-
const cookieFromParts = (name, value, valueEncoded, options) => Object.assign(Object.create(CookieProto), {
|
|
44
|
-
name,
|
|
45
|
-
value,
|
|
46
|
-
valueEncoded,
|
|
47
|
-
options,
|
|
48
|
-
});
|
|
49
|
-
export const empty = makeCookiesFromRecord({});
|
|
50
|
-
export const fromIterable = (cookies) => {
|
|
51
|
-
const record = {};
|
|
52
|
-
for (const cookie of cookies) {
|
|
53
|
-
record[cookie.name] = cookie;
|
|
54
|
-
}
|
|
55
|
-
return makeCookiesFromRecord(record);
|
|
56
|
-
};
|
|
57
|
-
export const fromSetCookie = (headers) => {
|
|
58
|
-
const arrayHeaders = typeof headers === "string" ? [headers] : headers;
|
|
59
|
-
const cookies = [];
|
|
60
|
-
for (const header of arrayHeaders) {
|
|
61
|
-
const cookie = parseSetCookie(header.trim());
|
|
62
|
-
if (Option.isSome(cookie)) {
|
|
63
|
-
cookies.push(cookie.value);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return fromIterable(cookies);
|
|
67
|
-
};
|
|
68
|
-
export const unsafeMakeCookie = (name, value, options) => cookieFromParts(name, value, encodeURIComponent(value), options);
|
|
69
|
-
export const isEmpty = (self) => {
|
|
70
|
-
for (const _ in self.cookies)
|
|
71
|
-
return false;
|
|
72
|
-
return true;
|
|
73
|
-
};
|
|
74
|
-
export const get = (self, name) => name in self.cookies ? Option.some(self.cookies[name]) : Option.none();
|
|
75
|
-
export const getValue = (self, name) => Option.map(get(self, name), (cookie) => cookie.value);
|
|
76
|
-
export const setCookie = (self, cookie) => makeCookiesFromRecord({ ...self.cookies, [cookie.name]: cookie });
|
|
77
|
-
export const unsafeSet = (self, name, value, options) => setCookie(self, unsafeMakeCookie(name, value, options));
|
|
78
|
-
export const unsafeSetAll = (self, cookies) => {
|
|
79
|
-
const record = { ...self.cookies };
|
|
80
|
-
for (const [name, value, options] of cookies) {
|
|
81
|
-
record[name] = unsafeMakeCookie(name, value, options);
|
|
82
|
-
}
|
|
83
|
-
return makeCookiesFromRecord(record);
|
|
84
|
-
};
|
|
85
|
-
export const remove = (self, name) => {
|
|
86
|
-
const { [name]: _, ...rest } = self.cookies;
|
|
87
|
-
return makeCookiesFromRecord(rest);
|
|
88
|
-
};
|
|
89
|
-
export const merge = (self, that) => makeCookiesFromRecord({ ...self.cookies, ...that.cookies });
|
|
90
|
-
export function serializeCookie(self) {
|
|
91
|
-
let str = self.name + "=" + self.valueEncoded;
|
|
92
|
-
if (self.options === undefined) {
|
|
93
|
-
return str;
|
|
94
|
-
}
|
|
95
|
-
const options = self.options;
|
|
96
|
-
if (options.maxAge !== undefined) {
|
|
97
|
-
const maxAge = Duration.toSeconds(options.maxAge);
|
|
98
|
-
str += "; Max-Age=" + Math.trunc(maxAge);
|
|
99
|
-
}
|
|
100
|
-
if (options.domain !== undefined) {
|
|
101
|
-
str += "; Domain=" + options.domain;
|
|
102
|
-
}
|
|
103
|
-
if (options.path !== undefined) {
|
|
104
|
-
str += "; Path=" + options.path;
|
|
105
|
-
}
|
|
106
|
-
if (options.priority !== undefined) {
|
|
107
|
-
switch (options.priority) {
|
|
108
|
-
case "low":
|
|
109
|
-
str += "; Priority=Low";
|
|
110
|
-
break;
|
|
111
|
-
case "medium":
|
|
112
|
-
str += "; Priority=Medium";
|
|
113
|
-
break;
|
|
114
|
-
case "high":
|
|
115
|
-
str += "; Priority=High";
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (options.expires !== undefined) {
|
|
120
|
-
str += "; Expires=" + options.expires.toUTCString();
|
|
121
|
-
}
|
|
122
|
-
if (options.httpOnly) {
|
|
123
|
-
str += "; HttpOnly";
|
|
124
|
-
}
|
|
125
|
-
if (options.secure) {
|
|
126
|
-
str += "; Secure";
|
|
127
|
-
}
|
|
128
|
-
if (options.partitioned) {
|
|
129
|
-
str += "; Partitioned";
|
|
130
|
-
}
|
|
131
|
-
if (options.sameSite !== undefined) {
|
|
132
|
-
switch (options.sameSite) {
|
|
133
|
-
case "lax":
|
|
134
|
-
str += "; SameSite=Lax";
|
|
135
|
-
break;
|
|
136
|
-
case "strict":
|
|
137
|
-
str += "; SameSite=Strict";
|
|
138
|
-
break;
|
|
139
|
-
case "none":
|
|
140
|
-
str += "; SameSite=None";
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return str;
|
|
145
|
-
}
|
|
146
|
-
export const toCookieHeader = (self) => Object.values(self.cookies)
|
|
147
|
-
.map((cookie) => `${cookie.name}=${cookie.valueEncoded}`)
|
|
148
|
-
.join("; ");
|
|
149
|
-
export const toRecord = (self) => {
|
|
150
|
-
const record = {};
|
|
151
|
-
for (const cookie of Object.values(self.cookies)) {
|
|
152
|
-
record[cookie.name] = cookie.value;
|
|
153
|
-
}
|
|
154
|
-
return record;
|
|
155
|
-
};
|
|
156
|
-
export const toSetCookieHeaders = (self) => Object.values(self.cookies).map(serializeCookie);
|
|
157
|
-
export function parseHeader(header) {
|
|
158
|
-
const result = {};
|
|
159
|
-
const strLen = header.length;
|
|
160
|
-
let pos = 0;
|
|
161
|
-
let terminatorPos = 0;
|
|
162
|
-
while (true) {
|
|
163
|
-
if (terminatorPos === strLen)
|
|
164
|
-
break;
|
|
165
|
-
terminatorPos = header.indexOf(";", pos);
|
|
166
|
-
if (terminatorPos === -1)
|
|
167
|
-
terminatorPos = strLen;
|
|
168
|
-
let eqIdx = header.indexOf("=", pos);
|
|
169
|
-
if (eqIdx === -1)
|
|
170
|
-
break;
|
|
171
|
-
if (eqIdx > terminatorPos) {
|
|
172
|
-
pos = terminatorPos + 1;
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
const key = header.substring(pos, eqIdx++).trim();
|
|
176
|
-
if (result[key] === undefined) {
|
|
177
|
-
const val = header.charCodeAt(eqIdx) === 0x22
|
|
178
|
-
? header.substring(eqIdx + 1, terminatorPos - 1).trim()
|
|
179
|
-
: header.substring(eqIdx, terminatorPos).trim();
|
|
180
|
-
result[key] = !(val.indexOf("%") === -1) ? tryDecodeURIComponent(val) : val;
|
|
181
|
-
}
|
|
182
|
-
pos = terminatorPos + 1;
|
|
183
|
-
}
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
|
-
// eslint-disable-next-line no-control-regex
|
|
187
|
-
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
188
|
-
function parseSetCookie(header) {
|
|
189
|
-
const parts = header
|
|
190
|
-
.split(";")
|
|
191
|
-
.map((_) => _.trim())
|
|
192
|
-
.filter((_) => _ !== "");
|
|
193
|
-
if (parts.length === 0) {
|
|
194
|
-
return Option.none();
|
|
195
|
-
}
|
|
196
|
-
const firstEqual = parts[0].indexOf("=");
|
|
197
|
-
if (firstEqual === -1) {
|
|
198
|
-
return Option.none();
|
|
199
|
-
}
|
|
200
|
-
const name = parts[0].slice(0, firstEqual);
|
|
201
|
-
if (!fieldContentRegExp.test(name)) {
|
|
202
|
-
return Option.none();
|
|
203
|
-
}
|
|
204
|
-
const valueEncoded = parts[0].slice(firstEqual + 1);
|
|
205
|
-
const value = tryDecodeURIComponent(valueEncoded);
|
|
206
|
-
if (parts.length === 1) {
|
|
207
|
-
return Option.some(cookieFromParts(name, value, valueEncoded));
|
|
208
|
-
}
|
|
209
|
-
const options = {};
|
|
210
|
-
for (let i = 1; i < parts.length; i++) {
|
|
211
|
-
const part = parts[i];
|
|
212
|
-
const equalIndex = part.indexOf("=");
|
|
213
|
-
const key = equalIndex === -1 ? part : part.slice(0, equalIndex).trim();
|
|
214
|
-
const value = equalIndex === -1 ? undefined : part.slice(equalIndex + 1).trim();
|
|
215
|
-
switch (key.toLowerCase()) {
|
|
216
|
-
case "domain": {
|
|
217
|
-
if (value === undefined)
|
|
218
|
-
break;
|
|
219
|
-
const domain = value.trim().replace(/^\./, "");
|
|
220
|
-
if (domain)
|
|
221
|
-
options.domain = domain;
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
case "expires": {
|
|
225
|
-
if (value === undefined)
|
|
226
|
-
break;
|
|
227
|
-
const date = new Date(value);
|
|
228
|
-
if (!isNaN(date.getTime()))
|
|
229
|
-
options.expires = date;
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
case "max-age": {
|
|
233
|
-
if (value === undefined)
|
|
234
|
-
break;
|
|
235
|
-
const maxAge = parseInt(value, 10);
|
|
236
|
-
if (!isNaN(maxAge))
|
|
237
|
-
options.maxAge = Duration.seconds(maxAge);
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
case "path": {
|
|
241
|
-
if (value === undefined)
|
|
242
|
-
break;
|
|
243
|
-
if (value[0] === "/")
|
|
244
|
-
options.path = value;
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
case "priority": {
|
|
248
|
-
if (value === undefined)
|
|
249
|
-
break;
|
|
250
|
-
switch (value.toLowerCase()) {
|
|
251
|
-
case "low":
|
|
252
|
-
options.priority = "low";
|
|
253
|
-
break;
|
|
254
|
-
case "medium":
|
|
255
|
-
options.priority = "medium";
|
|
256
|
-
break;
|
|
257
|
-
case "high":
|
|
258
|
-
options.priority = "high";
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
case "httponly": {
|
|
264
|
-
options.httpOnly = true;
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
case "secure": {
|
|
268
|
-
options.secure = true;
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
case "partitioned": {
|
|
272
|
-
options.partitioned = true;
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
case "samesite": {
|
|
276
|
-
if (value === undefined)
|
|
277
|
-
break;
|
|
278
|
-
switch (value.toLowerCase()) {
|
|
279
|
-
case "lax":
|
|
280
|
-
options.sameSite = "lax";
|
|
281
|
-
break;
|
|
282
|
-
case "strict":
|
|
283
|
-
options.sameSite = "strict";
|
|
284
|
-
break;
|
|
285
|
-
case "none":
|
|
286
|
-
options.sameSite = "none";
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return Option.some(cookieFromParts(name, value, valueEncoded, Object.keys(options).length > 0 ? options : undefined));
|
|
294
|
-
}
|
|
295
|
-
const tryDecodeURIComponent = (str) => {
|
|
296
|
-
try {
|
|
297
|
-
return decodeURIComponent(str);
|
|
298
|
-
}
|
|
299
|
-
catch {
|
|
300
|
-
return str;
|
|
301
|
-
}
|
|
302
|
-
};
|