Skip to content

Commit

Permalink
Fix: Handled Alt Object ID for Delete (#211)
Browse files Browse the repository at this point in the history
* fix: update delete to use specified object id
* refactor: update npm libraries
* chore(release): 1.2.4
  • Loading branch information
smomin authored May 8, 2024
1 parent aa398e8 commit 5bfc57d
Show file tree
Hide file tree
Showing 10 changed files with 535 additions and 607 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.2.4](https://github.com/algolia/firestore-algolia-search/compare/v1.2.2...v1.2.4) (2024-05-07)


### Bug Fixes

* update delete to use specified object id ([8987fc0](https://github.com/algolia/firestore-algolia-search/commit/8987fc03a4a23b0c5a4502fb3adb0c6f8a1af966))

### [1.2.2](https://github.com/algolia/firestore-algolia-search/compare/v1.2.1...v1.2.2) (2024-03-20)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name: firestore-algolia-search

# Follow semver versioning
version: 1.2.2
version: 1.2.4

# Version of the Firebase Extensions specification
specVersion: v1beta
Expand Down
847 changes: 402 additions & 445 deletions functions/package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firestore-algolia-search",
"version": "1.2.2",
"version": "1.2.4",
"description": "Index Cloud Firestore collection to Algolia",
"scripts": {
"build": "npm run clean && npm test && npm run compile",
Expand All @@ -15,31 +15,31 @@
},
"main": "lib/index.js",
"dependencies": {
"@algolia/client-common": "^4.20.0",
"@algolia/transporter": "^4.20.0",
"@babel/preset-typescript": "^7.23.2",
"@algolia/client-common": "^4.23.3",
"@algolia/transporter": "^4.23.3",
"@babel/preset-typescript": "^7.24.1",
"@types/jest": "^27.5.2",
"@types/js-yaml": "^4.0.8",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"algoliasearch": "^4.20.0",
"eslint": "^8.52.0",
"algoliasearch": "^4.23.3",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^4.2.1",
"firebase-admin": "^11.11.0",
"firebase-functions": "^4.4.1",
"firebase-functions-test": "^3.1.0",
"firebase-functions": "^4.9.0",
"firebase-functions-test": "^3.2.0",
"jest": "^29.7.0",
"jest-mock": "^29.7.0",
"lint-staged": "^13.3.0",
"mocked-env": "^1.3.5",
"node-fetch": "^2.6.11",
"node-fetch": "^2.7.0",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"pretty-quick": "^3.3.1",
"rimraf": "^4.4.1",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^4.9.5"
}
}
4 changes: 2 additions & 2 deletions functions/src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import config from './config';
import * as logs from './logs';
import { dataProcessor, valueProcessor } from './processors';
import transform from './transform';
import { getFields, getObjectSizeInBytes, isValidValue } from './util';
import { getFields, getObjectID, getObjectSizeInBytes, isValidValue } from './util';

const PAYLOAD_MAX_SIZE = 102400;
const PAYLOAD_TOO_LARGE_ERR_MSG = 'Record is too large.';
Expand All @@ -30,7 +30,7 @@ const getPayload = async (snapshot: DocumentSnapshot): Promise<any> => {
let payload: {
[key: string]: boolean | string | number;
} = {
objectID: config.altObjectId ? config.altObjectId === '(path)' ? snapshot.ref.path : snapshot.get(config.altObjectId) : snapshot.id,
objectID: getObjectID(config, snapshot),
path: snapshot.ref.path,
};

Expand Down
6 changes: 3 additions & 3 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import FieldPath = firestore.FieldPath;

import config from './config';
import extract from './extract';
import { areFieldsUpdated, ChangeType, getChangeType } from './util';
import { areFieldsUpdated, ChangeType, getChangeType, getObjectID } from './util';
import { version } from './version';
import * as logs from './logs';

Expand Down Expand Up @@ -122,8 +122,8 @@ const handleDeleteDocument = async (
deleted: DocumentSnapshot,
) => {
try {
logs.deleteIndex(deleted.id);
await index.deleteObject(deleted.id);
logs.deleteIndex(getObjectID(config, deleted),);
await index.deleteObject(getObjectID(config, deleted),);
} catch (e) {
logs.error(e);
}
Expand Down
4 changes: 4 additions & 0 deletions functions/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export const getChangeType = (change: functions.Change<DocumentSnapshot>) => {
return ChangeType.UPDATE;
};

export const getObjectID = (config, snapshot: DocumentSnapshot): string => {
return config.altObjectId ? config.altObjectId === '(path)' ? snapshot.ref.path : snapshot.get(config.altObjectId) : snapshot.id;
}

export const getObjectSizeInBytes = (object: [] | {}) => {
const recordBuffer = Buffer.from(JSON.stringify(object));
return recordBuffer.byteLength;
Expand Down
2 changes: 1 addition & 1 deletion functions/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '1.2.2';
export const version = '1.2.4';
Loading

0 comments on commit 5bfc57d

Please sign in to comment.