@wirecat/cli-core 0.606.0 → 0.607.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 (209) hide show
  1. package/CHANGELOG.md +186 -1
  2. package/dist/calendar/index.d.ts +1 -0
  3. package/dist/calendar/index.js +1 -0
  4. package/dist/calendar/reads.js +5 -0
  5. package/dist/cli/app-mcp-command.d.ts +6 -2
  6. package/dist/cli/app-mcp-command.js +11 -2
  7. package/dist/cli/csv.d.ts +10 -0
  8. package/dist/cli/csv.js +22 -0
  9. package/dist/cli/early-refusal.d.ts +10 -0
  10. package/dist/cli/early-refusal.js +19 -0
  11. package/dist/cli/index.d.ts +3 -0
  12. package/dist/cli/index.js +3 -0
  13. package/dist/cli/profile-token.d.ts +29 -0
  14. package/dist/cli/profile-token.js +65 -0
  15. package/dist/cli/program.js +4 -2
  16. package/dist/crm/cli/csv.d.ts +23 -0
  17. package/dist/crm/cli/csv.js +135 -0
  18. package/dist/crm/cli/index.d.ts +1 -1
  19. package/dist/crm/cli/index.js +33 -21
  20. package/dist/crm/cli/pipeline-view.d.ts +3 -0
  21. package/dist/crm/cli/pipeline-view.js +36 -0
  22. package/dist/crm/writes.d.ts +6 -4
  23. package/dist/crm/writes.js +17 -13
  24. package/dist/documents.d.ts +2 -0
  25. package/dist/documents.js +2 -0
  26. package/dist/domain/business.d.ts +79 -0
  27. package/dist/domain/business.js +42 -0
  28. package/dist/domain/finance.d.ts +2 -0
  29. package/dist/domain/finance.js +2 -2
  30. package/dist/domain/google-documents.d.ts +2 -0
  31. package/dist/domain/google-documents.js +3 -1
  32. package/dist/domain/money.d.ts +2 -0
  33. package/dist/domain/money.js +11 -3
  34. package/dist/domain/providers.d.ts +36 -1
  35. package/dist/domain/providers.js +69 -7
  36. package/dist/domain/record-fields.d.ts +42 -0
  37. package/dist/domain/record-fields.js +122 -0
  38. package/dist/domain/record-types.d.ts +489 -16
  39. package/dist/domain/record-types.js +374 -7
  40. package/dist/domain/records.d.ts +96 -5
  41. package/dist/domain/records.js +178 -32
  42. package/dist/domain/ref-summaries.js +5 -0
  43. package/dist/domain/references.d.ts +1 -1
  44. package/dist/domain/references.js +5 -0
  45. package/dist/domain/vcard.d.ts +25 -0
  46. package/dist/domain/vcard.js +267 -0
  47. package/dist/entities/deal.d.ts +14 -0
  48. package/dist/entities/deal.js +3 -0
  49. package/dist/entities/index.d.ts +12 -0
  50. package/dist/errors/reasons.js +61 -2
  51. package/dist/fetch/addresses.d.ts +5 -0
  52. package/dist/fetch/addresses.js +76 -0
  53. package/dist/fetch/page.d.ts +64 -0
  54. package/dist/fetch/page.js +256 -0
  55. package/dist/index.d.ts +5 -3
  56. package/dist/index.js +5 -3
  57. package/dist/meetings/calendar-text.d.ts +1 -1
  58. package/dist/meetings/calendar-text.js +4 -0
  59. package/dist/meetings/event-store.d.ts +2 -2
  60. package/dist/search/account-list.d.ts +4 -0
  61. package/dist/search/account-list.js +19 -8
  62. package/dist/search/query.js +2 -2
  63. package/dist/services/events-search.js +2 -2
  64. package/dist/services/index.d.ts +1 -1
  65. package/dist/services/index.js +1 -1
  66. package/dist/services/ingest.d.ts +56 -8
  67. package/dist/services/ingest.js +95 -61
  68. package/dist/services/messages-search.js +3 -2
  69. package/dist/services/metadata.d.ts +1 -1
  70. package/dist/services/notes-search.js +1 -0
  71. package/dist/services/proposals/kinds/contracts.d.ts +4 -0
  72. package/dist/services/proposals/kinds/contracts.js +9 -0
  73. package/dist/services/proposals/kinds/finance.d.ts +4 -0
  74. package/dist/services/proposals/kinds/finance.js +14 -35
  75. package/dist/services/proposals/kinds/orders.js +7 -30
  76. package/dist/services/proposals/kinds/shared.d.ts +27 -1
  77. package/dist/services/proposals/kinds/shared.js +34 -0
  78. package/dist/services/proposals/kinds/source-review.d.ts +4 -0
  79. package/dist/services/proposals/kinds/source-review.js +45 -0
  80. package/dist/services/proposals/kinds/subscriptions.d.ts +9 -0
  81. package/dist/services/proposals/kinds/subscriptions.js +24 -0
  82. package/dist/services/proposals/kinds/transactions.d.ts +4 -0
  83. package/dist/services/proposals/kinds/transactions.js +10 -0
  84. package/dist/services/proposals/registry.js +9 -0
  85. package/dist/services/search-all-meetings.js +2 -2
  86. package/dist/services/search-all.js +4 -3
  87. package/dist/services/search-kind.js +3 -3
  88. package/dist/store/decisions.js +5 -1
  89. package/dist/store/index.d.ts +14 -3
  90. package/dist/store/index.js +3 -0
  91. package/dist/store/people.js +1 -1
  92. package/dist/store/source-review.d.ts +64 -0
  93. package/dist/store/source-review.js +7 -0
  94. package/dist/store/sqlite/accounts.d.ts +1 -1
  95. package/dist/store/sqlite/accounts.js +24 -1
  96. package/dist/store/sqlite/added-sources.d.ts +82 -0
  97. package/dist/store/sqlite/added-sources.js +237 -0
  98. package/dist/store/sqlite/business-contracts.d.ts +90 -0
  99. package/dist/store/sqlite/business-contracts.js +182 -0
  100. package/dist/store/sqlite/calendar-events.js +7 -3
  101. package/dist/store/sqlite/calendar-forget.js +3 -0
  102. package/dist/store/sqlite/calendar.d.ts +21 -1
  103. package/dist/store/sqlite/calendar.js +27 -7
  104. package/dist/store/sqlite/chat-rekey.js +7 -0
  105. package/dist/store/sqlite/chats.d.ts +3 -1
  106. package/dist/store/sqlite/chats.js +15 -1
  107. package/dist/store/sqlite/crm-rows.d.ts +44 -0
  108. package/dist/store/sqlite/crm-rows.js +195 -0
  109. package/dist/store/sqlite/crm.d.ts +2 -11
  110. package/dist/store/sqlite/crm.js +11 -166
  111. package/dist/store/sqlite/deals.d.ts +4 -8
  112. package/dist/store/sqlite/deals.js +5 -3
  113. package/dist/store/sqlite/document-transfer/snapshot.js +2 -2
  114. package/dist/store/sqlite/emails.js +2 -0
  115. package/dist/store/sqlite/entity-types.d.ts +14 -9
  116. package/dist/store/sqlite/entity-types.js +4 -10
  117. package/dist/store/sqlite/evidence-signature.d.ts +114 -0
  118. package/dist/store/sqlite/evidence-signature.js +349 -0
  119. package/dist/store/sqlite/evidence-sources.d.ts +2 -1
  120. package/dist/store/sqlite/evidence-sources.js +7 -3
  121. package/dist/store/sqlite/facts.d.ts +7 -2
  122. package/dist/store/sqlite/facts.js +21 -5
  123. package/dist/store/sqlite/finance.d.ts +18 -105
  124. package/dist/store/sqlite/finance.js +100 -219
  125. package/dist/store/sqlite/knowledge.d.ts +8 -2
  126. package/dist/store/sqlite/knowledge.js +65 -71
  127. package/dist/store/sqlite/labelled.d.ts +3 -0
  128. package/dist/store/sqlite/labelled.js +11 -0
  129. package/dist/store/sqlite/link-kinds.d.ts +2 -0
  130. package/dist/store/sqlite/link-kinds.js +2 -0
  131. package/dist/store/sqlite/manifest.js +2 -0
  132. package/dist/store/sqlite/memories.d.ts +23 -9
  133. package/dist/store/sqlite/memories.js +41 -13
  134. package/dist/store/sqlite/messages.js +2 -0
  135. package/dist/store/sqlite/migrations.generated.js +103 -0
  136. package/dist/store/sqlite/money-lines.d.ts +48 -0
  137. package/dist/store/sqlite/money-lines.js +76 -0
  138. package/dist/store/sqlite/money-transactions.d.ts +132 -0
  139. package/dist/store/sqlite/money-transactions.js +295 -0
  140. package/dist/store/sqlite/notes.d.ts +11 -2
  141. package/dist/store/sqlite/notes.js +20 -25
  142. package/dist/store/sqlite/orders.d.ts +36 -6
  143. package/dist/store/sqlite/orders.js +126 -46
  144. package/dist/store/sqlite/payment-facts.js +1 -1
  145. package/dist/store/sqlite/private-people.js +2 -0
  146. package/dist/store/sqlite/products.d.ts +78 -0
  147. package/dist/store/sqlite/products.js +131 -0
  148. package/dist/store/sqlite/project-transfer/records.js +26 -1
  149. package/dist/store/sqlite/project-transfer/snapshot.js +5 -3
  150. package/dist/store/sqlite/proposed-actions.d.ts +1 -1
  151. package/dist/store/sqlite/proposed-actions.js +24 -7
  152. package/dist/store/sqlite/providers.d.ts +0 -4
  153. package/dist/store/sqlite/providers.js +20 -2
  154. package/dist/store/sqlite/record-matching.d.ts +80 -0
  155. package/dist/store/sqlite/record-matching.js +264 -0
  156. package/dist/store/sqlite/record-projection.d.ts +89 -0
  157. package/dist/store/sqlite/record-projection.js +50 -0
  158. package/dist/store/sqlite/record-projectors-direct.d.ts +17 -0
  159. package/dist/store/sqlite/record-projectors-direct.js +125 -0
  160. package/dist/store/sqlite/record-projectors-money.d.ts +26 -0
  161. package/dist/store/sqlite/record-projectors-money.js +214 -0
  162. package/dist/store/sqlite/record-projectors-phone.d.ts +28 -0
  163. package/dist/store/sqlite/record-projectors-phone.js +212 -0
  164. package/dist/store/sqlite/record-projectors.d.ts +3 -44
  165. package/dist/store/sqlite/record-projectors.js +7 -67
  166. package/dist/store/sqlite/record-relations.d.ts +24 -0
  167. package/dist/store/sqlite/record-relations.js +92 -0
  168. package/dist/store/sqlite/record-remap.d.ts +12 -0
  169. package/dist/store/sqlite/record-remap.js +92 -0
  170. package/dist/store/sqlite/record-run.d.ts +71 -0
  171. package/dist/store/sqlite/record-run.js +179 -0
  172. package/dist/store/sqlite/record-settling.d.ts +9 -0
  173. package/dist/store/sqlite/record-settling.js +74 -0
  174. package/dist/store/sqlite/record-stamps.d.ts +13 -0
  175. package/dist/store/sqlite/record-stamps.js +30 -0
  176. package/dist/store/sqlite/record-writes.d.ts +43 -0
  177. package/dist/store/sqlite/record-writes.js +307 -0
  178. package/dist/store/sqlite/records.d.ts +52 -42
  179. package/dist/store/sqlite/records.js +123 -353
  180. package/dist/store/sqlite/ref-summaries.d.ts +6 -5
  181. package/dist/store/sqlite/ref-summaries.js +60 -8
  182. package/dist/store/sqlite/refunds.d.ts +31 -0
  183. package/dist/store/sqlite/refunds.js +112 -0
  184. package/dist/store/sqlite/reviewed.d.ts +109 -0
  185. package/dist/store/sqlite/reviewed.js +173 -0
  186. package/dist/store/sqlite/schema.d.ts +2840 -83
  187. package/dist/store/sqlite/schema.js +256 -1
  188. package/dist/store/sqlite/source-review-marks.d.ts +54 -0
  189. package/dist/store/sqlite/source-review-marks.js +143 -0
  190. package/dist/store/sqlite/source-review.d.ts +54 -0
  191. package/dist/store/sqlite/source-review.js +221 -0
  192. package/dist/store/sqlite/stage-amounts.d.ts +14 -0
  193. package/dist/store/sqlite/stage-amounts.js +23 -0
  194. package/dist/store/sqlite/subscriptions.d.ts +135 -0
  195. package/dist/store/sqlite/subscriptions.js +294 -0
  196. package/dist/store/sqlite/text-input.d.ts +3 -0
  197. package/dist/store/sqlite/text-input.js +13 -0
  198. package/dist/store/sqlite/things.js +2 -9
  199. package/dist/store/sqlite/transaction.d.ts +15 -0
  200. package/dist/store/sqlite/transaction.js +57 -0
  201. package/dist/store/sqlite/wallets.d.ts +88 -0
  202. package/dist/store/sqlite/wallets.js +143 -0
  203. package/dist/store/store-errors.d.ts +1 -0
  204. package/dist/store/store-errors.js +45 -0
  205. package/dist/store/store.d.ts +16 -1
  206. package/dist/store/store.js +30 -6
  207. package/package.json +5 -2
  208. package/schemas/examples/records-business.jsonl +11 -0
  209. package/schemas/records-envelope.v1.schema.json +1160 -5
