Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [cleanup] separate out remote doc #3030

Draft
wants to merge 4 commits into
base: feature/connected-client
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CouchbaseLite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@
69002EBE234E695600776107 /* CBLErrorMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 69002EB8234E693F00776107 /* CBLErrorMessage.m */; };
69002EBF234E695600776107 /* CBLErrorMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = 69002EA9234E693F00776107 /* CBLErrorMessage.h */; };
69002EC0234E695600776107 /* CBLErrorMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 69002EB8234E693F00776107 /* CBLErrorMessage.m */; };
6981337D28EB0BAC00BFEA7B /* CBLRemoteDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 6981337028EB0B9F00BFEA7B /* CBLRemoteDocument.h */; };
6981337E28EB0BAC00BFEA7B /* CBLRemoteDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 6981337028EB0B9F00BFEA7B /* CBLRemoteDocument.h */; };
6981337F28EB0BAD00BFEA7B /* CBLRemoteDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 6981337028EB0B9F00BFEA7B /* CBLRemoteDocument.h */; };
6981338028EB0BAD00BFEA7B /* CBLRemoteDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 6981337028EB0B9F00BFEA7B /* CBLRemoteDocument.h */; };
6981338128EB0BB300BFEA7B /* CBLRemoteDocument.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6981337128EB0B9F00BFEA7B /* CBLRemoteDocument.mm */; };
6981338228EB0BB400BFEA7B /* CBLRemoteDocument.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6981337128EB0B9F00BFEA7B /* CBLRemoteDocument.mm */; };
6981338328EB0BB500BFEA7B /* CBLRemoteDocument.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6981337128EB0B9F00BFEA7B /* CBLRemoteDocument.mm */; };
6981338428EB0BB500BFEA7B /* CBLRemoteDocument.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6981337128EB0B9F00BFEA7B /* CBLRemoteDocument.mm */; };
69845B0723354D0A00CC16BB /* DateTimeQueryFunctionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A8DD7D921C9876E00741C47 /* DateTimeQueryFunctionTest.swift */; };
72A879F01E2DD51C008466FF /* CBLBlob.mm in Sources */ = {isa = PBXBuildFile; fileRef = 72A879EF1E2DD51C008466FF /* CBLBlob.mm */; };
72A87A051E2E0E70008466FF /* CBLBlobStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A87A031E2E0E70008466FF /* CBLBlobStream.h */; };
Expand Down Expand Up @@ -2003,6 +2011,8 @@
27F961981ED8D9440060F804 /* CBLReachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CBLReachability.m; sourceTree = "<group>"; };
69002EA9234E693F00776107 /* CBLErrorMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CBLErrorMessage.h; sourceTree = "<group>"; };
69002EB8234E693F00776107 /* CBLErrorMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CBLErrorMessage.m; sourceTree = "<group>"; };
6981337028EB0B9F00BFEA7B /* CBLRemoteDocument.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CBLRemoteDocument.h; sourceTree = "<group>"; };
6981337128EB0B9F00BFEA7B /* CBLRemoteDocument.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CBLRemoteDocument.mm; sourceTree = "<group>"; };
6992582A22DFE9A100E0D1D2 /* build_xcframework.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build_xcframework.sh; sourceTree = "<group>"; };
72A879EF1E2DD51C008466FF /* CBLBlob.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CBLBlob.mm; sourceTree = "<group>"; };
72A879FE1E2DD536008466FF /* CBLBlob.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CBLBlob.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3688,6 +3698,8 @@
27D721981F8E97F400AA4458 /* CBLFleece.mm */,
27D721B81F904B2500AA4458 /* CBLNewDictionary.h */,
27D721B91F904B2500AA4458 /* CBLNewDictionary.mm */,
6981337028EB0B9F00BFEA7B /* CBLRemoteDocument.h */,
6981337128EB0B9F00BFEA7B /* CBLRemoteDocument.mm */,
);
name = Document;
sourceTree = "<group>";
Expand Down Expand Up @@ -3887,6 +3899,7 @@
9374A89F201FC49800BA0D9E /* MYBackgroundMonitor.h in Headers */,
2753AFF61EC39CA200C12E98 /* CBLHTTPLogic.h in Headers */,
93B5036F1E64B0A0002C4680 /* CBLMisc.h in Headers */,
6981337E28EB0BAC00BFEA7B /* CBLRemoteDocument.h in Headers */,
9308F3F71E64B21D00F53EE4 /* CollectionUtils.h in Headers */,
930B367724AAAB3F000DF2B3 /* CBLDatabase+Debug.h in Headers */,
93EC42E01FB386BE00D54BB4 /* CBLQueryExpression+Internal.h in Headers */,
Expand Down Expand Up @@ -4033,6 +4046,7 @@
932CC559207D9ED2000B4B78 /* CouchbaseLite.h in Headers */,
9343EF94207D611600F19A89 /* CBLQueryFullTextFunction.h in Headers */,
9343EF96207D611600F19A89 /* CBLQueryExpression.h in Headers */,
6981337F28EB0BAD00BFEA7B /* CBLRemoteDocument.h in Headers */,
9343EF97207D611600F19A89 /* CBLQueryMeta.h in Headers */,
9343EF98207D611600F19A89 /* CBLIndexBuilder.h in Headers */,
939260AC20A0F5EA00E5748C /* CBLMessagingError.h in Headers */,
Expand Down Expand Up @@ -4204,6 +4218,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
6981338028EB0BAD00BFEA7B /* CBLRemoteDocument.h in Headers */,
1AAB2784227793DE0037A880 /* CBLConflict.h in Headers */,
9343F0B5207D61AB00F19A89 /* CBLQueryResultArray.h in Headers */,
93292D9F22BD448400A0862A /* CBLReplicatorConfiguration+Swift.h in Headers */,
Expand Down Expand Up @@ -4430,6 +4445,7 @@
2753AFF51EC39CA200C12E98 /* CBLHTTPLogic.h in Headers */,
939B1B5F2009C0F200FAA3CB /* CBLQueryVariableExpression+Internal.h in Headers */,
93B72063205CA6650069F5FC /* CBLException.h in Headers */,
6981337D28EB0BAC00BFEA7B /* CBLRemoteDocument.h in Headers */,
93B41D641F0580E700A7F114 /* CBLQueryJoin.h in Headers */,
1A3471A626736E660042C6BA /* CBLQuery+N1QL.h in Headers */,
9388CC3221C18671005CA66D /* CBLLog+Internal.h in Headers */,
Expand Down Expand Up @@ -5378,6 +5394,7 @@
93E18737211122EA001D52B9 /* MYURLUtils.m in Sources */,
1A416030227D0AD40061A567 /* Conflict.swift in Sources */,
93C18E831FB638E80029B567 /* CBLDatabaseConfiguration.m in Sources */,
6981338228EB0BB400BFEA7B /* CBLRemoteDocument.mm in Sources */,
9381961C1EC113860032CC51 /* CBLFragment.m in Sources */,
93EC42E91FB3930E00D54BB4 /* CBLQueryArrayExpression.m in Sources */,
93B41D7E1F05B3A800A7F114 /* Join.swift in Sources */,
Expand Down Expand Up @@ -5632,6 +5649,7 @@
9343EF5E207D611600F19A89 /* CBLVersion.m in Sources */,
9369A6A0207DBAA9009B5B83 /* CBLDatabase+Encryption.mm in Sources */,
9343EF5F207D611600F19A89 /* CBLDatabaseConfiguration.m in Sources */,
6981338328EB0BB500BFEA7B /* CBLRemoteDocument.mm in Sources */,
9343EF60207D611600F19A89 /* CBLQueryFullTextFunction.m in Sources */,
9343EF61207D611600F19A89 /* CBLQueryArrayFunction.m in Sources */,
931713D522C182F500F1B5BF /* CBLQueryFunction+Prediction.m in Sources */,
Expand Down Expand Up @@ -5826,6 +5844,7 @@
9343F067207D61AB00F19A89 /* ResultSet.swift in Sources */,
9343F068207D61AB00F19A89 /* CBLReplicator+Backgrounding.m in Sources */,
9343F069207D61AB00F19A89 /* CBLChangeListenerToken.m in Sources */,
6981338428EB0BB500BFEA7B /* CBLRemoteDocument.mm in Sources */,
9343F06A207D61AB00F19A89 /* MYAnonymousIdentity.m in Sources */,
9343F06B207D61AB00F19A89 /* CBLIndex.m in Sources */,
9343F06C207D61AB00F19A89 /* Limit.swift in Sources */,
Expand Down Expand Up @@ -6162,6 +6181,7 @@
93DBD0132004BCE00017CA83 /* CBLURLEndpoint.m in Sources */,
27D7219B1F8E97F400AA4458 /* CBLFleece.mm in Sources */,
932EA56A2061FF7E00EDB667 /* CBLVersion.m in Sources */,
6981338128EB0BB300BFEA7B /* CBLRemoteDocument.mm in Sources */,
93C18E821FB638E80029B567 /* CBLDatabaseConfiguration.m in Sources */,
9384D8421FC405D200FE89D8 /* CBLQueryFullTextFunction.m in Sources */,
9384D80B1FC3F75700FE89D8 /* CBLQueryArrayFunction.m in Sources */,
Expand Down
19 changes: 4 additions & 15 deletions Objective-C/CBLDocument.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "MRoot.hh"
#import "CBLErrorMessage.h"
#import "CBLData.h"
#import "CBLRemoteDocument.h"

