@buley/dash 0.0.30 → 2.1.4

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 (116) hide show
  1. package/README.md +82 -65
  2. package/dist/src/engine/ai.d.ts +10 -0
  3. package/dist/src/engine/ai.js +47 -0
  4. package/dist/src/engine/sqlite.d.ts +31 -0
  5. package/dist/src/engine/sqlite.js +239 -0
  6. package/dist/src/engine/vec_extension.d.ts +5 -0
  7. package/dist/src/engine/vec_extension.js +10 -0
  8. package/dist/src/index.d.ts +3 -0
  9. package/dist/src/index.js +3 -0
  10. package/dist/src/mcp/server.d.ts +8 -0
  11. package/dist/src/mcp/server.js +87 -0
  12. package/dist/src/reactivity/signal.d.ts +3 -0
  13. package/dist/src/reactivity/signal.js +31 -0
  14. package/dist/src/sync/backup.d.ts +12 -0
  15. package/dist/src/sync/backup.js +44 -0
  16. package/dist/src/sync/connection.d.ts +16 -0
  17. package/dist/src/sync/connection.js +29 -0
  18. package/dist/src/sync/provider.d.ts +11 -0
  19. package/dist/src/sync/provider.js +67 -0
  20. package/dist/tsconfig.tsbuildinfo +1 -0
  21. package/package.json +33 -31
  22. package/.coveralls.yml +0 -1
  23. package/.github/workflows/opencommit.yml +0 -33
  24. package/.github/workflows/testing.yml +0 -20
  25. package/.gitmodules +0 -0
  26. package/behaviors/cache.dev.js +0 -282
  27. package/behaviors/changes.dev.js +0 -337
  28. package/behaviors/collect.dev.js +0 -40
  29. package/behaviors/examples/async.dev.js +0 -17
  30. package/behaviors/firebase.dev.js +0 -283
  31. package/behaviors/live.dev.js +0 -67
  32. package/behaviors/map.dev.js +0 -54
  33. package/behaviors/mapreduce.dev.js +0 -68
  34. package/behaviors/match.dev.js +0 -66
  35. package/behaviors/patch.dev.js +0 -69
  36. package/behaviors/rest.dev.js +0 -340
  37. package/behaviors/shorthand.dev.js +0 -59
  38. package/behaviors/stats.dev.js +0 -672
  39. package/dist/behaviors/index.js +0 -142
  40. package/dist/database/index.js +0 -76
  41. package/dist/databases/index.js +0 -121
  42. package/dist/entry/index.js +0 -166
  43. package/dist/index.js +0 -93
  44. package/dist/indexes/index.js +0 -153
  45. package/dist/store/index.js +0 -97
  46. package/dist/stores/index.js +0 -90
  47. package/dist/utilities/index.js +0 -174
  48. package/documentation/database/closing.md +0 -3
  49. package/documentation/database/getting.md +0 -1
  50. package/documentation/database/opening.md +0 -5
  51. package/documentation/database/removing.md +0 -3
  52. package/documentation/databases.md +0 -21
  53. package/documentation/entries.md +0 -13
  54. package/documentation/entry/adding.md +0 -1
  55. package/documentation/entry/getting.md +0 -4
  56. package/documentation/entry/putting.md +0 -0
  57. package/documentation/entry/removing.md +0 -3
  58. package/documentation/entry/updating.md +0 -0
  59. package/documentation/general/security.md +0 -10
  60. package/documentation/general/transaction/requests.md +0 -3
  61. package/documentation/general/transactions.md +0 -5
  62. package/documentation/index/creating.md +0 -1
  63. package/documentation/index/getting.md +0 -1
  64. package/documentation/index/iterating.md +0 -1
  65. package/documentation/index/removing.md +0 -1
  66. package/documentation/indexes.md +0 -3
  67. package/documentation/key/cursors.md +0 -5
  68. package/documentation/key/range/bounds.md +0 -11
  69. package/documentation/key/range/direction.md +0 -1
  70. package/documentation/key/ranges.md +0 -3
  71. package/documentation/keys.md +0 -12
  72. package/documentation/objectstore/clearing.md +0 -1
  73. package/documentation/objectstore/creating.md +0 -1
  74. package/documentation/objectstore/getting.md +0 -1
  75. package/documentation/objectstore/iteration.md +0 -1
  76. package/documentation/objectstore/removing.md +0 -1
  77. package/documentation/overview.md +0 -5
  78. package/documentation/stores.md +0 -13
  79. package/jest.config.js +0 -12
  80. package/src/behaviors/index.ts +0 -140
  81. package/src/database/index.ts +0 -81
  82. package/src/databases/index.ts +0 -127
  83. package/src/entry/index.ts +0 -183
  84. package/src/index/index.ts +0 -61
  85. package/src/index.ts +0 -96
  86. package/src/indexes/index.ts +0 -151
  87. package/src/store/index.ts +0 -102
  88. package/src/stores/index.ts +0 -90
  89. package/src/utilities/index.ts +0 -349
  90. package/tests/behaviors/behaviors.spec.ts +0 -123
  91. package/tests/database/database.spec.ts +0 -177
  92. package/tests/databases/databases.spec.ts +0 -199
  93. package/tests/entry/entry.spec.ts +0 -252
  94. package/tests/index/index.spec.ts +0 -94
  95. package/tests/indexes/indexes.spec.ts +0 -203
  96. package/tests/store/store.spec.ts +0 -164
  97. package/tests/stores/stores.spec.ts +0 -148
  98. package/tests/utilities/clone.spec.ts +0 -48
  99. package/tests/utilities/cloneError.spec.ts +0 -33
  100. package/tests/utilities/contains.spec.ts +0 -28
  101. package/tests/utilities/exists.spec.ts +0 -21
  102. package/tests/utilities/is.spec.ts +0 -37
  103. package/tests/utilities/isArray.spec.ts +0 -21
  104. package/tests/utilities/isBoolean.spec.ts +0 -23
  105. package/tests/utilities/isEmpty.spec.ts +0 -45
  106. package/tests/utilities/isFunction.spec.ts +0 -30
  107. package/tests/utilities/isNumber.spec.ts +0 -29
  108. package/tests/utilities/isObject.spec.ts +0 -42
  109. package/tests/utilities/isRegEx.spec.ts +0 -33
  110. package/tests/utilities/isString.spec.ts +0 -25
  111. package/tests/utilities/isnt.spec.ts +0 -50
  112. package/tests/utilities/randomId.spec.ts +0 -39
  113. package/tests/utilities/safeApply.spec.ts +0 -49
  114. package/tests/utilities/safeEach.spec.ts +0 -38
  115. package/tests/utilities/safeIterate.spec.ts +0 -47
  116. package/tsconfig.json +0 -16
