ignotum 0.0.16 → 0.0.18

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 (126) hide show
  1. package/README.md +6 -6
  2. package/dist/cli/bin.mjs +13263 -2689
  3. package/dist/cli/bin.mjs.map +1 -1
  4. package/dist/platform/_headers +3 -0
  5. package/dist/platform/_ignotum/v1.0/client.js +12 -0
  6. package/dist/runtime/{api-B4fwp5a2.d.ts → api-BnUKx9cj-D49Tf0rX.d.ts} +4 -3
  7. package/dist/runtime/api-C-tltz6s.js +31 -0
  8. package/dist/runtime/api-C-tltz6s.js.map +1 -0
  9. package/dist/runtime/artifact-BB5qzoa6.js +42 -0
  10. package/dist/runtime/artifact-BB5qzoa6.js.map +1 -0
  11. package/dist/runtime/{bootstrap-BTFScKAc.d.ts → bootstrap-DjTwGJao-DBx5zdFI.d.ts} +64 -64
  12. package/dist/runtime/{bootstrap-BISQSn_O.js → bootstrap-DlNIfH-r.js} +9 -9
  13. package/dist/runtime/bootstrap-DlNIfH-r.js.map +1 -0
  14. package/dist/runtime/client.d.ts +24 -20
  15. package/dist/runtime/client.js +9 -9
  16. package/dist/runtime/client.js.map +1 -1
  17. package/dist/runtime/id-BI08JkmR.d.ts +1 -0
  18. package/dist/runtime/{id--1m0NuUL.js → id-BrEnxY-r.js} +118 -53
  19. package/dist/runtime/id-BrEnxY-r.js.map +1 -0
  20. package/dist/runtime/{image-Djtjy4Z8.js → image-gofzZeCm.js} +2 -2
  21. package/dist/runtime/image-gofzZeCm.js.map +1 -0
  22. package/dist/runtime/{index-D4seNHlX.d.ts → index-Biaw5vdF.d.ts} +2 -2
  23. package/dist/runtime/internal/api.d.ts +1 -1
  24. package/dist/runtime/internal/api.js +1 -30
  25. package/dist/runtime/internal/bootstrap.d.ts +1 -1
  26. package/dist/runtime/internal/bootstrap.js +1 -1
  27. package/dist/runtime/internal/client.d.ts +2 -2
  28. package/dist/runtime/internal/client.js +4 -4
  29. package/dist/runtime/internal/client.js.map +1 -1
  30. package/dist/runtime/internal/host.d.ts +4 -4
  31. package/dist/runtime/internal/host.js +4 -4
  32. package/dist/runtime/internal/routes.d.ts +1 -1
  33. package/dist/runtime/internal/routes.js +1 -1
  34. package/dist/runtime/internal/server.d.ts +3 -2
  35. package/dist/runtime/internal/server.js +2 -2
  36. package/dist/runtime/internal/server.js.map +1 -1
  37. package/dist/runtime/internal/types.d.ts +2 -2
  38. package/dist/runtime/internal/types.js +1 -1
  39. package/dist/runtime/{pagination-D3qd6s9N.js → pagination--f4kMKf6.js} +2 -2
  40. package/dist/runtime/{pagination-D3qd6s9N.js.map → pagination--f4kMKf6.js.map} +1 -1
  41. package/dist/runtime/pagination-BI08JkmR.d.ts +1 -0
  42. package/dist/runtime/{router-BSBI1oN1.js → router-C1eC9yy5.js} +462 -419
  43. package/dist/runtime/router-C1eC9yy5.js.map +1 -0
  44. package/dist/runtime/routes-DnU39R7c.js +152 -0
  45. package/dist/runtime/routes-DnU39R7c.js.map +1 -0
  46. package/dist/runtime/{schema-D1wOqiNH.js → schema-BSjepoNF.js} +271 -6
  47. package/dist/runtime/schema-BSjepoNF.js.map +1 -0
  48. package/dist/runtime/server.d.ts +5 -4
  49. package/dist/runtime/server.js +3 -3
  50. package/dist/runtime/server.js.map +1 -1
  51. package/dist/runtime/{sync-DzUwA8W9.js → sync-BwgS19Xy.js} +4 -16
  52. package/dist/runtime/sync-BwgS19Xy.js.map +1 -0
  53. package/dist/runtime/{sync-D-GK2sv9.d.ts → sync-By2hX5ev.d.ts} +1 -2
  54. package/dist/runtime/{types-DeCCyqLU-BIm7rU-0.d.ts → types-DeCCyqLU-CHx7KFtx.d.ts} +2 -2
  55. package/package.json +7 -1
  56. package/src/cli/agent-files.ts +2 -0
  57. package/src/cli/build/asset-names.ts +190 -0
  58. package/src/cli/build/managed-client.ts +151 -81
  59. package/src/cli/build/managed-server.ts +4 -4
  60. package/src/cli/build/managed.ts +5 -6
  61. package/src/cli/command.ts +7 -15
  62. package/src/cli/control-client.ts +7 -9
  63. package/src/cli/deploy.ts +45 -15
  64. package/src/cli/dev.ts +50 -99
  65. package/src/cli/image-assets.ts +5 -2
  66. package/src/cli/managed-client-boundaries.ts +6 -6
  67. package/src/cli/managed-dev-platform.ts +52 -66
  68. package/src/cli/managed-exports.ts +5 -66
  69. package/src/cli/new-app.ts +7 -2
  70. package/src/cli/path.ts +11 -0
  71. package/src/cli/route-codegen.ts +2 -1
  72. package/src/cli/route-static.ts +3 -2
  73. package/src/cli/upload-journal.ts +130 -0
  74. package/src/client/bootstrap.ts +1 -110
  75. package/src/client/errors.ts +1 -70
  76. package/src/client/files.ts +1 -233
  77. package/src/client/hooks.ts +1 -367
  78. package/src/client/id.ts +1 -263
  79. package/src/client/image.ts +1 -28
  80. package/src/client/index.ts +1 -126
  81. package/src/client/jsx-dev-runtime.ts +1 -2
  82. package/src/client/jsx-runtime.ts +1 -2
  83. package/src/client/managed-client.ts +1 -729
  84. package/src/client/managed-upgrade.ts +1 -283
  85. package/src/client/page-observers.ts +1 -77
  86. package/src/client/query.ts +1 -17
  87. package/src/client/recovery-journal.ts +1 -195
  88. package/src/client/route-boundaries.ts +1 -184
  89. package/src/client/router-history.ts +1 -152
  90. package/src/client/router-store.ts +1 -644
  91. package/src/client/router.ts +1 -324
  92. package/src/client/routes.ts +1 -28
  93. package/src/client/sync.ts +1 -286
  94. package/src/dev-runtime/id.ts +1 -1
  95. package/src/dev-runtime/managed-functions.ts +10 -18
  96. package/src/dev-runtime/managed-sync.ts +16 -16
  97. package/src/dev-runtime/sync.ts +6 -4
  98. package/src/internal/api.ts +1 -156
  99. package/src/internal/client.ts +1 -186
  100. package/src/internal/host.ts +1 -1
  101. package/src/internal/http-paths.ts +1 -4
  102. package/src/internal/routes.ts +1 -45
  103. package/src/internal/server.ts +1 -3
  104. package/src/internal/types.ts +1 -2
  105. package/src/server/index.ts +1 -27
  106. package/dist/cli/managed-release-WHYLZwaS.mjs +0 -10902
  107. package/dist/cli/managed-release-WHYLZwaS.mjs.map +0 -1
  108. package/dist/cli/managed-release.d.mts +0 -1
  109. package/dist/cli/managed-release.mjs +0 -14
  110. package/dist/cli/managed-release.mjs.map +0 -1
  111. package/dist/runtime/bootstrap-BISQSn_O.js.map +0 -1
  112. package/dist/runtime/descriptor-CTY4mtwS-cS43EbwS.js +0 -269
  113. package/dist/runtime/descriptor-CTY4mtwS-cS43EbwS.js.map +0 -1
  114. package/dist/runtime/id--1m0NuUL.js.map +0 -1
  115. package/dist/runtime/id-CBOt2kDo.d.ts +0 -1
  116. package/dist/runtime/identity-QjtJRxBD.d.ts +0 -2
  117. package/dist/runtime/image-Djtjy4Z8.js.map +0 -1
  118. package/dist/runtime/internal/api.js.map +0 -1
  119. package/dist/runtime/pagination-CBOt2kDo.d.ts +0 -1
  120. package/dist/runtime/router-BSBI1oN1.js.map +0 -1
  121. package/dist/runtime/routes-Ce8TVP-T.js +0 -690
  122. package/dist/runtime/routes-Ce8TVP-T.js.map +0 -1
  123. package/dist/runtime/schema-D1wOqiNH.js.map +0 -1
  124. package/dist/runtime/sync-DzUwA8W9.js.map +0 -1
  125. package/src/cli/managed-release-bin.ts +0 -13
  126. package/src/cli/managed-release.ts +0 -260