using namespace fleece;

Expand All @@ -38,7 +39,7 @@ @implementation CBLDocument
}

@synthesize database=_database, id=_id, c4Doc=_c4Doc, fleeceData=_fleeceData;
@synthesize remoteDocBody=_remoteDocBody, isRemoteDoc=_isRemoteDoc;
@synthesize remoteDoc=_remoteDoc, isRemoteDoc=_isRemoteDoc;

- (instancetype) initWithDatabase: (CBLDatabase*)database
documentID: (NSString*)documentID
Expand Down Expand Up @@ -135,32 +136,20 @@ - (instancetype) initWithDocumentID: (NSString*)documentID
revisionID: (NSString*)revisionID
body: (FLSliceResult)body {
NSParameterAssert(documentID != nil);
NSParameterAssert(revisionID != nil);
self = [self init];
if (self) {
_id = documentID;

// keeps a retained copy of body for CBLDocument & releases in dealloc
_remoteDocBody = FLSliceResult_Retain(body);
_remoteDoc = [[CBLRemoteDocument alloc] initWithBody: body];
_fleeceData = _remoteDoc.data;

FLDict dict = kFLEmptyDict;
if (body.buf) {
FLValue docBodyVal = FLValue_FromData(slice(_remoteDocBody), kFLTrusted);
dict = FLValue_AsDict(docBodyVal);
}
_fleeceData = dict;
_revID = revisionID;
_isRemoteDoc = true;
[self updateDictionary];
}
return self;
}

