@typed/ui 0.7.0 → 0.8.1

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.
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/Platform.js",
3
+ "module": "../dist/esm/Platform.js",
4
+ "types": "../dist/dts/Platform.d.ts",
5
+ "sideEffects": []
6
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.GuardsNotMatched = void 0;
7
+ exports.toHttpRouter = toHttpRouter;
8
+ var HttpServer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/HttpServer"));
9
+ var _Platform = /*#__PURE__*/require("@typed/template/Platform");
10
+ var _effect = /*#__PURE__*/require("effect");
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
+ /**
14
+ * @since 1.0.0
15
+ */
16
+
17
+ /**
18
+ * @since 1.0.0
19
+ */
20
+ class GuardsNotMatched extends _effect.Data.TaggedError("@typed/router/GuardsNotMatched") {}
21
+ /**
22
+ * @since 1.0.0
23
+ */
24
+ exports.GuardsNotMatched = GuardsNotMatched;
25
+ function toHttpRouter(matcher) {
26
+ let router = HttpServer.router.empty;
27
+ const guardsByPath = _effect.ReadonlyArray.groupBy(matcher.guards, guard => guard.route.path);
28
+ for (const [path, guards] of Object.entries(guardsByPath)) {
29
+ router = HttpServer.router.get(router, path, _effect.Effect.gen(function* (_) {
30
+ // Attempt to match a guard
31
+ for (const guard of guards) {
32
+ const match = yield* _(guard.guard(path));
33
+ if (_effect.Option.isSome(match)) {
34
+ const renderable = guard.match(match.value);
35
+ return yield* _((0, _Platform.htmlResponse)(renderable));
36
+ }
37
+ }
38
+ const request = yield* _(HttpServer.request.ServerRequest);
39
+ return yield* _(_effect.Effect.fail(new GuardsNotMatched({
40
+ request,
41
+ guards
42
+ })));
43
+ }));
44
+ }
45
+ return router;
46
+ }
47
+ //# sourceMappingURL=Platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.js","names":["HttpServer","_interopRequireWildcard","require","_Platform","_effect","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","GuardsNotMatched","Data","TaggedError","exports","toHttpRouter","matcher","router","empty","guardsByPath","ReadonlyArray","groupBy","guards","guard","route","path","entries","Effect","gen","_","match","Option","isSome","renderable","value","htmlResponse","request","ServerRequest","fail"],"sources":["../../src/Platform.ts"],"sourcesContent":[null],"mappings":";;;;;;;AAMA,IAAAA,UAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAGA,IAAAC,SAAA,gBAAAD,OAAA;AAIA,IAAAE,OAAA,gBAAAF,OAAA;AAA4D,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,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P,YAAY,CAAC,EAAE;IACzDF,MAAM,GAAGhC,UAAU,CAACgC,MAAM,CAACnB,GAAG,CAC5BmB,MAAM,EACNQ,IAAiB,EACjBE,cAAM,CAACC,GAAG,CAAC,WAAUC,CAAC;MACpB;MACA,KAAK,MAAMN,KAAK,IAAID,MAAM,EAAE;QAC1B,MAAMQ,KAAK,GAAG,OAAOD,CAAC,CAACN,KAAK,CAACA,KAAK,CAACE,IAAI,CAAC,CAAC;QACzC,IAAIM,cAAM,CAACC,MAAM,CAACF,KAAK,CAAC,EAAE;UACxB,MAAMG,UAAU,GAAGV,KAAK,CAACO,KAAK,CAACA,KAAK,CAACI,KAAK,CAAC;UAC3C,OAAO,OAAOL,CAAC,CAAC,IAAAM,sBAAY,EAACF,UAAU,CAAC,CAAC;QAC3C;MACF;MACA,MAAMG,OAAO,GAAG,OAAOP,CAAC,CAAC5C,UAAU,CAACmD,OAAO,CAACC,aAAa,CAAC;MAC1D,OAAO,OAAOR,CAAC,CAACF,cAAM,CAACW,IAAI,CAAC,IAAI3B,gBAAgB,CAAC;QAAEyB,OAAO;QAAEd;MAAM,CAAE,CAAC,CAAC,CAAC;IACzE,CAAC,CAAC,CACH;EACH;EAEA,OAAOL,MAAM;AACf"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type { ServerRequest } from "@effect/platform/Http/ServerRequest";
5
+ import * as HttpServer from "@effect/platform/HttpServer";
6
+ import type { RouteGuard, RouteMatcher } from "@typed/router";
7
+ import type { RenderContext, RenderTemplate } from "@typed/template";
8
+ import type { RenderEvent } from "@typed/template/RenderEvent";
9
+ import type { Scope } from "effect";
10
+ import { ReadonlyArray } from "effect";
11
+ declare const GuardsNotMatched_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
12
+ readonly _tag: "@typed/router/GuardsNotMatched";
13
+ } & Readonly<A>;
14
+ /**
15
+ * @since 1.0.0
16
+ */
17
+ export declare class GuardsNotMatched extends GuardsNotMatched_base<{
18
+ readonly request: HttpServer.request.ServerRequest;
19
+ readonly guards: ReadonlyArray.NonEmptyReadonlyArray<RouteGuard<any, any, any, any, any, any, any>>;
20
+ }> {
21
+ }
22
+ /**
23
+ * @since 1.0.0
24
+ */
25
+ export declare function toHttpRouter<E, R>(matcher: RouteMatcher<RenderEvent, E, R>): HttpServer.router.Router<R | RenderTemplate | RenderContext.RenderContext | ServerRequest | Scope.Scope, E | GuardsNotMatched>;
26
+ export {};
27
+ //# sourceMappingURL=Platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/Platform.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,KAAK,UAAU,MAAM,6BAA6B,CAAA;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAE9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAwB,aAAa,EAAE,MAAM,QAAQ,CAAA;;;;AAE5D;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,sBAAmD;IACvF,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,aAAa,CAAA;IAClD,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,qBAAqB,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;CACpG,CAAC;CAAG;AAEL;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,OAAO,EAAE,YAAY,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC,GACvC,UAAU,CAAC,MAAM,CAAC,MAAM,CACzB,CAAC,GAAG,cAAc,GAAG,aAAa,CAAC,aAAa,GAAG,aAAa,GAAG,KAAK,CAAC,KAAK,EAC9E,CAAC,GAAG,gBAAgB,CACrB,CA2BA"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as HttpServer from "@effect/platform/HttpServer";
5
+ import { htmlResponse } from "@typed/template/Platform";
6
+ import { Data, Effect, Option, ReadonlyArray } from "effect";
7
+ /**
8
+ * @since 1.0.0
9
+ */
10
+ export class GuardsNotMatched extends Data.TaggedError("@typed/router/GuardsNotMatched") {
11
+ }
12
+ /**
13
+ * @since 1.0.0
14
+ */
15
+ export function toHttpRouter(matcher) {
16
+ let router = HttpServer.router.empty;
17
+ const guardsByPath = ReadonlyArray.groupBy(matcher.guards, (guard) => guard.route.path);
18
+ for (const [path, guards] of Object.entries(guardsByPath)) {
19
+ router = HttpServer.router.get(router, path, Effect.gen(function* (_) {
20
+ // Attempt to match a guard
21
+ for (const guard of guards) {
22
+ const match = yield* _(guard.guard(path));
23
+ if (Option.isSome(match)) {
24
+ const renderable = guard.match(match.value);
25
+ return yield* _(htmlResponse(renderable));
26
+ }
27
+ }
28
+ const request = yield* _(HttpServer.request.ServerRequest);
29
+ return yield* _(Effect.fail(new GuardsNotMatched({ request, guards })));
30
+ }));
31
+ }
32
+ return router;
33
+ }
34
+ //# sourceMappingURL=Platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../src/Platform.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,UAAU,MAAM,6BAA6B,CAAA;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAIvD,OAAO,EAAE,IAAI,EAAE,MAA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,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAA;QACzE,CAAC,CAAC,CACH,CAAA;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typed/ui",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,11 +17,11 @@
17
17
  "@typed/context": "0.24.1",