@@ -1,184 +1 @@
1
- import { createElement as h, Fragment, type ComponentChildren, type ComponentType } from "preact";
2
- import { useErrorBoundary, useState } from "preact/hooks";
3
- import type {
4
- ErrorBoundaryProps,
5
- LoadedBranch,
6
- RouterSnapshot,
7
- RouterStore,
8
- } from "./router-store.js";
9
- import type { RouteLocation } from "./routes.js";
10
-
11
- export const DefaultError = ({ error, retry }: ErrorBoundaryProps): ComponentChildren =>
12
- h(
13
- "div",
14
- { role: "alert" },
15
- error instanceof Error ? error.message : "This page could not load or render. ",
16
- h("button", { onClick: retry }, "Retry"),
17
- );
18
-
19
- interface BoundaryProps {
20
- readonly children: ComponentChildren;
21
- readonly component: ComponentType<ErrorBoundaryProps>;
22
- readonly branch: LoadedBranch;
23
- readonly router: RouterStore;
24
- readonly onRetry?: () => void;
25
- }
26
- const Boundary = ({
27
- children,
28
- component,
29
- branch,
30
- router,
31
- onRetry,
32
- }: BoundaryProps): ComponentChildren => {
33
- const [failure, setFailure] = useState<{
34
- readonly branch: LoadedBranch;
35
- readonly error: unknown;
36
- }>();
37
- const [, reset] = useErrorBoundary((error) => {
38
- setFailure({ branch, error });
39
- router.setRenderError(true);
40
- });
41
- return failure?.branch !== branch
42
- ? children
43
- : h(component, {
44
- error: failure.error,
45
- retry: () => {
46
- router.setRenderError(false);
47
- onRetry?.();
48
- setFailure(undefined);
49
- reset();
50
- },
51
- });
52
- };
53
-
54
- export const Branch = ({
55
- branch,
56
- location,
57
- router,
58
- failure,
59
- }: {
60
- readonly branch: LoadedBranch;
61
- readonly location: RouteLocation;
62
- readonly router: RouterStore;
63
- readonly failure: RouterSnapshot["failure"];
64
- }): ComponentChildren => {
65
- const outcome = branch.outcome;
66
- let child: ComponentChildren;
67
- let lastLayout = branch.layouts.length - 1;
68
- let boundaryOwner: number | undefined;
69
- if (outcome._tag === "Matched" && branch.page !== undefined) {
70
- child = h(branch.page, {
71
- key: outcome.route.id,
72
- params: outcome.params,
73
- searchParams: outcome.searchParams,
74
- });
75
- } else if (outcome._tag === "Invalid" && branch.pageBoundaries?.invalid !== undefined) {
76
- child = h(branch.pageBoundaries.invalid, { location, issues: outcome.issues });
77
- } else {
78
- child = h(
79
- "main",
80
- { "data-ignotum-outcome": outcome._tag },
81
- outcome._tag === "Invalid" ? "Invalid URL" : "Page not found",
82
- );
83
- for (let index = lastLayout; index >= 0; index--) {
84
- const layout = branch.layouts[index]!;
85
- if (outcome._tag === "Invalid" && layout.invalid !== undefined) {
86
- child = h(layout.invalid, { location, issues: outcome.issues });
87
- lastLayout = index;
88
- boundaryOwner = index;
89
- break;
90
- }
91
- if (outcome._tag === "NotFound" && layout.notFound !== undefined) {
92
- child = h(layout.notFound, { location });
93
- lastLayout = index;
94
- boundaryOwner = index;
95
- break;
96
- }
97
- }
98
- }
99
- if (branch.pageBoundaries?.error !== undefined && outcome._tag === "Matched")
100
- child = h(Boundary, {
101
- key: "page-boundary",
102
- component: branch.pageBoundaries.error,
103
- branch,
104
- router,
105
- children: child,
106
- });
107
- let sharedLayouts = 0;
108
- while (
109
- sharedLayouts <= lastLayout &&
110
- branch.layouts[sharedLayouts]?.id === failure?.branch?.layouts[sharedLayouts]?.id
111
- )
112
- sharedLayouts++;
113
- const loadFailure =
114
- failure === undefined
115
- ? null
116
- : h(LoadFailure, {
117
- failure,
118
- router,
119
- layouts: branch.layouts.slice(0, sharedLayouts),
120
- });
121
- for (let index = lastLayout; index >= 0; index--) {
122
- const layout = branch.layouts[index]!;
123
- if (layout.error !== undefined && index !== boundaryOwner)
124
- child = h(Boundary, {
125
- key: layout.id,
126
- component: layout.error,
127
- branch,
128
- router,
129
- children: child,
130
- });
131
- child = h(layout.component, {
132
- key: layout.id,
133
- children: h(Fragment, {}, child, index === sharedLayouts - 1 ? loadFailure : null),
134
- });
135
- }
136
- return h(Boundary, {
137
- component: DefaultError,
138
- branch,
139
- router,
140
- children: h(Fragment, {}, child, sharedLayouts === 0 ? loadFailure : null),
141
- });
142
- };
143
-
144
- export const LoadFailure = ({
145
- failure,
146
- router,
147
- layouts,
148
- }: {
149
- readonly failure: NonNullable<RouterSnapshot["failure"]>;
150
- readonly layouts?: LoadedBranch["layouts"];
151
- readonly router: RouterStore;
152
- }): ComponentChildren => {
153
- const branch = failure.branch;
154
- if (branch === undefined)
155
- return h("div", { "data-ignotum-load-error": "" }, h(DefaultError, failure));
156
- let child: ComponentChildren = h(DefaultError, failure);
157
- let found = false;
158
- for (const layout of [...(layouts ?? branch.layouts)].reverse()) {
159
- if (layout.error === undefined) continue;
160
- if (!found) {
161
- child = h(layout.error, { error: failure.error, retry: failure.retry });
162
- found = true;
163
- } else {
164
- child = h(Boundary, {
165
- component: layout.error,
166
- branch,
167
- router,
168
- onRetry: failure.retry,
169
- children: child,
170
- });
171
- }
172
- }
173
- return h(
174
- "div",
175
- { "data-ignotum-load-error": "" },
176
- h(Boundary, {
177
- component: DefaultError,
178
- branch,
179
- router,
180
- onRetry: failure.retry,
181
- children: child,
182
- }),
183
- );
184
- };
1
+ export * from "@ignotum/platform/versions/1/browser/route-boundaries";
@@ -1,152 +1 @@
1
- import * as Versioned from "@ignotum/contracts/versioned";
2
- import { Deferred, Effect, Schema } from "effect";
3
-
4
- const HistoryEntryV1 = Schema.Struct({ formatVersion: Schema.Literal(1), key: Schema.String });
5
- const HistoryEntryV2 = Schema.Struct({
6
- formatVersion: Schema.Literal(2),
7
- key: Schema.String,
8
- index: Schema.NullOr(Schema.Int),
9
- });
10
- const HistoryEntry = Versioned.upgrade(
11
- Versioned.initial(HistoryEntryV1),
12
- HistoryEntryV2,
13
- (old) => ({
14
- formatVersion: 2 as const,
15
- key: old.key,
16
- index: null,
17
- }),
18
- );
19
- const HistoryState = Schema.Struct({ __ignotumRouter: HistoryEntry });
20
- const StateObject = Schema.Record(Schema.String, Schema.Unknown);
21
- export interface HistoryPosition {
22
- readonly key: string;
23
- readonly index: number;
24
- readonly href: string;
25
- }
26
- const hrefOf = (browser: Window) =>
27
- `${browser.location.pathname}${browser.location.search}${browser.location.hash}`;
28
-
29
- /** Serializes router corrections to native traversal without adding duplicate entries. */
30
- export class RouterHistory {
31
- committed: HistoryPosition;
32
- private actual: HistoryPosition;
33
- private readonly positions = new Map<string, number>();
34
- private seeking: { position: HistoryPosition; done: Deferred.Deferred<boolean> } | undefined;
35
- private readonly originalScrollRestoration;
36
- private direction = -1;
37
- private scrollPending = false;
38
- private expectedKey: string | undefined;
39
- readonly scroll = new Map<string, { x: number; y: number }>();
40
- constructor(
41
- private readonly browser: Window,
42
- private readonly onTraversal: (position: HistoryPosition) => void,
43
- ) {
44
- const parsed = Schema.decodeUnknownOption(HistoryState)(browser.history.state);
45
- const entry = parsed._tag === "Some" ? parsed.value.__ignotumRouter : undefined;
46
- this.actual = this.committed = {
47
- key: entry?.key ?? browser.crypto.randomUUID(),
48
- index: entry?.index ?? 0,
49
- href: hrefOf(browser),
50
- };
51
- this.write(this.actual, false);
52
- this.originalScrollRestoration = browser.history.scrollRestoration;
53
- browser.history.scrollRestoration = "manual";
54
- browser.addEventListener("popstate", this.onPop);
55
- browser.addEventListener("scroll", this.saveScroll);
56
- }
57
- private write(position: HistoryPosition, push: boolean): void {
58
- const parsed = Schema.decodeUnknownOption(StateObject)(this.browser.history.state);
59
- const owned = {
60
- __ignotumRouter: Schema.encodeSync(HistoryEntry)({
61
- formatVersion: 2,
62
- key: position.key,
63
- index: position.index,
64
- }),
65
- };
66
- const state = parsed._tag === "Some" ? { ...parsed.value, ...owned } : owned;
67
- if (push) this.browser.history.pushState(state, "", position.href);
68
- else this.browser.history.replaceState(state, "", position.href);
69
- this.positions.set(position.key, position.index);
70
- }
71
- saveScroll = (): void => {
72
- if (this.scrollPending) return;
73
- this.scroll.set(this.committed.key, { x: this.browser.scrollX, y: this.browser.scrollY });
74
- };
75
- captureScroll(): { x: number; y: number } {
76
- this.saveScroll();
77
- this.scrollPending = true;
78
- return (
79
- this.scroll.get(this.committed.key) ?? { x: this.browser.scrollX, y: this.browser.scrollY }
80
- );
81
- }
82
- finishScroll(): void {
83
- this.scrollPending = false;
84
- this.saveScroll();
85
- }
86
- restoreSourceScroll(): void {
87
- if (!this.scrollPending) return;
88
- const saved = this.scroll.get(this.committed.key);
89
- if (saved !== undefined) this.browser.scrollTo(saved.x, saved.y);
90
- this.finishScroll();
91
- }
92
- private onPop = (): void => {
93
- const parsed = Schema.decodeUnknownOption(HistoryState)(this.browser.history.state);
94
- const entry = parsed._tag === "Some" ? parsed.value.__ignotumRouter : undefined;
95
- const key = entry?.key ?? this.browser.crypto.randomUUID();
96
- const index = entry?.index ?? this.positions.get(key) ?? this.actual.index + this.direction;
97
- this.actual = { key, index, href: hrefOf(this.browser) };
98
- this.write(this.actual, false);
99
- const expected = this.expectedKey;
100
- this.expectedKey = undefined;
101
- const seeking = this.seeking;
102
- if (seeking !== undefined && (expected === key || seeking.position.key === key)) {
103
- this.advanceSeek();
104
- return;
105
- }
106
- if (seeking !== undefined) {
107
- this.seeking = undefined;
108
- Effect.runSync(Deferred.succeed(seeking.done, false));
109
- }
110
- this.onTraversal(this.actual);
111
- };
112
- private advanceSeek(): void {
113
- const seeking = this.seeking;
114
- if (seeking === undefined || this.expectedKey !== undefined) return;
115
- if (this.actual.key === seeking.position.key) {
116
- this.seeking = undefined;
117
- Effect.runSync(Deferred.succeed(seeking.done, true));
118
- } else {
119
- this.expectedKey = seeking.position.key;
120
- this.browser.history.go(seeking.position.index - this.actual.index);
121
- }
122
- }
123
- seek(position: HistoryPosition): Promise<boolean> {
124
- if (this.seeking !== undefined) {
125
- if (this.seeking.position.key === position.key)
126
- return Effect.runPromise(Deferred.await(this.seeking.done));
127
- Effect.runSync(Deferred.succeed(this.seeking.done, false));
128
- }
129
- const done = Deferred.makeUnsafe<boolean>();
130
- this.seeking = { position, done };
131
- this.advanceSeek();
132
- return Effect.runPromise(Deferred.await(done));
133
- }
134
- commit(position: HistoryPosition, kind: "initial" | "push" | "replace" | "traverse"): void {
135
- if (kind === "push" || kind === "replace") this.write(position, kind === "push");
136
- this.actual = this.committed = position;
137
- }
138
- back = (): void => {
139
- this.direction = -1;
140
- this.browser.history.back();
141
- };
142
- forward = (): void => {
143
- this.direction = 1;
144
- this.browser.history.forward();
145
- };
146
- dispose(): void {
147
- this.browser.removeEventListener("popstate", this.onPop);
148
- this.browser.removeEventListener("scroll", this.saveScroll);
149
- this.browser.history.scrollRestoration = this.originalScrollRestoration;
150
- if (this.seeking !== undefined) Effect.runSync(Deferred.succeed(this.seeking.done, false));
151
- }
152
- }
1
+ export * from "@ignotum/platform/versions/1/browser/router-history";