@@ -1,61 +1,534 @@
1
- /** Types with a table of their own; anything else a source sends is `custom:<name>` and stays a record only. */
2
- export declare const RECORD_ENTITY_TYPES: readonly ["invoice", "payment", "person", "organization", "project"];
3
- export type RecordEntityType = (typeof RECORD_ENTITY_TYPES)[number];
1
+ import { type FieldSchema } from "./record-fields.js";
2
+ import type { RelationKind } from "./relations.js";
4
3
  export interface RecordRoleSpec {
5
- /** Several relations may carry it; a single role may also be named in `fields.<role>`. */
4
+ /** The record types a relation of this role may point at; a typed ref (`organization:12`) is held to them too. */
5
+ targets: readonly string[];
6
6
  many?: boolean;
7
+ /** A record of the type is refused without one. */
8
+ required?: boolean;
9
+ /** Only `settles` carries a share of the payment. */
7
10
  amount?: boolean;
11
+ /** A business relationship between entities, by its kind: the relation may carry `as`, the part the target plays. */
12
+ relationship?: RelationKind;
13
+ /** Kept in `record_relations` only, never read to make the entity, so it never makes a record wait (PR 5). */
14
+ kept?: boolean;
15
+ /**
16
+ * A role v1 already had: `fields.<role>` may name a store ref instead of a relation, and its target type is not
17
+ * checked, so every v1 file means what it meant.
18
+ */
19
+ v1?: boolean;
20
+ /** The entity's own column this role fills, which an owner's remap repoints. */
21
+ column?: string;
22
+ /** `column` names a `<column>_type`/`<column>_id` pair, a person or an organization, not a foreign key. */
23
+ pair?: boolean;
24
+ /**
25
+ * Filled as a link instead of a column: an SMS's identity linked to the person, a call's `related-to` link. The
26
+ * remap repoints it too.
27
+ */
28
+ linked?: boolean;
29
+ }
30
+ export interface NestedSpec {
31
+ /** Where the items are kept, and the column naming their parent. */
32
+ table: string;
33
+ parent: string;
34
+ /** Item keys that name another record of this account by external id, and the type of that record. */
35
+ references?: Record<string, string>;
36
+ /** Item keys that name an entity by its ref, and the type it must be. */
37
+ refs?: Record<string, string>;
8
38
  }
