Installations
npm install seneca-entity
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=16
Node Version
20.11.1
NPM Version
10.2.4
Score
82.1
Supply Chain
99.2
Quality
82.7
Maintenance
100
Vulnerability
98.9
License
Contributors
Unable to fetch Contributors
Languages
JavaScript (56.25%)
TypeScript (43.75%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
senecajs
Download Statistics
Total Downloads
767,655
Last Day
1,159
Last Week
4,271
Last Month
20,428
Last Year
274,835
GitHub Statistics
MIT License
13 Stars
266 Commits
15 Forks
6 Watchers
8 Branches
10 Contributors
Updated on Jul 20, 2024
Bundle Size
44.51 kB
Minified
15.46 kB
Minified + Gzipped
Package Meta Information
Latest Version
28.1.0
Package Id
seneca-entity@28.1.0
Unpacked Size
138.58 kB
Size
33.69 kB
File Count
23
NPM Version
10.2.4
Node Version
20.11.1
Published on
Jul 15, 2024
Total Downloads
Cumulative downloads
Total Downloads
767,655
Last Day
28.8%
1,159
Compared to previous day
Last Week
1.8%
4,271
Compared to previous week
Last Month
-18.9%
20,428
Compared to previous month
Last Year
297.9%
274,835
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Peer Dependencies
2
Seneca Entity is a plugin for Seneca
Provides a simple Object-Relation Mapping over Seneca messages as a convenience API for manipulating data.
Any data store can then be accessed using the full power of Seneca messages.
seneca-entity
![]() | This open source module is sponsored and supported by Voxgig. |
---|
Install
With npm:
$ npm install seneca-entity
With yarn:
$ yarn add seneca-entity
TypeScript
Implemented using TypeScript. Minimal types are provided by the package.
Quick Example
Please visit senecajs.org for a more complete overview and documentation of the Seneca framework.
Read the Understanding Data Entities tutorial for a step-by-step introduction to Seneca data entities.
1const Seneca = require('seneca')
2
3const seneca = Seneca() // Create a new instance of Seneca.
4 .use('entity') // Use the seneca-entity plugin (Seneca will require it).
5
6// Create an reusable instance of the `person` entity.
7const Person = seneca.entity('person')
8
9// Create a specific person instance.
10let alice = Person.make$()
11
12// Set some fields (assumes a NoSQL database, or a predefined table).
13// Properties with a final `$` are reserved for the Entity API methods.
14alice.name = 'Alice'
15alice.location = 'Wonderland'
16
17// Save your data. Seneca entity provides a default in-memory store,
18// which is very useful for fast unit tests.
19alice = await alice.save$()
20
21// The `alice` entity now has an `id` field.
22let alsoAlice = await Person.load$(alice.id)
23alsoAlice.location = 'Looking Glass'
24
25// The `alsoAlice` entity will be updated, not created, because
26// it has an `id` field. The save$ method both creates and updates.
27await alsoAlice.save$()
28
29// Entity methods can be chained (until they return a Promise).
30let lily = await Person
31 .make$({
32 name: 'Lily',
33 location: 'Looking Glass'
34 })
35 .save$()
36
37// The data$ method exports a JSON serializable verson of the entity
38// as a plain object.
39console.log(lily.data$())
40
41// The data$ method can alternatively set multiple fields.
42await lily
43 .data$({
44 game: 'chess'
45 })
46 .save$()
47
48// List all the person entities.
49let people = await Person.list$()
50
51// List only those person entities with field `game` equal to the string "chess".
52let players = await Person.list$({game: 'chess'})
Seneca Entity is inspired in part by the ActiveRecord pattern as implemented by Ruby on Rails.
Seneca Entity is not a full Object Relation Mapping. It is a convenience API over the Seneca action patterns:
role:entity,cmd:load
-.load$()
role:entity,cmd:save
-.save$()
role:entity,cmd:list
-.list$()
role:entity,cmd:remove
-.remove$()
This means that you can extend the "ORM" using the same message manipulation as with all Seneca messages, including sending them over the network to other microservices.
In particular, you can:
- Support pretty much any kind of database for a standard set of basic operations, extending the query syntax if necessary - @seneca/s3-store
- Easily define reusable business logic that assumes standard entities, but is still extensible - @seneca/user
- Add cross-cutting concerns without polluting your business logic - @seneca/allow
- Customize specific operations for specific entities by adding your own action patterns -
seneca.message('role:entity,cmd:save,name:person', async function(msg) { ... })
- Expose most REST or GraphQL APIs as "databases" - @seneca/trello-provider
- Use different databases for different entities, see Mapping Entities to Data Stores
- Namespace and isolate entities as desired; entities have not just a name, but also an optional base (table namespace) and zone (good for strict multi-tenancy), to use as you see fit.
BUT, Seneca entity does not natively implement relations, and loads only the top level entity. Since relation mapping often leads to inefficient queries, this is not such a bad thing. When relations are needed, you can implement them manually by customizing the appropriate action patterns. Or you may find that denormalizing your data is more fun than you think.
More Examples
API
Contributing
Background
License
Copyright (c) 2012-2022, Richard Rodger and other contributors. Licensed under MIT.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/senecajs/seneca-entity/build.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/senecajs/seneca-entity/build.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/senecajs/seneca-entity/build.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/todo.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/senecajs/seneca-entity/todo.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/todo.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/senecajs/seneca-entity/todo.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/build.yml:31
- Warn: npmCommand not pinned by hash: .github/workflows/build.yml:33
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 0 out of 2 npmCommand dependencies pinned
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/build.yml:1
- Warn: no topLevel permission defined: .github/workflows/todo.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3.4
/10
Last Scanned on 2025-03-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More