dexie 4.1.0-alpha.3 → 4.1.0-alpha.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.
- package/dist/dexie.d.ts +2 -2
- package/dist/dexie.js +97 -6
- package/dist/dexie.js.map +1 -1
- package/dist/dexie.min.js +1 -1
- package/dist/dexie.min.js.map +1 -1
- package/dist/dexie.mjs +97 -6
- package/dist/dexie.mjs.map +1 -1
- package/dist/modern/dexie.min.mjs +1 -1
- package/dist/modern/dexie.min.mjs.map +1 -1
- package/dist/modern/dexie.mjs +95 -4
- package/dist/modern/dexie.mjs.map +1 -1
- package/package.json +1 -1
package/dist/dexie.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* By David Fahlander, david.fahlander@gmail.com
|
|
6
6
|
*
|
|
7
|
-
* Version 4.1.0-alpha.
|
|
7
|
+
* Version 4.1.0-alpha.4, Sun Oct 13 2024
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -746,7 +746,7 @@ export interface DBCoreMutateResponse {
|
|
|
746
746
|
[operationNumber: number]: Error;
|
|
747
747
|
};
|
|
748
748
|
lastResult: any;
|
|
749
|
-
results?: any[]; //
|
|
749
|
+
results?: any[]; // Always present on responses to AddRequest and PutRequest.
|
|
750
750
|
}
|
|
751
751
|
export interface DBCoreAddRequest {
|
|
752
752
|
type: "add";
|
package/dist/dexie.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* By David Fahlander, david.fahlander@gmail.com
|
|
6
6
|
*
|
|
7
|
-
* Version 4.1.0-alpha.
|
|
7
|
+
* Version 4.1.0-alpha.4, Sun Oct 13 2024
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -1177,7 +1177,7 @@
|
|
|
1177
1177
|
}
|
|
1178
1178
|
}
|
|
1179
1179
|
|
|
1180
|
-
var DEXIE_VERSION = '4.1.0-alpha.
|
|
1180
|
+
var DEXIE_VERSION = '4.1.0-alpha.4';
|
|
1181
1181
|
var maxString = String.fromCharCode(65535);
|
|
1182
1182
|
var minKey = -Infinity;
|
|
1183
1183
|
var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
|
|
@@ -1339,6 +1339,9 @@
|
|
|
1339
1339
|
var pkKeyPath = table.schema.primKey.keyPath;
|
|
1340
1340
|
var docCache = getDocCache(db);
|
|
1341
1341
|
return {
|
|
1342
|
+
set: function () {
|
|
1343
|
+
throw new TypeError("Y.Doc properties are read-only");
|
|
1344
|
+
},
|
|
1342
1345
|
get: function () {
|
|
1343
1346
|
var id = getByKeyPath(this, pkKeyPath);
|
|
1344
1347
|
var doc = docCache.find(table.name, id, prop);
|
|
@@ -1535,13 +1538,14 @@
|
|
|
1535
1538
|
}
|
|
1536
1539
|
if (this.schema.yProps) {
|
|
1537
1540
|
var Y_1 = getYLibrary(db);
|
|
1538
|
-
|
|
1539
|
-
__extends(
|
|
1540
|
-
function
|
|
1541
|
+
var DBObjectWithYProps = (function (_super) {
|
|
1542
|
+
__extends(DBObjectWithYProps, _super);
|
|
1543
|
+
function DBObjectWithYProps() {
|
|
1541
1544
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
1542
1545
|
}
|
|
1543
|
-
return
|
|
1546
|
+
return DBObjectWithYProps;
|
|
1544
1547
|
}(constructor));
|
|
1548
|
+
constructor = DBObjectWithYProps;
|
|
1545
1549
|
this.schema.yProps.forEach(function (_a) {
|
|
1546
1550
|
var prop = _a.prop, updatesTable = _a.updatesTable;
|
|
1547
1551
|
Object.defineProperty(constructor.prototype, prop, createYDocProperty(db, Y_1, _this, prop, updatesTable));
|
|
@@ -3847,6 +3851,87 @@
|
|
|
3847
3851
|
});
|
|
3848
3852
|
}
|
|
3849
3853
|
|
|
3854
|
+
var EMPTY_ARRAY = [];
|
|
3855
|
+
function createYjsMiddleware(dbSchema, Y) {
|
|
3856
|
+
return {
|
|
3857
|
+
stack: 'dbcore',
|
|
3858
|
+
name: 'yjsMiddleware',
|
|
3859
|
+
level: 50,
|
|
3860
|
+
create: function (downCore) {
|
|
3861
|
+
return (__assign(__assign({}, downCore), { table: function (tableName) {
|
|
3862
|
+
var downTable = downCore.table(tableName);
|
|
3863
|
+
var dbTableSchema = dbSchema[tableName];
|
|
3864
|
+
var yProps = dbTableSchema.yProps;
|
|
3865
|
+
if (!yProps || yProps.length === 0)
|
|
3866
|
+
return downTable;
|
|
3867
|
+
var tableMiddleware = __assign(__assign({}, downTable), { mutate: function (req) {
|
|
3868
|
+
if (req.type !== 'add' && req.type !== 'put')
|
|
3869
|
+
return downTable.mutate(req);
|
|
3870
|
+
var reqClone = req;
|
|
3871
|
+
var updateSources = yProps
|
|
3872
|
+
.map(function (p) { return ({
|
|
3873
|
+
p: p,
|
|
3874
|
+
entries: req.values.flatMap(function (value, iter) {
|
|
3875
|
+
if (!value || typeof value !== 'object')
|
|
3876
|
+
throw new TypeError("Table ".concat(tableName, " (with Y-properties) must only contain objects"));
|
|
3877
|
+
if (!hasOwn(value, p.prop))
|
|
3878
|
+
return [];
|
|
3879
|
+
if (reqClone === req)
|
|
3880
|
+
reqClone = __assign(__assign({}, req), { values: req.values.map(function (v) { return (__assign({}, v)); }) });
|
|
3881
|
+
delete reqClone.values[iter][p.prop];
|
|
3882
|
+
var doc = value[p.prop];
|
|
3883
|
+
if (doc === null)
|
|
3884
|
+
throw new TypeError("Cannot set Y property to null");
|
|
3885
|
+
if (doc === undefined)
|
|
3886
|
+
return EMPTY_ARRAY;
|
|
3887
|
+
if (typeof doc !== 'object' || !('whenLoaded' in doc)) {
|
|
3888
|
+
throw new TypeError("Y properties can only be inited with an Y.Doc instance or undefined to create an empty Y.Doc");
|
|
3889
|
+
}
|
|
3890
|
+
if (req.type === 'put')
|
|
3891
|
+
throw new TypeError("Setting ".concat(tableName, ".").concat(p.prop, " (declared as ").concat(p.prop, ":Y) is only allowed when inserting new objects using db.").concat(tableName, ".add(), not put() or update()."));
|
|
3892
|
+
if (Y.encodeStateVector(doc).length === 1) {
|
|
3893
|
+
return EMPTY_ARRAY;
|
|
3894
|
+
}
|
|
3895
|
+
return {
|
|
3896
|
+
iter: iter,
|
|
3897
|
+
u: Y.encodeStateAsUpdateV2(doc),
|
|
3898
|
+
};
|
|
3899
|
+
}),
|
|
3900
|
+
}); })
|
|
3901
|
+
.filter(function (_a) {
|
|
3902
|
+
var entries = _a.entries;
|
|
3903
|
+
return entries.length > 0;
|
|
3904
|
+
});
|
|
3905
|
+
if (req === reqClone)
|
|
3906
|
+
return downTable.mutate(req);
|
|
3907
|
+
return downTable.mutate(reqClone).then(function (res) {
|
|
3908
|
+
if (updateSources.length === 0)
|
|
3909
|
+
return res;
|
|
3910
|
+
return Promise.all(updateSources.map(function (_a) {
|
|
3911
|
+
var p = _a.p, entries = _a.entries;
|
|
3912
|
+
var updatesTable = downCore.table(p.updatesTable);
|
|
3913
|
+
var updatesToInsert = entries.map(function (_a) {
|
|
3914
|
+
var iter = _a.iter, u = _a.u;
|
|
3915
|
+
return ({
|
|
3916
|
+
k: res.results[iter],
|
|
3917
|
+
u: u,
|
|
3918
|
+
f: 1,
|
|
3919
|
+
});
|
|
3920
|
+
});
|
|
3921
|
+
return updatesTable.mutate({
|
|
3922
|
+
type: 'add',
|
|
3923
|
+
values: updatesToInsert,
|
|
3924
|
+
trans: req.trans,
|
|
3925
|
+
});
|
|
3926
|
+
})).then(function () { return res; });
|
|
3927
|
+
});
|
|
3928
|
+
} });
|
|
3929
|
+
return tableMiddleware;
|
|
3930
|
+
} }));
|
|
3931
|
+
},
|
|
3932
|
+
};
|
|
3933
|
+
}
|
|
3934
|
+
|
|
3850
3935
|
var Version = (function () {
|
|
3851
3936
|
function Version() {
|
|
3852
3937
|
}
|
|
@@ -3911,6 +3996,12 @@
|
|
|
3911
3996
|
db.table(tableName).mapToClass(dbschema[tableName].mappedClass || Object);
|
|
3912
3997
|
}
|
|
3913
3998
|
});
|
|
3999
|
+
if (Object.values(dbschema).some(function (table) { return table.yProps; })) {
|
|
4000
|
+
db.use(createYjsMiddleware(dbschema, getYLibrary(db)));
|
|
4001
|
+
}
|
|
4002
|
+
else {
|
|
4003
|
+
db.unuse({ stack: 'dbcore', name: 'yjsMiddleware' });
|
|
4004
|
+
}
|
|
3914
4005
|
return this;
|
|
3915
4006
|
};
|
|
3916
4007
|
Version.prototype.upgrade = function (upgradeFunction) {
|