9
39
  export interface RecordTypeSpec {
10
40
  table: string;
11
- /** `proposal`: the import proposes the entity and the owner decides; `identity`: only the owner's `map` gives one. */
12
- review: "proposal" | "identity";
41
+ /**
42
+ * `proposal`: an agent's or an import's row waits for the owner; `valued-proposal`: only while it carries money;
43
+ * `direct`: written as given, it feeds no total; `identity`: matched by a strong identifier or made by the import.
44
+ */
45
+ review: "proposal" | "valued-proposal" | "direct" | "identity";
46
+ /**
47
+ * What a changed record does to its entity: `in-place` updates it, `re-propose` updates a proposal the import made
48
+ * while the owner has not decided it and flags it after, `re-settle` takes a proposed payment's settles again,
49
+ * `flag` leaves the entity and reports it.
50
+ */
51
+ update: "in-place" | "re-propose" | "re-settle" | "flag";
52
+ /** A row can be marked gone, so a ref to it may read as deleted. */
53
+ tombstone: boolean;
54
+ /**
55
+ * A copy of what a sync would write (an SMS, a call): taken only under a provider marked import-only, so it can
56
+ * never land in a messenger's chat or a calendar's account.
57
+ */
58
+ importOnly?: boolean;
59
+ /** The type's `fields`: known keys typed, any other key kept as sent. */
60
+ fields: FieldSchema;
13
61
  /** The roles the entity is made from; any other role word is kept as the source's own. */
14
62
  roles: Record<string, RecordRoleSpec>;
63
+ /** Lists inside `fields` whose items name products or other records. */
64
+ nested?: Record<string, NestedSpec>;
65
+ /** Keys of `fields` that name another record of this account by external id, and its type: a deal's pipeline. */
66
+ references?: Record<string, string>;
15
67
  }
