mongodb-livedata-server 0.0.4 → 0.0.6

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 (93) hide show
  1. package/{livedata_server.ts → dist/livedata_server.d.ts} +1 -1
  2. package/dist/livedata_server.js +3 -1
  3. package/dist/meteor/binary-heap/max_heap.d.ts +31 -0
  4. package/dist/meteor/binary-heap/min_heap.d.ts +6 -0
  5. package/dist/meteor/binary-heap/min_max_heap.d.ts +11 -0
  6. package/dist/meteor/callback-hook/hook.d.ts +11 -0
  7. package/dist/meteor/ddp/crossbar.d.ts +15 -0
  8. package/dist/meteor/ddp/heartbeat.d.ts +19 -0
  9. package/dist/meteor/ddp/livedata_server.d.ts +141 -0
  10. package/dist/meteor/ddp/method-invocation.d.ts +25 -0
  11. package/dist/meteor/ddp/random-stream.d.ts +8 -0
  12. package/dist/meteor/ddp/session-collection-view.d.ts +27 -0
  13. package/dist/meteor/ddp/session-document-view.d.ts +8 -0
  14. package/dist/meteor/ddp/session.d.ts +69 -0
  15. package/dist/meteor/ddp/stream_server.d.ts +21 -0
  16. package/dist/meteor/ddp/subscription.d.ts +89 -0
  17. package/dist/meteor/ddp/utils.d.ts +8 -0
  18. package/dist/meteor/ddp/writefence.d.ts +20 -0
  19. package/dist/meteor/diff-sequence/diff.d.ts +13 -0
  20. package/dist/meteor/ejson/ejson.d.ts +82 -0
  21. package/dist/meteor/ejson/stringify.d.ts +2 -0
  22. package/dist/meteor/ejson/utils.d.ts +12 -0
  23. package/dist/meteor/id-map/id_map.d.ts +16 -0
  24. package/dist/meteor/mongo/caching_change_observer.d.ts +16 -0
  25. package/dist/meteor/mongo/doc_fetcher.d.ts +7 -0
  26. package/dist/meteor/mongo/geojson_utils.d.ts +3 -0
  27. package/dist/meteor/mongo/live_connection.d.ts +27 -0
  28. package/dist/meteor/mongo/live_cursor.d.ts +25 -0
  29. package/dist/meteor/mongo/minimongo_common.d.ts +84 -0
  30. package/dist/meteor/mongo/minimongo_matcher.d.ts +22 -0
  31. package/dist/meteor/mongo/minimongo_sorter.d.ts +16 -0
  32. package/dist/meteor/mongo/observe_driver_utils.d.ts +9 -0
  33. package/dist/meteor/mongo/observe_multiplexer.d.ts +36 -0
  34. package/dist/meteor/mongo/oplog-observe-driver.d.ts +67 -0
  35. package/dist/meteor/mongo/oplog_tailing.d.ts +35 -0
  36. package/dist/meteor/mongo/oplog_v2_converter.d.ts +1 -0
  37. package/dist/meteor/mongo/polling_observe_driver.d.ts +30 -0
  38. package/dist/meteor/mongo/synchronous-cursor.d.ts +17 -0
  39. package/dist/meteor/mongo/synchronous-queue.d.ts +14 -0
  40. package/dist/meteor/ordered-dict/ordered_dict.d.ts +31 -0
  41. package/dist/meteor/random/AbstractRandomGenerator.d.ts +42 -0
  42. package/dist/meteor/random/AleaRandomGenerator.d.ts +13 -0
  43. package/dist/meteor/random/NodeRandomGenerator.d.ts +16 -0
  44. package/dist/meteor/random/createAleaGenerator.d.ts +2 -0
  45. package/dist/meteor/random/createRandom.d.ts +1 -0
  46. package/dist/meteor/random/main.d.ts +1 -0
  47. package/package.json +2 -2
  48. package/meteor/LICENSE +0 -28
  49. package/meteor/binary-heap/max_heap.ts +0 -225
  50. package/meteor/binary-heap/min_heap.ts +0 -15
  51. package/meteor/binary-heap/min_max_heap.ts +0 -53
  52. package/meteor/callback-hook/hook.ts +0 -85
  53. package/meteor/ddp/crossbar.ts +0 -148
  54. package/meteor/ddp/heartbeat.ts +0 -97
  55. package/meteor/ddp/livedata_server.ts +0 -474
  56. package/meteor/ddp/method-invocation.ts +0 -86
  57. package/meteor/ddp/random-stream.ts +0 -102
  58. package/meteor/ddp/session-collection-view.ts +0 -119
  59. package/meteor/ddp/session-document-view.ts +0 -92
  60. package/meteor/ddp/session.ts +0 -708
  61. package/meteor/ddp/stream_server.ts +0 -204
  62. package/meteor/ddp/subscription.ts +0 -392
  63. package/meteor/ddp/utils.ts +0 -119
  64. package/meteor/ddp/writefence.ts +0 -130
  65. package/meteor/diff-sequence/diff.ts +0 -295
  66. package/meteor/ejson/ejson.ts +0 -601
  67. package/meteor/ejson/stringify.ts +0 -122
  68. package/meteor/ejson/utils.ts +0 -38
  69. package/meteor/id-map/id_map.ts +0 -84
  70. package/meteor/mongo/caching_change_observer.ts +0 -120
  71. package/meteor/mongo/doc_fetcher.ts +0 -52
  72. package/meteor/mongo/geojson_utils.ts +0 -42
  73. package/meteor/mongo/live_connection.ts +0 -302
  74. package/meteor/mongo/live_cursor.ts +0 -79
  75. package/meteor/mongo/minimongo_common.ts +0 -2440
  76. package/meteor/mongo/minimongo_matcher.ts +0 -275
  77. package/meteor/mongo/minimongo_sorter.ts +0 -331
  78. package/meteor/mongo/observe_driver_utils.ts +0 -79
  79. package/meteor/mongo/observe_multiplexer.ts +0 -256
  80. package/meteor/mongo/oplog-observe-driver.ts +0 -1049
  81. package/meteor/mongo/oplog_tailing.ts +0 -414
  82. package/meteor/mongo/oplog_v2_converter.ts +0 -124
  83. package/meteor/mongo/polling_observe_driver.ts +0 -247
  84. package/meteor/mongo/synchronous-cursor.ts +0 -293
  85. package/meteor/mongo/synchronous-queue.ts +0 -119
  86. package/meteor/ordered-dict/ordered_dict.ts +0 -229
  87. package/meteor/random/AbstractRandomGenerator.ts +0 -99
  88. package/meteor/random/AleaRandomGenerator.ts +0 -96
  89. package/meteor/random/NodeRandomGenerator.ts +0 -37
  90. package/meteor/random/createAleaGenerator.ts +0 -31
  91. package/meteor/random/createRandom.ts +0 -19
  92. package/meteor/random/main.ts +0 -8
  93. package/tsconfig.json +0 -10
