aifastdb 0.2.1

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 (53) hide show
  1. package/aidb.win32-x64-msvc.node +0 -0
  2. package/aifastdb.win32-x64-msvc.node +0 -0
  3. package/dist/client.d.ts +140 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +270 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/connectme-adapter.d.ts +76 -0
  8. package/dist/connectme-adapter.d.ts.map +1 -0
  9. package/dist/connectme-adapter.js +456 -0
  10. package/dist/connectme-adapter.js.map +1 -0
  11. package/dist/family-tree.d.ts +482 -0
  12. package/dist/family-tree.d.ts.map +1 -0
  13. package/dist/family-tree.js +676 -0
  14. package/dist/family-tree.js.map +1 -0
  15. package/dist/family-types.d.ts +228 -0
  16. package/dist/family-types.d.ts.map +1 -0
  17. package/dist/family-types.js +108 -0
  18. package/dist/family-types.js.map +1 -0
  19. package/dist/index.d.ts +25 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +70 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/memory-manager.d.ts +82 -0
  24. package/dist/memory-manager.d.ts.map +1 -0
  25. package/dist/memory-manager.js +273 -0
  26. package/dist/memory-manager.js.map +1 -0
  27. package/dist/native.d.ts +352 -0
  28. package/dist/native.d.ts.map +1 -0
  29. package/dist/native.js +35 -0
  30. package/dist/native.js.map +1 -0
  31. package/dist/query-builder.d.ts +143 -0
  32. package/dist/query-builder.d.ts.map +1 -0
  33. package/dist/query-builder.js +240 -0
  34. package/dist/query-builder.js.map +1 -0
  35. package/dist/social-graph.d.ts +392 -0
  36. package/dist/social-graph.d.ts.map +1 -0
  37. package/dist/social-graph.js +545 -0
  38. package/dist/social-graph.js.map +1 -0
  39. package/dist/social-types.d.ts +379 -0
  40. package/dist/social-types.d.ts.map +1 -0
  41. package/dist/social-types.js +34 -0
  42. package/dist/social-types.js.map +1 -0
  43. package/dist/types.d.ts +475 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +161 -0
  46. package/dist/types.js.map +1 -0
  47. package/dist/vibe-synapse.d.ts +174 -0
  48. package/dist/vibe-synapse.d.ts.map +1 -0
  49. package/dist/vibe-synapse.js +509 -0
  50. package/dist/vibe-synapse.js.map +1 -0
  51. package/package.json +61 -0
  52. package/vibebase.node +0 -0
  53. package/vibebase.win32-x64-msvc.node +0 -0