68
+ export declare const SMS_DIRECTIONS: readonly ["in", "out"];
69
+ export declare const CALL_DIRECTIONS: readonly ["in", "out", "missed"];
70
+ /** The one registry of typed entities: refs, tables, the owner's decisions and the envelope read it. */
16
71
  export declare const RECORD_TYPES: {
17
72
  readonly invoice: {
18
73
  readonly table: "invoices";
19
74
  readonly review: "proposal";
75
+ readonly update: "flag";
76
+ readonly tombstone: true;
77
+ readonly fields: FieldSchema;
20
78
  readonly roles: {
21
- readonly issuer: {};
22
- readonly counterparty: {};
23
- readonly project: {};
79
+ readonly issuer: {
80
+ readonly targets: readonly ["person", "organization"];
81
+ readonly v1: true;
82
+ readonly column: "issuer";
83
+ readonly pair: true;
84
+ };
85
+ readonly counterparty: {
86
+ readonly targets: readonly ["person", "organization"];
87
+ readonly v1: true;
88
+ readonly column: "counterparty";
89
+ readonly pair: true;
90
+ };
91
+ readonly project: {
92
+ readonly targets: readonly ["project"];
93
+ readonly v1: true;
94
+ readonly column: "project_id";
95
+ };
96
+ readonly contract: {
97
+ readonly targets: readonly ["contract"];
98
+ readonly column: "contract_id";
99
+ };
100
+ readonly subscription: {
101
+ readonly targets: readonly ["subscription"];
102
+ readonly column: "subscription_id";
103
+ };
104
+ };
105
+ readonly nested: {
106
+ readonly lines: {
107
+ readonly table: string;
108
+ readonly parent: string;
109
+ readonly references: {
110
+ readonly product: "product";
111
+ };
112
+ readonly refs: {
113
+ readonly product_ref: "product";
114
+ };
115
+ };
24
116
  };
25
117
  };
26
118
  readonly payment: {
27
119
  readonly table: "payments";
28
120
  readonly review: "proposal";
121
+ readonly update: "re-settle";
122
+ readonly tombstone: true;
123
+ readonly fields: FieldSchema;
29
124
  readonly roles: {
30
- readonly payer: {};
31
- readonly payee: {};
32
- readonly project: {};
125
+ readonly payer: {
126
+ readonly targets: readonly ["person", "organization"];
127
+ readonly v1: true;
128
+ readonly column: "payer";
129
+ readonly pair: true;
130
+ };
131
+ readonly payee: {
132
+ readonly targets: readonly ["person", "organization"];
133
+ readonly v1: true;
134
+ readonly column: "payee";
135
+ readonly pair: true;
136
+ };
137
+ readonly project: {
138
+ readonly targets: readonly ["project"];
139
+ readonly v1: true;
140
+ readonly column: "project_id";
141
+ };
33
142
  readonly settles: {
143
+ readonly targets: readonly ["invoice"];
34
144
  readonly many: true;
35
145
  readonly amount: true;
146
+ readonly v1: true;
147
+ };
148
+ readonly refund_of: {
149
+ readonly targets: readonly ["payment"];
150
+ readonly column: "refund_of";
151
+ };
152
+ readonly subscription: {
153
+ readonly targets: readonly ["subscription"];
154
+ readonly column: "subscription_id";
36
155
  };
37
156
  };
38
157
  };
39
158
  readonly person: {
40
159
  readonly table: "persons";
41
160
  readonly review: "identity";
42
- readonly roles: {};
161
+ readonly update: "in-place";
162
+ readonly tombstone: false;
163
+ readonly fields: FieldSchema;
164
+ readonly roles: {
165
+ readonly "member-of": {
166
+ readonly targets: readonly ["organization"];
167
+ readonly relationship: "member-of";
168
+ readonly kept: true;
169
+ };
170
+ };
43
171
  };
44
172
  readonly organization: {
45
173
  readonly table: "organizations";
46
174
  readonly review: "identity";
47
- readonly roles: {};
175
+ readonly update: "in-place";
176
+ readonly tombstone: true;
177
+ readonly fields: FieldSchema;
178
+ readonly roles: {
179
+ readonly "customer-of": {
180
+ readonly targets: readonly ["organization"];
181
+ readonly relationship: "customer-of";
182
+ readonly kept: true;
183
+ };
184
+ readonly "partner-of": {
185
+ readonly targets: readonly ["organization"];
186
+ readonly relationship: "partner-of";
187
+ readonly kept: true;
188
+ };
189
+ };
48
190
  };
49
191
  readonly project: {
50
192
  readonly table: "projects";
51
193
  readonly review: "identity";
194
+ readonly update: "in-place";
195
+ readonly tombstone: true;
196
+ readonly fields: FieldSchema;
197
+ readonly roles: {
198
+ readonly organization: {
199
+ readonly targets: readonly ["organization"];
200
+ readonly column: "organization_id";
201
+ };
202
+ };
203
+ };
204
+ readonly order: {
205
+ readonly table: "orders";
206
+ readonly review: "proposal";
207
+ readonly update: "re-propose";
208
+ readonly tombstone: true;
209
+ readonly fields: FieldSchema;
210
+ readonly roles: {
211
+ readonly customer: {
212
+ readonly targets: readonly ["person", "organization"];
213
+ readonly column: "customer";
214
+ readonly pair: true;
215
+ };
216
+ readonly supplier: {
217
+ readonly targets: readonly ["person", "organization"];
218
+ readonly column: "supplier";
219
+ readonly pair: true;
220
+ };
221
+ readonly project: {
222
+ readonly targets: readonly ["project"];
223
+ readonly column: "project_id";
224
+ };
225
+ readonly contract: {
226
+ readonly targets: readonly ["contract"];
227
+ readonly column: "contract_id";
228
+ };
229
+ readonly deal: {
230
+ readonly targets: readonly ["deal"];
231
+ readonly column: "deal_id";
232
+ };
233
+ readonly invoice: {
234
+ readonly targets: readonly ["invoice"];
235
+ readonly column: "invoice_id";
236
+ };
237
+ readonly payment: {
238
+ readonly targets: readonly ["payment"];
239
+ readonly column: "payment_id";
240
+ };
241
+ };
242
+ readonly nested: {
243
+ readonly lines: {
244
+ readonly table: string;
245
+ readonly parent: string;
246
+ readonly references: {
247
+ readonly product: "product";
248
+ };
249
+ readonly refs: {
250
+ readonly product_ref: "product";
251
+ };
252
+ };
253
+ };
254
+ };
255
+ readonly product: {
256
+ readonly table: "catalog_items";
257
+ readonly review: "direct";
258
+ readonly update: "in-place";
259
+ readonly tombstone: true;
260
+ readonly fields: FieldSchema;
261
+ readonly roles: {
262
+ readonly supplier: {
263
+ readonly targets: readonly ["person", "organization"];
264
+ readonly column: "supplier";
265
+ readonly pair: true;
266
+ };
267
+ };
268
+ };
269
+ readonly contract: {
270
+ readonly table: "contracts";
271
+ readonly review: "valued-proposal";
272
+ readonly update: "re-propose";
273
+ readonly tombstone: true;
274
+ readonly fields: FieldSchema;
275
+ readonly roles: {
276
+ readonly project: {
277
+ readonly targets: readonly ["project"];
278
+ readonly column: "project_id";
279
+ };
280
+ readonly deal: {
281
+ readonly targets: readonly ["deal"];
282
+ readonly column: "deal_id";
283
+ };
284
+ readonly party: {
285
+ readonly targets: readonly ["person", "organization"];
286
+ readonly many: true;
287
+ readonly relationship: "related-to";
288
+ readonly kept: true;
289
+ };
290
+ readonly document: {
291
+ readonly targets: readonly ["document"];
292
+ readonly many: true;
293
+ readonly kept: true;
294
+ };
295
+ };
296
+ };
297
+ readonly subscription: {
298
+ readonly table: "subscriptions";
299
+ readonly review: "proposal";
300
+ readonly update: "re-propose";
301
+ readonly tombstone: true;
302
+ readonly fields: FieldSchema;
303
+ readonly roles: {
304
+ readonly supplier: {
305
+ readonly targets: readonly ["person", "organization"];
306
+ readonly column: "supplier";
307
+ readonly pair: true;
308
+ };
309
+ readonly customer: {
310
+ readonly targets: readonly ["person", "organization"];
311
+ readonly column: "customer";
312
+ readonly pair: true;
313
+ };
314
+ readonly product: {
315
+ readonly targets: readonly ["product"];
316
+ readonly column: "catalog_item_id";
317
+ };
318
+ readonly contract: {
319
+ readonly targets: readonly ["contract"];
320
+ readonly column: "contract_id";
321
+ };
322
+ readonly project: {
323
+ readonly targets: readonly ["project"];
324
+ readonly column: "project_id";
325
+ };
326
+ };
327
+ readonly nested: {
328
+ readonly prices: {
329
+ readonly table: "subscription_prices";
330
+ readonly parent: "subscription_id";
331
+ };
332
+ };
333
+ };
334
+ readonly wallet: {
335
+ readonly table: "financial_accounts";
336
+ readonly review: "direct";
337
+ readonly update: "in-place";
338
+ readonly tombstone: true;
339
+ readonly fields: FieldSchema;
340
+ readonly roles: {
341
+ readonly holder: {
342
+ readonly targets: readonly ["person", "organization"];
343
+ readonly column: "holder";
344
+ readonly pair: true;
345
+ };
346
+ };
347
+ };
348
+ readonly transaction: {
349
+ readonly table: "financial_transactions";
350
+ readonly review: "proposal";
351
+ readonly update: "re-propose";
352
+ readonly tombstone: true;
353
+ readonly fields: FieldSchema;
354
+ readonly roles: {
355
+ readonly wallet: {
356
+ readonly targets: readonly ["wallet"];
357
+ readonly required: true;
358
+ readonly column: "financial_account_id";
359
+ };
360
+ readonly counterparty: {
361
+ readonly targets: readonly ["person", "organization"];
362
+ readonly column: "counterparty";
363
+ readonly pair: true;
364
+ };
365
+ readonly payment: {
366
+ readonly targets: readonly ["payment"];
367
+ readonly column: "payment_id";
368
+ };
369
+ readonly project: {
370
+ readonly targets: readonly ["project"];
371
+ readonly column: "project_id";
372
+ };
373
+ };
374
+ readonly nested: {
375
+ readonly splits: {
376
+ readonly table: "transaction_splits";
377
+ readonly parent: "transaction_id";
378
+ };
379
+ };
380
+ };
381
+ readonly deal: {
382
+ readonly table: "deals";
383
+ readonly review: "direct";
384
+ readonly update: "in-place";
385
+ readonly tombstone: true;
386
+ readonly fields: FieldSchema;
387
+ readonly references: {
388
+ readonly pipeline: "pipeline";
389
+ };
390
+ readonly roles: {
391
+ readonly organization: {
392
+ readonly targets: readonly ["organization"];
393
+ readonly column: "organization_id";
394
+ };
395
+ readonly person: {
396
+ readonly targets: readonly ["person"];
397
+ readonly many: true;
398
+ readonly relationship: "related-to";
399
+ readonly kept: true;
400
+ };
401
+ readonly project: {
402
+ readonly targets: readonly ["project"];
403
+ readonly column: "project_id";
404
+ };
405
+ };
406
+ };
407
+ readonly lead: {
408
+ readonly table: "leads";
409
+ readonly review: "direct";
410
+ readonly update: "in-place";
411
+ readonly tombstone: true;
412
+ readonly fields: FieldSchema;
413
+ readonly references: {
414
+ readonly pipeline: "pipeline";
415
+ };
416
+ readonly roles: {
417
+ readonly organization: {
418
+ readonly targets: readonly ["organization"];
419
+ readonly column: "organization_id";
420
+ };
421
+ readonly person: {
422
+ readonly targets: readonly ["person"];
423
+ readonly many: true;
424
+ readonly relationship: "related-to";
425
+ readonly kept: true;
426
+ };
427
+ readonly project: {
428
+ readonly targets: readonly ["project"];
429
+ readonly column: "project_id";
430
+ };
431
+ readonly deal: {
432
+ readonly targets: readonly ["deal"];
433
+ readonly column: "deal_id";
434
+ };
435
+ };
436
+ };
437
+ readonly message: {
438
+ readonly table: "messages";
439
+ readonly review: "direct";
440
+ readonly update: "in-place";
441
+ readonly tombstone: true;
442
+ readonly importOnly: true;
443
+ readonly fields: FieldSchema;
444
+ readonly roles: {
445
+ readonly counterpart: {
446
+ readonly targets: readonly ["person"];
447
+ readonly linked: true;
448
+ };
449
+ };
450
+ };
451
+ readonly event: {
452
+ readonly table: "events";
453
+ readonly review: "direct";
454
+ readonly update: "in-place";
455
+ readonly tombstone: true;
456
+ readonly importOnly: true;
457
+ readonly fields: FieldSchema;
458
+ readonly roles: {
459
+ readonly counterpart: {
460
+ readonly targets: readonly ["person"];
461
+ readonly linked: true;
462
+ };
463
+ };
464
+ };
465
+ readonly pipeline: {
466
+ readonly table: "pipelines";
467
+ readonly review: "direct";
468
+ readonly update: "in-place";
469
+ readonly tombstone: false;
470
+ readonly fields: FieldSchema;
52
471
  readonly roles: {};
472
+ readonly nested: {
473
+ readonly stages: {
474
+ readonly table: "pipeline_stages";
475
+ readonly parent: "pipeline_id";
476
+ };
477
+ };
53
478
  };
54
479
  };