- (void) dealloc {
if (_remoteDocBody)
FLSliceResult_Release(_remoteDocBody); // releases the retained copy
}

#pragma mark - Public

- (NSString*) description {
Expand Down
2 changes: 1 addition & 1 deletion Objective-C/CBLMutableDocument.mm
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ - (instancetype) initWithID: (nullable NSString*)documentID
// This is used by ConnectedClient API
// Used to convert a CBLDocument to CBLMutableDocument
- (instancetype) initAsCopyOfRemoteDB: (CBLDocument*)doc {
return [self initWithDocumentID: doc.id revisionID: doc.revisionID body: doc.remoteDocBody];
return [self initWithDocumentID: doc.id revisionID: doc.revisionID body: doc.remoteDoc.body];
}

#pragma mark - Edit
Expand Down
2 changes: 1 addition & 1 deletion Objective-C/CBLRemoteDatabase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ - (instancetype) initWithURL: (NSURL*)url authenticator: (CBLAuthenticator*)auth
}

- (void) dealloc {
c4client_free(_client);
c4client_release(_client);

_client = nil;
}
Expand Down
4 changes: 2 additions & 2 deletions Objective-C/CBLReplicator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -686,15 +686,15 @@ - (void) logErrorOnDocument: (CBLReplicatedDocument*)doc pushing: (BOOL)pushing

