API Reference
Classes and methods exported by the altseven framework (v9.1.4).
Everything exported by dist/a7.js. This reference reflects the source at
version 9.1.4.
Exports
import {
Application, View, Entity, Service, DataProvider, User, Model
} from "/lib/altseven/dist/a7.js";
Application
The application object; created once at startup and exported from app.js.
| Member |
Kind |
Notes |
constructor( options ) |
— |
Normalizes options; only options, name, util, log, constants exist until init() |
async init() |
method |
Creates all modules; awaits the auth check when security is enabled; returns the application |
.options |
property |
The normalized options (see Configuring) |
.log |
module |
LogManager — available immediately |
.util |
module |
Utilities incl. debounce( fn, ms ) and base64 encode/decode |
.constants |
property |
Convention: your app-wide constants |
.model |
module |
ModelManager (after init) |
.remote |
module |
RemoteManager (after init) |
.services |
module |
ServiceManager (after init) |
.dataproviders |
module |
DataProviderManager (after init) |
.events |
module |
EventManager (after init) |
.ui |
module |
UIManager (after init) |
.security |
module |
SecurityManager (when security enabled) |
.router |
module |
RouterManager (only when options.router is set) |
.error |
module |
ErrorManager (when security enabled) |
.console |
module |
Console (when console.enabled) |
.user / .authenticated |
property |
Session user / auth flag (when security enabled) |
View
Constructor props
| Prop |
Type |
Meaning |
id |
string |
Unique view id (used to address the view everywhere) |
selector |
string |
CSS selector of the mount point |
parentID |
string |
id of the parent view; child renders into the parent’s template |
cacheTemplate |
boolean, false |
Opt in to template caching for mayRender repaints |
isTransient |
boolean, false |
Garbage-collect when the mount point disappears |
Methods and properties
| Member |
Notes |
state / setState( args ) |
Partial merge of args into state; clears the template cache; fires mustRender (or delegates to the DataProvider) |
getState() |
Copy of the current state |
template |
String or () => string producing the view’s HTML |
eventHandlers |
Map of data-on<event> attribute names to handlers |
render() |
Resolve mount point, paint, bind data-on / data-bind, fire rendered |
onRendered() |
Renders registered children (called by the framework) |
addChild( view ) / removeChild( view ) / clearChildren() / getParent() |
Child-view tree management |
registerDataProvider( dp ) / unregisterDataProvider() |
Route state through a DataProvider |
hasRendered |
boolean — has this view ever painted (drives the 9.1.4 child-render fix) |
on( event, handler ) |
Instance event subscription (mustRender, rendered, stateChanged, …) |
fireEvent( event, args ) |
Instance event publish |
Entity
| Member |
Notes |
static schema |
Field descriptors: { type, required, id, entityClass }; types: string, integer, float, boolean, date, array, object |
constructor( props ) |
Validates required fields; coerces (string→Date, 1/0→boolean, plain object→entityClass) |
.id |
Value of the field marked id: true |
validate() |
Re-validates all fields; returns true or throws |
toFlatObject() |
Plain object (nested entities flattened recursively) |
fromFlatObject( obj ) |
Set values via setters (validated); returns the entity |
Service
| Member |
Notes |
constructor( props ) |
{ id, key, entityClass, remoteMethods }; remoteMethods maps operations to "module.action" strings |
async create( obj ) |
POST; caches and returns the saved entity (with server-assigned id) |
async read( obj ) |
GET one; cache first; deduplicates concurrent identical calls |
async readMany( IDs ) |
Fetches only ids missing from cache; returns an array |
async readAll( obj ) |
GET all (one request if cache empty); returns a Map |
async update( obj ) |
PUT; re-caches; fires entityChanged |
async delete( obj ) |
DELETE (remote action destroy); evicts; fires entityDeleted |
async invoke( name, params, options ) |
Custom method; options { merge, checkCache, filter, returnType } |
get() / get( ID ) |
Whole cache Map / one entity. A present-but-falsy ID (null, 0, “”) is a miss returning undefined (9.1.3) — never the whole map |
merge( items ) |
Merge raw entities into the cache; fires cacheChanged + per-entity events |
cacheSet( entity, action ) / cacheDelete( id ) |
Manual cache mutation with events |
filter( items, criteria ) |
Operators: =, !=, >, <, >=, <=, in, not in; [op, value, true] uses regex; bare value = equality |
sort( items, sortFields ) |
e.g. { priority: "desc", title: "asc" } |
bind( key, filter ) |
(Called by the DataProviderManager) |
on( "cacheChanged" / "entityChanged" / "entityDeleted", … ) |
Cache events consumed by data providers |
DataProvider
| Member |
Notes |
constructor( props ) |
{ view, state, schema, binding } |
setState( args ) / setStateOnly( args ) |
Merge state (+ fire stateChanged) / merge without firing |
getState() |
Copy of current state |
async loadRelation( name, criteria, options ) |
Fetch an entityMap relation: id list → service.readMany; options { merge, returnData } |
async refresh( name, criteria, options ) |
Re-fetch a loaded relation; options { merge, reload, returnData } |
clearRelation( name ) |
Empty the relation and forget its criteria |
getRelationCriteria( name ) |
Currently stored criteria (or null) |
on( "relationLoaded" / "relationRefreshed" / "relationCleared" / "stateChanged", … ) |
Relation lifecycle events |
Binding rule properties: entityClass, func, id, filter, sort, renderOn, dependencies — see DataProviders.
Model (myApp.model)
| Method |
Notes |
get( name [, key] ) |
Whole value, or one entity from a Map. A present-but-falsy key is a miss (9.1.3) |
set( name, value ) |
Store a value (deep-copied; Maps preserved as Maps) |
exists( name ) |
Whether the key is present |
bind( key, element ) |
Two-way HTML binding for data-bind elements |
undo( name ) / redo( name ) |
Step back / forward in the value’s history |
rewind( name ) / fastForward( name ) |
Jump to the oldest / newest history entry |
EventManager (myApp.events)
| Method |
Notes |
subscribe( topic, listener ) |
Returns { remove() }; non-function listeners are ignored but still declare the topic |
publish( topic, info ) |
Fires all listeners with info || {}; each listener is isolated — a throwing listener is logged, the rest still run (9.1.2) |
Built-in topics: auth.login, auth.logout, auth.refresh,
auth.sessionTimeout, auth.invalidateSession.
RemoteManager (myApp.remote)
| Method |
Notes |
async invoke( "module.action", params ) |
Dispatches to the module method; object methods map to CRUD verbs; function methods are called directly |
async fetch( uri, params, secure ) |
Raw fetch; secure attaches the session token |
webSocket( url, handleMessage, isSecure ) |
Raw socket; JSON-parses messages (async handlers supported); returns the WebSocket |
webSocketSession( options ) |
Managed session — see WebSockets |
setToken( t ) / getToken() / invalidateToken() |
Session token management (sessionStorage-backed) |
RouterManager (myApp.router)
| Method |
Notes |
open( path, params ) |
Navigate: push history, publish the mapped event with merged params |
match( path, params ) |
Same as open — use for the initial page load (no auto-match at startup) |
find( path ) |
Look up a route: { handler, params } or undefined |
add( path, handler ) |
Register a route programmatically |
UIManager (myApp.ui)
| Method |
Notes |
register( view ) |
Inject app modules into the view, add to registry, link to parent, fire registered |
unregister( id ) |
Remove a stale view |
getView( id ) |
Look up a registered view |
setSelector( name, selector ) / getSelector( name ) / getNode( name ) |
Named selector/node registry used by layout helpers |
enqueueForRender( id ) |
Add a view to the render queue |
mousePosition |
{ x, y } when ui.enableMouseTracking is on |
SecurityManager (myApp.security)
| Method |
Notes |
async isAuthenticated() |
Promise of { authenticated, user }; concurrent calls share one refresh request |
setUser( user ) / getUser() |
Session user in sessionStorage + model |
invalidateSession() |
Clear token and reset the user |
LogManager (myApp.log)
trace, debug, info, warn, error, fatal — enabled levels configured
via logging.logLevel. error/fatal accept ( message, error ).