@casual-simulation/aux-records 3.5.3 → 3.7.0-alpha.16977445547

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 (78) hide show
  1. package/ComIdConfig.d.ts +8 -0
  2. package/ComIdConfig.js +1 -0
  3. package/ComIdConfig.js.map +1 -1
  4. package/DataRecordsController.d.ts +4 -0
  5. package/DataRecordsController.js +21 -0
  6. package/DataRecordsController.js.map +1 -1
  7. package/DataRecordsStore.d.ts +5 -0
  8. package/DataRecordsStore.js.map +1 -1
  9. package/PolicyController.js +2 -1
  10. package/PolicyController.js.map +1 -1
  11. package/PolicyStore.d.ts +13 -0
  12. package/PolicyStore.js +16 -0
  13. package/PolicyStore.js.map +1 -1
  14. package/RecordsController.d.ts +5 -0
  15. package/RecordsServer.d.ts +144 -4
  16. package/RecordsServer.js +214 -1
  17. package/RecordsServer.js.map +1 -1
  18. package/ServerConfig.d.ts +447 -0
  19. package/ServerConfig.js +54 -0
  20. package/ServerConfig.js.map +1 -1
  21. package/SubscriptionConfigBuilder.d.ts +3 -1
  22. package/SubscriptionConfigBuilder.js +10 -0
  23. package/SubscriptionConfigBuilder.js.map +1 -1
  24. package/SubscriptionConfiguration.d.ts +229 -0
  25. package/SubscriptionConfiguration.js +35 -0
  26. package/SubscriptionConfiguration.js.map +1 -1
  27. package/crud/CrudRecordsController.d.ts +12 -8
  28. package/crud/CrudRecordsController.js +29 -12
  29. package/crud/CrudRecordsController.js.map +1 -1
  30. package/crud/CrudRecordsControllerTests.d.ts +5 -5
  31. package/crud/CrudRecordsControllerTests.js +128 -69
  32. package/crud/CrudRecordsControllerTests.js.map +1 -1
  33. package/index.d.ts +1 -0
  34. package/index.js +1 -0
  35. package/index.js.map +1 -1
  36. package/notifications/NotificationRecordsController.d.ts +1 -1
  37. package/notifications/NotificationRecordsController.js.map +1 -1
  38. package/package.json +4 -3
  39. package/packages/PackageRecordsController.d.ts +1 -1
  40. package/packages/PackageRecordsController.js.map +1 -1
  41. package/queue/MemoryQueue.d.ts +24 -0
  42. package/queue/MemoryQueue.js +45 -0
  43. package/queue/MemoryQueue.js.map +1 -0
  44. package/queue/Queue.d.ts +12 -0
  45. package/queue/Queue.js +19 -0
  46. package/queue/Queue.js.map +1 -0
  47. package/queue/index.d.ts +2 -0
  48. package/queue/index.js +19 -0
  49. package/queue/index.js.map +1 -0
  50. package/search/MemorySearchInterface.d.ts +25 -0
  51. package/search/MemorySearchInterface.js +192 -0
  52. package/search/MemorySearchInterface.js.map +1 -0
  53. package/search/MemorySearchRecordsStore.d.ts +21 -0
  54. package/search/MemorySearchRecordsStore.js +80 -0
  55. package/search/MemorySearchRecordsStore.js.map +1 -0
  56. package/search/SearchInterface.d.ts +329 -0
  57. package/search/SearchInterface.js +19 -0
  58. package/search/SearchInterface.js.map +1 -0
  59. package/search/SearchRecordsController.d.ts +491 -0
  60. package/search/SearchRecordsController.js +521 -0
  61. package/search/SearchRecordsController.js.map +1 -0
  62. package/search/SearchRecordsStore.d.ts +176 -0
  63. package/search/SearchRecordsStore.js +2 -0
  64. package/search/SearchRecordsStore.js.map +1 -0
  65. package/search/SearchSyncProcessor.d.ts +162 -0
  66. package/search/SearchSyncProcessor.js +256 -0
  67. package/search/SearchSyncProcessor.js.map +1 -0
  68. package/search/TypesenseSearchInterface.d.ts +18 -0
  69. package/search/TypesenseSearchInterface.js +171 -0
  70. package/search/TypesenseSearchInterface.js.map +1 -0
  71. package/search/index.d.ts +7 -0
  72. package/search/index.js +24 -0
  73. package/search/index.js.map +1 -0
  74. package/webhooks/WebhookRecordsController.d.ts +3 -3
  75. package/webhooks/WebhookRecordsController.js +3 -3
  76. package/webhooks/WebhookRecordsController.js.map +1 -1
  77. package/websockets/WebsocketController.js +30 -25
  78. package/websockets/WebsocketController.js.map +1 -1