#pragma mark - PUSH/PULL FILTER:

static bool pushFilter(C4String collectionName,
static bool pushFilter(C4CollectionSpec collectionSpec,
C4String docID, C4String revID, C4RevisionFlags flags,
FLDict flbody, void *context) {
auto replicator = (__bridge CBLReplicator*)context;
return [replicator filterDocument: docID revID: revID flags: flags
body: flbody pushing: true];
}

static bool pullFilter(C4String collectionName,
static bool pullFilter(C4CollectionSpec collectionSpec,
C4String docID, C4String revID, C4RevisionFlags flags,
FLDict flbody, void *context) {
auto replicator = (__bridge CBLReplicator*)context;
Expand Down
8 changes: 3 additions & 5 deletions Objective-C/Internal/CBLDocument+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import "CBLDictionary.h"
#import "CBLFragment.h"
#import "fleece/Fleece.h"

#import "CBLRemoteDocument.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -70,9 +70,7 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, readonly, nullable) FLDict fleeceData;

// Used by ConnectedClient API
// if the document is remoteDoc, this contains the document body
@property (nonatomic, readonly) FLSliceResult remoteDocBody;
@property (nonatomic, nullable, readonly) CBLRemoteDocument* remoteDoc;

// Document is from remote-DB or a regular-DB
@property (nonatomic, readonly) BOOL isRemoteDoc;
Expand Down Expand Up @@ -106,7 +104,7 @@ NS_ASSUME_NONNULL_BEGIN
Used to create a CBLDocument without database and c4doc
Will retain the passed in `body`(FLSliceResult) */
- (instancetype) initWithDocumentID: (NSString*)documentID
revisionID: (NSString*)revisionID
revisionID: (nullable NSString*)revisionID
body: (FLSliceResult)body;

- (BOOL) selectConflictingRevision;
Expand Down
40 changes: 40 additions & 0 deletions Objective-C/Internal/CBLRemoteDocument.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// CBLRemoteDocument.h
// CouchbaseLite
//
// Copyright (c) 2022 Couchbase, Inc All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/** Interface used by the remote database */
@interface CBLRemoteDocument : NSObject

/** if the document is remoteDoc, this contains the document body */
@property (nonatomic, readonly) FLSliceResult body;
@property (nonatomic, readonly) FLDict data;

/**
This constructor is used by ConnectedClient APIs.
Used to create a CBLDocument without database and c4doc
Will retain the passed in `body`(FLSliceResult) */
- (instancetype) initWithBody: (FLSliceResult)body;


@end

NS_ASSUME_NONNULL_END
56 changes: 56 additions & 0 deletions Objective-C/Internal/CBLRemoteDocument.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// CBLRemoteDocument.m
// CouchbaseLite
//
// Copyright (c) 2022 Couchbase, Inc All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "CBLRemoteDocument.h"
#import "CBLFleece.hh"
#include "fleece/FLExpert.h"

using namespace fleece;

@implementation CBLRemoteDocument {
FLDict _dict;
}

@synthesize body=_body;

- (instancetype) initWithBody:(FLSliceResult)body {
self = [self init];
if (self) {
// keeps a retained copy of body for CBLDocument & releases in dealloc
_body = FLSliceResult_Retain(body);

_dict = kFLEmptyDict;
if (body.buf) {
FLValue docBodyVal = FLValue_FromData(slice(_body), kFLTrusted);
_dict = FLValue_AsDict(docBodyVal);
}
}
return self;
}

- (FLDict) data {
return _dict;
}

- (void) dealloc {
if (_body)
FLSliceResult_Release(_body); // releases the retained copy
}

@end
1 change: 1 addition & 0 deletions Objective-C/Internal/Replicator/CBLWebSocket.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "c4Socket.h"
#import "MYURLUtils.h"
#import "fleece/Fleece.hh"
#import "fleece/Expert.hh" // for AllocedDict
#import <CommonCrypto/CommonDigest.h>
#import <dispatch/dispatch.h>
#import <memory>
Expand Down
Loading