@@ -1,122 +0,0 @@
1
- // Based on json2.js from https://github.com/douglascrockford/JSON-js
2
- //
3
- // json2.js
4
- // 2012-10-08
5
- //
6
- // Public Domain.
7
- //
8
- // NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
9
-
10
- function quote(string) {
11
- return JSON.stringify(string);
12
- }
13
-
14
- const str = (key, holder, singleIndent, outerIndent, canonical): string => {
15
- const value = holder[key];
16
-
17
- // What happens next depends on the value's type.
18
- switch (typeof value) {
19
- case 'string':
20
- return quote(value);
21
- case 'number':
22
- // JSON numbers must be finite. Encode non-finite numbers as null.
23
- return isFinite(value) ? String(value) : 'null';
24
- case 'boolean':
25
- return String(value);
26
- // If the type is 'object', we might be dealing with an object or an array or
27
- // null.
28
- case 'object': {
29
- // Due to a specification blunder in ECMAScript, typeof null is 'object',
30
- // so watch out for that case.
31
- if (!value) {
32
- return 'null';
33
- }
34
- // Make an array to hold the partial results of stringifying this object
35
- // value.
36
- const innerIndent = outerIndent + singleIndent;
37
- const partial = [];
38
- let v;
39
-
40
- // Is the value an array?
41
- if (Array.isArray(value) || ({}).hasOwnProperty.call(value, 'callee')) {
42
- // The value is an array. Stringify every element. Use null as a
43
- // placeholder for non-JSON values.
44
- const length = value.length;
45
- for (let i = 0; i < length; i += 1) {
46
- partial[i] =
47
- str(i, value, singleIndent, innerIndent, canonical) || 'null';
48
- }
49
-
50
- // Join all of the elements together, separated with commas, and wrap
51
- // them in brackets.
52
- if (partial.length === 0) {
53
- v = '[]';
54
- } else if (innerIndent) {
55
- v = '[\n' +
56
- innerIndent +
57
- partial.join(',\n' +
58
- innerIndent) +
59
- '\n' +
60
- outerIndent +
61
- ']';
62
- } else {
63
- v = '[' + partial.join(',') + ']';
64
- }
65
- return v;
66
- }
67
-
68
- // Iterate through all of the keys in the object.
69
- let keys = Object.keys(value);
70
- if (canonical) {
71
- keys = keys.sort();
72
- }
73
- keys.forEach(k => {
74
- v = str(k, value, singleIndent, innerIndent, canonical);
75
- if (v) {
76
- partial.push(quote(k) + (innerIndent ? ': ' : ':') + v);
77
- }
78
- });
79
-
80
- // Join all of the member texts together, separated with commas,
81
- // and wrap them in braces.
82
- if (partial.length === 0) {
83
- v = '{}';
84
- } else if (innerIndent) {
85
- v = '{\n' +
86
- innerIndent +
87
- partial.join(',\n' +
88
- innerIndent) +
89
- '\n' +
90
- outerIndent +
91
- '}';
92
- } else {
93
- v = '{' + partial.join(',') + '}';
94
- }
95
- return v;
96
- }
97
-
98
- default: // Do nothing
99
- }
100
- };
101
-
102
- // If the JSON object does not yet have a stringify method, give it one.
103
- const canonicalStringify = (value, options) => {
104
- // Make a fake root object containing our value under the key of ''.
105
- // Return the result of stringifying the value.
106
- const allOptions = Object.assign({
107
- indent: '',
108
- canonical: false,
109
- }, options);
110
- if (allOptions.indent === true) {
111
- allOptions.indent = ' ';
112
- } else if (typeof allOptions.indent === 'number') {
113
- let newIndent = '';
114
- for (let i = 0; i < allOptions.indent; i++) {
115
- newIndent += ' ';
116
- }
117
- allOptions.indent = newIndent;
118
- }
119
- return str('', {'': value}, allOptions.indent, '', allOptions.canonical);
120
- };
121
-
122
- export default canonicalStringify;
@@ -1,38 +0,0 @@
1
- export const isFunction = (fn) => typeof fn === 'function';
2
-
3
- export const isObject = (fn) => typeof fn === 'object';
4
-
5
- export const keysOf = (obj) => Object.keys(obj);
6
-
7
- export const lengthOf = (obj) => Object.keys(obj).length;
8
-
9
- export const hasOwn = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
10
-
11
- export const convertMapToObject = (map) => Array.from(map).reduce((acc, [key, value]) => {
12
- // reassign to not create new object
13
- acc[key] = value;
14
- return acc;
15
- }, {});
16
-
17
- export function isArguments (obj: any): obj is ArrayLike<any> {
18
- return obj != null && hasOwn(obj, 'callee');
19
- }
20
-
21
- export const isInfOrNaN =
22
- obj => Number.isNaN(obj) || obj === Infinity || obj === -Infinity;
23
-
24
- export const checkError = {
25
- maxStack: (msgError) => new RegExp('Maximum call stack size exceeded', 'g').test(msgError),
26
- };
27
-
28
- export function handleError<F extends (...args: any[]) => any>(fn: F, ...args: any[]) {
29
- try {
30
- return fn.apply(this, args) as ReturnType<F>;
31
- } catch (error) {
32
- const isMaxStack = checkError.maxStack(error.message);
33
- if (isMaxStack) {
34
- throw new Error('Converting circular structure to JSON')
35
- }
36
- throw error;
37
- }
38
- };
@@ -1,84 +0,0 @@
1
- import * as EJSON from "../ejson/ejson";
2
-
3
- export class IdMap {
4
- private _map: Map<string, any>;
5
- private _idStringify: (obj: any) => string;
6
- private _idParse: (str: string) => any;
7
- constructor(idStringify?: (obj: any) => string, idParse?: (str: string) => any) {
8
- this._map = new Map();
9
- this._idStringify = idStringify || JSON.stringify;
10
- this._idParse = idParse || JSON.parse;
11
- }
12
-
13
- // Some of these methods are designed to match methods on OrderedDict, since
14
- // (eg) ObserveMultiplex and _CachingChangeObserver use them interchangeably.
15
- // (Conceivably, this should be replaced with "UnorderedDict" with a specific
16
- // set of methods that overlap between the two.)
17
-
18
- get(id) {
19
- const key = this._idStringify(id);
20
- return this._map.get(key);
21
- }
22
-
23
- set(id, value) {
24
- const key = this._idStringify(id);
25
- this._map.set(key, value);
26
- }
27
-
28
- remove(id) {
29
- const key = this._idStringify(id);
30
- this._map.delete(key);
31
- }
32
-
33
- has(id) {
34
- const key = this._idStringify(id);
35
- return this._map.has(key);
36
- }
37
-
38
- empty() {
39
- return this._map.size === 0;
40
- }
41
-
42
- clear() {
43
- this._map.clear();
44
- }
45
-
46
- // Iterates over the items in the map. Return `false` to break the loop.
47
- forEach(iterator) {
48
- // don't use _.each, because we can't break out of it.
49
- for (let [key, value] of this._map) {
50
- const breakIfFalse = iterator.call(
51
- null,
52
- value,
53
- this._idParse(key)
54
- );
55
- if (breakIfFalse === false) {
56
- return;
57
- }
58
- }
59
- }
60
-
61
- size() {
62
- return this._map.size;
63
- }
64
-
65
- setDefault(id, def) {
66
- const key = this._idStringify(id);
67
- if (this._map.has(key)) {
68
- return this._map.get(key);
69
- }
70
- this._map.set(key, def);
71
- return def;
72
- }
73
-
74
- // Assumes that values are EJSON-cloneable, and that we don't need to clone
75
- // IDs (ie, that nobody is going to mutate an ObjectId).
76
- clone() {
77
- const clone = new IdMap(this._idStringify, this._idParse);
78
- // copy directly to avoid stringify/parse overhead
79
- this._map.forEach(function (value, key) {
80
- clone._map.set(key, EJSON.clone(value));
81
- });
82
- return clone;
83
- }
84
- }
@@ -1,120 +0,0 @@
1
- // _CachingChangeObserver is an object which receives observeChanges callbacks
2
- // and keeps a cache of the current cursor state up to date in this.docs. Users
3
- // of this class should read the docs field but not modify it. You should pass
4
- // the "applyChange" field as the callbacks to the underlying observeChanges
5
- // call. Optionally, you can specify your own observeChanges callbacks which are
6
- // invoked immediately before the docs field is updated; this object is made
7
-
8
- import { DiffSequence } from "../diff-sequence/diff";
9
- import { clone } from "../ejson/ejson";
10
- import { OrderedDict } from "../ordered-dict/ordered_dict";
11
-
12
- // available as `this` to those callbacks.
13
- export class _CachingChangeObserver {
14
- public docs: OrderedDict | Map<string, any>;
15
- public applyChange: {
16
- added?: (id: string, fields: any) => void;
17
- changed?: (id: string, fields: any) => void;
18
- removed?: (id: string) => void;
19
- addedBefore?: (id: string, fields: any, before: any) => void;
20
- movedBefore?: (id: string, before: any) => void;
21
- };
22
-
23
- private ordered: boolean;
24
-
25
- constructor(options: { callbacks?: any, ordered?: boolean } = {}) {
26
- const orderedFromCallbacks = (
27
- options.callbacks &&
28
- !!(options.callbacks.addedBefore || options.callbacks.movedBefore)
29
- );
30
-
31
- if (options.hasOwnProperty('ordered')) {
32
- this.ordered = options.ordered;
33
-
34
- if (options.callbacks && options.ordered !== orderedFromCallbacks) {
35
- throw Error('ordered option doesn\'t match callbacks');
36
- }
37
- } else if (options.callbacks) {
38
- this.ordered = orderedFromCallbacks;
39
- } else {
40
- throw Error('must provide ordered or callbacks');
41
- }
42
-
43
- const callbacks = options.callbacks || {};
44
-
45
- if (this.ordered) {
46
- this.docs = new OrderedDict();
47
- this.applyChange = {
48
- addedBefore: (id, fields, before) => {
49
- // Take a shallow copy since the top-level properties can be changed
50
- const doc = { ...fields };
51
-
52
- doc._id = id;
53
-
54
- if (callbacks.addedBefore) {
55
- callbacks.addedBefore.call(this, id, clone(fields), before);
56
- }
57
-
58
- // This line triggers if we provide added with movedBefore.
59
- if (callbacks.added) {
60
- callbacks.added.call(this, id, clone(fields));
61
- }
62
-
63
- // XXX could `before` be a falsy ID? Technically
64
- // idStringify seems to allow for them -- though
65
- // OrderedDict won't call stringify on a falsy arg.
66
- (this.docs as OrderedDict).putBefore(id, doc, before || null);
67
- },
68
- movedBefore: (id, before) => {
69
- const doc = this.docs.get(id);
70
-
71
- if (callbacks.movedBefore) {
72
- callbacks.movedBefore.call(this, id, before);
73
- }
74
-
75
- (this.docs as OrderedDict).moveBefore(id, before || null);
76
- },
77
- };
78
- } else {
79
- this.docs = new Map();
80
- this.applyChange = {
81
- added: (id, fields) => {
82
- // Take a shallow copy since the top-level properties can be changed
83
- const doc = { ...fields };
84
-
85
- if (callbacks.added) {
86
- callbacks.added.call(this, id, clone(fields));
87
- }
88
-
89
- doc._id = id;
90
-
91
- (this.docs as Map<string, any>).set(id, doc);
92
- },
93
- };
94
- }
95
-
96
- // The methods in _IdMap and OrderedDict used by these callbacks are
97
- // identical.
98
- this.applyChange.changed = (id, fields) => {
99
- const doc = this.docs.get(id);
100
-
101
- if (!doc) {
102
- throw new Error(`Unknown id for changed: ${id}`);
103
- }
104
-
105
- if (callbacks.changed) {
106
- callbacks.changed.call(this, id, clone(fields));
107
- }
108
-
109
- DiffSequence.applyChanges(doc, fields);
110
- };
111
-
112
- this.applyChange.removed = id => {
113
- if (callbacks.removed) {
114
- callbacks.removed.call(this, id);
115
- }
116
-
117
- (this.docs as Map<string, any>).delete(id);
118
- };
119
- }
120
- };
@@ -1,52 +0,0 @@
1
- import MongoDB from "mongodb";
2
- import { clone } from "../ejson/ejson";
3
-
4
- export class DocFetcher {
5
- private _callbacksForOp = new Map<Object, Function[]>();
6
- constructor(private db: MongoDB.Db) {
7
- }
8
-
9
- // Fetches document "id" from collectionName, returning it or null if not
10
- // found.
11
- //
12
- // If you make multiple calls to fetch() with the same op reference,
13
- // DocFetcher may assume that they all return the same document. (It does
14
- // not check to see if collectionName/id match.)
15
- //
16
- // You may assume that callback is never called synchronously (and in fact
17
- // OplogObserveDriver does so).
18
- async fetch(collectionName: string, id: string, op: Object, callback: Function) {
19
- const self = this;
20
-
21
- // If there's already an in-progress fetch for this cache key, yield until
22
- // it's done and return whatever it returns.
23
- if (self._callbacksForOp.has(op)) {
24
- self._callbacksForOp.get(op).push(callback);
25
- return;
26
- }
27
-
28
- const callbacks = [callback];
29
- self._callbacksForOp.set(op, callbacks);
30
-
31
- try {
32
- var doc = await self.db.collection(collectionName).findOne({ _id: id }) || null;
33
- // Return doc to all relevant callbacks. Note that this array can
34
- // continue to grow during callback execution.
35
- while (callbacks.length > 0) {
36
- // Clone the document so that the various calls to fetch don't return
37
- // objects that are intertwingled with each other. Clone before
38
- // popping the future, so that if clone throws, the error gets passed
39
- // to the next callback.
40
- callbacks.pop()(null, clone(doc));
41
- }
42
- } catch (e) {
43
- while (callbacks.length > 0) {
44
- callbacks.pop()(e);
45
- }
46
- } finally {
47
- // XXX consider keeping the doc around for a period of time before
48
- // removing from the cache
49
- self._callbacksForOp.delete(op);
50
- }
51
- }
52
- }
@@ -1,42 +0,0 @@
1
- export function numberToRadius(number) {
2
- return number * Math.PI / 180;
3
- }
4
-
5
- // from http://www.movable-type.co.uk/scripts/latlong.html
6
- export function pointDistance(pt1, pt2) {
7
- var lon1 = pt1.coordinates[0],
8
- lat1 = pt1.coordinates[1],
9
- lon2 = pt2.coordinates[0],
10
- lat2 = pt2.coordinates[1],
11
- dLat = numberToRadius(lat2 - lat1),
12
- dLon = numberToRadius(lon2 - lon1),
13
- a = Math.pow(Math.sin(dLat / 2), 2) + Math.cos(numberToRadius(lat1))
14
- * Math.cos(numberToRadius(lat2)) * Math.pow(Math.sin(dLon / 2), 2),
15
- c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
16
- // Earth radius is 6371 km
17
- return (6371 * c) * 1000; // returns meters
18
- }
19
-
20
- // checks if geometry lies entirely within a circle
21
- // works with Point, LineString, Polygon
22
- export function geometryWithinRadius(geometry, center, radius) {
23
- if (geometry.type == 'Point') {
24
- return pointDistance(geometry, center) <= radius;
25
- } else if (geometry.type == 'LineString' || geometry.type == 'Polygon') {
26
- var point: any = {};
27
- var coordinates;
28
- if (geometry.type == 'Polygon') {
29
- // it's enough to check the exterior ring of the Polygon
30
- coordinates = geometry.coordinates[0];
31
- } else {
32
- coordinates = geometry.coordinates;
33
- }
34
- for (var i in coordinates) {
35
- point.coordinates = coordinates[i];
36
- if (pointDistance(point, center) > radius) {
37
- return false;
38
- }
39
- }
40
- }
41
- return true;
42
- }