Skip to content

Commit

Permalink
feat: add vector value support
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Jan 10, 2025
1 parent 223351a commit 7651445
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 54 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
/pubsub_node/package-lock.json
/storage_node/pubspec_overrides.yaml
pubspec_overrides.yaml
/pubspec.yaml
/pubspec.lock
.dart_tool/
14 changes: 6 additions & 8 deletions auth_node/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: ^3.5.0

dependencies:
collection: '>=1.14.10'
collection: ">=1.18.0"
uuid: '>=1.0.0'
tekartik_firebase_auth:
git:
Expand Down Expand Up @@ -36,11 +36,11 @@ dependencies:
# firebase_admin_interop: ">=1.1.0"

dev_dependencies:
test: ">=1.2.0"
dev_build: '>=0.12.0-dev.1'
test: ">=1.24.0"
dev_build: ">=1.1.0+2"
grinder: any
build_test: ">=0.10.3"
process_run: '>=0.10.0+1'
process_run: ">=1.2.1+1"
tekartik_app_node_build:
git:
url: https://github.com/tekartik/app_node_utils.dart
Expand All @@ -54,13 +54,11 @@ dev_dependencies:
ref: dart3a
version: '>=0.4.0+0'
# needed node dependencies
build_runner:
build_runner: ">=2.4.13"
tekartik_build_node:
git:
url: https://github.com/tekartik/build_node.dart
path: packages/build_node
ref: dart3a

dependency_overrides:
tekartik_firebase_node:
path: ../firebase_node
resolution: workspace
9 changes: 5 additions & 4 deletions firebase_node/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
sdk: ^3.5.0

dependencies:
collection: '>=1.14.10'
collection: ">=1.18.0"
uuid: '>=1.0.0'
tekartik_firebase:
git:
Expand Down Expand Up @@ -56,29 +56,30 @@ dependencies:
ref: dart3a
path: platform
dev_dependencies:
test: ">=1.2.0"
test: ">=1.24.0"
tekartik_firebase_test:
git:
url: https://github.com/tekartik/firebase.dart
path: firebase_test
ref: dart3a
version: '>=0.7.3'
process_run:
process_run: ">=1.2.1+1"
tekartik_app_node_build:
git:
url: https://github.com/tekartik/app_node_utils.dart
path: app_build
ref: dart3a
version: '>=0.1.0'
# needed node dependencies
build_runner:
build_runner: ">=2.4.13"
tekartik_build_node:
git:
url: https://github.com/tekartik/build_node.dart
path: packages/build_node
ref: dart3a

dependency_overrides:
resolution: workspace
# tekartik_firebase:
# path: ../firebase
# tekartik_firebase_local:
Expand Down
8 changes: 8 additions & 0 deletions firestore_node/lib/src/node/firestore_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class FirestoreServiceNode
@override
bool get supportsAggregateQueries => true;

@override
bool get supportsVectorValue => true;
@override
String toString() => 'FirestoreServiceNode()';
}
Expand Down Expand Up @@ -492,6 +494,9 @@ js.JSAny? commonToNativeValue(Object value,
} else if (value is GeoPoint) {
return node.firestoreModule.geoPointProto
.fromLatitudeAndLongitude(value.latitude, value.longitude);
} else if (value is VectorValue) {
return node.firestoreModule.fieldValue
.vector(value.toArray().map((e) => e.toJS).toList().toJS);
} else if (value is DocumentReferenceNode) {
return value.nativeInstance;
}
Expand Down Expand Up @@ -610,6 +615,9 @@ Object? _commonSimpleTypesFromNativeValue(js.JSAny value,
} else if (value.isJSGeoPoint()) {
var nodeGeoPoint = value as node.GeoPoint;
return GeoPoint(nodeGeoPoint.latitude, nodeGeoPoint.longitude);
} else if (value.isVector()) {
var nodeVector = value as node.VectorValue;
return VectorValue(nodeVector.toDoubleList());
}

return null;
Expand Down
17 changes: 16 additions & 1 deletion firestore_node/lib/src/node/firestore_node_js_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ extension FirestoreModuleExt on FirestoreModule {
@js.JS('GeoPoint')
external GeoPointProto get geoPointProto;

// ignore: non_constant_identifier_names
@js.JS('AggregateField')
external AggregateFields get aggregateFields;

Expand Down Expand Up @@ -104,6 +103,15 @@ extension GeoPointProtoExt on GeoPointProto {
}
}

extension type VectorValue._(js.JSObject _) implements js.JSObject {}

