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.
Files changed (192) hide show
  1. package/README.md +751 -0
  2. package/dist/api/contract.d.ts +186 -0
  3. package/dist/api/contract.d.ts.map +1 -0
  4. package/dist/api/contract.js +251 -0
  5. package/dist/api/errors.d.ts +50 -0
  6. package/dist/api/errors.d.ts.map +1 -0
  7. package/dist/api/errors.js +50 -0
  8. package/dist/api/index.d.ts +13 -0
  9. package/dist/api/index.d.ts.map +1 -0
  10. package/dist/api/index.js +32 -0
  11. package/dist/client/confirmed-store.d.ts +33 -0
  12. package/dist/client/confirmed-store.d.ts.map +1 -0
  13. package/dist/client/confirmed-store.js +123 -0
  14. package/dist/client/connection.d.ts +102 -0
  15. package/dist/client/connection.d.ts.map +1 -0
  16. package/dist/client/connection.js +285 -0
  17. package/dist/client/list.d.ts +102 -0
  18. package/dist/client/list.d.ts.map +1 -0
  19. package/dist/client/list.js +257 -0
  20. package/dist/client/live-query.d.ts +153 -0
  21. package/dist/client/live-query.d.ts.map +1 -0
  22. package/dist/client/live-query.js +244 -0
  23. package/dist/client/nowity-client.d.ts +188 -0
  24. package/dist/client/nowity-client.d.ts.map +1 -0
  25. package/dist/client/nowity-client.js +580 -0
  26. package/dist/client/null-transport.d.ts +16 -0
  27. package/dist/client/null-transport.d.ts.map +1 -0
  28. package/dist/client/null-transport.js +17 -0
  29. package/dist/client/overlay.d.ts +44 -0
  30. package/dist/client/overlay.d.ts.map +1 -0
  31. package/dist/client/overlay.js +90 -0
  32. package/dist/client/query-source.d.ts +78 -0
  33. package/dist/client/query-source.d.ts.map +1 -0
  34. package/dist/client/query-source.js +57 -0
  35. package/dist/client/ssr-source.d.ts +70 -0
  36. package/dist/client/ssr-source.d.ts.map +1 -0
  37. package/dist/client/ssr-source.js +134 -0
  38. package/dist/client/transport.d.ts +19 -0
  39. package/dist/client/transport.d.ts.map +1 -0
  40. package/dist/client/transport.js +2 -0
  41. package/dist/client/ws-transport.d.ts +30 -0
  42. package/dist/client/ws-transport.d.ts.map +1 -0
  43. package/dist/client/ws-transport.js +89 -0
  44. package/dist/client.d.ts +47 -0
  45. package/dist/client.d.ts.map +1 -0
  46. package/dist/client.js +80 -0
  47. package/dist/core/diff.d.ts +14 -0
  48. package/dist/core/diff.d.ts.map +1 -0
  49. package/dist/core/diff.js +56 -0
  50. package/dist/core/normalize.d.ts +16 -0
  51. package/dist/core/normalize.d.ts.map +1 -0
  52. package/dist/core/normalize.js +67 -0
  53. package/dist/core/protocol.d.ts +215 -0
  54. package/dist/core/protocol.d.ts.map +1 -0
  55. package/dist/core/protocol.js +14 -0
  56. package/dist/core/ssr-bridge.d.ts +69 -0
  57. package/dist/core/ssr-bridge.d.ts.map +1 -0
  58. package/dist/core/ssr-bridge.js +40 -0
  59. package/dist/core/types.d.ts +96 -0
  60. package/dist/core/types.d.ts.map +1 -0
  61. package/dist/core/types.js +17 -0
  62. package/dist/index.d.ts +47 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +98 -0
  65. package/dist/ironbean/client.d.ts +7 -0
  66. package/dist/ironbean/client.d.ts.map +1 -0
  67. package/dist/ironbean/client.js +38 -0
  68. package/dist/ironbean/server.d.ts +42 -0
  69. package/dist/ironbean/server.d.ts.map +1 -0
  70. package/dist/ironbean/server.js +62 -0
  71. package/dist/ironbean/tokens.d.ts +26 -0
  72. package/dist/ironbean/tokens.d.ts.map +1 -0
  73. package/dist/ironbean/tokens.js +23 -0
  74. package/dist/next/config.d.ts +7 -0
  75. package/dist/next/config.d.ts.map +1 -0
  76. package/dist/next/config.js +77 -0
  77. package/dist/next/live.d.ts +69 -0
  78. package/dist/next/live.d.ts.map +1 -0
  79. package/dist/next/live.js +70 -0
  80. package/dist/next/serve.d.ts +44 -0
  81. package/dist/next/serve.d.ts.map +1 -0
  82. package/dist/next/serve.js +107 -0
  83. package/dist/next/server.d.ts +62 -0
  84. package/dist/next/server.d.ts.map +1 -0
  85. package/dist/next/server.js +127 -0
  86. package/dist/react/connection-context.d.ts +4 -0
  87. package/dist/react/connection-context.d.ts.map +1 -0
  88. package/dist/react/connection-context.js +28 -0
  89. package/dist/react/grid-list.d.ts +34 -0
  90. package/dist/react/grid-list.d.ts.map +1 -0
  91. package/dist/react/grid-list.js +62 -0
  92. package/dist/react/hydrate.d.ts +22 -0
  93. package/dist/react/hydrate.d.ts.map +1 -0
  94. package/dist/react/hydrate.js +18 -0
  95. package/dist/react/index.d.ts +35 -0
  96. package/dist/react/index.d.ts.map +1 -0
  97. package/dist/react/index.js +51 -0
  98. package/dist/react/list.d.ts +31 -0
  99. package/dist/react/list.d.ts.map +1 -0
  100. package/dist/react/list.js +35 -0
  101. package/dist/react/prerendered.d.ts +33 -0
  102. package/dist/react/prerendered.d.ts.map +1 -0
  103. package/dist/react/prerendered.js +165 -0
  104. package/dist/react/provider.d.ts +64 -0
  105. package/dist/react/provider.d.ts.map +1 -0
  106. package/dist/react/provider.js +130 -0
  107. package/dist/react/refusals.d.ts +31 -0
  108. package/dist/react/refusals.d.ts.map +1 -0
  109. package/dist/react/refusals.js +51 -0
  110. package/dist/react/restricted.d.ts +76 -0
  111. package/dist/react/restricted.d.ts.map +1 -0
  112. package/dist/react/restricted.js +126 -0
  113. package/dist/react/use-list.d.ts +42 -0
  114. package/dist/react/use-list.d.ts.map +1 -0
  115. package/dist/react/use-list.js +56 -0
  116. package/dist/react/use-query.d.ts +66 -0
  117. package/dist/react/use-query.d.ts.map +1 -0
  118. package/dist/react/use-query.js +126 -0
  119. package/dist/react/virtual.d.ts +60 -0
  120. package/dist/react/virtual.d.ts.map +1 -0
  121. package/dist/react/virtual.js +131 -0
  122. package/dist/server/api/auth.d.ts +37 -0
  123. package/dist/server/api/auth.d.ts.map +1 -0
  124. package/dist/server/api/auth.js +54 -0
  125. package/dist/server/api/bridge.d.ts +28 -0
  126. package/dist/server/api/bridge.d.ts.map +1 -0
  127. package/dist/server/api/bridge.js +330 -0
  128. package/dist/server/api/collector.d.ts +25 -0
  129. package/dist/server/api/collector.d.ts.map +1 -0
  130. package/dist/server/api/collector.js +184 -0
  131. package/dist/server/api/configure.d.ts +31 -0
  132. package/dist/server/api/configure.d.ts.map +1 -0
  133. package/dist/server/api/configure.js +67 -0
  134. package/dist/server/api/execution.d.ts +77 -0
  135. package/dist/server/api/execution.d.ts.map +1 -0
  136. package/dist/server/api/execution.js +97 -0
  137. package/dist/server/api/list.d.ts +141 -0
  138. package/dist/server/api/list.d.ts.map +1 -0
  139. package/dist/server/api/list.js +281 -0
  140. package/dist/server/api/prerender.d.ts +32 -0
  141. package/dist/server/api/prerender.d.ts.map +1 -0
  142. package/dist/server/api/prerender.js +69 -0
  143. package/dist/server/api/read-keys.d.ts +128 -0
  144. package/dist/server/api/read-keys.d.ts.map +1 -0
  145. package/dist/server/api/read-keys.js +464 -0
  146. package/dist/server/api/read-set.d.ts +103 -0
  147. package/dist/server/api/read-set.d.ts.map +1 -0
  148. package/dist/server/api/read-set.js +210 -0
  149. package/dist/server/api/runtime.d.ts +36 -0
  150. package/dist/server/api/runtime.d.ts.map +1 -0
  151. package/dist/server/api/runtime.js +49 -0
  152. package/dist/server/api/tracked-client.d.ts +6 -0
  153. package/dist/server/api/tracked-client.d.ts.map +1 -0
  154. package/dist/server/api/tracked-client.js +56 -0
  155. package/dist/server/change-source/change-source.d.ts +41 -0
  156. package/dist/server/change-source/change-source.d.ts.map +1 -0
  157. package/dist/server/change-source/change-source.js +2 -0
  158. package/dist/server/change-source/outbox-change-source.d.ts +106 -0
  159. package/dist/server/change-source/outbox-change-source.d.ts.map +1 -0
  160. package/dist/server/change-source/outbox-change-source.js +237 -0
  161. package/dist/server/change-source/wal-change-source.d.ts +85 -0
  162. package/dist/server/change-source/wal-change-source.d.ts.map +1 -0
  163. package/dist/server/change-source/wal-change-source.js +193 -0
  164. package/dist/server/db.d.ts +51 -0
  165. package/dist/server/db.d.ts.map +1 -0
  166. package/dist/server/db.js +53 -0
  167. package/dist/server/evaluate.d.ts +39 -0
  168. package/dist/server/evaluate.d.ts.map +1 -0
  169. package/dist/server/evaluate.js +61 -0
  170. package/dist/server/invalidation-index.d.ts +64 -0
  171. package/dist/server/invalidation-index.d.ts.map +1 -0
  172. package/dist/server/invalidation-index.js +0 -0
  173. package/dist/server/mutator.d.ts +59 -0
  174. package/dist/server/mutator.d.ts.map +1 -0
  175. package/dist/server/mutator.js +77 -0
  176. package/dist/server/query.d.ts +113 -0
  177. package/dist/server/query.d.ts.map +1 -0
  178. package/dist/server/query.js +35 -0
  179. package/dist/server/setup.d.ts +30 -0
  180. package/dist/server/setup.d.ts.map +1 -0
  181. package/dist/server/setup.js +107 -0
  182. package/dist/server/sql/setup.sql +215 -0
  183. package/dist/server/ssr.d.ts +29 -0
  184. package/dist/server/ssr.d.ts.map +1 -0
  185. package/dist/server/ssr.js +43 -0
  186. package/dist/server/sync-engine.d.ts +256 -0
  187. package/dist/server/sync-engine.d.ts.map +1 -0
  188. package/dist/server/sync-engine.js +805 -0
  189. package/dist/server/ws-server.d.ts +56 -0
  190. package/dist/server/ws-server.d.ts.map +1 -0
  191. package/dist/server/ws-server.js +241 -0
  192. package/package.json +81 -0
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Core value types shared by the server sync engine and the browser client.
3
+ *
4
+ * Nothing in this file may import `pg`, `mobx` or `ws` — it is the only part of
5
+ * the library that both sides are allowed to depend on (see the "share
6
+ * interfaces, types, DTO / don't share DB services" rule in the design doc).
7
+ */
8
+ /** A database row, already normalised for transport (see `normalizeRow`). */
9
+ export type Row = Record<string, unknown>;
10
+ /** Stable string identity of an entity instance inside the identity map. */
11
+ export type EntityId = string;
12
+ export type ChangeOp = "insert" | "update" | "delete";
13
+ /** A value a read key may be compared by. See `server/api/read-keys`. */
14
+ export type KeyValue = string | number | boolean | null;
15
+ /**
16
+ * "This query read the rows whose `column` equals `value`."
17
+ *
18
+ * The unit of invalidation. A change whose row matches no key of a subscription
19
+ * cannot alter that subscription's result, so it never reaches the database.
20
+ */
21
+ export interface ReadKey {
22
+ column: string;
23
+ value: KeyValue;
24
+ }
25
+ /** Every row of the table is potentially read. */
26
+ export declare const ANY_ROWS: "any";
27
+ /** Which rows of one table an execution read, or {@link ANY_ROWS} if unknown. */
28
+ export type TableKeys = ReadKey[] | typeof ANY_ROWS;
29
+ /**
30
+ * Per-table read keys of one execution.
31
+ *
32
+ * A table absent from the map was not read at all. A table mapped to
33
+ * {@link ANY_ROWS} was read in a way that could not be narrowed — which is
34
+ * correct, merely as expensive as watching the whole table.
35
+ */
36
+ export type ReadKeySet = Map<string, TableKeys>;
37
+ /**
38
+ * One row-level change, as produced by a {@link ChangeSource}.
39
+ *
40
+ * A ChangeEvent is deliberately *not* a patch for the client. It is only an
41
+ * invalidation signal plus enough context to decide which live queries and
42
+ * which authorization scopes it touches.
43
+ */
44
+ export interface ChangeEvent {
45
+ table: string;
46
+ op: ChangeOp;
47
+ /** Primary key of the affected row, as `{ column: value }`. */
48
+ pk: Row;
49
+ before: Row | null;
50
+ after: Row | null;
51
+ /** Client that caused the change, when it came through a mutator. */
52
+ clientId: string | null;
53
+ /** Mutation id that caused the change, when it came through a mutator. */
54
+ mutationId: number | null;
55
+ /**
56
+ * Whether `before` is the complete previous row rather than just its key.
57
+ *
58
+ * It decides whether a row can be seen *leaving* a subscription's filter.
59
+ * The outbox trigger stores `to_jsonb(OLD)` and always has it; logical
60
+ * replication carries only the replica identity, which is the primary key
61
+ * unless the table is set to `REPLICA IDENTITY FULL`. Absent means "no", so
62
+ * a source that does not say degrades to watching whole columns rather than
63
+ * to missing changes.
64
+ */
65
+ beforeComplete?: boolean;
66
+ }
67
+ /**
68
+ * All changes of one database transaction, in commit order.
69
+ *
70
+ * Transactions are the unit of fan-out: the client applies a whole batch inside
71
+ * a single MobX action so no observer can ever see a torn transaction.
72
+ */
73
+ export interface TransactionBatch {
74
+ /**
75
+ * Opaque resume token identifying the stream position *after* this batch.
76
+ * `xid` for the outbox source, an LSN for the WAL source.
77
+ */
78
+ position: string;
79
+ /** Database transaction id (or LSN), for logging and ordering assertions. */
80
+ xid: string;
81
+ events: ChangeEvent[];
82
+ }
83
+ /** Field-level upsert for a single entity instance. */
84
+ export interface RowPatch {
85
+ id: EntityId;
86
+ /** Only the fields that actually changed (on insert: all of them). */
87
+ fields: Row;
88
+ }
89
+ /** Difference between two consecutive results of the same live query. */
90
+ export interface SetDiff {
91
+ upsert: RowPatch[];
92
+ remove: EntityId[];
93
+ }
94
+ /** True when the diff would not change anything on the client. */
95
+ export declare function isEmptyDiff(diff: SetDiff): boolean;
96
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,6EAA6E;AAC7E,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,4EAA4E;AAC5E,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEtD,yEAAyE;AACzE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAExD;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC;CACnB;AAED,kDAAkD;AAClD,eAAO,MAAM,QAAQ,EAAG,KAAc,CAAC;AAEvC,iFAAiF;AACjF,MAAM,MAAM,SAAS,GAAG,OAAO,EAAE,GAAG,OAAO,QAAQ,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,QAAQ,CAAC;IACb,+DAA+D;IAC/D,EAAE,EAAE,GAAG,CAAC;IACR,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;IACnB,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IAClB,qEAAqE;IACrE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,0EAA0E;IAC1E,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;;;;;;;OASG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,6EAA6E;IAC7E,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,uDAAuD;AACvD,MAAM,WAAW,QAAQ;IACrB,EAAE,EAAE,QAAQ,CAAC;IACb,sEAAsE;IACtE,MAAM,EAAE,GAAG,CAAC;CACf;AAED,yEAAyE;AACzE,MAAM,WAAW,OAAO;IACpB,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,MAAM,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAElD"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * Core value types shared by the server sync engine and the browser client.
4
+ *
5
+ * Nothing in this file may import `pg`, `mobx` or `ws` — it is the only part of
6
+ * the library that both sides are allowed to depend on (see the "share
7
+ * interfaces, types, DTO / don't share DB services" rule in the design doc).
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ANY_ROWS = void 0;
11
+ exports.isEmptyDiff = isEmptyDiff;
12
+ /** Every row of the table is potentially read. */
13
+ exports.ANY_ROWS = "any";
14
+ /** True when the diff would not change anything on the client. */
15
+ function isEmptyDiff(diff) {
16
+ return diff.upsert.length === 0 && diff.remove.length === 0;
17
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Nowity — a realtime framework over PostgreSQL, Ironbean and Next.
3
+ *
4
+ * PostgreSQL is the source of truth, changes reach the browser as field-level
5
+ * patches batched per transaction, and the browser holds live MobX objects rather
6
+ * than JSON snapshots.
7
+ *
8
+ * There are two entry points. This one is everything that runs in a server
9
+ * process — the sync server, the Next integration, the schema setup — and
10
+ * `nowity/client` is everything the browser bundles. The line between them is
11
+ * not a matter of taste: this module reaches `pg`, `ws` and Prisma, so a client
12
+ * component importing from it would pull sixty-odd server modules into the
13
+ * bundle. `test/scenarios/16` fails if that ever becomes possible.
14
+ *
15
+ * Contracts and errors are in both, because they are the one thing both halves
16
+ * genuinely share, and it is the same module behind either path.
17
+ *
18
+ * Everything under `src/server` and `src/client` that is not re-exported here is
19
+ * the engine: the change stream, the sync engine, the store, the wire protocol.
20
+ * It is not part of the framework's surface, and it moves without notice.
21
+ */
22
+ export { api, contract, query, list, mutation, contractOf, endpointName, pageQuery, countQuery, type ApiManifest, type ContractMeta, type EndpointKind, type ListOptions, type MutationOptions, type QueryOptions, } from "./api/contract";
23
+ export { Forbidden, Rejected, isForbidden, isRejected } from "./api/errors";
24
+ export { createNowityServer, type NowityServer, type NowityServerConfig, } from "./server/api/configure";
25
+ export { createNowityRuntime, type NowityRuntime, type NowityRuntimeConfig, } from "./server/api/runtime";
26
+ export { Session } from "./server/api/execution";
27
+ export { Authenticator, AnonymousAuthenticator } from "./server/api/auth";
28
+ export type { AuthRequest, AuthResult } from "./server/ws-server";
29
+ export type { SessionInfo } from "./server/query";
30
+ export { prerender, type PrerenderError, type PrerenderGet, type PrerenderResult, } from "./server/api/prerender";
31
+ /** Where changes come from. The outbox is the default; the WAL needs `wal2json`. */
32
+ export { OutboxChangeSource, type OutboxChangeSourceOptions, } from "./server/change-source/outbox-change-source";
33
+ export { WalChangeSource, type WalChangeSourceOptions, } from "./server/change-source/wal-change-source";
34
+ export type { ChangeSource } from "./server/change-source/change-source";
35
+ /** Schema setup: the outbox triggers every tracked table needs. */
36
+ export { setupNowity, trackTable, untrackTable, setReplicaIdentityFull, type TrackedTables, } from "./server/setup";
37
+ export { createNextNowity, currentNextNowity, type NextNowity, type ReadAs, type ReadOptions, } from "./next/server";
38
+ export { Live, type LiveProps } from "./next/live";
39
+ export { serveNext, type ServeNextOptions, type ServedNext } from "./next/serve";
40
+ export { withNowity, type NowityNextConfig } from "./next/config";
41
+ export { configureNowityServer, type NowityServerContainerConfig } from "./ironbean/server";
42
+ export * from "./ironbean/tokens";
43
+ export { NowityConnection, activeConnection, currentConnection, type NowityConnectionOptions, type QueryError, } from "./client/connection";
44
+ export { WebSocketTransport, type WebSocketTransportOptions } from "./client/ws-transport";
45
+ export type { EntityId, Row } from "./core/types";
46
+ export type { HydrationPayload } from "./core/protocol";
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EACH,GAAG,EACH,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,YAAY,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG5E,OAAO,EACH,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,GAC1B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,mBAAmB,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EACH,SAAS,EACT,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,eAAe,GACvB,MAAM,wBAAwB,CAAC;AAEhC,oFAAoF;AACpF,OAAO,EACH,kBAAkB,EAClB,KAAK,yBAAyB,GACjC,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACH,eAAe,EACf,KAAK,sBAAsB,GAC9B,MAAM,0CAA0C,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEzE,mEAAmE;AACnE,OAAO,EACH,WAAW,EACX,UAAU,EACV,YAAY,EACZ,sBAAsB,EACtB,KAAK,aAAa,GACrB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACH,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,WAAW,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGlE,OAAO,EAAE,qBAAqB,EAAE,KAAK,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAC5F,cAAc,mBAAmB,CAAC;AAGlC,OAAO,EACH,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,uBAAuB,EAC5B,KAAK,UAAU,GAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAG3F,YAAY,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAClD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /**
3
+ * Nowity — a realtime framework over PostgreSQL, Ironbean and Next.
4
+ *
5
+ * PostgreSQL is the source of truth, changes reach the browser as field-level
6
+ * patches batched per transaction, and the browser holds live MobX objects rather
7
+ * than JSON snapshots.
8
+ *
9
+ * There are two entry points. This one is everything that runs in a server
10
+ * process — the sync server, the Next integration, the schema setup — and
11
+ * `nowity/client` is everything the browser bundles. The line between them is
12
+ * not a matter of taste: this module reaches `pg`, `ws` and Prisma, so a client
13
+ * component importing from it would pull sixty-odd server modules into the
14
+ * bundle. `test/scenarios/16` fails if that ever becomes possible.
15
+ *
16
+ * Contracts and errors are in both, because they are the one thing both halves
17
+ * genuinely share, and it is the same module behind either path.
18
+ *
19
+ * Everything under `src/server` and `src/client` that is not re-exported here is
20
+ * the engine: the change stream, the sync engine, the store, the wire protocol.
21
+ * It is not part of the framework's surface, and it moves without notice.
22
+ */
23
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.WebSocketTransport = exports.currentConnection = exports.activeConnection = exports.NowityConnection = exports.configureNowityServer = exports.withNowity = exports.serveNext = exports.Live = exports.currentNextNowity = exports.createNextNowity = exports.setReplicaIdentityFull = exports.untrackTable = exports.trackTable = exports.setupNowity = exports.WalChangeSource = exports.OutboxChangeSource = exports.prerender = exports.AnonymousAuthenticator = exports.Authenticator = exports.Session = exports.createNowityRuntime = exports.createNowityServer = exports.isRejected = exports.isForbidden = exports.Rejected = exports.Forbidden = exports.countQuery = exports.pageQuery = exports.endpointName = exports.contractOf = exports.mutation = exports.list = exports.query = exports.contract = exports.api = void 0;
39
+ // ------------------------------------------------------------------- contracts
40
+ var contract_1 = require("./api/contract");
41
+ Object.defineProperty(exports, "api", { enumerable: true, get: function () { return contract_1.api; } });
42
+ Object.defineProperty(exports, "contract", { enumerable: true, get: function () { return contract_1.contract; } });
43
+ Object.defineProperty(exports, "query", { enumerable: true, get: function () { return contract_1.query; } });
44
+ Object.defineProperty(exports, "list", { enumerable: true, get: function () { return contract_1.list; } });
45
+ Object.defineProperty(exports, "mutation", { enumerable: true, get: function () { return contract_1.mutation; } });
46
+ Object.defineProperty(exports, "contractOf", { enumerable: true, get: function () { return contract_1.contractOf; } });
47
+ Object.defineProperty(exports, "endpointName", { enumerable: true, get: function () { return contract_1.endpointName; } });
48
+ Object.defineProperty(exports, "pageQuery", { enumerable: true, get: function () { return contract_1.pageQuery; } });
49
+ Object.defineProperty(exports, "countQuery", { enumerable: true, get: function () { return contract_1.countQuery; } });
50
+ var errors_1 = require("./api/errors");
51
+ Object.defineProperty(exports, "Forbidden", { enumerable: true, get: function () { return errors_1.Forbidden; } });
52
+ Object.defineProperty(exports, "Rejected", { enumerable: true, get: function () { return errors_1.Rejected; } });
53
+ Object.defineProperty(exports, "isForbidden", { enumerable: true, get: function () { return errors_1.isForbidden; } });
54
+ Object.defineProperty(exports, "isRejected", { enumerable: true, get: function () { return errors_1.isRejected; } });
55
+ // ---------------------------------------------------------------------- server
56
+ var configure_1 = require("./server/api/configure");
57
+ Object.defineProperty(exports, "createNowityServer", { enumerable: true, get: function () { return configure_1.createNowityServer; } });
58
+ var runtime_1 = require("./server/api/runtime");
59
+ Object.defineProperty(exports, "createNowityRuntime", { enumerable: true, get: function () { return runtime_1.createNowityRuntime; } });
60
+ var execution_1 = require("./server/api/execution");
61
+ Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return execution_1.Session; } });
62
+ var auth_1 = require("./server/api/auth");
63
+ Object.defineProperty(exports, "Authenticator", { enumerable: true, get: function () { return auth_1.Authenticator; } });
64
+ Object.defineProperty(exports, "AnonymousAuthenticator", { enumerable: true, get: function () { return auth_1.AnonymousAuthenticator; } });
65
+ var prerender_1 = require("./server/api/prerender");
66
+ Object.defineProperty(exports, "prerender", { enumerable: true, get: function () { return prerender_1.prerender; } });
67
+ /** Where changes come from. The outbox is the default; the WAL needs `wal2json`. */
68
+ var outbox_change_source_1 = require("./server/change-source/outbox-change-source");
69
+ Object.defineProperty(exports, "OutboxChangeSource", { enumerable: true, get: function () { return outbox_change_source_1.OutboxChangeSource; } });
70
+ var wal_change_source_1 = require("./server/change-source/wal-change-source");
71
+ Object.defineProperty(exports, "WalChangeSource", { enumerable: true, get: function () { return wal_change_source_1.WalChangeSource; } });
72
+ /** Schema setup: the outbox triggers every tracked table needs. */
73
+ var setup_1 = require("./server/setup");
74
+ Object.defineProperty(exports, "setupNowity", { enumerable: true, get: function () { return setup_1.setupNowity; } });
75
+ Object.defineProperty(exports, "trackTable", { enumerable: true, get: function () { return setup_1.trackTable; } });
76
+ Object.defineProperty(exports, "untrackTable", { enumerable: true, get: function () { return setup_1.untrackTable; } });
77
+ Object.defineProperty(exports, "setReplicaIdentityFull", { enumerable: true, get: function () { return setup_1.setReplicaIdentityFull; } });
78
+ // ------------------------------------------------------------------------ next
79
+ var server_1 = require("./next/server");
80
+ Object.defineProperty(exports, "createNextNowity", { enumerable: true, get: function () { return server_1.createNextNowity; } });
81
+ Object.defineProperty(exports, "currentNextNowity", { enumerable: true, get: function () { return server_1.currentNextNowity; } });
82
+ var live_1 = require("./next/live");
83
+ Object.defineProperty(exports, "Live", { enumerable: true, get: function () { return live_1.Live; } });
84
+ var serve_1 = require("./next/serve");
85
+ Object.defineProperty(exports, "serveNext", { enumerable: true, get: function () { return serve_1.serveNext; } });
86
+ var config_1 = require("./next/config");
87
+ Object.defineProperty(exports, "withNowity", { enumerable: true, get: function () { return config_1.withNowity; } });
88
+ // -------------------------------------------------------------------- ironbean
89
+ var server_2 = require("./ironbean/server");
90
+ Object.defineProperty(exports, "configureNowityServer", { enumerable: true, get: function () { return server_2.configureNowityServer; } });
91
+ __exportStar(require("./ironbean/tokens"), exports);
92
+ // ---------------------------------------------------------------------- client
93
+ var connection_1 = require("./client/connection");
94
+ Object.defineProperty(exports, "NowityConnection", { enumerable: true, get: function () { return connection_1.NowityConnection; } });
95
+ Object.defineProperty(exports, "activeConnection", { enumerable: true, get: function () { return connection_1.activeConnection; } });
96
+ Object.defineProperty(exports, "currentConnection", { enumerable: true, get: function () { return connection_1.currentConnection; } });
97
+ var ws_transport_1 = require("./client/ws-transport");
98
+ Object.defineProperty(exports, "WebSocketTransport", { enumerable: true, get: function () { return ws_transport_1.WebSocketTransport; } });
@@ -0,0 +1,7 @@
1
+ import { NowityConnection, type NowityConnectionOptions } from "../client/connection";
2
+ export interface NowityClientContainerConfig extends NowityConnectionOptions {
3
+ /** Connect as soon as the container is configured. Default: true. */
4
+ autoConnect?: boolean;
5
+ }
6
+ export declare function configureNowityClient(config: NowityClientContainerConfig): NowityConnection;
7
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ironbean/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,gBAAgB,EAEhB,KAAK,uBAAuB,EAC/B,MAAM,sBAAsB,CAAC;AAG9B,MAAM,WAAW,2BAA4B,SAAQ,uBAAuB;IACxE,qEAAqE;IACrE,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,2BAA2B,GAAG,gBAAgB,CAgC3F"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureNowityClient = configureNowityClient;
4
+ const ironbean_1 = require("ironbean");
5
+ const contract_1 = require("../api/contract");
6
+ const connection_1 = require("../client/connection");
7
+ const tokens_1 = require("./tokens");
8
+ function configureNowityClient(config) {
9
+ const connection = new connection_1.NowityConnection(config);
10
+ (0, connection_1.setActiveConnection)(connection);
11
+ (0, ironbean_1.take)(connection_1.NowityConnection).setType(ironbean_1.ComponentType.Singleton);
12
+ (0, ironbean_1.take)(connection_1.NowityConnection).setFactory(() => connection);
13
+ (0, ironbean_1.take)(tokens_1.NowityClientToken).setType(ironbean_1.ComponentType.Singleton);
14
+ (0, ironbean_1.take)(tokens_1.NowityClientToken).setFactory(() => connection.client);
15
+ // Contracts are bound eagerly: a container cannot intercept a token it has
16
+ // never heard of, so a contract module imported after this call would resolve
17
+ // to nothing. Importing them is the registration, so import them first.
18
+ //
19
+ // Singletons, because a service is one thing: two proxies over one socket
20
+ // would be two objects claiming to be the same service, and anything that
21
+ // compared them — a memo, a map keyed by the service — would be wrong. The
22
+ // connection caches its proxies anyway; saying so here is what makes the
23
+ // container agree.
24
+ for (const contract of (0, contract_1.knownContracts)()) {
25
+ // Not cleared first, deliberately. A token already bound to an
26
+ // implementation keeps it, and this factory is then ignored — which is
27
+ // the right way round for the one process that has both halves: a
28
+ // headless check, a test, a page rendered in the server. There the
29
+ // server must keep its implementations, and components read through the
30
+ // connection anyway (`useService` asks the container only for a
31
+ // connection it configured itself).
32
+ (0, ironbean_1.take)(contract.contract).setType(ironbean_1.ComponentType.Singleton);
33
+ (0, ironbean_1.take)(contract.contract).setFactory(() => connection.contract(contract.name));
34
+ }
35
+ if (config.autoConnect !== false)
36
+ connection.connect();
37
+ return connection;
38
+ }
@@ -0,0 +1,42 @@
1
+ import type { ChangeEvent } from "../core/types";
2
+ import type { ChangeSource } from "../server/change-source/change-source";
3
+ import type { SnapshotRunner } from "../server/db";
4
+ import { MutatorRegistry, type WriteRunner } from "../server/mutator";
5
+ import { QueryRegistry } from "../server/query";
6
+ import { type NowitySyncServerOptions } from "../server/ws-server";
7
+ export interface NowityServerContainerConfig {
8
+ snapshots: SnapshotRunner | (() => SnapshotRunner);
9
+ writes: WriteRunner | (() => WriteRunner);
10
+ changeSource: ChangeSource | (() => ChangeSource);
11
+ /** Register the application's live queries. Called once, lazily. */
12
+ defineQueries?: (queries: QueryRegistry) => void;
13
+ /** Register the application's mutators. Called once, lazily. */
14
+ defineMutators?: (mutators: MutatorRegistry) => void;
15
+ permissionTables?: string[];
16
+ scopeOfChange?: (event: ChangeEvent) => string | string[] | null;
17
+ /** WebSocket front end options, minus the engine (which is injected). */
18
+ syncServer?: Omit<NowitySyncServerOptions, "engine">;
19
+ onError?: (err: Error) => void;
20
+ }
21
+ /**
22
+ * Bind the **server** half of Nowity into the Ironbean container.
23
+ *
24
+ * Import this module only from server code. It pulls in the sync engine, which
25
+ * pulls in database access — exactly the things the design doc says must not be
26
+ * shared with the browser container.
27
+ *
28
+ * ```ts
29
+ * configureNowityServer({
30
+ * snapshots: () => new PgSnapshotRunner(pool),
31
+ * writes: () => new PgWriteRunner(pool),
32
+ * changeSource: () => new OutboxChangeSource({ pool }),
33
+ * defineQueries, defineMutators,
34
+ * permissionTables: ["ProjectMember", "Project"],
35
+ * });
36
+ *
37
+ * const engine = getBaseApplicationContext().getBean(SyncEngineToken);
38
+ * await engine.start();
39
+ * ```
40
+ */
41
+ export declare function configureNowityServer(config: NowityServerContainerConfig): void;
42
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/ironbean/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAoB,KAAK,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAWrF,MAAM,WAAW,2BAA2B;IACxC,SAAS,EAAE,cAAc,GAAG,CAAC,MAAM,cAAc,CAAC,CAAC;IACnD,MAAM,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,CAAC,CAAC;IAC1C,YAAY,EAAE,YAAY,GAAG,CAAC,MAAM,YAAY,CAAC,CAAC;IAClD,oEAAoE;IACpE,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;IACjD,gEAAgE;IAChE,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;IACrD,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;IACjE,yEAAyE;IACzE,UAAU,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CAAC;IACrD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,2BAA2B,GAAG,IAAI,CAuC/E"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureNowityServer = configureNowityServer;
4
+ const ironbean_1 = require("ironbean");
5
+ const mutator_1 = require("../server/mutator");
6
+ const query_1 = require("../server/query");
7
+ const sync_engine_1 = require("../server/sync-engine");
8
+ const ws_server_1 = require("../server/ws-server");
9
+ const tokens_1 = require("./tokens");
10
+ /**
11
+ * Bind the **server** half of Nowity into the Ironbean container.
12
+ *
13
+ * Import this module only from server code. It pulls in the sync engine, which
14
+ * pulls in database access — exactly the things the design doc says must not be
15
+ * shared with the browser container.
16
+ *
17
+ * ```ts
18
+ * configureNowityServer({
19
+ * snapshots: () => new PgSnapshotRunner(pool),
20
+ * writes: () => new PgWriteRunner(pool),
21
+ * changeSource: () => new OutboxChangeSource({ pool }),
22
+ * defineQueries, defineMutators,
23
+ * permissionTables: ["ProjectMember", "Project"],
24
+ * });
25
+ *
26
+ * const engine = getBaseApplicationContext().getBean(SyncEngineToken);
27
+ * await engine.start();
28
+ * ```
29
+ */
30
+ function configureNowityServer(config) {
31
+ (0, ironbean_1.take)(tokens_1.SnapshotRunnerToken).setFactory(() => resolve(config.snapshots));
32
+ (0, ironbean_1.take)(tokens_1.WriteRunnerToken).setFactory(() => resolve(config.writes));
33
+ (0, ironbean_1.take)(tokens_1.ChangeSourceToken).setFactory(() => resolve(config.changeSource));
34
+ (0, ironbean_1.take)(tokens_1.QueryRegistryToken).setFactory(() => {
35
+ const queries = new query_1.QueryRegistry();
36
+ config.defineQueries?.(queries);
37
+ return queries;
38
+ });
39
+ (0, ironbean_1.take)(tokens_1.MutatorRegistryToken).setFactory(() => {
40
+ const mutators = new mutator_1.MutatorRegistry();
41
+ config.defineMutators?.(mutators);
42
+ return mutators;
43
+ });
44
+ (0, ironbean_1.take)(tokens_1.SyncEngineToken).setFactory((context) => new sync_engine_1.SyncEngine({
45
+ snapshots: context.getBean(tokens_1.SnapshotRunnerToken),
46
+ writes: context.getBean(tokens_1.WriteRunnerToken),
47
+ source: context.getBean(tokens_1.ChangeSourceToken),
48
+ queries: context.getBean(tokens_1.QueryRegistryToken),
49
+ mutators: context.getBean(tokens_1.MutatorRegistryToken),
50
+ permissionTables: config.permissionTables,
51
+ scopeOfChange: config.scopeOfChange,
52
+ onError: config.onError,
53
+ }));
54
+ (0, ironbean_1.take)(tokens_1.SyncServerToken).setFactory((context) => new ws_server_1.NowitySyncServer({
55
+ ...config.syncServer,
56
+ engine: context.getBean(tokens_1.SyncEngineToken),
57
+ onError: config.syncServer?.onError ?? config.onError,
58
+ }));
59
+ }
60
+ function resolve(value) {
61
+ return typeof value === "function" ? value() : value;
62
+ }
@@ -0,0 +1,26 @@
1
+ import { DependencyToken } from "ironbean";
2
+ import type { NowityClient } from "../client/nowity-client";
3
+ import type { ChangeSource } from "../server/change-source/change-source";
4
+ import type { SnapshotRunner } from "../server/db";
5
+ import type { MutatorRegistry, WriteRunner } from "../server/mutator";
6
+ import type { QueryRegistry } from "../server/query";
7
+ import type { SyncEngine } from "../server/sync-engine";
8
+ import type { NowitySyncServer } from "../server/ws-server";
9
+ /**
10
+ * Dependency tokens for wiring Nowity into an [[Ironbean]] container.
11
+ *
12
+ * Only tokens live here — every reference to a server class is a *type* import,
13
+ * erased at compile time. That is what lets the browser bundle import
14
+ * {@link NowityClientToken} without dragging `pg` in with it, and it is the same
15
+ * rule the design doc states for the two containers: share interfaces and types,
16
+ * never database services.
17
+ */
18
+ export declare const QueryRegistryToken: DependencyToken<QueryRegistry>;
19
+ export declare const MutatorRegistryToken: DependencyToken<MutatorRegistry>;
20
+ export declare const SnapshotRunnerToken: DependencyToken<SnapshotRunner>;
21
+ export declare const WriteRunnerToken: DependencyToken<WriteRunner>;
22
+ export declare const ChangeSourceToken: DependencyToken<ChangeSource>;
23
+ export declare const SyncEngineToken: DependencyToken<SyncEngine>;
24
+ export declare const SyncServerToken: DependencyToken<NowitySyncServer>;
25
+ export declare const NowityClientToken: DependencyToken<NowityClient>;
26
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/ironbean/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;;;;GAQG;AAGH,eAAO,MAAM,kBAAkB,gCAA0D,CAAC;AAC1F,eAAO,MAAM,oBAAoB,kCAA6D,CAAC;AAC/F,eAAO,MAAM,mBAAmB,iCAA6D,CAAC;AAC9F,eAAO,MAAM,gBAAgB,8BAAuD,CAAC;AACrF,eAAO,MAAM,iBAAiB,+BAA8D,CAAC;AAC7F,eAAO,MAAM,eAAe,6BAAsD,CAAC;AACnF,eAAO,MAAM,eAAe,mCAAgE,CAAC;AAG7F,eAAO,MAAM,iBAAiB,+BAAwD,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NowityClientToken = exports.SyncServerToken = exports.SyncEngineToken = exports.ChangeSourceToken = exports.WriteRunnerToken = exports.SnapshotRunnerToken = exports.MutatorRegistryToken = exports.QueryRegistryToken = void 0;
4
+ const ironbean_1 = require("ironbean");
5
+ /**
6
+ * Dependency tokens for wiring Nowity into an [[Ironbean]] container.
7
+ *
8
+ * Only tokens live here — every reference to a server class is a *type* import,
9
+ * erased at compile time. That is what lets the browser bundle import
10
+ * {@link NowityClientToken} without dragging `pg` in with it, and it is the same
11
+ * rule the design doc states for the two containers: share interfaces and types,
12
+ * never database services.
13
+ */
14
+ // ------------------------------------------------------------------ server side
15
+ exports.QueryRegistryToken = ironbean_1.DependencyToken.create("nowity.queries");
16
+ exports.MutatorRegistryToken = ironbean_1.DependencyToken.create("nowity.mutators");
17
+ exports.SnapshotRunnerToken = ironbean_1.DependencyToken.create("nowity.snapshots");
18
+ exports.WriteRunnerToken = ironbean_1.DependencyToken.create("nowity.writes");
19
+ exports.ChangeSourceToken = ironbean_1.DependencyToken.create("nowity.changeSource");
20
+ exports.SyncEngineToken = ironbean_1.DependencyToken.create("nowity.engine");
21
+ exports.SyncServerToken = ironbean_1.DependencyToken.create("nowity.syncServer");
22
+ // ------------------------------------------------------------------ client side
23
+ exports.NowityClientToken = ironbean_1.DependencyToken.create("nowity.client");
@@ -0,0 +1,7 @@
1
+ export interface NowityNextConfig {
2
+ serverExternalPackages?: string[];
3
+ turbopack?: Record<string, unknown>;
4
+ [key: string]: unknown;
5
+ }
6
+ export declare function withNowity(config?: NowityNextConfig): NowityNextConfig;
7
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/next/config.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,gBAAgB;IAC7B,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAID,wBAAgB,UAAU,CAAC,MAAM,GAAE,gBAAqB,GAAG,gBAAgB,CAM1E"}
@@ -0,0 +1,77 @@
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.withNowity = withNowity;
37
+ /**
38
+ * The Next config Nowity needs, so an application does not have to know it.
39
+ *
40
+ * ```js
41
+ * // next.config.mjs
42
+ * import { withNowity } from "nowity";
43
+ * export default withNowity();
44
+ * ```
45
+ *
46
+ * Two things, both about the server build: `pg`, `ws` and Prisma must stay
47
+ * external rather than be bundled — they are native or optional-peer-laden —
48
+ * and files outside the application root have to be reachable at all.
49
+ */
50
+ const path = __importStar(require("path"));
51
+ const EXTERNAL = ["pg", "ws", "pg-logical-replication", "@prisma/client"];
52
+ function withNowity(config = {}) {
53
+ return {
54
+ ...config,
55
+ serverExternalPackages: [...EXTERNAL, ...(config.serverExternalPackages ?? [])],
56
+ turbopack: { ...turbopackRoot(), ...config.turbopack },
57
+ };
58
+ }
59
+ /**
60
+ * Turbopack resolves nothing above its root, and the root it finds on its own is
61
+ * the directory holding the lockfile — the application's. A Nowity installed
62
+ * from the registry lives under it and needs no help; one linked from a checkout
63
+ * beside the application does not, and every file in it would fail to resolve.
64
+ *
65
+ * So: widen the root to the nearest directory containing both, and only then.
66
+ */
67
+ function turbopackRoot() {
68
+ const app = process.cwd();
69
+ const lib = path.resolve(__dirname, "..", "..");
70
+ if (lib === app || lib.startsWith(app + path.sep))
71
+ return {};
72
+ const [appParts, libParts] = [app, lib].map((dir) => dir.split(path.sep));
73
+ let shared = 0;
74
+ while (shared < appParts.length && appParts[shared] === libParts[shared])
75
+ shared++;
76
+ return { root: appParts.slice(0, shared).join(path.sep) || path.sep };
77
+ }