nowity 1.0.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 +751 -0
- package/dist/api/contract.d.ts +186 -0
- package/dist/api/contract.d.ts.map +1 -0
- package/dist/api/contract.js +251 -0
- package/dist/api/errors.d.ts +50 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +50 -0
- package/dist/api/index.d.ts +13 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +32 -0
- package/dist/client/confirmed-store.d.ts +33 -0
- package/dist/client/confirmed-store.d.ts.map +1 -0
- package/dist/client/confirmed-store.js +123 -0
- package/dist/client/connection.d.ts +102 -0
- package/dist/client/connection.d.ts.map +1 -0
- package/dist/client/connection.js +285 -0
- package/dist/client/list.d.ts +102 -0
- package/dist/client/list.d.ts.map +1 -0
- package/dist/client/list.js +257 -0
- package/dist/client/live-query.d.ts +153 -0
- package/dist/client/live-query.d.ts.map +1 -0
- package/dist/client/live-query.js +244 -0
- package/dist/client/nowity-client.d.ts +188 -0
- package/dist/client/nowity-client.d.ts.map +1 -0
- package/dist/client/nowity-client.js +580 -0
- package/dist/client/null-transport.d.ts +16 -0
- package/dist/client/null-transport.d.ts.map +1 -0
- package/dist/client/null-transport.js +17 -0
- package/dist/client/overlay.d.ts +44 -0
- package/dist/client/overlay.d.ts.map +1 -0
- package/dist/client/overlay.js +90 -0
- package/dist/client/query-source.d.ts +78 -0
- package/dist/client/query-source.d.ts.map +1 -0
- package/dist/client/query-source.js +57 -0
- package/dist/client/ssr-source.d.ts +70 -0
- package/dist/client/ssr-source.d.ts.map +1 -0
- package/dist/client/ssr-source.js +134 -0
- package/dist/client/transport.d.ts +19 -0
- package/dist/client/transport.d.ts.map +1 -0
- package/dist/client/transport.js +2 -0
- package/dist/client/ws-transport.d.ts +30 -0
- package/dist/client/ws-transport.d.ts.map +1 -0
- package/dist/client/ws-transport.js +89 -0
- package/dist/client.d.ts +47 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +80 -0
- package/dist/core/diff.d.ts +14 -0
- package/dist/core/diff.d.ts.map +1 -0
- package/dist/core/diff.js +56 -0
- package/dist/core/normalize.d.ts +16 -0
- package/dist/core/normalize.d.ts.map +1 -0
- package/dist/core/normalize.js +67 -0
- package/dist/core/protocol.d.ts +215 -0
- package/dist/core/protocol.d.ts.map +1 -0
- package/dist/core/protocol.js +14 -0
- package/dist/core/ssr-bridge.d.ts +69 -0
- package/dist/core/ssr-bridge.d.ts.map +1 -0
- package/dist/core/ssr-bridge.js +40 -0
- package/dist/core/types.d.ts +96 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +17 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +98 -0
- package/dist/ironbean/client.d.ts +7 -0
- package/dist/ironbean/client.d.ts.map +1 -0
- package/dist/ironbean/client.js +38 -0
- package/dist/ironbean/server.d.ts +42 -0
- package/dist/ironbean/server.d.ts.map +1 -0
- package/dist/ironbean/server.js +62 -0
- package/dist/ironbean/tokens.d.ts +26 -0
- package/dist/ironbean/tokens.d.ts.map +1 -0
- package/dist/ironbean/tokens.js +23 -0
- package/dist/next/config.d.ts +7 -0
- package/dist/next/config.d.ts.map +1 -0
- package/dist/next/config.js +77 -0
- package/dist/next/live.d.ts +69 -0
- package/dist/next/live.d.ts.map +1 -0
- package/dist/next/live.js +70 -0
- package/dist/next/serve.d.ts +44 -0
- package/dist/next/serve.d.ts.map +1 -0
- package/dist/next/serve.js +107 -0
- package/dist/next/server.d.ts +62 -0
- package/dist/next/server.d.ts.map +1 -0
- package/dist/next/server.js +127 -0
- package/dist/react/connection-context.d.ts +4 -0
- package/dist/react/connection-context.d.ts.map +1 -0
- package/dist/react/connection-context.js +28 -0
- package/dist/react/grid-list.d.ts +34 -0
- package/dist/react/grid-list.d.ts.map +1 -0
- package/dist/react/grid-list.js +62 -0
- package/dist/react/hydrate.d.ts +22 -0
- package/dist/react/hydrate.d.ts.map +1 -0
- package/dist/react/hydrate.js +18 -0
- package/dist/react/index.d.ts +35 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +51 -0
- package/dist/react/list.d.ts +31 -0
- package/dist/react/list.d.ts.map +1 -0
- package/dist/react/list.js +35 -0
- package/dist/react/prerendered.d.ts +33 -0
- package/dist/react/prerendered.d.ts.map +1 -0
- package/dist/react/prerendered.js +165 -0
- package/dist/react/provider.d.ts +64 -0
- package/dist/react/provider.d.ts.map +1 -0
- package/dist/react/provider.js +130 -0
- package/dist/react/refusals.d.ts +31 -0
- package/dist/react/refusals.d.ts.map +1 -0
- package/dist/react/refusals.js +51 -0
- package/dist/react/restricted.d.ts +76 -0
- package/dist/react/restricted.d.ts.map +1 -0
- package/dist/react/restricted.js +126 -0
- package/dist/react/use-list.d.ts +42 -0
- package/dist/react/use-list.d.ts.map +1 -0
- package/dist/react/use-list.js +56 -0
- package/dist/react/use-query.d.ts +66 -0
- package/dist/react/use-query.d.ts.map +1 -0
- package/dist/react/use-query.js +126 -0
- package/dist/react/virtual.d.ts +60 -0
- package/dist/react/virtual.d.ts.map +1 -0
- package/dist/react/virtual.js +131 -0
- package/dist/server/api/auth.d.ts +37 -0
- package/dist/server/api/auth.d.ts.map +1 -0
- package/dist/server/api/auth.js +54 -0
- package/dist/server/api/bridge.d.ts +28 -0
- package/dist/server/api/bridge.d.ts.map +1 -0
- package/dist/server/api/bridge.js +330 -0
- package/dist/server/api/collector.d.ts +25 -0
- package/dist/server/api/collector.d.ts.map +1 -0
- package/dist/server/api/collector.js +184 -0
- package/dist/server/api/configure.d.ts +31 -0
- package/dist/server/api/configure.d.ts.map +1 -0
- package/dist/server/api/configure.js +67 -0
- package/dist/server/api/execution.d.ts +77 -0
- package/dist/server/api/execution.d.ts.map +1 -0
- package/dist/server/api/execution.js +97 -0
- package/dist/server/api/list.d.ts +141 -0
- package/dist/server/api/list.d.ts.map +1 -0
- package/dist/server/api/list.js +281 -0
- package/dist/server/api/prerender.d.ts +32 -0
- package/dist/server/api/prerender.d.ts.map +1 -0
- package/dist/server/api/prerender.js +69 -0
- package/dist/server/api/read-keys.d.ts +128 -0
- package/dist/server/api/read-keys.d.ts.map +1 -0
- package/dist/server/api/read-keys.js +464 -0
- package/dist/server/api/read-set.d.ts +103 -0
- package/dist/server/api/read-set.d.ts.map +1 -0
- package/dist/server/api/read-set.js +210 -0
- package/dist/server/api/runtime.d.ts +36 -0
- package/dist/server/api/runtime.d.ts.map +1 -0
- package/dist/server/api/runtime.js +49 -0
- package/dist/server/api/tracked-client.d.ts +6 -0
- package/dist/server/api/tracked-client.d.ts.map +1 -0
- package/dist/server/api/tracked-client.js +56 -0
- package/dist/server/change-source/change-source.d.ts +41 -0
- package/dist/server/change-source/change-source.d.ts.map +1 -0
- package/dist/server/change-source/change-source.js +2 -0
- package/dist/server/change-source/outbox-change-source.d.ts +106 -0
- package/dist/server/change-source/outbox-change-source.d.ts.map +1 -0
- package/dist/server/change-source/outbox-change-source.js +237 -0
- package/dist/server/change-source/wal-change-source.d.ts +85 -0
- package/dist/server/change-source/wal-change-source.d.ts.map +1 -0
- package/dist/server/change-source/wal-change-source.js +193 -0
- package/dist/server/db.d.ts +51 -0
- package/dist/server/db.d.ts.map +1 -0
- package/dist/server/db.js +53 -0
- package/dist/server/evaluate.d.ts +39 -0
- package/dist/server/evaluate.d.ts.map +1 -0
- package/dist/server/evaluate.js +61 -0
- package/dist/server/invalidation-index.d.ts +64 -0
- package/dist/server/invalidation-index.d.ts.map +1 -0
- package/dist/server/invalidation-index.js +0 -0
- package/dist/server/mutator.d.ts +59 -0
- package/dist/server/mutator.d.ts.map +1 -0
- package/dist/server/mutator.js +77 -0
- package/dist/server/query.d.ts +113 -0
- package/dist/server/query.d.ts.map +1 -0
- package/dist/server/query.js +35 -0
- package/dist/server/setup.d.ts +30 -0
- package/dist/server/setup.d.ts.map +1 -0
- package/dist/server/setup.js +107 -0
- package/dist/server/sql/setup.sql +215 -0
- package/dist/server/ssr.d.ts +29 -0
- package/dist/server/ssr.d.ts.map +1 -0
- package/dist/server/ssr.js +43 -0
- package/dist/server/sync-engine.d.ts +256 -0
- package/dist/server/sync-engine.d.ts.map +1 -0
- package/dist/server/sync-engine.js +805 -0
- package/dist/server/ws-server.d.ts +56 -0
- package/dist/server/ws-server.d.ts.map +1 -0
- package/dist/server/ws-server.js +241 -0
- package/package.json +81 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js, the boundary where a page's live queries are read.
|
|
3
|
+
*
|
|
4
|
+
* A server component, deliberately. It is the only place that can be both above
|
|
5
|
+
* the components that read data and inside the request that knows who is asking,
|
|
6
|
+
* which is exactly what is needed to answer them from the database instead of
|
|
7
|
+
* making the page list them in advance.
|
|
8
|
+
*/
|
|
9
|
+
import type { ReactNode } from "react";
|
|
10
|
+
import { type ReadAs } from "./server";
|
|
11
|
+
export interface LiveProps {
|
|
12
|
+
/** Shown until the data is there — and in the server's HTML, if it is not. */
|
|
13
|
+
fallback?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Render for this session instead of the request's.
|
|
16
|
+
*
|
|
17
|
+
* The same option `read()` takes, and it matters for the same reason: what is
|
|
18
|
+
* rendered here is what the browser starts from, so whatever decides the
|
|
19
|
+
* session for the page has to be what decides it for the socket.
|
|
20
|
+
*/
|
|
21
|
+
as?: ReadAs;
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Where live queries are read, and where their first answers come from.
|
|
26
|
+
*
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <Live fallback={<Spinner />}>
|
|
29
|
+
* <Documents projectId={id} />
|
|
30
|
+
* </Live>
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* That is the whole of it. Nothing above says which queries `<Documents>` reads,
|
|
34
|
+
* because nothing above can be kept honest about it — a page and the components
|
|
35
|
+
* under it drift, and the old way of saying it — `read()` in the page, payloads
|
|
36
|
+
* handed down — failed by going quietly back to a spinner rather than by
|
|
37
|
+
* breaking. {@link NextNowity.read} is still there for a page that wants the
|
|
38
|
+
* rows as a value; it is no longer how a page is prerendered.
|
|
39
|
+
*
|
|
40
|
+
* Instead this opens one snapshot for the render and lets the components ask.
|
|
41
|
+
* Each `useQuerySuspense` under it resolves from the database, through the same
|
|
42
|
+
* code path a streamed snapshot takes, so the HTML has real rows in it; what they
|
|
43
|
+
* asked for leaves with the page and seeds the store before the socket is up. Add
|
|
44
|
+
* a query to a component three levels down and it is prerendered too, because the
|
|
45
|
+
* list is the render's own behaviour.
|
|
46
|
+
*
|
|
47
|
+
* The guarantees are the ones {@link prerender} gave: one snapshot, so panels
|
|
48
|
+
* cannot disagree about the time; the sync engine's own permission check, so a
|
|
49
|
+
* refusal arrives as "no access" on the first paint rather than as an empty list
|
|
50
|
+
* that changes its mind.
|
|
51
|
+
*
|
|
52
|
+
* It refuses to run without a runtime rather than quietly falling back to the
|
|
53
|
+
* socket. Rendering only fallbacks is what the old way did when it drifted, and
|
|
54
|
+
* it is the one failure nobody ever notices — a page that looks a little slow is
|
|
55
|
+
* not a page anybody reports.
|
|
56
|
+
*
|
|
57
|
+
* **Anything that reads live data has one of these above it**, and because this
|
|
58
|
+
* is a server component that means it goes in a page or a layout. A layout
|
|
59
|
+
* carries its own for the chrome around the page — a nav that reads is outside
|
|
60
|
+
* the page's boundary, and a read with none above it has nothing to answer it.
|
|
61
|
+
*
|
|
62
|
+
* Below it, `"use client"` changes nothing: the subtree reads through this
|
|
63
|
+
* render's snapshot whichever kind of component asks, so a client island is
|
|
64
|
+
* prerendered like anything else. An island that only mounts *after* hydration —
|
|
65
|
+
* a dialog, a tab — was never part of the server's render and needs no boundary
|
|
66
|
+
* of its own beyond a plain `<Suspense>`, which is all a browser ever needed.
|
|
67
|
+
*/
|
|
68
|
+
export declare function Live({ fallback, as, children }: LiveProps): Promise<import("react").JSX.Element>;
|
|
69
|
+
//# sourceMappingURL=live.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live.d.ts","sourceRoot":"","sources":["../../src/next/live.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,EAAqB,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAE1D,MAAM,WAAW,SAAS;IACtB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;;;;;OAMG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,SAAS,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAsB,IAAI,CAAC,EAAE,QAAe,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,SAAS,wCA6BtE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Live = Live;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const prerendered_1 = require("../react/prerendered");
|
|
6
|
+
const collector_1 = require("../server/api/collector");
|
|
7
|
+
const server_1 = require("./server");
|
|
8
|
+
/**
|
|
9
|
+
* Where live queries are read, and where their first answers come from.
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <Live fallback={<Spinner />}>
|
|
13
|
+
* <Documents projectId={id} />
|
|
14
|
+
* </Live>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* That is the whole of it. Nothing above says which queries `<Documents>` reads,
|
|
18
|
+
* because nothing above can be kept honest about it — a page and the components
|
|
19
|
+
* under it drift, and the old way of saying it — `read()` in the page, payloads
|
|
20
|
+
* handed down — failed by going quietly back to a spinner rather than by
|
|
21
|
+
* breaking. {@link NextNowity.read} is still there for a page that wants the
|
|
22
|
+
* rows as a value; it is no longer how a page is prerendered.
|
|
23
|
+
*
|
|
24
|
+
* Instead this opens one snapshot for the render and lets the components ask.
|
|
25
|
+
* Each `useQuerySuspense` under it resolves from the database, through the same
|
|
26
|
+
* code path a streamed snapshot takes, so the HTML has real rows in it; what they
|
|
27
|
+
* asked for leaves with the page and seeds the store before the socket is up. Add
|
|
28
|
+
* a query to a component three levels down and it is prerendered too, because the
|
|
29
|
+
* list is the render's own behaviour.
|
|
30
|
+
*
|
|
31
|
+
* The guarantees are the ones {@link prerender} gave: one snapshot, so panels
|
|
32
|
+
* cannot disagree about the time; the sync engine's own permission check, so a
|
|
33
|
+
* refusal arrives as "no access" on the first paint rather than as an empty list
|
|
34
|
+
* that changes its mind.
|
|
35
|
+
*
|
|
36
|
+
* It refuses to run without a runtime rather than quietly falling back to the
|
|
37
|
+
* socket. Rendering only fallbacks is what the old way did when it drifted, and
|
|
38
|
+
* it is the one failure nobody ever notices — a page that looks a little slow is
|
|
39
|
+
* not a page anybody reports.
|
|
40
|
+
*
|
|
41
|
+
* **Anything that reads live data has one of these above it**, and because this
|
|
42
|
+
* is a server component that means it goes in a page or a layout. A layout
|
|
43
|
+
* carries its own for the chrome around the page — a nav that reads is outside
|
|
44
|
+
* the page's boundary, and a read with none above it has nothing to answer it.
|
|
45
|
+
*
|
|
46
|
+
* Below it, `"use client"` changes nothing: the subtree reads through this
|
|
47
|
+
* render's snapshot whichever kind of component asks, so a client island is
|
|
48
|
+
* prerendered like anything else. An island that only mounts *after* hydration —
|
|
49
|
+
* a dialog, a tab — was never part of the server's render and needs no boundary
|
|
50
|
+
* of its own beyond a plain `<Suspense>`, which is all a browser ever needed.
|
|
51
|
+
*/
|
|
52
|
+
async function Live({ fallback = null, as, children }) {
|
|
53
|
+
const nowity = (0, server_1.currentNextNowity)();
|
|
54
|
+
if (!nowity) {
|
|
55
|
+
throw new Error("<Live> found no Nowity runtime in this process. The module that calls " +
|
|
56
|
+
"createNextNowity(...) has to be part of the App Router's module graph — " +
|
|
57
|
+
"importing it from the root layout is the usual way.");
|
|
58
|
+
}
|
|
59
|
+
const runtime = nowity.runtime();
|
|
60
|
+
const collector = (0, collector_1.openSsrCollector)({
|
|
61
|
+
snapshots: runtime.snapshots,
|
|
62
|
+
queries: runtime.api.queries,
|
|
63
|
+
manifest: { contracts: runtime.api.manifest.contracts, entities: runtime.api.entities },
|
|
64
|
+
}, await nowity.session(as));
|
|
65
|
+
// And that is this component's whole job: the request's half of it — who is
|
|
66
|
+
// asking, and one snapshot to answer from. What a rendered page then needs
|
|
67
|
+
// of it is {@link Prerendered}'s, on the other side of the ticket, because
|
|
68
|
+
// all of it happens where the components render rather than here.
|
|
69
|
+
return ((0, jsx_runtime_1.jsx)(prerendered_1.Prerendered, { ticket: collector.id, fallback: fallback, children: children }));
|
|
70
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next and the sync socket, on one port, in one call.
|
|
3
|
+
*
|
|
4
|
+
* Everything in here is mechanical: make an HTTP server, let Next answer the
|
|
5
|
+
* requests, let Nowity answer the upgrades, listen, shut down cleanly. An
|
|
6
|
+
* application that wrote it out would write the same thing, so it may as well
|
|
7
|
+
* not have to.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* // server.ts
|
|
11
|
+
* import { serveNext } from "nowity";
|
|
12
|
+
* import { prisma, Db } from "./lib/db";
|
|
13
|
+
*
|
|
14
|
+
* serveNext({ prisma, db: Db, authenticate });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* A custom server rather than `next dev` because the App Router cannot take over
|
|
18
|
+
* a connection for an upgrade — but the HTTP server underneath it can, and this
|
|
19
|
+
* file is plain Node, so nothing in it ever meets webpack or the edge runtime.
|
|
20
|
+
*/
|
|
21
|
+
import * as http from "http";
|
|
22
|
+
import { type NowityServer, type NowityServerConfig } from "../server/api/configure";
|
|
23
|
+
export interface ServeNextOptions extends Omit<NowityServerConfig, "syncServer"> {
|
|
24
|
+
port?: number;
|
|
25
|
+
hostname?: string;
|
|
26
|
+
/** Defaults to `NODE_ENV !== "production"`. */
|
|
27
|
+
dev?: boolean;
|
|
28
|
+
/** Path the socket is served on, alongside the pages. Default `/_nowity`. */
|
|
29
|
+
path?: string;
|
|
30
|
+
/** Bundle with Turbopack. Default `true`; set it to `false` to fall back to webpack. */
|
|
31
|
+
turbopack?: boolean;
|
|
32
|
+
onListen?: (info: {
|
|
33
|
+
port: number;
|
|
34
|
+
hostname: string;
|
|
35
|
+
path: string;
|
|
36
|
+
}) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface ServedNext {
|
|
39
|
+
nowity: NowityServer;
|
|
40
|
+
http: http.Server;
|
|
41
|
+
close(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
export declare function serveNext(options: ServeNextOptions): Promise<ServedNext>;
|
|
44
|
+
//# sourceMappingURL=serve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/next/serve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAsB,KAAK,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAEzG,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,kBAAkB,EAAE,YAAY,CAAC;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wFAAwF;IACxF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC/E;AAED,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;IAClB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAkE9E"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.serveNext = serveNext;
|
|
37
|
+
/**
|
|
38
|
+
* Next and the sync socket, on one port, in one call.
|
|
39
|
+
*
|
|
40
|
+
* Everything in here is mechanical: make an HTTP server, let Next answer the
|
|
41
|
+
* requests, let Nowity answer the upgrades, listen, shut down cleanly. An
|
|
42
|
+
* application that wrote it out would write the same thing, so it may as well
|
|
43
|
+
* not have to.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* // server.ts
|
|
47
|
+
* import { serveNext } from "nowity";
|
|
48
|
+
* import { prisma, Db } from "./lib/db";
|
|
49
|
+
*
|
|
50
|
+
* serveNext({ prisma, db: Db, authenticate });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* A custom server rather than `next dev` because the App Router cannot take over
|
|
54
|
+
* a connection for an upgrade — but the HTTP server underneath it can, and this
|
|
55
|
+
* file is plain Node, so nothing in it ever meets webpack or the edge runtime.
|
|
56
|
+
*/
|
|
57
|
+
const http = __importStar(require("http"));
|
|
58
|
+
const node_module_1 = require("node:module");
|
|
59
|
+
const configure_1 = require("../server/api/configure");
|
|
60
|
+
async function serveNext(options) {
|
|
61
|
+
const { port = Number(process.env.PORT ?? 3000), hostname = process.env.HOST ?? "0.0.0.0", dev = process.env.NODE_ENV !== "production", path = "/_nowity", turbopack = true, onListen, ...config } = options;
|
|
62
|
+
// Required rather than imported, so the library does not make every consumer
|
|
63
|
+
// depend on Next just to have this module in the package — and resolved from
|
|
64
|
+
// the application's directory, because that is where Next is installed, not
|
|
65
|
+
// necessarily next to the library.
|
|
66
|
+
//
|
|
67
|
+
// Through `createRequire` rather than the bare `require`, because this module
|
|
68
|
+
// now reaches every page's server bundle through `nowity`. Webpack cannot
|
|
69
|
+
// resolve a call it has to evaluate to understand, and says so twice per
|
|
70
|
+
// build; a require it does not own is one it leaves alone. Nothing here is
|
|
71
|
+
// ever bundled anyway — a custom server is plain Node.
|
|
72
|
+
const nodeRequire = (0, node_module_1.createRequire)(__filename);
|
|
73
|
+
const next = nodeRequire(nodeRequire.resolve("next", { paths: [process.cwd()] }));
|
|
74
|
+
// `next dev` picks its bundler from a flag, and a custom server has none —
|
|
75
|
+
// so it says which one it wants here. Left unsaid, Next 16 would still land
|
|
76
|
+
// on Turbopack, but only by inferring it from the absence of a webpack
|
|
77
|
+
// config; asked for outright, it is not something a stray plugin adding that
|
|
78
|
+
// config can quietly take away. Only in development: serving a finished
|
|
79
|
+
// build is the same work either way, and `next start` says nothing either.
|
|
80
|
+
const bundler = dev ? (turbopack ? { turbopack: true } : { webpack: true }) : {};
|
|
81
|
+
const app = next({ dev, hostname, port, ...bundler });
|
|
82
|
+
const handle = app.getRequestHandler();
|
|
83
|
+
await app.prepare();
|
|
84
|
+
const server = http.createServer((req, res) => {
|
|
85
|
+
void handle(req, res);
|
|
86
|
+
});
|
|
87
|
+
const nowity = (0, configure_1.createNowityServer)({
|
|
88
|
+
...config,
|
|
89
|
+
// Borrowed, not owned: Nowity takes the upgrades on its path and leaves
|
|
90
|
+
// every other one — including Next's own hot reload.
|
|
91
|
+
syncServer: { server, path },
|
|
92
|
+
});
|
|
93
|
+
await nowity.start();
|
|
94
|
+
await new Promise((resolve) => server.listen(port, hostname, resolve));
|
|
95
|
+
const close = async () => {
|
|
96
|
+
await nowity.stop();
|
|
97
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
98
|
+
};
|
|
99
|
+
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
100
|
+
process.on(signal, () => void close().then(() => process.exit(0)));
|
|
101
|
+
}
|
|
102
|
+
if (onListen)
|
|
103
|
+
onListen({ port, hostname, path });
|
|
104
|
+
else
|
|
105
|
+
console.log(`[nowity] http://${hostname}:${port} — pages and socket (${path})`);
|
|
106
|
+
return { nowity, http: server, close };
|
|
107
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { SessionInfo } from "../server/query";
|
|
2
|
+
import { type NowityRuntime, type NowityRuntimeConfig } from "../server/api/runtime";
|
|
3
|
+
import { type PrerenderError, type PrerenderGet, type PrerenderResult } from "../server/api/prerender";
|
|
4
|
+
/**
|
|
5
|
+
* The application's read half, wherever it was created.
|
|
6
|
+
*
|
|
7
|
+
* `<Live>` needs it and has no way to be handed it: it is a component in a tree,
|
|
8
|
+
* not something the application calls. Kept beside the runtime it wraps, which is
|
|
9
|
+
* already a singleton for the same reason — one process, one set of endpoints.
|
|
10
|
+
*/
|
|
11
|
+
export declare function currentNextNowity(): NextNowity | null;
|
|
12
|
+
/** Who a page renders for, when it is not the request's own session. */
|
|
13
|
+
export type ReadAs = SessionInfo | string;
|
|
14
|
+
export interface ReadOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Render for this session instead of the request's.
|
|
17
|
+
*
|
|
18
|
+
* A user id is enough; anything more (tenant, roles) goes in a full
|
|
19
|
+
* {@link SessionInfo}. Without it the session comes from the application's
|
|
20
|
+
* {@link Authenticator} — the same class the socket asks, given this
|
|
21
|
+
* request's own headers, so a page and its socket cannot disagree about who
|
|
22
|
+
* is looking.
|
|
23
|
+
*/
|
|
24
|
+
as?: ReadAs;
|
|
25
|
+
}
|
|
26
|
+
export interface NextNowity {
|
|
27
|
+
/** The runtime, created on first use and kept across HMR reloads. */
|
|
28
|
+
runtime(): NowityRuntime;
|
|
29
|
+
/**
|
|
30
|
+
* Read a page's endpoints in one snapshot, and collect what the browser needs
|
|
31
|
+
* to start from the same data.
|
|
32
|
+
*
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const { data, hydration } = await nowity.read((get) =>
|
|
35
|
+
* get(DocumentApi).byProject(id),
|
|
36
|
+
* );
|
|
37
|
+
*
|
|
38
|
+
* return (
|
|
39
|
+
* <NowityProvider hydrate={hydration}>
|
|
40
|
+
* <Documents projectId={id} />
|
|
41
|
+
* </NowityProvider>
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* Everything read here comes from one snapshot: a page that renders two
|
|
46
|
+
* endpoints cannot show them from two different points in time.
|
|
47
|
+
*
|
|
48
|
+
* {@link Live} is the way a page normally does this, and the difference is
|
|
49
|
+
* who says what to read. Here the page does, and has to keep saying it as
|
|
50
|
+
* the components below it change; under `<Live>` the components ask and the
|
|
51
|
+
* list is the render's own behaviour. This stays for the caller who wants
|
|
52
|
+
* the rows as a value — for metadata, or a check — rather than on screen.
|
|
53
|
+
*/
|
|
54
|
+
read<T>(render: (get: PrerenderGet) => Promise<T>, options?: ReadOptions): Promise<PrerenderResult<T>>;
|
|
55
|
+
/** {@link read} for a session the caller has already resolved. */
|
|
56
|
+
prerender<T>(session: SessionInfo, render: (get: PrerenderGet) => Promise<T>): Promise<PrerenderResult<T>>;
|
|
57
|
+
/** The session this request renders for, as {@link read} would resolve it. */
|
|
58
|
+
session(as?: ReadAs): Promise<SessionInfo>;
|
|
59
|
+
}
|
|
60
|
+
export declare function createNextNowity(config: () => NowityRuntimeConfig): NextNowity;
|
|
61
|
+
export type { PrerenderError, PrerenderGet, PrerenderResult };
|
|
62
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/next/server.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAEH,KAAK,aAAa,EAClB,KAAK,mBAAmB,EAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEH,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,eAAe,EACvB,MAAM,yBAAyB,CAAC;AAejC;;;;;;GAMG;AACH,wBAAgB,iBAAiB,IAAI,UAAU,GAAG,IAAI,CAErD;AAED,wEAAwE;AACxE,MAAM,MAAM,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAE1C,MAAM,WAAW,WAAW;IACxB;;;;;;;;OAQG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACvB,qEAAqE;IACrE,OAAO,IAAI,aAAa,CAAC;IACzB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,IAAI,CAAC,CAAC,EACF,MAAM,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,EACzC,OAAO,CAAC,EAAE,WAAW,GACtB,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,kEAAkE;IAClE,SAAS,CAAC,CAAC,EACP,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,8EAA8E;IAC9E,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC9C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,mBAAmB,GAAG,UAAU,CAuC9E;AAyBD,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.currentNextNowity = currentNextNowity;
|
|
37
|
+
exports.createNextNowity = createNextNowity;
|
|
38
|
+
/**
|
|
39
|
+
* Next.js, server side.
|
|
40
|
+
*
|
|
41
|
+
* Only the read half lives in the Next process: the endpoints and a way to run
|
|
42
|
+
* them inside one snapshot. The change stream and the WebSocket server run
|
|
43
|
+
* separately (`serveNext`), for two reasons that point the same way — the
|
|
44
|
+
* App Router has no supported way to hijack a connection for a WebSocket upgrade,
|
|
45
|
+
* and Next compiles `instrumentation.ts` for the edge runtime too, where `http`
|
|
46
|
+
* and `ws` do not exist to be imported.
|
|
47
|
+
*
|
|
48
|
+
* The runtime is memoised on `globalThis` because dev-mode HMR re-evaluates
|
|
49
|
+
* modules, and a fresh runtime per reload would mean a fresh Prisma client per
|
|
50
|
+
* reload.
|
|
51
|
+
*/
|
|
52
|
+
const ironbean_1 = require("ironbean");
|
|
53
|
+
const auth_1 = require("../server/api/auth");
|
|
54
|
+
const runtime_1 = require("../server/api/runtime");
|
|
55
|
+
const prerender_1 = require("../server/api/prerender");
|
|
56
|
+
const RUNTIME = Symbol.for("nowity.next.runtime");
|
|
57
|
+
const INSTANCE = Symbol.for("nowity.next.instance");
|
|
58
|
+
function slot() {
|
|
59
|
+
const global = globalThis;
|
|
60
|
+
return (global[RUNTIME] ?? (global[RUNTIME] = {}));
|
|
61
|
+
}
|
|
62
|
+
function instanceSlot() {
|
|
63
|
+
const global = globalThis;
|
|
64
|
+
return (global[INSTANCE] ?? (global[INSTANCE] = {}));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The application's read half, wherever it was created.
|
|
68
|
+
*
|
|
69
|
+
* `<Live>` needs it and has no way to be handed it: it is a component in a tree,
|
|
70
|
+
* not something the application calls. Kept beside the runtime it wraps, which is
|
|
71
|
+
* already a singleton for the same reason — one process, one set of endpoints.
|
|
72
|
+
*/
|
|
73
|
+
function currentNextNowity() {
|
|
74
|
+
return instanceSlot().current ?? null;
|
|
75
|
+
}
|
|
76
|
+
function createNextNowity(config) {
|
|
77
|
+
const ensure = () => {
|
|
78
|
+
const holder = slot();
|
|
79
|
+
return (holder.current ?? (holder.current = (0, runtime_1.createNowityRuntime)(config())));
|
|
80
|
+
};
|
|
81
|
+
const run = (session, render) => {
|
|
82
|
+
const runtime = ensure();
|
|
83
|
+
return (0, prerender_1.prerender)({ snapshots: runtime.snapshots, queries: runtime.api.queries }, session, render);
|
|
84
|
+
};
|
|
85
|
+
const session = async (as) => {
|
|
86
|
+
if (typeof as === "string")
|
|
87
|
+
return { clientId: `ssr:${as}`, userId: as, meta: {} };
|
|
88
|
+
if (as)
|
|
89
|
+
return as;
|
|
90
|
+
ensure(); // binds the application's Authenticator, if it has one
|
|
91
|
+
const authenticator = (0, ironbean_1.getBaseApplicationContext)().getBean(auth_1.Authenticator);
|
|
92
|
+
const result = await authenticator.authenticate(await requestOf());
|
|
93
|
+
const userId = result?.userId ?? null;
|
|
94
|
+
return { clientId: `ssr:${userId ?? "anonymous"}`, userId, meta: result?.meta ?? {} };
|
|
95
|
+
};
|
|
96
|
+
const instance = {
|
|
97
|
+
runtime: ensure,
|
|
98
|
+
prerender: (info, render) => run(info, render),
|
|
99
|
+
async read(render, options) {
|
|
100
|
+
return run(await session(options?.as), render);
|
|
101
|
+
},
|
|
102
|
+
session,
|
|
103
|
+
};
|
|
104
|
+
instanceSlot().current = instance;
|
|
105
|
+
return instance;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* This request, in the shape an {@link Authenticator} expects.
|
|
109
|
+
*
|
|
110
|
+
* `next/headers` is imported at call time and its absence is survivable: this
|
|
111
|
+
* module is also used outside a request — by a script, by a test — and there the
|
|
112
|
+
* caller says who it renders for.
|
|
113
|
+
*/
|
|
114
|
+
async function requestOf() {
|
|
115
|
+
try {
|
|
116
|
+
const { headers } = (await Promise.resolve().then(() => __importStar(require("next/headers"))));
|
|
117
|
+
const list = await headers();
|
|
118
|
+
const all = Object.fromEntries(list);
|
|
119
|
+
// Next puts the page's own address here; an application that
|
|
120
|
+
// authenticates from the URL needs it, and one that reads a cookie does
|
|
121
|
+
// not care that it is there.
|
|
122
|
+
return { url: all["x-invoke-path"] ?? all["referer"], headers: all };
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return { url: undefined, headers: {} };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-context.d.ts","sourceRoot":"","sources":["../../src/react/connection-context.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAoB1D,eAAO,MAAM,WAAW,8CAAyB,CAAC;AAElD,wBAAgB,cAAc,IAAI,WAAW,CAE5C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SourceScope = void 0;
|
|
5
|
+
exports.useQuerySource = useQuerySource;
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const connection_1 = require("../client/connection");
|
|
8
|
+
/**
|
|
9
|
+
* Where a subtree's queries are answered, when it is not the browser's socket.
|
|
10
|
+
*
|
|
11
|
+
* There is exactly one connection per browser session, which is why it is a
|
|
12
|
+
* singleton rather than a context — threading a provider through the tree bought
|
|
13
|
+
* nothing but a wrapper. Server rendering is the exception that needs one
|
|
14
|
+
* anyway: two requests render at the same time in the same process, each against
|
|
15
|
+
* its own session and its own snapshot, and a singleton would let one page read
|
|
16
|
+
* the other's data.
|
|
17
|
+
*
|
|
18
|
+
* So the context is empty in a browser — everything falls through to the
|
|
19
|
+
* singleton, exactly as before — and holds this request's own source while Next
|
|
20
|
+
* renders a page to HTML. What travels in it is a {@link QuerySource} rather
|
|
21
|
+
* than a connection: on the server those are not the same thing, and no
|
|
22
|
+
* component below is allowed to be able to tell.
|
|
23
|
+
*/
|
|
24
|
+
const SourceContext = (0, react_1.createContext)(null);
|
|
25
|
+
exports.SourceScope = SourceContext.Provider;
|
|
26
|
+
function useQuerySource() {
|
|
27
|
+
return (0, react_1.useContext)(SourceContext) ?? (0, connection_1.activeConnection)();
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
import { type VirtualProps } from "./virtual";
|
|
3
|
+
export interface GridListProps<T> extends VirtualProps<T> {
|
|
4
|
+
/** Fixed number of columns. Leave it out and `minItemWidth` decides. */
|
|
5
|
+
columns?: number;
|
|
6
|
+
/** Fit as many columns as this width allows. One column when neither is given. */
|
|
7
|
+
minItemWidth?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A virtualised grid over a live collection.
|
|
11
|
+
*
|
|
12
|
+
* It renders the rows the viewport covers and nothing else, which for a live
|
|
13
|
+
* collection is worth more than the rendering it saves: an item that is not on
|
|
14
|
+
* screen is not subscribed to either, so a table of a hundred thousand rows
|
|
15
|
+
* watches the forty a person is actually looking at. Scroll, and the windows
|
|
16
|
+
* that left the screen are released while the ones that entered it are opened.
|
|
17
|
+
*
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const documents = useList(DocumentApi).all(projectId);
|
|
20
|
+
* <GridList of={documents} itemHeight={72} minItemWidth={240}>
|
|
21
|
+
* {(row) => (row ? <Card row={row} /> : <Skeleton />)}
|
|
22
|
+
* </GridList>
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* The item is styled by whoever renders it; what this component owns is the
|
|
26
|
+
* geometry — how tall a row is, how many fit across, and which of them exist.
|
|
27
|
+
* `undefined` is a row whose window has not arrived, and it is an ordinary state
|
|
28
|
+
* rather than a failure: it is what a skeleton is for.
|
|
29
|
+
*
|
|
30
|
+
* {@link List} is the same component for one item per row, which is the shape
|
|
31
|
+
* that needs neither of the two props below.
|
|
32
|
+
*/
|
|
33
|
+
export declare const GridList: <T>(props: GridListProps<T>) => JSX.Element;
|
|
34
|
+
//# sourceMappingURL=grid-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid-list.d.ts","sourceRoot":"","sources":["../../src/react/grid-list.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,WAAW,aAAa,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IACrD,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kFAAkF;IAClF,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,QAAQ,EAIf,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.GridList = void 0;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const mobx_react_lite_1 = require("mobx-react-lite");
|
|
7
|
+
const virtual_1 = require("./virtual");
|
|
8
|
+
/**
|
|
9
|
+
* A virtualised grid over a live collection.
|
|
10
|
+
*
|
|
11
|
+
* It renders the rows the viewport covers and nothing else, which for a live
|
|
12
|
+
* collection is worth more than the rendering it saves: an item that is not on
|
|
13
|
+
* screen is not subscribed to either, so a table of a hundred thousand rows
|
|
14
|
+
* watches the forty a person is actually looking at. Scroll, and the windows
|
|
15
|
+
* that left the screen are released while the ones that entered it are opened.
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const documents = useList(DocumentApi).all(projectId);
|
|
19
|
+
* <GridList of={documents} itemHeight={72} minItemWidth={240}>
|
|
20
|
+
* {(row) => (row ? <Card row={row} /> : <Skeleton />)}
|
|
21
|
+
* </GridList>
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The item is styled by whoever renders it; what this component owns is the
|
|
25
|
+
* geometry — how tall a row is, how many fit across, and which of them exist.
|
|
26
|
+
* `undefined` is a row whose window has not arrived, and it is an ordinary state
|
|
27
|
+
* rather than a failure: it is what a skeleton is for.
|
|
28
|
+
*
|
|
29
|
+
* {@link List} is the same component for one item per row, which is the shape
|
|
30
|
+
* that needs neither of the two props below.
|
|
31
|
+
*/
|
|
32
|
+
exports.GridList = (0, mobx_react_lite_1.observer)(function GridList(props) {
|
|
33
|
+
return ((0, jsx_runtime_1.jsx)(virtual_1.Virtual, { ...props, columnsOf: (width) => columnsOf(props, width), template: template(props) }));
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* How many columns the arithmetic assumes. One until there is a width to say
|
|
37
|
+
* otherwise, which is only the render before the first measurement.
|
|
38
|
+
*/
|
|
39
|
+
function columnsOf(props, width) {
|
|
40
|
+
if (props.columns)
|
|
41
|
+
return Math.max(1, props.columns);
|
|
42
|
+
if (!props.minItemWidth || !width)
|
|
43
|
+
return 1;
|
|
44
|
+
const gap = props.gap ?? 0;
|
|
45
|
+
return Math.max(1, Math.floor((width + gap) / (props.minItemWidth + gap)));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* How many columns the browser draws — the same number, said in CSS.
|
|
49
|
+
*
|
|
50
|
+
* `auto-fill` computes exactly what {@link columnsOf} does, and it does it
|
|
51
|
+
* without a measurement, so the two agree by construction once one has been
|
|
52
|
+
* taken and the layout is right before one has. Saying it twice is the point:
|
|
53
|
+
* the arithmetic needs a number in JavaScript, and the first paint needs one
|
|
54
|
+
* before JavaScript has anything to measure.
|
|
55
|
+
*/
|
|
56
|
+
function template(props) {
|
|
57
|
+
if (props.columns)
|
|
58
|
+
return `repeat(${Math.max(1, props.columns)}, minmax(0, 1fr))`;
|
|
59
|
+
if (props.minItemWidth)
|
|
60
|
+
return `repeat(auto-fill, minmax(${props.minItemWidth}px, 1fr))`;
|
|
61
|
+
return "minmax(0, 1fr)";
|
|
62
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seeding the store with what a server render already read.
|
|
3
|
+
*
|
|
4
|
+
* There was a `<Hydrate payloads>` component here, and it went because there
|
|
5
|
+
* were two ways to say this and one of them was enough: `<NowityProvider
|
|
6
|
+
* hydrate={...}>` runs the very same function, at the very same point in the
|
|
7
|
+
* render, and is already in the tree. The path it served — `read()` in the page,
|
|
8
|
+
* payloads handed down — is also the one `<Live>` replaced, for a reason its own
|
|
9
|
+
* documentation gives: a page and the components under it drift, and that way of
|
|
10
|
+
* saying what a page reads went quietly back to a spinner rather than breaking.
|
|
11
|
+
*/
|
|
12
|
+
import type { QuerySource } from "../client/query-source";
|
|
13
|
+
import type { HydrationPayload } from "../core/protocol";
|
|
14
|
+
/**
|
|
15
|
+
* Apply a payload set once, however often this renders.
|
|
16
|
+
*
|
|
17
|
+
* Keyed on the payloads rather than on the component, because the connection
|
|
18
|
+
* outlives both a strict-mode double render and a remount — and re-applying then
|
|
19
|
+
* would push data the server has since replaced back over the live rows.
|
|
20
|
+
*/
|
|
21
|
+
export declare function hydrateOnce(source: QuerySource, payloads: HydrationPayload[] | undefined): void;
|
|
22
|
+
//# sourceMappingURL=hydrate.d.ts.map
|