gingersnap 0.22.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 (251) hide show
  1. package/_virtual/_tslib.cjs +102 -0
  2. package/_virtual/_tslib.mjs +93 -0
  3. package/data/AtomicValue.d.ts +15 -0
  4. package/data/bus.cjs +179 -0
  5. package/data/bus.d.ts +72 -0
  6. package/data/bus.mjs +177 -0
  7. package/data/decoders/index.d.ts +4 -0
  8. package/data/decoders/json.cjs +12 -0
  9. package/data/decoders/json.d.ts +7 -0
  10. package/data/decoders/json.mjs +10 -0
  11. package/data/decoders/msgpack.cjs +14 -0
  12. package/data/decoders/msgpack.d.ts +7 -0
  13. package/data/decoders/msgpack.mjs +12 -0
  14. package/data/decoders/protobuf.d.ts +13 -0
  15. package/data/decoders/string.cjs +12 -0
  16. package/data/decoders/string.d.ts +7 -0
  17. package/data/decoders/string.mjs +10 -0
  18. package/data/decoders/type.d.ts +7 -0
  19. package/data/decoders.cjs +11 -0
  20. package/data/decoders.mjs +3 -0
  21. package/data/model/credentials.cjs +114 -0
  22. package/data/model/credentials.d.ts +61 -0
  23. package/data/model/credentials.mjs +109 -0
  24. package/data/model/extra.cjs +88 -0
  25. package/data/model/extra.d.ts +5 -0
  26. package/data/model/extra.mjs +66 -0
  27. package/data/model/index.d.ts +6 -0
  28. package/data/model/model.cjs +541 -0
  29. package/data/model/model.d.ts +207 -0
  30. package/data/model/model.mjs +518 -0
  31. package/data/model/plugin.cjs +96 -0
  32. package/data/model/plugin.d.ts +38 -0
  33. package/data/model/plugin.mjs +72 -0
  34. package/data/model/property.cjs +310 -0
  35. package/data/model/property.d.ts +83 -0
  36. package/data/model/property.mjs +278 -0
  37. package/data/model/types.cjs +32 -0
  38. package/data/model/types.d.ts +28 -0
  39. package/data/model/types.mjs +32 -0
  40. package/data/model.cjs +43 -0
  41. package/data/model.mjs +6 -0
  42. package/data/signal.cjs +47 -0
  43. package/data/signal.d.ts +17 -0
  44. package/data/signal.mjs +45 -0
  45. package/data/store/index.d.ts +4 -0
  46. package/data/store/json.cjs +58 -0
  47. package/data/store/json.d.ts +18 -0
  48. package/data/store/json.mjs +56 -0
  49. package/data/store/manager.cjs +206 -0
  50. package/data/store/manager.d.ts +44 -0
  51. package/data/store/manager.mjs +203 -0
  52. package/data/store/web.cjs +92 -0
  53. package/data/store/web.d.ts +25 -0
  54. package/data/store/web.mjs +89 -0
  55. package/data/value.cjs +66 -0
  56. package/data/value.mjs +64 -0
  57. package/data-structures/array/CyclicalList.cjs +57 -0
  58. package/data-structures/array/CyclicalList.d.ts +12 -0
  59. package/data-structures/array/CyclicalList.mjs +55 -0
  60. package/data-structures/array/Pair.cjs +30 -0
  61. package/data-structures/array/Pair.d.ts +17 -0
  62. package/data-structures/array/Pair.mjs +27 -0
  63. package/data-structures/array/Stack.cjs +96 -0
  64. package/data-structures/array/Stack.d.ts +41 -0
  65. package/data-structures/array/Stack.mjs +94 -0
  66. package/data-structures/array/Triple.cjs +34 -0
  67. package/data-structures/array/Triple.d.ts +19 -0
  68. package/data-structures/array/Triple.mjs +31 -0
  69. package/data-structures/array/Tuple.d.ts +8 -0
  70. package/data-structures/array/index.d.ts +5 -0
  71. package/data-structures/array.cjs +15 -0
  72. package/data-structures/array.mjs +4 -0
  73. package/data-structures/object/BufferQueue.cjs +98 -0
  74. package/data-structures/object/BufferQueue.d.ts +21 -0
  75. package/data-structures/object/BufferQueue.mjs +77 -0
  76. package/data-structures/object/CyclicalObject.cjs +155 -0
  77. package/data-structures/object/CyclicalObject.d.ts +74 -0
  78. package/data-structures/object/CyclicalObject.mjs +134 -0
  79. package/data-structures/object/Queue.cjs +178 -0
  80. package/data-structures/object/Queue.d.ts +31 -0
  81. package/data-structures/object/Queue.mjs +176 -0
  82. package/data-structures/object/SimpleQueue.cjs +53 -0
  83. package/data-structures/object/SimpleQueue.d.ts +13 -0
  84. package/data-structures/object/SimpleQueue.mjs +51 -0
  85. package/data-structures/object/TimeableObject.cjs +73 -0
  86. package/data-structures/object/TimeableObject.d.ts +30 -0
  87. package/data-structures/object/TimeableObject.mjs +71 -0
  88. package/data-structures/object/WaitableObject.cjs +61 -0
  89. package/data-structures/object/WaitableObject.d.ts +29 -0
  90. package/data-structures/object/WaitableObject.mjs +59 -0
  91. package/data-structures/object/WatchableObject.cjs +251 -0
  92. package/data-structures/object/WatchableObject.d.ts +88 -0
  93. package/data-structures/object/WatchableObject.mjs +230 -0
  94. package/data-structures/object/index.d.ts +7 -0
  95. package/data-structures/object.cjs +23 -0
  96. package/data-structures/object.mjs +7 -0
  97. package/errors/AbortError.cjs +9 -0
  98. package/errors/AbortError.d.ts +5 -0
  99. package/errors/AbortError.mjs +7 -0
  100. package/errors/CallExecutionError.cjs +13 -0
  101. package/errors/CallExecutionError.d.ts +7 -0
  102. package/errors/CallExecutionError.mjs +11 -0
  103. package/errors/FutureCancelled.cjs +11 -0
  104. package/errors/FutureCancelled.d.ts +6 -0
  105. package/errors/FutureCancelled.mjs +9 -0
  106. package/errors/FutureError.cjs +11 -0
  107. package/errors/FutureError.d.ts +6 -0
  108. package/errors/FutureError.mjs +9 -0
  109. package/errors/IllegalArgumentsError.cjs +13 -0
  110. package/errors/IllegalArgumentsError.d.ts +7 -0
  111. package/errors/IllegalArgumentsError.mjs +11 -0
  112. package/errors/IllegalOperationError.cjs +6 -0
  113. package/errors/IllegalOperationError.d.ts +2 -0
  114. package/errors/IllegalOperationError.mjs +4 -0
  115. package/errors/InvalidType.cjs +6 -0
  116. package/errors/InvalidType.d.ts +2 -0
  117. package/errors/InvalidType.mjs +4 -0
  118. package/errors/InvalidValue.cjs +11 -0
  119. package/errors/InvalidValue.d.ts +4 -0
  120. package/errors/InvalidValue.mjs +9 -0
  121. package/errors/MissingArgumentsError.cjs +13 -0
  122. package/errors/MissingArgumentsError.d.ts +7 -0
  123. package/errors/MissingArgumentsError.mjs +11 -0
  124. package/errors/NetworkError.cjs +13 -0
  125. package/errors/NetworkError.d.ts +8 -0
  126. package/errors/NetworkError.mjs +11 -0
  127. package/errors/NoSuchElement.cjs +6 -0
  128. package/errors/NoSuchElement.d.ts +2 -0
  129. package/errors/NoSuchElement.mjs +4 -0
  130. package/errors/NotImplemented.cjs +9 -0
  131. package/errors/NotImplemented.d.ts +5 -0
  132. package/errors/NotImplemented.mjs +7 -0
  133. package/errors/ParsingError.cjs +10 -0
  134. package/errors/ParsingError.d.ts +5 -0
  135. package/errors/ParsingError.mjs +8 -0
  136. package/errors/QueueEmptyError.cjs +6 -0
  137. package/errors/QueueEmptyError.d.ts +2 -0
  138. package/errors/QueueEmptyError.mjs +4 -0
  139. package/errors/QueueFullError.cjs +6 -0
  140. package/errors/QueueFullError.d.ts +2 -0
  141. package/errors/QueueFullError.mjs +4 -0
  142. package/errors/StackEmptyError.cjs +6 -0
  143. package/errors/StackEmptyError.d.ts +2 -0
  144. package/errors/StackEmptyError.mjs +4 -0
  145. package/errors/StackFullError.cjs +6 -0
  146. package/errors/StackFullError.d.ts +2 -0
  147. package/errors/StackFullError.mjs +4 -0
  148. package/errors/StreamEnded.cjs +6 -0
  149. package/errors/StreamEnded.d.ts +2 -0
  150. package/errors/StreamEnded.mjs +4 -0
  151. package/errors/TimeoutError.cjs +11 -0
  152. package/errors/TimeoutError.d.ts +6 -0
  153. package/errors/TimeoutError.mjs +9 -0
  154. package/errors/ValueDestroyedError.cjs +6 -0
  155. package/errors/ValueDestroyedError.d.ts +2 -0
  156. package/errors/ValueDestroyedError.mjs +4 -0
  157. package/errors/VerificationError.cjs +9 -0
  158. package/errors/VerificationError.d.ts +5 -0
  159. package/errors/VerificationError.mjs +7 -0
  160. package/errors/index.d.ts +18 -0
  161. package/errors.cjs +41 -0
  162. package/errors.mjs +18 -0
  163. package/files.cjs +201 -0
  164. package/files.d.ts +31 -0
  165. package/files.mjs +180 -0
  166. package/functools/index.d.ts +31 -0
  167. package/functools.cjs +371 -0
  168. package/functools.mjs +334 -0
  169. package/future/future.cjs +570 -0
  170. package/future/future.d.ts +208 -0
  171. package/future/future.mjs +548 -0
  172. package/future/group.cjs +180 -0
  173. package/future/group.d.ts +82 -0
  174. package/future/group.mjs +159 -0
  175. package/future/index.d.ts +3 -0
  176. package/future/result.cjs +19 -0
  177. package/future/result.d.ts +18 -0
  178. package/future/result.mjs +17 -0
  179. package/future.cjs +11 -0
  180. package/future.mjs +3 -0
  181. package/managers/context.d.ts +8 -0
  182. package/managers/index.d.ts +1 -0
  183. package/managers.cjs +2 -0
  184. package/managers.mjs +1 -0
  185. package/mocks.cjs +301 -0
  186. package/mocks.d.ts +125 -0
  187. package/mocks.mjs +293 -0
  188. package/networking/EventSourceService.cjs +104 -0
  189. package/networking/EventSourceService.d.ts +11 -0
  190. package/networking/EventSourceService.mjs +83 -0
  191. package/networking/NetworkService.cjs +394 -0
  192. package/networking/NetworkService.d.ts +97 -0
  193. package/networking/NetworkService.mjs +373 -0
  194. package/networking/SocketService.cjs +218 -0
  195. package/networking/SocketService.d.ts +23 -0
  196. package/networking/SocketService.mjs +197 -0
  197. package/networking/decorators/index.d.ts +4 -0
  198. package/networking/decorators/options.cjs +289 -0
  199. package/networking/decorators/options.d.ts +148 -0
  200. package/networking/decorators/options.mjs +242 -0
  201. package/networking/decorators/requests.cjs +80 -0
  202. package/networking/decorators/requests.d.ts +34 -0
  203. package/networking/decorators/requests.mjs +52 -0
  204. package/networking/decorators/socket.cjs +81 -0
  205. package/networking/decorators/socket.d.ts +13 -0
  206. package/networking/decorators/socket.mjs +51 -0
  207. package/networking/http.cjs +69 -0
  208. package/networking/http.d.ts +66 -0
  209. package/networking/http.mjs +69 -0
  210. package/networking/index.d.ts +39 -0
  211. package/networking/request.cjs +18 -0
  212. package/networking/request.d.ts +9 -0
  213. package/networking/request.mjs +16 -0
  214. package/networking/types.cjs +37 -0
  215. package/networking/types.d.ts +132 -0
  216. package/networking/types.mjs +35 -0
  217. package/networking.cjs +91 -0
  218. package/networking.mjs +33 -0
  219. package/package.json +1 -0
  220. package/reflection/injector.cjs +43 -0
  221. package/reflection/injector.d.ts +3 -0
  222. package/reflection/injector.mjs +40 -0
  223. package/socket.cjs +239 -0
  224. package/socket.d.ts +65 -0
  225. package/socket.mjs +237 -0
  226. package/store.cjs +12 -0
  227. package/store.mjs +3 -0
  228. package/stream/call.cjs +157 -0
  229. package/stream/call.d.ts +66 -0
  230. package/stream/call.mjs +154 -0
  231. package/stream/collector.cjs +217 -0
  232. package/stream/collector.d.ts +14 -0
  233. package/stream/collector.mjs +215 -0
  234. package/stream/index.d.ts +257 -0
  235. package/stream/observable.cjs +110 -0
  236. package/stream/observable.d.ts +65 -0
  237. package/stream/observable.mjs +106 -0
  238. package/stream/state.cjs +10 -0
  239. package/stream/state.d.ts +5 -0
  240. package/stream/state.mjs +8 -0
  241. package/stream.cjs +1153 -0
  242. package/stream.mjs +1132 -0
  243. package/synchronize.cjs +106 -0
  244. package/synchronize.d.ts +54 -0
  245. package/synchronize.mjs +103 -0
  246. package/typing/types.d.ts +24 -0
  247. package/typing.cjs +2 -0
  248. package/typing.mjs +1 -0
  249. package/utils/parser.cjs +37 -0
  250. package/utils/parser.d.ts +7 -0
  251. package/utils/parser.mjs +16 -0
