@atscript/db-mongo 0.1.138 → 0.1.139
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/index.cjs +18 -17
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +18 -17
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1276,16 +1276,13 @@ async function recreateTableImpl(host) {
|
|
|
1276
1276
|
const tableName = host._table.tableName;
|
|
1277
1277
|
host._log("recreateTable", tableName);
|
|
1278
1278
|
const tempName = `${tableName}__tmp_${Date.now()}`;
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
const temp = host.db.collection(tempName);
|
|
1287
|
-
await temp.aggregate([{ $merge: { into: tableName } }]).toArray();
|
|
1288
|
-
await temp.drop();
|
|
1279
|
+
await host.db.createCollection(tempName, host.collectionCreateOptions());
|
|
1280
|
+
try {
|
|
1281
|
+
await host.db.collection(tableName).aggregate([{ $merge: { into: tempName } }]).toArray();
|
|
1282
|
+
await host.db.renameCollection(tempName, tableName, { dropTarget: true });
|
|
1283
|
+
} catch (error) {
|
|
1284
|
+
await dropTableByNameImpl(host, tempName);
|
|
1285
|
+
throw error;
|
|
1289
1286
|
}
|
|
1290
1287
|
}
|
|
1291
1288
|
async function renameTableImpl(host, oldName) {
|
|
@@ -2128,15 +2125,19 @@ var MongoAdapter = class MongoAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
2128
2125
|
async ensureCollectionExists() {
|
|
2129
2126
|
if (!await this.collectionExists()) {
|
|
2130
2127
|
this._log("createCollection", this._table.tableName);
|
|
2131
|
-
|
|
2132
|
-
if (this._cappedOptions) {
|
|
2133
|
-
opts.capped = true;
|
|
2134
|
-
opts.size = this._cappedOptions.size;
|
|
2135
|
-
if (this._cappedOptions.max !== null && this._cappedOptions.max !== void 0) opts.max = this._cappedOptions.max;
|
|
2136
|
-
}
|
|
2137
|
-
await this.db.createCollection(this._table.tableName, opts);
|
|
2128
|
+
await this.db.createCollection(this._table.tableName, this.collectionCreateOptions());
|
|
2138
2129
|
}
|
|
2139
2130
|
}
|
|
2131
|
+
/** `createCollection` options for this table (`@db.mongo.capped` size/max). */
|
|
2132
|
+
collectionCreateOptions() {
|
|
2133
|
+
const opts = { comment: "Created by Atscript Mongo Adapter" };
|
|
2134
|
+
if (this._cappedOptions) {
|
|
2135
|
+
opts.capped = true;
|
|
2136
|
+
opts.size = this._cappedOptions.size;
|
|
2137
|
+
if (this._cappedOptions.max !== null && this._cappedOptions.max !== void 0) opts.max = this._cappedOptions.max;
|
|
2138
|
+
}
|
|
2139
|
+
return opts;
|
|
2140
|
+
}
|
|
2140
2141
|
/**
|
|
2141
2142
|
* Builds a Mongo filter for CAS-aware writes. Throws when `expectedVersion`
|
|
2142
2143
|
* is supplied for a non-versioned table — fail loud at the adapter boundary
|
package/dist/index.d.cts
CHANGED
|
@@ -380,6 +380,8 @@ declare class MongoAdapter extends BaseDbAdapter {
|
|
|
380
380
|
}>;
|
|
381
381
|
collectionExists(): Promise<boolean>;
|
|
382
382
|
ensureCollectionExists(): Promise<void>;
|
|
383
|
+
/** `createCollection` options for this table (`@db.mongo.capped` size/max). */
|
|
384
|
+
collectionCreateOptions(): Record<string, unknown>;
|
|
383
385
|
/**
|
|
384
386
|
* Builds a Mongo filter for CAS-aware writes. Throws when `expectedVersion`
|
|
385
387
|
* is supplied for a non-versioned table — fail loud at the adapter boundary
|
package/dist/index.d.mts
CHANGED
|
@@ -380,6 +380,8 @@ declare class MongoAdapter extends BaseDbAdapter {
|
|
|
380
380
|
}>;
|
|
381
381
|
collectionExists(): Promise<boolean>;
|
|
382
382
|
ensureCollectionExists(): Promise<void>;
|
|
383
|
+
/** `createCollection` options for this table (`@db.mongo.capped` size/max). */
|
|
384
|
+
collectionCreateOptions(): Record<string, unknown>;
|
|
383
385
|
/**
|
|
384
386
|
* Builds a Mongo filter for CAS-aware writes. Throws when `expectedVersion`
|
|
385
387
|
* is supplied for a non-versioned table — fail loud at the adapter boundary
|
package/dist/index.mjs
CHANGED
|
@@ -1275,16 +1275,13 @@ async function recreateTableImpl(host) {
|
|
|
1275
1275
|
const tableName = host._table.tableName;
|
|
1276
1276
|
host._log("recreateTable", tableName);
|
|
1277
1277
|
const tempName = `${tableName}__tmp_${Date.now()}`;
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
const temp = host.db.collection(tempName);
|
|
1286
|
-
await temp.aggregate([{ $merge: { into: tableName } }]).toArray();
|
|
1287
|
-
await temp.drop();
|
|
1278
|
+
await host.db.createCollection(tempName, host.collectionCreateOptions());
|
|
1279
|
+
try {
|
|
1280
|
+
await host.db.collection(tableName).aggregate([{ $merge: { into: tempName } }]).toArray();
|
|
1281
|
+
await host.db.renameCollection(tempName, tableName, { dropTarget: true });
|
|
1282
|
+
} catch (error) {
|
|
1283
|
+
await dropTableByNameImpl(host, tempName);
|
|
1284
|
+
throw error;
|
|
1288
1285
|
}
|
|
1289
1286
|
}
|
|
1290
1287
|
async function renameTableImpl(host, oldName) {
|
|
@@ -2127,15 +2124,19 @@ var MongoAdapter = class MongoAdapter extends BaseDbAdapter {
|
|
|
2127
2124
|
async ensureCollectionExists() {
|
|
2128
2125
|
if (!await this.collectionExists()) {
|
|
2129
2126
|
this._log("createCollection", this._table.tableName);
|
|
2130
|
-
|
|
2131
|
-
if (this._cappedOptions) {
|
|
2132
|
-
opts.capped = true;
|
|
2133
|
-
opts.size = this._cappedOptions.size;
|
|
2134
|
-
if (this._cappedOptions.max !== null && this._cappedOptions.max !== void 0) opts.max = this._cappedOptions.max;
|
|
2135
|
-
}
|
|
2136
|
-
await this.db.createCollection(this._table.tableName, opts);
|
|
2127
|
+
await this.db.createCollection(this._table.tableName, this.collectionCreateOptions());
|
|
2137
2128
|
}
|
|
2138
2129
|
}
|
|
2130
|
+
/** `createCollection` options for this table (`@db.mongo.capped` size/max). */
|
|
2131
|
+
collectionCreateOptions() {
|
|
2132
|
+
const opts = { comment: "Created by Atscript Mongo Adapter" };
|
|
2133
|
+
if (this._cappedOptions) {
|
|
2134
|
+
opts.capped = true;
|
|
2135
|
+
opts.size = this._cappedOptions.size;
|
|
2136
|
+
if (this._cappedOptions.max !== null && this._cappedOptions.max !== void 0) opts.max = this._cappedOptions.max;
|
|
2137
|
+
}
|
|
2138
|
+
return opts;
|
|
2139
|
+
}
|
|
2139
2140
|
/**
|
|
2140
2141
|
* Builds a Mongo filter for CAS-aware writes. Throws when `expectedVersion`
|
|
2141
2142
|
* is supplied for a non-versioned table — fail loud at the adapter boundary
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-mongo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.139",
|
|
4
4
|
"description": "Mongodb plugin for atscript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@atscript/typescript": "^0.1.92",
|
|
59
59
|
"@uniqu/core": "^0.1.11",
|
|
60
60
|
"mongodb": "^6.17.0",
|
|
61
|
-
"@atscript/db": "^0.1.
|
|
61
|
+
"@atscript/db": "^0.1.139"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"postinstall": "asc -f dts",
|