1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var events = require("events");
|
33 |
|
34 | var DocumentNode = function(documentStore, documentName, path) {
|
35 | if (!documentName) return;
|
36 | path = path || [];
|
37 | var pathType = typeof path;
|
38 | if (pathType === 'string' || pathType === 'number') path = [path];
|
39 | if (!Array.isArray(path)) return;
|
40 | this.key = documentName + ';' + path.join();
|
41 | this.documentStore = documentStore;
|
42 | this.name = documentName;
|
43 | this.isDocumentNode = true;
|
44 |
|
45 | this.path = path.slice(0);
|
46 | if (path.length > 0) {
|
47 | this.name = path[path.length - 1];
|
48 | this.isDocumentNode = false
|
49 | }
|
50 | this.documentName = documentName;
|
51 |
|
52 | this._node = {global: documentName, subscripts: this.path};
|
53 |
|
54 | };
|
55 |
|
56 |
|
57 |
|
58 | var proto = DocumentNode.prototype;
|
59 | proto._keys = Object.keys(proto).slice(0);
|
60 |
|
61 | Object.defineProperty(proto, '_defined', require('./proto/defined'));
|
62 | Object.defineProperty(proto, 'exists', require('./proto/exists'));
|
63 | Object.defineProperty(proto, 'hasValue', require('./proto/hasValue'));
|
64 | Object.defineProperty(proto, 'hasChildren', require('./proto/hasChildren'));
|
65 | Object.defineProperty(proto, 'value', require('./proto/value'));
|
66 | Object.defineProperty(proto, 'parent', require('./proto/parent'));
|
67 | Object.defineProperty(proto, 'firstChild', require('./proto/firstChild'));
|
68 | Object.defineProperty(proto, 'lastChild', require('./proto/lastChild'));
|
69 | Object.defineProperty(proto, 'nextSibling', require('./proto/nextSibling'));
|
70 | Object.defineProperty(proto, 'previousSibling', require('./proto/previousSibling'));
|
71 |
|
72 | proto.delete = require('./proto/delete');
|
73 | proto.$ = require('./proto/dollar');
|
74 | proto.increment = require('./proto/increment');
|
75 | proto.countChildren = require('./proto/count');
|
76 | proto.forEachChild = require('./proto/forEach');
|
77 | proto.getDocument = require('./proto/getDocument');
|
78 | proto.setDocument = require('./proto/setDocument');
|
79 | proto.forEachLeafNode = require('./proto/forEachLeafNode');
|
80 | proto.lock = require('./proto/lock');
|
81 | proto.unlock = require('./proto/unlock');
|
82 |
|
83 | proto._set = require('./proto/set');
|
84 | proto.enable_kvs = require('./proto/enable_kvs');
|
85 | proto.enable_list = require('./proto/enable_list');
|
86 | proto.enable_dom = require('./proto/enable_dom');
|
87 | proto.enable_rdb = require('./proto/enable_rdb');
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | var build = require('./build');
|
93 |
|
94 | var DocumentStore = function(db) {
|
95 | this.db = db;
|
96 | this.build = build;
|
97 | events.EventEmitter.call(this);
|
98 | this.DocumentNode = DocumentNode.bind(undefined, this);
|
99 | var dn = this.DocumentNode;
|
100 | this.dbx_reg = {};
|
101 |
|
102 | this.use = function(documentName, ...subscripts) {
|
103 | if (subscripts.length === 1 && Array.isArray(subscripts[0])) {
|
104 | subscripts = subscripts[0];
|
105 | }
|
106 | return new dn(documentName, subscripts);
|
107 | };
|
108 |
|
109 | this.sql = require('./proto/rdb/sql');
|
110 |
|
111 | };
|
112 |
|
113 | proto = DocumentStore.prototype;
|
114 | proto.__proto__ = events.EventEmitter.prototype;
|
115 | proto.list = require('./proto/list');
|
116 |
|
117 |
|
118 | module.exports = DocumentStore;
|