@empressaio/atom-contract 1.7.0

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 (251) hide show
  1. package/CHANGELOG.md +360 -0
  2. package/README.md +379 -0
  3. package/dist/composition.d.ts +112 -0
  4. package/dist/composition.d.ts.map +1 -0
  5. package/dist/composition.js +80 -0
  6. package/dist/composition.js.map +1 -0
  7. package/dist/conformance/common.d.ts +21 -0
  8. package/dist/conformance/common.d.ts.map +1 -0
  9. package/dist/conformance/common.js +29 -0
  10. package/dist/conformance/common.js.map +1 -0
  11. package/dist/conformance/fixtures.d.ts +13 -0
  12. package/dist/conformance/fixtures.d.ts.map +1 -0
  13. package/dist/conformance/fixtures.js +63 -0
  14. package/dist/conformance/fixtures.js.map +1 -0
  15. package/dist/conformance/index.d.ts +11 -0
  16. package/dist/conformance/index.d.ts.map +1 -0
  17. package/dist/conformance/index.js +11 -0
  18. package/dist/conformance/index.js.map +1 -0
  19. package/dist/conformance/validate.d.ts +49 -0
  20. package/dist/conformance/validate.d.ts.map +1 -0
  21. package/dist/conformance/validate.js +138 -0
  22. package/dist/conformance/validate.js.map +1 -0
  23. package/dist/conformance/verify-chain.d.ts +25 -0
  24. package/dist/conformance/verify-chain.d.ts.map +1 -0
  25. package/dist/conformance/verify-chain.js +76 -0
  26. package/dist/conformance/verify-chain.js.map +1 -0
  27. package/dist/context.d.ts +134 -0
  28. package/dist/context.d.ts.map +1 -0
  29. package/dist/context.js +110 -0
  30. package/dist/context.js.map +1 -0
  31. package/dist/encumbrances/administrative-rule.d.ts +128 -0
  32. package/dist/encumbrances/administrative-rule.d.ts.map +1 -0
  33. package/dist/encumbrances/administrative-rule.js +18 -0
  34. package/dist/encumbrances/administrative-rule.js.map +1 -0
  35. package/dist/encumbrances/common.d.ts +153 -0
  36. package/dist/encumbrances/common.d.ts.map +1 -0
  37. package/dist/encumbrances/common.js +124 -0
  38. package/dist/encumbrances/common.js.map +1 -0
  39. package/dist/encumbrances/constraint-resolution.d.ts +169 -0
  40. package/dist/encumbrances/constraint-resolution.d.ts.map +1 -0
  41. package/dist/encumbrances/constraint-resolution.js +41 -0
  42. package/dist/encumbrances/constraint-resolution.js.map +1 -0
  43. package/dist/encumbrances/fixtures.d.ts +16 -0
  44. package/dist/encumbrances/fixtures.d.ts.map +1 -0
  45. package/dist/encumbrances/fixtures.js +107 -0
  46. package/dist/encumbrances/fixtures.js.map +1 -0
  47. package/dist/encumbrances/index.d.ts +15 -0
  48. package/dist/encumbrances/index.d.ts.map +1 -0
  49. package/dist/encumbrances/index.js +15 -0
  50. package/dist/encumbrances/index.js.map +1 -0
  51. package/dist/encumbrances/recorded-instrument.d.ts +131 -0
  52. package/dist/encumbrances/recorded-instrument.d.ts.map +1 -0
  53. package/dist/encumbrances/recorded-instrument.js +19 -0
  54. package/dist/encumbrances/recorded-instrument.js.map +1 -0
  55. package/dist/encumbrances/restriction-clause.d.ts +120 -0
  56. package/dist/encumbrances/restriction-clause.d.ts.map +1 -0
  57. package/dist/encumbrances/restriction-clause.js +17 -0
  58. package/dist/encumbrances/restriction-clause.js.map +1 -0
  59. package/dist/encumbrances/restriction-corpus.d.ts +44 -0
  60. package/dist/encumbrances/restriction-corpus.d.ts.map +1 -0
  61. package/dist/encumbrances/restriction-corpus.js +14 -0
  62. package/dist/encumbrances/restriction-corpus.js.map +1 -0
  63. package/dist/export/downloadable-atom.d.ts +133 -0
  64. package/dist/export/downloadable-atom.d.ts.map +1 -0
  65. package/dist/export/downloadable-atom.js +115 -0
  66. package/dist/export/downloadable-atom.js.map +1 -0
  67. package/dist/export/index.d.ts +6 -0
  68. package/dist/export/index.d.ts.map +1 -0
  69. package/dist/export/index.js +6 -0
  70. package/dist/export/index.js.map +1 -0
  71. package/dist/history.d.ts +124 -0
  72. package/dist/history.d.ts.map +1 -0
  73. package/dist/history.js +170 -0
  74. package/dist/history.js.map +1 -0
  75. package/dist/index.d.ts +29 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +20 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/inline-reference.d.ts +60 -0
  80. package/dist/inline-reference.d.ts.map +1 -0
  81. package/dist/inline-reference.js +73 -0
  82. package/dist/inline-reference.js.map +1 -0
  83. package/dist/obligation.d.ts +131 -0
  84. package/dist/obligation.d.ts.map +1 -0
  85. package/dist/obligation.js +55 -0
  86. package/dist/obligation.js.map +1 -0
  87. package/dist/og/common.d.ts +253 -0
  88. package/dist/og/common.d.ts.map +1 -0
  89. package/dist/og/common.js +195 -0
  90. package/dist/og/common.js.map +1 -0
  91. package/dist/og/completion.d.ts +70 -0
  92. package/dist/og/completion.d.ts.map +1 -0
  93. package/dist/og/completion.js +22 -0
  94. package/dist/og/completion.js.map +1 -0
  95. package/dist/og/equipment-state.d.ts +55 -0
  96. package/dist/og/equipment-state.d.ts.map +1 -0
  97. package/dist/og/equipment-state.js +25 -0
  98. package/dist/og/equipment-state.js.map +1 -0
  99. package/dist/og/fixtures.d.ts +40 -0
  100. package/dist/og/fixtures.d.ts.map +1 -0
  101. package/dist/og/fixtures.js +255 -0
  102. package/dist/og/fixtures.js.map +1 -0
  103. package/dist/og/index.d.ts +23 -0
  104. package/dist/og/index.d.ts.map +1 -0
  105. package/dist/og/index.js +23 -0
  106. package/dist/og/index.js.map +1 -0
  107. package/dist/og/mineral-lease.d.ts +150 -0
  108. package/dist/og/mineral-lease.d.ts.map +1 -0
  109. package/dist/og/mineral-lease.js +24 -0
  110. package/dist/og/mineral-lease.js.map +1 -0
  111. package/dist/og/ownership-interest.d.ts +163 -0
  112. package/dist/og/ownership-interest.d.ts.map +1 -0
  113. package/dist/og/ownership-interest.js +36 -0
  114. package/dist/og/ownership-interest.js.map +1 -0
  115. package/dist/og/pad.d.ts +101 -0
  116. package/dist/og/pad.d.ts.map +1 -0
  117. package/dist/og/pad.js +19 -0
  118. package/dist/og/pad.js.map +1 -0
  119. package/dist/og/production-timeseries.d.ts +154 -0
  120. package/dist/og/production-timeseries.d.ts.map +1 -0
  121. package/dist/og/production-timeseries.js +37 -0
  122. package/dist/og/production-timeseries.js.map +1 -0
  123. package/dist/og/revenue-allocation-unit.d.ts +762 -0
  124. package/dist/og/revenue-allocation-unit.d.ts.map +1 -0
  125. package/dist/og/revenue-allocation-unit.js +105 -0
  126. package/dist/og/revenue-allocation-unit.js.map +1 -0
  127. package/dist/og/rrc-lease.d.ts +124 -0
  128. package/dist/og/rrc-lease.d.ts.map +1 -0
  129. package/dist/og/rrc-lease.js +29 -0
  130. package/dist/og/rrc-lease.js.map +1 -0
  131. package/dist/og/tract.d.ts +88 -0
  132. package/dist/og/tract.d.ts.map +1 -0
  133. package/dist/og/tract.js +30 -0
  134. package/dist/og/tract.js.map +1 -0
  135. package/dist/og/well.d.ts +201 -0
  136. package/dist/og/well.d.ts.map +1 -0
  137. package/dist/og/well.js +40 -0
  138. package/dist/og/well.js.map +1 -0
  139. package/dist/og/wellbore.d.ts +61 -0
  140. package/dist/og/wellbore.d.ts.map +1 -0
  141. package/dist/og/wellbore.js +25 -0
  142. package/dist/og/wellbore.js.map +1 -0
  143. package/dist/og/zone.d.ts +45 -0
  144. package/dist/og/zone.d.ts.map +1 -0
  145. package/dist/og/zone.js +16 -0
  146. package/dist/og/zone.js.map +1 -0
  147. package/dist/read-contract/common.d.ts +74 -0
  148. package/dist/read-contract/common.d.ts.map +1 -0
  149. package/dist/read-contract/common.js +54 -0
  150. package/dist/read-contract/common.js.map +1 -0
  151. package/dist/read-contract/consequence.d.ts +99 -0
  152. package/dist/read-contract/consequence.d.ts.map +1 -0
  153. package/dist/read-contract/consequence.js +46 -0
  154. package/dist/read-contract/consequence.js.map +1 -0
  155. package/dist/read-contract/fixtures.d.ts +8 -0
  156. package/dist/read-contract/fixtures.d.ts.map +1 -0
  157. package/dist/read-contract/fixtures.js +44 -0
  158. package/dist/read-contract/fixtures.js.map +1 -0
  159. package/dist/read-contract/index.d.ts +14 -0
  160. package/dist/read-contract/index.d.ts.map +1 -0
  161. package/dist/read-contract/index.js +14 -0
  162. package/dist/read-contract/index.js.map +1 -0
  163. package/dist/read-contract/model-attribution.d.ts +85 -0
  164. package/dist/read-contract/model-attribution.d.ts.map +1 -0
  165. package/dist/read-contract/model-attribution.js +30 -0
  166. package/dist/read-contract/model-attribution.js.map +1 -0
  167. package/dist/read-contract/read-contract.d.ts +455 -0
  168. package/dist/read-contract/read-contract.d.ts.map +1 -0
  169. package/dist/read-contract/read-contract.js +46 -0
  170. package/dist/read-contract/read-contract.js.map +1 -0
  171. package/dist/registration.d.ts +192 -0
  172. package/dist/registration.d.ts.map +1 -0
  173. package/dist/registration.js +15 -0
  174. package/dist/registration.js.map +1 -0
  175. package/dist/registry.d.ts +128 -0
  176. package/dist/registry.d.ts.map +1 -0
  177. package/dist/registry.js +122 -0
  178. package/dist/registry.js.map +1 -0
  179. package/dist/render.d.ts +30 -0
  180. package/dist/render.d.ts.map +1 -0
  181. package/dist/render.js +44 -0
  182. package/dist/render.js.map +1 -0
  183. package/dist/scope.d.ts +46 -0
  184. package/dist/scope.d.ts.map +1 -0
  185. package/dist/scope.js +17 -0
  186. package/dist/scope.js.map +1 -0
  187. package/dist/temporal/anticipatory-atom.d.ts +123 -0
  188. package/dist/temporal/anticipatory-atom.d.ts.map +1 -0
  189. package/dist/temporal/anticipatory-atom.js +124 -0
  190. package/dist/temporal/anticipatory-atom.js.map +1 -0
  191. package/dist/temporal/common.d.ts +47 -0
  192. package/dist/temporal/common.d.ts.map +1 -0
  193. package/dist/temporal/common.js +100 -0
  194. package/dist/temporal/common.js.map +1 -0
  195. package/dist/temporal/fixtures.d.ts +7 -0
  196. package/dist/temporal/fixtures.d.ts.map +1 -0
  197. package/dist/temporal/fixtures.js +21 -0
  198. package/dist/temporal/fixtures.js.map +1 -0
  199. package/dist/temporal/index.d.ts +13 -0
  200. package/dist/temporal/index.d.ts.map +1 -0
  201. package/dist/temporal/index.js +13 -0
  202. package/dist/temporal/index.js.map +1 -0
  203. package/dist/temporal/interval-query.d.ts +42 -0
  204. package/dist/temporal/interval-query.d.ts.map +1 -0
  205. package/dist/temporal/interval-query.js +49 -0
  206. package/dist/temporal/interval-query.js.map +1 -0
  207. package/dist/temporal/node-id.d.ts +112 -0
  208. package/dist/temporal/node-id.d.ts.map +1 -0
  209. package/dist/temporal/node-id.js +208 -0
  210. package/dist/temporal/node-id.js.map +1 -0
  211. package/dist/temporal/would-affect-edge.d.ts +66 -0
  212. package/dist/temporal/would-affect-edge.d.ts.map +1 -0
  213. package/dist/temporal/would-affect-edge.js +113 -0
  214. package/dist/temporal/would-affect-edge.js.map +1 -0
  215. package/dist/testing/index.d.ts +98 -0
  216. package/dist/testing/index.d.ts.map +1 -0
  217. package/dist/testing/index.js +225 -0
  218. package/dist/testing/index.js.map +1 -0
  219. package/dist/vda.d.ts +46 -0
  220. package/dist/vda.d.ts.map +1 -0
  221. package/dist/vda.js +42 -0
  222. package/dist/vda.js.map +1 -0
  223. package/dist/workspace/brief-run.d.ts +104 -0
  224. package/dist/workspace/brief-run.d.ts.map +1 -0
  225. package/dist/workspace/brief-run.js +32 -0
  226. package/dist/workspace/brief-run.js.map +1 -0
  227. package/dist/workspace/common.d.ts +42 -0
  228. package/dist/workspace/common.d.ts.map +1 -0
  229. package/dist/workspace/common.js +26 -0
  230. package/dist/workspace/common.js.map +1 -0
  231. package/dist/workspace/fixtures.d.ts +10 -0
  232. package/dist/workspace/fixtures.d.ts.map +1 -0
  233. package/dist/workspace/fixtures.js +93 -0
  234. package/dist/workspace/fixtures.js.map +1 -0
  235. package/dist/workspace/index.d.ts +13 -0
  236. package/dist/workspace/index.d.ts.map +1 -0
  237. package/dist/workspace/index.js +13 -0
  238. package/dist/workspace/index.js.map +1 -0
  239. package/dist/workspace/property-workspace.d.ts +148 -0
  240. package/dist/workspace/property-workspace.d.ts.map +1 -0
  241. package/dist/workspace/property-workspace.js +21 -0
  242. package/dist/workspace/property-workspace.js.map +1 -0
  243. package/dist/workspace/workspace-attachment.d.ts +99 -0
  244. package/dist/workspace/workspace-attachment.d.ts.map +1 -0
  245. package/dist/workspace/workspace-attachment.js +35 -0
  246. package/dist/workspace/workspace-attachment.js.map +1 -0
  247. package/dist/workspace/workspace-share-edge.d.ts +115 -0
  248. package/dist/workspace/workspace-share-edge.d.ts.map +1 -0
  249. package/dist/workspace/workspace-share-edge.js +22 -0
  250. package/dist/workspace/workspace-share-edge.js.map +1 -0
  251. package/package.json +107 -0
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Event-anchored history for atoms.
3
+ *
4
+ * The `EventAnchoringService` interface every atom mutation flows through.
5
+ * Ships the interface verbatim plus a Postgres-backed implementation that
6
+ * writes deterministic SHA-256 `chainHash` values into the `atom_events`
7
+ * table. Cryptographic anchoring (Merkle root, external ledger anchor)
8
+ * lands later without changing the consumer interface — this is the
9
+ * central "interface-stable / implementation-evolves" promise.
10
+ *
11
+ * TODO(M2-C): replace deterministic chainHash with cryptographic anchor.
12
+ */
13
+ import { createHash } from "node:crypto";
14
+ import { sql } from "drizzle-orm";
15
+ /**
16
+ * Name of the host application's atom-events table. The host project owns
17
+ * the schema; this library is decoupled from it at runtime — we issue raw
18
+ * SQL against the agreed table name only. Keeping the table name in one
19
+ * constant makes the contract explicit and lets future versions of the
20
+ * framework move to a host-injected name without touching call sites.
21
+ */
22
+ const ATOM_EVENTS_TABLE = sql.identifier("atom_events");
23
+ /**
24
+ * Generate a ULID-like monotonic id. Time prefix (10 chars Crockford32)
25
+ * keeps ids time-sortable; random suffix makes them unique. We don't use
26
+ * the `ulid` package to avoid a runtime dep for one ~30-line helper.
27
+ */
28
+ const CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
29
+ function generateId() {
30
+ let time = Date.now();
31
+ let timeChars = "";
32
+ for (let i = 0; i < 10; i++) {
33
+ timeChars = (CROCKFORD[time % 32] ?? "0") + timeChars;
34
+ time = Math.floor(time / 32);
35
+ }
36
+ let rand = "";
37
+ for (let i = 0; i < 16; i++) {
38
+ rand += CROCKFORD[Math.floor(Math.random() * 32)] ?? "0";
39
+ }
40
+ return timeChars + rand;
41
+ }
42
+ /**
43
+ * Compute the deterministic SHA-256 chain hash for an event. Inputs are
44
+ * stringified with stable key order so two callers computing the same
45
+ * event get the same hash. TODO(M2-C): swap for the real cryptographic
46
+ * anchor — same signature, no consumer change.
47
+ */
48
+ function computeChainHash(args) {
49
+ // JSON.stringify with sorted keys is stable enough; we don't worry
50
+ // about deeply-nested object key ordering yet.
51
+ const stable = JSON.stringify({
52
+ prevHash: args.prevHash,
53
+ payload: args.payload,
54
+ occurredAt: args.occurredAt.toISOString(),
55
+ eventType: args.eventType,
56
+ actor: args.actor,
57
+ });
58
+ return createHash("sha256").update(stable).digest("hex");
59
+ }
60
+ /**
61
+ * Postgres-backed {@link EventAnchoringService} implementation. Uses raw
62
+ * SQL via Drizzle's `sql` template so the boundary to the host db package
63
+ * stays minimal — we depend on the `atom_events` table existing but not
64
+ * on the driver flavor.
65
+ */
66
+ export class PostgresEventAnchoringService {
67
+ db;
68
+ constructor(db) {
69
+ this.db = db;
70
+ }
71
+ async appendEvent(input) {
72
+ const occurredAt = input.occurredAt ?? new Date();
73
+ return await this.db.transaction(async (tx) => {
74
+ // Per-entity serialization: appendEvent is atomic with respect to
75
+ // its (entityType, entityId) chain — the resulting hash chain
76
+ // must be gap-free even under concurrent appends.
77
+ //
78
+ // We use a transaction-scoped Postgres advisory lock keyed on a
79
+ // 64-bit hash of `${entityType}:${entityId}`. Concurrent
80
+ // transactions touching the same chain serialize on the lock;
81
+ // transactions on different chains run in parallel. The lock
82
+ // releases automatically at COMMIT/ROLLBACK.
83
+ const lockKey = `${input.entityType}:${input.entityId}`;
84
+ await tx.execute(sql `SELECT pg_advisory_xact_lock(hashtextextended(${lockKey}, 0))`);
85
+ // Find the chain tail by structure, not by timestamp. Postgres'
86
+ // `now()` (used by `recorded_at` defaults) returns transaction-
87
+ // start time, not statement time, so under concurrent appends two
88
+ // rows can have equal/out-of-order recorded_at values and a
89
+ // timestamp-based ORDER BY cannot reliably identify the most-
90
+ // recently-inserted row. The tail is well-defined: it's the only
91
+ // row whose `chain_hash` is not any other row's `prev_hash`. The
92
+ // advisory lock above guarantees there is at most one such row.
93
+ const latestRows = await tx.execute(sql `SELECT chain_hash FROM ${ATOM_EVENTS_TABLE} e1
94
+ WHERE entity_type = ${input.entityType}
95
+ AND entity_id = ${input.entityId}
96
+ AND NOT EXISTS (
97
+ SELECT 1 FROM ${ATOM_EVENTS_TABLE} e2
98
+ WHERE e2.entity_type = e1.entity_type
99
+ AND e2.entity_id = e1.entity_id
100
+ AND e2.prev_hash = e1.chain_hash
101
+ )
102
+ LIMIT 1`);
103
+ const prevHash = latestRows.rows.length > 0
104
+ ? (latestRows.rows[0]?.chain_hash ?? null)
105
+ : null;
106
+ const id = generateId();
107
+ const chainHash = computeChainHash({
108
+ prevHash,
109
+ payload: input.payload,
110
+ occurredAt,
111
+ eventType: input.eventType,
112
+ actor: input.actor,
113
+ });
114
+ const inserted = await tx.execute(sql `INSERT INTO ${ATOM_EVENTS_TABLE}
115
+ (id, entity_type, entity_id, event_type, actor, payload,
116
+ prev_hash, chain_hash, occurred_at)
117
+ VALUES
118
+ (${id}, ${input.entityType}, ${input.entityId},
119
+ ${input.eventType}, ${JSON.stringify(input.actor)}::jsonb,
120
+ ${JSON.stringify(input.payload)}::jsonb,
121
+ ${prevHash}, ${chainHash}, ${occurredAt.toISOString()})
122
+ RETURNING id, entity_type, entity_id, event_type, actor,
123
+ payload, prev_hash, chain_hash, occurred_at,
124
+ recorded_at`);
125
+ const row = inserted.rows[0];
126
+ if (!row)
127
+ throw new Error("appendEvent: insert returned no rows");
128
+ // `chain_hash` carries a UNIQUE constraint at the schema level —
129
+ // if the lock failed for any reason, the duplicate insert would
130
+ // surface here instead of silently forking the chain.
131
+ return rowToEvent(row);
132
+ });
133
+ }
134
+ async readHistory(ref, opts = {}) {
135
+ const limit = Math.max(1, Math.min(opts.limit ?? 1000, 10_000));
136
+ const offset = Math.max(0, opts.offset ?? 0);
137
+ const direction = opts.reverse ? sql `DESC` : sql `ASC`;
138
+ const result = await this.db.execute(sql `SELECT id, entity_type, entity_id, event_type, actor, payload,
139
+ prev_hash, chain_hash, occurred_at, recorded_at
140
+ FROM ${ATOM_EVENTS_TABLE}
141
+ WHERE entity_type = ${ref.entityType}
142
+ AND entity_id = ${ref.entityId}
143
+ ORDER BY occurred_at ${direction}, recorded_at ${direction}, id ${direction}
144
+ LIMIT ${limit} OFFSET ${offset}`);
145
+ return result.rows.map(rowToEvent);
146
+ }
147
+ async latestEvent(ref) {
148
+ const rows = await this.readHistory(ref, { limit: 1, reverse: true });
149
+ return rows[0] ?? null;
150
+ }
151
+ }
152
+ function rowToEvent(row) {
153
+ const actor = row.actor;
154
+ const payload = row.payload;
155
+ return {
156
+ id: row.id,
157
+ entityType: row.entity_type,
158
+ entityId: row.entity_id,
159
+ eventType: row.event_type,
160
+ actor,
161
+ payload,
162
+ prevHash: row.prev_hash ?? null,
163
+ chainHash: row.chain_hash,
164
+ occurredAt: new Date(row.occurred_at),
165
+ recordedAt: new Date(row.recorded_at),
166
+ };
167
+ }
168
+ /** Re-exported for tests that want to assert the chain-hash formula. */
169
+ export const __internal = { computeChainHash, generateId };
170
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AA2ExD;;;;GAIG;AACH,MAAM,SAAS,GAAG,kCAAkC,CAAC;AACrD,SAAS,UAAU;IACjB,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACtB,IAAI,SAAS,GAAG,EAAE,C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AAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,GAAkB;QAClC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IACzB,CAAC;CACF;AAED,SAAS,UAAU,CAAC,GAA4B;IAC9C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAmB,CAAC;IACtC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAkC,CAAC;IACvD,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAY;QACpB,UAAU,EAAE,GAAG,CAAC,WAAqB;QACrC,QAAQ,EAAE,GAAG,CAAC,SAAmB;QACjC,SAAS,EAAE,GAAG,CAAC,UAAoB;QACnC,KAAK;QACL,OAAO;QACP,QAAQ,EAAG,GAAG,CAAC,SAA2B,IAAI,IAAI;QAClD,SAAS,EAAE,GAAG,CAAC,UAAoB;QACnC,UAAU,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,WAA4B,CAAC;QACtD,UAAU,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,WAA4B,CAAC;KACvD,CAAC;AACJ,CAAC;AAED,wEAAwE;AACxE,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,gBAAgB,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Public surface of `@empressaio/atom-contract`.
3
+ *
4
+ * The barrel re-exports every primitive but never anything from
5
+ * `src/testing/` — testing utilities live behind the `./testing` subpath
6
+ * so production bundles never pull them in.
7
+ *
8
+ * See `README.md` for the contract walk-through and the
9
+ * "What this package does NOT ship" deferred-surface list.
10
+ */
11
+ export type { AccessPolicy, AtomMode, AtomReference, AtomProps, ChipAction, AtomRegistration, AnyAtomRegistration, DefaultModeOf, } from "./registration.js";
12
+ export type { Scope } from "./scope.js";
13
+ export { defaultScope } from "./scope.js";
14
+ export type { ContextSummary, KeyMetric, HistoryProvenance, HttpContextSummaryOptions, HttpContextSummaryHandle, } from "./context.js";
15
+ export { httpContextSummary } from "./context.js";
16
+ export type { AtomComposition, ResolvedChild, CompositionRegistryView, } from "./composition.js";
17
+ export { resolveComposition } from "./composition.js";
18
+ export { FALLBACK_ORDER, resolveMode, } from "./render.js";
19
+ export type { ParsedSegment, ParsedTextSegment, ParsedAtomSegment, } from "./inline-reference.js";
20
+ export { INLINE_ATOM_REGEX, parseInlineReferences, serializeInlineReference, } from "./inline-reference.js";
21
+ export type { EventActor, AppendEventInput, AtomEvent, ReadHistoryOptions, EventAnchoringService, DrizzleLikeDb, } from "./history.js";
22
+ export { PostgresEventAnchoringService } from "./history.js";
23
+ export type { VdaEnvelope, WrappedValue } from "./vda.js";
24
+ export { wrapForStorage, unwrapFromStorage } from "./vda.js";
25
+ export type { AtomRegistry, ResolveResult, ValidateResult, DanglingCompositionRef, AtomPromptDescription, } from "./registry.js";
26
+ export { createAtomRegistry, AtomNotRegisteredError } from "./registry.js";
27
+ export type { ObligationAtomInstance, ObligationType, ObligationStatus, } from "./obligation.js";
28
+ export { OBLIGATION_SCHEMA, OBLIGATION_TYPES, OBLIGATION_STATUSES, } from "./obligation.js";
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,YAAY,EACV,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,YAAY,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,YAAY,EACV,eAAe,EACf,aAAa,EACb,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EACL,cAAc,EACd,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAE7D,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7D,YAAY,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE3E,YAAY,EACV,sBAAsB,EACtB,cAAc,EACd,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Public surface of `@empressaio/atom-contract`.
3
+ *
4
+ * The barrel re-exports every primitive but never anything from
5
+ * `src/testing/` — testing utilities live behind the `./testing` subpath
6
+ * so production bundles never pull them in.
7
+ *
8
+ * See `README.md` for the contract walk-through and the
9
+ * "What this package does NOT ship" deferred-surface list.
10
+ */
11
+ export { defaultScope } from "./scope.js";
12
+ export { httpContextSummary } from "./context.js";
13
+ export { resolveComposition } from "./composition.js";
14
+ export { FALLBACK_ORDER, resolveMode, } from "./render.js";
15
+ export { INLINE_ATOM_REGEX, parseInlineReferences, serializeInlineReference, } from "./inline-reference.js";
16
+ export { PostgresEventAnchoringService } from "./history.js";
17
+ export { wrapForStorage, unwrapFromStorage } from "./vda.js";
18
+ export { createAtomRegistry, AtomNotRegisteredError } from "./registry.js";
19
+ export { OBLIGATION_SCHEMA, OBLIGATION_TYPES, OBLIGATION_STATUSES, } from "./obligation.js";
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAcH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAS1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAOlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EACL,cAAc,EACd,WAAW,GACZ,MAAM,aAAa,CAAC;AAOrB,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAU/B,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAG7D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAS7D,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAO3E,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Inline atom reference syntax.
3
+ *
4
+ * The chat layer embeds atom references in prose using the syntax
5
+ * `{{atom|type|id|label}}`. This module ships a pure parser/serializer
6
+ * pair that operates on strings only — no dependency on the registry.
7
+ *
8
+ * Delimiter is `|`. The previous shape used `:` as the delimiter, which
9
+ * collided with entityId patterns that themselves contain `:` (e.g.
10
+ * `parcel-briefing:{parcelId}:{intentHash}`). `|` is collision-free
11
+ * against every registered entityType, every idResolver-produced id, and
12
+ * every displayLabel produced today. Backward compatibility with the old
13
+ * shape is intentionally NOT supported — see the "old-shape ... no
14
+ * dual-parse contract" test in inline-reference.test.ts.
15
+ */
16
+ import type { AtomMode, AtomReference } from "./registration.js";
17
+ /**
18
+ * Source-of-truth regex. Captures: entityType (no `|`), entityId (no `|`),
19
+ * displayLabel (no `}`). Greedy on the third group so labels with `|` or
20
+ * `:` are accepted (e.g. "Decision: pick HVAC vendor").
21
+ */
22
+ export declare const INLINE_ATOM_REGEX: RegExp;
23
+ /** A single text run between (or surrounding) inline atom references. */
24
+ export interface ParsedTextSegment {
25
+ kind: "text";
26
+ text: string;
27
+ }
28
+ /** A single parsed atom reference. */
29
+ export interface ParsedAtomSegment {
30
+ kind: "atom";
31
+ reference: AtomReference;
32
+ /** The exact source text that produced this segment (for round-trip). */
33
+ raw: string;
34
+ }
35
+ export type ParsedSegment = ParsedTextSegment | ParsedAtomSegment;
36
+ /**
37
+ * Parse `text` into an alternating sequence of text and atom segments.
38
+ * Empty text segments at the start, between atoms, or at the end are
39
+ * preserved as zero-length text runs so a caller iterating segments can
40
+ * always render in order.
41
+ *
42
+ * Malformed markers (missing fields, stray `{{`) are left as plain text.
43
+ */
44
+ export declare function parseInlineReferences(text: string): ParsedSegment[];
45
+ /**
46
+ * Serialize an {@link AtomReference} back to its `{{atom|type|id|label}}`
47
+ * form. Round-trips with {@link parseInlineReferences}.
48
+ *
49
+ * If `mode` is set, it is intentionally **not** serialized — the inline
50
+ * syntax has only three slots and the render binding decides on the mode
51
+ * from chip-vs-expand UX context. If `displayLabel` is missing,
52
+ * `entityId` is used so the syntax stays valid.
53
+ */
54
+ export declare function serializeInlineReference(ref: AtomReference): string;
55
+ /**
56
+ * Re-export {@link AtomMode} so consumers parsing inline references can
57
+ * narrow without a separate import — convenience only.
58
+ */
59
+ export type { AtomMode };
60
+ //# sourceMappingURL=inline-reference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-reference.d.ts","sourceRoot":"","sources":["../src/inline-reference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEjE;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAmD,CAAC;AAEpF,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,aAAa,CAAC;IACzB,yEAAyE;IACzE,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAElE;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CA4BnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAGnE;AAED;;;GAGG;AACH,YAAY,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Inline atom reference syntax.
3
+ *
4
+ * The chat layer embeds atom references in prose using the syntax
5
+ * `{{atom|type|id|label}}`. This module ships a pure parser/serializer
6
+ * pair that operates on strings only — no dependency on the registry.
7
+ *
8
+ * Delimiter is `|`. The previous shape used `:` as the delimiter, which
9
+ * collided with entityId patterns that themselves contain `:` (e.g.
10
+ * `parcel-briefing:{parcelId}:{intentHash}`). `|` is collision-free
11
+ * against every registered entityType, every idResolver-produced id, and
12
+ * every displayLabel produced today. Backward compatibility with the old
13
+ * shape is intentionally NOT supported — see the "old-shape ... no
14
+ * dual-parse contract" test in inline-reference.test.ts.
15
+ */
16
+ /**
17
+ * Source-of-truth regex. Captures: entityType (no `|`), entityId (no `|`),
18
+ * displayLabel (no `}`). Greedy on the third group so labels with `|` or
19
+ * `:` are accepted (e.g. "Decision: pick HVAC vendor").
20
+ */
21
+ export const INLINE_ATOM_REGEX = /\{\{atom\|([^|]+)\|([^|]+)\|([^}]+)\}\}/g;
22
+ /**
23
+ * Parse `text` into an alternating sequence of text and atom segments.
24
+ * Empty text segments at the start, between atoms, or at the end are
25
+ * preserved as zero-length text runs so a caller iterating segments can
26
+ * always render in order.
27
+ *
28
+ * Malformed markers (missing fields, stray `{{`) are left as plain text.
29
+ */
30
+ export function parseInlineReferences(text) {
31
+ const segments = [];
32
+ // Reset state because the regex is `g`-flagged and module-scoped.
33
+ INLINE_ATOM_REGEX.lastIndex = 0;
34
+ let cursor = 0;
35
+ let match;
36
+ while ((match = INLINE_ATOM_REGEX.exec(text)) !== null) {
37
+ const [raw, entityType, entityId, displayLabel] = match;
38
+ if (entityType === undefined || entityId === undefined)
39
+ continue;
40
+ if (match.index > cursor) {
41
+ segments.push({ kind: "text", text: text.slice(cursor, match.index) });
42
+ }
43
+ segments.push({
44
+ kind: "atom",
45
+ raw,
46
+ reference: {
47
+ kind: "atom",
48
+ entityType,
49
+ entityId,
50
+ displayLabel,
51
+ },
52
+ });
53
+ cursor = match.index + raw.length;
54
+ }
55
+ if (cursor < text.length) {
56
+ segments.push({ kind: "text", text: text.slice(cursor) });
57
+ }
58
+ return segments;
59
+ }
60
+ /**
61
+ * Serialize an {@link AtomReference} back to its `{{atom|type|id|label}}`
62
+ * form. Round-trips with {@link parseInlineReferences}.
63
+ *
64
+ * If `mode` is set, it is intentionally **not** serialized — the inline
65
+ * syntax has only three slots and the render binding decides on the mode
66
+ * from chip-vs-expand UX context. If `displayLabel` is missing,
67
+ * `entityId` is used so the syntax stays valid.
68
+ */
69
+ export function serializeInlineReference(ref) {
70
+ const label = ref.displayLabel ?? ref.entityId;
71
+ return `{{atom|${ref.entityType}|${ref.entityId}|${label}}}`;
72
+ }
73
+ //# sourceMappingURL=inline-reference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-reference.js","sourceRoot":"","sources":["../src/inline-reference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAW,0CAA0C,CAAC;AAkBpF;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,kEAAkE;IAClE,iBAAiB,CAAC,SAAS,GAAG,CAAC,CAAC;IAChC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,KAA6B,CAAC;IAClC,OAAO,CAAC,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACvD,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC;QACxD,IAAI,UAAU,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS;YAAE,SAAS;QACjE,IAAI,KAAK,CAAC,KAAK,GAAG,MAAM,EAAE,CAAC;YACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzE,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,MAAM;YACZ,GAAG;YACH,SAAS,EAAE;gBACT,IAAI,EAAE,MAAM;gBACZ,UAAU;gBACV,QAAQ;gBACR,YAAY;aACb;SACF,CAAC,CAAC;QACH,MAAM,GAAG,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC;IACpC,CAAC;IACD,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAkB;IACzD,MAAM,KAAK,GAAG,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,QAAQ,CAAC;IAC/C,OAAO,UAAU,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,QAAQ,IAAI,KAAK,IAAI,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Obligation atom type per ADR-025 — domain-neutral from birth.
3
+ * Shipped in the core contract module (not ./og), consumed by Mox and O&G.
4
+ * The oblg_ prefix registers with the core prefix set.
5
+ *
6
+ * What keeps a lease alive; the first job the product does. Status is
7
+ * engine-derived, never hand-asserted. Each status derivation is a
8
+ * procedure-execution atom (ADR-013) audit trail.
9
+ */
10
+ import { z } from "zod";
11
+ import type { AccessPolicy } from "./registration.js";
12
+ import { type WidthedConfidence } from "./read-contract/common.js";
13
+ /**
14
+ * Obligation type discriminator. ADR-025 specifies O&G obligation types;
15
+ * additively extensible for other verticals (Mox facility obligations, etc.).
16
+ */
17
+ export type ObligationType = "delay-rental" | "shut-in-royalty" | "minimum-royalty" | "bonus" | "rental" | "lease-expiration" | "continuous-development" | "pugh-release" | "other";
18
+ export declare const OBLIGATION_TYPES: ReadonlyArray<ObligationType>;
19
+ /**
20
+ * Obligation status. Derived, never hand-asserted. Each status derivation is
21
+ * recorded as a procedure-execution atom (ADR-013).
22
+ */
23
+ export type ObligationStatus = "upcoming" | "due" | "satisfied" | "delinquent" | "released";
24
+ export declare const OBLIGATION_STATUSES: ReadonlyArray<ObligationStatus>;
25
+ /**
26
+ * Obligation atom instance. Domain-neutral from birth (ADR-025 operator ruling
27
+ * 2): O&G anchors to mineral-lease DIDs (anchorKind: 'mineral-lease'), Mox
28
+ * anchors to facility DIDs (anchorKind: 'facility'). The core type must not
29
+ * freeze a lease-specific field name.
30
+ * DID format: oblg_<hash> (hashed derivation from source, externalId).
31
+ */
32
+ export interface ObligationAtomInstance {
33
+ entityType: "obligation";
34
+ obligationDid: string;
35
+ obligationType: ObligationType;
36
+ anchorDid: string;
37
+ anchorKind?: string;
38
+ owedToActorDid?: string;
39
+ owedToInterestDid?: string;
40
+ dueDate: string;
41
+ recurrence?: string;
42
+ amount?: number;
43
+ graceTerms?: string;
44
+ status: ObligationStatus;
45
+ confidence: WidthedConfidence;
46
+ sourceCitation: string;
47
+ extractedAt: string;
48
+ asOf?: string;
49
+ accessPolicy: AccessPolicy;
50
+ }
51
+ export declare const OBLIGATION_SCHEMA: z.ZodObject<{
52
+ entityType: z.ZodLiteral<"obligation">;
53
+ obligationDid: z.ZodEffects<z.ZodString, string, string>;
54
+ obligationType: z.ZodEnum<[ObligationType, ...ObligationType[]]>;
55
+ anchorDid: z.ZodString;
56
+ anchorKind: z.ZodOptional<z.ZodString>;
57
+ owedToActorDid: z.ZodOptional<z.ZodString>;
58
+ owedToInterestDid: z.ZodOptional<z.ZodString>;
59
+ dueDate: z.ZodString;
60
+ recurrence: z.ZodOptional<z.ZodString>;
61
+ amount: z.ZodOptional<z.ZodNumber>;
62
+ graceTerms: z.ZodOptional<z.ZodString>;
63
+ status: z.ZodEnum<[ObligationStatus, ...ObligationStatus[]]>;
64
+ confidence: z.ZodReadonly<z.ZodObject<{
65
+ readonly estimate: z.ZodNumber;
66
+ readonly n: z.ZodNumber;
67
+ readonly intervalWidth: z.ZodNumber;
68
+ readonly provenance: z.ZodEnum<["asserted", "backtest", "seed", "live"]>;
69
+ }, "strip", z.ZodTypeAny, {
70
+ estimate: number;
71
+ n: number;
72
+ intervalWidth: number;
73
+ provenance: "asserted" | "backtest" | "seed" | "live";
74
+ }, {
75
+ estimate: number;
76
+ n: number;
77
+ intervalWidth: number;
78
+ provenance: "asserted" | "backtest" | "seed" | "live";
79
+ }>>;
80
+ sourceCitation: z.ZodString;
81
+ extractedAt: z.ZodString;
82
+ asOf: z.ZodOptional<z.ZodString>;
83
+ accessPolicy: z.ZodEnum<["public-free", "public-paid", "platform-internal", "tenant-private", "tenant-shared"]>;
84
+ }, "strip", z.ZodTypeAny, {
85
+ accessPolicy: "public-free" | "public-paid" | "platform-internal" | "tenant-private" | "tenant-shared";
86
+ entityType: "obligation";
87
+ status: ObligationStatus;
88
+ confidence: Readonly<{
89
+ estimate: number;
90
+ n: number;
91
+ intervalWidth: number;
92
+ provenance: "asserted" | "backtest" | "seed" | "live";
93
+ }>;
94
+ sourceCitation: string;
95
+ obligationDid: string;
96
+ obligationType: ObligationType;
97
+ anchorDid: string;
98
+ dueDate: string;
99
+ extractedAt: string;
100
+ anchorKind?: string | undefined;
101
+ owedToActorDid?: string | undefined;
102
+ owedToInterestDid?: string | undefined;
103
+ recurrence?: string | undefined;
104
+ amount?: number | undefined;
105
+ graceTerms?: string | undefined;
106
+ asOf?: string | undefined;
107
+ }, {
108
+ accessPolicy: "public-free" | "public-paid" | "platform-internal" | "tenant-private" | "tenant-shared";
109
+ entityType: "obligation";
110
+ status: ObligationStatus;
111
+ confidence: Readonly<{
112
+ estimate: number;
113
+ n: number;
114
+ intervalWidth: number;
115
+ provenance: "asserted" | "backtest" | "seed" | "live";
116
+ }>;
117
+ sourceCitation: string;
118
+ obligationDid: string;
119
+ obligationType: ObligationType;
120
+ anchorDid: string;
121
+ dueDate: string;
122
+ extractedAt: string;
123
+ anchorKind?: string | undefined;
124
+ owedToActorDid?: string | undefined;
125
+ owedToInterestDid?: string | undefined;
126
+ recurrence?: string | undefined;
127
+ amount?: number | undefined;
128
+ graceTerms?: string | undefined;
129
+ asOf?: string | undefined;
130
+ }>;
131
+ //# sourceMapping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I,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuB5B,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Obligation atom type per ADR-025 — domain-neutral from birth.
3
+ * Shipped in the core contract module (not ./og), consumed by Mox and O&G.
4
+ * The oblg_ prefix registers with the core prefix set.
5
+ *
6
+ * What keeps a lease alive; the first job the product does. Status is
7
+ * engine-derived, never hand-asserted. Each status derivation is a
8
+ * procedure-execution atom (ADR-013) audit trail.
9
+ */
10
+ import { z } from "zod";
11
+ import { WIDTHED_CONFIDENCE_SCHEMA } from "./read-contract/common.js";
12
+ import { OG_ACCESS_POLICY_SCHEMA } from "./og/common.js";
13
+ export const OBLIGATION_TYPES = [
14
+ "delay-rental",
15
+ "shut-in-royalty",
16
+ "minimum-royalty",
17
+ "bonus",
18
+ "rental",
19
+ "lease-expiration",
20
+ "continuous-development",
21
+ "pugh-release",
22
+ "other",
23
+ ];
24
+ export const OBLIGATION_STATUSES = [
25
+ "upcoming",
26
+ "due",
27
+ "satisfied",
28
+ "delinquent",
29
+ "released",
30
+ ];
31
+ export const OBLIGATION_SCHEMA = z.object({
32
+ entityType: z.literal("obligation"),
33
+ obligationDid: z
34
+ .string()
35
+ .min(1)
36
+ .refine((val) => /^oblg_[0-9a-f]{16}$/.test(val), {
37
+ message: "obligationDid must be in format oblg_<16-hex-chars>",
38
+ }),
39
+ obligationType: z.enum(OBLIGATION_TYPES),
40
+ anchorDid: z.string().min(1),
41
+ anchorKind: z.string().min(1).optional(),
42
+ owedToActorDid: z.string().min(1).optional(),
43
+ owedToInterestDid: z.string().min(1).optional(),
44
+ dueDate: z.string().min(1),
45
+ recurrence: z.string().min(1).optional(),
46
+ amount: z.number().optional(),
47
+ graceTerms: z.string().min(1).optional(),
48
+ status: z.enum(OBLIGATION_STATUSES),
49
+ confidence: WIDTHED_CONFIDENCE_SCHEMA,
50
+ sourceCitation: z.string().min(1),
51
+ extractedAt: z.string().min(1),
52
+ asOf: z.string().min(1).optional(),
53
+ accessPolicy: OG_ACCESS_POLICY_SCHEMA,
54
+ });
55
+ //# sourceMappingURL=obligation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"obligation.js","sourceRoot":"","sources":["../src/obligation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,yBAAyB,EAA0B,MAAM,2BAA2B,CAAC;AAC9F,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAiBzD,MAAM,CAAC,MAAM,gBAAgB,GAAkC;IAC7D,cAAc;IACd,iBAAiB;IACjB,iBAAiB;IACjB,OAAO;IACP,QAAQ;IACR,kBAAkB;IAClB,wBAAwB;IACxB,cAAc;IACd,OAAO;CACR,CAAC;AAaF,MAAM,CAAC,MAAM,mBAAmB,GAAoC;IAClE,UAAU;IACV,KAAK;IACL,WAAW;IACX,YAAY;IACZ,UAAU;CACX,CAAC;AA6BF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACnC,aAAa,EAAE,CAAC;SACb,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAChD,OAAO,EAAE,qDAAqD;KAC/D,CAAC;IACJ,cAAc,EAAE,CAAC,CAAC,IAAI,CAAC,gBAAyD,CAAC;IACjF,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,UAAU,EAAE,CAAC,CAAC,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