@outlawdesigns/armorysdk
v1.0.6
Published
SDK for Armory Service
Readme
Armory SDK (Server-Side)
A lightweight Node.js SDK for interacting with the Armory data layer.
This package provides ORM-style access to firearms, ammunition, optics, and shooting data through a consistent, class-based interface built on @outlawdesigns/db-record.
🚀 Features
🔫 Comprehensive armory models — Manage firearms, ammunition, optics, and related entities.
🧩 Dynamic model factory — Fetch models or classes by name using a centralized interface.
🗃️ Database abstraction — Built on
@outlawdesigns/db-recordfor clean MySQL integration.📸 Media support — Includes models for firearm and target images.
📊 Activity tracking — Record shooting sessions and ammo purchases.
📦 Installation
npm install @outlawdesigns/armorysdk
🧠 Basic Usage
Require the SDK
import ModelFactory from '@outlawdesigns/armorysdk';Create a Model Instance
const firearm = await ModelFactory.get('firearm',2).init();
console.log(firearm.Serial_Number);Access Model Classes Directly
const Firearm = Armory.getClass('firearm');
const myFirearm = new Firearm(2);
await myFirearm.init();
//particularly useful for calling static methods
const allArms = await ModelFactory.getClass('firearm').getAll()
🧩 Available Models
| Model | Description | Backing Table |
| :--- | :---: | ---: |
| firearm | Concrete instance of a firearm owned by a user. | Firearm |
| firearmImage | Images associated with firearms. | FirearmImage |
| firearmType | Abstract firearm definition. | FirearmType |
| manufacturer | Firearm or component manufacturer. | Manufacturer |
| ammunition | Concrete instance of ammunition owned by a user. | Ammunition |
| ammunitionType | Abstract ammunition definition. | AmmunitionType |
| caliber | Caliber definitions. | Caliber |
| ammoPurchase | Records of ammunition purchases. | AmmoPurchase |
| optic | Concrete instance of an optic owned by a user. | Optic |
| opticType | Abstract optic definition. | OpticType |
| shoot | Shooting session records. | Shoot |
| targetImage | Images of shot targets. | TargetImage |
| vendor | Vendors or retailers. | Vendor |
All models extend @outlawdesigns/db-record.Record and support standard CRUD operations.
🔧 Example: Recording a Shooting Session
import ModelFactory from '@outlawdesigns/armorysdk';
const firearmId = 1;
const ammoId = 2;
const rounds = 100;
const distanceFt = 300;
const opticId = null;
const userId = 'example';
const newShoot = model = await ModelFactory.getClass('shoot').new(firearmId,ammoId,rounds, distanceFt, opticId, userId);🔧 Example: Logging an Ammo Purchase
import ModelFactory from '@outlawdesigns/armorysdk';
const ammoId = 2;
const vendorId = 12;
const rounds = 100;
const price = 55.90;
const datePurchased = new Date();
//pass undefined instead for pending receipt
const dateReceived = datePurchased;
const userId = 'example';
const purchase = await ModelFactory.getClass('ammoPurchase').new(ammoId, vendorId, rounds, price, datePurchased, dateReceived, userId);
⚙️ Environment Variables
| Variable | Description | Default |
| :--- | :---: | ---: |
| MYSQL_ARMORY_DB | Database name for Armory models. | Armory |
🧱 Project Structure
.
├── index.js # SDK entry point
├── modelFactory.js # Central model registry
├── models/
│ ├── ammunition.js
│ ├── ammunitionType.js
│ ├── ammoPurchase.js
│ ├── caliber.js
│ ├── firearm.js
│ ├── firearmImage.js
│ ├── firearmType.js
│ ├── manufacturer.js
│ ├── optic.js
│ ├── opticType.js
│ ├── shoot.js
│ ├── targetImage.js
│ └── vendor.js
└── package.json
🧩 Extending the SDK
To add a new model:
Create a file in
models/extending@outlawdesigns/db-record.Record.Register it in
modelFactory.js.
Example:
class Range extends Record {
static table = 'range';
static primaryKey = 'id';
static get database() {
return process.env.MYSQL_ARMORY_DB || 'armory';
}
}
Register it:
const Range = require('./models/range');
models.range = (id) => new Range(id);
modelClasses.range = Range;
👤 Author
Maintained by Outlaw Designs
https://github.com/outlawdesigns-io
