@voyantjs/crm 0.26.2 → 0.26.4
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.
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/routes/customer-signals.d.ts +281 -0
- package/dist/routes/customer-signals.d.ts.map +1 -0
- package/dist/routes/customer-signals.js +45 -0
- package/dist/routes/index.d.ts +450 -0
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +4 -0
- package/dist/routes/person-relationships.d.ts +189 -0
- package/dist/routes/person-relationships.d.ts.map +1 -0
- package/dist/routes/person-relationships.js +36 -0
- package/dist/schema-accounts.d.ts +237 -0
- package/dist/schema-accounts.d.ts.map +1 -1
- package/dist/schema-accounts.js +64 -1
- package/dist/schema-signals.d.ts +324 -0
- package/dist/schema-signals.d.ts.map +1 -0
- package/dist/schema-signals.js +80 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -0
- package/dist/service/customer-signals.d.ts +733 -0
- package/dist/service/customer-signals.d.ts.map +1 -0
- package/dist/service/customer-signals.js +112 -0
- package/dist/service/index.d.ts +1187 -0
- package/dist/service/index.d.ts.map +1 -1
- package/dist/service/index.js +6 -0
- package/dist/service/person-relationships.d.ts +502 -0
- package/dist/service/person-relationships.d.ts.map +1 -0
- package/dist/service/person-relationships.js +121 -0
- package/dist/validation.d.ts +246 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +98 -0
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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9B,YAAY,EACV,6BAA6B,EAC7B,sBAAsB,EACtB,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA"}
|
package/dist/service/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { accountsService } from "./accounts.js";
|
|
2
2
|
import { activitiesService } from "./activities.js";
|
|
3
3
|
import { customFieldsService } from "./custom-fields.js";
|
|
4
|
+
import { customerSignalsService } from "./customer-signals.js";
|
|
4
5
|
import { opportunitiesService } from "./opportunities.js";
|
|
5
6
|
import { personDocumentsService } from "./person-documents.js";
|
|
7
|
+
import { personRelationshipsService } from "./person-relationships.js";
|
|
6
8
|
import { pipelinesService } from "./pipelines.js";
|
|
7
9
|
import { quotesService } from "./quotes.js";
|
|
8
10
|
export const crmService = {
|
|
@@ -13,5 +15,9 @@ export const crmService = {
|
|
|
13
15
|
...activitiesService,
|
|
14
16
|
...customFieldsService,
|
|
15
17
|
...personDocumentsService,
|
|
18
|
+
...personRelationshipsService,
|
|
19
|
+
...customerSignalsService,
|
|
16
20
|
};
|
|
21
|
+
export { customerSignalsService } from "./customer-signals.js";
|
|
17
22
|
export { personDocumentNumberPlaintextSchema, personDocumentsService, personPiiBlobPlaintextSchema, } from "./person-documents.js";
|
|
23
|
+
export { personRelationshipsService } from "./person-relationships.js";
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import type { insertPersonRelationshipSchema, personRelationshipListQuerySchema, updatePersonRelationshipSchema } from "../validation.js";
|
|
4
|
+
export type CreatePersonRelationshipInput = z.infer<typeof insertPersonRelationshipSchema>;
|
|
5
|
+
export type UpdatePersonRelationshipInput = z.infer<typeof updatePersonRelationshipSchema>;
|
|
6
|
+
export type PersonRelationshipListQuery = z.infer<typeof personRelationshipListQuerySchema>;
|
|
7
|
+
export type PersonRelationshipKind = CreatePersonRelationshipInput["kind"];
|
|
8
|
+
export declare const personRelationshipsService: {
|
|
9
|
+
/**
|
|
10
|
+
* Lists relationships for a person. Default `direction: "both"`
|
|
11
|
+
* returns the union of outgoing and incoming edges — the typical
|
|
12
|
+
* "Jane's family" UI shape. Use `from` / `to` for one-sided lists.
|
|
13
|
+
*/
|
|
14
|
+
listPersonRelationships(db: PostgresJsDatabase, personId: string, query?: PersonRelationshipListQuery): Omit<import("drizzle-orm/pg-core").PgSelectBase<"person_relationships", {
|
|
15
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
16
|
+
name: string;
|
|
17
|
+
tableName: "person_relationships";
|
|
18
|
+
dataType: "string";
|
|
19
|
+
columnType: "PgText";
|
|
20
|
+
data: string;
|
|
21
|
+
driverParam: string;
|
|
22
|
+
notNull: true;
|
|
23
|
+
hasDefault: true;
|
|
24
|
+
isPrimaryKey: true;
|
|
25
|
+
isAutoincrement: false;
|
|
26
|
+
hasRuntimeDefault: true;
|
|
27
|
+
enumValues: [string, ...string[]];
|
|
28
|
+
baseColumn: never;
|
|
29
|
+
identity: undefined;
|
|
30
|
+
generated: undefined;
|
|
31
|
+
}, {}, {}>;
|
|
32
|
+
fromPersonId: import("drizzle-orm/pg-core").PgColumn<{
|
|
33
|
+
name: string;
|
|
34
|
+
tableName: "person_relationships";
|
|
35
|
+
dataType: "string";
|
|
36
|
+
columnType: "PgText";
|
|
37
|
+
data: string;
|
|
38
|
+
driverParam: string;
|
|
39
|
+
notNull: true;
|
|
40
|
+
hasDefault: false;
|
|
41
|
+
isPrimaryKey: false;
|
|
42
|
+
isAutoincrement: false;
|
|
43
|
+
hasRuntimeDefault: false;
|
|
44
|
+
enumValues: [string, ...string[]];
|
|
45
|
+
baseColumn: never;
|
|
46
|
+
identity: undefined;
|
|
47
|
+
generated: undefined;
|
|
48
|
+
}, {}, {}>;
|
|
49
|
+
toPersonId: import("drizzle-orm/pg-core").PgColumn<{
|
|
50
|
+
name: string;
|
|
51
|
+
tableName: "person_relationships";
|
|
52
|
+
dataType: "string";
|
|
53
|
+
columnType: "PgText";
|
|
54
|
+
data: string;
|
|
55
|
+
driverParam: string;
|
|
56
|
+
notNull: true;
|
|
57
|
+
hasDefault: false;
|
|
58
|
+
isPrimaryKey: false;
|
|
59
|
+
isAutoincrement: false;
|
|
60
|
+
hasRuntimeDefault: false;
|
|
61
|
+
enumValues: [string, ...string[]];
|
|
62
|
+
baseColumn: never;
|
|
63
|
+
identity: undefined;
|
|
64
|
+
generated: undefined;
|
|
65
|
+
}, {}, {}>;
|
|
66
|
+
kind: import("drizzle-orm/pg-core").PgColumn<{
|
|
67
|
+
name: "kind";
|
|
68
|
+
tableName: "person_relationships";
|
|
69
|
+
dataType: "string";
|
|
70
|
+
columnType: "PgEnumColumn";
|
|
71
|
+
data: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion";
|
|
72
|
+
driverParam: string;
|
|
73
|
+
notNull: true;
|
|
74
|
+
hasDefault: false;
|
|
75
|
+
isPrimaryKey: false;
|
|
76
|
+
isAutoincrement: false;
|
|
77
|
+
hasRuntimeDefault: false;
|
|
78
|
+
enumValues: ["spouse", "partner", "parent", "child", "sibling", "guardian", "ward", "emergency_contact", "friend", "travel_companion", "other"];
|
|
79
|
+
baseColumn: never;
|
|
80
|
+
identity: undefined;
|
|
81
|
+
generated: undefined;
|
|
82
|
+
}, {}, {}>;
|
|
83
|
+
inverseKind: import("drizzle-orm/pg-core").PgColumn<{
|
|
84
|
+
name: "inverse_kind";
|
|
85
|
+
tableName: "person_relationships";
|
|
86
|
+
dataType: "string";
|
|
87
|
+
columnType: "PgEnumColumn";
|
|
88
|
+
data: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion";
|
|
89
|
+
driverParam: string;
|
|
90
|
+
notNull: false;
|
|
91
|
+
hasDefault: false;
|
|
92
|
+
isPrimaryKey: false;
|
|
93
|
+
isAutoincrement: false;
|
|
94
|
+
hasRuntimeDefault: false;
|
|
95
|
+
enumValues: ["spouse", "partner", "parent", "child", "sibling", "guardian", "ward", "emergency_contact", "friend", "travel_companion", "other"];
|
|
96
|
+
baseColumn: never;
|
|
97
|
+
identity: undefined;
|
|
98
|
+
generated: undefined;
|
|
99
|
+
}, {}, {}>;
|
|
100
|
+
startDate: import("drizzle-orm/pg-core").PgColumn<{
|
|
101
|
+
name: "start_date";
|
|
102
|
+
tableName: "person_relationships";
|
|
103
|
+
dataType: "string";
|
|
104
|
+
columnType: "PgDateString";
|
|
105
|
+
data: string;
|
|
106
|
+
driverParam: string;
|
|
107
|
+
notNull: false;
|
|
108
|
+
hasDefault: false;
|
|
109
|
+
isPrimaryKey: false;
|
|
110
|
+
isAutoincrement: false;
|
|
111
|
+
hasRuntimeDefault: false;
|
|
112
|
+
enumValues: undefined;
|
|
113
|
+
baseColumn: never;
|
|
114
|
+
identity: undefined;
|
|
115
|
+
generated: undefined;
|
|
116
|
+
}, {}, {}>;
|
|
117
|
+
endDate: import("drizzle-orm/pg-core").PgColumn<{
|
|
118
|
+
name: "end_date";
|
|
119
|
+
tableName: "person_relationships";
|
|
120
|
+
dataType: "string";
|
|
121
|
+
columnType: "PgDateString";
|
|
122
|
+
data: string;
|
|
123
|
+
driverParam: string;
|
|
124
|
+
notNull: false;
|
|
125
|
+
hasDefault: false;
|
|
126
|
+
isPrimaryKey: false;
|
|
127
|
+
isAutoincrement: false;
|
|
128
|
+
hasRuntimeDefault: false;
|
|
129
|
+
enumValues: undefined;
|
|
130
|
+
baseColumn: never;
|
|
131
|
+
identity: undefined;
|
|
132
|
+
generated: undefined;
|
|
133
|
+
}, {}, {}>;
|
|
134
|
+
isPrimary: import("drizzle-orm/pg-core").PgColumn<{
|
|
135
|
+
name: "is_primary";
|
|
136
|
+
tableName: "person_relationships";
|
|
137
|
+
dataType: "boolean";
|
|
138
|
+
columnType: "PgBoolean";
|
|
139
|
+
data: boolean;
|
|
140
|
+
driverParam: boolean;
|
|
141
|
+
notNull: true;
|
|
142
|
+
hasDefault: true;
|
|
143
|
+
isPrimaryKey: false;
|
|
144
|
+
isAutoincrement: false;
|
|
145
|
+
hasRuntimeDefault: false;
|
|
146
|
+
enumValues: undefined;
|
|
147
|
+
baseColumn: never;
|
|
148
|
+
identity: undefined;
|
|
149
|
+
generated: undefined;
|
|
150
|
+
}, {}, {}>;
|
|
151
|
+
notes: import("drizzle-orm/pg-core").PgColumn<{
|
|
152
|
+
name: "notes";
|
|
153
|
+
tableName: "person_relationships";
|
|
154
|
+
dataType: "string";
|
|
155
|
+
columnType: "PgText";
|
|
156
|
+
data: string;
|
|
157
|
+
driverParam: string;
|
|
158
|
+
notNull: false;
|
|
159
|
+
hasDefault: false;
|
|
160
|
+
isPrimaryKey: false;
|
|
161
|
+
isAutoincrement: false;
|
|
162
|
+
hasRuntimeDefault: false;
|
|
163
|
+
enumValues: [string, ...string[]];
|
|
164
|
+
baseColumn: never;
|
|
165
|
+
identity: undefined;
|
|
166
|
+
generated: undefined;
|
|
167
|
+
}, {}, {}>;
|
|
168
|
+
metadata: import("drizzle-orm/pg-core").PgColumn<{
|
|
169
|
+
name: "metadata";
|
|
170
|
+
tableName: "person_relationships";
|
|
171
|
+
dataType: "json";
|
|
172
|
+
columnType: "PgJsonb";
|
|
173
|
+
data: Record<string, unknown>;
|
|
174
|
+
driverParam: unknown;
|
|
175
|
+
notNull: false;
|
|
176
|
+
hasDefault: false;
|
|
177
|
+
isPrimaryKey: false;
|
|
178
|
+
isAutoincrement: false;
|
|
179
|
+
hasRuntimeDefault: false;
|
|
180
|
+
enumValues: undefined;
|
|
181
|
+
baseColumn: never;
|
|
182
|
+
identity: undefined;
|
|
183
|
+
generated: undefined;
|
|
184
|
+
}, {}, {
|
|
185
|
+
$type: Record<string, unknown>;
|
|
186
|
+
}>;
|
|
187
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
188
|
+
name: "created_at";
|
|
189
|
+
tableName: "person_relationships";
|
|
190
|
+
dataType: "date";
|
|
191
|
+
columnType: "PgTimestamp";
|
|
192
|
+
data: Date;
|
|
193
|
+
driverParam: string;
|
|
194
|
+
notNull: true;
|
|
195
|
+
hasDefault: true;
|
|
196
|
+
isPrimaryKey: false;
|
|
197
|
+
isAutoincrement: false;
|
|
198
|
+
hasRuntimeDefault: false;
|
|
199
|
+
enumValues: undefined;
|
|
200
|
+
baseColumn: never;
|
|
201
|
+
identity: undefined;
|
|
202
|
+
generated: undefined;
|
|
203
|
+
}, {}, {}>;
|
|
204
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
205
|
+
name: "updated_at";
|
|
206
|
+
tableName: "person_relationships";
|
|
207
|
+
dataType: "date";
|
|
208
|
+
columnType: "PgTimestamp";
|
|
209
|
+
data: Date;
|
|
210
|
+
driverParam: string;
|
|
211
|
+
notNull: true;
|
|
212
|
+
hasDefault: true;
|
|
213
|
+
isPrimaryKey: false;
|
|
214
|
+
isAutoincrement: false;
|
|
215
|
+
hasRuntimeDefault: false;
|
|
216
|
+
enumValues: undefined;
|
|
217
|
+
baseColumn: never;
|
|
218
|
+
identity: undefined;
|
|
219
|
+
generated: undefined;
|
|
220
|
+
}, {}, {}>;
|
|
221
|
+
}, "single", Record<"person_relationships", "not-null">, false, "where" | "orderBy" | "limit" | "offset", {
|
|
222
|
+
id: string;
|
|
223
|
+
fromPersonId: string;
|
|
224
|
+
toPersonId: string;
|
|
225
|
+
kind: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion";
|
|
226
|
+
inverseKind: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion" | null;
|
|
227
|
+
startDate: string | null;
|
|
228
|
+
endDate: string | null;
|
|
229
|
+
isPrimary: boolean;
|
|
230
|
+
notes: string | null;
|
|
231
|
+
metadata: Record<string, unknown> | null;
|
|
232
|
+
createdAt: Date;
|
|
233
|
+
updatedAt: Date;
|
|
234
|
+
}[], {
|
|
235
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
236
|
+
name: string;
|
|
237
|
+
tableName: "person_relationships";
|
|
238
|
+
dataType: "string";
|
|
239
|
+
columnType: "PgText";
|
|
240
|
+
data: string;
|
|
241
|
+
driverParam: string;
|
|
242
|
+
notNull: true;
|
|
243
|
+
hasDefault: true;
|
|
244
|
+
isPrimaryKey: true;
|
|
245
|
+
isAutoincrement: false;
|
|
246
|
+
hasRuntimeDefault: true;
|
|
247
|
+
enumValues: [string, ...string[]];
|
|
248
|
+
baseColumn: never;
|
|
249
|
+
identity: undefined;
|
|
250
|
+
generated: undefined;
|
|
251
|
+
}, {}, {}>;
|
|
252
|
+
fromPersonId: import("drizzle-orm/pg-core").PgColumn<{
|
|
253
|
+
name: string;
|
|
254
|
+
tableName: "person_relationships";
|
|
255
|
+
dataType: "string";
|
|
256
|
+
columnType: "PgText";
|
|
257
|
+
data: string;
|
|
258
|
+
driverParam: string;
|
|
259
|
+
notNull: true;
|
|
260
|
+
hasDefault: false;
|
|
261
|
+
isPrimaryKey: false;
|
|
262
|
+
isAutoincrement: false;
|
|
263
|
+
hasRuntimeDefault: false;
|
|
264
|
+
enumValues: [string, ...string[]];
|
|
265
|
+
baseColumn: never;
|
|
266
|
+
identity: undefined;
|
|
267
|
+
generated: undefined;
|
|
268
|
+
}, {}, {}>;
|
|
269
|
+
toPersonId: import("drizzle-orm/pg-core").PgColumn<{
|
|
270
|
+
name: string;
|
|
271
|
+
tableName: "person_relationships";
|
|
272
|
+
dataType: "string";
|
|
273
|
+
columnType: "PgText";
|
|
274
|
+
data: string;
|
|
275
|
+
driverParam: string;
|
|
276
|
+
notNull: true;
|
|
277
|
+
hasDefault: false;
|
|
278
|
+
isPrimaryKey: false;
|
|
279
|
+
isAutoincrement: false;
|
|
280
|
+
hasRuntimeDefault: false;
|
|
281
|
+
enumValues: [string, ...string[]];
|
|
282
|
+
baseColumn: never;
|
|
283
|
+
identity: undefined;
|
|
284
|
+
generated: undefined;
|
|
285
|
+
}, {}, {}>;
|
|
286
|
+
kind: import("drizzle-orm/pg-core").PgColumn<{
|
|
287
|
+
name: "kind";
|
|
288
|
+
tableName: "person_relationships";
|
|
289
|
+
dataType: "string";
|
|
290
|
+
columnType: "PgEnumColumn";
|
|
291
|
+
data: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion";
|
|
292
|
+
driverParam: string;
|
|
293
|
+
notNull: true;
|
|
294
|
+
hasDefault: false;
|
|
295
|
+
isPrimaryKey: false;
|
|
296
|
+
isAutoincrement: false;
|
|
297
|
+
hasRuntimeDefault: false;
|
|
298
|
+
enumValues: ["spouse", "partner", "parent", "child", "sibling", "guardian", "ward", "emergency_contact", "friend", "travel_companion", "other"];
|
|
299
|
+
baseColumn: never;
|
|
300
|
+
identity: undefined;
|
|
301
|
+
generated: undefined;
|
|
302
|
+
}, {}, {}>;
|
|
303
|
+
inverseKind: import("drizzle-orm/pg-core").PgColumn<{
|
|
304
|
+
name: "inverse_kind";
|
|
305
|
+
tableName: "person_relationships";
|
|
306
|
+
dataType: "string";
|
|
307
|
+
columnType: "PgEnumColumn";
|
|
308
|
+
data: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion";
|
|
309
|
+
driverParam: string;
|
|
310
|
+
notNull: false;
|
|
311
|
+
hasDefault: false;
|
|
312
|
+
isPrimaryKey: false;
|
|
313
|
+
isAutoincrement: false;
|
|
314
|
+
hasRuntimeDefault: false;
|
|
315
|
+
enumValues: ["spouse", "partner", "parent", "child", "sibling", "guardian", "ward", "emergency_contact", "friend", "travel_companion", "other"];
|
|
316
|
+
baseColumn: never;
|
|
317
|
+
identity: undefined;
|
|
318
|
+
generated: undefined;
|
|
319
|
+
}, {}, {}>;
|
|
320
|
+
startDate: import("drizzle-orm/pg-core").PgColumn<{
|
|
321
|
+
name: "start_date";
|
|
322
|
+
tableName: "person_relationships";
|
|
323
|
+
dataType: "string";
|
|
324
|
+
columnType: "PgDateString";
|
|
325
|
+
data: string;
|
|
326
|
+
driverParam: string;
|
|
327
|
+
notNull: false;
|
|
328
|
+
hasDefault: false;
|
|
329
|
+
isPrimaryKey: false;
|
|
330
|
+
isAutoincrement: false;
|
|
331
|
+
hasRuntimeDefault: false;
|
|
332
|
+
enumValues: undefined;
|
|
333
|
+
baseColumn: never;
|
|
334
|
+
identity: undefined;
|
|
335
|
+
generated: undefined;
|
|
336
|
+
}, {}, {}>;
|
|
337
|
+
endDate: import("drizzle-orm/pg-core").PgColumn<{
|
|
338
|
+
name: "end_date";
|
|
339
|
+
tableName: "person_relationships";
|
|
340
|
+
dataType: "string";
|
|
341
|
+
columnType: "PgDateString";
|
|
342
|
+
data: string;
|
|
343
|
+
driverParam: string;
|
|
344
|
+
notNull: false;
|
|
345
|
+
hasDefault: false;
|
|
346
|
+
isPrimaryKey: false;
|
|
347
|
+
isAutoincrement: false;
|
|
348
|
+
hasRuntimeDefault: false;
|
|
349
|
+
enumValues: undefined;
|
|
350
|
+
baseColumn: never;
|
|
351
|
+
identity: undefined;
|
|
352
|
+
generated: undefined;
|
|
353
|
+
}, {}, {}>;
|
|
354
|
+
isPrimary: import("drizzle-orm/pg-core").PgColumn<{
|
|
355
|
+
name: "is_primary";
|
|
356
|
+
tableName: "person_relationships";
|
|
357
|
+
dataType: "boolean";
|
|
358
|
+
columnType: "PgBoolean";
|
|
359
|
+
data: boolean;
|
|
360
|
+
driverParam: boolean;
|
|
361
|
+
notNull: true;
|
|
362
|
+
hasDefault: true;
|
|
363
|
+
isPrimaryKey: false;
|
|
364
|
+
isAutoincrement: false;
|
|
365
|
+
hasRuntimeDefault: false;
|
|
366
|
+
enumValues: undefined;
|
|
367
|
+
baseColumn: never;
|
|
368
|
+
identity: undefined;
|
|
369
|
+
generated: undefined;
|
|
370
|
+
}, {}, {}>;
|
|
371
|
+
notes: import("drizzle-orm/pg-core").PgColumn<{
|
|
372
|
+
name: "notes";
|
|
373
|
+
tableName: "person_relationships";
|
|
374
|
+
dataType: "string";
|
|
375
|
+
columnType: "PgText";
|
|
376
|
+
data: string;
|
|
377
|
+
driverParam: string;
|
|
378
|
+
notNull: false;
|
|
379
|
+
hasDefault: false;
|
|
380
|
+
isPrimaryKey: false;
|
|
381
|
+
isAutoincrement: false;
|
|
382
|
+
hasRuntimeDefault: false;
|
|
383
|
+
enumValues: [string, ...string[]];
|
|
384
|
+
baseColumn: never;
|
|
385
|
+
identity: undefined;
|
|
386
|
+
generated: undefined;
|
|
387
|
+
}, {}, {}>;
|
|
388
|
+
metadata: import("drizzle-orm/pg-core").PgColumn<{
|
|
389
|
+
name: "metadata";
|
|
390
|
+
tableName: "person_relationships";
|
|
391
|
+
dataType: "json";
|
|
392
|
+
columnType: "PgJsonb";
|
|
393
|
+
data: Record<string, unknown>;
|
|
394
|
+
driverParam: unknown;
|
|
395
|
+
notNull: false;
|
|
396
|
+
hasDefault: false;
|
|
397
|
+
isPrimaryKey: false;
|
|
398
|
+
isAutoincrement: false;
|
|
399
|
+
hasRuntimeDefault: false;
|
|
400
|
+
enumValues: undefined;
|
|
401
|
+
baseColumn: never;
|
|
402
|
+
identity: undefined;
|
|
403
|
+
generated: undefined;
|
|
404
|
+
}, {}, {
|
|
405
|
+
$type: Record<string, unknown>;
|
|
406
|
+
}>;
|
|
407
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
408
|
+
name: "created_at";
|
|
409
|
+
tableName: "person_relationships";
|
|
410
|
+
dataType: "date";
|
|
411
|
+
columnType: "PgTimestamp";
|
|
412
|
+
data: Date;
|
|
413
|
+
driverParam: string;
|
|
414
|
+
notNull: true;
|
|
415
|
+
hasDefault: true;
|
|
416
|
+
isPrimaryKey: false;
|
|
417
|
+
isAutoincrement: false;
|
|
418
|
+
hasRuntimeDefault: false;
|
|
419
|
+
enumValues: undefined;
|
|
420
|
+
baseColumn: never;
|
|
421
|
+
identity: undefined;
|
|
422
|
+
generated: undefined;
|
|
423
|
+
}, {}, {}>;
|
|
424
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
425
|
+
name: "updated_at";
|
|
426
|
+
tableName: "person_relationships";
|
|
427
|
+
dataType: "date";
|
|
428
|
+
columnType: "PgTimestamp";
|
|
429
|
+
data: Date;
|
|
430
|
+
driverParam: string;
|
|
431
|
+
notNull: true;
|
|
432
|
+
hasDefault: true;
|
|
433
|
+
isPrimaryKey: false;
|
|
434
|
+
isAutoincrement: false;
|
|
435
|
+
hasRuntimeDefault: false;
|
|
436
|
+
enumValues: undefined;
|
|
437
|
+
baseColumn: never;
|
|
438
|
+
identity: undefined;
|
|
439
|
+
generated: undefined;
|
|
440
|
+
}, {}, {}>;
|
|
441
|
+
}>, "where" | "orderBy" | "limit" | "offset">;
|
|
442
|
+
getPersonRelationship(db: PostgresJsDatabase, id: string): Promise<{
|
|
443
|
+
id: string;
|
|
444
|
+
fromPersonId: string;
|
|
445
|
+
toPersonId: string;
|
|
446
|
+
kind: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion";
|
|
447
|
+
inverseKind: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion" | null;
|
|
448
|
+
startDate: string | null;
|
|
449
|
+
endDate: string | null;
|
|
450
|
+
isPrimary: boolean;
|
|
451
|
+
notes: string | null;
|
|
452
|
+
metadata: Record<string, unknown> | null;
|
|
453
|
+
createdAt: Date;
|
|
454
|
+
updatedAt: Date;
|
|
455
|
+
} | null>;
|
|
456
|
+
/**
|
|
457
|
+
* Inserts a directed edge `fromPerson → toPerson` of `data.kind`.
|
|
458
|
+
* When `data.inverseKind` is provided AND `data.autoInverse` is
|
|
459
|
+
* not explicitly false, also inserts the symmetric
|
|
460
|
+
* `toPerson → fromPerson` edge with `kind = inverseKind` (and
|
|
461
|
+
* `inverseKind` swapped back). The pair is written in a single
|
|
462
|
+
* transaction so a failed inverse rolls the primary back.
|
|
463
|
+
*
|
|
464
|
+
* The inverse insert is idempotent — if the symmetric edge
|
|
465
|
+
* already exists, the `(from, to, kind)` unique index would
|
|
466
|
+
* normally throw; we suppress that case so retrying a partially
|
|
467
|
+
* applied operation doesn't fail. Any other DB error still
|
|
468
|
+
* propagates.
|
|
469
|
+
*/
|
|
470
|
+
createPersonRelationship(db: PostgresJsDatabase, fromPersonId: string, data: CreatePersonRelationshipInput): Promise<{
|
|
471
|
+
metadata: Record<string, unknown> | null;
|
|
472
|
+
id: string;
|
|
473
|
+
createdAt: Date;
|
|
474
|
+
updatedAt: Date;
|
|
475
|
+
startDate: string | null;
|
|
476
|
+
endDate: string | null;
|
|
477
|
+
notes: string | null;
|
|
478
|
+
kind: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion";
|
|
479
|
+
isPrimary: boolean;
|
|
480
|
+
fromPersonId: string;
|
|
481
|
+
toPersonId: string;
|
|
482
|
+
inverseKind: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion" | null;
|
|
483
|
+
} | null>;
|
|
484
|
+
updatePersonRelationship(db: PostgresJsDatabase, id: string, data: UpdatePersonRelationshipInput): Promise<{
|
|
485
|
+
id: string;
|
|
486
|
+
fromPersonId: string;
|
|
487
|
+
toPersonId: string;
|
|
488
|
+
kind: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion";
|
|
489
|
+
inverseKind: "partner" | "other" | "spouse" | "parent" | "child" | "sibling" | "guardian" | "ward" | "emergency_contact" | "friend" | "travel_companion" | null;
|
|
490
|
+
startDate: string | null;
|
|
491
|
+
endDate: string | null;
|
|
492
|
+
isPrimary: boolean;
|
|
493
|
+
notes: string | null;
|
|
494
|
+
metadata: Record<string, unknown> | null;
|
|
495
|
+
createdAt: Date;
|
|
496
|
+
updatedAt: Date;
|
|
497
|
+
} | null>;
|
|
498
|
+
deletePersonRelationship(db: PostgresJsDatabase, id: string): Promise<{
|
|
499
|
+
id: string;
|
|
500
|
+
} | null>;
|
|
501
|
+
};
|
|
502
|
+
//# sourceMappingURL=person-relationships.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"person-relationships.d.ts","sourceRoot":"","sources":["../../src/service/person-relationships.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAG5B,OAAO,KAAK,EACV,8BAA8B,EAC9B,iCAAiC,EACjC,8BAA8B,EAC/B,MAAM,kBAAkB,CAAA;AAEzB,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;AAC1F,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;AAC1F,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iCAAiC,CAAC,CAAA;AAC3F,MAAM,MAAM,sBAAsB,GAAG,6BAA6B,CAAC,MAAM,CAAC,CAAA;AAW1E,eAAO,MAAM,0BAA0B;IACrC;;;;OAIG;gCAEG,kBAAkB,YACZ,MAAM,UACR,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BA8BL,kBAAkB,MAAM,MAAM;;;;;;;;;;;;;;IAS9D;;;;;;;;;;;;;OAaG;iCAEG,kBAAkB,gBACR,MAAM,QACd,6BAA6B;;;;;;;;;;;;;;iCAiD/B,kBAAkB,MAClB,MAAM,QACJ,6BAA6B;;;;;;;;;;;;;;iCAUF,kBAAkB,MAAM,MAAM;;;CAOlE,CAAA"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { and, asc, eq, or } from "drizzle-orm";
|
|
2
|
+
import { people, personRelationships } from "../schema.js";
|
|
3
|
+
async function personExists(db, personId) {
|
|
4
|
+
const [row] = await db
|
|
5
|
+
.select({ id: people.id })
|
|
6
|
+
.from(people)
|
|
7
|
+
.where(eq(people.id, personId))
|
|
8
|
+
.limit(1);
|
|
9
|
+
return Boolean(row);
|
|
10
|
+
}
|
|
11
|
+
export const personRelationshipsService = {
|
|
12
|
+
/**
|
|
13
|
+
* Lists relationships for a person. Default `direction: "both"`
|
|
14
|
+
* returns the union of outgoing and incoming edges — the typical
|
|
15
|
+
* "Jane's family" UI shape. Use `from` / `to` for one-sided lists.
|
|
16
|
+
*/
|
|
17
|
+
listPersonRelationships(db, personId, query) {
|
|
18
|
+
const direction = query?.direction ?? "both";
|
|
19
|
+
const directionFilter = direction === "from"
|
|
20
|
+
? eq(personRelationships.fromPersonId, personId)
|
|
21
|
+
: direction === "to"
|
|
22
|
+
? eq(personRelationships.toPersonId, personId)
|
|
23
|
+
: or(eq(personRelationships.fromPersonId, personId), eq(personRelationships.toPersonId, personId));
|
|
24
|
+
const conditions = [directionFilter];
|
|
25
|
+
if (query?.kind) {
|
|
26
|
+
conditions.push(eq(personRelationships.kind, query.kind));
|
|
27
|
+
}
|
|
28
|
+
const limit = query?.limit ?? 50;
|
|
29
|
+
const offset = query?.offset ?? 0;
|
|
30
|
+
return db
|
|
31
|
+
.select()
|
|
32
|
+
.from(personRelationships)
|
|
33
|
+
.where(and(...conditions))
|
|
34
|
+
.orderBy(asc(personRelationships.createdAt))
|
|
35
|
+
.limit(limit)
|
|
36
|
+
.offset(offset);
|
|
37
|
+
},
|
|
38
|
+
async getPersonRelationship(db, id) {
|
|
39
|
+
const [row] = await db
|
|
40
|
+
.select()
|
|
41
|
+
.from(personRelationships)
|
|
42
|
+
.where(eq(personRelationships.id, id))
|
|
43
|
+
.limit(1);
|
|
44
|
+
return row ?? null;
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* Inserts a directed edge `fromPerson → toPerson` of `data.kind`.
|
|
48
|
+
* When `data.inverseKind` is provided AND `data.autoInverse` is
|
|
49
|
+
* not explicitly false, also inserts the symmetric
|
|
50
|
+
* `toPerson → fromPerson` edge with `kind = inverseKind` (and
|
|
51
|
+
* `inverseKind` swapped back). The pair is written in a single
|
|
52
|
+
* transaction so a failed inverse rolls the primary back.
|
|
53
|
+
*
|
|
54
|
+
* The inverse insert is idempotent — if the symmetric edge
|
|
55
|
+
* already exists, the `(from, to, kind)` unique index would
|
|
56
|
+
* normally throw; we suppress that case so retrying a partially
|
|
57
|
+
* applied operation doesn't fail. Any other DB error still
|
|
58
|
+
* propagates.
|
|
59
|
+
*/
|
|
60
|
+
async createPersonRelationship(db, fromPersonId, data) {
|
|
61
|
+
if (fromPersonId === data.toPersonId)
|
|
62
|
+
return null;
|
|
63
|
+
if (!(await personExists(db, fromPersonId)))
|
|
64
|
+
return null;
|
|
65
|
+
if (!(await personExists(db, data.toPersonId)))
|
|
66
|
+
return null;
|
|
67
|
+
const { toPersonId, autoInverse: autoInverseInput, inverseKind, ...rest } = data;
|
|
68
|
+
const autoInverse = autoInverseInput !== false;
|
|
69
|
+
return db.transaction(async (tx) => {
|
|
70
|
+
const [primary] = await tx
|
|
71
|
+
.insert(personRelationships)
|
|
72
|
+
.values({
|
|
73
|
+
...rest,
|
|
74
|
+
inverseKind: inverseKind ?? null,
|
|
75
|
+
fromPersonId,
|
|
76
|
+
toPersonId,
|
|
77
|
+
})
|
|
78
|
+
.returning();
|
|
79
|
+
if (!primary)
|
|
80
|
+
return null;
|
|
81
|
+
if (autoInverse && inverseKind) {
|
|
82
|
+
await tx
|
|
83
|
+
.insert(personRelationships)
|
|
84
|
+
.values({
|
|
85
|
+
fromPersonId: toPersonId,
|
|
86
|
+
toPersonId: fromPersonId,
|
|
87
|
+
kind: inverseKind,
|
|
88
|
+
inverseKind: rest.kind,
|
|
89
|
+
startDate: rest.startDate ?? null,
|
|
90
|
+
endDate: rest.endDate ?? null,
|
|
91
|
+
isPrimary: rest.isPrimary,
|
|
92
|
+
notes: rest.notes ?? null,
|
|
93
|
+
metadata: rest.metadata ?? null,
|
|
94
|
+
})
|
|
95
|
+
.onConflictDoNothing({
|
|
96
|
+
target: [
|
|
97
|
+
personRelationships.fromPersonId,
|
|
98
|
+
personRelationships.toPersonId,
|
|
99
|
+
personRelationships.kind,
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return primary;
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
async updatePersonRelationship(db, id, data) {
|
|
107
|
+
const [row] = await db
|
|
108
|
+
.update(personRelationships)
|
|
109
|
+
.set({ ...data, updatedAt: new Date() })
|
|
110
|
+
.where(eq(personRelationships.id, id))
|
|
111
|
+
.returning();
|
|
112
|
+
return row ?? null;
|
|
113
|
+
},
|
|
114
|
+
async deletePersonRelationship(db, id) {
|
|
115
|
+
const [row] = await db
|
|
116
|
+
.delete(personRelationships)
|
|
117
|
+
.where(eq(personRelationships.id, id))
|
|
118
|
+
.returning({ id: personRelationships.id });
|
|
119
|
+
return row ?? null;
|
|
120
|
+
},
|
|
121
|
+
};
|