480
+ export type RecordType = keyof typeof RECORD_TYPES;
481
+ /** Every registered type is an envelope type: `custom:<name>` covers whatever a source has beyond them. */
482
+ export type RecordEntityType = RecordType;
483
+ export declare const isRecordType: (type: string) => type is RecordType;
484
+ type Identity<T> = {
485
+ [K in keyof T]: T[K] extends {
486
+ review: "identity";
487
+ } ? K : never;
488
+ }[keyof T];
489
+ export type IdentityType = Identity<typeof RECORD_TYPES>;
490
+ export type BusinessType = Exclude<RecordType, IdentityType>;
491
+ /** A business record (an invoice, a deal, a wallet): not a person, organization or project. */
492
+ export declare const isBusinessType: (type: string) => type is BusinessType;
493
+ export declare const isIdentityType: (type: unknown) => type is IdentityType;
494
+ export declare const RECORD_ENTITY_TYPES: RecordType[];
495
+ type Tables<T> = {
496
+ [K in keyof T]: T[K] extends {
497
+ table: infer N;
498
+ } ? N : never;
499
+ };
500
+ /** Each registered type's table, for the store's polymorphic pointers. */
501
+ export declare const RECORD_TABLES: Tables<typeof RECORD_TYPES>;
502
+ /**
503
+ * Where the owner's decision on each reviewed type is kept. A subscription's price is decided row by row, so it is
504
+ * one of them though it has no ref of its own.
505
+ */
506
+ export declare const DECIDED_TABLES: {
507
+ readonly invoice: "invoices";
508
+ readonly payment: "payments";
509
+ readonly order: "orders";
510
+ readonly contract: "contracts";
511
+ readonly subscription: "subscriptions";
512
+ readonly transaction: "financial_transactions";
513
+ readonly subscription_price: "subscription_prices";
514
+ };
515
+ export type DecidedType = keyof typeof DECIDED_TABLES;
516
+ export type DecidedTable = (typeof DECIDED_TABLES)[DecidedType];
55
517
  /** A role word, a source provider, and the name after `custom:`. */
