-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathSLObject.h
264 lines (235 loc) · 9.22 KB
/
SLObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/**
* @file SLObject.h
*
* @author Michael Schoonmaker
* @copyright (c) 2013 StrongLoop. All rights reserved.
*/
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h> // for CLLocation
#import "SLAdapter.h"
/**
* An error description for SLObjects with an invalid repository, which happens
* when SLObjects are created improperly.
*/
extern NSString *SLObjectInvalidRepositoryDescription;
@class SLRepository;
/**
* A local representative of a single virtual object. The behaviour of this
* object is defined through a prototype defined on the server, and the identity
* of this instance is defined through its `creationParameters`.
*/
@interface SLObject : NSObject
/** The SLRepository defining the type of this object. */
@property (readonly, nonatomic, strong) SLRepository *repository;
/**
* The complete set of parameters to be used to identify/create this object on
* the server.
*/
@property (readonly, nonatomic, strong) NSDictionary *creationParameters;
/**
* Returns a new object with the type defined by given repository.
*
* @param repository The repository this object is associated with.
* @param parameters The creationParameters of the new object.
* @return A new object.
*/
+ (instancetype)objectWithRepository:(SLRepository *)repository
parameters:(NSDictionary *)parameters;
/**
* Initializes a new object with the type defined by the given repository.
*
* @param repository The repository this object is associated with.
* @param parameters The creationParameters of the new object.
* @return The new object.
*/
- (instancetype)initWithRepository:(SLRepository *)repository
parameters:(NSDictionary *)parameters;
/**
* Invokes a remotable method exposed within instances of this class on the
* server.
*
* @see SLAdapter::invokeInstanceMethod:constructorParameters:parameters:success:failure:
*
* @param name The method to invoke (without the prototype), e.g.
* `doSomething`.
* @param parameters The parameters to invoke with.
* @param success An SLSuccessBlock to be executed when the invocation
* succeeds.
* @param failure An SLFailureBlock to be executed when the invocation
* fails.
*/
- (void)invokeMethod:(NSString *)name
parameters:(NSDictionary *)parameters
success:(SLSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Invokes a remotable method exposed within instances of this class on the
* server.
*
* @see SLAdapter::invokeInstanceMethod:constructorParameters:parameters:success:failure:
*
* @param name The method to invoke (without the prototype), e.g.
* `doSomething`.
* @param parameters The parameters to invoke with.
* @param bodyParameters The parameters that get JSON encoded and put into
* the message body when the verb is POST or PUT.
* @param success An SLSuccessBlock to be executed when the invocation
* succeeds.
* @param failure An SLFailureBlock to be executed when the invocation
* fails.
*/
- (void)invokeMethod:(NSString *)name
parameters:(NSDictionary *)parameters
bodyParameters:(NSDictionary *)bodyParameters
success:(SLSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Invokes a remotable method exposed within instances of this class on the
* server.
*
* @see SLAdapter::invokeInstanceMethod:constructorParameters:parameters:outputStream:success:failure:
*
* @param name The method to invoke (without the prototype), e.g.
* `doSomething`.
* @param parameters The parameters to invoke with.
* @param outputStream The stream to which all the response data goes.
* @param success An SLSuccessBlock to be executed when the invocation
* succeeds.
* @param failure An SLFailureBlock to be executed when the invocation
* fails.
*/
- (void)invokeMethod:(NSString *)name
parameters:(NSDictionary *)parameters
outputStream:(NSOutputStream *)outputStream
success:(SLSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Converts encoded Date value to an NSDate object following the argument encoding rule.
*
* @param value The argument value to be converted.
*/
+ (NSDate *)dateFromEncodedArgument:(NSDictionary *)value;
/**
* Converts encoded Buffer value to an NSData object following the argument encoding rule.
*
* @param value The argument value to be converted.
*/
+ (NSData *)dataFromEncodedArgument:(NSDictionary *)value;
/**
* Converts encoded GeoPoint value to a CLLocation object following the argument encoding rule.
*
* @param value The argument value to be converted.
*/
+ (CLLocation *)locationFromEncodedArgument:(NSDictionary *)value;
/**
* Converts encoded Date value to an NSDate object following the property encoding rule.
*
* @param value The property value to be converted.
*/
+ (NSDate *)dateFromEncodedProperty:(NSString *)value;
/**
* Converts encoded Buffer value to an NSData object following the property encoding rule.
*
* @param value The property value to be converted.
*/
+ (NSMutableData *)dataFromEncodedProperty:(NSDictionary *)value;
/**
* Converts encoded GeoPoint value to a CLLocation object following the property encoding rule.
*
* @param value The property value to be converted.
*/
+ (CLLocation *)locationFromEncodedProperty:(NSDictionary *)value;
@end
/**
* A local representative of classes ("prototypes" in JavaScript) defined and
* made remotable on the server.
*/
@interface SLRepository : NSObject
/** The name given to this class on the server. */
@property (readonly, nonatomic, copy) NSString *className;
/**
* The SLAdapter that should be used for invoking methods, both for static
* methods on this repository and all methods on all instances of this class.
*/
@property (readwrite, nonatomic) SLAdapter *adapter;
/**
* Returns a new Repository representing the named remote class.
*
* @param name The remote class name.
* @return A repository.
*/
+ (instancetype)repositoryWithClassName:(NSString *)name;
/**
* Initializes a new Repository, associating it with the named remote class.
*
* @param name The remote class name.
* @return The repository.
*/
- (instancetype)initWithClassName:(NSString *)name;
/**
* Returns a new SLObject as a virtual instance of this remote class.
*
* @param parameters The `creationParameters` of the new SLObject.
* @return A new SLObject based on this class.
*/
- (SLObject *)objectWithParameters:(NSDictionary *)parameters;
/**
* Invokes a remotable method exposed statically within this class on the
* server.
*
* @see SLAdapter::invokeStaticMethod:parameters:success:failure:
*
* @param name The method to invoke (without the class name), e.g.
* `doSomething`.
* @param parameters The parameters to invoke with.
* @param success An SLSuccessBlock to be executed when the invocation
* succeeds.
* @param failure An SLFailureBlock to be executed when the invocation
* fails.
*/
- (void)invokeStaticMethod:(NSString *)name
parameters:(NSDictionary *)parameters
success:(SLSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Invokes a remotable method exposed statically within this class on the
* server.
*
* @see SLAdapter::invokeStaticMethod:parameters:success:failure:
*
* @param name The method to invoke (without the class name), e.g.
* `doSomething`.
* @param parameters The parameters to invoke with.
* @param bodyParameters The parameters that get JSON encoded and put into
* the message body when the verb is POST or PUT.
* @param success An SLSuccessBlock to be executed when the invocation
* succeeds.
* @param failure An SLFailureBlock to be executed when the invocation
* fails.
*/
- (void)invokeStaticMethod:(NSString *)name
parameters:(NSDictionary *)parameters
bodyParameters:(NSDictionary *)bodyParameters
success:(SLSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Invokes a remotable method exposed statically within this class on the
* server.
*
* @see SLAdapter::invokeStaticMethod:parameters:outputStream:success:failure:
*
* @param name The method to invoke (without the class name), e.g.
* `doSomething`.
* @param parameters The parameters to invoke with.
* @param outputStream The stream to which all the response data goes.
* @param success An SLSuccessBlock to be executed when the invocation
* succeeds.
* @param failure An SLFailureBlock to be executed when the invocation
* fails.
*/
- (void)invokeStaticMethod:(NSString *)name
parameters:(NSDictionary *)parameters
outputStream:(NSOutputStream *)outputStream
success:(SLSuccessBlock)success
failure:(SLFailureBlock)failure;
@end