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,278 @@
1
+ import * as R from 'ramda';
2
+ import { namespacedModelInternalProps, Optional, Model } from './model.mjs';
3
+ import { InvalidType } from '../../errors/InvalidType.mjs';
4
+ import { InvalidValue } from '../../errors/InvalidValue.mjs';
5
+ import { DataType } from './types.mjs';
6
+
7
+ /**
8
+ * Creates a decorator that updates a field
9
+ * @param functor updater function
10
+ * @returns a decorator
11
+ */
12
+ const createFieldUpdater = (functor) => (target, key) => {
13
+ var _a;
14
+ const props = (_a = namespacedModelInternalProps.get(target.constructor.name)) !== null && _a !== void 0 ? _a : {
15
+ fields: new Map(),
16
+ };
17
+ const field = R.find((v) => v === key, Array.from(props.fields.keys()));
18
+ if (!field) {
19
+ throw new Error(`No field found that matches ${key}`);
20
+ }
21
+ functor({ field: props.fields.get(field), target, key });
22
+ props.parent = Object.getPrototypeOf(target).constructor.name;
23
+ namespacedModelInternalProps.set(target.constructor.name, props);
24
+ };
25
+ /**
26
+ * Creates a validator decorator
27
+ * @param functor validation function
28
+ * @param error error to be thrown when validation fails
29
+ * @param updater optional argument to update the current field
30
+ * @returns a decorator
31
+ */
32
+ const createValidator = (functor, error, updater) => createFieldUpdater(({ field, target, key }) => {
33
+ const symbol = Symbol(key);
34
+ Object.defineProperty(target, key, {
35
+ get: function () {
36
+ return this[symbol];
37
+ },
38
+ set: function (v) {
39
+ if (v instanceof Optional) {
40
+ if (v.isPresent()) {
41
+ v = v.get();
42
+ }
43
+ else {
44
+ this[symbol] = v;
45
+ return;
46
+ }
47
+ }
48
+ if (!functor(v))
49
+ throw error;
50
+ this[symbol] = v;
51
+ },
52
+ });
53
+ if (updater)
54
+ updater(field);
55
+ });
56
+ /**
57
+ * A property that exist in the incoming data
58
+ * @param name Name of the property in the incoming data. If not provided, the variable name will be assumed as the
59
+ * property name
60
+ * @param type type of the field. Not required (useful when the field is an Optional)
61
+ * @constructor
62
+ */
63
+ const Field = (name, type = undefined) => (target, key) => {
64
+ var _a, _b, _c, _d;
65
+ const schema = {};
66
+ const props = (_a = namespacedModelInternalProps.get(target.constructor.name)) !== null && _a !== void 0 ? _a : {
67
+ fields: new Map(),
68
+ };
69
+ const dtype = Reflect.getMetadata("design:type", target, key);
70
+ const fieldProp = (_b = props.fields.get(key)) !== null && _b !== void 0 ? _b : {};
71
+ if (type && dtype === Optional) {
72
+ schema.options = { useOptionalObj: true };
73
+ fieldProp.ignore = Object.assign(Object.assign({}, ((_c = fieldProp.ignore) !== null && _c !== void 0 ? _c : {})), { deserialize: true });
74
+ }
75
+ else if (!type) {
76
+ type = dtype;
77
+ }
78
+ else if (!(dtype instanceof type)) {
79
+ throw new InvalidType(`Type mismatch for property ${key}`);
80
+ }
81
+ if (type instanceof Number) {
82
+ schema.dataType = DataType.DOUBLE;
83
+ }
84
+ else if (type instanceof String) {
85
+ schema.dataType = DataType.STRING;
86
+ }
87
+ else if (type instanceof Boolean) {
88
+ schema.dataType = DataType.BOOLEAN;
89
+ }
90
+ else if (type instanceof Model) {
91
+ schema.dataType = DataType.RECORD;
92
+ schema.options = Object.assign(Object.assign({}, ((_d = schema.options) !== null && _d !== void 0 ? _d : {})), { recordClass: type });
93
+ }
94
+ fieldProp.name = name !== null && name !== void 0 ? name : key;
95
+ fieldProp.Type = type;
96
+ fieldProp.isArray = false;
97
+ fieldProp.schema = schema;
98
+ props.fields.set(key, fieldProp);
99
+ if (name) {
100
+ if (fieldProp.aliases) {
101
+ fieldProp.aliases.push(name);
102
+ }
103
+ else {
104
+ fieldProp.aliases = [name];
105
+ }
106
+ }
107
+ props.parent = Object.getPrototypeOf(target).constructor.name;
108
+ namespacedModelInternalProps.set(target.constructor.name, props);
109
+ };
110
+ /**
111
+ * A property that exists on the incoming data, that contains an array of same data types
112
+ * @param type Type of data in the array
113
+ * @param name Name of the property in the incoming data. If not provided, the variable name will be assumed as the
114
+ * property name
115
+ * @constructor
116
+ */
117
+ const ArrayField = (type, name) => (target, key) => {
118
+ var _a, _b;
119
+ const props = (_a = namespacedModelInternalProps.get(target.constructor.name)) !== null && _a !== void 0 ? _a : {
120
+ fields: new Map(),
121
+ };
122
+ const schema = { dataType: DataType.ARRAY };
123
+ const dtype = Reflect.getMetadata("design:type", target, key);
124
+ const optional = dtype === Optional;
125
+ schema.options = { useOptionalObj: optional, optional };
126
+ if (type instanceof Number) {
127
+ schema.itemType = DataType.DOUBLE;
128
+ }
129
+ else if (type instanceof String) {
130
+ schema.itemType = DataType.STRING;
131
+ }
132
+ else if (type instanceof Boolean) {
133
+ schema.itemType = DataType.BOOLEAN;
134
+ }
135
+ else if (type instanceof Model) {
136
+ schema.options.recordClass = type;
137
+ }
138
+ const fieldProp = (_b = props.fields.get(key)) !== null && _b !== void 0 ? _b : {};
139
+ fieldProp.name = key;
140
+ fieldProp.Type = type;
141
+ fieldProp.isArray = true;
142
+ fieldProp.schema = schema;
143
+ props.fields.set(key, fieldProp);
144
+ if (name) {
145
+ if (fieldProp.aliases) {
146
+ fieldProp.aliases.push(name);
147
+ }
148
+ else {
149
+ fieldProp.aliases = [name];
150
+ }
151
+ }
152
+ props.parent = Object.getPrototypeOf(target).constructor.name;
153
+ namespacedModelInternalProps.set(target.constructor.name, props);
154
+ };
155
+ /**
156
+ * A property that exists on the incoming data, that contains an object/array that can be represented as a hashmap
157
+ * @param keyType type for the keys in the map
158
+ * @param valueType type for the values in the map
159
+ * @param name optional name of the field
160
+ * @constructor
161
+ */
162
+ const MapField = (keyType, valueType, name) => (target, key) => {
163
+ var _a, _b;
164
+ const props = (_a = namespacedModelInternalProps.get(target.constructor.name)) !== null && _a !== void 0 ? _a : {
165
+ fields: new Map(),
166
+ };
167
+ const schema = { dataType: DataType.MAP };
168
+ const dtype = Reflect.getMetadata("design:type", target, key);
169
+ const optional = dtype === Optional;
170
+ schema.options = { useOptionalObj: optional, optional };
171
+ const fieldProp = (_b = props.fields.get(key)) !== null && _b !== void 0 ? _b : {};
172
+ fieldProp.name = key;
173
+ fieldProp.Type = Map;
174
+ fieldProp.isMap = true;
175
+ fieldProp.KeyType = keyType;
176
+ fieldProp.ValueType = valueType;
177
+ fieldProp.schema = schema;
178
+ props.fields.set(key, fieldProp);
179
+ if (name) {
180
+ props.fields.set(name, fieldProp);
181
+ }
182
+ props.parent = Object.getPrototypeOf(target).constructor.name;
183
+ namespacedModelInternalProps.set(target.constructor.name, props);
184
+ };
185
+ /**
186
+ * Alternative name for the associated field
187
+ * @param name
188
+ */
189
+ const Alias = (name) => createFieldUpdater(({ field }) => {
190
+ var _a;
191
+ const aliases = (_a = field.aliases) !== null && _a !== void 0 ? _a : [];
192
+ aliases.push(name);
193
+ field.aliases = aliases;
194
+ });
195
+ /**
196
+ * Makes the given property only readable
197
+ * @constructor
198
+ */
199
+ const Readonly = (target, key) => {
200
+ var _a, _b;
201
+ const props = (_a = namespacedModelInternalProps.get(target.constructor.name)) !== null && _a !== void 0 ? _a : {
202
+ fields: new Map(),
203
+ };
204
+ const fieldProps = (_b = props.fields.get(key)) !== null && _b !== void 0 ? _b : {};
205
+ fieldProps.readonly = true;
206
+ props.fields.set(key, fieldProps);
207
+ props.parent = Object.getPrototypeOf(target).constructor.name;
208
+ namespacedModelInternalProps.set(target.constructor.name, props);
209
+ };
210
+ /**
211
+ * Validates the value assigned to the associated property
212
+ * @param matcher functor to check if the assigned value is valid
213
+ */
214
+ const Validator = (matcher) => createValidator(matcher instanceof Function ? matcher : matcher instanceof RegExp ? (v) => matcher.test(v) : (v) => v === matcher, new InvalidValue(`Invalid value assigned`));
215
+ /**
216
+ * Raises an error if the field contains an error
217
+ * @constructor
218
+ */
219
+ const RaiseError = createFieldUpdater(({ field, target, key }) => {
220
+ const symbol = Symbol(key);
221
+ Object.defineProperty(target, key, {
222
+ get: function () {
223
+ return this[symbol];
224
+ },
225
+ set: function (v) {
226
+ if (v) {
227
+ throw v instanceof Error ? v : new Error(v);
228
+ }
229
+ this[symbol] = v;
230
+ },
231
+ });
232
+ });
233
+ /**
234
+ * Ignores the annotated field during deserialization (by default) and/or serialization
235
+ * @param value an object for enabling/disabling which directions should ignore be used
236
+ * @constructor
237
+ */
238
+ const Ignore = (value = { serialize: false, deserialize: true }) => createFieldUpdater(({ field }) => {
239
+ var _a, _b;
240
+ field.ignore = value;
241
+ if (value.serialize)
242
+ delete field.schema;
243
+ else if (field.schema) {
244
+ const options = (_b = (_a = field.schema) === null || _a === void 0 ? void 0 : _a.options) !== null && _b !== void 0 ? _b : {};
245
+ options.optional = true;
246
+ field.schema.options = options;
247
+ }
248
+ });
249
+ /**
250
+ * Registers a schema type for the given field
251
+ * @param dataType
252
+ * @param options
253
+ */
254
+ const SchemaType = (dataType, options) => createFieldUpdater(({ field }) => (field.schema = {
255
+ dataType,
256
+ options,
257
+ }));
258
+ /**
259
+ * Decorator that applies a lower limit validation on a numeric field
260
+ * @param value limit
261
+ * @param inclusive should the limit be included. Default is false
262
+ */
263
+ const LowerBound = (value, inclusive = true) => createValidator(inclusive ? (v) => v >= value : (v) => v > value, new InvalidValue(`value is lower than the minimum value of ${value}`));
264
+ /**
265
+ * Decorator that applies an upper limit validation on a numeric field
266
+ * @param value limit
267
+ * @param inclusive should the limit be included. Default is false
268
+ */
269
+ const UpperBound = (value, inclusive = false) => createValidator(inclusive ? (v) => v <= value : (v) => v < value, new InvalidValue(`value is higher than the maximum value of ${value}`));
270
+ /**
271
+ * Decorator that applies a range validation on a numeric field
272
+ * @param lower lower bound
273
+ * @param upper upper bound
274
+ * @param inclusive should the upper bound be included. Default is false
275
+ */
276
+ const Range = (lower, upper, inclusive = false) => createValidator(inclusive ? (v) => lower <= v && v <= upper : (v) => lower <= v && v < upper, new InvalidValue(`value is not within the range of ${lower} <= v ` + (inclusive ? `<= ${upper}` : `< ${upper}`)));
277
+
278
+ export { Alias, ArrayField, Field, Ignore, LowerBound, MapField, RaiseError, Range, Readonly, SchemaType, UpperBound, Validator };
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Formatting used with converting data to models
5
+ */
6
+ exports.DataFormat = void 0;
7
+ (function (DataFormat) {
8
+ DataFormat[DataFormat["CSV"] = 0] = "CSV";
9
+ DataFormat[DataFormat["XML"] = 1] = "XML";
10
+ DataFormat[DataFormat["JSON"] = 2] = "JSON";
11
+ DataFormat[DataFormat["MESSAGE_PACK"] = 3] = "MESSAGE_PACK";
12
+ })(exports.DataFormat || (exports.DataFormat = {}));
13
+ /**
14
+ * Supported data types
15
+ * @beta
16
+ */
17
+ exports.DataType = void 0;
18
+ (function (DataType) {
19
+ DataType["RECORD"] = "record";
20
+ DataType["NULL"] = "null";
21
+ DataType["BOOLEAN"] = "boolean";
22
+ DataType["INT"] = "int";
23
+ DataType["LONG"] = "long";
24
+ DataType["FLOAT"] = "float";
25
+ DataType["DOUBLE"] = "double";
26
+ DataType["BYTES"] = "bytes";
27
+ DataType["STRING"] = "string";
28
+ DataType["ENUM"] = "enum";
29
+ DataType["MAP"] = "map";
30
+ DataType["FIXED_STRING"] = "fixed";
31
+ DataType["ARRAY"] = "array";
32
+ })(exports.DataType || (exports.DataType = {}));
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Formatting used with converting data to models
3
+ */
4
+ export declare enum DataFormat {
5
+ CSV = 0,
6
+ XML = 1,
7
+ JSON = 2,
8
+ MESSAGE_PACK = 3
9
+ }
10
+ /**
11
+ * Supported data types
12
+ * @beta
13
+ */
14
+ export declare enum DataType {
15
+ RECORD = "record",
16
+ NULL = "null",
17
+ BOOLEAN = "boolean",
18
+ INT = "int",
19
+ LONG = "long",
20
+ FLOAT = "float",
21
+ DOUBLE = "double",
22
+ BYTES = "bytes",
23
+ STRING = "string",
24
+ ENUM = "enum",
25
+ MAP = "map",
26
+ FIXED_STRING = "fixed",
27
+ ARRAY = "array"
28
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Formatting used with converting data to models
3
+ */
4
+ var DataFormat;
5
+ (function (DataFormat) {
6
+ DataFormat[DataFormat["CSV"] = 0] = "CSV";
7
+ DataFormat[DataFormat["XML"] = 1] = "XML";
8
+ DataFormat[DataFormat["JSON"] = 2] = "JSON";
9
+ DataFormat[DataFormat["MESSAGE_PACK"] = 3] = "MESSAGE_PACK";
10
+ })(DataFormat || (DataFormat = {}));
11
+ /**
12
+ * Supported data types
13
+ * @beta
14
+ */
15
+ var DataType;
16
+ (function (DataType) {
17
+ DataType["RECORD"] = "record";
18
+ DataType["NULL"] = "null";
19
+ DataType["BOOLEAN"] = "boolean";
20
+ DataType["INT"] = "int";
21
+ DataType["LONG"] = "long";
22
+ DataType["FLOAT"] = "float";
23
+ DataType["DOUBLE"] = "double";
24
+ DataType["BYTES"] = "bytes";
25
+ DataType["STRING"] = "string";
26
+ DataType["ENUM"] = "enum";
27
+ DataType["MAP"] = "map";
28
+ DataType["FIXED_STRING"] = "fixed";
29
+ DataType["ARRAY"] = "array";
30
+ })(DataType || (DataType = {}));
31
+
32
+ export { DataFormat, DataType };
package/data/model.cjs ADDED
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var model = require('./model/model.cjs');
4
+ var property = require('./model/property.cjs');
5
+ var types = require('./model/types.cjs');
6
+ var credentials = require('./model/credentials.cjs');
7
+ var plugin = require('./model/plugin.cjs');
8
+ var extra = require('./model/extra.cjs');
9
+
10
+
11
+
12
+ exports.Model = model.Model;
13
+ exports.Optional = model.Optional;
14
+ exports.Alias = property.Alias;
15
+ exports.ArrayField = property.ArrayField;
16
+ exports.Field = property.Field;
17
+ exports.Ignore = property.Ignore;
18
+ exports.LowerBound = property.LowerBound;
19
+ exports.MapField = property.MapField;
20
+ exports.RaiseError = property.RaiseError;
21
+ exports.Range = property.Range;
22
+ exports.Readonly = property.Readonly;
23
+ exports.SchemaType = property.SchemaType;
24
+ exports.UpperBound = property.UpperBound;
25
+ exports.Validator = property.Validator;
26
+ Object.defineProperty(exports, 'DataFormat', {
27
+ enumerable: true,
28
+ get: function () { return types.DataFormat; }
29
+ });
30
+ Object.defineProperty(exports, 'DataType', {
31
+ enumerable: true,
32
+ get: function () { return types.DataType; }
33
+ });
34
+ exports.APIKeyCredentials = credentials.APIKeyCredentials;
35
+ exports.BasicCredentials = credentials.BasicCredentials;
36
+ exports.BearerCredentials = credentials.BearerCredentials;
37
+ exports.Credentials = credentials.Credentials;
38
+ exports.createModelClassAnnotationTag = plugin.createModelClassAnnotationTag;
39
+ exports.createModelFieldAnnotationTag = plugin.createModelFieldAnnotationTag;
40
+ exports.getModelClassAnnotationTagProperties = plugin.getModelClassAnnotationTagProperties;
41
+ exports.getModelFieldAnnotationTagProperties = plugin.getModelFieldAnnotationTagProperties;
42
+ exports.Union = extra.Union;
43
+ exports.View = extra.View;
package/data/model.mjs ADDED
@@ -0,0 +1,6 @@
1
+ export { Model, Optional } from './model/model.mjs';
2
+ export { Alias, ArrayField, Field, Ignore, LowerBound, MapField, RaiseError, Range, Readonly, SchemaType, UpperBound, Validator } from './model/property.mjs';
3
+ export { DataFormat, DataType } from './model/types.mjs';
4
+ export { APIKeyCredentials, BasicCredentials, BearerCredentials, Credentials } from './model/credentials.mjs';
5
+ export { createModelClassAnnotationTag, createModelFieldAnnotationTag, getModelClassAnnotationTagProperties, getModelFieldAnnotationTagProperties } from './model/plugin.mjs';
6
+ export { Union, View } from './model/extra.mjs';
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var stream = require('../stream.cjs');
4
+ require('../data-structures/object/WatchableObject.cjs');
5
+ require('object-hash');
6
+ require('ramda');
7
+ require('../_virtual/_tslib.cjs');
8
+ require('uuid');
9
+ var Queue = require('../data-structures/object/Queue.cjs');
10
+
11
+ class Signal {
12
+ constructor(source) {
13
+ this.subscribers = new Set();
14
+ this.source = source instanceof stream.Stream ? source : source.streamEntries;
15
+ }
16
+ start() {
17
+ this.task = this.source.forEach((value) => {
18
+ for (const subscriber of this.subscribers) {
19
+ subscriber(value);
20
+ }
21
+ });
22
+ }
23
+ stop() {
24
+ var _a;
25
+ (_a = this.task) === null || _a === void 0 ? void 0 : _a.cancel();
26
+ }
27
+ subscribe(callback) {
28
+ this.subscribers.add(callback);
29
+ if (this.latestValue !== undefined) {
30
+ callback(this.latestValue);
31
+ }
32
+ return {
33
+ cancel: () => {
34
+ this.subscribers.delete(callback);
35
+ },
36
+ };
37
+ }
38
+ stream(objectMaxSize, expiryPeriod) {
39
+ const queue = new Queue.Queue(objectMaxSize, expiryPeriod);
40
+ const token = this.subscribe((value) => {
41
+ queue.enqueue(value);
42
+ });
43
+ return queue.streamEntries.onCancellation(token.cancel);
44
+ }
45
+ }
46
+
47
+ exports.Signal = Signal;
@@ -0,0 +1,17 @@
1
+ import { Stream } from "../stream";
2
+ import { WaitPeriod } from "../future";
3
+ import { Queue } from "../data-structures/object";
4
+ export interface Token {
5
+ cancel: () => void;
6
+ }
7
+ export declare class Signal<T> {
8
+ private readonly subscribers;
9
+ private readonly latestValue;
10
+ private task?;
11
+ private readonly source;
12
+ constructor(source: Stream<T> | Queue<T>);
13
+ start(): void;
14
+ stop(): void;
15
+ subscribe(callback: (value: T) => void): Token;
16
+ stream(objectMaxSize?: number, expiryPeriod?: WaitPeriod): Stream<T>;
17
+ }
@@ -0,0 +1,45 @@
1
+ import { Stream } from '../stream.mjs';
2
+ import '../data-structures/object/WatchableObject.mjs';
3
+ import 'object-hash';
4
+ import 'ramda';
5
+ import '../_virtual/_tslib.mjs';
6
+ import 'uuid';
7
+ import { Queue } from '../data-structures/object/Queue.mjs';
8
+
9
+ class Signal {
10
+ constructor(source) {
11
+ this.subscribers = new Set();
12
+ this.source = source instanceof Stream ? source : source.streamEntries;
13
+ }
14
+ start() {
15
+ this.task = this.source.forEach((value) => {
16
+ for (const subscriber of this.subscribers) {
17
+ subscriber(value);
18
+ }
19
+ });
20
+ }
21
+ stop() {
22
+ var _a;
23
+ (_a = this.task) === null || _a === void 0 ? void 0 : _a.cancel();
24
+ }
25
+ subscribe(callback) {
26
+ this.subscribers.add(callback);
27
+ if (this.latestValue !== undefined) {
28
+ callback(this.latestValue);
29
+ }
30
+ return {
31
+ cancel: () => {
32
+ this.subscribers.delete(callback);
33
+ },
34
+ };
35
+ }
36
+ stream(objectMaxSize, expiryPeriod) {
37
+ const queue = new Queue(objectMaxSize, expiryPeriod);
38
+ const token = this.subscribe((value) => {
39
+ queue.enqueue(value);
40
+ });
41
+ return queue.streamEntries.onCancellation(token.cancel);
42
+ }
43
+ }
44
+
45
+ export { Signal };
@@ -0,0 +1,4 @@
1
+ export { CacheManager, PersistenceStore } from "./manager";
2
+ export type { Cache } from "./manager";
3
+ export { LocalWebStore, SessionWebStore } from "./web";
4
+ export { JSONFileStore } from "./json";
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ var files = require('../../files.cjs');
4
+ var future = require('../../future/future.cjs');
5
+ require('ramda');
6
+ require('../../stream.cjs');
7
+
8
+ class JSONFileStore {
9
+ constructor(filename) {
10
+ this.filename = filename;
11
+ }
12
+ close() {
13
+ return future.Future.completed(null);
14
+ }
15
+ open() {
16
+ return future.Future.completed(null);
17
+ }
18
+ clear() {
19
+ return files.Files.remove(this.filename);
20
+ }
21
+ get(key) {
22
+ return this.loadJSONData().thenApply(({ value }) => value[key]);
23
+ }
24
+ keys() {
25
+ return this.loadJSONData()
26
+ .thenApply(({ value }) => Object.keys(value))
27
+ .stream.flatten();
28
+ }
29
+ length() {
30
+ return this.loadJSONData().thenApply(({ value }) => Object.keys(value).length);
31
+ }
32
+ remove(key) {
33
+ return this.loadJSONData().thenApply(({ value }) => {
34
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
35
+ delete value[key];
36
+ return this.saveJSONData(value);
37
+ });
38
+ }
39
+ set(key, value) {
40
+ return this.loadJSONData().thenApply(({ value: data }) => {
41
+ data[key] = value;
42
+ return this.saveJSONData(data);
43
+ });
44
+ }
45
+ values() {
46
+ return this.loadJSONData()
47
+ .thenApply(({ value }) => Object.values(value))
48
+ .stream.flatten();
49
+ }
50
+ loadJSONData() {
51
+ return files.Files.readString(this.filename).thenApply(({ value }) => (value ? JSON.parse(value) : {}));
52
+ }
53
+ saveJSONData(data) {
54
+ return files.Files.write(JSON.stringify(data), this.filename);
55
+ }
56
+ }
57
+
58
+ exports.JSONFileStore = JSONFileStore;
@@ -0,0 +1,18 @@
1
+ import { PersistenceStore } from "./manager";
2
+ import { Future } from "../../future";
3
+ import { Stream } from "../../stream";
4
+ export declare class JSONFileStore implements PersistenceStore {
5
+ private readonly filename;
6
+ constructor(filename: string);
7
+ close(): Future<void>;
8
+ open(): Future<void>;
9
+ clear(): Future<void>;
10
+ get(key: string): Future<string | undefined>;
11
+ keys(): Stream<string>;
12
+ length(): Future<number>;
13
+ remove(key: string): Future<void>;
14
+ set(key: string, value: string): Future<void>;
15
+ values(): Stream<string>;
16
+ private loadJSONData;
17
+ private saveJSONData;
18
+ }
@@ -0,0 +1,56 @@
1
+ import { Files } from '../../files.mjs';
2
+ import { Future } from '../../future/future.mjs';
3
+ import 'ramda';
4
+ import '../../stream.mjs';
5
+
6
+ class JSONFileStore {
7
+ constructor(filename) {
8
+ this.filename = filename;
9
+ }
10
+ close() {
11
+ return Future.completed(null);
12
+ }
13
+ open() {
14
+ return Future.completed(null);
15
+ }
16
+ clear() {
17
+ return Files.remove(this.filename);
18
+ }
19
+ get(key) {
20
+ return this.loadJSONData().thenApply(({ value }) => value[key]);
21
+ }
22
+ keys() {
23
+ return this.loadJSONData()
24
+ .thenApply(({ value }) => Object.keys(value))
25
+ .stream.flatten();
26
+ }
27
+ length() {
28
+ return this.loadJSONData().thenApply(({ value }) => Object.keys(value).length);
29
+ }
30
+ remove(key) {
31
+ return this.loadJSONData().thenApply(({ value }) => {
32
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
33
+ delete value[key];
34
+ return this.saveJSONData(value);
35
+ });
36
+ }
37
+ set(key, value) {
38
+ return this.loadJSONData().thenApply(({ value: data }) => {
39
+ data[key] = value;
40
+ return this.saveJSONData(data);
41
+ });
42
+ }
43
+ values() {
44
+ return this.loadJSONData()
45
+ .thenApply(({ value }) => Object.values(value))
46
+ .stream.flatten();
47
+ }
48
+ loadJSONData() {
49
+ return Files.readString(this.filename).thenApply(({ value }) => (value ? JSON.parse(value) : {}));
50
+ }
51
+ saveJSONData(data) {
52
+ return Files.write(JSON.stringify(data), this.filename);
53
+ }
54
+ }
55
+
56
+ export { JSONFileStore };