@substrat-run/engine-booking 0.1.8 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +70 -0
  2. package/package.json +5 -5
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # @substrat-run/engine-booking
2
+
3
+ Reservation engine for [Substrat](https://github.com/substrat-run/substrat) —
4
+ **resources, intervals, and capacity**. It owns exactly one invariant and nothing else.
5
+
6
+ It knows nothing about pricing, opening hours, recurrence, cancellation windows, skill
7
+ levels, or timezones — all of that is vertical policy. It takes absolute instants and
8
+ compares them; it never does calendar arithmetic.
9
+
10
+ ## What it owns
11
+
12
+ - **One invariant: capacity is never exceeded.** Concurrent allocations against a
13
+ resource never exceed its capacity over any overlapping interval — enforced without
14
+ row locks.
15
+ - **A hold → confirm lifecycle.** A `hold` is a provisional claim that `expires` on its
16
+ own; `confirm` makes it firm; `move`, `cancel`, `start`, `complete`, and `no-show`
17
+ carry it the rest of the way.
18
+ - **Attribution comes from the ambient principal**, never from the input.
19
+ - **Every mutation emits a fat event** — `booking.held`, `booking.confirmed`,
20
+ `booking.moved`, `booking.completed`, … — so consumers never query back.
21
+
22
+ ## Install
23
+
24
+ ```sh
25
+ pnpm add @substrat-run/engine-booking
26
+ ```
27
+
28
+ ```ts
29
+ import {
30
+ bookingManifest,
31
+ createResource,
32
+ holdReservation,
33
+ confirmReservation,
34
+ PERM,
35
+ } from '@substrat-run/engine-booking';
36
+ import { assertAllowed } from '@substrat-run/kernel';
37
+
38
+ host.registerModule(bookingManifest);
39
+
40
+ // The engine registers no `booking/hold` operation: the vertical decides what a
41
+ // resource is, what it costs, and when it is bookable — then composes the in-scope
42
+ // function inside its own operation, in the same transaction, after its own check.
43
+ host.defineOperation('salon/request-slot', async (ctx, input) => {
44
+ assertAllowed(await ctx.check(PERM.hold));
45
+ return holdReservation(ctx, {
46
+ resource: input.chair, // opaque EntityRef — the vertical owns resources
47
+ from: input.from, // absolute instant
48
+ until: input.until,
49
+ holder: input.customer,
50
+ });
51
+ });
52
+ ```
53
+
54
+ ## Documentation
55
+
56
+ **https://substrat.net/engines** — the domain model and the capacity invariant, the full
57
+ operation/permission surface, the event contracts, and how a vertical composes or extends it.
58
+
59
+ The docs site is the single source of truth; this README deliberately doesn't restate it.
60
+
61
+ ## Related packages
62
+
63
+ - [`@substrat-run/kernel`](https://npmjs.com/package/@substrat-run/kernel) — the
64
+ scope-host contract these operations run on
65
+ - [`@substrat-run/contracts`](https://npmjs.com/package/@substrat-run/contracts) — the
66
+ branded IDs, `Money`, and manifest schemas in the surface
67
+
68
+ ## Status
69
+
70
+ Pre-release (0.x): surfaces change without notice until the first vertical ships.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@substrat-run/engine-booking",
3
- "version": "0.1.8",
3
+ "version": "0.1.11",
4
4
  "description": "Substrat engine: reservations — resource + interval + capacity, one allocation invariant, no locks",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -8,7 +8,7 @@
8
8
  "url": "git+https://github.com/substrat-run/substrat.git",
9
9
  "directory": "engines/booking"
10
10
  },
11
- "homepage": "https://github.com/substrat-run/substrat",
11
+ "homepage": "https://substrat.net/engines",
12
12
  "type": "module",
13
13
  "main": "./dist/index.js",
14
14
  "types": "./dist/index.d.ts",
@@ -26,13 +26,13 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "zod": "^4.4.3",
29
- "@substrat-run/contracts": "^0.14.0",
30
- "@substrat-run/kernel": "^0.14.0"
29
+ "@substrat-run/contracts": "^0.16.0",
30
+ "@substrat-run/kernel": "^0.16.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "typescript": "^7.0.0",
34
34
  "vitest": "^3.0.0",
35
- "@substrat-run/engine-test-kit": "^0.0.12"
35
+ "@substrat-run/engine-test-kit": "^0.0.14"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "tsc -p tsconfig.json",