@monlite/core 1.4.0 → 2.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 CHANGED
@@ -137,6 +137,17 @@ interface User {
137
137
  const users = db.collection<User>("users");
138
138
  ```
139
139
 
140
+ When you type a collection, queries are **type-checked** (since 2.0): `where`/
141
+ `orderBy` reject unknown fields, and `select` **narrows the return type** to the
142
+ fields you ask for. Prefer schema-free? Use `db.collection("users")` (untyped) —
143
+ it accepts any field, exactly as before.
144
+
145
+ ```ts
146
+ const u = await users.findMany({ select: { name: true } });
147
+ u[0].name; // string ✅ u[0].age // ✗ not selected
148
+ await users.findMany({ where: { naem: "x" } }); // ✗ 'naem' is not a field
149
+ ```
150
+
140
151
  Every stored document gains three system fields:
141
152
 
142
153
  | Field | Type | Notes |
@@ -619,6 +630,10 @@ These target **local / edge / desktop** runtimes — not a distributed cloud-sca
619
630
  Redis/Mongo/Qdrant replacement. For scale, keep the real services and
620
631
  [`@monlite/sync`](https://www.npmjs.com/package/@monlite/sync) to them.
621
632
 
633
+ **Building an Electron app?** [`@monlite/electron`](https://www.npmjs.com/package/@monlite/electron)
634
+ keeps the database in the main process and shares it with renderer windows over
635
+ IPC, with cross-window reactivity.
636
+
622
637
  ---
623
638
 
624
639
  ## Drivers & zero dependencies
@@ -708,8 +723,28 @@ future-proofing.
708
723
  ## Examples
709
724
 
710
725
  Runnable demos live in [`examples/`](examples/): a notes app (CRUD + full-text
711
- search + live queries), AI-agent memory (vector + hybrid search), and local-first
712
- sync. `cd examples && npm install && node notes.mjs`.
726
+ search + live queries), AI-agent memory (vector + hybrid search), local-first
727
+ sync, the cache/queue/cron harness, `$lookup`/`$unwind` joins, and the WASM
728
+ browser backend. `cd examples && npm install && node notes.mjs`.
729
+
730
+ ## Guides
731
+
732
+ - [Schema & migrations](docs/guides/migrations.md) — auto-additive changes and
733
+ `$migrate()` for drop/rename/type-change.
734
+ - [Custom adapters & drivers](docs/guides/custom-adapter.md) — add a sync backend
735
+ or a new SQLite binding/environment.
736
+ - [Migrating to 2.0](docs/guides/v2-migration.md) — the typed-query / select
737
+ changes (types only; runtime unchanged).
738
+
739
+ ## Studio (inspector)
740
+
741
+ Browse a database in your browser — collections, documents, filter queries:
742
+
743
+ ```bash
744
+ npx @monlite/studio app.db
745
+ ```
746
+
747
+ See [`@monlite/studio`](https://www.npmjs.com/package/@monlite/studio).
713
748
 
714
749
  ## Benchmarks
715
750
 
@@ -719,6 +754,12 @@ ops/sec, roughly 2× the raw-driver overhead for the full document API, and it
719
754
  **stays flat on indexed reads where JSON-file stores degrade** (lowdb point reads
720
755
  are ~15× slower at 10k docs).
721
756
 
757
+ ## On-disk format (cross-language)
758
+
759
+ A monlite database is **just a SQLite file** with documented conventions, so any
760
+ language with a SQLite library can read/write it — no port required. The contract
761
+ is in [`docs/FORMAT.md`](docs/FORMAT.md).
762
+
722
763
  ---
723
764
 
724
765
  ## License
package/dist/index.cjs CHANGED
@@ -1153,17 +1153,20 @@ var Collection = class {
1153
1153
  return this.db.prepare(`SELECT 1 FROM "${this.name}" WHERE ${clause} LIMIT 1`).get(...params) != null;
1154
1154
  }
1155
1155
  async findMany(args = {}) {
1156
- if (!args.lookup) return this.findManyCore(args);
1157
- const specs = Array.isArray(args.lookup) ? args.lookup : [args.lookup];
1156
+ const a = args;
1157
+ if (!a.lookup) {
1158
+ return this.findManyCore(a);
1159
+ }
1160
+ const specs = Array.isArray(a.lookup) ? a.lookup : [a.lookup];
1158
1161
  let rows = this.findManyCore({
1159
- ...args,
1162
+ ...a,
1160
1163
  select: void 0,
1161
1164
  lookup: void 0
1162
1165
  });
1163
1166
  for (const spec of specs) rows = await this.applyLookup(rows, spec);
1164
- if (args.select) {
1167
+ if (a.select) {
1165
1168
  rows = rows.map((r) => {
1166
- const projected = project(r, args.select);
1169
+ const projected = project(r, a.select);
1167
1170
  for (const spec of specs) projected[spec.as] = r[spec.as];
1168
1171
  return projected;
1169
1172
  });