firestore-meilisearch 0.1.4 → 0.1.6
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/README.md +2 -2
- package/__tests__/functions.test.ts +49 -22
- package/lib/index.js +24 -7
- package/lib/logs.js +5 -7
- package/lib/meilisearch/agents.js +9 -0
- package/lib/meilisearch/create-index.js +2 -0
- package/lib/validate.js +16 -0
- package/lib/version.js +1 -1
- package/package.json +2 -2
- package/src/index.ts +27 -8
- package/src/logs.ts +5 -9
- package/src/meilisearch/agents.ts +9 -0
- package/src/meilisearch/create-index.ts +2 -0
- package/src/validate.ts +13 -0
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Note that this extension only listens for changes to _documents_ in a specific c
|
|
|
40
40
|
Before installing this extension, you'll need to:
|
|
41
41
|
|
|
42
42
|
- [Set up Cloud Firestore in your Firebase project](https://firebase.google.com/docs/firestore/quickstart)
|
|
43
|
-
- Run a Meilisearch instance.
|
|
43
|
+
- Run a Meilisearch instance. [Learn more about Meilisearch cloud](https://www.meilisearch.com/pricing). Alternatively there are many other easy ways [to download and run a Meilisearch instance](https://docs.meilisearch.com/learn/getting_started/installation.html#download-and-launch)
|
|
44
44
|
|
|
45
45
|
#### Data import format
|
|
46
46
|
|
|
@@ -119,7 +119,7 @@ firebase ext:install meilisearch/firestore-meilisearch --project=[your-project-i
|
|
|
119
119
|
|
|
120
120
|
## 🤖 Compatibility with Meilisearch
|
|
121
121
|
|
|
122
|
-
This package only guarantees the compatibility with the [version v0.
|
|
122
|
+
This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).
|
|
123
123
|
|
|
124
124
|
## ⚙️ Development Workflow and Contributing
|
|
125
125
|
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import * as firebaseFunctionsTestInit from 'firebase-functions-test'
|
|
2
2
|
import mockedEnv from 'mocked-env'
|
|
3
3
|
import { mocked } from 'ts-jest/utils'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
mockConsoleLog,
|
|
6
|
+
mockConsoleInfo,
|
|
7
|
+
mockConsoleError,
|
|
8
|
+
} from './__mocks__/console'
|
|
5
9
|
import { MeiliSearch } from 'meilisearch'
|
|
6
10
|
import defaultEnvironment from './data/environment'
|
|
7
11
|
import defaultDocument from './data/document'
|
|
12
|
+
import { version } from '../src/version'
|
|
8
13
|
|
|
9
14
|
jest.mock('meilisearch')
|
|
10
15
|
|
|
@@ -18,11 +23,9 @@ describe('extension', () => {
|
|
|
18
23
|
// Mocking of Meilisearch package
|
|
19
24
|
const mockedMeilisearch = mocked(MeiliSearch, true)
|
|
20
25
|
const mockedAddDocuments = jest.fn()
|
|
21
|
-
const mockedUpdateDocuments = jest.fn()
|
|
22
26
|
const mockedDeleteDocument = jest.fn()
|
|
23
27
|
const mockedIndex = jest.fn(() => ({
|
|
24
28
|
addDocuments: mockedAddDocuments,
|
|
25
|
-
updateDocuments: mockedUpdateDocuments,
|
|
26
29
|
deleteDocument: mockedDeleteDocument,
|
|
27
30
|
}))
|
|
28
31
|
mockedMeilisearch.mockReturnValue({
|
|
@@ -52,6 +55,7 @@ describe('extension', () => {
|
|
|
52
55
|
expect(mockedMeilisearch).toHaveBeenCalledWith({
|
|
53
56
|
apiKey: defaultEnvironment.MEILISEARCH_API_KEY,
|
|
54
57
|
host: defaultEnvironment.MEILISEARCH_HOST,
|
|
58
|
+
clientAgents: [`Meilisearch Firebase (v${version})`],
|
|
55
59
|
})
|
|
56
60
|
expect(mockConsoleLog).toBeCalledWith(
|
|
57
61
|
'Initializing extension with configuration',
|
|
@@ -105,8 +109,7 @@ describe('extension', () => {
|
|
|
105
109
|
expect(mockConsoleInfo).toBeCalledWith(
|
|
106
110
|
`Creating new document ${
|
|
107
111
|
afterSnapshot.id as string
|
|
108
|
-
} in Meilisearch index ${defaultEnvironment.MEILISEARCH_INDEX_NAME}
|
|
109
|
-
{ _firestore_id: defaultDocument.id, ...afterSnapshot.data() }
|
|
112
|
+
} in Meilisearch index: ${defaultEnvironment.MEILISEARCH_INDEX_NAME}`
|
|
110
113
|
)
|
|
111
114
|
expect(mockedAddDocuments).toHaveBeenCalledWith(
|
|
112
115
|
[
|
|
@@ -148,8 +151,7 @@ describe('extension', () => {
|
|
|
148
151
|
expect(mockConsoleInfo).toBeCalledWith(
|
|
149
152
|
`Creating new document ${
|
|
150
153
|
afterSnapshot.id as string
|
|
151
|
-
} in Meilisearch index ${defaultEnvironment.MEILISEARCH_INDEX_NAME}
|
|
152
|
-
{ _firestore_id: defaultDocument.id, ...afterSnapshot.data() }
|
|
154
|
+
} in Meilisearch index: ${defaultEnvironment.MEILISEARCH_INDEX_NAME}`
|
|
153
155
|
)
|
|
154
156
|
expect(mockedAddDocuments).toHaveBeenCalledWith(
|
|
155
157
|
[
|
|
@@ -163,6 +165,37 @@ describe('extension', () => {
|
|
|
163
165
|
)
|
|
164
166
|
})
|
|
165
167
|
|
|
168
|
+
test('function run on creating document with unauthorized chars in document id', async () => {
|
|
169
|
+
const badId = '@@ !#'
|
|
170
|
+
const beforeSnapshot = firebaseMock.firestore.makeDocumentSnapshot(
|
|
171
|
+
{},
|
|
172
|
+
`collection/{}`
|
|
173
|
+
)
|
|
174
|
+
const afterSnapshot = firebaseMock.firestore.makeDocumentSnapshot(
|
|
175
|
+
{ id: badId },
|
|
176
|
+
`collection/${badId}`
|
|
177
|
+
)
|
|
178
|
+
const documentChange = firebaseMock.makeChange(
|
|
179
|
+
beforeSnapshot,
|
|
180
|
+
afterSnapshot
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
await mockExport(documentChange, {
|
|
184
|
+
resource: {
|
|
185
|
+
name: 'test',
|
|
186
|
+
},
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
expect(mockConsoleInfo).toBeCalledWith(
|
|
190
|
+
`Creating new document ${
|
|
191
|
+
afterSnapshot.id as string
|
|
192
|
+
} in Meilisearch index: ${defaultEnvironment.MEILISEARCH_INDEX_NAME}`
|
|
193
|
+
)
|
|
194
|
+
expect(mockConsoleError).toBeCalledWith(
|
|
195
|
+
`Could not create document with id: ${badId}. The document id can only contain case-insensitive alphanumeric characters (abcDEF), hyphens (-) or underscores(_).`
|
|
196
|
+
)
|
|
197
|
+
})
|
|
198
|
+
|
|
166
199
|
test('function runs with updated data', async () => {
|
|
167
200
|
const beforeSnapshot = firebaseMock.firestore.makeDocumentSnapshot(
|
|
168
201
|
{ foo: 'bar' },
|
|
@@ -189,13 +222,12 @@ describe('extension', () => {
|
|
|
189
222
|
config
|
|
190
223
|
)
|
|
191
224
|
expect(mockConsoleInfo).toBeCalledWith(
|
|
192
|
-
`Updating document ${
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
{ _firestore_id: defaultDocument.id, ...afterSnapshot.data() }
|
|
225
|
+
`Updating document ${
|
|
226
|
+
afterSnapshot.id as string
|
|
227
|
+
} in Meilisearch index: ${defaultEnvironment.MEILISEARCH_INDEX_NAME}`
|
|
196
228
|
)
|
|
197
229
|
expect(mockConsoleLog).toBeCalledWith('Completed execution of extension')
|
|
198
|
-
expect(
|
|
230
|
+
expect(mockedAddDocuments).toHaveBeenCalledWith([
|
|
199
231
|
{
|
|
200
232
|
_firestore_id: defaultDocument.id,
|
|
201
233
|
...defaultDocument.document,
|
|
@@ -229,17 +261,12 @@ describe('extension', () => {
|
|
|
229
261
|
config
|
|
230
262
|
)
|
|
231
263
|
expect(mockConsoleInfo).toBeCalledWith(
|
|
232
|
-
`Updating document ${
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
{
|
|
236
|
-
_firestore_id: defaultDocument.id,
|
|
237
|
-
id: '12345',
|
|
238
|
-
...afterSnapshot.data(),
|
|
239
|
-
}
|
|
264
|
+
`Updating document ${
|
|
265
|
+
afterSnapshot.id as string
|
|
266
|
+
} in Meilisearch index: ${defaultEnvironment.MEILISEARCH_INDEX_NAME}`
|
|
240
267
|
)
|
|
241
268
|
expect(mockConsoleLog).toBeCalledWith('Completed execution of extension')
|
|
242
|
-
expect(
|
|
269
|
+
expect(mockedAddDocuments).toHaveBeenCalledWith([
|
|
243
270
|
{
|
|
244
271
|
_firestore_id: defaultDocument.id,
|
|
245
272
|
id: '12345',
|
|
@@ -271,7 +298,7 @@ describe('extension', () => {
|
|
|
271
298
|
config
|
|
272
299
|
)
|
|
273
300
|
expect(mockConsoleInfo).toBeCalledWith(
|
|
274
|
-
`Deleting document ${defaultDocument.id} in Meilisearch index ${defaultEnvironment.MEILISEARCH_INDEX_NAME}`
|
|
301
|
+
`Deleting document ${defaultDocument.id} in Meilisearch index: ${defaultEnvironment.MEILISEARCH_INDEX_NAME}`
|
|
275
302
|
)
|
|
276
303
|
expect(mockConsoleLog).toBeCalledWith('Completed execution of extension')
|
|
277
304
|
expect(mockedDeleteDocument).toHaveBeenCalledWith(defaultDocument.id)
|
package/lib/index.js
CHANGED
|
@@ -17,11 +17,13 @@ exports.indexingWorker = void 0;
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
const functions = require("firebase-functions");
|
|
20
|
+
const firebase_functions_1 = require("firebase-functions");
|
|
20
21
|
const create_index_1 = require("./meilisearch/create-index");
|
|
21
22
|
const util_1 = require("./util");
|
|
22
23
|
const logs = require("./logs");
|
|
23
24
|
const adapter_1 = require("./adapter");
|
|
24
25
|
const config_1 = require("./config");
|
|
26
|
+
const validate_1 = require("./validate");
|
|
25
27
|
const index = (0, create_index_1.initMeilisearchIndex)(config_1.config.meilisearch);
|
|
26
28
|
logs.init();
|
|
27
29
|
/**
|
|
@@ -52,9 +54,14 @@ exports.indexingWorker = functions.handler.firestore.document.onWrite(async (cha
|
|
|
52
54
|
*/
|
|
53
55
|
async function handleAddDocument(documentId, snapshot) {
|
|
54
56
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
logs.addDocument(documentId);
|
|
58
|
+
if ((0, validate_1.validateDocumentId)(documentId)) {
|
|
59
|
+
const document = (0, adapter_1.adaptDocument)(documentId, snapshot);
|
|
60
|
+
await index.addDocuments([document], { primaryKey: '_firestore_id' });
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
firebase_functions_1.logger.error(`Could not create document with id: ${documentId}. The document id can only contain case-insensitive alphanumeric characters (abcDEF), hyphens (-) or underscores(_).`);
|
|
64
|
+
}
|
|
58
65
|
}
|
|
59
66
|
catch (e) {
|
|
60
67
|
logs.error(e);
|
|
@@ -66,8 +73,13 @@ async function handleAddDocument(documentId, snapshot) {
|
|
|
66
73
|
*/
|
|
67
74
|
async function handleDeleteDocument(documentId) {
|
|
68
75
|
try {
|
|
69
|
-
await index.deleteDocument(documentId);
|
|
70
76
|
logs.deleteDocument(documentId);
|
|
77
|
+
if ((0, validate_1.validateDocumentId)(documentId)) {
|
|
78
|
+
await index.deleteDocument(documentId);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
firebase_functions_1.logger.error(`Could not delete document with id: ${documentId}. The document id can only contain case-insensitive alphanumeric characters (abcDEF), hyphens (-) or underscores(_).`);
|
|
82
|
+
}
|
|
71
83
|
}
|
|
72
84
|
catch (e) {
|
|
73
85
|
logs.error(e);
|
|
@@ -80,9 +92,14 @@ async function handleDeleteDocument(documentId) {
|
|
|
80
92
|
*/
|
|
81
93
|
async function handleUpdateDocument(documentId, after) {
|
|
82
94
|
try {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
95
|
+
logs.updateDocument(documentId);
|
|
96
|
+
if ((0, validate_1.validateDocumentId)(documentId)) {
|
|
97
|
+
const document = (0, adapter_1.adaptDocument)(documentId, after);
|
|
98
|
+
await index.addDocuments([document]);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
firebase_functions_1.logger.error(`Could not update document with id: ${documentId}.The document id can only contain case-insensitive alphanumeric characters (abcDEF), hyphens (-) or underscores(_).`);
|
|
102
|
+
}
|
|
86
103
|
}
|
|
87
104
|
catch (e) {
|
|
88
105
|
logs.error(e);
|
package/lib/logs.js
CHANGED
|
@@ -50,19 +50,17 @@ exports.complete = complete;
|
|
|
50
50
|
/**
|
|
51
51
|
* Log an addition of a document.
|
|
52
52
|
* @param {string} id Document id added.
|
|
53
|
-
* @param {object} data Data contained in the document.
|
|
54
53
|
*/
|
|
55
|
-
function addDocument(id
|
|
56
|
-
firebase_functions_1.logger.info(`Creating new document ${id} in Meilisearch index ${config_1.config.meilisearch.indexUid}
|
|
54
|
+
function addDocument(id) {
|
|
55
|
+
firebase_functions_1.logger.info(`Creating new document ${id} in Meilisearch index: ${config_1.config.meilisearch.indexUid}`);
|
|
57
56
|
}
|
|
58
57
|
exports.addDocument = addDocument;
|
|
59
58
|
/**
|
|
60
59
|
* Log an update of a document.
|
|
61
60
|
* @param {string} id Document id updated.
|
|
62
|
-
* @param {object} data Data contained in the document.
|
|
63
61
|
*/
|
|
64
|
-
function updateDocument(id
|
|
65
|
-
firebase_functions_1.logger.info(`Updating document ${id} in Meilisearch index ${config_1.config.meilisearch.indexUid}
|
|
62
|
+
function updateDocument(id) {
|
|
63
|
+
firebase_functions_1.logger.info(`Updating document ${id} in Meilisearch index: ${config_1.config.meilisearch.indexUid}`);
|
|
66
64
|
}
|
|
67
65
|
exports.updateDocument = updateDocument;
|
|
68
66
|
/**
|
|
@@ -70,7 +68,7 @@ exports.updateDocument = updateDocument;
|
|
|
70
68
|
* @param {string} id Document id deleted.
|
|
71
69
|
*/
|
|
72
70
|
function deleteDocument(id) {
|
|
73
|
-
firebase_functions_1.logger.info(`Deleting document ${id} in Meilisearch index ${config_1.config.meilisearch.indexUid}`);
|
|
71
|
+
firebase_functions_1.logger.info(`Deleting document ${id} in Meilisearch index: ${config_1.config.meilisearch.indexUid}`);
|
|
74
72
|
}
|
|
75
73
|
exports.deleteDocument = deleteDocument;
|
|
76
74
|
/**
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constructClientAgents = void 0;
|
|
4
|
+
const version_1 = require("../version");
|
|
5
|
+
const constructClientAgents = (clientAgents = []) => {
|
|
6
|
+
const firebaseAgent = `Meilisearch Firebase (v${version_1.version})`;
|
|
7
|
+
return clientAgents.concat(firebaseAgent);
|
|
8
|
+
};
|
|
9
|
+
exports.constructClientAgents = constructClientAgents;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initMeilisearchIndex = void 0;
|
|
4
4
|
const meilisearch_1 = require("meilisearch");
|
|
5
|
+
const agents_1 = require("./agents");
|
|
5
6
|
/**
|
|
6
7
|
* initMeilisearchIndex
|
|
7
8
|
* @param {MeilisearchConfig} - Meilisearch configuration
|
|
@@ -11,6 +12,7 @@ function initMeilisearchIndex({ host, apiKey, indexUid, }) {
|
|
|
11
12
|
const client = new meilisearch_1.MeiliSearch({
|
|
12
13
|
host,
|
|
13
14
|
apiKey,
|
|
15
|
+
clientAgents: (0, agents_1.constructClientAgents)(),
|
|
14
16
|
});
|
|
15
17
|
return client.index(indexUid);
|
|
16
18
|
}
|
package/lib/validate.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateDocumentId = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Validate if the format of the document id is compliant with Meilisearch.
|
|
6
|
+
* Based on this documentation: https://docs.meilisearch.com/learn/core_concepts/primary_key.html#formatting-the-document-id
|
|
7
|
+
*
|
|
8
|
+
* @param {string} documentId Document id.
|
|
9
|
+
*
|
|
10
|
+
* @return {boolean} - Wether the document id is properly formatted (true) or not.
|
|
11
|
+
*/
|
|
12
|
+
function validateDocumentId(documentId) {
|
|
13
|
+
const wrongChars = documentId.search(/([^a-zA-Z0-9-_]+)/);
|
|
14
|
+
return wrongChars === -1;
|
|
15
|
+
}
|
|
16
|
+
exports.validateDocumentId = validateDocumentId;
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firestore-meilisearch",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"lint": "eslint .",
|
|
6
6
|
"lint:fix": "eslint . --fix",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"firebase-admin": "^9.8.0",
|
|
26
26
|
"firebase-functions": "^3.16.0",
|
|
27
27
|
"inquirer": "^8.2.2",
|
|
28
|
-
"meilisearch": "^0.
|
|
28
|
+
"meilisearch": "^0.27.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@babel/preset-typescript": "^7.15.0",
|
package/src/index.ts
CHANGED
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import * as functions from 'firebase-functions'
|
|
19
|
-
import { Change } from 'firebase-functions'
|
|
19
|
+
import { Change, logger } from 'firebase-functions'
|
|
20
20
|
import { DocumentSnapshot } from 'firebase-functions/lib/providers/firestore'
|
|
21
21
|
import { initMeilisearchIndex } from './meilisearch/create-index'
|
|
22
22
|
import { getChangeType, getChangedDocumentId, ChangeType } from './util'
|
|
23
23
|
import * as logs from './logs'
|
|
24
24
|
import { adaptDocument } from './adapter'
|
|
25
25
|
import { config } from './config'
|
|
26
|
+
import { validateDocumentId } from './validate'
|
|
26
27
|
|
|
27
28
|
const index = initMeilisearchIndex(config.meilisearch)
|
|
28
29
|
|
|
@@ -63,9 +64,15 @@ async function handleAddDocument(
|
|
|
63
64
|
snapshot: DocumentSnapshot
|
|
64
65
|
): Promise<void> {
|
|
65
66
|
try {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
logs.addDocument(documentId)
|
|
68
|
+
if (validateDocumentId(documentId)) {
|
|
69
|
+
const document = adaptDocument(documentId, snapshot)
|
|
70
|
+
await index.addDocuments([document], { primaryKey: '_firestore_id' })
|
|
71
|
+
} else {
|
|
72
|
+
logger.error(
|
|
73
|
+
`Could not create document with id: ${documentId}. The document id can only contain case-insensitive alphanumeric characters (abcDEF), hyphens (-) or underscores(_).`
|
|
74
|
+
)
|
|
75
|
+
}
|
|
69
76
|
} catch (e) {
|
|
70
77
|
logs.error(e as Error)
|
|
71
78
|
}
|
|
@@ -77,8 +84,14 @@ async function handleAddDocument(
|
|
|
77
84
|
*/
|
|
78
85
|
async function handleDeleteDocument(documentId: string): Promise<void> {
|
|
79
86
|
try {
|
|
80
|
-
await index.deleteDocument(documentId)
|
|
81
87
|
logs.deleteDocument(documentId)
|
|
88
|
+
if (validateDocumentId(documentId)) {
|
|
89
|
+
await index.deleteDocument(documentId)
|
|
90
|
+
} else {
|
|
91
|
+
logger.error(
|
|
92
|
+
`Could not delete document with id: ${documentId}. The document id can only contain case-insensitive alphanumeric characters (abcDEF), hyphens (-) or underscores(_).`
|
|
93
|
+
)
|
|
94
|
+
}
|
|
82
95
|
} catch (e) {
|
|
83
96
|
logs.error(e as Error)
|
|
84
97
|
}
|
|
@@ -94,9 +107,15 @@ async function handleUpdateDocument(
|
|
|
94
107
|
after: DocumentSnapshot
|
|
95
108
|
): Promise<void> {
|
|
96
109
|
try {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
logs.updateDocument(documentId)
|
|
111
|
+
if (validateDocumentId(documentId)) {
|
|
112
|
+
const document = adaptDocument(documentId, after)
|
|
113
|
+
await index.addDocuments([document])
|
|
114
|
+
} else {
|
|
115
|
+
logger.error(
|
|
116
|
+
`Could not update document with id: ${documentId}.The document id can only contain case-insensitive alphanumeric characters (abcDEF), hyphens (-) or underscores(_).`
|
|
117
|
+
)
|
|
118
|
+
}
|
|
100
119
|
} catch (e) {
|
|
101
120
|
logs.error(e as Error)
|
|
102
121
|
}
|
package/src/logs.ts
CHANGED
|
@@ -50,24 +50,20 @@ export function complete() {
|
|
|
50
50
|
/**
|
|
51
51
|
* Log an addition of a document.
|
|
52
52
|
* @param {string} id Document id added.
|
|
53
|
-
* @param {object} data Data contained in the document.
|
|
54
53
|
*/
|
|
55
|
-
export function addDocument(id: string
|
|
54
|
+
export function addDocument(id: string) {
|
|
56
55
|
logger.info(
|
|
57
|
-
`Creating new document ${id} in Meilisearch index ${config.meilisearch.indexUid}
|
|
58
|
-
data
|
|
56
|
+
`Creating new document ${id} in Meilisearch index: ${config.meilisearch.indexUid}`
|
|
59
57
|
)
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
/**
|
|
63
61
|
* Log an update of a document.
|
|
64
62
|
* @param {string} id Document id updated.
|
|
65
|
-
* @param {object} data Data contained in the document.
|
|
66
63
|
*/
|
|
67
|
-
export function updateDocument(id: string
|
|
64
|
+
export function updateDocument(id: string) {
|
|
68
65
|
logger.info(
|
|
69
|
-
`Updating document ${id} in Meilisearch index ${config.meilisearch.indexUid}
|
|
70
|
-
data
|
|
66
|
+
`Updating document ${id} in Meilisearch index: ${config.meilisearch.indexUid}`
|
|
71
67
|
)
|
|
72
68
|
}
|
|
73
69
|
|
|
@@ -77,7 +73,7 @@ export function updateDocument(id: string, data: Record<string, any>) {
|
|
|
77
73
|
*/
|
|
78
74
|
export function deleteDocument(id: string) {
|
|
79
75
|
logger.info(
|
|
80
|
-
`Deleting document ${id} in Meilisearch index ${config.meilisearch.indexUid}`
|
|
76
|
+
`Deleting document ${id} in Meilisearch index: ${config.meilisearch.indexUid}`
|
|
81
77
|
)
|
|
82
78
|
}
|
|
83
79
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MeiliSearch, Index } from 'meilisearch'
|
|
2
2
|
import { MeilisearchConfig } from '../types'
|
|
3
|
+
import { constructClientAgents } from './agents'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* initMeilisearchIndex
|
|
@@ -14,6 +15,7 @@ export function initMeilisearchIndex({
|
|
|
14
15
|
const client = new MeiliSearch({
|
|
15
16
|
host,
|
|
16
17
|
apiKey,
|
|
18
|
+
clientAgents: constructClientAgents(),
|
|
17
19
|
})
|
|
18
20
|
|
|
19
21
|
return client.index(indexUid)
|
package/src/validate.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate if the format of the document id is compliant with Meilisearch.
|
|
3
|
+
* Based on this documentation: https://docs.meilisearch.com/learn/core_concepts/primary_key.html#formatting-the-document-id
|
|
4
|
+
*
|
|
5
|
+
* @param {string} documentId Document id.
|
|
6
|
+
*
|
|
7
|
+
* @return {boolean} - Wether the document id is properly formatted (true) or not.
|
|
8
|
+
*/
|
|
9
|
+
export function validateDocumentId(documentId: string) {
|
|
10
|
+
const wrongChars = documentId.search(/([^a-zA-Z0-9-_]+)/)
|
|
11
|
+
|
|
12
|
+
return wrongChars === -1
|
|
13
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.1.
|
|
1
|
+
export const version = '0.1.6'
|