ignotum 0.0.0 → 0.0.2
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 +161 -0
- package/dist/cli/bin.d.mts +1 -0
- package/dist/cli/bin.mjs +1696 -0
- package/dist/cli/bin.mjs.map +1 -0
- package/dist/runtime/api-BXXIZc_Q.js +119 -0
- package/dist/runtime/api-BXXIZc_Q.js.map +1 -0
- package/dist/runtime/api-Cpx57mk3.d.ts +47 -0
- package/dist/runtime/client/jsx-dev-runtime.d.ts +2 -0
- package/dist/runtime/client/jsx-dev-runtime.js +2 -0
- package/dist/runtime/client/jsx-runtime.d.ts +2 -0
- package/dist/runtime/client/jsx-runtime.js +2 -0
- package/dist/runtime/client.d.ts +29 -0
- package/dist/runtime/client.js +364 -0
- package/dist/runtime/client.js.map +1 -0
- package/dist/runtime/index-BgWROoyk.d.ts +249 -0
- package/dist/runtime/internal/api.d.ts +2 -0
- package/dist/runtime/internal/api.js +2 -0
- package/dist/runtime/internal/server.d.ts +6 -0
- package/dist/runtime/internal/server.js +7 -0
- package/dist/runtime/internal/server.js.map +1 -0
- package/dist/runtime/internal/types.d.ts +2 -0
- package/dist/runtime/internal/types.js +2 -0
- package/dist/runtime/result-B2W-z2wG.js +136 -0
- package/dist/runtime/result-B2W-z2wG.js.map +1 -0
- package/dist/runtime/result-C1ZdsM6Y.d.ts +106 -0
- package/dist/runtime/schema-CNEVLF7D.js +116 -0
- package/dist/runtime/schema-CNEVLF7D.js.map +1 -0
- package/dist/runtime/server.d.ts +9 -0
- package/dist/runtime/server.js +9 -0
- package/dist/runtime/server.js.map +1 -0
- package/package.json +81 -2
- package/src/cli/agent-files.ts +35 -0
- package/src/cli/bin.ts +5 -0
- package/src/cli/client-plugin.ts +66 -0
- package/src/cli/codegen.ts +203 -0
- package/src/cli/command.ts +155 -0
- package/src/cli/dev.ts +206 -0
- package/src/cli/new-project.ts +377 -0
- package/src/cli/package-manager.ts +55 -0
- package/src/client/errors.ts +83 -0
- package/src/client/hooks.ts +141 -0
- package/src/client/index.ts +90 -0
- package/src/client/jsx-dev-runtime.ts +2 -0
- package/src/client/jsx-runtime.ts +2 -0
- package/src/client/query.ts +17 -0
- package/src/client/sync.ts +487 -0
- package/src/dev-runtime/database.ts +374 -0
- package/src/dev-runtime/dev-database.ts +199 -0
- package/src/dev-runtime/functions.ts +293 -0
- package/src/dev-runtime/id.ts +11 -0
- package/src/dev-runtime/sync.ts +473 -0
- package/src/internal/api.ts +141 -0
- package/src/internal/http-paths.ts +5 -0
- package/src/internal/server.ts +3 -0
- package/src/internal/types.ts +2 -0
- package/src/raw.d.ts +4 -0
- package/src/server/index.ts +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Ignotum
|
|
2
|
+
|
|
3
|
+
Ignotum is an opinionated TypeScript application cloud. Define a schema, queries, and mutations,
|
|
4
|
+
then call them from the client with end-to-end types and realtime updates.
|
|
5
|
+
|
|
6
|
+
The current release supports local development. Hosted infrastructure is not included yet.
|
|
7
|
+
|
|
8
|
+
## Get started
|
|
9
|
+
|
|
10
|
+
Ignotum requires Node.js 22.18 or newer.
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npx ignotum new my-app
|
|
14
|
+
cd my-app
|
|
15
|
+
npx ignotum dev
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Open <http://127.0.0.1:3210>. The generated project contains a schema, a query, a mutation, and a
|
|
19
|
+
JSX client.
|
|
20
|
+
|
|
21
|
+
## Follow the example app
|
|
22
|
+
|
|
23
|
+
```text
|
|
24
|
+
client/
|
|
25
|
+
App.tsx
|
|
26
|
+
styles.css
|
|
27
|
+
server/
|
|
28
|
+
counter.ts
|
|
29
|
+
schema.ts
|
|
30
|
+
shared/
|
|
31
|
+
utils.ts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Ignotum creates `_generated` beside them. Do not edit that directory by hand.
|
|
35
|
+
|
|
36
|
+
### Define the data
|
|
37
|
+
|
|
38
|
+
`server/schema.ts` declares a `counters` table with one numeric field:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { defineSchema } from "ignotum/server";
|
|
42
|
+
|
|
43
|
+
export default defineSchema(({ table, values }) => ({
|
|
44
|
+
counters: table({
|
|
45
|
+
value: values.number(),
|
|
46
|
+
}),
|
|
47
|
+
}));
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The schema supplies both runtime validation and TypeScript types. Ignotum also adds `id`,
|
|
51
|
+
`createdAt`, and `updatedAt` to every stored document.
|
|
52
|
+
|
|
53
|
+
The `shared/utils.ts` keeps the increment in one place that both the client and server
|
|
54
|
+
can import:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
export const counterIncrement = 1;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Read and write from the server
|
|
61
|
+
|
|
62
|
+
`server/counter.ts` defines the functions exposed to the client.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { mutation, query, values } from "@/_generated/server.js";
|
|
66
|
+
import { counterIncrement } from "@/shared/utils.js";
|
|
67
|
+
|
|
68
|
+
export const get = query({
|
|
69
|
+
returns: values.number(),
|
|
70
|
+
|
|
71
|
+
handler: function* (ctx) {
|
|
72
|
+
const counters = yield* ctx.db.query("counters").collect();
|
|
73
|
+
return counters[0]?.value ?? 0;
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const increment = mutation({
|
|
78
|
+
handler: function* (ctx) {
|
|
79
|
+
const counters = yield* ctx.db.query("counters").collect();
|
|
80
|
+
const counter = counters[0];
|
|
81
|
+
const value = (counter?.value ?? 0) + counterIncrement;
|
|
82
|
+
|
|
83
|
+
if (counter === undefined) {
|
|
84
|
+
yield* ctx.db.insert("counters", { value });
|
|
85
|
+
} else {
|
|
86
|
+
yield* ctx.db.patch("counters", counter.id, { value });
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Server handlers are generator functions. If `function*` and `yield*` look scary, read `function*`
|
|
93
|
+
as `async function` and `yield*` as `await`. That mental model is close enough when writing an
|
|
94
|
+
Ignotum handler. Use `yield*` for database operations, then return plain values from queries. Query
|
|
95
|
+
handlers can only read data. Mutation handlers can read and write, and Ignotum rolls back their
|
|
96
|
+
writes if they fail.
|
|
97
|
+
|
|
98
|
+
The file and export names form the generated API. The functions above become `api.counter.get`
|
|
99
|
+
and `api.counter.increment`.
|
|
100
|
+
|
|
101
|
+
### Call the functions from the client
|
|
102
|
+
|
|
103
|
+
`client/App.tsx` uses the generated references to call the server functions.
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { Result, useMutation, useQuery } from "ignotum/client";
|
|
107
|
+
|
|
108
|
+
import { api } from "@/_generated/api.js";
|
|
109
|
+
import { counterIncrement } from "@/shared/utils.js";
|
|
110
|
+
|
|
111
|
+
export default function App() {
|
|
112
|
+
const count = useQuery(api.counter.get);
|
|
113
|
+
const increment = useMutation(api.counter.increment);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<main class="mx-auto max-w-sm px-6 py-20 text-center">
|
|
117
|
+
<h1 class="text-2xl font-semibold">Counter</h1>
|
|
118
|
+
{Result.match(count, {
|
|
119
|
+
pending: () => <p class="mt-6">Loading...</p>,
|
|
120
|
+
value: (value) => (
|
|
121
|
+
<>
|
|
122
|
+
<p class="my-6 text-5xl tabular-nums">{value}</p>
|
|
123
|
+
<button
|
|
124
|
+
class="rounded bg-zinc-900 px-4 py-2 text-white"
|
|
125
|
+
type="button"
|
|
126
|
+
onClick={() => void increment()}
|
|
127
|
+
>
|
|
128
|
+
Increment by {counterIncrement}
|
|
129
|
+
</button>
|
|
130
|
+
</>
|
|
131
|
+
),
|
|
132
|
+
})}
|
|
133
|
+
</main>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`useQuery` starts with a pending result and subscribes to later values. `Result.match` makes the UI
|
|
139
|
+
handle each query state. `useMutation` returns a typed function whose arguments come from the
|
|
140
|
+
server definition.
|
|
141
|
+
|
|
142
|
+
Open the app in two browser tabs and increment the counter in either one. Both tabs update because
|
|
143
|
+
Ignotum refreshes active queries after a successful mutation.
|
|
144
|
+
|
|
145
|
+
## Keep working
|
|
146
|
+
|
|
147
|
+
The dev server watches the schema and server modules, regenerates bindings, and reloads the app.
|
|
148
|
+
Run code generation separately before a typecheck when the dev server is not running:
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
npx ignotum codegen
|
|
152
|
+
npx tsc --noEmit
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Local data survives dev-server restarts. Stop the server before resetting it:
|
|
156
|
+
|
|
157
|
+
```sh
|
|
158
|
+
npx ignotum dev db reset
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The package exports server APIs from `ignotum/server` and client APIs from `ignotum/client`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|