firestore-meilisearch 0.3.0 → 0.3.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/README.md +4 -7
- package/__tests__/adapter.test.ts +2 -1
- package/__tests__/config.test.ts +8 -0
- package/__tests__/functions.test.ts +10 -1
- package/__tests__/tsconfig.json +12 -2
- package/__tests__/util.test.ts +14 -10
- package/lib/import/config.js +24 -1
- package/lib/import/index.js +28 -5
- package/lib/index.js +25 -2
- package/lib/meilisearch-adapter.js +24 -1
- package/lib/version.js +1 -1
- package/package.json +5 -4
- package/src/import/index.ts +3 -3
- package/src/version.ts +1 -1
- package/tsconfig.json +3 -2
package/README.md
CHANGED
|
@@ -36,16 +36,16 @@ This extension listens to each creation, update, or deletion of your documents t
|
|
|
36
36
|
|
|
37
37
|
Note that this extension only listens for changes to _documents_ in a specific collection, but not changes in any _subcollection_. However, you can install additional instances of this extension to listen to other collections in your Firestore database.
|
|
38
38
|
|
|
39
|
-
##
|
|
40
|
-
|
|
41
|
-
Say goodbye to server deployment and manual updates with [Meilisearch Cloud](https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=github&utm_medium=firestore-meilisearch). Get started with a 14-day free trial! No credit card required.
|
|
39
|
+
## 🚀 Getting started
|
|
42
40
|
|
|
43
41
|
#### Additional setup
|
|
44
42
|
|
|
45
43
|
Before installing this extension, you'll need to:
|
|
46
44
|
|
|
47
45
|
- [Set up Cloud Firestore in your Firebase project](https://firebase.google.com/docs/firestore/quickstart)
|
|
48
|
-
- Run a Meilisearch instance
|
|
46
|
+
- Run a Meilisearch instance:
|
|
47
|
+
- ⚡ **Launch, scale, and streamline in minutes with Meilisearch Cloud**—no maintenance, no commitment, cancel anytime. [Try it free now](https://cloud.meilisearch.com/login?utm_campaign=oss&utm_source=github&utm_medium=firestore-meilisearch).
|
|
48
|
+
- 🪨 Prefer to self-host? [Download and deploy](https://www.meilisearch.com/docs/learn/self_hosted/getting_started_with_self_hosted_meilisearch?utm_campaign=oss&utm_source=github&utm_medium=firestore-meilisearch) our fast, open-source search engine on your own infrastructure.
|
|
49
49
|
|
|
50
50
|
#### Data import format
|
|
51
51
|
|
|
@@ -76,9 +76,6 @@ a Google Cloud API or making outbound network requests to non-Google services.
|
|
|
76
76
|
All Firebase services offer a free tier of usage.
|
|
77
77
|
[Learn more about Firebase billing.](https://firebase.google.com/pricing)
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
79
|
**Configuration Parameters:**
|
|
83
80
|
|
|
84
81
|
* Cloud Functions location: Where do you want to deploy the functions created for this extension? If you need help selecting a location, refer to the [location selection guide](https://firebase.google.com/docs/functions/locations).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { describe, test, expect } from '@jest/globals'
|
|
2
|
+
import firebaseFunctionsTestInit from 'firebase-functions-test'
|
|
2
3
|
import { mockConsoleInfo } from './__mocks__/console'
|
|
3
4
|
import * as firestore from 'firebase-admin/firestore'
|
|
4
5
|
import {
|
package/__tests__/config.test.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
test,
|
|
4
|
+
expect,
|
|
5
|
+
beforeEach,
|
|
6
|
+
afterEach,
|
|
7
|
+
jest,
|
|
8
|
+
} from '@jest/globals'
|
|
9
|
+
import firebaseFunctionsTestInit from 'firebase-functions-test'
|
|
2
10
|
import mockedEnv from 'mocked-env'
|
|
3
11
|
import { mocked } from 'jest-mock'
|
|
4
12
|
import {
|
|
@@ -49,6 +57,7 @@ describe('extension', () => {
|
|
|
49
57
|
test('functions are exported', () => {
|
|
50
58
|
const exportedFunctions = jest.requireActual('../src')
|
|
51
59
|
|
|
60
|
+
// @ts-ignore: We're asserting the export is a function
|
|
52
61
|
expect(exportedFunctions.indexingWorker).toBeInstanceOf(Function)
|
|
53
62
|
})
|
|
54
63
|
|
package/__tests__/tsconfig.json
CHANGED
package/__tests__/util.test.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
test,
|
|
4
|
+
expect,
|
|
5
|
+
beforeEach,
|
|
6
|
+
afterEach,
|
|
7
|
+
jest,
|
|
8
|
+
} from '@jest/globals'
|
|
9
|
+
import firebaseFunctionsTestInit from 'firebase-functions-test'
|
|
2
10
|
import mockedEnv from 'mocked-env'
|
|
3
11
|
import { ChangeType, getChangedDocumentId, getChangeType } from '../src/util'
|
|
4
12
|
import defaultEnvironment from './data/environment'
|
|
@@ -151,19 +159,19 @@ describe('getFieldsToIndex', () => {
|
|
|
151
159
|
test('return empty list', () => {
|
|
152
160
|
adapter = require('../src/meilisearch-adapter')
|
|
153
161
|
mockParseFieldsToIndex = adapter.parseFieldsToIndex()
|
|
154
|
-
expect(mockParseFieldsToIndex).
|
|
162
|
+
expect(mockParseFieldsToIndex).toEqual([])
|
|
155
163
|
})
|
|
156
164
|
|
|
157
165
|
test('return list with one field', () => {
|
|
158
166
|
adapter = require('../src/meilisearch-adapter')
|
|
159
167
|
mockParseFieldsToIndex = adapter.parseFieldsToIndex('field')
|
|
160
|
-
expect(mockParseFieldsToIndex).
|
|
168
|
+
expect(mockParseFieldsToIndex).toEqual(['field'])
|
|
161
169
|
})
|
|
162
170
|
|
|
163
171
|
test('return list with multiple fields', () => {
|
|
164
172
|
adapter = require('../src/meilisearch-adapter')
|
|
165
173
|
mockParseFieldsToIndex = adapter.parseFieldsToIndex('field1,field2,field3')
|
|
166
|
-
expect(mockParseFieldsToIndex).
|
|
174
|
+
expect(mockParseFieldsToIndex).toEqual(['field1', 'field2', 'field3'])
|
|
167
175
|
})
|
|
168
176
|
|
|
169
177
|
test('return list with multiple fields and spaces', () => {
|
|
@@ -171,7 +179,7 @@ describe('getFieldsToIndex', () => {
|
|
|
171
179
|
mockParseFieldsToIndex = adapter.parseFieldsToIndex(
|
|
172
180
|
'field1, field2, field3'
|
|
173
181
|
)
|
|
174
|
-
expect(mockParseFieldsToIndex).
|
|
182
|
+
expect(mockParseFieldsToIndex).toEqual(['field1', 'field2', 'field3'])
|
|
175
183
|
})
|
|
176
184
|
|
|
177
185
|
test('return list of fiels with underscore', () => {
|
|
@@ -179,10 +187,6 @@ describe('getFieldsToIndex', () => {
|
|
|
179
187
|
mockParseFieldsToIndex = adapter.parseFieldsToIndex(
|
|
180
188
|
'field_1,field_2,field_3'
|
|
181
189
|
)
|
|
182
|
-
expect(mockParseFieldsToIndex).
|
|
183
|
-
'field_1',
|
|
184
|
-
'field_2',
|
|
185
|
-
'field_3',
|
|
186
|
-
])
|
|
190
|
+
expect(mockParseFieldsToIndex).toEqual(['field_1', 'field_2', 'field_3'])
|
|
187
191
|
})
|
|
188
192
|
})
|
package/lib/import/config.js
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.parseConfig = void 0;
|
|
4
27
|
const commander_1 = require("commander");
|
|
5
|
-
const inquirer = require("inquirer");
|
|
28
|
+
const inquirer = __importStar(require("inquirer"));
|
|
6
29
|
const FIRESTORE_VALID_CHARACTERS = /^[^/]+$/;
|
|
7
30
|
const FIRESTORE_COLLECTION_NAME_MAX_CHARS = 6144;
|
|
8
31
|
const PROJECT_ID_MAX_CHARS = 30;
|
package/lib/import/index.js
CHANGED
|
@@ -15,21 +15,44 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
23
|
+
}
|
|
24
|
+
Object.defineProperty(o, k2, desc);
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
18
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
const
|
|
42
|
+
const firebase_admin_1 = __importStar(require("firebase-admin"));
|
|
20
43
|
const config_1 = require("./config");
|
|
21
|
-
const logs = require("../logs");
|
|
44
|
+
const logs = __importStar(require("../logs"));
|
|
22
45
|
const meilisearch_adapter_1 = require("../meilisearch-adapter");
|
|
23
46
|
const create_index_1 = require("../meilisearch/create-index");
|
|
24
47
|
const run = async () => {
|
|
25
48
|
// Retrieve all arguments from the commande line.
|
|
26
49
|
const config = await (0, config_1.parseConfig)();
|
|
27
50
|
// Initialize Firebase using the Google Credentials in the GOOGLE_APPLICATION_CREDENTIALS environment variable.
|
|
28
|
-
|
|
29
|
-
credential:
|
|
51
|
+
firebase_admin_1.default.initializeApp({
|
|
52
|
+
credential: firebase_admin_1.credential.applicationDefault(),
|
|
30
53
|
databaseURL: `https://${config.projectId}.firebaseio.com`,
|
|
31
54
|
});
|
|
32
|
-
const database =
|
|
55
|
+
const database = (0, firebase_admin_1.firestore)();
|
|
33
56
|
// Initialize Meilisearch index.
|
|
34
57
|
const index = (0, create_index_1.initMeilisearchIndex)(config.meilisearch);
|
|
35
58
|
await retrieveCollectionFromFirestore(database, config, index);
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.indexingWorker = void 0;
|
|
4
27
|
/*
|
|
@@ -16,11 +39,11 @@ exports.indexingWorker = void 0;
|
|
|
16
39
|
* See the License for the specific language governing permissions and
|
|
17
40
|
* limitations under the License.
|
|
18
41
|
*/
|
|
19
|
-
const functions = require("firebase-functions");
|
|
42
|
+
const functions = __importStar(require("firebase-functions"));
|
|
20
43
|
const firebase_functions_1 = require("firebase-functions");
|
|
21
44
|
const create_index_1 = require("./meilisearch/create-index");
|
|
22
45
|
const util_1 = require("./util");
|
|
23
|
-
const logs = require("./logs");
|
|
46
|
+
const logs = __importStar(require("./logs"));
|
|
24
47
|
const meilisearch_adapter_1 = require("./meilisearch-adapter");
|
|
25
48
|
const config_1 = require("./config");
|
|
26
49
|
const validate_1 = require("./validate");
|
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.adaptDocumentForMeilisearch = exports.adaptFieldsForMeilisearch = exports.parseFieldsToIndex = exports.isAFieldToIndex = void 0;
|
|
4
|
-
const firestore = require("firebase-admin/firestore");
|
|
27
|
+
const firestore = __importStar(require("firebase-admin/firestore"));
|
|
5
28
|
const logs_1 = require("./logs");
|
|
6
29
|
/**
|
|
7
30
|
* Adapts GeoPoint Firestore instance to fit with Meilisearch geo point.
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firestore-meilisearch",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"lint": "eslint .",
|
|
6
6
|
"lint:fix": "eslint . --fix",
|
|
@@ -25,10 +25,12 @@
|
|
|
25
25
|
"firebase-admin": "^11.5.0",
|
|
26
26
|
"firebase-functions": "^4.2.1",
|
|
27
27
|
"inquirer": "^8.2.2",
|
|
28
|
-
"meilisearch": "^0.30.0"
|
|
28
|
+
"meilisearch": "^0.30.0",
|
|
29
|
+
"typescript": "^4.4.3"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@babel/preset-typescript": "^7.15.0",
|
|
33
|
+
"@jest/globals": "^29.7.0",
|
|
32
34
|
"@types/jest": "^27.0.2",
|
|
33
35
|
"@typescript-eslint/eslint-plugin": "^4.32.0",
|
|
34
36
|
"@typescript-eslint/parser": "^4.32.0",
|
|
@@ -46,8 +48,7 @@
|
|
|
46
48
|
"mocked-env": "^1.3.5",
|
|
47
49
|
"prettier": "^2.4.1",
|
|
48
50
|
"ts-jest": "^29.0.5",
|
|
49
|
-
"ts-node": "^10.2.1"
|
|
50
|
-
"typescript": "^4.4.3"
|
|
51
|
+
"ts-node": "^10.2.1"
|
|
51
52
|
},
|
|
52
53
|
"bin": "lib/import/index.js"
|
|
53
54
|
}
|
package/src/import/index.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import
|
|
19
|
+
import admin, { credential, firestore } from 'firebase-admin'
|
|
20
20
|
import { DocumentSnapshot } from 'firebase-functions/lib/v1/providers/firestore'
|
|
21
21
|
import { CLIConfig, parseConfig } from './config'
|
|
22
22
|
import * as logs from '../logs'
|
|
@@ -30,11 +30,11 @@ const run = async () => {
|
|
|
30
30
|
|
|
31
31
|
// Initialize Firebase using the Google Credentials in the GOOGLE_APPLICATION_CREDENTIALS environment variable.
|
|
32
32
|
admin.initializeApp({
|
|
33
|
-
credential:
|
|
33
|
+
credential: credential.applicationDefault(),
|
|
34
34
|
databaseURL: `https://${config.projectId}.firebaseio.com`,
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
-
const database =
|
|
37
|
+
const database = firestore()
|
|
38
38
|
|
|
39
39
|
// Initialize Meilisearch index.
|
|
40
40
|
const index = initMeilisearchIndex(config.meilisearch)
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.3.
|
|
1
|
+
export const version = '0.3.2'
|
package/tsconfig.json
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"strict": true,
|
|
10
10
|
"target": "es2018",
|
|
11
11
|
"types": [
|
|
12
|
-
"jest",
|
|
13
12
|
"node",
|
|
14
|
-
]
|
|
13
|
+
],
|
|
14
|
+
"esModuleInterop": true,
|
|
15
15
|
},
|
|
16
16
|
"compileOnSave": true,
|
|
17
17
|
"include": [
|
|
@@ -19,5 +19,6 @@
|
|
|
19
19
|
],
|
|
20
20
|
"exclude": [
|
|
21
21
|
"node_modules",
|
|
22
|
+
"**/__tests__/**"
|
|
22
23
|
]
|
|
23
24
|
}
|