@lossless.org/client 1.0.0 → 1.2.0
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_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/nosqldb/classes.atomicupdate.d.ts +21 -0
- package/dist_ts/nosqldb/classes.atomicupdate.js +41 -1
- package/dist_ts/nosqldb/classes.collection.d.ts +31 -0
- package/dist_ts/nosqldb/classes.collection.js +203 -32
- package/dist_ts/nosqldb/classes.collectiontopology.d.ts +11 -0
- package/dist_ts/nosqldb/classes.collectiontopology.js +16 -1
- package/dist_ts/nosqldb/classes.doc.d.ts +66 -0
- package/dist_ts/nosqldb/classes.doc.js +313 -24
- package/dist_ts/nosqldb/classes.exactpersistence.js +10 -2
- package/dist_ts/nosqldb/classes.ordinarypersistence.d.ts +6 -0
- package/dist_ts/nosqldb/classes.ordinarypersistence.js +7 -1
- package/dist_ts/nosqldb/classes.persistence.d.ts +6 -0
- package/dist_ts/nosqldb/classes.persistence.js +13 -1
- package/package.json +1 -1
- package/readme.md +11 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/nosqldb/classes.atomicupdate.ts +67 -0
- package/ts/nosqldb/classes.collection.ts +313 -37
- package/ts/nosqldb/classes.collectiontopology.ts +25 -0
- package/ts/nosqldb/classes.doc.ts +575 -21
- package/ts/nosqldb/classes.exactpersistence.ts +9 -1
- package/ts/nosqldb/classes.ordinarypersistence.ts +8 -0
- package/ts/nosqldb/classes.persistence.ts +17 -0
|
@@ -4,6 +4,7 @@ import { assertBsonWithoutMutation } from './classes.bsonassertion.js';
|
|
|
4
4
|
import { getOrdinaryPersistencePolicy } from './classes.ordinarypersistence.js';
|
|
5
5
|
|
|
6
6
|
import type { SmartdataCollection } from './classes.collection.js';
|
|
7
|
+
import { getIdentityIndexName } from './classes.collectiontopology.js';
|
|
7
8
|
import { registerCollectionReconnectHandler } from './classes.collectionlifecycle.js';
|
|
8
9
|
import type { SmartdataSession } from './classes.session.js';
|
|
9
10
|
import { acquireSmartdataSession } from './classes.session.js';
|
|
@@ -1024,10 +1025,17 @@ export class SmartdataExactCollection<
|
|
|
1024
1025
|
const missingUniqueIndexes = this.uniqueIndexes.filter(
|
|
1025
1026
|
(uniqueIndexArg) => !this.collection.uniqueIndexes.includes(uniqueIndexArg),
|
|
1026
1027
|
);
|
|
1028
|
+
const boundSchema = this.collection.getBoundModelSchema();
|
|
1027
1029
|
for (const uniqueIndex of missingUniqueIndexes) {
|
|
1028
1030
|
await targetCollectionArg.createIndex(
|
|
1029
1031
|
{ [uniqueIndex]: 1 },
|
|
1030
|
-
{
|
|
1032
|
+
{
|
|
1033
|
+
unique: true,
|
|
1034
|
+
// A model may back its identity with a differently named index;
|
|
1035
|
+
// creating `<field>_1` would duplicate that key.
|
|
1036
|
+
name: getIdentityIndexName(boundSchema, uniqueIndex)
|
|
1037
|
+
?? `${uniqueIndex}_1`,
|
|
1038
|
+
},
|
|
1031
1039
|
);
|
|
1032
1040
|
}
|
|
1033
1041
|
|
|
@@ -20,6 +20,14 @@ export interface IOrdinaryPersistencePolicy {
|
|
|
20
20
|
const policySymbol = Symbol.for('@push.rocks/smartdata.ordinaryPersistencePolicy');
|
|
21
21
|
const exactSymbol = Symbol.for('@push.rocks/smartdata.exactPersistencePolicy');
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Reports whether a model opted into exact persistence. Exact persistence owns
|
|
25
|
+
* the stored `_id` as a MongoDB ObjectId, so options that hand the primary key
|
|
26
|
+
* to a declared identity field must refuse those models by name.
|
|
27
|
+
*/
|
|
28
|
+
export const hasExactPersistencePolicy = (modelArg: any): boolean =>
|
|
29
|
+
Boolean(modelArg?.[exactSymbol]);
|
|
30
|
+
|
|
23
31
|
export const getOrdinaryPersistencePolicy = (modelArg: any): IOrdinaryPersistencePolicy | undefined => {
|
|
24
32
|
const policy = modelArg?.[policySymbol] as IOrdinaryPersistencePolicy | undefined;
|
|
25
33
|
if (policy && modelArg[exactSymbol]) {
|
|
@@ -43,6 +43,23 @@ export const isMongoDuplicateKeyError = (
|
|
|
43
43
|
);
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* MongoDB refuses an index whose key or name collides with an existing one:
|
|
48
|
+
* `IndexOptionsConflict` when an equivalent index already carries another
|
|
49
|
+
* name, `IndexKeySpecsConflict` when the name is taken by another key.
|
|
50
|
+
*/
|
|
51
|
+
export const isMongoIndexConflictError = (
|
|
52
|
+
errorArg: unknown,
|
|
53
|
+
): errorArg is plugins.mongodb.MongoServerError => {
|
|
54
|
+
return (
|
|
55
|
+
errorArg instanceof plugins.mongodb.MongoServerError &&
|
|
56
|
+
(errorArg.code === 85 ||
|
|
57
|
+
errorArg.code === 86 ||
|
|
58
|
+
errorArg.codeName === 'IndexOptionsConflict' ||
|
|
59
|
+
errorArg.codeName === 'IndexKeySpecsConflict')
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
46
63
|
export const normalizeOrdinaryPersistenceError = (
|
|
47
64
|
errorArg: unknown,
|
|
48
65
|
messageArg: string,
|