firestore-meilisearch 0.1.0

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 (65) hide show
  1. package/.editorconfig +20 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +26 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.md +18 -0
  4. package/.github/ISSUE_TEMPLATE/other.md +7 -0
  5. package/.github/dependatbot.yml +23 -0
  6. package/.github/release-draft-template.yml +33 -0
  7. package/.github/scripts/check-release.sh +42 -0
  8. package/.github/workflows/publish.yml +30 -0
  9. package/.github/workflows/release-drafter.yml +16 -0
  10. package/.github/workflows/test.yml +42 -0
  11. package/CHANGELOG.md +3 -0
  12. package/CONTRIBUTING.md +236 -0
  13. package/LICENSE +201 -0
  14. package/POSTINSTALL.md +40 -0
  15. package/PREINSTALL.md +42 -0
  16. package/README.md +128 -0
  17. package/bors.toml +8 -0
  18. package/dataset/firebase-export-metadata.json +8 -0
  19. package/dataset/firestore_export/all_namespaces/all_kinds/all_namespaces_all_kinds.export_metadata +0 -0
  20. package/dataset/firestore_export/all_namespaces/all_kinds/output-0 +0 -0
  21. package/dataset/firestore_export/firestore_export.overall_export_metadata +0 -0
  22. package/extension.yaml +176 -0
  23. package/firebase.json +20 -0
  24. package/functions/.eslintignore +2 -0
  25. package/functions/.eslintrc.js +54 -0
  26. package/functions/__tests__/__mocks__/console.ts +7 -0
  27. package/functions/__tests__/adapter.test.ts +98 -0
  28. package/functions/__tests__/config.test.ts +130 -0
  29. package/functions/__tests__/data/document.ts +11 -0
  30. package/functions/__tests__/data/environment.ts +9 -0
  31. package/functions/__tests__/functions.test.ts +280 -0
  32. package/functions/__tests__/jest.setup.ts +1 -0
  33. package/functions/__tests__/test.types.d.ts +5 -0
  34. package/functions/__tests__/tsconfig.json +5 -0
  35. package/functions/__tests__/util.test.ts +200 -0
  36. package/functions/jest.config.js +12 -0
  37. package/functions/lib/adapter.js +61 -0
  38. package/functions/lib/config.js +13 -0
  39. package/functions/lib/import/config.js +127 -0
  40. package/functions/lib/import/index.js +93 -0
  41. package/functions/lib/index.js +90 -0
  42. package/functions/lib/logs.js +97 -0
  43. package/functions/lib/meilisearch/create-index.js +17 -0
  44. package/functions/lib/meilisearch-index.js +17 -0
  45. package/functions/lib/types.js +2 -0
  46. package/functions/lib/util.js +47 -0
  47. package/functions/lib/version.js +4 -0
  48. package/functions/package.json +53 -0
  49. package/functions/src/adapter.ts +106 -0
  50. package/functions/src/config.ts +34 -0
  51. package/functions/src/import/config.ts +207 -0
  52. package/functions/src/import/index.ts +115 -0
  53. package/functions/src/index.ts +103 -0
  54. package/functions/src/logs.ts +107 -0
  55. package/functions/src/meilisearch/create-index.ts +20 -0
  56. package/functions/src/types.ts +8 -0
  57. package/functions/src/util.ts +63 -0
  58. package/functions/src/version.ts +1 -0
  59. package/functions/tsconfig.eslint.json +13 -0
  60. package/functions/tsconfig.json +23 -0
  61. package/functions/yarn.lock +5306 -0
  62. package/guides/IMPORT_EXISTING_DOCUMENTS.md +74 -0
  63. package/package.json +21 -0
  64. package/script/version.sh +51 -0
  65. package/test-params-example.env +9 -0