@@ -1,153 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.indexesMethods = void 0;
4
- /**
5
- * Indexes methods
6
- * @module indexes
7
- */
8
- var utilities_1 = require("../utilities");
9
- // Indexes methods
10
- exports.indexesMethods = {
11
- /**
12
- * Get all indexes from a specific object store.
13
- * @param get_ctx The context object.
14
- * @returns Promise<DashContext>
15
- */
16
- get: function (get_ctx) {
17
- return new Promise(function (resolve, reject) {
18
- var _a;
19
- try {
20
- get_ctx.indexes = (_a = get_ctx.objectstore) === null || _a === void 0 ? void 0 : _a.indexNames;
21
- if (get_ctx.on_success) {
22
- (0, utilities_1.safeApply)(get_ctx.on_success, [get_ctx]);
23
- }
24
- resolve(get_ctx);
25
- }
26
- catch (error) {
27
- get_ctx.error = (0, utilities_1.cloneError)(error);
28
- if (get_ctx.on_error) {
29
- (0, utilities_1.safeApply)(get_ctx.on_error, [get_ctx]);
30
- }
31
- reject(get_ctx);
32
- }
33
- });
34
- },
35
- /**
36
- * Add a new index to an object store.
37
- * @param add_ctx The context object.
38
- * @returns Promise<DashContext>
39
- */
40
- add: function (add_ctx) {
41
- return new Promise(function (resolve, reject) {
42
- var _a;
43
- try {
44
- (_a = add_ctx.objectstore) === null || _a === void 0 ? void 0 : _a.createIndex(add_ctx.index, add_ctx.index_key_path, {
45
- unique: !!add_ctx.index_unique,
46
- multiEntry: !!add_ctx.index_multi_entry
47
- });
48
- if (add_ctx.on_success) {
49
- (0, utilities_1.safeApply)(add_ctx.on_success, [add_ctx]);
50
- }
51
- resolve(add_ctx);
52
- }
53
- catch (error) {
54
- add_ctx.error = (0, utilities_1.cloneError)(error);
55
- if (add_ctx.on_error) {
56
- (0, utilities_1.safeApply)(add_ctx.on_error, [add_ctx]);
57
- }
58
- reject(add_ctx);
59
- }
60
- });
61
- },
62
- /**
63
- * Remove an index from an object store.
64
- * @param remove_ctx The context object.
65
- * @returns Promise<DashContext>
66
- */
67
- remove: function (remove_ctx) {
68
- return new Promise(function (resolve, reject) {
69
- var _a;
70
- try {
71
- (_a = remove_ctx.objectstore) === null || _a === void 0 ? void 0 : _a.deleteIndex(remove_ctx.index);
72
- if (remove_ctx.on_success) {
73
- (0, utilities_1.safeApply)(remove_ctx.on_success, [remove_ctx]);
74
- }
75
- resolve(remove_ctx);
76
- }
77
- catch (error) {
78
- remove_ctx.error = (0, utilities_1.cloneError)(error);
79
- if (remove_ctx.on_error) {
80
- (0, utilities_1.safeApply)(remove_ctx.on_error, [remove_ctx]);
81
- }
82
- reject(remove_ctx);
83
- }
84
- });
85
- },
86
- /**
87
- * Get all entries from a specific index.
88
- * @param get_ctx The context object.
89
- * @returns Promise<DashContext>
90
- */
91
- getEntries: function (get_ctx) {
92
- return new Promise(function (resolve, reject) {
93
- var _a, _b;
94
- var request = (_b = (_a = get_ctx.objectstore) === null || _a === void 0 ? void 0 : _a.index(get_ctx.index)) === null || _b === void 0 ? void 0 : _b.openCursor();
95
- if (!request) {
96
- get_ctx.error = new Error("Failed to open cursor");
97
- if (get_ctx.on_error) {
98
- (0, utilities_1.safeApply)(get_ctx.on_error, [get_ctx]);
99
- }
100
- reject(get_ctx);
101
- return;
102
- }
103
- request.onsuccess = function (event) {
104
- var cursor = request.result;
105
- if (cursor) {
106
- if (get_ctx.on_success) {
107
- (0, utilities_1.safeApply)(get_ctx.on_success, [cursor.value]);
108
- }
109
- cursor.continue();
110
- }
111
- else {
112
- if (get_ctx.on_complete) {
113
- (0, utilities_1.safeApply)(get_ctx.on_complete, [get_ctx]);
114
- }
115
- resolve(get_ctx);
116
- }
117
- };
118
- request.onerror = function (event) {
119
- get_ctx.error = (0, utilities_1.cloneError)(request.error);
120
- if (get_ctx.on_error) {
121
- (0, utilities_1.safeApply)(get_ctx.on_error, [get_ctx]);
122
- }
123
- reject(get_ctx);
124
- };
125
- });
126
- },
127
- /**
128
- * Counts the number of entries in a specific index.
129
- * @param count_ctx The context object.
130
- * @returns Promise<DashContext>
131
- */
132
- countEntries: function (count_ctx) {
133
- return new Promise(function (resolve, reject) {
134
- var _a, _b;
135
- var request = (_b = (_a = count_ctx.objectstore) === null || _a === void 0 ? void 0 : _a.index(count_ctx.index)) === null || _b === void 0 ? void 0 : _b.count();
136
- request === null || request === void 0 ? void 0 : request.addEventListener('success', function () {
137
- count_ctx.total = request.result;
138
- if (count_ctx.on_success) {
139
- (0, utilities_1.safeApply)(count_ctx.on_success, [count_ctx]);
140
- }
141
- resolve(count_ctx);
142
- });
143
- request === null || request === void 0 ? void 0 : request.addEventListener('error', function (event) {
144
- count_ctx.error = (0, utilities_1.cloneError)(event.target.error);
145
- if (count_ctx.on_error) {
146
- (0, utilities_1.safeApply)(count_ctx.on_error, [count_ctx]);
147
- }
148
- reject(count_ctx);
149
- });
150
- });
151
- }
152
- };
153
- exports.default = exports.indexesMethods;
@@ -1,97 +0,0 @@
1
- "use strict";
2
- /**
3
- * Store methods
4
- * @module store
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.storeMethods = void 0;
8
- var utilities_1 = require("../utilities");
9
- // Store methods
10
- exports.storeMethods = {
11
- /**
12
- * Clear a store.
13
- * @param clear_ctx
14
- * @returns Promise<DashContext>
15
- */
16
- clear: function (clear_ctx) {
17
- return new Promise(function (resolve, reject) {
18
- var _a;
19
- var request = (_a = clear_ctx.objectstore) === null || _a === void 0 ? void 0 : _a.clear();
20
- request === null || request === void 0 ? void 0 : request.addEventListener('success', function () {
21
- if (clear_ctx.on_success) {
22
- clear_ctx.on_success(clear_ctx); // Call the success callback here
23
- }
24
- resolve(clear_ctx);
25
- });
26
- request === null || request === void 0 ? void 0 : request.addEventListener('error', function (event) {
27
- clear_ctx.error = (0, utilities_1.cloneError)(event.target.error);
28
- if (clear_ctx.on_error) {
29
- clear_ctx.on_error(clear_ctx); // Call the error callback here
30
- }
31
- reject(clear_ctx);
32
- });
33
- });
34
- },
35
- /**
36
- * Remove a store entry.
37
- * @param remove_ctx
38
- * @returns Promise<DashContext>
39
- */
40
- remove: function (remove_ctx) {
41
- return new Promise(function (resolve, reject) {
42
- var _a;
43
- var request = (_a = remove_ctx.objectstore) === null || _a === void 0 ? void 0 : _a.delete(remove_ctx.key);
44
- request === null || request === void 0 ? void 0 : request.addEventListener('success', function () {
45
- if (remove_ctx.on_success) {
46
- remove_ctx.on_success(remove_ctx); // Call the success callback here
47
- }
48
- resolve(remove_ctx);
49
- });
50
- request === null || request === void 0 ? void 0 : request.addEventListener('error', function (event) {
51
- remove_ctx.error = (0, utilities_1.cloneError)(event.target.error);
52
- if (remove_ctx.on_error) {
53
- remove_ctx.on_error(remove_ctx); // Call the error callback here
54
- }
55
- reject(remove_ctx);
56
- });
57
- });
58
- },
59
- /**
60
- * Get a store entry.
61
- * @param get_ctx
62
- * @returns Promise<DashContext>
63
- */
64
- get: function (get_ctx) {
65
- return new Promise(function (resolve, reject) {
66
- var _a, _b, _c;
67
- var request = (0, utilities_1.exists)(get_ctx.index)
68
- ? (_b = (_a = get_ctx.objectstore) === null || _a === void 0 ? void 0 : _a.index(get_ctx.index)) === null || _b === void 0 ? void 0 : _b.get(get_ctx.key)
69
- : (_c = get_ctx.objectstore) === null || _c === void 0 ? void 0 : _c.get(get_ctx.key);
70
- request === null || request === void 0 ? void 0 : request.addEventListener('success', function () {
71
- get_ctx.entry = request.result;
72
- if (!get_ctx.entry) {
73
- get_ctx.error = { message: 'missing', name: 'DashNoEntry' };
74
- if (get_ctx.on_error) {
75
- get_ctx.on_error(get_ctx); // Call the error callback here
76
- }
77
- reject(get_ctx);
78
- }
79
- else {
80
- if (get_ctx.on_success) {
81
- get_ctx.on_success(get_ctx); // Call the success callback here
82
- }
83
- resolve(get_ctx);
84
- }
85
- });
86
- request === null || request === void 0 ? void 0 : request.addEventListener('error', function (event) {
87
- get_ctx.error = (0, utilities_1.cloneError)(event.target.error);
88
- if (get_ctx.on_error) {
89
- get_ctx.on_error(get_ctx); // Call the error callback here
90
- }
91
- reject(get_ctx);
92
- });
93
- });
94
- }
95
- };
96
- // Export the store methods
97
- exports.default = exports.storeMethods;
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.storesMethods = void 0;
4
- /**
5
- * Stores methods.
6
- * @Module stores
7
- */
8
- var utilities_1 = require("../utilities");
9
- // Store methods
10
- exports.storesMethods = {
11
- /**
12
- * Get all object stores from the current database.
13
- * @param get_ctx The context object.
14
- * @returns Promise<DashContext>
15
- * @private
16
- */
17
- get: function (get_ctx) {
18
- var _a;
19
- // This method retrieves all object stores synchronously or asynchronously via an on_success callback.
20
- get_ctx.stores = (_a = get_ctx.db) === null || _a === void 0 ? void 0 : _a.objectStoreNames;
21
- (0, utilities_1.safeApply)(get_ctx.on_success, [get_ctx]);
22
- },
23
- /**
24
- * Add a new object store to the current database.
25
- * @param add_ctx The context object.
26
- * @returns Promise<DashContext>
27
- * @private
28
- */
29
- add: function (add_ctx) {
30
- var _a;
31
- // This method adds a new object store in the database, creating a version change.
32
- add_ctx.db = (_a = add_ctx.request) === null || _a === void 0 ? void 0 : _a.result;
33
- if (!add_ctx.db) {
34
- throw new Error("Database is undefined");
35
- }
36
- var store = add_ctx.db.createObjectStore(add_ctx.store, {
37
- keyPath: add_ctx.store_key_path || null,
38
- autoIncrement: !!add_ctx.auto_increment
39
- });
40
- if (add_ctx.request) {
41
- add_ctx.db = add_ctx.request.result;
42
- }
43
- if (add_ctx.indexes) {
44
- // If there are indexes defined, we create them in the new store
45
- add_ctx.indexes.forEach(function (idx) {
46
- store.createIndex(idx.name, idx.keyPath, {
47
- unique: !!idx.unique,
48
- multiEntry: !!idx.multiEntry
49
- });
50
- });
51
- }
52
- (0, utilities_1.safeApply)(add_ctx.on_success, [add_ctx]);
53
- },
54
- /**
55
- * Remove an object store from the current database.
56
- * @param remove_ctx The context object.
57
- * @returns Promise<DashContext>
58
- * @private
59
- */
60
- remove: function (remove_ctx) {
61
- var _a;
62
- // This method deletes a specified object store, triggering a version change.
63
- (_a = remove_ctx.db) === null || _a === void 0 ? void 0 : _a.deleteObjectStore(remove_ctx.store);
64
- (0, utilities_1.safeApply)(remove_ctx.on_success, [remove_ctx]);
65
- },
66
- /**
67
- * Clear all object stores in the current database.
68
- * @param clear_ctx The context object.
69
- * @returns Promise<DashContext>
70
- * @private
71
- */
72
- clearAll: function (clear_ctx) {
73
- var _a, _b;
74
- // This method clears all entries in all object stores in the current database.
75
- var storeNames = Array.from(((_a = clear_ctx.db) === null || _a === void 0 ? void 0 : _a.objectStoreNames) || []);
76
- var transaction = (_b = clear_ctx.db) === null || _b === void 0 ? void 0 : _b.transaction(storeNames, "readwrite");
77
- storeNames === null || storeNames === void 0 ? void 0 : storeNames.forEach(function (storeName) {
78
- var objectStore = transaction === null || transaction === void 0 ? void 0 : transaction.objectStore(storeName);
79
- objectStore === null || objectStore === void 0 ? void 0 : objectStore.clear();
80
- });
81
- transaction === null || transaction === void 0 ? void 0 : transaction.addEventListener('complete', function () {
82
- (0, utilities_1.safeApply)(clear_ctx.on_success, [clear_ctx]);
83
- });
84
- transaction === null || transaction === void 0 ? void 0 : transaction.addEventListener('error', function (event) {
85
- clear_ctx.error = (0, utilities_1.cloneError)(event.target.error);
86
- (0, utilities_1.safeApply)(clear_ctx.on_error, [clear_ctx]);
87
- });
88
- }
89
- };
90
- exports.default = exports.storesMethods;
@@ -1,174 +0,0 @@
1
- "use strict";
2
- /**
3
- * Common interfaces and utilities.
4
- * @module utilities
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.randomId = exports.safeIterate = exports.safeEach = exports.safeApply = exports.isString = exports.isNumber = exports.isObject = exports.isFunction = exports.isRegEx = exports.isBoolean = exports.isArray = exports.isnt = exports.is = exports.isEmpty = exports.exists = exports.contains = exports.clone = exports.cloneError = void 0;
8
- /**
9
- * @param {DashContext} ctx - The context.
10
- * @returns {Promise<DashContext>} The promise object.
11
- * @private
12
- */
13
- var cloneError = function (error) {
14
- var clonedError = new Error(error.message);
15
- // Optionally, clone the stack trace if it's available
16
- if (error.stack) {
17
- clonedError.stack = error.stack;
18
- }
19
- // Clone custom properties
20
- Object.keys(error).forEach(function (key) {
21
- clonedError[key] = error[key];
22
- });
23
- return clonedError;
24
- };
25
- exports.cloneError = cloneError;
26
- // Clone function that performs a deep copy of an object, array, or function
27
- var clone = function (source) {
28
- if (source === null || typeof source !== 'object') {
29
- return source;
30
- }
31
- // Handle arrays
32
- if (Array.isArray(source)) {
33
- return source.map(function (item) { return (0, exports.clone)(item); });
34
- }
35
- // Handle functions (return the same function reference)
36
- if (typeof source === 'function') {
37
- return source;
38
- }
39
- // Handle objects
40
- var copy = {};
41
- for (var key in source) {
42
- if (source.hasOwnProperty(key)) {
43
- copy[key] = (0, exports.clone)(source[key]); // Recursively clone properties
44
- }
45
- }
46
- return copy;
47
- };
48
- exports.clone = clone;
49
- // Checks if an item exists in an array or object
50
- var contains = function (str, substr) {
51
- if (typeof str !== 'string' || typeof substr !== 'string') {
52
- return false; // Ensure both inputs are strings
53
- }
54
- // An empty substring should always return true
55
- if (substr === '') {
56
- return true;
57
- }
58
- return str.includes(substr); // Use built-in includes method for substring checking
59
- };
60
- exports.contains = contains;
61
- // Checks whether a value exists
62
- var exists = function (value) {
63
- return value !== null && value !== undefined;
64
- };
65
- exports.exists = exists;
66
- // Checks if a variable is empty
67
- var isEmpty = function (mixed_var) {
68
- // Handle null and undefined cases
69
- if (mixed_var === null || mixed_var === undefined) {
70
- return true;
71
- }
72
- // Handle objects (including arrays)
73
- if (typeof mixed_var === 'object') {
74
- return Object.keys(mixed_var).length === 0;
75
- }
76
- // Handle strings (empty string should return true)
77
- if (typeof mixed_var === 'string') {
78
- return mixed_var.length === 0;
79
- }
80
- // For numbers and booleans, they are considered "not collections" and hence should return true
81
- if (typeof mixed_var === 'number' || typeof mixed_var === 'boolean') {
82
- return true;
83
- }
84
- return false;
85
- };
86
- exports.isEmpty = isEmpty;
87
- var is = function (a, b) {
88
- return Object.is(a, b);
89
- };
90
- exports.is = is;
91
- var isnt = function (a, b) {
92
- return a !== b;
93
- };
94
- exports.isnt = isnt;
95
- exports.isArray = Array.isArray;
96
- var isBoolean = function (mixed_var) { return typeof mixed_var === 'boolean'; };
97
- exports.isBoolean = isBoolean;
98
- var isRegEx = function (mixed_var) { return mixed_var instanceof RegExp; };
99
- exports.isRegEx = isRegEx;
100
- var isFunction = function (value) {
101
- if (typeof value !== 'function') {
102
- return false;
103
- }
104
- // Check if it's a class constructor by examining the function's string representation
105
- var isClass = /^class\s/.test(Function.prototype.toString.call(value));
106
- return !isClass;
107
- };
108
- exports.isFunction = isFunction;
109
- var isObject = function (value) {
110
- return Object.prototype.toString.call(value) === '[object Object]';
111
- };
112
- exports.isObject = isObject;
113
- var isNumber = function (mixed_var) { return typeof mixed_var === 'number'; };
114
- exports.isNumber = isNumber;
115
- var isString = function (value) {
116
- return typeof value === 'string' || value instanceof String;
117
- };
118
- exports.isString = isString;
119
- // Applies a function if it's defined
120
- var safeApply = function (fn, args, context, err) {
121
- if (typeof fn === 'function')
122
- return fn.apply(context || {}, args || []);
123
- if (typeof err === 'function')
124
- return (0, exports.safeApply)(err, []);
125
- };
126
- exports.safeApply = safeApply;
127
- // Iterates through an array and applies a callback function
128
- var safeEach = function (items, callback, inc) {
129
- if (inc === void 0) { inc = 1; }
130
- for (var x = 0; x < items.length; x += inc) {
131
- (0, exports.safeApply)(callback, [items[x], x]);
132
- }
133
- };
134
- exports.safeEach = safeEach;
135
- // Iterates through an object's properties and applies a callback function
136
- var safeIterate = function (item, callback) {
137
- for (var attr in item) {
138
- if (item.hasOwnProperty(attr)) {
139
- callback(attr, item[attr]);
140
- }
141
- }
142
- };
143
- exports.safeIterate = safeIterate;
144
- // Generates a random string ID
145
- var randomId = function (len, charset) {
146
- if (len === void 0) { len = 16; }
147
- if (charset === void 0) { charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; }
148
- var str = '';
149
- for (var i = 0; i < len; i++) {
150
- str += charset.charAt(Math.floor(Math.random() * charset.length));
151
- }
152
- return str;
153
- };
154
- exports.randomId = randomId;
155
- exports.default = {
156
- cloneError: exports.cloneError,
157
- clone: exports.clone,
158
- contains: exports.contains,
159
- exists: exports.exists,
160
- isEmpty: exports.isEmpty,
161
- is: exports.is,
162
- isnt: exports.isnt,
163
- isArray: exports.isArray,
164
- isBoolean: exports.isBoolean,
165
- isRegEx: exports.isRegEx,
166
- isFunction: exports.isFunction,
167
- isObject: exports.isObject,
168
- isNumber: exports.isNumber,
169
- isString: exports.isString,
170
- safeApply: exports.safeApply,
171
- safeEach: exports.safeEach,
172
- safeIterate: exports.safeIterate,
173
- randomId: exports.randomId
174
- };
@@ -1,3 +0,0 @@
1
- Databases can be [`close`d](http://www.w3.org/TR/IndexedDB/#dfn-database-close-1).
2
-
3
- Databases are browser resources and, like all resources, expensive for the brower to maintain. Just as opening a database is the first step to doing anything in IndexedDB, closing a database is usually a good last step.
@@ -1 +0,0 @@
1
- It's typically not possible to enumerate all databases for a host. Typically the programmer must already know the name of our database in order to of opening it, else create a new one. The exception is in Chrome, which offers a non-standard way of enumerating existing databases for a host.
@@ -1,5 +0,0 @@
1
- To get to objects, you have to through object stores, and to get to object stores you have to go through databases. So the first step in interaction with `IndexedDB` is almost always to open a database. Database open requests are instances of [`IDBOpenDBRequest`](https://developer.mozilla.org/en-US/docs/Web/API/IDBOpenDBRequest).
2
-
3
- Opening an existing database and creating a new one work in the same way: if the name passed matches an existing database, that database is opened; if the name doesn't match an existing database, a new one will be created when opened using a unique name. Opening a new database, or opening an existing database with a version greather than the current version, will trigger a `versionchange` event.
4
-
5
- As written in the spec, an IDBDatabase interface "represents a connection to a database." There can be multiple connections at any given time. So long as a reference to that object exists, the connection should remain open unless closed explictly using the `close()` method on IDBDatabase.
@@ -1,3 +0,0 @@
1
- Databases can be removed or "deleted" and their resources will be freed up for use elsewhere.
2
-
3
- Once a database is deleted you can open a new one with the same name; this is similar to a `versionchange` transaction but destroys and object stores and their contents.
@@ -1,21 +0,0 @@
1
- A [`database`](http://www.w3.org/TR/IndexedDB/#dfn-database) houses object stores and have two distinguishing characteristics: a [`name`](http://www.w3.org/TR/IndexedDB/#dfn-object-store-name) (string) and [`version`](http://www.w3.org/TR/IndexedDB/#dfn-version) (number). They are reached through an instance of [`IDBFactory`](https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory) object at the `window.indexedDB` namespace
2
-
3
- ##### Names
4
-
5
- When opening a database, a programmer must specify a databases [`name`](http://www.w3.org/TR/IndexedDB/#dfn-object-store-name) and optionally its version. A database name is case-sensitive and cannot change.
6
-
7
- ##### Versions
8
-
9
- #### Database Versions
10
-
11
- [`Version`](http://www.w3.org/TR/IndexedDB/#dfn-version) numbers are positive whole numbers greater than zero. A programmer can set a database's version manually or implictly by opening an existing database name with a greater version number than the database contains. While a database's name can never change, the database version changes all the time.
12
-
13
- Specifying a version greater than the current allows us to entry a "version change" transaction that enables database schema changes. When no version is specified, the database will open with the most recent database version.
14
-
15
- Database version numbers are stored as [8-byte "int long long"](https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB#Opening_a_database) in the underlying C programming language implementation of IDB and can number anywhere between `1` and `18446744073709551615`.
16
-
17
- ##### `versionchange` transactions
18
-
19
- A version number can represent only one schema for particular database, but a programmer can change a database's layout by incrementing its version number, triggering something called a "`versionchange`" transaction. [Version changes](https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction#VERSION_CHANGE) preserve databases object stores and indexes, but from within a `versionchange` callback the programmer is allowed to make modifications to a database schema.
20
-
21
- Database operations that require a version change include both creating and deleting object stores, and both creating and deleting indexes.
@@ -1,13 +0,0 @@
1
- The base unit of data in IDB is a [`record`](http://www.w3.org/TR/IndexedDB/#dfn-record) or "entry" and IndexedDB is capable of storing as records most standard types of JavaScript data. To copy values to the database, IDB uses something called the "[`structured clone algorithm`](http://www.w3.org/TR/IndexedDB/#dfn-structured-clone-algorithm)".
2
-
3
- IDB only stores JavaScript list objects, but the values associated with keys on those objects that can typically be any value that "[cloned](http://www.w3.org/TR/IndexedDB/#dfn-structured-clone)", which includes both the basic JavaSript primitives and more complex object types: null values, `Boolean`s, `Number`s, `String`s, `Date`s, `Array`s, other `Object`s and even advanced types such as RegExp, Blob, File, FileList and ImageData objects. The only standard object type IDB's structured clone algorithm cannot deal with are function objects. Thus JavaScript functions cannot be stored in their native object form.
4
-
5
- #### Working With One Entry At A Time
6
-
7
- It's possible to ["`add`"](http://www.w3.org/TR/IndexedDB/#widl-IDBObjectStore-add) (create), ["`get`"](http://www.w3.org/TR/IndexedDB/#widl-IDBObjectStore-get) (read), ["`put`"](http://www.w3.org/TR/IndexedDB/#widl-IDBObjectStore-put) (update an existing object, else create a new one) and ["`delete`"](http://www.w3.org/TR/IndexedDB/#widl-IDBObjectStore-delete) (destroy) single objects in an object store. Generally, to `delete` or `get` a record requires using its `key`, but both `add` and `put` operations do not require a key and will handily return an object's object store key value when added or put (useful when using a [`key generator`](http://www.w3.org/TR/IndexedDB/#dfn-key-generator) and the key is unknown until after insertion).
8
-
9
- #### Working With Multiple Entries At The Same Time
10
-
11
- When querying for more than one object we must use indexes, and to use indexes we in complex manners we typically need to use a special type of request called a "cursor." When you want to ask for a [`range`](http://www.w3.org/TR/IndexedDB/#dfn-range) of data on an index, what you get back is not the data itself but rather a cursor, which is a reference to a [`position`](http://www.w3.org/TR/IndexedDB/#dfn-position) in the index and fires asyncronous callbacks as that position changes.
12
-
13
- When a cursor's callbacks fire, the programmer can place a request and then either "continue" the cursor or abandon it. This process continues until either the programmer is done with the request or the cursor has [exhausted](http://www.w3.org/TR/IndexedDB/#dfn-got-value) the results from its request [`source`](http://www.w3.org/TR/IndexedDB/#dfn-cursor-source).
@@ -1 +0,0 @@
1
- When adding or putting values, the various uniqueness rules for the store and indexes together apply to any entries added to that object store.
@@ -1,4 +0,0 @@
1
- #### Getting An Object From An Object Store
2
-
3
-
4
- #### Getting Multiple Objects From A Database
File without changes
@@ -1,3 +0,0 @@
1
- #### Removing Object From An Object Store
2
-
3
- #### Removing Multiple Objects From A Database
File without changes
@@ -1,10 +0,0 @@
1
- IDB is typically available in both the main `window` and in Web Workers thanks to an abstracted [`IDBEnvironment`](https://developer.mozilla.org/en-US/docs/Web/API/IDBEnvironment) interface. It is restricted to a given [`origin`](http://www.w3.org/TR/IndexedDB/#dfn-origin), and
2
- [`same-origin`](http://www.w3.org/TR/IndexedDB/#dfn-same-origin) security restrictions apply.
3
-
4
- Most browsers will ask a user's permission before allowing IDB to store data locally. Although the specification does not specify a size limit, some browsers enforce one.
5
-
6
- Firefox has no size limit but will ask permission before storing data larger than 50 megabytes. It exposes "quota" information via the `dom.indexedDB.warningQuota` factory attribute for the programmer to judge utilization.
7
-
8
- Chrome automatically grants "[`temporary`](https://developers.google.com/chrome/whitepapers/storage#temporary)" storage to IDB and allocates a maximum of 20% of its "shared storage pool". Chrome also allows a "[`persistent`](https://developers.google.com/chrome/whitepapers/storage#persistent)" storage mode that asks the user to authorize a host for offline storage but enforces no size limitations other than user disk space.
9
-
10
- IE allows IDB up to 250 megabytes of space and provides the [`window.indexedDB.remainingSpace`](http://msdn.microsoft.com/en-us/library/windows/apps/cc197016.aspx) factory attribute for the programmer to judge utilization.
@@ -1,3 +0,0 @@
1
- Certain transactions return data, or "[`results`](http://www.w3.org/TR/IndexedDB/#dfn-request-result)", from the database. These transactions are called "[`requests`](http://www.w3.org/TR/IndexedDB/#dfn-request)" and with the exception of database opening, the values are always various combinations of object "keys" and "values" and instances of [`IDBRequest`](https://developer.mozilla.org/en-US/docs/Web/API/IDBRequest). [`Request transactions`](http://www.w3.org/TR/IndexedDB/#dfn-request-transaction) are just that: a transaction request," namely the act of asking for something rather than the getting of it. A programmer encounters them when dealing with `IDBObjectStore`, `IDBIndex` or `IDBCursor` objects. They have a `done` attribute and, alternatively displaying the same information, a `readyState` that says whether they are "`pending`" or "`done`". Unlike many databases, requests are not fulfilled immediately after being [`placed`](http://www.w3.org/TR/IndexedDB/#dfn-place-request), or "synconronously"; however, these non-immediate responses are rather "asyncronous", and the mechanism a programmer uses to await an asynconrous reponse is by coding a "callback" function IDB can invoke on various "events" such as a successful response.
2
-
3
- There are various types of callbacks in IDB depending on the type of transaction. Requests generally have "onsuccess", "onerror and "onabort" callbacks. Others include "onupgradeneeded", "onclose" and "onblocked," sometimes seen when working with databases. Each event has a different meaning depending on the transaction, but for example "onsuccess", "onupgraded" are generally a good event for the programmer while "onerror", "onabort" and "onblocked" mean something went awry for him.
@@ -1,5 +0,0 @@
1
- In IDB, work [tasked](http://www.w3.org/TR/IndexedDB/#dfn-task) to a database [queue](http://www.w3.org/TR/IndexedDB/#dfn-queue-a-task) is called a "[`transaction`](http://www.w3.org/TR/IndexedDB/#dfn-transaction)". A transaction is an instance of [`IDBTransaction`](https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction) and characterized by its "[`scope`](http://www.w3.org/TR/IndexedDB/#dfn-scope)". Transaction scope, in turn, is characterized by both the work to be done and where the programmer wants the work to happen. To create a transaction against an open database, a programmer names the object stores on which she'd like to operate, and optionally specifies what type of transaction she'd like to create.
2
-
3
- There are three "[`modes`](http://www.w3.org/TR/IndexedDB/#dfn-mode)" of transactions: "[`readwrite`](http://www.w3.org/TR/IndexedDB/#dfn-read_write)", "[`readonly`](http://www.w3.org/TR/IndexedDB/#dfn-read_only)" and "[`versionchange`](http://www.w3.org/TR/IndexedDB/#dfn-version_change)". These are an instance of an interface called IDBTransactionMode. The default is "readonly", convienient because changing a data via a "write" is generally more expensive than to "read" that data. The granularity and providing of "readonly" vs. "readwrite" offers the programmer an the opportunity to speed up her code depending on her needs. The final transaction type, "versionchange", is used when changing the schema of a database.
4
-
5
- The [`lifetime`](http://www.w3.org/TR/IndexedDB/#dfn-transaction-lifetime) of a transactions lasts as long as it's referenced: it's "`active`" so long as it's being referenced, after which it is said to be "`finished`" and the transaction is [`committed`](http://www.w3.org/TR/IndexedDB/#dfn-commit).
@@ -1 +0,0 @@
1
- The options for creating a new `index` are similar to those when creating an object store: a `key path` is given using the standard key syntax and the `unique` and `multirow` options can both be used. The ["`unique`"](http://www.w3.org/TR/IndexedDB/#dfn-multirow#dfn-unique) parameter tells the browser not to allow two values to correspond to the same key and the ["multirow"](http://www.w3.org/TR/IndexedDB/#dfn-multirow) flag controls how the index behaves when dealing with `Array` values.
@@ -1 +0,0 @@
1
- With a string index name, it's possible to get a reference to an existing index from an object store.
@@ -1 +0,0 @@
1
- Using an object store on an open database, it's possible to get a list of indexes names. This list is an `Array`-like collection of string names.
@@ -1 +0,0 @@
1
- With a string index name, it's possible to get a reference to an existing index from an object store.
@@ -1,3 +0,0 @@
1
- [`Indexes`](http://www.w3.org/TR/IndexedDB/#dfn-index) are the way values are generally found in an object store. An `index` is an instance of [`IDBIndex`](https://developer.mozilla.org/en-US/docs/Web/API/IDBIndex) and is a list of keys and values and has two characterizing components: the key path to find the data and the record value itself. `Indexes` stored primarily by key, and secondarily by their values, in ascending order.
2
-
3
- Both adding and removing indexes requires a `versionchange` transaction.
@@ -1,5 +0,0 @@
1
- Using an index and a key range for that index, you can use a "[`cursor`](http://www.w3.org/TR/IndexedDB/#dfn-cursor)" to get, put and delete [`values`](http://www.w3.org/TR/IndexedDB/#dfn-cursor-value) one at a time but in single request. Cursors are also capable of "[`advancing`](http://www.w3.org/TR/IndexedDB/#widl-IDBCursor-advance)" and, in effect, skip a number of objects in an index for a given key range.
2
-
3
- Cursors traverse an index matching a given "key range". There is no limit on the number of cursors that can be used at the same time.
4
-
5
- Two different types of cursors: cursors that read just keys (instances of [`IDBCursor`](https://developer.mozilla.org/en-US/docs/Web/API/IDBCursor)) and cursors that read keys and values [`IDBCursorWithValue`](https://developer.mozilla.org/en-US/docs/Web/API/IDBCursorWithValue) which are created on an index using the [`openKeyCursor`](http://www.w3.org/TR/IndexedDB/#widl-IDBIndex-openKeyCursor) and [`openCursor`](http://www.w3.org/TR/IndexedDB/#widl-IDBIndex-openCursor) methods respectively.