@ember-lattice/server 0.0.0-stage → 1.1.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/CHANGELOG.md +24 -0
- package/LICENSE.md +21 -0
- package/NOTICE +30 -0
- package/README.md +161 -2
- package/dist/chunk-WHFTIPTN.js +1542 -0
- package/dist/chunk-WHFTIPTN.js.map +1 -0
- package/dist/collab/index.d.ts +8 -0
- package/dist/collab/index.js +3 -0
- package/dist/collab/index.js.map +1 -0
- package/dist/collab/model.d.ts +68 -0
- package/dist/collab/server.d.ts +37 -0
- package/dist/collab/socket.d.ts +15 -0
- package/dist/collab/store.d.ts +31 -0
- package/dist/collab/wire.d.ts +157 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +417 -0
- package/dist/index.js.map +1 -0
- package/dist/rows.d.ts +21 -0
- package/package.json +62 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @ember-lattice/server
|
|
2
|
+
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @ember-lattice/formula@1.1.0
|
|
8
|
+
- @ember-lattice/protocol@1.1.0
|
|
9
|
+
|
|
10
|
+
## 1.0.0
|
|
11
|
+
|
|
12
|
+
### Major Changes
|
|
13
|
+
|
|
14
|
+
- 7ce4af2: Lattice 1.0: one grid for every collection in Ember. Lists, feeds, tables, boards and
|
|
15
|
+
spreadsheets come from one headless engine, a port of TanStack Table. It has 80 of the 81
|
|
16
|
+
AG Grid features in the parity matrix; the external filter runs after grouping. The release has the client row models, the Lattice wire protocol with servers for Node,
|
|
17
|
+
Rails and Python, an IronCalc spreadsheet with live collaboration, themes, test harnesses, Jig
|
|
18
|
+
stories and Marquetry catalog entries.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [7ce4af2]
|
|
23
|
+
- @ember-lattice/formula@1.0.0
|
|
24
|
+
- @ember-lattice/protocol@1.0.0
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joe Gaudet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Lattice
|
|
2
|
+
Copyright (c) 2026 Joe Gaudet. MIT licensed; see LICENSE.md.
|
|
3
|
+
|
|
4
|
+
Lattice ports code from two MIT-licensed TanStack projects into Ember-native code. Lattice does
|
|
5
|
+
not depend on either package. PORT_MAP.md names each ported file and its source.
|
|
6
|
+
|
|
7
|
+
TanStack Table (@tanstack/table-core 9.3.1)
|
|
8
|
+
https://github.com/TanStack/table
|
|
9
|
+
Copyright (c) 2016 Tanner Linsley
|
|
10
|
+
|
|
11
|
+
TanStack Virtual (@tanstack/virtual-core 3.19.16)
|
|
12
|
+
https://github.com/TanStack/virtual
|
|
13
|
+
Copyright (c) 2021-present Tanner Linsley
|
|
14
|
+
|
|
15
|
+
Both are licensed under the MIT License:
|
|
16
|
+
|
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
18
|
+
and associated documentation files (the "Software"), to deal in the Software without
|
|
19
|
+
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
|
20
|
+
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
|
21
|
+
Software is furnished to do so, subject to the following conditions:
|
|
22
|
+
|
|
23
|
+
The above copyright notice and this permission notice shall be included in all copies or
|
|
24
|
+
substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
27
|
+
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
28
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
29
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,162 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ember-lattice/server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Serve the Lattice wire protocol from Node. The package changes each request into SQL with
|
|
4
|
+
[Kysely](https://kysely.dev), and gives the same response as the reference evaluator of
|
|
5
|
+
`@ember-lattice/protocol`. It supports Postgres, SQLite and MySQL.
|
|
6
|
+
|
|
7
|
+
Part of [Lattice](https://joegaudet.com/ember-lattice/). Not released yet.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pnpm add @ember-lattice/server @ember-lattice/protocol kysely
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Also install the driver for your database, for example `pg` or `better-sqlite3`.
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
`createRowsHandler` gives an async function. The function takes the request body (parsed JSON)
|
|
20
|
+
and returns a `RowsResponse`. It throws `ProtocolValidationError` when the request is bad.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import express from 'express'
|
|
24
|
+
import { Kysely, PostgresDialect } from 'kysely'
|
|
25
|
+
import pg from 'pg'
|
|
26
|
+
import { ProtocolValidationError, type AllowList } from '@ember-lattice/protocol'
|
|
27
|
+
import { createRowsHandler } from '@ember-lattice/server'
|
|
28
|
+
|
|
29
|
+
const db = new Kysely<unknown>({
|
|
30
|
+
dialect: new PostgresDialect({
|
|
31
|
+
pool: new pg.Pool({ connectionString: process.env.DATABASE_URL, options: '-c TimeZone=UTC' }),
|
|
32
|
+
}),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const columns: AllowList = [
|
|
36
|
+
{ name: 'id', type: 'number', sort: true },
|
|
37
|
+
{ name: 'name', type: 'string', filter: ['eq', 'contains'], sort: true, search: true },
|
|
38
|
+
{ name: 'dept', type: 'string', filter: ['eq', 'in'], sort: true, group: true },
|
|
39
|
+
{ name: 'salary', type: 'number', filter: ['gt', 'lt'], aggregate: ['sum', 'avg'] },
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const rows = createRowsHandler({ db, table: 'people', columns, key: 'id', dialect: 'postgres' })
|
|
43
|
+
|
|
44
|
+
const app = express()
|
|
45
|
+
app.use(express.json({ limit: '100kb' }))
|
|
46
|
+
app.post('/people/rows', async (req, res, next) => {
|
|
47
|
+
try {
|
|
48
|
+
res.json(await rows(req.body))
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (e instanceof ProtocolValidationError) res.status(400).json({ errors: e.errors })
|
|
51
|
+
else next(e)
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
With the Node `http` module, read the body, limit its size, call `JSON.parse`, and then call the
|
|
57
|
+
handler in the same way. Send HTTP 400 with `{ errors }` for a `ProtocolValidationError`.
|
|
58
|
+
|
|
59
|
+
Always limit the body size before you parse it. The parser has its own limits (see the protocol
|
|
60
|
+
README), but it can only check a body that is already in memory.
|
|
61
|
+
|
|
62
|
+
## Options
|
|
63
|
+
|
|
64
|
+
| Option | Value |
|
|
65
|
+
| --------- | ----------------------------------------------------------------------------- |
|
|
66
|
+
| `db` | A Kysely instance or a Kysely transaction. |
|
|
67
|
+
| `table` | The table or view name. It can have a schema: `hr.people`. |
|
|
68
|
+
| `columns` | The allow-list: a list of `ColumnSchema` from `@ember-lattice/protocol`. |
|
|
69
|
+
| `key` | The unique column that is never null. It is the last sort key. |
|
|
70
|
+
| `dialect` | `'postgres'`, `'sqlite'` or `'mysql'`. It must agree with the Kysely dialect. |
|
|
71
|
+
|
|
72
|
+
## The allow-list
|
|
73
|
+
|
|
74
|
+
The allow-list is the trust boundary. A request can only use the columns, filter ops, aggregate
|
|
75
|
+
functions, sort, group and search that the allow-list gives.
|
|
76
|
+
|
|
77
|
+
- Each name must be an identifier (`[A-Za-z_][A-Za-z0-9_]*`). `__proto__`, `constructor` and
|
|
78
|
+
`prototype` are not permitted. `createRowsHandler` throws an error for a bad name or a `key`
|
|
79
|
+
that is not in the list.
|
|
80
|
+
- Each request goes through `parseRowsRequest` first. A request that fails the check never
|
|
81
|
+
makes a query.
|
|
82
|
+
- Only allow-list names become SQL identifiers, through `sql.id` and `sql.table`. The SQL
|
|
83
|
+
aliases are generated names (`a0`, `k1`, `v2`), so an aggregate `as` never goes into SQL.
|
|
84
|
+
- Every value is a bound parameter: filter values, search text, group keys, pivot keys and
|
|
85
|
+
cursor values. The tests read each compiled query and make sure that client strings are
|
|
86
|
+
never in the SQL text.
|
|
87
|
+
- The cursor is the JSON list of the sort values of a row. The handler checks each value
|
|
88
|
+
against the type of its sort column before it binds the value. A bad cursor gives the error
|
|
89
|
+
code `bad_cursor`.
|
|
90
|
+
|
|
91
|
+
## Queries
|
|
92
|
+
|
|
93
|
+
Each request uses one query for the page. It can also use these queries:
|
|
94
|
+
|
|
95
|
+
- The pivot keys, when the request has `pivot`. This query also checks the pivot width.
|
|
96
|
+
- The grand total, when the request has `aggregate`.
|
|
97
|
+
- The count, when the request asks for it, or when the page is the last page. An offset page
|
|
98
|
+
that is not empty and not full gives the count without a query.
|
|
99
|
+
- On a cursor page, one `limit 1` query that finds if rows are on the other side of the
|
|
100
|
+
cursor. This makes `cursor.prev` (for `after`) and `cursor.next` (for `before`) exact.
|
|
101
|
+
|
|
102
|
+
The queries do not run in one transaction. To get one snapshot, give a Kysely transaction as
|
|
103
|
+
`db`.
|
|
104
|
+
|
|
105
|
+
`first` and `last` use `first_value` and `last_value` window functions in a derived table,
|
|
106
|
+
in the leaf sort order.
|
|
107
|
+
|
|
108
|
+
## Dialects
|
|
109
|
+
|
|
110
|
+
| Item | Postgres | SQLite | MySQL |
|
|
111
|
+
| ------------------------ | ------------------------ | ---------------------- | ------------------------- |
|
|
112
|
+
| Tested | Yes (conformance) | Yes (conformance) | No: no server in the test |
|
|
113
|
+
| String order and compare | `collate "C"` | `collate binary` | `collate utf8mb4_bin` |
|
|
114
|
+
| Nulls first and last | `nulls first/last` | `nulls first/last` | `(col is null)` sort item |
|
|
115
|
+
| Pivot cells | `agg(x) filter (where)` | `agg(case when … end)` | `agg(case when … end)` |
|
|
116
|
+
| Date compare (filters) | `cast(x as timestamptz)` | `julianday(x)` | `col` with a UTC param |
|
|
117
|
+
| Boolean values | `boolean` | `0` and `1` | `0` and `1` |
|
|
118
|
+
| `min` and `max` boolean | cast to `integer` | native | native |
|
|
119
|
+
|
|
120
|
+
Requirements:
|
|
121
|
+
|
|
122
|
+
- **Postgres: set the session time zone to UTC.** For example, use
|
|
123
|
+
`options: '-c TimeZone=UTC'` in the `pg` pool. The protocol reads a date without a zone as
|
|
124
|
+
UTC. Postgres reads it in the session time zone.
|
|
125
|
+
- **Postgres: `date` columns.** By default, `pg` changes a `date` value into a JavaScript
|
|
126
|
+
`Date`. To get the ISO text that the protocol uses, add
|
|
127
|
+
`pg.types.setTypeParser(pg.types.builtins.DATE, v => v)`.
|
|
128
|
+
- **Date columns.** Filters and group keys compare dates by time. Sort, keyset, `min` and `max`
|
|
129
|
+
use the stored value. Thus, store each date column in one format: a native date type, or ISO
|
|
130
|
+
8601 text in one form (for example, all `YYYY-MM-DD`).
|
|
131
|
+
- **MySQL** needs version 8 (window functions) and a `utf8mb4` column character set. Store dates
|
|
132
|
+
as `DATE` or `DATETIME` in UTC. The MySQL SQL is not tested against a server.
|
|
133
|
+
- **Numbers.** `pg` gives `bigint` and `numeric` values as strings. The handler changes the
|
|
134
|
+
values of number columns, `count`, `sum`, `avg` and `$count` into JavaScript numbers. Very
|
|
135
|
+
large integers can lose precision.
|
|
136
|
+
|
|
137
|
+
## Differences from the reference evaluator
|
|
138
|
+
|
|
139
|
+
The conformance suite passes on SQLite and on Postgres. A random test (fast-check) also compares
|
|
140
|
+
the handler with `evaluate()` over many requests and cursor walks. These differences remain:
|
|
141
|
+
|
|
142
|
+
- **Text case.** `contains`, `startsWith`, `endsWith` and quick search use `lower()`. SQLite
|
|
143
|
+
`lower()` changes ASCII letters only. JavaScript `toLowerCase()` changes all letters.
|
|
144
|
+
- **String order.** Binary collation sorts UTF-8 bytes, which is code point order. The
|
|
145
|
+
evaluator sorts UTF-16 code units. The two orders are different only for characters above
|
|
146
|
+
`U+FFFF` and characters from `U+E000` to `U+FFFF`.
|
|
147
|
+
- **Pivot fields.** The handler writes the JSON of the pivot keys after it changes each key into
|
|
148
|
+
a JavaScript value. Postgres sends `float8` text that gives back the same number, so the
|
|
149
|
+
field text agrees with the evaluator.
|
|
150
|
+
- **Pivot width.** Each pivot key and value is one SQL column. Before the handler builds the
|
|
151
|
+
pivot SQL, it reads at most `LIMITS.maxPivotValues + 1` distinct pivot keys. If the scope has
|
|
152
|
+
more than `LIMITS.maxPivotValues` (200), the handler throws `ProtocolValidationError` with the
|
|
153
|
+
code `pivot_too_wide`.
|
|
154
|
+
|
|
155
|
+
## Tests
|
|
156
|
+
|
|
157
|
+
- `pnpm vitest run packages/server` runs the conformance suite, the security tests and the
|
|
158
|
+
random test on SQLite in memory.
|
|
159
|
+
- The Postgres tests run when a server answers at `LATTICE_TEST_PG_URL` (default
|
|
160
|
+
`postgres://localhost:5432/postgres`). If no server answers, they skip. They make a database
|
|
161
|
+
`lattice_test_node_<name>_<pid>` and drop it at the end.
|
|
162
|
+
- `LATTICE_PERF=1` also runs a smoke test on one million rows in Postgres.
|