@push.rocks/smartdb 4.1.0 → 5.0.1

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.
Binary file
Binary file
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartdb',
6
- version: '4.1.0',
6
+ version: '5.0.1',
7
7
  description: 'A MongoDB-compatible embedded database server with wire protocol support, backed by a high-performance Rust engine.'
8
8
  };
9
9
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSxxQkFBcUI7SUFDM0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLHFIQUFxSDtDQUNuSSxDQUFBIn0=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@push.rocks/smartdb",
3
- "version": "4.1.0",
3
+ "version": "5.0.1",
4
4
  "private": false,
5
5
  "description": "A MongoDB-compatible embedded database server with wire protocol support, backed by a high-performance Rust engine.",
6
6
  "exports": {
package/readme.hints.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # smartdb hints
2
2
 
3
+ ## Restricted Deny-All Views
4
+
5
+ - `rustdb-commands/src/views.rs` is the sole owner of `system.views` parsing, bounds, canonical `_id_` metadata validation, exact deny-all pipeline validation, and authoritative namespace classification. There is intentionally no mutable cross-command view cache; aggregate and transaction commit reuse one immutable authoritative catalog per database for that operation.
6
+ - The only accepted definition is `viewOn: <same-db collection name>` plus exact pipeline `[{ $match: { $expr: { $eq: [1, 0] } } }]`. A logical view has no physical collection and never reads `viewOn`.
7
+ - `system.views` is a physical reserved catalog. It is visible as a collection in wire `listCollections`, export, import, and content digest, but command-layer `IndexEngine` creation and direct wire access are forbidden. Internal view create/drop uses storage point insert/delete and preserves the storage adapter's canonical `_id` metadata.
8
+ - Catalog loading is bounded to 1,024 view records and 1 MiB of encoded view documents and never enumerates all physical collections. Runtime validation checks each bounded logical name with `collection_exists`; snapshot/import validation uses its already-provided physical-name set without adding a runtime collection ceiling. Exact document shape is `_id`, `viewOn`, and `pipeline`; malformed records, noncanonical indexes, duplicate/reserved names, and physical/view collisions fail closed.
9
+ - Publication permits validate once per newly observed publication state; databases without an epoch use an internal observed sentinel. Epoch refresh validates before recording the new observation. Startup validates databases whose publication lease can be acquired before listener bind; publication-held databases are validated on their first later permit. Snapshot/export explicitly revalidate. Import validates the source candidate, remaps only the exact source database prefix in catalog `_id` values, then validates the target candidate before mutation and clears its observed state after replacement.
10
+ - Content digest hashes the physical catalog but removes its already-validated deterministic database prefix from `_id` first, preserving the database-name-independent digest contract across cross-name imports.
11
+ - DDL and transaction commit take the maintenance write gate. View create/drop additionally lock the logical target and `${db}.system.views` in sorted order. View DDL validates the complete prospective catalog and performs cursor/index cleanup before its final point insert/delete, so cancellation cannot publish catalog state without cleanup. Commit locks every touched namespace in sorted order, loads one catalog per touched database, reclassifies each namespace, and transfers those guards into the storage completion closure.
12
+ - Mutation handlers reclassify after acquiring their target namespace lock and before existence, auto-create, or lazy-index work. Logical-view data/index/output/rename mutations and direct `system.views` operations return `CommandNotSupportedOnView` code 166; `dropCollection` removes a logical view, while direct catalog drop remains forbidden. Ordinary create collision with a logical view returns `NamespaceExists`.
13
+ - Find/count/distinct are empty outside a transaction, aggregate applies the client pipeline to an empty source, and lookup/union resolution is empty. A transaction first reading a current view snapshots an empty vector, while a populated snapshot captured before a rename-plus-view transition remains authoritative for find/count/distinct until commit revalidation. Do not infer view semantics from physical collection absence.
14
+ - Successful create/drop/rename/dropDatabase publication removes affected namespace cursors before releasing DDL guards. A subsequent `getMore` cannot continue against stale namespace contents.
15
+ - Management oplog revert rejects entries targeting `system.views` or a currently logical view. Logical-view `dropCollection` and whole-database drop are the catalog-removal exceptions; direct `system.views` drop is code 166. Database drop clears database indexes, cursors, oplog state, and observed publication state.
16
+
3
17
  ## Multikey Query Planning
4
18
 
5
19
  - SmartDB detects when an indexed path resolves through an array and keeps that state on the in-memory index until a complete rebuild.
package/readme.md CHANGED
@@ -458,9 +458,9 @@ Grant principals can read only their exact allocation database. Reads, collectio
458
458
 
459
459
  `revokeDatabaseAllocationReadAccessGrant()` takes `databaseName`, `grantId`, and the complete allocation identity, returns `{ revoked: true }` without a secret, and is idempotent. Revoke-before-issue records anti-replay state only while a read permit proves that exact allocation is current. A delayed revoke after deprovision returns success without recreating auth metadata.
460
460
 
461
- `exportDatabase()` drains live MongoDB wire commands for the selected database and holds an exclusive local and cross-process database lease while producing the snapshot. The export is therefore consistent across all collections. It enforces server ceilings while visiting documents instead of first materializing an unbounded database; callers can request lower `maxEncodedBytes`, `maxCollections`, `maxDocuments`, and `maxIndexes` limits. The result emits canonical MongoDB Extended JSON so every BSON type, including 64-bit integers, survives the JSON management channel exactly. `importDatabase()` accepts canonical or relaxed Extended JSON. Database migration clients should preserve the exported objects as JSON values and must not coerce Extended JSON numeric wrappers into JavaScript numbers.
461
+ `exportDatabase()` drains live MongoDB wire commands for the selected database and holds an exclusive local and cross-process database lease while producing the snapshot. The export is therefore consistent across all collections. It enforces server ceilings while visiting documents instead of first materializing an unbounded database; callers can request lower `maxEncodedBytes`, `maxCollections`, `maxDocuments`, and `maxIndexes` limits. The result emits canonical MongoDB Extended JSON so every BSON type, including 64-bit integers, survives the JSON management channel exactly. Restricted views are carried only through the physical `system.views` catalog and are never materialized. `importDatabase()` accepts canonical or relaxed Extended JSON, validates a candidate catalog before mutation, and remaps exact `system.views._id` source-database prefixes when importing under another database name. Database migration clients should preserve the exported objects as JSON values and must not coerce Extended JSON numeric wrappers into JavaScript numbers.
462
462
 
463
- `getDatabaseContentDigest()` computes a bounded, database-name-independent SHA-256 over collection names, exact BSON document bytes, and persisted index specifications. Collection, document, and index enumeration order is normalized; BSON field order and compound-index key order remain significant. `ISmartDbGetDatabaseContentDigestInput` accepts `databaseName` and optional `ISmartDbDatabaseContentDigestLimits` fields `maxScannedBsonBytes`, `maxCollections`, `maxDocuments`, and `maxIndexes`. Callers may lower the server ceilings of 96 MiB scanned BSON, 10,000 collections, 1,000,000 documents, and 100,000 indexes. The `ISmartDbDatabaseContentDigest` result reports format `smartdb.database.content-digest.v1`, algorithm `sha256`, the lowercase digest, and exact scan counters.
463
+ `getDatabaseContentDigest()` computes a bounded, database-name-independent SHA-256 over collection names, exact BSON document bytes, and persisted index specifications. Collection, document, and index enumeration order is normalized; BSON field order and compound-index key order remain significant. The physical `system.views` catalog is included, with only its already-validated deterministic database prefix removed from `_id` for hashing so a cross-name import retains the same digest. `ISmartDbGetDatabaseContentDigestInput` accepts `databaseName` and optional `ISmartDbDatabaseContentDigestLimits` fields `maxScannedBsonBytes`, `maxCollections`, `maxDocuments`, and `maxIndexes`. Callers may lower the server ceilings of 96 MiB scanned BSON, 10,000 collections, 1,000,000 documents, and 100,000 indexes. The `ISmartDbDatabaseContentDigest` result reports format `smartdb.database.content-digest.v1`, algorithm `sha256`, the lowercase digest, and exact scan counters.
464
464
 
465
465
  `SmartdbServer.start()` and the lifecycle-critical health, fence-state, digest, export, import, publication-commit, tenant-allocation, tenant-attestation, tenant-ensure, tenant-delete, read-grant issue, and read-grant revoke methods accept optional `ISmartDbManagementOperationOptions` with `signal?: AbortSignal` and `timeoutMs?: number`. `timeoutMs`, when provided, must be a positive safe integer no greater than `2,147,483,647`. Startup applies both cancellation and one deadline across legacy storage migration, sidecar spawn, auth metadata migration, and database readiness. Cancellation and deadlines are fail-stop once the sidecar is owned: SmartDB attempts to terminate the Rust engine before rejecting. Once termination is confirmed, the operation cannot continue after the caller releases ownership. If termination itself fails, the rejection retains bridge ownership and the service owner must retry `stop()` until it succeeds. After cancellation or deadline termination, restart SmartDB before accepting more traffic.
466
466
 
@@ -762,10 +762,62 @@ await admin.ping();
762
762
  await admin.serverStatus();
763
763
  ```
764
764
 
765
- SmartDB creates ordinary collections only. Unsupported collection semantics,
766
- including views, capped collections, validators, collation, time-series
767
- collections, clustered indexes, and encrypted fields, are rejected before the
768
- database or namespace is created.
765
+ SmartDB creates ordinary collections and one deliberately restricted view form.
766
+ Capped collections, validators, collation, time-series collections, clustered
767
+ indexes, encrypted fields, and all general view pipelines remain unsupported and
768
+ are rejected before the database or namespace is created.
769
+
770
+ ### Restricted Deny-All Views
771
+
772
+ The only accepted view definition is the exact deny-all pipeline below. This is
773
+ intended for compatibility barriers such as renaming a legacy source and leaving
774
+ its old namespace present but permanently empty:
775
+
776
+ ```typescript
777
+ await db.collection('secrets').rename('secrets_v2');
778
+ await db.createCollection('secrets', {
779
+ viewOn: 'secrets_v2',
780
+ pipeline: [{ $match: { $expr: { $eq: [1, 0] } } }],
781
+ });
782
+ ```
783
+
784
+ Both `viewOn` and `pipeline` are required. The pipeline must contain exactly one
785
+ `$match` stage with exactly `$expr: { $eq: [1, 0] }`; empty pipelines, numeric or
786
+ structural variants, additional stages, and additional collection-definition
787
+ options are rejected with `InvalidOptions` (code 72) before mutation. Command
788
+ metadata such as `$db`, `lsid`, `comment`, and API-version fields remains
789
+ accepted. `viewOn` must identify an existing same-database collection or
790
+ restricted view at creation time. General MongoDB views are not supported.
791
+
792
+ The logical view has no physical collection. `find`, `count`, and `distinct`
793
+ return empty results. `aggregate` starts with an empty source and still applies
794
+ the client pipeline; `$lookup` and `$unionWith` resolve the view as empty.
795
+ Transactions first reading a current view record an explicit empty snapshot; a
796
+ transaction that captured a populated collection before it is renamed and
797
+ replaced by a view keeps that original snapshot for `find`, `count`, and
798
+ `distinct` until commit conflict handling. Inserts, updates, deletes,
799
+ `findAndModify`, indexes, `$out`, `$merge`, rename, and other data mutations fail
800
+ with `CommandNotSupportedOnView` (code 166). `dropCollection` is the supported
801
+ DDL exception for removing a logical restricted view.
802
+
803
+ Definitions are persisted in the physical `system.views` catalog. As in MongoDB,
804
+ `listCollections` lists `system.views` as a physical storage collection and the
805
+ logical namespace as type `view` with `{ viewOn, pipeline }`, read-only metadata,
806
+ and no `idIndex`. `system.views` is reserved from direct wire reads,
807
+ writes, index operations, create, drop, rename, and aggregation output. Whole
808
+ database drop and trusted database export/import/digest operations handle it as
809
+ physical catalog data. Export never materializes a view; cross-database import
810
+ remaps the exact catalog `_id` database prefix. Startup validates databases whose
811
+ publication lease can be acquired before listener bind; a publication-held
812
+ database is validated on its first permit after release. Import validates before
813
+ mutation. Malformed, oversized, noncanonical, duplicate, reserved, or colliding
814
+ catalog state fails closed.
815
+
816
+ `system.views` was not interpreted by earlier SmartDB releases. This reservation
817
+ is a major-version compatibility boundary: before upgrading, operators must use
818
+ the older release to rename or remove any unrelated physical `system.views`
819
+ collection. Once upgraded, direct catalog rename or drop is intentionally
820
+ rejected with code 166.
769
821
 
770
822
  ### Bulk Operations
771
823
 
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartdb',
6
- version: '4.1.0',
6
+ version: '5.0.1',
7
7
  description: 'A MongoDB-compatible embedded database server with wire protocol support, backed by a high-performance Rust engine.'
8
8
  }