@casual-simulation/aux-records 3.6.0 → 3.7.0-alpha.17049743052
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/AuthController.d.ts +1 -2
- package/AuthController.js +5 -24
- package/AuthController.js.map +1 -1
- package/DataRecordsController.d.ts +4 -0
- package/DataRecordsController.js +21 -0
- package/DataRecordsController.js.map +1 -1
- package/DataRecordsStore.d.ts +5 -0
- package/DataRecordsStore.js.map +1 -1
- package/PolicyController.js +2 -1
- package/PolicyController.js.map +1 -1
- package/PolicyStore.d.ts +13 -0
- package/PolicyStore.js +16 -0
- package/PolicyStore.js.map +1 -1
- package/RecordsController.js +2 -2
- package/RecordsController.js.map +1 -1
- package/RecordsServer.d.ts +142 -4
- package/RecordsServer.js +205 -1
- package/RecordsServer.js.map +1 -1
- package/ServerConfig.d.ts +447 -0
- package/ServerConfig.js +54 -0
- package/ServerConfig.js.map +1 -1
- package/SubscriptionConfigBuilder.d.ts +3 -1
- package/SubscriptionConfigBuilder.js +10 -0
- package/SubscriptionConfigBuilder.js.map +1 -1
- package/SubscriptionConfiguration.d.ts +245 -1
- package/SubscriptionConfiguration.js +73 -19
- package/SubscriptionConfiguration.js.map +1 -1
- package/SubscriptionController.d.ts +1 -1
- package/SubscriptionController.js.map +1 -1
- package/TestUtils.js +1 -1
- package/TestUtils.js.map +1 -1
- package/crud/CrudRecordsController.d.ts +12 -8
- package/crud/CrudRecordsController.js +29 -12
- package/crud/CrudRecordsController.js.map +1 -1
- package/crud/CrudRecordsControllerTests.d.ts +5 -5
- package/crud/CrudRecordsControllerTests.js +128 -69
- package/crud/CrudRecordsControllerTests.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/notifications/NotificationRecordsController.d.ts +1 -1
- package/notifications/NotificationRecordsController.js.map +1 -1
- package/package.json +4 -3
- package/packages/PackageRecordsController.d.ts +1 -1
- package/packages/PackageRecordsController.js.map +1 -1
- package/queue/MemoryQueue.d.ts +24 -0
- package/queue/MemoryQueue.js +45 -0
- package/queue/MemoryQueue.js.map +1 -0
- package/queue/Queue.d.ts +12 -0
- package/queue/Queue.js +19 -0
- package/queue/Queue.js.map +1 -0
- package/queue/index.d.ts +2 -0
- package/queue/index.js +19 -0
- package/queue/index.js.map +1 -0
- package/search/MemorySearchInterface.d.ts +25 -0
- package/search/MemorySearchInterface.js +192 -0
- package/search/MemorySearchInterface.js.map +1 -0
- package/search/MemorySearchRecordsStore.d.ts +21 -0
- package/search/MemorySearchRecordsStore.js +80 -0
- package/search/MemorySearchRecordsStore.js.map +1 -0
- package/search/SearchInterface.d.ts +329 -0
- package/search/SearchInterface.js +19 -0
- package/search/SearchInterface.js.map +1 -0
- package/search/SearchRecordsController.d.ts +491 -0
- package/search/SearchRecordsController.js +521 -0
- package/search/SearchRecordsController.js.map +1 -0
- package/search/SearchRecordsStore.d.ts +176 -0
- package/search/SearchRecordsStore.js +2 -0
- package/search/SearchRecordsStore.js.map +1 -0
- package/search/SearchSyncProcessor.d.ts +162 -0
- package/search/SearchSyncProcessor.js +256 -0
- package/search/SearchSyncProcessor.js.map +1 -0
- package/search/TypesenseSearchInterface.d.ts +18 -0
- package/search/TypesenseSearchInterface.js +171 -0
- package/search/TypesenseSearchInterface.js.map +1 -0
- package/search/index.d.ts +7 -0
- package/search/index.js +24 -0
- package/search/index.js.map +1 -0
- package/webhooks/WebhookRecordsController.d.ts +3 -3
- package/webhooks/WebhookRecordsController.js +3 -3
- package/webhooks/WebhookRecordsController.js.map +1 -1
- package/websockets/WebsocketController.js +30 -25
- package/websockets/WebsocketController.js.map +1 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { ResourceKinds } from '@casual-simulation/aux-common';
|
|
2
|
+
import type { CrudRecord, CrudRecordsStore, CrudSubscriptionMetrics } from '../crud';
|
|
3
|
+
import type { SubscriptionFilter } from '../MetricsStore';
|
|
4
|
+
/**
|
|
5
|
+
* Defines a store that contains search records.
|
|
6
|
+
*/
|
|
7
|
+
export interface SearchRecordsStore extends CrudRecordsStore<SearchRecord> {
|
|
8
|
+
/**
|
|
9
|
+
* Gets the item metrics for the subscription of the given user or studio.
|
|
10
|
+
* @param filter The filter to use.
|
|
11
|
+
*/
|
|
12
|
+
getSubscriptionMetrics(filter: SubscriptionFilter): Promise<SearchSubscriptionMetrics>;
|
|
13
|
+
/**
|
|
14
|
+
* Creates or saves a search record sync.
|
|
15
|
+
* @param sync The search record sync to create or save.
|
|
16
|
+
*/
|
|
17
|
+
saveSync(sync: SearchRecordSync): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the search record sync with the given ID.
|
|
20
|
+
* @param syncId The ID of the sync to get.
|
|
21
|
+
*/
|
|
22
|
+
getSync(syncId: string): Promise<SearchRecordSync | null>;
|
|
23
|
+
/**
|
|
24
|
+
* Deletes the search record sync with the given ID.
|
|
25
|
+
* @param syncId The ID of the sync to delete.
|
|
26
|
+
*/
|
|
27
|
+
deleteSync(syncId: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the list of search record syncs for the given search record.
|
|
30
|
+
* @param recordName The name of the record.
|
|
31
|
+
* @param address The address of the search record.
|
|
32
|
+
*/
|
|
33
|
+
listSyncsBySearchRecord(recordName: string, address: string): Promise<SearchRecordSync[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new sync history entry.
|
|
36
|
+
* @param history The sync history entry to create.
|
|
37
|
+
*/
|
|
38
|
+
createSyncHistory(history: SearchRecordSyncHistory): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Finds the sync that matches the given target record name, resource kind, and markers.
|
|
41
|
+
*
|
|
42
|
+
* Always returns an object, but the sync and search record may be null if no sync was found.
|
|
43
|
+
*
|
|
44
|
+
* @param targetRecordName The name of the target record.
|
|
45
|
+
* @param targetResourceKind The kind of resource that the sync is for.
|
|
46
|
+
* @param markers The markers to use for the sync.
|
|
47
|
+
*/
|
|
48
|
+
getSyncsByTarget(targetRecordName: string, targetResourceKind: ResourceKinds, markers: string[]): Promise<GetSearchRecordSyncByTargetResult[]>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Defines a record that represents a collection of documents that can be searched.
|
|
52
|
+
*/
|
|
53
|
+
export interface SearchRecord extends CrudRecord {
|
|
54
|
+
/**
|
|
55
|
+
* The name of the collection that this search record is attached to.
|
|
56
|
+
*/
|
|
57
|
+
collectionName: string;
|
|
58
|
+
/**
|
|
59
|
+
* The API key that is used to query the collection.
|
|
60
|
+
*/
|
|
61
|
+
searchApiKey: string;
|
|
62
|
+
}
|
|
63
|
+
export interface SearchSubscriptionMetrics extends CrudSubscriptionMetrics {
|
|
64
|
+
/**
|
|
65
|
+
* The total number of search records that are stored in the subscription.
|
|
66
|
+
*/
|
|
67
|
+
totalItems: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Defines a record that represents syncing data to a search collection.
|
|
71
|
+
* This is used to sync data from data records to a search collection.
|
|
72
|
+
*/
|
|
73
|
+
export interface SearchRecordSync {
|
|
74
|
+
/**
|
|
75
|
+
* The ID of the search record sync.
|
|
76
|
+
*/
|
|
77
|
+
id: string;
|
|
78
|
+
/**
|
|
79
|
+
* The name of the record that the search record is in.
|
|
80
|
+
*/
|
|
81
|
+
searchRecordName: string;
|
|
82
|
+
/**
|
|
83
|
+
* The address of the search record.
|
|
84
|
+
*/
|
|
85
|
+
searchRecordAddress: string;
|
|
86
|
+
/**
|
|
87
|
+
* The name of the record that the data should be synced from.
|
|
88
|
+
*/
|
|
89
|
+
targetRecordName: string;
|
|
90
|
+
/**
|
|
91
|
+
* The marker that the data should be synced from.
|
|
92
|
+
*/
|
|
93
|
+
targetMarker: string;
|
|
94
|
+
/**
|
|
95
|
+
* The kind of resource that should be synced.
|
|
96
|
+
*/
|
|
97
|
+
targetResourceKind: ResourceKinds;
|
|
98
|
+
/**
|
|
99
|
+
* The mapping of the target properties to the search document properties.
|
|
100
|
+
*
|
|
101
|
+
* Each entry in the array is a tuple where the first element is the source property
|
|
102
|
+
* and the second element is the target property in the search document.
|
|
103
|
+
*/
|
|
104
|
+
targetMapping: [string, string][];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Defines an interface that represents the history of a search record sync.
|
|
108
|
+
*/
|
|
109
|
+
export interface SearchRecordSyncHistory {
|
|
110
|
+
/**
|
|
111
|
+
* The ID of the search record sync history.
|
|
112
|
+
*/
|
|
113
|
+
id: string;
|
|
114
|
+
/**
|
|
115
|
+
* The name of the record that the search collection is in.
|
|
116
|
+
*/
|
|
117
|
+
searchRecordName: string;
|
|
118
|
+
/**
|
|
119
|
+
* The address of the search record.
|
|
120
|
+
*/
|
|
121
|
+
searchRecordAddress: string;
|
|
122
|
+
/**
|
|
123
|
+
* The ID of the sync that this history is for.
|
|
124
|
+
*/
|
|
125
|
+
syncId: string;
|
|
126
|
+
/**
|
|
127
|
+
* The ID of the sync run that this history is for.
|
|
128
|
+
* Syncs may trigger multiple history entries, so this ID is used to group runs together.
|
|
129
|
+
*/
|
|
130
|
+
runId: string;
|
|
131
|
+
/**
|
|
132
|
+
* The time of the sync.
|
|
133
|
+
*
|
|
134
|
+
* Miliseconds since the unix epoch in UTC.
|
|
135
|
+
*/
|
|
136
|
+
timeMs: number;
|
|
137
|
+
/**
|
|
138
|
+
* The status of the sync.
|
|
139
|
+
*/
|
|
140
|
+
status: 'success' | 'failure';
|
|
141
|
+
/**
|
|
142
|
+
* Whether the sync was successful.
|
|
143
|
+
*/
|
|
144
|
+
success: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* The error message if the sync failed.
|
|
147
|
+
*/
|
|
148
|
+
errorMessage: string | null;
|
|
149
|
+
/**
|
|
150
|
+
* The number of documents that were successfully synced.
|
|
151
|
+
*/
|
|
152
|
+
numSynced: number;
|
|
153
|
+
/**
|
|
154
|
+
* The number of documents that errored during the sync.
|
|
155
|
+
*/
|
|
156
|
+
numErrored: number;
|
|
157
|
+
/**
|
|
158
|
+
* The total number of documents that were processed during the sync.
|
|
159
|
+
*/
|
|
160
|
+
numTotal: number;
|
|
161
|
+
}
|
|
162
|
+
export interface GetSearchRecordSyncByTargetResult {
|
|
163
|
+
/**
|
|
164
|
+
* The sync that matches the target record name, resource kind, and markers.
|
|
165
|
+
*
|
|
166
|
+
* Null if no sync was found.
|
|
167
|
+
*/
|
|
168
|
+
sync: SearchRecordSync | null;
|
|
169
|
+
/**
|
|
170
|
+
* The search record that the sync is for.
|
|
171
|
+
*
|
|
172
|
+
* Null if no search record was found.
|
|
173
|
+
*/
|
|
174
|
+
searchRecord: SearchRecord | null;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=SearchRecordsStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchRecordsStore.js","sourceRoot":"","sources":["SearchRecordsStore.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { DataRecordsStore } from '../DataRecordsStore';
|
|
2
|
+
import type { SearchRecordsStore, SearchRecordSync } from './SearchRecordsStore';
|
|
3
|
+
import type { Result, SimpleError } from '@casual-simulation/aux-common';
|
|
4
|
+
import type { SearchInterface } from './SearchInterface';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
export interface SearchSyncProcessorConfig {
|
|
7
|
+
search: SearchRecordsStore;
|
|
8
|
+
searchInterface: SearchInterface;
|
|
9
|
+
data: DataRecordsStore;
|
|
10
|
+
}
|
|
11
|
+
export declare class SearchSyncProcessor {
|
|
12
|
+
private _store;
|
|
13
|
+
private _searchInterface;
|
|
14
|
+
private _data;
|
|
15
|
+
constructor(config: SearchSyncProcessorConfig);
|
|
16
|
+
process(event: SearchSyncQueueEvent): Promise<void>;
|
|
17
|
+
private _syncItem;
|
|
18
|
+
private _syncSearchRecord;
|
|
19
|
+
private _syncDataRecord;
|
|
20
|
+
private _mapData;
|
|
21
|
+
}
|
|
22
|
+
export declare function getDocumentId(recordName: string, address: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Maps a object to another object using the given mapping.
|
|
25
|
+
* Returns null if the mapping was not successful.
|
|
26
|
+
*
|
|
27
|
+
* @param item The item to map.
|
|
28
|
+
* @param mapping The mapping to use.
|
|
29
|
+
*/
|
|
30
|
+
export declare function mapItem(item: object, mapping: [string, string][]): Result<any, SimpleError>;
|
|
31
|
+
export declare const SYNC_SEARCH_RECORD_EVENT_SCHEMA: z.ZodObject<{
|
|
32
|
+
type: z.ZodLiteral<"sync_search_record">;
|
|
33
|
+
sync: z.ZodObject<{
|
|
34
|
+
id: z.ZodString;
|
|
35
|
+
searchRecordName: z.ZodString;
|
|
36
|
+
searchRecordAddress: z.ZodString;
|
|
37
|
+
targetResourceKind: z.ZodLiteral<"data">;
|
|
38
|
+
targetRecordName: z.ZodString;
|
|
39
|
+
targetMarker: z.ZodString;
|
|
40
|
+
targetMapping: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
id?: string;
|
|
43
|
+
searchRecordName?: string;
|
|
44
|
+
searchRecordAddress?: string;
|
|
45
|
+
targetResourceKind?: "data";
|
|
46
|
+
targetRecordName?: string;
|
|
47
|
+
targetMarker?: string;
|
|
48
|
+
targetMapping?: [string, string, ...unknown[]][];
|
|
49
|
+
}, {
|
|
50
|
+
id?: string;
|
|
51
|
+
searchRecordName?: string;
|
|
52
|
+
searchRecordAddress?: string;
|
|
53
|
+
targetResourceKind?: "data";
|
|
54
|
+
targetRecordName?: string;
|
|
55
|
+
targetMarker?: string;
|
|
56
|
+
targetMapping?: [string, string, ...unknown[]][];
|
|
57
|
+
}>;
|
|
58
|
+
}, "strip", z.ZodTypeAny, {
|
|
59
|
+
type?: "sync_search_record";
|
|
60
|
+
sync?: {
|
|
61
|
+
id?: string;
|
|
62
|
+
searchRecordName?: string;
|
|
63
|
+
searchRecordAddress?: string;
|
|
64
|
+
targetResourceKind?: "data";
|
|
65
|
+
targetRecordName?: string;
|
|
66
|
+
targetMarker?: string;
|
|
67
|
+
targetMapping?: [string, string, ...unknown[]][];
|
|
68
|
+
};
|
|
69
|
+
}, {
|
|
70
|
+
type?: "sync_search_record";
|
|
71
|
+
sync?: {
|
|
72
|
+
id?: string;
|
|
73
|
+
searchRecordName?: string;
|
|
74
|
+
searchRecordAddress?: string;
|
|
75
|
+
targetResourceKind?: "data";
|
|
76
|
+
targetRecordName?: string;
|
|
77
|
+
targetMarker?: string;
|
|
78
|
+
targetMapping?: [string, string, ...unknown[]][];
|
|
79
|
+
};
|
|
80
|
+
}>;
|
|
81
|
+
export declare const SEARCH_SYNC_QUEUE_EVENT_SCHEMA: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
82
|
+
type: z.ZodLiteral<"sync_search_record">;
|
|
83
|
+
sync: z.ZodObject<{
|
|
84
|
+
id: z.ZodString;
|
|
85
|
+
searchRecordName: z.ZodString;
|
|
86
|
+
searchRecordAddress: z.ZodString;
|
|
87
|
+
targetResourceKind: z.ZodLiteral<"data">;
|
|
88
|
+
targetRecordName: z.ZodString;
|
|
89
|
+
targetMarker: z.ZodString;
|
|
90
|
+
targetMapping: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">;
|
|
91
|
+
}, "strip", z.ZodTypeAny, {
|
|
92
|
+
id?: string;
|
|
93
|
+
searchRecordName?: string;
|
|
94
|
+
searchRecordAddress?: string;
|
|
95
|
+
targetResourceKind?: "data";
|
|
96
|
+
targetRecordName?: string;
|
|
97
|
+
targetMarker?: string;
|
|
98
|
+
targetMapping?: [string, string, ...unknown[]][];
|
|
99
|
+
}, {
|
|
100
|
+
id?: string;
|
|
101
|
+
searchRecordName?: string;
|
|
102
|
+
searchRecordAddress?: string;
|
|
103
|
+
targetResourceKind?: "data";
|
|
104
|
+
targetRecordName?: string;
|
|
105
|
+
targetMarker?: string;
|
|
106
|
+
targetMapping?: [string, string, ...unknown[]][];
|
|
107
|
+
}>;
|
|
108
|
+
}, "strip", z.ZodTypeAny, {
|
|
109
|
+
type?: "sync_search_record";
|
|
110
|
+
sync?: {
|
|
111
|
+
id?: string;
|
|
112
|
+
searchRecordName?: string;
|
|
113
|
+
searchRecordAddress?: string;
|
|
114
|
+
targetResourceKind?: "data";
|
|
115
|
+
targetRecordName?: string;
|
|
116
|
+
targetMarker?: string;
|
|
117
|
+
targetMapping?: [string, string, ...unknown[]][];
|
|
118
|
+
};
|
|
119
|
+
}, {
|
|
120
|
+
type?: "sync_search_record";
|
|
121
|
+
sync?: {
|
|
122
|
+
id?: string;
|
|
123
|
+
searchRecordName?: string;
|
|
124
|
+
searchRecordAddress?: string;
|
|
125
|
+
targetResourceKind?: "data";
|
|
126
|
+
targetRecordName?: string;
|
|
127
|
+
targetMarker?: string;
|
|
128
|
+
targetMapping?: [string, string, ...unknown[]][];
|
|
129
|
+
};
|
|
130
|
+
}>]>;
|
|
131
|
+
export type SearchSyncQueueEvent = SyncSearchRecordEvent | SyncItemEvent;
|
|
132
|
+
export interface SyncSearchRecordEvent {
|
|
133
|
+
type: 'sync_search_record';
|
|
134
|
+
/**
|
|
135
|
+
* The search record that is being synced.
|
|
136
|
+
*/
|
|
137
|
+
sync: SearchRecordSync;
|
|
138
|
+
}
|
|
139
|
+
export interface SyncItemEvent {
|
|
140
|
+
type: 'sync_item';
|
|
141
|
+
/**
|
|
142
|
+
* The action that was performed on the item.
|
|
143
|
+
*/
|
|
144
|
+
action: 'create' | 'update' | 'delete';
|
|
145
|
+
/**
|
|
146
|
+
* The name of the record that the item is in.
|
|
147
|
+
*/
|
|
148
|
+
itemRecordName: string;
|
|
149
|
+
/**
|
|
150
|
+
* The kind of resource that the item is.
|
|
151
|
+
*/
|
|
152
|
+
itemResourceKind: string;
|
|
153
|
+
/**
|
|
154
|
+
* The address of the item.
|
|
155
|
+
*/
|
|
156
|
+
itemAddress: string;
|
|
157
|
+
/**
|
|
158
|
+
* The markers of the item.
|
|
159
|
+
*/
|
|
160
|
+
itemMarkers: string[];
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=SearchSyncProcessor.d.ts.map
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/* CasualOS is a set of web-based tools designed to facilitate the creation of real-time, multi-user, context-aware interactive experiences.
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2019-2025 Casual Simulation, Inc.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as
|
|
7
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
8
|
+
* License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
import { traced } from '../tracing/TracingDecorators';
|
|
25
|
+
import { v7 as uuid, v5 as uuidv5 } from 'uuid';
|
|
26
|
+
import { failure, isFailure, isSuccess, success, } from '@casual-simulation/aux-common';
|
|
27
|
+
import { z } from 'zod';
|
|
28
|
+
import { getMarkersOrDefault } from '../Utils';
|
|
29
|
+
const DOCUMENT_NAMESPACE = '36e15e17-0f44-4c07-ab84-22eafecc2614';
|
|
30
|
+
const TRACE_NAME = 'SearchSyncProcessor';
|
|
31
|
+
export class SearchSyncProcessor {
|
|
32
|
+
constructor(config) {
|
|
33
|
+
this._store = config.search;
|
|
34
|
+
this._searchInterface = config.searchInterface;
|
|
35
|
+
this._data = config.data;
|
|
36
|
+
}
|
|
37
|
+
async process(event) {
|
|
38
|
+
console.log(`[${TRACE_NAME}] Processing event:`, event);
|
|
39
|
+
if (event.type === 'sync_search_record') {
|
|
40
|
+
await this._syncSearchRecord(event);
|
|
41
|
+
}
|
|
42
|
+
else if (event.type === 'sync_item') {
|
|
43
|
+
await this._syncItem(event);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async _syncItem(event) {
|
|
47
|
+
if (event.itemResourceKind !== 'data') {
|
|
48
|
+
console.warn(`[${TRACE_NAME}] Unsupported resource kind: ${event.itemResourceKind}. Only 'data' is supported.`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const syncs = await this._store.getSyncsByTarget(event.itemRecordName, event.itemResourceKind, getMarkersOrDefault(event.itemMarkers));
|
|
52
|
+
if (syncs.length <= 0) {
|
|
53
|
+
console.warn(`[${TRACE_NAME}] No sync found for item: ${event.itemRecordName}, ${event.itemAddress}`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
for (let { sync, searchRecord } of syncs) {
|
|
57
|
+
console.log(`[${TRACE_NAME}] Syncing item: ${event.itemRecordName}, ${event.itemAddress} with sync:`, sync);
|
|
58
|
+
if (event.action === 'delete') {
|
|
59
|
+
const documentId = uuidv5(`${event.itemRecordName}:${event.itemAddress}`, DOCUMENT_NAMESPACE);
|
|
60
|
+
const deletionResult = await this._searchInterface.deleteDocument(searchRecord.collectionName, documentId);
|
|
61
|
+
if (deletionResult.success === true) {
|
|
62
|
+
console.log(`[${TRACE_NAME}] Successfully deleted document: ${documentId}`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
console.error(`[${TRACE_NAME}] Failed to delete document: ${documentId}`, deletionResult.error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const item = await this._data.getData(event.itemRecordName, event.itemAddress);
|
|
70
|
+
if (item.success === false) {
|
|
71
|
+
console.error(`[${TRACE_NAME}] Failed to get item: ${event.itemRecordName}, ${event.itemAddress}`, item.errorCode, item.errorMessage);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const mapped = this._mapData(event.itemAddress, item.data, sync);
|
|
75
|
+
if (isFailure(mapped)) {
|
|
76
|
+
console.error(`[${TRACE_NAME}] Failed to map item: ${mapped.error.errorMessage}`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
await this._searchInterface.createDocument(searchRecord.collectionName, mapped.value, 'emplace');
|
|
80
|
+
console.log(`[${TRACE_NAME}] Successfully synced item: ${event.itemRecordName}, ${event.itemAddress}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async _syncSearchRecord(event) {
|
|
85
|
+
const searchRecord = await this._store.getItemByAddress(event.sync.searchRecordName, event.sync.searchRecordAddress);
|
|
86
|
+
const result = event.sync.targetResourceKind === 'data'
|
|
87
|
+
? await this._syncDataRecord(event, searchRecord)
|
|
88
|
+
: failure({
|
|
89
|
+
errorCode: 'not_supported',
|
|
90
|
+
errorMessage: `Unsupported target resource kind: ${event.sync.targetResourceKind}`,
|
|
91
|
+
});
|
|
92
|
+
const runId = uuid();
|
|
93
|
+
const history = {
|
|
94
|
+
id: runId,
|
|
95
|
+
runId,
|
|
96
|
+
syncId: event.sync.id,
|
|
97
|
+
searchRecordAddress: event.sync.searchRecordAddress,
|
|
98
|
+
searchRecordName: event.sync.searchRecordName,
|
|
99
|
+
timeMs: Date.now(),
|
|
100
|
+
errorMessage: isFailure(result) ? result.error.errorMessage : null,
|
|
101
|
+
status: isFailure(result) ? 'failure' : 'success',
|
|
102
|
+
success: result.success,
|
|
103
|
+
numSynced: 0,
|
|
104
|
+
numTotal: 0,
|
|
105
|
+
numErrored: 0,
|
|
106
|
+
};
|
|
107
|
+
if (isSuccess(result)) {
|
|
108
|
+
console.log(`[${TRACE_NAME}] Successfully synced search record:`, result.value);
|
|
109
|
+
history.numSynced = result.value.numSynced;
|
|
110
|
+
history.numErrored = result.value.numErrored;
|
|
111
|
+
history.numTotal = result.value.numTotal;
|
|
112
|
+
}
|
|
113
|
+
await this._store.createSyncHistory(history);
|
|
114
|
+
}
|
|
115
|
+
async _syncDataRecord(event, searchRecord) {
|
|
116
|
+
let startingAddress = null;
|
|
117
|
+
let done = false;
|
|
118
|
+
let numSynced = 0;
|
|
119
|
+
let numErrored = 0;
|
|
120
|
+
const count = 100;
|
|
121
|
+
for (let iteration = 0; iteration < 1000; iteration++) {
|
|
122
|
+
const data = await this._data.listDataByMarker({
|
|
123
|
+
recordName: event.sync.targetRecordName,
|
|
124
|
+
marker: event.sync.targetMarker,
|
|
125
|
+
startingAddress,
|
|
126
|
+
count,
|
|
127
|
+
});
|
|
128
|
+
if (data.success === false) {
|
|
129
|
+
return failure(data);
|
|
130
|
+
}
|
|
131
|
+
for (let i = 0; i < data.items.length; i++) {
|
|
132
|
+
const item = data.items[i];
|
|
133
|
+
const mapped = this._mapData(item.address, item.data, event.sync);
|
|
134
|
+
if (isFailure(mapped)) {
|
|
135
|
+
numErrored++;
|
|
136
|
+
console.warn(`Error mapping item at address ${item.address} in record ${event.sync.targetRecordName}: ${mapped.error.errorMessage}`);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
await this._searchInterface.createDocument(searchRecord.collectionName, mapped.value, 'emplace');
|
|
140
|
+
numSynced++;
|
|
141
|
+
if (i === data.items.length - 1) {
|
|
142
|
+
startingAddress = item.address;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (data.items.length < count) {
|
|
146
|
+
done = true;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!done) {
|
|
151
|
+
return failure({
|
|
152
|
+
errorCode: 'took_too_long',
|
|
153
|
+
errorMessage: 'The record has too many items to sync in a single operation. Please reduce the number of items and try again.',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (numSynced === 0 && numErrored > 0) {
|
|
157
|
+
return failure({
|
|
158
|
+
errorCode: 'invalid_request',
|
|
159
|
+
errorMessage: `All mappings failed for all records (${numErrored}).`,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return success({
|
|
163
|
+
numSynced,
|
|
164
|
+
numErrored,
|
|
165
|
+
numTotal: numSynced + numErrored,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
_mapData(address, data, sync) {
|
|
169
|
+
const mapped = mapItem(data, sync.targetMapping);
|
|
170
|
+
if (isFailure(mapped)) {
|
|
171
|
+
return mapped;
|
|
172
|
+
}
|
|
173
|
+
const documentId = getDocumentId(sync.targetRecordName, address);
|
|
174
|
+
mapped.value.id = documentId;
|
|
175
|
+
return success(mapped.value);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
__decorate([
|
|
179
|
+
traced(TRACE_NAME)
|
|
180
|
+
], SearchSyncProcessor.prototype, "process", null);
|
|
181
|
+
__decorate([
|
|
182
|
+
traced(TRACE_NAME)
|
|
183
|
+
], SearchSyncProcessor.prototype, "_syncItem", null);
|
|
184
|
+
__decorate([
|
|
185
|
+
traced(TRACE_NAME)
|
|
186
|
+
], SearchSyncProcessor.prototype, "_syncSearchRecord", null);
|
|
187
|
+
export function getDocumentId(recordName, address) {
|
|
188
|
+
return uuidv5(`${recordName}:${address}`, DOCUMENT_NAMESPACE);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Maps a object to another object using the given mapping.
|
|
192
|
+
* Returns null if the mapping was not successful.
|
|
193
|
+
*
|
|
194
|
+
* @param item The item to map.
|
|
195
|
+
* @param mapping The mapping to use.
|
|
196
|
+
*/
|
|
197
|
+
export function mapItem(item, mapping) {
|
|
198
|
+
if (typeof item !== 'object' || item === null) {
|
|
199
|
+
return failure({
|
|
200
|
+
errorCode: 'invalid_request',
|
|
201
|
+
errorMessage: `Item must be an object, but got ${typeof item}.`,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
const result = {};
|
|
205
|
+
for (let i = 0; i < mapping.length; i++) {
|
|
206
|
+
const [from, to] = mapping[i];
|
|
207
|
+
const parts = from.split('.');
|
|
208
|
+
let value = item;
|
|
209
|
+
for (let p = 0; p < parts.length; p++) {
|
|
210
|
+
let part = parts[p];
|
|
211
|
+
if (p === 0 && part === '$') {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const optional = part.endsWith('?');
|
|
215
|
+
if (optional) {
|
|
216
|
+
part = part.substring(0, part.length - 1);
|
|
217
|
+
}
|
|
218
|
+
if (Object.hasOwn(value, part)) {
|
|
219
|
+
value = value[part];
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
// not found
|
|
223
|
+
if (optional) {
|
|
224
|
+
value = null;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
const pathTilFailure = parts.slice(0, p);
|
|
228
|
+
pathTilFailure.unshift('$');
|
|
229
|
+
return failure({
|
|
230
|
+
errorCode: 'invalid_request',
|
|
231
|
+
errorMessage: `Property missing. Could not find '${part}' (full path: '${from}') on '${pathTilFailure.join('.')}'`,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (value !== null && value !== undefined) {
|
|
236
|
+
result[to] = value;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return success(result);
|
|
240
|
+
}
|
|
241
|
+
export const SYNC_SEARCH_RECORD_EVENT_SCHEMA = z.object({
|
|
242
|
+
type: z.literal('sync_search_record'),
|
|
243
|
+
sync: z.object({
|
|
244
|
+
id: z.string(),
|
|
245
|
+
searchRecordName: z.string().min(1),
|
|
246
|
+
searchRecordAddress: z.string().min(1),
|
|
247
|
+
targetResourceKind: z.literal('data'),
|
|
248
|
+
targetRecordName: z.string().min(1),
|
|
249
|
+
targetMarker: z.string().min(1),
|
|
250
|
+
targetMapping: z.array(z.tuple([z.string().min(1), z.string().min(1)])),
|
|
251
|
+
}),
|
|
252
|
+
});
|
|
253
|
+
export const SEARCH_SYNC_QUEUE_EVENT_SCHEMA = z.discriminatedUnion('type', [
|
|
254
|
+
SYNC_SEARCH_RECORD_EVENT_SCHEMA,
|
|
255
|
+
]);
|
|
256
|
+
//# sourceMappingURL=SearchSyncProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchSyncProcessor.js","sourceRoot":"","sources":["SearchSyncProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;AASH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEhD,OAAO,EACH,OAAO,EACP,SAAS,EACT,SAAS,EACT,OAAO,GACV,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,kBAAkB,GAAG,sCAAsC,CAAC;AAElE,MAAM,UAAU,GAAG,qBAAqB,CAAC;AAQzC,MAAM,OAAO,mBAAmB;IAK5B,YAAY,MAAiC;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,eAAe,CAAC;QAC/C,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;IAC7B,CAAC;IAGK,AAAN,KAAK,CAAC,OAAO,CAAC,KAA2B;QACrC,OAAO,CAAC,GAAG,CAAC,IAAI,UAAU,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AM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC,MAAM,CAAC;IACpD,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QACX,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;QACd,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACnC,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACtC,kBAAkB,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;QACrC,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACnC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/B,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC1E,CAAC;CACL,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACvE,+BAA+B;CAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SearchApiKey, SearchApiKeyData, SearchCollection, SearchCollectionInfo, SearchDocument, SearchDocumentInfo, SearchInterface, SearchNode, SearchQuery, SearchResult, UpdatedSearchCollection } from './SearchInterface';
|
|
2
|
+
import type { Client } from 'typesense';
|
|
3
|
+
import type { Result, SimpleError } from '@casual-simulation/aux-common';
|
|
4
|
+
export declare class TypesenseSearchInterface implements SearchInterface {
|
|
5
|
+
private _client;
|
|
6
|
+
constructor(client: Client);
|
|
7
|
+
get nodes(): SearchNode[];
|
|
8
|
+
createCollection(collection: SearchCollection): Promise<SearchCollectionInfo>;
|
|
9
|
+
updateCollection(collection: UpdatedSearchCollection): Promise<SearchCollectionInfo>;
|
|
10
|
+
dropCollection(collectionName: string): Promise<SearchCollectionInfo>;
|
|
11
|
+
getCollection(collectionName: string): Promise<SearchCollectionInfo>;
|
|
12
|
+
createDocument(collectionName: string, document: SearchDocument, action?: 'create' | 'upsert' | 'update' | 'emplace'): Promise<SearchDocumentInfo>;
|
|
13
|
+
deleteDocument(collectionName: string, documentId: string): Promise<Result<SearchDocumentInfo, SimpleError>>;
|
|
14
|
+
createApiKey(apiKey: SearchApiKeyData): Promise<SearchApiKey>;
|
|
15
|
+
searchCollection(collectionName: string, query: SearchQuery): Promise<SearchResult>;
|
|
16
|
+
private _handleErrors;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=TypesenseSearchInterface.d.ts.map
|