@goatlab/typesense 0.0.2
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/LICENSE +21 -0
- package/dist/TypesenseApi.d.ts +229 -0
- package/dist/TypesenseApi.js +423 -0
- package/dist/TypesenseApi.js.map +1 -0
- package/dist/actions/admin/getCollectionStats.d.ts +3 -0
- package/dist/actions/admin/getCollectionStats.js +8 -0
- package/dist/actions/admin/getCollectionStats.js.map +1 -0
- package/dist/actions/admin/health.d.ts +4 -0
- package/dist/actions/admin/health.js +22 -0
- package/dist/actions/admin/health.js.map +1 -0
- package/dist/actions/admin/metrics.d.ts +4 -0
- package/dist/actions/admin/metrics.js +11 -0
- package/dist/actions/admin/metrics.js.map +1 -0
- package/dist/actions/aliases/createOrUpdateAlias.d.ts +3 -0
- package/dist/actions/aliases/createOrUpdateAlias.js +10 -0
- package/dist/actions/aliases/createOrUpdateAlias.js.map +1 -0
- package/dist/actions/aliases/deleteAlias.d.ts +3 -0
- package/dist/actions/aliases/deleteAlias.js +7 -0
- package/dist/actions/aliases/deleteAlias.js.map +1 -0
- package/dist/actions/aliases/getAlias.d.ts +3 -0
- package/dist/actions/aliases/getAlias.js +7 -0
- package/dist/actions/aliases/getAlias.js.map +1 -0
- package/dist/actions/aliases/listAliases.d.ts +3 -0
- package/dist/actions/aliases/listAliases.js +7 -0
- package/dist/actions/aliases/listAliases.js.map +1 -0
- package/dist/actions/collections/createCollection.d.ts +3 -0
- package/dist/actions/collections/createCollection.js +18 -0
- package/dist/actions/collections/createCollection.js.map +1 -0
- package/dist/actions/collections/deleteCollection.d.ts +3 -0
- package/dist/actions/collections/deleteCollection.js +13 -0
- package/dist/actions/collections/deleteCollection.js.map +1 -0
- package/dist/actions/collections/getCollection.d.ts +3 -0
- package/dist/actions/collections/getCollection.js +11 -0
- package/dist/actions/collections/getCollection.js.map +1 -0
- package/dist/actions/collections/getOrCreateCollection.d.ts +3 -0
- package/dist/actions/collections/getOrCreateCollection.js +19 -0
- package/dist/actions/collections/getOrCreateCollection.js.map +1 -0
- package/dist/actions/collections/listCollections.d.ts +3 -0
- package/dist/actions/collections/listCollections.js +7 -0
- package/dist/actions/collections/listCollections.js.map +1 -0
- package/dist/actions/collections/updateCollection.d.ts +3 -0
- package/dist/actions/collections/updateCollection.js +14 -0
- package/dist/actions/collections/updateCollection.js.map +1 -0
- package/dist/actions/documents/clearCollection.d.ts +5 -0
- package/dist/actions/documents/clearCollection.js +11 -0
- package/dist/actions/documents/clearCollection.js.map +1 -0
- package/dist/actions/documents/deleteByFilter.d.ts +5 -0
- package/dist/actions/documents/deleteByFilter.js +15 -0
- package/dist/actions/documents/deleteByFilter.js.map +1 -0
- package/dist/actions/documents/deleteDocument.d.ts +3 -0
- package/dist/actions/documents/deleteDocument.js +14 -0
- package/dist/actions/documents/deleteDocument.js.map +1 -0
- package/dist/actions/documents/exportDocuments.d.ts +5 -0
- package/dist/actions/documents/exportDocuments.js +51 -0
- package/dist/actions/documents/exportDocuments.js.map +1 -0
- package/dist/actions/documents/getDocumentById.d.ts +3 -0
- package/dist/actions/documents/getDocumentById.js +12 -0
- package/dist/actions/documents/getDocumentById.js.map +1 -0
- package/dist/actions/documents/importDocuments.d.ts +4 -0
- package/dist/actions/documents/importDocuments.js +58 -0
- package/dist/actions/documents/importDocuments.js.map +1 -0
- package/dist/actions/documents/insertDocument.d.ts +3 -0
- package/dist/actions/documents/insertDocument.js +38 -0
- package/dist/actions/documents/insertDocument.js.map +1 -0
- package/dist/actions/documents/updateDocument.d.ts +5 -0
- package/dist/actions/documents/updateDocument.js +15 -0
- package/dist/actions/documents/updateDocument.js.map +1 -0
- package/dist/actions/documents/upsertDocument.d.ts +3 -0
- package/dist/actions/documents/upsertDocument.js +16 -0
- package/dist/actions/documents/upsertDocument.js.map +1 -0
- package/dist/actions/overrides/deleteOverride.d.ts +3 -0
- package/dist/actions/overrides/deleteOverride.js +8 -0
- package/dist/actions/overrides/deleteOverride.js.map +1 -0
- package/dist/actions/overrides/getOverride.d.ts +3 -0
- package/dist/actions/overrides/getOverride.js +8 -0
- package/dist/actions/overrides/getOverride.js.map +1 -0
- package/dist/actions/overrides/listOverrides.d.ts +5 -0
- package/dist/actions/overrides/listOverrides.js +8 -0
- package/dist/actions/overrides/listOverrides.js.map +1 -0
- package/dist/actions/overrides/upsertOverride.d.ts +3 -0
- package/dist/actions/overrides/upsertOverride.js +11 -0
- package/dist/actions/overrides/upsertOverride.js.map +1 -0
- package/dist/actions/presets/deletePreset.d.ts +3 -0
- package/dist/actions/presets/deletePreset.js +7 -0
- package/dist/actions/presets/deletePreset.js.map +1 -0
- package/dist/actions/presets/getPreset.d.ts +3 -0
- package/dist/actions/presets/getPreset.js +7 -0
- package/dist/actions/presets/getPreset.js.map +1 -0
- package/dist/actions/presets/listPresets.d.ts +5 -0
- package/dist/actions/presets/listPresets.js +7 -0
- package/dist/actions/presets/listPresets.js.map +1 -0
- package/dist/actions/presets/upsertPreset.d.ts +3 -0
- package/dist/actions/presets/upsertPreset.js +10 -0
- package/dist/actions/presets/upsertPreset.js.map +1 -0
- package/dist/actions/search/multiSearch.d.ts +3 -0
- package/dist/actions/search/multiSearch.js +10 -0
- package/dist/actions/search/multiSearch.js.map +1 -0
- package/dist/actions/search/search.d.ts +5 -0
- package/dist/actions/search/search.js +19 -0
- package/dist/actions/search/search.js.map +1 -0
- package/dist/actions/synonyms/deleteSynonym.d.ts +3 -0
- package/dist/actions/synonyms/deleteSynonym.js +8 -0
- package/dist/actions/synonyms/deleteSynonym.js.map +1 -0
- package/dist/actions/synonyms/getSynonym.d.ts +3 -0
- package/dist/actions/synonyms/getSynonym.js +8 -0
- package/dist/actions/synonyms/getSynonym.js.map +1 -0
- package/dist/actions/synonyms/listSynonyms.d.ts +5 -0
- package/dist/actions/synonyms/listSynonyms.js +8 -0
- package/dist/actions/synonyms/listSynonyms.js.map +1 -0
- package/dist/actions/synonyms/upsertSynonym.d.ts +3 -0
- package/dist/actions/synonyms/upsertSynonym.js +11 -0
- package/dist/actions/synonyms/upsertSynonym.js.map +1 -0
- package/dist/components/export-formatter.d.ts +16 -0
- package/dist/components/export-formatter.js +226 -0
- package/dist/components/export-formatter.js.map +1 -0
- package/dist/components/http-client.d.ts +50 -0
- package/dist/components/http-client.js +149 -0
- package/dist/components/http-client.js.map +1 -0
- package/dist/components/resilience-policy.d.ts +33 -0
- package/dist/components/resilience-policy.js +115 -0
- package/dist/components/resilience-policy.js.map +1 -0
- package/dist/components/schema-manager.d.ts +30 -0
- package/dist/components/schema-manager.js +227 -0
- package/dist/components/schema-manager.js.map +1 -0
- package/dist/components/typesense.filter-builder.d.ts +127 -0
- package/dist/components/typesense.filter-builder.js +216 -0
- package/dist/components/typesense.filter-builder.js.map +1 -0
- package/dist/examples/multitenancy-example.d.ts +4 -0
- package/dist/examples/multitenancy-example.js +182 -0
- package/dist/examples/multitenancy-example.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/tests/const.d.ts +6 -0
- package/dist/tests/const.js +22 -0
- package/dist/tests/const.js.map +1 -0
- package/dist/tests/typesense.d.ts +2 -0
- package/dist/tests/typesense.js +24 -0
- package/dist/tests/typesense.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/typesense.model.d.ts +455 -0
- package/dist/typesense.model.js +98 -0
- package/dist/typesense.model.js.map +1 -0
- package/dist/utils/tenant.d.ts +48 -0
- package/dist/utils/tenant.js +89 -0
- package/dist/utils/tenant.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe filter builder for Typesense to prevent injection and typos
|
|
3
|
+
*/
|
|
4
|
+
export declare class TypesenseFilterBuilder {
|
|
5
|
+
private filters;
|
|
6
|
+
/**
|
|
7
|
+
* Add an equality filter
|
|
8
|
+
* @param field - Field name to filter on
|
|
9
|
+
* @param value - Value to match
|
|
10
|
+
*/
|
|
11
|
+
equals(field: string, value: string | number | boolean): this;
|
|
12
|
+
/**
|
|
13
|
+
* Add a not-equals filter
|
|
14
|
+
* @param field - Field name to filter on
|
|
15
|
+
* @param value - Value to not match
|
|
16
|
+
*/
|
|
17
|
+
notEquals(field: string, value: string | number | boolean): this;
|
|
18
|
+
/**
|
|
19
|
+
* Add an IN filter for matching multiple values
|
|
20
|
+
* @param field - Field name to filter on
|
|
21
|
+
* @param values - Array of values to match
|
|
22
|
+
*/
|
|
23
|
+
in(field: string, values: Array<string | number>): this;
|
|
24
|
+
/**
|
|
25
|
+
* Add a NOT IN filter
|
|
26
|
+
* @param field - Field name to filter on
|
|
27
|
+
* @param values - Array of values to not match
|
|
28
|
+
*/
|
|
29
|
+
notIn(field: string, values: Array<string | number>): this;
|
|
30
|
+
/**
|
|
31
|
+
* Add a greater than filter (numeric fields only)
|
|
32
|
+
* @param field - Field name to filter on
|
|
33
|
+
* @param value - Value to compare against
|
|
34
|
+
*/
|
|
35
|
+
greaterThan(field: string, value: number): this;
|
|
36
|
+
/**
|
|
37
|
+
* Add a greater than or equal filter (numeric fields only)
|
|
38
|
+
* @param field - Field name to filter on
|
|
39
|
+
* @param value - Value to compare against
|
|
40
|
+
*/
|
|
41
|
+
greaterThanOrEqual(field: string, value: number): this;
|
|
42
|
+
/**
|
|
43
|
+
* Add a less than filter (numeric fields only)
|
|
44
|
+
* @param field - Field name to filter on
|
|
45
|
+
* @param value - Value to compare against
|
|
46
|
+
*/
|
|
47
|
+
lessThan(field: string, value: number): this;
|
|
48
|
+
/**
|
|
49
|
+
* Add a less than or equal filter (numeric fields only)
|
|
50
|
+
* @param field - Field name to filter on
|
|
51
|
+
* @param value - Value to compare against
|
|
52
|
+
*/
|
|
53
|
+
lessThanOrEqual(field: string, value: number): this;
|
|
54
|
+
/**
|
|
55
|
+
* Add a range filter (numeric fields only)
|
|
56
|
+
* @param field - Field name to filter on
|
|
57
|
+
* @param min - Minimum value (inclusive)
|
|
58
|
+
* @param max - Maximum value (inclusive)
|
|
59
|
+
*/
|
|
60
|
+
range(field: string, min: number, max: number): this;
|
|
61
|
+
/**
|
|
62
|
+
* Add a contains filter (string fields only)
|
|
63
|
+
* @param field - Field name to filter on
|
|
64
|
+
* @param value - Value to search for
|
|
65
|
+
*/
|
|
66
|
+
contains(field: string, value: string): this;
|
|
67
|
+
/**
|
|
68
|
+
* Add a starts with filter (string fields only)
|
|
69
|
+
* @param field - Field name to filter on
|
|
70
|
+
* @param value - Prefix to match
|
|
71
|
+
*/
|
|
72
|
+
startsWith(field: string, value: string): this;
|
|
73
|
+
/**
|
|
74
|
+
* Add a ends with filter (string fields only)
|
|
75
|
+
* @param field - Field name to filter on
|
|
76
|
+
* @param value - Suffix to match
|
|
77
|
+
*/
|
|
78
|
+
endsWith(field: string, value: string): this;
|
|
79
|
+
/**
|
|
80
|
+
* Add an exists/not null filter
|
|
81
|
+
* @param field - Field name to check
|
|
82
|
+
*/
|
|
83
|
+
exists(field: string): this;
|
|
84
|
+
/**
|
|
85
|
+
* Add a not exists/null filter
|
|
86
|
+
* @param field - Field name to check
|
|
87
|
+
*/
|
|
88
|
+
notExists(field: string): this;
|
|
89
|
+
/**
|
|
90
|
+
* Group filters with AND logic
|
|
91
|
+
* @param callback - Callback to build grouped filters
|
|
92
|
+
*/
|
|
93
|
+
and(callback: (builder: TypesenseFilterBuilder) => void): this;
|
|
94
|
+
/**
|
|
95
|
+
* Group filters with OR logic
|
|
96
|
+
* @param callback - Callback to build grouped filters
|
|
97
|
+
*/
|
|
98
|
+
or(callback: (builder: TypesenseFilterBuilder) => void): this;
|
|
99
|
+
/**
|
|
100
|
+
* Add a raw filter expression (use with caution)
|
|
101
|
+
* @param expression - Raw filter expression
|
|
102
|
+
*/
|
|
103
|
+
raw(expression: string): this;
|
|
104
|
+
/**
|
|
105
|
+
* Build the final filter string
|
|
106
|
+
* @returns The constructed filter string
|
|
107
|
+
*/
|
|
108
|
+
build(): string;
|
|
109
|
+
/**
|
|
110
|
+
* Reset the builder
|
|
111
|
+
*/
|
|
112
|
+
reset(): this;
|
|
113
|
+
/**
|
|
114
|
+
* Escape field name to prevent injection
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
private escapeField;
|
|
118
|
+
/**
|
|
119
|
+
* Escape value to prevent injection
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
private escapeValue;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create a new filter builder instance
|
|
126
|
+
*/
|
|
127
|
+
export declare function filterBuilder(): TypesenseFilterBuilder;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// npx vitest run ./src/services/search/typesense.filter-builder.test.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TypesenseFilterBuilder = void 0;
|
|
5
|
+
exports.filterBuilder = filterBuilder;
|
|
6
|
+
/**
|
|
7
|
+
* Safe filter builder for Typesense to prevent injection and typos
|
|
8
|
+
*/
|
|
9
|
+
class TypesenseFilterBuilder {
|
|
10
|
+
filters = [];
|
|
11
|
+
/**
|
|
12
|
+
* Add an equality filter
|
|
13
|
+
* @param field - Field name to filter on
|
|
14
|
+
* @param value - Value to match
|
|
15
|
+
*/
|
|
16
|
+
equals(field, value) {
|
|
17
|
+
this.filters.push(`${this.escapeField(field)}:=${this.escapeValue(value)}`);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Add a not-equals filter
|
|
22
|
+
* @param field - Field name to filter on
|
|
23
|
+
* @param value - Value to not match
|
|
24
|
+
*/
|
|
25
|
+
notEquals(field, value) {
|
|
26
|
+
this.filters.push(`${this.escapeField(field)}:!=${this.escapeValue(value)}`);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Add an IN filter for matching multiple values
|
|
31
|
+
* @param field - Field name to filter on
|
|
32
|
+
* @param values - Array of values to match
|
|
33
|
+
*/
|
|
34
|
+
in(field, values) {
|
|
35
|
+
const escapedValues = values.map(v => this.escapeValue(v)).join(', ');
|
|
36
|
+
this.filters.push(`${this.escapeField(field)}:=[${escapedValues}]`);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Add a NOT IN filter
|
|
41
|
+
* @param field - Field name to filter on
|
|
42
|
+
* @param values - Array of values to not match
|
|
43
|
+
*/
|
|
44
|
+
notIn(field, values) {
|
|
45
|
+
const escapedValues = values.map(v => this.escapeValue(v)).join(', ');
|
|
46
|
+
this.filters.push(`${this.escapeField(field)}:!=[${escapedValues}]`);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Add a greater than filter (numeric fields only)
|
|
51
|
+
* @param field - Field name to filter on
|
|
52
|
+
* @param value - Value to compare against
|
|
53
|
+
*/
|
|
54
|
+
greaterThan(field, value) {
|
|
55
|
+
this.filters.push(`${this.escapeField(field)}:>${value}`);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Add a greater than or equal filter (numeric fields only)
|
|
60
|
+
* @param field - Field name to filter on
|
|
61
|
+
* @param value - Value to compare against
|
|
62
|
+
*/
|
|
63
|
+
greaterThanOrEqual(field, value) {
|
|
64
|
+
this.filters.push(`${this.escapeField(field)}:>=${value}`);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Add a less than filter (numeric fields only)
|
|
69
|
+
* @param field - Field name to filter on
|
|
70
|
+
* @param value - Value to compare against
|
|
71
|
+
*/
|
|
72
|
+
lessThan(field, value) {
|
|
73
|
+
this.filters.push(`${this.escapeField(field)}:<${value}`);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Add a less than or equal filter (numeric fields only)
|
|
78
|
+
* @param field - Field name to filter on
|
|
79
|
+
* @param value - Value to compare against
|
|
80
|
+
*/
|
|
81
|
+
lessThanOrEqual(field, value) {
|
|
82
|
+
this.filters.push(`${this.escapeField(field)}:<=${value}`);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Add a range filter (numeric fields only)
|
|
87
|
+
* @param field - Field name to filter on
|
|
88
|
+
* @param min - Minimum value (inclusive)
|
|
89
|
+
* @param max - Maximum value (inclusive)
|
|
90
|
+
*/
|
|
91
|
+
range(field, min, max) {
|
|
92
|
+
this.filters.push(`${this.escapeField(field)}:>=${min} && ${this.escapeField(field)}:<=${max}`);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Add a contains filter (string fields only)
|
|
97
|
+
* @param field - Field name to filter on
|
|
98
|
+
* @param value - Value to search for
|
|
99
|
+
*/
|
|
100
|
+
contains(field, value) {
|
|
101
|
+
this.filters.push(`${this.escapeField(field)}:*${this.escapeValue(value)}*`);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Add a starts with filter (string fields only)
|
|
106
|
+
* @param field - Field name to filter on
|
|
107
|
+
* @param value - Prefix to match
|
|
108
|
+
*/
|
|
109
|
+
startsWith(field, value) {
|
|
110
|
+
this.filters.push(`${this.escapeField(field)}:${this.escapeValue(value)}*`);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Add a ends with filter (string fields only)
|
|
115
|
+
* @param field - Field name to filter on
|
|
116
|
+
* @param value - Suffix to match
|
|
117
|
+
*/
|
|
118
|
+
endsWith(field, value) {
|
|
119
|
+
this.filters.push(`${this.escapeField(field)}:*${this.escapeValue(value)}`);
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Add an exists/not null filter
|
|
124
|
+
* @param field - Field name to check
|
|
125
|
+
*/
|
|
126
|
+
exists(field) {
|
|
127
|
+
this.filters.push(`${this.escapeField(field)}:!=null`);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Add a not exists/null filter
|
|
132
|
+
* @param field - Field name to check
|
|
133
|
+
*/
|
|
134
|
+
notExists(field) {
|
|
135
|
+
this.filters.push(`${this.escapeField(field)}:=null`);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Group filters with AND logic
|
|
140
|
+
* @param callback - Callback to build grouped filters
|
|
141
|
+
*/
|
|
142
|
+
and(callback) {
|
|
143
|
+
const subBuilder = new TypesenseFilterBuilder();
|
|
144
|
+
callback(subBuilder);
|
|
145
|
+
const subFilter = subBuilder.build();
|
|
146
|
+
if (subFilter) {
|
|
147
|
+
this.filters.push(`(${subFilter})`);
|
|
148
|
+
}
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Group filters with OR logic
|
|
153
|
+
* @param callback - Callback to build grouped filters
|
|
154
|
+
*/
|
|
155
|
+
or(callback) {
|
|
156
|
+
const subBuilder = new TypesenseFilterBuilder();
|
|
157
|
+
callback(subBuilder);
|
|
158
|
+
const subFilters = subBuilder.filters;
|
|
159
|
+
if (subFilters.length > 0) {
|
|
160
|
+
this.filters.push(`(${subFilters.join(' || ')})`);
|
|
161
|
+
}
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Add a raw filter expression (use with caution)
|
|
166
|
+
* @param expression - Raw filter expression
|
|
167
|
+
*/
|
|
168
|
+
raw(expression) {
|
|
169
|
+
this.filters.push(expression);
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Build the final filter string
|
|
174
|
+
* @returns The constructed filter string
|
|
175
|
+
*/
|
|
176
|
+
build() {
|
|
177
|
+
return this.filters.join(' && ');
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Reset the builder
|
|
181
|
+
*/
|
|
182
|
+
reset() {
|
|
183
|
+
this.filters = [];
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Escape field name to prevent injection
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
escapeField(field) {
|
|
191
|
+
// Field names in Typesense can contain alphanumeric characters and underscores
|
|
192
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(field)) {
|
|
193
|
+
throw new Error(`Invalid field name: ${field}. Field names must start with a letter or underscore and contain only alphanumeric characters and underscores.`);
|
|
194
|
+
}
|
|
195
|
+
return field;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Escape value to prevent injection
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
escapeValue(value) {
|
|
202
|
+
if (typeof value === 'string') {
|
|
203
|
+
// Escape backslashes first, then quotes
|
|
204
|
+
return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
205
|
+
}
|
|
206
|
+
return String(value);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exports.TypesenseFilterBuilder = TypesenseFilterBuilder;
|
|
210
|
+
/**
|
|
211
|
+
* Create a new filter builder instance
|
|
212
|
+
*/
|
|
213
|
+
function filterBuilder() {
|
|
214
|
+
return new TypesenseFilterBuilder();
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=typesense.filter-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typesense.filter-builder.js","sourceRoot":"","sources":["../../src/components/typesense.filter-builder.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;AAsOxE,sCAEC;AAtOD;;GAEG;AACH,MAAa,sBAAsB;IACzB,OAAO,GAAa,EAAE,CAAA;IAE9B;;;;OAIG;IACH,MAAM,CAAC,KAAa,EAAE,KAAgC;QACpD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,WAAW,CAAC,KAAK,CA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AC,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACnD,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,UAAkB;QACpB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAC7B,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAClC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;OAGG;IACK,WAAW,CAAC,KAAa;QAC/B,+EAA+E;QAC/E,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,uBAAuB,KAAK,gHAAgH,CAAC,CAAA;QAC/J,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;OAGG;IACK,WAAW,CAAC,KAAgC;QAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,wCAAwC;YACxC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAA;QACjE,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;CACF;AA5ND,wDA4NC;AAED;;GAEG;AACH,SAAgB,aAAa;IAC3B,OAAO,IAAI,sBAAsB,EAAE,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example of using TypesenseApi with multitenancy support
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const TypesenseApi_1 = require("../TypesenseApi");
|
|
7
|
+
const tenant_1 = require("../utils/tenant");
|
|
8
|
+
// Example 1: Creating separate API instances for different tenants
|
|
9
|
+
async function example1() {
|
|
10
|
+
// API instance for tenant "acme"
|
|
11
|
+
const acmeApi = new TypesenseApi_1.TypesenseApi({
|
|
12
|
+
prefixUrl: 'http://localhost:8108',
|
|
13
|
+
token: 'xyz',
|
|
14
|
+
tenantId: 'acme',
|
|
15
|
+
collectionName: 'products'
|
|
16
|
+
});
|
|
17
|
+
// API instance for tenant "globex"
|
|
18
|
+
const globexApi = new TypesenseApi_1.TypesenseApi({
|
|
19
|
+
prefixUrl: 'http://localhost:8108',
|
|
20
|
+
token: 'xyz',
|
|
21
|
+
tenantId: 'globex',
|
|
22
|
+
collectionName: 'products'
|
|
23
|
+
});
|
|
24
|
+
// Define schema
|
|
25
|
+
const productSchema = {
|
|
26
|
+
name: 'products',
|
|
27
|
+
fields: [
|
|
28
|
+
{ name: 'name', type: 'string' },
|
|
29
|
+
{ name: 'price', type: 'float' },
|
|
30
|
+
{ name: 'category', type: 'string', facet: true }
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
// Create collections - each tenant gets their own prefixed collection
|
|
34
|
+
// This creates "acme__products" collection
|
|
35
|
+
await acmeApi.collections.create(productSchema);
|
|
36
|
+
// This creates "globex__products" collection
|
|
37
|
+
await globexApi.collections.create(productSchema);
|
|
38
|
+
// Insert documents - completely isolated between tenants
|
|
39
|
+
await acmeApi.documents.insert({
|
|
40
|
+
id: '1',
|
|
41
|
+
name: 'Acme Widget',
|
|
42
|
+
price: 19.99,
|
|
43
|
+
category: 'widgets'
|
|
44
|
+
});
|
|
45
|
+
await globexApi.documents.insert({
|
|
46
|
+
id: '1', // Same ID is fine - different collection
|
|
47
|
+
name: 'Globex Gadget',
|
|
48
|
+
price: 29.99,
|
|
49
|
+
category: 'gadgets'
|
|
50
|
+
});
|
|
51
|
+
// Search - each tenant only sees their own data
|
|
52
|
+
const acmeResults = await acmeApi.search.text({
|
|
53
|
+
q: '*',
|
|
54
|
+
query_by: 'name'
|
|
55
|
+
});
|
|
56
|
+
console.log('Acme products:', acmeResults.hits); // Only Acme Widget
|
|
57
|
+
const globexResults = await globexApi.search.text({
|
|
58
|
+
q: '*',
|
|
59
|
+
query_by: 'name'
|
|
60
|
+
});
|
|
61
|
+
console.log('Globex products:', globexResults.hits); // Only Globex Gadget
|
|
62
|
+
}
|
|
63
|
+
// Example 2: Admin operations across tenants
|
|
64
|
+
async function example2() {
|
|
65
|
+
const adminApi = new TypesenseApi_1.TypesenseApi({
|
|
66
|
+
prefixUrl: 'http://localhost:8108',
|
|
67
|
+
token: 'xyz',
|
|
68
|
+
tenantId: 'acme'
|
|
69
|
+
});
|
|
70
|
+
// List all collections for the tenant
|
|
71
|
+
const tenantCollections = await adminApi.listTenantCollections();
|
|
72
|
+
console.log('Acme collections:', tenantCollections);
|
|
73
|
+
// Output: ['acme__products', 'acme__users', 'acme__orders']
|
|
74
|
+
// Get base collection names (without tenant prefix)
|
|
75
|
+
const baseNames = await adminApi.listTenantBaseCollectionNames();
|
|
76
|
+
console.log('Base collection names:', baseNames);
|
|
77
|
+
// Output: ['products', 'users', 'orders']
|
|
78
|
+
// Check if a specific collection exists
|
|
79
|
+
const exists = await adminApi.tenantCollectionExists('products');
|
|
80
|
+
console.log('Products collection exists:', exists);
|
|
81
|
+
// Delete all tenant data (use with caution!)
|
|
82
|
+
// await adminApi.deleteAllTenantCollections()
|
|
83
|
+
}
|
|
84
|
+
// Example 3: Working with multiple collections per tenant
|
|
85
|
+
async function example3() {
|
|
86
|
+
const api = new TypesenseApi_1.TypesenseApi({
|
|
87
|
+
prefixUrl: 'http://localhost:8108',
|
|
88
|
+
token: 'xyz',
|
|
89
|
+
tenantId: 'acme'
|
|
90
|
+
});
|
|
91
|
+
// Create multiple collections for the tenant
|
|
92
|
+
await api.collections.create({
|
|
93
|
+
name: 'users',
|
|
94
|
+
fields: [
|
|
95
|
+
{ name: 'email', type: 'string' },
|
|
96
|
+
{ name: 'name', type: 'string' }
|
|
97
|
+
]
|
|
98
|
+
});
|
|
99
|
+
await api.collections.create({
|
|
100
|
+
name: 'orders',
|
|
101
|
+
fields: [
|
|
102
|
+
{ name: 'order_id', type: 'string' },
|
|
103
|
+
{ name: 'user_email', type: 'string' },
|
|
104
|
+
{ name: 'total', type: 'float' }
|
|
105
|
+
]
|
|
106
|
+
});
|
|
107
|
+
// Work with different collections by changing the context
|
|
108
|
+
const userApi = new TypesenseApi_1.TypesenseApi({
|
|
109
|
+
prefixUrl: 'http://localhost:8108',
|
|
110
|
+
token: 'xyz',
|
|
111
|
+
tenantId: 'acme',
|
|
112
|
+
collectionName: 'users'
|
|
113
|
+
});
|
|
114
|
+
const orderApi = new TypesenseApi_1.TypesenseApi({
|
|
115
|
+
prefixUrl: 'http://localhost:8108',
|
|
116
|
+
token: 'xyz',
|
|
117
|
+
tenantId: 'acme',
|
|
118
|
+
collectionName: 'orders'
|
|
119
|
+
});
|
|
120
|
+
// Insert data into different collections
|
|
121
|
+
await userApi.documents.insert({
|
|
122
|
+
id: 'user-1',
|
|
123
|
+
email: 'john@acme.com',
|
|
124
|
+
name: 'John Doe'
|
|
125
|
+
});
|
|
126
|
+
await orderApi.documents.insert({
|
|
127
|
+
id: 'ORD-001',
|
|
128
|
+
order_id: 'ORD-001',
|
|
129
|
+
user_email: 'john@acme.com',
|
|
130
|
+
total: 99.99
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
// Example 4: Migrating existing non-tenant data
|
|
134
|
+
async function example4() {
|
|
135
|
+
// API without tenant (legacy mode)
|
|
136
|
+
const legacyApi = new TypesenseApi_1.TypesenseApi({
|
|
137
|
+
prefixUrl: 'http://localhost:8108',
|
|
138
|
+
token: 'xyz',
|
|
139
|
+
collectionName: 'products'
|
|
140
|
+
});
|
|
141
|
+
// API with tenant
|
|
142
|
+
const tenantApi = new TypesenseApi_1.TypesenseApi({
|
|
143
|
+
prefixUrl: 'http://localhost:8108',
|
|
144
|
+
token: 'xyz',
|
|
145
|
+
tenantId: 'legacy',
|
|
146
|
+
collectionName: 'products'
|
|
147
|
+
});
|
|
148
|
+
// Export from legacy collection
|
|
149
|
+
const legacyData = await legacyApi.documents.export();
|
|
150
|
+
// Create new tenant collection
|
|
151
|
+
const schema = await legacyApi.collections.get('products');
|
|
152
|
+
await tenantApi.collections.create(schema);
|
|
153
|
+
// Import into tenant collection
|
|
154
|
+
await tenantApi.documents.import(legacyData);
|
|
155
|
+
}
|
|
156
|
+
// Example 5: Using tenant utilities directly
|
|
157
|
+
async function example5() {
|
|
158
|
+
// Validate tenant ID
|
|
159
|
+
try {
|
|
160
|
+
const tenantId = (0, tenant_1.sanitizeTenantId)('ACME-Corp');
|
|
161
|
+
console.log('Sanitized:', tenantId); // 'acme-corp'
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error('Invalid tenant ID:', error.message);
|
|
165
|
+
}
|
|
166
|
+
// Create fully qualified collection name
|
|
167
|
+
const fqcn = (0, tenant_1.createFQCN)('acme', 'products');
|
|
168
|
+
console.log('FQCN:', fqcn); // 'acme__products'
|
|
169
|
+
// Parse collection name
|
|
170
|
+
const parsed = (0, tenant_1.parseFQCN)('acme__products');
|
|
171
|
+
console.log('Parsed:', parsed); // { tenantId: 'acme', baseCollectionName: 'products' }
|
|
172
|
+
// Filter collections by tenant
|
|
173
|
+
const allCollections = [
|
|
174
|
+
'acme__products',
|
|
175
|
+
'acme__users',
|
|
176
|
+
'globex__products',
|
|
177
|
+
'legacy_collection'
|
|
178
|
+
];
|
|
179
|
+
const acmeCollections = (0, tenant_1.filterCollectionsByTenant)(allCollections, 'acme');
|
|
180
|
+
console.log('Acme collections:', acmeCollections); // ['acme__products', 'acme__users']
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=multitenancy-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multitenancy-example.js","sourceRoot":"","s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,CAAC;IAED,yCAAyC;IACzC,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC3C,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA,CAAC,mBAAmB;IAE9C,wBAAwB;IACxB,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC,gBAAgB,CAAC,CAAA;IAC1C,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA,CAAC,uDAAuD;IAEtF,+BAA+B;IAC/B,MAAM,cAAc,GAAG;QACrB,gBAAgB;QAChB,aAAa;QACb,kBAAkB;QAClB,mBAAmB;KACpB,CAAA;IACD,MAAM,eAAe,GAAG,IAAA,kCAAyB,EAAC,cAAc,EAAE,MAAM,CAAC,CAAA;IACzE,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAA,CAAC,oCAAoC;AACxF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { TypesenseApi } from './TypesenseApi';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export * from './typesense.model';
|
|
4
|
+
export { TypesenseHttpClient } from './components/http-client';
|
|
5
|
+
export { ResiliencePolicy } from './components/resilience-policy';
|
|
6
|
+
export { CollectionSchemaManager } from './components/schema-manager';
|
|
7
|
+
export { ExportFormatter } from './components/export-formatter';
|
|
8
|
+
export { TypesenseFilterBuilder } from './components/typesense.filter-builder';
|
|
9
|
+
export * from './TypesenseApi';
|
|
10
|
+
export type { TypesenseFieldType, TypesenseCollection, TypesenseDocument, TypesenseDocumentGeneric, TypesenseQuery, TypesenseCollectionOutput, TypesenseQueryResults } from './typesense.model';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypesenseFilterBuilder = exports.ExportFormatter = exports.CollectionSchemaManager = exports.ResiliencePolicy = exports.TypesenseHttpClient = exports.TypesenseApi = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Main exports
|
|
6
|
+
var TypesenseApi_1 = require("./TypesenseApi");
|
|
7
|
+
Object.defineProperty(exports, "TypesenseApi", { enumerable: true, get: function () { return TypesenseApi_1.TypesenseApi; } });
|
|
8
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./typesense.model"), exports);
|
|
10
|
+
// Component exports
|
|
11
|
+
var http_client_1 = require("./components/http-client");
|
|
12
|
+
Object.defineProperty(exports, "TypesenseHttpClient", { enumerable: true, get: function () { return http_client_1.TypesenseHttpClient; } });
|
|
13
|
+
var resilience_policy_1 = require("./components/resilience-policy");
|
|
14
|
+
Object.defineProperty(exports, "ResiliencePolicy", { enumerable: true, get: function () { return resilience_policy_1.ResiliencePolicy; } });
|
|
15
|
+
var schema_manager_1 = require("./components/schema-manager");
|
|
16
|
+
Object.defineProperty(exports, "CollectionSchemaManager", { enumerable: true, get: function () { return schema_manager_1.CollectionSchemaManager; } });
|
|
17
|
+
var export_formatter_1 = require("./components/export-formatter");
|
|
18
|
+
Object.defineProperty(exports, "ExportFormatter", { enumerable: true, get: function () { return export_formatter_1.ExportFormatter; } });
|
|
19
|
+
var typesense_filter_builder_1 = require("./components/typesense.filter-builder");
|
|
20
|
+
Object.defineProperty(exports, "TypesenseFilterBuilder", { enumerable: true, get: function () { return typesense_filter_builder_1.TypesenseFilterBuilder; } });
|
|
21
|
+
// Re-export all action functions
|
|
22
|
+
tslib_1.__exportStar(require("./TypesenseApi"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,eAAe;AACf,+CAA6C;AAApC,4GAAA,YAAY,OAAA;AACrB,kDAAuB;AACvB,4DAAiC;AAEjC,oBAAoB;AACpB,wDAA8D;AAArD,kHAAA,mBAAmB,OAAA;AAC5B,oEAAiE;AAAxD,qHAAA,gBAAgB,OAAA;AACzB,8DAAqE;AAA5D,yHAAA,uBAAuB,OAAA;AAChC,kEAA+D;AAAtD,mHAAA,eAAe,OAAA;AACxB,kFAA8E;AAArE,kIAAA,sBAAsB,OAAA;AAE/B,iCAAiC;AACjC,yDAA8B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cleanGlobalData = exports.writeGlobalData = exports.getGlobalData = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const tempDataFilePath = (0, path_1.resolve)((0, path_1.join)(__dirname, '../../'), 'tempData.json');
|
|
7
|
+
const getGlobalData = () => {
|
|
8
|
+
const data = JSON.parse((0, fs_1.readFileSync)(tempDataFilePath, 'utf-8'));
|
|
9
|
+
return data;
|
|
10
|
+
};
|
|
11
|
+
exports.getGlobalData = getGlobalData;
|
|
12
|
+
const writeGlobalData = (data) => {
|
|
13
|
+
(0, fs_1.writeFileSync)(tempDataFilePath, JSON.stringify(data), 'utf-8');
|
|
14
|
+
};
|
|
15
|
+
exports.writeGlobalData = writeGlobalData;
|
|
16
|
+
const cleanGlobalData = () => {
|
|
17
|
+
if ((0, fs_1.existsSync)(tempDataFilePath)) {
|
|
18
|
+
(0, fs_1.unlinkSync)(tempDataFilePath);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.cleanGlobalData = cleanGlobalData;
|
|
22
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../src/tests/const.ts"],"names":[],"mappings":";;;AAAA,2BAAwE;AACxE,+BAAoC;AAKpC,MAAM,gBAAgB,GAAG,IAAA,cAAO,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,eAAe,CAAC,CAAA;AAErE,MAAM,aAAa,GAAG,GAAmB,EAAE;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAA;IAEhE,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAJY,QAAA,aAAa,iBAIzB;AAEM,MAAM,eAAe,GAAG,CAAC,IAAoB,EAAE,EAAE;IACtD,IAAA,kBAAa,EAAC,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;AAChE,CAAC,CAAA;AAFY,QAAA,eAAe,mBAE3B;AAEM,MAAM,eAAe,GAAG,GAAG,EAAE;IAClC,IAAI,IAAA,eAAU,EAAC,gBAAgB,CAAC,EAAE,CAAC;QACjC,IAAA,eAAU,EAAC,gBAAgB,CAAC,CAAA;IAC9B,CAAC;AACH,CAAC,CAAA;AAJY,QAAA,eAAe,mBAI3B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.typesenseContainer = void 0;
|
|
4
|
+
const testcontainers_1 = require("testcontainers");
|
|
5
|
+
exports.typesenseContainer = new testcontainers_1.GenericContainer('typesense/typesense:29.0')
|
|
6
|
+
.withEnvironment({
|
|
7
|
+
TYPESENSE_API_KEY: 'MY_API_KEY'
|
|
8
|
+
})
|
|
9
|
+
.withCommand([
|
|
10
|
+
'--data-dir',
|
|
11
|
+
'/tmp',
|
|
12
|
+
'--api-key',
|
|
13
|
+
'MY_API_KEY',
|
|
14
|
+
'--enable-cors',
|
|
15
|
+
'true',
|
|
16
|
+
'--enable-search-analytic',
|
|
17
|
+
'true',
|
|
18
|
+
'--analytics-dir',
|
|
19
|
+
'/path/to/analytics-data',
|
|
20
|
+
'--analytics-flush-interval',
|
|
21
|
+
'300'
|
|
22
|
+
])
|
|
23
|
+
.withExposedPorts(8108);
|
|
24
|
+
//# sourceMappingURL=typesense.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typesense.js","sourceRoot":"","sources":["../../src/tests/typesense.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAEpC,QAAA,kBAAkB,GAAG,IAAI,iCAAgB,CACpD,0BAA0B,CAC3B;KACE,eAAe,CAAC;IACf,iBAAiB,EAAE,YAAY;CAChC,CAAC;KACD,WAAW,CAAC;IACX,YAAY;IACZ,MAAM;IACN,WAAW;IACX,YAAY;IACZ,eAAe;IACf,MAAM;IACN,0BAA0B;IAC1B,MAAM;IACN,iBAAiB;IACjB,yBAAyB;IACzB,4BAA4B;IAC5B,KAAK;CACN,CAAC;KACD,gBAAgB,CAAC,IAAI,CAAC,CAAA"}
|