@@ -0,0 +1,676 @@
1
+ "use strict";
2
+ /**
3
+ * FamilyTree - High-level TypeScript API for family tree (genealogy) operations
4
+ *
5
+ * Provides a friendly API wrapper around the native Rust family tree implementation.
6
+ * Supports family relationship management, ancestor/descendant traversal,
7
+ * relationship calculation, and Chinese kinship title derivation.
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.FamilyTreeManager = void 0;
25
+ /**
26
+ * FamilyTreeManager provides high-level APIs for family tree operations.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const db = new AiFastDb({ path: './data', dimension: 768 });
31
+ * const social = db.socialGraph();
32
+ * const family = new FamilyTreeManager(social);
33
+ *
34
+ * // Add family members with gender
35
+ * const father = social.addPerson({ name: '张明', properties: { gender: 'male' } });
36
+ * const mother = social.addPerson({ name: '李芳', properties: { gender: 'female' } });
37
+ * const child = social.addPerson({ name: '张小明', properties: { gender: 'male' } });
38
+ *
39
+ * // Create family relationships
40
+ * family.addParentChild(father.id, child.id);
41
+ * family.addParentChild(mother.id, child.id);
42
+ * family.addSpouse(father.id, mother.id);
43
+ *
44
+ * // Query relationships
45
+ * const parents = family.getParents(child.id);
46
+ * const title = family.getRelationshipTitle(child.id, father.id); // "父亲"
47
+ * ```
48
+ */
49
+ class FamilyTreeManager {
50
+ /**
51
+ * Create a new FamilyTreeManager
52
+ * @param socialGraph - The SocialGraph instance (from db.socialGraph())
53
+ */
54
+ constructor(socialGraph) {
55
+ this.native = socialGraph;
56
+ }
57
+ // ========================================================================
58
+ // Core Relationship Management
59
+ // ========================================================================
60
+ /**
61
+ * Add parent-child relationship
62
+ *
63
+ * Creates a directed relationship from parent to child.
64
+ * Automatically determines father/mother based on parent's gender property.
65
+ *
66
+ * @param parentId - The parent's ID
67
+ * @param childId - The child's ID
68
+ * @returns The created relation, or null if failed
69
+ */
70
+ addParentChild(parentId, childId) {
71
+ return this.native.addParentChild(parentId, childId) ?? null;
72
+ }
73
+ /**
74
+ * Add spouse relationship (bidirectional)
75
+ *
76
+ * @param personA - First person's ID
77
+ * @param personB - Second person's ID
78
+ * @returns The created relation, or null if failed
79
+ */
80
+ addSpouse(personA, personB) {
81
+ return this.native.addSpouse(personA, personB) ?? null;
82
+ }
83
+ /**
84
+ * Add sibling relationship (bidirectional)
85
+ *
86
+ * @param personA - First person's ID
87
+ * @param personB - Second person's ID
88
+ * @param halfSibling - Whether this is a half-sibling relationship (default: false)
89
+ * @returns The created relation, or null if failed
90
+ */
91
+ addSibling(personA, personB, halfSibling = false) {
92
+ return this.native.addSibling(personA, personB, halfSibling) ?? null;
93
+ }
94
+ /**
95
+ * Remove family relationship between two people
96
+ *
97
+ * @param personA - First person's ID
98
+ * @param personB - Second person's ID
99
+ * @returns True if any relationship was removed
100
+ */
101
+ removeFamilyRelation(personA, personB) {
102
+ return this.native.removeFamilyRelation(personA, personB);
103
+ }
104
+ /**
105
+ * Add step-parent to step-child relationship (继父母-继子女)
106
+ *
107
+ * Used for remarriage families where one spouse brings children from previous marriage.
108
+ */
109
+ addStepParentChild(stepParentId, stepChildId) {
110
+ return this.native.addStepParentChild(stepParentId, stepChildId) ?? null;
111
+ }
112
+ /**
113
+ * Add adoptive parent to adopted child relationship (养父母-养子女)
114
+ */
115
+ addAdoptiveParentChild(adoptiveParentId, adoptedChildId) {
116
+ return this.native.addAdoptiveParentChild(adoptiveParentId, adoptedChildId) ?? null;
117
+ }
118
+ /**
119
+ * Add ex-spouse relationship (前配偶/前夫/前妻)
120
+ */
121
+ addExSpouse(personA, personB) {
122
+ return this.native.addExSpouse(personA, personB) ?? null;
123
+ }
124
+ // ========================================================================
125
+ // Direct Family Queries
126
+ // ========================================================================
127
+ /**
128
+ * Get parents of a person
129
+ */
130
+ getParents(personId) {
131
+ return this.native.getParents(personId);
132
+ }
133
+ /**
134
+ * Get father of a person
135
+ */
136
+ getFather(personId) {
137
+ return this.native.getFather(personId) ?? null;
138
+ }
139
+ /**
140
+ * Get mother of a person
141
+ */
142
+ getMother(personId) {
143
+ return this.native.getMother(personId) ?? null;
144
+ }
145
+ /**
146
+ * Get children of a person
147
+ */
148
+ getChildren(personId) {
149
+ return this.native.getChildren(personId);
150
+ }
151
+ /**
152
+ * Get sons of a person
153
+ */
154
+ getSons(personId) {
155
+ return this.native.getSons(personId);
156
+ }
157
+ /**
158
+ * Get daughters of a person
159
+ */
160
+ getDaughters(personId) {
161
+ return this.native.getDaughters(personId);
162
+ }
163
+ /**
164
+ * Get spouse of a person (current, not ex)
165
+ */
166
+ getSpouse(personId) {
167
+ return this.native.getSpouse(personId) ?? null;
168
+ }
169
+ /**
170
+ * Get all spouses including ex-spouses
171
+ *
172
+ * @returns Array of spouse info with isEx flag
173
+ */
174
+ getAllSpouses(personId) {
175
+ return this.native.getAllSpouses(personId);
176
+ }
177
+ // ========================================================================
178
+ // Step/Adoptive Family Queries (继/养家庭查询)
179
+ // ========================================================================
180
+ /**
181
+ * Get step-parents (继父母)
182
+ */
183
+ getStepParents(personId) {
184
+ return this.native.getStepParents(personId);
185
+ }
186
+ /**
187
+ * Get step-father (继父)
188
+ */
189
+ getStepFather(personId) {
190
+ return this.native.getStepFather(personId) ?? null;
191
+ }
192
+ /**
193
+ * Get step-mother (继母)
194
+ */
195
+ getStepMother(personId) {
196
+ return this.native.getStepMother(personId) ?? null;
197
+ }
198
+ /**
199
+ * Get step-children (继子女)
200
+ */
201
+ getStepChildren(personId) {
202
+ return this.native.getStepChildren(personId);
203
+ }
204
+ /**
205
+ * Get adoptive parents (养父母)
206
+ */
207
+ getAdoptiveParents(personId) {
208
+ return this.native.getAdoptiveParents(personId);
209
+ }
210
+ /**
211
+ * Get adoptive father (养父)
212
+ */
213
+ getAdoptiveFather(personId) {
214
+ return this.native.getAdoptiveFather(personId) ?? null;
215
+ }
216
+ /**
217
+ * Get adoptive mother (养母)
218
+ */
219
+ getAdoptiveMother(personId) {
220
+ return this.native.getAdoptiveMother(personId) ?? null;
221
+ }
222
+ /**
223
+ * Get adopted children (养子女)
224
+ */
225
+ getAdoptedChildren(personId) {
226
+ return this.native.getAdoptedChildren(personId);
227
+ }
228
+ /**
229
+ * Get all parents with type (biological/step/adoptive)
230
+ *
231
+ * Returns all parents including biological, step, and adoptive parents
232
+ * with their relationship type.
233
+ */
234
+ getAllParentsWithType(personId) {
235
+ return this.native.getAllParentsWithType(personId);
236
+ }
237
+ /**
238
+ * Get all children with type (biological/step/adopted)
239
+ *
240
+ * Returns all children including biological, step, and adopted children
241
+ * with their relationship type.
242
+ */
243
+ getAllChildrenWithType(personId) {
244
+ return this.native.getAllChildrenWithType(personId);
245
+ }
246
+ /**
247
+ * Get siblings of a person
248
+ */
249
+ getSiblings(personId) {
250
+ return this.native.getSiblings(personId);
251
+ }
252
+ /**
253
+ * Get brothers of a person
254
+ */
255
+ getBrothers(personId) {
256
+ return this.native.getBrothers(personId);
257
+ }
258
+ /**
259
+ * Get sisters of a person
260
+ */
261
+ getSisters(personId) {
262
+ return this.native.getSisters(personId);
263
+ }
264
+ // ========================================================================
265
+ // Extended Family Queries
266
+ // ========================================================================
267
+ /**
268
+ * Get all ancestors (traversing upward)
269
+ *
270
+ * @param personId - The person's ID
271
+ * @param options - Traversal options
272
+ */
273
+ getAncestors(personId, options) {
274
+ return this.native.getAncestors(personId, options?.maxGenerations);
275
+ }
276
+ /**
277
+ * Get all descendants (traversing downward)
278
+ *
279
+ * @param personId - The person's ID
280
+ * @param options - Traversal options
281
+ */
282
+ getDescendants(personId, options) {
283
+ return this.native.getDescendants(personId, options?.maxGenerations);
284
+ }
285
+ /**
286
+ * Get grandparents of a person
287
+ */
288
+ getGrandparents(personId) {
289
+ return this.native.getGrandparents(personId);
290
+ }
291
+ /**
292
+ * Get paternal grandfather (爷爷)
293
+ */
294
+ getPaternalGrandfather(personId) {
295
+ return this.native.getPaternalGrandfather(personId) ?? null;
296
+ }
297
+ /**
298
+ * Get paternal grandmother (奶奶)
299
+ */
300
+ getPaternalGrandmother(personId) {
301
+ return this.native.getPaternalGrandmother(personId) ?? null;
302
+ }
303
+ /**
304
+ * Get maternal grandfather (外公/姥爷)
305
+ */
306
+ getMaternalGrandfather(personId) {
307
+ return this.native.getMaternalGrandfather(personId) ?? null;
308
+ }
309
+ /**
310
+ * Get maternal grandmother (外婆/姥姥)
311
+ */
312
+ getMaternalGrandmother(personId) {
313
+ return this.native.getMaternalGrandmother(personId) ?? null;
314
+ }
315
+ /**
316
+ * Get grandchildren of a person
317
+ */
318
+ getGrandchildren(personId) {
319
+ return this.native.getGrandchildren(personId);
320
+ }
321
+ /**
322
+ * Get uncles and aunts (叔伯姑姨舅)
323
+ */
324
+ getUnclesAunts(personId) {
325
+ return this.native.getUnclesAunts(personId);
326
+ }
327
+ /**
328
+ * Get paternal uncles (叔叔/伯伯)
329
+ */
330
+ getPaternalUncles(personId) {
331
+ return this.native.getPaternalUncles(personId);
332
+ }
333
+ /**
334
+ * Get paternal aunts (姑姑)
335
+ */
336
+ getPaternalAunts(personId) {
337
+ return this.native.getPaternalAunts(personId);
338
+ }
339
+ /**
340
+ * Get maternal uncles (舅舅)
341
+ */
342
+ getMaternalUncles(personId) {
343
+ return this.native.getMaternalUncles(personId);
344
+ }
345
+ /**
346
+ * Get maternal aunts (姨妈)
347
+ */
348
+ getMaternalAunts(personId) {
349
+ return this.native.getMaternalAunts(personId);
350
+ }
351
+ /**
352
+ * Get nephews and nieces (侄子/侄女/外甥/外甥女)
353
+ */
354
+ getNephewsNieces(personId) {
355
+ return this.native.getNephewsNieces(personId);
356
+ }
357
+ /**
358
+ * Get cousins (堂/表兄弟姐妹)
359
+ */
360
+ getCousins(personId) {
361
+ return this.native.getCousins(personId);
362
+ }
363
+ /**
364
+ * Get paternal cousins (堂兄弟姐妹)
365
+ */
366
+ getPaternalCousins(personId) {
367
+ return this.native.getPaternalCousins(personId);
368
+ }
369
+ /**
370
+ * Get maternal cousins (表兄弟姐妹)
371
+ */
372
+ getMaternalCousins(personId) {
373
+ return this.native.getMaternalCousins(personId);
374
+ }
375
+ // ========================================================================
376
+ // In-law Queries
377
+ // ========================================================================
378
+ /**
379
+ * Get father-in-law (公公/岳父)
380
+ */
381
+ getFatherInLaw(personId) {
382
+ return this.native.getFatherInLaw(personId) ?? null;
383
+ }
384
+ /**
385
+ * Get mother-in-law (婆婆/岳母)
386
+ */
387
+ getMotherInLaw(personId) {
388
+ return this.native.getMotherInLaw(personId) ?? null;
389
+ }
390
+ /**
391
+ * Get siblings-in-law
392
+ */
393
+ getSiblingsInLaw(personId) {
394
+ return this.native.getSiblingsInLaw(personId);
395
+ }
396
+ /**
397
+ * Get children-in-law (儿媳/女婿)
398
+ */
399
+ getChildrenInLaw(personId) {
400
+ return this.native.getChildrenInLaw(personId);
401
+ }
402
+ // ========================================================================
403
+ // Relationship Calculation
404
+ // ========================================================================
405
+ /**
406
+ * Calculate the family relationship between two people
407
+ *
408
+ * Returns the full path including Chinese relationship title,
409
+ * generation difference, and blood distance.
410
+ *
411
+ * @param fromId - Starting person's ID
412
+ * @param toId - Ending person's ID
413
+ * @returns The family path, or null if no relationship found
414
+ */
415
+ calculateRelationship(fromId, toId) {
416
+ return this.native.calculateFamilyRelationship(fromId, toId) ?? null;
417
+ }
418
+ /**
419
+ * Get the Chinese relationship title between two people
420
+ *
421
+ * @example
422
+ * ```typescript
423
+ * const title = family.getRelationshipTitle(child.id, father.id);
424
+ * // Returns: "父亲"
425
+ * ```
426
+ *
427
+ * @param fromId - The person asking about the relationship
428
+ * @param toId - The person being referred to
429
+ * @returns The relationship title in Chinese, or null if not related
430
+ */
431
+ getRelationshipTitle(fromId, toId) {
432
+ return this.native.getRelationshipTitle(fromId, toId) ?? null;
433
+ }
434
+ /**
435
+ * Find the common ancestor of two people
436
+ *
437
+ * @returns The closest common ancestor, or null if none found
438
+ */
439
+ findCommonAncestor(personA, personB) {
440
+ return this.native.findCommonAncestor(personA, personB) ?? null;
441
+ }
442
+ /**
443
+ * Calculate the blood distance between two people
444
+ *
445
+ * Blood distance is the number of parent-child links needed
446
+ * to connect two people through their common ancestor.
447
+ *
448
+ * @returns The blood distance, or null if not blood-related
449
+ */
450
+ calculateBloodDistance(personA, personB) {
451
+ return this.native.calculateBloodDistance(personA, personB) ?? null;
452
+ }
453
+ /**
454
+ * Check if two people are direct blood relatives
455
+ *
456
+ * Returns true if one is an ancestor or descendant of the other.
457
+ */
458
+ isDirectBloodRelative(personA, personB) {
459
+ return this.native.isDirectBloodRelative(personA, personB);
460
+ }
461
+ // ========================================================================
462
+ // Family Tree Construction
463
+ // ========================================================================
464
+ /**
465
+ * Build a family tree centered on a person
466
+ *
467
+ * @param personId - The center person's ID
468
+ * @param options - Build options (generationsUp, generationsDown)
469
+ * @returns The family tree structure, or null if person not found
470
+ */
471
+ buildFamilyTree(personId, options) {
472
+ return this.native.buildFamilyTree(personId, options?.generationsUp, options?.generationsDown) ?? null;
473
+ }
474
+ /**
475
+ * Get the generation number of a person relative to a root
476
+ *
477
+ * @param personId - The person's ID
478
+ * @param rootId - The root person's ID (reference point)
479
+ * @returns The generation number (0 = same as root, positive = younger, negative = older)
480
+ */
481
+ getGeneration(personId, rootId) {
482
+ return this.native.getGeneration(personId, rootId) ?? null;
483
+ }
484
+ /**
485
+ * Get all people in the same generation as a person
486
+ *
487
+ * Includes siblings, cousins, and spouse.
488
+ */
489
+ getSameGeneration(personId) {
490
+ return this.native.getSameGeneration(personId);
491
+ }
492
+ // ========================================================================
493
+ // Lineage Queries (血统查询)
494
+ // ========================================================================
495
+ /**
496
+ * Get paternal lineage (父系血统)
497
+ *
498
+ * Traces the paternal line: father -> grandfather -> great-grandfather -> ...
499
+ * Returns ancestors in order from closest (father) to farthest.
500
+ *
501
+ * @param personId - The person's ID
502
+ * @param maxGenerations - Maximum generations to trace (default: 10)
503
+ * @returns Array of paternal ancestors in order
504
+ *
505
+ * @example
506
+ * ```typescript
507
+ * const lineage = family.getPaternalLineage(me.id);
508
+ * // Returns: [父亲, 爷爷, 曾祖父, ...]
509
+ * ```
510
+ */
511
+ getPaternalLineage(personId, maxGenerations) {
512
+ return this.native.getPaternalLineage(personId, maxGenerations);
513
+ }
514
+ /**
515
+ * Get maternal lineage (母系血统)
516
+ *
517
+ * Traces the maternal line: mother -> grandmother -> great-grandmother -> ...
518
+ * Returns ancestors in order from closest (mother) to farthest.
519
+ *
520
+ * @param personId - The person's ID
521
+ * @param maxGenerations - Maximum generations to trace (default: 10)
522
+ * @returns Array of maternal ancestors in order
523
+ *
524
+ * @example
525
+ * ```typescript
526
+ * const lineage = family.getMaternalLineage(me.id);
527
+ * // Returns: [母亲, 外婆, 外曾祖母, ...]
528
+ * ```
529
+ */
530
+ getMaternalLineage(personId, maxGenerations) {
531
+ return this.native.getMaternalLineage(personId, maxGenerations);
532
+ }
533
+ /**
534
+ * Get same surname relatives (同姓族人)
535
+ *
536
+ * Finds all relatives who share the same family_name property.
537
+ * Requires the person to have a `family_name` property set.
538
+ *
539
+ * @param personId - The person's ID
540
+ * @returns Array of relatives with the same surname
541
+ *
542
+ * @example
543
+ * ```typescript
544
+ * // Person needs family_name property
545
+ * const person = social.addPerson({
546
+ * name: '张小明',
547
+ * properties: { gender: 'male', family_name: '张' }
548
+ * });
549
+ *
550
+ * const zhangFamily = family.getSameSurnameRelatives(person.id);
551
+ * ```
552
+ */
553
+ getSameSurnameRelatives(personId) {
554
+ return this.native.getSameSurnameRelatives(personId);
555
+ }
556
+ /**
557
+ * Get paternal clan members (父系宗族成员)
558
+ *
559
+ * Gets all members connected through paternal lineage:
560
+ * - Paternal ancestors (father, grandfather, etc.)
561
+ * - Paternal uncles/aunts and their descendants
562
+ * - Siblings and their descendants (through father)
563
+ *
564
+ * This represents the traditional Chinese concept of "宗族" (patrilineal clan).
565
+ *
566
+ * @param personId - The person's ID
567
+ * @param maxGenerations - Maximum generations to include (default: 5)
568
+ * @returns Array of all paternal clan members
569
+ *
570
+ * @example
571
+ * ```typescript
572
+ * const clan = family.getPaternalClan(me.id);
573
+ * // Returns all members of the patrilineal clan
574
+ * ```
575
+ */
576
+ getPaternalClan(personId, maxGenerations) {
577
+ return this.native.getPaternalClan(personId, maxGenerations);
578
+ }
579
+ // ========================================================================
580
+ // Statistics
581
+ // ========================================================================
582
+ /**
583
+ * Get family statistics
584
+ *
585
+ * @param rootId - The root person's ID for the family tree
586
+ * @returns Family statistics, or null if root not found
587
+ */
588
+ getFamilyStats(rootId) {
589
+ return this.native.getFamilyStats(rootId) ?? null;
590
+ }
591
+ // ========================================================================
592
+ // Gender Management
593
+ // ========================================================================
594
+ /**
595
+ * Set the gender of a person
596
+ *
597
+ * @param personId - The person's ID
598
+ * @param gender - The gender ('male', 'female', or 'unknown')
599
+ * @returns True if successful
600
+ */
601
+ setPersonGender(personId, gender) {
602
+ return this.native.setPersonGender(personId, gender);
603
+ }
604
+ // ========================================================================
605
+ // Convenience Methods
606
+ // ========================================================================
607
+ /**
608
+ * Add a family member with gender
609
+ *
610
+ * Convenience method that creates a person with gender set in properties.
611
+ *
612
+ * @param social - The SocialGraph instance to use for creating the person
613
+ * @param name - The person's name
614
+ * @param gender - The person's gender
615
+ * @param properties - Additional properties
616
+ * @returns The created entity
617
+ */
618
+ static addFamilyMember(social, name, gender, properties) {
619
+ return social.addPerson({
620
+ name,
621
+ properties: {
622
+ gender,
623
+ ...properties,
624
+ },
625
+ });
626
+ }
627
+ /**
628
+ * Create a nuclear family (parents + children)
629
+ *
630
+ * Convenience method to create a basic family structure.
631
+ *
632
+ * @param father - Father entity
633
+ * @param mother - Mother entity
634
+ * @param children - Array of child entities
635
+ */
636
+ createNuclearFamily(father, mother, children) {
637
+ // Add spouse relationship
638
+ this.addSpouse(father.id, mother.id);
639
+ // Add parent-child relationships
640
+ for (const child of children) {
641
+ this.addParentChild(father.id, child.id);
642
+ this.addParentChild(mother.id, child.id);
643
+ }
644
+ }
645
+ /**
646
+ * Get immediate family of a person
647
+ *
648
+ * Returns parents, spouse, siblings, and children.
649
+ */
650
+ getImmediateFamily(personId) {
651
+ return {
652
+ parents: this.getParents(personId),
653
+ spouse: this.getSpouse(personId),
654
+ siblings: this.getSiblings(personId),
655
+ children: this.getChildren(personId),
656
+ };
657
+ }
658
+ /**
659
+ * Check if two people are family members (related by blood or marriage)
660
+ *
661
+ * @param personA - First person's ID
662
+ * @param personB - Second person's ID
663
+ * @param maxDistance - Maximum relationship distance to check (default: 6)
664
+ * @returns True if related within the specified distance
665
+ */
666
+ areRelated(personA, personB, maxDistance = 6) {
667
+ const path = this.calculateRelationship(personA, personB);
668
+ if (!path)
669
+ return false;
670
+ return path.path.length <= maxDistance;
671
+ }
672
+ }
673
+ exports.FamilyTreeManager = FamilyTreeManager;
674
+ // Re-export types
675
+ __exportStar(require("./family-types"), exports);
676
+ //# sourceMappingURL=family-tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"family-tree.js","sourceRoot":"","sources":["../ts/family-tree.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;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