@synap-core/sdk 0.1.0 → 1.0.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.
@@ -1,126 +0,0 @@
1
- /**
2
- * Entities API - Generic Entity Operations
3
- *
4
- * ALL MUTATIONS are event-sourced (go through events.log)
5
- * ALL QUERIES are direct reads (fast)
6
- */
7
- import { randomUUID } from 'node:crypto';
8
- /**
9
- * Entities API
10
- *
11
- * @example
12
- * ```typescript
13
- * // Create task (event-sourced)
14
- * const task = await sdk.entities.create({
15
- * type: 'task',
16
- * title: 'Call Marie',
17
- * metadata: { dueDate: '2024-12-20', priority: 'high' }
18
- * });
19
- *
20
- * // Get entity (direct read)
21
- * const entity = await sdk.entities.get(task.id);
22
- *
23
- * // List entities (direct read)
24
- * const tasks = await sdk.entities.list({ type: 'task' });
25
- * ```
26
- */
27
- export class EntitiesAPI {
28
- client;
29
- constructor(client) {
30
- this.client = client;
31
- }
32
- /**
33
- * Create entity (event-sourced)
34
- *
35
- * Publishes `entities.create.requested` event → entitiesWorker → DB
36
- */
37
- async create(input) {
38
- const entityId = randomUUID();
39
- // Call events.log to publish create event
40
- await this.client.events.log.mutate({
41
- aggregateId: entityId,
42
- aggregateType: 'entity',
43
- eventType: 'entities.create.requested',
44
- data: {
45
- id: entityId,
46
- entityType: input.type,
47
- title: input.title,
48
- preview: input.preview,
49
- content: input.content,
50
- metadata: input.metadata,
51
- },
52
- metadata: {},
53
- version: 1,
54
- source: 'api',
55
- });
56
- return { entityId };
57
- }
58
- /**
59
- * Update entity (event-sourced)
60
- *
61
- * Publishes `entities.update.requested` event → entitiesWorker → DB
62
- */
63
- async update(id, input) {
64
- await this.client.events.log.mutate({
65
- aggregateId: id,
66
- aggregateType: 'entity',
67
- eventType: 'entities.update.requested',
68
- data: {
69
- entityId: id,
70
- ...input,
71
- },
72
- metadata: {},
73
- version: 1, // TODO: Get actual version
74
- source: 'api',
75
- });
76
- return { success: true };
77
- }
78
- /**
79
- * Delete entity (event-sourced soft delete)
80
- *
81
- * Publishes `entities.delete.requested` event → entitiesWorker → DB
82
- */
83
- async delete(id) {
84
- await this.client.events.log.mutate({
85
- aggregateId: id,
86
- aggregateType: 'entity',
87
- eventType: 'entities.delete.requested',
88
- data: {
89
- entityId: id,
90
- },
91
- metadata: {},
92
- version: 1,
93
- source: 'api',
94
- });
95
- return { success: true };
96
- }
97
- /**
98
- * Get entity by ID (direct read)
99
- */
100
- async get(id) {
101
- const result = await this.client.entities.get.query({ id });
102
- return result.entity;
103
- }
104
- /**
105
- * List entities (direct read)
106
- */
107
- async list(options = {}) {
108
- const result = await this.client.entities.list.query({
109
- type: options.type, // Type cast because router has different enum
110
- limit: options.limit || 50,
111
- });
112
- return result.entities;
113
- }
114
- /**
115
- * Search entities (direct read)
116
- */
117
- async search(options) {
118
- const result = await this.client.entities.search.query({
119
- query: options.query,
120
- type: options.types?.[0], // Type cast because router has different enum
121
- limit: options.limit || 10,
122
- });
123
- return result.entities;
124
- }
125
- }
126
- //# sourceMappingURL=entities.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/resources/entities.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA4BzC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,WAAW;IACO;IAA7B,YAA6B,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;IAAG,CAAC;IAEpD;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAuB,KAA2B;QAC5D,MAAM,QAAQ,GAAG,UAAU,EAAE,CAAC;QAE9B,0CAA0C;QAC1C,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YAClC,WAAW,EAAE,QAAQ;YACrB,aAAa,EAAE,QAAQ;YACvB,SAAS,EAAE,2BAA2B;YACtC,IAAI,EAAE;gBACJ,EAAE,EAA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,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC5D,OAAO,MAAM,CAAC,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,UAA+B,EAAE;QAC1C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;YACnD,IAAI,EAAE,OAAO,CAAC,IAAW,EAAE,8CAA8C;YACzE,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;SAC3B,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,OAAsB;QACjC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC;YACrD,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAQ,EAAE,8CAA8C;YAC/E,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;SAC3B,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,QAAQ,CAAC;IACzB,CAAC;CACF"}
@@ -1,51 +0,0 @@
1
- /**
2
- * Events API - Event History and Replay
3
- *
4
- * ALL OPERATIONS are direct reads (query event log)
5
- */
6
- import type { SynapClient } from '@synap/client';
7
- import type { Event, EventFilter } from '../types/events.js';
8
- /**
9
- * Events API
10
- *
11
- * @example
12
- * ```typescript
13
- * // Get event history for an entity
14
- * const history = await sdk.events.getHistory(taskId);
15
- *
16
- * // Get user's event timeline
17
- * const timeline = await sdk.events.getTimeline({
18
- * limit: 100,
19
- * after: new Date('2024-01-01')
20
- * });
21
- *
22
- * // Filter by event types
23
- * const creates = await sdk.events.getHistory(entityId, {
24
- * eventTypes: ['entities.create.validated', 'entities.update.validated']
25
- * });
26
- * ```
27
- */
28
- export declare class EventsAPI {
29
- private readonly client;
30
- constructor(client: SynapClient);
31
- /**
32
- * Get event history for a specific subject (entity, relation, etc.)
33
- *
34
- * Returns all events related to the subject in chronological order
35
- */
36
- getHistory(subjectId: string, options?: Omit<EventFilter, 'subjectId'>): Promise<Event[]>;
37
- /**
38
- * Get user's complete event timeline
39
- *
40
- * Returns all events for the current user
41
- */
42
- getTimeline(options?: EventFilter): Promise<Event[]>;
43
- /**
44
- * Replay events to rebuild entity state
45
- *
46
- * Note: This is a client-side replay for now.
47
- * For production, server-side projector rebuild is recommended.
48
- */
49
- replay(subjectId: string): Promise<any>;
50
- }
51
- //# sourceMappingURL=events.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/resources/events.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,WAAW;IAEhD;;;;OAIG;IACG,UAAU,CACd,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,IAAI,CAAC,WAAW,EAAE,WAAW,CAAM,GAC3C,OAAO,CAAC,KAAK,EAAE,CAAC;IAmBnB;;;;OAIG;IACG,WAAW,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAS9D;;;;;OAKG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CAyB9C"}
@@ -1,92 +0,0 @@
1
- /**
2
- * Events API - Event History and Replay
3
- *
4
- * ALL OPERATIONS are direct reads (query event log)
5
- */
6
- /**
7
- * Events API
8
- *
9
- * @example
10
- * ```typescript
11
- * // Get event history for an entity
12
- * const history = await sdk.events.getHistory(taskId);
13
- *
14
- * // Get user's event timeline
15
- * const timeline = await sdk.events.getTimeline({
16
- * limit: 100,
17
- * after: new Date('2024-01-01')
18
- * });
19
- *
20
- * // Filter by event types
21
- * const creates = await sdk.events.getHistory(entityId, {
22
- * eventTypes: ['entities.create.validated', 'entities.update.validated']
23
- * });
24
- * ```
25
- */
26
- export class EventsAPI {
27
- client;
28
- constructor(client) {
29
- this.client = client;
30
- }
31
- /**
32
- * Get event history for a specific subject (entity, relation, etc.)
33
- *
34
- * Returns all events related to the subject in chronological order
35
- */
36
- async getHistory(subjectId, options = {}) {
37
- const events = await this.client.events.list.query({
38
- // Note: The current events.list doesn't support subjectId filter
39
- // For now, we'll get all events and filter client-side
40
- // TODO: Enhance events.list router to support subjectId
41
- limit: options.limit || 50,
42
- type: options.eventTypes?.[0], // Current API only supports single type
43
- });
44
- // Client-side filter by subjectId
45
- // TODO: Move this to server-side once router enhanced
46
- // Type cast to any because Event shape from router doesn't match our SDK Event type
47
- return events.filter((event) => event.data?.entityId === subjectId ||
48
- event.data?.relationId === subjectId ||
49
- event.data?.subjectId === subjectId);
50
- }
51
- /**
52
- * Get user's complete event timeline
53
- *
54
- * Returns all events for the current user
55
- */
56
- async getTimeline(options = {}) {
57
- const events = await this.client.events.list.query({
58
- limit: options.limit || 50,
59
- type: options.eventTypes?.[0],
60
- });
61
- return events;
62
- }
63
- /**
64
- * Replay events to rebuild entity state
65
- *
66
- * Note: This is a client-side replay for now.
67
- * For production, server-side projector rebuild is recommended.
68
- */
69
- async replay(subjectId) {
70
- const events = await this.getHistory(subjectId);
71
- // Simple event replay (can be enhanced)
72
- let state = {};
73
- for (const event of events) {
74
- switch (event.type) {
75
- case 'entity.created':
76
- case 'entities.create.validated':
77
- state = { ...event.data };
78
- break;
79
- case 'entity.updated':
80
- case 'entities.update.validated':
81
- state = { ...state, ...event.data };
82
- break;
83
- case 'entity.deleted':
84
- case 'entities.delete.validated':
85
- state.deletedAt = event.timestamp;
86
- break;
87
- }
88
- }
89
- return state;
90
- }
91
- }
92
- //# sourceMappingURL=events.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/resources/events.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,SAAS;IACS;IAA7B,YAA6B,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;IAAG,CAAC;IAEpD;;;;OAIG;IACH,KAAK,CAAC,UAAU,CACd,SAAiB,EACjB,UAA0C,EAAE;QAE5C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;YACjD,iEAAiE;YACjE,uDAAuD;YACvD,wDAAwD;YACxD,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;YAC1B,IAAI,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,wCAAwC;SACxE,CAAC,CAAC;QAEH,kCAAkC;QAClC,sDAAsD;QACtD,oFAAoF;QACpF,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAClC,KAAK,CAAC,IAAI,EAAE,QAAQ,KAAK,SAAS;YAClC,KAAK,CAAC,IAAI,EAAE,UAAU,KAAK,SAAS;YACpC,KAAK,CAAC,IAAI,EAAE,SAAS,KAAK,SAAS,CAC3B,CAAC;IACb,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,UAAuB,EAAE;QACzC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;YACjD,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;YAC1B,IAAI,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;SAC9B,CAAC,CAAC;QAEH,OAAO,MAAe,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CAAC,SAAiB;QAC5B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAEhD,wCAAwC;QACxC,IAAI,KAAK,GAAQ,EAAE,CAAC;QAEpB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;gBACnB,KAAK,gBAAgB,CAAC;gBACtB,KAAK,2BAA2B;oBAC9B,KAAK,GAAG,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;oBAC1B,MAAM;gBACR,KAAK,gBAAgB,CAAC;gBACtB,KAAK,2BAA2B;oBAC9B,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;oBACpC,MAAM;gBACR,KAAK,gBAAgB,CAAC;gBACtB,KAAK,2BAA2B;oBAC9B,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;oBAClC,MAAM;YACV,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -1,71 +0,0 @@
1
- /**
2
- * Relations API - Universal Relationship Management
3
- *
4
- * ALL MUTATIONS are event-sourced (go through events.log)
5
- * ALL QUERIES are direct reads (fast)
6
- */
7
- import type { SynapClient } from '@synap/client';
8
- import type { RelationType, Relation, RelationFilter } from '../types/relations.js';
9
- /**
10
- * Relations API
11
- *
12
- * @example
13
- * ```typescript
14
- * // Create relationship (event-sourced)
15
- * await sdk.relations.create(taskId, personId, 'assigned_to');
16
- *
17
- * // Get relations (direct read)
18
- * const relations = await sdk.relations.get(entityId, {
19
- * type: 'assigned_to',
20
- * direction: 'both'
21
- * });
22
- *
23
- * // Get related entities (direct read)
24
- * const people = await sdk.relations.getRelated(taskId, {
25
- * type: 'assigned_to',
26
- * direction: 'source'
27
- * });
28
- * ```
29
- */
30
- export declare class RelationsAPI {
31
- private readonly client;
32
- constructor(client: SynapClient);
33
- /**
34
- * Create relationship (event-sourced)
35
- *
36
- * Publishes `relations.create.requested` event → relationsWorker → DB
37
- *
38
- * @param sourceId - Source entity ID
39
- * @param targetId - Target entity ID
40
- * @param type - Relationship type
41
- * @param metadata - Optional metadata
42
- */
43
- create(sourceId: string, targetId: string, type: RelationType | string, metadata?: Record<string, unknown>): Promise<{
44
- relationId: string;
45
- }>;
46
- /**
47
- * Delete relationship (event-sourced)
48
- *
49
- * Publishes `relations.delete.requested` event → relationsWorker → DB
50
- */
51
- delete(relationId: string): Promise<{
52
- success: boolean;
53
- }>;
54
- /**
55
- * Get relations for an entity (direct read)
56
- *
57
- * Returns relationship records (not the related entities themselves)
58
- */
59
- get(entityId: string, options?: Omit<RelationFilter, 'entityId'>): Promise<Relation[]>;
60
- /**
61
- * Get related entities (direct read with join)
62
- *
63
- * Returns the actual entity objects that are related
64
- */
65
- getRelated(entityId: string, options?: Omit<RelationFilter, 'entityId'>): Promise<any>;
66
- /**
67
- * Get relation statistics for an entity (direct read)
68
- */
69
- getStats(entityId: string): Promise<any>;
70
- }
71
- //# sourceMappingURL=relations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"relations.d.ts","sourceRoot":"","sources":["../../src/resources/relations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGpF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,WAAW;IAEhD;;;;;;;;;OASG;IACG,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,YAAY,GAAG,MAAM,EAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAsBlC;;;;OAIG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAgB/D;;;;OAIG;IACG,GAAG,CACP,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,UAAU,CAAM,GAC7C,OAAO,CAAC,QAAQ,EAAE,CAAC;IAYtB;;;;OAIG;IACG,UAAU,CACd,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,UAAU,CAAM;IAahD;;OAEG;IACG,QAAQ,CAAC,QAAQ,EAAE,MAAM;CAKhC"}
@@ -1,121 +0,0 @@
1
- /**
2
- * Relations API - Universal Relationship Management
3
- *
4
- * ALL MUTATIONS are event-sourced (go through events.log)
5
- * ALL QUERIES are direct reads (fast)
6
- */
7
- import { randomUUID } from 'node:crypto';
8
- /**
9
- * Relations API
10
- *
11
- * @example
12
- * ```typescript
13
- * // Create relationship (event-sourced)
14
- * await sdk.relations.create(taskId, personId, 'assigned_to');
15
- *
16
- * // Get relations (direct read)
17
- * const relations = await sdk.relations.get(entityId, {
18
- * type: 'assigned_to',
19
- * direction: 'both'
20
- * });
21
- *
22
- * // Get related entities (direct read)
23
- * const people = await sdk.relations.getRelated(taskId, {
24
- * type: 'assigned_to',
25
- * direction: 'source'
26
- * });
27
- * ```
28
- */
29
- export class RelationsAPI {
30
- client;
31
- constructor(client) {
32
- this.client = client;
33
- }
34
- /**
35
- * Create relationship (event-sourced)
36
- *
37
- * Publishes `relations.create.requested` event → relationsWorker → DB
38
- *
39
- * @param sourceId - Source entity ID
40
- * @param targetId - Target entity ID
41
- * @param type - Relationship type
42
- * @param metadata - Optional metadata
43
- */
44
- async create(sourceId, targetId, type, metadata) {
45
- const relationId = randomUUID();
46
- await this.client.events.log.mutate({
47
- aggregateId: relationId,
48
- aggregateType: 'relation',
49
- eventType: 'relations.create.requested',
50
- data: {
51
- id: relationId,
52
- sourceEntityId: sourceId,
53
- targetEntityId: targetId,
54
- type,
55
- metadata,
56
- },
57
- metadata: {},
58
- version: 1,
59
- source: 'api',
60
- });
61
- return { relationId };
62
- }
63
- /**
64
- * Delete relationship (event-sourced)
65
- *
66
- * Publishes `relations.delete.requested` event → relationsWorker → DB
67
- */
68
- async delete(relationId) {
69
- await this.client.events.log.mutate({
70
- aggregateId: relationId,
71
- aggregateType: 'relation',
72
- eventType: 'relations.delete.requested',
73
- data: {
74
- relationId,
75
- },
76
- metadata: {},
77
- version: 1,
78
- source: 'api',
79
- });
80
- return { success: true };
81
- }
82
- /**
83
- * Get relations for an entity (direct read)
84
- *
85
- * Returns relationship records (not the related entities themselves)
86
- */
87
- async get(entityId, options = {}) {
88
- // Type assertion needed because relations router not in AppRouter type yet
89
- const result = await this.client.relations.get.query({
90
- entityId,
91
- type: options.type,
92
- direction: options.direction || 'both',
93
- limit: options.limit || 50,
94
- });
95
- return result.relations;
96
- }
97
- /**
98
- * Get related entities (direct read with join)
99
- *
100
- * Returns the actual entity objects that are related
101
- */
102
- async getRelated(entityId, options = {}) {
103
- // Type assertion needed because relations router not in AppRouter type yet
104
- const result = await this.client.relations.getRelated.query({
105
- entityId,
106
- type: options.type,
107
- direction: options.direction || 'both',
108
- limit: options.limit || 50,
109
- });
110
- return result.entities;
111
- }
112
- /**
113
- * Get relation statistics for an entity (direct read)
114
- */
115
- async getStats(entityId) {
116
- // Type assertion needed because relations router not in AppRouter type yet
117
- const result = await this.client.relations.getStats.query({ entityId });
118
- return result;
119
- }
120
- }
121
- //# sourceMappingURL=relations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"relations.js","sourceRoot":"","sources":["../../src/resources/relations.ts"],"names":[],"mappings":"AAAA;;;;;GAK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AAI,CAAC,MAAc,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;YAC5D,QAAQ;YACR,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,MAAM;YACtC,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;SAC3B,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,SAAuB,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU,CACd,QAAgB,EAChB,UAA4C,EAAE;QAE9C,6EAA6E;QAC7E,MAAM,MAAM,GAAG,MAAO,IAAI,CAAC,MAAc,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC;YACnE,QAAQ;YACR,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,MAAM;YACtC,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;SAC3B,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,QAAgB;QAC7B,2EAA2E;QAC3E,MAAM,MAAM,GAAG,MAAO,IAAI,CAAC,MAAc,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACjF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -1,24 +0,0 @@
1
- /**
2
- * Event Types
3
- */
4
- export interface Event {
5
- id: string;
6
- timestamp: Date;
7
- type: string;
8
- subjectId: string;
9
- subjectType: string;
10
- data: Record<string, unknown>;
11
- metadata?: Record<string, unknown>;
12
- source: string;
13
- correlationId?: string;
14
- userId: string;
15
- }
16
- export interface EventFilter {
17
- subjectId?: string;
18
- subjectType?: string;
19
- eventTypes?: string[];
20
- limit?: number;
21
- after?: Date;
22
- before?: Date;
23
- }
24
- //# sourceMappingURL=events.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,IAAI,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC;CACf"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Event Types
3
- */
4
- export {};
5
- //# sourceMappingURL=events.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -1,26 +0,0 @@
1
- /**
2
- * Relation Types
3
- */
4
- export type RelationType = 'assigned_to' | 'mentions' | 'links_to' | 'parent_of' | 'relates_to' | 'tagged_with' | 'created_by' | 'attended_by' | 'depends_on' | 'blocks';
5
- export interface Relation {
6
- id: string;
7
- userId: string;
8
- sourceEntityId: string;
9
- targetEntityId: string;
10
- type: RelationType | string;
11
- createdAt: Date;
12
- }
13
- export interface NewRelation {
14
- id?: string;
15
- sourceEntityId: string;
16
- targetEntityId: string;
17
- type: RelationType | string;
18
- metadata?: Record<string, unknown>;
19
- }
20
- export interface RelationFilter {
21
- entityId: string;
22
- type?: RelationType | string;
23
- direction?: 'source' | 'target' | 'both';
24
- limit?: number;
25
- }
26
- //# sourceMappingURL=relations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"relations.d.ts","sourceRoot":"","sources":["../../src/types/relations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,YAAY,GACpB,aAAa,GACb,UAAU,GACV,UAAU,GACV,WAAW,GACX,YAAY,GACZ,aAAa,GACb,YAAY,GACZ,aAAa,GACb,YAAY,GACZ,QAAQ,CAAC;AAEb,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,YAAY,GAAG,MAAM,CAAC;IAC5B,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,YAAY,GAAG,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Relation Types
3
- */
4
- export {};
5
- //# sourceMappingURL=relations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"relations.js","sourceRoot":"","sources":["../../src/types/relations.ts"],"names":[],"mappings":"AAAA;;GAEG"}