@@ -0,0 +1,329 @@
1
+ import type { Result, SimpleError } from '@casual-simulation/aux-common';
2
+ /**
3
+ * Defines a basic interface that is able to interact with a search engine.
4
+ */
5
+ export interface SearchInterface {
6
+ /**
7
+ * The nodes that should be used by clients to connect to the search engine.
8
+ */
9
+ readonly nodes: SearchNode[];
10
+ /**
11
+ * Creates a new collection in the search engine.
12
+ * @param collection The collection to create.
13
+ */
14
+ createCollection(collection: SearchCollection): Promise<SearchCollectionInfo>;
15
+ /**
16
+ * Updates an existing collection in the search engine.
17
+ * @param collection The updated collection.
18
+ */
19
+ updateCollection(collection: UpdatedSearchCollection): Promise<SearchCollectionInfo>;
20
+ /**
21
+ * Drops a collection from the search engine.
22
+ * @param collectionName The name of the collection to drop.
23
+ */
24
+ dropCollection(collectionName: string): Promise<SearchCollectionInfo>;
25
+ /**
26
+ * Retrieves a collection from the search engine.
27
+ * @param collectionName The name of the collection to retrieve.
28
+ */
29
+ getCollection(collectionName: string): Promise<SearchCollectionInfo>;
30
+ /**
31
+ * Creates a new document in the specified collection.
32
+ * @param collectionName The name of the collection to create the document in.
33
+ * @param document The document to create.
34
+ * @param action The action to perform (create, upsert, update, emplace).
35
+ */
36
+ createDocument(collectionName: string, document: SearchDocument, action?: 'create' | 'upsert' | 'update' | 'emplace'): Promise<SearchDocumentInfo>;
37
+ /**
38
+ * Deletes a document from the specified collection.
39
+ * @param collectionName The name of the collection to delete the document from.
40
+ * @param documentId The ID of the document to delete.
41
+ */
42
+ deleteDocument(collectionName: string, documentId: string): Promise<Result<SearchDocumentInfo, SimpleError>>;
43
+ /**
44
+ * Creates a new API key for use with the search engine.
45
+ * @param apiKey The API key.
46
+ */
47
+ createApiKey(apiKey: SearchApiKeyData): Promise<SearchApiKey>;
48
+ /**
49
+ * Searches for documents in the specified collection.
50
+ * @param collectionName The name of the collection to search.
51
+ * @param query The search query.
52
+ */
53
+ searchCollection(collectionName: string, query: SearchQuery): Promise<SearchResult>;
54
+ }
55
+ export interface SearchCollection {
56
+ name: string;
57
+ fields: SearchCollectionField[];
58
+ defaultSortingField?: string;
59
+ }
60
+ export interface UpdatedSearchCollection extends SearchCollection {
61
+ fields: UpdatedSearchCollectionField[];
62
+ }
63
+ export interface SearchCollectionInfo extends Omit<SearchCollection, 'defaultSortingField'> {
64
+ numDocuments: number;
65
+ }
66
+ export interface SearchCollectionField {
67
+ /**
68
+ * The name of the field.
69
+ */
70
+ name: string;
71
+ /**
72
+ * The type of the field.
73
+ */
74
+ type: 'string' | 'string[]' | 'int32' | 'int32[]' | 'int64' | 'int64[]' | 'float' | 'float[]' | 'bool' | 'bool[]' | 'geopoint' | 'geopoint[]' | 'geopolygon' | 'object' | 'object[]' | 'string*' | 'image' | 'auto';
75
+ /**
76
+ * Enables faceting on the field.
77
+ *
78
+ * Defaults to `false`.
79
+ */
80
+ facet?: boolean;
81
+ /**
82
+ * When set to `true`, the field can have empty, null or missing values. Default: `false`.
83
+ */
84
+ optional?: boolean;
85
+ /**
86
+ * When set to `false`, the field will not be indexed in any in-memory index (e.g. search/sort/filter/facet). Default: `true`.
87
+ */
88
+ index?: boolean;
89
+ /**
90
+ * When set to `false`, the field value will not be stored on disk. Default: `true`.
91
+ */
92
+ store?: boolean;
93
+ /**
94
+ * When set to true, the field will be sortable. Default: `true` for numbers, `false` otherwise.
95
+ */
96
+ sort?: boolean;
97
+ /**
98
+ * When set to `true`, the field value can be infix-searched. Incurs significant memory overhead. Default: `false`.
99
+ */
100
+ infix?: boolean;
101
+ /**
102
+ * For configuring language specific tokenization, e.g. `jp` for Japanese. Default: `en` which also broadly supports most European languages.
103
+ */
104
+ locale?: string;
105
+ /**
106
+ * Values are stemmed before indexing in-memory. Default: `false`.
107
+ */
108
+ stem?: boolean;
109
+ }
110
+ export interface UpdatedSearchCollectionField extends SearchCollectionField {
111
+ drop?: boolean;
112
+ }
113
+ /**
114
+ * Defines a document that can be stored in a search collection.
115
+ *
116
+ * @dochash types/records/search
117
+ * @docname SearchDocument
118
+ */
119
+ export interface SearchDocument {
120
+ /**
121
+ * The ID of the document.
122
+ * If not provided, a new ID will be generated.
123
+ */
124
+ id?: string;
125
+ /**
126
+ * The properties of the document.
127
+ */
128
+ [key: string]: any;
129
+ }
130
+ export interface SearchDocumentInfo extends SearchDocument {
131
+ id: string;
132
+ }
133
+ export interface SearchApiKeyData {
134
+ actions: string[];
135
+ collections: string[];
136
+ description: string;
137
+ expiresAt?: number;
138
+ }
139
+ export interface SearchApiKey extends SearchApiKeyData {
140
+ id: number;
141
+ value: string;
142
+ expiresAt: number;
143
+ }
144
+ /**
145
+ * Defines a node that search clients can use to connect to the search engine.
146
+ *
147
+ * @dochash types/records/search
148
+ * @docname SearchNode
149
+ */
150
+ export interface SearchNode {
151
+ /**
152
+ * The host of the node.
153
+ */
154
+ host: string;
155
+ /**
156
+ * The port number of the node.
157
+ */
158
+ port: number;
159
+ /**
160
+ * The protocol to use when connecting to the node.
161
+ */
162
+ protocol?: 'http' | 'https';
163
+ }
164
+ /**
165
+ * Defines a search query that can be used to search through documents in a collection.
166
+ *
167
+ * @dochash types/records/search
168
+ * @docname SearchQuery
169
+ */
170
+ export interface SearchQuery {
171
+ /**
172
+ * The query text to search for in the collection.
173
+ *
174
+ * Use `q: "*"` (wildcard operator) as the search string to return all documents. This is typically useful when used in conjunction with `filter_by`.
175
+ *
176
+ * For example, to return all documents that match a filter, use: `q=*&filter_by=num_employees:10`.
177
+ *
178
+ * Surround words with double quotes to do an exact phrase search. Eg: Setting `q` to `"tennis ball"` (including the surrounding double quotes) will only return documents that have those two words in that exact order, without any typo tolerance.
179
+ *
180
+ * To exclude words in your query explicitly, prefix the word with the `-` operator, e.g. `q: 'electric car -tesla'`.
181
+ */
182
+ q: string;
183
+ /**
184
+ * One or more field names that should be queried against.
185
+ *
186
+ * Separate multiple fields with a comma: `company_name, country`.
187
+ *
188
+ * The order of the fields is important: a record that matches on a field earlier in the list is considered more relevant than a record matched on a field later in the list. So, in the example above, documents that match on the `company_name` field are ranked above documents matched on the country field.
189
+ *
190
+ * Only string and string array fields can be used for full-text search in the `query_by` parameter. When you specify an object or object array field, Typesense uses the object(s)' children's string and string array fields automatically. You can read more about nested object fields here.
191
+ */
192
+ queryBy: string;
193
+ /**
194
+ * Filter conditions for refining your search results.
195
+ *
196
+ * A field can be matched against one or more values.
197
+ *
198
+ * Examples:
199
+ * - `country: USA`
200
+ * - `country: [USA, UK]` returns documents that have country of USA OR UK.
201
+ *
202
+ * **Exact vs Non-Exact Filtering:**
203
+ *
204
+ * To match a string field's full value verbatim, you can use the `:=` (exact match) operator. For eg: `category := Shoe` will match documents with `category` set as `Shoe` and not documents with a `category` field set as `Shoe Rack`.
205
+ *
206
+ * Using the `:` (non-exact) operator will do a word-level partial match on the field, without taking token position into account (so is usually faster). Eg: `category:Shoe` will match records with `category` of `Shoe` or `Shoe Rack` or `Outdoor Shoe`.
207
+ *
208
+ * Tip: If you have a field that doesn't have any spaces in the values across any documents and want to filter on it, you want to use the `:` operator to improve performance, since it will avoid doing token position checks.
209
+ *
210
+ * **Escaping Special Characters:**
211
+ *
212
+ * You can also filter using multiple values and use the backtick character to denote a string literal: `category:= [`Running Shoes, Men`, `Sneaker (Men)`, Boots]`.
213
+ *
214
+ * **Negation:**
215
+ *
216
+ * Not equals / negation is supported via the `:!=` operator, e.g. `author:!=JK Rowling` or `id:!=[id1, id2]`. You can also negate multiple values: `author:!=[JK Rowling, Gilbert Patten]`
217
+ *
218
+ * To exclude results that _contains_ a specific string during filtering you can do `artist:! Jackson` will exclude all documents whose artist field value contains the word `jackson`.
219
+ *
220
+ * **Numeric Filtering:**
221
+ *
222
+ * Filter documents with numeric values between a min and max value, using the range operator `[min..max]` or using simple comparison operators `>`, `>=`, `<`, `<=`, `=`.
223
+ *
224
+ * You can enable `"range_index": true` on the numerical field schema for fast range queries (will incur additional memory usage for the index though).
225
+ *
226
+ * Examples:
227
+ * -`num_employees:<40`
228
+ * -`num_employees:[10..100]`
229
+ * -`num_employees:[<10, >100]`
230
+ * -`num_employees:[10..100, 140]` (Filter docs where value is between 10 to 100 or exactly 140).
231
+ * -`num_employees:!= [10, 100, 140]` (Filter docs where value is **NOT** 10, 100 or 140).
232
+ *
233
+ * **Multiple Conditions:**
234
+ *
235
+ * You can separate multiple conditions with the `&&` operator.
236
+ *
237
+ * Examples:
238
+ * - `num_employees:>100 && country: [USA, UK]`
239
+ * - `categories:=Shoes && categories:=Outdoor`
240
+ *
241
+ * To do ORs across different fields (eg: color is blue OR category is Shoe), you can use the `||` operator.
242
+ *
243
+ * Examples:
244
+ * - `color: blue || category: shoe`
245
+ * - `(color: blue || category: shoe) && in_stock: true`
246
+ *
247
+ * **Filtering Arrays:**
248
+ *
249
+ * filter_by can be used with array fields as well.
250
+ *
251
+ * For eg: If `genres` is a `string[]` field:
252
+ *
253
+ * - `genres:=[Rock, Pop]` will return documents where the genres array field contains `Rock OR Pop`.
254
+ * - `genres:=Rock && genres:=Acoustic` will return documents where the genres array field contains both `Rock AND Acoustic`.
255
+ *
256
+ * **Filtering Nested Arrays of Objects:**
257
+ *
258
+ * When filtering on fields inside nested array objects, you need to use a special syntax to ensure the filters are applied to the same object within the array. The syntax is: `<nested_field_parent>.{<filter_conditions>}`.
259
+ *
260
+ * For eg, if you have a document like this:
261
+ *
262
+ * {"name": "Pasta", "ingredients": [ {"name": "cheese", "concentration": 40}, {"name": "spinach", "concentration": 10} ] }
263
+ *
264
+ * To filter on all dishes that have cheese with a concentration of less than 30, you would do:
265
+ *
266
+ * filter_by: ingredients.{name:=cheese && concentration:<30}
267
+ *
268
+ * **Prefix filtering:**
269
+ *
270
+ * You can filter on records that begin with a given prefix string like this:
271
+ *
272
+ * `company_name: Acm*`
273
+ *
274
+ * This will will return documents where any of the words in the `company_name` field begin with `acm`, for e.g. a name like `Corporation of Acme`.
275
+ *
276
+ * You can combine the field-level match operator `:=` with prefix filtering like this:
277
+ *
278
+ * `name := S*`
279
+ *
280
+ * This will return documents that have name: `Steve Jobs` but not documents that have name: `Adam Stator`.
281
+ *
282
+ * **Geo Filtering:**
283
+ *
284
+ * Read more about [GeoSearch and filtering in this dedicated section](https://typesense.org/docs/29.0/api/geosearch.html).
285
+ *
286
+ * **Embedding Filters in API Keys:**
287
+ *
288
+ * You can embed the `filter_by` parameter (or parts of it) in a Scoped Search API Key to set up conditional access control for documents and/or enforce filters for any search requests that use that API key. Read more about [Scoped Search API Key](https://typesense.org/docs/29.0/api/api-keys.html#generate-scoped-search-key) in this dedicated section.
289
+ */
290
+ filterBy?: string;
291
+ /**
292
+ * A parameter that controls the search query.
293
+ */
294
+ [key: string]: any;
295
+ }
296
+ export type SearchResult = Result<{
297
+ found: number;
298
+ outOf: number;
299
+ page: number;
300
+ searchTimeMs: number;
301
+ hits: SearchHit[];
302
+ }, SimpleError>;
303
+ /**
304
+ * Defines the interface for a search hit returned by the search engine.
305
+ *
306
+ * @dochash types/records/search
307
+ * @docname SearchHit
308
+ */
309
+ export interface SearchHit {
310
+ document: SearchDocument;
311
+ highlights?: SearchHighlight[];
312
+ highlight: SearchHighlight;
313
+ textMatch?: number;
314
+ }
315
+ /**
316
+ * Defines the interface for a search highlight returned by the search engine.
317
+ *
318
+ * @dochash types/records/search
319
+ * @docname SearchHighlight
320
+ */
321
+ export interface SearchHighlight {
322
+ field: string;
323
+ indices: [number, number];
324
+ snippet: string;
325
+ snippets?: string[];
326
+ matchedTokens: string[][] | string[];
327
+ value?: string;
328
+ }
329
+ //# sourceMappingURL=SearchInterface.d.ts.map
@@ -0,0 +1,19 @@
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
+ export {};
19
+ //# sourceMappingURL=SearchInterface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchInterface.js","sourceRoot":"","sources":["SearchInterface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG"}