extension VectorValueExt on VectorValue {
external js.JSArray toArray();

List<double> toDoubleList() =>
toArray().toDart.map((e) => (e as js.JSNumber).toDartDouble).toList();
}

/// Document data (for use with `DocumentReference.set()`) consists of fields
/// mapped to values.
extension type DocumentData._(js.JSObject _) implements js.JSObject {}
Expand Down Expand Up @@ -852,6 +860,10 @@ extension FieldValuesExt on FieldValues {
FieldValue arrayRemove(List<js.JSAny?> elements) =>
callMethodVarArgs('arrayRemove'.toJS, elements);
// external FieldValue arrayRemove(js.JSArray elements);

/// Vector
FieldValue vector(js.JSArray<js.JSAny> elements) =>
callMethod('vector'.toJS, elements);
}

extension type FieldValue._(js.JSObject _) implements js.JSObject {}
Expand Down Expand Up @@ -938,6 +950,9 @@ extension TekartikFirestoreNodeJsAnyExt on js.JSObject {

// instanceof(firestoreModule.geoPointProto as js.JSFunction);
bool isJSDocumentReference() => has('_firestore') && has('_path');

/// {'_values': [1]}
bool isVector() => has('_values');
// [_firestore, _path, _converter]
// has('_latitude') && has('_longitude');
}
14 changes: 6 additions & 8 deletions firestore_node/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: ^3.5.0

dependencies:
collection: '>=1.14.10'
collection: ">=1.18.0"
uuid: '>=1.0.0'
tekartik_firebase_firestore:
git:
Expand Down Expand Up @@ -40,24 +40,22 @@ dev_dependencies:
path: firestore_test
ref: dart3a
version: '>=0.8.0'
test: ">=1.2.0"
dev_build: '>=0.12.0-dev.1'
process_run: '>=0.10.2'
test: ">=1.24.0"
dev_build: ">=1.1.0+2"
process_run: ">=1.2.1+1"
# needed node dependencies
build_runner:
build_runner: ">=2.4.13"
tekartik_build_node:
git:
url: https://github.com/tekartik/build_node.dart
path: packages/build_node
ref: dart3a

dependency_overrides:
tekartik_firebase_node:
path: ../firebase_node
# temp test
_temp_dependency_overrides:
tekartik_firebase_firestore:
path: ../../firebase_firestore.dart/firestore
tekartik_firebase_firestore_test:
path: ../../firebase_firestore.dart/firestore_test
resolution: workspace

20 changes: 20 additions & 0 deletions firestore_node/test/firestore_node_no_app_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@TestOn('node')
library;

import 'dart:js_interop';