18
18
  "@typed/dom": "12.0.1",
19
19
  "@typed/environment": "0.6.1",
20
- "@typed/fx": "1.24.0",
21
- "@typed/navigation": "0.12.0",
22
- "@typed/route": "3.2.1",
23
- "@typed/router": "0.25.0",
24
- "@typed/template": "0.7.0"
20
+ "@typed/fx": "1.25.0",
21
+ "@typed/navigation": "0.12.2",
22
+ "@typed/route": "3.2.3",
23
+ "@typed/router": "0.26.1",
24
+ "@typed/template": "0.8.1"
25
25
  },
26
26
  "main": "./dist/cjs/index.js",
27
27
  "module": "./dist/esm/index.js",
@@ -38,6 +38,11 @@
38
38
  "import": "./dist/esm/Link.js",
39
39
  "default": "./dist/cjs/Link.js"
40
40
  },
41
+ "./Platform": {
42
+ "types": "./dist/dts/Platform.d.ts",
43
+ "import": "./dist/esm/Platform.js",
44
+ "default": "./dist/cjs/Platform.js"
45
+ },
41
46
  "./Props": {
42
47
  "types": "./dist/dts/Props.d.ts",
43
48
  "import": "./dist/esm/Props.js",
@@ -69,6 +74,9 @@
69
74
  "Link": [
70
75
  "./dist/dts/Link.d.ts"
71
76
  ],
77
+ "Platform": [
78
+ "./dist/dts/Platform.d.ts"
79
+ ],
72
80
  "Props": [
73
81
  "./dist/dts/Props.d.ts"
74
82
  ],
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+
5
+ import type { PathInput } from "@effect/platform/Http/Router"
6
+ import type { ServerRequest } from "@effect/platform/Http/ServerRequest"
7
+ import * as HttpServer from "@effect/platform/HttpServer"
8
+ import type { RouteGuard, RouteMatcher } from "@typed/router"
9
+ import type { RenderContext, RenderTemplate } from "@typed/template"
10
+ import { htmlResponse } from "@typed/template/Platform"
11
+ import type { RenderEvent } from "@typed/template/RenderEvent"
12
+
13
+ import type { Scope } from "effect"
14
+ import { Data, Effect, Option, ReadonlyArray } from "effect"
15
+
16
+ /**
17
+ * @since 1.0.0
18
+ */
19
+ export class GuardsNotMatched extends Data.TaggedError("@typed/router/GuardsNotMatched")<{
20
+ readonly request: HttpServer.request.ServerRequest
21
+ readonly guards: ReadonlyArray.NonEmptyReadonlyArray<RouteGuard<any, any, any, any, any, any, any>>
22
+ }> {}
23
+
24
+ /**
25
+ * @since 1.0.0
26
+ */
27
+ export function toHttpRouter<E, R>(
28
+ matcher: RouteMatcher<RenderEvent, E, R>
29
+ ): HttpServer.router.Router<
30
+ R | RenderTemplate | RenderContext.RenderContext | ServerRequest | Scope.Scope,
31
+ E | GuardsNotMatched
32
+ > {
33
+ let router: HttpServer.router.Router<
34
+ R | RenderTemplate | RenderContext.RenderContext | ServerRequest | Scope.Scope,
35
+ E | GuardsNotMatched
36
+ > = HttpServer.router.empty
37
+ const guardsByPath = ReadonlyArray.groupBy(matcher.guards, (guard) => guard.route.path)
38
+
39
+ for (const [path, guards] of Object.entries(guardsByPath)) {
40
+ router = HttpServer.router.get(
41
+ router,
42
+ path as PathInput,
43
+ Effect.gen(function*(_) {
44
+ // Attempt to match a guard
45
+ for (const guard of guards) {
46
+ const match = yield* _(guard.guard(path))
47
+ if (Option.isSome(match)) {
48
+ const renderable = guard.match(match.value)
49
+ return yield* _(htmlResponse(renderable))
50
+ }
51
+ }
52
+ const request = yield* _(HttpServer.request.ServerRequest)
53
+ return yield* _(Effect.fail(new GuardsNotMatched({ request, guards })))
54
+ })
55
+ )
56
+ }
57
+
58
+ return router
59
+ }