@buley/dash 0.0.30 → 2.1.1
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.
- package/README.md +82 -65
- package/dist/src/engine/ai.d.ts +10 -0
- package/dist/src/engine/ai.js +46 -0
- package/dist/src/engine/sqlite.d.ts +31 -0
- package/dist/src/engine/sqlite.js +255 -0
- package/dist/src/engine/vec_extension.d.ts +5 -0
- package/dist/src/engine/vec_extension.js +10 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/mcp/server.d.ts +8 -0
- package/dist/src/mcp/server.js +87 -0
- package/dist/src/reactivity/signal.d.ts +3 -0
- package/dist/src/reactivity/signal.js +31 -0
- package/dist/src/sync/backup.d.ts +12 -0
- package/dist/src/sync/backup.js +44 -0
- package/dist/src/sync/connection.d.ts +16 -0
- package/dist/src/sync/connection.js +29 -0
- package/dist/src/sync/provider.d.ts +11 -0
- package/dist/src/sync/provider.js +67 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +33 -31
- package/.coveralls.yml +0 -1
- package/.github/workflows/opencommit.yml +0 -33
- package/.github/workflows/testing.yml +0 -20
- package/.gitmodules +0 -0
- package/behaviors/cache.dev.js +0 -282
- package/behaviors/changes.dev.js +0 -337
- package/behaviors/collect.dev.js +0 -40
- package/behaviors/examples/async.dev.js +0 -17
- package/behaviors/firebase.dev.js +0 -283
- package/behaviors/live.dev.js +0 -67
- package/behaviors/map.dev.js +0 -54
- package/behaviors/mapreduce.dev.js +0 -68
- package/behaviors/match.dev.js +0 -66
- package/behaviors/patch.dev.js +0 -69
- package/behaviors/rest.dev.js +0 -340
- package/behaviors/shorthand.dev.js +0 -59
- package/behaviors/stats.dev.js +0 -672
- package/dist/behaviors/index.js +0 -142
- package/dist/database/index.js +0 -76
- package/dist/databases/index.js +0 -121
- package/dist/entry/index.js +0 -166
- package/dist/index.js +0 -93
- package/dist/indexes/index.js +0 -153
- package/dist/store/index.js +0 -97
- package/dist/stores/index.js +0 -90
- package/dist/utilities/index.js +0 -174
- package/documentation/database/closing.md +0 -3
- package/documentation/database/getting.md +0 -1
- package/documentation/database/opening.md +0 -5
- package/documentation/database/removing.md +0 -3
- package/documentation/databases.md +0 -21
- package/documentation/entries.md +0 -13
- package/documentation/entry/adding.md +0 -1
- package/documentation/entry/getting.md +0 -4
- package/documentation/entry/putting.md +0 -0
- package/documentation/entry/removing.md +0 -3
- package/documentation/entry/updating.md +0 -0
- package/documentation/general/security.md +0 -10
- package/documentation/general/transaction/requests.md +0 -3
- package/documentation/general/transactions.md +0 -5
- package/documentation/index/creating.md +0 -1
- package/documentation/index/getting.md +0 -1
- package/documentation/index/iterating.md +0 -1
- package/documentation/index/removing.md +0 -1
- package/documentation/indexes.md +0 -3
- package/documentation/key/cursors.md +0 -5
- package/documentation/key/range/bounds.md +0 -11
- package/documentation/key/range/direction.md +0 -1
- package/documentation/key/ranges.md +0 -3
- package/documentation/keys.md +0 -12
- package/documentation/objectstore/clearing.md +0 -1
- package/documentation/objectstore/creating.md +0 -1
- package/documentation/objectstore/getting.md +0 -1
- package/documentation/objectstore/iteration.md +0 -1
- package/documentation/objectstore/removing.md +0 -1
- package/documentation/overview.md +0 -5
- package/documentation/stores.md +0 -13
- package/jest.config.js +0 -12
- package/src/behaviors/index.ts +0 -140
- package/src/database/index.ts +0 -81
- package/src/databases/index.ts +0 -127
- package/src/entry/index.ts +0 -183
- package/src/index/index.ts +0 -61
- package/src/index.ts +0 -96
- package/src/indexes/index.ts +0 -151
- package/src/store/index.ts +0 -102
- package/src/stores/index.ts +0 -90
- package/src/utilities/index.ts +0 -349
- package/tests/behaviors/behaviors.spec.ts +0 -123
- package/tests/database/database.spec.ts +0 -177
- package/tests/databases/databases.spec.ts +0 -199
- package/tests/entry/entry.spec.ts +0 -252
- package/tests/index/index.spec.ts +0 -94
- package/tests/indexes/indexes.spec.ts +0 -203
- package/tests/store/store.spec.ts +0 -164
- package/tests/stores/stores.spec.ts +0 -148
- package/tests/utilities/clone.spec.ts +0 -48
- package/tests/utilities/cloneError.spec.ts +0 -33
- package/tests/utilities/contains.spec.ts +0 -28
- package/tests/utilities/exists.spec.ts +0 -21
- package/tests/utilities/is.spec.ts +0 -37
- package/tests/utilities/isArray.spec.ts +0 -21
- package/tests/utilities/isBoolean.spec.ts +0 -23
- package/tests/utilities/isEmpty.spec.ts +0 -45
- package/tests/utilities/isFunction.spec.ts +0 -30
- package/tests/utilities/isNumber.spec.ts +0 -29
- package/tests/utilities/isObject.spec.ts +0 -42
- package/tests/utilities/isRegEx.spec.ts +0 -33
- package/tests/utilities/isString.spec.ts +0 -25
- package/tests/utilities/isnt.spec.ts +0 -50
- package/tests/utilities/randomId.spec.ts +0 -39
- package/tests/utilities/safeApply.spec.ts +0 -49
- package/tests/utilities/safeEach.spec.ts +0 -38
- package/tests/utilities/safeIterate.spec.ts +0 -47
- package/tsconfig.json +0 -16
package/behaviors/cache.dev.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
var dashCache = (function (environment) {
|
|
2
|
-
"use strict";
|
|
3
|
-
var that,
|
|
4
|
-
cache = {},
|
|
5
|
-
set = function( request ) {
|
|
6
|
-
var key = request.key || null
|
|
7
|
-
, value = request.value || null
|
|
8
|
-
, expires = request.expires || 3000 //in millisecons
|
|
9
|
-
, current_date = new Date()
|
|
10
|
-
, timestamp = ( current_date.getTime() + expires );
|
|
11
|
-
if( 'undefined' === typeof key || null === key ) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
cache = cache || {};
|
|
15
|
-
cache[ key ] = {
|
|
16
|
-
data: value,
|
|
17
|
-
expire: timestamp
|
|
18
|
-
};
|
|
19
|
-
return cache[ key ].data;
|
|
20
|
-
},
|
|
21
|
-
get = function( request ) {
|
|
22
|
-
cache = cache || {};
|
|
23
|
-
var key = request.key || '';
|
|
24
|
-
if( 'undefined' === typeof key || null === key ) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
if(cache[ key ]) {
|
|
28
|
-
if(cache[ key ].expire > new Date().getTime()) {
|
|
29
|
-
cache[ key ].data = cache[ key ].data || {};
|
|
30
|
-
return cache[ key ].data;
|
|
31
|
-
}
|
|
32
|
-
delete cache[key];
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
},
|
|
36
|
-
zap = function( request ) {
|
|
37
|
-
cache = cache || {};
|
|
38
|
-
var key = request.key || ''
|
|
39
|
-
, temp
|
|
40
|
-
, keys = key.split('.')
|
|
41
|
-
, result;
|
|
42
|
-
if( 'undefined' === typeof key || null === key ) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
result = cache[ key ];
|
|
46
|
-
delete cache[ key ];
|
|
47
|
-
return result;
|
|
48
|
-
},
|
|
49
|
-
buildKey = function(key_ctx, type) {
|
|
50
|
-
var key = [ key_ctx.database, key_ctx.store, key_ctx.index, key_ctx.key, key_ctx.primary_key, key_ctx.limit ].reduce(function(acc, current){
|
|
51
|
-
acc = acc || [];
|
|
52
|
-
if(!!current) {
|
|
53
|
-
acc = [ acc, current ].join('.');
|
|
54
|
-
}
|
|
55
|
-
return acc;
|
|
56
|
-
});
|
|
57
|
-
return key;
|
|
58
|
-
},
|
|
59
|
-
scripts = ( !! environment.document) ? environment.document.getElementsByTagName("script") : [],
|
|
60
|
-
libraryScript = scripts[scripts.length - 1] || null,
|
|
61
|
-
libraryPath =( null !== libraryScript && null !== libraryScript.src.match(/cache/) && null === libraryScript.src.match(/chrome-extension/) ) ? libraryScript.src : self.currentScript || null,
|
|
62
|
-
workerEnvironment = null !== environment.constructor.toString().match(/WorkerGlobalScope/),
|
|
63
|
-
worker = !!workerEnvironment && !!libraryPath && null !== libraryPath.match(/cache/) && undefined !== Worker ? new Worker(libraryPath) : null,
|
|
64
|
-
workQueue = {},
|
|
65
|
-
workRegister = function (worker, message, context, success, error, notify) {
|
|
66
|
-
var id = that.random(),
|
|
67
|
-
callback = function (e) {
|
|
68
|
-
var data = e.data,
|
|
69
|
-
queued = workQueue[data.uid];
|
|
70
|
-
if (undefined !== queued) {
|
|
71
|
-
switch (e.data.type) {
|
|
72
|
-
case 'success':
|
|
73
|
-
delete workQueue[data.uid];
|
|
74
|
-
worker.removeEventListener('message', callback);
|
|
75
|
-
that.apply(success, [data.context]);
|
|
76
|
-
break;
|
|
77
|
-
case 'error':
|
|
78
|
-
delete workQueue[data.uid];
|
|
79
|
-
worker.removeEventListener('message', callback);
|
|
80
|
-
that.apply(error, [data.context]);
|
|
81
|
-
break;
|
|
82
|
-
case 'abort':
|
|
83
|
-
that.apply(notify, [data.context]);
|
|
84
|
-
break;
|
|
85
|
-
default:
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
clean = function(obj) {
|
|
91
|
-
if (that.isFunction(obj)) {
|
|
92
|
-
return undefined;
|
|
93
|
-
} else if (that.isObject(obj)) {
|
|
94
|
-
that.iterate(obj, function(key, val) {
|
|
95
|
-
obj[ key ] = clean(val);
|
|
96
|
-
});
|
|
97
|
-
} else if (that.isArray(obj)) {
|
|
98
|
-
that.each(obj, function(v, i) {
|
|
99
|
-
obj[i] = clean(v);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return obj;
|
|
103
|
-
};
|
|
104
|
-
workQueue[id] = {
|
|
105
|
-
success: success,
|
|
106
|
-
error: error,
|
|
107
|
-
notify: notify
|
|
108
|
-
};
|
|
109
|
-
if ( !!worker ) {
|
|
110
|
-
worker.addEventListener('message', callback);
|
|
111
|
-
worker.postMessage({
|
|
112
|
-
method: message,
|
|
113
|
-
context: clean(context),
|
|
114
|
-
uid: id
|
|
115
|
-
});
|
|
116
|
-
} else {
|
|
117
|
-
throw new Error('non-Worker interface not yet implemented');
|
|
118
|
-
}
|
|
119
|
-
return id;
|
|
120
|
-
},
|
|
121
|
-
workDispatch = function (message, context) {
|
|
122
|
-
var defd = that.deferred(),
|
|
123
|
-
callbacks = {
|
|
124
|
-
on_success: context.on_success,
|
|
125
|
-
on_error: context.on_error,
|
|
126
|
-
on_abort: context.on_abort,
|
|
127
|
-
on_complete: context.on_complete,
|
|
128
|
-
on_upgrade_needed: context.on_upgrade_needed,
|
|
129
|
-
on_blocked: context.on_blocked,
|
|
130
|
-
on_close: context.on_close
|
|
131
|
-
},
|
|
132
|
-
getData = function (data) {
|
|
133
|
-
if( that.isObject(data) ) {
|
|
134
|
-
that.iterate(callbacks, function (key, val) {
|
|
135
|
-
data[key] = val;
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
return data;
|
|
139
|
-
};
|
|
140
|
-
that.iterate(callbacks, function (key, val) {
|
|
141
|
-
delete context[key];
|
|
142
|
-
});
|
|
143
|
-
workRegister(worker, message, context, function (data) {
|
|
144
|
-
defd.resolve(getData(data));
|
|
145
|
-
}, function (data) {
|
|
146
|
-
defd.reject(getData(data));
|
|
147
|
-
}, function (data) {
|
|
148
|
-
defd.notify(getData(data));
|
|
149
|
-
});
|
|
150
|
-
return defd.promise;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
if (true === workerEnvironment) {
|
|
154
|
-
environment.addEventListener('message', function (e) {
|
|
155
|
-
var input = e.data,
|
|
156
|
-
method = input.method,
|
|
157
|
-
value = input.value,
|
|
158
|
-
key = input.key,
|
|
159
|
-
context = input.context,
|
|
160
|
-
expires = input.expires,
|
|
161
|
-
prune = function(obj) {
|
|
162
|
-
var isReducible = function(input) {
|
|
163
|
-
var attrs = 0,
|
|
164
|
-
attr;
|
|
165
|
-
if ( undefined === input || null === input || 'string' === typeof input || 'number' === typeof input || 'function' === typeof input.slice ) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
for ( attr in input ) {
|
|
169
|
-
if ( true === input.hasOwnProperty(attr) ) {
|
|
170
|
-
attrs += 1;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return ( attrs >= 1 ) ? true : false;
|
|
174
|
-
}, reduce = function(input) {
|
|
175
|
-
var attrs = {},
|
|
176
|
-
attr;
|
|
177
|
-
for ( attr in input ) {
|
|
178
|
-
if ( true === input.hasOwnProperty(attr) ) {
|
|
179
|
-
if ( !!input[ attr ] && !!input[ attr ].expire && ( input[ attr ].expire < new Date().getTime() ) ) {
|
|
180
|
-
//skip
|
|
181
|
-
} else if ( isReducible(input[ attr ] ) ) {
|
|
182
|
-
attrs[ attr ] = reduce(input[ attr ]);
|
|
183
|
-
} else {
|
|
184
|
-
attrs[ attr ] = input[ attr ];
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return attrs
|
|
189
|
-
};
|
|
190
|
-
return reduce(obj);
|
|
191
|
-
},
|
|
192
|
-
end = function (ctx) {
|
|
193
|
-
input.context = ctx;
|
|
194
|
-
input.type = 'success';
|
|
195
|
-
environment.postMessage(input);
|
|
196
|
-
setTimeout(function() {
|
|
197
|
-
cache = prune(cache);
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
if (method === 'get' || method === 'set' || method === 'delete') {
|
|
201
|
-
if ( method === 'get' ) {
|
|
202
|
-
end(get(context));
|
|
203
|
-
} else if ( method === 'set' ) {
|
|
204
|
-
end(set(context));
|
|
205
|
-
} else if ( method === 'delete' ) {
|
|
206
|
-
end(zap(context));
|
|
207
|
-
}
|
|
208
|
-
} else {
|
|
209
|
-
input.type = 'error';
|
|
210
|
-
end({
|
|
211
|
-
type: 'abort',
|
|
212
|
-
context: input,
|
|
213
|
-
error: 'No such method'
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}, false);
|
|
217
|
-
} else {
|
|
218
|
-
return [ function (state) {
|
|
219
|
-
that = this;
|
|
220
|
-
if(this.isEmpty(state.context.cache)) {
|
|
221
|
-
return state;
|
|
222
|
-
}
|
|
223
|
-
var promise = state.promise,
|
|
224
|
-
outward = this.deferred(),
|
|
225
|
-
inward,
|
|
226
|
-
response,
|
|
227
|
-
callbacks = {
|
|
228
|
-
on_success: state.context.on_success,
|
|
229
|
-
on_error: state.context.on_error,
|
|
230
|
-
on_abort: state.context.on_abort,
|
|
231
|
-
on_complete: state.context.on_complete,
|
|
232
|
-
on_upgrade_needed: state.context.on_upgrade_needed,
|
|
233
|
-
on_blocked: state.context.on_blocked,
|
|
234
|
-
on_close: state.context.on_close
|
|
235
|
-
}
|
|
236
|
-
if (this.contains(['get.entry'], state.method)) {
|
|
237
|
-
inward = workDispatch('get', { key: buildKey(state.context) } );
|
|
238
|
-
inward(function(response) {
|
|
239
|
-
if(that.isEmpty(response)) {
|
|
240
|
-
state.context.cached = false;
|
|
241
|
-
} else {
|
|
242
|
-
state = response;
|
|
243
|
-
state.promise = outward.promise;
|
|
244
|
-
state.context.cached = true;
|
|
245
|
-
that.iterate(callbacks, function(key, val) {
|
|
246
|
-
if (!that.isEmpty(val)) {
|
|
247
|
-
state.context[key] = val;
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
state.type = 'resolve';
|
|
251
|
-
outward.resolve(state);
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
return state;
|
|
256
|
-
}, function (state) {
|
|
257
|
-
if(this.is(state.context.cached, true) || this.is(state.context.cache, false)) {
|
|
258
|
-
return state;
|
|
259
|
-
}
|
|
260
|
-
var promise = state.promise,
|
|
261
|
-
outward = this.deferred(),
|
|
262
|
-
inward,
|
|
263
|
-
response,
|
|
264
|
-
args;
|
|
265
|
-
if (this.contains(['resolve','error'], state.type)) {
|
|
266
|
-
state.promise = outward.promise;
|
|
267
|
-
args = { key: buildKey(state.context, state.type) } ;
|
|
268
|
-
if ( !this.isEmpty(state.context.purge) || this.contains(['remove.entry', 'remove.entries', 'remove.index', 'remove.store', 'remove.database' ], state.method) ) {
|
|
269
|
-
inward = workDispatch('zap', args );
|
|
270
|
-
} else {
|
|
271
|
-
args.expires = state.context.expires || 3000;
|
|
272
|
-
args.value = state;
|
|
273
|
-
inward = workDispatch('set', args );
|
|
274
|
-
}
|
|
275
|
-
inward(function(ctx2){
|
|
276
|
-
outward.resolve(ctx2);
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
return state;
|
|
280
|
-
} ];
|
|
281
|
-
}
|
|
282
|
-
}(self));
|
package/behaviors/changes.dev.js
DELETED
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
var dashChanges = (function (environment) {
|
|
2
|
-
"use strict";
|
|
3
|
-
var callbackMap = {},
|
|
4
|
-
changeMap = {},
|
|
5
|
-
that,
|
|
6
|
-
update = function(type, ctx) {
|
|
7
|
-
if (that.exists(ctx.primary_key) || that.exists(ctx.key)) {
|
|
8
|
-
if (that.contains(['update.entries', 'update.entry'], type)) {
|
|
9
|
-
var key = ctx.primary_key || ctx.key;
|
|
10
|
-
changeMap[ctx.database].stores[ctx.store].entries = changeMap[ctx.database].stores[ctx.store].entries || {};
|
|
11
|
-
changeMap[ctx.database].stores[ctx.store].entries[key] = changeMap[ctx.database].stores[ctx.store].entries[key] || {
|
|
12
|
-
callbacks: []
|
|
13
|
-
};
|
|
14
|
-
if (that.exists(ctx.entry)) {
|
|
15
|
-
changeMap[ctx.database].stores[ctx.store].entries[key].data = ctx.entry;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
unregister = function(type, ctx) {
|
|
21
|
-
if (that.contains(['remove.database'], type)) {
|
|
22
|
-
delete changeMap[ctx.database];
|
|
23
|
-
} else if (that.exists(ctx.store)) {
|
|
24
|
-
if (that.contains(['remove.store'], type)) {
|
|
25
|
-
delete changeMap[ctx.database].stores[ctx.store];
|
|
26
|
-
} else if (that.exists(ctx.index)) {
|
|
27
|
-
if (that.contains(['remove.index'], type)) {
|
|
28
|
-
delete changeMap[ctx.database].stores[ctx.store].indexes[ctx.index];
|
|
29
|
-
} else if (that.exists(ctx.key) && that.isnt(ctx.primary_key, ctx.key)) {
|
|
30
|
-
if (that.contains(['remove.entries', 'remove.entry', 'clear.store'], type)) {
|
|
31
|
-
delete changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].entries[ ctx.key ];
|
|
32
|
-
delete changeMap[ctx.database].stores[ctx.store].entries[ ctx.primary_key ];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} else if (that.exists(ctx.primary_key) || that.exists(ctx.key)) {
|
|
36
|
-
if (that.contains(['remove.entries', 'remove.entry', 'clear.store'], type)) {
|
|
37
|
-
var key = ctx.primary_key || ctx.key;
|
|
38
|
-
if (that.exists(changeMap[ctx.database])) {
|
|
39
|
-
delete changeMap[ctx.database].stores[ctx.store].entries[key];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
register = function(type, ctx) {
|
|
46
|
-
var obj = ctx.changeid;
|
|
47
|
-
changeMap[ctx.database] = changeMap[ctx.database] || {
|
|
48
|
-
stores: {},
|
|
49
|
-
callbacks: []
|
|
50
|
-
};
|
|
51
|
-
if (that.contains(['get.databases','get.database'], type)) {
|
|
52
|
-
changeMap[ctx.database].callbacks.push(obj);
|
|
53
|
-
}
|
|
54
|
-
if (that.exists(ctx.store)) {
|
|
55
|
-
changeMap[ctx.database].stores[ctx.store] = changeMap[ctx.database].stores[ctx.store] || {
|
|
56
|
-
callbacks: [],
|
|
57
|
-
indexes: {}
|
|
58
|
-
};
|
|
59
|
-
if (that.contains(['get.stores','get.store'], type)) {
|
|
60
|
-
changeMap[ctx.database].stores[ctx.store].callbacks.push(obj);
|
|
61
|
-
}
|
|
62
|
-
if (that.exists(ctx.index)) {
|
|
63
|
-
changeMap[ctx.database].stores[ctx.store].indexes[ctx.index] = changeMap[ctx.database].stores[ctx.store].indexes[ctx.index] || {
|
|
64
|
-
callbacks: [],
|
|
65
|
-
entries: {}
|
|
66
|
-
};
|
|
67
|
-
if (that.contains(['get.index','get.indexes'], type)) {
|
|
68
|
-
if (that.exists(ctx.idx)) {
|
|
69
|
-
changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].data = ctx.idx;
|
|
70
|
-
}
|
|
71
|
-
if (!that.contains(changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].callbacks, obj)) {
|
|
72
|
-
changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].callbacks.push(obj);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (that.exists(ctx.key) && that.isnt(ctx.primary_key, ctx.key)) {
|
|
76
|
-
if (that.is(ctx.live, true) || that.contains(['get.entry','get.entries', 'update.entry', 'remove.entry', 'update.entries'], type)) {
|
|
77
|
-
changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].entries[ ctx.key ] = changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].entries[ ctx.key ] || {
|
|
78
|
-
callbacks: []
|
|
79
|
-
};
|
|
80
|
-
if (that.exists(ctx.entry)) {
|
|
81
|
-
changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].entries[ ctx.key ].data = ctx.entry;
|
|
82
|
-
}
|
|
83
|
-
if (!that.contains(changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].entries[ ctx.key ].callbacks, obj)) {
|
|
84
|
-
changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].entries[ ctx.key ].callbacks.push(obj);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (that.exists(ctx.primary_key) || that.exists(ctx.key)) {
|
|
90
|
-
if (that.is(ctx.live, true) || that.contains(['get.entry','get.entries', 'update.entries', 'update.entry'], type)) {
|
|
91
|
-
var key = ctx.primary_key || ctx.key;
|
|
92
|
-
changeMap[ctx.database].stores[ctx.store].entries = changeMap[ctx.database].stores[ctx.store].entries || {};
|
|
93
|
-
changeMap[ctx.database].stores[ctx.store].entries[key] = changeMap[ctx.database].stores[ctx.store].entries[key] || {
|
|
94
|
-
callbacks: []
|
|
95
|
-
};
|
|
96
|
-
if (that.exists(ctx.entry)) {
|
|
97
|
-
changeMap[ctx.database].stores[ctx.store].entries[key].data = ctx.entry;
|
|
98
|
-
}
|
|
99
|
-
if (!that.contains(changeMap[ctx.database].stores[ctx.store].entries[key].callbacks, obj)) {
|
|
100
|
-
changeMap[ctx.database].stores[ctx.store].entries[key].callbacks.push(obj);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
inquire = function(type, ctx) {
|
|
107
|
-
var listeners = [],
|
|
108
|
-
previous = null,
|
|
109
|
-
current = null,
|
|
110
|
-
obj = ctx.changeid,
|
|
111
|
-
key;
|
|
112
|
-
changeMap[ctx.database] = changeMap[ctx.database] || {
|
|
113
|
-
stores: {},
|
|
114
|
-
callbacks: []
|
|
115
|
-
};
|
|
116
|
-
if (that.contains(['remove.database', 'add.index', 'add.store'], type)) {
|
|
117
|
-
that.each(changeMap[ctx.database].callbacks, function(callback) {
|
|
118
|
-
if (!that.contains(listeners, callback)) {
|
|
119
|
-
listeners.push(callback);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
previous = changeMap[ctx.database].data;
|
|
123
|
-
current = ctx.db;
|
|
124
|
-
}
|
|
125
|
-
if (that.exists(ctx.store)) {
|
|
126
|
-
changeMap[ctx.database].stores[ctx.store] = changeMap[ctx.database].stores[ctx.store] || {
|
|
127
|
-
callbacks: [],
|
|
128
|
-
indexes: {}
|
|
129
|
-
};
|
|
130
|
-
if (that.contains(['remove.database', 'remove.store', 'clear.store', 'add.index'], type)) {
|
|
131
|
-
that.each(changeMap[ctx.database].stores[ctx.store].callbacks, function(callback) {
|
|
132
|
-
if (!that.contains(listeners, callback)) {
|
|
133
|
-
listeners.push(callback);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
previous = changeMap[ctx.database].stores[ctx.store].data;
|
|
137
|
-
current = ctx.objectstore;
|
|
138
|
-
}
|
|
139
|
-
if (that.exists(ctx.index)) {
|
|
140
|
-
changeMap[ctx.database].stores[ctx.store].indexes[ctx.index] = changeMap[ctx.database].stores[ctx.store].indexes[ctx.index] || {
|
|
141
|
-
callbacks: [],
|
|
142
|
-
entries: {}
|
|
143
|
-
};
|
|
144
|
-
if (that.contains(['remove.index', 'remove.store', 'remove.database', 'clear.store'], type)) {
|
|
145
|
-
that.each(changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].callbacks, function(callback) {
|
|
146
|
-
if (!that.contains(listeners, callback)) {
|
|
147
|
-
listeners.push(callback);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
previous = changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].data;
|
|
151
|
-
current = ctx.idx;
|
|
152
|
-
}
|
|
153
|
-
if (that.exists(ctx.key) && that.isnt(ctx.primary_key, ctx.key)) {
|
|
154
|
-
if (that.is(ctx.live, true) || that.contains(['get.entries', 'get.entry', 'remove.store', 'clear.store', 'remove.database', 'update.entries', 'update.entry', 'remove.entries', 'remove.entry'], type)) {
|
|
155
|
-
changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].entries[ ctx.key ] = changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].entries[ ctx.key ] || {
|
|
156
|
-
callbacks: []
|
|
157
|
-
};
|
|
158
|
-
previous = changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].entries[ ctx.key ].data;
|
|
159
|
-
current = ctx.entry;
|
|
160
|
-
that.each(changeMap[ctx.database].stores[ctx.store].indexes[ctx.index].entries[ ctx.key ].callbacks, function(callback) {
|
|
161
|
-
if (!that.contains(listeners, callback)) {
|
|
162
|
-
listeners.push(callback);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (that.exists(ctx.primary_key) || that.exists(ctx.key)) {
|
|
169
|
-
if (that.contains(['update.entries', 'update.entry', 'remove.entries', 'remove.entry', 'remove.database', 'remove.store', 'clear.store'], type)) {
|
|
170
|
-
key = ctx.primary_key || ctx.key;
|
|
171
|
-
changeMap[ctx.database].stores[ctx.store].entries = changeMap[ctx.database].stores[ctx.store].entries || {};
|
|
172
|
-
changeMap[ctx.database].stores[ctx.store].entries[key] = changeMap[ctx.database].stores[ctx.store].entries[key] || {
|
|
173
|
-
callbacks: []
|
|
174
|
-
};
|
|
175
|
-
previous = changeMap[ctx.database].stores[ctx.store].entries[key].data;
|
|
176
|
-
current = ctx.entry;
|
|
177
|
-
that.each(changeMap[ctx.database].stores[ctx.store].entries[key].callbacks, function(callback) {
|
|
178
|
-
if (!that.contains(listeners, callback)) {
|
|
179
|
-
listeners.push(callback);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return {
|
|
186
|
-
listeners: listeners,
|
|
187
|
-
current: current,
|
|
188
|
-
previous: previous
|
|
189
|
-
};
|
|
190
|
-
},
|
|
191
|
-
notSame = function(a, b) {
|
|
192
|
-
if ( that.isArray(a) ) {
|
|
193
|
-
a = a.join('');
|
|
194
|
-
}
|
|
195
|
-
if ( that.isArray(b) ) {
|
|
196
|
-
b = b.join('');
|
|
197
|
-
}
|
|
198
|
-
a = a ? a.toString() : a;
|
|
199
|
-
b = b ? b.toString() : b;
|
|
200
|
-
return that.isnt(a, b);
|
|
201
|
-
},
|
|
202
|
-
notify = function(ctx, method, type) {
|
|
203
|
-
var inquiry = inquire(method, ctx),
|
|
204
|
-
listeners = inquiry.listeners || [],
|
|
205
|
-
current = inquiry.current || {},
|
|
206
|
-
previous = inquiry.previous || {},
|
|
207
|
-
difference = function(one, two, shallow) {
|
|
208
|
-
var diff = {};
|
|
209
|
-
one = one || {};
|
|
210
|
-
two = two || {};
|
|
211
|
-
if (that.isObject(one)) {
|
|
212
|
-
that.iterate(one, function(key, val) {
|
|
213
|
-
if (notSame(val, two[key])) {
|
|
214
|
-
if ( that.isEmpty(val) || that.isEmpty(one[key])) {
|
|
215
|
-
diff[ key ] = [val, one[key]];
|
|
216
|
-
} else if ( that.isnt(shallow, true) && ( ( that.exists(two[key]) && that.isObject(two[key]) ) || that.isObject(val))) {
|
|
217
|
-
diff[ key ] = difference(val, two[key], shallow);
|
|
218
|
-
} else {
|
|
219
|
-
diff[ key ] = [val, two[key]];
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
} else if (that.isArray(one)) {
|
|
224
|
-
if (that.isArray(two)) {
|
|
225
|
-
that.each(one, function(val, i) {
|
|
226
|
-
diff[ i ] = diff[ i ] || [];
|
|
227
|
-
if ( that.isEmpty(val) || that.isEmpty(two[i])) {
|
|
228
|
-
diff[ key ] = [val, two[i]];
|
|
229
|
-
} if ( that.isnt(shallow, true) && (that.exists(one[i]) && that.isObject(one[i]) ) || that.isObject(val) ) {
|
|
230
|
-
diff[i] = difference(val, two[i], shallow);
|
|
231
|
-
} else {
|
|
232
|
-
diff[i] = [one[i], val];
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
if (that.isObject(two)) {
|
|
238
|
-
that.iterate(two, function(key, val) {
|
|
239
|
-
if (notSame(val, one[key]) && that.isEmpty(one[ key ])) {
|
|
240
|
-
if ( that.isEmpty(val) || that.isEmpty(two[key])) {
|
|
241
|
-
diff[ key ] = [val, two[key]];
|
|
242
|
-
} if ( that.isnt(shallow, true) && (that.exists(one[key]) && that.isObject(one[key]) ) || that.isObject(val) ) {
|
|
243
|
-
diff[ key ] = difference(one[key], val, shallow);
|
|
244
|
-
} else {
|
|
245
|
-
diff[ key ] = [one[key], val];
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
} else if (that.isArray(two)) {
|
|
250
|
-
if (that.isArray(two)) {
|
|
251
|
-
that.each(two, function(val, i) {
|
|
252
|
-
diff[ i ] = diff[ i ] || [];
|
|
253
|
-
if ( that.isEmpty(val) || that.isEmpty(one[i])) {
|
|
254
|
-
diff[ i ] = [val, one[i]];
|
|
255
|
-
} if ( that.isnt(shallow, true) && (that.exists(one[i]) && that.isObject(one[i]) ) || that.isObject(val) ) {
|
|
256
|
-
diff[ i ] = difference(one[i], val, shallow);
|
|
257
|
-
} else {
|
|
258
|
-
diff[ i ] = [one[i], val];
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return diff;
|
|
264
|
-
},
|
|
265
|
-
diff = (that.is(ctx.diff, true)) ? difference(current, previous, ctx.shallow ? true : false) : null,
|
|
266
|
-
args = { context: ctx, method: method, type: type, current: current, previous: previous };
|
|
267
|
-
if(that.is(ctx.diff, true)) {
|
|
268
|
-
args.difference = that.isEmpty(diff) ? null : diff;
|
|
269
|
-
}
|
|
270
|
-
if (that.isnt(ctx.diff, true) || that.isnt(args.difference, null)) {
|
|
271
|
-
that.each(listeners, function(id, i) {
|
|
272
|
-
var listens = callbackMap[id];
|
|
273
|
-
if(that.isArray(listens)) {
|
|
274
|
-
that.each(listens, function(listen, z) {
|
|
275
|
-
if ( false === that.apply(listen, [ args ]) ) {
|
|
276
|
-
delete listeners[i][z];
|
|
277
|
-
delete callbackMap[id][z];
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
} else {
|
|
281
|
-
if ( false === that.apply(callbackMap[id], [ args ]) ) {
|
|
282
|
-
delete listeners[i];
|
|
283
|
-
delete callbackMap[id];
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
return ctx;
|
|
289
|
-
};
|
|
290
|
-
return [ function(state) {
|
|
291
|
-
that = this;
|
|
292
|
-
var id = this.random();
|
|
293
|
-
state.context.changeid = id;
|
|
294
|
-
if(!this.isFunction(state.context.changes) && !this.isArray(state.context.changes)) {
|
|
295
|
-
return state;
|
|
296
|
-
}
|
|
297
|
-
callbackMap[ id ] = this.clone(state.context.changes);
|
|
298
|
-
return state;
|
|
299
|
-
}, function (state) {
|
|
300
|
-
if (this.exists(state.context.zombie)) {
|
|
301
|
-
return state;
|
|
302
|
-
}
|
|
303
|
-
that = this;
|
|
304
|
-
var promise = state.promise,
|
|
305
|
-
outward = this.deferred(),
|
|
306
|
-
doTick = function(ste) {
|
|
307
|
-
if (!ste || !!ste.context.changing) {
|
|
308
|
-
return ste;
|
|
309
|
-
}
|
|
310
|
-
ste.context.changing = true;
|
|
311
|
-
notify(ste.context, ste.method, ste.type);
|
|
312
|
-
unregister(ste.method, ste.context);
|
|
313
|
-
if (!!state.context.changes) {
|
|
314
|
-
register(ste.method, ste.context);
|
|
315
|
-
}
|
|
316
|
-
if(that.is('resolve', 'notify', ste.type)) {
|
|
317
|
-
update(ste.method, ste.context);
|
|
318
|
-
}
|
|
319
|
-
if(that.is('resolve', ste.type)) {
|
|
320
|
-
if ( !that.isEmpty(callbackMap[ ste.context.changeid ]) ) {
|
|
321
|
-
ste.context.changes = callbackMap[ ste.context.changeid ];
|
|
322
|
-
}
|
|
323
|
-
delete ste.context.changeid;
|
|
324
|
-
}
|
|
325
|
-
return ste;
|
|
326
|
-
};
|
|
327
|
-
promise(function(ste) {
|
|
328
|
-
outward.resolve(doTick(ste));
|
|
329
|
-
}, function(ste) {
|
|
330
|
-
outward.reject(ste);
|
|
331
|
-
}, function(ste) {
|
|
332
|
-
outward.notify(doTick(ste));
|
|
333
|
-
});
|
|
334
|
-
state.promise = outward.promise;
|
|
335
|
-
return state;
|
|
336
|
-
} ];
|
|
337
|
-
}(self));
|
package/behaviors/collect.dev.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
var dashCollect = (function(environment) {
|
|
2
|
-
"use strict";
|
|
3
|
-
var collections = {};
|
|
4
|
-
return [function(state) {
|
|
5
|
-
if (this.isnt(state.context.collect, true)) {
|
|
6
|
-
return state;
|
|
7
|
-
}
|
|
8
|
-
state.context.collector = this.random();
|
|
9
|
-
collections[state.context.collector] = [];
|
|
10
|
-
state.context.collection = collections[state.context.collector];
|
|
11
|
-
return state;
|
|
12
|
-
}, function(state) {
|
|
13
|
-
if (this.isnt(state.context.collect, true)) {
|
|
14
|
-
return state;
|
|
15
|
-
}
|
|
16
|
-
var promise = state.promise,
|
|
17
|
-
deferred = this.deferred(),
|
|
18
|
-
that = this;
|
|
19
|
-
promise(function(ste) {
|
|
20
|
-
if (that.contains(['notify', 'error'], ste.type)) {
|
|
21
|
-
if (that.exists(ste.context.entry)) {
|
|
22
|
-
collections[ste.context.collector].push(ste.context.entry);
|
|
23
|
-
deferred.notify(ste);
|
|
24
|
-
} else if (that.exists(ste.context.error)) {
|
|
25
|
-
collections[ste.context.collector].push(ste.context.error);
|
|
26
|
-
deferred.reject(ste);
|
|
27
|
-
}
|
|
28
|
-
} else if ("resolve" === ste.type) {
|
|
29
|
-
if (that.exists(ste.context.collector)) {
|
|
30
|
-
ste.context.collection = that.clone(collections[ste.context.collector]);
|
|
31
|
-
}
|
|
32
|
-
delete ste.context.collector;
|
|
33
|
-
deferred.resolve(ste);
|
|
34
|
-
delete collections[ste.context.collector];
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
state.promise = deferred.promise;
|
|
38
|
-
return state;
|
|
39
|
-
}];
|
|
40
|
-
}(self));
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
window.dashAsync = window.dashAsync || (function (environment) {
|
|
2
|
-
"use strict";
|
|
3
|
-
return [ null, function (state) {
|
|
4
|
-
if(this.isnt(state.context.async, true)) {
|
|
5
|
-
return state;
|
|
6
|
-
}
|
|
7
|
-
var promise = state.promise,
|
|
8
|
-
deferred = this.deferred();
|
|
9
|
-
promise(function(ste) {
|
|
10
|
-
setTimeout( function() {
|
|
11
|
-
deferred.resolve(ste);
|
|
12
|
-
}, 3000 );
|
|
13
|
-
});
|
|
14
|
-
state.promise = deferred.promise;
|
|
15
|
-
return state;
|
|
16
|
-
} ];
|
|
17
|
-
}(self));
|