Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion coverage.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"tests":7268,"assertions":32293,"lines":{"total":2408,"covered":2408,"skipped":0,"pct":100},"statements":{"total":2617,"covered":2617,"skipped":0,"pct":100},"functions":{"total":1046,"covered":1046,"skipped":0,"pct":100},"branches":{"total":906,"covered":906,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
{"tests":4368,"assertions":24850,"lines":{"total":2496,"covered":2482,"skipped":0,"pct":99.43},"statements":{"total":2705,"covered":2688,"skipped":0,"pct":99.37},"functions":{"total":1053,"covered":1037,"skipped":0,"pct":98.48},"branches":{"total":950,"covered":943,"skipped":0,"pct":99.26},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "tinybase",
"version": "7.3.1",
"version": "7.4.0",
"private": true,
"author": "jamesgpearce",
"repository": "github:tinyplex/tinybase",
"license": "MIT",
Expand Down Expand Up @@ -128,7 +129,6 @@
"optional": true
}
},
"private": true,
"scripts": {
"lintFiles": "gulp lintFiles",
"lintDocs": "gulp lintDocs",
Expand Down Expand Up @@ -262,4 +262,4 @@
"yup": "^1.7.1",
"zod": "^4.2.1"
}
}
}
2 changes: 1 addition & 1 deletion site/js/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const thisVersion = 'v7.3.1';
export const thisVersion = 'v7.4.0';
17 changes: 17 additions & 0 deletions src/@types/mergeable-store/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,23 @@
* @since v5.0.0
*/
/// MergeableStore.merge
/**
* The use method registers middleware to intercept mutations before they are
* applied. This is inherited from Store and works identically on
* MergeableStore.
*
* Middleware runs on both local mutations (setRow, setCell, etc.) and on
* incoming sync changes (applyMergeableChanges). It does NOT run on
* setMergeableContent (used for trusted persistence/hydration).
*
* See Store.use for full documentation and examples.
* @param tableId The table to intercept, or '*' for all tables.
* @param handler The handler function.
* @returns A reference to the MergeableStore for chaining.
* @category Middleware
* @since v7.4.0
*/
/// MergeableStore.use
}
/**
* The createMergeableStore function creates a MergeableStore, and is the main
Expand Down
20 changes: 20 additions & 0 deletions src/@types/mergeable-store/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// mergeable-store
import type {GetNow, Hash, Hlc, Id} from '../common/index.d.ts';
import type {
AllTablesRowMiddleware,
CellOrUndefined,
Content,
RowMiddleware,
Store,
ValueOrUndefined,
} from '../store/index.d.ts';
Expand Down Expand Up @@ -130,6 +132,24 @@ export interface MergeableStore extends Store {
/// MergeableStore.merge
merge(mergeableStore: MergeableStore): MergeableStore;

/// MergeableStore.use
/**
* Register middleware to intercept mutations before they are applied.
*
* Middleware runs on both local mutations (setRow, setCell, etc.) and
* incoming sync changes (applyMergeableChanges).
*
* Overloads:
* - `use(tableId, handler)` - Row-level middleware for a specific table.
* - `use('*', handler)` - Row-level middleware for all tables.
*
* Row-level handlers receive `(rowId, cells)` or `(tableId, rowId, cells)`
* and return the cells to accept (modified), or null to reject the row.
* @since v7.4.0
*/
use(tableId: Id, handler: RowMiddleware): this;
use(tableId: '*', handler: AllTablesRowMiddleware): this;

/// Store.isMergeable
isMergeable(): boolean;
}
Expand Down
39 changes: 39 additions & 0 deletions src/@types/store/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,31 @@
* @since v4.0.0
*/
/// Changes
/**
* The RowMiddleware type represents a function that intercepts row mutations
* for a specific table before they are applied.
*
* The handler receives the rowId and cells object and can return the cells
* unchanged (accept), return modified cells (transform), or return null to
* reject the row mutation entirely.
*
* Register with `store.use(tableId, handler)`.
* @category Middleware
* @since v7.4.0
*/
/// RowMiddleware
/**
* The AllTablesRowMiddleware type represents a function that intercepts row
* mutations for all tables before they are applied.
*
* This catch-all handler receives the tableId, rowId, and cells object.
* It runs after any table-specific handlers.
*
* Register with `store.use('*', handler)`.
* @category Middleware
* @since v7.4.0
*/
/// AllTablesRowMiddleware
/**
* The TransactionLog type describes the changes that were made to a Store
* during a transaction in detail.
Expand Down Expand Up @@ -7267,6 +7292,20 @@
* @since v5.0.0
*/
/// Store.isMergeable
/**
* The use method registers middleware to intercept mutations before they are
* applied to the Store.
*
* Middleware handlers can modify incoming data or reject mutations entirely.
* Use `use(tableId, handler)` for a specific table, or `use('*', handler)`
* to intercept mutations across all tables.
* @param tableId The Id of the Table to intercept, or '*' for all tables.
* @param handler The middleware handler function.
* @returns A reference to the Store.
* @category Middleware
* @since v7.4.0
*/
/// Store.use
}
/**
* The createStore function creates a Store, and is the main entry point into
Expand Down
33 changes: 33 additions & 0 deletions src/@types/store/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,24 @@ export type Changes = [
isChanges: 1,
];

/// RowMiddleware
/**
* Row-level middleware handler for a specific table.
* @since v7.4.0
*/
export type RowMiddleware = (rowId: Id | undefined, cells: Row) => Row | null;

/// AllTablesRowMiddleware
/**
* Row-level middleware handler for all tables (catch-all).
* @since v7.4.0
*/
export type AllTablesRowMiddleware = (
tableId: Id,
rowId: Id | undefined,
cells: Row,
) => Row | null;

/// TransactionLog
export type TransactionLog = [
cellsTouched: boolean,
Expand Down Expand Up @@ -809,6 +827,21 @@ export interface Store {

/// Store.isMergeable
isMergeable(): boolean;

/// Store.use
/**
* Register middleware to intercept mutations before they are applied.
*
* Overloads:
* - `use(tableId, handler)` - Row-level middleware for a specific table.
* - `use('*', handler)` - Row-level middleware for all tables.
*
* Row-level handlers receive `(rowId, cells)` or `(tableId, rowId, cells)`
* and return the cells to accept (modified), or null to reject the row.
* @since v7.4.0
*/
use(tableId: Id, handler: RowMiddleware): this;
use(tableId: '*', handler: AllTablesRowMiddleware): this;
//
}

Expand Down
Loading