56
518
  export declare const WORD_BODY = "[a-z0-9][a-z0-9_-]{0,62}";
57
519
  export declare const TYPE_PATTERN: string;
58
520
  export declare const TYPE_RULE: string;
59
- export declare const rolesOf: (type: RecordEntityType) => [string, RecordRoleSpec][];
60
- export declare const roleNames: (types: readonly RecordEntityType[], keep: (role: RecordRoleSpec) => boolean | undefined) => string[];
521
+ export declare const rolesOf: (type: RecordType) => [string, RecordRoleSpec][];
522
+ export declare const roleOf: (type: string, role: string) => RecordRoleSpec | undefined;
523
+ export declare const nestedOf: (type: RecordType) => [string, NestedSpec][];
524
+ export declare const referencesOf: (type: RecordType) => [string, string][];
525
+ export declare const roleNames: (types: readonly RecordType[], keep: (role: RecordRoleSpec) => boolean | undefined) => string[];
61
526
  export declare const AMOUNT_ROLES: string[];
527
+ /** v1's roles of a type, which `fields.<role>` may also name: v1 refused such a field when it was not text. */
528
+ export declare const FIELD_REFERENCE_ROLES: string[];
529
+ /** The types whose records v1 projected: their v1 roles keep v1's reading. */
530
+ export declare const hasV1Roles: (type: RecordType) => boolean;
531
+ export declare const IDENTITY_TYPES: ("contract" | "deal" | "event" | "invoice" | "lead" | "message" | "order" | "organization" | "payment" | "person" | "pipeline" | "product" | "project" | "subscription" | "transaction" | "wallet")[];
532
+ /** `a` or `an` before a type word: `an event`, `an invoice`, `a message`. */
533
+ export declare const article: (word: string) => "a" | "an";
534
+ export {};