@@ -0,0 +1,74 @@
1
+ The `firestore-meilisearch` script is for use with the official Firebase Extension [**Meilisearch**](https://github.com/firebase/extensions/tree/main/firestore-meilisearch).
2
+
3
+ ### Overview
4
+
5
+ The import script reads all existing documents in a Cloud Firestore collection or in sub-collections and index them into an index in Meilisearch.
6
+
7
+ #### Important notes
8
+
9
+ - You must run the import script over the entire collection **_after_** installing the Meilisearch extension in Firebase; otherwise all the data written in the meantime or during the import in your database might not be exported to your `${param:MEILISEARCH_INDEX_NAME}` index.
10
+
11
+ - The import script may take a while to complete if your collection is large. In which case we suggest setting a larger batch size in the configuration.
12
+
13
+ - You cannot use wildcard notation in the collection path (i.e. `/collection/{document}/sub_collection}`). Instead, you can use a collectionGroup query. To use a collectionGroup query, provide the collection name value as `${COLLECTION_PATH}`, and set `${COLLECTION_GROUP_QUERY}` to true.
14
+
15
+ Warning: A collectionGroup query will target every collection in your Firestore project with the provided `${COLLECTION_PATH}`. For example, if you have 10,000 documents with a sub-collection named: actors, the import script will query every document in 10,000 actors collections.
16
+
17
+ ### Run the script
18
+
19
+ The import script uses several values from the configuration provided when you installed the extension:
20
+
21
+ - `${PROJECT_ID}`: the project ID for the Firebase project in which you installed the extension
22
+ - `${COLLECTION_PATH}`: the collection path that you specified during extension installation
23
+ - `${COLLECTION_GROUP_QUERY}`: uses a collectionGroup query if this value is "true". For any other value, a collection query is used.
24
+ - `${MEILISEARCH_INDEX_NAME}`: the UID of the Meilisearch index that you specified for your indexation during extension installation
25
+ - `${BATCHSIZE}`: the number of documents you want to import into Meilisearch at once
26
+ - `${MEILISEARCH_HOST}`: the URL of the host of the Meilisearch database that you specified during extension installation
27
+ - `${MEILISEARCH_API_KEY}`: the Meilisearch API key with permission to perform actions on indexes you specified during extension installation
28
+
29
+ Run the import script using [`npx` (the Node Package Runner)](https://www.npmjs.com/package/npx).
30
+
31
+ 1. Make sure that you've installed the required tools to run the import script:
32
+
33
+ - To access the `npm` command tools, you need to install [Node.js](https://www.nodejs.org/).
34
+ - If you use `npm` v5.1 or earlier, you need to explicitly install `npx`. Run `npm install --global npx`.
35
+
36
+ 2. Set up credentials. The import script uses Application Default Credentials to communicate with Firebase. Please follow the instructions to [create and use a service account](https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually).
37
+
38
+ 3. Run the import script interactively via `npx` by running the following command:
39
+
40
+ - Run interactively:
41
+ ```bash
42
+ npx firestore-meilisearch
43
+ ```
44
+ When prompted, enter the Cloud Firestore collection path that you specified during extension installation, `${COLLECTION_PATH}` along with any other arguments.
45
+
46
+ - Run non-interactively with paramaters:
47
+ ```bash
48
+ npx firestore-meilisearch \
49
+ --project <project_id> \
50
+ --source-collection-path <collection_name> \
51
+ --index <index_uid> \
52
+ --batch-size <100/default=300> \
53
+ --host <host_address> \
54
+ --api-key <api_key> \
55
+ --non-interactive
56
+ ```
57
+ **Note**: The `--batch-size` and `--query-collection-group` arguments are optional. To see its usage, run the above command with `--help`.
58
+
59
+ 4. Check if the index and Document are imported in Meilisearch:
60
+
61
+ 1. Check that the index has been created.:
62
+ ```bash
63
+ curl \
64
+ -X GET 'http://${MEILISEARCH_HOST}/indexes/${MEILISEARCH_INDEX_NAME}'
65
+ ```
66
+ **Note**: This example must be launched in your terminal but if you are already using the Meilisearch SDK you can use the command related to the [latter](https://docs.meilisearch.com/reference/api/indexes.html#get-one-index)
67
+
68
+ 2. Check that the documents has been added to your Meilisearch database:
69
+ ```bash
70
+ curl \
71
+ -X GET 'http://${MEILISEARCH_HOST}/indexes/${MEILISEARCH_INDEX_NAME}/stats'
72
+ ```
73
+ The response will contain the number of documents in Meilisearch index.
74
+ **Note**: This example must be launched in your terminal but if you are already using the Meilisearch SDK you can use the command related to the [latter](https://docs.meilisearch.com/reference/api/stats.html#get-stat-of-an-index)
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "firestore-meilisearch",
3
+ "version": "0.1.0",
4
+ "description": "Search in your Firestore content with Meilisearch",
5
+ "repository": "",
6
+ "author": "Meilisearch (https://meilisearch.com/)",
7
+ "license": "Apache-2.0",
8
+ "scripts": {
9
+ "emulator": "firebase ext:dev:emulators:start --test-params=test-params-example.env --import=dataset --project=meilisearch --config=./firebase.json",
10
+ "lint": "yarn --cwd functions lint",
11
+ "lint:fix": "yarn --cwd functions lint:fix",
12
+ "build": "yarn --cwd functions build",
13
+ "watch": "yarn --cwd functions watch",
14
+ "playground": "yarn --cwd functions playground",
15
+ "install:functions": "yarn --cwd functions",
16
+ "test": "yarn --cwd functions test",
17
+ "test:watch": "yarn --cwd functions test:watch",
18
+ "test:coverage": "yarn --cwd functions test:coverage",
19
+ "run-cli": "./functions/lib/import/index.js"
20
+ }
21
+ }
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ## Setup
4
+
5
+ set -e
6
+
7
+ bold=$(tput bold)
8
+ normal=$(tput sgr0)
9
+
10
+ function isValidSemver() {
11
+ if [[ $1 =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
12
+ echo "$1"
13
+ else
14
+ echo ""
15
+ fi
16
+ }
17
+
18
+ ## Version
19
+
20
+ echo "replacing version number"
21
+
22
+ version=$(isValidSemver $1)
23
+
24
+ if [ -z $version ]; then
25
+ echo "$1 is not a valid semver version"
26
+ exit 1
27
+ fi
28
+
29
+ # extension.yaml
30
+ sed -i '' "s/^version:.*/version: $version/" extension.yaml
31
+ # package.json
32
+ sed -i '' "s/\"version.*/\"version\": \"$version\",/" package.json ./functions/package.json
33
+ # version.ts
34
+ echo "export const version = '$version'" > ./functions/src/version.ts
35
+
36
+ ## Build
37
+
38
+ echo "installing and building"
39
+
40
+ npm install
41
+
42
+ cd functions
43
+ npm install
44
+ npm run build
45
+ cd ..
46
+
47
+ ## Commit files
48
+
49
+ git add -u
50
+ git commit -m "Update version for the next release (v$version)"
51
+ echo "The updated files are ready to be pushed"
@@ -0,0 +1,9 @@
1
+ # from firebase v9.20.0 the parsing of optional parameters does not work in command line
2
+ # the MEILISEARCH_FIELDS_TO_INDEX must be defined to '' instead of empty
3
+
4
+ LOCATION=us-central1
5
+ COLLECTION_PATH=movies
6
+ MEILISEARCH_FIELDS_TO_INDEX=''
7
+ MEILISEARCH_INDEX_NAME=movies
8
+ MEILISEARCH_HOST='http://127.0.0.1:7700'
9
+ MEILISEARCH_API_KEY='masterKey'