# larvitorder

> Generic order system

Latest version **4.1.22** (published 2026-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install larvitorder
pnpm add larvitorder
yarn add larvitorder
bun add larvitorder
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.1.22 |
| Published | 2026-10-26 |
| First published | 2016-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 114.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | lilleman |
| Maintainers | klabbekluck, gagge, lilleman, filipjohansson, jaggu-snorr, jaggu-darull, vktr, jaggu-larvit-npm-publish |
| Keywords | order, orders, multi-purpose |

## Links

- npm: https://www.npmjs.com/package/larvitorder
- Repository: https://github.com/larvit/larvitorder
- Homepage: https://github.com/larvit/larvitorder#readme
- Issues: https://github.com/larvit/larvitorder/issues
- npm.io page: https://npm.io/package/larvitorder

## Dependencies (6)

- [uuid](https://npm.io/package/uuid.md) 11.1.1
- [async](https://npm.io/package/async.md) 3.2.6
- [luxon](https://npm.io/package/luxon.md) ^3.1.1
- [larvitdb](https://npm.io/package/larvitdb.md) 3.2.160
- [larvitutils](https://npm.io/package/larvitutils.md) 5.1.215
- [larvitdbmigration](https://npm.io/package/larvitdbmigration.md) 7.0.227

## Recent versions

- 4.1.22 (latest) — 2026-10-26
- 4.1.21 — 2026-10-19
- 4.1.20 — 2026-10-12
- 4.1.19 — 2026-10-05
- 4.1.18 — 2026-09-30
- 4.1.17 — 2026-09-29
- 4.1.16 — 2026-09-29
- 4.1.15 — 2026-09-29
- 4.1.14 — 2026-09-29
- 4.1.13 — 2026-09-29
- 4.1.12 — 2026-09-29
- 4.1.11 — 2026-09-29
- 4.1.7 — 2025-09-22
- 4.1.6 — 2025-02-20
- 4.1.4 — 2025-02-17
- … 106 more at https://npm.io/package/larvitorder/versions

## README

[![Build Status](https://github.com/larvit/larvitorder/actions/workflows/ci.yml/badge.svg)](https://github.com/larvit/larvitorder/actions)

# larvitorder

Generic order module for nodejs.

order data structure:
```json
{
	"uuid": "string",
	"fields": {
		"field1": [
			"value1",
			"value2"
		],
		"field2": [
			"value3"
		]
	},
	"rows": [
		{
			"uuid": "string", <-- special field
			"field1": [394],
			"field2": ["nisse", 20]
		}
	]
}
```

## Installation

```bash
npm i --save larvitorder
```

## Usage

### Initialize

All below instructions require the loading of libraries like something below (db is an instance of larvitdb and log an instance of winston or larvitutils.Log):

```javascript
const OrderLib = require('larvitorder');
const orderLib = new OrderLib({ db, log })
await orderLib.runDbMigrations();
```

### Add a new order

```javascript
const order = new orderLib.Order({db});

order.created = '2022-12-01T13:37:00Z'; // Must be ISO-8601
order.fields	= {'firstname': 'Günter', 'lastname': ['Edelweiss', 'Schloffs']};
order.rows	= [{'price': 399, 'name': 'Screw'}, {'price': 34, 'name': 'teh_foo', 'tags': ['foo', 'bar']}];

await order.save();
```

### Load existing order from database

```javascript
const order = new orderLib.Order({uuid: 'uuid-on-existing-order-in-db', db});

await order.loadFromDb();
// Now order.fields and order.rows is loaded from database
```

### Remove order from database

```javascript
const order = new orderLib.Order({uuid: 'uuid-on-existing-order-in-db', db});

await order.rm();
// order is now removed from DB
```

### Get orders

```javascript
const ordersCtx = new orderLib.Orders({db});

const {orders, hits} = await ordersCtx.get();
```

#### Filter and limit order list

```javascript
const ordersCtx = new orderLib.Orders({db});

// Filter and limit order hits
orders.limit = 10;	// Only return 10 orders
orders.offset = 5;	// Skip the 5 first orders
orders.uuids = ['1ebe346e-c05a-11e6-a4a6-cec0c932ce01'];	// Only return orders with these uuids
orders.matchAllFields = {'firstname': 'Abraham', 'lastname': 'Lincoln'};	// Only return orders that have both the fields firstname and lastname that matches
orders.matchAllRowFields = {'productName': 'A4 paper'};	// Only return orders that have rows matching both the row fieldname "productName" and the value "A4 paper"

// Return order fields
orders.returnFields	= ['firstname', 'lastname', 'status'];	// Only return the order fields listed. IMPORTANT! Will return no order fields if not supplied! Because performance.

// Return order row fields
orders.returnRowFields	= ['productName', 'price'];	// Only return the order row fields listed. IMPORTANT! Will return no order row fields if not supplied! Because performance.

const {orders, hits} = await ordersCtx.get();
```

---
_Source: https://npm.io/package/larvitorder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