@@ -0,0 +1,197 @@
1
+ import { __rest, __awaiter } from '../_virtual/_tslib.mjs';
2
+ import { NetworkService } from './NetworkService.mjs';
3
+ import { StreamableWebSocket } from '../socket.mjs';
4
+ import * as R from 'ramda';
5
+ import { CallExecutionError } from '../errors/CallExecutionError.mjs';
6
+ import { ParsingError } from '../errors/ParsingError.mjs';
7
+ import { Stream } from '../stream.mjs';
8
+ import { Future } from '../future/future.mjs';
9
+ import { FutureResult } from '../future/result.mjs';
10
+ import { JSONDecoder } from '../data/decoders/json.mjs';
11
+ import '@msgpack/msgpack';
12
+ import { Model } from '../data/model/model.mjs';
13
+ import '../data/model/types.mjs';
14
+ import '../data/model/credentials.mjs';
15
+
16
+ class WebSocketService extends NetworkService {
17
+ constructor(_a = {}) {
18
+ var { decoder } = _a, other = __rest(_a, ["decoder"]);
19
+ super(other !== null && other !== void 0 ? other : {});
20
+ const internals = this.__internal__;
21
+ this.socket = new StreamableWebSocket(this.baseUrl, decoder !== null && decoder !== void 0 ? decoder : (internals.classConfig.Decoder ? new internals.classConfig.Decoder() : new JSONDecoder()));
22
+ }
23
+ get connected() {
24
+ return this.socket.opened;
25
+ }
26
+ /**
27
+ * Called when socket connection is closed
28
+ * @protected
29
+ */
30
+ onceConnectionClosed() { }
31
+ /**
32
+ * Shutdown the socket connection
33
+ */
34
+ shutdown() {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ this.socket.close();
37
+ this.onceConnectionClosed();
38
+ yield this.socket.closedFuture();
39
+ });
40
+ }
41
+ /**
42
+ * Awaits socket closed
43
+ */
44
+ closedFuture() {
45
+ return this.socket.closedFuture();
46
+ }
47
+ ready() {
48
+ return Future.shield(this.socket.open());
49
+ }
50
+ __setup__() {
51
+ const internals = this.__internal__;
52
+ if (this.socket.decoder.load) {
53
+ this.socket.decoder.load();
54
+ }
55
+ const socketMethods = R.filter(([_, v]) => { var _a, _b; return ((_b = (_a = v.socketReadStream) !== null && _a !== void 0 ? _a : v.socketWriteStream) !== null && _b !== void 0 ? _b : v.socketRequestReply) !== undefined; }, R.toPairs(internals.methodConfig));
56
+ R.forEach(([key, config]) => {
57
+ var _a;
58
+ const oldMethod = this[key];
59
+ const details = (_a = internals.methodConfig[key]) === null || _a === void 0 ? void 0 : _a.socketReadStream;
60
+ let dataComparator = (v) => false;
61
+ if (config.socketReadStream) {
62
+ if (!details)
63
+ throw new ParsingError([], "ReadStreamDetailsMissing");
64
+ if (!config.responseClass)
65
+ throw new ParsingError([], "ResponseTypeMissing");
66
+ let equalsChecker;
67
+ switch (typeof details.value) {
68
+ case "boolean":
69
+ equalsChecker = R.equals(Boolean(details.value));
70
+ break;
71
+ case "string":
72
+ equalsChecker = R.equals(String(details.value));
73
+ break;
74
+ case "number":
75
+ equalsChecker = R.equals(Number(details.value));
76
+ break;
77
+ default:
78
+ if (details.value instanceof RegExp)
79
+ equalsChecker = details.value.test;
80
+ else
81
+ equalsChecker = R.equals(details.value);
82
+ }
83
+ dataComparator = R.compose((v) => equalsChecker(v), R.view(typeof details.keyPath === "string" ? R.lensProp(details.keyPath) : R.lensPath(details.keyPath)));
84
+ }
85
+ // TODO add caching for websockets
86
+ // const cacheInfo = config.cache;
87
+ // let cache: Cache<string, ArrayBuffer> | undefined;
88
+ //
89
+ // if (cacheInfo) {
90
+ // cache = this.cacheManager.createCache(
91
+ // this.baseUrl,
92
+ // cacheInfo.persist,
93
+ // async (buffer) => JSON.stringify(new Uint8Array(buffer)),
94
+ // (v) => Uint8Array.of(JSON.parse(v)).buffer,
95
+ // undefined,
96
+ // cacheInfo.duration
97
+ // );
98
+ // }
99
+ this[key] = (body) => {
100
+ var _a, _b;
101
+ if (config.socketRequestReply) {
102
+ const guid = config.socketRequestReply.guidGen();
103
+ const lens = R.lensPath(config.socketRequestReply.guidPath);
104
+ return Stream.seed(() => Future.of(() => __awaiter(this, void 0, void 0, function* () {
105
+ if (!this.socket.opened) {
106
+ yield this.socket.open();
107
+ }
108
+ let data = body;
109
+ if (body instanceof Model) {
110
+ data = body.object();
111
+ }
112
+ data = R.set(lens, guid, data);
113
+ yield this.socket.send(JSON.stringify(data));
114
+ return 1;
115
+ })))
116
+ .map(() => this.socket.streamView(R.compose(R.equals(guid), R.view(lens)), config.socketRequestReply.objectMaxSize, config.socketRequestReply.expiryPeriod))
117
+ .map((data) => {
118
+ if (config.responseClass.prototype instanceof Model) {
119
+ const ModelClass = config.responseClass;
120
+ return ModelClass.fromJSON(data);
121
+ }
122
+ return config.responseClass(data);
123
+ })
124
+ .flatten()
125
+ .map((v) => __awaiter(this, void 0, void 0, function* () {
126
+ let result = oldMethod(v);
127
+ if (result === null || result === undefined)
128
+ return v;
129
+ if (result instanceof Promise)
130
+ result = yield result;
131
+ if (result instanceof FutureResult)
132
+ result = result.value;
133
+ return result;
134
+ }));
135
+ }
136
+ else if (config.socketWriteStream) {
137
+ if (body === undefined || body === null)
138
+ throw new CallExecutionError("Empty body detected for a write stream");
139
+ return new Stream((signal) => __awaiter(this, void 0, void 0, function* () {
140
+ if (!this.socket.opened) {
141
+ yield this.socket.open();
142
+ }
143
+ if (body instanceof Model) {
144
+ yield this.socket.send(body.blob());
145
+ }
146
+ else if (body instanceof ArrayBuffer || body instanceof Blob) {
147
+ yield this.socket.send(body);
148
+ }
149
+ else {
150
+ yield this.socket.send(JSON.stringify(body));
151
+ }
152
+ const result = oldMethod();
153
+ if (result instanceof Promise) {
154
+ yield result;
155
+ }
156
+ return null;
157
+ })).once();
158
+ }
159
+ else {
160
+ let stream = this.socket.streamView(dataComparator);
161
+ if (((_a = config.socketReadStream) === null || _a === void 0 ? void 0 : _a.skip) !== undefined)
162
+ stream = stream.skip(config.socketReadStream.skip);
163
+ if (((_b = config.socketReadStream) === null || _b === void 0 ? void 0 : _b.take) !== undefined)
164
+ stream = stream.take(config.socketReadStream.take);
165
+ return stream
166
+ .map((data) => {
167
+ if (config.responseClass.prototype instanceof Model) {
168
+ const ModelClass = config.responseClass;
169
+ return ModelClass.fromJSON(data);
170
+ }
171
+ return config.responseClass(data);
172
+ })
173
+ .flatten()
174
+ .map((v) => __awaiter(this, void 0, void 0, function* () {
175
+ let result = oldMethod(v);
176
+ if (result === null || result === undefined)
177
+ return v;
178
+ if (result instanceof Promise)
179
+ result = yield result;
180
+ if (result instanceof FutureResult)
181
+ result = result.value;
182
+ return result;
183
+ }));
184
+ }
185
+ };
186
+ }, socketMethods);
187
+ if (!this.socket.opened) {
188
+ void this.socket.open();
189
+ }
190
+ const originalMethodConfig = internals.methodConfig;
191
+ internals.methodConfig = R.fromPairs(R.filter(([_, v]) => !(v.socketReadStream && v.socketWriteStream), R.toPairs(internals.methodConfig)));
192
+ super.__setup__();
193
+ internals.methodConfig = originalMethodConfig;
194
+ }
195
+ }
196
+
197
+ export { WebSocketService };
@@ -0,0 +1,4 @@
1
+ export * from "./options";
2
+ export * from "./requests";
3
+ export * from "../http";
4
+ export * from "./socket";
@@ -0,0 +1,289 @@
1
+ 'use strict';
2
+
3
+ var types = require('../types.cjs');
4
+ var R = require('ramda');
5
+ require('reflect-metadata');
6
+
7
+ function _interopNamespaceDefault(e) {
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
25
+
26
+ /// //// Constants ///////
27
+ const THROTTLE_DEFAULT_MS = 3000;
28
+ const SUPPORTED_HEADER_VALUES = ["String", "Number", "Boolean"];
29
+ /// // // Helpers ///////
30
+ const createProps = (constructor) => {
31
+ const proto = constructor.prototype;
32
+ if (proto.__internal__ === undefined) {
33
+ proto.__internal__ = { classConfig: {}, methodConfig: {} };
34
+ }
35
+ return proto;
36
+ };
37
+ const createResponseDecorator = (type) => ({ modelType, format, isArray, modelTypeMapping, modelTypeKeyPath } = {
38
+ modelType: String,
39
+ isArray: false,
40
+ }) => (target, propertyKey) => {
41
+ const proto = createProps(target.constructor);
42
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "responseType"]);
43
+ const formatLens = R__namespace.lensPath(["methodConfig", propertyKey, "dataFormat"]);
44
+ const typeLens = R__namespace.lensPath(["methodConfig", propertyKey, "responseClass"]);
45
+ const isArrayLens = R__namespace.lensPath(["methodConfig", propertyKey, "responseArray"]);
46
+ proto.__internal__ = R__namespace.set(lens, type, proto.__internal__);
47
+ proto.__internal__ = R__namespace.set(typeLens, modelType, proto.__internal__);
48
+ proto.__internal__ = R__namespace.set(isArrayLens, isArray, proto.__internal__);
49
+ proto.__internal__ = R__namespace.set(formatLens, format, proto.__internal__);
50
+ };
51
+ const createRequestBodyDecorator = (type) => (target, propertyKey, parameterIndex) => {
52
+ const proto = createProps(target.constructor);
53
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "parameters", "body"]);
54
+ proto.__internal__ = R__namespace.set(lens, { type, parameterIndex }, proto.__internal__);
55
+ };
56
+ const createRequestMultiBodyDecorator = (type) => (target, propertyKey) => {
57
+ const proto = createProps(target.constructor);
58
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "parameters", "body"]);
59
+ const changer = R__namespace.compose(R__namespace.mergeDeepLeft({ type }), R__namespace.or(R__namespace.__, {}));
60
+ proto.__internal__ = R__namespace.over(lens, changer, proto.__internal__);
61
+ };
62
+ const createRequestMultiBodyParameterDecorator = (key) => (value) => (target, propertyKey, parameterIndex) => {
63
+ const proto = createProps(target.constructor);
64
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "parameters", "body", key]);
65
+ const changer = R__namespace.compose(R__namespace.mergeDeepLeft({ [value]: parameterIndex }), R__namespace.or(R__namespace.__, {}));
66
+ proto.__internal__ = R__namespace.over(lens, changer, proto.__internal__);
67
+ };
68
+ /**
69
+ * Sets the host for the Snap Service
70
+ * @param value host
71
+ * @constructor
72
+ */
73
+ const BaseUrl = (value) => (constructor) => {
74
+ const proto = createProps(constructor);
75
+ proto.__internal__.classConfig.baseUrl = value;
76
+ };
77
+ /**
78
+ * Marks the SnapService method as on that returns a JSON Response of a specific Model type
79
+ */
80
+ const JSONResponse = createResponseDecorator(types.ResponseType.JSON);
81
+ /**
82
+ * Marks the SnapService method as on that returns a XML Response of a specific Model type
83
+ */
84
+ const XMLResponse = createResponseDecorator(types.ResponseType.XML);
85
+ /**
86
+ * Marks the SnapService method as on that returns a String Response
87
+ */
88
+ const StringResponse = createResponseDecorator(types.ResponseType.STRING)({ modelType: String });
89
+ /**
90
+ * Marks the SnapService method as on that returns a Blob
91
+ */
92
+ const BinaryResponse = createResponseDecorator(types.ResponseType.BINARY)({ modelType: Blob });
93
+ /**
94
+ * Marks the SnapService method as on that has no return value
95
+ */
96
+ const NoResponse = createResponseDecorator(types.ResponseType.NONE)();
97
+ /**
98
+ * Marks the SnapService method that it should use multipart/form-data when submitting the request
99
+ */
100
+ const Multipart = createRequestMultiBodyDecorator(types.BodyType.MULTIPART);
101
+ /**
102
+ * Marks the SnapService method that it should use application/x-www-form-urlencoded when submitting the request
103
+ */
104
+ const FormUrlEncoded = createRequestMultiBodyDecorator(types.BodyType.FORMURLENCODED);
105
+ /**
106
+ * Sets the headers for the request
107
+ * @param value MapOfHeaders
108
+ * @constructor
109
+ */
110
+ const Headers = (value) => (target, propertyKey) => {
111
+ const proto = createProps(target.constructor);
112
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "headers"]);
113
+ const changer = R__namespace.compose(R__namespace.mergeDeepLeft(value), R__namespace.or(R__namespace.__, {}));
114
+ proto.__internal__ = R__namespace.over(lens, changer, proto.__internal__);
115
+ };
116
+ /**
117
+ * Throttles the request by 3 seconds
118
+ * @param target
119
+ * @param propertyKey
120
+ * @constructor
121
+ */
122
+ const Throttle = (target, propertyKey) => {
123
+ const proto = createProps(target.constructor);
124
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "throttle"]);
125
+ proto.__internal__ = R__namespace.set(lens, { waitPeriodInMs: THROTTLE_DEFAULT_MS }, proto.__internal__);
126
+ };
127
+ /**
128
+ * Throttles the request by the value provided
129
+ * @param value ThrottleByProps - An object that contains the waitPeriodInMs
130
+ * @constructor
131
+ */
132
+ const ThrottleBy = (value) => (target, propertyKey) => {
133
+ const proto = createProps(target.constructor);
134
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "throttle"]);
135
+ proto.__internal__ = R__namespace.set(lens, value, proto.__internal__);
136
+ };
137
+ /**
138
+ * Marks this method as an authenticator. When requests receive 401 status code, this method will be called to retrieve
139
+ * the credentials
140
+ * @param type Credentials - Type of credentials that this authenticator should return
141
+ * (BasicCredentials | BearerCredentials | APIKeyCredentials | define one of your own by subclassing Credentials)
142
+ * @param global Whether this authenticator should be used across all services
143
+ * @param socketField
144
+ * @constructor
145
+ */
146
+ const Authenticator = (type, global = false, socketField = "accessToken") => (target, propertyKey) => {
147
+ const proto = createProps(target.constructor);
148
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "authenticator"]);
149
+ proto.__internal__ = R__namespace.over(lens, (v) => (Object.assign(Object.assign({}, (v !== null && v !== void 0 ? v : {})), { type, global })), proto.__internal__);
150
+ };
151
+ /**
152
+ * Marks this method as an auth refresher. Whenever a request receives a 401 status code for invalid credentials, this
153
+ * method will be called with the old Credentials, and should produce new credentials
154
+ * @param type Credentials - Type of credentials that this authenticator should return
155
+ * (BasicCredentials | BearerCredentials | APIKeyCredentials | define one of your own by subclassing Credentials)
156
+ * @param global Whether this auth refresher should be used across all services
157
+ * @constructor
158
+ */
159
+ const AuthRefresher = (type, global = false) => (target, propertyKey) => {
160
+ const proto = createProps(target.constructor);
161
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "authRefresher"]);
162
+ proto.__internal__ = R__namespace.over(lens, (v) => (Object.assign(Object.assign({}, (v !== null && v !== void 0 ? v : {})), { type, global })), proto.__internal__);
163
+ };
164
+ /**
165
+ * Marks argument as a property in the MultiPart form
166
+ */
167
+ const Part = createRequestMultiBodyParameterDecorator("parts");
168
+ /**
169
+ * Marks argument as a property in the FormUrlEncoded form or a JSON payload
170
+ */
171
+ const Field = createRequestMultiBodyParameterDecorator("fields");
172
+ /**
173
+ * Marks argument as a property in the FormUrlEncoded form or JSON payload, but it can be missing
174
+ */
175
+ const OptionalField = createRequestMultiBodyParameterDecorator("OptionalFields");
176
+ /**
177
+ * Marks argument that should be deserialized to a JSON string and attached as the body of the request
178
+ */
179
+ const JSONBody = createRequestBodyDecorator(types.BodyType.JSON);
180
+ /**
181
+ * Marks argument that should be deserialized to XML string and attached as the body of the request
182
+ */
183
+ const XMLBody = createRequestBodyDecorator(types.BodyType.XML);
184
+ /**
185
+ * Marks argument that should be the body of the request, and is a string
186
+ */
187
+ const StringBody = createRequestBodyDecorator(types.BodyType.STRING);
188
+ /**
189
+ * Marks argument that should contain a Map of the queries used in the request. Argument should be an object with each
190
+ * key value pair being the query name and value
191
+ * @constructor
192
+ */
193
+ const QueryMap = (target, propertyKey, parameterIndex) => {
194
+ const proto = createProps(target.constructor);
195
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "parameters", "queries"]);
196
+ proto.__internal__ = R__namespace.over(lens, R__namespace.compose(R__namespace.mergeLeft({ [Symbol(propertyKey)]: parameterIndex }, R__namespace.__), R__namespace.or(R__namespace.__, {})), proto.__internal__);
197
+ };
198
+ /**
199
+ * Marks argument as a path variable in the request url
200
+ * @param value Name of the path variable
201
+ * @constructor
202
+ */
203
+ const Path = (value) => {
204
+ return (target, propertyKey, parameterIndex) => {
205
+ const type = R__namespace.path([parameterIndex, "name"], Reflect.getMetadata("design:paramtypes", target, propertyKey));
206
+ if (!["String", "Number"].includes(type)) {
207
+ throw Error("Invalid type given for @Query. Should be of type string or number");
208
+ }
209
+ const proto = createProps(target.constructor);
210
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "parameters", "pathVariables"]);
211
+ proto.__internal__ = R__namespace.over(lens, R__namespace.compose(R__namespace.mergeDeepWith(R__namespace.concat, { [value]: parameterIndex }), R__namespace.or(R__namespace.__, {})), proto.__internal__);
212
+ };
213
+ };
214
+ /**
215
+ * Marks argument as a query to be attached to the request url
216
+ * @param value Name of the query
217
+ * @constructor
218
+ */
219
+ const Query = (value) => {
220
+ return (target, propertyKey, parameterIndex) => {
221
+ const proto = createProps(target.constructor);
222
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "parameters", "queries"]);
223
+ proto.__internal__ = R__namespace.over(lens, R__namespace.compose(R__namespace.mergeDeepWith(R__namespace.concat, { [value]: parameterIndex }), R__namespace.or(R__namespace.__, {})), proto.__internal__);
224
+ };
225
+ };
226
+ /**
227
+ * Marks argument as a header to be attached to the request
228
+ * @param value Name of the header
229
+ * @constructor
230
+ */
231
+ const Header = (value) => {
232
+ return (target, propertyKey, parameterIndex) => {
233
+ const type = R__namespace.path([parameterIndex, "name"], Reflect.getMetadata("design:paramtypes", target, propertyKey));
234
+ if (!SUPPORTED_HEADER_VALUES.includes(type)) {
235
+ throw Error("Invalid type given for @HeaderMap. Should be of type string, number or boolean");
236
+ }
237
+ const proto = createProps(target.constructor);
238
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "parameters", "headers"]);
239
+ proto.__internal__ = R__namespace.over(lens, R__namespace.compose(R__namespace.mergeDeepWith(R__namespace.concat, { [value]: parameterIndex }), R__namespace.or(R__namespace.__, {})), proto.__internal__);
240
+ };
241
+ };
242
+ /**
243
+ * Marks argument that should contain a Map of the headers used in the request. Argument should be an object with each
244
+ * key value pair being the header name and value
245
+ * @constructor
246
+ */
247
+ const HeaderMap = (target, propertyKey, parameterIndex) => {
248
+ const proto = createProps(target.constructor);
249
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey, "parameters", "headers"]);
250
+ const key = Symbol(propertyKey);
251
+ proto.__internal__ = R__namespace.over(lens, R__namespace.compose(R__namespace.mergeLeft({ [key]: parameterIndex }, R__namespace.__), R__namespace.or(R__namespace.__, {})), proto.__internal__);
252
+ };
253
+ /**
254
+ * Disables any authenticator that should be applied to this method
255
+ * @constructor
256
+ */
257
+ const NoAuth = (target, propertyKey) => {
258
+ const proto = createProps(target.constructor);
259
+ const lens = R__namespace.lensPath(["methodConfig", propertyKey]);
260
+ proto.__internal__ = R__namespace.set(lens, (v) => (Object.assign(Object.assign({}, (v !== null && v !== void 0 ? v : {})), { noAuth: true })), proto.__internal__);
261
+ };
262
+
263
+ exports.AuthRefresher = AuthRefresher;
264
+ exports.Authenticator = Authenticator;
265
+ exports.BaseUrl = BaseUrl;
266
+ exports.BinaryResponse = BinaryResponse;
267
+ exports.Field = Field;
268
+ exports.FormUrlEncoded = FormUrlEncoded;
269
+ exports.Header = Header;
270
+ exports.HeaderMap = HeaderMap;
271
+ exports.Headers = Headers;
272
+ exports.JSONBody = JSONBody;
273
+ exports.JSONResponse = JSONResponse;
274
+ exports.Multipart = Multipart;
275
+ exports.NoAuth = NoAuth;
276
+ exports.NoResponse = NoResponse;
277
+ exports.OptionalField = OptionalField;
278
+ exports.Part = Part;
279
+ exports.Path = Path;
280
+ exports.Query = Query;
281
+ exports.QueryMap = QueryMap;
282
+ exports.StringBody = StringBody;
283
+ exports.StringResponse = StringResponse;
284
+ exports.THROTTLE_DEFAULT_MS = THROTTLE_DEFAULT_MS;
285
+ exports.Throttle = Throttle;
286
+ exports.ThrottleBy = ThrottleBy;
287
+ exports.XMLBody = XMLBody;
288
+ exports.XMLResponse = XMLResponse;
289
+ exports.createProps = createProps;
@@ -0,0 +1,148 @@
1
+ import { MapOfHeaders, ServiceInternalProps, ThrottleByProps } from "../types";
2
+ import "reflect-metadata";
3
+ import { DataFormat } from "../../data/model";
4
+ interface ResponseDetails {
5
+ modelType?: any;
6
+ modelTypeMapping?: {
7
+ [string: string]: any;
8
+ };
9
+ modelTypeKeyPath?: string | Array<string | number>;
10
+ isArray?: boolean;
11
+ format?: DataFormat;
12
+ }
13
+ export declare const THROTTLE_DEFAULT_MS = 3000;
14
+ export declare const createProps: (constructor: any) => {
15
+ __internal__: ServiceInternalProps;
16
+ };
17
+ /**
18
+ * Sets the host for the Snap Service
19
+ * @param value host
20
+ * @constructor
21
+ */
22
+ export declare const BaseUrl: (value: string) => (constructor: any) => void;
23
+ /**
24
+ * Marks the SnapService method as on that returns a JSON Response of a specific Model type
25
+ */
26
+ export declare const JSONResponse: ({ modelType, format, isArray, modelTypeMapping, modelTypeKeyPath }?: ResponseDetails) => (target: any, propertyKey: string) => void;
27
+ /**
28
+ * Marks the SnapService method as on that returns a XML Response of a specific Model type
29
+ */
30
+ export declare const XMLResponse: ({ modelType, format, isArray, modelTypeMapping, modelTypeKeyPath }?: ResponseDetails) => (target: any, propertyKey: string) => void;
31
+ /**
32
+ * Marks the SnapService method as on that returns a String Response
33
+ */
34
+ export declare const StringResponse: (target: any, propertyKey: string) => void;
35
+ /**
36
+ * Marks the SnapService method as on that returns a Blob
37
+ */
38
+ export declare const BinaryResponse: (target: any, propertyKey: string) => void;
39
+ /**
40
+ * Marks the SnapService method as on that has no return value
41
+ */
42
+ export declare const NoResponse: (target: any, propertyKey: string) => void;
43
+ /**
44
+ * Marks the SnapService method that it should use multipart/form-data when submitting the request
45
+ */
46
+ export declare const Multipart: (target: any, propertyKey: string) => void;
47
+ /**
48
+ * Marks the SnapService method that it should use application/x-www-form-urlencoded when submitting the request
49
+ */
50
+ export declare const FormUrlEncoded: (target: any, propertyKey: string) => void;
51
+ /**
52
+ * Sets the headers for the request
53
+ * @param value MapOfHeaders
54
+ * @constructor
55
+ */
56
+ export declare const Headers: (value: MapOfHeaders) => (target: any, propertyKey: string) => void;
57
+ /**
58
+ * Throttles the request by 3 seconds
59
+ * @param target
60
+ * @param propertyKey
61
+ * @constructor
62
+ */
63
+ export declare const Throttle: (target: any, propertyKey: string) => void;
64
+ /**
65
+ * Throttles the request by the value provided
66
+ * @param value ThrottleByProps - An object that contains the waitPeriodInMs
67
+ * @constructor
68
+ */
69
+ export declare const ThrottleBy: (value: ThrottleByProps) => (target: any, propertyKey: string) => void;
70
+ /**
71
+ * Marks this method as an authenticator. When requests receive 401 status code, this method will be called to retrieve
72
+ * the credentials
73
+ * @param type Credentials - Type of credentials that this authenticator should return
74
+ * (BasicCredentials | BearerCredentials | APIKeyCredentials | define one of your own by subclassing Credentials)
75
+ * @param global Whether this authenticator should be used across all services
76
+ * @param socketField
77
+ * @constructor
78
+ */
79
+ export declare const Authenticator: <T>(type: T, global?: boolean, socketField?: string) => (target: any, propertyKey: string) => void;
80
+ /**
81
+ * Marks this method as an auth refresher. Whenever a request receives a 401 status code for invalid credentials, this
82
+ * method will be called with the old Credentials, and should produce new credentials
83
+ * @param type Credentials - Type of credentials that this authenticator should return
84
+ * (BasicCredentials | BearerCredentials | APIKeyCredentials | define one of your own by subclassing Credentials)
85
+ * @param global Whether this auth refresher should be used across all services
86
+ * @constructor
87
+ */
88
+ export declare const AuthRefresher: <T>(type: T, global?: boolean) => (target: any, propertyKey: string) => void;
89
+ /**
90
+ * Marks argument as a property in the MultiPart form
91
+ */
92
+ export declare const Part: (value: string) => (target: any, propertyKey: string, parameterIndex: number) => void;
93
+ /**
94
+ * Marks argument as a property in the FormUrlEncoded form or a JSON payload
95
+ */
96
+ export declare const Field: (value: string) => (target: any, propertyKey: string, parameterIndex: number) => void;
97
+ /**
98
+ * Marks argument as a property in the FormUrlEncoded form or JSON payload, but it can be missing
99
+ */
100
+ export declare const OptionalField: (value: string) => (target: any, propertyKey: string, parameterIndex: number) => void;
101
+ /**
102
+ * Marks argument that should be deserialized to a JSON string and attached as the body of the request
103
+ */
104
+ export declare const JSONBody: (target: any, propertyKey: string, parameterIndex: number) => void;
105
+ /**
106
+ * Marks argument that should be deserialized to XML string and attached as the body of the request
107
+ */
108
+ export declare const XMLBody: (target: any, propertyKey: string, parameterIndex: number) => void;
109
+ /**
110
+ * Marks argument that should be the body of the request, and is a string
111
+ */
112
+ export declare const StringBody: (target: any, propertyKey: string, parameterIndex: number) => void;
113
+ /**
114
+ * Marks argument that should contain a Map of the queries used in the request. Argument should be an object with each
115
+ * key value pair being the query name and value
116
+ * @constructor
117
+ */
118
+ export declare const QueryMap: (target: any, propertyKey: string, parameterIndex: number) => void;
119
+ /**
120
+ * Marks argument as a path variable in the request url
121
+ * @param value Name of the path variable
122
+ * @constructor
123
+ */
124
+ export declare const Path: (value: string) => (target: any, propertyKey: string, parameterIndex: number) => void;
125
+ /**
126
+ * Marks argument as a query to be attached to the request url
127
+ * @param value Name of the query
128
+ * @constructor
129
+ */
130
+ export declare const Query: (value: string) => (target: any, propertyKey: string, parameterIndex: number) => void;
131
+ /**
132
+ * Marks argument as a header to be attached to the request
133
+ * @param value Name of the header
134
+ * @constructor
135
+ */
136
+ export declare const Header: (value: string) => (target: any, propertyKey: string, parameterIndex: number) => void;
137
+ /**
138
+ * Marks argument that should contain a Map of the headers used in the request. Argument should be an object with each
139
+ * key value pair being the header name and value
140
+ * @constructor
141
+ */
142
+ export declare const HeaderMap: (target: any, propertyKey: string, parameterIndex: number) => void;
143
+ /**
144
+ * Disables any authenticator that should be applied to this method
145
+ * @constructor
146
+ */
147
+ export declare const NoAuth: (target: any, propertyKey: string) => void;
148
+ export {};