import 'package:tekartik_firebase_firestore/firestore.dart' as firestore;
import 'package:tekartik_firebase_firestore_node/src/node/firestore_node.dart';
import 'package:tekartik_firebase_firestore_node/src/node/firestore_node_js_interop.dart';
Expand All @@ -27,6 +29,9 @@ void main() {
print(cloudFirestoreModule.fieldValue.serverTimestamp());
expect(firebaseAdminFirestoreModule.fieldValue.serverTimestamp(),
cloudFirestoreModule.fieldValue.serverTimestamp());
print(jsObjectKeys(
firebaseAdminFirestoreModule.fieldValue.vector([.5.toJS].toJS)));
// [_values]
});
test('Bytes', () {
//var jsUint8Array = Uint8List.fromList([1, 2, 3]).toJS;
Expand Down Expand Up @@ -62,6 +67,20 @@ void main() {
//print(geoPoint.instanceOfString('GeoPoint')); // false
// print(geoPoint.instanceof(firestoreModule.geoPointProto as JSFunction));
});
test('Vector', () {
//print(jsObjectKeys(firestoreModule.vectorProto));
var geoPoint =
firestoreModule.geoPointProto.fromLatitudeAndLongitude(1, 2);
expect(geoPoint.isJSTimestamp(), isFalse);
expect(geoPoint.isJSGeoPoint(), isTrue);
expect(geoPoint.latitude, 1);
expect(geoPoint.longitude, 2);
print(jsObjectKeys(geoPoint));
// [_latitude, _longitude]
//print(jsObjectKeys(geoPoint.getProperty('__proto__'.toJS)));
//print(geoPoint.instanceOfString('GeoPoint')); // false
// print(geoPoint.instanceof(firestoreModule.geoPointProto as JSFunction));
});
test('fromToNative', () {
void testRoundTrip(Object? value) {
expect(fromNativeValueOrNull(toNativeValueOrNull(value)), value);
Expand All @@ -80,6 +99,7 @@ void main() {
testRoundTrip({'test': 1});
testRoundTrip([firestore.Timestamp(1, 2000)]);
testRoundTrip({'test': firestore.Timestamp(1, 2000)});
testRoundTrip(firestore.VectorValue([1]));
});
test('documentValueToNativeValue', () {});
});
Expand Down
4 changes: 4 additions & 0 deletions firestore_node/test/firestore_node_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Future<void> main() async {
}
var rootCollectionPath =
_env['TEKARTIK_FIRESTORE_NODE_TEST_ROOT_COLLECTION_PATH'];
test('support', () {
expect(firestoreServiceNode.supportsVectorValue, isTrue);
});

test('app', () {
print(
'TEKARTIK_FIRESTORE_NODE_TEST_ROOT_COLLECTION_PATH: $rootCollectionPath');
Expand Down
20 changes: 7 additions & 13 deletions functions_node/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies:
url: https://github.com/tekartik/firebase_node.dart
path: auth_node
ref: dart3a
sembast: '>=1.9.0-dev.1'
sembast: ">=3.7.4+3"
uuid: '>=1.0.0'
tekartik_fs_node:
git:
Expand All @@ -65,8 +65,8 @@ dev_dependencies:
path: app_build_menu
ref: dart3a
version: '>=0.3.0'
test: '>=1.2.0'
dev_build: '>=0.13.3+12'
test: ">=1.24.0"
dev_build: ">=1.1.0+2"
tekartik_firebase_functions_test:
git:
url: https://github.com/tekartik/firebase_functions.dart
Expand All @@ -85,10 +85,10 @@ dev_dependencies:
path: http_io
ref: dart3a
version: '>=0.1.0'
process_run: '>=0.11.1-dev.1'
process_run: ">=1.2.1+1"
# needed node dependencies
build_web_compilers:
build_runner:
build_web_compilers: ">=4.0.11"
build_runner: ">=2.4.13"
tekartik_build_node:
git:
url: https://github.com/tekartik/build_node.dart
Expand All @@ -100,13 +100,7 @@ dev_dependencies:
ref: dart3a
path: functions_call

dependency_overrides:
tekartik_firebase_firestore_node:
path: ../firestore_node
tekartik_firebase_node:
path: ../firebase_node
tekartik_firebase_auth_node:
path: ../auth_node
resolution: workspace
# Temp
# firebase_functions_interop:
# path: ../../../../github.com/tekartikdev/firebase-functions-interop
Expand Down
12 changes: 12 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: _
publish_to: none
environment:
sdk: ^3.6.0
workspace:
- auth_node
- firebase_node
- firestore_node
- functions_node
- pubsub_node
- repo_support
- storage_node
9 changes: 5 additions & 4 deletions pubsub_node/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: ^3.5.0

dependencies:
meta: '>=1.1.8'
meta: ">=1.15.0"
tekartik_app_node_utils:
git:
url: https://github.com/tekartik/app_node_utils.dart
Expand All @@ -25,18 +25,19 @@ dependencies:
ref: dart3a
path: js_utils_interop
dev_dependencies:
process_run:
test: '>=1.14.4'
process_run: ">=1.2.1+1"
test: ">=1.24.0"
tekartik_app_node_build:
git:
url: https://github.com/tekartik/app_node_utils.dart
path: app_build
ref: dart3a
version: '>=0.1.0'
# needed node dependencies
build_runner:
build_runner: ">=2.4.13"
tekartik_build_node:
git:
url: https://github.com/tekartik/build_node.dart
path: packages/build_node
ref: dart3a
resolution: workspace
11 changes: 6 additions & 5 deletions repo_support/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ environment:
sdk: ^3.5.0

dev_dependencies:
path:
pub_semver:
process_run: '>=0.10.3'
test:
dev_build:
path: ">=1.9.0"
pub_semver: ">=2.1.4"
process_run: ">=1.2.1+1"
test: ">=1.24.0"
dev_build: ">=1.1.0+2"
tekartik_app_node_build:
git:
url: https://github.com/tekartik/app_node_utils.dart
Expand All @@ -20,6 +20,7 @@ dev_dependencies:
version: '>=0.1.0'

dependency_overrides:
resolution: workspace
# Temp
# tekartik_app_node_build:
# path: ../../app_node_utils.dart/app_build
Loading

0 comments on commit 7651445

Please sign in to comment.